codexmate 0.0.25 → 0.0.26
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 +416 -413
- package/README.zh.md +349 -346
- package/cli/agents-files.js +224 -224
- package/cli/archive-helpers.js +446 -446
- package/cli/auth-profiles.js +375 -375
- package/cli/builtin-proxy.js +1079 -1079
- package/cli/claude-proxy.js +1022 -1022
- package/cli/config-bootstrap.js +384 -384
- package/cli/config-health.js +338 -338
- package/cli/doctor-core.js +903 -903
- package/cli/import-skills-url.js +356 -356
- package/cli/openai-bridge.js +997 -997
- package/cli/openclaw-config.js +629 -629
- package/cli/session-convert-args.js +65 -0
- package/cli/session-convert-io.js +82 -0
- package/cli/session-convert.js +43 -0
- package/cli/session-usage.concurrent.js +28 -28
- package/cli/session-usage.js +118 -118
- package/cli/session-usage.models.js +176 -176
- package/cli/skills.js +1141 -1141
- package/cli/zip-commands.js +510 -510
- package/cli.js +15218 -14736
- package/lib/automation.js +404 -404
- package/lib/cli-file-utils.js +151 -151
- package/lib/cli-models-utils.js +379 -379
- package/lib/cli-network-utils.js +190 -190
- package/lib/cli-path-utils.js +85 -85
- package/lib/cli-session-utils.js +121 -121
- package/lib/cli-sessions.js +417 -417
- package/lib/cli-utils.js +155 -155
- package/lib/download-artifacts.js +92 -92
- package/lib/mcp-stdio.js +453 -453
- package/lib/task-orchestrator.js +869 -869
- package/lib/text-diff.js +303 -303
- package/lib/workflow-engine.js +340 -340
- package/package.json +74 -74
- package/plugins/README.md +20 -20
- package/plugins/README.zh-CN.md +20 -20
- package/plugins/prompt-templates/comment-polish/index.mjs +25 -25
- package/plugins/prompt-templates/computed.mjs +253 -253
- package/plugins/prompt-templates/index.mjs +8 -8
- package/plugins/prompt-templates/manifest.mjs +15 -15
- package/plugins/prompt-templates/methods.mjs +619 -619
- package/plugins/prompt-templates/overview.mjs +90 -90
- package/plugins/prompt-templates/ownership.mjs +19 -19
- package/plugins/prompt-templates/rule-ack/index.mjs +21 -21
- package/plugins/prompt-templates/storage.mjs +64 -64
- package/plugins/registry.mjs +16 -16
- package/web-ui/app.js +625 -612
- package/web-ui/index.html +35 -35
- package/web-ui/logic.agents-diff.mjs +386 -386
- package/web-ui/logic.claude.mjs +168 -168
- package/web-ui/logic.mjs +5 -5
- package/web-ui/logic.runtime.mjs +128 -128
- package/web-ui/logic.session-convert.mjs +70 -0
- package/web-ui/logic.sessions.mjs +709 -614
- package/web-ui/modules/api.mjs +90 -90
- package/web-ui/modules/app.computed.dashboard.mjs +171 -128
- package/web-ui/modules/app.computed.index.mjs +17 -17
- package/web-ui/modules/app.computed.main-tabs.mjs +205 -205
- package/web-ui/modules/app.computed.session.mjs +946 -670
- package/web-ui/modules/app.constants.mjs +15 -15
- package/web-ui/modules/app.methods.agents.mjs +632 -632
- package/web-ui/modules/app.methods.claude-config.mjs +179 -174
- package/web-ui/modules/app.methods.codex-config.mjs +860 -784
- package/web-ui/modules/app.methods.index.mjs +92 -92
- package/web-ui/modules/app.methods.install.mjs +205 -205
- package/web-ui/modules/app.methods.navigation.mjs +743 -695
- package/web-ui/modules/app.methods.openclaw-core.mjs +814 -814
- package/web-ui/modules/app.methods.openclaw-editing.mjs +372 -372
- package/web-ui/modules/app.methods.openclaw-persist.mjs +369 -369
- package/web-ui/modules/app.methods.providers.mjs +404 -404
- package/web-ui/modules/app.methods.runtime.mjs +345 -345
- package/web-ui/modules/app.methods.session-actions.mjs +596 -544
- package/web-ui/modules/app.methods.session-browser.mjs +985 -722
- package/web-ui/modules/app.methods.session-timeline.mjs +479 -448
- package/web-ui/modules/app.methods.session-trash.mjs +424 -424
- package/web-ui/modules/app.methods.startup-claude.mjs +522 -417
- package/web-ui/modules/app.methods.task-orchestration.mjs +556 -556
- package/web-ui/modules/config-mode.computed.mjs +124 -124
- package/web-ui/modules/config-template-confirm-pref.mjs +33 -33
- package/web-ui/modules/i18n.dict.mjs +2113 -2055
- package/web-ui/modules/i18n.mjs +56 -56
- package/web-ui/modules/plugins.computed.mjs +3 -3
- package/web-ui/modules/plugins.methods.mjs +3 -3
- package/web-ui/modules/plugins.storage.mjs +11 -11
- package/web-ui/modules/sessions-filters-url.mjs +85 -85
- package/web-ui/modules/skills.computed.mjs +107 -107
- package/web-ui/modules/skills.methods.mjs +481 -481
- package/web-ui/partials/index/layout-footer.html +13 -13
- package/web-ui/partials/index/layout-header.html +475 -475
- package/web-ui/partials/index/modal-config-template-agents.html +174 -174
- package/web-ui/partials/index/modal-confirm-toast.html +32 -32
- package/web-ui/partials/index/modal-health-check.html +45 -45
- package/web-ui/partials/index/modal-openclaw-config.html +280 -280
- package/web-ui/partials/index/modal-skills.html +200 -200
- package/web-ui/partials/index/modals-basic.html +165 -165
- package/web-ui/partials/index/panel-config-claude.html +184 -179
- package/web-ui/partials/index/panel-config-codex.html +283 -283
- package/web-ui/partials/index/panel-config-openclaw.html +83 -83
- package/web-ui/partials/index/panel-dashboard.html +186 -186
- package/web-ui/partials/index/panel-docs.html +147 -147
- package/web-ui/partials/index/panel-market.html +177 -177
- package/web-ui/partials/index/panel-orchestration.html +391 -391
- package/web-ui/partials/index/panel-plugins.html +279 -279
- package/web-ui/partials/index/panel-sessions.html +326 -303
- package/web-ui/partials/index/panel-settings.html +258 -258
- package/web-ui/partials/index/panel-usage.html +342 -361
- package/web-ui/res/json5.min.js +1 -1
- package/web-ui/res/vue.global.prod.js +13 -13
- package/web-ui/session-helpers.mjs +576 -573
- package/web-ui/source-bundle.cjs +233 -233
- package/web-ui/styles/base-theme.css +268 -264
- package/web-ui/styles/controls-forms.css +423 -423
- package/web-ui/styles/dashboard.css +274 -274
- package/web-ui/styles/docs-panel.css +247 -247
- package/web-ui/styles/feedback.css +108 -108
- package/web-ui/styles/health-check-dialog.css +144 -144
- package/web-ui/styles/layout-shell.css +603 -603
- package/web-ui/styles/modals-core.css +464 -464
- package/web-ui/styles/navigation-panels.css +390 -390
- package/web-ui/styles/openclaw-structured.css +266 -266
- package/web-ui/styles/plugins-panel.css +523 -523
- package/web-ui/styles/responsive.css +454 -454
- package/web-ui/styles/sessions-list.css +415 -398
- package/web-ui/styles/sessions-preview.css +411 -411
- package/web-ui/styles/sessions-toolbar-trash.css +330 -268
- package/web-ui/styles/sessions-usage.css +945 -912
- package/web-ui/styles/settings-panel.css +166 -166
- package/web-ui/styles/skills-list.css +303 -303
- package/web-ui/styles/skills-market.css +406 -406
- package/web-ui/styles/task-orchestration.css +822 -822
- package/web-ui/styles/titles-cards.css +408 -408
- package/web-ui/styles.css +21 -21
- package/web-ui.html +17 -17
|
@@ -1,619 +1,619 @@
|
|
|
1
|
-
import {
|
|
2
|
-
persistPromptTemplatesToStorage,
|
|
3
|
-
persistPromptTemplateSelectedIdToStorage
|
|
4
|
-
} from './storage.mjs';
|
|
5
|
-
import {
|
|
6
|
-
getFirstPluginId,
|
|
7
|
-
getPluginEntry
|
|
8
|
-
} from '../registry.mjs';
|
|
9
|
-
|
|
10
|
-
const COMPOSER_VALUES_STORAGE_KEY = 'codexmate.plugins.promptTemplates.composerValues.v1';
|
|
11
|
-
|
|
12
|
-
function readComposerValuesFromStorage(storage = localStorage) {
|
|
13
|
-
if (!storage) return {};
|
|
14
|
-
let raw = '';
|
|
15
|
-
try {
|
|
16
|
-
raw = storage.getItem(COMPOSER_VALUES_STORAGE_KEY) || '';
|
|
17
|
-
} catch (_) {
|
|
18
|
-
raw = '';
|
|
19
|
-
}
|
|
20
|
-
if (!raw) return {};
|
|
21
|
-
try {
|
|
22
|
-
const parsed = JSON.parse(raw);
|
|
23
|
-
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return {};
|
|
24
|
-
return parsed;
|
|
25
|
-
} catch (_) {
|
|
26
|
-
return {};
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function persistComposerValuesToStorage(map, storage = localStorage) {
|
|
31
|
-
if (!storage) return false;
|
|
32
|
-
try {
|
|
33
|
-
storage.setItem(COMPOSER_VALUES_STORAGE_KEY, JSON.stringify(map && typeof map === 'object' && !Array.isArray(map) ? map : {}));
|
|
34
|
-
return true;
|
|
35
|
-
} catch (_) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function readComposerValuesForTemplate(templateId) {
|
|
41
|
-
const id = typeof templateId === 'string' ? templateId.trim() : '';
|
|
42
|
-
if (!id) return {};
|
|
43
|
-
const map = readComposerValuesFromStorage(localStorage);
|
|
44
|
-
const values = map && typeof map === 'object' ? map[id] : null;
|
|
45
|
-
return values && typeof values === 'object' && !Array.isArray(values) ? values : {};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function persistComposerValuesForTemplate(templateId, values) {
|
|
49
|
-
const id = typeof templateId === 'string' ? templateId.trim() : '';
|
|
50
|
-
if (!id) return false;
|
|
51
|
-
const map = readComposerValuesFromStorage(localStorage);
|
|
52
|
-
const next = map && typeof map === 'object' && !Array.isArray(map) ? { ...map } : {};
|
|
53
|
-
const payload = values && typeof values === 'object' && !Array.isArray(values) ? values : {};
|
|
54
|
-
next[id] = payload;
|
|
55
|
-
return persistComposerValuesToStorage(next, localStorage);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function createId(prefix = 'tpl') {
|
|
59
|
-
const rand = Math.random().toString(16).slice(2, 10);
|
|
60
|
-
return `${prefix}_${Date.now().toString(16)}_${rand}`;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function nowIso() {
|
|
64
|
-
return new Date().toISOString();
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function normalizePromptTemplateDraft(draft) {
|
|
68
|
-
const safe = draft && typeof draft === 'object' ? draft : {};
|
|
69
|
-
return {
|
|
70
|
-
id: typeof safe.id === 'string' ? safe.id : '',
|
|
71
|
-
name: typeof safe.name === 'string' ? safe.name : '',
|
|
72
|
-
description: typeof safe.description === 'string' ? safe.description : '',
|
|
73
|
-
template: typeof safe.template === 'string' ? safe.template : '',
|
|
74
|
-
createdAt: typeof safe.createdAt === 'string' ? safe.createdAt : '',
|
|
75
|
-
updatedAt: typeof safe.updatedAt === 'string' ? safe.updatedAt : '',
|
|
76
|
-
isBuiltin: safe.isBuiltin === true,
|
|
77
|
-
createdBy: typeof safe.createdBy === 'string' ? safe.createdBy : '',
|
|
78
|
-
maintainers: Array.isArray(safe.maintainers) ? safe.maintainers : []
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function createPluginsMethods() {
|
|
83
|
-
return {
|
|
84
|
-
resetPromptComposerVarValues() {
|
|
85
|
-
this.promptComposerVarValuesRaw = {};
|
|
86
|
-
persistComposerValuesForTemplate(this.promptComposerSelectedTemplateId, {});
|
|
87
|
-
if (typeof this.$nextTick === 'function') {
|
|
88
|
-
this.$nextTick(() => {
|
|
89
|
-
const first = this.$refs && this.$refs.promptComposerFirstField
|
|
90
|
-
? this.$refs.promptComposerFirstField
|
|
91
|
-
: null;
|
|
92
|
-
if (first && typeof first.focus === 'function') first.focus();
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
focusPromptComposerFirstMissingVar() {
|
|
98
|
-
const run = () => {
|
|
99
|
-
const input = document.querySelector('#panel-plugins .prompt-var-input.is-missing');
|
|
100
|
-
if (!input || typeof input.focus !== 'function') return;
|
|
101
|
-
try {
|
|
102
|
-
if (typeof input.scrollIntoView === 'function') {
|
|
103
|
-
input.scrollIntoView({ block: 'center', inline: 'nearest' });
|
|
104
|
-
}
|
|
105
|
-
} catch (_) {}
|
|
106
|
-
input.focus();
|
|
107
|
-
};
|
|
108
|
-
if (typeof this.$nextTick === 'function') {
|
|
109
|
-
this.$nextTick(run);
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
run();
|
|
113
|
-
},
|
|
114
|
-
|
|
115
|
-
selectPromptComposerTemplate(id) {
|
|
116
|
-
const next = typeof id === 'string' ? id.trim() : '';
|
|
117
|
-
if (!next) return;
|
|
118
|
-
if (next === this.promptComposerSelectedTemplateId) return;
|
|
119
|
-
this.promptComposerSelectedTemplateId = next;
|
|
120
|
-
persistPromptTemplateSelectedIdToStorage(next, localStorage);
|
|
121
|
-
this.promptComposerVarValuesRaw = readComposerValuesForTemplate(next);
|
|
122
|
-
if (typeof this.$nextTick === 'function') {
|
|
123
|
-
this.$nextTick(() => {
|
|
124
|
-
const first = this.$refs && this.$refs.promptComposerFirstField
|
|
125
|
-
? this.$refs.promptComposerFirstField
|
|
126
|
-
: null;
|
|
127
|
-
if (first && typeof first.focus === 'function') first.focus();
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
|
|
132
|
-
onPromptComposerInput() {
|
|
133
|
-
const raw = typeof this.promptComposerCommand === 'string' ? this.promptComposerCommand : '';
|
|
134
|
-
const text = raw.trimStart();
|
|
135
|
-
if (!text.startsWith('/')) {
|
|
136
|
-
if (this.promptComposerPickerVisible) {
|
|
137
|
-
this.promptComposerPickerVisible = false;
|
|
138
|
-
}
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const lower = text.toLowerCase();
|
|
143
|
-
const isPluginCommand = lower.startsWith('/pl') || lower.startsWith('/plugin') || lower.startsWith('/plugins');
|
|
144
|
-
if (!isPluginCommand) return;
|
|
145
|
-
|
|
146
|
-
const after = text.replace(/^\/plugins?\b/i, '').trim();
|
|
147
|
-
this.promptComposerPickerKeyword = after;
|
|
148
|
-
if (!this.promptComposerPickerVisible) {
|
|
149
|
-
this.openPromptComposerPicker({ keepKeyword: true });
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
|
-
|
|
153
|
-
onPromptComposerKeydown(event) {
|
|
154
|
-
const e = event || null;
|
|
155
|
-
if (!e || e.key !== 'Enter') return;
|
|
156
|
-
if (e.shiftKey) return;
|
|
157
|
-
e.preventDefault();
|
|
158
|
-
|
|
159
|
-
if (this.promptComposerPickerVisible) {
|
|
160
|
-
const list = Array.isArray(this.promptComposerPickerList) ? this.promptComposerPickerList : [];
|
|
161
|
-
if (list.length) {
|
|
162
|
-
this.usePromptTemplateInComposer(list[0].id);
|
|
163
|
-
}
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const value = typeof this.promptComposerCommand === 'string' ? this.promptComposerCommand.trim() : '';
|
|
168
|
-
const lower = value.toLowerCase();
|
|
169
|
-
if (lower === '/plugin' || lower === '/plugins' || lower === '/pl') {
|
|
170
|
-
this.openPromptComposerPicker();
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
},
|
|
174
|
-
|
|
175
|
-
onPromptComposerPickerKeydown(event) {
|
|
176
|
-
const e = event || null;
|
|
177
|
-
if (!e) return;
|
|
178
|
-
if (e.key === 'Enter' && !e.shiftKey) {
|
|
179
|
-
e.preventDefault();
|
|
180
|
-
const list = Array.isArray(this.promptComposerPickerList) ? this.promptComposerPickerList : [];
|
|
181
|
-
if (list.length) {
|
|
182
|
-
this.usePromptTemplateInComposer(list[0].id);
|
|
183
|
-
}
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
if (e.key === 'Escape') {
|
|
187
|
-
e.preventDefault();
|
|
188
|
-
this.closePromptComposerPicker();
|
|
189
|
-
}
|
|
190
|
-
},
|
|
191
|
-
|
|
192
|
-
openPromptComposerPicker(options = {}) {
|
|
193
|
-
this.promptComposerPickerVisible = true;
|
|
194
|
-
if (!(options && options.keepKeyword)) {
|
|
195
|
-
this.promptComposerPickerKeyword = '';
|
|
196
|
-
}
|
|
197
|
-
if (typeof this.$nextTick === 'function') {
|
|
198
|
-
this.$nextTick(() => {
|
|
199
|
-
const input = this.$refs && this.$refs.promptComposerPickerSearch
|
|
200
|
-
? this.$refs.promptComposerPickerSearch
|
|
201
|
-
: null;
|
|
202
|
-
if (input && typeof input.focus === 'function') input.focus();
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
},
|
|
206
|
-
|
|
207
|
-
closePromptComposerPicker() {
|
|
208
|
-
this.promptComposerPickerVisible = false;
|
|
209
|
-
if (typeof this.$nextTick === 'function') {
|
|
210
|
-
this.$nextTick(() => {
|
|
211
|
-
const input = this.$refs && this.$refs.promptComposerCommandInput
|
|
212
|
-
? this.$refs.promptComposerCommandInput
|
|
213
|
-
: null;
|
|
214
|
-
if (input && typeof input.focus === 'function') input.focus();
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
|
|
219
|
-
usePromptTemplateInComposer(id) {
|
|
220
|
-
const next = typeof id === 'string' ? id.trim() : '';
|
|
221
|
-
if (!next) return;
|
|
222
|
-
this.promptComposerSelectedTemplateId = next;
|
|
223
|
-
persistPromptTemplateSelectedIdToStorage(next, localStorage);
|
|
224
|
-
this.promptComposerVarValuesRaw = readComposerValuesForTemplate(next);
|
|
225
|
-
this.promptComposerCommand = '';
|
|
226
|
-
this.promptComposerPickerVisible = false;
|
|
227
|
-
this.promptTemplatesMode = 'compose';
|
|
228
|
-
if (typeof this.$nextTick === 'function') {
|
|
229
|
-
this.$nextTick(() => {
|
|
230
|
-
const firstVar = this.$refs && this.$refs.promptComposerFirstField
|
|
231
|
-
? this.$refs.promptComposerFirstField
|
|
232
|
-
: null;
|
|
233
|
-
if (firstVar && typeof firstVar.focus === 'function') firstVar.focus();
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
},
|
|
237
|
-
|
|
238
|
-
resetPromptComposer() {
|
|
239
|
-
this.promptComposerCommand = '';
|
|
240
|
-
this.promptComposerSelectedTemplateId = '';
|
|
241
|
-
persistPromptTemplateSelectedIdToStorage('', localStorage);
|
|
242
|
-
this.promptComposerVarValuesRaw = {};
|
|
243
|
-
this.promptComposerPickerVisible = false;
|
|
244
|
-
this.promptComposerPickerKeyword = '';
|
|
245
|
-
},
|
|
246
|
-
|
|
247
|
-
setPromptComposerVarValue(name, value) {
|
|
248
|
-
const key = typeof name === 'string' ? name.trim() : '';
|
|
249
|
-
if (!key) return;
|
|
250
|
-
const current = this.promptComposerVarValuesRaw && typeof this.promptComposerVarValuesRaw === 'object'
|
|
251
|
-
? this.promptComposerVarValuesRaw
|
|
252
|
-
: {};
|
|
253
|
-
const next = { ...current };
|
|
254
|
-
next[key] = value == null ? '' : String(value);
|
|
255
|
-
this.promptComposerVarValuesRaw = next;
|
|
256
|
-
persistComposerValuesForTemplate(this.promptComposerSelectedTemplateId, next);
|
|
257
|
-
},
|
|
258
|
-
|
|
259
|
-
async copyPromptComposerRendered() {
|
|
260
|
-
const text = typeof this.promptComposerRendered === 'string' ? this.promptComposerRendered.trim() : '';
|
|
261
|
-
if (!text) {
|
|
262
|
-
this.showMessage(typeof this.t === 'function' ? this.t('toast.copy.empty') : 'Nothing to copy', 'info');
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
265
|
-
try {
|
|
266
|
-
if (navigator.clipboard && window.isSecureContext) {
|
|
267
|
-
await navigator.clipboard.writeText(text);
|
|
268
|
-
this.showMessage(typeof this.t === 'function' ? this.t('toast.copy.ok') : 'Copied', 'success');
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
} catch (_) {}
|
|
272
|
-
const ok = typeof this.fallbackCopyText === 'function' ? this.fallbackCopyText(text) : false;
|
|
273
|
-
if (ok) {
|
|
274
|
-
this.showMessage(typeof this.t === 'function' ? this.t('toast.copy.ok') : 'Copied', 'success');
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
this.showMessage(typeof this.t === 'function' ? this.t('toast.copy.fail') : 'Copy failed', 'error');
|
|
278
|
-
},
|
|
279
|
-
|
|
280
|
-
selectPlugin(pluginId) {
|
|
281
|
-
const id = typeof pluginId === 'string' ? pluginId.trim() : '';
|
|
282
|
-
if (!id) return;
|
|
283
|
-
if (!getPluginEntry(id)) return;
|
|
284
|
-
this.pluginsActiveId = id;
|
|
285
|
-
},
|
|
286
|
-
|
|
287
|
-
async loadPluginsOverview(options = {}) {
|
|
288
|
-
const silent = !!(options && options.silent);
|
|
289
|
-
const forceRefresh = !!(options && options.forceRefresh);
|
|
290
|
-
if (this.pluginsLoading) return false;
|
|
291
|
-
|
|
292
|
-
this.pluginsLoading = true;
|
|
293
|
-
this.pluginsError = '';
|
|
294
|
-
try {
|
|
295
|
-
const fallbackId = getFirstPluginId();
|
|
296
|
-
const currentId = typeof this.pluginsActiveId === 'string' ? this.pluginsActiveId.trim() : '';
|
|
297
|
-
const resolved = getPluginEntry(currentId) ? currentId : fallbackId;
|
|
298
|
-
if (resolved && resolved !== currentId) {
|
|
299
|
-
this.pluginsActiveId = resolved;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
const entry = getPluginEntry(resolved);
|
|
303
|
-
if (!entry || typeof entry.loadOverview !== 'function') return true;
|
|
304
|
-
return await entry.loadOverview(this, { silent, forceRefresh });
|
|
305
|
-
} catch (e) {
|
|
306
|
-
this.pluginsError = e && e.message ? String(e.message) : 'Failed to load plugins';
|
|
307
|
-
if (!silent) {
|
|
308
|
-
this.showMessage(typeof this.t === 'function' ? this.t('toast.plugins.loadFail') : 'Failed to load plugins', 'error');
|
|
309
|
-
}
|
|
310
|
-
return false;
|
|
311
|
-
} finally {
|
|
312
|
-
this.pluginsLoading = false;
|
|
313
|
-
}
|
|
314
|
-
},
|
|
315
|
-
|
|
316
|
-
selectPromptTemplate(id) {
|
|
317
|
-
const next = typeof id === 'string' ? id.trim() : '';
|
|
318
|
-
if (!next) return;
|
|
319
|
-
const list = this.promptTemplatesList;
|
|
320
|
-
const entry = list.find((item) => item.id === next);
|
|
321
|
-
if (!entry) return;
|
|
322
|
-
this.promptTemplateSelectedId = next;
|
|
323
|
-
this.promptTemplatesMode = 'manage';
|
|
324
|
-
this.promptTemplateDraftRaw = {
|
|
325
|
-
id: entry.id,
|
|
326
|
-
name: entry.name,
|
|
327
|
-
description: entry.description,
|
|
328
|
-
template: entry.template,
|
|
329
|
-
createdAt: entry.createdAt,
|
|
330
|
-
updatedAt: entry.updatedAt,
|
|
331
|
-
isBuiltin: entry.isBuiltin === true,
|
|
332
|
-
createdBy: entry.createdBy || '',
|
|
333
|
-
maintainers: Array.isArray(entry.maintainers) ? entry.maintainers : []
|
|
334
|
-
};
|
|
335
|
-
this.promptTemplateVarValuesRaw = {};
|
|
336
|
-
},
|
|
337
|
-
|
|
338
|
-
createPromptTemplate() {
|
|
339
|
-
const id = createId('prompt');
|
|
340
|
-
const name = typeof this.t === 'function'
|
|
341
|
-
? this.t('plugins.promptTemplates.manage.newTemplateName')
|
|
342
|
-
: 'New template';
|
|
343
|
-
const draft = {
|
|
344
|
-
id,
|
|
345
|
-
name,
|
|
346
|
-
description: '',
|
|
347
|
-
template: '',
|
|
348
|
-
createdAt: nowIso(),
|
|
349
|
-
updatedAt: nowIso(),
|
|
350
|
-
isBuiltin: false
|
|
351
|
-
};
|
|
352
|
-
this.promptTemplateDraftRaw = draft;
|
|
353
|
-
this.promptTemplateSelectedId = id;
|
|
354
|
-
this.promptTemplateVarValuesRaw = {};
|
|
355
|
-
},
|
|
356
|
-
|
|
357
|
-
resetPromptVariableValues() {
|
|
358
|
-
this.promptTemplateVarValuesRaw = {};
|
|
359
|
-
},
|
|
360
|
-
|
|
361
|
-
addPromptTemplateVariable() {
|
|
362
|
-
const draft = normalizePromptTemplateDraft(this.promptTemplateDraftRaw);
|
|
363
|
-
if (!draft || !draft.id) return;
|
|
364
|
-
if (draft.isBuiltin) {
|
|
365
|
-
this.showMessage(typeof this.t === 'function' ? this.t('toast.templates.builtinNotEditable') : 'Built-in templates are not editable', 'error');
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
this.promptTemplateVarDraftName = 'var';
|
|
369
|
-
this.promptTemplateVarDraftError = '';
|
|
370
|
-
this.showPromptTemplateVarModal = true;
|
|
371
|
-
if (typeof this.$nextTick === 'function') {
|
|
372
|
-
this.$nextTick(() => {
|
|
373
|
-
const input = this.$refs && this.$refs.promptTemplateVarNameInput
|
|
374
|
-
? this.$refs.promptTemplateVarNameInput
|
|
375
|
-
: null;
|
|
376
|
-
if (input && typeof input.focus === 'function') input.focus();
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
},
|
|
380
|
-
|
|
381
|
-
closePromptTemplateVarModal() {
|
|
382
|
-
this.showPromptTemplateVarModal = false;
|
|
383
|
-
this.promptTemplateVarDraftError = '';
|
|
384
|
-
},
|
|
385
|
-
|
|
386
|
-
confirmAddPromptTemplateVariable() {
|
|
387
|
-
const draft = normalizePromptTemplateDraft(this.promptTemplateDraftRaw);
|
|
388
|
-
if (!draft || !draft.id) return;
|
|
389
|
-
if (draft.isBuiltin) {
|
|
390
|
-
this.promptTemplateVarDraftError = typeof this.t === 'function'
|
|
391
|
-
? this.t('toast.templates.builtinNotEditable')
|
|
392
|
-
: 'Built-in templates are not editable';
|
|
393
|
-
return;
|
|
394
|
-
}
|
|
395
|
-
const key = typeof this.promptTemplateVarDraftName === 'string'
|
|
396
|
-
? this.promptTemplateVarDraftName.trim()
|
|
397
|
-
: '';
|
|
398
|
-
if (!key) {
|
|
399
|
-
this.promptTemplateVarDraftError = typeof this.t === 'function'
|
|
400
|
-
? this.t('toast.templates.varNameRequired')
|
|
401
|
-
: 'Variable name is required';
|
|
402
|
-
return;
|
|
403
|
-
}
|
|
404
|
-
if (!/^[a-zA-Z0-9_.-]+$/.test(key)) {
|
|
405
|
-
this.promptTemplateVarDraftError = typeof this.t === 'function'
|
|
406
|
-
? this.t('toast.templates.varNameInvalid')
|
|
407
|
-
: 'Variable name may only contain letters, numbers, underscore, dash, dot';
|
|
408
|
-
return;
|
|
409
|
-
}
|
|
410
|
-
const placeholder = `{{${key}}}`;
|
|
411
|
-
const current = typeof draft.template === 'string' ? draft.template : '';
|
|
412
|
-
if (current.includes(placeholder)) {
|
|
413
|
-
this.promptTemplateVarDraftError = typeof this.t === 'function'
|
|
414
|
-
? this.t('toast.templates.varExists')
|
|
415
|
-
: 'Variable already exists';
|
|
416
|
-
return;
|
|
417
|
-
}
|
|
418
|
-
const nextText = current && !current.endsWith('\n')
|
|
419
|
-
? `${current}\n${placeholder}\n`
|
|
420
|
-
: `${current}${placeholder}\n`;
|
|
421
|
-
this.promptTemplateDraftRaw = { ...draft, template: nextText };
|
|
422
|
-
this.showPromptTemplateVarModal = false;
|
|
423
|
-
this.promptTemplateVarDraftError = '';
|
|
424
|
-
this.showMessage(typeof this.t === 'function' ? this.t('toast.templates.varAdded') : 'Variable added', 'success');
|
|
425
|
-
},
|
|
426
|
-
|
|
427
|
-
setPromptVariableValue(name, value) {
|
|
428
|
-
const key = typeof name === 'string' ? name.trim() : '';
|
|
429
|
-
if (!key) return;
|
|
430
|
-
const next = { ...(this.promptTemplateVarValuesRaw && typeof this.promptTemplateVarValuesRaw === 'object' ? this.promptTemplateVarValuesRaw : {}) };
|
|
431
|
-
next[key] = value == null ? '' : String(value);
|
|
432
|
-
this.promptTemplateVarValuesRaw = next;
|
|
433
|
-
},
|
|
434
|
-
|
|
435
|
-
async copyRenderedPrompt() {
|
|
436
|
-
const text = typeof this.renderedPrompt === 'string' ? this.renderedPrompt.trim() : '';
|
|
437
|
-
if (!text) {
|
|
438
|
-
this.showMessage(typeof this.t === 'function' ? this.t('toast.copy.empty') : 'Nothing to copy', 'info');
|
|
439
|
-
return;
|
|
440
|
-
}
|
|
441
|
-
try {
|
|
442
|
-
if (navigator.clipboard && window.isSecureContext) {
|
|
443
|
-
await navigator.clipboard.writeText(text);
|
|
444
|
-
this.showMessage(typeof this.t === 'function' ? this.t('toast.copy.ok') : 'Copied', 'success');
|
|
445
|
-
return;
|
|
446
|
-
}
|
|
447
|
-
} catch (_) {}
|
|
448
|
-
const ok = typeof this.fallbackCopyText === 'function' ? this.fallbackCopyText(text) : false;
|
|
449
|
-
if (ok) {
|
|
450
|
-
this.showMessage(typeof this.t === 'function' ? this.t('toast.copy.ok') : 'Copied', 'success');
|
|
451
|
-
return;
|
|
452
|
-
}
|
|
453
|
-
this.showMessage(typeof this.t === 'function' ? this.t('toast.copy.fail') : 'Copy failed', 'error');
|
|
454
|
-
},
|
|
455
|
-
|
|
456
|
-
async savePromptTemplate() {
|
|
457
|
-
const draft = normalizePromptTemplateDraft(this.promptTemplateDraftRaw);
|
|
458
|
-
if (draft.isBuiltin) {
|
|
459
|
-
this.showMessage(typeof this.t === 'function' ? this.t('toast.templates.builtinNotModifiable') : 'Built-in templates are read-only. Duplicate first.', 'error');
|
|
460
|
-
return false;
|
|
461
|
-
}
|
|
462
|
-
const name = draft.name.trim();
|
|
463
|
-
if (!name) {
|
|
464
|
-
this.showMessage(typeof this.t === 'function' ? this.t('toast.templates.nameRequired') : 'Template name is required', 'error');
|
|
465
|
-
return false;
|
|
466
|
-
}
|
|
467
|
-
const nextId = draft.id ? draft.id : createId('prompt');
|
|
468
|
-
const list = Array.isArray(this.promptTemplatesListRaw) ? [...this.promptTemplatesListRaw] : [];
|
|
469
|
-
const now = nowIso();
|
|
470
|
-
const entry = {
|
|
471
|
-
...draft,
|
|
472
|
-
id: nextId,
|
|
473
|
-
name,
|
|
474
|
-
updatedAt: now,
|
|
475
|
-
createdAt: draft.createdAt || now,
|
|
476
|
-
isBuiltin: draft.isBuiltin === true
|
|
477
|
-
};
|
|
478
|
-
const index = list.findIndex((item) => item && item.id === nextId);
|
|
479
|
-
if (index >= 0) {
|
|
480
|
-
list[index] = entry;
|
|
481
|
-
} else {
|
|
482
|
-
list.unshift(entry);
|
|
483
|
-
}
|
|
484
|
-
this.promptTemplatesListRaw = list;
|
|
485
|
-
persistPromptTemplatesToStorage(list, localStorage);
|
|
486
|
-
this.promptTemplateDraftRaw = entry;
|
|
487
|
-
this.promptTemplateSelectedId = nextId;
|
|
488
|
-
this.showMessage(typeof this.t === 'function' ? this.t('toast.save.ok') : 'Saved', 'success');
|
|
489
|
-
return true;
|
|
490
|
-
},
|
|
491
|
-
|
|
492
|
-
duplicatePromptTemplate() {
|
|
493
|
-
const draft = normalizePromptTemplateDraft(this.promptTemplateDraftRaw);
|
|
494
|
-
if (!draft.id) return;
|
|
495
|
-
if (draft.isBuiltin) {
|
|
496
|
-
this.showMessage(typeof this.t === 'function' ? this.t('toast.templates.builtinNotDuplicable') : 'Built-in templates cannot be duplicated', 'error');
|
|
497
|
-
return;
|
|
498
|
-
}
|
|
499
|
-
const nextId = createId('prompt');
|
|
500
|
-
this.promptTemplateDraftRaw = {
|
|
501
|
-
...draft,
|
|
502
|
-
id: nextId,
|
|
503
|
-
name: `${draft.name || 'Template'} (copy)`,
|
|
504
|
-
createdAt: nowIso(),
|
|
505
|
-
updatedAt: nowIso(),
|
|
506
|
-
isBuiltin: false
|
|
507
|
-
};
|
|
508
|
-
this.promptTemplateSelectedId = nextId;
|
|
509
|
-
this.promptTemplateVarValuesRaw = {};
|
|
510
|
-
},
|
|
511
|
-
|
|
512
|
-
async deletePromptTemplate() {
|
|
513
|
-
const draft = normalizePromptTemplateDraft(this.promptTemplateDraftRaw);
|
|
514
|
-
if (!draft.id) return;
|
|
515
|
-
if (draft.isBuiltin) {
|
|
516
|
-
this.showMessage(typeof this.t === 'function' ? this.t('toast.templates.builtinNotDeletable') : 'Built-in templates cannot be deleted', 'error');
|
|
517
|
-
return;
|
|
518
|
-
}
|
|
519
|
-
const t = typeof this.t === 'function' ? this.t : null;
|
|
520
|
-
const confirmed = await this.requestConfirmDialog({
|
|
521
|
-
title: t ? t('toast.templates.deleteTitle') : 'Delete template',
|
|
522
|
-
message: t ? t('toast.templates.deleteMessage', { name: draft.name || draft.id }) : `Delete “${draft.name || draft.id}”? This action cannot be undone.`,
|
|
523
|
-
confirmText: t ? t('toast.templates.deleteConfirm') : 'Delete',
|
|
524
|
-
cancelText: t ? t('toast.templates.deleteCancel') : 'Cancel',
|
|
525
|
-
danger: true
|
|
526
|
-
});
|
|
527
|
-
if (!confirmed) return;
|
|
528
|
-
|
|
529
|
-
const list = Array.isArray(this.promptTemplatesListRaw) ? this.promptTemplatesListRaw : [];
|
|
530
|
-
const next = list.filter((item) => !(item && item.id === draft.id));
|
|
531
|
-
this.promptTemplatesListRaw = next;
|
|
532
|
-
persistPromptTemplatesToStorage(next, localStorage);
|
|
533
|
-
this.promptTemplateDraftRaw = null;
|
|
534
|
-
this.promptTemplateSelectedId = '';
|
|
535
|
-
const first = this.promptTemplatesList && this.promptTemplatesList.length ? this.promptTemplatesList[0] : null;
|
|
536
|
-
if (first) this.selectPromptTemplate(first.id);
|
|
537
|
-
this.showMessage(typeof this.t === 'function' ? this.t('toast.delete.ok') : 'Deleted', 'success');
|
|
538
|
-
},
|
|
539
|
-
|
|
540
|
-
exportPromptTemplates() {
|
|
541
|
-
const list = this.promptTemplatesList;
|
|
542
|
-
if (!Array.isArray(list) || !list.length) {
|
|
543
|
-
this.showMessage(typeof this.t === 'function' ? this.t('toast.export.empty') : 'Nothing to export', 'info');
|
|
544
|
-
return;
|
|
545
|
-
}
|
|
546
|
-
const payload = JSON.stringify(list.map((item) => ({
|
|
547
|
-
id: item.id,
|
|
548
|
-
name: item.name,
|
|
549
|
-
description: item.description,
|
|
550
|
-
template: item.template,
|
|
551
|
-
createdAt: item.createdAt,
|
|
552
|
-
updatedAt: item.updatedAt,
|
|
553
|
-
isBuiltin: item.isBuiltin
|
|
554
|
-
})), null, 2);
|
|
555
|
-
if (typeof this.downloadTextFile === 'function') {
|
|
556
|
-
this.downloadTextFile(`prompt-templates-${Date.now()}.json`, payload, 'application/json;charset=utf-8');
|
|
557
|
-
this.showMessage(typeof this.t === 'function' ? this.t('toast.export.ok') : 'Exported', 'success');
|
|
558
|
-
return;
|
|
559
|
-
}
|
|
560
|
-
this.showMessage(typeof this.t === 'function' ? this.t('toast.export.notSupported') : 'Export not supported', 'error');
|
|
561
|
-
},
|
|
562
|
-
|
|
563
|
-
triggerPromptTemplatesImport() {
|
|
564
|
-
const input = this.$refs && this.$refs.promptTemplatesImportInput
|
|
565
|
-
? this.$refs.promptTemplatesImportInput
|
|
566
|
-
: null;
|
|
567
|
-
if (!input) {
|
|
568
|
-
this.showMessage(typeof this.t === 'function' ? this.t('toast.import.notAvailable') : 'Import is not available', 'error');
|
|
569
|
-
return;
|
|
570
|
-
}
|
|
571
|
-
input.value = '';
|
|
572
|
-
input.click();
|
|
573
|
-
},
|
|
574
|
-
|
|
575
|
-
async handlePromptTemplatesImportChange(event) {
|
|
576
|
-
const input = event && event.target ? event.target : null;
|
|
577
|
-
const file = input && input.files && input.files[0] ? input.files[0] : null;
|
|
578
|
-
if (!file) return;
|
|
579
|
-
let text = '';
|
|
580
|
-
try {
|
|
581
|
-
text = await file.text();
|
|
582
|
-
} catch (_) {
|
|
583
|
-
this.showMessage(typeof this.t === 'function' ? this.t('toast.import.readFileFail') : 'Failed to read file', 'error');
|
|
584
|
-
return;
|
|
585
|
-
}
|
|
586
|
-
let parsed;
|
|
587
|
-
try {
|
|
588
|
-
parsed = JSON.parse(text);
|
|
589
|
-
} catch (_) {
|
|
590
|
-
this.showMessage(typeof this.t === 'function' ? this.t('toast.import.invalidJson') : 'Invalid JSON', 'error');
|
|
591
|
-
return;
|
|
592
|
-
}
|
|
593
|
-
if (!Array.isArray(parsed)) {
|
|
594
|
-
this.showMessage(typeof this.t === 'function' ? this.t('toast.import.expectedArray') : 'Expected an array', 'error');
|
|
595
|
-
return;
|
|
596
|
-
}
|
|
597
|
-
const list = Array.isArray(this.promptTemplatesListRaw) ? [...this.promptTemplatesListRaw] : [];
|
|
598
|
-
for (const item of parsed) {
|
|
599
|
-
const draft = normalizePromptTemplateDraft(item);
|
|
600
|
-
if (!draft.name || !draft.template) continue;
|
|
601
|
-
const id = draft.id ? draft.id : createId('prompt');
|
|
602
|
-
const now = nowIso();
|
|
603
|
-
const entry = {
|
|
604
|
-
...draft,
|
|
605
|
-
id,
|
|
606
|
-
createdAt: draft.createdAt || now,
|
|
607
|
-
updatedAt: now,
|
|
608
|
-
isBuiltin: false
|
|
609
|
-
};
|
|
610
|
-
const index = list.findIndex((existing) => existing && existing.id === id);
|
|
611
|
-
if (index >= 0) list[index] = entry;
|
|
612
|
-
else list.unshift(entry);
|
|
613
|
-
}
|
|
614
|
-
this.promptTemplatesListRaw = list;
|
|
615
|
-
persistPromptTemplatesToStorage(list, localStorage);
|
|
616
|
-
this.showMessage(typeof this.t === 'function' ? this.t('toast.import.ok') : 'Imported', 'success');
|
|
617
|
-
}
|
|
618
|
-
};
|
|
619
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
persistPromptTemplatesToStorage,
|
|
3
|
+
persistPromptTemplateSelectedIdToStorage
|
|
4
|
+
} from './storage.mjs';
|
|
5
|
+
import {
|
|
6
|
+
getFirstPluginId,
|
|
7
|
+
getPluginEntry
|
|
8
|
+
} from '../registry.mjs';
|
|
9
|
+
|
|
10
|
+
const COMPOSER_VALUES_STORAGE_KEY = 'codexmate.plugins.promptTemplates.composerValues.v1';
|
|
11
|
+
|
|
12
|
+
function readComposerValuesFromStorage(storage = localStorage) {
|
|
13
|
+
if (!storage) return {};
|
|
14
|
+
let raw = '';
|
|
15
|
+
try {
|
|
16
|
+
raw = storage.getItem(COMPOSER_VALUES_STORAGE_KEY) || '';
|
|
17
|
+
} catch (_) {
|
|
18
|
+
raw = '';
|
|
19
|
+
}
|
|
20
|
+
if (!raw) return {};
|
|
21
|
+
try {
|
|
22
|
+
const parsed = JSON.parse(raw);
|
|
23
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return {};
|
|
24
|
+
return parsed;
|
|
25
|
+
} catch (_) {
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function persistComposerValuesToStorage(map, storage = localStorage) {
|
|
31
|
+
if (!storage) return false;
|
|
32
|
+
try {
|
|
33
|
+
storage.setItem(COMPOSER_VALUES_STORAGE_KEY, JSON.stringify(map && typeof map === 'object' && !Array.isArray(map) ? map : {}));
|
|
34
|
+
return true;
|
|
35
|
+
} catch (_) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function readComposerValuesForTemplate(templateId) {
|
|
41
|
+
const id = typeof templateId === 'string' ? templateId.trim() : '';
|
|
42
|
+
if (!id) return {};
|
|
43
|
+
const map = readComposerValuesFromStorage(localStorage);
|
|
44
|
+
const values = map && typeof map === 'object' ? map[id] : null;
|
|
45
|
+
return values && typeof values === 'object' && !Array.isArray(values) ? values : {};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function persistComposerValuesForTemplate(templateId, values) {
|
|
49
|
+
const id = typeof templateId === 'string' ? templateId.trim() : '';
|
|
50
|
+
if (!id) return false;
|
|
51
|
+
const map = readComposerValuesFromStorage(localStorage);
|
|
52
|
+
const next = map && typeof map === 'object' && !Array.isArray(map) ? { ...map } : {};
|
|
53
|
+
const payload = values && typeof values === 'object' && !Array.isArray(values) ? values : {};
|
|
54
|
+
next[id] = payload;
|
|
55
|
+
return persistComposerValuesToStorage(next, localStorage);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function createId(prefix = 'tpl') {
|
|
59
|
+
const rand = Math.random().toString(16).slice(2, 10);
|
|
60
|
+
return `${prefix}_${Date.now().toString(16)}_${rand}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function nowIso() {
|
|
64
|
+
return new Date().toISOString();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function normalizePromptTemplateDraft(draft) {
|
|
68
|
+
const safe = draft && typeof draft === 'object' ? draft : {};
|
|
69
|
+
return {
|
|
70
|
+
id: typeof safe.id === 'string' ? safe.id : '',
|
|
71
|
+
name: typeof safe.name === 'string' ? safe.name : '',
|
|
72
|
+
description: typeof safe.description === 'string' ? safe.description : '',
|
|
73
|
+
template: typeof safe.template === 'string' ? safe.template : '',
|
|
74
|
+
createdAt: typeof safe.createdAt === 'string' ? safe.createdAt : '',
|
|
75
|
+
updatedAt: typeof safe.updatedAt === 'string' ? safe.updatedAt : '',
|
|
76
|
+
isBuiltin: safe.isBuiltin === true,
|
|
77
|
+
createdBy: typeof safe.createdBy === 'string' ? safe.createdBy : '',
|
|
78
|
+
maintainers: Array.isArray(safe.maintainers) ? safe.maintainers : []
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function createPluginsMethods() {
|
|
83
|
+
return {
|
|
84
|
+
resetPromptComposerVarValues() {
|
|
85
|
+
this.promptComposerVarValuesRaw = {};
|
|
86
|
+
persistComposerValuesForTemplate(this.promptComposerSelectedTemplateId, {});
|
|
87
|
+
if (typeof this.$nextTick === 'function') {
|
|
88
|
+
this.$nextTick(() => {
|
|
89
|
+
const first = this.$refs && this.$refs.promptComposerFirstField
|
|
90
|
+
? this.$refs.promptComposerFirstField
|
|
91
|
+
: null;
|
|
92
|
+
if (first && typeof first.focus === 'function') first.focus();
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
focusPromptComposerFirstMissingVar() {
|
|
98
|
+
const run = () => {
|
|
99
|
+
const input = document.querySelector('#panel-plugins .prompt-var-input.is-missing');
|
|
100
|
+
if (!input || typeof input.focus !== 'function') return;
|
|
101
|
+
try {
|
|
102
|
+
if (typeof input.scrollIntoView === 'function') {
|
|
103
|
+
input.scrollIntoView({ block: 'center', inline: 'nearest' });
|
|
104
|
+
}
|
|
105
|
+
} catch (_) {}
|
|
106
|
+
input.focus();
|
|
107
|
+
};
|
|
108
|
+
if (typeof this.$nextTick === 'function') {
|
|
109
|
+
this.$nextTick(run);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
run();
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
selectPromptComposerTemplate(id) {
|
|
116
|
+
const next = typeof id === 'string' ? id.trim() : '';
|
|
117
|
+
if (!next) return;
|
|
118
|
+
if (next === this.promptComposerSelectedTemplateId) return;
|
|
119
|
+
this.promptComposerSelectedTemplateId = next;
|
|
120
|
+
persistPromptTemplateSelectedIdToStorage(next, localStorage);
|
|
121
|
+
this.promptComposerVarValuesRaw = readComposerValuesForTemplate(next);
|
|
122
|
+
if (typeof this.$nextTick === 'function') {
|
|
123
|
+
this.$nextTick(() => {
|
|
124
|
+
const first = this.$refs && this.$refs.promptComposerFirstField
|
|
125
|
+
? this.$refs.promptComposerFirstField
|
|
126
|
+
: null;
|
|
127
|
+
if (first && typeof first.focus === 'function') first.focus();
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
onPromptComposerInput() {
|
|
133
|
+
const raw = typeof this.promptComposerCommand === 'string' ? this.promptComposerCommand : '';
|
|
134
|
+
const text = raw.trimStart();
|
|
135
|
+
if (!text.startsWith('/')) {
|
|
136
|
+
if (this.promptComposerPickerVisible) {
|
|
137
|
+
this.promptComposerPickerVisible = false;
|
|
138
|
+
}
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const lower = text.toLowerCase();
|
|
143
|
+
const isPluginCommand = lower.startsWith('/pl') || lower.startsWith('/plugin') || lower.startsWith('/plugins');
|
|
144
|
+
if (!isPluginCommand) return;
|
|
145
|
+
|
|
146
|
+
const after = text.replace(/^\/plugins?\b/i, '').trim();
|
|
147
|
+
this.promptComposerPickerKeyword = after;
|
|
148
|
+
if (!this.promptComposerPickerVisible) {
|
|
149
|
+
this.openPromptComposerPicker({ keepKeyword: true });
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
onPromptComposerKeydown(event) {
|
|
154
|
+
const e = event || null;
|
|
155
|
+
if (!e || e.key !== 'Enter') return;
|
|
156
|
+
if (e.shiftKey) return;
|
|
157
|
+
e.preventDefault();
|
|
158
|
+
|
|
159
|
+
if (this.promptComposerPickerVisible) {
|
|
160
|
+
const list = Array.isArray(this.promptComposerPickerList) ? this.promptComposerPickerList : [];
|
|
161
|
+
if (list.length) {
|
|
162
|
+
this.usePromptTemplateInComposer(list[0].id);
|
|
163
|
+
}
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const value = typeof this.promptComposerCommand === 'string' ? this.promptComposerCommand.trim() : '';
|
|
168
|
+
const lower = value.toLowerCase();
|
|
169
|
+
if (lower === '/plugin' || lower === '/plugins' || lower === '/pl') {
|
|
170
|
+
this.openPromptComposerPicker();
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
onPromptComposerPickerKeydown(event) {
|
|
176
|
+
const e = event || null;
|
|
177
|
+
if (!e) return;
|
|
178
|
+
if (e.key === 'Enter' && !e.shiftKey) {
|
|
179
|
+
e.preventDefault();
|
|
180
|
+
const list = Array.isArray(this.promptComposerPickerList) ? this.promptComposerPickerList : [];
|
|
181
|
+
if (list.length) {
|
|
182
|
+
this.usePromptTemplateInComposer(list[0].id);
|
|
183
|
+
}
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (e.key === 'Escape') {
|
|
187
|
+
e.preventDefault();
|
|
188
|
+
this.closePromptComposerPicker();
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
|
|
192
|
+
openPromptComposerPicker(options = {}) {
|
|
193
|
+
this.promptComposerPickerVisible = true;
|
|
194
|
+
if (!(options && options.keepKeyword)) {
|
|
195
|
+
this.promptComposerPickerKeyword = '';
|
|
196
|
+
}
|
|
197
|
+
if (typeof this.$nextTick === 'function') {
|
|
198
|
+
this.$nextTick(() => {
|
|
199
|
+
const input = this.$refs && this.$refs.promptComposerPickerSearch
|
|
200
|
+
? this.$refs.promptComposerPickerSearch
|
|
201
|
+
: null;
|
|
202
|
+
if (input && typeof input.focus === 'function') input.focus();
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
|
|
207
|
+
closePromptComposerPicker() {
|
|
208
|
+
this.promptComposerPickerVisible = false;
|
|
209
|
+
if (typeof this.$nextTick === 'function') {
|
|
210
|
+
this.$nextTick(() => {
|
|
211
|
+
const input = this.$refs && this.$refs.promptComposerCommandInput
|
|
212
|
+
? this.$refs.promptComposerCommandInput
|
|
213
|
+
: null;
|
|
214
|
+
if (input && typeof input.focus === 'function') input.focus();
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
|
|
219
|
+
usePromptTemplateInComposer(id) {
|
|
220
|
+
const next = typeof id === 'string' ? id.trim() : '';
|
|
221
|
+
if (!next) return;
|
|
222
|
+
this.promptComposerSelectedTemplateId = next;
|
|
223
|
+
persistPromptTemplateSelectedIdToStorage(next, localStorage);
|
|
224
|
+
this.promptComposerVarValuesRaw = readComposerValuesForTemplate(next);
|
|
225
|
+
this.promptComposerCommand = '';
|
|
226
|
+
this.promptComposerPickerVisible = false;
|
|
227
|
+
this.promptTemplatesMode = 'compose';
|
|
228
|
+
if (typeof this.$nextTick === 'function') {
|
|
229
|
+
this.$nextTick(() => {
|
|
230
|
+
const firstVar = this.$refs && this.$refs.promptComposerFirstField
|
|
231
|
+
? this.$refs.promptComposerFirstField
|
|
232
|
+
: null;
|
|
233
|
+
if (firstVar && typeof firstVar.focus === 'function') firstVar.focus();
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
|
|
238
|
+
resetPromptComposer() {
|
|
239
|
+
this.promptComposerCommand = '';
|
|
240
|
+
this.promptComposerSelectedTemplateId = '';
|
|
241
|
+
persistPromptTemplateSelectedIdToStorage('', localStorage);
|
|
242
|
+
this.promptComposerVarValuesRaw = {};
|
|
243
|
+
this.promptComposerPickerVisible = false;
|
|
244
|
+
this.promptComposerPickerKeyword = '';
|
|
245
|
+
},
|
|
246
|
+
|
|
247
|
+
setPromptComposerVarValue(name, value) {
|
|
248
|
+
const key = typeof name === 'string' ? name.trim() : '';
|
|
249
|
+
if (!key) return;
|
|
250
|
+
const current = this.promptComposerVarValuesRaw && typeof this.promptComposerVarValuesRaw === 'object'
|
|
251
|
+
? this.promptComposerVarValuesRaw
|
|
252
|
+
: {};
|
|
253
|
+
const next = { ...current };
|
|
254
|
+
next[key] = value == null ? '' : String(value);
|
|
255
|
+
this.promptComposerVarValuesRaw = next;
|
|
256
|
+
persistComposerValuesForTemplate(this.promptComposerSelectedTemplateId, next);
|
|
257
|
+
},
|
|
258
|
+
|
|
259
|
+
async copyPromptComposerRendered() {
|
|
260
|
+
const text = typeof this.promptComposerRendered === 'string' ? this.promptComposerRendered.trim() : '';
|
|
261
|
+
if (!text) {
|
|
262
|
+
this.showMessage(typeof this.t === 'function' ? this.t('toast.copy.empty') : 'Nothing to copy', 'info');
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
try {
|
|
266
|
+
if (navigator.clipboard && window.isSecureContext) {
|
|
267
|
+
await navigator.clipboard.writeText(text);
|
|
268
|
+
this.showMessage(typeof this.t === 'function' ? this.t('toast.copy.ok') : 'Copied', 'success');
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
} catch (_) {}
|
|
272
|
+
const ok = typeof this.fallbackCopyText === 'function' ? this.fallbackCopyText(text) : false;
|
|
273
|
+
if (ok) {
|
|
274
|
+
this.showMessage(typeof this.t === 'function' ? this.t('toast.copy.ok') : 'Copied', 'success');
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
this.showMessage(typeof this.t === 'function' ? this.t('toast.copy.fail') : 'Copy failed', 'error');
|
|
278
|
+
},
|
|
279
|
+
|
|
280
|
+
selectPlugin(pluginId) {
|
|
281
|
+
const id = typeof pluginId === 'string' ? pluginId.trim() : '';
|
|
282
|
+
if (!id) return;
|
|
283
|
+
if (!getPluginEntry(id)) return;
|
|
284
|
+
this.pluginsActiveId = id;
|
|
285
|
+
},
|
|
286
|
+
|
|
287
|
+
async loadPluginsOverview(options = {}) {
|
|
288
|
+
const silent = !!(options && options.silent);
|
|
289
|
+
const forceRefresh = !!(options && options.forceRefresh);
|
|
290
|
+
if (this.pluginsLoading) return false;
|
|
291
|
+
|
|
292
|
+
this.pluginsLoading = true;
|
|
293
|
+
this.pluginsError = '';
|
|
294
|
+
try {
|
|
295
|
+
const fallbackId = getFirstPluginId();
|
|
296
|
+
const currentId = typeof this.pluginsActiveId === 'string' ? this.pluginsActiveId.trim() : '';
|
|
297
|
+
const resolved = getPluginEntry(currentId) ? currentId : fallbackId;
|
|
298
|
+
if (resolved && resolved !== currentId) {
|
|
299
|
+
this.pluginsActiveId = resolved;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const entry = getPluginEntry(resolved);
|
|
303
|
+
if (!entry || typeof entry.loadOverview !== 'function') return true;
|
|
304
|
+
return await entry.loadOverview(this, { silent, forceRefresh });
|
|
305
|
+
} catch (e) {
|
|
306
|
+
this.pluginsError = e && e.message ? String(e.message) : 'Failed to load plugins';
|
|
307
|
+
if (!silent) {
|
|
308
|
+
this.showMessage(typeof this.t === 'function' ? this.t('toast.plugins.loadFail') : 'Failed to load plugins', 'error');
|
|
309
|
+
}
|
|
310
|
+
return false;
|
|
311
|
+
} finally {
|
|
312
|
+
this.pluginsLoading = false;
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
|
|
316
|
+
selectPromptTemplate(id) {
|
|
317
|
+
const next = typeof id === 'string' ? id.trim() : '';
|
|
318
|
+
if (!next) return;
|
|
319
|
+
const list = this.promptTemplatesList;
|
|
320
|
+
const entry = list.find((item) => item.id === next);
|
|
321
|
+
if (!entry) return;
|
|
322
|
+
this.promptTemplateSelectedId = next;
|
|
323
|
+
this.promptTemplatesMode = 'manage';
|
|
324
|
+
this.promptTemplateDraftRaw = {
|
|
325
|
+
id: entry.id,
|
|
326
|
+
name: entry.name,
|
|
327
|
+
description: entry.description,
|
|
328
|
+
template: entry.template,
|
|
329
|
+
createdAt: entry.createdAt,
|
|
330
|
+
updatedAt: entry.updatedAt,
|
|
331
|
+
isBuiltin: entry.isBuiltin === true,
|
|
332
|
+
createdBy: entry.createdBy || '',
|
|
333
|
+
maintainers: Array.isArray(entry.maintainers) ? entry.maintainers : []
|
|
334
|
+
};
|
|
335
|
+
this.promptTemplateVarValuesRaw = {};
|
|
336
|
+
},
|
|
337
|
+
|
|
338
|
+
createPromptTemplate() {
|
|
339
|
+
const id = createId('prompt');
|
|
340
|
+
const name = typeof this.t === 'function'
|
|
341
|
+
? this.t('plugins.promptTemplates.manage.newTemplateName')
|
|
342
|
+
: 'New template';
|
|
343
|
+
const draft = {
|
|
344
|
+
id,
|
|
345
|
+
name,
|
|
346
|
+
description: '',
|
|
347
|
+
template: '',
|
|
348
|
+
createdAt: nowIso(),
|
|
349
|
+
updatedAt: nowIso(),
|
|
350
|
+
isBuiltin: false
|
|
351
|
+
};
|
|
352
|
+
this.promptTemplateDraftRaw = draft;
|
|
353
|
+
this.promptTemplateSelectedId = id;
|
|
354
|
+
this.promptTemplateVarValuesRaw = {};
|
|
355
|
+
},
|
|
356
|
+
|
|
357
|
+
resetPromptVariableValues() {
|
|
358
|
+
this.promptTemplateVarValuesRaw = {};
|
|
359
|
+
},
|
|
360
|
+
|
|
361
|
+
addPromptTemplateVariable() {
|
|
362
|
+
const draft = normalizePromptTemplateDraft(this.promptTemplateDraftRaw);
|
|
363
|
+
if (!draft || !draft.id) return;
|
|
364
|
+
if (draft.isBuiltin) {
|
|
365
|
+
this.showMessage(typeof this.t === 'function' ? this.t('toast.templates.builtinNotEditable') : 'Built-in templates are not editable', 'error');
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
this.promptTemplateVarDraftName = 'var';
|
|
369
|
+
this.promptTemplateVarDraftError = '';
|
|
370
|
+
this.showPromptTemplateVarModal = true;
|
|
371
|
+
if (typeof this.$nextTick === 'function') {
|
|
372
|
+
this.$nextTick(() => {
|
|
373
|
+
const input = this.$refs && this.$refs.promptTemplateVarNameInput
|
|
374
|
+
? this.$refs.promptTemplateVarNameInput
|
|
375
|
+
: null;
|
|
376
|
+
if (input && typeof input.focus === 'function') input.focus();
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
|
|
381
|
+
closePromptTemplateVarModal() {
|
|
382
|
+
this.showPromptTemplateVarModal = false;
|
|
383
|
+
this.promptTemplateVarDraftError = '';
|
|
384
|
+
},
|
|
385
|
+
|
|
386
|
+
confirmAddPromptTemplateVariable() {
|
|
387
|
+
const draft = normalizePromptTemplateDraft(this.promptTemplateDraftRaw);
|
|
388
|
+
if (!draft || !draft.id) return;
|
|
389
|
+
if (draft.isBuiltin) {
|
|
390
|
+
this.promptTemplateVarDraftError = typeof this.t === 'function'
|
|
391
|
+
? this.t('toast.templates.builtinNotEditable')
|
|
392
|
+
: 'Built-in templates are not editable';
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
const key = typeof this.promptTemplateVarDraftName === 'string'
|
|
396
|
+
? this.promptTemplateVarDraftName.trim()
|
|
397
|
+
: '';
|
|
398
|
+
if (!key) {
|
|
399
|
+
this.promptTemplateVarDraftError = typeof this.t === 'function'
|
|
400
|
+
? this.t('toast.templates.varNameRequired')
|
|
401
|
+
: 'Variable name is required';
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
if (!/^[a-zA-Z0-9_.-]+$/.test(key)) {
|
|
405
|
+
this.promptTemplateVarDraftError = typeof this.t === 'function'
|
|
406
|
+
? this.t('toast.templates.varNameInvalid')
|
|
407
|
+
: 'Variable name may only contain letters, numbers, underscore, dash, dot';
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
const placeholder = `{{${key}}}`;
|
|
411
|
+
const current = typeof draft.template === 'string' ? draft.template : '';
|
|
412
|
+
if (current.includes(placeholder)) {
|
|
413
|
+
this.promptTemplateVarDraftError = typeof this.t === 'function'
|
|
414
|
+
? this.t('toast.templates.varExists')
|
|
415
|
+
: 'Variable already exists';
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
const nextText = current && !current.endsWith('\n')
|
|
419
|
+
? `${current}\n${placeholder}\n`
|
|
420
|
+
: `${current}${placeholder}\n`;
|
|
421
|
+
this.promptTemplateDraftRaw = { ...draft, template: nextText };
|
|
422
|
+
this.showPromptTemplateVarModal = false;
|
|
423
|
+
this.promptTemplateVarDraftError = '';
|
|
424
|
+
this.showMessage(typeof this.t === 'function' ? this.t('toast.templates.varAdded') : 'Variable added', 'success');
|
|
425
|
+
},
|
|
426
|
+
|
|
427
|
+
setPromptVariableValue(name, value) {
|
|
428
|
+
const key = typeof name === 'string' ? name.trim() : '';
|
|
429
|
+
if (!key) return;
|
|
430
|
+
const next = { ...(this.promptTemplateVarValuesRaw && typeof this.promptTemplateVarValuesRaw === 'object' ? this.promptTemplateVarValuesRaw : {}) };
|
|
431
|
+
next[key] = value == null ? '' : String(value);
|
|
432
|
+
this.promptTemplateVarValuesRaw = next;
|
|
433
|
+
},
|
|
434
|
+
|
|
435
|
+
async copyRenderedPrompt() {
|
|
436
|
+
const text = typeof this.renderedPrompt === 'string' ? this.renderedPrompt.trim() : '';
|
|
437
|
+
if (!text) {
|
|
438
|
+
this.showMessage(typeof this.t === 'function' ? this.t('toast.copy.empty') : 'Nothing to copy', 'info');
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
try {
|
|
442
|
+
if (navigator.clipboard && window.isSecureContext) {
|
|
443
|
+
await navigator.clipboard.writeText(text);
|
|
444
|
+
this.showMessage(typeof this.t === 'function' ? this.t('toast.copy.ok') : 'Copied', 'success');
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
} catch (_) {}
|
|
448
|
+
const ok = typeof this.fallbackCopyText === 'function' ? this.fallbackCopyText(text) : false;
|
|
449
|
+
if (ok) {
|
|
450
|
+
this.showMessage(typeof this.t === 'function' ? this.t('toast.copy.ok') : 'Copied', 'success');
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
this.showMessage(typeof this.t === 'function' ? this.t('toast.copy.fail') : 'Copy failed', 'error');
|
|
454
|
+
},
|
|
455
|
+
|
|
456
|
+
async savePromptTemplate() {
|
|
457
|
+
const draft = normalizePromptTemplateDraft(this.promptTemplateDraftRaw);
|
|
458
|
+
if (draft.isBuiltin) {
|
|
459
|
+
this.showMessage(typeof this.t === 'function' ? this.t('toast.templates.builtinNotModifiable') : 'Built-in templates are read-only. Duplicate first.', 'error');
|
|
460
|
+
return false;
|
|
461
|
+
}
|
|
462
|
+
const name = draft.name.trim();
|
|
463
|
+
if (!name) {
|
|
464
|
+
this.showMessage(typeof this.t === 'function' ? this.t('toast.templates.nameRequired') : 'Template name is required', 'error');
|
|
465
|
+
return false;
|
|
466
|
+
}
|
|
467
|
+
const nextId = draft.id ? draft.id : createId('prompt');
|
|
468
|
+
const list = Array.isArray(this.promptTemplatesListRaw) ? [...this.promptTemplatesListRaw] : [];
|
|
469
|
+
const now = nowIso();
|
|
470
|
+
const entry = {
|
|
471
|
+
...draft,
|
|
472
|
+
id: nextId,
|
|
473
|
+
name,
|
|
474
|
+
updatedAt: now,
|
|
475
|
+
createdAt: draft.createdAt || now,
|
|
476
|
+
isBuiltin: draft.isBuiltin === true
|
|
477
|
+
};
|
|
478
|
+
const index = list.findIndex((item) => item && item.id === nextId);
|
|
479
|
+
if (index >= 0) {
|
|
480
|
+
list[index] = entry;
|
|
481
|
+
} else {
|
|
482
|
+
list.unshift(entry);
|
|
483
|
+
}
|
|
484
|
+
this.promptTemplatesListRaw = list;
|
|
485
|
+
persistPromptTemplatesToStorage(list, localStorage);
|
|
486
|
+
this.promptTemplateDraftRaw = entry;
|
|
487
|
+
this.promptTemplateSelectedId = nextId;
|
|
488
|
+
this.showMessage(typeof this.t === 'function' ? this.t('toast.save.ok') : 'Saved', 'success');
|
|
489
|
+
return true;
|
|
490
|
+
},
|
|
491
|
+
|
|
492
|
+
duplicatePromptTemplate() {
|
|
493
|
+
const draft = normalizePromptTemplateDraft(this.promptTemplateDraftRaw);
|
|
494
|
+
if (!draft.id) return;
|
|
495
|
+
if (draft.isBuiltin) {
|
|
496
|
+
this.showMessage(typeof this.t === 'function' ? this.t('toast.templates.builtinNotDuplicable') : 'Built-in templates cannot be duplicated', 'error');
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
const nextId = createId('prompt');
|
|
500
|
+
this.promptTemplateDraftRaw = {
|
|
501
|
+
...draft,
|
|
502
|
+
id: nextId,
|
|
503
|
+
name: `${draft.name || 'Template'} (copy)`,
|
|
504
|
+
createdAt: nowIso(),
|
|
505
|
+
updatedAt: nowIso(),
|
|
506
|
+
isBuiltin: false
|
|
507
|
+
};
|
|
508
|
+
this.promptTemplateSelectedId = nextId;
|
|
509
|
+
this.promptTemplateVarValuesRaw = {};
|
|
510
|
+
},
|
|
511
|
+
|
|
512
|
+
async deletePromptTemplate() {
|
|
513
|
+
const draft = normalizePromptTemplateDraft(this.promptTemplateDraftRaw);
|
|
514
|
+
if (!draft.id) return;
|
|
515
|
+
if (draft.isBuiltin) {
|
|
516
|
+
this.showMessage(typeof this.t === 'function' ? this.t('toast.templates.builtinNotDeletable') : 'Built-in templates cannot be deleted', 'error');
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
const t = typeof this.t === 'function' ? this.t : null;
|
|
520
|
+
const confirmed = await this.requestConfirmDialog({
|
|
521
|
+
title: t ? t('toast.templates.deleteTitle') : 'Delete template',
|
|
522
|
+
message: t ? t('toast.templates.deleteMessage', { name: draft.name || draft.id }) : `Delete “${draft.name || draft.id}”? This action cannot be undone.`,
|
|
523
|
+
confirmText: t ? t('toast.templates.deleteConfirm') : 'Delete',
|
|
524
|
+
cancelText: t ? t('toast.templates.deleteCancel') : 'Cancel',
|
|
525
|
+
danger: true
|
|
526
|
+
});
|
|
527
|
+
if (!confirmed) return;
|
|
528
|
+
|
|
529
|
+
const list = Array.isArray(this.promptTemplatesListRaw) ? this.promptTemplatesListRaw : [];
|
|
530
|
+
const next = list.filter((item) => !(item && item.id === draft.id));
|
|
531
|
+
this.promptTemplatesListRaw = next;
|
|
532
|
+
persistPromptTemplatesToStorage(next, localStorage);
|
|
533
|
+
this.promptTemplateDraftRaw = null;
|
|
534
|
+
this.promptTemplateSelectedId = '';
|
|
535
|
+
const first = this.promptTemplatesList && this.promptTemplatesList.length ? this.promptTemplatesList[0] : null;
|
|
536
|
+
if (first) this.selectPromptTemplate(first.id);
|
|
537
|
+
this.showMessage(typeof this.t === 'function' ? this.t('toast.delete.ok') : 'Deleted', 'success');
|
|
538
|
+
},
|
|
539
|
+
|
|
540
|
+
exportPromptTemplates() {
|
|
541
|
+
const list = this.promptTemplatesList;
|
|
542
|
+
if (!Array.isArray(list) || !list.length) {
|
|
543
|
+
this.showMessage(typeof this.t === 'function' ? this.t('toast.export.empty') : 'Nothing to export', 'info');
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
const payload = JSON.stringify(list.map((item) => ({
|
|
547
|
+
id: item.id,
|
|
548
|
+
name: item.name,
|
|
549
|
+
description: item.description,
|
|
550
|
+
template: item.template,
|
|
551
|
+
createdAt: item.createdAt,
|
|
552
|
+
updatedAt: item.updatedAt,
|
|
553
|
+
isBuiltin: item.isBuiltin
|
|
554
|
+
})), null, 2);
|
|
555
|
+
if (typeof this.downloadTextFile === 'function') {
|
|
556
|
+
this.downloadTextFile(`prompt-templates-${Date.now()}.json`, payload, 'application/json;charset=utf-8');
|
|
557
|
+
this.showMessage(typeof this.t === 'function' ? this.t('toast.export.ok') : 'Exported', 'success');
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
this.showMessage(typeof this.t === 'function' ? this.t('toast.export.notSupported') : 'Export not supported', 'error');
|
|
561
|
+
},
|
|
562
|
+
|
|
563
|
+
triggerPromptTemplatesImport() {
|
|
564
|
+
const input = this.$refs && this.$refs.promptTemplatesImportInput
|
|
565
|
+
? this.$refs.promptTemplatesImportInput
|
|
566
|
+
: null;
|
|
567
|
+
if (!input) {
|
|
568
|
+
this.showMessage(typeof this.t === 'function' ? this.t('toast.import.notAvailable') : 'Import is not available', 'error');
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
input.value = '';
|
|
572
|
+
input.click();
|
|
573
|
+
},
|
|
574
|
+
|
|
575
|
+
async handlePromptTemplatesImportChange(event) {
|
|
576
|
+
const input = event && event.target ? event.target : null;
|
|
577
|
+
const file = input && input.files && input.files[0] ? input.files[0] : null;
|
|
578
|
+
if (!file) return;
|
|
579
|
+
let text = '';
|
|
580
|
+
try {
|
|
581
|
+
text = await file.text();
|
|
582
|
+
} catch (_) {
|
|
583
|
+
this.showMessage(typeof this.t === 'function' ? this.t('toast.import.readFileFail') : 'Failed to read file', 'error');
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
let parsed;
|
|
587
|
+
try {
|
|
588
|
+
parsed = JSON.parse(text);
|
|
589
|
+
} catch (_) {
|
|
590
|
+
this.showMessage(typeof this.t === 'function' ? this.t('toast.import.invalidJson') : 'Invalid JSON', 'error');
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
if (!Array.isArray(parsed)) {
|
|
594
|
+
this.showMessage(typeof this.t === 'function' ? this.t('toast.import.expectedArray') : 'Expected an array', 'error');
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
const list = Array.isArray(this.promptTemplatesListRaw) ? [...this.promptTemplatesListRaw] : [];
|
|
598
|
+
for (const item of parsed) {
|
|
599
|
+
const draft = normalizePromptTemplateDraft(item);
|
|
600
|
+
if (!draft.name || !draft.template) continue;
|
|
601
|
+
const id = draft.id ? draft.id : createId('prompt');
|
|
602
|
+
const now = nowIso();
|
|
603
|
+
const entry = {
|
|
604
|
+
...draft,
|
|
605
|
+
id,
|
|
606
|
+
createdAt: draft.createdAt || now,
|
|
607
|
+
updatedAt: now,
|
|
608
|
+
isBuiltin: false
|
|
609
|
+
};
|
|
610
|
+
const index = list.findIndex((existing) => existing && existing.id === id);
|
|
611
|
+
if (index >= 0) list[index] = entry;
|
|
612
|
+
else list.unshift(entry);
|
|
613
|
+
}
|
|
614
|
+
this.promptTemplatesListRaw = list;
|
|
615
|
+
persistPromptTemplatesToStorage(list, localStorage);
|
|
616
|
+
this.showMessage(typeof this.t === 'function' ? this.t('toast.import.ok') : 'Imported', 'success');
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
}
|