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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/.sdd/manifest.json +876 -0
  2. package/AGENTS.md +94 -0
  3. package/ai-docs/ARCHITECTURE.md +168 -0
  4. package/ai-docs/CONTRACTS.md +46 -0
  5. package/ai-docs/GETTING_STARTED.md +168 -0
  6. package/ai-docs/GLOSSARY.md +43 -0
  7. package/ai-docs/README.md +138 -0
  8. package/ai-docs/REVIEW_CHECKLIST.md +41 -0
  9. package/ai-docs/RULES.md +444 -0
  10. package/ai-docs/SECURITY.md +52 -0
  11. package/ai-docs/SERVICE_STATE.md +48 -0
  12. package/ai-docs/SPEC_INDEX.md +65 -0
  13. package/ai-docs/adr/0001-spec-source-policy.md +55 -0
  14. package/ai-docs/adr/README.md +8 -0
  15. package/ai-docs/adr/_adr-template.md +31 -0
  16. package/ai-docs/contact-center-spec.md +341 -0
  17. package/ai-docs/features/generated-spec-conformance-fidelity-remediation/spec/feature-spec.md +117 -0
  18. package/ai-docs/features/residual-warning-coverage-completion/spec/feature-spec.md +203 -0
  19. package/ai-docs/features/validator-code-fidelity-drift-fix/spec/feature-spec.md +315 -0
  20. package/ai-docs/patterns/event-driven-patterns.md +485 -0
  21. package/ai-docs/patterns/testing-patterns.md +480 -0
  22. package/ai-docs/patterns/typescript-patterns.md +365 -0
  23. package/ai-docs/templates/README.md +102 -0
  24. package/ai-docs/templates/documentation/create-agents-md.md +240 -0
  25. package/ai-docs/templates/documentation/create-architecture-md.md +295 -0
  26. package/ai-docs/templates/existing-service/bug-fix.md +254 -0
  27. package/ai-docs/templates/existing-service/feature-enhancement.md +450 -0
  28. package/ai-docs/templates/new-method/00-master.md +80 -0
  29. package/ai-docs/templates/new-method/01-requirements.md +232 -0
  30. package/ai-docs/templates/new-method/02-implementation.md +295 -0
  31. package/ai-docs/templates/new-method/03-tests.md +201 -0
  32. package/ai-docs/templates/new-method/04-validation.md +141 -0
  33. package/ai-docs/templates/new-service/00-master.md +109 -0
  34. package/ai-docs/templates/new-service/01-pre-questions.md +159 -0
  35. package/ai-docs/templates/new-service/02-code-generation.md +346 -0
  36. package/ai-docs/templates/new-service/03-integration.md +178 -0
  37. package/ai-docs/templates/new-service/04-test-generation.md +205 -0
  38. package/ai-docs/templates/new-service/05-validation.md +145 -0
  39. package/dist/cc.js +265 -29
  40. package/dist/cc.js.map +1 -1
  41. package/dist/config.js +6 -0
  42. package/dist/config.js.map +1 -1
  43. package/dist/constants.js +17 -1
  44. package/dist/constants.js.map +1 -1
  45. package/dist/index.js +20 -5
  46. package/dist/index.js.map +1 -1
  47. package/dist/metrics/behavioral-events.js +101 -0
  48. package/dist/metrics/behavioral-events.js.map +1 -1
  49. package/dist/metrics/constants.js +25 -4
  50. package/dist/metrics/constants.js.map +1 -1
  51. package/dist/services/ApiAiAssistant.js +153 -8
  52. package/dist/services/ApiAiAssistant.js.map +1 -1
  53. package/dist/services/UserPreference.js +427 -0
  54. package/dist/services/UserPreference.js.map +1 -0
  55. package/dist/services/config/Util.js +3 -3
  56. package/dist/services/config/Util.js.map +1 -1
  57. package/dist/services/config/constants.js +23 -2
  58. package/dist/services/config/constants.js.map +1 -1
  59. package/dist/services/config/types.js +49 -9
  60. package/dist/services/config/types.js.map +1 -1
  61. package/dist/services/core/Err.js.map +1 -1
  62. package/dist/services/core/Utils.js +107 -32
  63. package/dist/services/core/Utils.js.map +1 -1
  64. package/dist/services/core/websocket/WebSocketManager.js +2 -1
  65. package/dist/services/core/websocket/WebSocketManager.js.map +1 -1
  66. package/dist/services/core/websocket/types.js.map +1 -1
  67. package/dist/services/index.js +1 -1
  68. package/dist/services/index.js.map +1 -1
  69. package/dist/services/task/Task.js +688 -0
  70. package/dist/services/task/Task.js.map +1 -0
  71. package/dist/services/task/TaskFactory.js +45 -0
  72. package/dist/services/task/TaskFactory.js.map +1 -0
  73. package/dist/services/task/TaskManager.js +728 -527
  74. package/dist/services/task/TaskManager.js.map +1 -1
  75. package/dist/services/task/TaskUtils.js +162 -26
  76. package/dist/services/task/TaskUtils.js.map +1 -1
  77. package/dist/services/task/constants.js +9 -2
  78. package/dist/services/task/constants.js.map +1 -1
  79. package/dist/services/task/dialer.js +78 -0
  80. package/dist/services/task/dialer.js.map +1 -1
  81. package/dist/services/task/digital/Digital.js +77 -0
  82. package/dist/services/task/digital/Digital.js.map +1 -0
  83. package/dist/services/task/state-machine/TaskStateMachine.js +837 -0
  84. package/dist/services/task/state-machine/TaskStateMachine.js.map +1 -0
  85. package/dist/services/task/state-machine/actions.js +543 -0
  86. package/dist/services/task/state-machine/actions.js.map +1 -0
  87. package/dist/services/task/state-machine/constants.js +161 -0
  88. package/dist/services/task/state-machine/constants.js.map +1 -0
  89. package/dist/services/task/state-machine/guards.js +340 -0
  90. package/dist/services/task/state-machine/guards.js.map +1 -0
  91. package/dist/services/task/state-machine/index.js +53 -0
  92. package/dist/services/task/state-machine/index.js.map +1 -0
  93. package/dist/services/task/state-machine/types.js +54 -0
  94. package/dist/services/task/state-machine/types.js.map +1 -0
  95. package/dist/services/task/state-machine/uiControlsComputer.js +553 -0
  96. package/dist/services/task/state-machine/uiControlsComputer.js.map +1 -0
  97. package/dist/services/task/taskDataNormalizer.js +99 -0
  98. package/dist/services/task/taskDataNormalizer.js.map +1 -0
  99. package/dist/services/task/types.js +212 -4
  100. package/dist/services/task/types.js.map +1 -1
  101. package/dist/services/task/voice/Voice.js +1042 -0
  102. package/dist/services/task/voice/Voice.js.map +1 -0
  103. package/dist/services/task/voice/WebRTC.js +149 -0
  104. package/dist/services/task/voice/WebRTC.js.map +1 -0
  105. package/dist/types/cc.d.ts +94 -1
  106. package/dist/types/config.d.ts +6 -0
  107. package/dist/types/constants.d.ts +17 -1
  108. package/dist/types/index.d.ts +21 -6
  109. package/dist/types/metrics/constants.d.ts +21 -1
  110. package/dist/types/services/ApiAiAssistant.d.ts +22 -4
  111. package/dist/types/services/UserPreference.d.ts +118 -0
  112. package/dist/types/services/config/constants.d.ts +21 -0
  113. package/dist/types/services/config/types.d.ts +171 -10
  114. package/dist/types/services/core/Err.d.ts +4 -0
  115. package/dist/types/services/core/Utils.d.ts +33 -13
  116. package/dist/types/services/core/websocket/WebSocketManager.d.ts +1 -0
  117. package/dist/types/services/core/websocket/types.d.ts +1 -1
  118. package/dist/types/services/index.d.ts +1 -1
  119. package/dist/types/services/task/Task.d.ts +157 -0
  120. package/dist/types/services/task/TaskFactory.d.ts +12 -0
  121. package/dist/types/services/task/TaskUtils.d.ts +46 -2
  122. package/dist/types/services/task/constants.d.ts +7 -0
  123. package/dist/types/services/task/dialer.d.ts +30 -0
  124. package/dist/types/services/task/digital/Digital.d.ts +22 -0
  125. package/dist/types/services/task/state-machine/TaskStateMachine.d.ts +1144 -0
  126. package/dist/types/services/task/state-machine/actions.d.ts +10 -0
  127. package/dist/types/services/task/state-machine/constants.d.ts +107 -0
  128. package/dist/types/services/task/state-machine/guards.d.ts +90 -0
  129. package/dist/types/services/task/state-machine/index.d.ts +13 -0
  130. package/dist/types/services/task/state-machine/types.d.ts +267 -0
  131. package/dist/types/services/task/state-machine/uiControlsComputer.d.ts +9 -0
  132. package/dist/types/services/task/taskDataNormalizer.d.ts +10 -0
  133. package/dist/types/services/task/types.d.ts +603 -66
  134. package/dist/types/services/task/voice/Voice.d.ts +184 -0
  135. package/dist/types/services/task/voice/WebRTC.d.ts +53 -0
  136. package/dist/types/types.d.ts +135 -0
  137. package/dist/types/webex.d.ts +1 -0
  138. package/dist/types.js +118 -2
  139. package/dist/types.js.map +1 -1
  140. package/dist/webex.js +14 -2
  141. package/dist/webex.js.map +1 -1
  142. package/package.json +15 -12
  143. package/src/cc.ts +329 -30
  144. package/src/config.ts +6 -0
  145. package/src/constants.ts +17 -1
  146. package/src/index.ts +23 -5
  147. package/src/metrics/ai-docs/AGENTS.md +350 -0
  148. package/src/metrics/ai-docs/ARCHITECTURE.md +338 -0
  149. package/src/metrics/ai-docs/metrics-spec.md +854 -0
  150. package/src/metrics/behavioral-events.ts +106 -0
  151. package/src/metrics/constants.ts +27 -4
  152. package/src/services/ApiAiAssistant.ts +203 -8
  153. package/src/services/UserPreference.ts +509 -0
  154. package/src/services/agent/ai-docs/AGENTS.md +240 -0
  155. package/src/services/agent/ai-docs/ARCHITECTURE.md +304 -0
  156. package/src/services/agent/ai-docs/agent-spec.md +504 -0
  157. package/src/services/ai-docs/AGENTS.md +386 -0
  158. package/src/services/ai-docs/services-spec.md +492 -0
  159. package/src/services/config/Util.ts +3 -3
  160. package/src/services/config/ai-docs/AGENTS.md +255 -0
  161. package/src/services/config/ai-docs/ARCHITECTURE.md +426 -0
  162. package/src/services/config/ai-docs/config-spec.md +669 -0
  163. package/src/services/config/constants.ts +25 -1
  164. package/src/services/config/types.ts +174 -11
  165. package/src/services/core/Err.ts +2 -0
  166. package/src/services/core/Utils.ts +123 -37
  167. package/src/services/core/ai-docs/AGENTS.md +381 -0
  168. package/src/services/core/ai-docs/ARCHITECTURE.md +698 -0
  169. package/src/services/core/ai-docs/core-spec.md +783 -0
  170. package/src/services/core/websocket/WebSocketManager.ts +2 -0
  171. package/src/services/core/websocket/types.ts +1 -1
  172. package/src/services/index.ts +1 -1
  173. package/src/services/task/Task.ts +837 -0
  174. package/src/services/task/TaskFactory.ts +55 -0
  175. package/src/services/task/TaskManager.ts +739 -614
  176. package/src/services/task/TaskUtils.ts +205 -25
  177. package/src/services/task/ai-docs/AGENTS.md +457 -0
  178. package/src/services/task/ai-docs/ARCHITECTURE.md +594 -0
  179. package/src/services/task/ai-docs/task-spec.md +1319 -0
  180. package/src/services/task/constants.ts +7 -0
  181. package/src/services/task/dialer.ts +80 -0
  182. package/src/services/task/digital/Digital.ts +95 -0
  183. package/src/services/task/state-machine/TaskStateMachine.ts +1077 -0
  184. package/src/services/task/state-machine/actions.ts +685 -0
  185. package/src/services/task/state-machine/ai-docs/AGENTS.md +458 -0
  186. package/src/services/task/state-machine/ai-docs/ARCHITECTURE.md +1137 -0
  187. package/src/services/task/state-machine/ai-docs/task-state-machine-spec.md +2115 -0
  188. package/src/services/task/state-machine/constants.ts +172 -0
  189. package/src/services/task/state-machine/guards.ts +406 -0
  190. package/src/services/task/state-machine/index.ts +28 -0
  191. package/src/services/task/state-machine/types.ts +241 -0
  192. package/src/services/task/state-machine/uiControlsComputer.ts +867 -0
  193. package/src/services/task/taskDataNormalizer.ts +137 -0
  194. package/src/services/task/types.ts +710 -71
  195. package/src/services/task/voice/Voice.ts +1267 -0
  196. package/src/services/task/voice/WebRTC.ts +187 -0
  197. package/src/types.ts +166 -2
  198. package/src/utils/AGENTS.md +278 -0
  199. package/src/utils/ai-docs/utils-spec.md +381 -0
  200. package/src/webex.js +2 -0
  201. package/test/unit/spec/cc.ts +343 -23
  202. package/test/unit/spec/logger-proxy.ts +70 -0
  203. package/test/unit/spec/services/ApiAiAssistant.ts +178 -20
  204. package/test/unit/spec/services/UserPreference.ts +401 -0
  205. package/test/unit/spec/services/WebCallingService.ts +7 -1
  206. package/test/unit/spec/services/config/index.ts +30 -30
  207. package/test/unit/spec/services/core/Utils.ts +425 -8
  208. package/test/unit/spec/services/core/websocket/WebSocketManager.ts +66 -40
  209. package/test/unit/spec/services/task/AutoWrapup.ts +63 -0
  210. package/test/unit/spec/services/task/Task.ts +477 -0
  211. package/test/unit/spec/services/task/TaskFactory.ts +62 -0
  212. package/test/unit/spec/services/task/TaskManager.ts +834 -1704
  213. package/test/unit/spec/services/task/TaskUtils.ts +206 -0
  214. package/test/unit/spec/services/task/dialer.ts +190 -0
  215. package/test/unit/spec/services/task/digital/Digital.ts +105 -0
  216. package/test/unit/spec/services/task/state-machine/TaskStateMachine.ts +1825 -0
  217. package/test/unit/spec/services/task/state-machine/guards.ts +479 -0
  218. package/test/unit/spec/services/task/state-machine/types.ts +18 -0
  219. package/test/unit/spec/services/task/state-machine/uiControlsComputer.ts +2020 -0
  220. package/test/unit/spec/services/task/taskTestUtils.ts +87 -0
  221. package/test/unit/spec/services/task/voice/Voice.ts +631 -0
  222. package/test/unit/spec/services/task/voice/WebRTC.ts +235 -0
  223. package/umd/contact-center.min.js +2 -2
  224. package/umd/contact-center.min.js.map +1 -1
  225. package/dist/services/task/index.js +0 -1525
  226. package/dist/services/task/index.js.map +0 -1
  227. package/dist/types/services/task/index.d.ts +0 -650
  228. package/src/services/task/index.ts +0 -1801
  229. package/test/unit/spec/services/task/index.ts +0 -2184
@@ -0,0 +1,240 @@
1
+ # Agent Service - AI Agent Guide
2
+
3
+ > **Legacy/reference-only.** Canonical SDD: [`agent-spec.md`](agent-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
+ > **Purpose**: Manage agent lifecycle including login, logout, state changes, and buddy agent queries.
6
+
7
+ ---
8
+
9
+ ## Quick Start
10
+
11
+ ```typescript
12
+ const cc = webex.cc;
13
+
14
+ // Register and login
15
+ const profile = await cc.register();
16
+ await cc.stationLogin({
17
+ teamId: profile.teams[0].teamId,
18
+ loginOption: 'BROWSER',
19
+ });
20
+
21
+ // Set state to Available
22
+ await cc.setAgentState({
23
+ state: 'Available',
24
+ auxCodeId: '0',
25
+ });
26
+
27
+ // Get available agents for transfer
28
+ const buddies = await cc.getBuddyAgents({
29
+ state: 'Available',
30
+ mediaType: 'telephony',
31
+ });
32
+ ```
33
+
34
+ ---
35
+
36
+ ## Key Capabilities
37
+
38
+ - **Station Login**: Login with browser (WebRTC), extension, or dial number
39
+ - **Station Logout**: Logout from current station with reason
40
+ - **State Management**: Toggle between Available/Idle states with aux codes
41
+ - **Buddy Agents**: Query available agents for consult/transfer
42
+ - **Silent Relogin**: Automatic re-authentication on reconnection
43
+
44
+ ---
45
+
46
+ ## API Reference
47
+
48
+ ### Login Options
49
+
50
+ | Option | Description | Requires dialNumber |
51
+ |--------|-------------|---------------------|
52
+ | `BROWSER` | WebRTC softphone in browser | No |
53
+ | `EXTENSION` | Desk phone extension | Yes |
54
+ | `AGENT_DN` | Direct dial number | Yes |
55
+
56
+ ### Methods
57
+
58
+ #### `cc.stationLogin(params)`
59
+
60
+ Login agent to a station.
61
+
62
+ **Parameters**:
63
+ - `teamId` (string): Team to login to
64
+ - `loginOption` ('BROWSER' | 'EXTENSION' | 'AGENT_DN'): Device type
65
+ - `dialNumber` (string, optional): Required for EXTENSION/AGENT_DN
66
+
67
+ **Returns**: `Promise<StationLoginResponse>`
68
+
69
+ **Example**:
70
+ ```typescript
71
+ // Browser login
72
+ const response = await cc.stationLogin({
73
+ teamId: 'team-123',
74
+ loginOption: 'BROWSER',
75
+ });
76
+
77
+ // Extension login
78
+ const response = await cc.stationLogin({
79
+ teamId: 'team-123',
80
+ loginOption: 'EXTENSION',
81
+ dialNumber: '1234',
82
+ });
83
+ ```
84
+
85
+ ---
86
+
87
+ #### `cc.stationLogout(params)`
88
+
89
+ Logout agent from station.
90
+
91
+ **Parameters**:
92
+ - `logoutReason` (string, optional): 'User requested logout' | 'Inactivity Logout' | 'User requested agent profile update'
93
+
94
+ **Returns**: `Promise<StationLogoutResponse>`
95
+
96
+ **Example**:
97
+ ```typescript
98
+ await cc.stationLogout({
99
+ logoutReason: 'User requested logout',
100
+ });
101
+ ```
102
+
103
+ ---
104
+
105
+ #### `cc.setAgentState(params)`
106
+
107
+ Change agent state (Available/Idle).
108
+
109
+ **Parameters**:
110
+ - `state` ('Available' | 'Idle'): New state
111
+ - `auxCodeId` (string): Auxiliary code ID
112
+ - `lastStateChangeReason` (string, optional): Reason for change
113
+ - `agentId` (string, optional): Agent ID (defaults to current agent)
114
+
115
+ **Returns**: `Promise<SetStateResponse>`
116
+
117
+ **Example**:
118
+ ```typescript
119
+ // Go Available
120
+ await cc.setAgentState({
121
+ state: 'Available',
122
+ auxCodeId: '0',
123
+ });
124
+
125
+ // Go to Idle with specific code
126
+ await cc.setAgentState({
127
+ state: 'Idle',
128
+ auxCodeId: 'break-code-123',
129
+ lastStateChangeReason: 'Coffee break',
130
+ });
131
+ ```
132
+
133
+ ---
134
+
135
+ #### `cc.getBuddyAgents(params)`
136
+
137
+ Get list of agents for consult/transfer.
138
+
139
+ **Parameters**:
140
+ - `state` (string, optional): Filter by state ('Available', 'Idle')
141
+ - `mediaType` (string): Media type filter ('telephony', 'chat', 'social', 'email')
142
+ **Returns**: `Promise<BuddyAgentsResponse>`
143
+
144
+ **Example**:
145
+ ```typescript
146
+ const response = await cc.getBuddyAgents({
147
+ state: 'Available',
148
+ mediaType: 'telephony',
149
+ });
150
+
151
+ response.data.agentList.forEach(agent => {
152
+ console.log(`${agent.agentName} (${agent.state})`);
153
+ });
154
+ ```
155
+
156
+ ---
157
+
158
+ ## Events
159
+
160
+ | Event | Type | Description |
161
+ |-------|------|-------------|
162
+ | `agent:stationLoginSuccess` | `StationLoginSuccessResponse` | Login succeeded |
163
+ | `agent:stationLoginFailed` | Error | Login failed |
164
+ | `agent:logoutSuccess` | `LogoutSuccess` | Logout succeeded |
165
+ | `agent:logoutFailed` | Error | Logout failed |
166
+ | `agent:stateChange` | `StateChangeSuccess` | State changed (any source) |
167
+ | `agent:stateChangeSuccess` | `StateChangeSuccess` | State change succeeded |
168
+ | `agent:stateChangeFailed` | Error | State change failed |
169
+ | `agent:multiLogin` | Object | Multi-login detected |
170
+ | `agent:reloginSuccess` | `ReloginSuccess` | Silent relogin succeeded |
171
+ | `agent:dnRegistered` | Object | DN registration complete |
172
+
173
+ ### Event Usage
174
+
175
+ ```typescript
176
+ cc.on('agent:stateChange', (event) => {
177
+ console.log(`State: ${event.subStatus}, AuxCode: ${event.auxCodeId}`);
178
+ });
179
+
180
+ cc.on('agent:multiLogin', (event) => {
181
+ console.warn('Another session detected');
182
+ });
183
+ ```
184
+
185
+ ---
186
+
187
+ ## Agent States
188
+
189
+ The `AgentState` type (`'Available' | 'Idle' | 'RONA' | string`) is extensible -- the `string` union member allows backend-defined states beyond the known values listed below.
190
+
191
+ | State | SubStatus | Description |
192
+ |-------|-----------|-------------|
193
+ | LoggedIn | Available | Ready to receive tasks |
194
+ | LoggedIn | Idle | On break or not ready (uses aux code for sub-reason) |
195
+ | RONA | - | Rang but no answer; agent failed to accept offered task |
196
+ | LoggedOut | - | Not logged in |
197
+ | LoggedIn | *(custom)* | Additional org-specific states defined via aux codes |
198
+
199
+ > **Note**: `AgentState` is a union with `string`, so consumers should handle unknown state values gracefully rather than exhaustively matching only the known literals.
200
+
201
+ ---
202
+
203
+ ## Error Handling
204
+
205
+ ```typescript
206
+ try {
207
+ await cc.stationLogin(params);
208
+ } catch (error) {
209
+ console.error('Login failed:', error.message);
210
+ // Access error details
211
+ if (error.data) {
212
+ console.error('Field:', error.data.fieldName);
213
+ console.error('Message:', error.data.message);
214
+ }
215
+ }
216
+ ```
217
+
218
+ ### Common Error Reasons
219
+
220
+ | Reason | Description |
221
+ |--------|-------------|
222
+ | `DUPLICATE_LOCATION` | Extension/DN already in use |
223
+ | `INVALID_DIAL_NUMBER` | Invalid phone number format |
224
+ | `AGENT_NOT_FOUND` | Agent doesn't exist (silent relogin) |
225
+
226
+ ---
227
+
228
+ ## Dependencies
229
+
230
+ - Requires `cc.register()` to be called first
231
+ - Agent profile must be fetched before login
232
+ - WebRTC (BROWSER option) requires mercury connection
233
+
234
+ ---
235
+
236
+ ## Related
237
+
238
+ - [ARCHITECTURE.md](ARCHITECTURE.md) - Technical deep-dive
239
+ - [`cc.ts`](../../../cc.ts) - Main plugin implementation
240
+ - [`types.ts`](../types.ts) - Type definitions
@@ -0,0 +1,304 @@
1
+ # Agent Service - Architecture
2
+
3
+ > **Legacy/reference-only.** Canonical SDD: [`agent-spec.md`](agent-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
+ > **Purpose**: Technical documentation for agent lifecycle operations.
6
+
7
+ ---
8
+
9
+ ## Component Overview
10
+
11
+ | Component | File | Responsibility |
12
+ | --------------- | --------------------------- | --------------------------------------------------------------- |
13
+ | `ContactCenter` | `src/cc.ts` | Plugin class exposing agent methods |
14
+ | `routingAgent` | `services/agent/index.ts` | AQM request definitions |
15
+ | `Services` | `services/index.ts` | Service singleton with agent service |
16
+ | `AqmReqs` | `services/core/aqm-reqs.ts` | HTTP requests to backend; responses via WebSocket notifications |
17
+
18
+ ---
19
+
20
+ ## File Structure
21
+
22
+ ```
23
+ services/agent/
24
+ ├── index.ts # Agent service factory
25
+ ├── types.ts # Agent types and events
26
+ └── ai-docs/
27
+ ├── AGENTS.md # Usage documentation
28
+ └── ARCHITECTURE.md # This file
29
+ ```
30
+
31
+ ---
32
+
33
+ ## Service Factory Pattern
34
+
35
+ The agent service uses a factory pattern:
36
+
37
+ ```typescript
38
+ // services/agent/index.ts
39
+ export default function routingAgent(routing: AqmReqs) {
40
+ return {
41
+ stationLogin: routing.req((p: {data: UserStationLogin}) => ({
42
+ url: '/v1/agents/login',
43
+ host: WCC_API_GATEWAY,
44
+ data: p.data,
45
+ notifSuccess: {
46
+ bind: {type: CC_EVENTS.AGENT_STATION_LOGIN, ...},
47
+ msg: {} as StationLoginSuccess,
48
+ },
49
+ notifFail: {...},
50
+ })),
51
+ logout: routing.req((p: {data: Logout}) => ({...})),
52
+ stateChange: routing.req((p: {data: StateChange}) => ({...})),
53
+ buddyAgents: routing.req((p: {data: BuddyAgents}) => ({...})),
54
+ reload: routing.reqEmpty(() => ({...})),
55
+ };
56
+ }
57
+ ```
58
+
59
+ ---
60
+
61
+ ## Data Flow
62
+
63
+ ### Station Login Flow
64
+
65
+ ```mermaid
66
+ flowchart TD
67
+ A[cc.stationLogin] --> B[Validate input]
68
+ B --> C[services.agent.stationLogin]
69
+ C --> D[AqmReqs.req]
70
+ D --> E[HTTP REST request to backend]
71
+ E --> F[Backend processes]
72
+ F --> G{Success?}
73
+ G -->|Yes| H[StationLoginSuccess event]
74
+ G -->|No| I[StationLoginFailed event]
75
+ H --> J[Register WebCalling if BROWSER]
76
+ J --> K[Track metrics]
77
+ K --> L[Return response]
78
+ I --> M[getErrorDetails]
79
+ M --> N[Throw error]
80
+ ```
81
+
82
+ ---
83
+
84
+ ## Sequence Diagrams
85
+
86
+ ### Station Login
87
+
88
+ ```mermaid
89
+ sequenceDiagram
90
+ participant App
91
+ participant CC as ContactCenter
92
+ participant Svc as Services.agent
93
+ participant AQM as AqmReqs
94
+ participant WS as WebSocket
95
+ participant BE as Backend
96
+ App->>CC: stationLogin(params)
97
+ CC->>CC: Validate dial number
98
+ CC->>CC: timeEvent(LOGIN_SUCCESS, LOGIN_FAILED)
99
+ CC->>Svc: stationLogin({data})
100
+ Svc->>AQM: req(config)
101
+ AQM->>BE: HTTP POST /v1/agents/login
102
+ BE-->>WS: AgentStationLoginSuccess
103
+ WS-->>AQM: Resolve with response
104
+ AQM-->>Svc: Return response
105
+ Svc-->>CC: Login response
106
+ CC->>CC: Register WebCalling (if BROWSER)
107
+ CC->>CC: trackEvent(LOGIN_SUCCESS)
108
+ CC-->>App: StationLoginResponse
109
+ ```
110
+
111
+ ### State Change
112
+
113
+ ```mermaid
114
+ sequenceDiagram
115
+ participant App
116
+ participant CC as ContactCenter
117
+ participant Svc as Services.agent
118
+ participant WS as WebSocket
119
+ participant BE as Backend
120
+
121
+ App->>CC: setAgentState(params)
122
+ CC->>CC: timeEvent(STATE_SUCCESS, STATE_FAILED)
123
+ CC->>Svc: stateChange({data})
124
+ Svc->>BE: HTTP PUT /v1/agents/session/state
125
+ BE-->>WS: AgentStateChangeSuccess
126
+ WS-->>CC: Emit via handleWebsocketMessage
127
+ CC->>CC: emit(agent:stateChange)
128
+ CC->>CC: trackEvent(STATE_SUCCESS)
129
+ CC-->>App: SetStateResponse
130
+ ```
131
+
132
+ ---
133
+
134
+ ## Request Configuration
135
+
136
+ Each agent method defines:
137
+
138
+ ```typescript
139
+ {
140
+ url: '/v1/agents/...', // API endpoint
141
+ host: WCC_API_GATEWAY, // Base URL
142
+ data: p.data, // Request payload
143
+ method: HTTP_METHODS.POST, // HTTP method (POST if data present, GET otherwise)
144
+ err: errorHandler, // Error transformer
145
+ notifSuccess: {
146
+ bind: {
147
+ type: CC_EVENTS.SUCCESS_TYPE,
148
+ data: {type: CC_EVENTS.SUCCESS_TYPE},
149
+ },
150
+ msg: {} as SuccessType, // Response type hint
151
+ },
152
+ notifFail: {
153
+ bind: {
154
+ type: CC_EVENTS.FAIL_TYPE,
155
+ data: {type: CC_EVENTS.FAIL_TYPE},
156
+ },
157
+ errId: 'Service.aqm.agent.method',
158
+ },
159
+ }
160
+ ```
161
+
162
+ ---
163
+
164
+ ## Event Flow
165
+
166
+ ### WebSocket to Application
167
+
168
+ ```mermaid
169
+ flowchart LR
170
+ A[WebSocket Message] --> B[WebSocketManager]
171
+ B --> C[cc.handleWebsocketMessage]
172
+ C --> D{Event Type?}
173
+ D -->|AGENT_STATE_CHANGE| E[emit agent:stateChange]
174
+ D -->|data.type check| F{Nested Type?}
175
+ F -->|STATION_LOGIN_SUCCESS| G[Transform channelsMap]
176
+ G --> H[emit agent:stationLoginSuccess]
177
+ F -->|LOGOUT_SUCCESS| I[emit agent:logoutSuccess]
178
+ ```
179
+
180
+ ### ChannelsMap Transformation
181
+
182
+ The login success event transforms `channelsMap` to `mmProfile`:
183
+
184
+ ```typescript
185
+ // Incoming
186
+ channelsMap: {
187
+ chat: ['channel-1', 'channel-2'],
188
+ email: ['channel-3'],
189
+ telephony: ['channel-4'],
190
+ }
191
+
192
+ // Transformed
193
+ mmProfile: {
194
+ chat: 2, // Length of arrays
195
+ email: 1,
196
+ social: 0,
197
+ telephony: 1,
198
+ }
199
+ ```
200
+
201
+ ---
202
+
203
+ ## Silent Relogin
204
+
205
+ Automatic relogin on WebSocket reconnection:
206
+
207
+ ```mermaid
208
+ flowchart TD
209
+ A[WebSocket Reconnected] --> B[handleConnectionLost]
210
+ B --> C{allowAutomatedRelogin?}
211
+ C -->|Yes| D[silentRelogin]
212
+ D --> E[services.agent.reload]
213
+ E --> F{Success?}
214
+ F -->|Yes| G[Update agentConfig]
215
+ G --> H{lastStateChangeReason?}
216
+ H -->|agent-wss-disconnect| I[setAgentState Available]
217
+ H -->|Other| J[Keep current state]
218
+ F -->|No, AGENT_NOT_FOUND| K[Handle silently]
219
+ F -->|No, Other| L[Throw error]
220
+ ```
221
+
222
+ ---
223
+
224
+ ## Error Handling
225
+
226
+ ### Login Error Details
227
+
228
+ For `stationLogin`, special error handling extracts field-specific messages:
229
+
230
+ ```typescript
231
+ // Utils.ts - getStationLoginErrorData
232
+ const errorCodeMessageMap = {
233
+ DUPLICATE_LOCATION: {
234
+ message: 'This extension is already in use',
235
+ fieldName: loginOption,
236
+ },
237
+ INVALID_DIAL_NUMBER: {
238
+ message: 'Enter a valid US dial number...',
239
+ fieldName: loginOption,
240
+ },
241
+ };
242
+ ```
243
+
244
+ ---
245
+
246
+ ## Metrics Tracking
247
+
248
+ | Metric | Type | When Tracked |
249
+ | ---------------------------- | --------------------------------- | ------------------------ |
250
+ | `STATION_LOGIN_SUCCESS` | behavioral, business, operational | Login succeeds |
251
+ | `STATION_LOGIN_FAILED` | behavioral, business, operational | Login fails |
252
+ | `STATION_LOGOUT_SUCCESS` | behavioral, business, operational | Logout succeeds |
253
+ | `STATION_LOGOUT_FAILED` | behavioral, business, operational | Logout fails |
254
+ | `AGENT_STATE_CHANGE_SUCCESS` | behavioral, business, operational | State change succeeds |
255
+ | `AGENT_STATE_CHANGE_FAILED` | behavioral, business, operational | State change fails |
256
+ | `FETCH_BUDDY_AGENTS_SUCCESS` | operational | Buddy agents fetched |
257
+ | `FETCH_BUDDY_AGENTS_FAILED` | operational | Buddy agents fetch fails |
258
+
259
+ ---
260
+
261
+ ## Troubleshooting
262
+
263
+ ### Issue: Login fails with DUPLICATE_LOCATION
264
+
265
+ **Cause**: Extension/DN already in use by another session
266
+
267
+ **Solution**:
268
+
269
+ 1. Logout from other session
270
+ 2. Use different extension
271
+ 3. Contact admin if stuck
272
+
273
+ ### Issue: State change fails
274
+
275
+ **Cause**: Agent may be in a call or transitioning state
276
+
277
+ **Solution**:
278
+ 1. Complete current interaction
279
+ 2. Wait for state to stabilize
280
+ 3. Retry state change
281
+
282
+ ### Issue: Silent relogin not working
283
+
284
+ **Cause**: `allowAutomatedRelogin` config not set
285
+
286
+ **Solution**:
287
+ ```typescript
288
+ const webex = Webex.init({
289
+ config: {
290
+ cc: {
291
+ allowAutomatedRelogin: true,
292
+ },
293
+ },
294
+ });
295
+ ```
296
+
297
+ ---
298
+
299
+ ## Related Files
300
+
301
+ - [cc.ts](../../../cc.ts) - Main plugin
302
+ - [agent/index.ts](../index.ts) - Service implementation
303
+ - [agent/types.ts](../types.ts) - Type definitions
304
+ - [cc.ts test](../../../../test/unit/spec/cc.ts) - Test file