appsocom 0.9.0__tar.gz → 0.10.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {appsocom-0.9.0 → appsocom-0.10.0}/PKG-INFO +1 -1
- {appsocom-0.9.0 → appsocom-0.10.0}/appsocom/__init__.py +52 -3
- {appsocom-0.9.0 → appsocom-0.10.0}/appsocom.egg-info/PKG-INFO +1 -1
- {appsocom-0.9.0 → appsocom-0.10.0}/pyproject.toml +1 -1
- {appsocom-0.9.0 → appsocom-0.10.0}/tests/test_sfukit.py +13 -0
- {appsocom-0.9.0 → appsocom-0.10.0}/LICENSE +0 -0
- {appsocom-0.9.0 → appsocom-0.10.0}/README.md +0 -0
- {appsocom-0.9.0 → appsocom-0.10.0}/appsocom.egg-info/SOURCES.txt +0 -0
- {appsocom-0.9.0 → appsocom-0.10.0}/appsocom.egg-info/dependency_links.txt +0 -0
- {appsocom-0.9.0 → appsocom-0.10.0}/appsocom.egg-info/top_level.txt +0 -0
- {appsocom-0.9.0 → appsocom-0.10.0}/setup.cfg +0 -0
|
@@ -31,7 +31,7 @@ __all__ = [
|
|
|
31
31
|
"assistant_tools",
|
|
32
32
|
"verify_assistant_tool_call",
|
|
33
33
|
]
|
|
34
|
-
__version__ = "0.
|
|
34
|
+
__version__ = "0.10.0"
|
|
35
35
|
|
|
36
36
|
SIGNATURE_HEADER = "X-SfuKit-Signature"
|
|
37
37
|
_ID = re.compile(r"^[A-Za-z0-9._:@-]{1,128}$")
|
|
@@ -138,6 +138,15 @@ class AiStream:
|
|
|
138
138
|
self.close()
|
|
139
139
|
|
|
140
140
|
|
|
141
|
+
def route_of(path: str) -> str:
|
|
142
|
+
""""/rooms/maths-7b/participants/u1" -> "/rooms/:id/participants/:id": IDs never leave in a report."""
|
|
143
|
+
segs = path.split("?")[0].split("/")
|
|
144
|
+
return "/".join(
|
|
145
|
+
s if i == 0 or (i % 2 == 1 and len(s) <= 20 and re.fullmatch(r"[a-z]+(-[a-z]+)*", s)) else ":id"
|
|
146
|
+
for i, s in enumerate(segs)
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
|
|
141
150
|
class SfuKit:
|
|
142
151
|
"""Admin client for one sfukit deployment.
|
|
143
152
|
|
|
@@ -146,7 +155,7 @@ class SfuKit:
|
|
|
146
155
|
jwt_secret: the deployment's JWT_SECRET; when set, create_token() signs locally
|
|
147
156
|
"""
|
|
148
157
|
|
|
149
|
-
def __init__(self, url: str, admin_key: str, jwt_secret: Optional[str] = None, timeout: float = 10.0):
|
|
158
|
+
def __init__(self, url: str, admin_key: str, jwt_secret: Optional[str] = None, timeout: float = 10.0, report_errors: bool = True):
|
|
150
159
|
if not url:
|
|
151
160
|
raise ValueError("url is required")
|
|
152
161
|
if not admin_key:
|
|
@@ -155,6 +164,9 @@ class SfuKit:
|
|
|
155
164
|
self._admin_key = admin_key
|
|
156
165
|
self._jwt_secret = jwt_secret
|
|
157
166
|
self.timeout = timeout
|
|
167
|
+
# Server errors (5xx) are reported to the Appsocom Live team, once per route every 10 minutes.
|
|
168
|
+
self.report_errors = report_errors
|
|
169
|
+
self._reported: Dict[str, float] = {}
|
|
158
170
|
|
|
159
171
|
# ---------- tokens ----------
|
|
160
172
|
|
|
@@ -174,6 +186,20 @@ class SfuKit:
|
|
|
174
186
|
body[names.get(k, k)] = v
|
|
175
187
|
return self.request("POST", "/tokens", body)
|
|
176
188
|
|
|
189
|
+
# ---------- feedback for the Appsocom team ----------
|
|
190
|
+
|
|
191
|
+
def send_feedback(self, title: str, message: str = "", kind: str = "issue", **report: Any) -> Dict[str, Any]:
|
|
192
|
+
"""Send a recommendation, issue or error report to the Appsocom Live team (POST /feedback).
|
|
193
|
+
|
|
194
|
+
kind: recommendation, issue, error, question or praise. Optional: severity (low, normal,
|
|
195
|
+
high, critical), area (e.g. "tokens", "ai-agent"), error ({"message", "code", "status"}),
|
|
196
|
+
reporter ({"type": "agent" | "app", "name"}), context (short fields). Keys, tokens and
|
|
197
|
+
email addresses are taken out on the server. Returns {"id", "received", "duplicate"}.
|
|
198
|
+
"""
|
|
199
|
+
body: Dict[str, Any] = {"sdk": {"name": "appsocom-python", "version": __version__}, "kind": kind, "title": title, "message": message}
|
|
200
|
+
body.update(report)
|
|
201
|
+
return self.request("POST", "/feedback", body)
|
|
202
|
+
|
|
177
203
|
# ---------- rooms ----------
|
|
178
204
|
|
|
179
205
|
def get_room(self, room_id: str) -> Dict[str, Any]:
|
|
@@ -839,6 +865,26 @@ class SfuKit:
|
|
|
839
865
|
raise _http_error("video upload", e) from None
|
|
840
866
|
return json.loads(text) if text else None
|
|
841
867
|
|
|
868
|
+
def _report_server_error(self, method: str, path: str, status: int, message: str) -> None:
|
|
869
|
+
route = route_of(path)
|
|
870
|
+
if not self.report_errors or route == "/feedback":
|
|
871
|
+
return
|
|
872
|
+
key = f"{method} {route} {status}"
|
|
873
|
+
now = time.time()
|
|
874
|
+
if now - self._reported.get(key, 0) < 600:
|
|
875
|
+
return
|
|
876
|
+
self._reported[key] = now
|
|
877
|
+
message = message.replace(path.split("?")[0], route)
|
|
878
|
+
try:
|
|
879
|
+
self.request("POST", "/feedback", {
|
|
880
|
+
"sdk": {"name": "appsocom-python", "version": __version__},
|
|
881
|
+
"kind": "error", "area": "api", "title": f"{status} on {method} {route}",
|
|
882
|
+
"error": {"status": status, "message": message[:300]},
|
|
883
|
+
"reporter": {"type": "app"}, "context": {"endpoint": f"{method} {route}", "automatic": True},
|
|
884
|
+
}, timeout=3)
|
|
885
|
+
except Exception:
|
|
886
|
+
pass
|
|
887
|
+
|
|
842
888
|
def request(
|
|
843
889
|
self,
|
|
844
890
|
method: str,
|
|
@@ -865,7 +911,10 @@ class SfuKit:
|
|
|
865
911
|
return data_out
|
|
866
912
|
text = data_out.decode("utf-8")
|
|
867
913
|
except urllib.error.HTTPError as e:
|
|
868
|
-
|
|
914
|
+
err = _http_error(f"{method} {path}", e)
|
|
915
|
+
if e.code >= 500:
|
|
916
|
+
self._report_server_error(method, path, e.code, str(err))
|
|
917
|
+
raise err from None
|
|
869
918
|
if raw:
|
|
870
919
|
return text
|
|
871
920
|
return json.loads(text) if text else None
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "appsocom"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.10.0"
|
|
8
8
|
description = "Python server SDK for Appsocom Live video calls: join tokens, rooms, moderation and webhook verification"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
@@ -87,6 +87,10 @@ class Handler(BaseHTTPRequestHandler):
|
|
|
87
87
|
self.send_response(204)
|
|
88
88
|
self.end_headers()
|
|
89
89
|
return
|
|
90
|
+
elif self.path.startswith("/rooms/broken"):
|
|
91
|
+
out, code = {"error": "internal error"}, 500
|
|
92
|
+
elif self.path == "/feedback":
|
|
93
|
+
out, code = {"id": "fb_1", "received": True}, 201
|
|
90
94
|
elif self.path.startswith("/rooms/missing"):
|
|
91
95
|
out, code = {"error": "nope"}, 404
|
|
92
96
|
elif self.command == "PATCH" and "/participants/" in self.path:
|
|
@@ -160,6 +164,15 @@ class AdminTests(unittest.TestCase):
|
|
|
160
164
|
kit.delete_presentation_link("pl_1")
|
|
161
165
|
self.assertEqual(Handler.seen[-1][:2], ("DELETE", "/presentation-links/pl_1"))
|
|
162
166
|
|
|
167
|
+
def test_server_errors_are_reported_once(self):
|
|
168
|
+
for _ in range(2):
|
|
169
|
+
with self.assertRaises(SfuKitError):
|
|
170
|
+
self.kit.get_room("broken-1")
|
|
171
|
+
reports = [s for s in Handler.seen if s[1] == "/feedback"]
|
|
172
|
+
self.assertEqual(len(reports), 1)
|
|
173
|
+
self.assertEqual(reports[0][3]["title"], "500 on GET /rooms/:id")
|
|
174
|
+
self.assertNotIn("broken-1", json.dumps(reports[0][3]))
|
|
175
|
+
|
|
163
176
|
def test_errors(self):
|
|
164
177
|
with self.assertRaises(SfuKitError) as e:
|
|
165
178
|
self.kit.get_room("missing")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|