@assistant-ui/core 0.3.18 → 0.3.19

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 (274) hide show
  1. package/dist/adapters/speech.d.ts.map +1 -1
  2. package/dist/adapters/speech.js +13 -3
  3. package/dist/adapters/speech.js.map +1 -1
  4. package/dist/adapters/thread-history.d.ts +4 -0
  5. package/dist/adapters/thread-history.d.ts.map +1 -1
  6. package/dist/index.d.ts +2 -2
  7. package/dist/index.js.map +1 -1
  8. package/dist/internal.d.ts +1 -1
  9. package/dist/model-context/frame/host.d.ts.map +1 -1
  10. package/dist/model-context/frame/host.js +26 -11
  11. package/dist/model-context/frame/host.js.map +1 -1
  12. package/dist/model-context/interactable-composer-metadata.js +11 -9
  13. package/dist/model-context/interactable-composer-metadata.js.map +1 -1
  14. package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts.map +1 -1
  15. package/dist/react/adapters/LocalStorageThreadListAdapter.js +45 -7
  16. package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
  17. package/dist/react/client/DataRenderers.d.ts.map +1 -1
  18. package/dist/react/client/DataRenderers.js +20 -15
  19. package/dist/react/client/DataRenderers.js.map +1 -1
  20. package/dist/react/client/Interactables.d.ts.map +1 -1
  21. package/dist/react/client/Interactables.js +11 -5
  22. package/dist/react/client/Interactables.js.map +1 -1
  23. package/dist/react/client/RemoteThreadList.d.ts.map +1 -1
  24. package/dist/react/client/RemoteThreadList.js +3 -2
  25. package/dist/react/client/RemoteThreadList.js.map +1 -1
  26. package/dist/react/client/interactable-model-context.d.ts.map +1 -1
  27. package/dist/react/client/interactable-model-context.js +3 -2
  28. package/dist/react/client/interactable-model-context.js.map +1 -1
  29. package/dist/react/index.d.ts +2 -2
  30. package/dist/react/index.js +2 -2
  31. package/dist/react/interactables-legacy/useAssistantInteractable.d.ts.map +1 -1
  32. package/dist/react/interactables-legacy/useAssistantInteractable.js +3 -0
  33. package/dist/react/interactables-legacy/useAssistantInteractable.js.map +1 -1
  34. package/dist/react/model-context/useInteractable.d.ts.map +1 -1
  35. package/dist/react/model-context/useInteractable.js +4 -1
  36. package/dist/react/model-context/useInteractable.js.map +1 -1
  37. package/dist/react/model-context/useInteractableVersions.js +1 -1
  38. package/dist/react/primitives/message/MessageGroupedParts.d.ts +11 -2
  39. package/dist/react/primitives/message/MessageGroupedParts.d.ts.map +1 -1
  40. package/dist/react/primitives/message/MessageGroupedParts.js +3 -2
  41. package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
  42. package/dist/react/primitives/part/PartMessages.d.ts +1 -0
  43. package/dist/react/primitives/part/PartMessages.d.ts.map +1 -1
  44. package/dist/react/primitives/part/PartMessages.js +1 -0
  45. package/dist/react/primitives/part/PartMessages.js.map +1 -1
  46. package/dist/react/primitives/thread/ThreadMessages.d.ts.map +1 -1
  47. package/dist/react/primitives/thread/ThreadMessages.js +6 -5
  48. package/dist/react/primitives/thread/ThreadMessages.js.map +1 -1
  49. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
  50. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +2 -1
  51. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
  52. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts +2 -24
  53. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
  54. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +135 -374
  55. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
  56. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts +1 -0
  57. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts.map +1 -1
  58. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js +22 -2
  59. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js.map +1 -1
  60. package/dist/react/runtimes/cloud/auiV0.d.ts +40 -15
  61. package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
  62. package/dist/react/runtimes/cloud/auiV0.js +62 -15
  63. package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
  64. package/dist/react/runtimes/cloud/createCloudThreadListAdapter.d.ts +2 -1
  65. package/dist/react/runtimes/cloud/createCloudThreadListAdapter.d.ts.map +1 -1
  66. package/dist/react/runtimes/cloud/createCloudThreadListAdapter.js +4 -0
  67. package/dist/react/runtimes/cloud/createCloudThreadListAdapter.js.map +1 -1
  68. package/dist/react/runtimes/cloud/sdkIdentity.d.ts +6 -0
  69. package/dist/react/runtimes/cloud/sdkIdentity.d.ts.map +1 -0
  70. package/dist/react/runtimes/cloud/sdkIdentity.js +9 -0
  71. package/dist/react/runtimes/cloud/sdkIdentity.js.map +1 -0
  72. package/dist/react/runtimes/external-message-converter.d.ts +12 -2
  73. package/dist/react/runtimes/external-message-converter.d.ts.map +1 -1
  74. package/dist/react/runtimes/external-message-converter.js +26 -61
  75. package/dist/react/runtimes/external-message-converter.js.map +1 -1
  76. package/dist/react/runtimes/useRemoteThreadListRuntime.js +1 -1
  77. package/dist/react/runtimes/useRemoteThreadListRuntime.js.map +1 -1
  78. package/dist/react/utils/groupParts.d.ts +6 -1
  79. package/dist/react/utils/groupParts.d.ts.map +1 -1
  80. package/dist/react/utils/groupParts.js +6 -0
  81. package/dist/react/utils/groupParts.js.map +1 -1
  82. package/dist/react/utils/useJSONEqual.d.ts +3 -1
  83. package/dist/react/utils/useJSONEqual.d.ts.map +1 -1
  84. package/dist/react/utils/useJSONEqual.js +6 -1
  85. package/dist/react/utils/useJSONEqual.js.map +1 -1
  86. package/dist/react/utils/useJSONSchemaDependency.d.ts +7 -0
  87. package/dist/react/utils/useJSONSchemaDependency.d.ts.map +1 -0
  88. package/dist/react/utils/useJSONSchemaDependency.js +20 -0
  89. package/dist/react/utils/useJSONSchemaDependency.js.map +1 -0
  90. package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
  91. package/dist/runtime/api/thread-runtime.js +2 -5
  92. package/dist/runtime/api/thread-runtime.js.map +1 -1
  93. package/dist/runtime/base/base-composer-runtime-core.d.ts +1 -0
  94. package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
  95. package/dist/runtime/base/base-composer-runtime-core.js +46 -10
  96. package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
  97. package/dist/runtime/base/base-thread-runtime-core.d.ts +2 -0
  98. package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
  99. package/dist/runtime/base/base-thread-runtime-core.js +155 -64
  100. package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
  101. package/dist/runtime/interfaces/thread-runtime-core.d.ts +6 -0
  102. package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -1
  103. package/dist/runtime/queue/message-queue.d.ts +5 -0
  104. package/dist/runtime/queue/message-queue.d.ts.map +1 -1
  105. package/dist/runtime/queue/message-queue.js +61 -6
  106. package/dist/runtime/queue/message-queue.js.map +1 -1
  107. package/dist/runtime/utils/auto-status.d.ts +6 -2
  108. package/dist/runtime/utils/auto-status.d.ts.map +1 -1
  109. package/dist/runtime/utils/auto-status.js +12 -4
  110. package/dist/runtime/utils/auto-status.js.map +1 -1
  111. package/dist/runtime/utils/external-message-conversion.d.ts +16 -4
  112. package/dist/runtime/utils/external-message-conversion.d.ts.map +1 -1
  113. package/dist/runtime/utils/external-message-conversion.js +48 -12
  114. package/dist/runtime/utils/external-message-conversion.js.map +1 -1
  115. package/dist/runtime/utils/message-repository.js +3 -3
  116. package/dist/runtime/utils/message-repository.js.map +1 -1
  117. package/dist/runtime/utils/thread-message-like.d.ts +2 -1
  118. package/dist/runtime/utils/thread-message-like.d.ts.map +1 -1
  119. package/dist/runtime/utils/thread-message-like.js +4 -2
  120. package/dist/runtime/utils/thread-message-like.js.map +1 -1
  121. package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
  122. package/dist/runtimes/external-store/external-store-thread-runtime-core.js +8 -1
  123. package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
  124. package/dist/runtimes/internal.d.ts +1 -1
  125. package/dist/runtimes/local/local-thread-runtime-core.d.ts +1 -1
  126. package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
  127. package/dist/runtimes/local/local-thread-runtime-core.js +4 -1
  128. package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
  129. package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts.map +1 -1
  130. package/dist/runtimes/tool-invocations/ToolInvocationTracker.js +2 -1
  131. package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
  132. package/dist/store/clients/external-thread.d.ts.map +1 -1
  133. package/dist/store/clients/external-thread.js +241 -200
  134. package/dist/store/clients/external-thread.js.map +1 -1
  135. package/dist/store/clients/thread-tasks.d.ts +13 -0
  136. package/dist/store/clients/thread-tasks.d.ts.map +1 -0
  137. package/dist/store/clients/thread-tasks.js +69 -0
  138. package/dist/store/clients/thread-tasks.js.map +1 -0
  139. package/dist/store/index.d.ts +3 -2
  140. package/dist/store/index.js +3 -3
  141. package/dist/store/primitive-predicates.d.ts.map +1 -1
  142. package/dist/store/primitive-predicates.js +4 -4
  143. package/dist/store/primitive-predicates.js.map +1 -1
  144. package/dist/store/runtime-clients/thread-runtime-client.d.ts.map +1 -1
  145. package/dist/store/runtime-clients/thread-runtime-client.js +176 -128
  146. package/dist/store/runtime-clients/thread-runtime-client.js.map +1 -1
  147. package/dist/store/scope-registration.d.ts +2 -0
  148. package/dist/store/scope-registration.d.ts.map +1 -1
  149. package/dist/store/scopes/task.d.ts +36 -0
  150. package/dist/store/scopes/task.d.ts.map +1 -0
  151. package/dist/store/scopes/task.js +0 -0
  152. package/dist/store/scopes/thread.d.ts +20 -0
  153. package/dist/store/scopes/thread.d.ts.map +1 -1
  154. package/dist/subscribable/subscribable.d.ts +2 -1
  155. package/dist/subscribable/subscribable.d.ts.map +1 -1
  156. package/dist/subscribable/subscribable.js +23 -15
  157. package/dist/subscribable/subscribable.js.map +1 -1
  158. package/dist/types/index.d.ts +2 -2
  159. package/dist/types/message.d.ts +8 -1
  160. package/dist/types/message.d.ts.map +1 -1
  161. package/dist/types/message.js.map +1 -1
  162. package/dist/utils/abortable-iterable.d.ts.map +1 -1
  163. package/dist/utils/abortable-iterable.js +30 -14
  164. package/dist/utils/abortable-iterable.js.map +1 -1
  165. package/dist/utils/getGroupStatus.d.ts +18 -2
  166. package/dist/utils/getGroupStatus.d.ts.map +1 -1
  167. package/dist/utils/getGroupStatus.js +32 -7
  168. package/dist/utils/getGroupStatus.js.map +1 -1
  169. package/dist/utils/wire-media.d.ts.map +1 -1
  170. package/dist/utils/wire-media.js +2 -2
  171. package/dist/utils/wire-media.js.map +1 -1
  172. package/package.json +6 -6
  173. package/src/adapters/speech.test.ts +236 -0
  174. package/src/adapters/speech.ts +17 -10
  175. package/src/adapters/thread-history.ts +3 -0
  176. package/src/index.ts +1 -0
  177. package/src/model-context/frame/host.test.ts +113 -1
  178. package/src/model-context/frame/host.ts +39 -12
  179. package/src/model-context/interactable-composer-metadata.test.ts +30 -0
  180. package/src/model-context/interactable-composer-metadata.ts +10 -10
  181. package/src/react/adapters/LocalStorageThreadListAdapter.test.ts +244 -0
  182. package/src/react/adapters/LocalStorageThreadListAdapter.tsx +104 -7
  183. package/src/react/client/DataRenderers.test.tsx +45 -0
  184. package/src/react/client/DataRenderers.ts +13 -9
  185. package/src/react/client/Interactables.test.ts +44 -1
  186. package/src/react/client/Interactables.ts +7 -1
  187. package/src/react/client/RemoteThreadList.test.ts +41 -1
  188. package/src/react/client/RemoteThreadList.ts +15 -2
  189. package/src/react/client/interactable-model-context.test.ts +44 -0
  190. package/src/react/client/interactable-model-context.ts +3 -2
  191. package/src/react/index.ts +5 -1
  192. package/src/react/interactables-legacy/useAssistantInteractable.test.tsx +132 -0
  193. package/src/react/interactables-legacy/useAssistantInteractable.ts +10 -1
  194. package/src/react/model-context/useInteractable.test.tsx +177 -0
  195. package/src/react/model-context/useInteractable.ts +3 -0
  196. package/src/react/primitive-hooks/useActionBarCopy.test.ts +0 -1
  197. package/src/react/primitive-hooks/useSuggestionTrigger.test.ts +0 -1
  198. package/src/react/primitives/message/MessageGroupedParts.test.tsx +96 -0
  199. package/src/react/primitives/message/MessageGroupedParts.tsx +15 -4
  200. package/src/react/primitives/part/PartMessages.test.tsx +104 -1
  201. package/src/react/primitives/part/PartMessages.tsx +1 -0
  202. package/src/react/primitives/thread/ThreadMessages.test.tsx +142 -0
  203. package/src/react/primitives/thread/ThreadMessages.tsx +8 -5
  204. package/src/react/providers/ReadonlyThreadProvider.test.tsx +56 -0
  205. package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +7 -1
  206. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.ts +20 -14
  207. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.tsx +221 -1
  208. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +166 -512
  209. package/src/react/runtimes/cloud/CloudFileAttachmentAdapter.test.ts +77 -0
  210. package/src/react/runtimes/cloud/CloudFileAttachmentAdapter.ts +27 -1
  211. package/src/react/runtimes/cloud/auiV0.ts +160 -25
  212. package/src/react/runtimes/cloud/createCloudThreadListAdapter.test.ts +21 -0
  213. package/src/react/runtimes/cloud/createCloudThreadListAdapter.ts +7 -1
  214. package/src/react/runtimes/cloud/sdkIdentity.ts +9 -0
  215. package/src/react/runtimes/cloud/useCloudThreadListAdapter.test.tsx +18 -4
  216. package/src/react/runtimes/external-message-converter.test.ts +136 -1
  217. package/src/react/runtimes/external-message-converter.ts +39 -93
  218. package/src/react/runtimes/useRemoteThreadListRuntime.ts +1 -1
  219. package/src/react/utils/groupParts.ts +12 -1
  220. package/src/react/utils/useJSONEqual.ts +9 -0
  221. package/src/react/utils/useJSONSchemaDependency.ts +22 -0
  222. package/src/runtime/api/thread-runtime.test.ts +58 -0
  223. package/src/runtime/api/thread-runtime.ts +2 -4
  224. package/src/runtime/base/base-composer-runtime-core.ts +69 -16
  225. package/src/runtime/base/base-thread-runtime-core.test.ts +1008 -1
  226. package/src/runtime/base/base-thread-runtime-core.ts +222 -83
  227. package/src/runtime/interfaces/thread-runtime-core.ts +6 -0
  228. package/src/runtime/queue/message-queue.ts +68 -6
  229. package/src/runtime/utils/auto-status.test.ts +112 -1
  230. package/src/runtime/utils/auto-status.ts +31 -5
  231. package/src/runtime/utils/external-message-conversion.test.ts +134 -0
  232. package/src/runtime/utils/external-message-conversion.ts +122 -31
  233. package/src/runtime/utils/message-repository.test.ts +49 -0
  234. package/src/runtime/utils/message-repository.ts +3 -3
  235. package/src/runtime/utils/thread-message-like.test.ts +52 -0
  236. package/src/runtime/utils/thread-message-like.ts +4 -0
  237. package/src/runtimes/external-store/external-store-thread-runtime-core.ts +31 -1
  238. package/src/runtimes/local/local-thread-runtime-core.test.ts +21 -0
  239. package/src/runtimes/local/local-thread-runtime-core.ts +11 -1
  240. package/src/runtimes/tool-invocations/EDGE_CASES.md +2 -6
  241. package/src/runtimes/tool-invocations/ToolInvocationTracker.test.ts +133 -0
  242. package/src/runtimes/tool-invocations/ToolInvocationTracker.ts +10 -6
  243. package/src/store/clients/external-thread.ts +19 -1
  244. package/src/store/clients/thread-tasks.test.ts +274 -0
  245. package/src/store/clients/thread-tasks.ts +138 -0
  246. package/src/store/index.ts +8 -0
  247. package/src/store/primitive-predicates.test.ts +48 -5
  248. package/src/store/primitive-predicates.ts +7 -2
  249. package/src/store/runtime-clients/thread-runtime-client.ts +31 -1
  250. package/src/store/scope-registration.ts +2 -0
  251. package/src/store/scopes/task.ts +34 -0
  252. package/src/store/scopes/thread.ts +16 -0
  253. package/src/store/thread-tasks.test.tsx +209 -0
  254. package/src/subscribable/subscribable.test.ts +156 -1
  255. package/src/subscribable/subscribable.ts +25 -15
  256. package/src/tests/MessageRepository.test.ts +1 -5
  257. package/src/tests/auiV0Encode.test.ts +300 -0
  258. package/src/tests/base-composer-runtime-core-send.test.ts +51 -0
  259. package/src/tests/base-composer-runtime-core.test.ts +314 -2
  260. package/src/tests/external-store-thread-runtime-core-adapter.test.ts +151 -0
  261. package/src/tests/external-thread-attachments.test.tsx +69 -0
  262. package/src/tests/external-thread-parity.test.tsx +34 -0
  263. package/src/tests/groupParts.test.ts +71 -0
  264. package/src/tests/message-queue.test.ts +253 -0
  265. package/src/tests/remote-thread-list-reactive-threadId.test.ts +51 -0
  266. package/src/tests/useRemoteThreadListRuntime-controlled.test.tsx +43 -0
  267. package/src/types/index.ts +1 -0
  268. package/src/types/message.ts +8 -0
  269. package/src/utils/abortable-iterable.test.ts +115 -0
  270. package/src/utils/abortable-iterable.ts +34 -23
  271. package/src/utils/getGroupStatus.test.ts +70 -4
  272. package/src/utils/getGroupStatus.ts +35 -12
  273. package/src/utils/wire-media.test.ts +10 -0
  274. package/src/utils/wire-media.ts +6 -2
@@ -2,15 +2,20 @@ import { auiV0Decode, auiV0Encode } from "./auiV0.js";
2
2
  import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
3
3
  import { useEffect, useRef, useState } from "@assistant-ui/tap/react-shim";
4
4
  import { getClientId, useAui } from "@assistant-ui/store";
5
- import { CloudMessagePersistence, createFormattedPersistence, createRunReport, createRunTelemetryToolCall, deriveRunOutcome, describeRunError, extractRunTelemetryModelId, normalizeRunTelemetryUsage, truncateRunTelemetryText } from "assistant-cloud";
5
+ import { CloudEngagementReporter, CloudMessagePersistence, CloudRunReporter, createFormattedPersistence, createRunTelemetryToolCall, deriveRunOutcome, describeRunError, extractRunTelemetryModelId, normalizeRunTelemetryUsage, truncateRunTelemetryText } from "assistant-cloud";
6
+ import { extractAISDKRunTelemetry } from "assistant-cloud/ai-sdk";
6
7
  //#region src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts
7
8
  const globalPersistence = /* @__PURE__ */ new WeakMap();
8
9
  var AssistantCloudThreadHistoryAdapter = class {
9
10
  cloudRef;
10
11
  getAui;
12
+ runReporter;
13
+ engagementReporter;
11
14
  constructor(cloudRef, getAui) {
12
15
  this.cloudRef = cloudRef;
13
16
  this.getAui = getAui;
17
+ this.runReporter = new CloudRunReporter(() => this.cloudRef.current);
18
+ this.engagementReporter = new CloudEngagementReporter(() => this.cloudRef.current, (threadId, messageId, options) => this.resolveEngagementEventIds(threadId, messageId, options));
14
19
  }
15
20
  get aui() {
16
21
  return this.getAui();
@@ -103,7 +108,7 @@ var AssistantCloudThreadHistoryAdapter = class {
103
108
  },
104
109
  reportTelemetry(items, options) {
105
110
  const encodedRunMessages = items.map((item) => formatAdapter.encode(item));
106
- adapter._reportRunTelemetry(formatAdapter.format, encodedRunMessages, options, resolvePinned(), extractLastRunMessageInfo(items, formatAdapter));
111
+ adapter._reportRunTelemetry(formatAdapter.format, encodedRunMessages, options, resolvePinned(), mergeRunMessageInfo(extractLastRunMessageInfo(items, formatAdapter), options?.message ? extractRunMessageInfo(options.message, "aui/v0") : void 0));
107
112
  },
108
113
  async load() {
109
114
  const pinned = pinCurrent();
@@ -138,11 +143,10 @@ var AssistantCloudThreadHistoryAdapter = class {
138
143
  return { messages: (await this._persistence.load(remoteId, "aui/v0")).filter((m) => m.format === "aui/v0").map(auiV0Decode).reverse() };
139
144
  }
140
145
  _reportRunTelemetry(format, runMessages, options, threadListItem, messageInfo) {
141
- if (!this.cloudRef.current.telemetry.enabled) return;
142
146
  const item = threadListItem ?? this.aui.threadListItem;
143
147
  const remoteId = item.getState().remoteId;
144
148
  if (!remoteId) return;
145
- const extracted = extractRunTelemetry(format, runMessages);
149
+ const extracted = extractRunTelemetry(format, runMessages) ?? (messageInfo?.status !== void 0 ? { status: "incomplete" } : void 0);
146
150
  if (!extracted) return;
147
151
  this._sendReport(remoteId, extracted, options?.durationMs, options?.stepTimestamps, messageInfo, this.getPersistence(item));
148
152
  }
@@ -154,7 +158,7 @@ var AssistantCloudThreadHistoryAdapter = class {
154
158
  _sendReport(remoteId, data, durationMs, stepTimestamps, messageInfo, persistence = this._persistence) {
155
159
  const mergedSteps = mergeStepTimestamps(data.steps, stepTimestamps);
156
160
  const messageId = messageInfo?.localMessageId ? persistence.getResolvedRemoteId(messageInfo.localMessageId) : void 0;
157
- const initial = createRunReport({
161
+ this.runReporter.report({
158
162
  threadId: remoteId,
159
163
  status: messageInfo?.status ?? data.status,
160
164
  outcome: messageInfo?.outcomeType,
@@ -164,48 +168,30 @@ var AssistantCloudThreadHistoryAdapter = class {
164
168
  traceId: messageInfo?.traceId,
165
169
  modelId: data.modelId,
166
170
  provider: messageInfo?.provider,
167
- usage: {
168
- inputTokens: data.inputTokens,
169
- outputTokens: data.outputTokens,
170
- reasoningTokens: data.reasoningTokens,
171
- cachedInputTokens: data.cachedInputTokens
172
- },
173
- steps: toRunReportSteps(mergedSteps),
171
+ usage: data.usage,
172
+ steps: mergedSteps,
174
173
  totalSteps: data.totalSteps,
175
174
  toolCalls: data.toolCalls,
176
175
  durationMs,
177
176
  firstTokenMs: messageInfo?.firstTokenMs,
178
177
  outputText: data.outputText,
179
- metadata: data.metadata,
180
- telemetry: this.cloudRef.current.telemetry
178
+ metadata: data.metadata
181
179
  });
182
- const { beforeReport } = this.cloudRef.current.telemetry;
183
- const report = beforeReport ? beforeReport(initial) : initial;
184
- if (!report) return;
185
- this.cloudRef.current.runs.report(report).catch(() => {});
186
180
  }
187
181
  };
188
- function toRunReportSteps(steps) {
189
- if (!steps) return void 0;
190
- return steps.map((step) => ({
191
- usage: {
192
- inputTokens: step.input_tokens,
193
- outputTokens: step.output_tokens,
194
- reasoningTokens: step.reasoning_tokens,
195
- cachedInputTokens: step.cached_input_tokens
196
- },
197
- toolCalls: step.tool_calls,
198
- startMs: step.start_ms,
199
- endMs: step.end_ms
200
- }));
201
- }
202
182
  function mergeStepTimestamps(steps, timestamps) {
203
183
  if (!timestamps) return steps;
204
- if (!steps) return timestamps.map((t) => ({ ...t }));
184
+ if (!steps) return timestamps.map(({ start_ms, end_ms }) => ({
185
+ startMs: start_ms,
186
+ endMs: end_ms
187
+ }));
205
188
  const len = Math.min(steps.length, timestamps.length);
206
- return steps.map((s, i) => ({
207
- ...s,
208
- ...i < len ? timestamps[i] : void 0
189
+ return steps.map((step, index) => ({
190
+ ...step,
191
+ ...index < len ? {
192
+ startMs: timestamps[index].start_ms,
193
+ endMs: timestamps[index].end_ms
194
+ } : void 0
209
195
  }));
210
196
  }
211
197
  function extractLastRunMessageInfo(items, formatAdapter) {
@@ -215,29 +201,36 @@ function extractLastRunMessageInfo(items, formatAdapter) {
215
201
  if (info) return info;
216
202
  }
217
203
  }
204
+ function mergeRunMessageInfo(stored, observed) {
205
+ if (!observed) return stored;
206
+ const { localMessageId: _observedId, ...outcome } = observed;
207
+ return {
208
+ ...stored,
209
+ ...outcome
210
+ };
211
+ }
218
212
  function extractRunMessageInfo(message, format, localMessageId) {
219
213
  if (!isRecord(message) || message.role !== "assistant") return void 0;
220
214
  const status = isRecord(message.status) ? message.status : void 0;
221
215
  const metadata = isRecord(message.metadata) ? message.metadata : void 0;
222
216
  const custom = isRecord(metadata?.custom) ? metadata.custom : void 0;
223
- const timing = isRecord(metadata?.timing) ? metadata.timing : void 0;
224
- const streamStartTime = timing?.streamStartTime;
225
- const firstTokenTime = timing?.firstTokenTime;
226
- const firstTokenMs = typeof streamStartTime === "number" && Number.isFinite(streamStartTime) && typeof firstTokenTime === "number" && Number.isFinite(firstTokenTime) ? Math.round(firstTokenTime - streamStartTime) : void 0;
227
- const finishReason = status?.type === "incomplete" ? status.reason : typeof metadata?.finishReason === "string" ? metadata.finishReason : void 0;
217
+ const firstTokenTime = (isRecord(metadata?.timing) ? metadata.timing : void 0)?.firstTokenTime;
218
+ const firstTokenMs = typeof firstTokenTime === "number" && Number.isFinite(firstTokenTime) ? Math.round(firstTokenTime) : void 0;
219
+ const finishReason = status?.type === "incomplete" ? typeof status.reason === "string" ? status.reason : void 0 : typeof metadata?.finishReason === "string" ? metadata.finishReason : void 0;
228
220
  const failed = status?.type === "incomplete" && status.reason === "error";
229
221
  const outcome = deriveRunOutcome({
230
- finishReason: typeof finishReason === "string" ? finishReason : void 0,
222
+ finishReason,
231
223
  isError: failed
232
224
  });
233
225
  const outcomeType = outcome.outcome;
226
+ const runStatus = outcome.status === "error" ? "error" : status?.type === "incomplete" ? "incomplete" : finishReason !== void 0 ? outcome.status : void 0;
234
227
  const failure = failed ? describeRunError(status.error) : {};
235
228
  const messageId = localMessageId ?? (typeof message.id === "string" ? message.id : void 0);
236
229
  const traceId = format === "aui/v0" ? custom?.traceId : format === "ai-sdk/v6" ? metadata?.traceId : void 0;
237
230
  const provider = typeof custom?.provider === "string" ? custom.provider : typeof metadata?.provider === "string" ? metadata.provider : void 0;
238
231
  return {
239
232
  ...messageId ? { localMessageId: messageId } : void 0,
240
- ...outcome.status === "error" ? { status: "error" } : void 0,
233
+ ...runStatus !== void 0 ? { status: runStatus } : void 0,
241
234
  ...outcomeType ? { outcomeType } : void 0,
242
235
  ...failure,
243
236
  ...firstTokenMs != null && firstTokenMs >= 0 ? { firstTokenMs } : void 0,
@@ -251,22 +244,18 @@ function isRecord(value) {
251
244
  function extractTelemetry(format, content) {
252
245
  switch (format) {
253
246
  case "aui/v0": return extractAuiV0(content);
254
- case "ai-sdk/v6": return extractAiSdkV6(content);
247
+ case "ai-sdk/v6": return extractAISDKRunTelemetry([content]);
255
248
  default: return null;
256
249
  }
257
250
  }
258
251
  function extractRunTelemetry(format, runMessages) {
259
- if (format === "ai-sdk/v6") return aggregateAiSdkV6RunSteps(runMessages);
252
+ if (format === "ai-sdk/v6") return extractAISDKRunTelemetry(runMessages);
260
253
  for (let i = runMessages.length - 1; i >= 0; i--) {
261
254
  const result = extractTelemetry(format, runMessages[i]);
262
255
  if (result) return result;
263
256
  }
264
257
  return null;
265
258
  }
266
- const AUI_STATUS_MAP = {
267
- error: "error",
268
- incomplete: "incomplete"
269
- };
270
259
  function extractAuiV0(content) {
271
260
  const msg = content;
272
261
  if (msg.role !== "assistant") return null;
@@ -320,196 +309,26 @@ function extractAuiV0(content) {
320
309
  reasoningTokens = hasReasoning ? totalReasoning : void 0;
321
310
  cachedInputTokens = hasCachedInput ? totalCachedInput : void 0;
322
311
  }
323
- const statusType = msg.status?.type;
324
- const status = statusType === "incomplete" && msg.status?.reason === "error" ? "error" : statusType && AUI_STATUS_MAP[statusType] || "completed";
312
+ const status = msg.status?.type === "incomplete" ? "incomplete" : "completed";
325
313
  const metadata = msg.metadata?.custom;
326
314
  const modelId = extractRunTelemetryModelId(msg.metadata);
327
- const telemetrySteps = steps && steps.length > 1 ? steps.map((s) => {
328
- const usage = s.usage ? normalizeRunTelemetryUsage(s.usage) : void 0;
329
- return {
330
- ...usage?.inputTokens != null ? { input_tokens: usage.inputTokens } : void 0,
331
- ...usage?.outputTokens != null ? { output_tokens: usage.outputTokens } : void 0,
332
- ...usage?.reasoningTokens != null ? { reasoning_tokens: usage.reasoningTokens } : void 0,
333
- ...usage?.cachedInputTokens != null ? { cached_input_tokens: usage.cachedInputTokens } : void 0
334
- };
335
- }) : void 0;
315
+ const telemetrySteps = steps && steps.length > 0 ? steps.map((step) => step.usage ? { usage: step.usage } : {}) : void 0;
336
316
  return {
337
317
  status,
338
318
  ...toolCalls && toolCalls.length > 0 ? { toolCalls } : void 0,
339
319
  ...steps?.length ? { totalSteps: steps.length } : void 0,
340
- ...inputTokens != null ? { inputTokens } : void 0,
341
- ...outputTokens != null ? { outputTokens } : void 0,
342
- ...reasoningTokens != null ? { reasoningTokens } : void 0,
343
- ...cachedInputTokens != null ? { cachedInputTokens } : void 0,
320
+ ...inputTokens != null || outputTokens != null || reasoningTokens != null || cachedInputTokens != null ? { usage: {
321
+ ...inputTokens != null ? { inputTokens } : void 0,
322
+ ...outputTokens != null ? { outputTokens } : void 0,
323
+ ...reasoningTokens != null ? { reasoningTokens } : void 0,
324
+ ...cachedInputTokens != null ? { cachedInputTokens } : void 0
325
+ } } : void 0,
344
326
  ...outputText != null ? { outputText } : void 0,
345
327
  ...metadata ? { metadata } : void 0,
346
328
  ...telemetrySteps ? { steps: telemetrySteps } : void 0,
347
329
  ...modelId ? { modelId } : void 0
348
330
  };
349
331
  }
350
- function isToolCallPart(p) {
351
- if (!p.toolCallId) return false;
352
- if (p.type === "tool-call" || p.type === "dynamic-tool") return !!p.toolName;
353
- return p.type.startsWith("tool-") || p.type.startsWith("dynamic-tool-");
354
- }
355
- function isDynamicToolPart(p) {
356
- return p.type === "dynamic-tool" || p.type.startsWith("dynamic-tool-");
357
- }
358
- function partToToolCall(p) {
359
- const toolSource = isDynamicToolPart(p) ? "mcp" : "frontend";
360
- return createRunTelemetryToolCall({
361
- toolName: p.toolName ?? p.type.slice(5),
362
- toolCallId: p.toolCallId,
363
- args: p.args ?? p.input,
364
- result: p.result ?? p.output,
365
- toolSource
366
- });
367
- }
368
- function collectAiSdkV6Parts(parts) {
369
- const textParts = [];
370
- const toolCalls = [];
371
- const stepsData = [];
372
- let currentStepToolCalls = null;
373
- for (const p of parts) if (p.type === "step-start") {
374
- if (currentStepToolCalls !== null) stepsData.push({ tool_calls: currentStepToolCalls });
375
- currentStepToolCalls = [];
376
- } else if (p.type === "text" && p.text) textParts.push(p.text);
377
- else if (isToolCallPart(p)) {
378
- const tc = partToToolCall(p);
379
- toolCalls.push(tc);
380
- if (currentStepToolCalls !== null) currentStepToolCalls.push(tc);
381
- }
382
- if (currentStepToolCalls !== null) stepsData.push({ tool_calls: currentStepToolCalls });
383
- return {
384
- textParts,
385
- toolCalls,
386
- stepsData
387
- };
388
- }
389
- function buildAiSdkV6Result(textParts, toolCalls, totalSteps, metadata, stepsData, usage) {
390
- const hasText = textParts.length > 0;
391
- const outputText = hasText ? truncateRunTelemetryText(textParts.join("")) : void 0;
392
- const modelId = extractRunTelemetryModelId(metadata);
393
- const steps = stepsData && stepsData.length > 1 ? stepsData.map((s) => ({ ...s.tool_calls.length > 0 ? { tool_calls: s.tool_calls } : void 0 })) : void 0;
394
- return {
395
- status: hasText ? "completed" : "incomplete",
396
- ...toolCalls.length > 0 ? { toolCalls } : void 0,
397
- ...totalSteps > 0 ? { totalSteps } : void 0,
398
- ...usage?.inputTokens != null ? { inputTokens: usage.inputTokens } : void 0,
399
- ...usage?.outputTokens != null ? { outputTokens: usage.outputTokens } : void 0,
400
- ...usage?.reasoningTokens != null ? { reasoningTokens: usage.reasoningTokens } : void 0,
401
- ...usage?.cachedInputTokens != null ? { cachedInputTokens: usage.cachedInputTokens } : void 0,
402
- ...outputText != null ? { outputText } : void 0,
403
- ...metadata ? { metadata } : void 0,
404
- ...steps ? { steps } : void 0,
405
- ...modelId ? { modelId } : void 0
406
- };
407
- }
408
- function extractAiSdkV6Usage(metadata) {
409
- const usage = metadata?.usage;
410
- if (usage) {
411
- const normalized = normalizeRunTelemetryUsage(usage);
412
- if (normalized) return normalized;
413
- }
414
- const steps = metadata?.steps;
415
- if (steps && steps.length > 0) {
416
- let inputTokens = 0;
417
- let outputTokens = 0;
418
- let reasoningTokens = 0;
419
- let cachedInputTokens = 0;
420
- let hasInput = false;
421
- let hasOutput = false;
422
- let hasReasoning = false;
423
- let hasCachedInput = false;
424
- let hasAny = false;
425
- for (const s of steps) {
426
- if (!s.usage) continue;
427
- const n = normalizeRunTelemetryUsage(s.usage);
428
- if (n) {
429
- if (n.inputTokens != null) {
430
- inputTokens += n.inputTokens;
431
- hasInput = true;
432
- }
433
- if (n.outputTokens != null) {
434
- outputTokens += n.outputTokens;
435
- hasOutput = true;
436
- }
437
- if (n.reasoningTokens != null) {
438
- reasoningTokens += n.reasoningTokens;
439
- hasReasoning = true;
440
- }
441
- if (n.cachedInputTokens != null) {
442
- cachedInputTokens += n.cachedInputTokens;
443
- hasCachedInput = true;
444
- }
445
- hasAny = true;
446
- }
447
- }
448
- if (hasAny) return {
449
- ...hasInput ? { inputTokens } : void 0,
450
- ...hasOutput ? { outputTokens } : void 0,
451
- ...hasReasoning ? { reasoningTokens } : void 0,
452
- ...hasCachedInput ? { cachedInputTokens } : void 0
453
- };
454
- }
455
- }
456
- function extractAiSdkV6(content) {
457
- const msg = content;
458
- if (msg.role !== "assistant") return null;
459
- const { textParts, toolCalls, stepsData } = collectAiSdkV6Parts(msg.parts ?? []);
460
- return buildAiSdkV6Result(textParts, toolCalls, stepsData.length, msg.metadata, stepsData, extractAiSdkV6Usage(msg.metadata));
461
- }
462
- function aggregateAiSdkV6RunSteps(stepMessages) {
463
- const allTextParts = [];
464
- const allToolCalls = [];
465
- const allStepsData = [];
466
- let hasAssistant = false;
467
- let metadata;
468
- let inputTokens = 0;
469
- let outputTokens = 0;
470
- let reasoningTokens = 0;
471
- let cachedInputTokens = 0;
472
- let hasInput = false;
473
- let hasOutput = false;
474
- let hasReasoning = false;
475
- let hasCachedInput = false;
476
- for (const content of stepMessages) {
477
- const msg = content;
478
- if (msg.role !== "assistant") continue;
479
- hasAssistant = true;
480
- const { textParts, toolCalls, stepsData } = collectAiSdkV6Parts(msg.parts ?? []);
481
- allTextParts.push(...textParts);
482
- allToolCalls.push(...toolCalls);
483
- allStepsData.push(...stepsData);
484
- if (msg.metadata) metadata = msg.metadata;
485
- const usage = extractAiSdkV6Usage(msg.metadata);
486
- if (usage) {
487
- if (usage.inputTokens != null) {
488
- inputTokens += usage.inputTokens;
489
- hasInput = true;
490
- }
491
- if (usage.outputTokens != null) {
492
- outputTokens += usage.outputTokens;
493
- hasOutput = true;
494
- }
495
- if (usage.reasoningTokens != null) {
496
- reasoningTokens += usage.reasoningTokens;
497
- hasReasoning = true;
498
- }
499
- if (usage.cachedInputTokens != null) {
500
- cachedInputTokens += usage.cachedInputTokens;
501
- hasCachedInput = true;
502
- }
503
- }
504
- }
505
- if (!hasAssistant) return null;
506
- return buildAiSdkV6Result(allTextParts, allToolCalls, allStepsData.length, metadata, allStepsData, {
507
- ...hasInput ? { inputTokens } : void 0,
508
- ...hasOutput ? { outputTokens } : void 0,
509
- ...hasReasoning ? { reasoningTokens } : void 0,
510
- ...hasCachedInput ? { cachedInputTokens } : void 0
511
- });
512
- }
513
332
  function useAssistantCloudThreadHistoryAdapter(cloudRef) {
514
333
  const aui = useAui();
515
334
  const auiRef = useRef(aui);
@@ -517,7 +336,7 @@ function useAssistantCloudThreadHistoryAdapter(cloudRef) {
517
336
  auiRef.current = aui;
518
337
  });
519
338
  const [adapter] = useState(() => new AssistantCloudThreadHistoryAdapter(cloudRef, () => auiRef.current));
520
- useAssistantCloudEngagementEvents(cloudRef, adapter, aui);
339
+ useAssistantCloudEngagementEvents(adapter, aui);
521
340
  return adapter;
522
341
  }
523
342
  const rootEngagementTrackers = /* @__PURE__ */ new WeakMap();
@@ -526,38 +345,29 @@ const rootEngagementTrackers = /* @__PURE__ */ new WeakMap();
526
345
  * client reports them; every thread runtime mounted under it shares the
527
346
  * subscription and the last one to unmount removes it.
528
347
  */
529
- const useRootEngagementEvents = (cloudRef, adapter, aui) => {
530
- const $ = c(5);
348
+ const useRootEngagementEvents = (adapter, aui) => {
349
+ const $ = c(6);
531
350
  let t0;
532
- let t1;
533
- if ($[0] !== adapter || $[1] !== aui || $[2] !== cloudRef) {
351
+ if ($[0] !== adapter.engagementReporter || $[1] !== aui) {
534
352
  t0 = () => {
535
353
  let tracker = rootEngagementTrackers.get(aui);
536
354
  if (!tracker) {
537
355
  const created = {
538
356
  count: 0,
539
- adapter,
540
- cloudRef,
357
+ engagementReporter: adapter.engagementReporter,
541
358
  dispose: _temp
542
359
  };
543
360
  created.dispose = aui.on({
544
361
  scope: "*",
545
362
  event: "threads.selectionChanged"
546
363
  }, (payload) => {
547
- created.adapter.resolveEngagementEventIds(payload.threadId).then((ids) => {
548
- if (!ids.thread_id) return;
549
- created.cloudRef.current.events?.track({
550
- kind: "thread_switched",
551
- ...ids
552
- });
553
- }).catch(_temp2);
364
+ created.engagementReporter.threadSwitched(payload.threadId);
554
365
  });
555
366
  rootEngagementTrackers.set(aui, created);
556
367
  tracker = created;
557
368
  }
558
369
  const active = tracker;
559
- active.adapter = adapter;
560
- active.cloudRef = cloudRef;
370
+ active.engagementReporter = adapter.engagementReporter;
561
371
  active.count = active.count + 1;
562
372
  return () => {
563
373
  active.count = active.count - 1;
@@ -567,222 +377,173 @@ const useRootEngagementEvents = (cloudRef, adapter, aui) => {
567
377
  }
568
378
  };
569
379
  };
570
- t1 = [
571
- adapter,
572
- aui,
573
- cloudRef
574
- ];
575
- $[0] = adapter;
380
+ $[0] = adapter.engagementReporter;
576
381
  $[1] = aui;
577
- $[2] = cloudRef;
578
- $[3] = t0;
579
- $[4] = t1;
580
- } else {
581
- t0 = $[3];
582
- t1 = $[4];
583
- }
382
+ $[2] = t0;
383
+ } else t0 = $[2];
384
+ let t1;
385
+ if ($[3] !== adapter || $[4] !== aui) {
386
+ t1 = [adapter, aui];
387
+ $[3] = adapter;
388
+ $[4] = aui;
389
+ $[5] = t1;
390
+ } else t1 = $[5];
584
391
  useEffect(t0, t1);
585
392
  };
586
- const useAssistantCloudEngagementEvents = (cloudRef, adapter, aui) => {
587
- const $ = c(13);
588
- useRootEngagementEvents(cloudRef, adapter, aui);
393
+ const useAssistantCloudEngagementEvents = (adapter, aui) => {
394
+ const $ = c(12);
395
+ useRootEngagementEvents(adapter, aui);
589
396
  let t0;
590
- if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
591
- t0 = /* @__PURE__ */ new Map();
592
- $[0] = t0;
593
- } else t0 = $[0];
594
- const runStartedAt = useRef(t0);
595
- let t1;
596
- if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
597
- t1 = /* @__PURE__ */ new Map();
598
- $[1] = t1;
599
- } else t1 = $[1];
600
- const runEndedAt = useRef(t1);
601
- let t2;
602
- if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
603
- t2 = /* @__PURE__ */ new Set();
604
- $[2] = t2;
605
- } else t2 = $[2];
606
- const shownSuggestions = useRef(t2);
607
- let t3;
608
- let t4;
609
- if ($[3] !== adapter || $[4] !== aui || $[5] !== cloudRef) {
610
- t3 = () => {
611
- const track = (event, threadId, messageId, options) => {
612
- adapter.resolveEngagementEventIds(threadId, messageId, options).then((ids) => {
613
- cloudRef.current.events?.track({
614
- ...event,
615
- ...ids
616
- });
617
- }).catch(_temp3);
618
- };
619
- const trackRunStopped = (threadId_0) => {
620
- const startedAt = runStartedAt.current.get(threadId_0);
621
- if (startedAt === void 0) return;
622
- runStartedAt.current.delete(threadId_0);
623
- track({
624
- kind: "run_stopped",
625
- value: Math.max(0, Date.now() - startedAt)
626
- }, threadId_0);
627
- };
397
+ if ($[0] !== adapter.engagementReporter || $[1] !== aui) {
398
+ t0 = () => {
399
+ const reporter = adapter.engagementReporter;
628
400
  const unsubscribers = [
629
401
  aui.on({
630
402
  scope: "thread",
631
403
  event: "composer.send"
632
404
  }, (payload) => {
633
- const previousRunEndedAt = runEndedAt.current.get(payload.threadId);
634
- track({
635
- kind: payload.messageId ? "message_edited" : "message_sent",
636
- ...payload.messageId ? { props: { chars: payload.chars } } : { props: {
637
- chars: payload.chars,
638
- attachments: payload.attachments
639
- } },
640
- ...!payload.messageId && previousRunEndedAt !== void 0 ? { value: Math.max(0, Date.now() - previousRunEndedAt) } : void 0
641
- }, payload.threadId, payload.messageId, { awaitThread: !payload.messageId });
642
- if (payload.suggestion) track({ kind: "suggestion_clicked" }, payload.threadId);
405
+ if (payload.messageId) reporter.messageEdited(payload.threadId, {
406
+ messageId: payload.messageId,
407
+ chars: payload.chars
408
+ });
409
+ else reporter.messageSent(payload.threadId, {
410
+ chars: payload.chars,
411
+ attachments: payload.attachments
412
+ });
413
+ if (payload.suggestion) reporter.suggestionClicked(payload.threadId);
643
414
  }),
644
415
  aui.on({
645
416
  scope: "thread",
646
417
  event: "composer.attachmentAdd"
647
418
  }, (payload_0) => {
648
- track({
649
- kind: "attachment_added",
650
- ...payload_0.contentType ? { props: { type: payload_0.contentType } } : void 0
651
- }, payload_0.threadId, payload_0.messageId);
419
+ reporter.attachmentAdded(payload_0.threadId, {
420
+ messageId: payload_0.messageId,
421
+ contentType: payload_0.contentType
422
+ });
652
423
  }),
653
424
  aui.on({
654
425
  scope: "thread",
655
426
  event: "composer.attachmentAddError"
656
427
  }, (payload_1) => {
657
- track({
658
- kind: "attachment_failed",
659
- ...payload_1.contentType ? { props: { type: payload_1.contentType } } : void 0
660
- }, payload_1.threadId, payload_1.messageId);
428
+ reporter.attachmentFailed(payload_1.threadId, {
429
+ messageId: payload_1.messageId,
430
+ contentType: payload_1.contentType
431
+ });
661
432
  }),
662
433
  aui.on({
663
434
  scope: "thread",
664
435
  event: "composer.cancel"
665
436
  }, (payload_2) => {
666
- trackRunStopped(payload_2.threadId);
437
+ reporter.runStopped(payload_2.threadId);
667
438
  }),
668
439
  aui.on({
669
440
  scope: "thread",
670
441
  event: "thread.runStart"
671
442
  }, (payload_3) => {
672
- runStartedAt.current.set(payload_3.threadId, Date.now());
443
+ reporter.runStarted(payload_3.threadId);
673
444
  }),
674
445
  aui.on({
675
446
  scope: "thread",
676
447
  event: "thread.runEnd"
677
448
  }, (payload_4) => {
678
- runStartedAt.current.delete(payload_4.threadId);
679
- runEndedAt.current.set(payload_4.threadId, Date.now());
449
+ reporter.runEnded(payload_4.threadId);
680
450
  }),
681
451
  aui.on({
682
452
  scope: "thread",
683
453
  event: "thread.cancelRun"
684
454
  }, (payload_5) => {
685
- trackRunStopped(payload_5.threadId);
455
+ reporter.runStopped(payload_5.threadId);
686
456
  }),
687
457
  aui.on({
688
458
  scope: "thread",
689
459
  event: "thread.voiceStarted"
690
460
  }, (payload_6) => {
691
- track({ kind: "voice_started" }, payload_6.threadId);
461
+ reporter.voiceStarted(payload_6.threadId);
692
462
  }),
693
463
  aui.on({
694
464
  scope: "thread",
695
465
  event: "message.reload"
696
466
  }, (payload_7) => {
697
- track({ kind: "message_regenerated" }, payload_7.threadId, payload_7.messageId);
467
+ reporter.messageRegenerated(payload_7.threadId, payload_7.messageId);
698
468
  }),
699
469
  aui.on({
700
470
  scope: "thread",
701
471
  event: "message.branchSwitched"
702
472
  }, (payload_8) => {
703
- track({ kind: "branch_switched" }, payload_8.threadId, payload_8.messageId);
473
+ reporter.branchSwitched(payload_8.threadId, payload_8.messageId);
704
474
  }),
705
475
  aui.on({
706
476
  scope: "thread",
707
477
  event: "message.copied"
708
478
  }, (payload_9) => {
709
- track({ kind: "message_copied" }, payload_9.threadId, payload_9.messageId);
479
+ reporter.messageCopied(payload_9.threadId, payload_9.messageId);
710
480
  }),
711
481
  aui.on({
712
482
  scope: "thread",
713
- event: "message.speak"
483
+ event: "thread.toolApprovalAnswered"
714
484
  }, (payload_10) => {
715
- track({ kind: "speech_started" }, payload_10.threadId, payload_10.messageId);
485
+ if (payload_10.approved) reporter.toolApproved(payload_10.threadId, payload_10.messageId, payload_10.toolCallId, payload_10.toolName);
486
+ else reporter.toolRejected(payload_10.threadId, payload_10.messageId, payload_10.toolCallId, payload_10.toolName);
716
487
  }),
717
488
  aui.on({
718
489
  scope: "thread",
719
- event: "message.error"
490
+ event: "message.speak"
720
491
  }, (payload_11) => {
721
- track({
722
- kind: "error_shown",
723
- props: { reason: payload_11.reason }
724
- }, payload_11.threadId, payload_11.messageId);
492
+ reporter.speechStarted(payload_11.threadId, payload_11.messageId);
493
+ }),
494
+ aui.on({
495
+ scope: "thread",
496
+ event: "message.error"
497
+ }, (payload_12) => {
498
+ reporter.errorShown(payload_12.threadId, {
499
+ messageId: payload_12.messageId,
500
+ reason: payload_12.reason
501
+ });
725
502
  })
726
503
  ];
727
504
  return () => {
728
505
  for (const unsubscribe of unsubscribers) unsubscribe();
729
506
  };
730
507
  };
731
- t4 = [
732
- adapter,
733
- aui,
734
- cloudRef
735
- ];
508
+ $[0] = adapter.engagementReporter;
509
+ $[1] = aui;
510
+ $[2] = t0;
511
+ } else t0 = $[2];
512
+ let t1;
513
+ if ($[3] !== adapter || $[4] !== aui) {
514
+ t1 = [adapter, aui];
736
515
  $[3] = adapter;
737
516
  $[4] = aui;
738
- $[5] = cloudRef;
739
- $[6] = t3;
740
- $[7] = t4;
741
- } else {
742
- t3 = $[6];
743
- t4 = $[7];
744
- }
745
- useEffect(t3, t4);
746
- let t5;
747
- let t6;
748
- if ($[8] !== adapter || $[9] !== aui || $[10] !== cloudRef) {
749
- t5 = () => {
517
+ $[5] = t1;
518
+ } else t1 = $[5];
519
+ useEffect(t0, t1);
520
+ let t2;
521
+ if ($[6] !== adapter.engagementReporter || $[7] !== aui) {
522
+ t2 = () => {
750
523
  const reportSuggestions = () => {
751
524
  const { mainThreadId } = aui.threads.getState();
752
525
  if (aui.threadListItem.getState().id !== mainThreadId) return;
753
526
  const { isEmpty, suggestions } = aui.thread.getState();
754
- if (!isEmpty || suggestions.length === 0 || shownSuggestions.current.has(mainThreadId)) return;
755
- shownSuggestions.current.add(mainThreadId);
756
- adapter.resolveEngagementEventIds(mainThreadId).then((ids_0) => {
757
- cloudRef.current.events?.track({
758
- kind: "suggestions_shown",
759
- value: suggestions.length,
760
- ...ids_0
761
- });
762
- });
527
+ if (!isEmpty || suggestions.length === 0) return;
528
+ adapter.engagementReporter.suggestionsShown(mainThreadId, suggestions.length);
763
529
  };
764
530
  reportSuggestions();
765
531
  return aui.subscribe(reportSuggestions);
766
532
  };
767
- t6 = [
768
- adapter,
769
- aui,
770
- cloudRef
771
- ];
772
- $[8] = adapter;
773
- $[9] = aui;
774
- $[10] = cloudRef;
775
- $[11] = t5;
776
- $[12] = t6;
777
- } else {
778
- t5 = $[11];
779
- t6 = $[12];
780
- }
781
- useEffect(t5, t6);
533
+ $[6] = adapter.engagementReporter;
534
+ $[7] = aui;
535
+ $[8] = t2;
536
+ } else t2 = $[8];
537
+ let t3;
538
+ if ($[9] !== adapter || $[10] !== aui) {
539
+ t3 = [adapter, aui];
540
+ $[9] = adapter;
541
+ $[10] = aui;
542
+ $[11] = t3;
543
+ } else t3 = $[11];
544
+ useEffect(t2, t3);
782
545
  };
783
546
  function _temp() {}
784
- function _temp2() {}
785
- function _temp3() {}
786
547
  //#endregion
787
548
  export { extractAuiV0, useAssistantCloudThreadHistoryAdapter };
788
549