@tanstack/ai 0.57.0 → 0.58.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.
@@ -6,6 +6,7 @@ import { publishRunDisconnectHandler } from "../../delivery-disconnect.js";
6
6
  import { EventType } from "../../types.js";
7
7
  import { rebuildTokenUsage } from "../../utilities/ag-ui-usage.js";
8
8
  import { tanstackMetadata, withTanstackMetadata } from "../../utilities/merge-metadata.js";
9
+ import { withDurabilityBatchHint } from "../../utilities/durability-batch.js";
9
10
  import { normalizeStreamChunk } from "../../utilities/normalize-stream-chunk.js";
10
11
  import { resolveDebugOption } from "../../logger/resolve.js";
11
12
  import { streamToText } from "../../stream-to-response.js";
@@ -228,8 +229,8 @@ var TextEngine = class {
228
229
  this.abortReason = reason;
229
230
  this.middlewareAbortController?.abort(reason);
230
231
  },
231
- emitCustomEvent: (name, value) => {
232
- this.middlewareCustomQueue.push(this.createCustomEventChunk(name, value));
232
+ emitCustomEvent: (name, value, options) => {
233
+ this.middlewareCustomQueue.push(this.createCustomEventChunk(name, value, options));
233
234
  const waiters = this.middlewareCustomWaiters;
234
235
  this.middlewareCustomWaiters = [];
235
236
  for (const waiter of waiters) waiter();
@@ -796,7 +797,7 @@ var TextEngine = class {
796
797
  return "wait";
797
798
  }
798
799
  const { approvals, clientToolResults } = this.collectClientState();
799
- const generator = executeToolCalls(executablePendingCalls, this.resolveExecutableTools(executablePendingCalls), approvals, clientToolResults, (eventName, data) => this.createCustomEventChunk(eventName, data), {
800
+ const generator = executeToolCalls(executablePendingCalls, this.resolveExecutableTools(executablePendingCalls), approvals, clientToolResults, (eventName, data, options) => this.createCustomEventChunk(eventName, data, options), {
800
801
  onBeforeToolCall: async (toolCall, tool, args) => {
801
802
  this.logger.tools(`phase=before name=${toolCall.function.name}`, {
802
803
  name: toolCall.function.name,
@@ -888,7 +889,7 @@ var TextEngine = class {
888
889
  return;
889
890
  }
890
891
  const { approvals, clientToolResults } = this.collectClientState();
891
- const generator = executeToolCalls(executableToolCalls, this.resolveExecutableTools(executableToolCalls), approvals, clientToolResults, (eventName, data) => this.createCustomEventChunk(eventName, data), {
892
+ const generator = executeToolCalls(executableToolCalls, this.resolveExecutableTools(executableToolCalls), approvals, clientToolResults, (eventName, data, options) => this.createCustomEventChunk(eventName, data, options), {
892
893
  onBeforeToolCall: async (toolCall, tool, args) => {
893
894
  this.logger.tools(`phase=before name=${toolCall.function.name}`, {
894
895
  name: toolCall.function.name,
@@ -2220,13 +2221,14 @@ var TextEngine = class {
2220
2221
  pending = generator.next();
2221
2222
  }
2222
2223
  }
2223
- createCustomEventChunk(eventName, value) {
2224
- return {
2224
+ createCustomEventChunk(eventName, value, options) {
2225
+ const chunk = {
2225
2226
  type: EventType.CUSTOM,
2226
2227
  timestamp: Date.now(),
2227
2228
  name: eventName,
2228
2229
  value
2229
2230
  };
2231
+ return options?.batch ? withDurabilityBatchHint(chunk) : chunk;
2230
2232
  }
2231
2233
  createId(prefix) {
2232
2234
  return `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;