@webex/contact-center 3.12.0-next.8 → 3.12.0-next.81
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 +265 -29
- package/dist/cc.js.map +1 -1
- package/dist/config.js +6 -0
- package/dist/config.js.map +1 -1
- package/dist/constants.js +16 -1
- package/dist/constants.js.map +1 -1
- package/dist/index.js +20 -5
- package/dist/index.js.map +1 -1
- package/dist/metrics/behavioral-events.js +101 -0
- package/dist/metrics/behavioral-events.js.map +1 -1
- package/dist/metrics/constants.js +23 -4
- 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/UserPreference.js +427 -0
- package/dist/services/UserPreference.js.map +1 -0
- package/dist/services/config/Util.js +3 -3
- package/dist/services/config/Util.js.map +1 -1
- package/dist/services/config/constants.js +23 -2
- package/dist/services/config/constants.js.map +1 -1
- package/dist/services/config/types.js +49 -9
- package/dist/services/config/types.js.map +1 -1
- package/dist/services/core/Err.js.map +1 -1
- package/dist/services/core/Utils.js +107 -32
- 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 -526
- 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 +9 -2
- package/dist/services/task/constants.js.map +1 -1
- package/dist/services/task/dialer.js +78 -0
- 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 +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 +212 -4
- 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 +94 -1
- package/dist/types/config.d.ts +6 -0
- package/dist/types/constants.d.ts +16 -1
- package/dist/types/index.d.ts +21 -6
- package/dist/types/metrics/constants.d.ts +19 -1
- package/dist/types/services/ApiAiAssistant.d.ts +11 -3
- package/dist/types/services/UserPreference.d.ts +118 -0
- package/dist/types/services/config/constants.d.ts +21 -0
- package/dist/types/services/config/types.d.ts +171 -10
- package/dist/types/services/core/Err.d.ts +4 -0
- package/dist/types/services/core/Utils.d.ts +33 -13
- 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 +7 -0
- package/dist/types/services/task/dialer.d.ts +30 -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 +603 -66
- 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 +94 -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 +329 -30
- package/src/config.ts +6 -0
- package/src/constants.ts +16 -1
- package/src/index.ts +23 -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 +106 -0
- package/src/metrics/constants.ts +23 -4
- package/src/services/ApiAiAssistant.ts +104 -3
- package/src/services/UserPreference.ts +509 -0
- 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 +3 -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/constants.ts +25 -1
- package/src/services/config/types.ts +174 -11
- package/src/services/core/Err.ts +2 -0
- package/src/services/core/Utils.ts +123 -37
- 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 -613
- 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 +7 -0
- package/src/services/task/dialer.ts +80 -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 +710 -71
- package/src/services/task/voice/Voice.ts +1267 -0
- package/src/services/task/voice/WebRTC.ts +187 -0
- package/src/types.ts +122 -2
- package/src/utils/AGENTS.md +276 -0
- package/src/webex.js +2 -0
- package/test/unit/spec/cc.ts +343 -23
- package/test/unit/spec/logger-proxy.ts +70 -0
- package/test/unit/spec/services/ApiAiAssistant.ts +122 -17
- package/test/unit/spec/services/UserPreference.ts +401 -0
- package/test/unit/spec/services/WebCallingService.ts +7 -1
- package/test/unit/spec/services/config/index.ts +30 -30
- package/test/unit/spec/services/core/Utils.ts +425 -8
- 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 +832 -1702
- package/test/unit/spec/services/task/TaskUtils.ts +206 -0
- package/test/unit/spec/services/task/dialer.ts +190 -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 -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,12 @@ 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 {
|
|
9
|
+
import {
|
|
10
|
+
AIFeatureFlags,
|
|
11
|
+
Profile,
|
|
12
|
+
CreateUserPreferenceRequest,
|
|
13
|
+
UpdateUserPreferenceRequest,
|
|
14
|
+
} from './services/config/types';
|
|
10
15
|
import {PaginatedResponse, BaseSearchParams} from './utils/PageCache';
|
|
11
16
|
|
|
12
17
|
/**
|
|
@@ -156,6 +161,8 @@ export interface CCPluginConfig {
|
|
|
156
161
|
};
|
|
157
162
|
/** Configuration for the calling client */
|
|
158
163
|
callingClientConfig: CallingClientConfig;
|
|
164
|
+
/** Whether to skip Mobius/WebRTC registration for browser login flows */
|
|
165
|
+
disableWebRTCRegistration?: boolean;
|
|
159
166
|
}
|
|
160
167
|
|
|
161
168
|
/**
|
|
@@ -542,7 +549,9 @@ export type RequestBody =
|
|
|
542
549
|
| Contact.cancelCtq
|
|
543
550
|
| Contact.WrapupPayLoad
|
|
544
551
|
| Contact.DialerPayload
|
|
545
|
-
| Contact.PreviewContactPayload
|
|
552
|
+
| Contact.PreviewContactPayload
|
|
553
|
+
| CreateUserPreferenceRequest
|
|
554
|
+
| UpdateUserPreferenceRequest;
|
|
546
555
|
|
|
547
556
|
/**
|
|
548
557
|
* Represents the options to fetch buddy agents for the logged in agent.
|
|
@@ -568,6 +577,25 @@ export type BuddyAgents = {
|
|
|
568
577
|
};
|
|
569
578
|
|
|
570
579
|
/**
|
|
580
|
+
* Holds the configuration flags for the Agent.
|
|
581
|
+
* These flags determine the availability of certain features in the Agent UI.
|
|
582
|
+
* @internal
|
|
583
|
+
*/
|
|
584
|
+
export type ConfigFlags = {
|
|
585
|
+
isEndTaskEnabled: boolean;
|
|
586
|
+
isEndConsultEnabled: boolean;
|
|
587
|
+
webRtcEnabled: boolean;
|
|
588
|
+
autoWrapup: boolean;
|
|
589
|
+
aiFeature?: AIFeatureFlags;
|
|
590
|
+
/**
|
|
591
|
+
* Optional toggle to globally enable/disable recording controls.
|
|
592
|
+
* Falls back to backend hints when omitted.
|
|
593
|
+
*/
|
|
594
|
+
isRecordingEnabled?: boolean;
|
|
595
|
+
};
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
|
|
571
599
|
* Generic error structure for Contact Center SDK errors.
|
|
572
600
|
* Contains detailed information about the error context.
|
|
573
601
|
* @public
|
|
@@ -821,38 +849,130 @@ export type BuddyAgentsResponse = Agent.BuddyAgentsSuccess | Error;
|
|
|
821
849
|
*/
|
|
822
850
|
export type UpdateDeviceTypeResponse = Agent.DeviceTypeUpdateSuccess | Error;
|
|
823
851
|
|
|
852
|
+
/**
|
|
853
|
+
* Supported transcript control actions for AI Assistant events.
|
|
854
|
+
* @public
|
|
855
|
+
* @example
|
|
856
|
+
* const action: TranscriptAction = 'START';
|
|
857
|
+
* @ignore
|
|
858
|
+
*/
|
|
824
859
|
export type TranscriptAction = 'START' | 'STOP';
|
|
825
860
|
|
|
861
|
+
/**
|
|
862
|
+
* Parameters used to request an AI Assistant suggested response.
|
|
863
|
+
* @public
|
|
864
|
+
* @example
|
|
865
|
+
* const params: SuggestedResponseParams = {
|
|
866
|
+
* interactionId: 'interaction-123',
|
|
867
|
+
* actionTimeStamp: Date.now(),
|
|
868
|
+
* context: 'Need help with credit card payment due date',
|
|
869
|
+
* };
|
|
870
|
+
*/
|
|
871
|
+
export type SuggestedResponseParams = {
|
|
872
|
+
/** Agent identifier */
|
|
873
|
+
agentId: string;
|
|
874
|
+
/** Interaction identifier for which suggestion should be generated */
|
|
875
|
+
interactionId: string;
|
|
876
|
+
/** Optional additional context that should refine the suggestion */
|
|
877
|
+
context?: string;
|
|
878
|
+
/** Optional language code for suggestions (for example, 'en'). Defaults to 'en'. */
|
|
879
|
+
languageCode?: string;
|
|
880
|
+
};
|
|
881
|
+
|
|
882
|
+
/**
|
|
883
|
+
* Supported AI Assistant event categories.
|
|
884
|
+
* @public
|
|
885
|
+
* @example
|
|
886
|
+
* const eventType: AIAssistantEventType = AIAssistantEventType.CUSTOM_EVENT;
|
|
887
|
+
* @ignore
|
|
888
|
+
*/
|
|
826
889
|
export const AIAssistantEventType = {
|
|
890
|
+
/** Custom AI Assistant event */
|
|
827
891
|
CUSTOM_EVENT: 'CUSTOM_EVENT',
|
|
892
|
+
/** CTI-backed AI Assistant event */
|
|
828
893
|
CTI_EVENT: 'CTI_EVENT',
|
|
829
894
|
} as const;
|
|
830
895
|
|
|
896
|
+
/**
|
|
897
|
+
* Union type of AI Assistant event categories.
|
|
898
|
+
* @public
|
|
899
|
+
* @example
|
|
900
|
+
* function send(type: AIAssistantEventType) { ... }
|
|
901
|
+
* @ignore
|
|
902
|
+
*/
|
|
831
903
|
export type AIAssistantEventType = Enum<typeof AIAssistantEventType>;
|
|
832
904
|
|
|
905
|
+
/**
|
|
906
|
+
* Supported AI Assistant event names.
|
|
907
|
+
* @public
|
|
908
|
+
* @example
|
|
909
|
+
* const name: AIAssistantEventName = AIAssistantEventName.GET_TRANSCRIPTS;
|
|
910
|
+
* @ignore
|
|
911
|
+
*/
|
|
833
912
|
export const AIAssistantEventName = {
|
|
913
|
+
/** Request transcript streaming for an interaction */
|
|
834
914
|
GET_TRANSCRIPTS: 'GET_TRANSCRIPTS',
|
|
915
|
+
/** Request a suggested response for an interaction */
|
|
916
|
+
GET_SUGGESTIONS: 'GET_SUGGESTIONS',
|
|
917
|
+
/** Add extra context to refine a suggested response */
|
|
918
|
+
ADD_SUGGESTIONS_EXTRA_CONTEXT: 'ADD_SUGGESTIONS_EXTRA_CONTEXT',
|
|
919
|
+
/** Request mid-call summary generation */
|
|
835
920
|
GET_MID_CALL_SUMMARY: 'GET_MID_CALL_SUMMARY',
|
|
921
|
+
/** Request post-call summary generation */
|
|
836
922
|
GET_POST_CALL_SUMMARY: 'GET_POST_CALL_SUMMARY',
|
|
923
|
+
/** Mid-call summary response event */
|
|
837
924
|
MID_CALL_SUMMARY_RESPONSE: 'MID_CALL_SUMMARY_RESPONSE',
|
|
925
|
+
/** Post-call summary response event */
|
|
838
926
|
POST_CALL_SUMMARY_RESPONSE: 'POST_CALL_SUMMARY_RESPONSE',
|
|
927
|
+
/** Suggested digital response event */
|
|
839
928
|
SUGGESTED_RESPONSES_DIGITAL: 'SUGGESTED_RESPONSES_DIGITAL',
|
|
840
929
|
} as const;
|
|
841
930
|
|
|
931
|
+
/**
|
|
932
|
+
* Union type of AI Assistant event names.
|
|
933
|
+
* @public
|
|
934
|
+
* @example
|
|
935
|
+
* function handle(name: AIAssistantEventName) { ... }
|
|
936
|
+
* @ignore
|
|
937
|
+
*/
|
|
842
938
|
export type AIAssistantEventName = Enum<typeof AIAssistantEventName>;
|
|
843
939
|
|
|
940
|
+
/**
|
|
941
|
+
* A single transcript message entry returned by AI Assistant APIs.
|
|
942
|
+
* @public
|
|
943
|
+
* @example
|
|
944
|
+
* const message: TranscriptMessage = { role: 'AGENT', content: 'Hello', messageId: '1', publishTimestamp: Date.now() };
|
|
945
|
+
*
|
|
946
|
+
*/
|
|
844
947
|
export type TranscriptMessage = {
|
|
948
|
+
/** Speaker role for this message */
|
|
845
949
|
role: string;
|
|
950
|
+
/** Transcript chunk content */
|
|
846
951
|
content: string;
|
|
952
|
+
/** Unique message identifier */
|
|
847
953
|
messageId: string;
|
|
954
|
+
/** Message publish timestamp (epoch milliseconds) */
|
|
848
955
|
publishTimestamp: number;
|
|
849
956
|
};
|
|
850
957
|
|
|
958
|
+
/**
|
|
959
|
+
* Response payload for historic transcripts API.
|
|
960
|
+
* @public
|
|
961
|
+
* @example
|
|
962
|
+
* const resp: HistoricTranscriptsResponse = { orgId: 'org', agentId: 'agent', conversationId: null, interactionId: 'int', source: 'AI', data: [] };
|
|
963
|
+
*
|
|
964
|
+
*/
|
|
851
965
|
export type HistoricTranscriptsResponse = {
|
|
966
|
+
/** Organization identifier */
|
|
852
967
|
orgId: string;
|
|
968
|
+
/** Agent identifier */
|
|
853
969
|
agentId: string;
|
|
970
|
+
/** Conversation identifier when available */
|
|
854
971
|
conversationId: string | null;
|
|
972
|
+
/** Interaction identifier */
|
|
855
973
|
interactionId: string;
|
|
974
|
+
/** Data source identifier */
|
|
856
975
|
source: string;
|
|
976
|
+
/** Transcript messages */
|
|
857
977
|
data: TranscriptMessage[];
|
|
858
978
|
};
|
|
@@ -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)
|