{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/robosystems-ai/json-schema/robosystems-ai-operation-envelope-schema.json",
  "title": "OperationEnvelope",
  "description": "Uniform response shape for every operation endpoint.\n\nEvery dispatch carries an `op_<ULID>` operation_id, which is the bridge\nto the monitoring surface: pass it to\n`GET /v1/operations/{operation_id}/stream` (see `routers/operations.py`)\nto subscribe to SSE progress events. Sync commands complete in the envelope\nitself (`status: \"completed\"`, HTTP 200); async commands\n(`status: \"pending\"`, HTTP 202) hand off to a background worker and stream\ntheir tail through that SSE endpoint. Failed dispatches still mint an\n`operation_id` so the audit log and any partial SSE events stay\ncorrelatable.\n\n`TResult` parameterizes `result` so per-op response shapes surface in\nOpenAPI. Operations that pin `OperationSpec.result_type` get\n`OperationEnvelope[YourEnvelope]` as their response model; the rest keep\nthe default `Any` shape (`result: any | null` on the wire).",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/robosystems-ai-connections-api-openapi.yml#/components/schemas/OperationEnvelope",
  "properties": {
    "operation": {
      "type": "string",
      "title": "Operation",
      "description": "Kebab-case operation name"
    },
    "operationId": {
      "type": "string",
      "title": "Operationid",
      "description": "op_-prefixed ULID for audit and SSE correlation"
    },
    "status": {
      "type": "string",
      "enum": [
        "completed",
        "pending",
        "failed"
      ],
      "title": "Status",
      "description": "Operation lifecycle state"
    },
    "result": {
      "anyOf": [
        {},
        {
          "type": "null"
        }
      ],
      "title": "Result",
      "description": "Command-specific result payload"
    },
    "at": {
      "type": "string",
      "title": "At",
      "description": "ISO-8601 UTC timestamp"
    },
    "createdBy": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Createdby",
      "description": "User ID that initiated the operation"
    },
    "idempotentReplay": {
      "type": "boolean",
      "title": "Idempotentreplay",
      "description": "True when this envelope came from the idempotency cache — the underlying command did not execute again. False on fresh executions.",
      "default": false
    }
  },
  "type": "object",
  "required": [
    "operation",
    "operationId",
    "status",
    "at"
  ]
}