diff --git a/README.md b/README.md index 7214268..9bf5a65 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,8 @@ credential, so no project wires its own provider calls. The connector gates nothing in dollars. It holds the provider credentials and subscription token, lends leases, derives optional per-call micro-USD visibility on receipts, and publishes communal monthly caller/model spend alongside the plan's usage windows (`usage_readout`, `claude_usage_readout` on the lease socket, and `plan_quota` on every lease grant) for the minds to read and decide their own burn. The one usage-derived refusal is the provider's own (`ProviderRejected`), repeated until its reset. Status: the `model-connector` crate and the `claude-connector` backend crate and binary are live -(`claude-connector serve|config|ask`); an OpenAI-compatible connector is not written. +(`claude-connector serve|config|ask|lease run`), with `RouterBackend` serving `ClaudeCodeBackend`, +`MessagesBackend`, and `OpenAiChatBackend`. ## Entry points @@ -42,11 +43,11 @@ Crate `crates/model-connector`: Crate `crates/claude-connector` (library and the `claude-connector` binary that wires it to `serve`): -- `RouterBackend` routes each configured `ModelRow` in the CultCache `gamecult.model_connector.connector_config.v4` +- `RouterBackend` is the connector's sole `ProviderBackend` implementation: it routes each configured `ModelRow` in the CultCache `gamecult.model_connector.connector_config.v4` document to its configured `ProviderEntry` (`ProviderWire::AnthropicMessages`, `ProviderWire::OpenAiChat`, or `ProviderWire::ClaudeCodeCli`), enforces per-model `ModelRow` policies (`upstream`, `efforts`, `unset_effort`, `forced_tool_choice`, `output_schema`, `strict_tools`), and isolates `ReasoningState` by provider entry id. -- `ClaudeCodeBackend` implements `ProviderBackend` for `ProviderWire::ClaudeCodeCli` by driving the +- `ClaudeCodeBackend` serves `ProviderWire::ClaudeCodeCli` (dispatched by `RouterBackend`) by driving the unmodified `claude` binary, one child per call, in print stream-json mode with no tools, no MCP servers, no settings sources and the system prompt replaced. Tool-less turns only: a request with tools or a final tool result is refused before any spawn. A request's output schema goes @@ -54,10 +55,10 @@ Crate `crates/claude-connector` (library and the `claude-connector` binary that - Reasoning state is a session handle (`ClaudeCodeHandle`) authenticated with a connector secret and bound to the caller it was minted for; a handle that cannot be proven to match the request and its caller re-seeds from the caller's transcript, and every resume forks. -- `MessagesBackend` implements `ProviderBackend` for `ProviderWire::AnthropicMessages` (one +- `MessagesBackend` serves `ProviderWire::AnthropicMessages` (one non-streaming `POST /v1/messages` per call: tools, tool calls and results, thinking blocks, `cache_control`, and cache read/write usage; optional `x-api-key` credential). `OpenAiChatBackend` - implements `ProviderBackend` for `ProviderWire::OpenAiChat` (non-streaming chat completions with + serves `ProviderWire::OpenAiChat` (non-streaming chat completions with `reasoning_content` replay and `Bearer` credential when configured). Neither HTTP wire has a plan: `plan_quota` comes only from a `ClaudeCodeCli` meter, and only a config with a `ClaudeCodeCli` provider lends token leases. diff --git a/crates/claude-connector/tests/config_document.rs b/crates/claude-connector/tests/config_document.rs index b98a117..02d453f 100644 --- a/crates/claude-connector/tests/config_document.rs +++ b/crates/claude-connector/tests/config_document.rs @@ -214,31 +214,91 @@ fn v2_config_is_refused_at_load() { assert!(matches!(load_config(&path), Err(ConfigError::Store))); } +#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +struct V3ModelRow { + id: String, + provider: String, + upstream: String, + efforts: EffortMap, + unset_effort: Option, + forced_tool_choice: ForcedToolChoice, + output_schema: OutputSchemaSupport, + strict_tools: bool, +} + #[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)] #[cultcache(type = "gamecult.model_connector.connector_config.v3")] struct V3Config { #[cultcache(key = 0)] listen: String, + #[cultcache(key = 1)] + replay_store: PathBuf, + #[cultcache(key = 2)] + max_frame_bytes: usize, + #[cultcache(key = 3)] + max_connections: usize, + #[cultcache(key = 4)] + socket_timeout_ms: u64, + #[cultcache(key = 5)] + max_expiry_skew_ms: u64, + #[cultcache(key = 6)] + providers: Vec, + #[cultcache(key = 7)] + models: Vec, + #[cultcache(key = 8)] + callers: Vec, + #[cultcache(key = 9)] + lease_socket: Option, + #[cultcache(key = 10)] + lease_holders: Vec, + #[cultcache(key = 11)] + lease_max_ms: u64, } #[test] fn v3_config_is_refused_at_load() { + assert_eq!( + ClaudeConnectorConfig::TYPE, + "gamecult.model_connector.connector_config.v4" + ); + let scratch = Scratch::new(); let v3_path = scratch.path("v3.cc"); + let base = valid(); + let v3 = V3Config { + listen: base.listen, + replay_store: base.replay_store, + max_frame_bytes: base.max_frame_bytes, + max_connections: base.max_connections, + socket_timeout_ms: base.socket_timeout_ms, + max_expiry_skew_ms: base.max_expiry_skew_ms, + providers: base.providers, + models: base + .models + .into_iter() + .map(|row| V3ModelRow { + id: row.id, + provider: row.provider, + upstream: row.upstream, + efforts: row.efforts, + unset_effort: row.unset_effort, + forced_tool_choice: row.forced_tool_choice, + output_schema: row.output_schema, + strict_tools: row.strict_tools, + }) + .collect(), + callers: base.callers, + lease_socket: base.lease_socket, + lease_holders: base.lease_holders, + lease_max_ms: base.lease_max_ms, + }; { let mut cache = CultCache::new(); cache.register_entry_type::().unwrap(); cache .add_generic_backing_store(SingleFileMessagePackBackingStore::new(&v3_path)) .unwrap(); - cache - .put( - "runtime".to_string(), - &V3Config { - listen: "127.0.0.1:7443".to_string(), - }, - ) - .unwrap(); + cache.put("runtime".to_string(), &v3).unwrap(); } assert!(matches!(load_config(&v3_path), Err(ConfigError::Store))); @@ -1278,9 +1338,9 @@ fn config_init_and_add_model_price_flags() { "--price-output", "500000", "--price-band", - "MON,tue,Wed:0,1:200000:20000:250000:1000000", + "MON,TUE,Wed:0,1:200000:20000:250000:1000000", "--price-band", - "Thu,FRI,sat,SuN:22,23:150000:15000:0:750000", + "Thu,FRI,SaT,SuN:22,23:150000:15000:0:750000", ], ), ); @@ -1476,6 +1536,21 @@ fn config_init_and_add_model_price_flags() { ], "canary-only-five", ), + ( + &[ + "--price-input", + "1", + "--price-cache-read", + "1", + "--price-cache-write", + "1", + "--price-output", + "1", + "--price-band", + "mon:1:2:3:4:5:canary-seventh", + ], + "canary-seventh", + ), ( &[ "--price-input",