@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
@@ -0,0 +1,505 @@
1
+ # Agent — SPEC
2
+
3
+ > Start here → root [`AGENTS.md`](../../../../AGENTS.md) · router [`SPEC_INDEX.md`](../../../../ai-docs/SPEC_INDEX.md) · system [`ARCHITECTURE.md`](../../../../ai-docs/ARCHITECTURE.md). This is the module's canonical specification.
4
+
5
+ ## Metadata
6
+
7
+ | Field | Value |
8
+ |---|---|
9
+ | Module id | `agent` |
10
+ | Source path(s) | `src/services/agent` |
11
+ | Doc kind | Module spec |
12
+ | Coverage score | Partial (manifest-authoritative); 15/15 required document fields present |
13
+ | Generated from | `module-spec` @ SDLC template library `0.2.1` |
14
+ | generated_by / approved_by / updated_at | Codex generator / developer-approved follow-up review remediation / 2026-07-21 |
15
+ | Validation status | Follow-up validation passed (independent Claude fallback, 2026-07-21); coverage remains Partial |
16
+
17
+ ## Evidence Rules
18
+ Every requirement cites stable source and test file paths. Code/tests are the behavioral referee; routed source text supplies explicit intent and rationale. Missing or contradictory evidence blocks promotion.
19
+
20
+ ## Source Material Register
21
+ | Source material | Scope | Decision | Detail location or disposition |
22
+ |---|---|---|---|
23
+ | Reviewed prior module guides and architecture material | overview / architecture / API / tests | used and code-checked | Content is placed by meaning throughout this specification; exact routing remains in the manifest. |
24
+
25
+ ## Overview
26
+ Agent owns the `routingAgent(AqmReqs)` request factory for station login, station logout, agent-state change, buddy-agent lookup, and agent-session reload. ContactCenter exposes the application-facing methods/events and owns profile/device updates plus recovery policy.
27
+
28
+ The factory initiates authenticated HTTP requests and supplies `CC_EVENTS` success/failure binds to AqmReqs. Public response aliases such as `StationLoginResponse`, `StationLogoutResponse`, `BuddyAgentsResponse`, and `SetStateResponse` are package-level contracts in `src/types.ts`; routing payload/notification types remain in `src/services/agent/types.ts`.
29
+
30
+ ## Purpose / Responsibility
31
+ Own AQM request definitions for station login/logout, state change, buddy-agent queries, and reload. Device/profile update and automated relogin orchestration belong to ContactCenter.
32
+
33
+ ## Stack
34
+ TypeScript 5.4 AQM request factory, REST initiation, WebSocket completion events, Jest 27.
35
+
36
+ ## Folder / Package Structure
37
+ ```text
38
+ src/services/agent/
39
+ ├── index.ts
40
+ ├── types.ts
41
+ ```
42
+
43
+ ```text
44
+ services/agent/
45
+ ├── index.ts # Agent service factory
46
+ ├── types.ts # Agent types and events
47
+ └── ai-docs/
48
+ ├── AGENTS.md # Usage documentation
49
+ └── ARCHITECTURE.md # Preserved legacy migration source (non-canonical)
50
+ ```
51
+
52
+ ## Key Files (source of truth)
53
+ | File | Holds |
54
+ |---|---|
55
+ | `src/services/agent/index.ts` | Authoritative Agent implementation or contract source. |
56
+ | `src/services/agent/types.ts` | Authoritative Agent implementation or contract source. |
57
+ | `src/cc.ts` | Authoritative Agent implementation or contract source. |
58
+
59
+ ## Public Surface
60
+ | Contract | Owner | Real surface | Source |
61
+ |---|---|---|---|
62
+ | `routingAgent` | Agent | exported factory `(routing: AqmReqs) => {reload, logout, stationLogin, stateChange, buddyAgents}` | `src/services/agent/index.ts`, `src/index.ts` |
63
+ | ContactCenter agent methods | Contact Center | `stationLogin`, `stationLogout`, `setAgentState`, `getBuddyAgents` | `src/cc.ts`, `src/types.ts` |
64
+ | Profile/device update | Contact Center | `updateAgentProfile(AgentProfileUpdate)`; not a routingAgent method | `src/cc.ts`, `src/types.ts` |
65
+ | Automated relogin | Contact Center | private `silentRelogin()` invokes `services.agent.reload()` | `src/cc.ts` |
66
+ | Routing notification types | Agent | `Logout`, `StateChange`, `StationLoginSuccess`, `BuddyAgentsSuccess`, `ReloginSuccess`, and related contracts | `src/services/agent/types.ts` |
67
+ | Public response aliases | Package | `StationLoginResponse`, `StationLogoutResponse`, `BuddyAgentsResponse`, `SetStateResponse`, `UpdateDeviceTypeResponse` | `src/types.ts`, `src/index.ts` |
68
+
69
+ Key nested WebSocket binds use the actual outer/data constants, for example `CC_EVENTS.AGENT_STATION_LOGIN` with `data.type = CC_EVENTS.AGENT_STATION_LOGIN_SUCCESS` or `CC_EVENTS.AGENT_STATION_LOGIN_FAILED`. See root `CONTRACTS.md` for the package export index.
70
+
71
+ ## Requires (dependencies)
72
+ - AqmReqs and WCC API gateway
73
+ - Correlated WebSocket success/failure notifications
74
+ - Registered ContactCenter profile and connection state
75
+
76
+ - Requires `cc.register()` to be called first
77
+
78
+ - Agent profile must be fetched before login
79
+
80
+ - WebRTC (BROWSER option) requires mercury connection
81
+
82
+ ## Requirements
83
+ | ID | WHAT | WHY | Source Evidence | Test / Example Evidence | Assumptions / Gaps | Confidence |
84
+ |---|---|---|---|---|---|---|
85
+ | AGENT-R-001 | routingAgent station login/logout must use the documented WCC endpoints and settle on their nested `CC_EVENTS` success/failure notifications. | The backend operation is asynchronous and HTTP acknowledgement is not final agent state. | `src/services/agent/index.ts` | `test/unit/spec/services/agent/index.ts` | None; source and test evidence rechecked during the 2026-07-09 remediation; independent document revalidation pending. | PRESENT |
86
+ | AGENT-R-002 | State change must use PUT `/v1/agents/session/state` and preserve typed success/failure binds. | Agent availability drives routing eligibility and must not be inferred from request acknowledgement. | `src/services/agent/index.ts` | `test/unit/spec/services/agent/index.ts` | None; source and test evidence rechecked during the 2026-07-09 remediation; independent document revalidation pending. | PRESENT |
87
+ | AGENT-R-003 | Buddy-agent lookup must preserve its typed request and correlated response contract. | Consult/transfer selection depends on backend-filtered availability. | `src/services/agent/index.ts` | `test/unit/spec/services/agent/index.ts` | None; source and test evidence rechecked during the 2026-07-09 remediation; independent document revalidation pending. | PRESENT |
88
+ | AGENT-R-004 | The agent factory exposes `reload`, while ContactCenter alone decides when automated relogin is permitted. | Transport recovery lacks the profile/policy context required to mutate an agent session safely. | `src/cc.ts` | `test/unit/spec/cc.ts` | None; source and test evidence rechecked during the 2026-07-09 remediation; independent document revalidation pending. | PRESENT |
89
+ | AGENT-R-005 | Device/profile update must be documented as `ContactCenter.updateAgentProfile`, not as an agent-factory method. | Calling a non-existent `routingAgent.deviceUpdate` would fail at runtime. | `src/cc.ts` | `test/unit/spec/cc.ts` | None; source and test evidence rechecked during the 2026-07-09 remediation; independent document revalidation pending. | PRESENT |
90
+ | AGENT-R-006 | BROWSER station login must send `dialNumber` and `deviceId` as `webrtc-{agentId}` on `POST /v1/agents/login`. EXTENSION and AGENT_DN continue to send the caller-supplied dial number for both fields. | QRM stores `agent.dn` from `dialNumber`. Legacy VPOP RTMS only treats a DN as WebRTC when it starts with `webrtc-`; a bare UUID gets a steering prefix and the agent invite fails with SIP 484. | `src/cc.ts` | `test/unit/spec/cc.ts` | Public `stationLogin({loginOption: 'BROWSER'})` input is unchanged; only the backend login payload is prefixed. | PRESENT |
91
+
92
+ ## Design Overview
93
+ `routingAgent` is a pure AQM factory. It receives an initialized AqmReqs instance and returns five request functions: `reload`, `logout`, `stationLogin`, `stateChange`, and `buddyAgents`. Each request config declares the endpoint/payload plus exact `CC_EVENTS` notification binds.
94
+
95
+ ContactCenter validates and enriches public inputs, starts metrics, delegates to the factory, performs browser-calling work when required, and maps backend notifications to application-facing events. `updateAgentProfile()` and private `silentRelogin()` are ContactCenter methods; the latter calls `services.agent.reload()` only after package-level recovery policy permits it.
96
+
97
+ ## Data Flow
98
+ ```mermaid
99
+ flowchart LR
100
+ App[Application] --> CC[ContactCenter public method]
101
+ CC --> Validate[Validate/enrich profile input]
102
+ Validate --> Factory[routingAgent request function]
103
+ Factory --> AQM[AqmReqs]
104
+ AQM --> HTTP[Authenticated WCC HTTP]
105
+ HTTP --> Ack[Acknowledgement]
106
+ AQM --> WS[Await matching CC_EVENTS notification]
107
+ WS -->|success| Result[Typed result to ContactCenter]
108
+ WS -->|failure/timeout| Error[Structured rejection]
109
+ Result --> AppEvent[Return result / emit application event]
110
+ ```
111
+
112
+ Recovery is separate: ConnectionService emits state → ContactCenter evaluates `allowAutomatedRelogin` → ContactCenter calls private `silentRelogin()` → `services.agent.reload()` uses the agent factory.
113
+
114
+ ### Station-login orchestration detail
115
+
116
+ ```mermaid
117
+ flowchart TD
118
+ A[cc.stationLogin] --> B[Validate dial number for AGENT_DN]
119
+ B --> C[services.agent.stationLogin]
120
+ C --> D[AqmReqs.req]
121
+ D --> E[HTTP REST request to backend]
122
+ E --> F[Backend processes]
123
+ F --> G{Success?}
124
+ G -->|Yes| H[StationLoginSuccess event]
125
+ G -->|No| I[StationLoginFailed event]
126
+ H --> J[Register WebCalling if BROWSER]
127
+ J --> K[Track metrics]
128
+ K --> L[Return response]
129
+ I --> M[getErrorDetails]
130
+ M --> N[Throw error]
131
+ ```
132
+
133
+ ### WebSocket-to-application event mapping
134
+
135
+ ```mermaid
136
+ flowchart LR
137
+ A[WebSocket Message] --> B[WebSocketManager]
138
+ B --> C[cc.handleWebsocketMessage]
139
+ C --> D{Event Type?}
140
+ D -->|AGENT_STATE_CHANGE| E[emit agent:stateChange]
141
+ D -->|data.type check| F{Nested Type?}
142
+ F -->|STATION_LOGIN_SUCCESS| G[Transform channelsMap]
143
+ G --> H[emit agent:stationLoginSuccess]
144
+ F -->|LOGOUT_SUCCESS| I[emit agent:logoutSuccess]
145
+ ```
146
+
147
+ ### Silent-relogin decision flow
148
+
149
+ ```mermaid
150
+ flowchart TD
151
+ A[WebSocket Reconnected] --> B[handleConnectionLost]
152
+ B --> C{allowAutomatedRelogin?}
153
+ C -->|Yes| D[silentRelogin]
154
+ C -->|No| M[Retain reported connection state]
155
+ D --> E[services.agent.reload]
156
+ E --> F{Success?}
157
+ F -->|Yes| G[Update agentConfig and device state]
158
+ G --> H{lastStateChangeReason?}
159
+ H -->|agent-wss-disconnect| I[setAgentState Available]
160
+ H -->|Other| J[Keep backend state]
161
+ F -->|No, AGENT_NOT_FOUND| K[Handle silently]
162
+ F -->|No, Other| L[Throw detailed error]
163
+ ```
164
+
165
+ ## Sequence Diagram(s)
166
+ Sequence coverage:
167
+
168
+ | Operation group | Diagram | Failure / recovery coverage |
169
+ |---|---|---|
170
+ | Station login | Station login | Validation, nested failure notification, HTTP rejection, and timeout throw. |
171
+ | Station logout | Station logout | Nested failure/timeout rejects and calling deregistration occurs only after success. |
172
+ | State change | State change | PUT failure notification/timeout returns a structured rejection. |
173
+ | Buddy agents | Buddy-agent lookup | Correlated retrieval failure/timeout rejects. |
174
+ | Reload | Recovery reload | ContactCenter gates reload; relogin failure or disabled policy preserves failure state. |
175
+
176
+ ### Station login
177
+
178
+ ```mermaid
179
+ sequenceDiagram
180
+ participant App
181
+ participant CC as ContactCenter
182
+ participant Svc as Services.agent
183
+ participant AQM as AqmReqs
184
+ participant WS as WebSocket
185
+ participant BE as Backend
186
+ App->>CC: stationLogin(params)
187
+ CC->>CC: Validate dial number
188
+ CC->>CC: timeEvent(LOGIN_SUCCESS, LOGIN_FAILED)
189
+ CC->>Svc: stationLogin({data})
190
+ Svc->>AQM: req(config)
191
+ AQM->>BE: HTTP POST /v1/agents/login
192
+ alt nested success
193
+ BE-->>WS: AgentStationLoginSuccess
194
+ WS-->>AQM: matching success notification
195
+ AQM-->>Svc: StationLoginSuccess
196
+ Svc-->>CC: login response
197
+ CC->>CC: Register WebCalling if BROWSER and enabled
198
+ CC->>CC: trackEvent(LOGIN_SUCCESS)
199
+ CC-->>App: StationLoginResponse
200
+ else nested failure, HTTP rejection, or timeout
201
+ WS-->>AQM: failure notification or no completion
202
+ AQM-->>CC: structured rejection
203
+ CC->>CC: trackEvent(LOGIN_FAILED)
204
+ CC-->>App: throw detailed error
205
+ end
206
+ ```
207
+
208
+ ### Station logout
209
+
210
+ ```mermaid
211
+ sequenceDiagram
212
+ participant App
213
+ participant CC as ContactCenter
214
+ participant Agent as routingAgent
215
+ participant AQM as AqmReqs
216
+ participant WS as Primary WebSocket
217
+ App->>CC: stationLogout({logoutReason})
218
+ CC->>Agent: logout({data})
219
+ Agent->>AQM: POST /v1/agents/logout + nested binds
220
+ alt AGENT_LOGOUT_SUCCESS
221
+ WS-->>AQM: matching nested success
222
+ AQM-->>CC: LogoutSuccess
223
+ CC->>CC: track success; deregister WebCalling line
224
+ CC-->>App: StationLogoutResponse
225
+ else failure, HTTP rejection, or timeout
226
+ WS-->>AQM: matching failure or no completion
227
+ CC->>CC: track failure
228
+ CC-->>App: throw detailed error
229
+ end
230
+ ```
231
+
232
+ ### State change
233
+
234
+ ```mermaid
235
+ sequenceDiagram
236
+ participant App
237
+ participant CC as ContactCenter
238
+ participant Agent as routingAgent
239
+ participant AQM as AqmReqs
240
+ participant WS as Primary WebSocket
241
+ App->>CC: setAgentState(data)
242
+ CC->>Agent: stateChange({data + agentId})
243
+ Agent->>AQM: PUT /v1/agents/session/state + binds
244
+ alt AGENT_STATE_CHANGE_SUCCESS
245
+ WS-->>AQM: matching nested success
246
+ AQM-->>CC: StateChangeSuccess
247
+ CC-->>App: SetStateResponse
248
+ else failure, HTTP rejection, or timeout
249
+ WS-->>AQM: matching failure or no completion
250
+ AQM-->>CC: structured rejection
251
+ CC-->>App: throw detailed error
252
+ end
253
+ ```
254
+
255
+ ### Buddy-agent lookup
256
+
257
+ ```mermaid
258
+ sequenceDiagram
259
+ participant App
260
+ participant CC as ContactCenter
261
+ participant Agent as routingAgent
262
+ participant AQM as AqmReqs
263
+ participant WS as Primary WebSocket
264
+ App->>CC: getBuddyAgents(query)
265
+ CC->>Agent: buddyAgents({data})
266
+ Agent->>AQM: POST /v1/agents/buddyList + binds
267
+ alt AGENT_BUDDY_AGENTS_SUCCESS
268
+ WS-->>AQM: matching nested success
269
+ AQM-->>App: BuddyAgentsResponse
270
+ else retrieve failure or timeout
271
+ WS-->>AQM: matching failure or no completion
272
+ AQM-->>App: structured rejection
273
+ end
274
+ ```
275
+
276
+ ### Recovery reload
277
+
278
+ ```mermaid
279
+ sequenceDiagram
280
+ participant CS as ConnectionService
281
+ participant CC as ContactCenter
282
+ participant Agent as routingAgent
283
+ CS-->>CC: connectionLost(details)
284
+ alt automated relogin allowed
285
+ CC->>CC: silentRelogin()
286
+ CC->>Agent: reload()
287
+ Agent-->>CC: relogin result/failure
288
+ else not allowed
289
+ CC->>CC: retain reported state
290
+ end
291
+ ```
292
+
293
+ ## Class / Component Relationships
294
+ ```mermaid
295
+ classDiagram
296
+ class ContactCenter
297
+ class routingAgent
298
+ class AqmReqs
299
+ class WebSocketManager
300
+ ContactCenter --> routingAgent : public agent operations / reload
301
+ routingAgent --> AqmReqs : request factories
302
+ AqmReqs --> WebSocketManager : correlated notifications
303
+ ContactCenter --> ContactCenter : updateAgentProfile + silentRelogin ownership
304
+ ```
305
+
306
+ ## Use Cases
307
+ - **UC-1 Station login/logout:** validate public input in ContactCenter, initiate through routingAgent, settle from nested WebSocket notification. Evidence: `src/cc.ts`, `src/services/agent/index.ts`, `test/unit/spec/services/agent/index.ts`.
308
+ - **UC-2 State change:** PUT the state payload and return the correlated typed response. Evidence: `src/services/agent/index.ts`, `test/unit/spec/services/agent/index.ts`.
309
+ - **UC-3 Buddy-agent query:** retrieve backend-filtered candidates for consult/transfer. Evidence: `src/services/agent/index.ts`, `test/unit/spec/services/agent/index.ts`.
310
+ - **UC-4 Recovery reload:** ContactCenter decides whether to invoke private relogin and the factory's `reload`. Evidence: `src/cc.ts`, `test/unit/spec/cc.ts`.
311
+ - **UC-5 Device/profile update:** ContactCenter owns `updateAgentProfile`; the agent factory has no device-update method. Evidence: `src/cc.ts`, `test/unit/spec/cc.ts`.
312
+
313
+ ## Business Rules & Invariants
314
+ - Agent must preserve its typed public/event contracts and must not invent backend states or responses. Enforced in `src/services/agent/index.ts`.
315
+
316
+ Change agent state (Available/Idle).
317
+
318
+ **Parameters**:
319
+
320
+ - `state` ('Available' | 'Idle'): New state
321
+
322
+ - `auxCodeId` (string): Auxiliary code ID
323
+
324
+ - `lastStateChangeReason` (string, optional): Reason for change
325
+
326
+ - `agentId` (string, optional): Agent ID (defaults to current agent)
327
+
328
+ **Returns**: `Promise<SetStateResponse>`
329
+
330
+ **Example**:
331
+
332
+ ```typescript
333
+ // Go Available
334
+ await cc.setAgentState({
335
+ state: 'Available',
336
+ auxCodeId: '0',
337
+ });
338
+
339
+ // Go to Idle with specific code
340
+ await cc.setAgentState({
341
+ state: 'Idle',
342
+ auxCodeId: 'break-code-123',
343
+ lastStateChangeReason: 'Coffee break',
344
+ });
345
+ ```
346
+
347
+ The `AgentState` type (`'Available' | 'Idle' | 'RONA' | string`) is extensible -- the `string` union member allows backend-defined states beyond the known values listed below.
348
+
349
+ | State | SubStatus | Description |
350
+ |---|---|---|
351
+ | LoggedIn | Available | Ready to receive tasks |
352
+ | LoggedIn | Idle | On break or not ready (uses aux code for sub-reason) |
353
+ | RONA | - | Rang but no answer; agent failed to accept offered task |
354
+ | LoggedOut | - | Not logged in |
355
+ | LoggedIn | *(custom)* | Additional org-specific states defined via aux codes |
356
+
357
+ > **Note**: `AgentState` is a union with `string`, so consumers should handle unknown state values gracefully rather than exhaustively matching only the known literals.
358
+
359
+ ## Concurrency & Reactive Flow
360
+ - Async operations must remain non-blocking; listener/queue/actor ordering and cleanup rules in the preserved source content are contractual.
361
+
362
+ ## Protocol / Wire Format
363
+ - Request, response, and event payload ownership is anchored in `src/services/agent/index.ts`. HTTP initiates backend work where applicable; WebSocket messages provide realtime events and, for AQM flows, correlated completion.
364
+
365
+ For example, station login defines the real outer and nested event binds:
366
+
367
+ ```typescript
368
+ {
369
+ url: '/v1/agents/login',
370
+ host: WCC_API_GATEWAY,
371
+ data: p.data,
372
+ err: (e) => new Err.Details('Service.aqm.agent.stationLogin', {/* response fields */}),
373
+ notifSuccess: {
374
+ bind: {
375
+ type: CC_EVENTS.AGENT_STATION_LOGIN,
376
+ data: {type: CC_EVENTS.AGENT_STATION_LOGIN_SUCCESS},
377
+ },
378
+ msg: {} as Agent.StationLoginSuccess,
379
+ },
380
+ notifFail: {
381
+ bind: {
382
+ type: CC_EVENTS.AGENT_STATION_LOGIN,
383
+ data: {type: CC_EVENTS.AGENT_STATION_LOGIN_FAILED},
384
+ },
385
+ errId: 'Service.aqm.agent.stationLoginFailed',
386
+ },
387
+ }
388
+ ```
389
+
390
+ ## Error Handling & Failure Modes
391
+ | Condition | Signal (error/code/result) | Caller recovery |
392
+ |---|---|---|
393
+ | Dependency rejection | Typed/rethrown error or failure event | Inspect structured details, preserve tracking id, and retry only when the operation is safe. |
394
+ | Timeout or missing async completion | Timeout/recovery state | Follow the module-specific recovery path; never synthesize success. |
395
+
396
+ > **Host-application example:** `showStationLoginError` represents consumer-owned UI handling. SDK package implementation must use `LoggerProxy` and must not log raw runtime values.
397
+
398
+ ```typescript
399
+ try {
400
+ await cc.stationLogin(params);
401
+ } catch (error) {
402
+ showStationLoginError({
403
+ message: error.message,
404
+ fieldName: error.data?.fieldName,
405
+ fieldMessage: error.data?.message,
406
+ });
407
+ }
408
+ ```
409
+
410
+ | Reason | Description |
411
+ |---|---|
412
+ | `DUPLICATE_LOCATION` | Extension/DN already in use |
413
+ | `INVALID_DIAL_NUMBER` | Invalid phone number format |
414
+ | `AGENT_NOT_FOUND` | Agent doesn't exist (silent relogin) |
415
+
416
+ For `stationLogin`, special error handling extracts field-specific messages:
417
+
418
+ ```typescript
419
+ // src/services/core/Utils.ts - getStationLoginErrorData
420
+ const errorCodeMessageMap = {
421
+ DUPLICATE_LOCATION: {
422
+ message: 'This extension is already in use',
423
+ fieldName: loginOption,
424
+ },
425
+ INVALID_DIAL_NUMBER: {
426
+ message: 'Enter a valid US dial number...',
427
+ fieldName: loginOption,
428
+ },
429
+ };
430
+ ```
431
+
432
+ **Cause**: Extension/DN already in use by another session
433
+
434
+ **Solution**:
435
+
436
+ 1. Logout from other session
437
+
438
+ 2. Use different extension
439
+
440
+ 3. Contact admin if stuck
441
+
442
+ **Cause**: Agent may be in a call or transitioning state
443
+
444
+ **Solution**:
445
+
446
+ 1. Complete current interaction
447
+
448
+ 2. Wait for state to stabilize
449
+
450
+ 3. Retry state change
451
+
452
+ **Cause**: `allowAutomatedRelogin` config not set
453
+
454
+ **Solution**:
455
+
456
+ ```typescript
457
+ const webex = Webex.init({
458
+ config: {
459
+ cc: {
460
+ allowAutomatedRelogin: true,
461
+ },
462
+ },
463
+ });
464
+ ```
465
+
466
+ ## Pitfalls
467
+ - Station login/logout and state-change binds match both the outer event type and nested `data.type`; flattening either bind can settle the wrong request.
468
+ - `routingAgent` has exactly five request functions and no `deviceUpdate`; profile/device changes belong to ContactCenter.
469
+ - ConnectionService reports transport state, but ContactCenter alone decides whether `silentRelogin()` is allowed and whether `AGENT_NOT_FOUND` is handled silently.
470
+
471
+ ## Module Do's / Don'ts
472
+ - DO keep HTTP endpoint/method and WebSocket success/failure binds in the same routing factory definition.
473
+ - DO keep browser-calling registration/deregistration in ContactCenter around successful station operations.
474
+ - DON'T resolve an agent operation from HTTP acknowledgement.
475
+ - DON'T move automated relogin policy into the agent factory or ConnectionService.
476
+
477
+ ## Key Design Trade-off
478
+ - HTTP initiates each operation while the correlated WebSocket notification is the completion signal, matching backend semantics at the cost of timeout/correlation complexity.
479
+
480
+ ## Test-Case Strategy (module)
481
+ Use `test/unit/spec/services/agent/index.ts` for factory endpoint/bind/payload contracts and `test/unit/spec/cc.ts` for public validation, metrics, calling, updateAgentProfile, and recovery ownership. Cover success, nested failure, HTTP rejection, and timeout without inventing a `deviceUpdate` factory method.
482
+
483
+ | Behavior / Requirement | Existing test evidence | Gap |
484
+ |---|---|---|
485
+ | `AGENT-R-001` | `test/unit/spec/services/agent/index.ts`, `test/unit/spec/cc.ts` | None. |
486
+ | `AGENT-R-002` | `test/unit/spec/services/agent/index.ts`, `test/unit/spec/cc.ts` | None. |
487
+ | `AGENT-R-003` | `test/unit/spec/services/agent/index.ts` | None. |
488
+ | `AGENT-R-004` | `test/unit/spec/cc.ts` | None. |
489
+ | `AGENT-R-005` | `test/unit/spec/cc.ts` | Keep a negative assertion that `routingAgent.deviceUpdate` is absent. |
490
+
491
+ ## Traceability
492
+ - Repo architecture: `../../../../ai-docs/ARCHITECTURE.md` · Registry: `../../../../ai-docs/SPEC_INDEX.md`
493
+ - Coverage state and contracts baseline: `../../../../.sdd/manifest.json`
494
+
495
+ - [`cc.ts`](../../../cc.ts) - Main plugin implementation
496
+
497
+ - [`types.ts`](../types.ts) - Type definitions
498
+
499
+ - [cc.ts](../../../cc.ts) - Main plugin
500
+
501
+ - [agent/index.ts](../index.ts) - Service implementation
502
+
503
+ - [agent/types.ts](../types.ts) - Type definitions
504
+
505
+ - [cc.ts test](../../../../test/unit/spec/cc.ts) - Test file