@fieldwangai/agentflow 0.1.32 → 0.1.34
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/catalog-flows.mjs +7 -2
- package/bin/lib/composer-node-schema.mjs +7 -7
- package/bin/lib/composer-planner.mjs +5 -5
- package/bin/lib/git-worktree.mjs +263 -0
- package/bin/lib/gitlab-mr.mjs +174 -0
- package/bin/lib/locales/en.json +27 -7
- package/bin/lib/locales/zh.json +26 -6
- package/bin/lib/marketplace.mjs +106 -2
- package/bin/lib/paths.mjs +5 -1
- package/bin/lib/scheduler.mjs +8 -3
- package/bin/lib/ui-server.mjs +284 -13
- package/bin/pipeline/build-node-prompt.mjs +27 -1
- package/bin/pipeline/pre-process-node.mjs +216 -39
- package/bin/pipeline/validate-flow.mjs +7 -17
- package/builtin/nodes/agent_subAgent.md +2 -0
- package/builtin/nodes/control_agent_toBool.md +4 -0
- package/builtin/nodes/control_cancelled.md +8 -4
- package/builtin/nodes/control_cd_workspace.md +2 -0
- package/builtin/nodes/control_delay.md +9 -0
- package/builtin/nodes/control_toBool.md +6 -2
- package/builtin/nodes/control_user_workspace.md +2 -0
- package/builtin/nodes/control_wait_until.md +9 -0
- package/builtin/nodes/display_html.md +31 -0
- package/builtin/nodes/display_image.md +35 -0
- package/builtin/nodes/provide_bool.md +13 -0
- package/builtin/nodes/provide_file.md +2 -0
- package/builtin/nodes/provide_str.md +2 -0
- package/builtin/nodes/tool_get_env.md +4 -0
- package/builtin/nodes/tool_git_checkout.md +14 -2
- package/builtin/nodes/tool_git_worktree_load.md +59 -0
- package/builtin/nodes/tool_git_worktree_unload.md +51 -0
- package/builtin/nodes/tool_gitlab_create_mr.md +113 -0
- package/builtin/nodes/tool_load_key.md +4 -0
- package/builtin/nodes/tool_nodejs.md +4 -0
- package/builtin/nodes/tool_print.md +2 -0
- package/builtin/nodes/tool_save_key.md +4 -0
- package/builtin/nodes/tool_user_ask.md +3 -1
- package/builtin/nodes/tool_user_check.md +3 -1
- package/builtin/web-ui/dist/assets/index-B1j_UaHw.js +202 -0
- package/builtin/web-ui/dist/assets/index-ChiTnW0H.css +1 -0
- package/builtin/web-ui/dist/index.html +2 -2
- package/package.json +1 -1
- package/builtin/nodes/control_deadline.md +0 -32
- package/builtin/web-ui/dist/assets/index-D0Tkhqr6.css +0 -1
- package/builtin/web-ui/dist/assets/index-DyhW5chp.js +0 -197
package/bin/lib/ui-server.mjs
CHANGED
|
@@ -74,7 +74,16 @@ import {
|
|
|
74
74
|
import { runNodeScript } from "./pipeline-scripts.mjs";
|
|
75
75
|
import { readFlowSchedule, writeFlowSchedule } from "./schedule-config.mjs";
|
|
76
76
|
import { listScheduleStatuses } from "./scheduler.mjs";
|
|
77
|
-
import {
|
|
77
|
+
import {
|
|
78
|
+
deleteMarketplaceNodePackage,
|
|
79
|
+
installFlowDependency,
|
|
80
|
+
listMarketplaceFlowSnippets,
|
|
81
|
+
listMarketplacePackages,
|
|
82
|
+
publishFlowSnippet,
|
|
83
|
+
publishNodeFromInstance,
|
|
84
|
+
} from "./marketplace.mjs";
|
|
85
|
+
import { buildGitContext, inferGitRepoRootFromWorktree, loadGitWorktree, normalizeGitContext, runGit, unloadGitWorktree } from "./git-worktree.mjs";
|
|
86
|
+
import { createGitLabMergeRequest } from "./gitlab-mr.mjs";
|
|
78
87
|
import {
|
|
79
88
|
authSetupRequired,
|
|
80
89
|
buildClearSessionCookie,
|
|
@@ -439,6 +448,7 @@ function readBody(req) {
|
|
|
439
448
|
const WORKSPACE_FILE_SKIP_DIRS = new Set([
|
|
440
449
|
".git",
|
|
441
450
|
"node_modules",
|
|
451
|
+
"runBuild",
|
|
442
452
|
".next",
|
|
443
453
|
".nuxt",
|
|
444
454
|
".turbo",
|
|
@@ -447,6 +457,11 @@ const WORKSPACE_FILE_SKIP_DIRS = new Set([
|
|
|
447
457
|
"coverage",
|
|
448
458
|
]);
|
|
449
459
|
|
|
460
|
+
const WORKSPACE_FILE_SKIP_FILES = new Set([
|
|
461
|
+
"flow.yaml",
|
|
462
|
+
"workspace.graph.json",
|
|
463
|
+
]);
|
|
464
|
+
|
|
450
465
|
const WORKSPACE_TEXT_EXTS = new Set([
|
|
451
466
|
".md",
|
|
452
467
|
".markdown",
|
|
@@ -510,6 +525,7 @@ function readWorkspaceFilesRecursive(dir, root, depth = 0, maxDepth = 3, budget
|
|
|
510
525
|
children: readWorkspaceFilesRecursive(abs, root, depth + 1, maxDepth, budget),
|
|
511
526
|
});
|
|
512
527
|
} else if (entry.isFile()) {
|
|
528
|
+
if (WORKSPACE_FILE_SKIP_FILES.has(entry.name)) continue;
|
|
513
529
|
const ext = path.extname(entry.name).toLowerCase();
|
|
514
530
|
if (!WORKSPACE_TEXT_EXTS.has(ext)) continue;
|
|
515
531
|
let size = 0;
|
|
@@ -653,6 +669,39 @@ function workspaceSlotValue(slot) {
|
|
|
653
669
|
return "";
|
|
654
670
|
}
|
|
655
671
|
|
|
672
|
+
function workspaceSlotByName(instance, name) {
|
|
673
|
+
const slots = [...(Array.isArray(instance?.input) ? instance.input : []), ...(Array.isArray(instance?.output) ? instance.output : [])];
|
|
674
|
+
return slots.find((slot) => String(slot?.name || "") === String(name || "")) || null;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
function workspaceSetOutputSlot(instance, name, value) {
|
|
678
|
+
const text = String(value ?? "");
|
|
679
|
+
return {
|
|
680
|
+
...(instance || {}),
|
|
681
|
+
output: (Array.isArray(instance?.output) ? instance.output : []).map((slot) => (
|
|
682
|
+
String(slot?.name || "") === String(name || "") ? { ...slot, default: text, value: text } : slot
|
|
683
|
+
)),
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
function workspaceResolvePath(baseCwd, raw) {
|
|
688
|
+
const text = String(raw || "").trim();
|
|
689
|
+
if (!text) return "";
|
|
690
|
+
return path.isAbsolute(text) ? path.resolve(text) : path.resolve(baseCwd, text);
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
function workspaceSanitizeRepoDirName(repoUrl) {
|
|
694
|
+
const raw = String(repoUrl || "").trim().replace(/\.git$/i, "");
|
|
695
|
+
const last = raw.split(/[/:]/).filter(Boolean).pop() || "repo";
|
|
696
|
+
return last.replace(/[^a-zA-Z0-9._-]+/g, "-").replace(/^-+|-+$/g, "") || "repo";
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
function workspaceBoolSlot(instance, name, defaultValue = false) {
|
|
700
|
+
const value = workspaceSlotValue(workspaceSlotByName(instance, name));
|
|
701
|
+
if (!value.trim()) return Boolean(defaultValue);
|
|
702
|
+
return ["true", "1", "yes", "on"].includes(value.trim().toLowerCase());
|
|
703
|
+
}
|
|
704
|
+
|
|
656
705
|
function workspaceInstanceText(instance) {
|
|
657
706
|
const body = String(instance?.body || "").trim();
|
|
658
707
|
if (body) return body;
|
|
@@ -666,10 +715,12 @@ function workspaceDisplayKind(definitionId) {
|
|
|
666
715
|
if (id === "display_markdown") return "markdown";
|
|
667
716
|
if (id === "display_mermaid") return "mermaid";
|
|
668
717
|
if (id === "display_ascii") return "ascii";
|
|
718
|
+
if (id === "display_html") return "html";
|
|
719
|
+
if (id === "display_image") return "image";
|
|
669
720
|
return "";
|
|
670
721
|
}
|
|
671
722
|
|
|
672
|
-
function
|
|
723
|
+
function workspaceRunPlan(graph, runNodeId) {
|
|
673
724
|
const instances = graph?.instances && typeof graph.instances === "object" ? graph.instances : {};
|
|
674
725
|
const edges = Array.isArray(graph?.edges) ? graph.edges : [];
|
|
675
726
|
const target = String(runNodeId || "").trim();
|
|
@@ -685,15 +736,20 @@ function workspaceRunOrder(graph, runNodeId) {
|
|
|
685
736
|
if (!downstream.has(source)) downstream.set(source, []);
|
|
686
737
|
downstream.get(source).push(dest);
|
|
687
738
|
}
|
|
688
|
-
const
|
|
739
|
+
const needed = new Set();
|
|
740
|
+
const pauseNodeIds = new Set();
|
|
689
741
|
const visit = (id) => {
|
|
690
|
-
if (!id ||
|
|
691
|
-
|
|
742
|
+
if (!id || needed.has(id)) return;
|
|
743
|
+
const defId = String(instances[id]?.definitionId || "");
|
|
744
|
+
if (id !== target && defId === "workspace_run") {
|
|
745
|
+
pauseNodeIds.add(id);
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
needed.add(id);
|
|
692
749
|
for (const next of downstream.get(id) || []) visit(next);
|
|
693
750
|
};
|
|
694
751
|
visit(target);
|
|
695
|
-
|
|
696
|
-
const needed = reachable;
|
|
752
|
+
needed.delete(target);
|
|
697
753
|
const indegree = new Map(Array.from(needed).map((id) => [id, 0]));
|
|
698
754
|
for (const id of needed) {
|
|
699
755
|
for (const prev of upstream.get(id) || []) {
|
|
@@ -715,7 +771,7 @@ function workspaceRunOrder(graph, runNodeId) {
|
|
|
715
771
|
if (ordered.length !== needed.size) {
|
|
716
772
|
throw new Error("Workspace run graph contains a cycle");
|
|
717
773
|
}
|
|
718
|
-
return ordered;
|
|
774
|
+
return { order: ordered, pauseNodeIds: Array.from(pauseNodeIds) };
|
|
719
775
|
}
|
|
720
776
|
|
|
721
777
|
function workspaceUpstreamText(graph, nodeId, outputs) {
|
|
@@ -762,14 +818,16 @@ function workspaceUpstreamSkillBlocks(graph, nodeId, outputs) {
|
|
|
762
818
|
function workspaceWriteDisplayContent(instance, content) {
|
|
763
819
|
const next = { ...(instance || {}) };
|
|
764
820
|
const text = String(content || "");
|
|
821
|
+
const kind = workspaceDisplayKind(next.definitionId);
|
|
822
|
+
const primaryName = kind === "image" ? "src" : "content";
|
|
765
823
|
next.body = text;
|
|
766
824
|
next.input = (Array.isArray(next.input) ? next.input : []).map((slot) => (
|
|
767
|
-
String(slot?.name || "") ===
|
|
825
|
+
String(slot?.name || "") === primaryName || String(slot?.type || "") === "text"
|
|
768
826
|
? { ...slot, default: text, value: text }
|
|
769
827
|
: slot
|
|
770
828
|
));
|
|
771
829
|
next.output = (Array.isArray(next.output) ? next.output : []).map((slot) => (
|
|
772
|
-
String(slot?.name || "") ===
|
|
830
|
+
String(slot?.name || "") === primaryName || String(slot?.type || "") === "text"
|
|
773
831
|
? { ...slot, default: text, value: text }
|
|
774
832
|
: slot
|
|
775
833
|
));
|
|
@@ -808,7 +866,7 @@ function workspaceNodePrompt(graph, nodeId, upstreamText, skillsBlock) {
|
|
|
808
866
|
async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts = {}) {
|
|
809
867
|
const graph = normalizeWorkspaceGraphPayload(payload.graph || {});
|
|
810
868
|
const runNodeId = String(payload?.runNodeId || "").trim();
|
|
811
|
-
const order =
|
|
869
|
+
const { order, pauseNodeIds } = workspaceRunPlan(graph, runNodeId);
|
|
812
870
|
const fallbackSelectedSkillKeys = Array.isArray(payload?.selectedSkills)
|
|
813
871
|
? payload.selectedSkills.map((x) => String(x || "").trim()).filter(Boolean)
|
|
814
872
|
: [];
|
|
@@ -880,6 +938,14 @@ async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts =
|
|
|
880
938
|
continue;
|
|
881
939
|
}
|
|
882
940
|
|
|
941
|
+
if (defId === "provide_bool") {
|
|
942
|
+
const raw = workspaceSlotValue(Array.isArray(instance.output) ? instance.output[0] : null) || workspaceInstanceText(instance);
|
|
943
|
+
const content = ["true", "1", "yes", "on"].includes(String(raw || "").trim().toLowerCase()) ? "true" : "false";
|
|
944
|
+
outputs.set(nodeId, content);
|
|
945
|
+
emit({ type: "node-done", nodeId, definitionId: defId });
|
|
946
|
+
continue;
|
|
947
|
+
}
|
|
948
|
+
|
|
883
949
|
if (defId === "provide_file") {
|
|
884
950
|
const fileValue = workspaceSlotValue(Array.isArray(instance.output) ? instance.output[0] : null) || workspaceInstanceText(instance);
|
|
885
951
|
const abs = path.resolve(scopedRoot, fileValue);
|
|
@@ -912,6 +978,182 @@ async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts =
|
|
|
912
978
|
continue;
|
|
913
979
|
}
|
|
914
980
|
|
|
981
|
+
if (defId === "tool_git_checkout") {
|
|
982
|
+
const repoUrl = workspaceSlotValue(workspaceSlotByName(instance, "repoUrl")).trim();
|
|
983
|
+
if (!repoUrl) throw new Error("Git Checkout requires repoUrl");
|
|
984
|
+
const branch = workspaceSlotValue(workspaceSlotByName(instance, "branch")).trim();
|
|
985
|
+
const targetRaw = workspaceSlotValue(workspaceSlotByName(instance, "targetDir")).trim();
|
|
986
|
+
const targetDir = targetRaw
|
|
987
|
+
? workspaceResolvePath(cwd, targetRaw)
|
|
988
|
+
: path.join(scopedRoot, ".workspace", "agentflow", "git-repos", workspaceSanitizeRepoDirName(repoUrl));
|
|
989
|
+
const pullIfExists = workspaceBoolSlot(instance, "pullIfExists", true);
|
|
990
|
+
const includeSubmodules = workspaceBoolSlot(instance, "includeSubmodules", false);
|
|
991
|
+
fs.mkdirSync(path.dirname(targetDir), { recursive: true });
|
|
992
|
+
let changed = false;
|
|
993
|
+
if (fs.existsSync(path.join(targetDir, ".git"))) {
|
|
994
|
+
if (pullIfExists) {
|
|
995
|
+
const fetch = runGit(["fetch", "--all", "--prune"], targetDir);
|
|
996
|
+
if (fetch.status !== 0) throw new Error(`git fetch failed: ${fetch.stderr || fetch.stdout}`);
|
|
997
|
+
if (branch) {
|
|
998
|
+
const checkout = runGit(["checkout", branch], targetDir);
|
|
999
|
+
if (checkout.status !== 0) throw new Error(`git checkout failed: ${checkout.stderr || checkout.stdout}`);
|
|
1000
|
+
}
|
|
1001
|
+
const before = runGit(["rev-parse", "HEAD"], targetDir).stdout.trim();
|
|
1002
|
+
const pull = runGit(["pull", "--ff-only"], targetDir);
|
|
1003
|
+
if (pull.status !== 0) throw new Error(`git pull failed: ${pull.stderr || pull.stdout}`);
|
|
1004
|
+
const after = runGit(["rev-parse", "HEAD"], targetDir).stdout.trim();
|
|
1005
|
+
changed = before !== after;
|
|
1006
|
+
}
|
|
1007
|
+
} else {
|
|
1008
|
+
const args = ["clone"];
|
|
1009
|
+
if (includeSubmodules) args.push("--recurse-submodules");
|
|
1010
|
+
if (branch) args.push("--branch", branch);
|
|
1011
|
+
args.push(repoUrl, targetDir);
|
|
1012
|
+
const clone = runGit(args, cwd);
|
|
1013
|
+
if (clone.status !== 0) throw new Error(`git clone failed: ${clone.stderr || clone.stdout}`);
|
|
1014
|
+
changed = true;
|
|
1015
|
+
}
|
|
1016
|
+
if (includeSubmodules) {
|
|
1017
|
+
const submodule = runGit(["submodule", "update", "--init", "--recursive"], targetDir);
|
|
1018
|
+
if (submodule.status !== 0) throw new Error(`git submodule update failed: ${submodule.stderr || submodule.stdout}`);
|
|
1019
|
+
}
|
|
1020
|
+
const currentBranch = runGit(["rev-parse", "--abbrev-ref", "HEAD"], targetDir).stdout.trim();
|
|
1021
|
+
const commit = runGit(["rev-parse", "HEAD"], targetDir).stdout.trim();
|
|
1022
|
+
const remote = workspaceSlotValue(workspaceSlotByName(instance, "remote")).trim() || "origin";
|
|
1023
|
+
const gitContext = buildGitContext({
|
|
1024
|
+
repoPath: targetDir,
|
|
1025
|
+
branch: currentBranch === "HEAD" ? "DETACHED" : currentBranch,
|
|
1026
|
+
commit,
|
|
1027
|
+
remote,
|
|
1028
|
+
});
|
|
1029
|
+
const previousCwd = cwd;
|
|
1030
|
+
cwd = path.resolve(targetDir);
|
|
1031
|
+
let nextInstance = workspaceSetOutputSlot(instance, "repoPath", targetDir);
|
|
1032
|
+
nextInstance = workspaceSetOutputSlot(nextInstance, "branch", gitContext.branch);
|
|
1033
|
+
nextInstance = workspaceSetOutputSlot(nextInstance, "commit", commit);
|
|
1034
|
+
nextInstance = workspaceSetOutputSlot(nextInstance, "changed", changed ? "true" : "false");
|
|
1035
|
+
nextInstance = workspaceSetOutputSlot(nextInstance, "gitContext", JSON.stringify(gitContext));
|
|
1036
|
+
nextInstance = workspaceSetOutputSlot(nextInstance, "workspaceContext", JSON.stringify({
|
|
1037
|
+
version: 1,
|
|
1038
|
+
label: workspaceSanitizeRepoDirName(repoUrl),
|
|
1039
|
+
cwd,
|
|
1040
|
+
workspaceRoot: cwd,
|
|
1041
|
+
pipelineWorkspace: scopedRoot,
|
|
1042
|
+
previous: { version: 1, label: "workspace", cwd: previousCwd, workspaceRoot: previousCwd, pipelineWorkspace: scopedRoot, previous: null },
|
|
1043
|
+
}));
|
|
1044
|
+
graph.instances[nodeId] = nextInstance;
|
|
1045
|
+
outputs.set(nodeId, targetDir);
|
|
1046
|
+
emit({ type: "graph", nodeId, graph });
|
|
1047
|
+
emit({ type: "node-done", nodeId, definitionId: defId });
|
|
1048
|
+
continue;
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
if (defId === "tool_git_worktree_load") {
|
|
1052
|
+
const gitContext = normalizeGitContext(workspaceSlotValue(workspaceSlotByName(instance, "gitContext")));
|
|
1053
|
+
const repoPath = workspaceResolvePath(cwd, workspaceSlotValue(workspaceSlotByName(instance, "repoPath"))) ||
|
|
1054
|
+
(gitContext?.repoPath ? path.resolve(gitContext.repoPath) : "");
|
|
1055
|
+
if (!repoPath) throw new Error("Load Worktree requires repoPath");
|
|
1056
|
+
const branch = workspaceSlotValue(workspaceSlotByName(instance, "branch")).trim();
|
|
1057
|
+
const rawWorktreePath = workspaceSlotValue(workspaceSlotByName(instance, "worktreePath")).trim();
|
|
1058
|
+
const worktreePath = rawWorktreePath ? workspaceResolvePath(cwd, rawWorktreePath) : (gitContext?.worktreePath ? path.resolve(gitContext.worktreePath) : "");
|
|
1059
|
+
const previousCwd = cwd;
|
|
1060
|
+
const result = loadGitWorktree({ repoPath, branch, worktreePath, pipelineWorkspace: scopedRoot });
|
|
1061
|
+
const outGitContext = buildGitContext({
|
|
1062
|
+
repoPath: result.repoRoot,
|
|
1063
|
+
worktreePath: result.worktreePath,
|
|
1064
|
+
branch: result.branch,
|
|
1065
|
+
commit: result.commit,
|
|
1066
|
+
remote: gitContext?.remote || "origin",
|
|
1067
|
+
remoteUrl: gitContext?.remoteUrl || "",
|
|
1068
|
+
});
|
|
1069
|
+
cwd = result.worktreePath;
|
|
1070
|
+
let nextInstance = workspaceSetOutputSlot(instance, "worktreePath", result.worktreePath);
|
|
1071
|
+
nextInstance = workspaceSetOutputSlot(nextInstance, "branch", result.branch);
|
|
1072
|
+
nextInstance = workspaceSetOutputSlot(nextInstance, "commit", result.commit);
|
|
1073
|
+
nextInstance = workspaceSetOutputSlot(nextInstance, "gitContext", JSON.stringify(outGitContext));
|
|
1074
|
+
nextInstance = workspaceSetOutputSlot(nextInstance, "workspaceContext", JSON.stringify({
|
|
1075
|
+
version: 1,
|
|
1076
|
+
label: result.branch === "DETACHED" ? `worktree:${result.commit.slice(0, 8)}` : `worktree:${result.branch}`,
|
|
1077
|
+
cwd: result.worktreePath,
|
|
1078
|
+
workspaceRoot: result.worktreePath,
|
|
1079
|
+
pipelineWorkspace: scopedRoot,
|
|
1080
|
+
previous: { version: 1, label: "workspace", cwd: previousCwd, workspaceRoot: previousCwd, pipelineWorkspace: scopedRoot, previous: null },
|
|
1081
|
+
}));
|
|
1082
|
+
graph.instances[nodeId] = nextInstance;
|
|
1083
|
+
outputs.set(nodeId, result.worktreePath);
|
|
1084
|
+
emit({ type: "graph", nodeId, graph });
|
|
1085
|
+
emit({ type: "node-done", nodeId, definitionId: defId });
|
|
1086
|
+
continue;
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
if (defId === "tool_git_worktree_unload") {
|
|
1090
|
+
const gitContext = normalizeGitContext(workspaceSlotValue(workspaceSlotByName(instance, "gitContext")));
|
|
1091
|
+
const workspaceContext = parseJsonText(workspaceSlotValue(workspaceSlotByName(instance, "workspaceContext")), null);
|
|
1092
|
+
const contextCwd = workspaceContext?.cwd ? path.resolve(String(workspaceContext.cwd)) : cwd;
|
|
1093
|
+
const worktreePath = workspaceResolvePath(contextCwd, workspaceSlotValue(workspaceSlotByName(instance, "worktreePath"))) ||
|
|
1094
|
+
(gitContext?.worktreePath ? path.resolve(gitContext.worktreePath) : "") ||
|
|
1095
|
+
contextCwd;
|
|
1096
|
+
const repoPath = workspaceResolvePath(contextCwd, workspaceSlotValue(workspaceSlotByName(instance, "repoPath"))) ||
|
|
1097
|
+
(gitContext?.repoPath ? path.resolve(gitContext.repoPath) : "") ||
|
|
1098
|
+
inferGitRepoRootFromWorktree(worktreePath);
|
|
1099
|
+
const force = ["true", "1", "yes", "on"].includes(workspaceSlotValue(workspaceSlotByName(instance, "force")).trim().toLowerCase());
|
|
1100
|
+
const pruneRaw = workspaceSlotValue(workspaceSlotByName(instance, "prune")).trim().toLowerCase();
|
|
1101
|
+
const prune = pruneRaw !== "false";
|
|
1102
|
+
const result = unloadGitWorktree({ repoPath, worktreePath, force, prune });
|
|
1103
|
+
const previousContext = workspaceContext?.previous && typeof workspaceContext.previous === "object" ? workspaceContext.previous : null;
|
|
1104
|
+
cwd = previousContext?.cwd ? path.resolve(String(previousContext.cwd)) : scopedRoot;
|
|
1105
|
+
let nextInstance = workspaceSetOutputSlot(instance, "removed", "true");
|
|
1106
|
+
nextInstance = workspaceSetOutputSlot(nextInstance, "message", result.message);
|
|
1107
|
+
nextInstance = workspaceSetOutputSlot(nextInstance, "workspaceContext", JSON.stringify(previousContext || {
|
|
1108
|
+
version: 1,
|
|
1109
|
+
label: "workspace",
|
|
1110
|
+
cwd,
|
|
1111
|
+
workspaceRoot: cwd,
|
|
1112
|
+
pipelineWorkspace: scopedRoot,
|
|
1113
|
+
previous: null,
|
|
1114
|
+
}));
|
|
1115
|
+
graph.instances[nodeId] = nextInstance;
|
|
1116
|
+
outputs.set(nodeId, result.message);
|
|
1117
|
+
emit({ type: "graph", nodeId, graph });
|
|
1118
|
+
emit({ type: "node-done", nodeId, definitionId: defId });
|
|
1119
|
+
continue;
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
if (defId === "tool_gitlab_create_mr") {
|
|
1123
|
+
const gitContext = normalizeGitContext(workspaceSlotValue(workspaceSlotByName(instance, "gitContext")));
|
|
1124
|
+
const repoPath = workspaceResolvePath(cwd, workspaceSlotValue(workspaceSlotByName(instance, "repoPath")));
|
|
1125
|
+
const result = await createGitLabMergeRequest({
|
|
1126
|
+
gitContext,
|
|
1127
|
+
workspaceCwd: cwd,
|
|
1128
|
+
repoPath,
|
|
1129
|
+
sourceBranch: workspaceSlotValue(workspaceSlotByName(instance, "sourceBranch")),
|
|
1130
|
+
targetBranch: workspaceSlotValue(workspaceSlotByName(instance, "targetBranch")),
|
|
1131
|
+
title: workspaceSlotValue(workspaceSlotByName(instance, "title")),
|
|
1132
|
+
description: workspaceSlotValue(workspaceSlotByName(instance, "description")),
|
|
1133
|
+
draft: workspaceSlotValue(workspaceSlotByName(instance, "draft")),
|
|
1134
|
+
labels: workspaceSlotValue(workspaceSlotByName(instance, "labels")),
|
|
1135
|
+
push: workspaceSlotValue(workspaceSlotByName(instance, "push")),
|
|
1136
|
+
remote: workspaceSlotValue(workspaceSlotByName(instance, "remote")),
|
|
1137
|
+
tokenEnv: workspaceSlotValue(workspaceSlotByName(instance, "tokenEnv")),
|
|
1138
|
+
gitlabApiBase: workspaceSlotValue(workspaceSlotByName(instance, "gitlabApiBase")),
|
|
1139
|
+
removeSourceBranch: workspaceSlotValue(workspaceSlotByName(instance, "removeSourceBranch")),
|
|
1140
|
+
squash: workspaceSlotValue(workspaceSlotByName(instance, "squash")),
|
|
1141
|
+
}, runtimeEnvForUser(userCtx));
|
|
1142
|
+
let nextInstance = workspaceSetOutputSlot(instance, "mrUrl", result.mrUrl);
|
|
1143
|
+
nextInstance = workspaceSetOutputSlot(nextInstance, "created", result.created ? "true" : "false");
|
|
1144
|
+
nextInstance = workspaceSetOutputSlot(nextInstance, "mrIid", result.mrIid ?? "");
|
|
1145
|
+
nextInstance = workspaceSetOutputSlot(nextInstance, "projectId", result.projectId ?? "");
|
|
1146
|
+
nextInstance = workspaceSetOutputSlot(nextInstance, "sourceBranch", result.sourceBranch ?? "");
|
|
1147
|
+
nextInstance = workspaceSetOutputSlot(nextInstance, "targetBranch", result.targetBranch ?? "");
|
|
1148
|
+
nextInstance = workspaceSetOutputSlot(nextInstance, "title", result.title ?? "");
|
|
1149
|
+
nextInstance = workspaceSetOutputSlot(nextInstance, "message", result.message ?? "");
|
|
1150
|
+
graph.instances[nodeId] = nextInstance;
|
|
1151
|
+
outputs.set(nodeId, result.mrUrl);
|
|
1152
|
+
emit({ type: "graph", nodeId, graph });
|
|
1153
|
+
emit({ type: "node-done", nodeId, definitionId: defId });
|
|
1154
|
+
continue;
|
|
1155
|
+
}
|
|
1156
|
+
|
|
915
1157
|
const upstreamText = workspaceUpstreamText(graph, nodeId, outputs);
|
|
916
1158
|
const body = String(instance.body || "").trim();
|
|
917
1159
|
if (defId === "agent_subAgent" && !body && !String(upstreamText || "").trim()) {
|
|
@@ -956,8 +1198,11 @@ async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts =
|
|
|
956
1198
|
if (updatedDisplays.length) emit({ type: "graph", nodeId, displayNodeIds: updatedDisplays, graph });
|
|
957
1199
|
emit({ type: "node-done", nodeId, definitionId: defId });
|
|
958
1200
|
}
|
|
1201
|
+
if (pauseNodeIds.length > 0) {
|
|
1202
|
+
emit({ type: "paused", nodeIds: pauseNodeIds, message: `Workspace run paused at ${pauseNodeIds.join(", ")}` });
|
|
1203
|
+
}
|
|
959
1204
|
graph.updatedAt = new Date().toISOString();
|
|
960
|
-
return { graph, events, order };
|
|
1205
|
+
return { graph, events, order, pauseNodeIds };
|
|
961
1206
|
}
|
|
962
1207
|
|
|
963
1208
|
function isTransientAgentNetworkError(err) {
|
|
@@ -1609,7 +1854,7 @@ export function startUiServer({
|
|
|
1609
1854
|
try {
|
|
1610
1855
|
const result = await runWorkspaceGraph(root, scoped.root, payload, userCtx, { onEvent: writeEvent });
|
|
1611
1856
|
fs.writeFileSync(graphPath, JSON.stringify(result.graph, null, 2) + "\n", "utf-8");
|
|
1612
|
-
writeEvent({ type: "done", ok: true, path: graphPath, graph: result.graph, order: result.order });
|
|
1857
|
+
writeEvent({ type: "done", ok: true, path: graphPath, graph: result.graph, order: result.order, pauseNodeIds: result.pauseNodeIds || [] });
|
|
1613
1858
|
res.end();
|
|
1614
1859
|
} catch (e) {
|
|
1615
1860
|
writeEvent({ type: "error", error: (e && e.message) || String(e) });
|
|
@@ -2287,6 +2532,15 @@ export function startUiServer({
|
|
|
2287
2532
|
return;
|
|
2288
2533
|
}
|
|
2289
2534
|
|
|
2535
|
+
if (req.method === "GET" && url.pathname === "/api/marketplace/flow-snippets") {
|
|
2536
|
+
try {
|
|
2537
|
+
json(res, 200, listMarketplaceFlowSnippets(root));
|
|
2538
|
+
} catch (e) {
|
|
2539
|
+
json(res, 500, { error: (e && e.message) || String(e) });
|
|
2540
|
+
}
|
|
2541
|
+
return;
|
|
2542
|
+
}
|
|
2543
|
+
|
|
2290
2544
|
if (req.method === "DELETE" && url.pathname === "/api/marketplace/node") {
|
|
2291
2545
|
const id = url.searchParams.get("id") || "";
|
|
2292
2546
|
const version = url.searchParams.get("version") || "";
|
|
@@ -2365,6 +2619,23 @@ export function startUiServer({
|
|
|
2365
2619
|
return;
|
|
2366
2620
|
}
|
|
2367
2621
|
|
|
2622
|
+
if (req.method === "POST" && url.pathname === "/api/marketplace/publish-flow-snippet") {
|
|
2623
|
+
let payload;
|
|
2624
|
+
try {
|
|
2625
|
+
payload = JSON.parse(await readBody(req));
|
|
2626
|
+
} catch {
|
|
2627
|
+
json(res, 400, { error: "Invalid JSON body" });
|
|
2628
|
+
return;
|
|
2629
|
+
}
|
|
2630
|
+
try {
|
|
2631
|
+
const result = publishFlowSnippet(root, payload || {});
|
|
2632
|
+
json(res, result.ok ? 200 : 400, result);
|
|
2633
|
+
} catch (e) {
|
|
2634
|
+
json(res, 500, { ok: false, error: (e && e.message) || String(e) });
|
|
2635
|
+
}
|
|
2636
|
+
return;
|
|
2637
|
+
}
|
|
2638
|
+
|
|
2368
2639
|
if (req.method === "GET" && url.pathname === "/api/flow") {
|
|
2369
2640
|
const flowId = url.searchParams.get("flowId");
|
|
2370
2641
|
const flowSource = url.searchParams.get("flowSource") || "user";
|
|
@@ -112,6 +112,31 @@ function marketplaceRuntimeCommand(marketplaceNode, resolvedInputs, resolvedOutp
|
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
function normalizePromptImages(images) {
|
|
116
|
+
if (!Array.isArray(images)) return [];
|
|
117
|
+
return images
|
|
118
|
+
.filter((item) => item && typeof item === "object")
|
|
119
|
+
.map((item, index) => ({
|
|
120
|
+
label: String(item.label || `image ${index + 1}`),
|
|
121
|
+
name: String(item.name || `image-${index + 1}`),
|
|
122
|
+
mimeType: String(item.mimeType || item.type || "image/png"),
|
|
123
|
+
dataUrl: String(item.dataUrl || item.data || ""),
|
|
124
|
+
}))
|
|
125
|
+
.filter((item) => item.dataUrl.startsWith("data:image/"));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function renderImagesForPrompt(images) {
|
|
129
|
+
const list = normalizePromptImages(images);
|
|
130
|
+
if (list.length === 0) return "";
|
|
131
|
+
const blocks = list.map((item) => [
|
|
132
|
+
`### [${item.label}]`,
|
|
133
|
+
`name: ${item.name}`,
|
|
134
|
+
`mimeType: ${item.mimeType}`,
|
|
135
|
+
`dataUrl: ${item.dataUrl}`,
|
|
136
|
+
].join("\n"));
|
|
137
|
+
return `## 图片附件\n\n${blocks.join("\n\n")}`;
|
|
138
|
+
}
|
|
139
|
+
|
|
115
140
|
/**
|
|
116
141
|
* 执行占位符替换,组装 prompt 并写入 intermediate 文件(文件名带 _execId)。
|
|
117
142
|
* @param {number} [execId] - 本轮 execId,缺省则从 memory 读取
|
|
@@ -153,6 +178,7 @@ export function buildNodePrompt(workspaceRoot, flowName, uuid, instanceId, execI
|
|
|
153
178
|
inst?.script != null
|
|
154
179
|
? String(inst.script || "").trim()
|
|
155
180
|
: "";
|
|
181
|
+
const imagePrompt = renderImagesForPrompt(inst?.images);
|
|
156
182
|
|
|
157
183
|
const { resolvedInputs = {}, resolvedOutputs = {}, systemPrompt = "" } = data;
|
|
158
184
|
const workspaceContext = normalizeWorkspaceContext(opts.workspaceContext || resolvedInputs.workspaceContext, workspaceRoot, flowName, { flowDir });
|
|
@@ -197,7 +223,7 @@ ${contextBlocks.join("\n\n")}
|
|
|
197
223
|
|
|
198
224
|
## 执行任务
|
|
199
225
|
|
|
200
|
-
${taskBody || "(无)"}
|
|
226
|
+
${[taskBody || "(无)", imagePrompt].filter((x) => x && String(x).trim()).join("\n\n")}
|
|
201
227
|
`;
|
|
202
228
|
|
|
203
229
|
try {
|