codexmate 0.0.32 → 0.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/README.md +147 -363
  2. package/README.zh.md +147 -371
  3. package/cli/agents-files.js +224 -224
  4. package/cli/archive-helpers.js +446 -446
  5. package/cli/auth-profiles.js +375 -375
  6. package/cli/builtin-proxy.js +1725 -1725
  7. package/cli/claude-proxy.js +1022 -1022
  8. package/cli/config-bootstrap.js +402 -402
  9. package/cli/config-health.js +454 -454
  10. package/cli/doctor-core.js +903 -903
  11. package/cli/import-skills-url.js +356 -356
  12. package/cli/local-bridge.js +551 -324
  13. package/cli/openai-bridge.js +1653 -1653
  14. package/cli/openclaw-config.js +629 -629
  15. package/cli/session-convert-args.js +69 -69
  16. package/cli/session-convert-io.js +82 -82
  17. package/cli/session-convert.js +150 -150
  18. package/cli/session-usage.concurrent.js +28 -28
  19. package/cli/session-usage.js +118 -118
  20. package/cli/session-usage.models.js +176 -176
  21. package/cli/skills.js +1141 -1141
  22. package/cli/update.js +162 -0
  23. package/cli/zip-commands.js +510 -510
  24. package/cli.js +16023 -15829
  25. package/lib/automation.js +404 -404
  26. package/lib/cli-file-utils.js +151 -151
  27. package/lib/cli-models-utils.js +440 -440
  28. package/lib/cli-network-utils.js +190 -190
  29. package/lib/cli-path-utils.js +85 -85
  30. package/lib/cli-session-utils.js +121 -121
  31. package/lib/cli-sessions.js +427 -426
  32. package/lib/cli-utils.js +155 -155
  33. package/lib/cli-webhook.js +126 -126
  34. package/lib/download-artifacts.js +92 -92
  35. package/lib/mcp-stdio.js +453 -453
  36. package/lib/task-orchestrator.js +869 -869
  37. package/lib/text-diff.js +303 -303
  38. package/lib/win-tray.js +119 -0
  39. package/lib/workflow-engine.js +340 -340
  40. package/package.json +76 -76
  41. package/plugins/README.md +20 -20
  42. package/plugins/README.zh-CN.md +20 -20
  43. package/plugins/prompt-templates/comment-polish/index.mjs +25 -25
  44. package/plugins/prompt-templates/computed.mjs +253 -253
  45. package/plugins/prompt-templates/index.mjs +8 -8
  46. package/plugins/prompt-templates/manifest.mjs +15 -15
  47. package/plugins/prompt-templates/methods.mjs +553 -553
  48. package/plugins/prompt-templates/overview.mjs +91 -91
  49. package/plugins/prompt-templates/ownership.mjs +19 -19
  50. package/plugins/prompt-templates/rule-ack/index.mjs +21 -21
  51. package/plugins/prompt-templates/storage.mjs +64 -64
  52. package/plugins/registry.mjs +16 -16
  53. package/web-ui/app.js +650 -647
  54. package/web-ui/index.html +36 -36
  55. package/web-ui/logic.agents-diff.mjs +386 -386
  56. package/web-ui/logic.claude.mjs +168 -168
  57. package/web-ui/logic.codex.mjs +69 -69
  58. package/web-ui/logic.mjs +5 -5
  59. package/web-ui/logic.runtime.mjs +128 -128
  60. package/web-ui/logic.session-convert.mjs +70 -70
  61. package/web-ui/logic.sessions.mjs +781 -781
  62. package/web-ui/modules/api.mjs +90 -90
  63. package/web-ui/modules/app.computed.dashboard.mjs +248 -248
  64. package/web-ui/modules/app.computed.index.mjs +17 -17
  65. package/web-ui/modules/app.computed.main-tabs.mjs +205 -205
  66. package/web-ui/modules/app.computed.session.mjs +735 -693
  67. package/web-ui/modules/app.constants.mjs +15 -15
  68. package/web-ui/modules/app.methods.agents.mjs +651 -651
  69. package/web-ui/modules/app.methods.claude-config.mjs +269 -200
  70. package/web-ui/modules/app.methods.codex-config.mjs +861 -861
  71. package/web-ui/modules/app.methods.index.mjs +94 -94
  72. package/web-ui/modules/app.methods.install.mjs +205 -205
  73. package/web-ui/modules/app.methods.navigation.mjs +774 -774
  74. package/web-ui/modules/app.methods.openclaw-core.mjs +814 -814
  75. package/web-ui/modules/app.methods.openclaw-editing.mjs +372 -372
  76. package/web-ui/modules/app.methods.openclaw-persist.mjs +369 -369
  77. package/web-ui/modules/app.methods.providers.mjs +575 -529
  78. package/web-ui/modules/app.methods.runtime.mjs +345 -345
  79. package/web-ui/modules/app.methods.session-actions.mjs +591 -591
  80. package/web-ui/modules/app.methods.session-browser.mjs +1012 -1012
  81. package/web-ui/modules/app.methods.session-timeline.mjs +479 -479
  82. package/web-ui/modules/app.methods.session-trash.mjs +438 -438
  83. package/web-ui/modules/app.methods.startup-claude.mjs +538 -537
  84. package/web-ui/modules/app.methods.task-orchestration.mjs +556 -556
  85. package/web-ui/modules/app.methods.webhook.mjs +79 -79
  86. package/web-ui/modules/config-mode.computed.mjs +124 -124
  87. package/web-ui/modules/config-template-confirm-pref.mjs +33 -33
  88. package/web-ui/modules/i18n.dict.mjs +3192 -3177
  89. package/web-ui/modules/i18n.mjs +62 -62
  90. package/web-ui/modules/plugins.computed.mjs +3 -3
  91. package/web-ui/modules/plugins.methods.mjs +3 -3
  92. package/web-ui/modules/plugins.storage.mjs +11 -11
  93. package/web-ui/modules/provider-url-display.mjs +17 -17
  94. package/web-ui/modules/sessions-filters-url.mjs +85 -85
  95. package/web-ui/modules/skills.computed.mjs +107 -107
  96. package/web-ui/modules/skills.methods.mjs +482 -482
  97. package/web-ui/partials/index/layout-footer.html +13 -13
  98. package/web-ui/partials/index/layout-header.html +499 -503
  99. package/web-ui/partials/index/modal-config-template-agents.html +185 -185
  100. package/web-ui/partials/index/modal-confirm-toast.html +32 -32
  101. package/web-ui/partials/index/modal-health-check.html +45 -45
  102. package/web-ui/partials/index/modal-openclaw-config.html +280 -280
  103. package/web-ui/partials/index/modal-skills.html +200 -200
  104. package/web-ui/partials/index/modals-basic.html +173 -162
  105. package/web-ui/partials/index/panel-config-claude.html +166 -136
  106. package/web-ui/partials/index/panel-config-codex.html +190 -196
  107. package/web-ui/partials/index/panel-config-codex.html.bak +337 -0
  108. package/web-ui/partials/index/panel-config-openclaw.html +83 -83
  109. package/web-ui/partials/index/panel-dashboard.html +186 -219
  110. package/web-ui/partials/index/panel-docs.html +114 -114
  111. package/web-ui/partials/index/panel-market.html +177 -177
  112. package/web-ui/partials/index/panel-orchestration.html +391 -391
  113. package/web-ui/partials/index/panel-plugins.html +253 -253
  114. package/web-ui/partials/index/panel-sessions.html +319 -313
  115. package/web-ui/partials/index/panel-settings.html +190 -190
  116. package/web-ui/partials/index/panel-trash.html +82 -82
  117. package/web-ui/partials/index/panel-usage.html +137 -137
  118. package/web-ui/res/json5.min.js +1 -1
  119. package/web-ui/res/vue.global.prod.js +13 -13
  120. package/web-ui/session-helpers.mjs +591 -591
  121. package/web-ui/source-bundle.cjs +233 -233
  122. package/web-ui/styles/base-theme.css +281 -281
  123. package/web-ui/styles/bridge-pool.css +197 -197
  124. package/web-ui/styles/controls-forms.css +433 -433
  125. package/web-ui/styles/dashboard.css +406 -406
  126. package/web-ui/styles/docs-panel.css +245 -245
  127. package/web-ui/styles/feedback.css +108 -108
  128. package/web-ui/styles/health-check-dialog.css +144 -144
  129. package/web-ui/styles/layout-shell.css +628 -638
  130. package/web-ui/styles/modals-core.css +499 -466
  131. package/web-ui/styles/navigation-panels.css +391 -391
  132. package/web-ui/styles/openclaw-structured.css +266 -266
  133. package/web-ui/styles/plugins-panel.css +564 -564
  134. package/web-ui/styles/responsive.css +392 -392
  135. package/web-ui/styles/sessions-list.css +683 -647
  136. package/web-ui/styles/sessions-preview.css +407 -407
  137. package/web-ui/styles/sessions-toolbar-trash.css +518 -518
  138. package/web-ui/styles/sessions-usage.css +588 -588
  139. package/web-ui/styles/settings-panel.css +349 -349
  140. package/web-ui/styles/skills-list.css +305 -305
  141. package/web-ui/styles/skills-market.css +429 -429
  142. package/web-ui/styles/task-orchestration.css +822 -822
  143. package/web-ui/styles/titles-cards.css +472 -472
  144. package/web-ui/styles/trash-panel.css +90 -90
  145. package/web-ui/styles/webhook.css +81 -81
  146. package/web-ui/styles.css +24 -24
  147. package/web-ui.html +17 -17
@@ -1,591 +1,591 @@
1
- import {
2
- normalizeConfigTemplateDiffConfirmEnabled,
3
- persistConfigTemplateDiffConfirmEnabledToStorage
4
- } from './config-template-confirm-pref.mjs';
5
-
6
- export function createSessionActionMethods(options = {}) {
7
- const {
8
- api,
9
- apiBase
10
- } = options;
11
-
12
- return {
13
- getResumeCommandTitle(session) {
14
- return (typeof this.t === 'function' ? this.t('sessions.copyResume') : 'Copy resume command');
15
- },
16
-
17
- getSessionStandaloneContext() {
18
- try {
19
- const url = new URL(window.location.href);
20
- if (url.pathname !== '/session') {
21
- return { requested: false, params: null, error: '' };
22
- }
23
-
24
- const source = (url.searchParams.get('source') || '').trim().toLowerCase();
25
- const sessionId = (url.searchParams.get('sessionId') || url.searchParams.get('id') || '').trim();
26
- const filePath = (url.searchParams.get('filePath') || url.searchParams.get('path') || '').trim();
27
- const maxMessagesRaw = (url.searchParams.get('maxMessages') || '').trim();
28
- const maxMessages = Number(maxMessagesRaw);
29
- let error = '';
30
- if (!source) {
31
- error = '缺少 source 参数';
32
- } else if (source !== 'codex' && source !== 'claude') {
33
- error = 'source 仅支持 codex 或 claude';
34
- }
35
- if (!sessionId && !filePath) {
36
- error = error ? `${error},还缺少 sessionId 或 filePath` : '缺少 sessionId 或 filePath 参数';
37
- }
38
-
39
- if (error) {
40
- return { requested: true, params: null, error };
41
- }
42
-
43
- return {
44
- requested: true,
45
- params: {
46
- source,
47
- sessionId,
48
- filePath,
49
- maxMessages: Number.isFinite(maxMessages) && maxMessages > 0 ? Math.floor(maxMessages) : 0
50
- },
51
- error: ''
52
- };
53
- } catch (_) {
54
- return { requested: false, params: null, error: '' };
55
- }
56
- },
57
-
58
- initSessionStandalone() {
59
- const context = this.getSessionStandaloneContext();
60
- if (!context.requested) return;
61
-
62
- this.sessionStandalone = true;
63
- this.mainTab = 'sessions';
64
- this.prepareSessionTabRender();
65
-
66
- if (context.error || !context.params) {
67
- this.sessionStandaloneError = `会话链接参数不完整:${context.error || '参数解析失败'}`;
68
- return;
69
- }
70
-
71
- const sourceLabel = context.params.source === 'codex' ? 'Codex' : 'Claude Code';
72
- this.activeSession = {
73
- source: context.params.source,
74
- sourceLabel,
75
- sessionId: context.params.sessionId,
76
- filePath: context.params.filePath,
77
- title: context.params.sessionId || context.params.filePath || '会话',
78
- maxMessages: context.params.maxMessages || 50
79
- };
80
- this.activeSessionMessages = [];
81
- this.activeSessionDetailError = '';
82
- this.activeSessionDetailClipped = false;
83
- this.cancelSessionTimelineSync();
84
- this.sessionTimelineActiveKey = '';
85
- this.clearSessionTimelineRefs();
86
- this.sessionStandaloneError = '';
87
- this.sessionStandaloneText = '';
88
- this.sessionStandaloneTitle = this.activeSession.title || '会话';
89
- this.sessionStandaloneSourceLabel = sourceLabel;
90
- this.loadSessionStandalonePlain();
91
- },
92
-
93
- buildSessionStandaloneUrl(session) {
94
- if (!session) return '';
95
- const source = typeof session.source === 'string' ? session.source.trim().toLowerCase() : '';
96
- if (!source || (source !== 'codex' && source !== 'claude')) return '';
97
- const sessionId = typeof session.sessionId === 'string' ? session.sessionId.trim() : '';
98
- const filePath = typeof session.filePath === 'string' ? session.filePath.trim() : '';
99
- if (!sessionId && !filePath) return '';
100
- const origin = window.location.origin && window.location.origin !== 'null'
101
- ? window.location.origin
102
- : (typeof apiBase === 'string' ? apiBase.trim() : '');
103
- if (!origin) return '';
104
- const params = new URLSearchParams();
105
- params.set('source', source);
106
- if (sessionId) params.set('sessionId', sessionId);
107
- if (filePath) params.set('filePath', filePath);
108
- return `${origin}/session?${params.toString()}`;
109
- },
110
-
111
- async copySessionLink(session) {
112
- const url = this.buildSessionStandaloneUrl(session);
113
- if (!url) {
114
- this.showMessage('无法生成链接', 'error');
115
- return;
116
- }
117
- const ok = this.fallbackCopyText(url);
118
- if (ok) {
119
- this.showMessage('已复制链接', 'success');
120
- return;
121
- }
122
- try {
123
- if (navigator.clipboard && window.isSecureContext) {
124
- await navigator.clipboard.writeText(url);
125
- this.showMessage('已复制链接', 'success');
126
- return;
127
- }
128
- } catch (_) {}
129
- this.showMessage('复制失败', 'error');
130
- },
131
-
132
- getSessionExportKey(session) {
133
- return `${session.source || 'unknown'}:${session.sessionId || ''}:${session.filePath || ''}`;
134
- },
135
-
136
- isResumeCommandAvailable(session) {
137
- if (!session) return false;
138
- const source = String(session.source || '').trim().toLowerCase();
139
- const sessionId = typeof session.sessionId === 'string' ? session.sessionId.trim() : '';
140
- const filePath = typeof session.filePath === 'string' ? session.filePath.trim() : '';
141
- if (source === 'claude') {
142
- return !!sessionId || !!this.extractClaudeResumeKeyFromFilePath(filePath);
143
- }
144
- if (source === 'gemini') {
145
- return !!sessionId || !!this.extractClaudeResumeKeyFromFilePath(filePath);
146
- }
147
- return (source === 'codex' || source === 'codebuddy' || source === 'gemini') && !!sessionId;
148
- },
149
-
150
- isCloneAvailable(session) {
151
- if (!session) return false;
152
- const source = String(session.source || '').trim().toLowerCase();
153
- const sessionId = typeof session.sessionId === 'string' ? session.sessionId.trim() : '';
154
- const filePath = typeof session.filePath === 'string' ? session.filePath.trim() : '';
155
- return source === 'codex' && (!!sessionId || !!filePath);
156
- },
157
-
158
- isDeleteAvailable(session) {
159
- if (!session) return false;
160
- const source = String(session.source || '').trim().toLowerCase();
161
- if (source !== 'codex' && source !== 'claude') return false;
162
- const sessionId = typeof session.sessionId === 'string' ? session.sessionId.trim() : '';
163
- const filePath = typeof session.filePath === 'string' ? session.filePath.trim() : '';
164
- return !!sessionId || !!filePath;
165
- },
166
-
167
- buildResumeCommand(session) {
168
- const source = session && session.source ? String(session.source).trim().toLowerCase() : '';
169
- const sessionId = session && session.sessionId ? String(session.sessionId).trim() : '';
170
- const filePath = session && session.filePath ? String(session.filePath).trim() : '';
171
- const resumeKey = (source === 'claude' || source === 'gemini')
172
- ? (sessionId || this.extractClaudeResumeKeyFromFilePath(filePath))
173
- : sessionId;
174
- const arg = this.quoteResumeArg(resumeKey);
175
- if (source === 'codebuddy') {
176
- return `codebuddy -r ${arg}`;
177
- }
178
- if (source === 'gemini') {
179
- return `gemini -r ${arg}`;
180
- }
181
- if (source === 'claude') {
182
- return `claude --dangerously-skip-permissions -r ${arg}`;
183
- }
184
- return `codex --yolo resume ${arg}`;
185
- },
186
-
187
- extractClaudeResumeKeyFromFilePath(filePath) {
188
- const value = typeof filePath === 'string' ? filePath.trim() : '';
189
- if (!value) return '';
190
- const normalized = value.replace(/\\/g, '/');
191
- const base = normalized.split('/').pop() || '';
192
- if (!base) return '';
193
- const lower = base.toLowerCase();
194
- if (lower.endsWith('.jsonl')) {
195
- return base.slice(0, -6);
196
- }
197
- if (lower.endsWith('.json')) {
198
- return base.slice(0, -5);
199
- }
200
- return base;
201
- },
202
-
203
- quoteShellArg(value) {
204
- const text = typeof value === 'string' ? value : String(value || '');
205
- if (!text) return "''";
206
- if (/^[a-zA-Z0-9._-]+$/.test(text)) return text;
207
- const escaped = text.replace(/'/g, "'\\''");
208
- return `'${escaped}'`;
209
- },
210
-
211
- quoteResumeArg(value) {
212
- return this.quoteShellArg(value);
213
- },
214
-
215
- normalizeShareCommandPrefix(value) {
216
- const normalized = typeof value === 'string' ? value.trim().toLowerCase() : '';
217
- if (normalized === 'codexmate') {
218
- return 'codexmate';
219
- }
220
- return 'npm start';
221
- },
222
-
223
- normalizeSessionTrashEnabled(value) {
224
- if (value === false) return false;
225
- const normalized = typeof value === 'string' ? value.trim().toLowerCase() : '';
226
- if (normalized === '0' || normalized === 'false' || normalized === 'off' || normalized === 'no') {
227
- return false;
228
- }
229
- return true;
230
- },
231
-
232
- normalizeConfigTemplateDiffConfirmEnabled(value) {
233
- return normalizeConfigTemplateDiffConfirmEnabled(value);
234
- },
235
-
236
- setSessionTrashEnabled(value) {
237
- const enabled = this.normalizeSessionTrashEnabled(value);
238
- this.sessionTrashEnabled = enabled;
239
- try {
240
- localStorage.setItem('codexmateSessionTrashEnabled', enabled ? 'true' : 'false');
241
- } catch (_) {}
242
- },
243
-
244
- setConfigTemplateDiffConfirmEnabled(value) {
245
- const enabled = this.normalizeConfigTemplateDiffConfirmEnabled(value);
246
- this.configTemplateDiffConfirmEnabled = enabled;
247
- persistConfigTemplateDiffConfirmEnabledToStorage(enabled);
248
- },
249
-
250
- getShareCommandPrefixInvocation() {
251
- const prefix = this.normalizeShareCommandPrefix(this.shareCommandPrefix);
252
- return prefix === 'codexmate' ? 'codexmate' : 'npm start --';
253
- },
254
-
255
- setShareCommandPrefix(value) {
256
- const normalized = this.normalizeShareCommandPrefix(value);
257
- this.shareCommandPrefix = normalized;
258
- try {
259
- localStorage.setItem('codexmateShareCommandPrefix', normalized);
260
- } catch (_) {}
261
- },
262
-
263
- fallbackCopyText(text) {
264
- let textarea = null;
265
- try {
266
- textarea = document.createElement('textarea');
267
- textarea.value = text;
268
- textarea.setAttribute('readonly', '');
269
- textarea.style.position = 'fixed';
270
- textarea.style.top = '-9999px';
271
- textarea.style.left = '-9999px';
272
- textarea.style.opacity = '0';
273
- document.body.appendChild(textarea);
274
- textarea.select();
275
- textarea.setSelectionRange(0, textarea.value.length);
276
- return document.execCommand('copy');
277
- } catch (_) {
278
- return false;
279
- } finally {
280
- if (textarea && textarea.parentNode) {
281
- textarea.parentNode.removeChild(textarea);
282
- }
283
- }
284
- },
285
-
286
- copyAgentsContent() {
287
- const text = typeof this.agentsContent === 'string' ? this.agentsContent : '';
288
- if (!text) {
289
- this.showMessage('没有可复制内容', 'info');
290
- return;
291
- }
292
- const ok = this.fallbackCopyText(text);
293
- if (ok) {
294
- this.showMessage('已复制', 'success');
295
- return;
296
- }
297
- this.showMessage('复制失败', 'error');
298
- },
299
-
300
- exportAgentsContent() {
301
- const text = typeof this.agentsContent === 'string' ? this.agentsContent : '';
302
- if (!text) {
303
- this.showMessage('没有可导出内容', 'info');
304
- return;
305
- }
306
- const now = new Date();
307
- const year = String(now.getFullYear());
308
- const month = String(now.getMonth() + 1).padStart(2, '0');
309
- const day = String(now.getDate()).padStart(2, '0');
310
- const hour = String(now.getHours()).padStart(2, '0');
311
- const minute = String(now.getMinutes()).padStart(2, '0');
312
- const second = String(now.getSeconds()).padStart(2, '0');
313
- const fileName = `agent-${year}${month}${day}-${hour}${minute}${second}.txt`;
314
- this.downloadTextFile(fileName, text, 'text/plain;charset=utf-8');
315
- this.showMessage(`已导出 ${fileName}`, 'success');
316
- },
317
-
318
- async copyInstallCommand(cmd) {
319
- const text = typeof cmd === 'string' ? cmd.trim() : '';
320
- if (!text) {
321
- this.showMessage('没有可复制内容', 'info');
322
- return;
323
- }
324
- try {
325
- if (navigator.clipboard && window.isSecureContext) {
326
- await navigator.clipboard.writeText(text);
327
- this.showMessage('已复制命令', 'success');
328
- return;
329
- }
330
- } catch (_) {}
331
- const ok = this.fallbackCopyText(text);
332
- if (ok) {
333
- this.showMessage('已复制命令', 'success');
334
- return;
335
- }
336
- this.showMessage('复制失败', 'error');
337
- },
338
-
339
- async copyResumeCommand(session) {
340
- if (!this.isResumeCommandAvailable(session)) {
341
- this.showMessage('不支持此操作', 'error');
342
- return;
343
- }
344
- const command = this.buildResumeCommand(session);
345
- const ok = this.fallbackCopyText(command);
346
- if (ok) {
347
- this.showMessage('已复制', 'success');
348
- return;
349
- }
350
- try {
351
- if (navigator.clipboard && window.isSecureContext) {
352
- await navigator.clipboard.writeText(command);
353
- this.showMessage('已复制', 'success');
354
- return;
355
- }
356
- } catch (_) {}
357
- this.showMessage('复制失败', 'error');
358
- },
359
-
360
- buildProviderShareCommand(payload) {
361
- if (!payload || typeof payload !== 'object') return '';
362
- const name = typeof payload.name === 'string' ? payload.name.trim() : '';
363
- const baseUrl = typeof payload.baseUrl === 'string' ? payload.baseUrl.trim() : '';
364
- const apiKey = typeof payload.apiKey === 'string' ? payload.apiKey : '';
365
- const model = typeof payload.model === 'string' ? payload.model.trim() : '';
366
- const bridge = typeof payload.bridge === 'string' ? payload.bridge.trim() : '';
367
- if (!name || !baseUrl) return '';
368
-
369
- const cli = this.getShareCommandPrefixInvocation();
370
- const nameArg = this.quoteShellArg(name);
371
- const urlArg = this.quoteShellArg(baseUrl);
372
- const keyArg = apiKey ? this.quoteShellArg(apiKey) : '';
373
- const switchCmd = `${cli} switch ${nameArg}`;
374
- const bridgeArgs = bridge ? ` --bridge ${this.quoteShellArg(bridge)}` : '';
375
- const addCmd = apiKey
376
- ? `${cli} add ${nameArg} ${urlArg} ${keyArg}${bridgeArgs}`
377
- : `${cli} add ${nameArg} ${urlArg}${bridgeArgs}`;
378
- const modelCmd = model ? ` && ${cli} use ${this.quoteShellArg(model)}` : '';
379
- return `${addCmd} && ${switchCmd}${modelCmd}`;
380
- },
381
-
382
- buildClaudeShareCommand(payload) {
383
- if (!payload || typeof payload !== 'object') return '';
384
- const baseUrl = typeof payload.baseUrl === 'string' ? payload.baseUrl.trim() : '';
385
- const apiKey = typeof payload.apiKey === 'string' ? payload.apiKey : '';
386
- const model = typeof payload.model === 'string' && payload.model.trim()
387
- ? payload.model.trim()
388
- : 'glm-4.7';
389
- if (!baseUrl || !apiKey) return '';
390
- const urlArg = this.quoteShellArg(baseUrl);
391
- const keyArg = this.quoteShellArg(apiKey);
392
- const modelArg = this.quoteShellArg(model);
393
- return `${this.getShareCommandPrefixInvocation()} claude ${urlArg} ${keyArg} ${modelArg}`;
394
- },
395
-
396
- async copyProviderShareCommand(provider) {
397
- const name = provider && typeof provider.name === 'string' ? provider.name.trim() : '';
398
- if (!name) {
399
- this.showMessage('参数无效', 'error');
400
- return;
401
- }
402
- if (!this.shouldAllowProviderShare(provider)) {
403
- this.showMessage('不可分享', 'info');
404
- return;
405
- }
406
- if (this.providerShareLoading[name]) {
407
- return;
408
- }
409
- this.providerShareLoading[name] = true;
410
- try {
411
- const res = await api('export-provider', { name });
412
- if (res && res.error) {
413
- this.showMessage(res.error, 'error');
414
- return;
415
- }
416
- const command = this.buildProviderShareCommand(res && res.payload ? res.payload : null);
417
- if (!command) {
418
- this.showMessage('生成命令失败', 'error');
419
- return;
420
- }
421
- const ok = this.fallbackCopyText(command);
422
- if (ok) {
423
- this.showMessage('已复制', 'success');
424
- return;
425
- }
426
- try {
427
- if (navigator.clipboard && window.isSecureContext) {
428
- await navigator.clipboard.writeText(command);
429
- this.showMessage('已复制', 'success');
430
- return;
431
- }
432
- } catch (_) {}
433
- this.showMessage('复制失败', 'error');
434
- } catch (_) {
435
- this.showMessage('生成命令失败', 'error');
436
- } finally {
437
- this.providerShareLoading[name] = false;
438
- }
439
- },
440
-
441
- async copyClaudeShareCommand(name) {
442
- const config = this.claudeConfigs[name];
443
- if (!config) {
444
- this.showMessage('配置不存在', 'error');
445
- return;
446
- }
447
- if (this.claudeShareLoading[name]) return;
448
- this.claudeShareLoading[name] = true;
449
- try {
450
- const res = await api('export-claude-share', { config });
451
- if (res && res.error) {
452
- this.showMessage(res.error, 'error');
453
- return;
454
- }
455
- const command = this.buildClaudeShareCommand(res && res.payload ? res.payload : null);
456
- if (!command) {
457
- this.showMessage('生成命令失败', 'error');
458
- return;
459
- }
460
- const ok = this.fallbackCopyText(command);
461
- if (ok) {
462
- this.showMessage('已复制', 'success');
463
- return;
464
- }
465
- try {
466
- if (navigator.clipboard && window.isSecureContext) {
467
- await navigator.clipboard.writeText(command);
468
- this.showMessage('已复制', 'success');
469
- return;
470
- }
471
- } catch (_) {}
472
- this.showMessage('复制失败', 'error');
473
- } catch (_) {
474
- this.showMessage('生成命令失败', 'error');
475
- } finally {
476
- this.claudeShareLoading[name] = false;
477
- }
478
- },
479
-
480
- async cloneSession(session) {
481
- if (!this.isCloneAvailable(session)) {
482
- this.showMessage('不支持此操作', 'error');
483
- return;
484
- }
485
- const key = this.getSessionExportKey(session);
486
- if (this.sessionCloning[key]) {
487
- return;
488
- }
489
- this.sessionCloning[key] = true;
490
- try {
491
- const res = await api('clone-session', {
492
- source: session.source,
493
- sessionId: session.sessionId,
494
- filePath: session.filePath
495
- });
496
- if (res.error) {
497
- this.showMessage(res.error, 'error');
498
- return;
499
- }
500
-
501
- this.showMessage('操作成功', 'success');
502
- if (typeof this.invalidateSessionsUsageData === 'function') {
503
- this.invalidateSessionsUsageData({ preserveList: true });
504
- }
505
- try {
506
- await this.loadSessions();
507
- if (res.sessionId) {
508
- const matched = this.sessionsList.find(item => item.source === 'codex' && item.sessionId === res.sessionId);
509
- if (matched) {
510
- await this.selectSession(matched);
511
- }
512
- }
513
- } catch (_) {
514
- // The clone already succeeded remotely; keep the success result.
515
- }
516
- } catch (_) {
517
- this.showMessage('克隆失败', 'error');
518
- } finally {
519
- this.sessionCloning[key] = false;
520
- }
521
- },
522
-
523
- async deleteSession(session) {
524
- if (!this.isDeleteAvailable(session)) {
525
- this.showMessage('不支持此操作', 'error');
526
- return;
527
- }
528
- const useTrash = this.sessionTrashEnabled !== false;
529
- if (!useTrash && typeof this.requestConfirmDialog === 'function') {
530
- const confirmed = await this.requestConfirmDialog({
531
- title: '直接删除会话',
532
- message: '关闭回收站后,删除会话将直接永久删除,且无法恢复。',
533
- confirmText: '直接删除',
534
- cancelText: '取消',
535
- danger: true
536
- });
537
- if (!confirmed) {
538
- return;
539
- }
540
- }
541
- const key = this.getSessionExportKey(session);
542
- if (this.sessionDeleting[key]) {
543
- return;
544
- }
545
- this.sessionDeleting[key] = true;
546
- try {
547
- const action = useTrash ? 'trash-session' : 'delete-session';
548
- const res = await api(action, {
549
- source: session.source,
550
- sessionId: session.sessionId,
551
- filePath: session.filePath
552
- });
553
- if (!res || res.error) {
554
- this.showMessage((res && res.error) || '删除失败', 'error');
555
- return;
556
- }
557
- this.removeSessionPin(session);
558
- if (useTrash) {
559
- this.invalidateSessionTrashRequests();
560
- this.showMessage('已移入回收站', 'success');
561
- if (this.sessionTrashLoadedOnce) {
562
- this.prependSessionTrashItem(this.buildSessionTrashItemFromSession(session, res), {
563
- totalCount: res && res.totalCount !== undefined ? res.totalCount : undefined
564
- });
565
- } else {
566
- this.sessionTrashTotalCount = this.normalizeSessionTrashTotalCount(
567
- res && res.totalCount !== undefined
568
- ? res.totalCount
569
- : (this.normalizeSessionTrashTotalCount(this.sessionTrashTotalCount, this.sessionTrashItems) + 1),
570
- this.sessionTrashItems
571
- );
572
- }
573
- } else {
574
- this.showMessage('已删除', 'success');
575
- }
576
- if (typeof this.invalidateSessionsUsageData === 'function') {
577
- this.invalidateSessionsUsageData({ preserveList: true });
578
- }
579
- try {
580
- await this.removeSessionFromCurrentList(session);
581
- } catch (_) {
582
- // The delete already succeeded remotely; keep the success result.
583
- }
584
- } catch (_) {
585
- this.showMessage('删除失败', 'error');
586
- } finally {
587
- this.sessionDeleting[key] = false;
588
- }
589
- }
590
- };
591
- }
1
+ import {
2
+ normalizeConfigTemplateDiffConfirmEnabled,
3
+ persistConfigTemplateDiffConfirmEnabledToStorage
4
+ } from './config-template-confirm-pref.mjs';
5
+
6
+ export function createSessionActionMethods(options = {}) {
7
+ const {
8
+ api,
9
+ apiBase
10
+ } = options;
11
+
12
+ return {
13
+ getResumeCommandTitle(session) {
14
+ return (typeof this.t === 'function' ? this.t('sessions.copyResume') : 'Copy resume command');
15
+ },
16
+
17
+ getSessionStandaloneContext() {
18
+ try {
19
+ const url = new URL(window.location.href);
20
+ if (url.pathname !== '/session') {
21
+ return { requested: false, params: null, error: '' };
22
+ }
23
+
24
+ const source = (url.searchParams.get('source') || '').trim().toLowerCase();
25
+ const sessionId = (url.searchParams.get('sessionId') || url.searchParams.get('id') || '').trim();
26
+ const filePath = (url.searchParams.get('filePath') || url.searchParams.get('path') || '').trim();
27
+ const maxMessagesRaw = (url.searchParams.get('maxMessages') || '').trim();
28
+ const maxMessages = Number(maxMessagesRaw);
29
+ let error = '';
30
+ if (!source) {
31
+ error = '缺少 source 参数';
32
+ } else if (source !== 'codex' && source !== 'claude') {
33
+ error = 'source 仅支持 codex 或 claude';
34
+ }
35
+ if (!sessionId && !filePath) {
36
+ error = error ? `${error},还缺少 sessionId 或 filePath` : '缺少 sessionId 或 filePath 参数';
37
+ }
38
+
39
+ if (error) {
40
+ return { requested: true, params: null, error };
41
+ }
42
+
43
+ return {
44
+ requested: true,
45
+ params: {
46
+ source,
47
+ sessionId,
48
+ filePath,
49
+ maxMessages: Number.isFinite(maxMessages) && maxMessages > 0 ? Math.floor(maxMessages) : 0
50
+ },
51
+ error: ''
52
+ };
53
+ } catch (_) {
54
+ return { requested: false, params: null, error: '' };
55
+ }
56
+ },
57
+
58
+ initSessionStandalone() {
59
+ const context = this.getSessionStandaloneContext();
60
+ if (!context.requested) return;
61
+
62
+ this.sessionStandalone = true;
63
+ this.mainTab = 'sessions';
64
+ this.prepareSessionTabRender();
65
+
66
+ if (context.error || !context.params) {
67
+ this.sessionStandaloneError = `会话链接参数不完整:${context.error || '参数解析失败'}`;
68
+ return;
69
+ }
70
+
71
+ const sourceLabel = context.params.source === 'codex' ? 'Codex' : 'Claude Code';
72
+ this.activeSession = {
73
+ source: context.params.source,
74
+ sourceLabel,
75
+ sessionId: context.params.sessionId,
76
+ filePath: context.params.filePath,
77
+ title: context.params.sessionId || context.params.filePath || '会话',
78
+ maxMessages: context.params.maxMessages || 50
79
+ };
80
+ this.activeSessionMessages = [];
81
+ this.activeSessionDetailError = '';
82
+ this.activeSessionDetailClipped = false;
83
+ this.cancelSessionTimelineSync();
84
+ this.sessionTimelineActiveKey = '';
85
+ this.clearSessionTimelineRefs();
86
+ this.sessionStandaloneError = '';
87
+ this.sessionStandaloneText = '';
88
+ this.sessionStandaloneTitle = this.activeSession.title || '会话';
89
+ this.sessionStandaloneSourceLabel = sourceLabel;
90
+ this.loadSessionStandalonePlain();
91
+ },
92
+
93
+ buildSessionStandaloneUrl(session) {
94
+ if (!session) return '';
95
+ const source = typeof session.source === 'string' ? session.source.trim().toLowerCase() : '';
96
+ if (!source || (source !== 'codex' && source !== 'claude')) return '';
97
+ const sessionId = typeof session.sessionId === 'string' ? session.sessionId.trim() : '';
98
+ const filePath = typeof session.filePath === 'string' ? session.filePath.trim() : '';
99
+ if (!sessionId && !filePath) return '';
100
+ const origin = window.location.origin && window.location.origin !== 'null'
101
+ ? window.location.origin
102
+ : (typeof apiBase === 'string' ? apiBase.trim() : '');
103
+ if (!origin) return '';
104
+ const params = new URLSearchParams();
105
+ params.set('source', source);
106
+ if (sessionId) params.set('sessionId', sessionId);
107
+ if (filePath) params.set('filePath', filePath);
108
+ return `${origin}/session?${params.toString()}`;
109
+ },
110
+
111
+ async copySessionLink(session) {
112
+ const url = this.buildSessionStandaloneUrl(session);
113
+ if (!url) {
114
+ this.showMessage('无法生成链接', 'error');
115
+ return;
116
+ }
117
+ const ok = this.fallbackCopyText(url);
118
+ if (ok) {
119
+ this.showMessage('已复制链接', 'success');
120
+ return;
121
+ }
122
+ try {
123
+ if (navigator.clipboard && window.isSecureContext) {
124
+ await navigator.clipboard.writeText(url);
125
+ this.showMessage('已复制链接', 'success');
126
+ return;
127
+ }
128
+ } catch (_) {}
129
+ this.showMessage('复制失败', 'error');
130
+ },
131
+
132
+ getSessionExportKey(session) {
133
+ return `${session.source || 'unknown'}:${session.sessionId || ''}:${session.filePath || ''}`;
134
+ },
135
+
136
+ isResumeCommandAvailable(session) {
137
+ if (!session) return false;
138
+ const source = String(session.source || '').trim().toLowerCase();
139
+ const sessionId = typeof session.sessionId === 'string' ? session.sessionId.trim() : '';
140
+ const filePath = typeof session.filePath === 'string' ? session.filePath.trim() : '';
141
+ if (source === 'claude') {
142
+ return !!sessionId || !!this.extractClaudeResumeKeyFromFilePath(filePath);
143
+ }
144
+ if (source === 'gemini') {
145
+ return !!sessionId || !!this.extractClaudeResumeKeyFromFilePath(filePath);
146
+ }
147
+ return (source === 'codex' || source === 'codebuddy' || source === 'gemini') && !!sessionId;
148
+ },
149
+
150
+ isCloneAvailable(session) {
151
+ if (!session) return false;
152
+ const source = String(session.source || '').trim().toLowerCase();
153
+ const sessionId = typeof session.sessionId === 'string' ? session.sessionId.trim() : '';
154
+ const filePath = typeof session.filePath === 'string' ? session.filePath.trim() : '';
155
+ return source === 'codex' && (!!sessionId || !!filePath);
156
+ },
157
+
158
+ isDeleteAvailable(session) {
159
+ if (!session) return false;
160
+ const source = String(session.source || '').trim().toLowerCase();
161
+ if (source !== 'codex' && source !== 'claude') return false;
162
+ const sessionId = typeof session.sessionId === 'string' ? session.sessionId.trim() : '';
163
+ const filePath = typeof session.filePath === 'string' ? session.filePath.trim() : '';
164
+ return !!sessionId || !!filePath;
165
+ },
166
+
167
+ buildResumeCommand(session) {
168
+ const source = session && session.source ? String(session.source).trim().toLowerCase() : '';
169
+ const sessionId = session && session.sessionId ? String(session.sessionId).trim() : '';
170
+ const filePath = session && session.filePath ? String(session.filePath).trim() : '';
171
+ const resumeKey = (source === 'claude' || source === 'gemini')
172
+ ? (sessionId || this.extractClaudeResumeKeyFromFilePath(filePath))
173
+ : sessionId;
174
+ const arg = this.quoteResumeArg(resumeKey);
175
+ if (source === 'codebuddy') {
176
+ return `codebuddy -r ${arg}`;
177
+ }
178
+ if (source === 'gemini') {
179
+ return `gemini -r ${arg}`;
180
+ }
181
+ if (source === 'claude') {
182
+ return `claude --dangerously-skip-permissions -r ${arg}`;
183
+ }
184
+ return `codex --yolo resume ${arg}`;
185
+ },
186
+
187
+ extractClaudeResumeKeyFromFilePath(filePath) {
188
+ const value = typeof filePath === 'string' ? filePath.trim() : '';
189
+ if (!value) return '';
190
+ const normalized = value.replace(/\\/g, '/');
191
+ const base = normalized.split('/').pop() || '';
192
+ if (!base) return '';
193
+ const lower = base.toLowerCase();
194
+ if (lower.endsWith('.jsonl')) {
195
+ return base.slice(0, -6);
196
+ }
197
+ if (lower.endsWith('.json')) {
198
+ return base.slice(0, -5);
199
+ }
200
+ return base;
201
+ },
202
+
203
+ quoteShellArg(value) {
204
+ const text = typeof value === 'string' ? value : String(value || '');
205
+ if (!text) return "''";
206
+ if (/^[a-zA-Z0-9._/:@~+=-]+$/.test(text)) return text;
207
+ const escaped = text.replace(/'/g, "'\\''");
208
+ return `'${escaped}'`;
209
+ },
210
+
211
+ quoteResumeArg(value) {
212
+ return this.quoteShellArg(value);
213
+ },
214
+
215
+ normalizeShareCommandPrefix(value) {
216
+ const normalized = typeof value === 'string' ? value.trim().toLowerCase() : '';
217
+ if (normalized === 'codexmate') {
218
+ return 'codexmate';
219
+ }
220
+ return 'npm start';
221
+ },
222
+
223
+ normalizeSessionTrashEnabled(value) {
224
+ if (value === false) return false;
225
+ const normalized = typeof value === 'string' ? value.trim().toLowerCase() : '';
226
+ if (normalized === '0' || normalized === 'false' || normalized === 'off' || normalized === 'no') {
227
+ return false;
228
+ }
229
+ return true;
230
+ },
231
+
232
+ normalizeConfigTemplateDiffConfirmEnabled(value) {
233
+ return normalizeConfigTemplateDiffConfirmEnabled(value);
234
+ },
235
+
236
+ setSessionTrashEnabled(value) {
237
+ const enabled = this.normalizeSessionTrashEnabled(value);
238
+ this.sessionTrashEnabled = enabled;
239
+ try {
240
+ localStorage.setItem('codexmateSessionTrashEnabled', enabled ? 'true' : 'false');
241
+ } catch (_) {}
242
+ },
243
+
244
+ setConfigTemplateDiffConfirmEnabled(value) {
245
+ const enabled = this.normalizeConfigTemplateDiffConfirmEnabled(value);
246
+ this.configTemplateDiffConfirmEnabled = enabled;
247
+ persistConfigTemplateDiffConfirmEnabledToStorage(enabled);
248
+ },
249
+
250
+ getShareCommandPrefixInvocation() {
251
+ const prefix = this.normalizeShareCommandPrefix(this.shareCommandPrefix);
252
+ return prefix === 'codexmate' ? 'codexmate' : 'npm start --';
253
+ },
254
+
255
+ setShareCommandPrefix(value) {
256
+ const normalized = this.normalizeShareCommandPrefix(value);
257
+ this.shareCommandPrefix = normalized;
258
+ try {
259
+ localStorage.setItem('codexmateShareCommandPrefix', normalized);
260
+ } catch (_) {}
261
+ },
262
+
263
+ fallbackCopyText(text) {
264
+ let textarea = null;
265
+ try {
266
+ textarea = document.createElement('textarea');
267
+ textarea.value = text;
268
+ textarea.setAttribute('readonly', '');
269
+ textarea.style.position = 'fixed';
270
+ textarea.style.top = '-9999px';
271
+ textarea.style.left = '-9999px';
272
+ textarea.style.opacity = '0';
273
+ document.body.appendChild(textarea);
274
+ textarea.select();
275
+ textarea.setSelectionRange(0, textarea.value.length);
276
+ return document.execCommand('copy');
277
+ } catch (_) {
278
+ return false;
279
+ } finally {
280
+ if (textarea && textarea.parentNode) {
281
+ textarea.parentNode.removeChild(textarea);
282
+ }
283
+ }
284
+ },
285
+
286
+ copyAgentsContent() {
287
+ const text = typeof this.agentsContent === 'string' ? this.agentsContent : '';
288
+ if (!text) {
289
+ this.showMessage('没有可复制内容', 'info');
290
+ return;
291
+ }
292
+ const ok = this.fallbackCopyText(text);
293
+ if (ok) {
294
+ this.showMessage('已复制', 'success');
295
+ return;
296
+ }
297
+ this.showMessage('复制失败', 'error');
298
+ },
299
+
300
+ exportAgentsContent() {
301
+ const text = typeof this.agentsContent === 'string' ? this.agentsContent : '';
302
+ if (!text) {
303
+ this.showMessage('没有可导出内容', 'info');
304
+ return;
305
+ }
306
+ const now = new Date();
307
+ const year = String(now.getFullYear());
308
+ const month = String(now.getMonth() + 1).padStart(2, '0');
309
+ const day = String(now.getDate()).padStart(2, '0');
310
+ const hour = String(now.getHours()).padStart(2, '0');
311
+ const minute = String(now.getMinutes()).padStart(2, '0');
312
+ const second = String(now.getSeconds()).padStart(2, '0');
313
+ const fileName = `agent-${year}${month}${day}-${hour}${minute}${second}.txt`;
314
+ this.downloadTextFile(fileName, text, 'text/plain;charset=utf-8');
315
+ this.showMessage(`已导出 ${fileName}`, 'success');
316
+ },
317
+
318
+ async copyInstallCommand(cmd) {
319
+ const text = typeof cmd === 'string' ? cmd.trim() : '';
320
+ if (!text) {
321
+ this.showMessage('没有可复制内容', 'info');
322
+ return;
323
+ }
324
+ try {
325
+ if (navigator.clipboard && window.isSecureContext) {
326
+ await navigator.clipboard.writeText(text);
327
+ this.showMessage('已复制命令', 'success');
328
+ return;
329
+ }
330
+ } catch (_) {}
331
+ const ok = this.fallbackCopyText(text);
332
+ if (ok) {
333
+ this.showMessage('已复制命令', 'success');
334
+ return;
335
+ }
336
+ this.showMessage('复制失败', 'error');
337
+ },
338
+
339
+ async copyResumeCommand(session) {
340
+ if (!this.isResumeCommandAvailable(session)) {
341
+ this.showMessage('不支持此操作', 'error');
342
+ return;
343
+ }
344
+ const command = this.buildResumeCommand(session);
345
+ const ok = this.fallbackCopyText(command);
346
+ if (ok) {
347
+ this.showMessage('已复制', 'success');
348
+ return;
349
+ }
350
+ try {
351
+ if (navigator.clipboard && window.isSecureContext) {
352
+ await navigator.clipboard.writeText(command);
353
+ this.showMessage('已复制', 'success');
354
+ return;
355
+ }
356
+ } catch (_) {}
357
+ this.showMessage('复制失败', 'error');
358
+ },
359
+
360
+ buildProviderShareCommand(payload) {
361
+ if (!payload || typeof payload !== 'object') return '';
362
+ const name = typeof payload.name === 'string' ? payload.name.trim() : '';
363
+ const baseUrl = typeof payload.baseUrl === 'string' ? payload.baseUrl.trim() : '';
364
+ const apiKey = typeof payload.apiKey === 'string' ? payload.apiKey : '';
365
+ const model = typeof payload.model === 'string' ? payload.model.trim() : '';
366
+ const bridge = typeof payload.bridge === 'string' ? payload.bridge.trim() : '';
367
+ if (!name || !baseUrl) return '';
368
+
369
+ const cli = this.getShareCommandPrefixInvocation();
370
+ const nameArg = this.quoteShellArg(name);
371
+ const urlArg = this.quoteShellArg(baseUrl);
372
+ const keyArg = apiKey ? this.quoteShellArg(apiKey) : '';
373
+ const switchCmd = `${cli} switch ${nameArg}`;
374
+ const bridgeArgs = bridge ? ` --bridge ${this.quoteShellArg(bridge)}` : '';
375
+ const addCmd = apiKey
376
+ ? `${cli} add ${nameArg} ${urlArg} ${keyArg}${bridgeArgs}`
377
+ : `${cli} add ${nameArg} ${urlArg}${bridgeArgs}`;
378
+ const modelCmd = model ? ` && ${cli} use ${this.quoteShellArg(model)}` : '';
379
+ return `${addCmd} && ${switchCmd}${modelCmd}`;
380
+ },
381
+
382
+ buildClaudeShareCommand(payload) {
383
+ if (!payload || typeof payload !== 'object') return '';
384
+ const baseUrl = typeof payload.baseUrl === 'string' ? payload.baseUrl.trim() : '';
385
+ const apiKey = typeof payload.apiKey === 'string' ? payload.apiKey : '';
386
+ const model = typeof payload.model === 'string' && payload.model.trim()
387
+ ? payload.model.trim()
388
+ : 'glm-4.7';
389
+ if (!baseUrl || !apiKey) return '';
390
+ const urlArg = this.quoteShellArg(baseUrl);
391
+ const keyArg = this.quoteShellArg(apiKey);
392
+ const modelArg = this.quoteShellArg(model);
393
+ return `${this.getShareCommandPrefixInvocation()} claude ${urlArg} ${keyArg} ${modelArg}`;
394
+ },
395
+
396
+ async copyProviderShareCommand(provider) {
397
+ const name = provider && typeof provider.name === 'string' ? provider.name.trim() : '';
398
+ if (!name) {
399
+ this.showMessage('参数无效', 'error');
400
+ return;
401
+ }
402
+ if (!this.shouldAllowProviderShare(provider)) {
403
+ this.showMessage('不可分享', 'info');
404
+ return;
405
+ }
406
+ if (this.providerShareLoading[name]) {
407
+ return;
408
+ }
409
+ this.providerShareLoading[name] = true;
410
+ try {
411
+ const res = await api('export-provider', { name });
412
+ if (res && res.error) {
413
+ this.showMessage(res.error, 'error');
414
+ return;
415
+ }
416
+ const command = this.buildProviderShareCommand(res && res.payload ? res.payload : null);
417
+ if (!command) {
418
+ this.showMessage('生成命令失败', 'error');
419
+ return;
420
+ }
421
+ const ok = this.fallbackCopyText(command);
422
+ if (ok) {
423
+ this.showMessage('已复制', 'success');
424
+ return;
425
+ }
426
+ try {
427
+ if (navigator.clipboard && window.isSecureContext) {
428
+ await navigator.clipboard.writeText(command);
429
+ this.showMessage('已复制', 'success');
430
+ return;
431
+ }
432
+ } catch (_) {}
433
+ this.showMessage('复制失败', 'error');
434
+ } catch (_) {
435
+ this.showMessage('生成命令失败', 'error');
436
+ } finally {
437
+ this.providerShareLoading[name] = false;
438
+ }
439
+ },
440
+
441
+ async copyClaudeShareCommand(name) {
442
+ const config = this.claudeConfigs[name];
443
+ if (!config) {
444
+ this.showMessage('配置不存在', 'error');
445
+ return;
446
+ }
447
+ if (this.claudeShareLoading[name]) return;
448
+ this.claudeShareLoading[name] = true;
449
+ try {
450
+ const res = await api('export-claude-share', { config });
451
+ if (res && res.error) {
452
+ this.showMessage(res.error, 'error');
453
+ return;
454
+ }
455
+ const command = this.buildClaudeShareCommand(res && res.payload ? res.payload : null);
456
+ if (!command) {
457
+ this.showMessage('生成命令失败', 'error');
458
+ return;
459
+ }
460
+ const ok = this.fallbackCopyText(command);
461
+ if (ok) {
462
+ this.showMessage('已复制', 'success');
463
+ return;
464
+ }
465
+ try {
466
+ if (navigator.clipboard && window.isSecureContext) {
467
+ await navigator.clipboard.writeText(command);
468
+ this.showMessage('已复制', 'success');
469
+ return;
470
+ }
471
+ } catch (_) {}
472
+ this.showMessage('复制失败', 'error');
473
+ } catch (_) {
474
+ this.showMessage('生成命令失败', 'error');
475
+ } finally {
476
+ this.claudeShareLoading[name] = false;
477
+ }
478
+ },
479
+
480
+ async cloneSession(session) {
481
+ if (!this.isCloneAvailable(session)) {
482
+ this.showMessage('不支持此操作', 'error');
483
+ return;
484
+ }
485
+ const key = this.getSessionExportKey(session);
486
+ if (this.sessionCloning[key]) {
487
+ return;
488
+ }
489
+ this.sessionCloning[key] = true;
490
+ try {
491
+ const res = await api('clone-session', {
492
+ source: session.source,
493
+ sessionId: session.sessionId,
494
+ filePath: session.filePath
495
+ });
496
+ if (res.error) {
497
+ this.showMessage(res.error, 'error');
498
+ return;
499
+ }
500
+
501
+ this.showMessage('操作成功', 'success');
502
+ if (typeof this.invalidateSessionsUsageData === 'function') {
503
+ this.invalidateSessionsUsageData({ preserveList: true });
504
+ }
505
+ try {
506
+ await this.loadSessions();
507
+ if (res.sessionId) {
508
+ const matched = this.sessionsList.find(item => item.source === 'codex' && item.sessionId === res.sessionId);
509
+ if (matched) {
510
+ await this.selectSession(matched);
511
+ }
512
+ }
513
+ } catch (_) {
514
+ // The clone already succeeded remotely; keep the success result.
515
+ }
516
+ } catch (_) {
517
+ this.showMessage('克隆失败', 'error');
518
+ } finally {
519
+ this.sessionCloning[key] = false;
520
+ }
521
+ },
522
+
523
+ async deleteSession(session) {
524
+ if (!this.isDeleteAvailable(session)) {
525
+ this.showMessage('不支持此操作', 'error');
526
+ return;
527
+ }
528
+ const useTrash = this.sessionTrashEnabled !== false;
529
+ if (!useTrash && typeof this.requestConfirmDialog === 'function') {
530
+ const confirmed = await this.requestConfirmDialog({
531
+ title: '直接删除会话',
532
+ message: '关闭回收站后,删除会话将直接永久删除,且无法恢复。',
533
+ confirmText: '直接删除',
534
+ cancelText: '取消',
535
+ danger: true
536
+ });
537
+ if (!confirmed) {
538
+ return;
539
+ }
540
+ }
541
+ const key = this.getSessionExportKey(session);
542
+ if (this.sessionDeleting[key]) {
543
+ return;
544
+ }
545
+ this.sessionDeleting[key] = true;
546
+ try {
547
+ const action = useTrash ? 'trash-session' : 'delete-session';
548
+ const res = await api(action, {
549
+ source: session.source,
550
+ sessionId: session.sessionId,
551
+ filePath: session.filePath
552
+ });
553
+ if (!res || res.error) {
554
+ this.showMessage((res && res.error) || '删除失败', 'error');
555
+ return;
556
+ }
557
+ this.removeSessionPin(session);
558
+ if (useTrash) {
559
+ this.invalidateSessionTrashRequests();
560
+ this.showMessage('已移入回收站', 'success');
561
+ if (this.sessionTrashLoadedOnce) {
562
+ this.prependSessionTrashItem(this.buildSessionTrashItemFromSession(session, res), {
563
+ totalCount: res && res.totalCount !== undefined ? res.totalCount : undefined
564
+ });
565
+ } else {
566
+ this.sessionTrashTotalCount = this.normalizeSessionTrashTotalCount(
567
+ res && res.totalCount !== undefined
568
+ ? res.totalCount
569
+ : (this.normalizeSessionTrashTotalCount(this.sessionTrashTotalCount, this.sessionTrashItems) + 1),
570
+ this.sessionTrashItems
571
+ );
572
+ }
573
+ } else {
574
+ this.showMessage('已删除', 'success');
575
+ }
576
+ if (typeof this.invalidateSessionsUsageData === 'function') {
577
+ this.invalidateSessionsUsageData({ preserveList: true });
578
+ }
579
+ try {
580
+ await this.removeSessionFromCurrentList(session);
581
+ } catch (_) {
582
+ // The delete already succeeded remotely; keep the success result.
583
+ }
584
+ } catch (_) {
585
+ this.showMessage('删除失败', 'error');
586
+ } finally {
587
+ this.sessionDeleting[key] = false;
588
+ }
589
+ }
590
+ };
591
+ }