codexmate 0.0.21 → 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +390 -284
- package/README.zh.md +322 -0
- package/cli/agents-files.js +224 -162
- package/cli/archive-helpers.js +446 -446
- package/cli/auth-profiles.js +359 -359
- package/cli/builtin-proxy.js +1044 -580
- package/cli/claude-proxy.js +998 -998
- package/cli/config-bootstrap.js +384 -384
- package/cli/config-health.js +338 -338
- package/cli/openai-bridge.js +950 -0
- package/cli/openclaw-config.js +629 -629
- package/cli/session-usage.concurrent.js +28 -0
- package/cli/session-usage.js +112 -0
- package/cli/session-usage.models.js +176 -0
- package/cli/skills.js +1141 -1141
- package/cli/zip-commands.js +510 -510
- package/cli.js +13214 -13129
- package/lib/cli-file-utils.js +151 -151
- package/lib/cli-models-utils.js +419 -419
- package/lib/cli-network-utils.js +164 -164
- package/lib/cli-path-utils.js +69 -69
- package/lib/cli-session-utils.js +121 -121
- package/lib/cli-sessions.js +386 -386
- package/lib/cli-utils.js +155 -155
- package/lib/download-artifacts.js +77 -77
- package/lib/mcp-stdio.js +440 -440
- package/lib/task-orchestrator.js +869 -869
- package/lib/text-diff.js +303 -303
- package/lib/workflow-engine.js +340 -340
- package/package.json +74 -74
- package/res/json5.min.js +1 -1
- package/res/logo.png +0 -0
- package/res/vue.global.prod.js +13 -13
- package/web-ui/app.js +626 -530
- package/web-ui/index.html +34 -33
- package/web-ui/logic.agents-diff.mjs +386 -386
- package/web-ui/logic.claude.mjs +168 -168
- package/web-ui/logic.mjs +5 -5
- package/web-ui/logic.runtime.mjs +128 -124
- package/web-ui/logic.sessions.mjs +614 -581
- package/web-ui/modules/api.mjs +90 -90
- package/web-ui/modules/app.computed.dashboard.mjs +126 -113
- package/web-ui/modules/app.computed.index.mjs +17 -15
- package/web-ui/modules/app.computed.main-tabs.mjs +202 -195
- package/web-ui/modules/app.computed.session.mjs +653 -507
- package/web-ui/modules/app.constants.mjs +15 -15
- package/web-ui/modules/app.methods.agents.mjs +544 -493
- package/web-ui/modules/app.methods.claude-config.mjs +174 -174
- package/web-ui/modules/app.methods.codex-config.mjs +795 -640
- package/web-ui/modules/app.methods.index.mjs +92 -88
- package/web-ui/modules/app.methods.install.mjs +177 -149
- package/web-ui/modules/app.methods.navigation.mjs +662 -619
- package/web-ui/modules/app.methods.openclaw-core.mjs +814 -814
- package/web-ui/modules/app.methods.openclaw-editing.mjs +372 -372
- package/web-ui/modules/app.methods.openclaw-persist.mjs +369 -369
- package/web-ui/modules/app.methods.providers.mjs +404 -363
- package/web-ui/modules/app.methods.runtime.mjs +323 -323
- package/web-ui/modules/app.methods.session-actions.mjs +537 -520
- package/web-ui/modules/app.methods.session-browser.mjs +691 -626
- package/web-ui/modules/app.methods.session-timeline.mjs +448 -448
- package/web-ui/modules/app.methods.session-trash.mjs +422 -422
- package/web-ui/modules/app.methods.startup-claude.mjs +417 -412
- package/web-ui/modules/app.methods.task-orchestration.mjs +556 -471
- package/web-ui/modules/config-mode.computed.mjs +126 -126
- package/web-ui/modules/config-template-confirm-pref.mjs +33 -0
- package/web-ui/modules/i18n.mjs +1823 -0
- package/web-ui/modules/plugins.computed.mjs +3 -0
- package/web-ui/modules/plugins.methods.mjs +3 -0
- package/web-ui/modules/plugins.storage.mjs +11 -0
- package/web-ui/modules/sessions-filters-url.mjs +85 -0
- package/web-ui/modules/skills.computed.mjs +107 -107
- package/web-ui/modules/skills.methods.mjs +481 -481
- package/web-ui/partials/index/layout-footer.html +13 -13
- package/web-ui/partials/index/layout-header.html +461 -402
- package/web-ui/partials/index/modal-config-template-agents.html +175 -125
- package/web-ui/partials/index/modal-confirm-toast.html +32 -32
- package/web-ui/partials/index/modal-health-check.html +72 -72
- package/web-ui/partials/index/modal-openclaw-config.html +280 -280
- package/web-ui/partials/index/modal-skills.html +200 -184
- package/web-ui/partials/index/modals-basic.html +165 -156
- package/web-ui/partials/index/panel-config-claude.html +159 -126
- package/web-ui/partials/index/panel-config-codex.html +255 -237
- package/web-ui/partials/index/panel-config-openclaw.html +78 -78
- package/web-ui/partials/index/panel-docs.html +147 -130
- package/web-ui/partials/index/panel-market.html +174 -174
- package/web-ui/partials/index/panel-orchestration.html +388 -397
- package/web-ui/partials/index/panel-plugins.html +273 -0
- package/web-ui/partials/index/panel-sessions.html +298 -292
- package/web-ui/partials/index/panel-settings.html +258 -190
- package/web-ui/partials/index/panel-usage.html +353 -213
- package/web-ui/session-helpers.mjs +573 -559
- package/web-ui/source-bundle.cjs +233 -233
- package/web-ui/styles/base-theme.css +264 -271
- package/web-ui/styles/controls-forms.css +369 -360
- package/web-ui/styles/docs-panel.css +247 -182
- package/web-ui/styles/feedback.css +108 -108
- package/web-ui/styles/health-check-dialog.css +144 -144
- package/web-ui/styles/layout-shell.css +602 -376
- package/web-ui/styles/modals-core.css +464 -464
- package/web-ui/styles/navigation-panels.css +390 -348
- package/web-ui/styles/openclaw-structured.css +266 -266
- package/web-ui/styles/plugins-panel.css +523 -0
- package/web-ui/styles/responsive.css +456 -450
- package/web-ui/styles/sessions-list.css +400 -400
- package/web-ui/styles/sessions-preview.css +411 -411
- package/web-ui/styles/sessions-toolbar-trash.css +268 -243
- package/web-ui/styles/sessions-usage.css +879 -628
- package/web-ui/styles/settings-panel.css +166 -0
- package/web-ui/styles/skills-list.css +303 -296
- package/web-ui/styles/skills-market.css +406 -335
- package/web-ui/styles/task-orchestration.css +822 -776
- package/web-ui/styles/titles-cards.css +408 -408
- package/web-ui/styles.css +20 -18
- package/web-ui.html +17 -17
- package/README.en.md +0 -349
|
@@ -1,493 +1,544 @@
|
|
|
1
|
-
import {
|
|
2
|
-
buildAgentsDiffPreview,
|
|
3
|
-
buildAgentsDiffPreviewRequest,
|
|
4
|
-
isAgentsDiffPreviewPayloadTooLarge,
|
|
5
|
-
shouldApplyAgentsDiffPreviewResponse
|
|
6
|
-
} from '../logic.mjs';
|
|
7
|
-
|
|
8
|
-
function isValidOpenclawWorkspaceFileName(fileName) {
|
|
9
|
-
if (typeof fileName !== 'string') {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
const normalized = fileName.trim();
|
|
13
|
-
if (!normalized || !normalized.endsWith('.md')) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
if (normalized.startsWith('/') || normalized.includes('\\') || normalized.includes('/') || normalized.includes('..')) {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function issueLatestRequestToken(context, key) {
|
|
23
|
-
const token = (Number(context[key]) || 0) + 1;
|
|
24
|
-
context[key] = token;
|
|
25
|
-
return token;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function isLatestRequestToken(context, key, token) {
|
|
29
|
-
return !!context && context[key] === token;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function createAgentsMethods(options = {}) {
|
|
33
|
-
const {
|
|
34
|
-
api,
|
|
35
|
-
apiWithMeta
|
|
36
|
-
} = options;
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
async
|
|
40
|
-
this.setAgentsModalContext('
|
|
41
|
-
const requestToken = issueLatestRequestToken(this, '_agentsOpenRequestToken');
|
|
42
|
-
this.agentsLoading = true;
|
|
43
|
-
try {
|
|
44
|
-
const res = await api('get-
|
|
45
|
-
if (!isLatestRequestToken(this, '_agentsOpenRequestToken', requestToken)) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
if (res.error) {
|
|
49
|
-
this.showMessage(res.error, 'error');
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
this.agentsContent = res.content || '';
|
|
53
|
-
this.agentsOriginalContent = this.agentsContent;
|
|
54
|
-
this.agentsPath = res.path || '';
|
|
55
|
-
this.agentsExists = !!res.exists;
|
|
56
|
-
this.agentsLineEnding = res.lineEnding === '\r\n' ? '\r\n' : '\n';
|
|
57
|
-
this.resetAgentsDiffState();
|
|
58
|
-
this.showAgentsModal = true;
|
|
59
|
-
} catch (e) {
|
|
60
|
-
if (!isLatestRequestToken(this, '_agentsOpenRequestToken', requestToken)) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
this.showMessage('加载文件失败', 'error');
|
|
64
|
-
} finally {
|
|
65
|
-
if (isLatestRequestToken(this, '_agentsOpenRequestToken', requestToken)) {
|
|
66
|
-
this.agentsLoading = false;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
async
|
|
72
|
-
this.setAgentsModalContext('
|
|
73
|
-
const requestToken = issueLatestRequestToken(this, '_agentsOpenRequestToken');
|
|
74
|
-
this.agentsLoading = true;
|
|
75
|
-
try {
|
|
76
|
-
const res = await api('get-
|
|
77
|
-
if (!isLatestRequestToken(this, '_agentsOpenRequestToken', requestToken)) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
if (res.error) {
|
|
81
|
-
this.showMessage(res.error, 'error');
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
this.
|
|
88
|
-
this.
|
|
89
|
-
this.
|
|
90
|
-
this.
|
|
91
|
-
|
|
92
|
-
this
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
this
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
this
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const
|
|
153
|
-
this
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
this.
|
|
165
|
-
this.
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
this.
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
this.
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
this.
|
|
268
|
-
this.
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
this.
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
this.
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
this.
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
this.
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
this.
|
|
312
|
-
this.
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
this.
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
}
|
|
413
|
-
if (
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
if (
|
|
437
|
-
this.
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
this.
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
1
|
+
import {
|
|
2
|
+
buildAgentsDiffPreview,
|
|
3
|
+
buildAgentsDiffPreviewRequest,
|
|
4
|
+
isAgentsDiffPreviewPayloadTooLarge,
|
|
5
|
+
shouldApplyAgentsDiffPreviewResponse
|
|
6
|
+
} from '../logic.mjs';
|
|
7
|
+
|
|
8
|
+
function isValidOpenclawWorkspaceFileName(fileName) {
|
|
9
|
+
if (typeof fileName !== 'string') {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const normalized = fileName.trim();
|
|
13
|
+
if (!normalized || !normalized.endsWith('.md')) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
if (normalized.startsWith('/') || normalized.includes('\\') || normalized.includes('/') || normalized.includes('..')) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function issueLatestRequestToken(context, key) {
|
|
23
|
+
const token = (Number(context[key]) || 0) + 1;
|
|
24
|
+
context[key] = token;
|
|
25
|
+
return token;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function isLatestRequestToken(context, key, token) {
|
|
29
|
+
return !!context && context[key] === token;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function createAgentsMethods(options = {}) {
|
|
33
|
+
const {
|
|
34
|
+
api,
|
|
35
|
+
apiWithMeta
|
|
36
|
+
} = options;
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
async openClaudeMdEditor() {
|
|
40
|
+
this.setAgentsModalContext('claude-md');
|
|
41
|
+
const requestToken = issueLatestRequestToken(this, '_agentsOpenRequestToken');
|
|
42
|
+
this.agentsLoading = true;
|
|
43
|
+
try {
|
|
44
|
+
const res = await api('get-claude-md-file');
|
|
45
|
+
if (!isLatestRequestToken(this, '_agentsOpenRequestToken', requestToken)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (res.error) {
|
|
49
|
+
this.showMessage(res.error, 'error');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
this.agentsContent = res.content || '';
|
|
53
|
+
this.agentsOriginalContent = this.agentsContent;
|
|
54
|
+
this.agentsPath = res.path || '';
|
|
55
|
+
this.agentsExists = !!res.exists;
|
|
56
|
+
this.agentsLineEnding = res.lineEnding === '\r\n' ? '\r\n' : '\n';
|
|
57
|
+
this.resetAgentsDiffState();
|
|
58
|
+
this.showAgentsModal = true;
|
|
59
|
+
} catch (e) {
|
|
60
|
+
if (!isLatestRequestToken(this, '_agentsOpenRequestToken', requestToken)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
this.showMessage('加载文件失败', 'error');
|
|
64
|
+
} finally {
|
|
65
|
+
if (isLatestRequestToken(this, '_agentsOpenRequestToken', requestToken)) {
|
|
66
|
+
this.agentsLoading = false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
async openAgentsEditor() {
|
|
72
|
+
this.setAgentsModalContext('codex');
|
|
73
|
+
const requestToken = issueLatestRequestToken(this, '_agentsOpenRequestToken');
|
|
74
|
+
this.agentsLoading = true;
|
|
75
|
+
try {
|
|
76
|
+
const res = await api('get-agents-file');
|
|
77
|
+
if (!isLatestRequestToken(this, '_agentsOpenRequestToken', requestToken)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (res.error) {
|
|
81
|
+
this.showMessage(res.error, 'error');
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
this.agentsContent = res.content || '';
|
|
85
|
+
this.agentsOriginalContent = this.agentsContent;
|
|
86
|
+
this.agentsPath = res.path || '';
|
|
87
|
+
this.agentsExists = !!res.exists;
|
|
88
|
+
this.agentsLineEnding = res.lineEnding === '\r\n' ? '\r\n' : '\n';
|
|
89
|
+
this.resetAgentsDiffState();
|
|
90
|
+
this.showAgentsModal = true;
|
|
91
|
+
} catch (e) {
|
|
92
|
+
if (!isLatestRequestToken(this, '_agentsOpenRequestToken', requestToken)) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
this.showMessage('加载文件失败', 'error');
|
|
96
|
+
} finally {
|
|
97
|
+
if (isLatestRequestToken(this, '_agentsOpenRequestToken', requestToken)) {
|
|
98
|
+
this.agentsLoading = false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
async openOpenclawAgentsEditor() {
|
|
104
|
+
this.setAgentsModalContext('openclaw');
|
|
105
|
+
const requestToken = issueLatestRequestToken(this, '_agentsOpenRequestToken');
|
|
106
|
+
this.agentsLoading = true;
|
|
107
|
+
try {
|
|
108
|
+
const res = await api('get-openclaw-agents-file');
|
|
109
|
+
if (!isLatestRequestToken(this, '_agentsOpenRequestToken', requestToken)) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (res.error) {
|
|
113
|
+
this.showMessage(res.error, 'error');
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (res.configError) {
|
|
117
|
+
this.showMessage(`OpenClaw 配置解析失败,已使用默认 Workspace:${res.configError}`, 'error');
|
|
118
|
+
}
|
|
119
|
+
this.agentsContent = res.content || '';
|
|
120
|
+
this.agentsOriginalContent = this.agentsContent;
|
|
121
|
+
this.agentsPath = res.path || '';
|
|
122
|
+
this.agentsExists = !!res.exists;
|
|
123
|
+
this.agentsLineEnding = res.lineEnding === '\r\n' ? '\r\n' : '\n';
|
|
124
|
+
this.resetAgentsDiffState();
|
|
125
|
+
this.showAgentsModal = true;
|
|
126
|
+
} catch (e) {
|
|
127
|
+
if (!isLatestRequestToken(this, '_agentsOpenRequestToken', requestToken)) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
this.showMessage('加载文件失败', 'error');
|
|
131
|
+
} finally {
|
|
132
|
+
if (isLatestRequestToken(this, '_agentsOpenRequestToken', requestToken)) {
|
|
133
|
+
this.agentsLoading = false;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
async openOpenclawWorkspaceEditor() {
|
|
139
|
+
const fileName = (this.openclawWorkspaceFileName || '').trim();
|
|
140
|
+
if (!fileName) {
|
|
141
|
+
this.showMessage('请输入文件名', 'error');
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (!isValidOpenclawWorkspaceFileName(fileName)) {
|
|
145
|
+
this.showMessage('仅支持 OpenClaw Workspace 内的 `.md` 文件', 'error');
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
this.setAgentsModalContext('openclaw-workspace', { fileName });
|
|
149
|
+
const requestToken = issueLatestRequestToken(this, '_agentsOpenRequestToken');
|
|
150
|
+
this.agentsLoading = true;
|
|
151
|
+
try {
|
|
152
|
+
const res = await api('get-openclaw-workspace-file', { fileName });
|
|
153
|
+
if (!isLatestRequestToken(this, '_agentsOpenRequestToken', requestToken)) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (res.error) {
|
|
157
|
+
this.showMessage(res.error, 'error');
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (res.configError) {
|
|
161
|
+
this.showMessage(`OpenClaw 配置解析失败,已使用默认 Workspace:${res.configError}`, 'error');
|
|
162
|
+
}
|
|
163
|
+
this.agentsContent = res.content || '';
|
|
164
|
+
this.agentsOriginalContent = this.agentsContent;
|
|
165
|
+
this.agentsPath = res.path || '';
|
|
166
|
+
this.agentsExists = !!res.exists;
|
|
167
|
+
this.agentsLineEnding = res.lineEnding === '\r\n' ? '\r\n' : '\n';
|
|
168
|
+
this.resetAgentsDiffState();
|
|
169
|
+
this.showAgentsModal = true;
|
|
170
|
+
} catch (e) {
|
|
171
|
+
if (!isLatestRequestToken(this, '_agentsOpenRequestToken', requestToken)) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
this.showMessage('加载文件失败', 'error');
|
|
175
|
+
} finally {
|
|
176
|
+
if (isLatestRequestToken(this, '_agentsOpenRequestToken', requestToken)) {
|
|
177
|
+
this.agentsLoading = false;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
|
|
182
|
+
setAgentsModalContext(context, options = {}) {
|
|
183
|
+
const t = typeof this.t === 'function' ? this.t : null;
|
|
184
|
+
const tr = (key, fallback, params = null) => (t ? t(key, params) : fallback);
|
|
185
|
+
if (context === 'claude-md') {
|
|
186
|
+
this.agentsContext = 'claude-md';
|
|
187
|
+
this.agentsWorkspaceFileName = '';
|
|
188
|
+
this.agentsModalTitle = tr('modal.agents.title.claudeMd', 'CLAUDE.md 编辑器');
|
|
189
|
+
this.agentsModalHint = tr('modal.agents.hint.claudeMd', '保存后会写入 ~/.claude/CLAUDE.md。');
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (context === 'openclaw-workspace') {
|
|
193
|
+
const fileName = (options.fileName || this.openclawWorkspaceFileName || 'AGENTS.md').trim();
|
|
194
|
+
this.agentsContext = 'openclaw-workspace';
|
|
195
|
+
this.agentsWorkspaceFileName = fileName;
|
|
196
|
+
this.agentsModalTitle = `OpenClaw 工作区文件: ${fileName}`;
|
|
197
|
+
this.agentsModalHint = `保存后会写入 OpenClaw Workspace 下的 ${fileName}。`;
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
this.agentsContext = context === 'openclaw' ? 'openclaw' : 'codex';
|
|
201
|
+
if (this.agentsContext === 'openclaw') {
|
|
202
|
+
this.agentsModalTitle = tr('modal.agents.title.openclaw', 'OpenClaw AGENTS.md 编辑器');
|
|
203
|
+
this.agentsModalHint = tr('modal.agents.hint.openclaw', '保存后会写入 OpenClaw Workspace 下的 AGENTS.md。');
|
|
204
|
+
} else {
|
|
205
|
+
this.agentsModalTitle = tr('modal.agents.title.default', 'AGENTS.md 编辑器');
|
|
206
|
+
this.agentsModalHint = tr('modal.agents.hint.default', '保存后会写入目标 AGENTS.md(与 config.toml 同级)。');
|
|
207
|
+
}
|
|
208
|
+
this.agentsWorkspaceFileName = '';
|
|
209
|
+
},
|
|
210
|
+
|
|
211
|
+
resetAgentsDiffState() {
|
|
212
|
+
this.agentsDiffVisible = false;
|
|
213
|
+
this.agentsDiffLoading = false;
|
|
214
|
+
this.agentsDiffError = '';
|
|
215
|
+
this.agentsDiffLines = [];
|
|
216
|
+
this.agentsDiffStats = {
|
|
217
|
+
added: 0,
|
|
218
|
+
removed: 0,
|
|
219
|
+
unchanged: 0
|
|
220
|
+
};
|
|
221
|
+
this.agentsDiffTruncated = false;
|
|
222
|
+
this.agentsDiffHasChangesValue = false;
|
|
223
|
+
this.agentsDiffFingerprint = '';
|
|
224
|
+
this._agentsDiffPreviewRequestToken = null;
|
|
225
|
+
},
|
|
226
|
+
handleGlobalKeydown(event) {
|
|
227
|
+
if (!event || event.key !== 'Escape') {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
if (this.showConfirmDialog) {
|
|
231
|
+
event.preventDefault();
|
|
232
|
+
event.stopPropagation();
|
|
233
|
+
this.resolveConfirmDialog(false);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
if (!this.showAgentsModal) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
event.preventDefault();
|
|
240
|
+
event.stopPropagation();
|
|
241
|
+
if (this.agentsSaving || this.agentsDiffLoading) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
if (this.agentsDiffVisible) {
|
|
245
|
+
this.resetAgentsDiffState();
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
this.closeAgentsModal();
|
|
249
|
+
},
|
|
250
|
+
hasPendingAgentsDraft() {
|
|
251
|
+
if (!this.showAgentsModal || this.agentsLoading) {
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
return !!this.agentsSaving || this.hasAgentsContentChanged() || this.agentsDiffVisible;
|
|
255
|
+
},
|
|
256
|
+
handleBeforeUnload(event) {
|
|
257
|
+
if (!this.hasPendingAgentsDraft()) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
if (event && typeof event.preventDefault === 'function') {
|
|
261
|
+
event.preventDefault();
|
|
262
|
+
event.returnValue = '';
|
|
263
|
+
}
|
|
264
|
+
return '';
|
|
265
|
+
},
|
|
266
|
+
hasAgentsContentChanged() {
|
|
267
|
+
const original = typeof this.agentsOriginalContent === 'string' ? this.agentsOriginalContent : '';
|
|
268
|
+
const current = typeof this.agentsContent === 'string' ? this.agentsContent : '';
|
|
269
|
+
return original !== current;
|
|
270
|
+
},
|
|
271
|
+
requestConfirmDialog(options = {}) {
|
|
272
|
+
if (typeof this.confirmDialogResolver === 'function') {
|
|
273
|
+
this.confirmDialogResolver(false);
|
|
274
|
+
}
|
|
275
|
+
const confirmDisabled = options.confirmDisabled;
|
|
276
|
+
const t = typeof this.t === 'function' ? this.t : null;
|
|
277
|
+
this.confirmDialogTitle = typeof options.title === 'string' && options.title.trim()
|
|
278
|
+
? options.title.trim()
|
|
279
|
+
: (t ? t('confirm.title.default') : '请确认操作');
|
|
280
|
+
this.confirmDialogMessage = typeof options.message === 'string' ? options.message : '';
|
|
281
|
+
this.confirmDialogConfirmText = typeof options.confirmText === 'string' && options.confirmText.trim()
|
|
282
|
+
? options.confirmText.trim()
|
|
283
|
+
: (t ? t('confirm.ok') : '确认');
|
|
284
|
+
this.confirmDialogCancelText = typeof options.cancelText === 'string' && options.cancelText.trim()
|
|
285
|
+
? options.cancelText.trim()
|
|
286
|
+
: (t ? t('confirm.cancel') : '取消');
|
|
287
|
+
this.confirmDialogDanger = !!options.danger;
|
|
288
|
+
this.confirmDialogConfirmDisabled = typeof confirmDisabled === 'function' ? false : !!confirmDisabled;
|
|
289
|
+
this.confirmDialogDisableWhen = typeof confirmDisabled === 'function' ? confirmDisabled : null;
|
|
290
|
+
this.showConfirmDialog = true;
|
|
291
|
+
return new Promise((resolve) => {
|
|
292
|
+
this.confirmDialogResolver = resolve;
|
|
293
|
+
});
|
|
294
|
+
},
|
|
295
|
+
isConfirmDialogDisabled() {
|
|
296
|
+
if (typeof this.confirmDialogDisableWhen === 'function') {
|
|
297
|
+
try {
|
|
298
|
+
return !!this.confirmDialogDisableWhen.call(this);
|
|
299
|
+
} catch (_) {
|
|
300
|
+
return true;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return !!this.confirmDialogConfirmDisabled;
|
|
304
|
+
},
|
|
305
|
+
resolveConfirmDialog(confirmed) {
|
|
306
|
+
const resolver = typeof this.confirmDialogResolver === 'function'
|
|
307
|
+
? this.confirmDialogResolver
|
|
308
|
+
: null;
|
|
309
|
+
this.showConfirmDialog = false;
|
|
310
|
+
this.confirmDialogTitle = '';
|
|
311
|
+
this.confirmDialogMessage = '';
|
|
312
|
+
if (typeof this.t === 'function') {
|
|
313
|
+
this.confirmDialogConfirmText = this.t('confirm.ok');
|
|
314
|
+
this.confirmDialogCancelText = this.t('confirm.cancel');
|
|
315
|
+
} else {
|
|
316
|
+
this.confirmDialogConfirmText = '确认';
|
|
317
|
+
this.confirmDialogCancelText = '取消';
|
|
318
|
+
}
|
|
319
|
+
this.confirmDialogDanger = false;
|
|
320
|
+
this.confirmDialogConfirmDisabled = false;
|
|
321
|
+
this.confirmDialogDisableWhen = null;
|
|
322
|
+
this.confirmDialogResolver = null;
|
|
323
|
+
if (resolver) {
|
|
324
|
+
resolver(!!confirmed);
|
|
325
|
+
}
|
|
326
|
+
},
|
|
327
|
+
closeConfirmDialog() {
|
|
328
|
+
this.resolveConfirmDialog(false);
|
|
329
|
+
},
|
|
330
|
+
onAgentsContentInput() {
|
|
331
|
+
if (this.agentsDiffVisible || this.agentsDiffLines.length) {
|
|
332
|
+
this.resetAgentsDiffState();
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
buildAgentsDiffFingerprint() {
|
|
336
|
+
const context = this.agentsContext || 'codex';
|
|
337
|
+
const fileName = context === 'openclaw-workspace'
|
|
338
|
+
? (this.agentsWorkspaceFileName || '')
|
|
339
|
+
: '';
|
|
340
|
+
const lineEnding = this.agentsLineEnding || '\n';
|
|
341
|
+
const content = typeof this.agentsContent === 'string' ? this.agentsContent : '';
|
|
342
|
+
const original = typeof this.agentsOriginalContent === 'string' ? this.agentsOriginalContent : '';
|
|
343
|
+
return `${context}::${fileName}::${lineEnding}::${content.length}::${content}::${original.length}::${original}`;
|
|
344
|
+
},
|
|
345
|
+
async prepareAgentsDiff() {
|
|
346
|
+
const requestFingerprint = this.buildAgentsDiffFingerprint();
|
|
347
|
+
const requestToken = Symbol('agents-diff-preview');
|
|
348
|
+
this._agentsDiffPreviewRequestToken = requestToken;
|
|
349
|
+
this.agentsDiffVisible = true;
|
|
350
|
+
this.agentsDiffLoading = true;
|
|
351
|
+
this.agentsDiffError = '';
|
|
352
|
+
this.agentsDiffLines = [];
|
|
353
|
+
this.agentsDiffStats = {
|
|
354
|
+
added: 0,
|
|
355
|
+
removed: 0,
|
|
356
|
+
unchanged: 0
|
|
357
|
+
};
|
|
358
|
+
this.agentsDiffTruncated = false;
|
|
359
|
+
this.agentsDiffHasChangesValue = false;
|
|
360
|
+
try {
|
|
361
|
+
const shouldApplyPreviewState = () => shouldApplyAgentsDiffPreviewResponse({
|
|
362
|
+
isVisible: this.agentsDiffVisible,
|
|
363
|
+
requestToken,
|
|
364
|
+
activeRequestToken: this._agentsDiffPreviewRequestToken,
|
|
365
|
+
requestFingerprint,
|
|
366
|
+
currentFingerprint: this.buildAgentsDiffFingerprint()
|
|
367
|
+
});
|
|
368
|
+
const applyPreviewState = (diff) => {
|
|
369
|
+
if (!shouldApplyPreviewState()) {
|
|
370
|
+
return false;
|
|
371
|
+
}
|
|
372
|
+
const normalizedDiff = diff && typeof diff === 'object' ? diff : {};
|
|
373
|
+
const rawLines = Array.isArray(normalizedDiff.lines) ? normalizedDiff.lines : [];
|
|
374
|
+
this.agentsDiffLines = rawLines.filter(line => line && line.type);
|
|
375
|
+
this.agentsDiffTruncated = !!normalizedDiff.truncated;
|
|
376
|
+
this.agentsDiffHasChangesValue = !!normalizedDiff.hasChanges;
|
|
377
|
+
if (normalizedDiff.stats && typeof normalizedDiff.stats === 'object') {
|
|
378
|
+
this.agentsDiffStats = {
|
|
379
|
+
added: Number(normalizedDiff.stats.added || 0),
|
|
380
|
+
removed: Number(normalizedDiff.stats.removed || 0),
|
|
381
|
+
unchanged: Number(normalizedDiff.stats.unchanged || 0)
|
|
382
|
+
};
|
|
383
|
+
} else {
|
|
384
|
+
const stats = { added: 0, removed: 0, unchanged: 0 };
|
|
385
|
+
for (const line of this.agentsDiffLines) {
|
|
386
|
+
if (line && line.type === 'add') stats.added += 1;
|
|
387
|
+
else if (line && line.type === 'del') stats.removed += 1;
|
|
388
|
+
else stats.unchanged += 1;
|
|
389
|
+
}
|
|
390
|
+
this.agentsDiffStats = stats;
|
|
391
|
+
}
|
|
392
|
+
this.agentsDiffFingerprint = requestFingerprint;
|
|
393
|
+
return true;
|
|
394
|
+
};
|
|
395
|
+
const previewRequest = buildAgentsDiffPreviewRequest({
|
|
396
|
+
baseContent: this.agentsOriginalContent,
|
|
397
|
+
content: this.agentsContent,
|
|
398
|
+
lineEnding: this.agentsLineEnding,
|
|
399
|
+
context: this.agentsContext,
|
|
400
|
+
fileName: this.agentsWorkspaceFileName
|
|
401
|
+
});
|
|
402
|
+
if (previewRequest.exceedsBodyLimit) {
|
|
403
|
+
applyPreviewState(buildAgentsDiffPreview({
|
|
404
|
+
baseContent: this.agentsOriginalContent,
|
|
405
|
+
content: this.agentsContent
|
|
406
|
+
}));
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
const res = await apiWithMeta('preview-agents-diff', previewRequest.params);
|
|
410
|
+
if (!shouldApplyPreviewState()) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
if (res.error) {
|
|
414
|
+
if (isAgentsDiffPreviewPayloadTooLarge(res)) {
|
|
415
|
+
applyPreviewState(buildAgentsDiffPreview({
|
|
416
|
+
baseContent: this.agentsOriginalContent,
|
|
417
|
+
content: this.agentsContent
|
|
418
|
+
}));
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
this.agentsDiffError = res.error;
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
applyPreviewState(res.diff);
|
|
425
|
+
} catch (e) {
|
|
426
|
+
if (shouldApplyAgentsDiffPreviewResponse({
|
|
427
|
+
isVisible: this.agentsDiffVisible,
|
|
428
|
+
requestToken,
|
|
429
|
+
activeRequestToken: this._agentsDiffPreviewRequestToken,
|
|
430
|
+
requestFingerprint,
|
|
431
|
+
currentFingerprint: this.buildAgentsDiffFingerprint()
|
|
432
|
+
})) {
|
|
433
|
+
this.agentsDiffError = '生成差异失败';
|
|
434
|
+
}
|
|
435
|
+
} finally {
|
|
436
|
+
if (this._agentsDiffPreviewRequestToken === requestToken) {
|
|
437
|
+
this.agentsDiffLoading = false;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
},
|
|
441
|
+
|
|
442
|
+
async closeAgentsModal(options = {}) {
|
|
443
|
+
const force = !!(options && options.force);
|
|
444
|
+
if (!force && (this.agentsSaving || this.agentsDiffLoading)) {
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
const shouldConfirmClose = !force
|
|
448
|
+
&& this.hasPendingAgentsDraft();
|
|
449
|
+
if (shouldConfirmClose) {
|
|
450
|
+
const message = this.agentsDiffVisible
|
|
451
|
+
? '当前处于差异预览模式,改动尚未保存。确认放弃改动并关闭吗?'
|
|
452
|
+
: '存在未保存改动,确认放弃改动并关闭吗?(关闭页面或应用也会丢失改动)';
|
|
453
|
+
const confirmed = await this.requestConfirmDialog({
|
|
454
|
+
title: '放弃未保存改动',
|
|
455
|
+
message,
|
|
456
|
+
confirmText: '放弃并关闭',
|
|
457
|
+
cancelText: '继续编辑',
|
|
458
|
+
danger: true
|
|
459
|
+
});
|
|
460
|
+
if (!confirmed) {
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
issueLatestRequestToken(this, '_agentsOpenRequestToken');
|
|
465
|
+
this.agentsLoading = false;
|
|
466
|
+
this.showAgentsModal = false;
|
|
467
|
+
this.agentsContent = '';
|
|
468
|
+
this.agentsOriginalContent = '';
|
|
469
|
+
this.agentsPath = '';
|
|
470
|
+
this.agentsExists = false;
|
|
471
|
+
this.agentsLineEnding = '\n';
|
|
472
|
+
this.agentsSaving = false;
|
|
473
|
+
this.agentsWorkspaceFileName = '';
|
|
474
|
+
this.resetAgentsDiffState();
|
|
475
|
+
this.setAgentsModalContext('codex');
|
|
476
|
+
},
|
|
477
|
+
|
|
478
|
+
async applyAgentsContent() {
|
|
479
|
+
if (this.agentsSaving) {
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
if (!this.agentsDiffVisible) {
|
|
483
|
+
if (!this.hasAgentsContentChanged()) {
|
|
484
|
+
this.showMessage('未检测到改动', 'info');
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
await this.prepareAgentsDiff();
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
if (this.agentsDiffLoading) {
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
if (this.agentsDiffError) {
|
|
494
|
+
this.showMessage(this.agentsDiffError, 'error');
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
const fingerprint = this.buildAgentsDiffFingerprint();
|
|
498
|
+
if (this.agentsDiffFingerprint !== fingerprint) {
|
|
499
|
+
await this.prepareAgentsDiff();
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
if (!this.agentsDiffHasChanges) {
|
|
503
|
+
this.showMessage('未检测到改动', 'info');
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
if (this.agentsContext === 'openclaw-workspace' && !isValidOpenclawWorkspaceFileName(this.agentsWorkspaceFileName)) {
|
|
507
|
+
this.showMessage('仅支持 OpenClaw Workspace 内的 `.md` 文件', 'error');
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
this.agentsSaving = true;
|
|
511
|
+
try {
|
|
512
|
+
let action = 'apply-agents-file';
|
|
513
|
+
const params = {
|
|
514
|
+
content: this.agentsContent,
|
|
515
|
+
lineEnding: this.agentsLineEnding
|
|
516
|
+
};
|
|
517
|
+
if (this.agentsContext === 'claude-md') {
|
|
518
|
+
action = 'apply-claude-md-file';
|
|
519
|
+
} else if (this.agentsContext === 'openclaw') {
|
|
520
|
+
action = 'apply-openclaw-agents-file';
|
|
521
|
+
} else if (this.agentsContext === 'openclaw-workspace') {
|
|
522
|
+
action = 'apply-openclaw-workspace-file';
|
|
523
|
+
params.fileName = this.agentsWorkspaceFileName;
|
|
524
|
+
}
|
|
525
|
+
const res = await api(action, params);
|
|
526
|
+
if (res.error) {
|
|
527
|
+
this.showMessage(res.error, 'error');
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
const successLabel = this.agentsContext === 'openclaw-workspace'
|
|
531
|
+
? `工作区文件已保存${this.agentsWorkspaceFileName ? `: ${this.agentsWorkspaceFileName}` : ''}`
|
|
532
|
+
: (this.agentsContext === 'claude-md'
|
|
533
|
+
? 'CLAUDE.md 已保存'
|
|
534
|
+
: (this.agentsContext === 'openclaw' ? 'OpenClaw AGENTS.md 已保存' : 'AGENTS.md 已保存'));
|
|
535
|
+
this.showMessage(successLabel, 'success');
|
|
536
|
+
this.closeAgentsModal({ force: true });
|
|
537
|
+
} catch (e) {
|
|
538
|
+
this.showMessage('保存失败', 'error');
|
|
539
|
+
} finally {
|
|
540
|
+
this.agentsSaving = false;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
}
|