Skip to content

Commit ee474b5

Browse files
authored
Merge branch 'main' into mollifier-phase-2
2 parents 50868ff + 5788573 commit ee474b5

46 files changed

Lines changed: 496 additions & 153 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/ai-prompts.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
"@trigger.dev/sdk": minor
3+
---
4+
5+
**AI Prompts** — define prompt templates as code alongside your tasks, version them on deploy, and override the text or model from the dashboard without redeploying. Prompts integrate with the Vercel AI SDK via `toAISDKTelemetry()` (links every generation span back to the prompt) and with `chat.agent` via `chat.prompt.set()` + `chat.toStreamTextOptions()`.
6+
7+
```ts
8+
import { prompts } from "@trigger.dev/sdk";
9+
import { generateText } from "ai";
10+
import { openai } from "@ai-sdk/openai";
11+
import { z } from "zod";
12+
13+
export const supportPrompt = prompts.define({
14+
id: "customer-support",
15+
model: "gpt-4o",
16+
config: { temperature: 0.7 },
17+
variables: z.object({
18+
customerName: z.string(),
19+
plan: z.string(),
20+
issue: z.string(),
21+
}),
22+
content: `You are a support agent for Acme.
23+
24+
Customer: {{customerName}} ({{plan}} plan)
25+
Issue: {{issue}}`,
26+
});
27+
28+
const resolved = await supportPrompt.resolve({
29+
customerName: "Alice",
30+
plan: "Pro",
31+
issue: "Can't access billing",
32+
});
33+
34+
const result = await generateText({
35+
model: openai(resolved.model ?? "gpt-4o"),
36+
system: resolved.text,
37+
prompt: "Can't access billing",
38+
...resolved.toAISDKTelemetry(),
39+
});
40+
```
41+
42+
**What you get:**
43+
44+
- **Code-defined, deploy-versioned templates** — define with `prompts.define({ id, model, config, variables, content })`. Every deploy creates a new version visible in the dashboard. Mustache-style placeholders (`{{var}}`, `{{#cond}}...{{/cond}}`) with Zod / ArkType / Valibot-typed variables.
45+
- **Dashboard overrides** — change a prompt's text or model from the dashboard without redeploying. Overrides take priority over the deployed "current" version and are environment-scoped (dev / staging / production independent).
46+
- **Resolve API**`prompt.resolve(vars, { version?, label? })` returns the compiled `text`, resolved `model`, `version`, and labels. Standalone `prompts.resolve<typeof handle>(slug, vars)` for cross-file resolution with full type inference on slug and variable shape.
47+
- **AI SDK integration** — spread `resolved.toAISDKTelemetry({ ...extra })` into any `generateText` / `streamText` call and every generation span links to the prompt in the dashboard alongside its input variables, model, tokens, and cost.
48+
- **`chat.agent` integration**`chat.prompt.set(resolved)` stores the resolved prompt run-scoped; `chat.toStreamTextOptions({ registry })` pulls `system`, `model` (resolved via the AI SDK provider registry), `temperature` / `maxTokens` / etc., and telemetry into a single spread for `streamText`.
49+
- **Management SDK**`prompts.list()`, `prompts.versions(slug)`, `prompts.promote(slug, version)`, `prompts.createOverride(slug, body)`, `prompts.updateOverride(slug, body)`, `prompts.removeOverride(slug)`, `prompts.reactivateOverride(slug, version)`.
50+
- **Dashboard** — prompts list with per-prompt usage sparklines; per-prompt detail with Template / Details / Versions / Generations / Metrics tabs. AI generation spans get a custom inspector showing the linked prompt's metadata, input variables, and template content alongside model, tokens, cost, and the message thread.
51+
52+
See [/docs/ai/prompts](https://trigger.dev/docs/ai/prompts) for the full reference — template syntax, version resolution order, override workflow, and type utilities (`PromptHandle`, `PromptIdentifier`, `PromptVariables`).

.changeset/chat-actions-no-turn.md

Lines changed: 0 additions & 33 deletions
This file was deleted.

.changeset/chat-agent-delta-wire-snapshots.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

.changeset/chat-agent-on-boot-hook.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ export const myChat = chat.agent({
1818
});
1919
```
2020

21-
If you previously initialized `chat.local` in `onChatStart`, move it to `onBoot` `onChatStart` is once-per-chat and won't fire on a continuation, leaving `chat.local` uninitialized when `run()` tries to use it. See the upgrade guide for the migration pattern.
21+
Use `onBoot` (not `onChatStart`) for state setup that must run every time a worker picks up the chat `onChatStart` fires once per chat and won't run on continuation, leaving `chat.local` uninitialized when `run()` tries to use it.

.changeset/chat-agent.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"@trigger.dev/core": patch
44
---
55

6-
Run AI chats as durable Trigger.dev tasks. Define the agent in one function, wire `useChat` to it from React, and the conversation survives page refreshes, network blips, and process restarts — with built-in support for tools, HITL approvals, multi-turn state, and stop-mid-stream cancellation.
6+
**AI Agents** — run AI SDK chat completions as durable Trigger.dev agents instead of fragile API routes. Define an agent in one function, point `useChat` at it from React, and the conversation survives page refreshes, network blips, and process restarts.
77

88
```ts
99
import { chat } from "@trigger.dev/sdk/ai";
@@ -21,10 +21,24 @@ export const myChat = chat.agent({
2121
import { useChat } from "@ai-sdk/react";
2222
import { useTriggerChatTransport } from "@trigger.dev/sdk/chat/react";
2323

24-
const transport = useTriggerChatTransport({ task: "my-chat", accessToken });
24+
const transport = useTriggerChatTransport({ task: "my-chat", accessToken, startSession });
2525
const { messages, sendMessage } = useChat({ transport });
2626
```
2727

28-
Lifecycle hooks (`onPreload`, `onTurnStart`, `onTurnComplete`, etc.) cover the common needs around persistence, validation, and post-turn work. `chat.store` gives you a typed shared-data slot the agent and client both read and write. `chat.endRun()` exits cleanly when the agent decides it's done. The transport's `watch` mode lets a dashboard tab observe a run without driving it.
28+
**What you get:**
2929

30-
Drops the pre-Sessions chat stream constants (`CHAT_STREAM_KEY`, `CHAT_MESSAGES_STREAM_ID`, `CHAT_STOP_STREAM_ID`) — migrate to `sessions.open(id).out` / `.in`.
30+
- **AI SDK `useChat` integration** — a custom [`ChatTransport`](https://sdk.vercel.ai/docs/ai-sdk-ui/transport) (`useTriggerChatTransport`) plugs straight into Vercel AI SDK's `useChat` hook. Text streaming, tool calls, reasoning, and `data-*` parts all work natively over Trigger.dev's realtime streams. No custom API routes needed.
31+
- **First-turn fast path (`chat.headStart`)** — opt-in handler that runs the first turn's `streamText` step in your warm server process while the agent run boots in parallel, cutting cold-start TTFC by roughly half (measured 2801ms → 1218ms on `claude-sonnet-4-6`). The agent owns step 2+ (tool execution, persistence, hooks) so heavy deps stay where they belong. Web Fetch handler works natively in Next.js, Hono, SvelteKit, Remix, Workers, etc.; bridge to Express/Fastify/Koa via `chat.toNodeListener`. New `@trigger.dev/sdk/chat-server` subpath.
32+
- **Multi-turn durability via Sessions** — every chat is backed by a durable Session that outlives any individual run. Conversations resume across page refreshes, idle timeout, crashes, and deploys; `resume: true` reconnects via `lastEventId` so clients only see new chunks. `sessions.list` enumerates chats for inbox-style UIs.
33+
- **Auto-accumulated history, delta-only wire** — the backend accumulates the full conversation across turns; clients only ship the new message each turn. Long chats never hit the 512 KiB body cap. Register `hydrateMessages` to be the source of truth yourself.
34+
- **Lifecycle hooks**`onPreload`, `onChatStart`, `onValidateMessages`, `hydrateMessages`, `onTurnStart`, `onBeforeTurnComplete`, `onTurnComplete`, `onChatSuspend`, `onChatResume` — for persistence, validation, and post-turn work.
35+
- **Stop generation** — client-driven `transport.stopGeneration(chatId)` aborts mid-stream; the run stays alive for the next message, partial response is captured, and aborted parts (stuck `partial-call` tools, in-progress reasoning) are auto-cleaned.
36+
- **Tool approvals (HITL)** — tools with `needsApproval: true` pause until the user approves or denies via `addToolApprovalResponse`. The runtime reconciles the updated assistant message by ID and continues `streamText`.
37+
- **Steering and background injection**`pendingMessages` injects user messages between tool-call steps so users can steer the agent mid-execution; `chat.inject()` + `chat.defer()` adds context from background work (self-review, RAG, safety checks) between turns.
38+
- **Actions** — non-turn frontend commands (undo, rollback, regenerate, edit) sent via `transport.sendAction`. Fire `hydrateMessages` + `onAction` only — no turn hooks, no `run()`. `onAction` can return a `StreamTextResult` for a model response, or `void` for side-effect-only.
39+
- **Typed state primitives**`chat.local<T>` for per-run state accessible from hooks, `run()`, tools, and subtasks (auto-serialized through `ai.toolExecute`); `chat.store` for typed shared data between agent and client; `chat.history` for reading and mutating the message chain; `clientDataSchema` for typed `clientData` in every hook.
40+
- **`chat.toStreamTextOptions()`** — one spread into `streamText` wires up versioned system [Prompts](https://trigger.dev/docs/ai/prompts), model resolution, telemetry metadata, compaction, steering, and background injection.
41+
- **Multi-tab coordination**`multiTab: true` + `useMultiTabChat` prevents duplicate sends and syncs state across browser tabs via `BroadcastChannel`. Non-active tabs go read-only with live updates.
42+
- **Network resilience** — built-in indefinite retry with bounded backoff, reconnect on `online` / tab refocus / bfcache restore, `Last-Event-ID` mid-stream resume. No app code needed.
43+
44+
See [/docs/ai-chat](https://trigger.dev/docs/ai-chat/overview) for the full surface — quick start, three backend approaches (`chat.agent`, `chat.createSession`, raw task), persistence and code-sandbox patterns, type-level guides, and API reference.

.changeset/chat-head-start.md

Lines changed: 0 additions & 34 deletions
This file was deleted.

.changeset/chat-ready-core-additions.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

.changeset/mcp-list-runs-region.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
MCP `list_runs` tool: add a `region` filter input and surface each run's executing region in the formatted summary.

.changeset/pre.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"mode": "pre",
3+
"tag": "rc",
4+
"initialVersions": {
5+
"coordinator": "0.0.1",
6+
"docker-provider": "0.0.1",
7+
"kubernetes-provider": "0.0.1",
8+
"supervisor": "0.0.1",
9+
"webapp": "1.0.0",
10+
"@trigger.dev/build": "4.4.6",
11+
"trigger.dev": "4.4.6",
12+
"@trigger.dev/core": "4.4.6",
13+
"@trigger.dev/plugins": "4.4.6",
14+
"@trigger.dev/python": "4.4.6",
15+
"@trigger.dev/react-hooks": "4.4.6",
16+
"@trigger.dev/redis-worker": "4.4.6",
17+
"@trigger.dev/rsc": "4.4.6",
18+
"@trigger.dev/schema-to-json": "4.4.6",
19+
"@trigger.dev/sdk": "4.4.6"
20+
},
21+
"changesets": []
22+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@trigger.dev/core": patch
3+
"@trigger.dev/sdk": patch
4+
---
5+
6+
Add `region` to the runs list / retrieve API: filter runs by region (`runs.list({ region: "..." })` / `filter[region]=<masterQueue>`) and read each run's executing region from the new `region` field on the response.

0 commit comments

Comments
 (0)