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