{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/zeronoise-ai/json-schema/zeronoise-ai-operation-schema.json",
  "title": "Operation",
  "x-generated": "2026-11-29",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/zeronoise-ai-openapi.yaml#/components/schemas/Operation",
  "type": "object",
  "required": [
    "id",
    "object",
    "capability",
    "status",
    "subject",
    "created_at",
    "updated_at",
    "links"
  ],
  "properties": {
    "id": {
      "$ref": "#/$defs/OpaqueId"
    },
    "object": {
      "type": "string",
      "enum": [
        "operation"
      ]
    },
    "capability": {
      "type": "string",
      "x-extensible-enum": [
        "agent_draft",
        "agent_chat",
        "add_source",
        "source_discovery",
        "brief_generation"
      ]
    },
    "status": {
      "type": "string",
      "x-extensible-enum": [
        "queued",
        "running",
        "succeeded",
        "failed"
      ]
    },
    "subject": {
      "$ref": "#/$defs/ResourceReference"
    },
    "caused_by": {
      "$ref": "#/$defs/ResourceReference"
    },
    "progress": {
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": true
    },
    "result": {
      "description": "Present when durable results exist. The capability determines the result family; fields may be absent on historical Operations.",
      "anyOf": [
        {
          "$ref": "#/$defs/AuthoringOperationResult"
        },
        {
          "$ref": "#/$defs/DiscoveryOperationResult"
        },
        {
          "$ref": "#/$defs/BriefOperationResult"
        },
        {
          "$ref": "#/$defs/SourceIngestionOperationResult"
        }
      ]
    },
    "error": {
      "$ref": "#/$defs/OperationError"
    },
    "usage": {
      "$ref": "#/$defs/OperationUsage"
    },
    "created_at": {
      "$ref": "#/$defs/Timestamp"
    },
    "started_at": {
      "$ref": "#/$defs/Timestamp"
    },
    "completed_at": {
      "$ref": "#/$defs/Timestamp"
    },
    "updated_at": {
      "$ref": "#/$defs/Timestamp"
    },
    "links": {
      "$ref": "#/$defs/Links"
    }
  },
  "$defs": {
    "AuthoringOperationResult": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "agent": {
          "$ref": "#/$defs/ResourceReference"
        },
        "chat": {
          "$ref": "#/$defs/ResourceReference"
        },
        "message": {
          "$ref": "#/$defs/ResourceReference"
        },
        "references": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/ResourceReference"
          }
        },
        "proposal": {
          "$ref": "#/$defs/ResourceReference"
        },
        "action_request": {
          "$ref": "#/$defs/ResourceReference"
        },
        "configuration_etag": {
          "type": "string"
        },
        "before_configuration_etag": {
          "type": [
            "string",
            "null"
          ]
        },
        "applied_effects": {
          "type": "array",
          "items": {
            "type": "string",
            "x-extensible-enum": [
              "agent_configuration_updated"
            ]
          }
        }
      }
    },
    "BriefOperationResult": {
      "type": "object",
      "properties": {
        "brief": {
          "$ref": "#/$defs/ResourceReference"
        },
        "href": {
          "type": "string"
        }
      }
    },
    "DiscoveryOperationResult": {
      "type": "object",
      "properties": {
        "outcome": {
          "type": "string",
          "x-extensible-enum": [
            "suggestions_ready",
            "partial",
            "no_suggestions"
          ]
        },
        "counts": {
          "type": "object",
          "properties": {
            "checked": {
              "type": "integer",
              "minimum": 0
            },
            "ready": {
              "type": "integer",
              "minimum": 0
            },
            "suggestions_ready": {
              "type": "integer",
              "minimum": 0
            }
          }
        },
        "gaps": {
          "type": "array",
          "maxItems": 12,
          "items": {
            "type": "string",
            "maxLength": 240
          }
        },
        "stop_reason": {
          "type": "string",
          "x-extensible-enum": [
            "step_limit",
            "cost_limit",
            "system_error",
            "final_selection_invalid",
            "stopped"
          ]
        },
        "sources": {
          "type": "object",
          "required": [
            "object",
            "agent_id",
            "created_by_operation_id",
            "href"
          ],
          "properties": {
            "object": {
              "type": "string",
              "enum": [
                "source_collection"
              ]
            },
            "agent_id": {
              "$ref": "#/$defs/OpaqueId"
            },
            "created_by_operation_id": {
              "$ref": "#/$defs/OpaqueId"
            },
            "href": {
              "type": "string"
            }
          }
        },
        "created_pending": {
          "type": "integer",
          "minimum": 0,
          "description": "Legacy result count."
        },
        "matched_existing": {
          "type": "integer",
          "minimum": 0,
          "description": "Legacy result count."
        },
        "skipped": {
          "type": "integer",
          "minimum": 0,
          "description": "Legacy result count."
        },
        "failed": {
          "type": "integer",
          "minimum": 0,
          "description": "Legacy result count."
        }
      }
    },
    "Link": {
      "type": "object",
      "required": [
        "href"
      ],
      "properties": {
        "href": {
          "type": "string"
        }
      }
    },
    "Links": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/Link"
      }
    },
    "OpaqueId": {
      "type": "string",
      "minLength": 1,
      "maxLength": 255,
      "description": "Opaque identifier; clients must not parse its format."
    },
    "OperationError": {
      "type": [
        "object",
        "null"
      ],
      "required": [
        "code",
        "message"
      ],
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        }
      }
    },
    "OperationUsage": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "amount_usd": {
          "type": "string",
          "pattern": "^-?\\d+(?:\\.\\d+)?$"
        },
        "charged": {
          "type": "boolean"
        }
      }
    },
    "ResourceReference": {
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": false,
      "required": [
        "object",
        "id"
      ],
      "properties": {
        "object": {
          "type": "string"
        },
        "id": {
          "$ref": "#/$defs/OpaqueId"
        }
      }
    },
    "SourceIngestionOperationResult": {
      "type": "object",
      "properties": {
        "total": {
          "type": "integer",
          "minimum": 0
        },
        "processed": {
          "type": "integer",
          "minimum": 0
        },
        "added": {
          "type": "integer",
          "minimum": 0
        },
        "added_channels": {
          "type": "integer",
          "minimum": 0
        },
        "added_web_sources": {
          "type": "integer",
          "minimum": 0
        },
        "duplicate": {
          "type": "integer",
          "minimum": 0
        },
        "invalid": {
          "type": "integer",
          "minimum": 0
        },
        "errors": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "Timestamp": {
      "type": "string",
      "format": "date-time"
    }
  }
}