@nelsonlongxiang/dsh-prompt-templates 0.2.10 → 0.4.4
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 +8 -11
- package/README_zh.md +8 -11
- package/cordis.patch.yml +4 -17
- package/lib/client/Panel.js +154 -23
- package/lib/client/api.js +19 -0
- package/lib/client/index.js +11 -1
- package/lib/client/locales.js +12 -0
- package/lib/client/service.js +52 -3
- package/lib/client.js +423 -67
- package/lib/client.js.map +1 -1
- package/lib/index.js +57 -47
- package/lib/store.js +275 -0
- package/lib/types/client/api.d.ts +14 -1
- package/lib/types/client/locales.d.ts +12 -0
- package/lib/types/client/service.d.ts +19 -3
- package/lib/types/client/slots.d.ts +19 -4
- package/lib/types/index.d.ts +13 -19
- package/lib/types/store.d.ts +57 -0
- package/lib/types/types.d.ts +20 -3
- package/lib/types.js +2 -2
- package/package.json +7 -15
- package/python/README.md +0 -26
- package/python/pyproject.toml +0 -33
- package/python/src/dsh_prompt_templates/__init__.py +0 -22
- package/python/src/dsh_prompt_templates/cli.py +0 -216
- package/python/src/dsh_prompt_templates/db.py +0 -125
- package/python/src/dsh_prompt_templates/models.py +0 -59
- package/python/src/dsh_prompt_templates/server.py +0 -170
- package/python/src/dsh_prompt_templates/store.py +0 -156
- package/python/uv.lock +0 -520
- package/scripts/bootstrap.mjs +0 -38
package/lib/client.js
CHANGED
|
@@ -22,6 +22,22 @@ window.__ModuleLoader__.load({
|
|
|
22
22
|
if (!response.ok) return [];
|
|
23
23
|
return [...(await response.json()).items ?? []];
|
|
24
24
|
}
|
|
25
|
+
/** Load every user category tab (global + all sessions'; the panel filters). */
|
|
26
|
+
async function listCategories() {
|
|
27
|
+
const response = await fetch(`${BASE}/categories`, { cache: "no-store" });
|
|
28
|
+
if (!response.ok) return [];
|
|
29
|
+
return [...(await response.json()).items ?? []];
|
|
30
|
+
}
|
|
31
|
+
/** Create one category tab. */
|
|
32
|
+
async function createCategory(request) {
|
|
33
|
+
return mutate("POST", "/categories", request);
|
|
34
|
+
}
|
|
35
|
+
/** Delete one category tab (its templates fall back to the default tab). */
|
|
36
|
+
async function deleteCategory(name, scope, sessionId) {
|
|
37
|
+
const params = new URLSearchParams({ scope });
|
|
38
|
+
if (sessionId !== null) params.set("session_id", sessionId);
|
|
39
|
+
return mutate("DELETE", `/categories/${encodeURIComponent(name)}?${params.toString()}`);
|
|
40
|
+
}
|
|
25
41
|
/** Create one template. */
|
|
26
42
|
async function createTemplate(request) {
|
|
27
43
|
return mutate("POST", "/templates", request);
|
|
@@ -70,7 +86,7 @@ window.__ModuleLoader__.load({
|
|
|
70
86
|
}
|
|
71
87
|
//#endregion
|
|
72
88
|
//#region \0dsh-css:D:\workspace\dsh-prompt-templates\src\client\Panel.module.css.mjs
|
|
73
|
-
const css$1 = ".h6AEjq_panel{background:var(--dsw-alias-bg-base);border:1px solid var(--dsw-alias-border-inverted);z-index:50;width:320px;color:var(--dsw-alias-label-primary);border-radius:8px;flex-direction:column;display:flex;position:fixed;top:16px;bottom:16px;right:16px;box-shadow:0 4px 24px #0000001f}.h6AEjq_header{border-bottom:1px solid var(--dsw-alias-border-inverted);cursor:grab;touch-action:none;user-select:none;justify-content:space-between;align-items:center;padding:10px 12px;display:flex}.h6AEjq_header:active{cursor:grabbing}.h6AEjq_title{font-size:13px;font-weight:600}.h6AEjq_closeBtn{cursor:pointer;color:var(--dsw-alias-label-secondary);background:0 0;border:none;border-radius:4px;padding:2px 6px;font-size:16px;line-height:1}.h6AEjq_closeBtn:hover{background:var(--dsw-alias-interactive-bg-hover)}.h6AEjq_searchBar{padding:8px 8px 0}.h6AEjq_searchInput{box-sizing:border-box;border:1px solid var(--dsw-alias-border-inverted);background:var(--dsw-specific-input-major);width:100%;color:var(--dsw-alias-label-primary);border-radius:4px;padding:4px 8px;font-family:inherit;font-size:12px}.h6AEjq_searchInput:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:-1px}.h6AEjq_body{--dsh-scrollbar-thumb:var(--dsw-alias-scrollbar-bg-l2);--dsh-scrollbar-thumb-hover:var(--dsw-alias-scrollbar-hover-l2);flex-direction:column;flex:1;gap:8px;min-height:0;padding:8px;display:flex;overflow-y:auto}.h6AEjq_empty{color:var(--dsw-alias-label-tertiary);text-align:center;padding:16px 0;font-size:12px}.h6AEjq_group{flex-direction:column;gap:4px;display:flex}.h6AEjq_groupTitle{color:var(--dsw-alias-label-tertiary);text-transform:uppercase;letter-spacing:.04em;padding:0 4px;font-size:11px}.h6AEjq_row{align-items:stretch;gap:4px;display:flex}.h6AEjq_insert{border:1px solid var(--dsw-alias-border-inverted);cursor:pointer;text-align:left;background:0 0;border-radius:6px;flex-direction:column;flex:1;align-items:flex-start;gap:2px;padding:6px 8px;display:flex}.h6AEjq_insert:hover{background:var(--dsw-alias-interactive-bg-hover)}.h6AEjq_name{color:var(--dsw-alias-label-primary);font-size:12px;font-weight:600}.h6AEjq_preview{color:var(--dsw-alias-label-tertiary);white-space:pre-wrap;word-break:break-word;max-height:4.5em;font-size:11px;overflow:hidden}.h6AEjq_deleteBtn{cursor:pointer;color:var(--dsw-alias-label-tertiary);background:0 0;border:none;border-radius:4px;padding:4px}.h6AEjq_sendBtn{cursor:pointer;color:var(--dsw-alias-label-secondary);background:0 0;border:none;border-radius:4px;padding:4px}.h6AEjq_sendBtn:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-state-business-primary)}.h6AEjq_editBtn{cursor:pointer;color:var(--dsw-alias-label-secondary);background:0 0;border:none;border-radius:4px;padding:4px}.h6AEjq_editBtn:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}.h6AEjq_globalBtn{cursor:pointer;color:var(--dsw-alias-label-secondary);background:0 0;border:none;border-radius:4px;padding:4px}.h6AEjq_globalBtn:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-state-business-primary)}.h6AEjq_deleteBtn:hover{background:var(--dsw-alias-interactive-bg-hover-danger);color:var(--dsw-alias-state-error-primary)}.h6AEjq_addForm{border:1px solid var(--dsw-alias-border-inverted);border-radius:6px;flex-direction:column;gap:6px;padding:8px;display:flex}.h6AEjq_nameInput,.h6AEjq_contentInput{border:1px solid var(--dsw-alias-border-inverted);background:var(--dsw-specific-input-major);color:var(--dsw-alias-label-primary);border-radius:4px;padding:4px 6px;font-family:inherit;font-size:12px}.h6AEjq_contentInput{resize:vertical}.h6AEjq_addRow{justify-content:space-between;align-items:center;gap:8px;display:flex}.h6AEjq_scopeLabel select{border:1px solid var(--dsw-alias-border-inverted);background:var(--dsw-specific-input-major);color:var(--dsw-alias-label-primary);border-radius:4px;padding:2px 4px;font-size:11px}.h6AEjq_addActions{align-items:center;gap:8px;display:flex}.h6AEjq_error{color:var(--dsw-alias-state-error-primary);font-size:11px}.h6AEjq_saveBtn{border:1px solid var(--dsw-alias-border-inverted);cursor:pointer;background:var(--dsw-alias-button-elevated-fill);color:var(--dsw-alias-label-primary);border-radius:4px;padding:3px 10px;font-size:12px}.h6AEjq_saveBtn:hover{background:var(--dsw-alias-interactive-bg-hover-solid)}.h6AEjq_saveBtn:disabled{opacity:.5;cursor:default}.h6AEjq_footer{border-top:1px solid var(--dsw-alias-border-inverted);justify-content:flex-end;padding:8px;display:flex}.h6AEjq_addBtn{border:1px solid var(--dsw-alias-border-inverted);cursor:pointer;background:var(--dsw-alias-button-elevated-fill);color:var(--dsw-alias-label-primary);border-radius:4px;align-items:center;gap:4px;padding:4px 10px;font-size:12px;display:inline-flex}.h6AEjq_addBtn:hover{background:var(--dsw-alias-interactive-bg-hover-solid)}";
|
|
89
|
+
const css$1 = ".h6AEjq_panel{background:var(--dsw-alias-bg-base);border:1px solid var(--dsw-alias-border-inverted);z-index:50;width:320px;color:var(--dsw-alias-label-primary);border-radius:8px;flex-direction:column;display:flex;position:fixed;top:16px;bottom:16px;right:16px;box-shadow:0 4px 24px #0000001f}.h6AEjq_header{border-bottom:1px solid var(--dsw-alias-border-inverted);cursor:grab;touch-action:none;user-select:none;justify-content:space-between;align-items:center;padding:10px 12px;display:flex}.h6AEjq_header:active{cursor:grabbing}.h6AEjq_title{font-size:13px;font-weight:600}.h6AEjq_closeBtn{cursor:pointer;color:var(--dsw-alias-label-secondary);background:0 0;border:none;border-radius:4px;padding:2px 6px;font-size:16px;line-height:1}.h6AEjq_closeBtn:hover{background:var(--dsw-alias-interactive-bg-hover)}.h6AEjq_searchBar{padding:8px 8px 0}.h6AEjq_searchInput{box-sizing:border-box;border:1px solid var(--dsw-alias-border-inverted);background:var(--dsw-specific-input-major);width:100%;color:var(--dsw-alias-label-primary);border-radius:4px;padding:4px 8px;font-family:inherit;font-size:12px}.h6AEjq_searchInput:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:-1px}.h6AEjq_tabsBar{flex-wrap:wrap;align-items:center;gap:4px;padding:6px 8px 0;display:flex}.h6AEjq_tab{border:1px solid var(--dsw-alias-border-inverted);color:var(--dsw-alias-label-secondary);background:0 0;border-radius:999px;align-items:center;gap:2px;padding:2px 8px;font-size:11px;display:inline-flex}.h6AEjq_tab>button{cursor:pointer;color:inherit;background:0 0;border:none;padding:0;font-size:11px}.h6AEjq_tabActive{border-color:var(--dsw-alias-state-business-primary);color:var(--dsw-alias-label-primary)}.h6AEjq_tabDelete{cursor:pointer;color:var(--dsw-alias-label-tertiary);background:0 0;border:none;border-radius:3px;padding:0 2px;font-size:12px;line-height:1}.h6AEjq_tabDelete:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}.h6AEjq_tabAdd{border:1px dashed var(--dsw-alias-border-inverted);cursor:pointer;color:var(--dsw-alias-label-tertiary);background:0 0;border-radius:999px;align-items:center;padding:2px 6px;display:inline-flex}.h6AEjq_tabAdd:hover{color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-state-business-primary)}.h6AEjq_body{--dsh-scrollbar-thumb:var(--dsw-alias-scrollbar-bg-l2);--dsh-scrollbar-thumb-hover:var(--dsw-alias-scrollbar-hover-l2);flex-direction:column;flex:1;gap:8px;min-height:0;padding:8px;display:flex;overflow-y:auto}.h6AEjq_empty{color:var(--dsw-alias-label-tertiary);text-align:center;padding:16px 0;font-size:12px}.h6AEjq_group{flex-direction:column;gap:4px;display:flex}.h6AEjq_groupTitle{color:var(--dsw-alias-label-tertiary);text-transform:uppercase;letter-spacing:.04em;padding:0 4px;font-size:11px}.h6AEjq_row{align-items:stretch;gap:4px;display:flex}.h6AEjq_insert{border:1px solid var(--dsw-alias-border-inverted);cursor:pointer;text-align:left;background:0 0;border-radius:6px;flex-direction:column;flex:1;align-items:flex-start;gap:2px;padding:6px 8px;display:flex}.h6AEjq_insert:hover{background:var(--dsw-alias-interactive-bg-hover)}.h6AEjq_name{color:var(--dsw-alias-label-primary);font-size:12px;font-weight:600}.h6AEjq_preview{color:var(--dsw-alias-label-tertiary);white-space:pre-wrap;word-break:break-word;max-height:4.5em;font-size:11px;overflow:hidden}.h6AEjq_deleteBtn,.h6AEjq_interjectBtn{cursor:pointer;color:var(--dsw-alias-label-tertiary);background:0 0;border:none;border-radius:4px;padding:4px}.h6AEjq_cancelBtn{border:1px solid var(--dsw-alias-border-inverted);cursor:pointer;color:var(--dsw-alias-label-secondary);background:0 0;border-radius:4px;padding:3px 10px;font-size:11px}.h6AEjq_cancelBtn:hover{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover)}.h6AEjq_sendBtn{cursor:pointer;color:var(--dsw-alias-label-secondary);background:0 0;border:none;border-radius:4px;padding:4px}.h6AEjq_sendBtn:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-state-business-primary)}.h6AEjq_editBtn{cursor:pointer;color:var(--dsw-alias-label-secondary);background:0 0;border:none;border-radius:4px;padding:4px}.h6AEjq_editBtn:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}.h6AEjq_globalBtn{cursor:pointer;color:var(--dsw-alias-label-secondary);background:0 0;border:none;border-radius:4px;padding:4px}.h6AEjq_globalBtn:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-state-business-primary)}.h6AEjq_deleteBtn:hover{background:var(--dsw-alias-interactive-bg-hover-danger);color:var(--dsw-alias-state-error-primary)}.h6AEjq_addForm{border:1px solid var(--dsw-alias-border-inverted);border-radius:6px;flex-direction:column;gap:6px;padding:8px;display:flex}.h6AEjq_nameInput,.h6AEjq_contentInput{border:1px solid var(--dsw-alias-border-inverted);background:var(--dsw-specific-input-major);color:var(--dsw-alias-label-primary);border-radius:4px;padding:4px 6px;font-family:inherit;font-size:12px}.h6AEjq_contentInput{resize:vertical}.h6AEjq_addRow{justify-content:space-between;align-items:center;gap:8px;display:flex}.h6AEjq_scopeLabel select{border:1px solid var(--dsw-alias-border-inverted);background:var(--dsw-specific-input-major);color:var(--dsw-alias-label-primary);border-radius:4px;padding:2px 4px;font-size:11px}.h6AEjq_addActions{align-items:center;gap:8px;display:flex}.h6AEjq_error{color:var(--dsw-alias-state-error-primary);font-size:11px}.h6AEjq_saveBtn{border:1px solid var(--dsw-alias-border-inverted);cursor:pointer;background:var(--dsw-alias-button-elevated-fill);color:var(--dsw-alias-label-primary);border-radius:4px;padding:3px 10px;font-size:12px}.h6AEjq_saveBtn:hover{background:var(--dsw-alias-interactive-bg-hover-solid)}.h6AEjq_saveBtn:disabled{opacity:.5;cursor:default}.h6AEjq_footer{border-top:1px solid var(--dsw-alias-border-inverted);justify-content:flex-end;padding:8px;display:flex}.h6AEjq_addBtn{border:1px solid var(--dsw-alias-border-inverted);cursor:pointer;background:var(--dsw-alias-button-elevated-fill);color:var(--dsw-alias-label-primary);border-radius:4px;align-items:center;gap:4px;padding:4px 10px;font-size:12px;display:inline-flex}.h6AEjq_addBtn:hover{background:var(--dsw-alias-interactive-bg-hover-solid)}";
|
|
74
90
|
const tagId$1 = "@nelsonlongxiang/dsh-prompt-templates/Panel.module.css";
|
|
75
91
|
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$1) + "]") === null) {
|
|
76
92
|
const tag = document.createElement("style");
|
|
@@ -85,6 +101,7 @@ window.__ModuleLoader__.load({
|
|
|
85
101
|
"addForm": "h6AEjq_addForm",
|
|
86
102
|
"addRow": "h6AEjq_addRow",
|
|
87
103
|
"body": "h6AEjq_body",
|
|
104
|
+
"cancelBtn": "h6AEjq_cancelBtn",
|
|
88
105
|
"closeBtn": "h6AEjq_closeBtn",
|
|
89
106
|
"contentInput": "h6AEjq_contentInput",
|
|
90
107
|
"deleteBtn": "h6AEjq_deleteBtn",
|
|
@@ -97,6 +114,7 @@ window.__ModuleLoader__.load({
|
|
|
97
114
|
"groupTitle": "h6AEjq_groupTitle",
|
|
98
115
|
"header": "h6AEjq_header",
|
|
99
116
|
"insert": "h6AEjq_insert",
|
|
117
|
+
"interjectBtn": "h6AEjq_interjectBtn",
|
|
100
118
|
"name": "h6AEjq_name",
|
|
101
119
|
"nameInput": "h6AEjq_nameInput",
|
|
102
120
|
"panel": "h6AEjq_panel",
|
|
@@ -107,6 +125,11 @@ window.__ModuleLoader__.load({
|
|
|
107
125
|
"searchBar": "h6AEjq_searchBar",
|
|
108
126
|
"searchInput": "h6AEjq_searchInput",
|
|
109
127
|
"sendBtn": "h6AEjq_sendBtn",
|
|
128
|
+
"tab": "h6AEjq_tab",
|
|
129
|
+
"tabActive": "h6AEjq_tabActive",
|
|
130
|
+
"tabAdd": "h6AEjq_tabAdd",
|
|
131
|
+
"tabDelete": "h6AEjq_tabDelete",
|
|
132
|
+
"tabsBar": "h6AEjq_tabsBar",
|
|
110
133
|
"title": "h6AEjq_title"
|
|
111
134
|
};
|
|
112
135
|
//#endregion
|
|
@@ -118,10 +141,25 @@ window.__ModuleLoader__.load({
|
|
|
118
141
|
* injected face carries the CRUD verbs and insert; the panel store holds
|
|
119
142
|
* visibility; the current session arrives through the standard kit.
|
|
120
143
|
*/
|
|
121
|
-
function TemplateRow({ template, onInsert, onSend, onEdit, onDelete, onMakeGlobal, t }) {
|
|
144
|
+
function TemplateRow({ template, onInsert, onSend, onInterject, onEdit, onDelete, onMakeGlobal, onDragStart, onDropOn, t }) {
|
|
122
145
|
return (0, react_jsx_runtime.jsxs)("div", {
|
|
123
146
|
className: Panel_module_css_default.row,
|
|
124
147
|
"data-prompt-template": true,
|
|
148
|
+
onMouseDown: (e) => {
|
|
149
|
+
e.preventDefault();
|
|
150
|
+
},
|
|
151
|
+
draggable: true,
|
|
152
|
+
onDragStart: () => {
|
|
153
|
+
onDragStart(template.id);
|
|
154
|
+
},
|
|
155
|
+
onDragOver: (e) => {
|
|
156
|
+
e.preventDefault();
|
|
157
|
+
},
|
|
158
|
+
onDrop: (e) => {
|
|
159
|
+
e.preventDefault();
|
|
160
|
+
e.stopPropagation();
|
|
161
|
+
onDropOn(template.id);
|
|
162
|
+
},
|
|
125
163
|
children: [
|
|
126
164
|
(0, react_jsx_runtime.jsxs)("button", {
|
|
127
165
|
type: "button",
|
|
@@ -138,6 +176,16 @@ window.__ModuleLoader__.load({
|
|
|
138
176
|
children: template.content
|
|
139
177
|
})]
|
|
140
178
|
}),
|
|
179
|
+
(0, react_jsx_runtime.jsx)("button", {
|
|
180
|
+
type: "button",
|
|
181
|
+
className: Panel_module_css_default.interjectBtn,
|
|
182
|
+
onClick: () => {
|
|
183
|
+
onInterject(template.content);
|
|
184
|
+
},
|
|
185
|
+
"aria-label": t("panel.interject"),
|
|
186
|
+
title: t("panel.interject"),
|
|
187
|
+
children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconQueueOutline14, { size: 12 })
|
|
188
|
+
}),
|
|
141
189
|
(0, react_jsx_runtime.jsx)("button", {
|
|
142
190
|
type: "button",
|
|
143
191
|
className: Panel_module_css_default.sendBtn,
|
|
@@ -180,11 +228,12 @@ window.__ModuleLoader__.load({
|
|
|
180
228
|
]
|
|
181
229
|
});
|
|
182
230
|
}
|
|
183
|
-
/** The template inline form: creation (with scope
|
|
184
|
-
function TemplateForm({ initial, allowScope, sessionId, t, submitLabel, onSubmit, onDone }) {
|
|
231
|
+
/** The template inline form: creation (with scope + category pickers) and in-place edit. */
|
|
232
|
+
function TemplateForm({ initial, allowScope, sessionId, categories, t, submitLabel, onSubmit, onDone, onCancel }) {
|
|
185
233
|
const [name, setName] = (0, react.useState)(initial?.name ?? "");
|
|
186
234
|
const [content, setContent] = (0, react.useState)(initial?.content ?? "");
|
|
187
235
|
const [scope, setScope] = (0, react.useState)("global");
|
|
236
|
+
const [category, setCategory] = (0, react.useState)(null);
|
|
188
237
|
const [busy, setBusy] = (0, react.useState)(false);
|
|
189
238
|
const [error, setError] = (0, react.useState)(null);
|
|
190
239
|
const submit = (0, react.useCallback)(async () => {
|
|
@@ -197,7 +246,7 @@ window.__ModuleLoader__.load({
|
|
|
197
246
|
}
|
|
198
247
|
setBusy(true);
|
|
199
248
|
setError(null);
|
|
200
|
-
const ok = await onSubmit(trimmedName, trimmedContent, scope);
|
|
249
|
+
const ok = await onSubmit(trimmedName, trimmedContent, scope, category);
|
|
201
250
|
setBusy(false);
|
|
202
251
|
if (!ok) {
|
|
203
252
|
setError(t("panel.error"));
|
|
@@ -208,12 +257,14 @@ window.__ModuleLoader__.load({
|
|
|
208
257
|
name,
|
|
209
258
|
content,
|
|
210
259
|
scope,
|
|
260
|
+
category,
|
|
211
261
|
allowScope,
|
|
212
262
|
sessionId,
|
|
213
263
|
onSubmit,
|
|
214
264
|
t,
|
|
215
265
|
onDone
|
|
216
266
|
]);
|
|
267
|
+
const scopeCategories = categories.filter((cat) => cat.scope === scope && (cat.scope === "global" || cat.session_id === sessionId));
|
|
217
268
|
return (0, react_jsx_runtime.jsxs)("div", {
|
|
218
269
|
className: Panel_module_css_default.addForm,
|
|
219
270
|
"data-prompt-add": true,
|
|
@@ -240,54 +291,107 @@ window.__ModuleLoader__.load({
|
|
|
240
291
|
}),
|
|
241
292
|
(0, react_jsx_runtime.jsxs)("div", {
|
|
242
293
|
className: Panel_module_css_default.addRow,
|
|
243
|
-
children: [
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
children:
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
294
|
+
children: [
|
|
295
|
+
allowScope && (0, react_jsx_runtime.jsx)("label", {
|
|
296
|
+
className: Panel_module_css_default.scopeLabel,
|
|
297
|
+
children: (0, react_jsx_runtime.jsxs)("select", {
|
|
298
|
+
value: scope,
|
|
299
|
+
onChange: (e) => {
|
|
300
|
+
setScope(e.target.value);
|
|
301
|
+
setCategory(null);
|
|
302
|
+
},
|
|
303
|
+
"aria-label": "scope",
|
|
304
|
+
children: [(0, react_jsx_runtime.jsx)("option", {
|
|
305
|
+
value: "global",
|
|
306
|
+
children: t("panel.global")
|
|
307
|
+
}), (0, react_jsx_runtime.jsx)("option", {
|
|
308
|
+
value: "session",
|
|
309
|
+
disabled: sessionId === null,
|
|
310
|
+
children: t("panel.session")
|
|
311
|
+
})]
|
|
312
|
+
})
|
|
313
|
+
}),
|
|
314
|
+
(0, react_jsx_runtime.jsx)("label", {
|
|
315
|
+
className: Panel_module_css_default.scopeLabel,
|
|
316
|
+
children: (0, react_jsx_runtime.jsxs)("select", {
|
|
317
|
+
value: category ?? "",
|
|
318
|
+
onChange: (e) => {
|
|
319
|
+
setCategory(e.target.value === "" ? null : e.target.value);
|
|
320
|
+
},
|
|
321
|
+
"aria-label": t("panel.category"),
|
|
322
|
+
children: [(0, react_jsx_runtime.jsx)("option", {
|
|
323
|
+
value: "",
|
|
324
|
+
children: t("panel.categoryNone")
|
|
325
|
+
}), scopeCategories.map((cat) => (0, react_jsx_runtime.jsx)("option", {
|
|
326
|
+
value: cat.name,
|
|
327
|
+
children: cat.name
|
|
328
|
+
}, `${cat.scope}:${cat.name}`))]
|
|
329
|
+
})
|
|
330
|
+
}),
|
|
331
|
+
(0, react_jsx_runtime.jsxs)("div", {
|
|
332
|
+
className: Panel_module_css_default.addActions,
|
|
333
|
+
children: [
|
|
334
|
+
error !== null && (0, react_jsx_runtime.jsx)("span", {
|
|
335
|
+
className: Panel_module_css_default.error,
|
|
336
|
+
role: "alert",
|
|
337
|
+
children: error
|
|
338
|
+
}),
|
|
339
|
+
onCancel !== void 0 && (0, react_jsx_runtime.jsx)("button", {
|
|
340
|
+
type: "button",
|
|
341
|
+
className: Panel_module_css_default.cancelBtn,
|
|
342
|
+
onClick: onCancel,
|
|
343
|
+
disabled: busy,
|
|
344
|
+
children: t("panel.addCancel")
|
|
345
|
+
}),
|
|
346
|
+
(0, react_jsx_runtime.jsx)("button", {
|
|
347
|
+
type: "button",
|
|
348
|
+
className: Panel_module_css_default.saveBtn,
|
|
349
|
+
onClick: () => void submit(),
|
|
350
|
+
disabled: busy || name.trim() === "" || content.trim() === "",
|
|
351
|
+
children: submitLabel
|
|
352
|
+
})
|
|
353
|
+
]
|
|
259
354
|
})
|
|
260
|
-
|
|
261
|
-
className: Panel_module_css_default.addActions,
|
|
262
|
-
children: [error !== null && (0, react_jsx_runtime.jsx)("span", {
|
|
263
|
-
className: Panel_module_css_default.error,
|
|
264
|
-
role: "alert",
|
|
265
|
-
children: error
|
|
266
|
-
}), (0, react_jsx_runtime.jsx)("button", {
|
|
267
|
-
type: "button",
|
|
268
|
-
className: Panel_module_css_default.saveBtn,
|
|
269
|
-
onClick: () => void submit(),
|
|
270
|
-
disabled: busy || name.trim() === "" || content.trim() === "",
|
|
271
|
-
children: submitLabel
|
|
272
|
-
})]
|
|
273
|
-
})]
|
|
355
|
+
]
|
|
274
356
|
})
|
|
275
357
|
]
|
|
276
358
|
});
|
|
277
359
|
}
|
|
360
|
+
/** Panel width used for viewport clamping (mirrors the CSS `.panel` width). */
|
|
361
|
+
const PANEL_WIDTH = 320;
|
|
362
|
+
/**
|
|
363
|
+
* Clamp a restored panel position into the current viewport so a placement
|
|
364
|
+
* saved on a wider screen (or a monitor that is no longer attached) can never
|
|
365
|
+
* render the panel unreachable off-screen. Null passes through untouched.
|
|
366
|
+
* @param position - the persisted placement, if any.
|
|
367
|
+
* @returns the clamped placement.
|
|
368
|
+
*/
|
|
369
|
+
function clampToViewport(position) {
|
|
370
|
+
if (position === null) return null;
|
|
371
|
+
const maxX = Math.max(0, window.innerWidth - PANEL_WIDTH);
|
|
372
|
+
const maxY = Math.max(0, window.innerHeight - 40);
|
|
373
|
+
return {
|
|
374
|
+
x: Math.min(Math.max(position.x, 0), maxX),
|
|
375
|
+
y: Math.min(Math.max(position.y, 0), maxY)
|
|
376
|
+
};
|
|
377
|
+
}
|
|
278
378
|
/**
|
|
279
379
|
* The prompt-templates panel body.
|
|
280
380
|
* @param props - runtime kit, injected face members, store handle, and locale.
|
|
281
381
|
*/
|
|
282
382
|
function PromptPanel(props) {
|
|
283
|
-
const { useStore, useSessions, refresh, create, update, remove, makeGlobal, insert, send, panelPosition, savePanelPosition, resetPanelPosition, actions, t } = props;
|
|
383
|
+
const { useStore, useSessions, refresh, refreshCategories, createCategory, removeCategory, create, update, remove, makeGlobal, insert, send, interject, panelPosition, savePanelPosition, resetPanelPosition, actions, t } = props;
|
|
284
384
|
const open = useStore((s) => s.open);
|
|
285
385
|
const currentSession = useSessions((s) => s.current);
|
|
286
386
|
const [templates, setTemplates] = (0, react.useState)([]);
|
|
387
|
+
const [categories, setCategories] = (0, react.useState)([]);
|
|
287
388
|
const [showAdd, setShowAdd] = (0, react.useState)(false);
|
|
288
389
|
const [query, setQuery] = (0, react.useState)("");
|
|
289
390
|
const [editingId, setEditingId] = (0, react.useState)(null);
|
|
290
|
-
const
|
|
391
|
+
const [activeTab, setActiveTab] = (0, react.useState)("global");
|
|
392
|
+
const [showCatForm, setShowCatForm] = (0, react.useState)(false);
|
|
393
|
+
const dragRowRef = (0, react.useRef)(null);
|
|
394
|
+
const persisted = clampToViewport(panelPosition());
|
|
291
395
|
const [dragPos, setDragPos] = (0, react.useState)(null);
|
|
292
396
|
const dragRef = (0, react.useRef)(null);
|
|
293
397
|
const panelRef = (0, react.useRef)(null);
|
|
@@ -296,9 +400,19 @@ window.__ModuleLoader__.load({
|
|
|
296
400
|
const items = await refresh();
|
|
297
401
|
setTemplates(items);
|
|
298
402
|
}, [refresh]);
|
|
403
|
+
const loadCategories = (0, react.useCallback)(async () => {
|
|
404
|
+
setCategories(await refreshCategories());
|
|
405
|
+
}, [refreshCategories]);
|
|
299
406
|
(0, react.useEffect)(() => {
|
|
300
|
-
if (open)
|
|
301
|
-
|
|
407
|
+
if (open) {
|
|
408
|
+
load();
|
|
409
|
+
loadCategories();
|
|
410
|
+
}
|
|
411
|
+
}, [
|
|
412
|
+
open,
|
|
413
|
+
load,
|
|
414
|
+
loadCategories
|
|
415
|
+
]);
|
|
302
416
|
const handleInsert = (0, react.useCallback)((content) => {
|
|
303
417
|
if (sessionId === null) return;
|
|
304
418
|
insert(sessionId, content);
|
|
@@ -307,6 +421,10 @@ window.__ModuleLoader__.load({
|
|
|
307
421
|
if (sessionId === null) return;
|
|
308
422
|
send(sessionId, content);
|
|
309
423
|
}, [send, sessionId]);
|
|
424
|
+
const handleInterject = (0, react.useCallback)((content) => {
|
|
425
|
+
if (sessionId === null) return;
|
|
426
|
+
interject(sessionId, content);
|
|
427
|
+
}, [interject, sessionId]);
|
|
310
428
|
const handleRemove = (0, react.useCallback)(async (id) => {
|
|
311
429
|
if ((await remove(id)).ok) load();
|
|
312
430
|
}, [remove, load]);
|
|
@@ -353,7 +471,29 @@ window.__ModuleLoader__.load({
|
|
|
353
471
|
if (!open) return null;
|
|
354
472
|
const needle = query.trim().toLowerCase();
|
|
355
473
|
const matches = (row) => needle === "" || row.name.toLowerCase().includes(needle) || row.content.toLowerCase().includes(needle);
|
|
356
|
-
const
|
|
474
|
+
const visibleCategories = categories.filter((cat) => cat.scope === "global" || cat.scope === "session" && cat.session_id === sessionId);
|
|
475
|
+
const activeCategory = activeTab.startsWith("cat:") ? visibleCategories.find((cat) => `cat:${cat.scope}:${cat.name}` === activeTab) : void 0;
|
|
476
|
+
const effectiveTab = activeTab.startsWith("cat:") && activeCategory === void 0 ? "global" : activeTab;
|
|
477
|
+
const tabRows = templates.filter((row) => {
|
|
478
|
+
if (!matches(row)) return false;
|
|
479
|
+
if (effectiveTab === "global") return row.scope === "global" && row.category === null;
|
|
480
|
+
if (effectiveTab === "session") return row.scope === "session" && row.session_id === sessionId && row.category === null;
|
|
481
|
+
return activeCategory !== void 0 && row.category === activeCategory.name && row.scope === activeCategory.scope && (activeCategory.scope === "global" || row.session_id === sessionId);
|
|
482
|
+
});
|
|
483
|
+
const handleRowDrop = (targetId) => {
|
|
484
|
+
const draggedId = dragRowRef.current;
|
|
485
|
+
dragRowRef.current = null;
|
|
486
|
+
if (draggedId === null || draggedId === targetId) return;
|
|
487
|
+
const ids = tabRows.map((row) => row.id);
|
|
488
|
+
const from = ids.indexOf(draggedId);
|
|
489
|
+
const to = ids.indexOf(targetId);
|
|
490
|
+
if (from === -1 || to === -1) return;
|
|
491
|
+
ids.splice(to, 0, ...ids.splice(from, 1));
|
|
492
|
+
(async () => {
|
|
493
|
+
await Promise.all(ids.map((id, index) => update(id, { position: index })));
|
|
494
|
+
load();
|
|
495
|
+
})();
|
|
496
|
+
};
|
|
357
497
|
/** One list row: the edit form while being edited, the rendered row otherwise. */
|
|
358
498
|
const renderTemplateRow = (row) => editingId === row.id ? (0, react_jsx_runtime.jsx)(TemplateForm, {
|
|
359
499
|
initial: {
|
|
@@ -362,15 +502,20 @@ window.__ModuleLoader__.load({
|
|
|
362
502
|
},
|
|
363
503
|
allowScope: false,
|
|
364
504
|
sessionId,
|
|
505
|
+
categories: visibleCategories,
|
|
365
506
|
t,
|
|
366
507
|
submitLabel: t("panel.addSave"),
|
|
367
|
-
onSubmit: async (name, content) => (await update(row.id, {
|
|
508
|
+
onSubmit: async (name, content, _scope, category) => (await update(row.id, {
|
|
368
509
|
name,
|
|
369
|
-
content
|
|
510
|
+
content,
|
|
511
|
+
category: row.scope === "global" ? category : category
|
|
370
512
|
})).ok,
|
|
371
513
|
onDone: () => {
|
|
372
514
|
setEditingId(null);
|
|
373
515
|
load();
|
|
516
|
+
},
|
|
517
|
+
onCancel: () => {
|
|
518
|
+
setEditingId(null);
|
|
374
519
|
}
|
|
375
520
|
}, row.id) : (0, react_jsx_runtime.jsx)(TemplateRow, {
|
|
376
521
|
template: row,
|
|
@@ -380,6 +525,9 @@ window.__ModuleLoader__.load({
|
|
|
380
525
|
onSend: (c) => {
|
|
381
526
|
handleSend(c);
|
|
382
527
|
},
|
|
528
|
+
onInterject: (c) => {
|
|
529
|
+
handleInterject(c);
|
|
530
|
+
},
|
|
383
531
|
onEdit: (id) => {
|
|
384
532
|
setEditingId(id);
|
|
385
533
|
},
|
|
@@ -389,15 +537,21 @@ window.__ModuleLoader__.load({
|
|
|
389
537
|
onMakeGlobal: row.scope === "session" ? (id) => {
|
|
390
538
|
handleMakeGlobal(id);
|
|
391
539
|
} : void 0,
|
|
540
|
+
onDragStart: (id) => {
|
|
541
|
+
dragRowRef.current = id;
|
|
542
|
+
},
|
|
543
|
+
onDropOn: (id) => {
|
|
544
|
+
handleRowDrop(id);
|
|
545
|
+
},
|
|
392
546
|
t
|
|
393
547
|
}, row.id);
|
|
394
|
-
const sessionRows = templates.filter((row) => row.scope === "session" && row.session_id === sessionId && matches(row));
|
|
395
548
|
const placement = dragPos ?? persisted;
|
|
396
549
|
const placementStyle = placement === null ? void 0 : {
|
|
397
550
|
left: placement.x,
|
|
398
551
|
top: placement.y,
|
|
399
552
|
right: "auto",
|
|
400
|
-
bottom: "auto"
|
|
553
|
+
bottom: "auto",
|
|
554
|
+
maxHeight: `calc(100vh - ${placement.y}px - 16px)`
|
|
401
555
|
};
|
|
402
556
|
return (0, react_jsx_runtime.jsxs)("div", {
|
|
403
557
|
className: Panel_module_css_default.panel,
|
|
@@ -439,46 +593,109 @@ window.__ModuleLoader__.load({
|
|
|
439
593
|
})
|
|
440
594
|
}),
|
|
441
595
|
(0, react_jsx_runtime.jsxs)("div", {
|
|
442
|
-
className: Panel_module_css_default.
|
|
596
|
+
className: Panel_module_css_default.tabsBar,
|
|
443
597
|
children: [
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
598
|
+
(0, react_jsx_runtime.jsx)("button", {
|
|
599
|
+
type: "button",
|
|
600
|
+
className: effectiveTab === "global" ? `${Panel_module_css_default.tab} ${Panel_module_css_default.tabActive}` : Panel_module_css_default.tab,
|
|
601
|
+
onClick: () => {
|
|
602
|
+
setActiveTab("global");
|
|
603
|
+
},
|
|
604
|
+
children: t("panel.global")
|
|
447
605
|
}),
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
606
|
+
(0, react_jsx_runtime.jsx)("button", {
|
|
607
|
+
type: "button",
|
|
608
|
+
className: effectiveTab === "session" ? `${Panel_module_css_default.tab} ${Panel_module_css_default.tabActive}` : Panel_module_css_default.tab,
|
|
609
|
+
onClick: () => {
|
|
610
|
+
setActiveTab("session");
|
|
611
|
+
},
|
|
612
|
+
disabled: sessionId === null,
|
|
613
|
+
children: t("panel.session")
|
|
451
614
|
}),
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
className: Panel_module_css_default.
|
|
456
|
-
children:
|
|
457
|
-
|
|
615
|
+
visibleCategories.map((cat) => {
|
|
616
|
+
const key = `cat:${cat.scope}:${cat.name}`;
|
|
617
|
+
return (0, react_jsx_runtime.jsxs)("span", {
|
|
618
|
+
className: effectiveTab === key ? `${Panel_module_css_default.tab} ${Panel_module_css_default.tabActive}` : Panel_module_css_default.tab,
|
|
619
|
+
children: [(0, react_jsx_runtime.jsx)("button", {
|
|
620
|
+
type: "button",
|
|
621
|
+
onClick: () => {
|
|
622
|
+
setActiveTab(key);
|
|
623
|
+
},
|
|
624
|
+
children: cat.name
|
|
625
|
+
}), (0, react_jsx_runtime.jsx)("button", {
|
|
626
|
+
type: "button",
|
|
627
|
+
className: Panel_module_css_default.tabDelete,
|
|
628
|
+
"aria-label": t("panel.deleteCategory"),
|
|
629
|
+
title: t("panel.deleteCategory"),
|
|
630
|
+
onClick: () => {
|
|
631
|
+
(async () => {
|
|
632
|
+
if ((await removeCategory(cat.name, cat.scope, cat.session_id)).ok) {
|
|
633
|
+
if (effectiveTab === key) setActiveTab("global");
|
|
634
|
+
loadCategories();
|
|
635
|
+
load();
|
|
636
|
+
}
|
|
637
|
+
})();
|
|
638
|
+
},
|
|
639
|
+
children: "×"
|
|
640
|
+
})]
|
|
641
|
+
}, key);
|
|
642
|
+
}),
|
|
643
|
+
(0, react_jsx_runtime.jsx)("button", {
|
|
644
|
+
type: "button",
|
|
645
|
+
className: Panel_module_css_default.tabAdd,
|
|
646
|
+
"aria-label": t("panel.newCategory"),
|
|
647
|
+
title: t("panel.newCategory"),
|
|
648
|
+
onClick: () => {
|
|
649
|
+
setShowCatForm((v) => !v);
|
|
650
|
+
},
|
|
651
|
+
children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconPlusOutline16, { size: 10 })
|
|
652
|
+
})
|
|
653
|
+
]
|
|
654
|
+
}),
|
|
655
|
+
showCatForm && (0, react_jsx_runtime.jsx)(CategoryForm, {
|
|
656
|
+
sessionId,
|
|
657
|
+
createCategory,
|
|
658
|
+
t,
|
|
659
|
+
onDone: () => {
|
|
660
|
+
setShowCatForm(false);
|
|
661
|
+
loadCategories();
|
|
662
|
+
}
|
|
663
|
+
}),
|
|
664
|
+
(0, react_jsx_runtime.jsxs)("div", {
|
|
665
|
+
className: Panel_module_css_default.body,
|
|
666
|
+
children: [
|
|
667
|
+
tabRows.length === 0 && !showAdd && !showCatForm && (0, react_jsx_runtime.jsx)("div", {
|
|
668
|
+
className: Panel_module_css_default.empty,
|
|
669
|
+
children: needle !== "" ? t("panel.noMatch") : t("panel.empty")
|
|
458
670
|
}),
|
|
459
|
-
|
|
671
|
+
tabRows.length > 0 && (0, react_jsx_runtime.jsx)("div", {
|
|
460
672
|
className: Panel_module_css_default.group,
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
673
|
+
onDragOver: (e) => {
|
|
674
|
+
e.preventDefault();
|
|
675
|
+
},
|
|
676
|
+
children: tabRows.map((row) => renderTemplateRow(row))
|
|
465
677
|
}),
|
|
466
678
|
showAdd && (0, react_jsx_runtime.jsx)(TemplateForm, {
|
|
467
679
|
sessionId,
|
|
680
|
+
categories: visibleCategories,
|
|
468
681
|
t,
|
|
469
682
|
allowScope: true,
|
|
470
683
|
submitLabel: t("panel.addSave"),
|
|
471
|
-
onSubmit: async (name, content, scope) => {
|
|
684
|
+
onSubmit: async (name, content, scope, category) => {
|
|
472
685
|
return (await create({
|
|
473
686
|
name,
|
|
474
687
|
content,
|
|
475
688
|
scope,
|
|
476
|
-
session_id: scope === "session" ? sessionId : null
|
|
689
|
+
session_id: scope === "session" ? sessionId : null,
|
|
690
|
+
category
|
|
477
691
|
})).ok;
|
|
478
692
|
},
|
|
479
693
|
onDone: () => {
|
|
480
694
|
setShowAdd(false);
|
|
481
695
|
load();
|
|
696
|
+
},
|
|
697
|
+
onCancel: () => {
|
|
698
|
+
setShowAdd(false);
|
|
482
699
|
}
|
|
483
700
|
})
|
|
484
701
|
]
|
|
@@ -501,6 +718,81 @@ window.__ModuleLoader__.load({
|
|
|
501
718
|
]
|
|
502
719
|
});
|
|
503
720
|
}
|
|
721
|
+
/** Inline form creating one category tab: name + scope (global, or the current session). */
|
|
722
|
+
function CategoryForm({ sessionId, createCategory, t, onDone }) {
|
|
723
|
+
const [name, setName] = (0, react.useState)("");
|
|
724
|
+
const [scope, setScope] = (0, react.useState)("global");
|
|
725
|
+
const [busy, setBusy] = (0, react.useState)(false);
|
|
726
|
+
const [error, setError] = (0, react.useState)(null);
|
|
727
|
+
const submit = async () => {
|
|
728
|
+
const trimmed = name.trim();
|
|
729
|
+
if (trimmed === "") return;
|
|
730
|
+
if (scope === "session" && sessionId === null) {
|
|
731
|
+
setError(t("panel.error"));
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
setBusy(true);
|
|
735
|
+
setError(null);
|
|
736
|
+
const result = await createCategory({
|
|
737
|
+
name: trimmed,
|
|
738
|
+
scope,
|
|
739
|
+
session_id: scope === "session" ? sessionId : null
|
|
740
|
+
});
|
|
741
|
+
setBusy(false);
|
|
742
|
+
if (!result.ok) {
|
|
743
|
+
setError(t("panel.error"));
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
onDone();
|
|
747
|
+
};
|
|
748
|
+
return (0, react_jsx_runtime.jsxs)("div", {
|
|
749
|
+
className: Panel_module_css_default.addForm,
|
|
750
|
+
"data-prompt-category-add": true,
|
|
751
|
+
children: [(0, react_jsx_runtime.jsx)("input", {
|
|
752
|
+
className: Panel_module_css_default.nameInput,
|
|
753
|
+
type: "text",
|
|
754
|
+
placeholder: t("panel.categoryName"),
|
|
755
|
+
value: name,
|
|
756
|
+
onChange: (e) => {
|
|
757
|
+
setName(e.target.value);
|
|
758
|
+
},
|
|
759
|
+
"aria-label": t("panel.categoryName")
|
|
760
|
+
}), (0, react_jsx_runtime.jsxs)("div", {
|
|
761
|
+
className: Panel_module_css_default.addRow,
|
|
762
|
+
children: [(0, react_jsx_runtime.jsx)("label", {
|
|
763
|
+
className: Panel_module_css_default.scopeLabel,
|
|
764
|
+
children: (0, react_jsx_runtime.jsxs)("select", {
|
|
765
|
+
value: scope,
|
|
766
|
+
onChange: (e) => {
|
|
767
|
+
setScope(e.target.value);
|
|
768
|
+
},
|
|
769
|
+
"aria-label": "scope",
|
|
770
|
+
children: [(0, react_jsx_runtime.jsx)("option", {
|
|
771
|
+
value: "global",
|
|
772
|
+
children: t("panel.global")
|
|
773
|
+
}), (0, react_jsx_runtime.jsx)("option", {
|
|
774
|
+
value: "session",
|
|
775
|
+
disabled: sessionId === null,
|
|
776
|
+
children: t("panel.session")
|
|
777
|
+
})]
|
|
778
|
+
})
|
|
779
|
+
}), (0, react_jsx_runtime.jsxs)("div", {
|
|
780
|
+
className: Panel_module_css_default.addActions,
|
|
781
|
+
children: [error !== null && (0, react_jsx_runtime.jsx)("span", {
|
|
782
|
+
className: Panel_module_css_default.error,
|
|
783
|
+
role: "alert",
|
|
784
|
+
children: error
|
|
785
|
+
}), (0, react_jsx_runtime.jsx)("button", {
|
|
786
|
+
type: "button",
|
|
787
|
+
className: Panel_module_css_default.saveBtn,
|
|
788
|
+
onClick: () => void submit(),
|
|
789
|
+
disabled: busy || name.trim() === "",
|
|
790
|
+
children: t("panel.addSave")
|
|
791
|
+
})]
|
|
792
|
+
})]
|
|
793
|
+
})]
|
|
794
|
+
});
|
|
795
|
+
}
|
|
504
796
|
//#endregion
|
|
505
797
|
//#region \0dsh-css:D:\workspace\dsh-prompt-templates\src\client\PanelButton.module.css.mjs
|
|
506
798
|
const css = ".-G3v8q_button,.-G3v8q_buttonActive{border:1px solid var(--dsw-alias-border-inverted);cursor:pointer;width:24px;height:24px;color:var(--dsw-alias-label-secondary);background:0 0;border-radius:4px;justify-content:center;align-items:center;padding:0;display:inline-flex}.-G3v8q_button:hover,.-G3v8q_buttonActive:hover{background:var(--dsw-alias-interactive-bg-hover)}.-G3v8q_buttonActive{background:var(--dsw-alias-interactive-bg-hover);border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-label-primary)}.-G3v8q_glyph{font-size:13px;line-height:1}";
|
|
@@ -585,6 +877,18 @@ window.__ModuleLoader__.load({
|
|
|
585
877
|
//#endregion
|
|
586
878
|
//#region lib/client/service.js
|
|
587
879
|
/**
|
|
880
|
+
* Locate the composer textarea for one draft. The input machine publishes
|
|
881
|
+
* no caret, so the caret can only be read from the DOM: of every textarea
|
|
882
|
+
* on the page, the one whose value equals the draft snapshot is the
|
|
883
|
+
* composer (the panel's own form fields never hold the draft). Falls back
|
|
884
|
+
* to null when no match exists (detached DOM, session switched mid-click).
|
|
885
|
+
*/
|
|
886
|
+
function composerTextarea(draft) {
|
|
887
|
+
if (typeof document === "undefined") return null;
|
|
888
|
+
for (const el of Array.from(document.querySelectorAll("textarea"))) if (el.value === draft) return el;
|
|
889
|
+
return null;
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
588
892
|
* Cross-entry panel face (ctx.promptPanel).
|
|
589
893
|
*/
|
|
590
894
|
var PromptPanelController = class {
|
|
@@ -631,8 +935,13 @@ window.__ModuleLoader__.load({
|
|
|
631
935
|
this.#actions.openOnce();
|
|
632
936
|
}
|
|
633
937
|
/**
|
|
634
|
-
*
|
|
635
|
-
*
|
|
938
|
+
* Insert one template's content into a session's composer draft at the
|
|
939
|
+
* live caret position (selection, when a range is selected, is replaced).
|
|
940
|
+
* The caret lives only in the DOM textarea — the input machine publishes
|
|
941
|
+
* no caret — so the composer textarea is located by matching its value
|
|
942
|
+
* against the draft snapshot; when no textarea is found the content falls
|
|
943
|
+
* back to an end-append (empty draft takes it verbatim, non-empty joins
|
|
944
|
+
* with a newline).
|
|
636
945
|
* @param sessionId - target session.
|
|
637
946
|
* @param content - template content.
|
|
638
947
|
*/
|
|
@@ -640,7 +949,32 @@ window.__ModuleLoader__.load({
|
|
|
640
949
|
const input = this.#inputOf(sessionId);
|
|
641
950
|
if (input === void 0) return;
|
|
642
951
|
const draft = input.state.getSnapshot().draft;
|
|
643
|
-
|
|
952
|
+
const textarea = composerTextarea(draft);
|
|
953
|
+
if (textarea === null) {
|
|
954
|
+
input.setDraft(draft === "" ? content : `${draft}\n${content}`);
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
const start = textarea.selectionStart ?? draft.length;
|
|
958
|
+
const end = textarea.selectionEnd ?? start;
|
|
959
|
+
const next = `${draft.slice(0, start)}${content}${draft.slice(end)}`;
|
|
960
|
+
const caret = start + content.length;
|
|
961
|
+
input.setDraft(next);
|
|
962
|
+
textarea.focus();
|
|
963
|
+
textarea.setSelectionRange(caret, caret);
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* Interject one template: steer it into the running agent turn. With
|
|
967
|
+
* steer mode the content interrupts the current turn at its next step
|
|
968
|
+
* (the same delivery as Cmd/Ctrl+Enter插话发送), rather than queuing
|
|
969
|
+
* after it. The user's own draft is left untouched.
|
|
970
|
+
* @param sessionId - target session.
|
|
971
|
+
* @param content - template content.
|
|
972
|
+
*/
|
|
973
|
+
interject(sessionId, content) {
|
|
974
|
+
const input = this.#inputOf(sessionId);
|
|
975
|
+
if (input === void 0) return;
|
|
976
|
+
input.setDraft(content);
|
|
977
|
+
input.submit("steer");
|
|
644
978
|
}
|
|
645
979
|
/**
|
|
646
980
|
* Fill the draft with one template's content and submit it immediately —
|
|
@@ -689,6 +1023,12 @@ window.__ModuleLoader__.load({
|
|
|
689
1023
|
"panel.addSave": "保存",
|
|
690
1024
|
"panel.addCancel": "取消",
|
|
691
1025
|
"panel.insert": "插入",
|
|
1026
|
+
"panel.interject": "插话打断",
|
|
1027
|
+
"panel.newCategory": "新增分类",
|
|
1028
|
+
"panel.categoryName": "分类名称",
|
|
1029
|
+
"panel.categoryNone": "不设分类",
|
|
1030
|
+
"panel.category": "分类",
|
|
1031
|
+
"panel.deleteCategory": "删除分类",
|
|
692
1032
|
"panel.delete": "删除",
|
|
693
1033
|
"panel.edit": "编辑",
|
|
694
1034
|
"panel.makeGlobal": "设为全局",
|
|
@@ -714,6 +1054,12 @@ window.__ModuleLoader__.load({
|
|
|
714
1054
|
"panel.addSave": "Save",
|
|
715
1055
|
"panel.addCancel": "Cancel",
|
|
716
1056
|
"panel.insert": "Insert",
|
|
1057
|
+
"panel.interject": "Interject (steer)",
|
|
1058
|
+
"panel.newCategory": "New category",
|
|
1059
|
+
"panel.categoryName": "Category name",
|
|
1060
|
+
"panel.categoryNone": "No category",
|
|
1061
|
+
"panel.category": "Category",
|
|
1062
|
+
"panel.deleteCategory": "Delete category",
|
|
717
1063
|
"panel.delete": "Delete",
|
|
718
1064
|
"panel.edit": "Edit",
|
|
719
1065
|
"panel.makeGlobal": "Make global",
|
|
@@ -752,6 +1098,13 @@ window.__ModuleLoader__.load({
|
|
|
752
1098
|
const uiSettings = ctx.settingsScope.bind({ namespace: "prompt-templates" });
|
|
753
1099
|
const panelFace = {
|
|
754
1100
|
refresh: listTemplates,
|
|
1101
|
+
refreshCategories: listCategories,
|
|
1102
|
+
createCategory: (request) => {
|
|
1103
|
+
return createCategory(request);
|
|
1104
|
+
},
|
|
1105
|
+
removeCategory: (name, scope, sessionId) => {
|
|
1106
|
+
return deleteCategory(name, scope, sessionId);
|
|
1107
|
+
},
|
|
755
1108
|
create: (request) => {
|
|
756
1109
|
return createTemplate(request);
|
|
757
1110
|
},
|
|
@@ -770,6 +1123,9 @@ window.__ModuleLoader__.load({
|
|
|
770
1123
|
send: (sessionId, content) => {
|
|
771
1124
|
controller.send(sessionId, content);
|
|
772
1125
|
},
|
|
1126
|
+
interject: (sessionId, content) => {
|
|
1127
|
+
controller.interject(sessionId, content);
|
|
1128
|
+
},
|
|
773
1129
|
panelPosition: () => {
|
|
774
1130
|
const snapshot = uiSettings.getSnapshot();
|
|
775
1131
|
if (snapshot.status !== "ready") return null;
|