Skip to main content

RunProgress

Struct RunProgress 

Source
pub struct RunProgress { /* private fields */ }
Expand description

The events of a run so far, folded into where the run is.

Feed it every event of the run in the order they are sent, with observe or replay. It keeps no log: what it holds is what is open, the text each open thing has produced, and the ids the run has used.

It is also the ordering check. With the verify feature, observe rejects what EventVerifier rejects and leaves the fold as it was, so one RunProgress can stand where a server that builds its own events has its verifier. Without the feature nothing is checked and the fold takes what it is given.

A stream may carry several runs in sequence. The progress is then that of the run that is open, or of the last one when none is: a RUN_STARTED after a terminal event begins the next run with nothing open. The runs before it are history, and what they produced is in the conversation.

See the module docs for what a prelude is and how it treats the messages it is given.

Implementations§

Source§

impl RunProgress

Source

pub fn new() -> Self

The progress of a run that has sent nothing yet.

Source

pub fn seed(&mut self, history: &[Message])

Learns the conversation the run continues — the request’s messages — before its first event.

A result in the run may answer a call the history made, which the ordering check has to know of. The fold has to know which ids were in use before the run: a start for one of them adds to a message that already holds something.

Source

pub fn observe(&mut self, event: &Event) -> Result<(), VerificationError>

Checks one event the run is sending, and folds it in.

§Errors

With the verify feature, the rule the event broke. A rejected event was not sent, so it changes nothing here either.

Source

pub fn replay<'a>( &mut self, events: impl IntoIterator<Item = &'a Event>, ) -> Result<(), VerificationError>

Observes the events a run has already sent, in order.

For a server that reads them from its store: when a client joins, or when it takes over a run another process was driving. Afterwards the progress is where the run is, and observe carries on from there.

§Errors

The first event that breaks a rule, as observe reports it. The events before it stay folded in.

Source

pub fn has_started(&self) -> bool

Whether the run has sent its RUN_STARTED: the run that is open, or the last one of a stream that carried several.

Source

pub fn has_ended(&self) -> bool

Whether that run has sent a terminal event, so that no run is open. A client that joins now is sent the prelude alone, until a RUN_STARTED begins the next run.

Source

pub fn open(&self) -> impl Iterator<Item = &OpenEntity>

What the run has open, in the order it was opened.

After RUN_ERROR this is what the run abandoned.

let mut progress = RunProgress::new();
progress.replay(&[
    Event::run_started("thread-1", "run-1"),
    Event::step_started("draft"),
    Event::text_message_start("msg-1", TextMessageRole::Assistant),
    Event::text_message_content("msg-1", "Dear "),
    Event::text_message_content("msg-1", "Ada,"),
])?;

let open: Vec<&OpenEntity> = progress.open().collect();
assert!(matches!(open[0], OpenEntity::Step { start, .. } if start.step_name.as_str() == "draft"));
assert!(matches!(open[1], OpenEntity::Message { content, .. } if content == "Dear Ada,"));
Source

pub fn prelude(&self) -> Prelude<'_>

Starts the prelude for a client that joins the run where it now is.

See the module docs for what it holds. It is empty for a run that has not started: there is nothing to catch up on, and the client reads the run from its first event.

Trait Implementations§

Source§

impl Clone for RunProgress

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 RunProgress

Source§

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

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

impl Default for RunProgress

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

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.

§

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

§

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
§

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