ailoy-web
    Preparing search index...

    Interface MessageDelta

    A streaming, incremental update to a [Message].

    MessageDelta accumulates partial outputs (text chunks, tool-call fragments, IDs, signatures, etc.) until they can be materialized as a full [Message]. It implements [Delta] to support accumulation.

    Accumulation Rules

    • role: merging two distinct roles fails.
    • thinking: concatenated in arrival order.
    • contents/tool_calls: last element is accumulated with the incoming delta when both are compatible (e.g., Text+Text, Function+Function with matching ID policy), otherwise appended as a new fragment.
    • id/signature: last-writer-wins.

    Finalization

    • finish() converts the accumulated deltas into a fully-formed [Message]. Fails if required fields (e.g., role) are missing or inner deltas cannot be finalized.

    Examples

    let d1 = MessageDelta::new().with_role(Role::Assistant).with_contents([PartDelta::Text { text: \"Hel\".into() }]);
    let d2 = MessageDelta::new().with_contents([PartDelta::Text { text: \"lo\".into() }]);

    let merged = d1.accumulate(d2).unwrap();
    let msg = merged.finish().unwrap();
    assert_eq!(msg.contents[0].as_text().unwrap(), \"Hello\");
    interface MessageDelta {
        contents: PartDelta[];
        id?: string;
        role?: Role;
        signature?: string;
        thinking?: string;
        tool_calls: PartDelta[];
    }
    Index

    Properties

    contents: PartDelta[]
    id?: string
    role?: Role
    signature?: string
    thinking?: string
    tool_calls: PartDelta[]