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

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 +570 -535
  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 +372 -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 +263 -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 +377 -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 +579 -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 +422 -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 +303 -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 +542 -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,365 @@
1
+ # TypeScript Patterns - Contact Center SDK
2
+
3
+ > **Purpose**: TypeScript conventions and patterns specific to the Contact Center SDK.
4
+
5
+ ---
6
+
7
+ ## Type Definition Patterns
8
+
9
+ ### Const Object + Type Pattern (for Enums)
10
+
11
+ The SDK uses const objects instead of TypeScript enums for better tree-shaking and runtime access:
12
+
13
+ ```typescript
14
+ // Step 1: Define const object
15
+ export const CC_EVENTS = {
16
+ AGENT_LOGIN: 'AgentLogin',
17
+ AGENT_LOGOUT: 'AgentLogout',
18
+ AGENT_STATE_CHANGE: 'AgentStateChange',
19
+ } as const;
20
+
21
+ // Step 2: Create union type from values
22
+ type Enum<T extends Record<string, unknown>> = T[keyof T];
23
+ export type CC_EVENTS = Enum<typeof CC_EVENTS>;
24
+
25
+ // Usage:
26
+ const event: CC_EVENTS = CC_EVENTS.AGENT_LOGIN; // ✅ Type-safe
27
+ const event2: CC_EVENTS = 'InvalidEvent'; // ❌ Compile error
28
+ ```
29
+
30
+ ### Failure Type Pattern
31
+
32
+ Error responses use the `Failure` type:
33
+
34
+ ```typescript
35
+ // From services/core/GlobalTypes.ts
36
+
37
+ // Base message type — all WebSocket messages extend this
38
+ export type Msg<T = any> = {
39
+ type: string;
40
+ orgId: string;
41
+ trackingId: string;
42
+ data: T;
43
+ };
44
+
45
+ // Failure wraps error details inside Msg
46
+ export type Failure = Msg<{
47
+ agentId: string;
48
+ trackingId: string;
49
+ reasonCode: number;
50
+ orgId: string;
51
+ reason: string;
52
+ }>;
53
+
54
+ // Usage in catch blocks:
55
+ const failure = error.details as Failure;
56
+ // Access: failure.trackingId, failure.data.reason, failure.data.reasonCode
57
+ LoggerProxy.error(`Operation failed`, {
58
+ module: CC_FILE,
59
+ method: 'methodName',
60
+ trackingId: failure.trackingId,
61
+ });
62
+ ```
63
+
64
+ ---
65
+
66
+ ## Naming Conventions
67
+
68
+ ### Files
69
+
70
+ | Type | Convention | Example |
71
+ |------|------------|---------|
72
+ | Class files | PascalCase | `TaskManager.ts`, `WebSocketManager.ts` |
73
+ | Type files | lowercase | `types.ts` |
74
+ | Constant files | lowercase | `constants.ts` |
75
+ | Index files | lowercase | `index.ts` |
76
+ | Utility files | PascalCase | `Utils.ts`, `Err.ts` |
77
+
78
+ ### Code Elements
79
+
80
+ ```typescript
81
+ // Classes: PascalCase
82
+ class ContactCenter { }
83
+ class TaskManager { }
84
+
85
+ // Interfaces: PascalCase with I prefix for contracts
86
+ // (e.g., IContactCenter, ITask, IVoice, IDigital)
87
+ // Types: PascalCase without prefix
88
+ type AgentLogin = { };
89
+ type Profile = { };
90
+
91
+ // Constants: SCREAMING_SNAKE_CASE
92
+ const CC_FILE = 'ContactCenter';
93
+ const METRIC_EVENT_NAMES = { };
94
+
95
+ // Methods: camelCase
96
+ public async stationLogin() { }
97
+ private handleWebsocketMessage() { }
98
+
99
+ // Properties: camelCase
100
+ private agentConfig: Profile;
101
+ private eventEmitter: EventEmitter;
102
+
103
+ // SDK references: $ prefix
104
+ private $webex: WebexSDK;
105
+ private $config: CCPluginConfig;
106
+ ```
107
+
108
+ ---
109
+
110
+ ## Import Patterns
111
+
112
+ ### Import Order
113
+
114
+ ```typescript
115
+ // 1. External packages
116
+ import {WebexPlugin} from '@webex/webex-core';
117
+ import EventEmitter from 'events';
118
+ import {v4 as uuidv4} from 'uuid';
119
+
120
+ // 2. Package-level imports (types, constants)
121
+ import {
122
+ WebexSDK,
123
+ CCPluginConfig,
124
+ AgentLogin,
125
+ StationLoginResponse,
126
+ } from './types';
127
+ import {READY, CC_FILE, METHODS} from './constants';
128
+
129
+ // 3. Service imports
130
+ import Services from './services';
131
+ import LoggerProxy from './logger-proxy';
132
+
133
+ // 4. Utility imports
134
+ import {getErrorDetails} from './services/core/Utils';
135
+ import {Failure} from './services/core/GlobalTypes';
136
+
137
+ // 5. Type-only imports (when applicable)
138
+ import type {Profile} from './services/config/types';
139
+ ```
140
+
141
+ ### Re-exports
142
+
143
+ ```typescript
144
+ // types.ts - Central export file
145
+ export {Profile, CC_EVENTS} from './services/config/types';
146
+ export {AGENT_EVENTS, StationLoginSuccess} from './services/agent/types';
147
+ export {TASK_EVENTS, ITask} from './services/task/types';
148
+ ```
149
+
150
+ ---
151
+
152
+ ## Type Derivation Patterns
153
+
154
+ ### Pick for Subset Types
155
+
156
+ ```typescript
157
+ // Original type
158
+ type FullProfile = {
159
+ agentId: string;
160
+ teamId: string;
161
+ state: string;
162
+ dialNumber: string;
163
+ permissions: string[];
164
+ };
165
+
166
+ // Derived subset
167
+ type LoginInfo = Pick<FullProfile, 'agentId' | 'teamId' | 'dialNumber'>;
168
+ ```
169
+
170
+ ### Partial for Optional Updates
171
+
172
+ ```typescript
173
+ type AgentUpdate = Partial<AgentProfile>;
174
+
175
+ // Usage: all fields optional
176
+ function updateAgent(update: AgentUpdate) {
177
+ // Only specified fields will be updated
178
+ }
179
+ ```
180
+
181
+ ### Omit for Exclusion
182
+
183
+ ```typescript
184
+ type PublicProfile = Omit<FullProfile, 'permissions' | 'internalId'>;
185
+ ```
186
+
187
+ ---
188
+
189
+ ## Generic Patterns
190
+
191
+ ### Type Parameter for Response Data
192
+
193
+ ```typescript
194
+ // Generic request handler
195
+ async function request<T>(config: RequestConfig): Promise<ApiResponse<T>> {
196
+ const response = await fetch(config.url);
197
+ return response.json() as ApiResponse<T>;
198
+ }
199
+
200
+ // Usage with specific type
201
+ const result = await request<AgentData>(config);
202
+ // result.data is typed as AgentData
203
+ ```
204
+
205
+ ### Conditional Types (Advanced)
206
+
207
+ ```typescript
208
+ // Used in event handling
209
+ type EventDataMap = {
210
+ [CC_EVENTS.AGENT_LOGIN]: LoginData;
211
+ [CC_EVENTS.AGENT_LOGOUT]: LogoutData;
212
+ [CC_EVENTS.AGENT_STATE_CHANGE]: StateChangeData;
213
+ };
214
+
215
+ type EventData<T extends CC_EVENTS> = EventDataMap[T];
216
+ ```
217
+
218
+ ---
219
+
220
+ ## JSDoc Patterns
221
+
222
+ ### Public API Documentation
223
+
224
+ ```typescript
225
+ /**
226
+ * Logs the agent into their assigned station.
227
+ *
228
+ * @description
229
+ * This method authenticates the agent and establishes their connection
230
+ * to the Contact Center system. The agent must be registered before
231
+ * calling this method.
232
+ *
233
+ * @param {AgentLogin} data - Login configuration
234
+ * @param {string} data.teamId - Team to log into
235
+ * @param {LoginOption} data.loginOption - Device type (BROWSER, EXTENSION, AGENT_DN)
236
+ * @param {string} [data.dialNumber] - Required for EXTENSION/AGENT_DN
237
+ *
238
+ * @returns {Promise<StationLoginResponse>} Login result with session info
239
+ *
240
+ * @throws {Error} If login fails with reason in error.data.reason
241
+ *
242
+ * @fires agent:stationLoginSuccess When login succeeds
243
+ * @fires agent:stationLoginFailed When login fails
244
+ *
245
+ * @public
246
+ *
247
+ * @example
248
+ * ```typescript
249
+ * // Browser-based login
250
+ * const result = await cc.stationLogin({
251
+ * teamId: 'team-123',
252
+ * loginOption: 'BROWSER',
253
+ * });
254
+ *
255
+ * // Extension-based login
256
+ * const result = await cc.stationLogin({
257
+ * teamId: 'team-123',
258
+ * loginOption: 'EXTENSION',
259
+ * dialNumber: '1234',
260
+ * });
261
+ * ```
262
+ */
263
+ public async stationLogin(data: AgentLogin): Promise<StationLoginResponse> {
264
+ // Implementation
265
+ }
266
+ ```
267
+
268
+ ### Type Documentation
269
+
270
+ ```typescript
271
+ /**
272
+ * Configuration for agent login operation.
273
+ *
274
+ * @public
275
+ */
276
+ export type AgentLogin = {
277
+ /**
278
+ * The team ID to log into.
279
+ * Must be a valid team from the agent's profile.
280
+ */
281
+ teamId: string;
282
+
283
+ /**
284
+ * Device type for the login.
285
+ * - BROWSER: WebRTC-based softphone
286
+ * - EXTENSION: Desk phone extension
287
+ * - AGENT_DN: Direct dial number
288
+ */
289
+ loginOption: LoginOption;
290
+
291
+ /**
292
+ * Phone number or extension.
293
+ * Required when loginOption is EXTENSION or AGENT_DN.
294
+ */
295
+ dialNumber?: string;
296
+ };
297
+ ```
298
+
299
+ ---
300
+
301
+ ## Async Patterns
302
+
303
+ ### Standard Async/Await
304
+
305
+ ```typescript
306
+ // Preferred pattern
307
+ public async fetchData(): Promise<Data> {
308
+ try {
309
+ const result = await this.service.getData();
310
+ return result;
311
+ } catch (error) {
312
+ // Handle error
313
+ throw error;
314
+ }
315
+ }
316
+ ```
317
+
318
+ ### Promise Chaining (When Necessary)
319
+
320
+ ```typescript
321
+ // Used in some initialization flows
322
+ this.$webex.once(READY, () => {
323
+ this.services = Services.getInstance({...});
324
+
325
+ this.services.webSocketManager
326
+ .initWebSocket({body: config})
327
+ .then((data) => {
328
+ // Handle success
329
+ })
330
+ .catch((error) => {
331
+ // Handle error
332
+ });
333
+ });
334
+ ```
335
+
336
+ ---
337
+
338
+ ## Type Guards
339
+
340
+ ### Type Narrowing
341
+
342
+ ```typescript
343
+ // Check for specific error type
344
+ function isFailure(error: unknown): error is {details: Failure} {
345
+ return (
346
+ typeof error === 'object' &&
347
+ error !== null &&
348
+ 'details' in error
349
+ );
350
+ }
351
+
352
+ // Usage
353
+ if (isFailure(error)) {
354
+ const failure = error.details;
355
+ // TypeScript knows failure is Failure type
356
+ }
357
+ ```
358
+
359
+ ### Event Type Guards
360
+
361
+ ```typescript
362
+ function isAgentEvent(event: CC_EVENTS): event is keyof typeof CC_AGENT_EVENTS {
363
+ return Object.values(CC_AGENT_EVENTS).includes(event as any);
364
+ }
365
+ ```
@@ -0,0 +1,102 @@
1
+ # Contact Center SDK - Templates
2
+
3
+ > **Purpose**: Code generation templates for AI agents to create, modify, and document SDK components.
4
+
5
+ ---
6
+
7
+ ## Template Categories
8
+
9
+ | Category | Purpose | Use When |
10
+ |----------|---------|----------|
11
+ | **new-service/** | Creating new services (like AddressBook, Queue) | Adding new data/API services |
12
+ | **new-method/** | Adding methods to existing services | Extending service capabilities |
13
+ | **existing-service/** | Bug fixes, feature enhancements, and modifications to existing methods | Modifying existing code |
14
+ | **documentation/** | Generating AGENTS.md and ARCHITECTURE.md | Creating service-level docs |
15
+
16
+ ---
17
+
18
+ ## Template Directory Structure
19
+
20
+ ```
21
+ templates/
22
+ ├── README.md # This file
23
+ ├── new-service/ # New service creation
24
+ │ ├── 00-master.md # Orchestrator
25
+ │ ├── 01-pre-questions.md # Requirements gathering (STOP gate)
26
+ │ ├── 02-code-generation.md # Service class generation
27
+ │ ├── 03-integration.md # Registration and exports
28
+ │ ├── 04-test-generation.md # Test file generation
29
+ │ └── 05-validation.md # Quality checklist
30
+ ├── new-method/ # New method addition
31
+ │ ├── 00-master.md # Orchestrator
32
+ │ ├── 01-requirements.md # Method requirements (STOP gate)
33
+ │ ├── 02-implementation.md # Code implementation
34
+ │ ├── 03-tests.md # Test generation
35
+ │ └── 04-validation.md # Quality checklist
36
+ ├── existing-service/ # Modifications
37
+ │ ├── bug-fix.md # Bug fix workflow (STOP gate in Section A)
38
+ │ └── feature-enhancement.md # Feature addition / modify existing method (STOP gate in Step 0)
39
+ └── documentation/ # Doc generation
40
+ ├── create-agents-md.md # AGENTS.md template
41
+ └── create-architecture-md.md # ARCHITECTURE.md template
42
+ ```
43
+
44
+ ---
45
+
46
+ ## Quick Reference
47
+
48
+ ### Creating a New Service (Task Type A)
49
+ Start with: [`new-service/00-master.md`](new-service/00-master.md)
50
+
51
+ ### Adding a New Method (Task Type B)
52
+ Start with: [`new-method/00-master.md`](new-method/00-master.md)
53
+
54
+ ### Fixing a Bug (Task Type C)
55
+ Use: [`existing-service/bug-fix.md`](existing-service/bug-fix.md)
56
+
57
+ ### Adding a Feature (Task Type D)
58
+ Start with: [`existing-service/feature-enhancement.md`](existing-service/feature-enhancement.md)
59
+
60
+ **Important:** Feature template includes a mandatory placement triage:
61
+ - if feature fits existing service -> continue feature-enhancement flow
62
+ - if feature needs standalone ownership -> reroute to [`new-service/00-master.md`](new-service/00-master.md)
63
+
64
+ ### Modifying an Existing Method (Task Type F)
65
+ Use: [`existing-service/feature-enhancement.md`](existing-service/feature-enhancement.md)
66
+
67
+ **Important:** When modifying an existing method (changing signature, parameters, return type, or behavior), use the feature-enhancement template but **skip Step 0 (Placement Triage)** since the method already exists. Start directly at Step 0B (Pre-Enhancement Questions).
68
+
69
+ ### Creating Service Documentation (Task Type E)
70
+ Use: [`documentation/create-agents-md.md`](documentation/create-agents-md.md)
71
+
72
+ ---
73
+
74
+ ## Template Usage Flow
75
+
76
+ ```
77
+ 1. Classify task using root AGENTS.md decision tree (../../AGENTS.md)
78
+ |
79
+ v
80
+ 2. Route to appropriate template
81
+ |
82
+ v
83
+ 3. STOP — Present pre-questions to developer, wait for answers
84
+ |
85
+ v
86
+ 4. Present Spec Summary to developer, wait for approval
87
+ |
88
+ v
89
+ 5. If task is "Add Feature", run placement triage (existing vs new service)
90
+ |
91
+ v
92
+ 6. Load relevant patterns as specified
93
+ |
94
+ v
95
+ 7. Generate/modify code
96
+ |
97
+ v
98
+ 8. Run validation checklist
99
+ |
100
+ v
101
+ 9. Update documentation if needed
102
+ ```
@@ -0,0 +1,240 @@
1
+ # Create AGENTS.md Template
2
+
3
+ > **Purpose**: Template for generating service-level AGENTS.md files optimized for LLM consumption.
4
+
5
+ ---
6
+
7
+ ## Pre-Generation Questions
8
+
9
+ Answer before writing:
10
+
11
+ 1. **Package/Service Name**: What is this service called?
12
+ 2. **Purpose**: What problem does this service solve? (1-2 sentences)
13
+ 3. **Key Capabilities**: What are the main features? (3-5 bullets)
14
+ 4. **Usage Examples**: What are the most common use cases?
15
+ 5. **API Surface**: What methods/properties are exposed?
16
+ 6. **Dependencies**: What does this service depend on?
17
+
18
+ ---
19
+
20
+ ## AGENTS.md Structure
21
+
22
+ ```markdown
23
+ # [Service Name] - AI Agent Guide
24
+
25
+ > **Purpose**: [One sentence describing what this service does]
26
+
27
+ ---
28
+
29
+ ## Quick Start
30
+
31
+ [3-5 line code example showing most basic usage]
32
+
33
+ ---
34
+
35
+ ## Key Capabilities
36
+
37
+ - [Capability 1]: [Brief description]
38
+ - [Capability 2]: [Brief description]
39
+ - [Capability 3]: [Brief description]
40
+
41
+ ---
42
+
43
+ ## Usage Examples
44
+
45
+ ### [Use Case 1]
46
+ ```typescript
47
+ // Example code
48
+ ```
49
+
50
+ ### [Use Case 2]
51
+ ```typescript
52
+ // Example code
53
+ ```
54
+
55
+ ---
56
+
57
+ ## API Reference
58
+
59
+ ### Properties
60
+
61
+ | Property | Type | Description |
62
+ |----------|------|-------------|
63
+ | `propertyName` | `Type` | Description |
64
+
65
+ ### Methods
66
+
67
+ #### `methodName(params)`
68
+
69
+ Description of what this method does.
70
+
71
+ **Parameters**:
72
+ - `param1` (Type): Description
73
+ - `param2` (Type, optional): Description
74
+
75
+ **Returns**: `Promise<ReturnType>` - Description
76
+
77
+ **Example**:
78
+ ```typescript
79
+ const result = await service.methodName({
80
+ param1: 'value',
81
+ });
82
+ ```
83
+
84
+ ---
85
+
86
+ ## Events (if applicable)
87
+
88
+ | Event | Data | When Emitted |
89
+ |-------|------|--------------|
90
+ | `event:name` | `EventData` | Description |
91
+
92
+ ---
93
+
94
+ ## Common Patterns
95
+
96
+ ### [Pattern Name]
97
+ ```typescript
98
+ // Pattern example
99
+ ```
100
+
101
+ ---
102
+
103
+ ## Error Handling
104
+
105
+ Errors are thrown as `Error` with:
106
+ - `message`: Error description
107
+ - `data.reason`: Error reason code
108
+
109
+ ```typescript
110
+ try {
111
+ await service.method();
112
+ } catch (error) {
113
+ console.error(error.message);
114
+ console.error(error.data?.reason);
115
+ }
116
+ ```
117
+
118
+ ---
119
+
120
+ ## Dependencies
121
+
122
+ - Requires: [dependency description]
123
+ - Used by: [what uses this service]
124
+
125
+ ---
126
+
127
+ ## Related Documentation
128
+
129
+ - [ARCHITECTURE.md](ARCHITECTURE.md) - Technical deep-dive
130
+ - [Pattern files](../../../ai-docs/patterns/) - Coding patterns
131
+ ```
132
+
133
+ ---
134
+
135
+ ## Content Guidelines
136
+
137
+ ### Purpose Section
138
+ - One clear sentence
139
+ - Focus on business value, not implementation
140
+
141
+ ### Quick Start
142
+ - Show the happy path
143
+ - Minimal code to demonstrate value
144
+ - Include all required setup steps
145
+
146
+ ### Examples
147
+ - Use realistic parameter values
148
+ - Show common variations
149
+ - Include error handling when relevant
150
+
151
+ ### API Reference
152
+ - List all public methods
153
+ - Include parameter types and descriptions
154
+ - Show return types
155
+ - Provide example for each method
156
+
157
+ ### Error Handling
158
+ - Document common error scenarios
159
+ - Show how to access error details
160
+
161
+ ---
162
+
163
+ ## Token Optimization Strategy
164
+
165
+ For LLM efficiency:
166
+ 1. **AGENTS.md first**: Contains usage info (most commonly needed)
167
+ 2. **ARCHITECTURE.md linked at end**: For deep technical questions
168
+ 3. **Concise examples**: Just enough to demonstrate
169
+ 4. **Tables for reference**: Quick scanning
170
+
171
+ ---
172
+
173
+ ## Validation Checklist
174
+
175
+ - [ ] Purpose is clear and concise
176
+ - [ ] Quick start works as-is
177
+ - [ ] All public methods documented
178
+ - [ ] Examples are realistic and working
179
+ - [ ] Error handling documented
180
+ - [ ] Links to ARCHITECTURE.md included
181
+ - [ ] No implementation details (save for ARCHITECTURE.md)
182
+
183
+ ---
184
+
185
+ ## Example: Services/Agent AGENTS.md
186
+
187
+ ```markdown
188
+ # Agent Service - AI Agent Guide
189
+
190
+ > **Purpose**: Manage agent lifecycle including login, logout, and state changes.
191
+
192
+ ---
193
+
194
+ ## Quick Start
195
+
196
+ ```typescript
197
+ const cc = webex.cc;
198
+ await cc.register();
199
+
200
+ // Login
201
+ await cc.stationLogin({
202
+ teamId: 'team-123',
203
+ loginOption: 'BROWSER',
204
+ });
205
+
206
+ // Set available
207
+ await cc.setAgentState({
208
+ state: 'Available',
209
+ auxCodeId: '0',
210
+ });
211
+ ```
212
+
213
+ ---
214
+
215
+ ## Key Capabilities
216
+
217
+ - **Station Login**: Login with browser, extension, or dial number
218
+ - **Station Logout**: Logout from current station
219
+ - **State Management**: Change between Available/Idle states
220
+ - **Buddy Agents**: Retrieve list of available agents
221
+
222
+ ---
223
+
224
+ ## API Reference
225
+
226
+ ### `stationLogin(params)`
227
+
228
+ Login agent to a station.
229
+
230
+ **Parameters**:
231
+ - `teamId` (string): Team to login to
232
+ - `loginOption` ('BROWSER' | 'EXTENSION' | 'AGENT_DN'): Device type
233
+ - `dialNumber` (string, optional): Required for EXTENSION/AGENT_DN
234
+
235
+ **Returns**: `Promise<StationLoginResponse>`
236
+
237
+ ---
238
+
239
+ See [ARCHITECTURE.md](ARCHITECTURE.md) for technical details.
240
+ ```