@webex/contact-center 3.12.0-next.13 → 3.12.0-next.130

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 (312) hide show
  1. package/.sdd/manifest.json +884 -0
  2. package/AGENTS.md +94 -0
  3. package/ai-docs/ARCHITECTURE.md +168 -0
  4. package/ai-docs/CONTRACTS.md +53 -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 +52 -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 +382 -0
  17. package/ai-docs/features/consult-transfer-list-policy/spec/feature-spec.md +362 -0
  18. package/ai-docs/features/contact-owner-change-refactor.md +78 -0
  19. package/ai-docs/features/generated-spec-conformance-fidelity-remediation/spec/feature-spec.md +117 -0
  20. package/ai-docs/features/residual-warning-coverage-completion/spec/feature-spec.md +203 -0
  21. package/ai-docs/features/validator-code-fidelity-drift-fix/spec/feature-spec.md +315 -0
  22. package/ai-docs/patterns/event-driven-patterns.md +485 -0
  23. package/ai-docs/patterns/testing-patterns.md +480 -0
  24. package/ai-docs/patterns/typescript-patterns.md +365 -0
  25. package/ai-docs/templates/README.md +102 -0
  26. package/ai-docs/templates/documentation/create-agents-md.md +240 -0
  27. package/ai-docs/templates/documentation/create-architecture-md.md +295 -0
  28. package/ai-docs/templates/existing-service/bug-fix.md +254 -0
  29. package/ai-docs/templates/existing-service/feature-enhancement.md +450 -0
  30. package/ai-docs/templates/new-method/00-master.md +80 -0
  31. package/ai-docs/templates/new-method/01-requirements.md +232 -0
  32. package/ai-docs/templates/new-method/02-implementation.md +295 -0
  33. package/ai-docs/templates/new-method/03-tests.md +201 -0
  34. package/ai-docs/templates/new-method/04-validation.md +141 -0
  35. package/ai-docs/templates/new-service/00-master.md +109 -0
  36. package/ai-docs/templates/new-service/01-pre-questions.md +159 -0
  37. package/ai-docs/templates/new-service/02-code-generation.md +346 -0
  38. package/ai-docs/templates/new-service/03-integration.md +178 -0
  39. package/ai-docs/templates/new-service/04-test-generation.md +205 -0
  40. package/ai-docs/templates/new-service/05-validation.md +145 -0
  41. package/dist/cc.js +971 -42
  42. package/dist/cc.js.map +1 -1
  43. package/dist/config.js +13 -0
  44. package/dist/config.js.map +1 -1
  45. package/dist/constants.js +31 -3
  46. package/dist/constants.js.map +1 -1
  47. package/dist/index.js +45 -15
  48. package/dist/index.js.map +1 -1
  49. package/dist/metrics/MetricsManager.js +16 -0
  50. package/dist/metrics/MetricsManager.js.map +1 -1
  51. package/dist/metrics/behavioral-events.js +205 -0
  52. package/dist/metrics/behavioral-events.js.map +1 -1
  53. package/dist/metrics/constants.js +48 -4
  54. package/dist/metrics/constants.js.map +1 -1
  55. package/dist/services/AddressBook.js +18 -15
  56. package/dist/services/AddressBook.js.map +1 -1
  57. package/dist/services/AnswerCallOnWebexService.js +202 -0
  58. package/dist/services/AnswerCallOnWebexService.js.map +1 -0
  59. package/dist/services/ApiAiAssistant.js +269 -9
  60. package/dist/services/ApiAiAssistant.js.map +1 -1
  61. package/dist/services/EntryPoint.js +46 -68
  62. package/dist/services/EntryPoint.js.map +1 -1
  63. package/dist/services/Queue.js +27 -22
  64. package/dist/services/Queue.js.map +1 -1
  65. package/dist/services/UserPreference.js +427 -0
  66. package/dist/services/UserPreference.js.map +1 -0
  67. package/dist/services/WebexCrossClientService.js +222 -0
  68. package/dist/services/WebexCrossClientService.js.map +1 -0
  69. package/dist/services/WxAppTelephonyMercurySync.js +108 -0
  70. package/dist/services/WxAppTelephonyMercurySync.js.map +1 -0
  71. package/dist/services/config/Util.js +11 -4
  72. package/dist/services/config/Util.js.map +1 -1
  73. package/dist/services/config/constants.js +41 -7
  74. package/dist/services/config/constants.js.map +1 -1
  75. package/dist/services/config/index.js +51 -0
  76. package/dist/services/config/index.js.map +1 -1
  77. package/dist/services/config/types.js +57 -12
  78. package/dist/services/config/types.js.map +1 -1
  79. package/dist/services/core/Err.js.map +1 -1
  80. package/dist/services/core/Utils.js +111 -32
  81. package/dist/services/core/Utils.js.map +1 -1
  82. package/dist/services/core/WebexRequest.js +6 -2
  83. package/dist/services/core/WebexRequest.js.map +1 -1
  84. package/dist/services/core/aqm-reqs.js +28 -14
  85. package/dist/services/core/aqm-reqs.js.map +1 -1
  86. package/dist/services/core/types.js.map +1 -1
  87. package/dist/services/core/websocket/WebSocketManager.js +2 -1
  88. package/dist/services/core/websocket/WebSocketManager.js.map +1 -1
  89. package/dist/services/core/websocket/types.js.map +1 -1
  90. package/dist/services/index.js +1 -1
  91. package/dist/services/index.js.map +1 -1
  92. package/dist/services/task/Task.js +754 -0
  93. package/dist/services/task/Task.js.map +1 -0
  94. package/dist/services/task/TaskFactory.js +49 -0
  95. package/dist/services/task/TaskFactory.js.map +1 -0
  96. package/dist/services/task/TaskManager.js +1172 -521
  97. package/dist/services/task/TaskManager.js.map +1 -1
  98. package/dist/services/task/TaskUtils.js +211 -27
  99. package/dist/services/task/TaskUtils.js.map +1 -1
  100. package/dist/services/task/WebexCallingUtils.js +70 -0
  101. package/dist/services/task/WebexCallingUtils.js.map +1 -0
  102. package/dist/services/task/constants.js +12 -2
  103. package/dist/services/task/constants.js.map +1 -1
  104. package/dist/services/task/contact.js +29 -0
  105. package/dist/services/task/contact.js.map +1 -1
  106. package/dist/services/task/dialer.js +78 -0
  107. package/dist/services/task/dialer.js.map +1 -1
  108. package/dist/services/task/digital/Digital.js +78 -0
  109. package/dist/services/task/digital/Digital.js.map +1 -0
  110. package/dist/services/task/state-machine/TaskStateMachine.js +982 -0
  111. package/dist/services/task/state-machine/TaskStateMachine.js.map +1 -0
  112. package/dist/services/task/state-machine/actions.js +572 -0
  113. package/dist/services/task/state-machine/actions.js.map +1 -0
  114. package/dist/services/task/state-machine/constants.js +161 -0
  115. package/dist/services/task/state-machine/constants.js.map +1 -0
  116. package/dist/services/task/state-machine/guards.js +379 -0
  117. package/dist/services/task/state-machine/guards.js.map +1 -0
  118. package/dist/services/task/state-machine/index.js +53 -0
  119. package/dist/services/task/state-machine/index.js.map +1 -0
  120. package/dist/services/task/state-machine/types.js +54 -0
  121. package/dist/services/task/state-machine/types.js.map +1 -0
  122. package/dist/services/task/state-machine/uiControlsComputer.js +703 -0
  123. package/dist/services/task/state-machine/uiControlsComputer.js.map +1 -0
  124. package/dist/services/task/taskDataNormalizer.js +99 -0
  125. package/dist/services/task/taskDataNormalizer.js.map +1 -0
  126. package/dist/services/task/types.js +228 -5
  127. package/dist/services/task/types.js.map +1 -1
  128. package/dist/services/task/voice/Voice.js +1485 -0
  129. package/dist/services/task/voice/Voice.js.map +1 -0
  130. package/dist/services/task/voice/WebRTC.js +152 -0
  131. package/dist/services/task/voice/WebRTC.js.map +1 -0
  132. package/dist/services/task/voice/wxAppVoiceMethods.js +354 -0
  133. package/dist/services/task/voice/wxAppVoiceMethods.js.map +1 -0
  134. package/dist/services/wxAppDiagnosticLogging.js +122 -0
  135. package/dist/services/wxAppDiagnosticLogging.js.map +1 -0
  136. package/dist/services/wxAppTelephonyUtils.js +19 -0
  137. package/dist/services/wxAppTelephonyUtils.js.map +1 -0
  138. package/dist/types/cc.d.ts +193 -6
  139. package/dist/types/config.d.ts +13 -0
  140. package/dist/types/constants.d.ts +29 -1
  141. package/dist/types/index.d.ts +35 -8
  142. package/dist/types/metrics/MetricsManager.d.ts +6 -0
  143. package/dist/types/metrics/constants.d.ts +43 -1
  144. package/dist/types/services/AddressBook.d.ts +2 -1
  145. package/dist/types/services/AnswerCallOnWebexService.d.ts +38 -0
  146. package/dist/types/services/ApiAiAssistant.d.ts +56 -5
  147. package/dist/types/services/EntryPoint.d.ts +7 -5
  148. package/dist/types/services/Queue.d.ts +5 -3
  149. package/dist/types/services/UserPreference.d.ts +118 -0
  150. package/dist/types/services/WebexCrossClientService.d.ts +32 -0
  151. package/dist/types/services/WxAppTelephonyMercurySync.d.ts +28 -0
  152. package/dist/types/services/config/constants.d.ts +34 -5
  153. package/dist/types/services/config/types.d.ts +197 -12
  154. package/dist/types/services/core/Err.d.ts +6 -0
  155. package/dist/types/services/core/Utils.d.ts +35 -13
  156. package/dist/types/services/core/WebexRequest.d.ts +1 -0
  157. package/dist/types/services/core/types.d.ts +2 -0
  158. package/dist/types/services/core/websocket/WebSocketManager.d.ts +1 -0
  159. package/dist/types/services/core/websocket/types.d.ts +1 -1
  160. package/dist/types/services/index.d.ts +1 -1
  161. package/dist/types/services/task/Task.d.ts +175 -0
  162. package/dist/types/services/task/TaskFactory.d.ts +13 -0
  163. package/dist/types/services/task/TaskUtils.d.ts +48 -2
  164. package/dist/types/services/task/WebexCallingUtils.d.ts +11 -0
  165. package/dist/types/services/task/constants.d.ts +10 -0
  166. package/dist/types/services/task/contact.d.ts +4 -0
  167. package/dist/types/services/task/dialer.d.ts +30 -0
  168. package/dist/types/services/task/digital/Digital.d.ts +22 -0
  169. package/dist/types/services/task/state-machine/TaskStateMachine.d.ts +1442 -0
  170. package/dist/types/services/task/state-machine/actions.d.ts +10 -0
  171. package/dist/types/services/task/state-machine/constants.d.ts +107 -0
  172. package/dist/types/services/task/state-machine/guards.d.ts +103 -0
  173. package/dist/types/services/task/state-machine/index.d.ts +13 -0
  174. package/dist/types/services/task/state-machine/types.d.ts +277 -0
  175. package/dist/types/services/task/state-machine/uiControlsComputer.d.ts +9 -0
  176. package/dist/types/services/task/taskDataNormalizer.d.ts +10 -0
  177. package/dist/types/services/task/types.d.ts +680 -66
  178. package/dist/types/services/task/voice/Voice.d.ts +227 -0
  179. package/dist/types/services/task/voice/WebRTC.d.ts +53 -0
  180. package/dist/types/services/task/voice/wxAppVoiceMethods.d.ts +55 -0
  181. package/dist/types/services/wxAppDiagnosticLogging.d.ts +51 -0
  182. package/dist/types/services/wxAppTelephonyUtils.d.ts +5 -0
  183. package/dist/types/types.d.ts +205 -9
  184. package/dist/types/utils/PageCache.d.ts +20 -3
  185. package/dist/types/webex.d.ts +1 -0
  186. package/dist/types.js +162 -4
  187. package/dist/types.js.map +1 -1
  188. package/dist/utils/PageCache.js +19 -5
  189. package/dist/utils/PageCache.js.map +1 -1
  190. package/dist/webex.js +22 -2
  191. package/dist/webex.js.map +1 -1
  192. package/package.json +16 -12
  193. package/src/cc.ts +1289 -112
  194. package/src/config.ts +13 -0
  195. package/src/constants.ts +29 -1
  196. package/src/index.ts +36 -5
  197. package/src/metrics/MetricsManager.ts +16 -0
  198. package/src/metrics/ai-docs/AGENTS.md +350 -0
  199. package/src/metrics/ai-docs/ARCHITECTURE.md +338 -0
  200. package/src/metrics/ai-docs/metrics-spec.md +921 -0
  201. package/src/metrics/behavioral-events.ts +212 -0
  202. package/src/metrics/constants.ts +52 -4
  203. package/src/services/AddressBook.ts +17 -6
  204. package/src/services/AnswerCallOnWebexService.ts +239 -0
  205. package/src/services/ApiAiAssistant.ts +356 -9
  206. package/src/services/EntryPoint.ts +59 -60
  207. package/src/services/Queue.ts +29 -12
  208. package/src/services/UserPreference.ts +509 -0
  209. package/src/services/WebexCrossClientService.ts +293 -0
  210. package/src/services/WxAppTelephonyMercurySync.ts +142 -0
  211. package/src/services/agent/ai-docs/AGENTS.md +240 -0
  212. package/src/services/agent/ai-docs/ARCHITECTURE.md +304 -0
  213. package/src/services/agent/ai-docs/agent-spec.md +505 -0
  214. package/src/services/ai-docs/AGENTS.md +386 -0
  215. package/src/services/ai-docs/services-spec.md +505 -0
  216. package/src/services/config/Util.ts +12 -3
  217. package/src/services/config/ai-docs/AGENTS.md +255 -0
  218. package/src/services/config/ai-docs/ARCHITECTURE.md +426 -0
  219. package/src/services/config/ai-docs/config-spec.md +686 -0
  220. package/src/services/config/constants.ts +46 -6
  221. package/src/services/config/index.ts +65 -0
  222. package/src/services/config/types.ts +197 -13
  223. package/src/services/core/Err.ts +3 -0
  224. package/src/services/core/Utils.ts +127 -37
  225. package/src/services/core/WebexRequest.ts +3 -1
  226. package/src/services/core/ai-docs/AGENTS.md +381 -0
  227. package/src/services/core/ai-docs/ARCHITECTURE.md +698 -0
  228. package/src/services/core/ai-docs/core-spec.md +787 -0
  229. package/src/services/core/aqm-reqs.ts +30 -15
  230. package/src/services/core/types.ts +2 -0
  231. package/src/services/core/websocket/WebSocketManager.ts +2 -0
  232. package/src/services/core/websocket/types.ts +1 -1
  233. package/src/services/index.ts +1 -1
  234. package/src/services/task/Task.ts +908 -0
  235. package/src/services/task/TaskFactory.ts +60 -0
  236. package/src/services/task/TaskManager.ts +1419 -608
  237. package/src/services/task/TaskUtils.ts +303 -25
  238. package/src/services/task/WebexCallingUtils.ts +136 -0
  239. package/src/services/task/ai-docs/AGENTS.md +457 -0
  240. package/src/services/task/ai-docs/ARCHITECTURE.md +595 -0
  241. package/src/services/task/ai-docs/task-spec.md +1474 -0
  242. package/src/services/task/constants.ts +10 -0
  243. package/src/services/task/contact.ts +30 -0
  244. package/src/services/task/dialer.ts +80 -0
  245. package/src/services/task/digital/Digital.ts +97 -0
  246. package/src/services/task/state-machine/TaskStateMachine.ts +1320 -0
  247. package/src/services/task/state-machine/actions.ts +741 -0
  248. package/src/services/task/state-machine/ai-docs/AGENTS.md +460 -0
  249. package/src/services/task/state-machine/ai-docs/ARCHITECTURE.md +1156 -0
  250. package/src/services/task/state-machine/ai-docs/task-state-machine-spec.md +2247 -0
  251. package/src/services/task/state-machine/constants.ts +172 -0
  252. package/src/services/task/state-machine/guards.ts +442 -0
  253. package/src/services/task/state-machine/index.ts +28 -0
  254. package/src/services/task/state-machine/types.ts +258 -0
  255. package/src/services/task/state-machine/uiControlsComputer.ts +1135 -0
  256. package/src/services/task/taskDataNormalizer.ts +137 -0
  257. package/src/services/task/types.ts +819 -70
  258. package/src/services/task/voice/Voice.ts +1851 -0
  259. package/src/services/task/voice/WebRTC.ts +191 -0
  260. package/src/services/task/voice/wxAppVoiceMethods.ts +516 -0
  261. package/src/services/wxAppDiagnosticLogging.ts +174 -0
  262. package/src/services/wxAppTelephonyUtils.ts +14 -0
  263. package/src/types.ts +262 -11
  264. package/src/utils/AGENTS.md +289 -0
  265. package/src/utils/PageCache.ts +38 -5
  266. package/src/utils/ai-docs/utils-spec.md +391 -0
  267. package/src/webex.js +10 -0
  268. package/test/unit/spec/cc.ts +2210 -119
  269. package/test/unit/spec/logger-proxy.ts +70 -0
  270. package/test/unit/spec/metrics/MetricsManager.ts +25 -0
  271. package/test/unit/spec/metrics/behavioral-events.ts +60 -0
  272. package/test/unit/spec/services/AddressBook.ts +37 -6
  273. package/test/unit/spec/services/AnswerCallOnWebexService.ts +264 -0
  274. package/test/unit/spec/services/ApiAiAssistant.ts +311 -21
  275. package/test/unit/spec/services/EntryPoint.ts +87 -40
  276. package/test/unit/spec/services/Queue.ts +123 -12
  277. package/test/unit/spec/services/UserPreference.ts +401 -0
  278. package/test/unit/spec/services/WebCallingService.ts +7 -1
  279. package/test/unit/spec/services/WebexCrossClientService.ts +467 -0
  280. package/test/unit/spec/services/WxAppTelephonyMercurySync.ts +136 -0
  281. package/test/unit/spec/services/config/Util.ts +129 -0
  282. package/test/unit/spec/services/config/index.ts +97 -29
  283. package/test/unit/spec/services/core/Utils.ts +425 -8
  284. package/test/unit/spec/services/core/WebexRequest.ts +3 -1
  285. package/test/unit/spec/services/core/aqm-reqs.ts +113 -1
  286. package/test/unit/spec/services/core/websocket/WebSocketManager.ts +66 -40
  287. package/test/unit/spec/services/task/AutoWrapup.ts +63 -0
  288. package/test/unit/spec/services/task/Task.ts +745 -0
  289. package/test/unit/spec/services/task/TaskFactory.ts +99 -0
  290. package/test/unit/spec/services/task/TaskManager.ts +2518 -1494
  291. package/test/unit/spec/services/task/TaskUtils.ts +235 -0
  292. package/test/unit/spec/services/task/WebexCallingUtils.ts +153 -0
  293. package/test/unit/spec/services/task/contact.ts +33 -0
  294. package/test/unit/spec/services/task/dialer.ts +190 -0
  295. package/test/unit/spec/services/task/digital/Digital.ts +105 -0
  296. package/test/unit/spec/services/task/state-machine/TaskStateMachine.ts +4060 -0
  297. package/test/unit/spec/services/task/state-machine/guards.ts +839 -0
  298. package/test/unit/spec/services/task/state-machine/types.ts +18 -0
  299. package/test/unit/spec/services/task/state-machine/uiControlsComputer.ts +3101 -0
  300. package/test/unit/spec/services/task/taskTestUtils.ts +87 -0
  301. package/test/unit/spec/services/task/voice/Voice.ts +2061 -0
  302. package/test/unit/spec/services/task/voice/WebRTC.ts +235 -0
  303. package/test/unit/spec/services/task/voice/wxAppVoiceMethods.ts +603 -0
  304. package/test/unit/spec/services/wxAppDiagnosticLogging.ts +143 -0
  305. package/test/unit/spec/wellnessSampleUtils.ts +288 -0
  306. package/umd/contact-center.min.js +2 -2
  307. package/umd/contact-center.min.js.map +1 -1
  308. package/dist/services/task/index.js +0 -1525
  309. package/dist/services/task/index.js.map +0 -1
  310. package/dist/types/services/task/index.d.ts +0 -650
  311. package/src/services/task/index.ts +0 -1801
  312. package/test/unit/spec/services/task/index.ts +0 -2184
@@ -4,14 +4,22 @@ import {Failure, AugmentedError} from './GlobalTypes';
4
4
  import LoggerProxy from '../../logger-proxy';
5
5
  import WebexRequest from './WebexRequest';
6
6
  import {
7
+ ConsultConferenceData,
8
+ consultConferencePayloadData,
9
+ ConsultTransferDestinationType,
7
10
  TaskData,
8
- ConsultTransferPayLoad,
9
11
  CONSULT_TRANSFER_DESTINATION_TYPE,
12
+ DESTINATION_TYPE,
10
13
  Interaction,
14
+ InteractionParticipant,
11
15
  } from '../task/types';
12
16
  import {PARTICIPANT_TYPES, STATE_CONSULT} from './constants';
13
17
  import {DialPlan} from '../config/types';
14
18
 
19
+ /** Returns whether a value is a non-null object with string keys. */
20
+ export const isRecord = (value: unknown): value is Record<string, unknown> =>
21
+ typeof value === 'object' && value !== null;
22
+
15
23
  /**
16
24
  * Extracts common error details from a Webex request payload.
17
25
  *
@@ -28,55 +36,68 @@ const getCommonErrorDetails = (errObj: WebexRequestPayload) => {
28
36
  };
29
37
 
30
38
  /**
31
- * Checks if the destination type represents an entry point variant (EPDN or ENTRYPOINT).
32
- */
33
- const isEntryPointOrEpdn = (destAgentType?: string): boolean => {
34
- return destAgentType === 'EPDN' || destAgentType === 'ENTRYPOINT';
35
- };
36
-
37
- /**
38
- * Determines if the task involves dialing a number based on the destination type.
39
- * Returns 'DIAL_NUMBER' for dial-related destinations, empty string otherwise.
39
+ * Strips characters defined in the dial plan entry from the input string.
40
+ *
41
+ * @param input - The dial number to sanitize
42
+ * @param strippedChars - String of characters to remove from the input
43
+ * @returns The sanitized input with specified characters removed
40
44
  */
41
- const getAgentActionTypeFromTask = (taskData?: TaskData): 'DIAL_NUMBER' | '' => {
42
- const destAgentType = taskData?.destinationType;
45
+ export const stripDialPlanChars = (input: string, strippedChars: string): string => {
46
+ if (!strippedChars) {
47
+ return input;
48
+ }
43
49
 
44
- // Check if destination requires dialing: direct dial number or entry point variants
45
- const isDialNumber = destAgentType === 'DN';
46
- const isEntryPointVariant = isEntryPointOrEpdn(destAgentType);
50
+ const charsToStrip = new Set(strippedChars.split(''));
47
51
 
48
- // If the destination type is a dial number or an entry point variant, return 'DIAL_NUMBER'
49
- return isDialNumber || isEntryPointVariant ? 'DIAL_NUMBER' : '';
52
+ return input
53
+ .split('')
54
+ .filter((c) => !charsToStrip.has(c))
55
+ .join('');
50
56
  };
51
57
 
52
- // Fallback regex for US/Canada dial numbers when no dial plan entries are configured
53
- export const FALLBACK_DIAL_NUMBER_REGEX = /1[0-9]{3}[2-9][0-9]{6}([,]{1,10}[0-9]+){0,1}/;
54
-
55
58
  /**
56
59
  * Validates a dial number against the provided dial plan regex patterns.
57
60
  * A number is valid if it matches at least one regex pattern in the dial plans.
58
- * Falls back to US/Canada regex validation if no dial plan entries are configured.
61
+ * Skips validation when no dial plan entries are configured, deferring to the server.
59
62
  *
60
63
  * @param input - The dial number to validate
61
64
  * @param dialPlanEntries - Array of dial plan entries containing regex patterns
62
- * @returns true if the input matches at least one dial plan regex pattern, false otherwise
65
+ * @returns true if the input matches at least one dial plan regex pattern or no entries are configured, false otherwise
63
66
  */
64
67
  export const isValidDialNumber = (
65
68
  input: string,
66
69
  dialPlanEntries: DialPlan['dialPlanEntity']
67
70
  ): boolean => {
71
+ if (!input) {
72
+ LoggerProxy.warn('Dial number is empty or undefined.', {
73
+ module: 'Utils',
74
+ method: 'isValidDialNumber',
75
+ });
76
+
77
+ return false;
78
+ }
79
+
68
80
  if (!dialPlanEntries || dialPlanEntries.length === 0) {
69
- LoggerProxy.info('No dial plan entries found. Falling back to US number validation.');
81
+ LoggerProxy.log(
82
+ 'No dial plan entries found. Skipping client-side validation, deferring to server.',
83
+ {module: 'Utils', method: 'isValidDialNumber'}
84
+ );
70
85
 
71
- return FALLBACK_DIAL_NUMBER_REGEX.test(input);
86
+ return true;
72
87
  }
73
88
 
74
89
  return dialPlanEntries.some((entry) => {
75
90
  try {
91
+ const sanitizedInput = stripDialPlanChars(input, entry.strippedChars);
76
92
  const regex = new RegExp(entry.regex);
77
93
 
78
- return regex.test(input);
79
- } catch {
94
+ return regex.test(sanitizedInput);
95
+ } catch (e) {
96
+ LoggerProxy.warn(`Failed to validate dial number against entry "${entry.name}": ${e}`, {
97
+ module: 'Utils',
98
+ method: 'isValidDialNumber',
99
+ });
100
+
80
101
  return false;
81
102
  }
82
103
  });
@@ -243,6 +264,7 @@ export const createErrDetailsObject = (errObj: WebexRequestPayload) => {
243
264
  return new Err.Details('Service.reqs.generic.failure', details);
244
265
  };
245
266
 
267
+ /*
246
268
  /**
247
269
  * Gets the consulted agent ID from the media object by finding the agent
248
270
  * in the consult media participants (excluding the current agent).
@@ -321,9 +343,16 @@ export const calculateDestAgentId = (interaction: Interaction, agentId: string):
321
343
  return destAgentIdCBT;
322
344
  }
323
345
 
324
- return interaction.participants[consultingAgent]?.type === PARTICIPANT_TYPES.EP_DN
325
- ? interaction.participants[consultingAgent]?.epId
326
- : interaction.participants[consultingAgent]?.id;
346
+ const participant = interaction.participants[consultingAgent];
347
+ if (!participant) {
348
+ return '';
349
+ }
350
+
351
+ if (participant.type === PARTICIPANT_TYPES.EP_DN) {
352
+ return (participant as InteractionParticipant & {epId?: string}).epId ?? '';
353
+ }
354
+
355
+ return participant.id ?? '';
327
356
  };
328
357
 
329
358
  /**
@@ -358,16 +387,77 @@ export const calculateDestType = (interaction: Interaction, agentId: string): st
358
387
  return CONSULT_TRANSFER_DESTINATION_TYPE.AGENT;
359
388
  };
360
389
 
390
+ /**
391
+ * Gets the destination agent ID from participants.
392
+ * Finds a participant who is not the current agent and is an agent type.
393
+ *
394
+ * @param participants - The participants object from interaction
395
+ * @param agentId - The current agent's ID
396
+ * @returns The destination agent ID, or undefined if none found
397
+ */
398
+ export const buildConsultConferenceParamData = (
399
+ dataPassed: consultConferencePayloadData,
400
+ interactionIdPassed: string
401
+ ): {interactionId: string; data: ConsultConferenceData} => {
402
+ const data: ConsultConferenceData = {
403
+ ...('agentId' in dataPassed && {agentId: dataPassed.agentId}),
404
+ to: dataPassed.destAgentId,
405
+ destinationType: '',
406
+ };
407
+
408
+ if ('destinationType' in dataPassed) {
409
+ const destinationType = String(dataPassed.destinationType || '').trim();
410
+ const normalizedDestinationType = destinationType.toUpperCase().replace(/[-_\s]/g, '');
411
+
412
+ if (normalizedDestinationType === 'DN' || normalizedDestinationType === 'DIALNUMBER') {
413
+ data.destinationType = DESTINATION_TYPE.DIALNUMBER;
414
+ } else if (normalizedDestinationType === 'EPDN' || normalizedDestinationType === 'ENTRYPOINT') {
415
+ data.destinationType = DESTINATION_TYPE.ENTRYPOINT;
416
+ } else if (normalizedDestinationType === 'QUEUE') {
417
+ data.destinationType = DESTINATION_TYPE.QUEUE;
418
+ } else if (normalizedDestinationType === 'AGENT') {
419
+ data.destinationType = DESTINATION_TYPE.AGENT;
420
+ } else {
421
+ data.destinationType = destinationType as ConsultConferenceData['destinationType'];
422
+ }
423
+ } else {
424
+ data.destinationType = DESTINATION_TYPE.AGENT;
425
+ }
426
+
427
+ return {
428
+ interactionId: interactionIdPassed,
429
+ data,
430
+ };
431
+ };
432
+
433
+ /**
434
+ * Derives the consult transfer destination type based on task data.
435
+ * This function determines the appropriate destination type for a consult transfer
436
+ * by examining the destination type stored in the task data.
437
+ *
438
+ * @param taskData - The task data containing destination information
439
+ * @returns The derived consult transfer destination type
440
+ * @public
441
+ */
361
442
  export const deriveConsultTransferDestinationType = (
362
- taskData?: TaskData
363
- ): ConsultTransferPayLoad['destinationType'] => {
364
- const agentActionType = getAgentActionTypeFromTask(taskData);
365
-
366
- if (agentActionType === 'DIAL_NUMBER') {
367
- return isEntryPointOrEpdn(taskData?.destinationType)
368
- ? CONSULT_TRANSFER_DESTINATION_TYPE.ENTRYPOINT
369
- : CONSULT_TRANSFER_DESTINATION_TYPE.DIALNUMBER;
443
+ taskData: TaskData
444
+ ): ConsultTransferDestinationType => {
445
+ const destType = taskData?.destinationType;
446
+ const normalizedDestType = String(destType || '')
447
+ .toUpperCase()
448
+ .replace(/[-_\s]/g, '');
449
+
450
+ // Map destination types to consult transfer destination types
451
+ if (normalizedDestType === 'DN' || normalizedDestType === 'DIALNUMBER') {
452
+ return CONSULT_TRANSFER_DESTINATION_TYPE.DIALNUMBER;
453
+ }
454
+ if (normalizedDestType === 'EPDN' || normalizedDestType === 'ENTRYPOINT') {
455
+ return CONSULT_TRANSFER_DESTINATION_TYPE.ENTRYPOINT;
456
+ }
457
+ if (normalizedDestType === 'QUEUE') {
458
+ return CONSULT_TRANSFER_DESTINATION_TYPE.QUEUE;
370
459
  }
371
460
 
461
+ // Default to agent if no specific type matches
372
462
  return CONSULT_TRANSFER_DESTINATION_TYPE.AGENT;
373
463
  };
@@ -34,14 +34,16 @@ class WebexRequest {
34
34
  resource: string;
35
35
  method: HTTP_METHODS;
36
36
  body?: RequestBody;
37
+ headers?: Record<string, string | null>;
37
38
  }): Promise<IHttpResponse> {
38
- const {service, resource, method, body} = options;
39
+ const {service, resource, method, body, headers} = options;
39
40
 
40
41
  return this.webex.request({
41
42
  service,
42
43
  resource,
43
44
  method,
44
45
  body,
46
+ ...(headers ? {headers} : {}),
45
47
  });
46
48
  }
47
49
 
@@ -0,0 +1,381 @@
1
+ # Core Service - AI Agent Guide
2
+
3
+ > **Legacy/reference-only.** Canonical SDD: [`core-spec.md`](core-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:** Core infrastructure components include WebSocket management, HTTP requests, error handling, and utilities. For repository rules and cross-service patterns, see the [root orchestrator AGENTS.md](../../../../AGENTS.md).
6
+
7
+ ---
8
+
9
+ ## Key Capabilities
10
+
11
+ The Core service provides the foundational infrastructure layer that all other services depend on:
12
+
13
+ - **WebSocket Communication**: Real-time bidirectional messaging with the contact center backend, including automatic reconnection and keepalive management
14
+ - **HTTP Request Handling**: Authenticated REST API calls to WCC API Gateway with built-in error handling and log upload support
15
+ - **AQM Request/Response Pattern**: A structured pattern used by the routing and contact layers to send HTTP requests to the contact center backend and correlate responses/failures via WebSocket notifications
16
+ - **Error Handling & Logging**: Standardized error extraction, logging via `LoggerProxy`, and log upload utilities that all services use for consistent error reporting
17
+
18
+ | Component | File | Description |
19
+ |-----------|------|-------------|
20
+ | `WebSocketManager` | [`WebSocketManager.ts`](../websocket/WebSocketManager.ts) | Manages the WebSocket connection lifecycle including initialization, message dispatch, and graceful shutdown. Emits `message` events for incoming data and `socketClose` when the connection drops while reconnect is allowed. |
21
+ | `ConnectionService` | [`connection-service.ts`](../websocket/connection-service.ts) | Orchestrates reconnection logic and keepalive heartbeats on top of `WebSocketManager`. Detects connection loss and triggers `silentRelogin()` to restore agent state transparently. |
22
+ | `WebexRequest` | [`WebexRequest.ts`](../WebexRequest.ts) | Singleton HTTP client that wraps authenticated requests to the WCC API Gateway. Handles service routing, response parsing, and provides a `uploadLogs` method for diagnostics. |
23
+ | `AqmReqs` | [`aqm-reqs.ts`](../aqm-reqs.ts) | Factory for creating request methods that send HTTP requests and wait for correlated WebSocket notifications (success or failure). Used by routing and task services to implement their API methods. |
24
+ | `Utils` | [`Utils.ts`](../Utils.ts) | Shared utility functions including `getErrorDetails()` for standardized error handling, `generateTaskErrorObject()` for task-specific errors, and `createErrDetailsObject()` for constructing error detail objects. |
25
+ | `Err` | [`Err.ts`](../Err.ts) | Error class definitions. `Err.Details` carries structured error metadata (status, type, trackingId) for consistent error propagation. |
26
+ | `constants` | [`constants.ts`](../constants.ts) | Timeout values, interval durations, participant types, interaction states, and method name constants used throughout the core layer. Any new constants for core should be defined here. |
27
+
28
+ ---
29
+
30
+ ## File Structure
31
+
32
+ ```
33
+ services/core/
34
+ ├── aqm-reqs.ts # AQM request handler
35
+ ├── constants.ts # Core constants
36
+ ├── Err.ts # Error classes
37
+ ├── GlobalTypes.ts # Failure, Msg<T>, etc.
38
+ ├── types.ts # Request/response types
39
+ ├── Utils.ts # Utility functions
40
+ ├── WebexRequest.ts # HTTP client
41
+ └── websocket/
42
+ ├── WebSocketManager.ts # Main WS handler
43
+ ├── connection-service.ts # Connection lifecycle
44
+ ├── keepalive.worker.js # Keepalive worker
45
+ └── types.ts # WS types
46
+ ```
47
+
48
+ ---
49
+
50
+
51
+ ## WebSocketManager
52
+
53
+ `WebSocketManager` handles the raw WebSocket connection to the contact center backend. It is instantiated by the `Services` layer and used internally — other services interact with it through `ConnectionService`.
54
+
55
+ ### Reference Usage
56
+
57
+ ```typescript
58
+ // Initialize in Services
59
+ this.webSocketManager = new WebSocketManager({webex});
60
+
61
+ // Connect
62
+ const welcomeEvent = await webSocketManager.initWebSocket({
63
+ body: connectionConfig,
64
+ });
65
+
66
+ // Listen for messages
67
+ webSocketManager.on('message', (event) => {
68
+ const data = JSON.parse(event);
69
+ // Handle event
70
+ });
71
+
72
+ // Close
73
+ webSocketManager.close(false, 'Reason');
74
+ ```
75
+
76
+ ### Events
77
+
78
+ | Event | Data | Description |
79
+ |-------|------|-------------|
80
+ | `message` | string (JSON) | WebSocket message received |
81
+ | `socketClose` | - | Socket closed while reconnect is allowed |
82
+
83
+ ### Connection Lifecycle
84
+
85
+ `WebSocketManager` and `ConnectionService` work together to manage the full connection lifecycle. `WebSocketManager` owns the raw socket while `ConnectionService` adds reconnection intelligence and keepalive on top.
86
+
87
+ **Connection Flow:**
88
+
89
+ ```
90
+ 1. initWebSocket() called
91
+ 2. ConnectionService listeners attached (`message`, `socketClose`) during construction
92
+ 3. WebSocket connects to backend
93
+ 4. Keepalive worker started on `onopen`
94
+ 5. Welcome event received
95
+ 6. Runtime messages/keepalive processed via existing listeners
96
+ ```
97
+
98
+ **Reconnection Flow:**
99
+
100
+ ```
101
+ 1. Connection lost detected
102
+ 2. ConnectionService emits 'connectionLost'
103
+ 3. cc.handleConnectionLost() called
104
+ 4. silentRelogin() attempted
105
+ 5. On success: state restored
106
+ 6. On AGENT_NOT_FOUND: handle silently
107
+ ```
108
+
109
+ ### Keepalive
110
+
111
+ A Web Worker ([`keepalive.worker.js`](../websocket/keepalive.worker.js)) runs alongside the WebSocket to detect connection loss and keep the socket alive. It starts on `onopen` and sends `{keepalive: 'true'}` to the backend every **4 seconds** (`KEEPALIVE_WORKER_INTERVAL`). The worker also monitors `navigator.onLine` — if the network goes offline and the socket doesn't close within **16 seconds** (`CLOSE_SOCKET_TIMEOUT`), it force-closes the socket.
112
+
113
+ On the receiving side, `ConnectionService.onPing()` listens for all WebSocket messages and resets two timers on each message:
114
+ - **`reconnectingTimer`** (8s / `WS_DISCONNECT_ALLOWED`) — if no message arrives within 8s, marks connection as lost
115
+ - **`restoreTimer`** (`lostConnectionRecoveryTimeout` from agent config) — if connection isn't restored within this window, marks restore as failed
116
+
117
+ When a keepalive response arrives after a lost-connection state, `ConnectionService` resets its flags and dispatches a recovery event. If the socket fully closes, `ConnectionService` retries `initWebSocket()` every **5 seconds** (`CONNECTIVITY_CHECK_INTERVAL`).
118
+
119
+ ---
120
+
121
+ ## WebexRequest
122
+
123
+ `WebexRequest` is a singleton HTTP client that all services use to make authenticated REST API calls to the contact center backend. It handles service URL resolution, request formatting, and response parsing.
124
+
125
+ ### The `service` Property
126
+
127
+ The `service` field in request options is a **service identifier string** that the Webex SDK's internal service catalog (`this.webex.request()`) resolves to a base URL at runtime. All contact center API calls use:
128
+
129
+ ```typescript
130
+ import {WCC_API_GATEWAY} from '../constants';
131
+ // WCC_API_GATEWAY = 'wcc-api-gateway'
132
+ ```
133
+
134
+ This constant is defined in [`services/constants.ts`](../../constants.ts). The Webex SDK maps `'wcc-api-gateway'` to the appropriate contact center API gateway URL based on the environment. The `resource` is then appended as the path.
135
+
136
+ ### Reference Usage
137
+
138
+ ```typescript
139
+ // Get singleton
140
+ const webexReq = WebexRequest.getInstance({webex});
141
+
142
+ // Make request
143
+ const response = await webexReq.request({
144
+ service: WCC_API_GATEWAY, // resolved to base URL by Webex SDK
145
+ resource: '/v1/endpoint', // appended as path
146
+ method: HTTP_METHODS.POST,
147
+ body: { key: 'value' }, // optional request payload
148
+ });
149
+
150
+ // Upload logs
151
+ await webexReq.uploadLogs({
152
+ correlationId: trackingId,
153
+ });
154
+ ```
155
+
156
+ ### Response Structure
157
+
158
+ ```typescript
159
+ {
160
+ statusCode: 200,
161
+ body: { /* response data */ },
162
+ headers: {
163
+ trackingid: 'uuid',
164
+ },
165
+ }
166
+ ```
167
+
168
+ ---
169
+
170
+ ## AqmReqs
171
+
172
+ The AQM (Agent Queue Manager) layer provides a request/response pattern over HTTP + WebSocket. Services like **routing** and **contact** use `AqmReqs` to define API methods that:
173
+
174
+ 1. Send an HTTP request to the contact center backend via `WebexRequest`
175
+ 2. Wait for a correlated WebSocket notification indicating success or failure
176
+ 3. Return the typed result or throw a structured error
177
+
178
+ This decouples the request initiation (HTTP) from the asynchronous result delivery (WebSocket), which matches the contact center backend's event-driven architecture.
179
+
180
+ ### Reference Usage
181
+
182
+ ```typescript
183
+ // Define request configuration
184
+ const serviceMethod = routing.req((p: {data: ParamType}) => ({
185
+ url: '/v1/endpoint',
186
+ host: WCC_API_GATEWAY,
187
+ data: p.data,
188
+ method: HTTP_METHODS.POST,
189
+ err: errorHandler,
190
+ notifSuccess: {
191
+ bind: {type: CC_EVENTS.SUCCESS, data: {type: CC_EVENTS.SUCCESS}},
192
+ msg: {} as SuccessType,
193
+ },
194
+ notifFail: {
195
+ bind: {type: CC_EVENTS.FAIL, data: {type: CC_EVENTS.FAIL}},
196
+ errId: 'Service.aqm.operation',
197
+ },
198
+ }));
199
+
200
+ // Call method
201
+ const result = await serviceMethod({data: params});
202
+ ```
203
+
204
+ ---
205
+
206
+ ## Error Handling Utilities
207
+
208
+ ### `getErrorDetails()`
209
+
210
+ Standard error handler for SDK operations:
211
+
212
+ ```typescript
213
+ import {getErrorDetails} from './services/core/Utils';
214
+
215
+ try {
216
+ await operation();
217
+ } catch (error) {
218
+ const {error: detailedError, reason} = getErrorDetails(
219
+ error,
220
+ 'methodName', // Method name for logging
221
+ 'ModuleName' // Module name for logging
222
+ );
223
+
224
+ // getErrorDetails automatically:
225
+ // 1. Logs the error
226
+ // 2. Uploads logs (unless AGENT_NOT_FOUND in silentRelogin)
227
+ // 3. Extracts reason from error.details
228
+ // 4. Creates Error with reason as message
229
+
230
+ throw detailedError;
231
+ }
232
+ ```
233
+
234
+ ### `generateTaskErrorObject()`
235
+
236
+ Error handler for task operations:
237
+
238
+ ```typescript
239
+ import {generateTaskErrorObject} from './services/core/Utils';
240
+
241
+ try {
242
+ await taskOperation();
243
+ } catch (error) {
244
+ const taskError = generateTaskErrorObject(
245
+ error,
246
+ 'transfer',
247
+ 'TaskModule'
248
+ );
249
+ throw taskError;
250
+ }
251
+ ```
252
+
253
+ ---
254
+
255
+ ## Type Definitions
256
+
257
+ ### Msg\<T\>
258
+
259
+ Generic message wrapper used throughout the SDK. All WebSocket messages and AQM responses conform to this shape:
260
+
261
+ ```typescript
262
+ export type Msg<T = any> = {
263
+ type: string; // Message/Event type identifier
264
+ orgId: string; // Organization identifier
265
+ trackingId: string; // Unique tracking identifier
266
+ data: T; // Message/Event payload data
267
+ };
268
+
269
+ // Usage — the payload type goes into `data`
270
+ export type LoginSuccess = Msg<{
271
+ agentId: string;
272
+ status: string;
273
+ // ...
274
+ }>;
275
+ // Resulting shape: { type, orgId, trackingId, data: { agentId, status, ... } }
276
+ ```
277
+
278
+ ### Failure
279
+
280
+ A specific `Msg<T>` for failure responses. Access error details via `failure.data`:
281
+
282
+ ```typescript
283
+ export type Failure = Msg<{
284
+ agentId: string;
285
+ trackingId: string;
286
+ reasonCode: number;
287
+ orgId: string;
288
+ reason: string;
289
+ }>;
290
+
291
+ // Usage in catch
292
+ const failure = error.details as Failure;
293
+ LoggerProxy.error(`Operation failed: ${failure.data?.reason}`, {
294
+ module: 'MyService',
295
+ method: 'myMethod',
296
+ trackingId: failure?.trackingId,
297
+ });
298
+ ```
299
+
300
+ ### AugmentedError
301
+
302
+ Error interface with a flexible data field for additional context:
303
+
304
+ ```typescript
305
+ export interface AugmentedError extends Error {
306
+ data?: Record<string, any>;
307
+ }
308
+ ```
309
+
310
+ ---
311
+
312
+ ## Error Classes
313
+
314
+ ### Err.Details
315
+
316
+ ```typescript
317
+ import * as Err from './Err';
318
+
319
+ const error = new Err.Details('Service.aqm.agent.login', {
320
+ status: 401,
321
+ type: 'UNAUTHORIZED',
322
+ trackingId: 'uuid',
323
+ });
324
+ ```
325
+
326
+ ### createErrDetailsObject
327
+
328
+ ```typescript
329
+ import {createErrDetailsObject} from './Utils';
330
+
331
+ const errDetails = createErrDetailsObject(webexRequestPayload);
332
+ // Returns Err.Details with trackingId and body
333
+ ```
334
+
335
+ ---
336
+
337
+ ## Constants
338
+
339
+ All core-level constants (timeouts, intervals, participant types, method names) are defined in [`constants.ts`](../constants.ts). Any new constants for the core layer should be added there.
340
+
341
+ ---
342
+
343
+ ## Best Practices
344
+
345
+ ### Always Use Error Utilities
346
+
347
+ ```typescript
348
+ // Correct
349
+ const {error: detailedError} = getErrorDetails(error, method, module);
350
+ throw detailedError;
351
+
352
+ // Wrong - loses context
353
+ throw error;
354
+ ```
355
+
356
+ ### Check Response Status
357
+
358
+ ```typescript
359
+ const response = await webexReq.request({...});
360
+
361
+ if (response.statusCode !== 200) {
362
+ throw new Error(`API call failed with ${response.statusCode}`);
363
+ }
364
+ ```
365
+
366
+ ### Extract TrackingId
367
+
368
+ ```typescript
369
+ const trackingId = response.headers?.trackingid ||
370
+ response.headers?.TrackingID;
371
+ ```
372
+
373
+ ---
374
+
375
+ ## Related
376
+
377
+ - [Root Orchestrator AGENTS.md](../../../../AGENTS.md) - Task routing, critical rules, cross-service patterns
378
+ - [WebSocketManager.ts](../websocket/WebSocketManager.ts)
379
+ - [WebexRequest.ts](../WebexRequest.ts)
380
+ - [Utils.ts](../Utils.ts)
381
+ - [GlobalTypes.ts](../GlobalTypes.ts)