Skip to content

Commit 2f0d2e7

Browse files
committed
Proper docs pass, v2 streams are now the default
1 parent f7876f7 commit 2f0d2e7

File tree

6 files changed

+251
-450
lines changed

6 files changed

+251
-450
lines changed

docs/realtime/backend/input-streams.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ description: Send data into running tasks from your backend code
77
The Input Streams API allows you to send data into running Trigger.dev tasks from your backend code. This enables bidirectional communication — while [output streams](/realtime/backend/streams) let you read data from tasks, input streams let you push data into them.
88

99
<Note>
10-
To learn how to receive input stream data inside your tasks, see our [Input
11-
Streams](/tasks/input-streams) documentation.
10+
To learn how to receive input stream data inside your tasks, see [Input
11+
Streams](/tasks/streams#input-streams) in the Streams doc.
1212
</Note>
1313

1414
## Sending data to a running task
1515

1616
### Using defined input streams (Recommended)
1717

18-
The recommended approach is to use [defined input streams](/tasks/input-streams#defining-input-streams) for full type safety:
18+
The recommended approach is to use [defined input streams](/tasks/streams#defining-input-streams) for full type safety:
1919

2020
```ts
2121
import { cancelSignal, approval } from "./trigger/streams";
@@ -32,7 +32,7 @@ The `.send()` method is fully typed — the data parameter must match the generi
3232
<Note>
3333
`.send()` works the same regardless of how the task is listening — whether it uses `.wait()`
3434
(suspending), `.once()` (non-suspending), or `.on()` (continuous). The sender doesn't need to know
35-
how the task is consuming the data. See [Input Streams](/tasks/input-streams) for details on each
35+
how the task is consuming the data. See [Input Streams](/tasks/streams#input-streams) for details on each
3636
receiving method.
3737
</Note>
3838

@@ -152,4 +152,4 @@ try {
152152
- Maximum payload size per `.send()` call is **1MB**
153153
- You cannot send data to a completed, failed, or canceled run
154154
- Data sent before a listener is registered inside the task is **buffered** and delivered when a listener attaches
155-
- Input streams require [Realtime Streams v2](/tasks/streams#enabling-streams-v2) (enabled by default in SDK 4.1.0+)
155+
- Input streams require the current streams implementation (v2 is the default in SDK 4.1.0+). See [Streams](/tasks/streams) for details.

docs/realtime/react-hooks/streams.mdx

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,70 @@ const { parts, error } = useRealtimeStream<string>(runId, {
151151
});
152152
```
153153

154-
For more information on defining and using streams, see the [Realtime Streams v2](/tasks/streams) documentation.
154+
For more information on defining and using streams, see the [Realtime Streams](/tasks/streams) documentation.
155+
156+
## useInputStreamSend
157+
158+
The `useInputStreamSend` hook lets you send data from your frontend into a running task's [input stream](/tasks/streams#input-streams). Use it for cancel buttons, approval forms, or any UI that needs to push typed data into a running task.
159+
160+
### Basic usage
161+
162+
Pass the input stream's `id` (string), the run ID, and options such as `accessToken`. You typically get `runId` and `accessToken` from the object returned when you trigger the task (e.g. `handle.id`, `handle.publicAccessToken`). The hook returns `send`, `isLoading`, `error`, and `isReady`:
163+
164+
```tsx
165+
"use client";
166+
167+
import { useInputStreamSend } from "@trigger.dev/react-hooks";
168+
import { approval } from "@/trigger/streams";
169+
170+
export function ApprovalForm({
171+
runId,
172+
accessToken,
173+
}: {
174+
runId: string;
175+
accessToken: string;
176+
}) {
177+
const { send, isLoading, isReady } = useInputStreamSend(
178+
approval.id,
179+
runId,
180+
{ accessToken }
181+
);
182+
183+
return (
184+
<button
185+
disabled={!isReady || isLoading}
186+
onClick={() => send({ approved: true, reviewer: "alice" })}
187+
>
188+
Approve
189+
</button>
190+
);
191+
}
192+
```
193+
194+
With a generic for type-safe payloads when not using a defined stream:
195+
196+
```tsx
197+
type ApprovalPayload = { approved: boolean; reviewer: string };
198+
const { send } = useInputStreamSend<ApprovalPayload>("approval", runId, {
199+
accessToken,
200+
});
201+
send({ approved: true, reviewer: "alice" });
202+
```
203+
204+
### Options and return value
205+
206+
- **`streamId`**: The input stream identifier (string). Use the `id` from your defined stream (e.g. `approval.id`) or the same string you used in `streams.input<T>({ id: "approval" })`.
207+
- **`runId`**: The run to send input to. When `runId` is undefined, `isReady` is false and `send` will not trigger.
208+
- **`options`**: `accessToken` (required for client usage), `baseURL` (optional). See [Realtime auth](/realtime/auth) for generating a public access token with the right scopes (e.g. input streams write for that run).
209+
210+
Return value:
211+
212+
- **`send(data)`**: Sends typed data to the input stream. Uses SWR mutation under the hood.
213+
- **`isLoading`**: True while a send is in progress.
214+
- **`error`**: Set if the last send failed.
215+
- **`isReady`**: True when both `runId` and access token are available.
216+
217+
For receiving input stream data inside a task (`.wait()`, `.once()`, `.on()`), see [Input Streams](/tasks/streams#input-streams) in the Streams doc.
155218

156219
## useRealtimeRunWithStreams
157220

0 commit comments

Comments
 (0)