{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://weverlabs.com/schemas/agent-run-state-event.schema.json",
  "title": "Wever Labs Agent Run State Event",
  "description": "A single ledger event in the lifecycle of a paid agent task run.",
  "type": "object",
  "required": [
    "event_type",
    "agent_task_run_id",
    "to_state",
    "occurred_at"
  ],
  "additionalProperties": true,
  "properties": {
    "event_type": {
      "type": "string",
      "enum": [
        "run_created",
        "credit_reserved",
        "evidence_review_started",
        "evidence_status_changed",
        "tool_execution_started",
        "result_package_ready",
        "credits_debited",
        "usage_receipt_issued",
        "callback_payload_ready",
        "callback_delivered",
        "run_closed",
        "run_paused",
        "run_failed",
        "lifecycle_state_changed",
        "preflight_checked",
        "contract_ready",
        "contract_accepted",
        "trust_approved",
        "settlement_intent_created",
        "settlement_provider_confirmed",
        "credit_funded_from_settlement",
        "exception_opened",
        "replay_package_ready",
        "callback_failed",
        "task_closed"
      ]
    },
    "agent_task_run_id": {
      "type": "string"
    },
    "work_order_id": {
      "type": "string"
    },
    "from_state": {
      "type": "string"
    },
    "to_state": {
      "type": "string"
    },
    "actor": {
      "type": "string",
      "description": "Agent, OS service, tool, or operator that caused the state movement."
    },
    "requested_tool": {
      "type": "string"
    },
    "evidence_status": {
      "type": "string",
      "enum": [
        "sufficient",
        "partial",
        "insufficient",
        "unknown"
      ]
    },
    "credit_delta": {
      "type": "number"
    },
    "public_note": {
      "type": "string"
    },
    "links": {
      "type": "object",
      "additionalProperties": {
        "type": "string"
      }
    },
    "occurred_at": {
      "type": "string",
      "format": "date-time"
    },
    "canonical_lifecycle_state": {
      "type": "string",
      "enum": [
        "created",
        "preflight_checked",
        "contract_ready",
        "contract_accepted",
        "trust_pending",
        "trusted",
        "quoted",
        "credit_pending",
        "credit_funded",
        "queued",
        "operating",
        "evidence_partial",
        "result_ready",
        "attested",
        "receipt_issued",
        "callback_pending",
        "callback_delivered",
        "exception_open",
        "replay_ready",
        "failed",
        "closed"
      ]
    },
    "settlement_provider": {
      "type": "string"
    },
    "provider_event_id": {
      "type": "string"
    }
  }
}
