Skip to content
Draft
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
41 changes: 41 additions & 0 deletions .changeset/ai-sdk-chat-transport.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
"@trigger.dev/ai": minor
---

New package: `@trigger.dev/ai` — AI SDK integration for Trigger.dev

Provides `TriggerChatTransport`, a custom `ChatTransport` implementation for the Vercel AI SDK that bridges `useChat` with Trigger.dev's durable task execution and realtime streams.

**Frontend usage:**
```tsx
import { useChat } from "@ai-sdk/react";
import { TriggerChatTransport } from "@trigger.dev/ai";

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

**Backend task:**
```ts
import { task, streams } from "@trigger.dev/sdk";
import { streamText, convertToModelMessages } from "ai";
import type { ChatTaskPayload } from "@trigger.dev/ai";

export const myChatTask = task({
id: "my-chat-task",
run: async (payload: ChatTaskPayload) => {
const result = streamText({
model: openai("gpt-4o"),
messages: convertToModelMessages(payload.messages),
});
const { waitUntilComplete } = streams.pipe("chat", result.toUIMessageStream());
await waitUntilComplete();
},
});
```

Also exports `createChatTransport()` factory function and `ChatTaskPayload` type for task-side typing.
74 changes: 74 additions & 0 deletions packages/ai/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"name": "@trigger.dev/ai",
"version": "4.3.3",
"description": "AI SDK integration for Trigger.dev - Custom ChatTransport for running AI chat as durable tasks",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/triggerdotdev/trigger.dev",
"directory": "packages/ai"
},
"type": "module",
"files": [
"dist"
],
"tshy": {
"selfLink": false,
"main": true,
"module": true,
"project": "./tsconfig.json",
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
},
"sourceDialects": [
"@triggerdotdev/source"
]
},
"scripts": {
"clean": "rimraf dist .tshy .tshy-build .turbo",
"build": "tshy && pnpm run update-version",
"dev": "tshy --watch",
"typecheck": "tsc --noEmit",
"test": "vitest",
"update-version": "tsx ../../scripts/updateVersion.ts",
"check-exports": "attw --pack ."
},
"dependencies": {
"@trigger.dev/core": "workspace:4.3.3"
},
"peerDependencies": {
"ai": "^5.0.0 || ^6.0.0"
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, find the transport.ts file and see what's being imported
fd -e ts -e tsx -p | grep -E "transport\.(ts|tsx)" | head -20

Repository: triggerdotdev/trigger.dev

Length of output: 97


🏁 Script executed:

# Search for ChatTransport imports in the codebase
rg "ChatTransport" --type ts --type tsx -n

Repository: triggerdotdev/trigger.dev

Length of output: 96


🌐 Web query:

When was ChatTransport introduced in Vercel AI SDK release history

💡 Result:

ChatTransport was introduced with Vercel AI SDK v5.0, when useChat moved to a transport-based architecture. The v5 release was announced on July 31, 2025. [1], [2]

Sources: AI SDK 5 announcement (Jul 31, 2025) [1]; useChat v5 docs showing the transport?: ChatTransport API and noting the v5 transport architecture [2].


🌐 Web query:

ChatTransport ai npm package v5 vs v6 compatibility

💡 Result:

ChatTransport is part of Vercel’s AI SDK (ai npm package). AI SDK v5 and v6 are different major versions and are not “drop-in compatible” at the type/API level—you should not mix ai@5.x with ai@6.x (or @ai-sdk/react@2.x with @ai-sdk/react@3.x) in the same app/library; keep the whole AI SDK stack on the same major. The official v5→v6 migration guide explicitly requires upgrading ai to ^6.0.0 and the @ai-sdk/* packages to their v6-compatible majors. [1]

What this means for ChatTransport implementations

  • If you wrote a custom transport against v5, it may need changes to compile/work on v6, because it must satisfy the v6 ChatTransport interface (e.g., sendMessages uses a { trigger: 'submit-message' | 'regenerate-message', chatId, messageId, messages, abortSignal, ...ChatRequestOptions } options object, and reconnectToStream returns Promise<ReadableStream<UIMessageChunk> | null>). [2]
  • The concept (transport-based useChat) exists in both v5 and v6, but treat the transport interface as versioned and pin it via peerDependencies if you publish a transport package. (Typical approach: release separate majors like your-transport@5 for ai@^5 and your-transport@6 for ai@^6.) [3][4]

Recommended path

  • App code: upgrade everything together per the v6 migration guide and run the codemod (npx @ai-sdk/codemod v6). [1]
  • Library/transport package: set peerDependencies to either ai@^5 or ai@^6 (not both unless you actively maintain compatibility), and provide separate releases if needed. [2]

Sources: v6 migration guide [1], v6 ChatTransport interface [2], v5/v6 transport docs showing the transport system around useChat [3][4].


🏁 Script executed:

# Read the transport.ts file to see the actual implementation
cat -n packages/ai/src/transport.ts

Repository: triggerdotdev/trigger.dev

Length of output: 10058


Narrow peer dependency to "ai": "^6.0.0" only.

ChatTransport exists in both AI SDK v5 and v6, but the interface is incompatible between versions. This implementation targets the v6 ChatTransport API (e.g., sendMessages signature with { trigger, chatId, messageId, messages, abortSignal } and reconnectToStream returning Promise<ReadableStream<UIMessageChunk> | null>). The current peer dependency "^5.0.0 || ^6.0.0" allows v5, which has a different interface and will cause runtime errors. Either narrow to "^6.0.0" or maintain separate major versions (e.g., @trigger.dev/ai@5 for ai@^5, @trigger.dev/ai@6 for ai@^6).

🤖 Prompt for AI Agents
In `@packages/ai/package.json` around lines 43 - 45, The peerDependency for the
"ai" package is too broad and must be narrowed to "^6.0.0" because this package
implements the v6 ChatTransport API (e.g., ChatTransport methods sendMessages
with { trigger, chatId, messageId, messages, abortSignal } and reconnectToStream
returning Promise<ReadableStream<UIMessageChunk> | null>); update the
peerDependencies entry for "ai" in package.json to "^6.0.0" (or alternatively
release a separate major package for v5 vs v6), ensuring only the v6-compatible
consumer is allowed.

"devDependencies": {
"@arethetypeswrong/cli": "^0.15.4",
"ai": "^6.0.0",
"rimraf": "^3.0.2",
"tshy": "^3.0.2",
"tsx": "4.17.0",
"vitest": "^2.1.0"
},
"engines": {
"node": ">=18.20.0"
},
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"@triggerdotdev/source": "./src/index.ts",
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
}
}
},
"main": "./dist/commonjs/index.js",
"types": "./dist/commonjs/index.d.ts",
"module": "./dist/esm/index.js"
}
3 changes: 3 additions & 0 deletions packages/ai/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { TriggerChatTransport, createChatTransport } from "./transport.js";
export type { TriggerChatTransportOptions, ChatTaskPayload } from "./types.js";
export { VERSION } from "./version.js";
Loading
Loading