Skip to content

@egain/ai-agent-sdk API Reference - v0.3.2 / AiAgentConfig

Interface: AiAgentConfig ​

Configuration options for creating an AiAgent instance.

Example

typescript
const config: AiAgentConfig = {
  id: "123-456-789",
  endpoint: "https://api.egain.com",
  auth: { type: "pre-auth", accessToken: "your-access-token" },
  autoConnect: true,
  logLevel: LogLevel.DEBUG
};

Table of contents ​

Properties ​

Properties ​

id ​

• id: string

Agent ID

Defined in ​

core/AiAgent.ts:59


endpoint ​

• endpoint: string

WebSocket endpoint URL

Defined in ​

core/AiAgent.ts:64


auth ​

• Optional auth: AuthenticationInput

Authentication configuration (optional) Can be:

  • AuthenticationServiceConfig: Configuration object (e.g., { type: 'pre-auth', accessToken: '...' })
  • AuthProvider: Custom auth provider implementing getToken()
  • AuthStrategy: Full authentication strategy with lifecycle
  • undefined: Falls back to anonymous authentication

Defined in ​

core/AiAgent.ts:74


autoConnect ​

• Optional autoConnect: boolean

Automatically connect after initialize() completes

Default

ts
false

Defined in ​

core/AiAgent.ts:80


maxQueueSize ​

• Optional maxQueueSize: number

Maximum queue size

Default

ts
1000

Defined in ​

core/AiAgent.ts:86


maxReconnectAttempts ​

• Optional maxReconnectAttempts: number

Maximum reconnection attempts

Default

ts
Infinity

Defined in ​

core/AiAgent.ts:92


baseReconnectDelay ​

• Optional baseReconnectDelay: number

Base reconnection delay in milliseconds

Default

ts
1000

Defined in ​

core/AiAgent.ts:98


maxReconnectDelay ​

• Optional maxReconnectDelay: number

Maximum reconnection delay in milliseconds

Default

ts
30000

Defined in ​

core/AiAgent.ts:104


logger ​

• Optional logger: Logger

Logger instance (optional) If not provided, a new logger instance will be created

Default

ts
undefined (creates new instance)

Defined in ​

core/AiAgent.ts:111


logLevel ​

• Optional logLevel: LogLevel

Logging level for the agent

Default

ts
INFO

Defined in ​

core/AiAgent.ts:117


enableLogging ​

• Optional enableLogging: boolean

Enable console output for logs

Default

ts
true

Defined in ​

core/AiAgent.ts:123


transcriptConfig ​

• Optional transcriptConfig: TranscriptConfig

Transcript configuration (optional) Controls whether and how messages are stored in the transcript

Defined in ​

core/AiAgent.ts:129


cache ​

• Optional cache: CacheConfig

Cache configuration for API calls (optional) Controls caching of agent details, portal details, and other API responses

Default

ts
{ enabled: true, storageType: 'session', ttl: 300000 }

Defined in ​

core/AiAgent.ts:136


sessionId ​

• Optional sessionId: string | number

Pre-provided session ID (optional) If provided, the SDK will skip fetching sessionId from the network during initialization. Useful when you already have a session ID from a previous session or external source.

Default

ts
undefined (fetches from network)

Example

typescript
// Use existing sessionId (skips network fetch)
const agent = new AiAgent({
  id: "agent-id",
  endpoint: "https://api.egain.com",
  sessionId: "existing-session-id"
});

Defined in ​

core/AiAgent.ts:155


initParams ​

• Optional initParams: Record<string, string>

Initialization parameters forwarded from the host application. SDK consumers pass them explicitly so the SDK remains URL-agnostic.

The SDK uses specific well-known keys internally:

  • agentid — when set and Flow A (isDefaultAgent is not "true"), portals are intersected with agentDetails.portals (cc-widget parity)
  • departmentId — optional fallback in Flow B when agentDetails.departmentId is missing; prefer agent details from the default agent API (cc-widget parity)
  • portalIds — comma-separated portal IDs; when set, skips getMyPortals and uses minimal portal objects
  • templateName — alias for theme short URL template sent as shortUrlTemplate to portalmgr APIs
  • authType — signals the authentication mode ("user" | "customer")
  • scopes — comma-separated OAuth scopes to request, used exactly as given (no defaults, no agent extraScopes, no platform augmentation). A host-supplied PKCE config's own scopes take precedence over this.
  • userid — user identifier for portal cache keying
  • isDefaultAgent — when "true", enables Flow B (agent selection mode)

All other keys are stored and accessible via agent.getInitParams() for use by the consuming application.

Example

typescript
initParams: {
  agentid: "agent-123",
  userid: "user-456",
  authType: "user",
  isDefaultAgent: "true",
  scopes: "knowledge.portalmgr.manage,core.aiservices.read"
}

Defined in ​

core/AiAgent.ts:185


context ​

• Optional context: Record<string, unknown>

Optional initialization context (merged with initialize({ context })). Used for portal/profile auto-select during the portal pipeline and stored for chat reconnect.

Defined in ​

core/AiAgent.ts:191


connector ​

• Optional connector: AiAgentConnectorConfig

Platform connector script URL and environment label from the host (e.g. cc-widget). When connectorUrl is omitted, the SDK loads from https://apps.egain.services/ using initParams.platform (with test mapped to the standalone connector path).

Defined in ​

core/AiAgent.ts:198


authScheme ​

• Optional authScheme: "popup" | "redirect"

Authentication scheme for the PKCE flow (login and logout).

  • 'popup': Opens a popup window for login / logout (default)
  • 'redirect': Redirects the current page to the identity provider

Only applies when the SDK auto-builds PKCE config from deployment info. Ignored when a full PKCEAuthConfig is supplied via config.auth.

Default

ts
'popup'

Defined in ​

core/AiAgent.ts:209

Released under the MIT License.