Files
hermes-agent 0c4e29b174 feat(client): add success_callback hook for application-side observation
Wires a single typed callback into Client::messages() that fires once per
successful completion, carrying the original Anthropic request, the
translated Anthropic response, the resolved backend model, wall-clock
duration, and (when pricing is configured) computed cost_usd.

Pattern borrowed from litelm's v0.5.0 success_callback design (single hook,
post-success, sync). Documented as 'Adopt' in docs/COMPARISON_LITELM.md.

Design:
- one hook, fires on success only (not streaming, not failures)
- callback runs sync on the calling task; panics caught and logged
- pricing is opt-in (PricingConfig); no bundled DB in the SDK
- per-Client: cloned Clients share the callback (Arc<CallbackContext>)
- end-to-end test backend is a TcpListener, no new dev-deps

Tests (9 in crates/client/src/client/tests/callback_tests.rs):
- callback_fires_with_input_and_response
- callback_not_called_on_transport_error
- callback_not_called_on_api_error_status
- callback_panic_does_not_break_call
- callback_cost_usd_uses_pricing_map
- callback_cost_usd_none_when_model_unknown
- callback_cost_usd_none_when_pricing_not_configured
- callback_is_shared_across_cloned_clients
- no_callback_still_works
- public_api_surface_compiles (compile-time witness)

Sabotage run verified: removing self.callbacks.fire(input) makes
callback_fires_with_input_and_response fail with 'left: 0, right: 1'.
2026-09-11 13:56:39 -05:00
..
2026-07-16 20:12:53 -05:00
2026-07-16 20:12:53 -05:00