dsh-plugin-opencode2api 0.0.0-stage → 1.2.0

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dsh-plugin-opencode2api contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,139 @@
1
- # Temporary Holding Version
1
+ # dsh-plugin-opencode2api · 本地免费 API
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 一键把 [opencode2api](https://github.com/jasonxu114514/opencode2api) 装进 DSH:自动下载对应平台的程序、生成配置、启动并常驻,并自动把「本地免费 API」注册成 DSH 的模型商(模型列表从网关动态获取)。装好后本机就有一个专属的、兼容 OpenAI 的免费 API;DSH 关闭再打开会自动重启。
4
+
5
+ ## 适用平台
6
+
7
+ | 平台 | 架构 | 状态 |
8
+ |---|---|---|
9
+ | Windows 10/11 | x64 / arm64 | 支持 |
10
+ | macOS | Intel / Apple Silicon | 支持 |
11
+ | Linux | x64 / arm64 | 支持 |
12
+ | Android(DSH Go,proot) | arm64 | 支持 |
13
+ | iOS | — | 暂不支持(App 沙箱不能运行外部程序) |
14
+
15
+ ## 安装
16
+
17
+ 最方便的是 npm(已发布,国内镜像已同步):
18
+
19
+ ```sh
20
+ dsh plugin --profile web add dsh-plugin-opencode2api
21
+ ```
22
+
23
+ 其他方式:
24
+
25
+ | 方式 | 命令 | 前提 |
26
+ |---|---|---|
27
+ | GitHub | `dsh plugin --profile web add github:king-andthe-nice/dsh-plugin-opencode2api` | 能访问 GitHub |
28
+ | 本地包 | `dsh plugin --profile web add ./dsh-plugin-opencode2api-1.2.0.tgz` | 有 17 KB 的 tgz |
29
+ | 局域网 | `dsh plugin --profile web add http://<手机IP>:8000/dsh-plugin-opencode2api-1.2.0.tgz` | 手机先 `python3 -m http.server 8000` |
30
+
31
+ 装好后引擎会自动下载程序(约 5 MB)、生成配置并在 `0.0.0.0:8080` 启动(本机和局域网都能连)。首次下载失败会每 30 秒重试。
32
+
33
+ Windows / macOS / Linux 装好后,打开 DSH Web UI(默认 `http://127.0.0.1:3080`)→ **设置 → 本地免费 API**,就能看到状态和操作按钮;手机 App 则在「本地API」胶囊/面板里。
34
+
35
+ ## 使用
36
+
37
+ 装好后插件会自动把本地 API 注册成模型商「本地免费 API」,模型列表从 `/v1/models` 动态获取。直接在 DSH 的模型选择器里选它下面的免费模型即可,不需要手动填 URL 和 Key。
38
+
39
+ 桌面端在 **设置 → 本地免费 API** 里操作;手机端在「本地API」面板里操作。面板会显示「模型商:已自动配置」。如果没配上,点面板里的「自动配置」重试;仍然失败时再手动接入:
40
+
41
+ 1. 打开「本地免费 API」面板。
42
+ 2. 点「复制接入」,得到:
43
+
44
+ ```text
45
+ 本机:http://127.0.0.1:8080/v1
46
+ 局域网:http://<你的局域网IP>:8080/v1
47
+ API Key:<随机生成>
48
+ 推荐模型:deepseek-v4.1-flash-free
49
+ ```
50
+
51
+ 3. 在 DSH 里添加 OpenAI 兼容服务商,Base URL 填上面的地址,API Key 填生成的 Key。
52
+
53
+ ## 功能(桌面设置页 / 手机面板)
54
+
55
+ - **启动 / 停止 / 重启 / 重装**:重装会重新下载程序。
56
+ - **仅本机 / 开局域网**:切换监听地址(`127.0.0.1` 或 `0.0.0.0`)。
57
+ - **复制地址 / 复制 Key / 复制后台信息**:桌面设置页有复制按钮;手机面板有「复制接入 / 复制后台」。
58
+ - **自动配置**:重新把本地 API 注册为模型商「本地免费 API」,并同步最新模型列表。
59
+ - **运行日志**:桌面设置页可展开查看最后 40 行;手机看数据目录里的 `opencode2api.log`。
60
+ - 状态实时显示;进程挂掉会自动拉起。
61
+
62
+ ## 界面说明
63
+
64
+ - **Windows / macOS / Linux(DSH Web UI)**:**设置 → 本地免费 API**,有状态、启动/停止/重启、监听切换、复制地址/Key、自动配置、重装和日志。
65
+ - **dsh-go 手机 App**:有「本地API」胶囊、状态条和原生面板。
66
+ - dsh-go 原生界面(胶囊/状态条/面板)只存在于手机 App;桌面端用的是 DSH Web UI 的设置页,不是 dsh-go 原生面板。
67
+
68
+ ### Windows 装完看不到界面?
69
+
70
+ 1. 先确认插件已装:DSH Web UI → 插件 → **已安装**,应看到 `dsh-plugin-opencode2api`。
71
+ 2. 打开 **设置 → 本地免费 API**(1.2.0 起提供桌面设置页)。1.1.0 只有手机原生面板,桌面没有界面。
72
+ 3. 如果插件市场里标着「本地开发」,说明装的是本地链接;想用 npm 版先移除再装,然后重启 DSH:
73
+
74
+ ```powershell
75
+ dsh plugin --profile web remove dsh-plugin-opencode2api
76
+ dsh plugin --profile web add dsh-plugin-opencode2api
77
+ ```
78
+
79
+ ## 自动配置
80
+
81
+ 网关就绪后,插件会:
82
+
83
+ - 把 `http://127.0.0.1:8080/v1` 注册为 `llm-pi-ai` 的提供方 `opencode2api`,显示名「本地免费 API」;
84
+ - 把本地 API Key 写入 DSH 凭据 `OPENCODE2API_API_KEY`(不写进配置文件);
85
+ - 从 `/v1/models` 读取模型,写入上下文窗口、输出上限、图片输入和推理档位;
86
+ - 模型列表变化时自动更新,没变化不重复写。
87
+
88
+ 不想自动配置时,在 DSH 的「设置 → 模型」里删掉「本地免费 API」即可;插件不会再加回来,除非模型列表变化或你点「自动配置」。
89
+
90
+ ## 管理后台
91
+
92
+ 浏览器打开 `http://127.0.0.1:8081`(或局域网地址),账号 `admin`,初始密码见桌面设置页(仅本机显示)或 `webui-password.txt`;后台改过后以新密码为准。后台可以改密码、查看请求、管理上游 Key 等。
93
+
94
+ ## 数据目录
95
+
96
+ ```text
97
+ $DSH_HOME/dsh-go/opencode2api/ # 默认 ~/.dsh/dsh-go/opencode2api/
98
+ ├── opencode2api # 程序
99
+ ├── config.json # 网关配置(监听、Key、匿名开关等)
100
+ ├── webui-password.txt # 后台初始密码(后台改过后会失效)
101
+ ├── auto-provider.json # 自动配置状态(模型列表指纹)
102
+ └── opencode2api.log # 运行日志
103
+ ```
104
+
105
+ ## 配置说明
106
+
107
+ 本插件为了开箱即用,默认开启匿名免费通道,并生成随机 `server_keys` 保护 `/v1/*`。注意:上游 opencode2api 本身默认**关闭**匿名,且明确提示匿名流量可能被大量拦截。想更稳可以:
108
+
109
+ - 在后台填入自己的 Zen / Go Key(`zen_keys` / `go_keys`),或
110
+ - 关闭匿名,只用自己的 Key。
111
+
112
+ 匿名通道由上游提供,可能被限流或拦截,仅供个人轻量使用;请遵守 OpenCode 与各模型服务的条款。
113
+
114
+ ## 卸载
115
+
116
+ ```sh
117
+ dsh plugin --profile web remove dsh-plugin-opencode2api
118
+ ```
119
+
120
+ 卸载不会删除 `$DSH_HOME/dsh-go/opencode2api/`;需要时手动删除该目录。
121
+
122
+ ## 能力与风险
123
+
124
+ 插件会读写本地文件、下载并运行外部程序、访问网络。请只从可信来源安装;公开分发代理免费模型时,请遵守上游服务条款。
125
+
126
+ ## 出处与许可
127
+
128
+ 本插件是 [opencode2api](https://github.com/jasonxu114514/opencode2api) 的**非官方**安装器,与作者无隶属关系。
129
+
130
+ - opencode2api:**GPL-3.0-or-later**,源码与许可证见[上游仓库](https://github.com/jasonxu114514/opencode2api)。
131
+ - 本插件**不打包、不修改** opencode2api;安装时从上游 GitHub Releases 下载官方原版二进制,以独立进程运行。
132
+ - 本插件自身代码:**MIT**(见 `LICENSE`)。
133
+ - 上游程序按“无担保”提供;匿名通道可能被上游限流或拦截,长期使用建议在后台填入自己的 Zen / Go Key,并遵守 OpenCode 与各模型服务的条款。
134
+
135
+ 详见 [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)。
136
+
137
+ ## License
138
+
139
+ MIT
@@ -0,0 +1,38 @@
1
+ # Third-party notices / 第三方说明
2
+
3
+ ## opencode2api
4
+
5
+ This plugin is an **unofficial** installer and process manager for **opencode2api**.
6
+
7
+ - Project: https://github.com/jasonxu114514/opencode2api
8
+ - Author: jasonxu114514 and contributors
9
+ - License: **GPL-3.0-or-later** — https://github.com/jasonxu114514/opencode2api/blob/main/LICENSE
10
+ - Source code: https://github.com/jasonxu114514/opencode2api
11
+
12
+ ### What this plugin does with it
13
+
14
+ - It does **not** bundle, vendor, or modify opencode2api.
15
+ - At install time it downloads the unmodified official release binary from the
16
+ project's GitHub Releases (with public mirrors as fallback) and runs it as a
17
+ separate process.
18
+ - The downloaded program remains under GPL-3.0-or-later and is provided
19
+ **without warranty** by its authors.
20
+ - This plugin's own code is MIT (see `LICENSE`).
21
+
22
+ Because the binary is fetched from the copyright holder's official release rather
23
+ than redistributed by this plugin, the plugin does not need to relicense its own
24
+ code under the GPL. If you fork this plugin and **bundle** the binary, you must
25
+ comply with GPL-3.0-or-later (include the license text and the corresponding
26
+ source).
27
+
28
+ ### Affiliation
29
+
30
+ This plugin is **not affiliated with or endorsed by** the opencode2api author.
31
+ "opencode2api" is used descriptively to identify the upstream project.
32
+
33
+ ## Model providers
34
+
35
+ opencode2api can proxy OpenCode Zen / Zen Go and an anonymous free channel. Your
36
+ use of those services is subject to their own terms and quotas. This plugin does
37
+ not grant any rights to those services, and anonymous traffic may be limited or
38
+ blocked upstream. Prefer supplying your own Zen / Go key.
@@ -0,0 +1,4 @@
1
+ # id: any unique id; name: must equal "name" in package.json.
2
+ - insert:
3
+ - id: dsh-plugin-opencode2api
4
+ name: dsh-plugin-opencode2api
package/lib/client.js ADDED
@@ -0,0 +1,468 @@
1
+ window.__ModuleLoader__.load({
2
+ id: 'dsh-plugin-opencode2api',
3
+ factory: require => {
4
+ const module = { exports: {} }
5
+ const exports = module.exports
6
+ const React = require('react')
7
+ const { createElement: h, useCallback, useEffect, useState } = React
8
+ const inject = ['slots']
9
+
10
+ const TONE = {
11
+ good: 'var(--dsw-alias-state-success-primary)',
12
+ warn: 'var(--dsw-alias-state-warning-primary)',
13
+ bad: 'var(--dsw-alias-state-error-primary)',
14
+ info: 'var(--dsw-alias-state-business-primary)',
15
+ muted: 'var(--dsw-alias-label-tertiary)',
16
+ }
17
+
18
+ const CSS = `
19
+ .oc2a button:hover:not(:disabled) { filter: brightness(1.08); }
20
+ .oc2a code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11px; background: var(--dsw-alias-bg-layer-2); padding: 1px 4px; border-radius: 4px; }
21
+ .oc2a summary { user-select: none; }
22
+ `
23
+
24
+ const calloutStyle = {
25
+ border: '1px solid var(--dsw-alias-border-l1)',
26
+ borderRadius: 9,
27
+ padding: '9px 11px',
28
+ margin: '8px 0',
29
+ fontSize: 12,
30
+ lineHeight: 1.6,
31
+ background: 'var(--dsw-alias-bg-layer-1)',
32
+ }
33
+
34
+ async function request(path, init) {
35
+ const res = await fetch(`/api/opencode2api${path}`, init)
36
+ const text = await res.text()
37
+ let data = null
38
+ try {
39
+ data = text ? JSON.parse(text) : null
40
+ } catch {
41
+ data = null
42
+ }
43
+ if (!res.ok) throw new Error(data?.error || text || `HTTP ${res.status}`)
44
+ return data
45
+ }
46
+
47
+ function useCopy() {
48
+ const [copied, setCopied] = useState('')
49
+ const copy = useCallback(async (label, value) => {
50
+ try {
51
+ await navigator.clipboard.writeText(value)
52
+ } catch {
53
+ const area = document.createElement('textarea')
54
+ area.value = value
55
+ document.body.appendChild(area)
56
+ area.select()
57
+ try {
58
+ document.execCommand('copy')
59
+ } catch {}
60
+ area.remove()
61
+ }
62
+ setCopied(label)
63
+ setTimeout(() => setCopied(''), 1500)
64
+ }, [])
65
+ return [copied, copy]
66
+ }
67
+
68
+ function Button({ children, onClick, disabled, primary }) {
69
+ return h(
70
+ 'button',
71
+ {
72
+ type: 'button',
73
+ onClick,
74
+ disabled,
75
+ style: {
76
+ appearance: 'none',
77
+ border: primary ? 'none' : '1px solid var(--dsw-alias-border-l1)',
78
+ background: primary
79
+ ? 'var(--dsw-alias-state-business-primary)'
80
+ : 'var(--dsw-alias-bg-layer-2)',
81
+ color: primary
82
+ ? 'var(--dsw-alias-label-on-accent)'
83
+ : 'var(--dsw-alias-label-primary)',
84
+ borderRadius: 8,
85
+ padding: '7px 12px',
86
+ font: 'inherit',
87
+ fontSize: 13,
88
+ cursor: disabled ? 'not-allowed' : 'pointer',
89
+ opacity: disabled ? 0.55 : 1,
90
+ },
91
+ },
92
+ children,
93
+ )
94
+ }
95
+
96
+ function Metric({ label, value, tone }) {
97
+ return h(
98
+ 'div',
99
+ {
100
+ style: {
101
+ border: '1px solid var(--dsw-alias-border-l1)',
102
+ borderRadius: 10,
103
+ padding: '10px 12px',
104
+ background: 'var(--dsw-alias-bg-layer-1)',
105
+ minWidth: 0,
106
+ },
107
+ },
108
+ h(
109
+ 'div',
110
+ {
111
+ style: {
112
+ fontSize: 11,
113
+ color: 'var(--dsw-alias-label-tertiary)',
114
+ marginBottom: 4,
115
+ },
116
+ },
117
+ label,
118
+ ),
119
+ h(
120
+ 'div',
121
+ {
122
+ style: {
123
+ fontSize: 13,
124
+ fontWeight: 600,
125
+ color: tone || 'var(--dsw-alias-label-primary)',
126
+ overflowWrap: 'anywhere',
127
+ },
128
+ },
129
+ value,
130
+ ),
131
+ )
132
+ }
133
+
134
+ function Page() {
135
+ const [state, setState] = useState(null)
136
+ const [error, setError] = useState('')
137
+ const [busy, setBusy] = useState('')
138
+ const [copied, copy] = useCopy()
139
+
140
+ const load = useCallback(async () => {
141
+ try {
142
+ setState(await request('/state'))
143
+ setError('')
144
+ } catch (err) {
145
+ setError(String(err?.message || err))
146
+ }
147
+ }, [])
148
+
149
+ useEffect(() => {
150
+ void load()
151
+ const timer = setInterval(load, 5000)
152
+ return () => clearInterval(timer)
153
+ }, [load])
154
+
155
+ const act = async action => {
156
+ setBusy(action)
157
+ setError('')
158
+ try {
159
+ const result = await request('/action', {
160
+ method: 'POST',
161
+ headers: { 'content-type': 'application/json' },
162
+ body: JSON.stringify({ action }),
163
+ })
164
+ if (result?.state) setState(result.state)
165
+ else void load()
166
+ } catch (err) {
167
+ setError(String(err?.message || err))
168
+ } finally {
169
+ setBusy('')
170
+ }
171
+ }
172
+
173
+ const tone = state
174
+ ? TONE[state.tone] || 'var(--dsw-alias-label-secondary)'
175
+ : 'var(--dsw-alias-label-secondary)'
176
+ const running = state?.running === true
177
+ const installed = state?.installed === true
178
+ const statusText = state
179
+ ? state.state || (running ? '运行中' : installed ? '已停止' : '未安装')
180
+ : '读取中…'
181
+ const disabled = busy !== ''
182
+ const secretHidden = state?.keyHidden === true
183
+
184
+ return h(
185
+ 'div',
186
+ {
187
+ className: 'oc2a',
188
+ style: {
189
+ padding: '18px 20px 28px',
190
+ maxWidth: 820,
191
+ color: 'var(--dsw-alias-label-primary)',
192
+ },
193
+ },
194
+ h('style', null, CSS),
195
+ h(
196
+ 'div',
197
+ {
198
+ style: {
199
+ display: 'flex',
200
+ alignItems: 'center',
201
+ gap: 10,
202
+ flexWrap: 'wrap',
203
+ marginBottom: 4,
204
+ },
205
+ },
206
+ h('div', { style: { fontSize: 18, fontWeight: 700 } }, '本地免费 API'),
207
+ h(
208
+ 'span',
209
+ {
210
+ style: {
211
+ display: 'inline-flex',
212
+ alignItems: 'center',
213
+ gap: 6,
214
+ fontSize: 12,
215
+ color: tone,
216
+ },
217
+ },
218
+ h('span', {
219
+ style: {
220
+ width: 7,
221
+ height: 7,
222
+ borderRadius: 99,
223
+ background: tone,
224
+ },
225
+ }),
226
+ statusText,
227
+ ),
228
+ ),
229
+ h(
230
+ 'div',
231
+ {
232
+ style: {
233
+ fontSize: 12,
234
+ color: 'var(--dsw-alias-label-tertiary)',
235
+ marginBottom: 14,
236
+ },
237
+ },
238
+ 'opencode2api · 自动下载、启动、掉线拉起;模型商自动配置,无需手动填 URL 和 Key。',
239
+ ),
240
+ error
241
+ ? h(
242
+ 'div',
243
+ {
244
+ style: {
245
+ ...calloutStyle,
246
+ borderColor: 'var(--dsw-alias-state-error-primary)',
247
+ color: 'var(--dsw-alias-state-error-primary)',
248
+ },
249
+ },
250
+ error,
251
+ )
252
+ : null,
253
+ state?.note
254
+ ? h(
255
+ 'div',
256
+ {
257
+ style: {
258
+ ...calloutStyle,
259
+ borderColor:
260
+ state.noteTone === 'warn'
261
+ ? 'var(--dsw-alias-state-warning-primary)'
262
+ : 'var(--dsw-alias-border-l1)',
263
+ color:
264
+ state.noteTone === 'warn'
265
+ ? 'var(--dsw-alias-state-warning-primary)'
266
+ : 'var(--dsw-alias-label-secondary)',
267
+ },
268
+ },
269
+ state.note,
270
+ )
271
+ : null,
272
+ h(
273
+ 'div',
274
+ {
275
+ style: {
276
+ display: 'grid',
277
+ gridTemplateColumns:
278
+ 'repeat(auto-fit, minmax(170px, 1fr))',
279
+ gap: 10,
280
+ margin: '14px 0',
281
+ },
282
+ },
283
+ h(Metric, { label: '本机地址', value: state?.baseUrl || '—' }),
284
+ h(Metric, { label: '局域网', value: state?.lanUrl || '—' }),
285
+ h(Metric, { label: '模型数', value: state?.models || '—' }),
286
+ h(Metric, {
287
+ label: '模型商',
288
+ value: state?.provider || '—',
289
+ tone: TONE[state?.providerTone] || undefined,
290
+ }),
291
+ h(Metric, { label: '监听', value: state?.listenMode || '—' }),
292
+ h(Metric, { label: '平台', value: state?.platform || '—' }),
293
+ ),
294
+ h(
295
+ 'div',
296
+ {
297
+ style: {
298
+ display: 'flex',
299
+ flexWrap: 'wrap',
300
+ gap: 8,
301
+ marginBottom: 10,
302
+ },
303
+ },
304
+ running
305
+ ? h(Button, { onClick: () => act('stop'), disabled }, '停止')
306
+ : h(
307
+ Button,
308
+ {
309
+ primary: true,
310
+ onClick: () => act('start'),
311
+ disabled,
312
+ },
313
+ busy === 'start' ? '启动中…' : '启动',
314
+ ),
315
+ h(Button, { onClick: () => act('restart'), disabled }, '重启'),
316
+ h(Button, { onClick: () => act('listenLocal'), disabled }, '仅本机'),
317
+ h(Button, { onClick: () => act('listenLan'), disabled }, '开局域网'),
318
+ h(
319
+ Button,
320
+ { onClick: () => act('autoConfig'), disabled },
321
+ busy === 'autoConfig' ? '配置中…' : '自动配置',
322
+ ),
323
+ h(Button, { onClick: () => act('reinstall'), disabled }, '重装'),
324
+ ),
325
+ h(
326
+ 'div',
327
+ {
328
+ style: {
329
+ display: 'flex',
330
+ flexWrap: 'wrap',
331
+ gap: 8,
332
+ marginBottom: 14,
333
+ },
334
+ },
335
+ h(
336
+ Button,
337
+ {
338
+ onClick: () => void copy('本机地址', state?.baseUrl || ''),
339
+ disabled: !state?.baseUrl,
340
+ },
341
+ copied === '本机地址' ? '已复制地址' : '复制地址',
342
+ ),
343
+ h(
344
+ Button,
345
+ {
346
+ onClick: () => void copy('Key', state?.key || ''),
347
+ disabled: !state?.key,
348
+ },
349
+ secretHidden
350
+ ? 'Key 仅本机可见'
351
+ : copied === 'Key'
352
+ ? '已复制 Key'
353
+ : '复制 Key',
354
+ ),
355
+ h(
356
+ Button,
357
+ {
358
+ onClick: () =>
359
+ window.open(
360
+ state?.webUrl || 'http://127.0.0.1:8081',
361
+ '_blank',
362
+ 'noopener',
363
+ ),
364
+ },
365
+ '打开后台',
366
+ ),
367
+ h(
368
+ Button,
369
+ {
370
+ onClick: () =>
371
+ window.open(
372
+ 'https://github.com/king-andthe-nice/dsh-plugin-opencode2api',
373
+ '_blank',
374
+ 'noopener',
375
+ ),
376
+ },
377
+ '项目主页',
378
+ ),
379
+ ),
380
+ h(
381
+ 'div',
382
+ {
383
+ style: {
384
+ fontSize: 12,
385
+ color: 'var(--dsw-alias-label-tertiary)',
386
+ lineHeight: 1.7,
387
+ marginBottom: 12,
388
+ },
389
+ },
390
+ 'DSH 模型选择器里应出现「本地免费 API」。后台账号 admin,密码见 ',
391
+ h('code', null, state?.webPasswordPath || 'webui-password.txt'),
392
+ secretHidden || !state?.password
393
+ ? null
394
+ : h('span', null, ';当前密码:', h('code', null, state.password)),
395
+ ),
396
+ h(
397
+ 'details',
398
+ {
399
+ style: {
400
+ borderTop: '1px solid var(--dsw-alias-border-l1)',
401
+ paddingTop: 10,
402
+ },
403
+ },
404
+ h(
405
+ 'summary',
406
+ {
407
+ style: {
408
+ cursor: 'pointer',
409
+ fontSize: 12,
410
+ color: 'var(--dsw-alias-label-secondary)',
411
+ },
412
+ },
413
+ '运行日志',
414
+ ),
415
+ h(
416
+ 'pre',
417
+ {
418
+ style: {
419
+ margin: '8px 0 0',
420
+ padding: 10,
421
+ borderRadius: 8,
422
+ background: 'var(--dsw-alias-bg-layer-2)',
423
+ color: 'var(--dsw-alias-label-secondary)',
424
+ fontSize: 11,
425
+ lineHeight: 1.55,
426
+ whiteSpace: 'pre-wrap',
427
+ wordBreak: 'break-all',
428
+ maxHeight: 220,
429
+ overflow: 'auto',
430
+ },
431
+ },
432
+ state?.log || '暂无日志',
433
+ ),
434
+ ),
435
+ h(
436
+ 'div',
437
+ {
438
+ style: {
439
+ marginTop: 12,
440
+ fontSize: 11,
441
+ color: 'var(--dsw-alias-label-tertiary)',
442
+ },
443
+ },
444
+ '网关来自 opencode2api(GPL-3.0-or-later)官方 Release,本插件不打包、不修改它。',
445
+ ),
446
+ )
447
+ }
448
+
449
+ function apply(ctx) {
450
+ ctx.slots.inject('settings.section', () =>
451
+ ctx.slots.register(
452
+ {
453
+ name: 'settings.section',
454
+ id: 'opencode2api',
455
+ order: 36,
456
+ label: () => '本地免费 API',
457
+ },
458
+ () => h(Page),
459
+ ),
460
+ )
461
+ }
462
+
463
+ exports.apply = apply
464
+ exports.inject = inject
465
+ exports.name = 'opencode2api'
466
+ return module.exports
467
+ },
468
+ })