Skip to main content

Out

Struct Out 

Source
pub struct Out<'id, Op: Operation> { /* private fields */ }
Expand description

Where a decoder writes one reply. The 'id brand ties it to that one reply: a writer cannot be kept past the decode step that received it.

ⓘ
use rig_core::operation::Completion;
use rig_core::wire::Out;

// A writer cannot be stashed to write into the reply later.
struct Stash(Option<Out<'static, Completion>>);

fn keep<'id>(stash: &mut Stash, out: Out<'id, Completion>) {
    stash.0 = Some(out);
}

Implementations§

Source§

impl<'id> Out<'id, Completion>

Source

pub fn open( &mut self, index: usize, block: Block, item: Value, ) -> Result<(), ProviderError>

Open the provider item at wire index as block: it takes the next position in the reply. item is the item as its first event states it, the base its deltas merge into; Null when the block keeps no provider item. An index already open is an error.

Source

pub fn push( &mut self, index: usize, fragment: &str, ) -> Result<(), ProviderError>

Append a fragment to the open item at index: text, reasoning, or a call’s argument JSON, by the item’s block.

Source

pub fn edit( &mut self, index: usize, edit: impl FnOnce(&mut Value), ) -> Result<(), ProviderError>

Edit the item at index in place: apply a delta with merge, or replace the whole item a provider restates when it finishes. Until the reply ends, an index whose block already closed edits that block’s item: the terminal backfill of a field the provider states only at its end.

Source

pub fn close(&mut self, index: usize) -> Result<(), ProviderError>

Close the item at index the provider never stated complete: its block becomes visible with no native, and an opaque item is kept but does not replay. Empty text and reasoning are dropped, and so is a call with no name. A call’s arguments are read by ToolFunction::parse, so malformed ones never fail the reply; a call that never got an id, or reuses one an earlier call took, gets one rig issues.

Source

pub fn finish(&mut self, index: usize) -> Result<(), ProviderError>

Close the item at index the provider stated complete: Self::close, with the item as assembled becoming the block’s native.

Source

pub fn finish_open(&mut self) -> Result<(), ProviderError>

End every item still open as stated complete, for a wire whose end of reply is the provider’s statement that its items are done.

Source

pub fn whole( &mut self, index: usize, block: Block, item: Value, text: &str, ) -> Result<(), ProviderError>

Open and finish the item at index in one step: a whole block a provider states in one piece, item its provider item and text its text, reasoning, argument JSON or base64 image data.

Source

pub fn order_by_index(&mut self)

Order the response’s blocks by wire index rather than by when they opened, for a wire whose indices are the provider’s item order and whose end may state items it never streamed. Call it before the first item opens; blocks with no wire index go last.

Source

pub fn lead(&mut self, index: usize) -> Result<(), ProviderError>

Hold the open item at index first in the response whenever it opened, for a wire that states one block of the turn apart from its order. Its events keep their arrival order. A turn leads with the first item named.

Source

pub fn restate(&mut self, index: usize, text: &str) -> Result<(), ProviderError>

Replace the text, reasoning or argument JSON of the open item at index with text, the whole of it as the provider restates it at its end. The fragments already streamed stand and nothing more streams for them; the block ends holding text.

Source

pub fn fragment( &mut self, index: Option<usize>, fragment: CallFragment<'_>, ) -> Result<(), ProviderError>

Write one fragment of a tool call the provider streams, opening the call at its first fragment. Its id and name may arrive in any fragment, and the first name it is given stays: the call starts streaming once it names a tool, carrying the argument text held until then, and its end states its id. Calls are told apart by index when the wire gives one. A new id under an index starts a new call once the held call’s arguments are a complete object or when it names a tool: some providers send a fresh id, and no name, with every chunk of one call. Without an index (None, or the wire’s null), a fragment with an unseen id opens a call, and one with no id continues the latest call while its arguments are incomplete.

Source

pub fn announce( &mut self, index: usize, announced: Value, ) -> Result<(), ProviderError>

Arguments the provider announced for the call at index, used only if no fragment arrives.

Source

pub fn fresh_index(&mut self) -> usize

An index no provider item uses, for a wire that indexes nothing.

Source

pub fn run( &mut self, block: Block, fragment: &str, ) -> Result<usize, ProviderError>

A fragment on a wire that marks no item boundaries: it continues the block the last fragment went to while block is the same kind, and otherwise closes that block and opens a new one. Returns the block’s index, for merging its provider item.

Source

pub fn end_run(&mut self) -> Result<(), ProviderError>

Close the block Self::run is extending, if any: output of another kind interleaved it.

Source

pub fn cite(&mut self, index: usize, citation: WireCitation)

Add citation to the text item at wire index, open or ended. Its span is resolved to bytes of the text when the item closes, or at once for an item already closed. A span that does not resolve, or covers other text than its quoted, drops the citation with a warning, as do citations of an item that is not text: a citation never fails a reply.

Source

pub fn set_citations(&mut self, index: usize, citations: Vec<WireCitation>)

Put citations in place of the text item’s own, for a provider that restates them; Self::cite otherwise.

Source§

impl<'id, Op: Operation> Out<'id, Op>

Source

pub fn end(self, end: Op::End) -> Flow

End the reply with what the provider sent at its end. It consumes the writer: nothing is written after the end.

Source

pub fn unknown(&mut self, payload: UnknownPayload)

A payload the provider sent that this decoder does not model. It reaches the consumer as Item::Unknown.

Source§

impl<Op: Operation<Emit = Free>> Out<'_, Op>

Source

pub fn raw(&mut self, raw: Value)

Record the reply’s provider document, the response’s raw. A whole JSON body the transport reported outranks it: a decoder whose reply is not one JSON document records it here.

Only an operation whose decoders build their own events has this. A completion’s raw is what its wire’s Reassembler rebuilds, never what a decoder writes:

ⓘ
use rig_core::operation::Completion;
use rig_core::wire::Out;

fn record(out: &mut Out<'_, Completion>) {
    out.raw(serde_json::json!({ "response_id": "x" }));
}
Source

pub fn event(&mut self, event: Op::Event)

One event of the reply.

Only an operation whose decoders build their own events has this; a completion’s events come from its part handles:

ⓘ
use rig_core::operation::Completion;
use rig_core::streaming::StreamEvent;
use rig_core::wire::Out;

fn reinject(out: &mut Out<'_, Completion>, seen: &StreamEvent) {
    out.event(seen.clone());
}

An event rebuilt from its serialized form is no different:

ⓘ
use rig_core::operation::Completion;
use rig_core::streaming::Transcript;
use rig_core::wire::Out;

fn rebuild(out: &mut Out<'_, Completion>, recorded: serde_json::Value) {
    let Ok(transcript) = Transcript::parse(recorded) else { return };
    for event in transcript.events() {
        out.event(event.clone());
    }
}

Auto Trait Implementations§

§

impl<'id, Op> Freeze for Out<'id, Op>
where &'id Mutex<Shared<Op>>: Freeze,

§

impl<'id, Op> RefUnwindSafe for Out<'id, Op>
where &'id Mutex<Shared<Op>>: RefUnwindSafe,

§

impl<'id, Op> Send for Out<'id, Op>
where &'id Mutex<Shared<Op>>: Send,

§

impl<'id, Op> Sync for Out<'id, Op>
where &'id Mutex<Shared<Op>>: Sync,

§

impl<'id, Op> Unpin for Out<'id, Op>
where &'id Mutex<Shared<Op>>: Unpin,

§

impl<'id, Op> UnsafeUnpin for Out<'id, Op>
where &'id Mutex<Shared<Op>>: UnsafeUnpin,

§

impl<'id, Op> UnwindSafe for Out<'id, Op>
where &'id Mutex<Shared<Op>>: UnwindSafe,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmCompatSend for T
where T: Send,

Source§

impl<T> WasmCompatSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

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

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