@webex/contact-center 3.11.0 → 3.12.0-llmrefactor.2
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/.sdd/manifest.json +882 -0
- package/AGENTS.md +94 -0
- package/ai-docs/ARCHITECTURE.md +168 -0
- package/ai-docs/CONTRACTS.md +46 -0
- package/ai-docs/GETTING_STARTED.md +168 -0
- package/ai-docs/GLOSSARY.md +43 -0
- package/ai-docs/README.md +138 -0
- package/ai-docs/REVIEW_CHECKLIST.md +41 -0
- package/ai-docs/RULES.md +444 -0
- package/ai-docs/SECURITY.md +52 -0
- package/ai-docs/SERVICE_STATE.md +48 -0
- package/ai-docs/SPEC_INDEX.md +65 -0
- package/ai-docs/adr/0001-spec-source-policy.md +55 -0
- package/ai-docs/adr/README.md +8 -0
- package/ai-docs/adr/_adr-template.md +31 -0
- package/ai-docs/contact-center-spec.md +341 -0
- package/ai-docs/features/generated-spec-conformance-fidelity-remediation/spec/feature-spec.md +117 -0
- package/ai-docs/features/residual-warning-coverage-completion/spec/feature-spec.md +203 -0
- package/ai-docs/features/validator-code-fidelity-drift-fix/spec/feature-spec.md +315 -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 +379 -50
- package/dist/cc.js.map +1 -1
- package/dist/config.js +6 -0
- package/dist/config.js.map +1 -1
- package/dist/constants.js +22 -2
- package/dist/constants.js.map +1 -1
- package/dist/index.js +27 -5
- package/dist/index.js.map +1 -1
- package/dist/metrics/behavioral-events.js +114 -0
- package/dist/metrics/behavioral-events.js.map +1 -1
- package/dist/metrics/constants.js +32 -3
- package/dist/metrics/constants.js.map +1 -1
- package/dist/services/ApiAiAssistant.js +318 -0
- package/dist/services/ApiAiAssistant.js.map +1 -0
- package/dist/services/UserPreference.js +427 -0
- package/dist/services/UserPreference.js.map +1 -0
- package/dist/services/agent/types.js.map +1 -1
- package/dist/services/config/Util.js +8 -4
- package/dist/services/config/Util.js.map +1 -1
- package/dist/services/config/constants.js +35 -2
- package/dist/services/config/constants.js.map +1 -1
- package/dist/services/config/index.js +41 -2
- package/dist/services/config/index.js.map +1 -1
- package/dist/services/config/types.js +66 -8
- package/dist/services/config/types.js.map +1 -1
- package/dist/services/constants.js +27 -1
- package/dist/services/constants.js.map +1 -1
- package/dist/services/core/Err.js.map +1 -1
- package/dist/services/core/Utils.js +122 -25
- package/dist/services/core/Utils.js.map +1 -1
- package/dist/services/core/aqm-reqs.js +92 -17
- package/dist/services/core/aqm-reqs.js.map +1 -1
- package/dist/services/core/websocket/WebSocketManager.js +22 -6
- package/dist/services/core/websocket/WebSocketManager.js.map +1 -1
- package/dist/services/core/websocket/connection-service.js +3 -1
- package/dist/services/core/websocket/connection-service.js.map +1 -1
- package/dist/services/core/websocket/types.js.map +1 -1
- package/dist/services/index.js +6 -0
- 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 +751 -457
- package/dist/services/task/TaskManager.js.map +1 -1
- package/dist/services/task/TaskUtils.js +220 -23
- package/dist/services/task/TaskUtils.js.map +1 -1
- package/dist/services/task/constants.js +23 -2
- package/dist/services/task/constants.js.map +1 -1
- package/dist/services/task/dialer.js +129 -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 +873 -0
- package/dist/services/task/state-machine/TaskStateMachine.js.map +1 -0
- package/dist/services/task/state-machine/actions.js +567 -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 +382 -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 +603 -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 +227 -4
- package/dist/services/task/types.js.map +1 -1
- package/dist/services/task/voice/Voice.js +1044 -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 +894 -0
- package/dist/types/config.d.ts +72 -0
- package/dist/types/constants.d.ts +66 -0
- package/dist/types/index.d.ts +199 -0
- package/dist/types/logger-proxy.d.ts +71 -0
- package/dist/types/metrics/MetricsManager.d.ts +223 -0
- package/dist/types/metrics/behavioral-events.d.ts +29 -0
- package/dist/types/metrics/constants.d.ts +181 -0
- package/dist/types/services/AddressBook.d.ts +74 -0
- package/dist/types/services/ApiAiAssistant.d.ts +49 -0
- package/dist/types/services/EntryPoint.d.ts +67 -0
- package/dist/types/services/Queue.d.ts +76 -0
- package/dist/types/services/UserPreference.d.ts +118 -0
- package/dist/types/services/WebCallingService.d.ts +1 -0
- package/dist/types/services/agent/index.d.ts +46 -0
- package/dist/types/services/agent/types.d.ts +413 -0
- package/dist/types/services/config/Util.d.ts +20 -0
- package/dist/types/services/config/constants.d.ts +270 -0
- package/dist/types/services/config/index.d.ts +177 -0
- package/dist/types/services/config/types.d.ts +1368 -0
- package/dist/types/services/constants.d.ts +110 -0
- package/dist/types/services/core/Err.d.ts +125 -0
- package/dist/types/services/core/GlobalTypes.d.ts +58 -0
- package/dist/types/services/core/Utils.d.ts +121 -0
- package/dist/types/services/core/WebexRequest.d.ts +22 -0
- package/dist/types/services/core/aqm-reqs.d.ts +65 -0
- package/dist/types/services/core/constants.d.ts +99 -0
- package/dist/types/services/core/types.d.ts +47 -0
- package/dist/types/services/core/websocket/WebSocketManager.d.ts +36 -0
- package/dist/types/services/core/websocket/connection-service.d.ts +27 -0
- package/dist/types/services/core/websocket/keepalive.worker.d.ts +2 -0
- package/dist/types/services/core/websocket/types.d.ts +37 -0
- package/dist/types/services/index.d.ts +54 -0
- package/dist/types/services/task/AutoWrapup.d.ts +40 -0
- 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/TaskManager.d.ts +1 -0
- package/dist/types/services/task/TaskUtils.d.ts +138 -0
- package/dist/types/services/task/constants.d.ts +91 -0
- package/dist/types/services/task/contact.d.ts +69 -0
- package/dist/types/services/task/dialer.d.ts +73 -0
- package/dist/types/services/task/digital/Digital.d.ts +22 -0
- package/dist/types/services/task/state-machine/TaskStateMachine.d.ts +1194 -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 +102 -0
- package/dist/types/services/task/state-machine/index.d.ts +13 -0
- package/dist/types/services/task/state-machine/types.d.ts +269 -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 +1856 -0
- 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 +778 -0
- package/dist/types/utils/PageCache.d.ts +173 -0
- package/dist/types/webex-config.d.ts +53 -0
- package/dist/types/webex.d.ts +8 -0
- package/dist/types.js +130 -1
- package/dist/types.js.map +1 -1
- package/dist/webex.js +14 -2
- package/dist/webex.js.map +1 -1
- package/package.json +16 -12
- package/src/cc.ts +477 -51
- package/src/config.ts +6 -0
- package/src/constants.ts +21 -1
- package/src/index.ts +24 -5
- package/src/metrics/ai-docs/AGENTS.md +350 -0
- package/src/metrics/ai-docs/ARCHITECTURE.md +338 -0
- package/src/metrics/ai-docs/metrics-spec.md +854 -0
- package/src/metrics/behavioral-events.ts +120 -0
- package/src/metrics/constants.ts +37 -3
- package/src/services/ApiAiAssistant.ts +412 -0
- package/src/services/UserPreference.ts +509 -0
- package/src/services/agent/ai-docs/AGENTS.md +240 -0
- package/src/services/agent/ai-docs/ARCHITECTURE.md +304 -0
- package/src/services/agent/ai-docs/agent-spec.md +504 -0
- package/src/services/agent/types.ts +1 -1
- package/src/services/ai-docs/AGENTS.md +386 -0
- package/src/services/ai-docs/services-spec.md +492 -0
- package/src/services/config/Util.ts +10 -2
- package/src/services/config/ai-docs/AGENTS.md +255 -0
- package/src/services/config/ai-docs/ARCHITECTURE.md +426 -0
- package/src/services/config/ai-docs/config-spec.md +669 -0
- package/src/services/config/constants.ts +37 -1
- package/src/services/config/index.ts +45 -1
- package/src/services/config/types.ts +241 -11
- package/src/services/constants.ts +29 -0
- package/src/services/core/Err.ts +3 -0
- package/src/services/core/Utils.ts +143 -30
- package/src/services/core/ai-docs/AGENTS.md +381 -0
- package/src/services/core/ai-docs/ARCHITECTURE.md +698 -0
- package/src/services/core/ai-docs/core-spec.md +783 -0
- package/src/services/core/aqm-reqs.ts +100 -22
- package/src/services/core/websocket/WebSocketManager.ts +23 -6
- package/src/services/core/websocket/connection-service.ts +5 -1
- package/src/services/core/websocket/types.ts +1 -1
- package/src/services/index.ts +4 -0
- package/src/services/task/Task.ts +837 -0
- package/src/services/task/TaskFactory.ts +55 -0
- package/src/services/task/TaskManager.ts +793 -521
- package/src/services/task/TaskUtils.ts +314 -24
- package/src/services/task/ai-docs/AGENTS.md +457 -0
- package/src/services/task/ai-docs/ARCHITECTURE.md +594 -0
- package/src/services/task/ai-docs/task-spec.md +1319 -0
- package/src/services/task/constants.ts +23 -0
- package/src/services/task/dialer.ts +136 -1
- package/src/services/task/digital/Digital.ts +95 -0
- package/src/services/task/state-machine/TaskStateMachine.ts +1166 -0
- package/src/services/task/state-machine/actions.ts +738 -0
- package/src/services/task/state-machine/ai-docs/AGENTS.md +458 -0
- package/src/services/task/state-machine/ai-docs/ARCHITECTURE.md +1137 -0
- package/src/services/task/state-machine/ai-docs/task-state-machine-spec.md +2177 -0
- package/src/services/task/state-machine/constants.ts +172 -0
- package/src/services/task/state-machine/guards.ts +445 -0
- package/src/services/task/state-machine/index.ts +28 -0
- package/src/services/task/state-machine/types.ts +243 -0
- package/src/services/task/state-machine/uiControlsComputer.ts +961 -0
- package/src/services/task/taskDataNormalizer.ts +137 -0
- package/src/services/task/types.ts +734 -71
- package/src/services/task/voice/Voice.ts +1270 -0
- package/src/services/task/voice/WebRTC.ts +187 -0
- package/src/types.ts +205 -2
- package/src/utils/AGENTS.md +278 -0
- package/src/utils/ai-docs/utils-spec.md +381 -0
- package/src/webex.js +2 -0
- package/test/unit/spec/cc.ts +503 -43
- package/test/unit/spec/logger-proxy.ts +70 -0
- package/test/unit/spec/services/ApiAiAssistant.ts +273 -0
- 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 +85 -29
- package/test/unit/spec/services/core/Utils.ts +481 -2
- package/test/unit/spec/services/core/websocket/WebSocketManager.ts +137 -41
- package/test/unit/spec/services/core/websocket/connection-service.ts +3 -1
- 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 +1001 -1003
- package/test/unit/spec/services/task/TaskUtils.ts +235 -0
- package/test/unit/spec/services/task/dialer.ts +372 -96
- package/test/unit/spec/services/task/digital/Digital.ts +105 -0
- package/test/unit/spec/services/task/state-machine/TaskStateMachine.ts +2651 -0
- package/test/unit/spec/services/task/state-machine/guards.ts +637 -0
- package/test/unit/spec/services/task/state-machine/types.ts +18 -0
- package/test/unit/spec/services/task/state-machine/uiControlsComputer.ts +2663 -0
- package/test/unit/spec/services/task/taskTestUtils.ts +87 -0
- package/test/unit/spec/services/task/voice/Voice.ts +649 -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/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
|
/**
|
|
@@ -295,6 +302,8 @@ interface IWebexInternal {
|
|
|
295
302
|
get: (service: string) => string;
|
|
296
303
|
/** Wait for service catalog to be loaded */
|
|
297
304
|
waitForCatalog: (service: string) => Promise<void>;
|
|
305
|
+
/** Check if current environment is INT (integration) */
|
|
306
|
+
isIntegrationEnvironment: () => boolean;
|
|
298
307
|
/** Host catalog for service discovery */
|
|
299
308
|
_hostCatalog: Record<string, ServiceHost[]>;
|
|
300
309
|
/** Service URLs cache */
|
|
@@ -539,7 +548,10 @@ export type RequestBody =
|
|
|
539
548
|
| Contact.ConsultTransferPayLoad
|
|
540
549
|
| Contact.cancelCtq
|
|
541
550
|
| Contact.WrapupPayLoad
|
|
542
|
-
| Contact.DialerPayload
|
|
551
|
+
| Contact.DialerPayload
|
|
552
|
+
| Contact.PreviewContactPayload
|
|
553
|
+
| CreateUserPreferenceRequest
|
|
554
|
+
| UpdateUserPreferenceRequest;
|
|
543
555
|
|
|
544
556
|
/**
|
|
545
557
|
* Represents the options to fetch buddy agents for the logged in agent.
|
|
@@ -565,6 +577,25 @@ export type BuddyAgents = {
|
|
|
565
577
|
};
|
|
566
578
|
|
|
567
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
|
+
|
|
568
599
|
* Generic error structure for Contact Center SDK errors.
|
|
569
600
|
* Contains detailed information about the error context.
|
|
570
601
|
* @public
|
|
@@ -817,3 +848,175 @@ export type BuddyAgentsResponse = Agent.BuddyAgentsSuccess | Error;
|
|
|
817
848
|
* function handleUpdateDeviceType(resp: UpdateDeviceTypeResponse) { ... }
|
|
818
849
|
*/
|
|
819
850
|
export type UpdateDeviceTypeResponse = Agent.DeviceTypeUpdateSuccess | Error;
|
|
851
|
+
|
|
852
|
+
/**
|
|
853
|
+
* Supported transcript control actions for AI Assistant events.
|
|
854
|
+
* @public
|
|
855
|
+
* @example
|
|
856
|
+
* const action: TranscriptAction = 'START';
|
|
857
|
+
* @ignore
|
|
858
|
+
*/
|
|
859
|
+
export type TranscriptAction = 'START' | 'STOP';
|
|
860
|
+
|
|
861
|
+
/**
|
|
862
|
+
* Parameters used to request AI Assistant real-time assistance.
|
|
863
|
+
* @public
|
|
864
|
+
* @example
|
|
865
|
+
* const params: RealTimeAssistanceParams = {
|
|
866
|
+
* interactionId: 'interaction-123',
|
|
867
|
+
* context: 'Need help with credit card payment due date',
|
|
868
|
+
* };
|
|
869
|
+
*/
|
|
870
|
+
export type RealTimeAssistanceParams = {
|
|
871
|
+
/** Agent identifier */
|
|
872
|
+
agentId: string;
|
|
873
|
+
/** Interaction identifier for which assistance should be generated */
|
|
874
|
+
interactionId: string;
|
|
875
|
+
/** Optional additional context that should refine the assistance */
|
|
876
|
+
context?: string;
|
|
877
|
+
/** Optional language code for assistance (for example, 'en'). Defaults to 'en'. */
|
|
878
|
+
languageCode?: string;
|
|
879
|
+
};
|
|
880
|
+
|
|
881
|
+
/**
|
|
882
|
+
* Supported user actions on an AI Assistant real-time assistance adaptive card.
|
|
883
|
+
* @public
|
|
884
|
+
*/
|
|
885
|
+
export const RealTimeAssistanceUserActionId = {
|
|
886
|
+
/** User liked the real-time assistance response */
|
|
887
|
+
LIKE: 'likeButton',
|
|
888
|
+
/** User disliked the real-time assistance response */
|
|
889
|
+
DISLIKE: 'dislikeButton',
|
|
890
|
+
/** User copied the real-time assistance response */
|
|
891
|
+
COPY: 'copyButton',
|
|
892
|
+
} as const;
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
* Union type of supported real-time assistance user actions.
|
|
896
|
+
* @public
|
|
897
|
+
*/
|
|
898
|
+
export type RealTimeAssistanceUserActionId = Enum<typeof RealTimeAssistanceUserActionId>;
|
|
899
|
+
|
|
900
|
+
/**
|
|
901
|
+
* Parameters used to send user action feedback for a real-time assistance adaptive card.
|
|
902
|
+
* @public
|
|
903
|
+
* @example
|
|
904
|
+
* const params: RealTimeAssistanceUserActionParams = {
|
|
905
|
+
* agentId: 'agent-123',
|
|
906
|
+
* interactionId: 'interaction-123',
|
|
907
|
+
* adaptiveCardId: 'adaptive-card-123',
|
|
908
|
+
* actionId: RealTimeAssistanceUserActionId.LIKE,
|
|
909
|
+
* };
|
|
910
|
+
*/
|
|
911
|
+
export type RealTimeAssistanceUserActionParams = {
|
|
912
|
+
/** Agent identifier */
|
|
913
|
+
agentId: string;
|
|
914
|
+
/** Interaction identifier associated with the real-time assistance response */
|
|
915
|
+
interactionId: string;
|
|
916
|
+
/** Adaptive card identifier from the real-time assistance payload */
|
|
917
|
+
adaptiveCardId: string;
|
|
918
|
+
/** User action performed on the adaptive card */
|
|
919
|
+
actionId: RealTimeAssistanceUserActionId;
|
|
920
|
+
/** Optional language code. Defaults to 'en'. */
|
|
921
|
+
languageCode?: string;
|
|
922
|
+
};
|
|
923
|
+
|
|
924
|
+
/**
|
|
925
|
+
* Supported AI Assistant event categories.
|
|
926
|
+
* @public
|
|
927
|
+
* @example
|
|
928
|
+
* const eventType: AIAssistantEventType = AIAssistantEventType.CUSTOM_EVENT;
|
|
929
|
+
* @ignore
|
|
930
|
+
*/
|
|
931
|
+
export const AIAssistantEventType = {
|
|
932
|
+
/** Custom AI Assistant event */
|
|
933
|
+
CUSTOM_EVENT: 'CUSTOM_EVENT',
|
|
934
|
+
/** CTI-backed AI Assistant event */
|
|
935
|
+
CTI_EVENT: 'CTI_EVENT',
|
|
936
|
+
} as const;
|
|
937
|
+
|
|
938
|
+
/**
|
|
939
|
+
* Union type of AI Assistant event categories.
|
|
940
|
+
* @public
|
|
941
|
+
* @example
|
|
942
|
+
* function send(type: AIAssistantEventType) { ... }
|
|
943
|
+
* @ignore
|
|
944
|
+
*/
|
|
945
|
+
export type AIAssistantEventType = Enum<typeof AIAssistantEventType>;
|
|
946
|
+
|
|
947
|
+
/**
|
|
948
|
+
* Supported AI Assistant event names.
|
|
949
|
+
* @public
|
|
950
|
+
* @example
|
|
951
|
+
* const name: AIAssistantEventName = AIAssistantEventName.GET_TRANSCRIPTS;
|
|
952
|
+
* @ignore
|
|
953
|
+
*/
|
|
954
|
+
export const AIAssistantEventName = {
|
|
955
|
+
/** Request transcript streaming for an interaction */
|
|
956
|
+
GET_TRANSCRIPTS: 'GET_TRANSCRIPTS',
|
|
957
|
+
/** Request a suggested response for an interaction */
|
|
958
|
+
GET_SUGGESTIONS: 'GET_SUGGESTIONS',
|
|
959
|
+
/** Add extra context to refine a suggested response */
|
|
960
|
+
ADD_SUGGESTIONS_EXTRA_CONTEXT: 'ADD_SUGGESTIONS_EXTRA_CONTEXT',
|
|
961
|
+
/** Request mid-call summary generation */
|
|
962
|
+
GET_MID_CALL_SUMMARY: 'GET_MID_CALL_SUMMARY',
|
|
963
|
+
/** Request post-call summary generation */
|
|
964
|
+
GET_POST_CALL_SUMMARY: 'GET_POST_CALL_SUMMARY',
|
|
965
|
+
/** Mid-call summary response event */
|
|
966
|
+
MID_CALL_SUMMARY_RESPONSE: 'MID_CALL_SUMMARY_RESPONSE',
|
|
967
|
+
/** Post-call summary response event */
|
|
968
|
+
POST_CALL_SUMMARY_RESPONSE: 'POST_CALL_SUMMARY_RESPONSE',
|
|
969
|
+
/** Suggested digital response event */
|
|
970
|
+
SUGGESTED_RESPONSES_DIGITAL: 'SUGGESTED_RESPONSES_DIGITAL',
|
|
971
|
+
/** User action on a suggested response adaptive card */
|
|
972
|
+
SUGGESTED_RESPONSES_USER_ACTION: 'SUGGESTED_RESPONSES_USER_ACTION',
|
|
973
|
+
} as const;
|
|
974
|
+
|
|
975
|
+
/**
|
|
976
|
+
* Union type of AI Assistant event names.
|
|
977
|
+
* @public
|
|
978
|
+
* @example
|
|
979
|
+
* function handle(name: AIAssistantEventName) { ... }
|
|
980
|
+
* @ignore
|
|
981
|
+
*/
|
|
982
|
+
export type AIAssistantEventName = Enum<typeof AIAssistantEventName>;
|
|
983
|
+
|
|
984
|
+
/**
|
|
985
|
+
* A single transcript message entry returned by AI Assistant APIs.
|
|
986
|
+
* @public
|
|
987
|
+
* @example
|
|
988
|
+
* const message: TranscriptMessage = { role: 'AGENT', content: 'Hello', messageId: '1', publishTimestamp: Date.now() };
|
|
989
|
+
*
|
|
990
|
+
*/
|
|
991
|
+
export type TranscriptMessage = {
|
|
992
|
+
/** Speaker role for this message */
|
|
993
|
+
role: string;
|
|
994
|
+
/** Transcript chunk content */
|
|
995
|
+
content: string;
|
|
996
|
+
/** Unique message identifier */
|
|
997
|
+
messageId: string;
|
|
998
|
+
/** Message publish timestamp (epoch milliseconds) */
|
|
999
|
+
publishTimestamp: number;
|
|
1000
|
+
};
|
|
1001
|
+
|
|
1002
|
+
/**
|
|
1003
|
+
* Response payload for historic transcripts API.
|
|
1004
|
+
* @public
|
|
1005
|
+
* @example
|
|
1006
|
+
* const resp: HistoricTranscriptsResponse = { orgId: 'org', agentId: 'agent', conversationId: null, interactionId: 'int', source: 'AI', data: [] };
|
|
1007
|
+
*
|
|
1008
|
+
*/
|
|
1009
|
+
export type HistoricTranscriptsResponse = {
|
|
1010
|
+
/** Organization identifier */
|
|
1011
|
+
orgId: string;
|
|
1012
|
+
/** Agent identifier */
|
|
1013
|
+
agentId: string;
|
|
1014
|
+
/** Conversation identifier when available */
|
|
1015
|
+
conversationId: string | null;
|
|
1016
|
+
/** Interaction identifier */
|
|
1017
|
+
interactionId: string;
|
|
1018
|
+
/** Data source identifier */
|
|
1019
|
+
source: string;
|
|
1020
|
+
/** Transcript messages */
|
|
1021
|
+
data: TranscriptMessage[];
|
|
1022
|
+
};
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
# Utils
|
|
2
|
+
|
|
3
|
+
> **Legacy/reference-only.** Canonical SDD: [`ai-docs/utils-spec.md`](ai-docs/utils-spec.md). Use the package [manifest](../../.sdd/manifest.json) and [`SPEC_INDEX.md`](../../ai-docs/SPEC_INDEX.md) for routing; code and tests remain the behavioral referee.
|
|
4
|
+
>
|
|
5
|
+
> **Legacy scope:** This guide covers shared pagination/cache contracts used by data services. For repository rules and cross-service conventions, see the [root orchestrator AGENTS.md](../../AGENTS.md).
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Key Capabilities
|
|
10
|
+
|
|
11
|
+
The utils scope currently provides shared pagination and cache behavior for contact-center data services:
|
|
12
|
+
|
|
13
|
+
- **Typed Pagination Contracts**: Reusable interfaces for response metadata and query params
|
|
14
|
+
- **Generic In-Memory Page Caching**: `PageCache<T>` utility for simple pagination reuse
|
|
15
|
+
- **Cache Safety Rules**: Explicit bypass behavior for search/filter/sort scenarios
|
|
16
|
+
- **Spec-Driven Utility Workflow**: Utility-specific implementation and validation flow documented inline in this file
|
|
17
|
+
|
|
18
|
+
| Component | File | Description |
|
|
19
|
+
| --------------------- | -------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
20
|
+
| `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. |
|
|
21
|
+
| `Pagination Types` | [`PageCache.ts`](./PageCache.ts) | `PaginationMeta`, `PaginatedResponse<T>`, `BaseSearchParams`, and `PageCacheEntry<T>` shared across data services. |
|
|
22
|
+
| `Pagination Defaults` | [`PageCache.ts`](./PageCache.ts) | `PAGINATION_DEFAULTS` (`PAGE`, `PAGE_SIZE`) used by services for consistent request defaults. |
|
|
23
|
+
| `Specs Workflow` | `AGENTS.md` (inline) | Mermaid flow for specs-driven utility changes, acceptance criteria, and drift checks. |
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## File Structure
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
src/utils/
|
|
31
|
+
├── AGENTS.md # This file: utils scope guide
|
|
32
|
+
└── PageCache.ts # Generic cache + pagination contracts/defaults
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## PageCache Utility
|
|
38
|
+
|
|
39
|
+
`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`).
|
|
40
|
+
|
|
41
|
+
### Reference Usage
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import PageCache, {PAGINATION_DEFAULTS} from '../utils/PageCache';
|
|
45
|
+
|
|
46
|
+
const cache = new PageCache<MyItem>('MyService');
|
|
47
|
+
|
|
48
|
+
const page = PAGINATION_DEFAULTS.PAGE;
|
|
49
|
+
const pageSize = PAGINATION_DEFAULTS.PAGE_SIZE;
|
|
50
|
+
const cacheKey = cache.buildCacheKey(scopeId, page, pageSize);
|
|
51
|
+
|
|
52
|
+
// Include sortBy only for services that support sorting.
|
|
53
|
+
const canUseCache = cache.canUseCache({search, filter, attributes, sortBy});
|
|
54
|
+
|
|
55
|
+
if (canUseCache) {
|
|
56
|
+
const cachedEntry = cache.getCachedPage(cacheKey);
|
|
57
|
+
if (cachedEntry) {
|
|
58
|
+
return {
|
|
59
|
+
data: cachedEntry.data,
|
|
60
|
+
meta: {
|
|
61
|
+
page,
|
|
62
|
+
pageSize,
|
|
63
|
+
...cachedEntry.totalMeta,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const response = await fetchPageFromApi();
|
|
70
|
+
|
|
71
|
+
if (canUseCache && response.data) {
|
|
72
|
+
cache.cachePage(cacheKey, response.data, response.meta);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return response;
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Cache Lifecycle
|
|
79
|
+
|
|
80
|
+
```mermaid
|
|
81
|
+
graph TD
|
|
82
|
+
A[Request arrives with scopeId/page/pageSize] --> B{canUseCache?}
|
|
83
|
+
B -->|No: search/filter/attributes/sortBy provided| C[Bypass cache and call API]
|
|
84
|
+
B -->|Yes| D[buildCacheKey scopeId:page:pageSize]
|
|
85
|
+
D --> E["getCachedPage(cacheKey)"]
|
|
86
|
+
E -->|Miss| C
|
|
87
|
+
E -->|Hit and not expired| F[Return cached data and totalMeta]
|
|
88
|
+
E -->|Hit but expired >= 5 minutes| G[Delete entry and treat as miss]
|
|
89
|
+
G --> C
|
|
90
|
+
C --> H[Receive API response]
|
|
91
|
+
H --> I["cachePage(cacheKey, data, meta)"]
|
|
92
|
+
I --> J[Return fresh response]
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## Public Contracts
|
|
98
|
+
|
|
99
|
+
All public contracts for utils are defined in [`PageCache.ts`](./PageCache.ts).
|
|
100
|
+
|
|
101
|
+
### `PaginationMeta`
|
|
102
|
+
|
|
103
|
+
Common pagination metadata used across list APIs.
|
|
104
|
+
|
|
105
|
+
| Field | Type | Notes |
|
|
106
|
+
| ----------------------------- | ------------------------ | ----------------------- |
|
|
107
|
+
| `orgid` | `string` | Organization identifier |
|
|
108
|
+
| `page` / `currentPage` | `number` | Current page aliases |
|
|
109
|
+
| `pageSize` | `number` | Items per page |
|
|
110
|
+
| `totalPages` | `number` | Total page count |
|
|
111
|
+
| `totalRecords` / `totalItems` | `number` | Total item aliases |
|
|
112
|
+
| `links` | `Record<string, string>` | Pagination link map |
|
|
113
|
+
|
|
114
|
+
### `PaginatedResponse<T>`
|
|
115
|
+
|
|
116
|
+
Canonical paginated response type:
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
interface PaginatedResponse<T> {
|
|
120
|
+
data: T[];
|
|
121
|
+
meta: PaginationMeta;
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### `PageCacheEntry<T>`
|
|
126
|
+
|
|
127
|
+
Shape of a cached page entry returned by `getCachedPage()`:
|
|
128
|
+
|
|
129
|
+
- `data: T[]`
|
|
130
|
+
- `timestamp: number` (epoch milliseconds)
|
|
131
|
+
- `totalMeta?: { totalPages?: number; totalRecords?: number }`
|
|
132
|
+
|
|
133
|
+
### `CacheValidationParams`
|
|
134
|
+
|
|
135
|
+
Contract passed to `canUseCache()`:
|
|
136
|
+
|
|
137
|
+
- `search?: string`
|
|
138
|
+
- `filter?: string`
|
|
139
|
+
- `attributes?: string`
|
|
140
|
+
- `sortBy?: string`
|
|
141
|
+
|
|
142
|
+
Behavior note:
|
|
143
|
+
|
|
144
|
+
- Cache bypass is triggered by `sortBy`, not by `sortOrder` alone.
|
|
145
|
+
- If a new service treats `sortOrder` as meaningful without `sortBy`, extend `CacheValidationParams` and `canUseCache()` together.
|
|
146
|
+
|
|
147
|
+
### `BaseSearchParams`
|
|
148
|
+
|
|
149
|
+
Common query parameter contract with pagination and sorting:
|
|
150
|
+
|
|
151
|
+
- `search`, `filter`, `attributes`
|
|
152
|
+
- `page`, `pageSize`
|
|
153
|
+
- `sortBy`, `sortOrder`
|
|
154
|
+
|
|
155
|
+
### `PAGINATION_DEFAULTS`
|
|
156
|
+
|
|
157
|
+
Standard defaults exported for callers:
|
|
158
|
+
|
|
159
|
+
- `PAGE: 0`
|
|
160
|
+
- `PAGE_SIZE: 100`
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## PageCache API
|
|
165
|
+
|
|
166
|
+
### `constructor(apiName: string)`
|
|
167
|
+
|
|
168
|
+
Creates a typed cache instance and stores `apiName` for `LoggerProxy` context.
|
|
169
|
+
|
|
170
|
+
### `canUseCache(params: CacheValidationParams): boolean`
|
|
171
|
+
|
|
172
|
+
Returns `true` only when all of these are absent:
|
|
173
|
+
|
|
174
|
+
- `search`
|
|
175
|
+
- `filter`
|
|
176
|
+
- `attributes`
|
|
177
|
+
- `sortBy`
|
|
178
|
+
|
|
179
|
+
`sortOrder` alone does not trigger cache bypass because `CacheValidationParams` currently keys bypass on fields that materially change the query result set in existing consumers.
|
|
180
|
+
|
|
181
|
+
### `buildCacheKey(scopeId: string, page: number, pageSize: number): string`
|
|
182
|
+
|
|
183
|
+
Builds deterministic cache key format:
|
|
184
|
+
|
|
185
|
+
```text
|
|
186
|
+
${scopeId}:${page}:${pageSize}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### `getCachedPage(cacheKey: string): PageCacheEntry<T> | null`
|
|
190
|
+
|
|
191
|
+
Behavior:
|
|
192
|
+
|
|
193
|
+
1. Returns `null` if key not found
|
|
194
|
+
2. Computes cache age in minutes
|
|
195
|
+
3. If age is `>= 5`, logs expiry, deletes entry, returns `null`
|
|
196
|
+
4. Otherwise returns cached entry
|
|
197
|
+
|
|
198
|
+
### `cachePage(cacheKey: string, data: T[], meta?: any): void`
|
|
199
|
+
|
|
200
|
+
Stores entry with:
|
|
201
|
+
|
|
202
|
+
- `data`
|
|
203
|
+
- `timestamp`
|
|
204
|
+
- `totalMeta.totalPages`
|
|
205
|
+
- `totalMeta.totalRecords` mapped from `meta.totalRecords || meta.totalItems`
|
|
206
|
+
|
|
207
|
+
### `clearCache(): void`
|
|
208
|
+
|
|
209
|
+
Clears all entries and logs cleared entry count.
|
|
210
|
+
|
|
211
|
+
### `getCacheSize(): number`
|
|
212
|
+
|
|
213
|
+
Returns current in-memory entry count.
|
|
214
|
+
|
|
215
|
+
Note: `clearCache()` and `getCacheSize()` are available for future use and are not currently called by existing consumers.
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## Consumer Map
|
|
220
|
+
|
|
221
|
+
Current consumers of `PageCache` and defaults:
|
|
222
|
+
|
|
223
|
+
| Consumer | File | Usage |
|
|
224
|
+
| ----------------------- | ---------------------------------------------------------- | ------------------------------------------------------------ |
|
|
225
|
+
| `AddressBook` | [`../services/AddressBook.ts`](../services/AddressBook.ts) | Caches paged address-book responses |
|
|
226
|
+
| `EntryPoint` | [`../services/EntryPoint.ts`](../services/EntryPoint.ts) | Caches paged entry-point responses |
|
|
227
|
+
| `Queue` | [`../services/Queue.ts`](../services/Queue.ts) | Caches paged queue responses |
|
|
228
|
+
| `Public type contracts` | [`../types.ts`](../types.ts) | Re-exports pagination/search contracts into SDK-facing types |
|
|
229
|
+
|
|
230
|
+
Cross-scope mention:
|
|
231
|
+
|
|
232
|
+
- Services-layer docs reference utils caching contracts at [`../services/ai-docs/AGENTS.md`](../services/ai-docs/AGENTS.md).
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
## Spec-Driven Utility Changes
|
|
237
|
+
|
|
238
|
+
When changing `src/utils` behavior or contracts:
|
|
239
|
+
|
|
240
|
+
1. Follow the workflow diagram below
|
|
241
|
+
2. Define acceptance criteria for contract and runtime behavior
|
|
242
|
+
3. Verify cache TTL, bypass rules, and key schema
|
|
243
|
+
4. Validate no spec drift before shipping
|
|
244
|
+
|
|
245
|
+
```mermaid
|
|
246
|
+
flowchart TD
|
|
247
|
+
A[Change proposed in src/utils] --> B{Classify change scope}
|
|
248
|
+
B -->|Contract change| C[Document expected API/type behavior]
|
|
249
|
+
B -->|Runtime behavior change| D[Document cache behavior and TTL impact]
|
|
250
|
+
B -->|Both| C
|
|
251
|
+
C --> E[Update utils AGENTS.md contracts and consumer map]
|
|
252
|
+
D --> F[Validate cache key schema and bypass conditions]
|
|
253
|
+
E --> G[Run drift check against PageCache.ts and consumer services]
|
|
254
|
+
F --> G
|
|
255
|
+
G --> H{Behavior and docs aligned?}
|
|
256
|
+
H -->|No| I[Revise implementation/docs and re-validate]
|
|
257
|
+
I --> G
|
|
258
|
+
H -->|Yes| J[Prepare PR with acceptance criteria and evidence]
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
## Validation Checklist
|
|
264
|
+
|
|
265
|
+
- [ ] Public types remain backward-compatible or migration is documented
|
|
266
|
+
- [ ] `PAGINATION_DEFAULTS` changes are intentional and propagated to consumers
|
|
267
|
+
- [ ] Cache TTL behavior remains explicit and covered by tests
|
|
268
|
+
- [ ] `canUseCache()` bypass conditions are unchanged or intentionally updated
|
|
269
|
+
- [ ] `totalRecords`/`totalItems` mapping behavior is preserved
|
|
270
|
+
- [ ] Logging still uses `LoggerProxy` with `module` and `method`
|
|
271
|
+
- [ ] AddressBook/EntryPoint/Queue integration behavior remains correct
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## Related
|
|
276
|
+
|
|
277
|
+
- [Root orchestrator AGENTS.md](../../AGENTS.md) - Task routing and critical package rules
|
|
278
|
+
- [PageCache implementation](./PageCache.ts)
|