one-model-router 0.0.13 → 0.0.15
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/README.md +11 -6
- package/bin/omr.js +96 -14
- package/package.json +2 -1
- package/src/admin.js +200 -31
- package/src/boot.js +14 -3
- package/src/bun-bootstrap.js +115 -0
- package/src/channels/index.js +8 -4
- package/src/channels/lingxi-browser-login.js +231 -0
- package/src/channels/lingxi-cred.js +448 -0
- package/src/channels/lingxi.js +1481 -0
- package/src/channels/loomy.js +140 -31
- package/src/default-group.js +142 -0
- package/src/free-models.js +9 -0
- package/src/install-forms.js +238 -0
- package/src/probe.js +55 -25
- package/src/providers/opencode/bun-fetch.js +6 -26
- package/src/sync/index.js +150 -19
- package/src/sync/qr-mobile.js +141 -0
- package/src/sync/remote-login.js +28 -130
- package/src/sync/snapshot.js +2 -0
- package/src/update.js +134 -59
- package/web/app.js +494 -81
- package/web/index.html +2 -2
- package/web/style.css +26 -6
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 本机「安装形态」探测:桌面端(安装包 / .app / AppImage)与 npm 全局包。
|
|
3
|
+
*
|
|
4
|
+
* 升级策略的前提:装了哪种形态就升级哪种形态——只装 npm 包就只升 npm 包,
|
|
5
|
+
* 只装桌面端就只升桌面端,两者都装则两者都升。探测只依赖 Node 内置模块
|
|
6
|
+
* (不 import electron),因此 npm 服务端、Electron 主进程、CLI 三处共用。
|
|
7
|
+
*
|
|
8
|
+
* 判定口径:
|
|
9
|
+
* - runningAs:当前进程自己是以哪种形态在跑(desktop / npm / source),
|
|
10
|
+
* 源码开发态(有 .git 或 electron/ 目录)既不算桌面安装也不算 npm 安装。
|
|
11
|
+
* - 当前形态必然「已安装」,不再额外探测(避免 npm prefix 漂移、asar 路径判断失误)。
|
|
12
|
+
* - 另一形态按各自的落盘位置探测;npm 全局根目录用 `npm root -g` 取,取不到退回常见前缀。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { spawn, execFileSync } from 'node:child_process'
|
|
16
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
17
|
+
import { dirname, join, resolve } from 'node:path'
|
|
18
|
+
import { homedir, tmpdir } from 'node:os'
|
|
19
|
+
import { fileURLToPath } from 'node:url'
|
|
20
|
+
|
|
21
|
+
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..')
|
|
22
|
+
const APP_NAME = 'OneModelRouter'
|
|
23
|
+
|
|
24
|
+
function readSelfPkg() {
|
|
25
|
+
try { return JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8')) } catch { return {} }
|
|
26
|
+
}
|
|
27
|
+
const SELF_PKG = readSelfPkg()
|
|
28
|
+
|
|
29
|
+
/** npm 包名(`npm i -g <PKG_NAME>@latest`)。 */
|
|
30
|
+
export const PKG_NAME = String(SELF_PKG.name || 'one-model-router')
|
|
31
|
+
|
|
32
|
+
/** 探测结果缓存 TTL:升级动作会改写磁盘状态,需要时可 refresh 强制重探。 */
|
|
33
|
+
const DETECT_TTL_MS = 10 * 60_000
|
|
34
|
+
/** `npm root -g` 的超时:npm 冷启动慢,超过这个时间当作拿不到全局根目录。 */
|
|
35
|
+
const NPM_ROOT_TIMEOUT_MS = 8000
|
|
36
|
+
let detectCache = null
|
|
37
|
+
|
|
38
|
+
const isElectron = () => Boolean(process.versions?.electron)
|
|
39
|
+
/** Electron 开发态直跑(打包态 process.defaultApp 恒为 undefined)。 */
|
|
40
|
+
const isElectronDev = () => isElectron() && process.defaultApp === true
|
|
41
|
+
const isSourceCheckout = () => existsSync(join(ROOT, '.git')) || existsSync(join(ROOT, 'electron', 'main.js'))
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 当前进程的运行形态。
|
|
45
|
+
* @returns {'desktop'|'npm'|'source'}
|
|
46
|
+
*/
|
|
47
|
+
export function runningAs() {
|
|
48
|
+
if (isElectron() && !isElectronDev()) return 'desktop'
|
|
49
|
+
if (isElectronDev() || isSourceCheckout()) return 'source'
|
|
50
|
+
return 'npm'
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** 桌面端在本机的可能落盘路径(按优先级),命中即为已安装。 */
|
|
54
|
+
function desktopCandidates() {
|
|
55
|
+
const home = homedir()
|
|
56
|
+
if (process.platform === 'win32') {
|
|
57
|
+
const local = process.env.LOCALAPPDATA || join(home, 'AppData', 'Local')
|
|
58
|
+
const pf = process.env.ProgramFiles || 'C:\\Program Files'
|
|
59
|
+
const pf86 = process.env['ProgramFiles(x86)'] || 'C:\\Program Files (x86)'
|
|
60
|
+
return [
|
|
61
|
+
join(local, 'Programs', APP_NAME, `${APP_NAME}.exe`),
|
|
62
|
+
join(pf, APP_NAME, `${APP_NAME}.exe`),
|
|
63
|
+
join(pf86, APP_NAME, `${APP_NAME}.exe`),
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
if (process.platform === 'darwin') {
|
|
67
|
+
return [
|
|
68
|
+
`/Applications/${APP_NAME}.app`,
|
|
69
|
+
join(home, 'Applications', `${APP_NAME}.app`),
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
// deb 落在 /opt/<productName>/,AppImage 由安装脚本放到 ~/.local/bin,两者都探
|
|
73
|
+
return [
|
|
74
|
+
join('/opt', APP_NAME, APP_NAME),
|
|
75
|
+
join('/opt', APP_NAME, PKG_NAME),
|
|
76
|
+
join(home, '.local', 'bin', APP_NAME),
|
|
77
|
+
join('/usr', 'bin', APP_NAME.toLowerCase()),
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Electron 打包态下正在运行的应用本体路径(可覆盖标准目录探测不到的自定义安装位置)。 */
|
|
82
|
+
function runningDesktopPath() {
|
|
83
|
+
if (!isElectron() || isElectronDev()) return ''
|
|
84
|
+
const exe = process.execPath || ''
|
|
85
|
+
if (!exe) return ''
|
|
86
|
+
// 便携版与安装版都算:exe 存在即视为已装桌面端
|
|
87
|
+
return existsSync(exe) ? exe : ''
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 读取 Windows exe 的版本号(FileVersion)。
|
|
92
|
+
* 非 Windows 或读不到返回空串——上层按「版本未知 → 需要升级」处理。
|
|
93
|
+
* 用 PowerShell 读版本信息是 Windows 上唯一免依赖的可靠方式(只在本机装了桌面端时才调用)。
|
|
94
|
+
*/
|
|
95
|
+
function exeVersion(file) {
|
|
96
|
+
if (process.platform !== 'win32') return ''
|
|
97
|
+
try {
|
|
98
|
+
const script = `(Get-Item -LiteralPath '${file.replace(/'/g, "''")}').VersionInfo.FileVersion`
|
|
99
|
+
const out = execFileSync('powershell', ['-NoProfile', '-NonInteractive', '-Command', script], {
|
|
100
|
+
encoding: 'utf8',
|
|
101
|
+
timeout: 8000,
|
|
102
|
+
windowsHide: true,
|
|
103
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
104
|
+
})
|
|
105
|
+
// FileVersion 形如 "0.0.13.0":取前三段作为语义化版本
|
|
106
|
+
const parts = String(out || '').trim().split(/\s+/)[0].split('.').filter(p => /^\d+$/.test(p))
|
|
107
|
+
if (!parts.length) return ''
|
|
108
|
+
return parts.slice(0, 3).join('.')
|
|
109
|
+
} catch { return '' }
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** `npm root -g`:拿不到(无 npm / 超时 / 报错)返回空串。 */
|
|
113
|
+
function npmGlobalRoot() {
|
|
114
|
+
return new Promise(resolveP => {
|
|
115
|
+
let child
|
|
116
|
+
try {
|
|
117
|
+
child = spawn('npm', ['root', '-g'], { stdio: ['ignore', 'pipe', 'ignore'], shell: process.platform === 'win32', windowsHide: true })
|
|
118
|
+
} catch { resolveP(''); return }
|
|
119
|
+
let out = ''
|
|
120
|
+
const timer = setTimeout(() => { try { child.kill('SIGKILL') } catch { /* 已结束 */ }; resolveP('') }, NPM_ROOT_TIMEOUT_MS)
|
|
121
|
+
child.stdout.on('data', chunk => { out = (out + chunk.toString()).slice(-4000) })
|
|
122
|
+
child.on('error', () => { clearTimeout(timer); resolveP('') })
|
|
123
|
+
child.on('close', code => {
|
|
124
|
+
clearTimeout(timer)
|
|
125
|
+
const root = code === 0 ? out.split(/\r?\n/).map(s => s.trim()).filter(Boolean).pop() || '' : ''
|
|
126
|
+
resolveP(root)
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** npm 全局根目录的候选(`npm root -g` 不可用时的兜底探测)。 */
|
|
132
|
+
function npmRootCandidates() {
|
|
133
|
+
const home = homedir()
|
|
134
|
+
const list = []
|
|
135
|
+
if (process.platform === 'win32') {
|
|
136
|
+
if (process.env.APPDATA) list.push(join(process.env.APPDATA, 'npm', 'node_modules'))
|
|
137
|
+
list.push(join(home, 'AppData', 'Roaming', 'npm', 'node_modules'))
|
|
138
|
+
list.push('C:\\Program Files\\nodejs\\node_modules')
|
|
139
|
+
} else {
|
|
140
|
+
list.push(join(home, '.npm-global', 'lib', 'node_modules'))
|
|
141
|
+
list.push('/usr/local/lib/node_modules')
|
|
142
|
+
list.push('/usr/lib/node_modules')
|
|
143
|
+
if (process.env.PREFIX) list.push(join(process.env.PREFIX, 'lib', 'node_modules'))
|
|
144
|
+
}
|
|
145
|
+
return list
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** 读取某个包目录里的版本号(读不到返回空串)。 */
|
|
149
|
+
function pkgVersionAt(dir) {
|
|
150
|
+
try { return String(JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'))?.version || '') } catch { return '' }
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* 探测 npm 全局包形态。
|
|
155
|
+
* @param {boolean} forceSelf 当前进程正以该 npm 包在跑时,即便探测不到全局目录也按已安装处理
|
|
156
|
+
*/
|
|
157
|
+
async function detectNpmForm(forceSelf) {
|
|
158
|
+
const roots = []
|
|
159
|
+
const push = r => { if (r && !roots.includes(r)) roots.push(r) }
|
|
160
|
+
push(await npmGlobalRoot())
|
|
161
|
+
npmRootCandidates().forEach(push)
|
|
162
|
+
for (const root of roots) {
|
|
163
|
+
const dir = join(root, PKG_NAME)
|
|
164
|
+
const version = pkgVersionAt(dir)
|
|
165
|
+
if (!version) continue
|
|
166
|
+
return { installed: true, version, prefix: root, self: forceSelf || dir === ROOT || dirname(dir) === ROOT }
|
|
167
|
+
}
|
|
168
|
+
// 以 npm 包形态在跑(如 `omr start`)却没探到全局目录:prefix 漂移等边缘情况,仍按已安装处理
|
|
169
|
+
if (forceSelf) return { installed: true, version: String(SELF_PKG.version || ''), prefix: dirname(ROOT), self: true }
|
|
170
|
+
return { installed: false, version: '', prefix: '', self: false }
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* 探测本机已安装的形态。
|
|
175
|
+
* @param {{ refresh?: boolean }} [options] refresh=true 忽略缓存重探(升级动作之后调用)
|
|
176
|
+
* @returns {Promise<{ desktop:object, npm:object, runningAs:string, installed:string[] }>}
|
|
177
|
+
*/
|
|
178
|
+
export async function detectForms({ refresh = false } = {}) {
|
|
179
|
+
if (!refresh && detectCache && Date.now() - detectCache.at < DETECT_TTL_MS) return detectCache.value
|
|
180
|
+
|
|
181
|
+
const mode = runningAs()
|
|
182
|
+
const hit = desktopCandidates().find(p => existsSync(p))
|
|
183
|
+
// 桌面形态:正在跑的就是桌面端 → 必已安装(自定义安装目录也能覆盖);否则按落盘位置探测
|
|
184
|
+
const desktop = mode === 'desktop'
|
|
185
|
+
? { installed: true, path: runningDesktopPath() || hit || '', version: String(SELF_PKG.version || '') }
|
|
186
|
+
: { installed: !!hit, path: hit || '', version: hit ? exeVersion(hit) : '' }
|
|
187
|
+
// npm 形态:以 npm 包在跑时按已安装处理,其余情况探测全局目录
|
|
188
|
+
const npm = mode === 'npm'
|
|
189
|
+
? { installed: true, version: String(SELF_PKG.version || ''), prefix: dirname(ROOT), self: true }
|
|
190
|
+
: await detectNpmForm(false)
|
|
191
|
+
|
|
192
|
+
const installed = [desktop.installed && 'desktop', npm.installed && 'npm'].filter(Boolean)
|
|
193
|
+
const value = { desktop, npm, runningAs: mode, installed }
|
|
194
|
+
detectCache = { at: Date.now(), value }
|
|
195
|
+
return value
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** 形态一句话描述(管理面板文案):如「桌面端 + npm 包」。 */
|
|
199
|
+
export function describeForms(forms) {
|
|
200
|
+
const parts = []
|
|
201
|
+
if (forms?.desktop?.installed) parts.push('桌面端')
|
|
202
|
+
if (forms?.npm?.installed) parts.push('npm 包')
|
|
203
|
+
return parts.join(' + ')
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* 升级 npm 全局包到最新版。
|
|
208
|
+
* @param {{ log?: (...args:any[])=>void, inherit?: boolean }} [options] inherit=true 直接把 npm 输出接到当前终端(CLI 用)
|
|
209
|
+
*/
|
|
210
|
+
export function upgradeNpmForm({ log = () => {}, inherit = false } = {}) {
|
|
211
|
+
const cmd = `npm i -g ${PKG_NAME}@latest`
|
|
212
|
+
log(`执行 npm 升级:${cmd}`)
|
|
213
|
+
return new Promise((resolveP, reject) => {
|
|
214
|
+
let child
|
|
215
|
+
try {
|
|
216
|
+
child = spawn('npm', ['i', '-g', `${PKG_NAME}@latest`], {
|
|
217
|
+
stdio: inherit ? 'inherit' : ['ignore', 'pipe', 'pipe'],
|
|
218
|
+
shell: true,
|
|
219
|
+
windowsHide: true,
|
|
220
|
+
})
|
|
221
|
+
} catch (error) { reject(error); return }
|
|
222
|
+
let tail = ''
|
|
223
|
+
const drain = stream => { stream?.on('data', chunk => { tail = (tail + chunk.toString()).slice(-4000) }) }
|
|
224
|
+
if (!inherit) { drain(child.stdout); drain(child.stderr) }
|
|
225
|
+
const timer = setTimeout(() => {
|
|
226
|
+
try { child.kill('SIGKILL') } catch { /* 已结束 */ }
|
|
227
|
+
reject(new Error('npm 升级超时'))
|
|
228
|
+
}, 10 * 60_000)
|
|
229
|
+
child.on('error', error => { clearTimeout(timer); reject(error) })
|
|
230
|
+
child.on('close', code => {
|
|
231
|
+
clearTimeout(timer)
|
|
232
|
+
if (code === 0) { resolveP(); return }
|
|
233
|
+
const detail = tail.trim().split(/\r?\n/).filter(Boolean).slice(-3).join(' / ')
|
|
234
|
+
reject(new Error(`npm 退出码 ${code}${detail ? ':' + detail : ''}`))
|
|
235
|
+
})
|
|
236
|
+
})
|
|
237
|
+
}
|
|
238
|
+
|
package/src/probe.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* - 全轮 rate_limit → 指数退避(30→60→120 分钟封顶),退避期跳过普通轮
|
|
6
6
|
* - 保守判据:探测失败只记录状态,不进请求冷却(网关抖动/限流 ≠ 模型死亡);
|
|
7
7
|
* 探测成功 → 清除该模型现有冷却,尽快回到路由链头
|
|
8
|
-
* - omr/
|
|
8
|
+
* - omr/ 虚拟组不探测(没有自己的端点);「测试组内模型」是把组展开成成员逐个探
|
|
9
9
|
* - 停用渠道不探测:目录缓存可能滞后(启动预热快照 / SWR 旧目录),探测前按
|
|
10
10
|
* 实时启用状态过滤(免密渠道看 settings、转发渠道看 channels.json、自定义提供商看 enabled)
|
|
11
11
|
* 单轮结果(延迟/状态)在内存;lastProbeAt 持久化到 settings.json,
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { completeOnModel, buildCatalog } from './providers/index.js'
|
|
16
|
-
import { loadSettings, saveSettings, emitRuntimeEvent, DATA_DIR, loadChannels, loadProviders } from './store.js'
|
|
16
|
+
import { loadSettings, saveSettings, emitRuntimeEvent, DATA_DIR, loadChannels, loadProviders, loadGroups } from './store.js'
|
|
17
17
|
import { slugify } from './util.js'
|
|
18
18
|
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'
|
|
19
19
|
import { join } from 'node:path'
|
|
@@ -59,8 +59,8 @@ export function primeProbeState() {
|
|
|
59
59
|
let timer = null
|
|
60
60
|
/** 全局探测轮进行中(「探测全部」/周期轮)。单渠道测试不占用此标记,避免影响 UI 的探测提示。 */
|
|
61
61
|
let running = false
|
|
62
|
-
/**
|
|
63
|
-
const
|
|
62
|
+
/** 正在批量测试的范围键集合(渠道 / 模型组):各范围互不阻塞,可并行执行。 */
|
|
63
|
+
const scopeRunning = new Map()
|
|
64
64
|
let throttleStreak = 0
|
|
65
65
|
let backoffUntil = 0
|
|
66
66
|
let log = () => {}
|
|
@@ -122,7 +122,7 @@ async function probeOne(row) {
|
|
|
122
122
|
publish(row.id, { state: 'available', detail: '', latencyMs, probedAt: Date.now() })
|
|
123
123
|
// 探测通过 → 清请求冷却(模型恢复后尽快回到链头)
|
|
124
124
|
health.markSuccess(row.id)
|
|
125
|
-
return { ok: true, kind: '' }
|
|
125
|
+
return { ok: true, kind: '', detail: '' }
|
|
126
126
|
} catch (error) {
|
|
127
127
|
const kind = error?.kind ?? 'unknown'
|
|
128
128
|
const message = String(error?.message ?? error).slice(0, 300)
|
|
@@ -138,7 +138,7 @@ async function probeOne(row) {
|
|
|
138
138
|
})
|
|
139
139
|
// 判死 → 长冷却殿后(组路由自动跳过);其余失败不进冷却,防探针误伤
|
|
140
140
|
if (dead) health.markFailure(row.id, 30 * 60_000)
|
|
141
|
-
return { ok: false, kind }
|
|
141
|
+
return { ok: false, kind, detail: message }
|
|
142
142
|
} finally {
|
|
143
143
|
probing.delete(row.id)
|
|
144
144
|
clearTimeout(timer)
|
|
@@ -181,29 +181,48 @@ function collectEnabledKeys(settings) {
|
|
|
181
181
|
return enabled
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
+
/**
|
|
185
|
+
* 模型组「测试组内模型」的目标集合:组内参与轮询的候选(跳过组内停用项与嵌套组引用,
|
|
186
|
+
* 组不允许套娃,omr/ 成员本身没有可直连的端点)。组不存在返回 null,交由调用方报错。
|
|
187
|
+
*/
|
|
188
|
+
function groupProbeTargets(gid) {
|
|
189
|
+
const g = (loadGroups().groups ?? []).find(x => x.id === gid)
|
|
190
|
+
if (!g) return null
|
|
191
|
+
const disabled = new Set(Array.isArray(g.disabled) ? g.disabled : [])
|
|
192
|
+
return new Set((Array.isArray(g.models) ? g.models : [])
|
|
193
|
+
.filter(id => typeof id === 'string' && id !== '' && !disabled.has(id) && !id.startsWith('omr/')))
|
|
194
|
+
}
|
|
195
|
+
|
|
184
196
|
/**
|
|
185
197
|
* 跑一轮探测。force=true 穿透退避与开关(UI 手动按钮)。
|
|
186
|
-
* channel
|
|
187
|
-
* -
|
|
198
|
+
* 定向轮(channel / group 二选一非空,UI 的「测试本渠道」「测试组内模型」):
|
|
199
|
+
* - 不同范围可并行跑,互不阻塞(同一范围单飞);
|
|
188
200
|
* - 不写 running / 不写 lastProbeAt / 不牵动退避,因此不影响「探测全部」旁的全局探测提示。
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
* 返回 { skipped?, reason?, total, ok, throttled }
|
|
201
|
+
* 全局轮与定向轮之间仍互斥(全局轮本来就会覆盖所有目标)。
|
|
202
|
+
* 未启用的渠道一律不探测(手动测试对停用渠道同样返回无可探测模型)。
|
|
203
|
+
* 返回 { skipped?, reason?, total, ok, throttled, channel, group, results };
|
|
204
|
+
* results 为逐模型明细 [{ id, ok, detail }],供 UI 汇总失败项。
|
|
192
205
|
*/
|
|
193
|
-
export async function runProbeRound({ force = false, channel = '' } = {}) {
|
|
194
|
-
const
|
|
195
|
-
|
|
206
|
+
export async function runProbeRound({ force = false, channel = '', group = '' } = {}) {
|
|
207
|
+
const scoped = channel !== '' || group !== ''
|
|
208
|
+
const scopeKey = group !== '' ? `group:${group}` : channel !== '' ? `channel:${channel}` : ''
|
|
209
|
+
const scopeName = group !== '' ? `模型组 omr/${group}` : channel !== '' ? `渠道「${channel}」` : ''
|
|
210
|
+
if (scoped) {
|
|
196
211
|
if (running) return { skipped: true, reason: '全局探测进行中' }
|
|
197
|
-
if (
|
|
198
|
-
} else if (running ||
|
|
212
|
+
if (scopeRunning.has(scopeKey)) return { skipped: true, reason: `${scopeName} 测试进行中` }
|
|
213
|
+
} else if (running || scopeRunning.size > 0) {
|
|
199
214
|
return { skipped: true, reason: '上一轮仍在进行' }
|
|
200
215
|
}
|
|
201
216
|
if (!force && Date.now() < backoffUntil) return { skipped: true, reason: '限流退避中' }
|
|
202
217
|
const settings = loadSettings()
|
|
203
218
|
if (settings.probe?.enabled === false && !force) return { skipped: true, reason: '探测已关闭' }
|
|
204
219
|
|
|
205
|
-
|
|
206
|
-
|
|
220
|
+
// 组轮先解析成员:组不存在 / 组内没有可探测的候选时直接返回,不出网也不占车道
|
|
221
|
+
const memberIds = group !== '' ? groupProbeTargets(group) : null
|
|
222
|
+
if (group !== '' && memberIds === null) return { skipped: true, reason: `模型组 omr/${group} 不存在` }
|
|
223
|
+
|
|
224
|
+
if (scoped) {
|
|
225
|
+
scopeRunning.set(scopeKey, scopeName)
|
|
207
226
|
} else {
|
|
208
227
|
running = true
|
|
209
228
|
emitRuntimeEvent('probe-meta', probeMeta())
|
|
@@ -216,18 +235,22 @@ export async function runProbeRound({ force = false, channel = '' } = {}) {
|
|
|
216
235
|
const targets = catalog.filter(r =>
|
|
217
236
|
!r.offline
|
|
218
237
|
&& (channel === '' || r.channel === channel)
|
|
238
|
+
&& (memberIds === null || memberIds.has(r.id))
|
|
219
239
|
&& enabledKeys.has(r.channelId ?? r.provider))
|
|
220
240
|
if (targets.length === 0) {
|
|
221
|
-
|
|
241
|
+
const emptyReason = group !== ''
|
|
242
|
+
? `模型组 omr/${group} 没有可探测的候选(组内为空 / 全部停用 / 所属渠道未启用)`
|
|
243
|
+
: channel !== '' ? `渠道「${channel}」没有可探测的模型` : '目录为空'
|
|
244
|
+
return { skipped: true, reason: emptyReason }
|
|
222
245
|
}
|
|
223
|
-
log(`探测开始:${targets.length} 个模型(并发 ${CONCURRENCY})${
|
|
246
|
+
log(`探测开始:${targets.length} 个模型(并发 ${CONCURRENCY})${scopeName === '' ? '' : ` · ${scopeName}`}`)
|
|
224
247
|
|
|
225
248
|
const results = await pool(targets, CONCURRENCY, probeOne)
|
|
226
249
|
const ok = results.filter(r => r.ok).length
|
|
227
250
|
const throttled = results.filter(r => !r.ok && r.kind === 'rate_limit').length
|
|
228
251
|
|
|
229
|
-
// 全轮限流 → 指数退避(30→60→120
|
|
230
|
-
if (
|
|
252
|
+
// 全轮限流 → 指数退避(30→60→120 分钟封顶);定向轮不牵动全局退避与「上次探测」时间
|
|
253
|
+
if (!scoped) {
|
|
231
254
|
if (results.length > 0 && throttled === results.length) {
|
|
232
255
|
throttleStreak += 1
|
|
233
256
|
const minutes = Math.min(30 * 2 ** (throttleStreak - 1), 120)
|
|
@@ -242,10 +265,17 @@ export async function runProbeRound({ force = false, channel = '' } = {}) {
|
|
|
242
265
|
}
|
|
243
266
|
log(`探测完成:${ok}/${results.length} 可用`)
|
|
244
267
|
saveProbeCache()
|
|
245
|
-
return {
|
|
268
|
+
return {
|
|
269
|
+
total: results.length,
|
|
270
|
+
ok,
|
|
271
|
+
throttled,
|
|
272
|
+
channel,
|
|
273
|
+
group,
|
|
274
|
+
results: targets.map((r, i) => ({ id: r.id, ok: results[i].ok, detail: results[i].detail ?? '' })),
|
|
275
|
+
}
|
|
246
276
|
} finally {
|
|
247
|
-
if (
|
|
248
|
-
|
|
277
|
+
if (scoped) {
|
|
278
|
+
scopeRunning.delete(scopeKey)
|
|
249
279
|
} else {
|
|
250
280
|
running = false
|
|
251
281
|
emitRuntimeEvent('probe-meta', probeMeta())
|
|
@@ -30,13 +30,16 @@
|
|
|
30
30
|
* @module src/providers/opencode/bun-fetch
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
33
|
+
import { existsSync, mkdirSync, mkdtempSync, writeFileSync } from 'node:fs'
|
|
34
|
+
import { tmpdir } from 'node:os'
|
|
35
|
+
import { join } from 'node:path'
|
|
36
36
|
import { spawn } from 'node:child_process'
|
|
37
37
|
import { PassThrough, Readable } from 'node:stream'
|
|
38
38
|
import { DATA_DIR } from '../../store.js'
|
|
39
39
|
|
|
40
|
+
// 检测口径统一在 src/bun-bootstrap.js(升级链路与运行时共用同一份候选路径)。
|
|
41
|
+
export { findBunExecutable } from '../../bun-bootstrap.js'
|
|
42
|
+
|
|
40
43
|
const WORKER_SOURCE = `import { Readable } from 'node:stream';
|
|
41
44
|
import { pipeline } from 'node:stream/promises';
|
|
42
45
|
try {
|
|
@@ -103,29 +106,6 @@ export function bunWorkerPath() {
|
|
|
103
106
|
return workerPath
|
|
104
107
|
}
|
|
105
108
|
|
|
106
|
-
/** 定位原生 Bun 可执行文件(永不执行 .cmd/.ps1 壳)。不安装、不下载。 */
|
|
107
|
-
export function findBunExecutable() {
|
|
108
|
-
const name = process.platform === 'win32' ? 'bun.exe' : 'bun'
|
|
109
|
-
const candidates = [
|
|
110
|
-
process.env.OMR_OPENCODE_BUN,
|
|
111
|
-
process.env.OUR_FREE_MODEL_BUN,
|
|
112
|
-
process.env.BUN_INSTALL && join(process.env.BUN_INSTALL, 'bin', name),
|
|
113
|
-
join(homedir(), '.bun', 'bin', name),
|
|
114
|
-
...(process.env.PATH || '').split(delimiter).filter(Boolean).map(p => join(p.replace(/^"|"$/g, ''), name)),
|
|
115
|
-
process.env.APPDATA && join(process.env.APPDATA, 'npm', 'node_modules', 'bun', 'bin', name),
|
|
116
|
-
]
|
|
117
|
-
for (const candidate of candidates.filter(Boolean)) {
|
|
118
|
-
try {
|
|
119
|
-
const path = resolve(candidate)
|
|
120
|
-
if (process.platform === 'win32' && !path.toLowerCase().endsWith('.exe')) continue
|
|
121
|
-
if (!statSync(path).isFile()) continue
|
|
122
|
-
accessSync(path, constants.X_OK)
|
|
123
|
-
return path
|
|
124
|
-
} catch { /* 试下一个候选 */ }
|
|
125
|
-
}
|
|
126
|
-
return undefined
|
|
127
|
-
}
|
|
128
|
-
|
|
129
109
|
/**
|
|
130
110
|
* 经 Bun worker 发一次请求。`init.body` 只接受 string/Uint8Array;
|
|
131
111
|
* `init.signal` 控制整个响应生命周期;重定向默认 error;无重试。
|
package/src/sync/index.js
CHANGED
|
@@ -31,6 +31,7 @@ import { claimAllProviders, claimChannel, collectAllBalances, collectChannelBala
|
|
|
31
31
|
import { recordChannelClaim } from '../checkin.js'
|
|
32
32
|
import { runProbeRound } from '../probe.js'
|
|
33
33
|
import { pruneRotation, completeOnGroup } from '../router.js'
|
|
34
|
+
import { isDefaultGroup, builtinGroupMembers } from '../default-group.js'
|
|
34
35
|
import * as health from '../health.js'
|
|
35
36
|
import { slugify, utc8Stamp } from '../util.js'
|
|
36
37
|
import { BUILTIN_PROVIDERS, BUILTIN_IDS } from '../providers/builtin.js'
|
|
@@ -39,7 +40,8 @@ import { createCloudRelay } from './relay-http.js'
|
|
|
39
40
|
import { createRemoteHost } from './remote-host.js'
|
|
40
41
|
import { createRemoteApi } from './remote-http.js'
|
|
41
42
|
import { createPairing } from './remote-pairing.js'
|
|
42
|
-
import { startRelayLogin, relayLoginState, cancelRelayLogin, isSiteToken } from './remote-login.js'
|
|
43
|
+
import { startRelayLogin, relayLoginState, cancelRelayLogin, isSiteToken, pickToken } from './remote-login.js'
|
|
44
|
+
import { ensureQrMobile } from './qr-mobile.js'
|
|
43
45
|
import {
|
|
44
46
|
DEFAULT_RELAY_URL, DEFAULT_API_ORIGIN,
|
|
45
47
|
generateIdentityKeyPair, identityFingerprint, isDeviceId, newDeviceId,
|
|
@@ -469,33 +471,126 @@ function restartSync() {
|
|
|
469
471
|
startClient()
|
|
470
472
|
}
|
|
471
473
|
|
|
474
|
+
/**
|
|
475
|
+
* 站点令牌到手后的统一收尾:密封落盘 + 启用 remote + 等 Host 真正注册成功。
|
|
476
|
+
* 三条入口共用:Electron 弹窗自动捕获 / Web 端粘贴令牌 / Web 端邮箱密码直登。
|
|
477
|
+
*/
|
|
478
|
+
async function completeSiteLogin(siteToken) {
|
|
479
|
+
const result = await updateSyncSettings({ enabled: true, transport: 'remote', siteToken })
|
|
480
|
+
if (!result.ok) throw new Error(result.message || '保存站点令牌失败')
|
|
481
|
+
// 关键:不能只报「已保存」。必须用该令牌等 Host 真正注册成功(accessToken 落盘),
|
|
482
|
+
// 否则抓到形状合法但不是站点令牌的值时,页面显示成功、实际 Host 永远没起来。
|
|
483
|
+
const deadline = Date.now() + 25_000
|
|
484
|
+
while (Date.now() < deadline) {
|
|
485
|
+
const s = syncState()
|
|
486
|
+
if (s.hasAccessToken) return
|
|
487
|
+
if (s.lastError) throw new Error(`Host 注册失败:${s.lastError}`)
|
|
488
|
+
await new Promise(resolve => setTimeout(resolve, 500))
|
|
489
|
+
}
|
|
490
|
+
throw new Error('站点令牌未能完成 Host 注册(25 秒无响应),请确认登录的是 DSH Remote 站点后重试')
|
|
491
|
+
}
|
|
492
|
+
|
|
472
493
|
/** 点击登录:打开站点登录窗口,捕获到的站点令牌自动密封落盘并启用 remote 通道。 */
|
|
473
494
|
export function startRelayBrowserLogin() {
|
|
474
495
|
const settings = loadSettings()
|
|
475
496
|
const apiOrigin = settings.sync?.apiOrigin || DEFAULT_API_ORIGIN
|
|
476
|
-
return startRelayLogin({
|
|
477
|
-
apiOrigin,
|
|
478
|
-
onToken: async siteToken => {
|
|
479
|
-
const result = await updateSyncSettings({ enabled: true, transport: 'remote', siteToken })
|
|
480
|
-
if (!result.ok) throw new Error(result.message || '保存站点令牌失败')
|
|
481
|
-
// 关键:不能只报「已保存」。必须用该令牌等 Host 真正注册成功(accessToken 落盘),
|
|
482
|
-
// 否则抓到形状合法但不是站点令牌的值时,页面显示成功、实际 Host 永远没起来。
|
|
483
|
-
const deadline = Date.now() + 25_000
|
|
484
|
-
while (Date.now() < deadline) {
|
|
485
|
-
const s = syncState()
|
|
486
|
-
if (s.hasAccessToken) return
|
|
487
|
-
if (s.lastError) throw new Error(`Host 注册失败:${s.lastError}`)
|
|
488
|
-
await new Promise(resolve => setTimeout(resolve, 500))
|
|
489
|
-
}
|
|
490
|
-
throw new Error('站点令牌未能完成 Host 注册(25 秒无响应),请确认窗口中登录的是 DSH Remote 站点后重试')
|
|
491
|
-
},
|
|
492
|
-
log,
|
|
493
|
-
})
|
|
497
|
+
return startRelayLogin({ apiOrigin, onToken: completeSiteLogin, log })
|
|
494
498
|
}
|
|
495
499
|
|
|
496
500
|
export const relayBrowserLoginState = relayLoginState
|
|
497
501
|
export const cancelRelayBrowserLogin = cancelRelayLogin
|
|
498
502
|
|
|
503
|
+
/** 站点自托管扫码登录支持的渠道(来自 /api/v1/auth/oauth/providers 实测)。 */
|
|
504
|
+
const QR_LOGIN_PROVIDERS = new Set(['zhihu', 'github', 'google', 'qq'])
|
|
505
|
+
/** 扫码会话缓存:qrId → {qrId, scanUrl, status, expiresAt}。手机落地页只读 status,令牌只留在 PC 侧。 */
|
|
506
|
+
const qrSessions = new Map()
|
|
507
|
+
|
|
508
|
+
async function qrSiteFetch(apiOrigin, path, init = {}) {
|
|
509
|
+
const res = await fetch(`${apiOrigin}${path}`, { ...init, signal: AbortSignal.timeout(15_000) })
|
|
510
|
+
let data = null
|
|
511
|
+
try { data = await res.json() } catch { /* 非 JSON */ }
|
|
512
|
+
if (!res.ok) {
|
|
513
|
+
const err = new Error(data?.error?.message || `站点接口返回 HTTP ${res.status}`)
|
|
514
|
+
err.code = data?.error?.code
|
|
515
|
+
throw err
|
|
516
|
+
}
|
|
517
|
+
return data ?? {}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* 站点托管扫码登录 · 起步:POST /api/v1/auth/oauth/qr/start?provider=<p>
|
|
522
|
+
* → {qrId, scanUrl, expiresIn}。二维码内容两种模式:
|
|
523
|
+
* - direct(默认):站点 scanUrl(公网 https,任何手机扫码都可达;代价是授权
|
|
524
|
+
* 完成后手机会落到站点页面,手动关闭即可);
|
|
525
|
+
* - mobile:本机局域网「手机落地页」(中性无品牌、授权后显示登录成功、不跳
|
|
526
|
+
* 站点页;但要求手机能访问本机 http://IP:端口 —— QQ/微信内置浏览器常拦截
|
|
527
|
+
* 此类地址且需同一网络,实测脆弱,仅作可选优化)。
|
|
528
|
+
*/
|
|
529
|
+
export async function startRelayQrLogin(provider, mode = 'direct') {
|
|
530
|
+
const p = String(provider ?? '').trim().toLowerCase()
|
|
531
|
+
if (!QR_LOGIN_PROVIDERS.has(p)) return { ok: false, message: '不支持的扫码渠道' }
|
|
532
|
+
const apiOrigin = String(loadSettings().sync?.apiOrigin || DEFAULT_API_ORIGIN).replace(/\/+$/, '')
|
|
533
|
+
try {
|
|
534
|
+
const data = await qrSiteFetch(apiOrigin, `/api/v1/auth/oauth/qr/start?provider=${p}`, {
|
|
535
|
+
method: 'POST',
|
|
536
|
+
headers: { 'content-type': 'application/json' },
|
|
537
|
+
body: '{}',
|
|
538
|
+
})
|
|
539
|
+
if (!data?.qrId || !data?.scanUrl) return { ok: false, message: '扫码登录起步失败(站点未返回 qrId/scanUrl)' }
|
|
540
|
+
const qrId = String(data.qrId)
|
|
541
|
+
const expiresIn = Number(data.expiresIn) || 600
|
|
542
|
+
// 清理过期会话(含 2 分钟宽限),再登记本次
|
|
543
|
+
for (const [key, entry] of qrSessions) {
|
|
544
|
+
if (Date.now() > entry.expiresAt + 120_000) qrSessions.delete(key)
|
|
545
|
+
}
|
|
546
|
+
qrSessions.set(qrId, { qrId, scanUrl: String(data.scanUrl), status: 'pending', expiresAt: Date.now() + expiresIn * 1000 })
|
|
547
|
+
// 手机落地页服务(仅 mobile 模式懒启动;失败回退直连 scanUrl)
|
|
548
|
+
let mobileBase = ''
|
|
549
|
+
if (mode === 'mobile') {
|
|
550
|
+
try {
|
|
551
|
+
mobileBase = await ensureQrMobile({
|
|
552
|
+
getScanUrl: id => qrSessions.get(id)?.scanUrl ?? '',
|
|
553
|
+
getStatus: id => (Date.now() > (qrSessions.get(id)?.expiresAt ?? 0) ? 'expired' : qrSessions.get(id)?.status ?? 'unknown'),
|
|
554
|
+
})
|
|
555
|
+
} catch (error) { log(`手机扫码落地页服务启动失败(回退直连站点链接):${error?.message ?? error}`) }
|
|
556
|
+
}
|
|
557
|
+
const qrTarget = mobileBase ? `${mobileBase}/qr/${encodeURIComponent(qrId)}` : String(data.scanUrl)
|
|
558
|
+
const qrDataUrl = await QRCode.toDataURL(qrTarget, { margin: 1, width: 480 })
|
|
559
|
+
return { ok: true, provider: p, qrId, expiresIn, qrDataUrl, mobile: mobileBase ? 'local' : 'direct' }
|
|
560
|
+
} catch (error) {
|
|
561
|
+
return { ok: false, message: `无法发起扫码登录:${error?.message ?? error}` }
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* 扫码登录 · 轮询:GET /api/v1/auth/oauth/qr/<qrId>(qrId 直接拼路径)。
|
|
567
|
+
* 实测:正确端点返回 {status:"pending"};`poll?id=` 等 query 变体是不存在的路由,
|
|
568
|
+
* 站点统一回 {status:"expired}",曾导致授权完成后网页侧永远拿不到令牌。
|
|
569
|
+
* 响应里一旦带出令牌(形状兼容 token/accessToken/data 嵌套),立即走与弹窗捕获
|
|
570
|
+
* 完全相同的 completeSiteLogin 收尾;令牌不进任何返回值。
|
|
571
|
+
*/
|
|
572
|
+
export async function pollRelayQrLogin(qrId) {
|
|
573
|
+
const id = String(qrId ?? '').trim()
|
|
574
|
+
if (!id) return { ok: false, message: '缺少 qrId' }
|
|
575
|
+
const apiOrigin = String(loadSettings().sync?.apiOrigin || DEFAULT_API_ORIGIN).replace(/\/+$/, '')
|
|
576
|
+
try {
|
|
577
|
+
const data = await qrSiteFetch(apiOrigin, `/api/v1/auth/oauth/qr/${encodeURIComponent(id)}`)
|
|
578
|
+
const entry = qrSessions.get(id)
|
|
579
|
+
const siteToken = pickToken(data)
|
|
580
|
+
if (siteToken) {
|
|
581
|
+
if (entry) entry.status = 'done'
|
|
582
|
+
await completeSiteLogin(siteToken)
|
|
583
|
+
log('站点扫码登录完成:令牌已保存并完成一次性 Host 注册')
|
|
584
|
+
return { ok: true, status: 'done' }
|
|
585
|
+
}
|
|
586
|
+
const status = String(data?.status ?? 'unknown')
|
|
587
|
+
if (entry && status !== entry.status) entry.status = status
|
|
588
|
+
return { ok: true, status }
|
|
589
|
+
} catch (error) {
|
|
590
|
+
return { ok: false, message: error?.message ?? String(error) }
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
499
594
|
/** 已配对 Client 落盘(凭据字段由 crypto.js 密封);上限 16 台。 */
|
|
500
595
|
function persistBoundClient(record) {
|
|
501
596
|
const settings = loadSettings()
|
|
@@ -946,8 +1041,43 @@ export async function executeCommand(command = {}) {
|
|
|
946
1041
|
const doc = loadGroups()
|
|
947
1042
|
doc.groups ??= []
|
|
948
1043
|
const prev = doc.groups.find(x => x.id === g.id)
|
|
1044
|
+
// 新建 vs 编辑:新建时手机端不传 id(或传空串),id 由名称 slugify 派生
|
|
1045
|
+
const isCreate = g.id === undefined || g.id === null || g.id === ''
|
|
949
1046
|
const id = g.id ?? slugify(name)
|
|
950
1047
|
if (id === '' || id === 'kilo' || id === 'opencode' || id === 'omr') return { ok: false, message: `模型组 ID「${id}」为保留字` }
|
|
1048
|
+
// 内置默认组(omr/default):成员集合由小时扫描维护,手机端只能调序,不能增删。
|
|
1049
|
+
if (isDefaultGroup(id)) {
|
|
1050
|
+
// 新建时撞上保留字:直接拒绝,别把内置组覆盖掉
|
|
1051
|
+
if (isCreate) {
|
|
1052
|
+
return { ok: false, message: `模型组 ID「default」为内置默认组保留字,请换一个名称` }
|
|
1053
|
+
}
|
|
1054
|
+
// 自建的同名组(id=default 但不是内置组)不该被当成内置组覆盖
|
|
1055
|
+
if (prev && prev.builtin !== true) {
|
|
1056
|
+
return { ok: false, message: `模型组 ID「default」为内置默认组保留字,请换一个名称` }
|
|
1057
|
+
}
|
|
1058
|
+
const kept = Array.isArray(prev?.models) ? prev.models : []
|
|
1059
|
+
if (kept.length === 0) return { ok: false, message: `内置模型组 omr/${id} 的成员由系统维护,请稍候扫描完成` }
|
|
1060
|
+
// 成员集合由扫描维护,这里只接受重排(增删会被丢弃,排序由用户决定)
|
|
1061
|
+
const nextModels = builtinGroupMembers(kept, g.models)
|
|
1062
|
+
const rawDisabled = Array.isArray(g.disabled) ? g.disabled : (Array.isArray(prev?.disabled) ? prev.disabled : [])
|
|
1063
|
+
const disabled = [...new Set(rawDisabled.map(v => String(v ?? '').trim()))].filter(v => v !== '')
|
|
1064
|
+
const row = {
|
|
1065
|
+
id,
|
|
1066
|
+
name: name === '' ? (prev?.name ?? id) : name,
|
|
1067
|
+
models: nextModels,
|
|
1068
|
+
strategy: g.strategy === 'round-robin' ? 'round-robin' : (prev?.strategy === 'round-robin' ? 'round-robin' : 'fallback'),
|
|
1069
|
+
stickyLimit: Math.max(1, Math.trunc(Number(g.stickyLimit) || prev?.stickyLimit || 3)),
|
|
1070
|
+
enabled: g.enabled !== undefined ? g.enabled !== false : prev?.enabled !== false,
|
|
1071
|
+
disabled,
|
|
1072
|
+
builtin: true,
|
|
1073
|
+
}
|
|
1074
|
+
doc.groups[doc.groups.indexOf(prev)] = row
|
|
1075
|
+
saveGroups(doc)
|
|
1076
|
+
pruneRotation(doc.groups.map(x => x.id))
|
|
1077
|
+
markDirty('groups')
|
|
1078
|
+
return { ok: true, message: `内置模型组 omr/${id} 已保存(成员由系统维护,${kept.length} 个候选)` }
|
|
1079
|
+
}
|
|
1080
|
+
if (name === '' || models.length === 0) return { ok: false, message: 'name 与至少一个成员模型必填' }
|
|
951
1081
|
const rawDisabled = Array.isArray(g.disabled) ? g.disabled : (Array.isArray(prev?.disabled) ? prev.disabled : [])
|
|
952
1082
|
const disabled = [...new Set(rawDisabled.map(v => String(v ?? '').trim()))].filter(v => models.includes(v))
|
|
953
1083
|
const row = {
|
|
@@ -967,6 +1097,7 @@ export async function executeCommand(command = {}) {
|
|
|
967
1097
|
}
|
|
968
1098
|
case 'group.remove': {
|
|
969
1099
|
const groupId = String(payload.groupId ?? '').trim()
|
|
1100
|
+
if (isDefaultGroup(groupId)) return { ok: false, message: `内置模型组 omr/${groupId} 不可删除` }
|
|
970
1101
|
const doc = loadGroups()
|
|
971
1102
|
const before = doc.groups.length
|
|
972
1103
|
doc.groups = (doc.groups ?? []).filter(x => x.id !== groupId)
|