{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/flashdata-dev/json-schema/flashdata-dev-agent-registration-schema.json",
  "title": "AgentRegistration",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/flashdata-dev-agent-connections-api-openapi.yml#/components/schemas/AgentRegistration",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "connection": {
      "$ref": "#/$defs/AgentConnection"
    },
    "credentials": {
      "$ref": "#/$defs/AgentCredentials"
    },
    "dataOrigin": {
      "type": "string"
    },
    "deniedScopes": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "limits": {
      "type": "object",
      "additionalProperties": true
    },
    "nextAction": {
      "type": "string",
      "enum": [
        "query_or_claim",
        "claim"
      ],
      "description": "Claim before the first data request when no requested source is trial eligible."
    }
  },
  "required": [
    "connection",
    "credentials",
    "dataOrigin",
    "deniedScopes",
    "limits"
  ],
  "$defs": {
    "AgentConnection": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "audience": {
          "type": "string",
          "enum": [
            "coding",
            "personal",
            "unspecified"
          ]
        },
        "ownership": {
          "type": "string",
          "enum": [
            "owned",
            "unowned"
          ]
        },
        "lifecycle": {
          "type": "string",
          "enum": [
            "valid",
            "revoked",
            "expired"
          ]
        },
        "access": {
          "type": "string",
          "enum": [
            "ready",
            "fenced",
            "blocked"
          ]
        },
        "scopes": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Actual scopes on the current API key. May be empty on an unowned claim-only connection; every data-source request is then forbidden."
        },
        "requestedScopes": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Original owner-access request. Claim approval can only reduce this set. Legacy connections retain their original scopes."
        },
        "trialScopes": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Saved subset eligible for the temporary key. Never expanded by catalog changes."
        },
        "permissions": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/AgentPermission"
          }
        },
        "generation": {
          "type": "integer",
          "minimum": 0
        },
        "installed": {
          "type": "boolean"
        },
        "trialExpiresAt": {
          "type": "string",
          "format": "date-time"
        },
        "fundingMode": {
          "type": "string",
          "enum": [
            "trial",
            "account_balance"
          ]
        },
        "trialCredits": {
          "type": "number"
        },
        "trialRequestCounts": {}
      },
      "required": [
        "id",
        "name",
        "audience",
        "ownership",
        "lifecycle",
        "access",
        "scopes",
        "generation",
        "installed",
        "trialExpiresAt",
        "fundingMode",
        "trialCredits",
        "trialRequestCounts"
      ]
    },
    "AgentCredentials": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "connectionId": {
          "type": "string"
        },
        "apiKey": {
          "type": "string"
        },
        "setupCredential": {
          "type": "string"
        },
        "handoffProof": {
          "type": "string"
        },
        "generation": {
          "type": "integer",
          "minimum": 0
        }
      },
      "required": [
        "connectionId",
        "apiKey",
        "generation"
      ],
      "description": "Sensitive ordinary API-key credentials. Never log or put in browser URLs. Proofs are returned on temporary registration; handoff returns the owned candidate key."
    },
    "AgentPermission": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source",
        "name",
        "product",
        "trialEligible",
        "ownerAllowed",
        "requiresStorageDestination"
      ],
      "properties": {
        "source": {
          "type": "string",
          "pattern": "^[a-z_]{1,80}$"
        },
        "name": {
          "type": "string"
        },
        "product": {
          "type": "string"
        },
        "trialEligible": {
          "type": "boolean"
        },
        "ownerAllowed": {
          "type": "boolean"
        },
        "requiresStorageDestination": {
          "type": "boolean"
        }
      },
      "description": "Catalog-derived agent permissions. Trial eligibility is an explicit opt-in independent of owner approval. Storage and variable-price sources require owner access."
    }
  }
}