use std::sync::{Arc, LazyLock};
use promptforge_tool_picker::Model;
use tempfile::TempDir;
use crate::catalog::{Catalog, OnBroken};
use crate::config::Config;
use crate::retrieval::Retrieval;
static MODEL: LazyLock<Model> =
LazyLock::new(|| Model::load().expect("the compiled-in retrieval model loads"));
pub(crate) fn model() -> Model {
MODEL.clone()
}
pub(crate) fn retrieval(catalog: &Catalog) -> Retrieval {
Retrieval::indexed_with(&model(), catalog)
}
pub(crate) fn prompt(name: &str, description: &str) -> String {
format!(
"---\nname: {name}\ndescription: {description}\npromptforge: 1\n---\n\n\
# Test prompt\n\n## Main\n\n```lua\nreturn '{name}'\n```\n"
)
}
pub(crate) struct Prompts {
_dir: TempDir,
pub(crate) config: Arc<Config>,
pub(crate) catalog: Catalog,
}
pub(crate) fn catalog(prompts: &[(&str, &str)]) -> Prompts {
let dir = tempfile::tempdir().expect("create a temporary prompts directory");
for (name, description) in prompts {
std::fs::write(
dir.path().join(format!("{name}.md")),
prompt(name, description),
)
.expect("write the fixture prompt");
}
let prompts = toml::Value::String(dir.path().display().to_string()).to_string();
let config = Config::from_toml_str(&format!(
"[server]\ntoken = \"t\"\n\n\
[gateway]\nurl = \"http://127.0.0.1:8081/v1\"\nkey = \"gw\"\n\n\
[paths]\nprompts = {prompts}\n\n\
[catalog]\ninclude = [\"*.md\"]\n",
))
.expect("the fixture configuration parses");
let catalog =
Catalog::resolve(&config, OnBroken::Reject).expect("the fixture catalog resolves");
Prompts {
_dir: dir,
config: Arc::new(config),
catalog,
}
}
pub(crate) const PROMPTS: &[(&str, &str)] = &[
(
"stakeholder_position",
"Build a stakeholder position report for one entity.",
),
(
"paper_summary",
"Summarize a standards paper and list the open questions it leaves.",
),
(
"meeting_minutes",
"Extract decisions and action items from a meeting transcript.",
),
(
"code_review",
"Review a source file and report each defect with its severity.",
),
(
"release_notes",
"Draft release notes from a range of commits.",
),
(
"translate_text",
"Translate a document into another language.",
),
];