dsh-plugin-opencode2api 1.2.1 → 1.2.2

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 (3) hide show
  1. package/README.md +10 -4
  2. package/lib/index.js +50 -21
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  一键把 [opencode2api](https://github.com/jasonxu114514/opencode2api) 装进 DSH:自动下载对应平台的程序、生成配置、启动并常驻,并自动把「本地免费 API」注册成 DSH 的模型商(模型列表从网关动态获取)。装好后本机就有一个专属的、兼容 OpenAI 的免费 API;DSH 关闭再打开会自动重启。
4
4
 
5
+ ## 1.2.2 更新
6
+
7
+ - 手机原生面板与桌面设置页对齐:移除「复制接入」「复制后台」,改为「复制地址」「复制 Key」;保留「打开后台」「查看日志」「项目主页」。
8
+ - 「打开后台」在 dshGo 原生面板受平台限制:`link` 只接受 https,本地后台是 `http://127.0.0.1:8081`,因此会自动复制地址并提示粘贴到浏览器;桌面 Web UI 仍可直接打开。
9
+ - 停止/重启在 Windows 之外补充 `ss` / `netstat` 兜底,Linux/macOS/Android 按端口找进程更可靠。
10
+
5
11
  ## 1.2.1 更新
6
12
 
7
13
  - 修复停止/重启:按端口反查并终止进程(Windows `netstat` + `taskkill`,macOS/Linux/Android 用 `lsof`/`fuser`/`/proc`),不再依赖可能丢失的 pid 文件;启动改为健康检查通过才算成功,并自动接管已有健康实例。
@@ -32,8 +38,8 @@ dsh plugin --profile web add dsh-plugin-opencode2api
32
38
  | 方式 | 命令 | 前提 |
33
39
  |---|---|---|
34
40
  | GitHub | `dsh plugin --profile web add github:king-andthe-nice/dsh-plugin-opencode2api` | 能访问 GitHub |
35
- | 本地包 | `dsh plugin --profile web add ./dsh-plugin-opencode2api-1.2.1.tgz` | 有 17 KB 的 tgz |
36
- | 局域网 | `dsh plugin --profile web add http://<手机IP>:8000/dsh-plugin-opencode2api-1.2.1.tgz` | 手机先 `python3 -m http.server 8000` |
41
+ | 本地包 | `dsh plugin --profile web add ./dsh-plugin-opencode2api-1.2.2.tgz` | 有 17 KB 的 tgz |
42
+ | 局域网 | `dsh plugin --profile web add http://<手机IP>:8000/dsh-plugin-opencode2api-1.2.2.tgz` | 手机先 `python3 -m http.server 8000` |
37
43
 
38
44
  装好后引擎会自动下载程序(约 5 MB)、生成配置并在 `0.0.0.0:8080` 启动(本机和局域网都能连)。首次下载失败会每 30 秒重试。
39
45
 
@@ -46,7 +52,7 @@ Windows / macOS / Linux 装好后,打开 DSH Web UI(默认 `http://127.0.0.1
46
52
  桌面端在 **设置 → 本地免费 API** 里操作;手机端在「本地API」面板里操作。面板会显示「模型商:已自动配置」。如果没配上,点面板里的「自动配置」重试;仍然失败时再手动接入:
47
53
 
48
54
  1. 打开「本地免费 API」面板。
49
- 2. 点「复制接入」,得到:
55
+ 2. 点「复制地址」得到本机/局域网地址,点「复制 Key」得到 API Key:
50
56
 
51
57
  ```text
52
58
  本机:http://127.0.0.1:8080/v1
@@ -61,7 +67,7 @@ Windows / macOS / Linux 装好后,打开 DSH Web UI(默认 `http://127.0.0.1
61
67
 
62
68
  - **启动 / 停止 / 重启 / 重装**:重装会重新下载程序。
63
69
  - **仅本机 / 开局域网**:切换监听地址(`127.0.0.1` 或 `0.0.0.0`)。
64
- - **复制地址 / 复制 Key / 复制后台信息 / 打开后台**:桌面设置页与手机面板都提供。
70
+ - **复制地址 / 复制 Key / 打开后台**:桌面设置页与手机面板都提供(手机原生面板的「打开后台」受 https 限制,会自动复制地址)。
65
71
  - **自动配置**:重新把本地 API 注册为模型商「本地免费 API」,并同步最新模型列表。
66
72
  - **运行日志**:桌面设置页可展开查看最后 40 行;手机面板新增「查看日志」,也可看数据目录里的 `opencode2api.log`。
67
73
  - 状态实时显示;进程挂掉会自动拉起。
package/lib/index.js CHANGED
@@ -574,13 +574,25 @@ function alive(pid) {
574
574
  }
575
575
  }
576
576
 
577
- function execLines(command, args) {
577
+ function execLines(command, args, timeout = 3000) {
578
578
  return new Promise((resolve) => {
579
579
  const child = spawn(command, args, { stdio: ['ignore', 'pipe', 'ignore'] })
580
580
  let out = ''
581
+ let done = false
582
+ let timer
583
+ const finish = (value) => {
584
+ if (done) return
585
+ done = true
586
+ clearTimeout(timer)
587
+ resolve(value)
588
+ }
589
+ timer = setTimeout(() => {
590
+ try { child.kill() } catch {}
591
+ finish(out)
592
+ }, timeout)
581
593
  child.stdout?.on('data', (chunk) => { out += chunk })
582
- child.once('error', () => resolve(''))
583
- child.once('close', () => resolve(out))
594
+ child.once('error', () => finish(''))
595
+ child.once('close', () => finish(out))
584
596
  })
585
597
  }
586
598
 
@@ -633,6 +645,22 @@ async function listenerPids(port) {
633
645
  const pid = Number(line.trim())
634
646
  if (pid) found.add(pid)
635
647
  }
648
+ if (!found.size) {
649
+ const ss = await execLines('ss', ['-ltnp'])
650
+ for (const line of ss.split(/\r?\n/)) {
651
+ if (!new RegExp(`:${port}\\b`).test(line)) continue
652
+ for (const match of line.matchAll(/pid=(\d+)/g)) found.add(Number(match[1]))
653
+ }
654
+ }
655
+ if (!found.size) {
656
+ const netstat = await execLines('netstat', ['-ltnp'])
657
+ for (const line of netstat.split(/\r?\n/)) {
658
+ if (!/LISTEN/.test(line) || !new RegExp(`:${port}\\b`).test(line)) continue
659
+ const last = line.trim().split(/\s+/).pop() || ''
660
+ const pid = Number((last.match(/^(\d+)\//) || last.match(/^(\d+)$/) || [])[1])
661
+ if (pid) found.add(pid)
662
+ }
663
+ }
636
664
  if (!found.size) {
637
665
  const fuser = await execLines('fuser', ['-n', 'tcp', String(port)])
638
666
  for (const token of fuser.split(/\s+/)) {
@@ -841,8 +869,8 @@ function registerUi(ctx) {
841
869
  {
842
870
  type: 'actions',
843
871
  items: [
844
- { label: '复制接入', action: 'copyInfo' },
845
- { label: '复制后台', action: 'copyWeb' },
872
+ { label: '复制地址', action: 'copyBase' },
873
+ { label: '复制Key', action: 'copyKey' },
846
874
  { label: '自动配置', action: 'autoConfig' },
847
875
  { label: '重装', action: 'reinstall' },
848
876
  ],
@@ -850,7 +878,7 @@ function registerUi(ctx) {
850
878
  {
851
879
  type: 'actions',
852
880
  items: [
853
- { label: '打开后台', action: 'openWeb', style: 'primary' },
881
+ { label: '打开后台', action: 'openWeb' },
854
882
  { label: '查看日志', action: 'viewLog' },
855
883
  { label: '项目主页', action: 'openHome' },
856
884
  ],
@@ -923,22 +951,19 @@ function registerUi(ctx) {
923
951
  const ok = await start()
924
952
  return { toast: ok ? '已开局域网' : '切换失败' }
925
953
  }),
926
- copyInfo: () => {
927
- const cfg = readConfig()
928
- const key = cfg.server_keys?.[0] || ''
954
+ copyBase: () => {
929
955
  const lan = lanAddress()
930
956
  const lanLine = lan ? `\n局域网:http://${lan}:${API_PORT}/v1` : ''
931
957
  return {
932
- copy: `本机:http://127.0.0.1:${API_PORT}/v1${lanLine}\nAPI Key:${key}\n推荐模型:big-pickle`,
933
- toast: '接入信息已复制',
958
+ copy: `本机:http://127.0.0.1:${API_PORT}/v1${lanLine}`,
959
+ toast: 'API 地址已复制',
934
960
  }
935
961
  },
936
- copyWeb: () => {
962
+ copyKey: () => {
937
963
  const cfg = readConfig()
938
- const password = readPassword() || '(已在后台改过,请用新密码)'
939
964
  return {
940
- copy: `后台:http://127.0.0.1:${WEB_PORT}\n账号:${cfg.webui?.username || 'admin'}\n密码:${password}`,
941
- toast: '后台信息已复制',
965
+ copy: cfg.server_keys?.[0] || '(无 Key)',
966
+ toast: 'API Key 已复制',
942
967
  }
943
968
  },
944
969
  reinstall: () => {
@@ -958,18 +983,22 @@ function registerUi(ctx) {
958
983
  })()
959
984
  return { toast: '后台重装中…' }
960
985
  },
961
- openWeb: () => ({
962
- copy: `http://127.0.0.1:${WEB_PORT}`,
963
- open: `http://127.0.0.1:${WEB_PORT}`,
964
- toast: '后台地址已复制,可粘贴到浏览器打开',
965
- }),
986
+ openWeb: () => {
987
+ const url = `http://127.0.0.1:${WEB_PORT}`
988
+ const effect = { copy: url, toast: '后台地址已复制,请粘贴到浏览器打开' }
989
+ if (/^https:\/\//i.test(url)) {
990
+ effect.link = url
991
+ effect.toast = '正在打开后台'
992
+ }
993
+ return effect
994
+ },
966
995
  viewLog: () => ({
967
996
  copy: tailLog(40) || '(暂无日志)',
968
997
  toast: '日志已复制',
969
998
  }),
970
999
  openHome: () => ({
971
1000
  copy: 'https://github.com/king-andthe-nice/dsh-plugin-opencode2api',
972
- open: 'https://github.com/king-andthe-nice/dsh-plugin-opencode2api',
1001
+ link: 'https://github.com/king-andthe-nice/dsh-plugin-opencode2api',
973
1002
  toast: '项目地址已复制',
974
1003
  }),
975
1004
  autoConfig: () =>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-opencode2api",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Unofficial one-click installer and auto-runner for opencode2api — a local free OpenAI-compatible API gateway — inside DSH, with a desktop settings UI and a dsh-go native panel (Windows, macOS, Linux, Android).",
5
5
  "repository": {
6
6
  "type": "git",