Skip to content

Commit 7f9b046

Browse files
authored
docs: Fixes and realtime improvements (#3265)
1 parent c00dae0 commit 7f9b046

File tree

20 files changed

+280
-114
lines changed

20 files changed

+280
-114
lines changed

.cursor/rules/writing-tasks.mdc

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ alwaysApply: false
1414

1515
## Essential requirements when generating task code
1616

17-
1. You MUST use `@trigger.dev/sdk/v3`
17+
1. You MUST import from `@trigger.dev/sdk` (NEVER `@trigger.dev/sdk/v3`)
1818
2. You MUST NEVER use `client.defineJob`
1919
3. YOU MUST `export` every task, including subtasks
2020
4. If you are able to generate an example payload for a task, do so.
@@ -53,7 +53,7 @@ Instead, you MUST ALWAYS generate ONLY this pattern:
5353
```ts
5454
// ✅ ALWAYS GENERATE THIS EXACT PATTERN
5555

56-
import { task } from "@trigger.dev/sdk/v3";
56+
import { task } from "@trigger.dev/sdk";
5757

5858
//1. You need to export each task, even if it's a subtask
5959
export const helloWorld = task({
@@ -71,7 +71,7 @@ export const helloWorld = task({
7171
A task is a function that can run for a long time with resilience to failure:
7272

7373
```ts
74-
import { task } from "@trigger.dev/sdk/v3";
74+
import { task } from "@trigger.dev/sdk";
7575

7676
export const helloWorld = task({
7777
id: "hello-world",
@@ -271,7 +271,7 @@ Global lifecycle hooks can also be defined in `trigger.config.ts` to apply to al
271271
## Correct Schedules task (cron) implementations
272272

273273
```ts
274-
import { schedules } from "@trigger.dev/sdk/v3";
274+
import { schedules } from "@trigger.dev/sdk";
275275

276276
export const firstScheduledTask = schedules.task({
277277
id: "first-scheduled-task",
@@ -312,7 +312,7 @@ export const firstScheduledTask = schedules.task({
312312
### Attach a Declarative schedule
313313

314314
```ts
315-
import { schedules } from "@trigger.dev/sdk/v3";
315+
import { schedules } from "@trigger.dev/sdk";
316316

317317
// Sepcify a cron pattern (UTC)
318318
export const firstScheduledTask = schedules.task({
@@ -326,7 +326,7 @@ export const firstScheduledTask = schedules.task({
326326
```
327327

328328
```ts
329-
import { schedules } from "@trigger.dev/sdk/v3";
329+
import { schedules } from "@trigger.dev/sdk";
330330

331331
// Specify a specific timezone like this:
332332
export const secondScheduledTask = schedules.task({
@@ -375,7 +375,7 @@ const createdSchedule = await schedules.create({
375375
Schema tasks validate payloads against a schema before execution:
376376

377377
```ts
378-
import { schemaTask } from "@trigger.dev/sdk/v3";
378+
import { schemaTask } from "@trigger.dev/sdk";
379379
import { z } from "zod";
380380

381381
const myTask = schemaTask({
@@ -400,7 +400,7 @@ When you trigger a task from your backend code, you need to set the `TRIGGER_SEC
400400
Triggers a single run of a task with specified payload and options without importing the task. Use type-only imports for full type checking.
401401

402402
```ts
403-
import { tasks } from "@trigger.dev/sdk/v3";
403+
import { tasks } from "@trigger.dev/sdk";
404404
import type { emailSequence } from "~/trigger/emails";
405405

406406
export async function POST(request: Request) {
@@ -418,7 +418,7 @@ export async function POST(request: Request) {
418418
Triggers multiple runs of a single task with different payloads without importing the task.
419419

420420
```ts
421-
import { tasks } from "@trigger.dev/sdk/v3";
421+
import { tasks } from "@trigger.dev/sdk";
422422
import type { emailSequence } from "~/trigger/emails";
423423

424424
export async function POST(request: Request) {
@@ -436,7 +436,7 @@ export async function POST(request: Request) {
436436
Triggers multiple runs of different tasks at once, useful when you need to execute multiple tasks simultaneously.
437437

438438
```ts
439-
import { batch } from "@trigger.dev/sdk/v3";
439+
import { batch } from "@trigger.dev/sdk";
440440
import type { myTask1, myTask2 } from "~/trigger/myTasks";
441441

442442
export async function POST(request: Request) {
@@ -621,7 +621,7 @@ const handle = await myTask.trigger(
621621
Access metadata inside a run:
622622

623623
```ts
624-
import { task, metadata } from "@trigger.dev/sdk/v3";
624+
import { task, metadata } from "@trigger.dev/sdk";
625625

626626
export const myTask = task({
627627
id: "my-task",
@@ -713,7 +713,7 @@ Trigger.dev Realtime enables subscribing to runs for real-time updates on run st
713713
Subscribe to a run after triggering a task:
714714

715715
```ts
716-
import { runs, tasks } from "@trigger.dev/sdk/v3";
716+
import { runs, tasks } from "@trigger.dev/sdk";
717717

718718
async function myBackend() {
719719
const handle = await tasks.trigger("my-task", { some: "data" });
@@ -735,7 +735,7 @@ async function myBackend() {
735735
You can infer types of run's payload and output by passing the task type:
736736

737737
```ts
738-
import { runs } from "@trigger.dev/sdk/v3";
738+
import { runs } from "@trigger.dev/sdk";
739739
import type { myTask } from "./trigger/my-task";
740740

741741
for await (const run of runs.subscribeToRun<typeof myTask>(handle.id)) {
@@ -752,7 +752,7 @@ for await (const run of runs.subscribeToRun<typeof myTask>(handle.id)) {
752752
Stream data in realtime from inside your tasks using the metadata system:
753753

754754
```ts
755-
import { task, metadata } from "@trigger.dev/sdk/v3";
755+
import { task, metadata } from "@trigger.dev/sdk";
756756
import OpenAI from "openai";
757757

758758
export type STREAMS = {
@@ -947,7 +947,7 @@ For most use cases, Realtime hooks are preferred over SWR hooks with polling due
947947
For client-side usage, generate a public access token with appropriate scopes:
948948

949949
```ts
950-
import { auth } from "@trigger.dev/sdk/v3";
950+
import { auth } from "@trigger.dev/sdk";
951951

952952
const publicToken = await auth.createPublicToken({
953953
scopes: {
@@ -967,7 +967,7 @@ Idempotency ensures that an operation produces the same result when called multi
967967
Provide an `idempotencyKey` when triggering a task to ensure it runs only once with that key:
968968

969969
```ts
970-
import { idempotencyKeys, task } from "@trigger.dev/sdk/v3";
970+
import { idempotencyKeys, task } from "@trigger.dev/sdk";
971971

972972
export const myTask = task({
973973
id: "my-task",
@@ -1058,7 +1058,7 @@ function hash(payload: any): string {
10581058

10591059
```ts
10601060
// onFailure executes after all retries are exhausted; use for notifications, logging, or side effects on final failure:
1061-
import { task, logger } from "@trigger.dev/sdk/v3";
1061+
import { task, logger } from "@trigger.dev/sdk";
10621062

10631063
export const loggingExample = task({
10641064
id: "logging-example",
@@ -1078,7 +1078,7 @@ export const loggingExample = task({
10781078
The `trigger.config.ts` file configures your Trigger.dev project, specifying task locations, retry settings, telemetry, and build options.
10791079

10801080
```ts
1081-
import { defineConfig } from "@trigger.dev/sdk/v3";
1081+
import { defineConfig } from "@trigger.dev/sdk";
10821082

10831083
export default defineConfig({
10841084
project: "<project ref>",
@@ -1226,7 +1226,7 @@ await myTask.trigger({ name: "Alice", age: 30 });
12261226

12271227
Before generating any code, you MUST verify:
12281228

1229-
1. Are you importing from `@trigger.dev/sdk/v3`? If not, STOP and FIX.
1229+
1. Are you importing from `@trigger.dev/sdk` (NOT `@trigger.dev/sdk/v3`)? If not, STOP and FIX.
12301230
2. Have you exported every task? If not, STOP and FIX.
12311231
3. Have you generated any DEPRECATED code patterns? If yes, STOP and FIX.
12321232

docs/docs.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
"realtime/run-object",
138138
"realtime/auth",
139139
{
140-
"group": "React hooks (frontend)",
140+
"group": "React hooks",
141141
"pages": [
142142
"realtime/react-hooks/overview",
143143
"realtime/react-hooks/triggering",
@@ -642,6 +642,10 @@
642642
"source": "/trigger-config",
643643
"destination": "/config/config-file"
644644
},
645+
{
646+
"source": "/guides/frameworks",
647+
"destination": "/guides/frameworks/nextjs"
648+
},
645649
{
646650
"source": "/guides/frameworks/introduction",
647651
"destination": "/guides/introduction"

docs/errors-retrying.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ You can configure retrying in two ways:
1212
1. In your [trigger.config file](/config/config-file) you can set the default retrying behavior for all tasks.
1313
2. On each task you can set the retrying behavior.
1414

15+
<Note>Task-level retry settings override the defaults in your `trigger.config` file.</Note>
16+
1517
<Note>
1618
By default when you create your project using the CLI init command we disabled retrying in the DEV
1719
environment. You can enable it in your [trigger.config file](/config/config-file).

docs/guides/frameworks/nextjs.mdx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ For more information on authenticating with Trigger.dev, see the [API keys page]
4545

4646
## Triggering your task in Next.js
4747

48-
Here are the steps to trigger your task in the Next.js App and Pages router and Server Actions. Alternatively, check out this repo for a [full working example](https://github.com/triggerdotdev/example-projects/tree/main/nextjs/server-actions/my-app) of a Next.js app with a Trigger.dev task triggered using a Server Action.
48+
Here are the steps to trigger your task in the Next.js App and Pages router and Server Actions.
4949

5050
<Tabs>
5151

@@ -432,5 +432,18 @@ You can test your revalidation task in the Trigger.dev dashboard on the testing
432432
<NextjsTroubleshootingMissingApiKey/>
433433
<NextjsTroubleshootingButtonSyntax/>
434434

435+
## Realtime updates with React hooks
436+
437+
The `@trigger.dev/react-hooks` package lets you subscribe to task runs from your React components. Show progress bars, stream AI responses, or display run status in real time.
438+
439+
<CardGroup cols={2}>
440+
<Card title="React hooks" icon="react" href="/realtime/react-hooks/overview">
441+
Hooks for subscribing to runs, streaming data, and triggering tasks from the frontend.
442+
</Card>
443+
<Card title="Streams" icon="wave-pulse" href="/tasks/streams">
444+
Pipe continuous data (like AI completions) from your tasks to the client while they run.
445+
</Card>
446+
</CardGroup>
447+
435448
<VercelDocsCards />
436449
<UsefulNextSteps />

docs/guides/frameworks/remix.mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,19 @@ The `vercel-build` script in `package.json` is specific to Remix projects on Ver
197197

198198
The `runtime: "edge"` configuration in the API route allows for better performance on Vercel's Edge Network.
199199

200+
## Realtime updates with React hooks
201+
202+
The `@trigger.dev/react-hooks` package lets you subscribe to task runs from your React components. Show progress bars, stream AI responses, or display run status in real time.
203+
204+
<CardGroup cols={2}>
205+
<Card title="React hooks" icon="react" href="/realtime/react-hooks/overview">
206+
Hooks for subscribing to runs, streaming data, and triggering tasks from the frontend.
207+
</Card>
208+
<Card title="Streams" icon="wave-pulse" href="/tasks/streams">
209+
Pipe continuous data (like AI completions) from your tasks to the client while they run.
210+
</Card>
211+
</CardGroup>
212+
200213
## Additional resources for Remix
201214

202215
<Card

docs/quick-start.mdx

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,57 @@
11
---
2-
title: "Quick start"
3-
description: "How to get started in 3 minutes using the CLI and SDK."
2+
title: "Quick start: add Trigger.dev to your project"
3+
sidebarTitle: "Quick start"
4+
description: "Set up Trigger.dev in your existing project in under 3 minutes. Install the SDK, create your first background task, and trigger it from your code."
45
---
56

6-
import CliInitStep from '/snippets/step-cli-init.mdx';
7-
import CliDevStep from '/snippets/step-cli-dev.mdx';
8-
import CliRunTestStep from '/snippets/step-run-test.mdx';
9-
import CliViewRunStep from '/snippets/step-view-run.mdx';
7+
import CliInitStep from "/snippets/step-cli-init.mdx";
8+
import CliDevStep from "/snippets/step-cli-dev.mdx";
9+
import CliRunTestStep from "/snippets/step-run-test.mdx";
10+
import CliViewRunStep from "/snippets/step-view-run.mdx";
1011

12+
## Set up with AI
1113

14+
Using an AI coding assistant? Copy this prompt and paste it into Claude Code, Cursor, Copilot, Windsurf, or any AI tool. It'll handle the setup for you.
1215

16+
<Accordion title="Copy the setup prompt">
17+
18+
```text
19+
Help me add Trigger.dev to this project.
20+
21+
## What to do
22+
23+
1. I need a Trigger.dev account. If I don't have one, point me to https://cloud.trigger.dev to sign up. Wait for me to confirm.
24+
2. Run `npx trigger.dev@latest init` in the project root.
25+
- When it asks about the MCP server, recommend I install it (best DX: gives you direct access to Trigger.dev docs, deploys, and run monitoring).
26+
- Install the "Hello World" example task when prompted.
27+
3. Run `npx trigger.dev@latest dev` to start the dev server.
28+
4. Once the dev server is running, test the example task from the Trigger.dev dashboard.
29+
5. Set TRIGGER_SECRET_KEY in my .env file (or .env.local for Next.js). I can find it on the API Keys page in the dashboard.
30+
6. Ask me what framework I'm using and show me how to trigger the task from my backend code.
31+
32+
If I've already run init and want the MCP server, run: npx trigger.dev@latest install-mcp
33+
34+
## Critical rules
35+
36+
- ALWAYS import from `@trigger.dev/sdk`. NEVER import from `@trigger.dev/sdk/v3`.
37+
- NEVER use `client.defineJob()` — that's the deprecated v2 API.
38+
- Use type-only imports when triggering from backend code to avoid bundling task code:
39+
40+
import type { myTask } from "./trigger/example";
41+
import { tasks } from "@trigger.dev/sdk";
42+
43+
const handle = await tasks.trigger<typeof myTask>("hello-world", { message: "Hello from my app!" });
44+
45+
## When done, point me to
46+
47+
- Writing tasks: https://trigger.dev/docs/tasks/overview
48+
- Real-time updates: https://trigger.dev/docs/realtime/overview
49+
- AI tooling: https://trigger.dev/docs/building-with-ai
50+
```
51+
52+
</Accordion>
53+
54+
## Manual setup
1355

1456
<Steps titleSize="h3">
1557

@@ -26,20 +68,30 @@ Sign up at [Trigger.dev Cloud](https://cloud.trigger.dev) (or [self-host](/open-
2668

2769
</Steps>
2870

71+
## Triggering tasks from your app
72+
73+
The test page in the dashboard is great for verifying your task works. To trigger tasks from your own code, you'll need to set the `TRIGGER_SECRET_KEY` environment variable. Grab it from the API Keys page in the dashboard and add it to your `.env` file.
74+
75+
```bash .env
76+
TRIGGER_SECRET_KEY=tr_dev_...
77+
```
78+
79+
See [Triggering](/triggering) for the full guide, or jump straight to framework-specific setup for [Next.js](/guides/frameworks/nextjs), [Remix](/guides/frameworks/remix), or [Node.js](/guides/frameworks/nodejs).
80+
2981
## Next steps
3082

3183
<CardGroup cols={2}>
3284
<Card title="Building with AI" icon="brain" href="/building-with-ai">
33-
Learn how to build Trigger.dev projects using AI coding assistants
85+
Build Trigger.dev projects using AI coding assistants
3486
</Card>
3587
<Card title="How to trigger your tasks" icon="bolt" href="/triggering">
36-
Learn how to trigger tasks from your code.
88+
Trigger tasks from your backend code
3789
</Card>
3890
<Card title="Writing tasks" icon="wand-magic-sparkles" href="/tasks/overview">
39-
Tasks are the core of Trigger.dev. Learn what they are and how to write them.
91+
Task options, lifecycle hooks, retries, and queues
4092
</Card>
4193
<Card title="Guides and example projects" icon="books" href="/guides/introduction">
42-
Guides and examples for triggering tasks from your code.
94+
Framework guides and working example repos
4395
</Card>
4496

4597
</CardGroup>

docs/realtime/auth.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ By default, auto-generated tokens expire after 15 minutes and have a read scope
141141

142142
See our [triggering documentation](/triggering) for detailed examples of how to trigger tasks and get auto-generated tokens.
143143

144+
<Note>
145+
**Where should I create tokens?** The standard pattern is to create tokens in your backend code (API route, server action) after triggering a task, then pass the token to your frontend. The `handle.publicAccessToken` returned by `tasks.trigger()` already does this for you. You rarely need to create tokens inside a task itself.
146+
</Note>
147+
144148
### Subscribing to runs with Public Access Tokens
145149

146150
Once you have a Public Access Token, you can use it to authenticate requests to the Realtime API in both backend and frontend applications.

docs/realtime/backend/overview.mdx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
---
2-
title: Backend overview
2+
title: "Subscribe to tasks from your backend"
33
sidebarTitle: Overview
4-
description: Using the Trigger.dev realtime API from your backend code
4+
description: "Subscribe to run progress, stream AI output, and react to task status changes from your backend code or other tasks."
55
---
66

77
import RealtimeExamplesCards from "/snippets/realtime-examples-cards.mdx";
88

9-
Use these backend functions to subscribe to runs and streams from your server-side code or other tasks.
9+
**Subscribe to runs from your server-side code or other tasks using async iterators.** Get status updates, metadata changes, and streamed data without polling.
1010

11-
## Overview
11+
## What's available
1212

13-
There are three main categories of functionality:
14-
15-
- **[Subscribe functions](/realtime/backend/subscribe)** - Subscribe to run updates using async iterators
16-
- **[Metadata](/realtime/backend/subscribe#subscribe-to-metadata-updates-from-your-tasks)** - Update and subscribe to run metadata in real-time
17-
- **[Streams](/realtime/backend/streams)** - Read and consume real-time streaming data from your tasks
13+
| Category | What it does | Guide |
14+
|---|---|---|
15+
| **Run updates** | Subscribe to run status, metadata, and tag changes | [Run updates](/realtime/backend/subscribe) |
16+
| **Streaming** | Read AI output, file chunks, or any continuous data from tasks | [Streaming](/realtime/backend/streams) |
1817

1918
<Note>
20-
To learn how to emit streams from your tasks, see our [Realtime Streams](/tasks/streams) documentation.
19+
To learn how to emit streams from your tasks, see [Streaming data from tasks](/tasks/streams).
2120
</Note>
2221

2322
## Authentication

0 commit comments

Comments
 (0)