Files
TimiServerAPI/src/ai/dsl/README.md
T
Timi 7e7a9cf60c feat(gao-ai): add confirmed write operations
- add prepare/commit/cancel MCP tools and pending operation state
- enforce execution identity, permissions, exact confirmation and audit
- support attachments and operation confirmation cards
- rewrite Dify DSL for write routing and destructive confirmations
2026-11-24 11:41:59 +08:00

2.9 KiB

GAO 门店智能助手 Dify DSL 配置说明

main_agent.yml 是 Advanced Chat 应用,支持:

  • 知识库规则回答
  • 实时业务查询 Agent
  • 规则 + 实时数据混合分析
  • 带预览和人工确认的写操作

1. MCP Provider

导入 DSL 后需要配置两个 MCP Provider。

DSL 中的 Provider 后端地址 服务密钥
gao-mcp-server-dev http(s)://<backend>/mcp/gao-ai 系统设置 DIFY_MCP_SERVICE_KEY
gao-mcp-commit-dev http(s)://<backend>/mcp/gao-ai-commit 系统设置 DIFY_MCP_COMMIT_SERVICE_KEY

要求:

  1. gao-mcp-server-dev 只暴露查询工具和 operation_prepare。
  2. gao-mcp-commit-dev 只暴露 operation_commit、operation_cancel。
  3. 提交 Provider 不得绑定到任何 Agent 节点,只允许 main_agent.yml 中的确定性工具节点调用。
  4. 如果 Dify 中的 Provider ID 与 DSL 不一致,请同时修改 DSL 中 commit_tool、cancel_tool、prepare_tool 的 provider_id 和 provider_name。

2. 写能力开关

后端默认关闭写能力:

gao:
  ai:
    write:
      enabled: true
      confirmation-ttl-seconds: 600
      result-ttl-seconds: 1800
      max-prepares-per-10-minutes: 10
      max-commits-per-10-minutes: 10
      order-max-sale-amount: 1000000
      order-max-discount-rate: 0.30
      point-adjust-max-abs: 10000
      stock-change-max-quantity: 1000
      attachment-max-count: 10
      attachment-max-size-mb: 10
      attachment-ttl-seconds: 86400

3. 附件

Dify 内置文件上传保持关闭。前端流程:

  1. 调用 POST /gao/ai/attachment/upload 上传凭证,获得 token。
  2. 聊天请求携带 attachmentTokenList。
  3. 后端把附件 token 注入 Dify start 输入 attachmentTokensJson。
  4. operation_prepare 解析并校验附件,token 不进入模型提示词。

4. 确认流程

文本确认

  1. 用户发起写操作。
  2. operation_prepare 返回 PENDING_CONFIRMATION、previewText、requiredPhrase。
  3. 下一轮聊天后端注入 pendingOperationToken 等 start 输入。
  4. pending_gate 判断是否存在待确认操作。
  5. pending_action 规则判断确认/取消。
  6. 确认时调用 operation_commit;取消时调用 operation_cancel。

卡片确认

  1. 后端在 SSE 结束前推送 operation_preview。
  2. 卡片调用 GET /gao/ai/operation/pending 恢复状态。
  3. 确认调用 POST /gao/ai/operation/commit。
  4. 取消调用 POST /gao/ai/operation/cancel。

卡片使用公开 operationId,确认 token 不进入浏览器。

5. 安全边界

  • 模型不可传 storeId、operatorUserId、requestNo、confirmationToken。
  • 提交工具只接受确认 token,不接受业务参数。
  • 破坏性和敏感操作必须精确短语,并重新校验权限、门店、价格、库存和状态。
  • 物理删除不在操作注册表中。