dynworkflow 0.1.2__tar.gz → 0.1.3__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: dynworkflow
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: Dynamic Workflow Library for Alkaid0
5
5
  Author: cxykevin
6
6
  Author-email: cxykevin <cxykevin@yeah.net>
@@ -65,7 +65,7 @@ flow.execute(summarize())
65
65
 
66
66
  缓存默认启用。可以使用 `Flow(..., cache=False)` 关闭缓存。缓存文件位于 `.alkaid0/workflow.db`;设置 `ALKAID0_WORKFLOW_SESSION_ID` 可以隔离不同会话。
67
67
 
68
- 可以通过 `Flow(..., report=True)` 或环境变量 `ALKAID0_WORKFLOW_REPORT=1` 开启 JSONL 状态上报。`Flow.run()` 会自动开启上报。事件包括 `graph`、`node`、`agent`、`agents_start`、`node_code` 和 `node_log`。
68
+ 可以通过 `Flow(..., report=True)` 或环境变量 `ALKAID0_WORKFLOW_REPORT=1` 开启 JSONL 状态上报。`Flow.run()` 会自动开启上报。事件包括 `graph`、`node`、`node_result`、`agent`、`agents_start`、`node_code` 和 `node_log`。
69
69
 
70
70
  ## 示例
71
71
 
@@ -55,7 +55,7 @@ flow.execute(summarize())
55
55
 
56
56
  缓存默认启用。可以使用 `Flow(..., cache=False)` 关闭缓存。缓存文件位于 `.alkaid0/workflow.db`;设置 `ALKAID0_WORKFLOW_SESSION_ID` 可以隔离不同会话。
57
57
 
58
- 可以通过 `Flow(..., report=True)` 或环境变量 `ALKAID0_WORKFLOW_REPORT=1` 开启 JSONL 状态上报。`Flow.run()` 会自动开启上报。事件包括 `graph`、`node`、`agent`、`agents_start`、`node_code` 和 `node_log`。
58
+ 可以通过 `Flow(..., report=True)` 或环境变量 `ALKAID0_WORKFLOW_REPORT=1` 开启 JSONL 状态上报。`Flow.run()` 会自动开启上报。事件包括 `graph`、`node`、`node_result`、`agent`、`agents_start`、`node_code` 和 `node_log`。
59
59
 
60
60
  ## 示例
61
61
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "dynworkflow"
3
- version = "0.1.2"
3
+ version = "0.1.3"
4
4
  description = "Dynamic Workflow Library for Alkaid0"
5
5
  readme = "README.md"
6
6
  authors = [{ name = "cxykevin", email = "cxykevin@yeah.net" }]
@@ -182,6 +182,13 @@ class Node():
182
182
  flow._reporter.report_node(flow._workflow_id, self._node_id,
183
183
  state.value, args, cached=cached)
184
184
 
185
+ def _report_result(self, flow: 'Flow', value: Any) -> None:
186
+ "_report_result() 推送一次节点终值事件(未启用上报时为空操作)"
187
+ if flow._reporter is None:
188
+ return
189
+ flow._reporter.report_node_result(flow._workflow_id, self._node_id,
190
+ value)
191
+
185
192
  def _run(self, flow: 'Flow') -> None:
186
193
  "Node.run() 执行节点,并把异常延迟到工作流结束统一抛出。"
187
194
  try:
@@ -315,7 +322,10 @@ class Node():
315
322
  return
316
323
  # 返回值处理
317
324
  if isinstance(ret, Result):
318
- flow._result[self._node_id] = ret.result()
325
+ value = ret.result()
326
+ flow._result[self._node_id] = value
327
+ # 推送:节点终值(宿主据此在 workflow 视图里展示 Result)
328
+ self._report_result(flow, value)
319
329
  return
320
330
 
321
331
  # 执行流程下一步
@@ -330,7 +340,10 @@ class Node():
330
340
  if kind == "none":
331
341
  return
332
342
  if kind == "result":
333
- flow._result[self._node_id] = cached.get("value")
343
+ value = cached.get("value")
344
+ flow._result[self._node_id] = value
345
+ # 缓存命中同样上报终值,宿主视图与真实执行保持一致
346
+ self._report_result(flow, value)
334
347
  return
335
348
  if kind == "executes":
336
349
  known = {node._node_id: node for node in flow._nodes}
@@ -579,7 +592,7 @@ class Flow:
579
592
  return {
580
593
  "nodes": {
581
594
  node._node_id: { # 节点信息
582
- "name": node._node_id,
595
+ "name": node._node_name, # 显示名(@flow.node("...") 的名字)
583
596
  } for node in self._nodes
584
597
  },
585
598
  "edges": edges,
@@ -156,6 +156,20 @@ class StatusReporter:
156
156
  "code": code,
157
157
  }])
158
158
 
159
+ def report_node_result(self, workflow_id: str, node_id: str,
160
+ result: Any) -> None:
161
+ """report_node_result() 上报节点终值(`Result` 携带的 value)。
162
+
163
+ 值不可 JSON 序列化时由 `emit` 的 `default=str` 兜底;上报失败不影响执行。
164
+ """
165
+ self.emit([{
166
+ "type": "node_result",
167
+ "time": _utc_now(),
168
+ "workflow": workflow_id,
169
+ "nodeId": node_id,
170
+ "result": result,
171
+ }])
172
+
159
173
  def report_graph(self, workflow_id: str, graph: Graph) -> None:
160
174
  """report_graph() 上报 Flow 生成的流程图(set 序列化为有序列表)。"""
161
175
  self.emit([{