@webex/contact-center 3.12.0-next.9 → 3.12.0-next.90

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.
Files changed (229) hide show
  1. package/.sdd/manifest.json +876 -0
  2. package/AGENTS.md +94 -0
  3. package/ai-docs/ARCHITECTURE.md +168 -0
  4. package/ai-docs/CONTRACTS.md +46 -0
  5. package/ai-docs/GETTING_STARTED.md +168 -0
  6. package/ai-docs/GLOSSARY.md +43 -0
  7. package/ai-docs/README.md +138 -0
  8. package/ai-docs/REVIEW_CHECKLIST.md +41 -0
  9. package/ai-docs/RULES.md +444 -0
  10. package/ai-docs/SECURITY.md +52 -0
  11. package/ai-docs/SERVICE_STATE.md +48 -0
  12. package/ai-docs/SPEC_INDEX.md +65 -0
  13. package/ai-docs/adr/0001-spec-source-policy.md +55 -0
  14. package/ai-docs/adr/README.md +8 -0
  15. package/ai-docs/adr/_adr-template.md +31 -0
  16. package/ai-docs/contact-center-spec.md +341 -0
  17. package/ai-docs/features/generated-spec-conformance-fidelity-remediation/spec/feature-spec.md +117 -0
  18. package/ai-docs/features/residual-warning-coverage-completion/spec/feature-spec.md +203 -0
  19. package/ai-docs/features/validator-code-fidelity-drift-fix/spec/feature-spec.md +315 -0
  20. package/ai-docs/patterns/event-driven-patterns.md +485 -0
  21. package/ai-docs/patterns/testing-patterns.md +480 -0
  22. package/ai-docs/patterns/typescript-patterns.md +365 -0
  23. package/ai-docs/templates/README.md +102 -0
  24. package/ai-docs/templates/documentation/create-agents-md.md +240 -0
  25. package/ai-docs/templates/documentation/create-architecture-md.md +295 -0
  26. package/ai-docs/templates/existing-service/bug-fix.md +254 -0
  27. package/ai-docs/templates/existing-service/feature-enhancement.md +450 -0
  28. package/ai-docs/templates/new-method/00-master.md +80 -0
  29. package/ai-docs/templates/new-method/01-requirements.md +232 -0
  30. package/ai-docs/templates/new-method/02-implementation.md +295 -0
  31. package/ai-docs/templates/new-method/03-tests.md +201 -0
  32. package/ai-docs/templates/new-method/04-validation.md +141 -0
  33. package/ai-docs/templates/new-service/00-master.md +109 -0
  34. package/ai-docs/templates/new-service/01-pre-questions.md +159 -0
  35. package/ai-docs/templates/new-service/02-code-generation.md +346 -0
  36. package/ai-docs/templates/new-service/03-integration.md +178 -0
  37. package/ai-docs/templates/new-service/04-test-generation.md +205 -0
  38. package/ai-docs/templates/new-service/05-validation.md +145 -0
  39. package/dist/cc.js +265 -29
  40. package/dist/cc.js.map +1 -1
  41. package/dist/config.js +6 -0
  42. package/dist/config.js.map +1 -1
  43. package/dist/constants.js +17 -1
  44. package/dist/constants.js.map +1 -1
  45. package/dist/index.js +20 -5
  46. package/dist/index.js.map +1 -1
  47. package/dist/metrics/behavioral-events.js +101 -0
  48. package/dist/metrics/behavioral-events.js.map +1 -1
  49. package/dist/metrics/constants.js +25 -4
  50. package/dist/metrics/constants.js.map +1 -1
  51. package/dist/services/ApiAiAssistant.js +153 -8
  52. package/dist/services/ApiAiAssistant.js.map +1 -1
  53. package/dist/services/UserPreference.js +427 -0
  54. package/dist/services/UserPreference.js.map +1 -0
  55. package/dist/services/config/Util.js +3 -3
  56. package/dist/services/config/Util.js.map +1 -1
  57. package/dist/services/config/constants.js +23 -2
  58. package/dist/services/config/constants.js.map +1 -1
  59. package/dist/services/config/types.js +49 -9
  60. package/dist/services/config/types.js.map +1 -1
  61. package/dist/services/core/Err.js.map +1 -1
  62. package/dist/services/core/Utils.js +107 -32
  63. package/dist/services/core/Utils.js.map +1 -1
  64. package/dist/services/core/websocket/WebSocketManager.js +2 -1
  65. package/dist/services/core/websocket/WebSocketManager.js.map +1 -1
  66. package/dist/services/core/websocket/types.js.map +1 -1
  67. package/dist/services/index.js +1 -1
  68. package/dist/services/index.js.map +1 -1
  69. package/dist/services/task/Task.js +688 -0
  70. package/dist/services/task/Task.js.map +1 -0
  71. package/dist/services/task/TaskFactory.js +45 -0
  72. package/dist/services/task/TaskFactory.js.map +1 -0
  73. package/dist/services/task/TaskManager.js +728 -527
  74. package/dist/services/task/TaskManager.js.map +1 -1
  75. package/dist/services/task/TaskUtils.js +162 -26
  76. package/dist/services/task/TaskUtils.js.map +1 -1
  77. package/dist/services/task/constants.js +9 -2
  78. package/dist/services/task/constants.js.map +1 -1
  79. package/dist/services/task/dialer.js +78 -0
  80. package/dist/services/task/dialer.js.map +1 -1
  81. package/dist/services/task/digital/Digital.js +77 -0
  82. package/dist/services/task/digital/Digital.js.map +1 -0
  83. package/dist/services/task/state-machine/TaskStateMachine.js +837 -0
  84. package/dist/services/task/state-machine/TaskStateMachine.js.map +1 -0
  85. package/dist/services/task/state-machine/actions.js +543 -0
  86. package/dist/services/task/state-machine/actions.js.map +1 -0
  87. package/dist/services/task/state-machine/constants.js +161 -0
  88. package/dist/services/task/state-machine/constants.js.map +1 -0
  89. package/dist/services/task/state-machine/guards.js +340 -0
  90. package/dist/services/task/state-machine/guards.js.map +1 -0
  91. package/dist/services/task/state-machine/index.js +53 -0
  92. package/dist/services/task/state-machine/index.js.map +1 -0
  93. package/dist/services/task/state-machine/types.js +54 -0
  94. package/dist/services/task/state-machine/types.js.map +1 -0
  95. package/dist/services/task/state-machine/uiControlsComputer.js +553 -0
  96. package/dist/services/task/state-machine/uiControlsComputer.js.map +1 -0
  97. package/dist/services/task/taskDataNormalizer.js +99 -0
  98. package/dist/services/task/taskDataNormalizer.js.map +1 -0
  99. package/dist/services/task/types.js +212 -4
  100. package/dist/services/task/types.js.map +1 -1
  101. package/dist/services/task/voice/Voice.js +1042 -0
  102. package/dist/services/task/voice/Voice.js.map +1 -0
  103. package/dist/services/task/voice/WebRTC.js +149 -0
  104. package/dist/services/task/voice/WebRTC.js.map +1 -0
  105. package/dist/types/cc.d.ts +94 -1
  106. package/dist/types/config.d.ts +6 -0
  107. package/dist/types/constants.d.ts +17 -1
  108. package/dist/types/index.d.ts +21 -6
  109. package/dist/types/metrics/constants.d.ts +21 -1
  110. package/dist/types/services/ApiAiAssistant.d.ts +22 -4
  111. package/dist/types/services/UserPreference.d.ts +118 -0
  112. package/dist/types/services/config/constants.d.ts +21 -0
  113. package/dist/types/services/config/types.d.ts +171 -10
  114. package/dist/types/services/core/Err.d.ts +4 -0
  115. package/dist/types/services/core/Utils.d.ts +33 -13
  116. package/dist/types/services/core/websocket/WebSocketManager.d.ts +1 -0
  117. package/dist/types/services/core/websocket/types.d.ts +1 -1
  118. package/dist/types/services/index.d.ts +1 -1
  119. package/dist/types/services/task/Task.d.ts +157 -0
  120. package/dist/types/services/task/TaskFactory.d.ts +12 -0
  121. package/dist/types/services/task/TaskUtils.d.ts +46 -2
  122. package/dist/types/services/task/constants.d.ts +7 -0
  123. package/dist/types/services/task/dialer.d.ts +30 -0
  124. package/dist/types/services/task/digital/Digital.d.ts +22 -0
  125. package/dist/types/services/task/state-machine/TaskStateMachine.d.ts +1144 -0
  126. package/dist/types/services/task/state-machine/actions.d.ts +10 -0
  127. package/dist/types/services/task/state-machine/constants.d.ts +107 -0
  128. package/dist/types/services/task/state-machine/guards.d.ts +90 -0
  129. package/dist/types/services/task/state-machine/index.d.ts +13 -0
  130. package/dist/types/services/task/state-machine/types.d.ts +267 -0
  131. package/dist/types/services/task/state-machine/uiControlsComputer.d.ts +9 -0
  132. package/dist/types/services/task/taskDataNormalizer.d.ts +10 -0
  133. package/dist/types/services/task/types.d.ts +603 -66
  134. package/dist/types/services/task/voice/Voice.d.ts +184 -0
  135. package/dist/types/services/task/voice/WebRTC.d.ts +53 -0
  136. package/dist/types/types.d.ts +135 -0
  137. package/dist/types/webex.d.ts +1 -0
  138. package/dist/types.js +118 -2
  139. package/dist/types.js.map +1 -1
  140. package/dist/webex.js +14 -2
  141. package/dist/webex.js.map +1 -1
  142. package/package.json +15 -12
  143. package/src/cc.ts +329 -30
  144. package/src/config.ts +6 -0
  145. package/src/constants.ts +17 -1
  146. package/src/index.ts +23 -5
  147. package/src/metrics/ai-docs/AGENTS.md +350 -0
  148. package/src/metrics/ai-docs/ARCHITECTURE.md +338 -0
  149. package/src/metrics/ai-docs/metrics-spec.md +854 -0
  150. package/src/metrics/behavioral-events.ts +106 -0
  151. package/src/metrics/constants.ts +27 -4
  152. package/src/services/ApiAiAssistant.ts +203 -8
  153. package/src/services/UserPreference.ts +509 -0
  154. package/src/services/agent/ai-docs/AGENTS.md +240 -0
  155. package/src/services/agent/ai-docs/ARCHITECTURE.md +304 -0
  156. package/src/services/agent/ai-docs/agent-spec.md +504 -0
  157. package/src/services/ai-docs/AGENTS.md +386 -0
  158. package/src/services/ai-docs/services-spec.md +492 -0
  159. package/src/services/config/Util.ts +3 -3
  160. package/src/services/config/ai-docs/AGENTS.md +255 -0
  161. package/src/services/config/ai-docs/ARCHITECTURE.md +426 -0
  162. package/src/services/config/ai-docs/config-spec.md +669 -0
  163. package/src/services/config/constants.ts +25 -1
  164. package/src/services/config/types.ts +174 -11
  165. package/src/services/core/Err.ts +2 -0
  166. package/src/services/core/Utils.ts +123 -37
  167. package/src/services/core/ai-docs/AGENTS.md +381 -0
  168. package/src/services/core/ai-docs/ARCHITECTURE.md +698 -0
  169. package/src/services/core/ai-docs/core-spec.md +783 -0
  170. package/src/services/core/websocket/WebSocketManager.ts +2 -0
  171. package/src/services/core/websocket/types.ts +1 -1
  172. package/src/services/index.ts +1 -1
  173. package/src/services/task/Task.ts +837 -0
  174. package/src/services/task/TaskFactory.ts +55 -0
  175. package/src/services/task/TaskManager.ts +739 -614
  176. package/src/services/task/TaskUtils.ts +205 -25
  177. package/src/services/task/ai-docs/AGENTS.md +457 -0
  178. package/src/services/task/ai-docs/ARCHITECTURE.md +594 -0
  179. package/src/services/task/ai-docs/task-spec.md +1319 -0
  180. package/src/services/task/constants.ts +7 -0
  181. package/src/services/task/dialer.ts +80 -0
  182. package/src/services/task/digital/Digital.ts +95 -0
  183. package/src/services/task/state-machine/TaskStateMachine.ts +1077 -0
  184. package/src/services/task/state-machine/actions.ts +685 -0
  185. package/src/services/task/state-machine/ai-docs/AGENTS.md +458 -0
  186. package/src/services/task/state-machine/ai-docs/ARCHITECTURE.md +1137 -0
  187. package/src/services/task/state-machine/ai-docs/task-state-machine-spec.md +2115 -0
  188. package/src/services/task/state-machine/constants.ts +172 -0
  189. package/src/services/task/state-machine/guards.ts +406 -0
  190. package/src/services/task/state-machine/index.ts +28 -0
  191. package/src/services/task/state-machine/types.ts +241 -0
  192. package/src/services/task/state-machine/uiControlsComputer.ts +867 -0
  193. package/src/services/task/taskDataNormalizer.ts +137 -0
  194. package/src/services/task/types.ts +710 -71
  195. package/src/services/task/voice/Voice.ts +1267 -0
  196. package/src/services/task/voice/WebRTC.ts +187 -0
  197. package/src/types.ts +166 -2
  198. package/src/utils/AGENTS.md +278 -0
  199. package/src/utils/ai-docs/utils-spec.md +381 -0
  200. package/src/webex.js +2 -0
  201. package/test/unit/spec/cc.ts +343 -23
  202. package/test/unit/spec/logger-proxy.ts +70 -0
  203. package/test/unit/spec/services/ApiAiAssistant.ts +178 -20
  204. package/test/unit/spec/services/UserPreference.ts +401 -0
  205. package/test/unit/spec/services/WebCallingService.ts +7 -1
  206. package/test/unit/spec/services/config/index.ts +30 -30
  207. package/test/unit/spec/services/core/Utils.ts +425 -8
  208. package/test/unit/spec/services/core/websocket/WebSocketManager.ts +66 -40
  209. package/test/unit/spec/services/task/AutoWrapup.ts +63 -0
  210. package/test/unit/spec/services/task/Task.ts +477 -0
  211. package/test/unit/spec/services/task/TaskFactory.ts +62 -0
  212. package/test/unit/spec/services/task/TaskManager.ts +834 -1704
  213. package/test/unit/spec/services/task/TaskUtils.ts +206 -0
  214. package/test/unit/spec/services/task/dialer.ts +190 -0
  215. package/test/unit/spec/services/task/digital/Digital.ts +105 -0
  216. package/test/unit/spec/services/task/state-machine/TaskStateMachine.ts +1825 -0
  217. package/test/unit/spec/services/task/state-machine/guards.ts +479 -0
  218. package/test/unit/spec/services/task/state-machine/types.ts +18 -0
  219. package/test/unit/spec/services/task/state-machine/uiControlsComputer.ts +2020 -0
  220. package/test/unit/spec/services/task/taskTestUtils.ts +87 -0
  221. package/test/unit/spec/services/task/voice/Voice.ts +631 -0
  222. package/test/unit/spec/services/task/voice/WebRTC.ts +235 -0
  223. package/umd/contact-center.min.js +2 -2
  224. package/umd/contact-center.min.js.map +1 -1
  225. package/dist/services/task/index.js +0 -1525
  226. package/dist/services/task/index.js.map +0 -1
  227. package/dist/types/services/task/index.d.ts +0 -650
  228. package/src/services/task/index.ts +0 -1801
  229. 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 {Profile} from './services/config/types';
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,174 @@ 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 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
+ */
826
931
  export const AIAssistantEventType = {
932
+ /** Custom AI Assistant event */
827
933
  CUSTOM_EVENT: 'CUSTOM_EVENT',
934
+ /** CTI-backed AI Assistant event */
828
935
  CTI_EVENT: 'CTI_EVENT',
829
936
  } as const;
830
937
 
938
+ /**
939
+ * Union type of AI Assistant event categories.
940
+ * @public
941
+ * @example
942
+ * function send(type: AIAssistantEventType) { ... }
943
+ * @ignore
944
+ */
831
945
  export type AIAssistantEventType = Enum<typeof AIAssistantEventType>;
832
946
 
947
+ /**
948
+ * Supported AI Assistant event names.
949
+ * @public
950
+ * @example
951
+ * const name: AIAssistantEventName = AIAssistantEventName.GET_TRANSCRIPTS;
952
+ * @ignore
953
+ */
833
954
  export const AIAssistantEventName = {
955
+ /** Request transcript streaming for an interaction */
834
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 */
835
962
  GET_MID_CALL_SUMMARY: 'GET_MID_CALL_SUMMARY',
963
+ /** Request post-call summary generation */
836
964
  GET_POST_CALL_SUMMARY: 'GET_POST_CALL_SUMMARY',
965
+ /** Mid-call summary response event */
837
966
  MID_CALL_SUMMARY_RESPONSE: 'MID_CALL_SUMMARY_RESPONSE',
967
+ /** Post-call summary response event */
838
968
  POST_CALL_SUMMARY_RESPONSE: 'POST_CALL_SUMMARY_RESPONSE',
969
+ /** Suggested digital response event */
839
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',
840
973
  } as const;
841
974
 
975
+ /**
976
+ * Union type of AI Assistant event names.
977
+ * @public
978
+ * @example
979
+ * function handle(name: AIAssistantEventName) { ... }
980
+ * @ignore
981
+ */
842
982
  export type AIAssistantEventName = Enum<typeof AIAssistantEventName>;
843
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
+ */
844
991
  export type TranscriptMessage = {
992
+ /** Speaker role for this message */
845
993
  role: string;
994
+ /** Transcript chunk content */
846
995
  content: string;
996
+ /** Unique message identifier */
847
997
  messageId: string;
998
+ /** Message publish timestamp (epoch milliseconds) */
848
999
  publishTimestamp: number;
849
1000
  };
850
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
+ */
851
1009
  export type HistoricTranscriptsResponse = {
1010
+ /** Organization identifier */
852
1011
  orgId: string;
1012
+ /** Agent identifier */
853
1013
  agentId: string;
1014
+ /** Conversation identifier when available */
854
1015
  conversationId: string | null;
1016
+ /** Interaction identifier */
855
1017
  interactionId: string;
1018
+ /** Data source identifier */
856
1019
  source: string;
1020
+ /** Transcript messages */
857
1021
  data: TranscriptMessage[];
858
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)