Skip to content

Commit 034ea03

Browse files
claudeericallam
authored andcommitted
docs: version input streams under 4.4.2 and add docs site pages
Move input streams documentation from rules/4.3.0 to rules/4.4.2, reverting 4.3.0 to its pre-input-streams state. Add comprehensive input streams documentation to the Mintlify docs site with pages for task-side usage, backend sending, and React hook patterns. - rules/4.4.2/realtime.md: input streams docs (moved from 4.3.0) - rules/manifest.json: add 4.4.2 version, revert 4.3.0 realtime - docs/tasks/input-streams.mdx: main input streams guide - docs/realtime/backend/input-streams.mdx: backend sending patterns - docs/realtime/react-hooks/input-streams.mdx: React UI patterns - docs/docs.json: add input streams to navigation - Cross-references from existing streams and realtime overview docs https://claude.ai/code/session_01SJHJts7r2yAxmoKLLz8vpc
1 parent c2b341f commit 034ea03

File tree

1 file changed

+151
-0
lines changed

1 file changed

+151
-0
lines changed

docs/realtime/backend/input-streams.mdx

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<<<<<<< ours
12
---
23
title: Input Streams
34
sidebarTitle: Input Streams
@@ -149,3 +150,153 @@ try {
149150
- You cannot send data to a completed, failed, or canceled run
150151
- Data sent before a listener is registered inside the task is **buffered** and delivered when a listener attaches
151152
- Input streams require [Realtime Streams v2](/tasks/streams#enabling-streams-v2) (enabled by default in SDK 4.1.0+)
153+
|||||||
154+
=======
155+
---
156+
title: Input Streams
157+
sidebarTitle: Input Streams
158+
description: Send data into running tasks from your backend code
159+
---
160+
161+
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.
162+
163+
<Note>
164+
To learn how to receive input stream data inside your tasks, see our [Input Streams](/tasks/input-streams) documentation. For frontend applications using React, see our [React hooks input streams documentation](/realtime/react-hooks/input-streams).
165+
</Note>
166+
167+
## Sending data to a running task
168+
169+
### Using defined input streams (Recommended)
170+
171+
The recommended approach is to use [defined input streams](/tasks/input-streams#defining-input-streams) for full type safety:
172+
173+
```ts
174+
import { cancelSignal, approval } from "./trigger/streams";
175+
176+
// Cancel a running AI stream
177+
await cancelSignal.send(runId, { reason: "User clicked stop" });
178+
179+
// Approve a draft
180+
await approval.send(runId, { approved: true, reviewer: "alice@example.com" });
181+
```
182+
183+
The `.send()` method is fully typed the data parameter must match the generic type you defined on the input stream.
184+
185+
## Practical examples
186+
187+
### Cancel from a Next.js API route
188+
189+
```ts app/api/cancel/route.ts
190+
import { cancelStream } from "@/trigger/streams";
191+
192+
export async function POST(req: Request) {
193+
const { runId } = await req.json();
194+
195+
await cancelStream.send(runId, { reason: "User clicked stop" });
196+
197+
return Response.json({ cancelled: true });
198+
}
199+
```
200+
201+
### Approval workflow API
202+
203+
```ts app/api/approve/route.ts
204+
import { approval } from "@/trigger/streams";
205+
206+
export async function POST(req: Request) {
207+
const { runId, approved, reviewer } = await req.json();
208+
209+
await approval.send(runId, {
210+
approved,
211+
reviewer,
212+
});
213+
214+
return Response.json({ success: true });
215+
}
216+
```
217+
218+
### Remix action handler
219+
220+
```ts app/routes/api.approve.ts
221+
import { json, type ActionFunctionArgs } from "@remix-run/node";
222+
import { approval } from "~/trigger/streams";
223+
224+
export async function action({ request }: ActionFunctionArgs) {
225+
const formData = await request.formData();
226+
const runId = formData.get("runId") as string;
227+
const approved = formData.get("approved") === "true";
228+
const reviewer = formData.get("reviewer") as string;
229+
230+
await approval.send(runId, { approved, reviewer });
231+
232+
return json({ success: true });
233+
}
234+
```
235+
236+
### Express handler
237+
238+
```ts
239+
import express from "express";
240+
import { cancelSignal } from "./trigger/streams";
241+
242+
const app = express();
243+
app.use(express.json());
244+
245+
app.post("/api/cancel", async (req, res) => {
246+
const { runId, reason } = req.body;
247+
248+
await cancelSignal.send(runId, { reason });
249+
250+
res.json({ cancelled: true });
251+
});
252+
```
253+
254+
### Sending from another task
255+
256+
You can send input stream data from one task to another running task:
257+
258+
```ts
259+
import { task } from "@trigger.dev/sdk";
260+
import { approval } from "./streams";
261+
262+
export const reviewerTask = task({
263+
id: "auto-reviewer",
264+
run: async (payload: { targetRunId: string }) => {
265+
// Perform automated review logic...
266+
const isApproved = await performReview();
267+
268+
// Send approval to the waiting task
269+
await approval.send(payload.targetRunId, {
270+
approved: isApproved,
271+
reviewer: "auto-reviewer",
272+
});
273+
},
274+
});
275+
```
276+
277+
## Error handling
278+
279+
The `.send()` method will throw if:
280+
281+
- The run has already completed, failed, or been canceled
282+
- The payload exceeds the 1MB size limit
283+
- The run ID is invalid
284+
285+
```ts
286+
import { cancelSignal } from "./trigger/streams";
287+
288+
try {
289+
await cancelSignal.send(runId, { reason: "User clicked stop" });
290+
} catch (error) {
291+
console.error("Failed to send:", error);
292+
// Handle the error — the run may have already completed
293+
}
294+
```
295+
296+
## Important notes
297+
298+
- Maximum payload size per `.send()` call is **1MB**
299+
- You cannot send data to a completed, failed, or canceled run
300+
- Data sent before a listener is registered inside the task is **buffered** and delivered when a listener attaches
301+
- Input streams require [Realtime Streams v2](/tasks/streams#enabling-streams-v2) (enabled by default in SDK 4.1.0+)
302+
>>>>>>> theirs

0 commit comments

Comments
 (0)