"""初中物理作业批改工作流主图编排 - 支持多图片批改"""
from langgraph.graph import StateGraph, END
from langchain_core.runnables import RunnableConfig
from langgraph.runtime import Runtime

from graphs.state import (
    GlobalState,
    GraphInput,
    GraphOutput
)

# 导入节点
from graphs.nodes.doc_extract_node import doc_extract_node
from graphs.nodes.process_images_node import process_images_node


# 创建状态图
builder = StateGraph(
    GlobalState,
    input_schema=GraphInput,
    output_schema=GraphOutput
)

# 添加节点
builder.add_node("doc_extract", doc_extract_node, metadata={"type": "agent", "llm_cfg": "config/doc_extract_llm_cfg.json"})
builder.add_node("process_images", process_images_node, metadata={"type": "looparray"})

# 设置入口点
builder.set_entry_point("doc_extract")

# 添加边 - 线性流程
# 1. 先解析Word答案（如果提供了URL）
builder.add_edge("doc_extract", "process_images")

# 2. 循环处理每张图片并生成最终结果
builder.add_edge("process_images", END)

# 编译图
main_graph = builder.compile()
