refactor(promptlib): 收藏入口归插件(宿主不再自带,随插件启停)
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 43s
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 43s
按项目所有人要求:提示词库插件负责「管理与收集」的完整能力,宿主只保留基础接口。
宿主侧移除(全部 4 处入口 + 实现):
- 节点气泡星标(app.js 单选气泡的「添加到提示词库」)
- 「选中操作 ▸ 添加到提示词库」、「该节点 ▸ 添加该提示词」
- 提示词节点标题栏星标(src/ui-node-card.js)
- src/runtime-workbench-logic.js 的 addPromptToLibrary(约 45 行)与 ui-canvas-nodes 的 onFavorite 注入
宿主侧保留:promptlib 能力(list/save/insert/copy/notify/onChanged/file*)、prompts 状态与 api('prompts')(备份/迁移)、插件数据通道。
宿主侧补回(此前缺失):右键菜单重新渲染 ctx.commands 注册的插件命令(「插件命令」分区)。
插件 promptlib 1.13.1 → 1.14.0:
- capabilities 增 nodeActions / commands
- nodeActions「收藏为提示词」:仅对 type=prompt 且 text 非空的节点出现(气泡按钮)
- commands「收藏选中的提示词」:右键「插件命令」入口
- 收藏写入插件数据 plugin-data/promptlib.json(以现有数据为基底,保留 cover:{img} 与分组),
新条目 group:'' 即未分组,并 notify 回执
测试:
- tests/iwb-prompt-collect.spec.js 改为 3 条新契约:插件提供气泡入口 + 宿主无自带入口;
右键插件命令可用且宿主旧条目已移除;插件停用后两个入口同时消失
- canvas-meta-notice 的旧「点按钮报错回执」用例改为「宿主不得再渲染该入口」
- tests/_helpers/wait.js openDockPanel 加固(等插件宿主初始化,修并行偶发)
- 棘轮下调:app.js 8324 / Workbench 2178
验证:npm run verify:ci 全绿(含 e2e 冒烟 31 条)。
This commit is contained in:
1 parent
31a89401ff
commit
2cd52d1d4e
14 files changed
+122
-145
No files matched your search
+3
-2
@@ -55,9 +55,10 @@
|
||||
"dir": "promptlib",
|
||||
"main": "main.js",
|
||||
"style": "styles.css",
|
||||
"version": "1.13.1",
|
||||
"version": "1.14.0",
|
||||
"files": {
|
||||
"main.js": "720b8aaa040e0310e6c7d7d2fe1ad6ed0a0e437de77d56bf1a2905355c795e13",
|
||||
"manifest.json": "4d8d6ce8d5ebe6ba2864f0e7f3708492b82561c8467b0c006343cab3cab1f769",
|
||||
"main.js": "e6e9ec6aad1582ae00f23c88a762e84e28ae5403d6739291dd1a44a28e3f49fe",
|
||||
"styles.css": "203d61278ad98b2a07053851d0cfb42dd826564e5ae4d068ec950423cd09c46b"
|
||||
}
|
||||
},
|
||||
|
||||
@@ -2201,12 +2201,40 @@
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 收藏(v1.14.0:宿主不再提供收藏入口,由插件自己注册)=====
|
||||
function plpNotifyCtx (ctx, t, ty) { try { if (ctx.promptlib && ctx.promptlib.notify) ctx.promptlib.notify(t, ty || 'ok') } catch (e) { /* ignore */ } }
|
||||
function plpCollect (ctx, nodeId) {
|
||||
var nodes = []
|
||||
try { nodes = (ctx.canvas && typeof ctx.canvas.getNodes === 'function') ? (ctx.canvas.getNodes() || []) : [] } catch (e) { nodes = [] }
|
||||
var n = null
|
||||
for (var i = 0; i < nodes.length; i++) if (nodes[i] && nodes[i].id === nodeId) { n = nodes[i]; break }
|
||||
var d0 = (n && n.data) || {}
|
||||
var text = String(d0.text || '').trim()
|
||||
var ttl = String(d0.title || '').trim()
|
||||
if (!text) { plpNotifyCtx(ctx, '提示词为空,无法收藏', 'err'); return Promise.resolve({ ok: false }) }
|
||||
var read = (ctx.data && typeof ctx.data.read === 'function') ? Promise.resolve(ctx.data.read()).catch(function () { return {} }) : Promise.resolve({})
|
||||
return read.then(function (d) {
|
||||
if (d && Array.isArray(d.prompts) && d.prompts.length) return { prompts: d.prompts, groups: Array.isArray(d.groups) ? d.groups : [] }
|
||||
return Promise.resolve(ctx.promptlib.list()).then(function (r) { return { prompts: (r && r.prompts) || [], groups: (r && r.groups) || [] } })
|
||||
}).then(function (cur) {
|
||||
var list = cur.prompts.slice()
|
||||
list.push({ id: 'q' + Date.now() + '_' + Math.floor(Math.random() * 1e6), name: ttl || ('提示词 ' + text.slice(0, 8) + '…'), text: text, tags: [], group: '' })
|
||||
var payload = { schemaVersion: 3, prompts: list, groups: cur.groups, updatedAt: Date.now() }
|
||||
var jobs = []
|
||||
if (ctx.data && typeof ctx.data.write === 'function') jobs.push(Promise.resolve(ctx.data.write(payload)).catch(function () {}))
|
||||
if (ctx.promptlib && typeof ctx.promptlib.save === 'function') jobs.push(Promise.resolve(ctx.promptlib.save({ prompts: list, groups: cur.groups })).catch(function () {}))
|
||||
return Promise.all(jobs)
|
||||
}).then(function () { plpNotifyCtx(ctx, '已收藏到未分组'); return { ok: true } })
|
||||
.catch(function () { plpNotifyCtx(ctx, '收藏失败,请重试', 'err'); return { ok: false } })
|
||||
}
|
||||
|
||||
|
||||
global.IWBPluginHost.register({
|
||||
id: 'promptlib',
|
||||
name: '提示词库',
|
||||
version: '1.13.1',
|
||||
version: '1.14.0',
|
||||
apiVersion: 1,
|
||||
capabilities: ['panels', 'promptlib', 'nodeTypes', 'canvas', 'canvasWrite'],
|
||||
capabilities: ['panels', 'promptlib', 'nodeTypes', 'canvas', 'canvasWrite', 'nodeActions', 'commands'],
|
||||
data: { schemaVersion: 3, maxBytes: 4 * 1024 * 1024 },
|
||||
settings: {
|
||||
panel: { type: 'custom', label: '分组与备份', render: renderPluginSettings },
|
||||
@@ -2433,6 +2461,29 @@
|
||||
}
|
||||
}
|
||||
|
||||
// v1.14.0:收藏入口归插件 —— 节点气泡(nodeAction)+ 右键「插件命令」;插件停用即消失
|
||||
if (ctx.nodeActions && typeof ctx.nodeActions.register === 'function') {
|
||||
ctx.nodeActions.register({
|
||||
id: 'collect-prompt',
|
||||
title: '收藏为提示词',
|
||||
icon: 'star',
|
||||
appliesTo: function (node) { return !!node && node.type === 'prompt' && String((node.data && node.data.text) || '').trim() !== '' },
|
||||
run: function (node) { if (node && node.id) plpCollect(ctx, node.id) },
|
||||
})
|
||||
}
|
||||
if (ctx.commands && typeof ctx.commands.register === 'function') {
|
||||
ctx.commands.register({
|
||||
id: 'collect-selected',
|
||||
title: '收藏选中的提示词',
|
||||
icon: 'star',
|
||||
run: function () {
|
||||
var sel = (ctx.canvas && typeof ctx.canvas.getSelectedNode === 'function') ? ctx.canvas.getSelectedNode() : null
|
||||
if (!sel || !sel.id) { plpNotifyCtx(ctx, '先选中一个提示词节点', 'err'); return }
|
||||
plpCollect(ctx, sel.id)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return {}
|
||||
})
|
||||
})(typeof window !== 'undefined' ? window : globalThis)
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "promptlib",
|
||||
"name": "提示词库",
|
||||
"version": "1.13.1",
|
||||
"version": "1.14.0",
|
||||
"apiVersion": 1,
|
||||
"main": "main.js",
|
||||
"style": "styles.css",
|
||||
|
||||
Reference in new issue
Block a user