{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "ARR Opera daily program input for fetch_oss_file",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "contract_version",
    "job_id",
    "attempt_no",
    "source_file_id",
    "processor_version",
    "rule_set_sha256",
    "oss_attachments",
    "oss_inline_images",
    "attachment_fetch_policy",
    "result_submission"
  ],
  "properties": {
    "contract_version": {
      "type": "string",
      "const": "arr-opera-daily-program-input-3"
    },
    "job_id": { "$ref": "#/$defs/opaqueId" },
    "attempt_no": {
      "type": "integer",
      "minimum": 1,
      "maximum": 9999
    },
    "source_file_id": { "$ref": "#/$defs/opaqueId" },
    "processor_version": {
      "type": "string",
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._+-]{0,63}$"
    },
    "rule_set_sha256": { "$ref": "#/$defs/sha256" },
    "oss_attachments": {
      "type": "array",
      "minItems": 1,
      "maxItems": 1,
      "items": { "$ref": "#/$defs/attachment" }
    },
    "oss_inline_images": {
      "type": "array",
      "maxItems": 0
    },
    "attachment_fetch_policy": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "tool_name",
        "required_before_skill_call",
        "applies_to",
        "output_field"
      ],
      "properties": {
        "tool_name": { "const": "fetch_oss_file" },
        "required_before_skill_call": { "const": true },
        "applies_to": {
          "type": "array",
          "prefixItems": [{ "const": "oss_attachments" }],
          "minItems": 1,
          "maxItems": 1
        },
        "output_field": { "const": "current_attachments" }
      }
    },
    "result_submission": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "tool_name",
        "submission_grant",
        "job_id",
        "attempt_no",
        "payload_source",
        "required_after_successful_skill_call"
      ],
      "properties": {
        "tool_name": { "const": "arr_submit_processing_result" },
        "submission_grant": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{32,128}$"
        },
        "job_id": { "$ref": "#/$defs/opaqueId" },
        "attempt_no": {
          "type": "integer",
          "minimum": 1,
          "maximum": 9999
        },
        "payload_source": { "const": "structured-result.json" },
        "required_after_successful_skill_call": { "const": true }
      }
    }
  },
  "$defs": {
    "opaqueId": {
      "type": "string",
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$"
    },
    "sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "attachment": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "name",
        "content_type",
        "size",
        "sha256",
        "current_or_history",
        "source_ref",
        "oss"
      ],
      "properties": {
        "id": { "$ref": "#/$defs/opaqueId" },
        "name": { "const": "source.xml" },
        "content_type": { "const": "application/xml" },
        "size": {
          "type": "integer",
          "minimum": 1,
          "maximum": 104857600
        },
        "sha256": { "$ref": "#/$defs/sha256" },
        "current_or_history": { "const": "current" },
        "source_ref": {
          "type": "object",
          "additionalProperties": false,
          "required": ["source", "index"],
          "properties": {
            "source": { "const": "oss_attachments" },
            "index": { "const": 0 }
          }
        },
        "oss": {
          "type": "object",
          "additionalProperties": false,
          "required": ["bucket", "endpoint", "object_key", "url"],
          "properties": {
            "bucket": {
              "type": "string",
              "pattern": "^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$"
            },
            "endpoint": {
              "type": "string",
              "pattern": "^oss-[a-z0-9-]+\\.aliyuncs\\.com$"
            },
            "object_key": {
              "type": "string",
              "pattern": "^arr/jobs/[A-Za-z0-9][A-Za-z0-9._:-]{0,127}/attempts/[0-9]{4}/committed/source_xml/source\\.xml$"
            },
            "url": {
              "type": "string",
              "format": "uri",
              "maxLength": 2048,
              "pattern": "^https://[a-z0-9][a-z0-9-]{1,61}[a-z0-9]\\.oss-[a-z0-9-]+\\.aliyuncs\\.com/arr/jobs/[A-Za-z0-9](?:[A-Za-z0-9._-]|%3A){0,127}/attempts/[0-9]{4}/committed/source_xml/source\\.xml$"
            }
          }
        }
      }
    }
  }
}
