|
1 | 1 | --- |
2 | | -"@trigger.dev/ai": minor |
| 2 | +"@trigger.dev/sdk": minor |
3 | 3 | --- |
4 | 4 |
|
5 | | -New package: `@trigger.dev/ai` — AI SDK integration for Trigger.dev |
| 5 | +Add AI SDK chat transport integration via two new subpath exports: |
6 | 6 |
|
7 | | -Provides `TriggerChatTransport`, a custom `ChatTransport` implementation for the Vercel AI SDK that bridges `useChat` with Trigger.dev's durable task execution and realtime streams. |
| 7 | +**`@trigger.dev/sdk/chat`** (frontend, browser-safe): |
| 8 | +- `TriggerChatTransport` — custom `ChatTransport` for the AI SDK's `useChat` hook that runs chat completions as durable Trigger.dev tasks |
| 9 | +- `createChatTransport()` — factory function |
8 | 10 |
|
9 | | -**Frontend usage:** |
10 | 11 | ```tsx |
11 | 12 | import { useChat } from "@ai-sdk/react"; |
12 | | -import { TriggerChatTransport } from "@trigger.dev/ai"; |
| 13 | +import { TriggerChatTransport } from "@trigger.dev/sdk/chat"; |
13 | 14 |
|
14 | 15 | const { messages, sendMessage } = useChat({ |
15 | 16 | transport: new TriggerChatTransport({ |
16 | | - accessToken: publicAccessToken, |
17 | | - taskId: "my-chat-task", |
| 17 | + task: "my-chat-task", |
| 18 | + accessToken, |
18 | 19 | }), |
19 | 20 | }); |
20 | 21 | ``` |
21 | 22 |
|
22 | | -**Backend task:** |
| 23 | +**`@trigger.dev/sdk/ai`** (backend, extends existing `ai.tool`/`ai.currentToolOptions`): |
| 24 | +- `chatTask()` — pre-typed task wrapper with auto-pipe support |
| 25 | +- `pipeChat()` — pipe a `StreamTextResult` or stream to the frontend |
| 26 | +- `CHAT_STREAM_KEY` — the default stream key constant |
| 27 | +- `ChatTaskPayload` type |
| 28 | + |
23 | 29 | ```ts |
24 | | -import { task, streams } from "@trigger.dev/sdk"; |
| 30 | +import { chatTask } from "@trigger.dev/sdk/ai"; |
25 | 31 | import { streamText, convertToModelMessages } from "ai"; |
26 | | -import type { ChatTaskPayload } from "@trigger.dev/ai"; |
27 | 32 |
|
28 | | -export const myChatTask = task({ |
| 33 | +export const myChatTask = chatTask({ |
29 | 34 | id: "my-chat-task", |
30 | | - run: async (payload: ChatTaskPayload) => { |
31 | | - const result = streamText({ |
| 35 | + run: async ({ messages }) => { |
| 36 | + return streamText({ |
32 | 37 | model: openai("gpt-4o"), |
33 | | - messages: convertToModelMessages(payload.messages), |
| 38 | + messages: convertToModelMessages(messages), |
34 | 39 | }); |
35 | | - const { waitUntilComplete } = streams.pipe("chat", result.toUIMessageStream()); |
36 | | - await waitUntilComplete(); |
37 | 40 | }, |
38 | 41 | }); |
39 | 42 | ``` |
40 | | - |
41 | | -Also exports `createChatTransport()` factory function and `ChatTaskPayload` type for task-side typing. |
|
0 commit comments