Skip to main content

ContextTemplateService

Struct ContextTemplateService 

Source
pub struct ContextTemplateService {
    config: SubcogConfig,
    storage_cache: HashMap<DomainScope, Arc<dyn ContextTemplateStorage>>,
    renderer: TemplateRenderer,
}
Expand description

Service for context template CRUD operations and rendering.

Fields§

§config: SubcogConfig

Full subcog configuration.

§storage_cache: HashMap<DomainScope, Arc<dyn ContextTemplateStorage>>

Cached storage backends per domain.

§renderer: TemplateRenderer

Template renderer instance.

Implementations§

Source§

impl ContextTemplateService

Source

pub fn new() -> Self

Creates a new context template service with default configuration.

Source

pub fn with_config(config: SubcogConfig) -> Self

Creates a new context template service with custom configuration.

Source

fn get_storage( &mut self, domain: DomainScope, ) -> Result<Arc<dyn ContextTemplateStorage>>

Gets the storage backend for a domain scope.

Source

pub fn save( &mut self, template: &ContextTemplate, domain: DomainScope, ) -> Result<(String, u32)>

Saves a context template, auto-incrementing the version.

§Arguments
  • template - The context template to save
  • domain - The domain scope to save in (defaults to User)
§Returns

A tuple of (name, version) for the saved template.

§Errors

Returns an error if:

  • The template name is empty or invalid
  • Storage fails
Source

pub fn save_default( &mut self, template: &ContextTemplate, ) -> Result<(String, u32)>

Saves a context template to the default domain (User).

§Errors

Returns an error if the template name is invalid or storage fails.

Source

pub fn get( &mut self, name: &str, version: Option<u32>, domain: Option<DomainScope>, ) -> Result<Option<ContextTemplate>>

Gets a context template by name and optional version.

§Arguments
  • name - The template name to search for
  • version - Optional version number (None = latest)
  • domain - Optional domain to search (if None, searches User then Project)
§Returns

The context template if found.

§Errors

Returns an error if storage access fails.

Source

pub fn list( &mut self, filter: &ContextTemplateFilter, ) -> Result<Vec<ContextTemplate>>

Lists context templates matching the filter.

Returns only the latest version of each template.

§Errors

Returns an error if storage access fails.

Source

pub fn delete( &mut self, name: &str, version: Option<u32>, domain: DomainScope, ) -> Result<bool>

Deletes a context template by name and optional version.

§Arguments
  • name - The template name to delete
  • version - Optional version (None = delete all versions)
  • domain - The domain scope to delete from
§Returns

true if any versions were deleted.

§Errors

Returns an error if storage access fails.

Source

pub fn get_versions( &mut self, name: &str, domain: DomainScope, ) -> Result<Vec<u32>>

Gets all available versions for a template.

§Errors

Returns an error if storage access fails.

Source

pub fn render_with_memories( &mut self, template_name: &str, version: Option<u32>, memories: &[Memory], statistics: &MemoryStatistics, custom_vars: &HashMap<String, String>, format: Option<OutputFormat>, ) -> Result<RenderResult>

Renders a template with memories and statistics.

This is the main entry point for template rendering. It:

  1. Retrieves the template by name/version
  2. Builds a render context with auto-variables populated
  3. Renders the template with variable substitution and iteration
  4. Converts to the requested output format
§Arguments
  • template_name - Name of the template to render
  • version - Optional version (None = latest)
  • memories - List of memories to include
  • statistics - Memory statistics
  • custom_vars - Custom user-defined variables
  • format - Output format (or None to use template default)
§Returns

A RenderResult containing the rendered output.

§Errors

Returns an error if:

  • Template not found
  • Required user variables not provided
  • Rendering fails
Source

pub fn render_direct( &self, template: &ContextTemplate, memories: &[Memory], statistics: &MemoryStatistics, custom_vars: &HashMap<String, String>, format: Option<OutputFormat>, ) -> Result<String>

Renders a template directly (without loading from storage).

Useful for preview/dry-run scenarios.

§Errors

Returns an error if rendering fails or required variables are missing.

Source

fn build_render_context( &self, memories: &[Memory], statistics: &MemoryStatistics, custom_vars: &HashMap<String, String>, template: &ContextTemplate, ) -> Result<RenderContext>

Builds a render context with auto-variables populated.

Source

pub fn validate(&self, template: &ContextTemplate) -> Result<ValidationResult>

Validates template content without saving.

Checks for:

  • Valid variable syntax
  • Balanced iteration blocks
  • Known auto-variables
§Errors

This function currently does not return errors (returns Ok with validation result).

Trait Implementations§

Source§

impl Default for ContextTemplateService

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

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

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

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

§

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
§

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> 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 = 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.
§

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

§

fn vzip(self) -> V

§

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