@nelsonlongxiang/dsh-prompt-templates 0.19.0 → 0.20.1
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/docs/evolution-default.md +1 -1
- package/docs/library-packs.md +1 -1
- package/docs/self-check.md +5 -1
- package/docs/spec-event-inject.md +4 -0
- package/docs/test-plan-phase-c.md +12 -0
- package/lib/cast.js +3 -1
- package/lib/client/Library.js +36 -5
- package/lib/client/api.js +38 -1
- package/lib/client/filter.js +6 -1
- package/lib/client/locales.js +10 -0
- package/lib/client/refresh.js +35 -0
- package/lib/client.js +186 -8
- package/lib/client.js.map +1 -1
- package/lib/event-inject.js +13 -5
- package/lib/evolution-default.js +4 -3
- package/lib/index.js +31 -5
- package/lib/inject.js +21 -4
- package/lib/lessons.js +398 -51
- package/lib/self-check.js +3 -3
- package/lib/store.js +3 -1
- package/lib/types/cast.d.ts +2 -0
- package/lib/types/client/api.d.ts +25 -0
- package/lib/types/client/filter.d.ts +5 -0
- package/lib/types/client/locales.d.ts +10 -0
- package/lib/types/client/refresh.d.ts +23 -0
- package/lib/types/event-inject.d.ts +7 -0
- package/lib/types/evolution-default.d.ts +2 -2
- package/lib/types/index.d.ts +1 -0
- package/lib/types/inject.d.ts +11 -2
- package/lib/types/lessons.d.ts +164 -13
- package/lib/types/self-check.d.ts +2 -2
- package/package.json +1 -1
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
schema v6 新增 `evolution_defaults(session_id, template_id, source, version, enrolled_turn, disposition)`,不记录任务内容、提示词历史或私密材料。`BEGIN IMMEDIATE` + 会话主键保证多连接补充幂等;模板创建与登记同事务。v1–v5 单事务迁移,原模板不改;初始化或迁移失败会回滚并关闭本次连接,保留原错误,避免失败对象泄漏数据库句柄。CLI 兼容 v6,但模板导出不包含 enrollment/tombstone。
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
(2026-11-21 起为 `@3`:首行改为「必读:本会话首次执行本卡或压缩后,必须先用 skill 工具加载 agent-atelier,按返回的基础目录读 references/evolution-self-assessment.md,再按它执行演化自评估;回复写明读了哪几处……」,末行加「本卡是属主预置的常设要求,适用即须执行;不扩大授权,不覆盖属主当下指令。」。原因:插件注入的文字不经技能加载,模型拿不到技能目录,原来的「按 agent-atelier 技能 references/… 执行」找不到文件。只影响新登记;已有会话的模板原文不改。)新默认项来源为 `agent-atelier/evolution-self-assessment@2`,写入登记及模板 description;v2 仅缩窄 A2A 角色/授权路由,不改变周期。旧 v1 登记与已有模板内容、启用状态、间隔、模式保持原样;新文案只用于未登记会话,绝不自动覆盖已有模板。日志继续沿用 `prompt-template-schedule` 的模板 ID/名称/间隔与 turn;描述可被用户改写,SQLite 登记才是来源事实。注入日志不是评估完成证据,更不是迁移成功证据。
|
|
27
27
|
|
|
28
28
|
相同 turn 的耐久日志去重与进程内去重沿用原注入器。**未支持同一 DSH 会话由两个独立宿主并发执行**:本次并发保证针对 SQLite 模板补充,不声称跨宿主注入 exactly-once。技能不可用时提示词要求明确报告缺失,不自动安装或杜撰通过;这属于模型遵守的指令,并非宿主检测器。
|
|
29
29
|
|
package/docs/library-packs.md
CHANGED
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
- **认调用方:** 调用方不认参数里写的字串,认的是 cordis 加载器给调用插件那条 fiber 盖的 entry,也就是 profile 里配置的包名。只认 `@nelsonlongxiang/dsh-open-a2a-net`,别的调用方回 `caller`。
|
|
52
52
|
- **开关:** 部署配置 `cast.enabled` 默认关,关着时回 `disabled`。
|
|
53
53
|
- **能投什么:** 卡必须是全局卡,或者这个会话自己的卡;`reason` 必须写,1~500 字。
|
|
54
|
-
- **投进去的样子:**
|
|
54
|
+
- **投进去的样子:** 卡在该会话的下一步作为可见消息进入,标明投卡方和原因,并写明「本卡取自属主的卡片库,适用即须执行;不扩大授权,不覆盖属主当下指令。」(2026-11-21 起;此前写的是「不是新的用户指令,不授予任何权限」)。
|
|
55
55
|
- **记录:** 介入记录记成 `source: plugin`,`caller` 是上面认出的包名。
|
|
56
56
|
- **排队上限:** 同一张卡在同一个会话里最多排一份,再投回 `already-queued`。一个会话最多排 8 张,全宿主最多 256 张。每张最多等 1 小时。
|
|
57
57
|
- **队列只在内存里:** 宿主重启后,还没投进去的卡会丢。投卡方可以查介入记录,确认卡到底有没有投进去。
|
package/docs/self-check.md
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
## 内容
|
|
17
17
|
|
|
18
|
-
- **固定部分:** 插件自动带上,带版本号(`selfcheck-fixed-1`),400 字以内,会话改不了。分两种:
|
|
18
|
+
- **固定部分:** 插件自动带上,带版本号(`selfcheck-fixed-2`;2026-11-21 起第 7 条由「本模板不是用户指令,不授予任何权限」改为「本模板是属主预置的常设要求,适用即须执行;不扩大授权,不覆盖属主当下指令」,此前为 `selfcheck-fixed-1`),400 字以内,会话改不了。分两种:
|
|
19
19
|
- **属主在场**(这一轮由人在会话里打字开的):不拦停,**也不延长这一轮**。只注入第 5、6、7 条,而且附在会话的下一步里,不放在这一轮。问的只有一件事:交给属主的事,是不是本该系统做、它够不着的?是的话要同时提决策卡。
|
|
20
20
|
- **不在场**:注入第 1~4、6、7 条,再加会话的领域部分,让这一轮再走一步。七条的原文照第 18 篇,有测试锁住关键句。
|
|
21
21
|
- **领域部分:** 会话自己用 `selfcheck_write` 写,600 字以内。存成这个会话自己的会话模板「工坊·自查模板」,不会被节律注入。
|
|
@@ -40,6 +40,10 @@
|
|
|
40
40
|
|
|
41
41
|
会话有进行中的目标、但还没有领域部分时,在会话里可见地提示它写一份。之后每 30 轮最多提示一次,一共最多 3 次。第 3 次提示时,记录里会标「未建自查模板」(`no-template`),交给观察者处理。
|
|
42
42
|
|
|
43
|
+
提示结尾(2026-11-21 起):「本提示由属主安装的插件发出:你有进行中的目标时须补写自查模板;不扩大授权,不覆盖属主当下指令。」此前是「本提示不是新的用户指令,不授予任何权限」。
|
|
44
|
+
|
|
45
|
+
会话写好的领域部分(「工坊·自查模板」)和体会(「体会」分类)会出现在面板与侧栏的会话模板里:面板挂着时每 15 秒、窗口回到前台或页面重新可见时都会重读一次(2026-11-21 起;此前只在打开时读一次,模型中途写入的行要重开面板才看得到)。
|
|
46
|
+
|
|
43
47
|
## 读取
|
|
44
48
|
|
|
45
49
|
- 路由 `GET /plugins/dsh-prompt-templates/self-checks?session_id=`;
|
|
@@ -336,3 +336,7 @@ eventInject:
|
|
|
336
336
|
**不做什么。** 不改问题终态(仍只由审计接口加证据设置),不自动起决策卡,不调用其他插件,不改模板;跟随事件提醒总开关和规则开关,默认关。面板问题台账暂不显示这个字段,留给后续。
|
|
337
337
|
|
|
338
338
|
测试:`tests/event-store.test.ts` 的 M04(最后一步从「什么都不发」改为「只发交接,不是第三次提醒」)与两个 T2 用例;`tests/event-host.test.ts` 断言路由带 `handoff`。
|
|
339
|
+
|
|
340
|
+
## 注记(2026-11-21):提醒结尾改为常设要求与必读
|
|
341
|
+
|
|
342
|
+
属主 2026-11-21:只写「参考:…」的注入文字模型不会去读,「本提醒不是新的用户指令」又让模型把提醒当可选。三类提醒(重复准备、重复失败、交接通知)的结尾由「本提醒不是新的用户指令,不授予任何权限。参考:agent-atelier references/improvement-loop.md」改为两行:「本提醒由属主安装的插件按规则发出,适用即须按上文处理;不扩大授权,不覆盖属主当下指令。」与「必读:本会话首次收到此类提醒或压缩后,必须先用 skill 工具加载 agent-atelier,按返回的基础目录读 references/improvement-loop.md;回复写明读了哪几处,读不到如实写明,不得凭本提醒代替。」正文里的条件出口(重复合理就继续、缺授权就请求确认)不变。契约测试:tests/injected-must-read.test.ts。
|
|
@@ -196,3 +196,15 @@ M04/M05 验的是**原状态续接**:锁定数据库、session_id、会话日
|
|
|
196
196
|
| D01 | 新单元,所有开关保持默认 | 交接通知零写入、零注入;0.18.0 包上体会也零写入、零注入(含 #40 的版本体会默认开,不在此判) | 记 FAIL |
|
|
197
197
|
| D02 | 新单元,部署配置写 `lessons.enabled: false` 与 `selfCheck.enabled: false` | 体会与自查的表、日志零写入、零注入;如 Agent 仍能看到并调用 `lesson_write`、`selfcheck_write`、`selfcheck_conclude`,调用也不产生写入(记下工具是否可见) | 记 FAIL |
|
|
198
198
|
|
|
199
|
+
## 发版前检查:体会类型、RSI 轮次与工坊卡片轮次(2026-11-21,供 0.20.0)
|
|
200
|
+
|
|
201
|
+
**机器侧(CI 每次都跑)**:`tests/e2e-lessons-real-runtime.test.ts` 在真实 ToolRuntime 上,经 `execute` 调用全部模型工具,跑通:工坊卡注入带卡片轮次行 → 带类型写入关闭卡片轮 → 同类情境唤起开 RSI 轮 → 改写同类关闭(软覆盖、旧文进时间线)→ 下一次卡片轮用 `lesson_none` 关闭 → 提出自定类型、未批准时写入被拒、经路由批准后可写 → 时间线含全部事件 → 路由报出类型、批准状态与每卡产出。真实模型是否照做、面板实际显示不在其内。
|
|
202
|
+
|
|
203
|
+
**真机(属主,约 15 分钟)**:用含该改动的构建、新开会话,依次:
|
|
204
|
+
|
|
205
|
+
1. 发「运行 ./check.sh,失败了就创建它(内容 echo ok)再运行」——应出现消化提示;模型写一条带类型的体会,面板「体会」分类里出现「体会·<类型>」。
|
|
206
|
+
2. 再发「再做一次同样的事」——应出现「【工坊·体会·<类型>|RSI 一轮】」;模型改写这一类后,该行显示「RSI 1/1」。
|
|
207
|
+
3. 发「用 lesson_type_propose 提一个新类型」——面板体会区顶部出现「会话提出新的体会类型」,点「批准」后,模型能用这个类型写入。
|
|
208
|
+
4. 在面板给一张「工坊」分类的卡开注入、间隔设小(如 2),等它注入——消息末尾有「【工坊·卡片轮次】」;模型写体会或调用 lesson_none 后,那张卡的行显示「体会 产出/注入」。
|
|
209
|
+
|
|
210
|
+
四步都对上记 PASS;任何一步不符记 FAIL,附截图与会话日志里对应的工具调用。
|
package/lib/cast.js
CHANGED
|
@@ -42,6 +42,8 @@ export function oneLine(text) {
|
|
|
42
42
|
// Control characters, line and paragraph separators, bidi controls and zero-width characters all become a space (#28 review).
|
|
43
43
|
return text.replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029\u200b-\u200f\u202a-\u202e\u2060-\u2069\ufeff]+/g, ' ').replace(/ {2,}/g, ' ').trim();
|
|
44
44
|
}
|
|
45
|
+
/** Closing line of a cast (owner 2026-11-21): the card comes from the owner's library, so it binds where it applies. */
|
|
46
|
+
export const CAST_BINDING_LINE = '本卡取自属主的卡片库,适用即须执行;不扩大授权,不覆盖属主当下指令。';
|
|
45
47
|
/** The visible message a cast becomes. */
|
|
46
48
|
export function renderCastMessage(turn, step, cards, sessionId) {
|
|
47
49
|
return createUserMessage({
|
|
@@ -51,7 +53,7 @@ export function renderCastMessage(turn, step, cards, sessionId) {
|
|
|
51
53
|
`⚙️ 投卡 · 第 ${String(turn)} 轮 · ${cards.map(card => card.name).join('、')}`,
|
|
52
54
|
'',
|
|
53
55
|
...cards.flatMap(card => [`(投卡方:${card.caller};原因:${card.reason})`, expandTemplateVariables(card.content, { sessionId, turn }), '']),
|
|
54
|
-
|
|
56
|
+
CAST_BINDING_LINE,
|
|
55
57
|
].join('\n').trimEnd(),
|
|
56
58
|
}],
|
|
57
59
|
source: { kind: 'user', scheduled: 'prompt-template-cast', turn, step, templates: cards.map(card => ({ id: card.templateId, name: card.name, caller: card.caller })) },
|
package/lib/client/Library.js
CHANGED
|
@@ -10,13 +10,14 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
10
10
|
*/
|
|
11
11
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
12
12
|
import { IconCopyOutlineRegular, IconDownloadOutlineRegular, IconEditOutlineRegular, IconGlobeOutlineRegular, IconPlusOutlineRegular, IconQueueOutlineRegular, IconSendOutlineRegular, IconTrashOutlineRegular } from '@deepseek-ai/dsh-client-ui-primitives';
|
|
13
|
-
import { listLessonPins, recordManualIntervention, setLessonPinned } from "./api.js";
|
|
13
|
+
import { decideLessonType, listCardStats, listLessonPins, listPendingLessonTypes, recordManualIntervention, setLessonPinned } from "./api.js";
|
|
14
14
|
import { filterTemplateRows, searchableTemplateRows } from "./filter.js";
|
|
15
15
|
import { buildSharePayload, parseSharePayload, planShareImport } from "./share.js";
|
|
16
|
+
import { startLibraryRefresh } from "./refresh.js";
|
|
16
17
|
import { copyShareText } from "./clipboard.js";
|
|
17
18
|
import { GITHUB_REPOSITORY_URL, PLUGIN_VERSION, templateCountLabel } from "./meta.js";
|
|
18
19
|
import css from './Panel.module.css';
|
|
19
|
-
function TemplateRow({ template, onInsert, onSend, onInterject, onEdit, onDelete, onShare, onMakeGlobal, pin, onToggleInject, sortable, onDragStart, onDropOn, t }) {
|
|
20
|
+
function TemplateRow({ template, onInsert, onSend, onInterject, onEdit, onDelete, onShare, onMakeGlobal, pin, cardYield, onToggleInject, sortable, onDragStart, onDropOn, t }) {
|
|
20
21
|
const injectTitle = template.inject_enabled && template.inject_every !== null
|
|
21
22
|
? `${t('panel.inject')} · ${template.inject_every}${template.mode === 'visible' ? ' · ' + t('panel.modeVisible') : ''}`
|
|
22
23
|
: t('panel.inject');
|
|
@@ -26,7 +27,7 @@ function TemplateRow({ template, onInsert, onSend, onInterject, onEdit, onDelete
|
|
|
26
27
|
e.preventDefault();
|
|
27
28
|
e.stopPropagation();
|
|
28
29
|
onDropOn(template.id);
|
|
29
|
-
} }, children: [_jsxs("button", { type: "button", className: css.insert, onClick: () => { onInsert(template); }, title: t('panel.insert'), children: [_jsx("span", { className: css.name, children: template.name }), _jsx("span", { className: css.preview, children: template.content })] }), _jsxs("button", { type: "button", className: template.inject_enabled ? css.injectBtnActive : css.injectBtn, onClick: () => { onToggleInject(template); }, "aria-label": t('panel.inject'), "aria-pressed": template.inject_enabled, title: injectTitle, children: ["\u27F3", template.inject_enabled && template.inject_every !== null ? template.inject_every : ''] }), _jsx("button", { type: "button", className: css.interjectBtn, onClick: () => { onInterject(template); }, "aria-label": t('panel.interject'), title: t('panel.interject'), children: _jsx(IconQueueOutlineRegular, { size: 12 }) }), _jsx("button", { type: "button", className: css.sendBtn, onClick: () => { onSend(template); }, "aria-label": t('panel.sendNow'), title: t('panel.sendNow'), children: _jsx(IconSendOutlineRegular, { size: 12 }) }), _jsx("button", { type: "button", className: css.shareBtn, onClick: (event) => { onShare(template, event.currentTarget); }, "aria-label": t('panel.share'), title: t('panel.share'), children: _jsx(IconCopyOutlineRegular, { size: 12 }) }), onMakeGlobal !== undefined && (_jsx("button", { type: "button", className: css.globalBtn, onClick: () => { onMakeGlobal(template.id); }, "aria-label": t('panel.makeGlobal'), title: t('panel.makeGlobal'), children: _jsx(IconGlobeOutlineRegular, { size: 12 }) })), pin !== undefined && (_jsx("button", { type: "button", className: pin.pinned ? css.injectBtnActive : css.injectBtn, onClick: () => { pin.onToggle(); }, "aria-label": pin.pinned ? t('panel.unpin') : t('panel.pin'), "aria-pressed": pin.pinned, title: pin.pinned ? t('panel.unpin') : t('panel.pin'), children: "\uD83D\uDCCC" })), _jsx("button", { type: "button", className: css.editBtn, onClick: () => { onEdit(template.id); }, "aria-label": t('panel.edit'), title: t('panel.edit'), children: _jsx(IconEditOutlineRegular, { size: 12 }) }), _jsx("button", { type: "button", className: css.deleteBtn, onClick: () => { onDelete(template.id); }, "aria-label": t('panel.delete'), children: _jsx(IconTrashOutlineRegular, { size: 12 }) })] }));
|
|
30
|
+
} }, children: [_jsxs("button", { type: "button", className: css.insert, onClick: () => { onInsert(template); }, title: t('panel.insert'), children: [_jsx("span", { className: css.name, children: template.name }), _jsx("span", { className: css.preview, children: template.content })] }), _jsxs("button", { type: "button", className: template.inject_enabled ? css.injectBtnActive : css.injectBtn, onClick: () => { onToggleInject(template); }, "aria-label": t('panel.inject'), "aria-pressed": template.inject_enabled, title: injectTitle, children: ["\u27F3", template.inject_enabled && template.inject_every !== null ? template.inject_every : ''] }), _jsx("button", { type: "button", className: css.interjectBtn, onClick: () => { onInterject(template); }, "aria-label": t('panel.interject'), title: t('panel.interject'), children: _jsx(IconQueueOutlineRegular, { size: 12 }) }), _jsx("button", { type: "button", className: css.sendBtn, onClick: () => { onSend(template); }, "aria-label": t('panel.sendNow'), title: t('panel.sendNow'), children: _jsx(IconSendOutlineRegular, { size: 12 }) }), _jsx("button", { type: "button", className: css.shareBtn, onClick: (event) => { onShare(template, event.currentTarget); }, "aria-label": t('panel.share'), title: t('panel.share'), children: _jsx(IconCopyOutlineRegular, { size: 12 }) }), onMakeGlobal !== undefined && (_jsx("button", { type: "button", className: css.globalBtn, onClick: () => { onMakeGlobal(template.id); }, "aria-label": t('panel.makeGlobal'), title: t('panel.makeGlobal'), children: _jsx(IconGlobeOutlineRegular, { size: 12 }) })), pin !== undefined && (_jsx("button", { type: "button", className: pin.pinned ? css.injectBtnActive : css.injectBtn, onClick: () => { pin.onToggle(); }, "aria-label": pin.pinned ? t('panel.unpin') : t('panel.pin'), "aria-pressed": pin.pinned, title: pin.pinned ? t('panel.unpin') : t('panel.pin'), children: "\uD83D\uDCCC" })), cardYield !== undefined && cardYield.injected > 0 && (_jsxs("span", { className: css.injectBadge, title: t('panel.cardYield').replace('{injected}', String(cardYield.injected)).replace('{lessons}', String(cardYield.lessons)).replace('{none}', String(cardYield.none)).replace('{missed}', String(cardYield.missed)), children: ["\u4F53\u4F1A ", cardYield.lessons, "/", cardYield.injected] })), pin?.rounds !== undefined && pin.rounds.opened > 0 && (_jsxs("span", { className: css.injectBadge, title: t('panel.rounds').replace('{opened}', String(pin.rounds.opened)).replace('{closed}', String(pin.rounds.closed)).replace('{missed}', String(pin.rounds.missed)), children: ["RSI ", pin.rounds.closed, "/", pin.rounds.opened] })), _jsx("button", { type: "button", className: css.editBtn, onClick: () => { onEdit(template.id); }, "aria-label": t('panel.edit'), title: t('panel.edit'), children: _jsx(IconEditOutlineRegular, { size: 12 }) }), _jsx("button", { type: "button", className: css.deleteBtn, onClick: () => { onDelete(template.id); }, "aria-label": t('panel.delete'), children: _jsx(IconTrashOutlineRegular, { size: 12 }) })] }));
|
|
30
31
|
}
|
|
31
32
|
/** The template inline form: creation (with scope + category pickers) and in-place edit. */
|
|
32
33
|
function TemplateForm({ initial, allowScope, sessionId, categories, t, submitLabel, onSubmit, onDone, onCancel }) {
|
|
@@ -142,6 +143,13 @@ export function TemplateLibrary({ sessionId, face, t, header, headerExtra }) {
|
|
|
142
143
|
void load();
|
|
143
144
|
void loadCategories();
|
|
144
145
|
}, [load, loadCategories]);
|
|
146
|
+
// Rows the agent writes with its own tools (selfcheck_write, lesson_write) land server-side while this library stays
|
|
147
|
+
// mounted; re-read rows and categories on a timer, on focus and on visibility, and whenever the target session changes.
|
|
148
|
+
useEffect(() => {
|
|
149
|
+
void load();
|
|
150
|
+
void loadCategories();
|
|
151
|
+
return startLibraryRefresh(() => { void load(); void loadCategories(); });
|
|
152
|
+
}, [load, loadCategories, sessionId]);
|
|
145
153
|
// Toolbar badge `⟳N`: the target session's latest scheduled injection,
|
|
146
154
|
// polled every 30s (and re-read whenever the target changes). null hides
|
|
147
155
|
// the badge — the route is memory-only, so polling stays O(1).
|
|
@@ -249,15 +257,38 @@ export function TemplateLibrary({ sessionId, face, t, header, headerExtra }) {
|
|
|
249
257
|
}, [sessionId]);
|
|
250
258
|
// 体会 pins (phase 2): only the session's own lessons get the toggle; the host enforces the quota.
|
|
251
259
|
const [lessonPins, setLessonPins] = useState(new Map());
|
|
260
|
+
const [lessonRounds, setLessonRounds] = useState(new Map());
|
|
252
261
|
const loadLessonPins = useCallback(async () => {
|
|
253
262
|
if (sessionId === null) {
|
|
254
263
|
setLessonPins(new Map());
|
|
264
|
+
setLessonRounds(new Map());
|
|
255
265
|
return;
|
|
256
266
|
}
|
|
257
267
|
const items = await listLessonPins(sessionId);
|
|
258
268
|
setLessonPins(new Map(items.map(item => [item.id, item.pinned])));
|
|
269
|
+
setLessonRounds(new Map(items.map(item => [item.id, item.rounds])));
|
|
259
270
|
}, [sessionId]);
|
|
260
271
|
useEffect(() => { void loadLessonPins(); }, [loadLessonPins, templates]);
|
|
272
|
+
// Workshop-card yields in this session (card rounds): shown on the card rows.
|
|
273
|
+
const [cardYields, setCardYields] = useState(new Map());
|
|
274
|
+
const loadCardYields = useCallback(async () => {
|
|
275
|
+
setCardYields(new Map(sessionId === null ? [] : (await listCardStats(sessionId)).map(card => [card.template_id, card])));
|
|
276
|
+
}, [sessionId]);
|
|
277
|
+
useEffect(() => { void loadCardYields(); }, [loadCardYields, templates]);
|
|
278
|
+
// Lesson types the session proposed (lesson_type_propose): only the owner approves them, here.
|
|
279
|
+
const [pendingTypes, setPendingTypes] = useState([]);
|
|
280
|
+
const loadPendingTypes = useCallback(async () => {
|
|
281
|
+
setPendingTypes(sessionId === null ? [] : await listPendingLessonTypes(sessionId));
|
|
282
|
+
}, [sessionId]);
|
|
283
|
+
useEffect(() => { void loadPendingTypes(); }, [loadPendingTypes, templates]);
|
|
284
|
+
const handleDecideType = useCallback(async (name, approved) => {
|
|
285
|
+
if (sessionId === null)
|
|
286
|
+
return;
|
|
287
|
+
const result = await decideLessonType(sessionId, name, approved);
|
|
288
|
+
if (!result.ok)
|
|
289
|
+
setNotice(result.error.message);
|
|
290
|
+
await loadPendingTypes();
|
|
291
|
+
}, [sessionId, loadPendingTypes]);
|
|
261
292
|
const handleTogglePin = useCallback(async (id) => {
|
|
262
293
|
const result = await setLessonPinned(id, lessonPins.get(id) !== true);
|
|
263
294
|
if (!result.ok)
|
|
@@ -472,7 +503,7 @@ export function TemplateLibrary({ sessionId, face, t, header, headerExtra }) {
|
|
|
472
503
|
});
|
|
473
504
|
return result.ok;
|
|
474
505
|
}, onDone: () => { setEditingId(null); void load(); }, onCancel: () => { setEditingId(null); } }, row.id))
|
|
475
|
-
: (_jsx(TemplateRow, { template: row, onInsert: (c) => { handleInsert(c); }, onSend: (c) => { handleSend(c); }, onInterject: (c) => { handleInterject(c); }, onEdit: (id) => { setEditingId(id); }, onDelete: (id) => { void handleRemove(id); }, onShare: (tpl, trigger) => { void handleShareTemplate(tpl, trigger); }, onMakeGlobal: row.scope === 'session' ? (id) => { void handleMakeGlobal(id); } : undefined, pin: lessonPins.has(row.id) ? { pinned: lessonPins.get(row.id) === true, onToggle: () => { void handleTogglePin(row.id); } } : undefined, onToggleInject: (tpl) => { void handleToggleInject(tpl); }, sortable: needle === '', onDragStart: (id) => { dragRowRef.current = id; }, onDropOn: (id) => { handleRowDrop(id); }, t: t }, row.id)));
|
|
506
|
+
: (_jsx(TemplateRow, { template: row, onInsert: (c) => { handleInsert(c); }, onSend: (c) => { handleSend(c); }, onInterject: (c) => { handleInterject(c); }, onEdit: (id) => { setEditingId(id); }, onDelete: (id) => { void handleRemove(id); }, onShare: (tpl, trigger) => { void handleShareTemplate(tpl, trigger); }, onMakeGlobal: row.scope === 'session' ? (id) => { void handleMakeGlobal(id); } : undefined, pin: lessonPins.has(row.id) ? { pinned: lessonPins.get(row.id) === true, onToggle: () => { void handleTogglePin(row.id); }, rounds: lessonRounds.get(row.id) } : undefined, cardYield: cardYields.get(row.id), onToggleInject: (tpl) => { void handleToggleInject(tpl); }, sortable: needle === '', onDragStart: (id) => { dragRowRef.current = id; }, onDropOn: (id) => { handleRowDrop(id); }, t: t }, row.id)));
|
|
476
507
|
return (_jsxs("div", { className: css.library, "data-prompt-library": true, children: [_jsxs("div", { className: header !== undefined ? `${css.toolbar} ${css.toolbarDraggable}` : css.toolbar, title: header?.hint, onPointerDown: header?.onPointerDown, onPointerMove: header?.onPointerMove, onPointerUp: header?.onPointerUp, onDoubleClick: header?.onDoubleClick, children: [_jsxs("span", { className: css.titleGroup, children: [_jsx("span", { className: css.title, children: t('panel.title') }), _jsx("span", { className: css.countBadge, "data-template-count": true, title: needle !== '' ? t('panel.searchCount') : t('panel.tabCount'), children: countLabel }), injected !== null && (_jsxs("button", { type: "button", className: `${css.injectBadge} ${css.injectBadgeButton}`, "data-prompt-injected": true, title: `${t('panel.injectedAt')} ${injected.turn} · ${new Date(injected.at).toLocaleTimeString()} · ${injected.templates.join(', ')}`, "aria-label": t('panel.historyTitle'), "aria-expanded": historyOpen, onClick: () => { setHistoryOpen(open => !open); }, children: ["\u27F3", injected.turn] })), _jsx("button", { type: "button", className: css.importBtn, onClick: () => { setShowImport(v => !v); }, "aria-label": t('panel.import'), "aria-expanded": showImport, title: t('panel.import'), children: _jsx(IconDownloadOutlineRegular, { size: 12 }) }), _jsx("button", { type: "button", className: css.importBtn, "data-prompt-events-toggle": true, onClick: () => { setEventsOpen(open => !open); }, "aria-label": t('panel.eventsTitle'), "aria-expanded": eventsOpen, title: t('panel.eventsTitle'), children: "\u2699" })] }), headerExtra] }), notice !== null && _jsx("div", { className: css.notice, role: "status", children: notice }), manualShare !== null && (_jsxs("section", { className: css.importForm, "data-prompt-share-manual": true, "aria-label": t('panel.shareManualTitle'), children: [_jsxs("div", { role: "status", children: [t(manualShare.failure.kind === 'unavailable' ? 'panel.copyUnavailable'
|
|
477
508
|
: manualShare.failure.kind === 'unfocused' ? 'panel.copyUnfocused'
|
|
478
509
|
: manualShare.failure.kind === 'denied' ? 'panel.copyDenied'
|
|
@@ -495,7 +526,7 @@ export function TemplateLibrary({ sessionId, face, t, header, headerExtra }) {
|
|
|
495
526
|
}
|
|
496
527
|
})();
|
|
497
528
|
}, children: "\u00D7" })] }, key));
|
|
498
|
-
}), _jsx("button", { type: "button", className: css.tabAdd, "aria-label": t('panel.newCategory'), title: t('panel.newCategory'), onClick: () => { setShowCatForm(v => !v); }, children: _jsx(IconPlusOutlineRegular, { size: 10 }) })] }), showCatForm && (_jsx(CategoryForm, { sessionId: sessionId, createCategory: createCategory, t: t, onDone: () => { setShowCatForm(false); void loadCategories(); } })), _jsxs("div", { className: css.body, children: [rowError !== null && (_jsxs("div", { className: css.error, role: "alert", "data-prompt-row-error": true, children: [t('panel.error'), " \u00B7 ", rowError] })), tabRows.length === 0 && !showAdd && !showCatForm && (_jsx("div", { className: css.empty, children: needle !== '' ? t('panel.noMatch') : t('panel.empty') })), tabRows.length > 0 && (_jsx("div", { className: css.group, onDragOver: (e) => { e.preventDefault(); }, children: tabRows.map(row => renderTemplateRow(row)) })), showAdd && (_jsx(TemplateForm, { sessionId: sessionId, categories: visibleCategories, t: t, allowScope: true, submitLabel: t('panel.addSave'), onSubmit: async (name, content, scope, category, injectEnabled, injectEvery, mode) => {
|
|
529
|
+
}), _jsx("button", { type: "button", className: css.tabAdd, "aria-label": t('panel.newCategory'), title: t('panel.newCategory'), onClick: () => { setShowCatForm(v => !v); }, children: _jsx(IconPlusOutlineRegular, { size: 10 }) })] }), showCatForm && (_jsx(CategoryForm, { sessionId: sessionId, createCategory: createCategory, t: t, onDone: () => { setShowCatForm(false); void loadCategories(); } })), _jsxs("div", { className: css.body, children: [rowError !== null && (_jsxs("div", { className: css.error, role: "alert", "data-prompt-row-error": true, children: [t('panel.error'), " \u00B7 ", rowError] })), pendingTypes.map(type => (_jsxs("div", { className: css.notice, "data-prompt-lesson-type": type.name, children: [t('panel.typeProposed'), "\u300C", type.name, "\u300D\uFF1A", type.description, ' ', _jsx("button", { type: "button", onClick: () => { void handleDecideType(type.name, true); }, children: t('panel.typeApprove') }), ' ', _jsx("button", { type: "button", onClick: () => { void handleDecideType(type.name, false); }, children: t('panel.typeReject') })] }, type.name))), tabRows.length === 0 && !showAdd && !showCatForm && (_jsx("div", { className: css.empty, children: needle !== '' ? t('panel.noMatch') : t('panel.empty') })), tabRows.length > 0 && (_jsx("div", { className: css.group, onDragOver: (e) => { e.preventDefault(); }, children: tabRows.map(row => renderTemplateRow(row)) })), showAdd && (_jsx(TemplateForm, { sessionId: sessionId, categories: visibleCategories, t: t, allowScope: true, submitLabel: t('panel.addSave'), onSubmit: async (name, content, scope, category, injectEnabled, injectEvery, mode) => {
|
|
499
530
|
const result = await create({
|
|
500
531
|
name,
|
|
501
532
|
content,
|
package/lib/client/api.js
CHANGED
|
@@ -105,12 +105,49 @@ export async function listLessonPins(sessionId) {
|
|
|
105
105
|
if (!response.ok)
|
|
106
106
|
return [];
|
|
107
107
|
const body = await response.json();
|
|
108
|
-
|
|
108
|
+
const n = (v) => typeof v === 'number' && Number.isFinite(v) ? v : 0;
|
|
109
|
+
return (body.items ?? []).filter(item => typeof item.id === 'string').map(item => ({
|
|
110
|
+
id: item.id, pinned: item.pinned === true,
|
|
111
|
+
rounds: { opened: n(item.rounds?.opened), closed: n(item.rounds?.closed), missed: n(item.rounds?.missed) },
|
|
112
|
+
}));
|
|
109
113
|
}
|
|
110
114
|
catch {
|
|
111
115
|
return [];
|
|
112
116
|
}
|
|
113
117
|
}
|
|
118
|
+
/** A session's workshop-card yields (empty when none, unavailable, or the host predates card rounds). */
|
|
119
|
+
export async function listCardStats(sessionId) {
|
|
120
|
+
try {
|
|
121
|
+
const response = await fetch(`${BASE}/lessons?session_id=${encodeURIComponent(sessionId)}`, { cache: 'no-store' });
|
|
122
|
+
if (!response.ok)
|
|
123
|
+
return [];
|
|
124
|
+
const body = await response.json();
|
|
125
|
+
const n = (v) => typeof v === 'number' && Number.isFinite(v) ? v : 0;
|
|
126
|
+
return (body.cards ?? []).filter(card => typeof card['template_id'] === 'string')
|
|
127
|
+
.map(card => ({ template_id: card['template_id'], injected: n(card['injected']), lessons: n(card['lessons']), none: n(card['none']), missed: n(card['missed']) }));
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return [];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/** The session's proposed lesson types still waiting for the owner (empty when none or unavailable). */
|
|
134
|
+
export async function listPendingLessonTypes(sessionId) {
|
|
135
|
+
try {
|
|
136
|
+
const response = await fetch(`${BASE}/lessons?session_id=${encodeURIComponent(sessionId)}`, { cache: 'no-store' });
|
|
137
|
+
if (!response.ok)
|
|
138
|
+
return [];
|
|
139
|
+
const body = await response.json();
|
|
140
|
+
return (body.types ?? []).filter(type => type.builtin !== true && type.status === 'pending' && typeof type.name === 'string')
|
|
141
|
+
.map(type => ({ name: type.name, description: typeof type.description === 'string' ? type.description : '' }));
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return [];
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/** The owner approves or rejects a proposed lesson type of one session. */
|
|
148
|
+
export function decideLessonType(sessionId, name, approved) {
|
|
149
|
+
return mutate('PATCH', `/lesson-types/${encodeURIComponent(name)}?session_id=${encodeURIComponent(sessionId)}`, { approved });
|
|
150
|
+
}
|
|
114
151
|
/** The owner pins or unpins one lesson; a full pin quota settles as error code `pinned-full`. */
|
|
115
152
|
export function setLessonPinned(templateId, pinned) {
|
|
116
153
|
return mutate('PATCH', `/lessons/${encodeURIComponent(templateId)}`, { pinned });
|
package/lib/client/filter.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The category the host files lessons (体会) under (server `LESSON_CATEGORY`). Owner 2026-11-21 on 0.20.0: lessons did
|
|
3
|
+
* not show in the 会话模板 tab — they sat only in their own 体会 tab. The session tab now lists them too; the 体会 tab stays.
|
|
4
|
+
*/
|
|
5
|
+
export const LESSON_TAB_CATEGORY = '体会';
|
|
1
6
|
/**
|
|
2
7
|
* Filter the panel's rows. A non-empty query is global across every category
|
|
3
8
|
* while respecting privacy: every global template and only the current
|
|
@@ -18,7 +23,7 @@ export function filterTemplateRows(templates, query, effectiveTab, activeCategor
|
|
|
18
23
|
if (effectiveTab === 'global')
|
|
19
24
|
return row.scope === 'global' && row.category === null;
|
|
20
25
|
if (effectiveTab === 'session')
|
|
21
|
-
return row.scope === 'session' && row.session_id === sessionId && row.category === null;
|
|
26
|
+
return row.scope === 'session' && row.session_id === sessionId && (row.category === null || row.category === LESSON_TAB_CATEGORY);
|
|
22
27
|
return activeCategory !== undefined
|
|
23
28
|
&& row.category === activeCategory.name
|
|
24
29
|
&& row.scope === activeCategory.scope
|
package/lib/client/locales.js
CHANGED
|
@@ -35,6 +35,11 @@ export const zh = {
|
|
|
35
35
|
'panel.pin': '设为常驻体会(会话开始、恢复和压缩后装载)',
|
|
36
36
|
'panel.unpin': '取消常驻',
|
|
37
37
|
'panel.pinFull': '常驻体会已达上限,先取消一条再设',
|
|
38
|
+
'panel.rounds': 'RSI 轮次:唤起 {opened},已闭合 {closed},未闭合 {missed}',
|
|
39
|
+
'panel.typeProposed': '会话提出新的体会类型',
|
|
40
|
+
'panel.cardYield': '本会话里这张工坊卡:注入 {injected},产出体会 {lessons},无可记 {none},未闭合 {missed}',
|
|
41
|
+
'panel.typeApprove': '批准',
|
|
42
|
+
'panel.typeReject': '拒绝',
|
|
38
43
|
'panel.inject': '定时注入',
|
|
39
44
|
'panel.injectEvery': '注入间隔(轮)',
|
|
40
45
|
'panel.variablesHint': '支持变量:{{date}} {{time}} {{datetime}} {{weekday}} {{session}} {{turn}}(发送/注入时展开,不可得时保留原文)',
|
|
@@ -116,6 +121,11 @@ export const en = {
|
|
|
116
121
|
'panel.pin': 'Pin this lesson (loaded at session start, resume and after compaction)',
|
|
117
122
|
'panel.unpin': 'Unpin',
|
|
118
123
|
'panel.pinFull': 'Pinned lessons are at the limit; unpin one first',
|
|
124
|
+
'panel.rounds': 'RSI rounds: recalled {opened}, closed {closed}, missed {missed}',
|
|
125
|
+
'panel.typeProposed': 'The session proposes a new lesson type',
|
|
126
|
+
'panel.cardYield': 'This workshop card in this session: injected {injected}, lessons {lessons}, no entry {none}, missed {missed}',
|
|
127
|
+
'panel.typeApprove': 'Approve',
|
|
128
|
+
'panel.typeReject': 'Reject',
|
|
119
129
|
'panel.inject': 'Auto-inject',
|
|
120
130
|
'panel.injectEvery': 'Every (rounds)',
|
|
121
131
|
'panel.variablesHint': 'Variables: {{date}} {{time}} {{datetime}} {{weekday}} {{session}} {{turn}} (expanded at delivery; unresolved stay literal)',
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keep the template library current while it stays mounted (owner 2026-11-21: a self-check template or a lesson the
|
|
3
|
+
* model wrote with its tools never showed in the session tab). The library used to read the rows once on mount, and
|
|
4
|
+
* the sidebar tab stays mounted for the whole conversation, so rows the agent wrote server-side never arrived. This
|
|
5
|
+
* re-reads on a timer, when the window regains focus, and when the page becomes visible again.
|
|
6
|
+
* @module @nelsonlongxiang/dsh-prompt-templates/client/refresh
|
|
7
|
+
*/
|
|
8
|
+
/** How often the mounted library re-reads its rows, in milliseconds. */
|
|
9
|
+
export const LIBRARY_REFRESH_MS = 15_000;
|
|
10
|
+
/**
|
|
11
|
+
* Start re-reading. `reload` is called on every tick, on window focus and when the document turns visible; never while
|
|
12
|
+
* it is hidden. Returns the stop function for an effect cleanup.
|
|
13
|
+
*/
|
|
14
|
+
export function startLibraryRefresh(reload, targets = defaultTargets(), intervalMs = LIBRARY_REFRESH_MS) {
|
|
15
|
+
const doc = targets.document;
|
|
16
|
+
const visible = () => doc?.visibilityState === undefined || doc.visibilityState === 'visible';
|
|
17
|
+
const tick = () => { if (visible())
|
|
18
|
+
reload(); };
|
|
19
|
+
const onVisibility = () => { if (visible())
|
|
20
|
+
reload(); };
|
|
21
|
+
const set = targets.setInterval ?? ((fn, ms) => globalThis.setInterval(fn, ms));
|
|
22
|
+
const clear = targets.clearInterval ?? ((handle) => { globalThis.clearInterval(handle); });
|
|
23
|
+
const handle = set(tick, intervalMs);
|
|
24
|
+
targets.window?.addEventListener('focus', tick);
|
|
25
|
+
doc?.addEventListener('visibilitychange', onVisibility);
|
|
26
|
+
return () => {
|
|
27
|
+
clear(handle);
|
|
28
|
+
targets.window?.removeEventListener('focus', tick);
|
|
29
|
+
doc?.removeEventListener('visibilitychange', onVisibility);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function defaultTargets() {
|
|
33
|
+
const g = globalThis;
|
|
34
|
+
return { window: g.window, document: g.document };
|
|
35
|
+
}
|