@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
package/AGENTS.md ADDED
@@ -0,0 +1,438 @@
1
+ # Contact Center SDK - AI Agent Guide
2
+
3
+ ## Purpose
4
+
5
+ This is the main orchestrator for AI assistants working with the package `@webex/contact-center` in this repository. It routes you to the correct templates and documentation based on the developer's task and provides critical rules for code generation.
6
+
7
+ **For every developer request, follow the Quick Start Workflow below.**
8
+
9
+ ---
10
+
11
+ ## Quick Start Workflow
12
+
13
+ When a developer provides a task, follow this workflow **in order**:
14
+
15
+ 1. **Classify the task** - Use the Task Classification Decision Tree below to identify the task type (A-F). If you cannot confidently classify, ask the developer.
16
+ 2. **STOP — Ask the developer questions** - Open the routed template's pre-questions file. Present every MANDATORY question to the developer. Wait for their answers. **Do NOT proceed until all MANDATORY fields have explicit answers from the developer.** Do not infer, assume, or fill in answers yourself.
17
+ 3. **Present Spec Summary for approval** - After gathering answers, present a structured summary of what you will build (see Spec Summary Gate below). Wait for the developer to confirm.
18
+ 4. **Load context** - Use the [Service Routing Table](#service-routing-table) to find and read the target service's `AGENTS.md` and `ARCHITECTURE.md`, then load relevant patterns.
19
+ 5. **Break down large or multi-part tasks** - If the prompt mixes multiple tasks (for example, "add a method" and "fix a bug"), split into smaller scoped subtasks and execute them one by one — each subtask goes through steps 1-3 independently.
20
+ 6. **Generate/fix code** - Follow established package patterns and the routed template's implementation steps.
21
+ 7. **Validate functionality and quality** - Verify behavior, tests, lint, and type checks.
22
+ 8. **Update documentation** - Keep ai-docs aligned with code changes.
23
+ 9. **Ask for review** - Confirm completion and offer adjustments.
24
+
25
+ ---
26
+
27
+ ## Task Classification Decision Tree
28
+
29
+ Use these questions **in order** to classify the developer's request. Follow the first matching path.
30
+
31
+ ```
32
+ Q1: Is the task read-only (understanding, explaining, or analyzing code)?
33
+ ├── YES → Type E: Understand Architecture
34
+
35
+ └── NO → Q2: Is something broken or behaving incorrectly?
36
+ ├── YES → Is this a UI/UX improvement or a code-level defect?
37
+ │ ├── UI/UX fix (visual, layout, interaction) → Type D: Add Feature / Enhance Existing Service
38
+ │ └── Code-level defect (wrong behavior, crash, data issue) → Type C: Fix Bug
39
+
40
+ └── NO → Q3: Does this involve creating a new file, class, or module?
41
+ ├── YES → Type A: Create New Service
42
+
43
+ └── NO → Q4: Does this involve adding a brand-new method that does not exist yet?
44
+ │ NOTE: If the developer describes a "capability" or "feature" that
45
+ │ happens to require a new method, check signal keywords — if the
46
+ │ request matches Type D signals ("add capability", "enhance", "enable"),
47
+ │ use the Disambiguation Rule to confirm with the developer.
48
+ ├── YES → Type B: Add New Method
49
+
50
+ └── NO → Q5: Does this involve changing an existing method's signature, behavior, parameters, or return type?
51
+ ├── YES → Type F: Modify Existing Method
52
+
53
+ └── NO → Type D: Add Feature / Enhance Existing Service
54
+ ```
55
+
56
+ ### Signal Keywords by Task Type
57
+
58
+ Use these keyword patterns to help confirm your classification:
59
+
60
+ | Task Type | Signal Keywords in Developer Request |
61
+ |---|---|
62
+ | **A. Create New Service** | "new service", "new module", "new class", "create a service for", "add a new [ServiceName]", "like AddressBook/Queue/EntryPoint" |
63
+ | **B. Add New Method** | "add a method", "add an API", "new method", "expose a new function", "add [methodName] to" |
64
+ | **C. Fix Bug** | "bug", "broken", "not working", "regression", "incorrect", "error", "crash", "unexpected behavior", "fix" |
65
+ | **D. Add Feature** | "enhance", "add feature", "add capability", "improve", "extend", "support for", "enable" |
66
+ | **E. Understand Architecture** | "explain", "how does", "understand", "architecture", "what is", "walk me through", "show me" |
67
+ | **F. Modify Existing Method** | "change", "modify", "update", "add parameter to", "change return type", "rename", "refactor [methodName]" |
68
+
69
+ ### Disambiguation Rule
70
+
71
+ **If you cannot confidently classify the task after using the decision tree and signal keywords, ask the developer:**
72
+
73
+ > "I want to make sure I follow the right workflow. Which of these best describes your task?"
74
+ > - A. Create a new service/module (new file/class)
75
+ > - B. Add a new method to an existing service
76
+ > - C. Fix a bug or incorrect behavior
77
+ > - D. Add a feature or enhance an existing service
78
+ > - E. Understand/explain the architecture (no code changes)
79
+ > - F. Modify an existing method (change signature, behavior, parameters)
80
+
81
+ **Do not guess. Do not default to the most common type. Ask.**
82
+
83
+ ---
84
+
85
+ ## Task Type Routing
86
+
87
+ **A. Create New Service**
88
+ - Use when adding a new service module (for example, a new service to support real-time transcripts, similar to existing services like AddressBook, Queue, or EntryPoint).
89
+ - **Route to:** [`ai-docs/templates/new-service/00-master.md`](ai-docs/templates/new-service/00-master.md)
90
+ - **Pre-questions:** [`ai-docs/templates/new-service/01-pre-questions.md`](ai-docs/templates/new-service/01-pre-questions.md) — STOP and ask these first.
91
+ - **Follow:** Full new-service workflow including validation and docs updates.
92
+
93
+ **B. Add New Method**
94
+ - Use when extending an existing service with a new method/API.
95
+ - **Route to:** [`ai-docs/templates/new-method/00-master.md`](ai-docs/templates/new-method/00-master.md)
96
+ - **Pre-questions:** [`ai-docs/templates/new-method/01-requirements.md`](ai-docs/templates/new-method/01-requirements.md) — STOP and ask these first.
97
+ - **Follow:** Method signature, implementation, tests, and validation checklist.
98
+
99
+ **C. Fix Bug**
100
+ - Use when behavior is incorrect or regressions are reported.
101
+ - **Route to:** [`ai-docs/templates/existing-service/bug-fix.md`](ai-docs/templates/existing-service/bug-fix.md)
102
+ - **Pre-questions:** Bug-fix template Section A (Questions for the Developer) — STOP and ask these first.
103
+ - **Follow:** Gather info from developer -> Investigate -> Root cause -> Fix -> Regression validation.
104
+
105
+ **D. Add Feature**
106
+ - Use when enhancing capabilities, then decide placement via triage:
107
+ - existing service/module enhancement, or
108
+ - new standalone service/module creation.
109
+ - **Route to:** [`ai-docs/templates/existing-service/feature-enhancement.md`](ai-docs/templates/existing-service/feature-enhancement.md)
110
+ - **Pre-questions:** Feature-enhancement template Step 0 (Placement Triage) + Pre-Enhancement Questions — STOP and ask these first.
111
+ - **Follow:** Run mandatory feature placement triage. If triage indicates a new service/module, reroute to [`ai-docs/templates/new-service/00-master.md`](ai-docs/templates/new-service/00-master.md).
112
+
113
+ **E. Understand Architecture**
114
+ - Use when the task is analysis/explanation and no immediate code generation is required.
115
+ - **Route to:** Use the [Service Routing Table](#service-routing-table) to identify the relevant service, then load its `AGENTS.md` and `ARCHITECTURE.md`:
116
+ - Agent: [`src/services/agent/ai-docs/`](src/services/agent/ai-docs/AGENTS.md)
117
+ - Task: [`src/services/task/ai-docs/`](src/services/task/ai-docs/AGENTS.md)
118
+ - Config: [`src/services/config/ai-docs/`](src/services/config/ai-docs/AGENTS.md)
119
+ - Core: [`src/services/core/ai-docs/`](src/services/core/ai-docs/AGENTS.md)
120
+ - **Follow:** Read-only architecture exploration with clear explanation.
121
+ - No pre-questions required (read-only task).
122
+
123
+ **F. Modify Existing Method**
124
+ - Use when changing an existing method's signature, behavior, parameters, or return type.
125
+ - **Route to:** [`ai-docs/templates/existing-service/feature-enhancement.md`](ai-docs/templates/existing-service/feature-enhancement.md) (follow the same workflow, but skip placement triage — the method already exists).
126
+ - **Pre-questions:** Feature-enhancement template Pre-Enhancement Questions (skip Step 0 triage) — STOP and ask these first.
127
+ - **Follow:** Gather requirements -> Design change -> Implement -> Test -> Validate backward compatibility.
128
+
129
+ If a developer request includes multiple task types, split into ordered subtasks and execute each through the full classify -> question -> spec-summary -> implement sequence.
130
+
131
+ ---
132
+
133
+ ## Spec Summary Gate (MANDATORY before code generation)
134
+
135
+ After gathering answers from the developer, and **before writing any code**, present a structured summary for developer approval.
136
+
137
+ ### Spec Summary Template
138
+
139
+ ```
140
+ ## Spec Summary — [Task Type]
141
+
142
+ **Task**: [One-sentence description of what will be done]
143
+ **Target file(s)**: [File paths that will be created or modified]
144
+ **Task type**: [A/B/C/D/E/F from classification]
145
+
146
+ ### What will be built/changed:
147
+ - [Bullet 1: key change]
148
+ - [Bullet 2: key change]
149
+ - [Bullet N: key change]
150
+
151
+ ### API Contract (if applicable):
152
+ - Method: `methodName(params: ParamType): Promise<ReturnType>`
153
+ - HTTP: [METHOD] [endpoint]
154
+ - Request payload: [structure]
155
+ - Response payload: [structure]
156
+
157
+ ### Events (if applicable):
158
+ | Event | Direction | Object | Payload | Trigger |
159
+ |---|---|---|---|---|
160
+ | [event name] | [emitted / listened] | [cc, task, taskManager, or service] | [payload type] | [what causes it] |
161
+ (or "No events")
162
+
163
+ ### Metrics (if applicable):
164
+ - Success: [metric name]
165
+ - Failure: [metric name]
166
+
167
+ ### Breaking changes: [Yes/No — if yes, describe migration]
168
+
169
+ ### Files to create/modify:
170
+ 1. [file path] — [what changes]
171
+ 2. [file path] — [what changes]
172
+
173
+ ---
174
+ Does this match your intent? (Yes / No / Adjust)
175
+ ```
176
+
177
+ **Rules:**
178
+ - Do NOT begin implementation until the developer confirms.
179
+ - If the developer says "Adjust", gather the corrections and re-present the summary.
180
+ - If the developer says "Skip" or "Just do it", you may proceed without the summary — but this must be an explicit developer choice.
181
+
182
+ ---
183
+
184
+ ## CRITICAL RULES (Always Apply)
185
+
186
+ ### 1. STOP and Ask Before Coding (MANDATORY — HIGHEST PRIORITY)
187
+
188
+ **This is the most important rule in this guide.**
189
+
190
+ Before writing, generating, or modifying any code:
191
+ 1. Classify the task using the decision tree.
192
+ 2. Present the template's pre-questions to the developer.
193
+ 3. Wait for answers. Do not infer or assume.
194
+ 4. Present the Spec Summary. Wait for approval.
195
+
196
+ **Violations of this rule include:**
197
+ - Reading code to "understand the context" before asking the developer questions
198
+ - Filling in pre-question answers yourself based on the developer's initial request
199
+ - Skipping the Spec Summary because the task "seems straightforward"
200
+ - Starting implementation while pre-questions have unanswered MANDATORY fields
201
+
202
+ The only exception is **Type E (Understand Architecture)** which is read-only.
203
+
204
+ ---
205
+
206
+ ### 2. LoggerProxy Usage (MANDATORY)
207
+
208
+ **NEVER use `console.log()`.** Always use `LoggerProxy` with `module` and `method` context. See full patterns and examples in [`ai-docs/RULES.md`](ai-docs/RULES.md) and [`ai-docs/patterns/typescript-patterns.md`](ai-docs/patterns/typescript-patterns.md).
209
+
210
+ ---
211
+
212
+ ### 3. MetricsManager Usage (MANDATORY)
213
+
214
+ All operations must track metrics using `timeEvent` + `trackEvent`. See full pattern in [`ai-docs/RULES.md`](ai-docs/RULES.md).
215
+
216
+ ---
217
+
218
+ ### 4. Error Handling Pattern (MANDATORY)
219
+
220
+ Always use `getErrorDetails` from `services/core/Utils` for consistent error handling. See full pattern in [`ai-docs/RULES.md`](ai-docs/RULES.md) and [`ai-docs/patterns/typescript-patterns.md`](ai-docs/patterns/typescript-patterns.md).
221
+
222
+ ---
223
+
224
+ ### 5. Event Emission Pattern (MANDATORY)
225
+
226
+ Use defined event constants (`CC_EVENTS`, `AGENT_EVENTS`, `TASK_EVENTS`), never raw strings. See full pattern in [`ai-docs/RULES.md`](ai-docs/RULES.md) and [`ai-docs/patterns/event-driven-patterns.md`](ai-docs/patterns/event-driven-patterns.md).
227
+
228
+ ---
229
+
230
+ ### 6. WebexPlugin Extension Pattern (MANDATORY)
231
+
232
+ Follow the established `cc.ts` plugin class pattern with JSDoc (`@public`, `@param`, `@returns`, `@example`). Refer to `src/cc.ts` directly for the canonical implementation.
233
+
234
+ ---
235
+
236
+ ### 7. Scope ai-docs Are Authoritative (MANDATORY)
237
+
238
+ When working inside a service scope, use the [Service Routing Table](#service-routing-table) to locate and load that service's `AGENTS.md` and `ARCHITECTURE.md`. Treat them as implementation authority for that scope.
239
+
240
+ - This root `AGENTS.md` is the orchestrator — it routes tasks and enforces rules.
241
+ - Service-level `ai-docs` define scope-specific behavior, architecture, and patterns.
242
+ - If there is any conflict between root and service docs, prefer the service docs for that scope.
243
+
244
+ ---
245
+
246
+ ### 8. Context Guardrail (APPLIES EVERYWHERE)
247
+
248
+ For **every** task type (new service, new method, bug fix, feature enhancement, architecture), gather context in this order:
249
+
250
+ 1. Same package code under `@webex/contact-center`
251
+ 2. Same package ai-docs (`AGENTS.md`, `ARCHITECTURE.md`, templates, patterns)
252
+ 3. Same package tests
253
+
254
+ Only use references from other plugins/modules/packages when the developer explicitly requests it.
255
+
256
+ Mandatory behavior:
257
+ - Prefer local package implementations/patterns before external references.
258
+ - If required context is missing, ask targeted clarification questions instead of guessing.
259
+ - Document what local references were used before implementation.
260
+
261
+ ---
262
+
263
+ ## Context Loading by Task Type
264
+
265
+ **First:** Identify the affected service using the [Service Routing Table](#service-routing-table). Load that service's `AGENTS.md` and `ARCHITECTURE.md` via the direct links in the table.
266
+
267
+ ### For New Service/Method:
268
+ 1. Load the affected service's docs via [Service Routing Table](#service-routing-table)
269
+ 2. Read [`ai-docs/patterns/typescript-patterns.md`](ai-docs/patterns/typescript-patterns.md)
270
+ 3. Read [`ai-docs/patterns/event-driven-patterns.md`](ai-docs/patterns/event-driven-patterns.md)
271
+ 4. Read [`ai-docs/patterns/testing-patterns.md`](ai-docs/patterns/testing-patterns.md)
272
+ 5. Read existing service in same category (e.g., `AddressBook.ts` for new data service)
273
+
274
+ ### For Bug Fix:
275
+ 1. Load the affected service's docs via [Service Routing Table](#service-routing-table) — prioritize `ARCHITECTURE.md`
276
+ 2. Read [`ai-docs/patterns/testing-patterns.md`](ai-docs/patterns/testing-patterns.md)
277
+ 3. Read related test files
278
+
279
+ ### For Feature Enhancement / Modify Existing Method:
280
+ 1. Load the affected service's docs via [Service Routing Table](#service-routing-table) — prioritize `AGENTS.md`
281
+ 2. Read [`ai-docs/patterns/typescript-patterns.md`](ai-docs/patterns/typescript-patterns.md)
282
+ 3. Read related existing implementation
283
+
284
+ ---
285
+
286
+ ## Repository Structure
287
+
288
+ ```
289
+ packages/@webex/contact-center/
290
+ ├── src/
291
+ │ ├── cc.ts # Main plugin class (WebexPlugin)
292
+ │ ├── types.ts # Public types and interfaces
293
+ │ ├── constants.ts # Package constants
294
+ │ ├── logger-proxy.ts # LoggerProxy implementation
295
+ │ ├── metrics/
296
+ │ │ ├── MetricsManager.ts # Singleton metrics manager
297
+ │ │ ├── behavioral-events.ts # Behavioral event taxonomy
298
+ │ │ └── constants.ts # METRIC_EVENT_NAMES
299
+ │ └── services/
300
+ │ ├── index.ts # Services singleton
301
+ │ ├── AddressBook.ts # Address book service
302
+ │ ├── EntryPoint.ts # Entry point service
303
+ │ ├── Queue.ts # Queue service
304
+ │ ├── WebCallingService.ts # WebRTC calling service
305
+ │ ├── agent/ # Agent operations
306
+ │ │ ├── index.ts # Agent service factory
307
+ │ │ ├── types.ts # Agent types and events
308
+ │ │ └── ai-docs/ # Agent-specific AI documentation
309
+ │ │ ├── AGENTS.md # Agent usage guide
310
+ │ │ └── ARCHITECTURE.md # Agent technical deep-dive
311
+ │ ├── task/ # Task management
312
+ │ │ ├── TaskManager.ts # Task lifecycle manager
313
+ │ │ ├── contact.ts # Contact operations
314
+ │ │ ├── dialer.ts # Outbound dialing
315
+ │ │ ├── AutoWrapup.ts # Auto wrapup handler
316
+ │ │ ├── types.ts # Task types and events
317
+ │ │ └── ai-docs/ # Task-specific AI documentation
318
+ │ │ ├── AGENTS.md # Task usage guide
319
+ │ │ └── ARCHITECTURE.md # Task technical deep-dive
320
+ │ ├── config/ # Configuration
321
+ │ │ ├── index.ts # Config service
322
+ │ │ ├── types.ts # CC_EVENTS, Profile, etc.
323
+ │ │ ├── constants.ts # Config constants
324
+ │ │ └── ai-docs/ # Config-specific AI documentation
325
+ │ │ ├── AGENTS.md # Config usage guide
326
+ │ │ └── ARCHITECTURE.md # Config technical deep-dive
327
+ │ └── core/ # Core utilities
328
+ │ ├── WebexRequest.ts # HTTP request handler
329
+ │ ├── Utils.ts # Utility functions
330
+ │ ├── Err.ts # Error classes
331
+ │ ├── GlobalTypes.ts # Failure, AugmentedError
332
+ │ ├── aqm-reqs.ts # AQM request handler
333
+ │ ├── websocket/
334
+ │ │ ├── WebSocketManager.ts # WebSocket handler
335
+ │ │ └── connection-service.ts
336
+ │ └── ai-docs/ # Core-specific AI documentation
337
+ │ ├── AGENTS.md # Core usage guide
338
+ │ └── ARCHITECTURE.md # Core technical deep-dive
339
+ ├── test/
340
+ │ └── unit/
341
+ │ └── spec/
342
+ │ └── cc.ts # Main test file (reference)
343
+ └── ai-docs/ # AI documentation
344
+ ├── README.md # AI-docs overview
345
+ ├── RULES.md # Coding standards
346
+ ├── patterns/ # Pattern documentation
347
+ └── templates/ # Code generation templates
348
+ ```
349
+
350
+ ---
351
+
352
+ ## Key Type Patterns
353
+
354
+ For enum patterns (const object + type), response type patterns, and failure type patterns, see [`ai-docs/patterns/typescript-patterns.md`](ai-docs/patterns/typescript-patterns.md).
355
+
356
+ ---
357
+
358
+ ## Validation Checklist (After Code Generation)
359
+
360
+ - [ ] **LoggerProxy**: All methods use LoggerProxy with `module` and `method` context
361
+ - [ ] **Metrics**: Operations track success/failure with `timeEvent` + `trackEvent`
362
+ - [ ] **Error Handling**: Uses `getErrorDetails` pattern
363
+ - [ ] **Types**: All public types have JSDoc with `@public` tag
364
+ - [ ] **Events**: Uses event constants (CC_EVENTS, AGENT_EVENTS, TASK_EVENTS)
365
+ - [ ] **Tests**: Added/updated unit tests with MockWebex
366
+ - [ ] **Exports**: New types exported from `types.ts`
367
+ - [ ] **No console.log**: Zero instances of console.log/warn/error
368
+
369
+ ---
370
+
371
+ ## Functionality Validation Gate (CRITICAL)
372
+
373
+ Before marking any coding task complete, verify:
374
+
375
+ 1. **API/Type correctness**
376
+ - method signatures and payload types align with existing contracts
377
+ - no accidental breaking API changes
378
+ 2. **Pattern compliance**
379
+ - `LoggerProxy`, `MetricsManager`, `getErrorDetails`, event constants
380
+ 3. **Behavior correctness**
381
+ - success/failure paths covered
382
+ - state/event flow is correct for affected service
383
+ 4. **Quality checks**
384
+ - relevant unit tests pass
385
+ - lint/type checks pass
386
+
387
+ If any gate fails, fix before completion.
388
+
389
+ ---
390
+
391
+ ## Documentation Update Gate
392
+
393
+ After code changes, verify whether docs must be updated:
394
+
395
+ - Service-level docs (use [Service Routing Table](#service-routing-table) to locate):
396
+ - Service `AGENTS.md` — if usage/workflow changed
397
+ - Service `ARCHITECTURE.md` — if data flow/architecture changed
398
+ - Root-level docs:
399
+ - This file ([`AGENTS.md`](AGENTS.md)) — if task routing or rules changed
400
+ - [`ai-docs/templates/`](ai-docs/templates/) — if a new reusable template is needed
401
+ - [`ai-docs/patterns/`](ai-docs/patterns/) — if a new reusable pattern is introduced
402
+
403
+ ---
404
+
405
+ ## Success Criteria
406
+
407
+ - Follows required coding patterns (`LoggerProxy`, metrics, error handling, event constants)
408
+ - Implements intended behavior without regressions
409
+ - Includes/updates tests where needed
410
+ - Passes lint/type/test checks
411
+ - Updates docs when behavior or architecture changes
412
+
413
+ ---
414
+
415
+ ## Service-Level Documentation
416
+
417
+ For deep understanding of specific services, read their `ai-docs/`. When working on a task that affects a specific service, **always load that service's AGENTS.md and ARCHITECTURE.md** for scope-specific guidance.
418
+
419
+ ### Service Routing Table
420
+
421
+ Use this table to identify which service's ai-docs to load based on the developer's task:
422
+
423
+ | Service | Scope / Keywords | AGENTS.md | ARCHITECTURE.md |
424
+ |---------|-----------------|-----------|-----------------|
425
+ | **Agent** | login, logout, state change, buddy agents, station | [`src/services/agent/ai-docs/AGENTS.md`](src/services/agent/ai-docs/AGENTS.md) | [`src/services/agent/ai-docs/ARCHITECTURE.md`](src/services/agent/ai-docs/ARCHITECTURE.md) |
426
+ | **Task** | task, hold, transfer, conference, wrapup, outdial, consult | [`src/services/task/ai-docs/AGENTS.md`](src/services/task/ai-docs/AGENTS.md) | [`src/services/task/ai-docs/ARCHITECTURE.md`](src/services/task/ai-docs/ARCHITECTURE.md) |
427
+ | **Config** | profile, register, teams, aux codes, desktop profile, settings | [`src/services/config/ai-docs/AGENTS.md`](src/services/config/ai-docs/AGENTS.md) | [`src/services/config/ai-docs/ARCHITECTURE.md`](src/services/config/ai-docs/ARCHITECTURE.md) |
428
+ | **Core** | websocket, HTTP, connection, reconnect, aqm, utils, errors | [`src/services/core/ai-docs/AGENTS.md`](src/services/core/ai-docs/AGENTS.md) | [`src/services/core/ai-docs/ARCHITECTURE.md`](src/services/core/ai-docs/ARCHITECTURE.md) |
429
+
430
+ **Routing rule:** If the developer's task mentions keywords in the "Scope / Keywords" column, load that service's ai-docs. If multiple services are involved, load all relevant ones. If unsure which service is affected, ask the developer.
431
+
432
+ ---
433
+
434
+ ## Need More Context?
435
+
436
+ - **TypeScript patterns**: [`ai-docs/patterns/typescript-patterns.md`](ai-docs/patterns/typescript-patterns.md)
437
+ - **Testing patterns**: [`ai-docs/patterns/testing-patterns.md`](ai-docs/patterns/testing-patterns.md)
438
+ - **Event patterns**: [`ai-docs/patterns/event-driven-patterns.md`](ai-docs/patterns/event-driven-patterns.md)
@@ -0,0 +1,131 @@
1
+ # Contact Center SDK - AI Documentation
2
+
3
+ > AI-focused documentation for the `@webex/contact-center` package to enable LLM agents to effectively create, modify, and fix SDK code.
4
+
5
+ ---
6
+
7
+ ## Package Overview
8
+
9
+ The `@webex/contact-center` package is a Webex SDK plugin that provides a TypeScript/JavaScript API for building Contact Center agent applications. It enables:
10
+
11
+ - **Agent Session Management**: Register, login, logout, state changes
12
+ - **Task Handling**: Inbound/outbound calls, chat, transfers, conferences
13
+ - **Real-time Events**: WebSocket-based notifications for agent and task events
14
+ - **Browser-based Calling**: WebRTC integration for browser softphone
15
+ - **Metrics & Diagnostics**: Built-in telemetry and log upload
16
+
17
+ ---
18
+
19
+ ## Technologies
20
+
21
+ | Technology | Purpose |
22
+ |------------|---------|
23
+ | **TypeScript** | Primary language with strict mode |
24
+ | **WebexPlugin** | Base class from `@webex/webex-core` |
25
+ | **EventEmitter** | Event handling for real-time updates |
26
+ | **WebSocket** | Real-time communication with Contact Center |
27
+ | **WebRTC** | Browser-based calling (via WebCalling) |
28
+ | **Jest** | Unit testing framework |
29
+
30
+ ---
31
+
32
+ ## Quick Links
33
+
34
+ | Document | Purpose |
35
+ |----------|---------|
36
+ | [AGENTS.md](../AGENTS.md) | **Start here** - Main AI agent orchestrator (at package root) |
37
+ | [RULES.md](RULES.md) | Coding standards and conventions |
38
+ | [patterns/](patterns/) | Pattern documentation |
39
+ | [templates/](templates/) | Code generation templates |
40
+
41
+ ---
42
+
43
+ ## For AI Agents
44
+
45
+ ### Starting a Task
46
+
47
+ Start with the root [`AGENTS.md`](../AGENTS.md) — it contains the full Quick Start Workflow, task classification decision tree, and critical rules.
48
+
49
+ ---
50
+
51
+ ## Directory Structure
52
+
53
+ ```
54
+ packages/@webex/contact-center/
55
+ ├── AGENTS.md # Main orchestrator (start here — at package root)
56
+ └── ai-docs/
57
+ ├── README.md # This file
58
+ ├── RULES.md # Coding standards
59
+ ├── patterns/ # Pattern documentation
60
+ │ ├── typescript-patterns.md
61
+ │ ├── testing-patterns.md
62
+ │ └── event-driven-patterns.md
63
+ └── templates/ # Code generation templates
64
+ ├── README.md
65
+ ├── new-service/ # Creating new services
66
+ ├── new-method/ # Adding methods
67
+ ├── existing-service/ # Bug fixes, features
68
+ └── documentation/ # Doc generation
69
+ ```
70
+
71
+ ---
72
+
73
+ ## Package Commands
74
+
75
+ ```bash
76
+ # Build
77
+ yarn workspace @webex/contact-center build:src
78
+
79
+ # Test unit tests
80
+ yarn workspace @webex/contact-center test:unit
81
+
82
+ # Test specific file
83
+ yarn workspace @webex/contact-center test:unit -- <path_of_test_file>
84
+
85
+ # Lint
86
+ yarn workspace @webex/contact-center test:styles
87
+ ```
88
+
89
+ ---
90
+
91
+ ## Service Architecture
92
+
93
+ ```
94
+ ContactCenter (cc.ts)
95
+ └── Services (singleton)
96
+ ├── agent/ → Agent operations (login, logout, state)
97
+ ├── task/ → Task operations (hold, transfer, wrapup)
98
+ │ └── TaskManager → Task lifecycle
99
+ ├── config/ → Configuration fetching
100
+ ├── core/ → WebSocket, HTTP, utilities
101
+ ├── AddressBook → Address book entries
102
+ ├── EntryPoint → Entry points
103
+ └── Queue → Queues
104
+ ```
105
+
106
+ ---
107
+
108
+ ## Service-Level AI Docs
109
+
110
+ Each service folder contains its own `ai-docs/` with:
111
+ - `AGENTS.md` - Usage examples, API reference, quick start
112
+ - `ARCHITECTURE.md` - Technical details, sequence diagrams, data flow
113
+
114
+ | Service | AGENTS.md | ARCHITECTURE.md |
115
+ |---------|-----------|-----------------|
116
+ | Agent | [`src/services/agent/ai-docs/AGENTS.md`](../src/services/agent/ai-docs/AGENTS.md) | [`src/services/agent/ai-docs/ARCHITECTURE.md`](../src/services/agent/ai-docs/ARCHITECTURE.md) |
117
+ | Task | [`src/services/task/ai-docs/AGENTS.md`](../src/services/task/ai-docs/AGENTS.md) | [`src/services/task/ai-docs/ARCHITECTURE.md`](../src/services/task/ai-docs/ARCHITECTURE.md) |
118
+ | Config | [`src/services/config/ai-docs/AGENTS.md`](../src/services/config/ai-docs/AGENTS.md) | [`src/services/config/ai-docs/ARCHITECTURE.md`](../src/services/config/ai-docs/ARCHITECTURE.md) |
119
+ | Core | [`src/services/core/ai-docs/AGENTS.md`](../src/services/core/ai-docs/AGENTS.md) | [`src/services/core/ai-docs/ARCHITECTURE.md`](../src/services/core/ai-docs/ARCHITECTURE.md) |
120
+
121
+ ---
122
+
123
+ ## Contributing to AI Docs
124
+
125
+ When adding new features:
126
+ 1. Update the relevant service's docs (use the table above to find the right file):
127
+ - Service `AGENTS.md` — if usage/API surface changed
128
+ - Service `ARCHITECTURE.md` — if data flow or architecture changed
129
+ 2. Add new patterns to [`patterns/`](patterns/) if introducing new patterns
130
+ 3. Update [`templates/`](templates/) if the workflow changes
131
+ 4. Update the root [`AGENTS.md`](../AGENTS.md) if task routing or critical rules changed