dsh-plugin-inspiration-workbench 0.13.3 → 0.13.4
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 +3 -3
- package/lib/client.js +202 -70
- package/lib/client.js.map +4 -4
- package/package.json +1 -1
- package/src/client/board.js +54 -11
- package/src/client/pipeline-utils.js +10 -0
- package/src/client/sessions.js +12 -2
- package/src/client/task-ai.js +1 -1
- package/src/client/task-controller.js +76 -16
- package/src/client/task-intelligence.js +22 -2
package/package.json
CHANGED
package/src/client/board.js
CHANGED
|
@@ -21,6 +21,7 @@ import { createTaskController } from './task-controller.js';
|
|
|
21
21
|
import { createTaskView } from './task-view.js';
|
|
22
22
|
import { createFileStore } from './file-store.js';
|
|
23
23
|
import { openFilePreview, fileKind, formatBytes } from './file-preview.js';
|
|
24
|
+
import { pipelineFingerprint } from './pipeline-utils.js';
|
|
24
25
|
|
|
25
26
|
const STORAGE_KEY = 'dsh.inspiration-workbench.v1';
|
|
26
27
|
const CANVAS_KEY = 'dsh.inspiration-workbench.canvases.v1';
|
|
@@ -1245,6 +1246,17 @@ export function createBoard({ host, adapter, approvals, t, onOpenSession }) {
|
|
|
1245
1246
|
state.canvases = merged;
|
|
1246
1247
|
state.activeCanvas = remote?.activeCanvas || local?.activeCanvas || null;
|
|
1247
1248
|
if (!merged.some((canvas) => canvas.id === state.activeCanvas)) state.activeCanvas = null;
|
|
1249
|
+
if (!state.cards.length && state.activeCanvas) {
|
|
1250
|
+
const active = merged.find((canvas) => canvas.id === state.activeCanvas);
|
|
1251
|
+
if (active?.layout?.cards?.length && Number(active.savedAt || active.layout.updatedAt || 0) >= localUpdatedAt) {
|
|
1252
|
+
suppressSave = true;
|
|
1253
|
+
try {
|
|
1254
|
+
await applyLayout(active.layout, { restore: true });
|
|
1255
|
+
} finally {
|
|
1256
|
+
suppressSave = false;
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1248
1260
|
renderCanvasButton();
|
|
1249
1261
|
}
|
|
1250
1262
|
|
|
@@ -1994,13 +2006,20 @@ export function createBoard({ host, adapter, approvals, t, onOpenSession }) {
|
|
|
1994
2006
|
}
|
|
1995
2007
|
}
|
|
1996
2008
|
|
|
2009
|
+
function alreadyDelivered(card, target, fingerprint) {
|
|
2010
|
+
const edgeKey = card.sessionId + '=>' + (target.kind === 'note' ? 'note' : 'session') + ':' + target.id;
|
|
2011
|
+
const latest = flow.latestByEdge().get(edgeKey);
|
|
2012
|
+
return latest?.fingerprint === fingerprint && (latest.status === 'delivered' || latest.status === 'drafted');
|
|
2013
|
+
}
|
|
2014
|
+
|
|
1997
2015
|
function maybeDeliverCompleted(card) {
|
|
1998
2016
|
if (card.running || card.kind === 'note') return;
|
|
1999
2017
|
const text = lastAssistantText(card);
|
|
2000
2018
|
if (!text) return;
|
|
2001
|
-
const fingerprint = text
|
|
2002
|
-
if (card.catchUpFingerprint === fingerprint) return;
|
|
2003
|
-
|
|
2019
|
+
const fingerprint = pipelineFingerprint(text);
|
|
2020
|
+
if (card.catchUpFingerprint === fingerprint || card.deliveringFingerprint === fingerprint) return;
|
|
2021
|
+
if (Number(card.retryAfter || 0) > Date.now()) return;
|
|
2022
|
+
const pending = pipeTargets(card).some((target) => (card.pipedFingerprints || {})[target.kind + ':' + target.id] !== fingerprint && !alreadyDelivered(card, target, fingerprint));
|
|
2004
2023
|
if (!pending) return;
|
|
2005
2024
|
card.catchUpFingerprint = fingerprint;
|
|
2006
2025
|
// A completed upstream can predate the edge or a page restore. Deliver it once
|
|
@@ -2015,17 +2034,24 @@ export function createBoard({ host, adapter, approvals, t, onOpenSession }) {
|
|
|
2015
2034
|
if (!targets.length) return;
|
|
2016
2035
|
const text = lastAssistantText(card);
|
|
2017
2036
|
if (!text) return;
|
|
2018
|
-
const fingerprint = text
|
|
2037
|
+
const fingerprint = pipelineFingerprint(text);
|
|
2038
|
+
if (card.deliveringFingerprint === fingerprint) return;
|
|
2039
|
+
card.deliveringFingerprint = fingerprint;
|
|
2019
2040
|
card.pipedFingerprints = card.pipedFingerprints || {};
|
|
2020
2041
|
const depth = (card.pipeDepth || 0) + 1;
|
|
2021
|
-
if (depth >
|
|
2042
|
+
if (depth > 16) {
|
|
2022
2043
|
toast(t('pipe.tooLong'));
|
|
2023
2044
|
return;
|
|
2024
2045
|
}
|
|
2025
2046
|
|
|
2026
|
-
|
|
2047
|
+
let hadFailure = false;
|
|
2048
|
+
try {
|
|
2049
|
+
for (const target of targets) {
|
|
2027
2050
|
const key = target.kind + ':' + target.id;
|
|
2028
|
-
if (card.pipedFingerprints[key] === fingerprint)
|
|
2051
|
+
if (card.pipedFingerprints[key] === fingerprint || alreadyDelivered(card, target, fingerprint)) {
|
|
2052
|
+
card.pipedFingerprints[key] = fingerprint;
|
|
2053
|
+
continue;
|
|
2054
|
+
}
|
|
2029
2055
|
const targetCard = cardOfPipeTarget(target);
|
|
2030
2056
|
|
|
2031
2057
|
// A note downstream just collects the text, whatever its mode says.
|
|
@@ -2067,16 +2093,27 @@ export function createBoard({ host, adapter, approvals, t, onOpenSession }) {
|
|
|
2067
2093
|
|
|
2068
2094
|
try {
|
|
2069
2095
|
recordFlow(card, target, 'delivering', { fingerprint, message: '正在投递到目标会话' });
|
|
2096
|
+
if (adapter.waitForReady) await adapter.waitForReady(target.id, { timeoutMs: 15000 });
|
|
2070
2097
|
await adapter.prompt(target.id, text, 'queue');
|
|
2071
2098
|
card.pipedFingerprints[key] = fingerprint;
|
|
2072
2099
|
if (targetCard) targetCard.pipeDepth = depth;
|
|
2073
2100
|
recordFlow(card, target, 'delivered', { fingerprint, message: '已发送到目标会话' });
|
|
2074
2101
|
toast(t('pipe.sent').replace('{name}', pipeTargetLabel(target)));
|
|
2075
2102
|
} catch (error) {
|
|
2103
|
+
hadFailure = true;
|
|
2076
2104
|
recordFlow(card, target, 'failed', { fingerprint, message: error?.message || '投递失败' });
|
|
2077
2105
|
toast(t('pipe.failed').replace('{error}', error?.message || ''));
|
|
2078
2106
|
}
|
|
2079
2107
|
}
|
|
2108
|
+
} finally {
|
|
2109
|
+
if (card.deliveringFingerprint === fingerprint) card.deliveringFingerprint = null;
|
|
2110
|
+
if (hadFailure) {
|
|
2111
|
+
card.catchUpFingerprint = null;
|
|
2112
|
+
card.retryAfter = Date.now() + 5000;
|
|
2113
|
+
} else {
|
|
2114
|
+
card.retryAfter = 0;
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2080
2117
|
}
|
|
2081
2118
|
|
|
2082
2119
|
/** Click a pipeline curve: switch that edge's mode or remove it. */
|
|
@@ -3047,15 +3084,16 @@ export function createBoard({ host, adapter, approvals, t, onOpenSession }) {
|
|
|
3047
3084
|
if (!saved || !Array.isArray(saved.cards)) {
|
|
3048
3085
|
hydratePending = true;
|
|
3049
3086
|
syncApprovalSessions();
|
|
3050
|
-
void
|
|
3087
|
+
void (async () => {
|
|
3088
|
+
const applied = await syncFromRemote();
|
|
3089
|
+
await loadCanvases();
|
|
3051
3090
|
hydratePending = false;
|
|
3052
3091
|
if (!applied && !saveTimer) {
|
|
3053
3092
|
// Host had nothing (or was unreachable): the empty board is legitimately
|
|
3054
3093
|
// ours now, so the next interaction may persist it.
|
|
3055
3094
|
}
|
|
3056
3095
|
startRemoteSync();
|
|
3057
|
-
});
|
|
3058
|
-
void loadCanvases();
|
|
3096
|
+
})();
|
|
3059
3097
|
return false;
|
|
3060
3098
|
}
|
|
3061
3099
|
localUpdatedAt = Number(saved.updatedAt) || 0;
|
|
@@ -3532,6 +3570,7 @@ export function createBoard({ host, adapter, approvals, t, onOpenSession }) {
|
|
|
3532
3570
|
setMode,
|
|
3533
3571
|
save,
|
|
3534
3572
|
schedulePipelines,
|
|
3573
|
+
maybeDeliverCompleted,
|
|
3535
3574
|
recordFlow,
|
|
3536
3575
|
},
|
|
3537
3576
|
});
|
|
@@ -3574,7 +3613,11 @@ export function createBoard({ host, adapter, approvals, t, onOpenSession }) {
|
|
|
3574
3613
|
const active = state.cards.filter(
|
|
3575
3614
|
(card) => card.kind !== 'note' && (card.running || card.queued || card.view?.questions?.length)
|
|
3576
3615
|
);
|
|
3577
|
-
if (active.length)
|
|
3616
|
+
if (active.length) {
|
|
3617
|
+
void Promise.resolve(adapter.pollStates?.(active.map((card) => card.sessionId))).then(() => {
|
|
3618
|
+
for (const card of active) markDirty(card);
|
|
3619
|
+
}).catch(() => {});
|
|
3620
|
+
}
|
|
3578
3621
|
}
|
|
3579
3622
|
}, 1000);
|
|
3580
3623
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Stable, full-content fingerprint for idempotent pipeline delivery. */
|
|
2
|
+
export function pipelineFingerprint(text) {
|
|
3
|
+
const source = String(text || '');
|
|
4
|
+
let hash = 2166136261;
|
|
5
|
+
for (let index = 0; index < source.length; index += 1) {
|
|
6
|
+
hash ^= source.charCodeAt(index);
|
|
7
|
+
hash = Math.imul(hash, 16777619);
|
|
8
|
+
}
|
|
9
|
+
return (hash >>> 0).toString(36);
|
|
10
|
+
}
|
package/src/client/sessions.js
CHANGED
|
@@ -703,7 +703,10 @@ export function createSessionsAdapter(ctx) {
|
|
|
703
703
|
return {
|
|
704
704
|
ready: true,
|
|
705
705
|
selection,
|
|
706
|
-
running:
|
|
706
|
+
running: (() => {
|
|
707
|
+
const latestTurn = folded.items.filter((item) => item.k === 'turnProcess').at(-1);
|
|
708
|
+
return latestTurn ? latestTurn.endTime == null : Boolean(snapshot.running);
|
|
709
|
+
})(),
|
|
707
710
|
questions,
|
|
708
711
|
approvals,
|
|
709
712
|
items: folded.items,
|
|
@@ -981,7 +984,14 @@ export function createSessionsAdapter(ctx) {
|
|
|
981
984
|
const request = {};
|
|
982
985
|
const workspaceId = options && typeof options === 'object' ? options.workspaceId : undefined;
|
|
983
986
|
if (workspaceId) request.workspaceId = workspaceId;
|
|
984
|
-
|
|
987
|
+
if (options?.agentPreset) request.agentPreset = options.agentPreset;
|
|
988
|
+
try {
|
|
989
|
+
return await sessions.create(request);
|
|
990
|
+
} catch (error) {
|
|
991
|
+
if (!options?.agentPreset) throw error;
|
|
992
|
+
delete request.agentPreset;
|
|
993
|
+
return await sessions.create(request);
|
|
994
|
+
}
|
|
985
995
|
}
|
|
986
996
|
|
|
987
997
|
async function waitForReady(sessionId, options) {
|
package/src/client/task-ai.js
CHANGED
|
@@ -31,7 +31,7 @@ export async function runTaskAnalysis({
|
|
|
31
31
|
}
|
|
32
32
|
if (!String(prompt || '').trim()) throw new Error('规划内容不能为空');
|
|
33
33
|
|
|
34
|
-
const sessionId = await adapter.createSession({ workspaceId, title });
|
|
34
|
+
const sessionId = await adapter.createSession({ workspaceId, title, agentPreset: 'minimal' });
|
|
35
35
|
const stop = adapter.open(sessionId, () => {});
|
|
36
36
|
let timedOut = false;
|
|
37
37
|
const startedAt = Date.now();
|
|
@@ -6,8 +6,10 @@ import {
|
|
|
6
6
|
createLocalTaskDraft,
|
|
7
7
|
createFallbackTopology,
|
|
8
8
|
computeLayeredLayout,
|
|
9
|
+
ensureTopologyDependencies,
|
|
9
10
|
} from './task-intelligence.js';
|
|
10
11
|
import { runTaskAnalysis, assistantTextFromView } from './task-ai.js';
|
|
12
|
+
import { pipelineFingerprint } from './pipeline-utils.js';
|
|
11
13
|
|
|
12
14
|
function hashText(value) {
|
|
13
15
|
let hash = 2166136261;
|
|
@@ -31,7 +33,7 @@ function runtimeExecution(view) {
|
|
|
31
33
|
running: Boolean(view?.running),
|
|
32
34
|
waiting: view?.waiting || '',
|
|
33
35
|
error: view?.error || view?.lastError || false,
|
|
34
|
-
done: Boolean(view?.ready && !view?.running && (view?.items || []).
|
|
36
|
+
done: Boolean(view?.ready && !view?.running && (view?.items || []).some((item) => item.k === 'assistant' && String(item.text || '').trim())),
|
|
35
37
|
activityAt: Date.now(),
|
|
36
38
|
};
|
|
37
39
|
}
|
|
@@ -39,7 +41,7 @@ function runtimeExecution(view) {
|
|
|
39
41
|
export function createTaskController({ adapter, taskStore, flow, t, toast, bridge }) {
|
|
40
42
|
const liveRuntime = new Map();
|
|
41
43
|
const runtimeSignatures = new Map();
|
|
42
|
-
|
|
44
|
+
const runtimeSaveTimers = new Map();
|
|
43
45
|
|
|
44
46
|
function rawTasks() {
|
|
45
47
|
return taskStore.snapshot().tasks;
|
|
@@ -84,7 +86,22 @@ export function createTaskController({ adapter, taskStore, flow, t, toast, bridg
|
|
|
84
86
|
const relatedEvents = [...flow.latestByEdge().values()].filter((event) => event.taskId === task.id || (task.canvasIds || []).includes(event.canvasId));
|
|
85
87
|
if (relatedEvents.some((event) => event.status === 'failed')) return 'blocked';
|
|
86
88
|
if (relatedEvents.some((event) => event.status === 'delivering')) return 'running';
|
|
87
|
-
|
|
89
|
+
const expectedStates = (task.sessionIds || []).length;
|
|
90
|
+
if (expectedStates && states.length === expectedStates && states.every((state) => state.done)) {
|
|
91
|
+
const pendingNote = (task.plan?.nodes || []).some((node) => {
|
|
92
|
+
if (node.kind !== 'note' || !node.cardId) return false;
|
|
93
|
+
return (node.dependsOn || []).some((sourceId) => {
|
|
94
|
+
const source = (task.plan.nodes || []).find((candidate) => candidate.id === sourceId && candidate.kind === 'session');
|
|
95
|
+
if (!source?.sessionId) return false;
|
|
96
|
+
const event = flow.latestByEdge().get(source.sessionId + '=>' + 'note:' + node.cardId);
|
|
97
|
+
const sourceCard = bridge.getCards().find((card) => card.sessionId === source.sessionId);
|
|
98
|
+
const latestText = [...(sourceCard?.view?.items || [])].reverse().find((item) => item.k === 'assistant' && String(item.text || '').trim())?.text || '';
|
|
99
|
+
return event?.status !== 'delivered' || event.fingerprint !== pipelineFingerprint(latestText);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
if (pendingNote) return 'running';
|
|
103
|
+
return 'done';
|
|
104
|
+
}
|
|
88
105
|
return task.executionStatus || 'idle';
|
|
89
106
|
}
|
|
90
107
|
function acceptanceFor(task) {
|
|
@@ -148,6 +165,10 @@ export function createTaskController({ adapter, taskStore, flow, t, toast, bridg
|
|
|
148
165
|
...task,
|
|
149
166
|
executionStatus,
|
|
150
167
|
acceptanceStatus,
|
|
168
|
+
...(task.executionStatus !== executionStatus ? (() => {
|
|
169
|
+
taskStore.updateTask(task.id, { executionStatus });
|
|
170
|
+
return {};
|
|
171
|
+
})() : {}),
|
|
151
172
|
reviewStatus: acceptanceStatus,
|
|
152
173
|
status: normalized.status,
|
|
153
174
|
canvasNames: canvasNames(task.canvasIds),
|
|
@@ -161,6 +182,17 @@ export function createTaskController({ adapter, taskStore, flow, t, toast, bridg
|
|
|
161
182
|
};
|
|
162
183
|
}
|
|
163
184
|
function snapshot() {
|
|
185
|
+
for (const card of bridge.getCards()) {
|
|
186
|
+
if (!card.sessionId) continue;
|
|
187
|
+
try {
|
|
188
|
+
card.view = adapter.read(card.sessionId);
|
|
189
|
+
card.running = Boolean(card.view?.running);
|
|
190
|
+
} catch {
|
|
191
|
+
// Keep the last view when a session is temporarily unavailable.
|
|
192
|
+
}
|
|
193
|
+
noteSessionRuntime(card);
|
|
194
|
+
if (!card.running) bridge.maybeDeliverCompleted?.(card);
|
|
195
|
+
}
|
|
164
196
|
return {
|
|
165
197
|
tasks: sortTasks(rawTasks().map(projectTask)),
|
|
166
198
|
canvases: canvases(),
|
|
@@ -173,21 +205,22 @@ export function createTaskController({ adapter, taskStore, flow, t, toast, bridg
|
|
|
173
205
|
running: Boolean(card.running),
|
|
174
206
|
waiting: card.waiting || '',
|
|
175
207
|
error: card.view?.lastError || ['error', 'failure'].includes((card.view?.items || []).at(-1)?.k) || false,
|
|
176
|
-
done: Boolean(card.view?.ready && !card.running && (card.view?.items || []).
|
|
208
|
+
done: Boolean(card.view?.ready && !card.running && !card.queued && (card.view?.items || []).some((item) => item.k === 'assistant' && String(item.text || '').trim())),
|
|
177
209
|
activityAt: card.activityAt || Date.now(),
|
|
178
210
|
};
|
|
179
211
|
const signature = JSON.stringify(runtime);
|
|
180
212
|
if (runtimeSignatures.get(card.sessionId) === signature) return;
|
|
181
213
|
runtimeSignatures.set(card.sessionId, signature);
|
|
182
214
|
liveRuntime.set(card.sessionId, runtime);
|
|
183
|
-
clearTimeout(
|
|
184
|
-
|
|
215
|
+
clearTimeout(runtimeSaveTimers.get(card.sessionId));
|
|
216
|
+
runtimeSaveTimers.set(card.sessionId, setTimeout(() => {
|
|
185
217
|
const next = rawTasks().map((task) => {
|
|
186
218
|
if (!(task.sessionIds || []).includes(card.sessionId)) return task;
|
|
187
219
|
return { ...task, sessionStates: { ...(task.sessionStates || {}), [card.sessionId]: runtime } };
|
|
188
220
|
});
|
|
189
221
|
taskStore.setTasks(next);
|
|
190
|
-
|
|
222
|
+
runtimeSaveTimers.delete(card.sessionId);
|
|
223
|
+
}, 650));
|
|
191
224
|
}
|
|
192
225
|
|
|
193
226
|
function canvasIdsForSession(sessionId) {
|
|
@@ -386,19 +419,35 @@ export function createTaskController({ adapter, taskStore, flow, t, toast, bridg
|
|
|
386
419
|
return fallback;
|
|
387
420
|
}
|
|
388
421
|
const prompt = [
|
|
389
|
-
'你是多 Agent
|
|
422
|
+
'你是多 Agent 工作流规划助手。根据需求复杂度拆成 4-12 个可执行节点,不要凑数;只有职责独立、输入输出明确、可单独验收的工作才单独成节点。简单任务可以少于 4 个,复杂任务应尽量拆细。',
|
|
390
423
|
'只输出 JSON:{"title":"...","goal":"...","acceptanceCriteria":["..."],"nodes":[{"id":"research","kind":"session","title":"...","prompt":"...","dependsOn":[]},{"id":"delivery","kind":"note","title":"结果汇总","note":"# 结果汇总","dependsOn":["research"]}]}。',
|
|
391
|
-
'session
|
|
424
|
+
'session 节点必须是真实可执行工作,覆盖实际需要的分析、设计、实现、验证和交付环节,不得重复或泛泛而谈。note 节点只能做最终或中间结果汇点,不能有下游。dependsOn 填上游节点 id,依赖必须真实,不要简单串成一条长链。每个 session 的 prompt 要包含目标、输入、期望输出和验收标准。',
|
|
392
425
|
'用户需求:' + goal,
|
|
393
426
|
].join('\n');
|
|
394
|
-
const
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
427
|
+
const parsePlan = (text) => {
|
|
428
|
+
const parsed = parseAIResponse(text);
|
|
429
|
+
const candidate = parsed.plan || parsed.topology || parsed;
|
|
430
|
+
return { candidate, normalized: ensureTopologyDependencies(normalizeTopologyPlan(candidate)) };
|
|
431
|
+
};
|
|
432
|
+
let result = await runTaskAnalysis({ adapter, prompt, workspaceId: workspaceId || defaultWorkspaceId(), selection: model });
|
|
433
|
+
let parsedPlan;
|
|
434
|
+
try {
|
|
435
|
+
parsedPlan = parsePlan(result.text);
|
|
436
|
+
} catch {
|
|
437
|
+
result = await runTaskAnalysis({
|
|
438
|
+
adapter,
|
|
439
|
+
prompt: prompt + '\n上一次输出无法解析为有效拓扑。请只返回合法 JSON,不要输出 Markdown、解释或多余文字。',
|
|
440
|
+
workspaceId: workspaceId || defaultWorkspaceId(),
|
|
441
|
+
selection: model,
|
|
442
|
+
});
|
|
443
|
+
parsedPlan = parsePlan(result.text);
|
|
444
|
+
}
|
|
445
|
+
const { candidate, normalized } = parsedPlan;
|
|
398
446
|
const validation = validateTopologyPlan(normalized);
|
|
399
447
|
if (!validation.valid) throw new Error(validation.errors.map((error) => error.message).join(';'));
|
|
400
448
|
normalized.acceptanceCriteria = asArray(candidate.acceptanceCriteria || candidate.acceptance).map(String);
|
|
401
449
|
normalized.workspaceId = workspaceId || defaultWorkspaceId();
|
|
450
|
+
normalized.model = model ? { provider: model.provider, model: model.model || model.id, reasoningEffort: model.reasoningEffort } : undefined;
|
|
402
451
|
const rawNodes = asArray(candidate.nodes);
|
|
403
452
|
for (const node of normalized.nodes) {
|
|
404
453
|
const raw = rawNodes.find((item) => (item.id || item.key) === node.id);
|
|
@@ -450,7 +499,7 @@ export function createTaskController({ adapter, taskStore, flow, t, toast, bridg
|
|
|
450
499
|
}
|
|
451
500
|
|
|
452
501
|
async function materializePlan(value, options = {}) {
|
|
453
|
-
const plan = normalizeTopologyPlan(value);
|
|
502
|
+
const plan = ensureTopologyDependencies(normalizeTopologyPlan(value));
|
|
454
503
|
plan.acceptanceCriteria = asArray(value?.acceptanceCriteria || value?.acceptance).map(String);
|
|
455
504
|
plan.workspaceId = value?.workspaceId || '';
|
|
456
505
|
const rawNodes = asArray(value?.nodes);
|
|
@@ -478,7 +527,15 @@ export function createTaskController({ adapter, taskStore, flow, t, toast, bridg
|
|
|
478
527
|
continue;
|
|
479
528
|
}
|
|
480
529
|
const workspace = adapter.listWorkspaces?.().find((item) => item.id === plan.workspaceId || item.title === node.workspace);
|
|
481
|
-
const sessionId = node.sessionId || await adapter.createSession({ workspaceId: workspace?.id || workspaceId });
|
|
530
|
+
const sessionId = node.sessionId || await adapter.createSession({ workspaceId: workspace?.id || workspaceId, agentPreset: 'minimal' });
|
|
531
|
+
if (plan.model && adapter.selectModel) {
|
|
532
|
+
if (adapter.waitForReady) await adapter.waitForReady(sessionId, { timeoutMs: 15000 });
|
|
533
|
+
await adapter.selectModel(sessionId, {
|
|
534
|
+
provider: plan.model.provider,
|
|
535
|
+
model: plan.model.model || plan.model.id,
|
|
536
|
+
reasoningEffort: plan.model.reasoningEffort,
|
|
537
|
+
});
|
|
538
|
+
}
|
|
482
539
|
const card = bridge.addSession({ sessionId, title: node.title, workspace: workspace?.title || node.workspace || '', x: position.x, y: position.y, w: 380, h: 500 });
|
|
483
540
|
node.sessionId = sessionId;
|
|
484
541
|
cards.set(nodeId, card);
|
|
@@ -615,6 +672,9 @@ export function createTaskController({ adapter, taskStore, flow, t, toast, bridg
|
|
|
615
672
|
},
|
|
616
673
|
async createCanvas(task) { return createCanvas(task); },
|
|
617
674
|
continuationDraft,
|
|
618
|
-
dispose() {
|
|
675
|
+
dispose() {
|
|
676
|
+
for (const timer of runtimeSaveTimers.values()) clearTimeout(timer);
|
|
677
|
+
runtimeSaveTimers.clear();
|
|
678
|
+
},
|
|
619
679
|
};
|
|
620
680
|
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* using the plan or computing a layout.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
const MAX_NODES =
|
|
9
|
+
const MAX_NODES = 12;
|
|
10
10
|
const DEFAULT_TITLE = '任务计划';
|
|
11
11
|
|
|
12
12
|
function isRecord(value) {
|
|
@@ -193,6 +193,26 @@ export function normalizeTopologyPlan(value) {
|
|
|
193
193
|
};
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
+
/**
|
|
197
|
+
* Complete a dependency-free AI plan by using its final session as the integrator.
|
|
198
|
+
* A plan that already has session dependencies is left untouched.
|
|
199
|
+
*/
|
|
200
|
+
export function ensureTopologyDependencies(value) {
|
|
201
|
+
const plan = normalizeTopologyPlan(value);
|
|
202
|
+
const sessions = plan.nodes.filter((node) => node.kind === 'session');
|
|
203
|
+
if (sessions.length < 2 || sessions.some((node) => node.dependsOn.length > 0)) return plan;
|
|
204
|
+
|
|
205
|
+
const notes = plan.nodes.filter((node) => node.kind === 'note');
|
|
206
|
+
const preferredId = notes.flatMap((node) => node.dependsOn).find((id) => sessions.some((node) => node.id === id));
|
|
207
|
+
const sink = preferredId ? sessions.find((node) => node.id === preferredId) : sessions.at(-1);
|
|
208
|
+
const others = sessions.filter((node) => node !== sink);
|
|
209
|
+
sink.dependsOn = others.map((node) => node.id);
|
|
210
|
+
for (const note of notes) {
|
|
211
|
+
if (!note.dependsOn.length) note.dependsOn = [sink.id];
|
|
212
|
+
}
|
|
213
|
+
return plan;
|
|
214
|
+
}
|
|
215
|
+
|
|
196
216
|
/** Validate all topology invariants and return machine-readable errors. */
|
|
197
217
|
export function validateTopologyPlan(value) {
|
|
198
218
|
let plan;
|
|
@@ -208,7 +228,7 @@ export function validateTopologyPlan(value) {
|
|
|
208
228
|
const errors = [];
|
|
209
229
|
const add = (code, message, details = {}) => errors.push({ code, message, ...details });
|
|
210
230
|
if (plan.nodes.length < 1 || plan.nodes.length > MAX_NODES) {
|
|
211
|
-
add('NODE_COUNT', '拓扑计划必须包含 1-
|
|
231
|
+
add('NODE_COUNT', '拓扑计划必须包含 1-12 个节点', { count: plan.nodes.length });
|
|
212
232
|
}
|
|
213
233
|
|
|
214
234
|
const counts = new Map();
|