Expand description
aphrodite - Reverse proxy with Chat Completions API support.
Two modes:
- Cache (:9797): In-memory CCR, lightweight compression, no tool injection. Passes most content through, only compresses very large outputs (>8KB).
- Token (:9798): SQLite CCR, aggressive compression, tool injection, tool relay for bidirectional Hermes communication.
Chat Completions API:
- Forwards POST /v1/chat/completions to DeepSeek
- Intercepts responses, compresses tool output via CCR
- Does NOT inject the aphrodite_retrieve tool definition into response
tool_calls (that was tried and reverted - see Bug 18 in
compress_chat_completion); the Python plugin registers the tool instead.
Structs§
- AppState
- Shared proxy state: upstream client config, CCR backend, and all
counters/caches used by request handlers. Wrapped in
Arcand cloned into every axum handler. - CcrCreate
Request - Inbound request body for
POST /ccr/create: storecontentunder an optional caller-suppliedkey(defaults to the content hash). - CcrCreate
Response - Response for
POST /ccr/create, reporting the resulting hash and the size reduction achieved. - CcrNotification
- Webhook payload POSTed to
notify_urlwhen a new CCR entry is created, so external subscribers (e.g. Hermes) can track store growth without polling. - Resolved
Thresholds - Live-resolved compression thresholds (report 07 F2/F4/T15): env var >
TOML
[compression]value > compiled-in default, the same precedence patternapply_port_overridealready uses for the listen port. Computed once at startup (build_state) and re-computed on every hot-reload (config-file watcher +POST /reload) so both actually change the live proxy instead of only re-parsing and logging. - Secret
- API key wrapper with safe Debug and Display - never leaks to logs.
- Tool
Relay Request - Inbound request body for
POST /tool_relay: a Hermes-side tool call to execute against this proxy’s CCR state (e.g.aphrodite_retrieve). - Tool
Relay Response - Response for a tool relay call. When
callback_urlwas set on the request, the call runs asynchronously and this comes back immediately withasync_call:trueand noresult- the real result is POSTed to the callback URL later.
Functions§
- build_
state - Construct
AppStatefrom CLI config: builds the tuned HTTP client, opens the CCR backend appropriate forcli.mode(SQLite for Token, in-memory for Cache), and zeroes all counters. - handle_
ccr_ create POST /ccr/create- stores content directly into the CCR backend, bypassing the Chat Completions compression path. Accepts either a JSONCcrCreateRequestbody or a raw octet-stream (treated as the content itself, hashed for the key). Fires thenotify_urlwebhook on success if configured.- handle_
ccr_ delete DELETE /ccr/:hash- removes a single entry from the CCR backend. Returns 404 if the hash wasn’t present, 503 if no backend is configured.- handle_
ccr_ list GET /ccr/list- reports entry count and backend kind for the active CCR store (no listing of actual entries/hashes).- handle_
ccr_ reload - Hot-reload aphrodite.toml and apply compression config changes.
POST /reload - returns the newly loaded compression settings.
POST /reload- re-parseaphrodite.tomland apply its[compression]thresholds to THIS listener’s liveAppState(report 07 F2/F4/T15) - previously this endpoint parsed the file, echoed the values back, and discarded them; a 200 response with"reloaded": trueasserted a state change that never happened. Other[compression]keys (engine_threshold_pct,catalog_mode,auto_expand*) have no consumer in this crate’s proxy path (they’re echoed for visibility, not applied - see report 07 F8/F9 for their fate). - handle_
tool_ relay POST /tool_relay- dispatches a Hermes-side tool call (see [execute_tool_relay]). Runs synchronously unless the request carries anhttps://callback_url, in which case it’s spawned ontotask_trackerand the result is POSTed back later instead of returned inline.- health_
check GET /health- local-only liveness check; does not call the upstream API (see/health/upstreamfor that). Always returns 200 - capability state (e.g. whether CCR is enabled) is conveyed via the JSON body instead of the status code, since CCR is optional/opt-in.- proxy_
handler - Catch-all proxy handler - forwards any request to DeepSeek. Specifically handles Chat Completions API at /v1/chat/completions.
- resolve_
thresholds - Resolve the four compression thresholds from env vars, the TOML
[compression]table (if any), and the compiled-in defaults, in that precedence order.