@nelsonlongxiang/dsh-prompt-templates 0.13.1 → 0.13.2
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/README.md +13 -2
- package/README_zh.md +13 -2
- package/cordis.patch.yml +28 -28
- package/lib/cli/app.js +12 -12
- package/lib/cli/database.js +6 -6
- package/lib/client/Library.js +20 -3
- package/lib/client/Panel.js +2 -2
- package/lib/client/PromptTab.js +2 -2
- package/lib/client/api.js +8 -0
- package/lib/client/index.js +2 -1
- package/lib/client/locales.js +6 -0
- package/lib/client/service.js +6 -4
- package/lib/client.js +134 -16
- package/lib/client.js.map +1 -1
- package/lib/index.js +12 -5
- package/lib/inject.js +38 -12
- package/lib/store.js +1 -1
- package/lib/types/client/api.d.ts +3 -1
- package/lib/types/client/locales.d.ts +6 -0
- package/lib/types/client/slots.d.ts +8 -2
- package/lib/types/index.d.ts +1 -1
- package/lib/types/inject.d.ts +12 -7
- package/lib/types/store.d.ts +1 -1
- package/lib/types/types.d.ts +15 -0
- package/lib/types/variables.d.ts +24 -0
- package/lib/variables.js +36 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -87,10 +87,21 @@ dsh-prompt-templates import --db /path/to/db.sqlite3 --in merged.json --apply \
|
|
|
87
87
|
|
|
88
88
|
```sh
|
|
89
89
|
pnpm install
|
|
90
|
-
pnpm verify #
|
|
91
|
-
pnpm
|
|
90
|
+
pnpm verify # everyday gate (local and CI)
|
|
91
|
+
pnpm verify:release # alias of pnpm verify
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
+
`pnpm verify` is the gate to run before pushing. It does not boot a DeepSeek Harness process. In order:
|
|
95
|
+
|
|
96
|
+
1. **typecheck** — `tsc --noEmit` for the host project and the client project
|
|
97
|
+
2. **test:cli** — `node:test` over `tests/*.test.ts`: CLI sync, store rules, schema migration, inject helpers, client filters, and an in-process host check. That check mounts `apply()` on Cordis with a stand-in web server, drives the `/plugins/dsh-prompt-templates` routes (including inject-status), and runs the `agent/pre-step` listener against a fake session log
|
|
98
|
+
3. **build** — host `tsc`, client `tsc`, and the tsdown browser bundle
|
|
99
|
+
4. **test:package** — every CSS module class is present in `lib/client.js`, then `npm pack` and the packed `dsh-prompt-templates --help` shim
|
|
100
|
+
|
|
101
|
+
GitHub Actions (`.github/workflows/verify.yml`) runs the same command on pushes and pull requests to `master`, and on `v*` tags, with Node 24. The `@deepseek-ai/*` devDependencies are public npm packages, so CI needs no registry token and no harness checkout.
|
|
102
|
+
|
|
103
|
+
Still manual, because they need a live harness profile: booting `dsh web`, the browser panel against the real web server, and resume or compaction against a real session log.
|
|
104
|
+
|
|
94
105
|
## Known limitations
|
|
95
106
|
|
|
96
107
|
- **Session templates need a current session** — with no session open, only global templates are reachable
|
package/README_zh.md
CHANGED
|
@@ -86,10 +86,21 @@ dsh-prompt-templates import --db /path/to/db.sqlite3 --in merged.json --apply \
|
|
|
86
86
|
|
|
87
87
|
```sh
|
|
88
88
|
pnpm install
|
|
89
|
-
pnpm verify #
|
|
90
|
-
pnpm
|
|
89
|
+
pnpm verify # 日常门禁(本地与 CI)
|
|
90
|
+
pnpm verify:release # pnpm verify 的别名
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
+
推送前跑 `pnpm verify`。它不启动 DeepSeek Harness 进程,顺序为:
|
|
94
|
+
|
|
95
|
+
1. **typecheck** — host 与 client 两个工程的 `tsc --noEmit`
|
|
96
|
+
2. **test:cli** — `node:test` 跑 `tests/*.test.ts`:CLI 同步、store 规则、schema 迁移、注入纯函数、client 过滤,以及进程内 host 检查。该检查把 `apply()` 挂到 Cordis 上,用替身 web server 驱动 `/plugins/dsh-prompt-templates` 路由(含 inject-status),并对一份假会话日志跑 `agent/pre-step` 监听器
|
|
97
|
+
3. **build** — host `tsc`、client `tsc`、tsdown 浏览器 bundle
|
|
98
|
+
4. **test:package** — `lib/client.js` 含全部 CSS module class,再 `npm pack` 并跑打包后的 `dsh-prompt-templates --help`
|
|
99
|
+
|
|
100
|
+
GitHub Actions(`.github/workflows/verify.yml`)在指向 `master` 的 push / pull request 以及 `v*` tag 上用 Node 24 跑同一命令。`@deepseek-ai/*` devDependencies 来自公网 npm,CI 不需要 registry token,也不需要 harness 检出。
|
|
101
|
+
|
|
102
|
+
仍需人工、因为它们依赖真实 harness profile:启动 `dsh web`、浏览器面板对接真实 web server,以及用真实会话日志验证 resume / compaction。
|
|
103
|
+
|
|
93
104
|
## 已知限制
|
|
94
105
|
|
|
95
106
|
- **会话模板需要当前会话**——无会话打开时只能用全局模板
|
package/cordis.patch.yml
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
# dsh-prompt-templates bundle patch: mounts the prompt-templates plugin into
|
|
2
|
-
# the host composition of a dsh profile. The plugin registers its
|
|
3
|
-
# /plugins/dsh-prompt-templates routes into the shared web server and its
|
|
4
|
-
# settings namespace into the shared settings document, so it needs no realm.
|
|
5
|
-
#
|
|
6
|
-
# Install: `dsh plugin --profile <name> add <this package>` (npm, a local
|
|
7
|
-
# path, or Git). The `dsh plugin` command pnpm-installs the package into the
|
|
8
|
-
# profile and reconciles it into the profile's `dsh.profile.bundles` layer
|
|
9
|
-
# list.
|
|
10
|
-
#
|
|
11
|
-
# The host half is pure TS: templates persist through `node:sqlite`
|
|
12
|
-
# directly inside the host process (no Python child, no pythonBridge
|
|
13
|
-
# service dependency). The patch JS sandbox exposes `process`; the default
|
|
14
|
-
# database path already resolves under $DSH_HOME, so only overrides need it.
|
|
15
|
-
- insert:
|
|
16
|
-
- id: prompt-templates
|
|
17
|
-
# Node-resolvable package name — must stay in sync with package.json
|
|
18
|
-
# `name`. Quoted because `@` is a reserved YAML indicator.
|
|
19
|
-
name: '@nelsonlongxiang/dsh-prompt-templates'
|
|
20
|
-
config:
|
|
21
|
-
# Explicit SQLite database path so persistence lands under
|
|
22
|
-
# $DSH_HOME/ext/prompt-templates/ regardless of cwd or environment drift.
|
|
23
|
-
dbPath: !!js >
|
|
24
|
-
`${(process.env.DSH_HOME ?? `${process.getBuiltinModule('node:os').homedir()}/.dsh`).replace(/\\/g, '/')}/ext/prompt-templates/db.sqlite3`
|
|
25
|
-
# Scheduled auto-injection (defaults shown; the schema fills them when
|
|
26
|
-
# omitted, so these lines are optional):
|
|
27
|
-
# injectEnabled: true — master switch; false keeps the listener pass-through
|
|
28
|
-
# injectMaxEvery: 1000 — upper bound accepted for a template's interval
|
|
1
|
+
# dsh-prompt-templates bundle patch: mounts the prompt-templates plugin into
|
|
2
|
+
# the host composition of a dsh profile. The plugin registers its
|
|
3
|
+
# /plugins/dsh-prompt-templates routes into the shared web server and its
|
|
4
|
+
# settings namespace into the shared settings document, so it needs no realm.
|
|
5
|
+
#
|
|
6
|
+
# Install: `dsh plugin --profile <name> add <this package>` (npm, a local
|
|
7
|
+
# path, or Git). The `dsh plugin` command pnpm-installs the package into the
|
|
8
|
+
# profile and reconciles it into the profile's `dsh.profile.bundles` layer
|
|
9
|
+
# list.
|
|
10
|
+
#
|
|
11
|
+
# The host half is pure TS: templates persist through `node:sqlite`
|
|
12
|
+
# directly inside the host process (no Python child, no pythonBridge
|
|
13
|
+
# service dependency). The patch JS sandbox exposes `process`; the default
|
|
14
|
+
# database path already resolves under $DSH_HOME, so only overrides need it.
|
|
15
|
+
- insert:
|
|
16
|
+
- id: prompt-templates
|
|
17
|
+
# Node-resolvable package name — must stay in sync with package.json
|
|
18
|
+
# `name`. Quoted because `@` is a reserved YAML indicator.
|
|
19
|
+
name: '@nelsonlongxiang/dsh-prompt-templates'
|
|
20
|
+
config:
|
|
21
|
+
# Explicit SQLite database path so persistence lands under
|
|
22
|
+
# $DSH_HOME/ext/prompt-templates/ regardless of cwd or environment drift.
|
|
23
|
+
dbPath: !!js >
|
|
24
|
+
`${(process.env.DSH_HOME ?? `${process.getBuiltinModule('node:os').homedir()}/.dsh`).replace(/\\/g, '/')}/ext/prompt-templates/db.sqlite3`
|
|
25
|
+
# Scheduled auto-injection (defaults shown; the schema fills them when
|
|
26
|
+
# omitted, so these lines are optional):
|
|
27
|
+
# injectEnabled: true — master switch; false keeps the listener pass-through
|
|
28
|
+
# injectMaxEvery: 1000 — upper bound accepted for a template's interval
|
package/lib/cli/app.js
CHANGED
|
@@ -3,18 +3,18 @@ import { readFileSync, writeFileSync } from 'node:fs';
|
|
|
3
3
|
import { resolve } from 'node:path';
|
|
4
4
|
import { databaseSha256, exportDatabase, ImportBlockedError, importDatabase, searchTemplates } from "./database.js";
|
|
5
5
|
import { canonicalJson, diffSnapshots, mergeSnapshots, parseSnapshot } from "./model.js";
|
|
6
|
-
const HELP = `dsh-prompt-templates — deterministic prompt-template database sync
|
|
7
|
-
|
|
8
|
-
Usage:
|
|
9
|
-
dsh-prompt-templates export --db <path> --out <json> [--scope all|global|session] [--session-id <id>] [--output human|json]
|
|
10
|
-
dsh-prompt-templates diff <left.json> <right.json> [--output human|json] [--json] [--fail-on-diff]
|
|
11
|
-
dsh-prompt-templates merge <base.json> <incoming.json> --strategy newer|keep-base|keep-incoming --out <json> [--allow-name-conflicts] [--output human|json]
|
|
12
|
-
dsh-prompt-templates import --db <path> --in <json> [--apply --expect-db-sha256 <sha> --confirm-summary-hash <sha>] [--backup-out <path>] [--max-changes <n>] [--output human|json]
|
|
13
|
-
dsh-prompt-templates db-sha256 --db <path> [--output human|json]
|
|
14
|
-
dsh-prompt-templates search --db <path> [--query <text>] [--category <name>] [--session-id <id>] [--limit <n>] [--output human|json]
|
|
15
|
-
|
|
16
|
-
Import is dry-run by default. --apply requires --expect-db-sha256 and creates a SQLite backup before one atomic transaction.
|
|
17
|
-
Search is read-only: globals always searchable; session-private rows only with --session-id (never other sessions).
|
|
6
|
+
const HELP = `dsh-prompt-templates — deterministic prompt-template database sync
|
|
7
|
+
|
|
8
|
+
Usage:
|
|
9
|
+
dsh-prompt-templates export --db <path> --out <json> [--scope all|global|session] [--session-id <id>] [--output human|json]
|
|
10
|
+
dsh-prompt-templates diff <left.json> <right.json> [--output human|json] [--json] [--fail-on-diff]
|
|
11
|
+
dsh-prompt-templates merge <base.json> <incoming.json> --strategy newer|keep-base|keep-incoming --out <json> [--allow-name-conflicts] [--output human|json]
|
|
12
|
+
dsh-prompt-templates import --db <path> --in <json> [--apply --expect-db-sha256 <sha> --confirm-summary-hash <sha>] [--backup-out <path>] [--max-changes <n>] [--output human|json]
|
|
13
|
+
dsh-prompt-templates db-sha256 --db <path> [--output human|json]
|
|
14
|
+
dsh-prompt-templates search --db <path> [--query <text>] [--category <name>] [--session-id <id>] [--limit <n>] [--output human|json]
|
|
15
|
+
|
|
16
|
+
Import is dry-run by default. --apply requires --expect-db-sha256 and creates a SQLite backup before one atomic transaction.
|
|
17
|
+
Search is read-only: globals always searchable; session-private rows only with --session-id (never other sessions).
|
|
18
18
|
`;
|
|
19
19
|
export async function run(argv) {
|
|
20
20
|
const started = performance.now();
|
package/lib/cli/database.js
CHANGED
|
@@ -127,12 +127,12 @@ export async function importDatabase(dbPath, incoming, options) {
|
|
|
127
127
|
insertCategory.run(item.name, item.scope, item.session_id);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
-
const upsertTemplate = db.prepare(`INSERT INTO templates
|
|
131
|
-
(id,name,content,scope,session_id,description,position,category,inject_enabled,inject_every,mode,created_at,updated_at)
|
|
132
|
-
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)
|
|
133
|
-
ON CONFLICT(id) DO UPDATE SET name=excluded.name,content=excluded.content,scope=excluded.scope,
|
|
134
|
-
session_id=excluded.session_id,description=excluded.description,position=excluded.position,
|
|
135
|
-
category=excluded.category,inject_enabled=excluded.inject_enabled,inject_every=excluded.inject_every,
|
|
130
|
+
const upsertTemplate = db.prepare(`INSERT INTO templates
|
|
131
|
+
(id,name,content,scope,session_id,description,position,category,inject_enabled,inject_every,mode,created_at,updated_at)
|
|
132
|
+
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)
|
|
133
|
+
ON CONFLICT(id) DO UPDATE SET name=excluded.name,content=excluded.content,scope=excluded.scope,
|
|
134
|
+
session_id=excluded.session_id,description=excluded.description,position=excluded.position,
|
|
135
|
+
category=excluded.category,inject_enabled=excluded.inject_enabled,inject_every=excluded.inject_every,
|
|
136
136
|
mode=excluded.mode,created_at=excluded.created_at,updated_at=excluded.updated_at`);
|
|
137
137
|
for (const item of incoming.templates)
|
|
138
138
|
upsertTemplate.run(item.id, item.name, item.content, item.scope, item.session_id, item.description, item.position, item.category, item.inject_enabled ? 1 : 0, item.inject_every ?? null, item.mode, item.created_at, item.updated_at);
|
package/lib/client/Library.js
CHANGED
|
@@ -71,7 +71,7 @@ function TemplateForm({ initial, allowScope, sessionId, categories, t, submitLab
|
|
|
71
71
|
}, [name, content, scope, category, injectOn, injectEvery, mode, allowScope, sessionId, onSubmit, t, onDone]);
|
|
72
72
|
// Categories selectable for the CURRENT scope pick (matching partition).
|
|
73
73
|
const scopeCategories = categories.filter((cat) => cat.scope === scope && (cat.scope === 'global' || cat.session_id === sessionId));
|
|
74
|
-
return (_jsxs("div", { className: css.addForm, "data-prompt-add": true, children: [_jsx("input", { className: css.nameInput, type: "text", placeholder: t('panel.addName'), value: name, onChange: (e) => { setName(e.target.value); }, "aria-label": t('panel.addName') }), _jsx("textarea", { className: css.contentInput, placeholder: t('panel.addContent'), value: content, onChange: (e) => { setContent(e.target.value); }, rows: 3, "aria-label": t('panel.addContent') }), _jsxs("div", { className: css.injectRow, children: [_jsxs("label", { className: css.injectLabel, children: [_jsx("input", { type: "checkbox", checked: injectOn, onChange: (e) => { setInjectOn(e.target.checked); } }), t('panel.inject')] }), injectOn && (_jsxs("label", { className: css.injectLabel, children: [_jsx("input", { className: css.injectEveryInput, type: "number", min: 1, step: 1, value: injectEvery, onChange: (e) => { setInjectEvery(e.target.value); }, "aria-label": t('panel.injectEvery') }), t('panel.injectEvery')] })), injectOn && (_jsx("label", { className: css.injectLabel, title: t('panel.modeHint'), children: _jsxs("select", { value: mode, onChange: (e) => { setMode(e.target.value); }, "aria-label": t('panel.modeLabel'), children: [_jsx("option", { value: "inject", children: t('panel.modeInject') }), _jsx("option", { value: "visible", children: t('panel.modeVisible') })] }) }))] }), _jsxs("div", { className: css.addRow, children: [allowScope && (_jsx("label", { className: css.scopeLabel, children: _jsxs("select", { value: scope, onChange: (e) => { setScope(e.target.value); setCategory(null); }, "aria-label": "scope", children: [_jsx("option", { value: "global", children: t('panel.global') }), _jsx("option", { value: "session", disabled: sessionId === null, children: t('panel.session') })] }) })), _jsx("label", { className: css.scopeLabel, children: _jsxs("select", { value: category ?? '', onChange: (e) => { setCategory(e.target.value === '' ? null : e.target.value); }, "aria-label": t('panel.category'), children: [_jsx("option", { value: "", children: t('panel.categoryNone') }), scopeCategories.map((cat) => _jsx("option", { value: cat.name, children: cat.name }, `${cat.scope}:${cat.name}`))] }) }), _jsxs("div", { className: css.addActions, children: [error !== null && _jsx("span", { className: css.error, role: "alert", children: error }), onCancel !== undefined && (_jsx("button", { type: "button", className: css.cancelBtn, onClick: onCancel, disabled: busy, children: t('panel.addCancel') })), _jsx("button", { type: "button", className: css.saveBtn, onClick: () => void submit(), disabled: busy || name.trim() === '' || content.trim() === '', children: submitLabel })] })] })] }));
|
|
74
|
+
return (_jsxs("div", { className: css.addForm, "data-prompt-add": true, children: [_jsx("input", { className: css.nameInput, type: "text", placeholder: t('panel.addName'), value: name, onChange: (e) => { setName(e.target.value); }, "aria-label": t('panel.addName') }), _jsx("textarea", { className: css.contentInput, placeholder: t('panel.addContent'), value: content, onChange: (e) => { setContent(e.target.value); }, rows: 3, "aria-label": t('panel.addContent') }), _jsx("div", { className: css.variablesHint, children: t('panel.variablesHint') }), _jsxs("div", { className: css.injectRow, children: [_jsxs("label", { className: css.injectLabel, children: [_jsx("input", { type: "checkbox", checked: injectOn, onChange: (e) => { setInjectOn(e.target.checked); } }), t('panel.inject')] }), injectOn && (_jsxs("label", { className: css.injectLabel, children: [_jsx("input", { className: css.injectEveryInput, type: "number", min: 1, step: 1, value: injectEvery, onChange: (e) => { setInjectEvery(e.target.value); }, "aria-label": t('panel.injectEvery') }), t('panel.injectEvery')] })), injectOn && (_jsx("label", { className: css.injectLabel, title: t('panel.modeHint'), children: _jsxs("select", { value: mode, onChange: (e) => { setMode(e.target.value); }, "aria-label": t('panel.modeLabel'), children: [_jsx("option", { value: "inject", children: t('panel.modeInject') }), _jsx("option", { value: "visible", children: t('panel.modeVisible') })] }) }))] }), _jsxs("div", { className: css.addRow, children: [allowScope && (_jsx("label", { className: css.scopeLabel, children: _jsxs("select", { value: scope, onChange: (e) => { setScope(e.target.value); setCategory(null); }, "aria-label": "scope", children: [_jsx("option", { value: "global", children: t('panel.global') }), _jsx("option", { value: "session", disabled: sessionId === null, children: t('panel.session') })] }) })), _jsx("label", { className: css.scopeLabel, children: _jsxs("select", { value: category ?? '', onChange: (e) => { setCategory(e.target.value === '' ? null : e.target.value); }, "aria-label": t('panel.category'), children: [_jsx("option", { value: "", children: t('panel.categoryNone') }), scopeCategories.map((cat) => _jsx("option", { value: cat.name, children: cat.name }, `${cat.scope}:${cat.name}`))] }) }), _jsxs("div", { className: css.addActions, children: [error !== null && _jsx("span", { className: css.error, role: "alert", children: error }), onCancel !== undefined && (_jsx("button", { type: "button", className: css.cancelBtn, onClick: onCancel, disabled: busy, children: t('panel.addCancel') })), _jsx("button", { type: "button", className: css.saveBtn, onClick: () => void submit(), disabled: busy || name.trim() === '' || content.trim() === '', children: submitLabel })] })] })] }));
|
|
75
75
|
}
|
|
76
76
|
/** Inline form creating one category tab: name + scope (global, or the current session). */
|
|
77
77
|
function CategoryForm({ sessionId, createCategory, t, onDone }) {
|
|
@@ -112,7 +112,7 @@ function CategoryForm({ sessionId, createCategory, t, onDone }) {
|
|
|
112
112
|
* @param props - target session, shared verbs, locale, optional title-row takeover.
|
|
113
113
|
*/
|
|
114
114
|
export function TemplateLibrary({ sessionId, face, t, header, headerExtra }) {
|
|
115
|
-
const { refresh, refreshCategories, createCategory, removeCategory, create, update, remove, makeGlobal, insert, send, interject, injectStatus } = face;
|
|
115
|
+
const { refresh, refreshCategories, createCategory, removeCategory, create, update, remove, makeGlobal, insert, send, interject, injectStatus, injectionHistory } = face;
|
|
116
116
|
const [templates, setTemplates] = useState([]);
|
|
117
117
|
const [categories, setCategories] = useState([]);
|
|
118
118
|
const [showAdd, setShowAdd] = useState(false);
|
|
@@ -155,6 +155,23 @@ export function TemplateLibrary({ sessionId, face, t, header, headerExtra }) {
|
|
|
155
155
|
const timer = setInterval(() => { void pollStatus(); }, 30_000);
|
|
156
156
|
return () => { clearInterval(timer); };
|
|
157
157
|
}, [pollStatus]);
|
|
158
|
+
// Badge dropdown: the recent-injection history for the target session,
|
|
159
|
+
// fetched on demand (on open, on target change, and whenever a new
|
|
160
|
+
// injection lands while open) so the 30s badge poll stays O(1).
|
|
161
|
+
const [historyOpen, setHistoryOpen] = useState(false);
|
|
162
|
+
const [history, setHistory] = useState([]);
|
|
163
|
+
const loadHistory = useCallback(async () => {
|
|
164
|
+
if (sessionId === null) {
|
|
165
|
+
setHistory([]);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
setHistory(await injectionHistory(sessionId));
|
|
169
|
+
}, [injectionHistory, sessionId]);
|
|
170
|
+
useEffect(() => {
|
|
171
|
+
if (historyOpen)
|
|
172
|
+
void loadHistory();
|
|
173
|
+
}, [historyOpen, loadHistory, injected]);
|
|
174
|
+
useEffect(() => { setHistoryOpen(false); }, [sessionId]);
|
|
158
175
|
const handleInsert = useCallback((content) => {
|
|
159
176
|
if (sessionId === null)
|
|
160
177
|
return;
|
|
@@ -244,7 +261,7 @@ export function TemplateLibrary({ sessionId, face, t, header, headerExtra }) {
|
|
|
244
261
|
return result.ok;
|
|
245
262
|
}, onDone: () => { setEditingId(null); void load(); }, onCancel: () => { setEditingId(null); } }, row.id))
|
|
246
263
|
: (_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); }, onMakeGlobal: row.scope === 'session' ? (id) => { void handleMakeGlobal(id); } : undefined, onToggleInject: (tpl) => { void handleToggleInject(tpl); }, sortable: needle === '', onDragStart: (id) => { dragRowRef.current = id; }, onDropOn: (id) => { handleRowDrop(id); }, t: t }, row.id)));
|
|
247
|
-
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("
|
|
264
|
+
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] }))] }), headerExtra] }), 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}`)))] })), _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) => {
|
|
248
265
|
const key = `cat:${cat.scope}:${cat.name}`;
|
|
249
266
|
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.tabDelete, "aria-label": t('panel.deleteCategory'), title: t('panel.deleteCategory'), onClick: () => {
|
|
250
267
|
void (async () => {
|
package/lib/client/Panel.js
CHANGED
|
@@ -33,7 +33,7 @@ function clampToViewport(position) {
|
|
|
33
33
|
* @param props - runtime kit, injected face members, store handle, and locale.
|
|
34
34
|
*/
|
|
35
35
|
export function PromptPanel(props) {
|
|
36
|
-
const { useStore, refresh, refreshCategories, createCategory, removeCategory, create, update, remove, makeGlobal, insert, send, interject, injectStatus, targetSession, targetVersion, subscribeTarget, panelPosition, savePanelPosition, resetPanelPosition, actions, t, } = props;
|
|
36
|
+
const { useStore, refresh, refreshCategories, createCategory, removeCategory, create, update, remove, makeGlobal, insert, send, interject, injectStatus, injectionHistory, targetSession, targetVersion, subscribeTarget, panelPosition, savePanelPosition, resetPanelPosition, actions, t, } = props;
|
|
37
37
|
const open = useStore(s => s.open);
|
|
38
38
|
// Re-render whenever the delivery target changes: the composer entry
|
|
39
39
|
// attaches its session whenever its composer becomes the visible one, so
|
|
@@ -121,7 +121,7 @@ export function PromptPanel(props) {
|
|
|
121
121
|
const libraryFace = {
|
|
122
122
|
refresh, refreshCategories, createCategory, removeCategory,
|
|
123
123
|
create, update, remove, makeGlobal,
|
|
124
|
-
insert, send, interject, injectStatus,
|
|
124
|
+
insert, send, interject, injectStatus, injectionHistory,
|
|
125
125
|
};
|
|
126
126
|
return (_jsx("div", { className: css.panel, "data-prompt-panel": true, ref: panelRef, style: placementStyle, children: _jsx(TemplateLibrary, { sessionId: sessionId, face: libraryFace, t: t, header: {
|
|
127
127
|
onPointerDown: onHeaderPointerDown,
|
package/lib/client/PromptTab.js
CHANGED
|
@@ -6,6 +6,6 @@ import css from './Panel.module.css';
|
|
|
6
6
|
* @param props - runtime kit (carries sessionId), injected face members, locale.
|
|
7
7
|
*/
|
|
8
8
|
export function PromptTab(props) {
|
|
9
|
-
const { sessionId, refresh, refreshCategories, createCategory, removeCategory, create, update, remove, makeGlobal, insert, send, interject, injectStatus, t, } = props;
|
|
10
|
-
return (_jsx("div", { className: css.tabBody, "data-prompt-tab": true, children: _jsx(TemplateLibrary, { sessionId: sessionId, face: { refresh, refreshCategories, createCategory, removeCategory, create, update, remove, makeGlobal, insert, send, interject, injectStatus }, t: t }) }));
|
|
9
|
+
const { sessionId, refresh, refreshCategories, createCategory, removeCategory, create, update, remove, makeGlobal, insert, send, interject, injectStatus, injectionHistory, t, } = props;
|
|
10
|
+
return (_jsx("div", { className: css.tabBody, "data-prompt-tab": true, children: _jsx(TemplateLibrary, { sessionId: sessionId, face: { refresh, refreshCategories, createCategory, removeCategory, create, update, remove, makeGlobal, insert, send, interject, injectStatus, injectionHistory }, t: t }) }));
|
|
11
11
|
}
|
package/lib/client/api.js
CHANGED
|
@@ -21,6 +21,14 @@ export async function injectStatus(sessionId) {
|
|
|
21
21
|
const body = await response.json();
|
|
22
22
|
return body.status ?? null;
|
|
23
23
|
}
|
|
24
|
+
/** Load a session recent scheduled injections, newest first (empty when none). */
|
|
25
|
+
export async function injectionHistory(sessionId) {
|
|
26
|
+
const response = await fetch(`${BASE}/inject-status?session_id=${encodeURIComponent(sessionId)}`, { cache: 'no-store' });
|
|
27
|
+
if (!response.ok)
|
|
28
|
+
return [];
|
|
29
|
+
const body = await response.json();
|
|
30
|
+
return [...body.history ?? []];
|
|
31
|
+
}
|
|
24
32
|
/** Load every user category tab (global + all sessions'; the panel filters). */
|
|
25
33
|
export async function listCategories() {
|
|
26
34
|
const response = await fetch(`${BASE}/categories`, { cache: 'no-store' });
|
package/lib/client/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { listTemplates, listCategories, injectStatus, createCategory, deleteCategory, createTemplate, updateTemplate, deleteTemplate, makeTemplateGlobal, } from "./api.js";
|
|
1
|
+
import { listTemplates, listCategories, injectStatus, injectionHistory, createCategory, deleteCategory, createTemplate, updateTemplate, deleteTemplate, makeTemplateGlobal, } from "./api.js";
|
|
2
2
|
import { PromptPanel } from "./Panel.js";
|
|
3
3
|
import { PanelButton } from "./PanelButton.js";
|
|
4
4
|
import { PromptTab } from "./PromptTab.js";
|
|
@@ -63,6 +63,7 @@ export function apply(ctx) {
|
|
|
63
63
|
controller.interject(sessionId, content);
|
|
64
64
|
},
|
|
65
65
|
injectStatus,
|
|
66
|
+
injectionHistory,
|
|
66
67
|
};
|
|
67
68
|
// Persisted prefs binding, filled by the overlay seat's inject (the seat
|
|
68
69
|
// owns the store instance; the face reads through these closures).
|
package/lib/client/locales.js
CHANGED
|
@@ -11,6 +11,8 @@ export const zh = {
|
|
|
11
11
|
'panel.searchCount': '匹配数 / 可搜索总数',
|
|
12
12
|
'panel.tabCount': '当前分类模板数',
|
|
13
13
|
'panel.injectedAt': '定时注入至轮次',
|
|
14
|
+
'panel.historyTitle': '最近定时注入',
|
|
15
|
+
'panel.historyEmpty': '本次启动后还没有定时注入',
|
|
14
16
|
'panel.github': '在 GitHub 查看源码',
|
|
15
17
|
'panel.noMatch': '没有匹配的模板',
|
|
16
18
|
'panel.global': '全局模板',
|
|
@@ -32,6 +34,7 @@ export const zh = {
|
|
|
32
34
|
'panel.makeGlobal': '设为全局',
|
|
33
35
|
'panel.inject': '定时注入',
|
|
34
36
|
'panel.injectEvery': '注入间隔(轮)',
|
|
37
|
+
'panel.variablesHint': '支持变量:{{date}} {{time}} {{datetime}} {{weekday}} {{session}} {{turn}}(发送/注入时展开,不可得时保留原文)',
|
|
35
38
|
'panel.modeLabel': '注入呈现方式',
|
|
36
39
|
'panel.modeInject': '静默注入',
|
|
37
40
|
'panel.modeVisible': '对话流可见',
|
|
@@ -55,6 +58,8 @@ export const en = {
|
|
|
55
58
|
'panel.searchCount': 'Matches / total searchable',
|
|
56
59
|
'panel.tabCount': 'Templates in current tab',
|
|
57
60
|
'panel.injectedAt': 'Scheduled injection at turn',
|
|
61
|
+
'panel.historyTitle': 'Recent injections',
|
|
62
|
+
'panel.historyEmpty': 'No scheduled injections since boot',
|
|
58
63
|
'panel.github': 'View source on GitHub',
|
|
59
64
|
'panel.noMatch': 'No matching templates',
|
|
60
65
|
'panel.global': 'Global templates',
|
|
@@ -76,6 +81,7 @@ export const en = {
|
|
|
76
81
|
'panel.makeGlobal': 'Make global',
|
|
77
82
|
'panel.inject': 'Auto-inject',
|
|
78
83
|
'panel.injectEvery': 'Every (rounds)',
|
|
84
|
+
'panel.variablesHint': 'Variables: {{date}} {{time}} {{datetime}} {{weekday}} {{session}} {{turn}} (expanded at delivery; unresolved stay literal)',
|
|
79
85
|
'panel.modeLabel': 'Injection delivery',
|
|
80
86
|
'panel.modeInject': 'Silent (model-only)',
|
|
81
87
|
'panel.modeVisible': 'Visible in chat',
|
package/lib/client/service.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { expandTemplateVariables } from "../variables.js";
|
|
1
2
|
/**
|
|
2
3
|
* Cross-entry panel face (ctx.promptPanel).
|
|
3
4
|
*/
|
|
@@ -95,11 +96,12 @@ export class PromptPanelController {
|
|
|
95
96
|
const input = this.#inputOf(sessionId);
|
|
96
97
|
if (input === undefined)
|
|
97
98
|
return;
|
|
99
|
+
const text = expandTemplateVariables(content, { sessionId });
|
|
98
100
|
const actions = input.actions;
|
|
99
101
|
if (actions !== undefined) {
|
|
100
102
|
try {
|
|
101
103
|
const span = actions.captureInsertion();
|
|
102
|
-
if (span !== undefined && actions.insertText(
|
|
104
|
+
if (span !== undefined && actions.insertText(text, span))
|
|
103
105
|
return;
|
|
104
106
|
}
|
|
105
107
|
catch {
|
|
@@ -107,7 +109,7 @@ export class PromptPanelController {
|
|
|
107
109
|
}
|
|
108
110
|
}
|
|
109
111
|
const draft = input.state.getSnapshot().draft;
|
|
110
|
-
input.setDraft(draft === '' ?
|
|
112
|
+
input.setDraft(draft === '' ? text : `${draft}\n${text}`);
|
|
111
113
|
}
|
|
112
114
|
/**
|
|
113
115
|
* Interject one template: steer it into the running agent turn. With
|
|
@@ -121,7 +123,7 @@ export class PromptPanelController {
|
|
|
121
123
|
const input = this.#inputOf(sessionId);
|
|
122
124
|
if (input === undefined)
|
|
123
125
|
return;
|
|
124
|
-
input.setDraft(content);
|
|
126
|
+
input.setDraft(expandTemplateVariables(content, { sessionId }));
|
|
125
127
|
input.submit('steer');
|
|
126
128
|
}
|
|
127
129
|
/**
|
|
@@ -134,7 +136,7 @@ export class PromptPanelController {
|
|
|
134
136
|
const input = this.#inputOf(sessionId);
|
|
135
137
|
if (input === undefined)
|
|
136
138
|
return;
|
|
137
|
-
input.setDraft(content);
|
|
139
|
+
input.setDraft(expandTemplateVariables(content, { sessionId }));
|
|
138
140
|
input.submit();
|
|
139
141
|
}
|
|
140
142
|
/** Resolve a session's input facade, or undefined when out of reach. */
|