""" services/shipping_notice/dify_inputs.py 用途:构建发货通知 Dify Chatflow 需要的输入变量,如 Tool API Base URL 和 Tool API Key。 依赖:agent_resolver、tool_api_url、Flask current_app 配置。 逻辑:由聊天 Agent 入口或 Dify 调用准备逻辑引用本文件,把环境相关变量注入到 Dify 请求上下文。 """ from __future__ import annotations from flask import current_app from app.services.shipping_notice.agent_resolver import CHAT_AGENT_NAME from app.services.shipping_notice.tool_api_url import resolve_tool_api_base_url # Dify Chatflow input variable names — must match canvas Start / 输入变量配置. HXOPS_TOOLS_API_BASE_INPUT = "HXOPS_TOOLS_API_BASE" HXOPS_TOOL_API_KEY_INPUT = "hxops_tool_api_key" def is_shipping_notice_chat_agent(agent) -> bool: """判断 Agent 记录是否为发货通知聊天 Agent。""" return getattr(agent, "name", None) == CHAT_AGENT_NAME def build_dify_chat_inputs() -> dict[str, str]: """构建 Dify Chatflow 输入变量(Tool API Base URL 与 API Key)。""" base = resolve_tool_api_base_url() key = str(current_app.config.get("SHIPPING_NOTICE_TOOL_API_KEY") or "").strip() inputs: dict[str, str] = {} if base: inputs[HXOPS_TOOLS_API_BASE_INPUT] = base if key: inputs[HXOPS_TOOL_API_KEY_INPUT] = key return inputs