{
  "openapi": "3.1.0",
  "info": {
    "title": "Agent Lab Workflow Check",
    "version": "1.0.0",
    "description": "Free on-demand checks of supplied observations from agent workflows. Each run returns evidence and an English company brief."
  },
  "servers": [
    {
      "url": "https://rinatsultan.com"
    }
  ],
  "externalDocs": {
    "url": "https://rinatsultan.com/agent-lab/workflow-check/guide.md"
  },
  "paths": {
    "/agent-lab/workflow-check/run": {
      "post": {
        "operationId": "check_workflow",
        "summary": "Check your own captured workflow results for free",
        "description": "Compare sanitized outputs from one run with explicit assertions. Returns a company brief and per-step evidence. Supply up to 64 KiB. No authentication or billing.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Workflow"
              },
              "examples": {
                "release": {
                  "externalValue": "https://rinatsultan.com/agent-lab/workflow-check/example.json"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Valid scenario evaluated. Read status for passed or failed assertions.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Report"
                }
              }
            }
          },
          "400": {
            "description": "Invalid JSON, unsupported assertion or invalid scenario.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Scenario exceeds the size limit.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "Send application/json.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "Use POST for an evaluation."
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Pointer": {
        "type": "string",
        "maxLength": 256,
        "pattern": "^(?:/(?:[^~/]|~[01])*)*$",
        "description": "RFC 6901 JSON Pointer. An empty pointer selects the whole output."
      },
      "StepId": {
        "type": "string",
        "minLength": 1,
        "maxLength": 48,
        "pattern": "^[A-Za-z0-9._-]+$"
      },
      "Assertion": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "op": {
                "enum": [
                  "exists",
                  "nonempty"
                ]
              },
              "path": {
                "$ref": "#/components/schemas/Pointer"
              }
            },
            "required": [
              "op",
              "path"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "op": {
                "const": "equals"
              },
              "path": {
                "$ref": "#/components/schemas/Pointer"
              },
              "value": {
                "type": [
                  "string",
                  "number",
                  "boolean",
                  "null"
                ]
              }
            },
            "required": [
              "op",
              "path",
              "value"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "op": {
                "const": "matches_step"
              },
              "path": {
                "$ref": "#/components/schemas/Pointer"
              },
              "step": {
                "$ref": "#/components/schemas/StepId"
              },
              "otherPath": {
                "$ref": "#/components/schemas/Pointer"
              }
            },
            "required": [
              "op",
              "path",
              "step",
              "otherPath"
            ],
            "additionalProperties": false
          }
        ]
      },
      "Step": {
        "type": "object",
        "properties": {
          "id": {
            "$ref": "#/components/schemas/StepId"
          },
          "output": {
            "type": [
              "object",
              "array"
            ],
            "description": "Observed JSON object or array, up to 24 nesting levels and 4,000 values per step. Use only needed, sanitized fields."
          },
          "checks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Assertion"
            },
            "minItems": 1,
            "maxItems": 20
          }
        },
        "required": [
          "id",
          "output",
          "checks"
        ],
        "additionalProperties": false
      },
      "Workflow": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "description": "A nonblank title suitable for sharing with the workflow owner."
          },
          "steps": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Step"
            },
            "minItems": 1,
            "maxItems": 12,
            "description": "Ordered steps. IDs must be unique; matches_step must reference an earlier step."
          }
        },
        "required": [
          "name",
          "steps"
        ],
        "additionalProperties": false
      },
      "Status": {
        "enum": [
          "passed",
          "failed"
        ]
      },
      "CheckResult": {
        "type": "object",
        "properties": {
          "path": {
            "$ref": "#/components/schemas/Pointer"
          },
          "op": {
            "enum": [
              "exists",
              "nonempty",
              "equals",
              "matches_step"
            ]
          },
          "status": {
            "$ref": "#/components/schemas/Status"
          },
          "detail": {
            "type": "string"
          }
        },
        "required": [
          "path",
          "op",
          "status",
          "detail"
        ]
      },
      "StepResult": {
        "type": "object",
        "properties": {
          "id": {
            "$ref": "#/components/schemas/StepId"
          },
          "status": {
            "$ref": "#/components/schemas/Status"
          },
          "checks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CheckResult"
            }
          }
        },
        "required": [
          "id",
          "status",
          "checks"
        ]
      },
      "Report": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "status": {
            "$ref": "#/components/schemas/Status"
          },
          "checkedAt": {
            "type": "string",
            "format": "date-time"
          },
          "passedChecks": {
            "type": "integer",
            "minimum": 0
          },
          "totalChecks": {
            "type": "integer",
            "minimum": 1
          },
          "steps": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/StepResult"
            }
          },
          "companyBrief": {
            "type": "string"
          }
        },
        "required": [
          "name",
          "status",
          "checkedAt",
          "passedChecks",
          "totalChecks",
          "steps",
          "companyBrief"
        ]
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        },
        "required": [
          "error"
        ]
      }
    }
  }
}
