Launch a session
launchSession combines createSession and run on both cloud and local clients:
session takes the client’s creation options; turn takes the existing run options,
including typed output. Launch waits for prompt acceptance, not work completion. On ACP v1,
acceptance uses the matching user-message echo, falling back to the completion response if the
agent doesn’t echo.
Keep the client alive while using the turn; local work is not detached from the CLI. Cancel
explicitly with session.cancel(). Startup failures after allocation throw
SessionStartupError with sessionId and cause; inspect that session before retrying. Later
execution failures reject turn.
Structured output
Pass a Zod (or any Standard Schema) schema asoutput and the turn resolves to a validated, typed value. A completed reply that doesn’t match
the schema rejects the turn instead of returning bad data. A turn that stops without finishing —
cancelled, refused, or out of tokens — resolves with that stopReason (since 0.0.1-beta.2;
earlier betas rejected with “The turn produced no JSON to validate”): stopReason, text and
events are readable, and reading outcome.output throws, so code that needs the value still
fails loudly.
Zod is an optional dependency:
npm install zod.launchSession:

