@webex/contact-center 3.12.0-webex-services-ready.4 → 3.13.0

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 (250) hide show
  1. package/.sdd/manifest.json +24 -13
  2. package/ai-docs/ARCHITECTURE.md +1 -1
  3. package/ai-docs/CONTRACTS.md +19 -3
  4. package/ai-docs/SECURITY.md +1 -1
  5. package/ai-docs/SERVICE_STATE.md +4 -0
  6. package/ai-docs/contact-center-spec.md +50 -6
  7. package/ai-docs/features/consult-transfer-list-policy/spec/feature-spec.md +362 -0
  8. package/ai-docs/features/contact-owner-change-refactor.md +78 -0
  9. package/dist/cc.js +757 -22
  10. package/dist/cc.js.map +1 -1
  11. package/dist/config.js +7 -0
  12. package/dist/config.js.map +1 -1
  13. package/dist/constants.js +23 -2
  14. package/dist/constants.js.map +1 -1
  15. package/dist/index.js +34 -12
  16. package/dist/index.js.map +1 -1
  17. package/dist/metrics/MetricsManager.js +16 -0
  18. package/dist/metrics/MetricsManager.js.map +1 -1
  19. package/dist/metrics/behavioral-events.js +110 -0
  20. package/dist/metrics/behavioral-events.js.map +1 -1
  21. package/dist/metrics/constants.js +33 -0
  22. package/dist/metrics/constants.js.map +1 -1
  23. package/dist/services/AddressBook.js +18 -15
  24. package/dist/services/AddressBook.js.map +1 -1
  25. package/dist/services/AnswerCallOnWebexService.js +202 -0
  26. package/dist/services/AnswerCallOnWebexService.js.map +1 -0
  27. package/dist/services/ApiAiAssistant.js +221 -11
  28. package/dist/services/ApiAiAssistant.js.map +1 -1
  29. package/dist/services/EntryPoint.js +46 -68
  30. package/dist/services/EntryPoint.js.map +1 -1
  31. package/dist/services/Queue.js +27 -22
  32. package/dist/services/Queue.js.map +1 -1
  33. package/dist/services/WebCallingService.js +10 -2
  34. package/dist/services/WebCallingService.js.map +1 -1
  35. package/dist/services/WebexCrossClientService.js +225 -0
  36. package/dist/services/WebexCrossClientService.js.map +1 -0
  37. package/dist/services/WxAppTelephonyMercurySync.js +111 -0
  38. package/dist/services/WxAppTelephonyMercurySync.js.map +1 -0
  39. package/dist/services/config/Util.js +46 -46
  40. package/dist/services/config/Util.js.map +1 -1
  41. package/dist/services/config/constants.js +34 -77
  42. package/dist/services/config/constants.js.map +1 -1
  43. package/dist/services/config/index.js +100 -226
  44. package/dist/services/config/index.js.map +1 -1
  45. package/dist/services/config/types.js +51 -18
  46. package/dist/services/config/types.js.map +1 -1
  47. package/dist/services/constants.js +11 -1
  48. package/dist/services/constants.js.map +1 -1
  49. package/dist/services/core/Err.js.map +1 -1
  50. package/dist/services/core/Utils.js +25 -1
  51. package/dist/services/core/Utils.js.map +1 -1
  52. package/dist/services/core/WebexRequest.js +6 -2
  53. package/dist/services/core/WebexRequest.js.map +1 -1
  54. package/dist/services/core/aqm-reqs.js +17 -11
  55. package/dist/services/core/aqm-reqs.js.map +1 -1
  56. package/dist/services/core/constants.js +9 -1
  57. package/dist/services/core/constants.js.map +1 -1
  58. package/dist/services/core/types.js.map +1 -1
  59. package/dist/services/core/websocket/WebSocketManager.js +17 -1
  60. package/dist/services/core/websocket/WebSocketManager.js.map +1 -1
  61. package/dist/services/task/Task.js +275 -8
  62. package/dist/services/task/Task.js.map +1 -1
  63. package/dist/services/task/TaskFactory.js +11 -6
  64. package/dist/services/task/TaskFactory.js.map +1 -1
  65. package/dist/services/task/TaskManager.js +590 -42
  66. package/dist/services/task/TaskManager.js.map +1 -1
  67. package/dist/services/task/TaskUtils.js +11 -1
  68. package/dist/services/task/TaskUtils.js.map +1 -1
  69. package/dist/services/task/WebexCallingUtils.js +70 -0
  70. package/dist/services/task/WebexCallingUtils.js.map +1 -0
  71. package/dist/services/task/constants.js +14 -2
  72. package/dist/services/task/constants.js.map +1 -1
  73. package/dist/services/task/contact.js +29 -0
  74. package/dist/services/task/contact.js.map +1 -1
  75. package/dist/services/task/digital/Digital.js +4 -3
  76. package/dist/services/task/digital/Digital.js.map +1 -1
  77. package/dist/services/task/state-machine/TaskStateMachine.js +162 -53
  78. package/dist/services/task/state-machine/TaskStateMachine.js.map +1 -1
  79. package/dist/services/task/state-machine/actions.js +6 -1
  80. package/dist/services/task/state-machine/actions.js.map +1 -1
  81. package/dist/services/task/state-machine/guards.js +7 -10
  82. package/dist/services/task/state-machine/guards.js.map +1 -1
  83. package/dist/services/task/state-machine/types.js.map +1 -1
  84. package/dist/services/task/state-machine/uiControlsComputer.js +118 -18
  85. package/dist/services/task/state-machine/uiControlsComputer.js.map +1 -1
  86. package/dist/services/task/types.js +47 -1
  87. package/dist/services/task/types.js.map +1 -1
  88. package/dist/services/task/voice/Voice.js +477 -17
  89. package/dist/services/task/voice/Voice.js.map +1 -1
  90. package/dist/services/task/voice/WebRTC.js +6 -3
  91. package/dist/services/task/voice/WebRTC.js.map +1 -1
  92. package/dist/services/task/voice/wxAppOfferObservability.js +145 -0
  93. package/dist/services/task/voice/wxAppOfferObservability.js.map +1 -0
  94. package/dist/services/task/voice/wxAppVoiceMethods.js +395 -0
  95. package/dist/services/task/voice/wxAppVoiceMethods.js.map +1 -0
  96. package/dist/services/wxAppDiagnosticLogging.js +159 -0
  97. package/dist/services/wxAppDiagnosticLogging.js.map +1 -0
  98. package/dist/services/wxAppTelephonyUtils.js +19 -0
  99. package/dist/services/wxAppTelephonyUtils.js.map +1 -0
  100. package/dist/types/cc.d.ts +102 -8
  101. package/dist/types/config.d.ts +7 -0
  102. package/dist/types/constants.d.ts +21 -0
  103. package/dist/types/index.d.ts +34 -15
  104. package/dist/types/metrics/MetricsManager.d.ts +6 -0
  105. package/dist/types/metrics/constants.d.ts +31 -0
  106. package/dist/types/services/AddressBook.d.ts +2 -1
  107. package/dist/types/services/AnswerCallOnWebexService.d.ts +38 -0
  108. package/dist/types/services/ApiAiAssistant.d.ts +48 -4
  109. package/dist/types/services/EntryPoint.d.ts +7 -5
  110. package/dist/types/services/Queue.d.ts +5 -3
  111. package/dist/types/services/WebexCrossClientService.d.ts +32 -0
  112. package/dist/types/services/WxAppTelephonyMercurySync.d.ts +28 -0
  113. package/dist/types/services/config/Util.d.ts +4 -8
  114. package/dist/types/services/config/constants.d.ts +28 -76
  115. package/dist/types/services/config/index.d.ts +16 -64
  116. package/dist/types/services/config/types.d.ts +146 -173
  117. package/dist/types/services/constants.d.ts +9 -0
  118. package/dist/types/services/core/Err.d.ts +2 -0
  119. package/dist/types/services/core/Utils.d.ts +10 -0
  120. package/dist/types/services/core/WebexRequest.d.ts +1 -0
  121. package/dist/types/services/core/constants.d.ts +7 -0
  122. package/dist/types/services/core/types.d.ts +2 -0
  123. package/dist/types/services/task/Task.d.ts +34 -5
  124. package/dist/types/services/task/TaskFactory.d.ts +4 -2
  125. package/dist/types/services/task/TaskUtils.d.ts +6 -0
  126. package/dist/types/services/task/WebexCallingUtils.d.ts +11 -0
  127. package/dist/types/services/task/constants.d.ts +12 -0
  128. package/dist/types/services/task/contact.d.ts +4 -0
  129. package/dist/types/services/task/digital/Digital.d.ts +4 -3
  130. package/dist/types/services/task/state-machine/TaskStateMachine.d.ts +304 -56
  131. package/dist/types/services/task/state-machine/guards.d.ts +6 -5
  132. package/dist/types/services/task/state-machine/types.d.ts +9 -1
  133. package/dist/types/services/task/types.d.ts +192 -5
  134. package/dist/types/services/task/voice/Voice.d.ts +68 -11
  135. package/dist/types/services/task/voice/WebRTC.d.ts +5 -4
  136. package/dist/types/services/task/voice/wxAppOfferObservability.d.ts +39 -0
  137. package/dist/types/services/task/voice/wxAppVoiceMethods.d.ts +68 -0
  138. package/dist/types/services/wxAppDiagnosticLogging.d.ts +63 -0
  139. package/dist/types/services/wxAppTelephonyUtils.d.ts +5 -0
  140. package/dist/types/types.d.ts +80 -13
  141. package/dist/types/utils/PageCache.d.ts +20 -3
  142. package/dist/types.js +54 -8
  143. package/dist/types.js.map +1 -1
  144. package/dist/utils/PageCache.js +19 -5
  145. package/dist/utils/PageCache.js.map +1 -1
  146. package/dist/webex.js +9 -1
  147. package/dist/webex.js.map +1 -1
  148. package/package.json +10 -9
  149. package/src/cc.ts +969 -38
  150. package/src/config.ts +7 -0
  151. package/src/constants.ts +24 -0
  152. package/src/index.ts +39 -10
  153. package/src/metrics/MetricsManager.ts +16 -0
  154. package/src/metrics/ai-docs/metrics-spec.md +138 -21
  155. package/src/metrics/behavioral-events.ts +112 -0
  156. package/src/metrics/constants.ts +36 -0
  157. package/src/services/AddressBook.ts +17 -6
  158. package/src/services/AnswerCallOnWebexService.ts +239 -0
  159. package/src/services/ApiAiAssistant.ts +297 -13
  160. package/src/services/EntryPoint.ts +59 -60
  161. package/src/services/Queue.ts +29 -12
  162. package/src/services/WebCallingService.ts +16 -2
  163. package/src/services/WebexCrossClientService.ts +298 -0
  164. package/src/services/WxAppTelephonyMercurySync.ts +142 -0
  165. package/src/services/agent/ai-docs/AGENTS.md +1 -1
  166. package/src/services/agent/ai-docs/agent-spec.md +1 -0
  167. package/src/services/ai-docs/AGENTS.md +10 -10
  168. package/src/services/ai-docs/services-spec.md +25 -5
  169. package/src/services/config/Util.ts +52 -82
  170. package/src/services/config/ai-docs/AGENTS.md +35 -40
  171. package/src/services/config/ai-docs/ARCHITECTURE.md +90 -103
  172. package/src/services/config/ai-docs/config-spec.md +132 -132
  173. package/src/services/config/constants.ts +39 -85
  174. package/src/services/config/index.ts +116 -277
  175. package/src/services/config/types.ts +140 -195
  176. package/src/services/constants.ts +10 -0
  177. package/src/services/core/Err.ts +1 -0
  178. package/src/services/core/Utils.ts +28 -0
  179. package/src/services/core/WebexRequest.ts +3 -1
  180. package/src/services/core/ai-docs/core-spec.md +25 -11
  181. package/src/services/core/aqm-reqs.ts +18 -12
  182. package/src/services/core/constants.ts +8 -0
  183. package/src/services/core/types.ts +33 -1
  184. package/src/services/core/websocket/WebSocketManager.ts +26 -2
  185. package/src/services/task/Task.ts +386 -12
  186. package/src/services/task/TaskFactory.ts +33 -6
  187. package/src/services/task/TaskManager.ts +857 -41
  188. package/src/services/task/TaskUtils.ts +13 -0
  189. package/src/services/task/WebexCallingUtils.ts +136 -0
  190. package/src/services/task/ai-docs/ARCHITECTURE.md +1 -0
  191. package/src/services/task/ai-docs/task-spec.md +190 -8
  192. package/src/services/task/constants.ts +13 -0
  193. package/src/services/task/contact.ts +30 -0
  194. package/src/services/task/digital/Digital.ts +11 -4
  195. package/src/services/task/state-machine/TaskStateMachine.ts +235 -81
  196. package/src/services/task/state-machine/actions.ts +5 -2
  197. package/src/services/task/state-machine/ai-docs/AGENTS.md +6 -4
  198. package/src/services/task/state-machine/ai-docs/ARCHITECTURE.md +35 -16
  199. package/src/services/task/state-machine/ai-docs/task-state-machine-spec.md +103 -33
  200. package/src/services/task/state-machine/guards.ts +7 -10
  201. package/src/services/task/state-machine/types.ts +16 -1
  202. package/src/services/task/state-machine/uiControlsComputer.ts +206 -32
  203. package/src/services/task/types.ts +269 -4
  204. package/src/services/task/voice/Voice.ts +625 -17
  205. package/src/services/task/voice/WebRTC.ts +11 -4
  206. package/src/services/task/voice/wxAppOfferObservability.ts +204 -0
  207. package/src/services/task/voice/wxAppVoiceMethods.ts +575 -0
  208. package/src/services/wxAppDiagnosticLogging.ts +286 -0
  209. package/src/services/wxAppTelephonyUtils.ts +14 -0
  210. package/src/types.ts +108 -13
  211. package/src/utils/AGENTS.md +21 -10
  212. package/src/utils/PageCache.ts +38 -5
  213. package/src/utils/ai-docs/utils-spec.md +21 -11
  214. package/src/webex.js +8 -0
  215. package/test/unit/fixtures/aiSummaryTestUtils.ts +40 -0
  216. package/test/unit/spec/cc.ts +3408 -152
  217. package/test/unit/spec/index.ts +885 -0
  218. package/test/unit/spec/metrics/MetricsManager.ts +25 -0
  219. package/test/unit/spec/metrics/behavioral-events.ts +60 -0
  220. package/test/unit/spec/services/AddressBook.ts +37 -6
  221. package/test/unit/spec/services/AnswerCallOnWebexService.ts +264 -0
  222. package/test/unit/spec/services/ApiAiAssistant.ts +269 -8
  223. package/test/unit/spec/services/EntryPoint.ts +87 -40
  224. package/test/unit/spec/services/Queue.ts +123 -12
  225. package/test/unit/spec/services/WebCallingService.ts +38 -0
  226. package/test/unit/spec/services/WebexCrossClientService.ts +509 -0
  227. package/test/unit/spec/services/WxAppTelephonyMercurySync.ts +136 -0
  228. package/test/unit/spec/services/config/Util.ts +501 -0
  229. package/test/unit/spec/services/config/index.ts +313 -543
  230. package/test/unit/spec/services/core/Utils.ts +22 -0
  231. package/test/unit/spec/services/core/WebexRequest.ts +8 -7
  232. package/test/unit/spec/services/core/aqm-reqs.ts +142 -1
  233. package/test/unit/spec/services/core/websocket/WebSocketManager.ts +64 -14
  234. package/test/unit/spec/services/task/Task.ts +2257 -11
  235. package/test/unit/spec/services/task/TaskFactory.ts +56 -2
  236. package/test/unit/spec/services/task/TaskManager.ts +5559 -1493
  237. package/test/unit/spec/services/task/TaskUtils.ts +72 -0
  238. package/test/unit/spec/services/task/WebexCallingUtils.ts +153 -0
  239. package/test/unit/spec/services/task/contact.ts +33 -0
  240. package/test/unit/spec/services/task/state-machine/TaskStateMachine.ts +1501 -92
  241. package/test/unit/spec/services/task/state-machine/guards.ts +210 -8
  242. package/test/unit/spec/services/task/state-machine/uiControlsComputer.ts +445 -7
  243. package/test/unit/spec/services/task/voice/Voice.ts +1710 -4
  244. package/test/unit/spec/services/task/voice/wxAppOfferObservability.ts +361 -0
  245. package/test/unit/spec/services/task/voice/wxAppVoiceMethods.ts +719 -0
  246. package/test/unit/spec/services/wxAppDiagnosticLogging.ts +179 -0
  247. package/test/unit/spec/wellnessSampleUtils.ts +288 -0
  248. package/typedoc.md +1 -1
  249. package/umd/contact-center.min.js +2 -2
  250. package/umd/contact-center.min.js.map +1 -1
@@ -0,0 +1,885 @@
1
+ import path from 'path';
2
+ import ts from 'typescript';
3
+
4
+ const CONTACT_CENTER_ROOT = path.resolve(__dirname, '../../..');
5
+ const SRC_ROOT = path.join(CONTACT_CENTER_ROOT, 'src');
6
+ const INDEX_PATH = path.join(SRC_ROOT, 'index.ts');
7
+ const TYPES_PATH = path.join(SRC_ROOT, 'types.ts');
8
+ const CONFIG_TYPES_PATH = path.join(SRC_ROOT, 'services/config/types.ts');
9
+
10
+ const EXPECTED_ROOT_EXPORTS = Object.freeze([
11
+ 'AGENT_EVENTS',
12
+ 'AISummaryAction',
13
+ 'AISummary',
14
+ 'AISummaryFeedback',
15
+ 'AISummaryResponse',
16
+ 'AISummarySections',
17
+ 'AISummaryState',
18
+ 'AI_SUMMARY_ERROR_CODES',
19
+ 'AddressBook',
20
+ 'AddressBookEntriesResponse',
21
+ 'AddressBookEntry',
22
+ 'AddressBookEntrySearchParams',
23
+ 'AgentContact',
24
+ 'AgentEvents',
25
+ 'AgentLogin',
26
+ 'AgentProfile',
27
+ 'AgentProfileUpdate',
28
+ 'AgentResponse',
29
+ 'AgentState',
30
+ 'ApiAIAssistant',
31
+ 'AuxCode',
32
+ 'AuxCodeType',
33
+ 'BuddyAgents',
34
+ 'BuddyAgentsResponse',
35
+ 'BuddyAgentsSuccess',
36
+ 'BuddyDetails',
37
+ 'CCPluginConfig',
38
+ 'CC_AGENT_EVENTS',
39
+ 'CC_TASK_EVENTS',
40
+ 'CC_EVENTS',
41
+ 'ConsultEndPayload',
42
+ 'ConsultPayload',
43
+ 'ConsultTransferPayLoad',
44
+ 'ContactCenter',
45
+ 'ContactCenterEvents',
46
+ 'ContactServiceQueue',
47
+ 'ContactServiceQueueSearchParams',
48
+ 'ContactServiceQueuesResponse',
49
+ 'CreateUserPreferenceRequest',
50
+ 'DeviceType',
51
+ 'DeviceTypeUpdateSuccess',
52
+ 'DialPlan',
53
+ 'DialPlanEntity',
54
+ 'DialerPayload',
55
+ 'DropConferenceParticipantPayload',
56
+ 'Entity',
57
+ 'EntryPointListResponse',
58
+ 'EntryPointRecord',
59
+ 'EntryPointSearchParams',
60
+ 'AISummaryFeatureEnablement',
61
+ 'GenericError',
62
+ 'GetUserPreferenceParams',
63
+ 'IContactCenter',
64
+ 'IDLE_CODE',
65
+ 'IEventEmitter',
66
+ 'ITask',
67
+ 'Interaction',
68
+ 'InteractionUIControls',
69
+ 'ListAuxCodesResponse',
70
+ 'ListTeamsResponse',
71
+ 'LoginOption',
72
+ 'Logout',
73
+ 'LogoutSuccess',
74
+ 'MicrosoftConfig',
75
+ 'MultimediaProfileResponse',
76
+ 'OrgDesktopLoginResponse',
77
+ 'OrgInfo',
78
+ 'OrgSettings',
79
+ 'OrgUrlMappings',
80
+ 'Profile',
81
+ 'ReloginSuccess',
82
+ 'RespondToWellnessBreakParams',
83
+ 'ResumeRecordingPayload',
84
+ 'SetStateResponse',
85
+ 'SiteInfo',
86
+ 'StateChange',
87
+ 'StateChangeSuccess',
88
+ 'StationLoginResponse',
89
+ 'StationLoginSuccess',
90
+ 'StationLoginSuccessResponse',
91
+ 'StationLogoutResponse',
92
+ 'SubscribeRequest',
93
+ 'TASK_EVENTS',
94
+ 'Task',
95
+ 'TaskData',
96
+ 'TaskEvents',
97
+ 'TaskResponse',
98
+ 'TaskUIControlState',
99
+ 'TaskUIControls',
100
+ 'TaskUILeg',
101
+ 'TeamList',
102
+ 'TenantData',
103
+ 'TransferPayLoad',
104
+ 'UpdateDeviceTypeResponse',
105
+ 'UpdateUserPreferenceRequest',
106
+ 'UploadLogsResponse',
107
+ 'UserDesktopLoginResponse',
108
+ 'UserPreference',
109
+ 'UserPreferenceData',
110
+ 'UserStationLogin',
111
+ 'WELLNESS_BREAK_NOTIFICATION_ACTIONS',
112
+ 'WELLNESS_BREAK_USER_ACTIONS',
113
+ 'WRAP_UP_CODE',
114
+ 'WebSocketEvent',
115
+ 'WebexConfig',
116
+ 'WebexSDK',
117
+ 'WellnessBreakEvent',
118
+ 'WellnessBreakNotificationAction',
119
+ 'WellnessBreakUserAction',
120
+ 'WrapUpReason',
121
+ 'WrapupData',
122
+ 'WrapupPayLoad',
123
+ 'default',
124
+ 'getDefaultUIControls',
125
+ 'routingAgent',
126
+ ]);
127
+
128
+ const INTERNAL_ROOT_EXPORTS = Object.freeze([
129
+ 'AIAssistantEventName',
130
+ 'AISummaryTimeoutCodeByInboundType',
131
+ 'AI_SUMMARY_DURATION_MS',
132
+ 'AI_SUMMARY_REQUEST_CANCELLED',
133
+ 'AI_ASSISTANT_CLIENT_TYPE',
134
+ ]);
135
+
136
+ const EXPECTED_AI_SUMMARY_ERROR_CODES = Object.freeze([
137
+ ['POST_CALL_SUMMARY_DISABLED', 'POST_CALL_SUMMARY_DISABLED'],
138
+ ['MID_CALL_SUMMARY_DISABLED', 'MID_CALL_SUMMARY_DISABLED'],
139
+ ['AI_ASSISTANT_BASE_URL_NOT_AVAILABLE', 'AI_ASSISTANT_BASE_URL_NOT_AVAILABLE'],
140
+ ['POST_CALL_SUMMARY_TIMEOUT', 'POST_CALL_SUMMARY_TIMEOUT'],
141
+ ['MID_CALL_SUMMARY_TIMEOUT', 'MID_CALL_SUMMARY_TIMEOUT'],
142
+ ]);
143
+
144
+ const EXPECTED_AI_SUMMARY_WIRE_LITERALS = Object.freeze({
145
+ AIAssistantEventName: Object.freeze({
146
+ GET_POST_CALL_SUMMARY: 'GET_POST_CALL_SUMMARY',
147
+ GET_MID_CALL_CONSULT_SUMMARY: 'GET_MID_CALL_CONSULT_SUMMARY',
148
+ GET_MID_CALL_TRANSFER_SUMMARY: 'GET_MID_CALL_TRANSFER_SUMMARY',
149
+ POST_CALL_SUMMARY_RESPONSE: 'POST_CALL_SUMMARY_RESPONSE',
150
+ MID_CALL_CONSULT_SUMMARY_RESPONSE: 'MID_CALL_CONSULT_SUMMARY_RESPONSE',
151
+ MID_CALL_TRANSFER_SUMMARY_RESPONSE: 'MID_CALL_TRANSFER_SUMMARY_RESPONSE',
152
+ }),
153
+ CC_TASK_EVENTS: Object.freeze({
154
+ REAL_TIME_TRANSCRIPTION: 'REAL_TIME_TRANSCRIPTION',
155
+ SUGGESTED_RESPONSE: 'SUGGESTED_RESPONSE',
156
+ SUGGESTED_RESPONSE_ACKNOWLEDGE: 'SUGGESTED_RESPONSE_ACKNOWLEDGE',
157
+ POST_CALL_SUMMARY: 'POST_CALL_SUMMARY',
158
+ MID_CALL_SUMMARY: 'MID_CALL_SUMMARY',
159
+ FEATURE_ENABLEMENT: 'FEATURE_ENABLEMENT',
160
+ MID_CALL_SUMMARY_RESPONSE_SUBSEQUENT_AGENT: 'MID_CALL_SUMMARY_RESPONSE_SUBSEQUENT_AGENT',
161
+ }),
162
+ });
163
+
164
+ const MISSING_EXPORT_DIAGNOSTIC_CODES = Object.freeze([2305, 2614, 2724]);
165
+
166
+ const VALID_PUBLIC_CONTRACT_FIXTURE = `
167
+ import {
168
+ AI_SUMMARY_ERROR_CODES,
169
+ CC_TASK_EVENTS,
170
+ TASK_EVENTS,
171
+ } from '../../../src';
172
+ import type {
173
+ AISummaryAction,
174
+ AISummaryFeedback,
175
+ AISummaryResponse,
176
+ AISummaryFeatureEnablement,
177
+ ITask,
178
+ } from '../../../src';
179
+
180
+ const action: AISummaryAction = 'CONSULT';
181
+ const transferAction: AISummaryAction = 'TRANSFER';
182
+ const feedback: AISummaryFeedback = 'thumbs_down';
183
+ const postCallEnabledTrue: AISummaryFeatureEnablement = {
184
+ interactionId: 'post-call-true',
185
+ postCallEnabled: true,
186
+ };
187
+ const postCallEnabledFalse: AISummaryFeatureEnablement = {
188
+ interactionId: 'post-call-false',
189
+ postCallEnabled: false,
190
+ };
191
+ const postCallEnabledOmitted: AISummaryFeatureEnablement = {
192
+ interactionId: 'post-call-omitted',
193
+ midCallEnabled: true,
194
+ };
195
+ const midCallEnabledTrue: AISummaryFeatureEnablement = {
196
+ interactionId: 'mid-call-true',
197
+ midCallEnabled: true,
198
+ };
199
+ const midCallEnabledFalse: AISummaryFeatureEnablement = {
200
+ interactionId: 'mid-call-false',
201
+ midCallEnabled: false,
202
+ };
203
+ const midCallEnabledOmitted: AISummaryFeatureEnablement = {
204
+ interactionId: 'mid-call-omitted',
205
+ postCallEnabled: true,
206
+ };
207
+
208
+ const structuredPostCall: AISummaryResponse = {
209
+ summary: {
210
+ initialContactReason: 'billing',
211
+ additionalContactReasons: 'renewal',
212
+ additionalContext: 'caller asked for an email',
213
+ keyActionsTaken: 'verified account',
214
+ nextSteps: 'send receipt',
215
+ },
216
+ feedback,
217
+ state: 'DEFAULT',
218
+ wrapUpCode: 'resolved',
219
+ numberOfTimesViewed: 1,
220
+ numberOfTimesEdited: 0,
221
+ numberOfTimesCopied: 0,
222
+ };
223
+ const textPostCall: AISummaryResponse = {
224
+ summary: 'plain post call summary',
225
+ feedback: 'thumbs_up',
226
+ state: 'IGNORED',
227
+ wrapUpCode: 'ignored',
228
+ numberOfTimesViewed: 2,
229
+ numberOfTimesEdited: 1,
230
+ numberOfTimesCopied: 1,
231
+ };
232
+ const noPostCallSummary: AISummaryResponse = {
233
+ summary: '',
234
+ feedback: 'none',
235
+ state: 'NOT_RECEIVED',
236
+ wrapUpCode: 'not-received',
237
+ numberOfTimesViewed: 0,
238
+ numberOfTimesEdited: 0,
239
+ numberOfTimesCopied: 0,
240
+ };
241
+
242
+ const structuredMidCall: AISummaryResponse = {
243
+ summaryReceived: true,
244
+ summary: {
245
+ reasonForTransferOrConsult: 'expert needed',
246
+ additionalContext: 'customer has prior ticket',
247
+ keyActionsTaken: 'authenticated caller',
248
+ },
249
+ feedback: 'none',
250
+ state: 'EXCLUDED',
251
+ numberOfTimesViewed: 1,
252
+ numberOfTimesEdited: 0,
253
+ numberOfTimesCopied: 0,
254
+ };
255
+ const textMidCall: AISummaryResponse = {
256
+ summaryReceived: true,
257
+ summary: 'plain mid call summary',
258
+ feedback: 'thumbs_up',
259
+ state: 'MID_CALL_CANCELLED',
260
+ numberOfTimesViewed: 0,
261
+ numberOfTimesEdited: 0,
262
+ numberOfTimesCopied: 0,
263
+ };
264
+ const unavailableMidCall: AISummaryResponse = {
265
+ summaryReceived: false,
266
+ summary: '',
267
+ feedback: 'thumbs_down',
268
+ state: 'NOT_RECEIVED',
269
+ numberOfTimesViewed: 0,
270
+ numberOfTimesEdited: 0,
271
+ numberOfTimesCopied: 0,
272
+ };
273
+ const cancelledMidCall: AISummaryResponse = {
274
+ summaryReceived: false,
275
+ summary: '',
276
+ feedback: 'none',
277
+ state: 'MID_CALL_CANCELLED',
278
+ numberOfTimesViewed: 0,
279
+ numberOfTimesEdited: 0,
280
+ numberOfTimesCopied: 0,
281
+ };
282
+
283
+ const taskSummaryMethods: Pick<
284
+ ITask,
285
+ | 'requestPostCallSummary'
286
+ | 'sendPostCallSummaryResponse'
287
+ | 'requestMidCallSummary'
288
+ | 'sendMidCallSummaryResponse'
289
+ > = {
290
+ requestPostCallSummary: async () => ({conversationId: 'conversation-1'}),
291
+ sendPostCallSummaryResponse: async (payload) => {
292
+ const responseState = payload.state;
293
+ void responseState;
294
+ },
295
+ requestMidCallSummary: async (requestedAction) => {
296
+ const selectedAction: AISummaryAction = requestedAction;
297
+ void selectedAction;
298
+ return {conversationId: 'conversation-1'};
299
+ },
300
+ sendMidCallSummaryResponse: async (payload, requestedAction) => {
301
+ const selectedAction: AISummaryAction = requestedAction;
302
+ const responseState = payload.state;
303
+ void selectedAction;
304
+ void responseState;
305
+ },
306
+ };
307
+
308
+ const inboundPost = CC_TASK_EVENTS.POST_CALL_SUMMARY;
309
+ const receivingEvent = TASK_EVENTS.TASK_MID_CALL_SUMMARY_RECEIVED;
310
+ const disabledCode = AI_SUMMARY_ERROR_CODES.POST_CALL_SUMMARY_DISABLED;
311
+ void action;
312
+ void transferAction;
313
+ void postCallEnabledTrue;
314
+ void postCallEnabledFalse;
315
+ void postCallEnabledOmitted;
316
+ void midCallEnabledTrue;
317
+ void midCallEnabledFalse;
318
+ void midCallEnabledOmitted;
319
+ void structuredPostCall;
320
+ void textPostCall;
321
+ void noPostCallSummary;
322
+ void structuredMidCall;
323
+ void textMidCall;
324
+ void unavailableMidCall;
325
+ void cancelledMidCall;
326
+ void taskSummaryMethods;
327
+ void inboundPost;
328
+ void receivingEvent;
329
+ void disabledCode;
330
+ `;
331
+
332
+ const createInternalRootImportFixture = () => `
333
+ import {
334
+ ${INTERNAL_ROOT_EXPORTS.map((name) => ` ${name},`).join('\n')}
335
+ } from '../../../src';
336
+
337
+ void [
338
+ ${INTERNAL_ROOT_EXPORTS.map((name) => ` ${name},`).join('\n')}
339
+ ];
340
+ `;
341
+
342
+ const INVALID_PUBLIC_CONTRACT_FIXTURE = `
343
+ import {
344
+ type AISummaryAction,
345
+ type AISummaryResponse,
346
+ type AISummaryFeatureEnablement,
347
+ } from '../../../src';
348
+
349
+ let invalidAction: AISummaryAction;
350
+ // @ts-expect-error invalid summary action type must not widen
351
+ invalidAction = 'WRAP_UP';
352
+ void invalidAction;
353
+
354
+ // @ts-expect-error postCallEnabled must stay boolean; string values must not satisfy the public flag contract
355
+ const invalidPostCallEnabledString: AISummaryFeatureEnablement = {interactionId: 'interaction-1', postCallEnabled: 'true'};
356
+ void invalidPostCallEnabledString;
357
+
358
+ // @ts-expect-error postCallEnabled must stay boolean; number values must not satisfy the public flag contract
359
+ const invalidPostCallEnabledNumber: AISummaryFeatureEnablement = {interactionId: 'interaction-2', postCallEnabled: 1};
360
+ void invalidPostCallEnabledNumber;
361
+
362
+ // @ts-expect-error midCallEnabled must stay boolean; string values must not satisfy the public flag contract
363
+ const invalidMidCallEnabledString: AISummaryFeatureEnablement = {interactionId: 'interaction-3', midCallEnabled: 'false'};
364
+ void invalidMidCallEnabledString;
365
+
366
+ // @ts-expect-error midCallEnabled must stay boolean; number values must not satisfy the public flag contract
367
+ const invalidMidCallEnabledNumber: AISummaryFeatureEnablement = {interactionId: 'interaction-4', midCallEnabled: 0};
368
+ void invalidMidCallEnabledNumber;
369
+
370
+ // @ts-expect-error invalid summary feedback must not be accepted
371
+ const invalidFeedback: AISummaryResponse = {summary: 'x', feedback: 'ok', state: 'DEFAULT', wrapUpCode: 'wrap', numberOfTimesViewed: 1, numberOfTimesEdited: 0, numberOfTimesCopied: 0};
372
+ void invalidFeedback;
373
+
374
+ // @ts-expect-error summaryReceived must stay boolean when supplied
375
+ const invalidDiscriminator: AISummaryResponse = {summaryReceived: 'true', summary: 'x', feedback: 'none', state: 'DEFAULT', numberOfTimesViewed: 1, numberOfTimesEdited: 0, numberOfTimesCopied: 0};
376
+ void invalidDiscriminator;
377
+
378
+ // @ts-expect-error unknown summary states must not be accepted
379
+ const invalidSummaryState: AISummaryResponse = {summaryReceived: true, summary: 'x', feedback: 'none', state: 'POST_CALL_ONLY', numberOfTimesViewed: 1, numberOfTimesEdited: 0, numberOfTimesCopied: 0};
380
+ void invalidSummaryState;
381
+
382
+ // @ts-expect-error actionTimeStamp is transport metadata generated by the SDK
383
+ const invalidActionTimestamp: AISummaryResponse = {summary: 'x', feedback: 'none', state: 'DEFAULT', numberOfTimesViewed: 1, numberOfTimesEdited: 0, numberOfTimesCopied: 0, actionTimeStamp: 100};
384
+ void invalidActionTimestamp;
385
+
386
+ // @ts-expect-error publishTimestamp is transport metadata generated by the SDK
387
+ const invalidPublishTimestamp: AISummaryResponse = {summary: 'x', feedback: 'none', state: 'DEFAULT', numberOfTimesViewed: 1, numberOfTimesEdited: 0, numberOfTimesCopied: 0, publishTimestamp: 100};
388
+ void invalidPublishTimestamp;
389
+ `;
390
+
391
+ const LEGACY_TASK_CALL_CONTROL_CONTRACT_FIXTURE = `
392
+ import type {
393
+ ITask,
394
+ TaskResponse,
395
+ } from '../../../src';
396
+
397
+ type IsExact<Actual, Expected> =
398
+ (<Value>() => Value extends Actual ? 1 : 2) extends
399
+ (<Value>() => Value extends Expected ? 1 : 2)
400
+ ? (<Value>() => Value extends Expected ? 1 : 2) extends
401
+ (<Value>() => Value extends Actual ? 1 : 2)
402
+ ? true
403
+ : false
404
+ : false;
405
+ type AssertExact<Actual extends true> = Actual;
406
+
407
+ type ExpectedWrapupParameters = [
408
+ wrapupPayload: {
409
+ wrapUpReason: string;
410
+ auxCodeId: string;
411
+ },
412
+ ];
413
+ type ExpectedConsultParameters = [
414
+ consultPayload: {
415
+ to: string | undefined;
416
+ destinationType: string;
417
+ holdParticipants?: boolean;
418
+ },
419
+ ];
420
+ type ExpectedTransferParameters = [
421
+ transferPayload: {
422
+ to: string;
423
+ destinationType: string;
424
+ },
425
+ options?: {
426
+ [key: string]: unknown;
427
+ },
428
+ ];
429
+
430
+ type WrapupParametersAreRetained = AssertExact<
431
+ IsExact<Parameters<ITask['wrapup']>, ExpectedWrapupParameters>
432
+ >;
433
+ type WrapupReturnIsRetained = AssertExact<
434
+ IsExact<ReturnType<ITask['wrapup']>, Promise<TaskResponse>>
435
+ >;
436
+ type ConsultParametersAreRetained = AssertExact<
437
+ IsExact<Parameters<ITask['consult']>, ExpectedConsultParameters>
438
+ >;
439
+ type ConsultReturnIsRetained = AssertExact<
440
+ IsExact<ReturnType<ITask['consult']>, Promise<TaskResponse>>
441
+ >;
442
+ type TransferParametersAreRetained = AssertExact<
443
+ IsExact<Parameters<ITask['transfer']>, ExpectedTransferParameters>
444
+ >;
445
+ type TransferReturnIsRetained = AssertExact<
446
+ IsExact<ReturnType<ITask['transfer']>, Promise<TaskResponse>>
447
+ >;
448
+
449
+ declare const task: ITask;
450
+
451
+ const wrapupResult: Promise<TaskResponse> = task.wrapup({
452
+ wrapUpReason: 'Customer issue resolved',
453
+ auxCodeId: 'RESOLVED',
454
+ });
455
+ const consultResult: Promise<TaskResponse> = task.consult({
456
+ to: 'agent-1',
457
+ destinationType: 'agent',
458
+ });
459
+ const consultWithOptionalHoldResult: Promise<TaskResponse> = task.consult({
460
+ to: undefined,
461
+ destinationType: 'queue',
462
+ holdParticipants: true,
463
+ });
464
+ const transferResult: Promise<TaskResponse> = task.transfer({
465
+ to: 'queue-1',
466
+ destinationType: 'queue',
467
+ });
468
+ const transferWithOptionsResult: Promise<TaskResponse> = task.transfer(
469
+ {
470
+ to: 'agent-2',
471
+ destinationType: 'agent',
472
+ },
473
+ {trackingId: 'transfer-1'}
474
+ );
475
+
476
+ // @ts-expect-error wrapup must keep requiring its retained payload tuple
477
+ task.wrapup();
478
+ // @ts-expect-error wrapup payload must keep auxCodeId as a required field
479
+ task.wrapup({wrapUpReason: 'Customer issue resolved'});
480
+ // @ts-expect-error wrapup payload must not accept AI summary response fields threaded into the call control API
481
+ task.wrapup({wrapUpReason: 'Customer issue resolved', auxCodeId: 'RESOLVED', actionTimeStamp: 100});
482
+ // @ts-expect-error wrapup payload must not accept post-call summary state as a control argument
483
+ task.wrapup({wrapUpReason: 'Customer issue resolved', auxCodeId: 'RESOLVED', state: 'DEFAULT'});
484
+
485
+ // @ts-expect-error consult must keep requiring its retained payload tuple
486
+ task.consult();
487
+ // @ts-expect-error consult payload must keep destinationType as a string
488
+ task.consult({to: 'agent-1', destinationType: 1});
489
+ // @ts-expect-error consult payload must not accept mid-call summary action fields threaded into the payload
490
+ task.consult({to: 'agent-1', destinationType: 'agent', actionType: 'CONSULT'});
491
+ // @ts-expect-error consult must not accept a feature action as a second argument
492
+ task.consult({to: 'agent-1', destinationType: 'agent'}, 'CONSULT');
493
+
494
+ // @ts-expect-error transfer must keep requiring its retained payload tuple
495
+ task.transfer();
496
+ // @ts-expect-error transfer payload must keep to as a required string field
497
+ task.transfer({destinationType: 'queue'});
498
+ // @ts-expect-error transfer payload must keep destinationType as a string
499
+ task.transfer({to: 'queue-1', destinationType: 1});
500
+ // @ts-expect-error transfer payload must not accept mid-call summary action fields threaded into the payload
501
+ task.transfer({to: 'agent-2', destinationType: 'agent', actionType: 'TRANSFER'});
502
+ // @ts-expect-error transfer options must not be replaced by a feature action argument
503
+ task.transfer({to: 'agent-2', destinationType: 'agent'}, 'TRANSFER');
504
+ // @ts-expect-error transfer must not accept a third feature action argument
505
+ task.transfer({to: 'agent-2', destinationType: 'agent'}, {trackingId: 'transfer-2'}, 'TRANSFER');
506
+
507
+ void wrapupResult;
508
+ void consultResult;
509
+ void consultWithOptionalHoldResult;
510
+ void transferResult;
511
+ void transferWithOptionsResult;
512
+ `;
513
+
514
+ const createProgram = (virtualSources: Record<string, string> = {}) => {
515
+ const configPath = path.join(CONTACT_CENTER_ROOT, 'tsconfig.json');
516
+ const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
517
+ const parsed = ts.parseJsonConfigFileContent(
518
+ configFile.config,
519
+ ts.sys,
520
+ CONTACT_CENTER_ROOT,
521
+ {emitDeclarationOnly: false, noEmit: true},
522
+ configPath
523
+ );
524
+ const virtualFileNames = Object.keys(virtualSources);
525
+ const host = ts.createCompilerHost(parsed.options, true);
526
+ const originalGetSourceFile = host.getSourceFile.bind(host);
527
+ const originalFileExists = host.fileExists.bind(host);
528
+ const originalReadFile = host.readFile.bind(host);
529
+
530
+ host.getSourceFile = (fileName, languageVersion, onError, shouldCreateNewSourceFile) => {
531
+ const normalizedFileName = path.normalize(fileName);
532
+ if (Object.prototype.hasOwnProperty.call(virtualSources, normalizedFileName)) {
533
+ return ts.createSourceFile(
534
+ normalizedFileName,
535
+ virtualSources[normalizedFileName],
536
+ languageVersion,
537
+ true
538
+ );
539
+ }
540
+
541
+ return originalGetSourceFile(
542
+ fileName,
543
+ languageVersion,
544
+ onError,
545
+ shouldCreateNewSourceFile
546
+ );
547
+ };
548
+
549
+ host.fileExists = (fileName) => {
550
+ const normalizedFileName = path.normalize(fileName);
551
+ return Object.prototype.hasOwnProperty.call(virtualSources, normalizedFileName)
552
+ ? true
553
+ : originalFileExists(fileName);
554
+ };
555
+
556
+ host.readFile = (fileName) => {
557
+ const normalizedFileName = path.normalize(fileName);
558
+ return Object.prototype.hasOwnProperty.call(virtualSources, normalizedFileName)
559
+ ? virtualSources[normalizedFileName]
560
+ : originalReadFile(fileName);
561
+ };
562
+
563
+ return ts.createProgram([...parsed.fileNames, ...virtualFileNames], parsed.options, host);
564
+ };
565
+
566
+ const getRootModuleSymbol = (program: ts.Program) => {
567
+ const checker = program.getTypeChecker();
568
+ const indexSource = program.getSourceFile(INDEX_PATH);
569
+ if (!indexSource) {
570
+ throw new Error(`Missing source file ${INDEX_PATH}`);
571
+ }
572
+ const moduleSymbol = checker.getSymbolAtLocation(indexSource);
573
+ if (!moduleSymbol) {
574
+ throw new Error('Unable to resolve contact-center root module symbol');
575
+ }
576
+
577
+ return moduleSymbol;
578
+ };
579
+
580
+ const getRootExportNames = (program: ts.Program) => {
581
+ const checker = program.getTypeChecker();
582
+
583
+ return checker
584
+ .getExportsOfModule(getRootModuleSymbol(program))
585
+ .map((symbol) => symbol.getName())
586
+ .sort();
587
+ };
588
+
589
+ const getRootExportSymbol = (program: ts.Program, exportName: string) => {
590
+ return getModuleExportSymbol(program, INDEX_PATH, exportName);
591
+ };
592
+
593
+ const getModuleExportSymbol = (
594
+ program: ts.Program,
595
+ modulePath: string,
596
+ exportName: string
597
+ ) => {
598
+ const checker = program.getTypeChecker();
599
+ const sourceFile = program.getSourceFile(modulePath);
600
+ if (!sourceFile) {
601
+ throw new Error(`Missing source file ${modulePath}`);
602
+ }
603
+
604
+ const moduleSymbol = checker.getSymbolAtLocation(sourceFile);
605
+ if (!moduleSymbol) {
606
+ throw new Error(`Unable to resolve module symbol ${modulePath}`);
607
+ }
608
+
609
+ const exportSymbol = checker
610
+ .getExportsOfModule(moduleSymbol)
611
+ .find((symbol) => symbol.getName() === exportName);
612
+
613
+ if (!exportSymbol) {
614
+ throw new Error(`Missing root export ${exportName}`);
615
+ }
616
+
617
+ return resolveSymbol(checker, exportSymbol);
618
+ };
619
+
620
+ const getDiagnosticsForFiles = (program: ts.Program, fileNames: string[]) =>
621
+ ts.getPreEmitDiagnostics(program).filter((diagnostic) => {
622
+ const fileName = diagnostic.file?.fileName;
623
+
624
+ return !!fileName && fileNames.includes(fileName);
625
+ });
626
+
627
+ const getMissingExportNameFromDiagnostic = (diagnostic: ts.Diagnostic) => {
628
+ const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
629
+ const match = message.match(/has no exported member(?: named)? '([^']+)'/);
630
+
631
+ if (!match) {
632
+ throw new Error(`Unexpected TS${diagnostic.code} diagnostic: ${message}`);
633
+ }
634
+
635
+ return match[1];
636
+ };
637
+
638
+ const getCanonicalMissingExportDiagnosticCode = (diagnostic: ts.Diagnostic) => {
639
+ if (
640
+ MISSING_EXPORT_DIAGNOSTIC_CODES.includes(diagnostic.code) &&
641
+ getMissingExportNameFromDiagnostic(diagnostic)
642
+ ) {
643
+ return 2305;
644
+ }
645
+
646
+ return diagnostic.code;
647
+ };
648
+
649
+ const getObjectLiteralInitializer = (symbol: ts.Symbol | undefined, symbolName: string) => {
650
+ const declaration = symbol?.valueDeclaration ?? symbol?.declarations?.[0];
651
+
652
+ if (!declaration || !ts.isVariableDeclaration(declaration)) {
653
+ throw new Error(`Root export ${symbolName} does not resolve to a variable declaration`);
654
+ }
655
+
656
+ let initializer = declaration.initializer;
657
+ if (!initializer) {
658
+ throw new Error(`Root export ${symbolName} is missing an initializer`);
659
+ }
660
+
661
+ while (ts.isAsExpression(initializer)) {
662
+ initializer = initializer.expression;
663
+ }
664
+
665
+ if (!ts.isObjectLiteralExpression(initializer)) {
666
+ throw new Error(`Root export ${symbolName} does not resolve to an object literal`);
667
+ }
668
+
669
+ return initializer;
670
+ };
671
+
672
+ const getStringLiteralObjectEntries = (objectLiteral: ts.ObjectLiteralExpression) =>
673
+ objectLiteral.properties.map((property) => {
674
+ if (
675
+ !ts.isPropertyAssignment(property) ||
676
+ !ts.isIdentifier(property.name) ||
677
+ !ts.isStringLiteral(property.initializer)
678
+ ) {
679
+ throw new Error('Expected string-literal object property assignment');
680
+ }
681
+
682
+ return [property.name.text, property.initializer.text];
683
+ });
684
+
685
+ const getNamedStringLiteralObjectEntries = (
686
+ objectLiteral: ts.ObjectLiteralExpression,
687
+ propertyNames: string[],
688
+ symbolName: string
689
+ ) =>
690
+ propertyNames.map((propertyName) => {
691
+ const property = objectLiteral.properties.find(
692
+ (candidate): candidate is ts.PropertyAssignment =>
693
+ ts.isPropertyAssignment(candidate) &&
694
+ ts.isIdentifier(candidate.name) &&
695
+ candidate.name.text === propertyName
696
+ );
697
+
698
+ if (!property) {
699
+ throw new Error(`Missing ${symbolName}.${propertyName}`);
700
+ }
701
+
702
+ if (!ts.isStringLiteral(property.initializer)) {
703
+ throw new Error(`Expected ${symbolName}.${propertyName} to be a string literal`);
704
+ }
705
+
706
+ return [propertyName, property.initializer.text];
707
+ });
708
+
709
+ const getObjectLiteralVariableInitializer = (
710
+ sourceFile: ts.SourceFile,
711
+ variableName: string
712
+ ) => {
713
+ let objectLiteral: ts.ObjectLiteralExpression | undefined;
714
+
715
+ const visit = (node: ts.Node) => {
716
+ if (
717
+ ts.isVariableDeclaration(node) &&
718
+ ts.isIdentifier(node.name) &&
719
+ node.name.text === variableName &&
720
+ node.initializer
721
+ ) {
722
+ const initializer = ts.isAsExpression(node.initializer)
723
+ ? node.initializer.expression
724
+ : node.initializer;
725
+
726
+ if (!ts.isObjectLiteralExpression(initializer)) {
727
+ throw new Error(`${variableName} does not resolve to an object literal`);
728
+ }
729
+
730
+ objectLiteral = initializer;
731
+ return;
732
+ }
733
+
734
+ ts.forEachChild(node, visit);
735
+ };
736
+
737
+ visit(sourceFile);
738
+
739
+ if (!objectLiteral) {
740
+ throw new Error(`Missing ${variableName} object literal`);
741
+ }
742
+
743
+ return objectLiteral;
744
+ };
745
+
746
+ const getObjectLiteralPropertyAssignment = (
747
+ objectLiteral: ts.ObjectLiteralExpression,
748
+ propertyName: string,
749
+ symbolName: string
750
+ ) => {
751
+ const property = objectLiteral.properties.find(
752
+ (candidate): candidate is ts.PropertyAssignment =>
753
+ ts.isPropertyAssignment(candidate) &&
754
+ ts.isIdentifier(candidate.name) &&
755
+ candidate.name.text === propertyName
756
+ );
757
+
758
+ if (!property) {
759
+ throw new Error(`Missing ${symbolName}.${propertyName}`);
760
+ }
761
+
762
+ return property;
763
+ };
764
+
765
+ const entriesToObject = (entries: string[][]) =>
766
+ entries.reduce<Record<string, string>>((accumulator, [name, value]) => {
767
+ accumulator[name] = value;
768
+
769
+ return accumulator;
770
+ }, {});
771
+
772
+ const resolveSymbol = (checker: ts.TypeChecker, symbol: ts.Symbol | undefined) => {
773
+ if (!symbol) return undefined;
774
+
775
+ return symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
776
+ };
777
+
778
+ describe('contact-center root public contract', () => {
779
+ it('preserves the literal root barrel export list and omits package internals', () => {
780
+ const program = createProgram();
781
+ const exportNames = getRootExportNames(program);
782
+
783
+ expect(exportNames).toEqual([...EXPECTED_ROOT_EXPORTS].sort());
784
+ INTERNAL_ROOT_EXPORTS.forEach((name) => {
785
+ expect(exportNames).not.toContain(name);
786
+ });
787
+ });
788
+
789
+ it('rejects root imports of package internals with TS2305 diagnostics', () => {
790
+ const internalFixture = path.join(
791
+ CONTACT_CENTER_ROOT,
792
+ 'test/unit/spec/__root_internals.ts'
793
+ );
794
+ const program = createProgram({
795
+ [internalFixture]: createInternalRootImportFixture(),
796
+ });
797
+ const diagnostics = getDiagnosticsForFiles(program, [internalFixture]);
798
+
799
+ expect(diagnostics.map(getCanonicalMissingExportDiagnosticCode)).toEqual(
800
+ INTERNAL_ROOT_EXPORTS.map(() => 2305)
801
+ );
802
+ expect(diagnostics.map(getMissingExportNameFromDiagnostic).sort()).toEqual(
803
+ [...INTERNAL_ROOT_EXPORTS].sort()
804
+ );
805
+ });
806
+
807
+ it('re-exports the exact AI summary error code object from the root symbol', () => {
808
+ const program = createProgram();
809
+ const errorCodeEntries = getStringLiteralObjectEntries(
810
+ getObjectLiteralInitializer(
811
+ getRootExportSymbol(program, 'AI_SUMMARY_ERROR_CODES'),
812
+ 'AI_SUMMARY_ERROR_CODES'
813
+ )
814
+ );
815
+
816
+ expect(errorCodeEntries).toEqual(EXPECTED_AI_SUMMARY_ERROR_CODES);
817
+ });
818
+
819
+ it('pins AI summary wire event literals to the backend contract', () => {
820
+ const program = createProgram();
821
+ const aiAssistantEventNameLiterals = entriesToObject(
822
+ getNamedStringLiteralObjectEntries(
823
+ getObjectLiteralInitializer(
824
+ getModuleExportSymbol(program, TYPES_PATH, 'AIAssistantEventName'),
825
+ 'AIAssistantEventName'
826
+ ),
827
+ Object.keys(EXPECTED_AI_SUMMARY_WIRE_LITERALS.AIAssistantEventName),
828
+ 'AIAssistantEventName'
829
+ )
830
+ );
831
+ const ccAISummaryEventLiterals = entriesToObject(
832
+ getNamedStringLiteralObjectEntries(
833
+ getObjectLiteralInitializer(
834
+ getRootExportSymbol(program, 'CC_TASK_EVENTS'),
835
+ 'CC_TASK_EVENTS'
836
+ ),
837
+ Object.keys(EXPECTED_AI_SUMMARY_WIRE_LITERALS.CC_TASK_EVENTS),
838
+ 'CC_TASK_EVENTS'
839
+ )
840
+ );
841
+
842
+ expect({
843
+ AIAssistantEventName: aiAssistantEventNameLiterals,
844
+ CC_TASK_EVENTS: ccAISummaryEventLiterals,
845
+ }).toEqual(EXPECTED_AI_SUMMARY_WIRE_LITERALS);
846
+ });
847
+
848
+ it('type-checks public AI summary assignments and keeps invalid branches narrow', () => {
849
+ const validFixture = path.join(CONTACT_CENTER_ROOT, 'test/unit/spec/__ai_summary_valid.ts');
850
+ const invalidFixture = path.join(
851
+ CONTACT_CENTER_ROOT,
852
+ 'test/unit/spec/__ai_summary_invalid.ts'
853
+ );
854
+ const program = createProgram({
855
+ [validFixture]: VALID_PUBLIC_CONTRACT_FIXTURE,
856
+ [invalidFixture]: INVALID_PUBLIC_CONTRACT_FIXTURE,
857
+ });
858
+ const fixtureDiagnostics = getDiagnosticsForFiles(program, [validFixture, invalidFixture]);
859
+
860
+ expect(
861
+ fixtureDiagnostics.map((diagnostic) => ({
862
+ code: diagnostic.code,
863
+ message: ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'),
864
+ }))
865
+ ).toEqual([]);
866
+ });
867
+
868
+ it('pins retained ITask wrapup, consult, and transfer signatures', () => {
869
+ const legacyTaskContractFixture = path.join(
870
+ CONTACT_CENTER_ROOT,
871
+ 'test/unit/spec/__legacy_task_call_control_contract.ts'
872
+ );
873
+ const program = createProgram({
874
+ [legacyTaskContractFixture]: LEGACY_TASK_CALL_CONTROL_CONTRACT_FIXTURE,
875
+ });
876
+ const fixtureDiagnostics = getDiagnosticsForFiles(program, [legacyTaskContractFixture]);
877
+
878
+ expect(
879
+ fixtureDiagnostics.map((diagnostic) => ({
880
+ code: diagnostic.code,
881
+ message: ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'),
882
+ }))
883
+ ).toEqual([]);
884
+ });
885
+ });