runtime-sdk 0.4.0__tar.gz → 0.4.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: runtime-sdk
3
- Version: 0.4.0
3
+ Version: 0.4.1
4
4
  Summary: Runtime Python SDK and CLI
5
5
  Project-URL: Repository, https://github.com/The-Money-Company-Limited/runtimevm
6
6
  Project-URL: Issues, https://github.com/The-Money-Company-Limited/runtimevm/issues
@@ -56,7 +56,7 @@ runtime login --api-key rt_live_...
56
56
  # Computers
57
57
  runtime create # in a real TTY, creates then drops you into the console
58
58
  runtime create myapp --command "python3 app.py" --cwd /home/ubuntu --port 3000
59
- runtime enter <id> # enter a fresh console session on an existing computer
59
+ runtime enter <name-or-id> # accepts slug/name like test, or the computer id
60
60
  runtime list
61
61
  runtime info <id>
62
62
  runtime start <id>
@@ -37,7 +37,7 @@ runtime login --api-key rt_live_...
37
37
  # Computers
38
38
  runtime create # in a real TTY, creates then drops you into the console
39
39
  runtime create myapp --command "python3 app.py" --cwd /home/ubuntu --port 3000
40
- runtime enter <id> # enter a fresh console session on an existing computer
40
+ runtime enter <name-or-id> # accepts slug/name like test, or the computer id
41
41
  runtime list
42
42
  runtime info <id>
43
43
  runtime start <id>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "runtime-sdk"
3
- version = "0.4.0"
3
+ version = "0.4.1"
4
4
  description = "Runtime Python SDK and CLI"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -372,6 +372,57 @@ def _computer_status_label(c: dict[str, Any]) -> str:
372
372
 
373
373
 
374
374
 
375
+ def _computer_matches_ref(c: dict[str, Any], ref: str) -> bool:
376
+ ref = ref.strip()
377
+ if not ref:
378
+ return False
379
+
380
+ candidates = {
381
+ str(c.get("id") or "").strip(),
382
+ str(c.get("slug") or "").strip(),
383
+ str(c.get("hostname") or "").strip(),
384
+ str(c.get("public_url") or "").strip(),
385
+ }
386
+
387
+ public_url = str(c.get("public_url") or "").strip()
388
+ if public_url:
389
+ parsed = urlparse(public_url)
390
+ if parsed.netloc:
391
+ candidates.add(parsed.netloc)
392
+ first_label = parsed.netloc.split(".", 1)[0].strip()
393
+ if first_label:
394
+ candidates.add(first_label)
395
+
396
+ return ref in {value for value in candidates if value}
397
+
398
+
399
+
400
+ def _resolve_computer_ref(client: RuntimeClient, ref: str) -> str:
401
+ ref = ref.strip()
402
+ if not ref:
403
+ raise RuntimeAPIError("computer id is required")
404
+ if ref.startswith("cmp_"):
405
+ return ref
406
+
407
+ try:
408
+ payload = client.list_computers()
409
+ except RuntimeAPIError:
410
+ return ref
411
+
412
+ computers = payload.get("computers") or []
413
+ if not isinstance(computers, list):
414
+ computers = []
415
+
416
+ matches = [c for c in computers if isinstance(c, dict) and _computer_matches_ref(c, ref)]
417
+ if len(matches) == 1:
418
+ resolved = str(matches[0].get("id") or "").strip()
419
+ return resolved or ref
420
+ if len(matches) > 1:
421
+ raise RuntimeAPIError(f"multiple computers matched {ref!r}; use the exact computer id")
422
+ return ref
423
+
424
+
425
+
375
426
  def _computer_table_layout(computers: list[dict[str, Any]]) -> dict[str, int]:
376
427
  term_width = shutil.get_terminal_size((100, 20)).columns
377
428
  slug_width = max(
@@ -774,6 +825,7 @@ def handle_info(config: RuntimeConfig, computer_id: str | None) -> int:
774
825
  return report_error("computer is missing an id")
775
826
 
776
827
  client = RuntimeClient(base_url=config.base_url, api_key=config.api_key)
828
+ computer_id = _resolve_computer_ref(client, computer_id)
777
829
  result = client.get_computer(computer_id)
778
830
  return report_success(result, lambda p: _render_computer_panel(p, title="computer"))
779
831
 
@@ -797,6 +849,7 @@ def handle_start(config: RuntimeConfig, computer_id: str | None) -> int:
797
849
  return report_error("computer is missing an id")
798
850
 
799
851
  client = RuntimeClient(base_url=config.base_url, api_key=config.api_key)
852
+ computer_id = _resolve_computer_ref(client, computer_id)
800
853
  result = _with_spinner(f"warming {computer_id}…", lambda: client.start_computer(computer_id))
801
854
 
802
855
  def render(payload: dict[str, Any]) -> None:
@@ -826,6 +879,8 @@ def handle_enter(config: RuntimeConfig, computer_id: str | None) -> int:
826
879
  if not computer_id:
827
880
  return report_error("computer is missing an id")
828
881
 
882
+ client = RuntimeClient(base_url=config.base_url, api_key=config.api_key)
883
+ computer_id = _resolve_computer_ref(client, str(computer_id))
829
884
  return _enter_computer(config, str(computer_id))
830
885
 
831
886
 
@@ -853,6 +908,7 @@ def handle_delete(config: RuntimeConfig, computer_id: str | None) -> int:
853
908
  return 0
854
909
 
855
910
  client = RuntimeClient(base_url=config.base_url, api_key=config.api_key)
911
+ computer_id = _resolve_computer_ref(client, computer_id)
856
912
  client.delete_computer(computer_id)
857
913
 
858
914
  def render(_: dict[str, Any]) -> None:
@@ -895,6 +951,7 @@ def handle_run(
895
951
  return report_error("command is required")
896
952
 
897
953
  client = RuntimeClient(base_url=config.base_url, api_key=config.api_key)
954
+ computer_id = _resolve_computer_ref(client, computer_id)
898
955
  result = _with_spinner(
899
956
  f"running on {computer_id}…",
900
957
  lambda: client.run_command(
@@ -937,6 +994,7 @@ def handle_publish(config: RuntimeConfig, computer_id: str | None, port: int | N
937
994
  return report_error("port must be between 1 and 65535")
938
995
 
939
996
  client = RuntimeClient(base_url=config.base_url, api_key=config.api_key)
997
+ computer_id = _resolve_computer_ref(client, computer_id)
940
998
  _with_spinner(
941
999
  f"publishing port {port} on {computer_id}…",
942
1000
  lambda: client.publish_port(computer_id, port),
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: runtime-sdk
3
- Version: 0.4.0
3
+ Version: 0.4.1
4
4
  Summary: Runtime Python SDK and CLI
5
5
  Project-URL: Repository, https://github.com/The-Money-Company-Limited/runtimevm
6
6
  Project-URL: Issues, https://github.com/The-Money-Company-Limited/runtimevm/issues
@@ -56,7 +56,7 @@ runtime login --api-key rt_live_...
56
56
  # Computers
57
57
  runtime create # in a real TTY, creates then drops you into the console
58
58
  runtime create myapp --command "python3 app.py" --cwd /home/ubuntu --port 3000
59
- runtime enter <id> # enter a fresh console session on an existing computer
59
+ runtime enter <name-or-id> # accepts slug/name like test, or the computer id
60
60
  runtime list
61
61
  runtime info <id>
62
62
  runtime start <id>
File without changes