@copilotkit/shared 1.72.1-canary.sp-longthread-perf → 1.73.1

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 (85) hide show
  1. package/README.md +22 -0
  2. package/dist/attachments/content.cjs +17 -0
  3. package/dist/attachments/content.cjs.map +1 -0
  4. package/dist/attachments/content.d.cts +9 -0
  5. package/dist/attachments/content.d.cts.map +1 -0
  6. package/dist/attachments/content.d.mts +9 -0
  7. package/dist/attachments/content.d.mts.map +1 -0
  8. package/dist/attachments/content.mjs +16 -0
  9. package/dist/attachments/content.mjs.map +1 -0
  10. package/dist/event-transforms/index.cjs +15 -0
  11. package/dist/event-transforms/index.d.cts +4 -0
  12. package/dist/event-transforms/index.d.mts +4 -0
  13. package/dist/event-transforms/index.mjs +5 -0
  14. package/dist/event-transforms/open-generative-ui-middleware.cjs +286 -0
  15. package/dist/event-transforms/open-generative-ui-middleware.cjs.map +1 -0
  16. package/dist/event-transforms/open-generative-ui-middleware.d.cts +60 -0
  17. package/dist/event-transforms/open-generative-ui-middleware.d.cts.map +1 -0
  18. package/dist/event-transforms/open-generative-ui-middleware.d.mts +60 -0
  19. package/dist/event-transforms/open-generative-ui-middleware.d.mts.map +1 -0
  20. package/dist/event-transforms/open-generative-ui-middleware.mjs +283 -0
  21. package/dist/event-transforms/open-generative-ui-middleware.mjs.map +1 -0
  22. package/dist/event-transforms/recorded-events.cjs +59 -0
  23. package/dist/event-transforms/recorded-events.cjs.map +1 -0
  24. package/dist/event-transforms/recorded-events.d.cts +23 -0
  25. package/dist/event-transforms/recorded-events.d.cts.map +1 -0
  26. package/dist/event-transforms/recorded-events.d.mts +23 -0
  27. package/dist/event-transforms/recorded-events.d.mts.map +1 -0
  28. package/dist/event-transforms/recorded-events.mjs +58 -0
  29. package/dist/event-transforms/recorded-events.mjs.map +1 -0
  30. package/dist/finalize-events.cjs +92 -71
  31. package/dist/finalize-events.cjs.map +1 -1
  32. package/dist/finalize-events.d.cts +20 -1
  33. package/dist/finalize-events.d.cts.map +1 -1
  34. package/dist/finalize-events.d.mts +20 -1
  35. package/dist/finalize-events.d.mts.map +1 -1
  36. package/dist/finalize-events.mjs +92 -72
  37. package/dist/finalize-events.mjs.map +1 -1
  38. package/dist/index.cjs +9 -0
  39. package/dist/index.cjs.map +1 -1
  40. package/dist/index.d.cts +4 -2
  41. package/dist/index.d.cts.map +1 -1
  42. package/dist/index.d.mts +4 -2
  43. package/dist/index.d.mts.map +1 -1
  44. package/dist/index.mjs +4 -2
  45. package/dist/index.mjs.map +1 -1
  46. package/dist/index.umd.js +316 -71
  47. package/dist/index.umd.js.map +1 -1
  48. package/dist/package.cjs +1 -1
  49. package/dist/package.mjs +1 -1
  50. package/dist/types/message.d.cts +3 -3
  51. package/dist/types/message.d.cts.map +1 -1
  52. package/dist/types/message.d.mts +3 -3
  53. package/dist/types/message.d.mts.map +1 -1
  54. package/dist/utils/index.cjs +1 -0
  55. package/dist/utils/index.cjs.map +1 -1
  56. package/dist/utils/index.d.cts +1 -0
  57. package/dist/utils/index.d.cts.map +1 -1
  58. package/dist/utils/index.d.mts +1 -0
  59. package/dist/utils/index.d.mts.map +1 -1
  60. package/dist/utils/index.mjs +1 -0
  61. package/dist/utils/index.mjs.map +1 -1
  62. package/dist/utils/row-render-keys.cjs +206 -0
  63. package/dist/utils/row-render-keys.cjs.map +1 -0
  64. package/dist/utils/row-render-keys.d.cts +65 -0
  65. package/dist/utils/row-render-keys.d.cts.map +1 -0
  66. package/dist/utils/row-render-keys.d.mts +65 -0
  67. package/dist/utils/row-render-keys.d.mts.map +1 -0
  68. package/dist/utils/row-render-keys.mjs +201 -0
  69. package/dist/utils/row-render-keys.mjs.map +1 -0
  70. package/package.json +12 -1
  71. package/src/__tests__/root-entry-browser-safety.test.ts +7 -1
  72. package/src/attachments/content.test.ts +48 -0
  73. package/src/attachments/content.ts +16 -0
  74. package/src/attachments/index.ts +2 -0
  75. package/src/event-transforms/index.ts +5 -0
  76. package/src/event-transforms/open-generative-ui-middleware.ts +392 -0
  77. package/src/event-transforms/recorded-events.test.ts +166 -0
  78. package/src/event-transforms/recorded-events.ts +74 -0
  79. package/src/finalize-events.test.ts +146 -0
  80. package/src/finalize-events.ts +124 -124
  81. package/src/index.ts +6 -1
  82. package/src/utils/__tests__/row-render-keys.test.ts +388 -0
  83. package/src/utils/index.ts +1 -0
  84. package/src/utils/row-render-keys.ts +263 -0
  85. package/tsdown.config.ts +7 -4
package/dist/index.umd.js CHANGED
@@ -1222,6 +1222,209 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
1222
1222
  }
1223
1223
  }
1224
1224
 
1225
+ //#endregion
1226
+ //#region src/utils/row-render-keys.ts
1227
+ /**
1228
+ * Stable per-row view keys for chat transcripts, across backends that re-key a
1229
+ * message mid-stream. Shared by every frontend package, because the defect and
1230
+ * the correlation signal are in the message stream, not in any one framework.
1231
+ *
1232
+ * ## The problem
1233
+ *
1234
+ * A message's canonical `id` is not stable within a turn. LangChain stamps a
1235
+ * placeholder id on the first streamed chunk when the provider didn't supply
1236
+ * one (`chat_models.py`: `if chunk.message.id is None: chunk.message.id =
1237
+ * "lc_run-" + "-" + run_id`), then prefers any provider-assigned id it sees
1238
+ * while merging chunks (`messages/ai.py`, "Ranks are defined by the order of
1239
+ * preference"). The `MESSAGES_SNAPSHOT` therefore carries the provider's final
1240
+ * id (e.g. `resp_…`) for a message the client already knows as `lc_run--…`.
1241
+ *
1242
+ * Every framework destroys and recreates a row whose key changes, so keying
1243
+ * rows by `id` turned that swap into the visible HITL chat flash, where a
1244
+ * rendered approval card appears to reset during a tool's
1245
+ * `executing → complete` transition.
1246
+ *
1247
+ * This is provider-conditional: providers that stamp an id on every chunk (so
1248
+ * `chunk.message.id is None` never holds) never trigger a rename.
1249
+ *
1250
+ * ## The approach
1251
+ *
1252
+ * Tool-call ids survive the rename, so they are used as *anchors*: the first
1253
+ * message seen carrying a given tool call records the key it was assigned, and
1254
+ * any later message carrying that same tool call reuses it. The store is an
1255
+ * override table consulted before falling back to `message.id`. Resolving only
1256
+ * reads it; each render that reaches the DOM then records what it rendered:
1257
+ *
1258
+ * ```text
1259
+ * render 1 id=lc_run--1 no tools key = message.id = lc_run--1
1260
+ * commit 1 store {}
1261
+ * render 2 id=lc_run--1 tc call_A key = message.id = lc_run--1
1262
+ * commit 2 store { tc:call_A -> lc_run--1 }
1263
+ * render 3 id=resp_1 tc call_A key = store[tc:call_A]
1264
+ * = lc_run--1 (row survives)
1265
+ * commit 3 store unchanged
1266
+ * ```
1267
+ *
1268
+ * Recording the anchor at commit 2 — while the id is still stable — is what
1269
+ * makes render 3 resolvable. Note the fix does not depend on render 2
1270
+ * existing: a message born already carrying a tool call anchors on the first
1271
+ * render that commits it, under whatever id it holds then.
1272
+ *
1273
+ * ## Why an override table rather than keying rows by tool-call id
1274
+ *
1275
+ * Deriving the key from the tool call directly (`tc:<id>` whenever a tool call
1276
+ * is present) needs no state, but changes the key the moment a tool call
1277
+ * *appears* — so an assistant message that streams text and then calls a tool
1278
+ * is torn down on that transition, for every provider, whether or not it
1279
+ * renames. That trades a conditional flash for an unconditional one. Recording
1280
+ * an override keeps the key the row already had.
1281
+ *
1282
+ * ## Cost
1283
+ *
1284
+ * The store holds only `tc:<toolCallId>` entries, so a conversation with no
1285
+ * tool calls keeps an empty store and behaviour byte-identical to keying by
1286
+ * `id`. Size is bounded to the tool calls of the currently-rendered messages
1287
+ * (see `pruneRowKeyStore`), not the conversation length. Deleting the store
1288
+ * reverts to plain `id` keying.
1289
+ *
1290
+ * ## Known gaps
1291
+ *
1292
+ * - A text-only assistant message has no anchor, so it still re-keys. No
1293
+ * client-side correlation signal exists for it; the fix is stable ids
1294
+ * upstream.
1295
+ * - If the tool call's arrival and the id swap land in the same update, the
1296
+ * intermediate state never renders, the anchor is never recorded, and the
1297
+ * row is recreated as before. Correlating in the event-apply layer (i.e. in
1298
+ * the AG-UI client, which observes every intermediate state) would be immune.
1299
+ */
1300
+ const TOOL_ANCHOR_PREFIX = "tc:";
1301
+ function createRowKeyStore() {
1302
+ return {
1303
+ overrides: /* @__PURE__ */ new Map(),
1304
+ ambiguous: /* @__PURE__ */ new Set()
1305
+ };
1306
+ }
1307
+ /**
1308
+ * Anchors a message contributes. Only assistant tool calls qualify: LangChain's
1309
+ * id preference applies when merging `AIMessageChunk`s, so user message ids are
1310
+ * not renamed, and `role: "tool"` messages are not rendered as rows. Every tool
1311
+ * call is used (not just the first) so the anchor survives tool-call reordering
1312
+ * between snapshots.
1313
+ */
1314
+ function toolAnchorsOf(message) {
1315
+ if ((message === null || message === void 0 ? void 0 : message.role) !== "assistant") return [];
1316
+ const toolCalls = message.toolCalls;
1317
+ if (!(toolCalls === null || toolCalls === void 0 ? void 0 : toolCalls.length)) return [];
1318
+ const anchors = [];
1319
+ for (const toolCall of toolCalls) if (toolCall === null || toolCall === void 0 ? void 0 : toolCall.id) anchors.push(`${TOOL_ANCHOR_PREFIX}${toolCall.id}`);
1320
+ return anchors;
1321
+ }
1322
+ /**
1323
+ * Resolves the row key for every message, returned by position.
1324
+ *
1325
+ * Pure: it reads `store` and never writes to it. Every framework here may
1326
+ * evaluate a render pass whose result never reaches the DOM — an abandoned
1327
+ * concurrent render in React, a discarded `computed` evaluation in Vue or
1328
+ * Angular. An anchor recorded by such a pass would vend its key to the pass
1329
+ * that does render, re-keying the row the user is looking at, which is the
1330
+ * teardown this module exists to prevent. Anchors are recorded by
1331
+ * `commitRowKeyStore`, from whichever phase each framework runs after the DOM
1332
+ * is updated.
1333
+ *
1334
+ * Uniqueness is structural rather than assumed: a caller that does not
1335
+ * deduplicate can pass two rows with the same id, and an override can vend a
1336
+ * key equal to a later message's own id.
1337
+ */
1338
+ function resolveRowRenderKeys(store, messages) {
1339
+ const keys = [];
1340
+ const claimed = /* @__PURE__ */ new Set();
1341
+ messages.forEach((message, index) => {
1342
+ var _key;
1343
+ const anchors = toolAnchorsOf(message);
1344
+ let key;
1345
+ for (const anchor of anchors) {
1346
+ if (store.ambiguous.has(anchor)) continue;
1347
+ const recorded = store.overrides.get(anchor);
1348
+ if (recorded !== void 0 && !claimed.has(recorded)) {
1349
+ key = recorded;
1350
+ break;
1351
+ }
1352
+ }
1353
+ (_key = key) !== null && _key !== void 0 || (key = (message === null || message === void 0 ? void 0 : message.id) || `index-${index}`);
1354
+ if (claimed.has(key)) {
1355
+ let suffix = 2;
1356
+ while (claimed.has(`${key}:${suffix}`)) suffix += 1;
1357
+ key = `${key}:${suffix}`;
1358
+ }
1359
+ keys.push(key);
1360
+ claimed.add(key);
1361
+ });
1362
+ return keys;
1363
+ }
1364
+ /**
1365
+ * `message.id` → row key, for callers that render by message rather than by
1366
+ * position. `messages` must be deduplicated: duplicate ids would overwrite
1367
+ * each other in the returned map.
1368
+ */
1369
+ function resolveRowRenderKeysById(store, messages) {
1370
+ const keys = resolveRowRenderKeys(store, messages);
1371
+ const byId = /* @__PURE__ */ new Map();
1372
+ messages.forEach((message, index) => {
1373
+ const key = keys[index];
1374
+ if (key !== void 0) byId.set(message.id, key);
1375
+ });
1376
+ return byId;
1377
+ }
1378
+ /**
1379
+ * Records the anchors of a rendered list, then bounds the store to it. Call
1380
+ * from the phase that runs after the DOM is updated, never while resolving —
1381
+ * see `resolveRowRenderKeys`.
1382
+ *
1383
+ * Re-resolving here reproduces the keys the rows were rendered with, because
1384
+ * the store cannot change between a render and its own post-render phase.
1385
+ *
1386
+ * An anchor carried by two rows in the same list is marked ambiguous rather
1387
+ * than recorded. Recording it would give the first row's key to whichever row
1388
+ * outlived the other, and with it that row's DOM and component state.
1389
+ */
1390
+ function commitRowKeyStore(store, messages) {
1391
+ const keys = resolveRowRenderKeys(store, messages);
1392
+ const anchorCounts = /* @__PURE__ */ new Map();
1393
+ for (const message of messages) for (const anchor of toolAnchorsOf(message)) {
1394
+ var _anchorCounts$get;
1395
+ anchorCounts.set(anchor, ((_anchorCounts$get = anchorCounts.get(anchor)) !== null && _anchorCounts$get !== void 0 ? _anchorCounts$get : 0) + 1);
1396
+ }
1397
+ store.ambiguous.clear();
1398
+ for (const [anchor, count] of anchorCounts) if (count > 1) {
1399
+ store.ambiguous.add(anchor);
1400
+ store.overrides.delete(anchor);
1401
+ }
1402
+ messages.forEach((message, index) => {
1403
+ const key = keys[index];
1404
+ if (key === void 0) return;
1405
+ for (const anchor of toolAnchorsOf(message)) {
1406
+ if (store.ambiguous.has(anchor)) continue;
1407
+ if (!store.overrides.has(anchor)) store.overrides.set(anchor, key);
1408
+ }
1409
+ });
1410
+ pruneRowKeyStore(store, messages);
1411
+ }
1412
+ /**
1413
+ * Drops anchors no longer present in `messages`, bounding the store to the
1414
+ * tool calls of the currently-rendered messages. Called by
1415
+ * `commitRowKeyStore`; like it, this writes to the store and so belongs after
1416
+ * the DOM is updated, never while resolving.
1417
+ *
1418
+ * Pruned entries are unreachable by construction: `resolveRowRenderKeys` only
1419
+ * looks up anchors belonging to messages in the list it is given.
1420
+ */
1421
+ function pruneRowKeyStore(store, messages) {
1422
+ const live = /* @__PURE__ */ new Set();
1423
+ for (const message of messages) for (const anchor of toolAnchorsOf(message)) live.add(anchor);
1424
+ for (const anchor of store.overrides.keys()) if (!live.has(anchor)) store.overrides.delete(anchor);
1425
+ for (const anchor of store.ambiguous) if (!live.has(anchor)) store.ambiguous.delete(anchor);
1426
+ }
1427
+
1225
1428
  //#endregion
1226
1429
  //#region src/utils/index.ts
1227
1430
  /**
@@ -1624,6 +1827,20 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
1624
1827
  throw new Error(`Cannot convert schema to JSON Schema. The schema (vendor: "${vendor}") does not implement Standard JSON Schema V1 and no zodToJsonSchema fallback is available. Use a library that supports Standard JSON Schema (e.g., Zod 3.24+, Valibot v1+, ArkType v2+) or pass a zodToJsonSchema function in options.`);
1625
1828
  }
1626
1829
 
1830
+ //#endregion
1831
+ //#region src/attachments/content.ts
1832
+ /** Build the AG-UI content part used when sending a ready attachment. */
1833
+ function createAttachmentContent(attachment) {
1834
+ return {
1835
+ type: attachment.type,
1836
+ source: attachment.source,
1837
+ metadata: {
1838
+ ...attachment.filename ? { filename: attachment.filename } : {},
1839
+ ...attachment.metadata
1840
+ }
1841
+ };
1842
+ }
1843
+
1627
1844
  //#endregion
1628
1845
  //#region src/attachments/utils.ts
1629
1846
  const DEFAULT_MAX_SIZE = 20 * 1024 * 1024;
@@ -1761,69 +1978,77 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
1761
1978
  //#region src/finalize-events.ts
1762
1979
  const defaultStopMessage = "Run stopped by user";
1763
1980
  const defaultAbruptEndMessage = "Run ended without emitting a terminal event";
1764
- function finalizeRunEvents(events, options = {}) {
1765
- const { stopRequested = false, interruptionMessage } = options;
1766
- const resolvedStopMessage = interruptionMessage !== null && interruptionMessage !== void 0 ? interruptionMessage : defaultStopMessage;
1767
- const resolvedAbruptMessage = interruptionMessage && interruptionMessage !== defaultStopMessage ? interruptionMessage : defaultAbruptEndMessage;
1768
- const appended = [];
1981
+ /**
1982
+ * Incremental finalizer for a streamed AG-UI run. Feed every event to
1983
+ * `observe`; when the stream ends without a terminal event, `finalize` returns
1984
+ * the closers for text messages and tool calls still open plus a terminal
1985
+ * event. Closed lifecycles are forgotten at once and payloads are never kept,
1986
+ * so a caller does not have to retain the event array for this purpose.
1987
+ */
1988
+ function createRunEventFinalizer() {
1769
1989
  const openMessageIds = /* @__PURE__ */ new Set();
1770
1990
  const openToolCalls = /* @__PURE__ */ new Map();
1771
- for (const event of events) switch (event.type) {
1772
- case _ag_ui_client.EventType.TEXT_MESSAGE_START: {
1773
- const messageId = event.messageId;
1774
- if (typeof messageId === "string") openMessageIds.add(messageId);
1775
- break;
1776
- }
1777
- case _ag_ui_client.EventType.TEXT_MESSAGE_END: {
1778
- const messageId = event.messageId;
1779
- if (typeof messageId === "string") openMessageIds.delete(messageId);
1780
- break;
1781
- }
1782
- case _ag_ui_client.EventType.TOOL_CALL_START: {
1783
- const toolCallId = event.toolCallId;
1784
- if (typeof toolCallId === "string") openToolCalls.set(toolCallId, {
1785
- hasEnd: false,
1786
- hasResult: false
1787
- });
1788
- break;
1789
- }
1790
- case _ag_ui_client.EventType.TOOL_CALL_END: {
1791
- const toolCallId = event.toolCallId;
1792
- const info = toolCallId ? openToolCalls.get(toolCallId) : void 0;
1793
- if (info) info.hasEnd = true;
1794
- break;
1795
- }
1796
- case _ag_ui_client.EventType.TOOL_CALL_RESULT: {
1797
- const toolCallId = event.toolCallId;
1798
- const info = toolCallId ? openToolCalls.get(toolCallId) : void 0;
1799
- if (info) info.hasResult = true;
1800
- break;
1991
+ let terminalEventObserved = false;
1992
+ const observe = (event) => {
1993
+ if (terminalEventObserved) return;
1994
+ switch (event.type) {
1995
+ case _ag_ui_client.EventType.TEXT_MESSAGE_START: {
1996
+ const messageId = event.messageId;
1997
+ if (messageId) openMessageIds.add(messageId);
1998
+ break;
1999
+ }
2000
+ case _ag_ui_client.EventType.TEXT_MESSAGE_END: {
2001
+ const messageId = event.messageId;
2002
+ if (typeof messageId === "string") openMessageIds.delete(messageId);
2003
+ break;
2004
+ }
2005
+ case _ag_ui_client.EventType.TOOL_CALL_START: {
2006
+ const toolCallId = event.toolCallId;
2007
+ if (toolCallId && !openToolCalls.has(toolCallId)) openToolCalls.set(toolCallId, {
2008
+ hasEnd: false,
2009
+ hasResult: false
2010
+ });
2011
+ break;
2012
+ }
2013
+ case _ag_ui_client.EventType.TOOL_CALL_END:
2014
+ case _ag_ui_client.EventType.TOOL_CALL_RESULT: {
2015
+ const toolCallId = event.toolCallId;
2016
+ if (!toolCallId) break;
2017
+ const info = openToolCalls.get(toolCallId);
2018
+ if (!info) break;
2019
+ if (event.type === _ag_ui_client.EventType.TOOL_CALL_END) info.hasEnd = true;
2020
+ else info.hasResult = true;
2021
+ if (info.hasEnd && info.hasResult) openToolCalls.delete(toolCallId);
2022
+ break;
2023
+ }
2024
+ case _ag_ui_client.EventType.RUN_FINISHED:
2025
+ case _ag_ui_client.EventType.RUN_ERROR:
2026
+ terminalEventObserved = true;
2027
+ openMessageIds.clear();
2028
+ openToolCalls.clear();
2029
+ break;
2030
+ default: break;
1801
2031
  }
1802
- default: break;
1803
- }
1804
- if (events.some((event) => event.type === _ag_ui_client.EventType.RUN_FINISHED || event.type === _ag_ui_client.EventType.RUN_ERROR)) return appended;
1805
- for (const messageId of openMessageIds) {
1806
- const endEvent = {
2032
+ };
2033
+ const finalize = (options = {}) => {
2034
+ if (terminalEventObserved) return [];
2035
+ const { stopRequested = false, interruptionMessage } = options;
2036
+ const resolvedStopMessage = interruptionMessage !== null && interruptionMessage !== void 0 ? interruptionMessage : defaultStopMessage;
2037
+ const resolvedAbruptMessage = interruptionMessage && interruptionMessage !== defaultStopMessage ? interruptionMessage : defaultAbruptEndMessage;
2038
+ const appended = [];
2039
+ for (const messageId of openMessageIds) appended.push({
1807
2040
  type: _ag_ui_client.EventType.TEXT_MESSAGE_END,
1808
2041
  messageId
1809
- };
1810
- events.push(endEvent);
1811
- appended.push(endEvent);
1812
- }
1813
- for (const [toolCallId, info] of openToolCalls) {
1814
- if (!info.hasEnd) {
1815
- const endEvent = {
2042
+ });
2043
+ for (const [toolCallId, info] of openToolCalls) {
2044
+ if (!info.hasEnd) appended.push({
1816
2045
  type: _ag_ui_client.EventType.TOOL_CALL_END,
1817
2046
  toolCallId
1818
- };
1819
- events.push(endEvent);
1820
- appended.push(endEvent);
1821
- }
1822
- if (!info.hasResult) {
1823
- const resultEvent = {
2047
+ });
2048
+ if (!info.hasResult) appended.push({
1824
2049
  type: _ag_ui_client.EventType.TOOL_CALL_RESULT,
1825
2050
  toolCallId,
1826
- messageId: `${toolCallId !== null && toolCallId !== void 0 ? toolCallId : randomUUID()}-result`,
2051
+ messageId: `${toolCallId}-result`,
1827
2052
  role: "tool",
1828
2053
  content: JSON.stringify(stopRequested ? {
1829
2054
  status: "stopped",
@@ -1834,24 +2059,37 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
1834
2059
  reason: "missing_terminal_event",
1835
2060
  message: resolvedAbruptMessage
1836
2061
  })
2062
+ });
2063
+ }
2064
+ if (stopRequested) appended.push({ type: _ag_ui_client.EventType.RUN_FINISHED });
2065
+ else {
2066
+ const errorEvent = {
2067
+ type: _ag_ui_client.EventType.RUN_ERROR,
2068
+ message: resolvedAbruptMessage,
2069
+ code: "INCOMPLETE_STREAM"
1837
2070
  };
1838
- events.push(resultEvent);
1839
- appended.push(resultEvent);
2071
+ appended.push(errorEvent);
1840
2072
  }
1841
- }
1842
- if (stopRequested) {
1843
- const finishedEvent = { type: _ag_ui_client.EventType.RUN_FINISHED };
1844
- events.push(finishedEvent);
1845
- appended.push(finishedEvent);
1846
- } else {
1847
- const errorEvent = {
1848
- type: _ag_ui_client.EventType.RUN_ERROR,
1849
- message: resolvedAbruptMessage,
1850
- code: "INCOMPLETE_STREAM"
1851
- };
1852
- events.push(errorEvent);
1853
- appended.push(errorEvent);
1854
- }
2073
+ terminalEventObserved = true;
2074
+ openMessageIds.clear();
2075
+ openToolCalls.clear();
2076
+ return appended;
2077
+ };
2078
+ return {
2079
+ observe,
2080
+ finalize
2081
+ };
2082
+ }
2083
+ /**
2084
+ * Array form of {@link createRunEventFinalizer} for callers that already keep
2085
+ * the run's events (runners persist them). Appends the closers to `events` in
2086
+ * place and returns them.
2087
+ */
2088
+ function finalizeRunEvents(events, options = {}) {
2089
+ const finalizer = createRunEventFinalizer();
2090
+ for (const event of events) finalizer.observe(event);
2091
+ const appended = finalizer.finalize(options);
2092
+ events.push(...appended);
1855
2093
  return appended;
1856
2094
  }
1857
2095
 
@@ -1937,7 +2175,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
1937
2175
 
1938
2176
  //#endregion
1939
2177
  //#region package.json
1940
- var version = "1.72.1-canary.sp-longthread-perf";
2178
+ var version = "1.73.1";
1941
2179
 
1942
2180
  //#endregion
1943
2181
  //#region src/a2ui-prompts.ts
@@ -2143,10 +2381,14 @@ exports.UNSAMPLED_RATE = UNSAMPLED_RATE;
2143
2381
  exports.UpgradeRequiredError = UpgradeRequiredError;
2144
2382
  exports.actionParametersToJsonSchema = actionParametersToJsonSchema;
2145
2383
  exports.classifyModelHost = classifyModelHost;
2384
+ exports.commitRowKeyStore = commitRowKeyStore;
2146
2385
  exports.computeSamplingMeta = computeSamplingMeta;
2147
2386
  exports.convertJsonSchemaToZodSchema = convertJsonSchemaToZodSchema;
2148
2387
  exports.copyToClipboard = copyToClipboard;
2388
+ exports.createAttachmentContent = createAttachmentContent;
2149
2389
  exports.createLicenseContextValue = createLicenseContextValue;
2390
+ exports.createRowKeyStore = createRowKeyStore;
2391
+ exports.createRunEventFinalizer = createRunEventFinalizer;
2150
2392
  exports.dataToUUID = dataToUUID;
2151
2393
  exports.ensureStructuredError = ensureStructuredError;
2152
2394
  exports.exceedsMaxSize = exceedsMaxSize;
@@ -2179,12 +2421,15 @@ exports.parseJson = parseJson;
2179
2421
  exports.parseTelemetryIdFromLicense = parseTelemetryIdFromLicense;
2180
2422
  exports.partialJSONParse = partialJSONParse;
2181
2423
  exports.phoenixExponentialBackoff = phoenixExponentialBackoff;
2424
+ exports.pruneRowKeyStore = pruneRowKeyStore;
2182
2425
  exports.publicApiKeyRequired = publicApiKeyRequired;
2183
2426
  exports.randomId = randomId;
2184
2427
  exports.randomUUID = randomUUID;
2185
2428
  exports.readBody = readBody;
2186
2429
  exports.readFileAsBase64 = readFileAsBase64;
2187
2430
  exports.resolveDebugConfig = resolveDebugConfig;
2431
+ exports.resolveRowRenderKeys = resolveRowRenderKeys;
2432
+ exports.resolveRowRenderKeysById = resolveRowRenderKeysById;
2188
2433
  exports.safeParseToolArgs = safeParseToolArgs;
2189
2434
  exports.schemaToJsonSchema = schemaToJsonSchema;
2190
2435
  exports.shouldEnableInspector = shouldEnableInspector;