@fieldwangai/agentflow 0.1.78 → 0.1.80

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.
@@ -2029,6 +2029,17 @@ function displayShareOutputUrl(shareId, baseUrl = "") {
2029
2029
  }
2030
2030
  }
2031
2031
 
2032
+ function requestPublicBaseUrl(req) {
2033
+ const origin = String(req?.headers?.origin || "").trim();
2034
+ if (/^https?:\/\//i.test(origin)) return origin;
2035
+ const forwardedHost = String(req?.headers?.["x-forwarded-host"] || "").split(",")[0].trim();
2036
+ const host = forwardedHost || String(req?.headers?.host || "").trim();
2037
+ if (!host) return "";
2038
+ const forwardedProto = String(req?.headers?.["x-forwarded-proto"] || "").split(",")[0].trim();
2039
+ const proto = /^https?$/i.test(forwardedProto) ? forwardedProto.toLowerCase() : "http";
2040
+ return `${proto}://${host}`;
2041
+ }
2042
+
2032
2043
  function normalizeRunEnvKey(key) {
2033
2044
  const text = String(key || "").trim();
2034
2045
  return /^[A-Za-z_][A-Za-z0-9_]*$/.test(text) ? text : "";
@@ -4677,6 +4688,18 @@ async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts =
4677
4688
  }
4678
4689
  return "";
4679
4690
  };
4691
+ const recordNodeOutput = (nodeId, content) => {
4692
+ outputs.set(nodeId, content);
4693
+ };
4694
+ const propagateNodeOutputDisplays = (nodeId, content, { emitGraph = false } = {}) => {
4695
+ const updatedDisplays = workspaceUpdateDirectDisplays(graph, nodeId, content, outputs, scopedRoot);
4696
+ if (emitGraph && updatedDisplays.length) emit({ type: "graph", nodeId, displayNodeIds: updatedDisplays, graph });
4697
+ return updatedDisplays;
4698
+ };
4699
+ const publishNodeOutput = (nodeId, content, options = {}) => {
4700
+ recordNodeOutput(nodeId, content);
4701
+ return propagateNodeOutputDisplays(nodeId, content, options);
4702
+ };
4680
4703
 
4681
4704
  try {
4682
4705
  for (const nodeId of order) {
@@ -4710,9 +4733,8 @@ async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts =
4710
4733
  : slot
4711
4734
  )),
4712
4735
  };
4713
- outputs.set(nodeId, skillsBlock);
4714
- workspaceUpdateDirectDisplays(graph, nodeId, skillsBlock, outputs, scopedRoot);
4715
- emit({ type: "graph", nodeId, graph });
4736
+ const updatedDisplays = publishNodeOutput(nodeId, skillsBlock);
4737
+ emit({ type: "graph", nodeId, displayNodeIds: updatedDisplays, graph });
4716
4738
  emit({ type: "node-done", nodeId, definitionId: defId });
4717
4739
  continue;
4718
4740
  }
@@ -4730,9 +4752,8 @@ async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts =
4730
4752
  : slot
4731
4753
  )),
4732
4754
  };
4733
- outputs.set(nodeId, mcpBlock);
4734
- workspaceUpdateDirectDisplays(graph, nodeId, mcpBlock, outputs, scopedRoot);
4735
- emit({ type: "graph", nodeId, graph });
4755
+ const updatedDisplays = publishNodeOutput(nodeId, mcpBlock);
4756
+ emit({ type: "graph", nodeId, displayNodeIds: updatedDisplays, graph });
4736
4757
  emit({ type: "node-done", nodeId, definitionId: defId });
4737
4758
  continue;
4738
4759
  }
@@ -4740,8 +4761,8 @@ async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts =
4740
4761
  if (workspaceDisplayKind(defId)) {
4741
4762
  const content = workspaceUpstreamText(graph, nodeId, outputs, scopedRoot);
4742
4763
  graph.instances[nodeId] = workspaceWriteDisplayContent(instance, content);
4743
- outputs.set(nodeId, content);
4744
- emit({ type: "graph", nodeId, graph });
4764
+ const updatedDisplays = publishNodeOutput(nodeId, content);
4765
+ emit({ type: "graph", nodeId, displayNodeIds: updatedDisplays, graph });
4745
4766
  emit({ type: "node-done", nodeId, definitionId: defId });
4746
4767
  continue;
4747
4768
  }
@@ -4757,7 +4778,7 @@ async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts =
4757
4778
  const boolValue = parseBool(rawValue);
4758
4779
  const branch = boolValue ? "true" : "false";
4759
4780
  controlBranches.set(nodeId, branch);
4760
- outputs.set(nodeId, branch);
4781
+ publishNodeOutput(nodeId, branch, { emitGraph: true });
4761
4782
  emit({ type: "status", nodeId, line: `control_if branch: ${branch}` });
4762
4783
  emit({ type: "node-done", nodeId, definitionId: defId, branch });
4763
4784
  continue;
@@ -4765,7 +4786,7 @@ async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts =
4765
4786
 
4766
4787
  if (defId === "provide_str" || defId === "provide_password") {
4767
4788
  const content = workspaceInstanceText(instance);
4768
- outputs.set(nodeId, content);
4789
+ publishNodeOutput(nodeId, content, { emitGraph: true });
4769
4790
  emit({ type: "node-done", nodeId, definitionId: defId });
4770
4791
  continue;
4771
4792
  }
@@ -4773,7 +4794,7 @@ async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts =
4773
4794
  if (defId === "provide_bool") {
4774
4795
  const raw = workspaceSlotValue(Array.isArray(instance.output) ? instance.output[0] : null) || workspaceInstanceText(instance);
4775
4796
  const content = ["true", "1", "yes", "on"].includes(String(raw || "").trim().toLowerCase()) ? "true" : "false";
4776
- outputs.set(nodeId, content);
4797
+ publishNodeOutput(nodeId, content, { emitGraph: true });
4777
4798
  emit({ type: "node-done", nodeId, definitionId: defId });
4778
4799
  continue;
4779
4800
  }
@@ -4785,7 +4806,7 @@ async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts =
4785
4806
  throw new Error(`Workspace file is outside root: ${fileValue}`);
4786
4807
  }
4787
4808
  const content = fs.existsSync(abs) && fs.statSync(abs).isFile() ? fs.readFileSync(abs, "utf-8") : fileValue;
4788
- outputs.set(nodeId, content);
4809
+ publishNodeOutput(nodeId, content, { emitGraph: true });
4789
4810
  emit({ type: "node-done", nodeId, definitionId: defId });
4790
4811
  continue;
4791
4812
  }
@@ -4803,9 +4824,9 @@ async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts =
4803
4824
  let nextInstance = workspaceSetOutputSlot(instance, "keys", keys.join(", "));
4804
4825
  nextInstance = workspaceSetOutputSlot(nextInstance, "count", String(keys.length));
4805
4826
  graph.instances[nodeId] = nextInstance;
4806
- outputs.set(nodeId, keys.join(", "));
4827
+ const updatedDisplays = publishNodeOutput(nodeId, keys.join(", "));
4807
4828
  emit({ type: "status", nodeId, line: `Set run env: ${keys.join(", ")}`, envKeys: keys });
4808
- emit({ type: "graph", nodeId, graph });
4829
+ emit({ type: "graph", nodeId, displayNodeIds: updatedDisplays, graph });
4809
4830
  emit({ type: "node-done", nodeId, definitionId: defId });
4810
4831
  continue;
4811
4832
  }
@@ -4818,14 +4839,14 @@ async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts =
4818
4839
  const candidate = workspaceSlotValue(pathSlot) || workspaceInstanceText(instance) || inputText;
4819
4840
  const abs = candidate ? path.resolve(scopedRoot, candidate) : scopedRoot;
4820
4841
  if (fs.existsSync(abs) && fs.statSync(abs).isDirectory()) cwd = abs;
4821
- outputs.set(nodeId, cwd);
4842
+ publishNodeOutput(nodeId, cwd, { emitGraph: true });
4822
4843
  emit({ type: "node-done", nodeId, definitionId: defId });
4823
4844
  continue;
4824
4845
  }
4825
4846
 
4826
4847
  if (defId === "control_user_workspace") {
4827
4848
  cwd = path.resolve(os.homedir());
4828
- outputs.set(nodeId, cwd);
4849
+ publishNodeOutput(nodeId, cwd, { emitGraph: true });
4829
4850
  emit({ type: "node-done", nodeId, definitionId: defId });
4830
4851
  continue;
4831
4852
  }
@@ -4894,8 +4915,8 @@ async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts =
4894
4915
  previous: { version: 1, label: "workspace", cwd: previousCwd, workspaceRoot: previousCwd, pipelineWorkspace: scopedRoot, previous: null },
4895
4916
  }));
4896
4917
  graph.instances[nodeId] = nextInstance;
4897
- outputs.set(nodeId, targetDir);
4898
- emit({ type: "graph", nodeId, graph });
4918
+ const updatedDisplays = publishNodeOutput(nodeId, targetDir);
4919
+ emit({ type: "graph", nodeId, displayNodeIds: updatedDisplays, graph });
4899
4920
  emit({ type: "node-done", nodeId, definitionId: defId });
4900
4921
  continue;
4901
4922
  }
@@ -4947,8 +4968,8 @@ async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts =
4947
4968
  previous: { version: 1, label: "workspace", cwd: previousCwd, workspaceRoot: previousCwd, pipelineWorkspace: scopedRoot, previous: null },
4948
4969
  }));
4949
4970
  graph.instances[nodeId] = nextInstance;
4950
- outputs.set(nodeId, result.worktreePath);
4951
- emit({ type: "graph", nodeId, graph });
4971
+ const updatedDisplays = publishNodeOutput(nodeId, result.worktreePath);
4972
+ emit({ type: "graph", nodeId, displayNodeIds: updatedDisplays, graph });
4952
4973
  emit({ type: "node-done", nodeId, definitionId: defId });
4953
4974
  continue;
4954
4975
  }
@@ -4981,8 +5002,8 @@ async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts =
4981
5002
  previous: null,
4982
5003
  }));
4983
5004
  graph.instances[nodeId] = nextInstance;
4984
- outputs.set(nodeId, result.message);
4985
- emit({ type: "graph", nodeId, graph });
5005
+ const updatedDisplays = publishNodeOutput(nodeId, result.message);
5006
+ emit({ type: "graph", nodeId, displayNodeIds: updatedDisplays, graph });
4986
5007
  emit({ type: "node-done", nodeId, definitionId: defId });
4987
5008
  continue;
4988
5009
  }
@@ -5016,8 +5037,8 @@ async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts =
5016
5037
  nextInstance = workspaceSetOutputSlot(nextInstance, "title", result.title ?? "");
5017
5038
  nextInstance = workspaceSetOutputSlot(nextInstance, "message", result.message ?? "");
5018
5039
  graph.instances[nodeId] = nextInstance;
5019
- outputs.set(nodeId, result.mrUrl);
5020
- emit({ type: "graph", nodeId, graph });
5040
+ const updatedDisplays = publishNodeOutput(nodeId, result.mrUrl);
5041
+ emit({ type: "graph", nodeId, displayNodeIds: updatedDisplays, graph });
5021
5042
  emit({ type: "node-done", nodeId, definitionId: defId });
5022
5043
  continue;
5023
5044
  }
@@ -5043,8 +5064,8 @@ async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts =
5043
5064
  nextInstance = workspaceSetOutputSlot(nextInstance, "message", result.message);
5044
5065
  nextInstance = workspaceSetOutputSlot(nextInstance, "response", JSON.stringify(result.response || {}));
5045
5066
  graph.instances[nodeId] = nextInstance;
5046
- outputs.set(nodeId, result.message);
5047
- emit({ type: "graph", nodeId, graph });
5067
+ const updatedDisplays = publishNodeOutput(nodeId, result.message);
5068
+ emit({ type: "graph", nodeId, displayNodeIds: updatedDisplays, graph });
5048
5069
  emit({ type: "node-done", nodeId, definitionId: defId });
5049
5070
  continue;
5050
5071
  }
@@ -5064,6 +5085,8 @@ async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts =
5064
5085
  env.AGENTFLOW_PUBLIC_BASE_URL ||
5065
5086
  env.AGENTFLOW_BASE_URL ||
5066
5087
  env.PUBLIC_BASE_URL ||
5088
+ payload.requestBaseUrl ||
5089
+ payload.requestOrigin ||
5067
5090
  "";
5068
5091
 
5069
5092
  const graphPath = workspaceGraphPath(scopedRoot);
@@ -5089,8 +5112,8 @@ async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts =
5089
5112
  nextInstance = workspaceSetOutputSlot(nextInstance, "shareId", share.id);
5090
5113
  nextInstance = workspaceSetOutputSlot(nextInstance, "expiresAt", share.expiresAt);
5091
5114
  graph.instances[nodeId] = nextInstance;
5092
- outputs.set(nodeId, url);
5093
- emit({ type: "graph", nodeId, graph, displayNodeIds: nodeIds });
5115
+ const updatedDisplays = publishNodeOutput(nodeId, url);
5116
+ emit({ type: "graph", nodeId, graph, displayNodeIds: [...nodeIds, ...updatedDisplays] });
5094
5117
  emit({ type: "node-done", nodeId, definitionId: defId });
5095
5118
  continue;
5096
5119
  }
@@ -5121,7 +5144,7 @@ async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts =
5121
5144
  });
5122
5145
  const normalizedAgentOutput = workspacePublishAgentOutputFiles(workspaceStructuredAgentOutput(content), runPackage);
5123
5146
  const resultContent = normalizedAgentOutput.result || content;
5124
- outputs.set(nodeId, resultContent);
5147
+ recordNodeOutput(nodeId, resultContent);
5125
5148
  const slotUpdate = workspaceApplyAgentOutputSlots(instance, normalizedAgentOutput);
5126
5149
  if (slotUpdate.changed) graph.instances[nodeId] = slotUpdate.instance;
5127
5150
  const implementationUpdate = await workspaceTryPersistNodeImplementation(scopedRoot, graph, nodeId, {
@@ -5135,7 +5158,7 @@ async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts =
5135
5158
  onActiveChild: opts.onActiveChild,
5136
5159
  });
5137
5160
  if (implementationUpdate.changed) graph.instances[nodeId] = implementationUpdate.instance;
5138
- const updatedDisplays = workspaceUpdateDirectDisplays(graph, nodeId, resultContent, outputs, scopedRoot);
5161
+ const updatedDisplays = propagateNodeOutputDisplays(nodeId, resultContent);
5139
5162
  if (slotUpdate.changed || implementationUpdate.changed || updatedDisplays.length) emit({ type: "graph", nodeId, displayNodeIds: updatedDisplays, graph });
5140
5163
  emit({ type: "node-done", nodeId, definitionId: defId });
5141
5164
  continue;
@@ -5258,7 +5281,7 @@ async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts =
5258
5281
  }
5259
5282
  const normalizedAgentOutput = workspacePublishAgentOutputFiles(workspaceStructuredAgentOutput(content), runPackage);
5260
5283
  const resultContent = normalizedAgentOutput.result || content;
5261
- outputs.set(nodeId, resultContent);
5284
+ recordNodeOutput(nodeId, resultContent);
5262
5285
  const slotUpdate = workspaceApplyAgentOutputSlots(instance, normalizedAgentOutput);
5263
5286
  if (slotUpdate.changed) graph.instances[nodeId] = slotUpdate.instance;
5264
5287
  const implementationUpdate = await workspaceTryPersistNodeImplementation(scopedRoot, graph, nodeId, {
@@ -5273,7 +5296,7 @@ async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts =
5273
5296
  onActiveChild: opts.onActiveChild,
5274
5297
  });
5275
5298
  if (implementationUpdate.changed) graph.instances[nodeId] = implementationUpdate.instance;
5276
- const updatedDisplays = workspaceUpdateDirectDisplays(graph, nodeId, resultContent, outputs, scopedRoot);
5299
+ const updatedDisplays = propagateNodeOutputDisplays(nodeId, resultContent);
5277
5300
  if (slotUpdate.changed || implementationUpdate.changed || updatedDisplays.length) emit({ type: "graph", nodeId, displayNodeIds: updatedDisplays, graph });
5278
5301
  emit({ type: "node-done", nodeId, definitionId: defId });
5279
5302
  }
@@ -6777,6 +6800,7 @@ export function startUiServer({
6777
6800
  };
6778
6801
  if (wantsStream) {
6779
6802
  const graphPath = workspaceGraphPath(scoped.root);
6803
+ const runPayload = { ...payload, requestBaseUrl: requestPublicBaseUrl(req) };
6780
6804
  res.writeHead(200, {
6781
6805
  "Content-Type": "application/x-ndjson; charset=utf-8",
6782
6806
  "Cache-Control": "no-cache",
@@ -6786,7 +6810,7 @@ export function startUiServer({
6786
6810
  try { res.write(JSON.stringify(event) + "\n"); } catch (_) {}
6787
6811
  };
6788
6812
  try {
6789
- const result = await runWorkspaceGraph(root, scoped.root, payload, userCtx, {
6813
+ const result = await runWorkspaceGraph(root, scoped.root, runPayload, userCtx, {
6790
6814
  onEvent: writeEvent,
6791
6815
  signal: controller.signal,
6792
6816
  onActiveChild: setActiveChild,
@@ -6825,7 +6849,7 @@ export function startUiServer({
6825
6849
  return;
6826
6850
  }
6827
6851
  try {
6828
- const result = await runWorkspaceGraph(root, scoped.root, payload, userCtx, {
6852
+ const result = await runWorkspaceGraph(root, scoped.root, { ...payload, requestBaseUrl: requestPublicBaseUrl(req) }, userCtx, {
6829
6853
  signal: controller.signal,
6830
6854
  onActiveChild: setActiveChild,
6831
6855
  });
@@ -9,22 +9,22 @@ input:
9
9
  - type: text
10
10
  name: title
11
11
  default: ""
12
- description: "分享页标题;为空时使用 AgentFlow Display。"
12
+ description: "可选。分享页标题;只影响打开分享页后的页面标题,不影响输出 URL。为空时使用 AgentFlow Display。"
13
13
  showOnNode: true
14
14
  - type: text
15
15
  name: layout
16
16
  default: "single"
17
- description: "分享布局:single、gallery、slides、document、canvas。"
18
- showOnNode: true
17
+ description: "可选。分享页布局:single、gallery、slides、document、canvas。通常保持默认 single。"
18
+ showOnNode: false
19
19
  - type: text
20
20
  name: nodeIds
21
21
  default: ""
22
- description: "可选。逗号或空格分隔的 Display 节点 ID;为空时自动使用连接到本节点的上游 Display 节点。"
22
+ description: "可选。逗号或空格分隔的 Display 节点 ID;为空时自动分享连接到本节点的上游 Display 节点。"
23
23
  showOnNode: false
24
24
  - type: text
25
25
  name: baseUrl
26
26
  default: ""
27
- description: "可选。输出绝对链接的站点地址,例如 https://agentflow.example.com;为空时输出 /display/<id>。"
27
+ description: "可选。分享站点地址,例如 https://agentflow.example.com;为空时优先使用环境变量,其次使用当前访问地址。"
28
28
  showOnNode: false
29
29
  output:
30
30
  - type: node
@@ -43,4 +43,4 @@ output:
43
43
  default: ""
44
44
  showOnNode: false
45
45
  ---
46
- Create a share link for connected Display nodes.
46
+ Create a share link for connected Display nodes. Connect a Display node to this node, optionally set title, and use the url output.