{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/roark/json-schema/roark-append-tool-invocations-response-schema.json",
  "title": "AppendToolInvocationsResponse",
  "description": "Result of appending tool invocations to a call.",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/roark-call-api-openapi.yml#/components/schemas/AppendToolInvocationsResponse",
  "type": "object",
  "properties": {
    "callId": {
      "type": "string",
      "format": "uuid",
      "description": "The call the tool invocations were attached to"
    },
    "added": {
      "type": "integer",
      "description": "Number of tool invocations newly written"
    },
    "skipped": {
      "type": "integer",
      "description": "Number of tool invocations skipped because an identical one (same tool and timing) already existed on the call"
    },
    "metricCollectionJob": {
      "oneOf": [
        {
          "$ref": "#/$defs/MetricCollectionJobResponse"
        },
        {
          "type": "null"
        }
      ],
      "description": "The metric collection job triggered to (re)score the requested metrics, or null when no metrics were requested (or when scoring failed, see metricCollectionError). Track its id to fetch results from GET /v1/metric/collection-jobs/:jobId."
    },
    "metricCollectionError": {
      "type": [
        "string",
        "null"
      ],
      "description": "Present (non-null) only when `metrics` were requested but the collection job could not be started (e.g. insufficient credits, or an unknown metric id). The tool invocations were still attached — retry scoring via POST /v1/metric/collection-jobs, or re-send this request (attaching is idempotent). Null on success or when no metrics were requested."
    }
  },
  "required": [
    "callId",
    "added",
    "skipped",
    "metricCollectionJob",
    "metricCollectionError"
  ],
  "$defs": {
    "MetricCollectionJobResponse": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid",
          "description": "Unique identifier of the metric collection job"
        },
        "status": {
          "type": "string",
          "enum": [
            "PENDING",
            "PROCESSING",
            "COMPLETED",
            "FAILED",
            "CANCELED"
          ],
          "description": "Current status of the job"
        },
        "triggeredBy": {
          "type": "string",
          "enum": [
            "USER_MANUAL",
            "USER_API",
            "METRIC_POLICY",
            "SIMULATION"
          ],
          "description": "What triggered this job"
        },
        "totalItems": {
          "type": "integer",
          "description": "Total number of call-metric pairs to process"
        },
        "completedItems": {
          "type": "integer",
          "description": "Number of items that finished without failing: a value was written, or the metric did not apply to the conversation"
        },
        "failedItems": {
          "type": "integer",
          "description": "Number of items that could not be computed, for example because an artifact the metric reads (such as diarization) failed to generate"
        },
        "startedAt": {
          "type": [
            "string",
            "null"
          ],
          "description": "When the job started processing"
        },
        "completedAt": {
          "type": [
            "string",
            "null"
          ],
          "description": "When the job completed"
        },
        "errorMessage": {
          "type": [
            "string",
            "null"
          ],
          "description": "Why the job failed or, on a COMPLETED job with failedItems above 0, why those items failed"
        },
        "policyIds": {
          "type": "array",
          "items": {
            "type": "string",
            "format": "uuid"
          },
          "description": "IDs of the metric policies that triggered this job"
        },
        "createdAt": {
          "type": "string",
          "description": "When the job was created"
        },
        "updatedAt": {
          "type": "string",
          "description": "When the job was last updated"
        }
      },
      "required": [
        "id",
        "status",
        "triggeredBy",
        "totalItems",
        "completedItems",
        "failedItems",
        "startedAt",
        "completedAt",
        "errorMessage",
        "policyIds",
        "createdAt",
        "updatedAt"
      ],
      "description": "A metric collection job that processes metrics for calls or chats"
    }
  }
}