Skip to content

Commit 644a412

Browse files
committed
fixed nasty bug caused by the fact that in Lambdas we are using pydantic 1.x which is missing the model_dump method
major improvments to Admin UI added lots of docs to admin section
1 parent 63fcfa7 commit 644a412

21 files changed

Lines changed: 4309 additions & 147 deletions

osbot_fast_api/admin_ui/api/routes/Routes__Admin__Cookies.py

Lines changed: 87 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import json
12
from typing import Dict, Any, List, Optional
3+
import osbot_fast_api
24
from fastapi import Request, Response
5+
from osbot_utils.utils.Files import path_combine, file_exists
36
from osbot_fast_api.api.routes.Fast_API__Routes import Fast_API__Routes
47
from osbot_utils.type_safe.Type_Safe import Type_Safe
58
from osbot_utils.utils.Misc import random_guid
@@ -32,77 +35,90 @@ class Cookies__Templates(Type_Safe):
3235

3336
class Routes__Admin__Cookies(Fast_API__Routes): # API routes for cookie management
3437
tag = 'admin-cookies'
35-
parent_app = None # Will be set by Admin_UI__Fast_API
36-
37-
# Predefined cookie templates
38-
COOKIE_TEMPLATES = [ # todo: move to .json file which can then be changed by the multiple implementations (especialy since by default we should not have have all this cookies set in the main Fast_API package)
39-
{
40-
"id": "openai",
41-
"name": "OpenAI Configuration",
42-
"description": "Cookies for OpenAI API integration",
43-
"cookies": [
44-
{
45-
"name": "openai-api-key",
46-
"description": "OpenAI API Key",
47-
"required": True,
48-
"category": "llm",
49-
"validator": "^sk-[a-zA-Z0-9]{48}$"
50-
},
51-
{
52-
"name": "openai-org-id",
53-
"description": "OpenAI Organization ID",
54-
"required": False,
55-
"category": "llm"
56-
}
57-
]
58-
},
59-
{
60-
"id": "anthropic",
61-
"name": "Anthropic Configuration",
62-
"description": "Cookies for Anthropic Claude API",
63-
"cookies": [
64-
{
65-
"name": "anthropic-api-key",
66-
"description": "Anthropic API Key",
67-
"required": True,
68-
"category": "llm",
69-
"validator": "^sk-ant-[a-zA-Z0-9-]{95}$"
70-
}
71-
]
72-
},
73-
{
74-
"id": "groq",
75-
"name": "Groq Configuration",
76-
"description": "Cookies for Groq API",
77-
"cookies": [
78-
{
79-
"name": "groq-api-key",
80-
"description": "Groq API Key",
81-
"required": True,
82-
"category": "llm"
83-
}
84-
]
85-
},
86-
{
87-
"id": "auth",
88-
"name": "Authentication",
89-
"description": "Authentication cookies",
90-
"cookies": [
91-
{
92-
"name": "auth-token",
93-
"description": "Authentication token",
94-
"required": False,
95-
"category": "auth"
96-
},
97-
{
98-
"name": "api-key",
99-
"description": "API Key for protected endpoints",
100-
"required": False,
101-
"category": "auth"
102-
}
103-
]
104-
}
105-
]
38+
parent_app = None # Will be set by Admin_UI__Fast_API
39+
_templates : list = None
40+
41+
@property
42+
def COOKIE_TEMPLATES(self):
43+
if self._templates is None:
44+
template_path = path_combine(osbot_fast_api.path, 'admin_ui/content/templates/cookies.json')
45+
if file_exists(template_path):
46+
with open(template_path, 'r') as f:
47+
data = json.load(f)
48+
self._templates = data.get('templates', [])
49+
else:
50+
self._templates = [] # Fallback to empty
51+
return self._templates
52+
53+
# # Predefined cookie templates
54+
# COOKIE_TEMPLATES = [ # todo: move to .json file which can then be changed by the multiple implementations (especialy since by default we should not have have all this cookies set in the main Fast_API package)
55+
# {
56+
# "id": "openai",
57+
# "name": "OpenAI Configuration",
58+
# "description": "Cookies for OpenAI API integration",
59+
# "cookies": [
60+
# {
61+
# "name": "openai-api-key",
62+
# "description": "OpenAI API Key",
63+
# "required": True,
64+
# "category": "llm",
65+
# "validator": "^sk-[a-zA-Z0-9]{48}$"
66+
# },
67+
# {
68+
# "name": "openai-org-id",
69+
# "description": "OpenAI Organization ID",
70+
# "required": False,
71+
# "category": "llm"
72+
# }
73+
# ]
74+
# },
75+
# {
76+
# "id": "anthropic",
77+
# "name": "Anthropic Configuration",
78+
# "description": "Cookies for Anthropic Claude API",
79+
# "cookies": [
80+
# {
81+
# "name": "anthropic-api-key",
82+
# "description": "Anthropic API Key",
83+
# "required": True,
84+
# "category": "llm",
85+
# "validator": "^sk-ant-[a-zA-Z0-9-]{95}$"
86+
# }
87+
# ]
88+
# },
89+
# {
90+
# "id": "groq",
91+
# "name": "Groq Configuration",
92+
# "description": "Cookies for Groq API",
93+
# "cookies": [
94+
# {
95+
# "name": "groq-api-key",
96+
# "description": "Groq API Key",
97+
# "required": True,
98+
# "category": "llm"
99+
# }
100+
# ]
101+
# },
102+
# {
103+
# "id": "auth",
104+
# "name": "Authentication",
105+
# "description": "Authentication cookies",
106+
# "cookies": [
107+
# {
108+
# "name": "auth-token",
109+
# "description": "Authentication token",
110+
# "required": False,
111+
# "category": "auth"
112+
# },
113+
# {
114+
# "name": "api-key",
115+
# "description": "API Key for protected endpoints",
116+
# "required": False,
117+
# "category": "auth"
118+
# }
119+
# ]
120+
# }
121+
# ]
106122

107123
def api__cookies_list(self, request: Request) -> List[Dict[str, Any]]: # Get list of all cookies with their current values
108124
cookies = []

osbot_fast_api/admin_ui/api/routes/Routes__Admin__Docs.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
import json
12
from typing import Dict, Any, List
3+
4+
import osbot_fast_api
5+
from osbot_utils.utils.Files import path_combine, file_exists
6+
27
from osbot_fast_api.api.routes.Fast_API__Routes import Fast_API__Routes
38

49

@@ -153,7 +158,41 @@ def _extract_tags(self, openapi: Dict) -> List[Dict[str, Any]]:
153158

154159
return list(tags.values())
155160

161+
def api__content__doc_id(self, doc_id: str) -> Dict[str, Any]: # Serve documentation content from markdown/JSON files
162+
163+
# Map doc_id to content files
164+
content_path = path_combine(osbot_fast_api.path, f'admin_ui/content/docs/{doc_id}.md')
165+
json_path = path_combine(osbot_fast_api.path, f'admin_ui/content/docs/{doc_id}.json')
166+
167+
# Try markdown first
168+
if file_exists(content_path):
169+
with open(content_path, 'r', encoding='utf-8') as f: # Add encoding
170+
content = f.read()
171+
return {
172+
"markdown": content,
173+
"format": "markdown",
174+
"doc_id": doc_id
175+
}
176+
177+
# Try JSON
178+
elif file_exists(json_path):
179+
with open(json_path, 'r', encoding='utf-8') as f: # Add encoding
180+
data = json.load(f)
181+
return {
182+
"sections": data.get("sections", []),
183+
"format": "json",
184+
"doc_id": doc_id
185+
}
186+
187+
# Return error (not default content - let frontend handle it)
188+
return {
189+
"error": "Content not found",
190+
"doc_id": doc_id,
191+
"format": "error"
192+
}
193+
156194
def setup_routes(self):
157195
self.add_route_get(self.api__docs_endpoints)
158196
self.add_route_get(self.api__client_examples)
159-
self.add_route_get(self.api__api_info)
197+
self.add_route_get(self.api__api_info)
198+
self.add_route_get(self.api__content__doc_id)

osbot_fast_api/admin_ui/api/testing/Admin_UI__Test_Objs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ def setup__admin_ui_test_objs(with_parent=True, with_server=False):
6363
version = 'v1.0.99' ,
6464
description = 'Parent API for Admin UI testing',
6565
enable_api_key = False , # Disable for tests
66-
enable_cors = True )
66+
enable_cors = True ,
67+
add_admin_ui = True )
6768
test_objs.parent_fast_api.setup()
6869

6970
# Add some test routes to parent

0 commit comments

Comments
 (0)