@egain/ai-agent-sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/README.md +295 -0
  2. package/dist/browser.js +22739 -0
  3. package/dist/core/AiAgent.d.ts +1126 -0
  4. package/dist/core/AiAgent.d.ts.map +1 -0
  5. package/dist/core/AiAgent.js +2037 -0
  6. package/dist/core/AiAgent.js.map +1 -0
  7. package/dist/core/api/ApiHelper.d.ts +433 -0
  8. package/dist/core/api/ApiHelper.d.ts.map +1 -0
  9. package/dist/core/api/ApiHelper.js +689 -0
  10. package/dist/core/api/ApiHelper.js.map +1 -0
  11. package/dist/core/api/CacheAdapter.d.ts +295 -0
  12. package/dist/core/api/CacheAdapter.d.ts.map +1 -0
  13. package/dist/core/api/CacheAdapter.js +298 -0
  14. package/dist/core/api/CacheAdapter.js.map +1 -0
  15. package/dist/core/auth/AnonymousAuthStrategy.d.ts +87 -0
  16. package/dist/core/auth/AnonymousAuthStrategy.d.ts.map +1 -0
  17. package/dist/core/auth/AnonymousAuthStrategy.js +257 -0
  18. package/dist/core/auth/AnonymousAuthStrategy.js.map +1 -0
  19. package/dist/core/auth/AuthProvider.d.ts +13 -0
  20. package/dist/core/auth/AuthProvider.d.ts.map +1 -0
  21. package/dist/core/auth/AuthProvider.js +2 -0
  22. package/dist/core/auth/AuthProvider.js.map +1 -0
  23. package/dist/core/auth/AuthStrategy.d.ts +74 -0
  24. package/dist/core/auth/AuthStrategy.d.ts.map +1 -0
  25. package/dist/core/auth/AuthStrategy.js +2 -0
  26. package/dist/core/auth/AuthStrategy.js.map +1 -0
  27. package/dist/core/auth/AuthenticationService.d.ts +226 -0
  28. package/dist/core/auth/AuthenticationService.d.ts.map +1 -0
  29. package/dist/core/auth/AuthenticationService.js +344 -0
  30. package/dist/core/auth/AuthenticationService.js.map +1 -0
  31. package/dist/core/auth/ClientCredentialsAuthStrategy.d.ts +62 -0
  32. package/dist/core/auth/ClientCredentialsAuthStrategy.d.ts.map +1 -0
  33. package/dist/core/auth/ClientCredentialsAuthStrategy.js +78 -0
  34. package/dist/core/auth/ClientCredentialsAuthStrategy.js.map +1 -0
  35. package/dist/core/auth/PKCEAuthStrategy.d.ts +136 -0
  36. package/dist/core/auth/PKCEAuthStrategy.d.ts.map +1 -0
  37. package/dist/core/auth/PKCEAuthStrategy.js +409 -0
  38. package/dist/core/auth/PKCEAuthStrategy.js.map +1 -0
  39. package/dist/core/auth/PreAuthStrategy.d.ts +101 -0
  40. package/dist/core/auth/PreAuthStrategy.d.ts.map +1 -0
  41. package/dist/core/auth/PreAuthStrategy.js +216 -0
  42. package/dist/core/auth/PreAuthStrategy.js.map +1 -0
  43. package/dist/core/auth/msal-browser.js +19683 -0
  44. package/dist/core/auth/msal-loader.d.ts +14 -0
  45. package/dist/core/auth/msal-loader.d.ts.map +1 -0
  46. package/dist/core/auth/msal-loader.js +43 -0
  47. package/dist/core/auth/msal-loader.js.map +1 -0
  48. package/dist/core/connection/Connection.d.ts +168 -0
  49. package/dist/core/connection/Connection.d.ts.map +1 -0
  50. package/dist/core/connection/Connection.js +290 -0
  51. package/dist/core/connection/Connection.js.map +1 -0
  52. package/dist/core/connection/ConnectionState.d.ts +11 -0
  53. package/dist/core/connection/ConnectionState.d.ts.map +1 -0
  54. package/dist/core/connection/ConnectionState.js +12 -0
  55. package/dist/core/connection/ConnectionState.js.map +1 -0
  56. package/dist/core/connection/Transport.d.ts +98 -0
  57. package/dist/core/connection/Transport.d.ts.map +1 -0
  58. package/dist/core/connection/Transport.js +27 -0
  59. package/dist/core/connection/Transport.js.map +1 -0
  60. package/dist/core/connection/WebSocketTransport.d.ts +65 -0
  61. package/dist/core/connection/WebSocketTransport.d.ts.map +1 -0
  62. package/dist/core/connection/WebSocketTransport.js +177 -0
  63. package/dist/core/connection/WebSocketTransport.js.map +1 -0
  64. package/dist/core/errors/SDKError.d.ts +27 -0
  65. package/dist/core/errors/SDKError.d.ts.map +1 -0
  66. package/dist/core/errors/SDKError.js +43 -0
  67. package/dist/core/errors/SDKError.js.map +1 -0
  68. package/dist/core/events/EventEmitter.d.ts +120 -0
  69. package/dist/core/events/EventEmitter.d.ts.map +1 -0
  70. package/dist/core/events/EventEmitter.js +183 -0
  71. package/dist/core/events/EventEmitter.js.map +1 -0
  72. package/dist/core/logging/LogLevel.d.ts +33 -0
  73. package/dist/core/logging/LogLevel.d.ts.map +1 -0
  74. package/dist/core/logging/LogLevel.js +40 -0
  75. package/dist/core/logging/LogLevel.js.map +1 -0
  76. package/dist/core/logging/Logger.d.ts +120 -0
  77. package/dist/core/logging/Logger.d.ts.map +1 -0
  78. package/dist/core/logging/Logger.js +204 -0
  79. package/dist/core/logging/Logger.js.map +1 -0
  80. package/dist/core/logging/globalLogger.d.ts +8 -0
  81. package/dist/core/logging/globalLogger.d.ts.map +1 -0
  82. package/dist/core/logging/globalLogger.js +12 -0
  83. package/dist/core/logging/globalLogger.js.map +1 -0
  84. package/dist/core/logging/types.d.ts +45 -0
  85. package/dist/core/logging/types.d.ts.map +1 -0
  86. package/dist/core/logging/types.js +2 -0
  87. package/dist/core/logging/types.js.map +1 -0
  88. package/dist/core/message/BaseMessageHandler.d.ts +208 -0
  89. package/dist/core/message/BaseMessageHandler.d.ts.map +1 -0
  90. package/dist/core/message/BaseMessageHandler.js +155 -0
  91. package/dist/core/message/BaseMessageHandler.js.map +1 -0
  92. package/dist/core/message/Message.d.ts +69 -0
  93. package/dist/core/message/Message.d.ts.map +1 -0
  94. package/dist/core/message/Message.js +131 -0
  95. package/dist/core/message/Message.js.map +1 -0
  96. package/dist/core/message/MessageProcessor.d.ts +51 -0
  97. package/dist/core/message/MessageProcessor.d.ts.map +1 -0
  98. package/dist/core/message/MessageProcessor.js +123 -0
  99. package/dist/core/message/MessageProcessor.js.map +1 -0
  100. package/dist/core/message/MessageTypes.d.ts +123 -0
  101. package/dist/core/message/MessageTypes.d.ts.map +1 -0
  102. package/dist/core/message/MessageTypes.js +106 -0
  103. package/dist/core/message/MessageTypes.js.map +1 -0
  104. package/dist/core/message/Transcript.d.ts +373 -0
  105. package/dist/core/message/Transcript.d.ts.map +1 -0
  106. package/dist/core/message/Transcript.js +355 -0
  107. package/dist/core/message/Transcript.js.map +1 -0
  108. package/dist/core/message/handlers/AgentMessageHandler.d.ts +26 -0
  109. package/dist/core/message/handlers/AgentMessageHandler.d.ts.map +1 -0
  110. package/dist/core/message/handlers/AgentMessageHandler.js +130 -0
  111. package/dist/core/message/handlers/AgentMessageHandler.js.map +1 -0
  112. package/dist/core/message/handlers/ChatHistoryHandler.d.ts +12 -0
  113. package/dist/core/message/handlers/ChatHistoryHandler.d.ts.map +1 -0
  114. package/dist/core/message/handlers/ChatHistoryHandler.js +49 -0
  115. package/dist/core/message/handlers/ChatHistoryHandler.js.map +1 -0
  116. package/dist/core/message/handlers/ErrorMessageHandler.d.ts +12 -0
  117. package/dist/core/message/handlers/ErrorMessageHandler.d.ts.map +1 -0
  118. package/dist/core/message/handlers/ErrorMessageHandler.js +49 -0
  119. package/dist/core/message/handlers/ErrorMessageHandler.js.map +1 -0
  120. package/dist/core/message/handlers/HeartbeatHandler.d.ts +12 -0
  121. package/dist/core/message/handlers/HeartbeatHandler.d.ts.map +1 -0
  122. package/dist/core/message/handlers/HeartbeatHandler.js +46 -0
  123. package/dist/core/message/handlers/HeartbeatHandler.js.map +1 -0
  124. package/dist/core/message/handlers/TokenRefreshHandler.d.ts +30 -0
  125. package/dist/core/message/handlers/TokenRefreshHandler.d.ts.map +1 -0
  126. package/dist/core/message/handlers/TokenRefreshHandler.js +84 -0
  127. package/dist/core/message/handlers/TokenRefreshHandler.js.map +1 -0
  128. package/dist/core/message/types.d.ts +107 -0
  129. package/dist/core/message/types.d.ts.map +1 -0
  130. package/dist/core/message/types.js +30 -0
  131. package/dist/core/message/types.js.map +1 -0
  132. package/dist/core/platform/HookContract.d.ts +112 -0
  133. package/dist/core/platform/HookContract.d.ts.map +1 -0
  134. package/dist/core/platform/HookContract.js +13 -0
  135. package/dist/core/platform/HookContract.js.map +1 -0
  136. package/dist/core/platform/PlatformComponentService.d.ts +40 -0
  137. package/dist/core/platform/PlatformComponentService.d.ts.map +1 -0
  138. package/dist/core/platform/PlatformComponentService.js +12 -0
  139. package/dist/core/platform/PlatformComponentService.js.map +1 -0
  140. package/dist/core/platform/PlatformScriptLoader.d.ts +41 -0
  141. package/dist/core/platform/PlatformScriptLoader.d.ts.map +1 -0
  142. package/dist/core/platform/PlatformScriptLoader.js +110 -0
  143. package/dist/core/platform/PlatformScriptLoader.js.map +1 -0
  144. package/dist/core/polyfills.d.ts +16 -0
  145. package/dist/core/polyfills.d.ts.map +1 -0
  146. package/dist/core/polyfills.js +168 -0
  147. package/dist/core/polyfills.js.map +1 -0
  148. package/dist/core/portal-initializer/PortalInitializer.d.ts +234 -0
  149. package/dist/core/portal-initializer/PortalInitializer.d.ts.map +1 -0
  150. package/dist/core/portal-initializer/PortalInitializer.js +636 -0
  151. package/dist/core/portal-initializer/PortalInitializer.js.map +1 -0
  152. package/dist/core/queue/MessageQueue.d.ts +277 -0
  153. package/dist/core/queue/MessageQueue.d.ts.map +1 -0
  154. package/dist/core/queue/MessageQueue.js +291 -0
  155. package/dist/core/queue/MessageQueue.js.map +1 -0
  156. package/dist/core/types/PortalTypes.d.ts +51 -0
  157. package/dist/core/types/PortalTypes.d.ts.map +1 -0
  158. package/dist/core/types/PortalTypes.js +8 -0
  159. package/dist/core/types/PortalTypes.js.map +1 -0
  160. package/dist/index.d.ts +91 -0
  161. package/dist/index.d.ts.map +1 -0
  162. package/dist/index.js +82 -0
  163. package/dist/index.js.map +1 -0
  164. package/package.json +84 -0
@@ -0,0 +1,226 @@
1
+ import { AuthStrategy, PostAuthenticationCallback, AuthServiceInitializeOptions } from './AuthStrategy.js';
2
+ import { AuthProvider } from './AuthProvider.js';
3
+ import { AnonymousAuthConfig } from './AnonymousAuthStrategy.js';
4
+ import { PKCEAuthConfig } from './PKCEAuthStrategy.js';
5
+ import { TokenExpiringCallback } from './PreAuthStrategy.js';
6
+ import { ClientCredentialsAuthConfig } from './ClientCredentialsAuthStrategy.js';
7
+ import { Logger } from '../logging/Logger.js';
8
+ import { CacheStorageType } from '../api/CacheAdapter.js';
9
+ /**
10
+ * Authentication types supported by the service
11
+ */
12
+ export type AuthenticationType = 'anonymous' | 'pkce' | 'pre-auth' | 'client-credentials';
13
+ /**
14
+ * Anonymous authentication configuration
15
+ */
16
+ export interface AnonymousAuthServiceConfig {
17
+ type: 'anonymous';
18
+ /**
19
+ * Optional anonymous auth config
20
+ */
21
+ config?: AnonymousAuthConfig;
22
+ }
23
+ /**
24
+ * PKCE authentication configuration
25
+ */
26
+ export interface PKCEAuthServiceConfig {
27
+ type: 'pkce';
28
+ /**
29
+ * PKCE configuration options
30
+ */
31
+ config: PKCEAuthConfig;
32
+ }
33
+ /**
34
+ * Pre-auth authentication configuration
35
+ */
36
+ export interface PreAuthServiceConfig {
37
+ type: 'pre-auth';
38
+ /**
39
+ * Access token to use directly
40
+ */
41
+ accessToken: string;
42
+ /**
43
+ * Optional token refresh function
44
+ * If provided, will be called when token needs to be refreshed
45
+ */
46
+ refreshTokenFn?: () => Promise<string>;
47
+ }
48
+ /**
49
+ * Client credentials authentication configuration
50
+ */
51
+ export interface ClientCredentialsAuthServiceConfig {
52
+ type: 'client-credentials';
53
+ /**
54
+ * Client credentials configuration options
55
+ */
56
+ config: ClientCredentialsAuthConfig;
57
+ }
58
+ /**
59
+ * Union type of all authentication service configurations
60
+ */
61
+ export type AuthenticationServiceConfig = AnonymousAuthServiceConfig | PKCEAuthServiceConfig | PreAuthServiceConfig | ClientCredentialsAuthServiceConfig;
62
+ /**
63
+ * Input types that AuthenticationService can accept
64
+ * - AuthenticationServiceConfig: Configuration object for automatic strategy selection
65
+ * - AuthProvider: Custom auth provider implementing getToken()
66
+ * - AuthStrategy: Full authentication strategy with lifecycle
67
+ * - undefined: Falls back to anonymous authentication
68
+ */
69
+ export type AuthenticationInput = AuthenticationServiceConfig | AuthProvider | AuthStrategy | undefined;
70
+ /**
71
+ * AuthenticationService - Centralized authentication management
72
+ *
73
+ * This service provides a unified interface for authentication by:
74
+ * - Accepting various input types (config objects, AuthProvider, AuthStrategy)
75
+ * - Selecting the appropriate strategy based on input
76
+ * - Implementing the AuthStrategy interface for seamless integration
77
+ * - Providing a single point for authentication logic
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * // Using pre-auth with a token
82
+ * const authService = new AuthenticationService({
83
+ * type: 'pre-auth',
84
+ * accessToken: 'your-api-key'
85
+ * });
86
+ *
87
+ * // Using pre-auth with token refresh
88
+ * const authService = new AuthenticationService({
89
+ * type: 'pre-auth',
90
+ * accessToken: 'your-jwt-token',
91
+ * refreshTokenFn: async () => await fetchNewToken()
92
+ * });
93
+ *
94
+ * // Using PKCE config
95
+ * const authService = new AuthenticationService({
96
+ * type: 'pkce',
97
+ * config: {
98
+ * authorizationUrl: 'https://auth.example.com/authorize',
99
+ * tokenUrl: 'https://auth.example.com/token',
100
+ * clientId: 'your-client-id',
101
+ * redirectUri: 'https://your-app.com/callback'
102
+ * }
103
+ * });
104
+ *
105
+ * // No auth (anonymous)
106
+ * const authService = new AuthenticationService();
107
+ *
108
+ * // Use with AiAgent
109
+ * const agent = new AiAgent({
110
+ * id: 'agent-id',
111
+ * endpoint: 'wss://...',
112
+ * auth: { type: 'pre-auth', accessToken: 'your-token' }
113
+ * });
114
+ * ```
115
+ */
116
+ /**
117
+ * Cache configuration options for AuthenticationService
118
+ * Used to configure caching for AnonymousAuthStrategy
119
+ */
120
+ export interface AuthServiceCacheConfig {
121
+ enabled?: boolean;
122
+ storageType?: CacheStorageType;
123
+ keyPrefix?: string;
124
+ ttl?: number;
125
+ }
126
+ export declare class AuthenticationService implements AuthStrategy {
127
+ private readonly input?;
128
+ private strategy;
129
+ private postAuthentication?;
130
+ private isInitialized;
131
+ private readonly authenticationType;
132
+ private domain?;
133
+ private logger;
134
+ private cacheConfig?;
135
+ constructor(input?: AuthenticationInput, logger?: Logger, cacheConfig?: AuthServiceCacheConfig);
136
+ /**
137
+ * Resolve the input to an authentication strategy
138
+ * Handles all input types: config objects, AuthProvider, AuthStrategy, or undefined
139
+ */
140
+ private resolveInput;
141
+ /**
142
+ * Type guard to check if input is an AuthenticationServiceConfig
143
+ */
144
+ private isAuthenticationServiceConfig;
145
+ /**
146
+ * Type guard to check if input is an AuthStrategy
147
+ */
148
+ private isAuthStrategy;
149
+ /**
150
+ * Type guard to check if input is an AuthProvider
151
+ */
152
+ private isAuthProvider;
153
+ /**
154
+ * Wrap an AuthProvider in an AuthStrategy
155
+ */
156
+ private wrapAuthProvider;
157
+ /**
158
+ * Select the appropriate authentication strategy based on configuration
159
+ */
160
+ private selectStrategy;
161
+ /**
162
+ * Initialize the authentication service
163
+ * Delegates to the selected strategy
164
+ */
165
+ initialize(options?: AuthServiceInitializeOptions): Promise<void>;
166
+ /**
167
+ * Get the domain for authentication
168
+ */
169
+ getDomain(): string;
170
+ /**
171
+ * Authenticate using the selected strategy
172
+ */
173
+ authenticate(): Promise<void>;
174
+ /**
175
+ * Get the authentication token from the selected strategy
176
+ */
177
+ getToken(): Promise<string | null>;
178
+ /**
179
+ * Cleanup resources from the selected strategy
180
+ */
181
+ cleanup(): Promise<void>;
182
+ /**
183
+ * Get the current authentication type
184
+ */
185
+ getAuthenticationType(): AuthenticationType;
186
+ /**
187
+ * Check if the service is initialized
188
+ */
189
+ getIsInitialized(): boolean;
190
+ /**
191
+ * Get the underlying strategy (for advanced use cases)
192
+ * @returns The underlying AuthStrategy instance
193
+ */
194
+ getStrategy(): AuthStrategy;
195
+ /**
196
+ * Check if the current strategy is anonymous
197
+ * @returns True if the current strategy is anonymous, false otherwise
198
+ */
199
+ isAnonymousStrategy(): boolean;
200
+ /**
201
+ * Check if the current strategy is PKCE
202
+ * @returns True if the current strategy is PKCE, false otherwise
203
+ */
204
+ isPKCEStrategy(): boolean;
205
+ /**
206
+ * Update the access token at runtime
207
+ * Only supported for PreAuthStrategy
208
+ * @param token - The new access token
209
+ * @throws AuthError if the underlying strategy doesn't support token updates
210
+ */
211
+ updateToken(token: string): Promise<void>;
212
+ /**
213
+ * Set the callback to be called when token is about to expire
214
+ * Only supported for PreAuthStrategy
215
+ * @param callback - Function to call when token is expiring, receives expiresAt timestamp
216
+ */
217
+ setTokenExpiringCallback(callback: TokenExpiringCallback): void;
218
+ /**
219
+ * Switch from anonymous strategy to PKCE strategy
220
+ * Only switches if the current strategy is anonymous, otherwise keeps the same strategy
221
+ * @param pkceConfig - PKCE configuration options
222
+ * @returns True if strategy was switched, false if it was already PKCE or not anonymous
223
+ */
224
+ switchStrategyTo(pkceConfig: PKCEAuthConfig, postAuthentication?: PostAuthenticationCallback): Promise<boolean>;
225
+ }
226
+ //# sourceMappingURL=AuthenticationService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthenticationService.d.ts","sourceRoot":"","sources":["../../../src/core/auth/AuthenticationService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,0BAA0B,EAAiC,4BAA4B,EAAE,MAAM,mBAAmB,CAAC;AAC1I,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAyB,mBAAmB,EAA4B,MAAM,4BAA4B,CAAC;AAClH,OAAO,EAAoB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAmB,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAiC,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AAGhH,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAC1B,WAAW,GACX,MAAM,GACN,UAAU,GACV,oBAAoB,CAAC;AAEzB;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,WAAW,CA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{ PKCEAuthStrategy } from './PKCEAuthStrategy.js';
3
+ import { PreAuthStrategy } from './PreAuthStrategy.js';
4
+ import { ClientCredentialsAuthStrategy } from './ClientCredentialsAuthStrategy.js';
5
+ import { AuthError } from '../errors/SDKError.js';
6
+ import { globalLogger } from '../logging/globalLogger.js';
7
+ export class AuthenticationService {
8
+ constructor(input, logger, cacheConfig) {
9
+ this.input = input;
10
+ this.isInitialized = false;
11
+ this.logger = logger ?? globalLogger;
12
+ this.cacheConfig = cacheConfig;
13
+ const resolved = this.resolveInput(input);
14
+ this.strategy = resolved.strategy;
15
+ this.authenticationType = resolved.type;
16
+ this.logger.debug('AuthenticationService created', { authenticationType: this.authenticationType });
17
+ }
18
+ /**
19
+ * Resolve the input to an authentication strategy
20
+ * Handles all input types: config objects, AuthProvider, AuthStrategy, or undefined
21
+ */
22
+ resolveInput(input) {
23
+ // No input - default to anonymous with cache config
24
+ if (!input) {
25
+ return {
26
+ strategy: new AnonymousAuthStrategy(this.cacheConfig ? { cache: this.cacheConfig } : undefined),
27
+ type: 'anonymous'
28
+ };
29
+ }
30
+ // AuthenticationServiceConfig - select strategy based on type
31
+ if (this.isAuthenticationServiceConfig(input)) {
32
+ return {
33
+ strategy: this.selectStrategy(input),
34
+ type: input.type
35
+ };
36
+ }
37
+ // AuthStrategy - use directly
38
+ if (this.isAuthStrategy(input)) {
39
+ return {
40
+ strategy: input,
41
+ type: 'pre-auth' // Default type for direct strategy
42
+ };
43
+ }
44
+ // AuthProvider - wrap in a strategy
45
+ if (this.isAuthProvider(input)) {
46
+ return {
47
+ strategy: this.wrapAuthProvider(input),
48
+ type: 'pre-auth'
49
+ };
50
+ }
51
+ throw new AuthError('Invalid authentication input provided');
52
+ }
53
+ /**
54
+ * Type guard to check if input is an AuthenticationServiceConfig
55
+ */
56
+ isAuthenticationServiceConfig(input) {
57
+ return (typeof input === 'object' &&
58
+ input !== null &&
59
+ 'type' in input &&
60
+ typeof input.type === 'string');
61
+ }
62
+ /**
63
+ * Type guard to check if input is an AuthStrategy
64
+ */
65
+ isAuthStrategy(input) {
66
+ return (typeof input === 'object' &&
67
+ input !== null &&
68
+ 'initialize' in input &&
69
+ typeof input.initialize === 'function' &&
70
+ 'authenticate' in input &&
71
+ typeof input.authenticate === 'function');
72
+ }
73
+ /**
74
+ * Type guard to check if input is an AuthProvider
75
+ */
76
+ isAuthProvider(input) {
77
+ return (typeof input === 'object' &&
78
+ input !== null &&
79
+ 'getToken' in input &&
80
+ typeof input.getToken === 'function' &&
81
+ !('initialize' in input) // Not an AuthStrategy
82
+ );
83
+ }
84
+ /**
85
+ * Wrap an AuthProvider in an AuthStrategy
86
+ */
87
+ wrapAuthProvider(provider) {
88
+ let postAuth;
89
+ let deploymentInfo;
90
+ return {
91
+ initialize: async (options) => {
92
+ postAuth = options?.postAuthentication;
93
+ deploymentInfo = options?.deploymentInfo;
94
+ },
95
+ authenticate: async () => {
96
+ const token = await provider.getToken();
97
+ if (postAuth) {
98
+ await postAuth(token);
99
+ }
100
+ },
101
+ getToken: () => provider.getToken(),
102
+ cleanup: async () => {
103
+ // No cleanup needed for simple providers
104
+ }
105
+ };
106
+ }
107
+ /**
108
+ * Select the appropriate authentication strategy based on configuration
109
+ */
110
+ selectStrategy(config) {
111
+ switch (config.type) {
112
+ case 'anonymous': {
113
+ // Merge cache config from service if not already provided in anonymous config
114
+ const anonymousConfig = config.config || {};
115
+ if (this.cacheConfig && !anonymousConfig.cache) {
116
+ anonymousConfig.cache = this.cacheConfig;
117
+ }
118
+ return new AnonymousAuthStrategy(anonymousConfig);
119
+ }
120
+ case 'pkce':
121
+ return new PKCEAuthStrategy(config.config);
122
+ case 'pre-auth':
123
+ return new PreAuthStrategy({
124
+ accessToken: config.accessToken,
125
+ refreshTokenFn: config.refreshTokenFn
126
+ });
127
+ case 'client-credentials':
128
+ return new ClientCredentialsAuthStrategy(config.config);
129
+ default:
130
+ // TypeScript exhaustiveness check
131
+ const exhaustiveCheck = config;
132
+ throw new AuthError(`Unsupported authentication type: ${exhaustiveCheck.type}`);
133
+ }
134
+ }
135
+ /**
136
+ * Initialize the authentication service
137
+ * Delegates to the selected strategy
138
+ */
139
+ async initialize(options) {
140
+ // Update postAuthentication callback even if already initialized
141
+ // This allows setting the callback after early initialization (e.g., for fetching agent details)
142
+ if (options?.postAuthentication) {
143
+ this.postAuthentication = options.postAuthentication;
144
+ }
145
+ if (this.isInitialized) {
146
+ // If already initialized, still update the strategy's postAuthentication callback if provided
147
+ // This fixes the regression where postAuthentication wasn't set after early initialization
148
+ if (options?.postAuthentication) {
149
+ this.logger.debug('AuthenticationService already initialized, updating postAuthentication callback', {
150
+ authenticationType: this.authenticationType,
151
+ hasPostAuthentication: !!options.postAuthentication
152
+ });
153
+ // Update the strategy's postAuthentication callback
154
+ await this.strategy.initialize({
155
+ deploymentInfo: options?.deploymentInfo,
156
+ scopes: options?.scopes,
157
+ postAuthentication: options.postAuthentication
158
+ });
159
+ this.logger.debug('Strategy postAuthentication callback updated', { authenticationType: this.authenticationType });
160
+ }
161
+ else {
162
+ this.logger.debug('AuthenticationService already initialized', { authenticationType: this.authenticationType });
163
+ }
164
+ return;
165
+ }
166
+ this.logger.debug('Initializing AuthenticationService', { authenticationType: this.authenticationType });
167
+ // Build scopes: default scopes + core.customermgr.read for customer userType
168
+ let scopes;
169
+ if (options?.scopes) {
170
+ scopes = options.scopes;
171
+ }
172
+ else {
173
+ scopes = ["knowledge.portalmgr.manage", "core.aiservices.read"];
174
+ if (options?.userType === 'customer') {
175
+ scopes.push("core.customermgr.read");
176
+ }
177
+ }
178
+ const deploymentInfo = options?.deploymentInfo;
179
+ // Use stored postAuthentication if no new one provided
180
+ const postAuth = options?.postAuthentication ?? this.postAuthentication;
181
+ await this.strategy.initialize({
182
+ deploymentInfo,
183
+ scopes: scopes,
184
+ postAuthentication: postAuth
185
+ });
186
+ this.isInitialized = true;
187
+ this.logger.info('AuthenticationService initialized', { authenticationType: this.authenticationType });
188
+ }
189
+ /**
190
+ * Get the domain for authentication
191
+ */
192
+ getDomain() {
193
+ return this.domain ?? '';
194
+ }
195
+ /**
196
+ * Authenticate using the selected strategy
197
+ */
198
+ async authenticate() {
199
+ this.logger.debug('Authenticating', { authenticationType: this.authenticationType });
200
+ try {
201
+ await this.strategy.authenticate();
202
+ this.logger.info('Authentication successful', { authenticationType: this.authenticationType });
203
+ }
204
+ catch (error) {
205
+ const err = error instanceof Error ? error : new Error(String(error));
206
+ this.logger.error('Authentication failed', err, { authenticationType: this.authenticationType });
207
+ throw error;
208
+ }
209
+ }
210
+ /**
211
+ * Get the authentication token from the selected strategy
212
+ */
213
+ async getToken() {
214
+ this.logger.debug('Getting authentication token', { authenticationType: this.authenticationType });
215
+ const token = await this.strategy.getToken();
216
+ if (token) {
217
+ this.logger.debug('Token retrieved successfully', { authenticationType: this.authenticationType, tokenLength: token.length });
218
+ }
219
+ else {
220
+ this.logger.warn('Token is null', { authenticationType: this.authenticationType });
221
+ }
222
+ return token;
223
+ }
224
+ /**
225
+ * Cleanup resources from the selected strategy
226
+ */
227
+ async cleanup() {
228
+ this.logger.debug('Cleaning up AuthenticationService', { authenticationType: this.authenticationType });
229
+ if (this.strategy.cleanup) {
230
+ await this.strategy.cleanup();
231
+ }
232
+ this.isInitialized = false;
233
+ this.logger.debug('AuthenticationService cleaned up', { authenticationType: this.authenticationType });
234
+ }
235
+ /**
236
+ * Get the current authentication type
237
+ */
238
+ getAuthenticationType() {
239
+ return this.authenticationType;
240
+ }
241
+ /**
242
+ * Check if the service is initialized
243
+ */
244
+ getIsInitialized() {
245
+ return this.isInitialized;
246
+ }
247
+ /**
248
+ * Get the underlying strategy (for advanced use cases)
249
+ * @returns The underlying AuthStrategy instance
250
+ */
251
+ getStrategy() {
252
+ return this.strategy;
253
+ }
254
+ /**
255
+ * Check if the current strategy is anonymous
256
+ * @returns True if the current strategy is anonymous, false otherwise
257
+ */
258
+ isAnonymousStrategy() {
259
+ return this.authenticationType === 'anonymous';
260
+ }
261
+ /**
262
+ * Check if the current strategy is PKCE
263
+ * @returns True if the current strategy is PKCE, false otherwise
264
+ */
265
+ isPKCEStrategy() {
266
+ return this.strategy instanceof PKCEAuthStrategy;
267
+ }
268
+ /**
269
+ * Update the access token at runtime
270
+ * Only supported for PreAuthStrategy
271
+ * @param token - The new access token
272
+ * @throws AuthError if the underlying strategy doesn't support token updates
273
+ */
274
+ async updateToken(token) {
275
+ this.logger.debug('Updating token', { authenticationType: this.authenticationType });
276
+ if (this.strategy instanceof PreAuthStrategy) {
277
+ await this.strategy.updateToken(token);
278
+ this.logger.info('Token updated successfully', { authenticationType: this.authenticationType });
279
+ }
280
+ else if ('updateToken' in this.strategy && typeof this.strategy.updateToken === 'function') {
281
+ // Support custom strategies that implement updateToken
282
+ await this.strategy.updateToken(token);
283
+ this.logger.info('Token updated successfully', { authenticationType: this.authenticationType });
284
+ }
285
+ else {
286
+ this.logger.warn('Token update not supported for this authentication type', { authenticationType: this.authenticationType });
287
+ throw new AuthError(`Token update is not supported for authentication type: ${this.authenticationType}`);
288
+ }
289
+ }
290
+ /**
291
+ * Set the callback to be called when token is about to expire
292
+ * Only supported for PreAuthStrategy
293
+ * @param callback - Function to call when token is expiring, receives expiresAt timestamp
294
+ */
295
+ setTokenExpiringCallback(callback) {
296
+ this.logger.debug('Setting token expiring callback', { authenticationType: this.authenticationType });
297
+ if (this.strategy instanceof PreAuthStrategy) {
298
+ this.strategy.setTokenExpiringCallback(callback);
299
+ this.logger.debug('Token expiring callback set', { authenticationType: this.authenticationType });
300
+ }
301
+ else if ('setTokenExpiringCallback' in this.strategy && typeof this.strategy.setTokenExpiringCallback === 'function') {
302
+ // Support custom strategies that implement setTokenExpiringCallback
303
+ this.strategy.setTokenExpiringCallback(callback);
304
+ this.logger.debug('Token expiring callback set', { authenticationType: this.authenticationType });
305
+ }
306
+ else {
307
+ this.logger.debug('Token expiring callback not supported for this authentication type', { authenticationType: this.authenticationType });
308
+ }
309
+ }
310
+ /**
311
+ * Switch from anonymous strategy to PKCE strategy
312
+ * Only switches if the current strategy is anonymous, otherwise keeps the same strategy
313
+ * @param pkceConfig - PKCE configuration options
314
+ * @returns True if strategy was switched, false if it was already PKCE or not anonymous
315
+ */
316
+ async switchStrategyTo(pkceConfig, postAuthentication) {
317
+ // Only switch if current strategy is anonymous
318
+ if (!this.isAnonymousStrategy()) {
319
+ this.logger.debug('Current strategy is not anonymous, keeping existing strategy', {
320
+ currentType: this.authenticationType
321
+ });
322
+ return false;
323
+ }
324
+ this.logger.info('Switching from anonymous to PKCE strategy');
325
+ // Clean up existing anonymous strategy
326
+ if (this.strategy.cleanup) {
327
+ await this.strategy.cleanup();
328
+ }
329
+ // Create and set new PKCE strategy
330
+ const pkceStrategy = new PKCEAuthStrategy(pkceConfig);
331
+ this.strategy = pkceStrategy;
332
+ // Update authentication type (using type assertion to update readonly field)
333
+ this.authenticationType = 'pkce';
334
+ // Reset initialization flag since we're switching strategies
335
+ this.isInitialized = false;
336
+ // Store postAuthentication callback if provided
337
+ if (postAuthentication) {
338
+ this.postAuthentication = postAuthentication;
339
+ }
340
+ this.logger.info('Successfully switched to PKCE strategy');
341
+ return true;
342
+ }
343
+ }
344
+ //# sourceMappingURL=AuthenticationService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthenticationService.js","sourceRoot":"","sources":["../../../src/core/auth/AuthenticationService.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAiD,MAAM,4BAA4B,CAAC;AAClH,OAAO,EAAE,gBAAgB,EAAkB,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,eAAe,EAAyB,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAE,6BAA6B,EAA+B,MAAM,oCAAoC,CAAC;AAChH,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGlD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AA4I1D,MAAM,OAAO,qBAAqB;IAShC,YAA6B,KAA2B,EAAE,MAAe,EAAE,WAAoC;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,2CAA2C,CAAC,CAAC;QAE9D,uCAAuC;QACvC,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;YAC1B,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;QAChC,CAAC;QAED,mCAAmC;QACnC,MAAM,YAAY,GAAG,IAAI,gBAAgB,CAAC,UAAU,CAAC,CAAC;QACtD,IAAI,CAAC,QAAQ,GAAG,YAAY,CAAC;QAE7B,6EAA6E;QAC5E,IAAY,CAAC,kBAAkB,GAAG,MAAM,CAAC;QAE1C,6DAA6D;QAC7D,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;QAE3B,gDAAgD;QAChD,IAAI,kBAAkB,EAAE,CAAC;YACvB,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;QAC/C,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;QAC3D,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,62 @@
1
+ import { AuthStrategy, AuthStrategyInitializeOptions } from './AuthStrategy.js';
2
+ /**
3
+ * Configuration for client credentials authentication strategy
4
+ */
5
+ export interface ClientCredentialsAuthConfig {
6
+ /**
7
+ * Token endpoint URL
8
+ */
9
+ tokenUrl: string;
10
+ /**
11
+ * Client ID
12
+ */
13
+ clientId: string;
14
+ /**
15
+ * Client secret
16
+ */
17
+ clientSecret: string;
18
+ /**
19
+ * Optional scopes to request
20
+ */
21
+ scopes?: string[];
22
+ }
23
+ /**
24
+ * Client credentials authentication strategy for server-side applications
25
+ * Implements OAuth 2.0 client credentials flow
26
+ */
27
+ export declare class ClientCredentialsAuthStrategy implements AuthStrategy {
28
+ private readonly config;
29
+ private postAuthentication?;
30
+ private isAuthenticatedFlag;
31
+ private deploymentInfo?;
32
+ constructor(config: ClientCredentialsAuthConfig);
33
+ /**
34
+ * Initialize the client credentials authentication strategy
35
+ */
36
+ initialize(options?: AuthStrategyInitializeOptions): Promise<void>;
37
+ /**
38
+ * Authenticate using client credentials flow
39
+ */
40
+ authenticate(): Promise<void>;
41
+ /**
42
+ * Check if the user is currently authenticated
43
+ */
44
+ isAuthenticated(): boolean;
45
+ /**
46
+ * Get authentication token using client credentials flow
47
+ */
48
+ getToken(): Promise<string>;
49
+ /**
50
+ * Request a new access token from the token endpoint
51
+ */
52
+ private requestToken;
53
+ /**
54
+ * Check if the current token is expired or about to expire
55
+ */
56
+ private isTokenExpired;
57
+ /**
58
+ * Cleanup resources
59
+ */
60
+ cleanup(): Promise<void>;
61
+ }
62
+ //# sourceMappingURL=ClientCredentialsAuthStrategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClientCredentialsAuthStrategy.d.ts","sourceRoot":"","sources":["../../../src/core/auth/ClientCredentialsAuthStrategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA8B,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AAE5G;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CAGnB;AAED;;;GAGG;AACH,qBAAa,6BAA8B,YAAW,YAAY;IAKpD,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJnC,OAAO,CAAC,kBAAkB,CAAC,CAA6B;IACxD,OAAO,CAAC,mBAAmB,CAAkB;IAC7C,OAAO,CAAC,cAAc,CAAC,CAAM;gBAEA,MAAM,EAAE,2BAA2B;IAEhE;;OAEG;IACG,UAAU,CAAC,OAAO,CAAC,EAAE,6BAA6B,GAAG,OAAO,CAAC,IAAI,CAAC;IAQxE;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAanC;;OAEG;IACH,eAAe,IAAI,OAAO;IAM1B;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC;IASjC;;OAEG;YACW,YAAY;IAQ1B;;OAEG;IACH,OAAO,CAAC,cAAc;IAKtB;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAI/B"}