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: ConfigSimple 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
impl PromptService
Sourcepub fn with_subcog_config(subcog_config: SubcogConfig) -> Self
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.
Sourcepub fn with_repo_path(self, path: impl Into<PathBuf>) -> Self
pub fn with_repo_path(self, path: impl Into<PathBuf>) -> Self
Creates a prompt service with a repository path.
Sourcepub fn set_repo_path(&mut self, path: impl Into<PathBuf>)
pub fn set_repo_path(&mut self, path: impl Into<PathBuf>)
Sets the repository path.
Sourcefn get_storage(&mut self, domain: DomainScope) -> Result<Arc<dyn PromptStorage>>
fn get_storage(&mut self, domain: DomainScope) -> Result<Arc<dyn PromptStorage>>
Gets the storage backend for a domain scope.
Sourcepub fn save(
&mut self,
template: &PromptTemplate,
domain: DomainScope,
) -> Result<String>
pub fn save( &mut self, template: &PromptTemplate, domain: DomainScope, ) -> Result<String>
Saves or updates a prompt template.
§Arguments
template- The prompt template to savedomain- 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)?;Sourcepub fn save_with_enrichment<P: LlmProvider>(
&mut self,
name: &str,
content: &str,
domain: DomainScope,
options: &SaveOptions,
llm: Option<P>,
existing: Option<PartialMetadata>,
) -> Result<SaveResult>
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.
Sourcepub fn get(
&mut self,
name: &str,
domain: Option<DomainScope>,
) -> Result<Option<PromptTemplate>>
pub fn get( &mut self, name: &str, domain: Option<DomainScope>, ) -> Result<Option<PromptTemplate>>
Sourcepub fn list(&mut self, filter: &PromptFilter) -> Result<Vec<PromptTemplate>>
pub fn list(&mut self, filter: &PromptFilter) -> Result<Vec<PromptTemplate>>
Sourcepub fn increment_usage(&mut self, name: &str, domain: DomainScope) -> Result<()>
pub fn increment_usage(&mut self, name: &str, domain: DomainScope) -> Result<()>
Sourcefn matches_filter(
&self,
template: &PromptTemplate,
filter: &PromptFilter,
) -> bool
fn matches_filter( &self, template: &PromptTemplate, filter: &PromptFilter, ) -> bool
Checks if a template matches the filter.
Sourcefn calculate_relevance(&self, template: &PromptTemplate, query: &str) -> f32
fn calculate_relevance(&self, template: &PromptTemplate, query: &str) -> f32
Calculates relevance score for search.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PromptService
impl !RefUnwindSafe for PromptService
impl Send for PromptService
impl Sync for PromptService
impl Unpin for PromptService
impl !UnwindSafe for PromptService
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].