asyncapi: 2.6.0
id: urn:gpuaas:asyncapi:realtime-events
info:
  title: GPUaaS Realtime and Event Contracts
  version: 0.3.0-draft
  description: |
    Async contracts for websocket sessions and internal domain events.
  contact:
    name: GPUaaS Platform Team
    url: https://example.com/gpuaas
    email: platform@gpuaas.local
  license:
    name: Proprietary
tags:
  - name: gpuaas
    description: GPUaaS realtime websocket and internal domain event contracts.

defaultContentType: application/json

servers:
  ws-public:
    url: localhost:8090
    protocol: ws
    description: Public websocket endpoint (development)
  nats-internal:
    url: nats://nats:4222
    protocol: nats
    description: Internal event bus (draft)

channels:
  ws/terminal:
    servers: [ws-public]
    description: |
      Interactive terminal websocket stream.

      Auth flow (required before connecting):
        1. Client calls POST /api/v1/allocations/{allocation_id}/terminal-token
           to obtain a short-lived (≤300s), single-use, allocation-scoped token.
        2. Client opens this WebSocket and presents the token:
             - Browser client: via Sec-WebSocket-Protocol
             - Non-browser client: via Authorization: Bearer <terminal-token>
        3. MVP (Day 1): Terminal Gateway validates token scope and allocation ownership
           using cache/DB checks for correctness.
           Single-use enforcement must use atomic consume semantics (e.g. Redis GETDEL).
           Phase-2 target: signed terminal tokens with local verification to reduce
           per-connection DB dependency.
        4. On token validation failure the gateway closes the connection with 4401.
        5. Gateway sends a JSON `TerminalControl` frame for session lifecycle events:
             - `session_ready` after PTY attach succeeds
             - `session_error` for non-fatal stream errors (includes `retryable`)
             - `session_closed` before normal close
           Close codes: 4401 auth failure, 4403 authorization denied, 1011 internal error.

      Query-token auth (e.g. ?token=) is explicitly prohibited.
    parameters:
      allocation_id:
        description: Allocation UUID for this terminal session.
        schema:
          type: string
          format: uuid
    bindings:
      ws:
        method: GET
        headers:
          type: object
          properties:
            Authorization:
              type: string
              description: >
                Optional for non-browser clients: Bearer <terminal-token> obtained
                from POST /api/v1/allocations/{allocation_id}/terminal-token.
            Sec-WebSocket-Protocol:
              type: string
              description: >
                Required auth transport for browser clients. Carries short-lived
                terminal token value.
    publish:
      operationId: clientTerminalInput
      summary: Client -> gateway terminal input or resize messages
      message:
        oneOf:
          - $ref: '#/components/messages/TerminalResize'
          - $ref: '#/components/messages/TerminalHeartbeat'
          - $ref: '#/components/messages/TerminalInputBinary'
    subscribe:
      operationId: serverTerminalOutput
      summary: Gateway -> client terminal output stream and control events
      message:
        oneOf:
          - $ref: '#/components/messages/TerminalControl'
          - $ref: '#/components/messages/TerminalOutputText'
          - $ref: '#/components/messages/TerminalOutputBinary'

  ws/notifications:
    servers: [ws-public]
    description: |
      Planned dedicated user notification channel.
      Interim state: prototype may multiplex notification messages on terminal channel.
      Target state: move all notification traffic to this dedicated channel.
    bindings:
      ws:
        method: GET
        headers:
          type: object
          properties:
            Authorization:
              type: string
              description: Optional for non-browser clients.
            Sec-WebSocket-Protocol:
              type: string
              description: Required auth transport for browser clients.
    subscribe:
      operationId: serverUserNotification
      message:
        $ref: '#/components/messages/UserNotification'

  billing.low_balance_warning:
    servers: [nats-internal]
    description: Emitted when user enters low-balance state.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.billing.low_balance_warning
    subscribe:
      operationId: onLowBalanceWarning
      message:
        $ref: '#/components/messages/LowBalanceWarningEvent'

  billing.balance_depleted:
    servers: [nats-internal]
    description: Emitted when user balance depletes and force release is required.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.billing.balance_depleted
    subscribe:
      operationId: onBalanceDepleted
      message:
        $ref: '#/components/messages/BalanceDepletedEvent'

  billing.auto_release_pending:
    servers: [nats-internal]
    description: Emitted when projected depletion indicates forced release is approaching.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.billing.auto_release_pending
    subscribe:
      operationId: onAutoReleasePending
      message:
        $ref: '#/components/messages/AutoReleasePendingEvent'

  payments.balance_credited:
    servers: [nats-internal]
    description: Emitted after successful idempotent payment credit posting.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.payments.balance_credited
    publish:
      operationId: publishBalanceCredited
      message:
        $ref: '#/components/messages/BalanceCreditedEvent'

  payments.reconcile_failed:
    servers: [nats-internal]
    description: Emitted when provider/session reconciliation fails and requires support follow-up.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.payments.reconcile_failed
    publish:
      operationId: publishReconcileFailed
      message:
        $ref: '#/components/messages/ReconcileFailedEvent'

  provisioning.requested:
    servers: [nats-internal]
    x-nats-config:
      ack_policy: explicit
      ack_wait: 45s
      max_deliver: 20
      dlq_subject: dlq.provisioning.requested
    publish:
      operationId: publishProvisionRequested
      message:
        $ref: '#/components/messages/ProvisionRequestedEvent'

  provisioning.active:
    servers: [nats-internal]
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.provisioning.active
    publish:
      operationId: publishAllocationActive
      message:
        $ref: '#/components/messages/AllocationActiveEvent'

  provisioning.failed:
    servers: [nats-internal]
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.provisioning.failed
    publish:
      operationId: publishProvisionFailed
      message:
        $ref: '#/components/messages/ProvisionFailedEvent'

  provisioning.releasing.requested:
    servers: [nats-internal]
    x-nats-config:
      ack_policy: explicit
      ack_wait: 45s
      max_deliver: 20
      dlq_subject: dlq.provisioning.releasing.requested
    publish:
      operationId: publishReleasingRequested
      message:
        $ref: '#/components/messages/ReleasingRequestedEvent'

  provisioning.releasing.completed:
    servers: [nats-internal]
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.provisioning.releasing.completed
    publish:
      operationId: publishReleasingCompleted
      message:
        $ref: '#/components/messages/ReleasingCompletedEvent'

  provisioning.force_release_requested:
    servers: [nats-internal]
    description: Requests forced release for specific active allocations.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 45s
      max_deliver: 20
      dlq_subject: dlq.provisioning.force_release_requested
    publish:
      operationId: publishForceReleaseRequested
      message:
        $ref: '#/components/messages/ForceReleaseRequestedEvent'

  provisioning.release_failed:
    servers: [nats-internal]
    description: |
      Published by the provisioning worker when all release retries are exhausted
      and the allocation cannot be cleaned up automatically. Consumers must stop
      billing accrual and alert the user/admin. The node remains assigned until
      an admin manually retries via POST /api/v1/admin/allocations/{id}/force-release.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.provisioning.release_failed
    publish:
      operationId: publishReleaseFailed
      message:
        $ref: '#/components/messages/ReleaseFailedEvent'

  storage.attachment.requested:
    servers: [nats-internal]
    description: Emitted when a storage attach workflow is accepted.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.storage.attachment.requested
    publish:
      operationId: publishStorageAttachmentRequested
      message:
        $ref: '#/components/messages/StorageAttachmentRequestedEvent'

  storage.attachment.detach_requested:
    servers: [nats-internal]
    description: Emitted when a storage detach workflow is accepted.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.storage.attachment.detach_requested
    publish:
      operationId: publishStorageAttachmentDetachRequested
      message:
        $ref: '#/components/messages/StorageAttachmentDetachRequestedEvent'

  storage.attachment.mounted:
    servers: [nats-internal]
    description: Emitted when node-agent mount verification succeeds.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.storage.attachment.mounted
    publish:
      operationId: publishStorageAttachmentMounted
      message:
        $ref: '#/components/messages/StorageAttachmentMountedEvent'

  storage.attachment.failed:
    servers: [nats-internal]
    description: Emitted when a storage attach workflow fails and compensation is complete or recorded.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.storage.attachment.failed
    publish:
      operationId: publishStorageAttachmentFailed
      message:
        $ref: '#/components/messages/StorageAttachmentFailedEvent'

  storage.attachment.detached:
    servers: [nats-internal]
    description: Emitted when a storage attachment is detached. Persistent storage is not deleted.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.storage.attachment.detached
    publish:
      operationId: publishStorageAttachmentDetached
      message:
        $ref: '#/components/messages/StorageAttachmentDetachedEvent'

  storage.attachment.detach_failed:
    servers: [nats-internal]
    description: Emitted when detach retries are exhausted and operator retry is required.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.storage.attachment.detach_failed
    publish:
      operationId: publishStorageAttachmentDetachFailed
      message:
        $ref: '#/components/messages/StorageAttachmentDetachFailedEvent'

  apps.entitlement.updated:
    servers: [nats-internal]
    description: Emitted when a project app entitlement is created or updated.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.apps.entitlement.updated
    publish:
      operationId: publishAppEntitlementUpdated
      message:
        $ref: '#/components/messages/AppEntitlementUpdatedEvent'

  apps.instance.requested:
    servers: [nats-internal]
    description: Emitted when an app instance deployment request is accepted.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 45s
      max_deliver: 20
      dlq_subject: dlq.apps.instance.requested
    publish:
      operationId: publishAppInstanceRequested
      message:
        $ref: '#/components/messages/AppInstanceRequestedEvent'

  apps.instance.running:
    servers: [nats-internal]
    description: Emitted when an app instance reaches running state.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.apps.instance.running
    publish:
      operationId: publishAppInstanceRunning
      message:
        $ref: '#/components/messages/AppInstanceRunningEvent'

  apps.instance.failed:
    servers: [nats-internal]
    description: Emitted when an app instance deployment or runtime transitions to failed.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.apps.instance.failed
    publish:
      operationId: publishAppInstanceFailed
      message:
        $ref: '#/components/messages/AppInstanceFailedEvent'

  apps.instance.deleting:
    servers: [nats-internal]
    description: Emitted when app instance deletion is requested and accepted.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.apps.instance.deleting
    publish:
      operationId: publishAppInstanceDeleting
      message:
        $ref: '#/components/messages/AppInstanceDeletingEvent'

  apps.instance.upgrade_requested:
    servers: [nats-internal]
    description: Emitted when an app instance upgrade is requested and accepted.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.apps.instance.upgrade_requested
    publish:
      operationId: publishAppInstanceUpgradeRequested
      message:
        $ref: '#/components/messages/AppInstanceUpgradeRequestedEvent'

  apps.instance.rollback_requested:
    servers: [nats-internal]
    description: Emitted when an app instance rollback is requested and accepted.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.apps.instance.rollback_requested
    publish:
      operationId: publishAppInstanceRollbackRequested
      message:
        $ref: '#/components/messages/AppInstanceRollbackRequestedEvent'

  apps.instance.decommission_requested:
    servers: [nats-internal]
    description: Emitted when an app instance decommission is requested and accepted.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.apps.instance.decommission_requested
    publish:
      operationId: publishAppInstanceDecommissionRequested
      message:
        $ref: '#/components/messages/AppInstanceDecommissionRequestedEvent'

  apps.instance.stop_requested:
    servers: [nats-internal]
    description: Emitted when a non-destructive app instance stop is requested and accepted.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.apps.instance.stop_requested
    publish:
      operationId: publishAppInstanceStopRequested
      message:
        $ref: '#/components/messages/AppInstanceStopRequestedEvent'

  apps.instance.start_requested:
    servers: [nats-internal]
    description: Emitted when a stopped app instance start is requested and accepted.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.apps.instance.start_requested
    publish:
      operationId: publishAppInstanceStartRequested
      message:
        $ref: '#/components/messages/AppInstanceStartRequestedEvent'

  apps.instance.restart_requested:
    servers: [nats-internal]
    description: Emitted when a non-destructive app instance restart is requested and accepted.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.apps.instance.restart_requested
    publish:
      operationId: publishAppInstanceRestartRequested
      message:
        $ref: '#/components/messages/AppInstanceRestartRequestedEvent'

  apps.instance.deleted:
    servers: [nats-internal]
    description: Emitted when app instance deletion is completed.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.apps.instance.deleted
    publish:
      operationId: publishAppInstanceDeleted
      message:
        $ref: '#/components/messages/AppInstanceDeletedEvent'

  apps.shared_runtime.requested:
    servers: [nats-internal]
    description: Emitted when a tenant-owned shared runtime deployment request is accepted.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 45s
      max_deliver: 20
      dlq_subject: dlq.apps.shared_runtime.requested
    publish:
      operationId: publishSharedAppRuntimeRequested
      message:
        $ref: '#/components/messages/SharedAppRuntimeRequestedEvent'

  apps.shared_runtime.running:
    servers: [nats-internal]
    description: Emitted when a tenant-owned shared runtime reaches running state.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.apps.shared_runtime.running
    publish:
      operationId: publishSharedAppRuntimeRunning
      message:
        $ref: '#/components/messages/SharedAppRuntimeRunningEvent'

  apps.shared_runtime.failed:
    servers: [nats-internal]
    description: Emitted when a tenant-owned shared runtime transitions to failed.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.apps.shared_runtime.failed
    publish:
      operationId: publishSharedAppRuntimeFailed
      message:
        $ref: '#/components/messages/SharedAppRuntimeFailedEvent'

  apps.shared_runtime.deleting:
    servers: [nats-internal]
    description: Emitted when tenant-owned shared runtime deletion is requested and accepted.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.apps.shared_runtime.deleting
    publish:
      operationId: publishSharedAppRuntimeDeleting
      message:
        $ref: '#/components/messages/SharedAppRuntimeDeletingEvent'

  apps.shared_runtime.deleted:
    servers: [nats-internal]
    description: Emitted when tenant-owned shared runtime deletion is completed.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.apps.shared_runtime.deleted
    publish:
      operationId: publishSharedAppRuntimeDeleted
      message:
        $ref: '#/components/messages/SharedAppRuntimeDeletedEvent'

  apps.artifact.registered:
    servers: [nats-internal]
    description: Emitted when an OCI artifact digest is registered for a project app.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.apps.artifact.registered
    publish:
      operationId: publishAppArtifactRegistered
      message:
        $ref: '#/components/messages/AppArtifactRegisteredEvent'

  apps.artifact.promoted:
    servers: [nats-internal]
    description: Emitted when a registered OCI artifact is promoted to a named channel.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.apps.artifact.promoted
    publish:
      operationId: publishAppArtifactPromoted
      message:
        $ref: '#/components/messages/AppArtifactPromotedEvent'

  apps.artifact.verified:
    servers: [nats-internal]
    description: Emitted when a registered app artifact trust state becomes verified.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.apps.artifact.verified
    publish:
      operationId: publishAppArtifactVerified
      message:
        $ref: '#/components/messages/AppArtifactVerifiedEvent'

  apps.artifact.revoked:
    servers: [nats-internal]
    description: Emitted when trust is revoked for a registered app artifact.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.apps.artifact.revoked
    publish:
      operationId: publishAppArtifactRevoked
      message:
        $ref: '#/components/messages/AppArtifactRevokedEvent'

  apps.artifact.deprecated:
    servers: [nats-internal]
    description: Emitted when a registered OCI artifact is deprecated.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.apps.artifact.deprecated
    publish:
      operationId: publishAppArtifactDeprecated
      message:
        $ref: '#/components/messages/AppArtifactDeprecatedEvent'

  apps.artifact.retired:
    servers: [nats-internal]
    description: Emitted when a registered OCI artifact is retired.
    x-nats-config:
      ack_policy: explicit
      ack_wait: 30s
      max_deliver: 10
      dlq_subject: dlq.apps.artifact.retired
    publish:
      operationId: publishAppArtifactRetired
      message:
        $ref: '#/components/messages/AppArtifactRetiredEvent'

components:
  schemas:
    EventMetadata:
      type: object
      additionalProperties: false
      properties:
        event_id:
          type: string
          format: uuid
        event_type:
          type: string
        occurred_at:
          type: string
          format: date-time
        version:
          type: string
        correlation_id:
          type: string
      required: [event_id, event_type, occurred_at, version, correlation_id]

    UserNotificationPayload:
      type: object
      additionalProperties: false
      properties:
        id:
          type: string
          format: uuid
        occurred_at:
          type: string
          format: date-time
        severity:
          type: string
          enum: [info, warning, error]
        type:
          type: string
          enum: [low_balance_warning, balance_depleted, info]
        title:
          type: string
        message:
          type: string
        action_url:
          type: string
          format: uri
          nullable: true
      required: [id, occurred_at, severity, type, title, message]

    TerminalControlPayload:
      type: object
      additionalProperties: false
      properties:
        type:
          type: string
          enum: [session_ready, session_error, session_closed]
        code:
          type: string
          description: Stable machine-readable terminal control code.
          enum:
            - normal_close        # clean close, no error
            - allocation_released # allocation release triggered session close
            - session_timeout     # terminal.session_max_ttl_seconds exceeded
            - node_stream_dropped # node-agent relay stream dropped (retryable)
            - open_failed         # terminal.open task failed or rejected by node
            - auth_failed         # terminal token invalid or unauthorized
            - admin_terminate     # admin-initiated session close
        session_id:
          type: string
          format: uuid
          description: Session identifier for correlation across client reconnects.
        message:
          type: string
        retryable:
          type: boolean
      required: [type, code, session_id, message, retryable]

    TerminalOpenTaskParams:
      type: object
      additionalProperties: false
      description: |
        Parameters for the `terminal.open` signed node task.
        Dispatched by the terminal gateway (via api.internal relay) to the node-agent
        to authorize and open a PTY session for the named OS user.
        This is a discrete signed task; I/O then flows on a separate stream channel.
      properties:
        session_id:
          type: string
          format: uuid
          description: Stable session identifier — enforced by node seen-set against replay.
        user_id:
          type: string
          format: uuid
        allocation_id:
          type: string
          format: uuid
        username:
          type: string
          description: Stable per-user OS username from user_posix_identities. Must exist on the node.
          pattern: '^[a-z_][a-z0-9_-]{0,31}$'
        uid:
          type: integer
          minimum: 10000
          maximum: 199999
          description: Stable per-user POSIX UID.
        gid:
          type: integer
          minimum: 10000
          maximum: 199999
          description: Stable per-user POSIX primary GID.
        supplemental_gids:
          type: array
          description: Optional supplemental groups for cluster interoperability.
          items:
            type: integer
            minimum: 10000
            maximum: 199999
        session_ttl_seconds:
          type: integer
          description: Maximum session lifetime in seconds. Enforced by node-agent. Sourced from policy key terminal.session_max_ttl_seconds.
          minimum: 300
          maximum: 86400
        cols:
          type: integer
          description: Initial PTY width in columns.
          minimum: 1
          maximum: 512
        rows:
          type: integer
          description: Initial PTY height in rows.
          minimum: 1
          maximum: 512
      required: [session_id, user_id, allocation_id, username, uid, gid, session_ttl_seconds, cols, rows]

    TerminalStreamFrame:
      type: object
      additionalProperties: false
      description: |
        Wire frame for terminal I/O relay between gateway and node-agent via api.internal.
        Not exposed externally on the public WS channel; governs the internal
        HTTP/2 streaming relay used by the TerminalSessionBroker implementation (Option A),
        transported on `POST /internal/v1/nodes/{node_id}/terminal/stream`.
        Gateway sends upstream frames (stdin, resize, close-request).
        Node-agent sends downstream frames (stdout/stderr, close-confirm).
      properties:
        session_id:
          type: string
          format: uuid
        type:
          type: string
          enum: [data, resize, close]
          description: |
            data:   stdin/stdout/stderr bytes (base64-encoded in `payload`).
            resize: PTY resize event (`cols` and `rows` set).
            close:  graceful close request (upstream) or close confirmation (downstream).
        direction:
          type: string
          enum: [upstream, downstream]
          description: |
            upstream:   gateway -> node-agent (stdin, resize, close-request).
            downstream: node-agent -> gateway (stdout/stderr, close-confirm).
        payload:
          type: string
          format: byte
          description: Base64-encoded raw bytes (present for type=data frames only).
          nullable: true
        close_reason:
          type: string
          description: Close reason code (present on type=close frames).
          enum:
            - normal_close
            - allocation_released
            - session_timeout
            - node_stream_dropped
            - admin_terminate
          nullable: true
        cols:
          type: integer
          description: New column count (present on type=resize frames).
          minimum: 1
          maximum: 512
          nullable: true
        rows:
          type: integer
          description: New row count (present on type=resize frames).
          minimum: 1
          maximum: 512
          nullable: true
      required: [session_id, type, direction]

    ProvisionRequestedPayload:
      type: object
      additionalProperties: false
      properties:
        allocation_id:
          type: string
          format: uuid
        user_id:
          type: string
          format: uuid
        node_id:
          type: string
          format: uuid
          nullable: true
        scheduler_type:
          type: string
          enum: [bare_metal, slurm, k8s, ray]
        org_id:
          type: string
          format: uuid
          nullable: true
      required: [allocation_id, user_id, scheduler_type]

    AllocationActivePayload:
      type: object
      additionalProperties: false
      properties:
        allocation_id:
          type: string
          format: uuid
        user_id:
          type: string
          format: uuid
        node_id:
          type: string
          format: uuid
        active_at:
          type: string
          format: date-time
      required: [allocation_id, user_id, node_id, active_at]

    ProvisionFailedPayload:
      type: object
      additionalProperties: false
      properties:
        allocation_id:
          type: string
          format: uuid
        user_id:
          type: string
          format: uuid
        reason:
          type: string
      required: [allocation_id, user_id, reason]

    ForceReleaseRequestedPayload:
      type: object
      additionalProperties: false
      properties:
        user_id:
          type: string
          format: uuid
        allocation_ids:
          type: array
          minItems: 1
          items:
            type: string
            format: uuid
        reason:
          type: string
      required: [user_id, allocation_ids, reason]

    ReleaseFailedPayload:
      type: object
      additionalProperties: false
      properties:
        allocation_id:
          type: string
          format: uuid
        user_id:
          type: string
          format: uuid
        reason:
          type: string
      required: [allocation_id, user_id, reason]

    StorageAttachmentPayload:
      type: object
      additionalProperties: false
      properties:
        attachment_id:
          type: string
          format: uuid
        bucket_id:
          type: string
        project_id:
          type: string
          format: uuid
        allocation_id:
          type: string
          format: uuid
          nullable: true
        workload_instance_id:
          type: string
          format: uuid
          nullable: true
        node_id:
          type: string
          format: uuid
          nullable: true
        provider_backend:
          type: string
          enum: [local_dev, weka, vast, ddn, nvme_pool, s3_compatible, unknown]
        mount_path:
          type: string
        access_mode:
          type: string
          enum: [read_only, read_write]
        write_policy:
          type: string
          enum: [single_writer, multi_writer]
        state:
          type: string
          enum: [requested, prechecking, grant_applying, grant_applied, mounting, mounted, failed, detaching, detached, detach_failed]
        reason:
          type: string
          nullable: true
      required: [attachment_id, bucket_id, project_id, provider_backend, mount_path, access_mode, write_policy, state]

    ReleasingRequestedPayload:
      type: object
      additionalProperties: false
      properties:
        allocation_id:
          type: string
          format: uuid
        user_id:
          type: string
          format: uuid
        reason:
          type: string
      required: [allocation_id, user_id, reason]

    ReleasingCompletedPayload:
      type: object
      additionalProperties: false
      properties:
        allocation_id:
          type: string
          format: uuid
        user_id:
          type: string
          format: uuid
        released_at:
          type: string
          format: date-time
      required: [allocation_id, user_id, released_at]

    BalanceCreditedPayload:
      type: object
      additionalProperties: false
      properties:
        user_id:
          type: string
          format: uuid
        amount_minor:
          type: integer
          minimum: 1
        currency:
          type: string
          pattern: '^[A-Z]{3}$'
        source:
          type: string
          enum: [stripe_webhook]
      required: [user_id, amount_minor, currency, source]

    ReconcileFailedPayload:
      type: object
      additionalProperties: false
      properties:
        user_id:
          type: string
          format: uuid
        payment_session_id:
          type: string
          format: uuid
        stripe_session_id:
          type: string
        reason:
          type: string
      required: [user_id, payment_session_id, stripe_session_id, reason]

    AppInstanceRequestedPayload:
      type: object
      additionalProperties: false
      properties:
        app_instance_id:
          type: string
          format: uuid
        app_artifact_id:
          type: string
          format: uuid
          nullable: true
        app_slug:
          type: string
          pattern: '^[a-z0-9][a-z0-9-]{1,62}$'
        app_version:
          type: string
        operating_mode:
          type: string
          enum: [tenant_dedicated, platform_managed]
        control_plane_scope:
          type: string
          enum: [project, tenant, platform]
        runtime_backend:
          type: string
          enum: [k8s, slurm, ray, bare_metal]
        tenant_boundary_mode:
          type: string
          enum: [tenant_isolated, shared_service]
        org_id:
          type: string
          format: uuid
        project_id:
          type: string
          format: uuid
        requested_by_user_id:
          type: string
          format: uuid
          nullable: true
        requested_by_service_account_id:
          type: string
          format: uuid
          nullable: true
        operator_service_account_id:
          type: string
          format: uuid
          nullable: true
      required: [app_instance_id, app_slug, app_version, operating_mode, control_plane_scope, runtime_backend, tenant_boundary_mode, org_id, project_id]

    AppEntitlementUpdatedPayload:
      type: object
      additionalProperties: false
      properties:
        org_id:
          type: string
          format: uuid
        project_id:
          type: string
          format: uuid
        app_slug:
          type: string
          pattern: '^[a-z0-9][a-z0-9-]{1,62}$'
        enabled:
          type: boolean
        policy_overrides:
          type: object
          additionalProperties: true
        updated_by_user_id:
          type: string
          format: uuid
          nullable: true
      required: [org_id, project_id, app_slug, enabled, policy_overrides]

    AppInstanceRunningPayload:
      type: object
      additionalProperties: false
      properties:
        app_instance_id:
          type: string
          format: uuid
        app_slug:
          type: string
          pattern: '^[a-z0-9][a-z0-9-]{1,62}$'
        operating_mode:
          type: string
          enum: [tenant_dedicated, platform_managed]
        control_plane_scope:
          type: string
          enum: [project, tenant, platform]
        runtime_backend:
          type: string
          enum: [k8s, slurm, ray, bare_metal]
        org_id:
          type: string
          format: uuid
        project_id:
          type: string
          format: uuid
        endpoint:
          type: string
          nullable: true
      required: [app_instance_id, app_slug, operating_mode, control_plane_scope, runtime_backend, org_id, project_id]

    AppInstanceFailedPayload:
      type: object
      additionalProperties: false
      properties:
        app_instance_id:
          type: string
          format: uuid
        app_slug:
          type: string
          pattern: '^[a-z0-9][a-z0-9-]{1,62}$'
        operating_mode:
          type: string
          enum: [tenant_dedicated, platform_managed]
        control_plane_scope:
          type: string
          enum: [project, tenant, platform]
        runtime_backend:
          type: string
          enum: [k8s, slurm, ray, bare_metal]
        org_id:
          type: string
          format: uuid
        project_id:
          type: string
          format: uuid
        reason:
          type: string
      required: [app_instance_id, app_slug, operating_mode, control_plane_scope, runtime_backend, org_id, project_id, reason]

    AppInstanceDeletingPayload:
      type: object
      additionalProperties: false
      properties:
        app_instance_id:
          type: string
          format: uuid
        app_slug:
          type: string
          pattern: '^[a-z0-9][a-z0-9-]{1,62}$'
        operating_mode:
          type: string
          enum: [tenant_dedicated, platform_managed]
        control_plane_scope:
          type: string
          enum: [project, tenant, platform]
        runtime_backend:
          type: string
          enum: [k8s, slurm, ray, bare_metal]
        org_id:
          type: string
          format: uuid
        project_id:
          type: string
          format: uuid
        requested_by_user_id:
          type: string
          format: uuid
          nullable: true
        requested_by_service_account_id:
          type: string
          format: uuid
          nullable: true
      required: [app_instance_id, app_slug, operating_mode, control_plane_scope, runtime_backend, org_id, project_id]

    AppInstanceUpgradeRequestedPayload:
      type: object
      additionalProperties: false
      properties:
        app_instance_id:
          type: string
          format: uuid
        app_slug:
          type: string
          pattern: '^[a-z0-9][a-z0-9-]{1,62}$'
        app_version:
          type: string
        previous_app_version:
          type: string
        operating_mode:
          type: string
          enum: [tenant_dedicated, platform_managed]
        control_plane_scope:
          type: string
          enum: [project, tenant, platform]
        runtime_backend:
          type: string
          enum: [k8s, slurm, ray, bare_metal]
        org_id:
          type: string
          format: uuid
        project_id:
          type: string
          format: uuid
        requested_by_user_id:
          type: string
          format: uuid
          nullable: true
        requested_by_service_account_id:
          type: string
          format: uuid
          nullable: true
        operator_service_account_id:
          type: string
          format: uuid
          nullable: true
      required: [app_instance_id, app_slug, app_version, previous_app_version, operating_mode, control_plane_scope, runtime_backend, org_id, project_id]

    AppInstanceRollbackRequestedPayload:
      type: object
      additionalProperties: false
      properties:
        app_instance_id:
          type: string
          format: uuid
        app_slug:
          type: string
          pattern: '^[a-z0-9][a-z0-9-]{1,62}$'
        app_version:
          type: string
        previous_app_version:
          type: string
        operating_mode:
          type: string
          enum: [tenant_dedicated, platform_managed]
        control_plane_scope:
          type: string
          enum: [project, tenant, platform]
        runtime_backend:
          type: string
          enum: [k8s, slurm, ray, bare_metal]
        org_id:
          type: string
          format: uuid
        project_id:
          type: string
          format: uuid
        requested_by_user_id:
          type: string
          format: uuid
          nullable: true
        requested_by_service_account_id:
          type: string
          format: uuid
          nullable: true
        operator_service_account_id:
          type: string
          format: uuid
          nullable: true
      required: [app_instance_id, app_slug, app_version, previous_app_version, operating_mode, control_plane_scope, runtime_backend, org_id, project_id]

    AppInstanceDecommissionRequestedPayload:
      type: object
      additionalProperties: false
      properties:
        app_instance_id:
          type: string
          format: uuid
        app_slug:
          type: string
          pattern: '^[a-z0-9][a-z0-9-]{1,62}$'
        app_version:
          type: string
        operating_mode:
          type: string
          enum: [tenant_dedicated, platform_managed]
        control_plane_scope:
          type: string
          enum: [project, tenant, platform]
        runtime_backend:
          type: string
          enum: [k8s, slurm, ray, bare_metal]
        org_id:
          type: string
          format: uuid
        project_id:
          type: string
          format: uuid
        requested_by_user_id:
          type: string
          format: uuid
          nullable: true
        requested_by_service_account_id:
          type: string
          format: uuid
          nullable: true
        operator_service_account_id:
          type: string
          format: uuid
          nullable: true
      required: [app_instance_id, app_slug, app_version, operating_mode, control_plane_scope, runtime_backend, org_id, project_id]

    AppInstanceLifecycleRequestedPayload:
      type: object
      additionalProperties: false
      properties:
        app_instance_id:
          type: string
          format: uuid
        app_slug:
          type: string
          pattern: '^[a-z0-9][a-z0-9-]{1,62}$'
        app_version:
          type: string
        org_id:
          type: string
          format: uuid
        project_id:
          type: string
          format: uuid
        requested_by_user_id:
          type: string
          format: uuid
          nullable: true
        requested_by_service_account_id:
          type: string
          format: uuid
          nullable: true
        operator_service_account_id:
          type: string
          format: uuid
          nullable: true
        operation:
          type: string
          enum: [stop, start, restart]
      required: [app_instance_id, app_slug, app_version, org_id, project_id, operation]

    AppInstanceDeletedPayload:
      type: object
      additionalProperties: false
      properties:
        app_instance_id:
          type: string
          format: uuid
        app_slug:
          type: string
          pattern: '^[a-z0-9][a-z0-9-]{1,62}$'
        operating_mode:
          type: string
          enum: [tenant_dedicated, platform_managed]
        control_plane_scope:
          type: string
          enum: [project, tenant, platform]
        runtime_backend:
          type: string
          enum: [k8s, slurm, ray, bare_metal]
        org_id:
          type: string
          format: uuid
        project_id:
          type: string
          format: uuid
        deleted_at:
          type: string
          format: date-time
      required: [app_instance_id, app_slug, operating_mode, control_plane_scope, runtime_backend, org_id, project_id, deleted_at]

    SharedAppRuntimeRequestedPayload:
      type: object
      additionalProperties: false
      properties:
        shared_runtime_id:
          type: string
          format: uuid
        app_slug:
          type: string
          pattern: '^[a-z0-9][a-z0-9-]{1,62}$'
        app_version:
          type: string
        operating_mode:
          type: string
          enum: [tenant_dedicated]
        control_plane_scope:
          type: string
          enum: [tenant]
        runtime_backend:
          type: string
          enum: [k8s, slurm, ray, bare_metal]
        org_id:
          type: string
          format: uuid
        requested_by_user_id:
          type: string
          format: uuid
          nullable: true
        operator_identity_ref:
          type: string
          nullable: true
      required: [shared_runtime_id, app_slug, app_version, operating_mode, control_plane_scope, runtime_backend, org_id]

    SharedAppRuntimeRunningPayload:
      type: object
      additionalProperties: false
      properties:
        shared_runtime_id:
          type: string
          format: uuid
        app_slug:
          type: string
          pattern: '^[a-z0-9][a-z0-9-]{1,62}$'
        operating_mode:
          type: string
          enum: [tenant_dedicated]
        control_plane_scope:
          type: string
          enum: [tenant]
        runtime_backend:
          type: string
          enum: [k8s, slurm, ray, bare_metal]
        org_id:
          type: string
          format: uuid
        endpoint:
          type: string
          nullable: true
      required: [shared_runtime_id, app_slug, operating_mode, control_plane_scope, runtime_backend, org_id]

    SharedAppRuntimeFailedPayload:
      type: object
      additionalProperties: false
      properties:
        shared_runtime_id:
          type: string
          format: uuid
        app_slug:
          type: string
          pattern: '^[a-z0-9][a-z0-9-]{1,62}$'
        org_id:
          type: string
          format: uuid
        reason:
          type: string
      required: [shared_runtime_id, app_slug, org_id, reason]

    SharedAppRuntimeDeletingPayload:
      type: object
      additionalProperties: false
      properties:
        shared_runtime_id:
          type: string
          format: uuid
        app_slug:
          type: string
          pattern: '^[a-z0-9][a-z0-9-]{1,62}$'
        runtime_backend:
          type: string
          enum: [k8s, slurm, ray, bare_metal]
        org_id:
          type: string
          format: uuid
        requested_by_user_id:
          type: string
          format: uuid
          nullable: true
      required: [shared_runtime_id, app_slug, runtime_backend, org_id]

    SharedAppRuntimeDeletedPayload:
      type: object
      additionalProperties: false
      properties:
        shared_runtime_id:
          type: string
          format: uuid
        app_slug:
          type: string
          pattern: '^[a-z0-9][a-z0-9-]{1,62}$'
        org_id:
          type: string
          format: uuid
        deleted_at:
          type: string
          format: date-time
      required: [shared_runtime_id, app_slug, org_id, deleted_at]

    AppArtifactLifecyclePayload:
      type: object
      additionalProperties: false
      properties:
        artifact_id:
          type: string
          format: uuid
        artifact_kind:
          type: string
          enum: [oci, blob]
        source_type:
          type: string
          enum: [oci_registry, s3, gcs, azure_blob, https, huggingface, artifact_store]
        app_slug:
          type: string
          pattern: '^[a-z0-9][a-z0-9-]{1,62}$'
        app_version:
          type: string
        artifact_name:
          type: string
        repository:
          type: string
        source_uri:
          type: string
          nullable: true
        digest:
          type: string
          pattern: '^sha256:[a-f0-9]{64}$'
        lifecycle_state:
          type: string
          enum: [published, promoted, deprecated, retired]
        trust_state:
          type: string
          enum: [unverified, verified, failed_verification, revoked]
        promoted_channel:
          type: string
          nullable: true
        target_environment:
          type: string
          nullable: true
        org_id:
          type: string
          format: uuid
          nullable: true
        project_id:
          type: string
          format: uuid
        actor_user_id:
          type: string
          format: uuid
          nullable: true
        actor_service_account_id:
          type: string
          format: uuid
          nullable: true
      required: [artifact_id, artifact_kind, source_type, app_slug, app_version, artifact_name, repository, digest, lifecycle_state, trust_state, project_id]

  messages:
    TerminalControl:
      name: TerminalControl
      messageId: terminal.control
      contentType: application/json
      payload:
        $ref: '#/components/schemas/TerminalControlPayload'

    TerminalResize:
      name: TerminalResize
      messageId: terminal.resize
      contentType: application/json
      payload:
        type: object
        additionalProperties: false
        properties:
          type:
            type: string
            const: resize
          cols:
            type: integer
            minimum: 1
          rows:
            type: integer
            minimum: 1
        required: [type, cols, rows]

    TerminalHeartbeat:
      name: TerminalHeartbeat
      messageId: terminal.heartbeat
      contentType: application/json
      payload:
        type: object
        additionalProperties: false
        description: Client keepalive frame. Gateway consumes this frame locally and must not forward it to the PTY or node-agent.
        properties:
          type:
            type: string
            const: ping
        required: [type]

    TerminalInputBinary:
      name: TerminalInputBinary
      messageId: terminal.input.binary
      contentType: application/octet-stream
      payload:
        type: string
        format: binary

    TerminalOutputText:
      name: TerminalOutputText
      messageId: terminal.output.text
      contentType: text/plain
      payload:
        type: string

    TerminalOutputBinary:
      name: TerminalOutputBinary
      messageId: terminal.output.binary
      contentType: application/octet-stream
      payload:
        type: string
        format: binary

    UserNotification:
      name: UserNotification
      messageId: notifications.user
      payload:
        $ref: '#/components/schemas/UserNotificationPayload'

    LowBalanceWarningEvent:
      name: LowBalanceWarningEvent
      messageId: billing.low_balance_warning
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: billing.low_balance_warning
              payload:
                type: object
                additionalProperties: false
                properties:
                  user_id:
                    type: string
                    format: uuid
                  balance_minor:
                    type: integer
                  threshold_minor:
                    type: integer
                  currency:
                    type: string
                    pattern: '^[A-Z]{3}$'
                  projected_depletion_at:
                    type: string
                    format: date-time
                    nullable: true
                  projected_hours_remaining:
                    type: number
                    minimum: 0
                    nullable: true
                required: [user_id, balance_minor, threshold_minor, currency]
            required: [event_type, payload]

    BalanceDepletedEvent:
      name: BalanceDepletedEvent
      messageId: billing.balance_depleted
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: billing.balance_depleted
              payload:
                type: object
                additionalProperties: false
                properties:
                  user_id:
                    type: string
                    format: uuid
                  balance_minor:
                    type: integer
                  currency:
                    type: string
                    pattern: '^[A-Z]{3}$'
                required: [user_id, balance_minor, currency]
            required: [event_type, payload]

    AutoReleasePendingEvent:
      name: AutoReleasePendingEvent
      messageId: billing.auto_release_pending
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: billing.auto_release_pending
              payload:
                type: object
                additionalProperties: false
                properties:
                  user_id:
                    type: string
                    format: uuid
                  currency:
                    type: string
                    pattern: '^[A-Z]{3}$'
                  projected_depletion_at:
                    type: string
                    format: date-time
                  projected_hours_remaining:
                    type: number
                    minimum: 0
                  active_allocation_ids:
                    type: array
                    minItems: 1
                    items:
                      type: string
                      format: uuid
                required: [user_id, currency, projected_depletion_at, projected_hours_remaining, active_allocation_ids]
            required: [event_type, payload]

    BalanceCreditedEvent:
      name: BalanceCreditedEvent
      messageId: payments.balance_credited
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: payments.balance_credited
              payload:
                $ref: '#/components/schemas/BalanceCreditedPayload'
            required: [event_type, payload]

    ReconcileFailedEvent:
      name: ReconcileFailedEvent
      messageId: payments.reconcile_failed
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: payments.reconcile_failed
              payload:
                $ref: '#/components/schemas/ReconcileFailedPayload'
            required: [event_type, payload]

    ProvisionRequestedEvent:
      name: ProvisionRequestedEvent
      messageId: provisioning.requested
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: provisioning.requested
              payload:
                $ref: '#/components/schemas/ProvisionRequestedPayload'
            required: [event_type, payload]

    AllocationActiveEvent:
      name: AllocationActiveEvent
      messageId: provisioning.active
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: provisioning.active
              payload:
                $ref: '#/components/schemas/AllocationActivePayload'
            required: [event_type, payload]

    ProvisionFailedEvent:
      name: ProvisionFailedEvent
      messageId: provisioning.failed
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: provisioning.failed
              payload:
                $ref: '#/components/schemas/ProvisionFailedPayload'
            required: [event_type, payload]

    ReleasingRequestedEvent:
      name: ReleasingRequestedEvent
      messageId: provisioning.releasing.requested
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: provisioning.releasing.requested
              payload:
                $ref: '#/components/schemas/ReleasingRequestedPayload'
            required: [event_type, payload]

    ReleasingCompletedEvent:
      name: ReleasingCompletedEvent
      messageId: provisioning.releasing.completed
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: provisioning.releasing.completed
              payload:
                $ref: '#/components/schemas/ReleasingCompletedPayload'
            required: [event_type, payload]

    ForceReleaseRequestedEvent:
      name: ForceReleaseRequestedEvent
      messageId: provisioning.force_release_requested
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: provisioning.force_release_requested
              payload:
                $ref: '#/components/schemas/ForceReleaseRequestedPayload'
            required: [event_type, payload]

    ReleaseFailedEvent:
      name: ReleaseFailedEvent
      messageId: provisioning.release_failed
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: provisioning.release_failed
              payload:
                $ref: '#/components/schemas/ReleaseFailedPayload'
            required: [event_type, payload]

    StorageAttachmentRequestedEvent:
      name: StorageAttachmentRequestedEvent
      messageId: storage.attachment.requested
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: storage.attachment.requested
              payload:
                $ref: '#/components/schemas/StorageAttachmentPayload'
            required: [event_type, payload]

    StorageAttachmentMountedEvent:
      name: StorageAttachmentMountedEvent
      messageId: storage.attachment.mounted
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: storage.attachment.mounted
              payload:
                $ref: '#/components/schemas/StorageAttachmentPayload'
            required: [event_type, payload]

    StorageAttachmentDetachRequestedEvent:
      name: StorageAttachmentDetachRequestedEvent
      messageId: storage.attachment.detach_requested
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: storage.attachment.detach_requested
              payload:
                $ref: '#/components/schemas/StorageAttachmentPayload'
            required: [event_type, payload]

    StorageAttachmentFailedEvent:
      name: StorageAttachmentFailedEvent
      messageId: storage.attachment.failed
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: storage.attachment.failed
              payload:
                $ref: '#/components/schemas/StorageAttachmentPayload'
            required: [event_type, payload]

    StorageAttachmentDetachedEvent:
      name: StorageAttachmentDetachedEvent
      messageId: storage.attachment.detached
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: storage.attachment.detached
              payload:
                $ref: '#/components/schemas/StorageAttachmentPayload'
            required: [event_type, payload]

    StorageAttachmentDetachFailedEvent:
      name: StorageAttachmentDetachFailedEvent
      messageId: storage.attachment.detach_failed
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: storage.attachment.detach_failed
              payload:
                $ref: '#/components/schemas/StorageAttachmentPayload'
            required: [event_type, payload]

    AppInstanceRequestedEvent:
      name: AppInstanceRequestedEvent
      messageId: apps.instance.requested
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: apps.instance.requested
              payload:
                $ref: '#/components/schemas/AppInstanceRequestedPayload'
            required: [event_type, payload]

    AppEntitlementUpdatedEvent:
      name: AppEntitlementUpdatedEvent
      messageId: apps.entitlement.updated
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: apps.entitlement.updated
              payload:
                $ref: '#/components/schemas/AppEntitlementUpdatedPayload'
            required: [event_type, payload]

    AppInstanceRunningEvent:
      name: AppInstanceRunningEvent
      messageId: apps.instance.running
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: apps.instance.running
              payload:
                $ref: '#/components/schemas/AppInstanceRunningPayload'
            required: [event_type, payload]

    AppInstanceFailedEvent:
      name: AppInstanceFailedEvent
      messageId: apps.instance.failed
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: apps.instance.failed
              payload:
                $ref: '#/components/schemas/AppInstanceFailedPayload'
            required: [event_type, payload]

    AppInstanceDeletingEvent:
      name: AppInstanceDeletingEvent
      messageId: apps.instance.deleting
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: apps.instance.deleting
              payload:
                $ref: '#/components/schemas/AppInstanceDeletingPayload'
            required: [event_type, payload]

    AppInstanceDeletedEvent:
      name: AppInstanceDeletedEvent
      messageId: apps.instance.deleted
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: apps.instance.deleted
              payload:
                $ref: '#/components/schemas/AppInstanceDeletedPayload'
            required: [event_type, payload]

    SharedAppRuntimeRequestedEvent:
      name: SharedAppRuntimeRequestedEvent
      messageId: apps.shared_runtime.requested
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: apps.shared_runtime.requested
              payload:
                $ref: '#/components/schemas/SharedAppRuntimeRequestedPayload'
            required: [event_type, payload]

    SharedAppRuntimeRunningEvent:
      name: SharedAppRuntimeRunningEvent
      messageId: apps.shared_runtime.running
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: apps.shared_runtime.running
              payload:
                $ref: '#/components/schemas/SharedAppRuntimeRunningPayload'
            required: [event_type, payload]

    SharedAppRuntimeFailedEvent:
      name: SharedAppRuntimeFailedEvent
      messageId: apps.shared_runtime.failed
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: apps.shared_runtime.failed
              payload:
                $ref: '#/components/schemas/SharedAppRuntimeFailedPayload'
            required: [event_type, payload]

    SharedAppRuntimeDeletingEvent:
      name: SharedAppRuntimeDeletingEvent
      messageId: apps.shared_runtime.deleting
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: apps.shared_runtime.deleting
              payload:
                $ref: '#/components/schemas/SharedAppRuntimeDeletingPayload'
            required: [event_type, payload]

    SharedAppRuntimeDeletedEvent:
      name: SharedAppRuntimeDeletedEvent
      messageId: apps.shared_runtime.deleted
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: apps.shared_runtime.deleted
              payload:
                $ref: '#/components/schemas/SharedAppRuntimeDeletedPayload'
            required: [event_type, payload]

    AppInstanceUpgradeRequestedEvent:
      name: AppInstanceUpgradeRequestedEvent
      messageId: apps.instance.upgrade_requested
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: apps.instance.upgrade_requested
              payload:
                $ref: '#/components/schemas/AppInstanceUpgradeRequestedPayload'
            required: [event_type, payload]

    AppInstanceRollbackRequestedEvent:
      name: AppInstanceRollbackRequestedEvent
      messageId: apps.instance.rollback_requested
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: apps.instance.rollback_requested
              payload:
                $ref: '#/components/schemas/AppInstanceRollbackRequestedPayload'
            required: [event_type, payload]

    AppInstanceDecommissionRequestedEvent:
      name: AppInstanceDecommissionRequestedEvent
      messageId: apps.instance.decommission_requested
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: apps.instance.decommission_requested
              payload:
                $ref: '#/components/schemas/AppInstanceDecommissionRequestedPayload'
            required: [event_type, payload]

    AppInstanceStopRequestedEvent:
      name: AppInstanceStopRequestedEvent
      messageId: apps.instance.stop_requested
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: apps.instance.stop_requested
              payload:
                $ref: '#/components/schemas/AppInstanceLifecycleRequestedPayload'
            required: [event_type, payload]

    AppInstanceStartRequestedEvent:
      name: AppInstanceStartRequestedEvent
      messageId: apps.instance.start_requested
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: apps.instance.start_requested
              payload:
                $ref: '#/components/schemas/AppInstanceLifecycleRequestedPayload'
            required: [event_type, payload]

    AppInstanceRestartRequestedEvent:
      name: AppInstanceRestartRequestedEvent
      messageId: apps.instance.restart_requested
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: apps.instance.restart_requested
              payload:
                $ref: '#/components/schemas/AppInstanceLifecycleRequestedPayload'
            required: [event_type, payload]

    AppArtifactRegisteredEvent:
      name: AppArtifactRegisteredEvent
      messageId: apps.artifact.registered
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: apps.artifact.registered
              payload:
                $ref: '#/components/schemas/AppArtifactLifecyclePayload'
            required: [event_type, payload]

    AppArtifactPromotedEvent:
      name: AppArtifactPromotedEvent
      messageId: apps.artifact.promoted
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: apps.artifact.promoted
              payload:
                $ref: '#/components/schemas/AppArtifactLifecyclePayload'
            required: [event_type, payload]

    AppArtifactVerifiedEvent:
      name: AppArtifactVerifiedEvent
      messageId: apps.artifact.verified
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: apps.artifact.verified
              payload:
                $ref: '#/components/schemas/AppArtifactLifecyclePayload'
            required: [event_type, payload]

    AppArtifactRevokedEvent:
      name: AppArtifactRevokedEvent
      messageId: apps.artifact.revoked
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: apps.artifact.revoked
              payload:
                $ref: '#/components/schemas/AppArtifactLifecyclePayload'
            required: [event_type, payload]

    AppArtifactDeprecatedEvent:
      name: AppArtifactDeprecatedEvent
      messageId: apps.artifact.deprecated
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: apps.artifact.deprecated
              payload:
                $ref: '#/components/schemas/AppArtifactLifecyclePayload'
            required: [event_type, payload]

    AppArtifactRetiredEvent:
      name: AppArtifactRetiredEvent
      messageId: apps.artifact.retired
      payload:
        allOf:
          - $ref: '#/components/schemas/EventMetadata'
          - type: object
            additionalProperties: false
            properties:
              event_type:
                const: apps.artifact.retired
              payload:
                $ref: '#/components/schemas/AppArtifactLifecyclePayload'
            required: [event_type, payload]
