-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_bridge_call.py
More file actions
40 lines (31 loc) · 1.04 KB
/
Copy path_bridge_call.py
File metadata and controls
40 lines (31 loc) · 1.04 KB
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
"""Tiny CLI bridge: call a server tool by name with JSON kwargs.
Usage: python _bridge_call.py <tool_name> '<json-kwargs>'
Requires CODEBERG_ACCOUNTS in the environment (see .env.example).
"""
import asyncio
import json
import os
import sys
import httpx
import server
tool = sys.argv[1]
kwargs = json.loads(sys.argv[2])
# Only allow calling public tool functions (not private/internal helpers).
if tool.startswith("_") or not callable(getattr(server, tool, None)):
raise SystemExit(f"unknown or non-callable tool: {tool!r}")
fn = getattr(server, tool)
server._accounts = json.loads(os.environ["CODEBERG_ACCOUNTS"])
server._default_account = os.environ.get("CODEBERG_DEFAULT_ACCOUNT") or next(
iter(server._accounts)
)
async def main():
server._client = httpx.AsyncClient(
base_url=server.BASE_URL,
headers={"Content-Type": "application/json", "Accept": "application/json"},
timeout=20,
)
try:
print(json.dumps(await fn(**kwargs)))
finally:
await server._client.aclose()
asyncio.run(main())