跳转到主要内容
# =============================================================
# 1. MANIFEST (协议名片)
# 定义资产的身份、版本及确权信息
# =============================================================
manifest:
  urn: "urn:runly:ecommerce:amazon:selection-expert:v1-8892"
  title: "亚马逊选品深度分析专家"
  version: "1.0.5"
  status: "stable" # 状态:稳定版
  creator:
    me_id: "me_arch_dow_001"
    name: "Solo Arch Lab"
    pub_key: "ed25519:0x8e5c...a12b" # 用于验证签名的公钥
  created_at: "2026-01-20T08:00:00Z"
  updated_at: "2026-02-05T18:45:00Z"
  min_runtime: "v1.0"

# =============================================================
# 2. DICTIONARY (数据字典)
# 定义变量强类型、外部数据源、服务调用及交付资产
# =============================================================
dictionary:
  # [2.1] Ingress: 输入准入规则
  inputs:
    - name: "target_asin"
      type: "string"
      pattern: "^[A-Z0-9]{10}$"
      required: true
    - name: "callback_url"
      type: "string"
      description: "接收异步执行结果的 Webhook"
      required: true

  # [2.2] External Data: 主动拉取外部数据
  external_data:
    - id: "market_api"
      type: "REST_API"
      config:
        url: "https://api.market-api.com/v1/products/{{inputs.target_asin}}"
        method: "GET"
        headers:
          Authorization: "Bearer {{env.MARKET_API_TOKEN}}"
      cache_policy:
        ttl: 3600

  # [2.3] External Services: 外部动作调用
  external_services:
    - action_id: "notify_slack"
      type: "HTTP"
      config:
        method: "POST"
        url: "{{env.SLACK_WEBHOOK_URL}}"
        timeout: 10
        retry_policy:
          max_retries: 3
          interval: "exponential"

  # [2.4] Egress: 交付物与异步推送定义
  outputs:
    - name: "analysis_report"
      type: "html"
      config:
        title: "选品分析报告 - {{inputs.target_asin}}"
        template_ref: "urn:runly:templates:modern-analysis-v1"
        data_mapping:
          market_data: "{{data.market_api.output}}"
          ai_insight: "{{steps.ai_logic_node.output}}"
      export_as: "artifact" # 标记为生成的持久化数字资产
      delivery:
        mode: "ASYNC_PUSH"
        target_url: "{{inputs.callback_url}}"
        payload_mapping:
          trace_id: "{{system.trace_id}}"
          status: "SUCCESS"
          report_url: "{{outputs.analysis_report.url}}"

# =============================================================
# 3. TOPOLOGY (拓扑逻辑域)
# 定义逻辑节点的流转时序与人工卡点(HITL)状态机
# =============================================================
topology:
  start_at: "node_ingress_check"
  
  nodes:
    # 节点 1: 逻辑校验
    - id: "node_ingress_check"
      type: "LOGIC_GATE"
      rules:
        - condition: "inputs.target_asin.length == 10"
          next: "node_fetch_data"
        - condition: "default"
          next: "terminate_error"

    # 节点 2: HTTP 外部请求 (拉取数据)
    - id: "node_fetch_data"
      type: "HTTP"
      config:
        ref: "external_data.market_api"
      on_success: "node_ai_logic"
      on_failure: "node_error_handler"

    # 节点 3: AI 智能处理
    - id: "node_ai_logic"
      type: "AI_TASK"
      config:
        model: "gemini-2.0-flash"
        capability: "reasoning"
        prompt: "基于市场数据 {{steps.node_fetch_data.output}},分析该 ASIN 的竞争力和盈利潜力..."
      on_success: "node_expert_audit"

    # 节点 4: HITL 人工卡点 (Runly Me 授权)
    - id: "node_expert_audit"
      type: "HITL"
      config:
        assignee: "{{manifest.creator.me_id}}"
        instruction: "请核对 AI 分析的毛利率是否符合当前季节性波动。"
        ui_snapshot:
          - "steps.node_ai_logic.output"
          - "data.market_api.output.price"
      on_success: "node_final_terminus"
      on_failure: "node_ai_logic" # 若专家打回,重回 AI 节点优化

    # 节点 5: 最终交付节点
    - id: "node_final_terminus"
      type: "TERMINUS"
      config:
        output_ref: "outputs.analysis_report"

# =============================================================
# 4. COMMERCE (商业分账域)
# 定义资产的定价策略与收益分配规则
# =============================================================
commerce:
  pricing:
    mode: "UNIT_PAYMENT"
    amount: 0.85
    currency: "USDT"
    precision: 2
  
  royalty:
    creator_share: 0.80   # 专家/创作者获得收益的 80%
    platform_share: 0.20  # Runly 平台获得收益的 20%
  
  settlement:
    trigger: "node_final_terminus" # 到达此节点即触发扣费
    auto_payout: true

# =============================================================
# 5. SECURITY (安全指纹 - 执行时计算)
# 位于文件末尾,确保存储与传输过程中逻辑不被篡改
# =============================================================
security:
  hash_algo: "SHA-256"
  signature: "0x8f2a...e41c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9"