Sessions
Sessions are communication channels between your AI agent and human recipients, backed by real-time WebSocket connections. For method details, see the TypeScript SDK reference.
Lifecycle
- Create —
client.sessions.create()opens a WebSocket and returns aSessionobject - Interact —
session.log()sends updates,session.ask()blocks for human input - Close —
session.close()cleans up the WebSocket connection - Resume —
client.sessions.resume(id)reconnects to an existing session - Expire — Session data is deleted after the retention period (default: 1 month, up to 12 on Pro)
Session data persists until expiry. Closing only disconnects the WebSocket — you can resume later.
Log vs Ask
Log is fire-and-forget. Use it for progress updates:
await session.log("Processing step 1 of 3...");await session.log("Scanning files...", { persist: false }); // ephemeralAsk blocks until a recipient responds. Requires at least one recipient:
const { approved } = await session.ask("Deploy?", { inputs: [{ type: "confirm", name: "approved" }] as const,});Typed Inputs
ask() supports three input types. Use as const to get inferred response types:
| Type | Response Type | Use Case |
|---|---|---|
text | string | Free-form input |
confirm | boolean | Yes/no decisions |
select | string or string[] | Choose from options |
Combine multiple inputs in a single ask. See Input Types for all options.
Markdown Support
Message content supports GitHub-flavored Markdown:
await session.ask( `## Summary\n| File | Changes |\n|------|--------|\n| index.ts | +50 |`, { inputs: [{ type: "confirm", name: "approved" }] as const });Timeout Handling
ask() times out after 5 minutes by default. Customize with the timeout option:
import { TimeoutError } from "@justack/sdk";
try { const response = await session.ask("Approve?", { inputs: [{ type: "confirm", name: "ok" }] as const, timeout: 60000, // 1 minute });} catch (error) { if (error instanceof TimeoutError) { // handle timeout }}Next Steps
- Recipients Guide — Multi-recipient patterns
- Callbacks Guide — Async notifications
- TypeScript SDK — Full method reference