@mupt-ai/dari-gateway 1.0.367 → 1.0.369
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 +4 -3
- package/dist/link/client.d.ts +3 -1
- package/dist/link/client.js +4 -1
- package/dist/link/endpoints.js +33 -5
- package/dist/link/self_hosted.js +0 -1
- package/dist/platform/platform.d.ts +2 -0
- package/dist/platform/routing_contract.d.ts +1 -0
- package/dist/platform/routing_contract.js +4 -0
- package/dist/protocol/input/chat_completions.js +9 -13
- package/dist/protocol/input/chat_completions_validation.js +2 -7
- package/dist/protocol/input/openai_responses.js +3 -3
- package/dist/protocol/output/anthropic_messages.d.ts +1 -0
- package/dist/protocol/output/anthropic_messages.js +1 -1
- package/dist/protocol/output/anthropic_messages_output.d.ts +1 -1
- package/dist/protocol/output/anthropic_messages_output.js +3 -1
- package/dist/protocol/output/anthropic_messages_stream.d.ts +1 -0
- package/dist/protocol/output/anthropic_messages_stream.js +1 -1
- package/dist/protocol/output/chat_completions.d.ts +2 -0
- package/dist/protocol/output/chat_completions.js +5 -3
- package/dist/protocol/output/openai_responses.d.ts +1 -0
- package/dist/protocol/output/openai_responses.js +1 -1
- package/dist/protocol/output/openai_responses_output.d.ts +1 -1
- package/dist/protocol/output/openai_responses_output.js +3 -1
- package/dist/protocol/output/openai_responses_stream.d.ts +1 -0
- package/dist/protocol/output/openai_responses_stream.js +1 -1
- package/dist/providers/execution.js +2 -0
- package/dist/providers/provider_call.d.ts +1 -0
- package/dist/providers/provider_call.js +2 -0
- package/dist/runtime/prepare_routed_completion.d.ts +1 -0
- package/dist/runtime/prepare_routed_completion.js +4 -0
- package/dist/runtime/routed_completion.js +2 -0
- package/dist/runtime/routed_protocol.d.ts +2 -0
- package/dist/self_host/connected.d.ts +7 -3
- package/dist/self_host/connected.js +9 -10
- package/dist/self_host/hosted_sync.js +1 -1
- package/dist/self_host/main.d.ts +3 -2
- package/dist/self_host/main.js +16 -6
- package/dist/self_host/private_mode.d.ts +16 -0
- package/dist/self_host/private_mode.js +35 -0
- package/dist/self_host/resolve.js +5 -2
- package/dist/self_host/stub_gateway.d.ts +1 -0
- package/dist/self_host/stub_gateway.js +7 -6
- package/dist/self_host/stub_main.js +1 -1
- package/dist/self_host/subscriptions/http.js +2 -17
- package/dist/self_host/subscriptions/store.d.ts +7 -6
- package/dist/self_host/subscriptions/store.js +15 -27
- package/dist/telemetry/report.js +1 -0
- package/dist/types.d.ts +1 -0
- package/package.json +2 -2
- package/src/link/client.ts +7 -1
- package/src/link/endpoints.ts +38 -5
- package/src/link/self_hosted.ts +0 -1
- package/src/platform/platform.ts +6 -0
- package/src/platform/routing_contract.ts +5 -0
- package/src/protocol/input/chat_completions.ts +8 -18
- package/src/protocol/input/chat_completions_validation.ts +2 -9
- package/src/protocol/input/openai_responses.ts +3 -8
- package/src/protocol/output/anthropic_messages.ts +2 -1
- package/src/protocol/output/anthropic_messages_output.ts +4 -1
- package/src/protocol/output/anthropic_messages_stream.ts +2 -1
- package/src/protocol/output/chat_completions.ts +7 -3
- package/src/protocol/output/openai_responses.ts +2 -1
- package/src/protocol/output/openai_responses_output.ts +4 -1
- package/src/protocol/output/openai_responses_stream.ts +2 -1
- package/src/providers/execution.ts +2 -0
- package/src/providers/provider_call.ts +5 -0
- package/src/runtime/prepare_routed_completion.ts +4 -0
- package/src/runtime/routed_completion.ts +2 -0
- package/src/runtime/routed_protocol.ts +2 -0
- package/src/self_host/connected.ts +16 -12
- package/src/self_host/hosted_sync.ts +1 -1
- package/src/self_host/main.ts +14 -6
- package/src/self_host/private_mode.ts +41 -0
- package/src/self_host/resolve.ts +4 -2
- package/src/self_host/stub_gateway.ts +12 -7
- package/src/self_host/stub_main.ts +1 -1
- package/src/self_host/subscriptions/http.ts +2 -15
- package/src/self_host/subscriptions/store.ts +15 -34
- package/src/telemetry/report.ts +1 -0
- package/src/types.ts +3 -0
package/README.md
CHANGED
|
@@ -157,7 +157,7 @@ Dari Link lets another app send one user's model requests through the gateway on
|
|
|
157
157
|
|
|
158
158
|
**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 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.
|
|
159
159
|
|
|
160
|
-
**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
|
|
160
|
+
**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 one per provider with an app, or several when the app passes `allow_pooling=true`.
|
|
161
161
|
|
|
162
162
|
**Connect with Dari.** For the user it is one button. It opens Dari in a popup, where they connect a Claude or ChatGPT subscription by signing in to it (or already have), pick which plans the app may use, and approve; the popup closes and the app has a code. Nobody pastes a key, and nobody needs the CLI.
|
|
163
163
|
|
|
@@ -222,6 +222,7 @@ The gateway refuses a model the grant cannot serve, a plan at its limit, a spent
|
|
|
222
222
|
- `client`: the clients the app runs, space-separated, such as `client=claude_code codex`. Naming `claude_code` or `muse_code` lets the user grant plans that serve only that client.
|
|
223
223
|
- `plans`: the plan kinds to offer, such as `plans=openai_codex`; the page lists only those.
|
|
224
224
|
- `purpose_any_app`, `purpose_claude_code`, `purpose_muse_code`: up to 200 characters each, shown beside the plans of that audience as what the app says it does with them.
|
|
225
|
+
- `allow_pooling=true` (`allowPooling` in the client): the user may share several accounts of one provider, such as two ChatGPT plans, which Dari pools. By default they share at most one per plan kind or API key provider: the page ticks the first of each, ticking another unticks it, and an approval with two is refused.
|
|
225
226
|
- `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.
|
|
226
227
|
- `grant_id`: update mode (above).
|
|
227
228
|
|
|
@@ -318,7 +319,7 @@ A sandbox given a child token needs to reach only the gateway's host (for hosted
|
|
|
318
319
|
|
|
319
320
|
Error text replaces anything shaped like an `sk-` key with `sk-…`, and responses replace the serving plan's own credential wherever it appears.
|
|
320
321
|
|
|
321
|
-
**Client.** `@mupt-ai/dari-gateway/link/client` (fetch and Web Crypto only; browsers, Node, Bun, Deno; erasable TypeScript only, so `node` runs the `.ts` file as is) has `DariLink` (`open`, `callback`, `renderButton`), `exchange`, `linkFetch`, `grant`, `childToken`, `usage`, `revoke`, `refresh`, `createAuthorization` (a PKCE pair and state made on your server), `registerClient`, and `authorizeUrl` (the approval URL without a popup; takes `clients`, `plans`, `purposes`, and `grantId`). Every call takes `clientSecret` for a confidential client.
|
|
322
|
+
**Client.** `@mupt-ai/dari-gateway/link/client` (fetch and Web Crypto only; browsers, Node, Bun, Deno; erasable TypeScript only, so `node` runs the `.ts` file as is) has `DariLink` (`open`, `callback`, `renderButton`), `exchange`, `linkFetch`, `grant`, `childToken`, `usage`, `revoke`, `refresh`, `createAuthorization` (a PKCE pair and state made on your server), `registerClient`, and `authorizeUrl` (the approval URL without a popup; takes `clients`, `plans`, `keyProviders`, `purposes`, `allowPooling`, and `grantId`). Every call takes `clientSecret` for a confidential client.
|
|
322
323
|
|
|
323
324
|
`linkFetch`, `grant`, `childToken`, and `usage` take one grant's tokens in either of two ways:
|
|
324
325
|
|
|
@@ -409,7 +410,7 @@ A child token is simpler still when the agent runs somewhere you control: give t
|
|
|
409
410
|
|
|
410
411
|
**Users with their own gateway.** A user who runs their own gateway links it the same way: ask for its base URL, read `GET <base>/.well-known/oauth-authorization-server`, and register there with `POST /v1/link/register` (a server registers as a confidential client with `"token_endpoint_auth_method": "client_secret_basic"`). Keep each registration (client id, endpoints) keyed by the metadata's `issuer`, and show the issuer's host to the user wherever the link appears, so they can see which gateway an app is using.
|
|
411
412
|
|
|
412
|
-
**Testing an integration.** `startStubGateway` from `@mupt-ai/dari-gateway/self_host/stub_gateway` (Bun) runs a self-hosted gateway on stand-in plans, for example `{ plans: ["openai_codex"] }`, whose provider calls go to a local stand-in that answers "hi" (or your `upstream`), so tests make no paid calls. `gateway.app` is a server app already registered on it (`gatewayUrl`, `clientId`, `clientSecret`, `redirectUri`: your app's Dari Link settings in the test), and `gateway.connect({ credentialIds?, deny?, clients?, plans?, keyProviders?, grantId? })` is its user approving it: it resolves with what `DariLink.open` hands your page, `{ code, codeVerifier, state }`, or rejects with the `LinkError` it would. For an app you registered yourself, `gateway.approve(authorizeUrl, { credentialIds?, deny? })` goes through the approval page as a user would and returns what it hands your app, `{message, targetOrigin}` (the popup's `web_message` post, or the redirect's query), also kept in `gateway.messages`. `gateway.setState({ limited: true })` makes every provider call a usage-limit refusal (plans go `plan_limit` with `unavailable_until`, requests get 424 `subscription_exhausted`), and `{ five_hour: 0.4, weekly: 0.9 }` makes each reply report that plan usage (filling `plans[].usage`, and against a grant's budget leading to `grant_budget_exhausted`). `gateway.calls` records each provider call's path, model, thinking settings, the effort it is served at (for Claude models that take a per-turn effort, the latest effort message, not the top-level `output_config.effort` that stays fixed for caching), and client headers, to assert on. Under any other test runner, run it as a process: `dari-gateway-stub --plans openai_codex,anthropic_claude_code` (Bun runs it) prints one JSON line, `{"baseUrl", "gatewayKey", "planIds", "userCookie", "controlUrl", "app"}` (the stand-in plans belong to the approval page's user, and `userCookie` is the `Cookie` header that opens the page as them); `POST <controlUrl>/connect` takes `connect`'s options in snake case and answers `{"code", "code_verifier", "state"}`, `GET <controlUrl>/served` answers `{"calls": [...]}`, `POST <controlUrl>/approve` with `{"url", "credential_ids"?, "deny"?}` answers `{"message", "target_origin"}` (listed at `GET <controlUrl>/messages`), and `POST <controlUrl>/state` takes the same fields as `setState`. A gateway config can send ChatGPT plan traffic elsewhere the same way, with `providers.openai-codex.baseUrl`.
|
|
413
|
+
**Testing an integration.** `startStubGateway` from `@mupt-ai/dari-gateway/self_host/stub_gateway` (Bun) runs a self-hosted gateway on stand-in plans, for example `{ plans: ["openai_codex"] }`, whose provider calls go to a local stand-in that answers "hi" (or your `upstream`), so tests make no paid calls. `gateway.app` is a server app already registered on it (`gatewayUrl`, `clientId`, `clientSecret`, `redirectUri`: your app's Dari Link settings in the test), and `gateway.connect({ credentialIds?, deny?, clients?, plans?, keyProviders?, allowPooling?, grantId? })` is its user approving it (sharing what the page ticks unless `credentialIds`): it resolves with what `DariLink.open` hands your page, `{ code, codeVerifier, state }`, or rejects with the `LinkError` it would. For an app you registered yourself, `gateway.approve(authorizeUrl, { credentialIds?, deny? })` goes through the approval page as a user would and returns what it hands your app, `{message, targetOrigin}` (the popup's `web_message` post, or the redirect's query), also kept in `gateway.messages`. `gateway.setState({ limited: true })` makes every provider call a usage-limit refusal (plans go `plan_limit` with `unavailable_until`, requests get 424 `subscription_exhausted`), and `{ five_hour: 0.4, weekly: 0.9 }` makes each reply report that plan usage (filling `plans[].usage`, and against a grant's budget leading to `grant_budget_exhausted`). `gateway.calls` records each provider call's path, model, thinking settings, the effort it is served at (for Claude models that take a per-turn effort, the latest effort message, not the top-level `output_config.effort` that stays fixed for caching), and client headers, to assert on. Under any other test runner, run it as a process: `dari-gateway-stub --plans openai_codex,anthropic_claude_code` (Bun runs it) prints one JSON line, `{"baseUrl", "gatewayKey", "planIds", "userCookie", "controlUrl", "app"}` (the stand-in plans belong to the approval page's user, and `userCookie` is the `Cookie` header that opens the page as them); `POST <controlUrl>/connect` takes `connect`'s options in snake case and answers `{"code", "code_verifier", "state"}`, `GET <controlUrl>/served` answers `{"calls": [...]}`, `POST <controlUrl>/approve` with `{"url", "credential_ids"?, "deny"?}` answers `{"message", "target_origin"}` (listed at `GET <controlUrl>/messages`), and `POST <controlUrl>/state` takes the same fields as `setState`. A gateway config can send ChatGPT plan traffic elsewhere the same way, with `providers.openai-codex.baseUrl`.
|
|
413
414
|
|
|
414
415
|
## Embed
|
|
415
416
|
|
package/dist/link/client.d.ts
CHANGED
|
@@ -147,7 +147,8 @@ export declare function registerClient(args: Gateway & {
|
|
|
147
147
|
* `clients` names the clients the app runs, such as `claude_code`, so the
|
|
148
148
|
* user can grant plans that serve only those. `plans` limits the page to
|
|
149
149
|
* those plan kinds, such as `openai_codex`, or `"supported"`. `purposes` says what the app does
|
|
150
|
-
* with each audience's plans, shown beside them.
|
|
150
|
+
* with each audience's plans, shown beside them. The user shares at most one
|
|
151
|
+
* account per provider unless `allowPooling`. `grantId` (update mode)
|
|
151
152
|
* opens the page on that existing grant: the user changes its plans in place,
|
|
152
153
|
* its id and tokens stay, and the new code redeems for more tokens of it.
|
|
153
154
|
*/
|
|
@@ -183,6 +184,7 @@ export type AuthorizeOptions = {
|
|
|
183
184
|
claude_code?: string;
|
|
184
185
|
muse_code?: string;
|
|
185
186
|
};
|
|
187
|
+
allowPooling?: boolean;
|
|
186
188
|
grantId?: string;
|
|
187
189
|
responseMode?: "query" | "web_message";
|
|
188
190
|
};
|
package/dist/link/client.js
CHANGED
|
@@ -102,7 +102,8 @@ export async function registerClient(args) {
|
|
|
102
102
|
* `clients` names the clients the app runs, such as `claude_code`, so the
|
|
103
103
|
* user can grant plans that serve only those. `plans` limits the page to
|
|
104
104
|
* those plan kinds, such as `openai_codex`, or `"supported"`. `purposes` says what the app does
|
|
105
|
-
* with each audience's plans, shown beside them.
|
|
105
|
+
* with each audience's plans, shown beside them. The user shares at most one
|
|
106
|
+
* account per provider unless `allowPooling`. `grantId` (update mode)
|
|
106
107
|
* opens the page on that existing grant: the user changes its plans in place,
|
|
107
108
|
* its id and tokens stay, and the new code redeems for more tokens of it.
|
|
108
109
|
*/
|
|
@@ -128,6 +129,7 @@ export async function createLinkToken(args) {
|
|
|
128
129
|
...(args.clients?.length ? { client: args.clients } : {}),
|
|
129
130
|
...(args.keyProviders?.length ? { key_providers: args.keyProviders } : {}),
|
|
130
131
|
...(args.purposes ? { purposes: args.purposes } : {}),
|
|
132
|
+
...(args.allowPooling ? { allow_pooling: true } : {}),
|
|
131
133
|
...(args.grantId ? { grant_id: args.grantId } : {}),
|
|
132
134
|
}),
|
|
133
135
|
});
|
|
@@ -159,6 +161,7 @@ function authorizationUrl(args) {
|
|
|
159
161
|
...(args.clients?.length ? { client: args.clients.join(" ") } : {}),
|
|
160
162
|
...(args.plans?.length ? { plans: [args.plans].flat().join(" ") } : {}),
|
|
161
163
|
...(args.keyProviders?.length ? { key_providers: args.keyProviders.join(" ") } : {}),
|
|
164
|
+
...(args.allowPooling ? { allow_pooling: "true" } : {}),
|
|
162
165
|
...(args.grantId ? { grant_id: args.grantId } : {}),
|
|
163
166
|
...Object.fromEntries(Object.entries(args.purposes ?? {}).flatMap(([audience, purpose]) => purpose ? [[`purpose_${audience}`, purpose]] : [])),
|
|
164
167
|
}).toString();
|
package/dist/link/endpoints.js
CHANGED
|
@@ -1000,8 +1000,8 @@ function oauthError(error, description, status = 400, headers = {}, errorCode) {
|
|
|
1000
1000
|
* secret alone: no state or PKCE for the app to keep. JSON body:
|
|
1001
1001
|
* `client_id`, `secret` (or HTTP Basic), and optionally `redirect_uri` (one
|
|
1002
1002
|
* the app registered; default its first), `plans`, `client`, `key_providers`
|
|
1003
|
-
* (arrays), `purposes` ({ any_app, claude_code, muse_code }),
|
|
1004
|
-
* for update mode.
|
|
1003
|
+
* (arrays), `purposes` ({ any_app, claude_code, muse_code }), `allow_pooling`
|
|
1004
|
+
* (true), and `grant_id` for update mode.
|
|
1005
1005
|
*/
|
|
1006
1006
|
async function createLinkToken(link, request) {
|
|
1007
1007
|
let body;
|
|
@@ -1027,6 +1027,7 @@ async function createLinkToken(link, request) {
|
|
|
1027
1027
|
...(list("plans") ? { plans: list("plans") } : {}),
|
|
1028
1028
|
...(list("client") ? { client: list("client") } : {}),
|
|
1029
1029
|
...(list("key_providers") ? { key_providers: list("key_providers") } : {}),
|
|
1030
|
+
...(body.allow_pooling === true ? { allow_pooling: "true" } : {}),
|
|
1030
1031
|
...(typeof body.grant_id === "string" ? { grant_id: body.grant_id } : {}),
|
|
1031
1032
|
...Object.fromEntries(PLAN_AUDIENCES.flatMap((audience) => typeof purposes[audience] === "string" ? [[`purpose_${audience}`, purposes[audience]]] : [])),
|
|
1032
1033
|
};
|
|
@@ -1140,6 +1141,10 @@ async function authorizeRequest(link, params) {
|
|
|
1140
1141
|
if (purpose)
|
|
1141
1142
|
purposes[audience] = purpose.slice(0, MAX_PURPOSE_CHARS);
|
|
1142
1143
|
}
|
|
1144
|
+
const allowPooling = params.get("allow_pooling");
|
|
1145
|
+
if (allowPooling !== null && allowPooling !== "true" && allowPooling !== "false") {
|
|
1146
|
+
return badRequest("allow_pooling is true or false.");
|
|
1147
|
+
}
|
|
1143
1148
|
const grantId = params.get("grant_id");
|
|
1144
1149
|
if (grantId !== null && !GRANT_ID.test(grantId)) {
|
|
1145
1150
|
return badRequest("grant_id names one of the user's grants for this app.");
|
|
@@ -1154,6 +1159,7 @@ async function authorizeRequest(link, params) {
|
|
|
1154
1159
|
plans: plans.length === 0 ? null : plans,
|
|
1155
1160
|
keyProviders: keyProviders.length === 0 ? null : keyProviders,
|
|
1156
1161
|
purposes,
|
|
1162
|
+
allowPooling: allowPooling === "true",
|
|
1157
1163
|
grantId,
|
|
1158
1164
|
};
|
|
1159
1165
|
}
|
|
@@ -1288,6 +1294,11 @@ async function authorizeSubmit(link, request, form) {
|
|
|
1288
1294
|
if (!credentialIds.every((id) => usable.has(id))) {
|
|
1289
1295
|
return choosePage(authorize, session, subscriptions, current, `${authorize.app.name} cannot use one of the plans you chose.`);
|
|
1290
1296
|
}
|
|
1297
|
+
const pooled = authorize.allowPooling ? undefined : subscriptions.find((subscription, index) => credentialIds.includes(subscription.id)
|
|
1298
|
+
&& subscriptions.slice(0, index).some((other) => credentialIds.includes(other.id) && pool(other) === pool(subscription)));
|
|
1299
|
+
if (pooled !== undefined) {
|
|
1300
|
+
return choosePage(authorize, session, subscriptions, current, `${authorize.app.name} uses one account per provider: choose one ${planName(pooled)}${pooled.apiKeyProvider === undefined ? " account" : ""}.`);
|
|
1301
|
+
}
|
|
1291
1302
|
const limits = limitsFromForm(form, credentialIds);
|
|
1292
1303
|
if (limits === null)
|
|
1293
1304
|
return choosePage(authorize, session, subscriptions, current, LIMITS_ERROR);
|
|
@@ -1775,8 +1786,13 @@ function providerPage(authorize, connect, error) {
|
|
|
1775
1786
|
function choosePage(authorize, session, subscriptions, current, error) {
|
|
1776
1787
|
const app = escapeHtml(authorize.app.name);
|
|
1777
1788
|
const plans = shareable(authorize, subscriptions);
|
|
1778
|
-
// A new connection starts with every plan ticked; an update, with the plans
|
|
1779
|
-
|
|
1789
|
+
// A new connection starts with every plan ticked; an update, with the plans
|
|
1790
|
+
// it shares now. Without pooling, only the first of each provider's, so an
|
|
1791
|
+
// update of a grant made with pooling saves as it opens.
|
|
1792
|
+
const candidates = plans.filter((plan) => current === null || current.credentialIds.includes(plan.id));
|
|
1793
|
+
const ticked = new Set(candidates
|
|
1794
|
+
.filter((plan, index) => authorize.allowPooling || !candidates.slice(0, index).some((other) => pool(other) === pool(plan)))
|
|
1795
|
+
.map((plan) => plan.id));
|
|
1780
1796
|
return pane(authorize, {
|
|
1781
1797
|
title: current === null ? `Connect ${authorize.app.name}` : `Update Plans For ${authorize.app.name}`,
|
|
1782
1798
|
step: "choose_plans",
|
|
@@ -1798,8 +1814,14 @@ ${plans.map((plan) => {
|
|
|
1798
1814
|
<p class="fine">${app} keeps access until you or it disconnect. Its requests fail while a plan is at its usage limit or yours.</p>`,
|
|
1799
1815
|
});
|
|
1800
1816
|
}
|
|
1817
|
+
// Plans and keys of one pool: one kind of plan, or one provider's API keys.
|
|
1818
|
+
function pool(subscription) {
|
|
1819
|
+
return subscription.apiKeyProvider === undefined ? subscription.provider : `api_key:${subscription.apiKeyProvider}`;
|
|
1820
|
+
}
|
|
1801
1821
|
function planOption(authorize, subscription, ticked) {
|
|
1802
|
-
|
|
1822
|
+
// Without pooling, ticking one of a pool unticks the rest (see `page`).
|
|
1823
|
+
const pooled = authorize.allowPooling ? "" : ` data-pool="${escapeHtml(pool(subscription))}"`;
|
|
1824
|
+
const box = `<input type="checkbox"${pooled} name="credential_id" value="${escapeHtml(subscription.id)}"${ticked ? " checked" : ""}>`;
|
|
1803
1825
|
if (subscription.apiKeyProvider !== undefined) {
|
|
1804
1826
|
return `<label class="option pick">${logo(subscription.apiKeyProvider, subscription.name)}<span class="grow"><strong>${escapeHtml(subscription.name)}</strong><small>API key · ${escapeHtml(planLabel(subscription))}</small></span>${box}</label>`;
|
|
1805
1827
|
}
|
|
@@ -1842,6 +1864,7 @@ function authorizeFields(authorize) {
|
|
|
1842
1864
|
...(authorize.clients.length > 0 ? { client: authorize.clients.join(" ") } : {}),
|
|
1843
1865
|
...(authorize.plans !== null ? { plans: authorize.plans.join(" ") } : {}),
|
|
1844
1866
|
...(authorize.keyProviders !== null ? { key_providers: authorize.keyProviders.join(" ") } : {}),
|
|
1867
|
+
...(authorize.allowPooling ? { allow_pooling: "true" } : {}),
|
|
1845
1868
|
...Object.fromEntries(Object.entries(authorize.purposes).map(([audience, purpose]) => [`purpose_${audience}`, purpose])),
|
|
1846
1869
|
...(authorize.grantId !== null ? { grant_id: authorize.grantId } : {}),
|
|
1847
1870
|
};
|
|
@@ -1878,6 +1901,11 @@ function page(title, body, options = {}) {
|
|
|
1878
1901
|
const button = event.submitter;
|
|
1879
1902
|
if (!(button instanceof HTMLButtonElement) || button.form?.target) return;
|
|
1880
1903
|
setTimeout(() => { button.disabled = true; button.setAttribute("aria-busy", "true"); button.prepend(Object.assign(document.createElement("span"), { className: "spin" })); });
|
|
1904
|
+
});
|
|
1905
|
+
document.addEventListener("change", (event) => {
|
|
1906
|
+
const box = event.target;
|
|
1907
|
+
if (!(box instanceof HTMLInputElement) || !box.checked || !box.dataset.pool) return;
|
|
1908
|
+
for (const other of box.form?.querySelectorAll("input[data-pool]") ?? []) if (other !== box && other.dataset.pool === box.dataset.pool) other.checked = false;
|
|
1881
1909
|
});</script>`;
|
|
1882
1910
|
options = { ...options, scriptNonce: busyNonce };
|
|
1883
1911
|
if (options.event !== undefined) {
|
package/dist/link/self_hosted.js
CHANGED
|
@@ -484,6 +484,7 @@ export type ResolveRouterRequest = {
|
|
|
484
484
|
includePublicEvalCatalog?: boolean;
|
|
485
485
|
clientHarness?: ClientHarness;
|
|
486
486
|
clientHeaders?: Record<string, string>;
|
|
487
|
+
private?: boolean;
|
|
487
488
|
provisional?: boolean;
|
|
488
489
|
};
|
|
489
490
|
export type ProviderCredentialRequest = {
|
|
@@ -563,6 +564,7 @@ export type RequestRecord = {
|
|
|
563
564
|
credentialId: string | null;
|
|
564
565
|
};
|
|
565
566
|
subscriptionCredentialId?: string;
|
|
567
|
+
private: boolean;
|
|
566
568
|
router: RequestRecordRouter;
|
|
567
569
|
candidates: Array<{
|
|
568
570
|
model: string;
|
|
@@ -6,3 +6,7 @@ export const ROUTING_PREFIX_HASHES_MAX_COUNT = 200;
|
|
|
6
6
|
// The provider id of hosted Dari when a gateway connected to it calls it for
|
|
7
7
|
// a model, as `dari/model/<id>` with the user's Dari key.
|
|
8
8
|
export const HOSTED_DARI_PROVIDER = "dari";
|
|
9
|
+
// A request with this header set to `true` stays out of Activity: the
|
|
10
|
+
// platform keeps only what billing needs. A gateway in private mode sets it on
|
|
11
|
+
// every request, and on each it hands hosted Dari.
|
|
12
|
+
export const PRIVATE_HEADER = "x-dari-private";
|
|
@@ -25,7 +25,7 @@ export function internalChatCompletionsToInteraction(request) {
|
|
|
25
25
|
});
|
|
26
26
|
continue;
|
|
27
27
|
}
|
|
28
|
-
const reasoningItems = chatReasoningItems(message
|
|
28
|
+
const reasoningItems = chatReasoningItems(message);
|
|
29
29
|
items.push(...reasoningItems);
|
|
30
30
|
items.push({
|
|
31
31
|
type: "message",
|
|
@@ -129,19 +129,19 @@ function hostedToolCallStatus(value, param) {
|
|
|
129
129
|
}
|
|
130
130
|
throw new HttpError(400, `${param} is not supported.`, "invalid_request_error", param);
|
|
131
131
|
}
|
|
132
|
-
function chatReasoningItems(message
|
|
132
|
+
function chatReasoningItems(message) {
|
|
133
133
|
if (message.role !== "assistant")
|
|
134
134
|
return [];
|
|
135
135
|
const readable = [message.reasoning_content, message.reasoning, message.reasoning_text]
|
|
136
136
|
.find((value) => typeof value === "string" && value.length > 0);
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
137
|
+
// A conversation begun on another provider carries that provider's reasoning
|
|
138
|
+
// details. They name no provider or model, so they cannot be replayed; the
|
|
139
|
+
// turn keeps its readable reasoning and the conversation continues.
|
|
140
|
+
const continuations = (message.reasoning_details ?? []).flatMap((detail) => {
|
|
141
|
+
if (detail.type !== "reasoning.encrypted" || typeof detail.data !== "string")
|
|
142
|
+
return [];
|
|
141
143
|
const continuation = decodeUntrustedProviderContinuationState(detail.data);
|
|
142
|
-
|
|
143
|
-
throw invalidChatContinuation(messageIndex, detailIndex);
|
|
144
|
-
return continuation;
|
|
144
|
+
return continuation ? [continuation] : [];
|
|
145
145
|
});
|
|
146
146
|
if (continuations.length === 0) {
|
|
147
147
|
return readable
|
|
@@ -156,10 +156,6 @@ function chatReasoningItems(message, messageIndex) {
|
|
|
156
156
|
continuation,
|
|
157
157
|
}));
|
|
158
158
|
}
|
|
159
|
-
function invalidChatContinuation(messageIndex, detailIndex) {
|
|
160
|
-
const param = `messages.${messageIndex}.reasoning_details.${detailIndex}.data`;
|
|
161
|
-
return new HttpError(400, `${param} must be a Dari provider continuation envelope; raw provider state has no recoverable provider/model provenance.`, "invalid_provider_continuation_state", param);
|
|
162
|
-
}
|
|
163
159
|
function contentShape(content) {
|
|
164
160
|
if (content === undefined)
|
|
165
161
|
return "absent";
|
|
@@ -69,13 +69,8 @@ function validateMessageReasoning(message, messageIndex) {
|
|
|
69
69
|
throw new HttpError(400, `messages[${messageIndex}].reasoning_details must be an array on an assistant message.`, "invalid_request_error", `messages.${messageIndex}.reasoning_details`);
|
|
70
70
|
}
|
|
71
71
|
for (const [detailIndex, detail] of message.reasoning_details.entries()) {
|
|
72
|
-
if (!isRecord(detail)
|
|
73
|
-
|
|
74
|
-
typeof detail.id !== "string" ||
|
|
75
|
-
!detail.id ||
|
|
76
|
-
typeof detail.data !== "string" ||
|
|
77
|
-
!detail.data) {
|
|
78
|
-
throw new HttpError(400, `messages[${messageIndex}].reasoning_details[${detailIndex}] is not a supported encrypted reasoning detail.`, "invalid_request_error", `messages.${messageIndex}.reasoning_details.${detailIndex}`);
|
|
72
|
+
if (!isRecord(detail)) {
|
|
73
|
+
throw new HttpError(400, `messages[${messageIndex}].reasoning_details[${detailIndex}] must be an object.`, "invalid_request_error", `messages.${messageIndex}.reasoning_details.${detailIndex}`);
|
|
79
74
|
}
|
|
80
75
|
}
|
|
81
76
|
}
|
|
@@ -307,11 +307,11 @@ function clientTurnId(value) {
|
|
|
307
307
|
: {};
|
|
308
308
|
}
|
|
309
309
|
function reasoningItem(value) {
|
|
310
|
+
// A conversation begun on OpenAI directly carries raw ciphertext. It names
|
|
311
|
+
// no provider or model, so it cannot be replayed; the item keeps its
|
|
312
|
+
// readable summary and the conversation continues.
|
|
310
313
|
const encoded = optionalString(value.encrypted_content, "input.reasoning.encrypted_content");
|
|
311
314
|
const continuation = encoded ? decodeUntrustedProviderContinuationState(encoded) : null;
|
|
312
|
-
if (encoded && !continuation) {
|
|
313
|
-
throw new HttpError(400, "input.reasoning.encrypted_content must be a Dari provider continuation envelope; raw provider ciphertext has no recoverable provider/model provenance.", "invalid_provider_continuation_state", "input.reasoning.encrypted_content");
|
|
314
|
-
}
|
|
315
315
|
return {
|
|
316
316
|
type: "reasoning",
|
|
317
317
|
id: optionalString(value.id, "input.reasoning.id"),
|
|
@@ -11,6 +11,6 @@ export function anthropicMessagesResponse(args) {
|
|
|
11
11
|
// As on Chat Completions. Null means unpriced, never a fabricated free request.
|
|
12
12
|
usage: { ...anthropicUsage(args.output), cost: args.modelCost ?? null },
|
|
13
13
|
...(args.output.safeguardResults ? { safeguard_results: args.output.safeguardResults } : {}),
|
|
14
|
-
dari_routing: anthropicRouting(args.routing, args.id, args.conversationId),
|
|
14
|
+
dari_routing: anthropicRouting(args.routing, args.id, args.conversationId, args.private),
|
|
15
15
|
};
|
|
16
16
|
}
|
|
@@ -7,4 +7,4 @@ export declare function anthropicReasoningBlock(item: Extract<InteractionOutput[
|
|
|
7
7
|
}>): Record<string, unknown>;
|
|
8
8
|
export declare function anthropicStopReason(output: Pick<InteractionOutput, "stopReason">): string;
|
|
9
9
|
export declare function anthropicUsage(output: Pick<InteractionOutput, "usage">): Record<string, unknown>;
|
|
10
|
-
export declare function anthropicRouting(decision: ServedDecision, requestId: string, conversationId?: string): Record<string, unknown>;
|
|
10
|
+
export declare function anthropicRouting(decision: ServedDecision, requestId: string, conversationId?: string, isPrivate?: boolean): Record<string, unknown>;
|
|
@@ -111,7 +111,7 @@ export function anthropicUsage(output) {
|
|
|
111
111
|
output_tokens: output.usage.output,
|
|
112
112
|
};
|
|
113
113
|
}
|
|
114
|
-
export function anthropicRouting(decision, requestId, conversationId) {
|
|
114
|
+
export function anthropicRouting(decision, requestId, conversationId, isPrivate) {
|
|
115
115
|
return {
|
|
116
116
|
requested_model: "dari/routing",
|
|
117
117
|
selected_model: decision.selectedModel,
|
|
@@ -119,6 +119,8 @@ export function anthropicRouting(decision, requestId, conversationId) {
|
|
|
119
119
|
reason: decision.reason,
|
|
120
120
|
request_id: requestId,
|
|
121
121
|
...(conversationId ? { conversation_id: conversationId } : {}),
|
|
122
|
+
// Kept out of Activity, so no link to it there.
|
|
123
|
+
...(isPrivate ? { private: true } : {}),
|
|
122
124
|
...(decision.leaseTurnsRemaining === undefined
|
|
123
125
|
? {}
|
|
124
126
|
: { lease_turns_remaining: decision.leaseTurnsRemaining }),
|
|
@@ -8,6 +8,7 @@ export declare function anthropicMessagesSseStream(args: {
|
|
|
8
8
|
source: ProviderIdentity;
|
|
9
9
|
request: InteractionRequest;
|
|
10
10
|
conversationId?: string;
|
|
11
|
+
private?: boolean;
|
|
11
12
|
onFinal?: (outcome: ProviderStreamOutcome) => void;
|
|
12
13
|
modelCost?: (message: Record<string, unknown>, failed: boolean) => number | null;
|
|
13
14
|
beforeClose?: (outcome: ProviderStreamOutcome) => Promise<void> | void;
|
|
@@ -33,7 +33,7 @@ export function anthropicMessagesSseStream(args) {
|
|
|
33
33
|
stop_reason: null,
|
|
34
34
|
stop_sequence: null,
|
|
35
35
|
usage: { input_tokens: 0, output_tokens: 0 },
|
|
36
|
-
dari_routing: anthropicRouting(args.routing, args.id, args.conversationId),
|
|
36
|
+
dari_routing: anthropicRouting(args.routing, args.id, args.conversationId, args.private),
|
|
37
37
|
},
|
|
38
38
|
});
|
|
39
39
|
const argumentDeltaIndexes = new Set();
|
|
@@ -8,6 +8,7 @@ export declare function chatCompletionResponse(args: {
|
|
|
8
8
|
modelCost?: number | null;
|
|
9
9
|
routing: RoutingDecision;
|
|
10
10
|
conversationId?: string;
|
|
11
|
+
private?: boolean;
|
|
11
12
|
}): Record<string, unknown>;
|
|
12
13
|
export declare function chatCompletionsSseStream(args: {
|
|
13
14
|
id: string;
|
|
@@ -17,6 +18,7 @@ export declare function chatCompletionsSseStream(args: {
|
|
|
17
18
|
source: ProviderIdentity;
|
|
18
19
|
request: InteractionRequest;
|
|
19
20
|
conversationId?: string;
|
|
21
|
+
private?: boolean;
|
|
20
22
|
onFinal?: (outcome: ProviderStreamOutcome) => void;
|
|
21
23
|
modelCost?: (message: Record<string, unknown>, failed: boolean) => number | null;
|
|
22
24
|
beforeClose?: (outcome: ProviderStreamOutcome) => Promise<void> | void;
|
|
@@ -19,7 +19,7 @@ export function chatCompletionResponse(args) {
|
|
|
19
19
|
},
|
|
20
20
|
],
|
|
21
21
|
usage: usagePayload(args.output, args.modelCost),
|
|
22
|
-
dari_routing: routingPayload(args.routing, args.id, args.conversationId),
|
|
22
|
+
dari_routing: routingPayload(args.routing, args.id, args.conversationId, args.private),
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
export function chatCompletionsSseStream(args) {
|
|
@@ -45,7 +45,7 @@ export function chatCompletionsSseStream(args) {
|
|
|
45
45
|
send({ ...errorChunk({ completion, created, model: args.model, message: providerFailureMessage(message) }),
|
|
46
46
|
usage: usagePayload(message, args.modelCost?.(message, true)) });
|
|
47
47
|
};
|
|
48
|
-
send(chunk({ completion, created, model: args.model, delta: {}, finishReason: null, routing: routingPayload(args.routing, args.id, args.conversationId) }));
|
|
48
|
+
send(chunk({ completion, created, model: args.model, delta: {}, finishReason: null, routing: routingPayload(args.routing, args.id, args.conversationId, args.private) }));
|
|
49
49
|
send(chunk({ completion, created, model: args.model, delta: { role: "assistant" }, finishReason: null }));
|
|
50
50
|
const argumentDeltaSeen = new Set();
|
|
51
51
|
const toolCallIdsSeen = new Set();
|
|
@@ -189,7 +189,7 @@ export function chatCompletionsSseStream(args) {
|
|
|
189
189
|
},
|
|
190
190
|
});
|
|
191
191
|
}
|
|
192
|
-
function routingPayload(decision, requestId, conversationId) {
|
|
192
|
+
function routingPayload(decision, requestId, conversationId, isPrivate) {
|
|
193
193
|
return {
|
|
194
194
|
requested_model: "dari/routing",
|
|
195
195
|
selected_model: decision.selectedModel,
|
|
@@ -197,6 +197,8 @@ function routingPayload(decision, requestId, conversationId) {
|
|
|
197
197
|
reason: decision.reason,
|
|
198
198
|
request_id: requestId,
|
|
199
199
|
...(conversationId ? { conversation_id: conversationId } : {}),
|
|
200
|
+
// Kept out of Activity, so no link to it there.
|
|
201
|
+
...(isPrivate ? { private: true } : {}),
|
|
200
202
|
};
|
|
201
203
|
}
|
|
202
204
|
function chunk(args) {
|
|
@@ -7,5 +7,6 @@ export declare function openAIResponsesResponse(args: {
|
|
|
7
7
|
request: InteractionRequest;
|
|
8
8
|
routing: RoutingDecision;
|
|
9
9
|
conversationId?: string;
|
|
10
|
+
private?: boolean;
|
|
10
11
|
}): Record<string, unknown>;
|
|
11
12
|
import type { RoutingDecision } from "@mupt-ai/dari-router/policy-engine";
|
|
@@ -10,6 +10,6 @@ export function openAIResponsesResponse(args) {
|
|
|
10
10
|
// As on Chat Completions. Null means unpriced, never a fabricated free request.
|
|
11
11
|
usage: { ...openAIResponsesUsage(args.output), cost: args.modelCost ?? null },
|
|
12
12
|
parallel_tool_calls: args.request.parallelToolCalls ?? true,
|
|
13
|
-
dari_routing: openAIResponsesRouting(args.routing, args.id, args.conversationId),
|
|
13
|
+
dari_routing: openAIResponsesRouting(args.routing, args.id, args.conversationId, args.private),
|
|
14
14
|
};
|
|
15
15
|
}
|
|
@@ -9,6 +9,6 @@ export declare function openAIResponsesTerminal(output: Pick<InteractionOutput,
|
|
|
9
9
|
export declare function openAIResponsesOutputItems(output: InteractionOutput): Array<Record<string, unknown>>;
|
|
10
10
|
export declare function openAIResponsesOutputItem(output: InteractionOutput, item: InteractionOutput["items"][number], index: number): Record<string, unknown>;
|
|
11
11
|
export declare function openAIResponsesUsage(output: Pick<InteractionOutput, "usage">): Record<string, unknown>;
|
|
12
|
-
export declare function openAIResponsesRouting(decision: RoutingDecision, requestId: string, conversationId?: string): Record<string, unknown>;
|
|
12
|
+
export declare function openAIResponsesRouting(decision: RoutingDecision, requestId: string, conversationId?: string, isPrivate?: boolean): Record<string, unknown>;
|
|
13
13
|
export declare function responseMessageOutputItem(id: string, text: string): Record<string, unknown>;
|
|
14
14
|
import type { RoutingDecision } from "@mupt-ai/dari-router/policy-engine";
|
|
@@ -33,7 +33,7 @@ export function openAIResponsesUsage(output) {
|
|
|
33
33
|
total_tokens: output.usage.totalTokens || inputTokens + output.usage.output,
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
-
export function openAIResponsesRouting(decision, requestId, conversationId) {
|
|
36
|
+
export function openAIResponsesRouting(decision, requestId, conversationId, isPrivate) {
|
|
37
37
|
return {
|
|
38
38
|
requested_model: "dari/routing",
|
|
39
39
|
selected_model: decision.selectedModel,
|
|
@@ -41,6 +41,8 @@ export function openAIResponsesRouting(decision, requestId, conversationId) {
|
|
|
41
41
|
reason: decision.reason,
|
|
42
42
|
request_id: requestId,
|
|
43
43
|
...(conversationId ? { conversation_id: conversationId } : {}),
|
|
44
|
+
// Kept out of Activity, so no link to it there.
|
|
45
|
+
...(isPrivate ? { private: true } : {}),
|
|
44
46
|
};
|
|
45
47
|
}
|
|
46
48
|
export function responseMessageOutputItem(id, text) {
|
|
@@ -8,6 +8,7 @@ type StreamArgs = {
|
|
|
8
8
|
source: ProviderIdentity;
|
|
9
9
|
request: InteractionRequest;
|
|
10
10
|
conversationId?: string;
|
|
11
|
+
private?: boolean;
|
|
11
12
|
onFinal?: (outcome: ProviderStreamOutcome) => void;
|
|
12
13
|
modelCost?: (message: Record<string, unknown>, failed: boolean) => number | null;
|
|
13
14
|
beforeClose?: (outcome: ProviderStreamOutcome) => Promise<void> | void;
|
|
@@ -547,7 +547,7 @@ function responseEnvelope(args, id, createdAt, status, output, interaction, cost
|
|
|
547
547
|
parallel_tool_calls: args.request.parallelToolCalls ?? true,
|
|
548
548
|
// `cost` as on Chat Completions: null means unpriced.
|
|
549
549
|
...(interaction ? { usage: { ...openAIResponsesUsage(interaction), cost: cost ?? null } } : {}),
|
|
550
|
-
dari_routing: openAIResponsesRouting(args.routing, args.id, args.conversationId),
|
|
550
|
+
dari_routing: openAIResponsesRouting(args.routing, args.id, args.conversationId, args.private),
|
|
551
551
|
};
|
|
552
552
|
}
|
|
553
553
|
function sendFailure(send, args, responseId, createdAt, accumulator, error) {
|
|
@@ -83,6 +83,7 @@ export async function completeNonStreaming(args) {
|
|
|
83
83
|
request: args.interaction,
|
|
84
84
|
routing: choice.decision,
|
|
85
85
|
conversationId: choice.execution.conversationId,
|
|
86
|
+
private: choice.execution.private,
|
|
86
87
|
});
|
|
87
88
|
}
|
|
88
89
|
catch (error) {
|
|
@@ -399,6 +400,7 @@ export async function executeStreaming(args) {
|
|
|
399
400
|
source: started.providerStream.source,
|
|
400
401
|
request: args.interaction,
|
|
401
402
|
conversationId: execution.conversationId,
|
|
403
|
+
private: execution.private,
|
|
402
404
|
clientSignal: args.clientSignal,
|
|
403
405
|
modelCost: (message, failed) => args.reporter.modelCost({
|
|
404
406
|
model: args.choice.decision.selectedModel, reasoning_effort: args.choice.decision.reasoningEffort,
|
|
@@ -32,6 +32,7 @@ export type ProviderExecution = ProviderCallConfig & {
|
|
|
32
32
|
subscriptionSources?: Source[];
|
|
33
33
|
subscriptionResetMinHours?: number;
|
|
34
34
|
thinkingLevel: string;
|
|
35
|
+
private?: boolean;
|
|
35
36
|
usageContext: RoutingUsageContext | undefined;
|
|
36
37
|
headers: Record<string, string>;
|
|
37
38
|
};
|
|
@@ -64,6 +64,7 @@ export function prepareProviderExecution(args) {
|
|
|
64
64
|
: {}),
|
|
65
65
|
...(providerKeySource === "subscription" && supplied?.account ? { subscriptionAccount: supplied.account } : {}),
|
|
66
66
|
thinkingLevel,
|
|
67
|
+
...(args.credentials.private === true ? { private: true } : {}),
|
|
67
68
|
usageContext: usageContextFor({
|
|
68
69
|
billable: args.billable,
|
|
69
70
|
credentials: args.credentials,
|
|
@@ -81,6 +82,7 @@ export function prepareProviderExecution(args) {
|
|
|
81
82
|
? {}
|
|
82
83
|
: { "X-Dari-Lease-Turns-Remaining": String(args.decision.leaseTurnsRemaining) }),
|
|
83
84
|
...(args.decision.sessionPinned === true ? { "X-Dari-Session-Pinned": "true" } : {}),
|
|
85
|
+
...(args.credentials.private === true ? { "X-Dari-Private": "true" } : {}),
|
|
84
86
|
},
|
|
85
87
|
};
|
|
86
88
|
}
|
|
@@ -36,6 +36,7 @@ export declare function prepareRoutedCompletion(args: {
|
|
|
36
36
|
requestId: string;
|
|
37
37
|
clientRequestId: string | null;
|
|
38
38
|
tagsHeader: string | null;
|
|
39
|
+
privateRequest?: boolean;
|
|
39
40
|
clientHarness?: ClientHarness;
|
|
40
41
|
clientHeaders?: Record<string, string>;
|
|
41
42
|
harnessConversationIdentity?: HarnessConversationIdentity;
|
|
@@ -25,6 +25,7 @@ export async function prepareRoutedCompletion(args) {
|
|
|
25
25
|
apiKey: args.apiKey,
|
|
26
26
|
includePublicEvalCatalog: true,
|
|
27
27
|
clientHeaders: args.clientHeaders,
|
|
28
|
+
...(args.privateRequest ? { private: true } : {}),
|
|
28
29
|
};
|
|
29
30
|
// Direct /v1 callers are authenticated by API key, so their canonical
|
|
30
31
|
// organization router is not known until this resolve completes. Fingerprint
|
|
@@ -109,6 +110,9 @@ export async function prepareRoutedCompletion(args) {
|
|
|
109
110
|
const strictAccess = strictProviderAccess(credentials, roleModel.interaction);
|
|
110
111
|
const access = linkGrantAccess(strictAccess.credentials, strictAccess.interaction);
|
|
111
112
|
credentials = access.credentials;
|
|
113
|
+
// A Dari Link app's usage is read back from its requests, so they are kept.
|
|
114
|
+
if (args.privateRequest && !credentials.link_grant_id)
|
|
115
|
+
credentials = { ...credentials, private: true };
|
|
112
116
|
// A child token's tags label every request it makes, whatever the request says.
|
|
113
117
|
Object.assign(tags, credentials.link_tags);
|
|
114
118
|
args = {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { isBackgroundRequest } from "../interaction/types.js";
|
|
3
|
+
import { PRIVATE_HEADER } from "../platform/routing_contract.js";
|
|
3
4
|
import { explicitModelId } from "../protocol/input/router_model.js";
|
|
4
5
|
import { captureRequestError } from "../observability/errors.js";
|
|
5
6
|
import { assertAutoroutingAllowed, assertCreditAvailableBeforeRouting, routerSelectsModels } from "../telemetry/usage.js";
|
|
@@ -22,6 +23,7 @@ export async function handleRoutedCompletion(args) {
|
|
|
22
23
|
requestId,
|
|
23
24
|
clientRequestId,
|
|
24
25
|
tagsHeader: args.request.headers.get("x-dari-tags"),
|
|
26
|
+
privateRequest: args.request.headers.get(PRIVATE_HEADER) === "true",
|
|
25
27
|
clientHarness: args.clientHarness,
|
|
26
28
|
clientHeaders: clientHeaders(args.request.headers),
|
|
27
29
|
harnessConversationIdentity: args.harnessConversationIdentity,
|
|
@@ -9,6 +9,7 @@ export type RoutedCompletionResponseArgs = {
|
|
|
9
9
|
request: InteractionRequest;
|
|
10
10
|
routing: RoutingDecision;
|
|
11
11
|
conversationId?: string;
|
|
12
|
+
private?: boolean;
|
|
12
13
|
};
|
|
13
14
|
export type RoutedCompletionStreamArgs = {
|
|
14
15
|
id: string;
|
|
@@ -18,6 +19,7 @@ export type RoutedCompletionStreamArgs = {
|
|
|
18
19
|
source: ProviderIdentity;
|
|
19
20
|
request: InteractionRequest;
|
|
20
21
|
conversationId?: string;
|
|
22
|
+
private?: boolean;
|
|
21
23
|
onFinal?: (outcome: ProviderStreamOutcome) => void;
|
|
22
24
|
modelCost?: (message: Record<string, unknown>, failed: boolean) => number | null;
|
|
23
25
|
beforeClose?: (outcome: ProviderStreamOutcome) => Promise<void> | void;
|