@webex/contact-center 3.12.0-next.9 → 3.12.0-task-refactor.1
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 +65 -123
- package/dist/cc.js.map +1 -1
- package/dist/constants.js +13 -2
- 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 -13
- package/dist/metrics/behavioral-events.js.map +1 -1
- package/dist/metrics/constants.js +7 -6
- package/dist/metrics/constants.js.map +1 -1
- package/dist/services/ApiAiAssistant.js +0 -3
- package/dist/services/ApiAiAssistant.js.map +1 -1
- package/dist/services/config/Util.js +2 -3
- package/dist/services/config/Util.js.map +1 -1
- package/dist/services/config/types.js +16 -14
- package/dist/services/config/types.js.map +1 -1
- package/dist/services/constants.js +0 -1
- package/dist/services/constants.js.map +1 -1
- package/dist/services/core/Err.js.map +1 -1
- package/dist/services/core/Utils.js +79 -55
- package/dist/services/core/Utils.js.map +1 -1
- package/dist/services/core/aqm-reqs.js +17 -92
- package/dist/services/core/aqm-reqs.js.map +1 -1
- package/dist/services/core/websocket/WebSocketManager.js +5 -25
- 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 -2
- package/dist/services/index.js.map +1 -1
- package/dist/services/task/Task.js +644 -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 +556 -532
- package/dist/services/task/TaskManager.js.map +1 -1
- package/dist/services/task/TaskUtils.js +132 -28
- package/dist/services/task/TaskUtils.js.map +1 -1
- package/dist/services/task/constants.js +7 -6
- package/dist/services/task/constants.js.map +1 -1
- package/dist/services/task/dialer.js +0 -51
- package/dist/services/task/dialer.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 +634 -0
- package/dist/services/task/state-machine/TaskStateMachine.js.map +1 -0
- package/dist/services/task/state-machine/actions.js +366 -0
- package/dist/services/task/state-machine/actions.js.map +1 -0
- package/dist/services/task/state-machine/constants.js +139 -0
- package/dist/services/task/state-machine/constants.js.map +1 -0
- package/dist/services/task/state-machine/guards.js +256 -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 +369 -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 +157 -18
- package/dist/services/task/types.js.map +1 -1
- package/dist/services/task/voice/Voice.js +1031 -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 +4 -33
- package/dist/types/constants.d.ts +13 -2
- package/dist/types/index.d.ts +11 -5
- package/dist/types/metrics/constants.d.ts +5 -3
- package/dist/types/services/ApiAiAssistant.d.ts +1 -1
- package/dist/types/services/config/types.d.ts +97 -25
- package/dist/types/services/core/Err.d.ts +0 -2
- package/dist/types/services/core/Utils.d.ts +25 -23
- package/dist/types/services/core/aqm-reqs.d.ts +0 -49
- package/dist/types/services/core/websocket/WebSocketManager.d.ts +1 -1
- package/dist/types/services/core/websocket/connection-service.d.ts +0 -1
- 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 +146 -0
- package/dist/types/services/task/TaskFactory.d.ts +12 -0
- package/dist/types/services/task/TaskUtils.d.ts +39 -8
- package/dist/types/services/task/constants.d.ts +5 -4
- package/dist/types/services/task/dialer.d.ts +0 -15
- package/dist/types/services/task/digital/Digital.d.ts +22 -0
- package/dist/types/services/task/state-machine/TaskStateMachine.d.ts +906 -0
- package/dist/types/services/task/state-machine/actions.d.ts +8 -0
- package/dist/types/services/task/state-machine/constants.d.ts +91 -0
- package/dist/types/services/task/state-machine/guards.d.ts +78 -0
- package/dist/types/services/task/state-machine/index.d.ts +13 -0
- package/dist/types/services/task/state-machine/types.d.ts +256 -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 +539 -88
- package/dist/types/services/task/voice/Voice.d.ts +183 -0
- package/dist/types/services/task/voice/WebRTC.d.ts +53 -0
- package/dist/types/types.d.ts +68 -0
- package/dist/types/webex.d.ts +1 -0
- package/dist/types.js +70 -0
- package/dist/types.js.map +1 -1
- package/dist/webex.js +14 -2
- package/dist/webex.js.map +1 -1
- package/package.json +14 -11
- package/src/cc.ts +91 -177
- package/src/constants.ts +13 -2
- 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 -14
- package/src/metrics/constants.ts +7 -8
- package/src/services/ApiAiAssistant.ts +2 -4
- 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 -3
- 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 +108 -20
- package/src/services/constants.ts +0 -1
- package/src/services/core/Err.ts +0 -1
- package/src/services/core/Utils.ts +90 -67
- package/src/services/core/ai-docs/AGENTS.md +379 -0
- package/src/services/core/ai-docs/ARCHITECTURE.md +696 -0
- package/src/services/core/aqm-reqs.ts +22 -100
- package/src/services/core/websocket/WebSocketManager.ts +4 -23
- package/src/services/core/websocket/types.ts +1 -1
- package/src/services/index.ts +1 -2
- package/src/services/task/Task.ts +785 -0
- package/src/services/task/TaskFactory.ts +55 -0
- package/src/services/task/TaskManager.ts +567 -633
- package/src/services/task/TaskUtils.ts +175 -31
- package/src/services/task/ai-docs/AGENTS.md +448 -0
- package/src/services/task/ai-docs/ARCHITECTURE.md +573 -0
- package/src/services/task/constants.ts +5 -4
- package/src/services/task/dialer.ts +1 -56
- package/src/services/task/digital/Digital.ts +95 -0
- package/src/services/task/state-machine/TaskStateMachine.ts +793 -0
- package/src/services/task/state-machine/actions.ts +409 -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 +150 -0
- package/src/services/task/state-machine/guards.ts +295 -0
- package/src/services/task/state-machine/index.ts +28 -0
- package/src/services/task/state-machine/types.ts +228 -0
- package/src/services/task/state-machine/uiControlsComputer.ts +529 -0
- package/src/services/task/taskDataNormalizer.ts +137 -0
- package/src/services/task/types.ts +641 -95
- package/src/services/task/voice/Voice.ts +1255 -0
- package/src/services/task/voice/WebRTC.ts +187 -0
- package/src/types.ts +88 -5
- package/src/utils/AGENTS.md +276 -0
- package/src/webex.js +2 -0
- package/test/unit/spec/cc.ts +59 -142
- package/test/unit/spec/logger-proxy.ts +70 -0
- package/test/unit/spec/services/ApiAiAssistant.ts +17 -0
- package/test/unit/spec/services/config/index.ts +26 -55
- package/test/unit/spec/services/core/Utils.ts +103 -52
- package/test/unit/spec/services/core/websocket/WebSocketManager.ts +48 -112
- package/test/unit/spec/services/core/websocket/connection-service.ts +5 -4
- package/test/unit/spec/services/task/AutoWrapup.ts +63 -0
- package/test/unit/spec/services/task/Task.ts +416 -0
- package/test/unit/spec/services/task/TaskFactory.ts +62 -0
- package/test/unit/spec/services/task/TaskManager.ts +781 -1735
- package/test/unit/spec/services/task/TaskUtils.ts +125 -0
- package/test/unit/spec/services/task/dialer.ts +112 -198
- package/test/unit/spec/services/task/digital/Digital.ts +105 -0
- package/test/unit/spec/services/task/state-machine/TaskStateMachine.ts +473 -0
- package/test/unit/spec/services/task/state-machine/guards.ts +288 -0
- package/test/unit/spec/services/task/state-machine/types.ts +18 -0
- package/test/unit/spec/services/task/state-machine/uiControlsComputer.ts +147 -0
- package/test/unit/spec/services/task/taskTestUtils.ts +87 -0
- package/test/unit/spec/services/task/voice/Voice.ts +587 -0
- package/test/unit/spec/services/task/voice/WebRTC.ts +242 -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 -1525
- 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 -1801
- package/test/unit/spec/services/task/index.ts +0 -2184
|
@@ -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
|
/**
|
|
@@ -295,8 +295,6 @@ interface IWebexInternal {
|
|
|
295
295
|
get: (service: string) => string;
|
|
296
296
|
/** Wait for service catalog to be loaded */
|
|
297
297
|
waitForCatalog: (service: string) => Promise<void>;
|
|
298
|
-
/** Check if current environment is INT (integration) */
|
|
299
|
-
isIntegrationEnvironment: () => boolean;
|
|
300
298
|
/** Host catalog for service discovery */
|
|
301
299
|
_hostCatalog: Record<string, ServiceHost[]>;
|
|
302
300
|
/** Service URLs cache */
|
|
@@ -541,8 +539,7 @@ export type RequestBody =
|
|
|
541
539
|
| Contact.ConsultTransferPayLoad
|
|
542
540
|
| Contact.cancelCtq
|
|
543
541
|
| Contact.WrapupPayLoad
|
|
544
|
-
| Contact.DialerPayload
|
|
545
|
-
| Contact.PreviewContactPayload;
|
|
542
|
+
| Contact.DialerPayload;
|
|
546
543
|
|
|
547
544
|
/**
|
|
548
545
|
* Represents the options to fetch buddy agents for the logged in agent.
|
|
@@ -568,6 +565,25 @@ export type BuddyAgents = {
|
|
|
568
565
|
};
|
|
569
566
|
|
|
570
567
|
/**
|
|
568
|
+
* Holds the configuration flags for the Agent.
|
|
569
|
+
* These flags determine the availability of certain features in the Agent UI.
|
|
570
|
+
* @internal
|
|
571
|
+
*/
|
|
572
|
+
export type ConfigFlags = {
|
|
573
|
+
isEndTaskEnabled: boolean;
|
|
574
|
+
isEndConsultEnabled: boolean;
|
|
575
|
+
webRtcEnabled: boolean;
|
|
576
|
+
autoWrapup: boolean;
|
|
577
|
+
aiFeature?: AIFeatureFlags;
|
|
578
|
+
/**
|
|
579
|
+
* Optional toggle to globally enable/disable recording controls.
|
|
580
|
+
* Falls back to backend hints when omitted.
|
|
581
|
+
*/
|
|
582
|
+
isRecordingEnabled?: boolean;
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
|
|
571
587
|
* Generic error structure for Contact Center SDK errors.
|
|
572
588
|
* Contains detailed information about the error context.
|
|
573
589
|
* @public
|
|
@@ -821,38 +837,105 @@ export type BuddyAgentsResponse = Agent.BuddyAgentsSuccess | Error;
|
|
|
821
837
|
*/
|
|
822
838
|
export type UpdateDeviceTypeResponse = Agent.DeviceTypeUpdateSuccess | Error;
|
|
823
839
|
|
|
840
|
+
/**
|
|
841
|
+
* Supported transcript control actions for AI Assistant events.
|
|
842
|
+
* @public
|
|
843
|
+
* @example
|
|
844
|
+
* const action: TranscriptAction = 'START';
|
|
845
|
+
* @ignore
|
|
846
|
+
*/
|
|
824
847
|
export type TranscriptAction = 'START' | 'STOP';
|
|
825
848
|
|
|
849
|
+
/**
|
|
850
|
+
* Supported AI Assistant event categories.
|
|
851
|
+
* @public
|
|
852
|
+
* @example
|
|
853
|
+
* const eventType: AIAssistantEventType = AIAssistantEventType.CUSTOM_EVENT;
|
|
854
|
+
* @ignore
|
|
855
|
+
*/
|
|
826
856
|
export const AIAssistantEventType = {
|
|
857
|
+
/** Custom AI Assistant event */
|
|
827
858
|
CUSTOM_EVENT: 'CUSTOM_EVENT',
|
|
859
|
+
/** CTI-backed AI Assistant event */
|
|
828
860
|
CTI_EVENT: 'CTI_EVENT',
|
|
829
861
|
} as const;
|
|
830
862
|
|
|
863
|
+
/**
|
|
864
|
+
* Union type of AI Assistant event categories.
|
|
865
|
+
* @public
|
|
866
|
+
* @example
|
|
867
|
+
* function send(type: AIAssistantEventType) { ... }
|
|
868
|
+
* @ignore
|
|
869
|
+
*/
|
|
831
870
|
export type AIAssistantEventType = Enum<typeof AIAssistantEventType>;
|
|
832
871
|
|
|
872
|
+
/**
|
|
873
|
+
* Supported AI Assistant event names.
|
|
874
|
+
* @public
|
|
875
|
+
* @example
|
|
876
|
+
* const name: AIAssistantEventName = AIAssistantEventName.GET_TRANSCRIPTS;
|
|
877
|
+
* @ignore
|
|
878
|
+
*/
|
|
833
879
|
export const AIAssistantEventName = {
|
|
880
|
+
/** Request transcript streaming for an interaction */
|
|
834
881
|
GET_TRANSCRIPTS: 'GET_TRANSCRIPTS',
|
|
882
|
+
/** Request mid-call summary generation */
|
|
835
883
|
GET_MID_CALL_SUMMARY: 'GET_MID_CALL_SUMMARY',
|
|
884
|
+
/** Request post-call summary generation */
|
|
836
885
|
GET_POST_CALL_SUMMARY: 'GET_POST_CALL_SUMMARY',
|
|
886
|
+
/** Mid-call summary response event */
|
|
837
887
|
MID_CALL_SUMMARY_RESPONSE: 'MID_CALL_SUMMARY_RESPONSE',
|
|
888
|
+
/** Post-call summary response event */
|
|
838
889
|
POST_CALL_SUMMARY_RESPONSE: 'POST_CALL_SUMMARY_RESPONSE',
|
|
890
|
+
/** Suggested digital response event */
|
|
839
891
|
SUGGESTED_RESPONSES_DIGITAL: 'SUGGESTED_RESPONSES_DIGITAL',
|
|
840
892
|
} as const;
|
|
841
893
|
|
|
894
|
+
/**
|
|
895
|
+
* Union type of AI Assistant event names.
|
|
896
|
+
* @public
|
|
897
|
+
* @example
|
|
898
|
+
* function handle(name: AIAssistantEventName) { ... }
|
|
899
|
+
* @ignore
|
|
900
|
+
*/
|
|
842
901
|
export type AIAssistantEventName = Enum<typeof AIAssistantEventName>;
|
|
843
902
|
|
|
903
|
+
/**
|
|
904
|
+
* A single transcript message entry returned by AI Assistant APIs.
|
|
905
|
+
* @public
|
|
906
|
+
* @example
|
|
907
|
+
* const message: TranscriptMessage = { role: 'AGENT', content: 'Hello', messageId: '1', publishTimestamp: Date.now() };
|
|
908
|
+
*
|
|
909
|
+
*/
|
|
844
910
|
export type TranscriptMessage = {
|
|
911
|
+
/** Speaker role for this message */
|
|
845
912
|
role: string;
|
|
913
|
+
/** Transcript chunk content */
|
|
846
914
|
content: string;
|
|
915
|
+
/** Unique message identifier */
|
|
847
916
|
messageId: string;
|
|
917
|
+
/** Message publish timestamp (epoch milliseconds) */
|
|
848
918
|
publishTimestamp: number;
|
|
849
919
|
};
|
|
850
920
|
|
|
921
|
+
/**
|
|
922
|
+
* Response payload for historic transcripts API.
|
|
923
|
+
* @public
|
|
924
|
+
* @example
|
|
925
|
+
* const resp: HistoricTranscriptsResponse = { orgId: 'org', agentId: 'agent', conversationId: null, interactionId: 'int', source: 'AI', data: [] };
|
|
926
|
+
*
|
|
927
|
+
*/
|
|
851
928
|
export type HistoricTranscriptsResponse = {
|
|
929
|
+
/** Organization identifier */
|
|
852
930
|
orgId: string;
|
|
931
|
+
/** Agent identifier */
|
|
853
932
|
agentId: string;
|
|
933
|
+
/** Conversation identifier when available */
|
|
854
934
|
conversationId: string | null;
|
|
935
|
+
/** Interaction identifier */
|
|
855
936
|
interactionId: string;
|
|
937
|
+
/** Data source identifier */
|
|
856
938
|
source: string;
|
|
939
|
+
/** Transcript messages */
|
|
857
940
|
data: TranscriptMessage[];
|
|
858
941
|
};
|
|
@@ -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)
|