codexmate 0.0.40 → 0.0.41
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 +168 -156
- package/README.zh.md +168 -156
- package/cli/agents-files.js +230 -230
- package/cli/analytics-export-args.js +68 -68
- package/cli/archive-helpers.js +453 -453
- package/cli/auth-profiles.js +375 -375
- package/cli/builtin-proxy.js +2144 -2144
- package/cli/claude-proxy.js +1022 -1022
- package/cli/config-bootstrap.js +407 -407
- package/cli/config-health.js +454 -454
- package/cli/doctor-core.js +903 -903
- package/cli/import-skills-url.js +356 -356
- package/cli/local-bridge.js +556 -556
- package/cli/openai-bridge.js +1984 -1984
- package/cli/openclaw-config.js +629 -629
- package/cli/session-convert-args.js +69 -69
- package/cli/session-convert-io.js +82 -82
- package/cli/session-convert.js +150 -150
- package/cli/session-usage.concurrent.js +28 -28
- package/cli/session-usage.js +304 -304
- package/cli/session-usage.models.js +176 -176
- package/cli/skills.js +1141 -1141
- package/cli/update.js +171 -171
- package/cli/zip-commands.js +510 -510
- package/cli.js +16458 -16341
- package/lib/automation.js +404 -404
- package/lib/cli-file-utils.js +151 -151
- package/lib/cli-models-utils.js +440 -440
- 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 +427 -427
- package/lib/cli-utils.js +155 -155
- package/lib/cli-webhook.js +154 -154
- 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/win-tray.js +119 -119
- package/lib/workflow-engine.js +340 -340
- package/package.json +77 -77
- 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 +311 -311
- package/plugins/prompt-templates/index.mjs +8 -8
- package/plugins/prompt-templates/manifest.mjs +18 -18
- package/plugins/prompt-templates/methods.mjs +553 -553
- package/plugins/prompt-templates/overview.mjs +91 -91
- 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 +695 -695
- package/web-ui/index.html +37 -37
- package/web-ui/logic.agents-diff.mjs +386 -386
- package/web-ui/logic.claude.mjs +172 -172
- package/web-ui/logic.codex.mjs +69 -69
- package/web-ui/logic.mjs +5 -5
- package/web-ui/logic.runtime.mjs +128 -128
- package/web-ui/logic.session-convert.mjs +70 -70
- package/web-ui/logic.sessions.mjs +782 -782
- package/web-ui/modules/api.mjs +90 -90
- package/web-ui/modules/app.computed.dashboard.mjs +252 -252
- package/web-ui/modules/app.computed.index.mjs +17 -17
- package/web-ui/modules/app.computed.main-tabs.mjs +214 -214
- package/web-ui/modules/app.computed.session.mjs +876 -876
- package/web-ui/modules/app.constants.mjs +15 -15
- package/web-ui/modules/app.methods.agents.mjs +651 -651
- package/web-ui/modules/app.methods.claude-config.mjs +412 -412
- package/web-ui/modules/app.methods.codex-config.mjs +869 -869
- package/web-ui/modules/app.methods.index.mjs +96 -96
- package/web-ui/modules/app.methods.install.mjs +205 -205
- package/web-ui/modules/app.methods.navigation.mjs +804 -804
- package/web-ui/modules/app.methods.openclaw-core.mjs +814 -814
- package/web-ui/modules/app.methods.openclaw-editing.mjs +420 -420
- package/web-ui/modules/app.methods.openclaw-persist.mjs +375 -375
- package/web-ui/modules/app.methods.providers.mjs +601 -601
- package/web-ui/modules/app.methods.runtime.mjs +420 -420
- package/web-ui/modules/app.methods.session-actions.mjs +591 -591
- package/web-ui/modules/app.methods.session-browser.mjs +1018 -1018
- package/web-ui/modules/app.methods.session-timeline.mjs +479 -479
- package/web-ui/modules/app.methods.session-trash.mjs +468 -468
- package/web-ui/modules/app.methods.startup-claude.mjs +554 -554
- package/web-ui/modules/app.methods.task-orchestration.mjs +556 -556
- package/web-ui/modules/app.methods.tool-config-permissions.mjs +87 -87
- package/web-ui/modules/app.methods.webhook.mjs +87 -87
- 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/locales/en.mjs +1140 -1140
- package/web-ui/modules/i18n/locales/ja.mjs +1130 -1130
- package/web-ui/modules/i18n/locales/vi.mjs +239 -239
- package/web-ui/modules/i18n/locales/zh.mjs +1143 -1143
- package/web-ui/modules/i18n.dict.mjs +14 -14
- package/web-ui/modules/i18n.mjs +111 -111
- 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/provider-url-display.mjs +17 -17
- package/web-ui/modules/sessions-filters-url.mjs +138 -138
- package/web-ui/modules/skills.computed.mjs +107 -107
- package/web-ui/modules/skills.methods.mjs +513 -513
- package/web-ui/partials/index/layout-footer.html +13 -13
- package/web-ui/partials/index/layout-header.html +478 -478
- package/web-ui/partials/index/modal-config-template-agents.html +185 -185
- 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 +344 -344
- package/web-ui/partials/index/modal-skills.html +200 -200
- package/web-ui/partials/index/modal-webhook.html +42 -42
- package/web-ui/partials/index/modals-basic.html +263 -263
- package/web-ui/partials/index/panel-config-claude.html +187 -187
- package/web-ui/partials/index/panel-config-codex.html +205 -205
- package/web-ui/partials/index/panel-config-openclaw.html +89 -89
- package/web-ui/partials/index/panel-dashboard.html +171 -171
- package/web-ui/partials/index/panel-docs.html +114 -114
- package/web-ui/partials/index/panel-market.html +104 -104
- package/web-ui/partials/index/panel-orchestration.html +391 -391
- package/web-ui/partials/index/panel-plugins.html +253 -253
- package/web-ui/partials/index/panel-sessions.html +319 -319
- package/web-ui/partials/index/panel-settings.html +181 -181
- package/web-ui/partials/index/panel-trash.html +82 -82
- package/web-ui/partials/index/panel-usage.html +181 -181
- package/web-ui/res/json5.min.js +1 -1
- package/web-ui/res/vue.global.prod.js +13 -13
- package/web-ui/res/vue.runtime.global.prod.js +7 -7
- package/web-ui/res/web-ui-render.precompiled.js +7666 -7666
- package/web-ui/session-helpers.mjs +602 -602
- package/web-ui/source-bundle.cjs +305 -305
- package/web-ui/styles/base-theme.css +291 -291
- package/web-ui/styles/bridge-pool.css +266 -266
- package/web-ui/styles/controls-forms.css +532 -532
- package/web-ui/styles/dashboard.css +438 -438
- package/web-ui/styles/docs-panel.css +245 -245
- 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 +711 -711
- package/web-ui/styles/modals-core.css +499 -499
- package/web-ui/styles/navigation-panels.css +399 -399
- package/web-ui/styles/openclaw-structured.css +616 -616
- package/web-ui/styles/plugins-panel.css +564 -564
- package/web-ui/styles/responsive.css +501 -501
- package/web-ui/styles/sessions-list.css +683 -683
- package/web-ui/styles/sessions-preview.css +407 -407
- package/web-ui/styles/sessions-toolbar-trash.css +518 -518
- package/web-ui/styles/sessions-usage.css +849 -849
- package/web-ui/styles/settings-panel.css +419 -419
- package/web-ui/styles/skills-list.css +305 -305
- package/web-ui/styles/skills-market.css +723 -723
- package/web-ui/styles/task-orchestration.css +822 -822
- package/web-ui/styles/titles-cards.css +486 -486
- package/web-ui/styles/trash-panel.css +90 -90
- package/web-ui/styles/webhook.css +115 -115
- package/web-ui/styles.css +24 -24
- package/web-ui.html +17 -17
|
@@ -1,420 +1,420 @@
|
|
|
1
|
-
import {
|
|
2
|
-
buildSpeedTestIssue,
|
|
3
|
-
formatLatency
|
|
4
|
-
} from '../logic.mjs';
|
|
5
|
-
|
|
6
|
-
const UI_MESSAGE_KEY_BY_TEXT = Object.freeze({
|
|
7
|
-
'操作成功': 'toast.operationSuccess',
|
|
8
|
-
'操作失败': 'toast.operationFailed',
|
|
9
|
-
'添加失败': 'toast.addFailed',
|
|
10
|
-
'更新失败': 'toast.updateFailed',
|
|
11
|
-
'删除失败': 'toast.deleteFailed',
|
|
12
|
-
'已删除': 'toast.deleted',
|
|
13
|
-
'已复制': 'toast.copied',
|
|
14
|
-
'复制失败': 'toast.copyFailed',
|
|
15
|
-
'剪贴板为空': 'toast.clipboardEmpty',
|
|
16
|
-
'无法读取剪贴板': 'toast.clipboardReadFailed',
|
|
17
|
-
'已粘贴': 'toast.pasted',
|
|
18
|
-
'未检测到改动': 'toast.noChanges',
|
|
19
|
-
'配置已应用': 'toast.configApplied',
|
|
20
|
-
'应用配置失败': 'toast.applyConfigFailed',
|
|
21
|
-
'应用失败': 'toast.applyFailed',
|
|
22
|
-
'配置已加载': 'toast.configLoaded',
|
|
23
|
-
'配置就绪': 'toast.configReady',
|
|
24
|
-
'加载配置失败': 'toast.loadConfigFailed',
|
|
25
|
-
'读取配置失败': 'toast.readConfigFailed',
|
|
26
|
-
'读取配置超时': 'toast.readConfigTimeout',
|
|
27
|
-
'备份失败': 'toast.backupFailed',
|
|
28
|
-
'备份成功,开始下载': 'toast.backupReadyDownload',
|
|
29
|
-
'导入失败': 'toast.importFailed',
|
|
30
|
-
'导入成功': 'toast.importSuccess',
|
|
31
|
-
'导入 skill 失败': 'toast.importSkillFailed',
|
|
32
|
-
'导出失败': 'toast.exportFailed',
|
|
33
|
-
'保存失败': 'toast.saveFailed',
|
|
34
|
-
'加载文件失败': 'toast.loadFileFailed',
|
|
35
|
-
'请填写名称': 'toast.nameRequired',
|
|
36
|
-
'请输入名称': 'toast.nameRequired',
|
|
37
|
-
'名称已存在': 'toast.nameExists',
|
|
38
|
-
'至少保留一项': 'toast.keepOneItem',
|
|
39
|
-
'请输入模型': 'toast.modelRequired',
|
|
40
|
-
'请选择提供商和模型': 'toast.providerModelRequired',
|
|
41
|
-
'请先配置 API Key': 'toast.apiKeyRequired',
|
|
42
|
-
'配置已存在': 'toast.configExists',
|
|
43
|
-
'不支持此操作': 'toast.unsupportedOperation',
|
|
44
|
-
'参数无效': 'toast.invalidParams',
|
|
45
|
-
'不可分享': 'toast.notShareable',
|
|
46
|
-
'已移入回收站': 'toast.movedToTrash',
|
|
47
|
-
'生成命令失败': 'toast.commandGenerationFailed',
|
|
48
|
-
'没有可复制内容': 'toast.nothingToCopy',
|
|
49
|
-
'没有可导出内容': 'toast.nothingToExport',
|
|
50
|
-
'会话已恢复': 'toast.sessionRestored',
|
|
51
|
-
'恢复失败': 'toast.restoreFailed',
|
|
52
|
-
'已彻底删除': 'toast.purged',
|
|
53
|
-
'彻底删除失败': 'toast.purgeFailed',
|
|
54
|
-
'回收站已清空': 'toast.trashCleared',
|
|
55
|
-
'清空回收站失败': 'toast.trashClearFailed',
|
|
56
|
-
'加载回收站失败': 'toast.trashLoadFailed',
|
|
57
|
-
'加载回收站数量失败': 'toast.trashCountLoadFailed',
|
|
58
|
-
'任务计划已更新': 'toast.taskPlanUpdated',
|
|
59
|
-
'任务计划生成失败': 'toast.taskPlanFailed',
|
|
60
|
-
'计划存在问题,请先修复再执行': 'toast.taskPlanHasIssues',
|
|
61
|
-
'已发出取消请求': 'toast.cancelRequested',
|
|
62
|
-
'取消任务失败': 'toast.cancelTaskFailed'
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const UI_MESSAGE_PREFIX_ENTRIES = Object.freeze(
|
|
66
|
-
Object.entries(UI_MESSAGE_KEY_BY_TEXT).sort((a, b) => b[0].length - a[0].length)
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
function translateUiMessage(context, text) {
|
|
70
|
-
if (!context || typeof context.t !== 'function' || typeof text !== 'string') return text;
|
|
71
|
-
const exactKey = UI_MESSAGE_KEY_BY_TEXT[text];
|
|
72
|
-
if (exactKey) return context.t(exactKey);
|
|
73
|
-
const prefixEntry = UI_MESSAGE_PREFIX_ENTRIES.find(([sourceText]) => {
|
|
74
|
-
return text.length > sourceText.length && text.startsWith(sourceText);
|
|
75
|
-
});
|
|
76
|
-
if (!prefixEntry) return text;
|
|
77
|
-
const [sourceText, key] = prefixEntry;
|
|
78
|
-
return `${context.t(key)}${text.slice(sourceText.length)}`;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function clearProgressResetTimer(context, timerKey) {
|
|
82
|
-
if (!context || !timerKey || !context[timerKey]) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
clearTimeout(context[timerKey]);
|
|
86
|
-
context[timerKey] = null;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function scheduleProgressResetTimer(context, timerKey, progressKey, delayMs = 800) {
|
|
90
|
-
if (!context || !timerKey || !progressKey) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
clearProgressResetTimer(context, timerKey);
|
|
94
|
-
context[timerKey] = setTimeout(() => {
|
|
95
|
-
context[progressKey] = 0;
|
|
96
|
-
context[timerKey] = null;
|
|
97
|
-
}, delayMs);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export function createRuntimeMethods(options = {}) {
|
|
101
|
-
const { api } = options;
|
|
102
|
-
|
|
103
|
-
return {
|
|
104
|
-
formatLatency,
|
|
105
|
-
|
|
106
|
-
buildSpeedTestIssue(name, result) {
|
|
107
|
-
return buildSpeedTestIssue(name, result);
|
|
108
|
-
},
|
|
109
|
-
|
|
110
|
-
async runSpeedTest(name, options = {}) {
|
|
111
|
-
if (!name || this.speedLoading[name]) return null;
|
|
112
|
-
const silent = !!options.silent;
|
|
113
|
-
this.speedLoading[name] = true;
|
|
114
|
-
try {
|
|
115
|
-
const timeoutMs = Number.isFinite(options.timeoutMs) ? Math.max(1000, Number(options.timeoutMs)) : 0;
|
|
116
|
-
const payload = { name };
|
|
117
|
-
if (timeoutMs) {
|
|
118
|
-
payload.timeoutMs = timeoutMs;
|
|
119
|
-
}
|
|
120
|
-
const res = await api('speed-test', payload);
|
|
121
|
-
if (res.error) {
|
|
122
|
-
this.speedResults[name] = { ok: false, error: res.error };
|
|
123
|
-
if (!silent) {
|
|
124
|
-
this.showMessage(res.error, 'error');
|
|
125
|
-
}
|
|
126
|
-
return { ok: false, error: res.error };
|
|
127
|
-
}
|
|
128
|
-
this.speedResults[name] = res;
|
|
129
|
-
if (!silent) {
|
|
130
|
-
const status = res.status ? ` (${res.status})` : '';
|
|
131
|
-
this.showMessage(`Speed ${name}: ${this.formatLatency(res)}${status}`, 'success');
|
|
132
|
-
}
|
|
133
|
-
return res;
|
|
134
|
-
} catch (e) {
|
|
135
|
-
const message = e && e.message ? e.message : 'Speed test failed';
|
|
136
|
-
this.speedResults[name] = { ok: false, error: message };
|
|
137
|
-
if (!silent) {
|
|
138
|
-
this.showMessage(message, 'error');
|
|
139
|
-
}
|
|
140
|
-
return { ok: false, error: message };
|
|
141
|
-
} finally {
|
|
142
|
-
this.speedLoading[name] = false;
|
|
143
|
-
}
|
|
144
|
-
},
|
|
145
|
-
|
|
146
|
-
async runClaudeSpeedTest(name, config) {
|
|
147
|
-
if (!name || this.claudeSpeedLoading[name]) return null;
|
|
148
|
-
const baseUrl = config && typeof config.baseUrl === 'string' ? config.baseUrl.trim() : '';
|
|
149
|
-
const apiKey = config && typeof config.apiKey === 'string' ? config.apiKey.trim() : '';
|
|
150
|
-
const model = config && typeof config.model === 'string' ? config.model.trim() : '';
|
|
151
|
-
this.claudeSpeedLoading[name] = true;
|
|
152
|
-
try {
|
|
153
|
-
if (!baseUrl) {
|
|
154
|
-
const res = { ok: false, error: 'Missing base URL' };
|
|
155
|
-
this.claudeSpeedResults[name] = res;
|
|
156
|
-
return res;
|
|
157
|
-
}
|
|
158
|
-
if (!apiKey) {
|
|
159
|
-
const res = { ok: false, error: 'Missing API key' };
|
|
160
|
-
this.claudeSpeedResults[name] = res;
|
|
161
|
-
return res;
|
|
162
|
-
}
|
|
163
|
-
if (!model) {
|
|
164
|
-
const res = { ok: false, error: 'Missing model' };
|
|
165
|
-
this.claudeSpeedResults[name] = res;
|
|
166
|
-
return res;
|
|
167
|
-
}
|
|
168
|
-
const res = await api('speed-test', {
|
|
169
|
-
kind: 'claude',
|
|
170
|
-
url: baseUrl,
|
|
171
|
-
apiKey,
|
|
172
|
-
model
|
|
173
|
-
});
|
|
174
|
-
if (res.error) {
|
|
175
|
-
this.claudeSpeedResults[name] = { ok: false, error: res.error };
|
|
176
|
-
return { ok: false, error: res.error };
|
|
177
|
-
}
|
|
178
|
-
this.claudeSpeedResults[name] = res;
|
|
179
|
-
return res;
|
|
180
|
-
} catch (e) {
|
|
181
|
-
const message = e && e.message ? e.message : 'Speed test failed';
|
|
182
|
-
const res = { ok: false, error: message };
|
|
183
|
-
this.claudeSpeedResults[name] = res;
|
|
184
|
-
return res;
|
|
185
|
-
} finally {
|
|
186
|
-
this.claudeSpeedLoading[name] = false;
|
|
187
|
-
}
|
|
188
|
-
},
|
|
189
|
-
|
|
190
|
-
async downloadClaudeDirectory() {
|
|
191
|
-
if (this.claudeDownloadLoading) return;
|
|
192
|
-
clearProgressResetTimer(this, '__claudeDownloadResetTimer');
|
|
193
|
-
this.claudeDownloadLoading = true;
|
|
194
|
-
this.claudeDownloadProgress = 5;
|
|
195
|
-
this.claudeDownloadTimer = setInterval(() => {
|
|
196
|
-
if (this.claudeDownloadProgress < 90) {
|
|
197
|
-
this.claudeDownloadProgress += 5;
|
|
198
|
-
}
|
|
199
|
-
}, 400);
|
|
200
|
-
try {
|
|
201
|
-
const res = await api('download-claude-dir');
|
|
202
|
-
if (res && res.error) {
|
|
203
|
-
this.showMessage(res.error, 'error');
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
if (!res || res.success !== true || !res.fileName) {
|
|
207
|
-
this.showMessage('备份失败', 'error');
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
this.claudeDownloadProgress = 100;
|
|
211
|
-
const downloadUrl = `/download/${encodeURIComponent(res.fileName)}`;
|
|
212
|
-
const link = document.createElement('a');
|
|
213
|
-
link.href = downloadUrl;
|
|
214
|
-
link.download = res.fileName;
|
|
215
|
-
document.body.appendChild(link);
|
|
216
|
-
link.click();
|
|
217
|
-
document.body.removeChild(link);
|
|
218
|
-
this.showMessage('备份成功,开始下载', 'success');
|
|
219
|
-
} catch (e) {
|
|
220
|
-
this.showMessage('备份失败:' + (e && e.message ? e.message : '未知错误'), 'error');
|
|
221
|
-
} finally {
|
|
222
|
-
if (this.claudeDownloadTimer) {
|
|
223
|
-
clearInterval(this.claudeDownloadTimer);
|
|
224
|
-
this.claudeDownloadTimer = null;
|
|
225
|
-
}
|
|
226
|
-
this.claudeDownloadLoading = false;
|
|
227
|
-
scheduleProgressResetTimer(this, '__claudeDownloadResetTimer', 'claudeDownloadProgress');
|
|
228
|
-
}
|
|
229
|
-
},
|
|
230
|
-
|
|
231
|
-
async downloadCodexDirectory() {
|
|
232
|
-
if (this.codexDownloadLoading) return;
|
|
233
|
-
clearProgressResetTimer(this, '__codexDownloadResetTimer');
|
|
234
|
-
this.codexDownloadLoading = true;
|
|
235
|
-
this.codexDownloadProgress = 5;
|
|
236
|
-
this.codexDownloadTimer = setInterval(() => {
|
|
237
|
-
if (this.codexDownloadProgress < 90) {
|
|
238
|
-
this.codexDownloadProgress += 5;
|
|
239
|
-
}
|
|
240
|
-
}, 400);
|
|
241
|
-
try {
|
|
242
|
-
const res = await api('download-codex-dir');
|
|
243
|
-
if (res && res.error) {
|
|
244
|
-
this.showMessage(res.error, 'error');
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
if (!res || res.success !== true || !res.fileName) {
|
|
248
|
-
this.showMessage('备份失败', 'error');
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
this.codexDownloadProgress = 100;
|
|
252
|
-
const downloadUrl = `/download/${encodeURIComponent(res.fileName)}`;
|
|
253
|
-
const link = document.createElement('a');
|
|
254
|
-
link.href = downloadUrl;
|
|
255
|
-
link.download = res.fileName;
|
|
256
|
-
document.body.appendChild(link);
|
|
257
|
-
link.click();
|
|
258
|
-
document.body.removeChild(link);
|
|
259
|
-
this.showMessage('备份成功,开始下载', 'success');
|
|
260
|
-
} catch (e) {
|
|
261
|
-
this.showMessage('备份失败:' + (e && e.message ? e.message : '未知错误'), 'error');
|
|
262
|
-
} finally {
|
|
263
|
-
if (this.codexDownloadTimer) {
|
|
264
|
-
clearInterval(this.codexDownloadTimer);
|
|
265
|
-
this.codexDownloadTimer = null;
|
|
266
|
-
}
|
|
267
|
-
this.codexDownloadLoading = false;
|
|
268
|
-
scheduleProgressResetTimer(this, '__codexDownloadResetTimer', 'codexDownloadProgress');
|
|
269
|
-
}
|
|
270
|
-
},
|
|
271
|
-
|
|
272
|
-
triggerClaudeImport() {
|
|
273
|
-
const input = this.$refs.claudeImportInput;
|
|
274
|
-
if (input) {
|
|
275
|
-
input.value = '';
|
|
276
|
-
input.click();
|
|
277
|
-
}
|
|
278
|
-
},
|
|
279
|
-
|
|
280
|
-
triggerCodexImport() {
|
|
281
|
-
const input = this.$refs.codexImportInput;
|
|
282
|
-
if (input) {
|
|
283
|
-
input.value = '';
|
|
284
|
-
input.click();
|
|
285
|
-
}
|
|
286
|
-
},
|
|
287
|
-
|
|
288
|
-
handleClaudeImportChange(event) {
|
|
289
|
-
const file = event && event.target && event.target.files ? event.target.files[0] : null;
|
|
290
|
-
if (file) {
|
|
291
|
-
void this.importBackupFile('claude', file);
|
|
292
|
-
}
|
|
293
|
-
},
|
|
294
|
-
|
|
295
|
-
handleCodexImportChange(event) {
|
|
296
|
-
const file = event && event.target && event.target.files ? event.target.files[0] : null;
|
|
297
|
-
if (file) {
|
|
298
|
-
void this.importBackupFile('codex', file);
|
|
299
|
-
}
|
|
300
|
-
},
|
|
301
|
-
|
|
302
|
-
async importBackupFile(type, file) {
|
|
303
|
-
const maxSize = 200 * 1024 * 1024;
|
|
304
|
-
const loadingKey = type === 'claude' ? 'claudeImportLoading' : 'codexImportLoading';
|
|
305
|
-
if (this[loadingKey]) {
|
|
306
|
-
this.resetImportInput(type);
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
309
|
-
if (file.size > maxSize) {
|
|
310
|
-
this.showMessage('备份文件过大,限制 200MB', 'error');
|
|
311
|
-
this.resetImportInput(type);
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
this[loadingKey] = true;
|
|
315
|
-
try {
|
|
316
|
-
const base64 = await this.readFileAsBase64(file);
|
|
317
|
-
const action = type === 'claude' ? 'restore-claude-dir' : 'restore-codex-dir';
|
|
318
|
-
const res = await api(action, {
|
|
319
|
-
fileName: file.name || `${type}-backup.zip`,
|
|
320
|
-
fileBase64: base64
|
|
321
|
-
});
|
|
322
|
-
if (res && res.error) {
|
|
323
|
-
this.showMessage(res.error, 'error');
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
const backupTip = res && res.backupPath ? `,原配置已备份到临时文件:${res.backupPath}` : '';
|
|
327
|
-
this.showMessage(`导入成功${backupTip}`, 'success');
|
|
328
|
-
try {
|
|
329
|
-
if (type === 'claude') {
|
|
330
|
-
await this.refreshClaudeSelectionFromSettings({ silent: true });
|
|
331
|
-
} else {
|
|
332
|
-
await this.loadAll();
|
|
333
|
-
}
|
|
334
|
-
} catch (_) {
|
|
335
|
-
this.showMessage('导入已完成,但界面刷新失败,请手动刷新', 'error');
|
|
336
|
-
}
|
|
337
|
-
} catch (e) {
|
|
338
|
-
this.showMessage('导入失败:' + (e && e.message ? e.message : '未知错误'), 'error');
|
|
339
|
-
} finally {
|
|
340
|
-
this[loadingKey] = false;
|
|
341
|
-
this.resetImportInput(type);
|
|
342
|
-
}
|
|
343
|
-
},
|
|
344
|
-
|
|
345
|
-
readFileAsBase64(file) {
|
|
346
|
-
return new Promise((resolve, reject) => {
|
|
347
|
-
const reader = new FileReader();
|
|
348
|
-
reader.onload = () => {
|
|
349
|
-
const result = reader.result;
|
|
350
|
-
if (result instanceof ArrayBuffer) {
|
|
351
|
-
resolve(this.arrayBufferToBase64(result));
|
|
352
|
-
return;
|
|
353
|
-
}
|
|
354
|
-
if (typeof result === 'string') {
|
|
355
|
-
const idx = result.indexOf('base64,');
|
|
356
|
-
resolve(idx >= 0 ? result.slice(idx + 7) : result);
|
|
357
|
-
return;
|
|
358
|
-
}
|
|
359
|
-
reject(new Error('不支持的文件读取结果'));
|
|
360
|
-
};
|
|
361
|
-
reader.onerror = () => reject(new Error('读取文件失败'));
|
|
362
|
-
reader.readAsArrayBuffer(file);
|
|
363
|
-
});
|
|
364
|
-
},
|
|
365
|
-
|
|
366
|
-
arrayBufferToBase64(buffer) {
|
|
367
|
-
const bytes = new Uint8Array(buffer);
|
|
368
|
-
const chunkSize = 0x8000;
|
|
369
|
-
let binary = '';
|
|
370
|
-
for (let i = 0; i < bytes.byteLength; i += chunkSize) {
|
|
371
|
-
binary += String.fromCharCode(...bytes.subarray(i, i + chunkSize));
|
|
372
|
-
}
|
|
373
|
-
return btoa(binary);
|
|
374
|
-
},
|
|
375
|
-
|
|
376
|
-
resetImportInput(type) {
|
|
377
|
-
const refName = type === 'claude' ? 'claudeImportInput' : 'codexImportInput';
|
|
378
|
-
const el = this.$refs[refName];
|
|
379
|
-
if (el) {
|
|
380
|
-
el.value = '';
|
|
381
|
-
}
|
|
382
|
-
},
|
|
383
|
-
|
|
384
|
-
async loadCodexAuthProfiles(options = {}) {
|
|
385
|
-
const silent = !!options.silent;
|
|
386
|
-
try {
|
|
387
|
-
const res = await api('list-auth-profiles');
|
|
388
|
-
if (res && res.error) {
|
|
389
|
-
if (!silent) {
|
|
390
|
-
this.showMessage(res.error, 'error');
|
|
391
|
-
}
|
|
392
|
-
return;
|
|
393
|
-
}
|
|
394
|
-
const list = Array.isArray(res && res.profiles) ? res.profiles : [];
|
|
395
|
-
this.codexAuthProfiles = list.sort((a, b) => {
|
|
396
|
-
if (!!a.current !== !!b.current) {
|
|
397
|
-
return a.current ? -1 : 1;
|
|
398
|
-
}
|
|
399
|
-
return String(a.name || '').localeCompare(String(b.name || ''));
|
|
400
|
-
});
|
|
401
|
-
} catch (e) {
|
|
402
|
-
if (!silent) {
|
|
403
|
-
this.showMessage('读取认证列表失败', 'error');
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
},
|
|
407
|
-
|
|
408
|
-
showMessage(text, type) {
|
|
409
|
-
if (this._messageTimer) {
|
|
410
|
-
clearTimeout(this._messageTimer);
|
|
411
|
-
}
|
|
412
|
-
this.message = translateUiMessage(this, text);
|
|
413
|
-
this.messageType = type || 'info';
|
|
414
|
-
this._messageTimer = setTimeout(() => {
|
|
415
|
-
this.message = '';
|
|
416
|
-
this._messageTimer = null;
|
|
417
|
-
}, 3000);
|
|
418
|
-
}
|
|
419
|
-
};
|
|
420
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
buildSpeedTestIssue,
|
|
3
|
+
formatLatency
|
|
4
|
+
} from '../logic.mjs';
|
|
5
|
+
|
|
6
|
+
const UI_MESSAGE_KEY_BY_TEXT = Object.freeze({
|
|
7
|
+
'操作成功': 'toast.operationSuccess',
|
|
8
|
+
'操作失败': 'toast.operationFailed',
|
|
9
|
+
'添加失败': 'toast.addFailed',
|
|
10
|
+
'更新失败': 'toast.updateFailed',
|
|
11
|
+
'删除失败': 'toast.deleteFailed',
|
|
12
|
+
'已删除': 'toast.deleted',
|
|
13
|
+
'已复制': 'toast.copied',
|
|
14
|
+
'复制失败': 'toast.copyFailed',
|
|
15
|
+
'剪贴板为空': 'toast.clipboardEmpty',
|
|
16
|
+
'无法读取剪贴板': 'toast.clipboardReadFailed',
|
|
17
|
+
'已粘贴': 'toast.pasted',
|
|
18
|
+
'未检测到改动': 'toast.noChanges',
|
|
19
|
+
'配置已应用': 'toast.configApplied',
|
|
20
|
+
'应用配置失败': 'toast.applyConfigFailed',
|
|
21
|
+
'应用失败': 'toast.applyFailed',
|
|
22
|
+
'配置已加载': 'toast.configLoaded',
|
|
23
|
+
'配置就绪': 'toast.configReady',
|
|
24
|
+
'加载配置失败': 'toast.loadConfigFailed',
|
|
25
|
+
'读取配置失败': 'toast.readConfigFailed',
|
|
26
|
+
'读取配置超时': 'toast.readConfigTimeout',
|
|
27
|
+
'备份失败': 'toast.backupFailed',
|
|
28
|
+
'备份成功,开始下载': 'toast.backupReadyDownload',
|
|
29
|
+
'导入失败': 'toast.importFailed',
|
|
30
|
+
'导入成功': 'toast.importSuccess',
|
|
31
|
+
'导入 skill 失败': 'toast.importSkillFailed',
|
|
32
|
+
'导出失败': 'toast.exportFailed',
|
|
33
|
+
'保存失败': 'toast.saveFailed',
|
|
34
|
+
'加载文件失败': 'toast.loadFileFailed',
|
|
35
|
+
'请填写名称': 'toast.nameRequired',
|
|
36
|
+
'请输入名称': 'toast.nameRequired',
|
|
37
|
+
'名称已存在': 'toast.nameExists',
|
|
38
|
+
'至少保留一项': 'toast.keepOneItem',
|
|
39
|
+
'请输入模型': 'toast.modelRequired',
|
|
40
|
+
'请选择提供商和模型': 'toast.providerModelRequired',
|
|
41
|
+
'请先配置 API Key': 'toast.apiKeyRequired',
|
|
42
|
+
'配置已存在': 'toast.configExists',
|
|
43
|
+
'不支持此操作': 'toast.unsupportedOperation',
|
|
44
|
+
'参数无效': 'toast.invalidParams',
|
|
45
|
+
'不可分享': 'toast.notShareable',
|
|
46
|
+
'已移入回收站': 'toast.movedToTrash',
|
|
47
|
+
'生成命令失败': 'toast.commandGenerationFailed',
|
|
48
|
+
'没有可复制内容': 'toast.nothingToCopy',
|
|
49
|
+
'没有可导出内容': 'toast.nothingToExport',
|
|
50
|
+
'会话已恢复': 'toast.sessionRestored',
|
|
51
|
+
'恢复失败': 'toast.restoreFailed',
|
|
52
|
+
'已彻底删除': 'toast.purged',
|
|
53
|
+
'彻底删除失败': 'toast.purgeFailed',
|
|
54
|
+
'回收站已清空': 'toast.trashCleared',
|
|
55
|
+
'清空回收站失败': 'toast.trashClearFailed',
|
|
56
|
+
'加载回收站失败': 'toast.trashLoadFailed',
|
|
57
|
+
'加载回收站数量失败': 'toast.trashCountLoadFailed',
|
|
58
|
+
'任务计划已更新': 'toast.taskPlanUpdated',
|
|
59
|
+
'任务计划生成失败': 'toast.taskPlanFailed',
|
|
60
|
+
'计划存在问题,请先修复再执行': 'toast.taskPlanHasIssues',
|
|
61
|
+
'已发出取消请求': 'toast.cancelRequested',
|
|
62
|
+
'取消任务失败': 'toast.cancelTaskFailed'
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const UI_MESSAGE_PREFIX_ENTRIES = Object.freeze(
|
|
66
|
+
Object.entries(UI_MESSAGE_KEY_BY_TEXT).sort((a, b) => b[0].length - a[0].length)
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
function translateUiMessage(context, text) {
|
|
70
|
+
if (!context || typeof context.t !== 'function' || typeof text !== 'string') return text;
|
|
71
|
+
const exactKey = UI_MESSAGE_KEY_BY_TEXT[text];
|
|
72
|
+
if (exactKey) return context.t(exactKey);
|
|
73
|
+
const prefixEntry = UI_MESSAGE_PREFIX_ENTRIES.find(([sourceText]) => {
|
|
74
|
+
return text.length > sourceText.length && text.startsWith(sourceText);
|
|
75
|
+
});
|
|
76
|
+
if (!prefixEntry) return text;
|
|
77
|
+
const [sourceText, key] = prefixEntry;
|
|
78
|
+
return `${context.t(key)}${text.slice(sourceText.length)}`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function clearProgressResetTimer(context, timerKey) {
|
|
82
|
+
if (!context || !timerKey || !context[timerKey]) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
clearTimeout(context[timerKey]);
|
|
86
|
+
context[timerKey] = null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function scheduleProgressResetTimer(context, timerKey, progressKey, delayMs = 800) {
|
|
90
|
+
if (!context || !timerKey || !progressKey) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
clearProgressResetTimer(context, timerKey);
|
|
94
|
+
context[timerKey] = setTimeout(() => {
|
|
95
|
+
context[progressKey] = 0;
|
|
96
|
+
context[timerKey] = null;
|
|
97
|
+
}, delayMs);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function createRuntimeMethods(options = {}) {
|
|
101
|
+
const { api } = options;
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
formatLatency,
|
|
105
|
+
|
|
106
|
+
buildSpeedTestIssue(name, result) {
|
|
107
|
+
return buildSpeedTestIssue(name, result);
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
async runSpeedTest(name, options = {}) {
|
|
111
|
+
if (!name || this.speedLoading[name]) return null;
|
|
112
|
+
const silent = !!options.silent;
|
|
113
|
+
this.speedLoading[name] = true;
|
|
114
|
+
try {
|
|
115
|
+
const timeoutMs = Number.isFinite(options.timeoutMs) ? Math.max(1000, Number(options.timeoutMs)) : 0;
|
|
116
|
+
const payload = { name };
|
|
117
|
+
if (timeoutMs) {
|
|
118
|
+
payload.timeoutMs = timeoutMs;
|
|
119
|
+
}
|
|
120
|
+
const res = await api('speed-test', payload);
|
|
121
|
+
if (res.error) {
|
|
122
|
+
this.speedResults[name] = { ok: false, error: res.error };
|
|
123
|
+
if (!silent) {
|
|
124
|
+
this.showMessage(res.error, 'error');
|
|
125
|
+
}
|
|
126
|
+
return { ok: false, error: res.error };
|
|
127
|
+
}
|
|
128
|
+
this.speedResults[name] = res;
|
|
129
|
+
if (!silent) {
|
|
130
|
+
const status = res.status ? ` (${res.status})` : '';
|
|
131
|
+
this.showMessage(`Speed ${name}: ${this.formatLatency(res)}${status}`, 'success');
|
|
132
|
+
}
|
|
133
|
+
return res;
|
|
134
|
+
} catch (e) {
|
|
135
|
+
const message = e && e.message ? e.message : 'Speed test failed';
|
|
136
|
+
this.speedResults[name] = { ok: false, error: message };
|
|
137
|
+
if (!silent) {
|
|
138
|
+
this.showMessage(message, 'error');
|
|
139
|
+
}
|
|
140
|
+
return { ok: false, error: message };
|
|
141
|
+
} finally {
|
|
142
|
+
this.speedLoading[name] = false;
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
async runClaudeSpeedTest(name, config) {
|
|
147
|
+
if (!name || this.claudeSpeedLoading[name]) return null;
|
|
148
|
+
const baseUrl = config && typeof config.baseUrl === 'string' ? config.baseUrl.trim() : '';
|
|
149
|
+
const apiKey = config && typeof config.apiKey === 'string' ? config.apiKey.trim() : '';
|
|
150
|
+
const model = config && typeof config.model === 'string' ? config.model.trim() : '';
|
|
151
|
+
this.claudeSpeedLoading[name] = true;
|
|
152
|
+
try {
|
|
153
|
+
if (!baseUrl) {
|
|
154
|
+
const res = { ok: false, error: 'Missing base URL' };
|
|
155
|
+
this.claudeSpeedResults[name] = res;
|
|
156
|
+
return res;
|
|
157
|
+
}
|
|
158
|
+
if (!apiKey) {
|
|
159
|
+
const res = { ok: false, error: 'Missing API key' };
|
|
160
|
+
this.claudeSpeedResults[name] = res;
|
|
161
|
+
return res;
|
|
162
|
+
}
|
|
163
|
+
if (!model) {
|
|
164
|
+
const res = { ok: false, error: 'Missing model' };
|
|
165
|
+
this.claudeSpeedResults[name] = res;
|
|
166
|
+
return res;
|
|
167
|
+
}
|
|
168
|
+
const res = await api('speed-test', {
|
|
169
|
+
kind: 'claude',
|
|
170
|
+
url: baseUrl,
|
|
171
|
+
apiKey,
|
|
172
|
+
model
|
|
173
|
+
});
|
|
174
|
+
if (res.error) {
|
|
175
|
+
this.claudeSpeedResults[name] = { ok: false, error: res.error };
|
|
176
|
+
return { ok: false, error: res.error };
|
|
177
|
+
}
|
|
178
|
+
this.claudeSpeedResults[name] = res;
|
|
179
|
+
return res;
|
|
180
|
+
} catch (e) {
|
|
181
|
+
const message = e && e.message ? e.message : 'Speed test failed';
|
|
182
|
+
const res = { ok: false, error: message };
|
|
183
|
+
this.claudeSpeedResults[name] = res;
|
|
184
|
+
return res;
|
|
185
|
+
} finally {
|
|
186
|
+
this.claudeSpeedLoading[name] = false;
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
|
|
190
|
+
async downloadClaudeDirectory() {
|
|
191
|
+
if (this.claudeDownloadLoading) return;
|
|
192
|
+
clearProgressResetTimer(this, '__claudeDownloadResetTimer');
|
|
193
|
+
this.claudeDownloadLoading = true;
|
|
194
|
+
this.claudeDownloadProgress = 5;
|
|
195
|
+
this.claudeDownloadTimer = setInterval(() => {
|
|
196
|
+
if (this.claudeDownloadProgress < 90) {
|
|
197
|
+
this.claudeDownloadProgress += 5;
|
|
198
|
+
}
|
|
199
|
+
}, 400);
|
|
200
|
+
try {
|
|
201
|
+
const res = await api('download-claude-dir');
|
|
202
|
+
if (res && res.error) {
|
|
203
|
+
this.showMessage(res.error, 'error');
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (!res || res.success !== true || !res.fileName) {
|
|
207
|
+
this.showMessage('备份失败', 'error');
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
this.claudeDownloadProgress = 100;
|
|
211
|
+
const downloadUrl = `/download/${encodeURIComponent(res.fileName)}`;
|
|
212
|
+
const link = document.createElement('a');
|
|
213
|
+
link.href = downloadUrl;
|
|
214
|
+
link.download = res.fileName;
|
|
215
|
+
document.body.appendChild(link);
|
|
216
|
+
link.click();
|
|
217
|
+
document.body.removeChild(link);
|
|
218
|
+
this.showMessage('备份成功,开始下载', 'success');
|
|
219
|
+
} catch (e) {
|
|
220
|
+
this.showMessage('备份失败:' + (e && e.message ? e.message : '未知错误'), 'error');
|
|
221
|
+
} finally {
|
|
222
|
+
if (this.claudeDownloadTimer) {
|
|
223
|
+
clearInterval(this.claudeDownloadTimer);
|
|
224
|
+
this.claudeDownloadTimer = null;
|
|
225
|
+
}
|
|
226
|
+
this.claudeDownloadLoading = false;
|
|
227
|
+
scheduleProgressResetTimer(this, '__claudeDownloadResetTimer', 'claudeDownloadProgress');
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
|
|
231
|
+
async downloadCodexDirectory() {
|
|
232
|
+
if (this.codexDownloadLoading) return;
|
|
233
|
+
clearProgressResetTimer(this, '__codexDownloadResetTimer');
|
|
234
|
+
this.codexDownloadLoading = true;
|
|
235
|
+
this.codexDownloadProgress = 5;
|
|
236
|
+
this.codexDownloadTimer = setInterval(() => {
|
|
237
|
+
if (this.codexDownloadProgress < 90) {
|
|
238
|
+
this.codexDownloadProgress += 5;
|
|
239
|
+
}
|
|
240
|
+
}, 400);
|
|
241
|
+
try {
|
|
242
|
+
const res = await api('download-codex-dir');
|
|
243
|
+
if (res && res.error) {
|
|
244
|
+
this.showMessage(res.error, 'error');
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
if (!res || res.success !== true || !res.fileName) {
|
|
248
|
+
this.showMessage('备份失败', 'error');
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
this.codexDownloadProgress = 100;
|
|
252
|
+
const downloadUrl = `/download/${encodeURIComponent(res.fileName)}`;
|
|
253
|
+
const link = document.createElement('a');
|
|
254
|
+
link.href = downloadUrl;
|
|
255
|
+
link.download = res.fileName;
|
|
256
|
+
document.body.appendChild(link);
|
|
257
|
+
link.click();
|
|
258
|
+
document.body.removeChild(link);
|
|
259
|
+
this.showMessage('备份成功,开始下载', 'success');
|
|
260
|
+
} catch (e) {
|
|
261
|
+
this.showMessage('备份失败:' + (e && e.message ? e.message : '未知错误'), 'error');
|
|
262
|
+
} finally {
|
|
263
|
+
if (this.codexDownloadTimer) {
|
|
264
|
+
clearInterval(this.codexDownloadTimer);
|
|
265
|
+
this.codexDownloadTimer = null;
|
|
266
|
+
}
|
|
267
|
+
this.codexDownloadLoading = false;
|
|
268
|
+
scheduleProgressResetTimer(this, '__codexDownloadResetTimer', 'codexDownloadProgress');
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
|
|
272
|
+
triggerClaudeImport() {
|
|
273
|
+
const input = this.$refs.claudeImportInput;
|
|
274
|
+
if (input) {
|
|
275
|
+
input.value = '';
|
|
276
|
+
input.click();
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
|
|
280
|
+
triggerCodexImport() {
|
|
281
|
+
const input = this.$refs.codexImportInput;
|
|
282
|
+
if (input) {
|
|
283
|
+
input.value = '';
|
|
284
|
+
input.click();
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
|
|
288
|
+
handleClaudeImportChange(event) {
|
|
289
|
+
const file = event && event.target && event.target.files ? event.target.files[0] : null;
|
|
290
|
+
if (file) {
|
|
291
|
+
void this.importBackupFile('claude', file);
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
|
|
295
|
+
handleCodexImportChange(event) {
|
|
296
|
+
const file = event && event.target && event.target.files ? event.target.files[0] : null;
|
|
297
|
+
if (file) {
|
|
298
|
+
void this.importBackupFile('codex', file);
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
|
|
302
|
+
async importBackupFile(type, file) {
|
|
303
|
+
const maxSize = 200 * 1024 * 1024;
|
|
304
|
+
const loadingKey = type === 'claude' ? 'claudeImportLoading' : 'codexImportLoading';
|
|
305
|
+
if (this[loadingKey]) {
|
|
306
|
+
this.resetImportInput(type);
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
if (file.size > maxSize) {
|
|
310
|
+
this.showMessage('备份文件过大,限制 200MB', 'error');
|
|
311
|
+
this.resetImportInput(type);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
this[loadingKey] = true;
|
|
315
|
+
try {
|
|
316
|
+
const base64 = await this.readFileAsBase64(file);
|
|
317
|
+
const action = type === 'claude' ? 'restore-claude-dir' : 'restore-codex-dir';
|
|
318
|
+
const res = await api(action, {
|
|
319
|
+
fileName: file.name || `${type}-backup.zip`,
|
|
320
|
+
fileBase64: base64
|
|
321
|
+
});
|
|
322
|
+
if (res && res.error) {
|
|
323
|
+
this.showMessage(res.error, 'error');
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
const backupTip = res && res.backupPath ? `,原配置已备份到临时文件:${res.backupPath}` : '';
|
|
327
|
+
this.showMessage(`导入成功${backupTip}`, 'success');
|
|
328
|
+
try {
|
|
329
|
+
if (type === 'claude') {
|
|
330
|
+
await this.refreshClaudeSelectionFromSettings({ silent: true });
|
|
331
|
+
} else {
|
|
332
|
+
await this.loadAll();
|
|
333
|
+
}
|
|
334
|
+
} catch (_) {
|
|
335
|
+
this.showMessage('导入已完成,但界面刷新失败,请手动刷新', 'error');
|
|
336
|
+
}
|
|
337
|
+
} catch (e) {
|
|
338
|
+
this.showMessage('导入失败:' + (e && e.message ? e.message : '未知错误'), 'error');
|
|
339
|
+
} finally {
|
|
340
|
+
this[loadingKey] = false;
|
|
341
|
+
this.resetImportInput(type);
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
|
|
345
|
+
readFileAsBase64(file) {
|
|
346
|
+
return new Promise((resolve, reject) => {
|
|
347
|
+
const reader = new FileReader();
|
|
348
|
+
reader.onload = () => {
|
|
349
|
+
const result = reader.result;
|
|
350
|
+
if (result instanceof ArrayBuffer) {
|
|
351
|
+
resolve(this.arrayBufferToBase64(result));
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
if (typeof result === 'string') {
|
|
355
|
+
const idx = result.indexOf('base64,');
|
|
356
|
+
resolve(idx >= 0 ? result.slice(idx + 7) : result);
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
reject(new Error('不支持的文件读取结果'));
|
|
360
|
+
};
|
|
361
|
+
reader.onerror = () => reject(new Error('读取文件失败'));
|
|
362
|
+
reader.readAsArrayBuffer(file);
|
|
363
|
+
});
|
|
364
|
+
},
|
|
365
|
+
|
|
366
|
+
arrayBufferToBase64(buffer) {
|
|
367
|
+
const bytes = new Uint8Array(buffer);
|
|
368
|
+
const chunkSize = 0x8000;
|
|
369
|
+
let binary = '';
|
|
370
|
+
for (let i = 0; i < bytes.byteLength; i += chunkSize) {
|
|
371
|
+
binary += String.fromCharCode(...bytes.subarray(i, i + chunkSize));
|
|
372
|
+
}
|
|
373
|
+
return btoa(binary);
|
|
374
|
+
},
|
|
375
|
+
|
|
376
|
+
resetImportInput(type) {
|
|
377
|
+
const refName = type === 'claude' ? 'claudeImportInput' : 'codexImportInput';
|
|
378
|
+
const el = this.$refs[refName];
|
|
379
|
+
if (el) {
|
|
380
|
+
el.value = '';
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
|
|
384
|
+
async loadCodexAuthProfiles(options = {}) {
|
|
385
|
+
const silent = !!options.silent;
|
|
386
|
+
try {
|
|
387
|
+
const res = await api('list-auth-profiles');
|
|
388
|
+
if (res && res.error) {
|
|
389
|
+
if (!silent) {
|
|
390
|
+
this.showMessage(res.error, 'error');
|
|
391
|
+
}
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
const list = Array.isArray(res && res.profiles) ? res.profiles : [];
|
|
395
|
+
this.codexAuthProfiles = list.sort((a, b) => {
|
|
396
|
+
if (!!a.current !== !!b.current) {
|
|
397
|
+
return a.current ? -1 : 1;
|
|
398
|
+
}
|
|
399
|
+
return String(a.name || '').localeCompare(String(b.name || ''));
|
|
400
|
+
});
|
|
401
|
+
} catch (e) {
|
|
402
|
+
if (!silent) {
|
|
403
|
+
this.showMessage('读取认证列表失败', 'error');
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
|
|
408
|
+
showMessage(text, type) {
|
|
409
|
+
if (this._messageTimer) {
|
|
410
|
+
clearTimeout(this._messageTimer);
|
|
411
|
+
}
|
|
412
|
+
this.message = translateUiMessage(this, text);
|
|
413
|
+
this.messageType = type || 'info';
|
|
414
|
+
this._messageTimer = setTimeout(() => {
|
|
415
|
+
this.message = '';
|
|
416
|
+
this._messageTimer = null;
|
|
417
|
+
}, 3000);
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
}
|