@webex/contact-center 3.12.0-next.73 → 3.12.0-next.74

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/AGENTS.md +438 -0
  2. package/ai-docs/README.md +131 -0
  3. package/ai-docs/RULES.md +455 -0
  4. package/ai-docs/patterns/event-driven-patterns.md +485 -0
  5. package/ai-docs/patterns/testing-patterns.md +480 -0
  6. package/ai-docs/patterns/typescript-patterns.md +365 -0
  7. package/ai-docs/templates/README.md +102 -0
  8. package/ai-docs/templates/documentation/create-agents-md.md +240 -0
  9. package/ai-docs/templates/documentation/create-architecture-md.md +295 -0
  10. package/ai-docs/templates/existing-service/bug-fix.md +254 -0
  11. package/ai-docs/templates/existing-service/feature-enhancement.md +450 -0
  12. package/ai-docs/templates/new-method/00-master.md +80 -0
  13. package/ai-docs/templates/new-method/01-requirements.md +232 -0
  14. package/ai-docs/templates/new-method/02-implementation.md +295 -0
  15. package/ai-docs/templates/new-method/03-tests.md +201 -0
  16. package/ai-docs/templates/new-method/04-validation.md +141 -0
  17. package/ai-docs/templates/new-service/00-master.md +109 -0
  18. package/ai-docs/templates/new-service/01-pre-questions.md +159 -0
  19. package/ai-docs/templates/new-service/02-code-generation.md +346 -0
  20. package/ai-docs/templates/new-service/03-integration.md +178 -0
  21. package/ai-docs/templates/new-service/04-test-generation.md +205 -0
  22. package/ai-docs/templates/new-service/05-validation.md +145 -0
  23. package/dist/cc.js +53 -38
  24. package/dist/cc.js.map +1 -1
  25. package/dist/config.js +6 -0
  26. package/dist/config.js.map +1 -1
  27. package/dist/constants.js +14 -1
  28. package/dist/constants.js.map +1 -1
  29. package/dist/index.js +13 -5
  30. package/dist/index.js.map +1 -1
  31. package/dist/metrics/behavioral-events.js +26 -0
  32. package/dist/metrics/behavioral-events.js.map +1 -1
  33. package/dist/metrics/constants.js +9 -3
  34. package/dist/metrics/constants.js.map +1 -1
  35. package/dist/services/ApiAiAssistant.js +74 -3
  36. package/dist/services/ApiAiAssistant.js.map +1 -1
  37. package/dist/services/config/Util.js +2 -2
  38. package/dist/services/config/Util.js.map +1 -1
  39. package/dist/services/config/types.js +25 -9
  40. package/dist/services/config/types.js.map +1 -1
  41. package/dist/services/core/Utils.js +74 -27
  42. package/dist/services/core/Utils.js.map +1 -1
  43. package/dist/services/core/websocket/WebSocketManager.js +2 -1
  44. package/dist/services/core/websocket/WebSocketManager.js.map +1 -1
  45. package/dist/services/core/websocket/types.js.map +1 -1
  46. package/dist/services/index.js +1 -1
  47. package/dist/services/index.js.map +1 -1
  48. package/dist/services/task/Task.js +688 -0
  49. package/dist/services/task/Task.js.map +1 -0
  50. package/dist/services/task/TaskFactory.js +45 -0
  51. package/dist/services/task/TaskFactory.js.map +1 -0
  52. package/dist/services/task/TaskManager.js +725 -612
  53. package/dist/services/task/TaskManager.js.map +1 -1
  54. package/dist/services/task/TaskUtils.js +162 -26
  55. package/dist/services/task/TaskUtils.js.map +1 -1
  56. package/dist/services/task/constants.js +6 -1
  57. package/dist/services/task/constants.js.map +1 -1
  58. package/dist/services/task/digital/Digital.js +77 -0
  59. package/dist/services/task/digital/Digital.js.map +1 -0
  60. package/dist/services/task/state-machine/TaskStateMachine.js +837 -0
  61. package/dist/services/task/state-machine/TaskStateMachine.js.map +1 -0
  62. package/dist/services/task/state-machine/actions.js +543 -0
  63. package/dist/services/task/state-machine/actions.js.map +1 -0
  64. package/dist/services/task/state-machine/constants.js +161 -0
  65. package/dist/services/task/state-machine/constants.js.map +1 -0
  66. package/dist/services/task/state-machine/guards.js +340 -0
  67. package/dist/services/task/state-machine/guards.js.map +1 -0
  68. package/dist/services/task/state-machine/index.js +53 -0
  69. package/dist/services/task/state-machine/index.js.map +1 -0
  70. package/dist/services/task/state-machine/types.js +54 -0
  71. package/dist/services/task/state-machine/types.js.map +1 -0
  72. package/dist/services/task/state-machine/uiControlsComputer.js +553 -0
  73. package/dist/services/task/state-machine/uiControlsComputer.js.map +1 -0
  74. package/dist/services/task/taskDataNormalizer.js +99 -0
  75. package/dist/services/task/taskDataNormalizer.js.map +1 -0
  76. package/dist/services/task/types.js +168 -16
  77. package/dist/services/task/types.js.map +1 -1
  78. package/dist/services/task/voice/Voice.js +1042 -0
  79. package/dist/services/task/voice/Voice.js.map +1 -0
  80. package/dist/services/task/voice/WebRTC.js +149 -0
  81. package/dist/services/task/voice/WebRTC.js.map +1 -0
  82. package/dist/types/cc.d.ts +19 -18
  83. package/dist/types/config.d.ts +6 -0
  84. package/dist/types/constants.d.ts +14 -1
  85. package/dist/types/index.d.ts +11 -5
  86. package/dist/types/metrics/constants.d.ts +7 -1
  87. package/dist/types/services/ApiAiAssistant.d.ts +11 -3
  88. package/dist/types/services/config/types.d.ts +113 -9
  89. package/dist/types/services/core/Utils.d.ts +23 -10
  90. package/dist/types/services/core/websocket/WebSocketManager.d.ts +1 -0
  91. package/dist/types/services/core/websocket/types.d.ts +1 -1
  92. package/dist/types/services/index.d.ts +1 -1
  93. package/dist/types/services/task/Task.d.ts +157 -0
  94. package/dist/types/services/task/TaskFactory.d.ts +12 -0
  95. package/dist/types/services/task/TaskUtils.d.ts +46 -2
  96. package/dist/types/services/task/constants.d.ts +5 -0
  97. package/dist/types/services/task/digital/Digital.d.ts +22 -0
  98. package/dist/types/services/task/state-machine/TaskStateMachine.d.ts +1144 -0
  99. package/dist/types/services/task/state-machine/actions.d.ts +10 -0
  100. package/dist/types/services/task/state-machine/constants.d.ts +107 -0
  101. package/dist/types/services/task/state-machine/guards.d.ts +90 -0
  102. package/dist/types/services/task/state-machine/index.d.ts +13 -0
  103. package/dist/types/services/task/state-machine/types.d.ts +267 -0
  104. package/dist/types/services/task/state-machine/uiControlsComputer.d.ts +9 -0
  105. package/dist/types/services/task/taskDataNormalizer.d.ts +10 -0
  106. package/dist/types/services/task/types.d.ts +551 -78
  107. package/dist/types/services/task/voice/Voice.d.ts +184 -0
  108. package/dist/types/services/task/voice/WebRTC.d.ts +53 -0
  109. package/dist/types/types.d.ts +92 -0
  110. package/dist/types/webex.d.ts +1 -0
  111. package/dist/types.js +85 -0
  112. package/dist/types.js.map +1 -1
  113. package/dist/webex.js +14 -2
  114. package/dist/webex.js.map +1 -1
  115. package/package.json +15 -12
  116. package/src/cc.ts +63 -43
  117. package/src/config.ts +6 -0
  118. package/src/constants.ts +14 -1
  119. package/src/index.ts +14 -5
  120. package/src/metrics/ai-docs/AGENTS.md +348 -0
  121. package/src/metrics/ai-docs/ARCHITECTURE.md +336 -0
  122. package/src/metrics/behavioral-events.ts +28 -0
  123. package/src/metrics/constants.ts +9 -4
  124. package/src/services/ApiAiAssistant.ts +104 -3
  125. package/src/services/agent/ai-docs/AGENTS.md +238 -0
  126. package/src/services/agent/ai-docs/ARCHITECTURE.md +302 -0
  127. package/src/services/ai-docs/AGENTS.md +384 -0
  128. package/src/services/config/Util.ts +2 -2
  129. package/src/services/config/ai-docs/AGENTS.md +253 -0
  130. package/src/services/config/ai-docs/ARCHITECTURE.md +424 -0
  131. package/src/services/config/types.ts +116 -10
  132. package/src/services/core/Utils.ts +85 -34
  133. package/src/services/core/ai-docs/AGENTS.md +379 -0
  134. package/src/services/core/ai-docs/ARCHITECTURE.md +696 -0
  135. package/src/services/core/websocket/WebSocketManager.ts +2 -0
  136. package/src/services/core/websocket/types.ts +1 -1
  137. package/src/services/index.ts +1 -1
  138. package/src/services/task/Task.ts +837 -0
  139. package/src/services/task/TaskFactory.ts +55 -0
  140. package/src/services/task/TaskManager.ts +738 -697
  141. package/src/services/task/TaskUtils.ts +205 -25
  142. package/src/services/task/ai-docs/AGENTS.md +455 -0
  143. package/src/services/task/ai-docs/ARCHITECTURE.md +585 -0
  144. package/src/services/task/constants.ts +5 -0
  145. package/src/services/task/digital/Digital.ts +95 -0
  146. package/src/services/task/state-machine/TaskStateMachine.ts +1077 -0
  147. package/src/services/task/state-machine/actions.ts +685 -0
  148. package/src/services/task/state-machine/ai-docs/AGENTS.md +495 -0
  149. package/src/services/task/state-machine/ai-docs/ARCHITECTURE.md +1135 -0
  150. package/src/services/task/state-machine/constants.ts +172 -0
  151. package/src/services/task/state-machine/guards.ts +406 -0
  152. package/src/services/task/state-machine/index.ts +28 -0
  153. package/src/services/task/state-machine/types.ts +241 -0
  154. package/src/services/task/state-machine/uiControlsComputer.ts +867 -0
  155. package/src/services/task/taskDataNormalizer.ts +137 -0
  156. package/src/services/task/types.ts +654 -85
  157. package/src/services/task/voice/Voice.ts +1267 -0
  158. package/src/services/task/voice/WebRTC.ts +187 -0
  159. package/src/types.ts +112 -1
  160. package/src/utils/AGENTS.md +276 -0
  161. package/src/webex.js +2 -0
  162. package/test/unit/spec/cc.ts +133 -3
  163. package/test/unit/spec/logger-proxy.ts +70 -0
  164. package/test/unit/spec/services/ApiAiAssistant.ts +122 -17
  165. package/test/unit/spec/services/WebCallingService.ts +7 -1
  166. package/test/unit/spec/services/config/index.ts +27 -27
  167. package/test/unit/spec/services/core/Utils.ts +335 -1
  168. package/test/unit/spec/services/core/websocket/WebSocketManager.ts +66 -40
  169. package/test/unit/spec/services/task/AutoWrapup.ts +63 -0
  170. package/test/unit/spec/services/task/Task.ts +477 -0
  171. package/test/unit/spec/services/task/TaskFactory.ts +62 -0
  172. package/test/unit/spec/services/task/TaskManager.ts +821 -1936
  173. package/test/unit/spec/services/task/TaskUtils.ts +206 -0
  174. package/test/unit/spec/services/task/digital/Digital.ts +105 -0
  175. package/test/unit/spec/services/task/state-machine/TaskStateMachine.ts +1825 -0
  176. package/test/unit/spec/services/task/state-machine/guards.ts +479 -0
  177. package/test/unit/spec/services/task/state-machine/types.ts +18 -0
  178. package/test/unit/spec/services/task/state-machine/uiControlsComputer.ts +2020 -0
  179. package/test/unit/spec/services/task/taskTestUtils.ts +87 -0
  180. package/test/unit/spec/services/task/voice/Voice.ts +631 -0
  181. package/test/unit/spec/services/task/voice/WebRTC.ts +235 -0
  182. package/umd/contact-center.min.js +2 -2
  183. package/umd/contact-center.min.js.map +1 -1
  184. package/dist/services/task/index.js +0 -1530
  185. package/dist/services/task/index.js.map +0 -1
  186. package/dist/types/services/task/index.d.ts +0 -650
  187. package/src/services/task/index.ts +0 -1806
  188. package/test/unit/spec/services/task/index.ts +0 -2205
@@ -0,0 +1,479 @@
1
+ import {guards, GuardParams} from '../../../../../../src/services/task/state-machine/guards';
2
+ import {
3
+ TaskContext,
4
+ TaskEventPayload,
5
+ } from '../../../../../../src/services/task/state-machine/types';
6
+ import {TaskData, InteractionParticipant} from '../../../../../../src/services/task/types';
7
+
8
+ describe('State Machine Guards', () => {
9
+ const createParticipant = (
10
+ id: string,
11
+ pType: string,
12
+ hasLeft = false
13
+ ): InteractionParticipant => ({
14
+ id,
15
+ pType,
16
+ type: pType,
17
+ hasJoined: true,
18
+ hasLeft,
19
+ isInPredial: false,
20
+ });
21
+ // Note: media key must match mainInteractionId for getIsConferenceInProgress to work
22
+ const INTERACTION_ID = 'interaction-123';
23
+
24
+ const createTaskData = (overrides: Partial<TaskData> = {}): TaskData =>
25
+ ({
26
+ mediaResourceId: INTERACTION_ID,
27
+ eventType: 'TEST_EVENT',
28
+ agentId: 'agent-123',
29
+ destAgentId: '',
30
+ trackingId: 'track-123',
31
+ consultMediaResourceId: '',
32
+ interactionId: INTERACTION_ID,
33
+ orgId: 'org-123',
34
+ owner: 'agent-123',
35
+ queueMgr: 'queue-mgr',
36
+ type: 'voice',
37
+ isConferencing: false,
38
+ interaction: {
39
+ mainInteractionId: INTERACTION_ID,
40
+ interactionId: INTERACTION_ID,
41
+ participants: {},
42
+ media: {
43
+ [INTERACTION_ID]: {
44
+ mediaResourceId: INTERACTION_ID,
45
+ mediaType: 'telephony',
46
+ mediaMgr: 'media-mgr',
47
+ participants: ['agent-123'],
48
+ mType: 'mainCall',
49
+ isHold: false,
50
+ holdTimestamp: null,
51
+ },
52
+ },
53
+ owner: 'agent-123',
54
+ mediaChannel: 'telephony',
55
+ contactDirection: {type: 'inbound'},
56
+ },
57
+ ...overrides,
58
+ } as TaskData);
59
+
60
+ const createContext = (overrides: Partial<TaskContext> = {}): TaskContext =>
61
+ ({
62
+ recordingControlsAvailable: false,
63
+ recordingInProgress: false,
64
+ consultDestinationAgentJoined: false,
65
+ consultCallHeld: false,
66
+ consultInitiator: false,
67
+ exitingConference: false,
68
+ consultDestinationType: null,
69
+ taskData: createTaskData(),
70
+ uiControlConfig: {agentId: 'agent-123'},
71
+ uiControls: {
72
+ main: {
73
+ accept: {isVisible: false, isEnabled: false},
74
+ decline: {isVisible: false, isEnabled: false},
75
+ hold: {isVisible: false, isEnabled: false},
76
+ end: {isVisible: false, isEnabled: false},
77
+ transfer: {isVisible: false, isEnabled: false},
78
+ consult: {isVisible: false, isEnabled: false},
79
+ consultTransfer: {isVisible: false, isEnabled: false},
80
+ endConsult: {isVisible: false, isEnabled: false},
81
+ recording: {isVisible: false, isEnabled: false},
82
+ conference: {isVisible: false, isEnabled: false},
83
+ wrapup: {isVisible: false, isEnabled: false},
84
+ exitConference: {isVisible: false, isEnabled: false},
85
+ transferConference: {isVisible: false, isEnabled: false},
86
+ mergeToConference: {isVisible: false, isEnabled: false},
87
+ switch: {isVisible: false, isEnabled: false},
88
+ mute: {isVisible: false, isEnabled: false},
89
+ },
90
+ consult: {
91
+ accept: {isVisible: false, isEnabled: false},
92
+ decline: {isVisible: false, isEnabled: false},
93
+ hold: {isVisible: false, isEnabled: false},
94
+ end: {isVisible: false, isEnabled: false},
95
+ transfer: {isVisible: false, isEnabled: false},
96
+ consult: {isVisible: false, isEnabled: false},
97
+ consultTransfer: {isVisible: false, isEnabled: false},
98
+ endConsult: {isVisible: false, isEnabled: false},
99
+ recording: {isVisible: false, isEnabled: false},
100
+ conference: {isVisible: false, isEnabled: false},
101
+ wrapup: {isVisible: false, isEnabled: false},
102
+ exitConference: {isVisible: false, isEnabled: false},
103
+ transferConference: {isVisible: false, isEnabled: false},
104
+ mergeToConference: {isVisible: false, isEnabled: false},
105
+ switch: {isVisible: false, isEnabled: false},
106
+ mute: {isVisible: false, isEnabled: false},
107
+ },
108
+ activeLeg: 'main',
109
+ },
110
+ ...overrides,
111
+ } as TaskContext);
112
+
113
+ const createParams = (context: TaskContext, event?: TaskEventPayload): GuardParams => ({
114
+ context,
115
+ event,
116
+ });
117
+
118
+ const createEventWithTaskData = (taskData: TaskData): TaskEventPayload =>
119
+ ({taskData} as TaskEventPayload);
120
+
121
+ describe('Conference Guards', () => {
122
+ it('conferenceInProgressFromEvent returns true with 2+ agents in event', () => {
123
+ const ctx = createContext();
124
+ const taskData = createTaskData({
125
+ interaction: {
126
+ ...createTaskData().interaction,
127
+ participants: {
128
+ a1: createParticipant('a1', 'Agent'),
129
+ a2: createParticipant('a2', 'Agent'),
130
+ },
131
+ media: {
132
+ [INTERACTION_ID]: {
133
+ mediaResourceId: INTERACTION_ID,
134
+ mediaType: 'telephony',
135
+ mediaMgr: 'media-mgr',
136
+ participants: ['a1', 'a2'],
137
+ mType: 'mainCall',
138
+ isHold: false,
139
+ holdTimestamp: null,
140
+ },
141
+ },
142
+ },
143
+ });
144
+ expect(
145
+ guards.conferenceInProgressFromEvent(createParams(ctx, createEventWithTaskData(taskData)))
146
+ ).toBe(true);
147
+ });
148
+
149
+ it('conferenceInProgressFromEvent returns false with 1 agent', () => {
150
+ const ctx = createContext();
151
+ const taskData = createTaskData({
152
+ interaction: {
153
+ ...createTaskData().interaction,
154
+ participants: {
155
+ a1: createParticipant('a1', 'Agent'),
156
+ },
157
+ media: {
158
+ [INTERACTION_ID]: {
159
+ mediaResourceId: INTERACTION_ID,
160
+ mediaType: 'telephony',
161
+ mediaMgr: 'media-mgr',
162
+ participants: ['a1'],
163
+ mType: 'mainCall',
164
+ isHold: false,
165
+ holdTimestamp: null,
166
+ },
167
+ },
168
+ },
169
+ });
170
+ expect(
171
+ guards.conferenceInProgressFromEvent(createParams(ctx, createEventWithTaskData(taskData)))
172
+ ).toBe(false);
173
+ });
174
+ });
175
+
176
+ describe('Consult Guards', () => {
177
+ it('didInitiateConsult returns true when consultingAgentId matches', () => {
178
+ const ctx = createContext();
179
+ const taskData = createTaskData({
180
+ consultingAgentId: 'agent-123',
181
+ isConsulted: false,
182
+ });
183
+ expect(guards.didInitiateConsult(createParams(ctx, createEventWithTaskData(taskData)))).toBe(
184
+ true
185
+ );
186
+ });
187
+
188
+ it('didInitiateConsult returns false when isConsulted is true', () => {
189
+ const ctx = createContext();
190
+ const taskData = createTaskData({isConsulted: true});
191
+ expect(guards.didInitiateConsult(createParams(ctx, createEventWithTaskData(taskData)))).toBe(
192
+ false
193
+ );
194
+ });
195
+
196
+ it('isInteractionConsulting returns true for pending self consult on hydrate', () => {
197
+ const ctx = createContext();
198
+ const taskData = createTaskData({
199
+ isConsulted: false,
200
+ interaction: {
201
+ ...createTaskData().interaction,
202
+ state: 'conference',
203
+ participants: {
204
+ 'agent-123': {
205
+ ...createParticipant('agent-123', 'Agent'),
206
+ consultState: 'consultInitiated',
207
+ isConsulted: false,
208
+ },
209
+ 'agent-456': {
210
+ ...createParticipant('agent-456', 'Agent'),
211
+ hasJoined: false,
212
+ consultState: 'consultReserved',
213
+ isConsulted: true,
214
+ },
215
+ },
216
+ media: {
217
+ [INTERACTION_ID]: {
218
+ mediaResourceId: INTERACTION_ID,
219
+ mediaType: 'telephony',
220
+ mediaMgr: 'media-mgr',
221
+ participants: ['agent-123'],
222
+ mType: 'mainCall',
223
+ isHold: true,
224
+ holdTimestamp: Date.now(),
225
+ },
226
+ 'consult-media': {
227
+ mediaResourceId: 'consult-media',
228
+ mediaType: 'telephony',
229
+ mediaMgr: 'media-mgr',
230
+ participants: ['agent-123', 'agent-456'],
231
+ mType: 'consult',
232
+ isHold: false,
233
+ holdTimestamp: null,
234
+ },
235
+ },
236
+ } as any,
237
+ });
238
+ expect(
239
+ guards.isInteractionConsulting(createParams(ctx, createEventWithTaskData(taskData)))
240
+ ).toBe(true);
241
+ });
242
+
243
+ it('isInteractionConsulting returns false for consulted agent pending consult state', () => {
244
+ const ctx = createContext();
245
+ const taskData = createTaskData({
246
+ isConsulted: true,
247
+ interaction: {
248
+ ...createTaskData().interaction,
249
+ state: 'conference',
250
+ participants: {
251
+ 'agent-123': {
252
+ ...createParticipant('agent-123', 'Agent'),
253
+ consultState: 'consultInitiated',
254
+ isConsulted: true,
255
+ },
256
+ },
257
+ media: {
258
+ [INTERACTION_ID]: {
259
+ mediaResourceId: INTERACTION_ID,
260
+ mediaType: 'telephony',
261
+ mediaMgr: 'media-mgr',
262
+ participants: ['agent-123'],
263
+ mType: 'mainCall',
264
+ isHold: true,
265
+ holdTimestamp: Date.now(),
266
+ },
267
+ 'consult-media': {
268
+ mediaResourceId: 'consult-media',
269
+ mediaType: 'telephony',
270
+ mediaMgr: 'media-mgr',
271
+ participants: ['agent-123'],
272
+ mType: 'consult',
273
+ isHold: false,
274
+ holdTimestamp: null,
275
+ },
276
+ },
277
+ } as any,
278
+ });
279
+ expect(
280
+ guards.isInteractionConsulting(createParams(ctx, createEventWithTaskData(taskData)))
281
+ ).toBe(false);
282
+ });
283
+ });
284
+
285
+ describe('Wrap-up Guards', () => {
286
+ it('shouldWrapUp returns true for owner', () => {
287
+ const ctx = createContext();
288
+ const taskData = createTaskData({
289
+ interaction: {
290
+ ...createTaskData().interaction,
291
+ owner: 'agent-123',
292
+ },
293
+ });
294
+ expect(guards.shouldWrapUp(createParams(ctx, createEventWithTaskData(taskData)))).toBe(true);
295
+ });
296
+
297
+ it('shouldWrapUp returns false for non-owner', () => {
298
+ const ctx = createContext();
299
+ const taskData = createTaskData({
300
+ interaction: {
301
+ ...createTaskData().interaction,
302
+ owner: 'other-agent',
303
+ },
304
+ });
305
+ expect(guards.shouldWrapUp(createParams(ctx, createEventWithTaskData(taskData)))).toBe(false);
306
+ });
307
+
308
+ it('shouldWrapUp returns true when agentsPendingWrapUp includes agent', () => {
309
+ const ctx = createContext();
310
+ const taskData = createTaskData({
311
+ agentsPendingWrapUp: ['agent-123', 'other-agent'],
312
+ } as Partial<TaskData>);
313
+ expect(guards.shouldWrapUp(createParams(ctx, createEventWithTaskData(taskData)))).toBe(true);
314
+ });
315
+
316
+ it('shouldWrapUp uses isConsulted fallback when no owner', () => {
317
+ const taskData = createTaskData({
318
+ isConsulted: false,
319
+ interaction: {
320
+ ...createTaskData().interaction,
321
+ owner: undefined as unknown as string, // No owner
322
+ },
323
+ });
324
+ const ctx = createContext({taskData});
325
+ expect(guards.shouldWrapUp(createParams(ctx, createEventWithTaskData(taskData)))).toBe(true);
326
+ });
327
+ });
328
+
329
+ describe('Hydration Guards - isInteractionConsulting', () => {
330
+ it('returns true when interaction state is consulting', () => {
331
+ const ctx = createContext();
332
+ const taskData = createTaskData({
333
+ interaction: {
334
+ ...createTaskData().interaction,
335
+ state: 'consulting',
336
+ },
337
+ });
338
+ expect(
339
+ guards.isInteractionConsulting(createParams(ctx, createEventWithTaskData(taskData)))
340
+ ).toBe(true);
341
+ });
342
+
343
+ it('returns true for EP_DN consulted agent (state=connected, CPD relationshipType=consult)', () => {
344
+ const ctx = createContext();
345
+ const taskData = createTaskData({
346
+ interaction: {
347
+ ...createTaskData().interaction,
348
+ state: 'connected',
349
+ callProcessingDetails: {
350
+ ...createTaskData().interaction!.callProcessingDetails,
351
+ relationshipType: 'consult',
352
+ },
353
+ },
354
+ });
355
+ expect(
356
+ guards.isInteractionConsulting(createParams(ctx, createEventWithTaskData(taskData)))
357
+ ).toBe(true);
358
+ });
359
+
360
+ it('returns true when post_call with active consult (consultState=consulting + consult media)', () => {
361
+ const ctx = createContext();
362
+ const taskData = createTaskData({
363
+ interaction: {
364
+ ...createTaskData().interaction,
365
+ state: 'post_call',
366
+ participants: {
367
+ 'agent-123': {
368
+ ...createParticipant('agent-123', 'Agent'),
369
+ consultState: 'consulting',
370
+ },
371
+ },
372
+ media: {
373
+ [INTERACTION_ID]: {
374
+ mediaResourceId: INTERACTION_ID,
375
+ mediaType: 'telephony',
376
+ mediaMgr: 'media-mgr',
377
+ participants: ['agent-123'],
378
+ mType: 'mainCall',
379
+ isHold: false,
380
+ holdTimestamp: null,
381
+ },
382
+ 'consult-media': {
383
+ mediaResourceId: 'consult-media',
384
+ mediaType: 'telephony',
385
+ mediaMgr: 'media-mgr',
386
+ participants: ['agent-123', 'agent-2'],
387
+ mType: 'consult',
388
+ isHold: false,
389
+ holdTimestamp: null,
390
+ },
391
+ },
392
+ },
393
+ });
394
+ expect(
395
+ guards.isInteractionConsulting(createParams(ctx, createEventWithTaskData(taskData)))
396
+ ).toBe(true);
397
+ });
398
+
399
+ it('returns false for post_call without consult media', () => {
400
+ const ctx = createContext();
401
+ const taskData = createTaskData({
402
+ interaction: {
403
+ ...createTaskData().interaction,
404
+ state: 'post_call',
405
+ participants: {
406
+ 'agent-123': {
407
+ ...createParticipant('agent-123', 'Agent'),
408
+ consultState: undefined,
409
+ },
410
+ },
411
+ },
412
+ });
413
+ expect(
414
+ guards.isInteractionConsulting(createParams(ctx, createEventWithTaskData(taskData)))
415
+ ).toBe(false);
416
+ });
417
+
418
+ it('returns false for plain connected state without consult CPD', () => {
419
+ const ctx = createContext();
420
+ const taskData = createTaskData({
421
+ interaction: {
422
+ ...createTaskData().interaction,
423
+ state: 'connected',
424
+ },
425
+ });
426
+ expect(
427
+ guards.isInteractionConsulting(createParams(ctx, createEventWithTaskData(taskData)))
428
+ ).toBe(false);
429
+ });
430
+ });
431
+
432
+ describe('Server State Guards', () => {
433
+ it('isPrimaryMediaOnHold returns true when media isHold is true', () => {
434
+ const ctx = createContext();
435
+ const taskData = createTaskData({
436
+ interaction: {
437
+ ...createTaskData().interaction,
438
+ media: {
439
+ [INTERACTION_ID]: {
440
+ mediaResourceId: INTERACTION_ID,
441
+ mediaType: 'telephony',
442
+ mediaMgr: 'media-mgr',
443
+ participants: ['agent-123'],
444
+ mType: 'mainCall',
445
+ isHold: true,
446
+ holdTimestamp: Date.now(),
447
+ },
448
+ },
449
+ },
450
+ });
451
+ expect(
452
+ guards.isPrimaryMediaOnHold(createParams(ctx, createEventWithTaskData(taskData)))
453
+ ).toBe(true);
454
+ });
455
+
456
+ it('isPrimaryMediaOnHold returns false when media isHold is false', () => {
457
+ const ctx = createContext();
458
+ const taskData = createTaskData({
459
+ interaction: {
460
+ ...createTaskData().interaction,
461
+ media: {
462
+ [INTERACTION_ID]: {
463
+ mediaResourceId: INTERACTION_ID,
464
+ mediaType: 'telephony',
465
+ mediaMgr: 'media-mgr',
466
+ participants: ['agent-123'],
467
+ mType: 'mainCall',
468
+ isHold: false,
469
+ holdTimestamp: null,
470
+ },
471
+ },
472
+ },
473
+ });
474
+ expect(
475
+ guards.isPrimaryMediaOnHold(createParams(ctx, createEventWithTaskData(taskData)))
476
+ ).toBe(false);
477
+ });
478
+ });
479
+ });
@@ -0,0 +1,18 @@
1
+ import {isEventOfType} from '../../../../../../src/services/task/state-machine/types';
2
+ import {TaskEvent} from '../../../../../../src/services/task/state-machine';
3
+
4
+ describe('state-machine types', () => {
5
+ describe('isEventOfType', () => {
6
+ it('returns true for matching type', () => {
7
+ const event = {type: TaskEvent.TASK_INCOMING, taskData: {interactionId: 'id'} as any};
8
+ expect(isEventOfType(event as any, TaskEvent.TASK_INCOMING)).toBe(true);
9
+ });
10
+
11
+ it('returns false for non-matching type or undefined', () => {
12
+ const event = {type: TaskEvent.TASK_INCOMING, taskData: {interactionId: 'id'} as any};
13
+ expect(isEventOfType(event as any, TaskEvent.ASSIGN)).toBe(false);
14
+ expect(isEventOfType(undefined, TaskEvent.ASSIGN)).toBe(false);
15
+ });
16
+ });
17
+ });
18
+