@mupt-ai/dari-gateway 1.0.338 → 1.0.340
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 +9 -7
- package/dist/index.d.ts +1 -1
- package/dist/ingress/codex.js +11 -5
- package/dist/ingress/codex_models.d.ts +2 -1
- package/dist/ingress/codex_models.js +60 -26
- package/dist/ingress/models.js +9 -4
- package/dist/link/assets.js +7 -0
- package/dist/link/endpoints.js +26 -6
- package/dist/link/errors.js +3 -0
- package/dist/link/self_hosted.js +8 -2
- package/dist/models/catalog.js +1 -0
- package/dist/models/execution_provider.d.ts +6 -1
- package/dist/models/execution_provider.js +12 -0
- package/dist/models/provider_defaults.js +9 -0
- package/dist/models/provider_models.json +217 -0
- package/dist/models/subscriptions.d.ts +5 -0
- package/dist/models/subscriptions.js +21 -2
- package/dist/providers/execution.d.ts +5 -0
- package/dist/providers/execution.js +12 -2
- package/dist/providers/github_copilot.d.ts +8 -0
- package/dist/providers/github_copilot.js +21 -0
- package/dist/providers/pi.js +3 -0
- package/dist/providers/provider_attempt_runner.d.ts +2 -0
- package/dist/providers/provider_attempt_runner.js +9 -0
- package/dist/providers/provider_call.js +6 -2
- package/dist/providers/subscription_limits.d.ts +6 -5
- package/dist/providers/subscription_limits.js +20 -9
- package/dist/runtime/model_menu_hint.d.ts +2 -0
- package/dist/runtime/model_menu_hint.js +13 -0
- package/dist/runtime/routed_completion.d.ts +2 -1
- package/dist/runtime/routed_completion.js +6 -2
- package/dist/runtime/routed_runtime.js +68 -3
- package/dist/self_host/resolve.d.ts +11 -9
- package/dist/self_host/resolve.js +247 -181
- package/dist/self_host/subscriptions/index.d.ts +6 -5
- package/dist/self_host/subscriptions/index.js +6 -5
- package/dist/self_host/subscriptions/oauth.d.ts +7 -3
- package/dist/self_host/subscriptions/oauth.js +195 -5
- package/dist/self_host/subscriptions/store.js +3 -0
- package/dist/telemetry/prefix_state.d.ts +1 -0
- package/dist/telemetry/prefix_state.js +1 -1
- package/dist/telemetry/report.js +2 -3
- package/dist/types.d.ts +6 -2
- package/package.json +2 -2
- package/src/index.ts +1 -1
- package/src/ingress/codex.ts +11 -5
- package/src/ingress/codex_models.ts +71 -27
- package/src/ingress/models.ts +9 -4
- package/src/link/assets.ts +7 -0
- package/src/link/endpoints.ts +27 -7
- package/src/link/errors.ts +3 -0
- package/src/link/self_hosted.ts +9 -1
- package/src/models/catalog.ts +1 -0
- package/src/models/execution_provider.ts +24 -1
- package/src/models/provider_defaults.ts +9 -0
- package/src/models/provider_models.json +217 -0
- package/src/models/subscriptions.ts +22 -2
- package/src/providers/execution.ts +22 -2
- package/src/providers/github_copilot.ts +24 -0
- package/src/providers/pi.ts +2 -0
- package/src/providers/provider_attempt_runner.ts +15 -0
- package/src/providers/provider_call.ts +6 -2
- package/src/providers/subscription_limits.ts +20 -10
- package/src/runtime/model_menu_hint.ts +20 -0
- package/src/runtime/routed_completion.ts +9 -3
- package/src/runtime/routed_runtime.ts +79 -3
- package/src/self_host/resolve.ts +253 -186
- package/src/self_host/subscriptions/index.ts +7 -4
- package/src/self_host/subscriptions/oauth.ts +264 -8
- package/src/self_host/subscriptions/store.ts +3 -0
- package/src/telemetry/prefix_state.ts +4 -1
- package/src/telemetry/report.ts +2 -3
- package/src/types.ts +27 -3
package/README.md
CHANGED
|
@@ -27,7 +27,8 @@ The gateway is the runtime behind Dari's hosted routing service, packaged to run
|
|
|
27
27
|
## Features
|
|
28
28
|
|
|
29
29
|
- **One endpoint, three protocols.** `/v1/messages`, `/v1/chat/completions`, and `/v1/responses` (plus `/v1/models`) reach API-key providers in the [Pi AI](https://www.npmjs.com/package/@mupt-ai/pi-ai) catalog, such as Anthropic, OpenAI, and OpenRouter, or any OpenAI-compatible server.
|
|
30
|
-
- **Subscription pooling.** Connect several Claude Code (Max/Pro) or ChatGPT plans. Each conversation stays on one plan so its prompt cache stays warm. Claude Code plans report their usage on every response: once a plan has used 95% of a window, its conversations move to another plan at their next turn, and new conversations start on the plan whose quota resets soonest. A plan that reports a usage limit is held until its reset, and the request it refused is served by the next plan at once.
|
|
30
|
+
- **Subscription pooling.** Connect several Claude Code (Max/Pro) or ChatGPT plans. Each conversation stays on one plan so its prompt cache stays warm. Claude Code plans report their usage on every response: once a plan has used 95% of a window, its conversations move to another plan at their next turn, and new conversations start on the plan whose quota resets soonest. A plan that reports a usage limit is held until its reset, and the request it refused is served by the next plan at once.
|
|
31
|
+
- **Cross-plan failover.** One model can be served by several kinds of plan: GitHub Copilot serves Claude and GPT models, and OpenCode Go and Vercel Token Pass serve the Kimi and GLM models. Each model tries the plans that serve it in a fixed order, the maker's plan first: Claude Code, ChatGPT, Grok, Muse Code, OpenCode Go, GitHub Copilot, Vercel Token Pass, then its provider's API key if you set one. When a plan reaches its usage limit with no other plan of its kind left, or refuses its token, the same request moves to the model's next plan, then to the key, before anything reaches the client.
|
|
31
32
|
- **Failover.** A provider failure retries the router's next model.
|
|
32
33
|
- **Prompt-cache aware.** Conversations keep their identity and serving model across turns, so provider caches stay warm. Responses carry `X-Dari-Selected-Model`, `X-Dari-Thinking-Level`, and `X-Dari-Conversation-Id` headers for status lines.
|
|
33
34
|
- **Coding agents.** `dari claude`, `dari codex`, `dari opencode`, and `dari pi` from the [Dari CLI](https://github.com/mupt-ai/dari) launch straight against your gateway.
|
|
@@ -100,7 +101,7 @@ providers: # endpoints outside the built-in catalog
|
|
|
100
101
|
apiKeyEnv: LOCAL_API_KEY
|
|
101
102
|
```
|
|
102
103
|
|
|
103
|
-
Model ids are `provider/model`. Clients send `model: "dari/routing"` to let the router choose, or `model: "dari/model/<id>"` to pin one of its models. A Claude Code subscription serves Anthropic models only for Claude Code itself; a ChatGPT subscription serves OpenAI models for every client. Each coding agent is offered the router's models that a credential can serve it, or its own `agentModels` list (`claude_code`, `codex`, `muse_code`, `opencode`, `pi`, `openclaw`, `hermes`) when the router has one.
|
|
104
|
+
Model ids are `provider/model`. Clients send `model: "dari/routing"` to let the router choose, or `model: "dari/model/<id>"` to pin one of its models. A Claude Code subscription serves Anthropic models only for Claude Code itself; a ChatGPT subscription serves OpenAI models for every client; other plans serve every client the models they serve (see **Cross-plan failover**). Each coding agent is offered the router's models that a credential can serve it, or its own `agentModels` list (`claude_code`, `codex`, `muse_code`, `opencode`, `pi`, `openclaw`, `hermes`) when the router has one.
|
|
104
105
|
|
|
105
106
|
`dari setup <agent>` opens the model picker on a running gateway, with any gateway key. It calls `PUT /v1/router/models[/<agent>]` (`GET` reads the lists, `DELETE` removes a saved one). The gateway saves the list in its database and serves it at once in place of the config file's.
|
|
106
107
|
|
|
@@ -124,7 +125,7 @@ native_compaction: false
|
|
|
124
125
|
agents: { codex: [openai/gpt-6.1-sol] }
|
|
125
126
|
```
|
|
126
127
|
|
|
127
|
-
The gateway pays with connected subscriptions when `payment.allow` lists `subscription`,
|
|
128
|
+
The gateway pays with connected subscriptions when `payment.allow` lists `subscription`, then with provider API keys; it has no Dari credits. On hosted Dari the same setting is the router's `subscription_providers`: it can name any provider whose models some plan serves, such as `fireworks` or `google`, and those models try the user's plans first. `hosted` settings and a model's `fast` apply only on hosted Dari and are ignored here; `routing.rules` runs only on hosted Dari and is refused. A model's `provider` must be one that serves it, such as `opencode-go` or `fireworks` for the DeepSeek, Kimi, and GLM models; the plan-only providers `github-copilot` and `vercel-token-pass` serve through a connected subscription.
|
|
128
129
|
|
|
129
130
|
With any gateway key:
|
|
130
131
|
|
|
@@ -143,7 +144,7 @@ With any gateway key:
|
|
|
143
144
|
export DARI_GATEWAY_URL=http://localhost:8080
|
|
144
145
|
export DARI_GATEWAY_KEY=<one of DARI_GATEWAY_KEYS>
|
|
145
146
|
|
|
146
|
-
dari accounts subscription connect claude-code # or codex
|
|
147
|
+
dari accounts subscription connect claude-code # or codex, muse-code, opencode-go, github-copilot, grok, vercel-token-pass; repeat to pool plans
|
|
147
148
|
dari claude
|
|
148
149
|
```
|
|
149
150
|
|
|
@@ -153,7 +154,7 @@ In gateway mode the CLI makes no calls to Dari's hosted API; `dari activity` rea
|
|
|
153
154
|
|
|
154
155
|
Dari Link lets another app send one user's model requests through the gateway on only the subscriptions that user grants it: never an API key, credits, or any other plan.
|
|
155
156
|
|
|
156
|
-
**Which plans serve which apps.** A ChatGPT plan (`openai_codex`) serves any app, including a plain OpenAI `chat/completions` or Responses client, through the Codex backend. A Claude Pro/Max/Ultra plan (`anthropic_claude_code`) serves only Claude Code itself, and a Muse Code plan only Muse Code; the gateway never presents another app as those clients. An OpenCode Go plan (`opencode_go`) serves any app its `opencode-go` models. So an app that calls the API itself needs the user to grant
|
|
157
|
+
**Which plans serve which apps.** A ChatGPT plan (`openai_codex`) serves any app, including a plain OpenAI `chat/completions` or Responses client, through the Codex backend. A Claude Pro/Max/Ultra plan (`anthropic_claude_code`) serves only Claude Code itself, and a Muse Code plan only Muse Code; the gateway never presents another app as those clients. An OpenCode Go plan (`opencode_go`) serves any app its `opencode-go` models, and GitHub Copilot (`github_copilot`), Grok (`xai_grok`), and Vercel Token Pass (`vercel_token_pass`, a pasted Token Pass key that serves Vercel AI Gateway's featured models) plans serve any app theirs. So an app that calls the API itself needs the user to grant one of those plans, or an API key. The approval page offers only what the app can use: a Claude or Muse plan appears when the app runs Claude Code or Muse Code itself and says so with `client` on the authorize request.
|
|
157
158
|
|
|
158
159
|
**API keys.** A user without a plan can add an API key on the same page instead: one per model provider (Anthropic, OpenAI, Meta, Moonshot AI, xAI) or gateway (OpenRouter, Vercel AI Gateway). A key is shared like a plan, shows on the grant as `kind: "api_key"` with `provider` (never the key itself), and serves that provider's catalog models to any app, so an Anthropic key serves a plain client where a Claude plan would not. A gateway key serves any model of its gateway named by its full id, such as `openrouter/anthropic/claude-sonnet-4.5`; the grant's `models` lists none of them. A child token can be pinned to such a model the same way (`model=openrouter/anthropic/claude-sonnet-4.5`). Such a plan entry carries `model_prefix` (`"openrouter/"`): any id the gateway lists, with that prefix, is a model name here, sent as `dari/model/openrouter/<id>` or just `openrouter/<id>`. Every plan entry has a `title` to show ("Claude", "ChatGPT", "OpenRouter"). Where a grant holds both a plan and a key for a provider, the plan serves first. The usage a provider bills on the user's key is the user's cost. `plans` on the authorize request lists what the app wants offered, plan kinds and `api_key`; omit it to offer everything the app can use. `key_providers` (`keyProviders` in the client) narrows the API keys to the providers the app can run, such as `anthropic openrouter`, so a user is never offered, or shown ticked, a key the app cannot use. A user can connect as many plans and keys as they like, several accounts of one kind included, and share any of them.
|
|
159
160
|
|
|
@@ -223,7 +224,7 @@ The gateway refuses a model the grant cannot serve, a plan at its limit, a spent
|
|
|
223
224
|
- `response_mode=web_message`: for a page opened as a popup. The result is posted to the window that opened it (`{"type": "dari-link", "code" | "error", "state"}`, addressed to the redirect URI's origin) instead of sent on a redirect; a page with no opener left redirects to `redirect_uri` instead. `DariLink.open` does this for you.
|
|
224
225
|
- `grant_id`: update mode (above).
|
|
225
226
|
|
|
226
|
-
The gateway serves the page itself, hosted and self-hosted alike. A new user sees what connecting means, picks a subscription (Claude, ChatGPT, Meta Muse, OpenCode Go) or a provider to add an API key for, signs in to that provider (Claude shows a code to paste back; the others take a code the page shows and continue on their own), and allows the app with what they connected ticked. A self-hosted gateway needs no sign-in: their first plan or key makes them a user. A platform with accounts (`LinkApprovalPage.signIn`; on hosted Dari, the user's Dari account) has them sign in first, and they are that account, with the plans it already has. Either way the gateway remembers them in a signed HttpOnly cookie, so the next app that asks finds their plans connected and takes one click: for a year without accounts, since the cookie is who they are; for 30 days with them, and they can sign out from the approval and connections pages. A self-hosted gateway takes their subscriptions and keys only when it encrypts what it stores (`DARI_GATEWAY_ENCRYPTION_KEY`). A plan a user connects this way is theirs alone: it serves only the grants they approve, never a gateway key, and the gateway owner's own plans are never offered on the page.
|
|
227
|
+
The gateway serves the page itself, hosted and self-hosted alike. A new user sees what connecting means, picks a subscription (Claude, ChatGPT, Meta Muse, OpenCode Go, GitHub Copilot, Grok, Vercel Token Pass) or a provider to add an API key for, signs in to that provider (Claude shows a code to paste back, and Vercel Token Pass takes a key the user creates at Vercel; the others take a code the page shows and continue on their own), and allows the app with what they connected ticked. A self-hosted gateway needs no sign-in: their first plan or key makes them a user. A platform with accounts (`LinkApprovalPage.signIn`; on hosted Dari, the user's Dari account) has them sign in first, and they are that account, with the plans it already has. Either way the gateway remembers them in a signed HttpOnly cookie, so the next app that asks finds their plans connected and takes one click: for a year without accounts, since the cookie is who they are; for 30 days with them, and they can sign out from the approval and connections pages. A self-hosted gateway takes their subscriptions and keys only when it encrypts what it stores (`DARI_GATEWAY_ENCRYPTION_KEY`). A plan a user connects this way is theirs alone: it serves only the grants they approve, never a gateway key, and the gateway owner's own plans are never offered on the page.
|
|
227
228
|
|
|
228
229
|
The user approves; they can later cap the tokens the app may use per 5 hours and per week (see **Budgets**). The app gets `code` and `state`, or `error=access_denied`, on `redirect_uri` or as the popup's message.
|
|
229
230
|
3. `POST /v1/link/token` (form or JSON; CORS open) with `grant_type=authorization_code`, `code`, `redirect_uri`, `client_id`, `code_verifier` returns an access token (`dlk_at_…`, one hour) and a refresh token (`dlk_rt_…`), with the grant's fields below. `grant_type=refresh_token` with `refresh_token` returns a new access token:
|
|
@@ -232,7 +233,7 @@ The gateway refuses a model the grant cannot serve, a plan at its limit, a spent
|
|
|
232
233
|
- A confidential client's refresh token never rotates, so any number of instances can refresh one grant.
|
|
233
234
|
4. Call the gateway's ordinary endpoints (`/v1/chat/completions`, `/v1/responses`, `/v1/messages`, `/v1/models`) with `Authorization: Bearer dlk_at_…`. A link token serves only the default router, and is served exactly what it names:
|
|
234
235
|
- `dari/routing` chooses among the router's models that a granted plan serves.
|
|
235
|
-
- Any other name is a model, served as exactly that model: any catalog model of a granted plan's provider, whether or not the user's router lists it. It may be named `dari/model/<provider>/<model>`, by its bare id (`gpt-5.5`, `claude-sonnet-5-5`), or as a dated snapshot of either (`claude-haiku-4-5-20251001` is `claude-haiku-4-5`), so an app forwarding Claude Code or Codex traffic needs no model map. A name no catalog model has, or one two models share, fails with `model_not_granted`. It is served with the client's own thinking settings: a level the request names is served exactly or refused (400 `thinking_level_unavailable`); Anthropic's `thinking: {"type": "disabled"}` is sent as it is, on every Claude model (`X-Dari-Thinking-Level: off`); a thinking budget (`thinking: {"type": "enabled", "budget_tokens": 8000}`) is sent as it is (`X-Dari-Thinking-Level: budget:8000`); and when it names none, none is chosen for it and the provider's default applies (`X-Dari-Thinking-Level: default`). `X-Dari-Thinking-Level` is what the provider was sent: a level, `off`, `default`, or `budget:<tokens>`. It never fails over to another model: a provider failure is returned as it is. Only when a granted plan hits its usage limit
|
|
236
|
+
- Any other name is a model, served as exactly that model: any catalog model of a granted plan's provider, whether or not the user's router lists it. It may be named `dari/model/<provider>/<model>`, by its bare id (`gpt-5.5`, `claude-sonnet-5-5`), or as a dated snapshot of either (`claude-haiku-4-5-20251001` is `claude-haiku-4-5`), so an app forwarding Claude Code or Codex traffic needs no model map. A name no catalog model has, or one two models share, fails with `model_not_granted`. It is served with the client's own thinking settings: a level the request names is served exactly or refused (400 `thinking_level_unavailable`); Anthropic's `thinking: {"type": "disabled"}` is sent as it is, on every Claude model (`X-Dari-Thinking-Level: off`); a thinking budget (`thinking: {"type": "enabled", "budget_tokens": 8000}`) is sent as it is (`X-Dari-Thinking-Level: budget:8000`); and when it names none, none is chosen for it and the provider's default applies (`X-Dari-Thinking-Level: default`). `X-Dari-Thinking-Level` is what the provider was sent: a level, `off`, `default`, or `budget:<tokens>`. It never fails over to another model: a provider failure is returned as it is. Only when a granted plan hits its usage limit or refuses its token is the request retried on the same model, on the next granted plan that serves it (in the order under **Cross-plan failover**), then on the grant's API key for the model's provider.
|
|
236
237
|
- `opus`, `sonnet`, `haiku`, and the other Anthropic tier names route, as `dari/routing` does.
|
|
237
238
|
- `POST /v1/messages/count_tokens` is not served: it answers an Anthropic-shaped 404, on which Claude Code estimates locally.
|
|
238
239
|
- A non-streamed response carries `X-Dari-Usage: {"input_tokens", "output_tokens", "cache_read_tokens", "cache_write_tokens"}` (input excludes cache reads and writes) beside `X-Dari-Selected-Model` and `X-Dari-Thinking-Level`, the same whatever protocol the app speaks. A stream reports usage in its protocol's own final event; `GET /v1/link/usage` has both.
|
|
@@ -425,6 +426,7 @@ The root entry needs no Bun APIs, so any runtime with web-standard `fetch`, `Req
|
|
|
425
426
|
Platforms can also:
|
|
426
427
|
|
|
427
428
|
- implement `resolveProviderCredential({ provider, model, routerId, organizationId, apiKey, clientHarness? })` to supply a per-request `{ apiKey, baseUrl?, headers?, subscription? }`, such as a tenant's own key, in place of the router's resolved key. With `subscription` (`"openai_codex"`, `"anthropic_claude_code"`, or `"meta_muse"`), `apiKey` is that plan's access token: Codex's `auth.json` `tokens.access_token`, the token `claude setup-token` prints, or the Model API key a Meta sign-in mints. The platform keeps it fresh. Strict routers serve these supplied plans, but never subscriptions the gateway resolved itself. A plan serves only its own provider's models; a Claude Code plan serves only Claude Code clients, and a Muse Code plan only Muse Code clients (recognized by their `x-client-id`);
|
|
429
|
+
- resolve a model's plans per model: `provider_credentials[model]` is `{ apiKey, subscription, credentialId }` for the plan that serves it first, and `provider_keys` hold only API keys. `model_fallbacks[model]` lists what serves it next, in order, each `{ config, subscription }`: a plan kind, whose token the gateway asks `nextSubscription` for when it gets there, or `null` for the API key of `config.provider`. The gateway moves down the list within a request when a plan reaches its usage limit with no other plan of its kind left or refuses its token, and skips API keys while `credit_exhausted` is set;
|
|
428
430
|
- resolve routers with `strict: true` to serve only the requested `dari/model/<id>` at the requested thinking level, with no selector, lease, or personal subscription. Set `strict_providers: ["openai"]` on the resolved router to permit any bundled-catalog model from that provider without enumerating `enabled_models`. Use `dari/model/openai/gpt-6.2-sol`; bare IDs and unknown models remain refused. This grant is ignored on non-strict routers and does not discover uncatalogued models;
|
|
429
431
|
- resolve routers with `session_pinning: true` to route each session once and serve that pair for the rest of the session. Each subagent (Claude Code agent id, Codex subagent thread, OpenCode child session) is routed once on its own. Pins are kept through `readSessionPin` and `writeSessionPin`, keyed by router and an opaque pin key; background requests and `dari/model/<id>` requests never use them;
|
|
430
432
|
- resolve routers with `native_compaction: true` to let Codex compact context server-side with the provider's native compaction. Requests carrying compaction state are routed only to models that support it;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export { DEFAULT_CATALOG_PROVIDERS, listModelCatalog, type CatalogModel, type Ca
|
|
|
4
4
|
export { createAutoRoutingSelectorBackend } from "./strategies/auto_routing_selector.js";
|
|
5
5
|
export { createPrioritySelectorBackend } from "./strategies/priority_selector.js";
|
|
6
6
|
export { createLlmSelectorBackend, type SelectorBackend } from "./strategies/routing.js";
|
|
7
|
-
export type { ProviderCredential, ResolvedRouter, SubscriptionKind } from "./types.js";
|
|
7
|
+
export type { ModelFallback, ProviderCredential, ResolvedRouter, SubscriptionKind } from "./types.js";
|
package/dist/ingress/codex.js
CHANGED
|
@@ -6,6 +6,7 @@ import { openAIResponsesResponse } from "../protocol/output/openai_responses.js"
|
|
|
6
6
|
import { openAIResponsesSseStream } from "../protocol/output/openai_responses_stream.js";
|
|
7
7
|
import { openAIResponsesToInteraction } from "../protocol/input/openai_responses.js";
|
|
8
8
|
import { claimedClientHarness } from "./client_harness.js";
|
|
9
|
+
import { codexModelsEtag } from "./codex_models.js";
|
|
9
10
|
import { parseJsonRequest } from "./json.js";
|
|
10
11
|
import { museCodeClientId } from "./muse_code.js";
|
|
11
12
|
import { handleRoutedCompletion } from "../runtime/routed_completion.js";
|
|
@@ -41,6 +42,11 @@ export async function handleResponses(request, routerId, selectorBackend) {
|
|
|
41
42
|
}
|
|
42
43
|
const harnessConversationIdentity = codexIdentity
|
|
43
44
|
?? (museClientId === undefined ? undefined : museCodeConversationIdentity(request.headers));
|
|
45
|
+
const clientHarness = museClientId !== undefined ? "muse_code"
|
|
46
|
+
// Codex describes every request in its turn metadata.
|
|
47
|
+
: codexContext !== undefined ? "codex"
|
|
48
|
+
: piContext !== undefined ? "pi"
|
|
49
|
+
: claimedClientHarness(request.headers);
|
|
44
50
|
return await handleRoutedCompletion({
|
|
45
51
|
request,
|
|
46
52
|
routerId,
|
|
@@ -50,12 +56,12 @@ export async function handleResponses(request, routerId, selectorBackend) {
|
|
|
50
56
|
streamBody: openAIResponsesSseStream,
|
|
51
57
|
errorResponse,
|
|
52
58
|
selectorBackend,
|
|
53
|
-
clientHarness
|
|
54
|
-
// Codex describes every request in its turn metadata.
|
|
55
|
-
: codexContext !== undefined ? "codex"
|
|
56
|
-
: piContext !== undefined ? "pi"
|
|
57
|
-
: claimedClientHarness(request.headers),
|
|
59
|
+
clientHarness,
|
|
58
60
|
harnessConversationIdentity,
|
|
61
|
+
// A running Codex re-reads its /model list when this changes.
|
|
62
|
+
...(clientHarness === "codex"
|
|
63
|
+
? { responseHeaders: (router) => ({ "X-Models-Etag": codexModelsEtag(router) }) }
|
|
64
|
+
: {}),
|
|
59
65
|
});
|
|
60
66
|
}
|
|
61
67
|
catch (error) {
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import type { ResolvedRouter } from "../types.js";
|
|
2
|
-
export declare function codexModelsResponse(router: Pick<ResolvedRouter, "enabled_models" | "model_configs" | "allow_long_context" | "autorouting_enabled" | "routing_listed" | "native_compaction">, imageInputFor: (model: string) => boolean, nativeCompactionFor?: (model: string) => boolean): Record<string, unknown>;
|
|
2
|
+
export declare function codexModelsResponse(router: Pick<ResolvedRouter, "enabled_models" | "model_configs" | "allow_long_context" | "autorouting_enabled" | "routing_listed" | "native_compaction">, imageInputFor: (model: string) => boolean, nativeCompactionFor?: (model: string) => boolean, direct?: boolean): Record<string, unknown>;
|
|
3
|
+
export declare function codexModelsEtag(router: Pick<ResolvedRouter, "enabled_models" | "model_configs" | "allow_long_context" | "autorouting_enabled" | "routing_listed">): string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
1
2
|
import { CANONICAL_ROUTER_MODEL, explicitModelSlug } from "../protocol/input/router_model.js";
|
|
2
3
|
import { effectiveContextWindow } from "../models/context_limits.js";
|
|
3
4
|
import { modelSupportsHostedWebSearch } from "../providers/model_capabilities.js";
|
|
@@ -64,38 +65,71 @@ function codexCatalogEntry(args) {
|
|
|
64
65
|
multi_agent_version: null,
|
|
65
66
|
};
|
|
66
67
|
}
|
|
68
|
+
/* What Codex needs to parse an entry it fetched itself: it rejects the whole
|
|
69
|
+
catalog over a null web-search type, leaving /model empty, so the entry
|
|
70
|
+
names one, and the two nullable fields it may not accept as null are left
|
|
71
|
+
out. The `dari` launchers make the same changes to the catalog they hand
|
|
72
|
+
Codex; they read the nulls first to decide whether to turn web search off. */
|
|
73
|
+
function codexReadable(entry) {
|
|
74
|
+
const { tool_mode, multi_agent_version, ...rest } = entry;
|
|
75
|
+
return {
|
|
76
|
+
...rest,
|
|
77
|
+
web_search_tool_type: entry.web_search_tool_type ?? "text",
|
|
78
|
+
...(tool_mode === null ? {} : { tool_mode }),
|
|
79
|
+
...(multi_agent_version === null ? {} : { multi_agent_version }),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
67
82
|
/* `dari/routing` comes first while the router may autoroute (the Codex
|
|
68
83
|
launcher patches it); each enabled model follows as `dari/model/<id>` so
|
|
69
84
|
Codex's /model menu can switch to it. The `dari` launchers build every
|
|
70
85
|
agent's model menu from this list. `remote_compaction` tells the
|
|
71
|
-
launcher which Codex provider compaction protocol the router accepts.
|
|
72
|
-
|
|
86
|
+
launcher which Codex provider compaction protocol the router accepts.
|
|
87
|
+
`direct` is a catalog for Codex's own fetch (its `model_catalog_url`),
|
|
88
|
+
which nothing patches on the way: `codex_direct` tells `dari setup codex`
|
|
89
|
+
that this gateway serves one, so it can point Codex at the URL instead of
|
|
90
|
+
a snapshot that goes stale when the router's models change. */
|
|
91
|
+
export function codexModelsResponse(router, imageInputFor, nativeCompactionFor = () => false, direct = false) {
|
|
73
92
|
const remoteCompaction = router.native_compaction === true && router.enabled_models.some(nativeCompactionFor);
|
|
93
|
+
const models = codexCatalogEntries(router, imageInputFor);
|
|
74
94
|
return {
|
|
75
95
|
remote_compaction: remoteCompaction ? "v2" : "unsupported",
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
slug: CANONICAL_ROUTER_MODEL,
|
|
79
|
-
displayName: "Dari Routing",
|
|
80
|
-
description: "Routes Codex HTTP Responses requests through the configured Dari model router.",
|
|
81
|
-
priority: 0,
|
|
82
|
-
contextWindow: codexRouterContextWindow(router),
|
|
83
|
-
hostedWebSearch: codexRouterSupportsHostedWebSearch(router),
|
|
84
|
-
imageInput: router.enabled_models.some(imageInputFor),
|
|
85
|
-
})]),
|
|
86
|
-
...router.enabled_models.map((model, index) => codexCatalogEntry({
|
|
87
|
-
slug: explicitModelSlug(model),
|
|
88
|
-
displayName: model,
|
|
89
|
-
description: `Serves ${model} directly, without routing.`,
|
|
90
|
-
priority: index + 1,
|
|
91
|
-
contextWindow: codexRouterContextWindow({ ...router, enabled_models: [model] }),
|
|
92
|
-
hostedWebSearch: codexRouterSupportsHostedWebSearch({ ...router, enabled_models: [model] }),
|
|
93
|
-
imageInput: imageInputFor(model),
|
|
94
|
-
reasoningLevels: router.model_configs?.[model]?.supported_thinking_levels
|
|
95
|
-
?.map((effort) => effort === "off" ? "none" : effort),
|
|
96
|
-
defaultReasoningLevel: router.model_configs?.[model]?.default_thinking_level === "off"
|
|
97
|
-
? "none" : router.model_configs?.[model]?.default_thinking_level,
|
|
98
|
-
})),
|
|
99
|
-
],
|
|
96
|
+
...(direct ? { codex_direct: true } : {}),
|
|
97
|
+
models: direct ? models.map(codexReadable) : models,
|
|
100
98
|
};
|
|
101
99
|
}
|
|
100
|
+
/* A version of the list Codex's /model menu shows: it changes when a model
|
|
101
|
+
is added or removed, or dari/routing comes or goes. Sent as
|
|
102
|
+
`X-Models-Etag` on the catalog and on Codex's responses, it makes a running
|
|
103
|
+
Codex re-read the catalog after the first turn that sees a new value,
|
|
104
|
+
instead of on its next timed refresh. Codex reads it only from a successful
|
|
105
|
+
response; a refused stale pick carries the menu hint instead. */
|
|
106
|
+
export function codexModelsEtag(router) {
|
|
107
|
+
const slugs = codexCatalogEntries(router, () => false).map((entry) => entry.slug);
|
|
108
|
+
return createHash("sha256").update(slugs.join("\n")).digest("hex").slice(0, 16);
|
|
109
|
+
}
|
|
110
|
+
function codexCatalogEntries(router, imageInputFor) {
|
|
111
|
+
return [
|
|
112
|
+
...(router.autorouting_enabled === false || router.routing_listed === false ? [] : [codexCatalogEntry({
|
|
113
|
+
slug: CANONICAL_ROUTER_MODEL,
|
|
114
|
+
displayName: "Dari Routing",
|
|
115
|
+
description: "Routes Codex HTTP Responses requests through the configured Dari model router.",
|
|
116
|
+
priority: 0,
|
|
117
|
+
contextWindow: codexRouterContextWindow(router),
|
|
118
|
+
hostedWebSearch: codexRouterSupportsHostedWebSearch(router),
|
|
119
|
+
imageInput: router.enabled_models.some(imageInputFor),
|
|
120
|
+
})]),
|
|
121
|
+
...router.enabled_models.map((model, index) => codexCatalogEntry({
|
|
122
|
+
slug: explicitModelSlug(model),
|
|
123
|
+
displayName: model,
|
|
124
|
+
description: `Serves ${model} directly, without routing.`,
|
|
125
|
+
priority: index + 1,
|
|
126
|
+
contextWindow: codexRouterContextWindow({ ...router, enabled_models: [model] }),
|
|
127
|
+
hostedWebSearch: codexRouterSupportsHostedWebSearch({ ...router, enabled_models: [model] }),
|
|
128
|
+
imageInput: imageInputFor(model),
|
|
129
|
+
reasoningLevels: router.model_configs?.[model]?.supported_thinking_levels
|
|
130
|
+
?.map((effort) => effort === "off" ? "none" : effort),
|
|
131
|
+
defaultReasoningLevel: router.model_configs?.[model]?.default_thinking_level === "off"
|
|
132
|
+
? "none" : router.model_configs?.[model]?.default_thinking_level,
|
|
133
|
+
})),
|
|
134
|
+
];
|
|
135
|
+
}
|
package/dist/ingress/models.js
CHANGED
|
@@ -16,7 +16,7 @@ import { modelMetadataLookup } from "../providers/pi.js";
|
|
|
16
16
|
import { resolveRouter } from "../strategies/routing.js";
|
|
17
17
|
import { anthropicModelsResponse } from "./anthropic_models.js";
|
|
18
18
|
import { namedClientHarness } from "./client_harness.js";
|
|
19
|
-
import { codexModelsResponse } from "./codex_models.js";
|
|
19
|
+
import { codexModelsEtag, codexModelsResponse } from "./codex_models.js";
|
|
20
20
|
import { CANONICAL_ROUTER_MODEL, explicitModelSlug, LINK_CHILD_TOKEN_PREFIX } from "../protocol/input/router_model.js";
|
|
21
21
|
export async function handleModels(request, routerId) {
|
|
22
22
|
// Anthropic SDK clients always send anthropic-version, and API-key probes
|
|
@@ -30,7 +30,12 @@ export async function handleModels(request, routerId) {
|
|
|
30
30
|
// when the response body (Anthropic shape) does not depend on it.
|
|
31
31
|
// A model list is for the agent the Dari CLI names: it changes only what
|
|
32
32
|
// is listed, and each request is still recognized by its own headers.
|
|
33
|
-
const
|
|
33
|
+
const query = new URL(request.url).searchParams;
|
|
34
|
+
// Codex itself reads this URL as its provider's `model_catalog_url`, and
|
|
35
|
+
// refreshes from it while it runs. It cannot send the CLI's header; it
|
|
36
|
+
// names its own version in the query, as only Codex does.
|
|
37
|
+
const codexDirect = !anthropicClient && query.has("client_version");
|
|
38
|
+
const clientHarness = namedClientHarness(request.headers) ?? (codexDirect ? "codex" : undefined);
|
|
34
39
|
let router;
|
|
35
40
|
try {
|
|
36
41
|
router = await resolveRouter({ routerId, apiKey, ...(clientHarness ? { clientHarness } : {}) });
|
|
@@ -43,7 +48,6 @@ export async function handleModels(request, routerId) {
|
|
|
43
48
|
}
|
|
44
49
|
throw error;
|
|
45
50
|
}
|
|
46
|
-
const query = new URL(request.url).searchParams;
|
|
47
51
|
if (query.get("detail") === "1") {
|
|
48
52
|
const providers = query.get("provider")?.split(",").map((id) => id.trim()).filter(Boolean);
|
|
49
53
|
const data = await listModelCatalog({
|
|
@@ -68,9 +72,10 @@ export async function handleModels(request, routerId) {
|
|
|
68
72
|
const metadataLookup = modelMetadataLookup(router.model_configs);
|
|
69
73
|
const imageInputFor = (model) => modelSupportsImageInput(metadataLookup(model));
|
|
70
74
|
const nativeCompactionFor = (model) => modelSupportsNativeCompaction(metadataLookup(model));
|
|
71
|
-
return Response.json(codexModelsResponse(router, imageInputFor, nativeCompactionFor), {
|
|
75
|
+
return Response.json(codexModelsResponse(router, imageInputFor, nativeCompactionFor, codexDirect), {
|
|
72
76
|
headers: {
|
|
73
77
|
"Cache-Control": "no-store",
|
|
78
|
+
"X-Models-Etag": codexModelsEtag(router),
|
|
74
79
|
},
|
|
75
80
|
});
|
|
76
81
|
}
|
package/dist/link/assets.js
CHANGED
|
@@ -9,6 +9,8 @@ const MARKS = {
|
|
|
9
9
|
anthropic: `<svg class="logo" viewBox="0 0 24 24" fill="currentColor" fill-rule="evenodd" aria-hidden="true"><path d="M13.827 3.52h3.603L24 20h-3.603l-6.57-16.48zm-7.258 0h3.767L16.906 20h-3.674l-1.343-3.461H5.017l-1.344 3.46H0L6.57 3.522zm4.132 9.959L8.453 7.687 6.205 13.48H10.7z"></path></svg>`,
|
|
10
10
|
claude: `<svg class="logo" viewBox="0 0 24 24" fill="currentColor" fill-rule="evenodd" aria-hidden="true"><path d="M4.709 15.955l4.72-2.647.08-.23-.08-.128H9.2l-.79-.048-2.698-.073-2.339-.097-2.266-.122-.571-.121L0 11.784l.055-.352.48-.321.686.06 1.52.103 2.278.158 1.652.097 2.449.255h.389l.055-.157-.134-.098-.103-.097-2.358-1.596-2.552-1.688-1.336-.972-.724-.491-.364-.462-.158-1.008.656-.722.881.06.225.061.893.686 1.908 1.476 2.491 1.833.365.304.145-.103.019-.073-.164-.274-1.355-2.446-1.446-2.49-.644-1.032-.17-.619a2.97 2.97 0 01-.104-.729L6.283.134 6.696 0l.996.134.42.364.62 1.414 1.002 2.229 1.555 3.03.456.898.243.832.091.255h.158V9.01l.128-1.706.237-2.095.23-2.695.08-.76.376-.91.747-.492.584.28.48.685-.067.444-.286 1.851-.559 2.903-.364 1.942h.212l.243-.242.985-1.306 1.652-2.064.73-.82.85-.904.547-.431h1.033l.76 1.129-.34 1.166-1.064 1.347-.881 1.142-1.264 1.7-.79 1.36.073.11.188-.02 2.856-.606 1.543-.28 1.841-.315.833.388.091.395-.328.807-1.969.486-2.309.462-3.439.813-.042.03.049.061 1.549.146.662.036h1.622l3.02.225.79.522.474.638-.079.485-1.215.62-1.64-.389-3.829-.91-1.312-.329h-.182v.11l1.093 1.068 2.006 1.81 2.509 2.33.127.578-.322.455-.34-.049-2.205-1.657-.851-.747-1.926-1.62h-.128v.17l.444.649 2.345 3.521.122 1.08-.17.353-.608.213-.668-.122-1.374-1.925-1.415-2.167-1.143-1.943-.14.08-.674 7.254-.316.37-.729.28-.607-.461-.322-.747.322-1.476.389-1.924.315-1.53.286-1.9.17-.632-.012-.042-.14.018-1.434 1.967-2.18 2.945-1.726 1.845-.414.164-.717-.37.067-.662.401-.589 2.388-3.036 1.44-1.882.93-1.086-.006-.158h-.055L4.132 18.56l-1.13.146-.487-.456.061-.746.231-.243 1.908-1.312-.006.006z"></path></svg>`,
|
|
11
11
|
gemini: `<svg class="logo" viewBox="0 0 24 24" fill="currentColor" fill-rule="evenodd" aria-hidden="true"><path d="M12 24A14.304 14.304 0 000 12 14.304 14.304 0 0012 0a14.305 14.305 0 0012 12 14.305 14.305 0 00-12 12"></path></svg>`,
|
|
12
|
+
githubcopilot: `<svg class="logo" viewBox="0 0 24 24" fill="currentColor" fill-rule="evenodd" aria-hidden="true"><path d="M19.245 5.364c1.322 1.36 1.877 3.216 2.11 5.817.622 0 1.2.135 1.592.654l.73.964c.21.278.323.61.323.955v2.62c0 .339-.173.669-.453.868C20.239 19.602 16.157 21.5 12 21.5c-4.6 0-9.205-2.583-11.547-4.258-.28-.2-.452-.53-.453-.868v-2.62c0-.345.113-.679.321-.956l.73-.963c.392-.517.974-.654 1.593-.654l.029-.297c.25-2.446.81-4.213 2.082-5.52 2.461-2.54 5.71-2.851 7.146-2.864h.198c1.436.013 4.685.323 7.146 2.864zm-7.244 4.328c-.284 0-.613.016-.962.05-.123.447-.305.85-.57 1.108-1.05 1.023-2.316 1.18-2.994 1.18-.638 0-1.306-.13-1.851-.464-.516.165-1.012.403-1.044.996a65.882 65.882 0 00-.063 2.884l-.002.48c-.002.563-.005 1.126-.013 1.69.002.326.204.63.51.765 2.482 1.102 4.83 1.657 6.99 1.657 2.156 0 4.504-.555 6.985-1.657a.854.854 0 00.51-.766c.03-1.682.006-3.372-.076-5.053-.031-.596-.528-.83-1.046-.996-.546.333-1.212.464-1.85.464-.677 0-1.942-.157-2.993-1.18-.266-.258-.447-.661-.57-1.108-.32-.032-.64-.049-.96-.05zm-2.525 4.013c.539 0 .976.426.976.95v1.753c0 .525-.437.95-.976.95a.964.964 0 01-.976-.95v-1.752c0-.525.437-.951.976-.951zm5 0c.539 0 .976.426.976.95v1.753c0 .525-.437.95-.976.95a.964.964 0 01-.976-.95v-1.752c0-.525.437-.951.976-.951zM7.635 5.087c-1.05.102-1.935.438-2.385.906-.975 1.037-.765 3.668-.21 4.224.405.394 1.17.657 1.995.657h.09c.649-.013 1.785-.176 2.73-1.11.435-.41.705-1.433.675-2.47-.03-.834-.27-1.52-.63-1.813-.39-.336-1.275-.482-2.265-.394zm6.465.394c-.36.292-.6.98-.63 1.813-.03 1.037.24 2.06.675 2.47.968.957 2.136 1.104 2.776 1.11h.044c.825 0 1.59-.263 1.995-.657.555-.556.765-3.187-.21-4.224-.45-.468-1.335-.804-2.385-.906-.99-.088-1.875.058-2.265.394zM12 7.615c-.24 0-.525.015-.84.044.03.16.045.336.06.526l-.001.159a2.94 2.94 0 01-.014.25c.225-.022.425-.027.612-.028h.366c.187 0 .387.006.612.028-.015-.146-.015-.277-.015-.409.015-.19.03-.365.06-.526a9.29 9.29 0 00-.84-.044z"></path></svg>`,
|
|
13
|
+
grok: `<svg class="logo" viewBox="0 0 24 24" fill="currentColor" fill-rule="evenodd" aria-hidden="true"><path d="M9.27 15.29l7.978-5.897c.391-.29.95-.177 1.137.272.98 2.369.542 5.215-1.41 7.169-1.951 1.954-4.667 2.382-7.149 1.406l-2.711 1.257c3.889 2.661 8.611 2.003 11.562-.953 2.341-2.344 3.066-5.539 2.388-8.42l.006.007c-.983-4.232.242-5.924 2.75-9.383.06-.082.12-.164.179-.248l-3.301 3.305v-.01L9.267 15.292M7.623 16.723c-2.792-2.67-2.31-6.801.071-9.184 1.761-1.763 4.647-2.483 7.166-1.425l2.705-1.25a7.808 7.808 0 00-1.829-1A8.975 8.975 0 005.984 5.83c-2.533 2.536-3.33 6.436-1.962 9.764 1.022 2.487-.653 4.246-2.34 6.022-.599.63-1.199 1.259-1.682 1.925l7.62-6.815"></path></svg>`,
|
|
12
14
|
meta: `<svg class="logo" viewBox="0 0 24 24" fill="currentColor" fill-rule="evenodd" aria-hidden="true"><path d="M6.897 4c1.915 0 3.516.932 5.43 3.376l.282-.373c.19-.246.383-.484.58-.71l.313-.35C14.588 4.788 15.792 4 17.225 4c1.273 0 2.469.557 3.491 1.516l.218.213c1.73 1.765 2.917 4.71 3.053 8.026l.011.392.002.25c0 1.501-.28 2.759-.818 3.7l-.14.23-.108.153c-.301.42-.664.758-1.086 1.009l-.265.142-.087.04a3.493 3.493 0 01-.302.118 4.117 4.117 0 01-1.33.208c-.524 0-.996-.067-1.438-.215-.614-.204-1.163-.56-1.726-1.116l-.227-.235c-.753-.812-1.534-1.976-2.493-3.586l-1.43-2.41-.544-.895-1.766 3.13-.343.592C7.597 19.156 6.227 20 4.356 20c-1.21 0-2.205-.42-2.936-1.182l-.168-.184c-.484-.573-.837-1.311-1.043-2.189l-.067-.32a8.69 8.69 0 01-.136-1.288L0 14.468c.002-.745.06-1.49.174-2.23l.1-.573c.298-1.53.828-2.958 1.536-4.157l.209-.34c1.177-1.83 2.789-3.053 4.615-3.16L6.897 4zm-.033 2.615l-.201.01c-.83.083-1.606.673-2.252 1.577l-.138.199-.01.018c-.67 1.017-1.185 2.378-1.456 3.845l-.004.022a12.591 12.591 0 00-.207 2.254l.002.188c.004.18.017.36.04.54l.043.291c.092.503.257.908.486 1.208l.117.137c.303.323.698.492 1.17.492 1.1 0 1.796-.676 3.696-3.641l2.175-3.4.454-.701-.139-.198C9.11 7.3 8.084 6.616 6.864 6.616zm10.196-.552l-.176.007c-.635.048-1.223.359-1.82.933l-.196.198c-.439.462-.887 1.064-1.367 1.807l.266.398c.18.274.362.56.55.858l.293.475 1.396 2.335.695 1.114c.583.926 1.03 1.6 1.408 2.082l.213.262c.282.326.529.54.777.673l.102.05c.227.1.457.138.718.138.176.002.35-.023.518-.073.338-.104.61-.32.813-.637l.095-.163.077-.162c.194-.459.29-1.06.29-1.785l-.006-.449c-.08-2.871-.938-5.372-2.2-6.798l-.176-.189c-.67-.683-1.444-1.074-2.27-1.074z"></path></svg>`,
|
|
13
15
|
moonshot: `<svg class="logo" viewBox="0 0 24 24" fill="currentColor" fill-rule="evenodd" aria-hidden="true"><path d="M1.052 16.916l9.539 2.552a21.007 21.007 0 00.06 2.033l5.956 1.593a11.997 11.997 0 01-5.586.865l-.18-.016-.044-.004-.084-.009-.094-.01a11.605 11.605 0 01-.157-.02l-.107-.014-.11-.016a11.962 11.962 0 01-.32-.051l-.042-.008-.075-.013-.107-.02-.07-.015-.093-.019-.075-.016-.095-.02-.097-.023-.094-.022-.068-.017-.088-.022-.09-.024-.095-.025-.082-.023-.109-.03-.062-.02-.084-.025-.093-.028-.105-.034-.058-.019-.08-.026-.09-.031-.066-.024a6.293 6.293 0 01-.044-.015l-.068-.025-.101-.037-.057-.022-.08-.03-.087-.035-.088-.035-.079-.032-.095-.04-.063-.028-.063-.027a5.655 5.655 0 01-.041-.018l-.066-.03-.103-.047-.052-.024-.096-.046-.062-.03-.084-.04-.086-.044-.093-.047-.052-.027-.103-.055-.057-.03-.058-.032a6.49 6.49 0 01-.046-.026l-.094-.053-.06-.034-.051-.03-.072-.041-.082-.05-.093-.056-.052-.032-.084-.053-.061-.039-.079-.05-.07-.047-.053-.035a7.785 7.785 0 01-.054-.036l-.044-.03-.044-.03a6.066 6.066 0 01-.04-.028l-.057-.04-.076-.054-.069-.05-.074-.054-.056-.042-.076-.057-.076-.059-.086-.067-.045-.035-.064-.052-.074-.06-.089-.073-.046-.039-.046-.039a7.516 7.516 0 01-.043-.037l-.045-.04-.061-.053-.07-.062-.068-.06-.062-.058-.067-.062-.053-.05-.088-.084a13.28 13.28 0 01-.099-.097l-.029-.028-.041-.042-.069-.07-.05-.051-.05-.053a6.457 6.457 0 01-.168-.179l-.08-.088-.062-.07-.071-.08-.042-.049-.053-.062-.058-.068-.046-.056a7.175 7.175 0 01-.027-.033l-.045-.055-.066-.082-.041-.052-.05-.064-.02-.025a11.99 11.99 0 01-1.44-2.402zm-1.02-5.794l11.353 3.037a20.468 20.468 0 00-.469 2.011l10.817 2.894a12.076 12.076 0 01-1.845 2.005L.657 15.923l-.016-.046-.035-.104a11.965 11.965 0 01-.05-.153l-.007-.023a11.896 11.896 0 01-.207-.741l-.03-.126-.018-.08-.021-.097-.018-.081-.018-.09-.017-.084-.018-.094c-.026-.141-.05-.283-.071-.426l-.017-.118-.011-.083-.013-.102a12.01 12.01 0 01-.019-.161l-.005-.047a12.12 12.12 0 01-.034-2.145zm1.593-5.15l11.948 3.196c-.368.605-.705 1.231-1.01 1.875l11.295 3.022c-.142.82-.368 1.612-.668 2.365l-11.55-3.09L.124 10.26l.015-.1.008-.049.01-.067.015-.087.018-.098c.026-.148.056-.295.088-.442l.028-.124.02-.085.024-.097c.022-.09.045-.18.07-.268l.028-.102.023-.083.03-.1.025-.082.03-.096.026-.082.031-.095a11.896 11.896 0 011.01-2.232zm4.442-4.4L17.352 4.59a20.77 20.77 0 00-1.688 1.721l7.823 2.093c.267.852.442 1.744.513 2.665L2.106 5.213l.045-.065.027-.04.04-.055.046-.065.055-.076.054-.072.064-.086.05-.065.057-.073.055-.07.06-.074.055-.069.065-.077.054-.066.066-.077.053-.06.072-.082.053-.06.067-.074.054-.058.073-.078.058-.06.063-.067.168-.17.1-.098.059-.056.076-.071a12.084 12.084 0 012.272-1.677zM12.017 0h.097l.082.001.069.001.054.002.068.002.046.001.076.003.047.002.06.003.054.002.087.005.105.007.144.011.088.007.044.004.077.008.082.008.047.005.102.012.05.006.108.014.081.01.042.006.065.01.207.032.07.012.065.011.14.026.092.018.11.022.046.01.075.016.041.01L14.7.3l.042.01.065.015.049.012.071.017.096.024.112.03.113.03.113.032.05.015.07.02.078.024.073.023.05.016.05.016.076.025.099.033.102.036.048.017.064.023.093.034.11.041.116.045.1.04.047.02.06.024.041.018.063.026.04.018.057.025.11.048.1.046.074.035.075.036.06.028.092.046.091.045.102.052.053.028.049.026.046.024.06.033.041.022.052.029.088.05.106.06.087.051.057.034.053.032.096.059.088.055.098.062.036.024.064.041.084.056.04.027.062.042.062.043.023.017c.054.037.108.075.161.114l.083.06.065.048.056.043.086.065.082.064.04.03.05.041.086.069.079.065.085.071c.712.6 1.353 1.283 1.909 2.031L7.222.994l.062-.027.065-.028.081-.034.086-.035c.113-.045.227-.09.341-.131l.096-.035.093-.033.084-.03.096-.031c.087-.03.176-.058.264-.085l.091-.027.086-.025.102-.03.085-.023.1-.026L9.04.37l.09-.023.091-.022.095-.022.09-.02.098-.021.091-.02.095-.018.092-.018.1-.018.091-.016.098-.017.092-.014.097-.015.092-.013.102-.013.091-.012.105-.012.09-.01.105-.01c.093-.01.186-.018.28-.024l.106-.008.09-.005.11-.006.093-.004.1-.004.097-.002.099-.002.197-.002z"></path></svg>`,
|
|
14
16
|
openai: `<svg class="logo" viewBox="0 0 24 24" fill="currentColor" fill-rule="evenodd" aria-hidden="true"><path d="M9.205 8.658v-2.26c0-.19.072-.333.238-.428l4.543-2.616c.619-.357 1.356-.523 2.117-.523 2.854 0 4.662 2.212 4.662 4.566 0 .167 0 .357-.024.547l-4.71-2.759a.797.797 0 00-.856 0l-5.97 3.473zm10.609 8.8V12.06c0-.333-.143-.57-.429-.737l-5.97-3.473 1.95-1.118a.433.433 0 01.476 0l4.543 2.617c1.309.76 2.189 2.378 2.189 3.948 0 1.808-1.07 3.473-2.76 4.163zM7.802 12.703l-1.95-1.142c-.167-.095-.239-.238-.239-.428V5.899c0-2.545 1.95-4.472 4.591-4.472 1 0 1.927.333 2.712.928L8.23 5.067c-.285.166-.428.404-.428.737v6.898zM12 15.128l-2.795-1.57v-3.33L12 8.658l2.795 1.57v3.33L12 15.128zm1.796 7.23c-1 0-1.927-.332-2.712-.927l4.686-2.712c.285-.166.428-.404.428-.737v-6.898l1.974 1.142c.167.095.238.238.238.428v5.233c0 2.545-1.974 4.472-4.614 4.472zm-5.637-5.303l-4.544-2.617c-1.308-.761-2.188-2.378-2.188-3.948A4.482 4.482 0 014.21 6.327v5.423c0 .333.143.571.428.738l5.947 3.449-1.95 1.118a.432.432 0 01-.476 0zm-.262 3.9c-2.688 0-4.662-2.021-4.662-4.519 0-.19.024-.38.047-.57l4.686 2.71c.286.167.571.167.856 0l5.97-3.448v2.26c0 .19-.07.333-.237.428l-4.543 2.616c-.619.357-1.356.523-2.117.523zm5.899 2.83a5.947 5.947 0 005.827-4.756C22.287 18.339 24 15.84 24 13.296c0-1.665-.713-3.282-1.998-4.448.119-.5.19-.999.19-1.498 0-3.401-2.759-5.947-5.946-5.947-.642 0-1.26.095-1.88.31A5.962 5.962 0 0010.205 0a5.947 5.947 0 00-5.827 4.757C1.713 5.447 0 7.945 0 10.49c0 1.666.713 3.283 1.998 4.448-.119.5-.19 1-.19 1.499 0 3.401 2.759 5.946 5.946 5.946.642 0 1.26-.095 1.88-.309a5.96 5.96 0 004.162 1.713z"></path></svg>`,
|
|
@@ -23,6 +25,9 @@ const MARK_FOR = {
|
|
|
23
25
|
openai_codex: "openai",
|
|
24
26
|
meta_muse: "meta",
|
|
25
27
|
opencode_go: "opencode",
|
|
28
|
+
github_copilot: "githubcopilot",
|
|
29
|
+
xai_grok: "grok",
|
|
30
|
+
vercel_token_pass: "vercel",
|
|
26
31
|
anthropic: "anthropic",
|
|
27
32
|
openai: "openai",
|
|
28
33
|
meta: "meta",
|
|
@@ -31,6 +36,8 @@ const MARK_FOR = {
|
|
|
31
36
|
google: "gemini",
|
|
32
37
|
openrouter: "openrouter",
|
|
33
38
|
"vercel-ai-gateway": "vercel",
|
|
39
|
+
"github-copilot": "githubcopilot",
|
|
40
|
+
"vercel-token-pass": "vercel",
|
|
34
41
|
};
|
|
35
42
|
/** The mark of a plan kind (`openai_codex`), key provider (`anthropic`), or gateway (`openrouter`); undefined when it has none. */
|
|
36
43
|
export function linkLogo(id) {
|
package/dist/link/endpoints.js
CHANGED
|
@@ -59,7 +59,7 @@ import { isReasoningEffort, providerForModel } from "@mupt-ai/dari-router/policy
|
|
|
59
59
|
import { bearerToken } from "../http/auth.js";
|
|
60
60
|
import { errorResponse, HttpError } from "../http/errors.js";
|
|
61
61
|
import { SUBSCRIPTION_PLAN_LABELS } from "./errors.js";
|
|
62
|
-
import {
|
|
62
|
+
import { modelSubscriptions, subscriptionClient } from "../models/subscriptions.js";
|
|
63
63
|
import { DEFAULT_ROUTER_ALIAS } from "../platform/routing_contract.js";
|
|
64
64
|
import { explicitModelId, explicitModelSlug } from "../protocol/input/router_model.js";
|
|
65
65
|
import { CANONICAL_MODELS, canonicalModelName } from "../models/canonical.js";
|
|
@@ -872,8 +872,10 @@ async function grantBody(platform, request, accessToken, detail) {
|
|
|
872
872
|
utilization: window.utilization,
|
|
873
873
|
resets_at: window.resetsAt,
|
|
874
874
|
})),
|
|
875
|
+
// A key's provider's models; a plan's are the ones it has an offering
|
|
876
|
+
// of, whoever makes them (every OpenCode Go model is another maker's).
|
|
875
877
|
models: models(served.get(client))
|
|
876
|
-
.filter((model) =>
|
|
878
|
+
.filter((model) => keyFor === undefined ? modelSubscriptions(model).includes(kind) : providerForModel(model) === keyFor)
|
|
877
879
|
.map(namedModel),
|
|
878
880
|
};
|
|
879
881
|
}),
|
|
@@ -1510,12 +1512,16 @@ function eventFor(authorize, step) {
|
|
|
1510
1512
|
origin: new URL(authorize.redirectUri).origin,
|
|
1511
1513
|
};
|
|
1512
1514
|
}
|
|
1513
|
-
// How a kind of plan reads on the page, and whose sign-in connects it.
|
|
1515
|
+
// How a kind of plan reads on the page, and whose sign-in connects it. A
|
|
1516
|
+
// `pastedKey` plan connects with a key the user creates there instead.
|
|
1514
1517
|
const KINDS = {
|
|
1515
1518
|
anthropic_claude_code: { name: "Claude", plan: "Pro, Max or Ultra plan", at: "Claude" },
|
|
1516
1519
|
openai_codex: { name: "ChatGPT", plan: "Plus or Pro plan", at: "OpenAI" },
|
|
1517
1520
|
meta_muse: { name: "Meta Muse", plan: "Muse Code plan", at: "Meta" },
|
|
1518
1521
|
opencode_go: { name: "OpenCode Go", plan: "Go plan", at: "OpenCode" },
|
|
1522
|
+
github_copilot: { name: "GitHub Copilot", plan: "Copilot plan", at: "GitHub" },
|
|
1523
|
+
xai_grok: { name: "Grok", plan: "SuperGrok plan", at: "xAI" },
|
|
1524
|
+
vercel_token_pass: { name: "Vercel Token Pass", plan: "Token Pass", at: "Vercel", pastedKey: true },
|
|
1519
1525
|
};
|
|
1520
1526
|
// The first page a new user sees: what connecting means, and one button.
|
|
1521
1527
|
function introPage(approval, authorize) {
|
|
@@ -1574,10 +1580,24 @@ function keyPage(authorize, provider, error, cookies = []) {
|
|
|
1574
1580
|
footer: `<button class="btn primary" type="submit" name="decision" value="add_key">Continue</button>`,
|
|
1575
1581
|
});
|
|
1576
1582
|
}
|
|
1577
|
-
// The provider's sign-in: a link to it, and the code to bring back or take
|
|
1583
|
+
// The provider's sign-in: a link to it, and the code to bring back or take
|
|
1584
|
+
// there; or, for a plan that is a key, where to create the key to paste back.
|
|
1578
1585
|
function providerPage(authorize, connect, error) {
|
|
1579
|
-
const { name, at } = KINDS[connect.kind];
|
|
1580
|
-
const open = (style) => `<a class="btn ${style}" href="${escapeHtml(connect.url)}" target="_blank" rel="noopener noreferrer">Open ${name}${ICONS.external}</a>`;
|
|
1586
|
+
const { name, at, pastedKey } = KINDS[connect.kind];
|
|
1587
|
+
const open = (style) => `<a class="btn ${style}" href="${escapeHtml(connect.url)}" target="_blank" rel="noopener noreferrer">Open ${pastedKey ? at : name}${ICONS.external}</a>`;
|
|
1588
|
+
if (pastedKey) {
|
|
1589
|
+
return pane(authorize, {
|
|
1590
|
+
title: `Add Your ${name} Key`,
|
|
1591
|
+
step: "connect_subscription",
|
|
1592
|
+
back: "select",
|
|
1593
|
+
error,
|
|
1594
|
+
body: `<span class="who">${logo(connect.kind, name)}</span>
|
|
1595
|
+
<h1>Add Your ${name} Key</h1>
|
|
1596
|
+
<div class="step"><span class="n">1</span><div><p>Create a ${name} key at ${at}.</p>${open("outline")}</div></div>
|
|
1597
|
+
<div class="step"><span class="n">2</span><div><label for="authorization_response">Paste the key.</label><input id="authorization_response" type="password" name="authorization_response" autocomplete="off" spellcheck="false" placeholder="Paste Key" required></div></div>`,
|
|
1598
|
+
footer: `<button class="btn primary" type="submit" name="decision" value="complete">Continue</button>`,
|
|
1599
|
+
});
|
|
1600
|
+
}
|
|
1581
1601
|
const head = `<span class="who">${logo(connect.kind, name)}</span>
|
|
1582
1602
|
<h1>Sign In To ${name}</h1>`;
|
|
1583
1603
|
if (connect.userCode === null) {
|
package/dist/link/errors.js
CHANGED
|
@@ -38,6 +38,9 @@ export const SUBSCRIPTION_PLAN_LABELS = {
|
|
|
38
38
|
openai_codex: "ChatGPT Plus/Pro",
|
|
39
39
|
meta_muse: "Meta Muse",
|
|
40
40
|
opencode_go: "OpenCode Go",
|
|
41
|
+
github_copilot: "GitHub Copilot",
|
|
42
|
+
xai_grok: "Grok",
|
|
43
|
+
vercel_token_pass: "Vercel Token Pass",
|
|
41
44
|
};
|
|
42
45
|
const ONLY_CLIENT = {
|
|
43
46
|
anthropic_claude_code: "Claude Code itself",
|
package/dist/link/self_hosted.js
CHANGED
|
@@ -5,7 +5,7 @@ import { randomBytes, randomUUID } from "node:crypto";
|
|
|
5
5
|
import { HttpError } from "../http/errors.js";
|
|
6
6
|
import { checkProviderKey } from "../providers/key_check.js";
|
|
7
7
|
import { gatewayKeyIndex } from "../self_host/resolve.js";
|
|
8
|
-
import { CODEX_APPROVAL_PENDING, META_APPROVAL_PENDING, OPENCODE_APPROVAL_PENDING, SUBSCRIPTION_PROVIDERS, SubscriptionOAuthInputError, SubscriptionOAuthProviderError, completeOAuth, currentUsage, startOAuth, } from "../self_host/subscriptions/index.js";
|
|
8
|
+
import { CODEX_APPROVAL_PENDING, GITHUB_APPROVAL_PENDING, META_APPROVAL_PENDING, OPENCODE_APPROVAL_PENDING, XAI_APPROVAL_PENDING, SUBSCRIPTION_PROVIDERS, SubscriptionOAuthInputError, SubscriptionOAuthProviderError, completeOAuth, currentUsage, startOAuth, } from "../self_host/subscriptions/index.js";
|
|
9
9
|
import { linkCompleteThrough } from "./in_flight.js";
|
|
10
10
|
import { LINK_KEY_PROVIDERS, linkKeyProviderName } from "./key_providers.js";
|
|
11
11
|
import { linkPlatform } from "./service.js";
|
|
@@ -113,7 +113,13 @@ export function selfHostedLink(deps) {
|
|
|
113
113
|
}
|
|
114
114
|
catch (error) {
|
|
115
115
|
if (error instanceof SubscriptionOAuthInputError) {
|
|
116
|
-
if ([
|
|
116
|
+
if ([
|
|
117
|
+
CODEX_APPROVAL_PENDING,
|
|
118
|
+
META_APPROVAL_PENDING,
|
|
119
|
+
OPENCODE_APPROVAL_PENDING,
|
|
120
|
+
GITHUB_APPROVAL_PENDING,
|
|
121
|
+
XAI_APPROVAL_PENDING,
|
|
122
|
+
].includes(error.message))
|
|
117
123
|
return null;
|
|
118
124
|
throw new HttpError(400, error.message, "invalid_request");
|
|
119
125
|
}
|
package/dist/models/catalog.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ProviderKeySource, ResolvedRouter } from "../types.js";
|
|
1
|
+
import type { ProviderCredential, ProviderKeySource, ResolvedRouter, ResolvedRouterModelConfig } from "../types.js";
|
|
2
2
|
/** Actual serving provider for a canonical model on a resolved managed router. */
|
|
3
3
|
export declare function executionProviderForModel(credentials: ResolvedRouter, model: string): string;
|
|
4
4
|
/**
|
|
@@ -7,3 +7,8 @@ export declare function executionProviderForModel(credentials: ResolvedRouter, m
|
|
|
7
7
|
* user-owned so unknown platform data cannot trigger managed-key billing.
|
|
8
8
|
*/
|
|
9
9
|
export declare function keySourceForModel(credentials: ResolvedRouter, model: string): ProviderKeySource;
|
|
10
|
+
/**
|
|
11
|
+
* The router as one of a model's fallbacks serves it: the fallback's config,
|
|
12
|
+
* and its plan's credential or, without one, the router's API credential.
|
|
13
|
+
*/
|
|
14
|
+
export declare function credentialsServedBy(credentials: ResolvedRouter, model: string, config: ResolvedRouterModelConfig, plan: ProviderCredential | undefined): ResolvedRouter;
|
|
@@ -15,3 +15,15 @@ export function keySourceForModel(credentials, model) {
|
|
|
15
15
|
return supplied.subscription ? "subscription" : "user";
|
|
16
16
|
return credentials.provider_key_sources?.[executionProviderForModel(credentials, model)] ?? "user";
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* The router as one of a model's fallbacks serves it: the fallback's config,
|
|
20
|
+
* and its plan's credential or, without one, the router's API credential.
|
|
21
|
+
*/
|
|
22
|
+
export function credentialsServedBy(credentials, model, config, plan) {
|
|
23
|
+
const { [model]: _replaced, ...others } = credentials.provider_credentials ?? {};
|
|
24
|
+
return {
|
|
25
|
+
...credentials,
|
|
26
|
+
model_configs: { ...credentials.model_configs, [model]: config },
|
|
27
|
+
provider_credentials: plan === undefined ? others : { ...others, [model]: plan },
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -10,6 +10,8 @@ const PROVIDER_LABELS = {
|
|
|
10
10
|
xai: "xAI",
|
|
11
11
|
google: "Google",
|
|
12
12
|
"opencode-go": "OpenCode Go",
|
|
13
|
+
"github-copilot": "GitHub Copilot",
|
|
14
|
+
"vercel-token-pass": "Vercel Token Pass",
|
|
13
15
|
dari: "Dari",
|
|
14
16
|
"amazon-bedrock": "Amazon Bedrock",
|
|
15
17
|
azure: "Microsoft Azure",
|
|
@@ -34,6 +36,13 @@ const PROVIDER_BASE_URLS = {
|
|
|
34
36
|
// A flat-rate plan for open models; each model keeps its own API path
|
|
35
37
|
// under https://opencode.ai/inference/go/, and this is chat completions.
|
|
36
38
|
"opencode-go": "https://opencode.ai/inference/go/openai/v1",
|
|
39
|
+
// Flat plans served only by personal subscriptions. Each Copilot account
|
|
40
|
+
// has its own API origin, named in its token (see github_copilot.ts); this
|
|
41
|
+
// one is the individual plans'.
|
|
42
|
+
"github-copilot": "https://api.individual.githubcopilot.com",
|
|
43
|
+
// A Token Pass key on Vercel AI Gateway, which serves only the gateway's
|
|
44
|
+
// featured models, over Anthropic Messages.
|
|
45
|
+
"vercel-token-pass": "https://ai-gateway.vercel.sh",
|
|
37
46
|
// Meta's Model API serves OpenAI Responses and Chat Completions here, and
|
|
38
47
|
// Anthropic Messages at https://api.meta.ai.
|
|
39
48
|
meta: "https://api.meta.ai/v1",
|