@deslop/gateway 0.1.1250 → 0.1.1256

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,4 +11,16 @@ gateway service install --url https://gateway.mp281x.xyz --auth https://auth.mp2
11
11
  - **Admins** (`--admins`) add and connect servers; everyone signed in shares them.
12
12
  - **Own tool**: `list_mcp_connections` explains a missing or failing server.
13
13
 
14
+ ## AI proxy
15
+
16
+ Each person manages their own Anthropic, OpenRouter, OpenCode Zen and OpenCode Go keys. Keys stay in Gateway's owner-only data files; only their last four characters and last upstream status leave the server.
17
+
18
+ App servers start with `--gateway https://gateway.mp281x.xyz`. The runtime enrolls each authenticated person with a grant for that app's `--url`; enrollment forwards the session cookie or app-audience bearer to `POST /ai/grants`. A new grant replaces the previous grant for that person and app. Revoking it immediately stops new proxy calls. Without `--auth`, calls use the local developer and need no grant.
19
+
20
+ Use `AiGateway` from `@deslop/runtime/ai`: `yield* gateway.apiUrl(provider)` and pass `gateway.authorize(userId)` as the provider client's **construction-time** `transformClient`. OpenRouter's scoped `withClientTransform` does not cover streaming chat completions. OpenRouter's base includes `/v1`; its Decisions client derives `/alpha/decisions` correctly. OpenCode bases expose protocol-family paths such as `/openai/v1/chat/completions` and `/anthropic/v1/messages` without translating them.
21
+
22
+ `/ai/<provider>/<rest>` forwards method, query, body and upstream status. Fetch decodes compressed responses; stale encoding and length headers, hop-by-hop headers and headers nominated by `Connection` are removed from the streamed answer. Caller credentials and hop-by-hop headers are removed before inserting the person's provider key. Missing keys return HTTP 402 with instructions to add a key in Gateway. JSON and SSE usage is metered asynchronously; provider-reported cost wins, then daily-cached models.dev prices, otherwise cost remains unknown. Usage is stored per person and UTC month.
23
+
24
+ Person-scoped RPCs: `ai.keys`, `ai.setKey`, `ai.removeKey`, `ai.grants`, `ai.revokeGrant`, `ai.usage`. Usage queries take epoch-millisecond `from` (inclusive), `to` (exclusive), and `bucket` (`hour` or `day`); `AiUsageReport` returns token/cost totals, UTC buckets split by app and model, and breakdowns by app, model and provider. `unknownCostCalls` distinguishes unknown cost from zero cost.
25
+
14
26
  Common flags and service commands: [Deslop app runtime](https://github.com/MP281X/deslop/blob/main/packages/runtime/README.md).