codexmate 0.0.39 → 0.0.41

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