openapi: 3.1.2
info:
  title: Emulator Content Server API
  version: 1.0.0
  summary: Versioned content protocol for emulator libraries.
  description: |
    To run requests, open `/docs/` on your ECS server. Sign in to obtain a
    session token and enter it under Authorize without the Bearer prefix. Device
    and guest tokens only work within their assigned permissions. Investigator
    and workflow host operations have separate credentials.

    Example credentials and IDs are placeholders. Replace them with values
    returned by your own server. Trusted local connections may work without a
    token according to the server's access policy. Owner actions require the
    corresponding authority.
servers:
  - url: /
security:
  - bearerAuth: []
tags:
  - name: Discovery
  - name: Authentication
  - name: Access and credentials
  - name: Libraries and items
  - name: Uploads and downloads
  - name: Folders and sources
  - name: Matching and jobs
  - name: Players
  - name: Investigators
  - name: Workflow review
  - name: Workflow workers
  - name: Server and plugins
paths:
  /health:
    get:
      operationId: getHealth
      tags: [Discovery]
      security: []
      responses:
        '200':
          description: Process is serving.
          content:
            application/json:
              example: {"ok": true}
              schema: {"type": "object", "required": ["ok"], "properties": {"ok": {"type": "boolean", "const": true}}}
  /openapi.yaml:
    get:
      operationId: getOpenApi
      tags: [Discovery]
      security: []
      responses:
        '200':
          description: This document.
          content:
            application/yaml:
              schema: {"type": "string"}
  /api/v1/capabilities:
    get:
      operationId: getCapabilities
      tags: [Discovery]
      security: []
      responses:
        '200':
          description: Protocol capabilities.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Capabilities'
  /api/v1/server/updates:
    get:
      operationId: getServerUpdates
      tags: [Server and plugins]
      description: Signed-in owner only. Server installation and update status.
      responses:
        '200':
          description: Update status.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/ServerUpdateStatus' }
    put:
      operationId: configureServerUpdates
      tags: [Server and plugins]
      description: Signed-in owner only. Select a GitHub server channel and update mode.
      requestBody:
        required: true
        content:
          application/json:
            example: {"channel": "release", "mode": "manual"}
            schema: { $ref: '#/components/schemas/ServerUpdateSettings' }
      responses:
        '200':
          description: Saved settings.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/ServerUpdateStatus' }
    post:
      operationId: decideServerUpdate
      tags: [Server and plugins]
      description: Signed-in owner only. Check for updates or act on a specific build.
      requestBody:
        required: true
        content:
          application/json:
            example: {"action": "check"}
            schema: { $ref: '#/components/schemas/ServerUpdateDecision' }
      responses:
        '200':
          description: Current status. An installation can continue in the background.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/ServerUpdateStatus' }
  /api/v1/plugins:
    get:
      operationId: getPluginManagement
      tags: [Server and plugins]
      description: Signed-in owner only. Managed native plugins and host health.
      responses:
        '200':
          description: Plugin installation state.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/PluginManagement' }
    patch:
      operationId: configurePlugin
      tags: [Server and plugins]
      description: Signed-in owner only. Enable an installed immutable plugin version or disable its package.
      requestBody:
        required: true
        content:
          application/json:
            example: {"id": "org.ecs.example", "digest": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", "enabled": true}
            schema: { $ref: '#/components/schemas/PluginConfiguration' }
      responses:
        '200':
          description: Updated plugin state.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/PluginManagement' }
  /api/v1/plugins/defaults:
    post:
      operationId: installDefaultPlugins
      tags: [Server and plugins]
      description: Signed-in owner only. Install bundled native plugins and provision a scoped local workflow host.
      responses:
        '200':
          description: Installed plugins and host state.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/PluginManagement' }
  /api/v1/plugins/doctor:
    post:
      operationId: doctorPlugins
      tags: [Server and plugins]
      description: Signed-in owner only. Check packages, repair revoked host enrollment and resume the local plugin host.
      responses:
        '200':
          description: Checked plugin state.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/PluginManagement' }
  /api/v1/player/core:
    get:
      operationId: getPlayerCore
      tags: [Players]
      security: [{ bearerAuth: [] }, {}]
      description: Trusted browser core metadata. Requires an admitted actor with read permission.
      responses:
        '200':
          description: Configured core descriptor without operator filesystem paths.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PlayerCoreDescriptor'
        '401':
          description: Authentication required.
        '403':
          description: Read permission required.
        '404':
          description: Browser playback is not configured.
  /play/cores/{coreId}/loader.js:
    get:
      operationId: getPlayerCoreLoader
      tags: [Players]
      security: [{ bearerAuth: [] }, {}]
      description: JavaScript loader named by the trusted browser core descriptor. Requires read permission.
      parameters:
        - { name: coreId, in: path, required: true, schema: { type: string } }
      responses:
        '200':
          description: JavaScript loader bytes.
          headers:
            ETag: { $ref: '#/components/headers/ETag' }
          content:
            text/javascript:
              schema: { type: string, format: binary }
        '401': { description: Authentication required. }
        '403': { description: Read permission required. }
        '404': { description: Browser core is not available. }
  /play/cores/{coreId}/core.wasm:
    get:
      operationId: getPlayerCoreWasm
      tags: [Players]
      security: [{ bearerAuth: [] }, {}]
      description: WebAssembly module named by the trusted browser core descriptor. Requires read permission.
      parameters:
        - { name: coreId, in: path, required: true, schema: { type: string } }
      responses:
        '200':
          description: WebAssembly module bytes.
          headers:
            ETag: { $ref: '#/components/headers/ETag' }
          content:
            application/wasm:
              schema: { type: string, format: binary }
        '401': { description: Authentication required. }
        '403': { description: Read permission required. }
        '404': { description: Browser core is not available. }
  /api/v1/player/management:
    get:
      operationId: getPlayerManagement
      tags: [Players]
      description: Owner bearer only. Installed emulators and trusted installation catalog without server paths.
      responses:
        '200':
          description: Emulator installation state.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/PlayerManagement' }
        '401': { description: Authentication required. }
        '403': { description: Owner sign-in required. }
  /api/v1/player/management/install:
    post:
      operationId: installPlayerPackage
      tags: [Players]
      description: Owner bearer only. Bounded ECS player package with hash-verified data-only manifest and resources. Activates atomically without restart.
      requestBody:
        required: true
        content:
          application/vnd.ecs.player-package:
            schema: { type: string, format: binary }
      responses:
        '200':
          description: Installed and activated.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/PlayerManagement' }
        '400': { description: Invalid or incompatible package. }
        '409': { description: Already installed or registry limit reached. }
  /api/v1/player/management/install/{id}:
    post:
      operationId: installCatalogPlayer
      tags: [Players]
      description: Owner bearer only. Install one pinned trusted catalog entry; arbitrary URLs are not accepted.
      parameters:
        - { name: id, in: path, required: true, schema: { type: string } }
      responses:
        '200':
          description: Installed and activated.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/PlayerManagement' }
        '404': { description: Catalog entry is not available. }
        '409': { description: Already installed. }
  /api/v1/player/management/{id}/system/{name}:
    put:
      operationId: installPlayerSystemFile
      tags: [Players]
      description: |
        Owner bearer only. Add or replace an operator-provided system file of
        1 byte to 32 MiB on a managed emulator with firmware support. Use a
        portable filename without a trailing period or a reserved name. An
        `awbios.zip` upload for `org.libretro.parallel-dc` must contain the
        131,072-byte `bios0.ic23` file. Installed firmware is shared with
        admitted players.
      parameters:
        - { name: id, in: path, required: true, schema: { type: string } }
        - { name: name, in: path, required: true, schema: { type: string, pattern: '^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$' } }
      requestBody:
        required: true
        content:
          application/vnd.ecs.player-system-file:
            schema: { type: string, format: binary }
      responses:
        '200':
          description: Installed for the next launch without changing games or saves.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/PlayerManagement' }
        '400': { description: Invalid system-file archive or size. }
        '403': { description: Owner sign-in or managed emulator required. }
        '404': { description: Emulator is not installed. }
  /api/v1/player/management/{id}:
    patch:
      operationId: configurePlayer
      tags: [Players]
      description: Owner bearer only. Enable, disable or select the default emulator. Existing sessions keep their loaded bytes.
      parameters:
        - { name: id, in: path, required: true, schema: { type: string } }
      requestBody:
        required: true
        content:
          application/json:
            example: {"enabled": true, "default": true}
            schema: { $ref: '#/components/schemas/PlayerConfiguration' }
      responses:
        '200':
          description: Updated installation state.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/PlayerManagement' }
    delete:
      operationId: removePlayer
      tags: [Players]
      description: Owner bearer only. Remove a managed emulator installation. Operator-configured files are read-only; games and saves are preserved.
      parameters:
        - { name: id, in: path, required: true, schema: { type: string } }
      responses:
        '200':
          description: Updated installation state.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/PlayerManagement' }
  /api/v1/player/isolated-sessions:
    post:
      operationId: createPlayerIsolation
      tags: [Players]
      description: Read bearer required. Local HTTP browser only; actual socket peer, Host, and exact Origin must be loopback. Creates a bounded ten-minute companion listener serving only a fixed first-party bootstrap for an enabled threaded Dolphin profile. No credentials, content, API, or registry resources are served by that listener.
      parameters:
        - { name: Origin, in: header, required: true, schema: { type: string } }
      requestBody:
        required: true
        content:
          application/json:
            example: {"profileId": "org.libretro.dolphin"}
            schema: { $ref: '#/components/schemas/PlayerIsolationDraft' }
      responses:
        '201':
          description: Separate loopback origin and random fixed bootstrap route. Four active listeners globally and two per actor. Expired or closed sessions retain 404-only origins, up to 64 listeners per main-server lifetime, to prevent origin reuse while an old iframe may still run. All listeners close with the main server.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/PlayerIsolationSession' }
        '400': { description: Invalid request body. }
        '401': { description: Bearer authentication required. }
        '403': { description: Read scope or local browser origin required. }
        '404': { description: Enabled compatible profile or fixed UI bootstrap unavailable. }
        '429': { description: Session or creation-rate limit reached. }
  /api/v1/player/isolated-sessions/{id}:
    delete:
      operationId: closePlayerIsolation
      tags: [Players]
      description: Close the caller actor's ephemeral local companion. Requires the same read bearer and local HTTP origin policy as creation. Foreign or expired session identifiers are not disclosed.
      parameters:
        - { name: id, in: path, required: true, schema: { type: string, pattern: '^[a-f0-9]{48}$' } }
        - { name: Origin, in: header, required: true, schema: { type: string } }
      responses:
        '204': { description: Session closed; origin retained as a 404-only tombstone until main-server shutdown. }
        '401': { description: Bearer authentication required. }
        '403': { description: Read scope or local browser origin required. }
        '404': { description: Session unavailable to this actor. }
  /api/v1/player/profiles:
    get:
      operationId: listPlayerProfiles
      tags: [Players]
      security: [{ bearerAuth: [] }, {}]
      description: Browser runtime profiles. Requires read permission.
      responses:
        '200':
          description: Configured profiles, empty when playback is disabled.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/WebPlayerCatalog' }
        '401': { description: Authentication required. }
        '403': { description: Read permission required. }
  /api/v1/player/profiles/{id}:
    get:
      operationId: getPlayerProfile
      tags: [Players]
      security: [{ bearerAuth: [] }, {}]
      parameters:
        - { name: id, in: path, required: true, schema: { type: string } }
      responses:
        '200':
          description: Immutable verified profile without operator paths.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/WebPlayerDescriptor' }
        '401': { description: Authentication required. }
        '403': { description: Read permission required. }
        '404': { description: Profile is not configured. }
  /play/plugins/{id}/loader.js:
    get:
      operationId: getPlayerProfileLoader
      tags: [Players]
      security: [{ bearerAuth: [] }, {}]
      description: Authenticated immutable startup snapshot; requires read permission.
      parameters:
        - { name: id, in: path, required: true, schema: { type: string } }
        - { $ref: '#/components/parameters/ContentVersion' }
      responses:
        '200':
          description: Hash-verified declared profile resource.
          content:
            text/javascript:
              schema: { type: string, format: binary }
        '401': { description: Authentication required. }
        '403': { description: Read permission required. }
        '404': { description: Profile or resource is not configured. }
  /play/plugins/{id}/core.wasm:
    get:
      operationId: getPlayerProfileWasm
      tags: [Players]
      security: [{ bearerAuth: [] }, {}]
      description: Authenticated immutable startup snapshot; requires read permission.
      parameters:
        - { name: id, in: path, required: true, schema: { type: string } }
        - { $ref: '#/components/parameters/ContentVersion' }
      responses:
        '200':
          description: Hash-verified declared profile resource.
          content:
            application/wasm:
              schema: { type: string, format: binary }
        '401': { description: Authentication required. }
        '403': { description: Read permission required. }
        '404': { description: Profile or resource is not configured. }
  /play/plugins/{id}/assets/{name}:
    get:
      operationId: getPlayerProfileAsset
      tags: [Players]
      security: [{ bearerAuth: [] }, {}]
      description: Authenticated immutable startup snapshot; requires read permission.
      parameters:
        - { name: id, in: path, required: true, schema: { type: string } }
        - { name: name, in: path, required: true, schema: { type: string } }
        - { $ref: '#/components/parameters/ContentVersion' }
      responses:
        '200':
          description: Hash-verified declared profile resource.
          content:
            application/octet-stream:
              schema: { type: string, format: binary }
        '401': { description: Authentication required. }
        '403': { description: Read permission required. }
        '404': { description: Profile or resource is not configured. }
  /api/v1/systems:
    get:
      operationId: listSystems
      tags: [Discovery]
      security: []
      responses:
        '200':
          description: Known system vocabulary. The catalog is not closed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SystemList'
  /api/v1/auth/bootstrap:
    post:
      operationId: bootstrap
      tags: [Authentication]
      security: []
      requestBody:
        required: true
        content:
          application/json:
            example: {"token": "REPLACE_WITH_BOOTSTRAP_TOKEN", "username": "library-owner", "password": "REPLACE_WITH_NEW_PASSWORD"}
            schema: { $ref: '#/components/schemas/BootstrapRequest' }
      responses:
        '201':
          description: Owner created.
          content:
            application/json:
              example: {"token": "REPLACE_WITH_RETURNED_SESSION_TOKEN", "tokenType": "Bearer", "userId": "user-demo", "expiresAt": "2026-11-10T20:00:00Z"}
              schema: { $ref: '#/components/schemas/SessionResponse' }
  /api/v1/auth/login:
    post:
      operationId: login
      tags: [Authentication]
      security: []
      requestBody:
        required: true
        content:
          application/json:
            example: {"username": "library-owner", "password": "REPLACE_WITH_PASSWORD"}
            schema: { $ref: '#/components/schemas/LoginRequest' }
      responses:
        '200':
          description: Session created.
          content:
            application/json:
              example: {"token": "REPLACE_WITH_RETURNED_SESSION_TOKEN", "tokenType": "Bearer", "userId": "user-demo", "expiresAt": "2026-11-10T20:00:00Z"}
              schema: { $ref: '#/components/schemas/SessionResponse' }
        '401': { description: Username or password is incorrect. }
        '429': { description: Too many attempts. }
  /api/v1/auth/local:
    post:
      operationId: localSignIn
      tags: [Authentication]
      summary: Sign in as the owner from the computer that runs the server.
      description: >-
        Exchanges the key the server wrote to `local-owner.key` in its data folder for an ordinary
        owner session. Only a loopback connection is accepted, and only while
        `features.localOwnerSignIn` is true. The key proves the caller can read the server's own
        files; it is replaced every time the server starts. Send it in the body, never in a URL.
      security: []
      requestBody:
        required: true
        content:
          application/json:
            example: {"key": "REPLACE_WITH_LOCAL_OWNER_KEY"}
            schema: { $ref: '#/components/schemas/LocalSignInRequest' }
      responses:
        '200':
          description: Owner session created.
          content:
            application/json:
              example: {"token": "REPLACE_WITH_RETURNED_SESSION_TOKEN", "tokenType": "Bearer", "userId": "user-demo", "expiresAt": "2026-11-10T20:00:00Z"}
              schema: { $ref: '#/components/schemas/SessionResponse' }
        '401': { description: The key is not this server's current key. }
        '403': { description: The connection is not from this computer. }
        '409': { description: "Local owner sign-in is unavailable, or no owner account exists yet." }
        '429': { description: Too many attempts. }
  /api/v1/auth/logout:
    post:
      operationId: logout
      tags: [Authentication]
      security: [{ bearerAuth: [] }]
      responses:
        '204':
          description: Session revoked.
  /api/v1/access:
    get:
      operationId: getAccess
      tags: [Access and credentials]
      security: []
      responses:
        '200':
          description: Who may use this server without a token, and whether this connection may.
          content:
            application/json:
              example: {"mode": "token", "subnets": [], "applies": true, "trusted": false, "manages": false}
              schema: {"$ref": "#/components/schemas/AccessPolicy"}
    put:
      operationId: putAccess
      tags: [Access and credentials]
      requestBody:
        required: true
        content:
          application/json:
            example: {"mode": "token", "subnets": []}
            schema: {"type": "object", "required": ["mode"], "properties": {"mode": {"type": "string", "enum": ["lan", "token", "subnets"]}, "subnets": {"type": "array", "items": {"type": "string"}}}}
      responses:
        '200':
          description: Access rule replaced.
          content:
            application/json:
              example: {"mode": "token", "subnets": [], "applies": true, "trusted": false, "manages": false}
              schema: {"$ref": "#/components/schemas/AccessPolicy"}
  /api/v1/users:
    get:
      operationId: listUsers
      tags: [Access and credentials]
      responses:
        '200':
          description: Accounts on this server.
          content:
            application/json:
              schema: {"type": "object", "required": ["items"], "properties": {"items": {"type": "array", "items": {"$ref": "#/components/schemas/User"}}}}
    post:
      operationId: createUser
      tags: [Access and credentials]
      parameters:
        - {"$ref": "#/components/parameters/IdempotencyKey"}
      requestBody:
        required: true
        content:
          application/json:
            example: {"username": "library-reader", "password": "REPLACE_WITH_NEW_PASSWORD"}
            schema: {"$ref": "#/components/schemas/UserDraft"}
      responses:
        '201':
          description: User created.
          content:
            application/json:
              schema: {"$ref": "#/components/schemas/User"}
  /api/v1/users/{userId}:
    parameters:
      - { name: userId, in: path, required: true, schema: { type: string } }
    patch:
      operationId: setPassword
      tags: [Access and credentials]
      requestBody:
        required: true
        content:
          application/json:
            example: {"password": "REPLACE_WITH_NEW_PASSWORD"}
            schema: {"type": "object", "required": ["password"], "properties": {"password": {"type": "string"}}}
      responses:
        '204':
          description: Password replaced.
  /api/v1/items/{itemId}/rom-copies:
    parameters:
      - { name: itemId, in: path, required: true, schema: { type: string } }
    get:
      operationId: gameRomCopies
      tags: [Libraries and items]
      responses:
        '200':
          description: Readable ROM copies of one game.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/GameRomCopies' }
  /api/v1/items/{itemId}/rom-selection:
    parameters:
      - { name: itemId, in: path, required: true, schema: { type: string } }
    post:
      operationId: selectGameRom
      tags: [Libraries and items]
      requestBody:
        required: true
        content:
          application/json:
            example: {"systems":[{"systemId":"com.provenance.dreamcast","formats":["chd","cdi"]}]}
            schema: { $ref: '#/components/schemas/GameRomPreferences' }
      responses:
        '200':
          description: Best readable copy for the announced system and formats, when available.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/GameRomSelection' }
  /api/v1/sources/{sourceId}/game:
    parameters:
      - { name: sourceId, in: path, required: true, schema: { type: string } }
    put:
      operationId: linkGameSource
      tags: [Folders and sources]
      requestBody:
        required: true
        content:
          application/json:
            example: {"title":"Example game"}
            schema: { $ref: '#/components/schemas/GameSourceLink' }
      responses:
        '200':
          description: Owner linked the folder source to a game, created its game entry, or removed the link.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/GameSourceLink' }
  /api/v1/browse:
    get:
      operationId: browseLibrary
      tags: [Libraries and items]
      security: [{ bearerAuth: [] }, {}]
      description: Bounded authorized collection. Exactly one of libraryId or unassigned=true is required. Unknown systems use systemId=unknown. Authorization and category filtering precede paging. Cursors bind normalized query and actor; changed or vanished anchors require refresh.
      parameters:
        - { name: libraryId, in: query, schema: { type: string } }
        - { name: unassigned, in: query, schema: { type: boolean }, description: Actual owner only. }
        - { name: category, in: query, required: true, schema: { type: string, enum: [games, saves, media, system_files] } }
        - { name: rootId, in: query, schema: { type: string } }
        - { name: systemId, in: query, schema: { type: string } }
        - { name: systemIds, in: query, description: Comma-separated system identifiers; OR selection; takes precedence over systemId., schema: { type: string, maxLength: 12000 } }
        - { name: search, in: query, schema: { type: string, maxLength: 256 } }
        - { name: sort, in: query, schema: { type: string, enum: [name_asc, name_desc], default: name_asc } }
        - { name: cursor, in: query, schema: { type: string, maxLength: 4096 } }
        - { name: limit, in: query, schema: { type: integer, minimum: 1, maximum: 100, default: 50 } }
        - { name: includeRomDownload, in: query, schema: { type: boolean, default: false }, example: true, description: 'Include authorized ROM download summaries on uploaded game rows. Scanned sources retain their existing filename, size and group fields.' }
      responses:
        '200':
          description: Authorized page; at most the requested limit. No absolute filesystem paths.
          content:
            application/json:
              example: {"items": [], "nextCursor": null}
              schema: { $ref: '#/components/schemas/LibraryBrowsePage' }
        '400': { description: Invalid query or cursor. Refresh after a changed anchor. }
        '401': { description: Authentication required. }
        '403': { description: Read scope or owner authority required. }
        '404': { description: Scope or folder unavailable. }
  /api/v1/browse-libraries:
    get:
      operationId: browseLibraries
      tags: [Libraries and items]
      security: [{ bearerAuth: [] }, {}]
      description: Libraries discoverable through membership or live readable item grants. canCreateItems reflects current create policy.
      responses:
        '200':
          description: Accessible libraries.
          content:
            application/json:
              example: {"items": [{"id": "library-demo", "name": "Retro games", "ownerId": "user-demo", "revision": 1, "createdAt": "2026-11-10T19:00:00Z", "canCreateItems": true}], "nextCursor": null}
              schema: { $ref: '#/components/schemas/LibraryList' }
  /api/v1/root-summaries:
    get:
      operationId: rootSummaries
      tags: [Folders and sources]
      description: Actual owner only. Cached counts and scan/check state; performs no probes or scans. Optional libraryId and unassigned=true filters are exclusive.
      parameters:
        - { name: libraryId, in: query, schema: { type: string } }
        - { name: unassigned, in: query, schema: { type: boolean } }
      responses:
        '200':
          description: Cached folder summaries; missing check means unknown availability.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/ContentRootSummaryList' }
        '400': { description: Invalid filter. }
        '403': { description: Actual owner authority required. }
  /api/v1/libraries/{libraryId}:
    patch:
      operationId: renameLibrary
      tags: [Libraries and items]
      description: Actual owner only. Renames a library without moving content.
      parameters:
        - { name: libraryId, in: path, required: true, schema: { type: string } }
        - { name: If-Match, in: header, required: true, schema: { type: string }, description: 'Revision validator "rev-N".' }
      requestBody:
        required: true
        content:
          application/json:
            example: {"name": "Handheld games"}
            schema: { $ref: '#/components/schemas/LibraryDraft' }
      responses:
        '200':
          description: Renamed library.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Library' }
        '409': { description: Revision conflict. }
        '428': { description: Revision validator required. }
        '403': { description: Actual owner authority required. }
        '404': { description: Library unavailable. }
  /api/v1/roots/{rootId}/library:
    put:
      operationId: assignRoot
      tags: [Folders and sources]
      description: Actual owner only. Assigns an unassigned folder in place; idempotent for the same target, rejects moving an assigned folder.
      parameters:
        - { name: rootId, in: path, required: true, schema: { type: string } }
      requestBody:
        required: true
        content:
          application/json:
            example: {"libraryId": "library-demo"}
            schema: { $ref: '#/components/schemas/RootLibraryAssignment' }
      responses:
        '200':
          description: Assigned folder.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/ContentRoot' }
        '409': { description: Folder already assigned elsewhere. }
        '403': { description: Actual owner authority required. }
        '404': { description: Library or folder unavailable. }
  /api/v1/libraries:
    get:
      operationId: listLibraries
      tags: [Libraries and items]
      security: [{ bearerAuth: [] }, {}]
      responses:
        '200':
          description: Visible libraries.
          content:
            application/json:
              example: {"items": [{"id": "library-demo", "name": "Retro games", "ownerId": "user-demo", "revision": 1, "createdAt": "2026-11-10T19:00:00Z", "canCreateItems": true}], "nextCursor": null}
              schema: {"$ref": "#/components/schemas/LibraryList"}
    post:
      operationId: createLibrary
      tags: [Libraries and items]
      requestBody:
        required: true
        content:
          application/json:
            example: {"name": "Retro games"}
            schema: {"$ref": "#/components/schemas/LibraryDraft"}
      responses:
        '201':
          description: Library created.
          content:
            application/json:
              schema: {"$ref": "#/components/schemas/Library"}
  /api/v1/libraries/{libraryId}/members:
    parameters:
      - { name: libraryId, in: path, required: true, schema: { type: string } }
    get:
      operationId: listLibraryMembers
      tags: [Libraries and items]
      responses:
        '200':
          description: Library membership metadata, visible to library administrators.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/LibraryMemberList' }
  /api/v1/libraries/{libraryId}/members/{userId}:
    parameters:
      - { name: libraryId, in: path, required: true, schema: { type: string } }
      - { name: userId, in: path, required: true, schema: { type: string } }
    put:
      operationId: putMember
      tags: [Libraries and items]
      requestBody:
        required: true
        content:
          application/json:
            example: {"role": "reader"}
            schema: {"$ref": "#/components/schemas/MemberDraft"}
      responses:
        '204':
          description: Membership replaced.
    delete:
      operationId: deleteMember
      tags: [Libraries and items]
      responses:
        '204':
          description: Membership removed.
  /api/v1/items:
    get:
      operationId: listItems
      tags: [Libraries and items]
      security: [{ bearerAuth: [] }, {}]
      parameters:
        - { name: libraryId, in: query, required: true, schema: { type: string } }
        - { name: cursor, in: query, schema: { type: string }, description: Opaque cursor from the previous page. }
        - { name: limit, in: query, schema: { type: integer, minimum: 1, maximum: 100 } }
      responses:
        '200':
          description: Item page.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/ItemList' }
    post:
      operationId: createItem
      tags: [Libraries and items]
      parameters:
        - {"$ref": "#/components/parameters/IdempotencyKey"}
      requestBody:
        required: true
        content:
          application/json:
            example: {"libraryId": "library-demo", "systemIdentifier": "com.provenance.nes", "title": "Example game"}
            schema: {"$ref": "#/components/schemas/ItemDraft"}
      responses:
        '201':
          description: Item created.
          content:
            application/json:
              schema: {"$ref": "#/components/schemas/Item"}
  /api/v1/items/{itemId}:
    parameters:
      - { name: itemId, in: path, required: true, schema: { type: string } }
    get:
      operationId: getItem
      tags: [Libraries and items]
      security: [{ bearerAuth: [] }, {}]
      responses:
        '200':
          description: Item.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Item' }
    patch:
      operationId: patchItem
      tags: [Libraries and items]
      parameters:
        - {"$ref": "#/components/parameters/RevisionMatch"}
      requestBody:
        required: true
        content:
          application/json:
            example: {"title": "Example game (revised)"}
            schema: {"$ref": "#/components/schemas/ItemPatch"}
      responses:
        '200':
          description: Item updated.
          content:
            application/json:
              schema: {"$ref": "#/components/schemas/Item"}
        '409': { description: Revision conflict. }
        '428': { description: Revision validator required. }
    delete:
      operationId: deleteItem
      tags: [Libraries and items]
      responses:
        '204':
          description: Item moved to the trash with its files. It can be restored until its purgeAfter date.
  /api/v1/items/{itemId}/restore:
    parameters:
      - { name: itemId, in: path, required: true, schema: { type: string } }
    post:
      operationId: restoreItem
      tags: [Libraries and items]
      description: Returns a deleted game and the files deleted with it. Needs write access to the game and a signed-in account. Restoring a game that is already live returns it unchanged.
      responses:
        '200':
          description: The game is live again.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Item' }
        '401': { description: Authentication is required. }
        '403': { description: Write access to the game and a signed-in account are required. }
        '404': { description: 'The game is unknown, hidden, or already purged.' }
        '413': { description: Restoring would exceed the library byte quota. }
  /api/v1/trash:
    get:
      operationId: listTrash
      tags: [Libraries and items]
      description: Deleted games and files the caller may restore, newest first. A game deleted with its files is one entry. Guest grants cannot list the trash.
      parameters:
        - { name: libraryId, in: query, schema: { type: string } }
        - { name: cursor, in: query, schema: { type: string, maxLength: 4096 }, description: Use nextCursor verbatim. }
        - { name: limit, in: query, schema: { type: integer, minimum: 1, maximum: 100, default: 50 } }
      responses:
        '200':
          description: One page of the trash.
          content:
            application/json:
              example: {"entries": [{"kind": "item", "id": "item-demo", "name": "Example game", "libraryId": "library-demo", "itemId": "item-demo", "itemTitle": "Example game", "systemIdentifier": "com.provenance.nes", "size": 262160, "fileCount": 1, "deletedAt": "2026-11-16T19:00:00.000Z", "deletedBy": {"id": "user-demo", "name": "owner"}, "purgeAfter": "2026-12-16T19:00:00.000Z", "itemDeleted": false}], "nextCursor": null}
              schema: { $ref: '#/components/schemas/TrashPage' }
        '401': { description: Authentication is required. }
        '403': { description: A signed-in account with write scope is required. }
  /api/v1/items/{itemId}/manifest:
    parameters:
      - { name: itemId, in: path, required: true, schema: { type: string } }
    get:
      operationId: getManifest
      tags: [Libraries and items]
      security: [{ bearerAuth: [] }, {}]
      responses:
        '200':
          description: File manifest.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Manifest' }
  /api/v1/items/{itemId}/companions:
    parameters:
      - { name: itemId, in: path, required: true, schema: { type: string } }
    get:
      operationId: itemCompanions
      tags: [Libraries and items]
      security: [{ bearerAuth: [] }, {}]
      responses:
        '200':
          description: Companion capabilities for an authorized uploaded item. Uploaded items currently expose no companion kinds.
          content:
            application/json:
              example: { supportedKinds: [], items: [] }
              schema: { $ref: '#/components/schemas/CompanionList' }
        '404': { description: Item unavailable to the caller. }
  /api/v1/items/{itemId}/access/{userId}:
    parameters:
      - { name: itemId, in: path, required: true, schema: { type: string } }
      - { name: userId, in: path, required: true, schema: { type: string } }
    put:
      operationId: putItemAccess
      tags: [Libraries and items]
      requestBody:
        required: true
        content:
          application/json:
            example: {"permission": "read"}
            schema: {"$ref": "#/components/schemas/ItemAccessDraft"}
      responses:
        '204':
          description: Item grant replaced.
    delete:
      operationId: deleteItemAccess
      tags: [Libraries and items]
      responses:
        '204':
          description: Item grant removed.
  /api/v1/uploads:
    post:
      operationId: createUpload
      tags: [Uploads and downloads]
      parameters:
        - {"$ref": "#/components/parameters/IdempotencyKey"}
      requestBody:
        required: true
        content:
          application/json:
            example: {"libraryId": "library-demo"}
            schema: {"type": "object", "required": ["libraryId"], "properties": {"libraryId": {"type": "string"}}}
      responses:
        '201':
          description: Upload session created.
          content:
            application/json:
              example: {"id": "upload-demo", "received": 0, "state": "open"}
              schema: {"$ref": "#/components/schemas/UploadSession"}
  /api/v1/uploads/{uploadId}/content:
    parameters:
      - { name: uploadId, in: path, required: true, schema: { type: string } }
    put:
      operationId: uploadContent
      tags: [Uploads and downloads]
      parameters:
        - {"$ref": "#/components/parameters/UploadRange"}
      requestBody:
        required: true
        content:
          application/octet-stream:
            schema: {"type": "string", "format": "binary"}
      responses:
        '204':
          description: Bytes accepted.
  /api/v1/uploads/{uploadId}/complete:
    parameters:
      - { name: uploadId, in: path, required: true, schema: { type: string } }
    post:
      operationId: completeUpload
      tags: [Uploads and downloads]
      parameters:
        - {"$ref": "#/components/parameters/IdempotencyKey"}
      requestBody:
        required: true
        content:
          application/json:
            example: {"itemId": "item-demo", "kind": "rom", "displayName": "Example game", "relativePath": "Example.nes", "baseRevision": 1}
            schema: {"$ref": "#/components/schemas/UploadComplete"}
      responses:
        '201':
          description: Asset committed.
          content:
            application/json:
              schema: {"$ref": "#/components/schemas/Asset"}
  /api/v1/uploads/{uploadId}:
    parameters:
      - { name: uploadId, in: path, required: true, schema: { type: string } }
    get:
      operationId: getUpload
      tags: [Uploads and downloads]
      responses:
        '200':
          description: Received byte offset, so an interrupted upload can resume.
          content:
            application/json:
              example: {"id": "upload-demo", "received": 65536, "state": "open"}
              schema:
                $ref: '#/components/schemas/UploadSession'
    delete:
      operationId: abortUpload
      tags: [Uploads and downloads]
      responses:
        '204':
          description: Upload aborted.
  /api/v1/files/{assetId}:
    parameters:
      - { name: assetId, in: path, required: true, schema: { type: string } }
    get:
      operationId: getFileMetadata
      tags: [Uploads and downloads]
      security: [{ bearerAuth: [] }, {}]
      responses:
        '200':
          description: Asset metadata.
          content:
            application/json:
              schema: {"$ref": "#/components/schemas/Asset"}
    delete:
      operationId: deleteFile
      tags: [Uploads and downloads]
      responses:
        '204':
          description: File moved to the trash. It can be restored until its purgeAfter date.
  /api/v1/files/{assetId}/restore:
    parameters:
      - { name: assetId, in: path, required: true, schema: { type: string } }
    post:
      operationId: restoreFile
      tags: [Uploads and downloads]
      description: Returns a deleted file to its game. If a newer file now holds its path, the restored file comes back beside it as a conflict copy and neither is overwritten.
      responses:
        '200':
          description: The file is live again.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Asset' }
        '401': { description: Authentication is required. }
        '403': { description: Write access to the game and a signed-in account are required. }
        '404': { description: 'The file is unknown, hidden, or already purged.' }
        '409': { description: The file's game is in the trash. Restore the game first. }
        '413': { description: Restoring would exceed the library byte quota. }
  /api/v1/files/{assetId}/adopt:
    parameters:
      - { name: assetId, in: path, required: true, schema: { type: string } }
    post:
      operationId: adoptFile
      tags: [Uploads and downloads]
      responses:
        '200':
          description: The chosen save is now the live file at its path. The bytes it replaced stay beside it.
          content:
            application/json:
              schema: {"$ref": "#/components/schemas/Asset"}
  /api/v1/files/{assetId}/content:
    parameters:
      - { name: assetId, in: path, required: true, schema: { type: string } }
      - { $ref: '#/components/parameters/ContentVersion' }
      - { $ref: '#/components/parameters/Range' }
      - { $ref: '#/components/parameters/IfRange' }
      - { $ref: '#/components/parameters/IfNoneMatch' }
    get:
      operationId: getFileContent
      tags: [Uploads and downloads]
      security: [{ bearerAuth: [] }, {}]
      responses:
        '200': { $ref: '#/components/responses/Content' }
        '206': { $ref: '#/components/responses/PartialContent' }
        '304': { description: Representation unchanged. }
        '416': { $ref: '#/components/responses/UnsatisfiableRange' }
    head:
      operationId: headFileContent
      tags: [Uploads and downloads]
      security: [{ bearerAuth: [] }, {}]
      responses:
        '200': { $ref: '#/components/responses/ContentHeaders' }
        '206': { $ref: '#/components/responses/PartialContentHeaders' }
        '304': { description: Representation unchanged. }
        '416': { $ref: '#/components/responses/UnsatisfiableRange' }
  /api/v1/files/{assetId}/entries:
    parameters:
      - { name: assetId, in: path, required: true, schema: { type: string } }
    get:
      operationId: listVirtualEntries
      tags: [Uploads and downloads]
      security: [{ bearerAuth: [] }, {}]
      parameters:
        - {"name": "entry", "in": "query", "schema": {"type": "string"}, "description": "Optional virtual entry path to inspect."}
      responses:
        '200':
          description: Virtual entries when a format provider exists.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/VirtualEntryList'
  /api/v1/files/{assetId}/entries/{entryId}/content:
    parameters:
      - { name: assetId, in: path, required: true, schema: { type: string } }
      - { name: entryId, in: path, required: true, schema: { type: string } }
      - { $ref: '#/components/parameters/Range' }
      - { $ref: '#/components/parameters/IfRange' }
      - { $ref: '#/components/parameters/IfNoneMatch' }
    get:
      operationId: getVirtualEntryContent
      tags: [Uploads and downloads]
      security: [{ bearerAuth: [] }, {}]
      responses:
        '200': { $ref: '#/components/responses/Content' }
        '206': { $ref: '#/components/responses/PartialContent' }
        '304': { description: Representation unchanged. }
        '416': { $ref: '#/components/responses/UnsatisfiableRange' }
    head:
      operationId: headVirtualEntryContent
      tags: [Uploads and downloads]
      security: [{ bearerAuth: [] }, {}]
      responses:
        '200': { $ref: '#/components/responses/ContentHeaders' }
        '206': { $ref: '#/components/responses/PartialContentHeaders' }
        '304': { description: Representation unchanged. }
        '416': { $ref: '#/components/responses/UnsatisfiableRange' }
  /api/v1/folders:
    get:
      operationId: browseFolders
      tags: [Folders and sources]
      parameters:
        - {"name": "path", "in": "query", "schema": {"type": "string"}, "description": "Absolute server folder path. Omit to list starting places."}
      responses:
        '200':
          description: Directories inside one folder on the server.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FolderListing'
  /api/v1/webdav-credentials:
    get:
      operationId: listWebdavCredentials
      tags: [Access and credentials]
      description: Account session only. Lists this account's credential metadata, never verifiers.
      responses:
        '200':
          description: Credentials including revoked entries.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WebDavCredentialList'
    post:
      operationId: createWebdavCredential
      tags: [Access and credentials]
      description: Account session only. Requires enabled WebDAV. Generates a read-only Digest app password shown once, without idempotency caching.
      requestBody:
        required: true
        content:
          application/json:
            example: {"name": "Media reader", "expiresInSeconds": 86400}
            schema:
              $ref: '#/components/schemas/WebDavCredentialDraft'
      responses:
        '201':
          description: Credential issued. Cache-Control is no-store.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WebDavCredentialCreated'
  /api/v1/webdav-credentials/{id}:
    parameters:
      - name: id
        in: path
        required: true
        schema: { type: string }
    delete:
      operationId: revokeWebdavCredential
      tags: [Access and credentials]
      description: Account session only. Revokes a credential belonging to this account.
      responses:
        '204':
          description: Credential revoked.
  /api/v1/storage-locations:
    get:
      operationId: listStorageLocations
      tags: [Folders and sources]
      description: Owner only. Includes server paths and current online status.
      responses:
        '200':
          description: Registered locations and the target for new bytes. Null means Primary.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StorageLocationList'
    post:
      operationId: createStorageLocation
      tags: [Folders and sources]
      description: Owner only. Initializes blob storage in an existing server folder.
      requestBody:
        required: true
        content:
          application/json:
            example: {"path": "/srv/ecs-storage", "label": "Secondary drive"}
            schema:
              $ref: '#/components/schemas/StorageLocationDraft'
      responses:
        '201':
          description: Location registered. Existing bytes are not moved.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StorageLocation'
  /api/v1/storage-locations/write-target:
    put:
      operationId: setStorageWriteTarget
      tags: [Folders and sources]
      description: Owner only. Selects where new bytes are written; null selects Primary.
      requestBody:
        required: true
        content:
          application/json:
            example: {"id": null}
            schema:
              $ref: '#/components/schemas/StorageWriteTarget'
      responses:
        '200':
          description: Write target saved. An offline target refuses new uploads until online.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StorageWriteTarget'
  /api/v1/storage-locations/{locationId}:
    parameters:
      - { name: locationId, in: path, required: true, schema: { type: string } }
    delete:
      operationId: deleteStorageLocation
      tags: [Folders and sources]
      description: Owner only. Forgets an unused location without deleting files. The active target or a location holding catalog blobs returns 409.
      responses:
        '204':
          description: Location forgotten.
  /api/v1/roots:
    get:
      operationId: listContentRoots
      tags: [Folders and sources]
      responses:
        '200':
          description: Saved content roots.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContentRootList'
    post:
      operationId: createContentRoot
      tags: [Folders and sources]
      requestBody:
        required: true
        content:
          application/json:
            example: {"path": "/srv/roms", "label": "Game files", "libraryId": "library-demo", "watch": false, "organize": false}
            schema:
              $ref: '#/components/schemas/ContentRootDraft'
      responses:
        '201':
          description: Content root saved.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContentRoot'
  /api/v1/roots/{rootId}:
    parameters:
      - { name: rootId, in: path, required: true, schema: { type: string } }
    delete:
      operationId: deleteContentRoot
      tags: [Folders and sources]
      responses:
        '204':
          description: Content root forgotten.
  /api/v1/roots/{rootId}/scan:
    parameters:
      - { name: rootId, in: path, required: true, schema: { type: string } }
    post:
      operationId: scanContentRoot
      tags: [Folders and sources]
      responses:
        '200':
          description: Folder read in place. Bytes stay where they are.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContentRootScan'
  /api/v1/sources:
    get:
      operationId: listSourceFiles
      tags: [Folders and sources]
      security: [{ bearerAuth: [] }, {}]
      description: Without a filter this checks every file in every folder. A player looking for one BIOS file should pass kind and name.
      parameters:
        - { name: kind, in: query, schema: { type: string, enum: [rom, battery_save, save_state, screenshot, artwork, bios, system_file] }, description: Only files of this kind. }
        - { name: name, in: query, schema: { type: string, maxLength: 255 }, description: "Only files with exactly this file name, compared without case." }
      responses:
        '200':
          description: Files found in content roots. Filesystem paths are not included.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SourceFileList'
  /api/v1/matching/plugins:
    get:
      operationId: matchingPlugins
      tags: [Matching and jobs]
      responses:
        '200':
          description: Owner-only provider and manager registry. Installed modules are not executed by discovery.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/MatchingPluginList' }
  /api/v1/roots/{rootId}/disc-conversion:
    parameters:
      - { name: rootId, in: path, required: true, schema: { type: string } }
    get:
      operationId: folderDiscConversion
      tags: [Folders and sources]
      responses:
        '200':
          description: Owner-only automatic CHD conversion settings for one folder.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/DiscConversionPolicy' }
    put:
      operationId: setFolderDiscConversion
      tags: [Folders and sources]
      requestBody:
        required: true
        content:
          application/json:
            example: {"enabled":true,"keepOriginals":false}
            schema: { $ref: '#/components/schemas/DiscConversionPolicy' }
      responses:
        '200':
          description: Automatic conversion settings saved. Conversion runs after a successful scan.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/DiscConversionPolicy' }
  /api/v1/sources/{sourceId}/disc-conversion:
    parameters:
      - { name: sourceId, in: path, required: true, schema: { type: string } }
    post:
      operationId: convertSourceDisc
      tags: [Folders and sources]
      requestBody:
        required: true
        content:
          application/json:
            example: {"keepOriginals":false}
            schema: { $ref: '#/components/schemas/DiscConversionDraft' }
      responses:
        '200':
          description: Verified CHD published using the existing source ID.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/DiscConversionResult' }
  /api/v1/roots/{rootId}/watching-policy:
    parameters:
      - { name: rootId, in: path, required: true, schema: { type: string } }
    get:
      operationId: folderWatchPolicy
      tags: [Folders and sources]
      responses:
        '200':
          description: Owner-only watching preference and live status for a registered server folder. Disabled by default. Internal filesystem paths are not exposed.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/FolderWatchPolicy' }
    put:
      operationId: setFolderWatchPolicy
      tags: [Folders and sources]
      requestBody:
        required: true
        content:
          application/json:
            example: {"enabled": true}
            schema: { $ref: '#/components/schemas/FolderWatchPolicyDraft' }
      responses:
        '200':
          description: Persist explicit owner consent and start or stop watching this server folder. Watching refreshes the index and fills missing metadata and artwork. An enabled organization policy may move games after matching. Enable both registered folders to track moves between them. Periodic recovery scans handle missed events and unavailable native watches. Preference survives restart; runtime status does not.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/FolderWatchPolicy' }
  /api/v1/roots/{rootId}/organization-policy:
    parameters:
      - { name: rootId, in: path, required: true, schema: { type: string } }
    get:
      operationId: sourceOrganizationPolicy
      tags: [Folders and sources]
      responses:
        '200':
          description: Owner-only automatic organization policy for a registered source folder. Disabled by default. Internal filesystem paths are not exposed.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/SourceOrganizationPolicy' }
    put:
      operationId: setSourceOrganizationPolicy
      tags: [Folders and sources]
      requestBody:
        required: true
        content:
          application/json:
            example: {"enabled": true, "planId": "REPLACE_WITH_PREVIEW_ID"}
            schema: { $ref: '#/components/schemas/SourceOrganizationPolicyDraft' }
      responses:
        '200':
          description: Owner explicitly enables organization for future successful ROM, metadata and artwork match saves using a current folder or source preview. Enabling does not process existing files. Disable at any time with enabled false. Policy fails closed if either folder changes library or path. Copy retains one verified owned copy and synchronizes later saved snapshots; move retains source identity. Unsupported files, stale sources and collisions leave saved matches intact and return an automatic organization warning.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/SourceOrganizationPolicy' }
        '409':
          description: Preview expired or changed. Create a new preview before enabling.
  /api/v1/roots/{rootId}/organization-policy/preview:
    parameters:
      - { name: rootId, in: path, required: true, schema: { type: string } }
    post:
      operationId: previewFolderOrganization
      tags: [Folders and sources]
      requestBody:
        required: true
        content:
          application/json:
            example: {"mode": "copy", "targetRootId": "root-demo"}
            schema: { $ref: '#/components/schemas/SourceOrganizationDraft' }
      responses:
        '200':
          description: Owner-only preview of a future folder policy, with up to five example paths based on indexed ROMs, archives and complete disc groups. The owner-bound plan expires after ten minutes. Files are checked individually when a match triggers organization.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/FolderOrganizationPreview' }
        '409':
          description: The selected folders or action do not support automatic organization.
  /api/v1/sources/{sourceId}/organization/preview:
    parameters:
      - { name: sourceId, in: path, required: true, schema: { type: string } }
    post:
      operationId: previewSourceOrganization
      tags: [Folders and sources]
      requestBody:
        required: true
        content:
          application/json:
            example: {"mode": "copy", "targetRootId": "root-demo"}
            schema: { $ref: '#/components/schemas/SourceOrganizationDraft' }
      responses:
        '200':
          description: Owner-only, read-only preview for a local ROM, intact archive or complete disc game set. Destination is generated from system, saved title and original filename, within a registered root in the same library (including unassigned roots). Every member and companion is included in the preview. Descriptor references, relative layout and archive contents are preserved. Copy supports different volumes; move requires the same volume. Preview is bound to owner, source, roots, saved matches and file validators, expires after ten minutes and may be discarded when the bounded preview cache fills. Preview itself does not organize files. A separate explicit root policy can enable automatic organization on future saved matches.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/SourceOrganizationPreview' }
        '409':
          description: Unsupported source, changed source, destination collision or cross-volume move. Preview again after resolving the conflict.
  /api/v1/sources/{sourceId}/organization/apply:
    parameters:
      - { name: sourceId, in: path, required: true, schema: { type: string } }
    post:
      operationId: applySourceOrganization
      tags: [Folders and sources]
      requestBody:
        required: true
        content:
          application/json:
            example: {"planId": "REPLACE_WITH_PREVIEW_ID"}
            schema: { $ref: '#/components/schemas/SourceOrganizationApply' }
      responses:
        '200':
          description: Applies exactly the owner's single-use preview with exclusive no-overwrite placement and revalidation. Move retains the source ID and saved match snapshots. Copy creates a source with cloned selections and leaves the original intact.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/SourceOrganizationResult' }
        '409':
          description: Preview expired, consumed, or changed. No new paths are accepted. Preview again.
  /api/v1/sources/{sourceId}/matches:
    parameters:
      - { name: sourceId, in: path, required: true, schema: { type: string } }
    post:
      operationId: findSourceMatches
      tags: [Matching and jobs]
      requestBody:
        required: true
        content:
          application/json:
            example: {"online": false, "checksum": true, "autoSave": false}
            schema: { $ref: '#/components/schemas/MatchingOptions' }
      responses:
        '200':
          description: Owner-requested suggestions from local and online providers. With autoSave enabled, unique best-confidence choices are saved and enabled organization rules may run. Suggestions expire after fifteen minutes.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/SourceMatches' }
  /api/v1/sources/{sourceId}/matches/selections:
    parameters:
      - { name: sourceId, in: path, required: true, schema: { type: string } }
    get:
      operationId: sourceMatchSelections
      tags: [Matching and jobs]
      parameters:
        - { name: includeArtworkRoles, in: query, schema: { type: boolean, default: false }, description: Include all artwork roles; older clients should keep the default front-only result. }
      responses:
        '200':
          description: Saved matches visible to the source reader. Selected metadata becomes game metadata; binary companions retain their source-kind access restrictions.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/SourceMatchSelections' }
    put:
      operationId: saveSourceMatch
      tags: [Matching and jobs]
      parameters:
        - { name: includeArtworkRoles, in: query, schema: { type: boolean, default: false }, description: Include all artwork roles in the response; older clients should keep the default front-only result. }
      requestBody:
        required: true
        content:
          application/json:
            example: {"requestId": "REPLACE_WITH_MATCH_REQUEST_ID", "candidateId": "REPLACE_WITH_CANDIDATE_ID", "expectedRevision": 0}
            schema: { $ref: '#/components/schemas/SourceMatchSelectionDraft' }
      responses:
        '200':
          description: Owner-selected match and optional immutable content snapshot persisted. A repeated candidate ID is idempotent.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/SourceMatchSelections' }
        '409':
          description: Revision conflict or source/companion changed since lookup.
  /api/v1/sources/{sourceId}/matches/lookup-hints:
    parameters:
      - { name: sourceId, in: path, required: true, schema: { type: string } }
    put:
      operationId: saveSourceLookupHints
      tags: [Matching and jobs]
      parameters:
        - { name: If-Match, in: header, required: true, schema: { type: string }, example: '"rev-0"' }
        - { name: includeArtworkRoles, in: query, schema: { type: boolean, default: false } }
      requestBody:
        required: true
        content:
          application/json:
            example: { title: "Example Game (USA)", systemId: "com.provenance.nes" }
            schema: { $ref: '#/components/schemas/SourceLookupHints' }
      responses:
        '200':
          description: Owner lookup hints saved. Changed hints make the indexed game eligible for automatic lookup when enabled.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/SourceMatchSelections' }
        '409':
          description: The matching revision changed. Reload saved matches before editing.
  /api/v1/sources/{sourceId}/details:
    parameters:
      - { name: sourceId, in: path, required: true, schema: { type: string } }
    put:
      operationId: saveSourceDetails
      tags: [Matching and jobs]
      description: |
        Saves a game's title and details as entered by a person (provider `manual`). The caller needs a user token with the `write` scope and write permission on the game's library (owners and editors); a game outside any library is owner-only. A game the caller cannot read is 404, one it can read but not write is 403. Access is decided before the body is read.

        `title` is always replaced. When `details` is omitted, the details already saved for the game are kept, whichever provider wrote them. When `details` is present, each key that is present replaces that field, an empty string clears it, and absent keys keep their current value. Automatic matching never replaces a hand-entered record.
      parameters:
        - { name: If-Match, in: header, required: true, schema: { type: string }, example: '"rev-0"', description: Saved matching revision (`revision` from the selections response) as a quoted rev-N ETag. }
        - { name: includeArtworkRoles, in: query, schema: { type: boolean, default: false } }
      requestBody:
        required: true
        content:
          application/json:
            example: { title: "Example Game", details: { publisher: "Example Co", year: "1991" } }
            schema: { $ref: '#/components/schemas/SourceDetailsDraft' }
      responses:
        '200':
          description: Saved. The response carries the new `revision`.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/SourceMatchSelections' }
        '400':
          description: Invalid title or details.
        '403':
          description: The caller can read the game but may not change it.
        '404':
          description: The game does not exist or is not visible to the caller.
        '409':
          description: The matching revision changed. Reload the selections and retry.
        '428':
          description: If-Match is missing.
  /api/v1/sources/{sourceId}/details/cover:
    parameters:
      - { name: sourceId, in: path, required: true, schema: { type: string } }
    put:
      operationId: saveSourceCover
      tags: [Matching and jobs]
      description: |
        Saves one picture for a game as entered by a person (provider `manual`): its front cover by default, or the kind named by `artworkRole`. Same authority as `saveSourceDetails`, decided before the image is read. It replaces the picture saved for that kind and leaves the others alone. The image is served from the game's existing artwork path with the same `artworkRole`. At most 2 MiB, or 8 MiB for `manual`; the declared type and the file's own signature must both be PNG, JPEG or WebP.
      parameters:
        - { name: If-Match, in: header, required: true, schema: { type: string }, example: '"rev-0"' }
        - { name: includeArtworkRoles, in: query, schema: { type: boolean, default: false } }
        - { name: artworkRole, in: query, schema: { type: string, enum: [front, back, disc, manual, title, screenshot, banner, other], default: front }, description: Which picture of the game this is. }
      requestBody:
        required: true
        content:
          image/png: { schema: { type: string, format: binary } }
          image/jpeg: { schema: { type: string, format: binary } }
          image/webp: { schema: { type: string, format: binary } }
      responses:
        '200':
          description: Saved. The response carries the new `revision`.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/SourceMatchSelections' }
        '403':
          description: The caller can read the game but may not change it.
        '404':
          description: The game does not exist or is not visible to the caller.
        '409':
          description: The matching revision changed. Reload the selections and retry.
        '400':
          description: Unknown `artworkRole`.
        '413':
          description: The image is larger than the limit for its kind (`matching-file-too-large`).
        '415':
          description: Not a PNG, JPEG or WebP image, or the declared type does not match the bytes.
        '428':
          description: If-Match is missing.
  /api/v1/sources/{sourceId}/matches/selections/{kind}:
    parameters:
      - { name: sourceId, in: path, required: true, schema: { type: string } }
      - { name: kind, in: path, required: true, schema: { type: string } }
    delete:
      operationId: removeSourceMatch
      tags: [Matching and jobs]
      parameters:
        - in: header
          name: If-Match
          required: true
          schema: { type: string }
          description: Current saved matching revision as a quoted rev-N ETag.
        - { name: artworkRole, in: query, schema: { type: string, enum: [front, back, disc, manual, title, screenshot, banner, other] }, description: Artwork role to remove; defaults to front. }
        - { name: includeArtworkRoles, in: query, schema: { type: boolean, default: false }, description: Include all artwork roles in the response; older clients should keep the default front-only result. }
      responses:
        '200':
          description: Owner removed a selection; original files remain unchanged.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/SourceMatchSelections' }
  /api/v1/sources/{sourceId}/matches/selections/{kind}/content:
    parameters:
      - { name: sourceId, in: path, required: true, schema: { type: string } }
      - { name: kind, in: path, required: true, schema: { type: string } }
    get:
      operationId: selectedMatchContent
      tags: [Matching and jobs]
      parameters:
        - { name: artworkRole, in: query, schema: { type: string, enum: [front, back, disc, manual, title, screenshot, banner, other] }, description: Artwork role content to retrieve; defaults to front. }
        - { name: width, in: query, schema: { type: integer, enum: [240, 480, 960] }, description: 'For a picture, a smaller copy no wider than this many pixels, for grids and lists. It is a JPEG, or a WebP when the picture has transparency, and is never enlarged: a picture already this narrow, or one the server cannot redraw, is returned as saved. Ignored for patches, cheats and PDF manuals. `v` is still the SHA-256 of the saved file.' }
        - { $ref: '#/components/parameters/ContentVersion' }
      responses:
        '200':
          description: Authorized immutable artwork, patch, or disabled RetroArch cheat file snapshot. With `width`, a smaller copy of a picture.
          content:
            application/octet-stream:
              schema: { type: string, format: binary }
            image/jpeg:
              schema: { type: string, format: binary }
            image/webp:
              schema: { type: string, format: binary }
  /api/v1/sources/{sourceId}/matches/{requestId}/artwork/{candidateId}:
    parameters:
      - { name: sourceId, in: path, required: true, schema: { type: string } }
      - { name: requestId, in: path, required: true, schema: { type: string } }
      - { name: candidateId, in: path, required: true, schema: { type: string } }
    get:
      operationId: matchingArtwork
      tags: [Matching and jobs]
      responses:
        '200':
          description: Owner-authorized raster preview of a candidate in a live matching request. No remote credentials or redirects.
          content:
            image/png:
              schema: { type: string, format: binary }
            image/jpeg:
              schema: { type: string, format: binary }
            image/webp:
              schema: { type: string, format: binary }
  /api/v1/sources/{sourceId}/companions:
    parameters:
      - { name: sourceId, in: path, required: true, schema: { type: string } }
    get:
      operationId: sourceCompanions
      tags: [Folders and sources]
      security: [{ bearerAuth: [] }, {}]
      responses:
        '200':
          description: Authorized optional companions with immutable content identity. Scanned games currently support saved patches.
          content:
            application/json:
              example:
                supportedKinds: [patch]
                items:
                  - id: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                    kind: patch
                    required: false
                    filename: translation.bps
                    sizeBytes: 144
                    sha256: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                    format: bps
                    base: { crc32: '12345678', sizeBytes: 2097152 }
                    contentPath: /api/v1/sources/source-demo/companions/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/content
              schema: { $ref: '#/components/schemas/CompanionList' }
        '404': { description: Source unavailable to the caller. }
  /api/v1/sources/{sourceId}/companions/{id}/content:
    parameters:
      - { name: sourceId, in: path, required: true, schema: { type: string } }
      - { name: id, in: path, required: true, schema: { type: string, pattern: '^[0-9a-f]{64}$' } }
    get:
      operationId: sourceCompanionContent
      tags: [Folders and sources]
      security: [{ bearerAuth: [] }, {}]
      parameters:
        - { name: If-None-Match, in: header, schema: { type: string } }
      responses:
        '200':
          description: Bytes for the current authorized companion with the requested digest.
          headers:
            ETag: { schema: { type: string } }
          content:
            application/octet-stream:
              schema: { type: string, format: binary }
        '304': { description: Authorized bytes match the supplied validator. }
        '404': { description: 'Source or companion unavailable, or the selection has changed.' }
  /api/v1/sources/{sourceId}/group:
    parameters:
      - { name: sourceId, in: path, required: true, schema: { type: string } }
    get:
      operationId: sourceGroup
      tags: [Folders and sources]
      security: [{ bearerAuth: [] }, {}]
      description: Scanned disc-set members with portable relative paths. NAOMI and NAOMI 2 ZIP primaries include CHDs in the matching ZIP-stem directory. Check error and every member availability before downloading the full set. Cartridge-only ZIPs can remain standalone. Clients with authoritative GD-ROM metadata must verify the expected companion name.
      responses:
        '200':
          description: Cached members of one disc group, authorized individually.
          content:
            application/json:
              example:
                sourceId: source-cart
                error: null
                files:
                  - { id: source-cart, name: cart.zip, relativePath: cart.zip, size: 8, availability: local }
                  - { id: source-gdrom, name: gdrom.chd, relativePath: cart/gdrom.chd, size: 16, availability: local }
              schema: { $ref: '#/components/schemas/SourceGroup' }
  /api/v1/sources/{sourceId}/bundle:
    parameters:
      - { name: sourceId, in: path, required: true, schema: { type: string } }
    get:
      operationId: sourceBundle
      tags: [Folders and sources]
      security: [{ bearerAuth: [] }, {}]
      responses:
        '200':
          description: Streaming ZIP64 archive of a complete, current disc group. Original relative layout is preserved. No ranges.
          content:
            application/zip:
              schema: { type: string, format: binary }
        '409':
          description: Incomplete or changed disc group; rescan before retrying.
  /api/v1/sources/{sourceId}/content:
    parameters:
      - { name: sourceId, in: path, required: true, schema: { type: string } }
      - { $ref: '#/components/parameters/Range' }
      - { $ref: '#/components/parameters/IfRange' }
      - { $ref: '#/components/parameters/IfNoneMatch' }
    get:
      operationId: readSourceContent
      tags: [Folders and sources]
      description: Reads original bytes from a local source without importing it.
      security: [{ bearerAuth: [] }, {}]
      responses:
        '200': { $ref: '#/components/responses/Content' }
        '206': { $ref: '#/components/responses/PartialContent' }
        '304': { description: Representation unchanged. }
        '409': { description: Source file is an evicted placeholder. }
        '416': { $ref: '#/components/responses/UnsatisfiableRange' }
        '503': { description: Source storage is offline. }
    head:
      operationId: statSourceContent
      tags: [Folders and sources]
      security: [{ bearerAuth: [] }, {}]
      responses:
        '200': { $ref: '#/components/responses/ContentHeaders' }
        '206': { $ref: '#/components/responses/PartialContentHeaders' }
        '304': { description: Representation unchanged. }
        '409': { description: Source file is an evicted placeholder. }
        '416': { $ref: '#/components/responses/UnsatisfiableRange' }
        '503': { description: Source storage is offline. }
  /api/v1/changes:
    get:
      operationId: listChanges
      tags: [Libraries and items]
      security: [{ bearerAuth: [] }, {}]
      parameters:
        - { name: cursor, in: query, schema: { type: string }, description: "Exclusive decimal cursor. Use 0 to replay history or now to get an empty page at the current cursor before loading a fresh snapshot." }
        - { name: limit, in: query, schema: { type: integer, minimum: 1, maximum: 100 } }
        - { name: excludeOwnDevice, in: query, schema: { type: string, enum: ['1'] }, description: Omit changes from the authenticated device. }
      responses:
        '200':
          description: Change feed.
          content:
            application/json:
              example: {"changes": [], "nextCursor": "42"}
              schema: { $ref: '#/components/schemas/ChangeList' }
  /api/v1/guest-grants:
    get:
      operationId: listGuestGrants
      tags: [Access and credentials]
      parameters:
        - {"name": "limit", "in": "query", "schema": {"type": "integer"}}
      responses:
        '200':
          description: Guest grants, including revoked ones. The token and its hash are omitted.
          content:
            application/json:
              schema: {"$ref": "#/components/schemas/GuestGrantList"}
    post:
      operationId: createGuestGrant
      tags: [Access and credentials]
      parameters:
        - {"$ref": "#/components/parameters/IdempotencyKey"}
      requestBody:
        required: true
        content:
          application/json:
            example: {"libraryId": "library-demo", "capabilities": ["read"], "expiresInSeconds": 3600}
            schema: {"$ref": "#/components/schemas/GuestGrantDraft"}
      responses:
        '201':
          description: Guest grant created. The token is returned once.
          content:
            application/json:
              schema: {"$ref": "#/components/schemas/GuestGrantCreated"}
  /api/v1/guest-grants/{grantId}:
    parameters:
      - { name: grantId, in: path, required: true, schema: { type: string } }
    delete:
      operationId: revokeGuestGrant
      tags: [Access and credentials]
      responses:
        '204':
          description: Guest grant revoked.
  /api/v1/device-pairing:
    post:
      operationId: startDevicePairing
      tags: [Authentication]
      security: []
      description: Starts a five-minute pairing request when the web UI is enabled. Keep the returned secret on the requesting device. The PIN can be shown to the owner or placed in the fragment of the web UI URL.
      requestBody:
        required: true
        content:
          application/json:
            example: {"name": "Living room Apple TV"}
            schema: { $ref: '#/components/schemas/DevicePairingDraft' }
      responses:
        '201':
          description: Pending pairing request.
          content:
            application/json:
              example: {"id": "pairing-demo", "pin": "123456", "secret": "REPLACE_WITH_RETURNED_PAIRING_SECRET", "expiresInSeconds": 300}
              schema: { $ref: '#/components/schemas/DevicePairingChallenge' }
        '404': { description: Pairing is unavailable. }
        '429': { description: Too many pending or recent requests. }
  /api/v1/device-pairing/inspect:
    post:
      operationId: inspectDevicePairing
      tags: [Authentication]
      description: Owner sign-in required. Resolves a PIN to the device name for explicit approval.
      requestBody:
        required: true
        content:
          application/json:
            example: {"pin": "123456"}
            schema: { $ref: '#/components/schemas/DevicePairingPIN' }
      responses:
        '200':
          description: Device awaiting approval.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/DevicePairingCandidate' }
        '404': { description: Pairing expired or unavailable. }
  /api/v1/device-pairing/approve:
    post:
      operationId: approveDevicePairing
      tags: [Authentication]
      description: Owner sign-in required. Approves only the request inspected under this PIN.
      requestBody:
        required: true
        content:
          application/json:
            example: {"id": "REPLACE_WITH_PAIRING_ID", "pin": "123456"}
            schema: { $ref: '#/components/schemas/DevicePairingApproval' }
      responses:
        '200':
          description: Device approved.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/DevicePairingApproved' }
        '404': { description: Pairing expired or unavailable. }
  /api/v1/device-pairing/redeem:
    post:
      operationId: redeemDevicePairing
      tags: [Authentication]
      security: []
      description: Poll every three seconds with the requesting device's private secret. A successful redemption returns a read-only device token once.
      requestBody:
        required: true
        content:
          application/json:
            example: {"id": "REPLACE_WITH_PAIRING_ID", "secret": "REPLACE_WITH_PAIRING_SECRET"}
            schema: { $ref: '#/components/schemas/DevicePairingRedemption' }
      responses:
        '200':
          description: Read-only token for the approved device.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/DeviceTokenCreated' }
        '202': { description: Awaiting owner approval. }
        '404': { description: 'Pairing expired, already redeemed, or unavailable.' }
  /api/v1/device-pairing/invitations:
    post:
      operationId: createDevicePairingInvitation
      tags: [Authentication]
      description: Owner-only. Creates a one-use invitation valid for five minutes. Encode its ID and PIN with the server origin for the requesting device.
      responses:
        '201':
          description: A new read-only pairing invitation.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/DevicePairingInvitation' }
        '429': { description: Too many active or recent invitations. }
  /api/v1/device-pairing/invitations/{id}:
    delete:
      operationId: withdrawDevicePairingInvitation
      tags: [Authentication]
      description: The owner who created the invitation may withdraw it before redemption.
      parameters:
        - {name: id, in: path, required: true, schema: {type: string}}
      responses:
        '204': { description: Invitation withdrawn. }
        '404': { description: 'Invitation expired, redeemed, or unavailable.' }
  /api/v1/device-pairing/invitations/redeem:
    post:
      operationId: redeemDevicePairingInvitation
      tags: [Authentication]
      security: []
      description: Exchanges an active invitation ID and its six-digit PIN for a revocable read-only device token issued once.
      requestBody:
        required: true
        content:
          application/json:
            example: {id: REPLACE_WITH_INVITATION_ID, pin: '123456', name: Living room handheld}
            schema: { $ref: '#/components/schemas/DevicePairingInvitationClaim' }
      responses:
        '200':
          description: Read-only token for this device.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/DeviceTokenCreated' }
        '404': { description: 'Invitation expired, redeemed, withdrawn, or code did not match.' }
        '429': { description: Too many attempts. }
  /api/v1/device-pairing/requests:
    get:
      operationId: listDevicePairingRequests
      tags: [Authentication]
      description: Lists pending and approved requests for the signed-in owner. Codes and device secrets are omitted.
      responses:
        '200':
          description: Active requests.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/DevicePairingRequestList' }
    post:
      operationId: requestDevicePairing
      tags: [Authentication]
      security: []
      description: Starts a five-minute request. Keep the returned secret on the requesting device.
      requestBody:
        required: true
        content:
          application/json:
            example: {name: Living room Apple TV}
            schema: { $ref: '#/components/schemas/DevicePairingDraft' }
      responses:
        '201':
          description: Request created.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/DevicePairingRequest' }
        '404': { description: Pairing is unavailable. }
        '429': { description: Too many pending or recent requests. }
  /api/v1/device-pairing/requests/{id}/approve:
    post:
      operationId: approveDevicePairingRequest
      tags: [Authentication]
      description: Owner sign-in required. Approves the request and reveals its six-digit PIN. The QR payload is ecs-pair followed by the request ID and PIN, separated by colons.
      parameters:
        - { name: id, in: path, required: true, schema: { type: string } }
      responses:
        '200':
          description: PIN to enter on the requesting device.
          content:
            application/json:
              example: {pin: '123456'}
              schema: { $ref: '#/components/schemas/DevicePairingPIN' }
        '404': { description: Request expired or unavailable. }
  /api/v1/device-pairing/requests/{id}:
    delete:
      operationId: dismissDevicePairingRequest
      tags: [Authentication]
      description: Owner sign-in required. Dismisses a pending or approved request.
      parameters:
        - { name: id, in: path, required: true, schema: { type: string } }
      responses:
        '204': { description: Request dismissed. }
        '404': { description: Request expired or unavailable. }
  /api/v1/device-pairing/requests/status:
    post:
      operationId: devicePairingRequestStatus
      tags: [Authentication]
      security: []
      description: Poll with the requesting device's secret to learn when the owner has approved.
      requestBody:
        required: true
        content:
          application/json:
            example: {id: REPLACE_WITH_PAIRING_ID, secret: REPLACE_WITH_PAIRING_SECRET}
            schema: { $ref: '#/components/schemas/DevicePairingRedemption' }
      responses:
        '200':
          description: Approval status.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/DevicePairingApproved' }
        '404': { description: Request expired or unavailable. }
  /api/v1/device-pairing/requests/cancel:
    post:
      operationId: cancelDevicePairingRequest
      tags: [Authentication]
      security: []
      description: Cancel a request using the requesting device's private secret.
      requestBody:
        required: true
        content:
          application/json:
            example: {id: REPLACE_WITH_PAIRING_ID, secret: REPLACE_WITH_PAIRING_SECRET}
            schema: { $ref: '#/components/schemas/DevicePairingRedemption' }
      responses:
        '204': { description: Request canceled. }
        '404': { description: Request expired or unavailable. }
  /api/v1/device-pairing/requests/complete:
    post:
      operationId: completeDevicePairingRequest
      tags: [Authentication]
      security: []
      description: Exchanges the private secret and the owner-approved PIN for a read-only device token issued once. Five wrong PIN attempts invalidate the request.
      requestBody:
        required: true
        content:
          application/json:
            example: {id: REPLACE_WITH_PAIRING_ID, secret: REPLACE_WITH_PAIRING_SECRET, pin: '123456'}
            schema: { $ref: '#/components/schemas/DevicePairingCompletion' }
      responses:
        '200':
          description: Read-only token for the approved device.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/DeviceTokenCreated' }
        '202': { description: Awaiting owner approval. }
        '400': { description: The PIN did not match or the request body is invalid. }
        '404': { description: 'Request expired, already redeemed, or unavailable.' }
  /api/v1/device-tokens:
    get:
      operationId: listDeviceTokens
      tags: [Access and credentials]
      responses:
        '200':
          description: Acting user's device token metadata, never hashes or token secrets.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/DeviceTokenList' }
    post:
      operationId: createDeviceToken
      tags: [Access and credentials]
      parameters:
        - {"$ref": "#/components/parameters/IdempotencyKey"}
      requestBody:
        required: true
        content:
          application/json:
            example: {"name": "Handheld client", "scopes": ["read"], "expiresInSeconds": 86400}
            schema: {"$ref": "#/components/schemas/DeviceTokenDraft"}
      responses:
        '201':
          description: Device token created.
          content:
            application/json:
              schema: {"$ref": "#/components/schemas/DeviceTokenCreated"}
  /api/v1/device-tokens/{tokenId}:
    parameters:
      - { name: tokenId, in: path, required: true, schema: { type: string } }
    delete:
      operationId: revokeDeviceToken
      tags: [Access and credentials]
      responses:
        '204':
          description: Device token revoked.
  /api/v1/audit:
    get:
      operationId: listAudit
      tags: [Access and credentials]
      parameters:
        - {"name": "limit", "in": "query", "schema": {"type": "integer"}}
      responses:
        '200':
          description: Audit events.
          content:
            application/json:
              schema: {"$ref": "#/components/schemas/AuditList"}
  /api/v1/library-jobs:
    get:
      operationId: listLibraryJobs
      tags: [Matching and jobs]
      description: Owner-only shared jobs, newest identifier first. Bounded keyset pages.
      parameters:
        - {name: limit, in: query, schema: {type: integer, minimum: 1, maximum: 99}}
        - {name: cursor, in: query, schema: {type: string}}
      responses:
        '200':
          description: Shared jobs.
          content:
            application/json:
              schema: {$ref: '#/components/schemas/LibraryJobList'}
    post:
      operationId: createLibraryJob
      tags: [Matching and jobs]
      description: Owner-only durable scan or matching job. Reuses covering active work with identical options. Partially overlapping work returns 409. Survives request disconnects. No scope selects all registered roots.
      requestBody:
        required: true
        content:
          application/json:
            example: {"kind": "match", "libraryId": "library-demo", "options": {"online": false, "checksum": true}}
            schema: {$ref: '#/components/schemas/LibraryJobDraft'}
      responses:
        '200':
          description: Existing covering job.
          content:
            application/json:
              schema: {$ref: '#/components/schemas/LibraryJobResponse'}
        '202':
          description: Shared job queued.
          content:
            application/json:
              schema: {$ref: '#/components/schemas/LibraryJobResponse'}
        '409': {description: Overlapping shared work already exists.}
  /api/v1/library-jobs/overview:
    get:
      operationId: getLibraryOverview
      tags: [Matching and jobs]
      description: Owner-only. Per saved folder, how many games have details and a cover, and what the automatic fill last decided. Counts come from the catalog; no file is read.
      responses:
        '200':
          description: Library status.
          content:
            application/json:
              schema: {$ref: '#/components/schemas/LibraryOverview'}
  /api/v1/library-jobs/{jobId}:
    parameters:
      - {name: jobId, in: path, required: true, schema: {type: string}}
    get:
      operationId: getLibraryJob
      tags: [Matching and jobs]
      description: Owner-only progress aggregates, shared by every session.
      responses:
        '200':
          description: Shared job.
          content:
            application/json:
              schema: {$ref: '#/components/schemas/LibraryJobResponse'}
  /api/v1/library-jobs/{jobId}/items:
    parameters:
      - {name: jobId, in: path, required: true, schema: {type: string}}
    get:
      operationId: listLibraryJobItems
      tags: [Matching and jobs]
      description: Owner-only bounded results for review; sourceId names a root for scan jobs.
      parameters:
        - {name: limit, in: query, schema: {type: integer, minimum: 1, maximum: 99}}
        - {name: cursor, in: query, schema: {type: string}}
        - {name: status, in: query, schema: {type: string, enum: [pending, saved, review, unmatched, failed, skipped, reviewed]}}
      responses:
        '200':
          description: Job results.
          content:
            application/json:
              schema: {$ref: '#/components/schemas/LibraryJobItemList'}
  /api/v1/library-jobs/{jobId}/cancel:
    parameters:
      - {name: jobId, in: path, required: true, schema: {type: string}}
    post:
      operationId: cancelLibraryJob
      tags: [Matching and jobs]
      description: Owner-only cancel from any owner session. Resume continues pending work; completed results are preserved. Interrupted work requires explicit resume.
      responses:
        '200':
          description: Shared job.
          content:
            application/json:
              schema: {$ref: '#/components/schemas/LibraryJobResponse'}
  /api/v1/library-jobs/{jobId}/resume:
    parameters:
      - {name: jobId, in: path, required: true, schema: {type: string}}
    post:
      operationId: resumeLibraryJob
      tags: [Matching and jobs]
      requestBody:
        content:
          application/json:
            example: {"retry": "failed"}
            schema:
              type: object
              properties:
                retry: {type: string, enum: [failed, unmatched]}
      description: Owner-only resume from any owner session. Resume continues pending work; completed results are preserved. Interrupted work requires explicit resume.
      responses:
        '200':
          description: Shared job.
          content:
            application/json:
              schema: {$ref: '#/components/schemas/LibraryJobResponse'}
  /api/v1/library-jobs/{jobId}/items/{sourceId}/reviewed:
    parameters:
      - {name: jobId, in: path, required: true, schema: {type: string}}
      - {name: sourceId, in: path, required: true, schema: {type: string}}
    post:
      operationId: reviewLibraryJobItem
      tags: [Matching and jobs]
      description: Owner-only acknowledgement of a completed result. Shared across sessions; does not select or save any candidate.
      responses:
        '200':
          description: Shared job progress after review.
          content:
            application/json:
              schema: {$ref: '#/components/schemas/LibraryJobResponse'}
  /api/v1/investigators:
    get:
      operationId: listInvestigators
      tags: [Investigators]
      description: "Owner only. List the active investigator grants for this owner."
      security: [{"bearerAuth":[]}]
      responses: {"200":{"description":"Operation succeeded.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/InvestigatorList"}}}},"400":{"description":"Invalid request."},"401":{"description":"Missing, invalid, expired or revoked credential."},"403":{"description":"The credential lacks this operation."},"404":{"description":"Resource is unavailable in this scope."}}
    post:
      operationId: createInvestigator
      tags: [Investigators]
      description: "Owner only. Return a library-scoped investigator token once."
      security: [{"bearerAuth":[]}]
      requestBody: {"required":true,"content":{"application/json":{"example": {"libraryIds": ["library-demo"], "operations": ["inspect", "cleanup"], "ttlSeconds": 3600}, "schema":{"$ref":"#/components/schemas/InvestigatorDraft"}}}}
      responses: {"201":{"description":"Operation succeeded.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/InvestigatorCreated"}}}},"400":{"description":"Invalid request."},"401":{"description":"Missing, invalid, expired or revoked credential."},"403":{"description":"The credential lacks this operation."},"404":{"description":"Resource is unavailable in this scope."},"409":{"description":"The scope, run state or source changed."},"429":{"description":"Operation is busy or quota was reached."}}
  /api/v1/investigators/{credentialId}:
    delete:
      operationId: revokeInvestigator
      tags: [Investigators]
      description: "Owner only. Revoke a credential and cancel its active investigations."
      security: [{"bearerAuth":[]}]
      parameters: [{"name":"credentialId","in":"path","required":true,"schema":{"type":"string","minLength":1,"maxLength":200}}]
      responses: {"204":{"description":"Operation succeeded."},"400":{"description":"Invalid request."},"401":{"description":"Missing, invalid, expired or revoked credential."},"403":{"description":"The credential lacks this operation."},"404":{"description":"Resource is unavailable in this scope."}}
  /api/v1/investigator/libraries:
    get:
      operationId: listInvestigatorLibraries
      tags: [Investigators]
      description: "Inspect scope. List live libraries allowed by the grant."
      security: [{"investigatorAuth":[]}]
      responses: {"200":{"description":"Operation succeeded.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/InvestigatorLibraryList"}}}},"400":{"description":"Invalid request."},"401":{"description":"Missing, invalid, expired or revoked credential."},"403":{"description":"The credential lacks this operation."},"404":{"description":"Resource is unavailable in this scope."}}
  /api/v1/investigator/libraries/{libraryId}/sources:
    get:
      operationId: listInvestigatorSources
      tags: [Investigators]
      description: "Inspect scope. Page through indexed game sources, omitting paths."
      security: [{"investigatorAuth":[]}]
      parameters: [{"name":"libraryId","in":"path","required":true,"schema":{"type":"string","minLength":1,"maxLength":200}},{"name":"cursor","in":"query","schema":{"type":"string","minLength":1,"maxLength":160}},{"name":"limit","in":"query","schema":{"type":"integer","minimum":1,"maximum":20}}]
      responses: {"200":{"description":"Operation succeeded.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/InvestigatorSourcePage"}}}},"400":{"description":"Invalid request."},"401":{"description":"Missing, invalid, expired or revoked credential."},"403":{"description":"The credential lacks this operation."},"404":{"description":"Resource is unavailable in this scope."}}
  /api/v1/investigator/diagnostics:
    get:
      operationId: getInvestigatorDiagnostics
      tags: [Investigators]
      description: "Diagnostics scope. Coarse host liveness and counts of active jobs scoped explicitly to granted libraries."
      security: [{"investigatorAuth":[]}]
      responses: {"200":{"description":"Operation succeeded.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/InvestigatorDiagnostics"}}}},"400":{"description":"Invalid request."},"401":{"description":"Missing, invalid, expired or revoked credential."},"403":{"description":"The credential lacks this operation."},"404":{"description":"Resource is unavailable in this scope."}}
  /api/v1/investigator/runs:
    post:
      operationId: startInvestigatorRun
      tags: [Investigators]
      description: "Cleanup scope. Start a bounded, local investigation of explicit sources, with no external workflow host or provider."
      security: [{"investigatorAuth":[]}]
      requestBody: {"required":true,"content":{"application/json":{"example": {"libraryId": "library-demo", "sourceIds": ["source-demo"]}, "schema":{"$ref":"#/components/schemas/InvestigatorRunDraft"}}}}
      responses: {"201":{"description":"Operation succeeded.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/InvestigatorRunResponse"}}}},"400":{"description":"Invalid request."},"401":{"description":"Missing, invalid, expired or revoked credential."},"403":{"description":"The credential lacks this operation."},"404":{"description":"Resource is unavailable in this scope."},"409":{"description":"The scope, run state or source changed."},"429":{"description":"Operation is busy or quota was reached."}}
  /api/v1/investigator/runs/{runId}:
    get:
      operationId: getInvestigatorRun
      tags: [Investigators]
      description: "Cleanup scope. Get the state of a run created with this credential."
      security: [{"investigatorAuth":[]}]
      parameters: [{"name":"runId","in":"path","required":true,"schema":{"type":"string","minLength":1,"maxLength":200}}]
      responses: {"200":{"description":"Operation succeeded.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/InvestigatorRunResponse"}}}},"400":{"description":"Invalid request."},"401":{"description":"Missing, invalid, expired or revoked credential."},"403":{"description":"The credential lacks this operation."},"404":{"description":"Resource is unavailable in this scope."}}
  /api/v1/investigator/runs/{runId}/cancel:
    post:
      operationId: cancelInvestigatorRun
      tags: [Investigators]
      description: "Cleanup scope. Stop the investigation and retain its suggestions for owner review."
      security: [{"investigatorAuth":[]}]
      parameters: [{"name":"runId","in":"path","required":true,"schema":{"type":"string","minLength":1,"maxLength":200}}]
      requestBody: {"required":true,"content":{"application/json":{"example": {}, "schema":{"type":"object","additionalProperties":false,"properties":{}}}}}
      responses: {"200":{"description":"Operation succeeded.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/InvestigatorRunResponse"}}}},"400":{"description":"Invalid request."},"401":{"description":"Missing, invalid, expired or revoked credential."},"403":{"description":"The credential lacks this operation."},"404":{"description":"Resource is unavailable in this scope."},"409":{"description":"The scope, run state or source changed."},"429":{"description":"Operation is busy or quota was reached."}}
  /api/v1/investigator/runs/{runId}/finish:
    post:
      operationId: finishInvestigatorRun
      tags: [Investigators]
      description: "Cleanup scope. Complete the investigation once all selected sources have been inspected."
      security: [{"investigatorAuth":[]}]
      parameters: [{"name":"runId","in":"path","required":true,"schema":{"type":"string","minLength":1,"maxLength":200}}]
      requestBody: {"required":true,"content":{"application/json":{"example": {}, "schema":{"type":"object","additionalProperties":false,"properties":{}}}}}
      responses: {"200":{"description":"Operation succeeded.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/InvestigatorRunResponse"}}}},"400":{"description":"Invalid request."},"401":{"description":"Missing, invalid, expired or revoked credential."},"403":{"description":"The credential lacks this operation."},"404":{"description":"Resource is unavailable in this scope."},"409":{"description":"The scope, run state or source changed."},"429":{"description":"Operation is busy or quota was reached."}}
  /api/v1/investigator/runs/{runId}/sources/{sourceId}/inspect:
    post:
      operationId: inspectInvestigatorSource
      tags: [Investigators]
      description: "Inspect scope. Collect local source facts and candidate evidence in an active investigation."
      security: [{"investigatorAuth":[]}]
      parameters: [{"name":"runId","in":"path","required":true,"schema":{"type":"string","minLength":1,"maxLength":200}},{"name":"sourceId","in":"path","required":true,"schema":{"type":"string","minLength":1,"maxLength":200}}]
      requestBody: {"required":true,"content":{"application/json":{"example": {}, "schema":{"type":"object","additionalProperties":false,"properties":{}}}}}
      responses: {"200":{"description":"Operation succeeded.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WorkflowCatalogResult"}}}},"400":{"description":"Invalid request."},"401":{"description":"Missing, invalid, expired or revoked credential."},"403":{"description":"The credential lacks this operation."},"404":{"description":"Resource is unavailable in this scope."},"409":{"description":"The scope, run state or source changed."},"429":{"description":"Operation is busy or quota was reached."}}
  /api/v1/investigator/runs/{runId}/findings:
    get:
      operationId: listInvestigatorFindings
      tags: [Investigators]
      description: "Inspect scope. Page through findings for sources still in scope."
      security: [{"investigatorAuth":[]}]
      parameters: [{"name":"runId","in":"path","required":true,"schema":{"type":"string","minLength":1,"maxLength":200}},{"name":"cursor","in":"query","schema":{"type":"string","minLength":1,"maxLength":160}},{"name":"limit","in":"query","schema":{"type":"integer","minimum":1,"maximum":20}}]
      responses: {"200":{"description":"Operation succeeded.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/InvestigatorFindingPage"}}}},"400":{"description":"Invalid request."},"401":{"description":"Missing, invalid, expired or revoked credential."},"403":{"description":"The credential lacks this operation."},"404":{"description":"Resource is unavailable in this scope."}}
  /api/v1/investigator/runs/{runId}/proposals:
    get:
      operationId: listInvestigatorProposals
      tags: [Investigators]
      description: "Inspect scope. Page through proposal identities and versions for sources still in scope."
      security: [{"investigatorAuth":[]}]
      parameters: [{"name":"runId","in":"path","required":true,"schema":{"type":"string","minLength":1,"maxLength":200}},{"name":"cursor","in":"query","schema":{"type":"string","minLength":1,"maxLength":160}},{"name":"limit","in":"query","schema":{"type":"integer","minimum":1,"maximum":20}}]
      responses: {"200":{"description":"Operation succeeded.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/InvestigatorProposalPage"}}}},"400":{"description":"Invalid request."},"401":{"description":"Missing, invalid, expired or revoked credential."},"403":{"description":"The credential lacks this operation."},"404":{"description":"Resource is unavailable in this scope."}}
  /api/v1/investigator/runs/{runId}/suggestions:
    post:
      operationId: submitInvestigatorSuggestion
      tags: [Investigators]
      description: "Suggest scope. Submit one observation backed by ECS evidence. Any resulting proposal requires owner review and apply."
      security: [{"investigatorAuth":[]}]
      parameters: [{"name":"runId","in":"path","required":true,"schema":{"type":"string","minLength":1,"maxLength":200}}]
      requestBody: {"required":true,"content":{"application/json":{"example": {"sourceId": "source-demo", "kind": "missing-front-artwork", "reason": "This source has no selected front cover.", "candidateIds": [], "evidenceIds": ["evidence-demo"]}, "schema":{"$ref":"#/components/schemas/InvestigatorSuggestion"}}}}
      responses: {"200":{"description":"Operation succeeded.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/InvestigatorSuggestionResponse"}}}},"400":{"description":"Invalid request."},"401":{"description":"Missing, invalid, expired or revoked credential."},"403":{"description":"The credential lacks this operation."},"404":{"description":"Resource is unavailable in this scope."},"409":{"description":"The scope, run state or source changed."},"429":{"description":"Operation is busy or quota was reached."}}
  /api/v1/workflow-hosts:
    get:
      operationId: "listWorkflowHosts"
      tags: [Workflow review]
      description: "Owner-only workflow management."
      responses: {"200": {"description": "Workflow operation result.","content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowHostList"}}}},"400": {"description": "Invalid workflow request."},"401": {"description": "Missing, expired or revoked credential."},"403": {"description": "This credential lacks authority for this operation."},"409": {"description": "Workflow scope, lease, sequence or state conflict."}}
    post:
      operationId: "createWorkflowHost"
      tags: [Workflow review]
      description: "Owner-only workflow management."
      requestBody: {"required": true,"content": {"application/json": {"example": {"name": "Local cleanup host"}, "schema": {"$ref": "#/components/schemas/WorkflowHostDraft"}}}}
      responses: {"201": {"description": "Workflow operation result.","content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowHostCreated"}}}},"400": {"description": "Invalid workflow request."},"401": {"description": "Missing, expired or revoked credential."},"403": {"description": "This credential lacks authority for this operation."},"409": {"description": "Workflow scope, lease, sequence or state conflict."}}
  /api/v1/workflow-hosts/{hostId}:
    delete:
      operationId: "revokeWorkflowHost"
      tags: [Workflow review]
      description: "Owner-only workflow management."
      parameters: [{"name": "hostId","in": "path","required": true,"schema": {"type": "string"}}]
      responses: {"204": {"description": "Workflow operation result."},"400": {"description": "Invalid workflow request."},"401": {"description": "Missing, expired or revoked credential."},"403": {"description": "This credential lacks authority for this operation."},"409": {"description": "Workflow scope, lease, sequence or state conflict."}}
  /api/v1/workflow-workers/enroll:
    post:
      operationId: "enrollWorkflowHost"
      tags: [Workflow workers]
      security: []
      description: "One-time enrollment using a ten-minute owner-issued secret; returns the worker bearer token once."
      requestBody: {"required": true,"content": {"application/json": {"example": {"enrollmentToken": "REPLACE_WITH_ENROLLMENT_TOKEN"}, "schema": {"$ref": "#/components/schemas/WorkflowEnrollmentDraft"}}}}
      responses: {"200": {"description": "Workflow operation result.","content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowHostEnrolled"}}}},"400": {"description": "Invalid workflow request."},"401": {"description": "Missing, expired or revoked credential."},"403": {"description": "This credential lacks authority for this operation."},"409": {"description": "Workflow scope, lease, sequence or state conflict."}}
  /api/v1/workflow-runs:
    get:
      operationId: "listWorkflowRuns"
      tags: [Workflow review]
      description: "Owner-only workflow management."
      parameters: [{"name": "cursor","in": "query","schema": {"type": "string"}},{"name": "limit","in": "query","schema": {"type": "integer","minimum": 1,"maximum": 100}},{"name":"libraryId","in":"query","schema":{"type":"string"}},{"name":"rootId","in":"query","schema":{"type":"string"}},{"name":"unassigned","in":"query","schema":{"type":"boolean"}}]
      responses: {"200": {"description": "Workflow operation result.","content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowRunList"}}}},"400": {"description": "Invalid workflow request."},"401": {"description": "Missing, expired or revoked credential."},"403": {"description": "This credential lacks authority for this operation."},"409": {"description": "Workflow scope, lease, sequence or state conflict."}}
    post:
      operationId: "createWorkflowRun"
      tags: [Workflow review]
      description: "Owner-only workflow management."
      requestBody: {"required": true,"content": {"application/json": {"example": {"workflowId": "org.ecs.library-cleanup", "workflowDigest": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", "hostId": "host-demo", "scope": {"libraryId": "library-demo"}, "options": {"online": false, "checksum": true, "shareImages": false}}, "schema": {"$ref": "#/components/schemas/WorkflowRunDraft"}}}}
      responses: {"201": {"description": "Workflow operation result.","content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowRunResponse"}}}},"400": {"description": "Invalid workflow request."},"401": {"description": "Missing, expired or revoked credential."},"403": {"description": "This credential lacks authority for this operation."},"409": {"description": "Workflow scope, lease, sequence or state conflict."},"503": {"description": "Enroll a workflow host before starting cleanup."}}
  /api/v1/workflow-runs/{runId}:
    get:
      operationId: "getWorkflowRun"
      tags: [Workflow review]
      description: "Owner-only workflow management."
      parameters: [{"name": "runId","in": "path","required": true,"schema": {"type": "string"}}]
      responses: {"200": {"description": "Workflow operation result.","content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowRunResponse"}}}},"400": {"description": "Invalid workflow request."},"401": {"description": "Missing, expired or revoked credential."},"403": {"description": "This credential lacks authority for this operation."},"409": {"description": "Workflow scope, lease, sequence or state conflict."}}
  /api/v1/workflow-runs/{runId}/findings/{findingId}/decision:
    post:
      operationId: "decideWorkflowFinding"
      tags: [Workflow review]
      description: "Owner-only workflow management."
      parameters: [{"name": "runId","in": "path","required": true,"schema": {"type": "string"}},{"name":"findingId","in":"path","required":true,"schema":{"type":"string"}}]
      requestBody: {required: true, content: {application/json: {"example": {"decision": "keep"}, schema: {$ref: "#/components/schemas/WorkflowDecision"}}}}
      responses: {"200": {"description": "Workflow operation result.","content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowFindingResponse"}}}},"400": {"description": "Invalid workflow request."},"401": {"description": "Missing, expired or revoked credential."},"403": {"description": "This credential lacks authority for this operation."},"409": {"description": "Workflow scope, lease, sequence or state conflict."}}
  /api/v1/workflow-runs/{runId}/cancel:
    post:
      operationId: "cancelWorkflowRun"
      tags: [Workflow review]
      description: "Owner-only workflow management."
      parameters: [{"name": "runId","in": "path","required": true,"schema": {"type": "string"}}]
      requestBody: { $ref: '#/components/requestBodies/EmptyObject' }
      responses: {"200": {"description": "Workflow operation result.","content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowRunResponse"}}}},"400": {"description": "Invalid workflow request."},"401": {"description": "Missing, expired or revoked credential."},"403": {"description": "This credential lacks authority for this operation."},"409": {"description": "Workflow scope, lease, sequence or state conflict."}}
  /api/v1/workflow-runs/{runId}/resume:
    post:
      operationId: "resumeWorkflowRun"
      tags: [Workflow review]
      description: "Owner-only workflow management."
      parameters: [{"name": "runId","in": "path","required": true,"schema": {"type": "string"}}]
      requestBody: { $ref: '#/components/requestBodies/EmptyObject' }
      responses: {"200": {"description": "Workflow operation result.","content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowRunResponse"}}}},"400": {"description": "Invalid workflow request."},"401": {"description": "Missing, expired or revoked credential."},"403": {"description": "This credential lacks authority for this operation."},"409": {"description": "Workflow scope, lease, sequence or state conflict."}}
  /api/v1/workflow-workers/advertise:
    post:
      operationId: "advertiseWorkflowHost"
      tags: [Workflow workers]
      security: [{ workflowHostAuth: [] }]
      description: "Assigned host claim, at most 20 seconds long polling. The lease field is absent when no work is available."
      requestBody: {"required": true,"content": {"application/json": {"example": {"packages": []}, "schema": {"$ref": "#/components/schemas/WorkflowAdvertisement"}}}}
      responses: {"200": {"description": "Workflow operation result.","content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowHostResponse"}}}},"400": {"description": "Invalid workflow request."},"401": {"description": "Missing, expired or revoked credential."},"403": {"description": "This credential lacks authority for this operation."},"409": {"description": "Workflow scope, lease, sequence or state conflict."}}
  /api/v1/workflow-workers/claim:
    post:
      operationId: "claimWorkflowRun"
      tags: [Workflow workers]
      security: [{ workflowHostAuth: [] }]
      description: "Assigned host claim, at most 20 seconds long polling. The lease field is absent when no work is available."
      requestBody: {"required": true,"content": {"application/json": {"example": {"waitMs": 10000}, "schema": {"$ref": "#/components/schemas/WorkflowClaimDraft"}}}}
      responses: {"200": {"description": "Workflow operation result.","content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowClaimResponse"}}}},"400": {"description": "Invalid workflow request."},"401": {"description": "Missing, expired or revoked credential."},"403": {"description": "This credential lacks authority for this operation."},"409": {"description": "Workflow scope, lease, sequence or state conflict."}}
  /api/v1/workflow-workers/heartbeat:
    post:
      operationId: "heartbeatWorkflowRun"
      tags: [Workflow workers]
      security: [{ workflowHostAuth: [] }]
      description: "Scoped workflow host operation; this credential cannot approve or apply fixes."
      requestBody: {"required": true,"content": {"application/json": {"example": {"lease": {"runId": "run-demo", "hostId": "host-demo", "fence": 1, "expiresAt": "2026-11-10T20:00:00Z"}}, "schema": {"$ref": "#/components/schemas/WorkflowHeartbeatDraft"}}}}
      responses: {"200": {"description": "Workflow operation result.","content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowClaimResponse"}}}},"400": {"description": "Invalid workflow request."},"401": {"description": "Missing, expired or revoked credential."},"403": {"description": "This credential lacks authority for this operation."},"409": {"description": "Workflow scope, lease, sequence or state conflict."}}
  /api/v1/workflow-workers/publish:
    post:
      operationId: "publishWorkflowRun"
      tags: [Workflow workers]
      security: [{ workflowHostAuth: [] }]
      description: "Scoped workflow host operation; this credential cannot approve or apply fixes."
      requestBody: {"required": true,"content": {"application/json": {"example": {"lease": {"runId": "run-demo", "hostId": "host-demo", "fence": 1, "expiresAt": "2026-11-10T20:00:00Z"}, "publication": {"sequence": 1, "checkpointRef": "checkpoint-demo", "completedSourceIds": ["source-demo"], "state": "running"}}, "schema": {"$ref": "#/components/schemas/WorkflowPublishDraft"}}}}
      responses: {"200": {"description": "Workflow operation result.","content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowRunResponse"}}}},"400": {"description": "Invalid workflow request."},"401": {"description": "Missing, expired or revoked credential."},"403": {"description": "This credential lacks authority for this operation."},"409": {"description": "Workflow scope, lease, sequence or state conflict."}}
  /api/v1/workflow-workers/interrupt:
    post:
      operationId: "interruptWorkflowRun"
      tags: [Workflow workers]
      security: [{ workflowHostAuth: [] }]
      description: "Assigned host reports interruption or private-state recovery; never approves or applies fixes."
      requestBody: {"required": true,"content": {"application/json": {"example": {"lease": {"runId": "run-demo", "hostId": "host-demo", "fence": 1, "expiresAt": "2026-11-10T20:00:00Z"}, "recoveryRequired": false}, "schema": {"$ref": "#/components/schemas/WorkflowInterruptDraft"}}}}
      responses: {"200": {"description": "Workflow operation result.","content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowRunResponse"}}}},"400": {"description": "Invalid workflow request."},"401": {"description": "Missing, expired or revoked credential."},"403": {"description": "This credential lacks authority for this operation."},"409": {"description": "Workflow lease or state conflict."}}
  /api/v1/workflow-workers/runs/{runId}/work:
    get:
      operationId: "listWorkflowWork"
      tags: [Workflow workers]
      security: [{ workflowHostAuth: [] }]
      description: "Scoped workflow host operation; this credential cannot approve or apply fixes."
      parameters: [{"name": "runId","in": "path","required": true,"schema": {"type": "string"}},{"name": "cursor","in": "query","schema": {"type": "string"}},{"name": "limit","in": "query","schema": {"type": "integer","minimum": 1,"maximum": 100}}]
      responses: {"200": {"description": "Workflow operation result.","content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowSourceSnapshotList"}}}},"400": {"description": "Invalid workflow request."},"401": {"description": "Missing, expired or revoked credential."},"403": {"description": "This credential lacks authority for this operation."},"409": {"description": "Workflow scope, lease, sequence or state conflict."}}

  /api/v1/workflow-workers/runs/{runId}/sources/{sourceId}/facts:
    get:
      operationId: "getWorkflowSourceFacts"
      tags: [Workflow workers]
      security: [{ workflowHostAuth: [] }]
      description: "Read-only scoped inspection or review data. Suggestions cannot approve or apply library changes."
      parameters: [{"name": "runId", "in": "path", "required": true, "schema": {"type": "string"}}, {"name": "sourceId", "in": "path", "required": true, "schema": {"type": "string"}}]
      responses: {"200": {"description": "Workflow inspection or finding data.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowSourceFacts"}}}}, "400": {"description": "Invalid observation or evidence."}, "401": {"description": "Missing or invalid credential."}, "403": {"description": "Credential outside scope."}, "409": {"description": "Source or run changed."}}
  /api/v1/workflow-workers/runs/{runId}/sources/{sourceId}/catalog:
    post:
      operationId: "searchWorkflowCatalog"
      tags: [Workflow workers]
      security: [{ workflowHostAuth: [] }]
      description: "Read-only scoped inspection or review data. Suggestions cannot approve or apply library changes."
      parameters: [{"name": "runId", "in": "path", "required": true, "schema": {"type": "string"}}, {"name": "sourceId", "in": "path", "required": true, "schema": {"type": "string"}}]
      responses: {"200": {"description": "Workflow inspection or finding data.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowCatalogResult"}}}}, "400": {"description": "Invalid observation or evidence."}, "401": {"description": "Missing or invalid credential."}, "403": {"description": "Credential outside scope."}, "409": {"description": "Source or run changed."}}
      requestBody: { $ref: '#/components/requestBodies/EmptyObject' }
  /api/v1/workflow-workers/runs/{runId}/suggestions:
    post:
      operationId: "submitWorkflowSuggestions"
      tags: [Workflow workers]
      security: [{ workflowHostAuth: [] }]
      description: "Read-only scoped inspection or review data. Suggestions cannot approve or apply library changes."
      parameters: [{"name": "runId", "in": "path", "required": true, "schema": {"type": "string"}}]
      responses: {"200": {"description": "Workflow inspection or finding data.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowSuggestionResponse"}}}}, "400": {"description": "Invalid observation or evidence."}, "401": {"description": "Missing or invalid credential."}, "403": {"description": "Credential outside scope."}, "409": {"description": "Source or run changed."}}
      requestBody: {"required": true, "content": {"application/json": {"example": {"sourceId": "source-demo", "observations": [{"sourceId": "source-demo", "kind": "missing-front-artwork", "reason": "This source has no selected front cover.", "candidateIds": [], "evidenceIds": ["evidence-demo"]}]}, "schema": {"$ref": "#/components/schemas/WorkflowSuggestionsDraft"}}}}
  /api/v1/workflow-runs/{runId}/findings:
    get:
      operationId: "listWorkflowFindings"
      tags: [Workflow review]
      description: "Read-only scoped inspection or review data. Suggestions cannot approve or apply library changes."
      parameters: [{"name": "runId", "in": "path", "required": true, "schema": {"type": "string"}}, {"name": "cursor", "in": "query", "schema": {"type": "string"}}, {"name": "limit", "in": "query", "schema": {"type": "integer", "minimum": 1, "maximum": 100}}]
      responses: {"200": {"description": "Workflow inspection or finding data.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowFindingList"}}}}, "400": {"description": "Invalid observation or evidence."}, "401": {"description": "Missing or invalid credential."}, "403": {"description": "Credential outside scope."}, "409": {"description": "Source or run changed."}}

  /api/v1/workflow-runs/{runId}/work:
    get:
      operationId: listWorkflowResults
      tags: [Workflow review]
      description: Owner-only paginated inspection results, including unresolved sources.
      parameters: [{name: runId, in: path, required: true, schema: {type: string}}, {name: cursor, in: query, schema: {type: string}}, {name: limit, in: query, schema: {type: integer, minimum: 1, maximum: 100}}]
      responses: {"200": {description: Inspection results., content: {application/json: {schema: {$ref: "#/components/schemas/WorkflowSourceSnapshotList"}}}}, "401": {description: Unauthorized.}, "403": {description: Owner required.}, "404": {description: Run unavailable.}}

  /api/v1/workflow-runs/{runId}/proposals:
    get:
      operationId: "listWorkflowProposals"
      tags: [Workflow review]
      description: "Owner-only immutable workflow review data. Artifact and evidence references are scoped to this run and source."
      parameters: [{"name": "runId", "in": "path", "required": true, "schema": {"type": "string"}}, {"name": "cursor", "in": "query", "schema": {"type": "string"}}, {"name": "limit", "in": "query", "schema": {"type": "integer", "minimum": 1, "maximum": 100}}]
      responses: {"200": {"description": "Review snapshot.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowProposalList"}}}}, "401": {"description": "Credential unavailable."}, "403": {"description": "Owner required."}, "404": {"description": "Scoped review record unavailable."}}
  /api/v1/workflow-runs/{runId}/sources/{sourceId}/evidence/{evidenceId}:
    get:
      operationId: "getWorkflowEvidence"
      tags: [Workflow review]
      description: "Owner-only immutable workflow review data. Artifact and evidence references are scoped to this run and source."
      parameters: [{"name": "runId", "in": "path", "required": true, "schema": {"type": "string"}}, {"name": "sourceId", "in": "path", "required": true, "schema": {"type": "string"}}, {"name": "evidenceId", "in": "path", "required": true, "schema": {"type": "string"}}]
      responses: {"200": {"description": "Review snapshot.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowEvidenceResponse"}}}}, "401": {"description": "Credential unavailable."}, "403": {"description": "Owner required."}, "404": {"description": "Scoped review record unavailable."}}
  /api/v1/workflow-runs/{runId}/sources/{sourceId}/artifacts/{artifactId}/metadata:
    get:
      operationId: "getWorkflowArtifactMetadata"
      tags: [Workflow review]
      description: "Owner-only immutable workflow review data. Artifact and evidence references are scoped to this run and source."
      parameters: [{"name": "runId", "in": "path", "required": true, "schema": {"type": "string"}}, {"name": "sourceId", "in": "path", "required": true, "schema": {"type": "string"}}, {"name": "artifactId", "in": "path", "required": true, "schema": {"type": "string"}}]
      responses: {"200": {"description": "Review snapshot.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowArtifactResponse"}}}}, "401": {"description": "Credential unavailable."}, "403": {"description": "Owner required."}, "404": {"description": "Scoped review record unavailable."}}
  /api/v1/workflow-runs/{runId}/sources/{sourceId}/artifacts/{artifactId}:
    get:
      operationId: "readWorkflowArtifact"
      tags: [Workflow review]
      description: "Owner-only immutable workflow review data. Artifact and evidence references are scoped to this run and source."
      parameters: [{"name": "runId", "in": "path", "required": true, "schema": {"type": "string"}}, {"name": "sourceId", "in": "path", "required": true, "schema": {"type": "string"}}, {"name": "artifactId", "in": "path", "required": true, "schema": {"type": "string"}}]
      responses: {"200": {"description": "Review snapshot.", "content": {"image/png": {"schema": {"type": "string", "format": "binary"}}, "image/jpeg": {"schema": {"type": "string", "format": "binary"}}, "image/webp": {"schema": {"type": "string", "format": "binary"}}}}, "401": {"description": "Credential unavailable."}, "403": {"description": "Owner required."}, "404": {"description": "Scoped review record unavailable."}}

  /api/v1/workflow-runs/{runId}/approvals:
    post:
      operationId: "approveWorkflowBatch"
      tags: [Workflow review]
      description: "Owner-only exact cleanup approval, per-source application receipts and conditional undo. Host and investigator grants cannot call this operation."
      parameters: [{"name": "runId", "in": "path", "required": true, "schema": {"type": "string"}}, {"name": "Idempotency-Key", "in": "header", "required": true, "schema": {"type": "string", "pattern": "^[A-Za-z0-9._:-]{8,200}$"}}]
      responses: {"201": {"description": "Exact review or application receipt.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowApprovalResponse"}}}}, "400": {"description": "Invalid review request."}, "401": {"description": "Credential unavailable."}, "403": {"description": "Owner approval authority required."}, "404": {"description": "Review record unavailable."}, "409": {"description": "Source, selection, proposal or undo state changed."}}
      requestBody: {"required": true, "content": {"application/json": {"example": {"runRevision": 1, "proposals": [{"id": "proposal-demo", "version": 1, "digest": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"}]}, "schema": {"$ref": "#/components/schemas/WorkflowApprovalDraft"}}}}
  /api/v1/workflow-approvals/{approvalId}:
    get:
      operationId: "getWorkflowApproval"
      tags: [Workflow review]
      description: "Owner-only exact cleanup approval, per-source application receipts and conditional undo. Host and investigator grants cannot call this operation."
      parameters: [{"name": "approvalId", "in": "path", "required": true, "schema": {"type": "string"}}]
      responses: {"200": {"description": "Exact review or application receipt.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowApprovalResponse"}}}}, "400": {"description": "Invalid review request."}, "401": {"description": "Credential unavailable."}, "403": {"description": "Owner approval authority required."}, "404": {"description": "Review record unavailable."}, "409": {"description": "Source, selection, proposal or undo state changed."}}
  /api/v1/workflow-approvals/{approvalId}/apply:
    post:
      operationId: "applyWorkflowApproval"
      tags: [Workflow review]
      description: "Owner-only exact cleanup approval, per-source application receipts and conditional undo. Host and investigator grants cannot call this operation."
      parameters: [{"name": "approvalId", "in": "path", "required": true, "schema": {"type": "string"}}]
      responses: {"200": {"description": "Exact review or application receipt.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowApplicationBatchResponse"}}}}, "400": {"description": "Invalid review request."}, "401": {"description": "Credential unavailable."}, "403": {"description": "Owner approval authority required."}, "404": {"description": "Review record unavailable."}, "409": {"description": "Source, selection, proposal or undo state changed."}}
      requestBody: {"required": true, "content": {"application/json": {"example": {"applicationId": "application-demo"}, "schema": {"$ref": "#/components/schemas/WorkflowApplicationDraft"}}}}
  /api/v1/workflow-applications/{applicationId}:
    get:
      operationId: "getWorkflowApplicationBatch"
      tags: [Workflow review]
      description: "Owner-only exact cleanup approval, per-source application receipts and conditional undo. Host and investigator grants cannot call this operation."
      parameters: [{"name": "applicationId", "in": "path", "required": true, "schema": {"type": "string"}}]
      responses: {"200": {"description": "Exact review or application receipt.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowApplicationBatchResponse"}}}}, "400": {"description": "Invalid review request."}, "401": {"description": "Credential unavailable."}, "403": {"description": "Owner approval authority required."}, "404": {"description": "Review record unavailable."}, "409": {"description": "Source, selection, proposal or undo state changed."}}
  /api/v1/workflow-runs/{runId}/applications:
    get:
      operationId: "listWorkflowApplications"
      tags: [Workflow review]
      description: "Owner-only exact cleanup approval, per-source application receipts and conditional undo. Host and investigator grants cannot call this operation."
      parameters: [{"name": "runId", "in": "path", "required": true, "schema": {"type": "string"}}, {"name": "cursor", "in": "query", "schema": {"type": "string"}}, {"name": "limit", "in": "query", "schema": {"type": "integer", "minimum": 1, "maximum": 100}}]
      responses: {"200": {"description": "Exact review or application receipt.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowApplicationList"}}}}, "400": {"description": "Invalid review request."}, "401": {"description": "Credential unavailable."}, "403": {"description": "Owner approval authority required."}, "404": {"description": "Review record unavailable."}, "409": {"description": "Source, selection, proposal or undo state changed."}}
  /api/v1/workflow-applications/{applicationId}/sources/{sourceId}/undo:
    post:
      operationId: "undoWorkflowApplication"
      tags: [Workflow review]
      description: "Owner-only exact cleanup approval, per-source application receipts and conditional undo. Host and investigator grants cannot call this operation."
      parameters: [{"name": "applicationId", "in": "path", "required": true, "schema": {"type": "string"}}, {"name": "sourceId", "in": "path", "required": true, "schema": {"type": "string"}}]
      responses: {"200": {"description": "Exact review or application receipt.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/WorkflowApplicationResponse"}}}}, "400": {"description": "Invalid review request."}, "401": {"description": "Credential unavailable."}, "403": {"description": "Owner approval authority required."}, "404": {"description": "Review record unavailable."}, "409": {"description": "Source, selection, proposal or undo state changed."}}
      requestBody: { $ref: '#/components/requestBodies/EmptyObject' }

components:
  requestBodies:
    EmptyObject:
      required: true
      content:
        application/json:
          schema: { type: object, maxProperties: 0 }
          example: {}
  securitySchemes:
    workflowHostAuth:
      type: http
      scheme: bearer
      description: Scoped workflow host token returned by enrollment. Use it for assigned work, never owner approval.
    investigatorAuth:
      type: http
      scheme: bearer
      description: Short-lived investigator token scoped to specified libraries and operations.
    bearerAuth:
      type: http
      scheme: bearer
      description: Session, device or guest token. Some reads also allow tokenless access under the server's network policy.
  parameters:
    ContentVersion:
      name: v
      in: query
      description: "SHA-256 of the bytes the client expects, as given beside the path in a listing. When it equals the current bytes of a picture (an artwork asset or saved artwork) or of an installed emulator file a 200, 206 or 304 answer carries `Cache-Control: private, max-age=31536000, immutable` and `Vary: Authorization`. Every other answer, including games, saves, system files, patches and any refusal, is unchanged and carries `private, no-cache`. It is not a credential and never widens access."
      schema: { type: string, pattern: '^[a-fA-F0-9]{64}$' }
    RevisionMatch:
      name: If-Match
      in: header
      required: true
      description: Revision ETag from the current item.
      schema: { type: string }
      example: '"rev-1"'
    UploadRange:
      name: Content-Range
      in: header
      description: Byte offset and total length for a resumable upload chunk.
      schema: { type: string }
      example: bytes 0-65535/131072
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      description: Client-generated key. Reuse the same key and request body when retrying.
      schema: { type: string }
      example: example-upload-001
    Range:
      name: Range
      in: header
      description: Single byte range, such as bytes=0-65535.
      schema: { type: string }
      example: bytes=0-65535
    IfRange:
      name: If-Range
      in: header
      description: Strong ETag from the previous response. A mismatch returns the whole file with status 200.
      schema: { type: string }
    IfNoneMatch:
      name: If-None-Match
      in: header
      description: Return status 304 if this validator matches.
      schema: { type: string }
  headers:
    ETag:
      schema: { type: string }
    ContentLength:
      schema: { type: integer, format: int64 }
    ContentRange:
      schema: { type: string }
  responses:
    Content:
      description: Complete file.
      headers:
        ETag: { $ref: '#/components/headers/ETag' }
        Content-Length: { $ref: '#/components/headers/ContentLength' }
      content:
        application/octet-stream:
          schema: { type: string, format: binary }
    PartialContent:
      description: Requested range of bytes.
      headers:
        ETag: { $ref: '#/components/headers/ETag' }
        Content-Length: { $ref: '#/components/headers/ContentLength' }
        Content-Range: { $ref: '#/components/headers/ContentRange' }
      content:
        application/octet-stream:
          schema: { type: string, format: binary }
    ContentHeaders:
      description: File length and validator.
      headers:
        ETag: { $ref: '#/components/headers/ETag' }
        Content-Length: { $ref: '#/components/headers/ContentLength' }
    PartialContentHeaders:
      description: Headers for the selected byte range.
      headers:
        ETag: { $ref: '#/components/headers/ETag' }
        Content-Length: { $ref: '#/components/headers/ContentLength' }
        Content-Range: { $ref: '#/components/headers/ContentRange' }
    UnsatisfiableRange:
      description: Range is outside the file. Content-Range reports the current total size.
      headers:
        Content-Range: { $ref: '#/components/headers/ContentRange' }
  schemas:
    ServerUpdateSettings:
      type: object
      required: [channel, mode]
      properties:
        channel: { type: string, enum: [release, nightly] }
        mode: { type: string, enum: ['off', manual, automatic] }
    ServerUpdateDecision:
      type: object
      required: [action]
      properties:
        action: { type: string, enum: [check, install, later, skip] }
        buildId: { type: string }
    ServerUpdateBuild:
      type: object
      required: [id, version, channel]
      properties:
        id: { type: string }
        version: { type: string }
        channel: { type: string, enum: [release, nightly] }
        builtAt: { type: string, format: date-time }
    ServerUpdateHistoryEntry:
      type: object
      required: [build, at, outcome]
      properties:
        build: { $ref: '#/components/schemas/ServerUpdateBuild' }
        at: { type: string, format: date-time }
        outcome: { type: string, enum: [installed, observed, rolled-back] }
    ServerUpdateStatus:
      type: object
      required: [supported, settings, phase, prompt]
      properties:
        supported: { type: boolean }
        settings: { $ref: '#/components/schemas/ServerUpdateSettings' }
        current: { $ref: '#/components/schemas/ServerUpdateBuild' }
        available: { $ref: '#/components/schemas/ServerUpdateBuild' }
        phase: { type: string, enum: [idle, checking, downloading, restarting] }
        prompt: { type: boolean }
        message: { type: string }
        lastCheckedAt: { type: string, format: date-time, description: Last completed update check for the selected channel. }
        history:
          type: array
          maxItems: 20
          items: { $ref: '#/components/schemas/ServerUpdateHistoryEntry' }
    Problem:
      type: object
      required: [type, title, status]
      properties:
        type: { type: string }
        title: { type: string }
        status: { type: integer }
        detail: { type: [string, 'null'] }
        instance: { type: [string, 'null'] }
        requestId: { type: [string, 'null'] }
    Capabilities:
      type: object
      required: [protocol, minClientVersion, features, limits, authentication]
      properties:
        protocol: { $ref: '#/components/schemas/ProtocolInfo' }
        minClientVersion: { type: string }
        features: { $ref: '#/components/schemas/FeatureFlags' }
        limits: { $ref: '#/components/schemas/Limits' }
        authentication:
          type: array
          items: { type: string }
        bootstrapped: { type: boolean }
        trash: { $ref: '#/components/schemas/TrashPolicy' }
    TrashPolicy:
      type: object
      required: [retentionDays]
      properties:
        retentionDays: { type: integer, description: Days a deleted game or file can still be restored before it is removed for good. }
    TrashEntry:
      type: object
      required: [kind, id, name, libraryId, itemId, itemTitle, systemIdentifier, size, fileCount, deletedAt, purgeAfter, itemDeleted]
      properties:
        kind: { type: string, enum: [item, file] }
        id: { type: string, description: Item id when kind is item, file id when kind is file. }
        name: { type: string }
        libraryId: { type: string }
        itemId: { type: string }
        itemTitle: { type: string }
        systemIdentifier: { type: string }
        size: { type: integer, format: int64, description: Bytes that return on restore. }
        fileCount: { type: integer }
        deletedAt: { type: string, format: date-time }
        deletedBy: { $ref: '#/components/schemas/TrashActor' }
        purgeAfter: { type: string, format: date-time, description: The entry is removed for good at the first retention run after this time. }
        itemDeleted: { type: boolean, description: True for a file whose game is also in the trash. Restore the game first. }
    TrashActor:
      type: object
      description: Who deleted an entry. Absent on entries deleted before the server recorded it.
      required: [id]
      properties:
        id: { type: string }
        name: { type: string, description: Account name. Absent when a guest link or a removed account deleted the entry. }
    TrashPage:
      type: object
      required: [entries, nextCursor]
      properties:
        entries:
          type: array
          items: { $ref: '#/components/schemas/TrashEntry' }
        nextCursor: { type: [string, 'null'] }
    ProtocolInfo:
      type: object
      required: [major, minor, path]
      properties:
        major: { type: integer }
        minor: { type: integer }
        path: { type: string }
    FeatureFlags:
      type: object
      required: [rangeRequests, multiRange, resumableUploads, changeFeed, guestGrants, virtualFormats, webdav, natTraversal]
      properties:
        rangeRequests: { type: boolean }
        multiRange: { type: boolean }
        resumableUploads: { type: boolean }
        changeFeed: { type: boolean }
        guestGrants: { type: boolean }
        virtualFormats:
          type: array
          items: { type: string }
        webdav: { type: boolean }
        natTraversal: { type: boolean }
        webPlayback: { type: boolean }
        romDownloadSummaries: { type: boolean, description: Supports the opt-in ROM download summary on browse rows. }
        gameCompanions: { type: boolean, description: Supports companion discovery and authorized downloads. Inspect supportedKinds on each game. }
        gameCopySelection: { type: boolean, description: Supports game copy links and per-system ROM format negotiation. }
        sourceDetailsWrite: { type: boolean, description: Supports saving a game's title and details and cover from a device with saveSourceDetails and saveSourceCover. }
        localOwnerSignIn: { type: boolean, description: The server wrote a local owner key this run, so localSignIn works from this computer. }
    PlayerCoreResource:
      type: object
      required: [url, sha256, sizeBytes]
      properties:
        url: { type: string, description: Fixed same-origin protected resource path. }
        sha256: { type: string, pattern: '^[a-f0-9]{64}$' }
        sizeBytes: { type: integer, format: int64, minimum: 1, maximum: 67108864 }
    PlayerCoreDescriptor:
      type: object
      required: [version, id, name, systems, runtime, threaded, filesystem, saveCompletion, frontendCommit, coreCommit, emscriptenVersion, contentExtension, maxContentBytes, loader, wasm]
      properties:
        version: { type: integer, enum: [1] }
        id: { type: string, pattern: '^[a-z0-9][a-z0-9_-]{0,63}$' }
        name: { type: string, maxLength: 80 }
        systems:
          type: array
          items: { type: string, pattern: '^com\.provenance\.nes$' }
        runtime: { type: string, enum: [retroarch-emscripten-esm] }
        threaded: { type: boolean, not: { const: true }, description: Always false for this runtime. }
        filesystem: { type: string, enum: [memfs] }
        saveCompletion: { type: string, enum: [command-reply-v1] }
        frontendCommit: { type: string, enum: [4d4bfc0fbaacca30d433e5c11b0b2b5242141b66] }
        coreCommit: { type: string, enum: [ac0d00a7fc01166f84c7bac01d1084ebfd2b865e] }
        emscriptenVersion: { type: string, pattern: '^3\.1\.46$' }
        contentExtension: { type: string, enum: [nes] }
        maxContentBytes: { type: integer, format: int64, minimum: 1, maximum: 67108864 }
        loader: { $ref: '#/components/schemas/PlayerCoreResource' }
        wasm: { $ref: '#/components/schemas/PlayerCoreResource' }
    WebPlayerAsset:
      type: object
      required: [name, url, sha256, sizeBytes]
      properties:
        name: { type: string, pattern: '^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$' }
        url: { type: string }
        sha256: { type: string, pattern: '^[a-f0-9]{64}$' }
        sizeBytes: { type: integer, format: int64, minimum: 1, maximum: 33554432 }
    WebPlayerDescriptor:
      type: object
      required: [profileVersion, id, name, systems, runtime, filesystem, threaded, saveCompletion, contentExtensions, maxContentBytes, buildVersion, loader, wasm, assets]
      properties:
        profileVersion: { type: integer, enum: [1] }
        id: { type: string, maxLength: 120, pattern: '^(?:[a-z0-9][a-z0-9_-]{0,63}|[a-z0-9]+(?:\.[a-z0-9-]+)+)$' }
        name: { type: string, maxLength: 80 }
        systems: { type: array, items: { type: string }, minItems: 1, maxItems: 64 }
        runtime: { type: string, enum: [emscripten-esm-v1, retroarch-emscripten-esm, dolphin-wasm-esm] }
        filesystem: { type: string, enum: [memfs] }
        systemFilesDirectory: { type: string, pattern: '^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$', maxLength: 64, description: Optional single folder below the emulator system directory for all named support files. }
        defaultInputLayout: { type: string, enum: [compact, standard], description: Default touch-controller preset. Saved user layouts take precedence. }
        defaultCoreOptions:
          type: object
          maxProperties: 64
          propertyNames: { pattern: '^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$', not: { enum: [__proto__, constructor, prototype] } }
          additionalProperties: { type: string, minLength: 1, maxLength: 512, pattern: '^(?!\s)(?![\s\S]*\s$)[^"\\|\u0000-\u001f\u007f]+$' }
          description: RetroArch startup defaults. Saved user options take precedence. Keys exclude prototype names; values exclude controls, quotes, backslashes, pipes and surrounding whitespace.
        threaded: { type: boolean, description: True only for the isolated Dolphin runtime. }
        saveCompletion: { type: string, enum: [none, command-reply-v1] }
        contentExtensions: { type: array, items: { type: string }, minItems: 1, maxItems: 32 }
        maxContentBytes: { type: integer, format: int64, minimum: 1, maximum: 9663676416, description: "Up to 9 GiB for disk-backed Dolphin; other runtimes remain limited to 512 MiB." }
        buildVersion: { type: string, maxLength: 128 }
        loader: { $ref: '#/components/schemas/PlayerCoreResource' }
        wasm: { $ref: '#/components/schemas/PlayerCoreResource' }
        assets: { type: array, items: { $ref: '#/components/schemas/WebPlayerAsset' }, maxItems: 16 }
      allOf:
        - if: { required: [defaultCoreOptions] }
          then: { properties: { runtime: { const: retroarch-emscripten-esm } } }
        - if: { properties: { runtime: { const: dolphin-wasm-esm } } }
          then: { properties: { threaded: { const: true }, saveCompletion: { const: none } } }
          else: { properties: { threaded: { const: false } } }
    PlayerIsolationDraft:
      type: object
      additionalProperties: false
      required: [profileId]
      properties:
        profileId: { type: string, minLength: 1, maxLength: 120 }
    PlayerIsolationSession:
      type: object
      additionalProperties: false
      required: [id, url, expiresAt]
      properties:
        id: { type: string, pattern: '^[a-f0-9]{48}$' }
        url: { type: string, format: uri, pattern: '^http://127\.0\.0\.1:[0-9]{1,5}/[a-f0-9]{48}/dolphin-sandbox\.html$' }
        expiresAt: { type: string, format: date-time }
    PlayerConfiguration:
      type: object
      additionalProperties: false
      properties:
        enabled: { type: boolean }
        default: { type: boolean }
    PlayerInstallation:
      type: object
      required: [profile, enabled, source, removable]
      properties:
        profile: { $ref: '#/components/schemas/WebPlayerDescriptor' }
        enabled: { type: boolean }
        source: { type: string, enum: [managed, operator] }
        removable: { type: boolean }
    PlayerCatalogEntry:
      type: object
      required: [id, name, systems, description, available, reason, downloadBytes]
      properties:
        id: { type: string }
        name: { type: string }
        systems: { type: array, items: { type: string } }
        description: { type: string }
        available: { type: boolean }
        reason: { type: [string, 'null'] }
        downloadBytes: { type: [integer, 'null'] }
    PlayerManagement:
      type: object
      required: [items, defaultProfileId, available]
      properties:
        items: { type: array, items: { $ref: '#/components/schemas/PlayerInstallation' } }
        defaultProfileId: { type: [string, 'null'] }
        available: { type: array, items: { $ref: '#/components/schemas/PlayerCatalogEntry' } }
    WebPlayerCatalog:
      type: object
      required: [items, defaultProfileId]
      properties:
        items: { type: array, items: { $ref: '#/components/schemas/WebPlayerDescriptor' }, maxItems: 64 }
        defaultProfileId: { type: [string, 'null'] }
    Limits:
      type: object
      required: [maxUploadBytes, maxPageSize]
      properties:
        maxUploadBytes: { type: integer, format: int64 }
        maxPageSize: { type: integer }
    SystemSummary:
      type: object
      required: [identifier, name]
      properties:
        identifier: { type: string }
        name: { type: string }
    SystemList:
      type: object
      required: [systems, closed]
      properties:
        systems:
          type: array
          items: { $ref: '#/components/schemas/SystemSummary' }
        closed: { type: boolean }
    Library:
      type: object
      required: [id, name, ownerId, revision, createdAt]
      properties:
        id: { type: string }
        name: { type: string }
        canCreateItems: { type: boolean, description: Present on browse-libraries; current permission to create global items. }
        ownerId: { type: string }
        revision: { type: integer }
        createdAt: { type: string }
    LibraryList:
      type: object
      required: [items, nextCursor]
      properties:
        items:
          type: array
          items: { $ref: '#/components/schemas/Library' }
        nextCursor: { type: [string, 'null'] }
    LibraryDraft:
      type: object
      required: [name]
      properties:
        name: { type: string }
    FolderEntry:
      type: object
      required: [name, path]
      properties:
        name:
          type: string
        path:
          type: string
    FolderPlace:
      type: object
      required: [label, path]
      properties:
        label:
          type: string
        path:
          type: string
    FolderListing:
      type: object
      required: [path, parent, entries, places]
      properties:
        path:
          type: string
        parent:
          type: [string, 'null']
        entries:
          type: array
          items:
            $ref: '#/components/schemas/FolderEntry'
        places:
          type: array
          items:
            $ref: '#/components/schemas/FolderPlace'
    WebDavCredential:
      type: object
      required: [id, name, username, createdAt, expiresAt, revokedAt]
      properties:
        id: { type: string }
        name: { type: string }
        username: { type: string }
        createdAt: { type: string, format: date-time }
        expiresAt: { type: string, format: date-time }
        revokedAt: { type: [string, 'null'], format: date-time }
    WebDavCredentialList:
      type: object
      required: [items]
      properties:
        items:
          type: array
          items: { $ref: '#/components/schemas/WebDavCredential' }
    WebDavCredentialDraft:
      type: object
      required: [name]
      properties:
        name: { type: string, minLength: 1, maxLength: 80 }
        expiresInSeconds: { type: integer, minimum: 60, maximum: 31536000, default: 7776000 }
    WebDavCredentialCreated:
      type: object
      required: [credential, password]
      properties:
        credential: { $ref: '#/components/schemas/WebDavCredential' }
        password: { type: string }
    StorageLocation:
      type: object
      required: [id, path, label, createdAt, online]
      properties:
        id: { type: string }
        path: { type: string }
        label: { type: string }
        createdAt: { type: string }
        online: { type: boolean }
    StorageLocationList:
      type: object
      required: [items, writeLocationId]
      properties:
        items:
          type: array
          items: { $ref: '#/components/schemas/StorageLocation' }
        writeLocationId: { type: [string, 'null'] }
    StorageLocationDraft:
      type: object
      required: [path, label]
      properties:
        path: { type: string }
        label: { type: string }
    StorageWriteTarget:
      type: object
      required: [id]
      properties:
        id: { type: [string, 'null'] }
    ContentRoot:
      type: object
      required: [id, path, label, libraryId, createdAt]
      properties:
        id: { type: string }
        path: { type: string }
        label: { type: string }
        libraryId: { type: [string, 'null'] }
        createdAt: { type: string }
    ContentRootList:
      type: object
      required: [items, nextCursor]
      properties:
        items:
          type: array
          items: { $ref: '#/components/schemas/ContentRoot' }
        nextCursor: { type: [string, 'null'] }
    ContentRootDraft:
      type: object
      required: [path, label]
      properties:
        path: { type: string }
        label: { type: string }
        libraryId: { type: [string, 'null'] }
        watch: { type: boolean, description: Explicitly enable automatic watching for the new folder. }
        organize: { type: boolean, description: 'Explicitly enable in-place organization of ROMs, archives and complete disc groups on future match saves.' }
    ContentRootScan:
      type: object
      required: [rootId, medium, online, count]
      properties:
        rootId: { type: string }
        medium: { type: string }
        online: { type: boolean }
        count: { type: integer }
    SourceFile:
      type: object
      required:
        [id, rootId, libraryId, name, kind, size, systemId, availability, medium, contentPath]
      properties:
        id: { type: string }
        rootId: { type: string }
        libraryId: { type: [string, 'null'] }
        name: { type: string }
        kind: { type: string }
        size: { type: integer, format: int64 }
        systemId: { type: [string, 'null'] }
        availability: { type: string }
        medium: { type: string }
        title: { type: string }
        artworkAvailable: { type: boolean }
        artworkPath:
          type: string
          description: Present with artworkAvailable. Authenticated GET for the saved front cover; send If-None-Match with the returned ETag to revalidate.
        artworkVersion:
          type: string
          pattern: '^[a-f0-9]{64}$'
          description: "SHA-256 of the saved front cover. Send it as the `v` query parameter of artworkPath to receive an answer that may be kept without revalidation."
        details: { $ref: '#/components/schemas/SourceDetails' }
        groupFileCount: { type: integer, minimum: 0, maximum: 512 }
        groupError: { type: [string, 'null'] }
        contentPath: { type: string }
    SourceDetails:
      type: object
      description: Saved game details for display. Every field is optional and absent until a match is saved.
      properties:
        publisher: { type: string }
        developer: { type: string }
        year: { type: string }
        genre: { type: string }
        region: { type: string }
        language: { type: string }
        description: { type: string, maxLength: 2000 }
    SourceDetailsDraft:
      type: object
      required: [title]
      additionalProperties: false
      properties:
        title: { type: string, minLength: 1, maxLength: 200, description: Replaces the game's title. Trimmed. }
        details:
          description: Optional. Present keys replace that field, an empty string clears it, absent keys keep their saved value. Omit to keep all saved details.
          allOf:
            - { $ref: '#/components/schemas/SourceDetails' }
    MatchingPlugin:
      type: object
      required: [id, name, kind, capabilities, network]
      properties:
        id: { type: string }
        name: { type: string }
        kind: { type: string, enum: [provider, manager] }
        capabilities:
          type: array
          items: { type: string, enum: [rom, metadata, artwork, patch, cheats] }
        network: { type: boolean }
    MatchingPluginList:
      type: object
      required: [plugins]
      properties:
        plugins:
          type: array
          items: { $ref: '#/components/schemas/MatchingPlugin' }
    FolderWatchPolicy:
      type: object
      required: [rootId, enabled, state]
      properties:
        rootId: { type: string }
        enabled: { type: boolean }
        state: { type: string, enum: [off, watching, polling, offline, scanning, error] }
        lastScanAt: { type: string, format: date-time }
        warning: { type: string }
    FolderWatchPolicyDraft:
      type: object
      additionalProperties: false
      required: [enabled]
      properties:
        enabled: { type: boolean }
    DiscConversionPolicy:
      type: object
      required: [enabled, keepOriginals]
      properties:
        enabled: { type: boolean }
        keepOriginals: { type: boolean }
    DiscConversionDraft:
      type: object
      properties:
        keepOriginals: { type: boolean, default: false }
    DiscConversionResult:
      type: object
      required: [sourceId, name, keptOriginals]
      properties:
        sourceId: { type: string }
        name: { type: string }
        keptOriginals: { type: boolean }
    SourceOrganizationPolicy:
      type: object
      required: [sourceRootId, enabled]
      properties:
        sourceRootId: { type: string }
        enabled: { type: boolean }
        mode: { type: string, enum: [copy, move] }
        targetRootId: { type: string }
        enabledAt: { type: string, format: date-time }
    SourceOrganizationPolicyDraft:
      type: object
      additionalProperties: false
      required: [enabled]
      properties:
        enabled: { type: boolean }
        planId: { type: string, description: Required when enabling. A current owner-bound folder or source organization preview. }
    FolderOrganizationPreview:
      type: object
      required: [planId, examples]
      properties:
        planId: { type: string }
        examples:
          type: array
          maxItems: 5
          items:
            type: object
            required: [sourceRelativePath, targetRelativePath]
            properties:
              sourceRelativePath: { type: string }
              targetRelativePath: { type: string }
    AutomaticOrganizationOutcome:
      type: object
      required: [status]
      properties:
        status: { type: string, enum: [copied, moved, synchronized, skipped, failed] }
        sourceId: { type: string }
        warning: { type: string, description: The match was saved. Organization needs owner attention. }
    SourceOrganizationDraft:
      type: object
      additionalProperties: false
      required: [mode, targetRootId]
      properties:
        mode: { type: string, enum: [copy, move] }
        targetRootId: { type: string }
    SourceOrganizationApply:
      type: object
      additionalProperties: false
      required: [planId]
      properties:
        planId: { type: string }
    SourceOrganizationPreview:
      type: object
      required: [planId, sourceId, mode, sourceRootId, targetRootId, sourceRelativePath, targetRelativePath, expiresAt]
      properties:
        planId: { type: string }
        sourceId: { type: string }
        mode: { type: string, enum: [copy, move] }
        sourceRootId: { type: string }
        targetRootId: { type: string }
        sourceRelativePath: { type: string }
        targetRelativePath: { type: string }
        expiresAt: { type: string, format: date-time }
        files:
          type: array
          maxItems: 512
          items: { $ref: '#/components/schemas/SourceOrganizationFile' }
    SourceOrganizationFile:
      type: object
      required: [sourceRelativePath, targetRelativePath]
      properties:
        sourceRelativePath: { type: string }
        targetRelativePath: { type: string }
    SourceOrganizationResult:
      type: object
      required: [sourceId, originalSourceId, mode, targetRootId, targetRelativePath]
      properties:
        sourceId: { type: string }
        originalSourceId: { type: string }
        warning: { type: string, description: Destination is indexed but the original could not be removed. Inspect both locations before removing the extra file. }
        mode: { type: string, enum: [copy, move] }
        targetRootId: { type: string }
        targetRelativePath: { type: string }
    MatchingOptions:
      type: object
      properties:
        online: { type: boolean, default: false }
        checksum: { type: boolean, default: false }
        autoSave: { type: boolean, default: false, description: Automatically save unique best-confidence matches during this search. Existing saved choices remain authoritative. }
        refreshCatalogs: { type: boolean, default: false, description: Refresh pinned hosted catalog shards through the shared matching job before matching. }
        allowExactNames: { type: boolean, default: false, description: Permit exact full filename and edition matches when no stronger identity conflicts. }
        providerIds:
          type: array
          maxItems: 32
          items: { type: string }
        managerId: { type: string }
    MatchingCandidate:
      type: object
      required: [id, providerId, kind, title, confidence, metadata]
      properties:
        id: { type: string }
        providerId: { type: string }
        kind: { type: string, enum: [rom, metadata, artwork, patch, cheats] }
        title: { type: string }
        confidence: { type: string, enum: [checksum, local, name] }
        metadata:
          type: object
          additionalProperties: { type: string }
        fileId: { type: string }
        url: { type: string }
    SavedSourceMatch:
      type: object
      required: [id, providerId, kind, title, confidence, metadata, contentAvailable, contentType, fileName, updatedAt]
      properties:
        id: { type: string }
        providerId: { type: string }
        kind: { type: string, enum: [rom, metadata, artwork, patch, cheats] }
        artworkRole: { type: string, enum: [front, back, disc, manual, title, screenshot, banner, other] }
        title: { type: string }
        confidence: { type: string, enum: [checksum, local, name] }
        metadata:
          type: object
          additionalProperties: { type: string }
        originFileId: { type: string }
        originUrl: { type: string }
        contentAvailable: { type: boolean }
        contentType: { type: [string, 'null'] }
        fileName: { type: [string, 'null'] }
        updatedAt: { type: string }
    SourceMatchSelections:
      type: object
      required: [sourceId, revision, matches]
      properties:
        automaticOrganization: { $ref: '#/components/schemas/AutomaticOrganizationOutcome' }
        sourceId: { type: string }
        revision: { type: integer, minimum: 0 }
        lookupHints: { $ref: '#/components/schemas/SourceLookupHints' }
        matches:
          type: array
          maxItems: 12
          items: { $ref: '#/components/schemas/SavedSourceMatch' }
    SourceLookupHints:
      type: object
      required: [title, systemId]
      properties:
        title: { type: [string, 'null'], maxLength: 160 }
        systemId: { type: [string, 'null'], maxLength: 120 }
    SourceMatchSelectionDraft:
      type: object
      required: [requestId, candidateId, expectedRevision]
      properties:
        requestId: { type: string }
        candidateId: { type: string }
        expectedRevision: { type: integer, minimum: 0 }
    MatchingProblem:
      type: object
      required: [providerId, code]
      properties:
        providerId: { type: string }
        code: { type: string, enum: [provider-failed] }
    SourceMatches:
      type: object
      required: [sourceId, requestId, plugins, candidates, problems]
      properties:
        sourceId: { type: string }
        requestId: { type: string }
        automatic: { $ref: '#/components/schemas/MatchingAutomaticResult' }
        plugins:
          type: array
          items: { $ref: '#/components/schemas/MatchingPlugin' }
        candidates:
          type: array
          items: { $ref: '#/components/schemas/MatchingCandidate' }
        problems:
          type: array
          items: { $ref: '#/components/schemas/MatchingProblem' }
    MatchingAutomaticResult:
      type: object
      required: [status, saved, error]
      properties:
        status: { type: string, enum: [saved, review, unmatched, skipped] }
        saved: { type: integer, minimum: 0 }
        error: { type: [string, 'null'] }
    SourceGroupFile:
      type: object
      required: [id, name, size, availability]
      properties:
        id: { type: string }
        name: { type: string }
        relativePath:
          type: string
          description: Portable path relative to the common disc-group directory, for contained media staging. Never an absolute server path.
        size: { type: integer, format: int64 }
        availability: { type: string }
    SourceGroup:
      type: object
      required: [sourceId, files, error]
      properties:
        sourceId: { type: string }
        error: { type: [string, 'null'] }
        files:
          type: array
          maxItems: 512
          items: { $ref: '#/components/schemas/SourceGroupFile' }
    SourceFileList:
      type: object
      required: [items]
      properties:
        items:
          type: array
          items: { $ref: '#/components/schemas/SourceFile' }
    Item:
      type: object
      required: [id, libraryId, systemIdentifier, title, md5, crc, revision, createdAt, updatedAt]
      properties:
        id: { type: string }
        libraryId: { type: string }
        systemIdentifier: { type: string }
        title: { type: string }
        md5: { type: [string, 'null'] }
        crc: { type: [string, 'null'] }
        revision: { type: integer }
        createdAt: { type: string }
        updatedAt: { type: string }
    ItemList:
      type: object
      required: [items, nextCursor]
      properties:
        items:
          type: array
          items: { $ref: '#/components/schemas/Item' }
        nextCursor: { type: [string, 'null'] }
    ItemDraft:
      type: object
      required: [libraryId, systemIdentifier, title]
      properties:
        libraryId: { type: string }
        systemIdentifier: { type: string }
        title: { type: string }
        md5: { type: [string, 'null'] }
        crc: { type: [string, 'null'] }
    ItemPatch:
      type: object
      properties:
        title: { type: string }
        md5: { type: [string, 'null'] }
        crc: { type: [string, 'null'] }
    Asset:
      type: object
      required: [id, itemId, kind, displayName, relativePath, sha256, size, md5, crc, shareable, revision, createdAt, updatedAt]
      properties:
        id: { type: string }
        itemId: { type: string }
        kind: { type: string }
        displayName: { type: string }
        relativePath: { type: string }
        sha256: { type: string }
        size: { type: integer, format: int64 }
        md5: { type: [string, 'null'] }
        crc: { type: [string, 'null'] }
        shareable: { type: boolean }
        revision: { type: integer }
        createdAt: { type: string }
        updatedAt: { type: string }
        conflictOf: { type: [string, 'null'] }
    ManifestFile:
      type: object
      required: [id, kind, relativePath, sha256, md5, crc, size, required, contentPath]
      properties:
        id: { type: string }
        kind: { type: string }
        relativePath: { type: string }
        sha256: { type: string }
        md5: { type: [string, 'null'] }
        crc: { type: [string, 'null'] }
        size: { type: integer, format: int64 }
        required: { type: boolean }
        contentPath: { type: string }
        conflictOf: { type: [string, 'null'] }
    Manifest:
      type: object
      required: [version, itemId, revision, files]
      properties:
        version: { type: integer }
        itemId: { type: string }
        revision: { type: integer }
        files:
          type: array
          items: { $ref: '#/components/schemas/ManifestFile' }
    UploadSession:
      type: object
      required: [id, received, state]
      properties:
        id: { type: string }
        received: { type: integer, format: int64 }
        state: { type: string }
    UploadComplete:
      type: object
      required: [itemId, kind, displayName, relativePath, baseRevision]
      properties:
        itemId: { type: string }
        kind: { type: string }
        displayName: { type: string }
        relativePath: { type: string }
        baseRevision: { type: integer }
    ChangeEvent:
      type: object
      required: [cursor, entityType, entityId, op, libraryId, itemId, sensitive, recordedAt]
      properties:
        cursor: { type: integer }
        entityType: { type: string }
        entityId: { type: string }
        op: { type: string }
        libraryId: { type: [string, 'null'] }
        itemId: { type: [string, 'null'] }
        sensitive: { type: boolean }
        recordedAt: { type: string }
    ChangeList:
      type: object
      required: [changes, nextCursor]
      properties:
        changes:
          type: array
          items: { $ref: '#/components/schemas/ChangeEvent' }
        nextCursor: { type: string }
    BootstrapRequest:
      type: object
      required: [token, username, password]
      properties:
        token: { type: string }
        username: { type: string }
        password: { type: string }
    LocalSignInRequest:
      type: object
      required: [key]
      properties:
        key: { type: string, minLength: 43, maxLength: 43 }
    LoginRequest:
      type: object
      required: [username, password]
      properties:
        username: { type: string }
        password: { type: string }
    SessionResponse:
      type: object
      required: [token, tokenType, userId, expiresAt]
      properties:
        token: { type: string }
        tokenType: { type: string }
        userId: { type: string }
        expiresAt: { type: string }
    UserDraft:
      type: object
      required: [username, password]
      properties:
        username: { type: string }
        password: { type: string }
    User:
      type: object
      required: [id, username, isOwner, createdAt]
      properties:
        id: { type: string }
        username: { type: string }
        isOwner: { type: boolean }
        createdAt: { type: string }
    MemberDraft:
      type: object
      required: [role]
      properties:
        role: { type: string }
    ItemAccessDraft:
      type: object
      required: [permission]
      properties:
        permission: { type: string }
    GuestGrantDraft:
      type: object
      required: [libraryId, capabilities, expiresInSeconds]
      properties:
        libraryId: { type: string }
        itemId: { type: [string, 'null'] }
        capabilities:
          type: array
          items: { type: string }
        expiresInSeconds: { type: integer }
    GuestGrantCreated:
      type: object
      required: [id, token, expiresAt]
      properties:
        id: { type: string }
        token: { type: string }
        expiresAt: { type: string }
    LibraryMember:
      type: object
      required: [userId, role]
      properties:
        userId: { type: string }
        role: { type: string }
    LibraryMemberList:
      type: object
      required: [items]
      properties:
        items:
          type: array
          items: { $ref: '#/components/schemas/LibraryMember' }
    DeviceToken:
      type: object
      required: [id, name, scopes, expiresAt, createdAt, revokedAt, lastUsedAt]
      properties:
        id: { type: string }
        name: { type: string }
        scopes:
          type: array
          items: { type: string }
        expiresAt: { type: [string, 'null'] }
        createdAt: { type: string }
        revokedAt: { type: [string, 'null'] }
        lastUsedAt: { type: [string, 'null'] }
    DeviceTokenList:
      type: object
      required: [items]
      properties:
        items:
          type: array
          items: { $ref: '#/components/schemas/DeviceToken' }
    DevicePairingDraft:
      type: object
      required: [name]
      properties:
        name: { type: string, minLength: 1, maxLength: 80 }
    DevicePairingChallenge:
      type: object
      required: [id, pin, secret, expiresInSeconds]
      properties:
        id: { type: string }
        pin: { type: string, pattern: '^[0-9]{6}$' }
        secret: { type: string }
        expiresInSeconds: { type: integer }
    DevicePairingPIN:
      type: object
      required: [pin]
      properties:
        pin: { type: string, pattern: '^[0-9]{6}$' }
    DevicePairingCandidate:
      type: object
      required: [id, name]
      properties:
        id: { type: string }
        name: { type: string }
    DevicePairingApproval:
      type: object
      required: [id, pin]
      properties:
        id: { type: string }
        pin: { type: string, pattern: '^[0-9]{6}$' }
    DevicePairingApproved:
      type: object
      required: [approved]
      properties:
        approved: { type: boolean }
    DevicePairingRedemption:
      type: object
      required: [id, secret]
      properties:
        id: { type: string }
        secret: { type: string }
    DevicePairingInvitation:
      type: object
      required: [id, pin, expiresInSeconds]
      properties:
        id: { type: string }
        pin: { type: string, pattern: '^[0-9]{6}$' }
        expiresInSeconds: { type: integer }
    DevicePairingInvitationClaim:
      type: object
      required: [id, pin, name]
      properties:
        id: { type: string }
        pin: { type: string, pattern: '^[0-9]{6}$' }
        name: { type: string }
    DevicePairingRequest:
      type: object
      required: [id, secret, expiresInSeconds]
      properties:
        id: { type: string }
        secret: { type: string }
        expiresInSeconds: { type: integer }
    DevicePairingPending:
      type: object
      required: [id, name, approved, expiresAt]
      properties:
        id: { type: string }
        name: { type: string }
        approved: { type: boolean }
        expiresAt: { type: string }
    DevicePairingRequestList:
      type: object
      required: [items]
      properties:
        items:
          type: array
          items: { $ref: '#/components/schemas/DevicePairingPending' }
    DevicePairingCompletion:
      type: object
      required: [id, secret, pin]
      properties:
        id: { type: string }
        secret: { type: string }
        pin: { type: string, pattern: '^[0-9]{6}$' }
    DeviceTokenDraft:
      type: object
      required: [name, scopes]
      properties:
        name: { type: string }
        scopes:
          type: array
          items: { type: string }
        expiresInSeconds: { type: [integer, 'null'] }
    DeviceTokenCreated:
      type: object
      required: [id, token, scopes]
      properties:
        id: { type: string }
        token: { type: string }
        scopes:
          type: array
          items: { type: string }
    AuditEvent:
      type: object
      required: [id, at, actorId, action, resourceType, resourceId]
      properties:
        id: { type: integer }
        at: { type: string }
        actorId: { type: [string, 'null'] }
        action: { type: string }
        resourceType: { type: [string, 'null'] }
        resourceId: { type: [string, 'null'] }
    AuditList:
      type: object
      required: [events]
      properties:
        events:
          type: array
          items: { $ref: '#/components/schemas/AuditEvent' }
    VirtualEntry:
      type: object
      required: [entryId, path, compressedSize, uncompressedSize, method]
      properties:
        entryId: { type: string }
        path: { type: string }
        compressedSize: { type: integer, format: int64 }
        uncompressedSize: { type: integer, format: int64 }
        method: { type: string }
        crc: { type: [string, 'null'] }
    VirtualEntryList:
      type: object
      required: [supported, entries]
      properties:
        supported: { type: boolean }
        entries:
          type: array
          items: { type: string }
        format: { type: [string, 'null'] }
        items:
          type: array
          items: { $ref: '#/components/schemas/VirtualEntry' }
    AccessPolicy:
      type: object
      required: [mode, subnets, applies, trusted, manages]
      properties:
        mode: { type: string }
        subnets:
          type: array
          items: { type: string }
        applies: { type: boolean }
        trusted: { type: boolean }
        manages: { type: boolean }
    GuestGrant:
      type: object
      required: [id, libraryId, capabilities, expiresAt, createdAt]
      properties:
        id: { type: string }
        libraryId: { type: string }
        itemId: { type: [string, 'null'] }
        capabilities:
          type: array
          items: { type: string }
        expiresAt: { type: string, format: date-time }
        createdAt: { type: string, format: date-time }
        revokedAt: { type: [string, 'null'] }
        createdBy: { type: string }
    GuestGrantList:
      type: object
      required: [items]
      properties:
        items:
          type: array
          items: { $ref: '#/components/schemas/GuestGrant' }
    RootLibraryAssignment:
      type: object
      required: [libraryId]
      properties:
        libraryId: { type: string }
    LibraryBrowseEntry:
      type: object
      description: entityType selects exactly one matching item, asset or source payload. parentItem is present only for asset entries; previewAsset only for item entries and is an authorized existing artwork asset. Flags reflect current endpoint permissions and are false where inapplicable.
      required: [entityType, id, name, libraryId, systemId, canUpload, canAdopt]
      properties:
        entityType: { type: string, enum: [item, asset, source] }
        id: { type: string }
        name: { type: string }
        libraryId: { type: [string, 'null'] }
        systemId: { type: [string, 'null'] }
        canUpload: { type: boolean }
        canAdopt: { type: boolean }
        item: { $ref: '#/components/schemas/Item' }
        asset: { $ref: '#/components/schemas/Asset' }
        source: { $ref: '#/components/schemas/SourceFile' }
        parentItem: { $ref: '#/components/schemas/Item' }
        previewAsset: { $ref: '#/components/schemas/Asset' }
        romDownload: { $ref: '#/components/schemas/RomDownloadSummary' }
    GameSourceLink:
      type: object
      properties:
        itemId: { type: [string, 'null'] }
        title: { type: string, description: Create a game with this title when itemId is omitted. }
    GameRomCopy:
      type: object
      required: [id, kind, name, format, sizeBytes, contentPath, availability, medium, grouped]
      properties:
        id: { type: string }
        kind: { type: string, enum: [asset, source] }
        name: { type: string }
        format: { type: string }
        sizeBytes: { type: integer, format: int64 }
        contentPath: { type: string }
        availability: { type: string, enum: [local, evicted, offline] }
        medium: { type: string, enum: [internal, removable, network, icloud, unknown] }
        grouped: { type: boolean, description: The content path returns the whole disc set as a ZIP. }
    GameRomCopies:
      type: object
      required: [systemId, items]
      properties:
        systemId: { type: string }
        items:
          type: array
          items: { $ref: '#/components/schemas/GameRomCopy' }
    SystemRomFormats:
      type: object
      required: [systemId, formats]
      properties:
        systemId: { type: string }
        formats:
          type: array
          maxItems: 32
          items: { type: string, pattern: '^[a-z0-9]{1,16}$' }
          description: File extensions in preference order, without a dot.
    GameRomPreferences:
      type: object
      required: [systems]
      properties:
        systems:
          type: array
          maxItems: 100
          items: { $ref: '#/components/schemas/SystemRomFormats' }
        maxBytes: { type: integer, format: int64, minimum: 1 }
        allowDiscBundles: { type: boolean, description: Accept complete disc sets delivered as ZIP bundles. }
    GameRomSelection:
      type: object
      required: [systemId]
      properties:
        systemId: { type: string }
        copy: { $ref: '#/components/schemas/GameRomCopy' }
    RomDownloadSummary:
      type: object
      description: Authorized uploaded-item ROM files. The single-file fields are omitted for empty and grouped results. A true requiresSystemFiles flag means this view also exposes a required BIOS or system file.
      required: [romFileCount, requiresSystemFiles]
      properties:
        romFileCount: { type: integer, minimum: 0 }
        requiresSystemFiles: { type: boolean }
        filename: { type: string }
        sizeBytes: { type: integer, format: int64, minimum: 0 }
        linkedSource: { $ref: '#/components/schemas/LinkedRomDownloadSummary' }
    LinkedRomDownloadSummary:
      type: object
      description: An authorized indexed folder copy selected when no uploaded ROM or required system file is present. Availability is based on the last scan.
      required: [filename, grouped]
      properties:
        filename: { type: string }
        grouped: { type: boolean }
        sizeBytes: { type: integer, format: int64, minimum: 0 }
    CompanionList:
      type: object
      required: [supportedKinds, items]
      properties:
        supportedKinds:
          type: array
          items: { type: string, enum: [patch, mod, texture_pack] }
          description: Types implemented for this entity. An empty array means companions are unsupported.
        items:
          type: array
          items: { $ref: '#/components/schemas/GameCompanion' }
    GameCompanion:
      type: object
      required: [id, kind, required, filename, sizeBytes, sha256, contentPath]
      properties:
        id: { type: string }
        kind: { type: string, enum: [patch, mod, texture_pack], description: Only saved patches are currently served. }
        required: { type: boolean }
        filename: { type: string }
        sizeBytes: { type: integer, format: int64, minimum: 1 }
        sha256: { type: string, pattern: '^[0-9a-f]{64}$' }
        contentPath: { type: string }
        format: { type: string, description: Patch format such as ips, bps, or ups. }
        base: { $ref: '#/components/schemas/CompanionBase' }
    CompanionBase:
      type: object
      description: Expected input from the patch header. Its absence means a base hash is unavailable.
      required: [crc32, sizeBytes]
      properties:
        crc32: { type: string, pattern: '^[0-9a-f]{8}$' }
        sizeBytes: { type: integer, format: int64, minimum: 0 }
    LibraryBrowsePage:
      type: object
      required: [items, nextCursor]
      properties:
        items:
          type: array
          maxItems: 100
          items: { $ref: '#/components/schemas/LibraryBrowseEntry' }
        systemCounts:
          type: array
          description: Readable game counts across the scope before system selection and pagination, respecting search and folder.
          items: { $ref: '#/components/schemas/SystemCount' }
        nextCursor: { type: [string, 'null'], maxLength: 4096 }
    SystemCount:
      type: object
      required: [systemId, count]
      properties:
        systemId: { type: string }
        count: { type: integer, minimum: 1 }
    ContentRootSummary:
      type: object
      required: [root, indexedFileCount, scanState, lastScanAt, lastCheckAt, online, medium]
      properties:
        root: { $ref: '#/components/schemas/ContentRoot' }
        indexedFileCount: { type: integer, minimum: 0 }
        scanState: { type: string, enum: [unknown, pending, completed, failed] }
        lastScanAt: { type: [string, 'null'] }
        lastCheckAt: { type: [string, 'null'] }
        online: { type: [boolean, 'null'] }
        medium: { type: [string, 'null'] }
    ContentRootSummaryList:
      type: object
      required: [items]
      properties:
        items:
          type: array
          items: { $ref: '#/components/schemas/ContentRootSummary' }

    LibraryJobScope:
      type: object
      properties:
        rootId: {type: string}
        libraryId: {type: string}
        unassigned: {type: boolean}
    LibraryJobDraft:
      type: object
      additionalProperties: false
      required: [kind]
      properties:
        kind: {type: string, enum: [scan, match]}
        rootId: {type: string}
        libraryId: {type: string}
        unassigned: {type: boolean}
        options: {$ref: '#/components/schemas/MatchingOptions'}
    LibraryJob:
      type: object
      required: [id, kind, scope, options, state, total, processed, saved, review, unmatched, failed, skipped, currentSourceId, error, createdAt, updatedAt, interruptedCount]
      properties:
        id: {type: string}
        kind: {type: string, enum: [scan, match]}
        scope: {$ref: '#/components/schemas/LibraryJobScope'}
        options: {$ref: '#/components/schemas/MatchingOptions'}
        state: {type: string, enum: [queued, running, completed, failed, cancelled, interrupted]}
        total: {type: integer}
        processed: {type: integer}
        saved: {type: integer}
        review: {type: integer}
        unmatched: {type: integer}
        failed: {type: integer}
        skipped: {type: integer}
        currentSourceId: {type: [string, 'null']}
        error: {type: [string, 'null']}
        createdAt: {type: string}
        updatedAt: {type: string}
        interruptedCount: {type: integer}
        providerFailures:
          type: integer
          minimum: 1
          description: Games in a match job whose lookup sources could not all be reached. Absent when none.
    LibraryOverview:
      type: object
      required: [automaticMatching, folders]
      properties:
        automaticMatching: {type: boolean, description: Whether the server fills missing details and covers after a scan.}
        folders: {type: array, items: {$ref: '#/components/schemas/LibraryOverviewFolder'}}
    LibraryOverviewFolder:
      type: object
      required: [rootId, label, libraryId, games, withDetails, withCover, unavailable, automatic]
      properties:
        rootId: {type: string}
        label: {type: string}
        libraryId: {type: [string, 'null']}
        games: {type: integer, minimum: 0}
        withDetails: {type: integer, minimum: 0}
        withCover: {type: integer, minimum: 0}
        unavailable: {type: integer, minimum: 0, description: Games whose file was offline or not downloaded when last seen.}
        automatic:
          type: object
          required: [state]
          properties:
            state:
              type: string
              enum: [none, waiting, queued, complete, unchanged]
              description: none - no automatic activity this session. waiting - evaluation is pending. queued - a matching batch was created. complete - nothing is missing. unchanged - no game was eligible for this pass.
            checkedAt: {type: string}
            jobId: {type: string}
            jobState: {type: string, enum: [queued, running, completed, failed, cancelled, interrupted]}
            processed: {type: integer, minimum: 0}
            total: {type: integer, minimum: 0}
            review: {type: integer, minimum: 0}
            unmatched: {type: integer, minimum: 0}
            failed: {type: integer, minimum: 0}
            providerFailures: {type: integer, minimum: 0}
            stoppedJobId: {type: string, description: An interrupted matching job covering this folder.}
          example:
            state: queued
            jobId: job-example
            jobState: running
            processed: 18
            total: 50
            review: 2
            unmatched: 3
            failed: 0
            providerFailures: 1
    LibraryJobResponse:
      type: object
      required: [job]
      properties:
        job: {$ref: '#/components/schemas/LibraryJob'}
        reused: {type: boolean}
    LibraryJobList:
      type: object
      required: [jobs, nextCursor]
      properties:
        jobs: {type: array, items: {$ref: '#/components/schemas/LibraryJob'}}
        nextCursor: {type: [string, 'null']}
    LibraryJobItem:
      type: object
      required: [sourceId, status, saved, suggestions, error]
      properties:
        sourceId: {type: string}
        source: {$ref: '#/components/schemas/SourceFile'}
        status: {type: string, enum: [pending, saved, review, unmatched, failed, skipped, reviewed]}
        saved: {type: integer}
        suggestions: {type: integer}
        error: {type: [string, 'null']}
    LibraryJobItemList:
      type: object
      required: [items, nextCursor]
      properties:
        items: {type: array, items: {$ref: '#/components/schemas/LibraryJobItem'}}
        nextCursor: {type: [string, 'null']}

    # Durable workflows are separate from existing scan/match jobs.
    WorkflowScope:
      type: object
      additionalProperties: false
      required: []
      properties:
        libraryId: {"type": "string"}
        rootId: {"type": "string"}
        sourceIds: {"type": "array","items": {"type": "string"},"minItems": 1,"maxItems": 1000,"uniqueItems": true}
        unassigned: {"type": "boolean"}
    WorkflowOptions:
      type: object
      additionalProperties: false
      required: ["online", "checksum", "shareImages"]
      properties:
        online: {"type": "boolean"}
        checksum: {"type": "boolean"}
        shareImages: {"type": "boolean"}
        providerIds: {"type": "array","items": {"type": "string"},"maxItems": 32}
        reasonerConnectionId: {"type": "string"}
        coverInspectorConnectionId: {"type": "string"}
    WorkflowRunDraft:
      type: object
      additionalProperties: false
      required: ["workflowId", "workflowDigest", "hostId", "scope", "options"]
      properties:
        workflowId: {"type": "string","maxLength": 200}
        workflowDigest: {"type": "string","pattern": "^[a-f0-9]{64}$"}
        hostId: {"type": "string"}
        scope: {"$ref": "#/components/schemas/WorkflowScope"}
        options: {"$ref": "#/components/schemas/WorkflowOptions"}
    WorkflowRun:
      type: object
      additionalProperties: false
      required: ["workflowId", "workflowDigest", "hostId", "scope", "options", "id", "actorId", "state", "revision", "total", "processed", "createdAt", "updatedAt", "error"]
      properties:
        workflowId: {"type": "string","maxLength": 200}
        workflowDigest: {"type": "string","pattern": "^[a-f0-9]{64}$"}
        hostId: {"type": "string"}
        scope: {"$ref": "#/components/schemas/WorkflowScope"}
        options: {"$ref": "#/components/schemas/WorkflowOptions"}
        id: {"type": "string"}
        actorId: {"type": "string"}
        state: {"type": "string","enum": ["queued","running","interrupted","completed","cancelled","failed","recovery-required"]}
        revision: {"type": "integer","minimum": 1}
        total: {"type": "integer","minimum": 0}
        processed: {"type": "integer","minimum": 0}
        createdAt: {"type": "string"}
        updatedAt: {"type": "string"}
        error: {"type": ["string","null"]}
    PluginConfiguration:
      type: object
      additionalProperties: false
      required: [id, digest, enabled]
      properties:
        id: { type: string, maxLength: 200 }
        digest: { type: string, pattern: '^[a-f0-9]{64}$' }
        enabled: { type: boolean }
    ManagedWorkflowPlugin:
      type: object
      required: [id, name, version, digest, kind, enabled]
      properties:
        id: { type: string }
        name: { type: string }
        version: { type: string }
        digest: { type: string }
        kind: { type: string, enum: [workflow, translator, tool] }
        enabled: { type: boolean }
    DefaultPlugin:
      type: object
      required: [id, name, version, description]
      properties:
        id: { type: string }
        name: { type: string }
        version: { type: string }
        description: { type: string }
    PluginManagement:
      type: object
      required: [available, hostId, running, error, items, defaults]
      properties:
        available: { type: boolean }
        hostId: { type: [string, 'null'] }
        running: { type: boolean }
        error: { type: [string, 'null'] }
        items:
          type: array
          items: { $ref: '#/components/schemas/ManagedWorkflowPlugin' }
        defaults:
          type: array
          items: { $ref: '#/components/schemas/DefaultPlugin' }
    WorkflowPackageSummary:
      type: object
      additionalProperties: false
      required: [id,name,version,digest,kind]
      properties:
        id: {type: string, maxLength: 200}
        name: {type: string, maxLength: 80}
        version: {type: string, maxLength: 80}
        digest: {type: string, pattern: '^[a-f0-9]{64}$'}
        kind: {type: string, enum: [workflow,translator,tool]}
    WorkflowAdvertisement:
      type: object
      additionalProperties: false
      required: [packages]
      properties:
        packages: {type: array, maxItems: 128, items: {$ref: '#/components/schemas/WorkflowPackageSummary'}}
    WorkflowDecision:
      type: object
      additionalProperties: false
      required: [decision]
      properties:
        decision: {type: string, enum: [keep,dismiss]}
    WorkflowFindingResponse:
      type: object
      required: [finding]
      properties:
        finding: {$ref: '#/components/schemas/WorkflowFinding'}
    InvestigatorDraft:
      type: object
      additionalProperties: false
      required: ["libraryIds","operations","ttlSeconds"]
      properties:
        libraryIds: {"type":"array","items":{"type":"string","minLength":1,"maxLength":200},"maxItems":20,"minItems":1,"uniqueItems":true}
        operations: {"type":"array","items":{"type":"string","enum":["inspect","cleanup","suggest","diagnostics"]},"maxItems":4,"minItems":1,"uniqueItems":true}
        ttlSeconds: {"type":"integer","minimum":60,"maximum":86400}
    InvestigatorCredential:
      type: object
      additionalProperties: false
      required: ["id","libraryIds","operations","expiresAt"]
      properties:
        id: {"type":"string","minLength":1,"maxLength":200}
        libraryIds: {"type":"array","items":{"type":"string","minLength":1,"maxLength":200},"maxItems":20,"minItems":1,"uniqueItems":true}
        operations: {"type":"array","items":{"type":"string","enum":["inspect","cleanup","suggest","diagnostics"]},"maxItems":4,"minItems":1,"uniqueItems":true}
        expiresAt: {"type":"string","format":"date-time"}
    InvestigatorCreated:
      type: object
      additionalProperties: false
      required: ["credential","token"]
      properties:
        credential: {"$ref":"#/components/schemas/InvestigatorCredential"}
        token: {"type":"string","minLength":1,"maxLength":100}
    InvestigatorList:
      type: object
      additionalProperties: false
      required: ["items"]
      properties:
        items: {"type":"array","items":{"$ref":"#/components/schemas/InvestigatorCredential"},"maxItems":32}
    InvestigatorLibrary:
      type: object
      additionalProperties: false
      required: ["id","name"]
      properties:
        id: {"type":"string","minLength":1,"maxLength":200}
        name: {"type":"string","minLength":1,"maxLength":200}
    InvestigatorLibraryList:
      type: object
      additionalProperties: false
      required: ["items"]
      properties:
        items: {"type":"array","items":{"$ref":"#/components/schemas/InvestigatorLibrary"},"maxItems":20}
    InvestigatorSource:
      type: object
      additionalProperties: false
      required: ["id","name","systemId"]
      properties:
        id: {"type":"string","minLength":1,"maxLength":200}
        name: {"type":"string","minLength":1,"maxLength":4096}
        systemId: {"type":["string","null"]}
    InvestigatorSourcePage:
      type: object
      additionalProperties: false
      required: ["items","nextCursor"]
      properties:
        items: {"type":"array","items":{"$ref":"#/components/schemas/InvestigatorSource"},"maxItems":20}
        nextCursor: {"type":["string","null"]}
    InvestigatorRunDraft:
      type: object
      additionalProperties: false
      required: ["libraryId","sourceIds"]
      properties:
        libraryId: {"type":"string","minLength":1,"maxLength":200}
        sourceIds: {"type":"array","items":{"type":"string","minLength":1,"maxLength":200},"maxItems":100,"minItems":1,"uniqueItems":true}
    InvestigatorRun:
      type: object
      additionalProperties: false
      required: ["id","state","createdAt","updatedAt"]
      properties:
        id: {"type":"string","minLength":1,"maxLength":200}
        state: {"type":"string","enum":["queued","running","interrupted","completed","cancelled","failed","recovery-required"]}
        createdAt: {"type":"string","minLength":1,"maxLength":40}
        updatedAt: {"type":"string","minLength":1,"maxLength":40}
    InvestigatorRunResponse:
      type: object
      additionalProperties: false
      required: ["run"]
      properties:
        run: {"$ref":"#/components/schemas/InvestigatorRun"}
    InvestigatorFinding:
      type: object
      additionalProperties: false
      required: ["id","sourceId","kind","evidenceIds","dismissed","reason"]
      properties:
        id: {"type":"string","minLength":1,"maxLength":200}
        sourceId: {"type":"string","minLength":1,"maxLength":200}
        kind: {"type":"string","enum":["identity-conflict","suspected-mismatch","missing-front-artwork","questionable-front-artwork","unavailable-selected-artwork"]}
        evidenceIds: {"type":"array","items":{"type":"string","minLength":1,"maxLength":200},"maxItems":5}
        dismissed: {"type":"boolean"}
        reason: {"type":"string","minLength":1,"maxLength":512}
    InvestigatorProposal:
      type: object
      additionalProperties: false
      required: ["id","sourceId","findingId","version","digest","action"]
      properties:
        id: {"type":"string","minLength":1,"maxLength":200}
        sourceId: {"type":"string","minLength":1,"maxLength":200}
        findingId: {"type":"string","minLength":1,"maxLength":200}
        version: {"type":"integer","minimum":1}
        digest: {"type":"string","minLength":1,"maxLength":64}
        action: {"type":"string","enum":["replace-metadata","replace-system","replace-front-artwork"]}
        evidenceClass: {"type":"string","enum":["verified-source","saved-selection","filename","local","unverified"]}
    InvestigatorFindingPage:
      type: object
      additionalProperties: false
      required: ["items","nextCursor"]
      properties:
        items: {"type":"array","items":{"$ref":"#/components/schemas/InvestigatorFinding"},"maxItems":20}
        nextCursor: {"type":["string","null"]}
    InvestigatorProposalPage:
      type: object
      additionalProperties: false
      required: ["items","nextCursor"]
      properties:
        items: {"type":"array","items":{"$ref":"#/components/schemas/InvestigatorProposal"},"maxItems":20}
        nextCursor: {"type":["string","null"]}
    InvestigatorSuggestion:
      type: object
      additionalProperties: false
      required: ["sourceId","kind","reason","candidateIds","evidenceIds"]
      properties:
        sourceId: {"type":"string","minLength":1,"maxLength":200}
        kind: {"type":"string","enum":["identity-conflict","suspected-mismatch","missing-front-artwork","questionable-front-artwork","unavailable-selected-artwork"]}
        reason: {"type":"string","minLength":1,"maxLength":512}
        candidateIds: {"type":"array","items":{"type":"string","minLength":1,"maxLength":200},"maxItems":1}
        evidenceIds: {"type":"array","items":{"type":"string","minLength":1,"maxLength":200},"maxItems":5,"minItems":1}
    InvestigatorSuggestionResponse:
      type: object
      additionalProperties: false
      required: ["findings","proposals"]
      properties:
        findings: {"type":"array","items":{"$ref":"#/components/schemas/InvestigatorFinding"},"maxItems":1}
        proposals: {"type":"array","items":{"$ref":"#/components/schemas/InvestigatorProposal"},"maxItems":1}
    InvestigatorJobCount:
      type: object
      additionalProperties: false
      required: ["kind","state","count"]
      properties:
        kind: {"type":"string","enum":["scan","match"]}
        state: {"type":"string","enum":["queued","running","interrupted"]}
        count: {"type":"integer","minimum":1}
    InvestigatorDiagnostics:
      type: object
      additionalProperties: false
      required: ["workflowHostRecentlySeen","jobs"]
      properties:
        workflowHostRecentlySeen: {"type":"boolean"}
        jobs: {"type":"array","items":{"$ref":"#/components/schemas/InvestigatorJobCount"},"maxItems":6}
    WorkflowHost:
      type: object
      additionalProperties: false
      required: ["id", "ownerId", "name", "enrolled", "revokedAt", "createdAt"]
      properties:
        packages: {type: array, maxItems: 128, items: {$ref: '#/components/schemas/WorkflowPackageSummary'}}
        lastSeenAt: {type: [string,'null']}
        id: {"type": "string"}
        ownerId: {"type": "string"}
        name: {"type": "string","maxLength": 80}
        enrolled: {"type": "boolean"}
        revokedAt: {"type": ["string","null"]}
        createdAt: {"type": "string"}
    WorkflowHostResponse:
      type: object
      required: [host]
      properties:
        host: { $ref: '#/components/schemas/WorkflowHost' }
    WorkflowLease:
      type: object
      additionalProperties: false
      required: ["runId", "hostId", "fence", "expiresAt"]
      properties:
        runId: {"type": "string"}
        hostId: {"type": "string"}
        fence: {"type": "integer","minimum": 1}
        expiresAt: {"type": "string"}
        publicationSequence: {type: integer, minimum: 0}
        checkpointRef: {type: [string, "null"]}
    WorkflowSourceSnapshot:
      type: object
      additionalProperties: false
      required: ["sourceId", "indexValidator", "selectionRevision", "state"]
      properties:
        sourceId: {"type": "string"}
        indexValidator: {"type": "string"}
        selectionRevision: {"type": "integer","minimum": 0}
        state: {"type": "string","enum": ["pending","completed"]}
        outputJson: {type: string, maxLength: 65536}
    WorkflowPublication:
      type: object
      additionalProperties: false
      required: ["sequence", "checkpointRef", "completedSourceIds"]
      properties:
        sequence: {"type": "integer","minimum": 1}
        checkpointRef: {"type": "string","minLength": 1,"maxLength": 200}
        completedSourceIds: {"type": "array","items": {"type": "string"},"maxItems": 50,"uniqueItems": true}
        state: {"type": "string","enum": ["running","completed"]}
        sourceOutputs: {type: array, maxItems: 50, items: {$ref: "#/components/schemas/WorkflowSourceOutput"}}
    WorkflowFindingDraft:
      type: object
      additionalProperties: false
      required: ["sourceId", "kind", "ruleVersion", "currentValueDigest", "evidenceDigest", "reason", "evidenceIds"]
      properties:
        sourceId: {"type": "string"}
        kind: {"type": "string","enum": ["identity-conflict","suspected-mismatch","missing-front-artwork","questionable-front-artwork","unavailable-selected-artwork"]}
        ruleVersion: {"type": "string","maxLength": 120}
        currentValueDigest: {"type": "string","pattern": "^[a-f0-9]{64}$"}
        evidenceDigest: {"type": "string","pattern": "^[a-f0-9]{64}$"}
        reason: {"type": "string","minLength": 1,"maxLength": 4096}
        evidenceIds: {"type": "array","items": {"type": "string"},"maxItems": 100}
    WorkflowFinding:
      type: object
      additionalProperties: false
      required: ["sourceId", "kind", "ruleVersion", "currentValueDigest", "evidenceDigest", "reason", "evidenceIds", "id", "runId", "fingerprint", "dismissed"]
      properties:
        sourceId: {"type": "string"}
        kind: {"type": "string","enum": ["identity-conflict","suspected-mismatch","missing-front-artwork","questionable-front-artwork","unavailable-selected-artwork"]}
        ruleVersion: {"type": "string","maxLength": 120}
        currentValueDigest: {"type": "string","pattern": "^[a-f0-9]{64}$"}
        evidenceDigest: {"type": "string","pattern": "^[a-f0-9]{64}$"}
        reason: {"type": "string","minLength": 1,"maxLength": 4096}
        evidenceIds: {"type": "array","items": {"type": "string"},"maxItems": 100}
        id: {"type": "string"}
        runId: {"type": "string"}
        fingerprint: {"type": "string"}
        dismissed: {"type": "boolean"}
    WorkflowEvidence:
      type: object
      additionalProperties: false
      required: ["id", "runId", "sourceId", "kind", "sourceValidator", "providerId", "payloadJson"]
      properties:
        id: {"type": "string"}
        runId: {"type": "string"}
        sourceId: {"type": "string"}
        kind: {"type": "string","enum": ["source-fact","catalog","filename","model-observation","tool-observation"]}
        sourceValidator: {"type": "string"}
        providerId: {"type": ["string","null"]}
        payloadJson: {"type": "string","maxLength": 262144}
    CleanupChange:
      type: object
      additionalProperties: false
      required: ["action", "candidateId", "artifactId", "snapshotJson"]
      properties:
        action: {"type": "string","enum": ["replace-metadata","replace-system","replace-front-artwork"]}
        candidateId: {"type": "string"}
        artifactId: {"type": ["string","null"]}
        snapshotJson: {"type": "string","maxLength": 262144}
    WorkflowProposal:
      type: object
      additionalProperties: false
      required: ["id", "version", "runId", "findingId", "sourceId", "sourceValidator", "selectionRevision", "currentValueDigest", "change", "evidenceIds", "reason", "digest"]
      properties:
        sourceName: {type: string, maxLength: 4096}
        evidenceClass: {type: string, enum: [verified-source,saved-selection,filename,local,unverified]}
        id: {"type": "string"}
        version: {"type": "integer","minimum": 1}
        runId: {"type": "string"}
        findingId: {"type": "string"}
        sourceId: {"type": "string"}
        sourceValidator: {"type": "string"}
        selectionRevision: {"type": "integer","minimum": 0}
        currentValueDigest: {"type": "string"}
        change: {"$ref": "#/components/schemas/CleanupChange"}
        evidenceIds: {"type": "array","items": {"type": "string"},"maxItems": 100}
        reason: {"type": "string","maxLength": 4096}
        digest: {"type": "string"}
    WorkflowArtifact:
      type: object
      additionalProperties: false
      required: ["id", "runId", "sourceId", "sha256", "size", "contentType", "width", "height", "attributionJson", "expiresAt"]
      properties:
        id: {"type": "string"}
        runId: {"type": "string"}
        sourceId: {"type": "string"}
        sha256: {"type": "string"}
        size: {"type": "integer","minimum": 0,"maximum": 2097152}
        contentType: { type: string, pattern: '^image/(?:png|jpeg|webp)$' }
        width: {"type": "integer","minimum": 1,"maximum": 16384}
        height: {"type": "integer","minimum": 1,"maximum": 16384}
        attributionJson: {"type": "string","maxLength": 65536}
        expiresAt: {"type": ["string","null"]}
    WorkflowApproval:
      type: object
      additionalProperties: false
      required: ["id", "runId", "actorId", "runRevision", "proposalVersionsJson", "digest", "createdAt"]
      properties:
        id: {"type": "string"}
        runId: {"type": "string"}
        actorId: {"type": "string"}
        runRevision: {"type": "integer","minimum": 0}
        proposalVersionsJson: {"type": "string","maxLength": 1048576}
        digest: {"type": "string"}
        createdAt: {"type": "string"}
    WorkflowApplication:
      type: object
      additionalProperties: false
      required: ["id", "approvalId", "sourceId", "status", "beforeRevision", "afterRevision", "resultJson", "undoExpiresAt"]
      properties:
        id: {"type": "string"}
        approvalId: {"type": "string"}
        sourceId: {"type": "string"}
        status: {"type": "string","enum": ["applied","conflict","failed","undone"]}
        beforeRevision: {"type": "integer","minimum": 0}
        afterRevision: {"type": "integer","minimum": 0}
        resultJson: {"type": "string","maxLength": 1048576}
        undoExpiresAt: {"type": "string"}
    WorkflowRunList:
      type: object
      additionalProperties: false
      required: ["items", "nextCursor"]
      properties:
        items: {"type": "array","items": {"$ref": "#/components/schemas/WorkflowRun"}}
        nextCursor: {"type": ["string","null"]}
    WorkflowFindingList:
      type: object
      additionalProperties: false
      required: ["items", "nextCursor"]
      properties:
        items: {"type": "array","items": {"$ref": "#/components/schemas/WorkflowFinding"}}
        nextCursor: {"type": ["string","null"]}
    WorkflowProposalList:
      type: object
      additionalProperties: false
      required: ["items", "nextCursor"]
      properties:
        findings: {type: array, maxItems: 100, items: {$ref: '#/components/schemas/WorkflowFinding'}}
        items: {"type": "array","items": {"$ref": "#/components/schemas/WorkflowProposal"}}
        nextCursor: {"type": ["string","null"]}
    WorkflowSourceSnapshotList:
      type: object
      additionalProperties: false
      required: ["items", "nextCursor"]
      properties:
        items: {"type": "array","items": {"$ref": "#/components/schemas/WorkflowSourceSnapshot"}}
        nextCursor: {"type": ["string","null"]}

    WorkflowHostDraft:
      type: object
      additionalProperties: false
      required: ["name"]
      properties: {"name": {"type": "string","minLength": 1,"maxLength": 80}}

    WorkflowHostList:
      type: object
      additionalProperties: false
      required: ["items"]
      properties: {"items": {"type": "array","items": {"$ref": "#/components/schemas/WorkflowHost"}}}

    WorkflowHostCreated:
      type: object
      additionalProperties: false
      required: ["host", "enrollmentToken"]
      properties: {"host": {"$ref": "#/components/schemas/WorkflowHost"},"enrollmentToken": {"type": "string"}}

    WorkflowEnrollmentDraft:
      type: object
      additionalProperties: false
      required: ["enrollmentToken"]
      properties: {"enrollmentToken": {"type": "string","minLength": 1,"maxLength": 100}}

    WorkflowHostEnrolled:
      type: object
      additionalProperties: false
      required: ["host", "token"]
      properties: {"host": {"$ref": "#/components/schemas/WorkflowHost"},"token": {"type": "string"}}

    WorkflowRunResponse:
      type: object
      additionalProperties: false
      required: ["run"]
      properties: {"run": {"$ref": "#/components/schemas/WorkflowRun"}}

    WorkflowClaimDraft:
      type: object
      additionalProperties: false
      required: []
      properties: {"waitMs": {"type": "integer","minimum": 0,"maximum": 20000}}

    WorkflowClaimResponse:
      type: object
      additionalProperties: false
      required: []
      properties: {"lease": {"$ref": "#/components/schemas/WorkflowLease"},"run": {"$ref": "#/components/schemas/WorkflowRun"}}

    WorkflowHeartbeatDraft:
      type: object
      additionalProperties: false
      required: ["lease"]
      properties: {"lease": {"$ref": "#/components/schemas/WorkflowLease"}}

    WorkflowPublishDraft:
      type: object
      additionalProperties: false
      required: ["lease", "publication"]
      properties: {"lease": {"$ref": "#/components/schemas/WorkflowLease"},"publication": {"$ref": "#/components/schemas/WorkflowPublication"}}

    WorkflowInterruptDraft:
      type: object
      additionalProperties: false
      required: [lease, recoveryRequired]
      properties: {lease: {$ref: "#/components/schemas/WorkflowLease"}, recoveryRequired: {type: boolean}}

    WorkflowSelectionSummary:
      {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "kind",
          "title",
          "systemId",
          "artworkRole",
          "contentAvailable",
          "identityConflict"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "kind": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "systemId": {
            "type": [
              "string",
              "null"
            ]
          },
          "artworkRole": {
            "type": [
              "string",
              "null"
            ]
          },
          "contentAvailable": {
            "type": "boolean"
          },
          "identityConflict": {
            "type": "boolean"
          }
        }
      }

    WorkflowSourceFacts:
      {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "sourceId",
          "name",
          "systemId",
          "sourceValidator",
          "selectionRevision",
          "currentValueDigest",
          "selected",
          "evidenceIds"
        ],
        "properties": {
          "sourceId": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "systemId": {
            "type": [
              "string",
              "null"
            ]
          },
          "sourceValidator": {
            "type": "string"
          },
          "selectionRevision": {
            "type": "integer",
            "minimum": 0
          },
          "currentValueDigest": {
            "type": "string"
          },
          "selected": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WorkflowSelectionSummary"
            }
          },
          "evidenceIds": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "maxItems": 100
          }
        }
      }

    WorkflowCatalogCandidate:
      {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "kind",
          "title",
          "systemId",
          "artworkRole",
          "providerId",
          "evidenceClass",
          "identityConflict",
          "agreesWithSelection",
          "evidenceIds"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "kind": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "systemId": {
            "type": [
              "string",
              "null"
            ]
          },
          "artworkRole": {
            "type": [
              "string",
              "null"
            ]
          },
          "providerId": {
            "type": "string"
          },
          "evidenceClass": {
            "type": "string",
            "enum": [
              "verified-source",
              "saved-selection",
              "filename",
              "local",
              "unverified"
            ]
          },
          "identityConflict": {
            "type": "boolean"
          },
          "agreesWithSelection": {
            "type": "boolean"
          },
          "evidenceIds": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "maxItems": 100
          }
        }
      }

    WorkflowCatalogProblem:
      {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "providerId",
          "code"
        ],
        "properties": {
          "providerId": {
            "type": "string"
          },
          "code": {
            "type": "string"
          }
        }
      }

    WorkflowCatalogResult:
      {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "facts",
          "candidates",
          "problems",
          "supportedIdentity"
        ],
        "properties": {
          "facts": {
            "$ref": "#/components/schemas/WorkflowSourceFacts"
          },
          "candidates": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WorkflowCatalogCandidate"
            },
            "maxItems": 200
          },
          "problems": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WorkflowCatalogProblem"
            }
          },
          "supportedIdentity": {
            "type": "boolean"
          }
        }
      }

    WorkflowObservation:
      {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "sourceId",
          "kind",
          "reason",
          "evidenceIds",
          "candidateIds"
        ],
        "properties": {
          "sourceId": {
            "type": "string"
          },
          "kind": {
            "type": "string",
            "enum": [
              "identity-conflict",
              "suspected-mismatch",
              "missing-front-artwork",
              "questionable-front-artwork",
              "unavailable-selected-artwork"
            ]
          },
          "reason": {
            "type": "string",
            "maxLength": 4096
          },
          "evidenceIds": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "maxItems": 100
          },
          "candidateIds": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "maxItems": 100
          }
        }
      }

    WorkflowSuggestionsDraft:
      {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "sourceId",
          "observations"
        ],
        "properties": {
          "sourceId": {
            "type": "string"
          },
          "observations": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WorkflowObservation"
            },
            "maxItems": 100
          },
          "proposals": {
            "type": "array",
            "maxItems": 10,
            "items": {
              "$ref": "#/components/schemas/WorkflowProposalSuggestion"
            }
          }
        }
      }

    WorkflowSuggestionResponse:
      {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "findings"
        ],
        "properties": {
          "findings": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WorkflowFinding"
            }
          },
          "proposals": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WorkflowProposal"
            }
          }
        }
      }

    WorkflowSourceOutput:
      type: object
      additionalProperties: false
      required: [sourceId, outputJson]
      properties:
        sourceId: {type: string}
        outputJson: {type: string, maxLength: 65536}

    WorkflowProposalSuggestion:
      {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "sourceId",
          "findingId",
          "action",
          "candidateId",
          "evidenceIds",
          "reason"
        ],
        "properties": {
          "sourceId": {
            "type": "string"
          },
          "findingId": {
            "type": "string"
          },
          "action": {
            "type": "string",
            "enum": [
              "replace-metadata",
              "replace-system",
              "replace-front-artwork"
            ]
          },
          "candidateId": {
            "type": "string"
          },
          "evidenceIds": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "maxItems": 100
          },
          "reason": {
            "type": "string",
            "maxLength": 4096
          }
        }
      }

    WorkflowArtifactResponse:
      {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "artifact"
        ],
        "properties": {
          "artifact": {
            "$ref": "#/components/schemas/WorkflowArtifact"
          }
        }
      }

    WorkflowEvidenceResponse:
      {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "evidence"
        ],
        "properties": {
          "evidence": {
            "$ref": "#/components/schemas/WorkflowEvidence"
          }
        }
      }

    WorkflowProposalVersion:
      {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "version",
          "digest"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "digest": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          }
        }
      }

    WorkflowApprovalDraft:
      {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "runRevision",
          "proposals"
        ],
        "properties": {
          "runRevision": {
            "type": "integer",
            "minimum": 1
          },
          "proposals": {
            "type": "array",
            "minItems": 1,
            "maxItems": 100,
            "items": {
              "$ref": "#/components/schemas/WorkflowProposalVersion"
            }
          }
        }
      }

    WorkflowApplicationDraft:
      {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "applicationId"
        ],
        "properties": {
          "applicationId": {
            "type": "string",
            "pattern": "^[A-Za-z0-9._:-]{8,200}$"
          }
        }
      }

    WorkflowApprovalResponse:
      {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "approval"
        ],
        "properties": {
          "approval": {
            "$ref": "#/components/schemas/WorkflowApproval"
          }
        }
      }

    WorkflowApplicationResponse:
      {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "application"
        ],
        "properties": {
          "application": {
            "$ref": "#/components/schemas/WorkflowApplication"
          }
        }
      }

    WorkflowApplicationBatchResponse:
      {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "applications"
        ],
        "properties": {
          "applications": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "$ref": "#/components/schemas/WorkflowApplication"
            }
          }
        }
      }

    WorkflowApplicationList:
      {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "items",
          "nextCursor"
        ],
        "properties": {
          "items": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "$ref": "#/components/schemas/WorkflowApplication"
            }
          },
          "nextCursor": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      }
