{
  "openapi": "3.1.0",
  "info": {
    "title": "Agent Primitives",
    "version": "0.2.0",
    "description": "Compose and publish private agent bundles and deploy individual files."
  },
  "paths": {
    "/v1/apps/{app}/files/{filename}": {
      "parameters": [
        {
          "name": "app",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9-]{0,62}$"
          }
        },
        {
          "name": "filename",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$"
          }
        }
      ],
      "get": {
        "operationId": "readFile",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Raw file bytes",
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "Invalid bearer"
          },
          "404": {
            "description": "Missing file"
          }
        }
      },
      "put": {
        "operationId": "deployFile",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "schema": {
              "type": "string"
            },
            "description": "Current file ETag when replacing it"
          },
          {
            "name": "If-None-Match",
            "in": "header",
            "schema": {
              "const": "*"
            },
            "description": "Optional explicit create precondition"
          },
          {
            "name": "X-Visibility",
            "in": "header",
            "schema": {
              "type": "string",
              "enum": [
                "private",
                "public_read"
              ],
              "default": "private"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/octet-stream": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated or identical deployment",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Receipt"
                }
              }
            }
          },
          "201": {
            "description": "New deployment",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Receipt"
                }
              }
            }
          },
          "400": {
            "description": "Invalid precondition or visibility"
          },
          "401": {
            "description": "Invalid bearer"
          },
          "403": {
            "description": "Public reads disabled"
          },
          "412": {
            "description": "Stale file version"
          },
          "413": {
            "description": "Over 1 MiB"
          },
          "415": {
            "description": "Unsupported file type"
          },
          "422": {
            "description": "Invalid UTF-8 or JSON"
          },
          "503": {
            "description": "Storage temporarily unavailable"
          }
        }
      }
    },
    "/v/{app}/{filename}": {
      "parameters": [
        {
          "name": "app",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "filename",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "openView",
        "parameters": [
          {
            "name": "preview",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Required for a private file"
          }
        ],
        "responses": {
          "200": {
            "description": "Browser-safe view"
          },
          "404": {
            "description": "File unavailable"
          }
        }
      }
    },
    "/v1/catalog": {
      "get": {
        "operationId": "getCatalog",
        "security": [],
        "responses": {
          "200": {
            "description": "Environment and supported capabilities"
          }
        }
      }
    },
    "/v1/bundles": {
      "post": {
        "operationId": "publishBundle",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Identical manifest reused"
          },
          "201": {
            "description": "Bundle published"
          },
          "401": {
            "description": "An environment bearer is required"
          },
          "409": {
            "description": "Slug bound to a different manifest"
          },
          "422": {
            "description": "Invalid manifest"
          },
          "503": {
            "description": "Temporary storage failure"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BundleInput"
              },
              "examples": {
                "api": {
                  "value": {
                    "version": 1,
                    "slug": "echo-api",
                    "kind": "api",
                    "title": "Echo API",
                    "primitives": {
                      "function": {
                        "echo": "echo"
                      },
                      "api": {
                        "echo": {
                          "method": "POST",
                          "function": "echo"
                        }
                      }
                    }
                  }
                },
                "app": {
                  "value": {
                    "version": 1,
                    "slug": "my-tasks",
                    "preset": "tasks",
                    "title": "My tasks"
                  }
                },
                "harness": {
                  "value": {
                    "version": 1,
                    "slug": "release-harness",
                    "kind": "harness",
                    "title": "Release harness",
                    "context": "# Deployment checks\nVerify the response contract before handing back an app.",
                    "checks": [
                      {
                        "function": "check",
                        "input": {
                          "status": "ok"
                        },
                        "equals": {
                          "status": "ok"
                        }
                      }
                    ],
                    "primitives": {
                      "function": {
                        "check": "echo"
                      },
                      "files": {
                        "fixture.json": "{\"status\":\"ok\"}"
                      }
                    }
                  }
                },
                "scheduler": {
                  "value": {
                    "version": 1,
                    "slug": "minute-check",
                    "kind": "scheduler",
                    "title": "Minute check",
                    "primitives": {
                      "function": {
                        "ping": "echo"
                      },
                      "cron": {
                        "everyMinutes": 1,
                        "function": "ping",
                        "input": {
                          "status": "ok"
                        }
                      }
                    }
                  }
                },
                "static-site": {
                  "value": {
                    "version": 1,
                    "slug": "release-notes",
                    "kind": "static-site",
                    "title": "Release notes",
                    "primitives": {
                      "fe": {
                        "template": "static",
                        "html": "<!doctype html><meta charset=utf-8><title>Release notes</title><h1>Release notes</h1><p>First deployment.</p>"
                      },
                      "files": {
                        "context.md": "# Release notes\nThis text ships with the bundle."
                      },
                      "auth": {
                        "visibility": "private"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/bundles/{slug}": {
      "parameters": [
        {
          "name": "slug",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9-]{0,62}$"
          }
        }
      ],
      "get": {
        "operationId": "getBundle",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Manifest and refreshed private preview"
          }
        }
      }
    },
    "/v1/bundles/{slug}/db/rows": {
      "parameters": [
        {
          "name": "slug",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9-]{0,62}$"
          }
        }
      ],
      "get": {
        "operationId": "listRows",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Current rows"
          }
        }
      },
      "put": {
        "operationId": "createRow",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Row replay"
          },
          "201": {
            "description": "Row created"
          },
          "409": {
            "description": "Existing row or capacity conflict"
          },
          "422": {
            "description": "Invalid row"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "id",
                  "data"
                ],
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "data": {
                    "type": "object"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/bundles/{slug}/db/rows/{id}": {
      "parameters": [
        {
          "name": "slug",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9-]{0,62}$"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9-]{0,62}$"
          }
        }
      ],
      "get": {
        "operationId": "getRow",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Current row and version"
          }
        }
      },
      "patch": {
        "operationId": "updateRow",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Mutation committed"
          },
          "404": {
            "description": "Row not found"
          },
          "412": {
            "description": "Stale version"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "version",
                  "data"
                ],
                "properties": {
                  "version": {
                    "type": "string"
                  },
                  "data": {
                    "type": "object"
                  }
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteRow",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Mutation committed"
          },
          "404": {
            "description": "Row not found"
          },
          "412": {
            "description": "Stale version"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "version"
                ],
                "properties": {
                  "version": {
                    "type": "string"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/bundles/{slug}/functions/{name}": {
      "parameters": [
        {
          "name": "slug",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9-]{0,62}$"
          }
        },
        {
          "name": "name",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9-]{0,62}$"
          }
        }
      ],
      "post": {
        "operationId": "invokeFunction",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Managed function result"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        }
      }
    },
    "/v1/bundles/{slug}/cron/latest": {
      "parameters": [
        {
          "name": "slug",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9-]{0,62}$"
          }
        }
      ],
      "get": {
        "operationId": "latestRun",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Latest run or null"
          }
        }
      }
    },
    "/v1/bundles/{slug}/run": {
      "parameters": [
        {
          "name": "slug",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9-]{0,62}$"
          }
        }
      ],
      "post": {
        "operationId": "runHarness",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "All checks passed"
          },
          "422": {
            "description": "At least one check failed"
          }
        }
      }
    },
    "/v1/bundles/{slug}/context.md": {
      "parameters": [
        {
          "name": "slug",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9-]{0,62}$"
          }
        }
      ],
      "get": {
        "operationId": "getHarnessContext",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Markdown context"
          }
        }
      }
    },
    "/a/{slug}/{route}": {
      "parameters": [
        {
          "name": "slug",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9-]{0,62}$"
          }
        },
        {
          "name": "route",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9-]{0,62}$"
          }
        }
      ],
      "get": {
        "operationId": "getAlias",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Declared function result"
          }
        }
      },
      "post": {
        "operationId": "postAlias",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Declared function result"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "patchAlias",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Declared function result"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteAlias",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Declared function result"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Receipt": {
        "type": "object",
        "required": [
          "app",
          "file",
          "revision",
          "visibility",
          "etag",
          "url",
          "preview_url",
          "preview_expires_at"
        ],
        "properties": {
          "app": {
            "type": "string"
          },
          "file": {
            "type": "string"
          },
          "revision": {
            "type": "string"
          },
          "visibility": {
            "type": "string",
            "enum": [
              "private",
              "public_read"
            ]
          },
          "etag": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "preview_url": {
            "type": "string",
            "format": "uri"
          },
          "preview_expires_at": {
            "type": [
              "integer",
              "null"
            ]
          }
        }
      },
      "BundleInput": {
        "type": "object",
        "required": [
          "version",
          "slug"
        ],
        "properties": {
          "version": {
            "const": 1
          },
          "slug": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9-]{0,62}$"
          },
          "preset": {
            "const": "tasks"
          },
          "title": {
            "type": "string",
            "maxLength": 100
          },
          "kind": {
            "enum": [
              "app",
              "static-site",
              "scheduler",
              "api",
              "harness"
            ]
          },
          "primitives": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "fe": {
                "type": "object"
              },
              "function": {
                "type": "object"
              },
              "db": {
                "type": "object"
              },
              "cron": {
                "type": "object"
              },
              "api": {
                "type": "object"
              },
              "files": {
                "type": "object"
              },
              "auth": {
                "type": "object"
              }
            }
          },
          "context": {
            "type": "string"
          },
          "checks": {
            "type": "array",
            "maxItems": 16,
            "items": {
              "type": "object"
            }
          }
        },
        "oneOf": [
          {
            "required": [
              "preset"
            ],
            "not": {
              "required": [
                "kind"
              ]
            }
          },
          {
            "required": [
              "kind",
              "title",
              "primitives"
            ],
            "not": {
              "required": [
                "preset"
              ]
            }
          }
        ],
        "additionalProperties": false
      }
    }
  },
  "servers": [
    {
      "url": "https://2zx6cxzb5g.execute-api.us-east-1.amazonaws.com",
      "description": "production"
    }
  ]
}
