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,17 +1,17 @@
1
- /**
2
- * `o2a/` 整形层的唯一出口(把 8 个纯函数模块摊成一个导入点)。
3
- *
4
- * 各模块的职责见每个文件的头注释;本文件只做再导出,
5
- * 不含任何逻辑。
6
- *
7
- * @module src/providers/opencode/o2a/entry
8
- */
9
-
10
- export * from './version.js'
11
- export * from './identity.js'
12
- export * from './headers.js'
13
- export * from './tool-renames.js'
14
- export * from './official-tools.js'
15
- export * from './official-prompt.js'
16
- export * from './toolshape.js'
17
- export * from './gateway-body.js'
1
+ /**
2
+ * `o2a/` 整形层的唯一出口(把 8 个纯函数模块摊成一个导入点)。
3
+ *
4
+ * 各模块的职责见每个文件的头注释;本文件只做再导出,
5
+ * 不含任何逻辑。
6
+ *
7
+ * @module src/providers/opencode/o2a/entry
8
+ */
9
+
10
+ export * from './version.js'
11
+ export * from './identity.js'
12
+ export * from './headers.js'
13
+ export * from './tool-renames.js'
14
+ export * from './official-tools.js'
15
+ export * from './official-prompt.js'
16
+ export * from './toolshape.js'
17
+ export * from './gateway-body.js'
@@ -1,42 +1,42 @@
1
- /**
2
- * Body-level shaping of the anonymous lane — the fields a 2.x chat body always
3
- * carries.
4
- *
5
- * Streaming is not forced here: the caller controls streaming itself (its
6
- * harness lane is always streamed, its probe lane may not be). What is applied:
7
- *
8
- * - `stream_options.include_usage: true` on a streamed chat body,
9
- * so the lane's usage frames survive shaping;
10
- * - `max_completion_tokens: 32000` when the caller named no ceiling,
11
- * so the free tier always sees the client's
12
- * own ceiling.
13
- *
14
- * Both apply to the Chat wire only; the Anthropic and Responses lanes keep
15
- * their own required fields (`max_tokens` / `max_output_tokens`).
16
- *
17
- * @module src/o2a/gateway-body.js
18
- */
19
-
20
- import { V2_COMPLETION_LIMIT } from './version.js'
21
-
22
- /** `stream_options.include_usage: true` on a streamed chat body. */
23
- export function ensureChatUsage(payload, shape) {
24
- if (shape !== 'chat') return false
25
- if (payload.stream !== true) return false
26
- if (payload.stream_options && typeof payload.stream_options === 'object' && !Array.isArray(payload.stream_options)) {
27
- if (payload.stream_options.include_usage === true) return false
28
- payload.stream_options = { ...payload.stream_options, include_usage: true }
29
- return true
30
- }
31
- payload.stream_options = { include_usage: true }
32
- return true
33
- }
34
-
35
- /** The 2.x completion ceiling when the caller named none. */
36
- export function ensureV2CompletionLimit(payload, shape) {
37
- if (shape !== 'chat') return false
38
- if (payload.max_completion_tokens !== undefined) return false
39
- if (payload.max_tokens !== undefined) return false
40
- payload.max_completion_tokens = V2_COMPLETION_LIMIT
41
- return true
42
- }
1
+ /**
2
+ * Body-level shaping of the anonymous lane — the fields a 2.x chat body always
3
+ * carries.
4
+ *
5
+ * Streaming is not forced here: the caller controls streaming itself (its
6
+ * harness lane is always streamed, its probe lane may not be). What is applied:
7
+ *
8
+ * - `stream_options.include_usage: true` on a streamed chat body,
9
+ * so the lane's usage frames survive shaping;
10
+ * - `max_completion_tokens: 32000` when the caller named no ceiling,
11
+ * so the free tier always sees the client's
12
+ * own ceiling.
13
+ *
14
+ * Both apply to the Chat wire only; the Anthropic and Responses lanes keep
15
+ * their own required fields (`max_tokens` / `max_output_tokens`).
16
+ *
17
+ * @module src/o2a/gateway-body.js
18
+ */
19
+
20
+ import { V2_COMPLETION_LIMIT } from './version.js'
21
+
22
+ /** `stream_options.include_usage: true` on a streamed chat body. */
23
+ export function ensureChatUsage(payload, shape) {
24
+ if (shape !== 'chat') return false
25
+ if (payload.stream !== true) return false
26
+ if (payload.stream_options && typeof payload.stream_options === 'object' && !Array.isArray(payload.stream_options)) {
27
+ if (payload.stream_options.include_usage === true) return false
28
+ payload.stream_options = { ...payload.stream_options, include_usage: true }
29
+ return true
30
+ }
31
+ payload.stream_options = { include_usage: true }
32
+ return true
33
+ }
34
+
35
+ /** The 2.x completion ceiling when the caller named none. */
36
+ export function ensureV2CompletionLimit(payload, shape) {
37
+ if (shape !== 'chat') return false
38
+ if (payload.max_completion_tokens !== undefined) return false
39
+ if (payload.max_tokens !== undefined) return false
40
+ payload.max_completion_tokens = V2_COMPLETION_LIMIT
41
+ return true
42
+ }
@@ -1,133 +1,133 @@
1
- /**
2
- * The OpenCode 2.x CLI header set the v2 gates fingerprint.
3
- *
4
- * Upstream facts (each one is a refusal on its own):
5
- * - `x-opencode-session` (conversation affinity), `x-session-affinity` and
6
- * `X-Session-Id` carry the canonical session; `x-opencode-session-id` carries
7
- * the client's child session when one exists (a subagent keeps its child id
8
- * while affinity stays on the parent) and the session itself otherwise.
9
- * - `x-opencode-project` is a bare 40-character hex id. A canonical `prj_*`
10
- * style project is rejected, so any caller project that is not the literal
11
- * `global` or a 40-hex git commit is hashed into the shape (`projectID`).
12
- * `projectID` is stable: one project maps to one upstream id, masking the
13
- * caller's spelling.
14
- * - `x-opencode-request` is the v1 lane's header; the v2 gate rejects it, so
15
- * it is never sent.
16
- * - Anthropic requests on the v2 lane carry the `anthropic-beta` header and a
17
- * `beta=true` query on the endpoint.
18
- *
19
- * The lane adds its own transport fields around that set: the pooled
20
- * keyless credential `Authorization: Bearer public`, the
21
- * JSON content type, the W3C trace pair the official 2.2.3 client emits
22
- * (`traceHeaders`), and the `accept` value the caller's streaming needs.
23
- *
24
- * @module src/o2a/headers.js
25
- */
26
-
27
- import crypto from 'node:crypto'
28
- import { ANONYMOUS_CREDENTIAL, CLIENT_UA } from './version.js'
29
-
30
- /** The 40-hex shape of a git root commit, which `projectID` keeps verbatim. */
31
- const GIT_COMMIT_RE = /^[0-9a-f]{40}$/
32
-
33
- /**
34
- * Render one project signal into the upstream project id:
35
- * a genuine git commit hash or `global` is kept verbatim, any other project is
36
- * hashed into the same 40-character lowercase hex shape. The value itself is
37
- * not checked upstream, only its shape.
38
- */
39
- export function projectID(project) {
40
- if (project === 'global' || GIT_COMMIT_RE.test(String(project))) return project
41
- const sum = crypto.createHash('sha256').update(`opencode-project\0${project}`).digest()
42
- return sum.subarray(0, 20).toString('hex')
43
- }
44
-
45
- /**
46
- * The stable project id for one conversation (`stableProjectID`).
47
- *
48
- * Minting a fresh project per request is the opposite of what a single-IP
49
- * client wants: every retry, continuation and catalog refresh then lands in a
50
- * fresh bucket, so one conversation's usage is scattered across identities the
51
- * upstream cannot correlate. Deriving the project from the
52
- * session id instead keeps one conversation on one bucket — the shape stays
53
- * the 40-hex id the gate checks, the value stays stable for the conversation's
54
- * life, and a caller-named project still wins (passed through `projectID`).
55
- *
56
- * @param {string} session - the canonical conversation-affinity session
57
- * @returns {string} a 40-character lowercase hex project id
58
- */
59
- export function stableProjectID(session) {
60
- return projectID(String(session ?? ''))
61
- }
62
-
63
- /**
64
- * One W3C Trace Context pair for one request (`traceHeaders`).
65
- *
66
- * The official 2.2.3 client carries `traceparent` and `b3` on every inference
67
- * request (captured live via an HTTP-Toolkit trace) — the distributed
68
- * trace propagation every OTel-instrumented client emits. The trace is the
69
- * header most likely to distinguish a genuine client; whatever
70
- * the gate does with it, a third-party client that omits both looks less like
71
- * the real thing, so the lane sends a well-formed pair: one trace id, one span
72
- * id, both sampled, the `b3` single-header form carrying the same ids plus the
73
- * parent span the zipkin shape expects.
74
- *
75
- * Fresh ids per request on purpose: a span is one request's work, and reusing
76
- * a trace across requests is the fingerprint of a broken instrumented client.
77
- *
78
- * @returns {{ 'traceparent': string, 'b3': string }}
79
- */
80
- export function traceHeaders() {
81
- const traceId = crypto.randomBytes(16).toString('hex')
82
- const spanId = crypto.randomBytes(8).toString('hex')
83
- const parentId = crypto.randomBytes(8).toString('hex')
84
- return {
85
- 'traceparent': `00-${traceId}-${spanId}-01`,
86
- 'b3': `${traceId}-${spanId}-1-${parentId}`,
87
- }
88
- }
89
-
90
- /**
91
- * The v2 header set for one request.
92
- *
93
- * Aligned with the official 2.2.3 client's outbound bytes (HTTP-Toolkit
94
- * trace, 2026-10-30): the trace pair rides every request, and the
95
- * client's fetch stack emits an `accept: asterisk-slash-asterisk` wildcard —
96
- * an earlier capture that omitted `accept` described a
97
- * Go client, not the official one.
98
- *
99
- * @param {object} options
100
- * @param {string} options.session - the canonical conversation-affinity session
101
- * @param {string} [options.childSession] - the client's own child session for
102
- * `x-opencode-session-id`; defaults to `session`
103
- * @param {string} [options.project] - caller project signal; defaults to a
104
- * stable id derived from the session ({@link stableProjectID}), so one
105
- * conversation's retries/continuations/refreshes share one quota bucket
106
- * instead of scattering across per-request identities
107
- * @param {boolean} [options.stream] - unused for the header set (the accept
108
- * value no longer depends on it); kept for signature compatibility
109
- * @param {string} [options.accept] - explicit `accept` override; the wildcard
110
- * the wildcard by default (the official client's fetch default), `null` to
111
- * omit the header entirely
112
- * @param {boolean} [options.anthropic] - add the Messages-lane beta header
113
- * @param {string} [options.userAgent] - UA override; the lane pins
114
- * {@link CLIENT_UA} (the attribution hook in src/http.js resolves to it)
115
- * @returns {Record<string, string>}
116
- */
117
- export function gatewayHeaders({ session, childSession, project, stream, accept, anthropic, userAgent } = {}) {
118
- const headers = {
119
- 'content-type': 'application/json',
120
- 'authorization': `Bearer ${ANONYMOUS_CREDENTIAL}`,
121
- 'user-agent': userAgent ?? CLIENT_UA,
122
- 'x-opencode-client': 'cli',
123
- 'x-session-affinity': session,
124
- 'x-session-id': session,
125
- 'x-opencode-session': session,
126
- 'x-opencode-session-id': childSession ?? session,
127
- 'x-opencode-project': projectID(project ?? stableProjectID(session)),
128
- ...traceHeaders(),
129
- }
130
- if (accept !== null) headers['accept'] = accept ?? '*/*'
131
- if (anthropic) headers['anthropic-beta'] = 'interleaved-thinking-2025-05-14'
132
- return headers
133
- }
1
+ /**
2
+ * The OpenCode 2.x CLI header set the v2 gates fingerprint.
3
+ *
4
+ * Upstream facts (each one is a refusal on its own):
5
+ * - `x-opencode-session` (conversation affinity), `x-session-affinity` and
6
+ * `X-Session-Id` carry the canonical session; `x-opencode-session-id` carries
7
+ * the client's child session when one exists (a subagent keeps its child id
8
+ * while affinity stays on the parent) and the session itself otherwise.
9
+ * - `x-opencode-project` is a bare 40-character hex id. A canonical `prj_*`
10
+ * style project is rejected, so any caller project that is not the literal
11
+ * `global` or a 40-hex git commit is hashed into the shape (`projectID`).
12
+ * `projectID` is stable: one project maps to one upstream id, masking the
13
+ * caller's spelling.
14
+ * - `x-opencode-request` is the v1 lane's header; the v2 gate rejects it, so
15
+ * it is never sent.
16
+ * - Anthropic requests on the v2 lane carry the `anthropic-beta` header and a
17
+ * `beta=true` query on the endpoint.
18
+ *
19
+ * The lane adds its own transport fields around that set: the pooled
20
+ * keyless credential `Authorization: Bearer public`, the
21
+ * JSON content type, the W3C trace pair the official 2.2.3 client emits
22
+ * (`traceHeaders`), and the `accept` value the caller's streaming needs.
23
+ *
24
+ * @module src/o2a/headers.js
25
+ */
26
+
27
+ import crypto from 'node:crypto'
28
+ import { ANONYMOUS_CREDENTIAL, CLIENT_UA } from './version.js'
29
+
30
+ /** The 40-hex shape of a git root commit, which `projectID` keeps verbatim. */
31
+ const GIT_COMMIT_RE = /^[0-9a-f]{40}$/
32
+
33
+ /**
34
+ * Render one project signal into the upstream project id:
35
+ * a genuine git commit hash or `global` is kept verbatim, any other project is
36
+ * hashed into the same 40-character lowercase hex shape. The value itself is
37
+ * not checked upstream, only its shape.
38
+ */
39
+ export function projectID(project) {
40
+ if (project === 'global' || GIT_COMMIT_RE.test(String(project))) return project
41
+ const sum = crypto.createHash('sha256').update(`opencode-project\0${project}`).digest()
42
+ return sum.subarray(0, 20).toString('hex')
43
+ }
44
+
45
+ /**
46
+ * The stable project id for one conversation (`stableProjectID`).
47
+ *
48
+ * Minting a fresh project per request is the opposite of what a single-IP
49
+ * client wants: every retry, continuation and catalog refresh then lands in a
50
+ * fresh bucket, so one conversation's usage is scattered across identities the
51
+ * upstream cannot correlate. Deriving the project from the
52
+ * session id instead keeps one conversation on one bucket — the shape stays
53
+ * the 40-hex id the gate checks, the value stays stable for the conversation's
54
+ * life, and a caller-named project still wins (passed through `projectID`).
55
+ *
56
+ * @param {string} session - the canonical conversation-affinity session
57
+ * @returns {string} a 40-character lowercase hex project id
58
+ */
59
+ export function stableProjectID(session) {
60
+ return projectID(String(session ?? ''))
61
+ }
62
+
63
+ /**
64
+ * One W3C Trace Context pair for one request (`traceHeaders`).
65
+ *
66
+ * The official 2.2.3 client carries `traceparent` and `b3` on every inference
67
+ * request (captured live via an HTTP-Toolkit trace) — the distributed
68
+ * trace propagation every OTel-instrumented client emits. The trace is the
69
+ * header most likely to distinguish a genuine client; whatever
70
+ * the gate does with it, a third-party client that omits both looks less like
71
+ * the real thing, so the lane sends a well-formed pair: one trace id, one span
72
+ * id, both sampled, the `b3` single-header form carrying the same ids plus the
73
+ * parent span the zipkin shape expects.
74
+ *
75
+ * Fresh ids per request on purpose: a span is one request's work, and reusing
76
+ * a trace across requests is the fingerprint of a broken instrumented client.
77
+ *
78
+ * @returns {{ 'traceparent': string, 'b3': string }}
79
+ */
80
+ export function traceHeaders() {
81
+ const traceId = crypto.randomBytes(16).toString('hex')
82
+ const spanId = crypto.randomBytes(8).toString('hex')
83
+ const parentId = crypto.randomBytes(8).toString('hex')
84
+ return {
85
+ 'traceparent': `00-${traceId}-${spanId}-01`,
86
+ 'b3': `${traceId}-${spanId}-1-${parentId}`,
87
+ }
88
+ }
89
+
90
+ /**
91
+ * The v2 header set for one request.
92
+ *
93
+ * Aligned with the official 2.2.3 client's outbound bytes (HTTP-Toolkit
94
+ * trace, 2026-10-30): the trace pair rides every request, and the
95
+ * client's fetch stack emits an `accept: asterisk-slash-asterisk` wildcard —
96
+ * an earlier capture that omitted `accept` described a
97
+ * Go client, not the official one.
98
+ *
99
+ * @param {object} options
100
+ * @param {string} options.session - the canonical conversation-affinity session
101
+ * @param {string} [options.childSession] - the client's own child session for
102
+ * `x-opencode-session-id`; defaults to `session`
103
+ * @param {string} [options.project] - caller project signal; defaults to a
104
+ * stable id derived from the session ({@link stableProjectID}), so one
105
+ * conversation's retries/continuations/refreshes share one quota bucket
106
+ * instead of scattering across per-request identities
107
+ * @param {boolean} [options.stream] - unused for the header set (the accept
108
+ * value no longer depends on it); kept for signature compatibility
109
+ * @param {string} [options.accept] - explicit `accept` override; the wildcard
110
+ * the wildcard by default (the official client's fetch default), `null` to
111
+ * omit the header entirely
112
+ * @param {boolean} [options.anthropic] - add the Messages-lane beta header
113
+ * @param {string} [options.userAgent] - UA override; the lane pins
114
+ * {@link CLIENT_UA} (the attribution hook in src/http.js resolves to it)
115
+ * @returns {Record<string, string>}
116
+ */
117
+ export function gatewayHeaders({ session, childSession, project, stream, accept, anthropic, userAgent } = {}) {
118
+ const headers = {
119
+ 'content-type': 'application/json',
120
+ 'authorization': `Bearer ${ANONYMOUS_CREDENTIAL}`,
121
+ 'user-agent': userAgent ?? CLIENT_UA,
122
+ 'x-opencode-client': 'cli',
123
+ 'x-session-affinity': session,
124
+ 'x-session-id': session,
125
+ 'x-opencode-session': session,
126
+ 'x-opencode-session-id': childSession ?? session,
127
+ 'x-opencode-project': projectID(project ?? stableProjectID(session)),
128
+ ...traceHeaders(),
129
+ }
130
+ if (accept !== null) headers['accept'] = accept ?? '*/*'
131
+ if (anthropic) headers['anthropic-beta'] = 'interleaved-thinking-2025-05-14'
132
+ return headers
133
+ }