feat:完成数据文件上传解析及测试
This commit is contained in:
+23
-3
@@ -3,6 +3,7 @@
|
||||
它们读写的是本次请求的大屏和 agent 状态,所以放在本地;物料等能力由 MCP 提供
|
||||
"""
|
||||
|
||||
from collections.abc import Sequence
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Annotated, NotRequired
|
||||
|
||||
@@ -14,6 +15,7 @@ from pydantic import Field
|
||||
|
||||
from app.actions.batch import BatchError, run_batch
|
||||
from app.agent.data_tools import DataContext
|
||||
from app.agent.query_values import EmbeddedQuery, encode_problems, fill_queries
|
||||
from app.schemas.actions import Action, AddAction, AgentAction
|
||||
from app.schemas.component_resource import ComponentCatalog
|
||||
from app.schemas.screen import Screen
|
||||
@@ -58,6 +60,7 @@ def _result_text(
|
||||
after: Screen,
|
||||
actions: list[Action],
|
||||
undeclared_sample: frozenset[str] = frozenset(),
|
||||
queries: Sequence[EmbeddedQuery] = (),
|
||||
) -> str:
|
||||
"""执行结果:除了动作数量,还给出执行后的画布和每个组件的布局
|
||||
|
||||
@@ -75,10 +78,19 @@ def _result_text(
|
||||
if guessed := [item for item in sample if item in undeclared_sample]:
|
||||
lines.append(
|
||||
f"未写 sample_data,按物料默认标成了示例数据:{'、'.join(guessed)};"
|
||||
"如果这些组件展示的数据都来自大屏上已有的组件,把 sample_data 设为 false 重新提交整批,否则不用处理"
|
||||
"如果这些组件展示的数据都来自大屏上已有的组件或上传的数据文件,把 sample_data 设为 false 重新提交整批,否则不用处理"
|
||||
)
|
||||
if declared := [item for item in sample if item not in undeclared_sample]:
|
||||
lines.append(f"标为示例数据的新增组件:{'、'.join(declared)}")
|
||||
# 模型提交时只写了 SQL,看不到结果;给出列名和行数,用来核对 encode 和数据量
|
||||
if queries:
|
||||
lines.append("$query 已替换为查询结果:")
|
||||
for item in queries:
|
||||
note = "(结果为空,组件会没有数据)" if not item.rows else ""
|
||||
lines.append(
|
||||
f"- 第 {item.index + 1} 个动作 {item.node_id} 的 {item.path}:"
|
||||
f"{item.rows} 行{note},列 {'、'.join(item.columns)}"
|
||||
)
|
||||
|
||||
old_layouts = {node.id: node.layout for node in before.nodes}
|
||||
lines.append(
|
||||
@@ -114,11 +126,17 @@ def apply_actions(
|
||||
失败时整批不生效,返回带动作序号的错误,修正后重新提交整批;以最后一次调用的结果为准
|
||||
"""
|
||||
try:
|
||||
actions, queries = fill_queries(actions, runtime.context.data)
|
||||
completed, after = run_batch(
|
||||
runtime.context.screen, runtime.context.catalog, actions
|
||||
)
|
||||
problems = encode_problems(after, {item.node_id for item in queries})
|
||||
except BatchError as error:
|
||||
message = f"执行失败,整批未生效:\n- {error}"
|
||||
problems = [str(error)]
|
||||
if problems:
|
||||
message = "执行失败,整批未生效:\n" + "\n".join(
|
||||
f"- {item}" for item in problems
|
||||
)
|
||||
return Command(
|
||||
update={
|
||||
"actions": None,
|
||||
@@ -155,7 +173,9 @@ def apply_actions(
|
||||
"apply_error": None,
|
||||
"messages": [
|
||||
ToolMessage(
|
||||
_result_text(runtime.context.screen, after, completed, undeclared),
|
||||
_result_text(
|
||||
runtime.context.screen, after, completed, undeclared, queries
|
||||
),
|
||||
tool_call_id=runtime.tool_call_id,
|
||||
)
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user