openapi: 3.1.0
info:
  title: RoleWright Agent API
  version: "0"
  description: >
    Authenticated, minimal Agent API for approved RoleWright users. The API can
    list/read user-owned applications and save manually supplied jobs for review.
    It cannot submit applications, control browser relay sessions, change billing,
    edit settings, write profile data, access admin data, or mass-apply. Long-lived
    tokens are scoped; application reads require `agent_read`, job creation requires
    `agent_write`, and browser relay use requires the separate `extension` scope.
servers:
  - url: https://rolewright.com/app/api/agent/v0
security:
  - bearerAuth: []
paths:
  /me:
    get:
      summary: Describe the authenticated user and available capabilities.
      operationId: getAgentMe
      responses:
        "200":
          description: User and capability catalog.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AgentMe"
        "401":
          description: Missing or invalid Bearer token.
  /applications:
    get:
      summary: List applications owned by the authenticated user.
      operationId: listAgentApplications
      parameters:
        - name: limit
          in: query
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 25
        - name: archived
          in: query
          required: false
          schema:
            type: boolean
            default: false
      responses:
        "200":
          description: Application list.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/ApplicationSummary"
                  meta:
                    type: object
        "403":
          description: Token is missing the required `agent_read` scope.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "429":
          description: Rate limit exceeded.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
  /applications/{id}:
    get:
      summary: Read one user-owned application.
      operationId: getAgentApplication
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: integer
      responses:
        "200":
          description: Application detail.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ApplicationDetail"
        "404":
          description: Application not found for this user.
        "403":
          description: Token is missing the required `agent_read` scope.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "429":
          description: Rate limit exceeded.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
  /jobs:
    post:
      summary: Save a manually supplied job for review and optional fit scoring.
      operationId: saveAgentJob
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ManualJobInput"
      responses:
        "201":
          description: Job saved for review.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SavedJob"
        "202":
          description: Job saved and fit scoring queued.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SavedJob"
        "400":
          description: Missing required job fields.
        "403":
          description: Token is missing the required `agent_write` scope or account quota is unavailable.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "413":
          description: Request body too large.
        "429":
          description: Rate limit exceeded.
          headers:
            Retry-After:
              schema:
                type: integer
              description: Seconds before retrying this action bucket.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
  schemas:
    AgentMe:
      type: object
      properties:
        user:
          type: object
          properties:
            id:
              type: integer
            email:
              type: string
        token_kind:
          type: string
          enum: [session, long_lived]
        scopes:
          type: array
          items:
            type: string
            enum: [session, extension, agent_read, agent_write]
        capabilities:
          type: object
    ApplicationSummary:
      type: object
      properties:
        id:
          type: integer
        company:
          type: string
        title:
          type: string
        status:
          type: string
        fit_score:
          type: integer
          nullable: true
    ApplicationDetail:
      allOf:
        - $ref: "#/components/schemas/ApplicationSummary"
        - type: object
          properties:
            posting_url:
              type: string
            posting_text:
              type: string
              nullable: true
            allowed_next_steps:
              type: array
              items:
                type: string
    ManualJobInput:
      type: object
      required: [url, company, title]
      properties:
        url:
          type: string
        company:
          type: string
        title:
          type: string
        description:
          type: string
    SavedJob:
      type: object
      properties:
        application_id:
          type: integer
        status:
          type: string
        analyze_enqueued:
          type: boolean
        allowed_next_steps:
          type: array
          items:
            type: string
    ErrorResponse:
      type: object
      properties:
        error:
          type: string
          examples:
            - unauthorized
            - insufficient_scope
            - rate_limited
            - invalid_json
        required_scope:
          type: string
          nullable: true
