visionai-sdk-python 2.2.0.dev5__tar.gz → 2.2.0.dev7__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.
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/PKG-INFO +16 -6
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/README.md +15 -5
- visionai_sdk_python-2.2.0.dev7/docs/relay-protocol.md +281 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/_base.py +29 -2
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/async_client.py +35 -18
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/auth/credentials.py +71 -17
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/client.py +35 -20
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/relay/__init__.py +3 -2
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/relay/examples/__init__.py +2 -2
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/relay/protocol.py +19 -12
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python.egg-info/PKG-INFO +16 -6
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python.egg-info/SOURCES.txt +2 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python.egg-info/scm_file_list.json +2 -0
- visionai_sdk_python-2.2.0.dev7/src/visionai_sdk_python.egg-info/scm_version.json +8 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/tests/relay/test_protocol.py +13 -7
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/tests/test_credentials.py +82 -0
- visionai_sdk_python-2.2.0.dev7/tests/test_transport_options.py +57 -0
- visionai_sdk_python-2.2.0.dev5/src/visionai_sdk_python.egg-info/scm_version.json +0 -8
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/.github/dependabot.yml +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/.github/workflows/ci.yml +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/.github/workflows/publish.yml +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/.gitignore +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/pyproject.toml +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/setup.cfg +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/__init__.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/_jwt_verifier.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/_request_attribution.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/_source_header.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/auth/__init__.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/auth/_mixin.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/auth/async_resource.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/auth/models.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/auth/resource.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/constants.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/endpoints.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/exceptions.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/instrumentation.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/py.typed +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/relay/examples/error_connection.json +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/relay/examples/error_request.json +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/relay/examples/heartbeat.json +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/relay/examples/register.json +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/relay/examples/registered.json +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/relay/examples/request.json +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/relay/examples/response.json +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/relay/examples/response_text.json +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/vlm/__init__.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/vlm/_mixin.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/vlm/async_resource.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/vlm/models.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/vlm/preprocess.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/vlm/resource.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python.egg-info/dependency_links.txt +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python.egg-info/requires.txt +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python.egg-info/top_level.txt +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/tests/__init__.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/tests/constants.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/tests/relay/__init__.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/tests/test__base.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/tests/test_async_client.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/tests/test_client.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/tests/test_instrumentation.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/tests/test_request.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/tests/test_vlm_preprocess.py +0 -0
- {visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/uv.lock +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: visionai-sdk-python
|
|
3
|
-
Version: 2.2.0.
|
|
3
|
+
Version: 2.2.0.dev7
|
|
4
4
|
Summary: VisionAI SDK for Python
|
|
5
5
|
Author-email: Tony Yang <tonyyang@linkervision.com>
|
|
6
6
|
Requires-Python: >=3.11
|
|
@@ -153,6 +153,13 @@ token = cred.get_token().token # for a WebSocket upgrade or another lib
|
|
|
153
153
|
nodes = client.request("GET", "https://vs.example.com/mgmt/nodes").json()
|
|
154
154
|
```
|
|
155
155
|
|
|
156
|
+
`request()` raises on a non-2xx like the resource methods (`AuthenticationError`,
|
|
157
|
+
`ClientError`, `ServerError`, ...), unlike plain httpx, and sends the token to whatever
|
|
158
|
+
host `url` names, so `url` comes from configuration or code, never from a caller. A
|
|
159
|
+
client built with `http_client=` (or a credential with `http=`) uses that client's TLS,
|
|
160
|
+
timeout and limits; passing `verify_ssl` / `timeout` / `max_connections` /
|
|
161
|
+
`max_keepalive_connections` with it raises `ValueError`.
|
|
162
|
+
|
|
156
163
|
A mint is a Platform round trip and, on sites that cap client tokens, a scarce one:
|
|
157
164
|
concurrent callers share one mint, a refresh that fails keeps the current token while
|
|
158
165
|
Platform still accepts it, a 401 on a token minted more than 30 minutes ago buys a
|
|
@@ -169,11 +176,14 @@ authentication wins. `vlm_url` is optional for clients that only authenticate.
|
|
|
169
176
|
|
|
170
177
|
`visionai_sdk_python.relay` holds the wire format between platform-relay and
|
|
171
178
|
platform-edge-agent: the frame models, the constants and `parse_agent_frame()` /
|
|
172
|
-
`parse_relay_frame()`
|
|
173
|
-
`
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
179
|
+
`parse_relay_frame()` (text frames only: `bytes` or `None` is an `InvalidFrame`) /
|
|
180
|
+
`dump_frame()` (which refuses a frame over `MAX_FRAME_BYTES`). The spec is
|
|
181
|
+
[`docs/relay-protocol.md`](docs/relay-protocol.md); both sides import this module instead of
|
|
182
|
+
keeping a copy, and a protocol change edits the spec and the module in one PR. The spec's
|
|
183
|
+
JSON examples ship with it (`visionai_sdk_python.relay.examples`: `example(name)` /
|
|
184
|
+
`example_text(name)`), so every implementation tests against the same frames. The decisions
|
|
185
|
+
behind the protocol are platform-service's `docs/adr/0001-relay-protocol.md`. It is internal
|
|
186
|
+
to the platform and not a public API.
|
|
177
187
|
|
|
178
188
|
## VLM Inference
|
|
179
189
|
|
|
@@ -135,6 +135,13 @@ token = cred.get_token().token # for a WebSocket upgrade or another lib
|
|
|
135
135
|
nodes = client.request("GET", "https://vs.example.com/mgmt/nodes").json()
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
+
`request()` raises on a non-2xx like the resource methods (`AuthenticationError`,
|
|
139
|
+
`ClientError`, `ServerError`, ...), unlike plain httpx, and sends the token to whatever
|
|
140
|
+
host `url` names, so `url` comes from configuration or code, never from a caller. A
|
|
141
|
+
client built with `http_client=` (or a credential with `http=`) uses that client's TLS,
|
|
142
|
+
timeout and limits; passing `verify_ssl` / `timeout` / `max_connections` /
|
|
143
|
+
`max_keepalive_connections` with it raises `ValueError`.
|
|
144
|
+
|
|
138
145
|
A mint is a Platform round trip and, on sites that cap client tokens, a scarce one:
|
|
139
146
|
concurrent callers share one mint, a refresh that fails keeps the current token while
|
|
140
147
|
Platform still accepts it, a 401 on a token minted more than 30 minutes ago buys a
|
|
@@ -151,11 +158,14 @@ authentication wins. `vlm_url` is optional for clients that only authenticate.
|
|
|
151
158
|
|
|
152
159
|
`visionai_sdk_python.relay` holds the wire format between platform-relay and
|
|
153
160
|
platform-edge-agent: the frame models, the constants and `parse_agent_frame()` /
|
|
154
|
-
`parse_relay_frame()`
|
|
155
|
-
`
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
161
|
+
`parse_relay_frame()` (text frames only: `bytes` or `None` is an `InvalidFrame`) /
|
|
162
|
+
`dump_frame()` (which refuses a frame over `MAX_FRAME_BYTES`). The spec is
|
|
163
|
+
[`docs/relay-protocol.md`](docs/relay-protocol.md); both sides import this module instead of
|
|
164
|
+
keeping a copy, and a protocol change edits the spec and the module in one PR. The spec's
|
|
165
|
+
JSON examples ship with it (`visionai_sdk_python.relay.examples`: `example(name)` /
|
|
166
|
+
`example_text(name)`), so every implementation tests against the same frames. The decisions
|
|
167
|
+
behind the protocol are platform-service's `docs/adr/0001-relay-protocol.md`. It is internal
|
|
168
|
+
to the platform and not a public API.
|
|
159
169
|
|
|
160
170
|
## VLM Inference
|
|
161
171
|
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
# platform-relay ↔ platform-edge-agent wire format, `platform-relay.v1`
|
|
2
|
+
|
|
3
|
+
What goes over the WebSocket between platform-relay (platform-service) and platform-edge-agent
|
|
4
|
+
(visionai-vlm-scheduling-service). `visionai_sdk_python.relay` implements it, the models, the
|
|
5
|
+
constants and the parsers, and both sides import that module instead of keeping a copy. The JSON
|
|
6
|
+
examples below ship as `visionai_sdk_python.relay.examples` and are the fixtures of the SDK's, the
|
|
7
|
+
relay's and the agent's tests. A protocol change edits this file and the module in one PR; the two
|
|
8
|
+
consumers then bump the SDK.
|
|
9
|
+
|
|
10
|
+
Why the protocol looks like this is platform-service's `docs/adr/0001-relay-protocol.md`. How the
|
|
11
|
+
relay implements it (the Platform check at `register`, routing, its HTTP API and status mapping) is
|
|
12
|
+
`relay/README.md` in that repository; the agent's side is in visionai-vlm-scheduling-service.
|
|
13
|
+
|
|
14
|
+
## 1. Connection
|
|
15
|
+
|
|
16
|
+
The agent connects to `wss://<platform_domain>/relay/ws`. The HTTP upgrade carries the agent's
|
|
17
|
+
identity and the protocol version:
|
|
18
|
+
|
|
19
|
+
```http
|
|
20
|
+
GET /relay/ws HTTP/1.1
|
|
21
|
+
Host: <platform_domain>
|
|
22
|
+
Upgrade: websocket
|
|
23
|
+
Connection: Upgrade
|
|
24
|
+
Sec-WebSocket-Version: 13
|
|
25
|
+
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
|
|
26
|
+
Sec-WebSocket-Protocol: platform-relay.v1
|
|
27
|
+
Authorization: Bearer eyJhbGciOi…
|
|
28
|
+
|
|
29
|
+
HTTP/1.1 101 Switching Protocols
|
|
30
|
+
Upgrade: websocket
|
|
31
|
+
Connection: Upgrade
|
|
32
|
+
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
|
|
33
|
+
Sec-WebSocket-Protocol: platform-relay.v1
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
- `Authorization` is a platform M2M token (client credentials). A refused upgrade is an HTTP
|
|
37
|
+
status, not a close code: 400 when the relay knows none of the offered subprotocols, 401 when the
|
|
38
|
+
token is not accepted (the agent fetches a new token, once, and reconnects), 503 when the relay
|
|
39
|
+
could not validate it (the agent retries with the same token).
|
|
40
|
+
- `Sec-WebSocket-Protocol` carries the protocol version (§6).
|
|
41
|
+
- After `101` the connection is the identity. Messages carry no agent or tenant fields.
|
|
42
|
+
|
|
43
|
+
Transport:
|
|
44
|
+
|
|
45
|
+
- Text frames only, one JSON object per frame, UTF-8. A binary frame is answered with
|
|
46
|
+
`error invalid_message`.
|
|
47
|
+
- Maximum frame size 16 MiB in both directions; both sides check the encoded frame before sending
|
|
48
|
+
(`dump_frame()` refuses a larger one).
|
|
49
|
+
- WebSocket ping every 20 s, pong timeout 60 s, on both sides. Large frames on slow links delay
|
|
50
|
+
pongs, so the timeout is not the library default.
|
|
51
|
+
|
|
52
|
+
## 2. Messages
|
|
53
|
+
|
|
54
|
+
Six message types, told apart by `type`. Optional fields may be omitted or `null`. Receivers ignore
|
|
55
|
+
unknown fields.
|
|
56
|
+
|
|
57
|
+
| `type` | Sender | Fields |
|
|
58
|
+
|---|---|---|
|
|
59
|
+
| `register` | agent | `agent_id`, `cluster_id`, `workspaces` |
|
|
60
|
+
| `registered` | relay | `accepted`, `rejected` |
|
|
61
|
+
| `heartbeat` | agent | none |
|
|
62
|
+
| `request` | relay | `request_id`, `workspace_id`, `method`, `path`, `headers`, `body`, `timeout_s` |
|
|
63
|
+
| `response` | agent | `request_id`, `status`, `headers`, `body` |
|
|
64
|
+
| `error` | either | `request_id` (optional), `code`, `message` |
|
|
65
|
+
|
|
66
|
+
| Field | Type | Meaning |
|
|
67
|
+
|---|---|---|
|
|
68
|
+
| `agent_id` | string | The agent's pod name. With `cluster_id` it identifies a reconnecting agent (§3). |
|
|
69
|
+
| `cluster_id` | string | The agent's site, from its own configuration: the value vlm-mgmt reports as `VLM_CLUSTER_NAME` and Platform stores in `Node.cluster`. Required. |
|
|
70
|
+
| `workspaces` | array of object | `{"id", "models"}` per workspace the agent serves. `id` is the workspace's Platform id, a lowercase hyphenated UUID. Complete list; replaces the previous one. |
|
|
71
|
+
| `models` | array of object | `{"name", "version", "replicas"}` per model the workspace's VS lists as available (§3). Empty when it lists none. |
|
|
72
|
+
| `replicas` | integer | Required; a `register` without it is invalid (§5). Available nodes listing that model and version (§3); weights the relay's routing. |
|
|
73
|
+
| `accepted` | array of string | Workspace ids from `workspaces` the relay registered. |
|
|
74
|
+
| `rejected` | array of object | `{"id", "reason"}` per refused workspace: the workspace id and a reason from §5. |
|
|
75
|
+
| `request_id` | string | UUID v4 minted by the relay. `response` and `error` echo it. |
|
|
76
|
+
| `workspace_id` | string | Target workspace of a `request`. |
|
|
77
|
+
| `method`, `path` | string | The caller's HTTP method and path below `/<workspace_id>`, query string included. |
|
|
78
|
+
| `headers` | object | `request`: `Authorization`, `X-Request-Source`, `Content-Type` only. `response`: `Content-Type` only. Names are case-insensitive. |
|
|
79
|
+
| `body` | object, string or null | The HTTP body: JSON as an object, anything else as a string, `null` when there is none. |
|
|
80
|
+
| `timeout_s` | integer | Seconds the agent waits for VS. |
|
|
81
|
+
| `status` | integer | VS's HTTP status code, unchanged. |
|
|
82
|
+
| `code`, `message` | string | Error code (§5) and a human-readable detail, at most 200 characters. |
|
|
83
|
+
|
|
84
|
+
Examples. Image data and tokens are truncated; the `request` body is what Dataverse sends today.
|
|
85
|
+
|
|
86
|
+
`register`, agent → relay, first frame after `101`:
|
|
87
|
+
|
|
88
|
+
```json
|
|
89
|
+
{"type": "register",
|
|
90
|
+
"agent_id": "platform-edge-agent-7d9f4b6c8-xk2pq",
|
|
91
|
+
"cluster_id": "aws-offline-edge",
|
|
92
|
+
"workspaces": [{"id": "31a6638a-5c2e-4f1b-9a7d-0e3c6b8d2f41",
|
|
93
|
+
"models": [{"name": "cr2-8b", "version": "4.5.0", "replicas": 2},
|
|
94
|
+
{"name": "cr2-8b", "version": "4.6.0", "replicas": 1}]},
|
|
95
|
+
{"id": "7589d018-2b4c-4e6f-8a1d-3c5e7f9b1d23", "models": []},
|
|
96
|
+
{"id": "QA Workspace", "models": []}]}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`registered`, relay → agent. Platform lists no node of `aws-offline-edge` for `7589…`; `QA Workspace`
|
|
100
|
+
is not a UUID:
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
{"type": "registered",
|
|
104
|
+
"accepted": ["31a6638a-5c2e-4f1b-9a7d-0e3c6b8d2f41"],
|
|
105
|
+
"rejected": [{"id": "7589d018-2b4c-4e6f-8a1d-3c5e7f9b1d23", "reason": "cluster_mismatch"},
|
|
106
|
+
{"id": "QA Workspace", "reason": "invalid_id"}]}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
`heartbeat`, agent → relay, every 30 s:
|
|
110
|
+
|
|
111
|
+
```json
|
|
112
|
+
{"type": "heartbeat"}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
`request`, relay → agent:
|
|
116
|
+
|
|
117
|
+
```json
|
|
118
|
+
{"type": "request",
|
|
119
|
+
"request_id": "7f3c2a1e-9d4b-4c8a-b2e6-1f5d3a7c9e0b",
|
|
120
|
+
"workspace_id": "31a6638a-5c2e-4f1b-9a7d-0e3c6b8d2f41",
|
|
121
|
+
"method": "POST",
|
|
122
|
+
"path": "/api/chat",
|
|
123
|
+
"headers": {"Authorization": "Bearer eyJhbGciOi…",
|
|
124
|
+
"X-Request-Source": "dataverse",
|
|
125
|
+
"Content-Type": "application/json"},
|
|
126
|
+
"body": {"img": "data:image/jpeg;base64,/9j/4AAQ…",
|
|
127
|
+
"prompt": "Describe the scene.",
|
|
128
|
+
"temperature": 0.2, "max_tokens": 500, "top_p": 0.7,
|
|
129
|
+
"stream": false, "use_cache": true, "num_beams": 1,
|
|
130
|
+
"model": "cr2-8b", "model_version": null,
|
|
131
|
+
"api_endpoint": null, "hook": null,
|
|
132
|
+
"keep_alive": true, "use_response_postprocess": true,
|
|
133
|
+
"workspace_id": "31a6638a-5c2e-4f1b-9a7d-0e3c6b8d2f41"},
|
|
134
|
+
"timeout_s": 100}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
`response`, agent → relay. The same shape carries VS's 408, 422 and 500 answers:
|
|
138
|
+
|
|
139
|
+
```json
|
|
140
|
+
{"type": "response",
|
|
141
|
+
"request_id": "7f3c2a1e-9d4b-4c8a-b2e6-1f5d3a7c9e0b",
|
|
142
|
+
"status": 200,
|
|
143
|
+
"headers": {"Content-Type": "application/json"},
|
|
144
|
+
"body": {"chat_id": "high:1760424000123-3f9a1c7e",
|
|
145
|
+
"status": "completed",
|
|
146
|
+
"message": "{\"description\": \"A forklift in a warehouse aisle.\"}",
|
|
147
|
+
"dispatch": {"model_name": "cr2-8b", "model_version": "4.5.0",
|
|
148
|
+
"api_endpoint": "http://cr2-8b:8000"}}}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
`response` with a non-JSON body, for example an unhandled 500 from VS:
|
|
152
|
+
|
|
153
|
+
```json
|
|
154
|
+
{"type": "response",
|
|
155
|
+
"request_id": "7f3c2a1e-9d4b-4c8a-b2e6-1f5d3a7c9e0b",
|
|
156
|
+
"status": 500,
|
|
157
|
+
"headers": {"Content-Type": "text/plain; charset=utf-8"},
|
|
158
|
+
"body": "Internal Server Error"}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
`error` about one request, agent → relay:
|
|
162
|
+
|
|
163
|
+
```json
|
|
164
|
+
{"type": "error",
|
|
165
|
+
"request_id": "7f3c2a1e-9d4b-4c8a-b2e6-1f5d3a7c9e0b",
|
|
166
|
+
"code": "upstream_unreachable",
|
|
167
|
+
"message": "connect to vlm-scheduling-service-backend.31a6638a-5c2e-4f1b-9a7d-0e3c6b8d2f41.svc.cluster.local:80 failed"}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
`error` about the connection, relay → agent, no `request_id`:
|
|
171
|
+
|
|
172
|
+
```json
|
|
173
|
+
{"type": "error",
|
|
174
|
+
"code": "invalid_message",
|
|
175
|
+
"message": "unknown type 'ping'"}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## 3. Registration and liveness
|
|
179
|
+
|
|
180
|
+
- The first frame after `101` MUST be `register`, within 10 s. Otherwise the relay closes with 1008.
|
|
181
|
+
- `workspaces` is every workspace the agent serves; an empty list is valid. `models` is what that
|
|
182
|
+
workspace's VS reports on `GET /mgmt/nodes`: the `model_name` / `model_version` pairs of nodes
|
|
183
|
+
with `status: available`, and in `replicas` how many such nodes list each pair.
|
|
184
|
+
- The relay answers every `register` with `registered`, checking each workspace on its own (reasons
|
|
185
|
+
in §5). The connection stays open whatever the outcome.
|
|
186
|
+
- The agent re-sends `register` when its list changes, and on its next poll after a
|
|
187
|
+
`platform_unavailable` rejection. The new list replaces the previous one; an agent shutting down
|
|
188
|
+
may send an empty list first so no new `request` reaches it while it drains.
|
|
189
|
+
- A new connection with the same `cluster_id` and `agent_id` replaces the old one: the relay closes
|
|
190
|
+
the old connection with 4000.
|
|
191
|
+
- The agent sends `heartbeat` every 30 s; the relay does not reply. No frame for 90 s: the relay
|
|
192
|
+
closes with 4001.
|
|
193
|
+
- Shutdown: on SIGTERM the agent finishes in-flight requests, 10 s at most, then closes with 1001.
|
|
194
|
+
The relay fails the requests still open on a connection that closes, whatever the code.
|
|
195
|
+
|
|
196
|
+
## 4. Request and response
|
|
197
|
+
|
|
198
|
+
The relay wraps the caller's HTTP request; the agent replays it against VS. The shape is generic
|
|
199
|
+
HTTP so further paths can be added without a protocol change.
|
|
200
|
+
|
|
201
|
+
- Several requests may be in flight on one connection. Responses may arrive in any order; the
|
|
202
|
+
`request_id` pairs them.
|
|
203
|
+
- The agent forwards the three allowed headers unchanged and adds `X-Request-ID: <request_id>`.
|
|
204
|
+
Nothing else is added.
|
|
205
|
+
- `timeout_s` is the agent's HTTP timeout for the call. Chat uses 100.
|
|
206
|
+
- Paths allowed in v1: `POST /api/chat`. Anything else: `error path_not_allowed`.
|
|
207
|
+
- The agent answers 422 without calling VS when the body has `stream: true`: a response is one
|
|
208
|
+
frame, so SSE cannot be carried.
|
|
209
|
+
- The agent always answers: VS unreachable → `error upstream_unreachable`; no answer within
|
|
210
|
+
`timeout_s` → `error upstream_timeout`; a `response` that would not fit a frame →
|
|
211
|
+
`error upstream_too_large`; any other body → `response` with the body as a string.
|
|
212
|
+
- Neither side logs `Authorization` or `body.img` (linker-convention `conventions/logging.md` §6).
|
|
213
|
+
|
|
214
|
+
One chat, end to end:
|
|
215
|
+
|
|
216
|
+
```text
|
|
217
|
+
agent → relay HTTP upgrade, Authorization + Sec-WebSocket-Protocol: platform-relay.v1
|
|
218
|
+
relay → agent 101 Switching Protocols
|
|
219
|
+
agent → relay {"type": "register", "agent_id": "…", "cluster_id": "aws-offline-edge", "workspaces": [{"id": "31a6…", "models": [{"name": "cr2-8b", "version": "4.5.0", "replicas": 2}]}, {"id": "7589…", "models": []}]}
|
|
220
|
+
relay → agent {"type": "registered", "accepted": ["31a6…", "7589…"], "rejected": []}
|
|
221
|
+
… Dataverse: POST http://platform-relay/31a6…/api/chat
|
|
222
|
+
relay → agent {"type": "request", "request_id": "7f3c…", "workspace_id": "31a6…", "method": "POST", "path": "/api/chat", …}
|
|
223
|
+
… agent: POST http://vlm-scheduling-service-backend.31a6….svc.cluster.local/api/chat
|
|
224
|
+
agent → relay {"type": "response", "request_id": "7f3c…", "status": 200, …}
|
|
225
|
+
… relay: 200 with VS's body back to Dataverse
|
|
226
|
+
agent → relay {"type": "heartbeat"} every 30 s throughout
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## 5. Errors and close codes
|
|
230
|
+
|
|
231
|
+
An `error` that carries a `request_id` ends that request at once. An `error` without
|
|
232
|
+
`request_id` is logged and the connection stays open.
|
|
233
|
+
|
|
234
|
+
| `code` | Sender | When |
|
|
235
|
+
|---|---|---|
|
|
236
|
+
| `invalid_message` | either | Frame is binary, not JSON, has no `type`, an unknown `type`, or fails validation |
|
|
237
|
+
| `unknown_workspace` | agent | `workspace_id` is not in the agent's current list |
|
|
238
|
+
| `path_not_allowed` | agent | `method` + `path` outside §4 |
|
|
239
|
+
| `upstream_unreachable` | agent | Connection to VS failed, or VS's answer could not be read |
|
|
240
|
+
| `upstream_timeout` | agent | VS did not answer within `timeout_s` |
|
|
241
|
+
| `upstream_too_large` | agent | VS answered, but the `response` frame would be over 16 MiB |
|
|
242
|
+
| any other value | either | Added by a later version |
|
|
243
|
+
|
|
244
|
+
`reason` values in `registered.rejected`:
|
|
245
|
+
|
|
246
|
+
| `reason` | When |
|
|
247
|
+
|---|---|
|
|
248
|
+
| `invalid_id` | `id` is not a lowercase hyphenated UUID, or appears twice |
|
|
249
|
+
| `cluster_mismatch` | Platform lists no node of `cluster_id` for that workspace |
|
|
250
|
+
| `platform_unavailable` | The relay could not ask Platform; the agent's next `register` retries |
|
|
251
|
+
|
|
252
|
+
Close codes:
|
|
253
|
+
|
|
254
|
+
| Code | Sender | When |
|
|
255
|
+
|---|---|---|
|
|
256
|
+
| 1000 | either | Normal close |
|
|
257
|
+
| 1001 | either | Shutting down. Agents reconnect after a relay 1001; the relay drops the entry after an agent 1001 |
|
|
258
|
+
| 1008 | relay | Protocol violation: no `register` within 10 s, or a first frame that is not `register` |
|
|
259
|
+
| 1009 | either | Frame over 16 MiB. Both sides enforce the limit before sending, so this is a bug |
|
|
260
|
+
| 4000 | relay | Replaced by a new connection with the same `cluster_id` and `agent_id` |
|
|
261
|
+
| 4001 | relay | No frame for 90 s |
|
|
262
|
+
|
|
263
|
+
HTTP 400, 401 and 503 at the upgrade (§1) are not close codes; the connection never opens.
|
|
264
|
+
|
|
265
|
+
## 6. Versioning
|
|
266
|
+
|
|
267
|
+
- The version is the WebSocket subprotocol name, `platform-relay.v1`. Messages carry no version field.
|
|
268
|
+
- Adding an optional field is not a new version. Receivers ignore unknown fields.
|
|
269
|
+
- Changing a field's meaning, removing one, or changing the message flow is `platform-relay.v2`.
|
|
270
|
+
- An agent may offer several versions, newest first: `platform-relay.v2, platform-relay.v1`. The
|
|
271
|
+
relay answers with the one it picked. An agent refused at the upgrade backs off and retries; it
|
|
272
|
+
does not fall back to an unversioned connection.
|
|
273
|
+
|
|
274
|
+
## 7. Limits
|
|
275
|
+
|
|
276
|
+
- 16 MiB per frame, both directions (`MAX_FRAME_BYTES`); the relay refuses a request body over
|
|
277
|
+
15 MiB before anything is sent (`MAX_BODY_BYTES`).
|
|
278
|
+
- `error.message` is cut at 200 characters (`MAX_MESSAGE_CHARS`): it quotes parts of the peer's
|
|
279
|
+
frame, and the error must fit a frame itself.
|
|
280
|
+
- Timers: `register` within 10 s of the upgrade, `heartbeat` every 30 s, stale after 90 s; the
|
|
281
|
+
agent waits `timeout_s` (100) for VS and the relay 110 s for the agent.
|
{visionai_sdk_python-2.2.0.dev5 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/_base.py
RENAMED
|
@@ -11,6 +11,29 @@ if TYPE_CHECKING:
|
|
|
11
11
|
from .auth.credentials import AsyncClientCredentials, ClientCredentials
|
|
12
12
|
|
|
13
13
|
|
|
14
|
+
_TRANSPORT_DEFAULTS = {
|
|
15
|
+
"verify_ssl": True,
|
|
16
|
+
"timeout": 10.0,
|
|
17
|
+
"max_connections": 100,
|
|
18
|
+
"max_keepalive_connections": 20,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _transport_settings(injected: object | None, **given: object) -> dict:
|
|
23
|
+
"""The settings for the httpx client the SDK builds, or an error with an injected one.
|
|
24
|
+
|
|
25
|
+
An injected client brings its own TLS, timeout and limits, so none of these
|
|
26
|
+
may be given with it: silently ignoring ``verify_ssl=False`` would surprise.
|
|
27
|
+
"""
|
|
28
|
+
passed = {name: value for name, value in given.items() if value is not None}
|
|
29
|
+
if injected is not None and passed:
|
|
30
|
+
raise ValueError(
|
|
31
|
+
"the injected http client has its own verify, timeout and limits; "
|
|
32
|
+
f"do not pass {', '.join(passed)} with it"
|
|
33
|
+
)
|
|
34
|
+
return {**_TRANSPORT_DEFAULTS, **passed}
|
|
35
|
+
|
|
36
|
+
|
|
14
37
|
class _BaseClient:
|
|
15
38
|
"""Base class for VisionAI SDK clients.
|
|
16
39
|
|
|
@@ -79,8 +102,12 @@ class _BaseClient:
|
|
|
79
102
|
|
|
80
103
|
@property
|
|
81
104
|
def credential(self) -> "ClientCredentials | AsyncClientCredentials | None":
|
|
82
|
-
"""The credential
|
|
83
|
-
|
|
105
|
+
"""The credential currently in use, or None.
|
|
106
|
+
|
|
107
|
+
Set by ``credential=`` or by ``auth.get_access_token()``; dropped by
|
|
108
|
+
``login()`` / ``set_token()``, whose token then takes over. For callers
|
|
109
|
+
that need the raw token themselves (a WebSocket upgrade, another HTTP
|
|
110
|
+
library): ``credential.get_token()`` / ``credential.invalidate(token)``."""
|
|
84
111
|
return self._credential
|
|
85
112
|
|
|
86
113
|
@staticmethod
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import httpx
|
|
2
2
|
|
|
3
|
-
from ._base import _BaseClient
|
|
3
|
+
from ._base import _BaseClient, _transport_settings
|
|
4
4
|
from ._request_attribution import merge_request_attribution
|
|
5
5
|
from .auth.async_resource import AsyncAuthResource
|
|
6
6
|
from .auth.credentials import AsyncClientCredentials
|
|
@@ -14,32 +14,49 @@ class AsyncClient(_BaseClient):
|
|
|
14
14
|
auth_url: str,
|
|
15
15
|
vlm_url: str | None = None,
|
|
16
16
|
allowed_issuers: list[str] | None = None,
|
|
17
|
-
verify_ssl: bool =
|
|
18
|
-
timeout: float =
|
|
19
|
-
max_connections: int =
|
|
20
|
-
max_keepalive_connections: int =
|
|
17
|
+
verify_ssl: bool | None = None,
|
|
18
|
+
timeout: float | None = None,
|
|
19
|
+
max_connections: int | None = None,
|
|
20
|
+
max_keepalive_connections: int | None = None,
|
|
21
21
|
credential: AsyncClientCredentials | None = None,
|
|
22
22
|
http_client: httpx.AsyncClient | None = None,
|
|
23
23
|
) -> None:
|
|
24
|
-
"""See ``_BaseClient
|
|
25
|
-
(tests, shared pools)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
"""See ``_BaseClient``. ``http_client`` is an httpx.AsyncClient to send through
|
|
25
|
+
(tests, shared pools): its own TLS, timeout and limits apply, so
|
|
26
|
+
``verify_ssl`` / ``timeout`` / ``max_connections`` /
|
|
27
|
+
``max_keepalive_connections`` cannot be given with it (``ValueError``);
|
|
28
|
+
the client closes only the one it created."""
|
|
29
|
+
if credential is not None and not isinstance(
|
|
30
|
+
credential, AsyncClientCredentials
|
|
31
|
+
):
|
|
32
|
+
raise TypeError(
|
|
33
|
+
"AsyncClient takes an AsyncClientCredentials; Client takes a ClientCredentials"
|
|
34
|
+
)
|
|
35
|
+
settings = _transport_settings(
|
|
36
|
+
http_client,
|
|
30
37
|
verify_ssl=verify_ssl,
|
|
31
38
|
timeout=timeout,
|
|
32
39
|
max_connections=max_connections,
|
|
33
40
|
max_keepalive_connections=max_keepalive_connections,
|
|
41
|
+
)
|
|
42
|
+
super().__init__(
|
|
43
|
+
auth_url=auth_url,
|
|
44
|
+
vlm_url=vlm_url,
|
|
45
|
+
allowed_issuers=allowed_issuers,
|
|
34
46
|
credential=credential,
|
|
47
|
+
**settings,
|
|
35
48
|
)
|
|
36
|
-
self._client =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
49
|
+
self._client = (
|
|
50
|
+
http_client
|
|
51
|
+
if http_client is not None
|
|
52
|
+
else httpx.AsyncClient(
|
|
53
|
+
verify=self.verify_ssl,
|
|
54
|
+
timeout=self.timeout,
|
|
55
|
+
limits=httpx.Limits(
|
|
56
|
+
max_connections=self.max_connections,
|
|
57
|
+
max_keepalive_connections=self.max_keepalive_connections,
|
|
58
|
+
),
|
|
59
|
+
)
|
|
43
60
|
)
|
|
44
61
|
self._http_owner = http_client is None # a client we built is ours to close
|
|
45
62
|
# Register the different function resource
|