File size: 4,081 Bytes
3a3bdee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from helpers.api import ApiHandler, Request, Response
import json

API_DOCS_PAYLOAD = {
    "title": "Open Operator API Documentation",
    "description": "API documentation for Open Operator (Agent Zero)",
    "endpoints": [
        {
            "path": "/health",
            "method": "GET",
            "purpose": "Health check endpoint for Hugging Face Spaces status probe",
            "request": {},
            "response": {"status": "ok"}
        },
        {
            "path": "/api-docs",
            "method": "GET",
            "purpose": "API documentation endpoint listing all endpoints",
            "request": {},
            "response": {"title": "Open Operator API Documentation", "endpoints": "..."}
        },
        {
            "path": "/api/health",
            "method": "GET",
            "purpose": "System health and git status details",
            "request": {},
            "response": {"gitinfo": {"version": "v1.6", "commit_time": "2026-01-01 00:00:00"}, "error": None}
        },
        {
            "path": "/api/message",
            "method": "POST",
            "purpose": "Send a synchronous message to the agent context",
            "request": {"message": "Hello agent", "context_id": "default"},
            "response": {"response": "Agent reply text"}
        },
        {
            "path": "/api/message_async",
            "method": "POST",
            "purpose": "Send an asynchronous message to the agent context",
            "request": {"message": "Hello agent", "context_id": "default"},
            "response": {"status": "queued"}
        },
        {
            "path": "/api/settings_get",
            "method": "GET",
            "purpose": "Retrieve runtime and user settings",
            "request": {},
            "response": {"settings": {"chat_model": "gpt-4o"}}
        },
        {
            "path": "/api/settings_set",
            "method": "POST",
            "purpose": "Update runtime and user settings",
            "request": {"settings": {"timezone": "UTC"}},
            "response": {"success": True}
        },
        {
            "path": "/api/chat_create",
            "method": "POST",
            "purpose": "Create a new chat context session",
            "request": {"name": "New Chat"},
            "response": {"context_id": "abc-123"}
        },
        {
            "path": "/api/chat_remove",
            "method": "POST",
            "purpose": "Remove a chat context session",
            "request": {"context_id": "abc-123"},
            "response": {"success": True}
        },
        {
            "path": "/api/chat_load",
            "method": "POST",
            "purpose": "Load history for a specific chat context",
            "request": {"context_id": "abc-123"},
            "response": {"history": []}
        },
        {
            "path": "/api/chat_reset",
            "method": "POST",
            "purpose": "Reset messages in a chat context",
            "request": {"context_id": "abc-123"},
            "response": {"success": True}
        },
        {
            "path": "/api/history_get",
            "method": "GET",
            "purpose": "Retrieve history for active context",
            "request": {},
            "response": {"history": []}
        },
        {
            "path": "/api/upload",
            "method": "POST",
            "purpose": "Upload file to context work directory",
            "request": {"file": "binary data"},
            "response": {"filename": "example.txt", "path": "/a0/usr/workdir/example.txt"}
        }
    ]
}

class ApiDocs(ApiHandler):

    @classmethod
    def requires_auth(cls) -> bool:
        return False

    @classmethod
    def requires_csrf(cls) -> bool:
        return False

    @classmethod
    def get_methods(cls) -> list[str]:
        return ["GET"]

    async def process(self, input: dict, request: Request) -> dict | Response:
        return Response(
            response=json.dumps(API_DOCS_PAYLOAD, indent=2),
            status=200,
            mimetype="application/json"
        )