dsh-model 0.20.0 → 0.20.1

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.
@@ -5,7 +5,7 @@
5
5
  // 3. 用新版本执行一次 repair:重写服务文件、重启引擎与守护进程、同步模型。
6
6
  import { spawn } from 'node:child_process';
7
7
  import { closeSync, openSync } from 'node:fs';
8
- import { chown, realpath } from 'node:fs/promises';
8
+ import { chown, realpath, writeFile } from 'node:fs/promises';
9
9
  import { delimiter, dirname, join } from 'node:path';
10
10
  import { requireRootInVps } from '../context.js';
11
11
  import { DshModelError, isDshModelError } from '../errors.js';
@@ -120,8 +120,12 @@ export async function selfUpdate(ctx, opts = {}) {
120
120
  }
121
121
  /** 管理页请求的日志:更新写在 home 里;卸载会删 home,写在它外面 */
122
122
  export function selfJobLog(ctx, action) {
123
- return action === 'uninstall' ? join(dirname(ctx.paths.home), 'dsh-model-uninstall.log') : join(ctx.paths.home, 'update.log');
123
+ if (action === 'uninstall')
124
+ return join(dirname(ctx.paths.home), 'dsh-model-uninstall.log');
125
+ return join(ctx.paths.home, action === 'repair' ? 'repair.log' : 'update.log');
124
126
  }
127
+ /** admin-run 跑完在日志最后写的一行:页面据此知道结束了、成没成 */
128
+ export const ADMIN_DONE_RE = /^\[dsh-model\] exit (-?\d+)$/m;
125
129
  /** 由 dsh-model-admin.service(root)执行:取出管理页的请求单,只做 update / uninstall */
126
130
  export async function adminRun(ctx) {
127
131
  if (!ctx.isRoot)
@@ -138,7 +142,8 @@ export async function adminRun(ctx) {
138
142
  const out = openSync(log, 'w', 0o600);
139
143
  if (ctx.owner)
140
144
  await chown(log, ctx.owner.uid, ctx.owner.gid).catch(() => { });
141
- const args = req.action === 'update' ? ['update'] : ['uninstall', '--yes', '--remove-plugin', ...(req.keepAuth ? ['--keep-auth'] : [])];
145
+ // repair 就是重跑 setup(幂等,什么缺了补什么;比 repair 命令能修的多)
146
+ const args = req.action === 'update' ? ['update'] : req.action === 'repair' ? ['setup', '--skip-dsh-plugin'] : ['uninstall', '--yes', '--remove-plugin', ...(req.keepAuth ? ['--keep-auth'] : [])];
142
147
  const code = await new Promise((resolve) => {
143
148
  const child = spawn(process.execPath, [join(PKG_ROOT, 'bin', 'dsh-model.js'), ...args, '--lang', req.lang ?? 'zh'], {
144
149
  stdio: ['ignore', out, out],
@@ -149,5 +154,6 @@ export async function adminRun(ctx) {
149
154
  child.on('exit', (c) => resolve(c ?? -1));
150
155
  });
151
156
  closeSync(out);
157
+ await writeFile(log, `\n[dsh-model] exit ${code}\n`, { flag: 'a' }).catch(() => { });
152
158
  return code;
153
159
  }
@@ -57,10 +57,15 @@ export async function uninstall(ctx, opts) {
57
57
  if (all.state.remote && all.state.remote.mode !== 'off')
58
58
  await disableRemote(ctx, all);
59
59
  });
60
- await step('dsh-plugin', async () => {
60
+ // 移除插件只是尽力而为:dsh 的 pnpm 可能因"新版本要等一天"的规则拒绝改动(2026-10-14 实测,连删除也会被拦)。
61
+ // 这一步失败不该让卸载停在半路:服务、配置照样清掉,home 照样删,插件请用户在 dsh 的插件页手动删。
62
+ try {
61
63
  if (await removeDshPlugin(ctx, all, { force: opts.removePlugin }))
62
64
  ok(L('已从 dsh 移除 dsh-model 插件', 'Removed the dsh-model plugin from dsh'));
63
- });
65
+ }
66
+ catch (error) {
67
+ warn(L(`没能自动从 dsh 移除 dsh-model 插件(${error.message}):请在 dsh 的插件页里手动删掉它`, `Could not remove the dsh-model plugin from dsh automatically (${error.message}); remove it on the dsh Plugins page`));
68
+ }
64
69
  await step('workbuddy', async () => {
65
70
  if (await removeWorkbuddyPlugin(ctx, all))
66
71
  ok(L('已移除上一版安装的 WorkBuddy 插件', 'Removed the WorkBuddy plugin installed by a previous version'));
@@ -2,7 +2,7 @@
2
2
  //
3
3
  // 守护进程以 dsh 用户运行,而更新(npm 全局目录、系统服务)和卸载(Caddy、防火墙、系统服务)要 root。
4
4
  // 所以 setup(root)装一个 systemd path 单元:守护进程在 <home>/admin/request 写一张请求单,
5
- // systemd 以 root 运行 `dsh-model admin-run`,它只认三件固定的事:更新到 npm 最新版、卸载、重启 dsh(插件更新后要重启才生效)。别的一律拒绝。
5
+ // systemd 以 root 运行 `dsh-model admin-run`,它只认四件固定的事:更新到 npm 最新版、卸载、重启 dsh(插件更新后要重启才生效)、修复(重跑 setup)。别的一律拒绝。
6
6
  import { chown, mkdir, readFile, rm } from 'node:fs/promises';
7
7
  import { join } from 'node:path';
8
8
  import { run } from '../util/exec.js';
@@ -76,7 +76,7 @@ export async function takeAdminRequest(ctx) {
76
76
  await rm(file, { force: true });
77
77
  try {
78
78
  const r = JSON.parse(raw);
79
- if (r.action !== 'update' && r.action !== 'uninstall' && r.action !== 'restart-dsh')
79
+ if (r.action !== 'update' && r.action !== 'uninstall' && r.action !== 'restart-dsh' && r.action !== 'repair')
80
80
  return null;
81
81
  return { action: r.action, keepAuth: r.keepAuth === true, lang: r.lang === 'en' ? 'en' : 'zh' };
82
82
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-model",
3
- "version": "0.20.0",
3
+ "version": "0.20.1",
4
4
  "description": "Many model sources behind one authenticated OpenAI-compatible endpoint for DeepSeek Harness (dsh) and your tools: WorkBuddy, OpenCode Zen and your CLI subscriptions (Codex, Kimi…), with a management page inside dsh. 多家模型汇成一个 OpenAI 兼容地址,dsh 和其他软件都能直接用。",
5
5
  "keywords": [
6
6
  "dsh-plugin",
package/plugin/client.js CHANGED
@@ -614,7 +614,8 @@ window.__ModuleLoader__.load({
614
614
  }
615
615
  }
616
616
  const cmds = notInstalled ? ['npm install -g dsh-model', 'dsh-model setup'] : ['dsh-model repair']
617
- const vpsCmds = notInstalled ? ['sudo npm install -g dsh-model', 'sudo dsh-model setup'] : ['sudo dsh-model repair']
617
+ // setup 什么缺了补什么(卸载到一半、服务被删了也能救回来),比 repair 稳
618
+ const vpsCmds = notInstalled ? ['sudo npm install -g dsh-model', 'sudo dsh-model setup'] : ['sudo dsh-model setup']
618
619
  const cmdBlock = (list) => h('div', { style: { ...S.card, padding: '8px 12px', marginTop: 8 } }, list.map((c) => h('div', { key: c, style: { ...S.line, minHeight: 30 } }, h('code', { style: { ...S.mono, ...S.grow } }, c), h(CopyButton, { get: c }))))
619
620
  return h('div', { style: { color: C.text, maxWidth: 820 } },
620
621
  h('div', { style: S.section },
@@ -623,7 +624,7 @@ window.__ModuleLoader__.load({
623
624
  ? L('这个页面只是管理界面;模型由 dsh-model 在本机运行的服务提供(统一端点、WorkBuddy bridge、登录与用量)。装好后,来源、key 和模型都在这里管理。', 'This page is only the control panel; models are served by dsh-model\'s local service (the unified endpoint, WorkBuddy bridge, sign-ins and usage). Once it is set up, manage sources, keys and models here.')
624
625
  : L('可能是电脑重启后服务没起来,或者刚升级。修复会按记录重新注册并启动服务。', 'The service may not have started after a reboot, or was just upgraded. Repair re-registers and starts it from the saved records.')),
625
626
  res?.vps ? h('div', null,
626
- h('p', { style: { ...S.note, color: C.text } }, L('这是 dsh-vps 服务器:安装要 root 权限,请在服务器终端里执行:', 'This is a dsh-vps server: setup needs root, so run this in a server terminal:')),
627
+ h('p', { style: { ...S.note, color: C.text } }, L('这是 dsh-vps 服务器:这一步要 root 权限,而这台机器上还没有 dsh-model 的管理员服务。请在服务器终端里执行一次(之后页面上的按钮就能用):', 'This is a dsh-vps server: this needs root, and dsh-model\'s admin service is not on this machine yet. Run this once in a server terminal (the page buttons work afterwards):')),
627
628
  cmdBlock(vpsCmds),
628
629
  h('p', { style: { ...S.note, marginTop: 8 } }, L('装好后刷新本页。', 'Reload this page when done.'))) : h('div', null,
629
630
  h('div', { style: S.line },
package/plugin/index.js CHANGED
@@ -238,7 +238,19 @@ export function apply(ctx) {
238
238
  } catch {
239
239
  return json(res, 400, { error: { code: 'invalid_json', message: 'invalid JSON' } })
240
240
  }
241
- if (await exists(VPS_ROOT)) return json(res, 200, { vps: true })
241
+ if (await exists(VPS_ROOT)) {
242
+ // dsh-vps:安装要 root。管理员小服务还在(setup 装的)就交给它跑 setup,页面照样看进度;不在就只能给命令
243
+ if (!(await exists(ADMIN_PATH_UNIT))) return json(res, 200, { vps: true })
244
+ const log = join(home(), 'repair.log')
245
+ if (body.poll) {
246
+ const text = await readFile(log, 'utf8').catch(() => '')
247
+ const m = /^\[dsh-model\] exit (-?\d+)$/m.exec(text)
248
+ return json(res, 200, { running: !m, output: text.replace(/\n?\[dsh-model\] exit -?\d+\n?$/, '').replace(/\x1b\[[0-9;]*m/g, ''), code: m ? Number(m[1]) : null, action: 'repair' })
249
+ }
250
+ await writeFile(log, '', { mode: 0o600 }).catch(() => {})
251
+ await writeFile(join(home(), 'admin', 'request'), JSON.stringify({ action: 'repair', lang: body.lang === 'en' ? 'en' : 'zh' }), { mode: 0o600 })
252
+ return json(res, 200, { running: true, output: '', code: null, action: 'repair' })
253
+ }
242
254
  // { poll: true }:只取进度;否则开始(已经在跑就接着看同一个)
243
255
  if (body.poll) return json(res, 200, job ? { running: job.running, output: job.output, code: job.code, action: job.action } : { running: false, output: '', code: null })
244
256
  const action = body.action === 'repair' ? 'repair' : 'setup'