import {
  AckWorkRequestSchema,
  AddResourceRequestSchema,
  AddUpstreamKeyRequestSchema,
  AgentDeletedResponseSchema,
  AgentListResponseSchema,
  AgentSchema,
  ApiKeyActivityResponseSchema,
  ApiKeyCreatedSchema,
  ApiKeyListResponseSchema,
  ApiKeyRevokedResponseSchema,
  ApiKeySchema,
  ApiMetricsResponseSchema,
  AuditListResponseSchema,
  BatchRequestSchema,
  BatchResponseSchema,
  CreateAgentRequestSchema,
  CreateApiKeyRequestSchema,
  CreateCredentialRequestSchema,
  CreateEnvironmentRequestSchema,
  CreateMemoryRequestSchema,
  CreateMemoryStoreRequestSchema,
  CreateSessionRequestSchema,
  CreateSkillVersionRequestSchema,
  CreateTenantRequestSchema,
  CreateVaultRequestSchema,
  CredentialDeletedResponseSchema,
  CredentialListResponseSchema,
  EnrollmentUrlRequestSchema,
  EnrollmentUrlResponseSchema,
  EnvironmentDeletedResponseSchema,
  EnvironmentListResponseSchema,
  EnvironmentSchema,
  ErrorEnvelopeSchema,
  EventListResponseSchema,
  FileDeletedResponseSchema,
  FileListResponseSchema,
  FileRecordSchema,
  LicenseResponseSchema,
  McpOauthValidationResultSchema,
  MemoryDeletedResponseSchema,
  MemoryListResponseSchema,
  MemorySchema,
  MemoryStoreDeletedResponseSchema,
  MemoryStoreListResponseSchema,
  MemoryStoreSchema,
  MemoryVersionListResponseSchema,
  MemoryVersionSchema,
  MetricsResponseSchema,
  ModelEntrySchema,
  ModelListResponseSchema,
  PatchApiKeyRequestSchema,
  PatchTenantRequestSchema,
  PatchUpstreamKeyRequestSchema,
  PollWorkResponseSchema,
  ProviderStatusResponseSchema,
  PutSettingRequestSchema,
  ResourceDeletedResponseSchema,
  ResourceListResponseSchema,
  SessionDeletedResponseSchema,
  SessionListResponseSchema,
  SessionResourceSchema,
  SessionSchema,
  SessionStatusSchema,
  SetVaultEntryRequestSchema,
  SettingResponseSchema,
  SkillDeletedResponseSchema,
  SkillListResponseSchema,
  SkillSchema,
  SkillVersionDeletedResponseSchema,
  SkillVersionListResponseSchema,
  SkillVersionSchema,
  SkillsCatalogResponseSchema,
  SkillsSourcesResponseSchema,
  SkillsStatsResponseSchema,
  StopWorkRequestSchema,
  TenantArchivedResponseSchema,
  TenantListResponseSchema,
  TenantSchema,
  TraceDetailSchema,
  TraceExportResponseSchema,
  TraceListResponseSchema,
  UpdateAgentRequestSchema,
  UpdateCredentialRequestSchema,
  UpdateEnvironmentRequestSchema,
  UpdateMemoryRequestSchema,
  UpdateSessionRequestSchema,
  UpdateVaultRequestSchema,
  UpdateWorkRequestSchema,
  UpstreamKeyDeletedResponseSchema,
  UpstreamKeyListResponseSchema,
  UpstreamKeySchema,
  UserEventAppendResponseSchema,
  UserEventBatchRequestSchema,
  UserProfileCreateSchema,
  UserProfileListSchema,
  UserProfileSchema,
  UserProfileUpdateSchema,
  VaultCredentialSchema,
  VaultDeletedResponseSchema,
  VaultEntryDeletedResponseSchema,
  VaultEntryListResponseSchema,
  VaultEntrySchema,
  VaultListResponseSchema,
  VaultSchema,
  WhoamiResponseSchema,
  WorkItemListResponseSchema,
  WorkItemSchema,
  WorkQueueStatsSchema,
  WorkStateSchema
} from "./chunk-5EP4ETN5.js";
import {
  registry
} from "./chunk-7346CKTF.js";

// src/openapi/spec.ts
import { z } from "zod";
import { OpenApiGeneratorV31 } from "@asteasolutions/zod-to-openapi";
registry.registerComponent("securitySchemes", "ApiKey", {
  type: "apiKey",
  in: "header",
  name: "x-api-key",
  description: "Gateway-issued API key (`ck_*`). When passthrough is enabled, `sk-ant-api*` keys are also accepted on Anthropic-mirror routes and forwarded transparently to api.anthropic.com."
});
var ErrorResponses = {
  400: { description: "Bad request", content: { "application/json": { schema: ErrorEnvelopeSchema } } },
  401: {
    description: "Missing or invalid API key",
    content: { "application/json": { schema: ErrorEnvelopeSchema } }
  },
  404: {
    description: "Resource not found",
    content: { "application/json": { schema: ErrorEnvelopeSchema } }
  },
  409: {
    description: "Conflict (e.g. environment has attached sessions)",
    content: { "application/json": { schema: ErrorEnvelopeSchema } }
  },
  500: {
    description: "Server error",
    content: { "application/json": { schema: ErrorEnvelopeSchema } }
  }
};
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/agents",
  tags: ["Agents"],
  summary: "Create an agent",
  security: [{ ApiKey: [] }],
  request: {
    body: {
      required: true,
      content: { "application/json": { schema: CreateAgentRequestSchema } }
    }
  },
  responses: {
    201: {
      description: "Agent created",
      content: { "application/json": { schema: AgentSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/agents",
  tags: ["Agents"],
  summary: "List agents",
  security: [{ ApiKey: [] }],
  request: {
    query: z.object({
      limit: z.coerce.number().int().min(1).max(100).optional(),
      order: z.enum(["asc", "desc"]).optional(),
      page: z.string().optional().describe("ULID cursor for pagination"),
      include_archived: z.enum(["true", "false"]).optional()
    })
  },
  responses: {
    200: {
      description: "A page of agents",
      content: { "application/json": { schema: AgentListResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/agents/{id}",
  tags: ["Agents"],
  summary: "Retrieve an agent (optionally a specific version)",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string() }),
    query: z.object({ version: z.coerce.number().int().optional() })
  },
  responses: {
    200: {
      description: "Agent retrieved",
      content: { "application/json": { schema: AgentSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/agents/{id}",
  tags: ["Agents"],
  summary: "Update an agent (creates a new version)",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string() }),
    body: {
      required: true,
      content: { "application/json": { schema: UpdateAgentRequestSchema } }
    }
  },
  responses: {
    200: {
      description: "Agent updated",
      content: { "application/json": { schema: AgentSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "delete",
  path: "/anthropic/v1/agents/{id}",
  tags: ["Agents"],
  summary: "Archive an agent",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Agent archived",
      content: { "application/json": { schema: AgentDeletedResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/agents/{id}/archive",
  tags: ["Agents"],
  summary: "Archive an agent (returns the archived agent)",
  description: "Archives the agent and returns the full agent object with `archived_at` set.",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Agent archived",
      content: { "application/json": { schema: AgentSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/agents/{id}/versions",
  tags: ["Agents"],
  summary: "List agent versions",
  description: "Returns a paginated list of all versions of this agent, ordered by version number descending.",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string() }),
    query: z.object({
      limit: z.coerce.number().int().min(1).max(100).optional(),
      page: z.string().optional().describe("Cursor for pagination (base64url-encoded version number)")
    })
  },
  responses: {
    200: {
      description: "A page of agent versions",
      content: { "application/json": { schema: AgentListResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/environments",
  tags: ["Environments"],
  summary: "Create an environment",
  description: 'Returns immediately with `state: "preparing"`. Poll `GET /v1/environments/{id}` until `state` becomes `ready` before creating a session against it.',
  security: [{ ApiKey: [] }],
  request: {
    body: {
      required: true,
      content: { "application/json": { schema: CreateEnvironmentRequestSchema } }
    }
  },
  responses: {
    201: {
      description: "Environment created; async setup in progress",
      content: { "application/json": { schema: EnvironmentSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/environments",
  tags: ["Environments"],
  summary: "List environments",
  security: [{ ApiKey: [] }],
  request: {
    query: z.object({
      limit: z.coerce.number().int().min(1).max(100).optional(),
      order: z.enum(["asc", "desc"]).optional(),
      page: z.string().optional(),
      include_archived: z.enum(["true", "false"]).optional()
    })
  },
  responses: {
    200: {
      description: "A page of environments",
      content: { "application/json": { schema: EnvironmentListResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/environments/{id}",
  tags: ["Environments"],
  summary: "Retrieve an environment",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Environment retrieved",
      content: { "application/json": { schema: EnvironmentSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/environments/{id}",
  tags: ["Environments"],
  summary: "Update an environment",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string() }),
    body: {
      required: true,
      content: { "application/json": { schema: UpdateEnvironmentRequestSchema } }
    }
  },
  responses: {
    200: {
      description: "Environment updated",
      content: { "application/json": { schema: EnvironmentSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "delete",
  path: "/anthropic/v1/environments/{id}",
  tags: ["Environments"],
  summary: "Delete an environment",
  description: "Returns 409 if the environment has non-terminated sessions still attached.",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Environment deleted",
      content: { "application/json": { schema: EnvironmentDeletedResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/environments/{id}/archive",
  tags: ["Environments"],
  summary: "Archive an environment",
  description: "Returns 409 if the environment has non-terminated sessions still attached (same guard as DELETE).",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Environment archived",
      content: { "application/json": { schema: EnvironmentSchema } }
    },
    ...ErrorResponses
  }
});
var WORK_NOTE = 'Only available on environments with `config.type = "self_hosted"`. Returns 400 (`bad_request`) on cloud environments. Self-hosted runners poll for work, ack to claim, heartbeat while active, and ack-complete or stop when done.';
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/environments/{id}/work",
  tags: ["Work"],
  summary: "List work items in an environment",
  description: WORK_NOTE,
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string() }),
    query: z.object({
      state: WorkStateSchema.optional().describe("Filter by lifecycle state."),
      limit: z.coerce.number().int().min(1).max(100).optional(),
      after_id: z.string().optional().describe("Opaque pagination cursor returned by a prior call.")
    })
  },
  responses: {
    200: {
      description: "Work item list",
      content: { "application/json": { schema: WorkItemListResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/environments/{id}/work/poll",
  tags: ["Work"],
  summary: "Poll for the next queued work item",
  description: WORK_NOTE + " Returns the next `queued` item and atomically moves it to `pending`. Pass `worker_id` to record the claiming worker. If the queue is empty, returns `{data: null}`.",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string() }),
    query: z.object({
      worker_id: z.string().optional().describe("Identifier of the polling worker.")
    })
  },
  responses: {
    200: {
      description: "Reserved work item (or null when empty)",
      content: { "application/json": { schema: PollWorkResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/environments/{id}/work/stats",
  tags: ["Work"],
  summary: "Get queue stats",
  description: WORK_NOTE,
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Queue stats",
      content: { "application/json": { schema: WorkQueueStatsSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/environments/{id}/work/{workId}",
  tags: ["Work"],
  summary: "Get a work item",
  description: WORK_NOTE,
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string(), workId: z.string() }) },
  responses: {
    200: {
      description: "Work item",
      content: { "application/json": { schema: WorkItemSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/environments/{id}/work/{workId}",
  tags: ["Work"],
  summary: "Update work-item metadata",
  description: WORK_NOTE + " Set keys with string values; set a key to `null` to delete it. Other lifecycle fields are immutable here \u2014 use the dedicated `/ack`, `/heartbeat`, `/stop` sub-paths.",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string(), workId: z.string() }),
    body: {
      required: true,
      content: { "application/json": { schema: UpdateWorkRequestSchema } }
    }
  },
  responses: {
    200: {
      description: "Updated work item",
      content: { "application/json": { schema: WorkItemSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/environments/{id}/work/{workId}/ack",
  tags: ["Work"],
  summary: "Acknowledge a polled work item",
  description: WORK_NOTE + " Confirms the worker has accepted responsibility for the item and moves it from `pending` to `active`. Must be called within the pending grace window or the item is requeued for another worker.",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string(), workId: z.string() }),
    body: {
      required: false,
      content: { "application/json": { schema: AckWorkRequestSchema } }
    }
  },
  responses: {
    200: {
      description: "Acknowledged",
      content: { "application/json": { schema: WorkItemSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/environments/{id}/work/{workId}/heartbeat",
  tags: ["Work"],
  summary: "Heartbeat an active work item",
  description: WORK_NOTE + " Updates `latest_heartbeat_at`. Workers that stop heartbeating within the heartbeat window are considered dead and their items are requeued.",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string(), workId: z.string() }) },
  responses: {
    200: {
      description: "Heartbeat accepted",
      content: { "application/json": { schema: WorkItemSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/environments/{id}/work/{workId}/stop",
  tags: ["Work"],
  summary: "Stop a work item",
  description: WORK_NOTE + " `force: false` (default) requests a graceful stop \u2014 sets `stop_requested_at` and waits for the worker to ack. `force: true` immediately marks the item stopped.",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string(), workId: z.string() }),
    body: {
      required: false,
      content: { "application/json": { schema: StopWorkRequestSchema } }
    }
  },
  responses: {
    200: {
      description: "Stop requested",
      content: { "application/json": { schema: WorkItemSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/sessions",
  tags: ["Sessions"],
  summary: "Create a session",
  description: "Creates a session idle and pinned to the specified agent version + environment. A sandbox is NOT allocated until the first user.message event.",
  security: [{ ApiKey: [] }],
  request: {
    body: {
      required: true,
      content: { "application/json": { schema: CreateSessionRequestSchema } }
    }
  },
  responses: {
    201: {
      description: "Session created",
      content: { "application/json": { schema: SessionSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/sessions",
  tags: ["Sessions"],
  summary: "List sessions",
  security: [{ ApiKey: [] }],
  request: {
    query: z.object({
      limit: z.coerce.number().int().min(1).max(100).optional(),
      order: z.enum(["asc", "desc"]).optional(),
      page: z.string().optional().describe("ULID cursor for pagination"),
      include_archived: z.enum(["true", "false"]).optional(),
      agent_id: z.string().optional(),
      agent_version: z.coerce.number().int().optional(),
      environment_id: z.string().optional(),
      status: SessionStatusSchema.optional().describe("Filter by single status (deprecated, use statuses)"),
      statuses: z.string().optional().describe("Comma-separated or repeated status filter, e.g. statuses=idle,running"),
      "created_at[gt]": z.string().optional(),
      "created_at[gte]": z.string().optional(),
      "created_at[lt]": z.string().optional(),
      "created_at[lte]": z.string().optional()
    })
  },
  responses: {
    200: {
      description: "A page of sessions",
      content: { "application/json": { schema: SessionListResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/sessions/{id}",
  tags: ["Sessions"],
  summary: "Retrieve a session",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Session retrieved",
      content: { "application/json": { schema: SessionSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/sessions/{id}",
  tags: ["Sessions"],
  summary: "Update session title / metadata",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string() }),
    body: {
      required: true,
      content: { "application/json": { schema: UpdateSessionRequestSchema } }
    }
  },
  responses: {
    200: {
      description: "Session updated",
      content: { "application/json": { schema: SessionSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "delete",
  path: "/anthropic/v1/sessions/{id}",
  tags: ["Sessions"],
  summary: "Delete (terminate) a session",
  description: 'Interrupts any in-flight turn, releases the sandbox, and flips the session to `terminated` with `stop_reason:"deleted"`.',
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Session deleted",
      content: { "application/json": { schema: SessionDeletedResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/sessions/{id}/archive",
  tags: ["Sessions"],
  summary: "Archive a session",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Session archived",
      content: { "application/json": { schema: SessionSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/sessions/{id}/events",
  tags: ["Events"],
  summary: "Append user events to a session",
  description: "Atomically appends a batch of user events. `user.message` events buffered while a turn is running are drained as a subsequent turn. Supports `user.message`, `user.interrupt`, `user.custom_tool_result`, `user.tool_confirmation` (requires confirmation_mode), and `user.define_outcome` (triggers grader loop).",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string() }),
    headers: z.object({
      "idempotency-key": z.string().optional().describe("Per-event key is built as `<idempotency-key>:<batch index>`.")
    }),
    body: {
      required: true,
      content: { "application/json": { schema: UserEventBatchRequestSchema } }
    }
  },
  responses: {
    200: {
      description: "Events appended",
      content: { "application/json": { schema: UserEventAppendResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/sessions/{id}/events",
  tags: ["Events"],
  summary: "List a session's event history",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string() }),
    query: z.object({
      limit: z.coerce.number().int().min(1).max(500).optional(),
      order: z.enum(["asc", "desc"]).optional(),
      after_seq: z.coerce.number().int().optional()
    })
  },
  responses: {
    200: {
      description: "A page of events",
      content: { "application/json": { schema: EventListResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/sessions/{id}/events/stream",
  tags: ["Events"],
  summary: "Stream a session's events via Server-Sent Events",
  description: 'Long-lived `text/event-stream` response. Each emitted event sets an `id:` field with the monotonic `seq`, so `EventSource` clients resume automatically via `Last-Event-ID`. A `data: {"type":"ping"}` keepalive is written every 15 seconds. On reconnect, the server backfills events with `seq > Last-Event-ID` from the DB before tailing live.',
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string() }),
    headers: z.object({
      "last-event-id": z.string().optional().describe("EventSource auto-populates this on reconnect; falls back to ?after_seq")
    }),
    query: z.object({
      after_seq: z.coerce.number().int().optional()
    })
  },
  responses: {
    200: {
      description: "SSE stream opened",
      content: {
        "text/event-stream": {
          schema: z.string().openapi({
            description: "Each frame is `id: <seq>\\nevent: <type>\\ndata: <json>\\n\\n`. JSON shape conforms to ManagedEvent."
          })
        }
      }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/sessions/{id}/threads",
  tags: ["Sessions"],
  summary: "List child thread sessions",
  description: "Returns sessions spawned as child threads of this session via the spawn_agent tool.",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string() }),
    query: z.object({
      limit: z.coerce.number().int().min(1).max(100).optional(),
      order: z.enum(["asc", "desc"]).optional()
    })
  },
  responses: {
    200: {
      description: "Child thread sessions",
      content: { "application/json": { schema: SessionListResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/sessions/{id}/threads/{tid}",
  tags: ["Sessions"],
  summary: "Get a thread session",
  description: "Retrieve a single child-thread session by id.",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string(), tid: z.string() }) },
  responses: {
    200: {
      description: "Thread session",
      content: { "application/json": { schema: SessionSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/sessions/{id}/threads/{tid}/archive",
  tags: ["Sessions"],
  summary: "Archive a thread session",
  description: "Soft-delete a child-thread session.",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string(), tid: z.string() }) },
  responses: {
    200: {
      description: "Thread archived",
      content: { "application/json": { schema: SessionSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/sessions/{id}/threads/{tid}/events",
  tags: ["Events"],
  summary: "List events for a thread",
  description: "Replay the recorded event log for a specific child thread.",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string(), tid: z.string() }),
    query: z.object({
      after_seq: z.coerce.number().int().optional(),
      limit: z.coerce.number().int().min(1).max(500).optional()
    })
  },
  responses: {
    200: {
      description: "Thread events",
      content: { "application/json": { schema: EventListResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/sessions/{id}/threads/{tid}/stream",
  tags: ["Events"],
  summary: "Server-Sent Events stream for a thread",
  description: 'Long-lived SSE connection delivering thread events as they arrive. Each event arrives as `event: <type>\\ndata: <json>\\n\\n`; the connection emits `data: {"type":"ping"}` every 15s as keepalive. Disconnect by closing the HTTP connection.',
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string(), tid: z.string() }),
    query: z.object({ after_seq: z.coerce.number().int().optional() })
  },
  responses: {
    200: {
      description: "SSE stream",
      content: { "text/event-stream": { schema: z.string() } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/sessions/{id}/resources",
  tags: ["Resources"],
  summary: "Add a resource to a session",
  description: "Attaches a resource (URI, text, file, or GitHub repo) to a session. Resources are provisioned into the container at turn start.",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string() }),
    body: {
      required: true,
      content: { "application/json": { schema: AddResourceRequestSchema } }
    }
  },
  responses: {
    201: {
      description: "Resource added",
      content: { "application/json": { schema: SessionResourceSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/sessions/{id}/resources",
  tags: ["Resources"],
  summary: "List session resources",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Session resources",
      content: { "application/json": { schema: ResourceListResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/sessions/{id}/resources/{rid}",
  tags: ["Resources"],
  summary: "Get a single session resource",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string(), rid: z.string() }) },
  responses: {
    200: {
      description: "Resource retrieved",
      content: { "application/json": { schema: SessionResourceSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "delete",
  path: "/anthropic/v1/sessions/{id}/resources/{rid}",
  tags: ["Resources"],
  summary: "Remove a resource from a session",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string(), rid: z.string() }) },
  responses: {
    200: {
      description: "Resource removed",
      content: { "application/json": { schema: ResourceDeletedResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/files",
  tags: ["Files"],
  summary: "Upload a file",
  description: "Accepts multipart/form-data with a `file` field, or a raw body with the file content. Use `?scope_id=<session_id>` to scope to a session.",
  security: [{ ApiKey: [] }],
  request: {
    query: z.object({
      filename: z.string().optional().describe("Filename for raw body uploads."),
      scope_id: z.string().optional().describe("Session ID to scope the file to."),
      scope_type: z.string().optional().describe("Scope type. Defaults to 'session'.")
    })
  },
  responses: {
    201: {
      description: "File uploaded",
      content: { "application/json": { schema: FileRecordSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/files",
  tags: ["Files"],
  summary: "List files",
  security: [{ ApiKey: [] }],
  request: {
    query: z.object({
      limit: z.coerce.number().int().min(1).max(500).optional(),
      scope_id: z.string().optional().describe("Session ID to filter by scope."),
      after_id: z.string().optional().describe("Cursor: return files after this ID (for forward pagination)."),
      before_id: z.string().optional().describe("Cursor: return files before this ID (for backward pagination).")
    })
  },
  responses: {
    200: {
      description: "List of file records with pagination",
      content: { "application/json": { schema: FileListResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/files/{id}",
  tags: ["Files"],
  summary: "Get file metadata",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "File metadata",
      content: { "application/json": { schema: FileRecordSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/files/{id}/content",
  tags: ["Files"],
  summary: "Download file content",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "File content as binary stream",
      content: {
        "application/octet-stream": {
          schema: z.string().openapi({ description: "Raw file bytes." })
        }
      }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "delete",
  path: "/anthropic/v1/files/{id}",
  tags: ["Files"],
  summary: "Delete a file",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "File deleted",
      content: { "application/json": { schema: FileDeletedResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/vaults",
  tags: ["Vaults"],
  summary: "Create a vault",
  security: [{ ApiKey: [] }],
  request: {
    body: {
      required: true,
      content: { "application/json": { schema: CreateVaultRequestSchema } }
    }
  },
  responses: {
    201: {
      description: "Vault created",
      content: { "application/json": { schema: VaultSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/vaults",
  tags: ["Vaults"],
  summary: "List vaults",
  security: [{ ApiKey: [] }],
  request: {
    query: z.object({
      agent_id: z.string().optional().describe("Filter by agent ID")
    })
  },
  responses: {
    200: {
      description: "A list of vaults",
      content: { "application/json": { schema: VaultListResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/vaults/{id}",
  tags: ["Vaults"],
  summary: "Retrieve a vault",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Vault retrieved",
      content: { "application/json": { schema: VaultSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/vaults/{id}",
  tags: ["Vaults"],
  summary: "Update a vault",
  description: "Updates vault display_name and/or metadata.",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string() }),
    body: {
      required: true,
      content: { "application/json": { schema: UpdateVaultRequestSchema } }
    }
  },
  responses: {
    200: {
      description: "Vault updated",
      content: { "application/json": { schema: VaultSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "delete",
  path: "/anthropic/v1/vaults/{id}",
  tags: ["Vaults"],
  summary: "Delete a vault and all its entries",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Vault deleted",
      content: { "application/json": { schema: VaultDeletedResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/vaults/{id}/archive",
  tags: ["Vaults"],
  summary: "Archive a vault",
  description: "Archives the vault and returns the full vault object with `archived_at` set.",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Vault archived",
      content: { "application/json": { schema: VaultSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/vaults/{id}/credentials",
  tags: ["Credentials"],
  summary: "Create an MCP-server credential (Anthropic CMA-compat)",
  description: "Creates an MCP-shaped credential record. **Reach for this when you have an MCP server URL plus an auth token** (OAuth, bearer, etc.). The token is encrypted at rest, never returned in responses, and automatically injected as MCP auth during sessions that attach this vault.\n\nIf your token is a plain env-var-style secret (`SPRITE_TOKEN`, `ANTHROPIC_API_KEY`, custom API keys) **not** associated with a specific MCP server URL, use `PUT /vaults/{id}/entries/{key}` (AgentStep extension) instead. Entries are injected as env vars into the container at session time and don't require an `mcp_server_url`.",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string() }),
    body: {
      required: true,
      content: { "application/json": { schema: CreateCredentialRequestSchema } }
    }
  },
  responses: {
    201: {
      description: "Credential created",
      content: { "application/json": { schema: VaultCredentialSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/vaults/{id}/credentials",
  tags: ["Credentials"],
  summary: "List vault credentials",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Credential list",
      content: { "application/json": { schema: CredentialListResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/vaults/{id}/credentials/{credId}",
  tags: ["Credentials"],
  summary: "Get a vault credential",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string(), credId: z.string() }) },
  responses: {
    200: {
      description: "Credential retrieved",
      content: { "application/json": { schema: VaultCredentialSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/vaults/{id}/credentials/{credId}",
  tags: ["Credentials"],
  summary: "Update a vault credential",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string(), credId: z.string() }),
    body: {
      required: true,
      content: { "application/json": { schema: UpdateCredentialRequestSchema } }
    }
  },
  responses: {
    200: {
      description: "Credential updated",
      content: { "application/json": { schema: VaultCredentialSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "delete",
  path: "/anthropic/v1/vaults/{id}/credentials/{credId}",
  tags: ["Credentials"],
  summary: "Delete a vault credential",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string(), credId: z.string() }) },
  responses: {
    200: {
      description: "Credential deleted",
      content: { "application/json": { schema: CredentialDeletedResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/vaults/{id}/credentials/{credId}/mcp_oauth_validate",
  tags: ["Credentials"],
  summary: "Validate an MCP OAuth credential",
  description: "Round-trips the credential's refresh token against the configured token endpoint and reports whether it still authenticates. Only valid for credentials with `auth.type = \"mcp_oauth\"`. Returns 200 with `{ valid: true|false, error? }` \u2014 the upstream provider's failure is surfaced in `error`, not as an HTTP error.",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string(), credId: z.string() }) },
  responses: {
    200: {
      description: "Validation result",
      content: { "application/json": { schema: McpOauthValidationResultSchema } }
    },
    ...ErrorResponses
  }
});
var ENTRIES_EXTENSION_NOTE = "**AgentStep extension \u2014 not part of Anthropic CMA.** The official Anthropic Managed Agents API exposes only `/credentials` (MCP-shaped, requires `mcp_server_url`). Entries are an AgentStep addition for raw key/value secrets that need to appear as environment variables inside the session container (e.g. `SPRITE_TOKEN`, `ANTHROPIC_API_KEY`, custom API keys). The Anthropic SDK won't expose these \u2014 call via raw HTTP or `@agentstep/agent-sdk` (`setEntry`, `listEntries`, etc.).";
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/vaults/{id}/entries",
  tags: ["Vaults"],
  summary: "List vault entries (AgentStep extension)",
  description: "Lists the metadata for each entry in the vault (key names, timestamps). **Never returns plaintext values** \u2014 use `GET /entries/{key}` for the decrypted value.\n\n" + ENTRIES_EXTENSION_NOTE,
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "A list of vault entries",
      content: { "application/json": { schema: VaultEntryListResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/vaults/{id}/entries/{key}",
  tags: ["Vaults"],
  summary: "Get a vault entry (AgentStep extension)",
  description: "Returns the decrypted value for a single entry. The value is encrypted at rest with `VAULT_ENCRYPTION_KEY`; this endpoint is the only path that decrypts it.\n\n" + ENTRIES_EXTENSION_NOTE,
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string(), key: z.string() }) },
  responses: {
    200: {
      description: "Vault entry retrieved",
      content: { "application/json": { schema: VaultEntrySchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "put",
  path: "/anthropic/v1/vaults/{id}/entries/{key}",
  tags: ["Vaults"],
  summary: "Set a raw env-var entry e.g. SPRITE_TOKEN (AgentStep extension)",
  description: "Upserts a raw key/value entry. The key (URL path) becomes the env-var name; the value (body) is the secret. At session-create time the SDK injects every entry from the agent's attached vault(s) into the container as environment variables, so the agent runtime sees `process.env.SPRITE_TOKEN === \"<value>\"`.\n\n**Use cases:** sprites/apple-container/docker provider auth tokens, additional API keys an agent needs at runtime, custom env vars referenced by MCP servers declared on the agent.\n\n**Don't use for MCP server auth** \u2014 for that, `POST /vaults/{id}/credentials` is the right path (structured shape with `mcp_server_url`, auto-injection into the MCP client transport, Anthropic CMA-compatible).\n\n" + ENTRIES_EXTENSION_NOTE,
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string(), key: z.string() }),
    body: {
      required: true,
      content: { "application/json": { schema: SetVaultEntryRequestSchema } }
    }
  },
  responses: {
    200: {
      description: "Entry set",
      content: { "application/json": { schema: VaultEntrySchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "delete",
  path: "/anthropic/v1/vaults/{id}/entries/{key}",
  tags: ["Vaults"],
  summary: "Delete a vault entry (AgentStep extension)",
  description: ENTRIES_EXTENSION_NOTE,
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string(), key: z.string() }) },
  responses: {
    200: {
      description: "Entry deleted",
      content: { "application/json": { schema: VaultEntryDeletedResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/memory_stores",
  tags: ["Memory"],
  summary: "Create a memory store",
  security: [{ ApiKey: [] }],
  request: {
    body: {
      required: true,
      content: { "application/json": { schema: CreateMemoryStoreRequestSchema } }
    }
  },
  responses: {
    201: {
      description: "Memory store created",
      content: { "application/json": { schema: MemoryStoreSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/memory_stores",
  tags: ["Memory"],
  summary: "List memory stores",
  security: [{ ApiKey: [] }],
  request: {
    query: z.object({
      agent_id: z.string().optional().describe("Filter by agent ID")
    })
  },
  responses: {
    200: {
      description: "Memory store list",
      content: { "application/json": { schema: MemoryStoreListResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/memory_stores/{id}",
  tags: ["Memory"],
  summary: "Get a memory store",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Memory store retrieved",
      content: { "application/json": { schema: MemoryStoreSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "delete",
  path: "/anthropic/v1/memory_stores/{id}",
  tags: ["Memory"],
  summary: "Delete a memory store",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Memory store deleted",
      content: { "application/json": { schema: MemoryStoreDeletedResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/memory_stores/{id}/memories",
  tags: ["Memory"],
  summary: "Create or upsert a memory",
  description: "Creates a new memory at the given path, or upserts if the path already exists in this store.",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string() }),
    body: {
      required: true,
      content: { "application/json": { schema: CreateMemoryRequestSchema } }
    }
  },
  responses: {
    201: {
      description: "Memory created",
      content: { "application/json": { schema: MemorySchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/memory_stores/{id}/memories",
  tags: ["Memory"],
  summary: "List memories in a store",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Memory list",
      content: { "application/json": { schema: MemoryListResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/memory_stores/{id}/memories/{memId}",
  tags: ["Memory"],
  summary: "Get a memory",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string(), memId: z.string() }) },
  responses: {
    200: {
      description: "Memory retrieved",
      content: { "application/json": { schema: MemorySchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "patch",
  path: "/anthropic/v1/memory_stores/{id}/memories/{memId}",
  tags: ["Memory"],
  summary: "Update a memory's content",
  description: "Updates the content of a memory. Optionally provide `content_sha256` for optimistic concurrency \u2014 returns 409 if the hash doesn't match.",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string(), memId: z.string() }),
    body: {
      required: true,
      content: { "application/json": { schema: UpdateMemoryRequestSchema } }
    }
  },
  responses: {
    200: {
      description: "Memory updated",
      content: { "application/json": { schema: MemorySchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "delete",
  path: "/anthropic/v1/memory_stores/{id}/memories/{memId}",
  tags: ["Memory"],
  summary: "Delete a memory",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string(), memId: z.string() }) },
  responses: {
    200: {
      description: "Memory deleted",
      content: { "application/json": { schema: MemoryDeletedResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/memory_stores/{id}/archive",
  tags: ["Memory"],
  summary: "Archive a memory store",
  description: "Soft-deletes a memory store: keeps memories readable but blocks new writes. Reversible via PATCH on the store record.",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Memory store archived",
      content: { "application/json": { schema: MemoryStoreSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/memory_stores/{id}/memory_versions",
  tags: ["Memory"],
  summary: "List memory versions",
  description: "Audit log of every create/update/delete on memories in this store. Filter to a single memory with `memory_id`.",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string() }),
    query: z.object({
      memory_id: z.string().optional().describe("Restrict to versions of a single memory."),
      limit: z.coerce.number().int().min(1).max(500).optional(),
      cursor: z.string().optional().describe("Opaque pagination cursor returned by a prior call.")
    })
  },
  responses: {
    200: {
      description: "Memory versions",
      content: { "application/json": { schema: MemoryVersionListResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/memory_stores/{id}/memory_versions/{vid}",
  tags: ["Memory"],
  summary: "Get a memory version",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string(), vid: z.string() }) },
  responses: {
    200: {
      description: "Memory version",
      content: { "application/json": { schema: MemoryVersionSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/memory_stores/{id}/memory_versions/{vid}/redact",
  tags: ["Memory"],
  summary: "Redact a memory version",
  description: "Strips the `content` field from this version's audit row. Cannot redact the current head of a live memory \u2014 redact a successor version first or delete the memory. Returns the (now-redacted) version.",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string(), vid: z.string() }) },
  responses: {
    200: {
      description: "Memory version redacted",
      content: { "application/json": { schema: MemoryVersionSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/v1/skills/catalog",
  tags: ["Skills"],
  summary: "Get skills catalog (legacy feed)",
  description: "Returns top skills from the feed, grouped by leaderboard.",
  security: [{ ApiKey: [] }],
  request: {
    query: z.object({
      leaderboard: z.enum(["trending", "hot", "allTime"]).optional().describe("Leaderboard to query. Defaults to 'trending'."),
      limit: z.coerce.number().int().optional()
    })
  },
  responses: {
    200: {
      description: "Skills catalog",
      content: { "application/json": { schema: SkillsCatalogResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/skills",
  tags: ["Skills"],
  summary: "List the caller's uploaded skills",
  description: "Returns a paginated list of skills uploaded by this tenant. Anthropic Managed Agents convention. The community catalog (skills.sh index) lives at /v1/skills/catalog \u2014 see also /v1/skills/feed, /sources, /stats. To search the catalog, use /v1/skills/index?q=\u2026",
  security: [{ ApiKey: [] }],
  request: {
    query: z.object({
      limit: z.coerce.number().int().min(1).max(100).optional().describe("Page size (default 20)."),
      after_id: z.string().optional().describe("Pagination cursor."),
      include_archived: z.coerce.boolean().optional().describe("Include archived skills (default false).")
    })
  },
  responses: {
    200: {
      description: "Paginated list of skills",
      content: { "application/json": { schema: SkillListResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/skills",
  tags: ["Skills"],
  summary: "Create a skill (multipart upload)",
  description: "Uploads a SKILL.md or .zip bundle as a new standalone skill. The first version is created automatically (1.0.0). Use POST /v1/skills/{id}/versions to add subsequent versions. The multipart body matches Anthropic's deploy-managed-agent.sh shape (`display_title` + `files=@path` or `files[]=@path`); a JSON body with `{ name, description?, content, tenant_id? }` is also accepted.",
  security: [{ ApiKey: [] }],
  request: {
    body: {
      content: {
        "multipart/form-data": {
          schema: z.object({
            display_title: z.string(),
            files: z.unknown().openapi({ format: "binary", description: "SKILL.md or .zip bundle. `files[]` is also accepted." })
          })
        },
        "application/json": {
          schema: z.object({
            name: z.string(),
            description: z.string().optional(),
            content: z.string(),
            tenant_id: z.string().optional()
          })
        }
      }
    }
  },
  responses: {
    201: {
      description: "Skill created",
      content: { "application/json": { schema: SkillSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/skills/{id}",
  tags: ["Skills"],
  summary: "Get a skill by id",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Skill",
      content: { "application/json": { schema: SkillSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "delete",
  path: "/anthropic/v1/skills/{id}",
  tags: ["Skills"],
  summary: "Delete a skill",
  description: "Hard-deletes the skill and all its versions.",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Skill deleted",
      content: { "application/json": { schema: SkillDeletedResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/skills/{id}/versions",
  tags: ["Skills"],
  summary: "List versions of a skill",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string() }),
    query: z.object({
      limit: z.coerce.number().int().min(1).max(100).optional(),
      after_id: z.string().optional()
    })
  },
  responses: {
    200: {
      description: "Paginated list of skill versions",
      content: { "application/json": { schema: SkillVersionListResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/skills/{id}/versions",
  tags: ["Skills"],
  summary: "Create a new version of a skill",
  description: "Appends a new version. Auto-increments from the current version if no explicit `version` is supplied.",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string() }),
    body: { content: { "application/json": { schema: CreateSkillVersionRequestSchema } } }
  },
  responses: {
    201: {
      description: "Skill version created",
      content: { "application/json": { schema: SkillVersionSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/skills/{id}/versions/{version}",
  tags: ["Skills"],
  summary: "Get a specific version of a skill",
  description: 'Returns version metadata + content. Pass `version: latest` to resolve to the skill\'s current version without pinning to a specific string \u2014 the recommended pattern for agent tool refs `{ type: "custom", skill_id, version: "latest" }`.',
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({
      id: z.string(),
      version: z.string().describe("Version string or the literal `latest`.")
    })
  },
  responses: {
    200: {
      description: "Skill version",
      content: { "application/json": { schema: SkillVersionSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "delete",
  path: "/anthropic/v1/skills/{id}/versions/{version}",
  tags: ["Skills"],
  summary: "Delete a specific version of a skill",
  description: "Cannot delete the skill's `current_version` \u2014 promote another version first.",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string(), version: z.string() })
  },
  responses: {
    200: {
      description: "Version deleted",
      content: { "application/json": { schema: SkillVersionDeletedResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/skills/{id}/versions/{version}/content",
  tags: ["Skills"],
  summary: "Download raw skill content",
  description: "Returns the SKILL.md content as `text/markdown` with a Content-Disposition attachment header.",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({
      id: z.string(),
      version: z.string().describe("Version string or the literal `latest`.")
    })
  },
  responses: {
    200: {
      description: "Raw skill content",
      content: { "text/markdown": { schema: z.string() } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/v1/skills/stats",
  tags: ["Skills"],
  summary: "Get skills statistics",
  security: [{ ApiKey: [] }],
  responses: {
    200: {
      description: "Skills stats",
      content: { "application/json": { schema: SkillsStatsResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/v1/skills/sources",
  tags: ["Skills"],
  summary: "List skill sources",
  description: "Returns aggregated source repositories sorted by install count.",
  security: [{ ApiKey: [] }],
  request: {
    query: z.object({
      limit: z.coerce.number().int().optional(),
      offset: z.coerce.number().int().optional()
    })
  },
  responses: {
    200: {
      description: "Skill sources",
      content: { "application/json": { schema: SkillsSourcesResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/v1/skills/index",
  tags: ["Skills"],
  summary: "Get the full skills index",
  description: "Returns the complete skills index as raw data.",
  security: [{ ApiKey: [] }],
  responses: {
    200: {
      description: "Full skills index",
      content: { "application/json": { schema: z.record(z.unknown()).openapi({ description: "Raw skills index data." }) } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/v1/skills/feed",
  tags: ["Skills"],
  summary: "Get raw skills feed data",
  security: [{ ApiKey: [] }],
  responses: {
    200: {
      description: "Raw feed data",
      content: { "application/json": { schema: z.record(z.unknown()).openapi({ description: "Raw feed data including topTrending, topHot, topAllTime." }) } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "put",
  path: "/v1/settings",
  tags: ["Settings"],
  summary: "Update a setting",
  description: "Persists a setting value. Secret settings (API keys, tokens) are stored encrypted and never returned in plaintext.",
  security: [{ ApiKey: [] }],
  request: {
    body: {
      required: true,
      content: { "application/json": { schema: PutSettingRequestSchema } }
    }
  },
  responses: {
    200: {
      description: "Setting saved",
      content: { "application/json": { schema: z.object({ ok: z.literal(true) }) } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/v1/settings/{key}",
  tags: ["Settings"],
  summary: "Read a setting",
  description: "Returns the setting value. Secret keys return a masked preview (e.g. 'sk-an........lAQR') with `masked: true`.",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ key: z.string() }) },
  responses: {
    200: {
      description: "Setting value",
      content: { "application/json": { schema: SettingResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/v1/providers/status",
  tags: ["Providers"],
  summary: "Get provider availability status",
  description: "Checks availability of all supported container providers (local: Docker, Apple Container, Podman; cloud: Sprites, E2B, Vercel, Daytona, Fly, Modal).",
  security: [{ ApiKey: [] }],
  responses: {
    200: {
      description: "Provider status map",
      content: { "application/json": { schema: ProviderStatusResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/models",
  tags: ["Models"],
  summary: "List available models",
  description: "Returns models available from configured provider APIs (Anthropic, OpenAI, Google, Ollama, OpenRouter). Results are cached for 4 hours. Supports filtering by engine, provider, and free-text search.",
  security: [{ ApiKey: [] }],
  request: {
    query: z.object({
      engine: z.string().optional().describe("Filter to models compatible with this engine (claude, opencode, codex, gemini, factory, pi)."),
      provider: z.string().optional().describe("Filter by source provider (anthropic, openai, google, ollama, openrouter)."),
      q: z.string().optional().describe("Free-text search on model ID.")
    })
  },
  responses: {
    200: {
      description: "List of available models",
      content: { "application/json": { schema: ModelListResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/models/{id}",
  tags: ["Models"],
  summary: "Retrieve a single model",
  description: "Look up a model entry by its bare id (e.g. `claude-sonnet-4-6`, `gemini-3.5-flash`). 404 if the model isn't in the cached registry. Matches Anthropic CMA `GET /v1/models/{model_id}`.",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Model entry",
      content: { "application/json": { schema: ModelEntrySchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/v1/traces",
  tags: ["Traces"],
  summary: "List recent traces",
  security: [{ ApiKey: [] }],
  request: {
    query: z.object({
      session_id: z.string().optional().describe("Filter by session ID."),
      limit: z.coerce.number().int().min(1).max(100).optional()
    })
  },
  responses: {
    200: {
      description: "List of traces",
      content: { "application/json": { schema: TraceListResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/v1/traces/{id}",
  tags: ["Traces"],
  summary: "Get a trace with full event log and span tree",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string() }),
    query: z.object({
      limit: z.coerce.number().int().optional().describe("Max events to return. Defaults to 2000.")
    })
  },
  responses: {
    200: {
      description: "Trace detail",
      content: { "application/json": { schema: TraceDetailSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/v1/traces/{id}/export",
  tags: ["Traces"],
  summary: "Export a trace via OTLP",
  description: "Triggers a synchronous OTLP export for the trace, bypassing the auto-export hook.",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Export result",
      content: { "application/json": { schema: TraceExportResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/v1/metrics",
  tags: ["Metrics"],
  summary: "Get session-level metrics",
  description: "On-read aggregation over sessions + events tables. Supports grouping by agent, environment, backend, hour, day, or api_key. Time-series mode available with `time_bucket` param.",
  security: [{ ApiKey: [] }],
  request: {
    query: z.object({
      group_by: z.enum(["agent", "environment", "backend", "hour", "day", "api_key", "none"]).optional(),
      from: z.coerce.number().optional().describe("Start of window in ms since epoch. Defaults to 0."),
      to: z.coerce.number().optional().describe("End of window in ms since epoch. Defaults to now."),
      agent_id: z.string().optional(),
      environment_id: z.string().optional(),
      time_bucket: z.enum(["hour", "day", "week"]).optional().describe("Time-series bucket size. Only used with group_by=api_key.")
    })
  },
  responses: {
    200: {
      description: "Metrics snapshot",
      content: { "application/json": { schema: MetricsResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/v1/metrics/api",
  tags: ["Metrics"],
  summary: "Get API throughput and latency metrics",
  description: "Global-admin-only. Returns real-time API throughput, latency percentiles, and status code distribution from an in-process ring buffer.",
  security: [{ ApiKey: [] }],
  request: {
    query: z.object({
      window_minutes: z.coerce.number().int().min(1).max(60).optional().describe("Rolling window in minutes. Defaults to 60.")
    })
  },
  responses: {
    200: {
      description: "API metrics snapshot",
      content: { "application/json": { schema: ApiMetricsResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/v1/api-keys",
  tags: ["API Keys"],
  summary: "Create an API key",
  description: "Admin-only. Creates a new virtual API key. The raw key value is returned ONCE in the response and must be stored by the caller.",
  security: [{ ApiKey: [] }],
  request: {
    body: {
      required: true,
      content: { "application/json": { schema: CreateApiKeyRequestSchema } }
    }
  },
  responses: {
    201: {
      description: "API key created (includes raw key)",
      content: { "application/json": { schema: ApiKeyCreatedSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/v1/api-keys",
  tags: ["API Keys"],
  summary: "List API keys",
  description: "Admin-only. Returns all non-revoked API keys (without raw key values).",
  security: [{ ApiKey: [] }],
  responses: {
    200: {
      description: "API key list",
      content: { "application/json": { schema: ApiKeyListResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/v1/api-keys/{id}",
  tags: ["API Keys"],
  summary: "Get an API key",
  description: "Admin-only.",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "API key details",
      content: { "application/json": { schema: ApiKeySchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "patch",
  path: "/v1/api-keys/{id}",
  tags: ["API Keys"],
  summary: "Update an API key's permissions",
  description: "Admin-only.",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string() }),
    body: {
      required: true,
      content: { "application/json": { schema: PatchApiKeyRequestSchema } }
    }
  },
  responses: {
    200: {
      description: "API key updated",
      content: { "application/json": { schema: ApiKeySchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "delete",
  path: "/v1/api-keys/{id}",
  tags: ["API Keys"],
  summary: "Revoke an API key",
  description: "Admin-only. A key cannot revoke itself.",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "API key revoked",
      content: { "application/json": { schema: ApiKeyRevokedResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/v1/api-keys/{id}/activity",
  tags: ["API Keys"],
  summary: "Get API key activity and cost attribution",
  description: "Admin-only (enterprise). Returns recent sessions, total cost, and error counts for a specific API key.",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Key activity",
      content: { "application/json": { schema: ApiKeyActivityResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/v1/upstream-keys",
  tags: ["Upstream Keys"],
  summary: "Add an upstream key to the pool",
  description: "Global-admin-only (enterprise). Adds a provider API key to the round-robin pool. Value is encrypted at rest.",
  security: [{ ApiKey: [] }],
  request: {
    body: {
      required: true,
      content: { "application/json": { schema: AddUpstreamKeyRequestSchema } }
    }
  },
  responses: {
    201: {
      description: "Upstream key added",
      content: { "application/json": { schema: UpstreamKeySchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/v1/upstream-keys",
  tags: ["Upstream Keys"],
  summary: "List upstream keys",
  description: "Global-admin-only (enterprise).",
  security: [{ ApiKey: [] }],
  request: {
    query: z.object({
      provider: z.string().optional().describe("Filter by provider (anthropic, openai, gemini).")
    })
  },
  responses: {
    200: {
      description: "Upstream key list",
      content: { "application/json": { schema: UpstreamKeyListResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/v1/upstream-keys/{id}",
  tags: ["Upstream Keys"],
  summary: "Get an upstream key",
  description: "Global-admin-only (enterprise).",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Upstream key details",
      content: { "application/json": { schema: UpstreamKeySchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "patch",
  path: "/v1/upstream-keys/{id}",
  tags: ["Upstream Keys"],
  summary: "Enable or disable an upstream key",
  description: "Global-admin-only (enterprise).",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string() }),
    body: {
      required: true,
      content: { "application/json": { schema: PatchUpstreamKeyRequestSchema } }
    }
  },
  responses: {
    200: {
      description: "Upstream key updated",
      content: { "application/json": { schema: UpstreamKeySchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "delete",
  path: "/v1/upstream-keys/{id}",
  tags: ["Upstream Keys"],
  summary: "Delete an upstream key from the pool",
  description: "Global-admin-only (enterprise).",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Upstream key deleted",
      content: { "application/json": { schema: UpstreamKeyDeletedResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/v1/tenants",
  tags: ["Tenants"],
  summary: "Create a tenant",
  description: "Global-admin-only (enterprise). Creates a new tenant for multi-tenant isolation.",
  security: [{ ApiKey: [] }],
  request: {
    body: {
      required: true,
      content: { "application/json": { schema: CreateTenantRequestSchema } }
    }
  },
  responses: {
    201: {
      description: "Tenant created",
      content: { "application/json": { schema: TenantSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/v1/tenants",
  tags: ["Tenants"],
  summary: "List tenants",
  description: "Global-admin-only (enterprise).",
  security: [{ ApiKey: [] }],
  request: {
    query: z.object({
      include_archived: z.enum(["true", "false"]).optional()
    })
  },
  responses: {
    200: {
      description: "Tenant list",
      content: { "application/json": { schema: TenantListResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/v1/tenants/{id}",
  tags: ["Tenants"],
  summary: "Get a tenant",
  description: "Global-admin-only (enterprise).",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Tenant details",
      content: { "application/json": { schema: TenantSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "patch",
  path: "/v1/tenants/{id}",
  tags: ["Tenants"],
  summary: "Update a tenant",
  description: "Global-admin-only (enterprise). Currently supports renaming.",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string() }),
    body: {
      required: true,
      content: { "application/json": { schema: PatchTenantRequestSchema } }
    }
  },
  responses: {
    200: {
      description: "Tenant updated",
      content: { "application/json": { schema: TenantSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "delete",
  path: "/v1/tenants/{id}",
  tags: ["Tenants"],
  summary: "Archive a tenant",
  description: "Global-admin-only (enterprise). Cannot archive the default tenant.",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "Tenant archived",
      content: { "application/json": { schema: TenantArchivedResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/v1/audit-log",
  tags: ["Audit"],
  summary: "List audit log entries",
  description: "Admin-only. Returns the append-only admin audit trail. Global admins see all entries; tenant admins see entries for their own tenant.",
  security: [{ ApiKey: [] }],
  request: {
    query: z.object({
      limit: z.coerce.number().int().optional(),
      page: z.string().optional().describe("ULID cursor for pagination."),
      action: z.string().optional().describe("Filter by action, e.g. 'tenants.create'."),
      actor_key_id: z.string().optional(),
      resource_type: z.string().optional(),
      resource_id: z.string().optional(),
      outcome: z.enum(["success", "denied", "failure"]).optional(),
      "created_at[gte]": z.string().optional().describe("Start of time range (ms or ISO string)."),
      "created_at[lte]": z.string().optional().describe("End of time range (ms or ISO string).")
    })
  },
  responses: {
    200: {
      description: "Audit log entries",
      content: { "application/json": { schema: AuditListResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/v1/whoami",
  tags: ["Auth"],
  summary: "Get caller identity",
  description: "Returns the minimal auth context for the authenticated API key: name, tenant, admin status, and permissions.",
  security: [{ ApiKey: [] }],
  responses: {
    200: {
      description: "Caller identity",
      content: { "application/json": { schema: WhoamiResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/v1/license",
  tags: ["Auth"],
  summary: "Get license info",
  description: "Returns the plan tier (community/enterprise) and enabled features. No auth required. The raw license key is never returned.",
  security: [{ ApiKey: [] }],
  responses: {
    200: {
      description: "License info",
      content: { "application/json": { schema: LicenseResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/user_profiles",
  tags: ["User Profiles"],
  summary: "Create user profile",
  security: [{ ApiKey: [] }],
  request: {
    body: {
      required: true,
      content: { "application/json": { schema: UserProfileCreateSchema } }
    }
  },
  responses: {
    201: {
      description: "Created",
      content: { "application/json": { schema: UserProfileSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/user_profiles",
  tags: ["User Profiles"],
  summary: "List user profiles",
  security: [{ ApiKey: [] }],
  responses: {
    200: {
      description: "OK",
      content: { "application/json": { schema: UserProfileListSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "get",
  path: "/anthropic/v1/user_profiles/{id}",
  tags: ["User Profiles"],
  summary: "Get user profile",
  security: [{ ApiKey: [] }],
  request: { params: z.object({ id: z.string() }) },
  responses: {
    200: {
      description: "OK",
      content: { "application/json": { schema: UserProfileSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/user_profiles/{id}",
  tags: ["User Profiles"],
  summary: "Update user profile",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string() }),
    body: {
      required: true,
      content: { "application/json": { schema: UserProfileUpdateSchema } }
    }
  },
  responses: {
    200: {
      description: "OK",
      content: { "application/json": { schema: UserProfileSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/anthropic/v1/user_profiles/{id}/enrollment_url",
  tags: ["User Profiles"],
  summary: "Generate OAuth enrollment URL",
  security: [{ ApiKey: [] }],
  request: {
    params: z.object({ id: z.string() }),
    body: {
      required: true,
      content: { "application/json": { schema: EnrollmentUrlRequestSchema } }
    }
  },
  responses: {
    200: {
      description: "OK",
      content: { "application/json": { schema: EnrollmentUrlResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/v1/batch",
  tags: ["Batch"],
  summary: "Execute multiple operations atomically",
  description: "Wraps all operations in a single SQLite transaction. On any error, the transaction rolls back and the error is returned.",
  security: [{ ApiKey: [] }],
  request: {
    body: {
      required: true,
      content: { "application/json": { schema: BatchRequestSchema } }
    }
  },
  responses: {
    200: {
      description: "All operations succeeded",
      content: { "application/json": { schema: BatchResponseSchema } }
    },
    ...ErrorResponses
  }
});
registry.registerPath({
  method: "post",
  path: "/google/v1beta/interactions",
  tags: ["Google Compat"],
  summary: "Create interaction (Google compat)",
  description: "Google Interactions API compatibility. Accepts google-genai SDK format.",
  responses: { 200: { description: "OK" } }
});
registry.registerPath({
  method: "get",
  path: "/google/v1beta/interactions/{id}",
  tags: ["Google Compat"],
  summary: "Get interaction (Google compat)",
  request: { params: z.object({ id: z.string() }) },
  responses: { 200: { description: "OK" } }
});
registry.registerPath({
  method: "delete",
  path: "/google/v1beta/interactions/{id}",
  tags: ["Google Compat"],
  summary: "Delete interaction (Google compat)",
  request: { params: z.object({ id: z.string() }) },
  responses: { 200: { description: "OK" } }
});
registry.registerPath({
  method: "post",
  path: "/google/v1beta/interactions/{id}/cancel",
  tags: ["Google Compat"],
  summary: "Cancel interaction (Google compat)",
  request: { params: z.object({ id: z.string() }) },
  responses: { 200: { description: "OK" } }
});
registry.registerPath({
  method: "post",
  path: "/google/v1beta/agents",
  tags: ["Google Compat"],
  summary: "Create agent (Google compat)",
  responses: { 201: { description: "Created" } }
});
registry.registerPath({
  method: "get",
  path: "/google/v1beta/agents",
  tags: ["Google Compat"],
  summary: "List agents (Google compat)",
  responses: { 200: { description: "OK" } }
});
registry.registerPath({
  method: "get",
  path: "/google/v1beta/agents/{id}",
  tags: ["Google Compat"],
  summary: "Get agent (Google compat)",
  request: { params: z.object({ id: z.string() }) },
  responses: { 200: { description: "OK" } }
});
registry.registerPath({
  method: "delete",
  path: "/google/v1beta/agents/{id}",
  tags: ["Google Compat"],
  summary: "Delete agent (Google compat)",
  request: { params: z.object({ id: z.string() }) },
  responses: { 200: { description: "OK" } }
});
registry.registerPath({
  method: "get",
  path: "/google/v1beta/files/{fileRef}",
  tags: ["Google Compat"],
  summary: "Download environment files (Google compat)",
  request: { params: z.object({ fileRef: z.string() }) },
  responses: { 200: { description: "Tar archive", content: { "application/x-tar": { schema: z.string().openapi({ description: "Raw tar archive bytes." }) } } } }
});
function buildOpenApiDocument(opts) {
  const generator = new OpenApiGeneratorV31(registry.definitions);
  const meta = surfaceMetadata(opts.pathPrefix);
  const doc = generator.generateDocument({
    openapi: "3.1.0",
    info: {
      title: meta.title,
      version: "0.4.16",
      description: meta.description
    },
    servers: [{ url: opts.serverUrl, description: "This host" }],
    security: [{ ApiKey: [] }],
    tags: [
      { name: "Agents", description: "Agent CRUD and versioning" },
      { name: "Environments", description: "Container environment management" },
      { name: "Sessions", description: "Session lifecycle management" },
      { name: "Events", description: "Event append, history, and streaming" },
      { name: "Resources", description: "Session resource attachments" },
      { name: "Files", description: "File upload, download, and management" },
      {
        name: "Vaults",
        description: "Secret vault management. A vault holds two distinct kinds of secrets: **(1) Credentials** (`POST /vaults/{id}/credentials`) \u2014 MCP-shaped auth records with required `mcp_server_url`. Part of Anthropic's Managed Agents API; injected as MCP auth at session time. **(2) Entries** (`PUT /vaults/{id}/entries/{key}`) \u2014 raw key/value strings (`SPRITE_TOKEN`, `ANTHROPIC_API_KEY`, custom API keys). AgentStep extension; injected into the session container as env vars. Reach for *credentials* when you have an MCP server URL + auth token; reach for *entries* when you have a plain token that should appear as `$NAME` inside the agent's runtime."
      },
      {
        name: "Credentials",
        description: "Vault credential CRUD \u2014 MCP-shaped structured auth (`mcp_server_url`, `oauth_token`, etc). Anthropic CMA-compatible. For plain env-var-style tokens that don't tie to an MCP server, use the Vaults entries endpoints (`PUT /vaults/{id}/entries/{key}`) instead."
      },
      { name: "Memory", description: "Memory stores and memories" },
      { name: "Work", description: "Self-hosted environment work queue (poll/ack/heartbeat/stop)" },
      { name: "Skills", description: "Skills catalog, search, and management" },
      { name: "Settings", description: "Gateway configuration settings" },
      { name: "Providers", description: "Container provider status" },
      { name: "Models", description: "Dynamic model registry" },
      { name: "Traces", description: "Distributed tracing and span trees" },
      { name: "Metrics", description: "Session and API metrics" },
      { name: "API Keys", description: "Virtual API key management (admin-only)" },
      { name: "Upstream Keys", description: "Upstream provider key pool (global-admin-only)" },
      { name: "Tenants", description: "Multi-tenant isolation (global-admin-only)" },
      { name: "Audit", description: "Admin audit trail" },
      { name: "Auth", description: "Caller identity and license info" },
      { name: "Batch", description: "Atomic batch operations" },
      { name: "User Profiles", description: "User profile management and OAuth enrollment" },
      { name: "Google Compat", description: "Google Interactions API compatibility layer" }
    ]
  });
  if (opts.pathPrefix) {
    const prefix = opts.pathPrefix;
    const filteredPaths = {};
    const allPaths = doc.paths ?? {};
    const isAgentstepSurface = prefix === "/agentstep/v1";
    for (const [pathKey, pathDef] of Object.entries(allPaths)) {
      if (isAgentstepSurface) {
        const META_AT_V1 = pathKey === "/v1/openapi.json" || pathKey === "/v1/docs";
        if (META_AT_V1) continue;
        if (pathKey === "/v1" || pathKey.startsWith("/v1/")) {
          const rewritten = pathKey === "/v1" ? "/agentstep/v1" : pathKey.replace(/^\/v1\//, "/agentstep/v1/");
          filteredPaths[rewritten] = pathDef;
        }
      } else if (pathKey === prefix || pathKey.startsWith(prefix + "/")) {
        filteredPaths[pathKey] = pathDef;
      }
    }
    doc.paths = filteredPaths;
  }
  return doc;
}
function surfaceMetadata(pathPrefix) {
  switch (pathPrefix) {
    case "/anthropic/v1":
      return {
        title: "AgentStep \u2014 Anthropic Managed Agents API",
        description: "Anthropic Managed Agents API surface. Drop-in compatible with the official Anthropic Managed Agents API \u2014 change the baseURL on your Anthropic SDK and stay on the same shapes: agents, sessions, vaults, environments, files, threads, resources, user_profiles, oauth, skills, memory_stores, models, environments/{id}/work."
      };
    case "/google/v1beta":
      return {
        title: "AgentStep \u2014 Google Interactions API",
        description: "Google Interactions API compatibility surface. Drop-in compatible with Google's Interactions API shape."
      };
    case "/agentstep/v1":
      return {
        title: "AgentStep \u2014 Gateway-native API",
        description: "Gateway-native API surface (canonical): settings, api-keys, metrics, audit, tenants, upstream-keys, license, traces, providers, batch, whoami, plus AgentStep-only extensions on CMA-shape resources (skills/{catalog,feed,index,sources,stats}, memory_stores/{id}/dream, sessions/{id}/debug-prompt). Anthropic-shaped resources (agents, sessions, vaults, environments, files, skills CRUD, memory_stores CRUD, models, environments/{id}/work) live under /anthropic/v1/* \u2014 see /anthropic/v1/openapi.json. The same routes are reachable under the deprecated /v1/* prefix (RFC 8594 `Deprecation` header on responses); new integrations should target /agentstep/v1/*."
      };
    case "/v1":
      return {
        title: "AgentStep \u2014 /v1/* (deprecated alias)",
        description: 'Deprecated alias surface. Every gateway-native route here is reachable at its canonical /agentstep/v1/* path; responses include an RFC 8594 `Deprecation` header and a `Link: rel="successor-version"` pointing at the canonical URL. CMA-shape resources (agents, sessions, vaults, environments, files, skills, memory_stores, models, environments/{id}/work) 308-redirect to /anthropic/v1/* and are NOT included in this alias.'
      };
    default:
      return {
        title: "AgentStep Gateway",
        description: "Open-source, drop-in replacement for the Claude Managed Agents API. Self-hosted agent gateway with 7 agent harnesses and 11 sandbox providers. Use with `@agentstep/agent-sdk` or the official Anthropic SDK \u2014 just change the baseURL."
      };
  }
}

export {
  buildOpenApiDocument
};
