botversion-sdk 2.2.2__tar.gz → 2.3.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.
Files changed (92) hide show
  1. botversion_sdk-2.3.0/PKG-INFO +84 -0
  2. botversion_sdk-2.3.0/README.md +42 -0
  3. botversion_sdk-2.3.0/botversion_sdk/__init__.py +19 -0
  4. {botversion_sdk-2.2.2/botversion_sdk → botversion_sdk-2.3.0/botversion_sdk/scanner_sdk}/__init__.py +1 -3
  5. botversion_sdk-2.3.0/botversion_sdk/scanner_sdk/bin/__init__.py +1 -0
  6. botversion_sdk-2.3.0/botversion_sdk/scanner_sdk/bin/scan_endpoints.py +114 -0
  7. {botversion_sdk-2.2.2/botversion_sdk → botversion_sdk-2.3.0/botversion_sdk/scanner_sdk}/client.py +1 -1
  8. {botversion_sdk-2.2.2/botversion_sdk → botversion_sdk-2.3.0/botversion_sdk/scanner_sdk}/interceptor.py +52 -17
  9. botversion_sdk-2.3.0/botversion_sdk/scanner_sdk/scan/__init__.py +2 -0
  10. botversion_sdk-2.3.0/botversion_sdk/scanner_sdk/scan/aiohttp.py +101 -0
  11. botversion_sdk-2.3.0/botversion_sdk/scanner_sdk/scan/bottle.py +136 -0
  12. botversion_sdk-2.3.0/botversion_sdk/scanner_sdk/scan/cherrypy.py +108 -0
  13. botversion_sdk-2.3.0/botversion_sdk/scanner_sdk/scan/common.py +144 -0
  14. botversion_sdk-2.3.0/botversion_sdk/scanner_sdk/scan/django.py +438 -0
  15. botversion_sdk-2.3.0/botversion_sdk/scanner_sdk/scan/django_static_bodies.py +1163 -0
  16. botversion_sdk-2.3.0/botversion_sdk/scanner_sdk/scan/django_static_urls.py +1341 -0
  17. botversion_sdk-2.3.0/botversion_sdk/scanner_sdk/scan/django_static_views.py +1073 -0
  18. botversion_sdk-2.3.0/botversion_sdk/scanner_sdk/scan/falcon.py +121 -0
  19. botversion_sdk-2.3.0/botversion_sdk/scanner_sdk/scan/fastapi.py +217 -0
  20. botversion_sdk-2.3.0/botversion_sdk/scanner_sdk/scan/fastapi_static.py +1292 -0
  21. botversion_sdk-2.3.0/botversion_sdk/scanner_sdk/scan/flask.py +1373 -0
  22. botversion_sdk-2.3.0/botversion_sdk/scanner_sdk/scan/multipart.py +229 -0
  23. botversion_sdk-2.3.0/botversion_sdk/scanner_sdk/scan/pyramid.py +120 -0
  24. botversion_sdk-2.3.0/botversion_sdk/scanner_sdk/scan/response_shapes.py +273 -0
  25. botversion_sdk-2.3.0/botversion_sdk/scanner_sdk/scan/sanic.py +63 -0
  26. botversion_sdk-2.3.0/botversion_sdk/scanner_sdk/scan/sanic_static.py +657 -0
  27. botversion_sdk-2.3.0/botversion_sdk/scanner_sdk/scan/starlette.py +50 -0
  28. botversion_sdk-2.3.0/botversion_sdk/scanner_sdk/scan/starlette_static.py +1286 -0
  29. botversion_sdk-2.3.0/botversion_sdk/scanner_sdk/scan/static_common.py +475 -0
  30. botversion_sdk-2.3.0/botversion_sdk/scanner_sdk/scan/tornado.py +133 -0
  31. botversion_sdk-2.3.0/botversion_sdk/scanner_sdk/scanner.py +116 -0
  32. botversion_sdk-2.3.0/botversion_sdk/undo/__init__.py +103 -0
  33. botversion_sdk-2.3.0/botversion_sdk/undo/__main__.py +4 -0
  34. botversion_sdk-2.3.0/botversion_sdk/undo/bin/__init__.py +1 -0
  35. botversion_sdk-2.3.0/botversion_sdk/undo/bin/scan.py +16 -0
  36. botversion_sdk-2.3.0/botversion_sdk/undo/lib/__init__.py +1 -0
  37. botversion_sdk-2.3.0/botversion_sdk/undo/lib/action_id.py +37 -0
  38. botversion_sdk-2.3.0/botversion_sdk/undo/lib/capture_guard.py +18 -0
  39. botversion_sdk-2.3.0/botversion_sdk/undo/lib/capture_mongo.py +205 -0
  40. botversion_sdk-2.3.0/botversion_sdk/undo/lib/capture_mssql.py +504 -0
  41. botversion_sdk-2.3.0/botversion_sdk/undo/lib/capture_mysql.py +485 -0
  42. botversion_sdk-2.3.0/botversion_sdk/undo/lib/capture_sql.py +546 -0
  43. botversion_sdk-2.3.0/botversion_sdk/undo/lib/capture_sqlite.py +527 -0
  44. botversion_sdk-2.3.0/botversion_sdk/undo/lib/gate.py +65 -0
  45. botversion_sdk-2.3.0/botversion_sdk/undo/lib/hooks/asyncpg.py +177 -0
  46. botversion_sdk-2.3.0/botversion_sdk/undo/lib/hooks/mongodb.py +62 -0
  47. botversion_sdk-2.3.0/botversion_sdk/undo/lib/hooks/mssql.py +139 -0
  48. botversion_sdk-2.3.0/botversion_sdk/undo/lib/hooks/mysql.py +112 -0
  49. botversion_sdk-2.3.0/botversion_sdk/undo/lib/hooks/psycopg.py +97 -0
  50. botversion_sdk-2.3.0/botversion_sdk/undo/lib/hooks/psycopg2.py +141 -0
  51. botversion_sdk-2.3.0/botversion_sdk/undo/lib/hooks/psycopg_async.py +96 -0
  52. botversion_sdk-2.3.0/botversion_sdk/undo/lib/hooks/sqlite.py +96 -0
  53. botversion_sdk-2.3.0/botversion_sdk/undo/lib/loader_watch.py +67 -0
  54. botversion_sdk-2.3.0/botversion_sdk/undo/lib/log.py +14 -0
  55. botversion_sdk-2.3.0/botversion_sdk/undo/lib/mssql_sql.py +156 -0
  56. botversion_sdk-2.3.0/botversion_sdk/undo/lib/mysql_sql.py +96 -0
  57. botversion_sdk-2.3.0/botversion_sdk/undo/lib/refuse.py +6 -0
  58. botversion_sdk-2.3.0/botversion_sdk/undo/lib/report.py +35 -0
  59. botversion_sdk-2.3.0/botversion_sdk/undo/lib/requester.py +33 -0
  60. botversion_sdk-2.3.0/botversion_sdk/undo/lib/scanner.py +92 -0
  61. botversion_sdk-2.3.0/botversion_sdk/undo/lib/setup_check.py +132 -0
  62. botversion_sdk-2.3.0/botversion_sdk/undo/lib/snapshot_crypto.py +112 -0
  63. botversion_sdk-2.3.0/botversion_sdk/undo/lib/snapshot_sql.py +23 -0
  64. botversion_sdk-2.3.0/botversion_sdk/undo/lib/snapshot_store.py +141 -0
  65. botversion_sdk-2.3.0/botversion_sdk/undo/lib/snapshot_store_mongo.py +95 -0
  66. botversion_sdk-2.3.0/botversion_sdk/undo/lib/sql_classify.py +175 -0
  67. botversion_sdk-2.3.0/botversion_sdk/undo/lib/sqlite_sql.py +262 -0
  68. botversion_sdk-2.3.0/botversion_sdk/undo/lib/steps.py +22 -0
  69. botversion_sdk-2.3.0/botversion_sdk/undo/lib/tagger.py +422 -0
  70. botversion_sdk-2.3.0/botversion_sdk/undo/lib/undo_mongo.py +134 -0
  71. botversion_sdk-2.3.0/botversion_sdk/undo/lib/undo_mssql.py +248 -0
  72. botversion_sdk-2.3.0/botversion_sdk/undo/lib/undo_mysql.py +216 -0
  73. botversion_sdk-2.3.0/botversion_sdk/undo/lib/undo_pg.py +244 -0
  74. botversion_sdk-2.3.0/botversion_sdk/undo/lib/undo_route.py +132 -0
  75. botversion_sdk-2.3.0/botversion_sdk/undo/lib/undo_sqlite.py +227 -0
  76. botversion_sdk-2.3.0/botversion_sdk/undo/register.py +5 -0
  77. botversion_sdk-2.3.0/botversion_sdk.egg-info/PKG-INFO +84 -0
  78. botversion_sdk-2.3.0/botversion_sdk.egg-info/SOURCES.txt +84 -0
  79. botversion_sdk-2.3.0/botversion_sdk.egg-info/entry_points.txt +3 -0
  80. {botversion_sdk-2.2.2 → botversion_sdk-2.3.0}/botversion_sdk.egg-info/requires.txt +8 -0
  81. {botversion_sdk-2.2.2 → botversion_sdk-2.3.0}/setup.py +9 -3
  82. botversion_sdk-2.2.2/PKG-INFO +0 -33
  83. botversion_sdk-2.2.2/botversion_sdk/bin/scan_endpoints.py +0 -59
  84. botversion_sdk-2.2.2/botversion_sdk/scanner.py +0 -2317
  85. botversion_sdk-2.2.2/botversion_sdk.egg-info/PKG-INFO +0 -33
  86. botversion_sdk-2.2.2/botversion_sdk.egg-info/SOURCES.txt +0 -14
  87. botversion_sdk-2.2.2/botversion_sdk.egg-info/entry_points.txt +0 -2
  88. {botversion_sdk-2.2.2/botversion_sdk/bin → botversion_sdk-2.3.0/botversion_sdk/undo/lib/hooks}/__init__.py +0 -0
  89. {botversion_sdk-2.2.2 → botversion_sdk-2.3.0}/botversion_sdk.egg-info/dependency_links.txt +0 -0
  90. {botversion_sdk-2.2.2 → botversion_sdk-2.3.0}/botversion_sdk.egg-info/top_level.txt +0 -0
  91. {botversion_sdk-2.2.2 → botversion_sdk-2.3.0}/pyproject.toml +0 -0
  92. {botversion_sdk-2.2.2 → botversion_sdk-2.3.0}/setup.cfg +0 -0
@@ -0,0 +1,84 @@
1
+ Metadata-Version: 2.4
2
+ Name: botversion-sdk
3
+ Version: 2.3.0
4
+ Summary: BotVersion SDK — automatically discover and register your API endpoints
5
+ Home-page: https://github.com/botversion/botversion-sdk-python
6
+ Author: BotVersion
7
+ Author-email: support@botversion.com
8
+ Keywords: botversion,api,sdk,fastapi,flask,django
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Topic :: Software Development :: Libraries
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+ Requires-Dist: python-dotenv>=1.0.0
17
+ Requires-Dist: cryptography
18
+ Requires-Dist: pglast
19
+ Requires-Dist: sqlglot
20
+ Provides-Extra: fastapi
21
+ Requires-Dist: fastapi; extra == "fastapi"
22
+ Requires-Dist: starlette; extra == "fastapi"
23
+ Provides-Extra: flask
24
+ Requires-Dist: flask; extra == "flask"
25
+ Provides-Extra: django
26
+ Requires-Dist: django; extra == "django"
27
+ Provides-Extra: undo
28
+ Requires-Dist: cryptography; extra == "undo"
29
+ Requires-Dist: pglast; extra == "undo"
30
+ Requires-Dist: sqlglot; extra == "undo"
31
+ Dynamic: author
32
+ Dynamic: author-email
33
+ Dynamic: classifier
34
+ Dynamic: description
35
+ Dynamic: description-content-type
36
+ Dynamic: home-page
37
+ Dynamic: keywords
38
+ Dynamic: provides-extra
39
+ Dynamic: requires-dist
40
+ Dynamic: requires-python
41
+ Dynamic: summary
42
+
43
+ \# BotVersion SDK (Python)
44
+
45
+
46
+
47
+ BotVersion adds a self-updating AI agent to your SaaS backend.
48
+
49
+
50
+
51
+ \## What it does
52
+
53
+
54
+
55
+ \- Scans your codebase and automatically discovers your API endpoints.
56
+
57
+ \- Keeps the endpoint list live, so new endpoints are detected automatically the first time they are called.
58
+
59
+ \- Lets an AI agent act on your app through its real, current API surface, with no manual endpoint maintenance.
60
+
61
+
62
+
63
+ \## Installation
64
+
65
+
66
+
67
+   pip install botversion-sdk
68
+
69
+
70
+
71
+ \## Quick start
72
+
73
+
74
+
75
+ Add the setup snippet to your backend entry file. See the documentation on your BotVersion dashboard for the exact snippet for your framework.
76
+
77
+
78
+
79
+ \## Support
80
+
81
+
82
+
83
+ For help, contact the BotVersion team through your dashboard.
84
+
@@ -0,0 +1,42 @@
1
+ \# BotVersion SDK (Python)
2
+
3
+
4
+
5
+ BotVersion adds a self-updating AI agent to your SaaS backend.
6
+
7
+
8
+
9
+ \## What it does
10
+
11
+
12
+
13
+ \- Scans your codebase and automatically discovers your API endpoints.
14
+
15
+ \- Keeps the endpoint list live, so new endpoints are detected automatically the first time they are called.
16
+
17
+ \- Lets an AI agent act on your app through its real, current API surface, with no manual endpoint maintenance.
18
+
19
+
20
+
21
+ \## Installation
22
+
23
+
24
+
25
+   pip install botversion-sdk
26
+
27
+
28
+
29
+ \## Quick start
30
+
31
+
32
+
33
+ Add the setup snippet to your backend entry file. See the documentation on your BotVersion dashboard for the exact snippet for your framework.
34
+
35
+
36
+
37
+ \## Support
38
+
39
+
40
+
41
+ For help, contact the BotVersion team through your dashboard.
42
+
@@ -0,0 +1,19 @@
1
+ # botversion_sdk/__init__.py
2
+ # Root entry point: the host app imports botversion_sdk and calls init().
3
+ # It starts the main SDK, and also the Undo SDK when undo=True is passed.
4
+ from .scanner_sdk import init as _scanner_init, get_endpoints, register_endpoint
5
+
6
+
7
+ def init(app=None, api_key=None, **options):
8
+ # undo is ON unless the host passes undo=False
9
+ undo_enabled = options.pop("undo", True) # Undo is on unless the host passes undo=False
10
+
11
+ # Undo goes first so its request tagger is in place before the main SDK attaches
12
+ if undo_enabled:
13
+ try:
14
+ from . import undo as _undo
15
+ _undo.init(api_key=api_key, quiet=not options.get("debug", False))
16
+ except Exception as e:
17
+ pass # Undo must never break the host app or the main SDK
18
+
19
+ _scanner_init(app, api_key=api_key, **options)
@@ -1,4 +1,4 @@
1
- # botversion-sdk-python/botversion-sdk/__init__.py
1
+ # botversion-sdk-python/botversion-sdk/scanner-sdk/__init__.py
2
2
  import sys
3
3
  import threading
4
4
  import builtins
@@ -152,8 +152,6 @@ def init(app=None, api_key=None, **options):
152
152
 
153
153
  if not framework:
154
154
  _initialized = False
155
- if debug:
156
- print("[botversion] No supported framework detected. SDK not initialized.")
157
155
  return
158
156
 
159
157
  _client = BotVersionClient({
@@ -0,0 +1 @@
1
+ # botversion-sdk-python/botversion-sdk/scanner-sdk/bin/__init__.py
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env python
2
+ """
3
+ Build-time backend endpoint scanner. Run this as part of your deploy
4
+ pipeline (Procfile 'release' step, build.sh, or Dockerfile RUN step) so
5
+ endpoints are reported even on serverless platforms where the live
6
+ interceptor's scan-trigger route may not be reachable.
7
+ """
8
+ import json
9
+ import os
10
+ import sys
11
+
12
+ from botversion_sdk.scanner_sdk.client import BotVersionClient
13
+ from botversion_sdk.scanner_sdk.scanner import scan_routes_static, detect_framework_from_deps
14
+
15
+ # Debug output is only printed when BOTVERSION_DEBUG=1 (keeps customer builds quiet)
16
+ DEBUG = os.environ.get("BOTVERSION_DEBUG") == "1"
17
+
18
+
19
+ def dlog(*args):
20
+ if DEBUG:
21
+ print(*args)
22
+
23
+
24
+ def field_list(schema):
25
+ # Turns a schema into a short "name:type, name:type" line for easy reading
26
+ if not schema or not isinstance(schema, dict) or not schema.get("properties"):
27
+ return "-"
28
+ parts = []
29
+ for name, prop in schema["properties"].items():
30
+ if isinstance(prop, dict) and prop.get("format") == "binary":
31
+ kind = "file"
32
+ elif isinstance(prop, dict):
33
+ kind = prop.get("type", "?")
34
+ else:
35
+ kind = "?"
36
+ parts.append(f"{name}:{kind}")
37
+ line = ", ".join(parts)
38
+ if schema.get("x-content-type"):
39
+ line += f" [{schema['x-content-type']}]"
40
+ return line
41
+
42
+
43
+ def _load_env_files(cwd):
44
+ try:
45
+ from dotenv import load_dotenv
46
+ except ImportError:
47
+ return
48
+ for filename in (".env", ".env.local"):
49
+ filepath = os.path.join(cwd, filename)
50
+ if os.path.exists(filepath):
51
+ load_dotenv(filepath, override=False)
52
+
53
+
54
+ def main():
55
+ cwd = os.getcwd()
56
+ _load_env_files(cwd)
57
+
58
+ api_key = os.environ.get("BOTVERSION_API_KEY")
59
+ platform_url = os.environ.get("BOTVERSION_PLATFORM_URL", "https://console.botversion.com")
60
+ for _envname in (".env", ".env.local"):
61
+ _ep = os.path.join(cwd, _envname)
62
+ print(f"[TEMP-DEBUG] {_envname} exists:", os.path.exists(_ep))
63
+ if os.path.exists(_ep):
64
+ with open(_ep, "rb") as _ef:
65
+ _eraw = _ef.read()
66
+ print(f"[TEMP-DEBUG] {_envname} first bytes:", _eraw[:4])
67
+ _etext = _eraw.decode("utf-16", errors="ignore") if _eraw.startswith((b"\xff\xfe", b"\xfe\xff")) else _eraw.decode("utf-8", errors="ignore")
68
+ for _line in _etext.splitlines():
69
+ if "BOTVERSION" in _line.upper():
70
+ _k, _, _v = _line.partition("=")
71
+ print(f"[TEMP-DEBUG] {_envname} line:", _k, "= (masked)", repr(_v[:6] + "..." + _v[-4:]), "| value length:", len(_v))
72
+
73
+ if not api_key:
74
+ sys.exit(0)
75
+
76
+ framework = detect_framework_from_deps(cwd)
77
+ if not framework:
78
+ sys.exit(0)
79
+
80
+ endpoints = scan_routes_static(cwd, framework)
81
+
82
+ dlog("[botversion:debug] endpoints found:", len(endpoints))
83
+ for i, e in enumerate(endpoints, 1):
84
+ dlog(
85
+ f"[botversion:debug] #{i} {e.get('method')} {e.get('path')}"
86
+ f"\n request : {field_list(e.get('requestBody'))}"
87
+ f"\n response : {field_list(e.get('responseBody'))}"
88
+ f"\n params : {json.dumps(e.get('routeParamMap') or {})}"
89
+ f"\n detectedBy: {e.get('detectedBy')}"
90
+ )
91
+ dlog("[botversion:debug] full endpoint JSON:\n" + json.dumps(endpoints, indent=2, default=str))
92
+
93
+ if not endpoints:
94
+ print(f"[botversion] No backend endpoints found via static scan. detected_framework={framework}")
95
+ sys.exit(0)
96
+
97
+ client = BotVersionClient({"api_key": api_key, "platform_url": platform_url, "debug": True})
98
+ # TEMP-DEBUG: send one endpoint directly so the real error shows
99
+ try:
100
+ _resp = client._post("/api/sdk/register-endpoints", {"workspaceKey": api_key, "endpoints": endpoints[:1]})
101
+ print("[TEMP-DEBUG] test post response:", _resp)
102
+ except Exception as _e:
103
+ print("[TEMP-DEBUG] test post failed:", repr(_e))
104
+ try:
105
+ client.register_endpoints_now(endpoints)
106
+ print(f"[botversion] Reported {len(endpoints)} backend endpoints. detected_framework={framework}")
107
+ except Exception as e:
108
+ print(f"[botversion] Failed to report backend endpoints: {e}")
109
+
110
+ sys.exit(0)
111
+
112
+
113
+ if __name__ == "__main__":
114
+ main()
@@ -1,4 +1,4 @@
1
- # botversion-sdk-python/botversion-sdk/client.py
1
+ # botversion-sdk-python/botversion-sdk/scanner-sdk/client.py
2
2
  import json
3
3
  import threading
4
4
  import urllib.request
@@ -1,4 +1,4 @@
1
- # botversion-sdk-python/botversion-sdk/interceptor.py
1
+ # botversion-sdk-python/botversion-sdk/scanner-sdk/interceptor.py
2
2
  import re
3
3
  import json
4
4
  import threading
@@ -28,6 +28,23 @@ def should_ignore(path, extra_ignore=None):
28
28
  return any(path.startswith(p) for p in ignore)
29
29
 
30
30
 
31
+ def is_multipart_content_type(value):
32
+ # True when the request carries a file-upload body that must not be read as JSON
33
+ return "multipart/form-data" in str(value or "").lower()
34
+
35
+
36
+ def raise_if_multipart(content_type):
37
+ # Placed first inside body-reading try blocks: skips reading uploads (existing except handles it)
38
+ if is_multipart_content_type(content_type):
39
+ raise ValueError("multipart body")
40
+
41
+
42
+ def with_multipart_marker(schema):
43
+ out = dict(schema) if schema else {"type": "object", "properties": {}}
44
+ out["x-content-type"] = "multipart/form-data"
45
+ return out
46
+
47
+
31
48
  def normalize_path(path):
32
49
  """
33
50
  Replace dynamic segments with :id
@@ -213,7 +230,7 @@ def extract_trpc_get_input_raw(path, query_string):
213
230
  return None
214
231
 
215
232
 
216
- def _report_single_endpoint(client, method, normalized_path, body_structure, options):
233
+ def _report_single_endpoint(client, method, normalized_path, body_structure, options, multipart=False):
217
234
  """
218
235
  Reports exactly one already-normalized, already-split endpoint.
219
236
  Uses body-key deduplication.
@@ -221,7 +238,7 @@ def _report_single_endpoint(client, method, normalized_path, body_structure, opt
221
238
  endpoint_key = f"{method}:{normalized_path}"
222
239
 
223
240
  body_fields = sorted(body_structure.keys()) if body_structure else []
224
- body_key = endpoint_key + ":" + ",".join(body_fields)
241
+ body_key = endpoint_key + ":" + ",".join(body_fields) + (":multipart" if multipart else "")
225
242
 
226
243
  with _lock:
227
244
  if body_key in _reported:
@@ -229,6 +246,8 @@ def _report_single_endpoint(client, method, normalized_path, body_structure, opt
229
246
  _reported.add(body_key)
230
247
 
231
248
  json_schema = body_structure_to_json_schema(body_structure)
249
+ if multipart:
250
+ json_schema = with_multipart_marker(json_schema)
232
251
 
233
252
  # update_endpoint only queues the update (sending happens in the background), so it never
234
253
  # blocks the request, and the queue order matches the order of calls.
@@ -243,7 +262,7 @@ def _report_single_endpoint(client, method, normalized_path, body_structure, opt
243
262
  return None
244
263
 
245
264
 
246
- def report_endpoint(client, method, path, body_data, query_string, options):
265
+ def report_endpoint(client, method, path, body_data, query_string, options, content_type=None):
247
266
  """
248
267
  Splits a (possibly batched) tRPC path into one clean endpoint per real
249
268
  procedure — instead of one garbled, comma-joined path — with each
@@ -254,6 +273,11 @@ def report_endpoint(client, method, path, body_data, query_string, options):
254
273
  body_data — the raw parsed JSON body (or None/empty for GET requests).
255
274
  query_string — the raw query string, used to recover tRPC GET input.
256
275
  """
276
+ multipart = is_multipart_content_type(content_type)
277
+ if multipart:
278
+ body_data = None
279
+ query_string = None
280
+
257
281
  split_paths = [normalize_path(p) for p in split_batch_path(path)]
258
282
 
259
283
  body_slots = None
@@ -272,7 +296,7 @@ def report_endpoint(client, method, path, body_data, query_string, options):
272
296
  for i, single_path in enumerate(split_paths):
273
297
  slot_body = body_slots[i] if i < len(body_slots) else None
274
298
  body_structure = build_body_structure(slot_body)
275
- _report_single_endpoint(client, method, single_path, body_structure, options)
299
+ _report_single_endpoint(client, method, single_path, body_structure, options, multipart)
276
300
 
277
301
 
278
302
  # ── FastAPI middleware ────────────────────────────────────────────────────────
@@ -316,6 +340,7 @@ def attach_fastapi_interceptor(app, client, options):
316
340
  if not should_ignore(path, options.get("exclude")):
317
341
  if not options.get("api_prefix") or path.startswith(options["api_prefix"]):
318
342
  try:
343
+ raise_if_multipart(request.headers.get("content-type"))
319
344
  body_bytes = await request.body()
320
345
  async def receive():
321
346
  return {"type": "http.request", "body": body_bytes}
@@ -325,7 +350,7 @@ def attach_fastapi_interceptor(app, client, options):
325
350
  body_data = None
326
351
 
327
352
  if response.status_code < 500:
328
- report_endpoint(client, method, path, body_data, request.url.query, options)
353
+ report_endpoint(client, method, path, body_data, request.url.query, options, request.headers.get("content-type"))
329
354
 
330
355
  return response
331
356
 
@@ -381,7 +406,7 @@ def attach_flask_interceptor(app, client, options):
381
406
  except Exception:
382
407
  body_data = None
383
408
 
384
- report_endpoint(client, method, path, body_data, flask_request.query_string.decode("utf-8"), options)
409
+ report_endpoint(client, method, path, body_data, flask_request.query_string.decode("utf-8"), options, flask_request.content_type)
385
410
 
386
411
  @app.after_request
387
412
  def botversion_response_capture(response):
@@ -443,6 +468,7 @@ class BotVersionDjangoMiddleware:
443
468
  if not should_ignore(path, self.__class__._options.get("exclude")):
444
469
  if not self.__class__._options.get("api_prefix") or path.startswith(self.__class__._options["api_prefix"]):
445
470
  try:
471
+ raise_if_multipart(request.META.get("CONTENT_TYPE"))
446
472
  body_data = json.loads(request.body) if request.body else None
447
473
  except Exception:
448
474
  body_data = None
@@ -455,6 +481,7 @@ class BotVersionDjangoMiddleware:
455
481
  body_data,
456
482
  request.META.get("QUERY_STRING", ""),
457
483
  self.__class__._options,
484
+ request.META.get("CONTENT_TYPE"),
458
485
  )
459
486
 
460
487
  # Drops cache-validation headers so the app sends a full reply instead of an empty 304
@@ -492,7 +519,7 @@ def attach_django_interceptor(client, options):
492
519
  try:
493
520
  from django.conf import settings
494
521
 
495
- middleware_path = "botversion_sdk.interceptor.BotVersionDjangoMiddleware"
522
+ middleware_path = __name__ + ".BotVersionDjangoMiddleware" # built from this file's real module path so it survives file moves
496
523
 
497
524
  if middleware_path not in settings.MIDDLEWARE:
498
525
  if isinstance(settings.MIDDLEWARE, tuple):
@@ -549,13 +576,14 @@ def attach_starlette_interceptor(app, client, options):
549
576
  if not should_ignore(path, options.get("exclude")):
550
577
  if not options.get("api_prefix") or path.startswith(options["api_prefix"]):
551
578
  try:
579
+ raise_if_multipart(request.headers.get("content-type"))
552
580
  body_bytes = await request.body()
553
581
  body_data = _json.loads(body_bytes) if body_bytes else None
554
582
  except Exception:
555
583
  body_data = None
556
584
 
557
585
  if response.status_code < 500:
558
- report_endpoint(client, method, path, body_data, request.url.query, options)
586
+ report_endpoint(client, method, path, body_data, request.url.query, options, request.headers.get("content-type"))
559
587
 
560
588
  return response
561
589
 
@@ -597,11 +625,12 @@ def attach_sanic_interceptor(app, client, options):
597
625
  return
598
626
 
599
627
  try:
628
+ raise_if_multipart(request.headers.get("content-type"))
600
629
  body_data = request.json if request.body else None
601
630
  except Exception:
602
631
  body_data = None
603
632
 
604
- report_endpoint(client, method, path, body_data, request.query_string, options)
633
+ report_endpoint(client, method, path, body_data, request.query_string, options, request.headers.get("content-type"))
605
634
 
606
635
  @app.middleware("response")
607
636
  async def botversion_sanic_response_capture(request, response):
@@ -661,6 +690,7 @@ def attach_falcon_interceptor(app, client, options):
661
690
  return
662
691
 
663
692
  try:
693
+ raise_if_multipart(req.content_type)
664
694
  body_bytes = req.bounded_stream.read()
665
695
  body_data = _json.loads(body_bytes) if body_bytes else None
666
696
  # Put body back so the actual handler can still read it
@@ -669,7 +699,7 @@ def attach_falcon_interceptor(app, client, options):
669
699
  except Exception:
670
700
  body_data = None
671
701
 
672
- report_endpoint(client, method, path, body_data, req.query_string, options)
702
+ report_endpoint(client, method, path, body_data, req.query_string, options, req.content_type)
673
703
 
674
704
  def process_response(self, req, resp, resource, req_succeeded):
675
705
  # Capture the shape of the successful JSON reply (field names only)
@@ -742,11 +772,12 @@ def attach_bottle_interceptor(app, client, options):
742
772
  return
743
773
 
744
774
  try:
775
+ raise_if_multipart(bottle_request.content_type)
745
776
  body_data = bottle_request.json
746
777
  except Exception:
747
778
  body_data = None
748
779
 
749
- report_endpoint(client, method, path, body_data, bottle_request.query_string, options)
780
+ report_endpoint(client, method, path, body_data, bottle_request.query_string, options, bottle_request.content_type)
750
781
 
751
782
  # Install on the specific app instance, not globally
752
783
  app.add_hook("before_request", botversion_bottle_interceptor)
@@ -826,13 +857,14 @@ def attach_aiohttp_interceptor(app, client, options):
826
857
  if not should_ignore(path, options.get("exclude")):
827
858
  if not options.get("api_prefix") or path.startswith(options["api_prefix"]):
828
859
  try:
860
+ raise_if_multipart(request.headers.get("Content-Type"))
829
861
  body_bytes = await request.read()
830
862
  body_data = _json.loads(body_bytes) if body_bytes else None
831
863
  except Exception:
832
864
  body_data = None
833
865
 
834
866
  if response.status < 500:
835
- report_endpoint(client, method, path, body_data, request.rel_url.query_string, options)
867
+ report_endpoint(client, method, path, body_data, request.rel_url.query_string, options, request.headers.get("Content-Type"))
836
868
 
837
869
  # Capture the shape of the successful JSON reply (field names only)
838
870
  try:
@@ -934,13 +966,14 @@ def attach_tornado_interceptor(app, client, options):
934
966
  if not should_ignore(path, options.get("exclude")):
935
967
  if not options.get("api_prefix") or path.startswith(options["api_prefix"]):
936
968
  try:
969
+ raise_if_multipart(self.request.headers.get("Content-Type"))
937
970
  body_bytes = self.request.body
938
971
  body_data = _json.loads(body_bytes) if body_bytes else None
939
972
  except Exception:
940
973
  body_data = None
941
974
 
942
975
  if self.get_status() < 500:
943
- report_endpoint(client, method, path, body_data, self.request.query, options)
976
+ report_endpoint(client, method, path, body_data, self.request.query, options, self.request.headers.get("Content-Type"))
944
977
 
945
978
  # Capture the shape of the successful JSON reply (field names only)
946
979
  if should_watch_response(method, path, options):
@@ -1006,12 +1039,13 @@ def botversion_pyramid_tween_factory(handler, registry):
1006
1039
  if _pyramid_client and not should_ignore(path, _pyramid_options.get("exclude")):
1007
1040
  if not _pyramid_options.get("api_prefix") or path.startswith(_pyramid_options["api_prefix"]):
1008
1041
  try:
1042
+ raise_if_multipart(request.content_type)
1009
1043
  body_data = request.json_body if request.content_length else None
1010
1044
  except Exception:
1011
1045
  body_data = None
1012
1046
 
1013
1047
  if response.status_int < 500:
1014
- report_endpoint(_pyramid_client, method, path, body_data, request.query_string, _pyramid_options)
1048
+ report_endpoint(_pyramid_client, method, path, body_data, request.query_string, _pyramid_options, request.content_type)
1015
1049
  except Exception:
1016
1050
  pass
1017
1051
 
@@ -1037,7 +1071,7 @@ def attach_pyramid_interceptor(app, client, options):
1037
1071
  For Pyramid, the tween must be added during config before app creation.
1038
1072
  We store client + options at module level so the tween factory can use them.
1039
1073
  Tell the user to add this to their Pyramid config:
1040
- config.add_tween('botversion_sdk.interceptor.botversion_pyramid_tween_factory')
1074
+ config.add_tween(__name__ + ".botversion_pyramid_tween_factory") # built from this file's real module path so it survives file moves
1041
1075
  """
1042
1076
  global _pyramid_client, _pyramid_options
1043
1077
  _pyramid_client = client
@@ -1087,6 +1121,7 @@ def attach_cherrypy_interceptor(app, client, options):
1087
1121
  return
1088
1122
 
1089
1123
  try:
1124
+ raise_if_multipart(request.headers.get("Content-Type"))
1090
1125
  body_bytes = request.body.read() if request.body else None
1091
1126
  body_data = _json.loads(body_bytes) if body_bytes else None
1092
1127
  # Put body back so actual handler can still read it
@@ -1096,7 +1131,7 @@ def attach_cherrypy_interceptor(app, client, options):
1096
1131
  body_data = None
1097
1132
 
1098
1133
  query_string = request.query_string if hasattr(request, "query_string") else ""
1099
- report_endpoint(client, method, path, body_data, query_string, options)
1134
+ report_endpoint(client, method, path, body_data, query_string, options, request.headers.get("Content-Type"))
1100
1135
 
1101
1136
  # Register as a CherryPy tool
1102
1137
  cherrypy.tools.botversion = cherrypy.Tool(
@@ -0,0 +1,2 @@
1
+ # botversion-sdk-python/botversion_sdk/scan/__init__.py
2
+
@@ -0,0 +1,101 @@
1
+ # botversion-sdk-python/botversion_sdk/scan/aiohttp.py
2
+
3
+ import re
4
+
5
+ from .common import generate_description
6
+ from .multipart import live_multipart
7
+ from .response_shapes import _resolve_view_handler, extract_static_response_from_callable
8
+ from .static_common import _extract_body_fields_static, _walk_py_files
9
+
10
+
11
+ # ── aiohttp ───────────────────────────────────────────────────────────────────
12
+ # aiohttp stores routes in app.router which has a resources() method
13
+
14
+ def scan_aiohttp_routes(app):
15
+ endpoints = []
16
+ seen = set()
17
+
18
+ try:
19
+ for resource in app.router.resources():
20
+ path = resource.canonical
21
+ # Normalize {param} → :param
22
+ normalized_path = re.sub(r"\{([^:}]+)(?::[^}]+)?\}", r":\1", path)
23
+ normalized_path = normalized_path.rstrip("/") or "/"
24
+
25
+ # Each resource has routes with methods
26
+ for route in resource:
27
+ method = route.method.upper()
28
+ if method in ("HEAD", "OPTIONS", "*"):
29
+ continue
30
+
31
+ key = f"{method}:{normalized_path}"
32
+ if key in seen:
33
+ continue
34
+ seen.add(key)
35
+
36
+ handler = route.handler
37
+ handler_name = getattr(handler, "__name__", None)
38
+
39
+ endpoints.append({
40
+ "method": method,
41
+ "path": normalized_path,
42
+ "description": generate_description(method, normalized_path, handler_name),
43
+ "requestBody": live_multipart(_resolve_view_handler(handler, method), method),
44
+ "responseBody": extract_static_response_from_callable(_resolve_view_handler(handler, method)),
45
+ "detectedBy": "static-scan",
46
+ })
47
+
48
+ except Exception:
49
+ pass
50
+
51
+ return endpoints
52
+
53
+
54
+ def _scan_aiohttp_static(cwd):
55
+ """
56
+ Handles aiohttp-style route registration:
57
+ app.router.add_get('/path', handler)
58
+ app.router.add_post('/path', handler)
59
+ app.router.add_route('POST', '/path', handler)
60
+ """
61
+ endpoints = []
62
+ seen = set()
63
+
64
+ shorthand_pattern = re.compile(
65
+ r"add_(get|post|put|delete|patch)\s*\(\s*[\"']([^\"']+)[\"']",
66
+ re.IGNORECASE,
67
+ )
68
+ generic_pattern = re.compile(
69
+ r"add_route\s*\(\s*[\"'](\w+)[\"']\s*,\s*[\"']([^\"']+)[\"']",
70
+ re.IGNORECASE,
71
+ )
72
+
73
+ for filepath in _walk_py_files(cwd):
74
+ try:
75
+ with open(filepath, "r", encoding="utf-8", errors="ignore") as fh:
76
+ content = fh.read()
77
+ except Exception:
78
+ continue
79
+
80
+ for pattern in (shorthand_pattern, generic_pattern):
81
+ for match in pattern.finditer(content):
82
+ method = match.group(1).upper()
83
+ path = match.group(2)
84
+ normalized = re.sub(r"\{([^:}]+)(?::[^}]+)?\}", r":\1", path)
85
+
86
+ key = f"{method}:{normalized}"
87
+ if key in seen:
88
+ continue
89
+ seen.add(key)
90
+
91
+ body_fields = _extract_body_fields_static(content) if method in ("POST", "PUT", "PATCH") else None
92
+
93
+ endpoints.append({
94
+ "method": method,
95
+ "path": normalized,
96
+ "description": generate_description(method, normalized, None),
97
+ "requestBody": body_fields,
98
+ "detectedBy": "static-scan-file",
99
+ })
100
+
101
+ return endpoints