{
  "openapi": "3.1.0",
  "info": {
    "title": "Henry's public text API",
    "version": "1.0.0",
    "description": "Read public material for reasoning in your own agent. Public GET requests require no authentication."
  },
  "servers": [
    {
      "url": "https://ask-henry.whenry6688.workers.dev/agent"
    }
  ],
  "security": [],
  "paths": {
    "/": {
      "get": {
        "operationId": "discover",
        "summary": "Discover sections and available operations",
        "parameters": [
          {
            "name": "format",
            "in": "query",
            "required": false,
            "description": "Response representation. Accept text/plain also selects text when format is omitted.",
            "schema": {
              "type": "string",
              "enum": [
                "json",
                "text"
              ],
              "default": "json"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Public source data.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Capabilities"
                }
              },
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid query. The response identifies the parameter to correct.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown source or route.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/sources": {
      "get": {
        "operationId": "listSources",
        "summary": "Browse source summaries",
        "parameters": [
          {
            "name": "section",
            "in": "query",
            "required": false,
            "description": "Section ID returned by the capabilities endpoint.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Maximum records in this response.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 20
            }
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "description": "Records to skip.",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 10000,
              "default": 0
            }
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "description": "Response representation. Accept text/plain also selects text when format is omitted.",
            "schema": {
              "type": "string",
              "enum": [
                "json",
                "text"
              ],
              "default": "json"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Public source data.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SourceList"
                }
              },
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid query. The response identifies the parameter to correct.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown source or route.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/context": {
      "get": {
        "operationId": "readContext",
        "summary": "Read full site text or several complete sections without pagination",
        "parameters": [
          {
            "name": "section",
            "in": "query",
            "required": false,
            "description": "Optional comma-separated section IDs. Omit to read the entire public text collection.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "description": "Response representation. Accept text/plain also selects text when format is omitted.",
            "schema": {
              "type": "string",
              "enum": [
                "json",
                "text"
              ],
              "default": "json"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Public source data.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Context"
                }
              },
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid query. The response identifies the parameter to correct.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown source or route.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/search": {
      "get": {
        "operationId": "searchSources",
        "summary": "Search public text by keyword",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "description": "Distinctive terms to match in the source text.",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 300
            }
          },
          {
            "name": "section",
            "in": "query",
            "required": false,
            "description": "Section ID returned by the capabilities endpoint.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Maximum records in this response.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 20
            }
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "description": "Records to skip.",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 10000,
              "default": 0
            }
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "description": "Response representation. Accept text/plain also selects text when format is omitted.",
            "schema": {
              "type": "string",
              "enum": [
                "json",
                "text"
              ],
              "default": "json"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Public source data.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SourceList"
                }
              },
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid query. The response identifies the parameter to correct.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown source or route.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/sources/{id}": {
      "get": {
        "operationId": "readSource",
        "summary": "Read one complete source",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "URL-encoded stable source ID."
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "description": "Response representation. Accept text/plain also selects text when format is omitted.",
            "schema": {
              "type": "string",
              "enum": [
                "json",
                "text"
              ],
              "default": "json"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Public source data.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SourceRead"
                }
              },
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid query. The response identifies the parameter to correct.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown source or route.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/read": {
      "get": {
        "operationId": "readSources",
        "summary": "Read up to 20 complete sources in one request",
        "parameters": [
          {
            "name": "ids",
            "in": "query",
            "required": true,
            "description": "Comma-separated stable IDs. Missing IDs appear in missing_ids.",
            "schema": {
              "type": "string",
              "maxLength": 4000
            }
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "description": "Response representation. Accept text/plain also selects text when format is omitted.",
            "schema": {
              "type": "string",
              "enum": [
                "json",
                "text"
              ],
              "default": "json"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Public source data.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BatchRead"
                }
              },
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid query. The response identifies the parameter to correct.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown source or route.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "SourceSummary": {
        "type": "object",
        "required": [
          "id",
          "section",
          "page",
          "title",
          "description",
          "url",
          "read_url"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "section": {
            "type": "string"
          },
          "page": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri",
            "description": "Original visual page and exact source location."
          },
          "read_url": {
            "type": "string",
            "format": "uri",
            "description": "Complete source text."
          },
          "snippet": {
            "type": "string"
          }
        }
      },
      "Source": {
        "type": "object",
        "required": [
          "id",
          "section",
          "page",
          "title",
          "description",
          "url",
          "read_url",
          "text"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "section": {
            "type": "string"
          },
          "page": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri",
            "description": "Original visual page and exact source location."
          },
          "read_url": {
            "type": "string",
            "format": "uri",
            "description": "Complete source text."
          },
          "text": {
            "type": "string"
          }
        }
      },
      "SourceList": {
        "type": "object",
        "required": [
          "revision",
          "total",
          "offset",
          "limit",
          "next",
          "sources"
        ],
        "properties": {
          "revision": {
            "type": "string"
          },
          "total": {
            "type": "integer"
          },
          "offset": {
            "type": "integer"
          },
          "limit": {
            "type": "integer"
          },
          "next": {
            "type": [
              "string",
              "null"
            ]
          },
          "sources": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SourceSummary"
            }
          }
        }
      },
      "SourceRead": {
        "type": "object",
        "required": [
          "revision",
          "source"
        ],
        "properties": {
          "revision": {
            "type": "string"
          },
          "source": {
            "$ref": "#/components/schemas/Source"
          }
        }
      },
      "Context": {
        "type": "object",
        "required": [
          "revision",
          "total",
          "complete",
          "text_characters",
          "sources"
        ],
        "properties": {
          "revision": {
            "type": "string"
          },
          "total": {
            "type": "integer"
          },
          "complete": {
            "const": true
          },
          "text_characters": {
            "type": "integer"
          },
          "sources": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Source"
            }
          }
        }
      },
      "BatchRead": {
        "type": "object",
        "required": [
          "revision",
          "sources",
          "missing_ids"
        ],
        "properties": {
          "revision": {
            "type": "string"
          },
          "sources": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Source"
            }
          },
          "missing_ids": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "Capabilities": {
        "type": "object",
        "required": [
          "revision",
          "source_count",
          "sections",
          "links"
        ],
        "properties": {
          "revision": {
            "type": "string"
          },
          "source_count": {
            "type": "integer"
          },
          "sections": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "title",
                "count"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "title": {
                  "type": "string"
                },
                "count": {
                  "type": "integer"
                }
              }
            }
          },
          "links": {
            "type": "object",
            "additionalProperties": {
              "type": "string",
              "format": "uri"
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error",
          "message"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        }
      }
    }
  }
}
