codexmate 0.0.21 → 0.0.22
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 +389 -284
- package/README.zh.md +321 -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 +575 -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 +198 -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 +161 -149
- package/web-ui/modules/app.methods.navigation.mjs +619 -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 +626 -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 +405 -412
- package/web-ui/modules/app.methods.task-orchestration.mjs +471 -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 +1609 -0
- package/web-ui/modules/plugins.computed.mjs +220 -0
- package/web-ui/modules/plugins.methods.mjs +620 -0
- package/web-ui/modules/plugins.storage.mjs +37 -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 +138 -126
- package/web-ui/partials/index/panel-config-codex.html +234 -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 +397 -397
- package/web-ui/partials/index/panel-plugins.html +243 -0
- package/web-ui/partials/index/panel-sessions.html +292 -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 +362 -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 +596 -376
- package/web-ui/styles/modals-core.css +464 -464
- package/web-ui/styles/navigation-panels.css +382 -348
- package/web-ui/styles/openclaw-structured.css +266 -266
- package/web-ui/styles/plugins-panel.css +518 -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 +851 -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 +396 -335
- package/web-ui/styles/task-orchestration.css +776 -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,471 +1,471 @@
|
|
|
1
|
-
function createDefaultTaskOrchestrationState() {
|
|
2
|
-
return {
|
|
3
|
-
loading: false,
|
|
4
|
-
planning: false,
|
|
5
|
-
running: false,
|
|
6
|
-
queueAdding: false,
|
|
7
|
-
queueStarting: false,
|
|
8
|
-
retrying: false,
|
|
9
|
-
target: '',
|
|
10
|
-
title: '',
|
|
11
|
-
notes: '',
|
|
12
|
-
followUpsText: '',
|
|
13
|
-
workflowIdsText: '',
|
|
14
|
-
selectedEngine: 'codex',
|
|
15
|
-
allowWrite: false,
|
|
16
|
-
dryRun: false,
|
|
17
|
-
concurrency: 2,
|
|
18
|
-
autoFixRounds: 1,
|
|
19
|
-
plan: null,
|
|
20
|
-
planIssues: [],
|
|
21
|
-
planWarnings: [],
|
|
22
|
-
overviewWarnings: [],
|
|
23
|
-
workflows: [],
|
|
24
|
-
queue: [],
|
|
25
|
-
runs: [],
|
|
26
|
-
selectedRunId: '',
|
|
27
|
-
workspaceTab: 'queue',
|
|
28
|
-
selectedRunDetail: null,
|
|
29
|
-
selectedRunLoading: false,
|
|
30
|
-
selectedRunError: '',
|
|
31
|
-
detailRequestToken: 0,
|
|
32
|
-
lastLoadedAt: '',
|
|
33
|
-
lastError: ''
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function normalizeLines(text) {
|
|
38
|
-
return String(text || '')
|
|
39
|
-
.split(/\r?\n/g)
|
|
40
|
-
.map((item) => item.trim())
|
|
41
|
-
.filter(Boolean);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function normalizePositiveInteger(value, fallback, min = 1, max = 8) {
|
|
45
|
-
const numeric = Number.parseInt(String(value), 10);
|
|
46
|
-
if (!Number.isFinite(numeric)) {
|
|
47
|
-
return fallback;
|
|
48
|
-
}
|
|
49
|
-
return Math.min(max, Math.max(min, Math.floor(numeric)));
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function normalizeTaskStatusTone(status) {
|
|
53
|
-
const normalized = String(status || '').trim().toLowerCase();
|
|
54
|
-
if (normalized === 'success' || normalized === 'completed') return 'success';
|
|
55
|
-
if (normalized === 'failed' || normalized === 'blocked' || normalized === 'cancelled') return 'error';
|
|
56
|
-
if (normalized === 'running' || normalized === 'queued') return 'warn';
|
|
57
|
-
return 'neutral';
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function isActiveStatus(status) {
|
|
61
|
-
const normalized = String(status || '').trim().toLowerCase();
|
|
62
|
-
return normalized === 'running' || normalized === 'queued';
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function createTaskOrchestrationMethods(options = {}) {
|
|
66
|
-
const { api } = options;
|
|
67
|
-
|
|
68
|
-
return {
|
|
69
|
-
ensureTaskOrchestrationState() {
|
|
70
|
-
const current = this.taskOrchestration;
|
|
71
|
-
if (current && typeof current === 'object' && !Array.isArray(current)) {
|
|
72
|
-
const defaults = createDefaultTaskOrchestrationState();
|
|
73
|
-
for (const [key, value] of Object.entries(defaults)) {
|
|
74
|
-
if (typeof current[key] === 'undefined') {
|
|
75
|
-
current[key] = value;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return current;
|
|
79
|
-
}
|
|
80
|
-
this.taskOrchestration = createDefaultTaskOrchestrationState();
|
|
81
|
-
return this.taskOrchestration;
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
buildTaskOrchestrationRequest() {
|
|
85
|
-
const state = this.ensureTaskOrchestrationState();
|
|
86
|
-
return {
|
|
87
|
-
title: String(state.title || '').trim(),
|
|
88
|
-
target: String(state.target || '').trim(),
|
|
89
|
-
notes: String(state.notes || '').trim(),
|
|
90
|
-
followUps: normalizeLines(state.followUpsText),
|
|
91
|
-
workflowIds: normalizeLines(state.workflowIdsText),
|
|
92
|
-
engine: String(state.selectedEngine || 'codex').trim().toLowerCase() === 'workflow' ? 'workflow' : 'codex',
|
|
93
|
-
allowWrite: state.allowWrite === true,
|
|
94
|
-
dryRun: state.dryRun === true,
|
|
95
|
-
concurrency: normalizePositiveInteger(state.concurrency, 2, 1, 8),
|
|
96
|
-
autoFixRounds: normalizePositiveInteger(state.autoFixRounds, 1, 0, 5)
|
|
97
|
-
};
|
|
98
|
-
},
|
|
99
|
-
|
|
100
|
-
taskRunStatusTone(status) {
|
|
101
|
-
return normalizeTaskStatusTone(status);
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
isTaskRunActive(status) {
|
|
105
|
-
return isActiveStatus(status);
|
|
106
|
-
},
|
|
107
|
-
|
|
108
|
-
formatTaskNodeDependencies(node) {
|
|
109
|
-
const dependsOn = Array.isArray(node && node.dependsOn) ? node.dependsOn : [];
|
|
110
|
-
return dependsOn.length > 0 ? dependsOn.join(', ') : '无';
|
|
111
|
-
},
|
|
112
|
-
|
|
113
|
-
formatTaskNodeLogs(logs) {
|
|
114
|
-
if (!Array.isArray(logs) || logs.length === 0) {
|
|
115
|
-
return '(no logs)';
|
|
116
|
-
}
|
|
117
|
-
return logs.map((item) => `${item && item.at ? item.at : ''} ${item && item.level ? item.level : ''} ${item && item.message ? item.message : ''}`.trim()).join('\n');
|
|
118
|
-
},
|
|
119
|
-
|
|
120
|
-
appendTaskWorkflowId(workflowId) {
|
|
121
|
-
const state = this.ensureTaskOrchestrationState();
|
|
122
|
-
const normalizedWorkflowId = typeof workflowId === 'string' ? workflowId.trim() : '';
|
|
123
|
-
if (!normalizedWorkflowId) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
const nextWorkflowIds = normalizeLines(state.workflowIdsText);
|
|
127
|
-
if (!nextWorkflowIds.includes(normalizedWorkflowId)) {
|
|
128
|
-
nextWorkflowIds.push(normalizedWorkflowId);
|
|
129
|
-
}
|
|
130
|
-
state.selectedEngine = 'workflow';
|
|
131
|
-
state.workflowIdsText = nextWorkflowIds.join('\n');
|
|
132
|
-
},
|
|
133
|
-
|
|
134
|
-
async loadTaskOrchestrationOverview(options = {}) {
|
|
135
|
-
const state = this.ensureTaskOrchestrationState();
|
|
136
|
-
if (state.loading && !options.forceRefresh) {
|
|
137
|
-
return null;
|
|
138
|
-
}
|
|
139
|
-
const silent = !!options.silent;
|
|
140
|
-
state.loading = true;
|
|
141
|
-
state.lastError = '';
|
|
142
|
-
try {
|
|
143
|
-
const res = await api('task-overview', {
|
|
144
|
-
queueLimit: 20,
|
|
145
|
-
runLimit: 20
|
|
146
|
-
});
|
|
147
|
-
if (res && res.error) {
|
|
148
|
-
state.lastError = res.error;
|
|
149
|
-
if (!silent) {
|
|
150
|
-
this.showMessage(res.error, 'error');
|
|
151
|
-
}
|
|
152
|
-
return res;
|
|
153
|
-
}
|
|
154
|
-
state.workflows = Array.isArray(res && res.workflows) ? res.workflows : [];
|
|
155
|
-
state.queue = Array.isArray(res && res.queue) ? res.queue : [];
|
|
156
|
-
state.runs = Array.isArray(res && res.runs) ? res.runs : [];
|
|
157
|
-
state.overviewWarnings = Array.isArray(res && res.warnings) ? res.warnings : [];
|
|
158
|
-
state.lastLoadedAt = new Date().toISOString();
|
|
159
|
-
if (!state.selectedRunId && state.runs.length > 0) {
|
|
160
|
-
state.selectedRunId = state.runs[0].runId || '';
|
|
161
|
-
}
|
|
162
|
-
const shouldRefreshSelectedDetail = !!state.selectedRunId
|
|
163
|
-
&& (options.includeDetail !== false
|
|
164
|
-
|| (state.selectedRunDetail && this.isTaskRunActive(state.selectedRunDetail && state.selectedRunDetail.run && state.selectedRunDetail.run.status)));
|
|
165
|
-
if (shouldRefreshSelectedDetail) {
|
|
166
|
-
await this.loadTaskRunDetail(state.selectedRunId, { silent: true });
|
|
167
|
-
}
|
|
168
|
-
this.syncTaskOrchestrationPolling();
|
|
169
|
-
return res;
|
|
170
|
-
} catch (error) {
|
|
171
|
-
const message = error && error.message ? error.message : '任务编排概览加载失败';
|
|
172
|
-
state.lastError = message;
|
|
173
|
-
if (!silent) {
|
|
174
|
-
this.showMessage(message, 'error');
|
|
175
|
-
}
|
|
176
|
-
return { error: message };
|
|
177
|
-
} finally {
|
|
178
|
-
state.loading = false;
|
|
179
|
-
}
|
|
180
|
-
},
|
|
181
|
-
|
|
182
|
-
async previewTaskPlan(options = {}) {
|
|
183
|
-
const state = this.ensureTaskOrchestrationState();
|
|
184
|
-
if (state.planning) {
|
|
185
|
-
return null;
|
|
186
|
-
}
|
|
187
|
-
state.planning = true;
|
|
188
|
-
try {
|
|
189
|
-
const res = await api('task-plan', this.buildTaskOrchestrationRequest());
|
|
190
|
-
state.plan = res && res.plan ? res.plan : null;
|
|
191
|
-
state.planIssues = Array.isArray(res && res.issues) ? res.issues : [];
|
|
192
|
-
state.planWarnings = Array.isArray(res && res.warnings) ? res.warnings : [];
|
|
193
|
-
if (res && res.error) {
|
|
194
|
-
if (!options.silent) {
|
|
195
|
-
this.showMessage(res.error, 'error');
|
|
196
|
-
}
|
|
197
|
-
return res;
|
|
198
|
-
}
|
|
199
|
-
if (!options.silent) {
|
|
200
|
-
this.showMessage('任务计划已更新', 'success');
|
|
201
|
-
}
|
|
202
|
-
return res;
|
|
203
|
-
} catch (error) {
|
|
204
|
-
const message = error && error.message ? error.message : '任务计划生成失败';
|
|
205
|
-
state.plan = null;
|
|
206
|
-
state.planIssues = [];
|
|
207
|
-
state.planWarnings = [];
|
|
208
|
-
if (!options.silent) {
|
|
209
|
-
this.showMessage(message, 'error');
|
|
210
|
-
}
|
|
211
|
-
return { error: message };
|
|
212
|
-
} finally {
|
|
213
|
-
state.planning = false;
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
|
|
217
|
-
async runTaskOrchestration() {
|
|
218
|
-
const state = this.ensureTaskOrchestrationState();
|
|
219
|
-
if (state.running) {
|
|
220
|
-
return null;
|
|
221
|
-
}
|
|
222
|
-
state.running = true;
|
|
223
|
-
try {
|
|
224
|
-
const res = await api('task-run', {
|
|
225
|
-
...this.buildTaskOrchestrationRequest(),
|
|
226
|
-
detach: true
|
|
227
|
-
});
|
|
228
|
-
if (res && res.error) {
|
|
229
|
-
this.showMessage(res.error, 'error');
|
|
230
|
-
return res;
|
|
231
|
-
}
|
|
232
|
-
state.selectedRunId = res.runId || state.selectedRunId;
|
|
233
|
-
await this.loadTaskOrchestrationOverview({ silent: true, includeDetail: false });
|
|
234
|
-
if (state.selectedRunId) {
|
|
235
|
-
await this.loadTaskRunDetail(state.selectedRunId, { silent: true });
|
|
236
|
-
}
|
|
237
|
-
this.syncTaskOrchestrationPolling();
|
|
238
|
-
this.showMessage(`任务已启动: ${res.runId || res.taskId || 'unknown'}`, 'success');
|
|
239
|
-
return res;
|
|
240
|
-
} catch (error) {
|
|
241
|
-
const message = error && error.message ? error.message : '任务启动失败';
|
|
242
|
-
this.showMessage(message, 'error');
|
|
243
|
-
return { error: message };
|
|
244
|
-
} finally {
|
|
245
|
-
state.running = false;
|
|
246
|
-
}
|
|
247
|
-
},
|
|
248
|
-
|
|
249
|
-
async addTaskOrchestrationToQueue() {
|
|
250
|
-
const state = this.ensureTaskOrchestrationState();
|
|
251
|
-
if (state.queueAdding) {
|
|
252
|
-
return null;
|
|
253
|
-
}
|
|
254
|
-
state.queueAdding = true;
|
|
255
|
-
try {
|
|
256
|
-
const res = await api('task-queue-add', this.buildTaskOrchestrationRequest());
|
|
257
|
-
if (res && res.error) {
|
|
258
|
-
this.showMessage(res.error, 'error');
|
|
259
|
-
return res;
|
|
260
|
-
}
|
|
261
|
-
await this.loadTaskOrchestrationOverview({ silent: true, includeDetail: false });
|
|
262
|
-
this.showMessage(`已加入队列: ${res && res.task ? res.task.taskId : ''}`.trim(), 'success');
|
|
263
|
-
return res;
|
|
264
|
-
} catch (error) {
|
|
265
|
-
const message = error && error.message ? error.message : '加入队列失败';
|
|
266
|
-
this.showMessage(message, 'error');
|
|
267
|
-
return { error: message };
|
|
268
|
-
} finally {
|
|
269
|
-
state.queueAdding = false;
|
|
270
|
-
}
|
|
271
|
-
},
|
|
272
|
-
|
|
273
|
-
async startTaskQueueRunner() {
|
|
274
|
-
const state = this.ensureTaskOrchestrationState();
|
|
275
|
-
if (state.queueStarting) {
|
|
276
|
-
return null;
|
|
277
|
-
}
|
|
278
|
-
state.queueStarting = true;
|
|
279
|
-
try {
|
|
280
|
-
const res = await api('task-queue-start', { detach: true });
|
|
281
|
-
if (res && res.error) {
|
|
282
|
-
this.showMessage(res.error, 'error');
|
|
283
|
-
return res;
|
|
284
|
-
}
|
|
285
|
-
await this.loadTaskOrchestrationOverview({ silent: true, includeDetail: false });
|
|
286
|
-
this.syncTaskOrchestrationPolling();
|
|
287
|
-
this.showMessage(res && res.alreadyRunning ? '队列执行器已在运行' : '队列执行器已启动', 'success');
|
|
288
|
-
return res;
|
|
289
|
-
} catch (error) {
|
|
290
|
-
const message = error && error.message ? error.message : '启动队列失败';
|
|
291
|
-
this.showMessage(message, 'error');
|
|
292
|
-
return { error: message };
|
|
293
|
-
} finally {
|
|
294
|
-
state.queueStarting = false;
|
|
295
|
-
}
|
|
296
|
-
},
|
|
297
|
-
|
|
298
|
-
async loadTaskRunDetail(runId, options = {}) {
|
|
299
|
-
const state = this.ensureTaskOrchestrationState();
|
|
300
|
-
const normalizedRunId = String(runId || '').trim();
|
|
301
|
-
if (!normalizedRunId) {
|
|
302
|
-
state.selectedRunDetail = null;
|
|
303
|
-
state.selectedRunId = '';
|
|
304
|
-
state.selectedRunError = '';
|
|
305
|
-
this.syncTaskOrchestrationPolling();
|
|
306
|
-
return null;
|
|
307
|
-
}
|
|
308
|
-
const requestToken = (state.detailRequestToken || 0) + 1;
|
|
309
|
-
const previousRunId = state.selectedRunId;
|
|
310
|
-
state.detailRequestToken = requestToken;
|
|
311
|
-
state.selectedRunLoading = true;
|
|
312
|
-
state.selectedRunId = normalizedRunId;
|
|
313
|
-
if (options.switchToDetail === true || !options.silent) {
|
|
314
|
-
state.workspaceTab = 'detail';
|
|
315
|
-
}
|
|
316
|
-
state.selectedRunError = '';
|
|
317
|
-
if (previousRunId !== normalizedRunId) {
|
|
318
|
-
state.selectedRunDetail = null;
|
|
319
|
-
}
|
|
320
|
-
try {
|
|
321
|
-
const res = await api('task-run-detail', { runId: normalizedRunId });
|
|
322
|
-
if (state.detailRequestToken !== requestToken) {
|
|
323
|
-
return res;
|
|
324
|
-
}
|
|
325
|
-
if (res && res.error) {
|
|
326
|
-
state.selectedRunDetail = null;
|
|
327
|
-
state.selectedRunError = res.error;
|
|
328
|
-
if (!options.silent) {
|
|
329
|
-
this.showMessage(res.error, 'error');
|
|
330
|
-
}
|
|
331
|
-
return res;
|
|
332
|
-
}
|
|
333
|
-
state.selectedRunDetail = res;
|
|
334
|
-
state.selectedRunError = '';
|
|
335
|
-
this.syncTaskOrchestrationPolling();
|
|
336
|
-
return res;
|
|
337
|
-
} catch (error) {
|
|
338
|
-
const message = error && error.message ? error.message : '加载任务详情失败';
|
|
339
|
-
if (state.detailRequestToken === requestToken) {
|
|
340
|
-
state.selectedRunDetail = null;
|
|
341
|
-
state.selectedRunError = message;
|
|
342
|
-
}
|
|
343
|
-
if (!options.silent) {
|
|
344
|
-
this.showMessage(message, 'error');
|
|
345
|
-
}
|
|
346
|
-
return { error: message };
|
|
347
|
-
} finally {
|
|
348
|
-
if (state.detailRequestToken === requestToken) {
|
|
349
|
-
state.selectedRunLoading = false;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
},
|
|
353
|
-
|
|
354
|
-
async selectTaskRun(runId) {
|
|
355
|
-
return this.loadTaskRunDetail(runId, { silent: false, switchToDetail: true });
|
|
356
|
-
},
|
|
357
|
-
|
|
358
|
-
async retryTaskRunFromUi(runId) {
|
|
359
|
-
const state = this.ensureTaskOrchestrationState();
|
|
360
|
-
const normalizedRunId = String(runId || '').trim();
|
|
361
|
-
if (!normalizedRunId || state.retrying) {
|
|
362
|
-
return null;
|
|
363
|
-
}
|
|
364
|
-
state.retrying = true;
|
|
365
|
-
try {
|
|
366
|
-
const res = await api('task-retry', { runId: normalizedRunId, detach: true });
|
|
367
|
-
if (res && res.error) {
|
|
368
|
-
this.showMessage(res.error, 'error');
|
|
369
|
-
return res;
|
|
370
|
-
}
|
|
371
|
-
state.selectedRunId = res.runId || state.selectedRunId;
|
|
372
|
-
await this.loadTaskOrchestrationOverview({ silent: true, includeDetail: false });
|
|
373
|
-
if (state.selectedRunId) {
|
|
374
|
-
await this.loadTaskRunDetail(state.selectedRunId, { silent: true });
|
|
375
|
-
}
|
|
376
|
-
this.syncTaskOrchestrationPolling();
|
|
377
|
-
this.showMessage(`已开始重试: ${res.runId || normalizedRunId}`, 'success');
|
|
378
|
-
return res;
|
|
379
|
-
} catch (error) {
|
|
380
|
-
const message = error && error.message ? error.message : '重试任务失败';
|
|
381
|
-
this.showMessage(message, 'error');
|
|
382
|
-
return { error: message };
|
|
383
|
-
} finally {
|
|
384
|
-
state.retrying = false;
|
|
385
|
-
}
|
|
386
|
-
},
|
|
387
|
-
|
|
388
|
-
async cancelTaskRunFromUi(target) {
|
|
389
|
-
const normalizedTarget = String(target || '').trim();
|
|
390
|
-
if (!normalizedTarget) {
|
|
391
|
-
return null;
|
|
392
|
-
}
|
|
393
|
-
try {
|
|
394
|
-
const res = await api('task-cancel', { target: normalizedTarget });
|
|
395
|
-
if (res && res.error) {
|
|
396
|
-
this.showMessage(res.error, 'error');
|
|
397
|
-
return res;
|
|
398
|
-
}
|
|
399
|
-
await this.loadTaskOrchestrationOverview({ silent: true, includeDetail: false });
|
|
400
|
-
if (this.taskOrchestration.selectedRunId) {
|
|
401
|
-
await this.loadTaskRunDetail(this.taskOrchestration.selectedRunId, { silent: true });
|
|
402
|
-
}
|
|
403
|
-
this.syncTaskOrchestrationPolling();
|
|
404
|
-
this.showMessage('已发出取消请求', 'success');
|
|
405
|
-
return res;
|
|
406
|
-
} catch (error) {
|
|
407
|
-
const message = error && error.message ? error.message : '取消任务失败';
|
|
408
|
-
this.showMessage(message, 'error');
|
|
409
|
-
return { error: message };
|
|
410
|
-
}
|
|
411
|
-
},
|
|
412
|
-
|
|
413
|
-
taskOrchestrationHasLiveActivity() {
|
|
414
|
-
const state = this.ensureTaskOrchestrationState();
|
|
415
|
-
const queue = Array.isArray(state.queue) ? state.queue : [];
|
|
416
|
-
if (queue.some((item) => isActiveStatus(item && (item.status || item.runStatus)))) {
|
|
417
|
-
return true;
|
|
418
|
-
}
|
|
419
|
-
const detail = state.selectedRunDetail;
|
|
420
|
-
const selectedStatus = detail && detail.run ? detail.run.status : '';
|
|
421
|
-
if (isActiveStatus(selectedStatus)) {
|
|
422
|
-
return true;
|
|
423
|
-
}
|
|
424
|
-
const runs = Array.isArray(state.runs) ? state.runs : [];
|
|
425
|
-
return runs.some((item) => isActiveStatus(item && item.status));
|
|
426
|
-
},
|
|
427
|
-
|
|
428
|
-
stopTaskOrchestrationPolling() {
|
|
429
|
-
if (this._taskOrchestrationPollTimer) {
|
|
430
|
-
clearTimeout(this._taskOrchestrationPollTimer);
|
|
431
|
-
this._taskOrchestrationPollTimer = 0;
|
|
432
|
-
}
|
|
433
|
-
},
|
|
434
|
-
|
|
435
|
-
syncTaskOrchestrationPolling() {
|
|
436
|
-
this.stopTaskOrchestrationPolling();
|
|
437
|
-
if (this.mainTab !== 'orchestration') {
|
|
438
|
-
return;
|
|
439
|
-
}
|
|
440
|
-
if (!this.taskOrchestrationHasLiveActivity()) {
|
|
441
|
-
return;
|
|
442
|
-
}
|
|
443
|
-
this._taskOrchestrationPollTimer = setTimeout(async () => {
|
|
444
|
-
this._taskOrchestrationPollTimer = 0;
|
|
445
|
-
if (this.mainTab !== 'orchestration') {
|
|
446
|
-
return;
|
|
447
|
-
}
|
|
448
|
-
await this.loadTaskOrchestrationOverview({ silent: true, includeDetail: true });
|
|
449
|
-
}, 4000);
|
|
450
|
-
},
|
|
451
|
-
|
|
452
|
-
resetTaskOrchestrationDraft() {
|
|
453
|
-
const state = this.ensureTaskOrchestrationState();
|
|
454
|
-
state.target = '';
|
|
455
|
-
state.title = '';
|
|
456
|
-
state.notes = '';
|
|
457
|
-
state.followUpsText = '';
|
|
458
|
-
state.workflowIdsText = '';
|
|
459
|
-
state.selectedEngine = 'codex';
|
|
460
|
-
state.allowWrite = false;
|
|
461
|
-
state.dryRun = false;
|
|
462
|
-
state.concurrency = 2;
|
|
463
|
-
state.autoFixRounds = 1;
|
|
464
|
-
state.plan = null;
|
|
465
|
-
state.planIssues = [];
|
|
466
|
-
state.planWarnings = [];
|
|
467
|
-
state.lastError = '';
|
|
468
|
-
this.syncTaskOrchestrationPolling();
|
|
469
|
-
}
|
|
470
|
-
};
|
|
471
|
-
}
|
|
1
|
+
function createDefaultTaskOrchestrationState() {
|
|
2
|
+
return {
|
|
3
|
+
loading: false,
|
|
4
|
+
planning: false,
|
|
5
|
+
running: false,
|
|
6
|
+
queueAdding: false,
|
|
7
|
+
queueStarting: false,
|
|
8
|
+
retrying: false,
|
|
9
|
+
target: '',
|
|
10
|
+
title: '',
|
|
11
|
+
notes: '',
|
|
12
|
+
followUpsText: '',
|
|
13
|
+
workflowIdsText: '',
|
|
14
|
+
selectedEngine: 'codex',
|
|
15
|
+
allowWrite: false,
|
|
16
|
+
dryRun: false,
|
|
17
|
+
concurrency: 2,
|
|
18
|
+
autoFixRounds: 1,
|
|
19
|
+
plan: null,
|
|
20
|
+
planIssues: [],
|
|
21
|
+
planWarnings: [],
|
|
22
|
+
overviewWarnings: [],
|
|
23
|
+
workflows: [],
|
|
24
|
+
queue: [],
|
|
25
|
+
runs: [],
|
|
26
|
+
selectedRunId: '',
|
|
27
|
+
workspaceTab: 'queue',
|
|
28
|
+
selectedRunDetail: null,
|
|
29
|
+
selectedRunLoading: false,
|
|
30
|
+
selectedRunError: '',
|
|
31
|
+
detailRequestToken: 0,
|
|
32
|
+
lastLoadedAt: '',
|
|
33
|
+
lastError: ''
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function normalizeLines(text) {
|
|
38
|
+
return String(text || '')
|
|
39
|
+
.split(/\r?\n/g)
|
|
40
|
+
.map((item) => item.trim())
|
|
41
|
+
.filter(Boolean);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function normalizePositiveInteger(value, fallback, min = 1, max = 8) {
|
|
45
|
+
const numeric = Number.parseInt(String(value), 10);
|
|
46
|
+
if (!Number.isFinite(numeric)) {
|
|
47
|
+
return fallback;
|
|
48
|
+
}
|
|
49
|
+
return Math.min(max, Math.max(min, Math.floor(numeric)));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function normalizeTaskStatusTone(status) {
|
|
53
|
+
const normalized = String(status || '').trim().toLowerCase();
|
|
54
|
+
if (normalized === 'success' || normalized === 'completed') return 'success';
|
|
55
|
+
if (normalized === 'failed' || normalized === 'blocked' || normalized === 'cancelled') return 'error';
|
|
56
|
+
if (normalized === 'running' || normalized === 'queued') return 'warn';
|
|
57
|
+
return 'neutral';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function isActiveStatus(status) {
|
|
61
|
+
const normalized = String(status || '').trim().toLowerCase();
|
|
62
|
+
return normalized === 'running' || normalized === 'queued';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function createTaskOrchestrationMethods(options = {}) {
|
|
66
|
+
const { api } = options;
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
ensureTaskOrchestrationState() {
|
|
70
|
+
const current = this.taskOrchestration;
|
|
71
|
+
if (current && typeof current === 'object' && !Array.isArray(current)) {
|
|
72
|
+
const defaults = createDefaultTaskOrchestrationState();
|
|
73
|
+
for (const [key, value] of Object.entries(defaults)) {
|
|
74
|
+
if (typeof current[key] === 'undefined') {
|
|
75
|
+
current[key] = value;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return current;
|
|
79
|
+
}
|
|
80
|
+
this.taskOrchestration = createDefaultTaskOrchestrationState();
|
|
81
|
+
return this.taskOrchestration;
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
buildTaskOrchestrationRequest() {
|
|
85
|
+
const state = this.ensureTaskOrchestrationState();
|
|
86
|
+
return {
|
|
87
|
+
title: String(state.title || '').trim(),
|
|
88
|
+
target: String(state.target || '').trim(),
|
|
89
|
+
notes: String(state.notes || '').trim(),
|
|
90
|
+
followUps: normalizeLines(state.followUpsText),
|
|
91
|
+
workflowIds: normalizeLines(state.workflowIdsText),
|
|
92
|
+
engine: String(state.selectedEngine || 'codex').trim().toLowerCase() === 'workflow' ? 'workflow' : 'codex',
|
|
93
|
+
allowWrite: state.allowWrite === true,
|
|
94
|
+
dryRun: state.dryRun === true,
|
|
95
|
+
concurrency: normalizePositiveInteger(state.concurrency, 2, 1, 8),
|
|
96
|
+
autoFixRounds: normalizePositiveInteger(state.autoFixRounds, 1, 0, 5)
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
taskRunStatusTone(status) {
|
|
101
|
+
return normalizeTaskStatusTone(status);
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
isTaskRunActive(status) {
|
|
105
|
+
return isActiveStatus(status);
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
formatTaskNodeDependencies(node) {
|
|
109
|
+
const dependsOn = Array.isArray(node && node.dependsOn) ? node.dependsOn : [];
|
|
110
|
+
return dependsOn.length > 0 ? dependsOn.join(', ') : '无';
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
formatTaskNodeLogs(logs) {
|
|
114
|
+
if (!Array.isArray(logs) || logs.length === 0) {
|
|
115
|
+
return '(no logs)';
|
|
116
|
+
}
|
|
117
|
+
return logs.map((item) => `${item && item.at ? item.at : ''} ${item && item.level ? item.level : ''} ${item && item.message ? item.message : ''}`.trim()).join('\n');
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
appendTaskWorkflowId(workflowId) {
|
|
121
|
+
const state = this.ensureTaskOrchestrationState();
|
|
122
|
+
const normalizedWorkflowId = typeof workflowId === 'string' ? workflowId.trim() : '';
|
|
123
|
+
if (!normalizedWorkflowId) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const nextWorkflowIds = normalizeLines(state.workflowIdsText);
|
|
127
|
+
if (!nextWorkflowIds.includes(normalizedWorkflowId)) {
|
|
128
|
+
nextWorkflowIds.push(normalizedWorkflowId);
|
|
129
|
+
}
|
|
130
|
+
state.selectedEngine = 'workflow';
|
|
131
|
+
state.workflowIdsText = nextWorkflowIds.join('\n');
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
async loadTaskOrchestrationOverview(options = {}) {
|
|
135
|
+
const state = this.ensureTaskOrchestrationState();
|
|
136
|
+
if (state.loading && !options.forceRefresh) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
const silent = !!options.silent;
|
|
140
|
+
state.loading = true;
|
|
141
|
+
state.lastError = '';
|
|
142
|
+
try {
|
|
143
|
+
const res = await api('task-overview', {
|
|
144
|
+
queueLimit: 20,
|
|
145
|
+
runLimit: 20
|
|
146
|
+
});
|
|
147
|
+
if (res && res.error) {
|
|
148
|
+
state.lastError = res.error;
|
|
149
|
+
if (!silent) {
|
|
150
|
+
this.showMessage(res.error, 'error');
|
|
151
|
+
}
|
|
152
|
+
return res;
|
|
153
|
+
}
|
|
154
|
+
state.workflows = Array.isArray(res && res.workflows) ? res.workflows : [];
|
|
155
|
+
state.queue = Array.isArray(res && res.queue) ? res.queue : [];
|
|
156
|
+
state.runs = Array.isArray(res && res.runs) ? res.runs : [];
|
|
157
|
+
state.overviewWarnings = Array.isArray(res && res.warnings) ? res.warnings : [];
|
|
158
|
+
state.lastLoadedAt = new Date().toISOString();
|
|
159
|
+
if (!state.selectedRunId && state.runs.length > 0) {
|
|
160
|
+
state.selectedRunId = state.runs[0].runId || '';
|
|
161
|
+
}
|
|
162
|
+
const shouldRefreshSelectedDetail = !!state.selectedRunId
|
|
163
|
+
&& (options.includeDetail !== false
|
|
164
|
+
|| (state.selectedRunDetail && this.isTaskRunActive(state.selectedRunDetail && state.selectedRunDetail.run && state.selectedRunDetail.run.status)));
|
|
165
|
+
if (shouldRefreshSelectedDetail) {
|
|
166
|
+
await this.loadTaskRunDetail(state.selectedRunId, { silent: true });
|
|
167
|
+
}
|
|
168
|
+
this.syncTaskOrchestrationPolling();
|
|
169
|
+
return res;
|
|
170
|
+
} catch (error) {
|
|
171
|
+
const message = error && error.message ? error.message : '任务编排概览加载失败';
|
|
172
|
+
state.lastError = message;
|
|
173
|
+
if (!silent) {
|
|
174
|
+
this.showMessage(message, 'error');
|
|
175
|
+
}
|
|
176
|
+
return { error: message };
|
|
177
|
+
} finally {
|
|
178
|
+
state.loading = false;
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
|
|
182
|
+
async previewTaskPlan(options = {}) {
|
|
183
|
+
const state = this.ensureTaskOrchestrationState();
|
|
184
|
+
if (state.planning) {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
state.planning = true;
|
|
188
|
+
try {
|
|
189
|
+
const res = await api('task-plan', this.buildTaskOrchestrationRequest());
|
|
190
|
+
state.plan = res && res.plan ? res.plan : null;
|
|
191
|
+
state.planIssues = Array.isArray(res && res.issues) ? res.issues : [];
|
|
192
|
+
state.planWarnings = Array.isArray(res && res.warnings) ? res.warnings : [];
|
|
193
|
+
if (res && res.error) {
|
|
194
|
+
if (!options.silent) {
|
|
195
|
+
this.showMessage(res.error, 'error');
|
|
196
|
+
}
|
|
197
|
+
return res;
|
|
198
|
+
}
|
|
199
|
+
if (!options.silent) {
|
|
200
|
+
this.showMessage('任务计划已更新', 'success');
|
|
201
|
+
}
|
|
202
|
+
return res;
|
|
203
|
+
} catch (error) {
|
|
204
|
+
const message = error && error.message ? error.message : '任务计划生成失败';
|
|
205
|
+
state.plan = null;
|
|
206
|
+
state.planIssues = [];
|
|
207
|
+
state.planWarnings = [];
|
|
208
|
+
if (!options.silent) {
|
|
209
|
+
this.showMessage(message, 'error');
|
|
210
|
+
}
|
|
211
|
+
return { error: message };
|
|
212
|
+
} finally {
|
|
213
|
+
state.planning = false;
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
|
|
217
|
+
async runTaskOrchestration() {
|
|
218
|
+
const state = this.ensureTaskOrchestrationState();
|
|
219
|
+
if (state.running) {
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
state.running = true;
|
|
223
|
+
try {
|
|
224
|
+
const res = await api('task-run', {
|
|
225
|
+
...this.buildTaskOrchestrationRequest(),
|
|
226
|
+
detach: true
|
|
227
|
+
});
|
|
228
|
+
if (res && res.error) {
|
|
229
|
+
this.showMessage(res.error, 'error');
|
|
230
|
+
return res;
|
|
231
|
+
}
|
|
232
|
+
state.selectedRunId = res.runId || state.selectedRunId;
|
|
233
|
+
await this.loadTaskOrchestrationOverview({ silent: true, includeDetail: false });
|
|
234
|
+
if (state.selectedRunId) {
|
|
235
|
+
await this.loadTaskRunDetail(state.selectedRunId, { silent: true });
|
|
236
|
+
}
|
|
237
|
+
this.syncTaskOrchestrationPolling();
|
|
238
|
+
this.showMessage(`任务已启动: ${res.runId || res.taskId || 'unknown'}`, 'success');
|
|
239
|
+
return res;
|
|
240
|
+
} catch (error) {
|
|
241
|
+
const message = error && error.message ? error.message : '任务启动失败';
|
|
242
|
+
this.showMessage(message, 'error');
|
|
243
|
+
return { error: message };
|
|
244
|
+
} finally {
|
|
245
|
+
state.running = false;
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
|
|
249
|
+
async addTaskOrchestrationToQueue() {
|
|
250
|
+
const state = this.ensureTaskOrchestrationState();
|
|
251
|
+
if (state.queueAdding) {
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
state.queueAdding = true;
|
|
255
|
+
try {
|
|
256
|
+
const res = await api('task-queue-add', this.buildTaskOrchestrationRequest());
|
|
257
|
+
if (res && res.error) {
|
|
258
|
+
this.showMessage(res.error, 'error');
|
|
259
|
+
return res;
|
|
260
|
+
}
|
|
261
|
+
await this.loadTaskOrchestrationOverview({ silent: true, includeDetail: false });
|
|
262
|
+
this.showMessage(`已加入队列: ${res && res.task ? res.task.taskId : ''}`.trim(), 'success');
|
|
263
|
+
return res;
|
|
264
|
+
} catch (error) {
|
|
265
|
+
const message = error && error.message ? error.message : '加入队列失败';
|
|
266
|
+
this.showMessage(message, 'error');
|
|
267
|
+
return { error: message };
|
|
268
|
+
} finally {
|
|
269
|
+
state.queueAdding = false;
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
|
|
273
|
+
async startTaskQueueRunner() {
|
|
274
|
+
const state = this.ensureTaskOrchestrationState();
|
|
275
|
+
if (state.queueStarting) {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
state.queueStarting = true;
|
|
279
|
+
try {
|
|
280
|
+
const res = await api('task-queue-start', { detach: true });
|
|
281
|
+
if (res && res.error) {
|
|
282
|
+
this.showMessage(res.error, 'error');
|
|
283
|
+
return res;
|
|
284
|
+
}
|
|
285
|
+
await this.loadTaskOrchestrationOverview({ silent: true, includeDetail: false });
|
|
286
|
+
this.syncTaskOrchestrationPolling();
|
|
287
|
+
this.showMessage(res && res.alreadyRunning ? '队列执行器已在运行' : '队列执行器已启动', 'success');
|
|
288
|
+
return res;
|
|
289
|
+
} catch (error) {
|
|
290
|
+
const message = error && error.message ? error.message : '启动队列失败';
|
|
291
|
+
this.showMessage(message, 'error');
|
|
292
|
+
return { error: message };
|
|
293
|
+
} finally {
|
|
294
|
+
state.queueStarting = false;
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
|
|
298
|
+
async loadTaskRunDetail(runId, options = {}) {
|
|
299
|
+
const state = this.ensureTaskOrchestrationState();
|
|
300
|
+
const normalizedRunId = String(runId || '').trim();
|
|
301
|
+
if (!normalizedRunId) {
|
|
302
|
+
state.selectedRunDetail = null;
|
|
303
|
+
state.selectedRunId = '';
|
|
304
|
+
state.selectedRunError = '';
|
|
305
|
+
this.syncTaskOrchestrationPolling();
|
|
306
|
+
return null;
|
|
307
|
+
}
|
|
308
|
+
const requestToken = (state.detailRequestToken || 0) + 1;
|
|
309
|
+
const previousRunId = state.selectedRunId;
|
|
310
|
+
state.detailRequestToken = requestToken;
|
|
311
|
+
state.selectedRunLoading = true;
|
|
312
|
+
state.selectedRunId = normalizedRunId;
|
|
313
|
+
if (options.switchToDetail === true || !options.silent) {
|
|
314
|
+
state.workspaceTab = 'detail';
|
|
315
|
+
}
|
|
316
|
+
state.selectedRunError = '';
|
|
317
|
+
if (previousRunId !== normalizedRunId) {
|
|
318
|
+
state.selectedRunDetail = null;
|
|
319
|
+
}
|
|
320
|
+
try {
|
|
321
|
+
const res = await api('task-run-detail', { runId: normalizedRunId });
|
|
322
|
+
if (state.detailRequestToken !== requestToken) {
|
|
323
|
+
return res;
|
|
324
|
+
}
|
|
325
|
+
if (res && res.error) {
|
|
326
|
+
state.selectedRunDetail = null;
|
|
327
|
+
state.selectedRunError = res.error;
|
|
328
|
+
if (!options.silent) {
|
|
329
|
+
this.showMessage(res.error, 'error');
|
|
330
|
+
}
|
|
331
|
+
return res;
|
|
332
|
+
}
|
|
333
|
+
state.selectedRunDetail = res;
|
|
334
|
+
state.selectedRunError = '';
|
|
335
|
+
this.syncTaskOrchestrationPolling();
|
|
336
|
+
return res;
|
|
337
|
+
} catch (error) {
|
|
338
|
+
const message = error && error.message ? error.message : '加载任务详情失败';
|
|
339
|
+
if (state.detailRequestToken === requestToken) {
|
|
340
|
+
state.selectedRunDetail = null;
|
|
341
|
+
state.selectedRunError = message;
|
|
342
|
+
}
|
|
343
|
+
if (!options.silent) {
|
|
344
|
+
this.showMessage(message, 'error');
|
|
345
|
+
}
|
|
346
|
+
return { error: message };
|
|
347
|
+
} finally {
|
|
348
|
+
if (state.detailRequestToken === requestToken) {
|
|
349
|
+
state.selectedRunLoading = false;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
|
|
354
|
+
async selectTaskRun(runId) {
|
|
355
|
+
return this.loadTaskRunDetail(runId, { silent: false, switchToDetail: true });
|
|
356
|
+
},
|
|
357
|
+
|
|
358
|
+
async retryTaskRunFromUi(runId) {
|
|
359
|
+
const state = this.ensureTaskOrchestrationState();
|
|
360
|
+
const normalizedRunId = String(runId || '').trim();
|
|
361
|
+
if (!normalizedRunId || state.retrying) {
|
|
362
|
+
return null;
|
|
363
|
+
}
|
|
364
|
+
state.retrying = true;
|
|
365
|
+
try {
|
|
366
|
+
const res = await api('task-retry', { runId: normalizedRunId, detach: true });
|
|
367
|
+
if (res && res.error) {
|
|
368
|
+
this.showMessage(res.error, 'error');
|
|
369
|
+
return res;
|
|
370
|
+
}
|
|
371
|
+
state.selectedRunId = res.runId || state.selectedRunId;
|
|
372
|
+
await this.loadTaskOrchestrationOverview({ silent: true, includeDetail: false });
|
|
373
|
+
if (state.selectedRunId) {
|
|
374
|
+
await this.loadTaskRunDetail(state.selectedRunId, { silent: true });
|
|
375
|
+
}
|
|
376
|
+
this.syncTaskOrchestrationPolling();
|
|
377
|
+
this.showMessage(`已开始重试: ${res.runId || normalizedRunId}`, 'success');
|
|
378
|
+
return res;
|
|
379
|
+
} catch (error) {
|
|
380
|
+
const message = error && error.message ? error.message : '重试任务失败';
|
|
381
|
+
this.showMessage(message, 'error');
|
|
382
|
+
return { error: message };
|
|
383
|
+
} finally {
|
|
384
|
+
state.retrying = false;
|
|
385
|
+
}
|
|
386
|
+
},
|
|
387
|
+
|
|
388
|
+
async cancelTaskRunFromUi(target) {
|
|
389
|
+
const normalizedTarget = String(target || '').trim();
|
|
390
|
+
if (!normalizedTarget) {
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
393
|
+
try {
|
|
394
|
+
const res = await api('task-cancel', { target: normalizedTarget });
|
|
395
|
+
if (res && res.error) {
|
|
396
|
+
this.showMessage(res.error, 'error');
|
|
397
|
+
return res;
|
|
398
|
+
}
|
|
399
|
+
await this.loadTaskOrchestrationOverview({ silent: true, includeDetail: false });
|
|
400
|
+
if (this.taskOrchestration.selectedRunId) {
|
|
401
|
+
await this.loadTaskRunDetail(this.taskOrchestration.selectedRunId, { silent: true });
|
|
402
|
+
}
|
|
403
|
+
this.syncTaskOrchestrationPolling();
|
|
404
|
+
this.showMessage('已发出取消请求', 'success');
|
|
405
|
+
return res;
|
|
406
|
+
} catch (error) {
|
|
407
|
+
const message = error && error.message ? error.message : '取消任务失败';
|
|
408
|
+
this.showMessage(message, 'error');
|
|
409
|
+
return { error: message };
|
|
410
|
+
}
|
|
411
|
+
},
|
|
412
|
+
|
|
413
|
+
taskOrchestrationHasLiveActivity() {
|
|
414
|
+
const state = this.ensureTaskOrchestrationState();
|
|
415
|
+
const queue = Array.isArray(state.queue) ? state.queue : [];
|
|
416
|
+
if (queue.some((item) => isActiveStatus(item && (item.status || item.runStatus)))) {
|
|
417
|
+
return true;
|
|
418
|
+
}
|
|
419
|
+
const detail = state.selectedRunDetail;
|
|
420
|
+
const selectedStatus = detail && detail.run ? detail.run.status : '';
|
|
421
|
+
if (isActiveStatus(selectedStatus)) {
|
|
422
|
+
return true;
|
|
423
|
+
}
|
|
424
|
+
const runs = Array.isArray(state.runs) ? state.runs : [];
|
|
425
|
+
return runs.some((item) => isActiveStatus(item && item.status));
|
|
426
|
+
},
|
|
427
|
+
|
|
428
|
+
stopTaskOrchestrationPolling() {
|
|
429
|
+
if (this._taskOrchestrationPollTimer) {
|
|
430
|
+
clearTimeout(this._taskOrchestrationPollTimer);
|
|
431
|
+
this._taskOrchestrationPollTimer = 0;
|
|
432
|
+
}
|
|
433
|
+
},
|
|
434
|
+
|
|
435
|
+
syncTaskOrchestrationPolling() {
|
|
436
|
+
this.stopTaskOrchestrationPolling();
|
|
437
|
+
if (this.mainTab !== 'orchestration') {
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
if (!this.taskOrchestrationHasLiveActivity()) {
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
this._taskOrchestrationPollTimer = setTimeout(async () => {
|
|
444
|
+
this._taskOrchestrationPollTimer = 0;
|
|
445
|
+
if (this.mainTab !== 'orchestration') {
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
await this.loadTaskOrchestrationOverview({ silent: true, includeDetail: true });
|
|
449
|
+
}, 4000);
|
|
450
|
+
},
|
|
451
|
+
|
|
452
|
+
resetTaskOrchestrationDraft() {
|
|
453
|
+
const state = this.ensureTaskOrchestrationState();
|
|
454
|
+
state.target = '';
|
|
455
|
+
state.title = '';
|
|
456
|
+
state.notes = '';
|
|
457
|
+
state.followUpsText = '';
|
|
458
|
+
state.workflowIdsText = '';
|
|
459
|
+
state.selectedEngine = 'codex';
|
|
460
|
+
state.allowWrite = false;
|
|
461
|
+
state.dryRun = false;
|
|
462
|
+
state.concurrency = 2;
|
|
463
|
+
state.autoFixRounds = 1;
|
|
464
|
+
state.plan = null;
|
|
465
|
+
state.planIssues = [];
|
|
466
|
+
state.planWarnings = [];
|
|
467
|
+
state.lastError = '';
|
|
468
|
+
this.syncTaskOrchestrationPolling();
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
}
|