armnet-core 0.1.0__py3-none-any.whl
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.
- armnet_core/__init__.py +78 -0
- armnet_core/auth.py +4 -0
- armnet_core/enums.py +33 -0
- armnet_core/models.py +632 -0
- armnet_core-0.1.0.dist-info/METADATA +36 -0
- armnet_core-0.1.0.dist-info/RECORD +7 -0
- armnet_core-0.1.0.dist-info/WHEEL +4 -0
armnet_core/__init__.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""Shared wire types for the armnet platform.
|
|
2
|
+
|
|
3
|
+
Single source of truth for everything that crosses a component boundary
|
|
4
|
+
(orchestrator HTTP API request/response bodies, NATS message envelopes,
|
|
5
|
+
runtime SDK return values).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from armnet_core.auth import API_KEY_ENV, API_KEY_HEADER
|
|
9
|
+
from armnet_core.enums import DEFAULT_EMBODIMENT, DEFAULT_TASK, Embodiment, Task
|
|
10
|
+
from armnet_core.models import (
|
|
11
|
+
CellRuntimeStatus,
|
|
12
|
+
CellStatus,
|
|
13
|
+
CellStatusSummary,
|
|
14
|
+
EmbodimentInfo,
|
|
15
|
+
EmbodimentList,
|
|
16
|
+
Job,
|
|
17
|
+
JobResult,
|
|
18
|
+
JobSpec,
|
|
19
|
+
JobStatus,
|
|
20
|
+
JobStatusTransition,
|
|
21
|
+
RegistryCredentials,
|
|
22
|
+
RemoteExecutionError,
|
|
23
|
+
RobotArmConfig,
|
|
24
|
+
RobotCellConfig,
|
|
25
|
+
SecretCreateRequest,
|
|
26
|
+
SecretInfo,
|
|
27
|
+
SecretList,
|
|
28
|
+
TaskInfo,
|
|
29
|
+
TaskList,
|
|
30
|
+
TELEOP_EVENT_NEXT_EPISODE,
|
|
31
|
+
TELEOP_EVENT_RERECORD_EPISODE,
|
|
32
|
+
TELEOP_EVENT_STOP_RECORDING,
|
|
33
|
+
TELEOP_EVENTS,
|
|
34
|
+
TeleopAction,
|
|
35
|
+
TeleopEvent,
|
|
36
|
+
TerminalStatus,
|
|
37
|
+
VolumeCredentials,
|
|
38
|
+
WhoAmI,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
__all__ = [
|
|
42
|
+
"API_KEY_ENV",
|
|
43
|
+
"API_KEY_HEADER",
|
|
44
|
+
"DEFAULT_EMBODIMENT",
|
|
45
|
+
"DEFAULT_TASK",
|
|
46
|
+
"Embodiment",
|
|
47
|
+
"CellRuntimeStatus",
|
|
48
|
+
"CellStatus",
|
|
49
|
+
"CellStatusSummary",
|
|
50
|
+
"EmbodimentInfo",
|
|
51
|
+
"EmbodimentList",
|
|
52
|
+
"Job",
|
|
53
|
+
"JobResult",
|
|
54
|
+
"JobStatusTransition",
|
|
55
|
+
"JobSpec",
|
|
56
|
+
"JobStatus",
|
|
57
|
+
"RegistryCredentials",
|
|
58
|
+
"RemoteExecutionError",
|
|
59
|
+
"RobotArmConfig",
|
|
60
|
+
"RobotCellConfig",
|
|
61
|
+
"SecretCreateRequest",
|
|
62
|
+
"SecretInfo",
|
|
63
|
+
"SecretList",
|
|
64
|
+
"Task",
|
|
65
|
+
"TaskInfo",
|
|
66
|
+
"TaskList",
|
|
67
|
+
"TELEOP_EVENT_NEXT_EPISODE",
|
|
68
|
+
"TELEOP_EVENT_RERECORD_EPISODE",
|
|
69
|
+
"TELEOP_EVENT_STOP_RECORDING",
|
|
70
|
+
"TELEOP_EVENTS",
|
|
71
|
+
"TeleopAction",
|
|
72
|
+
"TeleopEvent",
|
|
73
|
+
"TerminalStatus",
|
|
74
|
+
"VolumeCredentials",
|
|
75
|
+
"WhoAmI",
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
__version__ = "0.1.0"
|
armnet_core/auth.py
ADDED
armnet_core/enums.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Embodiment and Task wire-type aliases.
|
|
2
|
+
|
|
3
|
+
Embodiments and tasks are identified by stable wire-format string slugs that
|
|
4
|
+
appear in HTTP request bodies, NATS subjects, env vars injected into customer
|
|
5
|
+
containers, and cell configuration (e.g. ``"lerobot/so-101"``,
|
|
6
|
+
``"assemble_block_tower"``).
|
|
7
|
+
|
|
8
|
+
The *set of valid* embodiments and tasks is **not** hard-coded here. It lives
|
|
9
|
+
in the orchestrator's Postgres database (the ``embodiments`` and ``tasks``
|
|
10
|
+
tables; see ``db/``), which is the single source of truth. The orchestrator
|
|
11
|
+
validates incoming jobs against those tables and rejects unknown values with
|
|
12
|
+
HTTP 400. Adding a new embodiment or task is a database insert, not a code
|
|
13
|
+
change.
|
|
14
|
+
|
|
15
|
+
``Embodiment`` and ``Task`` are kept as ``str`` aliases so annotations stay
|
|
16
|
+
readable and existing ``Embodiment(value)``/``Task(value)`` call sites keep
|
|
17
|
+
working (they are now just ``str(value)``). The ``DEFAULT_*`` constants below
|
|
18
|
+
are convenience defaults for local development and SDK ergonomics only — they
|
|
19
|
+
are not an authoritative enumeration of valid values.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
# String slugs. Aliases (not enums) so the database, not code, owns the set of
|
|
25
|
+
# valid values.
|
|
26
|
+
Embodiment = str
|
|
27
|
+
Task = str
|
|
28
|
+
|
|
29
|
+
# Convenience defaults for local dev / SDK call sites. Not an authoritative
|
|
30
|
+
# list of valid values — the database is. Keep in sync with the seed rows in
|
|
31
|
+
# db/data_core/data_core.sql.
|
|
32
|
+
DEFAULT_EMBODIMENT: Embodiment = "lerobot/so-101"
|
|
33
|
+
DEFAULT_TASK: Task = "assemble_block_tower"
|
armnet_core/models.py
ADDED
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
"""External-facing wire types for the armnet platform.
|
|
2
|
+
|
|
3
|
+
Customer-touching models only \u2014 request/response bodies for the
|
|
4
|
+
orchestrator HTTP API and the result payloads embedded in those responses.
|
|
5
|
+
Internal NATS message envelopes (``JobDispatch``, ``CellHeartbeat``) live
|
|
6
|
+
in the separate ``armnet-protocol`` package alongside the NATS subject
|
|
7
|
+
taxonomy.
|
|
8
|
+
|
|
9
|
+
Keep this module dependency-light (pydantic + stdlib only) so it can be
|
|
10
|
+
imported from any component without dragging in HTTP or NATS clients.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
from datetime import datetime, timezone
|
|
16
|
+
from enum import Enum
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from typing import Any, Optional
|
|
19
|
+
from uuid import uuid4
|
|
20
|
+
|
|
21
|
+
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
|
22
|
+
|
|
23
|
+
from armnet_core.enums import DEFAULT_EMBODIMENT, DEFAULT_TASK, Embodiment, Task
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _utcnow() -> datetime:
|
|
27
|
+
return datetime.now(timezone.utc)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _new_job_id() -> str:
|
|
31
|
+
# Keep this UUID-compatible: the production job store uses a Postgres UUID
|
|
32
|
+
# column, while NATS subjects can safely carry the 32-char hex form.
|
|
33
|
+
return uuid4().hex
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class JobStatus(str, Enum):
|
|
37
|
+
"""Job lifecycle states.
|
|
38
|
+
|
|
39
|
+
Mirrors the design doc §3.5 state machine. A job is created ``SUBMITTED``;
|
|
40
|
+
if the target cell isn't available it becomes ``QUEUED`` (run when the cell
|
|
41
|
+
next comes online — the
|
|
42
|
+
scheduler is a later phase), otherwise it is ``DISPATCHED`` to a cell, then
|
|
43
|
+
``RUNNING``, then a terminal state.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
SUBMITTED = "submitted"
|
|
47
|
+
QUEUED = "queued"
|
|
48
|
+
DISPATCHED = "dispatched"
|
|
49
|
+
RUNNING = "running"
|
|
50
|
+
SUCCEEDED = "succeeded"
|
|
51
|
+
FAILED = "failed"
|
|
52
|
+
TIMEOUT = "timeout"
|
|
53
|
+
CANCELLED = "cancelled"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class CellRuntimeStatus(str, Enum):
|
|
57
|
+
"""Current availability state for a robot cell."""
|
|
58
|
+
|
|
59
|
+
AVAILABLE = "available"
|
|
60
|
+
OCCUPIED = "occupied"
|
|
61
|
+
OFFLINE = "offline"
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
TerminalStatus = frozenset(
|
|
65
|
+
{
|
|
66
|
+
JobStatus.SUCCEEDED,
|
|
67
|
+
JobStatus.FAILED,
|
|
68
|
+
JobStatus.TIMEOUT,
|
|
69
|
+
JobStatus.CANCELLED,
|
|
70
|
+
}
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class RobotArmConfig(BaseModel):
|
|
75
|
+
"""Named arm configuration for multi-arm (bimanual) cells.
|
|
76
|
+
|
|
77
|
+
The runtime derives each arm's connector endpoint from the cell-level
|
|
78
|
+
``robot_connector_endpoint`` plus the arm name; ``port`` is the physical
|
|
79
|
+
serial device that arm is wired to on the edge Pi, used by the Fleet Agent
|
|
80
|
+
to provision the (bimanual) edge connector with the per-arm port mapping
|
|
81
|
+
(``--arm-ports``). Optional because the edge can also be provisioned
|
|
82
|
+
out-of-band, but set it so the agent can bring a bimanual cell up itself.
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
model_config = ConfigDict(extra="forbid")
|
|
86
|
+
|
|
87
|
+
robot_id: Optional[str] = None
|
|
88
|
+
calibration_dir: Optional[Path] = None
|
|
89
|
+
calibration_file_path: Optional[Path] = None
|
|
90
|
+
rest_position: Optional[dict[str, float]] = None
|
|
91
|
+
safety_limit: Optional[float] = None
|
|
92
|
+
safety_delta_degrees: Optional[float] = None
|
|
93
|
+
power_plug_ip: Optional[str] = None
|
|
94
|
+
port: Optional[str] = None
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class JobSpec(BaseModel):
|
|
98
|
+
"""The fields a client supplies when creating a job.
|
|
99
|
+
|
|
100
|
+
This is the body of ``POST /jobs``. The orchestrator wraps it into a
|
|
101
|
+
:class:`Job` (assigning ``id``, ``status``, timestamps) before
|
|
102
|
+
persisting.
|
|
103
|
+
"""
|
|
104
|
+
|
|
105
|
+
image: str = Field(
|
|
106
|
+
...,
|
|
107
|
+
description="Fully-qualified container image reference, e.g. "
|
|
108
|
+
"`ghcr.io/my-org/my-image:tag` or `my-image:latest` for local M0.5.",
|
|
109
|
+
)
|
|
110
|
+
args: dict[str, Any] = Field(
|
|
111
|
+
default_factory=dict,
|
|
112
|
+
description="Keyword arguments passed to the customer's @main-decorated "
|
|
113
|
+
"function as `ctx.args`. JSON-encoded into the `ARMNET_ARGS` env "
|
|
114
|
+
"var by the cell; decoded by the `armnet-runtime` entrypoint "
|
|
115
|
+
"before calling user code. Must be JSON-serialisable.",
|
|
116
|
+
)
|
|
117
|
+
embodiment: Embodiment = Field(
|
|
118
|
+
...,
|
|
119
|
+
description="Required robot embodiment. The orchestrator routes the "
|
|
120
|
+
"job onto the NATS subject for this embodiment+task pair, where the "
|
|
121
|
+
"matching cell picks it up.",
|
|
122
|
+
)
|
|
123
|
+
task: Optional[Task] = Field(
|
|
124
|
+
default=None,
|
|
125
|
+
description="Optional task. When set, only cells configured for this "
|
|
126
|
+
"(embodiment, task) pair run the job. When omitted, any cell of the "
|
|
127
|
+
"embodiment may pick it up regardless of its configured task.",
|
|
128
|
+
)
|
|
129
|
+
timeout_seconds: int = Field(
|
|
130
|
+
default=120,
|
|
131
|
+
ge=1,
|
|
132
|
+
description="Wall-clock cap on container execution.",
|
|
133
|
+
)
|
|
134
|
+
secrets: dict[str, str] = Field(
|
|
135
|
+
default_factory=dict,
|
|
136
|
+
description=(
|
|
137
|
+
"Mapping of environment variable name to user secret name. "
|
|
138
|
+
"Example: {'HF_TOKEN': 'huggingface-token'} resolves the "
|
|
139
|
+
"authenticated user's secret and injects it as HF_TOKEN."
|
|
140
|
+
),
|
|
141
|
+
)
|
|
142
|
+
detach: bool = Field(
|
|
143
|
+
default=False,
|
|
144
|
+
description=(
|
|
145
|
+
"If false, losing the client log WebSocket requests graceful job "
|
|
146
|
+
"cancellation. If true, the job keeps running after client disconnect."
|
|
147
|
+
),
|
|
148
|
+
)
|
|
149
|
+
username: Optional[str] = Field(
|
|
150
|
+
default=None,
|
|
151
|
+
description=(
|
|
152
|
+
"Authenticated armnet username. Set by the orchestrator from "
|
|
153
|
+
"the API key; clients should not rely on supplied values being preserved."
|
|
154
|
+
),
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
class RobotCellConfig(BaseModel):
|
|
159
|
+
"""Physical robot cell configuration loaded from ``robot_cell.json``.
|
|
160
|
+
|
|
161
|
+
This is operator-owned configuration, not job input. The cell and local
|
|
162
|
+
Docker runner use it to inject the same robot metadata into the runtime
|
|
163
|
+
context for every job that lands on this cell.
|
|
164
|
+
|
|
165
|
+
The JSON file may use a nested structure with top-level groups:
|
|
166
|
+
``cell``, ``robot``, ``data_interface``, ``policy``. A model validator
|
|
167
|
+
flattens nested input into the canonical flat field set for backward
|
|
168
|
+
compatibility with all existing consumers.
|
|
169
|
+
"""
|
|
170
|
+
|
|
171
|
+
nats_url: Optional[str] = None
|
|
172
|
+
cell_id: Optional[str] = None
|
|
173
|
+
embodiment: Embodiment = DEFAULT_EMBODIMENT
|
|
174
|
+
task: Task = DEFAULT_TASK
|
|
175
|
+
connector_socket_path: Optional[str] = None
|
|
176
|
+
connector_tcp: Optional[str] = None
|
|
177
|
+
robot_connector_endpoint: Optional[str] = None
|
|
178
|
+
operator_call_endpoint: Optional[str] = "tcp://127.0.0.1:9877"
|
|
179
|
+
robot_port: Optional[str] = None
|
|
180
|
+
robot_power_plug_ip: Optional[str] = None
|
|
181
|
+
robot_id: Optional[str] = None
|
|
182
|
+
calibration_dir: Optional[Path] = None
|
|
183
|
+
calibration_file_path: Optional[Path] = None
|
|
184
|
+
camera_configs: dict[str, dict[str, Any]] = Field(default_factory=dict)
|
|
185
|
+
arms: dict[str, RobotArmConfig] = Field(default_factory=dict)
|
|
186
|
+
safety_limit: Optional[float] = Field(
|
|
187
|
+
default=None,
|
|
188
|
+
description=(
|
|
189
|
+
"Runtime-facing relative action safety limit for robot SDK configs. "
|
|
190
|
+
"SO-101 cells expose 30 degrees; embodiments with connector-only "
|
|
191
|
+
"safety, such as ARX5, leave this unset."
|
|
192
|
+
),
|
|
193
|
+
)
|
|
194
|
+
docker_gpus: Optional[str] = None
|
|
195
|
+
language_instruction: Optional[str] = None
|
|
196
|
+
completion_enabled: bool = False
|
|
197
|
+
completion_threshold: float = 0.9
|
|
198
|
+
completion_camera: Optional[str] = None
|
|
199
|
+
completion_min_interval_s: float = 1.0
|
|
200
|
+
completion_model_path: str = "robometer/Robometer-4B"
|
|
201
|
+
completion_chunk_seconds: float = 2.0
|
|
202
|
+
completion_sample_fps: float = 4.0
|
|
203
|
+
arm_rest_position: Optional[dict[str, float]] = None
|
|
204
|
+
# Robot motion/safety params (pushed to edge connector at job start)
|
|
205
|
+
safety_delta_degrees: float = 30.0
|
|
206
|
+
rest_return_seconds: float = 4.0
|
|
207
|
+
rest_return_hz: float = 20.0
|
|
208
|
+
gripper_release_seconds: float = 1.0
|
|
209
|
+
gripper_motor_name: str = "gripper"
|
|
210
|
+
gripper_release_offset: float = 10.0
|
|
211
|
+
# Data interface params
|
|
212
|
+
tcp_read_timeout: float = 10.0
|
|
213
|
+
jpeg_quality: int = 0
|
|
214
|
+
# Cell infra
|
|
215
|
+
shelly_timeout: float = 2.0
|
|
216
|
+
|
|
217
|
+
@classmethod
|
|
218
|
+
def _flatten_nested(cls, data: dict[str, Any]) -> dict[str, Any]:
|
|
219
|
+
"""Flatten nested JSON groups into the canonical flat field set."""
|
|
220
|
+
flat: dict[str, Any] = {}
|
|
221
|
+
|
|
222
|
+
cell = data.pop("cell", None)
|
|
223
|
+
if isinstance(cell, dict):
|
|
224
|
+
flat["nats_url"] = cell.get("nats_url")
|
|
225
|
+
flat["cell_id"] = cell.get("cell_id")
|
|
226
|
+
flat["connector_socket_path"] = cell.get("connector_socket_path")
|
|
227
|
+
flat["connector_tcp"] = cell.get("connector_tcp")
|
|
228
|
+
flat["robot_connector_endpoint"] = cell.get("robot_connector_endpoint")
|
|
229
|
+
flat["operator_call_endpoint"] = cell.get("operator_call_endpoint")
|
|
230
|
+
flat["robot_port"] = cell.get("robot_port")
|
|
231
|
+
flat["docker_gpus"] = cell.get("docker_gpus")
|
|
232
|
+
flat["robot_power_plug_ip"] = cell.get("power_plug_ip")
|
|
233
|
+
flat["shelly_timeout"] = cell.get("shelly_timeout", 2.0)
|
|
234
|
+
|
|
235
|
+
robot = data.pop("robot", None)
|
|
236
|
+
if isinstance(robot, dict):
|
|
237
|
+
flat["embodiment"] = robot.get("embodiment")
|
|
238
|
+
flat["robot_id"] = robot.get("robot_id")
|
|
239
|
+
flat["calibration_dir"] = robot.get("calibration_dir")
|
|
240
|
+
flat["calibration_file_path"] = robot.get("calibration_file_path")
|
|
241
|
+
flat["arm_rest_position"] = robot.get("rest_position")
|
|
242
|
+
flat["camera_configs"] = robot.get("camera_configs", {})
|
|
243
|
+
flat["arms"] = robot.get("arms", {})
|
|
244
|
+
flat["safety_delta_degrees"] = robot.get("safety_delta_degrees", 30.0)
|
|
245
|
+
flat["rest_return_seconds"] = robot.get("rest_return_seconds", 4.0)
|
|
246
|
+
flat["rest_return_hz"] = robot.get("rest_return_hz", 20.0)
|
|
247
|
+
flat["gripper_release_seconds"] = robot.get("gripper_release_seconds", 1.0)
|
|
248
|
+
flat["gripper_motor_name"] = robot.get("gripper_motor_name", "gripper")
|
|
249
|
+
flat["gripper_release_offset"] = robot.get("gripper_release_offset", 10.0)
|
|
250
|
+
|
|
251
|
+
data_interface = data.pop("data_interface", None)
|
|
252
|
+
if isinstance(data_interface, dict):
|
|
253
|
+
flat["tcp_read_timeout"] = data_interface.get("tcp_read_timeout", 10.0)
|
|
254
|
+
flat["jpeg_quality"] = data_interface.get("jpeg_quality", 0)
|
|
255
|
+
|
|
256
|
+
policy = data.pop("policy", None)
|
|
257
|
+
if isinstance(policy, dict):
|
|
258
|
+
# NOTE: ``task`` / ``language_instruction`` are intentionally NOT read
|
|
259
|
+
# from the config file. They are database-driven: the FMS owns the
|
|
260
|
+
# cell's assigned task and forwards it (plus the task description) to
|
|
261
|
+
# the cell via env vars (see cell/config.py). Any ``policy.task`` /
|
|
262
|
+
# ``policy.language_instruction`` left in a JSON file is ignored so a
|
|
263
|
+
# stale copy can't override the DB.
|
|
264
|
+
completion = policy.get("completion", {})
|
|
265
|
+
if isinstance(completion, dict):
|
|
266
|
+
flat["completion_enabled"] = completion.get("enabled", False)
|
|
267
|
+
flat["completion_threshold"] = completion.get("threshold", 0.9)
|
|
268
|
+
flat["completion_camera"] = completion.get("camera")
|
|
269
|
+
flat["completion_min_interval_s"] = completion.get("min_interval_s", 1.0)
|
|
270
|
+
flat["completion_model_path"] = completion.get(
|
|
271
|
+
"model_path", "robometer/Robometer-4B"
|
|
272
|
+
)
|
|
273
|
+
flat["completion_chunk_seconds"] = completion.get("chunk_seconds", 2.0)
|
|
274
|
+
flat["completion_sample_fps"] = completion.get("sample_fps", 4.0)
|
|
275
|
+
|
|
276
|
+
# Remove None values so Pydantic defaults apply
|
|
277
|
+
flat = {k: v for k, v in flat.items() if v is not None}
|
|
278
|
+
# Merge: explicit flat fields in data take precedence over unpacked nested
|
|
279
|
+
flat.update(data)
|
|
280
|
+
return flat
|
|
281
|
+
|
|
282
|
+
@model_validator(mode="before")
|
|
283
|
+
@classmethod
|
|
284
|
+
def _accept_nested_format(cls, data: Any) -> Any:
|
|
285
|
+
if not isinstance(data, dict):
|
|
286
|
+
return data
|
|
287
|
+
if any(key in data for key in ("cell", "robot", "policy", "data_interface")):
|
|
288
|
+
return cls._flatten_nested(dict(data))
|
|
289
|
+
return data
|
|
290
|
+
|
|
291
|
+
@model_validator(mode="after")
|
|
292
|
+
def _validate_named_arms(self) -> "RobotCellConfig":
|
|
293
|
+
if self.arms and not {"left", "right"}.issubset(self.arms):
|
|
294
|
+
raise ValueError("bimanual robot.arms must include both 'left' and 'right'")
|
|
295
|
+
return self
|
|
296
|
+
|
|
297
|
+
@classmethod
|
|
298
|
+
def from_file(cls, path: str | Path) -> "RobotCellConfig":
|
|
299
|
+
config_path = Path(path).expanduser().resolve()
|
|
300
|
+
config = cls.model_validate_json(config_path.read_text())
|
|
301
|
+
update: dict[str, Any] = {}
|
|
302
|
+
if config.calibration_dir and not config.calibration_dir.is_absolute():
|
|
303
|
+
update["calibration_dir"] = config_path.parent / config.calibration_dir
|
|
304
|
+
if config.calibration_file_path and not config.calibration_file_path.is_absolute():
|
|
305
|
+
update["calibration_file_path"] = config_path.parent / config.calibration_file_path
|
|
306
|
+
if config.arms:
|
|
307
|
+
arms: dict[str, RobotArmConfig] = {}
|
|
308
|
+
changed = False
|
|
309
|
+
for name, arm in config.arms.items():
|
|
310
|
+
arm_update: dict[str, Path] = {}
|
|
311
|
+
if arm.calibration_dir and not arm.calibration_dir.is_absolute():
|
|
312
|
+
arm_update["calibration_dir"] = config_path.parent / arm.calibration_dir
|
|
313
|
+
if arm.calibration_file_path and not arm.calibration_file_path.is_absolute():
|
|
314
|
+
arm_update["calibration_file_path"] = (
|
|
315
|
+
config_path.parent / arm.calibration_file_path
|
|
316
|
+
)
|
|
317
|
+
arms[name] = arm.model_copy(update=arm_update) if arm_update else arm
|
|
318
|
+
changed = changed or bool(arm_update)
|
|
319
|
+
if changed:
|
|
320
|
+
update["arms"] = arms
|
|
321
|
+
return config.model_copy(update=update) if update else config
|
|
322
|
+
|
|
323
|
+
class CellStatus(BaseModel):
|
|
324
|
+
"""Current status for one cell as reported by recent heartbeats."""
|
|
325
|
+
|
|
326
|
+
cell_id: str
|
|
327
|
+
embodiment: Embodiment
|
|
328
|
+
task: Task
|
|
329
|
+
status: CellRuntimeStatus
|
|
330
|
+
current_job_id: Optional[str] = None
|
|
331
|
+
last_heartbeat_at: Optional[datetime] = None
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
class CellStatusSummary(BaseModel):
|
|
335
|
+
"""Aggregate availability for an embodiment, optionally scoped to a task.
|
|
336
|
+
|
|
337
|
+
``task`` is ``None`` when the summary aggregates across every task of the
|
|
338
|
+
embodiment (used to answer "is any cell of this embodiment available?" for
|
|
339
|
+
task-less jobs).
|
|
340
|
+
"""
|
|
341
|
+
|
|
342
|
+
embodiment: Embodiment
|
|
343
|
+
task: Optional[Task] = None
|
|
344
|
+
status: CellRuntimeStatus
|
|
345
|
+
cells: list[CellStatus] = Field(default_factory=list)
|
|
346
|
+
heartbeat_timeout_seconds: int = 20
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
class TeleopAction(BaseModel):
|
|
350
|
+
"""A single remote-teleoperation action for a running job.
|
|
351
|
+
|
|
352
|
+
Sent by the client (sampling a local leader arm) to the orchestrator over a
|
|
353
|
+
websocket, forwarded to the cell on the job's teleop NATS subject, and kept
|
|
354
|
+
by the cell as a most-recent-value register. ``timestamp`` (unix seconds, on
|
|
355
|
+
the client clock) is used to drop out-of-order/stale messages so the cell
|
|
356
|
+
always holds the freshest action.
|
|
357
|
+
"""
|
|
358
|
+
|
|
359
|
+
job_id: str
|
|
360
|
+
timestamp: float
|
|
361
|
+
# Joint-space command keyed like LeRobot's send_action input, e.g.
|
|
362
|
+
# {"shoulder_pan.pos": 12.3, ...}.
|
|
363
|
+
action: dict[str, float] = Field(default_factory=dict)
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
# Recording-control events a teleoperating client can send (LeRobot's standard
|
|
367
|
+
# dataset-recording keyboard shortcuts).
|
|
368
|
+
TELEOP_EVENT_NEXT_EPISODE = "next_episode" # Right Arrow: save episode, move on
|
|
369
|
+
TELEOP_EVENT_RERECORD_EPISODE = "rerecord_episode" # Left Arrow: discard + redo
|
|
370
|
+
TELEOP_EVENT_STOP_RECORDING = "stop_recording" # Esc: end the session
|
|
371
|
+
|
|
372
|
+
TELEOP_EVENTS = (
|
|
373
|
+
TELEOP_EVENT_NEXT_EPISODE,
|
|
374
|
+
TELEOP_EVENT_RERECORD_EPISODE,
|
|
375
|
+
TELEOP_EVENT_STOP_RECORDING,
|
|
376
|
+
)
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
class TeleopEvent(BaseModel):
|
|
380
|
+
"""A discrete recording-control event for a running teleop job.
|
|
381
|
+
|
|
382
|
+
Travels the same path as :class:`TeleopAction` (client websocket →
|
|
383
|
+
orchestrator → the job's teleop NATS subject → cell), but with different
|
|
384
|
+
delivery semantics: actions are a freshest-wins stream where drops are
|
|
385
|
+
fine, whereas events are rare, user-initiated commands that the cell queues
|
|
386
|
+
in order so none is lost between runtime polls.
|
|
387
|
+
|
|
388
|
+
The ``event`` values mirror LeRobot's dataset-recording keyboard controls:
|
|
389
|
+
Right Arrow ends the current episode and moves on (``next_episode``), Left
|
|
390
|
+
Arrow discards and re-records it (``rerecord_episode``), and Esc stops the
|
|
391
|
+
whole session (``stop_recording``).
|
|
392
|
+
"""
|
|
393
|
+
|
|
394
|
+
job_id: str
|
|
395
|
+
timestamp: float
|
|
396
|
+
event: str = Field(..., pattern="^(next_episode|rerecord_episode|stop_recording)$")
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
class JobResult(BaseModel):
|
|
400
|
+
"""Terminal result published by a cell on the results subject.
|
|
401
|
+
|
|
402
|
+
Also returned (embedded in :class:`Job`) by ``GET /jobs/{id}`` once the
|
|
403
|
+
job is in a terminal state.
|
|
404
|
+
"""
|
|
405
|
+
|
|
406
|
+
status: JobStatus = Field(
|
|
407
|
+
...,
|
|
408
|
+
description="One of the terminal statuses (succeeded/failed/timeout/cancelled).",
|
|
409
|
+
)
|
|
410
|
+
exit_code: Optional[int] = Field(
|
|
411
|
+
default=None,
|
|
412
|
+
description="Container process exit code if the container ran to completion.",
|
|
413
|
+
)
|
|
414
|
+
stdout: str = Field(default="", description="Captured container stdout.")
|
|
415
|
+
stderr: str = Field(default="", description="Captured container stderr.")
|
|
416
|
+
error: Optional[str] = Field(
|
|
417
|
+
default=None,
|
|
418
|
+
description="Short, infra-side reason this job didn't run user code "
|
|
419
|
+
"to completion: image pull failure, docker error, timeout, etc. "
|
|
420
|
+
"Mutually exclusive with `traceback` in practice (one is a platform "
|
|
421
|
+
"failure, the other is a user-code failure).",
|
|
422
|
+
)
|
|
423
|
+
traceback: Optional[str] = Field(
|
|
424
|
+
default=None,
|
|
425
|
+
description="Python traceback from the customer's `@main`-decorated "
|
|
426
|
+
"function if it raised. Extracted by the cell from the "
|
|
427
|
+
"`[armnet:traceback]:json` marker line in stdout. Capped at "
|
|
428
|
+
"~64 KiB on the cell side; the full untruncated traceback is also "
|
|
429
|
+
"in `stderr` for power users. None for successful jobs and for "
|
|
430
|
+
"infra-side failures (those go in `error` instead).",
|
|
431
|
+
)
|
|
432
|
+
return_value: Optional[Any] = Field(
|
|
433
|
+
default=None,
|
|
434
|
+
description="Value returned by the customer's `@main`-decorated "
|
|
435
|
+
"function. Extracted by the cell from the marker line that the "
|
|
436
|
+
"`armnet-runtime` entrypoint prints to stdout. None if the "
|
|
437
|
+
"function returned None or did not run to completion.",
|
|
438
|
+
)
|
|
439
|
+
started_at: Optional[datetime] = None
|
|
440
|
+
finished_at: Optional[datetime] = None
|
|
441
|
+
|
|
442
|
+
def raise_for_status(self) -> None:
|
|
443
|
+
"""Raise :class:`RemoteExecutionError` iff this result isn't ``SUCCEEDED``.
|
|
444
|
+
|
|
445
|
+
The httpx-style "opt-in raising" pattern. Use it when you'd rather
|
|
446
|
+
bail than branch on ``result.status``::
|
|
447
|
+
|
|
448
|
+
result = execute(...)
|
|
449
|
+
result.raise_for_status()
|
|
450
|
+
do_thing(result.return_value)
|
|
451
|
+
|
|
452
|
+
For successful results this is a no-op.
|
|
453
|
+
"""
|
|
454
|
+
|
|
455
|
+
if self.status != JobStatus.SUCCEEDED:
|
|
456
|
+
raise RemoteExecutionError(self)
|
|
457
|
+
|
|
458
|
+
def __str__(self) -> str:
|
|
459
|
+
"""Human-readable rendering. Uses indentation to make tracebacks scannable.
|
|
460
|
+
|
|
461
|
+
``print(result)`` is intended to be the one-liner that tells you
|
|
462
|
+
what happened. ``repr(result)`` (pydantic's default) still shows
|
|
463
|
+
every field for debugging.
|
|
464
|
+
"""
|
|
465
|
+
|
|
466
|
+
lines: list[str] = []
|
|
467
|
+
head = f"JobResult(status={self.status.value}"
|
|
468
|
+
if self.exit_code is not None:
|
|
469
|
+
head += f", exit_code={self.exit_code}"
|
|
470
|
+
head += ")"
|
|
471
|
+
lines.append(head)
|
|
472
|
+
if self.return_value is not None:
|
|
473
|
+
lines.append(f" return_value: {self.return_value!r}")
|
|
474
|
+
if self.error:
|
|
475
|
+
lines.append(f" error: {self.error}")
|
|
476
|
+
if self.traceback:
|
|
477
|
+
lines.append(" traceback (from @main):")
|
|
478
|
+
for tb_line in self.traceback.splitlines():
|
|
479
|
+
lines.append(f" {tb_line}")
|
|
480
|
+
return "\n".join(lines)
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
class JobStatusTransition(BaseModel):
|
|
484
|
+
"""One entry in a job's status-change audit trail.
|
|
485
|
+
|
|
486
|
+
Emitted by the orchestrator's ``GET /jobs/{id}/status-transitions`` so users
|
|
487
|
+
can trace a job's lifecycle. ``detail`` carries optional context (e.g. the
|
|
488
|
+
cell id on dispatch/run, or the failure message on a terminal state).
|
|
489
|
+
"""
|
|
490
|
+
|
|
491
|
+
status: str
|
|
492
|
+
detail: Optional[str] = None
|
|
493
|
+
timestamp: datetime
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
class RemoteExecutionError(RuntimeError):
|
|
497
|
+
"""Raised by :meth:`JobResult.raise_for_status` for non-succeeded results.
|
|
498
|
+
|
|
499
|
+
The exception's ``__str__`` includes the underlying status, any
|
|
500
|
+
platform-side ``error``, and the user's ``traceback`` (if any), so an
|
|
501
|
+
unhandled raise prints all the diagnostic context an operator needs.
|
|
502
|
+
The original :class:`JobResult` is available as :attr:`result` for
|
|
503
|
+
structured access.
|
|
504
|
+
"""
|
|
505
|
+
|
|
506
|
+
def __init__(self, result: "JobResult") -> None:
|
|
507
|
+
self.result = result
|
|
508
|
+
super().__init__(str(result))
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
class Job(BaseModel):
|
|
512
|
+
"""The orchestrator's view of a job (response body of GET /jobs/{id})."""
|
|
513
|
+
|
|
514
|
+
id: str = Field(default_factory=_new_job_id)
|
|
515
|
+
spec: JobSpec
|
|
516
|
+
status: JobStatus = JobStatus.SUBMITTED
|
|
517
|
+
created_at: datetime = Field(default_factory=_utcnow)
|
|
518
|
+
updated_at: datetime = Field(default_factory=_utcnow)
|
|
519
|
+
cell_id: Optional[str] = Field(
|
|
520
|
+
default=None,
|
|
521
|
+
description="ID of the cell that picked up the job, set on dispatch.",
|
|
522
|
+
)
|
|
523
|
+
result: Optional[JobResult] = None
|
|
524
|
+
dispatched: Optional[bool] = Field(
|
|
525
|
+
default=None,
|
|
526
|
+
description=(
|
|
527
|
+
"Only set on the POST /jobs response: True if the job was dispatched "
|
|
528
|
+
"to a cell immediately, False if it was accepted but queued (no "
|
|
529
|
+
"matching cell was free). None on all other responses. Clients can use "
|
|
530
|
+
"this to decide whether to wait for logs/result or just report 'queued'."
|
|
531
|
+
),
|
|
532
|
+
)
|
|
533
|
+
|
|
534
|
+
def is_terminal(self) -> bool:
|
|
535
|
+
return self.status in TerminalStatus
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
class RegistryCredentials(BaseModel):
|
|
539
|
+
"""Short-lived credentials for pushing to the platform's image registry.
|
|
540
|
+
|
|
541
|
+
Returned by ``POST /registry/credentials``. The orchestrator mints
|
|
542
|
+
these on demand by impersonating a dedicated image-pusher service
|
|
543
|
+
account. Customers never need to know about Google Cloud, IAM, or
|
|
544
|
+
service accounts \u2014 they just ``Image.build(...).push()``.
|
|
545
|
+
|
|
546
|
+
The ``password`` is an OAuth2 access token valid for ~1 hour. The
|
|
547
|
+
SDK caches it on disk and refreshes within 5 minutes of expiry.
|
|
548
|
+
"""
|
|
549
|
+
|
|
550
|
+
registry: str = Field(
|
|
551
|
+
...,
|
|
552
|
+
description="Registry hostname, e.g. 'europe-north1-docker.pkg.dev'.",
|
|
553
|
+
)
|
|
554
|
+
namespace: str = Field(
|
|
555
|
+
...,
|
|
556
|
+
description="Path under the registry the customer is allowed to "
|
|
557
|
+
"push to: '<project>/<repo>/<customer-id>'. The full image ref "
|
|
558
|
+
"is '<registry>/<namespace>/<image-name>:<tag>'.",
|
|
559
|
+
)
|
|
560
|
+
username: str = Field(
|
|
561
|
+
...,
|
|
562
|
+
description="docker login username. Always 'oauth2accesstoken' for AR.",
|
|
563
|
+
)
|
|
564
|
+
password: str = Field(
|
|
565
|
+
...,
|
|
566
|
+
description="OAuth2 access token. Treat as a secret \u2014 valid for "
|
|
567
|
+
"~1 hour and grants write access to the namespace above.",
|
|
568
|
+
)
|
|
569
|
+
expires_at: datetime = Field(
|
|
570
|
+
...,
|
|
571
|
+
description="Wall-clock time at which the password becomes invalid.",
|
|
572
|
+
)
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
class VolumeCredentials(BaseModel):
|
|
576
|
+
"""Short-lived credentials for a user's cloud-backed volume prefix."""
|
|
577
|
+
|
|
578
|
+
bucket: str
|
|
579
|
+
prefix: str
|
|
580
|
+
access_token: str
|
|
581
|
+
expires_at: datetime
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
class WhoAmI(BaseModel):
|
|
585
|
+
"""Authenticated API identity."""
|
|
586
|
+
|
|
587
|
+
username: str
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
class EmbodimentInfo(BaseModel):
|
|
591
|
+
"""One known embodiment, as stored in the orchestrator database."""
|
|
592
|
+
|
|
593
|
+
slug: Embodiment = Field(..., description="Wire-format embodiment slug, e.g. 'lerobot/so-101'.")
|
|
594
|
+
description: Optional[str] = None
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
class EmbodimentList(BaseModel):
|
|
598
|
+
"""The set of embodiments the platform currently accepts (GET /embodiments)."""
|
|
599
|
+
|
|
600
|
+
embodiments: list[EmbodimentInfo] = Field(default_factory=list)
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
class TaskInfo(BaseModel):
|
|
604
|
+
"""One known task, as stored in the orchestrator database."""
|
|
605
|
+
|
|
606
|
+
slug: Task = Field(..., description="Wire-format task slug, e.g. 'assemble_block_tower'.")
|
|
607
|
+
description: Optional[str] = None
|
|
608
|
+
|
|
609
|
+
|
|
610
|
+
class TaskList(BaseModel):
|
|
611
|
+
"""The set of tasks the platform currently accepts (GET /tasks)."""
|
|
612
|
+
|
|
613
|
+
tasks: list[TaskInfo] = Field(default_factory=list)
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
class SecretInfo(BaseModel):
|
|
617
|
+
"""Secret metadata returned to clients. Never includes secret values."""
|
|
618
|
+
|
|
619
|
+
name: str
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
class SecretList(BaseModel):
|
|
623
|
+
"""List of secret metadata for the authenticated user."""
|
|
624
|
+
|
|
625
|
+
secrets: list[SecretInfo] = Field(default_factory=list)
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
class SecretCreateRequest(BaseModel):
|
|
629
|
+
"""Create or replace one user secret."""
|
|
630
|
+
|
|
631
|
+
name: str
|
|
632
|
+
value: str
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: armnet-core
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Shared wire types for the armnet platform: Embodiment, Task, JobSpec, JobResult, Job, JobStatus.
|
|
5
|
+
Project-URL: Homepage, https://armnet.dev
|
|
6
|
+
Project-URL: Documentation, https://safe-robotics.github.io/alpha-robotics/packages/core/
|
|
7
|
+
Author: Ville Kuosmanen
|
|
8
|
+
License: Apache-2.0
|
|
9
|
+
Requires-Python: <3.13,>=3.12
|
|
10
|
+
Requires-Dist: pydantic<3,>=2.6
|
|
11
|
+
Provides-Extra: dev
|
|
12
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# armnet-core
|
|
16
|
+
|
|
17
|
+
The shared wire types for the [Armnet](https://armnet.dev) managed arm farm: the
|
|
18
|
+
`Embodiment` and `Task` identifiers and the `JobSpec`, `Job`, `JobResult`,
|
|
19
|
+
`JobStatus` (and related) Pydantic models exchanged across the platform.
|
|
20
|
+
Pydantic-only dependencies.
|
|
21
|
+
|
|
22
|
+
Most users don't install this directly — it comes transitively with
|
|
23
|
+
[`armnet-runtime`](https://pypi.org/project/armnet-runtime/) (containers) or
|
|
24
|
+
[`armnet-client`](https://pypi.org/project/armnet-client/) (dev/CI). Depend on it
|
|
25
|
+
directly only when you need to construct or inspect the wire types without the
|
|
26
|
+
rest of the SDK (for example, a third-party tool that builds `JobSpec`s).
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install armnet-core
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Documentation
|
|
35
|
+
|
|
36
|
+
Full guides and API reference: **<https://safe-robotics.github.io/alpha-robotics/packages/core/>**
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
armnet_core/__init__.py,sha256=2NFRA-NJImqo8cGxckBisy1DQATTgfcm3ucofso7sFk,1736
|
|
2
|
+
armnet_core/auth.py,sha256=APSG7uh1Si80u-fNWdIASeeYPO_dWp9XvcahS8gnUfk,107
|
|
3
|
+
armnet_core/enums.py,sha256=JR-Y26bYN-wyhJCo3liNXaLHc1mDwNYCq9e3sblzp_A,1489
|
|
4
|
+
armnet_core/models.py,sha256=K_wslMfeemVHIQu9w3ZA6o5VC4fcGaZ0Iyjh3GBDLWM,24611
|
|
5
|
+
armnet_core-0.1.0.dist-info/METADATA,sha256=kqaDfh2a1T7TfRjDoFubgbpWxBhJUu_QFJ3lW26Na-Y,1323
|
|
6
|
+
armnet_core-0.1.0.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
|
|
7
|
+
armnet_core-0.1.0.dist-info/RECORD,,
|