dsh-workflow-canvas 1.0.0 → 1.0.1
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 +77 -9
- package/index.js +18 -5
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
window.__ModuleLoader__.load({
|
|
2
|
+
// Must stay identical to the published package name; DSH matches the sidebar
|
|
3
|
+
// client bundle by this id and silently skips loading if it drifts.
|
|
2
4
|
id: 'dsh-workflow-canvas',
|
|
3
5
|
factory(require) {
|
|
4
6
|
const React = require('react');
|
|
@@ -42,6 +44,8 @@ window.__ModuleLoader__.load({
|
|
|
42
44
|
|
|
43
45
|
const FX_KEY = STORAGE_PREFIX + 'fx';
|
|
44
46
|
const FX_LEVELS = ['minimal', 'standard', 'vivid'];
|
|
47
|
+
const PARALLEL_KEY = STORAGE_PREFIX + 'maxParallel';
|
|
48
|
+
const PARALLEL_STEPS = [1, 2, 4, 6, 8];
|
|
45
49
|
const STYLE_ID = 'dsh-workflow-canvas-styles';
|
|
46
50
|
|
|
47
51
|
/** Inject scoped CSS keyframes once; never touches host selectors. */
|
|
@@ -184,6 +188,8 @@ window.__ModuleLoader__.load({
|
|
|
184
188
|
fxMinimal: '极简',
|
|
185
189
|
fxStandard: '标准',
|
|
186
190
|
fxVivid: '炫酷',
|
|
191
|
+
maxParallelLabel: '最大并发',
|
|
192
|
+
tipMaxParallel: '默认 4 路并行(可选 1 / 2 / 4 / 6 / 8)。并发过高容易触发 API 限流(429)、增加多子代理同时写同一工作区的文件冲突,并放大单轮报错时的额度消耗;纯只读调研可适当调高。',
|
|
187
193
|
tipLeadReady: '上游节点已全部完成,正等待在对话里拍板继续',
|
|
188
194
|
stDeadEnd: '无出边',
|
|
189
195
|
tipDeadEnd: '该子代理没有下游连线,运行时不生效;请连入下游节点或终审 Lead',
|
|
@@ -294,6 +300,8 @@ window.__ModuleLoader__.load({
|
|
|
294
300
|
fxMinimal: 'Minimal',
|
|
295
301
|
fxStandard: 'Standard',
|
|
296
302
|
fxVivid: 'Vivid',
|
|
303
|
+
maxParallelLabel: 'Max parallel',
|
|
304
|
+
tipMaxParallel: 'Default 4 concurrent subagents (1 / 2 / 4 / 6 / 8). Higher concurrency can trigger API rate limits (429), increase workspace file-edit conflicts, and widen token spend on failure; raising it is safest for read-only research.',
|
|
297
305
|
tipLeadReady: 'Upstream steps are done; waiting for Lead in chat',
|
|
298
306
|
stDeadEnd: 'No out-link',
|
|
299
307
|
tipDeadEnd: 'This subagent has no outgoing link and is skipped at run time; wire it into a downstream node or Lead',
|
|
@@ -1043,7 +1051,7 @@ window.__ModuleLoader__.load({
|
|
|
1043
1051
|
}
|
|
1044
1052
|
|
|
1045
1053
|
/** Everything the Host executor needs; no prompts are pre-rendered here. */
|
|
1046
|
-
function buildPlan(nodes, edges) {
|
|
1054
|
+
function buildPlan(nodes, edges, opts) {
|
|
1047
1055
|
const entry = nodes.find((n) => n.id === 'lead');
|
|
1048
1056
|
if (!entry) return { error: '缺少入口 Lead 节点' };
|
|
1049
1057
|
const task = String(entry.task || '').trim();
|
|
@@ -1067,9 +1075,14 @@ window.__ModuleLoader__.load({
|
|
|
1067
1075
|
.filter((e) => (e.from === 'lead' || activeIds.has(e.from)) && activeIds.has(e.to))
|
|
1068
1076
|
.map((e) => ({ from: e.from, to: e.to, type: e.type || 'prompt' }));
|
|
1069
1077
|
|
|
1078
|
+
const maxParallel = opts && Number.isFinite(Number(opts.maxParallel))
|
|
1079
|
+
? Math.max(1, Math.min(8, Math.floor(Number(opts.maxParallel))))
|
|
1080
|
+
: 4;
|
|
1081
|
+
|
|
1070
1082
|
return {
|
|
1071
1083
|
plan: {
|
|
1072
1084
|
task,
|
|
1085
|
+
maxParallel,
|
|
1073
1086
|
skipped: skipped.map((n) => n.label || n.id),
|
|
1074
1087
|
nodes: active.map((n) => ({
|
|
1075
1088
|
id: n.id,
|
|
@@ -1129,6 +1142,25 @@ window.__ModuleLoader__.load({
|
|
|
1129
1142
|
return FX_LEVELS[(idx + 1) % FX_LEVELS.length];
|
|
1130
1143
|
}
|
|
1131
1144
|
|
|
1145
|
+
function loadMaxParallel() {
|
|
1146
|
+
try {
|
|
1147
|
+
const raw = Number(window.localStorage.getItem(PARALLEL_KEY));
|
|
1148
|
+
if (Number.isFinite(raw) && raw >= 1 && raw <= 8) return Math.floor(raw);
|
|
1149
|
+
} catch (_e) { /* ignore */ }
|
|
1150
|
+
return 4;
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
function saveMaxParallel(n) {
|
|
1154
|
+
try {
|
|
1155
|
+
if (Number.isFinite(n) && n >= 1 && n <= 8) window.localStorage.setItem(PARALLEL_KEY, String(Math.floor(n)));
|
|
1156
|
+
} catch (_e) { /* ignore */ }
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
function nextMaxParallel(cur) {
|
|
1160
|
+
const idx = PARALLEL_STEPS.indexOf(Number(cur));
|
|
1161
|
+
return PARALLEL_STEPS[(idx + 1) % PARALLEL_STEPS.length];
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1132
1164
|
/** Compute the next `{ k, x, y }` keeping the content point under `(mx, my)` fixed. */
|
|
1133
1165
|
function zoomAroundPoint(cur, mx, my, deltaY, deltaMode) {
|
|
1134
1166
|
if (!deltaY) return cur;
|
|
@@ -1259,6 +1291,9 @@ window.__ModuleLoader__.load({
|
|
|
1259
1291
|
const [helpOpen, setHelpOpen] = useState(false);
|
|
1260
1292
|
const [cutMode, setCutMode] = useState(loadCutMode);
|
|
1261
1293
|
const [fxLevel, setFxLevel] = useState(loadEffectLevel);
|
|
1294
|
+
const [maxParallel, setMaxParallel] = useState(loadMaxParallel);
|
|
1295
|
+
const maxParallelRef = useRef(maxParallel);
|
|
1296
|
+
maxParallelRef.current = maxParallel;
|
|
1262
1297
|
useEffect(() => { ensureStyles(); }, []);
|
|
1263
1298
|
const cutRef = useRef(null);
|
|
1264
1299
|
/** Timestamp of the remote document being applied, so saving it does not bump the clock. */
|
|
@@ -1321,8 +1356,12 @@ window.__ModuleLoader__.load({
|
|
|
1321
1356
|
saveDoc(sessionId, { nodes, edges, enabled }, stamp === null ? undefined : stamp);
|
|
1322
1357
|
}, [sessionId, nodes, edges, enabled]);
|
|
1323
1358
|
|
|
1324
|
-
|
|
1325
|
-
|
|
1359
|
+
// Plan signature excludes visual (x, y) coordinates so dragging nodes does
|
|
1360
|
+
// not trigger false "unsaved changes" warnings; `skipDirtyOnce` suppresses
|
|
1361
|
+
// the dirty flag when applying a canvas written by the Host itself.
|
|
1362
|
+
const planSig = (nextEnabled, curNodes, curEdges, overrideParallel) => {
|
|
1363
|
+
const mp = typeof overrideParallel === 'number' ? overrideParallel : maxParallelRef.current;
|
|
1364
|
+
const res = buildPlan(curNodes, curEdges, { maxParallel: mp });
|
|
1326
1365
|
const payload = res.error
|
|
1327
1366
|
? { enabled: nextEnabled, error: res.error }
|
|
1328
1367
|
: { enabled: nextEnabled, plan: res.plan };
|
|
@@ -1386,13 +1425,13 @@ window.__ModuleLoader__.load({
|
|
|
1386
1425
|
// Publishing costs one visible command row in the conversation, so it only
|
|
1387
1426
|
// happens when the user enables the canvas, loads a preset/import, clears,
|
|
1388
1427
|
// or asks for it explicitly.
|
|
1389
|
-
const pushPlan = (nextEnabled, overrideNodes, overrideEdges) => {
|
|
1428
|
+
const pushPlan = (nextEnabled, overrideNodes, overrideEdges, overrideParallel) => {
|
|
1390
1429
|
try {
|
|
1391
1430
|
const face = sessionFace(sessionId);
|
|
1392
1431
|
if (!face || typeof face.command !== 'function') { flash(t('syncFailed')); return; }
|
|
1393
1432
|
const curNodes = Array.isArray(overrideNodes) ? overrideNodes : nodesRef.current;
|
|
1394
1433
|
const curEdges = Array.isArray(overrideEdges) ? overrideEdges : edgesRef.current;
|
|
1395
|
-
const sig = planSig(nextEnabled, curNodes, curEdges);
|
|
1434
|
+
const sig = planSig(nextEnabled, curNodes, curEdges, overrideParallel);
|
|
1396
1435
|
if (sig === lastSync.current) { setDirty(false); flash(t('upToDate')); return; }
|
|
1397
1436
|
const line = '/canvas-sync ' + encodeURIComponent(sig);
|
|
1398
1437
|
const hasStandardAgent = nextEnabled && curNodes.some((n) => n && n.kind !== 'lead' && (n.preset || 'standard') !== 'minimal');
|
|
@@ -2791,9 +2830,12 @@ window.__ModuleLoader__.load({
|
|
|
2791
2830
|
const soloLeadIds = soloLeadNodeIds(nodes, edges);
|
|
2792
2831
|
const deadEndIds = deadEndNodeIds(nodes, edges);
|
|
2793
2832
|
|
|
2794
|
-
//
|
|
2795
|
-
//
|
|
2796
|
-
//
|
|
2833
|
+
// Lead nodes are never spawned, so their status is derived from graph state:
|
|
2834
|
+
// - Intermediate Lead (has downstream): glows "Ready" until any child starts,
|
|
2835
|
+
// then settles to "Done".
|
|
2836
|
+
// - Terminal Lead (no downstream): Host finishes in one shot, so it glows only
|
|
2837
|
+
// while the main conversation is still streaming (`sessionRunning`), then
|
|
2838
|
+
// settles to "Done" once the turn ends.
|
|
2797
2839
|
const leadReadyIds = new Set();
|
|
2798
2840
|
const leadDoneIds = new Set();
|
|
2799
2841
|
if (enabled) {
|
|
@@ -3049,6 +3091,32 @@ window.__ModuleLoader__.load({
|
|
|
3049
3091
|
flash(t('fxLabel') + t('sep') + fxName(next));
|
|
3050
3092
|
},
|
|
3051
3093
|
}, t('fxLabel') + t('sep') + fxName(fxLevel)),
|
|
3094
|
+
h('div', {
|
|
3095
|
+
style: { ...S.moreRow, display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '8px' },
|
|
3096
|
+
title: t('tipMaxParallel'),
|
|
3097
|
+
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
3098
|
+
onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
|
|
3099
|
+
onClick: () => {
|
|
3100
|
+
const next = nextMaxParallel(maxParallel);
|
|
3101
|
+
setMaxParallel(next);
|
|
3102
|
+
maxParallelRef.current = next;
|
|
3103
|
+
saveMaxParallel(next);
|
|
3104
|
+
if (enabled) pushPlan(true, undefined, undefined, next);
|
|
3105
|
+
else flash(t('maxParallelLabel') + t('sep') + next);
|
|
3106
|
+
},
|
|
3107
|
+
},
|
|
3108
|
+
h('span', null, t('maxParallelLabel') + t('sep') + maxParallel),
|
|
3109
|
+
h('span', {
|
|
3110
|
+
title: t('tipMaxParallel'),
|
|
3111
|
+
style: {
|
|
3112
|
+
display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
|
|
3113
|
+
width: '14px', height: '14px', borderRadius: '50%',
|
|
3114
|
+
border: '1px solid ' + (maxParallel > 4 ? '#d29922' : C.dim),
|
|
3115
|
+
color: maxParallel > 4 ? '#d29922' : C.dim,
|
|
3116
|
+
fontSize: '10px', fontWeight: 700, lineHeight: '12px', flex: '0 0 auto',
|
|
3117
|
+
},
|
|
3118
|
+
}, '!'),
|
|
3119
|
+
),
|
|
3052
3120
|
h('div', {
|
|
3053
3121
|
style: S.moreRow,
|
|
3054
3122
|
onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
|
|
@@ -3477,7 +3545,7 @@ window.__ModuleLoader__.load({
|
|
|
3477
3545
|
try { console.error('[workflow-canvas] apply failed', error); } catch (_e) { /* ignore */ }
|
|
3478
3546
|
}
|
|
3479
3547
|
},
|
|
3480
|
-
__test: { topoOrder, wouldCycle, soloLeadNodeIds, layoutGraph, builtinTemplates, deadEndNodeIds, nextEffectLevel, zoomAroundPoint, scrubZoom, buildPlan, loadDoc, saveDoc, storageKey, socketCenterY, distanceToEdge, edgeCurve },
|
|
3548
|
+
__test: { topoOrder, wouldCycle, soloLeadNodeIds, layoutGraph, builtinTemplates, deadEndNodeIds, nextEffectLevel, nextMaxParallel, zoomAroundPoint, scrubZoom, buildPlan, loadDoc, saveDoc, storageKey, socketCenterY, distanceToEdge, edgeCurve },
|
|
3481
3549
|
};
|
|
3482
3550
|
},
|
|
3483
3551
|
});
|
package/index.js
CHANGED
|
@@ -24,9 +24,14 @@ import { fileURLToPath } from 'node:url';
|
|
|
24
24
|
const canvasBySession = new Map();
|
|
25
25
|
/** In-flight run progress per Session id. */
|
|
26
26
|
const runBySession = new Map();
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Two separate maps by design:
|
|
29
|
+
* - `childByNode`: persisted memory slot written ONLY when `keepSession` is ON,
|
|
30
|
+
* so temporary `keepSession=false` runs never overwrite saved memory.
|
|
31
|
+
* - `liveChild`: latest child id in this process (updated even when Memory is OFF)
|
|
32
|
+
* so downstream `session-ref` purple links can always continue the upstream run.
|
|
33
|
+
*/
|
|
28
34
|
const childByNode = new Map();
|
|
29
|
-
/** node id → child id created in this process, safe to resume. */
|
|
30
35
|
const liveChild = new Map();
|
|
31
36
|
|
|
32
37
|
function storePath() {
|
|
@@ -716,8 +721,9 @@ function sessionIdFromContext(assembleCtx) {
|
|
|
716
721
|
|
|
717
722
|
/**
|
|
718
723
|
* Per-turn runtime prompt context injected ONLY for the session whose canvas is
|
|
719
|
-
* currently enabled.
|
|
720
|
-
*
|
|
724
|
+
* currently enabled. DSH invokes `systemPrompt.context` for both main chats AND
|
|
725
|
+
* spawned subagents, so strict `sid` matching (returning '' on miss) is required
|
|
726
|
+
* to prevent leaking canvas instructions into subagents and causing recursion.
|
|
721
727
|
*/
|
|
722
728
|
function buildActiveCanvasContext(sid) {
|
|
723
729
|
if (!sid) return '';
|
|
@@ -835,7 +841,10 @@ async function executePlan(scope, plan, args, exec) {
|
|
|
835
841
|
.filter((id) => byId.has(id));
|
|
836
842
|
|
|
837
843
|
let leadResult = typeof opts.leadResult === 'string' ? opts.leadResult : undefined;
|
|
838
|
-
const
|
|
844
|
+
const rawMaxParallel = opts.maxParallel !== undefined ? opts.maxParallel : plan.maxParallel;
|
|
845
|
+
const MAX_PARALLEL = Number.isFinite(Number(rawMaxParallel))
|
|
846
|
+
? Math.max(1, Math.min(8, Math.floor(Number(rawMaxParallel))))
|
|
847
|
+
: 4;
|
|
839
848
|
// Event-driven concurrency pool: as soon as any node finishes, newly unblocked
|
|
840
849
|
// downstream agents start immediately instead of waiting for slower siblings.
|
|
841
850
|
const inFlight = new Map();
|
|
@@ -867,6 +876,9 @@ async function executePlan(scope, plan, args, exec) {
|
|
|
867
876
|
if (sid) runBySession.delete(sid);
|
|
868
877
|
return { error: '工作流执行已取消。' };
|
|
869
878
|
}
|
|
879
|
+
// On circuit-break halt, stop launching new downstream waves immediately,
|
|
880
|
+
// but let already in-flight siblings settle so no orphan promises or partial
|
|
881
|
+
// results are dropped before returning the halted report.
|
|
870
882
|
if (haltedReason && inFlight.size === 0) {
|
|
871
883
|
if (sid) runBySession.delete(sid);
|
|
872
884
|
saveStore();
|
|
@@ -1348,6 +1360,7 @@ export function apply(ctx) {
|
|
|
1348
1360
|
task: { type: 'string', description: 'Optional overall task overriding the entry Lead task for this run (useful for reusing a preset).' },
|
|
1349
1361
|
reset: { type: 'boolean', description: 'Discard any paused run progress and start from the beginning.' },
|
|
1350
1362
|
clearMemory: { type: 'boolean', description: 'Forget saved subagent sessions (keepSession memory) for this session before running so every node starts fresh.' },
|
|
1363
|
+
maxParallel: { type: 'integer', minimum: 1, maximum: 8, description: 'Optional concurrency limit override (1–8, default 4).' },
|
|
1351
1364
|
},
|
|
1352
1365
|
additionalProperties: false,
|
|
1353
1366
|
},
|