cyberwave-contracts 0.1.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.
- cyberwave_contracts-0.1.0/LICENSE +201 -0
- cyberwave_contracts-0.1.0/PKG-INFO +161 -0
- cyberwave_contracts-0.1.0/README.md +141 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts/__init__.py +78 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts/_generate.py +550 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts/locomotion.py +390 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts/manifest.py +261 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts/manifest.yml +181 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts/models/__init__.py +60 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts/models/_scalars.py +43 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts/models/aerial_velocity_command_v1.py +48 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts/models/locomotion_velocity_command_v1.py +46 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts/models/policy_artifact_manifest_v1.py +41 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts/models/simulation_policy_manifest_v1.py +114 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts/models/source_type_envelope_v1.py +20 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts/models/twin_command_response_v1.py +49 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts/py.typed +1 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts/schemas/aerial.velocity_command.v1.schema.json +65 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts/schemas/locomotion.velocity_command.v1.schema.json +67 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts/schemas/policy_artifact_manifest.v1.schema.json +75 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts/schemas/simulation_policy_manifest.v1.schema.json +140 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts/schemas/source_type.envelope.v1.schema.json +24 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts/schemas/twin.command_response.v1.schema.json +48 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts/source_type.py +72 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts/source_type_axes.yml +116 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts.egg-info/PKG-INFO +161 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts.egg-info/SOURCES.txt +34 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts.egg-info/dependency_links.txt +1 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts.egg-info/requires.txt +6 -0
- cyberwave_contracts-0.1.0/cyberwave_contracts.egg-info/top_level.txt +1 -0
- cyberwave_contracts-0.1.0/pyproject.toml +48 -0
- cyberwave_contracts-0.1.0/setup.cfg +4 -0
- cyberwave_contracts-0.1.0/tests/test_locomotion.py +192 -0
- cyberwave_contracts-0.1.0/tests/test_manifest.py +21 -0
- cyberwave_contracts-0.1.0/tests/test_source_type.py +99 -0
- cyberwave_contracts-0.1.0/tests/test_source_type_conformance_monitor.py +114 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Cyberwave S.p.a.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cyberwave-contracts
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Payload and configuration contracts shared by the Cyberwave backend, SDK, and edge components
|
|
5
|
+
Author-email: Cyberwave Team <info@cyberwave.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://cyberwave.com
|
|
8
|
+
Project-URL: Documentation, https://docs.cyberwave.com
|
|
9
|
+
Project-URL: Repository, https://github.com/cyberwave-os/cyberwave-contracts
|
|
10
|
+
Keywords: robotics,contracts,json-schema,pydantic,cyberwave
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: pydantic>=2
|
|
15
|
+
Requires-Dist: pyyaml>=6.0
|
|
16
|
+
Provides-Extra: dev
|
|
17
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
18
|
+
Requires-Dist: ruff==0.9.9; extra == "dev"
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# cyberwave-contracts
|
|
22
|
+
|
|
23
|
+
Payload and configuration contracts shared by the Cyberwave backend, SDK, edge
|
|
24
|
+
components and simulator.
|
|
25
|
+
|
|
26
|
+
A **contract** is a payload shape that more than one component depends on. Each is
|
|
27
|
+
defined once as a JSON Schema, and a pydantic model is generated from it — so the
|
|
28
|
+
code that validates a payload cannot drift from the schema that documents it.
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install cyberwave-contracts
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
This repository is a read-only mirror of the `cyberwave-contracts/` directory of
|
|
35
|
+
the Cyberwave monorepo, published on every production release; issues are
|
|
36
|
+
welcome, but changes land upstream. Inside the monorepo the backend, the edge
|
|
37
|
+
images and the simulator install the package from the checkout rather than from
|
|
38
|
+
PyPI, and the schemas are also served at `GET /api/v1/contracts`.
|
|
39
|
+
|
|
40
|
+
## Validating a payload
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from cyberwave_contracts import MODELS_BY_CONTRACT_ID
|
|
44
|
+
|
|
45
|
+
model = MODELS_BY_CONTRACT_ID["locomotion.velocity_command.v1"]
|
|
46
|
+
command = model.model_validate(payload) # raises ValidationError if malformed
|
|
47
|
+
|
|
48
|
+
command.linear_x # typed float, autocompletes
|
|
49
|
+
command.gait # Literal["walk", "trot", "stand"]
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Every contract payload names itself in a required field, so you never have to
|
|
53
|
+
infer which contract you are holding from the shape of the fields:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
model = MODELS_BY_CONTRACT_ID[payload["contract"]]
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## What ships
|
|
60
|
+
|
|
61
|
+
| | |
|
|
62
|
+
| --- | --- |
|
|
63
|
+
| `cyberwave_contracts.schemas` | the JSON Schemas, usable from any language |
|
|
64
|
+
| `cyberwave_contracts.models` | generated pydantic models, one per schema |
|
|
65
|
+
| `cyberwave_contracts.manifest` | the index: every contract, its owner, and where it is mirrored |
|
|
66
|
+
| `cyberwave_contracts.source_type` | the authoritative decomposition of legacy `source_type` provenance |
|
|
67
|
+
| `cyberwave_contracts.locomotion` | the locomotion and aerial velocity commands: normalising, clamping, building and stopping them (standard library only) |
|
|
68
|
+
|
|
69
|
+
The schemas are installed with the package, so validation works offline and
|
|
70
|
+
against a pinned version rather than whatever a server happened to return.
|
|
71
|
+
|
|
72
|
+
They are also served unauthenticated at `GET /api/v1/contracts` for non-Python
|
|
73
|
+
consumers.
|
|
74
|
+
|
|
75
|
+
## Contracts
|
|
76
|
+
|
|
77
|
+
| id | what it carries |
|
|
78
|
+
| --- | --- |
|
|
79
|
+
| `locomotion.velocity_command.v1` | body-frame velocity command for ground robots |
|
|
80
|
+
| `aerial.velocity_command.v1` | the same for free-body / aerial platforms |
|
|
81
|
+
| `policy_artifact_manifest.v1` | the files making up a policy artifact |
|
|
82
|
+
| `simulation_policy_manifest.v1` | policy bindings exported for a simulator |
|
|
83
|
+
| `source_type.envelope.v1` | flat transport overlay requiring `source_type` |
|
|
84
|
+
| `twin.command_response.v1` | the reply to a twin command sent over MQTT v5 request/response |
|
|
85
|
+
|
|
86
|
+
`GET /api/v1/contracts` lists what a given deployment serves.
|
|
87
|
+
|
|
88
|
+
## Transport envelope
|
|
89
|
+
|
|
90
|
+
MQTT payloads keep their existing flat JSON shape. The v1 transport envelope
|
|
91
|
+
requires only `source_type` and preserves every domain field beside it:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from cyberwave_contracts import SourceTypeEnvelopeV1
|
|
95
|
+
|
|
96
|
+
envelope = SourceTypeEnvelopeV1.model_validate(
|
|
97
|
+
{"source_type": "tele", "command": "move_forward", "data": {}}
|
|
98
|
+
)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Domain payload models inherit this generated model, so one `payload_schema`
|
|
102
|
+
validation checks both the routing discriminator and topic-specific fields. This
|
|
103
|
+
keeps routing metadata owned by the transport layer without nesting or duplicating
|
|
104
|
+
it in every domain contract. The semantic decomposition remains in
|
|
105
|
+
`source_type_axes.yml` and is checked against the schema vocabulary.
|
|
106
|
+
|
|
107
|
+
## Versioning
|
|
108
|
+
|
|
109
|
+
A contract id ends in its version (`…v1`). Within a version, changes are
|
|
110
|
+
**additive only** — a payload valid against `v1` stays valid. A field that becomes
|
|
111
|
+
required, an enum value that is removed, or a type that narrows is a new version.
|
|
112
|
+
|
|
113
|
+
Contract roots accept unknown properties, so a newer publisher can add fields your
|
|
114
|
+
version has not heard of, and your model keeps them rather than dropping them on a
|
|
115
|
+
round-trip.
|
|
116
|
+
|
|
117
|
+
## Development
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
make models # regenerate the pydantic models from the schemas
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Generated output is committed, so consumers need no build step. CI fails if a
|
|
124
|
+
schema changes without the models being regenerated.
|
|
125
|
+
|
|
126
|
+
Runtime dependencies are deliberately limited to `pydantic` and `pyyaml`: this
|
|
127
|
+
package is imported by every Cyberwave component, so anything added here is added
|
|
128
|
+
to all of them.
|
|
129
|
+
|
|
130
|
+
## License
|
|
131
|
+
|
|
132
|
+
Apache-2.0
|
|
133
|
+
|
|
134
|
+
## Command request/response over MQTT v5
|
|
135
|
+
|
|
136
|
+
A twin command (`{prefix}cyberwave/twin/{twin_uuid}/command`) is fire-and-forget
|
|
137
|
+
over MQTT 3.1.1. Over MQTT v5 a caller can ask for the outcome instead of
|
|
138
|
+
guessing it:
|
|
139
|
+
|
|
140
|
+
1. **Requester** connects with MQTT v5 and subscribes, for each twin it will
|
|
141
|
+
command, to its own reply inbox under that twin:
|
|
142
|
+
`{prefix}cyberwave/twin/{twin_uuid}/command/{client_id}/response`. The broker
|
|
143
|
+
lets only the client with that client id read it, so other readers of the
|
|
144
|
+
twin (including `twin/{twin_uuid}/#` subscribers) never see the reply.
|
|
145
|
+
2. It publishes the command with two v5 properties:
|
|
146
|
+
- **Response Topic** `{prefix}cyberwave/twin/{twin_uuid}/command/{client_id}/response`
|
|
147
|
+
- **Correlation Data**: opaque bytes, unique per request (e.g. a UUID).
|
|
148
|
+
3. **Handler** (the twin's driver) publishes exactly one
|
|
149
|
+
`twin.command_response.v1` payload to that Response Topic, QoS 1, echoing the
|
|
150
|
+
Correlation Data. Publishing there is an ordinary write to the twin, so one
|
|
151
|
+
twin's driver cannot answer for another; the handler also ignores a Response
|
|
152
|
+
Topic that is not this twin's reply inbox.
|
|
153
|
+
4. The requester matches the reply by Correlation Data. `status` tells it what
|
|
154
|
+
happened: `accepted`, `rejected` (refused before reaching the device),
|
|
155
|
+
`denied` (the device refused, with `reason` and the device's `messages`) or
|
|
156
|
+
`timeout`.
|
|
157
|
+
|
|
158
|
+
A request without a Response Topic is handled exactly as before and gets no
|
|
159
|
+
reply, so MQTT 3.1.1 publishers are unaffected. Requesters should still bound
|
|
160
|
+
their wait: a handler that predates this contract never replies.
|
|
161
|
+
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# cyberwave-contracts
|
|
2
|
+
|
|
3
|
+
Payload and configuration contracts shared by the Cyberwave backend, SDK, edge
|
|
4
|
+
components and simulator.
|
|
5
|
+
|
|
6
|
+
A **contract** is a payload shape that more than one component depends on. Each is
|
|
7
|
+
defined once as a JSON Schema, and a pydantic model is generated from it — so the
|
|
8
|
+
code that validates a payload cannot drift from the schema that documents it.
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pip install cyberwave-contracts
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
This repository is a read-only mirror of the `cyberwave-contracts/` directory of
|
|
15
|
+
the Cyberwave monorepo, published on every production release; issues are
|
|
16
|
+
welcome, but changes land upstream. Inside the monorepo the backend, the edge
|
|
17
|
+
images and the simulator install the package from the checkout rather than from
|
|
18
|
+
PyPI, and the schemas are also served at `GET /api/v1/contracts`.
|
|
19
|
+
|
|
20
|
+
## Validating a payload
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from cyberwave_contracts import MODELS_BY_CONTRACT_ID
|
|
24
|
+
|
|
25
|
+
model = MODELS_BY_CONTRACT_ID["locomotion.velocity_command.v1"]
|
|
26
|
+
command = model.model_validate(payload) # raises ValidationError if malformed
|
|
27
|
+
|
|
28
|
+
command.linear_x # typed float, autocompletes
|
|
29
|
+
command.gait # Literal["walk", "trot", "stand"]
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Every contract payload names itself in a required field, so you never have to
|
|
33
|
+
infer which contract you are holding from the shape of the fields:
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
model = MODELS_BY_CONTRACT_ID[payload["contract"]]
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## What ships
|
|
40
|
+
|
|
41
|
+
| | |
|
|
42
|
+
| --- | --- |
|
|
43
|
+
| `cyberwave_contracts.schemas` | the JSON Schemas, usable from any language |
|
|
44
|
+
| `cyberwave_contracts.models` | generated pydantic models, one per schema |
|
|
45
|
+
| `cyberwave_contracts.manifest` | the index: every contract, its owner, and where it is mirrored |
|
|
46
|
+
| `cyberwave_contracts.source_type` | the authoritative decomposition of legacy `source_type` provenance |
|
|
47
|
+
| `cyberwave_contracts.locomotion` | the locomotion and aerial velocity commands: normalising, clamping, building and stopping them (standard library only) |
|
|
48
|
+
|
|
49
|
+
The schemas are installed with the package, so validation works offline and
|
|
50
|
+
against a pinned version rather than whatever a server happened to return.
|
|
51
|
+
|
|
52
|
+
They are also served unauthenticated at `GET /api/v1/contracts` for non-Python
|
|
53
|
+
consumers.
|
|
54
|
+
|
|
55
|
+
## Contracts
|
|
56
|
+
|
|
57
|
+
| id | what it carries |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| `locomotion.velocity_command.v1` | body-frame velocity command for ground robots |
|
|
60
|
+
| `aerial.velocity_command.v1` | the same for free-body / aerial platforms |
|
|
61
|
+
| `policy_artifact_manifest.v1` | the files making up a policy artifact |
|
|
62
|
+
| `simulation_policy_manifest.v1` | policy bindings exported for a simulator |
|
|
63
|
+
| `source_type.envelope.v1` | flat transport overlay requiring `source_type` |
|
|
64
|
+
| `twin.command_response.v1` | the reply to a twin command sent over MQTT v5 request/response |
|
|
65
|
+
|
|
66
|
+
`GET /api/v1/contracts` lists what a given deployment serves.
|
|
67
|
+
|
|
68
|
+
## Transport envelope
|
|
69
|
+
|
|
70
|
+
MQTT payloads keep their existing flat JSON shape. The v1 transport envelope
|
|
71
|
+
requires only `source_type` and preserves every domain field beside it:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from cyberwave_contracts import SourceTypeEnvelopeV1
|
|
75
|
+
|
|
76
|
+
envelope = SourceTypeEnvelopeV1.model_validate(
|
|
77
|
+
{"source_type": "tele", "command": "move_forward", "data": {}}
|
|
78
|
+
)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Domain payload models inherit this generated model, so one `payload_schema`
|
|
82
|
+
validation checks both the routing discriminator and topic-specific fields. This
|
|
83
|
+
keeps routing metadata owned by the transport layer without nesting or duplicating
|
|
84
|
+
it in every domain contract. The semantic decomposition remains in
|
|
85
|
+
`source_type_axes.yml` and is checked against the schema vocabulary.
|
|
86
|
+
|
|
87
|
+
## Versioning
|
|
88
|
+
|
|
89
|
+
A contract id ends in its version (`…v1`). Within a version, changes are
|
|
90
|
+
**additive only** — a payload valid against `v1` stays valid. A field that becomes
|
|
91
|
+
required, an enum value that is removed, or a type that narrows is a new version.
|
|
92
|
+
|
|
93
|
+
Contract roots accept unknown properties, so a newer publisher can add fields your
|
|
94
|
+
version has not heard of, and your model keeps them rather than dropping them on a
|
|
95
|
+
round-trip.
|
|
96
|
+
|
|
97
|
+
## Development
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
make models # regenerate the pydantic models from the schemas
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Generated output is committed, so consumers need no build step. CI fails if a
|
|
104
|
+
schema changes without the models being regenerated.
|
|
105
|
+
|
|
106
|
+
Runtime dependencies are deliberately limited to `pydantic` and `pyyaml`: this
|
|
107
|
+
package is imported by every Cyberwave component, so anything added here is added
|
|
108
|
+
to all of them.
|
|
109
|
+
|
|
110
|
+
## License
|
|
111
|
+
|
|
112
|
+
Apache-2.0
|
|
113
|
+
|
|
114
|
+
## Command request/response over MQTT v5
|
|
115
|
+
|
|
116
|
+
A twin command (`{prefix}cyberwave/twin/{twin_uuid}/command`) is fire-and-forget
|
|
117
|
+
over MQTT 3.1.1. Over MQTT v5 a caller can ask for the outcome instead of
|
|
118
|
+
guessing it:
|
|
119
|
+
|
|
120
|
+
1. **Requester** connects with MQTT v5 and subscribes, for each twin it will
|
|
121
|
+
command, to its own reply inbox under that twin:
|
|
122
|
+
`{prefix}cyberwave/twin/{twin_uuid}/command/{client_id}/response`. The broker
|
|
123
|
+
lets only the client with that client id read it, so other readers of the
|
|
124
|
+
twin (including `twin/{twin_uuid}/#` subscribers) never see the reply.
|
|
125
|
+
2. It publishes the command with two v5 properties:
|
|
126
|
+
- **Response Topic** `{prefix}cyberwave/twin/{twin_uuid}/command/{client_id}/response`
|
|
127
|
+
- **Correlation Data**: opaque bytes, unique per request (e.g. a UUID).
|
|
128
|
+
3. **Handler** (the twin's driver) publishes exactly one
|
|
129
|
+
`twin.command_response.v1` payload to that Response Topic, QoS 1, echoing the
|
|
130
|
+
Correlation Data. Publishing there is an ordinary write to the twin, so one
|
|
131
|
+
twin's driver cannot answer for another; the handler also ignores a Response
|
|
132
|
+
Topic that is not this twin's reply inbox.
|
|
133
|
+
4. The requester matches the reply by Correlation Data. `status` tells it what
|
|
134
|
+
happened: `accepted`, `rejected` (refused before reaching the device),
|
|
135
|
+
`denied` (the device refused, with `reason` and the device's `messages`) or
|
|
136
|
+
`timeout`.
|
|
137
|
+
|
|
138
|
+
A request without a Response Topic is handled exactly as before and gets no
|
|
139
|
+
reply, so MQTT 3.1.1 publishers are unaffected. Requesters should still bound
|
|
140
|
+
their wait: a handler that predates this contract never replies.
|
|
141
|
+
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""Cyberwave payload and configuration contracts.
|
|
2
|
+
|
|
3
|
+
A contract is a payload shape that more than one component depends on. Each is
|
|
4
|
+
defined once as a JSON Schema in :mod:`cyberwave_contracts.schemas`, indexed in
|
|
5
|
+
``manifest.yml``, and generated into a pydantic model in
|
|
6
|
+
:mod:`cyberwave_contracts.models`.
|
|
7
|
+
|
|
8
|
+
Validate a payload you received::
|
|
9
|
+
|
|
10
|
+
from cyberwave_contracts import MODELS_BY_CONTRACT_ID
|
|
11
|
+
|
|
12
|
+
model = MODELS_BY_CONTRACT_ID["locomotion.velocity_command.v1"]
|
|
13
|
+
command = model.model_validate(payload) # raises if it does not conform
|
|
14
|
+
|
|
15
|
+
Complete payload contracts name themselves in a required const field, so a
|
|
16
|
+
consumer never has to infer which contract it is holding from its shape. Overlay
|
|
17
|
+
contracts constrain shared fields on those payloads without adding another wire
|
|
18
|
+
identity field.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from cyberwave_contracts.manifest import (
|
|
22
|
+
MANIFEST_PATH,
|
|
23
|
+
SCHEMAS_DIR,
|
|
24
|
+
SHAPE_OWNERSHIP,
|
|
25
|
+
Contract,
|
|
26
|
+
Mirror,
|
|
27
|
+
load_contracts,
|
|
28
|
+
validate_ownership,
|
|
29
|
+
)
|
|
30
|
+
from cyberwave_contracts.models import (
|
|
31
|
+
MODELS_BY_CONTRACT_ID,
|
|
32
|
+
AerialVelocityCommandV1,
|
|
33
|
+
ArtifactFile,
|
|
34
|
+
LocomotionVelocityCommandV1,
|
|
35
|
+
PolicyArtifactManifestV1,
|
|
36
|
+
PolicyBinding,
|
|
37
|
+
PolicyBindingPolicyConfig,
|
|
38
|
+
PolicyBindingPolicyConfigNavigationCommandMinimums,
|
|
39
|
+
PolicyBindingPolicyRef,
|
|
40
|
+
SimulationPolicyManifestV1,
|
|
41
|
+
SourceTypeEnvelopeV1,
|
|
42
|
+
)
|
|
43
|
+
from cyberwave_contracts.source_type import (
|
|
44
|
+
SOURCE_TYPE_AXES_PATH,
|
|
45
|
+
SOURCE_TYPE_VALUES,
|
|
46
|
+
SourceType,
|
|
47
|
+
load_source_type_axes,
|
|
48
|
+
source_types_where,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
__version__ = "0.1.0"
|
|
52
|
+
|
|
53
|
+
__all__ = [
|
|
54
|
+
"MANIFEST_PATH",
|
|
55
|
+
"MODELS_BY_CONTRACT_ID",
|
|
56
|
+
"SCHEMAS_DIR",
|
|
57
|
+
"SOURCE_TYPE_AXES_PATH",
|
|
58
|
+
"SOURCE_TYPE_VALUES",
|
|
59
|
+
"SHAPE_OWNERSHIP",
|
|
60
|
+
"AerialVelocityCommandV1",
|
|
61
|
+
"ArtifactFile",
|
|
62
|
+
"Contract",
|
|
63
|
+
"LocomotionVelocityCommandV1",
|
|
64
|
+
"Mirror",
|
|
65
|
+
"PolicyArtifactManifestV1",
|
|
66
|
+
"PolicyBinding",
|
|
67
|
+
"PolicyBindingPolicyConfig",
|
|
68
|
+
"PolicyBindingPolicyConfigNavigationCommandMinimums",
|
|
69
|
+
"PolicyBindingPolicyRef",
|
|
70
|
+
"SimulationPolicyManifestV1",
|
|
71
|
+
"SourceType",
|
|
72
|
+
"SourceTypeEnvelopeV1",
|
|
73
|
+
"__version__",
|
|
74
|
+
"load_contracts",
|
|
75
|
+
"load_source_type_axes",
|
|
76
|
+
"source_types_where",
|
|
77
|
+
"validate_ownership",
|
|
78
|
+
]
|