# AUTO-GENERATED tier-A mirror spec — do not edit.
# Source: openapi/runtime/triggers.yaml (runtime 0.124.0)
#  + policy: openapi/mirror-policies/triggers.json
# Regenerate: node scripts/generate-mirror-specs.mjs
openapi: 3.0.3
info:
  title: naturali.ai — Triggers API
  version: 1.0.0
  description: >-
    Triggers: what starts an automation without a caller — a schedule, an inbound webhook, or a
    manual fire — pointed at an agent, a tool, an orchestration or an eval, with every firing
    recorded. A fully runtime-backed module — this spec is generated verbatim from the runtime's
    own, re-rooted under /v1/projects/{project_id}. The project in the path is authorized by
    naturali and enforced upstream by the project's scoped credential.


    This module mirrors the upstream runtime verbatim (tier A): paths are the runtime's own
    re-rooted under /v1/projects/{project_id}, and every field, method, status code and error shape
    passes through unchanged. Errors raised by the runtime arrive in its envelope; errors raised by
    naturali itself (authentication, project resolution, an unreachable runtime) use naturali's.
  contact:
    name: naturali.ai
    url: https://naturali.ai
servers:
  - url: "{baseUrl}"
    description: Host of your naturali.ai deployment; every path carries the /v1 prefix.
    variables:
      baseUrl:
        description: Base host URL.
        default: https://api.naturali.ai
tags:
  - name: Triggers
    description: Manage triggers and inspect firings
security:
  - bearerAuth: []
  - oauth2:
      - mcp:access
paths:
  /v1/projects/{project_id}/triggers:
    get:
      description: Lists triggers. Filter by project, starter type, or target type.
      tags:
        - Triggers
      summary: List triggers
      operationId: listTriggers
      parameters:
        - name: type
          in: query
          required: false
          schema:
            type: string
            enum:
              - manual
              - webhook
              - schedule
              - event
        - name: target_type
          in: query
          required: false
          schema:
            type: string
            enum:
              - orchestration
              - agent
              - tool
              - eval
        - $ref: "#/components/parameters/Limit"
        - $ref: "#/components/parameters/Cursor"
      responses:
        "200":
          description: A list of triggers
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/Page"
                  - properties:
                      data:
                        type: array
                        items:
                          $ref: "#/components/schemas/Trigger"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "403":
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "404":
          $ref: "#/components/responses/ProjectNotFound"
        "429":
          $ref: "#/components/responses/TooManyRequests"
        "500":
          $ref: "#/components/responses/InternalError"
    post:
      description: Creates a new trigger for a project. A `{{secret:...}}` reference in `tool_context`
        also needs `secrets:UseSecret` on that secret, else `403`. An event trigger whose
        `policy_ids` cannot read a platform namespace its `events` subscribe to is refused with
        `400` `EVENTS_UNREADABLE`.
      tags:
        - Triggers
      summary: Create a trigger
      operationId: createTrigger
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CreateTriggerRequest"
      responses:
        "201":
          description: Trigger created
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TriggerWithSecret"
        "400":
          description: Bad request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "403":
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "404":
          $ref: "#/components/responses/ProjectNotFound"
        "409":
          description: NAME_CONFLICT — a trigger with this name already exists in the project.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "413":
          $ref: "#/components/responses/PayloadTooLarge"
        "429":
          $ref: "#/components/responses/TooManyRequests"
        "500":
          $ref: "#/components/responses/InternalError"
        "502":
          $ref: "#/components/responses/AdmissionUnavailable"
        4XX:
          $ref: "#/components/responses/AdmissionRefused"
    parameters:
      - $ref: "#/components/parameters/ProjectId"
  /v1/projects/{project_id}/triggers/count:
    get:
      description: Counts the triggers `GET /v1/projects/{project_id}/triggers` pages through under the
        same project and filters.
      tags:
        - Triggers
      summary: Count triggers
      operationId: countTriggers
      parameters:
        - name: type
          in: query
          required: false
          description: Only triggers with this starter type.
          schema:
            type: string
            enum:
              - manual
              - webhook
              - schedule
              - event
        - name: target_type
          in: query
          required: false
          description: Only triggers activating this kind of target.
          schema:
            type: string
            enum:
              - orchestration
              - agent
              - tool
              - eval
      responses:
        "200":
          description: The number of matching triggers
          content:
            application/json:
              schema:
                type: object
                required:
                  - count
                properties:
                  count:
                    type: integer
                    description: How many triggers match.
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "403":
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "404":
          $ref: "#/components/responses/ProjectNotFound"
        "429":
          $ref: "#/components/responses/TooManyRequests"
        "500":
          $ref: "#/components/responses/InternalError"
    parameters:
      - $ref: "#/components/parameters/ProjectId"
  /v1/projects/{project_id}/triggers/{trigger_id}:
    get:
      description: Retrieves the details of a specific trigger
      tags:
        - Triggers
      summary: Get a trigger
      operationId: getTrigger
      parameters:
        - name: trigger_id
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Trigger details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Trigger"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "403":
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "404":
          description: Trigger not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "429":
          $ref: "#/components/responses/TooManyRequests"
        "500":
          $ref: "#/components/responses/InternalError"
    patch:
      description: >
        Updates an existing trigger's configuration. The type is immutable. Changing `target_type`
        or `target_id` re-checks that the caller may start the resulting target, because a firing
        acts under the trigger's `policy_ids` rather than the updater's grant. A caller who could
        not start the new target is answered `403` and the trigger keeps the target it had. A
        `{{secret:...}}` reference in a written `tool_context`, or in the stored one when the target
        changes, also needs `secrets:UseSecret` on that secret, else `403`. An update leaving an
        event trigger's `policy_ids` unable to read a platform namespace its `events` subscribe to
        is refused with `400` `EVENTS_UNREADABLE`.
      tags:
        - Triggers
      summary: Update a trigger
      operationId: updateTrigger
      parameters:
        - name: trigger_id
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/UpdateTriggerRequest"
      responses:
        "200":
          description: Trigger updated
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Trigger"
        "400":
          description: Bad request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "403":
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "404":
          description: Trigger not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "413":
          $ref: "#/components/responses/PayloadTooLarge"
        "429":
          $ref: "#/components/responses/TooManyRequests"
        "500":
          $ref: "#/components/responses/InternalError"
        "502":
          $ref: "#/components/responses/AdmissionUnavailable"
        4XX:
          $ref: "#/components/responses/AdmissionRefused"
    delete:
      description: Deletes a trigger
      tags:
        - Triggers
      summary: Delete a trigger
      operationId: deleteTrigger
      parameters:
        - name: trigger_id
          in: path
          required: true
          schema:
            type: string
      responses:
        "204":
          description: Trigger deleted
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "403":
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "404":
          description: Trigger not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "429":
          $ref: "#/components/responses/TooManyRequests"
        "500":
          $ref: "#/components/responses/InternalError"
        "502":
          $ref: "#/components/responses/AdmissionUnavailable"
        4XX:
          $ref: "#/components/responses/AdmissionRefused"
    parameters:
      - $ref: "#/components/parameters/ProjectId"
  /v1/projects/{project_id}/triggers/{trigger_id}/fire:
    post:
      description: Fires a trigger synchronously and returns the terminal firing record. The firing acts
        as the caller ∩ the trigger's `policy_ids`, which must allow starting the target, else the
        firing fails `FORBIDDEN`. A body carrying `input` or `tool_context` also needs the caller to
        start the target, else `403`. The firing itself always settles here; an `eval` target's run
        is queued rather than executed inline, so the record names a `queued` run to poll.
      tags:
        - Triggers
      summary: Fire a trigger
      operationId: fireTrigger
      parameters:
        - name: trigger_id
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/FireTriggerRequest"
      responses:
        "200":
          description: Terminal firing record
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TriggerFiring"
        "400":
          description: Bad request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "403":
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "404":
          description: Trigger not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "409":
          description: Trigger inactive
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "413":
          $ref: "#/components/responses/PayloadTooLarge"
        "429":
          $ref: "#/components/responses/TooManyRequests"
        "500":
          $ref: "#/components/responses/InternalError"
        "502":
          $ref: "#/components/responses/AdmissionUnavailable"
        4XX:
          $ref: "#/components/responses/AdmissionRefused"
    parameters:
      - $ref: "#/components/parameters/ProjectId"
  /v1/projects/{project_id}/triggers/{trigger_id}/secret:
    get:
      description: Retrieves the signing secret for a webhook trigger
      tags:
        - Triggers
      summary: Get trigger secret
      operationId: getTriggerSecret
      x-naturali-agent-exclude: true
      parameters:
        - name: trigger_id
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Trigger secret
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TriggerSecretResponse"
        "400":
          description: Trigger is not a webhook trigger
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "403":
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "404":
          description: Trigger not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "429":
          $ref: "#/components/responses/TooManyRequests"
        "500":
          $ref: "#/components/responses/InternalError"
    parameters:
      - $ref: "#/components/parameters/ProjectId"
  /v1/projects/{project_id}/triggers/{trigger_id}/rotate-secret:
    post:
      description: Rotates the signing secret for a webhook trigger
      tags:
        - Triggers
      summary: Rotate trigger secret
      operationId: rotateTriggerSecret
      x-naturali-agent-exclude: true
      parameters:
        - name: trigger_id
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Secret rotated
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TriggerWithSecret"
        "400":
          description: Trigger is not a webhook trigger
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "403":
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "404":
          description: Trigger not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "429":
          $ref: "#/components/responses/TooManyRequests"
        "500":
          $ref: "#/components/responses/InternalError"
        "502":
          $ref: "#/components/responses/AdmissionUnavailable"
        4XX:
          $ref: "#/components/responses/AdmissionRefused"
    parameters:
      - $ref: "#/components/parameters/ProjectId"
  /v1/projects/{project_id}/trigger-firings:
    get:
      description: Lists firings for a trigger (trigger_id is required).
      tags:
        - Triggers
      summary: List trigger firings
      operationId: listTriggerFirings
      parameters:
        - name: trigger_id
          in: query
          required: true
          description: Trigger to list firings for (trg_...)
          schema:
            type: string
        - $ref: "#/components/parameters/Limit"
        - $ref: "#/components/parameters/Cursor"
      responses:
        "200":
          description: A list of firings
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TriggerFiringListResponse"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "403":
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "404":
          description: Trigger not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "429":
          $ref: "#/components/responses/TooManyRequests"
        "500":
          $ref: "#/components/responses/InternalError"
    parameters:
      - $ref: "#/components/parameters/ProjectId"
  /v1/projects/{project_id}/trigger-firings/{firing_id}:
    get:
      description: Retrieves the details of a specific trigger firing
      tags:
        - Triggers
      summary: Get a trigger firing
      operationId: getTriggerFiring
      parameters:
        - name: firing_id
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Firing details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TriggerFiring"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "403":
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "404":
          description: Firing not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "429":
          $ref: "#/components/responses/TooManyRequests"
        "500":
          $ref: "#/components/responses/InternalError"
    parameters:
      - $ref: "#/components/parameters/ProjectId"
components:
  schemas:
    Trigger:
      type: object
      properties:
        id:
          type: string
        project_id:
          x-naturali-ref: projects
          type: string
        name:
          type: string
        description:
          type: string
          nullable: true
        type:
          type: string
          enum:
            - manual
            - webhook
            - schedule
            - event
        target_type:
          type: string
          enum:
            - orchestration
            - agent
            - tool
            - eval
        target_id:
          type: string
          description: Public ID of the target resource (orchestration, agent, tool, or eval)
        action:
          type: string
          nullable: true
          description: Tool targets only — the action for builtin/mcp tools
        input:
          type: object
          nullable: true
          description: Static input, shallow-merged under fire-time input. For `eval` targets the effective
            input may carry `agent_version` and `baseline_run_id`, which are passed to the queued
            run.
        cron:
          type: string
          nullable: true
          description: 5-field cron expression (UTC). Present only for schedule triggers
        events:
          nullable: true
          description: "Event triggers only: the event type patterns that fire it."
          allOf:
            - $ref: "#/components/schemas/EventTypePatterns"
        event_resources:
          nullable: true
          description: "Event triggers only: resource patterns the event must match. Null matches any resource
            in the project."
          allOf:
            - $ref: "#/components/schemas/EventResourcePatterns"
        event_data:
          nullable: true
          description: "Event triggers only: a filter the event's `data` must match."
          allOf:
            - $ref: "#/components/schemas/EventDataFilter"
        active:
          type: boolean
        policy_ids:
          description: "The policies a firing acts under: alone when nobody called the trigger, intersected
            with the caller's grant for a manual fire."
          allOf:
            - $ref: "#/components/schemas/AttachedPolicyIds"
        next_fire_at:
          type: string
          format: date-time
          nullable: true
          description: Read-only, schedule triggers only. Server-computed next fire time; null while the
            trigger is inactive, recomputed from now when it is re-activated
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
    TriggerWithSecret:
      allOf:
        - $ref: "#/components/schemas/Trigger"
        - type: object
          properties:
            secret:
              type: string
              description: Webhook triggers only. Returned only on create and rotate
    CreateTriggerRequest:
      type: object
      required:
        - name
        - type
        - target_type
        - target_id
        - policy_ids
      additionalProperties: false
      properties:
        name:
          type: string
        description:
          type: string
        type:
          type: string
          enum:
            - manual
            - webhook
            - schedule
            - event
        target_type:
          type: string
          enum:
            - orchestration
            - agent
            - tool
            - eval
        target_id:
          type: string
        action:
          type: string
          description: Tool targets only — the action for builtin/mcp tools
        input:
          type: object
        tool_context:
          type: object
          additionalProperties:
            type: string
          description: >
            Caller context every firing forwards to the run it starts, so an agent whose tools
            authorize through `{{context:<key>}}` can be put on a schedule — a firing has no request
            to carry one. Each key is forwarded as one `X-Naturali-Context-<key>` header.


            **Write-only.** It is accepted here and never returned on a read, so the record cannot
            be used to recover a value.


            A value may be a `{{secret:sec_...}}` reference, which keeps the credential in the
            [secret](/docs/modules/secrets) store and leaves only its id on the trigger; it is
            resolved at fire time, so rotating the secret changes the next firing without touching
            the trigger. A reference is refused here rather than at fire time when it is not in that
            id form (a secret's name does not resolve) or names a secret that does not exist in this
            project.
        cron:
          type: string
          description: 5-field cron expression (UTC). Required when type is schedule
        events:
          description: Required when type is event, rejected otherwise. The event type patterns that fire the
            trigger.
          allOf:
            - $ref: "#/components/schemas/EventTypePatterns"
        event_pattern:
          type: string
          description: "One event type pattern, the same as `events: [event_pattern]`. Send `events` or this,
            not both."
        event_resources:
          description: Event triggers only. Resource patterns the event must match; omitted matches any
            resource in the project.
          allOf:
            - $ref: "#/components/schemas/EventResourcePatterns"
        event_data:
          description: Event triggers only. A filter the event's `data` must match.
          allOf:
            - $ref: "#/components/schemas/EventDataFilter"
        active:
          type: boolean
          default: true
        policy_ids:
          description: The policies every firing acts under. The caller must hold every grant they carry
            inside the trigger's project, else `403 POLICY_GRANT_NOT_HELD`.
          allOf:
            - $ref: "#/components/schemas/AttachedPolicyIds"
    UpdateTriggerRequest:
      type: object
      additionalProperties: false
      properties:
        name:
          type: string
        description:
          type: string
          nullable: true
        target_type:
          type: string
          enum:
            - orchestration
            - agent
            - tool
            - eval
        target_id:
          type: string
        action:
          type: string
          nullable: true
        input:
          type: object
          nullable: true
        tool_context:
          type: object
          nullable: true
          additionalProperties:
            type: string
          description: >
            Replaces the stored bag; `null` clears it. Write-only and resolved at fire time — see
            `CreateTriggerRequest.tool_context`.
        cron:
          type: string
          nullable: true
        events:
          description: Replaces the event type patterns; event triggers only.
          allOf:
            - $ref: "#/components/schemas/EventTypePatterns"
        event_pattern:
          type: string
          description: "The same as `events: [event_pattern]`."
        event_resources:
          nullable: true
          description: Replaces the resource patterns; `null` matches any resource.
          allOf:
            - $ref: "#/components/schemas/EventResourcePatterns"
        event_data:
          nullable: true
          description: Replaces the data filter; `null` clears it.
          allOf:
            - $ref: "#/components/schemas/EventDataFilter"
        active:
          type: boolean
        policy_ids:
          description: Replaces the policies every firing acts under. The caller must hold every grant of each
            one added, else `403 POLICY_GRANT_NOT_HELD`.
          allOf:
            - $ref: "#/components/schemas/AttachedPolicyIds"
    FireTriggerRequest:
      type: object
      additionalProperties: false
      properties:
        input:
          type: object
          description: Fire-time input, shallow-merged over the trigger's static input. For `eval` targets it
            may carry `agent_version` and `baseline_run_id`.
        tool_context:
          type: object
          additionalProperties:
            type: string
          description: >
            Fire-time caller context, shallow-merged per key over the trigger's stored
            `tool_context`. A manual fire has a caller, so this is the one path that can supply a
            value without storing it.


            Forwarded exactly as written: a `{{secret:...}}` reference is resolved only in the
            trigger's stored bag, never in one supplied here.
    TriggerSecretResponse:
      type: object
      properties:
        secret:
          type: string
    TriggerFiring:
      type: object
      properties:
        id:
          type: string
        trigger_id:
          x-naturali-ref: triggers
          type: string
        project_id:
          x-naturali-ref: projects
          type: string
        source:
          type: string
          enum:
            - manual
            - webhook
            - schedule
            - event
        status:
          type: string
          enum:
            - queued
            - running
            - completed
            - failed
        input:
          type: object
          nullable: true
          description: Effective input, after the trigger's static input is merged under the fire-time input.
            For an `event` firing the fire-time input is the event envelope a webhook delivery
            carries (`id`, `event`, `project_id`, `resource_type`, `resource_id`, `data`,
            `timestamp`). For every target but a tool, `fired_at` is the firing's own time (ISO 8601
            UTC), overriding a supplied `fired_at`.
        result:
          type: object
          nullable: true
          description: "{ target_type, result_id, status, output } — output truncated"
        error:
          allOf:
            - $ref: "#/components/schemas/StoredError"
          nullable: true
          description: Why the firing failed, when it did.
        idempotency_key:
          type: string
          nullable: true
          description: "`<event_id>:<trigger_id>` for an `event` firing, where `event_id` is the `id` in
            `input`; `<v1>:<trigger_id>` for a `webhook` firing, from its delivery's `t=,v1=`
            signature; null otherwise. The same event reaching the same trigger twice produces one
            firing under this key, so a consumer reading firings can recognise a redelivery; a
            replayed signed delivery is refused."
        attempts:
          type: integer
          description: Dispatch attempts started. Above 1 means an earlier attempt was interrupted before it
            recorded a result and the firing was redelivered — not that the target refused it, which
            is recorded terminally in `error` and never retried.
        acted_as:
          type: object
          nullable: true
          description: "The principal the firing acted as: the trigger itself (`trigger`, under its
            `policy_ids`), or the caller of a manual fire (under the caller's grant ∩ `policy_ids`).
            Null for a firing refused before it was dispatched."
          required:
            - principal_type
            - principal_id
          properties:
            principal_type:
              $ref: "#/components/schemas/PrincipalType"
            principal_id:
              type: string
              example: trg_V1StGXR8Z5jdHi6B
        started_at:
          type: string
          format: date-time
          nullable: true
        completed_at:
          type: string
          format: date-time
          nullable: true
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
    TriggerFiringListResponse:
      allOf:
        - $ref: "#/components/schemas/Page"
        - properties:
            data:
              type: array
              items:
                $ref: "#/components/schemas/TriggerFiring"
    Page:
      type: object
      description: One page of a list. Rows inserted or removed between two calls neither repeat nor skip
        a row on the next page.
      required:
        - data
        - next_cursor
      properties:
        data:
          type: array
          description: This page's items, in the list's order.
          items: {}
        next_cursor:
          type: string
          nullable: true
          description: Pass as `cursor` to fetch the next page; `null` on the last page.
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          description: Structured error. Every error response uses this shape, so `code` can be read without
            first checking the type of `error`.
          required:
            - code
            - message
            - hint
          properties:
            code:
              type: string
              pattern: ^[A-Z][A-Z0-9_]*$
              description: Machine-readable error code, UPPER_SNAKE whether naturali or the runtime raises it.
              example: FORBIDDEN
            message:
              type: string
              description: Human-readable explanation.
              example: Your role in this project does not carry this action.
            hint:
              type: string
              description: What to do about it, naming the routes of this API to call. For people and agents; it
                may change, so branch on `code`.
              example: Use a credential whose scope includes this action, or ask a project `admin` or `owner` to
                act; the caller's role or key excludes it.
            meta:
              type: object
              additionalProperties: true
              description: Structured context, such as the `resource` and `limit` of a `PLAN_LIMIT_REACHED`.
    EventTypePatterns:
      type: array
      minItems: 1
      items:
        type: string
      description: "Event type patterns: `*` matches every event, `prefix.*` a namespace, or an exact name
        such as `documents.ingested` or a custom name an orchestration emits. A pattern in a
        platform namespace must match a registered event, else `400 INVALID_EVENT_PATTERN`."
      example:
        - documents.*
    EventResourcePatterns:
      type: array
      items:
        type: string
      description: SRN patterns with IAM wildcards (`srn:<project>:<type>:<id>` or `*`); an event is
        received only when its resource matches one. Null or omitted matches any resource in the
        project.
      example:
        - srn:prj_V1StGXR8Z5jdHi6B:document:*
    EventDataFilter:
      description: "A filter the event's `data` must match: a top-level field to a value, or to `in`,
        `gt`, `gte`, `lt`, `lte`. An absent field never matches."
      allOf:
        - $ref: "#/components/schemas/StructuredFilter"
    StructuredFilter:
      type: object
      description: >-
        Narrows results by a JSON field, such as the `metadata` bag. Each key is a field; its value
        is either a value to match exactly, or an object naming one or more operators.


        Equality and `in` match the stored value exactly, so `3` and `"3"` are different filters.


        `gt`, `gte`, `lt` and `lte` order the field against the operand, and the operand's own JSON
        type says which comparison is meant: a number orders numerically, a string
        lexicographically. They work on any field, in any scope. A row whose field holds another
        type is excluded from the comparison rather than erroring on it, so a range never fails on a
        bag that happens to hold text where another holds a number. An operand that is neither a
        number nor a string — a boolean, `null`, a list, an object — has no ordering and is `400
        VALIDATION_FAILED`, naming the field in `meta.field`.
      additionalProperties: true
      example:
        quarter: Q1
        revision:
          gte: 3
          lt: 11
        status:
          in:
            - draft
            - final
    AttachedPolicyIds:
      type: array
      minItems: 1
      items:
        x-naturali-ref: policies
        type: string
      description: The policies the resource acts under; an event subscriber receives an event only when
        they allow reading its resource. The caller must hold every grant of each one it attaches
        inside the project, else `403 POLICY_GRANT_NOT_HELD`.
      example:
        - pol_V1StGXR8Z5jdHi6B
    StoredError:
      type: object
      description: Why a resource's work failed, in the shape of an error response's `error` without
        `hint`. Every `error` field a resource records carries it, so `code` can be read without
        first checking the type of `error`.
      required:
        - code
        - message
      properties:
        code:
          type: string
          description: A key from the server's ERROR_CODES registry, documented on the Error Codes page.
            `INTERNAL_ERROR`, with the message `Internal Server Error`, records an unexpected
            failure whose detail reaches the server log only.
          example: AI_PROVIDER_ERROR
        message:
          type: string
          example: "Provider returned 402: insufficient credits"
        meta:
          type: object
          additionalProperties: true
          description: The failure's own structured context, when it names any.
    PrincipalType:
      type: string
      enum:
        - user
        - api_key
        - agent
        - automation
        - approval
        - trigger
        - system
        - eval
        - decider
        - ingestion_rule
        - memory_rule
        - playbook_version
      description: What kind of principal acted. `user` and `api_key` are authenticated callers, and the
        id is the user's (`user_…`) or the key's own (`key_…`), so a record names which key acted
        rather than its owner. `agent` is an agent writing under its own identity (`agent_…`).
        `automation` is the task engine acting on a dispatch outcome and `approval` an approval
        resolution; neither carries an id. `trigger` is a trigger firing under its own `policy_ids`
        (`trg_…`). `system` is the platform itself, with an id naming the mechanism
        (`retention_sweep`, `zero_retention`). `eval`, `decider`, `ingestion_rule`, `memory_rule`
        and `playbook_version` are that resource's work running under its own `policy_ids` when
        nobody started it, the id its own.
      example: user
  parameters:
    ProjectId:
      name: project_id
      in: path
      required: true
      description: Project public ID (proj_ prefix).
      schema:
        type: string
        example: proj_V1StGXR8Z5jdHi6B
    Limit:
      name: limit
      in: query
      required: false
      description: Results per page, 1 to 100 (default 50). Above 100 it is clamped; below 1 or not an
        integer it is `400`.
      schema:
        type: integer
        minimum: 1
        maximum: 100
        default: 50
    Cursor:
      name: cursor
      in: query
      required: false
      description: The previous page's `next_cursor`; omit it for the first page. A cursor this list did
        not issue is `400`.
      schema:
        type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: A naturali API key (nat_sk_…) or a session JWT.
    oauth2:
      type: oauth2
      description: "A connected app's OAuth access token, issued by this API's authorization server
        (discovery: /.well-known/oauth-authorization-server). Its one scope carries every operation,
        confined to the projects the user chose when approving the app."
      flows:
        authorizationCode:
          authorizationUrl: https://api.naturali.ai/authorize
          tokenUrl: https://api.naturali.ai/token
          refreshUrl: https://api.naturali.ai/token
          scopes:
            mcp:access: Every operation this API serves, on the projects the grant covers.
  responses:
    BadRequest:
      description: The request was malformed or failed validation.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
    TooManyRequests:
      description: "`QUOTA_EXCEEDED` — a `requests` quota on the calling API key or its project is spent
        for the window; `Retry-After` says when it reopens"
      headers:
        Retry-After:
          description: Seconds until the quota window admits a request again
          schema:
            type: integer
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
    InternalError:
      description: Unexpected server error — `INTERNAL_ERROR`, with the raw message never forwarded
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
    PayloadTooLarge:
      description: "`REQUEST_REJECTED` — the request body is over the size the body parser accepts"
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
    AdmissionUnavailable:
      description: The deployment's admission service is asked about this write and did not answer —
        `ADMISSION_UNAVAILABLE`; the write did not happen
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
    AdmissionRefused:
      description: The deployment's admission service refused this write — answered under the service's
        own `4xx` status, with its `code` (matching `^[A-Za-z_][A-Za-z0-9_]{0,63}$`, not necessarily
        an `ERROR_CODES` key), `message` and `meta`; the write did not happen. A status this
        operation also declares on its own is documented there
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
    ProjectNotFound:
      description: The project does not exist or the caller is not a member of it (`RESOURCE_NOT_FOUND`).
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
