@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.
Files changed (50) hide show
  1. package/README.md +113 -62
  2. package/README_zh.md +112 -62
  3. package/cordis.patch.yml +4 -0
  4. package/lib/cli/app.js +169 -0
  5. package/lib/cli/database.js +162 -0
  6. package/lib/cli/main.js +6 -0
  7. package/lib/cli/model.js +247 -0
  8. package/lib/client/Library.js +290 -0
  9. package/lib/client/Panel.js +37 -201
  10. package/lib/client/PanelButton.js +27 -3
  11. package/lib/client/PromptTab.js +11 -0
  12. package/lib/client/api.js +16 -0
  13. package/lib/client/filter.js +27 -0
  14. package/lib/client/index.js +53 -36
  15. package/lib/client/locales.js +34 -2
  16. package/lib/client/meta.js +10 -0
  17. package/lib/client/service.js +57 -37
  18. package/lib/client/slots.js +5 -3
  19. package/lib/client/store.js +12 -1
  20. package/lib/client/tab.js +32 -0
  21. package/lib/client.js +798 -286
  22. package/lib/client.js.map +1 -1
  23. package/lib/index.js +35 -16
  24. package/lib/inject.js +236 -0
  25. package/lib/invariant.js +1 -1
  26. package/lib/store.js +108 -32
  27. package/lib/types/cli/app.d.ts +1 -0
  28. package/lib/types/cli/database.d.ts +69 -0
  29. package/lib/types/cli/main.d.ts +2 -0
  30. package/lib/types/cli/model.d.ts +62 -0
  31. package/lib/types/client/Library.d.ts +34 -0
  32. package/lib/types/client/Panel.d.ts +1 -1
  33. package/lib/types/client/PanelButton.d.ts +10 -9
  34. package/lib/types/client/PromptTab.d.ts +17 -0
  35. package/lib/types/client/api.d.ts +11 -1
  36. package/lib/types/client/filter.d.ts +10 -0
  37. package/lib/types/client/index.d.ts +6 -2
  38. package/lib/types/client/locales.d.ts +34 -2
  39. package/lib/types/client/meta.d.ts +6 -0
  40. package/lib/types/client/service.d.ts +50 -6
  41. package/lib/types/client/slots.d.ts +57 -5
  42. package/lib/types/client/store.d.ts +14 -1
  43. package/lib/types/client/tab.d.ts +31 -0
  44. package/lib/types/index.d.ts +8 -1
  45. package/lib/types/inject.d.ts +150 -0
  46. package/lib/types/store.d.ts +27 -4
  47. package/lib/types/types.d.ts +49 -0
  48. package/lib/types/variables.d.ts +24 -0
  49. package/lib/variables.js +36 -0
  50. package/package.json +98 -105
package/lib/client.js CHANGED
@@ -7,7 +7,7 @@ window.__ModuleLoader__.load({
7
7
  let react_jsx_runtime = require("react/jsx-runtime");
8
8
  let react = require("react");
9
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");
10
+ let _deepseek_ai_dsh_client_store = require("@deepseek-ai/dsh-client-store");
11
11
  //#region lib/client/api.js
12
12
  /**
13
13
  * Browser-side API over the host's `/plugins/dsh-prompt-templates` routes.
@@ -22,6 +22,18 @@ window.__ModuleLoader__.load({
22
22
  if (!response.ok) return [];
23
23
  return [...(await response.json()).items ?? []];
24
24
  }
25
+ /** Poll a session's latest scheduled injection; null when none since boot (badges hide). */
26
+ async function injectStatus(sessionId) {
27
+ const response = await fetch(`${BASE}/inject-status?session_id=${encodeURIComponent(sessionId)}`, { cache: "no-store" });
28
+ if (!response.ok) return null;
29
+ return (await response.json()).status ?? null;
30
+ }
31
+ /** Load a session recent scheduled injections, newest first (empty when none). */
32
+ async function injectionHistory(sessionId) {
33
+ const response = await fetch(`${BASE}/inject-status?session_id=${encodeURIComponent(sessionId)}`, { cache: "no-store" });
34
+ if (!response.ok) return [];
35
+ return [...(await response.json()).history ?? []];
36
+ }
25
37
  /** Load every user category tab (global + all sessions'; the panel filters). */
26
38
  async function listCategories() {
27
39
  const response = await fetch(`${BASE}/categories`, { cache: "no-store" });
@@ -85,8 +97,40 @@ window.__ModuleLoader__.load({
85
97
  }
86
98
  }
87
99
  //#endregion
100
+ //#region lib/client/filter.js
101
+ /**
102
+ * Filter the panel's rows. A non-empty query is global across every category
103
+ * while respecting privacy: every global template and only the current
104
+ * session's private templates are searchable. With no query, the active tab
105
+ * keeps its normal partition/category semantics.
106
+ */
107
+ /** All templates a search is allowed to inspect (global + current session). */
108
+ function searchableTemplateRows(templates, sessionId) {
109
+ return templates.filter((row) => row.scope === "global" || row.scope === "session" && row.session_id === sessionId);
110
+ }
111
+ function filterTemplateRows(templates, query, effectiveTab, activeCategory, sessionId) {
112
+ const needle = query.trim().toLowerCase();
113
+ const matches = (row) => row.name.toLowerCase().includes(needle) || row.content.toLowerCase().includes(needle);
114
+ if (needle !== "") return searchableTemplateRows(templates, sessionId).filter(matches);
115
+ return templates.filter((row) => {
116
+ if (effectiveTab === "global") return row.scope === "global" && row.category === null;
117
+ if (effectiveTab === "session") return row.scope === "session" && row.session_id === sessionId && row.category === null;
118
+ return activeCategory !== void 0 && row.category === activeCategory.name && row.scope === activeCategory.scope && (activeCategory.scope === "global" || row.session_id === sessionId);
119
+ });
120
+ }
121
+ //#endregion
122
+ //#region lib/client/meta.js
123
+ /** Canonical public source repository for the panel's metadata link. */
124
+ const GITHUB_REPOSITORY_URL = "https://github.com/NelsonLongXiang/dsh-prompt-templates";
125
+ /** Build-injected package version; `dev` only exists in unbundled unit tests. */
126
+ const PLUGIN_VERSION = "0.13.2";
127
+ /** Header count: current-tab size when idle, matched/searchable when searching. */
128
+ function templateCountLabel(matched, searchable, searching) {
129
+ return searching ? `${matched}/${searchable}` : String(matched);
130
+ }
131
+ //#endregion
88
132
  //#region \0dsh-css:D:\workspace\dsh-prompt-templates\src\client\Panel.module.css.mjs
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)}";
133
+ 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_titleGroup{align-items:center;gap:6px;min-width:0;display:inline-flex}.h6AEjq_title{font-size:13px;font-weight:600}.h6AEjq_countBadge{box-sizing:border-box;min-width:18px;height:18px;color:var(--dsw-alias-label-secondary);background:var(--dsw-alias-interactive-bg-hover);border-radius:999px;justify-content:center;align-items:center;padding:0 5px;font-size:10px;line-height:1;display:inline-flex}.h6AEjq_injectBadge{box-sizing:border-box;min-width:18px;height:18px;color:var(--dsw-alias-label-secondary);background:var(--dsw-alias-interactive-bg-hover);cursor:help;user-select:none;border-radius:999px;justify-content:center;align-items:center;padding:0 5px;font-size:10px;line-height:1;display:inline-flex}.h6AEjq_injectBadgeButton{font:inherit;cursor:pointer;border:none}.h6AEjq_injectBadgeButton:hover{filter:brightness(.92)}.h6AEjq_injectHistory{z-index:30;box-sizing:border-box;border:1px solid var(--dsw-alias-border-inverted);background:var(--dsw-alias-bg-base);text-align:left;border-radius:6px;max-height:280px;padding:6px 0;font-size:11px;position:absolute;top:40px;left:8px;right:8px;overflow-y:auto;box-shadow:0 4px 16px #0000002e}.h6AEjq_injectHistoryTitle{color:var(--dsw-alias-label-secondary);padding:2px 10px 6px}.h6AEjq_injectHistoryEmpty{color:var(--dsw-alias-label-secondary);padding:4px 10px}.h6AEjq_injectHistoryItem{padding:6px 10px}.h6AEjq_injectHistoryItem+.h6AEjq_injectHistoryItem{border-top:1px solid var(--dsw-alias-border-inverted)}.h6AEjq_injectHistoryHead{color:var(--dsw-alias-label-secondary);white-space:nowrap;text-overflow:ellipsis;overflow:hidden}.h6AEjq_injectHistoryContent{white-space:pre-wrap;word-break:break-word;max-height:84px;margin-top:4px;overflow-y:auto}.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_variablesHint{color:var(--dsw-alias-label-secondary);padding:0 2px 4px;font-size:10px;line-height:1.4}.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_injectBtn{cursor:pointer;color:var(--dsw-alias-label-tertiary);background:0 0;border:none;border-radius:4px;padding:4px;font-size:11px;line-height:1}.h6AEjq_injectBtn:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}.h6AEjq_injectBtnActive{border:1px solid var(--dsw-alias-state-business-primary);cursor:pointer;color:var(--dsw-alias-state-business-primary);background:0 0;border-radius:4px;padding:3px 5px;font-size:11px;line-height:1}.h6AEjq_injectBtnActive:hover{background:var(--dsw-alias-interactive-bg-hover)}.h6AEjq_injectRow{flex-wrap:wrap;align-items:center;gap:12px;display:flex}.h6AEjq_injectLabel{color:var(--dsw-alias-label-secondary);align-items:center;gap:4px;font-size:11px;display:inline-flex}.h6AEjq_injectEveryInput{border:1px solid var(--dsw-alias-border-inverted);background:var(--dsw-specific-input-major);width:52px;color:var(--dsw-alias-label-primary);border-radius:4px;padding:2px 4px;font-family:inherit;font-size:11px}.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:space-between;align-items:center;gap:8px;padding:8px;display:flex}.h6AEjq_meta{min-width:0;color:var(--dsw-alias-label-tertiary);align-items:center;gap:6px;font-size:10px;display:inline-flex}.h6AEjq_githubLink{color:var(--dsw-alias-label-secondary);text-decoration:none}.h6AEjq_githubLink:hover{color:var(--dsw-alias-label-primary);text-decoration:underline}.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)}.h6AEjq_library{min-height:0;color:var(--dsw-alias-label-primary);flex-direction:column;flex:1;display:flex;position:relative}.h6AEjq_toolbar{border-bottom:1px solid var(--dsw-alias-border-inverted);user-select:none;justify-content:space-between;align-items:center;gap:6px;padding:10px 12px;display:flex}.h6AEjq_toolbarDraggable{cursor:grab;touch-action:none}.h6AEjq_toolbarDraggable:active{cursor:grabbing}.h6AEjq_tabBody{height:100%;min-height:0;color:var(--dsw-alias-label-primary);flex-direction:column;padding:4px;display:flex}";
90
134
  const tagId$1 = "@nelsonlongxiang/dsh-prompt-templates/Panel.module.css";
91
135
  if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$1) + "]") === null) {
92
136
  const tag = document.createElement("style");
@@ -104,17 +148,34 @@ window.__ModuleLoader__.load({
104
148
  "cancelBtn": "h6AEjq_cancelBtn",
105
149
  "closeBtn": "h6AEjq_closeBtn",
106
150
  "contentInput": "h6AEjq_contentInput",
151
+ "countBadge": "h6AEjq_countBadge",
107
152
  "deleteBtn": "h6AEjq_deleteBtn",
108
153
  "editBtn": "h6AEjq_editBtn",
109
154
  "empty": "h6AEjq_empty",
110
155
  "error": "h6AEjq_error",
111
156
  "footer": "h6AEjq_footer",
157
+ "githubLink": "h6AEjq_githubLink",
112
158
  "globalBtn": "h6AEjq_globalBtn",
113
159
  "group": "h6AEjq_group",
114
160
  "groupTitle": "h6AEjq_groupTitle",
115
161
  "header": "h6AEjq_header",
162
+ "injectBadge": "h6AEjq_injectBadge",
163
+ "injectBadgeButton": "h6AEjq_injectBadgeButton",
164
+ "injectBtn": "h6AEjq_injectBtn",
165
+ "injectBtnActive": "h6AEjq_injectBtnActive",
166
+ "injectEveryInput": "h6AEjq_injectEveryInput",
167
+ "injectHistory": "h6AEjq_injectHistory",
168
+ "injectHistoryContent": "h6AEjq_injectHistoryContent",
169
+ "injectHistoryEmpty": "h6AEjq_injectHistoryEmpty",
170
+ "injectHistoryHead": "h6AEjq_injectHistoryHead",
171
+ "injectHistoryItem": "h6AEjq_injectHistoryItem",
172
+ "injectHistoryTitle": "h6AEjq_injectHistoryTitle",
173
+ "injectLabel": "h6AEjq_injectLabel",
174
+ "injectRow": "h6AEjq_injectRow",
116
175
  "insert": "h6AEjq_insert",
117
176
  "interjectBtn": "h6AEjq_interjectBtn",
177
+ "library": "h6AEjq_library",
178
+ "meta": "h6AEjq_meta",
118
179
  "name": "h6AEjq_name",
119
180
  "nameInput": "h6AEjq_nameInput",
120
181
  "panel": "h6AEjq_panel",
@@ -128,37 +189,47 @@ window.__ModuleLoader__.load({
128
189
  "tab": "h6AEjq_tab",
129
190
  "tabActive": "h6AEjq_tabActive",
130
191
  "tabAdd": "h6AEjq_tabAdd",
192
+ "tabBody": "h6AEjq_tabBody",
131
193
  "tabDelete": "h6AEjq_tabDelete",
132
194
  "tabsBar": "h6AEjq_tabsBar",
133
- "title": "h6AEjq_title"
195
+ "title": "h6AEjq_title",
196
+ "titleGroup": "h6AEjq_titleGroup",
197
+ "toolbar": "h6AEjq_toolbar",
198
+ "toolbarDraggable": "h6AEjq_toolbarDraggable",
199
+ "variablesHint": "h6AEjq_variablesHint"
134
200
  };
135
201
  //#endregion
136
- //#region lib/client/Panel.js
202
+ //#region lib/client/Library.js
137
203
  /**
138
- * Quick prompt panel: the right-anchored floating surface registered into
139
- * shell.overlay. Lists global templates plus the current session's private
140
- * ones; clicking a row inserts its content into the composer draft. The
141
- * injected face carries the CRUD verbs and insert; the panel store holds
142
- * visibility; the current session arrives through the standard kit.
204
+ * The template library: the search bar, category tabs, row list, inline
205
+ * forms, and footer shared by BOTH surfaces — the floating shell.overlay
206
+ * panel and the right-sidebar tab body. This component owns the list state
207
+ * (rows, categories, query, active tab, in-place edit) and loads on mount;
208
+ * each host surface decides placement around it. The delivery target is
209
+ * passed in as `sessionId` (the overlay reads it from its composer-entry
210
+ * attachment; the sidebar tab reads it straight from its standard props).
143
211
  */
144
- function TemplateRow({ template, onInsert, onSend, onInterject, onEdit, onDelete, onMakeGlobal, onDragStart, onDropOn, t }) {
212
+ function TemplateRow({ template, onInsert, onSend, onInterject, onEdit, onDelete, onMakeGlobal, onToggleInject, sortable, onDragStart, onDropOn, t }) {
213
+ const injectTitle = template.inject_enabled && template.inject_every !== null ? `${t("panel.inject")} · ${template.inject_every}${template.mode === "visible" ? " · " + t("panel.modeVisible") : ""}` : t("panel.inject");
145
214
  return (0, react_jsx_runtime.jsxs)("div", {
146
215
  className: Panel_module_css_default.row,
147
216
  "data-prompt-template": true,
148
217
  onMouseDown: (e) => {
149
218
  e.preventDefault();
150
219
  },
151
- draggable: true,
220
+ draggable: sortable,
152
221
  onDragStart: () => {
153
- onDragStart(template.id);
222
+ if (sortable) onDragStart(template.id);
154
223
  },
155
224
  onDragOver: (e) => {
156
- e.preventDefault();
225
+ if (sortable) e.preventDefault();
157
226
  },
158
227
  onDrop: (e) => {
159
- e.preventDefault();
160
- e.stopPropagation();
161
- onDropOn(template.id);
228
+ if (sortable) {
229
+ e.preventDefault();
230
+ e.stopPropagation();
231
+ onDropOn(template.id);
232
+ }
162
233
  },
163
234
  children: [
164
235
  (0, react_jsx_runtime.jsxs)("button", {
@@ -176,6 +247,17 @@ window.__ModuleLoader__.load({
176
247
  children: template.content
177
248
  })]
178
249
  }),
250
+ (0, react_jsx_runtime.jsxs)("button", {
251
+ type: "button",
252
+ className: template.inject_enabled ? Panel_module_css_default.injectBtnActive : Panel_module_css_default.injectBtn,
253
+ onClick: () => {
254
+ onToggleInject(template);
255
+ },
256
+ "aria-label": t("panel.inject"),
257
+ "aria-pressed": template.inject_enabled,
258
+ title: injectTitle,
259
+ children: ["⟳", template.inject_enabled && template.inject_every !== null ? template.inject_every : ""]
260
+ }),
179
261
  (0, react_jsx_runtime.jsx)("button", {
180
262
  type: "button",
181
263
  className: Panel_module_css_default.interjectBtn,
@@ -184,7 +266,7 @@ window.__ModuleLoader__.load({
184
266
  },
185
267
  "aria-label": t("panel.interject"),
186
268
  title: t("panel.interject"),
187
- children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconQueueOutline14, { size: 12 })
269
+ children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconQueueOutlineRegular, { size: 12 })
188
270
  }),
189
271
  (0, react_jsx_runtime.jsx)("button", {
190
272
  type: "button",
@@ -194,7 +276,7 @@ window.__ModuleLoader__.load({
194
276
  },
195
277
  "aria-label": t("panel.sendNow"),
196
278
  title: t("panel.sendNow"),
197
- children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconSendOutline16, { size: 12 })
279
+ children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconSendOutlineRegular, { size: 12 })
198
280
  }),
199
281
  onMakeGlobal !== void 0 && (0, react_jsx_runtime.jsx)("button", {
200
282
  type: "button",
@@ -204,7 +286,7 @@ window.__ModuleLoader__.load({
204
286
  },
205
287
  "aria-label": t("panel.makeGlobal"),
206
288
  title: t("panel.makeGlobal"),
207
- children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconGlobeOutline14, { size: 12 })
289
+ children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconGlobeOutlineRegular, { size: 12 })
208
290
  }),
209
291
  (0, react_jsx_runtime.jsx)("button", {
210
292
  type: "button",
@@ -214,7 +296,7 @@ window.__ModuleLoader__.load({
214
296
  },
215
297
  "aria-label": t("panel.edit"),
216
298
  title: t("panel.edit"),
217
- children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconEditOutline16, { size: 12 })
299
+ children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconEditOutlineRegular, { size: 12 })
218
300
  }),
219
301
  (0, react_jsx_runtime.jsx)("button", {
220
302
  type: "button",
@@ -223,7 +305,7 @@ window.__ModuleLoader__.load({
223
305
  onDelete(template.id);
224
306
  },
225
307
  "aria-label": t("panel.delete"),
226
- children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconTrashOutline16, { size: 12 })
308
+ children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconTrashOutlineRegular, { size: 12 })
227
309
  })
228
310
  ]
229
311
  });
@@ -232,8 +314,11 @@ window.__ModuleLoader__.load({
232
314
  function TemplateForm({ initial, allowScope, sessionId, categories, t, submitLabel, onSubmit, onDone, onCancel }) {
233
315
  const [name, setName] = (0, react.useState)(initial?.name ?? "");
234
316
  const [content, setContent] = (0, react.useState)(initial?.content ?? "");
235
- const [scope, setScope] = (0, react.useState)("global");
236
- const [category, setCategory] = (0, react.useState)(null);
317
+ const [scope, setScope] = (0, react.useState)(initial?.scope ?? "global");
318
+ const [category, setCategory] = (0, react.useState)(initial?.category ?? null);
319
+ const [injectOn, setInjectOn] = (0, react.useState)(initial?.injectEnabled ?? false);
320
+ const [injectEvery, setInjectEvery] = (0, react.useState)(initial?.injectEvery != null ? String(initial.injectEvery) : "5");
321
+ const [mode, setMode] = (0, react.useState)(initial?.mode ?? "inject");
237
322
  const [busy, setBusy] = (0, react.useState)(false);
238
323
  const [error, setError] = (0, react.useState)(null);
239
324
  const submit = (0, react.useCallback)(async () => {
@@ -244,9 +329,18 @@ window.__ModuleLoader__.load({
244
329
  setError(t("panel.error"));
245
330
  return;
246
331
  }
332
+ let every = null;
333
+ if (injectOn) {
334
+ const parsed = Number(injectEvery);
335
+ if (!Number.isInteger(parsed) || parsed < 1) {
336
+ setError(t("panel.error"));
337
+ return;
338
+ }
339
+ every = parsed;
340
+ }
247
341
  setBusy(true);
248
342
  setError(null);
249
- const ok = await onSubmit(trimmedName, trimmedContent, scope, category);
343
+ const ok = await onSubmit(trimmedName, trimmedContent, scope, category, injectOn, every, mode);
250
344
  setBusy(false);
251
345
  if (!ok) {
252
346
  setError(t("panel.error"));
@@ -258,6 +352,9 @@ window.__ModuleLoader__.load({
258
352
  content,
259
353
  scope,
260
354
  category,
355
+ injectOn,
356
+ injectEvery,
357
+ mode,
261
358
  allowScope,
262
359
  sessionId,
263
360
  onSubmit,
@@ -289,6 +386,57 @@ window.__ModuleLoader__.load({
289
386
  rows: 3,
290
387
  "aria-label": t("panel.addContent")
291
388
  }),
389
+ (0, react_jsx_runtime.jsx)("div", {
390
+ className: Panel_module_css_default.variablesHint,
391
+ children: t("panel.variablesHint")
392
+ }),
393
+ (0, react_jsx_runtime.jsxs)("div", {
394
+ className: Panel_module_css_default.injectRow,
395
+ children: [
396
+ (0, react_jsx_runtime.jsxs)("label", {
397
+ className: Panel_module_css_default.injectLabel,
398
+ children: [(0, react_jsx_runtime.jsx)("input", {
399
+ type: "checkbox",
400
+ checked: injectOn,
401
+ onChange: (e) => {
402
+ setInjectOn(e.target.checked);
403
+ }
404
+ }), t("panel.inject")]
405
+ }),
406
+ injectOn && (0, react_jsx_runtime.jsxs)("label", {
407
+ className: Panel_module_css_default.injectLabel,
408
+ children: [(0, react_jsx_runtime.jsx)("input", {
409
+ className: Panel_module_css_default.injectEveryInput,
410
+ type: "number",
411
+ min: 1,
412
+ step: 1,
413
+ value: injectEvery,
414
+ onChange: (e) => {
415
+ setInjectEvery(e.target.value);
416
+ },
417
+ "aria-label": t("panel.injectEvery")
418
+ }), t("panel.injectEvery")]
419
+ }),
420
+ injectOn && (0, react_jsx_runtime.jsx)("label", {
421
+ className: Panel_module_css_default.injectLabel,
422
+ title: t("panel.modeHint"),
423
+ children: (0, react_jsx_runtime.jsxs)("select", {
424
+ value: mode,
425
+ onChange: (e) => {
426
+ setMode(e.target.value);
427
+ },
428
+ "aria-label": t("panel.modeLabel"),
429
+ children: [(0, react_jsx_runtime.jsx)("option", {
430
+ value: "inject",
431
+ children: t("panel.modeInject")
432
+ }), (0, react_jsx_runtime.jsx)("option", {
433
+ value: "visible",
434
+ children: t("panel.modeVisible")
435
+ })]
436
+ })
437
+ })
438
+ ]
439
+ }),
292
440
  (0, react_jsx_runtime.jsxs)("div", {
293
441
  className: Panel_module_css_default.addRow,
294
442
  children: [
@@ -357,32 +505,91 @@ window.__ModuleLoader__.load({
357
505
  ]
358
506
  });
359
507
  }
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)
508
+ /** Inline form creating one category tab: name + scope (global, or the current session). */
509
+ function CategoryForm({ sessionId, createCategory, t, onDone }) {
510
+ const [name, setName] = (0, react.useState)("");
511
+ const [scope, setScope] = (0, react.useState)("global");
512
+ const [busy, setBusy] = (0, react.useState)(false);
513
+ const [error, setError] = (0, react.useState)(null);
514
+ const submit = async () => {
515
+ const trimmed = name.trim();
516
+ if (trimmed === "") return;
517
+ if (scope === "session" && sessionId === null) {
518
+ setError(t("panel.error"));
519
+ return;
520
+ }
521
+ setBusy(true);
522
+ setError(null);
523
+ const result = await createCategory({
524
+ name: trimmed,
525
+ scope,
526
+ session_id: scope === "session" ? sessionId : null
527
+ });
528
+ setBusy(false);
529
+ if (!result.ok) {
530
+ setError(t("panel.error"));
531
+ return;
532
+ }
533
+ onDone();
376
534
  };
535
+ return (0, react_jsx_runtime.jsxs)("div", {
536
+ className: Panel_module_css_default.addForm,
537
+ "data-prompt-category-add": true,
538
+ children: [(0, react_jsx_runtime.jsx)("input", {
539
+ className: Panel_module_css_default.nameInput,
540
+ type: "text",
541
+ placeholder: t("panel.categoryName"),
542
+ value: name,
543
+ onChange: (e) => {
544
+ setName(e.target.value);
545
+ },
546
+ "aria-label": t("panel.categoryName")
547
+ }), (0, react_jsx_runtime.jsxs)("div", {
548
+ className: Panel_module_css_default.addRow,
549
+ children: [(0, react_jsx_runtime.jsx)("label", {
550
+ className: Panel_module_css_default.scopeLabel,
551
+ children: (0, react_jsx_runtime.jsxs)("select", {
552
+ value: scope,
553
+ onChange: (e) => {
554
+ setScope(e.target.value);
555
+ },
556
+ "aria-label": "scope",
557
+ children: [(0, react_jsx_runtime.jsx)("option", {
558
+ value: "global",
559
+ children: t("panel.global")
560
+ }), (0, react_jsx_runtime.jsx)("option", {
561
+ value: "session",
562
+ disabled: sessionId === null,
563
+ children: t("panel.session")
564
+ })]
565
+ })
566
+ }), (0, react_jsx_runtime.jsxs)("div", {
567
+ className: Panel_module_css_default.addActions,
568
+ children: [error !== null && (0, react_jsx_runtime.jsx)("span", {
569
+ className: Panel_module_css_default.error,
570
+ role: "alert",
571
+ children: error
572
+ }), (0, react_jsx_runtime.jsx)("button", {
573
+ type: "button",
574
+ className: Panel_module_css_default.saveBtn,
575
+ onClick: () => void submit(),
576
+ disabled: busy || name.trim() === "",
577
+ children: t("panel.addSave")
578
+ })]
579
+ })]
580
+ })]
581
+ });
377
582
  }
378
583
  /**
379
- * The prompt-templates panel body.
380
- * @param props - runtime kit, injected face members, store handle, and locale.
584
+ * The shared template library: toolbar (title + row count), live search,
585
+ * category tabs, the row list with inline edit/create forms, and the
586
+ * footer. Loads everything on mount; the parent decides placement and
587
+ * lifetime (the overlay mounts it only while open, the sidebar tab mounts
588
+ * it for the tab's lifetime).
589
+ * @param props - target session, shared verbs, locale, optional title-row takeover.
381
590
  */
382
- function PromptPanel(props) {
383
- const { useStore, useSessions, refresh, refreshCategories, createCategory, removeCategory, create, update, remove, makeGlobal, insert, send, interject, panelPosition, savePanelPosition, resetPanelPosition, actions, t } = props;
384
- const open = useStore((s) => s.open);
385
- const currentSession = useSessions((s) => s.current);
591
+ function TemplateLibrary({ sessionId, face, t, header, headerExtra }) {
592
+ const { refresh, refreshCategories, createCategory, removeCategory, create, update, remove, makeGlobal, insert, send, interject, injectStatus, injectionHistory } = face;
386
593
  const [templates, setTemplates] = (0, react.useState)([]);
387
594
  const [categories, setCategories] = (0, react.useState)([]);
388
595
  const [showAdd, setShowAdd] = (0, react.useState)(false);
@@ -391,11 +598,7 @@ window.__ModuleLoader__.load({
391
598
  const [activeTab, setActiveTab] = (0, react.useState)("global");
392
599
  const [showCatForm, setShowCatForm] = (0, react.useState)(false);
393
600
  const dragRowRef = (0, react.useRef)(null);
394
- const persisted = clampToViewport(panelPosition());
395
- const [dragPos, setDragPos] = (0, react.useState)(null);
396
- const dragRef = (0, react.useRef)(null);
397
- const panelRef = (0, react.useRef)(null);
398
- const sessionId = currentSession ?? null;
601
+ const [rowError, setRowError] = (0, react.useState)(null);
399
602
  const load = (0, react.useCallback)(async () => {
400
603
  const items = await refresh();
401
604
  setTemplates(items);
@@ -404,15 +607,45 @@ window.__ModuleLoader__.load({
404
607
  setCategories(await refreshCategories());
405
608
  }, [refreshCategories]);
406
609
  (0, react.useEffect)(() => {
407
- if (open) {
408
- load();
409
- loadCategories();
610
+ load();
611
+ loadCategories();
612
+ }, [load, loadCategories]);
613
+ const [injected, setInjected] = (0, react.useState)(null);
614
+ const pollStatus = (0, react.useCallback)(async () => {
615
+ if (sessionId === null) {
616
+ setInjected(null);
617
+ return;
618
+ }
619
+ setInjected(await injectStatus(sessionId));
620
+ }, [injectStatus, sessionId]);
621
+ (0, react.useEffect)(() => {
622
+ pollStatus();
623
+ const timer = setInterval(() => {
624
+ pollStatus();
625
+ }, 3e4);
626
+ return () => {
627
+ clearInterval(timer);
628
+ };
629
+ }, [pollStatus]);
630
+ const [historyOpen, setHistoryOpen] = (0, react.useState)(false);
631
+ const [history, setHistory] = (0, react.useState)([]);
632
+ const loadHistory = (0, react.useCallback)(async () => {
633
+ if (sessionId === null) {
634
+ setHistory([]);
635
+ return;
410
636
  }
637
+ setHistory(await injectionHistory(sessionId));
638
+ }, [injectionHistory, sessionId]);
639
+ (0, react.useEffect)(() => {
640
+ if (historyOpen) loadHistory();
411
641
  }, [
412
- open,
413
- load,
414
- loadCategories
642
+ historyOpen,
643
+ loadHistory,
644
+ injected
415
645
  ]);
646
+ (0, react.useEffect)(() => {
647
+ setHistoryOpen(false);
648
+ }, [sessionId]);
416
649
  const handleInsert = (0, react.useCallback)((content) => {
417
650
  if (sessionId === null) return;
418
651
  insert(sessionId, content);
@@ -431,55 +664,24 @@ window.__ModuleLoader__.load({
431
664
  const handleMakeGlobal = (0, react.useCallback)(async (id) => {
432
665
  if ((await makeGlobal(id)).ok) load();
433
666
  }, [makeGlobal, load]);
434
- const onHeaderPointerDown = (event) => {
435
- if (event.button !== 0) return;
436
- if (event.target.closest("button")) return;
437
- const panel = panelRef.current;
438
- if (panel === null) return;
439
- const rect = panel.getBoundingClientRect();
440
- dragRef.current = {
441
- pointerId: event.pointerId,
442
- offX: event.clientX - rect.left,
443
- offY: event.clientY - rect.top
444
- };
445
- if (Reflect.has(event.currentTarget, "setPointerCapture")) event.currentTarget.setPointerCapture(event.pointerId);
446
- };
447
- const onHeaderPointerMove = (event) => {
448
- const drag = dragRef.current;
449
- if (drag === null || event.pointerId !== drag.pointerId) return;
450
- const width = panelRef.current?.getBoundingClientRect().width ?? 320;
451
- const maxX = Math.max(0, window.innerWidth - width);
452
- const maxY = Math.max(0, window.innerHeight - 40);
453
- const x = Math.min(Math.max(event.clientX - drag.offX, 0), maxX);
454
- const y = Math.min(Math.max(event.clientY - drag.offY, 0), maxY);
455
- setDragPos({
456
- x,
457
- y
458
- });
459
- };
460
- const onHeaderPointerUp = (event) => {
461
- const drag = dragRef.current;
462
- if (drag === null || event.pointerId !== drag.pointerId) return;
463
- dragRef.current = null;
464
- if (Reflect.has(event.currentTarget, "releasePointerCapture")) event.currentTarget.releasePointerCapture(event.pointerId);
465
- if (dragPos !== null) savePanelPosition(dragPos);
466
- };
467
- const onHeaderDoubleClick = () => {
468
- setDragPos(null);
469
- resetPanelPosition();
470
- };
471
- if (!open) return null;
472
- const needle = query.trim().toLowerCase();
473
- const matches = (row) => needle === "" || row.name.toLowerCase().includes(needle) || row.content.toLowerCase().includes(needle);
667
+ const handleToggleInject = (0, react.useCallback)(async (template) => {
668
+ if (!template.inject_enabled && template.inject_every === null) {
669
+ setEditingId(template.id);
670
+ return;
671
+ }
672
+ const result = await update(template.id, { inject_enabled: !template.inject_enabled });
673
+ if (result.ok) {
674
+ setRowError(null);
675
+ load();
676
+ } else setRowError(result.error.message);
677
+ }, [update, load]);
474
678
  const visibleCategories = categories.filter((cat) => cat.scope === "global" || cat.scope === "session" && cat.session_id === sessionId);
475
679
  const activeCategory = activeTab.startsWith("cat:") ? visibleCategories.find((cat) => `cat:${cat.scope}:${cat.name}` === activeTab) : void 0;
476
680
  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
- });
681
+ const needle = query.trim().toLowerCase();
682
+ const tabRows = filterTemplateRows(templates, query, effectiveTab, activeCategory, sessionId);
683
+ const searchableCount = searchableTemplateRows(templates, sessionId).length;
684
+ const countLabel = templateCountLabel(tabRows.length, searchableCount, needle !== "");
483
685
  const handleRowDrop = (targetId) => {
484
686
  const draggedId = dragRowRef.current;
485
687
  dragRowRef.current = null;
@@ -498,18 +700,30 @@ window.__ModuleLoader__.load({
498
700
  const renderTemplateRow = (row) => editingId === row.id ? (0, react_jsx_runtime.jsx)(TemplateForm, {
499
701
  initial: {
500
702
  name: row.name,
501
- content: row.content
703
+ content: row.content,
704
+ scope: row.scope,
705
+ category: row.category,
706
+ injectEnabled: row.inject_enabled,
707
+ injectEvery: row.inject_every,
708
+ mode: row.mode
502
709
  },
503
710
  allowScope: false,
504
711
  sessionId,
505
712
  categories: visibleCategories,
506
713
  t,
507
714
  submitLabel: t("panel.addSave"),
508
- onSubmit: async (name, content, _scope, category) => (await update(row.id, {
509
- name,
510
- content,
511
- category: row.scope === "global" ? category : category
512
- })).ok,
715
+ onSubmit: async (name, content, _scope, category, injectEnabled, injectEvery, mode) => {
716
+ return (await update(row.id, {
717
+ name,
718
+ content,
719
+ category,
720
+ inject_enabled: injectEnabled,
721
+ ...injectEnabled ? {
722
+ inject_every: injectEvery,
723
+ mode
724
+ } : {}
725
+ })).ok;
726
+ },
513
727
  onDone: () => {
514
728
  setEditingId(null);
515
729
  load();
@@ -537,6 +751,10 @@ window.__ModuleLoader__.load({
537
751
  onMakeGlobal: row.scope === "session" ? (id) => {
538
752
  handleMakeGlobal(id);
539
753
  } : void 0,
754
+ onToggleInject: (tpl) => {
755
+ handleToggleInject(tpl);
756
+ },
757
+ sortable: needle === "",
540
758
  onDragStart: (id) => {
541
759
  dragRowRef.current = id;
542
760
  },
@@ -545,39 +763,77 @@ window.__ModuleLoader__.load({
545
763
  },
546
764
  t
547
765
  }, row.id);
548
- const placement = dragPos ?? persisted;
549
- const placementStyle = placement === null ? void 0 : {
550
- left: placement.x,
551
- top: placement.y,
552
- right: "auto",
553
- bottom: "auto",
554
- maxHeight: `calc(100vh - ${placement.y}px - 16px)`
555
- };
556
766
  return (0, react_jsx_runtime.jsxs)("div", {
557
- className: Panel_module_css_default.panel,
558
- "data-prompt-panel": true,
559
- ref: panelRef,
560
- style: placementStyle,
767
+ className: Panel_module_css_default.library,
768
+ "data-prompt-library": true,
561
769
  children: [
562
770
  (0, react_jsx_runtime.jsxs)("div", {
563
- className: Panel_module_css_default.header,
564
- title: t("panel.dragHint"),
565
- onPointerDown: onHeaderPointerDown,
566
- onPointerMove: onHeaderPointerMove,
567
- onPointerUp: onHeaderPointerUp,
568
- onDoubleClick: onHeaderDoubleClick,
569
- children: [(0, react_jsx_runtime.jsx)("span", {
570
- className: Panel_module_css_default.title,
571
- children: t("panel.title")
572
- }), (0, react_jsx_runtime.jsx)("button", {
573
- type: "button",
574
- className: Panel_module_css_default.closeBtn,
575
- onClick: () => {
576
- actions.close();
577
- },
578
- "aria-label": t("panel.close"),
579
- children: "×"
580
- })]
771
+ className: header !== void 0 ? `${Panel_module_css_default.toolbar} ${Panel_module_css_default.toolbarDraggable}` : Panel_module_css_default.toolbar,
772
+ title: header?.hint,
773
+ onPointerDown: header?.onPointerDown,
774
+ onPointerMove: header?.onPointerMove,
775
+ onPointerUp: header?.onPointerUp,
776
+ onDoubleClick: header?.onDoubleClick,
777
+ children: [(0, react_jsx_runtime.jsxs)("span", {
778
+ className: Panel_module_css_default.titleGroup,
779
+ children: [
780
+ (0, react_jsx_runtime.jsx)("span", {
781
+ className: Panel_module_css_default.title,
782
+ children: t("panel.title")
783
+ }),
784
+ (0, react_jsx_runtime.jsx)("span", {
785
+ className: Panel_module_css_default.countBadge,
786
+ "data-template-count": true,
787
+ title: needle !== "" ? t("panel.searchCount") : t("panel.tabCount"),
788
+ children: countLabel
789
+ }),
790
+ injected !== null && (0, react_jsx_runtime.jsxs)("button", {
791
+ type: "button",
792
+ className: `${Panel_module_css_default.injectBadge} ${Panel_module_css_default.injectBadgeButton}`,
793
+ "data-prompt-injected": true,
794
+ title: `${t("panel.injectedAt")} ${injected.turn} · ${new Date(injected.at).toLocaleTimeString()} · ${injected.templates.join(", ")}`,
795
+ "aria-label": t("panel.historyTitle"),
796
+ "aria-expanded": historyOpen,
797
+ onClick: () => {
798
+ setHistoryOpen((open) => !open);
799
+ },
800
+ children: ["⟳", injected.turn]
801
+ })
802
+ ]
803
+ }), headerExtra]
804
+ }),
805
+ historyOpen && (0, react_jsx_runtime.jsxs)("div", {
806
+ className: Panel_module_css_default.injectHistory,
807
+ "data-prompt-inject-history": true,
808
+ role: "dialog",
809
+ "aria-label": t("panel.historyTitle"),
810
+ children: [
811
+ (0, react_jsx_runtime.jsx)("div", {
812
+ className: Panel_module_css_default.injectHistoryTitle,
813
+ children: t("panel.historyTitle")
814
+ }),
815
+ history.length === 0 && (0, react_jsx_runtime.jsx)("div", {
816
+ className: Panel_module_css_default.injectHistoryEmpty,
817
+ children: t("panel.historyEmpty")
818
+ }),
819
+ history.map((entry) => (0, react_jsx_runtime.jsxs)("div", {
820
+ className: Panel_module_css_default.injectHistoryItem,
821
+ children: [(0, react_jsx_runtime.jsxs)("div", {
822
+ className: Panel_module_css_default.injectHistoryHead,
823
+ children: [
824
+ "⟳",
825
+ entry.turn,
826
+ " · ",
827
+ new Date(entry.at).toLocaleTimeString(),
828
+ " · ",
829
+ entry.templates.join(", ")
830
+ ]
831
+ }), (0, react_jsx_runtime.jsx)("div", {
832
+ className: Panel_module_css_default.injectHistoryContent,
833
+ children: entry.content
834
+ })]
835
+ }, `${entry.turn}-${entry.at}`))
836
+ ]
581
837
  }),
582
838
  (0, react_jsx_runtime.jsx)("div", {
583
839
  className: Panel_module_css_default.searchBar,
@@ -648,7 +904,7 @@ window.__ModuleLoader__.load({
648
904
  onClick: () => {
649
905
  setShowCatForm((v) => !v);
650
906
  },
651
- children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconPlusOutline16, { size: 10 })
907
+ children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconPlusOutlineRegular, { size: 10 })
652
908
  })
653
909
  ]
654
910
  }),
@@ -664,6 +920,16 @@ window.__ModuleLoader__.load({
664
920
  (0, react_jsx_runtime.jsxs)("div", {
665
921
  className: Panel_module_css_default.body,
666
922
  children: [
923
+ rowError !== null && (0, react_jsx_runtime.jsxs)("div", {
924
+ className: Panel_module_css_default.error,
925
+ role: "alert",
926
+ "data-prompt-row-error": true,
927
+ children: [
928
+ t("panel.error"),
929
+ " · ",
930
+ rowError
931
+ ]
932
+ }),
667
933
  tabRows.length === 0 && !showAdd && !showCatForm && (0, react_jsx_runtime.jsx)("div", {
668
934
  className: Panel_module_css_default.empty,
669
935
  children: needle !== "" ? t("panel.noMatch") : t("panel.empty")
@@ -681,13 +947,16 @@ window.__ModuleLoader__.load({
681
947
  t,
682
948
  allowScope: true,
683
949
  submitLabel: t("panel.addSave"),
684
- onSubmit: async (name, content, scope, category) => {
950
+ onSubmit: async (name, content, scope, category, injectEnabled, injectEvery, mode) => {
685
951
  return (await create({
686
952
  name,
687
953
  content,
688
954
  scope,
689
955
  session_id: scope === "session" ? sessionId : null,
690
- category
956
+ category,
957
+ inject_enabled: injectEnabled,
958
+ inject_every: injectEvery,
959
+ mode
691
960
  })).ok;
692
961
  },
693
962
  onDone: () => {
@@ -700,97 +969,164 @@ window.__ModuleLoader__.load({
700
969
  })
701
970
  ]
702
971
  }),
703
- (0, react_jsx_runtime.jsx)("div", {
972
+ (0, react_jsx_runtime.jsxs)("div", {
704
973
  className: Panel_module_css_default.footer,
705
- children: (0, react_jsx_runtime.jsxs)("button", {
974
+ children: [(0, react_jsx_runtime.jsxs)("span", {
975
+ className: Panel_module_css_default.meta,
976
+ children: [(0, react_jsx_runtime.jsxs)("span", {
977
+ "data-plugin-version": true,
978
+ children: ["v", PLUGIN_VERSION]
979
+ }), (0, react_jsx_runtime.jsx)("a", {
980
+ className: Panel_module_css_default.githubLink,
981
+ href: GITHUB_REPOSITORY_URL,
982
+ target: "_blank",
983
+ rel: "noopener noreferrer",
984
+ title: t("panel.github"),
985
+ children: "GitHub ↗"
986
+ })]
987
+ }), (0, react_jsx_runtime.jsxs)("button", {
706
988
  type: "button",
707
989
  className: Panel_module_css_default.addBtn,
708
990
  onClick: () => {
709
991
  setShowAdd((v) => !v);
710
992
  },
711
993
  children: [
712
- (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconPlusOutline16, { size: 12 }),
994
+ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconPlusOutlineRegular, { size: 12 }),
713
995
  " ",
714
996
  t("panel.add")
715
997
  ]
716
- })
998
+ })]
717
999
  })
718
1000
  ]
719
1001
  });
720
1002
  }
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
1003
+ //#endregion
1004
+ //#region lib/client/Panel.js
1005
+ /**
1006
+ * Quick prompt panel: the right-anchored floating surface registered into
1007
+ * shell.overlay. The shell owns only placement (drag-by-title, persisted
1008
+ * position) and visibility; the template library itself — search, tabs,
1009
+ * rows, forms, footer — is the shared TemplateLibrary component, also
1010
+ * mounted by the right-sidebar tab. The current session arrives through
1011
+ * the composer entry attachment (targetSession), never the session list.
1012
+ */
1013
+ const PANEL_WIDTH = 320;
1014
+ /**
1015
+ * Clamp a restored panel position into the current viewport so a placement
1016
+ * saved on a wider screen (or a monitor that is no longer attached) can never
1017
+ * render the panel unreachable off-screen. Null passes through untouched.
1018
+ * @param position - the persisted placement, if any.
1019
+ * @returns the clamped placement.
1020
+ */
1021
+ function clampToViewport(position) {
1022
+ if (position === null) return null;
1023
+ const maxX = Math.max(0, window.innerWidth - PANEL_WIDTH);
1024
+ const maxY = Math.max(0, window.innerHeight - 40);
1025
+ return {
1026
+ x: Math.min(Math.max(position.x, 0), maxX),
1027
+ y: Math.min(Math.max(position.y, 0), maxY)
1028
+ };
1029
+ }
1030
+ /**
1031
+ * The prompt-templates floating panel shell.
1032
+ * @param props - runtime kit, injected face members, store handle, and locale.
1033
+ */
1034
+ function PromptPanel(props) {
1035
+ const { useStore, refresh, refreshCategories, createCategory, removeCategory, create, update, remove, makeGlobal, insert, send, interject, injectStatus, injectionHistory, targetSession, targetVersion, subscribeTarget, panelPosition, savePanelPosition, resetPanelPosition, actions, t } = props;
1036
+ const open = useStore((s) => s.open);
1037
+ (0, react.useSyncExternalStore)(subscribeTarget, targetVersion);
1038
+ const sessionId = targetSession() ?? null;
1039
+ const persisted = clampToViewport(panelPosition());
1040
+ const [dragPos, setDragPos] = (0, react.useState)(null);
1041
+ const dragRef = (0, react.useRef)(null);
1042
+ const panelRef = (0, react.useRef)(null);
1043
+ const onHeaderPointerDown = (event) => {
1044
+ if (event.button !== 0) return;
1045
+ if (event.target.closest("button")) return;
1046
+ const panel = panelRef.current;
1047
+ if (panel === null) return;
1048
+ const rect = panel.getBoundingClientRect();
1049
+ dragRef.current = {
1050
+ pointerId: event.pointerId,
1051
+ offX: event.clientX - rect.left,
1052
+ offY: event.clientY - rect.top
1053
+ };
1054
+ if (Reflect.has(event.currentTarget, "setPointerCapture")) event.currentTarget.setPointerCapture(event.pointerId);
1055
+ };
1056
+ const onHeaderPointerMove = (event) => {
1057
+ const drag = dragRef.current;
1058
+ if (drag === null || event.pointerId !== drag.pointerId) return;
1059
+ const width = panelRef.current?.getBoundingClientRect().width ?? PANEL_WIDTH;
1060
+ const maxX = Math.max(0, window.innerWidth - width);
1061
+ const maxY = Math.max(0, window.innerHeight - 40);
1062
+ const x = Math.min(Math.max(event.clientX - drag.offX, 0), maxX);
1063
+ const y = Math.min(Math.max(event.clientY - drag.offY, 0), maxY);
1064
+ setDragPos({
1065
+ x,
1066
+ y
740
1067
  });
741
- setBusy(false);
742
- if (!result.ok) {
743
- setError(t("panel.error"));
744
- return;
745
- }
746
- onDone();
747
1068
  };
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);
1069
+ const onHeaderPointerUp = (event) => {
1070
+ const drag = dragRef.current;
1071
+ if (drag === null || event.pointerId !== drag.pointerId) return;
1072
+ dragRef.current = null;
1073
+ if (Reflect.has(event.currentTarget, "releasePointerCapture")) event.currentTarget.releasePointerCapture(event.pointerId);
1074
+ if (dragPos !== null) savePanelPosition(dragPos);
1075
+ };
1076
+ const onHeaderDoubleClick = () => {
1077
+ setDragPos(null);
1078
+ resetPanelPosition();
1079
+ };
1080
+ if (!open) return null;
1081
+ const placement = dragPos ?? persisted;
1082
+ const placementStyle = placement === null ? void 0 : {
1083
+ left: placement.x,
1084
+ top: placement.y,
1085
+ right: "auto",
1086
+ bottom: "auto",
1087
+ maxHeight: `calc(100vh - ${placement.y}px - 16px)`
1088
+ };
1089
+ const libraryFace = {
1090
+ refresh,
1091
+ refreshCategories,
1092
+ createCategory,
1093
+ removeCategory,
1094
+ create,
1095
+ update,
1096
+ remove,
1097
+ makeGlobal,
1098
+ insert,
1099
+ send,
1100
+ interject,
1101
+ injectStatus,
1102
+ injectionHistory
1103
+ };
1104
+ return (0, react_jsx_runtime.jsx)("div", {
1105
+ className: Panel_module_css_default.panel,
1106
+ "data-prompt-panel": true,
1107
+ ref: panelRef,
1108
+ style: placementStyle,
1109
+ children: (0, react_jsx_runtime.jsx)(TemplateLibrary, {
1110
+ sessionId,
1111
+ face: libraryFace,
1112
+ t,
1113
+ header: {
1114
+ onPointerDown: onHeaderPointerDown,
1115
+ onPointerMove: onHeaderPointerMove,
1116
+ onPointerUp: onHeaderPointerUp,
1117
+ onDoubleClick: onHeaderDoubleClick,
1118
+ hint: t("panel.dragHint")
758
1119
  },
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
- })]
1120
+ headerExtra: (0, react_jsx_runtime.jsx)("button", {
1121
+ type: "button",
1122
+ className: Panel_module_css_default.closeBtn,
1123
+ onClick: () => {
1124
+ actions.close();
1125
+ },
1126
+ "aria-label": t("panel.close"),
1127
+ children: "×"
1128
+ })
1129
+ })
794
1130
  });
795
1131
  }
796
1132
  //#endregion
@@ -812,14 +1148,30 @@ window.__ModuleLoader__.load({
812
1148
  //#endregion
813
1149
  //#region lib/client/PanelButton.js
814
1150
  /**
1151
+ * Composer entry button: toggles the quick prompt panel. Registered into
1152
+ * conversation.input.right (the tool row, before the send button). The
1153
+ * session-scoped inject face carries the toggle verb, which routes through
1154
+ * ctx.promptPanel to the panel's store. The standard kit delivers this
1155
+ * composer's sessionId as a prop; the button attaches the panel to that
1156
+ * session whenever its composer becomes the visible one — on mount, on
1157
+ * session change, and at click — so inserts and sends land in the
1158
+ * conversation the user is looking at, even right after a switch.
1159
+ */
1160
+ /**
815
1161
  * The composer tool-row button.
816
- * @param props - runtime kit (includes the InputZone owner share), the toggle verb, and the locale seat.
1162
+ * @param props - runtime kit (the composer's sessionId), the toggle + attach verbs, and the locale seat.
817
1163
  */
818
- function PanelButton({ toggle, t }) {
1164
+ function PanelButton({ toggle, attachSession, sessionId, t }) {
1165
+ (0, react.useEffect)(() => {
1166
+ if (sessionId !== void 0) attachSession(sessionId);
1167
+ }, [sessionId, attachSession]);
819
1168
  return (0, react_jsx_runtime.jsx)("button", {
820
1169
  type: "button",
821
1170
  className: PanelButton_module_css_default.button,
822
- onClick: toggle,
1171
+ onClick: () => {
1172
+ if (sessionId !== void 0) attachSession(sessionId);
1173
+ toggle();
1174
+ },
823
1175
  "aria-label": t("panel.open"),
824
1176
  "aria-pressed": "false",
825
1177
  title: t("panel.title"),
@@ -830,6 +1182,69 @@ window.__ModuleLoader__.load({
830
1182
  });
831
1183
  }
832
1184
  //#endregion
1185
+ //#region lib/client/PromptTab.js
1186
+ /**
1187
+ * The prompt-templates sidebar tab body.
1188
+ * @param props - runtime kit (carries sessionId), injected face members, locale.
1189
+ */
1190
+ function PromptTab(props) {
1191
+ const { sessionId, refresh, refreshCategories, createCategory, removeCategory, create, update, remove, makeGlobal, insert, send, interject, injectStatus, injectionHistory, t } = props;
1192
+ return (0, react_jsx_runtime.jsx)("div", {
1193
+ className: Panel_module_css_default.tabBody,
1194
+ "data-prompt-tab": true,
1195
+ children: (0, react_jsx_runtime.jsx)(TemplateLibrary, {
1196
+ sessionId,
1197
+ face: {
1198
+ refresh,
1199
+ refreshCategories,
1200
+ createCategory,
1201
+ removeCategory,
1202
+ create,
1203
+ update,
1204
+ remove,
1205
+ makeGlobal,
1206
+ insert,
1207
+ send,
1208
+ interject,
1209
+ injectStatus,
1210
+ injectionHistory
1211
+ },
1212
+ t
1213
+ })
1214
+ });
1215
+ }
1216
+ //#endregion
1217
+ //#region lib/client/tab.js
1218
+ /** The tab kind this plugin owns — the name openTab and the guide dispatch by. */
1219
+ const PROMPT_TEMPLATES_KIND = "promptTemplates";
1220
+ /**
1221
+ * This implementation's identity in the tab system, and the key its body
1222
+ * registers under in the 'sidebar.right.pane.tab' seat (a package name is
1223
+ * the natural value, exactly as the builtin files tab does).
1224
+ */
1225
+ const PROMPT_TEMPLATES_ID = "@nelsonlongxiang/dsh-prompt-templates";
1226
+ /** Guide entry identity within this provider. */
1227
+ const GUIDE_ENTRY_ID = "prompt-templates";
1228
+ /**
1229
+ * The prompt-templates type's registry definition.
1230
+ * @param t - namespace-bound translate, read fresh on every label call
1231
+ * (a language change needs no re-registration).
1232
+ * @returns the definition to register.
1233
+ */
1234
+ function promptTemplatesTabDefinition(t) {
1235
+ return {
1236
+ id: PROMPT_TEMPLATES_ID,
1237
+ kind: PROMPT_TEMPLATES_KIND,
1238
+ title: () => t("tab.title"),
1239
+ guide: [{
1240
+ id: GUIDE_ENTRY_ID,
1241
+ order: 20,
1242
+ title: () => t("tab.guideTitle"),
1243
+ description: () => t("tab.guideDescription")
1244
+ }]
1245
+ };
1246
+ }
1247
+ //#endregion
833
1248
  //#region lib/client/store.js
834
1249
  /**
835
1250
  * Panel store owned by the shell.overlay entry: the open flag plus the
@@ -848,7 +1263,7 @@ window.__ModuleLoader__.load({
848
1263
  * @returns the store handle (spec + type + identity + factory in one).
849
1264
  */
850
1265
  function createPromptPanelStore() {
851
- return (0, _deepseek_ai_dsh_client_runtime_client.defineStore)({
1266
+ return (0, _deepseek_ai_dsh_client_store.defineStore)({
852
1267
  init: () => ({
853
1268
  open: false,
854
1269
  everOpened: false
@@ -875,19 +1290,40 @@ window.__ModuleLoader__.load({
875
1290
  });
876
1291
  }
877
1292
  //#endregion
878
- //#region lib/client/service.js
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;
1293
+ //#region lib/variables.js
1294
+ /** The placeholder namespace: a double-brace name with optional inner spacing. */
1295
+ const PATTERN = /\{\{\s*(date|time|datetime|weekday|session|turn)\s*\}\}/g;
1296
+ const WEEKDAYS = [
1297
+ "星期日",
1298
+ "星期一",
1299
+ "星期二",
1300
+ "星期三",
1301
+ "星期四",
1302
+ "星期五",
1303
+ "星期六"
1304
+ ];
1305
+ function pad(value) {
1306
+ return String(value).padStart(2, "0");
890
1307
  }
1308
+ /** Expand every resolvable placeholder in the content; the rest passes through. */
1309
+ function expandTemplateVariables(content, context) {
1310
+ const now = context.now ?? /* @__PURE__ */ new Date();
1311
+ const date = now.getFullYear() + "-" + pad(now.getMonth() + 1) + "-" + pad(now.getDate());
1312
+ const clock = pad(now.getHours()) + ":" + pad(now.getMinutes());
1313
+ return content.replace(PATTERN, (match, name) => {
1314
+ switch (name) {
1315
+ case "date": return date;
1316
+ case "time": return clock;
1317
+ case "datetime": return date + " " + clock;
1318
+ case "weekday": return WEEKDAYS[now.getDay()] ?? match;
1319
+ case "session": return context.sessionId ?? match;
1320
+ case "turn": return context.turn !== void 0 ? String(context.turn) : match;
1321
+ default: return match;
1322
+ }
1323
+ });
1324
+ }
1325
+ //#endregion
1326
+ //#region lib/client/service.js
891
1327
  /**
892
1328
  * Cross-entry panel face (ctx.promptPanel).
893
1329
  */
@@ -896,6 +1332,11 @@ window.__ModuleLoader__.load({
896
1332
  #sessions;
897
1333
  #conversation;
898
1334
  #pendingAutoOpen = false;
1335
+ /** Session whose composer entry last opened the panel (delivery target). */
1336
+ #targetSession;
1337
+ /** Bumped every time the delivery target changes; drives the open panel's re-render. */
1338
+ #targetVersion = 0;
1339
+ #targetListeners = /* @__PURE__ */ new Set();
899
1340
  /**
900
1341
  * Adopt the shell.overlay entry's bound store actions. Called from that
901
1342
  * registration's inject hook; a re-register overwrites the stale set. A
@@ -923,6 +1364,35 @@ window.__ModuleLoader__.load({
923
1364
  this.#require().toggle();
924
1365
  }
925
1366
  /**
1367
+ * Record the panel's delivery target. Called by the session-scoped
1368
+ * composer entry when its session becomes the visible one (mount or
1369
+ * session change) and again at click time, so the target always follows
1370
+ * the conversation the user is looking at — switching sessions must not
1371
+ * leave the panel pointed at a detached composer whose scope (and
1372
+ * send/insert path) has gone away.
1373
+ */
1374
+ setTargetSession(sessionId) {
1375
+ if (this.#targetSession === sessionId) return;
1376
+ this.#targetSession = sessionId;
1377
+ this.#targetVersion += 1;
1378
+ for (const notify of this.#targetListeners) notify();
1379
+ }
1380
+ /** The session whose composer last opened the panel, if any. */
1381
+ targetSession() {
1382
+ return this.#targetSession;
1383
+ }
1384
+ /** Monotonic change counter of the delivery target (snapshot for useSyncExternalStore). */
1385
+ targetVersion() {
1386
+ return this.#targetVersion;
1387
+ }
1388
+ /** Subscribe to delivery-target changes; returns the unsubscribe function. */
1389
+ subscribeTarget(notify) {
1390
+ this.#targetListeners.add(notify);
1391
+ return () => {
1392
+ this.#targetListeners.delete(notify);
1393
+ };
1394
+ }
1395
+ /**
926
1396
  * Apply the settings-driven default open, at most once per store lifetime
927
1397
  * and never after any user interaction with the panel. Before the entry's
928
1398
  * first render the request parks as pending and attach() replays it.
@@ -937,30 +1407,27 @@ window.__ModuleLoader__.load({
937
1407
  /**
938
1408
  * Insert one template's content into a session's composer draft at the
939
1409
  * 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).
1410
+ * The caret path goes through the input face's provide-channel pair —
1411
+ * capture the caret span with its draft revision, then apply through the
1412
+ * face so the editor lands it as one undoable edit. The pair declines on
1413
+ * a stale revision or a locked admission transaction (submitting /
1414
+ * adjudicating), and older runtimes without the channel simply lack the
1415
+ * member; both fall back to an end-append over the draft snapshot (empty
1416
+ * draft takes the content verbatim, non-empty joins with a newline).
945
1417
  * @param sessionId - target session.
946
1418
  * @param content - template content.
947
1419
  */
948
1420
  insert(sessionId, content) {
949
1421
  const input = this.#inputOf(sessionId);
950
1422
  if (input === void 0) return;
1423
+ const text = expandTemplateVariables(content, { sessionId });
1424
+ const actions = input.actions;
1425
+ if (actions !== void 0) try {
1426
+ const span = actions.captureInsertion();
1427
+ if (span !== void 0 && actions.insertText(text, span)) return;
1428
+ } catch {}
951
1429
  const draft = input.state.getSnapshot().draft;
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);
1430
+ input.setDraft(draft === "" ? text : `${draft}\n${text}`);
964
1431
  }
965
1432
  /**
966
1433
  * Interject one template: steer it into the running agent turn. With
@@ -973,7 +1440,7 @@ window.__ModuleLoader__.load({
973
1440
  interject(sessionId, content) {
974
1441
  const input = this.#inputOf(sessionId);
975
1442
  if (input === void 0) return;
976
- input.setDraft(content);
1443
+ input.setDraft(expandTemplateVariables(content, { sessionId }));
977
1444
  input.submit("steer");
978
1445
  }
979
1446
  /**
@@ -985,7 +1452,7 @@ window.__ModuleLoader__.load({
985
1452
  send(sessionId, content) {
986
1453
  const input = this.#inputOf(sessionId);
987
1454
  if (input === void 0) return;
988
- input.setDraft(content);
1455
+ input.setDraft(expandTemplateVariables(content, { sessionId }));
989
1456
  input.submit();
990
1457
  }
991
1458
  /** Resolve a session's input facade, or undefined when out of reach. */
@@ -1013,7 +1480,13 @@ window.__ModuleLoader__.load({
1013
1480
  "panel.open": "打开提示词面板",
1014
1481
  "panel.close": "关闭提示词面板",
1015
1482
  "panel.empty": "暂无模板",
1016
- "panel.search": "搜索模板…",
1483
+ "panel.search": "搜索全部模板…",
1484
+ "panel.searchCount": "匹配数 / 可搜索总数",
1485
+ "panel.tabCount": "当前分类模板数",
1486
+ "panel.injectedAt": "定时注入至轮次",
1487
+ "panel.historyTitle": "最近定时注入",
1488
+ "panel.historyEmpty": "本次启动后还没有定时注入",
1489
+ "panel.github": "在 GitHub 查看源码",
1017
1490
  "panel.noMatch": "没有匹配的模板",
1018
1491
  "panel.global": "全局模板",
1019
1492
  "panel.session": "会话模板",
@@ -1032,9 +1505,19 @@ window.__ModuleLoader__.load({
1032
1505
  "panel.delete": "删除",
1033
1506
  "panel.edit": "编辑",
1034
1507
  "panel.makeGlobal": "设为全局",
1508
+ "panel.inject": "定时注入",
1509
+ "panel.injectEvery": "注入间隔(轮)",
1510
+ "panel.variablesHint": "支持变量:{{date}} {{time}} {{datetime}} {{weekday}} {{session}} {{turn}}(发送/注入时展开,不可得时保留原文)",
1511
+ "panel.modeLabel": "注入呈现方式",
1512
+ "panel.modeInject": "静默注入",
1513
+ "panel.modeVisible": "对话流可见",
1514
+ "panel.modeHint": "静默:只进模型上下文(对话流不显示,基座设计);可见:以用户消息样式显示在对话流中,带\"⚙️ 定时注入\"标记",
1035
1515
  "panel.error": "操作失败",
1036
1516
  "panel.inserted": "已插入",
1037
- "panel.none": "无"
1517
+ "panel.none": "无",
1518
+ "tab.title": "提示词",
1519
+ "tab.guideTitle": "提示词模板",
1520
+ "tab.guideDescription": "模板库:插入、发送、定时注入"
1038
1521
  };
1039
1522
  /** English dictionary. */
1040
1523
  const en = {
@@ -1044,7 +1527,13 @@ window.__ModuleLoader__.load({
1044
1527
  "panel.open": "Open prompt panel",
1045
1528
  "panel.close": "Close prompt panel",
1046
1529
  "panel.empty": "No templates yet",
1047
- "panel.search": "Search templates…",
1530
+ "panel.search": "Search all templates…",
1531
+ "panel.searchCount": "Matches / total searchable",
1532
+ "panel.tabCount": "Templates in current tab",
1533
+ "panel.injectedAt": "Scheduled injection at turn",
1534
+ "panel.historyTitle": "Recent injections",
1535
+ "panel.historyEmpty": "No scheduled injections since boot",
1536
+ "panel.github": "View source on GitHub",
1048
1537
  "panel.noMatch": "No matching templates",
1049
1538
  "panel.global": "Global templates",
1050
1539
  "panel.session": "Session templates",
@@ -1063,9 +1552,19 @@ window.__ModuleLoader__.load({
1063
1552
  "panel.delete": "Delete",
1064
1553
  "panel.edit": "Edit",
1065
1554
  "panel.makeGlobal": "Make global",
1555
+ "panel.inject": "Auto-inject",
1556
+ "panel.injectEvery": "Every (rounds)",
1557
+ "panel.variablesHint": "Variables: {{date}} {{time}} {{datetime}} {{weekday}} {{session}} {{turn}} (expanded at delivery; unresolved stay literal)",
1558
+ "panel.modeLabel": "Injection delivery",
1559
+ "panel.modeInject": "Silent (model-only)",
1560
+ "panel.modeVisible": "Visible in chat",
1561
+ "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",
1066
1562
  "panel.error": "Operation failed",
1067
1563
  "panel.inserted": "Inserted",
1068
- "panel.none": "None"
1564
+ "panel.none": "None",
1565
+ "tab.title": "Prompts",
1566
+ "tab.guideTitle": "Prompt templates",
1567
+ "tab.guideDescription": "Template library: insert, send, auto-inject"
1069
1568
  };
1070
1569
  //#endregion
1071
1570
  //#region lib/client/index.js
@@ -1076,9 +1575,9 @@ window.__ModuleLoader__.load({
1076
1575
  "slots",
1077
1576
  "sessions",
1078
1577
  "locale",
1079
- "conversation",
1080
- "settingsScope"
1578
+ "conversation"
1081
1579
  ];
1580
+ /** The promptTemplates settings section (registered host-side; optional). */
1082
1581
  /**
1083
1582
  * Client plugin body: the shell.overlay panel owns the store; the controller
1084
1583
  * bridges its actions to the composer entry and performs inserts.
@@ -1095,8 +1594,7 @@ window.__ModuleLoader__.load({
1095
1594
  conversation: ctx.conversation
1096
1595
  });
1097
1596
  ctx.effect(() => ctx.reflect.provide("promptPanel", controller), "ui-prompt-templates: panel service");
1098
- const uiSettings = ctx.settingsScope.bind({ namespace: "prompt-templates" });
1099
- const panelFace = {
1597
+ const verbs = {
1100
1598
  refresh: listTemplates,
1101
1599
  refreshCategories: listCategories,
1102
1600
  createCategory: (request) => {
@@ -1126,42 +1624,37 @@ window.__ModuleLoader__.load({
1126
1624
  interject: (sessionId, content) => {
1127
1625
  controller.interject(sessionId, content);
1128
1626
  },
1129
- panelPosition: () => {
1130
- const snapshot = uiSettings.getSnapshot();
1131
- if (snapshot.status !== "ready") return null;
1132
- const panel = snapshot.value?.panel;
1133
- if (panel === void 0) return null;
1134
- return typeof panel.x === "number" && typeof panel.y === "number" ? panel : null;
1135
- },
1627
+ injectStatus,
1628
+ injectionHistory
1629
+ };
1630
+ let prefsActions;
1631
+ let prefsSnapshot;
1632
+ const panelFace = {
1633
+ ...verbs,
1634
+ targetSession: () => controller.targetSession() ?? null,
1635
+ targetVersion: () => controller.targetVersion(),
1636
+ subscribeTarget: (notify) => controller.subscribeTarget(notify),
1637
+ panelPosition: () => prefsSnapshot?.().panel ?? null,
1136
1638
  savePanelPosition: (position) => {
1137
- uiSettings.set("panel", {
1138
- x: Math.round(position.x),
1139
- y: Math.round(position.y)
1140
- });
1639
+ prefsActions?.setPosition(position.x, position.y);
1141
1640
  },
1142
1641
  resetPanelPosition: () => {
1143
- uiSettings.unset("panel");
1642
+ prefsActions?.resetPosition();
1144
1643
  }
1145
1644
  };
1146
- const applyDefaultOpen = () => {
1147
- const snapshot = uiSettings.getSnapshot();
1148
- if (snapshot.status === "ready" && snapshot.value?.defaultOpen === true) controller.openOnce();
1149
- };
1150
- ctx.effect(() => {
1151
- const unsubscribe = uiSettings.subscribe(applyDefaultOpen);
1152
- return () => {
1153
- unsubscribe();
1154
- };
1155
- }, "ui-prompt-templates: default-open watch");
1156
- applyDefaultOpen();
1157
1645
  ctx.slots.inject("shell.overlay", () => ctx.slots.register({
1158
1646
  name: "shell.overlay",
1159
1647
  id: "prompt-templates",
1160
1648
  order: 10,
1161
1649
  locale: NS,
1162
1650
  store: createPromptPanelStore,
1163
- inject: (actions) => {
1651
+ inject: (actions, store) => {
1164
1652
  controller.attach(actions);
1653
+ if (store !== void 0) {
1654
+ const s = store;
1655
+ prefsActions = s.actions;
1656
+ prefsSnapshot = () => s.getSnapshot();
1657
+ }
1165
1658
  return panelFace;
1166
1659
  }
1167
1660
  }, PromptPanel));
@@ -1170,17 +1663,36 @@ window.__ModuleLoader__.load({
1170
1663
  id: "prompt-templates",
1171
1664
  order: 10,
1172
1665
  locale: NS,
1173
- inject: () => ({ toggle: () => {
1174
- controller.toggle();
1175
- } })
1666
+ inject: () => ({
1667
+ toggle: () => {
1668
+ controller.toggle();
1669
+ },
1670
+ attachSession: (sessionId) => {
1671
+ controller.setTargetSession(sessionId);
1672
+ }
1673
+ })
1176
1674
  }, PanelButton));
1675
+ ctx.inject(["sidebarRightTabs"], (ctx) => {
1676
+ const t = ctx.locale.bind(NS);
1677
+ ctx.effect(() => ctx.sidebarRightTabs.register(promptTemplatesTabDefinition(t)), "ui-prompt-templates: sidebar tab type");
1678
+ ctx.slots.inject("sidebar.right.pane.tab", () => ctx.slots.register({
1679
+ name: "sidebar.right.pane.tab",
1680
+ key: PROMPT_TEMPLATES_ID,
1681
+ locale: NS,
1682
+ inject: () => verbs
1683
+ }, PromptTab));
1684
+ });
1177
1685
  }
1178
1686
  //#endregion
1687
+ exports.PROMPT_TEMPLATES_ID = PROMPT_TEMPLATES_ID;
1688
+ exports.PROMPT_TEMPLATES_KIND = PROMPT_TEMPLATES_KIND;
1179
1689
  exports.PanelButton = PanelButton;
1180
1690
  exports.PromptPanel = PromptPanel;
1181
1691
  exports.PromptPanelController = PromptPanelController;
1692
+ exports.PromptTab = PromptTab;
1182
1693
  exports.apply = apply;
1183
1694
  exports.inject = inject;
1695
+ exports.promptTemplatesTabDefinition = promptTemplatesTabDefinition;
1184
1696
  return module.exports;
1185
1697
  }
1186
1698
  });