//! Stable error surface of Story 3.16 (FR-18): pinned Prompt dependencies. //! //! Every refusal names only the code, the exact `source_path` of the definition array and the //! pinned identity (`resource_id`, `version`) — never content, name or workspace. use serde_json::json; use super::ApiError; const UNRESOLVED: &str = "prompt_dependency_unresolved"; const UNSUPPORTED: &str = "prompt_dependency_representation_unsupported"; const UNUSED: &str = "prompt_dependency_unused"; const UNAVAILABLE: &str = "prompt_dependency_unavailable"; pub(crate) fn unresolved(resource_id: String, version: u32, position: usize) -> ApiError { ApiError::conflict_with_context( "a pinned prompt dependency cannot be resolved", json!({ "error_code": UNRESOLVED, "source_path": source_path(position), "resource_id": resource_id, "version": version, }), ) } pub(crate) fn representation_unsupported( resource_id: String, version: u32, position: usize, ) -> ApiError { ApiError::validation_with_context( "a pinned prompt dependency has no message representation", json!({ "error_code": UNSUPPORTED, "source_path": source_path(position), "resource_id": resource_id, "version": version, }), ) } pub(crate) fn unused(resource_id: String, version: u32, position: usize) -> ApiError { ApiError::validation_with_context( "a pinned prompt dependency is not referenced by any message", json!({ "error_code": UNUSED, "source_path": source_path(position), "resource_id": resource_id, "version": version, }), ) } pub(crate) fn unavailable(position: usize) -> ApiError { ApiError::service_unavailable_with_context( "a pinned prompt dependency is unavailable", json!({ "error_code": UNAVAILABLE, "source_path": source_path(position) }), ) } /// Exact definition path of one pinned dependency (`dependencies[i]`). pub(crate) fn source_path(position: usize) -> String { format!("dependencies[{position}]") } /// Template-level finding of the bounded scan (contract §5): the matched text is never carried. pub(crate) fn template_finding(code: &'static str, source_path: String) -> ApiError { ApiError::validation_with_context( "the prompt template text is refused by the bounded scan", json!({ "error_code": code, "source_path": source_path }), ) } /// Read-time finding inside dynamic dependency content (contract §5). pub(crate) fn dependency_finding(code: &'static str, position: usize) -> ApiError { template_finding(code, source_path(position)) }