Skip to main content

ContentBlock

Enum ContentBlock 

Source
pub enum ContentBlock {
    Text {
        text: String,
        extras: Extras,
    },
    Thinking {
        thinking: String,
        signature: String,
        extras: Extras,
    },
    ToolUse {
        id: String,
        name: String,
        input: Value,
        extras: Extras,
    },
    ToolResult {
        tool_use_id: String,
        content: Value,
        is_error: bool,
        extras: Extras,
    },
    ServerToolUse {
        id: String,
        name: String,
        input: Value,
        extras: Extras,
    },
    ServerToolResult {
        tool_use_id: String,
        content: Value,
        extras: Extras,
    },
    Document {
        source: Value,
        extras: Extras,
    },
    Image {
        source: Value,
        extras: Extras,
    },
    QueuedCommand {
        prompt: Value,
        command_mode: Option<String>,
        source_uuid: Option<String>,
        extras: Extras,
    },
    Unknown {
        type_str: String,
        raw: Value,
    },
}
Expand description

A single block inside an assistant turn’s content array or a user message’s tool-result envelope.

Variants§

§

Text

Plain text from the assistant.

Fields

§text: String

The text payload.

§extras: Extras

Fields of the block’s own object that forge does not model.

§

Thinking

Extended-thinking reasoning block. Present when the model was run in thinking mode.

Fields

§thinking: String

The reasoning text.

§signature: String

Anthropic’s signature for the thinking block.

§extras: Extras

Fields of the block’s own object that forge does not model.

§

ToolUse

The model wants to invoke a tool.

Fields

§id: String

Opaque id Anthropic assigns to this tool invocation.

§name: String

Tool name (e.g. "Edit", "Bash", "mcp__foo__bar").

§input: Value

JSON input the model generated for this tool.

§extras: Extras

Fields of the block’s own object that forge does not model (caller, for one).

§

ToolResult

A tool’s output, sent back to the model in a user turn.

Fields

§tool_use_id: String

The id from the corresponding ToolUse block.

§content: Value

Rendered tool output (often a string, may be a JSON object in the wire).

§is_error: bool

Whether the tool reported failure.

§extras: Extras

Fields of the block’s own object that forge does not model.

§

ServerToolUse

Server-side tool invocation the API executed on the model’s behalf (e.g. advisor, web_search, web_fetch). Surfaces alongside regular ToolUse blocks but the caller never returns a result - the server supplies one in a matching ContentBlock::ServerToolResult. ServerToolUseBlock.

name is a discriminator: typed as the Literal set {"advisor", "web_search", "web_fetch", "code_execution", "bash_code_execution", "text_editor_code_execution", "tool_search_tool_regex", "tool_search_tool_bm25"}. forge-sdk keeps it as String so new server tools don’t require an SDK bump to deserialise.

Fields

§id: String

Opaque id Anthropic assigns to this server-tool invocation.

§name: String

Server-tool name (see type-level docs for the current Literal set).

§input: Value

JSON input the model generated for this call.

§extras: Extras

Fields of the block’s own object that forge does not model.

§

ServerToolResult

Result block for a server-side tool call (wire type advisor_tool_result). Same wire shape as ToolResult but the content dict is opaque - branch on content["type"] to tell which concrete server-tool result schema applies (e.g. advisor_result vs. advisor_redacted_result).

Fields

§tool_use_id: String

The id from the corresponding ContentBlock::ServerToolUse block.

§content: Value

Raw server-tool result payload. Schema depends on the server tool - inspect content["type"] for the concrete shape.

§extras: Extras

Fields of the block’s own object that forge does not model.

§

Document

Document attachment (PDF, etc.) inlined into a user turn. The Anthropic API supports these directly - when the user attaches a file to a Claude Code conversation, the CLI emits {"type":"document","source":{"type":"base64", "media_type":"<mime>","data":"<base64>"}} (or "type":"url" / "type":"text" for the alternate source variants).

source stays a Value rather than a typed struct because Anthropic’s source schema branches on source.type (base64 / url / text / content) and each variant carries different fields - keeping it as a JSON object lets new source types decode without an SDK bump.

Fields

§source: Value

Source of the document - JSON object whose type field discriminates between base64, url, text, content.

§extras: Extras

Fields of the block’s own object that forge does not model.

§

Image

Image attachment (JPEG / PNG / GIF / WEBP) inlined into a user turn. Same shape as ContentBlock::Document but with "type":"image" on the wire. Surfaced when a user pastes or attaches an image in a Claude Code conversation.

Fields

§source: Value

Source of the image - JSON object whose type field discriminates between base64, url, etc.

§extras: Extras

Fields of the block’s own object that forge does not model.

§

QueuedCommand

User input that was typed while a previous turn was in flight and got “queued” by the CLI. Claude Code packages these as queued_command-type content blocks on the next outbound user-message envelope going to the model, so the model sees them as additional context.

Wire shape (from the CLI binary’s gO6 function):

{"type": "queued_command",
 "prompt": "<text or content-block list>",
 "commandMode": "prompt" | "bash",
 "source_uuid": "<optional>",
 ...}

Forge surfaces this so resumed sessions render the queued inputs as user bubbles in the chat. Without it, a session that had mid-turn queued inputs would replay missing those user messages.

Fields

§prompt: Value

The queued user text (or content-block array - kept as Value so list-of-blocks variants pass through cleanly).

§command_mode: Option<String>

Mode the input was submitted in. Typically "prompt"; "bash" for !-prefixed shell commands.

§source_uuid: Option<String>

Source UUID assigned by the CLI when the input was queued. Useful for de-duplication / threading; not load-bearing for rendering.

§extras: Extras

Fields of the block’s own object that forge does not model.

§

Unknown

Forward-compat fallback for content block types forge-sdk doesn’t model explicitly. Callers can branch on type_str + inspect raw - the decoder never errors on an unrecognised block. Mirrors the top-level the SDK’s DecodedLine::Unknown fallback pattern.

Fields

§type_str: String

The unrecognised type field value.

§raw: Value

Full JSON payload for the block.

Trait Implementations§

Source§

impl Clone for ContentBlock

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ContentBlock

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ContentBlock

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for ContentBlock

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ContentBlock

Wire-shape type discriminator used by the custom (de)serialise impls. The discriminator mirrors the original #[serde(tag="type")] layout but lets us fall through to ContentBlock::Unknown for anything we don’t recognise.

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ContentBlock

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more