CoAgent8 - Source API
    Preparing search index...

    Function createCodexStreamCollector

    • Collects validated answers, tool activity, usage and terminal state from codex app-server notifications (protocol of Codex CLI 0.160).

      Parameters

      Returns {
          beginTurn: (id: string) => void;
          initialize: (id: string) => void;
          isTerminal: () => boolean;
          line: (raw: string) => void;
          notify: (method: string, value: unknown) => void;
          snapshot: () => {
              error: ExecutionError
              | undefined;
              initialized: boolean;
              interrupted: boolean;
              output: string;
              terminal: boolean;
              threadId: string | null;
              truncated: boolean;
              turnId: string | null;
              usage:
                  | {
                      inputTokens?: number;
                      outputTokens?: number;
                      source: "provider";
                      totalTokens?: number;
                  }
                  | undefined;
          };
      }

      A collector fed with notifications by the app-server session, whose snapshot is used directly by the production adapter.

      • beginTurn: (id: string) => void
      • initialize: (id: string) => void
      • isTerminal: () => boolean
      • line: (raw: string) => void
      • notify: (method: string, value: unknown) => void
      • snapshot: () => {
            error: ExecutionError
            | undefined;
            initialized: boolean;
            interrupted: boolean;
            output: string;
            terminal: boolean;
            threadId: string | null;
            truncated: boolean;
            turnId: string | null;
            usage:
                | {
                    inputTokens?: number;
                    outputTokens?: number;
                    source: "provider";
                    totalTokens?: number;
                }
                | undefined;
        }

      On malformed notifications for the run's thread or a second terminal event.

      Notifications for other threads (for example sub-agents) are ignored. Private reasoning, raw commands and tool output are discarded. Latest public snapshots replace drafts, including under budget pressure. Truncation is explicit; the adapter returns BUFFER_LIMIT rather than claiming a complete answer. Turn usage is the sum of tokenUsage.last over the turn's thread/tokenUsage/updated notifications, which the server emits once per model request.