one-model-router 0.0.10 → 0.0.12

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.
Files changed (80) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +32 -5
  3. package/bin/omr.js +46 -0
  4. package/package.json +3 -2
  5. package/src/admin.js +965 -941
  6. package/src/balances.js +61 -61
  7. package/src/boot.js +117 -117
  8. package/src/channels/buddy.js +2031 -2031
  9. package/src/channels/cline.js +753 -753
  10. package/src/channels/codearts.js +2051 -2051
  11. package/src/channels/comate.js +830 -830
  12. package/src/channels/doubaowork.js +1784 -1784
  13. package/src/channels/freebuff.js +1316 -1316
  14. package/src/channels/gemini.js +1721 -1721
  15. package/src/channels/index.js +270 -270
  16. package/src/channels/joycode.js +936 -936
  17. package/src/channels/kimi.js +572 -572
  18. package/src/channels/lobsterai.js +1226 -1226
  19. package/src/channels/loomy.js +1032 -1032
  20. package/src/channels/miaoshou.js +1396 -1396
  21. package/src/channels/mimo.js +474 -474
  22. package/src/channels/minimax.js +1451 -1451
  23. package/src/channels/qoder-wasm.js +434 -434
  24. package/src/channels/qoder.js +1619 -1619
  25. package/src/channels/raccoon.js +1842 -1842
  26. package/src/channels/tabbit.js +1457 -1457
  27. package/src/channels/trae.js +1405 -1405
  28. package/src/channels/zcode-global.js +35 -35
  29. package/src/channels/zcode.js +2085 -2085
  30. package/src/checkin.js +496 -496
  31. package/src/credits.js +464 -464
  32. package/src/crypto.js +132 -132
  33. package/src/free-models.js +683 -683
  34. package/src/gateway.js +596 -578
  35. package/src/health.js +86 -86
  36. package/src/model-key.js +35 -35
  37. package/src/paths.js +96 -96
  38. package/src/probe.js +318 -318
  39. package/src/providers/builtin.js +626 -626
  40. package/src/providers/index.js +483 -457
  41. package/src/providers/kilo.js +111 -111
  42. package/src/providers/last-good.js +69 -69
  43. package/src/providers/modelsdev.js +242 -242
  44. package/src/providers/openai-compat.js +312 -312
  45. package/src/providers/opencode/bun-fetch.js +226 -226
  46. package/src/providers/opencode/lane.js +186 -186
  47. package/src/providers/opencode/o2a/LICENSE.dsh-our-free-model +21 -21
  48. package/src/providers/opencode/o2a/asset-source.js +43 -43
  49. package/src/providers/opencode/o2a/assets/opencode_prompt_v2.txt +96 -96
  50. package/src/providers/opencode/o2a/assets/opencode_tools.json +327 -327
  51. package/src/providers/opencode/o2a/entry.js +17 -17
  52. package/src/providers/opencode/o2a/gateway-body.js +42 -42
  53. package/src/providers/opencode/o2a/headers.js +133 -133
  54. package/src/providers/opencode/o2a/identity.js +148 -148
  55. package/src/providers/opencode/o2a/official-prompt.js +191 -191
  56. package/src/providers/opencode/o2a/official-tools.js +110 -110
  57. package/src/providers/opencode/o2a/tool-renames.js +217 -217
  58. package/src/providers/opencode/o2a/toolshape.js +418 -418
  59. package/src/providers/opencode/o2a/version.js +37 -37
  60. package/src/providers/opencode/upstream.js +403 -403
  61. package/src/providers/opencode/wire.js +496 -496
  62. package/src/providers/opencode.js +652 -652
  63. package/src/router.js +629 -629
  64. package/src/server.js +49 -33
  65. package/src/store.js +467 -467
  66. package/src/sync/index.js +1529 -1529
  67. package/src/sync/login-preload.cjs +52 -52
  68. package/src/sync/noise.js +141 -141
  69. package/src/sync/relay-http.js +176 -176
  70. package/src/sync/remote-host.js +818 -818
  71. package/src/sync/remote-http.js +112 -112
  72. package/src/sync/remote-login.js +657 -657
  73. package/src/sync/remote-pairing.js +204 -204
  74. package/src/sync/remote-protocol.js +321 -321
  75. package/src/sync/snapshot.js +211 -211
  76. package/src/update.js +458 -0
  77. package/src/util.js +334 -334
  78. package/web/app.js +4010 -3972
  79. package/web/index.html +32 -32
  80. package/web/style.css +971 -971
@@ -1,217 +1,217 @@
1
- /**
2
- * The opaque renaming of
3
- * client tools that keeps another client's vocabulary off the free-tier wire.
4
- *
5
- * Upstream fact: the free tier refuses a shaped body
6
- * that still carries a foreign client's tool vocabulary — Claude Code's
7
- * `ReportFindings` and `ScheduleWakeup` together are enough, and dropping
8
- * either name lifts the refusal — so **no** client tool name may reach the
9
- * wire, whatever the client is. Every named client tool is therefore renamed
10
- * to `clint_` + 12 hex of its name digest; the digest keeps one client tool on
11
- * one wire name across requests, and collisions take a `_2`, `_3`, … suffix.
12
- * The rename is invertible and the response side maps wire names back.
13
- *
14
- * Legacy `read_client`-style aliases and the earlier two-entry
15
- * compatibility table (2026-10-30) are superseded by this: renaming everything
16
- * is the general form of the same fix.
17
- *
18
- * @module src/o2a/tool-renames.js
19
- */
20
-
21
- import crypto from 'node:crypto'
22
-
23
- /** Marks every client tool the shaper renames. */
24
- export const CLIENT_TOOL_PREFIX = 'clint_'
25
-
26
- /** How many hex characters of the digest a wire name carries. */
27
- export const CLIENT_TOOL_DIGEST_LENGTH = 12
28
-
29
- /** The longest tool name the upstreams accept. */
30
- export const TOOL_WIRE_NAME_LIMIT = 64
31
-
32
- /**
33
- * Characters ignored when matching a tool name by shape, after case:
34
- * `todo_write`, `todo-write`, `todo.write` and `todowrite` all fold to one key.
35
- */
36
- const TOOL_NAME_SEPARATORS = '_.- \t\r\n'
37
-
38
- /** Lowercase `name` and drop the separators agents spell tool names with. */
39
- const SEPARATOR_SET = new Set(TOOL_NAME_SEPARATORS)
40
- export function foldToolName(name) {
41
- let out = ''
42
- for (const char of String(name ?? '').toLowerCase()) {
43
- if (!SEPARATOR_SET.has(char)) out += char
44
- }
45
- return out
46
- }
47
-
48
- /** The opaque wire name for one client tool. */
49
- export function clientToolWireName(name, used) {
50
- const taken = used instanceof Set ? used : new Set()
51
- const digest = crypto.createHash('sha256').update(String(name)).digest('hex')
52
- let clean = digest.slice(0, CLIENT_TOOL_DIGEST_LENGTH)
53
- const max = TOOL_WIRE_NAME_LIMIT - CLIENT_TOOL_PREFIX.length
54
- if (clean.length > max) clean = clean.slice(0, max)
55
- const base = CLIENT_TOOL_PREFIX + clean
56
- if (!taken.has(base)) {
57
- taken.add(base)
58
- return base
59
- }
60
- for (let suffix = 2; ; suffix += 1) {
61
- const tag = `_${suffix}`
62
- const cut = Math.min(TOOL_WIRE_NAME_LIMIT - tag.length, base.length)
63
- const candidate = base.slice(0, cut) + tag
64
- if (!taken.has(candidate)) {
65
- taken.add(candidate)
66
- return candidate
67
- }
68
- }
69
- }
70
-
71
- /**
72
- * The official tool each common client tool binds to.
73
- *
74
- * An earlier behaviour renamed every client tool into opaque `clint_` wire names
75
- * and appended the full official set beside them. That keeps the vocabulary
76
- * clean, but it also means the model can only call the *official* spellings —
77
- * a `Bash` the caller declared comes back as a call to `shell`, and the model
78
- * routinely prefers the official tool that sits right next to the renamed one.
79
- * Binding a client tool whose folded name matches one of the
80
- * known client spellings to that official name directly avoids this: the caller's own
81
- * definition rides the wire under the official name, the official definition
82
- * is not appended a second time, and the response side maps the official name
83
- * back to the caller's spelling through the same rename map as before.
84
- *
85
- * Keys are official names; values are the client spellings that bind, compared
86
- * after {@link foldToolName} (case and separators ignored). Only spellings that
87
- * actually bind are listed — `execute` has no client candidate in
88
- * the captured CLI, and `todowrite` is not one of this lane's 13 captured
89
- * definitions, so neither appears here.
90
- */
91
- export const OFFICIAL_TOOL_ALIASES = Object.freeze({
92
- edit: ['edit'],
93
- glob: ['glob'],
94
- grep: ['grep'],
95
- question: ['question', 'askuserquestion'],
96
- read: ['read', 'view'],
97
- shell: ['shell', 'bash'],
98
- skill: ['skill'],
99
- subagent: ['subagent', 'agent', 'task'],
100
- webfetch: ['webfetch', 'fetch'],
101
- websearch: ['websearch'],
102
- write: ['write'],
103
- patch: ['patch', 'applypatch'],
104
- })
105
-
106
- /** Folded client spelling → official name, first spelling wins. */
107
- const FOLDED_OFFICIAL_ALIASES = (() => {
108
- const index = new Map()
109
- for (const [official, spellings] of Object.entries(OFFICIAL_TOOL_ALIASES)) {
110
- for (const spelling of spellings) {
111
- const folded = foldToolName(spelling)
112
- if (!index.has(folded)) index.set(folded, official)
113
- }
114
- }
115
- return index
116
- })()
117
-
118
- /**
119
- * The official name one declared client tool binds to, or null.
120
- * Matching is folded, so `WebFetch`, `webfetch` and `web_fetch` all bind to
121
- * `webfetch`; a name two officials could claim keeps its first declaration
122
- * order win because each official is bound at most once per request (the
123
- * caller checks that).
124
- */
125
- export function officialForClientName(name) {
126
- if (typeof name !== 'string' || name === '') return null
127
- return FOLDED_OFFICIAL_ALIASES.get(foldToolName(name)) ?? null
128
- }
129
-
130
- /**
131
- * The rename set of one shaped request, as a `Map` from wire
132
- * name back to client name so existing consumers keep working — the stream
133
- * decoder has always received exactly such a map. The extra methods are
134
- * forward lookup, response-side {@link resolve} with the folded
135
- * fallbacks, and prefix probes for streaming.
136
- */
137
- export class ToolRenameMap extends Map {
138
- constructor() {
139
- super()
140
- this.#byClient = new Map()
141
- this.#byCase = new Map()
142
- this.#byShape = new Map()
143
- }
144
-
145
- /** Records one client→wire mapping. Conflicts keep the first allocation. */
146
- add(client, wire) {
147
- if (!client || !wire || client === wire) return
148
- if (this.#byClient.has(client)) return
149
- if (this.has(wire)) return
150
- this.#byClient.set(client, wire)
151
- this.set(wire, client)
152
- bindFolded(this.#byCase, String(client).toLowerCase(), client)
153
- bindFolded(this.#byShape, foldToolName(client), client)
154
- }
155
-
156
- /** The wire name registered for an exact client name. */
157
- wireOf(client) {
158
- return this.#byClient.get(client)
159
- }
160
-
161
- /** Whether any wire name starts with `prefix`. */
162
- hasPrefix(prefix) {
163
- if (!prefix) return false
164
- for (const wire of this.keys()) {
165
- if (wire.startsWith(prefix)) return true
166
- }
167
- return false
168
- }
169
-
170
- /** Whether a wire name is longer than `prefix` and starts with it. */
171
- hasLongerPrefix(prefix) {
172
- if (!prefix) return false
173
- for (const wire of this.keys()) {
174
- if (wire.length > prefix.length && wire.startsWith(prefix)) return true
175
- }
176
- return false
177
- }
178
-
179
- /**
180
- * Map a name the upstream reported back to the name the client declared:
181
- * an exact wire name restores; a `clint_` prefix is stripped as
182
- * best-effort recovery; a name that differs from exactly one declared client
183
- * tool in case, or in case and separators, folds onto that tool. A name two
184
- * tools fold to is never guessed between.
185
- */
186
- resolve(wire) {
187
- if (!wire) return wire
188
- const exact = this.get(wire)
189
- if (exact !== undefined) return exact
190
- let client = wire
191
- if (client.startsWith(CLIENT_TOOL_PREFIX)) {
192
- const rest = client.slice(CLIENT_TOOL_PREFIX.length)
193
- if (rest !== '') client = rest
194
- }
195
- if (this.#byClient.has(client)) return client
196
- const caseMatch = this.#byCase.get(client.toLowerCase())
197
- if (caseMatch !== undefined) return caseMatch !== '' ? caseMatch : client
198
- const shapeMatch = this.#byShape.get(foldToolName(client))
199
- if (shapeMatch !== undefined && shapeMatch !== '') return shapeMatch
200
- return client
201
- }
202
-
203
- #byClient
204
- #byCase
205
- #byShape
206
- }
207
-
208
- /** Records `client` under `key`, marking a key two clients share as ambiguous (`bindFolded`). */
209
- function bindFolded(folded, key, client) {
210
- if (!key) return
211
- const existing = folded.get(key)
212
- if (existing === undefined) {
213
- folded.set(key, client)
214
- return
215
- }
216
- if (existing !== client) folded.set(key, '')
217
- }
1
+ /**
2
+ * The opaque renaming of
3
+ * client tools that keeps another client's vocabulary off the free-tier wire.
4
+ *
5
+ * Upstream fact: the free tier refuses a shaped body
6
+ * that still carries a foreign client's tool vocabulary — Claude Code's
7
+ * `ReportFindings` and `ScheduleWakeup` together are enough, and dropping
8
+ * either name lifts the refusal — so **no** client tool name may reach the
9
+ * wire, whatever the client is. Every named client tool is therefore renamed
10
+ * to `clint_` + 12 hex of its name digest; the digest keeps one client tool on
11
+ * one wire name across requests, and collisions take a `_2`, `_3`, … suffix.
12
+ * The rename is invertible and the response side maps wire names back.
13
+ *
14
+ * Legacy `read_client`-style aliases and the earlier two-entry
15
+ * compatibility table (2026-10-30) are superseded by this: renaming everything
16
+ * is the general form of the same fix.
17
+ *
18
+ * @module src/o2a/tool-renames.js
19
+ */
20
+
21
+ import crypto from 'node:crypto'
22
+
23
+ /** Marks every client tool the shaper renames. */
24
+ export const CLIENT_TOOL_PREFIX = 'clint_'
25
+
26
+ /** How many hex characters of the digest a wire name carries. */
27
+ export const CLIENT_TOOL_DIGEST_LENGTH = 12
28
+
29
+ /** The longest tool name the upstreams accept. */
30
+ export const TOOL_WIRE_NAME_LIMIT = 64
31
+
32
+ /**
33
+ * Characters ignored when matching a tool name by shape, after case:
34
+ * `todo_write`, `todo-write`, `todo.write` and `todowrite` all fold to one key.
35
+ */
36
+ const TOOL_NAME_SEPARATORS = '_.- \t\r\n'
37
+
38
+ /** Lowercase `name` and drop the separators agents spell tool names with. */
39
+ const SEPARATOR_SET = new Set(TOOL_NAME_SEPARATORS)
40
+ export function foldToolName(name) {
41
+ let out = ''
42
+ for (const char of String(name ?? '').toLowerCase()) {
43
+ if (!SEPARATOR_SET.has(char)) out += char
44
+ }
45
+ return out
46
+ }
47
+
48
+ /** The opaque wire name for one client tool. */
49
+ export function clientToolWireName(name, used) {
50
+ const taken = used instanceof Set ? used : new Set()
51
+ const digest = crypto.createHash('sha256').update(String(name)).digest('hex')
52
+ let clean = digest.slice(0, CLIENT_TOOL_DIGEST_LENGTH)
53
+ const max = TOOL_WIRE_NAME_LIMIT - CLIENT_TOOL_PREFIX.length
54
+ if (clean.length > max) clean = clean.slice(0, max)
55
+ const base = CLIENT_TOOL_PREFIX + clean
56
+ if (!taken.has(base)) {
57
+ taken.add(base)
58
+ return base
59
+ }
60
+ for (let suffix = 2; ; suffix += 1) {
61
+ const tag = `_${suffix}`
62
+ const cut = Math.min(TOOL_WIRE_NAME_LIMIT - tag.length, base.length)
63
+ const candidate = base.slice(0, cut) + tag
64
+ if (!taken.has(candidate)) {
65
+ taken.add(candidate)
66
+ return candidate
67
+ }
68
+ }
69
+ }
70
+
71
+ /**
72
+ * The official tool each common client tool binds to.
73
+ *
74
+ * An earlier behaviour renamed every client tool into opaque `clint_` wire names
75
+ * and appended the full official set beside them. That keeps the vocabulary
76
+ * clean, but it also means the model can only call the *official* spellings —
77
+ * a `Bash` the caller declared comes back as a call to `shell`, and the model
78
+ * routinely prefers the official tool that sits right next to the renamed one.
79
+ * Binding a client tool whose folded name matches one of the
80
+ * known client spellings to that official name directly avoids this: the caller's own
81
+ * definition rides the wire under the official name, the official definition
82
+ * is not appended a second time, and the response side maps the official name
83
+ * back to the caller's spelling through the same rename map as before.
84
+ *
85
+ * Keys are official names; values are the client spellings that bind, compared
86
+ * after {@link foldToolName} (case and separators ignored). Only spellings that
87
+ * actually bind are listed — `execute` has no client candidate in
88
+ * the captured CLI, and `todowrite` is not one of this lane's 13 captured
89
+ * definitions, so neither appears here.
90
+ */
91
+ export const OFFICIAL_TOOL_ALIASES = Object.freeze({
92
+ edit: ['edit'],
93
+ glob: ['glob'],
94
+ grep: ['grep'],
95
+ question: ['question', 'askuserquestion'],
96
+ read: ['read', 'view'],
97
+ shell: ['shell', 'bash'],
98
+ skill: ['skill'],
99
+ subagent: ['subagent', 'agent', 'task'],
100
+ webfetch: ['webfetch', 'fetch'],
101
+ websearch: ['websearch'],
102
+ write: ['write'],
103
+ patch: ['patch', 'applypatch'],
104
+ })
105
+
106
+ /** Folded client spelling → official name, first spelling wins. */
107
+ const FOLDED_OFFICIAL_ALIASES = (() => {
108
+ const index = new Map()
109
+ for (const [official, spellings] of Object.entries(OFFICIAL_TOOL_ALIASES)) {
110
+ for (const spelling of spellings) {
111
+ const folded = foldToolName(spelling)
112
+ if (!index.has(folded)) index.set(folded, official)
113
+ }
114
+ }
115
+ return index
116
+ })()
117
+
118
+ /**
119
+ * The official name one declared client tool binds to, or null.
120
+ * Matching is folded, so `WebFetch`, `webfetch` and `web_fetch` all bind to
121
+ * `webfetch`; a name two officials could claim keeps its first declaration
122
+ * order win because each official is bound at most once per request (the
123
+ * caller checks that).
124
+ */
125
+ export function officialForClientName(name) {
126
+ if (typeof name !== 'string' || name === '') return null
127
+ return FOLDED_OFFICIAL_ALIASES.get(foldToolName(name)) ?? null
128
+ }
129
+
130
+ /**
131
+ * The rename set of one shaped request, as a `Map` from wire
132
+ * name back to client name so existing consumers keep working — the stream
133
+ * decoder has always received exactly such a map. The extra methods are
134
+ * forward lookup, response-side {@link resolve} with the folded
135
+ * fallbacks, and prefix probes for streaming.
136
+ */
137
+ export class ToolRenameMap extends Map {
138
+ constructor() {
139
+ super()
140
+ this.#byClient = new Map()
141
+ this.#byCase = new Map()
142
+ this.#byShape = new Map()
143
+ }
144
+
145
+ /** Records one client→wire mapping. Conflicts keep the first allocation. */
146
+ add(client, wire) {
147
+ if (!client || !wire || client === wire) return
148
+ if (this.#byClient.has(client)) return
149
+ if (this.has(wire)) return
150
+ this.#byClient.set(client, wire)
151
+ this.set(wire, client)
152
+ bindFolded(this.#byCase, String(client).toLowerCase(), client)
153
+ bindFolded(this.#byShape, foldToolName(client), client)
154
+ }
155
+
156
+ /** The wire name registered for an exact client name. */
157
+ wireOf(client) {
158
+ return this.#byClient.get(client)
159
+ }
160
+
161
+ /** Whether any wire name starts with `prefix`. */
162
+ hasPrefix(prefix) {
163
+ if (!prefix) return false
164
+ for (const wire of this.keys()) {
165
+ if (wire.startsWith(prefix)) return true
166
+ }
167
+ return false
168
+ }
169
+
170
+ /** Whether a wire name is longer than `prefix` and starts with it. */
171
+ hasLongerPrefix(prefix) {
172
+ if (!prefix) return false
173
+ for (const wire of this.keys()) {
174
+ if (wire.length > prefix.length && wire.startsWith(prefix)) return true
175
+ }
176
+ return false
177
+ }
178
+
179
+ /**
180
+ * Map a name the upstream reported back to the name the client declared:
181
+ * an exact wire name restores; a `clint_` prefix is stripped as
182
+ * best-effort recovery; a name that differs from exactly one declared client
183
+ * tool in case, or in case and separators, folds onto that tool. A name two
184
+ * tools fold to is never guessed between.
185
+ */
186
+ resolve(wire) {
187
+ if (!wire) return wire
188
+ const exact = this.get(wire)
189
+ if (exact !== undefined) return exact
190
+ let client = wire
191
+ if (client.startsWith(CLIENT_TOOL_PREFIX)) {
192
+ const rest = client.slice(CLIENT_TOOL_PREFIX.length)
193
+ if (rest !== '') client = rest
194
+ }
195
+ if (this.#byClient.has(client)) return client
196
+ const caseMatch = this.#byCase.get(client.toLowerCase())
197
+ if (caseMatch !== undefined) return caseMatch !== '' ? caseMatch : client
198
+ const shapeMatch = this.#byShape.get(foldToolName(client))
199
+ if (shapeMatch !== undefined && shapeMatch !== '') return shapeMatch
200
+ return client
201
+ }
202
+
203
+ #byClient
204
+ #byCase
205
+ #byShape
206
+ }
207
+
208
+ /** Records `client` under `key`, marking a key two clients share as ambiguous (`bindFolded`). */
209
+ function bindFolded(folded, key, client) {
210
+ if (!key) return
211
+ const existing = folded.get(key)
212
+ if (existing === undefined) {
213
+ folded.set(key, client)
214
+ return
215
+ }
216
+ if (existing !== client) folded.set(key, '')
217
+ }