540e1c86a4
Input streams enable sending typed data to executing tasks from external
callers — backends, frontends, or other tasks. This unlocks interactive
use cases like approval UIs, cancel buttons, chat interfaces, and
human-in-the-loop AI workflows where the task needs to receive data
while running.
Three consumption patterns inside a task:
* `.wait()` — Suspend the task until data arrives (process freed, most
efficient)
* `.once()` — Wait for the next message (process stays alive)
* `.on()` — Subscribe to a continuous stream of messages
One send pattern from outside:
* `.send(runId, data)` — Send typed data to a specific run's input
stream
## User-facing API
### Define a typed input stream
```ts
import { streams, task } from "@trigger.dev/sdk";
const approval = streams.input<{ approved: boolean; reviewer: string }>({ id: "approval" });
```
### Consume inside a task
```ts
export const myTask = task({
id: "my-task",
run: async () => {
// Pattern 1: Suspend until data arrives (most efficient — frees the process)
const result = await approval.wait({ timeout: "5m" });
// Pattern 2: Wait for next message (process stays alive)
const data = await approval.once().unwrap();
// Pattern 3: Subscribe to multiple messages
approval.on((data) => { /* handle each message */ });
},
});
```
### Send from outside
```ts
// From a backend (using secret API key)
await approval.send(runId, { approved: true, reviewer: "alice" });
// From a frontend (using public JWT token from trigger response)
const { send } = useInputStreamSend("approval", runId, { accessToken });
send({ approved: true, reviewer: "alice" });
```
---------
Co-authored-by: Claude <noreply@anthropic.com>
71 lines
980 B
Plaintext
71 lines
980 B
Plaintext
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
|
|
|
postgres-data
|
|
# dependencies
|
|
node_modules
|
|
.pnp
|
|
.pnp.js
|
|
|
|
# testing
|
|
coverage
|
|
|
|
# next.js
|
|
.next/
|
|
out/
|
|
dist
|
|
packages/**/dist
|
|
|
|
# vendored bundles (generated during build)
|
|
packages/**/src/**/vendor
|
|
|
|
# Tailwind
|
|
apps/**/styles/tailwind.css
|
|
packages/**/styles/tailwind.css
|
|
|
|
# misc
|
|
.DS_Store
|
|
*.pem
|
|
|
|
# debug
|
|
npm-debug.log*
|
|
yarn-debug.log*
|
|
yarn-error.log*
|
|
|
|
# local env files
|
|
.env
|
|
.env.*
|
|
.docker/*.env
|
|
!.env.example
|
|
|
|
# turbo
|
|
.turbo
|
|
.vercel
|
|
.cache
|
|
.env
|
|
.output
|
|
apps/**/public/build
|
|
.tests-container-id.txt
|
|
.sentryclirc
|
|
.buildt
|
|
|
|
**/tmp/
|
|
/test-results/
|
|
/playwright-report/
|
|
/playwright/.cache/
|
|
|
|
.cosine
|
|
.trigger
|
|
.tshy*
|
|
.yarn
|
|
*.tsbuildinfo
|
|
/packages/cli-v3/src/package.json
|
|
.husky
|
|
/packages/react-hooks/src/package.json
|
|
/packages/core/src/package.json
|
|
/packages/trigger-sdk/src/package.json
|
|
/packages/python/src/package.json
|
|
**/.claude/settings.local.json
|
|
.mcp.log
|
|
.mcp.json
|
|
.cursor/debug.log
|
|
ailogger-output.log |