# Claim or replay a public-view AI operation

`POST /ai-capabilities/public-view/operations`

## OpenAPI

````yaml openapi/agata-v1.yaml post /ai-capabilities/public-view/operations
openapi: 3.0.3
info:
  title: Agata canonical API
  version: 1.0.0
  description: Canonical contract of the Agata Go API. Every documented route is
    registered in internal/delivery/http/handler.go. Monetary amounts are
    expressed in cents and local date keys use YYYY-MM-DD.
servers:
  - url: http://localhost:{port}/api
    description: Local server
    variables:
      port:
        default: "8080"
        description: Local HTTP port
  - url: "{scheme}://{host}/api"
    description: Configurable server
    variables:
      scheme:
        default: https
        enum:
          - http
          - https
      host:
        default: api.example.com
tags:
  - name: Health check
    description: Health-check operations.
  - name: Users
    description: Users domain operations.
  - name: Profiles
    description: Studio domain operations.
  - name: Organizations
    description: Company accounts that own people and Studios. Not followable.
  - name: Public profiles
    description: Public studio reads and one-way follows. Membership is not required.
  - name: Membership
    description: Studio membership plans, Connect status, and fan subscriptions.
  - name: Messages
    description: 1:1 owner chat between a studio owner and a subscriber with the
      owner_chat perk.
  - name: Feedback
    description: Feedback domain operations.
  - name: Internal system
    description: Internal system operations.
  - name: AI capabilities
    description: Durable leases, outcomes, and reversible effects for integrated AI actions.
  - name: Finance
    description: Finance domain operations.
  - name: Goals
    description: Goals domain operations.
  - name: Pomodoro
    description: Pomodoro domain operations.
  - name: Activities
    description: Activities domain operations.
  - name: Calendar
    description: Calendar domain operations.
  - name: Library
    description: Library domain operations.
  - name: Health
    description: Health domain operations.
  - name: Nutrition
    description: Nutrition domain operations.
  - name: Notebook
    description: Notebook domain operations.
  - name: Week plan
    description: Week-plan domain operations.
  - name: Files
    description: Files domain operations.
  - name: Tags
    description: Tags domain operations.
  - name: Tasks
    description: Tasks domain operations.
  - name: Projects
    description: Projects domain operations.
  - name: Internal
    description: Internal integrations protected by Bearer session.
  - name: Internal cron
    description: Internal cron operations.
paths:
  /ai-capabilities/public-view/operations:
    post:
      tags:
        - AI capabilities
      operationId: claimAIPublicViewCapabilityOperation
      summary: Claim or replay a public-view AI operation
      security:
        - sessionBearer: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/AIClaimOperationInput"
      responses:
        "200":
          description: Existing operation resumed, busy, or replayed.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AIClaimOperationResponse"
        "201":
          description: Operation lease claimed.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AIClaimOperationResponse"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "409":
          $ref: "#/components/responses/Conflict"
        "429":
          $ref: "#/components/responses/RateLimited"
        "500":
          $ref: "#/components/responses/ServerError"
components:
  schemas:
    AIClaimOperationInput:
      type: object
      required:
        - operationId
        - capability
        - capabilityVersion
        - targetKey
        - requestDigest
        - leaseOwner
      properties:
        operationId:
          type: string
          format: uuid
        capability:
          type: string
          minLength: 1
          maxLength: 128
        capabilityVersion:
          type: integer
          minimum: 1
        targetKey:
          type: string
          minLength: 1
          maxLength: 500
        requestDigest:
          type: string
          pattern: ^[0-9a-fA-F]{64}$
          description: SHA-256 digest of the immutable operation request.
        leaseOwner:
          type: string
          format: uuid
    AIOperation:
      type: object
      required:
        - operationId
        - capability
        - capabilityVersion
        - targetKey
        - state
        - outcomeData
        - fencingToken
        - evaluatedCount
        - appliedCount
        - skippedCount
        - undoneCount
        - createdAt
        - updatedAt
      properties:
        operationId:
          type: string
          format: uuid
        capability:
          type: string
        capabilityVersion:
          type: integer
          minimum: 1
        targetKey:
          type: string
        state:
          type: string
          enum:
            - running
            - applied
            - partial
            - unchanged
            - stale
            - ineligible
            - busy
            - error
        outcomeCode:
          type: string
        outcomeData:
          description: Capability-specific JSON outcome, limited to 32 KiB on finalization.
        leaseOwner:
          type: string
          format: uuid
        fencingToken:
          type: integer
          format: int64
          minimum: 1
        leaseExpiresAt:
          type: string
          format: date-time
        evaluatedCount:
          type: integer
          minimum: 0
        appliedCount:
          type: integer
          minimum: 0
        skippedCount:
          type: integer
          minimum: 0
        undoneCount:
          type: integer
          minimum: 0
        errorCode:
          type: string
        undoExpiresAt:
          type: string
          format: date-time
          description: Present for undoable operations with applied effects; currently 24
            hours after completion.
        completedAt:
          type: string
          format: date-time
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
    AIClaimOperationResponse:
      type: object
      required:
        - data
      properties:
        data:
          type: object
          required:
            - status
            - operation
          properties:
            status:
              type: string
              enum:
                - claimed
                - resumed
                - busy
                - replayed
            operation:
              $ref: "#/components/schemas/AIOperation"
        request_id:
          type: string
          format: uuid
    ErrorDetail:
      type: object
      required:
        - message
      properties:
        code:
          type: string
          example: VALIDATION_ERROR
        message:
          type: string
          example: The request is not valid.
        limit_key:
          type: string
        limit:
          type: integer
        required_plan:
          type: string
          enum:
            - pro
            - business
        resolution:
          type: string
          enum:
            - upgrade_plan
            - purchase_addon
        addon_key:
          type: string
          enum:
            - extra_members
            - ai_credit_packs
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          $ref: "#/components/schemas/ErrorDetail"
        request_id:
          type: string
          format: uuid
  responses:
    BadRequest:
      description: Invalid request.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
    Unauthorized:
      description: Missing or invalid authentication.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
    Forbidden:
      description: Acceso denegado.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
    Conflict:
      description: Conflict with the current state.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
    RateLimited:
      description: Request limit exceeded.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
    ServerError:
      description: Internal server error.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
````
