artificialbrains-sdk 0.1.3__py3-none-any.whl → 0.1.5__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.
ab_sdk/client.py CHANGED
@@ -122,7 +122,15 @@ class ABClient:
122
122
  # derive host root from base_url (/api stripped)
123
123
  url = self.base_url[:-4] if self.base_url.endswith("/api") else self.base_url
124
124
 
125
- socket = socketio.Client(reconnection=True, logger=False, engineio_logger=False)
125
+ socket = socketio.Client(
126
+ reconnection=True,
127
+ reconnection_attempts=0, # infinite retries
128
+ reconnection_delay=1,
129
+ reconnection_delay_max=5,
130
+ logger=True, # Enable to see ping/pong
131
+ engineio_logger=True,
132
+ request_timeout=3600, # Allow long requests (1 hour)
133
+ )
126
134
 
127
135
  connect_headers: Dict[str, str] = {}
128
136
  auth_payload: Optional[Dict[str, Any]] = None
@@ -136,49 +144,23 @@ class ABClient:
136
144
  # Helpful visibility: log namespace connect/disconnect
137
145
  @socket.on("connect", namespace=ns)
138
146
  def _on_connect():
139
- logger.info("Realtime connected to namespace %s (namespaces=%s)", ns, list(getattr(socket, "namespaces", {}).keys()))
147
+ logger.info("Realtime connected to namespace %s", ns)
140
148
 
141
149
  @socket.on("disconnect", namespace=ns)
142
150
  def _on_disconnect():
143
151
  logger.warning("Realtime disconnected from namespace %s", ns)
144
152
 
145
- # Robust connect strategy:
146
- # 1) Try websocket-only (does NOT require `requests`)
147
- # 2) Fallback to default transports (polling+websocket) if needed
148
- # Provide a clear error message if dependencies are missing.
149
- try:
150
- socket.connect(
151
- url,
152
- headers=connect_headers,
153
- auth=auth_payload,
154
- namespaces=[ns],
155
- transports=["websocket"],
156
- wait=True,
157
- wait_timeout=self.timeout,
158
- )
159
- except Exception as e1:
160
- # If websocket-client is missing, python-socketio will fail here.
161
- # If polling is needed and `requests` is missing, it will fail on fallback.
162
- try:
163
- socket.connect(
164
- url,
165
- headers=connect_headers,
166
- auth=auth_payload,
167
- namespaces=[ns],
168
- wait=True,
169
- wait_timeout=self.timeout,
170
- )
171
- except Exception as e2:
172
- msg = (
173
- "Realtime connection failed.\n\n"
174
- "Tried websocket-only then default transports.\n\n"
175
- "Common fixes:\n"
176
- " - pip install websocket-client\n"
177
- " - pip install requests\n\n"
178
- f"websocket error: {e1}\n"
179
- f"fallback error: {e2}"
180
- )
181
- raise socketio.exceptions.ConnectionError(msg)
153
+ # Use polling + websocket (not websocket-only)
154
+ # This maintains connection through NAT devices
155
+ socket.connect(
156
+ url,
157
+ headers=connect_headers,
158
+ auth=auth_payload,
159
+ namespaces=[ns],
160
+ transports=["polling", "websocket"], # MUST have polling first!
161
+ wait=True,
162
+ wait_timeout=120,
163
+ )
182
164
 
183
165
 
184
166
  # HARD ASSERT: the namespace must actually be connected, or emits will fail with:
ab_sdk/run_session.py CHANGED
@@ -20,7 +20,7 @@ appropriate synchronization in your handlers.
20
20
  """
21
21
 
22
22
  from __future__ import annotations
23
-
23
+ import struct
24
24
  import logging
25
25
  import threading
26
26
  import time
@@ -198,6 +198,64 @@ class RunSession:
198
198
  }
199
199
  logger.debug("Sending input chunk: %s", {k: payload[k] for k in payload if k != "data"})
200
200
  self.socket.emit("io:chunk", payload, namespace=self.namespace)
201
+
202
+ def send_proprioception_ticks(
203
+ self,
204
+ input_id: str,
205
+ raw_tick: float,
206
+ prev_raw_tick: Optional[float] = None,
207
+ vel_tick_s: Optional[float] = None,
208
+ *,
209
+ cycle: Optional[int] = None,
210
+ seq: Optional[int] = None,
211
+ t: Optional[float] = None,
212
+ lo: Optional[float] = None,
213
+ hi: Optional[float] = None,
214
+ meta: Optional[Dict[str, Any]] = None,
215
+ ) -> None:
216
+ """Send a per-joint proprioception sample as RAW ticks (+ optional velocity).
217
+
218
+ Payload format:
219
+ fmt="rawtick_f32x3"
220
+ data=3x float32 little-endian: [raw_tick, prev_raw_tick, vel_tick_s]
221
+
222
+ Notes:
223
+ - We include cycle in meta for debugging/traceability.
224
+ - For non-Feedback chunks, the server uses its own brainCycle; the cycle
225
+ value is still useful for logs and alignment.
226
+ """
227
+ if prev_raw_tick is None:
228
+ prev_raw_tick = float(raw_tick)
229
+ if vel_tick_s is None:
230
+ vel_tick_s = 0.0
231
+
232
+ payload = struct.pack("<fff", float(raw_tick), float(prev_raw_tick), float(vel_tick_s))
233
+
234
+ m = dict(meta or {})
235
+ if cycle is not None:
236
+ m.setdefault("cycle", int(cycle))
237
+ if lo is not None:
238
+ m.setdefault("lo", float(lo))
239
+ if hi is not None:
240
+ m.setdefault("hi", float(hi))
241
+ m.setdefault("rawTick", float(raw_tick))
242
+ m.setdefault("prevRawTick", float(prev_raw_tick))
243
+ m.setdefault("velTickPerS", float(vel_tick_s))
244
+
245
+ if seq is None:
246
+ seq = int(cycle) if cycle is not None else 0
247
+ if t is None:
248
+ t = time.time()
249
+
250
+ self.send_input_chunk(
251
+ input_id=str(input_id),
252
+ kind="Proprioception",
253
+ seq=int(seq),
254
+ t=float(t),
255
+ fmt="rawtick_f32x3",
256
+ meta=m,
257
+ data=payload,
258
+ )
201
259
 
202
260
  def send_feedback_raster(self, input_id: str, raster: Iterable[float],
203
261
  cycle: int) -> None:
@@ -228,6 +286,7 @@ class RunSession:
228
286
  t=time.time(), fmt="raster_f32",
229
287
  meta=meta, data=data_bytes)
230
288
 
289
+
231
290
  def send_reward(self, global_reward: float, by_layer: Dict[str, float],
232
291
  cycle: int) -> None:
233
292
  """Send reward information to the server.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: artificialbrains_sdk
3
- Version: 0.1.3
3
+ Version: 0.1.5
4
4
  Summary: ArtificialBrains Python SDK
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: License :: Other/Proprietary License
@@ -1,15 +1,15 @@
1
1
  ab_sdk/__init__.py,sha256=tYSMwbFzqsiZ7Bp7mYy2kQ0rX9I1NwM6wS1hEGYuze4,1831
2
- ab_sdk/client.py,sha256=TvANQpuEgjDYn51tIcXtGijHrqFUVXKPGXjKMRbWflc,10144
2
+ ab_sdk/client.py,sha256=Aj5XgAEBtXeKg5DQgdG66SNtOvTYugd9DROkw34GmEY,9220
3
3
  ab_sdk/contract_scaffold.py,sha256=4zcsWhd9axxMu--FZ7U8B8u4QLUwluifyvqac2apDno,8930
4
4
  ab_sdk/endpoints.py,sha256=yc4h_E8vQA9TmWF0sW2GprgE0QnS3eBetH13ogeuw4E,2102
5
5
  ab_sdk/input_streamer.py,sha256=fRPlBimaTDBsm1gz9cdoYanVbmwYTBXSyI9IrXslXiM,6847
6
6
  ab_sdk/robot_loop.py,sha256=x5QCmJ28ET2iQf2q6AcreN0fy0WfPVUA4g-8b4TDjXo,7567
7
- ab_sdk/run_session.py,sha256=AQ_Xxn41s52MaCfi94liX3hkJxT3VT1INlf1u9NcXa0,12733
7
+ ab_sdk/run_session.py,sha256=nwUSsOMSk5AupXQSyvArh--pe12Y3QyHDDjhjmTfHdU,14661
8
8
  ab_sdk/plugins/__init__.py,sha256=veHfKqvymY8YPN9HF4E1S4pwRUcVVJHDAyBZptbLNlA,1870
9
9
  ab_sdk/plugins/decoder.py,sha256=vHAubiAPOaOg3J006TLjn4qAoLIu2Lz2D2kjz421odc,10148
10
10
  ab_sdk/plugins/deviation.py,sha256=QLKOqOSa9HIj3Z3bO6oR79wY1Lni_P-j3GAGM7UYKVs,2019
11
11
  ab_sdk/plugins/reward.py,sha256=E5IsV29N6juyfIQ7ZksDa8JSxAAbVflaJOtLplilAD4,1796
12
- artificialbrains_sdk-0.1.3.dist-info/METADATA,sha256=_YNYqtSlvLxl7u9c7mX4LVls1n2XkuxIS0iQy354TD0,12177
13
- artificialbrains_sdk-0.1.3.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
14
- artificialbrains_sdk-0.1.3.dist-info/top_level.txt,sha256=Ttsz2oF0qRh68OI9w3mu_LKkv2I_YvOWr3kudSpckpM,7
15
- artificialbrains_sdk-0.1.3.dist-info/RECORD,,
12
+ artificialbrains_sdk-0.1.5.dist-info/METADATA,sha256=mu2eo9FmI8BgPKrOTE7h6INcLlwTNGFYKFQpaOCHFSo,12177
13
+ artificialbrains_sdk-0.1.5.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
14
+ artificialbrains_sdk-0.1.5.dist-info/top_level.txt,sha256=Ttsz2oF0qRh68OI9w3mu_LKkv2I_YvOWr3kudSpckpM,7
15
+ artificialbrains_sdk-0.1.5.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.10.1)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5