You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 6a69681
Browse filesBrowse the repository at this point in the historyBrowse files
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
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.
159
159
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).
161
161
162
162
See our [triggering documentation](/triggering) for detailed examples of how to trigger tasks and get auto-generated tokens.
Copy file name to clipboardExpand all lines: docs/realtime/backend/streams.mdx
+25-10Lines changed: 25 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -90,18 +90,16 @@ async function consumeWithTimeout(runId: string) {
90
90
timeoutInSeconds: 120, // Wait up to 2 minutes for data
91
91
});
92
92
93
-
try {
94
-
forawait (const chunk ofstream) {
95
-
console.log("Received chunk:", chunk);
96
-
}
97
-
} catch (error) {
98
-
if (error.name==="TimeoutError") {
99
-
console.log("Stream timed out");
100
-
}
93
+
forawait (const chunk ofstream) {
94
+
console.log("Received chunk:", chunk);
101
95
}
96
+
97
+
// The loop ends normally if no data arrives within the timeout
102
98
}
103
99
```
104
100
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
+
105
103
### Start index
106
104
107
105
Resume reading from a specific chunk index (useful for reconnection scenarios):
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
+
asyncfunction watchLive(runId:string) {
132
+
const stream =awaitaiStream.read(runId, {
133
+
from: "latest", // Start at the end of the stream instead of replaying history
134
+
});
135
+
136
+
forawait (const chunk ofstream) {
137
+
console.log("Received chunk:", chunk);
138
+
}
139
+
}
140
+
```
141
+
125
142
### Abort signal
126
143
127
144
Use an `AbortSignal` to cancel stream reading:
@@ -181,8 +198,6 @@ async function advancedStreamConsumption(runId: string) {
Copy file name to clipboardExpand all lines: docs/realtime/how-it-works.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -80,7 +80,7 @@ See our [run metadata docs](/runs/metadata) for more on how to write tasks that
80
80
81
81
You can combine run metadata with the Realtime API to bridge the gap between your trigger.dev tasks and your applications in two ways:
82
82
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.
84
84
2. Using our [backend functions](/realtime/backend) to subscribe to metadata updates in your backend.
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.
Copy file name to clipboardExpand all lines: docs/realtime/react-hooks/subscribe.mdx
+19-3Lines changed: 19 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -119,6 +119,15 @@ export function RunStatusBadge({
119
119
120
120
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.
121
121
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
+
122
131
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.
123
132
124
133
### useRealtimeRunsWithTag
@@ -198,6 +207,14 @@ export function MyComponent({ tag }: { tag: string }) {
198
207
}
199
208
```
200
209
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.
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