SDK Streaming
Streaming improves user trust by showing progress during long-running actions.
Step 1: Start an Operation
Create a run or long task using the SDK.
const run = await client.runs.create({ projectId, goal: "Generate release notes" });
Step 2: Subscribe to Progress Events
const stream = client.runs.stream(run.id);
for await (const event of stream) {
console.log(event.type, event.data);
}
Step 3: Render Progress in UI
- Show current status.
- Append intermediate output as it arrives.
- Mark completion or failure explicitly.
Step 4: Handle Interruptions
- Reconnect when network drops.
- Guard against duplicate event rendering.
- Persist final status server-side.
Step 5: Close the Loop
On completion, refresh related project data and store final artifacts.