@egain/ai-agent-sdk API Reference - v0.1.1 / AiAgentConfig
Interface: AiAgentConfig
Configuration options for creating an AiAgent instance.
Example
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
- id
- endpoint
- auth
- autoConnect
- maxQueueSize
- maxReconnectAttempts
- baseReconnectDelay
- maxReconnectDelay
- logger
- logLevel
- enableLogging
- transcriptConfig
- cache
- scopes
- sessionId
- initParams
- platformScriptUrl
- authScheme
Properties
id
• id: string
Agent ID
Defined in
endpoint
• endpoint: string
WebSocket endpoint URL
Defined in
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
autoConnect
• Optional autoConnect: boolean
Automatically connect after initialize() completes
Default
falseDefined in
maxQueueSize
• Optional maxQueueSize: number
Maximum queue size
Default
1000Defined in
maxReconnectAttempts
• Optional maxReconnectAttempts: number
Maximum reconnection attempts
Default
InfinityDefined in
baseReconnectDelay
• Optional baseReconnectDelay: number
Base reconnection delay in milliseconds
Default
1000Defined in
maxReconnectDelay
• Optional maxReconnectDelay: number
Maximum reconnection delay in milliseconds
Default
30000Defined in
logger
• Optional logger: Logger
Logger instance (optional) If not provided, a new logger instance will be created
Default
undefined (creates new instance)Defined in
logLevel
• Optional logLevel: LogLevel
Logging level for the agent
Default
INFODefined in
enableLogging
• Optional enableLogging: boolean
Enable console output for logs
Default
trueDefined in
transcriptConfig
• Optional transcriptConfig: TranscriptConfig
Transcript configuration (optional) Controls whether and how messages are stored in the transcript
Defined in
cache
• Optional cache: CacheConfig
Cache configuration for API calls (optional) Controls caching of agent details, portal details, and other API responses
Default
{ enabled: true, storageType: 'session', ttl: 300000 }Defined in
scopes
• Optional scopes: string[]
Custom OAuth scopes to request during authentication (optional) If not provided, default scopes will be used:
- ["knowledge.portalmgr.manage", "core.aiservices.read"] for agents
- ["knowledge.portalmgr.manage", "core.aiservices.read", "core.customermgr.read"] for customers
You can provide additional scopes to extend the default ones, or replace them entirely.
Example
// Add additional scopes
scopes: ["knowledge.portalmgr.manage", "core.aiservices.read", "custom.scope"]Defined in
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
undefined (fetches from network)Example
// Use existing sessionId (skips network fetch)
const agent = new AiAgent({
id: "agent-id",
endpoint: "https://api.egain.com",
sessionId: "existing-session-id"
});Defined in
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 (isDefaultAgentis not"true"), portals are intersected withagentDetails.portals(cc-widget parity)departmentId— optional fallback in Flow B whenagentDetails.departmentIdis missing; prefer agent details from the default agent API (cc-widget parity)portalIds— comma-separated portal IDs; when set, skipsgetMyPortalsand uses minimal portal objectstemplateName— alias for theme short URL template sent asshortUrlTemplateto portalmgr APIsauthType— signals the authentication mode ("user" | "customer")scopes— comma-separated OAuth scopes to request; when non-empty after parsing, overridesconfig.scopesand default scopes for PKCE / token acquisitionuserid— user identifier for portal cache keyingisDefaultAgent— 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
initParams: {
agentid: "agent-123",
userid: "user-456",
authType: "user",
isDefaultAgent: "true",
scopes: "knowledge.portalmgr.manage,core.aiservices.read"
}Defined in
platformScriptUrl
• Optional platformScriptUrl: string
Override URL for the platform connector script. When provided, the SDK loads this URL instead of constructing one from the platform name and deployment environment. Useful for local development or custom connector deployments.
Defined in
authScheme
• Optional authScheme: "popup" | "redirect"
Authentication scheme for the PKCE flow.
- 'popup': Opens a popup window for login (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
'popup'