Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
f025cca
feat: add @trigger.dev/ai package with TriggerChatTransport
cursoragent Feb 15, 2026
bf4ed19
test: add comprehensive unit tests for TriggerChatTransport
cursoragent Feb 15, 2026
cfb3212
refactor: polish TriggerChatTransport implementation
cursoragent Feb 15, 2026
7d097ce
test: add abort signal, multiple sessions, and body merging tests
cursoragent Feb 15, 2026
c4934b7
chore: add changeset for @trigger.dev/ai package
cursoragent Feb 15, 2026
c6e4c7d
refactor: remove internal ChatSessionState from public exports
cursoragent Feb 15, 2026
8891110
feat: support dynamic accessToken function for token refresh
cursoragent Feb 15, 2026
c92b28c
refactor: avoid double-resolving accessToken in sendMessages
cursoragent Feb 15, 2026
0a2e7f1
feat: add chat transport and AI chat helpers to @trigger.dev/sdk
cursoragent Feb 15, 2026
ab30c08
test: move chat transport tests to @trigger.dev/sdk
cursoragent Feb 15, 2026
03b26fb
refactor: delete packages/ai/ — moved to @trigger.dev/sdk subpaths
cursoragent Feb 15, 2026
36916ef
chore: update changeset to target @trigger.dev/sdk
cursoragent Feb 15, 2026
0b9bb98
fix: address CodeRabbit review feedback
cursoragent Feb 15, 2026
f2e5e4c
docs(ai): add AI Chat with useChat guide
cursoragent Feb 15, 2026
ce16c56
feat(reference): add ai-chat Next.js reference project
cursoragent Feb 15, 2026
8009d40
fix(reference): use compatible @ai-sdk v3 packages, await convertToMo…
cursoragent Feb 15, 2026
15f48ff
Use a single run with iterative waitpoint token completions
ericallam Feb 21, 2026
19539e7
Added tool example
ericallam Feb 21, 2026
9f22201
expose a useTriggerChatTransport hook
ericallam Feb 21, 2026
89e3113
use input streams and rename chatTask and chatState to chat.task and …
ericallam Mar 3, 2026
e6bf1e9
add stopping support and fix issue with the OpenAI responses API and …
ericallam Mar 4, 2026
03a2434
Add warmTimeoutInSeconds option
ericallam Mar 4, 2026
82ef8e2
Add clientData support
ericallam Mar 4, 2026
09b7f4d
provide already converted UIMessages to the run function for better dx
ericallam Mar 4, 2026
6c3c193
Added better telemetry support to view turns
ericallam Mar 4, 2026
58e7ef4
Fix double looping when resuming from an input stream waitpoint
ericallam Mar 4, 2026
f04b179
Add some pending message support in the example
ericallam Mar 4, 2026
8640cf0
Accumulate messages in the task, allowing us to only have to send use…
ericallam Mar 5, 2026
bfa3341
build full example with persisting messages, adding necessary hooks, …
ericallam Mar 5, 2026
326044f
Add ai chat to the sidebar for now
ericallam Mar 5, 2026
6d0da2e
remove postinstall hook
ericallam Mar 5, 2026
21050cc
feat: add onTurnStart hook, lastEventId support, and stream resume de…
ericallam Mar 5, 2026
1151b20
Minor fixes around reconnecting streams
ericallam Mar 6, 2026
5f36155
update pnpm link file
ericallam Mar 6, 2026
0df407e
fixed chat tests
ericallam Mar 6, 2026
2b00606
use locals for the chat pipe counter instead of a module global
ericallam Mar 6, 2026
800725f
Add triggerOptions to the transport, auto-tag with the chat ID
ericallam Mar 6, 2026
28afa98
Make clientData typesafe and pass to all chat.task hooks
ericallam Mar 6, 2026
fc9768a
feat: add chat.local for per-run typed data with Proxy access and dir…
ericallam Mar 6, 2026
5c1aa24
feat(chat): add stop handling, abort cleanup, continuation support, a…
ericallam Mar 7, 2026
6b8df32
Some improvements to the example ai-chat
ericallam Mar 7, 2026
acb1f98
feat(chat): expose typed chat.stream, add deepResearch subtask exampl…
ericallam Mar 8, 2026
1cc19f8
feat(ai): pass chat context and toolCallId to subtasks, add typed ai.…
ericallam Mar 8, 2026
b2dc691
feat(chat): add preload support, dynamic tools, and preload-specific …
ericallam Mar 9, 2026
ebc3199
docs: add mermaid architecture diagrams for ai-chat system
ericallam Mar 9, 2026
01fab9d
docs: add sequence diagrams to ai-chat guide
ericallam Mar 9, 2026
3d0b027
feat(chat): auto-hydrate chat.local values in ai.tool subtasks
ericallam Mar 9, 2026
dc84597
feat(chat): add chat.defer(), preload toggle, TTFB measurement, and f…
ericallam Mar 9, 2026
7aa5964
fix(reference): replace hand-rolled HTML stripping with turndown
ericallam Mar 9, 2026
2908b35
feat(streams): add inputStream.waitWithWarmup(), warm timeout config …
ericallam Mar 9, 2026
25f7ded
feat(chat): add composable primitives, raw task example, and task mod…
ericallam Mar 10, 2026
1f6ea4b
Introduce the chat session API and better docs organization
ericallam Mar 10, 2026
7890072
Add support for toUIMessageStream() options
ericallam Mar 10, 2026
18ca682
Add metadata to the streamText call
ericallam Mar 12, 2026
856d252
feat(chat): add chat.prompt API with provider registry support
ericallam Mar 23, 2026
aeb0fbb
refactor: rename warmTimeout to idleTimeout across chat APIs
ericallam Mar 23, 2026
c21e920
feat: support message compaction
ericallam Mar 24, 2026
f7442f1
better compaction support in our other chat variants
ericallam Mar 24, 2026
f05d638
feat(chat): add compaction option, pendingMessages steering, and useP…
ericallam Mar 25, 2026
49e858e
Add a writer to easily write chunks in callbacks
ericallam Mar 26, 2026
9d334e8
feat(ai): add triggerAndSubscribe method and use it in ai.tool
ericallam Mar 26, 2026
71abce7
feat(chat): add chat.inject() for background context injection and ch…
ericallam Mar 26, 2026
be820d0
feat(sdk): ToolSet typing for toolFromTask, ai.toolExecute, deprecate…
ericallam Mar 27, 2026
5a8ba63
Add run-scoped PAT renewal for chat transport
ericallam Mar 27, 2026
dde3934
feat(sdk): ctx on chat.task hooks; ai-chat E2B sandbox; docs patterns
ericallam Mar 27, 2026
817367a
feat(sdk): add onChatSuspend/onChatResume hooks, exitAfterPreloadIdle…
ericallam Mar 28, 2026
254bf42
Add support for triggering from the backend
ericallam Mar 28, 2026
89de993
chat.task -> chat.agent
ericallam Mar 30, 2026
91b21ea
feat: upgrade streamdown to v2.5.0 with custom Trigger.dev Shiki theme
ericallam Apr 1, 2026
ae2123b
playground ui tweaks
ericallam Apr 1, 2026
f4817fd
Some design tweaks, improvements to playground options, rename unname…
ericallam Apr 1, 2026
5502950
Add the chat client and strip agent crumbs
ericallam Apr 1, 2026
9831a2f
Add server-to-server chat support and subagent support to the playgro…
ericallam Apr 2, 2026
15c2ee8
add agent mcp tools
ericallam Apr 2, 2026
7f649ef
Add support for optionally validating UI messages
ericallam Apr 2, 2026
77a755c
Support for upgrading an agent to a new version
ericallam Apr 3, 2026
e958695
Add run agent view
ericallam Apr 10, 2026
b99bd75
feat(chat): add stopGeneration, fix onTurnComplete/onFinishPromise, a…
ericallam Apr 11, 2026
258ddb2
fix(sdk): inject prepareStep in toStreamTextOptions even without chat…
ericallam Apr 13, 2026
d6ac62f
feat(chat): allow generateMessageId in uiMessageStreamOptions, auto-p…
ericallam Apr 14, 2026
d54e6a2
feat(chat): tool approvals support — ID-matched message replacement, …
ericallam Apr 14, 2026
1cf81d1
fix: restore applyPrepareMessages call after agentcrumbs strip
ericallam Apr 14, 2026
27cb3cc
prevent preloads from firing twice when in React strictMode
ericallam Apr 14, 2026
8c43c74
feat(chat): add chat.response API for persistent data parts, transien…
ericallam Apr 14, 2026
49df95b
feat(chat): add hydrateMessages, chat.history, and custom actions
ericallam Apr 15, 2026
5bb7ae6
fix(chat): prevent useChat resume from hanging on completed turns
ericallam Apr 15, 2026
ecc8ee7
fix pnpm lock file
ericallam Apr 16, 2026
a7078eb
feat(ai-chat): add askUser tool for HITL testing, verify TRI-8556 fix
ericallam Apr 17, 2026
3de23d1
chore(ai-chat): remove test-big-error trigger from onValidateMessages
ericallam Apr 17, 2026
788661a
feat(chat): multi-tab coordination via BroadcastChannel
ericallam Apr 17, 2026
cf7aec8
fix(ai-chat): defer multi-tab broadcasts, disable streamdown word ani…
ericallam Apr 17, 2026
0973ae6
feat(core): add runInMockTaskContext test infrastructure
ericallam Apr 18, 2026
220eeee
feat(sdk): add mockChatAgent test harness with locals DI
ericallam Apr 18, 2026
fded2cd
feat(chat): expose finishReason on turn-complete events
ericallam Apr 18, 2026
0a401d8
feat(chat): add chat.endRun()
ericallam Apr 18, 2026
b27da8b
fix(chat): include "action" in ChatTaskPayload.trigger type
ericallam Apr 18, 2026
ee673f7
feat(core): add skill resource catalog + SkillManifest schemas
ericallam Apr 18, 2026
cf4b61e
feat(sdk): add skills.define + chat.skills runtime wiring
ericallam Apr 18, 2026
cc24ab1
feat(cli): built-in skill bundler for trigger dev + deploy
ericallam Apr 18, 2026
3ae6f91
feat(sdk,cli,core,build): phase 1 of agent skills
ericallam Apr 18, 2026
9942ef4
fix(cli): skills bundler resolves caller-relative paths + correct dev…
ericallam Apr 18, 2026
a846634
WIP chat.store primitive
ericallam Apr 19, 2026
85db7bd
feat(sdk,core): Session client SDK + hello-world smoke test
ericallam Apr 20, 2026
f232f52
feat(sdk,core): Session channel SDK toolkits + waitpoints — client side
ericallam Apr 23, 2026
6ac545a
feat(sdk): chat.agent → Sessions migration (phases B + C + min E)
ericallam Apr 23, 2026
fffd2d5
feat(sdk): server-side ChatStream / AgentChat -> Sessions (phase D)
ericallam Apr 23, 2026
7ba0a66
fix(sdk,chat): route pipeChat through session.out + chat-agent smoke …
ericallam Apr 23, 2026
23ec6a2
test(sdk,core): session-aware mockChatAgent harness + chat.test.ts mocks
ericallam Apr 23, 2026
a93238b
docs(architecture): chat.agent over Sessions reference
ericallam Apr 23, 2026
3c148c6
feat(cli): MCP agentChat tool → Sessions migration
ericallam Apr 23, 2026
6730467
feat(webapp,sdk): dashboard AgentView → session streams
ericallam Apr 23, 2026
86a3f85
feat(sdk,ai-chat): skills runtime subpath + ai-chat browser test bridge
ericallam Apr 23, 2026
e56d9db
feat(sdk,webapp,ai-chat): end-to-end browser UI smoke on sessions
ericallam Apr 23, 2026
bca80dd
feat(sdk,core): drop legacy chat stream-ID constants
ericallam Apr 23, 2026
b04f1cc
fix(sdk,chat): make isStreaming optional in reconnectToStream short-c…
ericallam Apr 24, 2026
3f62880
fix(webapp): use getRequestAbortSignal() for dashboard stream routes
ericallam Apr 24, 2026
3d2483a
refactor(sdk): extract browser-safe chat types into ai-shared
ericallam Apr 25, 2026
5164aab
feat(sdk,webapp): X-Peek-Settled opt-in fast-close on session.out
ericallam Apr 25, 2026
bb6aeb7
feat(sdk,webapp): X-Peek-Settled fast-close (webapp + docs)
ericallam Apr 25, 2026
9477917
feat(sdk,playground,ai-chat): chat.agent on Sessions-as-run-manager
ericallam Apr 27, 2026
56beb17
ignore claude subdirs
ericallam Apr 28, 2026
7691512
fix sdk build for new context field
ericallam Apr 28, 2026
d424c41
fix(core): buffer session-stream chunks even when handlers exist
ericallam Apr 28, 2026
edf477f
ignroe claude scheduled tasks lock file
ericallam Apr 28, 2026
527b651
fix(sdk,ai-chat): auto chat:{chatId} tag on server-mediated start; at…
ericallam Apr 28, 2026
b6ed98e
fix(ai-chat reference): await Chat.messages persist in onTurnStart
ericallam Apr 29, 2026
7146af9
feat(ai-chat reference): db:reset:chats helper for clean smoke-test s…
ericallam Apr 29, 2026
3295e59
feat(ai-chat reference): explicit Preload button + Runs link in debug…
ericallam Apr 29, 2026
00a61b6
fix(cli): MCP agentChat — task-bound session creation
ericallam Apr 29, 2026
9fc1870
test(clickhouse): add missing task_kind to taskRuns test fixtures
ericallam Apr 29, 2026
2639259
fix(sdk,cli): server-to-agent chat preload — `trigger: "preload"` + `…
ericallam Apr 29, 2026
f150cf2
feat(sdk,core): ChatChunkTooLargeError for oversized chat-stream chunks
ericallam Apr 30, 2026
f65022a
fix(sdk,core): unblock CI on PR #3173
ericallam Apr 30, 2026
f9e7dac
fix(core): typesVersions entry for v3/chat-client + inline CodeQL guards
ericallam Apr 30, 2026
55fa0f7
fix(core,webapp): plumb maxDuration / lockToVersion / region through …
ericallam May 1, 2026
6c74ef0
chore: consolidate chat.agent / Sessions / Skills changesets (26 → 8)
ericallam May 1, 2026
fadbc3d
chore: rewrite consolidated changesets in user-facing changelog voice
ericallam May 1, 2026
9b88079
fix: address PR 3173 review feedback
ericallam May 1, 2026
ea54931
feat(sdk): resilient SSE reconnection in chat transport
ericallam May 1, 2026
f063a2f
feat(sdk): chat.headStart for fast first-turn TTFC
ericallam May 3, 2026
64ede82
chore(references): demo chat.headStart in ai-chat reference
ericallam May 3, 2026
c9e02e3
fix(webapp): wrap playground 'save' JSON.parse to return 400 on malfo…
ericallam May 3, 2026
785d015
feat(webapp): plumb per-org basin through playground + dashboard rout…
ericallam May 4, 2026
6e492b6
fix: AGENT/SCHEDULED runs misclassified + green up the chat.handover …
ericallam May 5, 2026
bd52546
fix(webapp): normalize taskKind in API + drop unsafe casts in playgro…
ericallam May 5, 2026
6c7d4a1
fix(sdk): drop session-stream auto-reconnect after explicit disconnect
ericallam May 5, 2026
0f8e1ce
fix(sdk): drop duplicate onError on SSE auth-error path
ericallam May 5, 2026
3eba74a
feat(sdk): stamp gen_ai.conversation.id on chat spans and metrics
ericallam May 5, 2026
6585ce8
feat(sdk)!: chat.agent actions are no longer turns
ericallam May 6, 2026
080bace
feat(ai-chat-ref): add undo action + button to demo agent
ericallam May 6, 2026
16c3c9b
docs(sdk): clarify sendAction semantics for actions-not-turns
ericallam May 6, 2026
2bb5684
feat(webapp): Sessions list + detail views and run inspector linkage
ericallam May 7, 2026
1aa3606
fix: address PR 3173 review feedback (closure + unhandled rejection)
ericallam May 7, 2026
f6f0f46
fix(sdk): tolerate AI SDK assistant-id regen on HITL addToolOutput re…
ericallam May 7, 2026
49aab61
feat(sdk): add chat.history read primitives for HITL flows
ericallam May 7, 2026
701d80b
fix(sdk): tighten chat.history read primitives from review feedback
ericallam May 7, 2026
3ffc73f
feat(sdk): chat.agent oomMachine for automatic OOM-retry on a larger …
ericallam May 7, 2026
c202f3a
feat(chat.agent): delta-only wire and history reconstruction at run boot
ericallam May 9, 2026
2d05629
fix(sdk): update tests to match the delta-only wire and current AI SD…
ericallam May 10, 2026
a814e3b
chore: reconcile pnpm-lock.yaml after merging main
ericallam May 10, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .changeset/agent-skills.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
"@trigger.dev/sdk": patch
"@trigger.dev/core": patch
"@trigger.dev/build": patch
"trigger.dev": patch
---

Add Agent Skills for `chat.agent`. Drop a folder with a `SKILL.md` and any helper scripts/references next to your task code, register it with `skills.define({ id, path })`, and the CLI bundles it into the deploy image automatically — no `trigger.config.ts` changes. The agent gets a one-line summary in its system prompt and discovers full instructions on demand via `loadSkill`, with `bash` and `readFile` tools scoped per-skill (path-traversal guards, output caps, abort-signal propagation).

```ts
const pdfSkill = skills.define({ id: "pdf-extract", path: "./skills/pdf-extract" });

chat.skills.set([await pdfSkill.local()]);
```

Built on the [AI SDK cookbook pattern](https://ai-sdk.dev/cookbook/guides/agent-skills) — portable across providers. SDK + CLI only for now; dashboard-editable `SKILL.md` text is on the roadmap.
15 changes: 15 additions & 0 deletions .changeset/ai-tool-helpers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@trigger.dev/sdk": patch
---

Add `ai.toolExecute(task)` so you can wire a Trigger subtask in as the `execute` handler of an AI SDK `tool()` while defining `description` and `inputSchema` yourself — useful when you want full control over the tool surface and just need Trigger's subtask machinery for the body.

```ts
const myTool = tool({
description: "...",
inputSchema: z.object({ ... }),
execute: ai.toolExecute(mySubtask),
});
```

`ai.tool(task)` (`toolFromTask`) keeps doing the all-in-one wrap and now aligns its return type with AI SDK's `ToolSet`. Minimum `ai` peer raised to `^6.0.116` to avoid cross-version `ToolSet` mismatches in monorepos.
33 changes: 33 additions & 0 deletions .changeset/chat-actions-no-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
"@trigger.dev/sdk": minor
---

`chat.agent` actions are no longer treated as turns. They fire `hydrateMessages` and `onAction` only — no `onTurnStart` / `prepareMessages` / `onBeforeTurnComplete` / `onTurnComplete`, no `run()`, no turn-counter increment. The trace span is named `chat action` instead of `chat turn N`.

`onAction` can now return a `StreamTextResult`, `string`, or `UIMessage` to produce a model response from the action; returning `void` (the previous and now default) is side-effect-only.

**Migration**: if you previously had `run()` branching on `payload.trigger === "action"`, return your `streamText(...)` from `onAction` instead. If you persisted in `onTurnComplete`, do that work inside `onAction`. For any other state-only action, just remove your skip-the-model workaround — the default is now correct.

```ts
// before
onAction: async ({ action }) => {
if (action.type === "regenerate") {
chat.store.set({ skipModelCall: false });
chat.history.slice(0, -1);
}
},
run: async ({ messages, signal }) => {
if (chat.store.get()?.skipModelCall) return;
return streamText({ model, messages, abortSignal: signal });
},

// after
onAction: async ({ action, messages, signal }) => {
if (action.type === "regenerate") {
chat.history.slice(0, -1);
return streamText({ model, messages, abortSignal: signal });
}
},
run: async ({ messages, signal }) =>
streamText({ model, messages, abortSignal: signal }),
```
8 changes: 8 additions & 0 deletions .changeset/chat-agent-delta-wire-snapshots.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@trigger.dev/sdk": patch
"@trigger.dev/core": patch
---

`chat.agent` wire is now delta-only — clients ship at most one new message per `.in/append` instead of the full `UIMessage[]` history. The agent rebuilds prior history at run boot from a JSON snapshot in object storage plus a `wait=0` replay of the `session.out` tail. Long chats stop hitting the 512 KiB body cap on `/realtime/v1/sessions/{id}/in/append`. Snapshot writes happen after every `onTurnComplete`, awaited so they survive idle suspend; reads happen only at run boot. Registering a `hydrateMessages` hook short-circuits both the snapshot read/write and the replay — the customer is the source of truth for history.

Custom transports that constructed `ChatTaskWirePayload` directly need to drop the `messages: UIMessage[]` field and use `message?: UIMessage` (singular). Built-in transports (`TriggerChatTransport`, `AgentChat`) handle the change below the customer-facing surface — most apps need no changes. Configure object-store env vars (`OBJECT_STORE_*`) on your webapp deployment if you haven't already; without an object store and without `hydrateMessages`, conversations don't survive run boundaries.
30 changes: 30 additions & 0 deletions .changeset/chat-agent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
"@trigger.dev/sdk": minor
"@trigger.dev/core": patch
---

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.

```ts
import { chat } from "@trigger.dev/sdk/ai";
import { streamText } from "ai";
import { openai } from "@ai-sdk/openai";

export const myChat = chat.agent({
id: "my-chat",
run: async ({ messages, signal }) =>
streamText({ model: openai("gpt-4o"), messages, abortSignal: signal }),
});
```

```tsx
import { useChat } from "@ai-sdk/react";
import { useTriggerChatTransport } from "@trigger.dev/sdk/chat/react";

const transport = useTriggerChatTransport({ task: "my-chat", accessToken });
const { messages, sendMessage } = useChat({ transport });
```

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.

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`.
34 changes: 34 additions & 0 deletions .changeset/chat-head-start.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
"@trigger.dev/sdk": minor
---

Add `chat.headStart` — an opt-in fast-path that runs the first turn's `streamText` step in your warm Next.js / Hono / Workers / Express handler while the trigger agent run boots in parallel. Cold-start TTFC drops by ~50% on the first message; the agent owns step 2+ (tool execution, persistence, hooks) so heavy deps stay where they belong.

```ts
// app/api/chat/route.ts (Next.js / any Web Fetch framework)
import { chat } from "@trigger.dev/sdk/chat-server";
import { streamText } from "ai";
import { openai } from "@ai-sdk/openai";
import { headStartTools } from "@/lib/chat-tools-schemas"; // schema-only

export const POST = chat.headStart({
agentId: "ai-chat",
run: async ({ chat: chatHelper }) =>
streamText({
...chatHelper.toStreamTextOptions({ tools: headStartTools }),
model: openai("gpt-4o-mini"),
system: "You are a helpful AI assistant.",
}),
});
```

```tsx
// browser — opt in by pointing the transport at your handler
const transport = useTriggerChatTransport({
task: "ai-chat",
accessToken,
headStart: "/api/chat", // first-turn-only; turn 2+ bypasses the endpoint
});
```

For Node-only frameworks (Express, Fastify, Koa, raw `node:http`) use `chat.toNodeListener(handler)` to bridge the Web Fetch handler to `(req, res)`. Adds a new `@trigger.dev/sdk/chat-server` subpath; bundle stays Web Fetch–only with no `node:*` imports.
21 changes: 21 additions & 0 deletions .changeset/chat-history-read-primitives.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
"@trigger.dev/sdk": minor
---

Add read primitives to `chat.history` for HITL flows: `getPendingToolCalls()`, `getResolvedToolCalls()`, `extractNewToolResults(message)`, `getChain()`, and `findMessage(messageId)`. These lift the accumulator-walking logic that customers building human-in-the-loop tools were re-implementing into the SDK.

Use `getPendingToolCalls()` to gate fresh user turns while a tool call is awaiting an answer. Use `extractNewToolResults(message)` to dedup tool results when persisting to your own store — the helper returns only the parts whose `toolCallId` is not already resolved on the chain.

```ts
const pending = chat.history.getPendingToolCalls();
if (pending.length > 0) {
// an addToolOutput is expected before a new user message
}

onTurnComplete: async ({ responseMessage }) => {
const newResults = chat.history.extractNewToolResults(responseMessage);
for (const r of newResults) {
await db.toolResults.upsert({ id: r.toolCallId, output: r.output, errorText: r.errorText });
}
};
```
6 changes: 6 additions & 0 deletions .changeset/chat-session-attributes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@trigger.dev/sdk": patch
"@trigger.dev/core": patch
---

Stamp `gen_ai.conversation.id` (the chat id) on every span and metric emitted from inside a `chat.task` or `chat.agent` run. Lets you filter dashboard spans, runs, and metrics by the chat conversation that produced them — independent of the run boundary, so multi-run chats correlate cleanly. No code changes required on the user side.
5 changes: 5 additions & 0 deletions .changeset/mcp-agent-chat-sessions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"trigger.dev": patch
---

The CLI MCP server's agent-chat tools (`start_agent_chat`, `send_agent_message`, `close_agent_chat`) now run on the new Sessions primitive, so AI assistants driving a `chat.agent` get the same idempotent-by-`chatId`, durable-across-runs behavior the browser transport gets. Required PAT scopes go from `write:inputStreams` to `read:sessions` + `write:sessions`.
8 changes: 8 additions & 0 deletions .changeset/mock-chat-agent-test-harness.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@trigger.dev/sdk": patch
"@trigger.dev/core": patch
---

Unit-test `chat.agent` definitions offline with `mockChatAgent` from `@trigger.dev/sdk/ai/test`. Drives a real agent's turn loop in-process — no network, no task runtime — so you can send messages, actions, and stop signals via driver methods, inspect captured output chunks, and verify hooks fire. Pairs with `MockLanguageModelV3` from `ai/test` for model mocking. `setupLocals` lets you pre-seed `locals` (DB clients, service stubs) before `run()` starts.

The broader `runInMockTaskContext` harness it's built on lives at `@trigger.dev/core/v3/test` — useful for unit-testing any task code, not just chat.
14 changes: 14 additions & 0 deletions .changeset/sessions-primitive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"@trigger.dev/core": patch
"@trigger.dev/sdk": patch
---

Add Sessions — a durable, task-bound, bidirectional channel pair that outlives any single run. One identifier (your `externalId`), many runs over time, with a stable `.in` channel clients can write to and a stable `.out` channel they can subscribe to. Powers `chat.agent` (separate changeset), and unblocks anything that needs "resume tomorrow" or "approval loop" workflows.

```ts
const session = await sessions.create({ externalId: chatId, taskIdentifier: "my-task" });
await session.in.send({ kind: "message", payload: "..." });
for await (const chunk of session.out.read()) { /* ... */ }
```

Inside the task, `.in.wait()` / `.waitWithIdleTimeout()` suspends the run on a session-stream waitpoint until the next record arrives. `.out.append` / `.pipe` / `.writer` produce records via direct-to-S2 writes.
Loading
Loading