/** * `weft tail ` — stream a workflow's token events as they replay * from the server's Server-Sent Events endpoint (`GET /v1/workflows/:id/sse`). * * Each SSE frame is parsed into a structured event and emitted as one line: * a compact JSON object under `--json` (valid NDJSON), or a TTY-formatted line * otherwise. The stream ends on the server's `done` event, when the connection * closes, or when the caller aborts (Ctrl-C) — all of which resolve cleanly * with exit code 0 rather than leaving the reader hanging. * * The consumer is factored as {@link streamWorkflowEvents} so tests drive it * with an injected `fetch` and `AbortSignal` instead of a real terminal. * * @module cli/tail */ import type { CommandOutput, TailCommand } from './types.ts'; /** A single parsed SSE frame surfaced to the tail sink. */ export type TailEvent = { readonly id?: string; readonly event: string; readonly data: string; }; /** Minimal `fetch` shape the tail consumer needs; lets tests inject a stub. */ export type TailFetch = (url: URL, init: RequestInit) => Promise; /** Dependencies injected into {@link streamWorkflowEvents} for testing. */ export type TailStreamOptions = { readonly url: URL; readonly token?: string; readonly signal: AbortSignal; /** Sink for streamed events (stdout, suppressed under `--quiet`). */ readonly write: (line: string) => void; /** Sink for connection/status errors (stderr, never suppressed). Defaults to `write`. */ readonly reportError?: (line: string) => void; readonly json: boolean; readonly fetchImpl?: TailFetch; }; /** * Connect to the workflow SSE endpoint and emit each frame through `write`. * Resolves when the stream ends, the server emits `done`, or the signal aborts. * Returns the exit code (0 on a clean end/abort, non-zero on a failed connect). */ export declare function streamWorkflowEvents(options: TailStreamOptions): Promise; /** * Execute `weft tail`. Wires the process's SIGINT into an `AbortController` so * Ctrl-C ends the stream cleanly, and writes events to stdout. A bare * `weft tail` with no workflow id is not yet supported (system-wide tail needs * a server-side multiplexed SSE route); it returns a usage error pointing at * the per-workflow form. */ export declare function executeTail(command: TailCommand): Promise;