@trigger.dev/sdk 4.5.0-rc.5 → 4.5.0-rc.7
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.d.ts +178 -5
- package/dist/commonjs/v3/ai.js +603 -119
- package/dist/commonjs/v3/ai.js.map +1 -1
- package/dist/commonjs/v3/chat-client.js +3 -0
- package/dist/commonjs/v3/chat-client.js.map +1 -1
- package/dist/commonjs/v3/chat-react.js +10 -7
- package/dist/commonjs/v3/chat-react.js.map +1 -1
- package/dist/commonjs/v3/chat-server.d.ts +8 -0
- package/dist/commonjs/v3/chat-server.js +32 -10
- package/dist/commonjs/v3/chat-server.js.map +1 -1
- package/dist/commonjs/v3/chat-server.test.js +51 -0
- package/dist/commonjs/v3/chat-server.test.js.map +1 -1
- package/dist/commonjs/v3/chat.js +34 -6
- package/dist/commonjs/v3/chat.js.map +1 -1
- package/dist/commonjs/v3/chat.test.js +53 -0
- package/dist/commonjs/v3/chat.test.js.map +1 -1
- package/dist/commonjs/v3/createStartSessionAction.test.js +30 -0
- package/dist/commonjs/v3/createStartSessionAction.test.js.map +1 -1
- package/dist/commonjs/v3/sessions.d.ts +11 -6
- package/dist/commonjs/v3/sessions.js +10 -5
- package/dist/commonjs/v3/sessions.js.map +1 -1
- package/dist/commonjs/v3/test/mock-chat-agent.d.ts +6 -0
- package/dist/commonjs/v3/test/mock-chat-agent.js +1 -0
- package/dist/commonjs/v3/test/mock-chat-agent.js.map +1 -1
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/v3/ai.d.ts +178 -5
- package/dist/esm/v3/ai.js +603 -120
- package/dist/esm/v3/ai.js.map +1 -1
- package/dist/esm/v3/chat-client.js +3 -0
- package/dist/esm/v3/chat-client.js.map +1 -1
- package/dist/esm/v3/chat-react.js +10 -7
- package/dist/esm/v3/chat-react.js.map +1 -1
- package/dist/esm/v3/chat-server.d.ts +8 -0
- package/dist/esm/v3/chat-server.js +32 -10
- package/dist/esm/v3/chat-server.js.map +1 -1
- package/dist/esm/v3/chat-server.test.js +51 -0
- package/dist/esm/v3/chat-server.test.js.map +1 -1
- package/dist/esm/v3/chat.js +34 -6
- package/dist/esm/v3/chat.js.map +1 -1
- package/dist/esm/v3/chat.test.js +53 -0
- package/dist/esm/v3/chat.test.js.map +1 -1
- package/dist/esm/v3/createStartSessionAction.test.js +30 -0
- package/dist/esm/v3/createStartSessionAction.test.js.map +1 -1
- package/dist/esm/v3/sessions.d.ts +11 -6
- package/dist/esm/v3/sessions.js +10 -5
- package/dist/esm/v3/sessions.js.map +1 -1
- package/dist/esm/v3/test/mock-chat-agent.d.ts +6 -0
- package/dist/esm/v3/test/mock-chat-agent.js +1 -0
- package/dist/esm/v3/test/mock-chat-agent.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/docs/ai/prompts.mdx +430 -0
- package/docs/ai-chat/actions.mdx +115 -0
- package/docs/ai-chat/anatomy.mdx +71 -0
- package/docs/ai-chat/backend.mdx +817 -0
- package/docs/ai-chat/background-injection.mdx +221 -0
- package/docs/ai-chat/changelog.mdx +850 -0
- package/docs/ai-chat/chat-local.mdx +174 -0
- package/docs/ai-chat/client-protocol.mdx +1081 -0
- package/docs/ai-chat/compaction.mdx +411 -0
- package/docs/ai-chat/custom-agents.mdx +364 -0
- package/docs/ai-chat/error-handling.mdx +415 -0
- package/docs/ai-chat/fast-starts.mdx +672 -0
- package/docs/ai-chat/frontend.mdx +580 -0
- package/docs/ai-chat/how-it-works.mdx +230 -0
- package/docs/ai-chat/lifecycle-hooks.mdx +530 -0
- package/docs/ai-chat/mcp.mdx +101 -0
- package/docs/ai-chat/overview.mdx +90 -0
- package/docs/ai-chat/patterns/branching-conversations.mdx +284 -0
- package/docs/ai-chat/patterns/code-sandbox.mdx +126 -0
- package/docs/ai-chat/patterns/database-persistence.mdx +414 -0
- package/docs/ai-chat/patterns/human-in-the-loop.mdx +275 -0
- package/docs/ai-chat/patterns/large-payloads.mdx +169 -0
- package/docs/ai-chat/patterns/oom-resilience.mdx +120 -0
- package/docs/ai-chat/patterns/persistence-and-replay.mdx +211 -0
- package/docs/ai-chat/patterns/recovery-boot.mdx +230 -0
- package/docs/ai-chat/patterns/skills.mdx +221 -0
- package/docs/ai-chat/patterns/sub-agents.mdx +383 -0
- package/docs/ai-chat/patterns/tool-result-auditing.mdx +148 -0
- package/docs/ai-chat/patterns/trusted-edge-signals.mdx +337 -0
- package/docs/ai-chat/patterns/version-upgrades.mdx +172 -0
- package/docs/ai-chat/pending-messages.mdx +343 -0
- package/docs/ai-chat/prompt-caching.mdx +206 -0
- package/docs/ai-chat/quick-start.mdx +161 -0
- package/docs/ai-chat/reference.mdx +909 -0
- package/docs/ai-chat/server-chat.mdx +263 -0
- package/docs/ai-chat/sessions.mdx +333 -0
- package/docs/ai-chat/testing.mdx +682 -0
- package/docs/ai-chat/tools.mdx +191 -0
- package/docs/ai-chat/types.mdx +242 -0
- package/docs/ai-chat/upgrade-guide.mdx +515 -0
- package/docs/apikeys.mdx +54 -0
- package/docs/building-with-ai.mdx +261 -0
- package/docs/bulk-actions.mdx +49 -0
- package/docs/changelog.mdx +6 -0
- package/docs/cli-deploy-commands.mdx +9 -0
- package/docs/cli-dev-commands.mdx +9 -0
- package/docs/cli-dev.mdx +8 -0
- package/docs/cli-init-commands.mdx +58 -0
- package/docs/cli-introduction.mdx +25 -0
- package/docs/cli-list-profiles-commands.mdx +42 -0
- package/docs/cli-login-commands.mdx +33 -0
- package/docs/cli-logout-commands.mdx +33 -0
- package/docs/cli-preview-archive.mdx +59 -0
- package/docs/cli-promote-commands.mdx +9 -0
- package/docs/cli-switch.mdx +43 -0
- package/docs/cli-update-commands.mdx +42 -0
- package/docs/cli-whoami-commands.mdx +33 -0
- package/docs/community.mdx +6 -0
- package/docs/config/config-file.mdx +602 -0
- package/docs/config/extensions/additionalFiles.mdx +38 -0
- package/docs/config/extensions/additionalPackages.mdx +40 -0
- package/docs/config/extensions/aptGet.mdx +34 -0
- package/docs/config/extensions/audioWaveform.mdx +20 -0
- package/docs/config/extensions/custom.mdx +380 -0
- package/docs/config/extensions/emitDecoratorMetadata.mdx +29 -0
- package/docs/config/extensions/esbuildPlugin.mdx +31 -0
- package/docs/config/extensions/ffmpeg.mdx +45 -0
- package/docs/config/extensions/lightpanda.mdx +56 -0
- package/docs/config/extensions/overview.mdx +67 -0
- package/docs/config/extensions/playwright.mdx +195 -0
- package/docs/config/extensions/prismaExtension.mdx +1014 -0
- package/docs/config/extensions/puppeteer.mdx +30 -0
- package/docs/config/extensions/pythonExtension.mdx +182 -0
- package/docs/config/extensions/syncEnvVars.mdx +291 -0
- package/docs/context.mdx +235 -0
- package/docs/database-connections.mdx +213 -0
- package/docs/deploy-environment-variables.mdx +435 -0
- package/docs/deployment/atomic-deployment.mdx +172 -0
- package/docs/deployment/overview.mdx +257 -0
- package/docs/deployment/preview-branches.mdx +224 -0
- package/docs/errors-retrying.mdx +379 -0
- package/docs/github-actions.mdx +222 -0
- package/docs/github-integration.mdx +136 -0
- package/docs/github-repo.mdx +8 -0
- package/docs/help-email.mdx +6 -0
- package/docs/help-slack.mdx +11 -0
- package/docs/hidden-tasks.mdx +56 -0
- package/docs/how-it-works.mdx +454 -0
- package/docs/how-to-reduce-your-spend.mdx +217 -0
- package/docs/idempotency.mdx +504 -0
- package/docs/introduction.mdx +223 -0
- package/docs/limits.mdx +241 -0
- package/docs/logging.mdx +195 -0
- package/docs/machines.mdx +952 -0
- package/docs/manual-setup.mdx +632 -0
- package/docs/mcp-agent-rules.mdx +41 -0
- package/docs/mcp-introduction.mdx +385 -0
- package/docs/mcp-tools.mdx +273 -0
- package/docs/migrating-from-v3.mdx +334 -0
- package/docs/observability/dashboards.mdx +102 -0
- package/docs/observability/query.mdx +585 -0
- package/docs/open-source-contributing.mdx +16 -0
- package/docs/open-source-self-hosting.mdx +541 -0
- package/docs/private-networking/aws-console-setup.mdx +304 -0
- package/docs/private-networking/overview.mdx +144 -0
- package/docs/private-networking/troubleshooting.mdx +78 -0
- package/docs/queue-concurrency.mdx +354 -0
- package/docs/quick-start.mdx +97 -0
- package/docs/realtime/auth.mdx +208 -0
- package/docs/realtime/backend/overview.mdx +45 -0
- package/docs/realtime/backend/streams.mdx +418 -0
- package/docs/realtime/backend/subscribe.mdx +225 -0
- package/docs/realtime/how-it-works.mdx +94 -0
- package/docs/realtime/overview.mdx +63 -0
- package/docs/realtime/react-hooks/overview.mdx +73 -0
- package/docs/realtime/react-hooks/streams.mdx +449 -0
- package/docs/realtime/react-hooks/subscribe.mdx +674 -0
- package/docs/realtime/react-hooks/swr.mdx +87 -0
- package/docs/realtime/react-hooks/triggering.mdx +194 -0
- package/docs/realtime/react-hooks/use-wait-token.mdx +34 -0
- package/docs/realtime/run-object.mdx +174 -0
- package/docs/replaying.mdx +72 -0
- package/docs/request-feature.mdx +6 -0
- package/docs/roadmap.mdx +6 -0
- package/docs/run-tests.mdx +20 -0
- package/docs/run-usage.mdx +113 -0
- package/docs/runs/heartbeats.mdx +38 -0
- package/docs/runs/max-duration.mdx +139 -0
- package/docs/runs/metadata.mdx +734 -0
- package/docs/runs/priority.mdx +31 -0
- package/docs/runs.mdx +396 -0
- package/docs/self-hosting/docker.mdx +458 -0
- package/docs/self-hosting/env/supervisor.mdx +74 -0
- package/docs/self-hosting/env/webapp.mdx +276 -0
- package/docs/self-hosting/kubernetes.mdx +601 -0
- package/docs/self-hosting/overview.mdx +108 -0
- package/docs/skills.mdx +85 -0
- package/docs/tags.mdx +120 -0
- package/docs/tasks/overview.mdx +697 -0
- package/docs/tasks/scheduled.mdx +382 -0
- package/docs/tasks/schemaTask.mdx +413 -0
- package/docs/tasks/streams.mdx +884 -0
- package/docs/triggering.mdx +1320 -0
- package/docs/troubleshooting-alerts.mdx +385 -0
- package/docs/troubleshooting-debugging-in-vscode.mdx +8 -0
- package/docs/troubleshooting-github-issues.mdx +6 -0
- package/docs/troubleshooting-uptime-status.mdx +6 -0
- package/docs/troubleshooting.mdx +398 -0
- package/docs/upgrading-packages.mdx +80 -0
- package/docs/vercel-integration.mdx +207 -0
- package/docs/versioning.mdx +56 -0
- package/docs/video-walkthrough.mdx +23 -0
- package/docs/wait-for-token.mdx +540 -0
- package/docs/wait-for.mdx +42 -0
- package/docs/wait-until.mdx +53 -0
- package/docs/wait.mdx +18 -0
- package/docs/writing-tasks-introduction.mdx +33 -0
- package/package.json +10 -6
- package/skills/trigger-authoring-chat-agent/SKILL.md +296 -0
- package/skills/trigger-authoring-tasks/SKILL.md +254 -0
- package/skills/trigger-chat-agent-advanced/SKILL.md +368 -0
- package/skills/trigger-cost-savings/SKILL.md +116 -0
- package/skills/trigger-realtime-and-frontend/SKILL.md +276 -0
package/dist/commonjs/v3/ai.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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, LanguageModelUsage, ModelMessage, Tool, ToolSet, UIMessage, UIMessageChunk, UIMessageStreamOptions } from "ai";
|
|
2
|
+
import type { FinishReason, LanguageModelUsage, ModelMessage, ProviderMetadata, Tool, ToolSet, UIMessage, UIMessageChunk, UIMessageStreamOptions } from "ai";
|
|
3
3
|
type ToolCallOptions = {
|
|
4
4
|
toolCallId: string;
|
|
5
5
|
messages?: ModelMessage[];
|
|
@@ -259,6 +259,57 @@ export type ChatTaskRunPayload<TClientData = unknown, TTools extends ToolSet = T
|
|
|
259
259
|
*/
|
|
260
260
|
tools: TTools;
|
|
261
261
|
};
|
|
262
|
+
/**
|
|
263
|
+
* Signal received by a `handover-prepare` agent run waiting on
|
|
264
|
+
* `session.in`. Either the customer's first-turn `streamText` finished
|
|
265
|
+
* with pending tool calls (`"handover"` — agent picks up from tool
|
|
266
|
+
* execution), or it finished pure-text (`"handover-skip"` — agent
|
|
267
|
+
* exits cleanly without making an LLM call).
|
|
268
|
+
*
|
|
269
|
+
* Returned by `chat.waitForHandover()` for custom-agent loops.
|
|
270
|
+
*/
|
|
271
|
+
export type HandoverSignal = {
|
|
272
|
+
kind: "handover";
|
|
273
|
+
partialAssistantMessage: ModelMessage[];
|
|
274
|
+
messageId?: string;
|
|
275
|
+
/**
|
|
276
|
+
* Whether the customer's step 1 is the final response. When
|
|
277
|
+
* true, the agent's turn loop runs hooks but skips the LLM
|
|
278
|
+
* call (the partial IS the response). When false, the agent
|
|
279
|
+
* runs `streamText` which executes pending tool-calls via the
|
|
280
|
+
* approval round and continues from step 2.
|
|
281
|
+
*/
|
|
282
|
+
isFinal: boolean;
|
|
283
|
+
} | {
|
|
284
|
+
kind: "handover-skip";
|
|
285
|
+
};
|
|
286
|
+
/**
|
|
287
|
+
* Wait for a `chat.headStart` handover signal inside a custom-agent loop or
|
|
288
|
+
* `chat.createSession`. Returns:
|
|
289
|
+
* - `null` — this run is not a `handover-prepare` boot, or the wait idled out /
|
|
290
|
+
* the warm handler crashed before signaling. Treat as "no handover".
|
|
291
|
+
* - `{ kind: "handover-skip" }` — the warm handler aborted; exit without a turn.
|
|
292
|
+
* - `{ kind: "handover", partialAssistantMessage, messageId?, isFinal }` — splice
|
|
293
|
+
* the partial (`chat.MessageAccumulator.applyHandover`) and, when `isFinal` is
|
|
294
|
+
* false, fall through to `streamText` to run the handed-over tool round.
|
|
295
|
+
*
|
|
296
|
+
* For the common case prefer `accumulator.consumeHandover()`, which also seeds
|
|
297
|
+
* `payload.headStartMessages` and applies the partial for you.
|
|
298
|
+
*
|
|
299
|
+
* Must be called at turn 0 before any `chat.messages.waitWithIdleTimeout` —
|
|
300
|
+
* that facade consumes and discards non-message chunks, which would swallow the
|
|
301
|
+
* handover signal.
|
|
302
|
+
*/
|
|
303
|
+
declare function waitForHandover(options: {
|
|
304
|
+
/** The run's wire payload (only `trigger` / `idleTimeoutInSeconds` are read). */
|
|
305
|
+
payload: {
|
|
306
|
+
trigger?: string;
|
|
307
|
+
idleTimeoutInSeconds?: number;
|
|
308
|
+
};
|
|
309
|
+
idleTimeoutInSeconds?: number;
|
|
310
|
+
timeout?: string;
|
|
311
|
+
spanName?: string;
|
|
312
|
+
}): Promise<HandoverSignal | null>;
|
|
262
313
|
/** Convenience re-export of the AI SDK's `LanguageModelUsage` type. */
|
|
263
314
|
export type ChatTurnUsage = LanguageModelUsage;
|
|
264
315
|
/**
|
|
@@ -718,11 +769,29 @@ export type ChatPromptValue = ResolvedPrompt | {
|
|
|
718
769
|
};
|
|
719
770
|
};
|
|
720
771
|
};
|
|
772
|
+
/**
|
|
773
|
+
* Options for `chat.prompt.set()`.
|
|
774
|
+
*/
|
|
775
|
+
export type SetChatPromptOptions = {
|
|
776
|
+
/**
|
|
777
|
+
* Provider options attached to the system prompt so a provider can cache it.
|
|
778
|
+
* The most common use is an Anthropic prompt-cache breakpoint on the (large,
|
|
779
|
+
* stable) system block — see the prompt-caching guide. Carried through to
|
|
780
|
+
* `chat.toStreamTextOptions()` automatically; a `systemProviderOptions` /
|
|
781
|
+
* `cacheControl` passed there overrides this.
|
|
782
|
+
*
|
|
783
|
+
* @example
|
|
784
|
+
* chat.prompt.set(SYSTEM_PROMPT, {
|
|
785
|
+
* providerOptions: { anthropic: { cacheControl: { type: "ephemeral" } } },
|
|
786
|
+
* });
|
|
787
|
+
*/
|
|
788
|
+
providerOptions?: ProviderMetadata;
|
|
789
|
+
};
|
|
721
790
|
/**
|
|
722
791
|
* Store a resolved prompt (or plain string) for the current run.
|
|
723
792
|
* Call from any hook (`onPreload`, `onChatStart`, `onTurnStart`) or `run()`.
|
|
724
793
|
*/
|
|
725
|
-
declare function setChatPrompt(resolved: ResolvedPrompt | string): void;
|
|
794
|
+
declare function setChatPrompt(resolved: ResolvedPrompt | string, options?: SetChatPromptOptions): void;
|
|
726
795
|
/**
|
|
727
796
|
* Read the stored prompt. Throws if `chat.prompt.set()` has not been called.
|
|
728
797
|
*/
|
|
@@ -770,6 +839,40 @@ export type ToStreamTextOptionsOptions = {
|
|
|
770
839
|
* your tools here.
|
|
771
840
|
*/
|
|
772
841
|
tools?: Record<string, Tool>;
|
|
842
|
+
/**
|
|
843
|
+
* Provider options attached to the system prompt so a provider can cache it.
|
|
844
|
+
* When set (or when {@link cacheControl} or `chat.prompt.set`'s
|
|
845
|
+
* `providerOptions` is set), `system` is returned as a structured
|
|
846
|
+
* `SystemModelMessage` carrying these options instead of a plain string —
|
|
847
|
+
* letting providers like Anthropic apply prompt caching to the (large,
|
|
848
|
+
* stable) system block, which is the single highest-value cache target.
|
|
849
|
+
*
|
|
850
|
+
* Overrides any `providerOptions` set on `chat.prompt.set()`.
|
|
851
|
+
*
|
|
852
|
+
* @example
|
|
853
|
+
* chat.toStreamTextOptions({
|
|
854
|
+
* systemProviderOptions: { anthropic: { cacheControl: { type: "ephemeral" } } },
|
|
855
|
+
* });
|
|
856
|
+
*/
|
|
857
|
+
systemProviderOptions?: ProviderMetadata;
|
|
858
|
+
/**
|
|
859
|
+
* Anthropic-only convenience for {@link systemProviderOptions}: caches the
|
|
860
|
+
* system prompt with the given cache breakpoint. Equivalent to
|
|
861
|
+
* `systemProviderOptions: { anthropic: { cacheControl } }`. For other
|
|
862
|
+
* providers (e.g. Amazon Bedrock's `cachePoint`), use `systemProviderOptions`.
|
|
863
|
+
*
|
|
864
|
+
* @example
|
|
865
|
+
* chat.toStreamTextOptions({ cacheControl: { type: "ephemeral" } });
|
|
866
|
+
*/
|
|
867
|
+
cacheControl?: SystemCacheControl;
|
|
868
|
+
};
|
|
869
|
+
/**
|
|
870
|
+
* Anthropic prompt-cache breakpoint shape (`providerOptions.anthropic.cacheControl`).
|
|
871
|
+
* `ttl` defaults to the 5-minute cache; `"1h"` selects the 1-hour cache.
|
|
872
|
+
*/
|
|
873
|
+
export type SystemCacheControl = {
|
|
874
|
+
type: "ephemeral";
|
|
875
|
+
ttl?: "5m" | "1h";
|
|
773
876
|
};
|
|
774
877
|
/**
|
|
775
878
|
* Returns an options object ready to spread into `streamText()`.
|
|
@@ -1263,6 +1366,13 @@ export type TurnCompleteEvent<TClientData = unknown, TUIM extends UIMessage = UI
|
|
|
1263
1366
|
* manual `pipeChat()` or an aborted stream).
|
|
1264
1367
|
*/
|
|
1265
1368
|
finishReason?: FinishReason;
|
|
1369
|
+
/**
|
|
1370
|
+
* Set when the turn failed (the `run()` body or a lifecycle hook threw).
|
|
1371
|
+
* On an errored turn `responseMessage` is undefined or partial and
|
|
1372
|
+
* `finishReason` is `"error"`. Use this to mark the turn failed in your
|
|
1373
|
+
* persistence. Undefined on a successful turn.
|
|
1374
|
+
*/
|
|
1375
|
+
error?: unknown;
|
|
1266
1376
|
};
|
|
1267
1377
|
/**
|
|
1268
1378
|
* Event passed to the `onBeforeTurnComplete` callback.
|
|
@@ -2373,6 +2483,7 @@ declare function chatWriteTurnComplete(options?: {
|
|
|
2373
2483
|
declare function pipeChatAndCapture(source: UIMessageStreamable, options?: {
|
|
2374
2484
|
signal?: AbortSignal;
|
|
2375
2485
|
spanName?: string;
|
|
2486
|
+
originalMessages?: UIMessage[];
|
|
2376
2487
|
}): Promise<UIMessage | undefined>;
|
|
2377
2488
|
/**
|
|
2378
2489
|
* Accumulates conversation messages across turns.
|
|
@@ -2416,6 +2527,42 @@ declare class ChatMessageAccumulator {
|
|
|
2416
2527
|
* Converts UIMessages to ModelMessages internally.
|
|
2417
2528
|
*/
|
|
2418
2529
|
setMessages(uiMessages: UIMessage[]): Promise<void>;
|
|
2530
|
+
/**
|
|
2531
|
+
* Splice a `chat.headStart` handover partial into the accumulator (the warm
|
|
2532
|
+
* step-1 response). Dedups by `messageId` so a seeded/hydrated history that
|
|
2533
|
+
* already carries the partial isn't doubled. Seed any prior history first
|
|
2534
|
+
* (e.g. `setMessages(payload.headStartMessages)`). Low-level — see
|
|
2535
|
+
* `consumeHandover` for the wait+seed+apply convenience.
|
|
2536
|
+
*/
|
|
2537
|
+
applyHandover(signal: {
|
|
2538
|
+
partialAssistantMessage: ModelMessage[];
|
|
2539
|
+
messageId?: string;
|
|
2540
|
+
}): void;
|
|
2541
|
+
/**
|
|
2542
|
+
* One-call `chat.headStart` handover for a custom-agent loop: waits for the
|
|
2543
|
+
* handover signal, seeds prior history from `payload.headStartMessages`,
|
|
2544
|
+
* applies the warm step-1 partial, and reports what to do next.
|
|
2545
|
+
*
|
|
2546
|
+
* Returns `{ isFinal, skipped }`:
|
|
2547
|
+
* - `skipped: true` — not a `handover-prepare` run, the wait idled out, or the
|
|
2548
|
+
* warm handler aborted. Exit the run without a turn.
|
|
2549
|
+
* - `isFinal: true` — step 1 IS the response (pure text). Write turn-complete
|
|
2550
|
+
* and continue; do not call `streamText`.
|
|
2551
|
+
* - `isFinal: false` — fall through to `streamText`, which runs the pending
|
|
2552
|
+
* tool round handed over from step 1.
|
|
2553
|
+
*/
|
|
2554
|
+
consumeHandover(options: {
|
|
2555
|
+
payload: {
|
|
2556
|
+
trigger?: string;
|
|
2557
|
+
idleTimeoutInSeconds?: number;
|
|
2558
|
+
headStartMessages?: UIMessage[];
|
|
2559
|
+
};
|
|
2560
|
+
idleTimeoutInSeconds?: number;
|
|
2561
|
+
timeout?: string;
|
|
2562
|
+
}): Promise<{
|
|
2563
|
+
isFinal: boolean;
|
|
2564
|
+
skipped: boolean;
|
|
2565
|
+
}>;
|
|
2419
2566
|
addResponse(response: UIMessage): Promise<void>;
|
|
2420
2567
|
/**
|
|
2421
2568
|
* Queue a message for injection via `prepareStep`. Call from a
|
|
@@ -2491,6 +2638,15 @@ export type ChatTurn = {
|
|
|
2491
2638
|
previousTurnUsage?: LanguageModelUsage;
|
|
2492
2639
|
/** Cumulative token usage across all completed turns so far. */
|
|
2493
2640
|
totalUsage: LanguageModelUsage;
|
|
2641
|
+
/**
|
|
2642
|
+
* Set on the first turn of a `chat.headStart` handover; `null` otherwise.
|
|
2643
|
+
* When `isFinal` is true the warm step-1 IS the response — call
|
|
2644
|
+
* `turn.complete()` with no argument (don't call `streamText`). When false,
|
|
2645
|
+
* call `streamText` as usual; it runs the handed-over tool round.
|
|
2646
|
+
*/
|
|
2647
|
+
handover: {
|
|
2648
|
+
isFinal: boolean;
|
|
2649
|
+
} | null;
|
|
2494
2650
|
/**
|
|
2495
2651
|
* Replace accumulated messages (for compaction). Takes UIMessages and
|
|
2496
2652
|
* converts to ModelMessages internally. After calling this, `turn.messages`
|
|
@@ -2500,8 +2656,11 @@ export type ChatTurn = {
|
|
|
2500
2656
|
/**
|
|
2501
2657
|
* Easy path: pipe stream, capture response, accumulate it,
|
|
2502
2658
|
* clean up aborted parts if stopped, and write turn-complete chunk.
|
|
2659
|
+
*
|
|
2660
|
+
* Call with no argument on a head-start final turn (`turn.handover?.isFinal`)
|
|
2661
|
+
* — the warm step-1 partial is already the response, so there's nothing to pipe.
|
|
2503
2662
|
*/
|
|
2504
|
-
complete(source
|
|
2663
|
+
complete(source?: UIMessageStreamable): Promise<UIMessage | undefined>;
|
|
2505
2664
|
/**
|
|
2506
2665
|
* Manual path: just write turn-complete chunk.
|
|
2507
2666
|
* Use when you've already piped and accumulated manually.
|
|
@@ -2531,14 +2690,18 @@ export type ChatTurn = {
|
|
|
2531
2690
|
* signaling, and idle/suspend between turns. You control: initialization,
|
|
2532
2691
|
* model/tool selection, persistence, and any custom per-turn logic.
|
|
2533
2692
|
*
|
|
2693
|
+
* Call from inside a `chat.customAgent()` run — the wrapper binds the
|
|
2694
|
+
* backing Session that the iterator's stop signal and message channels
|
|
2695
|
+
* resolve to. (A plain `task()` does not bind it, so `createSession`
|
|
2696
|
+
* would throw "session handle is not initialized".)
|
|
2697
|
+
*
|
|
2534
2698
|
* @example
|
|
2535
2699
|
* ```ts
|
|
2536
|
-
* import { task } from "@trigger.dev/sdk";
|
|
2537
2700
|
* import { chat, type ChatTaskWirePayload } from "@trigger.dev/sdk/ai";
|
|
2538
2701
|
* import { streamText } from "ai";
|
|
2539
2702
|
* import { openai } from "@ai-sdk/openai";
|
|
2540
2703
|
*
|
|
2541
|
-
* export const myChat =
|
|
2704
|
+
* export const myChat = chat.customAgent({
|
|
2542
2705
|
* id: "my-chat",
|
|
2543
2706
|
* run: async (payload: ChatTaskWirePayload, { signal }) => {
|
|
2544
2707
|
* const session = chat.createSession(payload, { signal });
|
|
@@ -2814,10 +2977,20 @@ export declare const chat: {
|
|
|
2814
2977
|
MessageAccumulator: typeof ChatMessageAccumulator;
|
|
2815
2978
|
/** Create a chat session (async iterator). See {@link createChatSession}. */
|
|
2816
2979
|
createSession: typeof createChatSession;
|
|
2980
|
+
/**
|
|
2981
|
+
* Wait for a `chat.headStart` handover signal inside a `chat.customAgent`
|
|
2982
|
+
* loop (turn 0). See {@link waitForHandover}. For most loops prefer the
|
|
2983
|
+
* `chat.MessageAccumulator.consumeHandover()` convenience, which also seeds
|
|
2984
|
+
* `payload.headStartMessages` and applies the partial.
|
|
2985
|
+
*/
|
|
2986
|
+
waitForHandover: typeof waitForHandover;
|
|
2817
2987
|
/**
|
|
2818
2988
|
* Store and retrieve a resolved prompt for the current run.
|
|
2819
2989
|
*
|
|
2820
2990
|
* - `chat.prompt.set(resolved)` — store a `ResolvedPrompt` or plain string
|
|
2991
|
+
* - `chat.prompt.set(resolved, { providerOptions })` — also attach provider
|
|
2992
|
+
* options to the system block so a provider can cache it (e.g. Anthropic
|
|
2993
|
+
* prompt caching). See the prompt-caching guide.
|
|
2821
2994
|
* - `chat.prompt()` — read the stored prompt (throws if not set)
|
|
2822
2995
|
*/
|
|
2823
2996
|
prompt: typeof getChatPrompt & {
|