@volter/twin-openrouter 0.1.0
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/LICENSE +202 -0
- package/README.md +131 -0
- package/client/openrouter-mirror.css +131 -0
- package/client/openrouter-mirror.tsx +221 -0
- package/dist/client/openrouter-mirror.bundle.js +235 -0
- package/dist/client/openrouter-mirror.css +131 -0
- package/dist/client/openrouter-mirror.d.ts +1 -0
- package/dist/client/openrouter-mirror.js +95 -0
- package/dist/client/openrouter-mirror.tsx +221 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +31 -0
- package/dist/src/index.d.ts +15 -0
- package/dist/src/index.js +66 -0
- package/dist/src/openrouter-budget.d.ts +58 -0
- package/dist/src/openrouter-budget.js +133 -0
- package/dist/src/openrouter-capabilities.d.ts +3 -0
- package/dist/src/openrouter-capabilities.js +720 -0
- package/dist/src/openrouter-conformance.d.ts +11 -0
- package/dist/src/openrouter-conformance.js +53 -0
- package/dist/src/openrouter-connector.d.ts +90 -0
- package/dist/src/openrouter-connector.js +245 -0
- package/dist/src/openrouter-local-generation.d.ts +17 -0
- package/dist/src/openrouter-local-generation.js +271 -0
- package/dist/src/openrouter-mirror-ui.d.ts +12 -0
- package/dist/src/openrouter-mirror-ui.js +78 -0
- package/dist/src/openrouter-models.d.ts +39 -0
- package/dist/src/openrouter-models.js +78 -0
- package/dist/src/openrouter-scenario.d.ts +36 -0
- package/dist/src/openrouter-scenario.js +145 -0
- package/dist/src/openrouter-server.d.ts +20 -0
- package/dist/src/openrouter-server.js +144 -0
- package/dist/src/openrouter-stub.d.ts +8 -0
- package/dist/src/openrouter-stub.js +58 -0
- package/dist/src/openrouter-twin.d.ts +4 -0
- package/dist/src/openrouter-twin.js +1506 -0
- package/dist/src/openrouter-types.d.ts +50 -0
- package/dist/src/openrouter-types.js +1 -0
- package/dist/test-fixtures/openrouter-openapi-operations.SOURCE.md +16 -0
- package/dist/test-fixtures/openrouter-openapi-operations.json +1041 -0
- package/package.json +71 -0
- package/src/cli.ts +29 -0
- package/src/index.ts +108 -0
- package/src/openrouter-budget.ts +159 -0
- package/src/openrouter-capabilities.ts +861 -0
- package/src/openrouter-conformance.ts +60 -0
- package/src/openrouter-connector.ts +264 -0
- package/src/openrouter-local-generation.ts +207 -0
- package/src/openrouter-mirror-ui.ts +84 -0
- package/src/openrouter-models.ts +118 -0
- package/src/openrouter-scenario.ts +156 -0
- package/src/openrouter-server.ts +158 -0
- package/src/openrouter-stub.ts +60 -0
- package/src/openrouter-twin.ts +1441 -0
- package/src/openrouter-types.ts +49 -0
- package/test-fixtures/openrouter-openapi-operations.SOURCE.md +16 -0
- package/test-fixtures/openrouter-openapi-operations.json +1041 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--bg: #f6f6f3;
|
|
3
|
+
--panel: #ffffff;
|
|
4
|
+
--ink: #171717;
|
|
5
|
+
--muted: #6b6f76;
|
|
6
|
+
--line: #deded8;
|
|
7
|
+
--accent: #256f63;
|
|
8
|
+
--accent-dark: #174c45;
|
|
9
|
+
--warn-bg: #fff4dc;
|
|
10
|
+
--warn: #8f5a00;
|
|
11
|
+
--bad-bg: #fee8e7;
|
|
12
|
+
--bad: #b3261e;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
* { box-sizing: border-box; }
|
|
16
|
+
body {
|
|
17
|
+
margin: 0;
|
|
18
|
+
background: var(--bg);
|
|
19
|
+
color: var(--ink);
|
|
20
|
+
font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.app { min-height: 100vh; padding: 28px; }
|
|
24
|
+
header {
|
|
25
|
+
display: flex;
|
|
26
|
+
align-items: flex-start;
|
|
27
|
+
justify-content: space-between;
|
|
28
|
+
gap: 16px;
|
|
29
|
+
margin-bottom: 22px;
|
|
30
|
+
}
|
|
31
|
+
h1 { margin: 0; font-size: 28px; letter-spacing: 0; }
|
|
32
|
+
p { margin: 4px 0 0; color: var(--muted); }
|
|
33
|
+
button {
|
|
34
|
+
border: 0;
|
|
35
|
+
border-radius: 7px;
|
|
36
|
+
background: var(--accent);
|
|
37
|
+
color: white;
|
|
38
|
+
padding: 8px 14px;
|
|
39
|
+
font-weight: 650;
|
|
40
|
+
cursor: pointer;
|
|
41
|
+
}
|
|
42
|
+
button:hover { background: var(--accent-dark); }
|
|
43
|
+
button:disabled { opacity: .65; cursor: default; }
|
|
44
|
+
|
|
45
|
+
.grid {
|
|
46
|
+
display: grid;
|
|
47
|
+
grid-template-columns: minmax(300px, 420px) minmax(0, 1fr);
|
|
48
|
+
gap: 18px;
|
|
49
|
+
align-items: start;
|
|
50
|
+
}
|
|
51
|
+
.panel {
|
|
52
|
+
background: var(--panel);
|
|
53
|
+
border: 1px solid var(--line);
|
|
54
|
+
border-radius: 8px;
|
|
55
|
+
padding: 16px;
|
|
56
|
+
}
|
|
57
|
+
.generations-panel { grid-column: 2; }
|
|
58
|
+
h2 { margin: 0 0 12px; font-size: 17px; letter-spacing: 0; }
|
|
59
|
+
label { display: block; margin-bottom: 12px; }
|
|
60
|
+
label span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 12px; font-weight: 650; }
|
|
61
|
+
input, textarea {
|
|
62
|
+
width: 100%;
|
|
63
|
+
border: 1px solid var(--line);
|
|
64
|
+
border-radius: 7px;
|
|
65
|
+
padding: 8px 10px;
|
|
66
|
+
font: inherit;
|
|
67
|
+
}
|
|
68
|
+
.rows { display: flex; flex-direction: column; gap: 8px; }
|
|
69
|
+
.row {
|
|
70
|
+
display: grid;
|
|
71
|
+
grid-template-columns: minmax(0, 1fr) auto auto;
|
|
72
|
+
gap: 14px;
|
|
73
|
+
align-items: center;
|
|
74
|
+
border: 1px solid var(--line);
|
|
75
|
+
border-radius: 7px;
|
|
76
|
+
padding: 10px 12px;
|
|
77
|
+
}
|
|
78
|
+
button.row {
|
|
79
|
+
background: var(--panel);
|
|
80
|
+
color: var(--ink);
|
|
81
|
+
font: inherit;
|
|
82
|
+
text-align: left;
|
|
83
|
+
cursor: pointer;
|
|
84
|
+
}
|
|
85
|
+
button.row:hover { background: #f0f5f3; }
|
|
86
|
+
.row strong, .row span { display: block; min-width: 0; overflow-wrap: anywhere; }
|
|
87
|
+
|
|
88
|
+
.detail {
|
|
89
|
+
margin-top: 18px;
|
|
90
|
+
background: var(--panel);
|
|
91
|
+
border: 1px solid var(--line);
|
|
92
|
+
border-radius: 8px;
|
|
93
|
+
padding: 16px;
|
|
94
|
+
}
|
|
95
|
+
.detail-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
|
|
96
|
+
.detail-head h3 { margin: 0; font-size: 16px; }
|
|
97
|
+
.detail-body h4 { margin: 14px 0 6px; font-size: 13px; color: var(--muted); }
|
|
98
|
+
.kv { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--line); }
|
|
99
|
+
.endpoint-row { margin-top: 6px; }
|
|
100
|
+
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--muted); }
|
|
101
|
+
.empty { color: var(--muted); padding: 18px 4px; }
|
|
102
|
+
.error {
|
|
103
|
+
background: var(--bad-bg);
|
|
104
|
+
color: var(--bad);
|
|
105
|
+
border-radius: 7px;
|
|
106
|
+
padding: 10px 12px;
|
|
107
|
+
margin: 12px 0;
|
|
108
|
+
}
|
|
109
|
+
.stub-output { margin-top: 14px; }
|
|
110
|
+
.stub-banner {
|
|
111
|
+
background: var(--warn-bg);
|
|
112
|
+
color: var(--warn);
|
|
113
|
+
border-radius: 7px;
|
|
114
|
+
padding: 8px 10px;
|
|
115
|
+
font-weight: 650;
|
|
116
|
+
}
|
|
117
|
+
pre {
|
|
118
|
+
margin: 10px 0 0;
|
|
119
|
+
white-space: pre-wrap;
|
|
120
|
+
overflow-wrap: anywhere;
|
|
121
|
+
background: #fafaf8;
|
|
122
|
+
border: 1px solid var(--line);
|
|
123
|
+
border-radius: 7px;
|
|
124
|
+
padding: 12px;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
@media (max-width: 850px) {
|
|
128
|
+
.app { padding: 18px; }
|
|
129
|
+
.grid { grid-template-columns: 1fr; }
|
|
130
|
+
.generations-panel { grid-column: auto; }
|
|
131
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { createRoot } from 'react-dom/client';
|
|
4
|
+
// WHERE THIS MIRROR LIVES. Served at a vendor root the base is '' (fetches are root-relative, as
|
|
5
|
+
// before); served under a path prefix with a <base> tag every read and write resolves inside that
|
|
6
|
+
// prefix instead of escaping it.
|
|
7
|
+
const WIRE_BASE = typeof document === 'undefined' || document.querySelector('base[href]') === null ? '' : new URL('.', document.baseURI).pathname.replace(/\/$/, '');
|
|
8
|
+
async function json(path, init) {
|
|
9
|
+
const response = await fetch(`${WIRE_BASE}${path}`, init);
|
|
10
|
+
const body = await response.json();
|
|
11
|
+
if (!response.ok)
|
|
12
|
+
throw new Error(body?.error?.message ?? `request failed: ${response.status}`);
|
|
13
|
+
return body;
|
|
14
|
+
}
|
|
15
|
+
function ModelDetail({ model, onClose }) {
|
|
16
|
+
const [detail, setDetail] = useState(null);
|
|
17
|
+
const [error, setError] = useState('');
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
void json(`/api/v1/models/${model}/endpoints`)
|
|
20
|
+
.then((body) => setDetail(body.data))
|
|
21
|
+
.catch((err) => setError(err instanceof Error ? err.message : String(err)));
|
|
22
|
+
}, [model]);
|
|
23
|
+
return (_jsxs("div", { className: "detail model-detail", children: [_jsxs("div", { className: "detail-head", children: [_jsx("h3", { children: "Model detail" }), _jsx("button", { onClick: onClose, children: "Close" })] }), error ? _jsx("div", { className: "error", children: error }) : null, detail ? (_jsxs("div", { className: "detail-body", children: [_jsx("div", { className: "mono", children: detail.id }), _jsxs("div", { className: "kv", children: [_jsx("span", { children: "Context" }), _jsx("span", { className: "mono", children: detail.context_length.toLocaleString() })] }), _jsxs("div", { className: "kv", children: [_jsx("span", { children: "Prompt $/tok" }), _jsx("span", { className: "mono", children: detail.pricing?.prompt ?? '-' })] }), _jsxs("div", { className: "kv", children: [_jsx("span", { children: "Completion $/tok" }), _jsx("span", { className: "mono", children: detail.pricing?.completion ?? '-' })] }), _jsx("h4", { children: "Endpoints" }), (detail.endpoints ?? []).map((endpoint) => (_jsxs("div", { className: "row endpoint-row", children: [_jsx("span", { children: endpoint.name }), _jsx("span", { className: "mono", children: endpoint.provider_name }), _jsxs("span", { className: "mono", children: [endpoint.context_length.toLocaleString(), " ctx"] })] }, endpoint.provider_name)))] })) : (error ? null : _jsx("div", { className: "empty", children: "Loading\u2026" }))] }));
|
|
24
|
+
}
|
|
25
|
+
function Models({ models, onSelect }) {
|
|
26
|
+
return (_jsxs("section", { className: "panel models-panel", children: [_jsx("h2", { children: "Models" }), _jsx("div", { className: "rows", children: models.map((model) => (_jsxs("button", { className: "row model-row", onClick: () => onSelect(model.id), children: [_jsxs("div", { children: [_jsx("strong", { children: model.name }), _jsx("span", { className: "mono", children: model.id })] }), _jsx("span", { children: model.architecture?.modality ?? 'text->text' }), _jsxs("span", { className: "mono", children: [model.context_length.toLocaleString(), " ctx"] })] }, model.id))) })] }));
|
|
27
|
+
}
|
|
28
|
+
function GenerationDetail({ id, onClose }) {
|
|
29
|
+
const [detail, setDetail] = useState(null);
|
|
30
|
+
const [error, setError] = useState('');
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
void json(`/api/v1/generation?id=${encodeURIComponent(id)}`)
|
|
33
|
+
.then((body) => setDetail(body.data))
|
|
34
|
+
.catch((err) => setError(err instanceof Error ? err.message : String(err)));
|
|
35
|
+
}, [id]);
|
|
36
|
+
return (_jsxs("div", { className: "detail generation-detail", children: [_jsxs("div", { className: "detail-head", children: [_jsx("h3", { children: "Generation detail" }), _jsx("button", { onClick: onClose, children: "Close" })] }), error ? _jsx("div", { className: "error", children: error }) : null, detail ? (_jsxs("div", { className: "detail-body", children: [_jsx("div", { className: "mono", children: detail.id }), _jsxs("div", { className: "kv", children: [_jsx("span", { children: "Model" }), _jsx("span", { className: "mono", children: detail.model })] }), _jsxs("div", { className: "kv", children: [_jsx("span", { children: "Provider" }), _jsx("span", { className: "mono", children: detail.provider_name ?? 'twin' })] }), _jsxs("div", { className: "kv", children: [_jsx("span", { children: "Finish" }), _jsx("span", { className: "mono", children: detail.finish_reason ?? '-' })] }), _jsxs("div", { className: "kv", children: [_jsx("span", { children: "Prompt tokens" }), _jsx("span", { className: "mono", children: detail.tokens_prompt })] }), _jsxs("div", { className: "kv", children: [_jsx("span", { children: "Completion tokens" }), _jsx("span", { className: "mono", children: detail.tokens_completion })] }), _jsxs("div", { className: "kv", children: [_jsx("span", { children: "Total cost" }), _jsxs("span", { className: "mono", children: ["$", detail.total_cost.toFixed(8)] })] })] })) : (error ? null : _jsx("div", { className: "empty", children: "Loading\u2026" }))] }));
|
|
37
|
+
}
|
|
38
|
+
function Generations({ generations, onSelect }) {
|
|
39
|
+
return (_jsxs("section", { className: "panel generations-panel", children: [_jsx("h2", { children: "Generations" }), _jsxs("div", { className: "rows", children: [generations.length === 0 ? _jsx("div", { className: "empty", children: "No generations yet." }) : null, generations.map((generation) => (_jsxs("button", { className: "row generation-row", onClick: () => onSelect(generation.id), children: [_jsxs("div", { children: [_jsx("strong", { children: generation.model }), _jsx("span", { className: "mono", children: generation.id })] }), _jsx("span", { children: generation.streamed ? 'streamed' : 'standard' }), _jsxs("span", { className: "mono", children: ["$", generation.total_cost.toFixed(8)] })] }, generation.id)))] })] }));
|
|
40
|
+
}
|
|
41
|
+
function Playground({ onComplete }) {
|
|
42
|
+
const [model, setModel] = useState('google/gemini-3-flash-preview');
|
|
43
|
+
const [prompt, setPrompt] = useState('Summarize the OpenRouter twin.');
|
|
44
|
+
const [result, setResult] = useState('');
|
|
45
|
+
const [error, setError] = useState('');
|
|
46
|
+
const [busy, setBusy] = useState(false);
|
|
47
|
+
async function send() {
|
|
48
|
+
setBusy(true);
|
|
49
|
+
setError('');
|
|
50
|
+
setResult('');
|
|
51
|
+
try {
|
|
52
|
+
const body = await json('/api/v1/chat/completions', {
|
|
53
|
+
method: 'POST',
|
|
54
|
+
headers: { 'content-type': 'application/json' },
|
|
55
|
+
body: JSON.stringify({ model, messages: [{ role: 'user', content: prompt }] }),
|
|
56
|
+
});
|
|
57
|
+
setResult(body.choices?.[0]?.message?.content ?? '');
|
|
58
|
+
onComplete();
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
setBusy(false);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return (_jsxs("section", { className: "panel playground-panel", children: [_jsx("h2", { children: "Playground" }), _jsxs("label", { children: [_jsx("span", { children: "Model" }), _jsx("input", { value: model, onChange: (event) => setModel(event.target.value) })] }), _jsxs("label", { children: [_jsx("span", { children: "Prompt" }), _jsx("textarea", { rows: 4, value: prompt, onChange: (event) => setPrompt(event.target.value) })] }), _jsx("button", { onClick: send, disabled: busy, children: busy ? 'Sending...' : 'Send' }), error ? _jsx("div", { className: "error", children: error }) : null, result ? (_jsxs("div", { className: "stub-output", children: [_jsx("div", { className: "stub-banner", children: "Stub completion: deterministic twin output, no provider model was run." }), _jsx("pre", { children: result })] })) : null] }));
|
|
68
|
+
}
|
|
69
|
+
function App() {
|
|
70
|
+
const [models, setModels] = useState([]);
|
|
71
|
+
const [generations, setGenerations] = useState([]);
|
|
72
|
+
const [loadError, setLoadError] = useState('');
|
|
73
|
+
const [selectedModel, setSelectedModel] = useState('');
|
|
74
|
+
const [selectedGeneration, setSelectedGeneration] = useState('');
|
|
75
|
+
async function load() {
|
|
76
|
+
try {
|
|
77
|
+
const [modelsBody, generationBody] = await Promise.all([
|
|
78
|
+
json('/api/v1/models'),
|
|
79
|
+
json('/api/v1/generations'),
|
|
80
|
+
]);
|
|
81
|
+
setModels(modelsBody.data);
|
|
82
|
+
setGenerations(generationBody.data);
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
setLoadError(err instanceof Error ? err.message : String(err));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
void load();
|
|
90
|
+
}, []);
|
|
91
|
+
return (_jsxs("main", { className: "app openrouter-mirror", children: [_jsxs("header", { children: [_jsxs("div", { children: [_jsx("h1", { children: "OpenRouter Twin" }), _jsx("p", { children: "OpenAI-compatible API simulation with deterministic stub output." })] }), _jsx("button", { onClick: () => void load(), children: "Refresh" })] }), loadError ? _jsx("div", { className: "error", children: loadError }) : null, _jsxs("div", { className: "grid", children: [_jsx(Playground, { onComplete: () => void load() }), _jsx(Models, { models: models, onSelect: setSelectedModel }), _jsx(Generations, { generations: generations, onSelect: setSelectedGeneration })] }), selectedModel ? _jsx(ModelDetail, { model: selectedModel, onClose: () => setSelectedModel('') }) : null, selectedGeneration ? _jsx(GenerationDetail, { id: selectedGeneration, onClose: () => setSelectedGeneration('') }) : null] }));
|
|
92
|
+
}
|
|
93
|
+
const root = document.getElementById('root');
|
|
94
|
+
if (root)
|
|
95
|
+
createRoot(root).render(_jsx(App, {}));
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { createRoot } from 'react-dom/client';
|
|
3
|
+
|
|
4
|
+
// WHERE THIS MIRROR LIVES. Served at a vendor root the base is '' (fetches are root-relative, as
|
|
5
|
+
// before); served under a path prefix with a <base> tag every read and write resolves inside that
|
|
6
|
+
// prefix instead of escaping it.
|
|
7
|
+
const WIRE_BASE = typeof document === 'undefined' || document.querySelector('base[href]') === null ? '' : new URL('.', document.baseURI).pathname.replace(/\/$/, '');
|
|
8
|
+
|
|
9
|
+
type Model = { id: string; name: string; context_length: number; architecture?: { modality?: string }; pricing?: { prompt?: string; completion?: string } };
|
|
10
|
+
type ModelEndpoints = Model & { endpoints?: Array<{ name: string; provider_name: string; context_length: number }> };
|
|
11
|
+
type Generation = { id: string; model: string; created_at: string; total_cost: number; tokens_prompt: number; tokens_completion: number; streamed: boolean; provider_name?: string; finish_reason?: string };
|
|
12
|
+
|
|
13
|
+
async function json<T>(path: string, init?: RequestInit): Promise<T> {
|
|
14
|
+
const response = await fetch(`${WIRE_BASE}${path}`, init);
|
|
15
|
+
const body = await response.json();
|
|
16
|
+
if (!response.ok) throw new Error(body?.error?.message ?? `request failed: ${response.status}`);
|
|
17
|
+
return body as T;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function ModelDetail({ model, onClose }: { model: string; onClose: () => void }) {
|
|
21
|
+
const [detail, setDetail] = useState<ModelEndpoints | null>(null);
|
|
22
|
+
const [error, setError] = useState('');
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
void json<{ data: ModelEndpoints }>(`/api/v1/models/${model}/endpoints`)
|
|
25
|
+
.then((body) => setDetail(body.data))
|
|
26
|
+
.catch((err) => setError(err instanceof Error ? err.message : String(err)));
|
|
27
|
+
}, [model]);
|
|
28
|
+
return (
|
|
29
|
+
<div className="detail model-detail">
|
|
30
|
+
<div className="detail-head">
|
|
31
|
+
<h3>Model detail</h3>
|
|
32
|
+
<button onClick={onClose}>Close</button>
|
|
33
|
+
</div>
|
|
34
|
+
{error ? <div className="error">{error}</div> : null}
|
|
35
|
+
{detail ? (
|
|
36
|
+
<div className="detail-body">
|
|
37
|
+
<div className="mono">{detail.id}</div>
|
|
38
|
+
<div className="kv"><span>Context</span><span className="mono">{detail.context_length.toLocaleString()}</span></div>
|
|
39
|
+
<div className="kv"><span>Prompt $/tok</span><span className="mono">{detail.pricing?.prompt ?? '-'}</span></div>
|
|
40
|
+
<div className="kv"><span>Completion $/tok</span><span className="mono">{detail.pricing?.completion ?? '-'}</span></div>
|
|
41
|
+
<h4>Endpoints</h4>
|
|
42
|
+
{(detail.endpoints ?? []).map((endpoint) => (
|
|
43
|
+
<div className="row endpoint-row" key={endpoint.provider_name}>
|
|
44
|
+
<span>{endpoint.name}</span>
|
|
45
|
+
<span className="mono">{endpoint.provider_name}</span>
|
|
46
|
+
<span className="mono">{endpoint.context_length.toLocaleString()} ctx</span>
|
|
47
|
+
</div>
|
|
48
|
+
))}
|
|
49
|
+
</div>
|
|
50
|
+
) : (error ? null : <div className="empty">Loading…</div>)}
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function Models({ models, onSelect }: { models: Model[]; onSelect: (id: string) => void }) {
|
|
56
|
+
return (
|
|
57
|
+
<section className="panel models-panel">
|
|
58
|
+
<h2>Models</h2>
|
|
59
|
+
<div className="rows">
|
|
60
|
+
{models.map((model) => (
|
|
61
|
+
<button className="row model-row" key={model.id} onClick={() => onSelect(model.id)}>
|
|
62
|
+
<div>
|
|
63
|
+
<strong>{model.name}</strong>
|
|
64
|
+
<span className="mono">{model.id}</span>
|
|
65
|
+
</div>
|
|
66
|
+
<span>{model.architecture?.modality ?? 'text->text'}</span>
|
|
67
|
+
<span className="mono">{model.context_length.toLocaleString()} ctx</span>
|
|
68
|
+
</button>
|
|
69
|
+
))}
|
|
70
|
+
</div>
|
|
71
|
+
</section>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function GenerationDetail({ id, onClose }: { id: string; onClose: () => void }) {
|
|
76
|
+
const [detail, setDetail] = useState<Generation | null>(null);
|
|
77
|
+
const [error, setError] = useState('');
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
void json<{ data: Generation }>(`/api/v1/generation?id=${encodeURIComponent(id)}`)
|
|
80
|
+
.then((body) => setDetail(body.data))
|
|
81
|
+
.catch((err) => setError(err instanceof Error ? err.message : String(err)));
|
|
82
|
+
}, [id]);
|
|
83
|
+
return (
|
|
84
|
+
<div className="detail generation-detail">
|
|
85
|
+
<div className="detail-head">
|
|
86
|
+
<h3>Generation detail</h3>
|
|
87
|
+
<button onClick={onClose}>Close</button>
|
|
88
|
+
</div>
|
|
89
|
+
{error ? <div className="error">{error}</div> : null}
|
|
90
|
+
{detail ? (
|
|
91
|
+
<div className="detail-body">
|
|
92
|
+
<div className="mono">{detail.id}</div>
|
|
93
|
+
<div className="kv"><span>Model</span><span className="mono">{detail.model}</span></div>
|
|
94
|
+
<div className="kv"><span>Provider</span><span className="mono">{detail.provider_name ?? 'twin'}</span></div>
|
|
95
|
+
<div className="kv"><span>Finish</span><span className="mono">{detail.finish_reason ?? '-'}</span></div>
|
|
96
|
+
<div className="kv"><span>Prompt tokens</span><span className="mono">{detail.tokens_prompt}</span></div>
|
|
97
|
+
<div className="kv"><span>Completion tokens</span><span className="mono">{detail.tokens_completion}</span></div>
|
|
98
|
+
<div className="kv"><span>Total cost</span><span className="mono">${detail.total_cost.toFixed(8)}</span></div>
|
|
99
|
+
</div>
|
|
100
|
+
) : (error ? null : <div className="empty">Loading…</div>)}
|
|
101
|
+
</div>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function Generations({ generations, onSelect }: { generations: Generation[]; onSelect: (id: string) => void }) {
|
|
106
|
+
return (
|
|
107
|
+
<section className="panel generations-panel">
|
|
108
|
+
<h2>Generations</h2>
|
|
109
|
+
<div className="rows">
|
|
110
|
+
{generations.length === 0 ? <div className="empty">No generations yet.</div> : null}
|
|
111
|
+
{generations.map((generation) => (
|
|
112
|
+
<button className="row generation-row" key={generation.id} onClick={() => onSelect(generation.id)}>
|
|
113
|
+
<div>
|
|
114
|
+
<strong>{generation.model}</strong>
|
|
115
|
+
<span className="mono">{generation.id}</span>
|
|
116
|
+
</div>
|
|
117
|
+
<span>{generation.streamed ? 'streamed' : 'standard'}</span>
|
|
118
|
+
<span className="mono">${generation.total_cost.toFixed(8)}</span>
|
|
119
|
+
</button>
|
|
120
|
+
))}
|
|
121
|
+
</div>
|
|
122
|
+
</section>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function Playground({ onComplete }: { onComplete: () => void }) {
|
|
127
|
+
const [model, setModel] = useState('google/gemini-3-flash-preview');
|
|
128
|
+
const [prompt, setPrompt] = useState('Summarize the OpenRouter twin.');
|
|
129
|
+
const [result, setResult] = useState('');
|
|
130
|
+
const [error, setError] = useState('');
|
|
131
|
+
const [busy, setBusy] = useState(false);
|
|
132
|
+
|
|
133
|
+
async function send() {
|
|
134
|
+
setBusy(true);
|
|
135
|
+
setError('');
|
|
136
|
+
setResult('');
|
|
137
|
+
try {
|
|
138
|
+
const body = await json<any>('/api/v1/chat/completions', {
|
|
139
|
+
method: 'POST',
|
|
140
|
+
headers: { 'content-type': 'application/json' },
|
|
141
|
+
body: JSON.stringify({ model, messages: [{ role: 'user', content: prompt }] }),
|
|
142
|
+
});
|
|
143
|
+
setResult(body.choices?.[0]?.message?.content ?? '');
|
|
144
|
+
onComplete();
|
|
145
|
+
} catch (err) {
|
|
146
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
147
|
+
} finally {
|
|
148
|
+
setBusy(false);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<section className="panel playground-panel">
|
|
154
|
+
<h2>Playground</h2>
|
|
155
|
+
<label>
|
|
156
|
+
<span>Model</span>
|
|
157
|
+
<input value={model} onChange={(event) => setModel(event.target.value)} />
|
|
158
|
+
</label>
|
|
159
|
+
<label>
|
|
160
|
+
<span>Prompt</span>
|
|
161
|
+
<textarea rows={4} value={prompt} onChange={(event) => setPrompt(event.target.value)} />
|
|
162
|
+
</label>
|
|
163
|
+
<button onClick={send} disabled={busy}>{busy ? 'Sending...' : 'Send'}</button>
|
|
164
|
+
{error ? <div className="error">{error}</div> : null}
|
|
165
|
+
{result ? (
|
|
166
|
+
<div className="stub-output">
|
|
167
|
+
<div className="stub-banner">Stub completion: deterministic twin output, no provider model was run.</div>
|
|
168
|
+
<pre>{result}</pre>
|
|
169
|
+
</div>
|
|
170
|
+
) : null}
|
|
171
|
+
</section>
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function App() {
|
|
176
|
+
const [models, setModels] = useState<Model[]>([]);
|
|
177
|
+
const [generations, setGenerations] = useState<Generation[]>([]);
|
|
178
|
+
const [loadError, setLoadError] = useState('');
|
|
179
|
+
const [selectedModel, setSelectedModel] = useState('');
|
|
180
|
+
const [selectedGeneration, setSelectedGeneration] = useState('');
|
|
181
|
+
|
|
182
|
+
async function load() {
|
|
183
|
+
try {
|
|
184
|
+
const [modelsBody, generationBody] = await Promise.all([
|
|
185
|
+
json<{ data: Model[] }>('/api/v1/models'),
|
|
186
|
+
json<{ data: Generation[] }>('/api/v1/generations'),
|
|
187
|
+
]);
|
|
188
|
+
setModels(modelsBody.data);
|
|
189
|
+
setGenerations(generationBody.data);
|
|
190
|
+
} catch (err) {
|
|
191
|
+
setLoadError(err instanceof Error ? err.message : String(err));
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
useEffect(() => {
|
|
196
|
+
void load();
|
|
197
|
+
}, []);
|
|
198
|
+
|
|
199
|
+
return (
|
|
200
|
+
<main className="app openrouter-mirror">
|
|
201
|
+
<header>
|
|
202
|
+
<div>
|
|
203
|
+
<h1>OpenRouter Twin</h1>
|
|
204
|
+
<p>OpenAI-compatible API simulation with deterministic stub output.</p>
|
|
205
|
+
</div>
|
|
206
|
+
<button onClick={() => void load()}>Refresh</button>
|
|
207
|
+
</header>
|
|
208
|
+
{loadError ? <div className="error">{loadError}</div> : null}
|
|
209
|
+
<div className="grid">
|
|
210
|
+
<Playground onComplete={() => void load()} />
|
|
211
|
+
<Models models={models} onSelect={setSelectedModel} />
|
|
212
|
+
<Generations generations={generations} onSelect={setSelectedGeneration} />
|
|
213
|
+
</div>
|
|
214
|
+
{selectedModel ? <ModelDetail model={selectedModel} onClose={() => setSelectedModel('')} /> : null}
|
|
215
|
+
{selectedGeneration ? <GenerationDetail id={selectedGeneration} onClose={() => setSelectedGeneration('')} /> : null}
|
|
216
|
+
</main>
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const root = document.getElementById('root');
|
|
221
|
+
if (root) createRoot(root).render(<App />);
|
package/dist/src/cli.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { keepProcessAlive } from '@volter/world-core/lifecycle';
|
|
3
|
+
import { hasFlag, optionValue } from '@volter/world-core/args';
|
|
4
|
+
import { createOpenRouterTwinServer } from "./openrouter-server.js";
|
|
5
|
+
import { createOpenRouterMirrorServer } from "./openrouter-mirror-ui.js";
|
|
6
|
+
const [cmd, ...rest] = process.argv.slice(2);
|
|
7
|
+
const port = Number(optionValue(rest, '--port', '0')) || undefined;
|
|
8
|
+
const root = optionValue(rest, '--root') || undefined;
|
|
9
|
+
const scenario = optionValue(rest, '--scenario') || undefined;
|
|
10
|
+
const localGenerationUrl = hasFlag(rest, '--local-generation-url') ? optionValue(rest, '--local-generation-url') : undefined;
|
|
11
|
+
const readOnly = hasFlag(rest, '--read-only');
|
|
12
|
+
if (cmd === 'serve') {
|
|
13
|
+
const server = await createOpenRouterTwinServer({ readOnly, ...(root ? { root } : {}), ...(port ? { port } : {}), ...(scenario ? { scenarioPath: scenario } : {}), ...(localGenerationUrl !== undefined ? { localGenerationUrl } : {}) });
|
|
14
|
+
process.stdout.write(`openrouter twin (${localGenerationUrl !== undefined || process.env.TWIN_OPENROUTER_LOCAL_GENERATION_URL !== undefined ? 'optional local generation' : 'deterministic stub output'})${readOnly ? ' [read-only]' : ''}${scenario ? ' [scenario]' : ''} at http://127.0.0.1:${server.port}\n`);
|
|
15
|
+
await keepProcessAlive();
|
|
16
|
+
}
|
|
17
|
+
else if (cmd === 'mirror') {
|
|
18
|
+
const server = await createOpenRouterMirrorServer({ ...(root ? { root } : {}), ...(port ? { port } : {}) });
|
|
19
|
+
process.stdout.write(`openrouter mirror UI at http://127.0.0.1:${server.port}\n`);
|
|
20
|
+
await keepProcessAlive();
|
|
21
|
+
}
|
|
22
|
+
else if (cmd === 'conformance') {
|
|
23
|
+
const { checkOpenRouterConformance } = await import("./openrouter-conformance.js");
|
|
24
|
+
const report = await checkOpenRouterConformance({ ...(root ? { root } : {}) });
|
|
25
|
+
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
26
|
+
if (!report.ok)
|
|
27
|
+
process.exitCode = 1;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
process.stdout.write('Usage: world-openrouter serve|mirror|conformance [--port N] [--root DIR] [--read-only] [--scenario FILE] [--local-generation-url http://127.0.0.1:PORT]\n');
|
|
31
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { handleOpenRouterTwinRequest } from './openrouter-twin.js';
|
|
2
|
+
export type { OpenRouterRequest, OpenRouterResponse, SseEvent, SseSink, GenerationStat } from './openrouter-types.js';
|
|
3
|
+
export { createOpenRouterTwinFetch, createOpenRouterTwinServer, type OpenRouterTwinFetchOptions } from './openrouter-server.js';
|
|
4
|
+
export { OPENROUTER_MODELS, OPENROUTER_PROVIDERS, findOpenRouterModel } from './openrouter-models.js';
|
|
5
|
+
export type { OpenRouterModel, OpenRouterProvider } from './openrouter-models.js';
|
|
6
|
+
export { contentToText, countPromptTokens, estimateTokens, lastUserText, stableHash, stubAssistantText } from './openrouter-stub.js';
|
|
7
|
+
export { createOpenRouterScenarioEngine, loadOpenRouterScenarioDocument, openrouterScenarioAdapter, realizeOpenRouterRespond, } from './openrouter-scenario.js';
|
|
8
|
+
export type { OpenRouterScenarioEngine, OpenRouterScenarioRequest, OpenRouterScenarioRespond, ScenarioToolCall, } from './openrouter-scenario.js';
|
|
9
|
+
export { buildOpenRouterMirrorClient, createOpenRouterMirrorServer, openrouterMirrorHtml } from './openrouter-mirror-ui.js';
|
|
10
|
+
export { OPENROUTER_API_BASE, liveOpenRouterExecute, openRouterRequestForAction, pullOpenRouterState, pushOpenRouterAction, pushPendingOpenRouterActions, syncOpenRouterFromReal, } from './openrouter-connector.js';
|
|
11
|
+
export type { OpenRouterExecute } from './openrouter-connector.js';
|
|
12
|
+
export { OPENROUTER_BUDGET_CEILING, OPENROUTER_BUDGET_MAX_RETRY_AFTER_S, OPENROUTER_BUDGET_WINDOW_MS, OPENROUTER_CALL_WEIGHTS, OPENROUTER_RATE_BUDGET, OpenRouterBudget, OpenRouterBudgetError, openRouterBudgetPath, openRouterCallWeight, splitOpenRouterPath, } from './openrouter-budget.js';
|
|
13
|
+
export type { OpenRouterBudgetErrorKind, OpenRouterBudgetOptions, OpenRouterBudgetReservation, OpenRouterBudgetSnapshot, } from './openrouter-budget.js';
|
|
14
|
+
import { type TwinPack } from '@volter/world-core';
|
|
15
|
+
export declare const pack: TwinPack;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export { handleOpenRouterTwinRequest } from "./openrouter-twin.js";
|
|
2
|
+
export { createOpenRouterTwinFetch, createOpenRouterTwinServer } from "./openrouter-server.js";
|
|
3
|
+
export { OPENROUTER_MODELS, OPENROUTER_PROVIDERS, findOpenRouterModel } from "./openrouter-models.js";
|
|
4
|
+
export { contentToText, countPromptTokens, estimateTokens, lastUserText, stableHash, stubAssistantText } from "./openrouter-stub.js";
|
|
5
|
+
// The pack's HALF of the scenario system (the grammar is the kernel's ONE engine). Exported so a
|
|
6
|
+
// test can build an engine and `use()` handlers in-process, and so the fetch adapter can mount it.
|
|
7
|
+
export { createOpenRouterScenarioEngine, loadOpenRouterScenarioDocument, openrouterScenarioAdapter, realizeOpenRouterRespond, } from "./openrouter-scenario.js";
|
|
8
|
+
export { buildOpenRouterMirrorClient, createOpenRouterMirrorServer, openrouterMirrorHtml } from "./openrouter-mirror-ui.js";
|
|
9
|
+
export { OPENROUTER_API_BASE, liveOpenRouterExecute, openRouterRequestForAction, pullOpenRouterState, pushOpenRouterAction, pushPendingOpenRouterActions, syncOpenRouterFromReal, } from "./openrouter-connector.js";
|
|
10
|
+
// The client-side rate budget — the fail-closed backstop `liveOpenRouterExecute` routes every live
|
|
11
|
+
// request through. The mechanism is the kernel's (`@volter/world-core` -> rateBudget.ts); these are this
|
|
12
|
+
// vendor's numbers and the typed bindings around them.
|
|
13
|
+
export { OPENROUTER_BUDGET_CEILING, OPENROUTER_BUDGET_MAX_RETRY_AFTER_S, OPENROUTER_BUDGET_WINDOW_MS, OPENROUTER_CALL_WEIGHTS, OPENROUTER_RATE_BUDGET, OpenRouterBudget, OpenRouterBudgetError, openRouterBudgetPath, openRouterCallWeight, splitOpenRouterPath, } from "./openrouter-budget.js";
|
|
14
|
+
import { registerPack } from '@volter/world-core';
|
|
15
|
+
import { performOpenRouterAction, syncOpenRouterFromRemote } from "./openrouter-connector.js";
|
|
16
|
+
import { OPENROUTER_RATE_BUDGET as RATE_BUDGET } from "./openrouter-budget.js";
|
|
17
|
+
export const pack = {
|
|
18
|
+
// PROTOCOL 2 (docs/contributing/architecture.md#protocol-2-the-pack-is-a-plugin): the pack is a plugin — its wire, its tree, and its half of
|
|
19
|
+
// the real state system. Moved 2026-09-08.
|
|
20
|
+
protocol: '2',
|
|
21
|
+
// OpenRouter publishes no webhooks for the provisioning surface, so the refresh is a poll. Five
|
|
22
|
+
// minutes is the catalog's cadence, and the pull is two calls (the model catalog, the account's
|
|
23
|
+
// keys) which the rate budget counts as two.
|
|
24
|
+
refresh: { every: '5m', webhook: false, onDemand: { atMost: '30s' } },
|
|
25
|
+
stateSystem: { perform: performOpenRouterAction, refresh: syncOpenRouterFromRemote },
|
|
26
|
+
// The round trip is a provisioning-key create — OpenRouter's own write, and the ONE part of an
|
|
27
|
+
// account this twin both writes and reads back (`GET /api/v1/keys` is the pull's second domain).
|
|
28
|
+
// The key's hash is minted from the name AND the write's instant, so a second send on a branch
|
|
29
|
+
// is a second key rather than a refused duplicate.
|
|
30
|
+
roundTrip: { method: 'POST', path: '/api/v1/keys', body: { name: 'round trip' }, headers: { authorization: 'Bearer round-trip' } },
|
|
31
|
+
parityOrigin: 'http://twin',
|
|
32
|
+
vendor: 'openrouter',
|
|
33
|
+
// The SAME object openrouter-budget.ts declares at module load — one source of truth, so
|
|
34
|
+
// registering the pack and importing the connector arm identical numbers.
|
|
35
|
+
rateBudget: RATE_BUDGET,
|
|
36
|
+
transport: 'rest',
|
|
37
|
+
archetype: 'generative',
|
|
38
|
+
bin: 'world-openrouter',
|
|
39
|
+
// The subject types the twin SERVES from its own state — the R2 resource-level claim.
|
|
40
|
+
// `model` is deliberately NOT here: it is a connector-side projection that only
|
|
41
|
+
// `pullOpenRouterState` folds in from a real OpenRouter through an injected client, and no
|
|
42
|
+
// route reads it back — `GET /v1/models`, `/v1/models/count`, `/v1/models/:id` and
|
|
43
|
+
// `/:id/endpoints` all serve the static OPENROUTER_MODELS catalog (openrouter-models.ts),
|
|
44
|
+
// never a stored subject (the ai-gateway `model`/`credits` precedent).
|
|
45
|
+
resources: ['generation', 'api_key', 'byok', 'preset'],
|
|
46
|
+
specSource: 'OpenRouter API reference (OpenAI-compatible chat completions + API Reference surfaces; model output is a deterministic stub)',
|
|
47
|
+
description: 'OpenRouter API twin — OpenAI-compatible chat completions/streaming, models, key/credits/generation stats; generative output is a labeled deterministic stub.',
|
|
48
|
+
// Adoption + interception, moved off the central maps unchanged (descriptor-first back-migration, adding-a-twin.md §3,
|
|
49
|
+
// 2026-08-31).
|
|
50
|
+
adoption: {
|
|
51
|
+
// OpenRouter's official Python SDK (OpenRouterTeam/python-sdk). An `openai` client pointed at
|
|
52
|
+
// openrouter.ai is NOT claimed here - that distribution is the openai pack's, and
|
|
53
|
+
// OPENROUTER_BASE_URL is what routes it.
|
|
54
|
+
pypi: ['openrouter'],
|
|
55
|
+
sdks: ['@openrouter/ai-sdk-provider'],
|
|
56
|
+
scopes: ['@openrouter/'],
|
|
57
|
+
// 'OR' — OpenRouter's own documented short prefix, the trio LiteLLM ships in its .env.example
|
|
58
|
+
// under a literal `# OpenRouter` heading (OR_SITE_URL / OR_APP_NAME / OR_API_KEY). Only a var
|
|
59
|
+
// whose WHOLE prefix is `OR` reaches this stem, the same narrowness that lets the github pack
|
|
60
|
+
// claim 'GH' (ladder classification 2026-09-02: litellm detected no openrouter without it).
|
|
61
|
+
envStems: ['OPENROUTER', 'OR'],
|
|
62
|
+
},
|
|
63
|
+
hosts: [{ host: 'openrouter.ai' }],
|
|
64
|
+
browserRouting: { apiPathPrefix: '/api/v1/', loaderHost: 'https://openrouter.ai' },
|
|
65
|
+
};
|
|
66
|
+
registerPack(pack);
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { RateBudget, type RateBudgetDeclaration, type RateBudgetOptions, type RateBudgetReservation, type RateBudgetSnapshot } from '@volter/world-core';
|
|
2
|
+
/** Rolling window, in ms. Matches the per-MINUTE shape of every figure OpenRouter publishes. */
|
|
3
|
+
export declare const OPENROUTER_BUDGET_WINDOW_MS = 60000;
|
|
4
|
+
/**
|
|
5
|
+
* Weighted units allowed inside one window. 20 calls/60s — the tightest per-minute figure OpenRouter
|
|
6
|
+
* documents anywhere, adopted wholesale because none of its published figures governs this connector.
|
|
7
|
+
*/
|
|
8
|
+
export declare const OPENROUTER_BUDGET_CEILING = 20;
|
|
9
|
+
/** Seconds. A `Retry-After` above this means the key is throttled hard — fail loudly. */
|
|
10
|
+
export declare const OPENROUTER_BUDGET_MAX_RETRY_AFTER_S = 300;
|
|
11
|
+
/** Per-call cost, keyed by the `<METHOD> <path>` this connector is about to request. See the header. */
|
|
12
|
+
export declare const OPENROUTER_CALL_WEIGHTS: {
|
|
13
|
+
/** `GET /api/v1/generation?id=…` — one per pending action, so unbounded in the caller's backlog. */
|
|
14
|
+
readonly generation: 2;
|
|
15
|
+
/** Every other modeled call, including the `/api/v1/models` catalog pull. */
|
|
16
|
+
readonly other: 1;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* THE PACK'S DECLARATION — pure data, the only OpenRouter-specific thing in the whole budget. Rules
|
|
20
|
+
* are ordered and first-match-wins, and they are keyed on `"<METHOD> <pathname>"`.
|
|
21
|
+
*
|
|
22
|
+
* Also exported as `pack.rateBudget` (see index.ts), so `registerPack` arms it too.
|
|
23
|
+
*/
|
|
24
|
+
export declare const OPENROUTER_RATE_BUDGET: RateBudgetDeclaration;
|
|
25
|
+
/** Split a connector path (which carries its own query string) into pathname + parsed query. */
|
|
26
|
+
export declare function splitOpenRouterPath(path: string): {
|
|
27
|
+
pathname: string;
|
|
28
|
+
query: Record<string, string>;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Price one call. Keyed off the request the connector is ABOUT to make, so an unclassified endpoint
|
|
32
|
+
* still costs `defaultWeight` — an unknown endpoint must never be free.
|
|
33
|
+
*/
|
|
34
|
+
export declare function openRouterCallWeight(method: string, path: string): number;
|
|
35
|
+
/** Where OpenRouter's ledger lives. Key-keyed and cwd-independent by default (limits are per key /
|
|
36
|
+
* per account, so a cwd-scoped ledger would hand the same key a fresh allowance in every checkout,
|
|
37
|
+
* worktree and CI matrix leg); pass `root` to opt into world-scoped accounting instead. */
|
|
38
|
+
export declare function openRouterBudgetPath(opts?: {
|
|
39
|
+
root?: string;
|
|
40
|
+
token?: string;
|
|
41
|
+
} | string): string;
|
|
42
|
+
/** Construction options for OpenRouter's budget. The vendor is fixed; everything else may only TIGHTEN. */
|
|
43
|
+
export type OpenRouterBudgetOptions = Omit<RateBudgetOptions, 'vendor'>;
|
|
44
|
+
/**
|
|
45
|
+
* OpenRouter's budget — the shared kernel guard bound to this vendor's declaration. A real subclass,
|
|
46
|
+
* not an alias, so `budget instanceof OpenRouterBudget` in `liveOpenRouterExecute` still means "a
|
|
47
|
+
* budget that accounts against OPENROUTER's ledger under OPENROUTER's ceiling": another vendor's
|
|
48
|
+
* `RateBudget` (with its own, almost certainly larger, ceiling) is NOT assignable there.
|
|
49
|
+
*/
|
|
50
|
+
export declare class OpenRouterBudget extends RateBudget {
|
|
51
|
+
constructor(opts?: OpenRouterBudgetOptions);
|
|
52
|
+
}
|
|
53
|
+
/** The typed refusal. One error class shared with every other vendor's budget; `err.vendor` says
|
|
54
|
+
* which one refused, and `err.kind` says why. */
|
|
55
|
+
export { RateBudgetError as OpenRouterBudgetError } from '@volter/world-core';
|
|
56
|
+
export type { RateBudgetErrorKind as OpenRouterBudgetErrorKind } from '@volter/world-core';
|
|
57
|
+
export type OpenRouterBudgetReservation = RateBudgetReservation;
|
|
58
|
+
export type OpenRouterBudgetSnapshot = RateBudgetSnapshot;
|