53 lines
2.0 KiB
Python
53 lines
2.0 KiB
Python
"""请求摘要:意图判断和 screen agent 共用,只给组件的识别信息和布局,完整配置按需读取
|
|
|
|
只描述本次请求;会话历史由各使用方另行传入,见 history.py
|
|
"""
|
|
|
|
from app.schemas.base import JsonObject
|
|
from app.schemas.input_context import InputContext
|
|
|
|
|
|
def request_summary(context: InputContext) -> JsonObject:
|
|
"""用户输入、澄清记录、编辑上下文、附件和大屏摘要"""
|
|
nodes: list[JsonObject] = []
|
|
for node in context.screen.nodes:
|
|
# 图表标题帮助判断用户指的是哪个组件;没有 option 或标题格式不符时按无标题处理
|
|
option = node.props.get("option")
|
|
title = option.get("title") if isinstance(option, dict) else None
|
|
titles = title if isinstance(title, list) else [title]
|
|
nodes.append(
|
|
{
|
|
"id": node.id,
|
|
"type": node.type,
|
|
"name": node.name,
|
|
"titles": [
|
|
item["text"]
|
|
for item in titles
|
|
if isinstance(item, dict) and isinstance(item.get("text"), str)
|
|
],
|
|
"layout": node.layout.model_dump(mode="json", exclude_unset=True),
|
|
}
|
|
)
|
|
|
|
return {
|
|
"prompt": context.prompt,
|
|
"clarification_history": context.clarification_history,
|
|
"context": context.context.model_dump(mode="json", exclude_unset=True),
|
|
"screen_summary": {
|
|
"canvas": {
|
|
"width": context.screen.canvas.width,
|
|
"height": context.screen.canvas.height,
|
|
},
|
|
"nodes": nodes,
|
|
# 数据源只保留标识、名称和类型
|
|
"data_sources": [
|
|
{key: source[key] for key in ("id", "name", "type") if key in source}
|
|
for source in context.screen.dataSource
|
|
],
|
|
},
|
|
"attachments": [
|
|
{key: item[key] for key in ("id", "kind", "name") if key in item}
|
|
for item in context.attachments
|
|
],
|
|
}
|