Skip to main content

PromptService

Struct PromptService 

Source
pub struct PromptService {
    config: Config,
    subcog_config: Option<SubcogConfig>,
    storage_cache: HashMap<DomainScope, Arc<dyn PromptStorage>>,
}
Expand description

Service for prompt template CRUD operations.

Uses PromptStorageFactory to get domain-scoped storage backends.

Fields§

§config: Config

Simple configuration (for backwards compatibility).

§subcog_config: Option<SubcogConfig>

Full subcog configuration (for storage config).

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

Cached storage backends per domain.

Implementations§

Source§

impl PromptService

Source

pub fn new(config: Config) -> Self

Creates a new prompt service.

Source

pub fn with_subcog_config(subcog_config: SubcogConfig) -> Self

Creates a new prompt service with full subcog configuration.

This allows the service to use storage settings from the config file.

Source

pub fn with_repo_path(self, path: impl Into<PathBuf>) -> Self

Creates a prompt service with a repository path.

Source

pub fn set_repo_path(&mut self, path: impl Into<PathBuf>)

Sets the repository path.

Source

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

Gets the storage backend for a domain scope.

Source

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

Saves or updates a prompt template.

§Arguments
  • template - The prompt template to save
  • domain - The domain scope to save in (defaults to Project)
§Returns

The unique ID of the saved prompt.

§Errors

Returns an error if:

  • The template name is empty or invalid
  • Storage fails
§Example
use subcog::services::PromptService;
use subcog::models::PromptTemplate;
use subcog::storage::index::DomainScope;

let mut service = PromptService::new(Default::default());
let template = PromptTemplate::new("code-review", "Review {{code}}");
let id = service.save(&template, DomainScope::Project)?;
Source

pub fn save_with_enrichment<P: LlmProvider>( &mut self, name: &str, content: &str, domain: DomainScope, options: &SaveOptions, llm: Option<P>, existing: Option<PartialMetadata>, ) -> Result<SaveResult>

Saves a prompt with LLM-powered enrichment.

This method extracts variables from the content, optionally enriches with LLM-generated metadata (descriptions, tags, variable info), and saves the template.

§Arguments
  • name - Prompt name (kebab-case).
  • content - The prompt template content.
  • domain - Domain scope to save in.
  • options - Save options (skip enrichment, dry run).
  • llm - Optional LLM provider for enrichment.
  • existing - Optional existing metadata to preserve.
§Returns

A SaveResult containing the saved template and enrichment status.

§Errors

Returns an error if the name is invalid or storage fails. Enrichment failures are gracefully handled with fallback.

Source

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

Gets a prompt by name, searching domain hierarchy.

Searches in priority order: Project → User → Org

§Arguments
  • name - The prompt name to search for
  • domain - Optional domain to search (if None, searches all)
§Returns

The prompt template if found.

§Errors

Returns an error if storage operations fail.

Source

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

Lists prompts matching the filter.

§Arguments
  • filter - Filter criteria
§Returns

List of matching prompt templates.

§Errors

Returns an error if storage operations fail.

Source

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

Deletes a prompt by name.

§Arguments
  • name - The prompt name to delete
  • domain - The domain scope to delete from
§Returns

true if the prompt was found and deleted.

§Errors

Returns an error if storage operations fail.

Source

pub fn search( &mut self, query: &str, limit: usize, ) -> Result<Vec<PromptTemplate>>

Searches prompts semantically by query.

§Arguments
  • query - The search query
  • limit - Maximum results
§Returns

List of matching prompt templates, ordered by relevance.

§Errors

Returns an error if storage operations fail.

Source

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

Increments the usage count for a prompt.

§Arguments
  • name - The prompt name
  • domain - The domain scope
§Errors

Returns an error if the prompt is not found or storage fails.

Source

fn matches_filter( &self, template: &PromptTemplate, filter: &PromptFilter, ) -> bool

Checks if a template matches the filter.

Source

fn calculate_relevance(&self, template: &PromptTemplate, query: &str) -> f32

Calculates relevance score for search.

Trait Implementations§

Source§

impl Default for PromptService

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