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: SubcogConfigFull subcog configuration.
storage_cache: HashMap<DomainScope, Arc<dyn ContextTemplateStorage>>Cached storage backends per domain.
renderer: TemplateRendererTemplate renderer instance.
Implementations§
Source§impl ContextTemplateService
impl ContextTemplateService
Sourcepub fn with_config(config: SubcogConfig) -> Self
pub fn with_config(config: SubcogConfig) -> Self
Creates a new context template service with custom configuration.
Sourcefn get_storage(
&mut self,
domain: DomainScope,
) -> Result<Arc<dyn ContextTemplateStorage>>
fn get_storage( &mut self, domain: DomainScope, ) -> Result<Arc<dyn ContextTemplateStorage>>
Gets the storage backend for a domain scope.
Sourcepub fn save(
&mut self,
template: &ContextTemplate,
domain: DomainScope,
) -> Result<(String, u32)>
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 savedomain- 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
Sourcepub fn save_default(
&mut self,
template: &ContextTemplate,
) -> Result<(String, u32)>
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.
Sourcepub fn get(
&mut self,
name: &str,
version: Option<u32>,
domain: Option<DomainScope>,
) -> Result<Option<ContextTemplate>>
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 forversion- 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.
Sourcepub fn list(
&mut self,
filter: &ContextTemplateFilter,
) -> Result<Vec<ContextTemplate>>
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.
Sourcepub fn delete(
&mut self,
name: &str,
version: Option<u32>,
domain: DomainScope,
) -> Result<bool>
pub fn delete( &mut self, name: &str, version: Option<u32>, domain: DomainScope, ) -> Result<bool>
Sourcepub fn get_versions(
&mut self,
name: &str,
domain: DomainScope,
) -> Result<Vec<u32>>
pub fn get_versions( &mut self, name: &str, domain: DomainScope, ) -> Result<Vec<u32>>
Sourcepub 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>
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:
- Retrieves the template by name/version
- Builds a render context with auto-variables populated
- Renders the template with variable substitution and iteration
- Converts to the requested output format
§Arguments
template_name- Name of the template to renderversion- Optional version (None = latest)memories- List of memories to includestatistics- Memory statisticscustom_vars- Custom user-defined variablesformat- 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
Sourcepub fn render_direct(
&self,
template: &ContextTemplate,
memories: &[Memory],
statistics: &MemoryStatistics,
custom_vars: &HashMap<String, String>,
format: Option<OutputFormat>,
) -> Result<String>
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.
Sourcefn build_render_context(
&self,
memories: &[Memory],
statistics: &MemoryStatistics,
custom_vars: &HashMap<String, String>,
template: &ContextTemplate,
) -> Result<RenderContext>
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.
Sourcepub fn validate(&self, template: &ContextTemplate) -> Result<ValidationResult>
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§
Auto Trait Implementations§
impl Freeze for ContextTemplateService
impl !RefUnwindSafe for ContextTemplateService
impl Send for ContextTemplateService
impl Sync for ContextTemplateService
impl Unpin for ContextTemplateService
impl !UnwindSafe for ContextTemplateService
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].