codexmate 0.0.30 → 0.0.32

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