清理废弃的shipping xfa ocr automark相关代码和job配置 新增收料报表管理的前端页面、路由和侧边栏入口 新增后端收料报表配置接口、数据库模型和RPA脚本 优化发货通知流程的重试策略,将shipping相关job默认不自动重试 移除废弃的库存源确认相关逻辑,更新流程门禁规则 重构订单模板的值适配器模块,新增坐标OCR值适配器 清理前端shipping菜单和action的废弃选项 更新相关文档和测试用例,调整.gitignore忽略规则
106 lines
4.0 KiB
Python
106 lines
4.0 KiB
Python
"""
|
||
services/shipping_notice/openapi_spec.py
|
||
|
||
用途:构建发货通知 Tool API 的 OpenAPI 描述,供 Dify 导入和联调用。
|
||
依赖:标准 `typing` 类型。
|
||
逻辑:由 api/shipping_notice_tools.py 调用本文件生成 JSON/YAML OpenAPI 文档,再暴露给 Dify 或开发工具;
|
||
co8 起不再导出 get_batch_status(shipping_batches 已 DROP)。
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from typing import Any
|
||
|
||
def _str_prop(description: str, *, enum: list[str] | None = None) -> dict[str, Any]:
|
||
prop: dict[str, Any] = {"type": "string", "description": description}
|
||
if enum:
|
||
prop["enum"] = enum
|
||
return prop
|
||
|
||
|
||
def _int_prop(description: str) -> dict[str, Any]:
|
||
return {"type": "integer", "description": description}
|
||
|
||
|
||
def _post_op(
|
||
operation_id: str,
|
||
summary: str,
|
||
properties: dict[str, Any],
|
||
*,
|
||
required: list[str] | None = None,
|
||
description: str | None = None,
|
||
) -> dict[str, Any]:
|
||
schema: dict[str, Any] = {"type": "object", "properties": properties}
|
||
if required:
|
||
schema["required"] = required
|
||
return {
|
||
"post": {
|
||
"operationId": operation_id,
|
||
"summary": summary,
|
||
"description": str(description or summary),
|
||
"parameters": [],
|
||
"requestBody": {
|
||
"required": True,
|
||
"content": {
|
||
"application/json": {
|
||
"schema": schema,
|
||
}
|
||
},
|
||
},
|
||
"responses": {
|
||
"200": {
|
||
"description": (
|
||
"Tool response (status: ok|running|needs_human|failed). "
|
||
"May include checkpoint; business buttons are exposed only by ui_state.actions."
|
||
),
|
||
"content": {
|
||
"application/json": {
|
||
"schema": {"type": "object"},
|
||
}
|
||
},
|
||
}
|
||
},
|
||
}
|
||
}
|
||
|
||
|
||
def build_dify_openapi_spec(base_url: str) -> dict[str, Any]:
|
||
"""Build OpenAPI 3.0 spec for Dify Chatflow custom tools (agent-facing only)."""
|
||
server = str(base_url or "").strip().rstrip("/")
|
||
if not server.endswith("/api/shipping-notice"):
|
||
server = f"{server}/api/shipping-notice" if server else "/api/shipping-notice"
|
||
|
||
task_id = _str_prop("发货任务引用:技术任务号 SN-20260529-ABCD1234 或业务号 WYC26071501")
|
||
capability_token = _str_prop("HXOPS 每轮注入的短效只读能力令牌;必须原样透传")
|
||
return {
|
||
"openapi": "3.0.0",
|
||
"info": {
|
||
"title": "Shipping Notice Tools",
|
||
"version": "1.0.0",
|
||
"description": (
|
||
"货代 Chatflow 仅作自然语言只读解释。所有写操作必须由 HXOPS 确认卡和后端状态机执行;"
|
||
"本 OpenAPI 不包含改单、确认、冻结、库存、Excel 或上传接口。"
|
||
),
|
||
},
|
||
"servers": [{"url": server}],
|
||
"paths": {
|
||
"/tools/get_task_status": _post_op(
|
||
"get_task_status",
|
||
"查询任务当前状态;响应含库存连接器独立字段与候选结构",
|
||
{
|
||
"task_id": task_id,
|
||
"conversation_id": _str_prop("Dify 会话 ID"),
|
||
"shipping_chat_capability_token": capability_token,
|
||
},
|
||
required=["task_id", "shipping_chat_capability_token"],
|
||
description=(
|
||
"返回 inventory_source_code、inventory_connector_type、"
|
||
"inventory_warehouse_id、inventory_source_status(unresolved|ambiguous|resolved|"
|
||
"candidates_frozen|invalid|conflicted)、inventory_source_method、"
|
||
"inventory_source_config_version、inventory_routing_fingerprint、"
|
||
"以及 step_payload.inventory_source_resolution.candidates。"
|
||
),
|
||
),
|
||
},
|
||
}
|