{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://weverlabs.com/schemas/agent-callback-payload.schema.json",
  "title": "Agent Callback Payload",
  "description": "Schema for the public-safe callback payload returned to a requesting agent or system after a paid Wever Labs OS task is ready, partial, failed, or delivered.",
  "type": "object",
  "required": [
    "payload_type",
    "event_type",
    "work_order_id",
    "agent_task_run_id",
    "requested_tool",
    "result_status",
    "result_url",
    "issued_at"
  ],
  "additionalProperties": true,
  "properties": {
    "payload_type": {
      "type": "string",
      "const": "agent_callback_payload"
    },
    "event_type": {
      "type": "string",
      "enum": [
        "task_result_ready",
        "task_result_partial",
        "task_result_failed",
        "task_result_delivered",
        "receipt_issued"
      ]
    },
    "work_order_id": {
      "type": "string"
    },
    "agent_task_run_id": {
      "type": "string"
    },
    "requested_tool": {
      "type": "string",
      "enum": [
        "tokenops",
        "packetops",
        "distributionops",
        "wever_labs_os"
      ]
    },
    "requested_capability": {
      "type": "string"
    },
    "result_status": {
      "type": "string",
      "enum": [
        "ready",
        "partial",
        "failed",
        "delivered"
      ]
    },
    "result_url": {
      "type": "string",
      "format": "uri"
    },
    "receipt_url": {
      "type": "string",
      "format": "uri"
    },
    "usage_receipt": {
      "$ref": "https://weverlabs.com/schemas/tokenops-usage-receipt.schema.json"
    },
    "result_package": {
      "$ref": "https://weverlabs.com/schemas/tokenops-result-package.schema.json"
    },
    "delivery": {
      "type": "object",
      "additionalProperties": true,
      "properties": {
        "callback_status": {
          "type": "string",
          "enum": [
            "pending",
            "ready",
            "delivered",
            "failed",
            "retry_required"
          ]
        },
        "attempt_count": {
          "type": "integer",
          "minimum": 0
        },
        "last_attempt_at": {
          "type": "string",
          "format": "date-time"
        },
        "next_retry_at": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "next_available_actions": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "public_safe_note": {
      "type": "string"
    },
    "issued_at": {
      "type": "string",
      "format": "date-time"
    },
    "handshake_id": {
      "type": "string",
      "description": "Optional upstream agent handshake ID."
    },
    "preflight_id": {
      "type": "string",
      "description": "Optional upstream preflight check ID."
    },
    "contract_id": {
      "type": "string",
      "description": "Optional upstream run contract ID."
    },
    "run_contract_url": {
      "type": "string",
      "format": "uri",
      "description": "Optional URL for the run contract object."
    }
  }
}
