@nelsonlongxiang/dsh-prompt-templates 0.4.4 → 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 +113 -62
- package/README_zh.md +112 -62
- package/cordis.patch.yml +4 -0
- package/lib/cli/app.js +169 -0
- package/lib/cli/database.js +162 -0
- package/lib/cli/main.js +6 -0
- package/lib/cli/model.js +247 -0
- package/lib/client/Library.js +290 -0
- package/lib/client/Panel.js +37 -201
- package/lib/client/PanelButton.js +27 -3
- package/lib/client/PromptTab.js +11 -0
- package/lib/client/api.js +16 -0
- package/lib/client/filter.js +27 -0
- package/lib/client/index.js +53 -36
- package/lib/client/locales.js +34 -2
- package/lib/client/meta.js +10 -0
- package/lib/client/service.js +57 -37
- package/lib/client/slots.js +5 -3
- package/lib/client/store.js +12 -1
- package/lib/client/tab.js +32 -0
- package/lib/client.js +798 -286
- package/lib/client.js.map +1 -1
- package/lib/index.js +35 -16
- package/lib/inject.js +236 -0
- package/lib/invariant.js +1 -1
- package/lib/store.js +108 -32
- package/lib/types/cli/app.d.ts +1 -0
- package/lib/types/cli/database.d.ts +69 -0
- package/lib/types/cli/main.d.ts +2 -0
- package/lib/types/cli/model.d.ts +62 -0
- package/lib/types/client/Library.d.ts +34 -0
- package/lib/types/client/Panel.d.ts +1 -1
- package/lib/types/client/PanelButton.d.ts +10 -9
- package/lib/types/client/PromptTab.d.ts +17 -0
- package/lib/types/client/api.d.ts +11 -1
- package/lib/types/client/filter.d.ts +10 -0
- package/lib/types/client/index.d.ts +6 -2
- package/lib/types/client/locales.d.ts +34 -2
- package/lib/types/client/meta.d.ts +6 -0
- package/lib/types/client/service.d.ts +50 -6
- package/lib/types/client/slots.d.ts +57 -5
- package/lib/types/client/store.d.ts +14 -1
- package/lib/types/client/tab.d.ts +31 -0
- package/lib/types/index.d.ts +8 -1
- package/lib/types/inject.d.ts +150 -0
- package/lib/types/store.d.ts +27 -4
- package/lib/types/types.d.ts +49 -0
- package/lib/types/variables.d.ts +24 -0
- package/lib/variables.js +36 -0
- package/package.json +98 -105
|
@@ -1,9 +1,33 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Composer entry button: toggles the quick prompt panel. Registered into
|
|
4
|
+
* conversation.input.right (the tool row, before the send button). The
|
|
5
|
+
* session-scoped inject face carries the toggle verb, which routes through
|
|
6
|
+
* ctx.promptPanel to the panel's store. The standard kit delivers this
|
|
7
|
+
* composer's sessionId as a prop; the button attaches the panel to that
|
|
8
|
+
* session whenever its composer becomes the visible one — on mount, on
|
|
9
|
+
* session change, and at click — so inserts and sends land in the
|
|
10
|
+
* conversation the user is looking at, even right after a switch.
|
|
11
|
+
*/
|
|
12
|
+
import { useEffect } from 'react';
|
|
2
13
|
import css from './PanelButton.module.css';
|
|
3
14
|
/**
|
|
4
15
|
* The composer tool-row button.
|
|
5
|
-
* @param props - runtime kit (
|
|
16
|
+
* @param props - runtime kit (the composer's sessionId), the toggle + attach verbs, and the locale seat.
|
|
6
17
|
*/
|
|
7
|
-
export function PanelButton({ toggle, t }) {
|
|
8
|
-
|
|
18
|
+
export function PanelButton({ toggle, attachSession, sessionId, t }) {
|
|
19
|
+
// Keep the panel's delivery target glued to this composer: the effect
|
|
20
|
+
// fires when this composer becomes the visible one (mount or session
|
|
21
|
+
// swap), not only at click time — otherwise switching sessions leaves
|
|
22
|
+
// the panel pointing at the previous conversation whose input scope may
|
|
23
|
+
// be gone, and send/insert would silently drop.
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (sessionId !== undefined)
|
|
26
|
+
attachSession(sessionId);
|
|
27
|
+
}, [sessionId, attachSession]);
|
|
28
|
+
return (_jsx("button", { type: "button", className: css.button, onClick: () => {
|
|
29
|
+
if (sessionId !== undefined)
|
|
30
|
+
attachSession(sessionId);
|
|
31
|
+
toggle();
|
|
32
|
+
}, "aria-label": t('panel.open'), "aria-pressed": "false", title: t('panel.title'), children: _jsx("span", { className: css.glyph, children: "\u25A4" }) }));
|
|
9
33
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { TemplateLibrary } from "./Library.js";
|
|
3
|
+
import css from './Panel.module.css';
|
|
4
|
+
/**
|
|
5
|
+
* The prompt-templates sidebar tab body.
|
|
6
|
+
* @param props - runtime kit (carries sessionId), injected face members, locale.
|
|
7
|
+
*/
|
|
8
|
+
export function PromptTab(props) {
|
|
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
|
+
}
|
package/lib/client/api.js
CHANGED
|
@@ -13,6 +13,22 @@ export async function listTemplates() {
|
|
|
13
13
|
const body = await response.json();
|
|
14
14
|
return [...body.items ?? []];
|
|
15
15
|
}
|
|
16
|
+
/** Poll a session's latest scheduled injection; null when none since boot (badges hide). */
|
|
17
|
+
export async function injectStatus(sessionId) {
|
|
18
|
+
const response = await fetch(`${BASE}/inject-status?session_id=${encodeURIComponent(sessionId)}`, { cache: 'no-store' });
|
|
19
|
+
if (!response.ok)
|
|
20
|
+
return null;
|
|
21
|
+
const body = await response.json();
|
|
22
|
+
return body.status ?? null;
|
|
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
|
+
}
|
|
16
32
|
/** Load every user category tab (global + all sessions'; the panel filters). */
|
|
17
33
|
export async function listCategories() {
|
|
18
34
|
const response = await fetch(`${BASE}/categories`, { cache: 'no-store' });
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filter the panel's rows. A non-empty query is global across every category
|
|
3
|
+
* while respecting privacy: every global template and only the current
|
|
4
|
+
* session's private templates are searchable. With no query, the active tab
|
|
5
|
+
* keeps its normal partition/category semantics.
|
|
6
|
+
*/
|
|
7
|
+
/** All templates a search is allowed to inspect (global + current session). */
|
|
8
|
+
export function searchableTemplateRows(templates, sessionId) {
|
|
9
|
+
return templates.filter(row => row.scope === 'global' || (row.scope === 'session' && row.session_id === sessionId));
|
|
10
|
+
}
|
|
11
|
+
export function filterTemplateRows(templates, query, effectiveTab, activeCategory, sessionId) {
|
|
12
|
+
const needle = query.trim().toLowerCase();
|
|
13
|
+
const matches = (row) => row.name.toLowerCase().includes(needle) || row.content.toLowerCase().includes(needle);
|
|
14
|
+
if (needle !== '') {
|
|
15
|
+
return searchableTemplateRows(templates, sessionId).filter(matches);
|
|
16
|
+
}
|
|
17
|
+
return templates.filter((row) => {
|
|
18
|
+
if (effectiveTab === 'global')
|
|
19
|
+
return row.scope === 'global' && row.category === null;
|
|
20
|
+
if (effectiveTab === 'session')
|
|
21
|
+
return row.scope === 'session' && row.session_id === sessionId && row.category === null;
|
|
22
|
+
return activeCategory !== undefined
|
|
23
|
+
&& row.category === activeCategory.name
|
|
24
|
+
&& row.scope === activeCategory.scope
|
|
25
|
+
&& (activeCategory.scope === 'global' || row.session_id === sessionId);
|
|
26
|
+
});
|
|
27
|
+
}
|
package/lib/client/index.js
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
import { listTemplates, listCategories, 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
|
+
import { PromptTab } from "./PromptTab.js";
|
|
5
|
+
import { PROMPT_TEMPLATES_ID, promptTemplatesTabDefinition } from "./tab.js";
|
|
4
6
|
import { createPromptPanelStore } from "./store.js";
|
|
5
7
|
import { PromptPanelController } from "./service.js";
|
|
6
8
|
import { en, zh } from "./locales.js";
|
|
7
9
|
export { PromptPanel } from "./Panel.js";
|
|
8
10
|
export { PanelButton } from "./PanelButton.js";
|
|
11
|
+
export { PromptTab } from "./PromptTab.js";
|
|
12
|
+
export { PROMPT_TEMPLATES_KIND, PROMPT_TEMPLATES_ID, promptTemplatesTabDefinition } from "./tab.js";
|
|
9
13
|
export { PromptPanelController } from "./service.js";
|
|
10
14
|
/** Dictionary namespace owned by this plugin. */
|
|
11
15
|
const NS = 'promptTemplates';
|
|
12
16
|
/** Required services: slots, sessions, locale, conversation, and settings scope. */
|
|
13
|
-
export const inject = ['slots', 'sessions', 'locale', 'conversation'
|
|
17
|
+
export const inject = ['slots', 'sessions', 'locale', 'conversation'];
|
|
18
|
+
/** The promptTemplates settings section (registered host-side; optional). */
|
|
14
19
|
/**
|
|
15
20
|
* Client plugin body: the shell.overlay panel owns the store; the controller
|
|
16
21
|
* bridges its actions to the composer entry and performs inserts.
|
|
@@ -21,13 +26,13 @@ export function apply(ctx) {
|
|
|
21
26
|
const controller = new PromptPanelController();
|
|
22
27
|
controller.bind({ sessions: ctx.sessions, conversation: ctx.conversation });
|
|
23
28
|
ctx.effect(() => ctx.reflect.provide('promptPanel', controller), 'ui-prompt-templates: panel service');
|
|
24
|
-
|
|
25
|
-
//
|
|
26
|
-
// feeds the
|
|
27
|
-
// inject evaluation would loop the
|
|
29
|
+
// The library verbs, created exactly once and shared by BOTH surfaces:
|
|
30
|
+
// the floating panel face and the sidebar tab body. The `refresh`
|
|
31
|
+
// identity feeds the load-effect dependency arrays, so a fresh object per
|
|
32
|
+
// inject evaluation would loop the effects. refresh pulls EVERYTHING and
|
|
28
33
|
// the component groups rows — a server-side session_id filter would hide
|
|
29
34
|
// the global rows (their session_id is NULL and never matches).
|
|
30
|
-
const
|
|
35
|
+
const verbs = {
|
|
31
36
|
refresh: listTemplates,
|
|
32
37
|
refreshCategories: listCategories,
|
|
33
38
|
createCategory: (request) => {
|
|
@@ -57,38 +62,26 @@ export function apply(ctx) {
|
|
|
57
62
|
interject: (sessionId, content) => {
|
|
58
63
|
controller.interject(sessionId, content);
|
|
59
64
|
},
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
injectStatus,
|
|
66
|
+
injectionHistory,
|
|
67
|
+
};
|
|
68
|
+
// Persisted prefs binding, filled by the overlay seat's inject (the seat
|
|
69
|
+
// owns the store instance; the face reads through these closures).
|
|
70
|
+
let prefsActions;
|
|
71
|
+
let prefsSnapshot;
|
|
72
|
+
const panelFace = {
|
|
73
|
+
...verbs,
|
|
74
|
+
targetSession: () => controller.targetSession() ?? null,
|
|
75
|
+
targetVersion: () => controller.targetVersion(),
|
|
76
|
+
subscribeTarget: (notify) => controller.subscribeTarget(notify),
|
|
77
|
+
panelPosition: () => prefsSnapshot?.().panel ?? null,
|
|
69
78
|
savePanelPosition: (position) => {
|
|
70
|
-
|
|
79
|
+
prefsActions?.setPosition(position.x, position.y);
|
|
71
80
|
},
|
|
72
81
|
resetPanelPosition: () => {
|
|
73
|
-
|
|
82
|
+
prefsActions?.resetPosition();
|
|
74
83
|
},
|
|
75
84
|
};
|
|
76
|
-
// Settings-driven default open: applied once per store lifetime, only
|
|
77
|
-
// while the user has never touched the panel. The scope is a snapshot
|
|
78
|
-
// source, so the subscription re-checks when the host document lands (the
|
|
79
|
-
// initial read usually races the settings transport). Before the entry
|
|
80
|
-
// renders, openOnce parks the request and attach() replays it.
|
|
81
|
-
const applyDefaultOpen = () => {
|
|
82
|
-
const snapshot = uiSettings.getSnapshot();
|
|
83
|
-
if (snapshot.status === 'ready' && snapshot.value?.defaultOpen === true) {
|
|
84
|
-
controller.openOnce();
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
ctx.effect(() => {
|
|
88
|
-
const unsubscribe = uiSettings.subscribe(applyDefaultOpen);
|
|
89
|
-
return () => { unsubscribe(); };
|
|
90
|
-
}, 'ui-prompt-templates: default-open watch');
|
|
91
|
-
applyDefaultOpen();
|
|
92
85
|
// The shell.overlay entry: root scope, owns the panel store; the inject
|
|
93
86
|
// hook hands the bound actions to the controller and the shared face.
|
|
94
87
|
ctx.slots.inject('shell.overlay', () => ctx.slots.register({
|
|
@@ -97,13 +90,19 @@ export function apply(ctx) {
|
|
|
97
90
|
order: 10,
|
|
98
91
|
locale: NS,
|
|
99
92
|
store: createPromptPanelStore,
|
|
100
|
-
inject: (actions) => {
|
|
93
|
+
inject: (actions, store) => {
|
|
101
94
|
// attach is a side effect on the controller; the face is the data verbs.
|
|
102
95
|
controller.attach(actions);
|
|
96
|
+
if (store !== undefined) {
|
|
97
|
+
const s = store;
|
|
98
|
+
prefsActions = s.actions;
|
|
99
|
+
prefsSnapshot = () => s.getSnapshot();
|
|
100
|
+
}
|
|
103
101
|
return panelFace;
|
|
104
102
|
},
|
|
105
103
|
}, PromptPanel));
|
|
106
|
-
// The composer entry: session scope,
|
|
104
|
+
// The composer entry: session scope, attaches the panel to this composer's
|
|
105
|
+
// session at click time and toggles it via the controller.
|
|
107
106
|
ctx.slots.inject('conversation.input.right', () => ctx.slots.register({
|
|
108
107
|
name: 'conversation.input.right',
|
|
109
108
|
id: 'prompt-templates',
|
|
@@ -111,6 +110,24 @@ export function apply(ctx) {
|
|
|
111
110
|
locale: NS,
|
|
112
111
|
inject: () => ({
|
|
113
112
|
toggle: () => { controller.toggle(); },
|
|
113
|
+
attachSession: (sessionId) => { controller.setTargetSession(sessionId); },
|
|
114
114
|
}),
|
|
115
115
|
}, PanelButton));
|
|
116
|
+
// The right-sidebar tab: a page type (opened by kind from the guide '+'
|
|
117
|
+
// picker) whose body lands in the session-scoped
|
|
118
|
+
// 'sidebar.right.pane.tab' seat under the definition's own id — the
|
|
119
|
+
// body's standard props carry the sessionId of the session the sidebar
|
|
120
|
+
// is viewing, so no composer attachment is needed. Optional injection:
|
|
121
|
+
// on a base without the sidebar services the whole block (type AND
|
|
122
|
+
// body) simply never activates, and the floating panel keeps working.
|
|
123
|
+
ctx.inject(['sidebarRightTabs'], (ctx) => {
|
|
124
|
+
const t = ctx.locale.bind(NS);
|
|
125
|
+
ctx.effect(() => ctx.sidebarRightTabs.register(promptTemplatesTabDefinition(t)), 'ui-prompt-templates: sidebar tab type');
|
|
126
|
+
ctx.slots.inject('sidebar.right.pane.tab', () => ctx.slots.register({
|
|
127
|
+
name: 'sidebar.right.pane.tab',
|
|
128
|
+
key: PROMPT_TEMPLATES_ID,
|
|
129
|
+
locale: NS,
|
|
130
|
+
inject: () => verbs,
|
|
131
|
+
}, PromptTab));
|
|
132
|
+
});
|
|
116
133
|
}
|
package/lib/client/locales.js
CHANGED
|
@@ -7,7 +7,13 @@ export const zh = {
|
|
|
7
7
|
'panel.open': '打开提示词面板',
|
|
8
8
|
'panel.close': '关闭提示词面板',
|
|
9
9
|
'panel.empty': '暂无模板',
|
|
10
|
-
'panel.search': '
|
|
10
|
+
'panel.search': '搜索全部模板…',
|
|
11
|
+
'panel.searchCount': '匹配数 / 可搜索总数',
|
|
12
|
+
'panel.tabCount': '当前分类模板数',
|
|
13
|
+
'panel.injectedAt': '定时注入至轮次',
|
|
14
|
+
'panel.historyTitle': '最近定时注入',
|
|
15
|
+
'panel.historyEmpty': '本次启动后还没有定时注入',
|
|
16
|
+
'panel.github': '在 GitHub 查看源码',
|
|
11
17
|
'panel.noMatch': '没有匹配的模板',
|
|
12
18
|
'panel.global': '全局模板',
|
|
13
19
|
'panel.session': '会话模板',
|
|
@@ -26,9 +32,19 @@ export const zh = {
|
|
|
26
32
|
'panel.delete': '删除',
|
|
27
33
|
'panel.edit': '编辑',
|
|
28
34
|
'panel.makeGlobal': '设为全局',
|
|
35
|
+
'panel.inject': '定时注入',
|
|
36
|
+
'panel.injectEvery': '注入间隔(轮)',
|
|
37
|
+
'panel.variablesHint': '支持变量:{{date}} {{time}} {{datetime}} {{weekday}} {{session}} {{turn}}(发送/注入时展开,不可得时保留原文)',
|
|
38
|
+
'panel.modeLabel': '注入呈现方式',
|
|
39
|
+
'panel.modeInject': '静默注入',
|
|
40
|
+
'panel.modeVisible': '对话流可见',
|
|
41
|
+
'panel.modeHint': '静默:只进模型上下文(对话流不显示,基座设计);可见:以用户消息样式显示在对话流中,带"⚙️ 定时注入"标记',
|
|
29
42
|
'panel.error': '操作失败',
|
|
30
43
|
'panel.inserted': '已插入',
|
|
31
44
|
'panel.none': '无',
|
|
45
|
+
'tab.title': '提示词',
|
|
46
|
+
'tab.guideTitle': '提示词模板',
|
|
47
|
+
'tab.guideDescription': '模板库:插入、发送、定时注入',
|
|
32
48
|
};
|
|
33
49
|
/** English dictionary. */
|
|
34
50
|
export const en = {
|
|
@@ -38,7 +54,13 @@ export const en = {
|
|
|
38
54
|
'panel.open': 'Open prompt panel',
|
|
39
55
|
'panel.close': 'Close prompt panel',
|
|
40
56
|
'panel.empty': 'No templates yet',
|
|
41
|
-
'panel.search': 'Search templates…',
|
|
57
|
+
'panel.search': 'Search all templates…',
|
|
58
|
+
'panel.searchCount': 'Matches / total searchable',
|
|
59
|
+
'panel.tabCount': 'Templates in current tab',
|
|
60
|
+
'panel.injectedAt': 'Scheduled injection at turn',
|
|
61
|
+
'panel.historyTitle': 'Recent injections',
|
|
62
|
+
'panel.historyEmpty': 'No scheduled injections since boot',
|
|
63
|
+
'panel.github': 'View source on GitHub',
|
|
42
64
|
'panel.noMatch': 'No matching templates',
|
|
43
65
|
'panel.global': 'Global templates',
|
|
44
66
|
'panel.session': 'Session templates',
|
|
@@ -57,7 +79,17 @@ export const en = {
|
|
|
57
79
|
'panel.delete': 'Delete',
|
|
58
80
|
'panel.edit': 'Edit',
|
|
59
81
|
'panel.makeGlobal': 'Make global',
|
|
82
|
+
'panel.inject': 'Auto-inject',
|
|
83
|
+
'panel.injectEvery': 'Every (rounds)',
|
|
84
|
+
'panel.variablesHint': 'Variables: {{date}} {{time}} {{datetime}} {{weekday}} {{session}} {{turn}} (expanded at delivery; unresolved stay literal)',
|
|
85
|
+
'panel.modeLabel': 'Injection delivery',
|
|
86
|
+
'panel.modeInject': 'Silent (model-only)',
|
|
87
|
+
'panel.modeVisible': 'Visible in chat',
|
|
88
|
+
'panel.modeHint': 'Silent: model context only (omitted from the chat transcript by base design); Visible: rendered as a user message in the chat flow, headed by a ⚙️ scheduled-injection marker',
|
|
60
89
|
'panel.error': 'Operation failed',
|
|
61
90
|
'panel.inserted': 'Inserted',
|
|
62
91
|
'panel.none': 'None',
|
|
92
|
+
'tab.title': 'Prompts',
|
|
93
|
+
'tab.guideTitle': 'Prompt templates',
|
|
94
|
+
'tab.guideDescription': 'Template library: insert, send, auto-inject',
|
|
63
95
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Canonical public source repository for the panel's metadata link. */
|
|
2
|
+
export const GITHUB_REPOSITORY_URL = 'https://github.com/NelsonLongXiang/dsh-prompt-templates';
|
|
3
|
+
/** Build-injected package version; `dev` only exists in unbundled unit tests. */
|
|
4
|
+
export const PLUGIN_VERSION = typeof __PROMPT_TEMPLATES_VERSION__ === 'string'
|
|
5
|
+
? __PROMPT_TEMPLATES_VERSION__
|
|
6
|
+
: 'dev';
|
|
7
|
+
/** Header count: current-tab size when idle, matched/searchable when searching. */
|
|
8
|
+
export function templateCountLabel(matched, searchable, searching) {
|
|
9
|
+
return searching ? `${matched}/${searchable}` : String(matched);
|
|
10
|
+
}
|
package/lib/client/service.js
CHANGED
|
@@ -1,19 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Locate the composer textarea for one draft. The input machine publishes
|
|
3
|
-
* no caret, so the caret can only be read from the DOM: of every textarea
|
|
4
|
-
* on the page, the one whose value equals the draft snapshot is the
|
|
5
|
-
* composer (the panel's own form fields never hold the draft). Falls back
|
|
6
|
-
* to null when no match exists (detached DOM, session switched mid-click).
|
|
7
|
-
*/
|
|
8
|
-
function composerTextarea(draft) {
|
|
9
|
-
if (typeof document === 'undefined')
|
|
10
|
-
return null;
|
|
11
|
-
for (const el of Array.from(document.querySelectorAll('textarea'))) {
|
|
12
|
-
if (el.value === draft)
|
|
13
|
-
return el;
|
|
14
|
-
}
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
1
|
+
import { expandTemplateVariables } from "../variables.js";
|
|
17
2
|
/**
|
|
18
3
|
* Cross-entry panel face (ctx.promptPanel).
|
|
19
4
|
*/
|
|
@@ -22,6 +7,11 @@ export class PromptPanelController {
|
|
|
22
7
|
#sessions;
|
|
23
8
|
#conversation;
|
|
24
9
|
#pendingAutoOpen = false;
|
|
10
|
+
/** Session whose composer entry last opened the panel (delivery target). */
|
|
11
|
+
#targetSession;
|
|
12
|
+
/** Bumped every time the delivery target changes; drives the open panel's re-render. */
|
|
13
|
+
#targetVersion = 0;
|
|
14
|
+
#targetListeners = new Set();
|
|
25
15
|
/**
|
|
26
16
|
* Adopt the shell.overlay entry's bound store actions. Called from that
|
|
27
17
|
* registration's inject hook; a re-register overwrites the stale set. A
|
|
@@ -48,6 +38,35 @@ export class PromptPanelController {
|
|
|
48
38
|
toggle() {
|
|
49
39
|
this.#require().toggle();
|
|
50
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Record the panel's delivery target. Called by the session-scoped
|
|
43
|
+
* composer entry when its session becomes the visible one (mount or
|
|
44
|
+
* session change) and again at click time, so the target always follows
|
|
45
|
+
* the conversation the user is looking at — switching sessions must not
|
|
46
|
+
* leave the panel pointed at a detached composer whose scope (and
|
|
47
|
+
* send/insert path) has gone away.
|
|
48
|
+
*/
|
|
49
|
+
setTargetSession(sessionId) {
|
|
50
|
+
if (this.#targetSession === sessionId)
|
|
51
|
+
return;
|
|
52
|
+
this.#targetSession = sessionId;
|
|
53
|
+
this.#targetVersion += 1;
|
|
54
|
+
for (const notify of this.#targetListeners)
|
|
55
|
+
notify();
|
|
56
|
+
}
|
|
57
|
+
/** The session whose composer last opened the panel, if any. */
|
|
58
|
+
targetSession() {
|
|
59
|
+
return this.#targetSession;
|
|
60
|
+
}
|
|
61
|
+
/** Monotonic change counter of the delivery target (snapshot for useSyncExternalStore). */
|
|
62
|
+
targetVersion() {
|
|
63
|
+
return this.#targetVersion;
|
|
64
|
+
}
|
|
65
|
+
/** Subscribe to delivery-target changes; returns the unsubscribe function. */
|
|
66
|
+
subscribeTarget(notify) {
|
|
67
|
+
this.#targetListeners.add(notify);
|
|
68
|
+
return () => { this.#targetListeners.delete(notify); };
|
|
69
|
+
}
|
|
51
70
|
/**
|
|
52
71
|
* Apply the settings-driven default open, at most once per store lifetime
|
|
53
72
|
* and never after any user interaction with the panel. Before the entry's
|
|
@@ -63,11 +82,13 @@ export class PromptPanelController {
|
|
|
63
82
|
/**
|
|
64
83
|
* Insert one template's content into a session's composer draft at the
|
|
65
84
|
* live caret position (selection, when a range is selected, is replaced).
|
|
66
|
-
* The caret
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
85
|
+
* The caret path goes through the input face's provide-channel pair —
|
|
86
|
+
* capture the caret span with its draft revision, then apply through the
|
|
87
|
+
* face so the editor lands it as one undoable edit. The pair declines on
|
|
88
|
+
* a stale revision or a locked admission transaction (submitting /
|
|
89
|
+
* adjudicating), and older runtimes without the channel simply lack the
|
|
90
|
+
* member; both fall back to an end-append over the draft snapshot (empty
|
|
91
|
+
* draft takes the content verbatim, non-empty joins with a newline).
|
|
71
92
|
* @param sessionId - target session.
|
|
72
93
|
* @param content - template content.
|
|
73
94
|
*/
|
|
@@ -75,21 +96,20 @@ export class PromptPanelController {
|
|
|
75
96
|
const input = this.#inputOf(sessionId);
|
|
76
97
|
if (input === undefined)
|
|
77
98
|
return;
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
|
|
99
|
+
const text = expandTemplateVariables(content, { sessionId });
|
|
100
|
+
const actions = input.actions;
|
|
101
|
+
if (actions !== undefined) {
|
|
102
|
+
try {
|
|
103
|
+
const span = actions.captureInsertion();
|
|
104
|
+
if (span !== undefined && actions.insertText(text, span))
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
// The channel is best-effort; the append path below always works.
|
|
109
|
+
}
|
|
83
110
|
}
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
const next = `${draft.slice(0, start)}${content}${draft.slice(end)}`;
|
|
87
|
-
const caret = start + content.length;
|
|
88
|
-
input.setDraft(next);
|
|
89
|
-
// Return focus and land the caret after the inserted text; the panel
|
|
90
|
-
// rows preventDefault on mousedown, so the textarea never lost focus.
|
|
91
|
-
textarea.focus();
|
|
92
|
-
textarea.setSelectionRange(caret, caret);
|
|
111
|
+
const draft = input.state.getSnapshot().draft;
|
|
112
|
+
input.setDraft(draft === '' ? text : `${draft}\n${text}`);
|
|
93
113
|
}
|
|
94
114
|
/**
|
|
95
115
|
* Interject one template: steer it into the running agent turn. With
|
|
@@ -103,7 +123,7 @@ export class PromptPanelController {
|
|
|
103
123
|
const input = this.#inputOf(sessionId);
|
|
104
124
|
if (input === undefined)
|
|
105
125
|
return;
|
|
106
|
-
input.setDraft(content);
|
|
126
|
+
input.setDraft(expandTemplateVariables(content, { sessionId }));
|
|
107
127
|
input.submit('steer');
|
|
108
128
|
}
|
|
109
129
|
/**
|
|
@@ -116,7 +136,7 @@ export class PromptPanelController {
|
|
|
116
136
|
const input = this.#inputOf(sessionId);
|
|
117
137
|
if (input === undefined)
|
|
118
138
|
return;
|
|
119
|
-
input.setDraft(content);
|
|
139
|
+
input.setDraft(expandTemplateVariables(content, { sessionId }));
|
|
120
140
|
input.submit();
|
|
121
141
|
}
|
|
122
142
|
/** Resolve a session's input facade, or undefined when out of reach. */
|
package/lib/client/slots.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Injected faces of the prompt-templates entries. The panel slot
|
|
3
3
|
* ('shell.overlay') is root-scoped, so its inject factory receives no
|
|
4
|
-
* session id — the
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* session id — the delivery target arrives from the composer entry: the
|
|
5
|
+
* session-scoped 'conversation.input.right' button reports its sessionId
|
|
6
|
+
* whenever its composer becomes the visible one (mount, session change,
|
|
7
|
+
* and click), and the panel reads it back through the face. The composer
|
|
8
|
+
* entry carries the panel toggle plus that target attachment.
|
|
7
9
|
*/
|
|
8
10
|
export {};
|
package/lib/client/store.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* Module level exports the factory only (de-facto singleton prohibition —
|
|
11
11
|
* see ui-layout's store).
|
|
12
12
|
*/
|
|
13
|
-
import { defineStore } from '@deepseek-ai/dsh-client-
|
|
13
|
+
import { defineStore } from '@deepseek-ai/dsh-client-store';
|
|
14
14
|
/**
|
|
15
15
|
* Complete write set for the panel.
|
|
16
16
|
* @returns the store handle (spec + type + identity + factory in one).
|
|
@@ -43,3 +43,14 @@ export function createPromptPanelStore() {
|
|
|
43
43
|
});
|
|
44
44
|
return handle;
|
|
45
45
|
}
|
|
46
|
+
/** Complete write set for the persisted preferences. */
|
|
47
|
+
export function createPromptPanelPrefsStore() {
|
|
48
|
+
return defineStore({
|
|
49
|
+
persist: 'prompt-templates.panel',
|
|
50
|
+
init: () => ({ defaultOpen: false, panel: null }),
|
|
51
|
+
actions: {
|
|
52
|
+
setPosition: (d, x, y) => { d.panel = { x: Math.round(x), y: Math.round(y) }; },
|
|
53
|
+
resetPosition: (d) => { d.panel = null; },
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** The tab kind this plugin owns — the name openTab and the guide dispatch by. */
|
|
2
|
+
export const PROMPT_TEMPLATES_KIND = 'promptTemplates';
|
|
3
|
+
/**
|
|
4
|
+
* This implementation's identity in the tab system, and the key its body
|
|
5
|
+
* registers under in the 'sidebar.right.pane.tab' seat (a package name is
|
|
6
|
+
* the natural value, exactly as the builtin files tab does).
|
|
7
|
+
*/
|
|
8
|
+
export const PROMPT_TEMPLATES_ID = '@nelsonlongxiang/dsh-prompt-templates';
|
|
9
|
+
/** Guide entry identity within this provider. */
|
|
10
|
+
const GUIDE_ENTRY_ID = 'prompt-templates';
|
|
11
|
+
/**
|
|
12
|
+
* The prompt-templates type's registry definition.
|
|
13
|
+
* @param t - namespace-bound translate, read fresh on every label call
|
|
14
|
+
* (a language change needs no re-registration).
|
|
15
|
+
* @returns the definition to register.
|
|
16
|
+
*/
|
|
17
|
+
export function promptTemplatesTabDefinition(t) {
|
|
18
|
+
return {
|
|
19
|
+
id: PROMPT_TEMPLATES_ID,
|
|
20
|
+
kind: PROMPT_TEMPLATES_KIND,
|
|
21
|
+
// A page type: no patterns, opened by kind, recognizes no address.
|
|
22
|
+
// Omitted priority defaults to 'extension' — correct for a type from
|
|
23
|
+
// outside the product, and the band that outranks builtin viewers.
|
|
24
|
+
title: () => t('tab.title'),
|
|
25
|
+
guide: [{
|
|
26
|
+
id: GUIDE_ENTRY_ID,
|
|
27
|
+
order: 20,
|
|
28
|
+
title: () => t('tab.guideTitle'),
|
|
29
|
+
description: () => t('tab.guideDescription'),
|
|
30
|
+
}],
|
|
31
|
+
};
|
|
32
|
+
}
|