dsh-workflow-canvas 0.2.2 → 0.2.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/client.js +129 -27
- package/index.js +149 -14
- package/package.json +1 -1
- package/skills/workflow-canvas/SKILL.md +3 -3
package/client.js
CHANGED
|
@@ -169,6 +169,9 @@ window.__ModuleLoader__.load({
|
|
|
169
169
|
exportFail: '复制失败(剪贴板不可用)',
|
|
170
170
|
autoLayoutBtn: '⊞ 自动排版',
|
|
171
171
|
layoutDone: '已自动整理布局',
|
|
172
|
+
clearCanvasBtn: '✕ 清空画布',
|
|
173
|
+
newBlankCanvas: '+ 新建空白画布',
|
|
174
|
+
clearedCanvas: '已清空画布(可用 ↶ 撤销)',
|
|
172
175
|
cycleBlocked: '不能形成环,已阻止连线',
|
|
173
176
|
builtinTemplates: '内置示例模板',
|
|
174
177
|
myPresets: '我的预设',
|
|
@@ -267,6 +270,9 @@ window.__ModuleLoader__.load({
|
|
|
267
270
|
exportFail: 'Copy failed (clipboard unavailable)',
|
|
268
271
|
autoLayoutBtn: '⊞ Auto layout',
|
|
269
272
|
layoutDone: 'Layout tidied',
|
|
273
|
+
clearCanvasBtn: '✕ Clear canvas',
|
|
274
|
+
newBlankCanvas: '+ New blank canvas',
|
|
275
|
+
clearedCanvas: 'Canvas cleared (use Undo to restore)',
|
|
270
276
|
cycleBlocked: 'Cannot create a cycle',
|
|
271
277
|
builtinTemplates: 'Starter templates',
|
|
272
278
|
myPresets: 'Saved presets',
|
|
@@ -835,6 +841,43 @@ window.__ModuleLoader__.load({
|
|
|
835
841
|
return set;
|
|
836
842
|
}
|
|
837
843
|
|
|
844
|
+
/**
|
|
845
|
+
* Reachable agent nodes with zero outgoing edges when the graph has at least
|
|
846
|
+
* one reachable non-entry Lead that is NOT an ancestor of that agent (so the
|
|
847
|
+
* agent likely forgot to wire into a downstream or terminal Lead).
|
|
848
|
+
*/
|
|
849
|
+
function deadEndNodeIds(nodes, edges) {
|
|
850
|
+
const list = Array.isArray(nodes) ? nodes : [];
|
|
851
|
+
const linkList = Array.isArray(edges) ? edges : [];
|
|
852
|
+
const reachable = reachableFrom(list, linkList);
|
|
853
|
+
const downstreamLeads = list.filter((n) => n.kind === 'lead' && n.id !== 'lead' && reachable.has(n.id));
|
|
854
|
+
if (!downstreamLeads.length) return new Set();
|
|
855
|
+
const hasOut = new Set(linkList.map((e) => e.from));
|
|
856
|
+
const parents = new Map();
|
|
857
|
+
for (const e of linkList) {
|
|
858
|
+
if (!parents.has(e.to)) parents.set(e.to, []);
|
|
859
|
+
parents.get(e.to).push(e.from);
|
|
860
|
+
}
|
|
861
|
+
const ancestorsOf = (id) => {
|
|
862
|
+
const seen = new Set();
|
|
863
|
+
const stack = [id];
|
|
864
|
+
while (stack.length) {
|
|
865
|
+
const cur = stack.pop();
|
|
866
|
+
for (const p of parents.get(cur) || []) {
|
|
867
|
+
if (!seen.has(p)) { seen.add(p); stack.push(p); }
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
return seen;
|
|
871
|
+
};
|
|
872
|
+
const out = new Set();
|
|
873
|
+
for (const n of list) {
|
|
874
|
+
if (n.kind === 'lead' || !reachable.has(n.id) || hasOut.has(n.id)) continue;
|
|
875
|
+
const anc = ancestorsOf(n.id);
|
|
876
|
+
if (downstreamLeads.some((ln) => !anc.has(ln.id))) out.add(n.id);
|
|
877
|
+
}
|
|
878
|
+
return out;
|
|
879
|
+
}
|
|
880
|
+
|
|
838
881
|
/** True when adding `fromId -> toId` would create a cycle or point into entry Lead. */
|
|
839
882
|
function wouldCycle(nodes, edges, fromId, toId) {
|
|
840
883
|
if (!fromId || !toId || fromId === toId || toId === 'lead') return true;
|
|
@@ -1022,6 +1065,7 @@ window.__ModuleLoader__.load({
|
|
|
1022
1065
|
{ id: 'n_b', kind: 'agent', label: en ? 'Option B (Bold)' : '方案 B(创新)', provider: '', model: '', reasoning: '', preset: 'minimal', keepSession: false, role: en ? 'Propose a high-leverage alternative with better long-term payoff.' : '提出上限更高、长期收益更大的进阶方案。' },
|
|
1023
1066
|
{ id: 'n_pick', kind: 'lead', label: en ? 'Lead Pick' : 'Lead 拍板', provider: '', model: '', role: en ? 'Compare both options and pick the direction to execute.' : '对比两份方案,选定最终路线并补充约束。' },
|
|
1024
1067
|
{ id: 'n_exec', kind: 'agent', label: en ? 'Execute' : '执行落地', provider: '', model: '', reasoning: '', preset: 'standard', keepSession: false, role: en ? 'Deliver the chosen solution end to end.' : '按照拍板路线完成最终交付。' },
|
|
1068
|
+
{ id: 'n_review', kind: 'lead', label: en ? 'Lead Review' : 'Lead 验收', provider: '', model: '', role: en ? 'Verify the deliverable matches the chosen direction and sign off.' : '核对最终产出是否符合拍板方向,确认无误后交付。' },
|
|
1025
1069
|
];
|
|
1026
1070
|
const abEdges = [
|
|
1027
1071
|
{ id: 'a1', from: 'lead', to: 'n_a', type: 'prompt' },
|
|
@@ -1029,6 +1073,7 @@ window.__ModuleLoader__.load({
|
|
|
1029
1073
|
{ id: 'a3', from: 'n_a', to: 'n_pick', type: 'prompt' },
|
|
1030
1074
|
{ id: 'a4', from: 'n_b', to: 'n_pick', type: 'prompt' },
|
|
1031
1075
|
{ id: 'a5', from: 'n_pick', to: 'n_exec', type: 'prompt' },
|
|
1076
|
+
{ id: 'a6', from: 'n_exec', to: 'n_review', type: 'prompt' },
|
|
1032
1077
|
];
|
|
1033
1078
|
return [
|
|
1034
1079
|
{
|
|
@@ -1045,7 +1090,7 @@ window.__ModuleLoader__.load({
|
|
|
1045
1090
|
},
|
|
1046
1091
|
{
|
|
1047
1092
|
id: 'tpl-ab',
|
|
1048
|
-
name: en ? 'Parallel Options → Decide → Execute' : '并行方案对比 → 拍板 → 执行',
|
|
1093
|
+
name: en ? 'Parallel Options → Decide → Execute → Review' : '并行方案对比 → 拍板 → 执行 → 验收',
|
|
1049
1094
|
nodes: layoutGraph(abNodes, abEdges),
|
|
1050
1095
|
edges: abEdges,
|
|
1051
1096
|
},
|
|
@@ -1376,12 +1421,15 @@ window.__ModuleLoader__.load({
|
|
|
1376
1421
|
}, [openModelFor]);
|
|
1377
1422
|
|
|
1378
1423
|
// Publishing costs one visible command row in the conversation, so it only
|
|
1379
|
-
// happens when the user enables the canvas
|
|
1380
|
-
|
|
1424
|
+
// happens when the user enables the canvas, loads a preset/import, clears,
|
|
1425
|
+
// or asks for it explicitly.
|
|
1426
|
+
const pushPlan = (nextEnabled, overrideNodes, overrideEdges) => {
|
|
1381
1427
|
try {
|
|
1382
1428
|
const face = sessionFace(sessionId);
|
|
1383
1429
|
if (!face || typeof face.command !== 'function') { flash(t('syncFailed')); return; }
|
|
1384
|
-
const
|
|
1430
|
+
const curNodes = Array.isArray(overrideNodes) ? overrideNodes : nodesRef.current;
|
|
1431
|
+
const curEdges = Array.isArray(overrideEdges) ? overrideEdges : edgesRef.current;
|
|
1432
|
+
const res = buildPlan(curNodes, curEdges);
|
|
1385
1433
|
const payload = res.error
|
|
1386
1434
|
? { enabled: nextEnabled, error: res.error }
|
|
1387
1435
|
: { enabled: nextEnabled, plan: res.plan };
|
|
@@ -1856,6 +1904,28 @@ window.__ModuleLoader__.load({
|
|
|
1856
1904
|
flash(t('layoutDone'));
|
|
1857
1905
|
};
|
|
1858
1906
|
|
|
1907
|
+
const clearCanvas = () => {
|
|
1908
|
+
const blank = [{ id: 'lead', kind: 'lead', x: 40, y: 203, label: 'Lead', task: '', provider: '', model: '', role: '' }];
|
|
1909
|
+
pushSnapshot();
|
|
1910
|
+
if (enabled) {
|
|
1911
|
+
skipDirtyOnce.current = true;
|
|
1912
|
+
setEnabled(false);
|
|
1913
|
+
setDirty(false);
|
|
1914
|
+
pushPlan(false, blank, []);
|
|
1915
|
+
}
|
|
1916
|
+
setNodes(blank);
|
|
1917
|
+
setEdges([]);
|
|
1918
|
+
setSelectedIds([]);
|
|
1919
|
+
setRoleEditFor(null);
|
|
1920
|
+
setOpenModelFor(null);
|
|
1921
|
+
setPresetOpen(null);
|
|
1922
|
+
setMenuOpen(false);
|
|
1923
|
+
snapshotStaleCatalog();
|
|
1924
|
+
setRunsById({});
|
|
1925
|
+
setTimeout(() => centerOn(40 + NODE_W / 2, 203 + NODE_H / 2, 1), 0);
|
|
1926
|
+
flash(t('clearedCanvas'));
|
|
1927
|
+
};
|
|
1928
|
+
|
|
1859
1929
|
const exportToClipboard = () => {
|
|
1860
1930
|
const cleanNodes = nodesRef.current.map((n) => {
|
|
1861
1931
|
const { runs: _runs, ...rest } = n;
|
|
@@ -2452,6 +2522,7 @@ window.__ModuleLoader__.load({
|
|
|
2452
2522
|
doc = JSON.parse(text.slice(start, end + 1));
|
|
2453
2523
|
} catch (_e) { flash(t('importBad')); return; }
|
|
2454
2524
|
if (!applyCanvasDoc(doc.canvas || doc)) { flash(t('importBad')); return; }
|
|
2525
|
+
if (enabled) setTimeout(() => pushPlan(true), 0);
|
|
2455
2526
|
flash(t('importOk') + (doc.canvas || doc).nodes.length);
|
|
2456
2527
|
};
|
|
2457
2528
|
try {
|
|
@@ -2467,6 +2538,10 @@ window.__ModuleLoader__.load({
|
|
|
2467
2538
|
const preset = presets[name];
|
|
2468
2539
|
if (!preset || !Array.isArray(preset.nodes) || !Array.isArray(preset.edges)) { flash(t('invalidPreset')); return; }
|
|
2469
2540
|
pushSnapshot();
|
|
2541
|
+
if (enabled) {
|
|
2542
|
+
skipDirtyOnce.current = true;
|
|
2543
|
+
pushPlan(true, preset.nodes, preset.edges);
|
|
2544
|
+
}
|
|
2470
2545
|
setNodes(preset.nodes);
|
|
2471
2546
|
setEdges(preset.edges);
|
|
2472
2547
|
setSelectedIds([]);
|
|
@@ -2482,6 +2557,10 @@ window.__ModuleLoader__.load({
|
|
|
2482
2557
|
const clonedNodes = tpl.nodes.map((n) => ({ ...n }));
|
|
2483
2558
|
const clonedEdges = tpl.edges.map((e) => ({ ...e }));
|
|
2484
2559
|
pushSnapshot();
|
|
2560
|
+
if (enabled) {
|
|
2561
|
+
skipDirtyOnce.current = true;
|
|
2562
|
+
pushPlan(true, clonedNodes, clonedEdges);
|
|
2563
|
+
}
|
|
2485
2564
|
setNodes(clonedNodes);
|
|
2486
2565
|
setEdges(clonedEdges);
|
|
2487
2566
|
setSelectedIds([]);
|
|
@@ -2687,11 +2766,7 @@ window.__ModuleLoader__.load({
|
|
|
2687
2766
|
}
|
|
2688
2767
|
const reachableIds = reachableFrom(nodes, edges);
|
|
2689
2768
|
const nodeById = new Map(nodes.map((n) => [n.id, n]));
|
|
2690
|
-
const
|
|
2691
|
-
const hasOutNode = new Set(edges.map((e) => e.from));
|
|
2692
|
-
const deadEndIds = new Set(hasDownstreamLead
|
|
2693
|
-
? nodes.filter((n) => n.kind !== 'lead' && reachableIds.has(n.id) && !hasOutNode.has(n.id)).map((n) => n.id)
|
|
2694
|
-
: []);
|
|
2769
|
+
const deadEndIds = deadEndNodeIds(nodes, edges);
|
|
2695
2770
|
|
|
2696
2771
|
// Identify intermediate/final Lead nodes whose upstream subagents are all
|
|
2697
2772
|
// finished and whose downstream has not started yet ("Ready for Lead").
|
|
@@ -2732,6 +2807,7 @@ window.__ModuleLoader__.load({
|
|
|
2732
2807
|
const isCompletedLink = enabled && !highlighted && statusById[edge.from] === 'done'
|
|
2733
2808
|
&& (statusById[edge.to] === 'done' || statusById[edge.to] === 'running' || leadReadyIds.has(edge.to));
|
|
2734
2809
|
const dimmed = hasSel && !linkedToSel && !highlighted && !isFlowing;
|
|
2810
|
+
const strokeColor = highlighted ? '#e5534b' : color;
|
|
2735
2811
|
const baseWidth = highlighted ? 3 : (linkedToSel || isFlowing ? 2.6 : 2);
|
|
2736
2812
|
const baseOpacity = dimmed ? 0.26 : (isFlowing || linkedToSel ? 1 : (isCompletedLink ? 0.92 : 0.78));
|
|
2737
2813
|
const useGlow = fxLevel === 'vivid' && !dimmed && (highlighted || isFlowing || linkedToSel || edge.type !== 'prompt');
|
|
@@ -2739,13 +2815,39 @@ window.__ModuleLoader__.load({
|
|
|
2739
2815
|
const showBead = isFlowing && fxLevel === 'vivid';
|
|
2740
2816
|
|
|
2741
2817
|
return h('g', { key: edge.id, style: { pointerEvents: 'none' } },
|
|
2818
|
+
// Vector halo layers instead of an SVG objectBoundingBox <filter>, which
|
|
2819
|
+
// Chromium clips to 0px height on strictly horizontal links (from.y === to.y).
|
|
2820
|
+
useGlow && h('path', {
|
|
2821
|
+
d,
|
|
2822
|
+
stroke: strokeColor,
|
|
2823
|
+
strokeWidth: baseWidth + 7,
|
|
2824
|
+
strokeOpacity: showDashFlow ? 0.1 : 0.16,
|
|
2825
|
+
strokeLinecap: 'round',
|
|
2826
|
+
fill: 'none',
|
|
2827
|
+
}),
|
|
2828
|
+
useGlow && h('path', {
|
|
2829
|
+
d,
|
|
2830
|
+
stroke: strokeColor,
|
|
2831
|
+
strokeWidth: baseWidth + 3.2,
|
|
2832
|
+
strokeOpacity: showDashFlow ? 0.18 : 0.3,
|
|
2833
|
+
strokeLinecap: 'round',
|
|
2834
|
+
fill: 'none',
|
|
2835
|
+
}),
|
|
2742
2836
|
h('path', {
|
|
2743
2837
|
d,
|
|
2744
|
-
stroke:
|
|
2838
|
+
stroke: strokeColor,
|
|
2745
2839
|
strokeWidth: baseWidth,
|
|
2746
2840
|
strokeOpacity: showDashFlow ? 0.35 : baseOpacity,
|
|
2747
2841
|
fill: 'none',
|
|
2748
|
-
|
|
2842
|
+
}),
|
|
2843
|
+
showDashFlow && fxLevel === 'vivid' && h('path', {
|
|
2844
|
+
d,
|
|
2845
|
+
className: 'dsh-wc-edge-flow',
|
|
2846
|
+
stroke: color,
|
|
2847
|
+
strokeWidth: 6.4,
|
|
2848
|
+
strokeOpacity: 0.28,
|
|
2849
|
+
strokeLinecap: 'round',
|
|
2850
|
+
fill: 'none',
|
|
2749
2851
|
}),
|
|
2750
2852
|
showDashFlow && h('path', {
|
|
2751
2853
|
d,
|
|
@@ -2754,13 +2856,10 @@ window.__ModuleLoader__.load({
|
|
|
2754
2856
|
strokeWidth: fxLevel === 'vivid' ? 2.8 : 2.4,
|
|
2755
2857
|
strokeLinecap: 'round',
|
|
2756
2858
|
fill: 'none',
|
|
2757
|
-
filter: fxLevel === 'vivid' ? 'url(#dsh-wc-glow)' : undefined,
|
|
2758
2859
|
}),
|
|
2759
|
-
showBead && h('
|
|
2760
|
-
r:
|
|
2761
|
-
fill: color,
|
|
2762
|
-
filter: 'url(#dsh-wc-glow)',
|
|
2763
|
-
},
|
|
2860
|
+
showBead && h('g', null,
|
|
2861
|
+
h('circle', { r: 6.5, fill: color, fillOpacity: 0.28 }),
|
|
2862
|
+
h('circle', { r: 3.3, fill: color }),
|
|
2764
2863
|
h('animateMotion', {
|
|
2765
2864
|
dur: '1.25s',
|
|
2766
2865
|
repeatCount: 'indefinite',
|
|
@@ -2892,6 +2991,12 @@ window.__ModuleLoader__.load({
|
|
|
2892
2991
|
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
2893
2992
|
onClick: () => { setMenuOpen(false); autoLayout(); },
|
|
2894
2993
|
}, t('autoLayoutBtn')),
|
|
2994
|
+
h('div', {
|
|
2995
|
+
style: { ...S.moreRow, color: '#e5534b' },
|
|
2996
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
2997
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
2998
|
+
onClick: () => { clearCanvas(); },
|
|
2999
|
+
}, t('clearCanvasBtn')),
|
|
2895
3000
|
h('div', {
|
|
2896
3001
|
style: S.moreRow,
|
|
2897
3002
|
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
@@ -2949,6 +3054,12 @@ window.__ModuleLoader__.load({
|
|
|
2949
3054
|
const names = Object.keys(presets);
|
|
2950
3055
|
const templates = builtinTemplates(lang);
|
|
2951
3056
|
return h('div', { style: S.presetMenu, onMouseDown: (e) => e.stopPropagation() },
|
|
3057
|
+
h('div', {
|
|
3058
|
+
style: { ...S.presetRow, color: C.accent, fontWeight: 500, borderBottom: '1px solid ' + C.border, marginBottom: '4px', paddingBottom: '6px', borderRadius: '4px 4px 0 0' },
|
|
3059
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
3060
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
3061
|
+
onClick: () => clearCanvas(),
|
|
3062
|
+
}, h('span', { style: S.presetRowText }, t('newBlankCanvas'))),
|
|
2952
3063
|
h('div', { style: S.menuHead }, t('builtinTemplates')),
|
|
2953
3064
|
templates.map((tpl) => h('div', {
|
|
2954
3065
|
key: tpl.id,
|
|
@@ -3048,15 +3159,6 @@ window.__ModuleLoader__.load({
|
|
|
3048
3159
|
},
|
|
3049
3160
|
},
|
|
3050
3161
|
h('svg', { width: contentW, height: contentH, style: { position: 'absolute', left: 0, top: 0, pointerEvents: 'none', overflow: 'visible' } },
|
|
3051
|
-
fxLevel === 'vivid' && h('defs', null,
|
|
3052
|
-
h('filter', { id: 'dsh-wc-glow', x: '-30%', y: '-30%', width: '160%', height: '160%' },
|
|
3053
|
-
h('feGaussianBlur', { stdDeviation: '2.2', result: 'blur' }),
|
|
3054
|
-
h('feMerge', null,
|
|
3055
|
-
h('feMergeNode', { in: 'blur' }),
|
|
3056
|
-
h('feMergeNode', { in: 'SourceGraphic' }),
|
|
3057
|
-
),
|
|
3058
|
-
),
|
|
3059
|
-
),
|
|
3060
3162
|
h('g', null, edgeEls),
|
|
3061
3163
|
cutPath.length > 1 && h('polyline', {
|
|
3062
3164
|
points: cutPath.map((pt) => (pt.x + WORLD_PAD) + ',' + (pt.y + WORLD_PAD)).join(' '),
|
|
@@ -3328,7 +3430,7 @@ window.__ModuleLoader__.load({
|
|
|
3328
3430
|
try { console.error('[workflow-canvas] apply failed', error); } catch (_e) { /* ignore */ }
|
|
3329
3431
|
}
|
|
3330
3432
|
},
|
|
3331
|
-
__test: { topoOrder, wouldCycle, layoutGraph, builtinTemplates, nextEffectLevel, zoomAroundPoint, scrubZoom, buildWorkflowScript, buildPlan, loadDoc, saveDoc, storageKey, socketCenterY, distanceToEdge, edgeCurve },
|
|
3433
|
+
__test: { topoOrder, wouldCycle, layoutGraph, builtinTemplates, deadEndNodeIds, nextEffectLevel, zoomAroundPoint, scrubZoom, buildWorkflowScript, buildPlan, loadDoc, saveDoc, storageKey, socketCenterY, distanceToEdge, edgeCurve },
|
|
3332
3434
|
};
|
|
3333
3435
|
},
|
|
3334
3436
|
});
|
package/index.js
CHANGED
|
@@ -342,10 +342,30 @@ function analyzeCanvasWarnings(nodes, edges) {
|
|
|
342
342
|
+ orphans.map((n) => (n.label || n.id) + '(' + n.id + ')').join('、'));
|
|
343
343
|
}
|
|
344
344
|
|
|
345
|
-
const
|
|
346
|
-
if (
|
|
345
|
+
const downstreamLeads = list.filter((n) => n.kind === 'lead' && reachable.has(n.id));
|
|
346
|
+
if (downstreamLeads.length) {
|
|
347
347
|
const hasOut = new Set(linkList.map((e) => e.from));
|
|
348
|
-
const
|
|
348
|
+
const parents = new Map();
|
|
349
|
+
for (const e of linkList) {
|
|
350
|
+
if (!parents.has(e.to)) parents.set(e.to, []);
|
|
351
|
+
parents.get(e.to).push(e.from);
|
|
352
|
+
}
|
|
353
|
+
const ancestorsOf = (id) => {
|
|
354
|
+
const seen = new Set();
|
|
355
|
+
const stack = [id];
|
|
356
|
+
while (stack.length) {
|
|
357
|
+
const cur = stack.pop();
|
|
358
|
+
for (const p of parents.get(cur) || []) {
|
|
359
|
+
if (!seen.has(p)) { seen.add(p); stack.push(p); }
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return seen;
|
|
363
|
+
};
|
|
364
|
+
const deadEnds = list.filter((n) => {
|
|
365
|
+
if (n.kind === 'lead' || !reachable.has(n.id) || hasOut.has(n.id)) return false;
|
|
366
|
+
const anc = ancestorsOf(n.id);
|
|
367
|
+
return downstreamLeads.some((ln) => !anc.has(ln.id));
|
|
368
|
+
});
|
|
349
369
|
if (deadEnds.length) {
|
|
350
370
|
warnings.push('以下子代理节点没有出边,产出未显式连入下游或终审 Lead:'
|
|
351
371
|
+ deadEnds.map((n) => (n.label || n.id) + '(' + n.id + ')').join('、'));
|
|
@@ -637,13 +657,62 @@ function inspectPlan(sid) {
|
|
|
637
657
|
nodes,
|
|
638
658
|
edges,
|
|
639
659
|
warnings: analyzeCanvasWarnings(nodes, edges),
|
|
640
|
-
paused: Boolean(sid && runBySession.
|
|
660
|
+
paused: Boolean(sid && runBySession.get(sid) && runBySession.get(sid).waitingLead),
|
|
641
661
|
};
|
|
642
662
|
// Never attach `error: undefined`: DSH's lossless JSON validator rejects keys with undefined values.
|
|
643
663
|
if (payload.error) out.error = String(payload.error);
|
|
644
664
|
return out;
|
|
645
665
|
}
|
|
646
666
|
|
|
667
|
+
/** Extract the active session id from a DSH `AssembleContext`. */
|
|
668
|
+
function sessionIdFromContext(assembleCtx) {
|
|
669
|
+
if (!assembleCtx || typeof assembleCtx !== 'object') return '';
|
|
670
|
+
if (assembleCtx.agent && assembleCtx.agent.id !== undefined) return String(assembleCtx.agent.id);
|
|
671
|
+
if (assembleCtx.sessionId !== undefined) return String(assembleCtx.sessionId);
|
|
672
|
+
return '';
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* Per-turn runtime prompt context injected ONLY for the session whose canvas is
|
|
677
|
+
* currently enabled. Returns '' for disabled canvases, unrelated sessions, and
|
|
678
|
+
* subagent sessions (zero token overhead and no recursive triggering).
|
|
679
|
+
*/
|
|
680
|
+
function buildActiveCanvasContext(sid) {
|
|
681
|
+
if (!sid) return '';
|
|
682
|
+
const payload = canvasBySession.get(String(sid));
|
|
683
|
+
if (!payload || !payload.enabled || payload.error) return '';
|
|
684
|
+
const plan = payload.plan;
|
|
685
|
+
const nodes = withoutEntry(plan && plan.nodes);
|
|
686
|
+
if (!nodes.length) return '';
|
|
687
|
+
|
|
688
|
+
const runState = runBySession.get(String(sid));
|
|
689
|
+
if (runState && runState.waitingLead) {
|
|
690
|
+
const wl = runState.waitingLead;
|
|
691
|
+
return [
|
|
692
|
+
'[Workflow Canvas Active — Paused at Lead Step]',
|
|
693
|
+
'当前会话的工作流画布正暂停在中间 Lead 节点「' + wl.label + '」(分工:' + (wl.role || wl.label) + ')。',
|
|
694
|
+
'- 若用户的当前消息是在拍板、确认、补充决策或要求继续:请整理决策结论并直接调用 `canvas_workflow({ leadResult: "..." })` 恢复下游节点运行。',
|
|
695
|
+
'- 若用户要求放弃当前进度从头重跑:调用 `canvas_workflow({ reset: true })`。',
|
|
696
|
+
'- 若用户要求修改画布结构/分工:先 `canvas_inspect` 再用 `canvas_patch`。',
|
|
697
|
+
].join('\n');
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
const preview = nodes
|
|
701
|
+
.slice(0, 8)
|
|
702
|
+
.map((n) => (n.kind === 'lead' ? '〔Lead〕' : '') + (n.label || n.id))
|
|
703
|
+
.join(' → ') + (nodes.length > 8 ? ' …' : '');
|
|
704
|
+
const hasTask = Boolean(String((plan && plan.task) || '').trim());
|
|
705
|
+
return [
|
|
706
|
+
'[Workflow Canvas Active]',
|
|
707
|
+
'当前会话的右侧工作流画布处于「● 已启用」状态(共 ' + nodes.length + ' 个执行节点:' + preview + ';入口总任务:' + (hasTask ? '已填写' : '未填写') + ')。',
|
|
708
|
+
'- 若用户发出任务请求、布置工作或说「开始 / 执行 / 跑一次」:请直接调用 `canvas_workflow` 按画布编排执行('
|
|
709
|
+
+ (hasTask ? '可直接沿用入口总任务;若用户给出了新任务则通过 task 参数传入' : '请将用户的任务内容作为 task 参数传入')
|
|
710
|
+
+ '),不要绕过画布直接自己完成。',
|
|
711
|
+
'- 若用户在讨论或要求修改画布结构、模型、分工或连线:请先 `canvas_inspect` 再用 `canvas_patch` 就地修改,不要直接运行。',
|
|
712
|
+
'- 仅当用户明确只是闲聊、问无关问题或要求先停用画布时,才无需调用 `canvas_workflow`。',
|
|
713
|
+
].join('\n');
|
|
714
|
+
}
|
|
715
|
+
|
|
647
716
|
/** Takes a plan directly so tests can feed any plan shape (sync, generate, patch). */
|
|
648
717
|
async function executePlan(scope, plan, args, exec) {
|
|
649
718
|
const opts = args || {};
|
|
@@ -686,7 +755,7 @@ async function executePlan(scope, plan, args, exec) {
|
|
|
686
755
|
const sig = JSON.stringify(plan);
|
|
687
756
|
let state = runBySession.get(sid);
|
|
688
757
|
if (!state || state.sig !== sig) {
|
|
689
|
-
state = { sig, done: new Set(), results: {}, labels: {}, failed: {}, emptyOutputs: {} };
|
|
758
|
+
state = { sig, done: new Set(), results: {}, labels: {}, failed: {}, emptyOutputs: {}, waitingLead: null };
|
|
690
759
|
runBySession.set(sid, state);
|
|
691
760
|
}
|
|
692
761
|
if (!state.emptyOutputs) state.emptyOutputs = {};
|
|
@@ -725,6 +794,7 @@ async function executePlan(scope, plan, args, exec) {
|
|
|
725
794
|
|
|
726
795
|
for (;;) {
|
|
727
796
|
if (isAborted()) {
|
|
797
|
+
if (sid) runBySession.delete(sid);
|
|
728
798
|
return { error: '工作流执行已取消。' };
|
|
729
799
|
}
|
|
730
800
|
const remaining = runnable.filter((n) => !state.done.has(n.id));
|
|
@@ -747,6 +817,7 @@ async function executePlan(scope, plan, args, exec) {
|
|
|
747
817
|
const { node, outcome } = await Promise.race(inFlight.values());
|
|
748
818
|
inFlight.delete(node.id);
|
|
749
819
|
if (isAborted()) {
|
|
820
|
+
if (sid) runBySession.delete(sid);
|
|
750
821
|
return { error: '工作流执行已取消。' };
|
|
751
822
|
}
|
|
752
823
|
state.results[node.id] = outcome.text;
|
|
@@ -765,7 +836,42 @@ async function executePlan(scope, plan, args, exec) {
|
|
|
765
836
|
|
|
766
837
|
const leadNode = ready.find((n) => n.kind === 'lead');
|
|
767
838
|
if (!leadNode) return { error: '没有可执行的节点。' };
|
|
839
|
+
const leadSessions = depsOf(leadNode)
|
|
840
|
+
.filter((id) => (plan.edges || []).some((e) => e.to === leadNode.id && e.from === id && e.type === 'session-ref'))
|
|
841
|
+
.map((id) => ({
|
|
842
|
+
label: labelOf.get(id) || id,
|
|
843
|
+
childId: liveChild.get(String(sid || '') + '::' + id)
|
|
844
|
+
|| childByNode.get(String(sid || '') + '::' + id)
|
|
845
|
+
|| null,
|
|
846
|
+
}));
|
|
847
|
+
const hasDownstreamWork = remaining.some((n) => n.id !== leadNode.id);
|
|
848
|
+
if (!hasDownstreamWork && leadResult === undefined) {
|
|
849
|
+
// Terminal Lead: zero downstream nodes remain, so complete the run directly
|
|
850
|
+
// and hand off final review/delivery to the Lead without a redundant extra turn.
|
|
851
|
+
if (sid) runBySession.delete(sid);
|
|
852
|
+
saveStore();
|
|
853
|
+
return {
|
|
854
|
+
status: 'done',
|
|
855
|
+
finalLead: {
|
|
856
|
+
label: leadNode.label,
|
|
857
|
+
role: leadNode.role || leadNode.label,
|
|
858
|
+
needs: depsOf(leadNode).map((id) => byId.get(id).label),
|
|
859
|
+
},
|
|
860
|
+
results: state.results,
|
|
861
|
+
labels: state.labels,
|
|
862
|
+
failed: Object.values(state.failed),
|
|
863
|
+
emptyOutputs: Object.values(state.emptyOutputs),
|
|
864
|
+
sessions: leadSessions,
|
|
865
|
+
skipped,
|
|
866
|
+
hint: '所有子代理已完成。最后一步由你(Lead 本体)按要求完成终审/汇总后直接向用户交付即可,无需再次调用 canvas_workflow。',
|
|
867
|
+
};
|
|
868
|
+
}
|
|
768
869
|
if (leadResult === undefined) {
|
|
870
|
+
state.waitingLead = {
|
|
871
|
+
id: leadNode.id,
|
|
872
|
+
label: leadNode.label,
|
|
873
|
+
role: leadNode.role || leadNode.label,
|
|
874
|
+
};
|
|
769
875
|
return {
|
|
770
876
|
status: 'need-lead',
|
|
771
877
|
node: {
|
|
@@ -777,17 +883,11 @@ async function executePlan(scope, plan, args, exec) {
|
|
|
777
883
|
labels: state.labels,
|
|
778
884
|
failed: Object.values(state.failed),
|
|
779
885
|
emptyOutputs: Object.values(state.emptyOutputs),
|
|
780
|
-
sessions:
|
|
781
|
-
.filter((id) => (plan.edges || []).some((e) => e.to === leadNode.id && e.from === id && e.type === 'session-ref'))
|
|
782
|
-
.map((id) => ({
|
|
783
|
-
label: labelOf.get(id) || id,
|
|
784
|
-
childId: liveChild.get(String(sid || '') + '::' + id)
|
|
785
|
-
|| childByNode.get(String(sid || '') + '::' + id)
|
|
786
|
-
|| null,
|
|
787
|
-
})),
|
|
886
|
+
sessions: leadSessions,
|
|
788
887
|
hint: '这一步由你(Lead 本体)完成。完成后再次调用本工具,把结果放进 leadResult 继续;若需从头重跑可传 reset: true。',
|
|
789
888
|
};
|
|
790
889
|
}
|
|
890
|
+
state.waitingLead = null;
|
|
791
891
|
state.results[leadNode.id] = leadResult;
|
|
792
892
|
state.labels[leadNode.id] = leadNode.label;
|
|
793
893
|
state.done.add(leadNode.id);
|
|
@@ -823,7 +923,20 @@ function fallbackGuide() {
|
|
|
823
923
|
}
|
|
824
924
|
export function apply(ctx) {
|
|
825
925
|
loadStore();
|
|
826
|
-
|
|
926
|
+
ctx.inject(['systemPrompt'], (promptCtx) => {
|
|
927
|
+
try {
|
|
928
|
+
if (promptCtx.systemPrompt && typeof promptCtx.systemPrompt.context === 'function') {
|
|
929
|
+
promptCtx.effect(() => promptCtx.systemPrompt.context({
|
|
930
|
+
name: 'app:workflow-canvas-active',
|
|
931
|
+
order: 950,
|
|
932
|
+
text: (assembleCtx) => buildActiveCanvasContext(sessionIdFromContext(assembleCtx)),
|
|
933
|
+
}), 'workflow-canvas: active context');
|
|
934
|
+
}
|
|
935
|
+
} catch (_e) {
|
|
936
|
+
/* systemPrompt service unavailable */
|
|
937
|
+
}
|
|
938
|
+
});
|
|
939
|
+
ctx.inject(['skills'], (scope) => {
|
|
827
940
|
try {
|
|
828
941
|
scope.effect(() => scope.skills.registerProvider(() => ({
|
|
829
942
|
name: 'dsh-workflow-canvas',
|
|
@@ -1152,6 +1265,7 @@ export function apply(ctx) {
|
|
|
1152
1265
|
properties: {
|
|
1153
1266
|
status: { type: 'string' },
|
|
1154
1267
|
node: { type: 'object' },
|
|
1268
|
+
finalLead: { type: 'object' },
|
|
1155
1269
|
results: { type: 'object' },
|
|
1156
1270
|
labels: { type: 'object' },
|
|
1157
1271
|
failed: { type: 'array' },
|
|
@@ -1201,6 +1315,25 @@ export function apply(ctx) {
|
|
|
1201
1315
|
const skip = Array.isArray(v.skipped) && v.skipped.length
|
|
1202
1316
|
? '\n\n已跳过(未连线):' + v.skipped.join('、')
|
|
1203
1317
|
: '';
|
|
1318
|
+
if (v.finalLead) {
|
|
1319
|
+
const fl = v.finalLead;
|
|
1320
|
+
const handed = Array.isArray(v.sessions) ? v.sessions.filter((s) => s && s.childId) : [];
|
|
1321
|
+
const handover = handed.length
|
|
1322
|
+
? '\n\n可用会话(session 连线):' + handed.map((s) => s.label + ' → ' + s.childId).join(';')
|
|
1323
|
+
+ '\n如需局部追问或返工,可直接给对应子代理发消息。'
|
|
1324
|
+
: '';
|
|
1325
|
+
return [{
|
|
1326
|
+
type: 'text',
|
|
1327
|
+
text: '所有子代理已完成,现在进入终审 Lead 步骤「' + fl.label + '」:' + fl.role
|
|
1328
|
+
+ '\n需要用到:' + ((fl.needs && fl.needs.length) ? fl.needs.join('、') : '(无上游)')
|
|
1329
|
+
+ failedList
|
|
1330
|
+
+ emptyList
|
|
1331
|
+
+ '\n\n已完成节点的结果:\n' + body
|
|
1332
|
+
+ handover
|
|
1333
|
+
+ skip
|
|
1334
|
+
+ '\n\n' + (v.hint || ''),
|
|
1335
|
+
}];
|
|
1336
|
+
}
|
|
1204
1337
|
return [{ type: 'text', text: '画布执行完成。' + failedList + emptyList + '\n\n' + body + skip }];
|
|
1205
1338
|
}
|
|
1206
1339
|
return [{ type: 'text', text: JSON.stringify(v) }];
|
|
@@ -1227,6 +1360,8 @@ export {
|
|
|
1227
1360
|
normalizeCanvas,
|
|
1228
1361
|
applyPatch,
|
|
1229
1362
|
inspectPlan,
|
|
1363
|
+
sessionIdFromContext,
|
|
1364
|
+
buildActiveCanvasContext,
|
|
1230
1365
|
runPlan,
|
|
1231
1366
|
executePlan,
|
|
1232
1367
|
};
|
package/package.json
CHANGED
|
@@ -49,11 +49,11 @@ Links only join matching types. Nodes the entry Lead cannot reach are skipped at
|
|
|
49
49
|
|
|
50
50
|
## Running
|
|
51
51
|
|
|
52
|
-
1. The canvas must be enabled (the pill over the canvas); `canvas_workflow` refuses while it is disabled.
|
|
52
|
+
1. The canvas must be enabled (the pill over the canvas); `canvas_workflow` refuses while it is disabled. While enabled, the host automatically injects a per-session runtime context reminder on each turn.
|
|
53
53
|
2. You may pass `task` to override the entry Lead's task (handy when reusing a preset), or `reset: true` to discard a paused run and start from scratch.
|
|
54
54
|
3. Subagent nodes run in a dynamic concurrency pool of up to four: as soon as any node finishes, newly unblocked downstream subagents start immediately without waiting for slower siblings.
|
|
55
|
-
4.
|
|
56
|
-
5.
|
|
55
|
+
4. Intermediate downstream Lead nodes pause the run (`status: "need-lead"`). Complete that Lead step yourself, then call `canvas_workflow` again with `leadResult` to resume downstream nodes — do not spawn an agent for it.
|
|
56
|
+
5. A **terminal** Lead node (zero remaining downstream nodes) finishes directly with `status: "done"` and `finalLead`: complete the review/summary and reply directly to the user — no extra `canvas_workflow` callback is needed.
|
|
57
57
|
6. When a `session-ref` link points into that Lead node the result lists `sessions: [{ label, childId }]`; you may message those agents directly to follow up.
|
|
58
58
|
7. Only assign image/visual inspection roles to models that declare image input support.
|
|
59
59
|
|