@wangpinlan/dsh-vision-bridge 0.0.0-stage → 0.1.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 +21 -0
- package/README.md +110 -2
- package/client.js +470 -0
- package/cordis.patch.yml +18 -0
- package/docs/DETAIL.md +59 -0
- package/icon.svg +6 -0
- package/index.js +500 -0
- package/lib/pure.js +97 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +67 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 wangpinglan
|
|
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,111 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-vision-bridge
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
让**纯文本模型**在 DeepSeek Harness(DSH)里按需「看图」的插件。
|
|
4
|
+
|
|
5
|
+
用户发的图仍然以缩略图留在对话里;模型在请求里看到的是一段带附件引用的占位文字;当模型调用 `read_image` 时,插件读取附件字节、交给本机(或任意 OpenAI 兼容)视觉模型,把**文字描述**作为工具结果返回——描述出现在思维链里,而不是把图直接塞给纯文本后端。
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
用户发图 → 消息保留 image 块(GUI 缩略图)
|
|
9
|
+
→ 请求边界把 image 块换成占位文字(含 attachment id 与 read_image 指引)
|
|
10
|
+
→ 模型调用 read_image("attachment:sha256:…")
|
|
11
|
+
→ per-agent read_image 变体读取附件 → 调用视觉模型 → 返回中文描述
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## 安装
|
|
15
|
+
|
|
16
|
+
要求 DSH `0.2.3-alpha.4` 附近版本(见 `engines.dsh`)。
|
|
17
|
+
|
|
18
|
+
在 DSH 主界面打开 **插件 → 添加插件**,在输入框里填下面任意一种地址:
|
|
19
|
+
|
|
20
|
+
**GitHub 仓库地址(推荐)**
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
https://github.com/Wangpinglan/dsh-vision-bridge
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
也接受 `github:Wangpinglan/dsh-vision-bridge` 或 `git+https://github.com/Wangpinglan/dsh-vision-bridge.git`。
|
|
27
|
+
|
|
28
|
+
**本地目录**(开发 / 自用)
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
/absolute/path/to/dsh-vision-bridge
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
必须是绝对路径,也可以加 `file:` 前缀。相对路径会被拒绝。
|
|
35
|
+
|
|
36
|
+
也可以把仓库地址直接发给 DSH 里的 Agent,说一句「装这个插件」:
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
https://github.com/Wangpinglan/dsh-vision-bridge
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Agent 会调用 `plugin_manager` 的 `install_bundle` 完成安装(它会自己把地址转成 `git+https://...` 的安装 spec),装完还能顺手帮你启用、拉取模型和填配置。
|
|
43
|
+
|
|
44
|
+
**包名**
|
|
45
|
+
|
|
46
|
+
本插件尚未发布到 npm,`@wangpinlan/dsh-vision-bridge` 不能直接 `pnpm add`;请用上面的 Git 地址或本地目录安装。
|
|
47
|
+
|
|
48
|
+
安装完成后,到 **插件 → 视觉桥接** 启用,并按下一节填写配置。
|
|
49
|
+
|
|
50
|
+
> 对话框下方可以切换安装源(例如「中国大陆镜像源」)。如果拉取超时,先换一个源再试。
|
|
51
|
+
|
|
52
|
+
## 配置
|
|
53
|
+
|
|
54
|
+
安装后默认是 **inert** 的(`baseUrl`/`model` 为空,不安装任何监听器)。在插件详情页填写:
|
|
55
|
+
|
|
56
|
+
| 键 | 说明 |
|
|
57
|
+
| --- | --- |
|
|
58
|
+
| `baseUrl` | 视觉模型的 OpenAI 兼容基址,例如 `http://127.0.0.1:8080/v1` |
|
|
59
|
+
| `model` | 视觉模型名,例如 `qwen3-vl-4b`;填好 `baseUrl` 后可点「从端点拉取模型」自动列出候选 |
|
|
60
|
+
| `apiKey` | 可选;本地 llama-server 通常留空 |
|
|
61
|
+
| `prompt` | 可选;**默认提示词**。模型调用 `read_image` 时可传 `prompt` 参数按场景覆盖(如「只读文字」「检查布局」「描述主体」);模型没传时用这里的默认值,并附上用户当前的问题 |
|
|
62
|
+
| `maxTokens` | 单张图描述的最大 token 数,默认 768 |
|
|
63
|
+
| `providers` | 需要桥接的 provider 列表,例如 `strata` |
|
|
64
|
+
|
|
65
|
+
**`providers` 很关键**:DSH 的 GUI 在 `hasImage` 时会检查当前路由的 `inputModalities`,声明不含 `image` 就拒绝上传。所以目标路由通常仍要声明 `input: [text, image]`(让 GUI 放行),再由本插件在请求边界把图换成文字。`providers` 留空时,插件只桥接「声明明确不含 image」的路由。
|
|
66
|
+
|
|
67
|
+
## 视觉模型
|
|
68
|
+
|
|
69
|
+
任意 OpenAI 兼容的视觉服务都行,推荐本地 llama.cpp + Qwen3-VL-4B。本仓库不附带模型与启动脚本;llama-server 的典型参数是:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
llama-server -m Qwen3-VL-4B-Instruct-IQ4_XS.gguf --mmproj mmproj-F16.gguf \
|
|
73
|
+
--host 0.0.0.0 --port 8080 -ngl 99 -c 4096 --jinja --alias qwen3-vl-4b
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
把 `providers` 设为你实际使用的文本模型 provider(例如 `strata`)。
|
|
77
|
+
|
|
78
|
+
读图场景不需要长上下文:每次请求只有一条指令 + 一张图 + 最多几百 token 输出,`CTX=2048~4096` 足够,长上下文留给文本模型。
|
|
79
|
+
|
|
80
|
+
## 已知限制
|
|
81
|
+
|
|
82
|
+
- **模型切换后需要再发一轮**:变体在 agent 创建或下一次 `pre-step` 安装,而本步工具列表在此之前已捕获。
|
|
83
|
+
- **视觉服务不在线时** `read_image` 返回错误(不会静默降级)。
|
|
84
|
+
- **请求边界改写**通过包装 `llm.prepareCall()` 实现;与其它同样改写请求的插件叠加时行为取决于注册顺序。
|
|
85
|
+
- **依赖宿主内部 API**:`agent.ctx.tools`、`systemPrompt.section`、`llm.prepareCall`、settings 的 `volatile`/`configForms`。DSH 升级后请按版本验证。
|
|
86
|
+
|
|
87
|
+
## 开发
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
npm test # node --test,覆盖 lib/pure.js
|
|
91
|
+
npm pack --dry-run
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
目录结构:
|
|
95
|
+
|
|
96
|
+
| 文件 | 作用 |
|
|
97
|
+
| --- | --- |
|
|
98
|
+
| `index.js` | Host 半:请求边界、per-agent 工具、系统提示 |
|
|
99
|
+
| `lib/pure.js` | 纯函数(可单测) |
|
|
100
|
+
| `client.js` | 浏览器半:插件详情页配置表单 |
|
|
101
|
+
| `cordis.patch.yml` | bundle 行声明 |
|
|
102
|
+
| `locale/`、`docs/`、`icon.svg` | 展示资源 |
|
|
103
|
+
|
|
104
|
+
## Contributors
|
|
105
|
+
|
|
106
|
+
- Wangpinglan
|
|
107
|
+
- DeepSeek
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
MIT
|
package/client.js
ADDED
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-vision-bridge 客户端半:在 Plugins 页给本插件提供配置表单。
|
|
3
|
+
*
|
|
4
|
+
* 两条入口:
|
|
5
|
+
* - `plugins.bundle.config`(bundle 详情页,无需再点行):Owner 只传 `view`,
|
|
6
|
+
* 不传 `form`,所以这里通过 `configForms` 服务(`whileServed`)拿到该 entry
|
|
7
|
+
* 的共享表单;
|
|
8
|
+
* - `plugins.row.config`(row 详情页):Owner 直接传 `ConfigPageForm`。
|
|
9
|
+
*
|
|
10
|
+
* 表单编辑的是 Host 侧 profile patch 层的插件行 config,字段对应 index.js 的
|
|
11
|
+
* Config schema。写入走 Host 的 settings 通道(revision 栅栏),不另存一份配置。
|
|
12
|
+
*
|
|
13
|
+
* @module @wangpinlan/dsh-vision-bridge/client
|
|
14
|
+
*/
|
|
15
|
+
window.__ModuleLoader__.load({
|
|
16
|
+
id: '@wangpinlan/dsh-vision-bridge',
|
|
17
|
+
factory(require) {
|
|
18
|
+
const React = require('react')
|
|
19
|
+
const h = React.createElement
|
|
20
|
+
|
|
21
|
+
/** settings namespace:profile patch 里本插件行的 entry id。 */
|
|
22
|
+
const NAMESPACE = 'dsh-vision-bridge'
|
|
23
|
+
/** row 级配置 slot key:`<package name>#<row id>`。 */
|
|
24
|
+
const ROW_KEY = '@wangpinlan/dsh-vision-bridge#dsh-vision-bridge'
|
|
25
|
+
/** bundle 级配置 slot key:bundle 的包名。 */
|
|
26
|
+
const BUNDLE_KEY = '@wangpinlan/dsh-vision-bridge'
|
|
27
|
+
/** 客户端 locale 命名空间。 */
|
|
28
|
+
const NS = 'visionBridge'
|
|
29
|
+
|
|
30
|
+
const zh = {
|
|
31
|
+
summary: '视觉模型 {model} · {baseUrl}',
|
|
32
|
+
baseUrl: '视觉服务地址',
|
|
33
|
+
baseUrlHint: 'OpenAI 兼容的 /v1 基址',
|
|
34
|
+
model: '视觉模型名',
|
|
35
|
+
modelHint: '例如 qwen3-vl-4b',
|
|
36
|
+
apiKey: 'API Key',
|
|
37
|
+
apiKeyHint: '本地 llama-server 通常留空',
|
|
38
|
+
prompt: '描述指令',
|
|
39
|
+
promptHint: '模型没有自带指令时使用的默认提示词。模型可通过 read_image 的 prompt 参数按场景覆盖(如「只读文字」「检查布局」);留空用内置默认',
|
|
40
|
+
maxTokens: '最大生成 token',
|
|
41
|
+
maxTokensHint: '单张图片描述的上限,默认 768',
|
|
42
|
+
providers: '生效的 provider',
|
|
43
|
+
providersHint: '必填:勾选需要桥接的模型提供方。声明了 image 但后端其实无视觉的(如 llama.cpp 纯文本模型)必须勾上;一个都不勾时只桥接「声明为纯文本」的路由',
|
|
44
|
+
providersLoadFailed: '读取模型提供方列表失败,可手动输入 provider id',
|
|
45
|
+
providersNone: '没有可勾选的提供方,可手动输入 provider id',
|
|
46
|
+
providersManual: '手动输入 provider id(逗号分隔)',
|
|
47
|
+
required: '必填',
|
|
48
|
+
optional: '可选',
|
|
49
|
+
requiredNote: '标记为必填的项为空时插件不会生效(inert);apiKey/prompt/maxTokens 可选。',
|
|
50
|
+
fetchModels: '从端点拉取模型',
|
|
51
|
+
fetching: '拉取中…',
|
|
52
|
+
needBaseUrl: '先填写视觉服务地址',
|
|
53
|
+
noModels: '端点没有返回模型列表',
|
|
54
|
+
fetchFailed: '拉取失败',
|
|
55
|
+
save: '保存',
|
|
56
|
+
saving: '保存中…',
|
|
57
|
+
reset: '恢复默认',
|
|
58
|
+
saved: '已保存',
|
|
59
|
+
failed: '保存失败',
|
|
60
|
+
loading: '配置加载中… (v2)',
|
|
61
|
+
unavailable: '当前 Host 未提供该插件的配置',
|
|
62
|
+
readOnly: '当前 profile 不可写',
|
|
63
|
+
}
|
|
64
|
+
const en = {
|
|
65
|
+
summary: 'vision model {model} · {baseUrl}',
|
|
66
|
+
baseUrl: 'Vision endpoint',
|
|
67
|
+
baseUrlHint: 'OpenAI-compatible /v1 base URL',
|
|
68
|
+
model: 'Vision model',
|
|
69
|
+
modelHint: 'e.g. qwen3-vl-4b',
|
|
70
|
+
apiKey: 'API key',
|
|
71
|
+
apiKeyHint: 'Usually empty for a local llama-server',
|
|
72
|
+
prompt: 'Description prompt',
|
|
73
|
+
promptHint: 'Default prompt used when the calling model passes none. The model can override it per call through read_image’s prompt parameter (e.g. “read the text”, “check the layout”); leave empty for the built-in default',
|
|
74
|
+
maxTokens: 'Max tokens',
|
|
75
|
+
maxTokensHint: 'Upper bound for one image description, default 768',
|
|
76
|
+
providers: 'Bridged providers',
|
|
77
|
+
providersHint: 'Required: tick the providers to bridge. A route that declares image input but has no vision encoder (e.g. a llama.cpp text model) must be ticked here; ticking nothing bridges only routes declared text-only',
|
|
78
|
+
providersLoadFailed: 'Could not load the provider list; type provider ids manually',
|
|
79
|
+
providersNone: 'No providers to tick; type provider ids manually',
|
|
80
|
+
providersManual: 'Provider ids, comma separated',
|
|
81
|
+
required: 'Required',
|
|
82
|
+
optional: 'Optional',
|
|
83
|
+
requiredNote: 'The plugin stays inert while a required field is empty; apiKey, prompt and maxTokens are optional.',
|
|
84
|
+
fetchModels: 'Fetch models from endpoint',
|
|
85
|
+
fetching: 'Fetching…',
|
|
86
|
+
needBaseUrl: 'Fill the endpoint first',
|
|
87
|
+
noModels: 'The endpoint returned no model list',
|
|
88
|
+
fetchFailed: 'Fetch failed',
|
|
89
|
+
save: 'Save',
|
|
90
|
+
saving: 'Saving…',
|
|
91
|
+
reset: 'Reset to default',
|
|
92
|
+
saved: 'Saved',
|
|
93
|
+
failed: 'Save failed',
|
|
94
|
+
loading: 'Loading configuration… (v2)',
|
|
95
|
+
unavailable: 'This Host does not expose this plugin\'s configuration',
|
|
96
|
+
readOnly: 'This profile is not writable',
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** 字段定义(key 与 Config schema 同名)。 */
|
|
100
|
+
function fieldSpecs(tr) {
|
|
101
|
+
return [
|
|
102
|
+
{ key: 'baseUrl', label: tr('baseUrl', 'Vision endpoint'), hint: tr('baseUrlHint', 'OpenAI-compatible /v1 base URL'), required: true },
|
|
103
|
+
{ key: 'model', label: tr('model', 'Vision model'), hint: tr('modelHint', 'e.g. qwen3-vl-4b'), required: true },
|
|
104
|
+
{ key: 'apiKey', label: tr('apiKey', 'API key'), hint: tr('apiKeyHint', 'Usually empty for a local llama-server'), required: false },
|
|
105
|
+
{ key: 'prompt', label: tr('prompt', 'Description prompt'), hint: tr('promptHint', 'Leave empty to use the built-in prompt'), required: false, multiline: true },
|
|
106
|
+
{ key: 'maxTokens', label: tr('maxTokens', 'Max tokens'), hint: tr('maxTokensHint', 'Upper bound for one image description, default 768'), required: false },
|
|
107
|
+
{ key: 'providers', label: tr('providers', 'Bridged providers'), hint: tr('providersHint', 'Tick the providers to bridge'), required: true, placeholder: 'strata' },
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** 单个文本字段。 */
|
|
112
|
+
function TextField({ field, value, onChange, multiline, tr }) {
|
|
113
|
+
const style = { display: 'flex', flexDirection: 'column', gap: 4, marginBottom: 12 }
|
|
114
|
+
const input = {
|
|
115
|
+
padding: '6px 8px',
|
|
116
|
+
borderRadius: 6,
|
|
117
|
+
border: '1px solid var(--dsh-border, rgba(128,128,128,.35))',
|
|
118
|
+
background: 'var(--dsh-input-bg, transparent)',
|
|
119
|
+
color: 'inherit',
|
|
120
|
+
fontSize: 13,
|
|
121
|
+
fontFamily: 'inherit',
|
|
122
|
+
width: '100%',
|
|
123
|
+
boxSizing: 'border-box',
|
|
124
|
+
}
|
|
125
|
+
const placeholder = field.placeholder === undefined ? undefined : field.placeholder
|
|
126
|
+
const control = multiline
|
|
127
|
+
? h('textarea', { value, rows: 3, placeholder, style: { ...input, resize: 'vertical' }, onChange: e => onChange(e.target.value) })
|
|
128
|
+
: h('input', { value, placeholder, style: input, onChange: e => onChange(e.target.value) })
|
|
129
|
+
// 必填/可选徽标:必填红底红字,可选灰底淡字。
|
|
130
|
+
const badge = h('span', {
|
|
131
|
+
style: {
|
|
132
|
+
marginLeft: 6,
|
|
133
|
+
fontSize: 10.5,
|
|
134
|
+
padding: '1px 5px',
|
|
135
|
+
borderRadius: 4,
|
|
136
|
+
background: field.required ? 'rgba(198,40,40,.12)' : 'rgba(128,128,128,.12)',
|
|
137
|
+
color: field.required ? 'var(--dsh-danger, #c62828)' : 'inherit',
|
|
138
|
+
opacity: field.required ? 1 : 0.75,
|
|
139
|
+
},
|
|
140
|
+
}, field.required ? tr('required', 'Required') : tr('optional', 'Optional'))
|
|
141
|
+
return h('label', { style }, h('span', { style: { fontSize: 12, opacity: 0.85 } }, field.label, badge), control,
|
|
142
|
+
field.hint ? h('span', { style: { fontSize: 11, opacity: 0.6 } }, field.hint) : null)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** providers 字段的 JSON 值 → 输入框文本。 */
|
|
146
|
+
function providersText(value) {
|
|
147
|
+
if (Array.isArray(value)) return value.join(', ')
|
|
148
|
+
return value === undefined || value === null ? '' : String(value)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** providers 字段的 JSON 值 → provider id 数组。 */
|
|
152
|
+
function providersArray(value) {
|
|
153
|
+
if (Array.isArray(value)) return value.filter(id => typeof id === 'string')
|
|
154
|
+
return String(value === undefined || value === null ? '' : value)
|
|
155
|
+
.split(',').map(s => s.trim()).filter(Boolean)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** 把草稿转换成一类 set 操作。 */
|
|
159
|
+
function opsFor(draft, fields) {
|
|
160
|
+
const ops = []
|
|
161
|
+
for (const field of fields) {
|
|
162
|
+
if (!Object.hasOwn(draft, field.key)) continue
|
|
163
|
+
const raw = draft[field.key]
|
|
164
|
+
if (field.key === 'providers') {
|
|
165
|
+
ops.push({
|
|
166
|
+
op: 'set',
|
|
167
|
+
path: ['providers'],
|
|
168
|
+
value: Array.isArray(raw) ? raw.slice() : providersArray(raw),
|
|
169
|
+
})
|
|
170
|
+
} else if (field.key === 'maxTokens') {
|
|
171
|
+
const n = Number(raw)
|
|
172
|
+
if (Number.isFinite(n)) ops.push({ op: 'set', path: ['maxTokens'], value: n })
|
|
173
|
+
} else {
|
|
174
|
+
ops.push({ op: 'set', path: [field.key], value: String(raw ?? '') })
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return ops
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** provider 多选:选项来自 Host 的模型目录(所有已添加的 provider)。 */
|
|
181
|
+
function ProviderChecks({ field, tr, groups, selected, onChange }) {
|
|
182
|
+
const badge = h('span', {
|
|
183
|
+
style: {
|
|
184
|
+
marginLeft: 6,
|
|
185
|
+
fontSize: 10.5,
|
|
186
|
+
padding: '1px 5px',
|
|
187
|
+
borderRadius: 4,
|
|
188
|
+
background: field.required ? 'rgba(198,40,40,.12)' : 'rgba(128,128,128,.12)',
|
|
189
|
+
color: field.required ? 'var(--dsh-danger, #c62828)' : 'inherit',
|
|
190
|
+
opacity: field.required ? 1 : 0.75,
|
|
191
|
+
},
|
|
192
|
+
}, field.required ? tr('required', 'Required') : tr('optional', 'Optional'))
|
|
193
|
+
return h('div', { style: { display: 'flex', flexDirection: 'column', gap: 4, marginBottom: 12 } },
|
|
194
|
+
h('span', { style: { fontSize: 12, opacity: 0.85 } }, field.label, badge),
|
|
195
|
+
h('div', { style: { display: 'flex', flexDirection: 'column', gap: 4, padding: '2px 0' } },
|
|
196
|
+
groups.map(group => h('label', {
|
|
197
|
+
key: group.id,
|
|
198
|
+
style: { display: 'flex', gap: 8, alignItems: 'center', fontSize: 13, cursor: 'pointer' },
|
|
199
|
+
},
|
|
200
|
+
h('input', {
|
|
201
|
+
type: 'checkbox',
|
|
202
|
+
checked: selected.includes(group.id),
|
|
203
|
+
onChange: event => {
|
|
204
|
+
const next = event.target.checked
|
|
205
|
+
? [...selected, group.id]
|
|
206
|
+
: selected.filter(id => id !== group.id)
|
|
207
|
+
onChange(next)
|
|
208
|
+
},
|
|
209
|
+
}),
|
|
210
|
+
h('span', null, group.name !== undefined && group.name !== group.id
|
|
211
|
+
? `${group.name} (${group.id})`
|
|
212
|
+
: group.id)))),
|
|
213
|
+
field.hint ? h('span', { style: { fontSize: 11, opacity: 0.6 } }, field.hint) : null)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** 字段 + 保存/恢复默认/状态行,供两种表单入口共用。 */
|
|
217
|
+
function Fields({ t, value, writable, mutate, revision, fields, loadCatalog }) {
|
|
218
|
+
const [draft, setDraft] = React.useState({})
|
|
219
|
+
const [status, setStatus] = React.useState('idle')
|
|
220
|
+
const [models, setModels] = React.useState(null)
|
|
221
|
+
const [fetching, setFetching] = React.useState(false)
|
|
222
|
+
const [fetchError, setFetchError] = React.useState(null)
|
|
223
|
+
const [providerGroups, setProviderGroups] = React.useState(null)
|
|
224
|
+
const [providerError, setProviderError] = React.useState(null)
|
|
225
|
+
const tr = (key, fallback) => (typeof t === 'function' ? t(key) : fallback)
|
|
226
|
+
const read = key => (Object.hasOwn(draft, key) ? draft[key] : value[key])
|
|
227
|
+
const text = key => {
|
|
228
|
+
const v = read(key)
|
|
229
|
+
if (key === 'providers') return providersText(v)
|
|
230
|
+
return v === undefined || v === null ? '' : String(v)
|
|
231
|
+
}
|
|
232
|
+
React.useEffect(() => {
|
|
233
|
+
let cancelled = false
|
|
234
|
+
if (typeof loadCatalog !== 'function') return undefined
|
|
235
|
+
Promise.resolve()
|
|
236
|
+
.then(() => loadCatalog())
|
|
237
|
+
.then((catalog) => {
|
|
238
|
+
if (cancelled) return
|
|
239
|
+
const groups = catalog && Array.isArray(catalog.groups)
|
|
240
|
+
? catalog.groups
|
|
241
|
+
.filter(group => group && typeof group.id === 'string')
|
|
242
|
+
.map(group => ({ id: group.id, name: typeof group.name === 'string' ? group.name : undefined }))
|
|
243
|
+
: []
|
|
244
|
+
setProviderGroups(groups)
|
|
245
|
+
})
|
|
246
|
+
.catch((error) => {
|
|
247
|
+
if (!cancelled) setProviderError(error instanceof Error ? error.message : String(error))
|
|
248
|
+
})
|
|
249
|
+
return () => { cancelled = true }
|
|
250
|
+
}, [loadCatalog])
|
|
251
|
+
const save = async () => {
|
|
252
|
+
if (!writable) return
|
|
253
|
+
setStatus('saving')
|
|
254
|
+
try {
|
|
255
|
+
const ops = opsFor(draft, fields)
|
|
256
|
+
if (ops.length === 0) { setStatus('saved'); return }
|
|
257
|
+
const ok = await mutate(ops, revision)
|
|
258
|
+
setStatus(ok ? 'saved' : 'failed')
|
|
259
|
+
if (ok) setDraft({})
|
|
260
|
+
} catch {
|
|
261
|
+
setStatus('failed')
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
const reset = async () => {
|
|
265
|
+
if (!writable) return
|
|
266
|
+
try {
|
|
267
|
+
const ok = await mutate(fields.map(field => ({ op: 'unset', path: [field.key] })), revision)
|
|
268
|
+
setStatus(ok ? 'saved' : 'failed')
|
|
269
|
+
if (ok) setDraft({})
|
|
270
|
+
} catch {
|
|
271
|
+
setStatus('failed')
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
/** 从 baseUrl 的 `/v1/models` 拉取候选模型名,列表只有一个时直接填入。 */
|
|
275
|
+
const fetchModels = async () => {
|
|
276
|
+
const base = String(read('baseUrl') ?? '').trim()
|
|
277
|
+
if (base.length === 0) { setFetchError(tr('needBaseUrl', 'Fill the endpoint first')); return }
|
|
278
|
+
setFetching(true)
|
|
279
|
+
setFetchError(null)
|
|
280
|
+
try {
|
|
281
|
+
const trimmed = base.replace(/\/+$/, '')
|
|
282
|
+
const apiBase = /\/v\d+(?:$|\/)/iu.test(trimmed) ? trimmed : trimmed + '/v1'
|
|
283
|
+
const response = await fetch(apiBase + '/models', { headers: { Accept: 'application/json' } })
|
|
284
|
+
if (!response.ok) throw new Error('HTTP ' + response.status)
|
|
285
|
+
const json = await response.json()
|
|
286
|
+
const list = Array.isArray(json && json.data) ? json.data
|
|
287
|
+
: Array.isArray(json && json.models) ? json.models : []
|
|
288
|
+
const ids = [...new Set(list
|
|
289
|
+
.map(item => (item && (item.id || item.model || item.name)) || '')
|
|
290
|
+
.filter(name => typeof name === 'string' && name.length > 0))]
|
|
291
|
+
if (ids.length === 0) { setFetchError(tr('noModels', 'The endpoint returned no model list')); return }
|
|
292
|
+
setModels(ids)
|
|
293
|
+
if (ids.length === 1) setDraft(prev => ({ ...prev, model: ids[0] }))
|
|
294
|
+
} catch (error) {
|
|
295
|
+
setFetchError(String(error && error.message ? error.message : error))
|
|
296
|
+
} finally {
|
|
297
|
+
setFetching(false)
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
const selectStyle = {
|
|
301
|
+
padding: '6px 8px',
|
|
302
|
+
borderRadius: 6,
|
|
303
|
+
border: '1px solid var(--dsh-border, rgba(128,128,128,.35))',
|
|
304
|
+
background: 'var(--dsh-input-bg, transparent)',
|
|
305
|
+
color: 'inherit',
|
|
306
|
+
fontSize: 13,
|
|
307
|
+
fontFamily: 'inherit',
|
|
308
|
+
width: '100%',
|
|
309
|
+
boxSizing: 'border-box',
|
|
310
|
+
}
|
|
311
|
+
/** model 字段下方追加「拉取/候选」控件,其余字段保持原样。 */
|
|
312
|
+
const modelExtra = h('div', { style: { display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap', marginTop: -6, marginBottom: 12 } },
|
|
313
|
+
h('button', {
|
|
314
|
+
type: 'button',
|
|
315
|
+
disabled: fetching,
|
|
316
|
+
onClick: fetchModels,
|
|
317
|
+
style: { padding: '6px 12px', borderRadius: 6, cursor: fetching ? 'wait' : 'pointer', fontSize: 12 },
|
|
318
|
+
}, fetching ? tr('fetching', 'Fetching…') : tr('fetchModels', 'Fetch models from endpoint')),
|
|
319
|
+
fetchError === null ? null : h('span', { style: { fontSize: 12, color: 'var(--dsh-danger, #c62828)' } }, `${tr('fetchFailed', 'Fetch failed')}: ${fetchError}`),
|
|
320
|
+
)
|
|
321
|
+
const modelPicker = models === null || models.length <= 1 ? null : h('select', {
|
|
322
|
+
value: text('model'),
|
|
323
|
+
onChange: event => setDraft(prev => ({ ...prev, model: event.target.value })),
|
|
324
|
+
style: { ...selectStyle, marginTop: -6, marginBottom: 12 },
|
|
325
|
+
}, models.map(id => h('option', { key: id, value: id }, id)))
|
|
326
|
+
const providerList = providersArray(read('providers'))
|
|
327
|
+
const useChecks = Array.isArray(providerGroups) && providerGroups.length > 0
|
|
328
|
+
const providerFallbackNote = providerError !== null
|
|
329
|
+
? tr('providersLoadFailed', 'Could not load the provider list; type provider ids manually')
|
|
330
|
+
: (Array.isArray(providerGroups) ? tr('providersNone', 'No providers to tick; type provider ids manually') : null)
|
|
331
|
+
return h('div', { style: { maxWidth: 520 } },
|
|
332
|
+
fields.map((field) => {
|
|
333
|
+
if (field.key === 'providers') {
|
|
334
|
+
if (useChecks) {
|
|
335
|
+
return h(ProviderChecks, {
|
|
336
|
+
key: field.key,
|
|
337
|
+
field,
|
|
338
|
+
tr,
|
|
339
|
+
groups: providerGroups,
|
|
340
|
+
selected: providerList,
|
|
341
|
+
onChange: next => setDraft(prev => ({ ...prev, providers: next })),
|
|
342
|
+
})
|
|
343
|
+
}
|
|
344
|
+
return h(React.Fragment, { key: field.key },
|
|
345
|
+
h(TextField, {
|
|
346
|
+
field: { ...field, hint: providerFallbackNote !== null ? providerFallbackNote : field.hint },
|
|
347
|
+
value: text(field.key),
|
|
348
|
+
tr,
|
|
349
|
+
onChange: next => setDraft(prev => ({ ...prev, [field.key]: next })),
|
|
350
|
+
}))
|
|
351
|
+
}
|
|
352
|
+
if (field.key === 'model') {
|
|
353
|
+
return h(React.Fragment, { key: field.key },
|
|
354
|
+
h(TextField, {
|
|
355
|
+
field,
|
|
356
|
+
value: text(field.key),
|
|
357
|
+
tr,
|
|
358
|
+
onChange: next => setDraft(prev => ({ ...prev, [field.key]: next })),
|
|
359
|
+
}),
|
|
360
|
+
modelExtra,
|
|
361
|
+
modelPicker)
|
|
362
|
+
}
|
|
363
|
+
return h(TextField, {
|
|
364
|
+
key: field.key,
|
|
365
|
+
field,
|
|
366
|
+
value: text(field.key),
|
|
367
|
+
multiline: field.multiline === true,
|
|
368
|
+
tr,
|
|
369
|
+
onChange: next => setDraft(prev => ({ ...prev, [field.key]: next })),
|
|
370
|
+
})
|
|
371
|
+
}),
|
|
372
|
+
h('div', { style: { display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' } },
|
|
373
|
+
h('button', {
|
|
374
|
+
type: 'button',
|
|
375
|
+
disabled: !writable || status === 'saving',
|
|
376
|
+
onClick: save,
|
|
377
|
+
style: { padding: '6px 14px', borderRadius: 6, cursor: writable ? 'pointer' : 'not-allowed' },
|
|
378
|
+
}, status === 'saving' ? tr('saving', 'Saving…') : tr('save', 'Save')),
|
|
379
|
+
h('button', {
|
|
380
|
+
type: 'button',
|
|
381
|
+
disabled: !writable || status === 'saving',
|
|
382
|
+
onClick: reset,
|
|
383
|
+
style: { padding: '6px 14px', borderRadius: 6, cursor: writable ? 'pointer' : 'not-allowed' },
|
|
384
|
+
}, tr('reset', 'Reset to default')),
|
|
385
|
+
status === 'saved' ? h('span', { style: { fontSize: 12, color: 'var(--dsh-success, #2e7d32)' } }, tr('saved', 'Saved')) : null,
|
|
386
|
+
status === 'failed' ? h('span', { style: { fontSize: 12, color: 'var(--dsh-danger, #c62828)' } }, tr('failed', 'Save failed')) : null,
|
|
387
|
+
writable ? null : h('span', { style: { fontSize: 12, opacity: 0.6 } }, tr('readOnly', 'This profile is not writable')),
|
|
388
|
+
),
|
|
389
|
+
h('p', { style: { fontSize: 11, opacity: 0.6, marginTop: 10 } }, tr('requiredNote', 'The plugin stays inert while a required field is empty.')),
|
|
390
|
+
)
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/** bundle 详情页表单:数据来自 configForms 服务(ConfigForm 接口)。 */
|
|
394
|
+
function BundleForm({ form, t, loadCatalog }) {
|
|
395
|
+
const [snap, setSnap] = React.useState(() => form.getSnapshot())
|
|
396
|
+
React.useEffect(() => form.subscribe(() => setSnap(form.getSnapshot())), [form])
|
|
397
|
+
const tr = (key, fallback) => (typeof t === 'function' ? t(key) : fallback)
|
|
398
|
+
if (snap.status === 'loading') return h('p', { style: { opacity: 0.7 } }, tr('loading', 'Loading configuration…'))
|
|
399
|
+
if (snap.status === 'unavailable') return h('p', { style: { opacity: 0.7 } }, tr('unavailable', 'This Host does not expose this plugin\'s configuration'))
|
|
400
|
+
return h(Fields, {
|
|
401
|
+
t,
|
|
402
|
+
value: snap.value || {},
|
|
403
|
+
writable: snap.writable !== false,
|
|
404
|
+
mutate: form.mutate.bind(form),
|
|
405
|
+
revision: snap.revision,
|
|
406
|
+
fields: fieldSpecs(tr),
|
|
407
|
+
loadCatalog,
|
|
408
|
+
})
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/** row 详情页表单:数据由 Owner 以 ConfigPageForm 传入。 */
|
|
412
|
+
function RowForm({ form, t, loadCatalog }) {
|
|
413
|
+
const tr = (key, fallback) => (typeof t === 'function' ? t(key) : fallback)
|
|
414
|
+
const state = form && form.state
|
|
415
|
+
if (state === undefined) return h('p', { style: { opacity: 0.7 } }, tr('loading', 'Loading configuration…'))
|
|
416
|
+
if (state.status === 'unavailable') return h('p', { style: { opacity: 0.7 } }, tr('unavailable', 'This Host does not expose this plugin\'s configuration'))
|
|
417
|
+
return h(Fields, {
|
|
418
|
+
t,
|
|
419
|
+
value: state.value || {},
|
|
420
|
+
writable: state.writable !== false,
|
|
421
|
+
mutate: (ops, revision) => form.mutate(ops, revision),
|
|
422
|
+
revision: state.revision,
|
|
423
|
+
fields: fieldSpecs(tr),
|
|
424
|
+
loadCatalog,
|
|
425
|
+
})
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/** 列表与 row 摘要。 */
|
|
429
|
+
function Summary({ value }) {
|
|
430
|
+
return h('span', null, `read_image → ${value.model || 'qwen3-vl-4b'} @ ${value.baseUrl || 'http://127.0.0.1:8080/v1'}`)
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
return {
|
|
434
|
+
inject: ['slots', 'locale', 'remote', 'remote.models'],
|
|
435
|
+
apply(ctx) {
|
|
436
|
+
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'vision-bridge: locale dictionaries')
|
|
437
|
+
const t = ctx.locale.bind(NS)
|
|
438
|
+
/** 读取 Host 的模型目录:所有已添加的 provider 及其模型。 */
|
|
439
|
+
const loadCatalog = async () => {
|
|
440
|
+
const response = await ctx.remote.models.catalog()
|
|
441
|
+
if (!response || response.ok !== true) {
|
|
442
|
+
throw new Error(response && response.error ? String(response.error.message || response.error.code) : 'catalog failed')
|
|
443
|
+
}
|
|
444
|
+
return response.value
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// row 详情页:Owner 直接提供 ConfigPageForm。
|
|
448
|
+
ctx.slots.inject('plugins.row.config', () => ctx.slots.register({
|
|
449
|
+
name: 'plugins.row.config',
|
|
450
|
+
key: ROW_KEY,
|
|
451
|
+
locale: NS,
|
|
452
|
+
}, props => (props.view === 'summary'
|
|
453
|
+
? h(Summary, { value: (props.form && props.form.state && props.form.state.value) || {} })
|
|
454
|
+
: h(RowForm, { form: props.form, t: props.t || t, loadCatalog }))))
|
|
455
|
+
|
|
456
|
+
// bundle 详情页:Owner 不传 form,必须经 configForms 服务接表单。
|
|
457
|
+
ctx.inject(['configForms'], (scoped) => {
|
|
458
|
+
const forms = scoped.configForms
|
|
459
|
+
if (forms === undefined || typeof forms.get !== 'function' || typeof forms.whileServed !== 'function') return
|
|
460
|
+
const form = forms.get(NAMESPACE)
|
|
461
|
+
scoped.effect(() => forms.whileServed([NAMESPACE], () => scoped.slots.inject('plugins.bundle.config', () => scoped.slots.register({
|
|
462
|
+
name: 'plugins.bundle.config',
|
|
463
|
+
key: BUNDLE_KEY,
|
|
464
|
+
locale: NS,
|
|
465
|
+
}, props => h(BundleForm, { form, t: props.t || t, loadCatalog })))), 'vision-bridge: bundle config form')
|
|
466
|
+
})
|
|
467
|
+
},
|
|
468
|
+
}
|
|
469
|
+
},
|
|
470
|
+
})
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# dsh-vision-bridge bundle patch.
|
|
2
|
+
#
|
|
3
|
+
# Mounts the vision-bridge plugin under the stable row id `dsh-vision-bridge`.
|
|
4
|
+
# The plugin keeps user images as real attachments (the GUI shows thumbnails),
|
|
5
|
+
# replaces image blocks with text placeholders at the LLM request boundary for
|
|
6
|
+
# the configured providers, and installs a per-agent `read_image` variant that
|
|
7
|
+
# answers with a description from an external OpenAI-compatible vision model.
|
|
8
|
+
#
|
|
9
|
+
# No config is declared here on purpose: the published default is inert until
|
|
10
|
+
# the user fills `baseUrl` and `model` in Settings → Plugins → Vision bridge.
|
|
11
|
+
# Leaving `providers` empty makes the plugin bridge only routes whose declared
|
|
12
|
+
# `input` is explicitly text-only; set it (e.g. `providers: ['strata']`) to
|
|
13
|
+
# bridge a route that still declares image input so the GUI keeps accepting
|
|
14
|
+
# uploads.
|
|
15
|
+
|
|
16
|
+
- insert:
|
|
17
|
+
- id: dsh-vision-bridge
|
|
18
|
+
name: '@wangpinlan/dsh-vision-bridge'
|