Polyman Documentation - v3.1.0
    Preparing search index...

    Type Alias StreamEvent

    StreamEvent:
        | { type: "text_delta"; text: string }
        | {
            type: "reasoning_delta";
            text: string;
            signature?: string;
            redacted?: string;
        }
        | {
            type: "tool_call";
            id: string;
            name: string;
            args: unknown;
            argsError?: string;
        }
        | {
            type: "usage";
            inputTokens: number;
            outputTokens: number;
            cachedTokens?: number;
            costUsd?: number;
        }
        | {
            type: "done";
            stopReason: "end"
            | "tool_calls"
            | "max_tokens"
            | "content_filter";
        }

    One event of a streamed model turn.

    A tool_call is emitted only when its arguments are complete. Providers stream arguments in pieces, each in its own way; the adapter collects the pieces and parses the JSON once, so the core never sees partial arguments.

    Type Declaration

    • { type: "text_delta"; text: string }

      A chunk of the answer text.

    • { type: "reasoning_delta"; text: string; signature?: string; redacted?: string }

      A chunk of the model's reasoning. Anthropic ends each thinking block with a reasoning_delta that has its signature (the text may be empty), and gives a redacted thinking block as one reasoning_delta with empty text and redacted data. The loop keeps these on the reasoning part, and starts a new part for the reasoning after them, so each block can be sent back unchanged.

    • {
          type: "tool_call";
          id: string;
          name: string;
          args: unknown;
          argsError?: string;
      }

      A finished tool call, emitted only when its arguments are complete. When the arguments are not valid JSON and could not be fixed, args is the raw string and argsError says why. The loop then sends an error tool result, so the model can try again.

    • {
          type: "usage";
          inputTokens: number;
          outputTokens: number;
          cachedTokens?: number;
          costUsd?: number;
      }

      Token counts for the turn.

    • {
          type: "done";
          stopReason: "end" | "tool_calls" | "max_tokens" | "content_filter";
      }

      The turn is over, and why.