dsh-gallery 0.16.6 → 1.0.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/CHANGELOG.md +180 -30
- package/README.md +48 -17
- package/client.js +577 -164
- package/host/context.js +87 -0
- package/host/feedback-text.js +81 -1
- package/host/frames.js +34 -0
- package/host/groups.js +5 -0
- package/host/http.js +246 -20
- package/host/protocol.js +403 -1
- package/host/scan.js +90 -23
- package/host/tools.js +344 -0
- package/index.js +6 -2
- package/package.json +1 -1
package/host/tools.js
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 产出台 · Agent 工具(阶段 1 / B1)
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要这一层:插件的 op 路由挂在 DSH 的 `/api` 网关上,需要进程内
|
|
5
|
+
* 随机签名 cookie,对话框里的 Agent 拿不到;`window.dshGallerySeam` 又只
|
|
6
|
+
* 存在于 renderer。让模型「主动调用」的正规通道是 Host 侧的
|
|
7
|
+
* `ctx.tools.register` —— 注册后 schema 自动进每轮请求。
|
|
8
|
+
*
|
|
9
|
+
* 本文件零外部依赖:只用本插件自己的模块与 Node 内置模块。
|
|
10
|
+
* `ctx.tools.register` 接受裸定义对象(不强制 defineTool),宿主实测校验:
|
|
11
|
+
* · output 必须是对象,且 output.render 必须是函数
|
|
12
|
+
* · output.schema 属于支持的 JSON Schema 子集
|
|
13
|
+
* (type / oneOf / properties / required / additionalProperties /
|
|
14
|
+
* items / enum / const + 注解)
|
|
15
|
+
* · timeoutMs 若给,必须是正有限数;名字不能是保留的 run_code
|
|
16
|
+
* · 同名 tool 在同一层重复注册会抛错 —— 未捕获会让整个插件不激活,
|
|
17
|
+
* 所以注册必须包 try/catch(deep-view 源码注释里踩过这个坑)
|
|
18
|
+
*
|
|
19
|
+
* 红线:本工具**只读**。不改资产、不写反馈、不替用户发送任何东西。
|
|
20
|
+
*/
|
|
21
|
+
import path from 'node:path'
|
|
22
|
+
import { statSync } from 'node:fs'
|
|
23
|
+
import { scanGallery } from './scan.js'
|
|
24
|
+
import { applyAssetFilter, sortByRelevance } from './http.js'
|
|
25
|
+
import { resolveOptions } from './settings.js'
|
|
26
|
+
// 阶段 3 / C1:读「人正在看哪张图」(另一份临时状态,只读)
|
|
27
|
+
import { readContext } from './context.js'
|
|
28
|
+
// 原图 / 预览图反查配套主遮罩(与前端双击、拖图同一口径)
|
|
29
|
+
import { buildLinkedMaskIndex } from './frames.js'
|
|
30
|
+
|
|
31
|
+
const TOOL_NAME = 'gallery_find'
|
|
32
|
+
const CONTEXT_TOOL_NAME = 'gallery_context'
|
|
33
|
+
const MAX_LIMIT = 100
|
|
34
|
+
const DEFAULT_LIMIT = 20
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 短时复用扫描结果(2026-11-15):同一轮里模型反复查同一批资产时,
|
|
38
|
+
* 不再每次重扫全库(本机实测一次约 7 秒)。
|
|
39
|
+
* 键里带上标签 / 遮罩登记 / 标记 / 反馈篮的时间戳:人改了标签或刚生成新图
|
|
40
|
+
* 立刻失效;最长也只复用 12 秒,不会把新资产藏太久。过滤每轮仍重做。
|
|
41
|
+
*/
|
|
42
|
+
const SCAN_TTL_MS = 12_000
|
|
43
|
+
const scanCache = new Map()
|
|
44
|
+
function scanCacheKey(config, kind, scope, sid, opts) {
|
|
45
|
+
let stamp = ""
|
|
46
|
+
try {
|
|
47
|
+
const home = path.dirname(String(opts.settingsFile ?? ""))
|
|
48
|
+
const names = ["dsh-gallery.json", "dsh-gallery-labels.json", "dsh-gallery-frames.json",
|
|
49
|
+
"dsh-gallery-marks.json", "dsh-gallery-feedback.json"]
|
|
50
|
+
for (const name of names) {
|
|
51
|
+
try { stamp += `${statSync(path.join(home, name)).mtimeMs}|` } catch { stamp += "0|" }
|
|
52
|
+
}
|
|
53
|
+
} catch { stamp = "" }
|
|
54
|
+
return [kind, scope, sid, JSON.stringify(config ?? {}), stamp].join("~")
|
|
55
|
+
}
|
|
56
|
+
async function scanWithShortCache(config, kind, scope, sid, opts) {
|
|
57
|
+
const key = scanCacheKey(config, kind, scope, sid, opts)
|
|
58
|
+
const now = Date.now()
|
|
59
|
+
const hit = scanCache.get(key)
|
|
60
|
+
if (hit !== undefined && now - hit.at < SCAN_TTL_MS) return hit.value
|
|
61
|
+
const value = await scanGallery(config, kind, scope, sid, 1)
|
|
62
|
+
if (scanCache.size >= 6) scanCache.clear()
|
|
63
|
+
scanCache.set(key, { at: now, value })
|
|
64
|
+
return value
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** 找绝对路径所属的最长产出根;跨多根时不能赌 roots[0]。 */
|
|
68
|
+
function rootOf(roots, abs) {
|
|
69
|
+
const a = path.resolve(String(abs ?? ''))
|
|
70
|
+
let best = ''
|
|
71
|
+
for (const r of roots) {
|
|
72
|
+
const rr = path.resolve(String(r ?? ''))
|
|
73
|
+
if ((a === rr || a.startsWith(rr + path.sep)) && rr.length > best.length) best = rr
|
|
74
|
+
}
|
|
75
|
+
return best
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 把 scan 出来的资产压成给模型的行。
|
|
80
|
+
* groups 分支缺 maskOf / sessionTitle,用扁平 items 建的索引补齐。
|
|
81
|
+
*/
|
|
82
|
+
function toRow(f, roots, maskIndex, linkedIndex) {
|
|
83
|
+
const relPath = String(f?.relPath ?? '')
|
|
84
|
+
const absPath = String(f?.absPath ?? '')
|
|
85
|
+
const mask = f?.maskOf ?? maskIndex.get(relPath) ?? null
|
|
86
|
+
// 原图 / 预览图自己没有 maskOf,按登记反查配套主遮罩(与双击、拖图一致)
|
|
87
|
+
const maskRel = String(mask?.relPath ?? '') || String(linkedIndex.get(relPath) ?? '')
|
|
88
|
+
const root = rootOf(roots, absPath)
|
|
89
|
+
return {
|
|
90
|
+
relPath,
|
|
91
|
+
absPath,
|
|
92
|
+
name: String(f?.name ?? relPath.split('/').pop() ?? ''),
|
|
93
|
+
category: String(f?.category ?? 'unknown'),
|
|
94
|
+
categoryManual: f?.categoryManual === true,
|
|
95
|
+
sessionId: String(f?.sessionId ?? ''),
|
|
96
|
+
sessionTitle: String(f?.sessionTitle ?? ''),
|
|
97
|
+
maskPath: maskRel,
|
|
98
|
+
maskAbsPath: maskRel !== '' && root !== '' ? path.resolve(root, maskRel) : '',
|
|
99
|
+
mtime: Number(f?.mtime ?? 0),
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** render 的返回值就是模型与用户看到的内容 —— 路径必须直接写在文本里。 */
|
|
104
|
+
function renderRows(args, value) {
|
|
105
|
+
if (value?.error) return [{ type: 'text', text: `产出台查询失败:${value.error}` }]
|
|
106
|
+
const items = Array.isArray(value?.items) ? value.items : []
|
|
107
|
+
if (items.length === 0) return [{ type: 'text', text: '产出台里没有符合条件的资产。' }]
|
|
108
|
+
const q = String(args?.query ?? '').trim()
|
|
109
|
+
// 2026-11-15:明确告诉模型「不填关键词=按时间从新到旧」,
|
|
110
|
+
// 否则问「最后三张」时模型会以为必须调大 limit 重查一次才能确认排序。
|
|
111
|
+
const orderNote = q === ''
|
|
112
|
+
? '已按文件修改时间从新到旧排列,第一条就是最新的一张'
|
|
113
|
+
: '已按关键词相关性排列'
|
|
114
|
+
const lines = [`共 ${value.total} 个资产符合条件,这里列出${q === '' ? '最近的' : '最相关的'} ${items.length} 条`
|
|
115
|
+
+ `(${orderNote};一次默认最多 ${DEFAULT_LIMIT} 条;本清单即最终依据,直接据此作答):`]
|
|
116
|
+
// 问「最后三张」时把结论摆在最前面,省得模型自己再跑脚本排序核对。
|
|
117
|
+
if (q === '' && items.length > 0) {
|
|
118
|
+
const top = items.slice(0, 3)
|
|
119
|
+
lines.push(`最新 ${top.length} 张:${top.map((it, i) => `${i + 1}. ${it.name}`).join(';')}`)
|
|
120
|
+
}
|
|
121
|
+
for (const it of items) {
|
|
122
|
+
lines.push(`· ${it.relPath} | ${it.category}${it.sessionTitle ? ` | 会话「${it.sessionTitle}」` : ''}`)
|
|
123
|
+
lines.push(` 图:${it.absPath}`)
|
|
124
|
+
if (it.maskAbsPath) lines.push(` 主遮罩:${it.maskAbsPath}`)
|
|
125
|
+
}
|
|
126
|
+
lines.push('以上均为绝对路径;做局部重绘时用「图 + 主遮罩」成对取用。'
|
|
127
|
+
+ (q === ''
|
|
128
|
+
? '问「最后几张 / 最近几张」直接取上面的前几条即可,不必重查;'
|
|
129
|
+
: '')
|
|
130
|
+
+ '结果已核对完毕,禁止再用命令行 / 脚本 / 读取源码重复扫描,也不要再次调用本工具确认排序;'
|
|
131
|
+
+ '只有用户明确要求看更多张时才把 limit 调大后再查一次。')
|
|
132
|
+
return [{ type: 'text', text: lines.join('\n') }]
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** 真查一次:进程内复用 scanGallery + applyAssetFilter,不走 /api 网关。 */
|
|
136
|
+
async function findAssets(args, exec, config) {
|
|
137
|
+
const a = args ?? {}
|
|
138
|
+
try {
|
|
139
|
+
const opts = resolveOptions(config)
|
|
140
|
+
const roots = Array.isArray(opts.roots) ? opts.roots : []
|
|
141
|
+
const kind = a.kind === 'file' || a.kind === 'media' ? a.kind : 'image'
|
|
142
|
+
const execSessionId = typeof exec?.agent?.session?.id === 'string' ? exec.agent.session.id : ''
|
|
143
|
+
const scope = a.scope === 'session' && execSessionId !== '' ? 'session' : 'global'
|
|
144
|
+
const limit = Math.max(1, Math.min(MAX_LIMIT, Math.trunc(Number(a.limit)) || DEFAULT_LIMIT))
|
|
145
|
+
|
|
146
|
+
const value = await scanWithShortCache(config, kind, scope, execSessionId, opts)
|
|
147
|
+
const filtered = await applyAssetFilter(value, {
|
|
148
|
+
filterLabel: '',
|
|
149
|
+
filterCategory: typeof a.category === 'string' ? a.category : '',
|
|
150
|
+
filterAction: '',
|
|
151
|
+
filterExt: '',
|
|
152
|
+
filterQuery: typeof a.query === 'string' ? a.query.trim().toLowerCase() : '',
|
|
153
|
+
filterLimit: 500,
|
|
154
|
+
settingsFile: opts.settingsFile,
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
// groups[].files 不带 maskOf;用扁平 items 建索引,按 relPath 回查补齐
|
|
158
|
+
const flat = [
|
|
159
|
+
...(Array.isArray(filtered.items) ? filtered.items : []),
|
|
160
|
+
...(Array.isArray(filtered.files) ? filtered.files : []),
|
|
161
|
+
]
|
|
162
|
+
const maskIndex = new Map()
|
|
163
|
+
for (const f of flat) {
|
|
164
|
+
if (f?.relPath && f.maskOf) maskIndex.set(String(f.relPath), f.maskOf)
|
|
165
|
+
}
|
|
166
|
+
const linkedIndex = await buildLinkedMaskIndex(opts.settingsFile)
|
|
167
|
+
|
|
168
|
+
const rows = []
|
|
169
|
+
const seen = new Set()
|
|
170
|
+
const add = (f) => {
|
|
171
|
+
const rel = String(f?.relPath ?? '')
|
|
172
|
+
if (rel === '' || seen.has(rel)) return
|
|
173
|
+
seen.add(rel)
|
|
174
|
+
rows.push(toRow(f, roots, maskIndex, linkedIndex))
|
|
175
|
+
}
|
|
176
|
+
flat.forEach(add)
|
|
177
|
+
if (Array.isArray(filtered.groups)) {
|
|
178
|
+
for (const g of filtered.groups) {
|
|
179
|
+
if (Array.isArray(g?.files)) g.files.forEach(add)
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// 有关键词时按相关性排(与清单接口同一套打分);没关键词时仍按时间倒序。
|
|
183
|
+
const q = typeof a.query === 'string' ? a.query.trim().toLowerCase() : ''
|
|
184
|
+
const ordered = q !== ''
|
|
185
|
+
? sortByRelevance(rows, q, (r) => String(maskIndex.get(r.relPath)?.sourceName ?? ''))
|
|
186
|
+
: rows.slice().sort((x, y) => y.mtime - x.mtime)
|
|
187
|
+
|
|
188
|
+
return { total: ordered.length, items: ordered.slice(0, limit), error: '' }
|
|
189
|
+
} catch (error) {
|
|
190
|
+
// 查询出错也不能让 tool 调用抛异常,否则模型这一轮直接废掉
|
|
191
|
+
return { total: 0, items: [], error: String(error?.message ?? error) }
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** 生成注册用的裸定义对象(导出给测试真跑,不依赖 DSH 运行时)。 */
|
|
196
|
+
export function buildToolDefinition(config) {
|
|
197
|
+
return {
|
|
198
|
+
name: TOOL_NAME,
|
|
199
|
+
description: '查找本机「产出台」里的资产(图片 / 文件 / 音视频)。'
|
|
200
|
+
+ '返回每条资产的绝对路径、分类、所属会话标题与关联主遮罩的绝对路径。'
|
|
201
|
+
+ '当用户问「这轮产出了什么」「把定稿图拿来」「门头那张图在哪」「有哪些素材」时用本工具,'
|
|
202
|
+
+ '不要让用户自己报文件名。一次默认最多返回 20 条;除非用户明确要求更多张,否则不要调大 limit。'
|
|
203
|
+
+ '不填关键词时结果按文件修改时间从新到旧排列,第一条就是最新的一张;'
|
|
204
|
+
+ '用户问「最后几张 / 最近几张 / 最新几张」时直接取返回的前几条回答,保持默认 limit 即可。'
|
|
205
|
+
+ '本工具结果就是最终依据:直接用它作答,禁止再运行命令行 / 脚本 / 读取源码去重复扫描或核对,'
|
|
206
|
+
+ '也不要为了确认排序再次调用本工具(重查要重扫全库,实测会多花一两分钟)。'
|
|
207
|
+
+ '只读,不会修改任何资产,也不会发送任何消息。',
|
|
208
|
+
parameters: {
|
|
209
|
+
type: 'object',
|
|
210
|
+
properties: {
|
|
211
|
+
query: { type: 'string', description: '关键词,匹配文件名与相对路径(不区分大小写);留空=不限' },
|
|
212
|
+
category: { type: 'string', description: '标签过滤:final=定稿 / input=素材 / intermediate=过程稿 / unknown=未归类;留空=不限' },
|
|
213
|
+
kind: { type: 'string', description: '资产类型:image / file / media;默认 image' },
|
|
214
|
+
scope: { type: 'string', description: 'global=全部对话 / session=当前对话;默认 global' },
|
|
215
|
+
limit: { type: 'number', description: `最多返回条数,默认 ${DEFAULT_LIMIT},最大 ${MAX_LIMIT};问「最后几张 / 最近几张」保持默认即可,除非用户明确要更多张,否则不要调大` },
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
output: {
|
|
219
|
+
schema: {
|
|
220
|
+
type: 'object',
|
|
221
|
+
properties: {
|
|
222
|
+
total: { type: 'number', description: '过滤后的资产总数' },
|
|
223
|
+
items: {
|
|
224
|
+
type: 'array',
|
|
225
|
+
items: {
|
|
226
|
+
type: 'object',
|
|
227
|
+
properties: {
|
|
228
|
+
relPath: { type: 'string' },
|
|
229
|
+
absPath: { type: 'string' },
|
|
230
|
+
name: { type: 'string' },
|
|
231
|
+
category: { type: 'string' },
|
|
232
|
+
categoryManual: { type: 'boolean' },
|
|
233
|
+
sessionId: { type: 'string' },
|
|
234
|
+
sessionTitle: { type: 'string' },
|
|
235
|
+
maskPath: { type: 'string' },
|
|
236
|
+
maskAbsPath: { type: 'string' },
|
|
237
|
+
mtime: { type: 'number' },
|
|
238
|
+
},
|
|
239
|
+
required: ['relPath', 'absPath', 'category'],
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
error: { type: 'string', description: '查询失败原因;成功时为空串' },
|
|
243
|
+
},
|
|
244
|
+
required: ['total', 'items'],
|
|
245
|
+
},
|
|
246
|
+
render: renderRows,
|
|
247
|
+
},
|
|
248
|
+
async execute(args, exec) {
|
|
249
|
+
return findAssets(args, exec, config)
|
|
250
|
+
},
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** 阶段 3 / C1:把「人正在看哪张」写成模型直接看得懂的文字。 */
|
|
255
|
+
function renderContext(args, value) {
|
|
256
|
+
const it = value?.item
|
|
257
|
+
if (value?.found !== true || it === null || it === undefined || String(it?.relPath ?? '') === '') {
|
|
258
|
+
return [{ type: 'text', text: typeof value?.text === 'string' && value.text !== ''
|
|
259
|
+
? value.text : '产出台里还没记下用户打开过哪张图(需要用户先在产出台点开一张大图)。' }]
|
|
260
|
+
}
|
|
261
|
+
const lines = ['用户最近在产出台里打开看的资产:']
|
|
262
|
+
lines.push(`· 文件名:${it.name || it.relPath}`)
|
|
263
|
+
lines.push(`· 完整路径:${it.absPath || it.relPath}`)
|
|
264
|
+
lines.push(`· 分类:${it.category}${it.categoryManual ? '(手动改过)' : ''}`)
|
|
265
|
+
if (it.sessionTitle) lines.push(`· 所属对话:${it.sessionTitle}`)
|
|
266
|
+
if (it.maskAbsPath) lines.push(`· 主遮罩:${it.maskAbsPath}`)
|
|
267
|
+
lines.push('以上均为绝对路径;做局部重绘时用「图 + 主遮罩」成对取用。')
|
|
268
|
+
return [{ type: 'text', text: lines.join('\n') }]
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** 导出给测试真跑:不依赖 DSH 运行时。 */
|
|
272
|
+
export function buildContextToolDefinition(config) {
|
|
273
|
+
return {
|
|
274
|
+
name: CONTEXT_TOOL_NAME,
|
|
275
|
+
description: '查用户此刻(或最近一次)在产出台里点开看的是哪一件资产。'
|
|
276
|
+
+ '当用户说「我刚看的那张」「这张图」「当前打开的图」时用本工具,'
|
|
277
|
+
+ '不要让用户重新报文件名。返回完整绝对路径与关联主遮罩。只读,不发送任何消息。',
|
|
278
|
+
parameters: { type: 'object', properties: {} },
|
|
279
|
+
output: {
|
|
280
|
+
schema: {
|
|
281
|
+
type: 'object',
|
|
282
|
+
properties: {
|
|
283
|
+
found: { type: 'boolean', description: '有没有记下用户看过的图' },
|
|
284
|
+
item: {
|
|
285
|
+
type: 'object',
|
|
286
|
+
properties: {
|
|
287
|
+
relPath: { type: 'string' }, absPath: { type: 'string' },
|
|
288
|
+
name: { type: 'string' }, category: { type: 'string' },
|
|
289
|
+
categoryManual: { type: 'boolean' },
|
|
290
|
+
maskPath: { type: 'string' }, maskAbsPath: { type: 'string' },
|
|
291
|
+
sessionId: { type: 'string' }, sessionTitle: { type: 'string' },
|
|
292
|
+
updatedAt: { type: 'number' },
|
|
293
|
+
},
|
|
294
|
+
required: ['relPath', 'absPath'],
|
|
295
|
+
},
|
|
296
|
+
text: { type: 'string' },
|
|
297
|
+
},
|
|
298
|
+
required: ['found', 'item'],
|
|
299
|
+
},
|
|
300
|
+
render: renderContext,
|
|
301
|
+
},
|
|
302
|
+
async execute() {
|
|
303
|
+
try {
|
|
304
|
+
const opts = resolveOptions(config)
|
|
305
|
+
const item = await readContext(opts.settingsFile)
|
|
306
|
+
if (item === null) {
|
|
307
|
+
const text = '产出台里还没记下用户打开过哪张图(需要用户先在产出台点开一张大图)。'
|
|
308
|
+
return { found: false, item: { relPath: '', absPath: '' }, text }
|
|
309
|
+
}
|
|
310
|
+
const text = renderContext({}, { found: true, item })[0].text
|
|
311
|
+
return { found: true, item, text }
|
|
312
|
+
} catch (error) {
|
|
313
|
+
const text = `产出台当前状态读取失败:${String(error?.message ?? error)}`
|
|
314
|
+
return { found: false, item: { relPath: '', absPath: '' }, text }
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* 在插件 apply() 里调用。
|
|
321
|
+
* 返回 disposer;任何失败都吞掉并记日志 —— 绝不能因为 tool 注册失败
|
|
322
|
+
* 让整个产出台插件不激活(拖累既有的资产台与全部 op)。
|
|
323
|
+
*/
|
|
324
|
+
export function registerTools(ctx, config) {
|
|
325
|
+
const definitions = [buildToolDefinition(config), buildContextToolDefinition(config)]
|
|
326
|
+
if (!ctx?.tools || typeof ctx.tools.register !== 'function') {
|
|
327
|
+
ctx?.logger?.warn?.('dsh-gallery: ctx.tools 不可用,Agent 工具未注册')
|
|
328
|
+
return () => {}
|
|
329
|
+
}
|
|
330
|
+
const disposers = []
|
|
331
|
+
// 每个工具单独 try/catch:一个注册失败不能拖垮另一个,更不能让整个插件不激活。
|
|
332
|
+
for (const def of definitions) {
|
|
333
|
+
try {
|
|
334
|
+
const dispose = ctx.tools.register(def)
|
|
335
|
+
ctx?.logger?.info?.('dsh-gallery: tool %s 已注册', def.name)
|
|
336
|
+
if (typeof dispose === 'function') disposers.push(dispose)
|
|
337
|
+
} catch (error) {
|
|
338
|
+
ctx?.logger?.warn?.('dsh-gallery: tool %s 未注册(%s)', def.name, error?.message ?? error)
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return () => { for (const d of disposers) { try { d() } catch { /* 忽略 */ } } }
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export { TOOL_NAME, CONTEXT_TOOL_NAME, rootOf, toRow, renderRows, renderContext }
|
package/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 产出台 · DSH 插件 —— Host 半入口。
|
|
3
3
|
*
|
|
4
|
-
* S1
|
|
4
|
+
* S1 拆分后本文件只做四件事:
|
|
5
5
|
* 1. 声明 inject
|
|
6
6
|
* 2. 把 config 交给各模块
|
|
7
7
|
* 3. 注册两条路由
|
|
8
|
+
* 4. 注册 Agent 工具(B1)
|
|
8
9
|
*
|
|
9
10
|
* 实际逻辑分布在 host/ 下:
|
|
10
11
|
* constants.js 常量与默认值
|
|
@@ -16,15 +17,18 @@
|
|
|
16
17
|
* groups.js 按对话分组
|
|
17
18
|
* media.js Range / 流式 / MIME
|
|
18
19
|
* http.js 路由注册
|
|
20
|
+
* tools.js Agent 工具(gallery_find,Host 进程内,模型可直接调用)
|
|
19
21
|
*/
|
|
20
22
|
|
|
21
23
|
import { registerMediaRoute, registerOpsRoute } from './host/http.js'
|
|
24
|
+
import { registerTools } from './host/tools.js'
|
|
22
25
|
|
|
23
|
-
export const inject = ['connection', 'webServer']
|
|
26
|
+
export const inject = ['connection', 'webServer', 'tools']
|
|
24
27
|
|
|
25
28
|
export function apply(ctx, config) {
|
|
26
29
|
registerMediaRoute(ctx, config)
|
|
27
30
|
registerOpsRoute(ctx, config)
|
|
31
|
+
registerTools(ctx, config)
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
// 对外再导出(保持与拆分前的公开接口一致)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-gallery",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "产出台:图片 / 文件 / 音视频实时可见、当场校验;原生产出标签(素材 / 过程稿 / 定稿 / 未归类)可手动改且持久生效,改标签动作与图上圈选批注攒进反馈篮,由人审核合并后发送,全程零自动发送;视频「截取当前帧」自动存入当前对话资产;图上左键画矩形框、右键多点闭合成实心多边形,可导出 ComfyUI 直接可用的 RGBA 遮罩(选区内 alpha=0、RGB 保留原图),另出红 / 绿 / 蓝纯色半透明填充预览图供目视核对;同一张图可连框多处、每处各带说明一并交给 Agent,分类显隐按图片 / 文件 / 音视频各记各的;把图拖进对话框会自动带上文件名与绝对路径(含对应主遮罩名),Agent 不必扫目录找图;批注框跟随图片缩放平移,标注态按住鼠标中键可平移且框不脱框。Output gallery for DeepSeek Harness: live image/file/audio/video preview, persistent manual asset labels, region annotations and label changes queued in a human-approved feedback basket, one-click video frame capture filed into the current session, rectangle and multi-point polygon selections exported as ComfyUI-ready RGBA masks (alpha=0 inside the selection, original RGB kept) plus a colored translucent fill preview, drag-to-chat that carries the file name and absolute path so agents need no directory scan; annotation boxes follow image zoom/pan, and holding the middle mouse button pans the image while annotating without losing the boxes.",
|
|
6
6
|
"repository": {
|