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,52 +1,52 @@
1
- /**
2
- * 登录窗口 preload:在站点任何脚本与首帧绘制之前盖一层「加载中」遮罩,
3
- * 等主进程注入的脚本改完 DOM 后撤掉,避免用户先看到站点原样、再闪一下变成目标样式。
4
- *
5
- * 沙箱渲染进程里可用 DOM API,不使用 Node 能力。
6
- * 注意:遮罩不能带 pointer-events:none —— 失败/超时提示的「返回重试」按钮会追加进这个
7
- * 遮罩,none 会让真实点击穿透、按钮永远点不到。
8
- */
9
- const VEIL_ID = 'omr-login-veil'
10
-
11
- function installVeil() {
12
- const root = document.documentElement
13
- if (!root) { setTimeout(installVeil, 0); return }
14
- if (document.getElementById(VEIL_ID)) return
15
-
16
- const veil = document.createElement('div')
17
- veil.id = VEIL_ID
18
- veil.setAttribute('style', [
19
- 'position:fixed', 'inset:0', 'z-index:2147483647',
20
- 'display:flex', 'flex-direction:column', 'align-items:center', 'justify-content:center', 'gap:14px',
21
- 'background:#fff', 'color:#6b7280', 'font:14px/1.5 system-ui,sans-serif',
22
- ].join(';'))
23
-
24
- const style = document.createElement('style')
25
- style.textContent = '@keyframes omr-veil-spin{to{transform:rotate(360deg)}}'
26
-
27
- const ring = document.createElement('div')
28
- ring.setAttribute('style', [
29
- 'width:34px', 'height:34px', 'border-radius:50%',
30
- 'border:3px solid rgba(15,110,86,.16)', 'border-top-color:#0F6E56',
31
- 'animation:omr-veil-spin .8s linear infinite',
32
- ].join(';'))
33
-
34
- const text = document.createElement('div')
35
- text.textContent = '加载中…'
36
-
37
- veil.appendChild(style)
38
- veil.appendChild(ring)
39
- veil.appendChild(text)
40
- root.appendChild(veil)
41
-
42
- // 兜底:注入脚本异常时不至于一直卡在加载动画。
43
- // 只在遮罩还是纯加载态时移除——若里面已追加失败/超时提示(#omr-login-timeout),保留给用户操作。
44
- setTimeout(() => {
45
- try {
46
- const v = document.getElementById(VEIL_ID)
47
- if (v && !v.querySelector('#omr-login-timeout')) v.remove()
48
- } catch { /* 页面已卸载 */ }
49
- }, 8000)
50
- }
51
-
52
- installVeil()
1
+ /**
2
+ * 登录窗口 preload:在站点任何脚本与首帧绘制之前盖一层「加载中」遮罩,
3
+ * 等主进程注入的脚本改完 DOM 后撤掉,避免用户先看到站点原样、再闪一下变成目标样式。
4
+ *
5
+ * 沙箱渲染进程里可用 DOM API,不使用 Node 能力。
6
+ * 注意:遮罩不能带 pointer-events:none —— 失败/超时提示的「返回重试」按钮会追加进这个
7
+ * 遮罩,none 会让真实点击穿透、按钮永远点不到。
8
+ */
9
+ const VEIL_ID = 'omr-login-veil'
10
+
11
+ function installVeil() {
12
+ const root = document.documentElement
13
+ if (!root) { setTimeout(installVeil, 0); return }
14
+ if (document.getElementById(VEIL_ID)) return
15
+
16
+ const veil = document.createElement('div')
17
+ veil.id = VEIL_ID
18
+ veil.setAttribute('style', [
19
+ 'position:fixed', 'inset:0', 'z-index:2147483647',
20
+ 'display:flex', 'flex-direction:column', 'align-items:center', 'justify-content:center', 'gap:14px',
21
+ 'background:#fff', 'color:#6b7280', 'font:14px/1.5 system-ui,sans-serif',
22
+ ].join(';'))
23
+
24
+ const style = document.createElement('style')
25
+ style.textContent = '@keyframes omr-veil-spin{to{transform:rotate(360deg)}}'
26
+
27
+ const ring = document.createElement('div')
28
+ ring.setAttribute('style', [
29
+ 'width:34px', 'height:34px', 'border-radius:50%',
30
+ 'border:3px solid rgba(15,110,86,.16)', 'border-top-color:#0F6E56',
31
+ 'animation:omr-veil-spin .8s linear infinite',
32
+ ].join(';'))
33
+
34
+ const text = document.createElement('div')
35
+ text.textContent = '加载中…'
36
+
37
+ veil.appendChild(style)
38
+ veil.appendChild(ring)
39
+ veil.appendChild(text)
40
+ root.appendChild(veil)
41
+
42
+ // 兜底:注入脚本异常时不至于一直卡在加载动画。
43
+ // 只在遮罩还是纯加载态时移除——若里面已追加失败/超时提示(#omr-login-timeout),保留给用户操作。
44
+ setTimeout(() => {
45
+ try {
46
+ const v = document.getElementById(VEIL_ID)
47
+ if (v && !v.querySelector('#omr-login-timeout')) v.remove()
48
+ } catch { /* 页面已卸载 */ }
49
+ }, 8000)
50
+ }
51
+
52
+ installVeil()
package/src/sync/noise.js CHANGED
@@ -1,141 +1,141 @@
1
- /**
2
- * Noise_IK_25519_ChaChaPoly_SHA256 会话封装。
3
- *
4
- * 只保留 v1 固定套件;在握手完成前强制校验远端静态公钥(identity pinning),
5
- * 不匹配即 `PEER_IDENTITY_MISMATCH` fail closed 并销毁会话。
6
- *
7
- * 实现要点:随机数默认走 WebCrypto `getRandomValues`(Node 22 与小程序
8
- * 都可 shim);base64url 解码用 Buffer,
9
- * B2 小程序移植时替换 base64url 编码函数即可。
10
- *
11
- * 本机实测:initiator msg1=96B、responder msg2=48B,
12
- * 双向 transport 加解密往返成功。
13
- */
14
-
15
- import { NqHandshake, noiseIk, chachaPoly, sha256H } from '@lukeburns/clatterjs'
16
-
17
- export const NOISE_IK_PROTOCOL = 'Noise_IK_25519_ChaChaPoly_SHA256'
18
-
19
- const defaultRandom = length => {
20
- const out = new Uint8Array(length)
21
- globalThis.crypto.getRandomValues(out)
22
- return out
23
- }
24
-
25
- const fromBase64Url = value => Uint8Array.from(Buffer.from(String(value), 'base64url'))
26
-
27
- export class NoiseSessionError extends Error {
28
- constructor(code, message) {
29
- super(message)
30
- this.name = 'NoiseSessionError'
31
- this.code = code
32
- }
33
- }
34
-
35
- function requireKey(value, label) {
36
- const key = fromBase64Url(value)
37
- if (key.byteLength !== 32) throw new NoiseSessionError('INVALID_KEY', `${label} must be a 32-byte X25519 key.`)
38
- return key
39
- }
40
-
41
- function constantTimeEqual(left, right) {
42
- if (left.byteLength !== right.byteLength) return false
43
- let different = 0
44
- for (let i = 0; i < left.byteLength; i += 1) different |= left[i] ^ right[i]
45
- return different === 0
46
- }
47
-
48
- export class NoiseIkSession {
49
- constructor(options) {
50
- const localPrivate = requireKey(options.localPrivateKey, 'local private key')
51
- const localPublic = requireKey(options.localPublicKey, 'local public key')
52
- this.expectedRemoteStatic = requireKey(options.remotePublicKey, 'remote public key')
53
- const initiator = options.role === 'initiator'
54
- this.handshake = new NqHandshake(noiseIk(), {
55
- prologue: Uint8Array.from(options.prologue),
56
- initiator,
57
- s: { secretKey: localPrivate, publicKey: localPublic },
58
- ...(initiator ? { rs: Uint8Array.from(this.expectedRemoteStatic) } : {}),
59
- cipher: chachaPoly,
60
- hash: sha256H,
61
- rng: options.random ?? defaultRandom,
62
- })
63
- if (this.handshake.getName() !== NOISE_IK_PROTOCOL) {
64
- throw new NoiseSessionError('NOISE_SUITE_MISMATCH', 'The Noise provider selected an unexpected cipher suite.')
65
- }
66
- this.transport = undefined
67
- this.destroyed = false
68
- }
69
-
70
- get protocol() { return NOISE_IK_PROTOCOL }
71
- get complete() { return this.transport !== undefined }
72
-
73
- writeHandshake(payload = new Uint8Array()) {
74
- this.assertHandshake(false)
75
- const output = new Uint8Array(payload.byteLength + this.handshake.getNextMessageOverhead())
76
- const length = this.handshake.writeMessage(payload, output)
77
- this.finishIfReady()
78
- return output.slice(0, length)
79
- }
80
-
81
- readHandshake(message) {
82
- this.assertHandshake(true)
83
- const output = new Uint8Array(message.byteLength)
84
- const length = this.handshake.readMessage(message, output)
85
- this.verifyRemoteStatic()
86
- this.finishIfReady()
87
- return output.slice(0, length)
88
- }
89
-
90
- encrypt(plaintext) {
91
- this.assertLive()
92
- if (!this.transport) throw new NoiseSessionError('NOISE_NOT_READY', 'The Noise handshake is not complete.')
93
- return this.transport.sendVec(plaintext)
94
- }
95
-
96
- decrypt(ciphertext) {
97
- this.assertLive()
98
- if (!this.transport) throw new NoiseSessionError('NOISE_NOT_READY', 'The Noise handshake is not complete.')
99
- return this.transport.receiveVec(ciphertext)
100
- }
101
-
102
- sendingCounter() { return this.transport ? this.transport.sendingNonce() : 0n }
103
- receivingCounter() { return this.transport ? this.transport.receivingNonce() : 0n }
104
-
105
- destroy() {
106
- this.destroyed = true
107
- this.expectedRemoteStatic.fill(0)
108
- this.transport = undefined
109
- }
110
-
111
- finishIfReady() {
112
- if (!this.handshake.isFinished()) return
113
- this.verifyRemoteStatic()
114
- this.transport = this.handshake.finalize()
115
- }
116
-
117
- verifyRemoteStatic() {
118
- const actual = this.handshake.getRemoteStatic()
119
- if (actual === undefined || !constantTimeEqual(actual, this.expectedRemoteStatic)) {
120
- this.destroy()
121
- throw new NoiseSessionError('PEER_IDENTITY_MISMATCH', 'The Noise peer static key does not match local trust.')
122
- }
123
- }
124
-
125
- assertHandshake(reading) {
126
- this.assertLive()
127
- if (this.complete) throw new NoiseSessionError('NOISE_ALREADY_READY', 'The Noise handshake is already complete.')
128
- if (this.handshake.isWriteTurn() === reading) {
129
- throw new NoiseSessionError('NOISE_HANDSHAKE_ORDER', 'The Noise handshake message arrived out of order.')
130
- }
131
- }
132
-
133
- assertLive() {
134
- if (this.destroyed) throw new NoiseSessionError('NOISE_DESTROYED', 'The Noise session is closed.')
135
- }
136
- }
137
-
138
- /** 便捷构造:prologue 由 remote-protocol.js 生成,两端必须一致。 */
139
- export function createNoiseSession({ role, localPrivateKey, localPublicKey, remotePublicKey, prologue, random }) {
140
- return new NoiseIkSession({ role, localPrivateKey, localPublicKey, remotePublicKey, prologue, random })
141
- }
1
+ /**
2
+ * Noise_IK_25519_ChaChaPoly_SHA256 会话封装。
3
+ *
4
+ * 只保留 v1 固定套件;在握手完成前强制校验远端静态公钥(identity pinning),
5
+ * 不匹配即 `PEER_IDENTITY_MISMATCH` fail closed 并销毁会话。
6
+ *
7
+ * 实现要点:随机数默认走 WebCrypto `getRandomValues`(Node 22 与小程序
8
+ * 都可 shim);base64url 解码用 Buffer,
9
+ * B2 小程序移植时替换 base64url 编码函数即可。
10
+ *
11
+ * 本机实测:initiator msg1=96B、responder msg2=48B,
12
+ * 双向 transport 加解密往返成功。
13
+ */
14
+
15
+ import { NqHandshake, noiseIk, chachaPoly, sha256H } from '@lukeburns/clatterjs'
16
+
17
+ export const NOISE_IK_PROTOCOL = 'Noise_IK_25519_ChaChaPoly_SHA256'
18
+
19
+ const defaultRandom = length => {
20
+ const out = new Uint8Array(length)
21
+ globalThis.crypto.getRandomValues(out)
22
+ return out
23
+ }
24
+
25
+ const fromBase64Url = value => Uint8Array.from(Buffer.from(String(value), 'base64url'))
26
+
27
+ export class NoiseSessionError extends Error {
28
+ constructor(code, message) {
29
+ super(message)
30
+ this.name = 'NoiseSessionError'
31
+ this.code = code
32
+ }
33
+ }
34
+
35
+ function requireKey(value, label) {
36
+ const key = fromBase64Url(value)
37
+ if (key.byteLength !== 32) throw new NoiseSessionError('INVALID_KEY', `${label} must be a 32-byte X25519 key.`)
38
+ return key
39
+ }
40
+
41
+ function constantTimeEqual(left, right) {
42
+ if (left.byteLength !== right.byteLength) return false
43
+ let different = 0
44
+ for (let i = 0; i < left.byteLength; i += 1) different |= left[i] ^ right[i]
45
+ return different === 0
46
+ }
47
+
48
+ export class NoiseIkSession {
49
+ constructor(options) {
50
+ const localPrivate = requireKey(options.localPrivateKey, 'local private key')
51
+ const localPublic = requireKey(options.localPublicKey, 'local public key')
52
+ this.expectedRemoteStatic = requireKey(options.remotePublicKey, 'remote public key')
53
+ const initiator = options.role === 'initiator'
54
+ this.handshake = new NqHandshake(noiseIk(), {
55
+ prologue: Uint8Array.from(options.prologue),
56
+ initiator,
57
+ s: { secretKey: localPrivate, publicKey: localPublic },
58
+ ...(initiator ? { rs: Uint8Array.from(this.expectedRemoteStatic) } : {}),
59
+ cipher: chachaPoly,
60
+ hash: sha256H,
61
+ rng: options.random ?? defaultRandom,
62
+ })
63
+ if (this.handshake.getName() !== NOISE_IK_PROTOCOL) {
64
+ throw new NoiseSessionError('NOISE_SUITE_MISMATCH', 'The Noise provider selected an unexpected cipher suite.')
65
+ }
66
+ this.transport = undefined
67
+ this.destroyed = false
68
+ }
69
+
70
+ get protocol() { return NOISE_IK_PROTOCOL }
71
+ get complete() { return this.transport !== undefined }
72
+
73
+ writeHandshake(payload = new Uint8Array()) {
74
+ this.assertHandshake(false)
75
+ const output = new Uint8Array(payload.byteLength + this.handshake.getNextMessageOverhead())
76
+ const length = this.handshake.writeMessage(payload, output)
77
+ this.finishIfReady()
78
+ return output.slice(0, length)
79
+ }
80
+
81
+ readHandshake(message) {
82
+ this.assertHandshake(true)
83
+ const output = new Uint8Array(message.byteLength)
84
+ const length = this.handshake.readMessage(message, output)
85
+ this.verifyRemoteStatic()
86
+ this.finishIfReady()
87
+ return output.slice(0, length)
88
+ }
89
+
90
+ encrypt(plaintext) {
91
+ this.assertLive()
92
+ if (!this.transport) throw new NoiseSessionError('NOISE_NOT_READY', 'The Noise handshake is not complete.')
93
+ return this.transport.sendVec(plaintext)
94
+ }
95
+
96
+ decrypt(ciphertext) {
97
+ this.assertLive()
98
+ if (!this.transport) throw new NoiseSessionError('NOISE_NOT_READY', 'The Noise handshake is not complete.')
99
+ return this.transport.receiveVec(ciphertext)
100
+ }
101
+
102
+ sendingCounter() { return this.transport ? this.transport.sendingNonce() : 0n }
103
+ receivingCounter() { return this.transport ? this.transport.receivingNonce() : 0n }
104
+
105
+ destroy() {
106
+ this.destroyed = true
107
+ this.expectedRemoteStatic.fill(0)
108
+ this.transport = undefined
109
+ }
110
+
111
+ finishIfReady() {
112
+ if (!this.handshake.isFinished()) return
113
+ this.verifyRemoteStatic()
114
+ this.transport = this.handshake.finalize()
115
+ }
116
+
117
+ verifyRemoteStatic() {
118
+ const actual = this.handshake.getRemoteStatic()
119
+ if (actual === undefined || !constantTimeEqual(actual, this.expectedRemoteStatic)) {
120
+ this.destroy()
121
+ throw new NoiseSessionError('PEER_IDENTITY_MISMATCH', 'The Noise peer static key does not match local trust.')
122
+ }
123
+ }
124
+
125
+ assertHandshake(reading) {
126
+ this.assertLive()
127
+ if (this.complete) throw new NoiseSessionError('NOISE_ALREADY_READY', 'The Noise handshake is already complete.')
128
+ if (this.handshake.isWriteTurn() === reading) {
129
+ throw new NoiseSessionError('NOISE_HANDSHAKE_ORDER', 'The Noise handshake message arrived out of order.')
130
+ }
131
+ }
132
+
133
+ assertLive() {
134
+ if (this.destroyed) throw new NoiseSessionError('NOISE_DESTROYED', 'The Noise session is closed.')
135
+ }
136
+ }
137
+
138
+ /** 便捷构造:prologue 由 remote-protocol.js 生成,两端必须一致。 */
139
+ export function createNoiseSession({ role, localPrivateKey, localPublicKey, remotePublicKey, prologue, random }) {
140
+ return new NoiseIkSession({ role, localPrivateKey, localPublicKey, remotePublicKey, prologue, random })
141
+ }