/** * Collects a Codex turn from the JSON-RPC notification stream. * * Adapted from claudemux's `plugins/claudemux/core/src/engines/codex/events.ts`. * We drop `notLoaded` item merging. Feishu * outbound delivery is MCP reply-only, so collected assistant text is for * diagnostics and tests rather than channel forwarding. */ import type { CodexWsClient } from './rpc.js'; import type { ThreadItem, ThreadTokenUsage, TurnStartResponse, TurnStatus } from './types.js'; export interface CollectedTurn { threadId: string; turnId: string; items: ThreadItem[]; /** codex's own terminal for this turn; see {@link TurnStatus}. */ status: TurnStatus; } export interface TurnCollector { /** * Forget a turn's buffered `item/completed` items. `itemsByTurn` has no * size bound of its own (unlike the terminal-id set below): every * `item/completed` notification appends to it, and nothing else ever * deletes an entry, so a long-lived resident collector leaks one array per * native turn it has ever seen unless the caller releases each turn once * it is done with it. */ releaseTurn(turnId: string): void; dispose(): void; } export interface TurnSubscriptionOptions { onTokenUsage?: (usage: ThreadTokenUsage) => void; onItemStarted?: (turnId: string, item: ThreadItem) => void; onItemCompleted?: (turnId: string, item: ThreadItem, occurredAt: number) => void; onTerminal?: (turnId: string, terminal: CollectedTurn | Error) => void; /** * An `error` notification with no `turnId` — a connection-level protocol * failure rather than one turn's failure. The collector stops reacting to * further notifications once this fires: nothing scopes a recovery to a * single turn. */ onUnscopedFailure?: (error: Error) => void; } /** * Subscribe to turn notifications for one thread, pushing each turn's * lifecycle to the given callbacks as codex reports it. Stays subscribed * across successive native turns until `dispose()`. */ export declare function subscribeTurnCollection(client: CodexWsClient, threadId: string, options?: TurnSubscriptionOptions): TurnCollector; /** * Send a `turn/start` request and resolve once Codex accepts the submission. * This is the production Feishu inbound primitive: it intentionally does not * wait for `turn/completed`. */ export declare function submitTurnStart(client: CodexWsClient, threadId: string, texts: string[], outputSchema?: Record, effort?: string): Promise; /** Interrupt one running turn and resolve once Codex accepts the request. */ export declare function interruptTurn(client: CodexWsClient, threadId: string, turnId: string): Promise; /** * Extract the final assistant message text from a collected turn. * Returns null if the turn had no assistant message — caller decides * what to surface to the user (see issue #2 "open questions", Q4). */ export declare function extractAssistantText(turn: CollectedTurn): string | null; //# sourceMappingURL=events.d.ts.map