@webex/contact-center 3.12.0-next.9 → 3.12.0-task-refactor.1

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 (200) hide show
  1. package/AGENTS.md +438 -0
  2. package/ai-docs/README.md +131 -0
  3. package/ai-docs/RULES.md +455 -0
  4. package/ai-docs/patterns/event-driven-patterns.md +485 -0
  5. package/ai-docs/patterns/testing-patterns.md +480 -0
  6. package/ai-docs/patterns/typescript-patterns.md +365 -0
  7. package/ai-docs/templates/README.md +102 -0
  8. package/ai-docs/templates/documentation/create-agents-md.md +240 -0
  9. package/ai-docs/templates/documentation/create-architecture-md.md +295 -0
  10. package/ai-docs/templates/existing-service/bug-fix.md +254 -0
  11. package/ai-docs/templates/existing-service/feature-enhancement.md +450 -0
  12. package/ai-docs/templates/new-method/00-master.md +80 -0
  13. package/ai-docs/templates/new-method/01-requirements.md +232 -0
  14. package/ai-docs/templates/new-method/02-implementation.md +295 -0
  15. package/ai-docs/templates/new-method/03-tests.md +201 -0
  16. package/ai-docs/templates/new-method/04-validation.md +141 -0
  17. package/ai-docs/templates/new-service/00-master.md +109 -0
  18. package/ai-docs/templates/new-service/01-pre-questions.md +159 -0
  19. package/ai-docs/templates/new-service/02-code-generation.md +346 -0
  20. package/ai-docs/templates/new-service/03-integration.md +178 -0
  21. package/ai-docs/templates/new-service/04-test-generation.md +205 -0
  22. package/ai-docs/templates/new-service/05-validation.md +145 -0
  23. package/dist/cc.js +65 -123
  24. package/dist/cc.js.map +1 -1
  25. package/dist/constants.js +13 -2
  26. package/dist/constants.js.map +1 -1
  27. package/dist/index.js +13 -5
  28. package/dist/index.js.map +1 -1
  29. package/dist/metrics/behavioral-events.js +26 -13
  30. package/dist/metrics/behavioral-events.js.map +1 -1
  31. package/dist/metrics/constants.js +7 -6
  32. package/dist/metrics/constants.js.map +1 -1
  33. package/dist/services/ApiAiAssistant.js +0 -3
  34. package/dist/services/ApiAiAssistant.js.map +1 -1
  35. package/dist/services/config/Util.js +2 -3
  36. package/dist/services/config/Util.js.map +1 -1
  37. package/dist/services/config/types.js +16 -14
  38. package/dist/services/config/types.js.map +1 -1
  39. package/dist/services/constants.js +0 -1
  40. package/dist/services/constants.js.map +1 -1
  41. package/dist/services/core/Err.js.map +1 -1
  42. package/dist/services/core/Utils.js +79 -55
  43. package/dist/services/core/Utils.js.map +1 -1
  44. package/dist/services/core/aqm-reqs.js +17 -92
  45. package/dist/services/core/aqm-reqs.js.map +1 -1
  46. package/dist/services/core/websocket/WebSocketManager.js +5 -25
  47. package/dist/services/core/websocket/WebSocketManager.js.map +1 -1
  48. package/dist/services/core/websocket/types.js.map +1 -1
  49. package/dist/services/index.js +1 -2
  50. package/dist/services/index.js.map +1 -1
  51. package/dist/services/task/Task.js +644 -0
  52. package/dist/services/task/Task.js.map +1 -0
  53. package/dist/services/task/TaskFactory.js +45 -0
  54. package/dist/services/task/TaskFactory.js.map +1 -0
  55. package/dist/services/task/TaskManager.js +556 -532
  56. package/dist/services/task/TaskManager.js.map +1 -1
  57. package/dist/services/task/TaskUtils.js +132 -28
  58. package/dist/services/task/TaskUtils.js.map +1 -1
  59. package/dist/services/task/constants.js +7 -6
  60. package/dist/services/task/constants.js.map +1 -1
  61. package/dist/services/task/dialer.js +0 -51
  62. package/dist/services/task/dialer.js.map +1 -1
  63. package/dist/services/task/digital/Digital.js +77 -0
  64. package/dist/services/task/digital/Digital.js.map +1 -0
  65. package/dist/services/task/state-machine/TaskStateMachine.js +634 -0
  66. package/dist/services/task/state-machine/TaskStateMachine.js.map +1 -0
  67. package/dist/services/task/state-machine/actions.js +366 -0
  68. package/dist/services/task/state-machine/actions.js.map +1 -0
  69. package/dist/services/task/state-machine/constants.js +139 -0
  70. package/dist/services/task/state-machine/constants.js.map +1 -0
  71. package/dist/services/task/state-machine/guards.js +256 -0
  72. package/dist/services/task/state-machine/guards.js.map +1 -0
  73. package/dist/services/task/state-machine/index.js +53 -0
  74. package/dist/services/task/state-machine/index.js.map +1 -0
  75. package/dist/services/task/state-machine/types.js +54 -0
  76. package/dist/services/task/state-machine/types.js.map +1 -0
  77. package/dist/services/task/state-machine/uiControlsComputer.js +369 -0
  78. package/dist/services/task/state-machine/uiControlsComputer.js.map +1 -0
  79. package/dist/services/task/taskDataNormalizer.js +99 -0
  80. package/dist/services/task/taskDataNormalizer.js.map +1 -0
  81. package/dist/services/task/types.js +157 -18
  82. package/dist/services/task/types.js.map +1 -1
  83. package/dist/services/task/voice/Voice.js +1031 -0
  84. package/dist/services/task/voice/Voice.js.map +1 -0
  85. package/dist/services/task/voice/WebRTC.js +149 -0
  86. package/dist/services/task/voice/WebRTC.js.map +1 -0
  87. package/dist/types/cc.d.ts +4 -33
  88. package/dist/types/constants.d.ts +13 -2
  89. package/dist/types/index.d.ts +11 -5
  90. package/dist/types/metrics/constants.d.ts +5 -3
  91. package/dist/types/services/ApiAiAssistant.d.ts +1 -1
  92. package/dist/types/services/config/types.d.ts +97 -25
  93. package/dist/types/services/core/Err.d.ts +0 -2
  94. package/dist/types/services/core/Utils.d.ts +25 -23
  95. package/dist/types/services/core/aqm-reqs.d.ts +0 -49
  96. package/dist/types/services/core/websocket/WebSocketManager.d.ts +1 -1
  97. package/dist/types/services/core/websocket/connection-service.d.ts +0 -1
  98. package/dist/types/services/core/websocket/types.d.ts +1 -1
  99. package/dist/types/services/index.d.ts +1 -1
  100. package/dist/types/services/task/Task.d.ts +146 -0
  101. package/dist/types/services/task/TaskFactory.d.ts +12 -0
  102. package/dist/types/services/task/TaskUtils.d.ts +39 -8
  103. package/dist/types/services/task/constants.d.ts +5 -4
  104. package/dist/types/services/task/dialer.d.ts +0 -15
  105. package/dist/types/services/task/digital/Digital.d.ts +22 -0
  106. package/dist/types/services/task/state-machine/TaskStateMachine.d.ts +906 -0
  107. package/dist/types/services/task/state-machine/actions.d.ts +8 -0
  108. package/dist/types/services/task/state-machine/constants.d.ts +91 -0
  109. package/dist/types/services/task/state-machine/guards.d.ts +78 -0
  110. package/dist/types/services/task/state-machine/index.d.ts +13 -0
  111. package/dist/types/services/task/state-machine/types.d.ts +256 -0
  112. package/dist/types/services/task/state-machine/uiControlsComputer.d.ts +9 -0
  113. package/dist/types/services/task/taskDataNormalizer.d.ts +10 -0
  114. package/dist/types/services/task/types.d.ts +539 -88
  115. package/dist/types/services/task/voice/Voice.d.ts +183 -0
  116. package/dist/types/services/task/voice/WebRTC.d.ts +53 -0
  117. package/dist/types/types.d.ts +68 -0
  118. package/dist/types/webex.d.ts +1 -0
  119. package/dist/types.js +70 -0
  120. package/dist/types.js.map +1 -1
  121. package/dist/webex.js +14 -2
  122. package/dist/webex.js.map +1 -1
  123. package/package.json +14 -11
  124. package/src/cc.ts +91 -177
  125. package/src/constants.ts +13 -2
  126. package/src/index.ts +14 -5
  127. package/src/metrics/ai-docs/AGENTS.md +348 -0
  128. package/src/metrics/ai-docs/ARCHITECTURE.md +336 -0
  129. package/src/metrics/behavioral-events.ts +28 -14
  130. package/src/metrics/constants.ts +7 -8
  131. package/src/services/ApiAiAssistant.ts +2 -4
  132. package/src/services/agent/ai-docs/AGENTS.md +238 -0
  133. package/src/services/agent/ai-docs/ARCHITECTURE.md +302 -0
  134. package/src/services/ai-docs/AGENTS.md +384 -0
  135. package/src/services/config/Util.ts +2 -3
  136. package/src/services/config/ai-docs/AGENTS.md +253 -0
  137. package/src/services/config/ai-docs/ARCHITECTURE.md +424 -0
  138. package/src/services/config/types.ts +108 -20
  139. package/src/services/constants.ts +0 -1
  140. package/src/services/core/Err.ts +0 -1
  141. package/src/services/core/Utils.ts +90 -67
  142. package/src/services/core/ai-docs/AGENTS.md +379 -0
  143. package/src/services/core/ai-docs/ARCHITECTURE.md +696 -0
  144. package/src/services/core/aqm-reqs.ts +22 -100
  145. package/src/services/core/websocket/WebSocketManager.ts +4 -23
  146. package/src/services/core/websocket/types.ts +1 -1
  147. package/src/services/index.ts +1 -2
  148. package/src/services/task/Task.ts +785 -0
  149. package/src/services/task/TaskFactory.ts +55 -0
  150. package/src/services/task/TaskManager.ts +567 -633
  151. package/src/services/task/TaskUtils.ts +175 -31
  152. package/src/services/task/ai-docs/AGENTS.md +448 -0
  153. package/src/services/task/ai-docs/ARCHITECTURE.md +573 -0
  154. package/src/services/task/constants.ts +5 -4
  155. package/src/services/task/dialer.ts +1 -56
  156. package/src/services/task/digital/Digital.ts +95 -0
  157. package/src/services/task/state-machine/TaskStateMachine.ts +793 -0
  158. package/src/services/task/state-machine/actions.ts +409 -0
  159. package/src/services/task/state-machine/ai-docs/AGENTS.md +495 -0
  160. package/src/services/task/state-machine/ai-docs/ARCHITECTURE.md +1135 -0
  161. package/src/services/task/state-machine/constants.ts +150 -0
  162. package/src/services/task/state-machine/guards.ts +295 -0
  163. package/src/services/task/state-machine/index.ts +28 -0
  164. package/src/services/task/state-machine/types.ts +228 -0
  165. package/src/services/task/state-machine/uiControlsComputer.ts +529 -0
  166. package/src/services/task/taskDataNormalizer.ts +137 -0
  167. package/src/services/task/types.ts +641 -95
  168. package/src/services/task/voice/Voice.ts +1255 -0
  169. package/src/services/task/voice/WebRTC.ts +187 -0
  170. package/src/types.ts +88 -5
  171. package/src/utils/AGENTS.md +276 -0
  172. package/src/webex.js +2 -0
  173. package/test/unit/spec/cc.ts +59 -142
  174. package/test/unit/spec/logger-proxy.ts +70 -0
  175. package/test/unit/spec/services/ApiAiAssistant.ts +17 -0
  176. package/test/unit/spec/services/config/index.ts +26 -55
  177. package/test/unit/spec/services/core/Utils.ts +103 -52
  178. package/test/unit/spec/services/core/websocket/WebSocketManager.ts +48 -112
  179. package/test/unit/spec/services/core/websocket/connection-service.ts +5 -4
  180. package/test/unit/spec/services/task/AutoWrapup.ts +63 -0
  181. package/test/unit/spec/services/task/Task.ts +416 -0
  182. package/test/unit/spec/services/task/TaskFactory.ts +62 -0
  183. package/test/unit/spec/services/task/TaskManager.ts +781 -1735
  184. package/test/unit/spec/services/task/TaskUtils.ts +125 -0
  185. package/test/unit/spec/services/task/dialer.ts +112 -198
  186. package/test/unit/spec/services/task/digital/Digital.ts +105 -0
  187. package/test/unit/spec/services/task/state-machine/TaskStateMachine.ts +473 -0
  188. package/test/unit/spec/services/task/state-machine/guards.ts +288 -0
  189. package/test/unit/spec/services/task/state-machine/types.ts +18 -0
  190. package/test/unit/spec/services/task/state-machine/uiControlsComputer.ts +147 -0
  191. package/test/unit/spec/services/task/taskTestUtils.ts +87 -0
  192. package/test/unit/spec/services/task/voice/Voice.ts +587 -0
  193. package/test/unit/spec/services/task/voice/WebRTC.ts +242 -0
  194. package/umd/contact-center.min.js +2 -2
  195. package/umd/contact-center.min.js.map +1 -1
  196. package/dist/services/task/index.js +0 -1525
  197. package/dist/services/task/index.js.map +0 -1
  198. package/dist/types/services/task/index.d.ts +0 -650
  199. package/src/services/task/index.ts +0 -1801
  200. package/test/unit/spec/services/task/index.ts +0 -2184
@@ -0,0 +1,295 @@
1
+ # Create ARCHITECTURE.md Template
2
+
3
+ > **Purpose**: Template for generating service-level ARCHITECTURE.md files with technical deep-dives.
4
+
5
+ ---
6
+
7
+ ## Pre-Generation Questions
8
+
9
+ Answer before writing:
10
+
11
+ 1. **Component Overview**: What are the main components/classes?
12
+ 2. **File Structure**: How are files organized?
13
+ 3. **Data Flow**: How does data move through the system?
14
+ 4. **Integration Points**: How does this integrate with other services?
15
+ 5. **Key Sequences**: What are the important operation sequences?
16
+ 6. **Troubleshooting**: What are common issues and solutions?
17
+
18
+ ---
19
+
20
+ ## ARCHITECTURE.md Structure
21
+
22
+ ```markdown
23
+ # [Service Name] - Architecture
24
+
25
+ > **Purpose**: Technical documentation for the [service name] component.
26
+
27
+ ---
28
+
29
+ ## Component Overview
30
+
31
+ | Component | File | Responsibility |
32
+ |-----------|------|----------------|
33
+ | `ClassName` | `path/to/file.ts` | What it does |
34
+ | `ClassName2` | `path/to/file2.ts` | What it does |
35
+
36
+ ---
37
+
38
+ ## File Structure
39
+
40
+ > **Note:** The file structure listing typically belongs in the service's `AGENTS.md` (usage documentation), not in `ARCHITECTURE.md`. Include it here only if you need to reference specific files in the architecture discussion. Otherwise, link to the AGENTS.md file structure section.
41
+
42
+ ```
43
+ services/[name]/
44
+ ├── index.ts # Main service export
45
+ ├── types.ts # Type definitions
46
+ ├── constants.ts # Constants
47
+ └── ai-docs/
48
+ ├── AGENTS.md # Usage documentation (file structure lives here)
49
+ └── ARCHITECTURE.md # This file
50
+ ```
51
+
52
+ ---
53
+
54
+ ## Data Flow
55
+
56
+ ```mermaid
57
+ flowchart TD
58
+ A[User Action] --> B[cc.methodName]
59
+ B --> C[services.service.method]
60
+ C --> D[WebSocket/HTTP Request]
61
+ D --> E[Backend Response]
62
+ E --> F[Event Emission]
63
+ ```
64
+
65
+ ---
66
+
67
+ ## Sequence Diagrams
68
+
69
+ ### [Operation Name]
70
+
71
+ ```mermaid
72
+ sequenceDiagram
73
+ participant App
74
+ participant CC as ContactCenter
75
+ participant Svc as Service
76
+ participant WS as WebSocket
77
+ participant BE as Backend
78
+
79
+ App->>CC: methodName(params)
80
+ CC->>Svc: service.method({data})
81
+ Svc->>WS: Send request
82
+ WS->>BE: WebSocket message
83
+ BE-->>WS: Response event
84
+ WS-->>Svc: Resolve promise
85
+ Svc-->>CC: Return response
86
+ CC-->>App: Promise resolves
87
+ ```
88
+
89
+ ---
90
+
91
+ ## Key Patterns
92
+
93
+ ### [Pattern Name]
94
+
95
+ Description of the pattern and why it's used.
96
+
97
+ ```typescript
98
+ // Code example
99
+ ```
100
+
101
+ ---
102
+
103
+ ## Integration Points
104
+
105
+ ### With [Component]
106
+
107
+ How this service integrates with other components.
108
+
109
+ ### With WebSocket
110
+
111
+ How WebSocket events are handled.
112
+
113
+ ### With Metrics
114
+
115
+ What metrics are tracked.
116
+
117
+ ---
118
+
119
+ ## State Management
120
+
121
+ ### Lifecycle States
122
+
123
+ ```
124
+ [State 1] → [State 2] → [State 3]
125
+ ↑ ↓
126
+ └──────────────────────┘
127
+ ```
128
+
129
+ ### State Transitions
130
+
131
+ | From | To | Trigger |
132
+ |------|-----|---------|
133
+ | State1 | State2 | Action |
134
+
135
+ ---
136
+
137
+ ## Error Handling
138
+
139
+ ### Error Types
140
+
141
+ | Error | Cause | Resolution |
142
+ |-------|-------|------------|
143
+ | `REASON_CODE` | Why it happens | How to fix |
144
+
145
+ ### Error Flow
146
+
147
+ ```mermaid
148
+ flowchart TD
149
+ A[API Call] --> B{Success?}
150
+ B -->|Yes| C[Track Success Metric]
151
+ B -->|No| D[Cast to Failure]
152
+ D --> E[Track Failure Metric]
153
+ E --> F[getErrorDetails]
154
+ F --> G[Log Error]
155
+ G --> H[Upload Logs]
156
+ H --> I[Throw Error]
157
+ ```
158
+
159
+ ---
160
+
161
+ ## Troubleshooting
162
+
163
+ ### [Issue]: [Symptom]
164
+
165
+ **Cause**: Why this happens
166
+
167
+ **Solution**: How to fix
168
+
169
+ **Example**:
170
+ ```typescript
171
+ // Code showing the fix
172
+ ```
173
+
174
+ ---
175
+
176
+ ## Related Files
177
+
178
+ - [Main implementation](../../path/to/file.ts)
179
+ - [Types](../../path/to/types.ts)
180
+ - [Tests](../../../../test/unit/spec/path/to/file.ts)
181
+ ```
182
+
183
+ ---
184
+
185
+ ## Content Guidelines
186
+
187
+ ### Component Overview
188
+ - List main classes/functions
189
+ - Include file paths
190
+ - Brief responsibility description
191
+
192
+ ### Diagrams
193
+ - Use Mermaid for all diagrams
194
+ - Keep diagrams focused (not too complex)
195
+ - Include legends if needed
196
+
197
+ ### Sequence Diagrams
198
+ - Show key operations
199
+ - Include error paths for critical flows
200
+ - Label all participants clearly
201
+
202
+ ### Troubleshooting
203
+ - Document real issues encountered
204
+ - Provide concrete solutions
205
+ - Include code examples
206
+
207
+ ---
208
+
209
+ ## Mermaid Diagram Guidelines
210
+
211
+ ### Flowchart
212
+ ```mermaid
213
+ flowchart TD
214
+ A[Start] --> B{Decision}
215
+ B -->|Yes| C[Action]
216
+ B -->|No| D[Other Action]
217
+ ```
218
+
219
+ ### Sequence
220
+ ```mermaid
221
+ sequenceDiagram
222
+ participant A as ActorA
223
+ participant B as ActorB
224
+ A->>B: Message
225
+ B-->>A: Response
226
+ ```
227
+
228
+ ### State
229
+ ```mermaid
230
+ stateDiagram-v2
231
+ [*] --> State1
232
+ State1 --> State2
233
+ State2 --> [*]
234
+ ```
235
+
236
+ ---
237
+
238
+ ## Validation Checklist
239
+
240
+ - [ ] All components listed with files
241
+ - [ ] Data flow diagram included
242
+ - [ ] Key sequence diagrams present
243
+ - [ ] Error handling documented
244
+ - [ ] Troubleshooting section has real issues
245
+ - [ ] Mermaid diagrams render correctly
246
+ - [ ] Links to source files included
247
+
248
+ ---
249
+
250
+ ## Example: Task Service ARCHITECTURE.md
251
+
252
+ ```markdown
253
+ # Task Service - Architecture
254
+
255
+ > Technical documentation for task lifecycle management.
256
+
257
+ ---
258
+
259
+ ## Component Overview
260
+
261
+ | Component | File | Responsibility |
262
+ |-----------|------|----------------|
263
+ | `TaskManager` | `task/TaskManager.ts` | Task lifecycle coordination |
264
+ | `contact` | `task/contact.ts` | Task operations (hold, transfer) |
265
+ | `dialer` | `task/dialer.ts` | Outbound call initiation |
266
+ | `AutoWrapup` | `task/AutoWrapup.ts` | Auto wrapup timer |
267
+
268
+ ---
269
+
270
+ ## Sequence: Incoming Task
271
+
272
+ ```mermaid
273
+ sequenceDiagram
274
+ participant WS as WebSocket
275
+ participant TM as TaskManager
276
+ participant CC as ContactCenter
277
+ participant App as Application
278
+
279
+ WS->>TM: AgentOfferContact event
280
+ TM->>TM: Create Task object
281
+ TM->>CC: emit task:incoming
282
+ CC->>App: trigger task:incoming
283
+ App->>App: Display incoming task UI
284
+ ```
285
+
286
+ ---
287
+
288
+ ## Troubleshooting
289
+
290
+ ### Issue: Task events not received
291
+
292
+ **Cause**: TaskManager listeners not registered
293
+
294
+ **Solution**: Ensure register() is called before login
295
+ ```
@@ -0,0 +1,254 @@
1
+ # Bug Fix Template
2
+
3
+ > **Purpose**: Systematic workflow for fixing bugs in existing code.
4
+
5
+ ---
6
+
7
+ ## Section A: Questions for the Developer (MANDATORY — Ask First)
8
+
9
+ **STOP. Present the following questions to the developer and wait for their answers.** Do not read code, run tests, or start investigating until the developer has answered these questions. Do not infer or assume answers.
10
+
11
+ If the developer cannot provide reproduction steps, ask for logs, error messages, or a description of expected vs actual behavior.
12
+
13
+ ### Questions to Ask:
14
+
15
+ 1. **"What is the unexpected behavior you are seeing?"**
16
+ - Get a clear description of what is going wrong.
17
+
18
+ 2. **"What should happen instead? What is the expected behavior?"**
19
+
20
+ 3. **"How do you reproduce this bug? What are the steps?"**
21
+ - If the developer cannot reproduce it, ask:
22
+ - "Do you have any error messages or stack traces?"
23
+ - "Do you have a trackingId from the logs?"
24
+ - "When did this start happening? Was there a recent code change?"
25
+
26
+ 4. **"Which layer do you think is affected?"**
27
+ - [ ] Plugin (`cc.ts`)
28
+ - [ ] Service (`services/*`)
29
+ - [ ] Core (`services/core/*`)
30
+ - [ ] Types
31
+ - [ ] Not sure (this is fine — you will investigate)
32
+
33
+ ### Completion Gate for Section A
34
+
35
+ **Before proceeding to investigation, verify:**
36
+
37
+ - [ ] Unexpected behavior described by developer
38
+ - [ ] Expected behavior described by developer
39
+ - [ ] Reproduction steps provided (or logs/error messages if steps are unknown)
40
+ - [ ] Affected layer identified (or "not sure" — which is acceptable)
41
+
42
+ **If the description is too vague to start investigating (e.g., "it's broken"), ask targeted follow-up questions. Do not proceed until you have enough context to know where to look.**
43
+
44
+ ---
45
+
46
+ ## Section B: Agent Investigation Steps (After Developer Answers)
47
+
48
+ Only proceed here after Section A questions are answered.
49
+
50
+ ### Step 1: Reproduce the Bug
51
+
52
+ #### Understand Current Behavior
53
+
54
+ 1. Read the affected code — trace the execution flow
55
+ 2. Identify where behavior diverges from the developer's expected behavior
56
+ 3. Check the call chain: plugin -> service -> core
57
+
58
+ #### Check Existing Tests
59
+
60
+ ```bash
61
+ # Run tests for the affected area
62
+ yarn workspace @webex/contact-center test:unit -- <path_to_specific_file>
63
+ ```
64
+
65
+ Are there tests that should have caught this? Do they pass incorrectly?
66
+
67
+ ---
68
+
69
+ ### Step 2: Identify Root Cause
70
+
71
+ #### Common Bug Patterns in This SDK
72
+
73
+ **A. Async/Promise Issues**
74
+ ```typescript
75
+ // Bug: Not awaiting promise
76
+ this.services.agent.stateChange({data});
77
+
78
+ // Fix: Await the promise
79
+ await this.services.agent.stateChange({data});
80
+ ```
81
+
82
+ **B. Missing Error Handling**
83
+ ```typescript
84
+ // Bug: Error swallowed
85
+ try {
86
+ await operation();
87
+ } catch (e) {}
88
+
89
+ // Fix: Proper error handling
90
+ try {
91
+ await operation();
92
+ } catch (error) {
93
+ const {error: detailedError} = getErrorDetails(error, method, module);
94
+ throw detailedError;
95
+ }
96
+ ```
97
+
98
+ **C. Event Listener Leaks**
99
+ ```typescript
100
+ // Bug: Listener not removed
101
+ this.on('event', handler);
102
+
103
+ // Fix: Store reference and remove
104
+ this.handler = (data) => { /* handle */ };
105
+ this.on('event', this.handler);
106
+ // Later in cleanup:
107
+ this.off('event', this.handler);
108
+ ```
109
+
110
+ **D. Type Mismatches**
111
+ ```typescript
112
+ // Bug: Accessing wrong property
113
+ const id = response.data.agentId; // But it's response.agentId
114
+
115
+ // Fix: Check actual response structure
116
+ const id = response.agentId;
117
+ ```
118
+
119
+ **E. Missing Null Checks**
120
+ ```typescript
121
+ // Bug: Crashes if undefined
122
+ const name = this.agentConfig.teams[0].teamName;
123
+
124
+ // Fix: Optional chaining
125
+ const name = this.agentConfig?.teams?.[0]?.teamName;
126
+ ```
127
+
128
+ ---
129
+
130
+ ### Step 3: Present Root Cause and Proposed Fix to Developer
131
+
132
+ **STOP. Before writing any fix, present your findings to the developer:**
133
+
134
+ ```
135
+ ## Bug Analysis Summary
136
+
137
+ **Bug**: [one-sentence description]
138
+ **Root cause**: [what is actually wrong in the code]
139
+ **Affected file(s)**: [file paths and line numbers]
140
+ **Root cause category**: [A/B/C/D/E from patterns above, or other]
141
+
142
+ ### Proposed Fix:
143
+ - [What will change in which file]
144
+ - [What the code will look like after the fix]
145
+
146
+ ### Risk Assessment:
147
+ - Could this fix break anything else? [Yes/No — if yes, what]
148
+ - Backward compatible? [Yes/No]
149
+
150
+ ### Tests to Add:
151
+ - [Regression test description]
152
+
153
+ ---
154
+ Does this analysis look correct? Should I proceed with this fix? (Yes / No / Adjust)
155
+ ```
156
+
157
+ **Wait for developer confirmation before implementing the fix.**
158
+
159
+ ---
160
+
161
+ ### Step 4: Implement the Fix
162
+
163
+ After developer approval:
164
+
165
+ ```typescript
166
+ // 1. Make the minimal fix
167
+ // 2. Add/update logging if it helps debugging
168
+ LoggerProxy.log('Processing data', {
169
+ module: MODULE,
170
+ method: METHOD,
171
+ data: { relevantField: value }, // Add context
172
+ });
173
+
174
+ // 3. Ensure error handling is complete
175
+ try {
176
+ // fixed code
177
+ } catch (error) {
178
+ LoggerProxy.error(`Operation failed: ${error}`, {
179
+ module: MODULE,
180
+ method: METHOD,
181
+ });
182
+ // ... proper error handling
183
+ }
184
+ ```
185
+
186
+ ---
187
+
188
+ ### Step 5: Add Regression Test
189
+
190
+ ```typescript
191
+ describe('methodName - Bug Fix', () => {
192
+ it('should handle [specific scenario that was buggy]', async () => {
193
+ // Arrange: Setup the conditions that triggered the bug
194
+ const bugTriggerInput = { /* ... */ };
195
+
196
+ // Act: Execute the fixed code
197
+ const result = await service.methodName(bugTriggerInput);
198
+
199
+ // Assert: Verify correct behavior
200
+ expect(result).toEqual(expectedResult);
201
+ });
202
+
203
+ it('should not throw error when [edge case]', async () => {
204
+ // Test the specific edge case that was failing
205
+ });
206
+ });
207
+ ```
208
+
209
+ ---
210
+
211
+ ### Step 6: Validation Checklist
212
+
213
+ #### Code Changes
214
+ - [ ] Fix is minimal and focused
215
+ - [ ] No unrelated changes
216
+ - [ ] LoggerProxy used (no console.log)
217
+ - [ ] Error handling complete
218
+
219
+ #### Tests
220
+ - [ ] Regression test added
221
+ - [ ] All existing tests still pass
222
+ - [ ] Test covers the specific bug scenario
223
+
224
+ #### Verification
225
+ ```bash
226
+ # Lint
227
+ yarn workspace @webex/contact-center test:style
228
+
229
+ # All tests
230
+ yarn workspace @webex/contact-center test:unit
231
+
232
+ # Build
233
+ yarn workspace @webex/contact-center build:src
234
+ ```
235
+
236
+ ---
237
+
238
+ ## Documentation
239
+
240
+ If the bug affected documented behavior:
241
+ - [ ] Update JSDoc if behavior changed
242
+ - [ ] Update the affected service's `AGENTS.md` if API behavior changed (find via root [`AGENTS.md` Service Routing Table](../../../AGENTS.md#service-routing-table))
243
+ - [ ] Update the affected service's `ARCHITECTURE.md` if data flow changed
244
+
245
+ ---
246
+
247
+ ## Complete!
248
+
249
+ Bug fix is complete when:
250
+ 1. Root cause identified and confirmed with developer
251
+ 2. Fix implemented after developer approval
252
+ 3. Regression test added — a test that reproduces the original bug (fails before the fix, passes after) to prevent the same issue from recurring
253
+ 4. All tests pass
254
+ 5. Build succeeds