@stage-labs/metro 0.1.0-beta.105 → 0.1.0-beta.106
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/package.json +1 -1
- package/runtime/marketplace/plugin/.claude-plugin/plugin.json +1 -1
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/gateway.ts +8 -1
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-api.ts +5 -1
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-config.ts +12 -3
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/openrouter.ts +11 -0
- package/runtime/runtime.json +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stage-labs/metro",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.106",
|
|
4
4
|
"description": "The metro command line. Sign in once per machine, then hand your MCP connector list to Claude Code without the credentials touching disk, argv or shell history.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metro",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.106",
|
|
4
4
|
"description": "Metro for Claude Code, installed by the metro daemon on this machine: every connector the agent holds as its own MCP server relayed through the daemon, the orchestrator-only guard on the main thread, the standing rules loaded at each session start, and a refresh skill for when the daemon could not keep the server list current. No vendor credential ever sits in a config file.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Bonustrack",
|
|
@@ -13,6 +13,7 @@ import { anthropicHeaders, forwardedHeaders, GatewayError, parseJson, pipeRespon
|
|
|
13
13
|
import { notReady, readModelConfig, resolveRoute, routeLabel, setCodexAuth, writeModelConfig, type ModelConfig, type Route } from './model-config.js';
|
|
14
14
|
import { codexCount, codexMessages, freshCodexState, type CodexDeps } from './codex.js';
|
|
15
15
|
import { OPENROUTER_BASE } from './openrouter.js';
|
|
16
|
+
import { isRecord } from '@metro-labs/core/is-record';
|
|
16
17
|
import { forgetServed, noteServed } from './served.js';
|
|
17
18
|
import type { CodexTokens } from './codex-auth.js';
|
|
18
19
|
|
|
@@ -128,13 +129,19 @@ async function toOpenRouter(
|
|
|
128
129
|
const upstream = await fetch(`${deps.openrouterBase ?? OPENROUTER_BASE}${MESSAGES}`, {
|
|
129
130
|
method: 'POST',
|
|
130
131
|
headers,
|
|
131
|
-
body: JSON.stringify(
|
|
132
|
+
body: JSON.stringify(openrouterBody(body, route.model, cfg.openrouter.zdr)),
|
|
132
133
|
signal: watch.signal,
|
|
133
134
|
redirect: 'manual',
|
|
134
135
|
});
|
|
135
136
|
await pipeResponse(upstream, res, watch, { keepalive: true, ownCredential: true });
|
|
136
137
|
}
|
|
137
138
|
|
|
139
|
+
export function openrouterBody(body: Record<string, unknown>, model: string, zdr: boolean): Record<string, unknown> {
|
|
140
|
+
if (!zdr) return { ...body, model };
|
|
141
|
+
const provider = isRecord(body.provider) ? body.provider : {};
|
|
142
|
+
return { ...body, model, provider: { ...provider, zdr: true } };
|
|
143
|
+
}
|
|
144
|
+
|
|
138
145
|
async function dispatch(req: IncomingMessage, res: ServerResponse, path: string, deps: GatewayDeps): Promise<void> {
|
|
139
146
|
const cfg = deps.config();
|
|
140
147
|
const raw = await readBody(req);
|
|
@@ -6,7 +6,7 @@ import { log } from '@metro-labs/core/log';
|
|
|
6
6
|
import { beginLogin, CodexAuthError, finishLogin, readCodexCliAuth } from './codex-auth.js';
|
|
7
7
|
import { beginDeviceLogin, pollDeviceLogin } from './codex-device.js';
|
|
8
8
|
import { codexModels, currentTokens, freshCodexState } from './codex.js';
|
|
9
|
-
import { openrouterModels } from './openrouter.js';
|
|
9
|
+
import { openrouterModels, openrouterZdrModels } from './openrouter.js';
|
|
10
10
|
import { lastServed } from './served.js';
|
|
11
11
|
import type { CodexTokens } from './codex-auth.js';
|
|
12
12
|
import { GatewayError } from './forward.js';
|
|
@@ -140,6 +140,10 @@ const OPENROUTER_ROUTES: Record<string, Route> = {
|
|
|
140
140
|
method: 'GET',
|
|
141
141
|
run: async (_req, deps) => ({ models: await openrouterModels(deps.openrouterBase, deps.fetchImpl).catch(asApiError) }),
|
|
142
142
|
},
|
|
143
|
+
zdr: {
|
|
144
|
+
method: 'GET',
|
|
145
|
+
run: async (_req, deps) => ({ models: await openrouterZdrModels(deps.openrouterBase, deps.fetchImpl).catch(asApiError) }),
|
|
146
|
+
},
|
|
143
147
|
};
|
|
144
148
|
|
|
145
149
|
const named = (table: Record<string, Route>, name: string, method: string | undefined): Route | number => {
|
|
@@ -21,6 +21,7 @@ export interface BedrockSettings {
|
|
|
21
21
|
export interface OpenRouterSettings {
|
|
22
22
|
apiKey: string;
|
|
23
23
|
model: string;
|
|
24
|
+
zdr: boolean;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
export interface CodexSettings {
|
|
@@ -54,7 +55,7 @@ const empty = (): ModelConfig => ({
|
|
|
54
55
|
provider: 'anthropic',
|
|
55
56
|
anthropic: { apiKey: '', model: '' },
|
|
56
57
|
bedrock: { region: '', apiKey: '', model: '' },
|
|
57
|
-
openrouter: { apiKey: '', model: '' },
|
|
58
|
+
openrouter: { apiKey: '', model: '', zdr: false },
|
|
58
59
|
codex: { model: '', auth: null },
|
|
59
60
|
});
|
|
60
61
|
|
|
@@ -93,7 +94,7 @@ function fromDisk(raw: unknown): ModelConfig {
|
|
|
93
94
|
provider: isProvider(raw.provider) ? raw.provider : 'anthropic',
|
|
94
95
|
anthropic: { apiKey: text(anthropic.apiKey), model: text(anthropic.model) },
|
|
95
96
|
bedrock: { region: text(bedrock.region), apiKey: text(bedrock.apiKey), model: text(bedrock.model) },
|
|
96
|
-
openrouter: { apiKey: text(openrouter.apiKey), model: text(openrouter.model) },
|
|
97
|
+
openrouter: { apiKey: text(openrouter.apiKey), model: text(openrouter.model), zdr: openrouter.zdr === true },
|
|
97
98
|
codex: { model: text(codex.model), auth: tokensFromDisk(codex.auth) },
|
|
98
99
|
};
|
|
99
100
|
}
|
|
@@ -106,6 +107,13 @@ export function writeModelConfig(cfg: ModelConfig, dir = agentsDir()): void {
|
|
|
106
107
|
writeSecure(join(dir, MODEL_FILE), JSON.stringify(cfg, null, 2));
|
|
107
108
|
}
|
|
108
109
|
|
|
110
|
+
function flag(patch: Record<string, unknown>, key: string, current: boolean, what: string): boolean {
|
|
111
|
+
if (!(key in patch)) return current;
|
|
112
|
+
const value = patch[key];
|
|
113
|
+
if (typeof value !== 'boolean') throw new ModelConfigError(`${what} must be true or false`);
|
|
114
|
+
return value;
|
|
115
|
+
}
|
|
116
|
+
|
|
109
117
|
function field(patch: Record<string, unknown>, key: string, current: string, what: string): string {
|
|
110
118
|
if (!(key in patch)) return current;
|
|
111
119
|
const value = patch[key];
|
|
@@ -137,6 +145,7 @@ export function applyModelUpdate(cfg: ModelConfig, patch: unknown): ModelConfig
|
|
|
137
145
|
openrouter: {
|
|
138
146
|
apiKey: field(openrouter, 'apiKey', cfg.openrouter.apiKey, 'OpenRouter API key'),
|
|
139
147
|
model: field(openrouter, 'model', cfg.openrouter.model, 'OpenRouter model'),
|
|
148
|
+
zdr: flag(openrouter, 'zdr', cfg.openrouter.zdr, 'OpenRouter zero data retention'),
|
|
140
149
|
},
|
|
141
150
|
codex: { model: field(codex, 'model', cfg.codex.model, 'Codex model'), auth: cfg.codex.auth },
|
|
142
151
|
};
|
|
@@ -172,7 +181,7 @@ export function publicModelConfig(cfg: ModelConfig): Record<string, unknown> {
|
|
|
172
181
|
reason: notReady(cfg),
|
|
173
182
|
anthropic: { model: cfg.anthropic.model, hasKey: cfg.anthropic.apiKey !== '' },
|
|
174
183
|
bedrock: { region: cfg.bedrock.region, model: cfg.bedrock.model, hasKey: cfg.bedrock.apiKey !== '' },
|
|
175
|
-
openrouter: { model: cfg.openrouter.model, hasKey: cfg.openrouter.apiKey !== '' },
|
|
184
|
+
openrouter: { model: cfg.openrouter.model, hasKey: cfg.openrouter.apiKey !== '', zdr: cfg.openrouter.zdr },
|
|
176
185
|
codex: { model: cfg.codex.model, signedIn: auth !== null, account: auth?.email ?? null, plan: auth?.plan ?? null },
|
|
177
186
|
};
|
|
178
187
|
}
|
|
@@ -38,3 +38,14 @@ export async function openrouterModels(base = OPENROUTER_BASE, fetchImpl: typeof
|
|
|
38
38
|
.slice(0, MODELS_MAX)
|
|
39
39
|
.sort((a, b) => a.id.localeCompare(b.id));
|
|
40
40
|
}
|
|
41
|
+
|
|
42
|
+
export async function openrouterZdrModels(base = OPENROUTER_BASE, fetchImpl: typeof fetch = fetch): Promise<string[]> {
|
|
43
|
+
const res = await fetchImpl(`${base}/v1/endpoints/zdr`, { headers: { accept: 'application/json' }, redirect: 'manual' });
|
|
44
|
+
if (!res.ok) throw new GatewayError(res.status, 'api_error', `OpenRouter would not list its zero data retention endpoints (${String(res.status)})`);
|
|
45
|
+
const body: unknown = await res.json();
|
|
46
|
+
const data = typeof body === 'object' && body !== null ? (body as { data?: unknown }).data : undefined;
|
|
47
|
+
if (!Array.isArray(data)) throw new GatewayError(502, 'api_error', 'OpenRouter answered with no endpoint list');
|
|
48
|
+
const ids = new Set<string>();
|
|
49
|
+
for (const entry of data) if (isRecord(entry) && str(entry.model_id) !== '') ids.add(str(entry.model_id));
|
|
50
|
+
return [...ids].sort();
|
|
51
|
+
}
|
package/runtime/runtime.json
CHANGED