Skip to content

Commit 6a69681

Browse files
isshaddadTrigger.dev RepoOps
authored andcommitted
docs: fix inaccuracies in realtime pages
Corrects the Realtime docs where they had drifted from the SDK and API. - Run object: the status table now lists the statuses the API actually returns, removes `number` and `ttl` (not on the object), and documents `realtimeStreams` and the boolean status helpers (`isQueued`, `isExecuting`, and the rest). - React hooks: fixes the `useRealtimeRun` example types and loading check, adds the `stopOnCompletion` option and the tag filter options for `useRealtimeRunsWithTag`, and corrects the install command. - Streams: a stream timeout ends the read loop normally instead of throwing, and reads can start at the end of the stream instead of replaying history. - Auth and wait tokens: corrects token expiry defaults and points to `auth.createPublicToken` for custom tokens. - Fixes a broken anchor in "How it works". Mono-RevId: a7c014100e0d82e821ef4423787b99342684a9fb
1 parent b435f81 commit 6a69681

9 files changed

Lines changed: 99 additions & 45 deletions

File tree

‎docs/realtime/auth.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ const { parts } = useRealtimeStream<{ url: string }>(runId, "frames", {
157157

158158
When you [trigger tasks](/triggering) from your backend, the `handle` received includes a `publicAccessToken` field. This token can be used to authenticate real-time requests in your frontend application.
159159

160-
By default, auto-generated tokens expire after 15 minutes and have a read scope for the specific run(s) that were triggered. You can customize the expiration by passing a `publicTokenOptions` object to the trigger function.
160+
Auto-generated tokens expire after 1 hour and have a read scope for the specific run(s) that were triggered. For a different expiration or scopes, create a token yourself with [`auth.createPublicToken`](#creating-public-access-tokens).
161161

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

‎docs/realtime/backend/streams.mdx‎

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,16 @@ async function consumeWithTimeout(runId: string) {
9090
timeoutInSeconds: 120, // Wait up to 2 minutes for data
9191
});
9292

93-
try {
94-
for await (const chunk of stream) {
95-
console.log("Received chunk:", chunk);
96-
}
97-
} catch (error) {
98-
if (error.name === "TimeoutError") {
99-
console.log("Stream timed out");
100-
}
93+
for await (const chunk of stream) {
94+
console.log("Received chunk:", chunk);
10195
}
96+
97+
// The loop ends normally if no data arrives within the timeout
10298
}
10399
```
104100

101+
If no data arrives within `timeoutInSeconds`, the stream closes and the `for await` loop ends without throwing an error. To detect a timeout, track whether you received the chunk you expected to be last.
102+
105103
### Start index
106104

107105
Resume reading from a specific chunk index (useful for reconnection scenarios):
@@ -122,6 +120,25 @@ async function resumeStream(runId: string, lastChunkIndex: number) {
122120
}
123121
```
124122

123+
### Start from latest
124+
125+
Pass `from: "latest"` to start reading at the end of the stream instead of replaying its history. You may still receive the most recent existing chunk before new chunks arrive. The default is `"beginning"`, which replays the full history first. `from` is ignored when `startIndex` is set:
126+
127+
```ts
128+
import { streams } from "@trigger.dev/sdk";
129+
import { aiStream } from "./trigger/streams";
130+
131+
async function watchLive(runId: string) {
132+
const stream = await aiStream.read(runId, {
133+
from: "latest", // Start at the end of the stream instead of replaying history
134+
});
135+
136+
for await (const chunk of stream) {
137+
console.log("Received chunk:", chunk);
138+
}
139+
}
140+
```
141+
125142
### Abort signal
126143

127144
Use an `AbortSignal` to cancel stream reading:
@@ -181,8 +198,6 @@ async function advancedStreamConsumption(runId: string) {
181198
} catch (error) {
182199
if (error.name === "AbortError") {
183200
console.log("Stream was cancelled");
184-
} else if (error.name === "TimeoutError") {
185-
console.log("Stream timed out");
186201
} else {
187202
console.error("Stream error:", error);
188203
}

‎docs/realtime/how-it-works.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ See our [run metadata docs](/runs/metadata) for more on how to write tasks that
8080

8181
You can combine run metadata with the Realtime API to bridge the gap between your trigger.dev tasks and your applications in two ways:
8282

83-
1. Using our [React hooks](/realtime/react-hooks/subscribe#using-metadata) to subscribe to metadata updates and update your UI in real-time.
83+
1. Using our [React hooks](/realtime/react-hooks/subscribe#using-metadata-to-show-progress-in-your-ui) to subscribe to metadata updates and update your UI in real-time.
8484
2. Using our [backend functions](/realtime/backend) to subscribe to metadata updates in your backend.
8585

8686
## Limits

‎docs/realtime/react-hooks/overview.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pnpm add @trigger.dev/react-hooks
2323
```
2424

2525
```bash yarn
26-
yarn install @trigger.dev/react-hooks
26+
yarn add @trigger.dev/react-hooks
2727
```
2828

2929
</CodeGroup>

‎docs/realtime/react-hooks/streams.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ function MyComponent({ runId, publicAccessToken }: { runId: string; publicAccess
466466

467467
### Throttling updates
468468

469-
The `useRealtimeRunWithStreams` hook accepts an `experimental_throttleInMs` option to throttle the updates from the server. This can be useful if you are getting too many updates and want to reduce the number of updates.
469+
The `useRealtimeRunWithStreams` hook accepts a `throttleInMs` option to throttle the updates from the server. This can be useful if you are getting too many updates and want to reduce the number of updates.
470470

471471
```tsx
472472
import { useRealtimeRunWithStreams } from "@trigger.dev/react-hooks";
@@ -480,7 +480,7 @@ export function MyComponent({
480480
}) {
481481
const { run, streams, error } = useRealtimeRunWithStreams(runId, {
482482
accessToken: publicAccessToken,
483-
experimental_throttleInMs: 1000, // Throttle updates to once per second
483+
throttleInMs: 1000, // Throttle updates to once per second
484484
});
485485

486486
if (error) return <div>Error: {error.message}</div>;

‎docs/realtime/react-hooks/subscribe.mdx‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ export function RunStatusBadge({
119119

120120
You can skip any of: `payload`, `output`, `metadata`, `startedAt`, `delayUntil`, `queuedAt`, `expiredAt`, `completedAt`, `number`, `isTest`, `usageDurationMs`, `costInCents`, `baseCostInCents`, `ttl`, `payloadType`, `outputType`, `runTags`, `error`. The `useRealtimeRunsWithTag` hook also accepts a `skipColumns` option in the same way.
121121

122+
By default the hook stops subscribing once the run completes. Pass `stopOnCompletion: false` to keep receiving updates after completion, for example metadata updates from child runs.
123+
124+
```tsx
125+
const { run, error } = useRealtimeRun(runId, {
126+
accessToken: publicAccessToken,
127+
stopOnCompletion: false, // Keep receiving updates after the run completes
128+
});
129+
```
130+
122131
See our [run object reference](/realtime/run-object) for the complete schema and [How it Works documentation](/realtime/how-it-works) for more technical details.
123132

124133
### useRealtimeRunsWithTag
@@ -198,6 +207,14 @@ export function MyComponent({ tag }: { tag: string }) {
198207
}
199208
```
200209

210+
You can also pass an array of tags, and use the `createdAt` option to only subscribe to runs created within a recent period. It accepts a duration string such as `"30m"` or `"1h"` and is applied when the subscription starts. The default and maximum lookback is 24 hours, so longer durations are capped at 24 hours.
211+
212+
```tsx
213+
const { runs, error } = useRealtimeRunsWithTag(["user:123", "report"], {
214+
createdAt: "1h", // Only runs created in the last hour
215+
});
216+
```
217+
201218
### useRealtimeBatch
202219

203220
The `useRealtimeBatch` hook allows you to subscribe to a batch of runs by its the batch ID.
@@ -246,13 +263,12 @@ export function ProgressMonitor({
246263
runId: string;
247264
publicAccessToken: string;
248265
}) {
249-
const { run, error, isLoading } = useRealtimeRun(runId, {
266+
const { run, error } = useRealtimeRun(runId, {
250267
accessToken: publicAccessToken,
251268
});
252269

253-
if (isLoading) return <div>Loading run...</div>;
254270
if (error) return <div>Error: {error.message}</div>;
255-
if (!run) return <div>Run not found</div>;
271+
if (!run) return <div>Loading run...</div>;
256272

257273
const progress = run.metadata?.progress as
258274
| {

‎docs/realtime/react-hooks/triggering.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ export function MyComponent({ publicAccessToken }: { publicAccessToken: string }
8484
accessToken: publicAccessToken, // 👈 this is the "trigger" token
8585
});
8686

87-
// use the handle object to preserve type-safety 👇
88-
const { run, error: realtimeError } = useRealtimeRun(handle, {
87+
// pass the run ID and the task type to preserve type-safety 👇
88+
const { run, error: realtimeError } = useRealtimeRun<typeof myTask>(handle?.id, {
8989
accessToken: handle?.publicAccessToken,
9090
enabled: !!handle, // Only subscribe to the run if the handle is available
9191
});

‎docs/realtime/react-hooks/use-wait-token.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const token = await wait.createToken({
1515

1616
return {
1717
tokenId: token.id,
18-
publicToken: token.publicAccessToken, // An automatically generated public access token that expires in 1 hour
18+
publicToken: token.publicAccessToken, // An automatically generated public access token that expires in 24 hours
1919
};
2020
```
2121

‎docs/realtime/run-object.mdx‎

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,26 @@ Type-safety is supported for the run object, so you can infer the types of the r
3636
Timestamp when the run was last updated.
3737
</ParamField>
3838

39-
<ParamField path="number" type="number" required>
40-
Sequential number assigned to the run.
41-
</ParamField>
42-
4339
<ParamField path="status" type="RunStatus" required>
4440
Current status of the run.
4541

4642
<Accordion title="RunStatus enum">
4743

48-
| Status | Description |
49-
| -------------------- | --------------------------------------------------------------------------------------------------------- |
50-
| `WAITING_FOR_DEPLOY` | Task hasn't been deployed yet but is waiting to be executed |
51-
| `QUEUED` | Run is waiting to be executed by a worker |
52-
| `EXECUTING` | Run is currently being executed by a worker |
53-
| `REATTEMPTING` | Run has failed and is waiting to be retried |
54-
| `FROZEN` | Run has been paused by the system, and will be resumed by the system |
55-
| `COMPLETED` | Run has been completed successfully |
56-
| `CANCELED` | Run has been canceled by the user |
57-
| `FAILED` | Run has been completed with errors |
58-
| `CRASHED` | Run has crashed and won't be retried, most likely the worker ran out of resources, e.g. memory or storage |
59-
| `INTERRUPTED` | Run was interrupted during execution, mostly this happens in development environments |
60-
| `SYSTEM_FAILURE` | Run has failed to complete, due to an error in the system |
61-
| `DELAYED` | Run has been scheduled to run at a specific time |
62-
| `EXPIRED` | Run has expired and won't be executed |
63-
| `TIMED_OUT` | Run has reached it's maxDuration and has been stopped |
44+
| Status | Description |
45+
| ----------------- | --------------------------------------------------------------------------------------------------------- |
46+
| `PENDING_VERSION` | Run is waiting for a version update because it cannot execute without additional information |
47+
| `QUEUED` | Run is waiting to be executed by a worker |
48+
| `DEQUEUED` | Run has been dequeued and is being sent to a worker to start executing |
49+
| `EXECUTING` | Run is currently being executed by a worker |
50+
| `WAITING` | Run has been paused by the system, and will be resumed by the system |
51+
| `COMPLETED` | Run has been completed successfully |
52+
| `CANCELED` | Run has been canceled by the user |
53+
| `FAILED` | Run has been completed with errors |
54+
| `CRASHED` | Run has crashed and won't be retried, most likely the worker ran out of resources, e.g. memory or storage |
55+
| `SYSTEM_FAILURE` | Run has failed to complete, due to an error in the system |
56+
| `DELAYED` | Run has been scheduled to run at a specific time |
57+
| `EXPIRED` | Run has expired and won't be executed |
58+
| `TIMED_OUT` | Run has reached it's maxDuration and has been stopped |
6459

6560
</Accordion>
6661
</ParamField>
@@ -89,10 +84,6 @@ Type-safety is supported for the run object, so you can infer the types of the r
8984
Timestamp when the run expired.
9085
</ParamField>
9186

92-
<ParamField path="ttl" type="string">
93-
Time-to-live duration for the run.
94-
</ParamField>
95-
9687
<ParamField path="finishedAt" type="Date">
9788
Timestamp when the run finished.
9889
</ParamField>
@@ -121,6 +112,38 @@ Type-safety is supported for the run object, so you can infer the types of the r
121112
Indicates whether this is a test run.
122113
</ParamField>
123114

115+
<ParamField path="realtimeStreams" type="string[]" required>
116+
Names of the Realtime streams on the run.
117+
</ParamField>
118+
119+
<ParamField path="isQueued" type="boolean" required>
120+
`true` if the run is queued, delayed or waiting for a version update.
121+
</ParamField>
122+
123+
<ParamField path="isExecuting" type="boolean" required>
124+
`true` if the run is dequeued or executing.
125+
</ParamField>
126+
127+
<ParamField path="isWaiting" type="boolean" required>
128+
`true` if the run is waiting.
129+
</ParamField>
130+
131+
<ParamField path="isCompleted" type="boolean" required>
132+
`true` if the run has finished, either successfully or with any failure status.
133+
</ParamField>
134+
135+
<ParamField path="isFailed" type="boolean" required>
136+
`true` if the run failed, crashed, hit a system failure, expired or timed out.
137+
</ParamField>
138+
139+
<ParamField path="isSuccess" type="boolean" required>
140+
`true` if the run completed successfully.
141+
</ParamField>
142+
143+
<ParamField path="isCancelled" type="boolean" required>
144+
`true` if the run was canceled.
145+
</ParamField>
146+
124147
## Type-safety
125148

126149
You can infer the types of the run's payload and output by passing the type of the task to the `subscribeToRun` function. This will give you type-safe access to the run's payload and output.

0 commit comments

Comments
 (0)