@webex/contact-center 3.12.0-next.73 → 3.12.0-next.74
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/AGENTS.md +438 -0
- package/ai-docs/README.md +131 -0
- package/ai-docs/RULES.md +455 -0
- package/ai-docs/patterns/event-driven-patterns.md +485 -0
- package/ai-docs/patterns/testing-patterns.md +480 -0
- package/ai-docs/patterns/typescript-patterns.md +365 -0
- package/ai-docs/templates/README.md +102 -0
- package/ai-docs/templates/documentation/create-agents-md.md +240 -0
- package/ai-docs/templates/documentation/create-architecture-md.md +295 -0
- package/ai-docs/templates/existing-service/bug-fix.md +254 -0
- package/ai-docs/templates/existing-service/feature-enhancement.md +450 -0
- package/ai-docs/templates/new-method/00-master.md +80 -0
- package/ai-docs/templates/new-method/01-requirements.md +232 -0
- package/ai-docs/templates/new-method/02-implementation.md +295 -0
- package/ai-docs/templates/new-method/03-tests.md +201 -0
- package/ai-docs/templates/new-method/04-validation.md +141 -0
- package/ai-docs/templates/new-service/00-master.md +109 -0
- package/ai-docs/templates/new-service/01-pre-questions.md +159 -0
- package/ai-docs/templates/new-service/02-code-generation.md +346 -0
- package/ai-docs/templates/new-service/03-integration.md +178 -0
- package/ai-docs/templates/new-service/04-test-generation.md +205 -0
- package/ai-docs/templates/new-service/05-validation.md +145 -0
- package/dist/cc.js +53 -38
- package/dist/cc.js.map +1 -1
- package/dist/config.js +6 -0
- package/dist/config.js.map +1 -1
- package/dist/constants.js +14 -1
- package/dist/constants.js.map +1 -1
- package/dist/index.js +13 -5
- package/dist/index.js.map +1 -1
- package/dist/metrics/behavioral-events.js +26 -0
- package/dist/metrics/behavioral-events.js.map +1 -1
- package/dist/metrics/constants.js +9 -3
- package/dist/metrics/constants.js.map +1 -1
- package/dist/services/ApiAiAssistant.js +74 -3
- package/dist/services/ApiAiAssistant.js.map +1 -1
- package/dist/services/config/Util.js +2 -2
- package/dist/services/config/Util.js.map +1 -1
- package/dist/services/config/types.js +25 -9
- package/dist/services/config/types.js.map +1 -1
- package/dist/services/core/Utils.js +74 -27
- package/dist/services/core/Utils.js.map +1 -1
- package/dist/services/core/websocket/WebSocketManager.js +2 -1
- package/dist/services/core/websocket/WebSocketManager.js.map +1 -1
- package/dist/services/core/websocket/types.js.map +1 -1
- package/dist/services/index.js +1 -1
- package/dist/services/index.js.map +1 -1
- package/dist/services/task/Task.js +688 -0
- package/dist/services/task/Task.js.map +1 -0
- package/dist/services/task/TaskFactory.js +45 -0
- package/dist/services/task/TaskFactory.js.map +1 -0
- package/dist/services/task/TaskManager.js +725 -612
- package/dist/services/task/TaskManager.js.map +1 -1
- package/dist/services/task/TaskUtils.js +162 -26
- package/dist/services/task/TaskUtils.js.map +1 -1
- package/dist/services/task/constants.js +6 -1
- package/dist/services/task/constants.js.map +1 -1
- package/dist/services/task/digital/Digital.js +77 -0
- package/dist/services/task/digital/Digital.js.map +1 -0
- package/dist/services/task/state-machine/TaskStateMachine.js +837 -0
- package/dist/services/task/state-machine/TaskStateMachine.js.map +1 -0
- package/dist/services/task/state-machine/actions.js +543 -0
- package/dist/services/task/state-machine/actions.js.map +1 -0
- package/dist/services/task/state-machine/constants.js +161 -0
- package/dist/services/task/state-machine/constants.js.map +1 -0
- package/dist/services/task/state-machine/guards.js +340 -0
- package/dist/services/task/state-machine/guards.js.map +1 -0
- package/dist/services/task/state-machine/index.js +53 -0
- package/dist/services/task/state-machine/index.js.map +1 -0
- package/dist/services/task/state-machine/types.js +54 -0
- package/dist/services/task/state-machine/types.js.map +1 -0
- package/dist/services/task/state-machine/uiControlsComputer.js +553 -0
- package/dist/services/task/state-machine/uiControlsComputer.js.map +1 -0
- package/dist/services/task/taskDataNormalizer.js +99 -0
- package/dist/services/task/taskDataNormalizer.js.map +1 -0
- package/dist/services/task/types.js +168 -16
- package/dist/services/task/types.js.map +1 -1
- package/dist/services/task/voice/Voice.js +1042 -0
- package/dist/services/task/voice/Voice.js.map +1 -0
- package/dist/services/task/voice/WebRTC.js +149 -0
- package/dist/services/task/voice/WebRTC.js.map +1 -0
- package/dist/types/cc.d.ts +19 -18
- package/dist/types/config.d.ts +6 -0
- package/dist/types/constants.d.ts +14 -1
- package/dist/types/index.d.ts +11 -5
- package/dist/types/metrics/constants.d.ts +7 -1
- package/dist/types/services/ApiAiAssistant.d.ts +11 -3
- package/dist/types/services/config/types.d.ts +113 -9
- package/dist/types/services/core/Utils.d.ts +23 -10
- package/dist/types/services/core/websocket/WebSocketManager.d.ts +1 -0
- package/dist/types/services/core/websocket/types.d.ts +1 -1
- package/dist/types/services/index.d.ts +1 -1
- package/dist/types/services/task/Task.d.ts +157 -0
- package/dist/types/services/task/TaskFactory.d.ts +12 -0
- package/dist/types/services/task/TaskUtils.d.ts +46 -2
- package/dist/types/services/task/constants.d.ts +5 -0
- package/dist/types/services/task/digital/Digital.d.ts +22 -0
- package/dist/types/services/task/state-machine/TaskStateMachine.d.ts +1144 -0
- package/dist/types/services/task/state-machine/actions.d.ts +10 -0
- package/dist/types/services/task/state-machine/constants.d.ts +107 -0
- package/dist/types/services/task/state-machine/guards.d.ts +90 -0
- package/dist/types/services/task/state-machine/index.d.ts +13 -0
- package/dist/types/services/task/state-machine/types.d.ts +267 -0
- package/dist/types/services/task/state-machine/uiControlsComputer.d.ts +9 -0
- package/dist/types/services/task/taskDataNormalizer.d.ts +10 -0
- package/dist/types/services/task/types.d.ts +551 -78
- package/dist/types/services/task/voice/Voice.d.ts +184 -0
- package/dist/types/services/task/voice/WebRTC.d.ts +53 -0
- package/dist/types/types.d.ts +92 -0
- package/dist/types/webex.d.ts +1 -0
- package/dist/types.js +85 -0
- package/dist/types.js.map +1 -1
- package/dist/webex.js +14 -2
- package/dist/webex.js.map +1 -1
- package/package.json +15 -12
- package/src/cc.ts +63 -43
- package/src/config.ts +6 -0
- package/src/constants.ts +14 -1
- package/src/index.ts +14 -5
- package/src/metrics/ai-docs/AGENTS.md +348 -0
- package/src/metrics/ai-docs/ARCHITECTURE.md +336 -0
- package/src/metrics/behavioral-events.ts +28 -0
- package/src/metrics/constants.ts +9 -4
- package/src/services/ApiAiAssistant.ts +104 -3
- package/src/services/agent/ai-docs/AGENTS.md +238 -0
- package/src/services/agent/ai-docs/ARCHITECTURE.md +302 -0
- package/src/services/ai-docs/AGENTS.md +384 -0
- package/src/services/config/Util.ts +2 -2
- package/src/services/config/ai-docs/AGENTS.md +253 -0
- package/src/services/config/ai-docs/ARCHITECTURE.md +424 -0
- package/src/services/config/types.ts +116 -10
- package/src/services/core/Utils.ts +85 -34
- package/src/services/core/ai-docs/AGENTS.md +379 -0
- package/src/services/core/ai-docs/ARCHITECTURE.md +696 -0
- package/src/services/core/websocket/WebSocketManager.ts +2 -0
- package/src/services/core/websocket/types.ts +1 -1
- package/src/services/index.ts +1 -1
- package/src/services/task/Task.ts +837 -0
- package/src/services/task/TaskFactory.ts +55 -0
- package/src/services/task/TaskManager.ts +738 -697
- package/src/services/task/TaskUtils.ts +205 -25
- package/src/services/task/ai-docs/AGENTS.md +455 -0
- package/src/services/task/ai-docs/ARCHITECTURE.md +585 -0
- package/src/services/task/constants.ts +5 -0
- package/src/services/task/digital/Digital.ts +95 -0
- package/src/services/task/state-machine/TaskStateMachine.ts +1077 -0
- package/src/services/task/state-machine/actions.ts +685 -0
- package/src/services/task/state-machine/ai-docs/AGENTS.md +495 -0
- package/src/services/task/state-machine/ai-docs/ARCHITECTURE.md +1135 -0
- package/src/services/task/state-machine/constants.ts +172 -0
- package/src/services/task/state-machine/guards.ts +406 -0
- package/src/services/task/state-machine/index.ts +28 -0
- package/src/services/task/state-machine/types.ts +241 -0
- package/src/services/task/state-machine/uiControlsComputer.ts +867 -0
- package/src/services/task/taskDataNormalizer.ts +137 -0
- package/src/services/task/types.ts +654 -85
- package/src/services/task/voice/Voice.ts +1267 -0
- package/src/services/task/voice/WebRTC.ts +187 -0
- package/src/types.ts +112 -1
- package/src/utils/AGENTS.md +276 -0
- package/src/webex.js +2 -0
- package/test/unit/spec/cc.ts +133 -3
- package/test/unit/spec/logger-proxy.ts +70 -0
- package/test/unit/spec/services/ApiAiAssistant.ts +122 -17
- package/test/unit/spec/services/WebCallingService.ts +7 -1
- package/test/unit/spec/services/config/index.ts +27 -27
- package/test/unit/spec/services/core/Utils.ts +335 -1
- package/test/unit/spec/services/core/websocket/WebSocketManager.ts +66 -40
- package/test/unit/spec/services/task/AutoWrapup.ts +63 -0
- package/test/unit/spec/services/task/Task.ts +477 -0
- package/test/unit/spec/services/task/TaskFactory.ts +62 -0
- package/test/unit/spec/services/task/TaskManager.ts +821 -1936
- package/test/unit/spec/services/task/TaskUtils.ts +206 -0
- package/test/unit/spec/services/task/digital/Digital.ts +105 -0
- package/test/unit/spec/services/task/state-machine/TaskStateMachine.ts +1825 -0
- package/test/unit/spec/services/task/state-machine/guards.ts +479 -0
- package/test/unit/spec/services/task/state-machine/types.ts +18 -0
- package/test/unit/spec/services/task/state-machine/uiControlsComputer.ts +2020 -0
- package/test/unit/spec/services/task/taskTestUtils.ts +87 -0
- package/test/unit/spec/services/task/voice/Voice.ts +631 -0
- package/test/unit/spec/services/task/voice/WebRTC.ts +235 -0
- package/umd/contact-center.min.js +2 -2
- package/umd/contact-center.min.js.map +1 -1
- package/dist/services/task/index.js +0 -1530
- package/dist/services/task/index.js.map +0 -1
- package/dist/types/services/task/index.d.ts +0 -650
- package/src/services/task/index.ts +0 -1806
- package/test/unit/spec/services/task/index.ts +0 -2205
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import {LocalMicrophoneStream, CALL_EVENT_KEYS} from '@webex/calling';
|
|
2
|
+
import {CC_FILE} from '../../../constants';
|
|
3
|
+
import {getErrorDetails} from '../../core/Utils';
|
|
4
|
+
import routingContact from '../contact';
|
|
5
|
+
import {
|
|
6
|
+
TaskData,
|
|
7
|
+
TaskResponse,
|
|
8
|
+
TASK_EVENTS,
|
|
9
|
+
IWebRTC,
|
|
10
|
+
VoiceUIControlOptions,
|
|
11
|
+
VOICE_VARIANT,
|
|
12
|
+
} from '../types';
|
|
13
|
+
import Voice from './Voice';
|
|
14
|
+
import WebCallingService from '../../WebCallingService';
|
|
15
|
+
import {WrapupData} from '../../config/types';
|
|
16
|
+
import MetricsManager from '../../../metrics/MetricsManager';
|
|
17
|
+
import {METRIC_EVENT_NAMES} from '../../../metrics/constants';
|
|
18
|
+
import LoggerProxy from '../../../logger-proxy';
|
|
19
|
+
|
|
20
|
+
export default class WebRTC extends Voice implements IWebRTC {
|
|
21
|
+
private localAudioStream: LocalMicrophoneStream;
|
|
22
|
+
private webCallingService: WebCallingService;
|
|
23
|
+
|
|
24
|
+
constructor(
|
|
25
|
+
contact: ReturnType<typeof routingContact>,
|
|
26
|
+
webCallingService: WebCallingService,
|
|
27
|
+
data: TaskData,
|
|
28
|
+
callOptions?: VoiceUIControlOptions,
|
|
29
|
+
wrapupData?: WrapupData,
|
|
30
|
+
agentId?: string
|
|
31
|
+
) {
|
|
32
|
+
const mergedCallOptions: VoiceUIControlOptions = {
|
|
33
|
+
...callOptions,
|
|
34
|
+
voiceVariant: VOICE_VARIANT.WEBRTC,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
super(contact, data, mergedCallOptions, wrapupData, agentId);
|
|
38
|
+
this.webCallingService = webCallingService;
|
|
39
|
+
this.registerWebCallListeners();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private registerWebCallListeners() {
|
|
43
|
+
this.webCallingService.on(CALL_EVENT_KEYS.REMOTE_MEDIA, this.handleRemoteMedia);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private handleRemoteMedia = (track: MediaStreamTrack) => {
|
|
47
|
+
this.emit(TASK_EVENTS.TASK_MEDIA, track);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* This method is used to unregister the web call listeners.
|
|
52
|
+
* @returns void
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* task.unregisterWebCallListeners();
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
public unregisterWebCallListeners() {
|
|
59
|
+
this.webCallingService.off(CALL_EVENT_KEYS.REMOTE_MEDIA, this.handleRemoteMedia);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* This is used for incoming task accept by agent.
|
|
64
|
+
*
|
|
65
|
+
* @returns Promise<TaskResponse>
|
|
66
|
+
* @throws Error
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* task.accept().then(()=>{}).catch(()=>{})
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
public async accept(): Promise<TaskResponse> {
|
|
73
|
+
LoggerProxy.log(`Accepting WebRTC task for taskId:${this.data.interactionId}`, {
|
|
74
|
+
module: 'WebRTC',
|
|
75
|
+
method: 'accept',
|
|
76
|
+
});
|
|
77
|
+
try {
|
|
78
|
+
this.metricsManager.timeEvent([
|
|
79
|
+
METRIC_EVENT_NAMES.TASK_ACCEPT_SUCCESS,
|
|
80
|
+
METRIC_EVENT_NAMES.TASK_ACCEPT_FAILED,
|
|
81
|
+
]);
|
|
82
|
+
|
|
83
|
+
const constraints = {audio: true};
|
|
84
|
+
const localStream = await navigator.mediaDevices.getUserMedia(constraints);
|
|
85
|
+
const audioTrack = localStream.getAudioTracks()[0];
|
|
86
|
+
this.localAudioStream = new LocalMicrophoneStream(new MediaStream([audioTrack]));
|
|
87
|
+
this.webCallingService.answerCall(this.localAudioStream, this.data.interactionId);
|
|
88
|
+
|
|
89
|
+
this.metricsManager.trackEvent(
|
|
90
|
+
METRIC_EVENT_NAMES.TASK_ACCEPT_SUCCESS,
|
|
91
|
+
{
|
|
92
|
+
taskId: this.data.interactionId,
|
|
93
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponse(this.data),
|
|
94
|
+
},
|
|
95
|
+
['operational', 'behavioral', 'business']
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
return Promise.resolve();
|
|
99
|
+
} catch (error) {
|
|
100
|
+
this.metricsManager.trackEvent(
|
|
101
|
+
METRIC_EVENT_NAMES.TASK_ACCEPT_FAILED,
|
|
102
|
+
{
|
|
103
|
+
taskId: this.data.interactionId,
|
|
104
|
+
error: error.toString(),
|
|
105
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponseFailed(
|
|
106
|
+
(error as any).details || {}
|
|
107
|
+
),
|
|
108
|
+
},
|
|
109
|
+
['operational', 'behavioral', 'business']
|
|
110
|
+
);
|
|
111
|
+
const {error: detailedError} = getErrorDetails(error, 'accept', CC_FILE);
|
|
112
|
+
throw detailedError;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* This is used for the incoming task decline by agent.
|
|
118
|
+
*
|
|
119
|
+
* @returns Promise<TaskResponse>
|
|
120
|
+
* @throws Error
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* task.decline().then(()=>{}).catch(()=>{})
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
public async decline(): Promise<TaskResponse> {
|
|
127
|
+
LoggerProxy.log(`Declining WebRTC task for taskId:${this.data.interactionId}`, {
|
|
128
|
+
module: 'WebRTC',
|
|
129
|
+
method: 'decline',
|
|
130
|
+
});
|
|
131
|
+
try {
|
|
132
|
+
this.metricsManager.timeEvent([
|
|
133
|
+
METRIC_EVENT_NAMES.TASK_DECLINE_SUCCESS,
|
|
134
|
+
METRIC_EVENT_NAMES.TASK_DECLINE_FAILED,
|
|
135
|
+
]);
|
|
136
|
+
|
|
137
|
+
this.webCallingService.declineCall(this.data.interactionId);
|
|
138
|
+
this.unregisterWebCallListeners();
|
|
139
|
+
|
|
140
|
+
this.metricsManager.trackEvent(
|
|
141
|
+
METRIC_EVENT_NAMES.TASK_DECLINE_SUCCESS,
|
|
142
|
+
{taskId: this.data.interactionId},
|
|
143
|
+
['operational', 'behavioral']
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
return Promise.resolve();
|
|
147
|
+
} catch (error) {
|
|
148
|
+
this.metricsManager.trackEvent(
|
|
149
|
+
METRIC_EVENT_NAMES.TASK_DECLINE_FAILED,
|
|
150
|
+
{
|
|
151
|
+
taskId: this.data.interactionId,
|
|
152
|
+
error: error.toString(),
|
|
153
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponseFailed(
|
|
154
|
+
(error as any).details || {}
|
|
155
|
+
),
|
|
156
|
+
},
|
|
157
|
+
['operational', 'behavioral']
|
|
158
|
+
);
|
|
159
|
+
const {error: detailedError} = getErrorDetails(error, 'decline', CC_FILE);
|
|
160
|
+
throw detailedError;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* This is used for the placing the call in mute or unmute by the agent.
|
|
166
|
+
*
|
|
167
|
+
* @throws Error
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* task.toggleMute().then(()=>{}).catch(()=>{})
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
public async toggleMute() {
|
|
174
|
+
LoggerProxy.log(`Toggling mute WebRTC task for taskId:${this.data.interactionId}`, {
|
|
175
|
+
module: 'WebRTC',
|
|
176
|
+
method: 'toggleMute',
|
|
177
|
+
});
|
|
178
|
+
try {
|
|
179
|
+
this.webCallingService.muteUnmuteCall(this.localAudioStream);
|
|
180
|
+
|
|
181
|
+
return Promise.resolve();
|
|
182
|
+
} catch (error) {
|
|
183
|
+
const {error: detailedError} = getErrorDetails(error, 'mute', CC_FILE);
|
|
184
|
+
throw detailedError;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from '@webex/internal-plugin-metrics/src/metrics.types';
|
|
7
7
|
import * as Agent from './services/agent/types';
|
|
8
8
|
import * as Contact from './services/task/types';
|
|
9
|
-
import {Profile} from './services/config/types';
|
|
9
|
+
import {AIFeatureFlags, Profile} from './services/config/types';
|
|
10
10
|
import {PaginatedResponse, BaseSearchParams} from './utils/PageCache';
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -570,6 +570,25 @@ export type BuddyAgents = {
|
|
|
570
570
|
};
|
|
571
571
|
|
|
572
572
|
/**
|
|
573
|
+
* Holds the configuration flags for the Agent.
|
|
574
|
+
* These flags determine the availability of certain features in the Agent UI.
|
|
575
|
+
* @internal
|
|
576
|
+
*/
|
|
577
|
+
export type ConfigFlags = {
|
|
578
|
+
isEndTaskEnabled: boolean;
|
|
579
|
+
isEndConsultEnabled: boolean;
|
|
580
|
+
webRtcEnabled: boolean;
|
|
581
|
+
autoWrapup: boolean;
|
|
582
|
+
aiFeature?: AIFeatureFlags;
|
|
583
|
+
/**
|
|
584
|
+
* Optional toggle to globally enable/disable recording controls.
|
|
585
|
+
* Falls back to backend hints when omitted.
|
|
586
|
+
*/
|
|
587
|
+
isRecordingEnabled?: boolean;
|
|
588
|
+
};
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
|
|
573
592
|
* Generic error structure for Contact Center SDK errors.
|
|
574
593
|
* Contains detailed information about the error context.
|
|
575
594
|
* @public
|
|
@@ -823,38 +842,130 @@ export type BuddyAgentsResponse = Agent.BuddyAgentsSuccess | Error;
|
|
|
823
842
|
*/
|
|
824
843
|
export type UpdateDeviceTypeResponse = Agent.DeviceTypeUpdateSuccess | Error;
|
|
825
844
|
|
|
845
|
+
/**
|
|
846
|
+
* Supported transcript control actions for AI Assistant events.
|
|
847
|
+
* @public
|
|
848
|
+
* @example
|
|
849
|
+
* const action: TranscriptAction = 'START';
|
|
850
|
+
* @ignore
|
|
851
|
+
*/
|
|
826
852
|
export type TranscriptAction = 'START' | 'STOP';
|
|
827
853
|
|
|
854
|
+
/**
|
|
855
|
+
* Parameters used to request an AI Assistant suggested response.
|
|
856
|
+
* @public
|
|
857
|
+
* @example
|
|
858
|
+
* const params: SuggestedResponseParams = {
|
|
859
|
+
* interactionId: 'interaction-123',
|
|
860
|
+
* actionTimeStamp: Date.now(),
|
|
861
|
+
* context: 'Need help with credit card payment due date',
|
|
862
|
+
* };
|
|
863
|
+
*/
|
|
864
|
+
export type SuggestedResponseParams = {
|
|
865
|
+
/** Agent identifier */
|
|
866
|
+
agentId: string;
|
|
867
|
+
/** Interaction identifier for which suggestion should be generated */
|
|
868
|
+
interactionId: string;
|
|
869
|
+
/** Optional additional context that should refine the suggestion */
|
|
870
|
+
context?: string;
|
|
871
|
+
/** Optional language code for suggestions (for example, 'en'). Defaults to 'en'. */
|
|
872
|
+
languageCode?: string;
|
|
873
|
+
};
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
* Supported AI Assistant event categories.
|
|
877
|
+
* @public
|
|
878
|
+
* @example
|
|
879
|
+
* const eventType: AIAssistantEventType = AIAssistantEventType.CUSTOM_EVENT;
|
|
880
|
+
* @ignore
|
|
881
|
+
*/
|
|
828
882
|
export const AIAssistantEventType = {
|
|
883
|
+
/** Custom AI Assistant event */
|
|
829
884
|
CUSTOM_EVENT: 'CUSTOM_EVENT',
|
|
885
|
+
/** CTI-backed AI Assistant event */
|
|
830
886
|
CTI_EVENT: 'CTI_EVENT',
|
|
831
887
|
} as const;
|
|
832
888
|
|
|
889
|
+
/**
|
|
890
|
+
* Union type of AI Assistant event categories.
|
|
891
|
+
* @public
|
|
892
|
+
* @example
|
|
893
|
+
* function send(type: AIAssistantEventType) { ... }
|
|
894
|
+
* @ignore
|
|
895
|
+
*/
|
|
833
896
|
export type AIAssistantEventType = Enum<typeof AIAssistantEventType>;
|
|
834
897
|
|
|
898
|
+
/**
|
|
899
|
+
* Supported AI Assistant event names.
|
|
900
|
+
* @public
|
|
901
|
+
* @example
|
|
902
|
+
* const name: AIAssistantEventName = AIAssistantEventName.GET_TRANSCRIPTS;
|
|
903
|
+
* @ignore
|
|
904
|
+
*/
|
|
835
905
|
export const AIAssistantEventName = {
|
|
906
|
+
/** Request transcript streaming for an interaction */
|
|
836
907
|
GET_TRANSCRIPTS: 'GET_TRANSCRIPTS',
|
|
908
|
+
/** Request a suggested response for an interaction */
|
|
909
|
+
GET_SUGGESTIONS: 'GET_SUGGESTIONS',
|
|
910
|
+
/** Add extra context to refine a suggested response */
|
|
911
|
+
ADD_SUGGESTIONS_EXTRA_CONTEXT: 'ADD_SUGGESTIONS_EXTRA_CONTEXT',
|
|
912
|
+
/** Request mid-call summary generation */
|
|
837
913
|
GET_MID_CALL_SUMMARY: 'GET_MID_CALL_SUMMARY',
|
|
914
|
+
/** Request post-call summary generation */
|
|
838
915
|
GET_POST_CALL_SUMMARY: 'GET_POST_CALL_SUMMARY',
|
|
916
|
+
/** Mid-call summary response event */
|
|
839
917
|
MID_CALL_SUMMARY_RESPONSE: 'MID_CALL_SUMMARY_RESPONSE',
|
|
918
|
+
/** Post-call summary response event */
|
|
840
919
|
POST_CALL_SUMMARY_RESPONSE: 'POST_CALL_SUMMARY_RESPONSE',
|
|
920
|
+
/** Suggested digital response event */
|
|
841
921
|
SUGGESTED_RESPONSES_DIGITAL: 'SUGGESTED_RESPONSES_DIGITAL',
|
|
842
922
|
} as const;
|
|
843
923
|
|
|
924
|
+
/**
|
|
925
|
+
* Union type of AI Assistant event names.
|
|
926
|
+
* @public
|
|
927
|
+
* @example
|
|
928
|
+
* function handle(name: AIAssistantEventName) { ... }
|
|
929
|
+
* @ignore
|
|
930
|
+
*/
|
|
844
931
|
export type AIAssistantEventName = Enum<typeof AIAssistantEventName>;
|
|
845
932
|
|
|
933
|
+
/**
|
|
934
|
+
* A single transcript message entry returned by AI Assistant APIs.
|
|
935
|
+
* @public
|
|
936
|
+
* @example
|
|
937
|
+
* const message: TranscriptMessage = { role: 'AGENT', content: 'Hello', messageId: '1', publishTimestamp: Date.now() };
|
|
938
|
+
*
|
|
939
|
+
*/
|
|
846
940
|
export type TranscriptMessage = {
|
|
941
|
+
/** Speaker role for this message */
|
|
847
942
|
role: string;
|
|
943
|
+
/** Transcript chunk content */
|
|
848
944
|
content: string;
|
|
945
|
+
/** Unique message identifier */
|
|
849
946
|
messageId: string;
|
|
947
|
+
/** Message publish timestamp (epoch milliseconds) */
|
|
850
948
|
publishTimestamp: number;
|
|
851
949
|
};
|
|
852
950
|
|
|
951
|
+
/**
|
|
952
|
+
* Response payload for historic transcripts API.
|
|
953
|
+
* @public
|
|
954
|
+
* @example
|
|
955
|
+
* const resp: HistoricTranscriptsResponse = { orgId: 'org', agentId: 'agent', conversationId: null, interactionId: 'int', source: 'AI', data: [] };
|
|
956
|
+
*
|
|
957
|
+
*/
|
|
853
958
|
export type HistoricTranscriptsResponse = {
|
|
959
|
+
/** Organization identifier */
|
|
854
960
|
orgId: string;
|
|
961
|
+
/** Agent identifier */
|
|
855
962
|
agentId: string;
|
|
963
|
+
/** Conversation identifier when available */
|
|
856
964
|
conversationId: string | null;
|
|
965
|
+
/** Interaction identifier */
|
|
857
966
|
interactionId: string;
|
|
967
|
+
/** Data source identifier */
|
|
858
968
|
source: string;
|
|
969
|
+
/** Transcript messages */
|
|
859
970
|
data: TranscriptMessage[];
|
|
860
971
|
};
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
# Utils
|
|
2
|
+
|
|
3
|
+
> **This is the authoritative documentation for the `src/utils` scope.** It covers shared pagination/cache contracts used by data services. For task routing and cross-service conventions, see the [root orchestrator AGENTS.md](../../AGENTS.md).
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Key Capabilities
|
|
8
|
+
|
|
9
|
+
The utils scope currently provides shared pagination and cache behavior for contact-center data services:
|
|
10
|
+
|
|
11
|
+
- **Typed Pagination Contracts**: Reusable interfaces for response metadata and query params
|
|
12
|
+
- **Generic In-Memory Page Caching**: `PageCache<T>` utility for simple pagination reuse
|
|
13
|
+
- **Cache Safety Rules**: Explicit bypass behavior for search/filter/sort scenarios
|
|
14
|
+
- **Spec-Driven Utility Workflow**: Utility-specific implementation and validation flow documented inline in this file
|
|
15
|
+
|
|
16
|
+
| Component | File | Description |
|
|
17
|
+
| --------------------- | -------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
18
|
+
| `PageCache` | [`PageCache.ts`](./PageCache.ts) | Generic in-memory cache utility for paginated API responses with TTL expiry and helper methods for key generation and cache eligibility checks. |
|
|
19
|
+
| `Pagination Types` | [`PageCache.ts`](./PageCache.ts) | `PaginationMeta`, `PaginatedResponse<T>`, `BaseSearchParams`, and `PageCacheEntry<T>` shared across data services. |
|
|
20
|
+
| `Pagination Defaults` | [`PageCache.ts`](./PageCache.ts) | `PAGINATION_DEFAULTS` (`PAGE`, `PAGE_SIZE`) used by services for consistent request defaults. |
|
|
21
|
+
| `Specs Workflow` | `AGENTS.md` (inline) | Mermaid flow for specs-driven utility changes, acceptance criteria, and drift checks. |
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## File Structure
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
src/utils/
|
|
29
|
+
├── AGENTS.md # This file: utils scope guide
|
|
30
|
+
└── PageCache.ts # Generic cache + pagination contracts/defaults
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## PageCache Utility
|
|
36
|
+
|
|
37
|
+
`PageCache<T>` provides a consistent caching model for paginated list APIs. It is optimized for simple page browsing and intentionally bypasses cache for parameterized query cases (`search`, `filter`, `attributes`, `sortBy`).
|
|
38
|
+
|
|
39
|
+
### Reference Usage
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import PageCache, {PAGINATION_DEFAULTS} from '../utils/PageCache';
|
|
43
|
+
|
|
44
|
+
const cache = new PageCache<MyItem>('MyService');
|
|
45
|
+
|
|
46
|
+
const page = PAGINATION_DEFAULTS.PAGE;
|
|
47
|
+
const pageSize = PAGINATION_DEFAULTS.PAGE_SIZE;
|
|
48
|
+
const cacheKey = cache.buildCacheKey(scopeId, page, pageSize);
|
|
49
|
+
|
|
50
|
+
// Include sortBy only for services that support sorting.
|
|
51
|
+
const canUseCache = cache.canUseCache({search, filter, attributes, sortBy});
|
|
52
|
+
|
|
53
|
+
if (canUseCache) {
|
|
54
|
+
const cachedEntry = cache.getCachedPage(cacheKey);
|
|
55
|
+
if (cachedEntry) {
|
|
56
|
+
return {
|
|
57
|
+
data: cachedEntry.data,
|
|
58
|
+
meta: {
|
|
59
|
+
page,
|
|
60
|
+
pageSize,
|
|
61
|
+
...cachedEntry.totalMeta,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const response = await fetchPageFromApi();
|
|
68
|
+
|
|
69
|
+
if (canUseCache && response.data) {
|
|
70
|
+
cache.cachePage(cacheKey, response.data, response.meta);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return response;
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Cache Lifecycle
|
|
77
|
+
|
|
78
|
+
```mermaid
|
|
79
|
+
graph TD
|
|
80
|
+
A[Request arrives with scopeId/page/pageSize] --> B{canUseCache?}
|
|
81
|
+
B -->|No: search/filter/attributes/sortBy provided| C[Bypass cache and call API]
|
|
82
|
+
B -->|Yes| D[buildCacheKey scopeId:page:pageSize]
|
|
83
|
+
D --> E["getCachedPage(cacheKey)"]
|
|
84
|
+
E -->|Miss| C
|
|
85
|
+
E -->|Hit and not expired| F[Return cached data and totalMeta]
|
|
86
|
+
E -->|Hit but expired >= 5 minutes| G[Delete entry and treat as miss]
|
|
87
|
+
G --> C
|
|
88
|
+
C --> H[Receive API response]
|
|
89
|
+
H --> I["cachePage(cacheKey, data, meta)"]
|
|
90
|
+
I --> J[Return fresh response]
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Public Contracts
|
|
96
|
+
|
|
97
|
+
All public contracts for utils are defined in [`PageCache.ts`](./PageCache.ts).
|
|
98
|
+
|
|
99
|
+
### `PaginationMeta`
|
|
100
|
+
|
|
101
|
+
Common pagination metadata used across list APIs.
|
|
102
|
+
|
|
103
|
+
| Field | Type | Notes |
|
|
104
|
+
| ----------------------------- | ------------------------ | ----------------------- |
|
|
105
|
+
| `orgid` | `string` | Organization identifier |
|
|
106
|
+
| `page` / `currentPage` | `number` | Current page aliases |
|
|
107
|
+
| `pageSize` | `number` | Items per page |
|
|
108
|
+
| `totalPages` | `number` | Total page count |
|
|
109
|
+
| `totalRecords` / `totalItems` | `number` | Total item aliases |
|
|
110
|
+
| `links` | `Record<string, string>` | Pagination link map |
|
|
111
|
+
|
|
112
|
+
### `PaginatedResponse<T>`
|
|
113
|
+
|
|
114
|
+
Canonical paginated response type:
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
interface PaginatedResponse<T> {
|
|
118
|
+
data: T[];
|
|
119
|
+
meta: PaginationMeta;
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### `PageCacheEntry<T>`
|
|
124
|
+
|
|
125
|
+
Shape of a cached page entry returned by `getCachedPage()`:
|
|
126
|
+
|
|
127
|
+
- `data: T[]`
|
|
128
|
+
- `timestamp: number` (epoch milliseconds)
|
|
129
|
+
- `totalMeta?: { totalPages?: number; totalRecords?: number }`
|
|
130
|
+
|
|
131
|
+
### `CacheValidationParams`
|
|
132
|
+
|
|
133
|
+
Contract passed to `canUseCache()`:
|
|
134
|
+
|
|
135
|
+
- `search?: string`
|
|
136
|
+
- `filter?: string`
|
|
137
|
+
- `attributes?: string`
|
|
138
|
+
- `sortBy?: string`
|
|
139
|
+
|
|
140
|
+
Behavior note:
|
|
141
|
+
|
|
142
|
+
- Cache bypass is triggered by `sortBy`, not by `sortOrder` alone.
|
|
143
|
+
- If a new service treats `sortOrder` as meaningful without `sortBy`, extend `CacheValidationParams` and `canUseCache()` together.
|
|
144
|
+
|
|
145
|
+
### `BaseSearchParams`
|
|
146
|
+
|
|
147
|
+
Common query parameter contract with pagination and sorting:
|
|
148
|
+
|
|
149
|
+
- `search`, `filter`, `attributes`
|
|
150
|
+
- `page`, `pageSize`
|
|
151
|
+
- `sortBy`, `sortOrder`
|
|
152
|
+
|
|
153
|
+
### `PAGINATION_DEFAULTS`
|
|
154
|
+
|
|
155
|
+
Standard defaults exported for callers:
|
|
156
|
+
|
|
157
|
+
- `PAGE: 0`
|
|
158
|
+
- `PAGE_SIZE: 100`
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## PageCache API
|
|
163
|
+
|
|
164
|
+
### `constructor(apiName: string)`
|
|
165
|
+
|
|
166
|
+
Creates a typed cache instance and stores `apiName` for `LoggerProxy` context.
|
|
167
|
+
|
|
168
|
+
### `canUseCache(params: CacheValidationParams): boolean`
|
|
169
|
+
|
|
170
|
+
Returns `true` only when all of these are absent:
|
|
171
|
+
|
|
172
|
+
- `search`
|
|
173
|
+
- `filter`
|
|
174
|
+
- `attributes`
|
|
175
|
+
- `sortBy`
|
|
176
|
+
|
|
177
|
+
`sortOrder` alone does not trigger cache bypass because `CacheValidationParams` currently keys bypass on fields that materially change the query result set in existing consumers.
|
|
178
|
+
|
|
179
|
+
### `buildCacheKey(scopeId: string, page: number, pageSize: number): string`
|
|
180
|
+
|
|
181
|
+
Builds deterministic cache key format:
|
|
182
|
+
|
|
183
|
+
```text
|
|
184
|
+
${scopeId}:${page}:${pageSize}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### `getCachedPage(cacheKey: string): PageCacheEntry<T> | null`
|
|
188
|
+
|
|
189
|
+
Behavior:
|
|
190
|
+
|
|
191
|
+
1. Returns `null` if key not found
|
|
192
|
+
2. Computes cache age in minutes
|
|
193
|
+
3. If age is `>= 5`, logs expiry, deletes entry, returns `null`
|
|
194
|
+
4. Otherwise returns cached entry
|
|
195
|
+
|
|
196
|
+
### `cachePage(cacheKey: string, data: T[], meta?: any): void`
|
|
197
|
+
|
|
198
|
+
Stores entry with:
|
|
199
|
+
|
|
200
|
+
- `data`
|
|
201
|
+
- `timestamp`
|
|
202
|
+
- `totalMeta.totalPages`
|
|
203
|
+
- `totalMeta.totalRecords` mapped from `meta.totalRecords || meta.totalItems`
|
|
204
|
+
|
|
205
|
+
### `clearCache(): void`
|
|
206
|
+
|
|
207
|
+
Clears all entries and logs cleared entry count.
|
|
208
|
+
|
|
209
|
+
### `getCacheSize(): number`
|
|
210
|
+
|
|
211
|
+
Returns current in-memory entry count.
|
|
212
|
+
|
|
213
|
+
Note: `clearCache()` and `getCacheSize()` are available for future use and are not currently called by existing consumers.
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## Consumer Map
|
|
218
|
+
|
|
219
|
+
Current consumers of `PageCache` and defaults:
|
|
220
|
+
|
|
221
|
+
| Consumer | File | Usage |
|
|
222
|
+
| ----------------------- | ---------------------------------------------------------- | ------------------------------------------------------------ |
|
|
223
|
+
| `AddressBook` | [`../services/AddressBook.ts`](../services/AddressBook.ts) | Caches paged address-book responses |
|
|
224
|
+
| `EntryPoint` | [`../services/EntryPoint.ts`](../services/EntryPoint.ts) | Caches paged entry-point responses |
|
|
225
|
+
| `Queue` | [`../services/Queue.ts`](../services/Queue.ts) | Caches paged queue responses |
|
|
226
|
+
| `Public type contracts` | [`../types.ts`](../types.ts) | Re-exports pagination/search contracts into SDK-facing types |
|
|
227
|
+
|
|
228
|
+
Cross-scope mention:
|
|
229
|
+
|
|
230
|
+
- Services-layer docs reference utils caching contracts at [`../services/ai-docs/AGENTS.md`](../services/ai-docs/AGENTS.md).
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## Spec-Driven Utility Changes
|
|
235
|
+
|
|
236
|
+
When changing `src/utils` behavior or contracts:
|
|
237
|
+
|
|
238
|
+
1. Follow the workflow diagram below
|
|
239
|
+
2. Define acceptance criteria for contract and runtime behavior
|
|
240
|
+
3. Verify cache TTL, bypass rules, and key schema
|
|
241
|
+
4. Validate no spec drift before shipping
|
|
242
|
+
|
|
243
|
+
```mermaid
|
|
244
|
+
flowchart TD
|
|
245
|
+
A[Change proposed in src/utils] --> B{Classify change scope}
|
|
246
|
+
B -->|Contract change| C[Document expected API/type behavior]
|
|
247
|
+
B -->|Runtime behavior change| D[Document cache behavior and TTL impact]
|
|
248
|
+
B -->|Both| C
|
|
249
|
+
C --> E[Update utils AGENTS.md contracts and consumer map]
|
|
250
|
+
D --> F[Validate cache key schema and bypass conditions]
|
|
251
|
+
E --> G[Run drift check against PageCache.ts and consumer services]
|
|
252
|
+
F --> G
|
|
253
|
+
G --> H{Behavior and docs aligned?}
|
|
254
|
+
H -->|No| I[Revise implementation/docs and re-validate]
|
|
255
|
+
I --> G
|
|
256
|
+
H -->|Yes| J[Prepare PR with acceptance criteria and evidence]
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## Validation Checklist
|
|
262
|
+
|
|
263
|
+
- [ ] Public types remain backward-compatible or migration is documented
|
|
264
|
+
- [ ] `PAGINATION_DEFAULTS` changes are intentional and propagated to consumers
|
|
265
|
+
- [ ] Cache TTL behavior remains explicit and covered by tests
|
|
266
|
+
- [ ] `canUseCache()` bypass conditions are unchanged or intentionally updated
|
|
267
|
+
- [ ] `totalRecords`/`totalItems` mapping behavior is preserved
|
|
268
|
+
- [ ] Logging still uses `LoggerProxy` with `module` and `method`
|
|
269
|
+
- [ ] AddressBook/EntryPoint/Queue integration behavior remains correct
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
## Related
|
|
274
|
+
|
|
275
|
+
- [Root orchestrator AGENTS.md](../../AGENTS.md) - Task routing and critical package rules
|
|
276
|
+
- [PageCache implementation](./PageCache.ts)
|