@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.
- package/README.md +295 -0
- package/dist/browser.js +22739 -0
- package/dist/core/AiAgent.d.ts +1126 -0
- package/dist/core/AiAgent.d.ts.map +1 -0
- package/dist/core/AiAgent.js +2037 -0
- package/dist/core/AiAgent.js.map +1 -0
- package/dist/core/api/ApiHelper.d.ts +433 -0
- package/dist/core/api/ApiHelper.d.ts.map +1 -0
- package/dist/core/api/ApiHelper.js +689 -0
- package/dist/core/api/ApiHelper.js.map +1 -0
- package/dist/core/api/CacheAdapter.d.ts +295 -0
- package/dist/core/api/CacheAdapter.d.ts.map +1 -0
- package/dist/core/api/CacheAdapter.js +298 -0
- package/dist/core/api/CacheAdapter.js.map +1 -0
- package/dist/core/auth/AnonymousAuthStrategy.d.ts +87 -0
- package/dist/core/auth/AnonymousAuthStrategy.d.ts.map +1 -0
- package/dist/core/auth/AnonymousAuthStrategy.js +257 -0
- package/dist/core/auth/AnonymousAuthStrategy.js.map +1 -0
- package/dist/core/auth/AuthProvider.d.ts +13 -0
- package/dist/core/auth/AuthProvider.d.ts.map +1 -0
- package/dist/core/auth/AuthProvider.js +2 -0
- package/dist/core/auth/AuthProvider.js.map +1 -0
- package/dist/core/auth/AuthStrategy.d.ts +74 -0
- package/dist/core/auth/AuthStrategy.d.ts.map +1 -0
- package/dist/core/auth/AuthStrategy.js +2 -0
- package/dist/core/auth/AuthStrategy.js.map +1 -0
- package/dist/core/auth/AuthenticationService.d.ts +226 -0
- package/dist/core/auth/AuthenticationService.d.ts.map +1 -0
- package/dist/core/auth/AuthenticationService.js +344 -0
- package/dist/core/auth/AuthenticationService.js.map +1 -0
- package/dist/core/auth/ClientCredentialsAuthStrategy.d.ts +62 -0
- package/dist/core/auth/ClientCredentialsAuthStrategy.d.ts.map +1 -0
- package/dist/core/auth/ClientCredentialsAuthStrategy.js +78 -0
- package/dist/core/auth/ClientCredentialsAuthStrategy.js.map +1 -0
- package/dist/core/auth/PKCEAuthStrategy.d.ts +136 -0
- package/dist/core/auth/PKCEAuthStrategy.d.ts.map +1 -0
- package/dist/core/auth/PKCEAuthStrategy.js +409 -0
- package/dist/core/auth/PKCEAuthStrategy.js.map +1 -0
- package/dist/core/auth/PreAuthStrategy.d.ts +101 -0
- package/dist/core/auth/PreAuthStrategy.d.ts.map +1 -0
- package/dist/core/auth/PreAuthStrategy.js +216 -0
- package/dist/core/auth/PreAuthStrategy.js.map +1 -0
- package/dist/core/auth/msal-browser.js +19683 -0
- package/dist/core/auth/msal-loader.d.ts +14 -0
- package/dist/core/auth/msal-loader.d.ts.map +1 -0
- package/dist/core/auth/msal-loader.js +43 -0
- package/dist/core/auth/msal-loader.js.map +1 -0
- package/dist/core/connection/Connection.d.ts +168 -0
- package/dist/core/connection/Connection.d.ts.map +1 -0
- package/dist/core/connection/Connection.js +290 -0
- package/dist/core/connection/Connection.js.map +1 -0
- package/dist/core/connection/ConnectionState.d.ts +11 -0
- package/dist/core/connection/ConnectionState.d.ts.map +1 -0
- package/dist/core/connection/ConnectionState.js +12 -0
- package/dist/core/connection/ConnectionState.js.map +1 -0
- package/dist/core/connection/Transport.d.ts +98 -0
- package/dist/core/connection/Transport.d.ts.map +1 -0
- package/dist/core/connection/Transport.js +27 -0
- package/dist/core/connection/Transport.js.map +1 -0
- package/dist/core/connection/WebSocketTransport.d.ts +65 -0
- package/dist/core/connection/WebSocketTransport.d.ts.map +1 -0
- package/dist/core/connection/WebSocketTransport.js +177 -0
- package/dist/core/connection/WebSocketTransport.js.map +1 -0
- package/dist/core/errors/SDKError.d.ts +27 -0
- package/dist/core/errors/SDKError.d.ts.map +1 -0
- package/dist/core/errors/SDKError.js +43 -0
- package/dist/core/errors/SDKError.js.map +1 -0
- package/dist/core/events/EventEmitter.d.ts +120 -0
- package/dist/core/events/EventEmitter.d.ts.map +1 -0
- package/dist/core/events/EventEmitter.js +183 -0
- package/dist/core/events/EventEmitter.js.map +1 -0
- package/dist/core/logging/LogLevel.d.ts +33 -0
- package/dist/core/logging/LogLevel.d.ts.map +1 -0
- package/dist/core/logging/LogLevel.js +40 -0
- package/dist/core/logging/LogLevel.js.map +1 -0
- package/dist/core/logging/Logger.d.ts +120 -0
- package/dist/core/logging/Logger.d.ts.map +1 -0
- package/dist/core/logging/Logger.js +204 -0
- package/dist/core/logging/Logger.js.map +1 -0
- package/dist/core/logging/globalLogger.d.ts +8 -0
- package/dist/core/logging/globalLogger.d.ts.map +1 -0
- package/dist/core/logging/globalLogger.js +12 -0
- package/dist/core/logging/globalLogger.js.map +1 -0
- package/dist/core/logging/types.d.ts +45 -0
- package/dist/core/logging/types.d.ts.map +1 -0
- package/dist/core/logging/types.js +2 -0
- package/dist/core/logging/types.js.map +1 -0
- package/dist/core/message/BaseMessageHandler.d.ts +208 -0
- package/dist/core/message/BaseMessageHandler.d.ts.map +1 -0
- package/dist/core/message/BaseMessageHandler.js +155 -0
- package/dist/core/message/BaseMessageHandler.js.map +1 -0
- package/dist/core/message/Message.d.ts +69 -0
- package/dist/core/message/Message.d.ts.map +1 -0
- package/dist/core/message/Message.js +131 -0
- package/dist/core/message/Message.js.map +1 -0
- package/dist/core/message/MessageProcessor.d.ts +51 -0
- package/dist/core/message/MessageProcessor.d.ts.map +1 -0
- package/dist/core/message/MessageProcessor.js +123 -0
- package/dist/core/message/MessageProcessor.js.map +1 -0
- package/dist/core/message/MessageTypes.d.ts +123 -0
- package/dist/core/message/MessageTypes.d.ts.map +1 -0
- package/dist/core/message/MessageTypes.js +106 -0
- package/dist/core/message/MessageTypes.js.map +1 -0
- package/dist/core/message/Transcript.d.ts +373 -0
- package/dist/core/message/Transcript.d.ts.map +1 -0
- package/dist/core/message/Transcript.js +355 -0
- package/dist/core/message/Transcript.js.map +1 -0
- package/dist/core/message/handlers/AgentMessageHandler.d.ts +26 -0
- package/dist/core/message/handlers/AgentMessageHandler.d.ts.map +1 -0
- package/dist/core/message/handlers/AgentMessageHandler.js +130 -0
- package/dist/core/message/handlers/AgentMessageHandler.js.map +1 -0
- package/dist/core/message/handlers/ChatHistoryHandler.d.ts +12 -0
- package/dist/core/message/handlers/ChatHistoryHandler.d.ts.map +1 -0
- package/dist/core/message/handlers/ChatHistoryHandler.js +49 -0
- package/dist/core/message/handlers/ChatHistoryHandler.js.map +1 -0
- package/dist/core/message/handlers/ErrorMessageHandler.d.ts +12 -0
- package/dist/core/message/handlers/ErrorMessageHandler.d.ts.map +1 -0
- package/dist/core/message/handlers/ErrorMessageHandler.js +49 -0
- package/dist/core/message/handlers/ErrorMessageHandler.js.map +1 -0
- package/dist/core/message/handlers/HeartbeatHandler.d.ts +12 -0
- package/dist/core/message/handlers/HeartbeatHandler.d.ts.map +1 -0
- package/dist/core/message/handlers/HeartbeatHandler.js +46 -0
- package/dist/core/message/handlers/HeartbeatHandler.js.map +1 -0
- package/dist/core/message/handlers/TokenRefreshHandler.d.ts +30 -0
- package/dist/core/message/handlers/TokenRefreshHandler.d.ts.map +1 -0
- package/dist/core/message/handlers/TokenRefreshHandler.js +84 -0
- package/dist/core/message/handlers/TokenRefreshHandler.js.map +1 -0
- package/dist/core/message/types.d.ts +107 -0
- package/dist/core/message/types.d.ts.map +1 -0
- package/dist/core/message/types.js +30 -0
- package/dist/core/message/types.js.map +1 -0
- package/dist/core/platform/HookContract.d.ts +112 -0
- package/dist/core/platform/HookContract.d.ts.map +1 -0
- package/dist/core/platform/HookContract.js +13 -0
- package/dist/core/platform/HookContract.js.map +1 -0
- package/dist/core/platform/PlatformComponentService.d.ts +40 -0
- package/dist/core/platform/PlatformComponentService.d.ts.map +1 -0
- package/dist/core/platform/PlatformComponentService.js +12 -0
- package/dist/core/platform/PlatformComponentService.js.map +1 -0
- package/dist/core/platform/PlatformScriptLoader.d.ts +41 -0
- package/dist/core/platform/PlatformScriptLoader.d.ts.map +1 -0
- package/dist/core/platform/PlatformScriptLoader.js +110 -0
- package/dist/core/platform/PlatformScriptLoader.js.map +1 -0
- package/dist/core/polyfills.d.ts +16 -0
- package/dist/core/polyfills.d.ts.map +1 -0
- package/dist/core/polyfills.js +168 -0
- package/dist/core/polyfills.js.map +1 -0
- package/dist/core/portal-initializer/PortalInitializer.d.ts +234 -0
- package/dist/core/portal-initializer/PortalInitializer.d.ts.map +1 -0
- package/dist/core/portal-initializer/PortalInitializer.js +636 -0
- package/dist/core/portal-initializer/PortalInitializer.js.map +1 -0
- package/dist/core/queue/MessageQueue.d.ts +277 -0
- package/dist/core/queue/MessageQueue.d.ts.map +1 -0
- package/dist/core/queue/MessageQueue.js +291 -0
- package/dist/core/queue/MessageQueue.js.map +1 -0
- package/dist/core/types/PortalTypes.d.ts +51 -0
- package/dist/core/types/PortalTypes.d.ts.map +1 -0
- package/dist/core/types/PortalTypes.js +8 -0
- package/dist/core/types/PortalTypes.js.map +1 -0
- package/dist/index.d.ts +91 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +82 -0
- package/dist/index.js.map +1 -0
- package/package.json +84 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseMessageHandler } from '../BaseMessageHandler.js';
|
|
2
|
+
import { Message } from '../Message.js';
|
|
3
|
+
import { MessageHandlerResult } from '../types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Handler for heartbeat messages
|
|
6
|
+
* Processes system heartbeat messages indicating the agent is processing/typing
|
|
7
|
+
*/
|
|
8
|
+
export declare class HeartbeatHandler extends BaseMessageHandler {
|
|
9
|
+
canHandle(message: Message): boolean;
|
|
10
|
+
handle(message: Message): MessageHandlerResult;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=HeartbeatHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HeartbeatHandler.d.ts","sourceRoot":"","sources":["../../../../src/core/message/handlers/HeartbeatHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAGnD;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,kBAAkB;IACtD,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO;IAOpC,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,oBAAoB;CAsC/C"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { BaseMessageHandler } from '../BaseMessageHandler.js';
|
|
2
|
+
import { PERSONA, ROLE } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Handler for heartbeat messages
|
|
5
|
+
* Processes system heartbeat messages indicating the agent is processing/typing
|
|
6
|
+
*/
|
|
7
|
+
export class HeartbeatHandler extends BaseMessageHandler {
|
|
8
|
+
canHandle(message) {
|
|
9
|
+
return (message.persona === PERSONA.SYSTEM &&
|
|
10
|
+
message.role === ROLE.HEARTBEAT);
|
|
11
|
+
}
|
|
12
|
+
handle(message) {
|
|
13
|
+
const sessionId = message.sessionId;
|
|
14
|
+
const agentId = message.agentId;
|
|
15
|
+
// Build from object - system/agent is the sender
|
|
16
|
+
const from = {
|
|
17
|
+
name: message.from || 'AI Agent',
|
|
18
|
+
isAi: true,
|
|
19
|
+
};
|
|
20
|
+
// Build to object - customer is the recipient
|
|
21
|
+
const to = {
|
|
22
|
+
name: message.to || 'Customer',
|
|
23
|
+
isAi: false,
|
|
24
|
+
};
|
|
25
|
+
// Build message object with persona, role, content, and raw data
|
|
26
|
+
const messageObj = {
|
|
27
|
+
persona: message.persona,
|
|
28
|
+
role: message.role,
|
|
29
|
+
content: message.content,
|
|
30
|
+
raw: message.messageData || {},
|
|
31
|
+
};
|
|
32
|
+
// Build result in the required format
|
|
33
|
+
const result = {
|
|
34
|
+
type: 'heartbeat_processed',
|
|
35
|
+
messageId: message.messageId,
|
|
36
|
+
timestamp: message.timestamp || Date.now(),
|
|
37
|
+
sessionId: sessionId,
|
|
38
|
+
agentId: agentId,
|
|
39
|
+
from: from,
|
|
40
|
+
to: to,
|
|
41
|
+
message: messageObj,
|
|
42
|
+
};
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=HeartbeatHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HeartbeatHandler.js","sourceRoot":"","sources":["../../../../src/core/message/handlers/HeartbeatHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAG9D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAE5C;;;GAGG;AACH,MAAM,OAAO,gBAAiB,SAAQ,kBAAkB;IACtD,SAAS,CAAC,OAAgB;QACxB,OAAO,CACL,OAAO,CAAC,OAAO,KAAK,OAAO,CAAC,MAAM;YAClC,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC,SAAS,CAChC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,OAAgB;QACrB,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACpC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAEhC,iDAAiD;QACjD,MAAM,IAAI,GAAG;YACX,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,UAAU;YAChC,IAAI,EAAE,IAAI;SACX,CAAC;QAEF,8CAA8C;QAC9C,MAAM,EAAE,GAAG;YACT,IAAI,EAAE,OAAO,CAAC,EAAE,IAAI,UAAU;YAC9B,IAAI,EAAE,KAAK;SACZ,CAAC;QAEF,iEAAiE;QACjE,MAAM,UAAU,GAAG;YACjB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,GAAG,EAAE,OAAO,CAAC,WAAW,IAAI,EAAE;SAC/B,CAAC;QAEF,sCAAsC;QACtC,MAAM,MAAM,GAAyB;YACnC,IAAI,EAAE,qBAAqB;YAC3B,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE;YAC1C,SAAS,EAAE,SAAS;YACpB,OAAO,EAAE,OAAO;YAChB,IAAI,EAAE,IAAI;YACV,EAAE,EAAE,EAAE;YACN,OAAO,EAAE,UAAU;SACpB,CAAC;QAEF,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BaseMessageHandler } from '../BaseMessageHandler.js';
|
|
2
|
+
import { Message } from '../Message.js';
|
|
3
|
+
import { MessageHandlerResult } from '../types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Options for TokenRefreshHandler
|
|
6
|
+
*/
|
|
7
|
+
export interface TokenRefreshHandlerOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Function to get a new access token
|
|
10
|
+
* @returns Promise resolving to the access token string
|
|
11
|
+
*/
|
|
12
|
+
getAccessToken?: () => Promise<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Function to send a message to the connection
|
|
15
|
+
* @param payload - The message payload to send
|
|
16
|
+
*/
|
|
17
|
+
sendToConnection?: (payload: any) => Promise<void> | void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Handler for stale or expired token messages
|
|
21
|
+
* Processes metadata messages indicating token refresh is required
|
|
22
|
+
*/
|
|
23
|
+
export declare class TokenRefreshHandler extends BaseMessageHandler {
|
|
24
|
+
private getAccessToken?;
|
|
25
|
+
private sendToConnection?;
|
|
26
|
+
constructor(options?: TokenRefreshHandlerOptions);
|
|
27
|
+
canHandle(message: Message): boolean;
|
|
28
|
+
handle(message: Message): Promise<MessageHandlerResult>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=TokenRefreshHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenRefreshHandler.d.ts","sourceRoot":"","sources":["../../../../src/core/message/handlers/TokenRefreshHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAGnD;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IAEvC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAC3D;AAED;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,kBAAkB;IACzD,OAAO,CAAC,cAAc,CAAC,CAAwB;IAC/C,OAAO,CAAC,gBAAgB,CAAC,CAAyC;gBAEtD,OAAO,CAAC,EAAE,0BAA0B;IAMhD,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO;IAiB9B,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,oBAAoB,CAAC;CAmE9D"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { BaseMessageHandler } from '../BaseMessageHandler.js';
|
|
2
|
+
import { PERSONA, ROLE, ERROR_CODES } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Handler for stale or expired token messages
|
|
5
|
+
* Processes metadata messages indicating token refresh is required
|
|
6
|
+
*/
|
|
7
|
+
export class TokenRefreshHandler extends BaseMessageHandler {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
super();
|
|
10
|
+
this.getAccessToken = options?.getAccessToken;
|
|
11
|
+
this.sendToConnection = options?.sendToConnection;
|
|
12
|
+
}
|
|
13
|
+
canHandle(message) {
|
|
14
|
+
if (message.persona !== PERSONA.METADATA) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
const isStaleToken = message.role === ROLE.STALE_TOKEN &&
|
|
18
|
+
message.messageData?.error_code === ERROR_CODES.STALE_TOKEN;
|
|
19
|
+
const isExpiredToken = message.role === ROLE.EXPIRED_TOKEN &&
|
|
20
|
+
(message.messageData?.error_code?.indexOf(ERROR_CODES.UNAUTHORIZED_PREFIX) === 0 ||
|
|
21
|
+
message.messageData?.error_code?.indexOf(ERROR_CODES.FORBIDDEN_PREFIX) === 0);
|
|
22
|
+
return isStaleToken || isExpiredToken;
|
|
23
|
+
}
|
|
24
|
+
async handle(message) {
|
|
25
|
+
const sessionId = message.sessionId;
|
|
26
|
+
const agentId = message.agentId;
|
|
27
|
+
const errorCode = message.messageData?.error_code;
|
|
28
|
+
// Build from object - metadata/system is the sender
|
|
29
|
+
const from = {
|
|
30
|
+
name: message.from || 'System',
|
|
31
|
+
isAi: false,
|
|
32
|
+
};
|
|
33
|
+
// Build to object - customer/client is the recipient
|
|
34
|
+
const to = {
|
|
35
|
+
name: message.to || 'Client',
|
|
36
|
+
isAi: false,
|
|
37
|
+
};
|
|
38
|
+
// Build message object with persona, role, content, and raw data
|
|
39
|
+
const messageObj = {
|
|
40
|
+
persona: message.persona,
|
|
41
|
+
role: message.role,
|
|
42
|
+
content: message.content,
|
|
43
|
+
raw: message.messageData || {},
|
|
44
|
+
errorCode,
|
|
45
|
+
};
|
|
46
|
+
// Build result in the required format
|
|
47
|
+
const result = {
|
|
48
|
+
type: 'token_refresh_required',
|
|
49
|
+
messageId: message.messageId,
|
|
50
|
+
timestamp: message.timestamp || Date.now(),
|
|
51
|
+
sessionId: sessionId,
|
|
52
|
+
agentId: agentId,
|
|
53
|
+
from: from,
|
|
54
|
+
to: to,
|
|
55
|
+
message: messageObj,
|
|
56
|
+
role: message.role,
|
|
57
|
+
errorCode,
|
|
58
|
+
};
|
|
59
|
+
// If callbacks are provided, perform the token refresh automatically
|
|
60
|
+
if (this.getAccessToken && this.sendToConnection) {
|
|
61
|
+
try {
|
|
62
|
+
const authToken = await this.getAccessToken();
|
|
63
|
+
const payload = {
|
|
64
|
+
persona: PERSONA.METADATA,
|
|
65
|
+
role: ROLE.TOKEN,
|
|
66
|
+
messageData: {
|
|
67
|
+
token: authToken,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
await this.sendToConnection(payload);
|
|
71
|
+
// Update result to indicate refresh was successful
|
|
72
|
+
result.type = 'token_refreshed';
|
|
73
|
+
result.tokenRefreshed = true;
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
// Update result to indicate refresh failed
|
|
77
|
+
result.type = 'token_refresh_failed';
|
|
78
|
+
result.tokenRefreshError = error instanceof Error ? error.message : String(error);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=TokenRefreshHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenRefreshHandler.js","sourceRoot":"","sources":["../../../../src/core/message/handlers/TokenRefreshHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAG9D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAmBzD;;;GAGG;AACH,MAAM,OAAO,mBAAoB,SAAQ,kBAAkB;IAIzD,YAAY,OAAoC;QAC9C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,cAAc,GAAG,OAAO,EAAE,cAAc,CAAC;QAC9C,IAAI,CAAC,gBAAgB,GAAG,OAAO,EAAE,gBAAgB,CAAC;IACpD,CAAC;IAED,SAAS,CAAC,OAAgB;QACxB,IAAI,OAAO,CAAC,OAAO,KAAK,OAAO,CAAC,QAAQ,EAAE,CAAC;YACzC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,YAAY,GAChB,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC,WAAW;YACjC,OAAO,CAAC,WAAW,E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AAE,OAAO;YAChB,IAAI,EAAE,IAAI;YACV,EAAE,EAAE,EAAE;YACN,OAAO,EAAE,UAAU;YACnB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,SAAS;SACV,CAAC;QAEF,qEAAqE;QACrE,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACjD,IAAI,CAAC;gBACH,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;gBAE9C,MAAM,OAAO,GAAG;oBACd,OAAO,EAAE,OAAO,CAAC,QAAQ;oBACzB,IAAI,EAAE,IAAI,CAAC,KAAK;oBAChB,WAAW,EAAE;wBACX,KAAK,EAAE,SAAS;qBACjB;iBACF,CAAC;gBAEF,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;gBAErC,mDAAmD;gBACnD,MAAM,CAAC,IAAI,GAAG,iBAAiB,CAAC;gBAC/B,MAAc,CAAC,cAAc,GAAG,IAAI,CAAC;YACxC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,2CAA2C;gBAC3C,MAAM,CAAC,IAAI,GAAG,sBAAsB,CAAC;gBACpC,MAAc,CAAC,iBAAiB,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC7F,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message type constants
|
|
3
|
+
*/
|
|
4
|
+
export declare const PERSONA: Readonly<{
|
|
5
|
+
readonly METADATA: "metadata";
|
|
6
|
+
readonly SYSTEM: "system";
|
|
7
|
+
readonly AGENT: "agent";
|
|
8
|
+
readonly CUSTOMER: "customer";
|
|
9
|
+
}>;
|
|
10
|
+
export declare const ROLE: Readonly<{
|
|
11
|
+
readonly STALE_TOKEN: "stale_token";
|
|
12
|
+
readonly EXPIRED_TOKEN: "expired_token";
|
|
13
|
+
readonly TOKEN: "token";
|
|
14
|
+
readonly CHAT_HISTORY: "chat history";
|
|
15
|
+
readonly ERROR: "error";
|
|
16
|
+
readonly HEARTBEAT: "heartbeat";
|
|
17
|
+
readonly FOLLOW_UP_QUESTION: "follow up question agent";
|
|
18
|
+
readonly CUSTOMER_SUPPORT: "customer support agent";
|
|
19
|
+
readonly CONTEXT: "context";
|
|
20
|
+
readonly GRACEFUL_DISCONNECT: "graceful disconnect";
|
|
21
|
+
readonly ESCALATION: "escalation";
|
|
22
|
+
readonly FEEDBACK: "feedback";
|
|
23
|
+
readonly HUMAN: "human";
|
|
24
|
+
}>;
|
|
25
|
+
export declare const ERROR_CODES: Readonly<{
|
|
26
|
+
readonly STALE_TOKEN: "401-012";
|
|
27
|
+
readonly UNAUTHORIZED_PREFIX: "401";
|
|
28
|
+
readonly FORBIDDEN_PREFIX: "403";
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Type definitions for persona values
|
|
32
|
+
*/
|
|
33
|
+
export type Persona = typeof PERSONA[keyof typeof PERSONA];
|
|
34
|
+
/**
|
|
35
|
+
* Type definitions for role values
|
|
36
|
+
*/
|
|
37
|
+
export type Role = typeof ROLE[keyof typeof ROLE];
|
|
38
|
+
/**
|
|
39
|
+
* Message data structure
|
|
40
|
+
*/
|
|
41
|
+
export interface MessageData {
|
|
42
|
+
[key: string]: any;
|
|
43
|
+
error_code?: string;
|
|
44
|
+
chat_history?: any[];
|
|
45
|
+
options?: string[];
|
|
46
|
+
escalation?: boolean;
|
|
47
|
+
escalationData?: {
|
|
48
|
+
live?: boolean;
|
|
49
|
+
phone?: boolean;
|
|
50
|
+
phoneNumber?: string;
|
|
51
|
+
sms?: boolean;
|
|
52
|
+
smsNumber?: string;
|
|
53
|
+
email?: boolean;
|
|
54
|
+
};
|
|
55
|
+
sources?: any[];
|
|
56
|
+
reasoning?: string;
|
|
57
|
+
context?: object;
|
|
58
|
+
feedback?: {
|
|
59
|
+
rating: any;
|
|
60
|
+
answerMessageId: string;
|
|
61
|
+
};
|
|
62
|
+
escalationEvent?: any;
|
|
63
|
+
token?: string;
|
|
64
|
+
workflowType?: "preChatWorkflow" | "escalationWorkflow" | "agentWorkflow" | null;
|
|
65
|
+
workflowNodeType?: string | null;
|
|
66
|
+
inputType?: string | null;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Result returned by message handlers
|
|
70
|
+
*/
|
|
71
|
+
export interface MessageHandlerResult {
|
|
72
|
+
type: string;
|
|
73
|
+
messageId?: string | number;
|
|
74
|
+
timestamp: number;
|
|
75
|
+
sessionId?: string | number;
|
|
76
|
+
agentId?: string | number;
|
|
77
|
+
from: {
|
|
78
|
+
name: string;
|
|
79
|
+
isAi: boolean;
|
|
80
|
+
};
|
|
81
|
+
to: {
|
|
82
|
+
name: string;
|
|
83
|
+
isAi: boolean;
|
|
84
|
+
};
|
|
85
|
+
message: {
|
|
86
|
+
persona: string;
|
|
87
|
+
role: string;
|
|
88
|
+
content?: string;
|
|
89
|
+
raw: any;
|
|
90
|
+
escalationType?: string | null;
|
|
91
|
+
escalationData?: any;
|
|
92
|
+
sources?: any[];
|
|
93
|
+
reasoning?: string;
|
|
94
|
+
showReasoning?: boolean;
|
|
95
|
+
showFeedback?: boolean;
|
|
96
|
+
showOptions?: boolean;
|
|
97
|
+
};
|
|
98
|
+
isEscalation?: boolean;
|
|
99
|
+
[key: string]: any;
|
|
100
|
+
}
|
|
101
|
+
export interface SessionContext {
|
|
102
|
+
agentId: string;
|
|
103
|
+
sessionId: string;
|
|
104
|
+
customerName: string;
|
|
105
|
+
agentName: string;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/message/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAA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|
+
METADATA: "metadata",
|
|
6
|
+
SYSTEM: "system",
|
|
7
|
+
AGENT: "agent",
|
|
8
|
+
CUSTOMER: "customer",
|
|
9
|
+
});
|
|
10
|
+
export const ROLE = Object.freeze({
|
|
11
|
+
STALE_TOKEN: "stale_token",
|
|
12
|
+
EXPIRED_TOKEN: "expired_token",
|
|
13
|
+
TOKEN: "token",
|
|
14
|
+
CHAT_HISTORY: "chat history",
|
|
15
|
+
ERROR: "error",
|
|
16
|
+
HEARTBEAT: "heartbeat",
|
|
17
|
+
FOLLOW_UP_QUESTION: "follow up question agent",
|
|
18
|
+
CUSTOMER_SUPPORT: "customer support agent",
|
|
19
|
+
CONTEXT: "context",
|
|
20
|
+
GRACEFUL_DISCONNECT: "graceful disconnect",
|
|
21
|
+
ESCALATION: "escalation",
|
|
22
|
+
FEEDBACK: "feedback",
|
|
23
|
+
HUMAN: "human",
|
|
24
|
+
});
|
|
25
|
+
export const ERROR_CODES = Object.freeze({
|
|
26
|
+
STALE_TOKEN: "401-012",
|
|
27
|
+
UNAUTHORIZED_PREFIX: "401",
|
|
28
|
+
FORBIDDEN_PREFIX: "403",
|
|
29
|
+
});
|
|
30
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/message/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;IACnC,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,OAAO;IACd,QAAQ,EAAE,UAAU;CACZ,CAAC,CAAC;AAEZ,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC;IAChC,WAAW,EAAE,aAAa;IAC1B,aAAa,EAAE,eAAe;IAC9B,KAAK,EAAE,OAAO;IACd,YAAY,EAAE,cAAc;IAC5B,KAAK,EAAE,OAAO;IACd,SAAS,EAAE,WAAW;IACtB,kBAAkB,EAAE,0BAA0B;IAC9C,gBAAgB,EAAE,wBAAwB;IAC1C,OAAO,EAAE,SAAS;IAClB,mBAAmB,EAAE,qBAAqB;IAC1C,UAAU,EAAE,YAAY;IACxB,QAAQ,EAAE,UAAU;IACpB,KAAK,EAAE,OAAO;CACN,CAAC,CAAC;AAEZ,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC;IACvC,WAAW,EAAE,SAAS;IACtB,mBAAmB,EAAE,KAAK;IAC1B,gBAAgB,EAAE,KAAK;CACf,CAAC,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bidirectional facade between the SDK and platform connector scripts.
|
|
3
|
+
*
|
|
4
|
+
* The SDK builds an implementation internally (closing over `AiAgent` state)
|
|
5
|
+
* and passes it to the connector via `PlatformComponentService.setHookContract()`.
|
|
6
|
+
* Connector authors can type their code against these interfaces.
|
|
7
|
+
*
|
|
8
|
+
* **Not intended for SDK consumers** — only for platform connector authors.
|
|
9
|
+
*
|
|
10
|
+
* @module HookContract
|
|
11
|
+
*/
|
|
12
|
+
import type { Portal } from '../types/PortalTypes.js';
|
|
13
|
+
/**
|
|
14
|
+
* A single entry in the call transcript — the live customer-agent
|
|
15
|
+
* conversation on the telephony platform (Genesys, Amazon Connect, etc.).
|
|
16
|
+
*
|
|
17
|
+
* This is distinct from the AiAgent chat transcript (`Transcript` /
|
|
18
|
+
* `TranscriptEntry`), which tracks WebSocket messages between the SDK
|
|
19
|
+
* and the AI Agent backend.
|
|
20
|
+
*/
|
|
21
|
+
export interface CallTranscriptEntry {
|
|
22
|
+
sender: string;
|
|
23
|
+
content: string;
|
|
24
|
+
timestamp: Date;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Caller information pushed by the platform connector.
|
|
28
|
+
*/
|
|
29
|
+
export interface CallerInfo {
|
|
30
|
+
name?: string;
|
|
31
|
+
phone?: string;
|
|
32
|
+
email?: string;
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Bidirectional contract between the SDK and a platform connector script.
|
|
37
|
+
*
|
|
38
|
+
* Read-only getters return live state (not stale snapshots) because the
|
|
39
|
+
* implementation closes over the `AiAgent` instance.
|
|
40
|
+
*/
|
|
41
|
+
export interface HookContract {
|
|
42
|
+
/** Returns the current call transcript entries (telephony conversation, not AI chat). */
|
|
43
|
+
getTranscript: () => CallTranscriptEntry[];
|
|
44
|
+
/** Returns a shallow copy of the initialization parameters. */
|
|
45
|
+
getInitParams: () => Record<string, string>;
|
|
46
|
+
/** Returns the agent details object. */
|
|
47
|
+
getAgentDetails: () => any;
|
|
48
|
+
/** Returns the current MSAL/auth access token. */
|
|
49
|
+
getMsalAccessToken: () => Promise<string | null>;
|
|
50
|
+
/** Returns the deployment info object. */
|
|
51
|
+
getDeploymentInfo: () => any;
|
|
52
|
+
/** Returns the platform type string (e.g. "genesys"). */
|
|
53
|
+
getPlatformType: () => string | null;
|
|
54
|
+
/** Returns the deployment environment ("dev" | "qa" | "prod"). */
|
|
55
|
+
getEnvironment: () => string;
|
|
56
|
+
/** Returns the user ID from init params. */
|
|
57
|
+
getUserId: () => string | null;
|
|
58
|
+
/** Returns the user context object. */
|
|
59
|
+
getUserContext: () => Record<string, unknown> | null;
|
|
60
|
+
/** Returns the conversation ID set by the connector. */
|
|
61
|
+
getConversationId: () => string | null;
|
|
62
|
+
/**
|
|
63
|
+
* Returns effective OAuth resource scopes for the auth flow: after the platform connector runs,
|
|
64
|
+
* the merged list in `config.scopes` wins; otherwise non-empty `initParams.scopes` (comma-separated)
|
|
65
|
+
* overrides `config.scopes`, then defaults (including `core.customermgr.read` for customer when
|
|
66
|
+
* neither query nor config supplies scopes).
|
|
67
|
+
*/
|
|
68
|
+
getAuthScopes: () => string[];
|
|
69
|
+
/** Returns the tenant ID from deployment info. */
|
|
70
|
+
getTenantId: () => string | null;
|
|
71
|
+
/** Returns the currently selected portal, or null before selection. */
|
|
72
|
+
getSelectedPortal: () => Portal | null;
|
|
73
|
+
/** Returns the caller info set by the connector. */
|
|
74
|
+
getCallerInfo: () => CallerInfo | null;
|
|
75
|
+
/** Add an entry to the call transcript (telephony conversation, not AI chat). */
|
|
76
|
+
addToTranscript: (entry: {
|
|
77
|
+
sender: string;
|
|
78
|
+
content: string;
|
|
79
|
+
timestamp?: Date;
|
|
80
|
+
}) => void;
|
|
81
|
+
/** Set caller information (e.g. from CTI integration). */
|
|
82
|
+
setCallerInfo: (callerInfo: CallerInfo) => void;
|
|
83
|
+
/** Mark the platform as authenticated. */
|
|
84
|
+
setPlatformAuthenticated: (value: boolean) => void;
|
|
85
|
+
/** Store a secondary platform-specific token. */
|
|
86
|
+
setPlatformToken: (token: string) => void;
|
|
87
|
+
/** Set the conversation/interaction ID. */
|
|
88
|
+
setConversationId: (id: string) => void;
|
|
89
|
+
/** Append to the user context (merge, not overwrite). */
|
|
90
|
+
setUserContext: (userContext: Record<string, unknown>) => void;
|
|
91
|
+
/** Set filter tags for portal content filtering. */
|
|
92
|
+
setUserFilterTags: (filterTags: Record<string, string[]>) => void;
|
|
93
|
+
/** Subscribe to agent widget actions. Returns an unsubscribe function. */
|
|
94
|
+
subscribeToAgentWidgetActions: (callback: (action: string, data: unknown) => void) => () => void;
|
|
95
|
+
/** Forward a user message through the SDK's send pipeline. */
|
|
96
|
+
onUserMessage: (message: string) => void;
|
|
97
|
+
/** Handle a source click from the connector. */
|
|
98
|
+
onSourceClick: (source: {
|
|
99
|
+
id: string;
|
|
100
|
+
title: string;
|
|
101
|
+
url?: string;
|
|
102
|
+
[key: string]: unknown;
|
|
103
|
+
}) => void;
|
|
104
|
+
/** Handle an intent confirmation from the connector. */
|
|
105
|
+
onIntentConfirm: (intent: {
|
|
106
|
+
id: string;
|
|
107
|
+
intent: string;
|
|
108
|
+
confidence: number;
|
|
109
|
+
[key: string]: unknown;
|
|
110
|
+
}) => void;
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=HookContract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HookContract.d.ts","sourceRoot":"","sources":["../../../src/core/platform/HookContract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD;;;;;;;GAOG;AACH,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAG3B,yFAAyF;IACzF,aAAa,EAAE,MAAM,mBAAmB,EAAE,CAAC;IAE3C,+DAA+D;IAC/D,aAAa,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE5C,wCAAwC;IACxC,eAAe,EAAE,MAAM,GAAG,CAAC;IAE3B,kDAAkD;IAClD,kBAAkB,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAEjD,0CAA0C;IAC1C,iBAAiB,EAAE,MAAM,GAAG,CAAC;IAE7B,yDAAyD;IACzD,eAAe,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IAErC,kEAAkE;IAClE,cAAc,EAAE,MAAM,MAAM,CAAC;IAE7B,4CAA4C;IAC5C,SAAS,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IAE/B,uCAAuC;IACvC,cAAc,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAErD,wDAAwD;IACx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AgD;IAChD,aAAa,EAAE,CAAC,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IAErG,wDAAwD;IACxD,eAAe,EAAE,CAAC,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;CAC/G"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bidirectional facade between the SDK and platform connector scripts.
|
|
3
|
+
*
|
|
4
|
+
* The SDK builds an implementation internally (closing over `AiAgent` state)
|
|
5
|
+
* and passes it to the connector via `PlatformComponentService.setHookContract()`.
|
|
6
|
+
* Connector authors can type their code against these interfaces.
|
|
7
|
+
*
|
|
8
|
+
* **Not intended for SDK consumers** — only for platform connector authors.
|
|
9
|
+
*
|
|
10
|
+
* @module HookContract
|
|
11
|
+
*/
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=HookContract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HookContract.js","sourceRoot":"","sources":["../../../src/core/platform/HookContract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for platform-specific connector scripts (Genesys, Amazon Connect, etc.).
|
|
3
|
+
*
|
|
4
|
+
* Connector scripts register an implementation of this interface on
|
|
5
|
+
* `window.PlatformComponentService` (browser) or `globalThis.PlatformComponentService`
|
|
6
|
+
* (non-browser). The SDK calls these methods at defined lifecycle points
|
|
7
|
+
* during initialization.
|
|
8
|
+
*
|
|
9
|
+
* @module PlatformComponentService
|
|
10
|
+
*/
|
|
11
|
+
import type { HookContract } from './HookContract.js';
|
|
12
|
+
import type { Portal } from '../types/PortalTypes.js';
|
|
13
|
+
/**
|
|
14
|
+
* Contract that platform connector scripts must implement.
|
|
15
|
+
*
|
|
16
|
+
* All methods except `initPlatform` are optional — the SDK calls them
|
|
17
|
+
* when present and silently skips them when absent.
|
|
18
|
+
*/
|
|
19
|
+
export interface PlatformComponentService {
|
|
20
|
+
/** Main connector initialization (e.g., connecting to Genesys/NICE). Called after authentication, before the CC pipeline starts. */
|
|
21
|
+
initPlatform: (hookContract: HookContract) => Promise<void>;
|
|
22
|
+
/** Filter or reorder the portal list after fetching. */
|
|
23
|
+
getPortalList?: (filteredPortals: Portal[]) => Portal[] | Promise<Portal[]>;
|
|
24
|
+
/** Auto-select a default portal. Receives the output of `getPortalList`. Return `null` to fall through to count-based logic. */
|
|
25
|
+
getDefaultPortal?: (portalList: Portal[]) => Portal | null | Promise<Portal | null>;
|
|
26
|
+
/** Called after a portal is selected. Returns filter tags (`Record<string, string[]>`) stored via `setUserFilterTags`. */
|
|
27
|
+
onPortalSelected?: (portal: Portal) => Record<string, string[]> | Promise<Record<string, string[]>>;
|
|
28
|
+
/** Modify OAuth scopes before authentication. Returns the augmented scopes array. */
|
|
29
|
+
addCustomAuthScopes?: (scopes: string[]) => string[] | Promise<string[]>;
|
|
30
|
+
/** Register custom hooks on the HookContract. */
|
|
31
|
+
loadCustomHook?: (hookContract: HookContract) => void;
|
|
32
|
+
/** Receive the HookContract for bidirectional communication with the SDK. */
|
|
33
|
+
setHookContract?: (hookContract: HookContract) => void;
|
|
34
|
+
}
|
|
35
|
+
declare global {
|
|
36
|
+
interface Window {
|
|
37
|
+
PlatformComponentService?: PlatformComponentService;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=PlatformComponentService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlatformComponentService.d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
/**
|
|
2
|
+
* Interface for platform-specific connector scripts (Genesys, Amazon Connect, etc.).
|
|
3
|
+
*
|
|
4
|
+
* Connector scripts register an implementation of this interface on
|
|
5
|
+
* `window.PlatformComponentService` (browser) or `globalThis.PlatformComponentService`
|
|
6
|
+
* (non-browser). The SDK calls these methods at defined lifecycle points
|
|
7
|
+
* during initialization.
|
|
8
|
+
*
|
|
9
|
+
* @module PlatformComponentService
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=PlatformComponentService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlatformComponentService.js","sourceRoot":"","sources":["../../../src/core/platform/PlatformComponentService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dynamic loader for platform connector scripts.
|
|
3
|
+
*
|
|
4
|
+
* In browser environments, injects a `<script>` tag. In non-browser
|
|
5
|
+
* environments (Node.js, SSR), falls back to dynamic `import()` using
|
|
6
|
+
* the same constructed URL.
|
|
7
|
+
*
|
|
8
|
+
* @module PlatformScriptLoader
|
|
9
|
+
*/
|
|
10
|
+
export interface LoadPlatformScriptOptions {
|
|
11
|
+
platform: string;
|
|
12
|
+
baseUrl: string;
|
|
13
|
+
overrideUrl?: string;
|
|
14
|
+
logger: {
|
|
15
|
+
debug: (msg: string, ctx?: object) => void;
|
|
16
|
+
info: (msg: string, ctx?: object) => void;
|
|
17
|
+
warn: (msg: string, ctx?: object) => void;
|
|
18
|
+
error: (msg: string, err?: Error, ctx?: object) => void;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Derive the deployment environment from available state.
|
|
23
|
+
*
|
|
24
|
+
* Priority: explicit env string > parsed from domain (dev-/qa- prefix) > "prod".
|
|
25
|
+
*/
|
|
26
|
+
export declare function deriveEnvironment(domain?: string, explicitEnv?: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Construct the connector script URL for a given platform and environment.
|
|
29
|
+
*/
|
|
30
|
+
export declare function buildPlatformScriptUrl(platform: string, environment: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Load a platform connector script.
|
|
33
|
+
*
|
|
34
|
+
* - **Browser:** Injects a `<script>` tag into `document.head`, waits for
|
|
35
|
+
* `onload` + 100ms buffer, then verifies `window.PlatformComponentService`.
|
|
36
|
+
* - **Non-browser:** Uses dynamic `import()` with the same constructed URL.
|
|
37
|
+
* The imported module must export `PlatformComponentService` as a default
|
|
38
|
+
* or named export.
|
|
39
|
+
*/
|
|
40
|
+
export declare function loadPlatformScript(options: LoadPlatformScriptOptions): Promise<void>;
|
|
41
|
+
//# sourceMappingURL=PlatformScriptLoader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlatformScriptLoader.d.ts","sourceRoot":"","sources":["../../../src/core/platform/PlatformScriptLoader.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,MAAM,WAAW,yBAAyB;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE;QACN,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;QAC3C,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;QAC1C,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;QAC1C,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;KACzD,CAAC;CACH;AAYD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAW/E;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAGpF;AAED;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC,CAW1F"}
|