Skip to main content

Module proxy

Module proxy 

Source
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 Arc and cloned into every axum handler.
CcrCreateRequest
Inbound request body for POST /ccr/create: store content under an optional caller-supplied key (defaults to the content hash).
CcrCreateResponse
Response for POST /ccr/create, reporting the resulting hash and the size reduction achieved.
CcrNotification
Webhook payload POSTed to notify_url when a new CCR entry is created, so external subscribers (e.g. Hermes) can track store growth without polling.
ResolvedThresholds
Live-resolved compression thresholds (report 07 F2/F4/T15): env var > TOML [compression] value > compiled-in default, the same precedence pattern apply_port_override already 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.
ToolRelayRequest
Inbound request body for POST /tool_relay: a Hermes-side tool call to execute against this proxy’s CCR state (e.g. aphrodite_retrieve).
ToolRelayResponse
Response for a tool relay call. When callback_url was set on the request, the call runs asynchronously and this comes back immediately with async_call:true and no result - the real result is POSTed to the callback URL later.

Functions§

build_state
Construct AppState from CLI config: builds the tuned HTTP client, opens the CCR backend appropriate for cli.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 JSON CcrCreateRequest body or a raw octet-stream (treated as the content itself, hashed for the key). Fires the notify_url webhook 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-parse aphrodite.toml and apply its [compression] thresholds to THIS listener’s live AppState (report 07 F2/F4/T15) - previously this endpoint parsed the file, echoed the values back, and discarded them; a 200 response with "reloaded": true asserted 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 an https:// callback_url, in which case it’s spawned onto task_tracker and 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/upstream for 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.