{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://weverlabs.com/schemas/tokenops-usage-receipt.schema.json",
  "title": "TokenOps Usage Receipt",
  "description": "Schema for a public-safe TokenOps usage receipt issued after a funded agent task consumes credits. Settlement receipts separately record credit funding.",
  "type": "object",
  "required": [
    "receipt_id",
    "receipt_type",
    "operating_tool",
    "work_order_id",
    "agent_task_run_id",
    "requested_tool",
    "credits_debited",
    "remaining_credits",
    "result_status",
    "issued_at"
  ],
  "additionalProperties": true,
  "properties": {
    "receipt_id": {
      "type": "string"
    },
    "receipt_type": {
      "type": "string",
      "const": "tokenops_usage_receipt"
    },
    "operating_tool": {
      "type": "string",
      "const": "tokenops"
    },
    "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"
    },
    "settlement_reference": {
      "type": "string"
    },
    "payment_request_reference": {
      "type": "string"
    },
    "credit_ledger_entry": {
      "type": "object",
      "additionalProperties": true,
      "properties": {
        "ledger_entry_id": {
          "type": "string"
        },
        "agent_account_id": {
          "type": "string"
        },
        "credits_funded": {
          "type": "number"
        },
        "credits_debited": {
          "type": "number"
        },
        "remaining_credits": {
          "type": "number"
        },
        "currency_or_unit": {
          "type": "string"
        }
      }
    },
    "credits_debited": {
      "type": "number",
      "minimum": 0
    },
    "remaining_credits": {
      "type": "number",
      "minimum": 0
    },
    "evidence_status": {
      "type": "string",
      "enum": [
        "sufficient",
        "partial",
        "insufficient",
        "unknown"
      ]
    },
    "evidence_score": {
      "type": "integer",
      "minimum": 0,
      "maximum": 100
    },
    "result_status": {
      "type": "string",
      "enum": [
        "queued",
        "operating",
        "ready",
        "partial",
        "failed",
        "delivered"
      ]
    },
    "result_package_url": {
      "type": "string",
      "format": "uri"
    },
    "callback_status": {
      "type": "string",
      "enum": [
        "not_requested",
        "pending",
        "ready",
        "delivered",
        "failed",
        "retry_required"
      ]
    },
    "callback_url_present": {
      "type": "boolean"
    },
    "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."
    },
    "settlement_receipt_id": {
      "type": "string"
    },
    "settlement_receipt_url": {
      "type": "string",
      "format": "uri"
    },
    "agent_result_contract_id": {
      "type": "string"
    },
    "agent_result_contract_url": {
      "type": "string",
      "format": "uri"
    },
    "receipt_split": {
      "type": "string",
      "const": "usage_receipt_records_credits_consumed"
    },
    "os_support_matrix_url": {
      "type": "string",
      "format": "uri"
    },
    "rail_binding_url": {
      "type": "string",
      "format": "uri"
    },
    "runtime_execution_plan_url": {
      "type": "string",
      "format": "uri"
    }
  }
}
