@nelsonlongxiang/dsh-prompt-templates 0.15.0 → 0.17.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/docs/library-packs.md +60 -0
- package/docs/self-check.md +73 -0
- package/docs/spec-event-inject.md +5 -4
- package/lib/cast.js +170 -0
- package/lib/cli/database.js +3 -3
- package/lib/client/Library.js +13 -8
- package/lib/client/api.js +10 -0
- package/lib/client/locales.js +2 -0
- package/lib/client.js +118 -95
- package/lib/client.js.map +1 -1
- package/lib/event-inject.js +34 -1
- package/lib/event-store.js +10 -3
- package/lib/index.js +80 -2
- package/lib/inject.js +16 -2
- package/lib/interventions.js +85 -0
- package/lib/self-check.js +314 -0
- package/lib/store.js +148 -4
- package/lib/types/cast.d.ts +93 -0
- package/lib/types/client/api.d.ts +7 -0
- package/lib/types/client/locales.d.ts +2 -0
- package/lib/types/event-inject.d.ts +13 -1
- package/lib/types/event-store.d.ts +7 -0
- package/lib/types/index.d.ts +19 -0
- package/lib/types/interventions.d.ts +73 -0
- package/lib/types/self-check.d.ts +137 -0
- package/lib/types/store.d.ts +70 -2
- package/lib/types/types.d.ts +7 -0
- package/package.json +5 -2
- package/packs/atelier-5.16.1.json +75 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# 卡库版本包(library pack)
|
|
2
|
+
|
|
3
|
+
0.16 起(schema v9),模板带版本号 `version`。版本包是一份带版本的卡库文件,把某个来源(例如 agent-atelier 的七张卡)的现行文字打成一个可导入的版本。
|
|
4
|
+
|
|
5
|
+
## 格式
|
|
6
|
+
|
|
7
|
+
```json
|
|
8
|
+
{ "format": "dsh-prompt-templates-library", "version": "atelier-5.16.1",
|
|
9
|
+
"source": { "package": "agent-atelier", "version": "5.16.1", "commit": "<sha>", "path": "assets/injection-templates.json" },
|
|
10
|
+
"templates": [ { "id": "…", "name": "…", "content": "…", "description": "…", "position": 0, "inject_every": 26, "mode": "visible" } ] }
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
每张卡也可以带自己的 `version`;不带的用包的 `version`。
|
|
14
|
+
|
|
15
|
+
## 导入只存新版本,不切换(第 1 期,workbench-market #883)
|
|
16
|
+
|
|
17
|
+
- 每张卡在宿主上有一份**生效正文**(`templates.content`),以及指向它版本的**生效版本指针**(`templates.version`)。节律注入和面板手动发用的都是生效正文。
|
|
18
|
+
- 导入把包里的每张卡存成卡库里的**一个新版本**(`template_versions` 表),和旧版并存。**导入从不改生效正文和生效版本指针**,`apply: true` 也一样,所以节律注入的照旧是旧版正文。
|
|
19
|
+
- 卡按 `id` 匹配;找不到时,再找同名的全局卡。这台宿主没有的卡,只存版本,不建模板:它出现在卡库里(`stored_only: true`),但面板和节律都发不出去。
|
|
20
|
+
- 同一版本、正文没变的不重写,记为 `unchanged`。
|
|
21
|
+
- 把某张卡切到已存的新版本,是第 3 期的事,要走决策卡,由属主同意;第 1 期没有切换入口。
|
|
22
|
+
- 人改了生效正文却没同时指定 `version`,生效版本指针会被清空,表示它已经不是任何包里的版本。
|
|
23
|
+
|
|
24
|
+
## 导入步骤
|
|
25
|
+
|
|
26
|
+
1. 在要导入的宿主上,确认插件是 0.16 或更高:`GET /plugins/dsh-prompt-templates/library` 返回 `schema` ≥ 9。
|
|
27
|
+
2. 预演,不写入:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
jq -n --slurpfile p packs/atelier-5.16.1.json '{pack: $p[0]}' | curl -s -X POST http://127.0.0.1:<端口>/plugins/dsh-prompt-templates/library/import -H 'content-type: application/json' -d @-
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
看返回的 `plan`:`stored`(这次会存的新版本,每条带 `active_version` 当前生效版本和 `new_card`)、`unchanged`。
|
|
34
|
+
3. 确认无误后正式导入:同一条命令,把 `{pack: $p[0]}` 改成 `{pack: $p[0], apply: true}`。返回 `plan.applied: true`。
|
|
35
|
+
4. 用 `GET /plugins/dsh-prompt-templates/library` 读回:每张卡的 `stored_versions` 里有 `atelier-5.16.1`,而 `active_version`、`content_sha256`、`inject_enabled`、`inject_every` 都和导入前一样。
|
|
36
|
+
|
|
37
|
+
## 读取面(只读)
|
|
38
|
+
|
|
39
|
+
- `GET /plugins/dsh-prompt-templates/library`:卡库,返回名称、生效版本、范围、开关、间隔、模式、生效正文摘要(`content_sha256`)和已存的版本列表,不含正文。加 `?session_id=<会话>` 只返回这个会话自己的模板(会话级模板,范围 `session`),比如它自己配的自查模板;没有就返回空列表。写会话级模板的工具留到第 2 期,第 1 期只读。
|
|
40
|
+
- `GET /plugins/dsh-prompt-templates/interventions?session_id=&since=&source=&limit=`:介入记录,按时间从旧到新。
|
|
41
|
+
- `source` 取 `schedule`(按轮次)、`event`(按事件)、`manual`(人在面板上手动发,`method` 分 `insert`、`send`、`interject`)、`plugin`(别的插件发起,留给第 2 期;第 2 期的投卡服务只接受 a2a 插件,记录里的 `caller` 字段写调用方,认不出的调用方被拒)。
|
|
42
|
+
- 每条只记模板的标识、版本、所发文字的 sha256、会话、轮、步和时间,不记会话里的其他内容。
|
|
43
|
+
- 手动发的记录没有轮和步,因为面板看不到 agent 当时走到哪一步。
|
|
44
|
+
|
|
45
|
+
## 给其他插件的服务(第 2 期,PT-3)
|
|
46
|
+
|
|
47
|
+
同一宿主上的其他插件通过 `ctx.promptTemplates` 使用:
|
|
48
|
+
|
|
49
|
+
- **只读,所有插件都能用:** `library()`、`templates(sessionId)`、`interventions({ sessionId, since, source, limit })`。返回的形状和只读路由一样,只给摘要,不给正文。
|
|
50
|
+
- **投卡:** `cast({ sessionId, templateId, reason })`。
|
|
51
|
+
- **认调用方:** 调用方不认参数里写的字串,认的是 cordis 加载器给调用插件那条 fiber 盖的 entry,也就是 profile 里配置的包名。只认 `@nelsonlongxiang/dsh-open-a2a-net`,别的调用方回 `caller`。
|
|
52
|
+
- **开关:** 部署配置 `cast.enabled` 默认关,关着时回 `disabled`。
|
|
53
|
+
- **能投什么:** 卡必须是全局卡,或者这个会话自己的卡;`reason` 必须写,1~500 字。
|
|
54
|
+
- **投进去的样子:** 卡在该会话的下一步作为可见消息进入,标明投卡方和原因,并写明「不是新的用户指令,不授予任何权限」。
|
|
55
|
+
- **记录:** 介入记录记成 `source: plugin`,`caller` 是上面认出的包名。
|
|
56
|
+
- **排队上限:** 同一张卡在同一个会话里最多排一份,再投回 `already-queued`。一个会话最多排 8 张,全宿主最多 256 张。每张最多等 1 小时。
|
|
57
|
+
- **队列只在内存里:** 宿主重启后,还没投进去的卡会丢。投卡方可以查介入记录,确认卡到底有没有投进去。
|
|
58
|
+
- **原因压成一行:** 换行和控制字符一律换成空格,所以原因里伪造不出抬头那样的一行。
|
|
59
|
+
- **服务对象上不暴露存储和队列:** 别的插件拿到的服务只有五个方法:`library`、`templates`、`interventions`、`castEnabled`、`cast`。
|
|
60
|
+
- **白名单冻结:** `PLUGIN_CALLERS` 用 `Object.freeze` 冻住,运行时改不动。
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# 收尾自查(第 2 期,PT-4)
|
|
2
|
+
|
|
3
|
+
依据 workbench-market 第 18 篇「自查模板」一节(属主裁定 R103~R106)。部署配置 `selfCheck.enabled` 默认关,启用需另外批准。
|
|
4
|
+
|
|
5
|
+
## 什么时候触发
|
|
6
|
+
|
|
7
|
+
挂在 DSH 的 `agent/turn-stopping` 上:一轮本来要结束、要停下之前,插件往会话里静默放进一条自查。这一步会让这一轮再走一步,不会马上停。
|
|
8
|
+
|
|
9
|
+
下面几条全部满足才触发:
|
|
10
|
+
|
|
11
|
+
- 是顶层会话,并且手上有活:有进行中的目标(`goals` 的 phase 为 `active`),或者手上有在办的 a2a 单。后一项读 a2a 提供的只读服务 `a2aTickets.hasOpenTicket(sessionId)`。a2a 没装或读不到时按「不知道」处理,只看目标,并在记录里标 `a2a-ticket-source-missing`。
|
|
12
|
+
- 同一轮最多一次。
|
|
13
|
+
- 从上次自查到现在有新动作(新的工具结果)。没有新动作就接受这次停下。
|
|
14
|
+
- 这一轮不是被中止的。出错、被中断、属主在面板上手动停掉的,都不触发。
|
|
15
|
+
|
|
16
|
+
## 内容
|
|
17
|
+
|
|
18
|
+
- **固定部分:** 插件自动带上,带版本号(`selfcheck-fixed-1`),400 字以内,会话改不了。分两种:
|
|
19
|
+
- **属主在场**(这一轮由人在会话里打字开的):不拦停,**也不延长这一轮**。只注入第 5、6、7 条,而且附在会话的下一步里,不放在这一轮。问的只有一件事:交给属主的事,是不是本该系统做、它够不着的?是的话要同时提决策卡。
|
|
20
|
+
- **不在场**:注入第 1~4、6、7 条,再加会话的领域部分,让这一轮再走一步。七条的原文照第 18 篇,有测试锁住关键句。
|
|
21
|
+
- **领域部分:** 会话自己用 `selfcheck_write` 写,600 字以内。存成这个会话自己的会话模板「工坊·自查模板」,不会被节律注入。
|
|
22
|
+
- 每次写入,旧文字都存成一个版本,新文字标为 `self-rN`。
|
|
23
|
+
- 属主在面板上改过以后,版本标记会被清掉,会话就不能再覆盖(回 `owner-edited`)。
|
|
24
|
+
- 还没写领域部分时,固定部分照样触发。
|
|
25
|
+
|
|
26
|
+
## 交结论
|
|
27
|
+
|
|
28
|
+
用 `selfcheck_conclude`,从下面四种里选一个:
|
|
29
|
+
|
|
30
|
+
- `done`:做完,必须附证据;
|
|
31
|
+
- `waiting`:登记等待,必须写叫醒条件和期限;
|
|
32
|
+
- `continue`:接着做;
|
|
33
|
+
- `orphan`:孤儿停。
|
|
34
|
+
|
|
35
|
+
可以带上关联的单子。注入了自查、会话却没交结论就停了,记为孤儿停。
|
|
36
|
+
|
|
37
|
+
两个工具都只认调用它的那个会话(取运行时的会话身份),不认参数里写的会话号。
|
|
38
|
+
|
|
39
|
+
## 缺模板时的提示
|
|
40
|
+
|
|
41
|
+
会话有进行中的目标、但还没有领域部分时,在会话里可见地提示它写一份。之后每 30 轮最多提示一次,一共最多 3 次。第 3 次提示时,记录里会标「未建自查模板」(`no-template`),交给观察者处理。
|
|
42
|
+
|
|
43
|
+
## 读取
|
|
44
|
+
|
|
45
|
+
- 路由 `GET /plugins/dsh-prompt-templates/self-checks?session_id=`;
|
|
46
|
+
- 服务 `ctx.promptTemplates.selfChecks(sessionId)`。
|
|
47
|
+
|
|
48
|
+
都是只读。记录分六类:注入、交结论、孤儿停、提示、未建模板、写模板。
|
|
49
|
+
|
|
50
|
+
## 「属主在场」怎么判(#29 评审)
|
|
51
|
+
|
|
52
|
+
只有本轮里**真人直接发的消息**才算属主在场,判断条件是:`source.kind === 'user'`,而且不带插件自己的任何标记。
|
|
53
|
+
|
|
54
|
+
插件自己发的可见消息(定时注入、可见的事件提醒、投卡、缺模板提示)为了在对话里显示出来,`kind` 也写成 `user`,但都带着 `scheduled` 这类标记,所以一律不算在场。
|
|
55
|
+
|
|
56
|
+
判断出错或判不准时,按不在场处理:宁可多跑五问,也不能漏掉。
|
|
57
|
+
|
|
58
|
+
## 谁能读到什么
|
|
59
|
+
|
|
60
|
+
`ctx.promptTemplates.selfChecks(sessionId)` 按调用方区别对待:
|
|
61
|
+
|
|
62
|
+
- a2a 插件(观察者的读取方)拿到完整记录;
|
|
63
|
+
- 其他插件只拿到摘要:会话、时间、记录类型、结论,不带证据、叫醒条件、期限和单子的原文。
|
|
64
|
+
|
|
65
|
+
## v10 之后怎么退回旧版本
|
|
66
|
+
|
|
67
|
+
v10 只新增了一张表 `self_check_log`,没改任何旧表,旧版本插件打开时不会碰它。可是旧版本只认它自己的 schema 号,遇到更新的库会拒绝打开。所以退回时要先把库的版本号改回去:
|
|
68
|
+
|
|
69
|
+
1. 停掉宿主,把 `$DSH_HOME/ext/prompt-templates/db.sqlite3` 及 `-wal`、`-shm` 整组备份。
|
|
70
|
+
2. 用 `sqlite3` 打开这个库,执行 `PRAGMA user_version=9;`。`self_check_log` 表可以留着,旧版不读它;不想留就 `DROP TABLE self_check_log;`。
|
|
71
|
+
3. 换回 0.16 的插件包,启动宿主。
|
|
72
|
+
|
|
73
|
+
这一步只对退回到 0.16 有效。再往前的版本,按各自的发版说明处理。
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Spec:事件触发提醒(行动证据 → 问题队列 → 下一次决策前注入)
|
|
2
2
|
|
|
3
3
|
- 仓库:`dsh-prompt-templates`(master)
|
|
4
|
-
-
|
|
5
|
-
-
|
|
4
|
+
- 状态:**已实现,已发布**:0.14.0(2026-11-17)首发,0.15.0 加面板自己的事件总开关,0.16.0 加每条提醒的交接行。属主 2026-11-14 裁定第 7 节开放问题全部按默认取向。默认关闭,只在获授权的测试宿主显式开启。第 1–8 节保留初始设计与当时证据,现行实现差异见第 9 节;失败适配现行契约见[失败契约](event-failure-contract.md),不能将历史“仅结构化字段”描述当作当前实现。
|
|
5
|
+
- 首发版本:0.14.0(2026-11-17;撰写时为候选)
|
|
6
6
|
- 撰写日期:2026-11-14
|
|
7
7
|
- 取证基线:
|
|
8
8
|
- 本插件 master `3e6f6c7`(0.13.4):typecheck 通过,node:test 77/77 通过。
|
|
@@ -139,6 +139,7 @@ src/
|
|
|
139
139
|
- 插件自己只推进到 `notified`,并给出两个**信号**,不自己改终态:
|
|
140
140
|
- 提醒之后,下一次相关调用的稳定指纹变了 → `signal: changed`
|
|
141
141
|
- 提醒之后同一模式又出现 → `signal: repeated`,修订号加 1
|
|
142
|
+
- 0.16(schema v8):同时 `repeated_after_reminder` 加 1,即「提醒后仍在重复」的次数。`signal` 在下一次提醒时清空,这个计数不清空,留给以后的观察者读;在 `GET …/event-episodes` 和面板的问题台账里都能看到。
|
|
142
143
|
- `applied` / `verified` / `ineffective` / `reverted` / `rejected` / `deferred` / `awaiting_authorization` 只通过审计接口设置,并且必须附证据引用(call id 或会话事件序号)。Agent 的口头自述不是证据。
|
|
143
144
|
- 宿主不能证明模型“读到”了提醒,所以不设 `consumed`;需要时在报告里写 UNKNOWN。
|
|
144
145
|
|
|
@@ -170,7 +171,7 @@ interface TemplateEventSource {
|
|
|
170
171
|
}
|
|
171
172
|
```
|
|
172
173
|
|
|
173
|
-
正文按 Atelier
|
|
174
|
+
正文按 Atelier 模板契约渲染:规则与版本、脱敏观察、证据引用、要判断的问题、授权边界、无问题时继续、验证标准、正式参考。0.16 起每条正文末尾加一句通用交接话:「按提醒查过仍解不开的,按所在环境的上报方式交出去,写清已查处、缺的那一句背景。」这句不写任何 a2a 工具名,插件不绑定 a2a。默认 `visible`(对话流可见,便于用户看到为什么被提醒),可按策略改为静默;两种模式都是 user-role,不赋予 system 权限。
|
|
174
175
|
|
|
175
176
|
**交付语义**:不承诺恰好一次,采用“可恢复的至少一次 + 幂等去重”。崩溃窗口如下:
|
|
176
177
|
|
|
@@ -191,7 +192,7 @@ interface TemplateEventSource {
|
|
|
191
192
|
|---|---|---|
|
|
192
193
|
| `event_policies` | `rule_id` PK、`rule_version`、`enabled`、`threshold`、`window`、`cooldown_turns`、`max_per_episode`、`mode` | 与 `inject_every` 无关的独立策略实体;默认全部 `enabled=0`。 |
|
|
193
194
|
| `event_observations` | `session_id`、`seq`、`call_id`、`root_call_id`、`tool_name`、`is_ptc_subcall`、`stable_fingerprint`、`target_fingerprint`、`outcome`、`redacted_summary`、`created_at` | 每会话按窗口截断。 |
|
|
194
|
-
| `event_episodes` | `episode_id` PK、`session_id`、`rule_id`、`rule_version`、`fingerprint`、`state`、`evidence_refs`(JSON)、`evidence_revision`、`signal`、`cooldown_until_turn`、`created_at`、`updated_at` | 问题状态机。 |
|
|
195
|
+
| `event_episodes` | `episode_id` PK、`session_id`、`rule_id`、`rule_version`、`fingerprint`、`state`、`evidence_refs`(JSON)、`evidence_revision`、`signal`、`repeated_after_reminder`(v8)、`cooldown_until_turn`、`created_at`、`updated_at` | 问题状态机。 |
|
|
195
196
|
| `event_outbox` | `dedup_key` PK、`episode_id`、`state`、`attempts`、`turn`、`step`、`created_at`、`updated_at` | 交付状态。 |
|
|
196
197
|
|
|
197
198
|
旧版本插件遇到 v5 库会按现有逻辑拒绝打开(`store.ts` 遇到更新的 `user_version` 抛错),不会降级运行。
|
package/lib/cast.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The prompt-templates service for other plugins on the same host (observer phase 2, workbench-market 18; PT-3).
|
|
3
|
+
*
|
|
4
|
+
* Reads are open to any plugin, read-only: the card library, one session's own templates, and the intervention log —
|
|
5
|
+
* the same shapes as the read-only routes. Casting a card into a session is not: only a caller this plugin recognizes
|
|
6
|
+
* may cast (today the a2a plugin alone), and the caller is taken from the cordis loader entry of the plugin that holds
|
|
7
|
+
* the context it calls through — the package name the profile configured, never a string the caller passes. Casting is
|
|
8
|
+
* off unless the deployment turns `cast.enabled` on. A cast card goes into the named session at its next step as a
|
|
9
|
+
* visible message, and the delivery is recorded in the intervention log as `source: plugin` with that caller.
|
|
10
|
+
* @module @nelsonlongxiang/dsh-prompt-templates/cast
|
|
11
|
+
*/
|
|
12
|
+
import { Service } from '@deepseek-ai/cordis';
|
|
13
|
+
import { createUserMessage } from '@deepseek-ai/dsh-llm';
|
|
14
|
+
import { PLUGIN_CALLERS, contentDigest } from "./interventions.js";
|
|
15
|
+
import { expandTemplateVariables } from "./variables.js";
|
|
16
|
+
/** The service name other plugins read: `ctx.promptTemplates`. */
|
|
17
|
+
export const SERVICE_NAME = 'promptTemplates';
|
|
18
|
+
/** Cast cards waiting for one session, at most. */
|
|
19
|
+
export const CAST_QUEUE_MAX = 8;
|
|
20
|
+
/**
|
|
21
|
+
* The package name of the plugin that owns `ctx`, as the profile's loader entry configured it (walking up to the nearest
|
|
22
|
+
* fiber with an entry). Undefined for a context outside any loader entry (the root, a test harness).
|
|
23
|
+
*/
|
|
24
|
+
export function callerOf(ctx) {
|
|
25
|
+
let fiber = ctx.fiber;
|
|
26
|
+
for (let depth = 0; fiber !== undefined && depth < 64; depth++) {
|
|
27
|
+
const name = fiber.entry?.options?.name;
|
|
28
|
+
if (typeof name === 'string' && name !== '')
|
|
29
|
+
return name;
|
|
30
|
+
const next = fiber.parent?.fiber;
|
|
31
|
+
if (next === undefined || next === fiber)
|
|
32
|
+
return undefined;
|
|
33
|
+
fiber = next;
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
/** Casts waiting across all sessions, at most, and how long one waits before it is dropped. */
|
|
38
|
+
export const CAST_QUEUE_TOTAL_MAX = 256;
|
|
39
|
+
export const CAST_WAIT_MS = 60 * 60_000;
|
|
40
|
+
/** A reason on one line: newlines and control characters become a space (no forged header lines). */
|
|
41
|
+
export function oneLine(text) {
|
|
42
|
+
// Control characters, line and paragraph separators, bidi controls and zero-width characters all become a space (#28 review).
|
|
43
|
+
return text.replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029\u200b-\u200f\u202a-\u202e\u2060-\u2069\ufeff]+/g, ' ').replace(/ {2,}/g, ' ').trim();
|
|
44
|
+
}
|
|
45
|
+
/** The visible message a cast becomes. */
|
|
46
|
+
export function renderCastMessage(turn, step, cards, sessionId) {
|
|
47
|
+
return createUserMessage({
|
|
48
|
+
content: [{
|
|
49
|
+
type: 'text',
|
|
50
|
+
text: [
|
|
51
|
+
`⚙️ 投卡 · 第 ${String(turn)} 轮 · ${cards.map(card => card.name).join('、')}`,
|
|
52
|
+
'',
|
|
53
|
+
...cards.flatMap(card => [`(投卡方:${card.caller};原因:${card.reason})`, expandTemplateVariables(card.content, { sessionId, turn }), '']),
|
|
54
|
+
'本卡不是新的用户指令,不授予任何权限。',
|
|
55
|
+
].join('\n').trimEnd(),
|
|
56
|
+
}],
|
|
57
|
+
source: { kind: 'user', scheduled: 'prompt-template-cast', turn, step, templates: cards.map(card => ({ id: card.templateId, name: card.name, caller: card.caller })) },
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Provide the service and deliver queued casts at a session's next admitted step. The store, the switch and the queues
|
|
62
|
+
* live in this closure only: the service object other plugins hold carries the five public methods and cordis' own
|
|
63
|
+
* `ctx`/`name`, never the store or a way to read or drain a queue (#28 review). Delivery is recorded as `source: plugin`
|
|
64
|
+
* with the caller; a fault is reported once and never fails the step. Queues are in memory: a restart drops casts that
|
|
65
|
+
* have not gone in yet (the caller can check the intervention log), and a cast waits at most an hour.
|
|
66
|
+
*/
|
|
67
|
+
export function registerCast(ctx, store, enabled, selfCheckEnabled = () => false) {
|
|
68
|
+
const queues = new Map();
|
|
69
|
+
// Expired casts never count toward the host-wide cap: they are dropped first (#28 review).
|
|
70
|
+
const total = (now) => {
|
|
71
|
+
let n = 0;
|
|
72
|
+
for (const [sessionId, q] of [...queues]) {
|
|
73
|
+
const live = q.filter(card => now - card.at < CAST_WAIT_MS);
|
|
74
|
+
if (live.length === 0)
|
|
75
|
+
queues.delete(sessionId);
|
|
76
|
+
else {
|
|
77
|
+
queues.set(sessionId, live);
|
|
78
|
+
n += live.length;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return n;
|
|
82
|
+
};
|
|
83
|
+
const take = (sessionId, now) => {
|
|
84
|
+
const queue = queues.get(sessionId) ?? [];
|
|
85
|
+
queues.delete(sessionId);
|
|
86
|
+
return queue.filter(card => now - card.at < CAST_WAIT_MS);
|
|
87
|
+
};
|
|
88
|
+
class Face extends Service {
|
|
89
|
+
constructor(c) { super(c, SERVICE_NAME); }
|
|
90
|
+
library() { return store().library(); }
|
|
91
|
+
templates(sessionId) { return store().library().filter(card => card.scope === 'session' && card.session_id === sessionId); }
|
|
92
|
+
interventions(filter = {}) { return store().interventions.list(filter); }
|
|
93
|
+
castEnabled() { return enabled(); }
|
|
94
|
+
/**
|
|
95
|
+
* One session's self-check log. The a2a plugin (the observer's reader) gets the rows whole; any other plugin gets a
|
|
96
|
+
* summary only — session, time, kind and conclusion — never the evidence, wake, deadline or ticket text (#29 review).
|
|
97
|
+
*/
|
|
98
|
+
selfChecks(sessionId) {
|
|
99
|
+
const rows = store().selfChecks.list(String(sessionId));
|
|
100
|
+
const caller = callerOf(this.ctx);
|
|
101
|
+
if (caller !== undefined && PLUGIN_CALLERS.includes(caller))
|
|
102
|
+
return rows;
|
|
103
|
+
return rows.map(row => ({ ...row, evidence: null, wake: null, deadline: null, ticket: null }));
|
|
104
|
+
}
|
|
105
|
+
selfCheckEnabled() { return selfCheckEnabled(); }
|
|
106
|
+
/**
|
|
107
|
+
* Cast one card into a session: it goes in at the session's next step as a visible message. Only a recognized caller
|
|
108
|
+
* (PLUGIN_CALLERS) may cast, and only while `cast.enabled` is on. The card must be a global template or one of that
|
|
109
|
+
* session's own; one copy of a card waits per session. The reason is put on one line and must be 1..500 characters.
|
|
110
|
+
*/
|
|
111
|
+
cast(input) {
|
|
112
|
+
if (!enabled())
|
|
113
|
+
return { ok: false, code: 'disabled', error: 'casting is off on this host (cast.enabled)' };
|
|
114
|
+
const caller = callerOf(this.ctx);
|
|
115
|
+
if (caller === undefined || !PLUGIN_CALLERS.includes(caller))
|
|
116
|
+
return { ok: false, code: 'caller', error: 'only a plugin this host recognizes may cast a card' };
|
|
117
|
+
const sessionId = String(input?.sessionId ?? '').trim();
|
|
118
|
+
if (sessionId === '')
|
|
119
|
+
return { ok: false, code: 'session', error: 'name the session to cast into' };
|
|
120
|
+
const reason = oneLine(String(input?.reason ?? ''));
|
|
121
|
+
if (reason === '' || reason.length > 500)
|
|
122
|
+
return { ok: false, code: 'reason', error: 'give a reason of 1..500 characters on one line' };
|
|
123
|
+
const template = store().get(String(input?.templateId ?? ''));
|
|
124
|
+
if (template === undefined || (template.scope === 'session' && template.session_id !== sessionId))
|
|
125
|
+
return { ok: false, code: 'template', error: 'no such card for that session' };
|
|
126
|
+
const live = total(Date.now());
|
|
127
|
+
const queue = queues.get(sessionId) ?? [];
|
|
128
|
+
if (queue.some(card => card.templateId === template.id))
|
|
129
|
+
return { ok: false, code: 'already-queued', error: 'that card already waits for this session' };
|
|
130
|
+
if (queue.length >= CAST_QUEUE_MAX || live >= CAST_QUEUE_TOTAL_MAX)
|
|
131
|
+
return { ok: false, code: 'full', error: `at most ${String(CAST_QUEUE_MAX)} cast cards can wait for one session` };
|
|
132
|
+
queue.push({ templateId: template.id, name: template.name, version: template.version ?? null, content: template.content, caller, reason, at: Date.now() });
|
|
133
|
+
queues.set(sessionId, queue);
|
|
134
|
+
return { ok: true, queued: queue.length };
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const service = new Face(ctx);
|
|
138
|
+
let faultReported = false;
|
|
139
|
+
ctx.on('agent/pre-step', async ({ agent, messages, turn, step }, next) => {
|
|
140
|
+
const decision = await next();
|
|
141
|
+
if (decision.kind === 'reject' || messages.length === 0)
|
|
142
|
+
return decision;
|
|
143
|
+
try {
|
|
144
|
+
const sessionId = String(agent.session.header.id);
|
|
145
|
+
const cards = take(sessionId, Date.now());
|
|
146
|
+
if (cards.length === 0)
|
|
147
|
+
return decision;
|
|
148
|
+
const message = renderCastMessage(turn, typeof step === 'number' ? step : 1, cards, sessionId);
|
|
149
|
+
try {
|
|
150
|
+
const at = new Date().toISOString();
|
|
151
|
+
for (const card of cards) {
|
|
152
|
+
store().interventions.record({ session_id: sessionId, source: 'plugin', method: null, caller: card.caller, template_id: card.templateId, template_name: card.name,
|
|
153
|
+
template_version: card.version, content_sha256: contentDigest(expandTemplateVariables(card.content, { sessionId, turn })), turn, step: typeof step === 'number' ? step : null, at });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
console.error('[dsh-prompt-templates] intervention log skipped a cast:', error);
|
|
158
|
+
}
|
|
159
|
+
return { ...decision, messages: [...decision.messages, message] };
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
if (!faultReported) {
|
|
163
|
+
faultReported = true;
|
|
164
|
+
console.error('[dsh-prompt-templates] cast skipped this step; further faults stay silent:', error);
|
|
165
|
+
}
|
|
166
|
+
return decision;
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
return service;
|
|
170
|
+
}
|
package/lib/cli/database.js
CHANGED
|
@@ -9,7 +9,7 @@ import { createSnapshot, diffSnapshots } from "./model.js";
|
|
|
9
9
|
* v5 event tables, v6 the stored master switch / evolution enrollment, and
|
|
10
10
|
* v7 the combined migration all hold runtime state that is never exported.
|
|
11
11
|
*/
|
|
12
|
-
const SUPPORTED_DB_VERSIONS = [4, 5, 6, 7];
|
|
12
|
+
const SUPPORTED_DB_VERSIONS = [4, 5, 6, 7, 8, 9, 10];
|
|
13
13
|
/** A valid operation blocked by a safety/business gate (CLI exit 1). */
|
|
14
14
|
export class ImportBlockedError extends Error {
|
|
15
15
|
constructor(message) { super(message); this.name = 'ImportBlockedError'; }
|
|
@@ -21,7 +21,7 @@ export function exportDatabase(dbPath, filters = {}) {
|
|
|
21
21
|
db.exec('PRAGMA query_only=ON');
|
|
22
22
|
const version = Number(db.prepare('PRAGMA user_version').get().user_version);
|
|
23
23
|
if (!SUPPORTED_DB_VERSIONS.includes(version))
|
|
24
|
-
throw new Error(`${path} has schema version ${version}, expected 4
|
|
24
|
+
throw new Error(`${path} has schema version ${version}, expected 4 to 10`);
|
|
25
25
|
const clauses = [];
|
|
26
26
|
const args = [];
|
|
27
27
|
if (filters.scope !== undefined) {
|
|
@@ -116,7 +116,7 @@ export async function importDatabase(dbPath, incoming, options) {
|
|
|
116
116
|
db.exec(`PRAGMA busy_timeout=${options.busyTimeoutMs ?? 5000}`);
|
|
117
117
|
const version = Number(db.prepare('PRAGMA user_version').get().user_version);
|
|
118
118
|
if (!SUPPORTED_DB_VERSIONS.includes(version))
|
|
119
|
-
throw new Error(`${path} has schema version ${version}, expected 4
|
|
119
|
+
throw new Error(`${path} has schema version ${version}, expected 4 to 10`);
|
|
120
120
|
backupPath = resolve(options.backupOut ?? `${path}.${timestampName()}.bak`);
|
|
121
121
|
mkdirSync(dirname(backupPath), { recursive: true });
|
|
122
122
|
await backup(db, backupPath);
|
package/lib/client/Library.js
CHANGED
|
@@ -10,6 +10,7 @@ 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 { recordManualIntervention } from "./api.js";
|
|
13
14
|
import { filterTemplateRows, searchableTemplateRows } from "./filter.js";
|
|
14
15
|
import { buildSharePayload, parseSharePayload, planShareImport } from "./share.js";
|
|
15
16
|
import { copyShareText } from "./clipboard.js";
|
|
@@ -25,7 +26,7 @@ function TemplateRow({ template, onInsert, onSend, onInterject, onEdit, onDelete
|
|
|
25
26
|
e.preventDefault();
|
|
26
27
|
e.stopPropagation();
|
|
27
28
|
onDropOn(template.id);
|
|
28
|
-
} }, children: [_jsxs("button", { type: "button", className: css.insert, onClick: () => { onInsert(template
|
|
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 }) })), _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 }) })] }));
|
|
29
30
|
}
|
|
30
31
|
/** The template inline form: creation (with scope + category pickers) and in-place edit. */
|
|
31
32
|
function TemplateForm({ initial, allowScope, sessionId, categories, t, submitLabel, onSubmit, onDone, onCancel }) {
|
|
@@ -362,20 +363,24 @@ export function TemplateLibrary({ sessionId, face, t, header, headerExtra }) {
|
|
|
362
363
|
void load();
|
|
363
364
|
void loadCategories();
|
|
364
365
|
}, [importText, templates, categories, sessionId, create, update, createCategory, load, loadCategories, t]);
|
|
365
|
-
|
|
366
|
+
// Observer phase 1 (v9): each hand-sent template is recorded on the host (identity and digest, never the text).
|
|
367
|
+
const handleInsert = useCallback((template) => {
|
|
366
368
|
if (sessionId === null)
|
|
367
369
|
return;
|
|
368
|
-
insert(sessionId, content);
|
|
370
|
+
insert(sessionId, template.content);
|
|
371
|
+
void recordManualIntervention(sessionId, template.id, 'insert');
|
|
369
372
|
}, [insert, sessionId]);
|
|
370
|
-
const handleSend = useCallback((
|
|
373
|
+
const handleSend = useCallback((template) => {
|
|
371
374
|
if (sessionId === null)
|
|
372
375
|
return;
|
|
373
|
-
send(sessionId, content);
|
|
376
|
+
send(sessionId, template.content);
|
|
377
|
+
void recordManualIntervention(sessionId, template.id, 'send');
|
|
374
378
|
}, [send, sessionId]);
|
|
375
|
-
const handleInterject = useCallback((
|
|
379
|
+
const handleInterject = useCallback((template) => {
|
|
376
380
|
if (sessionId === null)
|
|
377
381
|
return;
|
|
378
|
-
interject(sessionId, content);
|
|
382
|
+
interject(sessionId, template.content);
|
|
383
|
+
void recordManualIntervention(sessionId, template.id, 'interject');
|
|
379
384
|
}, [interject, sessionId]);
|
|
380
385
|
const handleRemove = useCallback(async (id) => {
|
|
381
386
|
const result = await remove(id);
|
|
@@ -460,7 +465,7 @@ export function TemplateLibrary({ sessionId, face, t, header, headerExtra }) {
|
|
|
460
465
|
shareOpener.current = null;
|
|
461
466
|
if (opener?.isConnected)
|
|
462
467
|
opener.focus({ preventScroll: true });
|
|
463
|
-
}, children: t('panel.shareDismiss') })] })] })), showImport && (_jsxs("div", { className: css.importForm, "data-prompt-import": true, children: [_jsx("textarea", { className: css.contentInput, rows: 4, value: importText, onChange: (e) => { setImportText(e.target.value); }, placeholder: t('panel.importPlaceholder'), "aria-label": t('panel.import') }), _jsxs("div", { className: css.importActions, children: [_jsx("button", { type: "button", className: css.saveBtn, onClick: () => { void handleImport(); }, disabled: importBusy, children: t('panel.importRun') }), _jsx("button", { type: "button", className: css.cancelBtn, onClick: () => { setShowImport(false); setImportText(''); }, disabled: importBusy, children: t('panel.importCancel') })] })] })), historyOpen && (_jsxs("div", { className: css.injectHistory, "data-prompt-inject-history": true, role: "dialog", "aria-label": t('panel.historyTitle'), children: [_jsx("div", { className: css.injectHistoryTitle, children: t('panel.historyTitle') }), history.length === 0 && _jsx("div", { className: css.injectHistoryEmpty, children: t('panel.historyEmpty') }), history.map(entry => (_jsxs("div", { className: css.injectHistoryItem, children: [_jsxs("div", { className: css.injectHistoryHead, children: ["\u27F3", entry.turn, " \u00B7 ", new Date(entry.at).toLocaleTimeString(), " \u00B7 ", entry.templates.join(', ')] }), _jsx("div", { className: css.injectHistoryContent, children: entry.content })] }, `${entry.turn}-${entry.at}`)))] })), eventsOpen && (_jsxs("div", { className: css.eventsPanel, "data-prompt-events": true, role: "dialog", "aria-label": t('panel.eventsTitle'), children: [_jsx("div", { className: css.eventsHead, children: t('panel.eventsTitle') }), _jsx("div", { className: policies !== null && policies.enabled ? css.eventsBanner : `${css.eventsBanner} ${css.eventsBannerOff}`, children: _jsxs("label", { className: css.eventsRuleHead, children: [_jsx("input", { type: "checkbox", className: css.eventsToggle, checked: policies?.enabled === true, disabled: policies === null, onChange: () => { void handleToggleMaster(); } }), _jsx("span", { children: policies === null ? t('panel.eventsLoadFailed') : policies.enabled ? t('panel.eventsMasterOn') : t('panel.eventsMasterOff') })] }) }), (policies?.items ?? []).map(rule => (_jsxs("div", { className: css.eventsRule, children: [_jsxs("label", { className: css.eventsRuleHead, children: [_jsx("input", { type: "checkbox", className: css.eventsToggle, checked: rule.enabled, disabled: policies === null || !policies.enabled, onChange: () => { void handleToggleRule(rule); } }), _jsx("span", { className: css.eventsRuleName, children: t(rule.rule_id === 'repeated-preparation' ? 'panel.eventsRulePrep' : 'panel.eventsRuleFail') })] }), _jsxs("div", { className: css.eventsParams, children: [_jsxs("label", { className: css.eventsParam, children: [t('panel.eventsThreshold'), _jsx("input", { type: "number", min: 1, defaultValue: rule.threshold, disabled: !rule.enabled || policies === null || !policies.enabled, onBlur: (event) => { void handleRuleParam(rule, 'threshold', event.target.value); } })] }), _jsxs("label", { className: css.eventsParam, children: [t('panel.eventsCooldown'), _jsx("input", { type: "number", min: 0, defaultValue: rule.cooldown_turns, disabled: !rule.enabled || policies === null || !policies.enabled, onBlur: (event) => { void handleRuleParam(rule, 'cooldown_turns', event.target.value); } })] })] })] }, rule.rule_id))), _jsx("div", { className: css.eventsEpisodesTitle, children: t('panel.eventsEpisodes') }), episodes.length === 0 && _jsx("div", { className: css.eventsEmpty, children: t('panel.eventsEpisodesEmpty') }), episodes.slice(0, 8).map(episode => (_jsxs("div", { className: css.eventsEpisode, children: [_jsxs("div", { className: css.eventsEpisodeHead, children: [episode.rule_id, " \u00B7 ", episode.state, " \u00B7 \u00D7", episode.notify_count, " \u00B7 ", new Date(episode.updated_at).toLocaleTimeString()] }), _jsx("div", { className: css.eventsEpisodeSummary, children: episode.summary })] }, episode.episode_id)))] })), _jsx("div", { className: css.searchBar, children: _jsx("input", { type: "search", className: css.searchInput, value: query, onChange: (e) => { setQuery(e.target.value); }, placeholder: t('panel.search'), "aria-label": t('panel.search') }) }), _jsxs("div", { className: css.tabsBar, children: [_jsx("button", { type: "button", className: effectiveTab === 'global' ? `${css.tab} ${css.tabActive}` : css.tab, onClick: () => { setActiveTab('global'); }, children: t('panel.global') }), _jsx("button", { type: "button", className: effectiveTab === 'session' ? `${css.tab} ${css.tabActive}` : css.tab, onClick: () => { setActiveTab('session'); }, disabled: sessionId === null, children: t('panel.session') }), visibleCategories.map((cat) => {
|
|
468
|
+
}, children: t('panel.shareDismiss') })] })] })), showImport && (_jsxs("div", { className: css.importForm, "data-prompt-import": true, children: [_jsx("textarea", { className: css.contentInput, rows: 4, value: importText, onChange: (e) => { setImportText(e.target.value); }, placeholder: t('panel.importPlaceholder'), "aria-label": t('panel.import') }), _jsxs("div", { className: css.importActions, children: [_jsx("button", { type: "button", className: css.saveBtn, onClick: () => { void handleImport(); }, disabled: importBusy, children: t('panel.importRun') }), _jsx("button", { type: "button", className: css.cancelBtn, onClick: () => { setShowImport(false); setImportText(''); }, disabled: importBusy, children: t('panel.importCancel') })] })] })), historyOpen && (_jsxs("div", { className: css.injectHistory, "data-prompt-inject-history": true, role: "dialog", "aria-label": t('panel.historyTitle'), children: [_jsx("div", { className: css.injectHistoryTitle, children: t('panel.historyTitle') }), history.length === 0 && _jsx("div", { className: css.injectHistoryEmpty, children: t('panel.historyEmpty') }), history.map(entry => (_jsxs("div", { className: css.injectHistoryItem, children: [_jsxs("div", { className: css.injectHistoryHead, children: ["\u27F3", entry.turn, " \u00B7 ", new Date(entry.at).toLocaleTimeString(), " \u00B7 ", entry.templates.join(', ')] }), _jsx("div", { className: css.injectHistoryContent, children: entry.content })] }, `${entry.turn}-${entry.at}`)))] })), eventsOpen && (_jsxs("div", { className: css.eventsPanel, "data-prompt-events": true, role: "dialog", "aria-label": t('panel.eventsTitle'), children: [_jsx("div", { className: css.eventsHead, children: t('panel.eventsTitle') }), _jsx("div", { className: policies !== null && policies.enabled ? css.eventsBanner : `${css.eventsBanner} ${css.eventsBannerOff}`, children: _jsxs("label", { className: css.eventsRuleHead, children: [_jsx("input", { type: "checkbox", className: css.eventsToggle, checked: policies?.enabled === true, disabled: policies === null, onChange: () => { void handleToggleMaster(); } }), _jsx("span", { children: policies === null ? t('panel.eventsLoadFailed') : policies.enabled ? t('panel.eventsMasterOn') : t('panel.eventsMasterOff') })] }) }), (policies?.items ?? []).map(rule => (_jsxs("div", { className: css.eventsRule, children: [_jsxs("label", { className: css.eventsRuleHead, children: [_jsx("input", { type: "checkbox", className: css.eventsToggle, checked: rule.enabled, disabled: policies === null || !policies.enabled, onChange: () => { void handleToggleRule(rule); } }), _jsx("span", { className: css.eventsRuleName, children: t(rule.rule_id === 'repeated-preparation' ? 'panel.eventsRulePrep' : 'panel.eventsRuleFail') })] }), _jsxs("div", { className: css.eventsParams, children: [_jsxs("label", { className: css.eventsParam, children: [t('panel.eventsThreshold'), _jsx("input", { type: "number", min: 1, defaultValue: rule.threshold, disabled: !rule.enabled || policies === null || !policies.enabled, onBlur: (event) => { void handleRuleParam(rule, 'threshold', event.target.value); } })] }), _jsxs("label", { className: css.eventsParam, children: [t('panel.eventsCooldown'), _jsx("input", { type: "number", min: 0, defaultValue: rule.cooldown_turns, disabled: !rule.enabled || policies === null || !policies.enabled, onBlur: (event) => { void handleRuleParam(rule, 'cooldown_turns', event.target.value); } })] })] })] }, rule.rule_id))), _jsx("div", { className: css.eventsEpisodesTitle, children: t('panel.eventsEpisodes') }), episodes.length === 0 && _jsx("div", { className: css.eventsEmpty, children: t('panel.eventsEpisodesEmpty') }), episodes.slice(0, 8).map(episode => (_jsxs("div", { className: css.eventsEpisode, children: [_jsxs("div", { className: css.eventsEpisodeHead, children: [episode.rule_id, " \u00B7 ", episode.state, " \u00B7 \u00D7", episode.notify_count, (episode.repeated_after_reminder ?? 0) > 0 ? ` · ${t('panel.eventsRepeatedAfter')} ×${String(episode.repeated_after_reminder ?? 0)}` : '', " \u00B7 ", new Date(episode.updated_at).toLocaleTimeString()] }), _jsx("div", { className: css.eventsEpisodeSummary, children: episode.summary })] }, episode.episode_id)))] })), _jsx("div", { className: css.searchBar, children: _jsx("input", { type: "search", className: css.searchInput, value: query, onChange: (e) => { setQuery(e.target.value); }, placeholder: t('panel.search'), "aria-label": t('panel.search') }) }), _jsxs("div", { className: css.tabsBar, children: [_jsx("button", { type: "button", className: effectiveTab === 'global' ? `${css.tab} ${css.tabActive}` : css.tab, onClick: () => { setActiveTab('global'); }, children: t('panel.global') }), _jsx("button", { type: "button", className: effectiveTab === 'session' ? `${css.tab} ${css.tabActive}` : css.tab, onClick: () => { setActiveTab('session'); }, disabled: sessionId === null, children: t('panel.session') }), visibleCategories.map((cat) => {
|
|
464
469
|
const key = `cat:${cat.scope}:${cat.name}`;
|
|
465
470
|
return (_jsxs("span", { className: effectiveTab === key ? `${css.tab} ${css.tabActive}` : css.tab, children: [_jsx("button", { type: "button", onClick: () => { setActiveTab(key); }, children: cat.name }), _jsx("button", { type: "button", className: css.tabShare, "aria-label": t('panel.shareCategory'), title: t('panel.shareCategory'), onClick: (event) => { void handleShareCategory(cat, event.currentTarget); }, children: _jsx(IconCopyOutlineRegular, { size: 11 }) }), _jsx("button", { type: "button", className: css.tabDelete, "aria-label": t('panel.deleteCategory'), title: t('panel.deleteCategory'), onClick: () => {
|
|
466
471
|
void (async () => {
|
package/lib/client/api.js
CHANGED
|
@@ -29,6 +29,16 @@ export async function injectionHistory(sessionId) {
|
|
|
29
29
|
const body = await response.json();
|
|
30
30
|
return [...body.history ?? []];
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Record one template a person sent from the panel (observer phase 1, schema v9). Best effort: an older host without the
|
|
34
|
+
* route, or a network fault, never gets in the way of the send itself.
|
|
35
|
+
*/
|
|
36
|
+
export async function recordManualIntervention(sessionId, templateId, method) {
|
|
37
|
+
try {
|
|
38
|
+
await fetch(`${BASE}/interventions/manual`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ session_id: sessionId, template_id: templateId, method }) });
|
|
39
|
+
}
|
|
40
|
+
catch { /* best effort */ }
|
|
41
|
+
}
|
|
32
42
|
/** Load every user category tab (global + all sessions'; the panel filters). */
|
|
33
43
|
export async function listCategories() {
|
|
34
44
|
const response = await fetch(`${BASE}/categories`, { cache: 'no-store' });
|
package/lib/client/locales.js
CHANGED
|
@@ -69,6 +69,7 @@ export const zh = {
|
|
|
69
69
|
'panel.eventsCooldown': '冷却(轮)',
|
|
70
70
|
'panel.eventsEpisodes': '本会话问题台账',
|
|
71
71
|
'panel.eventsEpisodesEmpty': '暂无记录',
|
|
72
|
+
'panel.eventsRepeatedAfter': '提醒后仍在重复',
|
|
72
73
|
'panel.error': '操作失败',
|
|
73
74
|
'panel.inserted': '已插入',
|
|
74
75
|
'panel.none': '无',
|
|
@@ -146,6 +147,7 @@ export const en = {
|
|
|
146
147
|
'panel.eventsCooldown': 'Cooldown',
|
|
147
148
|
'panel.eventsEpisodes': 'Session episodes',
|
|
148
149
|
'panel.eventsEpisodesEmpty': 'None yet',
|
|
150
|
+
'panel.eventsRepeatedAfter': 'repeated after reminder',
|
|
149
151
|
'panel.error': 'Operation failed',
|
|
150
152
|
'panel.inserted': 'Inserted',
|
|
151
153
|
'panel.none': 'None',
|