@mupt-ai/dari-gateway 1.0.368 → 1.0.370
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/dist/harnesses/claude_code.d.ts +11 -0
- package/dist/{ingress/claude_code/request_context.js → harnesses/claude_code.js} +40 -1
- package/dist/harnesses/codex.d.ts +9 -0
- package/dist/harnesses/codex.js +112 -0
- package/dist/harnesses/hermes.d.ts +4 -0
- package/dist/harnesses/hermes.js +6 -0
- package/dist/harnesses/index.d.ts +34 -0
- package/dist/harnesses/index.js +13 -0
- package/dist/harnesses/muse_code.d.ts +9 -0
- package/dist/harnesses/muse_code.js +22 -0
- package/dist/harnesses/openclaw.d.ts +4 -0
- package/dist/harnesses/openclaw.js +6 -0
- package/dist/harnesses/opencode.d.ts +7 -0
- package/dist/harnesses/opencode.js +40 -0
- package/dist/harnesses/pi.d.ts +6 -0
- package/dist/harnesses/pi.js +23 -0
- package/dist/ingress/client_harness.d.ts +1 -2
- package/dist/ingress/client_harness.js +4 -39
- package/dist/ingress/harness_request.js +6 -3
- package/dist/ingress/models.js +2 -1
- package/dist/link/endpoints.js +5 -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/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.d.ts +1 -0
- package/dist/providers/execution.js +29 -7
- package/dist/providers/provider_call.d.ts +1 -0
- package/dist/providers/provider_call.js +2 -0
- package/dist/runtime/harness_identity/extract.d.ts +0 -8
- package/dist/runtime/harness_identity/extract.js +2 -201
- package/dist/runtime/harness_identity/ids.d.ts +2 -0
- package/dist/runtime/harness_identity/ids.js +26 -0
- package/dist/runtime/harness_identity/index.d.ts +1 -1
- package/dist/runtime/harness_identity/index.js +1 -1
- 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 +4 -1
- package/dist/runtime/routed_protocol.d.ts +2 -0
- package/dist/self_host/config.js +1 -1
- 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/router_models.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 +2 -1
- package/package.json +2 -2
- package/src/{ingress/claude_code/request_context.ts → harnesses/claude_code.ts} +56 -2
- package/src/harnesses/codex.ts +156 -0
- package/src/harnesses/hermes.ts +8 -0
- package/src/harnesses/index.ts +29 -0
- package/src/harnesses/muse_code.ts +30 -0
- package/src/harnesses/openclaw.ts +8 -0
- package/src/harnesses/opencode.ts +51 -0
- package/src/harnesses/pi.ts +28 -0
- package/src/ingress/client_harness.ts +4 -41
- package/src/ingress/harness_request.ts +9 -9
- package/src/ingress/models.ts +2 -1
- package/src/link/endpoints.ts +5 -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/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 +36 -7
- package/src/providers/provider_call.ts +5 -0
- package/src/runtime/harness_identity/extract.ts +2 -284
- package/src/runtime/harness_identity/ids.ts +41 -0
- package/src/runtime/harness_identity/index.ts +1 -10
- package/src/runtime/prepare_routed_completion.ts +4 -0
- package/src/runtime/routed_completion.ts +4 -1
- package/src/runtime/routed_protocol.ts +2 -0
- package/src/self_host/config.ts +1 -1
- 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/router_models.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 +5 -10
- package/dist/ingress/claude_code/request_context.d.ts +0 -4
- package/dist/ingress/muse_code.d.ts +0 -2
- package/dist/ingress/muse_code.js +0 -8
- package/src/ingress/muse_code.ts +0 -9
package/src/self_host/main.ts
CHANGED
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
servedRouterIds,
|
|
37
37
|
type ServedRouters,
|
|
38
38
|
} from "./router_specs.js";
|
|
39
|
+
import { handlePrivateModeRequest, PRIVATE_MODE_ROUTE, PrivateMode } from "./private_mode.js";
|
|
39
40
|
import { SessionPinStore } from "./session_pin_store.js";
|
|
40
41
|
import { handleSubscriptionRequest, SubscriptionStore } from "./subscriptions/index.js";
|
|
41
42
|
import { providerBaseUrls } from "./subscriptions/resets.js";
|
|
@@ -44,8 +45,8 @@ import { refreshStaleUsage } from "./subscriptions/usage.js";
|
|
|
44
45
|
const SUBSCRIPTION_ROUTES = "/v1/organizations/current/credentials";
|
|
45
46
|
// The models Dari serves, which the Dari CLI's model picker offers.
|
|
46
47
|
const CANONICAL_MODELS_ROUTE = "/v1/canonical-models";
|
|
47
|
-
// How often a connected gateway reads idle plans' usage, so
|
|
48
|
-
//
|
|
48
|
+
// How often a connected gateway reads idle plans' usage, so their meters move
|
|
49
|
+
// without a request here.
|
|
49
50
|
const IDLE_USAGE_INTERVAL_MS = 5 * 60_000;
|
|
50
51
|
|
|
51
52
|
/**
|
|
@@ -76,8 +77,9 @@ const IDLE_USAGE_INTERVAL_MS = 5 * 60_000;
|
|
|
76
77
|
* - `DARI_HOSTED_URL` and `DARI_HOSTED_API_KEY`: connect the gateway to hosted
|
|
77
78
|
* Dari (connected.ts), with `DARI_GATEWAY_ID`, `DARI_GATEWAY_NAME`, and
|
|
78
79
|
* `DARI_GATEWAY_ENCRYPTION_KEY`. It then serves the user's hosted routers on
|
|
79
|
-
* its own plans and then on hosted Dari, and syncs its
|
|
80
|
-
*
|
|
80
|
+
* its own plans and then on hosted Dari, and syncs its requests there unless
|
|
81
|
+
* private mode is on (`/v1/gateway/private`); Dari Link and Activity are
|
|
82
|
+
* hosted's.
|
|
81
83
|
*/
|
|
82
84
|
export async function startSelfHostedGateway(env: Record<string, string> = process.env as Record<string, string>) {
|
|
83
85
|
const hosted = hostedConnectionFromEnv(env);
|
|
@@ -103,6 +105,10 @@ export async function startSelfHostedGateway(env: Record<string, string> = proce
|
|
|
103
105
|
);
|
|
104
106
|
}
|
|
105
107
|
const subscriptions = new SubscriptionStore(db, secrets);
|
|
108
|
+
const privateMode = new PrivateMode(db);
|
|
109
|
+
// Plans marked private before private mode kept their requests out of
|
|
110
|
+
// Activity; the gateway now keeps all of them out instead.
|
|
111
|
+
if (subscriptions.clearLegacyPrivate()) privateMode.set(true);
|
|
106
112
|
const prefixes = new PrefixStore(db);
|
|
107
113
|
const sessionPins = new SessionPinStore(db);
|
|
108
114
|
const routerModels = new RouterModelStore(db);
|
|
@@ -180,7 +186,7 @@ export async function startSelfHostedGateway(env: Record<string, string> = proce
|
|
|
180
186
|
const routed = createRequestHandler({ platform, selectorBackend });
|
|
181
187
|
const gateway = hosted === null || sync === null || hostedRouter === null
|
|
182
188
|
? routed
|
|
183
|
-
: connectedHandler({ gateway: routed, gatewayKeys, hosted, hostedRouter, fetch });
|
|
189
|
+
: connectedHandler({ gateway: routed, gatewayKeys, hosted, hostedRouter, privateMode, fetch });
|
|
184
190
|
|
|
185
191
|
// Subscriptions, model lists, and router specs are managed with any gateway
|
|
186
192
|
// key; every other path is the gateway's own.
|
|
@@ -190,7 +196,8 @@ export async function startSelfHostedGateway(env: Record<string, string> = proce
|
|
|
190
196
|
|| pathname.startsWith(`${SUBSCRIPTION_ROUTES}/`)
|
|
191
197
|
|| pathname === CANONICAL_MODELS_ROUTE
|
|
192
198
|
|| ROUTER_MODELS_ROUTE.test(pathname)
|
|
193
|
-
|| ROUTERS_ROUTE.test(pathname)
|
|
199
|
+
|| ROUTERS_ROUTE.test(pathname)
|
|
200
|
+
|| pathname === PRIVATE_MODE_ROUTE;
|
|
194
201
|
if (!manages) return await gateway(request);
|
|
195
202
|
try {
|
|
196
203
|
if (gatewayKeyIndex(gatewayKeys, bearerToken(request.headers)) === null) {
|
|
@@ -199,6 +206,7 @@ export async function startSelfHostedGateway(env: Record<string, string> = proce
|
|
|
199
206
|
} catch (error) {
|
|
200
207
|
return errorResponse(error);
|
|
201
208
|
}
|
|
209
|
+
if (pathname === PRIVATE_MODE_ROUTE) return await handlePrivateModeRequest(request, privateMode).catch(errorResponse);
|
|
202
210
|
if (pathname === CANONICAL_MODELS_ROUTE && request.method === "GET") {
|
|
203
211
|
return Response.json({ data: CANONICAL_MODELS }, { headers: { "Cache-Control": "no-store" } });
|
|
204
212
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Database } from "bun:sqlite";
|
|
2
|
+
|
|
3
|
+
import { HttpError } from "../http/errors.js";
|
|
4
|
+
import { parseJsonRequest } from "../ingress/json.js";
|
|
5
|
+
|
|
6
|
+
/** `GET` reads private mode and `PUT {"private": true|false}` sets it. */
|
|
7
|
+
export const PRIVATE_MODE_ROUTE = "/v1/gateway/private";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Private mode of a gateway connected to hosted Dari, kept in its database:
|
|
11
|
+
* on, none of its requests reach Activity, whichever plan or Dari serves them.
|
|
12
|
+
* It sends none to hosted Activity, and asks hosted Dari to keep only what
|
|
13
|
+
* billing needs of each it serves (PRIVATE_HEADER).
|
|
14
|
+
*/
|
|
15
|
+
export class PrivateMode {
|
|
16
|
+
constructor(private readonly db: Database) {
|
|
17
|
+
db.run("CREATE TABLE IF NOT EXISTS gateway_settings (key TEXT PRIMARY KEY, value TEXT NOT NULL)");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get on(): boolean {
|
|
21
|
+
return this.db.query<{ value: string }, []>("SELECT value FROM gateway_settings WHERE key = 'private'").get()?.value === "1";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
set(on: boolean): void {
|
|
25
|
+
this.db.run(
|
|
26
|
+
"INSERT INTO gateway_settings (key, value) VALUES ('private', ?) ON CONFLICT (key) DO UPDATE SET value = excluded.value",
|
|
27
|
+
[on ? "1" : "0"],
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function handlePrivateModeRequest(request: Request, mode: PrivateMode): Promise<Response> {
|
|
33
|
+
if (request.method === "PUT") {
|
|
34
|
+
const body = await parseJsonRequest(request);
|
|
35
|
+
if (typeof body.private !== "boolean") throw new HttpError(400, "private must be true or false.", "invalid_request_error");
|
|
36
|
+
mode.set(body.private);
|
|
37
|
+
} else if (request.method !== "GET") {
|
|
38
|
+
throw new HttpError(405, "Use GET or PUT.", "method_not_allowed");
|
|
39
|
+
}
|
|
40
|
+
return Response.json({ private: mode.on }, { headers: { "Cache-Control": "no-store" } });
|
|
41
|
+
}
|
package/src/self_host/resolve.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from "@mupt-ai/dari-router/policy-engine";
|
|
11
11
|
import { HttpError } from "../http/errors.js";
|
|
12
12
|
import type { ResolveRouterRequest } from "../platform/platform.js";
|
|
13
|
-
import { DEFAULT_ROUTER_ALIAS, HOSTED_DARI_PROVIDER } from "../platform/routing_contract.js";
|
|
13
|
+
import { DEFAULT_ROUTER_ALIAS, HOSTED_DARI_PROVIDER, PRIVATE_HEADER } from "../platform/routing_contract.js";
|
|
14
14
|
import { explicitModelSlug } from "../protocol/input/router_model.js";
|
|
15
15
|
import { CLIENT_HARNESS_HEADER } from "../ingress/client_harness.js";
|
|
16
16
|
import {
|
|
@@ -461,7 +461,8 @@ function candidateConfig(
|
|
|
461
461
|
* called for `dari/model/<id>` with the user's Dari key, in Anthropic's API
|
|
462
462
|
* for Anthropic's models and OpenAI's Responses API for the rest, with the
|
|
463
463
|
* client's own identifying headers and the coding agent it named, so hosted
|
|
464
|
-
* sees the same client. Hosted Dari bills and logs what it serves
|
|
464
|
+
* sees the same client. Hosted Dari bills and logs what it serves; a private
|
|
465
|
+
* request asks it to keep only what billing needs.
|
|
465
466
|
*/
|
|
466
467
|
function hostedCandidate(hosted: HostedConnection, request: ResolveRouterRequest, modelId: string): Candidate {
|
|
467
468
|
let routerUrl = hosted.url;
|
|
@@ -475,6 +476,7 @@ function hostedCandidate(hosted: HostedConnection, request: ResolveRouterRequest
|
|
|
475
476
|
}
|
|
476
477
|
const headers: Record<string, string> = { ...request.clientHeaders };
|
|
477
478
|
if (request.clientHarness !== undefined) headers[CLIENT_HARNESS_HEADER] = request.clientHarness;
|
|
479
|
+
if (request.private === true) headers[PRIVATE_HEADER] = "true";
|
|
478
480
|
return {
|
|
479
481
|
provider: HOSTED_DARI_PROVIDER,
|
|
480
482
|
key: hosted.apiKey,
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import type { Database } from "bun:sqlite";
|
|
8
8
|
|
|
9
9
|
import { errorResponse, HttpError } from "../http/errors.js";
|
|
10
|
-
import { CLIENT_HARNESSES } from "../
|
|
10
|
+
import { CLIENT_HARNESSES } from "../harnesses/index.js";
|
|
11
11
|
import { DEFAULT_ROUTER_ALIAS } from "../platform/routing_contract.js";
|
|
12
12
|
import type { ClientHarness } from "../types.js";
|
|
13
13
|
import {
|
|
@@ -43,7 +43,7 @@ export type SubscriptionHttpDeps = {
|
|
|
43
43
|
const BASE = "/v1/organizations/current/credentials";
|
|
44
44
|
// Subscription names are env-var-style, which keeps other credential routes
|
|
45
45
|
// such as `provider-credentials/...` out of these matches.
|
|
46
|
-
const NAMED = /^\/([A-Za-z_][A-Za-z0-9_]*)(\/label|\/mark-available|\/
|
|
46
|
+
const NAMED = /^\/([A-Za-z_][A-Za-z0-9_]*)(\/label|\/mark-available|\/resets|\/resets\/[^/]+\/use)?$/;
|
|
47
47
|
|
|
48
48
|
class HttpError extends Error {
|
|
49
49
|
constructor(readonly status: number, message: string) {
|
|
@@ -98,13 +98,6 @@ export async function handleSubscriptionRequest(
|
|
|
98
98
|
}
|
|
99
99
|
return json(200, summary(deps.store, found(renamed, name), now));
|
|
100
100
|
}
|
|
101
|
-
if (action === "/private" && request.method === "PUT") {
|
|
102
|
-
// Private plans stay off hosted Dari: a connected gateway neither
|
|
103
|
-
// serves nor reports them.
|
|
104
|
-
const body = await readBody(request);
|
|
105
|
-
if (typeof body.private !== "boolean") throw new HttpError(400, "private must be true or false.");
|
|
106
|
-
return json(200, summary(deps.store, found(deps.store.setPrivate(name, body.private, now), name), now));
|
|
107
|
-
}
|
|
108
101
|
if (action === "/mark-available" && request.method === "POST") {
|
|
109
102
|
return json(200, summary(deps.store, found(deps.store.markAvailable(name, now), name), now));
|
|
110
103
|
}
|
|
@@ -161,9 +154,6 @@ async function startSession(deps: SubscriptionHttpDeps, body: Record<string, unk
|
|
|
161
154
|
if (credentialName !== null && reconnecting?.provider !== provider) {
|
|
162
155
|
throw new HttpError(404, `Unknown subscription credential ${JSON.stringify(credentialName)}.`);
|
|
163
156
|
}
|
|
164
|
-
// A reconnected plan stays where it was unless the caller says otherwise.
|
|
165
|
-
const isPrivate = body.private ?? reconnecting?.private ?? false;
|
|
166
|
-
if (typeof isPrivate !== "boolean") throw new HttpError(400, "private must be true or false.");
|
|
167
157
|
// `dari accounts subscription connect` names the hosted plan it moves here.
|
|
168
158
|
const movingFrom = body.moving_from ?? null;
|
|
169
159
|
if (movingFrom !== null && (typeof movingFrom !== "string" || !movingFrom.trim())) {
|
|
@@ -176,7 +166,6 @@ async function startSession(deps: SubscriptionHttpDeps, body: Record<string, unk
|
|
|
176
166
|
flow: authorization.flow,
|
|
177
167
|
credentialName,
|
|
178
168
|
owner: null,
|
|
179
|
-
private: isPrivate,
|
|
180
169
|
movingFrom,
|
|
181
170
|
expiresAt: authorization.expiresAt,
|
|
182
171
|
},
|
|
@@ -224,7 +213,7 @@ async function completeSession(deps: SubscriptionHttpDeps, body: Record<string,
|
|
|
224
213
|
console.error("hosted account check failed", error instanceof Error ? error.message : String(error));
|
|
225
214
|
}
|
|
226
215
|
}
|
|
227
|
-
const stored = deps.store.connect(tokens, session.credentialName, now, null,
|
|
216
|
+
const stored = deps.store.connect(tokens, session.credentialName, now, null, elsewhere);
|
|
228
217
|
if (stored === null) {
|
|
229
218
|
throw new HttpError(404, `Unknown subscription credential ${JSON.stringify(session.credentialName)}.`);
|
|
230
219
|
}
|
|
@@ -317,8 +306,6 @@ function credentialBody(credential: SubscriptionCredential, active: boolean, now
|
|
|
317
306
|
// subscription here belongs to the gateway's one user.
|
|
318
307
|
credential_scope: "user",
|
|
319
308
|
oauth_provider: credential.provider,
|
|
320
|
-
// Kept off hosted Dari (`dari accounts subscription connect --on private`).
|
|
321
|
-
private: credential.private,
|
|
322
309
|
created_at: credential.createdAt.toISOString(),
|
|
323
310
|
last_used_at: credential.lastUsedAt?.toISOString() ?? null,
|
|
324
311
|
unavailable_until: held ? credential.unavailableUntil!.toISOString() : null,
|
|
@@ -50,9 +50,6 @@ export type SubscriptionCredential = {
|
|
|
50
50
|
// The Dari Link user who connected the plan on the approval page; null for
|
|
51
51
|
// the gateway owner's own plans, which alone serve the gateway's keys.
|
|
52
52
|
owner: string | null;
|
|
53
|
-
// Its requests stay on this computer: a gateway connected to hosted Dari
|
|
54
|
-
// never sends them to Activity.
|
|
55
|
-
private: boolean;
|
|
56
53
|
accessToken: string;
|
|
57
54
|
refreshToken: string;
|
|
58
55
|
expiresAt: Date;
|
|
@@ -82,8 +79,6 @@ export type PendingOAuthSession = {
|
|
|
82
79
|
credentialName: string | null;
|
|
83
80
|
// The Dari Link user connecting the plan; null for the gateway owner.
|
|
84
81
|
owner: string | null;
|
|
85
|
-
// Whether the plan connects as private (see SubscriptionCredential).
|
|
86
|
-
private: boolean;
|
|
87
82
|
// The plan on hosted Dari this sign-in moves here, by name: its account is
|
|
88
83
|
// not a second copy, since the caller disconnects it there next.
|
|
89
84
|
movingFrom: string | null;
|
|
@@ -112,7 +107,7 @@ export type AccountRef = {
|
|
|
112
107
|
* other computers. `name` is the plan's handle.
|
|
113
108
|
*/
|
|
114
109
|
export type ConnectedAccount = AccountRef & {
|
|
115
|
-
place: "dari" | "this_computer"
|
|
110
|
+
place: "dari" | "this_computer";
|
|
116
111
|
name: string | null;
|
|
117
112
|
// When a plan on Dari was connected; hosted Dari before this release does
|
|
118
113
|
// not say.
|
|
@@ -145,7 +140,6 @@ const PROVIDER_LABELS: Record<SubscriptionProvider, string> = {
|
|
|
145
140
|
const PLACE_NAMES: Record<ConnectedAccount["place"], string> = {
|
|
146
141
|
dari: "on Dari",
|
|
147
142
|
this_computer: "on This Computer",
|
|
148
|
-
private: "Private on This Computer",
|
|
149
143
|
};
|
|
150
144
|
|
|
151
145
|
function connectedAccountMessage(account: ConnectedAccount): string {
|
|
@@ -170,7 +164,6 @@ type CredentialRow = {
|
|
|
170
164
|
account_email: string | null;
|
|
171
165
|
account_id: string | null;
|
|
172
166
|
owner: string | null;
|
|
173
|
-
private: number | null;
|
|
174
167
|
access_token: string;
|
|
175
168
|
refresh_token: string;
|
|
176
169
|
expires_at: number;
|
|
@@ -196,7 +189,7 @@ const ADDED_COLUMNS = {
|
|
|
196
189
|
usage_windows: "TEXT",
|
|
197
190
|
model_holds: "TEXT",
|
|
198
191
|
owner: "TEXT",
|
|
199
|
-
private: "INTEGER",
|
|
192
|
+
private: "INTEGER", // read once, by clearLegacyPrivate
|
|
200
193
|
auto_redeem_resets: "INTEGER", // no longer read; resets follow each model's sources
|
|
201
194
|
} as const;
|
|
202
195
|
|
|
@@ -206,7 +199,6 @@ type SessionRow = {
|
|
|
206
199
|
flow_json: string;
|
|
207
200
|
credential_name: string | null;
|
|
208
201
|
owner: string | null;
|
|
209
|
-
private: number | null;
|
|
210
202
|
moving_from: string | null;
|
|
211
203
|
expires_at: number;
|
|
212
204
|
};
|
|
@@ -260,14 +252,13 @@ export class SubscriptionStore {
|
|
|
260
252
|
flow_json TEXT NOT NULL,
|
|
261
253
|
credential_name TEXT,
|
|
262
254
|
owner TEXT,
|
|
263
|
-
private INTEGER,
|
|
264
255
|
moving_from TEXT,
|
|
265
256
|
expires_at INTEGER NOT NULL
|
|
266
257
|
)`);
|
|
267
258
|
const sessionColumns = new Set(
|
|
268
259
|
db.query<{ name: string }, []>("PRAGMA table_info(subscription_oauth_sessions)").all().map((column) => column.name),
|
|
269
260
|
);
|
|
270
|
-
for (const [column, type] of [["owner", "TEXT"], ["
|
|
261
|
+
for (const [column, type] of [["owner", "TEXT"], ["moving_from", "TEXT"]] as const) {
|
|
271
262
|
if (!sessionColumns.has(column)) db.run(`ALTER TABLE subscription_oauth_sessions ADD COLUMN ${column} ${type}`);
|
|
272
263
|
}
|
|
273
264
|
this.encryptStored();
|
|
@@ -472,7 +463,6 @@ export class SubscriptionStore {
|
|
|
472
463
|
reconnectName: string | null,
|
|
473
464
|
now = new Date(),
|
|
474
465
|
owner: string | null = null,
|
|
475
|
-
isPrivate = false,
|
|
476
466
|
elsewhere: ConnectedAccount[] = [],
|
|
477
467
|
): SubscriptionCredential | null {
|
|
478
468
|
const connected = this.db.transaction(() => {
|
|
@@ -490,7 +480,7 @@ export class SubscriptionStore {
|
|
|
490
480
|
`UPDATE subscription_credentials SET access_token = ?, refresh_token = ?, expires_at = ?,
|
|
491
481
|
account_id = ?, account_email = ?, unavailable_until = ?, unavailable_reason = ?,
|
|
492
482
|
usage_utilization = ?, usage_resets_at = ?, usage_observed_at = ?, usage_windows = ?, model_holds = ?,
|
|
493
|
-
|
|
483
|
+
updated_at = ?
|
|
494
484
|
WHERE id = ?`,
|
|
495
485
|
[
|
|
496
486
|
this.seal(tokens.accessToken, tokenPlace(existing.id, "access_token")),
|
|
@@ -505,7 +495,6 @@ export class SubscriptionStore {
|
|
|
505
495
|
usage?.observedAt.getTime() ?? null,
|
|
506
496
|
usage === null ? null : windowsJson(usage),
|
|
507
497
|
sameAccount ? modelHoldsJson(existing.modelHolds) : null,
|
|
508
|
-
isPrivate ? 1 : 0,
|
|
509
498
|
now.getTime(),
|
|
510
499
|
existing.id,
|
|
511
500
|
],
|
|
@@ -522,9 +511,9 @@ export class SubscriptionStore {
|
|
|
522
511
|
.query<{ next: number }, []>("SELECT COALESCE(MAX(position), 0) + 1 AS next FROM subscription_credentials")
|
|
523
512
|
.get()!.next;
|
|
524
513
|
this.db.run(
|
|
525
|
-
`INSERT INTO subscription_credentials (id, provider, name, account_email, account_id, owner,
|
|
514
|
+
`INSERT INTO subscription_credentials (id, provider, name, account_email, account_id, owner,
|
|
526
515
|
access_token, refresh_token, expires_at, position, created_at, updated_at)
|
|
527
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
|
516
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
528
517
|
[
|
|
529
518
|
id,
|
|
530
519
|
tokens.provider,
|
|
@@ -532,7 +521,6 @@ export class SubscriptionStore {
|
|
|
532
521
|
tokens.accountEmail,
|
|
533
522
|
tokens.accountId,
|
|
534
523
|
owner,
|
|
535
|
-
isPrivate ? 1 : 0,
|
|
536
524
|
this.seal(tokens.accessToken, tokenPlace(id, "access_token")),
|
|
537
525
|
this.seal(tokens.refreshToken, tokenPlace(id, "refresh_token")),
|
|
538
526
|
tokens.expiresAt.getTime(),
|
|
@@ -556,7 +544,7 @@ export class SubscriptionStore {
|
|
|
556
544
|
provider: local.provider,
|
|
557
545
|
accountId: local.accountId,
|
|
558
546
|
accountEmail: local.accountEmail,
|
|
559
|
-
place:
|
|
547
|
+
place: "this_computer",
|
|
560
548
|
name: local.name,
|
|
561
549
|
}));
|
|
562
550
|
}
|
|
@@ -600,16 +588,12 @@ export class SubscriptionStore {
|
|
|
600
588
|
return this.get(credential.id);
|
|
601
589
|
}
|
|
602
590
|
|
|
603
|
-
/**
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
now.getTime(),
|
|
610
|
-
credential.id,
|
|
611
|
-
]);
|
|
612
|
-
return this.get(credential.id);
|
|
591
|
+
/**
|
|
592
|
+
* Clear the marks of plans connected as private, before private mode
|
|
593
|
+
* replaced them; true when any was marked.
|
|
594
|
+
*/
|
|
595
|
+
clearLegacyPrivate(): boolean {
|
|
596
|
+
return this.db.run("UPDATE subscription_credentials SET private = NULL WHERE private = 1").changes > 0;
|
|
613
597
|
}
|
|
614
598
|
|
|
615
599
|
/** Remove a subscription. Returns what was removed, or null when it was not connected. */
|
|
@@ -678,15 +662,14 @@ export class SubscriptionStore {
|
|
|
678
662
|
const token = randomBytes(32).toString("base64url");
|
|
679
663
|
this.db.run("DELETE FROM subscription_oauth_sessions WHERE expires_at <= ?", [now.getTime()]);
|
|
680
664
|
this.db.run(
|
|
681
|
-
`INSERT INTO subscription_oauth_sessions (token, provider, flow_json, credential_name, owner,
|
|
682
|
-
VALUES (?, ?, ?, ?, ?, ?,
|
|
665
|
+
`INSERT INTO subscription_oauth_sessions (token, provider, flow_json, credential_name, owner, moving_from, expires_at)
|
|
666
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
|
683
667
|
[
|
|
684
668
|
token,
|
|
685
669
|
session.provider,
|
|
686
670
|
this.seal(JSON.stringify(session.flow), flowPlace(token)),
|
|
687
671
|
session.credentialName,
|
|
688
672
|
session.owner,
|
|
689
|
-
session.private ? 1 : 0,
|
|
690
673
|
session.movingFrom,
|
|
691
674
|
session.expiresAt.getTime(),
|
|
692
675
|
],
|
|
@@ -706,7 +689,6 @@ export class SubscriptionStore {
|
|
|
706
689
|
flow: JSON.parse(this.open(row.flow_json, flowPlace(row.token))) as Record<string, string>,
|
|
707
690
|
credentialName: row.credential_name,
|
|
708
691
|
owner: row.owner,
|
|
709
|
-
private: row.private === 1,
|
|
710
692
|
movingFrom: row.moving_from,
|
|
711
693
|
expiresAt: new Date(row.expires_at),
|
|
712
694
|
};
|
|
@@ -820,7 +802,6 @@ function credentialFromRow(row: CredentialRow): SubscriptionCredential {
|
|
|
820
802
|
accountEmail: row.account_email,
|
|
821
803
|
accountId: row.account_id,
|
|
822
804
|
owner: row.owner,
|
|
823
|
-
private: row.private === 1,
|
|
824
805
|
accessToken: row.access_token,
|
|
825
806
|
refreshToken: row.refresh_token,
|
|
826
807
|
expiresAt: new Date(row.expires_at),
|
package/src/telemetry/report.ts
CHANGED
|
@@ -650,6 +650,7 @@ export class RequestReporter {
|
|
|
650
650
|
gatewayPlatform().recordRequest({
|
|
651
651
|
...(link === undefined ? {} : { link }),
|
|
652
652
|
...(subscriptionCredentialId === undefined ? {} : { subscriptionCredentialId }),
|
|
653
|
+
private: a.credentials.private === true,
|
|
653
654
|
router: requestRecordRouter(a.credentials),
|
|
654
655
|
candidates: a.candidates.map(({ model, reasoningEffort }) => ({ model, reasoningEffort })),
|
|
655
656
|
...(a.sessionPinKey === undefined ? {} : { sessionPinKey: a.sessionPinKey }),
|
package/src/types.ts
CHANGED
|
@@ -106,16 +106,8 @@ export type PublicEvalCatalogCard = Omit<RouterEval, "scores"> & {
|
|
|
106
106
|
// and Anthropic routing metadata.
|
|
107
107
|
export type ServedDecision = RoutingDecision & { sessionPinned?: boolean };
|
|
108
108
|
|
|
109
|
-
// The coding agent a request comes from.
|
|
110
|
-
|
|
111
|
-
export type ClientHarness =
|
|
112
|
-
| "claude_code"
|
|
113
|
-
| "codex"
|
|
114
|
-
| "muse_code"
|
|
115
|
-
| "opencode"
|
|
116
|
-
| "pi"
|
|
117
|
-
| "openclaw"
|
|
118
|
-
| "hermes";
|
|
109
|
+
// The coding agent a request comes from.
|
|
110
|
+
export type { ClientHarness } from "./harnesses/index.js";
|
|
119
111
|
|
|
120
112
|
export type ResolvedRouterModelConfig = {
|
|
121
113
|
provider: string;
|
|
@@ -206,6 +198,9 @@ export type ResolvedRouter = {
|
|
|
206
198
|
// Tags a Dari Link child token carries onto every request it makes.
|
|
207
199
|
link_tags?: Record<string, string> | null;
|
|
208
200
|
zdr?: boolean;
|
|
201
|
+
// The request asked to stay out of Activity (`x-dari-private: true`): the
|
|
202
|
+
// platform records only what billing needs, and the response says so.
|
|
203
|
+
private?: boolean;
|
|
209
204
|
allow_long_context?: boolean;
|
|
210
205
|
speculative_routing?: boolean;
|
|
211
206
|
// Route each session's (and each subagent's) first turn, then serve that
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { AgentRequestContext } from "../../interaction/types.js";
|
|
2
|
-
/** Whether a request carries Claude Code's own headers. */
|
|
3
|
-
export declare function isClaudeCodeRequest(headers: Headers): boolean;
|
|
4
|
-
export declare function claudeCodeRequestContext(headers: Headers): AgentRequestContext;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// Muse Code names its surface (TUI, `muse exec`, desktop, `muse serve`) in
|
|
2
|
-
// x-client-id on every model request.
|
|
3
|
-
const MUSE_CODE_CLIENT_IDS = new Set(["tbh:tui", "tbh:exec", "tbh:desktop", "tbh:serve"]);
|
|
4
|
-
/** Muse Code's x-client-id when the request comes from Muse Code. */
|
|
5
|
-
export function museCodeClientId(headers) {
|
|
6
|
-
const clientId = headers.get("x-client-id")?.trim().toLowerCase();
|
|
7
|
-
return clientId !== undefined && MUSE_CODE_CLIENT_IDS.has(clientId) ? clientId : undefined;
|
|
8
|
-
}
|
package/src/ingress/muse_code.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// Muse Code names its surface (TUI, `muse exec`, desktop, `muse serve`) in
|
|
2
|
-
// x-client-id on every model request.
|
|
3
|
-
const MUSE_CODE_CLIENT_IDS = new Set(["tbh:tui", "tbh:exec", "tbh:desktop", "tbh:serve"]);
|
|
4
|
-
|
|
5
|
-
/** Muse Code's x-client-id when the request comes from Muse Code. */
|
|
6
|
-
export function museCodeClientId(headers: Headers): string | undefined {
|
|
7
|
-
const clientId = headers.get("x-client-id")?.trim().toLowerCase();
|
|
8
|
-
return clientId !== undefined && MUSE_CODE_CLIENT_IDS.has(clientId) ? clientId : undefined;
|
|
9
|
-
}
|