@nelsonlongxiang/dsh-prompt-templates 0.2.8
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 +70 -0
- package/cordis.patch.yml +37 -0
- package/lib/client/Panel.js +166 -0
- package/lib/client/PanelButton.js +9 -0
- package/lib/client/api.js +53 -0
- package/lib/client/index.js +106 -0
- package/lib/client/locales.js +51 -0
- package/lib/client/service.js +90 -0
- package/lib/client/slots.js +8 -0
- package/lib/client/store.js +45 -0
- package/lib/client.js +832 -0
- package/lib/client.js.map +1 -0
- package/lib/index.js +180 -0
- package/lib/invariant.js +11 -0
- package/lib/types/client/Panel.d.ts +10 -0
- package/lib/types/client/PanelButton.d.ts +15 -0
- package/lib/types/client/api.d.ts +39 -0
- package/lib/types/client/index.d.ts +43 -0
- package/lib/types/client/locales.d.ts +53 -0
- package/lib/types/client/service.d.ts +72 -0
- package/lib/types/client/slots.d.ts +54 -0
- package/lib/types/client/store.d.ts +31 -0
- package/lib/types/index.d.ts +48 -0
- package/lib/types/invariant.d.ts +8 -0
- package/lib/types/types.d.ts +38 -0
- package/lib/types.js +7 -0
- package/package.json +111 -0
- package/python/README.md +26 -0
- package/python/pyproject.toml +33 -0
- package/python/src/dsh_prompt_templates/__init__.py +22 -0
- package/python/src/dsh_prompt_templates/cli.py +216 -0
- package/python/src/dsh_prompt_templates/db.py +125 -0
- package/python/src/dsh_prompt_templates/models.py +59 -0
- package/python/src/dsh_prompt_templates/server.py +170 -0
- package/python/src/dsh_prompt_templates/store.py +156 -0
- package/python/uv.lock +520 -0
- package/scripts/bootstrap.mjs +38 -0
package/lib/client.js
ADDED
|
@@ -0,0 +1,832 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "@nelsonlongxiang/dsh-prompt-templates",
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
var module = { exports: {} };
|
|
5
|
+
var exports = module.exports;
|
|
6
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
|
+
let react = require("react");
|
|
9
|
+
let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
10
|
+
let _deepseek_ai_dsh_client_runtime_client = require("@deepseek-ai/dsh-client-runtime/client");
|
|
11
|
+
//#region lib/client/api.js
|
|
12
|
+
/**
|
|
13
|
+
* Browser-side API over the host's `/plugins/dsh-prompt-templates` routes.
|
|
14
|
+
* One fetch helper per verb; every response settles into the same
|
|
15
|
+
* `{ ok: true; value } | { ok: false; error }` envelope the panel face
|
|
16
|
+
* consumes, so callers never see transport details.
|
|
17
|
+
*/
|
|
18
|
+
const BASE = "/plugins/dsh-prompt-templates";
|
|
19
|
+
/** Load the full template set (global + every session's). */
|
|
20
|
+
async function listTemplates() {
|
|
21
|
+
const response = await fetch(`${BASE}/templates`, { cache: "no-store" });
|
|
22
|
+
if (!response.ok) return [];
|
|
23
|
+
return [...(await response.json()).items ?? []];
|
|
24
|
+
}
|
|
25
|
+
/** Create one template. */
|
|
26
|
+
async function createTemplate(request) {
|
|
27
|
+
return mutate("POST", "/templates", request);
|
|
28
|
+
}
|
|
29
|
+
/** Patch one template by id. */
|
|
30
|
+
async function updateTemplate(id, request) {
|
|
31
|
+
return mutate("PATCH", `/templates/${encodeURIComponent(id)}`, request);
|
|
32
|
+
}
|
|
33
|
+
/** Promote one session template to the global partition. */
|
|
34
|
+
async function makeTemplateGlobal(id) {
|
|
35
|
+
return mutate("POST", `/templates/${encodeURIComponent(id)}/make-global`, {});
|
|
36
|
+
}
|
|
37
|
+
/** Delete one template by id. */
|
|
38
|
+
async function deleteTemplate(id) {
|
|
39
|
+
return mutate("DELETE", `/templates/${encodeURIComponent(id)}`);
|
|
40
|
+
}
|
|
41
|
+
/** Run one mutating request and settle it into the action envelope. */
|
|
42
|
+
async function mutate(method, path, body) {
|
|
43
|
+
try {
|
|
44
|
+
const response = await fetch(`${BASE}${path}`, {
|
|
45
|
+
method,
|
|
46
|
+
headers: body === void 0 ? void 0 : { "content-type": "application/json" },
|
|
47
|
+
body: body === void 0 ? void 0 : JSON.stringify(body),
|
|
48
|
+
cache: "no-store"
|
|
49
|
+
});
|
|
50
|
+
if (!response.ok) return {
|
|
51
|
+
ok: false,
|
|
52
|
+
error: (await response.json().catch(() => null))?.error ?? {
|
|
53
|
+
code: `http:${response.status}`,
|
|
54
|
+
message: response.statusText
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
return {
|
|
58
|
+
ok: true,
|
|
59
|
+
value: await response.json().catch(() => void 0)
|
|
60
|
+
};
|
|
61
|
+
} catch (error) {
|
|
62
|
+
return {
|
|
63
|
+
ok: false,
|
|
64
|
+
error: {
|
|
65
|
+
code: "network-error",
|
|
66
|
+
message: String(error)
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#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)}";
|
|
74
|
+
const tagId$1 = "@nelsonlongxiang/dsh-prompt-templates/Panel.module.css";
|
|
75
|
+
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$1) + "]") === null) {
|
|
76
|
+
const tag = document.createElement("style");
|
|
77
|
+
tag.dataset.plugin = "@nelsonlongxiang/dsh-prompt-templates";
|
|
78
|
+
tag.dataset.pluginCss = tagId$1;
|
|
79
|
+
tag.textContent = css$1;
|
|
80
|
+
document.head.appendChild(tag);
|
|
81
|
+
}
|
|
82
|
+
var Panel_module_css_default = {
|
|
83
|
+
"addActions": "h6AEjq_addActions",
|
|
84
|
+
"addBtn": "h6AEjq_addBtn",
|
|
85
|
+
"addForm": "h6AEjq_addForm",
|
|
86
|
+
"addRow": "h6AEjq_addRow",
|
|
87
|
+
"body": "h6AEjq_body",
|
|
88
|
+
"closeBtn": "h6AEjq_closeBtn",
|
|
89
|
+
"contentInput": "h6AEjq_contentInput",
|
|
90
|
+
"deleteBtn": "h6AEjq_deleteBtn",
|
|
91
|
+
"editBtn": "h6AEjq_editBtn",
|
|
92
|
+
"empty": "h6AEjq_empty",
|
|
93
|
+
"error": "h6AEjq_error",
|
|
94
|
+
"footer": "h6AEjq_footer",
|
|
95
|
+
"globalBtn": "h6AEjq_globalBtn",
|
|
96
|
+
"group": "h6AEjq_group",
|
|
97
|
+
"groupTitle": "h6AEjq_groupTitle",
|
|
98
|
+
"header": "h6AEjq_header",
|
|
99
|
+
"insert": "h6AEjq_insert",
|
|
100
|
+
"name": "h6AEjq_name",
|
|
101
|
+
"nameInput": "h6AEjq_nameInput",
|
|
102
|
+
"panel": "h6AEjq_panel",
|
|
103
|
+
"preview": "h6AEjq_preview",
|
|
104
|
+
"row": "h6AEjq_row",
|
|
105
|
+
"saveBtn": "h6AEjq_saveBtn",
|
|
106
|
+
"scopeLabel": "h6AEjq_scopeLabel",
|
|
107
|
+
"searchBar": "h6AEjq_searchBar",
|
|
108
|
+
"searchInput": "h6AEjq_searchInput",
|
|
109
|
+
"sendBtn": "h6AEjq_sendBtn",
|
|
110
|
+
"title": "h6AEjq_title"
|
|
111
|
+
};
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region lib/client/Panel.js
|
|
114
|
+
/**
|
|
115
|
+
* Quick prompt panel: the right-anchored floating surface registered into
|
|
116
|
+
* shell.overlay. Lists global templates plus the current session's private
|
|
117
|
+
* ones; clicking a row inserts its content into the composer draft. The
|
|
118
|
+
* injected face carries the CRUD verbs and insert; the panel store holds
|
|
119
|
+
* visibility; the current session arrives through the standard kit.
|
|
120
|
+
*/
|
|
121
|
+
function TemplateRow({ template, onInsert, onSend, onEdit, onDelete, onMakeGlobal, t }) {
|
|
122
|
+
return (0, react_jsx_runtime.jsxs)("div", {
|
|
123
|
+
className: Panel_module_css_default.row,
|
|
124
|
+
"data-prompt-template": true,
|
|
125
|
+
children: [
|
|
126
|
+
(0, react_jsx_runtime.jsxs)("button", {
|
|
127
|
+
type: "button",
|
|
128
|
+
className: Panel_module_css_default.insert,
|
|
129
|
+
onClick: () => {
|
|
130
|
+
onInsert(template.content);
|
|
131
|
+
},
|
|
132
|
+
title: t("panel.insert"),
|
|
133
|
+
children: [(0, react_jsx_runtime.jsx)("span", {
|
|
134
|
+
className: Panel_module_css_default.name,
|
|
135
|
+
children: template.name
|
|
136
|
+
}), (0, react_jsx_runtime.jsx)("span", {
|
|
137
|
+
className: Panel_module_css_default.preview,
|
|
138
|
+
children: template.content
|
|
139
|
+
})]
|
|
140
|
+
}),
|
|
141
|
+
(0, react_jsx_runtime.jsx)("button", {
|
|
142
|
+
type: "button",
|
|
143
|
+
className: Panel_module_css_default.sendBtn,
|
|
144
|
+
onClick: () => {
|
|
145
|
+
onSend(template.content);
|
|
146
|
+
},
|
|
147
|
+
"aria-label": t("panel.sendNow"),
|
|
148
|
+
title: t("panel.sendNow"),
|
|
149
|
+
children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconSendOutline16, { size: 12 })
|
|
150
|
+
}),
|
|
151
|
+
onMakeGlobal !== void 0 && (0, react_jsx_runtime.jsx)("button", {
|
|
152
|
+
type: "button",
|
|
153
|
+
className: Panel_module_css_default.globalBtn,
|
|
154
|
+
onClick: () => {
|
|
155
|
+
onMakeGlobal(template.id);
|
|
156
|
+
},
|
|
157
|
+
"aria-label": t("panel.makeGlobal"),
|
|
158
|
+
title: t("panel.makeGlobal"),
|
|
159
|
+
children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconGlobeOutline14, { size: 12 })
|
|
160
|
+
}),
|
|
161
|
+
(0, react_jsx_runtime.jsx)("button", {
|
|
162
|
+
type: "button",
|
|
163
|
+
className: Panel_module_css_default.editBtn,
|
|
164
|
+
onClick: () => {
|
|
165
|
+
onEdit(template.id);
|
|
166
|
+
},
|
|
167
|
+
"aria-label": t("panel.edit"),
|
|
168
|
+
title: t("panel.edit"),
|
|
169
|
+
children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconEditOutline16, { size: 12 })
|
|
170
|
+
}),
|
|
171
|
+
(0, react_jsx_runtime.jsx)("button", {
|
|
172
|
+
type: "button",
|
|
173
|
+
className: Panel_module_css_default.deleteBtn,
|
|
174
|
+
onClick: () => {
|
|
175
|
+
onDelete(template.id);
|
|
176
|
+
},
|
|
177
|
+
"aria-label": t("panel.delete"),
|
|
178
|
+
children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconTrashOutline16, { size: 12 })
|
|
179
|
+
})
|
|
180
|
+
]
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
/** The template inline form: creation (with scope picker) and in-place edit. */
|
|
184
|
+
function TemplateForm({ initial, allowScope, sessionId, t, submitLabel, onSubmit, onDone }) {
|
|
185
|
+
const [name, setName] = (0, react.useState)(initial?.name ?? "");
|
|
186
|
+
const [content, setContent] = (0, react.useState)(initial?.content ?? "");
|
|
187
|
+
const [scope, setScope] = (0, react.useState)("global");
|
|
188
|
+
const [busy, setBusy] = (0, react.useState)(false);
|
|
189
|
+
const [error, setError] = (0, react.useState)(null);
|
|
190
|
+
const submit = (0, react.useCallback)(async () => {
|
|
191
|
+
const trimmedName = name.trim();
|
|
192
|
+
const trimmedContent = content.trim();
|
|
193
|
+
if (trimmedName === "" || trimmedContent === "") return;
|
|
194
|
+
if (allowScope && scope === "session" && sessionId === null) {
|
|
195
|
+
setError(t("panel.error"));
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
setBusy(true);
|
|
199
|
+
setError(null);
|
|
200
|
+
const ok = await onSubmit(trimmedName, trimmedContent, scope);
|
|
201
|
+
setBusy(false);
|
|
202
|
+
if (!ok) {
|
|
203
|
+
setError(t("panel.error"));
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
onDone();
|
|
207
|
+
}, [
|
|
208
|
+
name,
|
|
209
|
+
content,
|
|
210
|
+
scope,
|
|
211
|
+
allowScope,
|
|
212
|
+
sessionId,
|
|
213
|
+
onSubmit,
|
|
214
|
+
t,
|
|
215
|
+
onDone
|
|
216
|
+
]);
|
|
217
|
+
return (0, react_jsx_runtime.jsxs)("div", {
|
|
218
|
+
className: Panel_module_css_default.addForm,
|
|
219
|
+
"data-prompt-add": true,
|
|
220
|
+
children: [
|
|
221
|
+
(0, react_jsx_runtime.jsx)("input", {
|
|
222
|
+
className: Panel_module_css_default.nameInput,
|
|
223
|
+
type: "text",
|
|
224
|
+
placeholder: t("panel.addName"),
|
|
225
|
+
value: name,
|
|
226
|
+
onChange: (e) => {
|
|
227
|
+
setName(e.target.value);
|
|
228
|
+
},
|
|
229
|
+
"aria-label": t("panel.addName")
|
|
230
|
+
}),
|
|
231
|
+
(0, react_jsx_runtime.jsx)("textarea", {
|
|
232
|
+
className: Panel_module_css_default.contentInput,
|
|
233
|
+
placeholder: t("panel.addContent"),
|
|
234
|
+
value: content,
|
|
235
|
+
onChange: (e) => {
|
|
236
|
+
setContent(e.target.value);
|
|
237
|
+
},
|
|
238
|
+
rows: 3,
|
|
239
|
+
"aria-label": t("panel.addContent")
|
|
240
|
+
}),
|
|
241
|
+
(0, react_jsx_runtime.jsxs)("div", {
|
|
242
|
+
className: Panel_module_css_default.addRow,
|
|
243
|
+
children: [allowScope && (0, react_jsx_runtime.jsx)("label", {
|
|
244
|
+
className: Panel_module_css_default.scopeLabel,
|
|
245
|
+
children: (0, react_jsx_runtime.jsxs)("select", {
|
|
246
|
+
value: scope,
|
|
247
|
+
onChange: (e) => {
|
|
248
|
+
setScope(e.target.value);
|
|
249
|
+
},
|
|
250
|
+
"aria-label": "scope",
|
|
251
|
+
children: [(0, react_jsx_runtime.jsx)("option", {
|
|
252
|
+
value: "global",
|
|
253
|
+
children: t("panel.global")
|
|
254
|
+
}), (0, react_jsx_runtime.jsx)("option", {
|
|
255
|
+
value: "session",
|
|
256
|
+
disabled: sessionId === null,
|
|
257
|
+
children: t("panel.session")
|
|
258
|
+
})]
|
|
259
|
+
})
|
|
260
|
+
}), (0, react_jsx_runtime.jsxs)("div", {
|
|
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
|
+
})]
|
|
274
|
+
})
|
|
275
|
+
]
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* The prompt-templates panel body.
|
|
280
|
+
* @param props - runtime kit, injected face members, store handle, and locale.
|
|
281
|
+
*/
|
|
282
|
+
function PromptPanel(props) {
|
|
283
|
+
const { useStore, useSessions, refresh, create, update, remove, makeGlobal, insert, send, panelPosition, savePanelPosition, resetPanelPosition, actions, t } = props;
|
|
284
|
+
const open = useStore((s) => s.open);
|
|
285
|
+
const currentSession = useSessions((s) => s.current);
|
|
286
|
+
const [templates, setTemplates] = (0, react.useState)([]);
|
|
287
|
+
const [showAdd, setShowAdd] = (0, react.useState)(false);
|
|
288
|
+
const [query, setQuery] = (0, react.useState)("");
|
|
289
|
+
const [editingId, setEditingId] = (0, react.useState)(null);
|
|
290
|
+
const persisted = panelPosition();
|
|
291
|
+
const [dragPos, setDragPos] = (0, react.useState)(null);
|
|
292
|
+
const dragRef = (0, react.useRef)(null);
|
|
293
|
+
const panelRef = (0, react.useRef)(null);
|
|
294
|
+
const sessionId = currentSession ?? null;
|
|
295
|
+
const load = (0, react.useCallback)(async () => {
|
|
296
|
+
const items = await refresh();
|
|
297
|
+
setTemplates(items);
|
|
298
|
+
}, [refresh]);
|
|
299
|
+
(0, react.useEffect)(() => {
|
|
300
|
+
if (open) load();
|
|
301
|
+
}, [open, load]);
|
|
302
|
+
const handleInsert = (0, react.useCallback)((content) => {
|
|
303
|
+
if (sessionId === null) return;
|
|
304
|
+
insert(sessionId, content);
|
|
305
|
+
}, [insert, sessionId]);
|
|
306
|
+
const handleSend = (0, react.useCallback)((content) => {
|
|
307
|
+
if (sessionId === null) return;
|
|
308
|
+
send(sessionId, content);
|
|
309
|
+
}, [send, sessionId]);
|
|
310
|
+
const handleRemove = (0, react.useCallback)(async (id) => {
|
|
311
|
+
if ((await remove(id)).ok) load();
|
|
312
|
+
}, [remove, load]);
|
|
313
|
+
const handleMakeGlobal = (0, react.useCallback)(async (id) => {
|
|
314
|
+
if ((await makeGlobal(id)).ok) load();
|
|
315
|
+
}, [makeGlobal, load]);
|
|
316
|
+
const onHeaderPointerDown = (event) => {
|
|
317
|
+
if (event.button !== 0) return;
|
|
318
|
+
if (event.target.closest("button")) return;
|
|
319
|
+
const panel = panelRef.current;
|
|
320
|
+
if (panel === null) return;
|
|
321
|
+
const rect = panel.getBoundingClientRect();
|
|
322
|
+
dragRef.current = {
|
|
323
|
+
pointerId: event.pointerId,
|
|
324
|
+
offX: event.clientX - rect.left,
|
|
325
|
+
offY: event.clientY - rect.top
|
|
326
|
+
};
|
|
327
|
+
if (Reflect.has(event.currentTarget, "setPointerCapture")) event.currentTarget.setPointerCapture(event.pointerId);
|
|
328
|
+
};
|
|
329
|
+
const onHeaderPointerMove = (event) => {
|
|
330
|
+
const drag = dragRef.current;
|
|
331
|
+
if (drag === null || event.pointerId !== drag.pointerId) return;
|
|
332
|
+
const width = panelRef.current?.getBoundingClientRect().width ?? 320;
|
|
333
|
+
const maxX = Math.max(0, window.innerWidth - width);
|
|
334
|
+
const maxY = Math.max(0, window.innerHeight - 40);
|
|
335
|
+
const x = Math.min(Math.max(event.clientX - drag.offX, 0), maxX);
|
|
336
|
+
const y = Math.min(Math.max(event.clientY - drag.offY, 0), maxY);
|
|
337
|
+
setDragPos({
|
|
338
|
+
x,
|
|
339
|
+
y
|
|
340
|
+
});
|
|
341
|
+
};
|
|
342
|
+
const onHeaderPointerUp = (event) => {
|
|
343
|
+
const drag = dragRef.current;
|
|
344
|
+
if (drag === null || event.pointerId !== drag.pointerId) return;
|
|
345
|
+
dragRef.current = null;
|
|
346
|
+
if (Reflect.has(event.currentTarget, "releasePointerCapture")) event.currentTarget.releasePointerCapture(event.pointerId);
|
|
347
|
+
if (dragPos !== null) savePanelPosition(dragPos);
|
|
348
|
+
};
|
|
349
|
+
const onHeaderDoubleClick = () => {
|
|
350
|
+
setDragPos(null);
|
|
351
|
+
resetPanelPosition();
|
|
352
|
+
};
|
|
353
|
+
if (!open) return null;
|
|
354
|
+
const needle = query.trim().toLowerCase();
|
|
355
|
+
const matches = (row) => needle === "" || row.name.toLowerCase().includes(needle) || row.content.toLowerCase().includes(needle);
|
|
356
|
+
const globalRows = templates.filter((row) => row.scope === "global" && matches(row));
|
|
357
|
+
/** One list row: the edit form while being edited, the rendered row otherwise. */
|
|
358
|
+
const renderTemplateRow = (row) => editingId === row.id ? (0, react_jsx_runtime.jsx)(TemplateForm, {
|
|
359
|
+
initial: {
|
|
360
|
+
name: row.name,
|
|
361
|
+
content: row.content
|
|
362
|
+
},
|
|
363
|
+
allowScope: false,
|
|
364
|
+
sessionId,
|
|
365
|
+
t,
|
|
366
|
+
submitLabel: t("panel.addSave"),
|
|
367
|
+
onSubmit: async (name, content) => (await update(row.id, {
|
|
368
|
+
name,
|
|
369
|
+
content
|
|
370
|
+
})).ok,
|
|
371
|
+
onDone: () => {
|
|
372
|
+
setEditingId(null);
|
|
373
|
+
load();
|
|
374
|
+
}
|
|
375
|
+
}, row.id) : (0, react_jsx_runtime.jsx)(TemplateRow, {
|
|
376
|
+
template: row,
|
|
377
|
+
onInsert: (c) => {
|
|
378
|
+
handleInsert(c);
|
|
379
|
+
},
|
|
380
|
+
onSend: (c) => {
|
|
381
|
+
handleSend(c);
|
|
382
|
+
},
|
|
383
|
+
onEdit: (id) => {
|
|
384
|
+
setEditingId(id);
|
|
385
|
+
},
|
|
386
|
+
onDelete: (id) => {
|
|
387
|
+
handleRemove(id);
|
|
388
|
+
},
|
|
389
|
+
onMakeGlobal: row.scope === "session" ? (id) => {
|
|
390
|
+
handleMakeGlobal(id);
|
|
391
|
+
} : void 0,
|
|
392
|
+
t
|
|
393
|
+
}, row.id);
|
|
394
|
+
const sessionRows = templates.filter((row) => row.scope === "session" && row.session_id === sessionId && matches(row));
|
|
395
|
+
const placement = dragPos ?? persisted;
|
|
396
|
+
const placementStyle = placement === null ? void 0 : {
|
|
397
|
+
left: placement.x,
|
|
398
|
+
top: placement.y,
|
|
399
|
+
right: "auto",
|
|
400
|
+
bottom: "auto"
|
|
401
|
+
};
|
|
402
|
+
return (0, react_jsx_runtime.jsxs)("div", {
|
|
403
|
+
className: Panel_module_css_default.panel,
|
|
404
|
+
"data-prompt-panel": true,
|
|
405
|
+
ref: panelRef,
|
|
406
|
+
style: placementStyle,
|
|
407
|
+
children: [
|
|
408
|
+
(0, react_jsx_runtime.jsxs)("div", {
|
|
409
|
+
className: Panel_module_css_default.header,
|
|
410
|
+
title: t("panel.dragHint"),
|
|
411
|
+
onPointerDown: onHeaderPointerDown,
|
|
412
|
+
onPointerMove: onHeaderPointerMove,
|
|
413
|
+
onPointerUp: onHeaderPointerUp,
|
|
414
|
+
onDoubleClick: onHeaderDoubleClick,
|
|
415
|
+
children: [(0, react_jsx_runtime.jsx)("span", {
|
|
416
|
+
className: Panel_module_css_default.title,
|
|
417
|
+
children: t("panel.title")
|
|
418
|
+
}), (0, react_jsx_runtime.jsx)("button", {
|
|
419
|
+
type: "button",
|
|
420
|
+
className: Panel_module_css_default.closeBtn,
|
|
421
|
+
onClick: () => {
|
|
422
|
+
actions.close();
|
|
423
|
+
},
|
|
424
|
+
"aria-label": t("panel.close"),
|
|
425
|
+
children: "×"
|
|
426
|
+
})]
|
|
427
|
+
}),
|
|
428
|
+
(0, react_jsx_runtime.jsx)("div", {
|
|
429
|
+
className: Panel_module_css_default.searchBar,
|
|
430
|
+
children: (0, react_jsx_runtime.jsx)("input", {
|
|
431
|
+
type: "search",
|
|
432
|
+
className: Panel_module_css_default.searchInput,
|
|
433
|
+
value: query,
|
|
434
|
+
onChange: (e) => {
|
|
435
|
+
setQuery(e.target.value);
|
|
436
|
+
},
|
|
437
|
+
placeholder: t("panel.search"),
|
|
438
|
+
"aria-label": t("panel.search")
|
|
439
|
+
})
|
|
440
|
+
}),
|
|
441
|
+
(0, react_jsx_runtime.jsxs)("div", {
|
|
442
|
+
className: Panel_module_css_default.body,
|
|
443
|
+
children: [
|
|
444
|
+
templates.length === 0 && !showAdd && (0, react_jsx_runtime.jsx)("div", {
|
|
445
|
+
className: Panel_module_css_default.empty,
|
|
446
|
+
children: t("panel.empty")
|
|
447
|
+
}),
|
|
448
|
+
templates.length > 0 && needle !== "" && globalRows.length === 0 && sessionRows.length === 0 && (0, react_jsx_runtime.jsx)("div", {
|
|
449
|
+
className: Panel_module_css_default.empty,
|
|
450
|
+
children: t("panel.noMatch")
|
|
451
|
+
}),
|
|
452
|
+
globalRows.length > 0 && (0, react_jsx_runtime.jsxs)("div", {
|
|
453
|
+
className: Panel_module_css_default.group,
|
|
454
|
+
children: [(0, react_jsx_runtime.jsx)("div", {
|
|
455
|
+
className: Panel_module_css_default.groupTitle,
|
|
456
|
+
children: t("panel.global")
|
|
457
|
+
}), globalRows.map((row) => renderTemplateRow(row))]
|
|
458
|
+
}),
|
|
459
|
+
sessionRows.length > 0 && sessionId !== null && (0, react_jsx_runtime.jsxs)("div", {
|
|
460
|
+
className: Panel_module_css_default.group,
|
|
461
|
+
children: [(0, react_jsx_runtime.jsx)("div", {
|
|
462
|
+
className: Panel_module_css_default.groupTitle,
|
|
463
|
+
children: t("panel.session")
|
|
464
|
+
}), sessionRows.map((row) => renderTemplateRow(row))]
|
|
465
|
+
}),
|
|
466
|
+
showAdd && (0, react_jsx_runtime.jsx)(TemplateForm, {
|
|
467
|
+
sessionId,
|
|
468
|
+
t,
|
|
469
|
+
allowScope: true,
|
|
470
|
+
submitLabel: t("panel.addSave"),
|
|
471
|
+
onSubmit: async (name, content, scope) => {
|
|
472
|
+
return (await create({
|
|
473
|
+
name,
|
|
474
|
+
content,
|
|
475
|
+
scope,
|
|
476
|
+
session_id: scope === "session" ? sessionId : null
|
|
477
|
+
})).ok;
|
|
478
|
+
},
|
|
479
|
+
onDone: () => {
|
|
480
|
+
setShowAdd(false);
|
|
481
|
+
load();
|
|
482
|
+
}
|
|
483
|
+
})
|
|
484
|
+
]
|
|
485
|
+
}),
|
|
486
|
+
(0, react_jsx_runtime.jsx)("div", {
|
|
487
|
+
className: Panel_module_css_default.footer,
|
|
488
|
+
children: (0, react_jsx_runtime.jsxs)("button", {
|
|
489
|
+
type: "button",
|
|
490
|
+
className: Panel_module_css_default.addBtn,
|
|
491
|
+
onClick: () => {
|
|
492
|
+
setShowAdd((v) => !v);
|
|
493
|
+
},
|
|
494
|
+
children: [
|
|
495
|
+
(0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconPlusOutline16, { size: 12 }),
|
|
496
|
+
" ",
|
|
497
|
+
t("panel.add")
|
|
498
|
+
]
|
|
499
|
+
})
|
|
500
|
+
})
|
|
501
|
+
]
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
//#endregion
|
|
505
|
+
//#region \0dsh-css:D:\workspace\dsh-prompt-templates\src\client\PanelButton.module.css.mjs
|
|
506
|
+
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}";
|
|
507
|
+
const tagId = "@nelsonlongxiang/dsh-prompt-templates/PanelButton.module.css";
|
|
508
|
+
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
|
|
509
|
+
const tag = document.createElement("style");
|
|
510
|
+
tag.dataset.plugin = "@nelsonlongxiang/dsh-prompt-templates";
|
|
511
|
+
tag.dataset.pluginCss = tagId;
|
|
512
|
+
tag.textContent = css;
|
|
513
|
+
document.head.appendChild(tag);
|
|
514
|
+
}
|
|
515
|
+
var PanelButton_module_css_default = {
|
|
516
|
+
"button": "-G3v8q_button",
|
|
517
|
+
"buttonActive": "-G3v8q_buttonActive",
|
|
518
|
+
"glyph": "-G3v8q_glyph"
|
|
519
|
+
};
|
|
520
|
+
//#endregion
|
|
521
|
+
//#region lib/client/PanelButton.js
|
|
522
|
+
/**
|
|
523
|
+
* The composer tool-row button.
|
|
524
|
+
* @param props - runtime kit (includes the InputZone owner share), the toggle verb, and the locale seat.
|
|
525
|
+
*/
|
|
526
|
+
function PanelButton({ toggle, t }) {
|
|
527
|
+
return (0, react_jsx_runtime.jsx)("button", {
|
|
528
|
+
type: "button",
|
|
529
|
+
className: PanelButton_module_css_default.button,
|
|
530
|
+
onClick: toggle,
|
|
531
|
+
"aria-label": t("panel.open"),
|
|
532
|
+
"aria-pressed": "false",
|
|
533
|
+
title: t("panel.title"),
|
|
534
|
+
children: (0, react_jsx_runtime.jsx)("span", {
|
|
535
|
+
className: PanelButton_module_css_default.glyph,
|
|
536
|
+
children: "▤"
|
|
537
|
+
})
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
//#endregion
|
|
541
|
+
//#region lib/client/store.js
|
|
542
|
+
/**
|
|
543
|
+
* Panel store owned by the shell.overlay entry: the open flag plus the
|
|
544
|
+
* ever-opened marker. The composer button reaches the same state through
|
|
545
|
+
* ctx.promptPanel (the controller holds the entry's bound actions); inserts
|
|
546
|
+
* go through the controller's session-input path, never this store. The
|
|
547
|
+
* ever-opened marker lets the settings-driven default-open apply exactly
|
|
548
|
+
* once: any manual toggle or open marks the panel user-owned, so a late
|
|
549
|
+
* settings load can never reopen what the user closed.
|
|
550
|
+
*
|
|
551
|
+
* Module level exports the factory only (de-facto singleton prohibition —
|
|
552
|
+
* see ui-layout's store).
|
|
553
|
+
*/
|
|
554
|
+
/**
|
|
555
|
+
* Complete write set for the panel.
|
|
556
|
+
* @returns the store handle (spec + type + identity + factory in one).
|
|
557
|
+
*/
|
|
558
|
+
function createPromptPanelStore() {
|
|
559
|
+
return (0, _deepseek_ai_dsh_client_runtime_client.defineStore)({
|
|
560
|
+
init: () => ({
|
|
561
|
+
open: false,
|
|
562
|
+
everOpened: false
|
|
563
|
+
}),
|
|
564
|
+
actions: {
|
|
565
|
+
toggle: (d) => {
|
|
566
|
+
d.everOpened = true;
|
|
567
|
+
d.open = !d.open;
|
|
568
|
+
},
|
|
569
|
+
open: (d) => {
|
|
570
|
+
d.everOpened = true;
|
|
571
|
+
d.open = true;
|
|
572
|
+
},
|
|
573
|
+
close: (d) => {
|
|
574
|
+
d.everOpened = true;
|
|
575
|
+
d.open = false;
|
|
576
|
+
},
|
|
577
|
+
openOnce: (d) => {
|
|
578
|
+
if (d.everOpened) return;
|
|
579
|
+
d.everOpened = true;
|
|
580
|
+
d.open = true;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
//#endregion
|
|
586
|
+
//#region lib/client/service.js
|
|
587
|
+
/**
|
|
588
|
+
* Cross-entry panel face (ctx.promptPanel).
|
|
589
|
+
*/
|
|
590
|
+
var PromptPanelController = class {
|
|
591
|
+
#actions;
|
|
592
|
+
#sessions;
|
|
593
|
+
#conversation;
|
|
594
|
+
#pendingAutoOpen = false;
|
|
595
|
+
/**
|
|
596
|
+
* Adopt the shell.overlay entry's bound store actions. Called from that
|
|
597
|
+
* registration's inject hook; a re-register overwrites the stale set. A
|
|
598
|
+
* default-open that arrived before the entry's first render is applied
|
|
599
|
+
* here, once wiring exists.
|
|
600
|
+
* @param actions - bound actions of the panel store instance.
|
|
601
|
+
*/
|
|
602
|
+
attach(actions) {
|
|
603
|
+
this.#actions = actions;
|
|
604
|
+
if (this.#pendingAutoOpen) {
|
|
605
|
+
this.#pendingAutoOpen = false;
|
|
606
|
+
actions.openOnce();
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Bind the session-scope resolution services needed for inserts.
|
|
611
|
+
* @param deps - sessions and conversation services from the plugin closure.
|
|
612
|
+
*/
|
|
613
|
+
bind(deps) {
|
|
614
|
+
this.#sessions = deps.sessions;
|
|
615
|
+
this.#conversation = deps.conversation;
|
|
616
|
+
}
|
|
617
|
+
/** Flip the panel open/closed. */
|
|
618
|
+
toggle() {
|
|
619
|
+
this.#require().toggle();
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* Apply the settings-driven default open, at most once per store lifetime
|
|
623
|
+
* and never after any user interaction with the panel. Before the entry's
|
|
624
|
+
* first render the request parks as pending and attach() replays it.
|
|
625
|
+
*/
|
|
626
|
+
openOnce() {
|
|
627
|
+
if (this.#actions === void 0) {
|
|
628
|
+
this.#pendingAutoOpen = true;
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
this.#actions.openOnce();
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* Append one template's content to a session's composer draft. An empty
|
|
635
|
+
* draft takes the content verbatim; a non-empty draft joins with a newline.
|
|
636
|
+
* @param sessionId - target session.
|
|
637
|
+
* @param content - template content.
|
|
638
|
+
*/
|
|
639
|
+
insert(sessionId, content) {
|
|
640
|
+
const input = this.#inputOf(sessionId);
|
|
641
|
+
if (input === void 0) return;
|
|
642
|
+
const draft = input.state.getSnapshot().draft;
|
|
643
|
+
input.setDraft(draft === "" ? content : `${draft}\n${content}`);
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Fill the draft with one template's content and submit it immediately —
|
|
647
|
+
* the same transaction as typing the text and pressing send.
|
|
648
|
+
* @param sessionId - target session.
|
|
649
|
+
* @param content - template content.
|
|
650
|
+
*/
|
|
651
|
+
send(sessionId, content) {
|
|
652
|
+
const input = this.#inputOf(sessionId);
|
|
653
|
+
if (input === void 0) return;
|
|
654
|
+
input.setDraft(content);
|
|
655
|
+
input.submit();
|
|
656
|
+
}
|
|
657
|
+
/** Resolve a session's input facade, or undefined when out of reach. */
|
|
658
|
+
#inputOf(sessionId) {
|
|
659
|
+
const sessions = this.#sessions;
|
|
660
|
+
const conversation = this.#conversation;
|
|
661
|
+
if (sessions === void 0 || conversation === void 0) return void 0;
|
|
662
|
+
const actx = sessions.scope(sessionId);
|
|
663
|
+
if (actx === void 0) return void 0;
|
|
664
|
+
return conversation.input.for(actx);
|
|
665
|
+
}
|
|
666
|
+
#require() {
|
|
667
|
+
if (this.#actions === void 0) throw new Error("prompt-panel: panel actions not wired (shell.overlay entry not mounted)");
|
|
668
|
+
return this.#actions;
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
//#endregion
|
|
672
|
+
//#region lib/client/locales.js
|
|
673
|
+
/** Locale keys for the prompt-templates surface. */
|
|
674
|
+
/** Chinese dictionary. */
|
|
675
|
+
const zh = {
|
|
676
|
+
"panel.title": "快捷提示词",
|
|
677
|
+
"panel.dragHint": "拖动移动,双击复位",
|
|
678
|
+
"panel.sendNow": "直接发送",
|
|
679
|
+
"panel.open": "打开提示词面板",
|
|
680
|
+
"panel.close": "关闭提示词面板",
|
|
681
|
+
"panel.empty": "暂无模板",
|
|
682
|
+
"panel.search": "搜索模板…",
|
|
683
|
+
"panel.noMatch": "没有匹配的模板",
|
|
684
|
+
"panel.global": "全局模板",
|
|
685
|
+
"panel.session": "会话模板",
|
|
686
|
+
"panel.add": "新增",
|
|
687
|
+
"panel.addName": "模板名称",
|
|
688
|
+
"panel.addContent": "模板内容",
|
|
689
|
+
"panel.addSave": "保存",
|
|
690
|
+
"panel.addCancel": "取消",
|
|
691
|
+
"panel.insert": "插入",
|
|
692
|
+
"panel.delete": "删除",
|
|
693
|
+
"panel.edit": "编辑",
|
|
694
|
+
"panel.makeGlobal": "设为全局",
|
|
695
|
+
"panel.error": "操作失败",
|
|
696
|
+
"panel.inserted": "已插入",
|
|
697
|
+
"panel.none": "无"
|
|
698
|
+
};
|
|
699
|
+
/** English dictionary. */
|
|
700
|
+
const en = {
|
|
701
|
+
"panel.title": "Quick prompts",
|
|
702
|
+
"panel.dragHint": "Drag to move, double-click to reset",
|
|
703
|
+
"panel.sendNow": "Send now",
|
|
704
|
+
"panel.open": "Open prompt panel",
|
|
705
|
+
"panel.close": "Close prompt panel",
|
|
706
|
+
"panel.empty": "No templates yet",
|
|
707
|
+
"panel.search": "Search templates…",
|
|
708
|
+
"panel.noMatch": "No matching templates",
|
|
709
|
+
"panel.global": "Global templates",
|
|
710
|
+
"panel.session": "Session templates",
|
|
711
|
+
"panel.add": "Add",
|
|
712
|
+
"panel.addName": "Template name",
|
|
713
|
+
"panel.addContent": "Template content",
|
|
714
|
+
"panel.addSave": "Save",
|
|
715
|
+
"panel.addCancel": "Cancel",
|
|
716
|
+
"panel.insert": "Insert",
|
|
717
|
+
"panel.delete": "Delete",
|
|
718
|
+
"panel.edit": "Edit",
|
|
719
|
+
"panel.makeGlobal": "Make global",
|
|
720
|
+
"panel.error": "Operation failed",
|
|
721
|
+
"panel.inserted": "Inserted",
|
|
722
|
+
"panel.none": "None"
|
|
723
|
+
};
|
|
724
|
+
//#endregion
|
|
725
|
+
//#region lib/client/index.js
|
|
726
|
+
/** Dictionary namespace owned by this plugin. */
|
|
727
|
+
const NS = "promptTemplates";
|
|
728
|
+
/** Required services: slots, sessions, locale, conversation, and settings scope. */
|
|
729
|
+
const inject = [
|
|
730
|
+
"slots",
|
|
731
|
+
"sessions",
|
|
732
|
+
"locale",
|
|
733
|
+
"conversation",
|
|
734
|
+
"settingsScope"
|
|
735
|
+
];
|
|
736
|
+
/**
|
|
737
|
+
* Client plugin body: the shell.overlay panel owns the store; the controller
|
|
738
|
+
* bridges its actions to the composer entry and performs inserts.
|
|
739
|
+
* @param ctx - client root context.
|
|
740
|
+
*/
|
|
741
|
+
function apply(ctx) {
|
|
742
|
+
ctx.effect(() => ctx.locale.register(NS, {
|
|
743
|
+
zh,
|
|
744
|
+
en
|
|
745
|
+
}), "ui-prompt-templates: dictionaries");
|
|
746
|
+
const controller = new PromptPanelController();
|
|
747
|
+
controller.bind({
|
|
748
|
+
sessions: ctx.sessions,
|
|
749
|
+
conversation: ctx.conversation
|
|
750
|
+
});
|
|
751
|
+
ctx.effect(() => ctx.reflect.provide("promptPanel", controller), "ui-prompt-templates: panel service");
|
|
752
|
+
const uiSettings = ctx.settingsScope.bind({ namespace: "prompt-templates" });
|
|
753
|
+
const panelFace = {
|
|
754
|
+
refresh: listTemplates,
|
|
755
|
+
create: (request) => {
|
|
756
|
+
return createTemplate(request);
|
|
757
|
+
},
|
|
758
|
+
update: (id, request) => {
|
|
759
|
+
return updateTemplate(id, request);
|
|
760
|
+
},
|
|
761
|
+
remove: (id) => {
|
|
762
|
+
return deleteTemplate(id);
|
|
763
|
+
},
|
|
764
|
+
makeGlobal: (id) => {
|
|
765
|
+
return makeTemplateGlobal(id);
|
|
766
|
+
},
|
|
767
|
+
insert: (sessionId, content) => {
|
|
768
|
+
controller.insert(sessionId, content);
|
|
769
|
+
},
|
|
770
|
+
send: (sessionId, content) => {
|
|
771
|
+
controller.send(sessionId, content);
|
|
772
|
+
},
|
|
773
|
+
panelPosition: () => {
|
|
774
|
+
const snapshot = uiSettings.getSnapshot();
|
|
775
|
+
if (snapshot.status !== "ready") return null;
|
|
776
|
+
const panel = snapshot.value?.panel;
|
|
777
|
+
if (panel === void 0) return null;
|
|
778
|
+
return typeof panel.x === "number" && typeof panel.y === "number" ? panel : null;
|
|
779
|
+
},
|
|
780
|
+
savePanelPosition: (position) => {
|
|
781
|
+
uiSettings.set("panel", {
|
|
782
|
+
x: Math.round(position.x),
|
|
783
|
+
y: Math.round(position.y)
|
|
784
|
+
});
|
|
785
|
+
},
|
|
786
|
+
resetPanelPosition: () => {
|
|
787
|
+
uiSettings.unset("panel");
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
const applyDefaultOpen = () => {
|
|
791
|
+
const snapshot = uiSettings.getSnapshot();
|
|
792
|
+
if (snapshot.status === "ready" && snapshot.value?.defaultOpen === true) controller.openOnce();
|
|
793
|
+
};
|
|
794
|
+
ctx.effect(() => {
|
|
795
|
+
const unsubscribe = uiSettings.subscribe(applyDefaultOpen);
|
|
796
|
+
return () => {
|
|
797
|
+
unsubscribe();
|
|
798
|
+
};
|
|
799
|
+
}, "ui-prompt-templates: default-open watch");
|
|
800
|
+
applyDefaultOpen();
|
|
801
|
+
ctx.slots.inject("shell.overlay", () => ctx.slots.register({
|
|
802
|
+
name: "shell.overlay",
|
|
803
|
+
id: "prompt-templates",
|
|
804
|
+
order: 10,
|
|
805
|
+
locale: NS,
|
|
806
|
+
store: createPromptPanelStore,
|
|
807
|
+
inject: (actions) => {
|
|
808
|
+
controller.attach(actions);
|
|
809
|
+
return panelFace;
|
|
810
|
+
}
|
|
811
|
+
}, PromptPanel));
|
|
812
|
+
ctx.slots.inject("conversation.input.right", () => ctx.slots.register({
|
|
813
|
+
name: "conversation.input.right",
|
|
814
|
+
id: "prompt-templates",
|
|
815
|
+
order: 10,
|
|
816
|
+
locale: NS,
|
|
817
|
+
inject: () => ({ toggle: () => {
|
|
818
|
+
controller.toggle();
|
|
819
|
+
} })
|
|
820
|
+
}, PanelButton));
|
|
821
|
+
}
|
|
822
|
+
//#endregion
|
|
823
|
+
exports.PanelButton = PanelButton;
|
|
824
|
+
exports.PromptPanel = PromptPanel;
|
|
825
|
+
exports.PromptPanelController = PromptPanelController;
|
|
826
|
+
exports.apply = apply;
|
|
827
|
+
exports.inject = inject;
|
|
828
|
+
return module.exports;
|
|
829
|
+
}
|
|
830
|
+
});
|
|
831
|
+
|
|
832
|
+
//# sourceMappingURL=client.js.map
|