use crate::MangledName;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct CheckedCall {
pub callee: &'static str,
pub example: &'static str,
pub checks: &'static str,
pub alternative: &'static str,
pub answerer: Option<&'static str>,
}
impl CheckedCall {
pub fn sends_schema(&self) -> bool {
self.answerer.is_some()
}
}
pub(crate) fn checked_call(mangled: &MangledName) -> Option<CheckedCall> {
if super::llm::declaration::is_checked_batch(mangled) {
return Some(CheckedCall {
callee: "llm.batch",
example: "llm.batch<Severity>(model, prompts)",
checks: "each model response",
alternative: "call `llm.texts(model, prompts)` for the completion texts",
answerer: Some("the model"),
});
}
if super::llm::declaration::is_checked_call(mangled) {
return Some(CheckedCall {
callee: "llm.call",
example: "llm.call<Severity>(model, prompt)",
checks: "the model's response",
alternative: "call `llm.text(model, prompt)` for the completion text",
answerer: Some("the model"),
});
}
if super::agents::declaration::is_checked_run(mangled) {
return Some(CheckedCall {
callee: "agents.run",
example: "agents.run<Report>(agent, input)",
checks: "the agent's result",
alternative: "call `agents.runText(agent, input)` for the answer as text",
answerer: Some("the agent"),
});
}
if super::session::declaration::is_checked_get(mangled) {
return Some(CheckedCall {
callee: "session.get",
example: "session.get<Progress>(key)",
checks: "the stored value",
alternative: "narrow an unchecked `session.get(key)` yourself with a \
runtime-checked `as`: `session.get(key) as Progress`",
answerer: None,
});
}
if super::http::declaration::is_checked_json(mangled) {
return Some(CheckedCall {
callee: "r.json",
example: "r.json<User>()",
checks: "the response body",
alternative: "narrow an unchecked `r.json()` yourself with a runtime-checked \
`as`: `r.json() as User`",
answerer: None,
});
}
None
}