File size: 896 Bytes
f0b07c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import os
import threading
from typing import Any
from flask import Flask

class ApiDocs:
    def __init__(self, webapp: Flask, lock: threading.Lock) -> None:
        self.webapp = webapp
        self.lock = lock

    async def process(self, data: dict[str, Any], request: Any) -> dict[str, Any]:
        endpoints = []
        for rule in self.webapp.url_map.iter_rules():
            if rule.rule.startswith("/api/"):
                methods = ",".join(m for m in rule.methods if m not in ["OPTIONS", "HEAD"])
                endpoints.append({
                    "path": rule.rule,
                    "methods": methods,
                    "endpoint": rule.endpoint
                })

        return {
            "title": "Agent-Zero API Documentation",
            "version": "1.0.0",
            "hf_space": os.getenv("HF_SPACE") == "true",
            "endpoints": endpoints
        }