@fieldwangai/agentflow 0.1.65 → 0.1.67
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/bin/lib/ui-server.mjs
CHANGED
|
@@ -2416,25 +2416,31 @@ function workspaceOutputProtocolRequirements(graph, nodeId) {
|
|
|
2416
2416
|
].join("\n");
|
|
2417
2417
|
}
|
|
2418
2418
|
|
|
2419
|
-
function workspaceRunPlan(graph, runNodeId) {
|
|
2419
|
+
function workspaceRunPlan(graph, runNodeId, scopedRoot = "") {
|
|
2420
2420
|
const instances = graph?.instances && typeof graph.instances === "object" ? graph.instances : {};
|
|
2421
2421
|
const edges = Array.isArray(graph?.edges) ? graph.edges : [];
|
|
2422
2422
|
const target = String(runNodeId || "").trim();
|
|
2423
2423
|
if (!target || !instances[target]) throw new Error("Missing workspace run node");
|
|
2424
|
-
const
|
|
2425
|
-
const
|
|
2424
|
+
const incoming = new Map();
|
|
2425
|
+
const controlDownstream = new Map();
|
|
2426
|
+
const validEdges = [];
|
|
2426
2427
|
for (const edge of edges) {
|
|
2427
2428
|
const source = String(edge?.source || "");
|
|
2428
2429
|
const dest = String(edge?.target || "");
|
|
2429
2430
|
if (!source || !dest || !instances[source] || !instances[dest]) continue;
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2431
|
+
validEdges.push(edge);
|
|
2432
|
+
if (!incoming.has(dest)) incoming.set(dest, []);
|
|
2433
|
+
incoming.get(dest).push(edge);
|
|
2434
|
+
if (workspaceIsControlEdge(graph, edge)) {
|
|
2435
|
+
if (!controlDownstream.has(source)) controlDownstream.set(source, []);
|
|
2436
|
+
controlDownstream.get(source).push(dest);
|
|
2437
|
+
}
|
|
2434
2438
|
}
|
|
2435
2439
|
const needed = new Set();
|
|
2436
2440
|
const pauseNodeIds = new Set();
|
|
2437
|
-
|
|
2441
|
+
// Downstream execution is selected only by control edges. Data/context edges
|
|
2442
|
+
// are used later to pull in upstream dependencies for selected nodes.
|
|
2443
|
+
const addNeeded = (id) => {
|
|
2438
2444
|
if (!id || needed.has(id)) return;
|
|
2439
2445
|
const defId = String(instances[id]?.definitionId || "");
|
|
2440
2446
|
if (id !== target && defId === "workspace_run") {
|
|
@@ -2442,23 +2448,42 @@ function workspaceRunPlan(graph, runNodeId) {
|
|
|
2442
2448
|
return;
|
|
2443
2449
|
}
|
|
2444
2450
|
needed.add(id);
|
|
2445
|
-
for (const next of downstream.get(id) || []) visit(next);
|
|
2446
2451
|
};
|
|
2447
|
-
|
|
2452
|
+
const visitControlDownstream = (id) => {
|
|
2453
|
+
for (const next of controlDownstream.get(id) || []) {
|
|
2454
|
+
const before = needed.size;
|
|
2455
|
+
addNeeded(next);
|
|
2456
|
+
if (needed.size !== before) visitControlDownstream(next);
|
|
2457
|
+
}
|
|
2458
|
+
};
|
|
2459
|
+
visitControlDownstream(target);
|
|
2448
2460
|
needed.delete(target);
|
|
2449
|
-
const
|
|
2450
|
-
for (
|
|
2451
|
-
|
|
2452
|
-
|
|
2461
|
+
const dependencyQueue = Array.from(needed);
|
|
2462
|
+
for (let i = 0; i < dependencyQueue.length; i++) {
|
|
2463
|
+
const id = dependencyQueue[i];
|
|
2464
|
+
for (const edge of incoming.get(id) || []) {
|
|
2465
|
+
const source = String(edge?.source || "");
|
|
2466
|
+
if (!source || source === target || needed.has(source)) continue;
|
|
2467
|
+
if (!workspaceNeedsUpstreamExecutionForEdge(graph, edge, scopedRoot)) continue;
|
|
2468
|
+
addNeeded(source);
|
|
2469
|
+
if (needed.has(source)) dependencyQueue.push(source);
|
|
2453
2470
|
}
|
|
2454
2471
|
}
|
|
2472
|
+
const indegree = new Map(Array.from(needed).map((id) => [id, 0]));
|
|
2473
|
+
const dependents = new Map(Array.from(needed).map((id) => [id, []]));
|
|
2474
|
+
for (const edge of validEdges) {
|
|
2475
|
+
const source = String(edge?.source || "");
|
|
2476
|
+
const dest = String(edge?.target || "");
|
|
2477
|
+
if (!needed.has(source) || !needed.has(dest)) continue;
|
|
2478
|
+
indegree.set(dest, (indegree.get(dest) || 0) + 1);
|
|
2479
|
+
dependents.get(source)?.push(dest);
|
|
2480
|
+
}
|
|
2455
2481
|
const ready = Array.from(needed).filter((id) => (indegree.get(id) || 0) === 0);
|
|
2456
2482
|
const ordered = [];
|
|
2457
2483
|
while (ready.length) {
|
|
2458
2484
|
const id = ready.shift();
|
|
2459
2485
|
ordered.push(id);
|
|
2460
|
-
for (const next of
|
|
2461
|
-
if (!needed.has(next)) continue;
|
|
2486
|
+
for (const next of dependents.get(id) || []) {
|
|
2462
2487
|
const n = (indegree.get(next) || 0) - 1;
|
|
2463
2488
|
indegree.set(next, n);
|
|
2464
2489
|
if (n === 0) ready.push(next);
|
|
@@ -2470,6 +2495,59 @@ function workspaceRunPlan(graph, runNodeId) {
|
|
|
2470
2495
|
return { order: ordered, pauseNodeIds: Array.from(pauseNodeIds) };
|
|
2471
2496
|
}
|
|
2472
2497
|
|
|
2498
|
+
function workspaceIsControlInputSlot(slot) {
|
|
2499
|
+
const name = String(slot?.name || "");
|
|
2500
|
+
const type = String(slot?.type || "");
|
|
2501
|
+
return type === "node" || name === "prev" || name === "next";
|
|
2502
|
+
}
|
|
2503
|
+
|
|
2504
|
+
function workspaceIsControlOutputSlot(slot) {
|
|
2505
|
+
const name = String(slot?.name || "");
|
|
2506
|
+
const type = String(slot?.type || "");
|
|
2507
|
+
return type === "node" || name === "prev" || name === "next";
|
|
2508
|
+
}
|
|
2509
|
+
|
|
2510
|
+
function workspaceIsControlEdge(graph, edge) {
|
|
2511
|
+
return workspaceIsControlOutputSlot(workspaceSourceSlotForEdge(graph, edge)) ||
|
|
2512
|
+
workspaceIsControlInputSlot(workspaceTargetSlotForEdge(graph, edge));
|
|
2513
|
+
}
|
|
2514
|
+
|
|
2515
|
+
function workspaceNeedsUpstreamExecutionForEdge(graph, edge, scopedRoot = "") {
|
|
2516
|
+
if (workspaceIsControlEdge(graph, edge)) return true;
|
|
2517
|
+
return !workspaceEdgeHasCachedOutput(graph, edge, scopedRoot);
|
|
2518
|
+
}
|
|
2519
|
+
|
|
2520
|
+
function workspaceEdgeHasCachedOutput(graph, edge, scopedRoot = "") {
|
|
2521
|
+
const sourceId = String(edge?.source || "");
|
|
2522
|
+
const instances = graph?.instances && typeof graph.instances === "object" ? graph.instances : {};
|
|
2523
|
+
const source = instances[sourceId];
|
|
2524
|
+
if (!source) return false;
|
|
2525
|
+
const slot = workspaceSourceSlotForEdge(graph, edge);
|
|
2526
|
+
if (!isWorkspaceSemanticOutputSlot(slot) && slot && String(slot?.type || "") !== "node") {
|
|
2527
|
+
const value = workspaceSlotValue(slot);
|
|
2528
|
+
if (workspaceCachedOutputValueExists(value, scopedRoot)) return true;
|
|
2529
|
+
}
|
|
2530
|
+
const defId = String(source.definitionId || "");
|
|
2531
|
+
if (workspaceDisplayKind(defId) && String(source.body || "").trim()) return true;
|
|
2532
|
+
if (defId === "provide_str" || defId === "provide_bool" || defId === "provide_file") {
|
|
2533
|
+
return Boolean(String(workspaceInstanceText(source) || "").trim());
|
|
2534
|
+
}
|
|
2535
|
+
return false;
|
|
2536
|
+
}
|
|
2537
|
+
|
|
2538
|
+
function workspaceCachedOutputValueExists(value, scopedRoot = "") {
|
|
2539
|
+
const text = String(value || "").trim();
|
|
2540
|
+
if (!text) return false;
|
|
2541
|
+
const outputRel = workspaceSafeNodeOutputRelPath(text);
|
|
2542
|
+
if (!outputRel) return true;
|
|
2543
|
+
const root = path.resolve(scopedRoot || "");
|
|
2544
|
+
if (!root) return false;
|
|
2545
|
+
const abs = path.resolve(root, outputRel);
|
|
2546
|
+
const rootWithSep = root.endsWith(path.sep) ? root : `${root}${path.sep}`;
|
|
2547
|
+
if (abs !== root && !abs.startsWith(rootWithSep)) return false;
|
|
2548
|
+
return fs.existsSync(abs) && fs.statSync(abs).isFile();
|
|
2549
|
+
}
|
|
2550
|
+
|
|
2473
2551
|
function workspaceUpstreamText(graph, nodeId, outputs) {
|
|
2474
2552
|
const edges = Array.isArray(graph?.edges) ? graph.edges : [];
|
|
2475
2553
|
const incoming = edges
|
|
@@ -2498,13 +2576,17 @@ function isWorkspaceSemanticInputSlot(slot) {
|
|
|
2498
2576
|
return type === "node" || name === "prev" || name === "next" || name === "skillsContext" || name === "mcpContext" || name === "workspaceContext" || name === "gitContext";
|
|
2499
2577
|
}
|
|
2500
2578
|
|
|
2501
|
-
function workspaceAgentInputBlock(inputValues = {}) {
|
|
2579
|
+
function workspaceAgentInputBlock(inputValues = {}, inputMounts = {}) {
|
|
2502
2580
|
const entries = Object.entries(inputValues || {}).filter(([name, value]) => String(name || "").trim() && String(value || "").trim());
|
|
2503
2581
|
if (!entries.length) return "## 输入\n\n无。";
|
|
2504
2582
|
const lines = entries.map(([name, value]) => {
|
|
2505
2583
|
const text = String(value || "");
|
|
2506
2584
|
const clipped = text.length > 6000 ? `${text.slice(0, 6000)}\n...[已截断 ${text.length - 6000} 字]` : text;
|
|
2507
|
-
|
|
2585
|
+
const mount = inputMounts?.[name];
|
|
2586
|
+
const mountNote = mount?.mounted
|
|
2587
|
+
? `\n\n> 源文件:\`${mount.source}\`\n> 已挂载为当前任务可读文件:\`${mount.mounted}\`。请读取挂载路径,不要修改源文件。`
|
|
2588
|
+
: "";
|
|
2589
|
+
return `### ${name}\n\n${clipped}${mountNote}`;
|
|
2508
2590
|
});
|
|
2509
2591
|
return ["## 输入", "", ...lines].join("\n");
|
|
2510
2592
|
}
|
|
@@ -2519,6 +2601,7 @@ function workspaceNodeFileBoundaryBlock(runPackage = {}) {
|
|
|
2519
2601
|
"",
|
|
2520
2602
|
nodeRunDir ? `- 当前执行目录:\`${nodeRunDir}\`。` : "",
|
|
2521
2603
|
nodeTmpDir ? `- 临时文件只能写入:\`${nodeTmpDir}\`,也可通过环境变量 \`AGENTFLOW_NODE_TMP_DIR\` 获取。` : "",
|
|
2604
|
+
Object.keys(runPackage?.inputMounts || {}).length ? "- 已挂载的输入文件位于本任务 `inputs/`;`inputs/` 只用于读取,正式产物仍写入 `outputs/`。" : "",
|
|
2522
2605
|
`- 正式产物写入本任务 \`${outputsRel}/\`,例如 \`${outputsRel}/result.html\`、\`${outputsRel}/result.md\`;返回时仍使用 \`${outputsRel}/...\` 相对路径。`,
|
|
2523
2606
|
"- 不要在执行目录根部创建 `temp_*`、`_out.json`、`tmp.html` 等临时产物。",
|
|
2524
2607
|
"- 不要自行删除 run package;AgentFlow 会在运行结束后统一清理。",
|
|
@@ -2574,6 +2657,18 @@ function workspaceResolveBodyPlaceholders(body, inputValues = {}) {
|
|
|
2574
2657
|
});
|
|
2575
2658
|
}
|
|
2576
2659
|
|
|
2660
|
+
function workspacePromptUpstreamText(upstreamText, runPackage = {}) {
|
|
2661
|
+
const raw = String(upstreamText || "").trim();
|
|
2662
|
+
if (!raw) return "";
|
|
2663
|
+
for (const [name, mount] of Object.entries(runPackage?.inputMounts || {})) {
|
|
2664
|
+
if (!mount?.mounted) continue;
|
|
2665
|
+
if (raw === String(mount.source || "").trim() || raw === String(mount.mounted || "").trim()) {
|
|
2666
|
+
return `输入 \`${name}\` 已挂载为 \`${mount.mounted}\`。源文件:\`${mount.source}\`。`;
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2669
|
+
return upstreamText;
|
|
2670
|
+
}
|
|
2671
|
+
|
|
2577
2672
|
function parseWorkspaceSkillKeys(raw) {
|
|
2578
2673
|
const text = String(raw || "").trim();
|
|
2579
2674
|
if (!text) return [];
|
|
@@ -2751,7 +2846,7 @@ function workspaceNodePrompt(graph, nodeId, upstreamText, skillsBlock, mcpBlock
|
|
|
2751
2846
|
const body = workspaceResolveBodyPlaceholders(instance.body || "", inputValues).trim();
|
|
2752
2847
|
const { values: relevantInputValues, placeholders } = workspaceRelevantInputValues(instance.body || "", inputValues);
|
|
2753
2848
|
const runPackage = typeof nodeTmpDir === "object" && nodeTmpDir ? nodeTmpDir : { nodeTmpDir: String(nodeTmpDir || "") };
|
|
2754
|
-
const inputBlock = workspaceAgentInputBlock(relevantInputValues);
|
|
2849
|
+
const inputBlock = workspaceAgentInputBlock(relevantInputValues, runPackage.inputMounts || {});
|
|
2755
2850
|
const fileBoundary = workspaceNodeFileBoundaryBlock(runPackage);
|
|
2756
2851
|
const outputProtocolRequirements = workspaceOutputProtocolRequirements(graph, nodeId);
|
|
2757
2852
|
return [
|
|
@@ -2859,7 +2954,8 @@ function workspaceCreateNodeRunPackage(runTmpRoot, nodeId, { scopedRoot, task =
|
|
|
2859
2954
|
const nodeRunDir = workspaceCreateNodeTmpDir(runTmpRoot, nodeId);
|
|
2860
2955
|
const nodeTmpDir = path.join(nodeRunDir, "tmp");
|
|
2861
2956
|
const outputsDir = path.join(nodeRunDir, "outputs");
|
|
2862
|
-
const
|
|
2957
|
+
const workspaceRoot = path.resolve(scopedRoot);
|
|
2958
|
+
const workspaceOutputsDir = path.join(workspaceRoot, "outputs");
|
|
2863
2959
|
fs.mkdirSync(nodeTmpDir, { recursive: true });
|
|
2864
2960
|
fs.mkdirSync(outputsDir, { recursive: true });
|
|
2865
2961
|
fs.mkdirSync(workspaceOutputsDir, { recursive: true });
|
|
@@ -2869,13 +2965,19 @@ function workspaceCreateNodeRunPackage(runTmpRoot, nodeId, { scopedRoot, task =
|
|
|
2869
2965
|
nodeRunDir,
|
|
2870
2966
|
nodeTmpDir,
|
|
2871
2967
|
outputsDir,
|
|
2968
|
+
workspaceRoot,
|
|
2872
2969
|
createdAt: new Date().toISOString(),
|
|
2873
2970
|
};
|
|
2971
|
+
const materializedInputs = workspaceMaterializeNodeInputFiles(nodeRunDir, workspaceRoot, inputValues);
|
|
2972
|
+
const runtimeInputValues = { ...(inputValues || {}), ...(materializedInputs.values || {}) };
|
|
2874
2973
|
try {
|
|
2875
2974
|
fs.writeFileSync(path.join(nodeRunDir, "manifest.json"), JSON.stringify(manifest, null, 2) + "\n", "utf-8");
|
|
2876
2975
|
fs.writeFileSync(path.join(nodeRunDir, "task.md"), String(task || "").trimEnd() + "\n", "utf-8");
|
|
2877
|
-
if (Object.keys(
|
|
2878
|
-
fs.writeFileSync(path.join(nodeRunDir, "inputs.json"), JSON.stringify(
|
|
2976
|
+
if (Object.keys(runtimeInputValues || {}).length) {
|
|
2977
|
+
fs.writeFileSync(path.join(nodeRunDir, "inputs.json"), JSON.stringify(runtimeInputValues, null, 2) + "\n", "utf-8");
|
|
2978
|
+
}
|
|
2979
|
+
if (Object.keys(materializedInputs.mounts || {}).length) {
|
|
2980
|
+
fs.writeFileSync(path.join(nodeRunDir, "inputs.manifest.json"), JSON.stringify(materializedInputs.mounts, null, 2) + "\n", "utf-8");
|
|
2879
2981
|
}
|
|
2880
2982
|
if (skillsBlock) fs.writeFileSync(path.join(nodeRunDir, "skills.md"), String(skillsBlock).trimEnd() + "\n", "utf-8");
|
|
2881
2983
|
if (mcpBlock) fs.writeFileSync(path.join(nodeRunDir, "mcp.md"), String(mcpBlock).trimEnd() + "\n", "utf-8");
|
|
@@ -2886,9 +2988,59 @@ function workspaceCreateNodeRunPackage(runTmpRoot, nodeId, { scopedRoot, task =
|
|
|
2886
2988
|
...manifest,
|
|
2887
2989
|
workspaceOutputsDir,
|
|
2888
2990
|
outputsRel: "outputs",
|
|
2991
|
+
inputValues: runtimeInputValues,
|
|
2992
|
+
inputMounts: materializedInputs.mounts,
|
|
2889
2993
|
};
|
|
2890
2994
|
}
|
|
2891
2995
|
|
|
2996
|
+
function workspaceMaterializeNodeInputFiles(nodeRunDir, workspaceRoot, inputValues = {}) {
|
|
2997
|
+
const values = {};
|
|
2998
|
+
const mounts = {};
|
|
2999
|
+
for (const [name, value] of Object.entries(inputValues || {})) {
|
|
3000
|
+
const slotName = String(name || "").trim();
|
|
3001
|
+
if (!slotName) continue;
|
|
3002
|
+
const rel = workspaceInputFileRelPath(value);
|
|
3003
|
+
if (!rel) continue;
|
|
3004
|
+
const src = path.resolve(workspaceRoot, rel);
|
|
3005
|
+
const rootWithSep = workspaceRoot.endsWith(path.sep) ? workspaceRoot : `${workspaceRoot}${path.sep}`;
|
|
3006
|
+
if (src !== workspaceRoot && !src.startsWith(rootWithSep)) continue;
|
|
3007
|
+
if (!fs.existsSync(src) || !fs.statSync(src).isFile()) continue;
|
|
3008
|
+
const stat = fs.statSync(src);
|
|
3009
|
+
const mountedRel = path.join("inputs", workspaceSanitizeTmpSegment(slotName, "input"), path.basename(rel));
|
|
3010
|
+
const dest = path.resolve(nodeRunDir, mountedRel);
|
|
3011
|
+
const nodeRunWithSep = nodeRunDir.endsWith(path.sep) ? nodeRunDir : `${nodeRunDir}${path.sep}`;
|
|
3012
|
+
if (dest !== nodeRunDir && !dest.startsWith(nodeRunWithSep)) continue;
|
|
3013
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
3014
|
+
workspaceCopyInputFile(src, dest);
|
|
3015
|
+
const mounted = mountedRel.split(path.sep).join(path.posix.sep);
|
|
3016
|
+
values[slotName] = mounted;
|
|
3017
|
+
mounts[slotName] = {
|
|
3018
|
+
source: rel,
|
|
3019
|
+
mounted,
|
|
3020
|
+
bytes: stat.size,
|
|
3021
|
+
};
|
|
3022
|
+
}
|
|
3023
|
+
return { values, mounts };
|
|
3024
|
+
}
|
|
3025
|
+
|
|
3026
|
+
function workspaceCopyInputFile(src, dest) {
|
|
3027
|
+
try {
|
|
3028
|
+
fs.copyFileSync(src, dest, fs.constants.COPYFILE_FICLONE);
|
|
3029
|
+
} catch {
|
|
3030
|
+
fs.copyFileSync(src, dest);
|
|
3031
|
+
}
|
|
3032
|
+
}
|
|
3033
|
+
|
|
3034
|
+
function workspaceInputFileRelPath(value) {
|
|
3035
|
+
const text = String(value || "").trim().replace(/^["']|["']$/g, "");
|
|
3036
|
+
if (!text || text.length > 260) return "";
|
|
3037
|
+
if (/[\r\n<>]/.test(text)) return "";
|
|
3038
|
+
if (/^(?:https?:|data:|blob:|file:|javascript:|mailto:|tel:)/i.test(text)) return "";
|
|
3039
|
+
const clean = text.replace(/^\/+/, "");
|
|
3040
|
+
if (clean.includes("..") || clean.startsWith(".") || path.isAbsolute(clean)) return "";
|
|
3041
|
+
return clean;
|
|
3042
|
+
}
|
|
3043
|
+
|
|
2892
3044
|
function workspaceShouldKeepTmp(userCtx = {}) {
|
|
2893
3045
|
const env = { ...process.env, ...readMergedEnvObject(userCtx.userId) };
|
|
2894
3046
|
const value = String(env.AGENTFLOW_KEEP_TMP || env.AGENTFLOW_KEEP_WORKSPACE_TMP || "").trim().toLowerCase();
|
|
@@ -2912,7 +3064,7 @@ function workspaceCleanupTmpRoot(runTmpRoot, userCtx = {}, emit = () => {}) {
|
|
|
2912
3064
|
async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts = {}) {
|
|
2913
3065
|
const graph = normalizeWorkspaceGraphPayload(payload.graph || {});
|
|
2914
3066
|
const runNodeId = String(payload?.runNodeId || "").trim();
|
|
2915
|
-
const { order, pauseNodeIds } = workspaceRunPlan(graph, runNodeId);
|
|
3067
|
+
const { order, pauseNodeIds } = workspaceRunPlan(graph, runNodeId, scopedRoot);
|
|
2916
3068
|
const signal = opts.signal || null;
|
|
2917
3069
|
const throwIfAborted = () => {
|
|
2918
3070
|
if (signal?.aborted) {
|
|
@@ -3275,22 +3427,29 @@ async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts =
|
|
|
3275
3427
|
const inputValues = workspaceInputValues(graph, nodeId, outputs);
|
|
3276
3428
|
const relevantInputs = workspaceRelevantInputValues(instance.body || "", inputValues);
|
|
3277
3429
|
const upstreamText = workspaceTaskUpstreamText(graph, nodeId, outputs, relevantInputs.placeholders);
|
|
3278
|
-
const body = workspaceResolveBodyPlaceholders(instance.body || "", inputValues).trim();
|
|
3279
|
-
if (defId === "agent_subAgent" && !body && !String(upstreamText || "").trim()) {
|
|
3280
|
-
throw new Error(`Workspace node ${nodeId} has no task. Fill the node body or connect upstream text.`);
|
|
3281
|
-
}
|
|
3282
3430
|
const upstreamSkillBlocks = workspaceUpstreamSkillBlocks(graph, nodeId, outputs);
|
|
3283
3431
|
const promptSkillsBlock = mergeWorkspaceSkillBlocks(upstreamSkillBlocks);
|
|
3284
3432
|
const promptMcpBlock = workspaceUpstreamMcpBlocks(graph, nodeId, outputs);
|
|
3285
3433
|
const runPackage = workspaceCreateNodeRunPackage(runTmpRoot, nodeId, {
|
|
3286
3434
|
scopedRoot,
|
|
3287
3435
|
cwd,
|
|
3288
|
-
task: body || upstreamText,
|
|
3436
|
+
task: workspaceResolveBodyPlaceholders(instance.body || "", inputValues).trim() || upstreamText,
|
|
3289
3437
|
inputValues: relevantInputs.values,
|
|
3290
3438
|
skillsBlock: promptSkillsBlock,
|
|
3291
3439
|
mcpBlock: promptMcpBlock,
|
|
3292
3440
|
});
|
|
3293
|
-
const
|
|
3441
|
+
const runtimeInputValues = { ...inputValues, ...(runPackage.inputValues || {}) };
|
|
3442
|
+
const body = workspaceResolveBodyPlaceholders(instance.body || "", runtimeInputValues).trim();
|
|
3443
|
+
const promptUpstreamText = workspacePromptUpstreamText(upstreamText, runPackage);
|
|
3444
|
+
if (defId === "agent_subAgent" && !body && !String(promptUpstreamText || "").trim()) {
|
|
3445
|
+
throw new Error(`Workspace node ${nodeId} has no task. Fill the node body or connect upstream text.`);
|
|
3446
|
+
}
|
|
3447
|
+
try {
|
|
3448
|
+
fs.writeFileSync(path.join(runPackage.nodeRunDir, "task.md"), String(body || promptUpstreamText || "").trimEnd() + "\n", "utf-8");
|
|
3449
|
+
} catch {
|
|
3450
|
+
// Best-effort debug artifact only.
|
|
3451
|
+
}
|
|
3452
|
+
const prompt = workspaceNodePrompt(graph, nodeId, promptUpstreamText, promptSkillsBlock, promptMcpBlock, runtimeInputValues, runPackage);
|
|
3294
3453
|
try {
|
|
3295
3454
|
fs.writeFileSync(path.join(runPackage.nodeRunDir, "prompt.md"), prompt.trimEnd() + "\n", "utf-8");
|
|
3296
3455
|
} catch {
|
|
@@ -125,7 +125,7 @@ script: node -e "console.log('TODO: scripts/x.mjs')"
|
|
|
125
125
|
|
|
126
126
|
`).trimEnd()}function Lx(e){return String(e||"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function PK(e){const t=String(e||"");let n="",r=0;dg.lastIndex=0;let s;for(;s=dg.exec(t);)n+=Lx(t.slice(r,s.index)),n+=`<span class="af-flow-node__image-token">${Lx(s[0])}</span>`,r=s.index+s[0].length;return n+=Lx(t.slice(r)),n||" "}function AK(e,t){const n=window.getComputedStyle(e),r=Number.parseFloat(n.lineHeight)||18,s=Number.parseFloat(n.paddingTop)||0,i=Number.parseFloat(n.paddingBottom)||0,a=Number.parseFloat(n.borderTopWidth)||0,l=Number.parseFloat(n.borderBottomWidth)||0,c=String(t||"").split(/\r\n|\r|\n/).length,d=Math.min(Math.max(c,2),8);return Math.ceil(d*r+s+i+a+l)}function HT({data:e,selected:t,id:n,deleteNode:r,onProvideExpand:s,onProvideValueChange:i,onNodeBodyChange:a,onNodeImagesChange:l,modelLists:c,onModelChange:d}){var bn,lr;const{t:f}=Mn(),u=(e==null?void 0:e.inputs)??[],p=(e==null?void 0:e.outputs)??[],m=((e==null?void 0:e.schemaType)??"agent").toLowerCase(),y=NK(e),b=jK(y),k=(e==null?void 0:e.isRunMode)??!1,g=!!(e!=null&&e.readOnly),v=(e==null?void 0:e.isExecuting)??!1,x=(e==null?void 0:e.isDim)??!1,N=(e==null?void 0:e.nodeStatus)??null,_=(e==null?void 0:e.nodeElapsed)??null,C=(e==null?void 0:e.definitionId)||"",T=C.startsWith("provide_"),H=C==="provide_bool",M=C==="provide_str",F=C==="provide_file",D=C==="agent_subAgent",$=D&&!k,W=H?CK(p[0]):!1,O=T?String(((bn=p[0])==null?void 0:bn.value)??((lr=p[0])==null?void 0:lr.default)??(e==null?void 0:e.body)??""):"",R=String((e==null?void 0:e.body)||""),I=(e==null?void 0:e.displayLabel)||(e==null?void 0:e.label)||f("flow:node.fallbackLabel"),z=!T&&!$&&(e!=null&&e.showBodyPreview)?String((e==null?void 0:e.body)||"").trim():"",P=Ts(e==null?void 0:e.images),L=h.useRef(!1),E=h.useRef(!1),X=h.useRef(null),ee=h.useRef(null),V=h.useRef(null),[ie,fe]=h.useState(O),[me,ge]=h.useState(R);h.useEffect(()=>{L.current||fe(O)},[n,O]),h.useEffect(()=>{E.current||ge(R)},[n,R]),h.useEffect(()=>{const ve=ee.current;if(!ve)return;const $e=AK(ve,me);ve.style.minHeight=`${$e}px`,ve.style.height="",V.current&&(V.current.style.minHeight=`${$e}px`,V.current.style.height="")},[me]),h.useEffect(()=>{const ve=X.current,$e=e==null?void 0:e.onNodeContentResize;if(!$||!ve||!$e||typeof ResizeObserver>"u")return;let nt=0;const zt=()=>{window.cancelAnimationFrame(nt),nt=window.requestAnimationFrame(()=>$e(n))},oe=new ResizeObserver(zt);return oe.observe(ve),zt(),()=>{window.cancelAnimationFrame(nt),oe.disconnect()}},[e==null?void 0:e.onNodeContentResize,$,n]);const Z=Array.isArray(c==null?void 0:c.cursor)?c.cursor:[],ae=Array.isArray(c==null?void 0:c.opencode)?c.opencode:[],xe=Array.isArray(c==null?void 0:c.claudeCode)?c.claudeCode:[],pe=((e==null?void 0:e.model)??"").trim(),_e=m==="agent"&&!C.startsWith("tool_nodejs"),je=new Set(Z.map(Xo)),Ve=new Set(ae.map(Xo)),et=new Set(xe.map(Xo)),qe=pe?pe.startsWith("cursor:")||pe.startsWith("opencode:")||pe.startsWith("claude-code:")?pe:et.has(pe)?`claude-code:${pe}`:Ve.has(pe)?`opencode:${pe}`:je.has(pe)?`cursor:${pe}`:pe:"",dt=pe&&!qe.startsWith("cursor:")&&!qe.startsWith("opencode:")&&!qe.startsWith("claude-code:")&&!je.has(pe)&&!Ve.has(pe)&&!et.has(pe),He=pe.startsWith("cursor:")?pe.slice(7):pe.startsWith("opencode:")?pe.slice(9):pe.startsWith("claude-code:")?pe.slice(12):pe,bt=ve=>{if(g)return;const $e=ve.target.value;d&&d(n,$e)},sn=ve=>{ve.stopPropagation(),!g&&r&&r(n)},on=ve=>{ve.stopPropagation(),s&&s()},an=ve=>{ve.stopPropagation(),!g&&(i==null||i(n,ve.target.value==="true"?"true":"false"))},Yt=ve=>{if(ve.stopPropagation(),g)return;const $e=ve.target.value;fe($e),L.current||i==null||i(n,$e)},En=ve=>{ve.stopPropagation(),L.current=!0},hn=ve=>{if(ve.stopPropagation(),g)return;L.current=!1;const $e=ve.currentTarget.value;fe($e),i==null||i(n,$e)},ue=()=>{g||i==null||i(n,ie)},ke=ve=>{if(ve.stopPropagation(),g)return;const $e=window.prompt("文件路径",ie);$e!=null&&(fe($e),i==null||i(n,$e))},De=ve=>{if(ge(ve),a==null||a(n,ve),l){const $e=lK(P,ve);($e.length!==P.length||$e.some((nt,zt)=>{var oe;return nt.id!==((oe=P[zt])==null?void 0:oe.id)}))&&l(n,$e)}},rt=ve=>{if(ve.stopPropagation(),g)return;const $e=ve.target.value;E.current?ge($e):De($e)},at=ve=>{ve.stopPropagation(),!g&&(E.current=!0)},Lt=ve=>{if(ve.stopPropagation(),g)return;E.current=!1;const $e=ve.currentTarget.value;De($e)},st=()=>{g||De(me)},mn=async ve=>{if(g)return;const $e=await OT({files:ve,body:me,images:P});$e&&(ge($e.body),a==null||a(n,$e.body),l==null||l(n,$e.images))},Zt=(ve,$e)=>{if(ve.stopPropagation(),g)return;const nt=P.filter(oe=>oe.id!==$e.id),zt=_K(me,$e.label);ge(zt),a==null||a(n,zt),l==null||l(n,nt)},ar=ve=>{if(g)return;const $e=MT(ve);$e.length!==0&&(ve.preventDefault(),ve.stopPropagation(),mn($e).catch(()=>{}))},_n=ve=>{if(g)return;const $e=fg(ve);$e.length!==0&&(ve.preventDefault(),ve.stopPropagation(),mn($e).catch(()=>{}))},gn=()=>{const ve=ee.current,$e=V.current;!ve||!$e||($e.scrollTop=ve.scrollTop,$e.scrollLeft=ve.scrollLeft)};return o.jsxs("div",{className:"af-flow-node"+(t?" af-flow-node--selected":"")+(v?" af-flow-node--executing":"")+(N==="success"?" af-flow-node--done":"")+(N==="failed"?" af-flow-node--failed":"")+(N==="running"&&!v?" af-flow-node--running-disk":"")+(x?" af-flow-node--dim":"")+($?" af-flow-node--inline-body-editor":"")+(M?" af-flow-node--provide-text":"")+" af-flow-node--"+m.replace(/[^a-z0-9_-]/g,""),"data-schema":m,children:[o.jsxs("div",{className:"af-flow-node__chrome",children:[o.jsx("span",{className:"af-flow-node__type",title:y,children:b}),!k&&_e&&o.jsxs("div",{className:"af-flow-node__model-wrap nodrag",onPointerDown:$r,onMouseDown:$r,onClick:$r,children:[o.jsxs("select",{className:"af-flow-node__model nodrag",value:qe,onChange:bt,onPointerDown:$r,onMouseDown:$r,onClick:$r,"aria-label":f("flow:node.model"),title:He||f("flow:node.defaultModel"),disabled:g,children:[o.jsx("option",{value:"",children:f("flow:node.defaultModel")}),dt&&o.jsx("option",{value:pe,children:pe}),Z.length>0&&o.jsx("optgroup",{label:"Cursor",children:Z.map(ve=>o.jsx("option",{value:`cursor:${Xo(ve)}`,children:Xo(ve)},`c-${ve}`))}),ae.length>0&&o.jsx("optgroup",{label:"OpenCode",children:ae.map(ve=>o.jsx("option",{value:`opencode:${Xo(ve)}`,children:Xo(ve)},`o-${ve}`))}),xe.length>0&&o.jsx("optgroup",{label:"Claude Code",children:xe.map(ve=>o.jsx("option",{value:`claude-code:${Xo(ve)}`,children:Xo(ve)},`cc-${ve}`))})]}),o.jsx("span",{className:"af-flow-node__model-arrow material-symbols-outlined",children:"expand_more"})]}),v&&o.jsx("span",{className:"af-flow-node__status-badge af-flow-node__status-badge--executing",children:"EXECUTING"}),N==="running"&&!v&&o.jsx("span",{className:"af-flow-node__status-badge af-flow-node__status-badge--running-disk",title:f("flow:node.diskRunning"),children:"RUNNING"}),N==="success"&&o.jsx("span",{className:"af-flow-node__status-badge af-flow-node__status-badge--done",children:_!=null&&String(_).trim()!==""?_:"--"}),N==="failed"&&o.jsx("span",{className:"af-flow-node__status-badge af-flow-node__status-badge--failed",children:"FAILED"}),!k&&T&&!H&&!M&&!F&&o.jsx("button",{type:"button",className:"af-flow-node__expand",onClick:on,"aria-label":f("flow:node.expandProvide"),title:f("flow:node.expandProvide"),children:o.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})}),!k&&o.jsx("button",{type:"button",className:"af-flow-node__delete",disabled:g,onClick:sn,"aria-label":f("flow:node.deleteNode"),title:f("flow:node.deleteNode"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsxs("div",{className:"af-flow-node__body",children:[o.jsx("div",{className:"af-flow-node__ports af-flow-node__ports--in",children:u.map((ve,$e)=>{if(ve.showOnNode===!1)return null;const nt=f("flow:node.inputTooltip",{name:ve.name||`#${$e}`,type:ve.type})+(ve.default!=null&&ve.default!==""?f("flow:node.defaultSuffix",{value:ve.default}):""),zt=ve.name||`#${$e+1}`;return o.jsxs("div",{className:"af-flow-node__port-row",title:nt,children:[o.jsxs("span",{className:"af-flow-node__port-label af-flow-node__port-label--in",children:[zt,ve.required?o.jsx("span",{className:"af-flow-node__port-required",children:"*"}):null]}),o.jsx(Fs,{type:"target",position:Ze.Left,id:`input-${$e}`,className:"af-flow-node__handle",style:{background:or(ve.type)},title:nt})]},`in-${$e}`)})}),o.jsxs("div",{className:"af-flow-node__title-wrap",children:[o.jsx("span",{className:"af-flow-node__title",children:I}),n?o.jsx("span",{className:"af-flow-node__subtitle",title:n,children:n}):null,H?o.jsxs("select",{className:"af-flow-node__bool-select nodrag"+(W?" af-flow-node__bool-select--true":""),value:W?"true":"false",onChange:an,onPointerDown:$r,onMouseDown:$r,onClick:$r,"aria-label":"Boolean value",title:W?"true":"false",disabled:g,children:[o.jsx("option",{value:"false",children:"false"}),o.jsx("option",{value:"true",children:"true"})]}):M?o.jsx("textarea",{className:"af-flow-node__inline-text nodrag",value:ie,onChange:Yt,onCompositionStart:En,onCompositionEnd:hn,onBlur:ue,onPointerDown:$r,onMouseDown:$r,onClick:$r,placeholder:"输入文本",rows:2,readOnly:g}):F?o.jsxs("div",{className:"af-flow-node__file-value nodrag",onPointerDown:$r,onMouseDown:$r,onClick:$r,children:[o.jsx("input",{className:"af-flow-node__file-input nodrag",value:ie,onChange:Yt,onCompositionStart:En,onCompositionEnd:hn,onBlur:ue,placeholder:"选择或输入文件路径",title:ie||"选择或输入文件路径",readOnly:g}),o.jsx("button",{type:"button",className:"af-flow-node__file-picker nodrag",disabled:g,onClick:ke,"aria-label":"选择文件",title:"选择文件",children:o.jsx("span",{className:"material-symbols-outlined",children:"folder_open"})})]}):D&&!k?o.jsxs("div",{ref:X,className:"af-flow-node__prompt-stack nodrag",children:[o.jsx("pre",{ref:V,className:"af-flow-node__prompt-backdrop","aria-hidden":"true",dangerouslySetInnerHTML:{__html:PK(me)+`
|
|
127
127
|
`}}),o.jsx("textarea",{ref:ee,className:"af-flow-node__prompt-editor nodrag",value:me,onChange:rt,onCompositionStart:at,onCompositionEnd:Lt,onBlur:st,onPaste:ar,onDrop:_n,onScroll:gn,onDragOver:ve=>{fg(ve).length>0&&ve.preventDefault()},placeholder:"输入 prompt",rows:2,readOnly:g})]}):null,D&&P.length>0?o.jsx("div",{className:"af-flow-node__image-chips",children:P.map((ve,$e)=>o.jsxs("span",{className:"af-flow-node__image-chip",title:ve.name,children:[o.jsx("img",{src:ve.dataUrl,alt:""}),o.jsxs("span",{children:["[",ve.label||`image ${$e+1}`,"]"]}),o.jsx("button",{type:"button",className:"af-flow-node__image-remove nodrag",disabled:g,onClick:nt=>Zt(nt,ve),onPointerDown:$r,onMouseDown:$r,"aria-label":`删除 ${ve.label||`image ${$e+1}`}`,title:"删除图片",children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]},ve.id||$e))}):null,z?o.jsx("span",{className:"af-flow-node__prompt-preview",title:z,children:z}):null]}),o.jsx("div",{className:"af-flow-node__ports af-flow-node__ports--out",children:p.map((ve,$e)=>{if(ve.showOnNode===!1)return null;const nt=f("flow:node.outputTooltip",{name:ve.name||`#${$e}`,type:ve.type})+(ve.default!=null&&ve.default!==""?f("flow:node.defaultSuffix",{value:ve.default}):""),zt=ve.name||`#${$e+1}`;return o.jsxs("div",{className:"af-flow-node__port-row",title:nt,children:[o.jsxs("span",{className:"af-flow-node__port-label af-flow-node__port-label--out",children:[zt,ve.required?o.jsx("span",{className:"af-flow-node__port-required",children:"*"}):null]}),o.jsx(Fs,{type:"source",position:Ze.Right,id:`output-${$e}`,className:"af-flow-node__handle",style:{background:or(ve.type)},title:nt})]},`out-${$e}`)})})]})]})}const Sp="flowNode";function BT(e){if(!e||!(e instanceof Element))return!1;if(e.closest('[contenteditable="true"]'))return!0;const t=e.tagName;return!!(t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable)}function mg(e){return e.key==="?"||e.key==="/"&&e.shiftKey}function IK(){return typeof navigator>"u"?!1:/Mac|iPhone|iPod|iPad/i.test(navigator.platform||navigator.userAgent||"")}function WT({open:e,onClose:t,flowId:n,flowSource:r,onArchived:s}){const{t:i}=Mn(),a=h.useId(),l=h.useRef(null),[c,d]=h.useState(""),[f,u]=h.useState(!1),[p,m]=h.useState("");if(h.useEffect(()=>{if(!e)return;d(""),m(""),u(!1);const g=requestAnimationFrame(()=>{var v;return(v=l.current)==null?void 0:v.focus()});return()=>cancelAnimationFrame(g)},[e,n]),!e)return null;const y=c.trim(),b=y===n;async function k(g){if(g.preventDefault(),!(!b||f)){u(!0),m("");try{const v=await fetch("/api/flow/archive",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:n,flowSource:r,confirmFlowId:y})}),x=await v.json().catch(()=>({}));if(!v.ok){m(typeof x.error=="string"?x.error:i("project:archiveModal.archiveFailed"));return}s()}catch(v){m(String((v==null?void 0:v.message)||v))}finally{u(!1)}}}return o.jsx("div",{className:"af-shortcuts-overlay",role:"presentation",onMouseDown:g=>{g.target===g.currentTarget&&t()},children:o.jsxs("div",{ref:l,className:"af-shortcuts-panel af-new-pipeline-panel",role:"dialog","aria-modal":"true","aria-labelledby":a,tabIndex:-1,onMouseDown:g=>g.stopPropagation(),children:[o.jsxs("div",{className:"af-shortcuts-panel__head",children:[o.jsx("h2",{id:a,className:"af-shortcuts-panel__title",children:i("project:archiveModal.title")}),o.jsx("button",{type:"button",className:"af-shortcuts-panel__close af-icon-btn",onClick:t,"aria-label":i("project:archiveModal.close"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsxs("form",{className:"af-shortcuts-panel__body af-new-pipeline-form",onSubmit:k,children:[o.jsx("p",{className:"af-new-pipeline-lead",children:i("project:archiveModal.lead",{flowId:n})}),o.jsxs("label",{className:"af-new-pipeline-field",children:[o.jsx("span",{className:"af-pipeline-drawer-label",children:i("project:archiveModal.confirmLabel")}),o.jsx("input",{type:"text",className:"af-new-pipeline-input",value:c,onChange:g=>d(g.target.value),placeholder:n,autoComplete:"off",spellCheck:!1,"aria-invalid":y.length>0&&!b})]}),p?o.jsx("p",{className:"af-err af-new-pipeline-err",children:p}):null,o.jsxs("div",{className:"af-new-pipeline-actions",children:[o.jsx("button",{type:"button",className:"af-btn-secondary",onClick:t,disabled:f,children:i("project:archiveModal.cancel")}),o.jsx("button",{type:"submit",className:"af-btn-primary",disabled:!b||f,children:i(f?"project:archiveModal.archiving":"project:archiveModal.confirmArchive")})]})]})]})})}function qj({open:e,title:t,message:n,confirmLabel:r,cancelLabel:s,destructive:i=!1,secondaryLabel:a,secondaryDestructive:l=!1,onSecondary:c,onConfirm:d,onCancel:f}){const{t:u}=Mn(),p=h.useId(),m=h.useRef(null);if(h.useEffect(()=>{if(!e)return;const g=requestAnimationFrame(()=>{var x;return(x=m.current)==null?void 0:x.focus()});function v(x){x.key==="Escape"&&f(),x.key==="Enter"&&d()}return window.addEventListener("keydown",v),()=>{cancelAnimationFrame(g),window.removeEventListener("keydown",v)}},[e,f,d]),!e)return null;const y=r??u("common:common.confirm","确定"),b=s??u("common:common.cancel","取消"),k=t??u("common:common.confirmTitle","请确认");return o.jsx("div",{className:"af-shortcuts-overlay",role:"presentation",onMouseDown:g=>{g.target===g.currentTarget&&f()},children:o.jsxs("div",{ref:m,className:"af-shortcuts-panel af-new-pipeline-panel",role:"dialog","aria-modal":"true","aria-labelledby":p,tabIndex:-1,onMouseDown:g=>g.stopPropagation(),children:[o.jsxs("div",{className:"af-shortcuts-panel__head",children:[o.jsx("h2",{id:p,className:"af-shortcuts-panel__title",children:k}),o.jsx("button",{type:"button",className:"af-shortcuts-panel__close af-icon-btn",onClick:f,"aria-label":b,children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsxs("div",{className:"af-shortcuts-panel__body af-new-pipeline-form",children:[o.jsx("p",{className:"af-new-pipeline-lead",children:n}),o.jsxs("div",{className:"af-new-pipeline-actions",children:[o.jsx("button",{type:"button",className:"af-btn-secondary",onClick:f,children:b}),a&&c?o.jsx("button",{type:"button",className:l?"af-btn-secondary af-btn-destructive":"af-btn-secondary",onClick:c,children:a}):null,o.jsx("button",{type:"button",className:i?"af-btn-primary af-btn-destructive":"af-btn-primary",onClick:d,autoFocus:!0,children:y})]})]})]})})}function VT({open:e,onClose:t,flowId:n,flowSource:r,flowArchived:s=!1,onDeleted:i}){const{t:a}=Mn(),l=h.useId(),c=h.useRef(null),[d,f]=h.useState(""),[u,p]=h.useState(!1),[m,y]=h.useState("");if(h.useEffect(()=>{if(!e)return;f(""),y(""),p(!1);const v=requestAnimationFrame(()=>{var x;return(x=c.current)==null?void 0:x.focus()});return()=>cancelAnimationFrame(v)},[e,n]),!e)return null;const b=d.trim(),k=b===n;async function g(v){if(v.preventDefault(),!k||u)return;p(!0),y("");let x=null;try{const N=new AbortController;x=setTimeout(()=>N.abort(),15e3);const _=await fetch("/api/flow/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:n,flowSource:r,confirmFlowId:b,flowArchived:s}),signal:N.signal}),C=await _.json().catch(()=>({}));if(!_.ok){y(typeof C.error=="string"?C.error:a("project:deleteModal.deleteFailed"));return}try{for(let T=localStorage.length-1;T>=0;T--){const H=localStorage.key(T);H&&(H.startsWith(`af:composer-sessions:${n}:${r}`)||H.startsWith(`af:composer-active-session:${n}:${r}`)||H.startsWith(`af:workspace-composer:${n}:${r}`))&&localStorage.removeItem(H)}}catch{}await i()}catch(N){if((N==null?void 0:N.name)==="AbortError"){y(a("project:deleteModal.deleteTimeout"));return}y(String((N==null?void 0:N.message)||N))}finally{x&&clearTimeout(x),p(!1)}}return o.jsx("div",{className:"af-shortcuts-overlay",role:"presentation",onMouseDown:v=>{v.target===v.currentTarget&&t()},children:o.jsxs("div",{ref:c,className:"af-shortcuts-panel af-new-pipeline-panel",role:"dialog","aria-modal":"true","aria-labelledby":l,tabIndex:-1,onMouseDown:v=>v.stopPropagation(),children:[o.jsxs("div",{className:"af-shortcuts-panel__head",children:[o.jsx("h2",{id:l,className:"af-shortcuts-panel__title",children:a("project:deleteModal.title")}),o.jsx("button",{type:"button",className:"af-shortcuts-panel__close af-icon-btn",onClick:t,"aria-label":a("project:deleteModal.close"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsxs("form",{className:"af-shortcuts-panel__body af-new-pipeline-form",onSubmit:g,children:[o.jsx("p",{className:"af-new-pipeline-lead",children:a("project:deleteModal.lead",{flowId:n})}),o.jsxs("label",{className:"af-new-pipeline-field",children:[o.jsx("span",{className:"af-pipeline-drawer-label",children:a("project:deleteModal.confirmLabel")}),o.jsx("input",{type:"text",className:"af-new-pipeline-input",value:d,onChange:v=>f(v.target.value),placeholder:n,autoComplete:"off",spellCheck:!1,"aria-invalid":b.length>0&&!k})]}),m?o.jsx("p",{className:"af-err af-new-pipeline-err",children:m}):null,o.jsxs("div",{className:"af-new-pipeline-actions",children:[o.jsx("button",{type:"button",className:"af-btn-secondary",onClick:t,disabled:u,children:a("project:deleteModal.cancel")}),o.jsx("button",{type:"submit",className:"af-btn-primary af-btn-destructive",disabled:!k||u,children:a(u?"project:deleteModal.deleting":"project:deleteModal.confirmDelete")})]})]})]})})}function TK({children:e}){return o.jsx("kbd",{className:"af-kbd",children:e})}function Hi({keys:e}){return o.jsx("span",{className:"af-shortcuts-keys",children:e.map((t,n)=>o.jsxs("span",{children:[n>0?o.jsx("span",{className:"af-shortcuts-keys__plus",children:"+"}):null,o.jsx(TK,{children:t})]},n))})}function UT({open:e,onClose:t}){const{t:n}=Mn(),r=h.useRef(null);if(h.useEffect(()=>{if(!e)return;const a=requestAnimationFrame(()=>{var l;return(l=r.current)==null?void 0:l.focus()});return()=>cancelAnimationFrame(a)},[e]),!e)return null;const i=IK()?"⌘":"Ctrl";return o.jsx("div",{className:"af-shortcuts-overlay",role:"presentation",onMouseDown:a=>{a.target===a.currentTarget&&t()},children:o.jsxs("div",{ref:r,className:"af-shortcuts-panel",role:"dialog","aria-modal":"true","aria-labelledby":"af-shortcuts-title",tabIndex:-1,onMouseDown:a=>a.stopPropagation(),children:[o.jsxs("div",{className:"af-shortcuts-panel__head",children:[o.jsx("h2",{id:"af-shortcuts-title",className:"af-shortcuts-panel__title",children:n("flow:shortcuts.title")}),o.jsx("button",{type:"button",className:"af-shortcuts-panel__close af-icon-btn",onClick:t,"aria-label":n("common:common.close"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsxs("div",{className:"af-shortcuts-panel__body",children:[o.jsxs("section",{className:"af-shortcuts-section",children:[o.jsx("h3",{className:"af-shortcuts-cat",children:n("flow:shortcuts.general")}),o.jsxs("ul",{className:"af-shortcuts-list",children:[o.jsxs("li",{className:"af-shortcuts-row",children:[o.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.saveDesc")}),o.jsx(Hi,{keys:[i,"S"]})]}),o.jsxs("li",{className:"af-shortcuts-row",children:[o.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.shortcutsLabel")}),o.jsx(Hi,{keys:["?"]})]}),o.jsxs("li",{className:"af-shortcuts-row",children:[o.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.jumpToNode")}),o.jsx(Hi,{keys:[i,"K"]})]}),o.jsxs("li",{className:"af-shortcuts-row",children:[o.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.openNodePalette")}),o.jsx(Hi,{keys:["A"]})]})]})]}),o.jsxs("section",{className:"af-shortcuts-section",children:[o.jsx("h3",{className:"af-shortcuts-cat",children:n("flow:shortcuts.canvas")}),o.jsxs("ul",{className:"af-shortcuts-list",children:[o.jsxs("li",{className:"af-shortcuts-row",children:[o.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.selectTool")}),o.jsx(Hi,{keys:["V"]})]}),o.jsxs("li",{className:"af-shortcuts-row",children:[o.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.panTool")}),o.jsx(Hi,{keys:["H"]})]}),o.jsxs("li",{className:"af-shortcuts-row",children:[o.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.holdSpacePan")}),o.jsx(Hi,{keys:["Space"]})]}),o.jsxs("li",{className:"af-shortcuts-row",children:[o.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.saveViewport")}),o.jsx(Hi,{keys:["F"]})]}),o.jsxs("li",{className:"af-shortcuts-row",children:[o.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.selectAll")}),o.jsx(Hi,{keys:[i,"A"]})]}),o.jsxs("li",{className:"af-shortcuts-row",children:[o.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.undo")}),o.jsx(Hi,{keys:[i,"Z"]})]}),o.jsxs("li",{className:"af-shortcuts-row",children:[o.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.redo")}),o.jsx(Hi,{keys:[i,"Shift","Z"]})]})]})]})]})]})})}function RK(e,t){if(!t)return 1;const n=t.toLowerCase(),r=(e.id||"").toLowerCase(),s=(e.label||"").toLowerCase(),i=(e.definitionId||"").toLowerCase();return r===n?100:r.startsWith(n)?80:r.includes(n)?60:s.startsWith(n)?40:s.includes(n)?30:i.includes(n)?15:0}function KT({open:e,onClose:t,onJump:n,nodes:r}){const{t:s}=Mn(),[i,a]=h.useState(""),[l,c]=h.useState(0),d=h.useRef(null),f=h.useRef(null);h.useEffect(()=>{if(!e)return;a(""),c(0);const y=requestAnimationFrame(()=>{var b;return(b=d.current)==null?void 0:b.focus()});return()=>cancelAnimationFrame(y)},[e]);const u=h.useMemo(()=>{const y=(r||[]).map(g=>{var v,x,N;return{id:g.id,label:((v=g.data)==null?void 0:v.label)||"",definitionId:((x=g.data)==null?void 0:x.definitionId)||"",schemaType:((N=g.data)==null?void 0:N.schemaType)||""}}),b=i.trim(),k=y.map(g=>({e:g,s:RK(g,b)})).filter(g=>g.s>0);return k.sort((g,v)=>v.s-g.s||g.e.id.localeCompare(v.e.id)),k.slice(0,50).map(g=>g.e)},[r,i]);if(h.useEffect(()=>{l>=u.length&&c(0)},[u.length,l]),h.useEffect(()=>{var b;const y=(b=f.current)==null?void 0:b.querySelector(`[data-idx="${l}"]`);y&&y.scrollIntoView({block:"nearest"})},[l]),!e)return null;const p=y=>{const b=u[y];b&&(n(b.id),t())},m=y=>{if(y.key==="Escape"){y.preventDefault(),t();return}if(y.key==="ArrowDown"){y.preventDefault(),c(b=>Math.min(u.length-1,b+1));return}if(y.key==="ArrowUp"){y.preventDefault(),c(b=>Math.max(0,b-1));return}y.key==="Enter"&&(y.preventDefault(),p(l))};return o.jsx("div",{className:"af-jump-overlay",role:"presentation",onMouseDown:y=>{y.target===y.currentTarget&&t()},children:o.jsxs("div",{className:"af-jump-panel",role:"dialog","aria-modal":"true","aria-label":s("flow:jumpPalette.title"),onMouseDown:y=>y.stopPropagation(),children:[o.jsxs("div",{className:"af-jump-panel__input-wrap",children:[o.jsx("span",{className:"af-jump-panel__icon material-symbols-outlined","aria-hidden":!0,children:"search"}),o.jsx("input",{ref:d,type:"text",className:"af-jump-panel__input",placeholder:s("flow:jumpPalette.placeholder"),value:i,onChange:y=>{a(y.target.value),c(0)},onKeyDown:m,spellCheck:!1,autoComplete:"off"}),o.jsx("span",{className:"af-jump-panel__count",children:u.length})]}),u.length===0?o.jsx("div",{className:"af-jump-panel__empty",children:s("flow:jumpPalette.empty")}):o.jsx("ul",{ref:f,className:"af-jump-panel__list",role:"listbox",children:u.map((y,b)=>o.jsxs("li",{"data-idx":b,role:"option","aria-selected":b===l,className:"af-jump-panel__item"+(b===l?" af-jump-panel__item--active":""),onMouseEnter:()=>c(b),onMouseDown:k=>{k.preventDefault(),p(b)},children:[o.jsx("span",{className:"af-jump-panel__id",children:y.id}),y.label&&y.label!==y.id&&o.jsx("span",{className:"af-jump-panel__label",children:y.label}),y.definitionId&&o.jsx("span",{className:"af-jump-panel__tag",children:y.definitionId})]},y.id))}),o.jsxs("div",{className:"af-jump-panel__hint",children:[o.jsxs("span",{children:[o.jsx("kbd",{className:"af-kbd",children:"↑"}),o.jsx("kbd",{className:"af-kbd",children:"↓"})," ",s("flow:jumpPalette.hintNavigate")]}),o.jsxs("span",{children:[o.jsx("kbd",{className:"af-kbd",children:"Enter"})," ",s("flow:jumpPalette.hintJump")]}),o.jsxs("span",{children:[o.jsx("kbd",{className:"af-kbd",children:"Esc"})," ",s("flow:jumpPalette.hintClose")]})]})]})})}function LK({open:e,onClose:t,flowId:n,flowSource:r,flowArchived:s=!1,filePath:i,fileName:a,onSaved:l,onAiEdit:c}){const{t:d}=Mn(),f=h.useId(),u=h.useRef(null),p=h.useRef(null),[m,y]=h.useState(""),[b,k]=h.useState(""),[g,v]=h.useState(!1),[x,N]=h.useState(!1),[_,C]=h.useState(!1),[T,H]=h.useState(""),[M,F]=h.useState("");if(h.useEffect(()=>{if(!e||!i)return;y(""),k(""),H(""),F(""),v(!0),N(!1),C(!1);const I=new URLSearchParams({flowId:n,flowSource:r,archived:s?"1":"0",path:i});(async()=>{try{const P=await fetch(`/api/pipeline-file-content?${I}`),L=await P.json();if(!P.ok)throw new Error(L.error||"HTTP "+P.status);y(L.content||""),k(L.content||"")}catch(P){H(P.message||String(P))}finally{v(!1)}})();const z=requestAnimationFrame(()=>{var P;return(P=u.current)==null?void 0:P.focus()});return()=>cancelAnimationFrame(z)},[e,i,n,r,s]),!e)return null;const D=m!==b;async function $(I){if(I.preventDefault(),!x){N(!0),H(""),F("");try{const z=new URLSearchParams({flowId:n,flowSource:r,archived:s?"1":"0",path:i}),P=await fetch(`/api/pipeline-file-save?${z}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:m})}),L=await P.json();if(!P.ok)throw new Error(L.error||"HTTP "+P.status);k(m),F(d("flow:fileEdit.saved")),l&&l()}catch(z){H(z.message||String(z))}finally{N(!1)}}}async function W(){if(!(!c||_||!m)){C(!0),H("");try{const I=await c(m);typeof I=="string"&&I&&y(I)}catch(I){H(I.message||String(I))}finally{C(!1)}}}function O(){y(b),H(""),F("")}const R=m.length>1e5;return o.jsx("div",{className:"af-shortcuts-overlay",role:"presentation",onMouseDown:I=>{I.target===I.currentTarget&&t()},children:o.jsxs("div",{ref:u,className:"af-shortcuts-panel af-file-edit-panel",role:"dialog","aria-modal":"true","aria-labelledby":f,tabIndex:-1,onMouseDown:I=>I.stopPropagation(),children:[o.jsxs("div",{className:"af-shortcuts-panel__head",children:[o.jsx("h2",{id:f,className:"af-shortcuts-panel__title",children:a||i}),o.jsx("button",{type:"button",className:"af-shortcuts-panel__close af-icon-btn",onClick:t,"aria-label":d("flow:fileEdit.close"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsx("div",{className:"af-file-edit-body",children:g?o.jsx("div",{className:"af-file-edit-loading",children:d("flow:fileEdit.loading")}):T&&!m?o.jsx("div",{className:"af-file-edit-error",children:T}):o.jsxs(o.Fragment,{children:[R&&o.jsx("div",{className:"af-file-edit-warning",children:d("flow:fileEdit.largeFileWarning")}),o.jsx("textarea",{ref:p,className:"af-file-edit-textarea",value:m,onChange:I=>y(I.target.value),spellCheck:!1,placeholder:d("flow:fileEdit.placeholder")})]})}),(T||M)&&!g&&o.jsx("div",{className:`af-file-edit-status${M?" af-file-edit-status--success":""}`,children:M||T}),o.jsxs("div",{className:"af-file-edit-actions",children:[o.jsx("button",{type:"button",className:"af-btn-secondary",onClick:O,disabled:!D||x||_,children:d("flow:fileEdit.reset")}),c&&o.jsx("button",{type:"button",className:"af-btn-secondary af-btn-ai",onClick:W,disabled:_||x||!m,children:d(_?"flow:fileEdit.aiRunning":"flow:fileEdit.aiEdit")}),o.jsx("button",{type:"button",className:"af-btn-primary",onClick:$,disabled:!D||x||_,children:d(x?"flow:fileEdit.saving":"flow:fileEdit.save")})]})]})})}const qT=new Set(["workspaceRoot","pipelineWorkspace","cwd","flowName","runDir","flowDir"]),MK=["workspaceRoot","pipelineWorkspace","cwd","flowName","runDir","flowDir"];function OK(e,t){const n=e.slice(0,t),r=n.lastIndexOf("${");if(r<0)return null;const s=n.slice(r+2);return s.includes("}")?null:{atIndex:r,query:s}}function $K(e){const t=/\$\{([^}]*)\}/g,n=[];let r;for(;(r=t.exec(e))!==null;)n.push({start:r.index,end:r.index+r[0].length,key:r[1]});return n}function Yj(e){const t=new Set;if(!Array.isArray(e))return t;for(const n of e){const r=(n==null?void 0:n.name)!=null?String(n.name).trim():"";r&&t.add(r)}return t}function YT(e,{inputNames:t,outputNames:n}){const r=e.trim();if(!r)return!1;if(r.startsWith("input.")){const s=r.slice(6).trim();return s!==""&&t.has(s)}if(r.startsWith("output.")){const s=r.slice(7).trim();return s!==""&&n.has(s)}if(qT.has(r)||t.has(r)||n.has(r))return!0;if(!r.includes(".")){const s=`${r}.md`;if(t.has(s)||n.has(s))return!0}return!1}function GT(e){return{inputNames:Yj(e==null?void 0:e.inputs),outputNames:Yj(e==null?void 0:e.outputs)}}function DK(e,t,n){const r=GT(t),s=$K(e),i=[];for(const a of s)if(!YT(a.key,r)){const l=a.key.trim()===""?n("flow:placeholder.empty"):a.key.trim();i.push({start:a.start,end:a.end,message:n("flow:placeholder.invalidPlaceholder",{hint:l})})}return i}function FK(e,t){const n=GT(t),r=/\$\{([^}]*)\}/g,s=[];let i=0,a;for(;(a=r.exec(e))!==null;){a.index>i&&s.push({kind:"plain",text:e.slice(i,a.index)});const l=a[0],c=YT(a[1],n);s.push({kind:c?"ph-valid":"ph-invalid",text:l}),i=a.index+l.length}return i<e.length&&s.push({kind:"plain",text:e.slice(i)}),s}function zK(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function HK(e){return e.map(t=>{const n=zK(t.text);return t.kind==="ph-invalid"?`<span class="af-body-ph-invalid">${n}</span>`:t.kind==="ph-valid"?`<span class="af-body-ph-valid">${n}</span>`:n}).join("")}function BK(e,t){const n=[];for(const r of(e==null?void 0:e.inputs)??[]){const s=(r==null?void 0:r.name)!=null?String(r.name).trim():"";if(!s)continue;const i=(r==null?void 0:r.type)!=null?String(r.type):"";n.push({section:"input",insert:`input.${s}`,label:s,subtitle:i?t("flow:placeholder.inputSubtitle",{type:i}):t("flow:placeholder.inputSubtitleNoType")})}for(const r of(e==null?void 0:e.outputs)??[]){const s=(r==null?void 0:r.name)!=null?String(r.name).trim():"";if(!s)continue;const i=(r==null?void 0:r.type)!=null?String(r.type):"";n.push({section:"output",insert:`output.${s}`,label:s,subtitle:i?t("flow:placeholder.outputSubtitle",{type:i}):t("flow:placeholder.outputSubtitleNoType")})}for(const r of MK)qT.has(r)&&n.push({section:"runtime",insert:r,label:r,subtitle:t("flow:placeholder.runtimeConst")});return n}function WK(e,t){const n=t.toLowerCase();return n?e.filter(r=>[r.insert,r.label,r.subtitle??""].map(i=>String(i).toLowerCase()).some(i=>i.includes(n))):e}function VK(e,t){if(!e||t<0)return null;const n=Math.min(t,e.value.length),r=getComputedStyle(e),s=document.createElement("div");s.setAttribute("aria-hidden","true"),s.style.visibility="hidden",s.style.position="fixed",s.style.top="0",s.style.left="-99999px",s.style.whiteSpace="pre-wrap",s.style.wordWrap="break-word",s.style.overflow="hidden";const i=e.clientWidth;if(i<=0)return null;s.style.width=`${i}px`,s.style.font=r.font,s.style.lineHeight=r.lineHeight,s.style.padding=r.padding,s.style.border=r.border,s.style.boxSizing=r.boxSizing,s.style.letterSpacing=r.letterSpacing,s.style.textIndent=r.textIndent,s.style.tabSize=r.tabSize||"8",s.textContent=e.value.slice(0,n);const a=document.createElement("span");a.textContent="",s.appendChild(a),document.body.appendChild(s);const l=a.getBoundingClientRect(),c=parseFloat(r.lineHeight),d=Number.isFinite(c)&&c>0?c:l.height||16;return document.body.removeChild(s),{top:l.top,left:l.left,bottom:l.bottom,height:d}}function $h({value:e,onChange:t,disabled:n,placeholder:r,rows:s=8,textareaClassName:i,ioSlots:a,variant:l="drawer",images:c,onImagesChange:d}){const{t:f}=Mn(),u=h.useId(),p=h.useRef(null),m=h.useRef(null),[y,b]=h.useState(0),[k,g]=h.useState(0),[v,x]=h.useState(null),N=h.useMemo(()=>Ts(c),[c]),_=h.useMemo(()=>DK(e,a,f),[e,a,f]),C=_.length>0,T=h.useMemo(()=>FK(e,a),[e,a]),H=h.useMemo(()=>HK(T),[T]),M=h.useMemo(()=>n?null:OK(e,y),[e,y,n]),F=h.useMemo(()=>{if(!M)return[];const I=BK(a,f);return WK(I,M.query)},[M,a,f]);h.useEffect(()=>{g(I=>{const z=Math.max(0,F.length-1);return Math.min(Math.max(0,I),z)})},[F.length]);const D=h.useCallback(()=>{const I=p.current;if(!I||!M||F.length===0){x(null);return}const z=VK(I,y);if(!z){x(null);return}const P=4,L=44,E=13.5*16,X=Math.min(F.length*L+8,E);let ee=z.bottom+P;ee+X>window.innerHeight-8&&(ee=Math.max(8,z.top-X-P));const V=288;let ie=z.left;ie=Math.max(8,Math.min(ie,window.innerWidth-V-8)),x({top:ee,left:ie})},[M,F.length,y]);h.useLayoutEffect(()=>{if(!M||F.length===0){x(null);return}const I=requestAnimationFrame(()=>D());return()=>cancelAnimationFrame(I)},[M,F.length,y,e,D]),h.useEffect(()=>{if(!M||F.length===0)return;const I=()=>D();return window.addEventListener("scroll",I,!0),window.addEventListener("resize",I),()=>{window.removeEventListener("scroll",I,!0),window.removeEventListener("resize",I)}},[M,F.length,D]);const $=h.useCallback(I=>{if(!M)return;const{atIndex:z}=M,P=e.slice(0,z)+"${"+I+"}"+e.slice(y);t(P);const L=z+I.length+3;queueMicrotask(()=>{const E=p.current;E&&(E.focus(),E.setSelectionRange(L,L)),b(L)})},[M,e,y,t]),W=h.useCallback(()=>{const I=p.current,z=m.current;!I||!z||(z.scrollTop=I.scrollTop,z.scrollLeft=I.scrollLeft,M&&F.length>0&&queueMicrotask(()=>D()))},[M,F.length,D]),O=h.useCallback(I=>{if(!n&&M&&F.length>0&&(I.key==="ArrowDown"||I.key==="ArrowUp"||I.key==="Enter")){if(I.key==="ArrowDown")I.preventDefault(),g(z=>(z+1)%F.length);else if(I.key==="ArrowUp")I.preventDefault(),g(z=>(z-1+F.length)%F.length);else if(I.key==="Enter"&&!I.shiftKey){I.preventDefault();const z=F[k];z&&$(z.insert)}}},[n,M,F,k,$]),R=h.useCallback(async I=>{if(n||typeof d!="function")return!1;const z=await OT({files:I,body:e,images:N});return z?(t(z.body),d(z.images),queueMicrotask(()=>{const P=p.current;if(!P)return;P.focus();const L=z.body.length;P.setSelectionRange(L,L),b(L)}),!0):!1},[n,N,t,d,e]);return o.jsxs("div",{className:"af-body-prompt-editor"+(l==="expand"?" af-body-prompt-editor--expand":""),children:[N.length>0?o.jsx("div",{className:"af-body-image-list","aria-label":"image attachments",children:N.map((I,z)=>o.jsxs("span",{className:"af-body-image-chip",title:I.name,children:[o.jsx("img",{src:I.dataUrl,alt:""}),o.jsxs("span",{children:["[",I.label||`image ${z+1}`,"]"]})]},I.id||z))}):null,o.jsxs("div",{className:"af-body-prompt-stack",children:[o.jsx("pre",{ref:m,className:"af-body-prompt-backdrop "+i,"aria-hidden":"true",dangerouslySetInnerHTML:{__html:H+`
|
|
128
|
-
`}}),o.jsx("textarea",{ref:p,className:"af-body-prompt-textarea "+i,rows:s,value:e,disabled:n,placeholder:r,spellCheck:!1,"aria-invalid":C,"aria-describedby":C?u:void 0,onChange:I=>{t(I.target.value),b(I.target.selectionStart??I.target.value.length)},onSelect:I=>{const z=I.target;z instanceof HTMLTextAreaElement&&b(z.selectionStart??0)},onClick:I=>{const z=I.target;z instanceof HTMLTextAreaElement&&b(z.selectionStart??0)},onKeyUp:I=>{const z=I.target;z instanceof HTMLTextAreaElement&&b(z.selectionStart??z.value.length)},onKeyDown:O,onPaste:I=>{const z=MT(I);z.length!==0&&(I.preventDefault(),R(z).catch(()=>{}))},onDragOver:I=>{fg(I).length>0&&I.preventDefault()},onDrop:I=>{const z=fg(I);z.length!==0&&(I.preventDefault(),R(z).catch(()=>{}))},onScroll:W})]}),M&&F.length>0&&v?Fr.createPortal(o.jsx("ul",{className:"af-body-ph-menu af-body-ph-menu--pop af-composer-mention-menu",role:"listbox","aria-label":f("flow:nodeProps.placeholderSlots"),style:{position:"fixed",top:v.top,left:v.left,right:"auto",bottom:"auto",margin:0,zIndex:2e4},children:F.map((I,z)=>o.jsx("li",{role:"option","aria-selected":z===k,children:o.jsxs("button",{type:"button",className:"af-composer-mention-item"+(z===k?" af-composer-mention-item--active":""),onMouseDown:P=>P.preventDefault(),onMouseEnter:()=>g(z),onClick:()=>$(I.insert),children:[o.jsx("span",{className:"af-composer-mention-id",children:`\${${I.insert}}`}),I.subtitle?o.jsx("span",{className:"af-composer-mention-sub",children:I.subtitle}):null]})},`${I.section}-${I.insert}`))}),document.body):null,C?o.jsx("p",{id:u,className:"af-body-ph-issues",role:"status",children:_.map(I=>I.message).join(" · ")}):null]})}const XT=/^[a-zA-Z_][a-zA-Z0-9_-]*$/;function Dh(e){const t=e.indexOf(" - ");return t>=0?e.slice(0,t).trim():e.trim()}function Gj({kind:e,label:t,slots:n,onSlotsChange:r,disabled:s,requiredReadonly:i=!0}){const{t:a}=Mn(),l=()=>r([...n,{type:"text",name:"",default:"",required:!1,showOnNode:!1}]),c=u=>r(n.filter((p,m)=>m!==u)),d=(u,p,m)=>{const y=n.map((b,k)=>{if(k!==u)return b;const g={...b,[p]:m};return p==="required"&&m===!0&&(g.showOnNode=!0),g});r(y)},f=e==="input"?"input":"output";return o.jsxs("div",{className:"af-node-props-field af-node-props-field--io",children:[o.jsxs("div",{className:"af-node-props-io-head",children:[o.jsx("span",{className:"af-node-props-label",children:t}),o.jsx("button",{type:"button",className:"af-btn-ghost af-node-props-io-add",onClick:l,disabled:s,"aria-label":a("flow:nodeProps.addPinAriaLabel",{label:t}),children:a("flow:nodeProps.addPin")})]}),o.jsx("p",{className:"af-node-props-io-hint",children:a("flow:nodeProps.handleHint",{prefix:f})}),n.length===0?o.jsx("p",{className:"af-node-props-io-empty",children:a(e==="input"?"flow:nodeProps.noInputPins":"flow:nodeProps.noOutputPins")}):null,n.length>0?o.jsxs("div",{className:"af-node-props-io-table",role:"group","aria-label":t,children:[o.jsxs("div",{className:"af-node-props-io-table-head","aria-hidden":!0,children:[o.jsx("span",{children:a("flow:nodeProps.handle")}),o.jsx("span",{children:a("flow:nodeProps.type")}),o.jsx("span",{children:a("flow:nodeProps.name")}),o.jsx("span",{children:a("flow:nodeProps.defaultValue")}),o.jsx("span",{children:a("flow:nodeProps.required")}),o.jsx("span",{children:a("flow:nodeProps.showOnNode")}),o.jsx("span",{})]}),n.map((u,p)=>o.jsxs("div",{className:"af-node-props-io-row",children:[o.jsxs("span",{className:"af-node-props-io-handle",title:`${f}-${p}`,children:[f,"-",p]}),o.jsx("select",{className:"af-node-props-input af-node-props-io-cell",value:u.type,onChange:m=>d(p,"type",m.target.value),disabled:s,"aria-label":a("flow:nodeProps.pinTypeAriaLabel",{label:t,index:p}),children:["node","text","file","bool"].map(m=>o.jsx("option",{value:m,children:m},m))}),o.jsx("input",{type:"text",className:"af-node-props-input af-node-props-io-cell",value:u.name,onChange:m=>d(p,"name",m.target.value),disabled:s,spellCheck:!1,autoComplete:"off","aria-label":a("flow:nodeProps.pinNameAriaLabel",{label:t,index:p})}),o.jsx("input",{type:"text",className:"af-node-props-input af-node-props-io-cell",value:u.default,onChange:m=>d(p,"default",m.target.value),disabled:s,spellCheck:!1,autoComplete:"off","aria-label":a("flow:nodeProps.pinDefaultAriaLabel",{label:t,index:p})}),o.jsx("label",{className:"af-node-props-io-flag",title:a("flow:nodeProps.requiredHint"),children:o.jsx("input",{type:"checkbox",checked:!!u.required,onChange:m=>{i||d(p,"required",m.target.checked)},disabled:s||i,"aria-label":a("flow:nodeProps.pinRequiredAriaLabel",{label:t,index:p})})}),o.jsx("label",{className:"af-node-props-io-flag",title:a("flow:nodeProps.showOnNodeHint"),children:o.jsx("input",{type:"checkbox",checked:u.showOnNode!==!1,onChange:m=>d(p,"showOnNode",m.target.checked),disabled:s,"aria-label":a("flow:nodeProps.pinShowOnNodeAriaLabel",{label:t,index:p})})}),o.jsx("button",{type:"button",className:"af-icon-btn af-node-props-io-remove",onClick:()=>c(p),disabled:s,"aria-label":a("flow:nodeProps.deletePinAriaLabel",{label:t,index:p}),title:a("flow:nodeProps.deletePin"),children:o.jsx("span",{className:"material-symbols-outlined",children:"delete"})})]},`${f}-${p}`))]}):null]})}function JT({draft:e,setDraft:t,definitionId:n,systemPromptReadonly:r,modelLists:s,disabled:i,onIdBlur:a,onClose:l,onPublishToMarketplace:c,allowEditRequiredPins:d=!1,error:f,ioSlots:u}){const{t:p}=Mn(),[m,y]=h.useState(!1),[b,k]=h.useState(!1),[g,v]=h.useState({status:"idle",message:""}),x=h.useCallback($=>{t(W=>W&&{...W,...$})},[t]),{cursorList:N,opencodeList:_,claudeCodeList:C,currentNotInLists:T}=h.useMemo(()=>{const $=Array.isArray(s==null?void 0:s.cursor)?s.cursor:[],W=Array.isArray(s==null?void 0:s.opencode)?s.opencode:[],O=Array.isArray(s==null?void 0:s.claudeCode)?s.claudeCode:[],R=new Set([...$,...W,...O].map(Dh)),I=((e==null?void 0:e.model)??"").trim(),z=I.startsWith("cursor:")?I.slice(7):I.startsWith("opencode:")?I.slice(9):I.startsWith("claude-code:")?I.slice(12):I,P=I&&!R.has(z)?I:"";return{cursorList:$,opencodeList:W,claudeCodeList:O,currentNotInLists:P}},[s,e==null?void 0:e.model]);if(!e)return null;const H=String(e.script??""),M=n==="tool_nodejs"||H.trim()!=="",F=typeof c=="function"&&!i&&(e==null?void 0:e.newId),D=async()=>{if(F){v({status:"running",message:p("flow:nodeProps.publishRunning")});try{const $=await c(e,n);v({status:"success",message:$!=null&&$.definitionId?p("flow:nodeProps.publishSuccessWithId",{id:$.definitionId}):p("flow:nodeProps.publishSuccess")})}catch($){v({status:"error",message:String(($==null?void 0:$.message)||$)})}}};return o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"af-pipeline-drawer-head af-node-props-head",children:[o.jsx("h2",{className:"af-pipeline-drawer-title",children:p("flow:nodeProps.title")}),o.jsxs("div",{className:"af-node-props-head-actions",children:[o.jsxs("button",{type:"button",className:"af-btn-ghost af-node-props-market-btn",onClick:D,disabled:!F||g.status==="running",title:p("flow:nodeProps.publishToMarketplaceHint"),children:[o.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"inventory_2"}),g.status==="running"?p("flow:nodeProps.publishing"):p("flow:nodeProps.publishToMarketplace")]}),o.jsx("button",{type:"button",className:"af-btn-ghost af-node-props-close-secondary",onClick:l,children:p("common:common.close")})]})]}),o.jsxs("div",{className:"af-pipeline-drawer-body af-node-props-body",children:[f?o.jsx("p",{className:"af-err af-node-props-err",children:f}):null,g.message?o.jsx("p",{className:`af-node-props-market-status af-node-props-market-status--${g.status}`,children:g.message}):null,o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsx("span",{className:"af-node-props-label",children:p("flow:node.nodeType")}),o.jsx("div",{className:"af-pipeline-drawer-readonly af-node-props-readonly-mono",children:n})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsxs("span",{className:"af-node-props-label",children:[p("flow:nodeProps.instanceId"),o.jsx("span",{className:"af-node-props-hint",children:p("flow:node.displayNameHint")})]}),o.jsx("input",{type:"text",className:"af-node-props-input",value:e.newId,onChange:$=>x({newId:$.target.value}),onBlur:a,disabled:i,spellCheck:!1,autoComplete:"off","aria-label":p("flow:nodeProps.instanceId")})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsxs("span",{className:"af-node-props-label",children:[p("flow:node.displayName"),"(LABEL)"]}),o.jsx("input",{type:"text",className:"af-node-props-input",value:e.label,onChange:$=>x({label:$.target.value}),disabled:i,spellCheck:!1})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsxs("span",{className:"af-node-props-label",children:[p("flow:node.role"),"(ROLE)"]}),o.jsx("select",{className:"af-node-props-select",value:dl.includes(e.role)?e.role:p("flow:roles.normal"),onChange:$=>x({role:$.target.value}),disabled:i,children:dl.map($=>o.jsx("option",{value:$,children:$},$))})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsxs("span",{className:"af-node-props-label",children:[p("flow:node.model"),"(MODEL)"]}),o.jsx("span",{className:"af-node-props-sublabel",children:p("flow:node.modelHint")}),o.jsxs("select",{className:"af-node-props-select",value:(()=>{const $=(e.model||"").trim();return $?T||$:""})(),onChange:$=>x({model:$.target.value}),disabled:i,"aria-label":p("flow:nodeProps.modelAriaLabel"),children:[o.jsx("option",{value:"",children:p("flow:node.defaultModel")}),T?o.jsxs("option",{value:T,children:[T,p("flow:nodeProps.yamlValueNotInList")]}):null,N.length>0?o.jsx("optgroup",{label:"Cursor",children:N.map($=>o.jsx("option",{value:Dh($),children:$},`c-${$}`))}):null,_.length>0?o.jsx("optgroup",{label:"OpenCode",children:_.map($=>o.jsx("option",{value:Dh($),children:$},`o-${$}`))}):null,C.length>0?o.jsx("optgroup",{label:"Claude Code",children:C.map($=>o.jsx("option",{value:`claude-code:${Dh($)}`,children:$},`cc-${$}`))}):null]})]}),o.jsx(Gj,{kind:"input",label:p("flow:nodeProps.inputPins"),slots:Array.isArray(e.inputs)?e.inputs:[],onSlotsChange:$=>x({inputs:$}),disabled:i,requiredReadonly:!d}),o.jsx(Gj,{kind:"output",label:p("flow:nodeProps.outputPins"),slots:Array.isArray(e.outputs)?e.outputs:[],onSlotsChange:$=>x({outputs:$}),disabled:i,requiredReadonly:!d}),M?o.jsxs("div",{className:"af-pipeline-drawer-field af-node-props-field af-node-props-field--prompt",children:[o.jsxs("div",{className:"af-node-props-prompt-head",children:[o.jsxs("span",{className:"af-node-props-label",children:[p("flow:node.directCommand"),"(script)",o.jsx("span",{className:"af-node-props-hint",children:p("flow:node.scriptHint")})]}),o.jsx("button",{type:"button",className:"af-icon-btn af-node-props-expand",onClick:()=>k(!0),"aria-label":p("flow:nodeProps.expandEditScript"),title:p("flow:nodeProps.expand"),disabled:i,children:o.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),o.jsx($h,{value:H,onChange:$=>x({script:$}),disabled:i,placeholder:p("flow:nodeProps.scriptPlaceholder"),rows:6,textareaClassName:"af-pipeline-drawer-textarea af-node-props-body-textarea af-node-props-script-textarea",ioSlots:u,variant:"drawer"})]}):null,o.jsxs("div",{className:"af-pipeline-drawer-field af-node-props-field af-node-props-field--prompt",children:[o.jsxs("div",{className:"af-node-props-prompt-head",children:[o.jsx("span",{className:"af-node-props-label",children:p("flow:node.userPrompt")}),o.jsx("button",{type:"button",className:"af-icon-btn af-node-props-expand",onClick:()=>y(!0),"aria-label":p("flow:nodeProps.expandEdit"),title:p("flow:nodeProps.expand"),disabled:i,children:o.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),o.jsx($h,{value:e.body,onChange:$=>x({body:$}),images:e.images,onImagesChange:$=>x({images:$}),disabled:i,placeholder:p("flow:nodeProps.bodyPlaceholder"),rows:8,textareaClassName:"af-pipeline-drawer-textarea af-node-props-body-textarea",ioSlots:u,variant:"drawer"})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsx("span",{className:"af-node-props-label",children:p("flow:node.systemDescription")}),o.jsx("textarea",{className:"af-pipeline-drawer-textarea af-node-props-system-readonly",rows:4,readOnly:!0,value:r||p("flow:nodeProps.noDescription"),spellCheck:!1})]})]}),b?o.jsx("div",{className:"af-node-props-expand-overlay",role:"dialog","aria-modal":"true","aria-label":p("flow:nodeProps.editScript"),onMouseDown:$=>{$.target===$.currentTarget&&k(!1)},children:o.jsxs("div",{className:"af-node-props-expand-panel",children:[o.jsxs("div",{className:"af-node-props-expand-head",children:[o.jsx("span",{className:"af-node-props-expand-title",children:p("flow:node.directCommand")}),o.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>k(!1),"aria-label":p("flow:nodeProps.collapse"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsx($h,{value:H,onChange:$=>x({script:$}),disabled:i,placeholder:p("flow:nodeProps.scriptPlaceholderExpand"),rows:16,textareaClassName:"af-node-props-expand-textarea",ioSlots:u,variant:"expand"})]})}):null,m?o.jsx("div",{className:"af-node-props-expand-overlay",role:"dialog","aria-modal":"true","aria-label":p("flow:nodeProps.editUserPrompt"),onMouseDown:$=>{$.target===$.currentTarget&&y(!1)},children:o.jsxs("div",{className:"af-node-props-expand-panel",children:[o.jsxs("div",{className:"af-node-props-expand-head",children:[o.jsx("span",{className:"af-node-props-expand-title",children:p("flow:node.body")}),o.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>y(!1),"aria-label":p("flow:nodeProps.collapse"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsx($h,{value:e.body,onChange:$=>x({body:$}),images:e.images,onImagesChange:$=>x({images:$}),disabled:i,placeholder:p("flow:nodeProps.bodyPlaceholderExpand"),rows:16,textareaClassName:"af-node-props-expand-textarea",ioSlots:u,variant:"expand"})]})}):null]})}function R0(e){var n;if(e.displayKind==="image"||e.encoding==="base64"&&((n=e.mimeType)!=null&&n.startsWith("image/")))return"image";if(e.displayKind==="json"||e.mimeType==="application/json")return"json";if(e.displayKind==="markdown"||e.mimeType==="text/markdown")return"markdown";if(e.displayKind==="text")return"text";const t=(e.content||"").trim();if(t&&(t.startsWith("{")||t.startsWith("[")))try{return JSON.parse(t),"json"}catch{}return"text"}function UK(e){const t=R0(e);if(t==="image"){const n=(e.mimeType||"image/png").split("/")[1];return n?n.toUpperCase():"IMAGE"}return t==="json"?"JSON":t==="markdown"?"MD":null}function QT(e){try{return JSON.stringify(JSON.parse(e.trim()),null,2)}catch{return e}}function Xj({text:e}){const{t}=Mn(),n=e||"";return n.trim()?o.jsx("div",{className:"af-run-ctx-md",children:o.jsx(vp,{children:n})}):o.jsx("div",{className:"af-run-ctx-hint",children:t("flow:runContext.empty")})}function Jj({o:e}){var r;const{t}=Mn(),n=R0(e);if(n==="image"||e.encoding==="base64"&&((r=e.mimeType)!=null&&r.startsWith("image/"))){const i=`data:${e.mimeType||"image/png"};base64,${e.content||""}`;return o.jsxs("div",{className:"af-run-ctx-media",children:[o.jsx("img",{className:"af-run-ctx-img",src:i,alt:e.slot||"output",loading:"lazy"}),e.truncated?o.jsx("div",{className:"af-run-ctx-hint",children:t("flow:runContext.imageTruncated")}):null]})}if(n==="json")return o.jsx("pre",{className:"af-run-ctx-pre",children:QT(e.content||"")});if(n==="markdown"){const s=e.content||"";return s.trim()?o.jsx("div",{className:"af-run-ctx-md",children:o.jsx(vp,{children:s})}):o.jsx("div",{className:"af-run-ctx-hint",children:t("flow:runContext.empty")})}return o.jsx("pre",{className:"af-run-ctx-pre",children:e.content!=null&&e.content!==""?e.content:t("flow:runContext.empty")})}function Qj(e){return UK(e)}function Zj(e){var r;if(!e)return null;const t=R0(e);if(t==="image"||e.encoding==="base64"&&((r=e.mimeType)!=null&&r.startsWith("image/")))return null;const n=e.content;return n==null||n===""?null:t==="json"?QT(String(n)):String(n)}function e1({text:e,title:t,copiedLabel:n}){const[r,s]=h.useState(!1);if(!e)return null;const i=async()=>{try{await navigator.clipboard.writeText(e),s(!0),window.setTimeout(()=>s(!1),1400)}catch{}};return o.jsx("button",{type:"button",className:"af-icon-btn af-run-ctx-copy-btn",onClick:i,title:r?n:t,"aria-label":r?n:t,children:o.jsx("span",{className:"material-symbols-outlined",children:r?"check":"content_copy"})})}const t1=2e4,ZT="af:run-node-ctx-width";function mm(){return typeof window>"u"?416:Math.min(26*16,window.innerWidth-32)}function qa(e){const n=Math.max(280,Math.min(Math.floor(window.innerWidth*.92),1200));return Number.isFinite(e)?Math.min(Math.max(Math.round(e),200),n):qa(mm())}function KK(){try{const e=localStorage.getItem(ZT);if(e==null)return qa(mm());const t=parseInt(e,10);return Number.isFinite(t)?qa(t):qa(mm())}catch{return qa(mm())}}async function n1(e,t,n,r){const s=new URLSearchParams({flowId:e,instanceId:t});n&&String(n).trim()&&s.set("runId",String(n).trim());const i=await fetch(`/api/node-exec-context?${s.toString()}`,{signal:r}),a=await i.text();let l;try{l=JSON.parse(a)}catch{throw new Error(a.startsWith("<!")||a.startsWith("<html")?"apiConnectError":"invalidJson")}if(!i.ok)throw new Error(l.error||"HTTP "+i.status);return l}function qK(e,t){const n=`flow:runContext.${t}`,r=e(n);return r!==n?r:t}function YK({instanceId:e,flowId:t,runId:n,nodeStatus:r,onClose:s}){const{t:i}=Mn(),[a,l]=h.useState(()=>typeof window<"u"&&window.matchMedia("(max-width: 960px)").matches),[c,d]=h.useState(KK),f=h.useRef({active:!1,pointerId:-1,startX:0,startW:416}),[u,p]=h.useState(!0),[m,y]=h.useState(""),[b,k]=h.useState([]),[g,v]=h.useState(null),[x,N]=h.useState(null),_=h.useRef(null),C=h.useRef(null),T=h.useRef(0),H=h.useRef(0);h.useLayoutEffect(()=>{const P=window.matchMedia("(max-width: 960px)"),L=()=>l(P.matches);return P.addEventListener("change",L),()=>P.removeEventListener("change",L)},[]),h.useEffect(()=>{function P(){d(L=>qa(L))}return window.addEventListener("resize",P),()=>window.removeEventListener("resize",P)},[]);const M=h.useCallback(()=>{d(P=>{const L=qa(P);try{localStorage.setItem(ZT,String(L))}catch{}return L})},[]),F=h.useCallback(P=>{if(a||P.button!==0)return;P.preventDefault();const L=P.currentTarget;f.current={active:!0,pointerId:P.pointerId,startX:P.clientX,startW:c},L.setPointerCapture(P.pointerId)},[a,c]),D=h.useCallback(P=>{const L=f.current;if(!L.active||P.pointerId!==L.pointerId)return;const E=L.startX-P.clientX;d(qa(L.startW+E))},[]),$=h.useCallback(P=>{const L=f.current;if(!(!L.active||P.pointerId!==L.pointerId)){L.active=!1;try{P.currentTarget.releasePointerCapture(P.pointerId)}catch{}M()}},[M]),W=h.useCallback(()=>{const P=f.current;P.active&&(P.active=!1,M())},[M]),O=h.useCallback(P=>{const L=Array.isArray(P)?P:[];k(L),v(E=>E&&L.some(X=>X.execId===E)?E:L.length>0?L[L.length-1].execId:null)},[]),R=h.useCallback(()=>{if(!e||!t)return;const P=++T.current,L=new AbortController,E=window.setTimeout(()=>L.abort(),t1);(async()=>{try{const X=await n1(t,e,n,L.signal);if(P!==T.current)return;O(Array.isArray(X.rounds)?X.rounds:[])}catch{}finally{window.clearTimeout(E)}})()},[e,t,n,O]);h.useEffect(()=>{if(!e||!t){p(!1),y(""),k([]);return}const P=++H.current;p(!0),y(""),k([]),v(null);const L=new AbortController,E=window.setTimeout(()=>L.abort(),t1);return(async()=>{try{const X=await n1(t,e,n,L.signal);if(P!==H.current)return;O(Array.isArray(X.rounds)?X.rounds:[])}catch(X){if(P!==H.current)return;const ee=(X==null?void 0:X.name)==="AbortError"?"requestTimeout":X.message||String(X);y(ee)}finally{window.clearTimeout(E),P===H.current&&p(!1)}})(),()=>{L.abort(),H.current++,T.current++}},[e,t,n,O]),h.useEffect(()=>{r&&R()},[r,R]),h.useEffect(()=>{clearInterval(C.current);const P=b.length>0?b[b.length-1]:null;return(r==="running"&&b.length===0||!!(P&&P.status==="running"))&&e&&t&&(C.current=setInterval(()=>R(),2e3)),()=>clearInterval(C.current)},[b,e,t,n,r,R]),h.useEffect(()=>{_.current&&(_.current.scrollTop=0)},[g]);const I=b.find(P=>P.execId===g),z=a?void 0:{width:`${c}px`};return o.jsxs("aside",{className:"af-run-ctx-panel",style:z,"aria-label":i("flow:runContext.title"),children:[a?null:o.jsx("div",{className:"af-run-ctx-resize",role:"separator","aria-orientation":"vertical","aria-label":i("flow:runContext.resizeHandle"),onPointerDown:F,onPointerMove:D,onPointerUp:$,onPointerCancel:$,onLostPointerCapture:W}),o.jsxs("div",{className:"af-run-ctx-panel__main",children:[o.jsxs("div",{className:"af-run-ctx-head",children:[o.jsx("h2",{className:"af-run-ctx-title",title:e,children:e}),o.jsx("button",{type:"button",className:"af-icon-btn",onClick:s,"aria-label":i("common:common.close"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),u&&o.jsx("div",{className:"af-run-ctx-placeholder",children:i("common:common.loading")}),m&&o.jsx("div",{className:"af-run-ctx-error",children:qK(i,m)}),!u&&!m&&b.length===0&&o.jsx("div",{className:"af-run-ctx-placeholder",children:i(r==="running"?"flow:runContext.executingNoArtifacts":"flow:runContext.noData")}),b.length>0&&o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"af-run-ctx-rounds af-run-ctx-rounds--select af-run-ctx-round--"+XK((I==null?void 0:I.status)||""),children:[o.jsx("span",{className:"af-run-ctx-round-dot","aria-hidden":!0}),o.jsx("select",{className:"af-run-ctx-round-select",value:String(g??""),onChange:P=>{const L=P.target.value;v(L==="latest"?"latest":Number(L))},children:[...b].reverse().map(P=>{const L=P.execId==="latest"?i("flow:runContext.latest"):`#${P.execId}`,E=JK(i,P.status),X=P.finishedAt?` · ${GK(P.finishedAt)}`:"";return o.jsx("option",{value:String(P.execId),children:`${L} · ${E}${X}`},P.execId)})})]}),I&&o.jsxs("div",{className:"af-run-ctx-body",ref:_,children:[I.inputs&&I.inputs.length>0&&o.jsxs("section",{className:"af-run-ctx-section",children:[o.jsxs("h3",{className:"af-run-ctx-section-title",children:[o.jsx("span",{className:"material-symbols-outlined af-run-ctx-section-icon","aria-hidden":!0,children:"input"}),"Inputs"]}),I.inputs.map((P,L)=>o.jsxs("div",{className:"af-run-ctx-output-slot",children:[o.jsx("div",{className:"af-run-ctx-slot-head",children:o.jsx("div",{className:"af-run-ctx-slot-name",children:P.slot})}),o.jsx("pre",{className:"af-run-ctx-slot-text",children:P.value})]},`${P.slot}-${L}`))]}),I.prompt!=null&&o.jsxs("section",{className:"af-run-ctx-section",children:[o.jsxs("h3",{className:"af-run-ctx-section-title",children:[o.jsx("span",{className:"material-symbols-outlined af-run-ctx-section-icon","aria-hidden":!0,children:"description"}),"Prompt",o.jsx("button",{type:"button",className:"af-icon-btn af-run-ctx-section-expand",onClick:()=>N("prompt"),title:i("flow:nodeProps.expand"),children:o.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),o.jsx(Xj,{text:I.prompt})]}),I.outputs&&I.outputs.length>0&&o.jsxs("section",{className:"af-run-ctx-section",children:[o.jsxs("h3",{className:"af-run-ctx-section-title",children:[o.jsx("span",{className:"material-symbols-outlined af-run-ctx-section-icon","aria-hidden":!0,children:"output"}),"Outputs",o.jsx("button",{type:"button",className:"af-icon-btn af-run-ctx-section-expand",onClick:()=>N("output"),title:i("flow:nodeProps.expand"),children:o.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),I.outputs.map((P,L)=>{const E=Qj(P),X=Zj(P);return o.jsxs("div",{className:"af-run-ctx-output-slot",children:[o.jsxs("div",{className:"af-run-ctx-slot-head",children:[o.jsx("div",{className:"af-run-ctx-slot-name",children:P.slot}),E?o.jsx("span",{className:"af-run-ctx-format-badge",title:i("flow:runContext.detectedContentType"),children:E}):null,o.jsx(e1,{text:X,title:i("common:common.copy"),copiedLabel:i("common:common.copied")})]}),o.jsx(Jj,{o:P})]},`${P.slot}-${L}`)})]}),!I.prompt&&(!I.outputs||I.outputs.length===0)&&o.jsx("div",{className:"af-run-ctx-placeholder",children:i("flow:runContext.roundNoContent")})]})]})]}),x&&I&&o.jsx("div",{className:"af-node-props-expand-overlay",role:"dialog","aria-modal":"true",onClick:P=>{P.target===P.currentTarget&&N(null)},children:o.jsxs("div",{className:"af-node-props-expand-panel",children:[o.jsxs("div",{className:"af-node-props-expand-head",children:[o.jsx("span",{className:"af-node-props-expand-title",children:x==="prompt"?"Prompt":"Outputs"}),o.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>N(null),"aria-label":i("common:common.close"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsxs("div",{className:"af-node-props-expand-body af-run-ctx-expand-body",children:[x==="prompt"&&I.prompt!=null&&o.jsx(Xj,{text:I.prompt}),x==="output"&&I.outputs&&I.outputs.map((P,L)=>{const E=Qj(P),X=Zj(P);return o.jsxs("div",{className:"af-run-ctx-output-slot",style:{marginBottom:"1rem"},children:[o.jsxs("div",{className:"af-run-ctx-slot-head",children:[o.jsx("div",{className:"af-run-ctx-slot-name",children:P.slot}),E?o.jsx("span",{className:"af-run-ctx-format-badge",children:E}):null,o.jsx(e1,{text:X,title:i("common:common.copy"),copiedLabel:i("common:common.copied")})]}),o.jsx(Jj,{o:P})]},`${P.slot}-${L}`)})]})]})})]})}function GK(e){try{const t=new Date(e);if(isNaN(t.getTime()))return e;const n=r=>String(r).padStart(2,"0");return`${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}`}catch{return e}}function XK(e){const t=String(e||"").toLowerCase();return t==="success"||t==="completed"||t==="done"?"success":t==="failed"||t==="error"?"failed":t==="running"||t==="executing"?"running":t==="cache_not_met"?"cache":t?"unknown":"pending"}function JK(e,t){const n=String(t||"").toLowerCase();return n?n==="success"||n==="completed"||n==="done"?e("flow:runContext.statusSuccess",{defaultValue:"成功"}):n==="failed"||n==="error"?e("flow:runContext.statusFailed",{defaultValue:"失败"}):n==="running"||n==="executing"?e("flow:runContext.statusRunning",{defaultValue:"运行中"}):n==="cache_not_met"?e("flow:runContext.statusCacheMiss",{defaultValue:"缓存失效"}):t:e("flow:runContext.statusPending",{defaultValue:"等待"})}function QK({flowId:e,flowSource:t,flowArchived:n,provideNodes:r,edges:s,nodes:i,onCliInputsChange:a,onBackToEdit:l}){const{t:c}=Mn(),[d,f]=h.useState({}),[u,p]=h.useState(null),[m,y]=h.useState({}),[b,k]=h.useState(!0),[g,v]=h.useState(!1),[x,N]=h.useState(""),[_,C]=h.useState(!1),[T,H]=h.useState(null),M=h.useRef(null),F=h.useRef(!0),D=h.useRef({});h.useMemo(()=>{var E,X,ee;const L={};for(const V of r){const ie=(ee=(X=(E=V.data)==null?void 0:E.outputs)==null?void 0:X[0])==null?void 0:ee.default;ie!=null&&ie!==""&&(L[V.id]=String(ie))}return D.current=L,L},[r]);const $=h.useMemo(()=>{var E;const L={};for(const X of i){if(!((E=X.data)!=null&&E.inputs))continue;const ee=X.data.inputs;for(let V=0;V<ee.length;V++){const ie=ee[V];if(!(ie!=null&&ie.name))continue;const fe=s.find(ge=>ge.target===X.id&&ge.targetHandle===`input-${V}`);if(!(fe!=null&&fe.source))continue;r.find(ge=>ge.id===fe.source)&&(L[fe.source]=ie.name)}}return L},[i,s,r]);h.useEffect(()=>(F.current=!0,()=>{F.current=!1}),[]),h.useEffect(()=>{if(!e){k(!1);return}k(!0);const L=new URLSearchParams({flowId:e,flowSource:t||"user"});n&&L.set("archived","1"),fetch(`/api/flow/run-config?${L.toString()}`).then(E=>{if(!E.ok)throw new Error(`HTTP ${E.status}`);return E.json()}).then(E=>{var ee;if(!F.current)return;f(E.presets||{}),p(E.activePreset||null);const X=E.activePreset&&((ee=E.presets)!=null&&ee[E.activePreset])?E.presets[E.activePreset]:{};y({...D.current,...X}),k(!1)}).catch(()=>{F.current&&(y(D.current),k(!1))})},[e,t,n]),h.useEffect(()=>{var E;if(!a)return;const L={};for(const[X,ee]of Object.entries(m)){const V=$[X];if(!V)continue;const ie=r.find(me=>me.id===X);if(!ie)continue;(((E=ie.data)==null?void 0:E.definitionId)||"").startsWith("provide_file")?L[V]={type:"file",path:ee}:L[V]={type:"str",value:ee}}a(L)},[m,$,r,a]);const W=h.useCallback((L,E)=>{y(X=>({...X,[L]:E}))},[]),O=h.useCallback(L=>{L!==u&&(p(L),L&&d[L]?y({...D.current,...d[L]}):y(D.current))},[u,d]),R=h.useCallback(async()=>{if(x.trim()){v(!0);try{const L={...d,[x.trim()]:m},E={flowId:e,flowSource:t,archived:n,presets:L,activePreset:x.trim()};(await fetch("/api/flow/run-config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(E)})).ok&&(f(L),p(x.trim()),N(""),C(!1))}finally{v(!1)}}},[e,t,n,d,m,x]),I=h.useCallback(async()=>{if(u){v(!0);try{const L={...d};delete L[u];const E=Object.keys(L)[0]||null;(await fetch("/api/flow/run-config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:e,flowSource:t,archived:n,presets:L,activePreset:E})})).ok&&(f(L),p(E),E&&L[E]?y({...D.current,...L[E]}):y(D.current))}finally{v(!1)}}},[e,t,n,d,u]),z=h.useCallback(async()=>{if(u){v(!0);try{const L={...d,[u]:m};(await fetch("/api/flow/run-config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:e,flowSource:t,archived:n,presets:L,activePreset:u})})).ok&&f(L)}finally{v(!1)}}},[e,t,n,d,u,m]),P=Object.keys(d);return P.length>0,b?o.jsx("aside",{className:"af-run-config-panel",children:o.jsx("div",{className:"af-run-config-loading",children:c("common.loading")})}):o.jsxs("aside",{className:"af-run-config-panel",children:[o.jsxs("div",{className:"af-run-config-preset",children:[o.jsx("label",{className:"af-run-config-preset-label",children:c("flow:runConfig.preset")}),o.jsxs("div",{className:"af-run-config-preset-row",children:[o.jsxs("select",{className:"af-run-config-preset-select",value:u||"",onChange:L=>O(L.target.value||null),disabled:g,children:[o.jsx("option",{value:"",children:c("flow:runConfig.default")}),P.map(L=>o.jsx("option",{value:L,children:L},L))]}),o.jsx("button",{type:"button",className:"af-run-config-preset-btn af-run-config-preset-btn--new",onClick:()=>C(!0),disabled:g,title:c("flow:runConfig.newPreset"),children:o.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"add"})}),u&&o.jsx("button",{type:"button",className:"af-run-config-preset-btn af-run-config-preset-btn--save",onClick:z,disabled:g,title:c("flow:runConfig.savePreset"),children:o.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"save"})}),u&&o.jsx("button",{type:"button",className:"af-run-config-preset-btn af-run-config-preset-btn--delete",onClick:I,disabled:g,title:c("flow:runConfig.deletePreset"),children:o.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"delete"})})]})]}),_&&o.jsxs("div",{className:"af-run-config-save-dialog",children:[o.jsx("input",{type:"text",className:"af-run-config-save-input",placeholder:c("flow:runConfig.presetNamePlaceholder"),value:x,onChange:L=>N(L.target.value),disabled:g}),o.jsxs("div",{className:"af-run-config-save-actions",children:[o.jsx("button",{type:"button",className:"af-btn-primary",onClick:R,disabled:g||!x.trim(),children:c(g?"common.saving":"common.save")}),o.jsx("button",{type:"button",className:"af-btn-outline",onClick:()=>{C(!1),N("")},disabled:g,children:c("common.cancel")})]})]}),o.jsxs("div",{className:"af-run-config-inputs",children:[o.jsx("div",{className:"af-run-config-inputs-header",children:c("flow:runConfig.inputParams")}),r.length===0?o.jsx("div",{className:"af-run-config-empty",children:c("flow:runConfig.noProvideNodes")}):o.jsx("div",{className:"af-run-config-input-list",children:r.map(L=>{var ge,Z;const E=((ge=L.data)==null?void 0:ge.definitionId)||"",X=E.startsWith("provide_file"),ee=E==="provide_bool",V=((Z=L.data)==null?void 0:Z.label)||L.id,ie=L.id,fe=m[ie]||"",me=["true","1","yes","on"].includes(String(fe).trim().toLowerCase());return o.jsxs("div",{className:"af-run-config-input-item",children:[o.jsxs("div",{className:"af-run-config-input-head",children:[o.jsx("span",{className:"af-run-config-input-icon material-symbols-outlined"+(X?" af-run-config-input-icon--file":""),"aria-hidden":!0,children:X?"description":ee?"toggle_on":"text_fields"}),o.jsx("span",{className:"af-run-config-input-label",children:V}),ee?null:o.jsx("button",{type:"button",className:"af-run-config-input-expand",onClick:()=>H({instanceId:ie,label:V,content:fe}),"aria-label":c("flow:runConfig.expandInput"),title:c("flow:runConfig.expandInput"),children:o.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),o.jsx("div",{className:"af-run-config-input-id",children:ie}),ee?o.jsx("button",{type:"button",className:"af-run-config-bool-toggle"+(me?" af-run-config-bool-toggle--true":""),onClick:()=>W(ie,me?"false":"true"),"aria-pressed":me,children:me?"true":"false"}):o.jsx("input",{type:"text",className:"af-run-config-input-field",value:fe,onChange:ae=>W(ie,ae.target.value),placeholder:c(X?"flow:runConfig.filePathPlaceholder":"flow:runConfig.stringValuePlaceholder")})]},ie)})})]}),T&&Fr.createPortal(o.jsx("div",{className:"af-provide-edit-overlay",children:o.jsxs("div",{className:"af-provide-edit-modal",role:"dialog","aria-modal":"true",children:[o.jsxs("div",{className:"af-provide-edit-modal__head",children:[o.jsx("span",{className:"material-symbols-outlined",children:"edit_document"}),o.jsx("span",{className:"af-provide-edit-modal__title",children:T.label}),o.jsx("button",{type:"button",className:"af-provide-edit-modal__close",onClick:()=>H(null),"aria-label":c("common:close"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsx("div",{className:"af-provide-edit-modal__body",children:o.jsx("textarea",{ref:M,className:"af-provide-edit-modal__textarea",defaultValue:T.content,autoFocus:!0})}),o.jsxs("div",{className:"af-provide-edit-modal__foot",children:[o.jsxs("button",{type:"button",className:"af-provide-edit-modal__btn af-provide-edit-modal__btn--save",onClick:()=>{!T||!M.current||(W(T.instanceId,M.current.value),H(null))},children:[o.jsx("span",{className:"material-symbols-outlined",children:"save"}),c("flow:provideEdit.save")]}),o.jsxs("button",{type:"button",className:"af-provide-edit-modal__btn",onClick:()=>H(null),children:[o.jsx("span",{className:"material-symbols-outlined",children:"close"}),c("flow:provideEdit.cancel")]})]})]})}),document.body)]})}const e2={ai:["planner-system","planner-user","planner-response","agent-step-prompt","repair-prompt","ai-thinking","ai-assistant","ai-result","ai-tool"],flow:["composer-start","classify","plan","phase-plan","phase-complete","phase-auto-continue","composer-done"],step:["step-start","step-progress","step-done","validation"],output:["natural","status"],error:["error"]},ZK={"planner-system":"#9ecaff","planner-user":"#9ecaff","planner-response":"#7c4dff","agent-step-prompt":"#7c4dff","repair-prompt":"#ff6b6b","ai-thinking":"#a8b9d4","ai-assistant":"#e8deff","ai-result":"#00e475","ai-tool":"#9ecaff","composer-start":"#00e475","composer-done":"#00e475","step-start":"#e8deff","step-done":"#e8deff","step-progress":"#e8deff",natural:"#a8a8a8",status:"#a8a8a8",error:"#ff6b6b","phase-plan":"#00e475","phase-complete":"#00e475"};function e7(e){return!e||e<1024?`${e||0} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(2)} MB`}function t7(e){if(!e)return"";const t=new Date(e);return isNaN(t.getTime())?e:`${t.getHours().toString().padStart(2,"0")}:${t.getMinutes().toString().padStart(2,"0")}:${t.getSeconds().toString().padStart(2,"0")}.${t.getMilliseconds().toString().padStart(3,"0")}`}function n7(e){if(!e)return"";const t=new Date(e);return isNaN(t.getTime())?e:`${t.getMonth()+1}/${t.getDate()} ${t.getHours().toString().padStart(2,"0")}:${t.getMinutes().toString().padStart(2,"0")}`}function r1(e,t){if(e==="natural"&&t&&typeof t=="object"){const n=t.kind;if(n==="thinking"||n==="assistant"||n==="result"||n==="tool")return"ai";if(n==="error")return"error"}for(const[n,r]of Object.entries(e2))if(r.includes(e))return n;return"other"}function r7({event:e,defaultExpanded:t}){const[n,r]=h.useState(!!t),s=ZK[e.tag]||"#a8a8a8",i=e.payload,a=i&&typeof i=="object",l=a?typeof i.text=="string"?i.text:"":String(i||""),c=a?i.meta:null,d=h.useMemo(()=>l?l.slice(0,140).replace(/\s+/g," "):a?Object.keys(i).filter(m=>m!=="text"&&m!=="meta").slice(0,3).map(m=>{const y=i[m];return y==null?`${m}:null`:typeof y=="object"?`${m}:{…}`:`${m}:${String(y).slice(0,30)}`}).join(" "):"",[i,l,a]),f=h.useCallback(u=>{u.stopPropagation();const p=a?JSON.stringify(i,null,2):String(i);try{navigator.clipboard.writeText(p)}catch{}},[i,a]);return o.jsxs("div",{style:{borderLeft:`3px solid ${s}`,background:n?"#1c1b1b":"#131313",marginBottom:4,borderRadius:4,cursor:"pointer",transition:"background 120ms"},onClick:()=>r(u=>!u),children:[o.jsxs("div",{style:{padding:"6px 10px",display:"flex",alignItems:"center",gap:10,fontSize:12},children:[o.jsx("span",{style:{color:"#9a9a9a",fontFamily:"monospace",flexShrink:0},children:t7(e.ts)}),o.jsx("span",{style:{color:s,fontWeight:600,fontFamily:"monospace",flexShrink:0,padding:"1px 6px",background:"rgba(255,255,255,0.04)",borderRadius:3},children:e.tag}),o.jsx("span",{style:{color:"#c5c2c1",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"monospace"},children:d}),n&&o.jsx("button",{type:"button",onClick:f,style:{background:"rgba(124,77,255,0.15)",color:"#e8deff",border:"none",borderRadius:3,padding:"2px 8px",fontSize:11,cursor:"pointer"},children:"Copy"})]}),n&&o.jsxs("div",{style:{padding:"0 10px 10px 10px",borderTop:"1px solid rgba(255,255,255,0.04)"},children:[c&&Object.keys(c).length>0&&o.jsx("div",{style:{marginTop:8,padding:8,background:"#0e0e0e",borderRadius:4,fontSize:11,fontFamily:"monospace",color:"#9ecaff",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:JSON.stringify(c,null,2)}),l?o.jsx("pre",{style:{marginTop:8,padding:10,background:"#0e0e0e",borderRadius:4,fontSize:12,color:"#e5e2e1",whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:600,overflowY:"auto",margin:"8px 0 0 0",fontFamily:"ui-monospace, SF Mono, Menlo, monospace"},children:l}):a?o.jsx("pre",{style:{marginTop:8,padding:10,background:"#0e0e0e",borderRadius:4,fontSize:12,color:"#e5e2e1",whiteSpace:"pre-wrap",wordBreak:"break-all",maxHeight:400,overflowY:"auto",margin:"8px 0 0 0",fontFamily:"ui-monospace, SF Mono, Menlo, monospace"},children:JSON.stringify(i,null,2)}):null]})]})}function s7({open:e,onClose:t,flowId:n}){var H;const[r,s]=h.useState([]),[i,a]=h.useState(!1),[l,c]=h.useState(null),[d,f]=h.useState(null),[u,p]=h.useState(!1),[m,y]=h.useState(!0),[b,k]=h.useState({ai:!0,flow:!0,step:!0,output:!0,error:!0}),[g,v]=h.useState(""),x=h.useRef(null),N=h.useCallback(async()=>{a(!0);try{const M=m&&n?`?flowId=${encodeURIComponent(n)}`:"",D=await(await fetch(`/api/composer-logs${M}`)).json();s(Array.isArray(D.sessions)?D.sessions:[])}catch{s([])}finally{a(!1)}},[n,m]),_=h.useCallback(async M=>{if(!M){f(null);return}p(!0);try{const D=await(await fetch(`/api/composer-logs/${encodeURIComponent(M)}`)).json();f(D)}catch{f(null)}finally{p(!1)}},[]);h.useEffect(()=>{e&&N()},[e,N]),h.useEffect(()=>{if(!(!e||!l))return _(l),x.current=setInterval(()=>_(l),2e3),()=>{x.current&&clearInterval(x.current),x.current=null}},[e,l,_]);const C=h.useMemo(()=>{const M=(d==null?void 0:d.events)||[],F=g.trim().toLowerCase();return M.filter(D=>{const $=r1(D.tag,D.payload);return!b[$]&&$!=="other"?!1:F?[D.tag,JSON.stringify(D.payload||"")].join(" ").toLowerCase().includes(F):!0})},[d,b,g]),T=h.useMemo(()=>{const M=(d==null?void 0:d.events)||[],F={};for(const D of M){const $=r1(D.tag,D.payload);F[$]=(F[$]||0)+1}return F},[d]);return e?o.jsxs("div",{style:{position:"fixed",top:0,right:0,bottom:0,width:"min(1100px, 80vw)",background:"#131313",borderLeft:"1px solid rgba(255,255,255,0.08)",display:"flex",flexDirection:"column",zIndex:9999,boxShadow:"-8px 0 32px rgba(0,0,0,0.5)",color:"#e5e2e1",fontFamily:"Inter, system-ui, sans-serif"},children:[o.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",gap:12,flexShrink:0,background:"#1c1b1b"},children:[o.jsx("span",{style:{fontWeight:600,fontSize:14},children:"Composer Logs"}),o.jsx("span",{style:{fontSize:11,color:"#9a9a9a"},children:n?`flowId: ${n}`:"no flow selected"}),o.jsxs("label",{style:{fontSize:11,color:"#9a9a9a",display:"flex",alignItems:"center",gap:4,cursor:"pointer"},children:[o.jsx("input",{type:"checkbox",checked:m,onChange:M=>y(M.target.checked),disabled:!n}),"仅显示当前 flow"]}),o.jsx("button",{type:"button",onClick:N,style:{background:"rgba(124,77,255,0.15)",color:"#e8deff",border:"none",borderRadius:4,padding:"4px 10px",fontSize:12,cursor:"pointer"},children:"Refresh"}),o.jsx("span",{style:{flex:1}}),o.jsx("button",{type:"button",onClick:t,style:{background:"transparent",color:"#e5e2e1",border:"1px solid rgba(255,255,255,0.12)",borderRadius:4,padding:"4px 12px",fontSize:12,cursor:"pointer"},children:"Close"})]}),o.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden",minHeight:0},children:[o.jsxs("div",{style:{width:280,borderRight:"1px solid rgba(255,255,255,0.06)",overflowY:"auto",background:"#0e0e0e",flexShrink:0},children:[i&&o.jsx("div",{style:{padding:12,fontSize:12,color:"#9a9a9a"},children:"Loading…"}),!i&&r.length===0&&o.jsx("div",{style:{padding:12,fontSize:12,color:"#9a9a9a"},children:m&&n?"no sessions for this flow":"no sessions"}),r.map(M=>{const F=l===M.sessionId;return o.jsxs("div",{onClick:()=>c(M.sessionId),style:{padding:"10px 12px",borderBottom:"1px solid rgba(255,255,255,0.04)",cursor:"pointer",background:F?"rgba(124,77,255,0.18)":"transparent",borderLeft:F?"3px solid #7c4dff":"3px solid transparent"},children:[o.jsx("div",{style:{fontSize:12,fontWeight:600,color:"#e5e2e1"},children:n7(M.mtime)}),o.jsx("div",{style:{fontSize:11,color:"#9ecaff",marginTop:2,fontFamily:"monospace"},children:M.flowId||"(no flow)"}),M.promptPreview&&o.jsx("div",{style:{fontSize:11,color:"#9a9a9a",marginTop:4,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:M.promptPreview}),o.jsxs("div",{style:{fontSize:10,color:"#6a6a6a",marginTop:4},children:[e7(M.size)," · ",M.model||"default"]})]},M.sessionId)})]}),o.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minHeight:0},children:[o.jsxs("div",{style:{padding:"10px 16px",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",gap:8,flexWrap:"wrap",flexShrink:0,background:"#1c1b1b"},children:[Object.keys(e2).map(M=>o.jsxs("button",{type:"button",onClick:()=>k(F=>({...F,[M]:!F[M]})),style:{background:b[M]?"rgba(124,77,255,0.25)":"transparent",color:b[M]?"#e8deff":"#6a6a6a",border:`1px solid ${b[M]?"rgba(124,77,255,0.4)":"rgba(255,255,255,0.08)"}`,borderRadius:999,padding:"3px 12px",fontSize:11,cursor:"pointer",fontFamily:"monospace",textTransform:"uppercase"},children:[M," ",T[M]!=null?`(${T[M]})`:""]},M)),o.jsx("input",{type:"text",placeholder:"search…",value:g,onChange:M=>v(M.target.value),style:{marginLeft:8,flex:1,minWidth:120,background:"#0e0e0e",border:"1px solid rgba(255,255,255,0.08)",borderRadius:4,color:"#e5e2e1",padding:"4px 8px",fontSize:12}})]}),o.jsxs("div",{style:{flex:1,overflowY:"auto",padding:12,minHeight:0},children:[!l&&o.jsx("div",{style:{color:"#9a9a9a",fontSize:12,padding:20,textAlign:"center"},children:"Select a session on the left to view events"}),u&&!d&&o.jsx("div",{style:{color:"#9a9a9a",fontSize:12,padding:20},children:"Loading…"}),d&&C.length===0&&o.jsxs("div",{style:{color:"#9a9a9a",fontSize:12,padding:20},children:["No events match current filter (",((H=d.events)==null?void 0:H.length)||0," total)"]}),C.map((M,F)=>o.jsx(r7,{event:M,defaultExpanded:M.tag==="error"},`${M.ts}_${F}`))]})]})]})]}):null}const i7="0.1.65";function s1(e){const t=Math.max(0,Number(e)||0),n=Math.floor(t/36e5),r=Math.floor(t%36e5/6e4),s=Math.floor(t%6e4/1e3);return`${String(n).padStart(2,"0")}:${String(r).padStart(2,"0")}:${String(s).padStart(2,"0")}`}function Mx(e,t){return t==="running"?s1(e):e==null||!Number.isFinite(e)||e<=0?"--":s1(e)}const t2=h.createContext({modelLists:{cursor:[],opencode:[]},onModelChange:()=>{}});function o7(e){var v,x,N,_,C,T,H,M,F,D,$;const{setNodes:t}=wc(),n=u0(),{modelLists:r,onModelChange:s}=h.useContext(t2),i=h.useRef(null),a=!!((v=e.data)!=null&&v.readOnly),l=(x=e.data)!=null&&x.displaySize&&Number(e.data.displaySize.width)>0&&Number(e.data.displaySize.height)>0?{width:Number(e.data.displaySize.width),height:Number(e.data.displaySize.height)}:null,c=((N=e.data)==null?void 0:N.definitionId)==="agent_subAgent"&&!((_=e.data)!=null&&_.isRunMode)&&!a,d=h.useCallback(W=>{const O=()=>n(W);window.requestAnimationFrame(O),window.setTimeout(O,80)},[n]),f=h.useCallback((W,O)=>{const R=f1(O);R&&(t(I=>I.map(z=>{var E,X,ee,V,ie,fe;if(z.id!==W)return z;const P=Number(((X=(E=z.data)==null?void 0:E.displaySize)==null?void 0:X.width)||z.width||((ee=z.measured)==null?void 0:ee.width)||0),L=Number(((ie=(V=z.data)==null?void 0:V.displaySize)==null?void 0:ie.height)||z.height||((fe=z.measured)==null?void 0:fe.height)||0);return Math.abs(P-R.width)<2&&Math.abs(L-R.height)<2?z:{...z,width:R.width,height:R.height,data:{...z.data,displaySize:R}}})),d(W))},[d,t]),u=h.useCallback(W=>{if(a)return;const O=i.current;if(!O)return;const R=O.getBoundingClientRect();f(W,{width:Math.max(R.width,O.scrollWidth),height:Math.max(R.height,O.scrollHeight)})},[f,a]),p=h.useCallback(W=>{var ie,fe,me,ge,Z,ae;if(!c)return;W.preventDefault(),W.stopPropagation();const O=i.current,R=O==null?void 0:O.getBoundingClientRect(),I=Number(((fe=(ie=e.data)==null?void 0:ie.displaySize)==null?void 0:fe.width)||e.width||((me=e.measured)==null?void 0:me.width)||(R==null?void 0:R.width)||i2),z=Number(((Z=(ge=e.data)==null?void 0:ge.displaySize)==null?void 0:Z.height)||e.height||((ae=e.measured)==null?void 0:ae.height)||(R==null?void 0:R.height)||Ob),P=W.clientX,L=W.clientY,E=e.id;let X=0;const ee=xe=>{const pe=f1({width:I+xe.clientX-P,height:z+xe.clientY-L});pe&&(window.cancelAnimationFrame(X),X=window.requestAnimationFrame(()=>f(E,pe)))},V=()=>{window.cancelAnimationFrame(X),window.removeEventListener("pointermove",ee),window.removeEventListener("pointerup",V),window.removeEventListener("pointercancel",V),d(E)};window.addEventListener("pointermove",ee),window.addEventListener("pointerup",V,{once:!0}),window.addEventListener("pointercancel",V,{once:!0})},[f,(T=(C=e.data)==null?void 0:C.displaySize)==null?void 0:T.height,(M=(H=e.data)==null?void 0:H.displaySize)==null?void 0:M.width,e.height,e.id,(F=e.measured)==null?void 0:F.height,(D=e.measured)==null?void 0:D.width,e.width,d,c]),m=h.useCallback(W=>{t(O=>O.filter(R=>R.id!==W))},[t]),y=h.useCallback(()=>{var I,z,P,L,E,X,ee,V;const W=((I=e.data)==null?void 0:I.definitionId)||"",O=((z=e.data)==null?void 0:z.label)||e.id,R=((E=(L=(P=e.data)==null?void 0:P.outputs)==null?void 0:L[0])==null?void 0:E.value)||((V=(ee=(X=e.data)==null?void 0:X.outputs)==null?void 0:ee[0])==null?void 0:V.default)||"";window.__provideEditContent={instanceId:e.id,label:O,definitionId:W,content:R},window.dispatchEvent(new CustomEvent("provide-expand"))},[e.id,e.data]),b=h.useCallback((W,O)=>{t(R=>R.map(I=>{var P;if(I.id!==W)return I;const z=Array.isArray((P=I.data)==null?void 0:P.outputs)&&I.data.outputs.length?I.data.outputs.map((L,E)=>E===0?{...L,default:O,value:O}:L):[{type:"bool",name:"value",default:O,value:O}];return{...I,data:{...I.data,body:"",outputs:z}}}))},[t]),k=h.useCallback((W,O)=>{t(R=>R.map(I=>I.id===W?{...I,data:{...I.data,body:O}}:I))},[t]),g=h.useCallback((W,O)=>{t(R=>R.map(I=>I.id===W?{...I,data:{...I.data,images:Ts(O)}}:I))},[t]);return o.jsxs("div",{ref:i,className:"af-flow-node-shell"+(c?" af-flow-node-shell--resizable":""),style:l?{width:l.width,height:l.height}:void 0,children:[o.jsx(HT,{...e,data:{...e.data,onNodeContentResize:u},deleteNode:m,onProvideExpand:y,onProvideValueChange:b,onNodeBodyChange:k,onNodeImagesChange:g,modelLists:r,onModelChange:s}),c?o.jsx("span",{className:"af-flow-node-shell__resize-grip nodrag","aria-label":(($=e.data)==null?void 0:$.resizeLabel)||"Resize node",role:"separator",onPointerDown:p}):null]})}const a7={[Sp]:o7},Jd=["CONTROL","TOOL","PROVIDE","AGENT"],l7=1200,i1="af-flow-node--sync-flash",o1="af-flow-edge--sync-flash";function a1(e,t){const n=String(e||"").trim();return n?n.split(/\s+/).includes(t)?n:`${n} ${t}`:t}function l1(e,t){const n=String(e||"").trim();return n?n.split(/\s+/).filter(r=>r&&r!==t).join(" "):""}function L0(e){const t=((e==null?void 0:e.id)??"").trim();return/^control/i.test(t)?"CONTROL":/^tool/i.test(t)?"TOOL":/^provide/i.test(t)?"PROVIDE":"AGENT"}function c7(e){const t=L0(e);return t==="CONTROL"?"control":t==="PROVIDE"?"provide":t==="TOOL"?"tool":"agent"}function Fh(e){return(Array.isArray(e)?e:[]).map(n=>{const r=String((n==null?void 0:n.name)||(n==null?void 0:n.id)||"").trim(),s=String((n==null?void 0:n.type)||"").trim();return!r&&!s?"":s?`${r||"-"}: ${s}`:r}).filter(Boolean)}function n2(e){return String((e==null?void 0:e.label)||"").trim()||String((e==null?void 0:e.id)||"").trim()}function r2(e){return String((e==null?void 0:e.description)||(e==null?void 0:e.body)||"").replace(/\s+/g," ").trim()}function Ox(e,t){const n=String((e==null?void 0:e.name)||(e==null?void 0:e.id)||"").trim(),r=String((e==null?void 0:e.type)||"").trim();return n||r||`#${t+1}`}function c1(e,t,n){const r=String((t==null?void 0:t.name)||(t==null?void 0:t.id)||`#${n+1}`).trim(),s=String((t==null?void 0:t.type)||"").trim(),i=String((t==null?void 0:t.default)??(t==null?void 0:t.value)??"").trim();return[e,r,s?`type: ${s}`:"",i?`default: ${i}`:""].filter(Boolean).join(" · ")}function u1(e,t){const n=Array.isArray(e)?e:[],r=n.slice(0,4),s=Math.max(0,n.length-r.length);return{list:n,shown:r,hidden:s,kind:t}}function u7(e){return e==="CONTROL"?"account_tree":e==="TOOL"?"build":e==="PROVIDE"?"database":"smart_toy"}function d7(e,t){return t?[e==null?void 0:e.id,e==null?void 0:e.label,e==null?void 0:e.description].filter(Boolean).some(r=>String(r).toLowerCase().includes(t)):!0}function s2(e,t,n,r,s){const i=c7(e),a={id:t,type:Sp,position:n,data:{label:e.label??e.id,definitionId:e.id,schemaType:i,inputs:Array.isArray(e.inputs)?e.inputs.map(l=>({...l})):[],outputs:Array.isArray(e.outputs)?e.outputs.map(l=>({...l})):[]}};return tp(a,r,s)}const i2=320,f7=220,p7=1600,Ob=104,h7=900;function d1(e,t,n){const r=Number(e);return!Number.isFinite(r)||r<=0?0:Math.min(n,Math.max(t,Math.round(r)))}function f1(e){if(!e||typeof e!="object")return null;const t=Number(e.width),n=Number(e.height);return!Number.isFinite(t)||!Number.isFinite(n)||t<=0||n<=0?null:{width:d1(t,f7,p7)||i2,height:d1(n,Ob,h7)||Ob}}function m7(e){const t=(e==null?void 0:e.data)||{},n=r=>(Array.isArray(r)?r:[]).map((s,i)=>(s==null?void 0:s.showOnNode)===!1?"":[i,String((s==null?void 0:s.type)||""),String((s==null?void 0:s.name)||""),s!=null&&s.required?"1":"0"].join(":")).filter(Boolean).join("|");return`${n(t.inputs)}=>${n(t.outputs)}`}function p1(e,t){const n=String((e==null?void 0:e.source)||""),r=String((e==null?void 0:e.target)||"");if(!n||!r)return!1;const s=new Map(t.map(d=>[d.id,d])),i=s.get(n),a=s.get(r),l=zu(i,e.sourceHandle||"output-0","source"),c=zu(a,e.targetHandle||"input-0","target");return!l||!c?!1:Fu(l,c)}function g7(e,t){const n=String((e==null?void 0:e.nodeId)||""),r=String((e==null?void 0:e.handleId)||""),s=(e==null?void 0:e.handleType)==="target"?"target":(e==null?void 0:e.handleType)==="source"?"source":"";if(!n||!r||!s)return null;const i=t.find(l=>l.id===n),a=zu(i,r,s);return a?{nodeId:n,handleId:r,handleType:s,slot:a,slotType:zT(a)}:null}function y7(e,t,n){var a;const r=s2(e,`__candidate_${e.id}`,{x:0,y:0},{},t),s=n.handleType==="source"?"inputs":"outputs",i=Array.isArray((a=r.data)==null?void 0:a[s])?r.data[s]:[];for(let l=0;l<i.length;l+=1){const c=i[l];if(n.handleType==="source"?Fu(n.slot,c):Fu(c,n.slot))return{slot:c,slotIndex:l,hydrated:r}}return null}function x7(e,t){return t?e.map((n,r)=>{const s=y7(n,e,t);if(!s)return null;const i=L0(n);return{def:n,order:r,category:i,categoryRank:Jd.indexOf(i),slot:s.slot,slotIndex:s.slotIndex,displayLabel:n2(s.hydrated.data||n),description:r2(n)}}).filter(Boolean).sort((n,r)=>{var a,l;const s=(a=n.slot)!=null&&a.required?0:1,i=(l=r.slot)!=null&&l.required?0:1;return s-i||n.slotIndex-r.slotIndex||n.categoryRank-r.categoryRank||n.order-r.order}):[]}const w7=/@([a-zA-Z_][a-zA-Z0-9_]*)/g;function b7(e){const t=new Set,n=[];let r;const s=new RegExp(w7.source,"g");for(;(r=s.exec(e))!==null;){const i=r[1];t.has(i)||(t.add(i),n.push(i))}return n}function h1(e,t){const n=e.slice(0,t),r=n.lastIndexOf("@");if(r<0)return null;const s=n.slice(r+1);return/[\s\n]/.test(s)?null:{atIndex:r,query:s}}function Zo(e){const t=String(e||"").indexOf(" - ");return t>=0?e.slice(0,t).trim():String(e||"").trim()}function zh(e,t,n,r){const s=(e||"").trim();if(!s)return"";if(s.startsWith("opencode:")||s.startsWith("claude-code:"))return s;const i=Array.isArray(t)?t:[],a=Array.isArray(n)?n:[],l=Array.isArray(r)?r:[],c=i.map(Zo),d=a.map(Zo);return l.map(Zo).includes(s)&&!c.includes(s)&&!d.includes(s)?`claude-code:${s}`:d.includes(s)&&!c.includes(s)?`opencode:${s}`:s}function v7(e){if(e==null)return"";const t=String(e).trim();return t?t.length<=26?t:`${t.slice(0,12)}…${t.slice(-10)}`:""}function $x(e){if(!Array.isArray(e)||e.length===0)return 0;let t=0;for(const n of e){const r=/^(?:对话|Conversation|Chat)\s*(\d+)\s*$/.exec(String((n==null?void 0:n.label)??"").trim());r&&(t=Math.max(t,parseInt(r[1],10)))}return t}function k7({steps:e}){const{t}=Mn();return!e||e.length===0?null:o.jsx("div",{className:"af-composer-steps-track",role:"list","aria-label":t("flow:composer.stepsAriaLabel"),children:e.map(n=>{const r=String(n.description||n.type||"").trim(),s=n.model||n.executorModel,i=[`${n.index+1}. ${r||"—"}`,n.nodeRole?t("flow:composer.stepRoleLabel",{role:n.nodeRole}):"",n.instanceId?t("flow:composer.stepInstanceLabel",{instanceId:n.instanceId}):"",s?`${t("flow:palette.model")}:${s}`:""].filter(Boolean).join(`
|
|
128
|
+
`}}),o.jsx("textarea",{ref:p,className:"af-body-prompt-textarea "+i,rows:s,value:e,disabled:n,placeholder:r,spellCheck:!1,"aria-invalid":C,"aria-describedby":C?u:void 0,onChange:I=>{t(I.target.value),b(I.target.selectionStart??I.target.value.length)},onSelect:I=>{const z=I.target;z instanceof HTMLTextAreaElement&&b(z.selectionStart??0)},onClick:I=>{const z=I.target;z instanceof HTMLTextAreaElement&&b(z.selectionStart??0)},onKeyUp:I=>{const z=I.target;z instanceof HTMLTextAreaElement&&b(z.selectionStart??z.value.length)},onKeyDown:O,onPaste:I=>{const z=MT(I);z.length!==0&&(I.preventDefault(),R(z).catch(()=>{}))},onDragOver:I=>{fg(I).length>0&&I.preventDefault()},onDrop:I=>{const z=fg(I);z.length!==0&&(I.preventDefault(),R(z).catch(()=>{}))},onScroll:W})]}),M&&F.length>0&&v?Fr.createPortal(o.jsx("ul",{className:"af-body-ph-menu af-body-ph-menu--pop af-composer-mention-menu",role:"listbox","aria-label":f("flow:nodeProps.placeholderSlots"),style:{position:"fixed",top:v.top,left:v.left,right:"auto",bottom:"auto",margin:0,zIndex:2e4},children:F.map((I,z)=>o.jsx("li",{role:"option","aria-selected":z===k,children:o.jsxs("button",{type:"button",className:"af-composer-mention-item"+(z===k?" af-composer-mention-item--active":""),onMouseDown:P=>P.preventDefault(),onMouseEnter:()=>g(z),onClick:()=>$(I.insert),children:[o.jsx("span",{className:"af-composer-mention-id",children:`\${${I.insert}}`}),I.subtitle?o.jsx("span",{className:"af-composer-mention-sub",children:I.subtitle}):null]})},`${I.section}-${I.insert}`))}),document.body):null,C?o.jsx("p",{id:u,className:"af-body-ph-issues",role:"status",children:_.map(I=>I.message).join(" · ")}):null]})}const XT=/^[a-zA-Z_][a-zA-Z0-9_-]*$/;function Dh(e){const t=e.indexOf(" - ");return t>=0?e.slice(0,t).trim():e.trim()}function Gj({kind:e,label:t,slots:n,onSlotsChange:r,disabled:s,requiredReadonly:i=!0}){const{t:a}=Mn(),l=()=>r([...n,{type:"text",name:"",default:"",required:!1,showOnNode:!1}]),c=u=>r(n.filter((p,m)=>m!==u)),d=(u,p,m)=>{const y=n.map((b,k)=>{if(k!==u)return b;const g={...b,[p]:m};return p==="required"&&m===!0&&(g.showOnNode=!0),g});r(y)},f=e==="input"?"input":"output";return o.jsxs("div",{className:"af-node-props-field af-node-props-field--io",children:[o.jsxs("div",{className:"af-node-props-io-head",children:[o.jsx("span",{className:"af-node-props-label",children:t}),o.jsx("button",{type:"button",className:"af-btn-ghost af-node-props-io-add",onClick:l,disabled:s,"aria-label":a("flow:nodeProps.addPinAriaLabel",{label:t}),children:a("flow:nodeProps.addPin")})]}),o.jsx("p",{className:"af-node-props-io-hint",children:a("flow:nodeProps.handleHint",{prefix:f})}),n.length===0?o.jsx("p",{className:"af-node-props-io-empty",children:a(e==="input"?"flow:nodeProps.noInputPins":"flow:nodeProps.noOutputPins")}):null,n.length>0?o.jsxs("div",{className:"af-node-props-io-table",role:"group","aria-label":t,children:[o.jsxs("div",{className:"af-node-props-io-table-head","aria-hidden":!0,children:[o.jsx("span",{children:a("flow:nodeProps.handle")}),o.jsx("span",{children:a("flow:nodeProps.type")}),o.jsx("span",{children:a("flow:nodeProps.name")}),o.jsx("span",{children:a("flow:nodeProps.defaultValue")}),o.jsx("span",{children:a("flow:nodeProps.required")}),o.jsx("span",{children:a("flow:nodeProps.showOnNode")}),o.jsx("span",{})]}),n.map((u,p)=>o.jsxs("div",{className:"af-node-props-io-row",children:[o.jsxs("span",{className:"af-node-props-io-handle",title:`${f}-${p}`,children:[f,"-",p]}),o.jsx("select",{className:"af-node-props-input af-node-props-io-cell",value:u.type,onChange:m=>d(p,"type",m.target.value),disabled:s,"aria-label":a("flow:nodeProps.pinTypeAriaLabel",{label:t,index:p}),children:["node","text","file","bool"].map(m=>o.jsx("option",{value:m,children:m},m))}),o.jsx("input",{type:"text",className:"af-node-props-input af-node-props-io-cell",value:u.name,onChange:m=>d(p,"name",m.target.value),disabled:s,spellCheck:!1,autoComplete:"off","aria-label":a("flow:nodeProps.pinNameAriaLabel",{label:t,index:p})}),o.jsx("input",{type:"text",className:"af-node-props-input af-node-props-io-cell",value:u.default,onChange:m=>d(p,"default",m.target.value),disabled:s,spellCheck:!1,autoComplete:"off","aria-label":a("flow:nodeProps.pinDefaultAriaLabel",{label:t,index:p})}),o.jsx("label",{className:"af-node-props-io-flag",title:a("flow:nodeProps.requiredHint"),children:o.jsx("input",{type:"checkbox",checked:!!u.required,onChange:m=>{i||d(p,"required",m.target.checked)},disabled:s||i,"aria-label":a("flow:nodeProps.pinRequiredAriaLabel",{label:t,index:p})})}),o.jsx("label",{className:"af-node-props-io-flag",title:a("flow:nodeProps.showOnNodeHint"),children:o.jsx("input",{type:"checkbox",checked:u.showOnNode!==!1,onChange:m=>d(p,"showOnNode",m.target.checked),disabled:s,"aria-label":a("flow:nodeProps.pinShowOnNodeAriaLabel",{label:t,index:p})})}),o.jsx("button",{type:"button",className:"af-icon-btn af-node-props-io-remove",onClick:()=>c(p),disabled:s,"aria-label":a("flow:nodeProps.deletePinAriaLabel",{label:t,index:p}),title:a("flow:nodeProps.deletePin"),children:o.jsx("span",{className:"material-symbols-outlined",children:"delete"})})]},`${f}-${p}`))]}):null]})}function JT({draft:e,setDraft:t,definitionId:n,systemPromptReadonly:r,modelLists:s,disabled:i,onIdBlur:a,onClose:l,onPublishToMarketplace:c,allowEditRequiredPins:d=!1,error:f,ioSlots:u}){const{t:p}=Mn(),[m,y]=h.useState(!1),[b,k]=h.useState(!1),[g,v]=h.useState({status:"idle",message:""}),x=h.useCallback($=>{t(W=>W&&{...W,...$})},[t]),{cursorList:N,opencodeList:_,claudeCodeList:C,currentNotInLists:T}=h.useMemo(()=>{const $=Array.isArray(s==null?void 0:s.cursor)?s.cursor:[],W=Array.isArray(s==null?void 0:s.opencode)?s.opencode:[],O=Array.isArray(s==null?void 0:s.claudeCode)?s.claudeCode:[],R=new Set([...$,...W,...O].map(Dh)),I=((e==null?void 0:e.model)??"").trim(),z=I.startsWith("cursor:")?I.slice(7):I.startsWith("opencode:")?I.slice(9):I.startsWith("claude-code:")?I.slice(12):I,P=I&&!R.has(z)?I:"";return{cursorList:$,opencodeList:W,claudeCodeList:O,currentNotInLists:P}},[s,e==null?void 0:e.model]);if(!e)return null;const H=String(e.script??""),M=n==="tool_nodejs"||H.trim()!=="",F=typeof c=="function"&&!i&&(e==null?void 0:e.newId),D=async()=>{if(F){v({status:"running",message:p("flow:nodeProps.publishRunning")});try{const $=await c(e,n);v({status:"success",message:$!=null&&$.definitionId?p("flow:nodeProps.publishSuccessWithId",{id:$.definitionId}):p("flow:nodeProps.publishSuccess")})}catch($){v({status:"error",message:String(($==null?void 0:$.message)||$)})}}};return o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"af-pipeline-drawer-head af-node-props-head",children:[o.jsx("h2",{className:"af-pipeline-drawer-title",children:p("flow:nodeProps.title")}),o.jsxs("div",{className:"af-node-props-head-actions",children:[o.jsxs("button",{type:"button",className:"af-btn-ghost af-node-props-market-btn",onClick:D,disabled:!F||g.status==="running",title:p("flow:nodeProps.publishToMarketplaceHint"),children:[o.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"inventory_2"}),g.status==="running"?p("flow:nodeProps.publishing"):p("flow:nodeProps.publishToMarketplace")]}),o.jsx("button",{type:"button",className:"af-btn-ghost af-node-props-close-secondary",onClick:l,children:p("common:common.close")})]})]}),o.jsxs("div",{className:"af-pipeline-drawer-body af-node-props-body",children:[f?o.jsx("p",{className:"af-err af-node-props-err",children:f}):null,g.message?o.jsx("p",{className:`af-node-props-market-status af-node-props-market-status--${g.status}`,children:g.message}):null,o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsx("span",{className:"af-node-props-label",children:p("flow:node.nodeType")}),o.jsx("div",{className:"af-pipeline-drawer-readonly af-node-props-readonly-mono",children:n})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsxs("span",{className:"af-node-props-label",children:[p("flow:nodeProps.instanceId"),o.jsx("span",{className:"af-node-props-hint",children:p("flow:node.displayNameHint")})]}),o.jsx("input",{type:"text",className:"af-node-props-input",value:e.newId,onChange:$=>x({newId:$.target.value}),onBlur:a,disabled:i,spellCheck:!1,autoComplete:"off","aria-label":p("flow:nodeProps.instanceId")})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsxs("span",{className:"af-node-props-label",children:[p("flow:node.displayName"),"(LABEL)"]}),o.jsx("input",{type:"text",className:"af-node-props-input",value:e.label,onChange:$=>x({label:$.target.value}),disabled:i,spellCheck:!1})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsxs("span",{className:"af-node-props-label",children:[p("flow:node.role"),"(ROLE)"]}),o.jsx("select",{className:"af-node-props-select",value:dl.includes(e.role)?e.role:p("flow:roles.normal"),onChange:$=>x({role:$.target.value}),disabled:i,children:dl.map($=>o.jsx("option",{value:$,children:$},$))})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsxs("span",{className:"af-node-props-label",children:[p("flow:node.model"),"(MODEL)"]}),o.jsx("span",{className:"af-node-props-sublabel",children:p("flow:node.modelHint")}),o.jsxs("select",{className:"af-node-props-select",value:(()=>{const $=(e.model||"").trim();return $?T||$:""})(),onChange:$=>x({model:$.target.value}),disabled:i,"aria-label":p("flow:nodeProps.modelAriaLabel"),children:[o.jsx("option",{value:"",children:p("flow:node.defaultModel")}),T?o.jsxs("option",{value:T,children:[T,p("flow:nodeProps.yamlValueNotInList")]}):null,N.length>0?o.jsx("optgroup",{label:"Cursor",children:N.map($=>o.jsx("option",{value:Dh($),children:$},`c-${$}`))}):null,_.length>0?o.jsx("optgroup",{label:"OpenCode",children:_.map($=>o.jsx("option",{value:Dh($),children:$},`o-${$}`))}):null,C.length>0?o.jsx("optgroup",{label:"Claude Code",children:C.map($=>o.jsx("option",{value:`claude-code:${Dh($)}`,children:$},`cc-${$}`))}):null]})]}),o.jsx(Gj,{kind:"input",label:p("flow:nodeProps.inputPins"),slots:Array.isArray(e.inputs)?e.inputs:[],onSlotsChange:$=>x({inputs:$}),disabled:i,requiredReadonly:!d}),o.jsx(Gj,{kind:"output",label:p("flow:nodeProps.outputPins"),slots:Array.isArray(e.outputs)?e.outputs:[],onSlotsChange:$=>x({outputs:$}),disabled:i,requiredReadonly:!d}),M?o.jsxs("div",{className:"af-pipeline-drawer-field af-node-props-field af-node-props-field--prompt",children:[o.jsxs("div",{className:"af-node-props-prompt-head",children:[o.jsxs("span",{className:"af-node-props-label",children:[p("flow:node.directCommand"),"(script)",o.jsx("span",{className:"af-node-props-hint",children:p("flow:node.scriptHint")})]}),o.jsx("button",{type:"button",className:"af-icon-btn af-node-props-expand",onClick:()=>k(!0),"aria-label":p("flow:nodeProps.expandEditScript"),title:p("flow:nodeProps.expand"),disabled:i,children:o.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),o.jsx($h,{value:H,onChange:$=>x({script:$}),disabled:i,placeholder:p("flow:nodeProps.scriptPlaceholder"),rows:6,textareaClassName:"af-pipeline-drawer-textarea af-node-props-body-textarea af-node-props-script-textarea",ioSlots:u,variant:"drawer"})]}):null,o.jsxs("div",{className:"af-pipeline-drawer-field af-node-props-field af-node-props-field--prompt",children:[o.jsxs("div",{className:"af-node-props-prompt-head",children:[o.jsx("span",{className:"af-node-props-label",children:p("flow:node.userPrompt")}),o.jsx("button",{type:"button",className:"af-icon-btn af-node-props-expand",onClick:()=>y(!0),"aria-label":p("flow:nodeProps.expandEdit"),title:p("flow:nodeProps.expand"),disabled:i,children:o.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),o.jsx($h,{value:e.body,onChange:$=>x({body:$}),images:e.images,onImagesChange:$=>x({images:$}),disabled:i,placeholder:p("flow:nodeProps.bodyPlaceholder"),rows:8,textareaClassName:"af-pipeline-drawer-textarea af-node-props-body-textarea",ioSlots:u,variant:"drawer"})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsx("span",{className:"af-node-props-label",children:p("flow:node.systemDescription")}),o.jsx("textarea",{className:"af-pipeline-drawer-textarea af-node-props-system-readonly",rows:4,readOnly:!0,value:r||p("flow:nodeProps.noDescription"),spellCheck:!1})]})]}),b?o.jsx("div",{className:"af-node-props-expand-overlay",role:"dialog","aria-modal":"true","aria-label":p("flow:nodeProps.editScript"),onMouseDown:$=>{$.target===$.currentTarget&&k(!1)},children:o.jsxs("div",{className:"af-node-props-expand-panel",children:[o.jsxs("div",{className:"af-node-props-expand-head",children:[o.jsx("span",{className:"af-node-props-expand-title",children:p("flow:node.directCommand")}),o.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>k(!1),"aria-label":p("flow:nodeProps.collapse"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsx($h,{value:H,onChange:$=>x({script:$}),disabled:i,placeholder:p("flow:nodeProps.scriptPlaceholderExpand"),rows:16,textareaClassName:"af-node-props-expand-textarea",ioSlots:u,variant:"expand"})]})}):null,m?o.jsx("div",{className:"af-node-props-expand-overlay",role:"dialog","aria-modal":"true","aria-label":p("flow:nodeProps.editUserPrompt"),onMouseDown:$=>{$.target===$.currentTarget&&y(!1)},children:o.jsxs("div",{className:"af-node-props-expand-panel",children:[o.jsxs("div",{className:"af-node-props-expand-head",children:[o.jsx("span",{className:"af-node-props-expand-title",children:p("flow:node.body")}),o.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>y(!1),"aria-label":p("flow:nodeProps.collapse"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsx($h,{value:e.body,onChange:$=>x({body:$}),images:e.images,onImagesChange:$=>x({images:$}),disabled:i,placeholder:p("flow:nodeProps.bodyPlaceholderExpand"),rows:16,textareaClassName:"af-node-props-expand-textarea",ioSlots:u,variant:"expand"})]})}):null]})}function R0(e){var n;if(e.displayKind==="image"||e.encoding==="base64"&&((n=e.mimeType)!=null&&n.startsWith("image/")))return"image";if(e.displayKind==="json"||e.mimeType==="application/json")return"json";if(e.displayKind==="markdown"||e.mimeType==="text/markdown")return"markdown";if(e.displayKind==="text")return"text";const t=(e.content||"").trim();if(t&&(t.startsWith("{")||t.startsWith("[")))try{return JSON.parse(t),"json"}catch{}return"text"}function UK(e){const t=R0(e);if(t==="image"){const n=(e.mimeType||"image/png").split("/")[1];return n?n.toUpperCase():"IMAGE"}return t==="json"?"JSON":t==="markdown"?"MD":null}function QT(e){try{return JSON.stringify(JSON.parse(e.trim()),null,2)}catch{return e}}function Xj({text:e}){const{t}=Mn(),n=e||"";return n.trim()?o.jsx("div",{className:"af-run-ctx-md",children:o.jsx(vp,{children:n})}):o.jsx("div",{className:"af-run-ctx-hint",children:t("flow:runContext.empty")})}function Jj({o:e}){var r;const{t}=Mn(),n=R0(e);if(n==="image"||e.encoding==="base64"&&((r=e.mimeType)!=null&&r.startsWith("image/"))){const i=`data:${e.mimeType||"image/png"};base64,${e.content||""}`;return o.jsxs("div",{className:"af-run-ctx-media",children:[o.jsx("img",{className:"af-run-ctx-img",src:i,alt:e.slot||"output",loading:"lazy"}),e.truncated?o.jsx("div",{className:"af-run-ctx-hint",children:t("flow:runContext.imageTruncated")}):null]})}if(n==="json")return o.jsx("pre",{className:"af-run-ctx-pre",children:QT(e.content||"")});if(n==="markdown"){const s=e.content||"";return s.trim()?o.jsx("div",{className:"af-run-ctx-md",children:o.jsx(vp,{children:s})}):o.jsx("div",{className:"af-run-ctx-hint",children:t("flow:runContext.empty")})}return o.jsx("pre",{className:"af-run-ctx-pre",children:e.content!=null&&e.content!==""?e.content:t("flow:runContext.empty")})}function Qj(e){return UK(e)}function Zj(e){var r;if(!e)return null;const t=R0(e);if(t==="image"||e.encoding==="base64"&&((r=e.mimeType)!=null&&r.startsWith("image/")))return null;const n=e.content;return n==null||n===""?null:t==="json"?QT(String(n)):String(n)}function e1({text:e,title:t,copiedLabel:n}){const[r,s]=h.useState(!1);if(!e)return null;const i=async()=>{try{await navigator.clipboard.writeText(e),s(!0),window.setTimeout(()=>s(!1),1400)}catch{}};return o.jsx("button",{type:"button",className:"af-icon-btn af-run-ctx-copy-btn",onClick:i,title:r?n:t,"aria-label":r?n:t,children:o.jsx("span",{className:"material-symbols-outlined",children:r?"check":"content_copy"})})}const t1=2e4,ZT="af:run-node-ctx-width";function mm(){return typeof window>"u"?416:Math.min(26*16,window.innerWidth-32)}function qa(e){const n=Math.max(280,Math.min(Math.floor(window.innerWidth*.92),1200));return Number.isFinite(e)?Math.min(Math.max(Math.round(e),200),n):qa(mm())}function KK(){try{const e=localStorage.getItem(ZT);if(e==null)return qa(mm());const t=parseInt(e,10);return Number.isFinite(t)?qa(t):qa(mm())}catch{return qa(mm())}}async function n1(e,t,n,r){const s=new URLSearchParams({flowId:e,instanceId:t});n&&String(n).trim()&&s.set("runId",String(n).trim());const i=await fetch(`/api/node-exec-context?${s.toString()}`,{signal:r}),a=await i.text();let l;try{l=JSON.parse(a)}catch{throw new Error(a.startsWith("<!")||a.startsWith("<html")?"apiConnectError":"invalidJson")}if(!i.ok)throw new Error(l.error||"HTTP "+i.status);return l}function qK(e,t){const n=`flow:runContext.${t}`,r=e(n);return r!==n?r:t}function YK({instanceId:e,flowId:t,runId:n,nodeStatus:r,onClose:s}){const{t:i}=Mn(),[a,l]=h.useState(()=>typeof window<"u"&&window.matchMedia("(max-width: 960px)").matches),[c,d]=h.useState(KK),f=h.useRef({active:!1,pointerId:-1,startX:0,startW:416}),[u,p]=h.useState(!0),[m,y]=h.useState(""),[b,k]=h.useState([]),[g,v]=h.useState(null),[x,N]=h.useState(null),_=h.useRef(null),C=h.useRef(null),T=h.useRef(0),H=h.useRef(0);h.useLayoutEffect(()=>{const P=window.matchMedia("(max-width: 960px)"),L=()=>l(P.matches);return P.addEventListener("change",L),()=>P.removeEventListener("change",L)},[]),h.useEffect(()=>{function P(){d(L=>qa(L))}return window.addEventListener("resize",P),()=>window.removeEventListener("resize",P)},[]);const M=h.useCallback(()=>{d(P=>{const L=qa(P);try{localStorage.setItem(ZT,String(L))}catch{}return L})},[]),F=h.useCallback(P=>{if(a||P.button!==0)return;P.preventDefault();const L=P.currentTarget;f.current={active:!0,pointerId:P.pointerId,startX:P.clientX,startW:c},L.setPointerCapture(P.pointerId)},[a,c]),D=h.useCallback(P=>{const L=f.current;if(!L.active||P.pointerId!==L.pointerId)return;const E=L.startX-P.clientX;d(qa(L.startW+E))},[]),$=h.useCallback(P=>{const L=f.current;if(!(!L.active||P.pointerId!==L.pointerId)){L.active=!1;try{P.currentTarget.releasePointerCapture(P.pointerId)}catch{}M()}},[M]),W=h.useCallback(()=>{const P=f.current;P.active&&(P.active=!1,M())},[M]),O=h.useCallback(P=>{const L=Array.isArray(P)?P:[];k(L),v(E=>E&&L.some(X=>X.execId===E)?E:L.length>0?L[L.length-1].execId:null)},[]),R=h.useCallback(()=>{if(!e||!t)return;const P=++T.current,L=new AbortController,E=window.setTimeout(()=>L.abort(),t1);(async()=>{try{const X=await n1(t,e,n,L.signal);if(P!==T.current)return;O(Array.isArray(X.rounds)?X.rounds:[])}catch{}finally{window.clearTimeout(E)}})()},[e,t,n,O]);h.useEffect(()=>{if(!e||!t){p(!1),y(""),k([]);return}const P=++H.current;p(!0),y(""),k([]),v(null);const L=new AbortController,E=window.setTimeout(()=>L.abort(),t1);return(async()=>{try{const X=await n1(t,e,n,L.signal);if(P!==H.current)return;O(Array.isArray(X.rounds)?X.rounds:[])}catch(X){if(P!==H.current)return;const ee=(X==null?void 0:X.name)==="AbortError"?"requestTimeout":X.message||String(X);y(ee)}finally{window.clearTimeout(E),P===H.current&&p(!1)}})(),()=>{L.abort(),H.current++,T.current++}},[e,t,n,O]),h.useEffect(()=>{r&&R()},[r,R]),h.useEffect(()=>{clearInterval(C.current);const P=b.length>0?b[b.length-1]:null;return(r==="running"&&b.length===0||!!(P&&P.status==="running"))&&e&&t&&(C.current=setInterval(()=>R(),2e3)),()=>clearInterval(C.current)},[b,e,t,n,r,R]),h.useEffect(()=>{_.current&&(_.current.scrollTop=0)},[g]);const I=b.find(P=>P.execId===g),z=a?void 0:{width:`${c}px`};return o.jsxs("aside",{className:"af-run-ctx-panel",style:z,"aria-label":i("flow:runContext.title"),children:[a?null:o.jsx("div",{className:"af-run-ctx-resize",role:"separator","aria-orientation":"vertical","aria-label":i("flow:runContext.resizeHandle"),onPointerDown:F,onPointerMove:D,onPointerUp:$,onPointerCancel:$,onLostPointerCapture:W}),o.jsxs("div",{className:"af-run-ctx-panel__main",children:[o.jsxs("div",{className:"af-run-ctx-head",children:[o.jsx("h2",{className:"af-run-ctx-title",title:e,children:e}),o.jsx("button",{type:"button",className:"af-icon-btn",onClick:s,"aria-label":i("common:common.close"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),u&&o.jsx("div",{className:"af-run-ctx-placeholder",children:i("common:common.loading")}),m&&o.jsx("div",{className:"af-run-ctx-error",children:qK(i,m)}),!u&&!m&&b.length===0&&o.jsx("div",{className:"af-run-ctx-placeholder",children:i(r==="running"?"flow:runContext.executingNoArtifacts":"flow:runContext.noData")}),b.length>0&&o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"af-run-ctx-rounds af-run-ctx-rounds--select af-run-ctx-round--"+XK((I==null?void 0:I.status)||""),children:[o.jsx("span",{className:"af-run-ctx-round-dot","aria-hidden":!0}),o.jsx("select",{className:"af-run-ctx-round-select",value:String(g??""),onChange:P=>{const L=P.target.value;v(L==="latest"?"latest":Number(L))},children:[...b].reverse().map(P=>{const L=P.execId==="latest"?i("flow:runContext.latest"):`#${P.execId}`,E=JK(i,P.status),X=P.finishedAt?` · ${GK(P.finishedAt)}`:"";return o.jsx("option",{value:String(P.execId),children:`${L} · ${E}${X}`},P.execId)})})]}),I&&o.jsxs("div",{className:"af-run-ctx-body",ref:_,children:[I.inputs&&I.inputs.length>0&&o.jsxs("section",{className:"af-run-ctx-section",children:[o.jsxs("h3",{className:"af-run-ctx-section-title",children:[o.jsx("span",{className:"material-symbols-outlined af-run-ctx-section-icon","aria-hidden":!0,children:"input"}),"Inputs"]}),I.inputs.map((P,L)=>o.jsxs("div",{className:"af-run-ctx-output-slot",children:[o.jsx("div",{className:"af-run-ctx-slot-head",children:o.jsx("div",{className:"af-run-ctx-slot-name",children:P.slot})}),o.jsx("pre",{className:"af-run-ctx-slot-text",children:P.value})]},`${P.slot}-${L}`))]}),I.prompt!=null&&o.jsxs("section",{className:"af-run-ctx-section",children:[o.jsxs("h3",{className:"af-run-ctx-section-title",children:[o.jsx("span",{className:"material-symbols-outlined af-run-ctx-section-icon","aria-hidden":!0,children:"description"}),"Prompt",o.jsx("button",{type:"button",className:"af-icon-btn af-run-ctx-section-expand",onClick:()=>N("prompt"),title:i("flow:nodeProps.expand"),children:o.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),o.jsx(Xj,{text:I.prompt})]}),I.outputs&&I.outputs.length>0&&o.jsxs("section",{className:"af-run-ctx-section",children:[o.jsxs("h3",{className:"af-run-ctx-section-title",children:[o.jsx("span",{className:"material-symbols-outlined af-run-ctx-section-icon","aria-hidden":!0,children:"output"}),"Outputs",o.jsx("button",{type:"button",className:"af-icon-btn af-run-ctx-section-expand",onClick:()=>N("output"),title:i("flow:nodeProps.expand"),children:o.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),I.outputs.map((P,L)=>{const E=Qj(P),X=Zj(P);return o.jsxs("div",{className:"af-run-ctx-output-slot",children:[o.jsxs("div",{className:"af-run-ctx-slot-head",children:[o.jsx("div",{className:"af-run-ctx-slot-name",children:P.slot}),E?o.jsx("span",{className:"af-run-ctx-format-badge",title:i("flow:runContext.detectedContentType"),children:E}):null,o.jsx(e1,{text:X,title:i("common:common.copy"),copiedLabel:i("common:common.copied")})]}),o.jsx(Jj,{o:P})]},`${P.slot}-${L}`)})]}),!I.prompt&&(!I.outputs||I.outputs.length===0)&&o.jsx("div",{className:"af-run-ctx-placeholder",children:i("flow:runContext.roundNoContent")})]})]})]}),x&&I&&o.jsx("div",{className:"af-node-props-expand-overlay",role:"dialog","aria-modal":"true",onClick:P=>{P.target===P.currentTarget&&N(null)},children:o.jsxs("div",{className:"af-node-props-expand-panel",children:[o.jsxs("div",{className:"af-node-props-expand-head",children:[o.jsx("span",{className:"af-node-props-expand-title",children:x==="prompt"?"Prompt":"Outputs"}),o.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>N(null),"aria-label":i("common:common.close"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsxs("div",{className:"af-node-props-expand-body af-run-ctx-expand-body",children:[x==="prompt"&&I.prompt!=null&&o.jsx(Xj,{text:I.prompt}),x==="output"&&I.outputs&&I.outputs.map((P,L)=>{const E=Qj(P),X=Zj(P);return o.jsxs("div",{className:"af-run-ctx-output-slot",style:{marginBottom:"1rem"},children:[o.jsxs("div",{className:"af-run-ctx-slot-head",children:[o.jsx("div",{className:"af-run-ctx-slot-name",children:P.slot}),E?o.jsx("span",{className:"af-run-ctx-format-badge",children:E}):null,o.jsx(e1,{text:X,title:i("common:common.copy"),copiedLabel:i("common:common.copied")})]}),o.jsx(Jj,{o:P})]},`${P.slot}-${L}`)})]})]})})]})}function GK(e){try{const t=new Date(e);if(isNaN(t.getTime()))return e;const n=r=>String(r).padStart(2,"0");return`${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}`}catch{return e}}function XK(e){const t=String(e||"").toLowerCase();return t==="success"||t==="completed"||t==="done"?"success":t==="failed"||t==="error"?"failed":t==="running"||t==="executing"?"running":t==="cache_not_met"?"cache":t?"unknown":"pending"}function JK(e,t){const n=String(t||"").toLowerCase();return n?n==="success"||n==="completed"||n==="done"?e("flow:runContext.statusSuccess",{defaultValue:"成功"}):n==="failed"||n==="error"?e("flow:runContext.statusFailed",{defaultValue:"失败"}):n==="running"||n==="executing"?e("flow:runContext.statusRunning",{defaultValue:"运行中"}):n==="cache_not_met"?e("flow:runContext.statusCacheMiss",{defaultValue:"缓存失效"}):t:e("flow:runContext.statusPending",{defaultValue:"等待"})}function QK({flowId:e,flowSource:t,flowArchived:n,provideNodes:r,edges:s,nodes:i,onCliInputsChange:a,onBackToEdit:l}){const{t:c}=Mn(),[d,f]=h.useState({}),[u,p]=h.useState(null),[m,y]=h.useState({}),[b,k]=h.useState(!0),[g,v]=h.useState(!1),[x,N]=h.useState(""),[_,C]=h.useState(!1),[T,H]=h.useState(null),M=h.useRef(null),F=h.useRef(!0),D=h.useRef({});h.useMemo(()=>{var E,X,ee;const L={};for(const V of r){const ie=(ee=(X=(E=V.data)==null?void 0:E.outputs)==null?void 0:X[0])==null?void 0:ee.default;ie!=null&&ie!==""&&(L[V.id]=String(ie))}return D.current=L,L},[r]);const $=h.useMemo(()=>{var E;const L={};for(const X of i){if(!((E=X.data)!=null&&E.inputs))continue;const ee=X.data.inputs;for(let V=0;V<ee.length;V++){const ie=ee[V];if(!(ie!=null&&ie.name))continue;const fe=s.find(ge=>ge.target===X.id&&ge.targetHandle===`input-${V}`);if(!(fe!=null&&fe.source))continue;r.find(ge=>ge.id===fe.source)&&(L[fe.source]=ie.name)}}return L},[i,s,r]);h.useEffect(()=>(F.current=!0,()=>{F.current=!1}),[]),h.useEffect(()=>{if(!e){k(!1);return}k(!0);const L=new URLSearchParams({flowId:e,flowSource:t||"user"});n&&L.set("archived","1"),fetch(`/api/flow/run-config?${L.toString()}`).then(E=>{if(!E.ok)throw new Error(`HTTP ${E.status}`);return E.json()}).then(E=>{var ee;if(!F.current)return;f(E.presets||{}),p(E.activePreset||null);const X=E.activePreset&&((ee=E.presets)!=null&&ee[E.activePreset])?E.presets[E.activePreset]:{};y({...D.current,...X}),k(!1)}).catch(()=>{F.current&&(y(D.current),k(!1))})},[e,t,n]),h.useEffect(()=>{var E;if(!a)return;const L={};for(const[X,ee]of Object.entries(m)){const V=$[X];if(!V)continue;const ie=r.find(me=>me.id===X);if(!ie)continue;(((E=ie.data)==null?void 0:E.definitionId)||"").startsWith("provide_file")?L[V]={type:"file",path:ee}:L[V]={type:"str",value:ee}}a(L)},[m,$,r,a]);const W=h.useCallback((L,E)=>{y(X=>({...X,[L]:E}))},[]),O=h.useCallback(L=>{L!==u&&(p(L),L&&d[L]?y({...D.current,...d[L]}):y(D.current))},[u,d]),R=h.useCallback(async()=>{if(x.trim()){v(!0);try{const L={...d,[x.trim()]:m},E={flowId:e,flowSource:t,archived:n,presets:L,activePreset:x.trim()};(await fetch("/api/flow/run-config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(E)})).ok&&(f(L),p(x.trim()),N(""),C(!1))}finally{v(!1)}}},[e,t,n,d,m,x]),I=h.useCallback(async()=>{if(u){v(!0);try{const L={...d};delete L[u];const E=Object.keys(L)[0]||null;(await fetch("/api/flow/run-config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:e,flowSource:t,archived:n,presets:L,activePreset:E})})).ok&&(f(L),p(E),E&&L[E]?y({...D.current,...L[E]}):y(D.current))}finally{v(!1)}}},[e,t,n,d,u]),z=h.useCallback(async()=>{if(u){v(!0);try{const L={...d,[u]:m};(await fetch("/api/flow/run-config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:e,flowSource:t,archived:n,presets:L,activePreset:u})})).ok&&f(L)}finally{v(!1)}}},[e,t,n,d,u,m]),P=Object.keys(d);return P.length>0,b?o.jsx("aside",{className:"af-run-config-panel",children:o.jsx("div",{className:"af-run-config-loading",children:c("common.loading")})}):o.jsxs("aside",{className:"af-run-config-panel",children:[o.jsxs("div",{className:"af-run-config-preset",children:[o.jsx("label",{className:"af-run-config-preset-label",children:c("flow:runConfig.preset")}),o.jsxs("div",{className:"af-run-config-preset-row",children:[o.jsxs("select",{className:"af-run-config-preset-select",value:u||"",onChange:L=>O(L.target.value||null),disabled:g,children:[o.jsx("option",{value:"",children:c("flow:runConfig.default")}),P.map(L=>o.jsx("option",{value:L,children:L},L))]}),o.jsx("button",{type:"button",className:"af-run-config-preset-btn af-run-config-preset-btn--new",onClick:()=>C(!0),disabled:g,title:c("flow:runConfig.newPreset"),children:o.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"add"})}),u&&o.jsx("button",{type:"button",className:"af-run-config-preset-btn af-run-config-preset-btn--save",onClick:z,disabled:g,title:c("flow:runConfig.savePreset"),children:o.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"save"})}),u&&o.jsx("button",{type:"button",className:"af-run-config-preset-btn af-run-config-preset-btn--delete",onClick:I,disabled:g,title:c("flow:runConfig.deletePreset"),children:o.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"delete"})})]})]}),_&&o.jsxs("div",{className:"af-run-config-save-dialog",children:[o.jsx("input",{type:"text",className:"af-run-config-save-input",placeholder:c("flow:runConfig.presetNamePlaceholder"),value:x,onChange:L=>N(L.target.value),disabled:g}),o.jsxs("div",{className:"af-run-config-save-actions",children:[o.jsx("button",{type:"button",className:"af-btn-primary",onClick:R,disabled:g||!x.trim(),children:c(g?"common.saving":"common.save")}),o.jsx("button",{type:"button",className:"af-btn-outline",onClick:()=>{C(!1),N("")},disabled:g,children:c("common.cancel")})]})]}),o.jsxs("div",{className:"af-run-config-inputs",children:[o.jsx("div",{className:"af-run-config-inputs-header",children:c("flow:runConfig.inputParams")}),r.length===0?o.jsx("div",{className:"af-run-config-empty",children:c("flow:runConfig.noProvideNodes")}):o.jsx("div",{className:"af-run-config-input-list",children:r.map(L=>{var ge,Z;const E=((ge=L.data)==null?void 0:ge.definitionId)||"",X=E.startsWith("provide_file"),ee=E==="provide_bool",V=((Z=L.data)==null?void 0:Z.label)||L.id,ie=L.id,fe=m[ie]||"",me=["true","1","yes","on"].includes(String(fe).trim().toLowerCase());return o.jsxs("div",{className:"af-run-config-input-item",children:[o.jsxs("div",{className:"af-run-config-input-head",children:[o.jsx("span",{className:"af-run-config-input-icon material-symbols-outlined"+(X?" af-run-config-input-icon--file":""),"aria-hidden":!0,children:X?"description":ee?"toggle_on":"text_fields"}),o.jsx("span",{className:"af-run-config-input-label",children:V}),ee?null:o.jsx("button",{type:"button",className:"af-run-config-input-expand",onClick:()=>H({instanceId:ie,label:V,content:fe}),"aria-label":c("flow:runConfig.expandInput"),title:c("flow:runConfig.expandInput"),children:o.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),o.jsx("div",{className:"af-run-config-input-id",children:ie}),ee?o.jsx("button",{type:"button",className:"af-run-config-bool-toggle"+(me?" af-run-config-bool-toggle--true":""),onClick:()=>W(ie,me?"false":"true"),"aria-pressed":me,children:me?"true":"false"}):o.jsx("input",{type:"text",className:"af-run-config-input-field",value:fe,onChange:ae=>W(ie,ae.target.value),placeholder:c(X?"flow:runConfig.filePathPlaceholder":"flow:runConfig.stringValuePlaceholder")})]},ie)})})]}),T&&Fr.createPortal(o.jsx("div",{className:"af-provide-edit-overlay",children:o.jsxs("div",{className:"af-provide-edit-modal",role:"dialog","aria-modal":"true",children:[o.jsxs("div",{className:"af-provide-edit-modal__head",children:[o.jsx("span",{className:"material-symbols-outlined",children:"edit_document"}),o.jsx("span",{className:"af-provide-edit-modal__title",children:T.label}),o.jsx("button",{type:"button",className:"af-provide-edit-modal__close",onClick:()=>H(null),"aria-label":c("common:close"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsx("div",{className:"af-provide-edit-modal__body",children:o.jsx("textarea",{ref:M,className:"af-provide-edit-modal__textarea",defaultValue:T.content,autoFocus:!0})}),o.jsxs("div",{className:"af-provide-edit-modal__foot",children:[o.jsxs("button",{type:"button",className:"af-provide-edit-modal__btn af-provide-edit-modal__btn--save",onClick:()=>{!T||!M.current||(W(T.instanceId,M.current.value),H(null))},children:[o.jsx("span",{className:"material-symbols-outlined",children:"save"}),c("flow:provideEdit.save")]}),o.jsxs("button",{type:"button",className:"af-provide-edit-modal__btn",onClick:()=>H(null),children:[o.jsx("span",{className:"material-symbols-outlined",children:"close"}),c("flow:provideEdit.cancel")]})]})]})}),document.body)]})}const e2={ai:["planner-system","planner-user","planner-response","agent-step-prompt","repair-prompt","ai-thinking","ai-assistant","ai-result","ai-tool"],flow:["composer-start","classify","plan","phase-plan","phase-complete","phase-auto-continue","composer-done"],step:["step-start","step-progress","step-done","validation"],output:["natural","status"],error:["error"]},ZK={"planner-system":"#9ecaff","planner-user":"#9ecaff","planner-response":"#7c4dff","agent-step-prompt":"#7c4dff","repair-prompt":"#ff6b6b","ai-thinking":"#a8b9d4","ai-assistant":"#e8deff","ai-result":"#00e475","ai-tool":"#9ecaff","composer-start":"#00e475","composer-done":"#00e475","step-start":"#e8deff","step-done":"#e8deff","step-progress":"#e8deff",natural:"#a8a8a8",status:"#a8a8a8",error:"#ff6b6b","phase-plan":"#00e475","phase-complete":"#00e475"};function e7(e){return!e||e<1024?`${e||0} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(2)} MB`}function t7(e){if(!e)return"";const t=new Date(e);return isNaN(t.getTime())?e:`${t.getHours().toString().padStart(2,"0")}:${t.getMinutes().toString().padStart(2,"0")}:${t.getSeconds().toString().padStart(2,"0")}.${t.getMilliseconds().toString().padStart(3,"0")}`}function n7(e){if(!e)return"";const t=new Date(e);return isNaN(t.getTime())?e:`${t.getMonth()+1}/${t.getDate()} ${t.getHours().toString().padStart(2,"0")}:${t.getMinutes().toString().padStart(2,"0")}`}function r1(e,t){if(e==="natural"&&t&&typeof t=="object"){const n=t.kind;if(n==="thinking"||n==="assistant"||n==="result"||n==="tool")return"ai";if(n==="error")return"error"}for(const[n,r]of Object.entries(e2))if(r.includes(e))return n;return"other"}function r7({event:e,defaultExpanded:t}){const[n,r]=h.useState(!!t),s=ZK[e.tag]||"#a8a8a8",i=e.payload,a=i&&typeof i=="object",l=a?typeof i.text=="string"?i.text:"":String(i||""),c=a?i.meta:null,d=h.useMemo(()=>l?l.slice(0,140).replace(/\s+/g," "):a?Object.keys(i).filter(m=>m!=="text"&&m!=="meta").slice(0,3).map(m=>{const y=i[m];return y==null?`${m}:null`:typeof y=="object"?`${m}:{…}`:`${m}:${String(y).slice(0,30)}`}).join(" "):"",[i,l,a]),f=h.useCallback(u=>{u.stopPropagation();const p=a?JSON.stringify(i,null,2):String(i);try{navigator.clipboard.writeText(p)}catch{}},[i,a]);return o.jsxs("div",{style:{borderLeft:`3px solid ${s}`,background:n?"#1c1b1b":"#131313",marginBottom:4,borderRadius:4,cursor:"pointer",transition:"background 120ms"},onClick:()=>r(u=>!u),children:[o.jsxs("div",{style:{padding:"6px 10px",display:"flex",alignItems:"center",gap:10,fontSize:12},children:[o.jsx("span",{style:{color:"#9a9a9a",fontFamily:"monospace",flexShrink:0},children:t7(e.ts)}),o.jsx("span",{style:{color:s,fontWeight:600,fontFamily:"monospace",flexShrink:0,padding:"1px 6px",background:"rgba(255,255,255,0.04)",borderRadius:3},children:e.tag}),o.jsx("span",{style:{color:"#c5c2c1",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"monospace"},children:d}),n&&o.jsx("button",{type:"button",onClick:f,style:{background:"rgba(124,77,255,0.15)",color:"#e8deff",border:"none",borderRadius:3,padding:"2px 8px",fontSize:11,cursor:"pointer"},children:"Copy"})]}),n&&o.jsxs("div",{style:{padding:"0 10px 10px 10px",borderTop:"1px solid rgba(255,255,255,0.04)"},children:[c&&Object.keys(c).length>0&&o.jsx("div",{style:{marginTop:8,padding:8,background:"#0e0e0e",borderRadius:4,fontSize:11,fontFamily:"monospace",color:"#9ecaff",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:JSON.stringify(c,null,2)}),l?o.jsx("pre",{style:{marginTop:8,padding:10,background:"#0e0e0e",borderRadius:4,fontSize:12,color:"#e5e2e1",whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:600,overflowY:"auto",margin:"8px 0 0 0",fontFamily:"ui-monospace, SF Mono, Menlo, monospace"},children:l}):a?o.jsx("pre",{style:{marginTop:8,padding:10,background:"#0e0e0e",borderRadius:4,fontSize:12,color:"#e5e2e1",whiteSpace:"pre-wrap",wordBreak:"break-all",maxHeight:400,overflowY:"auto",margin:"8px 0 0 0",fontFamily:"ui-monospace, SF Mono, Menlo, monospace"},children:JSON.stringify(i,null,2)}):null]})]})}function s7({open:e,onClose:t,flowId:n}){var H;const[r,s]=h.useState([]),[i,a]=h.useState(!1),[l,c]=h.useState(null),[d,f]=h.useState(null),[u,p]=h.useState(!1),[m,y]=h.useState(!0),[b,k]=h.useState({ai:!0,flow:!0,step:!0,output:!0,error:!0}),[g,v]=h.useState(""),x=h.useRef(null),N=h.useCallback(async()=>{a(!0);try{const M=m&&n?`?flowId=${encodeURIComponent(n)}`:"",D=await(await fetch(`/api/composer-logs${M}`)).json();s(Array.isArray(D.sessions)?D.sessions:[])}catch{s([])}finally{a(!1)}},[n,m]),_=h.useCallback(async M=>{if(!M){f(null);return}p(!0);try{const D=await(await fetch(`/api/composer-logs/${encodeURIComponent(M)}`)).json();f(D)}catch{f(null)}finally{p(!1)}},[]);h.useEffect(()=>{e&&N()},[e,N]),h.useEffect(()=>{if(!(!e||!l))return _(l),x.current=setInterval(()=>_(l),2e3),()=>{x.current&&clearInterval(x.current),x.current=null}},[e,l,_]);const C=h.useMemo(()=>{const M=(d==null?void 0:d.events)||[],F=g.trim().toLowerCase();return M.filter(D=>{const $=r1(D.tag,D.payload);return!b[$]&&$!=="other"?!1:F?[D.tag,JSON.stringify(D.payload||"")].join(" ").toLowerCase().includes(F):!0})},[d,b,g]),T=h.useMemo(()=>{const M=(d==null?void 0:d.events)||[],F={};for(const D of M){const $=r1(D.tag,D.payload);F[$]=(F[$]||0)+1}return F},[d]);return e?o.jsxs("div",{style:{position:"fixed",top:0,right:0,bottom:0,width:"min(1100px, 80vw)",background:"#131313",borderLeft:"1px solid rgba(255,255,255,0.08)",display:"flex",flexDirection:"column",zIndex:9999,boxShadow:"-8px 0 32px rgba(0,0,0,0.5)",color:"#e5e2e1",fontFamily:"Inter, system-ui, sans-serif"},children:[o.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",gap:12,flexShrink:0,background:"#1c1b1b"},children:[o.jsx("span",{style:{fontWeight:600,fontSize:14},children:"Composer Logs"}),o.jsx("span",{style:{fontSize:11,color:"#9a9a9a"},children:n?`flowId: ${n}`:"no flow selected"}),o.jsxs("label",{style:{fontSize:11,color:"#9a9a9a",display:"flex",alignItems:"center",gap:4,cursor:"pointer"},children:[o.jsx("input",{type:"checkbox",checked:m,onChange:M=>y(M.target.checked),disabled:!n}),"仅显示当前 flow"]}),o.jsx("button",{type:"button",onClick:N,style:{background:"rgba(124,77,255,0.15)",color:"#e8deff",border:"none",borderRadius:4,padding:"4px 10px",fontSize:12,cursor:"pointer"},children:"Refresh"}),o.jsx("span",{style:{flex:1}}),o.jsx("button",{type:"button",onClick:t,style:{background:"transparent",color:"#e5e2e1",border:"1px solid rgba(255,255,255,0.12)",borderRadius:4,padding:"4px 12px",fontSize:12,cursor:"pointer"},children:"Close"})]}),o.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden",minHeight:0},children:[o.jsxs("div",{style:{width:280,borderRight:"1px solid rgba(255,255,255,0.06)",overflowY:"auto",background:"#0e0e0e",flexShrink:0},children:[i&&o.jsx("div",{style:{padding:12,fontSize:12,color:"#9a9a9a"},children:"Loading…"}),!i&&r.length===0&&o.jsx("div",{style:{padding:12,fontSize:12,color:"#9a9a9a"},children:m&&n?"no sessions for this flow":"no sessions"}),r.map(M=>{const F=l===M.sessionId;return o.jsxs("div",{onClick:()=>c(M.sessionId),style:{padding:"10px 12px",borderBottom:"1px solid rgba(255,255,255,0.04)",cursor:"pointer",background:F?"rgba(124,77,255,0.18)":"transparent",borderLeft:F?"3px solid #7c4dff":"3px solid transparent"},children:[o.jsx("div",{style:{fontSize:12,fontWeight:600,color:"#e5e2e1"},children:n7(M.mtime)}),o.jsx("div",{style:{fontSize:11,color:"#9ecaff",marginTop:2,fontFamily:"monospace"},children:M.flowId||"(no flow)"}),M.promptPreview&&o.jsx("div",{style:{fontSize:11,color:"#9a9a9a",marginTop:4,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:M.promptPreview}),o.jsxs("div",{style:{fontSize:10,color:"#6a6a6a",marginTop:4},children:[e7(M.size)," · ",M.model||"default"]})]},M.sessionId)})]}),o.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minHeight:0},children:[o.jsxs("div",{style:{padding:"10px 16px",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",gap:8,flexWrap:"wrap",flexShrink:0,background:"#1c1b1b"},children:[Object.keys(e2).map(M=>o.jsxs("button",{type:"button",onClick:()=>k(F=>({...F,[M]:!F[M]})),style:{background:b[M]?"rgba(124,77,255,0.25)":"transparent",color:b[M]?"#e8deff":"#6a6a6a",border:`1px solid ${b[M]?"rgba(124,77,255,0.4)":"rgba(255,255,255,0.08)"}`,borderRadius:999,padding:"3px 12px",fontSize:11,cursor:"pointer",fontFamily:"monospace",textTransform:"uppercase"},children:[M," ",T[M]!=null?`(${T[M]})`:""]},M)),o.jsx("input",{type:"text",placeholder:"search…",value:g,onChange:M=>v(M.target.value),style:{marginLeft:8,flex:1,minWidth:120,background:"#0e0e0e",border:"1px solid rgba(255,255,255,0.08)",borderRadius:4,color:"#e5e2e1",padding:"4px 8px",fontSize:12}})]}),o.jsxs("div",{style:{flex:1,overflowY:"auto",padding:12,minHeight:0},children:[!l&&o.jsx("div",{style:{color:"#9a9a9a",fontSize:12,padding:20,textAlign:"center"},children:"Select a session on the left to view events"}),u&&!d&&o.jsx("div",{style:{color:"#9a9a9a",fontSize:12,padding:20},children:"Loading…"}),d&&C.length===0&&o.jsxs("div",{style:{color:"#9a9a9a",fontSize:12,padding:20},children:["No events match current filter (",((H=d.events)==null?void 0:H.length)||0," total)"]}),C.map((M,F)=>o.jsx(r7,{event:M,defaultExpanded:M.tag==="error"},`${M.ts}_${F}`))]})]})]})]}):null}const i7="0.1.67";function s1(e){const t=Math.max(0,Number(e)||0),n=Math.floor(t/36e5),r=Math.floor(t%36e5/6e4),s=Math.floor(t%6e4/1e3);return`${String(n).padStart(2,"0")}:${String(r).padStart(2,"0")}:${String(s).padStart(2,"0")}`}function Mx(e,t){return t==="running"?s1(e):e==null||!Number.isFinite(e)||e<=0?"--":s1(e)}const t2=h.createContext({modelLists:{cursor:[],opencode:[]},onModelChange:()=>{}});function o7(e){var v,x,N,_,C,T,H,M,F,D,$;const{setNodes:t}=wc(),n=u0(),{modelLists:r,onModelChange:s}=h.useContext(t2),i=h.useRef(null),a=!!((v=e.data)!=null&&v.readOnly),l=(x=e.data)!=null&&x.displaySize&&Number(e.data.displaySize.width)>0&&Number(e.data.displaySize.height)>0?{width:Number(e.data.displaySize.width),height:Number(e.data.displaySize.height)}:null,c=((N=e.data)==null?void 0:N.definitionId)==="agent_subAgent"&&!((_=e.data)!=null&&_.isRunMode)&&!a,d=h.useCallback(W=>{const O=()=>n(W);window.requestAnimationFrame(O),window.setTimeout(O,80)},[n]),f=h.useCallback((W,O)=>{const R=f1(O);R&&(t(I=>I.map(z=>{var E,X,ee,V,ie,fe;if(z.id!==W)return z;const P=Number(((X=(E=z.data)==null?void 0:E.displaySize)==null?void 0:X.width)||z.width||((ee=z.measured)==null?void 0:ee.width)||0),L=Number(((ie=(V=z.data)==null?void 0:V.displaySize)==null?void 0:ie.height)||z.height||((fe=z.measured)==null?void 0:fe.height)||0);return Math.abs(P-R.width)<2&&Math.abs(L-R.height)<2?z:{...z,width:R.width,height:R.height,data:{...z.data,displaySize:R}}})),d(W))},[d,t]),u=h.useCallback(W=>{if(a)return;const O=i.current;if(!O)return;const R=O.getBoundingClientRect();f(W,{width:Math.max(R.width,O.scrollWidth),height:Math.max(R.height,O.scrollHeight)})},[f,a]),p=h.useCallback(W=>{var ie,fe,me,ge,Z,ae;if(!c)return;W.preventDefault(),W.stopPropagation();const O=i.current,R=O==null?void 0:O.getBoundingClientRect(),I=Number(((fe=(ie=e.data)==null?void 0:ie.displaySize)==null?void 0:fe.width)||e.width||((me=e.measured)==null?void 0:me.width)||(R==null?void 0:R.width)||i2),z=Number(((Z=(ge=e.data)==null?void 0:ge.displaySize)==null?void 0:Z.height)||e.height||((ae=e.measured)==null?void 0:ae.height)||(R==null?void 0:R.height)||Ob),P=W.clientX,L=W.clientY,E=e.id;let X=0;const ee=xe=>{const pe=f1({width:I+xe.clientX-P,height:z+xe.clientY-L});pe&&(window.cancelAnimationFrame(X),X=window.requestAnimationFrame(()=>f(E,pe)))},V=()=>{window.cancelAnimationFrame(X),window.removeEventListener("pointermove",ee),window.removeEventListener("pointerup",V),window.removeEventListener("pointercancel",V),d(E)};window.addEventListener("pointermove",ee),window.addEventListener("pointerup",V,{once:!0}),window.addEventListener("pointercancel",V,{once:!0})},[f,(T=(C=e.data)==null?void 0:C.displaySize)==null?void 0:T.height,(M=(H=e.data)==null?void 0:H.displaySize)==null?void 0:M.width,e.height,e.id,(F=e.measured)==null?void 0:F.height,(D=e.measured)==null?void 0:D.width,e.width,d,c]),m=h.useCallback(W=>{t(O=>O.filter(R=>R.id!==W))},[t]),y=h.useCallback(()=>{var I,z,P,L,E,X,ee,V;const W=((I=e.data)==null?void 0:I.definitionId)||"",O=((z=e.data)==null?void 0:z.label)||e.id,R=((E=(L=(P=e.data)==null?void 0:P.outputs)==null?void 0:L[0])==null?void 0:E.value)||((V=(ee=(X=e.data)==null?void 0:X.outputs)==null?void 0:ee[0])==null?void 0:V.default)||"";window.__provideEditContent={instanceId:e.id,label:O,definitionId:W,content:R},window.dispatchEvent(new CustomEvent("provide-expand"))},[e.id,e.data]),b=h.useCallback((W,O)=>{t(R=>R.map(I=>{var P;if(I.id!==W)return I;const z=Array.isArray((P=I.data)==null?void 0:P.outputs)&&I.data.outputs.length?I.data.outputs.map((L,E)=>E===0?{...L,default:O,value:O}:L):[{type:"bool",name:"value",default:O,value:O}];return{...I,data:{...I.data,body:"",outputs:z}}}))},[t]),k=h.useCallback((W,O)=>{t(R=>R.map(I=>I.id===W?{...I,data:{...I.data,body:O}}:I))},[t]),g=h.useCallback((W,O)=>{t(R=>R.map(I=>I.id===W?{...I,data:{...I.data,images:Ts(O)}}:I))},[t]);return o.jsxs("div",{ref:i,className:"af-flow-node-shell"+(c?" af-flow-node-shell--resizable":""),style:l?{width:l.width,height:l.height}:void 0,children:[o.jsx(HT,{...e,data:{...e.data,onNodeContentResize:u},deleteNode:m,onProvideExpand:y,onProvideValueChange:b,onNodeBodyChange:k,onNodeImagesChange:g,modelLists:r,onModelChange:s}),c?o.jsx("span",{className:"af-flow-node-shell__resize-grip nodrag","aria-label":(($=e.data)==null?void 0:$.resizeLabel)||"Resize node",role:"separator",onPointerDown:p}):null]})}const a7={[Sp]:o7},Jd=["CONTROL","TOOL","PROVIDE","AGENT"],l7=1200,i1="af-flow-node--sync-flash",o1="af-flow-edge--sync-flash";function a1(e,t){const n=String(e||"").trim();return n?n.split(/\s+/).includes(t)?n:`${n} ${t}`:t}function l1(e,t){const n=String(e||"").trim();return n?n.split(/\s+/).filter(r=>r&&r!==t).join(" "):""}function L0(e){const t=((e==null?void 0:e.id)??"").trim();return/^control/i.test(t)?"CONTROL":/^tool/i.test(t)?"TOOL":/^provide/i.test(t)?"PROVIDE":"AGENT"}function c7(e){const t=L0(e);return t==="CONTROL"?"control":t==="PROVIDE"?"provide":t==="TOOL"?"tool":"agent"}function Fh(e){return(Array.isArray(e)?e:[]).map(n=>{const r=String((n==null?void 0:n.name)||(n==null?void 0:n.id)||"").trim(),s=String((n==null?void 0:n.type)||"").trim();return!r&&!s?"":s?`${r||"-"}: ${s}`:r}).filter(Boolean)}function n2(e){return String((e==null?void 0:e.label)||"").trim()||String((e==null?void 0:e.id)||"").trim()}function r2(e){return String((e==null?void 0:e.description)||(e==null?void 0:e.body)||"").replace(/\s+/g," ").trim()}function Ox(e,t){const n=String((e==null?void 0:e.name)||(e==null?void 0:e.id)||"").trim(),r=String((e==null?void 0:e.type)||"").trim();return n||r||`#${t+1}`}function c1(e,t,n){const r=String((t==null?void 0:t.name)||(t==null?void 0:t.id)||`#${n+1}`).trim(),s=String((t==null?void 0:t.type)||"").trim(),i=String((t==null?void 0:t.default)??(t==null?void 0:t.value)??"").trim();return[e,r,s?`type: ${s}`:"",i?`default: ${i}`:""].filter(Boolean).join(" · ")}function u1(e,t){const n=Array.isArray(e)?e:[],r=n.slice(0,4),s=Math.max(0,n.length-r.length);return{list:n,shown:r,hidden:s,kind:t}}function u7(e){return e==="CONTROL"?"account_tree":e==="TOOL"?"build":e==="PROVIDE"?"database":"smart_toy"}function d7(e,t){return t?[e==null?void 0:e.id,e==null?void 0:e.label,e==null?void 0:e.description].filter(Boolean).some(r=>String(r).toLowerCase().includes(t)):!0}function s2(e,t,n,r,s){const i=c7(e),a={id:t,type:Sp,position:n,data:{label:e.label??e.id,definitionId:e.id,schemaType:i,inputs:Array.isArray(e.inputs)?e.inputs.map(l=>({...l})):[],outputs:Array.isArray(e.outputs)?e.outputs.map(l=>({...l})):[]}};return tp(a,r,s)}const i2=320,f7=220,p7=1600,Ob=104,h7=900;function d1(e,t,n){const r=Number(e);return!Number.isFinite(r)||r<=0?0:Math.min(n,Math.max(t,Math.round(r)))}function f1(e){if(!e||typeof e!="object")return null;const t=Number(e.width),n=Number(e.height);return!Number.isFinite(t)||!Number.isFinite(n)||t<=0||n<=0?null:{width:d1(t,f7,p7)||i2,height:d1(n,Ob,h7)||Ob}}function m7(e){const t=(e==null?void 0:e.data)||{},n=r=>(Array.isArray(r)?r:[]).map((s,i)=>(s==null?void 0:s.showOnNode)===!1?"":[i,String((s==null?void 0:s.type)||""),String((s==null?void 0:s.name)||""),s!=null&&s.required?"1":"0"].join(":")).filter(Boolean).join("|");return`${n(t.inputs)}=>${n(t.outputs)}`}function p1(e,t){const n=String((e==null?void 0:e.source)||""),r=String((e==null?void 0:e.target)||"");if(!n||!r)return!1;const s=new Map(t.map(d=>[d.id,d])),i=s.get(n),a=s.get(r),l=zu(i,e.sourceHandle||"output-0","source"),c=zu(a,e.targetHandle||"input-0","target");return!l||!c?!1:Fu(l,c)}function g7(e,t){const n=String((e==null?void 0:e.nodeId)||""),r=String((e==null?void 0:e.handleId)||""),s=(e==null?void 0:e.handleType)==="target"?"target":(e==null?void 0:e.handleType)==="source"?"source":"";if(!n||!r||!s)return null;const i=t.find(l=>l.id===n),a=zu(i,r,s);return a?{nodeId:n,handleId:r,handleType:s,slot:a,slotType:zT(a)}:null}function y7(e,t,n){var a;const r=s2(e,`__candidate_${e.id}`,{x:0,y:0},{},t),s=n.handleType==="source"?"inputs":"outputs",i=Array.isArray((a=r.data)==null?void 0:a[s])?r.data[s]:[];for(let l=0;l<i.length;l+=1){const c=i[l];if(n.handleType==="source"?Fu(n.slot,c):Fu(c,n.slot))return{slot:c,slotIndex:l,hydrated:r}}return null}function x7(e,t){return t?e.map((n,r)=>{const s=y7(n,e,t);if(!s)return null;const i=L0(n);return{def:n,order:r,category:i,categoryRank:Jd.indexOf(i),slot:s.slot,slotIndex:s.slotIndex,displayLabel:n2(s.hydrated.data||n),description:r2(n)}}).filter(Boolean).sort((n,r)=>{var a,l;const s=(a=n.slot)!=null&&a.required?0:1,i=(l=r.slot)!=null&&l.required?0:1;return s-i||n.slotIndex-r.slotIndex||n.categoryRank-r.categoryRank||n.order-r.order}):[]}const w7=/@([a-zA-Z_][a-zA-Z0-9_]*)/g;function b7(e){const t=new Set,n=[];let r;const s=new RegExp(w7.source,"g");for(;(r=s.exec(e))!==null;){const i=r[1];t.has(i)||(t.add(i),n.push(i))}return n}function h1(e,t){const n=e.slice(0,t),r=n.lastIndexOf("@");if(r<0)return null;const s=n.slice(r+1);return/[\s\n]/.test(s)?null:{atIndex:r,query:s}}function Zo(e){const t=String(e||"").indexOf(" - ");return t>=0?e.slice(0,t).trim():String(e||"").trim()}function zh(e,t,n,r){const s=(e||"").trim();if(!s)return"";if(s.startsWith("opencode:")||s.startsWith("claude-code:"))return s;const i=Array.isArray(t)?t:[],a=Array.isArray(n)?n:[],l=Array.isArray(r)?r:[],c=i.map(Zo),d=a.map(Zo);return l.map(Zo).includes(s)&&!c.includes(s)&&!d.includes(s)?`claude-code:${s}`:d.includes(s)&&!c.includes(s)?`opencode:${s}`:s}function v7(e){if(e==null)return"";const t=String(e).trim();return t?t.length<=26?t:`${t.slice(0,12)}…${t.slice(-10)}`:""}function $x(e){if(!Array.isArray(e)||e.length===0)return 0;let t=0;for(const n of e){const r=/^(?:对话|Conversation|Chat)\s*(\d+)\s*$/.exec(String((n==null?void 0:n.label)??"").trim());r&&(t=Math.max(t,parseInt(r[1],10)))}return t}function k7({steps:e}){const{t}=Mn();return!e||e.length===0?null:o.jsx("div",{className:"af-composer-steps-track",role:"list","aria-label":t("flow:composer.stepsAriaLabel"),children:e.map(n=>{const r=String(n.description||n.type||"").trim(),s=n.model||n.executorModel,i=[`${n.index+1}. ${r||"—"}`,n.nodeRole?t("flow:composer.stepRoleLabel",{role:n.nodeRole}):"",n.instanceId?t("flow:composer.stepInstanceLabel",{instanceId:n.instanceId}):"",s?`${t("flow:palette.model")}:${s}`:""].filter(Boolean).join(`
|
|
129
129
|
`),a=n.status||"pending";return o.jsxs("div",{className:"af-composer-step-chip"+(a==="done"?" af-composer-step-chip--done":"")+(a==="running"?" af-composer-step-chip--running":"")+(a==="error"?" af-composer-step-chip--error":"")+(a==="pending"?" af-composer-step-chip--pending":""),role:"listitem",title:i,children:[o.jsx("span",{className:"af-composer-step-chip-idx",children:n.index+1}),o.jsx("span",{className:"af-composer-step-chip-main",children:n.nodeRole||s?o.jsxs("span",{className:"af-composer-step-chip-meta",children:[n.nodeRole?o.jsx("span",{className:"af-composer-step-chip-role",children:n.nodeRole}):null,s?o.jsx("span",{className:"af-composer-step-chip-model",children:v7(s)}):null]}):null})]},n.index)})})}function S7(e,t){const n=e.trim(),r=t.trim();return r?n?!!(n===r||n.endsWith(r)||r.length>=8&&n.includes(r)):!1:!0}function N7(e){const t=[];for(const n of e){if(!n||typeof n.text!="string"||!n.text.trim())continue;const s=typeof n.kind=="string"&&n.kind?n.kind:"assistant",i=t[t.length-1];i&&i.kind===s?i.text+=s==="error"||s==="result"?`
|
|
130
130
|
${n.text}`:n.text:t.push({kind:s,text:n.text})}return t}function j7(e,t){return e==="thinking"?t("flow:composer.thinking"):e==="result"?t("flow:composer.result"):e==="assistant"?t("flow:composer.reply"):e==="error"?t("flow:composer.error"):String(e)}function C7(e){return e==="thinking"?"af-composer-ai-block af-composer-ai-block--thinking":e==="result"?"af-composer-ai-block af-composer-ai-block--result":e==="assistant"?"af-composer-ai-block af-composer-ai-block--reply":e==="error"?"af-composer-ai-block af-composer-ai-block--error":"af-composer-ai-block af-composer-ai-block--reply"}function m1({thread:e,liveSegments:t,running:n,className:r="",autoScroll:s=!0}){const{t:i}=Mn(),a=h.useRef(null),l=["af-composer-ai-stack","af-composer-ai-stack--in-panel","af-composer-thread-stack",r].filter(Boolean).join(" ");return h.useEffect(()=>{if(!s||!a.current)return;const c=a.current;requestAnimationFrame(()=>{c.scrollTop=c.scrollHeight})},[e,t,s]),o.jsxs("div",{ref:a,className:l,children:[e.map((c,d)=>c.type==="user"?o.jsxs("section",{className:"af-composer-ai-block af-composer-ai-block--user-msg",children:[o.jsx("div",{className:"af-composer-ai-block-label",children:i("flow:composer.yourQuestion")}),o.jsx("div",{className:"af-composer-ai-block-body",children:c.text})]},`composer-u-${d}-${c.text.slice(0,48)}`):o.jsx("div",{className:"af-composer-thread-assistant",children:o.jsx(g1,{segments:c.segments,running:!1})},`composer-a-${d}`)),o.jsx("div",{className:"af-composer-thread-assistant",children:o.jsx(g1,{segments:t,running:n})})]})}function g1({segments:e,running:t=!1}){const{t:n}=Mn(),r=e.filter(u=>u.kind==="assistant").map(u=>u.text).join(""),s=e.filter(u=>u.kind==="result").map(u=>u.text).join(""),i=S7(r,s),a=e.filter(u=>u.kind==="error").map(u=>u.text).join(`
|
|
131
131
|
`),l=e.filter(u=>u.kind!=="error"),c=i?l.filter(u=>u.kind!=="result"):l,d=N7(c),f=!!(d.length>0||a);return o.jsxs(o.Fragment,{children:[d.map((u,p)=>o.jsxs("section",{className:C7(u.kind),children:[o.jsx("div",{className:"af-composer-ai-block-label",children:j7(u.kind,n)}),o.jsx("div",{className:"af-composer-ai-block-body",children:u.text})]},`${u.kind}-${p}`)),t&&!f?o.jsxs("section",{className:"af-composer-ai-block af-composer-ai-block--reply af-composer-ai-block--pending",children:[o.jsx("div",{className:"af-composer-ai-block-label",children:n("flow:composer.reply")}),o.jsx("div",{className:"af-composer-ai-block-body",children:n("flow:composer.waiting")})]}):null,a?o.jsxs("section",{className:"af-composer-ai-block af-composer-ai-block--error",children:[o.jsx("div",{className:"af-composer-ai-block-label",children:n("flow:composer.error")}),o.jsx("div",{className:"af-composer-ai-block-body",children:a})]}):null]})}function E7({fitViewEpoch:e}){const{fitView:t}=wc(),n=h.useRef(t);return n.current=t,h.useEffect(()=>{if(e>0){const r=requestAnimationFrame(()=>n.current({padding:.2,duration:200,maxZoom:1}));return()=>cancelAnimationFrame(r)}},[e]),null}function _7({onReady:e}){const t=u0();return h.useEffect(()=>(e(t),()=>e(null)),[e,t]),null}function y1(e){const t=Number.isFinite(e)?e:1;return Math.min(Math.max(t,.75),1)}function x1(e){if(!e||typeof e!="object")return null;const t=Number(e.x),n=Number(e.y),r=Number(e.zoom);return!Number.isFinite(t)||!Number.isFinite(n)||!Number.isFinite(r)?null:{x:t,y:n,zoom:Math.min(Math.max(r,.1),4)}}const gm=1500,w1=500,P7=262144,A7=2e3;function Dx(e){return typeof e!="string"?"":e.length<=A7?e:`[log line truncated, ${e.length} chars]`}const I7=gm;function T7(e){const t=e.match(/^\[([^\]]+)\]\s+\[([^\]]+)\]\s+([\s\S]*)$/);if(!t)return null;const[,n,r,s]=t;if(r==="cli")try{const i=JSON.parse(s);return i&&i.event==="node-start"?{ts:n,type:"node-start",text:`节点 ${i.instanceId||""}${i.label?` · ${i.label}`:""} 开始`}:i&&i.event==="node-done"?{ts:n,type:"node-done",text:`节点 ${i.instanceId||""} 完成${i.elapsed?` (${i.elapsed})`:""}`}:i&&i.event==="node-failed"?{ts:n,type:"node-failed",text:`节点 ${i.instanceId||""} 失败${i.error?`: ${i.error}`:""}`}:i&&i.event==="apply-start"?{ts:n,type:"info",text:`[apply-start] uuid=${i.uuid||""}`}:{ts:n,type:"info",text:Dx(s)}}catch{return{ts:n,type:"info",text:Dx(s)}}return{ts:n,type:"log",text:Dx(`[${r}] ${s}`)}}function b1(e){if(!e)return[];const t=[],n=e.split(`
|
|
@@ -142,7 +142,7 @@ ${n.text}`:n.text:t.push({kind:s,text:n.text})}return t}function j7(e,t){return
|
|
|
142
142
|
`);for(let l=0;l<a.length;l+=1){const c=a[l],d=a[l+1];if(i){c==='"'&&d==='"'?(s+='"',l+=1):c==='"'?i=!1:s+=c;continue}c==='"'?i=!0:c===t?(r.push(s.trim()),s=""):c===`
|
|
143
143
|
`?(r.push(s.trim()),n.push(r),r=[],s=""):s+=c}return(s||r.length)&&(r.push(s.trim()),n.push(r)),n.filter(l=>l.some(c=>String(c||"").trim()))}function mo(e){if(e==null)return"";if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return String(e);try{return JSON.stringify(e)}catch{return String(e)}}function cq(e){if(Array.isArray(e)){if(e.every(s=>s&&typeof s=="object"&&!Array.isArray(s))){const s=Array.from(new Set(e.flatMap(i=>Object.keys(i))));return{columns:s.map(i=>({key:i,label:i,align:"left"})),rows:e.map(i=>s.map(a=>mo(i[a])))}}if(e.every(Array.isArray)&&e.length>0){const s=e[0].map((i,a)=>mo(i)||`Column ${a+1}`);return{columns:s.map((i,a)=>({key:String(a),label:i,align:"left"})),rows:e.slice(1).map(i=>s.map((a,l)=>mo(i[l])))}}}if(!e||typeof e!="object")return null;const t=Array.isArray(e.columns)?e.columns:Array.isArray(e.headers)?e.headers:[],n=Array.isArray(e.rows)?e.rows:Array.isArray(e.data)?e.data:[];let r=t.map((s,i)=>s&&typeof s=="object"?{key:String(s.key||s.name||s.field||i),label:String(s.label||s.title||s.name||s.key||`Column ${i+1}`),align:["left","center","right"].includes(s.align)?s.align:"left"}:{key:String(i),label:mo(s)||`Column ${i+1}`,align:"left"});return r.length===0&&n.every(s=>s&&typeof s=="object"&&!Array.isArray(s))&&(r=Array.from(new Set(n.flatMap(s=>Object.keys(s)))).map(s=>({key:s,label:s,align:"left"}))),r.length===0&&n.every(Array.isArray)&&n.length>0?(r=n[0].map((s,i)=>({key:String(i),label:mo(s)||`Column ${i+1}`,align:"left"})),{columns:r,rows:n.slice(1).map(s=>r.map((i,a)=>mo(s[a])))}):{columns:r,rows:n.map(s=>Array.isArray(s)?r.map((i,a)=>mo(s[a])):s&&typeof s=="object"?r.map(i=>mo(s[i.key])):r.map((i,a)=>a===0?mo(s):""))}}function uq(e){const t=String(e||"").trim();if(!t)return{columns:[],rows:[],error:""};const n=t.match(/^```(?:json|table|csv|tsv|markdown|md)?\s*\n?([\s\S]*?)```\s*$/i),r=n?n[1].trim():t;try{const l=cq(JSON.parse(r));if(l&&l.columns.length)return{...l,error:""}}catch{}const s=r.replace(/\r\n/g,`
|
|
144
144
|
`).split(`
|
|
145
|
-
`).filter(l=>l.trim());if(s.length>=2&&sa(s[0]).length>1&&a2(s[1])){const l=sa(s[0]),c=l2(s[1]);return{columns:l.map((d,f)=>({key:String(f),label:d,align:c[f]||"left"})),rows:s.slice(2).map(d=>sa(d)),error:""}}const i=r.includes(" ")?" ":",",a=lq(r,i);return a.length>0&&a[0].length>1?{columns:a[0].map((c,d)=>c||`Column ${d+1}`).map((c,d)=>({key:String(d),label:c,align:"left"})),rows:a.slice(1),error:""}:{columns:[],rows:[],error:"No table data detected"}}function O0({content:e}){const t=h.useMemo(()=>uq(e),[e]);return t.error||t.columns.length===0?o.jsxs("div",{className:"af-work-display-table-empty",children:[o.jsx("strong",{children:"Table data error"}),o.jsx("span",{children:t.error||"No columns found"})]}):o.jsx("div",{className:"af-work-display-table-wrap af-work-display-table-wrap--standalone",children:o.jsxs("table",{className:"af-work-display-table",children:[o.jsx("thead",{children:o.jsx("tr",{children:t.columns.map((n,r)=>o.jsx("th",{style:{textAlign:n.align||"left"},children:n.label},`${n.key}-${r}`))})}),o.jsx("tbody",{children:t.rows.map((n,r)=>o.jsx("tr",{children:t.columns.map((s,i)=>o.jsx("td",{style:{textAlign:s.align||"left"},children:mo(n[i])},`${s.key}-${i}`))},r))})]})})}function $0({content:e}){const t=h.useRef(null),n=h.useMemo(()=>tq(e),[e]),[r,s]=h.useState({loading:!1,error:""});return h.useEffect(()=>{if(!n.ok){s({loading:!1,error:n.error||"Invalid chart spec"});return}let i=!1,a=null,l=null,c=null;return s({loading:!0,error:""}),B7(()=>import("./index-DgQRkS4v.js"),[]).then(d=>{i||!t.current||(a=d.init(t.current,"dark",{renderer:"canvas"}),a.setOption(n.spec.option,!0),c=()=>a==null?void 0:a.resize(),typeof ResizeObserver<"u"&&(l=new ResizeObserver(c),l.observe(t.current)),window.addEventListener("resize",c),window.requestAnimationFrame(c),i||s({loading:!1,error:""}))}).catch(d=>{i||s({loading:!1,error:String((d==null?void 0:d.message)||d)})}),()=>{var d,f;i=!0,c&&window.removeEventListener("resize",c),(d=l==null?void 0:l.disconnect)==null||d.call(l),(f=a==null?void 0:a.dispose)==null||f.call(a)}},[n]),!n.ok||r.error?o.jsxs("div",{className:"af-work-display-chart-error",children:[o.jsx("strong",{children:"Chart configuration error"}),o.jsx("span",{children:r.error||n.error})]}):o.jsxs("div",{className:"af-work-display-chart",children:[o.jsx("div",{ref:t,className:"af-work-display-chart__canvas"}),r.loading?o.jsx("div",{className:"af-work-display-chart__loading",children:"Loading chart..."}):null]})}const dq="af:workspace-graph:v2",Vc=["DISPLAY","CONTROL","TOOL","PROVIDE","AGENT"],fq=new Set(["control_start","control_end","control_load_skills","control_load_mcp"]),pq={id:"workspace_run",displayName:"Run",label:"Run",description:"Run the downstream workspace subgraph connected from this node.",type:"control",inputs:[{type:"node",name:"prev",default:""}],outputs:[{type:"node",name:"next",default:""}]},hq={id:"control_load_skills",displayName:"Load Skills",label:"Load Skills",description:"Load the currently selected Workspace skill collection for downstream agent nodes.",type:"control",inputs:[{type:"node",name:"prev",default:""},{type:"text",name:"skillKeys",default:"",showOnNode:!1}],outputs:[{type:"node",name:"next",default:""},{type:"text",name:"skillsContext",default:"",showOnNode:!0}]},mq={id:"control_load_mcp",displayName:"Load MCP",label:"Load MCP",description:"Load selected Cursor MCP server tool manifests for downstream agent nodes.",type:"control",inputs:[{type:"node",name:"prev",default:""},{type:"text",name:"serverNames",default:"",showOnNode:!1}],outputs:[{type:"node",name:"next",default:""},{type:"text",name:"mcpContext",default:"",showOnNode:!0}]},gq=new Set(["png","jpg","jpeg","gif","webp","svg"]),yq=320,d2=180,f2=960,Db=96,p2=900,Fb="display-ref:",xq="0.1.65";function wq(){const e=new URLSearchParams(window.location.search);return{flowId:e.get("flowId")||"",flowSource:e.get("flowSource")||"user",archived:e.get("archived")==="1"||e.get("flowArchived")==="1"}}function xo(e){const t=new URLSearchParams;return e.flowId&&t.set("flowId",e.flowId),e.flowSource&&t.set("flowSource",e.flowSource),e.archived&&t.set("archived","1"),t}function gg(e){if(!e)return!1;const t=String(e.type||"");if(t&&/^image\//i.test(t))return!0;const n=String(e.name||"").toLowerCase().split(".").pop();return gq.has(n)}function yg(e,t,n={}){const r=String(e||"").trim();if(!r)return"";if(/^(?:https?:|data:|blob:|file:)/i.test(r)||r.startsWith("/"))return r;const s=xo(t||{});return s.set("path",r),n.download&&s.set("download","1"),`/api/workspace/file/raw?${s.toString()}`}function bq(e,t){const n=String(e||"").trim();if(!n)return"";const r=xo(t||{});return r.set("path",n),r.set("download","1"),`/api/workspace/file/raw?${r.toString()}`}function vq(e){const t=String((e==null?void 0:e.flowId)||"").trim();if(!t)return"";const n=String((e==null?void 0:e.flowSource)||"user").trim()||"user";return`af:composer-skills:workspace:${t}:${n}${e!=null&&e.archived?":archived":""}`}function kq(e){return!e||typeof e.closest!="function"?!1:!!e.closest("input, textarea, select, [contenteditable='true']")}function Sq(e){var t;if(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)return Number(e.selectionStart??0)!==Number(e.selectionEnd??0);if(e instanceof Element&&e.closest('[contenteditable="true"]')){const n=(t=window.getSelection)==null?void 0:t.call(window);return!!(n&&!n.isCollapsed)}return!1}function Nq(e){return!e||typeof e.closest!="function"?!1:!!e.closest(".af-flow-node__prompt-stack")&&!Sq(e)}function jq(e){const t=String(e||"").trim();if(!t)return"";if(/^运行完成/.test(t))return"运行完成";if(/^运行暂停/.test(t))return"运行暂停";if(/^运行停止/.test(t))return"运行停止";if(/^思考中/.test(t))return"模型正在思考";if(/^生成回复中/.test(t))return"模型正在生成回复";if(/^Timing\s+(.+?):\s+(\d+)ms/i.test(t)){const n=t.match(/^Timing\s+(.+?):\s+(\d+)ms/i);return`耗时:${(n==null?void 0:n[1])||"step"} ${(n==null?void 0:n[2])||"0"}ms`}if(/^工具\s+(.+?)(?:\s+\((started|completed)\))?$/i.test(t)){const n=t.match(/^工具\s+(.+?)(?:\s+\((started|completed)\))?$/i),r=String((n==null?void 0:n[1])||"tool").trim(),s=String((n==null?void 0:n[2])||"").toLowerCase();if(r==="thinking")return"模型正在思考";const i=r==="readToolCall"?"读取文件/上下文":r==="grepToolCall"?"搜索代码":r==="editToolCall"?"编辑文件":r;return s==="completed"?`完成:${i}`:`执行:${i}`}return/^\[stderr\]/.test(t)?t:""}function C1(e){const t=Math.max(0,Number(e)||0);if(t<1e3)return`${t}ms`;if(t<6e4)return`${(t/1e3).toFixed(t<1e4?1:0)}s`;const n=Math.floor(t/6e4),r=Math.round(t%6e4/1e3);return`${n}m${r?`${r}s`:""}`}function Cq(e,t){const n=typeof e=="string"?e:String((e==null?void 0:e.text)||""),r=typeof e=="object"?Number(e==null?void 0:e.stepMs):NaN,s=typeof e=="object"?Number(e==null?void 0:e.totalMs):NaN,i=Number.isFinite(r)&&Number.isFinite(s)?`(+${C1(r)} / 总 ${C1(s)})`:"";return`${t+1}. ${n}${i}`}function E1(e){if(String((e==null?void 0:e.type)||"")!=="raw"||String((e==null?void 0:e.eventType)||"")!=="thinking")return"";const t=String((e==null?void 0:e.text)||"").trim();if(!t)return"";try{const n=JSON.parse(t);if((n==null?void 0:n.type)!=="thinking")return"";const r=String((n==null?void 0:n.subtype)||"");return r&&r!=="delta"?"":String((n==null?void 0:n.text)||(n==null?void 0:n.delta)||(n==null?void 0:n.thinking)||"").trim()}catch{return""}}function h2(e,t){const n=String(e||(t==null?void 0:t.id)||"").toLowerCase();return n.startsWith("control_")?"control":n.startsWith("provide_")?"provide":n.startsWith("tool_")?"agent":(t==null?void 0:t.type)||"agent"}function m2(e){const t=String((e==null?void 0:e.marketplaceDefinitionId)||(e==null?void 0:e.id)||"").trim();return t.startsWith("marketplace:")?t:""}function D0(e){if(!e)return"";const t=String(e.baseDefinitionId||"").trim();if(!t)return String(e.id||"").trim();const n=e.runtime&&typeof e.runtime=="object"?e.runtime:{};return!!(n.entry||n.command)&&t==="tool_nodejs"?String(e.id||"").trim():t}function Qd(e){const t=String(D0(e)||(e==null?void 0:e.id)||"");return t==="workspace_run"?"CONTROL":t.startsWith("display_")?"DISPLAY":/^control/i.test(t)?"CONTROL":/^tool/i.test(t)?"TOOL":/^provide/i.test(t)?"PROVIDE":"AGENT"}function _1(e){return e==="DISPLAY"?"preview":e==="CONTROL"?"account_tree":e==="TOOL"?"build":e==="PROVIDE"?"database":"smart_toy"}function xg(e){return String((e==null?void 0:e.displayName)||(e==null?void 0:e.label)||(e==null?void 0:e.id)||"Node")}function Zd(e){return xg(e)}function zb(e){return String((e==null?void 0:e.description)||(e==null?void 0:e.body)||"").replace(/\s+/g," ").trim()}function Fx(e,t){const n=String((e==null?void 0:e.name)||(e==null?void 0:e.id)||"").trim(),r=String((e==null?void 0:e.type)||"").trim();return n||r||`#${t+1}`}function P1(e,t,n){const r=String((t==null?void 0:t.name)||(t==null?void 0:t.id)||`#${n+1}`).trim(),s=String((t==null?void 0:t.type)||"").trim(),i=String((t==null?void 0:t.default)??(t==null?void 0:t.value)??"").trim();return[e,r,s?`type: ${s}`:"",i?`default: ${i}`:""].filter(Boolean).join(" · ")}function A1(e,t){const n=Array.isArray(e)?e:[],r=n.slice(0,4),s=Math.max(0,n.length-r.length);return{list:n,shown:r,hidden:s,kind:t}}function I1(e,t){const n=String((e==null?void 0:e.source)||""),r=String((e==null?void 0:e.target)||"");if(!n||!r)return!1;const s=new Map(t.map(l=>[l.id,l])),i=zu(s.get(n),e.sourceHandle||"output-0","source"),a=zu(s.get(r),e.targetHandle||"input-0","target");return!!(i&&a&&Fu(i,a))}function Eq(e,t){const n=String((e==null?void 0:e.nodeId)||""),r=String((e==null?void 0:e.handleId)||""),s=(e==null?void 0:e.handleType)==="target"?"target":(e==null?void 0:e.handleType)==="source"?"source":"";if(!n||!r||!s)return null;const i=t.find(l=>l.id===n),a=zu(i,r,s);return a?{nodeId:n,handleId:r,handleType:s,slot:a,slotType:zT(a)}:null}function _q(e,t){return t?e.map((n,r)=>{const s=Array.isArray(t.handleType==="source"?n.inputs:n.outputs)?t.handleType==="source"?n.inputs:n.outputs:[];for(let i=0;i<s.length;i+=1){const a=s[i];if(!(t.handleType==="source"?Fu(t.slot,a):Fu(a,t.slot)))continue;const c=Qd(n);return{def:n,order:r,category:c,categoryRank:Vc.indexOf(c),slot:a,slotIndex:i,displayLabel:Zd(n),description:zb(n)}}return null}).filter(Boolean).sort((n,r)=>{var a,l;const s=(a=n.slot)!=null&&a.required?0:1,i=(l=r.slot)!=null&&l.required?0:1;return s-i||n.slotIndex-r.slotIndex||n.categoryRank-r.categoryRank||n.order-r.order}):[]}function ef(e,t=!1){if(t)return"folder";const n=String(e||"").toLowerCase().split(".").pop();return n==="md"||n==="markdown"?"article":n==="html"?"web":["csv","tsv"].includes(n)?"table":["js","jsx","ts","tsx","mjs","cjs"].includes(n)?"code":["yaml","yml","json"].includes(n)?"data_object":"draft"}function Pq(e,t){const n=String(e||"node").replace(/^(agent|control|provide|tool|display)_/i,"").replace(/[^a-zA-Z0-9_]+/g,"_").replace(/^_+|_+$/g,"")||"node",r=new Set(t.map(s=>s.id));for(let s=1;s<1e4;s++){const i=`${n}_${s}`;if(!r.has(i))return i}return`${n}_${Date.now().toString(36)}`}function Aq(e){return(e==null?void 0:e.default)!=null?String(e.default):(e==null?void 0:e.value)!=null?String(e.value):""}function Bh(e){return(Array.isArray(e)?e:[]).map(t=>({type:(t==null?void 0:t.type)||"node",name:(t==null?void 0:t.name)||"",default:Aq(t),required:!!(t!=null&&t.required),showOnNode:(t==null?void 0:t.showOnNode)!=null?t.showOnNode!==!1:!!(t!=null&&t.required)||String((t==null?void 0:t.type)||"node").trim().toLowerCase()==="node"}))}function g2(e){const t=(e==null?void 0:e.data)||{},n=r=>(Array.isArray(r)?r:[]).map((s,i)=>(s==null?void 0:s.showOnNode)===!1?"":[i,String((s==null?void 0:s.type)||""),String((s==null?void 0:s.name)||""),s!=null&&s.required?"1":"0"].join(":")).filter(Boolean).join("|");return`${n(t.inputs)}=>${n(t.outputs)}`}function Iq(e){var s,i;const t=(e==null?void 0:e.data)||{},n=t!=null&&t.displaySize&&typeof t.displaySize=="object"?t.displaySize:{},r=t!=null&&t.nodeSize&&typeof t.nodeSize=="object"?t.nodeSize:{};return[g2(e),Number((e==null?void 0:e.width)||0)||"",Number((e==null?void 0:e.height)||0)||"",Number(((s=e==null?void 0:e.measured)==null?void 0:s.width)||0)||"",Number(((i=e==null?void 0:e.measured)==null?void 0:i.height)||0)||"",Number(r.width||0)||"",Number(r.height||0)||"",Number(n.width||0)||"",Number(n.height||0)||"",t!=null&&t.isExecuting?"executing":"",(t==null?void 0:t.nodeStatus)||"",(t==null?void 0:t.runningRunNodeId)||""].join("::")}function zx(e,t){var u,p;const n=e!=null&&e.instances&&typeof e.instances=="object"?e.instances:{},r=x2(n),s=Array.isArray(e==null?void 0:e.edges)?e.edges:[],i=(u=e==null?void 0:e.ui)!=null&&u.nodePositions&&typeof e.ui.nodePositions=="object"?e.ui.nodePositions:{},a=(p=e==null?void 0:e.ui)!=null&&p.nodeSizes&&typeof e.ui.nodeSizes=="object"?e.ui.nodeSizes:{},l=new Set(Object.keys(r));for(const m of s)m!=null&&m.source&&l.add(String(m.source)),m!=null&&m.target&&l.add(String(m.target));const d=Array.from(l).map(m=>{const y=r[m]||{},b=y.definitionId||m,k=t.find(H=>H.id===b),g=D0(k)||b,v=t.find(H=>H.id===g)||k,x=y.marketplaceRef||m2(k),N=i[m]&&typeof i[m].x=="number"&&typeof i[m].y=="number"?i[m]:{x:320+l.size*20,y:180+l.size*12},_=!!Kn(g),C=a[m]&&typeof a[m].width=="number"&&typeof a[m].height=="number"?{width:a[m].width,height:a[m].height}:null,T=bu(C,{display:_});return{id:m,type:Sp,position:N,...T?{width:T.width,height:T.height}:{},data:{label:y.label||xg(k)||xg(v)||m,definitionId:g,...x?{marketplaceRef:x}:{},...k!=null&&k.packageId?{marketplacePackageId:k.packageId}:{},...k!=null&&k.version?{marketplaceVersion:k.version}:{},schemaType:h2(g,v||k),role:y.role||"normal",model:y.model||void 0,body:y.body||"",script:y.script||"",...T?{nodeSize:T}:{},..._&&T?{displaySize:T}:{}}}}).map(m=>tp(m,r,t)),f=s.filter(m=>(m==null?void 0:m.source)&&(m==null?void 0:m.target)).map((m,y)=>({id:m.id||`we-${m.source}-${m.target}-${y}`,source:String(m.source),target:String(m.target),sourceHandle:m.sourceHandle??void 0,targetHandle:m.targetHandle??void 0,markerEnd:{type:$s.ArrowClosed}}));return{nodes:d,edges:DT(f,d),instances:r}}function T1(e){return`${Fb}${e}`}function Hx(e){const t=String(e||"");return t.startsWith(Fb)?t.slice(Fb.length):t}function y2(e){if(!e||typeof e!="object")return null;const t=Number(e.x),n=Number(e.y),r=Number(e.zoom);return!Number.isFinite(t)||!Number.isFinite(n)||!Number.isFinite(r)?null:{x:t,y:n,zoom:Math.min(Math.max(r,.1),4)}}function Hb(e,t=[]){const n=new Map((Array.isArray(t)?t:[]).filter(u=>{var p;return Kn((p=u==null?void 0:u.data)==null?void 0:p.definitionId)}).map(u=>[u.id,u])),r=Array.isArray(e==null?void 0:e.nodeIds)?e.nodeIds:[],s=[],i=new Set;for(const u of r){const p=String(u||"").trim();!p||i.has(p)||!n.has(p)||(i.add(p),s.push(p))}const a={},l=e!=null&&e.nodePositions&&typeof e.nodePositions=="object"?e.nodePositions:{};s.forEach((u,p)=>{const m=l[u];a[u]=m&&typeof m.x=="number"&&typeof m.y=="number"?{x:m.x,y:m.y}:{x:180+p*36,y:120+p*28}});const c={},d=e!=null&&e.nodeSizes&&typeof e.nodeSizes=="object"?e.nodeSizes:{};s.forEach(u=>{const p=bu(d[u],{display:!0});p&&(c[u]=p)});const f=y2(e==null?void 0:e.viewport);return{nodeIds:s,nodePositions:a,nodeSizes:c,...f?{viewport:f}:{}}}function Tq(e,t=[]){return Hb(e,t)}function Rq(e){const t=Number.isFinite(e)?e:1;return Math.min(Math.max(t,.75),1)}async function Lq(e){var n;const t=String(e||"");if(!t)return!1;try{if((n=navigator.clipboard)!=null&&n.writeText)return await navigator.clipboard.writeText(t),!0}catch{}try{const r=document.createElement("textarea");r.value=t,r.setAttribute("readonly",""),r.style.position="fixed",r.style.left="-9999px",r.style.top="0",document.body.appendChild(r),r.focus(),r.select();const s=document.execCommand("copy");return document.body.removeChild(r),s}catch{return!1}}function R1(e,t,n){const r=Number(e);return!Number.isFinite(r)||r<=0?0:Math.min(n,Math.max(t,Math.round(r)))}function bu(e,{display:t=!1}={}){if(!e||typeof e!="object")return null;const n=Number(e.width),r=Number(e.height);return!Number.isFinite(n)||!Number.isFinite(r)||n<=0||r<=0?null:t?{width:Math.round(n),height:Math.round(r)}:{width:R1(n,d2,f2)||yq,height:R1(r,Db,p2)||Db}}function Uc(e){var s,i,a,l,c,d,f,u,p,m,y;const t=!!Kn((s=e==null?void 0:e.data)==null?void 0:s.definitionId),n=Number(((a=(i=e==null?void 0:e.data)==null?void 0:i.displaySize)==null?void 0:a.width)||((c=(l=e==null?void 0:e.data)==null?void 0:l.nodeSize)==null?void 0:c.width)||(e==null?void 0:e.width)||(t?(d=e==null?void 0:e.measured)==null?void 0:d.width:0)||0),r=Number(((u=(f=e==null?void 0:e.data)==null?void 0:f.displaySize)==null?void 0:u.height)||((m=(p=e==null?void 0:e.data)==null?void 0:p.nodeSize)==null?void 0:m.height)||(e==null?void 0:e.height)||(t?(y=e==null?void 0:e.measured)==null?void 0:y.height:0)||0);return bu({width:n,height:r},{display:t})}function Wh(e,t,n){var l,c;const r=x2(kp(e,n||{})),s=t.map(d=>({source:d.source,target:d.target,sourceHandle:d.sourceHandle??null,targetHandle:d.targetHandle??null})),i={},a={};for(const d of e){i[d.id]={x:((l=d.position)==null?void 0:l.x)||0,y:((c=d.position)==null?void 0:c.y)||0};const f=Uc(d);f&&(a[d.id]=f)}return{version:1,instances:r,edges:s,ui:{nodePositions:i,nodeSizes:a}}}function x2(e){const t={};for(const[n,r]of Object.entries(e||{})){const s=String((r==null?void 0:r.definitionId)||n);if(!!Kn(s)||s.startsWith("provide_")||!Array.isArray(r==null?void 0:r.output)){t[n]=r;continue}t[n]={...r,output:r.output.map(a=>({...a,value:"",default:""}))}}return t}function Kn(e){const t=String(e||"");return t==="display_markdown"?"markdown":t==="display_mermaid"?"mermaid":t==="display_ascii"?"ascii":t==="display_html"?"html":t==="display_image"?"image":t==="display_chart"?"chart":t==="display_table"?"table":""}function sc(e){const t=[...(e==null?void 0:e.inputs)||[],...(e==null?void 0:e.outputs)||[]],r=Kn(e==null?void 0:e.definitionId)==="image"?"src":"content",s=l=>String((l==null?void 0:l.value)??(l==null?void 0:l.default)??""),i=l=>s(l).trim(),a=t.find(l=>(l==null?void 0:l.name)===r&&i(l))||t.find(l=>(l==null?void 0:l.name)==="filePath"&&i(l))||t.find(l=>(l==null?void 0:l.type)==="text"&&i(l));return String((e==null?void 0:e.body)||(a?s(a):""))}function Hu(e,t=""){const n=String(e||"").trim();if(!n||n.length>260||/[\r\n<>]/.test(n)||/^(?:https?:|data:|blob:|file:|javascript:|mailto:|tel:)/i.test(n))return"";const r=n.replace(/^\/+/,"");if(r.includes("..")||r.startsWith("."))return"";const s=r.split("?")[0].split("#")[0].toLowerCase().split(".").pop()||"";return({html:new Set(["html","htm"]),markdown:new Set(["md","markdown","txt"]),mermaid:new Set(["mmd","mermaid","txt"]),ascii:new Set(["txt","log"]),chart:new Set(["json"]),table:new Set(["json","csv","tsv"])}[t]||new Set(["html","htm","md","markdown","txt","json","csv","tsv"])).has(s)?r:""}function Mq(e){let t=String(e||"").replace(/\r\n/g,`
|
|
145
|
+
`).filter(l=>l.trim());if(s.length>=2&&sa(s[0]).length>1&&a2(s[1])){const l=sa(s[0]),c=l2(s[1]);return{columns:l.map((d,f)=>({key:String(f),label:d,align:c[f]||"left"})),rows:s.slice(2).map(d=>sa(d)),error:""}}const i=r.includes(" ")?" ":",",a=lq(r,i);return a.length>0&&a[0].length>1?{columns:a[0].map((c,d)=>c||`Column ${d+1}`).map((c,d)=>({key:String(d),label:c,align:"left"})),rows:a.slice(1),error:""}:{columns:[],rows:[],error:"No table data detected"}}function O0({content:e}){const t=h.useMemo(()=>uq(e),[e]);return t.error||t.columns.length===0?o.jsxs("div",{className:"af-work-display-table-empty",children:[o.jsx("strong",{children:"Table data error"}),o.jsx("span",{children:t.error||"No columns found"})]}):o.jsx("div",{className:"af-work-display-table-wrap af-work-display-table-wrap--standalone",children:o.jsxs("table",{className:"af-work-display-table",children:[o.jsx("thead",{children:o.jsx("tr",{children:t.columns.map((n,r)=>o.jsx("th",{style:{textAlign:n.align||"left"},children:n.label},`${n.key}-${r}`))})}),o.jsx("tbody",{children:t.rows.map((n,r)=>o.jsx("tr",{children:t.columns.map((s,i)=>o.jsx("td",{style:{textAlign:s.align||"left"},children:mo(n[i])},`${s.key}-${i}`))},r))})]})})}function $0({content:e}){const t=h.useRef(null),n=h.useMemo(()=>tq(e),[e]),[r,s]=h.useState({loading:!1,error:""});return h.useEffect(()=>{if(!n.ok){s({loading:!1,error:n.error||"Invalid chart spec"});return}let i=!1,a=null,l=null,c=null;return s({loading:!0,error:""}),B7(()=>import("./index-DgQRkS4v.js"),[]).then(d=>{i||!t.current||(a=d.init(t.current,"dark",{renderer:"canvas"}),a.setOption(n.spec.option,!0),c=()=>a==null?void 0:a.resize(),typeof ResizeObserver<"u"&&(l=new ResizeObserver(c),l.observe(t.current)),window.addEventListener("resize",c),window.requestAnimationFrame(c),i||s({loading:!1,error:""}))}).catch(d=>{i||s({loading:!1,error:String((d==null?void 0:d.message)||d)})}),()=>{var d,f;i=!0,c&&window.removeEventListener("resize",c),(d=l==null?void 0:l.disconnect)==null||d.call(l),(f=a==null?void 0:a.dispose)==null||f.call(a)}},[n]),!n.ok||r.error?o.jsxs("div",{className:"af-work-display-chart-error",children:[o.jsx("strong",{children:"Chart configuration error"}),o.jsx("span",{children:r.error||n.error})]}):o.jsxs("div",{className:"af-work-display-chart",children:[o.jsx("div",{ref:t,className:"af-work-display-chart__canvas"}),r.loading?o.jsx("div",{className:"af-work-display-chart__loading",children:"Loading chart..."}):null]})}const dq="af:workspace-graph:v2",Vc=["DISPLAY","CONTROL","TOOL","PROVIDE","AGENT"],fq=new Set(["control_start","control_end","control_load_skills","control_load_mcp"]),pq={id:"workspace_run",displayName:"Run",label:"Run",description:"Run the downstream workspace subgraph connected from this node.",type:"control",inputs:[{type:"node",name:"prev",default:""}],outputs:[{type:"node",name:"next",default:""}]},hq={id:"control_load_skills",displayName:"Load Skills",label:"Load Skills",description:"Load the currently selected Workspace skill collection for downstream agent nodes.",type:"control",inputs:[{type:"node",name:"prev",default:""},{type:"text",name:"skillKeys",default:"",showOnNode:!1}],outputs:[{type:"node",name:"next",default:""},{type:"text",name:"skillsContext",default:"",showOnNode:!0}]},mq={id:"control_load_mcp",displayName:"Load MCP",label:"Load MCP",description:"Load selected Cursor MCP server tool manifests for downstream agent nodes.",type:"control",inputs:[{type:"node",name:"prev",default:""},{type:"text",name:"serverNames",default:"",showOnNode:!1}],outputs:[{type:"node",name:"next",default:""},{type:"text",name:"mcpContext",default:"",showOnNode:!0}]},gq=new Set(["png","jpg","jpeg","gif","webp","svg"]),yq=320,d2=180,f2=960,Db=96,p2=900,Fb="display-ref:",xq="0.1.67";function wq(){const e=new URLSearchParams(window.location.search);return{flowId:e.get("flowId")||"",flowSource:e.get("flowSource")||"user",archived:e.get("archived")==="1"||e.get("flowArchived")==="1"}}function xo(e){const t=new URLSearchParams;return e.flowId&&t.set("flowId",e.flowId),e.flowSource&&t.set("flowSource",e.flowSource),e.archived&&t.set("archived","1"),t}function gg(e){if(!e)return!1;const t=String(e.type||"");if(t&&/^image\//i.test(t))return!0;const n=String(e.name||"").toLowerCase().split(".").pop();return gq.has(n)}function yg(e,t,n={}){const r=String(e||"").trim();if(!r)return"";if(/^(?:https?:|data:|blob:|file:)/i.test(r)||r.startsWith("/"))return r;const s=xo(t||{});return s.set("path",r),n.download&&s.set("download","1"),`/api/workspace/file/raw?${s.toString()}`}function bq(e,t){const n=String(e||"").trim();if(!n)return"";const r=xo(t||{});return r.set("path",n),r.set("download","1"),`/api/workspace/file/raw?${r.toString()}`}function vq(e){const t=String((e==null?void 0:e.flowId)||"").trim();if(!t)return"";const n=String((e==null?void 0:e.flowSource)||"user").trim()||"user";return`af:composer-skills:workspace:${t}:${n}${e!=null&&e.archived?":archived":""}`}function kq(e){return!e||typeof e.closest!="function"?!1:!!e.closest("input, textarea, select, [contenteditable='true']")}function Sq(e){var t;if(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)return Number(e.selectionStart??0)!==Number(e.selectionEnd??0);if(e instanceof Element&&e.closest('[contenteditable="true"]')){const n=(t=window.getSelection)==null?void 0:t.call(window);return!!(n&&!n.isCollapsed)}return!1}function Nq(e){return!e||typeof e.closest!="function"?!1:!!e.closest(".af-flow-node__prompt-stack")&&!Sq(e)}function jq(e){const t=String(e||"").trim();if(!t)return"";if(/^运行完成/.test(t))return"运行完成";if(/^运行暂停/.test(t))return"运行暂停";if(/^运行停止/.test(t))return"运行停止";if(/^思考中/.test(t))return"模型正在思考";if(/^生成回复中/.test(t))return"模型正在生成回复";if(/^Timing\s+(.+?):\s+(\d+)ms/i.test(t)){const n=t.match(/^Timing\s+(.+?):\s+(\d+)ms/i);return`耗时:${(n==null?void 0:n[1])||"step"} ${(n==null?void 0:n[2])||"0"}ms`}if(/^工具\s+(.+?)(?:\s+\((started|completed)\))?$/i.test(t)){const n=t.match(/^工具\s+(.+?)(?:\s+\((started|completed)\))?$/i),r=String((n==null?void 0:n[1])||"tool").trim(),s=String((n==null?void 0:n[2])||"").toLowerCase();if(r==="thinking")return"模型正在思考";const i=r==="readToolCall"?"读取文件/上下文":r==="grepToolCall"?"搜索代码":r==="editToolCall"?"编辑文件":r;return s==="completed"?`完成:${i}`:`执行:${i}`}return/^\[stderr\]/.test(t)?t:""}function C1(e){const t=Math.max(0,Number(e)||0);if(t<1e3)return`${t}ms`;if(t<6e4)return`${(t/1e3).toFixed(t<1e4?1:0)}s`;const n=Math.floor(t/6e4),r=Math.round(t%6e4/1e3);return`${n}m${r?`${r}s`:""}`}function Cq(e,t){const n=typeof e=="string"?e:String((e==null?void 0:e.text)||""),r=typeof e=="object"?Number(e==null?void 0:e.stepMs):NaN,s=typeof e=="object"?Number(e==null?void 0:e.totalMs):NaN,i=Number.isFinite(r)&&Number.isFinite(s)?`(+${C1(r)} / 总 ${C1(s)})`:"";return`${t+1}. ${n}${i}`}function E1(e){if(String((e==null?void 0:e.type)||"")!=="raw"||String((e==null?void 0:e.eventType)||"")!=="thinking")return"";const t=String((e==null?void 0:e.text)||"").trim();if(!t)return"";try{const n=JSON.parse(t);if((n==null?void 0:n.type)!=="thinking")return"";const r=String((n==null?void 0:n.subtype)||"");return r&&r!=="delta"?"":String((n==null?void 0:n.text)||(n==null?void 0:n.delta)||(n==null?void 0:n.thinking)||"").trim()}catch{return""}}function h2(e,t){const n=String(e||(t==null?void 0:t.id)||"").toLowerCase();return n.startsWith("control_")?"control":n.startsWith("provide_")?"provide":n.startsWith("tool_")?"agent":(t==null?void 0:t.type)||"agent"}function m2(e){const t=String((e==null?void 0:e.marketplaceDefinitionId)||(e==null?void 0:e.id)||"").trim();return t.startsWith("marketplace:")?t:""}function D0(e){if(!e)return"";const t=String(e.baseDefinitionId||"").trim();if(!t)return String(e.id||"").trim();const n=e.runtime&&typeof e.runtime=="object"?e.runtime:{};return!!(n.entry||n.command)&&t==="tool_nodejs"?String(e.id||"").trim():t}function Qd(e){const t=String(D0(e)||(e==null?void 0:e.id)||"");return t==="workspace_run"?"CONTROL":t.startsWith("display_")?"DISPLAY":/^control/i.test(t)?"CONTROL":/^tool/i.test(t)?"TOOL":/^provide/i.test(t)?"PROVIDE":"AGENT"}function _1(e){return e==="DISPLAY"?"preview":e==="CONTROL"?"account_tree":e==="TOOL"?"build":e==="PROVIDE"?"database":"smart_toy"}function xg(e){return String((e==null?void 0:e.displayName)||(e==null?void 0:e.label)||(e==null?void 0:e.id)||"Node")}function Zd(e){return xg(e)}function zb(e){return String((e==null?void 0:e.description)||(e==null?void 0:e.body)||"").replace(/\s+/g," ").trim()}function Fx(e,t){const n=String((e==null?void 0:e.name)||(e==null?void 0:e.id)||"").trim(),r=String((e==null?void 0:e.type)||"").trim();return n||r||`#${t+1}`}function P1(e,t,n){const r=String((t==null?void 0:t.name)||(t==null?void 0:t.id)||`#${n+1}`).trim(),s=String((t==null?void 0:t.type)||"").trim(),i=String((t==null?void 0:t.default)??(t==null?void 0:t.value)??"").trim();return[e,r,s?`type: ${s}`:"",i?`default: ${i}`:""].filter(Boolean).join(" · ")}function A1(e,t){const n=Array.isArray(e)?e:[],r=n.slice(0,4),s=Math.max(0,n.length-r.length);return{list:n,shown:r,hidden:s,kind:t}}function I1(e,t){const n=String((e==null?void 0:e.source)||""),r=String((e==null?void 0:e.target)||"");if(!n||!r)return!1;const s=new Map(t.map(l=>[l.id,l])),i=zu(s.get(n),e.sourceHandle||"output-0","source"),a=zu(s.get(r),e.targetHandle||"input-0","target");return!!(i&&a&&Fu(i,a))}function Eq(e,t){const n=String((e==null?void 0:e.nodeId)||""),r=String((e==null?void 0:e.handleId)||""),s=(e==null?void 0:e.handleType)==="target"?"target":(e==null?void 0:e.handleType)==="source"?"source":"";if(!n||!r||!s)return null;const i=t.find(l=>l.id===n),a=zu(i,r,s);return a?{nodeId:n,handleId:r,handleType:s,slot:a,slotType:zT(a)}:null}function _q(e,t){return t?e.map((n,r)=>{const s=Array.isArray(t.handleType==="source"?n.inputs:n.outputs)?t.handleType==="source"?n.inputs:n.outputs:[];for(let i=0;i<s.length;i+=1){const a=s[i];if(!(t.handleType==="source"?Fu(t.slot,a):Fu(a,t.slot)))continue;const c=Qd(n);return{def:n,order:r,category:c,categoryRank:Vc.indexOf(c),slot:a,slotIndex:i,displayLabel:Zd(n),description:zb(n)}}return null}).filter(Boolean).sort((n,r)=>{var a,l;const s=(a=n.slot)!=null&&a.required?0:1,i=(l=r.slot)!=null&&l.required?0:1;return s-i||n.slotIndex-r.slotIndex||n.categoryRank-r.categoryRank||n.order-r.order}):[]}function ef(e,t=!1){if(t)return"folder";const n=String(e||"").toLowerCase().split(".").pop();return n==="md"||n==="markdown"?"article":n==="html"?"web":["csv","tsv"].includes(n)?"table":["js","jsx","ts","tsx","mjs","cjs"].includes(n)?"code":["yaml","yml","json"].includes(n)?"data_object":"draft"}function Pq(e,t){const n=String(e||"node").replace(/^(agent|control|provide|tool|display)_/i,"").replace(/[^a-zA-Z0-9_]+/g,"_").replace(/^_+|_+$/g,"")||"node",r=new Set(t.map(s=>s.id));for(let s=1;s<1e4;s++){const i=`${n}_${s}`;if(!r.has(i))return i}return`${n}_${Date.now().toString(36)}`}function Aq(e){return(e==null?void 0:e.default)!=null?String(e.default):(e==null?void 0:e.value)!=null?String(e.value):""}function Bh(e){return(Array.isArray(e)?e:[]).map(t=>({type:(t==null?void 0:t.type)||"node",name:(t==null?void 0:t.name)||"",default:Aq(t),required:!!(t!=null&&t.required),showOnNode:(t==null?void 0:t.showOnNode)!=null?t.showOnNode!==!1:!!(t!=null&&t.required)||String((t==null?void 0:t.type)||"node").trim().toLowerCase()==="node"}))}function g2(e){const t=(e==null?void 0:e.data)||{},n=r=>(Array.isArray(r)?r:[]).map((s,i)=>(s==null?void 0:s.showOnNode)===!1?"":[i,String((s==null?void 0:s.type)||""),String((s==null?void 0:s.name)||""),s!=null&&s.required?"1":"0"].join(":")).filter(Boolean).join("|");return`${n(t.inputs)}=>${n(t.outputs)}`}function Iq(e){var s,i;const t=(e==null?void 0:e.data)||{},n=t!=null&&t.displaySize&&typeof t.displaySize=="object"?t.displaySize:{},r=t!=null&&t.nodeSize&&typeof t.nodeSize=="object"?t.nodeSize:{};return[g2(e),Number((e==null?void 0:e.width)||0)||"",Number((e==null?void 0:e.height)||0)||"",Number(((s=e==null?void 0:e.measured)==null?void 0:s.width)||0)||"",Number(((i=e==null?void 0:e.measured)==null?void 0:i.height)||0)||"",Number(r.width||0)||"",Number(r.height||0)||"",Number(n.width||0)||"",Number(n.height||0)||"",t!=null&&t.isExecuting?"executing":"",(t==null?void 0:t.nodeStatus)||"",(t==null?void 0:t.runningRunNodeId)||""].join("::")}function zx(e,t){var u,p;const n=e!=null&&e.instances&&typeof e.instances=="object"?e.instances:{},r=x2(n),s=Array.isArray(e==null?void 0:e.edges)?e.edges:[],i=(u=e==null?void 0:e.ui)!=null&&u.nodePositions&&typeof e.ui.nodePositions=="object"?e.ui.nodePositions:{},a=(p=e==null?void 0:e.ui)!=null&&p.nodeSizes&&typeof e.ui.nodeSizes=="object"?e.ui.nodeSizes:{},l=new Set(Object.keys(r));for(const m of s)m!=null&&m.source&&l.add(String(m.source)),m!=null&&m.target&&l.add(String(m.target));const d=Array.from(l).map(m=>{const y=r[m]||{},b=y.definitionId||m,k=t.find(H=>H.id===b),g=D0(k)||b,v=t.find(H=>H.id===g)||k,x=y.marketplaceRef||m2(k),N=i[m]&&typeof i[m].x=="number"&&typeof i[m].y=="number"?i[m]:{x:320+l.size*20,y:180+l.size*12},_=!!Kn(g),C=a[m]&&typeof a[m].width=="number"&&typeof a[m].height=="number"?{width:a[m].width,height:a[m].height}:null,T=bu(C,{display:_});return{id:m,type:Sp,position:N,...T?{width:T.width,height:T.height}:{},data:{label:y.label||xg(k)||xg(v)||m,definitionId:g,...x?{marketplaceRef:x}:{},...k!=null&&k.packageId?{marketplacePackageId:k.packageId}:{},...k!=null&&k.version?{marketplaceVersion:k.version}:{},schemaType:h2(g,v||k),role:y.role||"normal",model:y.model||void 0,body:y.body||"",script:y.script||"",...T?{nodeSize:T}:{},..._&&T?{displaySize:T}:{}}}}).map(m=>tp(m,r,t)),f=s.filter(m=>(m==null?void 0:m.source)&&(m==null?void 0:m.target)).map((m,y)=>({id:m.id||`we-${m.source}-${m.target}-${y}`,source:String(m.source),target:String(m.target),sourceHandle:m.sourceHandle??void 0,targetHandle:m.targetHandle??void 0,markerEnd:{type:$s.ArrowClosed}}));return{nodes:d,edges:DT(f,d),instances:r}}function T1(e){return`${Fb}${e}`}function Hx(e){const t=String(e||"");return t.startsWith(Fb)?t.slice(Fb.length):t}function y2(e){if(!e||typeof e!="object")return null;const t=Number(e.x),n=Number(e.y),r=Number(e.zoom);return!Number.isFinite(t)||!Number.isFinite(n)||!Number.isFinite(r)?null:{x:t,y:n,zoom:Math.min(Math.max(r,.1),4)}}function Hb(e,t=[]){const n=new Map((Array.isArray(t)?t:[]).filter(u=>{var p;return Kn((p=u==null?void 0:u.data)==null?void 0:p.definitionId)}).map(u=>[u.id,u])),r=Array.isArray(e==null?void 0:e.nodeIds)?e.nodeIds:[],s=[],i=new Set;for(const u of r){const p=String(u||"").trim();!p||i.has(p)||!n.has(p)||(i.add(p),s.push(p))}const a={},l=e!=null&&e.nodePositions&&typeof e.nodePositions=="object"?e.nodePositions:{};s.forEach((u,p)=>{const m=l[u];a[u]=m&&typeof m.x=="number"&&typeof m.y=="number"?{x:m.x,y:m.y}:{x:180+p*36,y:120+p*28}});const c={},d=e!=null&&e.nodeSizes&&typeof e.nodeSizes=="object"?e.nodeSizes:{};s.forEach(u=>{const p=bu(d[u],{display:!0});p&&(c[u]=p)});const f=y2(e==null?void 0:e.viewport);return{nodeIds:s,nodePositions:a,nodeSizes:c,...f?{viewport:f}:{}}}function Tq(e,t=[]){return Hb(e,t)}function Rq(e){const t=Number.isFinite(e)?e:1;return Math.min(Math.max(t,.75),1)}async function Lq(e){var n;const t=String(e||"");if(!t)return!1;try{if((n=navigator.clipboard)!=null&&n.writeText)return await navigator.clipboard.writeText(t),!0}catch{}try{const r=document.createElement("textarea");r.value=t,r.setAttribute("readonly",""),r.style.position="fixed",r.style.left="-9999px",r.style.top="0",document.body.appendChild(r),r.focus(),r.select();const s=document.execCommand("copy");return document.body.removeChild(r),s}catch{return!1}}function R1(e,t,n){const r=Number(e);return!Number.isFinite(r)||r<=0?0:Math.min(n,Math.max(t,Math.round(r)))}function bu(e,{display:t=!1}={}){if(!e||typeof e!="object")return null;const n=Number(e.width),r=Number(e.height);return!Number.isFinite(n)||!Number.isFinite(r)||n<=0||r<=0?null:t?{width:Math.round(n),height:Math.round(r)}:{width:R1(n,d2,f2)||yq,height:R1(r,Db,p2)||Db}}function Uc(e){var s,i,a,l,c,d,f,u,p,m,y;const t=!!Kn((s=e==null?void 0:e.data)==null?void 0:s.definitionId),n=Number(((a=(i=e==null?void 0:e.data)==null?void 0:i.displaySize)==null?void 0:a.width)||((c=(l=e==null?void 0:e.data)==null?void 0:l.nodeSize)==null?void 0:c.width)||(e==null?void 0:e.width)||(t?(d=e==null?void 0:e.measured)==null?void 0:d.width:0)||0),r=Number(((u=(f=e==null?void 0:e.data)==null?void 0:f.displaySize)==null?void 0:u.height)||((m=(p=e==null?void 0:e.data)==null?void 0:p.nodeSize)==null?void 0:m.height)||(e==null?void 0:e.height)||(t?(y=e==null?void 0:e.measured)==null?void 0:y.height:0)||0);return bu({width:n,height:r},{display:t})}function Wh(e,t,n){var l,c;const r=x2(kp(e,n||{})),s=t.map(d=>({source:d.source,target:d.target,sourceHandle:d.sourceHandle??null,targetHandle:d.targetHandle??null})),i={},a={};for(const d of e){i[d.id]={x:((l=d.position)==null?void 0:l.x)||0,y:((c=d.position)==null?void 0:c.y)||0};const f=Uc(d);f&&(a[d.id]=f)}return{version:1,instances:r,edges:s,ui:{nodePositions:i,nodeSizes:a}}}function x2(e){const t={};for(const[n,r]of Object.entries(e||{})){const s=String((r==null?void 0:r.definitionId)||n);if(!!Kn(s)||s.startsWith("provide_")||!Array.isArray(r==null?void 0:r.output)){t[n]=r;continue}t[n]={...r,output:r.output.map(a=>({...a,value:"",default:""}))}}return t}function Kn(e){const t=String(e||"");return t==="display_markdown"?"markdown":t==="display_mermaid"?"mermaid":t==="display_ascii"?"ascii":t==="display_html"?"html":t==="display_image"?"image":t==="display_chart"?"chart":t==="display_table"?"table":""}function sc(e){const t=[...(e==null?void 0:e.inputs)||[],...(e==null?void 0:e.outputs)||[]],r=Kn(e==null?void 0:e.definitionId)==="image"?"src":"content",s=l=>String((l==null?void 0:l.value)??(l==null?void 0:l.default)??""),i=l=>s(l).trim(),a=t.find(l=>(l==null?void 0:l.name)===r&&i(l))||t.find(l=>(l==null?void 0:l.name)==="filePath"&&i(l))||t.find(l=>(l==null?void 0:l.type)==="text"&&i(l));return String((e==null?void 0:e.body)||(a?s(a):""))}function Hu(e,t=""){const n=String(e||"").trim();if(!n||n.length>260||/[\r\n<>]/.test(n)||/^(?:https?:|data:|blob:|file:|javascript:|mailto:|tel:)/i.test(n))return"";const r=n.replace(/^\/+/,"");if(r.includes("..")||r.startsWith("."))return"";const s=r.split("?")[0].split("#")[0].toLowerCase().split(".").pop()||"";return({html:new Set(["html","htm"]),markdown:new Set(["md","markdown","txt"]),mermaid:new Set(["mmd","mermaid","txt"]),ascii:new Set(["txt","log"]),chart:new Set(["json"]),table:new Set(["json","csv","tsv"])}[t]||new Set(["html","htm","md","markdown","txt","json","csv","tsv"])).has(s)?r:""}function Mq(e){let t=String(e||"").replace(/\r\n/g,`
|
|
146
146
|
`).trim();return t.includes(`
|
|
147
147
|
`)||(t=t.replace(/\s+(resultFile|result|outParams|outParams\.[A-Za-z_][A-Za-z0-9_-]*)\s*:/g,`
|
|
148
148
|
$1:`).replace(/(^|\n)outParams:\s+([A-Za-z_][A-Za-z0-9_-]*\s*:)/g,`$1outParams:
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0"
|
|
16
16
|
rel="stylesheet"
|
|
17
17
|
/>
|
|
18
|
-
<script type="module" crossorigin src="/assets/index-
|
|
18
|
+
<script type="module" crossorigin src="/assets/index-BD8MsiMa.js"></script>
|
|
19
19
|
<link rel="stylesheet" crossorigin href="/assets/index-BFZ6_IPB.css">
|
|
20
20
|
</head>
|
|
21
21
|
<body>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fieldwangai/agentflow",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.67",
|
|
4
4
|
"description": "Orchestration system for long-running complex agent tasks using Cursor, OpenCode, or Claude Code as execution backends",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "bin/agentflow.mjs",
|