chore: format
This commit is contained in:
@@ -695,7 +695,9 @@ async def lifespan(app: FastAPI):
|
||||
log.info(f"Initialized {len(app.state.TOOL_SERVERS)} tool server(s)")
|
||||
|
||||
await set_terminal_servers(mock_request)
|
||||
log.info(f"Initialized {len(app.state.TERMINAL_SERVERS)} terminal server(s)")
|
||||
log.info(
|
||||
f"Initialized {len(app.state.TERMINAL_SERVERS)} terminal server(s)"
|
||||
)
|
||||
except Exception as e:
|
||||
log.warning(f"Failed to initialize tool/terminal servers at startup: {e}")
|
||||
|
||||
@@ -2220,7 +2222,6 @@ async def get_app_config(request: Request):
|
||||
"pending_user_overlay_content": app.state.config.PENDING_USER_OVERLAY_CONTENT,
|
||||
"response_watermark": app.state.config.RESPONSE_WATERMARK,
|
||||
},
|
||||
|
||||
"license_metadata": app.state.LICENSE_METADATA,
|
||||
**(
|
||||
{
|
||||
|
||||
@@ -33,9 +33,14 @@ async def list_terminal_servers(request: Request, user=Depends(get_verified_user
|
||||
user_group_ids = {group.id for group in Groups.get_groups_by_member_id(user.id)}
|
||||
|
||||
return [
|
||||
{"id": connection.get("id", ""), "url": connection.get("url", ""), "name": connection.get("name", "")}
|
||||
{
|
||||
"id": connection.get("id", ""),
|
||||
"url": connection.get("url", ""),
|
||||
"name": connection.get("name", ""),
|
||||
}
|
||||
for connection in connections
|
||||
if connection.get("enabled", True) and has_connection_access(user, connection, user_group_ids)
|
||||
if connection.get("enabled", True)
|
||||
and has_connection_access(user, connection, user_group_ids)
|
||||
]
|
||||
|
||||
|
||||
@@ -54,7 +59,9 @@ async def proxy_terminal(
|
||||
connection = next((c for c in connections if c.get("id") == server_id), None)
|
||||
|
||||
if connection is None:
|
||||
return JSONResponse({"error": f"Terminal server '{server_id}' not found"}, status_code=404)
|
||||
return JSONResponse(
|
||||
{"error": f"Terminal server '{server_id}' not found"}, status_code=404
|
||||
)
|
||||
|
||||
user_group_ids = {group.id for group in Groups.get_groups_by_member_id(user.id)}
|
||||
if not has_connection_access(user, connection, user_group_ids):
|
||||
@@ -62,7 +69,9 @@ async def proxy_terminal(
|
||||
|
||||
base_url = (connection.get("url") or "").rstrip("/")
|
||||
if not base_url:
|
||||
return JSONResponse({"error": "Terminal server URL not configured"}, status_code=503)
|
||||
return JSONResponse(
|
||||
{"error": "Terminal server URL not configured"}, status_code=503
|
||||
)
|
||||
|
||||
target_url = f"{base_url}/{path}"
|
||||
if request.query_params:
|
||||
@@ -112,6 +121,7 @@ async def proxy_terminal(
|
||||
|
||||
# Stream binary responses directly
|
||||
if any(t in upstream_content_type for t in STREAMING_CONTENT_TYPES):
|
||||
|
||||
async def cleanup():
|
||||
await upstream_response.release()
|
||||
await session.close()
|
||||
@@ -129,9 +139,13 @@ async def proxy_terminal(
|
||||
await upstream_response.release()
|
||||
await session.close()
|
||||
|
||||
return Response(content=response_body, status_code=status_code, headers=filtered_headers)
|
||||
return Response(
|
||||
content=response_body, status_code=status_code, headers=filtered_headers
|
||||
)
|
||||
|
||||
except Exception as error:
|
||||
await session.close()
|
||||
log.exception("Terminal proxy error: %s", error)
|
||||
return JSONResponse({"error": f"Terminal proxy error: {error}"}, status_code=502)
|
||||
return JSONResponse(
|
||||
{"error": f"Terminal proxy error: {error}"}, status_code=502
|
||||
)
|
||||
|
||||
@@ -930,10 +930,9 @@ def process_tool_result(
|
||||
else:
|
||||
tool_result = tool_result.body.decode("utf-8", "replace")
|
||||
|
||||
elif (
|
||||
tool_type in EXTERNAL_TOOL_TYPES
|
||||
and isinstance(tool_result, tuple)
|
||||
) or (direct_tool and isinstance(tool_result, list) and len(tool_result) == 2):
|
||||
elif (tool_type in EXTERNAL_TOOL_TYPES and isinstance(tool_result, tuple)) or (
|
||||
direct_tool and isinstance(tool_result, list) and len(tool_result) == 2
|
||||
):
|
||||
tool_result, tool_response_headers = tool_result
|
||||
|
||||
try:
|
||||
@@ -1232,7 +1231,10 @@ async def chat_completion_tools_handler(
|
||||
|
||||
if event_emitter:
|
||||
await display_file_handler(
|
||||
tool_function_name, tool_function_params, tool_result, event_emitter
|
||||
tool_function_name,
|
||||
tool_function_params,
|
||||
tool_result,
|
||||
event_emitter,
|
||||
)
|
||||
|
||||
if tool_result_files:
|
||||
@@ -4223,7 +4225,10 @@ async def streaming_chat_response_handler(response, ctx):
|
||||
)
|
||||
|
||||
await display_file_handler(
|
||||
tool_function_name, tool_function_params, tool_result, event_emitter
|
||||
tool_function_name,
|
||||
tool_function_params,
|
||||
tool_result,
|
||||
event_emitter,
|
||||
)
|
||||
|
||||
# Extract citation sources from tool results
|
||||
@@ -4408,8 +4413,7 @@ async def streaming_chat_response_handler(response, ctx):
|
||||
code = sanitize_code(code)
|
||||
|
||||
if CODE_INTERPRETER_BLOCKED_MODULES:
|
||||
blocking_code = textwrap.dedent(
|
||||
f"""
|
||||
blocking_code = textwrap.dedent(f"""
|
||||
import builtins
|
||||
|
||||
BLOCKED_MODULES = {CODE_INTERPRETER_BLOCKED_MODULES}
|
||||
@@ -4425,8 +4429,7 @@ async def streaming_chat_response_handler(response, ctx):
|
||||
return _real_import(name, globals, locals, fromlist, level)
|
||||
|
||||
builtins.__import__ = restricted_import
|
||||
"""
|
||||
)
|
||||
""")
|
||||
code = blocking_code + "\n" + code
|
||||
|
||||
if (
|
||||
|
||||
@@ -144,8 +144,6 @@ def get_updated_tool_function(function: Callable, extra_params: dict):
|
||||
return function
|
||||
|
||||
|
||||
|
||||
|
||||
async def get_tools(
|
||||
request: Request, tool_ids: list[str], user: UserModel, extra_params: dict
|
||||
) -> dict[str, dict]:
|
||||
@@ -909,19 +907,21 @@ async def set_terminal_servers(request: Request):
|
||||
|
||||
enabled = connection.get("enabled", True)
|
||||
|
||||
server_configs.append({
|
||||
"url": connection.get("url", ""),
|
||||
"key": connection.get("key", ""),
|
||||
"auth_type": connection.get("auth_type", "bearer"),
|
||||
"path": connection.get("path", "/openapi.json"),
|
||||
"spec_type": "url",
|
||||
# get_tool_servers_data reads config.enable to filter active servers
|
||||
"config": {"enable": enabled},
|
||||
"info": {
|
||||
"id": connection.get("id", ""),
|
||||
"name": connection.get("name", ""),
|
||||
},
|
||||
})
|
||||
server_configs.append(
|
||||
{
|
||||
"url": connection.get("url", ""),
|
||||
"key": connection.get("key", ""),
|
||||
"auth_type": connection.get("auth_type", "bearer"),
|
||||
"path": connection.get("path", "/openapi.json"),
|
||||
"spec_type": "url",
|
||||
# get_tool_servers_data reads config.enable to filter active servers
|
||||
"config": {"enable": enabled},
|
||||
"info": {
|
||||
"id": connection.get("id", ""),
|
||||
"name": connection.get("name", ""),
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
request.app.state.TERMINAL_SERVERS = await get_tool_servers_data(server_configs)
|
||||
|
||||
@@ -965,9 +965,7 @@ async def get_terminal_tools(
|
||||
- Builds callables that route through the terminal proxy
|
||||
"""
|
||||
connections = request.app.state.config.TERMINAL_SERVER_CONNECTIONS or []
|
||||
connection = next(
|
||||
(c for c in connections if c.get("id") == terminal_id), None
|
||||
)
|
||||
connection = next((c for c in connections if c.get("id") == terminal_id), None)
|
||||
if connection is None:
|
||||
log.warning(f"Terminal server not found: {terminal_id}")
|
||||
return {}
|
||||
@@ -1007,9 +1005,7 @@ async def get_terminal_tools(
|
||||
headers["Authorization"] = f"Bearer {oauth_token.get('access_token', '')}"
|
||||
# auth_type == "none": no Authorization header
|
||||
|
||||
terminal_cwd = await get_terminal_cwd(
|
||||
connection.get("url", ""), headers, cookies
|
||||
)
|
||||
terminal_cwd = await get_terminal_cwd(connection.get("url", ""), headers, cookies)
|
||||
|
||||
tools_dict = {}
|
||||
for spec in specs:
|
||||
@@ -1033,6 +1029,7 @@ async def get_terminal_tools(
|
||||
params=kwargs,
|
||||
server_data=srv_data,
|
||||
)
|
||||
|
||||
return tool_function
|
||||
|
||||
tool_function = make_tool_function(function_name, server_data, headers, cookies)
|
||||
|
||||
Reference in New Issue
Block a user