@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.
- package/dist/esm/activities/chat/index.js +8 -6
- package/dist/esm/activities/chat/index.js.map +1 -1
- package/dist/esm/activities/chat/middleware/types.d.ts +4 -3
- package/dist/esm/activities/chat/middleware/types.js.map +1 -1
- package/dist/esm/activities/chat/tools/tool-calls.d.ts +2 -2
- package/dist/esm/activities/chat/tools/tool-calls.js +2 -2
- package/dist/esm/activities/chat/tools/tool-calls.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/stream-to-response.js +12 -6
- package/dist/esm/stream-to-response.js.map +1 -1
- package/dist/esm/strip-to-spec-middleware.js +2 -1
- package/dist/esm/strip-to-spec-middleware.js.map +1 -1
- package/dist/esm/types.d.ts +18 -1
- package/dist/esm/utilities/durability-batch.d.ts +8 -0
- package/dist/esm/utilities/durability-batch.js +45 -0
- package/dist/esm/utilities/durability-batch.js.map +1 -0
- package/package.json +3 -3
- package/src/activities/chat/index.ts +11 -5
- package/src/activities/chat/middleware/types.ts +8 -2
- package/src/activities/chat/tools/tool-calls.ts +15 -5
- package/src/stream-to-response.ts +16 -6
- package/src/strip-to-spec-middleware.ts +2 -1
- package/src/types.ts +23 -1
- package/src/utilities/durability-batch.ts +48 -0
|
@@ -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
|
-
|
|
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)}`;
|