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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/.sdd/manifest.json +876 -0
  2. package/AGENTS.md +94 -0
  3. package/ai-docs/ARCHITECTURE.md +168 -0
  4. package/ai-docs/CONTRACTS.md +46 -0
  5. package/ai-docs/GETTING_STARTED.md +168 -0
  6. package/ai-docs/GLOSSARY.md +43 -0
  7. package/ai-docs/README.md +138 -0
  8. package/ai-docs/REVIEW_CHECKLIST.md +41 -0
  9. package/ai-docs/RULES.md +444 -0
  10. package/ai-docs/SECURITY.md +52 -0
  11. package/ai-docs/SERVICE_STATE.md +48 -0
  12. package/ai-docs/SPEC_INDEX.md +65 -0
  13. package/ai-docs/adr/0001-spec-source-policy.md +55 -0
  14. package/ai-docs/adr/README.md +8 -0
  15. package/ai-docs/adr/_adr-template.md +31 -0
  16. package/ai-docs/contact-center-spec.md +341 -0
  17. package/ai-docs/features/generated-spec-conformance-fidelity-remediation/spec/feature-spec.md +117 -0
  18. package/ai-docs/features/residual-warning-coverage-completion/spec/feature-spec.md +203 -0
  19. package/ai-docs/features/validator-code-fidelity-drift-fix/spec/feature-spec.md +315 -0
  20. package/ai-docs/patterns/event-driven-patterns.md +485 -0
  21. package/ai-docs/patterns/testing-patterns.md +480 -0
  22. package/ai-docs/patterns/typescript-patterns.md +365 -0
  23. package/ai-docs/templates/README.md +102 -0
  24. package/ai-docs/templates/documentation/create-agents-md.md +240 -0
  25. package/ai-docs/templates/documentation/create-architecture-md.md +295 -0
  26. package/ai-docs/templates/existing-service/bug-fix.md +254 -0
  27. package/ai-docs/templates/existing-service/feature-enhancement.md +450 -0
  28. package/ai-docs/templates/new-method/00-master.md +80 -0
  29. package/ai-docs/templates/new-method/01-requirements.md +232 -0
  30. package/ai-docs/templates/new-method/02-implementation.md +295 -0
  31. package/ai-docs/templates/new-method/03-tests.md +201 -0
  32. package/ai-docs/templates/new-method/04-validation.md +141 -0
  33. package/ai-docs/templates/new-service/00-master.md +109 -0
  34. package/ai-docs/templates/new-service/01-pre-questions.md +159 -0
  35. package/ai-docs/templates/new-service/02-code-generation.md +346 -0
  36. package/ai-docs/templates/new-service/03-integration.md +178 -0
  37. package/ai-docs/templates/new-service/04-test-generation.md +205 -0
  38. package/ai-docs/templates/new-service/05-validation.md +145 -0
  39. package/dist/cc.js +265 -29
  40. package/dist/cc.js.map +1 -1
  41. package/dist/config.js +6 -0
  42. package/dist/config.js.map +1 -1
  43. package/dist/constants.js +17 -1
  44. package/dist/constants.js.map +1 -1
  45. package/dist/index.js +20 -5
  46. package/dist/index.js.map +1 -1
  47. package/dist/metrics/behavioral-events.js +101 -0
  48. package/dist/metrics/behavioral-events.js.map +1 -1
  49. package/dist/metrics/constants.js +25 -4
  50. package/dist/metrics/constants.js.map +1 -1
  51. package/dist/services/ApiAiAssistant.js +153 -8
  52. package/dist/services/ApiAiAssistant.js.map +1 -1
  53. package/dist/services/UserPreference.js +427 -0
  54. package/dist/services/UserPreference.js.map +1 -0
  55. package/dist/services/config/Util.js +3 -3
  56. package/dist/services/config/Util.js.map +1 -1
  57. package/dist/services/config/constants.js +23 -2
  58. package/dist/services/config/constants.js.map +1 -1
  59. package/dist/services/config/types.js +49 -9
  60. package/dist/services/config/types.js.map +1 -1
  61. package/dist/services/core/Err.js.map +1 -1
  62. package/dist/services/core/Utils.js +107 -32
  63. package/dist/services/core/Utils.js.map +1 -1
  64. package/dist/services/core/websocket/WebSocketManager.js +2 -1
  65. package/dist/services/core/websocket/WebSocketManager.js.map +1 -1
  66. package/dist/services/core/websocket/types.js.map +1 -1
  67. package/dist/services/index.js +1 -1
  68. package/dist/services/index.js.map +1 -1
  69. package/dist/services/task/Task.js +688 -0
  70. package/dist/services/task/Task.js.map +1 -0
  71. package/dist/services/task/TaskFactory.js +45 -0
  72. package/dist/services/task/TaskFactory.js.map +1 -0
  73. package/dist/services/task/TaskManager.js +728 -527
  74. package/dist/services/task/TaskManager.js.map +1 -1
  75. package/dist/services/task/TaskUtils.js +162 -26
  76. package/dist/services/task/TaskUtils.js.map +1 -1
  77. package/dist/services/task/constants.js +9 -2
  78. package/dist/services/task/constants.js.map +1 -1
  79. package/dist/services/task/dialer.js +78 -0
  80. package/dist/services/task/dialer.js.map +1 -1
  81. package/dist/services/task/digital/Digital.js +77 -0
  82. package/dist/services/task/digital/Digital.js.map +1 -0
  83. package/dist/services/task/state-machine/TaskStateMachine.js +837 -0
  84. package/dist/services/task/state-machine/TaskStateMachine.js.map +1 -0
  85. package/dist/services/task/state-machine/actions.js +543 -0
  86. package/dist/services/task/state-machine/actions.js.map +1 -0
  87. package/dist/services/task/state-machine/constants.js +161 -0
  88. package/dist/services/task/state-machine/constants.js.map +1 -0
  89. package/dist/services/task/state-machine/guards.js +340 -0
  90. package/dist/services/task/state-machine/guards.js.map +1 -0
  91. package/dist/services/task/state-machine/index.js +53 -0
  92. package/dist/services/task/state-machine/index.js.map +1 -0
  93. package/dist/services/task/state-machine/types.js +54 -0
  94. package/dist/services/task/state-machine/types.js.map +1 -0
  95. package/dist/services/task/state-machine/uiControlsComputer.js +553 -0
  96. package/dist/services/task/state-machine/uiControlsComputer.js.map +1 -0
  97. package/dist/services/task/taskDataNormalizer.js +99 -0
  98. package/dist/services/task/taskDataNormalizer.js.map +1 -0
  99. package/dist/services/task/types.js +212 -4
  100. package/dist/services/task/types.js.map +1 -1
  101. package/dist/services/task/voice/Voice.js +1042 -0
  102. package/dist/services/task/voice/Voice.js.map +1 -0
  103. package/dist/services/task/voice/WebRTC.js +149 -0
  104. package/dist/services/task/voice/WebRTC.js.map +1 -0
  105. package/dist/types/cc.d.ts +94 -1
  106. package/dist/types/config.d.ts +6 -0
  107. package/dist/types/constants.d.ts +17 -1
  108. package/dist/types/index.d.ts +21 -6
  109. package/dist/types/metrics/constants.d.ts +21 -1
  110. package/dist/types/services/ApiAiAssistant.d.ts +22 -4
  111. package/dist/types/services/UserPreference.d.ts +118 -0
  112. package/dist/types/services/config/constants.d.ts +21 -0
  113. package/dist/types/services/config/types.d.ts +171 -10
  114. package/dist/types/services/core/Err.d.ts +4 -0
  115. package/dist/types/services/core/Utils.d.ts +33 -13
  116. package/dist/types/services/core/websocket/WebSocketManager.d.ts +1 -0
  117. package/dist/types/services/core/websocket/types.d.ts +1 -1
  118. package/dist/types/services/index.d.ts +1 -1
  119. package/dist/types/services/task/Task.d.ts +157 -0
  120. package/dist/types/services/task/TaskFactory.d.ts +12 -0
  121. package/dist/types/services/task/TaskUtils.d.ts +46 -2
  122. package/dist/types/services/task/constants.d.ts +7 -0
  123. package/dist/types/services/task/dialer.d.ts +30 -0
  124. package/dist/types/services/task/digital/Digital.d.ts +22 -0
  125. package/dist/types/services/task/state-machine/TaskStateMachine.d.ts +1144 -0
  126. package/dist/types/services/task/state-machine/actions.d.ts +10 -0
  127. package/dist/types/services/task/state-machine/constants.d.ts +107 -0
  128. package/dist/types/services/task/state-machine/guards.d.ts +90 -0
  129. package/dist/types/services/task/state-machine/index.d.ts +13 -0
  130. package/dist/types/services/task/state-machine/types.d.ts +267 -0
  131. package/dist/types/services/task/state-machine/uiControlsComputer.d.ts +9 -0
  132. package/dist/types/services/task/taskDataNormalizer.d.ts +10 -0
  133. package/dist/types/services/task/types.d.ts +603 -66
  134. package/dist/types/services/task/voice/Voice.d.ts +184 -0
  135. package/dist/types/services/task/voice/WebRTC.d.ts +53 -0
  136. package/dist/types/types.d.ts +135 -0
  137. package/dist/types/webex.d.ts +1 -0
  138. package/dist/types.js +118 -2
  139. package/dist/types.js.map +1 -1
  140. package/dist/webex.js +14 -2
  141. package/dist/webex.js.map +1 -1
  142. package/package.json +15 -12
  143. package/src/cc.ts +329 -30
  144. package/src/config.ts +6 -0
  145. package/src/constants.ts +17 -1
  146. package/src/index.ts +23 -5
  147. package/src/metrics/ai-docs/AGENTS.md +350 -0
  148. package/src/metrics/ai-docs/ARCHITECTURE.md +338 -0
  149. package/src/metrics/ai-docs/metrics-spec.md +854 -0
  150. package/src/metrics/behavioral-events.ts +106 -0
  151. package/src/metrics/constants.ts +27 -4
  152. package/src/services/ApiAiAssistant.ts +203 -8
  153. package/src/services/UserPreference.ts +509 -0
  154. package/src/services/agent/ai-docs/AGENTS.md +240 -0
  155. package/src/services/agent/ai-docs/ARCHITECTURE.md +304 -0
  156. package/src/services/agent/ai-docs/agent-spec.md +504 -0
  157. package/src/services/ai-docs/AGENTS.md +386 -0
  158. package/src/services/ai-docs/services-spec.md +492 -0
  159. package/src/services/config/Util.ts +3 -3
  160. package/src/services/config/ai-docs/AGENTS.md +255 -0
  161. package/src/services/config/ai-docs/ARCHITECTURE.md +426 -0
  162. package/src/services/config/ai-docs/config-spec.md +669 -0
  163. package/src/services/config/constants.ts +25 -1
  164. package/src/services/config/types.ts +174 -11
  165. package/src/services/core/Err.ts +2 -0
  166. package/src/services/core/Utils.ts +123 -37
  167. package/src/services/core/ai-docs/AGENTS.md +381 -0
  168. package/src/services/core/ai-docs/ARCHITECTURE.md +698 -0
  169. package/src/services/core/ai-docs/core-spec.md +783 -0
  170. package/src/services/core/websocket/WebSocketManager.ts +2 -0
  171. package/src/services/core/websocket/types.ts +1 -1
  172. package/src/services/index.ts +1 -1
  173. package/src/services/task/Task.ts +837 -0
  174. package/src/services/task/TaskFactory.ts +55 -0
  175. package/src/services/task/TaskManager.ts +739 -614
  176. package/src/services/task/TaskUtils.ts +205 -25
  177. package/src/services/task/ai-docs/AGENTS.md +457 -0
  178. package/src/services/task/ai-docs/ARCHITECTURE.md +594 -0
  179. package/src/services/task/ai-docs/task-spec.md +1319 -0
  180. package/src/services/task/constants.ts +7 -0
  181. package/src/services/task/dialer.ts +80 -0
  182. package/src/services/task/digital/Digital.ts +95 -0
  183. package/src/services/task/state-machine/TaskStateMachine.ts +1077 -0
  184. package/src/services/task/state-machine/actions.ts +685 -0
  185. package/src/services/task/state-machine/ai-docs/AGENTS.md +458 -0
  186. package/src/services/task/state-machine/ai-docs/ARCHITECTURE.md +1137 -0
  187. package/src/services/task/state-machine/ai-docs/task-state-machine-spec.md +2115 -0
  188. package/src/services/task/state-machine/constants.ts +172 -0
  189. package/src/services/task/state-machine/guards.ts +406 -0
  190. package/src/services/task/state-machine/index.ts +28 -0
  191. package/src/services/task/state-machine/types.ts +241 -0
  192. package/src/services/task/state-machine/uiControlsComputer.ts +867 -0
  193. package/src/services/task/taskDataNormalizer.ts +137 -0
  194. package/src/services/task/types.ts +710 -71
  195. package/src/services/task/voice/Voice.ts +1267 -0
  196. package/src/services/task/voice/WebRTC.ts +187 -0
  197. package/src/types.ts +166 -2
  198. package/src/utils/AGENTS.md +278 -0
  199. package/src/utils/ai-docs/utils-spec.md +381 -0
  200. package/src/webex.js +2 -0
  201. package/test/unit/spec/cc.ts +343 -23
  202. package/test/unit/spec/logger-proxy.ts +70 -0
  203. package/test/unit/spec/services/ApiAiAssistant.ts +178 -20
  204. package/test/unit/spec/services/UserPreference.ts +401 -0
  205. package/test/unit/spec/services/WebCallingService.ts +7 -1
  206. package/test/unit/spec/services/config/index.ts +30 -30
  207. package/test/unit/spec/services/core/Utils.ts +425 -8
  208. package/test/unit/spec/services/core/websocket/WebSocketManager.ts +66 -40
  209. package/test/unit/spec/services/task/AutoWrapup.ts +63 -0
  210. package/test/unit/spec/services/task/Task.ts +477 -0
  211. package/test/unit/spec/services/task/TaskFactory.ts +62 -0
  212. package/test/unit/spec/services/task/TaskManager.ts +834 -1704
  213. package/test/unit/spec/services/task/TaskUtils.ts +206 -0
  214. package/test/unit/spec/services/task/dialer.ts +190 -0
  215. package/test/unit/spec/services/task/digital/Digital.ts +105 -0
  216. package/test/unit/spec/services/task/state-machine/TaskStateMachine.ts +1825 -0
  217. package/test/unit/spec/services/task/state-machine/guards.ts +479 -0
  218. package/test/unit/spec/services/task/state-machine/types.ts +18 -0
  219. package/test/unit/spec/services/task/state-machine/uiControlsComputer.ts +2020 -0
  220. package/test/unit/spec/services/task/taskTestUtils.ts +87 -0
  221. package/test/unit/spec/services/task/voice/Voice.ts +631 -0
  222. package/test/unit/spec/services/task/voice/WebRTC.ts +235 -0
  223. package/umd/contact-center.min.js +2 -2
  224. package/umd/contact-center.min.js.map +1 -1
  225. package/dist/services/task/index.js +0 -1525
  226. package/dist/services/task/index.js.map +0 -1
  227. package/dist/types/services/task/index.d.ts +0 -650
  228. package/src/services/task/index.ts +0 -1801
  229. package/test/unit/spec/services/task/index.ts +0 -2184
@@ -0,0 +1,457 @@
1
+ # Task Service - AI Agent Guide
2
+
3
+ > **Legacy/reference-only.** Canonical SDD: [`task-spec.md`](task-spec.md). Use the package [manifest](../../../../.sdd/manifest.json) and [`SPEC_INDEX.md`](../../../../ai-docs/SPEC_INDEX.md) for routing; code and tests remain the behavioral referee.
4
+
5
+ ## Purpose
6
+
7
+ Manage task lifecycle including inbound/outbound calls, hold/resume, consult, transfer, conference, and wrapup.
8
+
9
+ ---
10
+
11
+ ## File Structure
12
+
13
+ ```
14
+ services/task/
15
+ ├── Task.ts # Task class (ITask implementation)
16
+ ├── TaskManager.ts # Singleton task manager
17
+ ├── contact.ts # Contact operations (AQM)
18
+ ├── dialer.ts # Outbound dialing (AQM)
19
+ ├── AutoWrapup.ts # Auto wrapup handler
20
+ ├── TaskUtils.ts # Helper functions
21
+ ├── types.ts # Task types and events
22
+ ├── constants.ts # Task constants
23
+ ├── TaskFactory.ts # Task factory
24
+ ├── taskDataNormalizer.ts # Task data normalization helpers
25
+ ├── digital/ # Digital task implementations
26
+ │ └── Digital.ts
27
+ ├── voice/ # Voice task implementations
28
+ │ ├── Voice.ts
29
+ │ └── WebRTC.ts
30
+ ├── state-machine/ # XState task lifecycle engine
31
+ │ ├── TaskStateMachine.ts
32
+ │ ├── actions.ts
33
+ │ ├── guards.ts
34
+ │ ├── uiControlsComputer.ts
35
+ │ ├── constants.ts
36
+ │ ├── types.ts
37
+ │ └── ai-docs/
38
+ │ ├── AGENTS.md
39
+ │ └── ARCHITECTURE.md
40
+ └── ai-docs/
41
+ ├── AGENTS.md # Usage documentation
42
+ └── ARCHITECTURE.md # Task service architecture
43
+ ```
44
+
45
+ ## Source of Truth
46
+
47
+ - Task creation: `TaskFactory.ts`
48
+ - Task APIs and behavior: `Task.ts`, `voice/Voice.ts`, `voice/WebRTC.ts`, `digital/Digital.ts`
49
+ - Task management: `TaskManager.ts`
50
+ - Shared task types: `types.ts`, `constants.ts`
51
+ - Task lifecycle state machine: `state-machine/TaskStateMachine.ts`
52
+ - State machine types/events: `state-machine/constants.ts`, `state-machine/types.ts`
53
+
54
+ ## Public Types and Constants
55
+
56
+ - `TASK_EVENTS` enum (`types.ts`)
57
+ - `TaskData`, `TaskId`, `TaskResponse`, `TaskUIControls` (`types.ts`)
58
+ - `ITask`, `IVoice`, `IWebRTC`, `IDigital` (`types.ts`)
59
+ - `MEDIA_CHANNEL`, `TASK_CHANNEL_TYPE`, `VOICE_VARIANT` (`types.ts`)
60
+ - State machine: `TaskState`, `TaskEvent` (`state-machine/constants.ts`)
61
+
62
+ ## Key Capabilities
63
+
64
+ - **Task Creation by Channel**: `TaskFactory.ts` chooses `WebRTC`, `Voice`, or `Digital` based on `MEDIA_CHANNEL` and `webCallingService.loginOption`, so each task class exposes the correct capabilities for the media type.
65
+ - **Task Orchestration**: `TaskManager.ts` owns task lifecycle wiring—initializes listeners, receives task events, creates/updates tasks, emits SDK events, and exposes task collections for consumers.
66
+ - **Event Emission and Public APIs**: Task objects register listeners, update context, emit SDK events (e.g., `task:*`), and expose public methods that delegate to `contact.ts` for call control and to the state machine for transition validation.
67
+ - **AQM Contact Operations**: `contact.ts` builds the AQM request surface for call control (accept, hold, consult, transfer, wrapup, end) and is the primary bridge from `Task`/`Voice`/`WebRTC`/`Digital` methods to WCC task APIs.
68
+ - **Outbound Dialing**: `dialer.ts` exposes the AQM dialer request (`startOutdial`) used by `cc.startOutdial()` to create outbound voice tasks with success/failure event mapping.
69
+ - **State Machine Driven UI Controls**: The `state-machine/` folder provides the XState engine (`TaskStateMachine.ts`) plus `actions.ts`, `guards.ts`, `uiControlsComputer.ts`, `constants.ts`, and `types.ts` to compute valid transitions and UI control state. Capability-level details live in `state-machine/ai-docs/AGENTS.md`.
70
+
71
+ ---
72
+
73
+ ## Task Layer Overview
74
+
75
+ This section describes how the task layer constructs tasks, initializes the state machine, and wires AQM calls to task methods. It provides context for how the state machine fits into the end-to-end flow.
76
+
77
+ ### Task Class Hierarchy
78
+
79
+ - **Hierarchy**: `Task` (base) → `Voice` → `WebRTC`; `Digital` extends `Task`.
80
+ - **`Task` (base)**: Holds task data, emits SDK events, and provides default (unsupported) implementations for call control APIs.
81
+ - **`Voice`**: Adds hold/resume and consult-related capabilities for telephony tasks.
82
+ - **`WebRTC`**: Overrides `accept/decline` for WebRTC calls and hooks media events.
83
+ - **`Digital`**: Implements `accept` and refreshes digital task data/UI controls.
84
+
85
+ ### Task Creation and State Machine Initialization
86
+
87
+ - **Factory**: `TaskFactory.ts` selects `WebRTC`, `Voice`, or `Digital` based on `MEDIA_CHANNEL` and `webCallingService.loginOption`.
88
+ - **Initialization**: `Task.ts` creates a state machine actor using `createTaskStateMachine(...)`, wires action overrides (emitters), and starts the actor.
89
+ - **Task State**: The task holds `stateMachineService` and uses it to send `TaskEvent` payloads.
90
+
91
+ Example (state machine init inside a task object):
92
+
93
+ ```typescript
94
+ const machine = createTaskStateMachine(uiControlConfig, {
95
+ actions: {
96
+ emitTaskIncoming: ({event}) => task.emit('task:incoming', task),
97
+ },
98
+ });
99
+ const actor = createActor(machine);
100
+ actor.start();
101
+ ```
102
+
103
+ ### TaskManager Lifecycle Orchestration
104
+
105
+ - **Listener Setup**: Registers WebSocket listeners to receive CC events and map them to `TaskEvent` payloads.
106
+ - **Task Registry**: Creates tasks via `TaskFactory`, stores them in the task collection, and updates task data on incoming events.
107
+ - **Event Emission**: Re-emits `task:*` events on the task or `cc` object for SDK consumers.
108
+ - **Hydration/Recovery**: Handles state updates and transitions during reconnect/hydrate flows.
109
+
110
+ Example (backend event to state machine):
111
+
112
+ ```typescript
113
+ const payload = TaskManager.mapEventToTaskStateMachineEvent(event, taskData);
114
+ if (payload) {
115
+ task.sendStateMachineEvent(payload);
116
+ }
117
+ ```
118
+
119
+ ### AQM Call Control Integration
120
+
121
+ - **`contact.ts`**: Builds the AQM request surface for call control (hold, consult, transfer, wrapup, end). Task methods delegate to these calls, then drive state transitions based on success/failure events.
122
+ - **`dialer.ts`**: Exposes the `startOutdial` AQM request used by `cc.startOutdial()` to create outbound tasks.
123
+
124
+ Example (task method delegating to AQM):
125
+
126
+ ```typescript
127
+ // task.hold() -> contact.hold(...) -> stateMachine events on response
128
+ await contact.hold({interactionId});
129
+ stateMachineService.send({type: TaskEvent.HOLD_INITIATED, mediaResourceId});
130
+ ```
131
+
132
+ ### Sequential Flow (End-to-End)
133
+
134
+ 1. **WebSocket event arrives** → `TaskManager` maps CC event to `TaskEvent`.
135
+ 2. **Task creation** (if new) → `TaskFactory` builds `Voice`/`WebRTC`/`Digital`.
136
+ 3. **State machine actor starts** → `Task` wires emitters + UI control updates.
137
+ 4. **Task method called** (e.g., hold/transfer) → delegates to `contact.ts` or `dialer.ts`.
138
+ 5. **State transitions** → guards/actions update context and emit `task:*` events.
139
+ 6. **SDK consumers update UI** → `TaskUIControls` reflect the latest state.
140
+
141
+ ```mermaid
142
+ flowchart TD
143
+ A[WebSocket event arrives] --> B[TaskManager maps CC event to TaskEvent]
144
+ B --> C{Task exists?}
145
+ C -- No --> D[TaskFactory creates Voice/WebRTC/Digital]
146
+ C -- Yes --> E[Use existing task]
147
+ D --> F[Task initializes state machine actor]
148
+ E --> F
149
+ F --> G[Task method called (hold/transfer/etc)]
150
+ G --> H[contact.ts or dialer.ts API call]
151
+ H --> I[State machine transition]
152
+ I --> J[Actions + guards update context]
153
+ J --> K[Emit task:* events]
154
+ K --> L[TaskUIControls updated for SDK UI]
155
+ ```
156
+
157
+ ---
158
+
159
+ ## Quick Start
160
+
161
+ ```typescript
162
+ // Listen for incoming tasks
163
+ cc.on('task:incoming', async (task) => {
164
+ console.log('Incoming task:', task.data.interactionId);
165
+
166
+ // Accept the task
167
+ await task.accept();
168
+
169
+ // Task operations
170
+ await task.hold();
171
+ await task.resume();
172
+ await task.end();
173
+ await task.wrapup({
174
+ wrapUpReason: 'Resolved',
175
+ auxCodeId: 'wrapup-code',
176
+ });
177
+ });
178
+ ```
179
+
180
+ ---
181
+
182
+ ## Task Events
183
+
184
+ ### Emitted on `cc` object(ContactCenter)
185
+
186
+ | Event | When Emitted |
187
+ | --------------- | ---------------------------- |
188
+ | `task:incoming` | New task offered to agent |
189
+ | `task:hydrate` | Task data updated |
190
+ | `task:merged` | Tasks merged (EPDN transfer) |
191
+
192
+ ### Emitted on `task` object(ITask)
193
+
194
+ | Event | When Emitted |
195
+ | --------------------------------------------------------------------------- | ------------------------------------------------ |
196
+ | `task:assigned` | Task assigned to agent |
197
+ | `task:media` | Media stream/track updates are available |
198
+ | `task:unassigned` | Task is unassigned from agent |
199
+ | `task:offerContact` | Contact offer received/updated |
200
+ | `task:offerConsult` | Consult offer received |
201
+ | `task:hold` | Task placed on hold |
202
+ | `task:resume` | Task resumed from hold |
203
+ | `task:end` | Task ended |
204
+ | `task:rejected` | Task rejected / failure path emitted |
205
+ | `task:wrapup` | Task entering wrapup |
206
+ | `task:wrappedup` | Wrapup completed |
207
+ | `task:consulting` | Consult is in progress |
208
+ | `task:consultAccepted` | Consult accepted by destination party |
209
+ | `task:consultCreated` | Consultation started |
210
+ | `task:consultEnd` | Consultation ended |
211
+ | `task:autoAnswered` | Task was auto-answered |
212
+ | `task:recordingStarted` / `task:recordingPaused` / `task:recordingResumed` | Recording lifecycle updates |
213
+ | `task:conferenceStarted` / `task:conferenceEnded` / `task:conferenceFailed` | Conference lifecycle updates |
214
+ | `task:participantJoined` / `task:participantLeft` | Conference participant updates |
215
+ | `task:switchCall` | Switched between consult and main call |
216
+ | `task:outdialFailed` | Outdial operation failed |
217
+ | `task:ui-controls-updated` | UI controls changed due to state transition |
218
+ | `task:cleanup` | Internal cleanup signal emitted by state machine |
219
+
220
+ > Full list is defined in `TASK_EVENTS` (`types.ts`).
221
+
222
+ ### AI Assistant events on `task`
223
+
224
+ | Event | When Emitted |
225
+ | --- | --- |
226
+ | `REAL_TIME_TRANSCRIPTION` | A realtime transcript payload is received for the task interaction |
227
+ | `SUGGESTED_RESPONSE` | A final AI Assistant suggestion payload is received for the task interaction |
228
+
229
+ ---
230
+
231
+ ## API Reference
232
+
233
+ ### `cc.startOutdial(destination, origin)`
234
+
235
+ Initiate outbound call.
236
+
237
+ **Parameters**:
238
+
239
+ - `destination` (string): Phone number to call
240
+ - `origin` (string): Outbound ANI/caller ID
241
+
242
+ **Returns**: `Promise<TaskResponse>` (AQM response, not a Task instance)
243
+
244
+ **Example**:
245
+
246
+ ```typescript
247
+ const response = await cc.startOutdial('+14155551234', '+18005551000');
248
+
249
+ // Outdial task object is created asynchronously via TaskManager.
250
+ // Listen on cc/task events instead of treating startOutdial response as an ITask.
251
+ cc.on('task:incoming', (task) => {
252
+ task.on('task:assigned', () => {
253
+ console.log('Call connected');
254
+ });
255
+
256
+ task.on('task:end', () => {
257
+ console.log('Call ended');
258
+ });
259
+ });
260
+ ```
261
+
262
+ ---
263
+
264
+ ### `task.accept()`
265
+
266
+ Accept an incoming task.
267
+
268
+ **Returns**: `Promise<TaskResponse>`
269
+
270
+ **Example**:
271
+
272
+ ```typescript
273
+ cc.on('task:incoming', async (task) => {
274
+ await task.accept();
275
+ });
276
+ ```
277
+
278
+ ---
279
+
280
+ ### `task.hold(mediaResourceId?)` / `task.resume(mediaResourceId?)`
281
+
282
+ Put task on hold or resume.
283
+
284
+ **Parameters**:
285
+
286
+ - `mediaResourceId` (optional `string`): Media resource ID for the hold/resume operation
287
+
288
+ **Returns**: `Promise<TaskResponse>`
289
+
290
+ **Example**:
291
+
292
+ ```typescript
293
+ // Put on hold
294
+ await task.hold();
295
+
296
+ // Resume
297
+ await task.resume();
298
+ ```
299
+
300
+ ---
301
+
302
+ ### `task.end()`
303
+
304
+ End the current task.
305
+
306
+ **Returns**: `Promise<TaskResponse>`
307
+
308
+ **Example**:
309
+
310
+ ```typescript
311
+ await task.end();
312
+ ```
313
+
314
+ ---
315
+
316
+ ### `task.wrapup(params)`
317
+
318
+ Complete task with wrapup code.
319
+
320
+ **Parameters**:
321
+
322
+ - `wrapUpReason` (string, required): Wrapup reason text
323
+ - `auxCodeId` (string, required): Wrapup code ID
324
+
325
+ **Returns**: `Promise<TaskResponse>`
326
+
327
+ **Example**:
328
+
329
+ ```typescript
330
+ await task.wrapup({
331
+ wrapUpReason: 'Customer issue resolved',
332
+ auxCodeId: 'resolved-code',
333
+ });
334
+ ```
335
+
336
+ ---
337
+
338
+ ### `task.transfer(params)`
339
+
340
+ Transfer task to another destination.
341
+
342
+ **Parameters**:
343
+
344
+ - `to` (string): Agent ID, queue ID, or phone number
345
+ - `destinationType` ('queue' | 'agent' | 'dialNumber'): Destination type
346
+
347
+ **Returns**: `Promise<TaskResponse>`
348
+
349
+ **Example**:
350
+
351
+ ```typescript
352
+ // Transfer to queue
353
+ await task.transfer({
354
+ to: 'queue-123',
355
+ destinationType: 'queue',
356
+ });
357
+
358
+ // Transfer to agent
359
+ await task.transfer({
360
+ to: 'agent-456',
361
+ destinationType: 'agent',
362
+ });
363
+ ```
364
+
365
+ ---
366
+
367
+ ### `task.consult(params)`
368
+
369
+ Start consultation.
370
+
371
+ **Parameters**:
372
+
373
+ - `to` (string): Agent/queue/phone to consult
374
+ - `destinationType` ('queue' | 'agent' | 'dialNumber' | 'entryPoint'): Type
375
+
376
+ **Returns**: `Promise<TaskResponse>`
377
+
378
+ **Example**:
379
+
380
+ ```typescript
381
+ await task.consult({
382
+ to: 'agent-456',
383
+ destinationType: 'agent',
384
+ });
385
+
386
+ // Later: complete transfer (consulting voice flow uses transfer())
387
+ await task.transfer({
388
+ to: 'queue-123',
389
+ destinationType: 'queue',
390
+ });
391
+ // Or end consult
392
+ await task.endConsult();
393
+ ```
394
+
395
+ ---
396
+
397
+ ### `task.endConsult(consultEndPayload?)`
398
+
399
+ End consultation without transfer.
400
+
401
+ **Parameters**:
402
+
403
+ - `consultEndPayload` (optional `ConsultEndPayload`)
404
+
405
+ **Returns**: `Promise<TaskResponse>`
406
+
407
+ ---
408
+
409
+ ## Media Channels
410
+
411
+ | Channel | Description |
412
+ | ----------- | ------------------ |
413
+ | `telephony` | Voice calls |
414
+ | `chat` | Web chat |
415
+ | `email` | Email interactions |
416
+ | `social` | Social media |
417
+ | `sms` | SMS messages |
418
+ | `facebook` | Facebook Messenger |
419
+ | `whatsapp` | WhatsApp messages |
420
+
421
+ ---
422
+
423
+ ## Error Handling
424
+
425
+ ```typescript
426
+ try {
427
+ await task.transfer({
428
+ to: 'queue-123',
429
+ destinationType: 'queue',
430
+ });
431
+ } catch (error) {
432
+ console.error('Transfer failed:', error.message);
433
+ // error.data contains structured error info
434
+ }
435
+ ```
436
+
437
+ ---
438
+
439
+ ## Auto Wrapup
440
+
441
+ If enabled in agent profile, wrapup completes automatically after timeout:
442
+
443
+ ```typescript
444
+ task.on('task:wrappedup', () => {
445
+ console.log('Task wrapup completed');
446
+ });
447
+ ```
448
+
449
+ ---
450
+
451
+ ## Related
452
+
453
+ - [ARCHITECTURE.md](ARCHITECTURE.md) - Technical deep-dive
454
+ - [TaskManager.ts](../TaskManager.ts) - Manager implementation
455
+ - [types.ts](../types.ts) - Type definitions
456
+ - [../state-machine/ai-docs/AGENTS.md](../state-machine/ai-docs/AGENTS.md) - State machine implementation guide
457
+ - [../state-machine/ai-docs/ARCHITECTURE.md](../state-machine/ai-docs/ARCHITECTURE.md) - State machine internals