-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
104 lines (84 loc) · 2.89 KB
/
setup.py
File metadata and controls
104 lines (84 loc) · 2.89 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
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
"""One-time setup: register the support ticket demo app with the broker.
Usage:
docker compose up -d
uv run python demo2/setup.py
"""
from __future__ import annotations
import os
import sys
import httpx
BROKER_URL = os.environ.get("AGENTWRIT_BROKER_URL", "http://localhost:8080")
ADMIN_SECRET = os.environ.get("AGENTWRIT_ADMIN_SECRET", "")
APP_SCOPE_CEILING = [
"read:tickets:*",
"read:customers:*",
"write:customers:*",
"read:kb:*",
"read:billing:*",
"write:billing:*",
"write:notes:*",
"write:email:internal",
"delete:account:*",
]
def main() -> None:
if not ADMIN_SECRET:
print("ERROR: Set AGENTWRIT_ADMIN_SECRET environment variable")
sys.exit(1)
print(f"Broker: {BROKER_URL}")
# Health check
try:
health = httpx.get(f"{BROKER_URL}/v1/health", timeout=5)
health.raise_for_status()
h = health.json()
print(f"Broker status: {h['status']} (v{h['version']}, uptime {h['uptime']}s)")
except Exception as e:
print(f"ERROR: Cannot reach broker at {BROKER_URL}: {e}")
sys.exit(1)
# Authenticate as admin
print("\nAuthenticating as admin...")
auth_resp = httpx.post(
f"{BROKER_URL}/v1/admin/auth",
json={"secret": ADMIN_SECRET},
timeout=10,
)
if auth_resp.status_code != 200:
print(f"ERROR: Admin auth failed ({auth_resp.status_code}): {auth_resp.text}")
sys.exit(1)
admin_token = auth_resp.json()["access_token"]
print("Admin authenticated.")
# Register the demo app
print("\nRegistering support ticket demo app with scope ceiling:")
for scope in APP_SCOPE_CEILING:
print(f" - {scope}")
app_resp = httpx.post(
f"{BROKER_URL}/v1/admin/apps",
json={
"name": "support-ticket-demo",
"scopes": APP_SCOPE_CEILING,
"token_ttl": 1800,
},
headers={"Authorization": f"Bearer {admin_token}"},
timeout=10,
)
if app_resp.status_code not in (200, 201):
print(f"ERROR: App registration failed ({app_resp.status_code}): {app_resp.text}")
sys.exit(1)
app_data = app_resp.json()
print("\nApp registered successfully!")
print(f" app_id: {app_data['app_id']}")
print(f" client_id: {app_data['client_id']}")
print(f" client_secret: {app_data['client_secret']}")
print(f" scopes: {app_data['scopes']}")
print(f"\n{'='*60}")
print("Add these to demo2/.env:")
print(f"{'='*60}")
print(f"AGENTWRIT_BROKER_URL={BROKER_URL}")
print(f"AGENTWRIT_CLIENT_ID={app_data['client_id']}")
print(f"AGENTWRIT_CLIENT_SECRET={app_data['client_secret']}")
print(f"AGENTWRIT_ADMIN_SECRET={ADMIN_SECRET}")
print("LLM_BASE_URL=<your-llm-base-url>")
print("LLM_API_KEY=<your-api-key>")
print("LLM_MODEL=<your-model>")
print(f"{'='*60}")
if __name__ == "__main__":
main()