@trigger.dev/sdk 4.4.5 → 4.5.0-rc.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/commonjs/v3/agentSkillsRuntime.d.ts +28 -0
- package/dist/commonjs/v3/agentSkillsRuntime.js +163 -0
- package/dist/commonjs/v3/agentSkillsRuntime.js.map +1 -0
- package/dist/commonjs/v3/ai-shared.d.ts +173 -0
- package/dist/commonjs/v3/ai-shared.js +25 -0
- package/dist/commonjs/v3/ai-shared.js.map +1 -0
- package/dist/commonjs/v3/ai.d.ts +2823 -5
- package/dist/commonjs/v3/ai.js +6197 -13
- package/dist/commonjs/v3/ai.js.map +1 -1
- package/dist/commonjs/v3/auth.d.ts +9 -0
- package/dist/commonjs/v3/auth.js.map +1 -1
- package/dist/commonjs/v3/chat-client.d.ts +301 -0
- package/dist/commonjs/v3/chat-client.js +624 -0
- package/dist/commonjs/v3/chat-client.js.map +1 -0
- package/dist/commonjs/v3/chat-react.d.ts +155 -0
- package/dist/commonjs/v3/chat-react.js +330 -0
- package/dist/commonjs/v3/chat-react.js.map +1 -0
- package/dist/commonjs/v3/chat-server.d.ts +206 -0
- package/dist/commonjs/v3/chat-server.js +737 -0
- package/dist/commonjs/v3/chat-server.js.map +1 -0
- package/dist/commonjs/v3/chat-server.test.d.ts +1 -0
- package/dist/commonjs/v3/chat-server.test.js +518 -0
- package/dist/commonjs/v3/chat-server.test.js.map +1 -0
- package/dist/commonjs/v3/chat-tab-coordinator.d.ts +65 -0
- package/dist/commonjs/v3/chat-tab-coordinator.js +235 -0
- package/dist/commonjs/v3/chat-tab-coordinator.js.map +1 -0
- package/dist/commonjs/v3/chat-tab-coordinator.test.d.ts +1 -0
- package/dist/commonjs/v3/chat-tab-coordinator.test.js +140 -0
- package/dist/commonjs/v3/chat-tab-coordinator.test.js.map +1 -0
- package/dist/commonjs/v3/chat.d.ts +437 -0
- package/dist/commonjs/v3/chat.js +968 -0
- package/dist/commonjs/v3/chat.js.map +1 -0
- package/dist/commonjs/v3/chat.test.d.ts +1 -0
- package/dist/commonjs/v3/chat.test.js +1180 -0
- package/dist/commonjs/v3/chat.test.js.map +1 -0
- package/dist/commonjs/v3/createStartSessionAction.test.d.ts +1 -0
- package/dist/commonjs/v3/createStartSessionAction.test.js +113 -0
- package/dist/commonjs/v3/createStartSessionAction.test.js.map +1 -0
- package/dist/commonjs/v3/deployments.d.ts +26 -0
- package/dist/commonjs/v3/deployments.js +37 -0
- package/dist/commonjs/v3/deployments.js.map +1 -0
- package/dist/commonjs/v3/index.d.ts +6 -3
- package/dist/commonjs/v3/index.js +7 -1
- package/dist/commonjs/v3/index.js.map +1 -1
- package/dist/commonjs/v3/runs.d.ts +22 -7
- package/dist/commonjs/v3/runs.js +1 -0
- package/dist/commonjs/v3/runs.js.map +1 -1
- package/dist/commonjs/v3/sessions.d.ts +228 -0
- package/dist/commonjs/v3/sessions.js +664 -0
- package/dist/commonjs/v3/sessions.js.map +1 -0
- package/dist/commonjs/v3/sessions.test.d.ts +1 -0
- package/dist/commonjs/v3/sessions.test.js +154 -0
- package/dist/commonjs/v3/sessions.test.js.map +1 -0
- package/dist/commonjs/v3/shared.d.ts +24 -2
- package/dist/commonjs/v3/shared.js +189 -1
- package/dist/commonjs/v3/shared.js.map +1 -1
- package/dist/commonjs/v3/skill.d.ts +99 -0
- package/dist/commonjs/v3/skill.js +155 -0
- package/dist/commonjs/v3/skill.js.map +1 -0
- package/dist/commonjs/v3/skills.d.ts +2 -0
- package/dist/commonjs/v3/skills.js +6 -0
- package/dist/commonjs/v3/skills.js.map +1 -0
- package/dist/commonjs/v3/streams.js +127 -19
- package/dist/commonjs/v3/streams.js.map +1 -1
- package/dist/commonjs/v3/tasks.d.ts +2 -1
- package/dist/commonjs/v3/tasks.js +1 -0
- package/dist/commonjs/v3/tasks.js.map +1 -1
- package/dist/commonjs/v3/test/index.d.ts +3 -0
- package/dist/commonjs/v3/test/index.js +18 -0
- package/dist/commonjs/v3/test/index.js.map +1 -0
- package/dist/commonjs/v3/test/mock-chat-agent.d.ts +259 -0
- package/dist/commonjs/v3/test/mock-chat-agent.js +468 -0
- package/dist/commonjs/v3/test/mock-chat-agent.js.map +1 -0
- package/dist/commonjs/v3/test/setup-catalog.d.ts +1 -0
- package/dist/commonjs/v3/test/setup-catalog.js +18 -0
- package/dist/commonjs/v3/test/setup-catalog.js.map +1 -0
- package/dist/commonjs/v3/test/test-session-handle.d.ts +53 -0
- package/dist/commonjs/v3/test/test-session-handle.js +256 -0
- package/dist/commonjs/v3/test/test-session-handle.js.map +1 -0
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/v3/agentSkillsRuntime.d.ts +28 -0
- package/dist/esm/v3/agentSkillsRuntime.js +136 -0
- package/dist/esm/v3/agentSkillsRuntime.js.map +1 -0
- package/dist/esm/v3/ai-shared.d.ts +173 -0
- package/dist/esm/v3/ai-shared.js +22 -0
- package/dist/esm/v3/ai-shared.js.map +1 -0
- package/dist/esm/v3/ai.d.ts +2823 -5
- package/dist/esm/v3/ai.js +6187 -14
- package/dist/esm/v3/ai.js.map +1 -1
- package/dist/esm/v3/auth.d.ts +9 -0
- package/dist/esm/v3/auth.js.map +1 -1
- package/dist/esm/v3/chat-client.d.ts +301 -0
- package/dist/esm/v3/chat-client.js +619 -0
- package/dist/esm/v3/chat-client.js.map +1 -0
- package/dist/esm/v3/chat-react.d.ts +155 -0
- package/dist/esm/v3/chat-react.js +325 -0
- package/dist/esm/v3/chat-react.js.map +1 -0
- package/dist/esm/v3/chat-server.d.ts +206 -0
- package/dist/esm/v3/chat-server.js +734 -0
- package/dist/esm/v3/chat-server.js.map +1 -0
- package/dist/esm/v3/chat-server.test.d.ts +1 -0
- package/dist/esm/v3/chat-server.test.js +516 -0
- package/dist/esm/v3/chat-server.test.js.map +1 -0
- package/dist/esm/v3/chat-tab-coordinator.d.ts +65 -0
- package/dist/esm/v3/chat-tab-coordinator.js +231 -0
- package/dist/esm/v3/chat-tab-coordinator.js.map +1 -0
- package/dist/esm/v3/chat-tab-coordinator.test.d.ts +1 -0
- package/dist/esm/v3/chat-tab-coordinator.test.js +138 -0
- package/dist/esm/v3/chat-tab-coordinator.test.js.map +1 -0
- package/dist/esm/v3/chat.d.ts +437 -0
- package/dist/esm/v3/chat.js +961 -0
- package/dist/esm/v3/chat.js.map +1 -0
- package/dist/esm/v3/chat.test.d.ts +1 -0
- package/dist/esm/v3/chat.test.js +1178 -0
- package/dist/esm/v3/chat.test.js.map +1 -0
- package/dist/esm/v3/createStartSessionAction.test.d.ts +1 -0
- package/dist/esm/v3/createStartSessionAction.test.js +111 -0
- package/dist/esm/v3/createStartSessionAction.test.js.map +1 -0
- package/dist/esm/v3/deployments.d.ts +26 -0
- package/dist/esm/v3/deployments.js +34 -0
- package/dist/esm/v3/deployments.js.map +1 -0
- package/dist/esm/v3/index.d.ts +6 -3
- package/dist/esm/v3/index.js +4 -1
- package/dist/esm/v3/index.js.map +1 -1
- package/dist/esm/v3/runs.d.ts +15 -0
- package/dist/esm/v3/runs.js +1 -0
- package/dist/esm/v3/runs.js.map +1 -1
- package/dist/esm/v3/sessions.d.ts +228 -0
- package/dist/esm/v3/sessions.js +656 -0
- package/dist/esm/v3/sessions.js.map +1 -0
- package/dist/esm/v3/sessions.test.d.ts +1 -0
- package/dist/esm/v3/sessions.test.js +152 -0
- package/dist/esm/v3/sessions.test.js.map +1 -0
- package/dist/esm/v3/shared.d.ts +24 -2
- package/dist/esm/v3/shared.js +188 -1
- package/dist/esm/v3/shared.js.map +1 -1
- package/dist/esm/v3/skill.d.ts +99 -0
- package/dist/esm/v3/skill.js +128 -0
- package/dist/esm/v3/skill.js.map +1 -0
- package/dist/esm/v3/skills.d.ts +2 -0
- package/dist/esm/v3/skills.js +2 -0
- package/dist/esm/v3/skills.js.map +1 -0
- package/dist/esm/v3/streams.js +127 -20
- package/dist/esm/v3/streams.js.map +1 -1
- package/dist/esm/v3/tasks.d.ts +2 -1
- package/dist/esm/v3/tasks.js +2 -1
- package/dist/esm/v3/tasks.js.map +1 -1
- package/dist/esm/v3/test/index.d.ts +3 -0
- package/dist/esm/v3/test/index.js +13 -0
- package/dist/esm/v3/test/index.js.map +1 -0
- package/dist/esm/v3/test/mock-chat-agent.d.ts +259 -0
- package/dist/esm/v3/test/mock-chat-agent.js +465 -0
- package/dist/esm/v3/test/mock-chat-agent.js.map +1 -0
- package/dist/esm/v3/test/setup-catalog.d.ts +1 -0
- package/dist/esm/v3/test/setup-catalog.js +16 -0
- package/dist/esm/v3/test/setup-catalog.js.map +1 -0
- package/dist/esm/v3/test/test-session-handle.d.ts +53 -0
- package/dist/esm/v3/test/test-session-handle.js +251 -0
- package/dist/esm/v3/test/test-session-handle.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/package.json +87 -6
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-side helpers for the `chat.agent` head-start flow — a
|
|
3
|
+
* customer's warm process (Next.js route handler, Express, etc.)
|
|
4
|
+
* gets the conversation moving while the heavy chat.agent run boots
|
|
5
|
+
* in parallel. Mid-turn, ownership of the durable stream hands over
|
|
6
|
+
* to the agent.
|
|
7
|
+
*
|
|
8
|
+
* The `chat.headStart({ agentId, run })` entry point returns a
|
|
9
|
+
* Next.js-style POST handler. Inside the customer's `run` callback
|
|
10
|
+
* they call `streamText` themselves, spreading
|
|
11
|
+
* `chat.toStreamTextOptions({ tools })` to inherit handover wiring.
|
|
12
|
+
* The handler runs `streamText` step 1 in the customer's process
|
|
13
|
+
* while the chat.agent run boots in parallel; on `tool-calls` the
|
|
14
|
+
* agent run picks up tool execution and continues, on pure-text the
|
|
15
|
+
* agent run exits clean without an LLM call.
|
|
16
|
+
*
|
|
17
|
+
* Two-layer naming: customer-facing surface is "head start"
|
|
18
|
+
* (describes the *benefit* — fast first-turn TTFC). The internal
|
|
19
|
+
* protocol still uses "handover" (describes the *mechanism* — the
|
|
20
|
+
* conversation hands off mid-turn from the warm process to the
|
|
21
|
+
* agent). Customers see `chat.headStart`, `HeadStartSession`, etc.
|
|
22
|
+
* The wire format and run-loop locals stay on `handover` /
|
|
23
|
+
* `handover-prepare` / `handover-skip`.
|
|
24
|
+
*
|
|
25
|
+
* Cooperative ordering only — handler stops writing to `session.out`
|
|
26
|
+
* before sending the `handover` chunk on `session.in`. No S2 fencing.
|
|
27
|
+
*
|
|
28
|
+
* ⚠️ HARD CONSTRAINT — bundle isolation
|
|
29
|
+
*
|
|
30
|
+
* This module is the customer-facing boundary for the route handler.
|
|
31
|
+
* The whole TTFC win comes from the customer's process being
|
|
32
|
+
* lightweight while the heavy agent run boots in parallel. **The
|
|
33
|
+
* route-handler bundle must not include heavy tool execute deps**:
|
|
34
|
+
* E2B, puppeteer/playwright, native bindings, the trigger SDK
|
|
35
|
+
* runtime, turndown, image processing libs, anything that pulls
|
|
36
|
+
* weight or pulls `node:` builtins.
|
|
37
|
+
*
|
|
38
|
+
* "Schema-only" tools must live in a module that imports only `ai`
|
|
39
|
+
* (for `tool()`) and `zod`. The agent task module imports those
|
|
40
|
+
* schemas and adds execute fns elsewhere — that's where the heavy
|
|
41
|
+
* deps live, and it's never reached by the route handler bundle.
|
|
42
|
+
*
|
|
43
|
+
* Runtime "strip executes" helpers (anything that takes a tool
|
|
44
|
+
* catalog with executes and removes them) DO NOT solve this. The
|
|
45
|
+
* import chain is resolved at bundle/build time, so importing the
|
|
46
|
+
* full catalog drags every dep in regardless of what the SDK does
|
|
47
|
+
* with the value at runtime.
|
|
48
|
+
*
|
|
49
|
+
* IMPORTANT (internal): this module must NOT import from `./ai.ts`.
|
|
50
|
+
* `ai.ts` statically imports `agentSkillsRuntime` (which uses `node:`
|
|
51
|
+
* builtins unfit for some serverless runtimes) and the heavy task
|
|
52
|
+
* runtime. Allowed imports: `./ai-shared.js`, `./chat-client.js`,
|
|
53
|
+
* `@trigger.dev/core/v3` (api client), `ai` (types + lightweight
|
|
54
|
+
* helpers like `stepCountIs` / `convertToModelMessages`).
|
|
55
|
+
*/
|
|
56
|
+
import { type ModelMessage, type StreamTextResult, type Tool, type UIMessage, type UIMessageChunk } from "ai";
|
|
57
|
+
export type HeadStartRunArgs<TTools extends Record<string, Tool>> = {
|
|
58
|
+
/** User messages parsed from the incoming request. */
|
|
59
|
+
messages: UIMessage[];
|
|
60
|
+
/** Aborts when the request closes or the SDK times out the handover. */
|
|
61
|
+
signal: AbortSignal;
|
|
62
|
+
/** Helper exposing `toStreamTextOptions(...)` and a session escape hatch. */
|
|
63
|
+
chat: HeadStartChatHelper<TTools>;
|
|
64
|
+
};
|
|
65
|
+
export type HeadStartChatHelper<TTools extends Record<string, Tool>> = {
|
|
66
|
+
/**
|
|
67
|
+
* Spread into the customer's `streamText` call to inherit handover
|
|
68
|
+
* wiring. Returns options for:
|
|
69
|
+
*
|
|
70
|
+
* - `messages` — converted from the wire payload's UIMessages
|
|
71
|
+
* - `tools` — the customer's tool set (typically schema-only — see
|
|
72
|
+
* the bundle-isolation note in this module's header)
|
|
73
|
+
* - `abortSignal` — combined request-lifecycle + idle timeout
|
|
74
|
+
* - `stopWhen` — `stepCountIs(1)`. Step 1 only. The agent run picks
|
|
75
|
+
* up tool execution and step 2+ after the handover signal.
|
|
76
|
+
*
|
|
77
|
+
* Customer adds `model`, `system`, `providerOptions`, etc. on top.
|
|
78
|
+
* The customer keeps full control of the `streamText` call shape;
|
|
79
|
+
* this helper just hands back the options the SDK needs to own.
|
|
80
|
+
*
|
|
81
|
+
* The customer COULD override any of these by re-setting them after
|
|
82
|
+
* the spread, but doing so for `stopWhen` / `messages` /
|
|
83
|
+
* `abortSignal` will break the handover protocol. The intent is
|
|
84
|
+
* that customers spread first, then add only their own keys.
|
|
85
|
+
*/
|
|
86
|
+
toStreamTextOptions<TOpts extends Record<string, unknown> = Record<string, unknown>>(opts?: {
|
|
87
|
+
tools?: TTools;
|
|
88
|
+
}): TOpts;
|
|
89
|
+
/** Lower-level escape hatch with manual `out` / `in` / dispatch primitives. */
|
|
90
|
+
session: HeadStartSession;
|
|
91
|
+
};
|
|
92
|
+
export type HeadStartSession = {
|
|
93
|
+
readonly chatId: string;
|
|
94
|
+
/**
|
|
95
|
+
* Tees a UIMessage stream into `session.out` for durability/resume,
|
|
96
|
+
* fire-and-forget. Returns a passthrough that the caller can use as
|
|
97
|
+
* the HTTP response body.
|
|
98
|
+
*/
|
|
99
|
+
tee(stream: ReadableStream<UIMessageChunk>): ReadableStream<UIMessageChunk>;
|
|
100
|
+
/**
|
|
101
|
+
* Awaits `result.finishReason` and dispatches `handover` (with the
|
|
102
|
+
* partial assistant ModelMessages) or `handover-skip`.
|
|
103
|
+
*/
|
|
104
|
+
handoverWhenDone(result: StreamTextResult<any, any>): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Sugar over `tee` + `handoverWhenDone` + standard SSE response.
|
|
107
|
+
* Returns a `Response` with `Content-Type: text/event-stream` whose
|
|
108
|
+
* body is the teed stream.
|
|
109
|
+
*/
|
|
110
|
+
handoverResponse(result: StreamTextResult<any, any>): Response;
|
|
111
|
+
/**
|
|
112
|
+
* Manually dispatch the `handover` signal on `session.in`.
|
|
113
|
+
*
|
|
114
|
+
* - `isFinal: true` — the partial assistant message IS the response.
|
|
115
|
+
* The agent runs `onChatStart` / `onTurnStart` / `onTurnComplete`
|
|
116
|
+
* against it but skips the LLM call. Use for pure-text replies.
|
|
117
|
+
* - `isFinal: false` — the partial assistant message ends with
|
|
118
|
+
* pending tool calls. The agent executes them and then runs a
|
|
119
|
+
* step-2 LLM call to produce the final response.
|
|
120
|
+
*
|
|
121
|
+
* `messageId` lets the caller carry a stable assistant message id
|
|
122
|
+
* across the handover boundary so the browser merges step 1 and
|
|
123
|
+
* step 2 into the same `UIMessage`.
|
|
124
|
+
*/
|
|
125
|
+
handover(args: {
|
|
126
|
+
partialAssistantMessage: ModelMessage[];
|
|
127
|
+
isFinal: boolean;
|
|
128
|
+
messageId?: string;
|
|
129
|
+
}): Promise<void>;
|
|
130
|
+
/** Manually dispatch the `handover-skip` signal on `session.in`. */
|
|
131
|
+
handoverSkip(): Promise<void>;
|
|
132
|
+
};
|
|
133
|
+
export type HeadStartHandlerOptions<TTools extends Record<string, Tool>> = {
|
|
134
|
+
/** The `chat.agent({ id })` of the agent we're handing off to. */
|
|
135
|
+
agentId: string;
|
|
136
|
+
/**
|
|
137
|
+
* Customer's first-turn implementation. Receives `messages`,
|
|
138
|
+
* `signal`, and a `chat` helper. Should call `streamText` with
|
|
139
|
+
* `...chat.toStreamTextOptions({ tools })` and return the
|
|
140
|
+
* `StreamTextResult`.
|
|
141
|
+
*/
|
|
142
|
+
run: (args: HeadStartRunArgs<TTools>) => Promise<StreamTextResult<any, any>>;
|
|
143
|
+
/**
|
|
144
|
+
* Seconds the agent run waits for the handover signal before
|
|
145
|
+
* exiting. Defaults to 60.
|
|
146
|
+
*/
|
|
147
|
+
idleTimeoutInSeconds?: number;
|
|
148
|
+
};
|
|
149
|
+
export declare const chat: {
|
|
150
|
+
/**
|
|
151
|
+
* Returns a Next.js-style POST handler for the chat.agent
|
|
152
|
+
* head-start flow. Customer mounts it as
|
|
153
|
+
* `export const { POST } = chat.headStart({...})` (or
|
|
154
|
+
* `export const POST = chat.headStart({...})`).
|
|
155
|
+
*
|
|
156
|
+
* Pair with the browser transport's `headStart: "/api/chat"`
|
|
157
|
+
* option so the first message of a brand-new chat lands here
|
|
158
|
+
* before the agent run boots.
|
|
159
|
+
*/
|
|
160
|
+
headStart<TTools extends Record<string, Tool>>(opts: HeadStartHandlerOptions<TTools>): (req: Request) => Promise<Response>;
|
|
161
|
+
/**
|
|
162
|
+
* Lower-level primitive for power users who want to call
|
|
163
|
+
* `streamText` themselves outside the `run` callback shape — custom
|
|
164
|
+
* transforms, non-AI-SDK code paths, or manual control over the
|
|
165
|
+
* response. Same wiring `chat.headStart` builds on internally.
|
|
166
|
+
*/
|
|
167
|
+
openSession(opts: {
|
|
168
|
+
req: Request;
|
|
169
|
+
agentId: string;
|
|
170
|
+
idleTimeoutInSeconds?: number;
|
|
171
|
+
}): Promise<HeadStartSession>;
|
|
172
|
+
/**
|
|
173
|
+
* Wrap a Web Fetch handler — `(req: Request) => Promise<Response>` —
|
|
174
|
+
* as a Node `http` listener — `(req: IncomingMessage, res: ServerResponse) => Promise<void>`.
|
|
175
|
+
*
|
|
176
|
+
* Use this to mount `chat.headStart` (or any other Web Fetch
|
|
177
|
+
* handler) inside Node-only frameworks like Express, Fastify, Koa,
|
|
178
|
+
* or raw `node:http`. Web-native frameworks (Next.js App Router,
|
|
179
|
+
* Hono, SvelteKit, Remix, Workers, Bun, Deno, etc.) don't need
|
|
180
|
+
* this — they pass `Request` objects directly.
|
|
181
|
+
*
|
|
182
|
+
* Streams the response body chunk-by-chunk to the Node response,
|
|
183
|
+
* so the `chat.headStart` SSE chunks reach the browser as they
|
|
184
|
+
* arrive (no buffering). Aborts the underlying handler if the
|
|
185
|
+
* client closes the connection.
|
|
186
|
+
*
|
|
187
|
+
* Type-only import of `node:http` types — no runtime dep on `node:http`,
|
|
188
|
+
* so this stays safe to bundle into edge / Workers builds (the
|
|
189
|
+
* function just won't be called there).
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```ts
|
|
193
|
+
* import express from "express";
|
|
194
|
+
* import { chat } from "@trigger.dev/sdk/chat-server";
|
|
195
|
+
*
|
|
196
|
+
* const handler = chat.headStart({
|
|
197
|
+
* agentId: "my-chat",
|
|
198
|
+
* run: async ({ chat: helper }) => streamText({ ... }),
|
|
199
|
+
* });
|
|
200
|
+
*
|
|
201
|
+
* const app = express();
|
|
202
|
+
* app.post("/api/chat", chat.toNodeListener(handler));
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
toNodeListener: typeof toNodeListener;
|
|
206
|
+
};
|