codexmate 0.0.28 → 0.0.29

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 (142) hide show
  1. package/README.md +421 -421
  2. package/README.zh.md +354 -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 -1620
  7. package/cli/claude-proxy.js +1022 -1022
  8. package/cli/config-bootstrap.js +384 -384
  9. package/cli/config-health.js +338 -338
  10. package/cli/doctor-core.js +903 -903
  11. package/cli/import-skills-url.js +356 -356
  12. package/cli/openai-bridge.js +1576 -1489
  13. package/cli/openclaw-config.js +629 -629
  14. package/cli/session-convert-args.js +65 -65
  15. package/cli/session-convert-io.js +82 -82
  16. package/cli/session-convert.js +43 -43
  17. package/cli/session-usage.concurrent.js +28 -28
  18. package/cli/session-usage.js +118 -118
  19. package/cli/session-usage.models.js +176 -176
  20. package/cli/skills.js +1141 -1141
  21. package/cli/zip-commands.js +510 -510
  22. package/cli.js +15340 -15264
  23. package/lib/automation.js +404 -404
  24. package/lib/cli-file-utils.js +151 -151
  25. package/lib/cli-models-utils.js +440 -440
  26. package/lib/cli-network-utils.js +190 -190
  27. package/lib/cli-path-utils.js +85 -85
  28. package/lib/cli-session-utils.js +121 -121
  29. package/lib/cli-sessions.js +417 -417
  30. package/lib/cli-utils.js +155 -155
  31. package/lib/cli-webhook.js +126 -0
  32. package/lib/download-artifacts.js +92 -92
  33. package/lib/mcp-stdio.js +453 -453
  34. package/lib/task-orchestrator.js +869 -869
  35. package/lib/text-diff.js +303 -303
  36. package/lib/workflow-engine.js +340 -340
  37. package/package.json +76 -76
  38. package/plugins/README.md +20 -20
  39. package/plugins/README.zh-CN.md +20 -20
  40. package/plugins/prompt-templates/comment-polish/index.mjs +25 -25
  41. package/plugins/prompt-templates/computed.mjs +253 -253
  42. package/plugins/prompt-templates/index.mjs +8 -8
  43. package/plugins/prompt-templates/manifest.mjs +15 -15
  44. package/plugins/prompt-templates/methods.mjs +553 -553
  45. package/plugins/prompt-templates/overview.mjs +91 -91
  46. package/plugins/prompt-templates/ownership.mjs +19 -19
  47. package/plugins/prompt-templates/rule-ack/index.mjs +21 -21
  48. package/plugins/prompt-templates/storage.mjs +64 -64
  49. package/plugins/registry.mjs +16 -16
  50. package/web-ui/app.js +639 -625
  51. package/web-ui/index.html +36 -35
  52. package/web-ui/logic.agents-diff.mjs +386 -386
  53. package/web-ui/logic.claude.mjs +168 -168
  54. package/web-ui/logic.codex.mjs +69 -56
  55. package/web-ui/logic.mjs +5 -5
  56. package/web-ui/logic.runtime.mjs +128 -128
  57. package/web-ui/logic.session-convert.mjs +70 -70
  58. package/web-ui/logic.sessions.mjs +765 -765
  59. package/web-ui/modules/api.mjs +90 -90
  60. package/web-ui/modules/app.computed.dashboard.mjs +225 -225
  61. package/web-ui/modules/app.computed.index.mjs +17 -17
  62. package/web-ui/modules/app.computed.main-tabs.mjs +205 -205
  63. package/web-ui/modules/app.computed.session.mjs +999 -994
  64. package/web-ui/modules/app.constants.mjs +15 -15
  65. package/web-ui/modules/app.methods.agents.mjs +632 -632
  66. package/web-ui/modules/app.methods.claude-config.mjs +200 -190
  67. package/web-ui/modules/app.methods.codex-config.mjs +892 -892
  68. package/web-ui/modules/app.methods.index.mjs +94 -92
  69. package/web-ui/modules/app.methods.install.mjs +205 -205
  70. package/web-ui/modules/app.methods.navigation.mjs +761 -743
  71. package/web-ui/modules/app.methods.openclaw-core.mjs +814 -814
  72. package/web-ui/modules/app.methods.openclaw-editing.mjs +372 -372
  73. package/web-ui/modules/app.methods.openclaw-persist.mjs +369 -369
  74. package/web-ui/modules/app.methods.providers.mjs +493 -412
  75. package/web-ui/modules/app.methods.runtime.mjs +345 -345
  76. package/web-ui/modules/app.methods.session-actions.mjs +593 -593
  77. package/web-ui/modules/app.methods.session-browser.mjs +984 -984
  78. package/web-ui/modules/app.methods.session-timeline.mjs +479 -479
  79. package/web-ui/modules/app.methods.session-trash.mjs +438 -439
  80. package/web-ui/modules/app.methods.startup-claude.mjs +533 -533
  81. package/web-ui/modules/app.methods.task-orchestration.mjs +556 -556
  82. package/web-ui/modules/app.methods.webhook.mjs +79 -0
  83. package/web-ui/modules/config-mode.computed.mjs +124 -124
  84. package/web-ui/modules/config-template-confirm-pref.mjs +33 -33
  85. package/web-ui/modules/i18n.dict.mjs +3131 -2109
  86. package/web-ui/modules/i18n.mjs +62 -56
  87. package/web-ui/modules/plugins.computed.mjs +3 -3
  88. package/web-ui/modules/plugins.methods.mjs +3 -3
  89. package/web-ui/modules/plugins.storage.mjs +11 -11
  90. package/web-ui/modules/provider-url-display.mjs +17 -17
  91. package/web-ui/modules/sessions-filters-url.mjs +85 -85
  92. package/web-ui/modules/skills.computed.mjs +107 -107
  93. package/web-ui/modules/skills.methods.mjs +481 -481
  94. package/web-ui/partials/index/layout-footer.html +13 -13
  95. package/web-ui/partials/index/layout-header.html +500 -475
  96. package/web-ui/partials/index/modal-config-template-agents.html +174 -174
  97. package/web-ui/partials/index/modal-confirm-toast.html +32 -32
  98. package/web-ui/partials/index/modal-health-check.html +45 -45
  99. package/web-ui/partials/index/modal-openclaw-config.html +280 -280
  100. package/web-ui/partials/index/modal-skills.html +200 -200
  101. package/web-ui/partials/index/modals-basic.html +162 -165
  102. package/web-ui/partials/index/panel-config-claude.html +194 -188
  103. package/web-ui/partials/index/panel-config-codex.html +323 -312
  104. package/web-ui/partials/index/panel-config-openclaw.html +83 -83
  105. package/web-ui/partials/index/panel-dashboard.html +186 -186
  106. package/web-ui/partials/index/panel-docs.html +147 -147
  107. package/web-ui/partials/index/panel-market.html +177 -177
  108. package/web-ui/partials/index/panel-orchestration.html +391 -391
  109. package/web-ui/partials/index/panel-plugins.html +253 -253
  110. package/web-ui/partials/index/panel-sessions.html +316 -316
  111. package/web-ui/partials/index/panel-settings.html +190 -253
  112. package/web-ui/partials/index/panel-trash.html +88 -0
  113. package/web-ui/partials/index/panel-usage.html +371 -371
  114. package/web-ui/res/json5.min.js +1 -1
  115. package/web-ui/res/vue.global.prod.js +13 -13
  116. package/web-ui/session-helpers.mjs +576 -576
  117. package/web-ui/source-bundle.cjs +233 -233
  118. package/web-ui/styles/base-theme.css +281 -281
  119. package/web-ui/styles/controls-forms.css +422 -422
  120. package/web-ui/styles/dashboard.css +274 -274
  121. package/web-ui/styles/docs-panel.css +271 -247
  122. package/web-ui/styles/feedback.css +108 -108
  123. package/web-ui/styles/health-check-dialog.css +144 -144
  124. package/web-ui/styles/layout-shell.css +626 -606
  125. package/web-ui/styles/modals-core.css +466 -466
  126. package/web-ui/styles/navigation-panels.css +391 -391
  127. package/web-ui/styles/openclaw-structured.css +266 -266
  128. package/web-ui/styles/plugins-panel.css +523 -523
  129. package/web-ui/styles/responsive.css +454 -454
  130. package/web-ui/styles/sessions-list.css +419 -419
  131. package/web-ui/styles/sessions-preview.css +411 -411
  132. package/web-ui/styles/sessions-toolbar-trash.css +330 -330
  133. package/web-ui/styles/sessions-usage.css +1040 -1040
  134. package/web-ui/styles/settings-panel.css +349 -185
  135. package/web-ui/styles/skills-list.css +303 -303
  136. package/web-ui/styles/skills-market.css +406 -406
  137. package/web-ui/styles/task-orchestration.css +822 -822
  138. package/web-ui/styles/titles-cards.css +472 -472
  139. package/web-ui/styles/trash-panel.css +90 -0
  140. package/web-ui/styles/webhook.css +81 -0
  141. package/web-ui/styles.css +23 -21
  142. package/web-ui.html +17 -17
@@ -1,593 +1,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
- 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
+ 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
+ }