one-model-router 0.0.10 → 0.0.11
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 +21 -21
- package/package.json +1 -1
- package/src/admin.js +941 -941
- package/src/balances.js +61 -61
- package/src/boot.js +117 -117
- package/src/channels/buddy.js +2031 -2031
- package/src/channels/cline.js +753 -753
- package/src/channels/codearts.js +2051 -2051
- package/src/channels/comate.js +830 -830
- package/src/channels/doubaowork.js +1784 -1784
- package/src/channels/freebuff.js +1316 -1316
- package/src/channels/gemini.js +1721 -1721
- package/src/channels/index.js +270 -270
- package/src/channels/joycode.js +936 -936
- package/src/channels/kimi.js +572 -572
- package/src/channels/lobsterai.js +1226 -1226
- package/src/channels/loomy.js +1032 -1032
- package/src/channels/miaoshou.js +1396 -1396
- package/src/channels/mimo.js +474 -474
- package/src/channels/minimax.js +1451 -1451
- package/src/channels/qoder-wasm.js +434 -434
- package/src/channels/qoder.js +1619 -1619
- package/src/channels/raccoon.js +1842 -1842
- package/src/channels/tabbit.js +1457 -1457
- package/src/channels/trae.js +1405 -1405
- package/src/channels/zcode-global.js +35 -35
- package/src/channels/zcode.js +2085 -2085
- package/src/checkin.js +496 -496
- package/src/credits.js +464 -464
- package/src/crypto.js +132 -132
- package/src/free-models.js +683 -683
- package/src/gateway.js +596 -578
- package/src/health.js +86 -86
- package/src/model-key.js +35 -35
- package/src/paths.js +96 -96
- package/src/probe.js +318 -318
- package/src/providers/builtin.js +626 -626
- package/src/providers/index.js +483 -457
- package/src/providers/kilo.js +111 -111
- package/src/providers/last-good.js +69 -69
- package/src/providers/modelsdev.js +242 -242
- package/src/providers/openai-compat.js +312 -312
- package/src/providers/opencode/bun-fetch.js +226 -226
- package/src/providers/opencode/lane.js +186 -186
- package/src/providers/opencode/o2a/LICENSE.dsh-our-free-model +21 -21
- package/src/providers/opencode/o2a/asset-source.js +43 -43
- package/src/providers/opencode/o2a/assets/opencode_prompt_v2.txt +96 -96
- package/src/providers/opencode/o2a/assets/opencode_tools.json +327 -327
- package/src/providers/opencode/o2a/entry.js +17 -17
- package/src/providers/opencode/o2a/gateway-body.js +42 -42
- package/src/providers/opencode/o2a/headers.js +133 -133
- package/src/providers/opencode/o2a/identity.js +148 -148
- package/src/providers/opencode/o2a/official-prompt.js +191 -191
- package/src/providers/opencode/o2a/official-tools.js +110 -110
- package/src/providers/opencode/o2a/tool-renames.js +217 -217
- package/src/providers/opencode/o2a/toolshape.js +418 -418
- package/src/providers/opencode/o2a/version.js +37 -37
- package/src/providers/opencode/upstream.js +403 -403
- package/src/providers/opencode/wire.js +496 -496
- package/src/providers/opencode.js +652 -652
- package/src/router.js +629 -629
- package/src/server.js +33 -33
- package/src/store.js +467 -467
- package/src/sync/index.js +1529 -1529
- package/src/sync/login-preload.cjs +52 -52
- package/src/sync/noise.js +141 -141
- package/src/sync/relay-http.js +176 -176
- package/src/sync/remote-host.js +818 -818
- package/src/sync/remote-http.js +112 -112
- package/src/sync/remote-login.js +657 -657
- package/src/sync/remote-pairing.js +204 -204
- package/src/sync/remote-protocol.js +321 -321
- package/src/sync/snapshot.js +211 -211
- package/src/util.js +334 -334
- package/web/app.js +3972 -3972
- package/web/index.html +32 -32
- package/web/style.css +971 -971
package/src/sync/remote-http.js
CHANGED
|
@@ -1,112 +1,112 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DSH Remote 控制面 HTTP 客户端(注册 / 续期 / 撤销 / 设备目录)。
|
|
3
|
-
*
|
|
4
|
-
* 端点契约来自 P0 公共版实测:
|
|
5
|
-
* POST /api/v1/devices/register 站点 Bearer,注册任意设备
|
|
6
|
-
* POST /api/v1/devices/register-owned-role 设备 Bearer,注册反角色设备
|
|
7
|
-
* POST /api/v1/auth/refresh body {deviceId, refreshToken},无需 Bearer
|
|
8
|
-
* DELETE /api/v1/devices/self 设备 Bearer,撤销自身
|
|
9
|
-
* GET /api/v1/devices Client 设备 Bearer,列同账号 Host
|
|
10
|
-
* GET /api/v1/me 设备 Bearer
|
|
11
|
-
*
|
|
12
|
-
* 本机实测:Node 22 原生 fetch 可直连 dsh.r2049.cn(无需 https-proxy-agent),
|
|
13
|
-
* 因此不引入代理依赖;relayUrl / apiOrigin 均可配置以便换中继。
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { DEFAULT_API_ORIGIN, PROTOCOL_VERSION, CLIENT_VERSION } from './remote-protocol.js'
|
|
17
|
-
|
|
18
|
-
function apiError(status, code, message, body, retryable) {
|
|
19
|
-
const e = new Error(message)
|
|
20
|
-
e.name = 'RemoteApiError'
|
|
21
|
-
e.status = status
|
|
22
|
-
e.code = code
|
|
23
|
-
// 公共 Server 的错误体带 `retryable`:false 表示这类失败重试也不会变好
|
|
24
|
-
// (典型:`refresh token replay window elapsed`,凭据已永久作废)。
|
|
25
|
-
if (retryable !== undefined) e.retryable = retryable === true
|
|
26
|
-
e.body = body
|
|
27
|
-
return e
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** 严格 device descriptor:公共 Server 对 device 对象也 strict,字段不能多。 */
|
|
31
|
-
export function makeDeviceDescriptor({ deviceId, role, identityKey, name, platform, clientVersion = CLIENT_VERSION }) {
|
|
32
|
-
const descriptor = {
|
|
33
|
-
deviceId: String(deviceId),
|
|
34
|
-
name: String(name).slice(0, 128),
|
|
35
|
-
role,
|
|
36
|
-
platform: String(platform),
|
|
37
|
-
identityKey: String(identityKey),
|
|
38
|
-
clientVersion: String(clientVersion).slice(0, 64),
|
|
39
|
-
}
|
|
40
|
-
if (role !== 'host' && role !== 'client') throw new Error(`invalid device role: ${role}`)
|
|
41
|
-
return descriptor
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function createRemoteApi({ origin = DEFAULT_API_ORIGIN, fetchImpl = globalThis.fetch } = {}) {
|
|
45
|
-
const base = String(origin).replace(/\/+$/, '')
|
|
46
|
-
|
|
47
|
-
async function request(path, { method = 'GET', token = '', body } = {}) {
|
|
48
|
-
const headers = { Accept: 'application/json' }
|
|
49
|
-
if (body !== undefined) headers['Content-Type'] = 'application/json'
|
|
50
|
-
if (token !== '') headers.Authorization = `Bearer ${token}`
|
|
51
|
-
let res
|
|
52
|
-
try {
|
|
53
|
-
res = await fetchImpl(`${base}${path}`, {
|
|
54
|
-
method,
|
|
55
|
-
headers,
|
|
56
|
-
body: body === undefined ? undefined : JSON.stringify(body),
|
|
57
|
-
signal: AbortSignal.timeout(15_000),
|
|
58
|
-
})
|
|
59
|
-
} catch (error) {
|
|
60
|
-
throw apiError(0, 'NETWORK_ERROR', `中继请求失败:${error?.message ?? error}`, null)
|
|
61
|
-
}
|
|
62
|
-
let data = null
|
|
63
|
-
try { data = await res.json() } catch { /* 非 JSON 响应 */ }
|
|
64
|
-
if (!res.ok) {
|
|
65
|
-
const err = data?.error ?? {}
|
|
66
|
-
throw apiError(res.status, String(err.code ?? 'HTTP_ERROR'), String(err.message ?? `HTTP ${res.status}`), data, err.retryable)
|
|
67
|
-
}
|
|
68
|
-
return data
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
/** 首次配置:用站点账号 token 注册 Host;注册完站点 token 即弃。 */
|
|
73
|
-
registerDevice(siteToken, device) {
|
|
74
|
-
return request('/api/v1/devices/register', {
|
|
75
|
-
method: 'POST', token: siteToken, body: { v: PROTOCOL_VERSION, device },
|
|
76
|
-
})
|
|
77
|
-
},
|
|
78
|
-
/** 配对:用 Host 设备 token 注册一台 Client,返回设备级 token pair。 */
|
|
79
|
-
registerOwnedRole(hostAccessToken, device) {
|
|
80
|
-
return request('/api/v1/devices/register-owned-role', {
|
|
81
|
-
method: 'POST', token: hostAccessToken, body: { v: PROTOCOL_VERSION, device },
|
|
82
|
-
})
|
|
83
|
-
},
|
|
84
|
-
/** 设备凭据续期(无 Bearer,凭 deviceId + refreshToken)。 */
|
|
85
|
-
refreshDevice(deviceId, refreshToken) {
|
|
86
|
-
return request('/api/v1/auth/refresh', {
|
|
87
|
-
method: 'POST', body: { deviceId, refreshToken },
|
|
88
|
-
})
|
|
89
|
-
},
|
|
90
|
-
revokeDevice(accessToken) {
|
|
91
|
-
return request('/api/v1/devices/self', { method: 'DELETE', token: accessToken })
|
|
92
|
-
},
|
|
93
|
-
listDevices(clientAccessToken) {
|
|
94
|
-
return request('/api/v1/devices', { token: clientAccessToken })
|
|
95
|
-
},
|
|
96
|
-
me(deviceAccessToken) {
|
|
97
|
-
return request('/api/v1/me', { token: deviceAccessToken })
|
|
98
|
-
},
|
|
99
|
-
get origin() { return base },
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/** 从 token pair 里挑出长期凭据(兼容两种返回形状)。 */
|
|
104
|
-
export function normalizeTokenPair(pair) {
|
|
105
|
-
const p = pair?.data ?? pair?.result ?? pair ?? {}
|
|
106
|
-
return {
|
|
107
|
-
accessToken: String(p.accessToken ?? ''),
|
|
108
|
-
refreshToken: String(p.refreshToken ?? ''),
|
|
109
|
-
accessTokenExpiresAt: Number(p.accessTokenExpiresAt ?? 0) || 0,
|
|
110
|
-
refreshTokenExpiresAt: Number(p.refreshTokenExpiresAt ?? 0) || 0,
|
|
111
|
-
}
|
|
112
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* DSH Remote 控制面 HTTP 客户端(注册 / 续期 / 撤销 / 设备目录)。
|
|
3
|
+
*
|
|
4
|
+
* 端点契约来自 P0 公共版实测:
|
|
5
|
+
* POST /api/v1/devices/register 站点 Bearer,注册任意设备
|
|
6
|
+
* POST /api/v1/devices/register-owned-role 设备 Bearer,注册反角色设备
|
|
7
|
+
* POST /api/v1/auth/refresh body {deviceId, refreshToken},无需 Bearer
|
|
8
|
+
* DELETE /api/v1/devices/self 设备 Bearer,撤销自身
|
|
9
|
+
* GET /api/v1/devices Client 设备 Bearer,列同账号 Host
|
|
10
|
+
* GET /api/v1/me 设备 Bearer
|
|
11
|
+
*
|
|
12
|
+
* 本机实测:Node 22 原生 fetch 可直连 dsh.r2049.cn(无需 https-proxy-agent),
|
|
13
|
+
* 因此不引入代理依赖;relayUrl / apiOrigin 均可配置以便换中继。
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { DEFAULT_API_ORIGIN, PROTOCOL_VERSION, CLIENT_VERSION } from './remote-protocol.js'
|
|
17
|
+
|
|
18
|
+
function apiError(status, code, message, body, retryable) {
|
|
19
|
+
const e = new Error(message)
|
|
20
|
+
e.name = 'RemoteApiError'
|
|
21
|
+
e.status = status
|
|
22
|
+
e.code = code
|
|
23
|
+
// 公共 Server 的错误体带 `retryable`:false 表示这类失败重试也不会变好
|
|
24
|
+
// (典型:`refresh token replay window elapsed`,凭据已永久作废)。
|
|
25
|
+
if (retryable !== undefined) e.retryable = retryable === true
|
|
26
|
+
e.body = body
|
|
27
|
+
return e
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** 严格 device descriptor:公共 Server 对 device 对象也 strict,字段不能多。 */
|
|
31
|
+
export function makeDeviceDescriptor({ deviceId, role, identityKey, name, platform, clientVersion = CLIENT_VERSION }) {
|
|
32
|
+
const descriptor = {
|
|
33
|
+
deviceId: String(deviceId),
|
|
34
|
+
name: String(name).slice(0, 128),
|
|
35
|
+
role,
|
|
36
|
+
platform: String(platform),
|
|
37
|
+
identityKey: String(identityKey),
|
|
38
|
+
clientVersion: String(clientVersion).slice(0, 64),
|
|
39
|
+
}
|
|
40
|
+
if (role !== 'host' && role !== 'client') throw new Error(`invalid device role: ${role}`)
|
|
41
|
+
return descriptor
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function createRemoteApi({ origin = DEFAULT_API_ORIGIN, fetchImpl = globalThis.fetch } = {}) {
|
|
45
|
+
const base = String(origin).replace(/\/+$/, '')
|
|
46
|
+
|
|
47
|
+
async function request(path, { method = 'GET', token = '', body } = {}) {
|
|
48
|
+
const headers = { Accept: 'application/json' }
|
|
49
|
+
if (body !== undefined) headers['Content-Type'] = 'application/json'
|
|
50
|
+
if (token !== '') headers.Authorization = `Bearer ${token}`
|
|
51
|
+
let res
|
|
52
|
+
try {
|
|
53
|
+
res = await fetchImpl(`${base}${path}`, {
|
|
54
|
+
method,
|
|
55
|
+
headers,
|
|
56
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
57
|
+
signal: AbortSignal.timeout(15_000),
|
|
58
|
+
})
|
|
59
|
+
} catch (error) {
|
|
60
|
+
throw apiError(0, 'NETWORK_ERROR', `中继请求失败:${error?.message ?? error}`, null)
|
|
61
|
+
}
|
|
62
|
+
let data = null
|
|
63
|
+
try { data = await res.json() } catch { /* 非 JSON 响应 */ }
|
|
64
|
+
if (!res.ok) {
|
|
65
|
+
const err = data?.error ?? {}
|
|
66
|
+
throw apiError(res.status, String(err.code ?? 'HTTP_ERROR'), String(err.message ?? `HTTP ${res.status}`), data, err.retryable)
|
|
67
|
+
}
|
|
68
|
+
return data
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
/** 首次配置:用站点账号 token 注册 Host;注册完站点 token 即弃。 */
|
|
73
|
+
registerDevice(siteToken, device) {
|
|
74
|
+
return request('/api/v1/devices/register', {
|
|
75
|
+
method: 'POST', token: siteToken, body: { v: PROTOCOL_VERSION, device },
|
|
76
|
+
})
|
|
77
|
+
},
|
|
78
|
+
/** 配对:用 Host 设备 token 注册一台 Client,返回设备级 token pair。 */
|
|
79
|
+
registerOwnedRole(hostAccessToken, device) {
|
|
80
|
+
return request('/api/v1/devices/register-owned-role', {
|
|
81
|
+
method: 'POST', token: hostAccessToken, body: { v: PROTOCOL_VERSION, device },
|
|
82
|
+
})
|
|
83
|
+
},
|
|
84
|
+
/** 设备凭据续期(无 Bearer,凭 deviceId + refreshToken)。 */
|
|
85
|
+
refreshDevice(deviceId, refreshToken) {
|
|
86
|
+
return request('/api/v1/auth/refresh', {
|
|
87
|
+
method: 'POST', body: { deviceId, refreshToken },
|
|
88
|
+
})
|
|
89
|
+
},
|
|
90
|
+
revokeDevice(accessToken) {
|
|
91
|
+
return request('/api/v1/devices/self', { method: 'DELETE', token: accessToken })
|
|
92
|
+
},
|
|
93
|
+
listDevices(clientAccessToken) {
|
|
94
|
+
return request('/api/v1/devices', { token: clientAccessToken })
|
|
95
|
+
},
|
|
96
|
+
me(deviceAccessToken) {
|
|
97
|
+
return request('/api/v1/me', { token: deviceAccessToken })
|
|
98
|
+
},
|
|
99
|
+
get origin() { return base },
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** 从 token pair 里挑出长期凭据(兼容两种返回形状)。 */
|
|
104
|
+
export function normalizeTokenPair(pair) {
|
|
105
|
+
const p = pair?.data ?? pair?.result ?? pair ?? {}
|
|
106
|
+
return {
|
|
107
|
+
accessToken: String(p.accessToken ?? ''),
|
|
108
|
+
refreshToken: String(p.refreshToken ?? ''),
|
|
109
|
+
accessTokenExpiresAt: Number(p.accessTokenExpiresAt ?? 0) || 0,
|
|
110
|
+
refreshTokenExpiresAt: Number(p.refreshTokenExpiresAt ?? 0) || 0,
|
|
111
|
+
}
|
|
112
|
+
}
|