sdk, agent: review fixes (T18R)

- The serve loop ends the process after EOF or exit_after_response,
  also with background tasks or listeners.
- One schema generator per direction for the whole document, so types
  with the same name get distinct names.
- The agent gives the complete error (code, message, data) to the
  model, writes SKIP only after a successful request, caps tool output
  at 64 KiB, writes each history line in one write, and skips a damaged
  line.
- Endpoints skip blank and non-RPC lines. client_rs does not panic.
- #[must_use] on builders and the lock guard; #[schemars] attributes
  and duplicate hooks are compile errors; raw identifiers; -32000 for
  local SDK errors; x-sausage-params only for methods with params.
This commit is contained in:
2026-10-23 02:38:35 +01:00
parent d7b78ed0fd
commit c728429d04
29 changed files with 829 additions and 104 deletions
+9 -2
View File
@@ -21,6 +21,11 @@ pub use locks::*;
pub trait Interface: 'static {
/// Describe this interface without constructing its value.
fn describe() -> Value
where
Self: Sized;
/// Add this type's methods to shared document generators.
#[doc(hidden)]
fn add_methods(doc: &mut crate::Discovery)
where
Self: Sized;
/// Describe only this type's methods, without endpoint declarations.
@@ -58,7 +63,7 @@ impl Ctx {
let params = json!({"name":name,"params":params});
if let Some(sink) = &self.sink {
sink.unbounded_send(json!({"jsonrpc":"2.0","method":"core.notify","params":params}))
.map_err(|_| Error::new(-32002, "endpoint closed"))
.map_err(|_| Error::new(-32000, "endpoint closed"))
} else {
notify("core.notify", params)
}
@@ -152,7 +157,7 @@ fn send(value: Value) -> Result<()> {
}
fn notify(method: &str, params: Value) -> Result<()> {
if !STATE.with(|s| s.borrow().active) {
return Err(Error::new(-32002, "no core transport"));
return Err(Error::new(-32000, "no core transport"));
}
send(json!({"jsonrpc":"2.0","method":method,"params":params}))
}
@@ -376,4 +381,6 @@ async fn serve<T: Interface>(value: T) {
s.active = false;
s.pending.clear();
});
let _ = std::io::stdout().flush();
std::process::exit(0);
}