@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,346 @@
1
+ # New Service - Code Generation
2
+
3
+ > **Purpose**: Generate the service class file, types, and constants following existing codebase patterns.
4
+
5
+ ---
6
+
7
+ ## File Structure
8
+
9
+ Based on the placement decision from pre-questions (Q3), follow the pattern that matches existing services:
10
+
11
+ ### Folder-based service (complex services like `agent/`, `config/`, `task/`)
12
+ ```
13
+ src/services/ServiceName/
14
+ ├── index.ts # Service class (main entry point)
15
+ ├── types.ts # Type definitions for this service
16
+ └── constants.ts # Constants and enums (optional — only if needed)
17
+ ```
18
+
19
+ **When to use**: The service has multiple files, sub-modules, or significant type/constant definitions. Examples: `agent/` (index.ts + types.ts), `config/` (index.ts + types.ts + constants.ts + Util.ts), `task/` (TaskManager.ts + Task.ts + types.ts + constants.ts + sub-folders).
20
+
21
+ ### Single-file service (lightweight services like `AddressBook.ts`, `EntryPoint.ts`, `Queue.ts`)
22
+ ```
23
+ src/services/ServiceName.ts # Service class in a single file
24
+ ```
25
+
26
+ - Types go in the **root** `src/types.ts` (where `AddressBookEntry`, `EntryPointRecord`, etc. are defined)
27
+ - Shared constants go in `src/services/constants.ts`
28
+ - Service-specific METHODS can go in `src/constants.ts` or inline
29
+
30
+ **When to use**: The service is a straightforward API wrapper (REST calls, pagination, caching) without sub-modules or complex event handling.
31
+
32
+ ### Sub-module under existing service (like `task/Voice.ts`, `task/Digital.ts`)
33
+ ```
34
+ src/services/{ParentService}/ServiceName.ts # Single file within parent folder
35
+ ```
36
+
37
+ - Types go in the parent service's `types.ts` (e.g., `task/types.ts`)
38
+ - Constants go in the parent service's `constants.ts` (e.g., `task/constants.ts`)
39
+
40
+ ---
41
+
42
+ ## Step 1: Type Definitions
43
+
44
+ Based on placement:
45
+
46
+ ### For folder-based services → create `types.ts` in the service folder
47
+
48
+ ```typescript
49
+ // src/services/ServiceName/types.ts
50
+
51
+ /**
52
+ * [Description — from pre-questions Q4 response structure]
53
+ * @public
54
+ */
55
+ export type ServiceResponse = {
56
+ /** [field description] */
57
+ fieldName: string;
58
+ // Define fields to match the exact API response from pre-questions Q4
59
+ };
60
+
61
+ /**
62
+ * [Description — from pre-questions Q4 request payload]
63
+ * @public
64
+ */
65
+ export type ServiceRequest = {
66
+ /** [required field — from Q4] */
67
+ requiredField: string;
68
+ /** [optional field — from Q4] */
69
+ optionalField?: number;
70
+ };
71
+
72
+ // Add event payload types from Q5 if applicable
73
+ // Add one type per API endpoint's request and response (from Q4)
74
+ // Use Pick, Partial, Omit for derived types (see typescript-patterns.md)
75
+ ```
76
+
77
+ ### For single-file services → add types to `src/types.ts`
78
+
79
+ Follow the existing pattern — `AddressBookEntry`, `EntryPointRecord`, `ContactServiceQueue` are all defined in `src/types.ts`:
80
+
81
+ ```typescript
82
+ // src/types.ts (add alongside existing types)
83
+
84
+ /**
85
+ * [Description]
86
+ * @public
87
+ */
88
+ export interface ServiceItem {
89
+ /** [field description] */
90
+ id: string;
91
+ name: string;
92
+ }
93
+
94
+ export type ServiceListResponse = PaginatedResponse<ServiceItem>;
95
+
96
+ export interface ServiceSearchParams extends BaseSearchParams {
97
+ // Add service-specific search fields
98
+ }
99
+ ```
100
+
101
+ ### For sub-modules → add types to parent's `types.ts`
102
+
103
+ Add types to the parent service's types file (e.g., `task/types.ts`).
104
+
105
+ ---
106
+
107
+ ## Step 2: Constants (if needed)
108
+
109
+ ### STOP — Validate Before Creating Any Constants
110
+
111
+ **Before defining any new constant, search the existing constants hierarchy to check if it already exists or belongs at a shared level.** Constants are defined at multiple levels — adding duplicates or placing them at the wrong level creates drift.
112
+
113
+ #### Constants Hierarchy (search in this order)
114
+
115
+ | Level | File | What lives here | Examples |
116
+ |---|---|---|---|
117
+ | **Root** | `src/constants.ts` | SDK-wide file names, method names, global settings | `CC_FILE`, `TASK_FILE`, `READY`, `METHODS`, `TIMEOUT_DURATION` |
118
+ | **Services shared** | `src/services/constants.ts` | API gateways, auth, network constants shared across services | `WCC_API_GATEWAY`, `POST_AUTH`, `WEBSOCKET_EVENT_TIMEOUT` |
119
+ | **Metrics** | `src/metrics/constants.ts` | All metric event names | `METRIC_EVENT_NAMES` (single object with all events) |
120
+ | **Config** | `src/services/config/constants.ts` | Endpoint maps, pagination defaults, agent states | `endPointMap`, `DEFAULT_PAGE_SIZE`, `AGENT_STATE_AVAILABLE` |
121
+ | **Service-specific** | `src/services/{ServiceName}/constants.ts` | Constants used only within that service | `TASK_API`, `HOLD`, `KEEPALIVE_WORKER_INTERVAL` |
122
+
123
+ #### Validation Steps
124
+
125
+ For **each** constant the new service needs:
126
+
127
+ 1. **Search existing files**: Grep for the constant name or value across all `constants.ts` files
128
+ 2. **If found** → import from that file. Do NOT redefine it.
129
+ 3. **If not found** → determine the correct level:
130
+ - Is it SDK-wide (file names, method names)? → add to `src/constants.ts`
131
+ - Is it shared across multiple services (API paths, auth)? → add to `src/services/constants.ts`
132
+ - Is it a metric event? → add to `src/metrics/constants.ts` inside `METRIC_EVENT_NAMES`
133
+ - Is it specific to this service only? → add to service-level `constants.ts` (see below)
134
+
135
+ 4. **Only create a new `constants.ts` file** if:
136
+ - The service is folder-based AND
137
+ - The service folder does not already have a `constants.ts` AND
138
+ - There are service-specific constants that don't belong at any shared level
139
+
140
+ ### For folder-based services
141
+
142
+ If service-specific constants are needed after the validation above, add them to the service folder's `constants.ts`:
143
+
144
+ ```typescript
145
+ // src/services/ServiceName/constants.ts
146
+
147
+ /**
148
+ * Module identifier for logging
149
+ * @private
150
+ */
151
+ export const SERVICE_FILE = 'ServiceName';
152
+
153
+ /**
154
+ * Method names for consistent logging
155
+ * @private
156
+ */
157
+ export const METHODS = {
158
+ METHOD_ONE: 'methodOne',
159
+ METHOD_TWO: 'methodTwo',
160
+ // One entry per method from pre-questions Q8
161
+ } as const;
162
+
163
+ // Add event constants if applicable (from Q5):
164
+ // export const SERVICE_NAME_EVENTS = {
165
+ // SOME_EVENT: 'SomeEvent',
166
+ // } as const;
167
+ ```
168
+
169
+ > **Note**: Not all folder-based services have `constants.ts` — `agent/` has only `index.ts` + `types.ts`. Only create it if there are constants that don't belong at a shared level.
170
+
171
+ ### For single-file services → add to existing shared constants files
172
+
173
+ Do NOT create a new file. Add constants to the appropriate shared file based on the hierarchy above:
174
+
175
+ - File/method names: `src/constants.ts`
176
+ - API/network constants: `src/services/constants.ts`
177
+ - Metric event names: `src/metrics/constants.ts`
178
+ - Endpoint maps: `src/services/config/constants.ts`
179
+
180
+ ### For sub-modules → add to parent's `constants.ts`
181
+
182
+ Check the parent service's `constants.ts` first. Only add if the constant doesn't already exist there.
183
+
184
+ ---
185
+
186
+ ## Step 3: Service Class
187
+
188
+ ### For folder-based services → `index.ts`
189
+
190
+ ```typescript
191
+ // src/services/ServiceName/index.ts
192
+
193
+ import {WebexSDK} from '../../types';
194
+ import LoggerProxy from '../../logger-proxy';
195
+ import {getErrorDetails} from '../core/Utils';
196
+ import {Failure} from '../core/GlobalTypes';
197
+ import MetricsManager from '../../metrics/MetricsManager';
198
+ import {METRIC_EVENT_NAMES} from '../../metrics/constants';
199
+ import {SERVICE_FILE, METHODS} from './constants'; // or define inline if no constants.ts
200
+ import {ServiceResponse, ServiceRequest} from './types';
201
+
202
+ /**
203
+ * [Service purpose — from pre-questions Q2].
204
+ *
205
+ * @description
206
+ * This service handles:
207
+ * - [capability 1 — from Q8]
208
+ * - [capability 2]
209
+ *
210
+ * @example
211
+ * ```typescript
212
+ * // Adapt based on exposure decision (Q7)
213
+ * const result = await cc.serviceName.methodOne(params);
214
+ * ```
215
+ *
216
+ * @public
217
+ */
218
+ export default class ServiceName {
219
+ private webex: WebexSDK;
220
+ private metricsManager: MetricsManager;
221
+
222
+ constructor(webex: WebexSDK) {
223
+ this.webex = webex;
224
+ this.metricsManager = MetricsManager.getInstance();
225
+ // Add constructor params based on dependencies (Q6)
226
+ }
227
+
228
+ /**
229
+ * [Method description — from Q8].
230
+ *
231
+ * @param {ServiceRequest} data - [from Q4]
232
+ * @returns {Promise<ServiceResponse>} [from Q4]
233
+ * @throws {Error} If the request fails
234
+ * @public
235
+ */
236
+ public async methodOne(data: ServiceRequest): Promise<ServiceResponse> {
237
+ this.metricsManager.timeEvent([
238
+ METRIC_EVENT_NAMES.METHOD_ONE_SUCCESS,
239
+ METRIC_EVENT_NAMES.METHOD_ONE_FAILED,
240
+ ]);
241
+
242
+ LoggerProxy.info('Starting methodOne', {
243
+ module: SERVICE_FILE,
244
+ method: METHODS.METHOD_ONE,
245
+ });
246
+
247
+ try {
248
+ // === Implement based on Q4 API contract ===
249
+ // For REST services: use webex.request or WebexRequest
250
+ // For AQM services: use routing.req pattern (see agent/index.ts)
251
+
252
+ const result = {} as ServiceResponse; // Replace with actual implementation
253
+
254
+ this.metricsManager.trackEvent(
255
+ METRIC_EVENT_NAMES.METHOD_ONE_SUCCESS,
256
+ { /* tracking fields */ },
257
+ ['behavioral', 'operational']
258
+ );
259
+
260
+ return result;
261
+ } catch (error) {
262
+ const failure = error.details as Failure;
263
+ this.metricsManager.trackEvent(
264
+ METRIC_EVENT_NAMES.METHOD_ONE_FAILED,
265
+ MetricsManager.getCommonTrackingFieldForAQMResponseFailed(failure),
266
+ ['operational']
267
+ );
268
+
269
+ const {error: detailedError} = getErrorDetails(
270
+ error,
271
+ METHODS.METHOD_ONE,
272
+ SERVICE_FILE
273
+ );
274
+
275
+ throw detailedError;
276
+ }
277
+ }
278
+ }
279
+ ```
280
+
281
+ ### For single-file services → follow existing `AddressBook.ts` / `EntryPoint.ts` pattern
282
+
283
+ ```typescript
284
+ // src/services/ServiceName.ts
285
+
286
+ import {HTTP_METHODS, WebexSDK} from '../types';
287
+ import type {ServiceItem, ServiceListResponse, ServiceSearchParams} from '../types';
288
+ import LoggerProxy from '../logger-proxy';
289
+ import WebexRequest from './core/WebexRequest';
290
+ import MetricsManager from '../metrics/MetricsManager';
291
+ import {WCC_API_GATEWAY} from './constants';
292
+ import {endPointMap} from './config/constants';
293
+ import {METRIC_EVENT_NAMES} from '../metrics/constants';
294
+
295
+ // Follow the exact same class structure as AddressBook.ts or EntryPoint.ts
296
+ // Key patterns from existing single-file services:
297
+ // - Use WebexRequest for HTTP calls (not raw webex.request)
298
+ // - Import types from src/types.ts
299
+ // - Import shared constants from services/constants.ts and config/constants.ts
300
+ // - Use MetricsManager for tracking
301
+ // - Use PageCache if paginated (import from ../utils/PageCache)
302
+ ```
303
+
304
+ ### For sub-modules → single file in parent folder
305
+
306
+ ```typescript
307
+ // src/services/{ParentService}/ServiceName.ts
308
+
309
+ // Import from parent-relative paths
310
+ import {WebexSDK} from '../../types';
311
+ import LoggerProxy from '../../logger-proxy';
312
+ // Types and constants from parent's files
313
+ import {ServiceType} from './types';
314
+ import {SOME_CONSTANT} from './constants';
315
+
316
+ // Example: sub-module class structure (see task/Voice.ts or task/Digital.ts for reference)
317
+ export default class ServiceName {
318
+ private webex: WebexSDK;
319
+
320
+ constructor(webex: WebexSDK) {
321
+ this.webex = webex;
322
+ }
323
+
324
+ // Methods follow the same patterns as top-level services
325
+ // but may receive parent service state/context via constructor or method params
326
+ }
327
+ ```
328
+
329
+ ---
330
+
331
+ ## Customization Based on Service Type
332
+
333
+ ### AQM-based service (like `agent/index.ts`)
334
+ Uses the factory function + `routing.req` pattern. See `services/agent/index.ts` for the complete pattern.
335
+
336
+ ### REST API service (like `AddressBook.ts`, `EntryPoint.ts`)
337
+ Uses `WebexRequest` for HTTP calls, `PageCache` for pagination. Study the existing implementations directly.
338
+
339
+ ### Event-driven service
340
+ If the service processes WebSocket events (from Q5), follow the event patterns in `event-driven-patterns.md`.
341
+
342
+ ---
343
+
344
+ ## Next Step
345
+
346
+ Proceed to: [`03-integration.md`](03-integration.md)
@@ -0,0 +1,178 @@
1
+ # New Service - Integration
2
+
3
+ > **Purpose**: Integrate the new service into the SDK based on its placement decision.
4
+
5
+ ---
6
+
7
+ ## Choose Integration Path
8
+
9
+ Based on the placement decision from pre-questions (Q3):
10
+
11
+ | Placement | Integration point | Types location | Constants location |
12
+ |---|---|---|---|
13
+ | **Folder-based** | `cc.ts` or `Services` singleton | Service folder's `types.ts` | Service folder's `constants.ts` |
14
+ | **Single-file** | `cc.ts` directly | Root `src/types.ts` | `src/services/constants.ts` |
15
+ | **Sub-module** | Parent service | Parent's `types.ts` | Parent's `constants.ts` |
16
+
17
+ ---
18
+
19
+ ## Path A: Folder-Based Service Integration
20
+
21
+ Study how existing folder-based services are wired in:
22
+ - **AQM services** (`agent`, `contact`, `dialer`): instantiated via the `Services` singleton in `src/services/index.ts`
23
+ - **Config service**: instantiated in `Services` singleton as `AgentConfigService`
24
+ - **Non-AQM services**: can be instantiated directly in `cc.ts`
25
+
26
+ ### Step A1: If AQM-based — add to Services singleton
27
+
28
+ In `src/services/index.ts`:
29
+
30
+ ```typescript
31
+ import routingServiceName from './ServiceName';
32
+
33
+ export default class Services {
34
+ public readonly serviceName: ReturnType<typeof routingServiceName>;
35
+
36
+ constructor(options: {...}) {
37
+ // ... existing initialization
38
+ this.serviceName = routingServiceName(aqmReq);
39
+ }
40
+ }
41
+ ```
42
+
43
+ Then access via `this.services.serviceName` from `cc.ts`.
44
+
45
+ ### Step A2: If non-AQM — instantiate in cc.ts
46
+
47
+ ```typescript
48
+ import ServiceName from './services/ServiceName';
49
+
50
+ export default class ContactCenter extends WebexPlugin implements IContactCenter {
51
+ public serviceName: ServiceName; // or private if internal (Q7)
52
+
53
+ // In $webex.once(READY, ...) block:
54
+ this.serviceName = new ServiceName(this.$webex);
55
+ }
56
+ ```
57
+
58
+ ### Step A3: Export types (if public — Q7)
59
+
60
+ Types stay in the service folder's `types.ts`. Re-export from `src/types.ts`:
61
+
62
+ ```typescript
63
+ // src/types.ts
64
+ export type {ServiceResponse, ServiceRequest} from './services/ServiceName/types';
65
+ ```
66
+
67
+ ---
68
+
69
+ ## Path B: Single-File Service Integration
70
+
71
+ Follow the exact pattern of `AddressBook`, `EntryPoint`, `Queue`:
72
+
73
+ ### Step B1: Import and add property in cc.ts
74
+
75
+ ```typescript
76
+ import ServiceName from './services/ServiceName';
77
+
78
+ export default class ContactCenter extends WebexPlugin implements IContactCenter {
79
+ /**
80
+ * [Service purpose — from Q2]
81
+ * @type {ServiceName}
82
+ * @public
83
+ */
84
+ public serviceName: ServiceName;
85
+ ```
86
+
87
+ ### Step B2: Initialize in constructor
88
+
89
+ In the `$webex.once(READY, ...)` block:
90
+
91
+ ```typescript
92
+ this.$webex.once(READY, () => {
93
+ // ... existing initialization
94
+
95
+ this.serviceName = new ServiceName(this.$webex);
96
+
97
+ // If service needs profile dependency (Q6):
98
+ // this.serviceName = new ServiceName(
99
+ // this.$webex,
100
+ // () => this.agentConfig?.someProfileField
101
+ // );
102
+ });
103
+ ```
104
+
105
+ ### Step B3: Types already in src/types.ts
106
+
107
+ Since single-file service types are defined in `src/types.ts` (Step 1 of code generation), they're already available to consumers. No separate re-export needed.
108
+
109
+ ---
110
+
111
+ ## Path C: Sub-Module Integration
112
+
113
+ ### Step C1: Instantiate in parent service
114
+
115
+ In the parent service file (e.g., `TaskManager.ts`):
116
+
117
+ ```typescript
118
+ import ServiceName from './ServiceName';
119
+
120
+ // As a property
121
+ private serviceName: ServiceName;
122
+
123
+ // In constructor or init method
124
+ this.serviceName = new ServiceName(this.webex);
125
+ ```
126
+
127
+ ### Step C2: Expose through parent if needed
128
+
129
+ If the sub-module's methods should be callable through the parent service:
130
+
131
+ ```typescript
132
+ public async methodThatUsesSubModule(data: SomeType): Promise<SomeResponse> {
133
+ return this.serviceName.methodOne(data);
134
+ }
135
+ ```
136
+
137
+ ### Step C3: Types in parent's types.ts
138
+
139
+ Since sub-module types are defined in the parent's `types.ts` (from code generation), they're already available. Re-export from `src/types.ts` if the sub-module is public.
140
+
141
+ ---
142
+
143
+ ## Add Metric Event Names
144
+
145
+ For all placement types, add new metric events to `src/metrics/constants.ts`:
146
+
147
+ ```typescript
148
+ export const METRIC_EVENT_NAMES = {
149
+ // ... existing events
150
+ METHOD_ONE_SUCCESS: 'method one success',
151
+ METHOD_ONE_FAILED: 'method one failed',
152
+ } as const;
153
+ ```
154
+
155
+ ---
156
+
157
+ ## Verification
158
+
159
+ After integration, verify:
160
+
161
+ ```typescript
162
+ // For public top-level / single-file service:
163
+ const cc = webex.cc;
164
+ await cc.register();
165
+ const result = await cc.serviceName.methodOne(params);
166
+
167
+ // For AQM service accessed through Services:
168
+ // Verify through cc.ts methods that delegate to this.services.serviceName
169
+
170
+ // For sub-module:
171
+ // Verify through parent service's API or internal tests
172
+ ```
173
+
174
+ ---
175
+
176
+ ## Next Step
177
+
178
+ Proceed to: [`04-test-generation.md`](04-test-generation.md)