Skip to main content

Context

Struct Context 

Source
pub struct Context {
    pub scope_value: Option<Value>,
    pub scope_index: usize,
    pub session_id: Option<String>,
    pub stack_info: Option<StackInfo>,
    pub prompts_dir: PathBuf,
    /* private fields */
}
Expand description

Tree-structured context that stores step outputs

Fields§

§scope_value: Option<Value>§scope_index: usize§session_id: Option<String>§stack_info: Option<StackInfo>

Detected stack info for prompt resolution (Story 11.5/11.6)

§prompts_dir: PathBuf

Directory where prompt template files live (defaults to “prompts”)

Implementations§

Source§

impl Context

Source

pub fn new(target: String, vars: HashMap<String, Value>) -> Self

Source

pub fn store(&mut self, name: &str, output: StepOutput)

Store a step output

Source

pub fn get_step(&self, name: &str) -> Option<&StepOutput>

Get a step output (looks in parent if not found locally)

Source

pub fn insert_var(&mut self, name: impl Into<String>, value: Value)

Insert a variable into this context

Source

pub fn get_var(&self, name: &str) -> Option<&Value>

Get a variable

Source

pub fn get_session(&self) -> Option<&str>

Get session ID (searches parent chain)

Source

pub fn store_parsed(&mut self, name: &str, parsed: ParsedValue)

Store a parsed value for a step

Source

pub fn get_parsed(&self, name: &str) -> Option<&ParsedValue>

Get a parsed value for a step (looks in parent if not found locally)

Source

pub fn child( parent: Arc<Context>, scope_value: Option<Value>, index: usize, ) -> Self

Create a child context for a scope

Source

pub fn all_variables(&self) -> HashMap<String, Value>

Get all variables (local + parent chain) merged into a flat HashMap

Source

pub fn get_stack_info(&self) -> Option<&StackInfo>

Get the stack_info from this context or any parent

Source

pub fn get_from_value(&self, name: &str) -> Option<Value>

Get the Tera-ready value for a step by name (used by from() preprocessing). Returns None if the step doesn’t exist in this context or any parent.

Source

pub fn var_exists(&self, path: &str) -> bool

Check if a dotted path variable exists in this context (used for strict accessor)

Source

pub fn get_chat_messages(&self, session: &str) -> Vec<ChatMessage>

Return all stored messages for a chat session (empty vec if session doesn’t exist)

Source

pub fn append_chat_messages(&self, session: &str, messages: Vec<ChatMessage>)

Append messages to a chat session, creating the session if it doesn’t exist

Source

pub fn to_tera_context(&self) -> Context

Convert to Tera template context

Source

pub fn render_template(&self, template: &str) -> Result<String, StepError>

Render a template string with this context

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> 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> 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> 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: 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: 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

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

Source§

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