envloop-cli 0.4.0__tar.gz → 1.4.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.
Files changed (32) hide show
  1. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/.gitignore +3 -0
  2. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/PKG-INFO +1 -1
  3. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/agent_runs.py +36 -0
  4. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/cli.py +43 -8
  5. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/cli_errors.py +5 -0
  6. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/client.py +64 -9
  7. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/http.py +5 -17
  8. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/profile_updates.py +23 -3
  9. envloop_cli-1.4.0/envloop/rsi_cli.py +49 -0
  10. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/pyproject.toml +1 -1
  11. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/README.pypi.md +0 -0
  12. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/__init__.py +0 -0
  13. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/auth_cli.py +0 -0
  14. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/auth_login.py +0 -0
  15. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/auth_workspace.py +0 -0
  16. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/cli_output.py +0 -0
  17. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/config.py +0 -0
  18. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/job_logs.py +0 -0
  19. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/lifecycle_cli.py +0 -0
  20. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/navigation_resources.py +0 -0
  21. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/profile_secrets.py +0 -0
  22. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/resource_cli.py +0 -0
  23. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/resources.py +0 -0
  24. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/sandbox.py +0 -0
  25. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/train.py +0 -0
  26. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/train_log_cli.py +0 -0
  27. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/training/__init__.py +0 -0
  28. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/training/credentials.py +0 -0
  29. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/training/sampling_client.py +0 -0
  30. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/training/service_client.py +0 -0
  31. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/utils/__init__.py +0 -0
  32. {envloop_cli-0.4.0 → envloop_cli-1.4.0}/envloop/utils/logging.py +0 -0
@@ -6,3 +6,6 @@ dist/
6
6
 
7
7
  # Local environment configuration is machine-specific and must not be committed.
8
8
  .env.local
9
+
10
+ # Local runtime output from offline platform API contract fixtures.
11
+ .envplatform/
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: envloop-cli
3
- Version: 0.4.0
3
+ Version: 1.4.0
4
4
  Summary: EnvLoop CLI and Python SDK for jobs, training, checkpoints and inference
5
5
  Project-URL: Homepage, https://envloop.ai
6
6
  Project-URL: Documentation, https://docs.envloop.ai
@@ -7,6 +7,7 @@ using the same rules as the Console's agent runs page.
7
7
  """
8
8
 
9
9
  from datetime import datetime
10
+ from urllib.parse import quote, urlencode
10
11
 
11
12
  from .train import TrainJobs
12
13
 
@@ -206,3 +207,38 @@ class AgentRuns:
206
207
  if run not in runs:
207
208
  raise AgentRunError("AGENT_RUN_NOT_FOUND")
208
209
  return {**_detail(run, runs[run]), "observed_at": observed_at}
210
+
211
+ # The RSI loop service behind the platform (``/v1/agent-runs/rsi``). Starting spends money, so
212
+ # ``start`` needs a key with ``training.run``; ``control(stop)`` also needs ``training.stop``.
213
+ def _rsi(self, method: str, path: str, body=None) -> dict:
214
+ return self._train_jobs.transport.request(method, "/v1/agent-runs/rsi" + path, body)
215
+
216
+ def start(self, run: str, brief: str, *, model_usd_cap: float, usd_cap: float | None = None,
217
+ model_request_cap: int | None = None, domain: str | None = None, rounds: int | None = None,
218
+ dry_run: bool = False, student_model: str | None = None) -> dict:
219
+ """Start a new RSI run; the platform validates every field. ``dry_run`` uses no GPU."""
220
+ limits = {"model_usd_cap": model_usd_cap}
221
+ for key, value in (("usd_cap", usd_cap), ("model_request_cap", model_request_cap)):
222
+ if value is not None:
223
+ limits[key] = value
224
+ body = {"run": run, "brief": brief, "limits": limits}
225
+ for key, value in (("domain", domain), ("rounds", rounds), ("student_model", student_model)):
226
+ if value is not None:
227
+ body[key] = value
228
+ if dry_run:
229
+ body["dry_run"] = True
230
+ return self._rsi("POST", "/runs", body)
231
+
232
+ def live(self, run: str, since: int | None = None) -> dict:
233
+ """What a run does now; pass the previous ``next_cursor`` as ``since`` for newer events."""
234
+ query = "?" + urlencode({"since": since}) if since is not None else ""
235
+ return self._rsi("GET", f"/runs/{quote(run, safe='')}/live{query}")
236
+
237
+ def steer(self, run: str, text: str) -> dict:
238
+ """Queue a message for the running operator (1 to 4000 characters)."""
239
+ return self._rsi("POST", f"/runs/{quote(run, safe='')}/steer", {"text": text})
240
+
241
+ def control(self, run: str, action: str, rounds: int | None = None) -> dict:
242
+ """``extend`` (needs ``rounds``), ``stop`` (after the current round) or ``resume``."""
243
+ return self._rsi("POST", f"/runs/{quote(run, safe='')}/control",
244
+ {"action": action, **({} if rounds is None else {"rounds": rounds})})
@@ -208,6 +208,27 @@ def parser():
208
208
  runs_get = runs.add_parser("get", help="Show a run's rounds, Train Jobs and checkpoints")
209
209
  runs_get.add_argument("run", metavar="RUN", help="run label: user_metadata.rsi_run or agent_run")
210
210
  runs_get.add_argument("--json", action="store_true", help="Output the complete run as JSON (default: tables)")
211
+ runs_start = runs.add_parser("start", help="Start a new RSI loop run (paid; needs training.run)")
212
+ runs_start.add_argument("run", metavar="RUN", help="new run id: lower-case letters, digits and dashes")
213
+ brief = runs_start.add_mutually_exclusive_group(required=True)
214
+ brief.add_argument("--brief", help="the goal of the run (up to 4000 characters)")
215
+ brief.add_argument("--brief-file", metavar="PATH", help="read the goal from a file, or - for standard input")
216
+ runs_start.add_argument("--model-usd-cap", type=float, required=True, help="strong-model spend cap in USD (the hard stop)")
217
+ runs_start.add_argument("--usd-cap", type=float, help="cap in USD for model plus GPU training together")
218
+ runs_start.add_argument("--model-request-cap", type=int, help="cap on model requests")
219
+ runs_start.add_argument("--domain", help="task family (default: the service's default; an unknown value is rejected)")
220
+ runs_start.add_argument("--rounds", type=int, help="target rounds (default: the service's default)")
221
+ runs_start.add_argument("--dry-run", action="store_true", help="GPU-free run: trains nothing; exercises the loop, spends model budget only")
222
+ runs_start.add_argument("--student-model", help="gateway student model of a dry run")
223
+ runs_live = runs.add_parser("live", help="Show what a run does now; --follow streams new events")
224
+ runs_live.add_argument("run", metavar="RUN")
225
+ runs_live.add_argument("--since", type=int, help="only events after this cursor (the previous next_cursor)")
226
+ runs_live.add_argument("--follow", action="store_true", help="poll and print new events until the run ends; Ctrl-C exits without stopping it")
227
+ runs_steer = runs.add_parser("steer", help="Message the running operator now (needs training.run)")
228
+ runs_steer.add_argument("run", metavar="RUN")
229
+ runs_steer.add_argument("text", metavar="TEXT", help="1 to 4000 characters")
230
+ runs_stop = runs.add_parser("stop", help="Stop a run after its current round (needs training.run and training.stop)")
231
+ runs_stop.add_argument("run", metavar="RUN")
211
232
  tasks = groups.add_parser("trail", help="Inspect and control existing trials").add_subparsers(dest="action", required=True)
212
233
  listing = tasks.add_parser("list", help="List Agent, Sandbox, Train and Inference worker Trials")
213
234
  listing.add_argument("--type", choices=("agent", "sandbox", "train", "inference"), help="Filter by Trial type")
@@ -230,11 +251,11 @@ def parser():
230
251
  download.add_argument("trial_id")
231
252
  download.add_argument("directory", type=Path)
232
253
  profiles = groups.add_parser("profile", help="Manage platform runtime profiles").add_subparsers(dest="action", required=True)
233
- put = profiles.add_parser("create", help="Create an immutable Profile version from JSON")
254
+ put = profiles.add_parser("create", help="Create an immutable Profile version from TOML or JSON")
234
255
  put.add_argument("name")
235
256
  put.add_argument("version")
236
- put.add_argument("--file", type=Path, required=True, help="ProfileSpec JSON file")
237
- put.add_argument("--runner", metavar="RUNNER", help="Bind org/name@<full-commit> to this version")
257
+ put.add_argument("--file", type=Path, required=True, help="Profile TOML or JSON file")
258
+ put.add_argument("--runner", metavar="RUNNER", help="Bind a Runner revision to this version")
238
259
  secret_input = put.add_mutually_exclusive_group()
239
260
  secret_input.add_argument("--prompt-model-api-key", action="store_true", help="Read the model API key from a non-echoing prompt")
240
261
  secret_input.add_argument("--model-api-key-stdin", action="store_true", help="Read the model API key from one line of standard input")
@@ -242,11 +263,16 @@ def parser():
242
263
  update.add_argument("name")
243
264
  update.add_argument("version", help="New version; existing versions cannot be overwritten")
244
265
  update.add_argument("--from-version", help="Source version; omit to use the explicit default")
245
- update.add_argument("--file", type=Path, required=True, help="JSON patch: merge literal params keys, replace supplied metadata; preserve omitted fields")
246
- update.add_argument("--runner", metavar="RUNNER", help="Bind a Runner name@full-commit; omit to preserve the source binding")
266
+ update.add_argument("--file", type=Path, required=True, help="TOML or JSON patch: merge params keys, replace supplied metadata; preserve omitted fields")
267
+ update.add_argument("--runner", metavar="RUNNER", help="Bind a Runner revision; v1 requires a full commit; omit to preserve the source binding")
247
268
  update_secret = update.add_mutually_exclusive_group()
248
269
  update_secret.add_argument("--prompt-model-api-key", action="store_true", help="Read an encrypted model connection key from a non-echoing prompt")
249
270
  update_secret.add_argument("--model-api-key-stdin", action="store_true", help="Read an encrypted model connection key from one line of standard input")
271
+ fork = profiles.add_parser('fork', help='Fork an existing Profile into a new immutable identity')
272
+ fork.add_argument('source_name')
273
+ fork.add_argument('source_version')
274
+ fork.add_argument('name')
275
+ fork.add_argument('version')
250
276
  get = profiles.add_parser("get")
251
277
  get.add_argument("name")
252
278
  get.add_argument("--version")
@@ -406,7 +432,8 @@ def main(argv=None):
406
432
  args.runner = runner_selector(args.runner)
407
433
  except ValueError as exc:
408
434
  cli.error(str(exc))
409
- if sum(value is not None for value in (args.dataset, args.dataset_option, args.source)) != 1:
435
+ selections = sum(value is not None for value in (args.dataset, args.dataset_option, args.source))
436
+ if selections != 1 and not (selections == 0 and args.profile):
410
437
  cli.error("provide exactly one positional dataset, --dataset or --source")
411
438
  args.dataset = args.dataset if args.dataset is not None else args.dataset_option
412
439
  if args.source is not None and any(getattr(args, key) is not None for key in ("runner", "task_id", "config", "split", "revision")):
@@ -430,7 +457,7 @@ def main(argv=None):
430
457
 
431
458
  raw = args.file.read_bytes()
432
459
  patch = read_profile_patch(raw)
433
- if args.runner is not None:
460
+ if args.action == 'update' and args.runner is not None:
434
461
  patch = with_runner(patch, args.runner)
435
462
  raw = json.dumps(patch).encode('utf-8')
436
463
  secrets = None
@@ -450,8 +477,10 @@ def main(argv=None):
450
477
  patch=patch, from_version=args.from_version, secrets=secrets)
451
478
  else:
452
479
  result = client.profiles.import_spec(
453
- raw, name=args.name, version=args.version, secrets=secrets
480
+ raw, name=args.name, version=args.version, secrets=secrets, runner=args.runner
454
481
  )
482
+ elif args.action == 'fork':
483
+ result = client.profiles.fork(args.source_name, args.source_version, name=args.name, version=args.version)
455
484
  elif args.action == "get":
456
485
  result = client.profiles.get(args.name, args.version)
457
486
  elif args.action == "list":
@@ -495,6 +524,12 @@ def main(argv=None):
495
524
  from .train_log_cli import read_logs
496
525
 
497
526
  return read_logs(client.jobs, args)
527
+ elif args.action == "run" and args.run_action in {"start", "live", "steer", "stop"}:
528
+ from .rsi_cli import run_rsi
529
+
530
+ result = run_rsi(client.agent_runs, args)
531
+ if result is None:
532
+ return 0
498
533
  elif args.action == "run":
499
534
  result = client.agent_runs.list() if args.run_action == "list" else client.agent_runs.get(args.run)
500
535
  elif args.action == "list":
@@ -82,6 +82,11 @@ _register("RUNNER_NOT_FOUND", "The Runner reference was not found or is not read
82
82
  _register("INVALID_SANDBOX_RUNNER", "The Runner revision cannot execute as a standalone Sandbox Job.", "Check '{program} runner list' and select a frozen Runner revision whose environment supports execution without a Dataset.")
83
83
  _register("INVALID_SANDBOX_IMAGE", "The Sandbox image reference is invalid.", "Use a Docker image reference name[:tag][@sha256:digest] and check '{command} --help'.")
84
84
 
85
+ _register("RSI_RUN_NOT_FOUND", "No RSI run with this name is visible in the current project.", "Check the name with '{program} job run list' and the scope with '{program} auth config show'; a run you just started appears once the service has accepted it.")
86
+ _register("INVALID_RSI_REQUEST INVALID_STEER INVALID_DIRECTIVE", "The RSI service rejected the request fields.", "Check '{command} --help' and https://docs.envloop.ai/agent-docs/en/guides/agent-runs.md for the run id format, the allowed domain and rounds, and the required spend cap.")
87
+ _register("RSI_CONFLICT RSI_RUN_NOT_ACTIVE", "The run id exists, the run is not in a state that allows this action, or no loop machine is free.", "Pick a new run id for a start; read the run with '{program} job run live RUN' before steering or stopping it.")
88
+ _register("RSI_CONTROL_UNCONFIGURED RSI_CONTROL_UNAVAILABLE RSI_CONTROL_TIMEOUT", "The RSI loop service is not available through this platform right now.", _RETRY_HINT)
89
+
85
90
  _register("JOB_ACTION_UNSUPPORTED", "This Job type does not support the requested action.", "Check the Job type with '{program} job get JOB_ID' and use its supported actions.")
86
91
  _register("INFERENCE_ROUTE_RETIRED", "The global inference route has been retired.", "Use the owning Job's base URL: API_BASE/v1/job/JOB_ID/Inference, and a model deployed by that Job.")
87
92
 
@@ -343,16 +343,38 @@ class Profiles:
343
343
 
344
344
  Omitted fields and Secret markers are preserved. Supplied metadata,
345
345
  including secret_params, replaces that field. Parameter values replace
346
- whole values, including objects; keys are literal. The default is unchanged.
346
+ whole values, including objects. V1 keys are literal; v2 keys are case
347
+ insensitive and live in spec.params. The default is unchanged.
347
348
  """
348
- from .profile_updates import checked_patch
349
+ from .profile_updates import checked_patch, merge_v2_params
349
350
 
350
351
  patch = checked_patch(patch, name, version)
351
352
  original = self.get(name, from_version)["spec"]
352
- spec = {**original, **patch, "name": name, "version": version,
353
- "params": {**original.get("params", {}), **patch.get("params", {})}}
353
+ spec = {**original, **patch, "name": name, "version": version}
354
+ if original.get('schema_version') == 'envplatform.profile/v2':
355
+ if 'params' in patch:
356
+ from .http import RemoteError
357
+ raise RemoteError('INVALID_PROFILE', 422)
358
+ before, changes = original.get('spec', {}), patch.get('spec', {})
359
+ spec['spec'] = {**before, **changes, 'params': merge_v2_params(before.get('params', {}), changes.get('params', {}), spec.get('secret_params', []))}
360
+ else:
361
+ spec['params'] = {**original.get('params', {}), **patch.get('params', {})}
354
362
  return self.put(spec, secrets=secrets)
355
363
 
364
+ def fork(self, source_name, source_version, *, name, version, patch=None, secrets=None):
365
+ """Publish a new identity from an authorized source; never change its default."""
366
+ from .profile_updates import checked_patch, merge_v2_params
367
+
368
+ original = self.get(source_name, source_version)['spec']
369
+ changes = checked_patch({} if patch is None else patch, name, version)
370
+ result = {**original, **changes, 'name': name, 'version': version}
371
+ if original.get('schema_version') == 'envplatform.profile/v2':
372
+ before, updates = original.get('spec', {}), changes.get('spec', {})
373
+ result['spec'] = {**before, **updates, 'params': merge_v2_params(before.get('params', {}), updates.get('params', {}), result.get('secret_params', []))}
374
+ else:
375
+ result['params'] = {**original.get('params', {}), **changes.get('params', {})}
376
+ return self.put(result, secrets=secrets)
377
+
356
378
  def get(self, name: str, version: str | None = None) -> dict:
357
379
  return self._server.get_profile(name, version)
358
380
 
@@ -377,7 +399,31 @@ class Profiles:
377
399
  """Revoke model access for a scoped immutable secret revision."""
378
400
  return self._server.revoke_profile_secret(name, version)
379
401
 
380
- def import_spec(self, raw: bytes, *, name=None, version=None, secrets=None):
402
+ def import_spec(self, raw: bytes, *, name=None, version=None, secrets=None, runner=None):
403
+ import json
404
+
405
+ from .profile_updates import read_profile_patch, with_runner
406
+
407
+ value = read_profile_patch(raw)
408
+ if isinstance(value, dict) and value.get('schema_version') == 'envhub.runner/v1':
409
+ from .http import RemoteError
410
+
411
+ definition = value.get('runner')
412
+ declarations = value.get('params', {})
413
+ if (not isinstance(definition, dict) or not isinstance(definition.get('name'), str)
414
+ or not definition['name'] or not isinstance(declarations, dict)
415
+ or any(not isinstance(item, dict) for item in declarations.values())):
416
+ raise RemoteError('INVALID_PROFILE', 422)
417
+ if runner is not None and runner.partition('@')[0] != definition['name']:
418
+ raise RemoteError('INVALID_PROFILE_RUNNER', 422)
419
+ defaults = {key: declaration['default'] for key, declaration in declarations.items()
420
+ if 'default' in declaration}
421
+ value = {'schema_version': 'envplatform.profile/v2', 'name': name, 'version': version,
422
+ 'runner': runner if runner is not None else definition['name'] + '@main',
423
+ 'spec': {'params': defaults, **({'env': value['env']} if 'env' in value else {})}}
424
+ if runner is not None:
425
+ value = with_runner(value, runner)
426
+ raw = json.dumps(value, allow_nan=False, ensure_ascii=False).encode('utf-8')
381
427
  options = {} if secrets is None else {"secrets": secrets}
382
428
  return self._server.import_profile(raw, name=name, version=version, **options)
383
429
 
@@ -454,9 +500,10 @@ class Jobs:
454
500
  body['image'] = validate_image(image)
455
501
  validate_public_execution(body)
456
502
  return self._server.submit_job(body)
457
- if sum(value is not None for value in (dataset, source, task_ref)) != 1:
503
+ profile_only = all(value is None for value in (dataset, source, task_ref)) and (profile_id is not None or options.get("profile_name") is not None)
504
+ if sum(value is not None for value in (dataset, source, task_ref)) != 1 and not profile_only:
458
505
  raise ValueError("provide exactly one dataset, source or task_ref")
459
- if dataset is None and (runner is not None or any(value is not None for value in (task_id, namespace, config, split, revision))):
506
+ if dataset is None and not profile_only and (runner is not None or any(value is not None for value in (task_id, namespace, config, split, revision))):
460
507
  raise ValueError("dataset selection options require a dataset")
461
508
  if runner is not None:
462
509
  runner = runner_selector(runner)
@@ -464,7 +511,9 @@ class Jobs:
464
511
  options["command"] = validate_command(command)
465
512
  selection = {key: value for key, value in dict(task_id=task_id, namespace=namespace, config=config,
466
513
  split=split, revision=revision).items() if value is not None}
467
- if source is not None:
514
+ if profile_only:
515
+ source = {"dataset": selection} if selection else {}
516
+ elif source is not None:
468
517
  source = {"task": load_task(source)}
469
518
  elif task_ref is not None:
470
519
  source = {"task_ref": dict(task_ref)}
@@ -535,7 +584,12 @@ class Jobs:
535
584
  def stop(self, job_id):
536
585
  return self._server.stop_job(job_id)
537
586
 
538
- def wait(self, job_id, *, timeout=600, poll_interval=.1):
587
+ def wait(self, job_id, *, timeout=600, poll_interval=.1, max_poll_interval=5):
588
+ """Poll until terminal; the interval grows 1.5x per poll up to ``max_poll_interval``.
589
+
590
+ Jobs that run for tens of minutes (large-model training) would otherwise
591
+ issue ten status requests a second for the whole wait.
592
+ """
539
593
  if not math.isfinite(timeout) or timeout < 0:
540
594
  raise ValueError("timeout must be finite and non-negative")
541
595
  if not math.isfinite(poll_interval) or poll_interval <= 0:
@@ -549,6 +603,7 @@ class Jobs:
549
603
  if remaining <= 0:
550
604
  raise TimeoutError("job did not reach a terminal state")
551
605
  time.sleep(min(poll_interval, remaining))
606
+ poll_interval = max(poll_interval, min(poll_interval * 1.5, max_poll_interval))
552
607
 
553
608
 
554
609
  class Client:
@@ -307,22 +307,10 @@ class HttpService:
307
307
  sort_keys=True, separators=(",", ":"), allow_nan=False).encode("utf-8")
308
308
 
309
309
  def import_profile(self, raw, *, name=None, version=None, secrets=None):
310
- def unique_object(pairs):
311
- result = {}
312
- for key, value in pairs:
313
- if key in result:
314
- raise ValueError("duplicate key")
315
- result[key] = value
316
- return result
310
+ from .profile_updates import read_profile_patch
317
311
 
318
- def invalid_constant(value):
319
- raise ValueError("non-finite JSON value")
320
-
321
- try:
322
- spec = json.loads(raw, object_pairs_hook=unique_object, parse_constant=invalid_constant)
323
- if (not isinstance(spec, dict) or (name is not None and spec.get("name") != name)
324
- or (version is not None and spec.get("version") != version)):
325
- raise ValueError("Profile name/version mismatch")
326
- except (ValueError, UnicodeError, TypeError):
327
- raise RemoteError("INVALID_PROFILE", 422) from None
312
+ spec = read_profile_patch(raw)
313
+ if (not isinstance(spec, dict) or (name is not None and spec.get("name") != name)
314
+ or (version is not None and spec.get("version") != version)):
315
+ raise RemoteError("INVALID_PROFILE", 422)
328
316
  return self.put_profile(profile_payload(spec, secrets))
@@ -1,5 +1,6 @@
1
1
  """Build new Profile versions without changing the source or its default."""
2
2
  import json
3
+ import tomllib
3
4
  from collections.abc import Mapping
4
5
 
5
6
  from .http import RemoteError
@@ -18,13 +19,19 @@ def read_profile_patch(raw):
18
19
  raise ValueError
19
20
 
20
21
  try:
21
- return json.loads(raw, object_pairs_hook=unique, parse_constant=invalid_constant)
22
+ text = raw.decode('utf-8') if isinstance(raw, bytes) else raw
23
+ try:
24
+ value = json.loads(text, object_pairs_hook=unique, parse_constant=invalid_constant)
25
+ except ValueError:
26
+ value = tomllib.loads(text)
27
+ json.dumps(value, allow_nan=False)
28
+ return value
22
29
  except (ValueError, UnicodeError, TypeError):
23
30
  raise RemoteError("INVALID_PROFILE", 422) from None
24
31
 
25
32
 
26
33
  def checked_patch(patch, name, version):
27
- allowed = {"schema_version", "name", "version", "params", "description", "created_for", "secret_params", "runner"}
34
+ allowed = {"schema_version", "name", "version", "params", "description", "created_for", "secret_params", "agent", "runner", "dataset", "dataset_mode", "task", "tags", "spec"}
28
35
 
29
36
  def string_keys(value):
30
37
  if isinstance(value, Mapping):
@@ -39,7 +46,8 @@ def checked_patch(patch, name, version):
39
46
  try:
40
47
  if (not isinstance(patch, Mapping) or set(patch) - allowed
41
48
  or patch.get("name", name) != name or patch.get("version", version) != version
42
- or not isinstance(patch.get("params", {}), Mapping)):
49
+ or not isinstance(patch.get("params", {}), Mapping)
50
+ or not isinstance(patch.get("spec", {}), Mapping)):
43
51
  raise ValueError
44
52
  # Reject non-finite numbers for SDK input as well as CLI JSON files.
45
53
  json.dumps(patch, allow_nan=False)
@@ -49,6 +57,18 @@ def checked_patch(patch, name, version):
49
57
  return dict(patch)
50
58
 
51
59
 
60
+ def merge_v2_params(base, override, secrets=()):
61
+ """Overlay parameter values using the Runner's case insensitive names."""
62
+ if not isinstance(base, Mapping) or not isinstance(override, Mapping):
63
+ raise RemoteError("INVALID_PROFILE", 422)
64
+ targets = [key.upper() for key in override]
65
+ if len(set(targets)) != len(targets):
66
+ raise RemoteError("INVALID_PROFILE", 422)
67
+ marked = {key.upper(): key for key in secrets}
68
+ changes = {marked.get(key.upper(), key): item for key, item in override.items()}
69
+ return {key: item for key, item in base.items() if key.upper() not in targets} | changes
70
+
71
+
52
72
  def with_runner(value, runner):
53
73
  """Keep a file binding and explicit CLI binding unambiguous."""
54
74
  if not isinstance(value, Mapping) or value.get('runner', runner) != runner:
@@ -0,0 +1,49 @@
1
+ """``el job run start|live|steer|stop``: thin wrappers over the platform's RSI routes."""
2
+
3
+ import sys
4
+ import time
5
+
6
+ FINISHED = frozenset({"finished", "failed", "stopped", "unreadable"})
7
+ POLL_SECONDS = 3.0
8
+
9
+
10
+ def _brief(args):
11
+ if args.brief is not None:
12
+ return args.brief
13
+ if args.brief_file == "-":
14
+ return sys.stdin.read()
15
+ with open(args.brief_file, encoding="utf-8") as handle:
16
+ return handle.read()
17
+
18
+
19
+ def _follow(runs, run, since):
20
+ """Print new events as ``seq kind: text`` until the run ends; the run itself is left alone."""
21
+ while True:
22
+ live = runs.live(run, since)
23
+ for event in live.get("events") or []:
24
+ print(f"{event.get('seq')} {event.get('kind')}: {event.get('text') or ''}", flush=True)
25
+ if isinstance(live.get("next_cursor"), int):
26
+ since = live["next_cursor"]
27
+ if live.get("state") in FINISHED:
28
+ print(f"state: {live['state']}", flush=True)
29
+ return
30
+ time.sleep(POLL_SECONDS)
31
+
32
+
33
+ def run_rsi(runs, args):
34
+ """Run one action; returns the result to print, or None when it printed its own output."""
35
+ if args.run_action == "start":
36
+ return runs.start(args.run, _brief(args), model_usd_cap=args.model_usd_cap, usd_cap=args.usd_cap,
37
+ model_request_cap=args.model_request_cap, domain=args.domain, rounds=args.rounds,
38
+ dry_run=args.dry_run, student_model=args.student_model)
39
+ if args.run_action == "live":
40
+ if not args.follow:
41
+ return runs.live(args.run, args.since)
42
+ try:
43
+ _follow(runs, args.run, args.since)
44
+ except KeyboardInterrupt:
45
+ pass
46
+ return None
47
+ if args.run_action == "steer":
48
+ return runs.steer(args.run, args.text)
49
+ return runs.control(args.run, "stop")
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "envloop-cli"
3
- version = "0.4.0"
3
+ version = "1.4.0"
4
4
  description = "EnvLoop CLI and Python SDK for jobs, training, checkpoints and inference"
5
5
  requires-python = ">=3.11"
6
6
  readme = "README.pypi.md"
File without changes