@trigger.dev/sdk 4.5.0-rc.7 → 4.5.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.
- package/dist/commonjs/v3/ai-shared.js +1 -4
- package/dist/commonjs/v3/ai-shared.js.map +1 -1
- package/dist/commonjs/v3/ai.d.ts +13 -10
- package/dist/commonjs/v3/ai.js +121 -66
- package/dist/commonjs/v3/ai.js.map +1 -1
- package/dist/commonjs/v3/auth.d.ts +1 -1
- package/dist/commonjs/v3/auth.js +3 -4
- package/dist/commonjs/v3/auth.js.map +1 -1
- package/dist/commonjs/v3/batch.d.ts +1 -1
- package/dist/commonjs/v3/batch.js.map +1 -1
- package/dist/commonjs/v3/chat-client.js +18 -14
- package/dist/commonjs/v3/chat-client.js.map +1 -1
- package/dist/commonjs/v3/chat-react.js +2 -4
- package/dist/commonjs/v3/chat-react.js.map +1 -1
- package/dist/commonjs/v3/chat-server.d.ts +69 -1
- package/dist/commonjs/v3/chat-server.js +162 -14
- package/dist/commonjs/v3/chat-server.js.map +1 -1
- package/dist/commonjs/v3/chat-server.test.js +156 -12
- package/dist/commonjs/v3/chat-server.test.js.map +1 -1
- package/dist/commonjs/v3/chat.js +4 -3
- package/dist/commonjs/v3/chat.js.map +1 -1
- package/dist/commonjs/v3/chat.test.js +9 -48
- package/dist/commonjs/v3/chat.test.js.map +1 -1
- package/dist/commonjs/v3/deployments.d.ts +2 -3
- package/dist/commonjs/v3/deployments.js.map +1 -1
- package/dist/commonjs/v3/envvars.js.map +1 -1
- package/dist/commonjs/v3/idempotencyKeys.js.map +1 -1
- package/dist/commonjs/v3/metadata.d.ts +2 -2
- package/dist/commonjs/v3/prompt.js +2 -6
- package/dist/commonjs/v3/prompt.js.map +1 -1
- package/dist/commonjs/v3/promptManagement.js.map +1 -1
- package/dist/commonjs/v3/query.js.map +1 -1
- package/dist/commonjs/v3/queues.d.ts +1 -1
- package/dist/commonjs/v3/queues.js.map +1 -1
- package/dist/commonjs/v3/retry.d.ts +1 -1
- package/dist/commonjs/v3/retry.js +1 -1
- package/dist/commonjs/v3/retry.js.map +1 -1
- package/dist/commonjs/v3/runs.d.ts +3 -4
- package/dist/commonjs/v3/runs.js.map +1 -1
- package/dist/commonjs/v3/schedules/index.d.ts +3 -3
- package/dist/commonjs/v3/schedules/index.js.map +1 -1
- package/dist/commonjs/v3/sessions.d.ts +3 -4
- package/dist/commonjs/v3/sessions.js +2 -1
- package/dist/commonjs/v3/sessions.js.map +1 -1
- package/dist/commonjs/v3/shared.d.ts +3 -4
- package/dist/commonjs/v3/shared.js +0 -12
- package/dist/commonjs/v3/shared.js.map +1 -1
- package/dist/commonjs/v3/skill.js.map +1 -1
- package/dist/commonjs/v3/streams.d.ts +1 -1
- package/dist/commonjs/v3/streams.js +4 -5
- package/dist/commonjs/v3/streams.js.map +1 -1
- package/dist/commonjs/v3/streams.test.js +3 -3
- package/dist/commonjs/v3/streams.test.js.map +1 -1
- package/dist/commonjs/v3/test/mock-chat-agent.js +1 -4
- package/dist/commonjs/v3/test/mock-chat-agent.js.map +1 -1
- package/dist/commonjs/v3/test/test-session-handle.d.ts +2 -1
- package/dist/commonjs/v3/test/test-session-handle.js.map +1 -1
- package/dist/commonjs/v3/triggerClient.test.js +1 -1
- package/dist/commonjs/v3/triggerClient.test.js.map +1 -1
- package/dist/commonjs/v3/triggerClient.types.test.js +11 -11
- package/dist/commonjs/v3/triggerClient.types.test.js.map +1 -1
- package/dist/commonjs/v3/wait.d.ts +2 -1
- package/dist/commonjs/v3/wait.js.map +1 -1
- package/dist/commonjs/v3/webhooks.js +1 -1
- package/dist/commonjs/v3/webhooks.js.map +1 -1
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/v3/ai-shared.js +1 -4
- package/dist/esm/v3/ai-shared.js.map +1 -1
- package/dist/esm/v3/ai.d.ts +13 -10
- package/dist/esm/v3/ai.js +119 -54
- package/dist/esm/v3/ai.js.map +1 -1
- package/dist/esm/v3/auth.d.ts +1 -1
- package/dist/esm/v3/auth.js +1 -2
- package/dist/esm/v3/auth.js.map +1 -1
- package/dist/esm/v3/batch.d.ts +1 -1
- package/dist/esm/v3/batch.js +1 -1
- package/dist/esm/v3/batch.js.map +1 -1
- package/dist/esm/v3/chat-client.js +18 -14
- package/dist/esm/v3/chat-client.js.map +1 -1
- package/dist/esm/v3/chat-react.js +2 -4
- package/dist/esm/v3/chat-react.js.map +1 -1
- package/dist/esm/v3/chat-server.d.ts +69 -1
- package/dist/esm/v3/chat-server.js +162 -14
- package/dist/esm/v3/chat-server.js.map +1 -1
- package/dist/esm/v3/chat-server.test.js +156 -12
- package/dist/esm/v3/chat-server.test.js.map +1 -1
- package/dist/esm/v3/chat.js +4 -3
- package/dist/esm/v3/chat.js.map +1 -1
- package/dist/esm/v3/chat.test.js +9 -48
- package/dist/esm/v3/chat.test.js.map +1 -1
- package/dist/esm/v3/deployments.d.ts +2 -3
- package/dist/esm/v3/deployments.js +1 -1
- package/dist/esm/v3/deployments.js.map +1 -1
- package/dist/esm/v3/envvars.js.map +1 -1
- package/dist/esm/v3/idempotencyKeys.js +1 -1
- package/dist/esm/v3/idempotencyKeys.js.map +1 -1
- package/dist/esm/v3/metadata.d.ts +2 -2
- package/dist/esm/v3/prompt.js +2 -6
- package/dist/esm/v3/prompt.js.map +1 -1
- package/dist/esm/v3/promptManagement.js.map +1 -1
- package/dist/esm/v3/query.js.map +1 -1
- package/dist/esm/v3/queues.d.ts +1 -1
- package/dist/esm/v3/queues.js.map +1 -1
- package/dist/esm/v3/retry.d.ts +1 -1
- package/dist/esm/v3/retry.js +1 -1
- package/dist/esm/v3/retry.js.map +1 -1
- package/dist/esm/v3/runs.d.ts +2 -3
- package/dist/esm/v3/runs.js.map +1 -1
- package/dist/esm/v3/schedules/index.d.ts +3 -3
- package/dist/esm/v3/schedules/index.js.map +1 -1
- package/dist/esm/v3/sessions.d.ts +3 -4
- package/dist/esm/v3/sessions.js +2 -1
- package/dist/esm/v3/sessions.js.map +1 -1
- package/dist/esm/v3/shared.d.ts +3 -4
- package/dist/esm/v3/shared.js +1 -13
- package/dist/esm/v3/shared.js.map +1 -1
- package/dist/esm/v3/skill.js.map +1 -1
- package/dist/esm/v3/streams.d.ts +1 -1
- package/dist/esm/v3/streams.js +4 -5
- package/dist/esm/v3/streams.js.map +1 -1
- package/dist/esm/v3/streams.test.js +4 -4
- package/dist/esm/v3/streams.test.js.map +1 -1
- package/dist/esm/v3/test/mock-chat-agent.js +4 -7
- package/dist/esm/v3/test/mock-chat-agent.js.map +1 -1
- package/dist/esm/v3/test/test-session-handle.d.ts +2 -1
- package/dist/esm/v3/test/test-session-handle.js +1 -1
- package/dist/esm/v3/test/test-session-handle.js.map +1 -1
- package/dist/esm/v3/triggerClient.test.js +1 -1
- package/dist/esm/v3/triggerClient.test.js.map +1 -1
- package/dist/esm/v3/triggerClient.types.test.js +11 -11
- package/dist/esm/v3/triggerClient.types.test.js.map +1 -1
- package/dist/esm/v3/wait.d.ts +2 -1
- package/dist/esm/v3/wait.js.map +1 -1
- package/dist/esm/v3/webhooks.js +1 -1
- package/dist/esm/v3/webhooks.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/docs/ai/prompts.mdx +0 -4
- package/docs/ai-chat/actions.mdx +0 -4
- package/docs/ai-chat/anatomy.mdx +0 -4
- package/docs/ai-chat/backend.mdx +0 -4
- package/docs/ai-chat/background-injection.mdx +0 -4
- package/docs/ai-chat/changelog.mdx +109 -1
- package/docs/ai-chat/chat-local.mdx +0 -4
- package/docs/ai-chat/client-protocol.mdx +0 -4
- package/docs/ai-chat/compaction.mdx +0 -4
- package/docs/ai-chat/custom-agents.mdx +32 -4
- package/docs/ai-chat/error-handling.mdx +0 -4
- package/docs/ai-chat/fast-starts.mdx +86 -4
- package/docs/ai-chat/frontend.mdx +0 -4
- package/docs/ai-chat/how-it-works.mdx +0 -4
- package/docs/ai-chat/lifecycle-hooks.mdx +0 -4
- package/docs/ai-chat/mcp.mdx +0 -4
- package/docs/ai-chat/overview.mdx +0 -4
- package/docs/ai-chat/patterns/branching-conversations.mdx +0 -4
- package/docs/ai-chat/patterns/code-sandbox.mdx +0 -4
- package/docs/ai-chat/patterns/database-persistence.mdx +0 -4
- package/docs/ai-chat/patterns/human-in-the-loop.mdx +9 -5
- package/docs/ai-chat/patterns/large-payloads.mdx +0 -4
- package/docs/ai-chat/patterns/oom-resilience.mdx +0 -4
- package/docs/ai-chat/patterns/persistence-and-replay.mdx +0 -4
- package/docs/ai-chat/patterns/recovery-boot.mdx +0 -4
- package/docs/ai-chat/patterns/skills.mdx +0 -4
- package/docs/ai-chat/patterns/sub-agents.mdx +0 -4
- package/docs/ai-chat/patterns/tool-result-auditing.mdx +0 -4
- package/docs/ai-chat/patterns/trusted-edge-signals.mdx +0 -4
- package/docs/ai-chat/patterns/version-upgrades.mdx +0 -4
- package/docs/ai-chat/pending-messages.mdx +0 -4
- package/docs/ai-chat/prompt-caching.mdx +4 -4
- package/docs/ai-chat/quick-start.mdx +0 -4
- package/docs/ai-chat/reference.mdx +1 -5
- package/docs/ai-chat/server-chat.mdx +0 -4
- package/docs/ai-chat/sessions.mdx +0 -4
- package/docs/ai-chat/testing.mdx +0 -4
- package/docs/ai-chat/tools.mdx +0 -4
- package/docs/ai-chat/types.mdx +0 -4
- package/docs/ai-chat/upgrade-guide.mdx +0 -4
- package/docs/building-with-ai.mdx +1 -1
- package/docs/deploy-environment-variables.mdx +1 -1
- package/docs/deployment/dev-branches.mdx +92 -0
- package/docs/deployment/overview.mdx +1 -1
- package/docs/help-slack.mdx +1 -0
- package/docs/how-to-reduce-your-spend.mdx +14 -7
- package/docs/introduction.mdx +13 -13
- package/docs/mcp-agent-rules.mdx +1 -1
- package/docs/open-source-self-hosting.mdx +1 -1
- package/docs/self-hosting/kubernetes.mdx +8 -8
- package/docs/self-hosting/overview.mdx +2 -1
- package/docs/tasks/scheduled.mdx +2 -2
- package/docs/troubleshooting-debugging-in-vscode.mdx +1 -0
- package/docs/troubleshooting-github-issues.mdx +1 -1
- package/docs/troubleshooting-uptime-status.mdx +1 -0
- package/docs/video-walkthrough.mdx +1 -1
- package/docs/wait-for.mdx +1 -1
- package/package.json +2 -2
- package/docs/cli-dev.mdx +0 -8
|
@@ -128,10 +128,7 @@ function slimSubmitMessageForWire(message) {
|
|
|
128
128
|
if (message.role !== "assistant")
|
|
129
129
|
return message;
|
|
130
130
|
const parts = (message.parts ?? []);
|
|
131
|
-
const advancedToolParts = parts.filter((p) => p &&
|
|
132
|
-
typeof p === "object" &&
|
|
133
|
-
isToolPartType(p.type) &&
|
|
134
|
-
isWireAdvanceableToolState(p.state));
|
|
131
|
+
const advancedToolParts = parts.filter((p) => p && typeof p === "object" && isToolPartType(p.type) && isWireAdvanceableToolState(p.state));
|
|
135
132
|
if (advancedToolParts.length === 0)
|
|
136
133
|
return message;
|
|
137
134
|
const slimParts = advancedToolParts.map((p) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-shared.js","sourceRoot":"","sources":["../../../src/v3/ai-shared.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;
|
|
1
|
+
{"version":3,"file":"ai-shared.js","sourceRoot":"","sources":["../../../src/v3/ai-shared.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AA4OH,sDAiBC;AAoDD,4DAkCC;AA9UD;;;GAGG;AACU,QAAA,6BAA6B,GAAG,+BAAwC,CAAC;AA6LtF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,SAAgB,qBAAqB,CACnC,MAAc,EACd,KAGC;IAED,IAAI,KAAK,CAAC,OAAO,KAAK,gBAAgB;QAAE,OAAO,KAAK,CAAC;IACrD,IAAI,KAAK,CAAC,gBAAgB,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACtD,MAAM,MAAM,GAAG,KAAK,CAAC,gBAAgB,CAAC,KAAK,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACzE,IAAI,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAC1B,IAAI,MAAM,CAAC,EAAE,EAAE,CAAC;QACd,MAAM,WAAW,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,MAAM,CAAC,EAAE,CAAC,CAAC;QAChE,IAAI,WAAW,KAAK,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;IACvC,CAAC;IACD,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpB,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;GAMG;AACH,SAAS,0BAA0B,CACjC,KAAc;IAEd,OAAO,CACL,KAAK,KAAK,kBAAkB;QAC5B,KAAK,KAAK,cAAc;QACxB,KAAK,KAAK,oBAAoB;QAC9B,KAAK,KAAK,eAAe,CAC1B,CAAC;AACJ,CAAC;AAED,2EAA2E;AAC3E,SAAS,cAAc,CAAC,IAAa;IACnC,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,IAAI,KAAK,cAAc,CAAC,CAAC;AAC3F,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,SAAgB,wBAAwB,CAAqC,OAAa;IACxF,IAAI,CAAC,OAAO;QAAE,OAAO,OAAO,CAAC;IAC7B,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW;QAAE,OAAO,OAAO,CAAC;IACjD,MAAM,KAAK,GAAG,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,CAAU,CAAC;IAC7C,MAAM,iBAAiB,GAAG,KAAK,CAAC,MAAM,CACpC,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,0BAA0B,CAAC,CAAC,CAAC,KAAK,CAAC,CAC9F,CAAC;IACF,IAAI,iBAAiB,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC;IACnD,MAAM,SAAS,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE;QACjD,MAAM,IAAI,GAA4B;YACpC,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,UAAU,EAAE,CAAC,CAAC,UAAU;YACxB,KAAK,EAAE,CAAC,CAAC,KAAK;SACf,CAAC;QACF,IAAI,CAAC,CAAC,IAAI,KAAK,cAAc,IAAI,OAAO,CAAC,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAChE,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC;QAC7B,CAAC;QACD,IAAI,CAAC,CAAC,KAAK,KAAK,kBAAkB,EAAE,CAAC;YACnC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;YACvB,IAAI,CAAC,CAAC,QAAQ,KAAK,SAAS;gBAAE,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC;QAC3D,CAAC;aAAM,IAAI,CAAC,CAAC,KAAK,KAAK,cAAc,EAAE,CAAC;YACtC,IAAI,CAAC,CAAC,SAAS,KAAK,SAAS;gBAAE,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC;YAC5D,IAAI,CAAC,CAAC,QAAQ,KAAK,SAAS;gBAAE,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC;QAC3D,CAAC;aAAM,IAAI,CAAC,CAAC,KAAK,KAAK,oBAAoB,IAAI,CAAC,CAAC,KAAK,KAAK,eAAe,EAAE,CAAC;YAC3E,IAAI,CAAC,CAAC,QAAQ,KAAK,SAAS;gBAAE,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC;QAC3D,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;IACH,OAAO;QACL,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,KAAK,EAAE,SAAS;KACE,CAAC;AACvB,CAAC"}
|
package/dist/commonjs/v3/ai.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { AnyTask, type
|
|
1
|
+
import { type AnyTask, type Task, type ChatSnapshotV1, type ApiClientConfiguration, type inferSchemaIn, type inferSchemaOut, type MachinePresetName, type RealtimeDefinedInputStream, type RealtimeDefinedStream, type SessionTriggerConfig, type TaskIdentifier, type TaskOptions, type TaskRunContext, type TaskSchema, type TaskWithSchema } from "@trigger.dev/core/v3";
|
|
2
2
|
import type { FinishReason, LanguageModelUsage, ModelMessage, ProviderMetadata, Tool, ToolSet, UIMessage, UIMessageChunk, UIMessageStreamOptions } from "ai";
|
|
3
|
+
import { type ChatInputChunk, type ChatTaskWirePayload, type InferChatClientData, type InferChatUIMessage, type InferChatUIMessageFromTools, PENDING_MESSAGE_INJECTED_TYPE, upsertIncomingMessage } from "./ai-shared.js";
|
|
4
|
+
import { locals } from "./locals.js";
|
|
5
|
+
import type { ResolvedPrompt } from "./prompt.js";
|
|
6
|
+
import type { ResolvedSkill } from "./skill.js";
|
|
3
7
|
type ToolCallOptions = {
|
|
4
8
|
toolCallId: string;
|
|
5
9
|
messages?: ModelMessage[];
|
|
@@ -7,10 +11,6 @@ type ToolCallOptions = {
|
|
|
7
11
|
experimental_context?: unknown;
|
|
8
12
|
context?: unknown;
|
|
9
13
|
};
|
|
10
|
-
import { locals } from "./locals.js";
|
|
11
|
-
import type { ResolvedPrompt } from "./prompt.js";
|
|
12
|
-
import type { ResolvedSkill } from "./skill.js";
|
|
13
|
-
import { type SessionTriggerConfig } from "@trigger.dev/core/v3";
|
|
14
14
|
/** Re-export for typing `ctx` in `chat.agent` hooks without importing `@trigger.dev/core`. */
|
|
15
15
|
export type { TaskRunContext } from "@trigger.dev/core/v3";
|
|
16
16
|
export type ToolCallExecutionOptions = {
|
|
@@ -171,8 +171,6 @@ export type ChatWriter = {
|
|
|
171
171
|
/** Merge another stream's chunks into the chat stream. */
|
|
172
172
|
merge(stream: ReadableStream<UIMessageChunk>): void;
|
|
173
173
|
};
|
|
174
|
-
import type { ChatTaskWirePayload } from "./ai-shared.js";
|
|
175
|
-
export type { ChatTaskWirePayload, ChatInputChunk } from "./ai-shared.js";
|
|
176
174
|
/**
|
|
177
175
|
* The payload shape passed to the `chatAgent` run function.
|
|
178
176
|
*
|
|
@@ -520,7 +518,8 @@ export type PendingMessagesOptions<TUIM extends UIMessage = UIMessage> = {
|
|
|
520
518
|
* between tool-call steps. The frontend can match on this to render
|
|
521
519
|
* injection points inline in the assistant response.
|
|
522
520
|
*/
|
|
523
|
-
export { PENDING_MESSAGE_INJECTED_TYPE, upsertIncomingMessage }
|
|
521
|
+
export { PENDING_MESSAGE_INJECTED_TYPE, upsertIncomingMessage };
|
|
522
|
+
export type { InferChatClientData, InferChatUIMessage, InferChatUIMessageFromTools };
|
|
524
523
|
/**
|
|
525
524
|
* Event passed to the `prepareMessages` hook.
|
|
526
525
|
*/
|
|
@@ -2795,8 +2794,6 @@ declare function chatLocal<T extends Record<string, unknown>>(options: {
|
|
|
2795
2794
|
* // { model?: string; userId: string }
|
|
2796
2795
|
* ```
|
|
2797
2796
|
*/
|
|
2798
|
-
import type { InferChatClientData } from "./ai-shared.js";
|
|
2799
|
-
export type { InferChatClientData, InferChatUIMessage, InferChatUIMessageFromTools, } from "./ai-shared.js";
|
|
2800
2797
|
/**
|
|
2801
2798
|
* Options for {@link createChatStartSessionAction}.
|
|
2802
2799
|
*/
|
|
@@ -2839,6 +2836,12 @@ export type CreateChatStartSessionActionOptions = {
|
|
|
2839
2836
|
* custom retry. Applies to both session-create and JWT-claims POSTs.
|
|
2840
2837
|
*/
|
|
2841
2838
|
fetch?: ChatStartSessionFetchOverride;
|
|
2839
|
+
/**
|
|
2840
|
+
* API client config (baseURL / accessToken) to scope this action to a specific
|
|
2841
|
+
* environment, for callers that can't set a global `TRIGGER_SECRET_KEY`. The
|
|
2842
|
+
* returned action runs under this config.
|
|
2843
|
+
*/
|
|
2844
|
+
apiClient?: ApiClientConfiguration;
|
|
2842
2845
|
};
|
|
2843
2846
|
/**
|
|
2844
2847
|
* Params for the function returned by {@link createChatStartSessionAction}.
|
package/dist/commonjs/v3/ai.js
CHANGED
|
@@ -15,8 +15,11 @@ exports.buildSkillTools = buildSkillTools;
|
|
|
15
15
|
const v3_1 = require("@trigger.dev/core/v3");
|
|
16
16
|
// Runtime VALUES go through the ESM/CJS shim so the CJS build can `require`
|
|
17
17
|
// ESM-only `ai@7` (see ../imports/ai-runtime.ts).
|
|
18
|
-
const ai_runtime_js_1 = require("../imports/ai-runtime.js");
|
|
19
18
|
const api_1 = require("@opentelemetry/api");
|
|
19
|
+
const ai_runtime_js_1 = require("../imports/ai-runtime.js");
|
|
20
|
+
const ai_shared_js_1 = require("./ai-shared.js");
|
|
21
|
+
Object.defineProperty(exports, "PENDING_MESSAGE_INJECTED_TYPE", { enumerable: true, get: function () { return ai_shared_js_1.PENDING_MESSAGE_INJECTED_TYPE; } });
|
|
22
|
+
Object.defineProperty(exports, "upsertIncomingMessage", { enumerable: true, get: function () { return ai_shared_js_1.upsertIncomingMessage; } });
|
|
20
23
|
const auth_js_1 = require("./auth.js");
|
|
21
24
|
const locals_js_1 = require("./locals.js");
|
|
22
25
|
const metadata_js_1 = require("./metadata.js");
|
|
@@ -29,11 +32,10 @@ const metadata_js_1 = require("./metadata.js");
|
|
|
29
32
|
// never touches `ai.ts`'s module graph, so the `node:*` builtins
|
|
30
33
|
// pulled in transitively here never reach a client chunk.
|
|
31
34
|
const agentSkillsRuntime_js_1 = require("./agentSkillsRuntime.js");
|
|
32
|
-
const
|
|
35
|
+
const aiAutoTelemetry_js_1 = require("./aiAutoTelemetry.js");
|
|
33
36
|
const sessions_js_1 = require("./sessions.js");
|
|
34
37
|
const shared_js_1 = require("./shared.js");
|
|
35
|
-
const
|
|
36
|
-
const v3_2 = require("@trigger.dev/core/v3");
|
|
38
|
+
const streams_js_1 = require("./streams.js");
|
|
37
39
|
const tracer_js_1 = require("./tracer.js");
|
|
38
40
|
const METADATA_KEY = "tool.execute.options";
|
|
39
41
|
/**
|
|
@@ -155,7 +157,9 @@ async function seedSessionInResumeCursorForCustomLoop(payload) {
|
|
|
155
157
|
}
|
|
156
158
|
}
|
|
157
159
|
catch (error) {
|
|
158
|
-
v3_1.logger.warn("chat session: session.in resume cursor lookup failed; old messages may replay", {
|
|
160
|
+
v3_1.logger.warn("chat session: session.in resume cursor lookup failed; old messages may replay", {
|
|
161
|
+
error: error instanceof Error ? error.message : String(error),
|
|
162
|
+
});
|
|
159
163
|
}
|
|
160
164
|
}
|
|
161
165
|
let readChatSnapshotImpl;
|
|
@@ -1241,8 +1245,7 @@ const handoverInput = {
|
|
|
1241
1245
|
const result = await getChatSession().in.waitWithIdleTimeout(options);
|
|
1242
1246
|
if (!result.ok)
|
|
1243
1247
|
return result;
|
|
1244
|
-
if (result.output.kind === "handover" ||
|
|
1245
|
-
result.output.kind === "handover-skip") {
|
|
1248
|
+
if (result.output.kind === "handover" || result.output.kind === "handover-skip") {
|
|
1246
1249
|
return { ok: true, output: result.output };
|
|
1247
1250
|
}
|
|
1248
1251
|
// Other kinds (message, stop) are not expected during handover-prepare.
|
|
@@ -1898,19 +1901,6 @@ const chatUpgradeRequestedKey = locals_js_1.locals.create("chat.upgradeRequested
|
|
|
1898
1901
|
const chatEndRunRequestedKey = locals_js_1.locals.create("chat.endRunRequested");
|
|
1899
1902
|
/** @internal */
|
|
1900
1903
|
const chatAgentCompactionKey = locals_js_1.locals.create("chat.agentCompaction");
|
|
1901
|
-
/**
|
|
1902
|
-
* The data part type used to signal that pending messages were injected
|
|
1903
|
-
* between tool-call steps. The frontend can match on this to render
|
|
1904
|
-
* injection points inline in the assistant response.
|
|
1905
|
-
*/
|
|
1906
|
-
// `PENDING_MESSAGE_INJECTED_TYPE` lives in `./ai-shared.ts` so the chat
|
|
1907
|
-
// React hooks (`@trigger.dev/sdk/chat/react`) can import it without
|
|
1908
|
-
// dragging `ai.ts` into the browser graph. Re-exported here so
|
|
1909
|
-
// `@trigger.dev/sdk/ai` consumers still see it.
|
|
1910
|
-
var ai_shared_js_1 = require("./ai-shared.js");
|
|
1911
|
-
Object.defineProperty(exports, "PENDING_MESSAGE_INJECTED_TYPE", { enumerable: true, get: function () { return ai_shared_js_1.PENDING_MESSAGE_INJECTED_TYPE; } });
|
|
1912
|
-
Object.defineProperty(exports, "upsertIncomingMessage", { enumerable: true, get: function () { return ai_shared_js_1.upsertIncomingMessage; } });
|
|
1913
|
-
const ai_shared_js_2 = require("./ai-shared.js");
|
|
1914
1904
|
/** @internal */
|
|
1915
1905
|
const chatPendingMessagesKey = locals_js_1.locals.create("chat.pendingMessages");
|
|
1916
1906
|
/** @internal */
|
|
@@ -1955,6 +1945,55 @@ function isStepBoundarySafe(step) {
|
|
|
1955
1945
|
.map((p) => p.toolCallId));
|
|
1956
1946
|
return ![...callIds].some((id) => !settledIds.has(id));
|
|
1957
1947
|
}
|
|
1948
|
+
/**
|
|
1949
|
+
* True when a model message is a `tool` message carrying a
|
|
1950
|
+
* `tool-approval-response` part — the trailing row a head-start handover
|
|
1951
|
+
* reshapes a pending first-turn tool call into. AI SDK's `collectToolApprovals`
|
|
1952
|
+
* only inspects the conversation's last message, so this row must survive to
|
|
1953
|
+
* `streamText` intact for the agent to execute the handed-over call.
|
|
1954
|
+
* @internal
|
|
1955
|
+
*/
|
|
1956
|
+
function hasToolApprovalResponse(message) {
|
|
1957
|
+
return (message?.role === "tool" &&
|
|
1958
|
+
Array.isArray(message.content) &&
|
|
1959
|
+
message.content.some((part) => part != null &&
|
|
1960
|
+
typeof part === "object" &&
|
|
1961
|
+
part.type === "tool-approval-response"));
|
|
1962
|
+
}
|
|
1963
|
+
/**
|
|
1964
|
+
* Keep a head-start handover's tool-approval tail intact across `prepareMessages`.
|
|
1965
|
+
*
|
|
1966
|
+
* The handover reshapes the warm step-1's pending tool call into AI SDK's
|
|
1967
|
+
* tool-approval round: a `tool-approval-request` on the assistant plus a
|
|
1968
|
+
* trailing `tool` message with `tool-approval-response { approved: true }`. The
|
|
1969
|
+
* agent's next `streamText` runs `collectToolApprovals`, which ONLY looks at the
|
|
1970
|
+
* last message — so that tool row must stay last and unmodified for the pending
|
|
1971
|
+
* call to execute. A user `prepareMessages` hook that rewrites or drops the last
|
|
1972
|
+
* message (e.g. rolling a provider cache breakpoint onto it) silently breaks the
|
|
1973
|
+
* resume: the agent sends a bare `tool_use` and the turn dies with
|
|
1974
|
+
* "tool_use ids were found without tool_result". If the hook's input ended with
|
|
1975
|
+
* that approval tail, re-assert the original tail as the last message.
|
|
1976
|
+
*
|
|
1977
|
+
* No-op for every normal turn — only fires when the input genuinely ended with a
|
|
1978
|
+
* pending tool-approval response (i.e. a head-start resume).
|
|
1979
|
+
* @internal
|
|
1980
|
+
*/
|
|
1981
|
+
function preserveToolApprovalTail(original, prepared) {
|
|
1982
|
+
const originalTail = original[original.length - 1];
|
|
1983
|
+
if (!hasToolApprovalResponse(originalTail))
|
|
1984
|
+
return prepared;
|
|
1985
|
+
// Hook left the exact tail object in place — nothing to do.
|
|
1986
|
+
if (prepared[prepared.length - 1] === originalTail)
|
|
1987
|
+
return prepared;
|
|
1988
|
+
// Otherwise drop only the trailing approval tail the hook produced (the
|
|
1989
|
+
// original moved, or a rewritten copy) and re-append the original so it is
|
|
1990
|
+
// last and intact. Older approval rounds deeper in history must survive.
|
|
1991
|
+
const withoutMovedOriginal = prepared.filter((m) => m !== originalTail);
|
|
1992
|
+
while (hasToolApprovalResponse(withoutMovedOriginal[withoutMovedOriginal.length - 1])) {
|
|
1993
|
+
withoutMovedOriginal.pop();
|
|
1994
|
+
}
|
|
1995
|
+
return [...withoutMovedOriginal, originalTail];
|
|
1996
|
+
}
|
|
1958
1997
|
/**
|
|
1959
1998
|
* Apply the prepareMessages hook if one is set in locals.
|
|
1960
1999
|
* @internal
|
|
@@ -1964,7 +2003,7 @@ async function applyPrepareMessages(messages, reason) {
|
|
|
1964
2003
|
if (!hook)
|
|
1965
2004
|
return messages;
|
|
1966
2005
|
const turnCtx = locals_js_1.locals.get(chatTurnContextKey);
|
|
1967
|
-
|
|
2006
|
+
const prepared = await tracer_js_1.tracer.startActiveSpan("prepareMessages()", async () => {
|
|
1968
2007
|
return hook({
|
|
1969
2008
|
messages,
|
|
1970
2009
|
reason,
|
|
@@ -1980,6 +2019,9 @@ async function applyPrepareMessages(messages, reason) {
|
|
|
1980
2019
|
"chat.prepareMessages.messageCount": messages.length,
|
|
1981
2020
|
},
|
|
1982
2021
|
});
|
|
2022
|
+
// A user hook must never be able to break the head-start handover resume by
|
|
2023
|
+
// disturbing the trailing tool-approval row (see preserveToolApprovalTail).
|
|
2024
|
+
return preserveToolApprovalTail(messages, prepared);
|
|
1983
2025
|
}
|
|
1984
2026
|
/**
|
|
1985
2027
|
* Resolve the `tools` option into a concrete `ToolSet` and cache it in locals so
|
|
@@ -2250,7 +2292,7 @@ async function drainSteeringQueue(config, messages, steps, queueOverride) {
|
|
|
2250
2292
|
.filter((p) => p.type === "text")
|
|
2251
2293
|
.map((p) => p.text)
|
|
2252
2294
|
.join("") || "");
|
|
2253
|
-
const
|
|
2295
|
+
const _previewText = messageTexts.length === 1 ? messageTexts[0].slice(0, 80) : `${queue.length} messages`;
|
|
2254
2296
|
return tracer_js_1.tracer.startActiveSpan("pending message injected", async () => {
|
|
2255
2297
|
// Transform the batch — default: concatenate all pre-converted model messages
|
|
2256
2298
|
const injected = config.prepare
|
|
@@ -2271,7 +2313,7 @@ async function drainSteeringQueue(config, messages, steps, queueOverride) {
|
|
|
2271
2313
|
collapsed: true,
|
|
2272
2314
|
execute: ({ write }) => {
|
|
2273
2315
|
write({
|
|
2274
|
-
type:
|
|
2316
|
+
type: ai_shared_js_1.PENDING_MESSAGE_INJECTED_TYPE,
|
|
2275
2317
|
id: (0, ai_runtime_js_1.generateId)(),
|
|
2276
2318
|
data: {
|
|
2277
2319
|
messageIds: uiMessages.map((m) => m.id),
|
|
@@ -2764,7 +2806,7 @@ function chatCustomAgent(options) {
|
|
|
2764
2806
|
// Register clientDataSchema so the CLI converts it to JSONSchema
|
|
2765
2807
|
// and stores it as payloadSchema — used by the Playground UI
|
|
2766
2808
|
if (clientDataSchema) {
|
|
2767
|
-
|
|
2809
|
+
v3_1.resourceCatalog.updateTaskMetadata(options.id, {
|
|
2768
2810
|
schema: clientDataSchema,
|
|
2769
2811
|
});
|
|
2770
2812
|
}
|
|
@@ -2928,7 +2970,9 @@ function chatAgent(options) {
|
|
|
2928
2970
|
const replayOutPhase = async () => {
|
|
2929
2971
|
const replayOutStart = Date.now();
|
|
2930
2972
|
try {
|
|
2931
|
-
const replayResult = await replaySessionOutTail(sessionIdForSnapshot, {
|
|
2973
|
+
const replayResult = await replaySessionOutTail(sessionIdForSnapshot, {
|
|
2974
|
+
lastEventId: bootSnapshot?.lastOutEventId,
|
|
2975
|
+
});
|
|
2932
2976
|
replayedSettled = replayResult.settled;
|
|
2933
2977
|
replayedPartial = replayResult.partial;
|
|
2934
2978
|
replayedPartialRaw = replayResult.partialRaw;
|
|
@@ -3025,9 +3069,7 @@ function chatAgent(options) {
|
|
|
3025
3069
|
// crashed / was canceled / requested upgrade
|
|
3026
3070
|
// - Snapshot exists at all (catches edge cases where the wire
|
|
3027
3071
|
// didn't set `continuation` but a snapshot indicates prior turns)
|
|
3028
|
-
const needsResumeCursor = ctx.attempt.number > 1 ||
|
|
3029
|
-
payload.continuation === true ||
|
|
3030
|
-
bootSnapshot !== undefined;
|
|
3072
|
+
const needsResumeCursor = ctx.attempt.number > 1 || payload.continuation === true || bootSnapshot !== undefined;
|
|
3031
3073
|
if (needsResumeCursor) {
|
|
3032
3074
|
try {
|
|
3033
3075
|
// Reuse the cursor the boot block already resolved (snapshot
|
|
@@ -3374,9 +3416,7 @@ function chatAgent(options) {
|
|
|
3374
3416
|
// Wait for the first real message — task-level idle settings win over
|
|
3375
3417
|
// `transport.preload(..., { idleTimeoutInSeconds })` / wire payload so
|
|
3376
3418
|
// `chat.agent({ idleTimeoutInSeconds, preloadIdleTimeoutInSeconds })` is authoritative.
|
|
3377
|
-
const effectivePreloadIdleTimeout = preloadIdleTimeoutInSeconds ??
|
|
3378
|
-
idleTimeoutInSeconds ??
|
|
3379
|
-
payload.idleTimeoutInSeconds;
|
|
3419
|
+
const effectivePreloadIdleTimeout = preloadIdleTimeoutInSeconds ?? idleTimeoutInSeconds ?? payload.idleTimeoutInSeconds;
|
|
3380
3420
|
const effectivePreloadTimeout = metadata_js_1.metadata.get(TURN_TIMEOUT_METADATA_KEY) ??
|
|
3381
3421
|
preloadTimeout ??
|
|
3382
3422
|
turnTimeout;
|
|
@@ -3621,7 +3661,9 @@ function chatAgent(options) {
|
|
|
3621
3661
|
if (lastUserMessage) {
|
|
3622
3662
|
turnAttributes["chat.user_message"] = lastUserMessage;
|
|
3623
3663
|
// Show a truncated preview of the user message as an accessory
|
|
3624
|
-
const preview = lastUserMessage.length > 80
|
|
3664
|
+
const preview = lastUserMessage.length > 80
|
|
3665
|
+
? lastUserMessage.slice(0, 80) + "..."
|
|
3666
|
+
: lastUserMessage;
|
|
3625
3667
|
Object.assign(turnAttributes, (0, v3_1.accessoryAttributes)({
|
|
3626
3668
|
items: [{ text: preview, variant: "normal" }],
|
|
3627
3669
|
style: "codepath",
|
|
@@ -3908,8 +3950,7 @@ function chatAgent(options) {
|
|
|
3908
3950
|
if (currentWirePayload.trigger === "submit-message" &&
|
|
3909
3951
|
cleanedUIMessages.length > 0) {
|
|
3910
3952
|
const lastUI = cleanedUIMessages[cleanedUIMessages.length - 1];
|
|
3911
|
-
const matchedExisting = lastUI.id !== undefined &&
|
|
3912
|
-
previouslyKnownMessageIds.has(lastUI.id);
|
|
3953
|
+
const matchedExisting = lastUI.id !== undefined && previouslyKnownMessageIds.has(lastUI.id);
|
|
3913
3954
|
if (!matchedExisting) {
|
|
3914
3955
|
turnNewUIMessages.push(lastUI);
|
|
3915
3956
|
const lastModel = (await toModelMessages([lastUI]))[0];
|
|
@@ -4244,7 +4285,8 @@ function chatAgent(options) {
|
|
|
4244
4285
|
// We call toUIMessageStream ourselves to attach onFinish for response capture.
|
|
4245
4286
|
// Pass originalMessages so the AI SDK reuses message IDs across turns
|
|
4246
4287
|
// (e.g. for tool approval continuations / HITL flows).
|
|
4247
|
-
if ((locals_js_1.locals.get(chatPipeCountKey) ?? 0) === 0 &&
|
|
4288
|
+
if ((locals_js_1.locals.get(chatPipeCountKey) ?? 0) === 0 &&
|
|
4289
|
+
isUIMessageStreamable(runResult)) {
|
|
4248
4290
|
onFinishAttached = true;
|
|
4249
4291
|
const resolvedOptions = resolveUIMessageStreamOptions();
|
|
4250
4292
|
// For action turns, don't pass originalMessages: the response
|
|
@@ -4257,9 +4299,7 @@ function chatAgent(options) {
|
|
|
4257
4299
|
// Pass originalMessages so the AI SDK reuses message IDs across
|
|
4258
4300
|
// turns (e.g. for tool approval continuations / HITL flows).
|
|
4259
4301
|
// Omit for action turns to force a fresh response ID.
|
|
4260
|
-
...(isActionTurn
|
|
4261
|
-
? {}
|
|
4262
|
-
: { originalMessages: accumulatedUIMessages }),
|
|
4302
|
+
...(isActionTurn ? {} : { originalMessages: accumulatedUIMessages }),
|
|
4263
4303
|
// Always provide generateMessageId so the start chunk carries a
|
|
4264
4304
|
// messageId. Without this, the frontend and backend generate IDs
|
|
4265
4305
|
// independently and they won't match for ID-based dedup.
|
|
@@ -4270,7 +4310,10 @@ function chatAgent(options) {
|
|
|
4270
4310
|
resolveOnFinish();
|
|
4271
4311
|
},
|
|
4272
4312
|
});
|
|
4273
|
-
await pipeChat(uiStream, {
|
|
4313
|
+
await pipeChat(uiStream, {
|
|
4314
|
+
signal: combinedSignal,
|
|
4315
|
+
spanName: "stream response",
|
|
4316
|
+
});
|
|
4274
4317
|
}
|
|
4275
4318
|
}
|
|
4276
4319
|
catch (error) {
|
|
@@ -4305,7 +4348,8 @@ function chatAgent(options) {
|
|
|
4305
4348
|
// never reports final usage), which would block the turn loop
|
|
4306
4349
|
// from ever firing onTurnComplete / writeTurnComplete.
|
|
4307
4350
|
let turnUsage;
|
|
4308
|
-
if (runResult != null &&
|
|
4351
|
+
if (runResult != null &&
|
|
4352
|
+
typeof runResult.totalUsage?.then === "function") {
|
|
4309
4353
|
try {
|
|
4310
4354
|
turnUsage = (await Promise.race([
|
|
4311
4355
|
runResult.totalUsage,
|
|
@@ -4391,7 +4435,10 @@ function chatAgent(options) {
|
|
|
4391
4435
|
// may produce a message with an empty ID since IDs are normally
|
|
4392
4436
|
// assigned by the frontend's useChat).
|
|
4393
4437
|
if (!capturedResponseMessage.id) {
|
|
4394
|
-
capturedResponseMessage = {
|
|
4438
|
+
capturedResponseMessage = {
|
|
4439
|
+
...capturedResponseMessage,
|
|
4440
|
+
id: (0, ai_runtime_js_1.generateId)(),
|
|
4441
|
+
};
|
|
4395
4442
|
}
|
|
4396
4443
|
// Append any non-transient data parts queued via chat.response or writer.write()
|
|
4397
4444
|
const queuedParts = locals_js_1.locals.get(chatResponsePartsKey);
|
|
@@ -4692,7 +4739,9 @@ function chatAgent(options) {
|
|
|
4692
4739
|
? { "gen_ai.usage.total_tokens": turnUsage.totalTokens }
|
|
4693
4740
|
: {}),
|
|
4694
4741
|
...(cumulativeUsage.totalTokens != null
|
|
4695
|
-
? {
|
|
4742
|
+
? {
|
|
4743
|
+
"gen_ai.usage.cumulative_total_tokens": cumulativeUsage.totalTokens,
|
|
4744
|
+
}
|
|
4696
4745
|
: {}),
|
|
4697
4746
|
},
|
|
4698
4747
|
});
|
|
@@ -4724,9 +4773,7 @@ function chatAgent(options) {
|
|
|
4724
4773
|
savedAt: Date.now(),
|
|
4725
4774
|
messages: accumulatedUIMessages,
|
|
4726
4775
|
lastOutEventId: turnCompleteResult?.lastEventId,
|
|
4727
|
-
lastInEventId: snapshotInCursor !== undefined
|
|
4728
|
-
? String(snapshotInCursor)
|
|
4729
|
-
: undefined,
|
|
4776
|
+
lastInEventId: snapshotInCursor !== undefined ? String(snapshotInCursor) : undefined,
|
|
4730
4777
|
});
|
|
4731
4778
|
}, {
|
|
4732
4779
|
attributes: {
|
|
@@ -4768,8 +4815,7 @@ function chatAgent(options) {
|
|
|
4768
4815
|
// chat.requestUpgrade() was called — exit the loop so the
|
|
4769
4816
|
// transport triggers a new run on the latest version.
|
|
4770
4817
|
// chat.endRun() — same exit, no upgrade semantics.
|
|
4771
|
-
if (locals_js_1.locals.get(chatUpgradeRequestedKey) ||
|
|
4772
|
-
locals_js_1.locals.get(chatEndRunRequestedKey)) {
|
|
4818
|
+
if (locals_js_1.locals.get(chatUpgradeRequestedKey) || locals_js_1.locals.get(chatEndRunRequestedKey)) {
|
|
4773
4819
|
return "exit";
|
|
4774
4820
|
}
|
|
4775
4821
|
// Wait for the next message — stay idle briefly, then suspend
|
|
@@ -4849,7 +4895,9 @@ function chatAgent(options) {
|
|
|
4849
4895
|
// Turn error handler: write an error chunk + turn-complete to the stream
|
|
4850
4896
|
// so the client sees the error, then wait for the next message instead
|
|
4851
4897
|
// of killing the entire run. This keeps the conversation alive.
|
|
4852
|
-
if (turnError instanceof Error &&
|
|
4898
|
+
if (turnError instanceof Error &&
|
|
4899
|
+
turnError.name === "AbortError" &&
|
|
4900
|
+
runSignal.aborted) {
|
|
4853
4901
|
// Full run cancellation — exit immediately
|
|
4854
4902
|
throw turnError;
|
|
4855
4903
|
}
|
|
@@ -4945,9 +4993,7 @@ function chatAgent(options) {
|
|
|
4945
4993
|
savedAt: Date.now(),
|
|
4946
4994
|
messages: erroredUIMessages,
|
|
4947
4995
|
lastOutEventId: errorTurnCompleteResult?.lastEventId,
|
|
4948
|
-
lastInEventId: errorSnapshotInCursor !== undefined
|
|
4949
|
-
? String(errorSnapshotInCursor)
|
|
4950
|
-
: undefined,
|
|
4996
|
+
lastInEventId: errorSnapshotInCursor !== undefined ? String(errorSnapshotInCursor) : undefined,
|
|
4951
4997
|
});
|
|
4952
4998
|
}
|
|
4953
4999
|
catch (error) {
|
|
@@ -4958,8 +5004,7 @@ function chatAgent(options) {
|
|
|
4958
5004
|
}
|
|
4959
5005
|
}
|
|
4960
5006
|
// chat.requestUpgrade() / chat.endRun() — exit after error turn too
|
|
4961
|
-
if (locals_js_1.locals.get(chatUpgradeRequestedKey) ||
|
|
4962
|
-
locals_js_1.locals.get(chatEndRunRequestedKey)) {
|
|
5007
|
+
if (locals_js_1.locals.get(chatUpgradeRequestedKey) || locals_js_1.locals.get(chatEndRunRequestedKey)) {
|
|
4963
5008
|
return;
|
|
4964
5009
|
}
|
|
4965
5010
|
// Drain remaining recovered turns before idling — a thrown
|
|
@@ -4992,12 +5037,12 @@ function chatAgent(options) {
|
|
|
4992
5037
|
// cleanup so a missing subscription doesn't throw.
|
|
4993
5038
|
stopSub?.off();
|
|
4994
5039
|
}
|
|
4995
|
-
}
|
|
5040
|
+
},
|
|
4996
5041
|
});
|
|
4997
5042
|
// Register clientDataSchema so the CLI converts it to JSONSchema
|
|
4998
5043
|
// and stores it as payloadSchema — used by the Playground UI
|
|
4999
5044
|
if (clientDataSchema) {
|
|
5000
|
-
|
|
5045
|
+
v3_1.resourceCatalog.updateTaskMetadata(options.id, {
|
|
5001
5046
|
schema: clientDataSchema,
|
|
5002
5047
|
});
|
|
5003
5048
|
}
|
|
@@ -5084,7 +5129,7 @@ function createChatBuilder(config) {
|
|
|
5084
5129
|
agent(options) {
|
|
5085
5130
|
const mergedUiStream = config.uiStreamOptions && options.uiMessageStreamOptions
|
|
5086
5131
|
? { ...config.uiStreamOptions, ...options.uiMessageStreamOptions }
|
|
5087
|
-
: options.uiMessageStreamOptions ?? config.uiStreamOptions;
|
|
5132
|
+
: (options.uiMessageStreamOptions ?? config.uiStreamOptions);
|
|
5088
5133
|
return chatAgent({
|
|
5089
5134
|
...options,
|
|
5090
5135
|
...(config.clientDataSchema ? { clientDataSchema: config.clientDataSchema } : {}),
|
|
@@ -5912,7 +5957,9 @@ function createChatSession(payload, options) {
|
|
|
5912
5957
|
if (turn === 0 && currentPayload.trigger === "handover-prepare") {
|
|
5913
5958
|
const signal = await waitForHandover({
|
|
5914
5959
|
payload: currentPayload,
|
|
5915
|
-
idleTimeoutInSeconds: sessionIdleTimeoutOpt ??
|
|
5960
|
+
idleTimeoutInSeconds: sessionIdleTimeoutOpt ??
|
|
5961
|
+
currentPayload.idleTimeoutInSeconds ??
|
|
5962
|
+
idleTimeoutInSeconds,
|
|
5916
5963
|
timeout,
|
|
5917
5964
|
});
|
|
5918
5965
|
if (!signal || signal.kind === "handover-skip" || runSignal.aborted) {
|
|
@@ -5931,7 +5978,8 @@ function createChatSession(payload, options) {
|
|
|
5931
5978
|
// arrive with the sticky boot-payload fields stripped, so running
|
|
5932
5979
|
// a turn immediately would invoke the model with no user input.
|
|
5933
5980
|
const isMessagelessContinuationBoot = currentPayload.continuation === true && !currentPayload.message;
|
|
5934
|
-
if (turn === 0 &&
|
|
5981
|
+
if (turn === 0 &&
|
|
5982
|
+
(currentPayload.trigger === "preload" || isMessagelessContinuationBoot)) {
|
|
5935
5983
|
const result = await messagesInput.waitWithIdleTimeout({
|
|
5936
5984
|
idleTimeoutInSeconds: sessionIdleTimeoutOpt ?? currentPayload.idleTimeoutInSeconds ?? 30,
|
|
5937
5985
|
timeout,
|
|
@@ -5955,8 +6003,7 @@ function createChatSession(payload, options) {
|
|
|
5955
6003
|
// Subsequent turns: wait for the next message
|
|
5956
6004
|
if (turn > 0) {
|
|
5957
6005
|
// chat.requestUpgrade() / chat.endRun() — exit before waiting
|
|
5958
|
-
if (locals_js_1.locals.get(chatUpgradeRequestedKey) ||
|
|
5959
|
-
locals_js_1.locals.get(chatEndRunRequestedKey)) {
|
|
6006
|
+
if (locals_js_1.locals.get(chatUpgradeRequestedKey) || locals_js_1.locals.get(chatEndRunRequestedKey)) {
|
|
5960
6007
|
stop.cleanup();
|
|
5961
6008
|
return { done: true, value: undefined };
|
|
5962
6009
|
}
|
|
@@ -6030,7 +6077,7 @@ function createChatSession(payload, options) {
|
|
|
6030
6077
|
const incomingForAccumulator = currentPayload.message
|
|
6031
6078
|
? [currentPayload.message]
|
|
6032
6079
|
: [];
|
|
6033
|
-
const
|
|
6080
|
+
const _messages = await accumulator.addIncoming(incomingForAccumulator, currentPayload.trigger, turn);
|
|
6034
6081
|
// Apply the head-start handover AFTER addIncoming — turn-0 addIncoming
|
|
6035
6082
|
// replaces accumulator state, which would wipe a pre-applied splice.
|
|
6036
6083
|
// Seed prior history first, then splice the warm step-1 partial.
|
|
@@ -6203,7 +6250,8 @@ function createChatSession(payload, options) {
|
|
|
6203
6250
|
},
|
|
6204
6251
|
];
|
|
6205
6252
|
if (sessionCompaction.compactUIMessages) {
|
|
6206
|
-
accumulator.uiMessages =
|
|
6253
|
+
accumulator.uiMessages =
|
|
6254
|
+
await sessionCompaction.compactUIMessages(compactEvent);
|
|
6207
6255
|
}
|
|
6208
6256
|
}
|
|
6209
6257
|
}
|
|
@@ -6215,7 +6263,10 @@ function createChatSession(payload, options) {
|
|
|
6215
6263
|
// Append any non-transient data parts queued via chat.response or writer.write()
|
|
6216
6264
|
const queuedParts = locals_js_1.locals.get(chatResponsePartsKey);
|
|
6217
6265
|
if (queuedParts && queuedParts.length > 0) {
|
|
6218
|
-
response = {
|
|
6266
|
+
response = {
|
|
6267
|
+
...response,
|
|
6268
|
+
parts: [...(response.parts ?? []), ...queuedParts],
|
|
6269
|
+
};
|
|
6219
6270
|
locals_js_1.locals.set(chatResponsePartsKey, []);
|
|
6220
6271
|
}
|
|
6221
6272
|
await accumulator.addResponse(response);
|
|
@@ -6484,6 +6535,12 @@ function createChatStartSessionAction(taskId, options) {
|
|
|
6484
6535
|
if (!params.chatId) {
|
|
6485
6536
|
throw new Error("chat.createStartSessionAction: params.chatId is required — used as the session externalId.");
|
|
6486
6537
|
}
|
|
6538
|
+
// Scope the action to `apiClient`'s env: re-enter without it so the body
|
|
6539
|
+
// runs once, under that config (read via apiClientManager.accessToken/.baseURL).
|
|
6540
|
+
if (options?.apiClient) {
|
|
6541
|
+
const { apiClient, ...rest } = options;
|
|
6542
|
+
return v3_1.apiClientManager.runWithConfig(apiClient, () => createChatStartSessionAction(taskId, rest)(params));
|
|
6543
|
+
}
|
|
6487
6544
|
// The first run boots before the user's first message lands on
|
|
6488
6545
|
// `.in/append`, so it sees an empty `messages` array and `trigger:
|
|
6489
6546
|
// "preload"`. This matches the pre-Sessions preload semantics:
|
|
@@ -6591,9 +6648,7 @@ function createChatStartSessionAction(taskId, options) {
|
|
|
6591
6648
|
}
|
|
6592
6649
|
function resolveChatStartBaseURL(endpoint, chatId, option) {
|
|
6593
6650
|
const fallback = v3_1.apiClientManager.baseURL ?? "https://api.trigger.dev";
|
|
6594
|
-
const raw = typeof option === "function"
|
|
6595
|
-
? option({ endpoint, chatId })
|
|
6596
|
-
: option ?? fallback;
|
|
6651
|
+
const raw = typeof option === "function" ? option({ endpoint, chatId }) : (option ?? fallback);
|
|
6597
6652
|
return raw.replace(/\/$/, "");
|
|
6598
6653
|
}
|
|
6599
6654
|
function overrideRequestHeaders(accessToken) {
|