feat(shipping-notice): 添加订单抽取功能,支持异步运行和管理,优化相关数据模型和处理逻辑
This commit is contained in:
1 parent
34d489a2d1
commit
ce26d6d0c4
144 files changed
+12241
-4233
No files matched your search
@@ -74,31 +74,6 @@ def build_dify_openapi_spec(base_url: str) -> dict[str, Any]:
|
||||
runtime_context = _str_prop(
|
||||
"HXOPS 注入的完整 agent_runtime_context JSON 字符串;必须原样透传,禁止由 LLM 构造或修改"
|
||||
)
|
||||
observation_schema = {
|
||||
"type": "object",
|
||||
"required": ["value", "document_id", "quote"],
|
||||
"properties": {
|
||||
"value": {"description": "从证据原文提取的字段值,类型必须符合动态字段契约"},
|
||||
"document_id": _int_prop("证据来源 Document ID,必须来自抽取上下文"),
|
||||
"quote": _str_prop("证据原文中的逐字引用,HXOPS 将验证其确实存在"),
|
||||
"confidence": {"type": "number", "minimum": 0, "maximum": 1},
|
||||
},
|
||||
"additionalProperties": False,
|
||||
}
|
||||
extracted_field_schema = {
|
||||
"type": "object",
|
||||
"required": ["field_id", "observations"],
|
||||
"properties": {
|
||||
"field_id": _str_prop("动态字段契约中的稳定 field_id,禁止传 field_code 或显示名称"),
|
||||
"observations": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"items": observation_schema,
|
||||
},
|
||||
},
|
||||
"additionalProperties": False,
|
||||
}
|
||||
|
||||
return {
|
||||
"openapi": "3.0.0",
|
||||
"info": {
|
||||
@@ -121,84 +96,6 @@ def build_dify_openapi_spec(base_url: str) -> dict[str, Any]:
|
||||
},
|
||||
"servers": [{"url": server}],
|
||||
"paths": {
|
||||
"/tools/get_order_extraction_context": _post_op(
|
||||
"get_order_extraction_context",
|
||||
"读取点击发送后完整订单抽取所需的邮件正文与附件文本",
|
||||
{"agent_runtime_context": runtime_context},
|
||||
required=["agent_runtime_context"],
|
||||
description=(
|
||||
"仅在 refs.capability=order_extraction 分支调用。Tool 从 platform.session_id 反查当前用户,"
|
||||
"并返回 input_snapshot_hash、documents 与当前 published 动态 Schema 契约;禁止让 LLM 传 user_id。"
|
||||
),
|
||||
),
|
||||
"/tools/submit_order_extraction": _post_op(
|
||||
"submit_order_extraction",
|
||||
"提交完整订单抽取结果,由 HXOPS 执行证据校验、订单级判重与自动建单",
|
||||
{
|
||||
"agent_runtime_context": runtime_context,
|
||||
"input_snapshot_hash": _str_prop("get_order_extraction_context 返回的不可变输入快照 SHA-256"),
|
||||
"orders": {
|
||||
"type": "array",
|
||||
"description": "LLM 从一封或多封邮件中识别出的订单数组;一个附件可产生多个订单,非发货邮件可为空数组",
|
||||
"maxItems": 50,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"schema_version_id",
|
||||
"schema_checksum",
|
||||
"source_intake_no",
|
||||
"primary_document_id",
|
||||
"classification",
|
||||
"classification_confidence",
|
||||
"header_fields",
|
||||
"lines",
|
||||
],
|
||||
"properties": {
|
||||
"source_intake_no": _str_prop("来源 Intake 编号,必须来自上下文"),
|
||||
"schema_version_id": _int_prop("context.contract.schema_version_id,必须原样回传"),
|
||||
"schema_checksum": _str_prop("context.contract.checksum,必须原样回传"),
|
||||
"primary_document_id": _int_prop("主来源 Document ID,必须来自上下文"),
|
||||
"candidate_key_hint": _str_prop("可选稳定订单标识,如 PO/订单号;不得使用随机值"),
|
||||
"classification": _str_prop("仅 shipping_request 可自动建单", enum=["shipping_request", "non_shipping_request", "uncertain"]),
|
||||
"classification_confidence": {"type": "number", "minimum": 0, "maximum": 1},
|
||||
"header_fields": {
|
||||
"type": "array",
|
||||
"description": "Header scope 动态字段;仅可使用 context.contract.fields 中的稳定 field_id",
|
||||
"items": extracted_field_schema,
|
||||
},
|
||||
"lines": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"required": ["fields"],
|
||||
"properties": {
|
||||
"fields": {
|
||||
"type": "array",
|
||||
"description": "Line scope 动态字段;每项含 field_id 与 observations[]",
|
||||
"items": extracted_field_schema,
|
||||
},
|
||||
},
|
||||
"additionalProperties": False,
|
||||
},
|
||||
},
|
||||
"conflicts": {
|
||||
"type": "array",
|
||||
"items": {"type": "object", "additionalProperties": True},
|
||||
},
|
||||
},
|
||||
"additionalProperties": True,
|
||||
},
|
||||
},
|
||||
},
|
||||
required=["agent_runtime_context", "input_snapshot_hash", "orders"],
|
||||
description=(
|
||||
"只接受同一快照和同一 Schema checksum。Dify 必须逐字段返回稳定 field_id 与 observations[];"
|
||||
"每个 Observation 包含 value、document_id、逐字 quote 和可选 confidence。"
|
||||
"HXOPS 验证原文、执行类型/validator/证据策略与跨 Document 裁决后,才按 field_code 投影给下游。"
|
||||
"响应以持久化结果分别返回 created_count、opened_existing_count、pending_count、"
|
||||
"non_shipping_count;auto_created_count 仅为兼容字段且等于 created_count。"
|
||||
),
|
||||
),
|
||||
"/tools/create_temporary_inventory_session": _post_op(
|
||||
"create_temporary_inventory_session",
|
||||
"创建对话上传库存文件的临时分析会话",
|
||||
|
||||
Reference in new issue
Block a user