Skip to main content

max / makenotwork

2.3 KB · 65 lines History Blame Raw
1 use thiserror::Error;
2
3 pub type Result<T> = std::result::Result<T, Error>;
4
5 #[derive(Debug, Error)]
6 pub enum Error {
7 #[error("tool not found: {0}")]
8 ToolNotFound(String),
9
10 #[error("resource not found: {0}")]
11 ResourceNotFound(String),
12
13 /// An in-flight request was cancelled — by the client (`notifications/
14 /// cancelled`) or by the app (a human took the buffer back). The `String`
15 /// is the cancelled request id.
16 #[error("request cancelled: {0}")]
17 Cancelled(String),
18
19 /// App-level argument rejection, raised by a tool for a contract its
20 /// schema can't express (a slug that must already exist, a range that
21 /// depends on other state). Schema-expressible problems are caught before
22 /// the tool runs — see [`Error::InvalidArguments`].
23 #[error("invalid arguments for tool `{tool}`: {message}")]
24 InvalidArgs { tool: String, message: String },
25
26 /// Arguments failed the tool's own `input_schema`, caught by
27 /// [`ToolRegistry::call`](crate::ToolRegistry::call) before dispatch. The
28 /// slots name each offending field, so the agent loop can hand the model a
29 /// diagnostic precise enough to correct in one turn.
30 #[error("invalid arguments for tool `{tool}`: {}", crate::schema::render_slots(.slots))]
31 InvalidArguments {
32 tool: String,
33 slots: Vec<crate::schema::SlotError>,
34 },
35
36 #[error("tool `{tool}` failed: {message}")]
37 ToolFailed { tool: String, message: String },
38
39 /// Registered refusal — the tool exists in the surface but is not offered.
40 /// The `reason` is stable text the model can act on.
41 #[error("tool `{tool}` is not offered: {reason}")]
42 Refused { tool: String, reason: String },
43
44 /// Write tool called without a grant for its capability. Includes a stable
45 /// suffix so small models learn not to retry.
46 #[error("tool `{tool}` requires capability `{capability}` which was not granted; do not retry")]
47 CapabilityDenied { tool: String, capability: String },
48
49 #[error("protocol error: {0}")]
50 Protocol(String),
51
52 #[error("transport error: {0}")]
53 Transport(String),
54
55 #[error(transparent)]
56 Json(#[from] serde_json::Error),
57
58 #[error(transparent)]
59 Io(#[from] std::io::Error),
60
61 #[cfg(feature = "ollama")]
62 #[error(transparent)]
63 Http(#[from] reqwest::Error),
64 }
65