visionai-sdk-python 2.2.0.dev6__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.dev6 → visionai_sdk_python-2.2.0.dev7}/PKG-INFO +8 -6
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/README.md +7 -5
- visionai_sdk_python-2.2.0.dev7/docs/relay-protocol.md +281 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/relay/__init__.py +3 -2
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/relay/examples/__init__.py +2 -2
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/relay/protocol.py +3 -4
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python.egg-info/PKG-INFO +8 -6
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python.egg-info/SOURCES.txt +1 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python.egg-info/scm_file_list.json +1 -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.dev6 → visionai_sdk_python-2.2.0.dev7}/tests/relay/test_protocol.py +6 -7
- visionai_sdk_python-2.2.0.dev6/src/visionai_sdk_python.egg-info/scm_version.json +0 -8
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/.github/dependabot.yml +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/.github/workflows/ci.yml +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/.github/workflows/publish.yml +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/.gitignore +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/pyproject.toml +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/setup.cfg +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/__init__.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/_base.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/_jwt_verifier.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/_request_attribution.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/_source_header.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/async_client.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/auth/__init__.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/auth/_mixin.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/auth/async_resource.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/auth/credentials.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/auth/models.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/auth/resource.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/client.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/constants.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/endpoints.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/exceptions.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/instrumentation.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/py.typed +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/relay/examples/error_connection.json +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/relay/examples/error_request.json +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/relay/examples/heartbeat.json +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/relay/examples/register.json +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/relay/examples/registered.json +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/relay/examples/request.json +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/relay/examples/response.json +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/relay/examples/response_text.json +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/vlm/__init__.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/vlm/_mixin.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/vlm/async_resource.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/vlm/models.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/vlm/preprocess.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/vlm/resource.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python.egg-info/dependency_links.txt +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python.egg-info/requires.txt +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python.egg-info/top_level.txt +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/tests/__init__.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/tests/constants.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/tests/relay/__init__.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/tests/test__base.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/tests/test_async_client.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/tests/test_client.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/tests/test_credentials.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/tests/test_instrumentation.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/tests/test_request.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/tests/test_transport_options.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/tests/test_vlm_preprocess.py +0 -0
- {visionai_sdk_python-2.2.0.dev6 → 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
|
|
@@ -177,11 +177,13 @@ authentication wins. `vlm_url` is optional for clients that only authenticate.
|
|
|
177
177
|
`visionai_sdk_python.relay` holds the wire format between platform-relay and
|
|
178
178
|
platform-edge-agent: the frame models, the constants and `parse_agent_frame()` /
|
|
179
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/
|
|
182
|
-
copy
|
|
183
|
-
|
|
184
|
-
|
|
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.
|
|
185
187
|
|
|
186
188
|
## VLM Inference
|
|
187
189
|
|
|
@@ -159,11 +159,13 @@ authentication wins. `vlm_url` is optional for clients that only authenticate.
|
|
|
159
159
|
`visionai_sdk_python.relay` holds the wire format between platform-relay and
|
|
160
160
|
platform-edge-agent: the frame models, the constants and `parse_agent_frame()` /
|
|
161
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/
|
|
164
|
-
copy
|
|
165
|
-
|
|
166
|
-
|
|
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.
|
|
167
169
|
|
|
168
170
|
## VLM Inference
|
|
169
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.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"""The platform-relay wire protocol, shared by platform-relay and platform-edge-agent.
|
|
2
2
|
|
|
3
|
-
Internal to the platform
|
|
4
|
-
``docs/adr/0001-relay-protocol.md
|
|
3
|
+
Internal to the platform. The wire format is specified in ``docs/relay-protocol.md``
|
|
4
|
+
of this repository; platform-service's ``docs/adr/0001-relay-protocol.md`` records the
|
|
5
|
+
decisions around it. See :mod:`.protocol`.
|
|
5
6
|
"""
|
|
6
7
|
|
|
7
8
|
from .protocol import (
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""The
|
|
1
|
+
"""The wire-format spec's JSON examples, shipped so every implementation tests against the same frames.
|
|
2
2
|
|
|
3
3
|
``example("register")`` is the parsed object, ``example_text("register")`` the wire text.
|
|
4
4
|
"""
|
|
@@ -19,7 +19,7 @@ NAMES = (
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
def example_text(name: str) -> str:
|
|
22
|
-
"""One
|
|
22
|
+
"""One spec example as the text that goes over the wire."""
|
|
23
23
|
return (files(__package__) / f"{name}.json").read_text(encoding="utf-8")
|
|
24
24
|
|
|
25
25
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"""Wire format between platform-relay and platform-edge-agent.
|
|
2
2
|
|
|
3
|
-
The spec is
|
|
4
|
-
the one implementation both sides import. Frames are JSON objects told apart by
|
|
3
|
+
The spec is ``docs/relay-protocol.md`` in this repository (the decisions behind it:
|
|
4
|
+
platform-service's ADR 0001); this module is the one implementation both sides import. Frames are JSON objects told apart by
|
|
5
5
|
``type``. Receivers ignore unknown fields, and the string-typed ``reason`` /
|
|
6
6
|
``code`` fields accept values they do not know, so either side can be upgraded
|
|
7
7
|
first.
|
|
@@ -71,8 +71,7 @@ class Frame(BaseModel):
|
|
|
71
71
|
class ModelEntry(Frame):
|
|
72
72
|
name: str
|
|
73
73
|
version: str
|
|
74
|
-
|
|
75
|
-
replicas: int | None = Field(default=None, ge=0)
|
|
74
|
+
replicas: int = Field(ge=0)
|
|
76
75
|
|
|
77
76
|
|
|
78
77
|
class WorkspaceEntry(Frame):
|
|
@@ -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
|
|
@@ -177,11 +177,13 @@ authentication wins. `vlm_url` is optional for clients that only authenticate.
|
|
|
177
177
|
`visionai_sdk_python.relay` holds the wire format between platform-relay and
|
|
178
178
|
platform-edge-agent: the frame models, the constants and `parse_agent_frame()` /
|
|
179
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/
|
|
182
|
-
copy
|
|
183
|
-
|
|
184
|
-
|
|
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.
|
|
185
187
|
|
|
186
188
|
## VLM Inference
|
|
187
189
|
|
{visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/tests/relay/test_protocol.py
RENAMED
|
@@ -82,13 +82,12 @@ def test_unknown_fields_are_ignored_on_both_sides():
|
|
|
82
82
|
)
|
|
83
83
|
|
|
84
84
|
|
|
85
|
-
def
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
assert frame.workspaces[0].models[0].replicas is None
|
|
85
|
+
def test_register_without_replicas_is_invalid():
|
|
86
|
+
with pytest.raises(InvalidFrame):
|
|
87
|
+
parse_agent_frame(
|
|
88
|
+
'{"type": "register", "agent_id": "a", "cluster_id": "c",'
|
|
89
|
+
' "workspaces": [{"id": "x", "models": [{"name": "m", "version": "1"}]}]}'
|
|
90
|
+
)
|
|
92
91
|
|
|
93
92
|
|
|
94
93
|
def test_unknown_reasons_and_codes_are_accepted_as_strings():
|
|
File without changes
|
|
File without changes
|
{visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/.github/workflows/publish.yml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/_base.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/client.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/src/visionai_sdk_python/py.typed
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/tests/test_async_client.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/tests/test_instrumentation.py
RENAMED
|
File without changes
|
|
File without changes
|
{visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/tests/test_transport_options.py
RENAMED
|
File without changes
|
{visionai_sdk_python-2.2.0.dev6 → visionai_sdk_python-2.2.0.dev7}/tests/test_vlm_preprocess.py
RENAMED
|
File without changes
|
|
File without changes
|