{
  "name": "config_mm_api",
  "title": "mm API接口配置",
  "description": "mm API接口配置规范",
  "group": "mm",
  "version": "1.0.0",
  "input_schema": {
    "type": "object",
    "properties": {
      "task": {
        "type": "string",
        "description": "需要生成的配置描述"
      },
      "file_path": {
        "type": "string",
        "description": "配置文件写入路径"
      }
    },
    "required": ["task", "file_path"]
  },
  "output_schema": {
    "type": "object",
    "properties": {
      "file_path": {
        "type": "string",
        "description": "写入的文件路径"
      },
      "passed": {
        "type": "boolean",
        "description": "是否通过校验"
      }
    }
  },
  "steps": [
    {
      "id": "generate",
      "description": "按配置规范生成JSON内容",
      "operator": "executor",
      "handler": "llm",
      "on_error": {
        "retry": 2,
        "retry_delay": 500
      },
      "params": {
        "system_prompt": "{{ $meta.system_prompt }}",
        "user_prompt": "{{ $input.task }}",
        "response_format": {
          "type": "json_object"
        }
      }
    },
    {
      "id": "validate_json",
      "description": "验证JSON语法和字段规范",
      "operator": "validator",
      "handler": "json",
      "params": {
        "code": "{{ $steps.generate.content }}"
      }
    },
    {
      "id": "check_valid",
      "description": "校验失败则中止，通过则写入文件",
      "operator": "dispatcher",
      "handler": "condition",
      "params": {
        "source": "{{ $steps.validate_json.valid }}",
        "operator": "truthy",
        "then_jump": "write_file",
        "else_jump": "end"
      }
    },
    {
      "id": "write_file",
      "description": "将配置内容写入文件",
      "operator": "manager",
      "handler": "file",
      "params": {
        "action": "write",
        "file_path": "{{ $input.file_path }}",
        "content": "{{ $steps.generate.content }}"
      }
    },
    {
      "id": "log_artifact",
      "description": "记录产出文件信息",
      "operator": "manager",
      "handler": "artifact",
      "params": {
        "work_name": "config_mm_api",
        "stage": "executed",
        "file_path": "{{ $input.file_path }}",
        "valid": "{{ $steps.validate_json.valid }}",
        "error_count": "{{ $steps.validate_json.error_count }}",
        "line_count": "{{ $steps.validate_json.line_count }}"
      }
    },
    {
      "id": "log_call",
      "description": "记录调用日志",
      "operator": "manager",
      "handler": "call_log",
      "params": {
        "work_name": "config_mm_api",
        "stage": "executed",
        "status": "{{ $steps.validate_json.valid ? 'saved' : 'rejected' }}",
        "input_preview": { "$expr": "String($input.task).slice(0, 80)" },
        "last_error": "{{ $last_error }}"
      }
    }
  ]
}
