@trigger.dev/sdk 4.5.0-rc.4 → 4.5.0-rc.5
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/commonjs/imports/ai-runtime-cjs.cjs.map +1 -0
- package/dist/commonjs/imports/ai-runtime.d.ts +1 -0
- package/dist/commonjs/imports/ai-runtime.js +27 -0
- package/dist/commonjs/v3/ai.d.ts +10 -2
- package/dist/commonjs/v3/ai.js +46 -33
- package/dist/commonjs/v3/ai.js.map +1 -1
- package/dist/commonjs/v3/aiAutoTelemetry.d.ts +2 -0
- package/dist/commonjs/v3/aiAutoTelemetry.js +81 -0
- package/dist/commonjs/v3/aiAutoTelemetry.js.map +1 -0
- package/dist/commonjs/v3/chat-client.js +5 -3
- package/dist/commonjs/v3/chat-client.js.map +1 -1
- package/dist/commonjs/v3/chat-server.d.ts +29 -6
- package/dist/commonjs/v3/chat-server.js +6 -4
- package/dist/commonjs/v3/chat-server.js.map +1 -1
- package/dist/commonjs/v3/chat.d.ts +11 -0
- package/dist/commonjs/v3/chat.js +61 -1
- package/dist/commonjs/v3/chat.js.map +1 -1
- package/dist/commonjs/v3/shared.js +17 -9
- package/dist/commonjs/v3/shared.js.map +1 -1
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/imports/ai-runtime.d.ts +2 -0
- package/dist/esm/imports/ai-runtime.js +16 -0
- package/dist/esm/imports/ai-runtime.js.map +1 -0
- package/dist/esm/v3/ai.d.ts +10 -2
- package/dist/esm/v3/ai.js +16 -3
- package/dist/esm/v3/ai.js.map +1 -1
- package/dist/esm/v3/aiAutoTelemetry.d.ts +2 -0
- package/dist/esm/v3/aiAutoTelemetry.js +78 -0
- package/dist/esm/v3/aiAutoTelemetry.js.map +1 -0
- package/dist/esm/v3/chat-client.js +3 -1
- package/dist/esm/v3/chat-client.js.map +1 -1
- package/dist/esm/v3/chat-server.d.ts +29 -6
- package/dist/esm/v3/chat-server.js +3 -1
- package/dist/esm/v3/chat-server.js.map +1 -1
- package/dist/esm/v3/chat.d.ts +11 -0
- package/dist/esm/v3/chat.js +61 -1
- package/dist/esm/v3/chat.js.map +1 -1
- package/dist/esm/v3/shared.js +18 -10
- package/dist/esm/v3/shared.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +11 -6
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-runtime-cjs.cjs","sourceRoot":"","sources":["../../../src/imports/ai-runtime-cjs.cts"],"names":[],"mappings":";AAAA,8EAA8E;AAC9E,iFAAiF;;AAEjF,aAAa;AACb,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzB,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,sBAAsB,GAAG,EAAE,CAAC,sBAAsB,CAAC;AAClE,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,WAAW,GAAG,EAAE,CAAC,WAAW,CAAC;AAC5C,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,UAAU,GAAG,EAAE,CAAC,UAAU,CAAC;AAC1C,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,WAAW,GAAG,EAAE,CAAC,WAAW,CAAC;AAC5C,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,YAAY,GAAG,EAAE,CAAC,YAAY,CAAC;AAC9C,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,UAAU,GAAG,EAAE,CAAC,UAAU,CAAC;AAC1C,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,mBAAmB,GAAG,EAAE,CAAC,mBAAmB,CAAC;AAC5D,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,WAAW,GAAG,EAAE,CAAC,WAAW,CAAC;AAC5C,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,CAAC;AAC9B,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,SAAS,GAAG,EAAE,CAAC,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// CJS variant of ./ai-runtime.ts — tshy swaps this in for the CommonJS build.
|
|
3
|
+
// `require("ai")` of an ESM-only package is supported on Node >=20.19 / >=22.12.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
const ai = require("ai");
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
module.exports.convertToModelMessages = ai.convertToModelMessages;
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
module.exports.dynamicTool = ai.dynamicTool;
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
module.exports.generateId = ai.generateId;
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
module.exports.getToolName = ai.getToolName;
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
module.exports.isToolUIPart = ai.isToolUIPart;
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
module.exports.jsonSchema = ai.jsonSchema;
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
module.exports.readUIMessageStream = ai.readUIMessageStream;
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
module.exports.stepCountIs = ai.stepCountIs;
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
module.exports.tool = ai.tool;
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
module.exports.zodSchema = ai.zodSchema;
|
|
27
|
+
//# sourceMappingURL=ai-runtime-cjs.cjs.map
|
package/dist/commonjs/v3/ai.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { AnyTask, type MachinePresetName, type RealtimeDefinedInputStream, type RealtimeDefinedStream, Task, type inferSchemaIn, type inferSchemaOut, type TaskIdentifier, type TaskOptions, type TaskSchema, type TaskRunContext, type TaskWithSchema } from "@trigger.dev/core/v3";
|
|
2
|
-
import type { FinishReason, ModelMessage, ToolSet, UIMessage, UIMessageChunk, UIMessageStreamOptions
|
|
3
|
-
|
|
2
|
+
import type { FinishReason, LanguageModelUsage, ModelMessage, Tool, ToolSet, UIMessage, UIMessageChunk, UIMessageStreamOptions } from "ai";
|
|
3
|
+
type ToolCallOptions = {
|
|
4
|
+
toolCallId: string;
|
|
5
|
+
messages?: ModelMessage[];
|
|
6
|
+
abortSignal?: AbortSignal;
|
|
7
|
+
experimental_context?: unknown;
|
|
8
|
+
context?: unknown;
|
|
9
|
+
};
|
|
4
10
|
import { locals } from "./locals.js";
|
|
5
11
|
import type { ResolvedPrompt } from "./prompt.js";
|
|
6
12
|
import type { ResolvedSkill } from "./skill.js";
|
|
@@ -10,6 +16,8 @@ export type { TaskRunContext } from "@trigger.dev/core/v3";
|
|
|
10
16
|
export type ToolCallExecutionOptions = {
|
|
11
17
|
toolCallId: string;
|
|
12
18
|
experimental_context?: unknown;
|
|
19
|
+
/** v7 name for the user context (`experimental_context` on v6). */
|
|
20
|
+
context?: unknown;
|
|
13
21
|
/** Chat context — only present when the tool runs inside a chat.agent turn. */
|
|
14
22
|
chatId?: string;
|
|
15
23
|
turn?: number;
|
package/dist/commonjs/v3/ai.js
CHANGED
|
@@ -12,7 +12,9 @@ exports.__setReplaySessionInTailImplForTests = __setReplaySessionInTailImplForTe
|
|
|
12
12
|
exports.__replaySessionInTailProductionPathForTests = __replaySessionInTailProductionPathForTests;
|
|
13
13
|
exports.buildSkillTools = buildSkillTools;
|
|
14
14
|
const v3_1 = require("@trigger.dev/core/v3");
|
|
15
|
-
|
|
15
|
+
// Runtime VALUES go through the ESM/CJS shim so the CJS build can `require`
|
|
16
|
+
// ESM-only `ai@7` (see ../imports/ai-runtime.ts).
|
|
17
|
+
const ai_runtime_js_1 = require("../imports/ai-runtime.js");
|
|
16
18
|
const api_1 = require("@opentelemetry/api");
|
|
17
19
|
const auth_js_1 = require("./auth.js");
|
|
18
20
|
const locals_js_1 = require("./locals.js");
|
|
@@ -29,6 +31,7 @@ const agentSkillsRuntime_js_1 = require("./agentSkillsRuntime.js");
|
|
|
29
31
|
const streams_js_1 = require("./streams.js");
|
|
30
32
|
const sessions_js_1 = require("./sessions.js");
|
|
31
33
|
const shared_js_1 = require("./shared.js");
|
|
34
|
+
const aiAutoTelemetry_js_1 = require("./aiAutoTelemetry.js");
|
|
32
35
|
const v3_2 = require("@trigger.dev/core/v3");
|
|
33
36
|
const tracer_js_1 = require("./tracer.js");
|
|
34
37
|
const METADATA_KEY = "tool.execute.options";
|
|
@@ -44,7 +47,7 @@ function toModelMessages(messages) {
|
|
|
44
47
|
// conditional spread keeps the options object byte-identical to the no-tools
|
|
45
48
|
// path when nothing was declared.
|
|
46
49
|
const tools = locals_js_1.locals.get(chatResolvedToolsKey);
|
|
47
|
-
return (0,
|
|
50
|
+
return (0, ai_runtime_js_1.convertToModelMessages)(messages, {
|
|
48
51
|
ignoreIncompleteToolCalls: true,
|
|
49
52
|
...(tools ? { tools } : {}),
|
|
50
53
|
});
|
|
@@ -451,7 +454,7 @@ async function replaySessionOutTail(sessionId, options) {
|
|
|
451
454
|
});
|
|
452
455
|
let last;
|
|
453
456
|
try {
|
|
454
|
-
for await (const snapshot of (0,
|
|
457
|
+
for await (const snapshot of (0, ai_runtime_js_1.readUIMessageStream)({ stream: segmentStream })) {
|
|
455
458
|
last = snapshot;
|
|
456
459
|
}
|
|
457
460
|
}
|
|
@@ -654,9 +657,14 @@ function createTaskToolExecuteHandler(task) {
|
|
|
654
657
|
const toolMeta = {
|
|
655
658
|
toolCallId: toolOpts?.toolCallId ?? "",
|
|
656
659
|
};
|
|
657
|
-
|
|
660
|
+
// v6 passes user context as `experimental_context`, v7 as `context`. Read
|
|
661
|
+
// whichever is set and stamp both so subtasks reading either name work.
|
|
662
|
+
const toolContext = toolOpts?.context ?? toolOpts?.experimental_context;
|
|
663
|
+
if (toolContext !== undefined) {
|
|
658
664
|
try {
|
|
659
|
-
|
|
665
|
+
const serialized = JSON.parse(JSON.stringify(toolContext));
|
|
666
|
+
toolMeta.experimental_context = serialized;
|
|
667
|
+
toolMeta.context = serialized;
|
|
660
668
|
}
|
|
661
669
|
catch {
|
|
662
670
|
/* non-serializable */
|
|
@@ -699,9 +707,9 @@ function toolFromTask(task, options) {
|
|
|
699
707
|
// Zod-backed tasks: use static `tool()` so runtime shape matches `ToolSet`. Generic task context
|
|
700
708
|
// prevents `tool()` overloads from inferring input; `as any` is localized to this call only.
|
|
701
709
|
if ("schema" in task && task.schema && (0, v3_1.isSchemaZodEsque)(task.schema)) {
|
|
702
|
-
const staticTool = (0,
|
|
710
|
+
const staticTool = (0, ai_runtime_js_1.tool)({
|
|
703
711
|
description: task.description ?? "",
|
|
704
|
-
inputSchema: (0,
|
|
712
|
+
inputSchema: (0, ai_runtime_js_1.zodSchema)(task.schema),
|
|
705
713
|
execute: async (input, toolOpts) => executeFromTaskInput(input, toolOpts),
|
|
706
714
|
...(options?.experimental_toToolResultContent !== undefined
|
|
707
715
|
? { experimental_toToolResultContent: options.experimental_toToolResultContent }
|
|
@@ -709,7 +717,7 @@ function toolFromTask(task, options) {
|
|
|
709
717
|
});
|
|
710
718
|
return staticTool;
|
|
711
719
|
}
|
|
712
|
-
const toolDefinition = (0,
|
|
720
|
+
const toolDefinition = (0, ai_runtime_js_1.dynamicTool)({
|
|
713
721
|
description: task.description,
|
|
714
722
|
inputSchema: convertTaskSchemaToToolParameters(task),
|
|
715
723
|
...(options?.experimental_toToolResultContent !== undefined
|
|
@@ -777,15 +785,15 @@ function convertTaskSchemaToToolParameters(task) {
|
|
|
777
785
|
if ("schema" in task) {
|
|
778
786
|
// If TaskSchema is ArkTypeEsque, use ai.jsonSchema to convert it to a Schema
|
|
779
787
|
if ("toJsonSchema" in task.schema && typeof task.schema.toJsonSchema === "function") {
|
|
780
|
-
return (0,
|
|
788
|
+
return (0, ai_runtime_js_1.jsonSchema)(task.schema.toJsonSchema());
|
|
781
789
|
}
|
|
782
790
|
// If TaskSchema is ZodEsque, use ai.zodSchema to convert it to a Schema
|
|
783
791
|
if ((0, v3_1.isSchemaZodEsque)(task.schema)) {
|
|
784
|
-
return (0,
|
|
792
|
+
return (0, ai_runtime_js_1.zodSchema)(task.schema);
|
|
785
793
|
}
|
|
786
794
|
}
|
|
787
795
|
if ("jsonSchema" in task) {
|
|
788
|
-
return (0,
|
|
796
|
+
return (0, ai_runtime_js_1.jsonSchema)(task.jsonSchema);
|
|
789
797
|
}
|
|
790
798
|
throw new Error("Cannot convert task to a tool. Make sure to use a task with a schema or jsonSchema.");
|
|
791
799
|
}
|
|
@@ -1269,7 +1277,7 @@ function synthesizeHandoverUIMessage(partial, messageId) {
|
|
|
1269
1277
|
// browser). Fall back to a fresh id only if the handover signal
|
|
1270
1278
|
// didn't carry one.
|
|
1271
1279
|
return {
|
|
1272
|
-
id: messageId ?? (0,
|
|
1280
|
+
id: messageId ?? (0, ai_runtime_js_1.generateId)(),
|
|
1273
1281
|
role: "assistant",
|
|
1274
1282
|
parts,
|
|
1275
1283
|
};
|
|
@@ -1425,7 +1433,7 @@ function* iterateToolParts(message) {
|
|
|
1425
1433
|
if (message.role !== "assistant")
|
|
1426
1434
|
return;
|
|
1427
1435
|
for (const part of (message.parts ?? [])) {
|
|
1428
|
-
if (!(0,
|
|
1436
|
+
if (!(0, ai_runtime_js_1.isToolUIPart)(part))
|
|
1429
1437
|
continue;
|
|
1430
1438
|
const toolCallId = part.toolCallId;
|
|
1431
1439
|
if (typeof toolCallId !== "string" || toolCallId.length === 0)
|
|
@@ -1433,7 +1441,7 @@ function* iterateToolParts(message) {
|
|
|
1433
1441
|
yield {
|
|
1434
1442
|
part,
|
|
1435
1443
|
toolCallId,
|
|
1436
|
-
toolName: (0,
|
|
1444
|
+
toolName: (0, ai_runtime_js_1.getToolName)(part),
|
|
1437
1445
|
state: part.state,
|
|
1438
1446
|
};
|
|
1439
1447
|
}
|
|
@@ -1457,7 +1465,7 @@ function extractPendingToolCallsFromPartial(partial) {
|
|
|
1457
1465
|
const parts = (partial.parts ?? []);
|
|
1458
1466
|
for (let i = 0; i < parts.length; i++) {
|
|
1459
1467
|
const part = parts[i];
|
|
1460
|
-
if (!(0,
|
|
1468
|
+
if (!(0, ai_runtime_js_1.isToolUIPart)(part))
|
|
1461
1469
|
continue;
|
|
1462
1470
|
if (!isPendingToolState(part.state))
|
|
1463
1471
|
continue;
|
|
@@ -1466,7 +1474,7 @@ function extractPendingToolCallsFromPartial(partial) {
|
|
|
1466
1474
|
continue;
|
|
1467
1475
|
out.push({
|
|
1468
1476
|
toolCallId,
|
|
1469
|
-
toolName: (0,
|
|
1477
|
+
toolName: (0, ai_runtime_js_1.getToolName)(part),
|
|
1470
1478
|
input: part.input,
|
|
1471
1479
|
partIndex: i,
|
|
1472
1480
|
});
|
|
@@ -1569,7 +1577,7 @@ function extractNewToolResultsFromHistory(message, messages) {
|
|
|
1569
1577
|
function mergeIncomingIntoHydrated(hydrated, incoming) {
|
|
1570
1578
|
const incomingAdvancedByCallId = new Map();
|
|
1571
1579
|
for (const part of (incoming.parts ?? [])) {
|
|
1572
|
-
if (!(0,
|
|
1580
|
+
if (!(0, ai_runtime_js_1.isToolUIPart)(part))
|
|
1573
1581
|
continue;
|
|
1574
1582
|
const toolCallId = part.toolCallId;
|
|
1575
1583
|
if (typeof toolCallId !== "string" || toolCallId.length === 0)
|
|
@@ -1583,7 +1591,7 @@ function mergeIncomingIntoHydrated(hydrated, incoming) {
|
|
|
1583
1591
|
let mutated = false;
|
|
1584
1592
|
const hydratedParts = (hydrated.parts ?? []);
|
|
1585
1593
|
const mergedParts = hydratedParts.map((part) => {
|
|
1586
|
-
if (!(0,
|
|
1594
|
+
if (!(0, ai_runtime_js_1.isToolUIPart)(part))
|
|
1587
1595
|
return part;
|
|
1588
1596
|
const toolCallId = part.toolCallId;
|
|
1589
1597
|
if (typeof toolCallId !== "string" || toolCallId.length === 0)
|
|
@@ -1973,7 +1981,7 @@ async function chatCompact(messages, steps, options) {
|
|
|
1973
1981
|
return { type: "skipped" };
|
|
1974
1982
|
}
|
|
1975
1983
|
const result = await tracer_js_1.tracer.startActiveSpan("context compaction", async (span) => {
|
|
1976
|
-
const compactionId = (0,
|
|
1984
|
+
const compactionId = (0, ai_runtime_js_1.generateId)();
|
|
1977
1985
|
let summary;
|
|
1978
1986
|
const { waitUntilComplete } = chatStream.writer({
|
|
1979
1987
|
spanName: "stream compaction chunks",
|
|
@@ -2148,7 +2156,7 @@ async function drainSteeringQueue(config, messages, steps, queueOverride) {
|
|
|
2148
2156
|
execute: ({ write }) => {
|
|
2149
2157
|
write({
|
|
2150
2158
|
type: ai_shared_js_2.PENDING_MESSAGE_INJECTED_TYPE,
|
|
2151
|
-
id: (0,
|
|
2159
|
+
id: (0, ai_runtime_js_1.generateId)(),
|
|
2152
2160
|
data: {
|
|
2153
2161
|
messageIds: uiMessages.map((m) => m.id),
|
|
2154
2162
|
messages: uiMessages.map((m, idx) => ({
|
|
@@ -2302,9 +2310,9 @@ function findSkillByName(skills, name) {
|
|
|
2302
2310
|
* (e.g. in a `chat.createSession` loop with custom streamText).
|
|
2303
2311
|
*/
|
|
2304
2312
|
function buildSkillTools(skills) {
|
|
2305
|
-
const loadSkill = (0,
|
|
2313
|
+
const loadSkill = (0, ai_runtime_js_1.tool)({
|
|
2306
2314
|
description: "Load the full instructions for a skill by its name. Call this first before using a skill.",
|
|
2307
|
-
inputSchema: (0,
|
|
2315
|
+
inputSchema: (0, ai_runtime_js_1.jsonSchema)({
|
|
2308
2316
|
type: "object",
|
|
2309
2317
|
properties: {
|
|
2310
2318
|
name: {
|
|
@@ -2332,9 +2340,9 @@ function buildSkillTools(skills) {
|
|
|
2332
2340
|
};
|
|
2333
2341
|
},
|
|
2334
2342
|
});
|
|
2335
|
-
const readFile = (0,
|
|
2343
|
+
const readFile = (0, ai_runtime_js_1.tool)({
|
|
2336
2344
|
description: "Read a file from a skill's bundled folder. Paths must be relative to the skill's root.",
|
|
2337
|
-
inputSchema: (0,
|
|
2345
|
+
inputSchema: (0, ai_runtime_js_1.jsonSchema)({
|
|
2338
2346
|
type: "object",
|
|
2339
2347
|
properties: {
|
|
2340
2348
|
skill: { type: "string", description: "The skill's name (from frontmatter)." },
|
|
@@ -2362,9 +2370,9 @@ function buildSkillTools(skills) {
|
|
|
2362
2370
|
}
|
|
2363
2371
|
},
|
|
2364
2372
|
});
|
|
2365
|
-
const bash = (0,
|
|
2373
|
+
const bash = (0, ai_runtime_js_1.tool)({
|
|
2366
2374
|
description: "Run a bash command inside a skill's bundled folder. Use this to invoke the skill's scripts. The working directory is the skill's root.",
|
|
2367
|
-
inputSchema: (0,
|
|
2375
|
+
inputSchema: (0, ai_runtime_js_1.jsonSchema)({
|
|
2368
2376
|
type: "object",
|
|
2369
2377
|
properties: {
|
|
2370
2378
|
skill: { type: "string", description: "The skill's name (from frontmatter)." },
|
|
@@ -2630,6 +2638,11 @@ function chatAgent(options) {
|
|
|
2630
2638
|
agentConfig: { type: "ai-sdk-chat" },
|
|
2631
2639
|
run: async (payload, { signal: runSignal, ctx }) => {
|
|
2632
2640
|
locals_js_1.locals.set(chatAgentRunContextKey, ctx);
|
|
2641
|
+
// On AI SDK 7, register the `@ai-sdk/otel` integration (once per process)
|
|
2642
|
+
// so `experimental_telemetry` spans flow into the run trace. Awaited here
|
|
2643
|
+
// at run boot — before any `streamText` — and a no-op on v5/v6 or when the
|
|
2644
|
+
// optional `@ai-sdk/otel` peer isn't installed. See ./aiAutoTelemetry.ts.
|
|
2645
|
+
await (0, aiAutoTelemetry_js_1.ensureAiSdkTelemetry)();
|
|
2633
2646
|
// Bind the run to its backing Session so every module-level helper
|
|
2634
2647
|
// (chat.stream, chat.messages, chat.stopSignal) resolves to this
|
|
2635
2648
|
// chat's `.in` / `.out` channels.
|
|
@@ -3826,7 +3839,7 @@ function chatAgent(options) {
|
|
|
3826
3839
|
const resolvedOptions = resolveUIMessageStreamOptions();
|
|
3827
3840
|
const uiStream = actionStreamResult.toUIMessageStream({
|
|
3828
3841
|
...resolvedOptions,
|
|
3829
|
-
generateMessageId: resolvedOptions.generateMessageId ??
|
|
3842
|
+
generateMessageId: resolvedOptions.generateMessageId ?? ai_runtime_js_1.generateId,
|
|
3830
3843
|
});
|
|
3831
3844
|
await pipeChat(uiStream, {
|
|
3832
3845
|
signal: combinedSignal,
|
|
@@ -4050,7 +4063,7 @@ function chatAgent(options) {
|
|
|
4050
4063
|
// Always provide generateMessageId so the start chunk carries a
|
|
4051
4064
|
// messageId. Without this, the frontend and backend generate IDs
|
|
4052
4065
|
// independently and they won't match for ID-based dedup.
|
|
4053
|
-
generateMessageId: resolvedOptions.generateMessageId ??
|
|
4066
|
+
generateMessageId: resolvedOptions.generateMessageId ?? ai_runtime_js_1.generateId,
|
|
4054
4067
|
onFinish: ({ responseMessage, finishReason, }) => {
|
|
4055
4068
|
capturedResponseMessage = responseMessage;
|
|
4056
4069
|
capturedFinishReason = finishReason;
|
|
@@ -4178,7 +4191,7 @@ function chatAgent(options) {
|
|
|
4178
4191
|
// may produce a message with an empty ID since IDs are normally
|
|
4179
4192
|
// assigned by the frontend's useChat).
|
|
4180
4193
|
if (!capturedResponseMessage.id) {
|
|
4181
|
-
capturedResponseMessage = { ...capturedResponseMessage, id: (0,
|
|
4194
|
+
capturedResponseMessage = { ...capturedResponseMessage, id: (0, ai_runtime_js_1.generateId)() };
|
|
4182
4195
|
}
|
|
4183
4196
|
// Append any non-transient data parts queued via chat.response or writer.write()
|
|
4184
4197
|
const queuedParts = locals_js_1.locals.get(chatResponsePartsKey);
|
|
@@ -4234,7 +4247,7 @@ function chatAgent(options) {
|
|
|
4234
4247
|
const remainingParts = locals_js_1.locals.get(chatResponsePartsKey);
|
|
4235
4248
|
if (remainingParts && remainingParts.length > 0) {
|
|
4236
4249
|
capturedResponseMessage = {
|
|
4237
|
-
id: (0,
|
|
4250
|
+
id: (0, ai_runtime_js_1.generateId)(),
|
|
4238
4251
|
role: "assistant",
|
|
4239
4252
|
parts: [...remainingParts],
|
|
4240
4253
|
};
|
|
@@ -4276,7 +4289,7 @@ function chatAgent(options) {
|
|
|
4276
4289
|
});
|
|
4277
4290
|
if (shouldTrigger) {
|
|
4278
4291
|
await tracer_js_1.tracer.startActiveSpan("context compaction (outer loop)", async (compactionSpan) => {
|
|
4279
|
-
const compactionId = (0,
|
|
4292
|
+
const compactionId = (0, ai_runtime_js_1.generateId)();
|
|
4280
4293
|
const { waitUntilComplete } = chatStream.writer({
|
|
4281
4294
|
spanName: "stream compaction chunks",
|
|
4282
4295
|
collapsed: true,
|
|
@@ -5350,7 +5363,7 @@ class ChatMessageAccumulator {
|
|
|
5350
5363
|
}
|
|
5351
5364
|
async addResponse(response) {
|
|
5352
5365
|
if (!response.id) {
|
|
5353
|
-
response = { ...response, id: (0,
|
|
5366
|
+
response = { ...response, id: (0, ai_runtime_js_1.generateId)() };
|
|
5354
5367
|
}
|
|
5355
5368
|
this.uiMessages.push(response);
|
|
5356
5369
|
try {
|
|
@@ -5679,7 +5692,7 @@ function createChatSession(payload, options) {
|
|
|
5679
5692
|
const queuedParts = locals_js_1.locals.get(chatResponsePartsKey);
|
|
5680
5693
|
if (queuedParts && queuedParts.length > 0) {
|
|
5681
5694
|
await accumulator.addResponse({
|
|
5682
|
-
id: (0,
|
|
5695
|
+
id: (0, ai_runtime_js_1.generateId)(),
|
|
5683
5696
|
role: "assistant",
|
|
5684
5697
|
parts: queuedParts,
|
|
5685
5698
|
});
|