@simplexai/localmodels-darwin-arm64 0.1.0-dev.43 → 0.1.0-dev.45
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.
- package/bootstrap.identity +1 -1
- package/bootstrap.sha256 +76 -79
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/__main__.py +0 -1
- package/modules/localmodels/auth_proxy.py +285 -82
- package/modules/localmodels/bifrost_checks.py +3 -127
- package/modules/localmodels/bifrost_clients.py +1 -1
- package/modules/localmodels/bifrost_config.py +2 -2
- package/modules/localmodels/bifrost_models.py +9 -2
- package/modules/localmodels/bifrost_pi.py +1 -1
- package/modules/localmodels/bifrost_provider.py +42 -7
- package/modules/localmodels/budget.py +16 -1
- package/modules/localmodels/catalog.json +15 -50
- package/modules/localmodels/catalog_recipes.py +1 -1
- package/modules/localmodels/debug_mode.py +2 -18
- package/modules/localmodels/engines-strata-poly-0.1.45-poly.9.json +41 -1
- package/modules/localmodels/engines.py +19 -6
- package/modules/localmodels/gateway.py +50 -15
- package/modules/localmodels/gateway_accept.py +8 -5
- package/modules/localmodels/gateway_bifrost.py +23 -13
- package/modules/localmodels/gateway_cli.py +5 -2
- package/modules/localmodels/gateway_requests.py +9 -2
- package/modules/localmodels/harness.py +41 -12
- package/modules/localmodels/harness_gateway.py +1 -1
- package/modules/localmodels/hosts.py +7 -20
- package/modules/localmodels/library_convert.py +491 -57
- package/modules/localmodels/library_gateway.py +27 -16
- package/modules/localmodels/library_pricing.py +155 -31
- package/modules/localmodels/library_status.py +29 -4
- package/modules/localmodels/npm_transport.py +62 -54
- package/modules/localmodels/probe.py +42 -9
- package/modules/localmodels/recommend.py +1 -1
- package/modules/localmodels/recommend_cli.py +2 -2
- package/modules/localmodels/remote_ops.py +14 -6
- package/modules/localmodels/remote_ops_download.py +1 -1
- package/modules/localmodels/remote_ops_verify.py +0 -33
- package/modules/localmodels/runtime_args.py +2 -1
- package/modules/localmodels/runtime_auth.py +75 -25
- package/modules/localmodels/runtime_cli.py +9 -9
- package/modules/localmodels/runtime_install.py +57 -23
- package/modules/localmodels/runtime_io.py +224 -243
- package/modules/localmodels/runtime_process.py +15 -7
- package/modules/localmodels/runtime_windows_acl.py +196 -0
- package/modules/localmodels/source_byok.py +122 -33
- package/modules/localmodels/source_byok_probe.py +57 -141
- package/modules/localmodels/source_cli.py +19 -18
- package/modules/localmodels/stack.py +13 -6
- package/modules/localmodels/stack_args.py +6 -8
- package/modules/localmodels/stack_binding.py +3 -3
- package/modules/localmodels/stack_client_settings.py +8 -1
- package/modules/localmodels/stack_compose.py +4 -8
- package/modules/localmodels/stack_events.py +2 -1
- package/modules/localmodels/stack_plan.py +1 -4
- package/modules/localmodels/stack_ports.py +0 -1
- package/modules/localmodels/stack_route.py +1 -5
- package/modules/localmodels/stack_run.py +15 -30
- package/modules/localmodels/stack_suite.py +23 -46
- package/modules/localmodels/stack_summary.py +0 -1
- package/modules/localmodels/stack_try.py +3 -92
- package/modules/localmodels/stack_up.py +27 -4
- package/modules/localmodels/stack_update.py +5 -5
- package/modules/localmodels/stack_view_apply.py +1 -1
- package/modules/localmodels/stack_view_sandbox.py +0 -2
- package/modules/localmodels/stack_view_text.py +0 -1
- package/modules/localmodels/stack_view_words.py +0 -1
- package/modules/localmodels/suite.py +4 -7
- package/modules/localmodels/tui_dialogs.py +0 -1
- package/modules/localmodels/vision.py +2 -1
- package/modules/localmodels/web/view/view.css +1 -4
- package/modules/{simplex_localmodels-0.1.0.dev43.dist-info → simplex_localmodels-0.1.0.dev45.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev43.dist-info → simplex_localmodels-0.1.0.dev45.dist-info}/RECORD +73 -76
- package/package.json +1 -1
- package/tool.json +1 -1
- package/modules/localmodels/bifrost_search.py +0 -66
- package/modules/localmodels/gateway_search.py +0 -223
- package/modules/localmodels/search-ddgs-9.16.1.txt +0 -222
- package/modules/localmodels/search_server.py +0 -474
- /package/modules/{simplex_localmodels-0.1.0.dev43.dist-info → simplex_localmodels-0.1.0.dev45.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev43.dist-info → simplex_localmodels-0.1.0.dev45.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev43.dist-info → simplex_localmodels-0.1.0.dev45.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev43.dist-info → simplex_localmodels-0.1.0.dev45.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -95,6 +95,9 @@ class _Archive(TypedDict):
|
|
|
95
95
|
|
|
96
96
|
class Archive(_Archive, total=False):
|
|
97
97
|
npm_copy: NpmCopy
|
|
98
|
+
# Only these paths of the archive are unpacked (prefixes, after its top folder is dropped):
|
|
99
|
+
# a source archive whose deepest paths would pass Windows' 260-character limit.
|
|
100
|
+
members: list[str]
|
|
98
101
|
|
|
99
102
|
|
|
100
103
|
class ServiceParams(TypedDict): # all start, stop and status need; the base of the rest
|
|
@@ -206,7 +209,6 @@ RERANK_DOCS = [
|
|
|
206
209
|
"The Pacific is the largest ocean on Earth.",
|
|
207
210
|
]
|
|
208
211
|
RERANK_RELEVANT = 1
|
|
209
|
-
SEARCH_QUERY = "Python programming language" # every engine finds pages for it
|
|
210
212
|
|
|
211
213
|
|
|
212
214
|
def emit(event: str, **fields: object) -> None:
|
|
@@ -462,7 +464,7 @@ def _relative(name: str) -> str:
|
|
|
462
464
|
return name
|
|
463
465
|
|
|
464
466
|
|
|
465
|
-
def _unzip(archive: str, directory: str) -> None:
|
|
467
|
+
def _unzip(archive: str, directory: str, members: tuple[str, ...] = ()) -> None:
|
|
466
468
|
"""A Windows release zip: regular files only, each kept inside ``directory``."""
|
|
467
469
|
with zipfile.ZipFile(archive) as bundle:
|
|
468
470
|
names = [_relative(i.filename.replace("\\", "/")) for i in bundle.infolist()]
|
|
@@ -471,6 +473,8 @@ def _unzip(archive: str, directory: str) -> None:
|
|
|
471
473
|
for info, name in zip(bundle.infolist(), names):
|
|
472
474
|
if strip:
|
|
473
475
|
name = name.split("/", 1)[1] if "/" in name else ""
|
|
476
|
+
if members and not name.startswith(members):
|
|
477
|
+
continue
|
|
474
478
|
if not name or info.is_dir() or name.startswith("/") or ".." in name.split("/"):
|
|
475
479
|
continue
|
|
476
480
|
if ":" in name or (info.external_attr >> 16) & 0o170000 == 0o120000:
|
|
@@ -481,10 +485,12 @@ def _unzip(archive: str, directory: str) -> None:
|
|
|
481
485
|
shutil.copyfileobj(source, dest)
|
|
482
486
|
|
|
483
487
|
|
|
484
|
-
def unpack(archive: str, directory: str) -> None:
|
|
485
|
-
"""Extract into ``directory``, dropping the archive's single top folder when it has one
|
|
486
|
-
|
|
487
|
-
|
|
488
|
+
def unpack(archive: str, directory: str, keep: tuple[str, ...] = ()) -> None:
|
|
489
|
+
"""Extract into ``directory``, dropping the archive's single top folder when it has one;
|
|
490
|
+
``keep``: only the paths under these prefixes (Archive.members). A wheel is a zip
|
|
491
|
+
(PolyStrata's Windows build takes cuBLAS from NVIDIA's)."""
|
|
492
|
+
if archive.endswith((".zip", ".whl")):
|
|
493
|
+
_unzip(archive, directory, keep)
|
|
488
494
|
return
|
|
489
495
|
with tarfile.open(archive) as tar:
|
|
490
496
|
members = tar.getmembers()
|
|
@@ -494,6 +500,8 @@ def unpack(archive: str, directory: str) -> None:
|
|
|
494
500
|
name = member.name.lstrip("./")
|
|
495
501
|
if strip:
|
|
496
502
|
name = name.split("/", 1)[1] if "/" in name else ""
|
|
503
|
+
if keep and not name.startswith(keep):
|
|
504
|
+
continue
|
|
497
505
|
if not name or name.startswith("/") or ".." in name.split("/"):
|
|
498
506
|
continue
|
|
499
507
|
if member.issym() or member.islnk():
|
|
@@ -56,7 +56,7 @@ def act_engine(p: remote_ops.EngineParams) -> None:
|
|
|
56
56
|
npm_copies(a),
|
|
57
57
|
p.get("region"),
|
|
58
58
|
)
|
|
59
|
-
remote_ops.unpack(archive, directory)
|
|
59
|
+
remote_ops.unpack(archive, directory, tuple(a.get("members") or ()))
|
|
60
60
|
if not os.access(binary, os.X_OK):
|
|
61
61
|
raise RuntimeError(f"the engine has no executable {os.path.relpath(binary, directory)}")
|
|
62
62
|
remote_ops._write(done_marker, expected)
|
|
@@ -415,38 +415,6 @@ def _verify_tts(root: str, p: remote_ops.VerifyParams) -> None:
|
|
|
415
415
|
)
|
|
416
416
|
|
|
417
417
|
|
|
418
|
-
SEARCH_ATTEMPTS = 3 # free engines throttle by exit IP: aws-l4 answered 2 of 3 queries 8 s apart
|
|
419
|
-
SEARCH_RETRY_S = 5.0
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
def _verify_search(root: str, p: remote_ops.VerifyParams) -> None:
|
|
423
|
-
"""A real web search answers with at least one result page; the engine named is the one that
|
|
424
|
-
answered (DuckDuckGo unless it is rate limited). Only "no engine answered" is asked again, a
|
|
425
|
-
few times and spaced out; any other failure is final."""
|
|
426
|
-
started = time.monotonic()
|
|
427
|
-
query = urllib.parse.urlencode({"q": remote_ops.SEARCH_QUERY, "format": "json"})
|
|
428
|
-
for attempt in range(1, SEARCH_ATTEMPTS + 1):
|
|
429
|
-
try:
|
|
430
|
-
resp = remote_ops._http(f"{root}/search?{query}", p["api_key"], timeout=120)
|
|
431
|
-
break
|
|
432
|
-
except urllib.error.HTTPError as exc:
|
|
433
|
-
if exc.code != 502 or json.loads(exc.read(1024)) != {
|
|
434
|
-
"error": "SEARCH_PROVIDER_UNAVAILABLE"
|
|
435
|
-
}:
|
|
436
|
-
raise
|
|
437
|
-
if attempt == SEARCH_ATTEMPTS:
|
|
438
|
-
raise RuntimeError("SEARCH_PROVIDER_UNAVAILABLE") from None
|
|
439
|
-
time.sleep(SEARCH_RETRY_S)
|
|
440
|
-
results = resp.get("results")
|
|
441
|
-
if not isinstance(results, list) or not all(isinstance(r, dict) for r in results):
|
|
442
|
-
raise ValueError("invalid search results")
|
|
443
|
-
urls = [str(r.get("url") or "") for r in results]
|
|
444
|
-
found = [u for u in urls if u.startswith(("http://", "https://"))]
|
|
445
|
-
engine = str(results[0].get("engine") or "") if results else ""
|
|
446
|
-
answer = f"{len(found)} results via {engine or '?'}"
|
|
447
|
-
_report(bool(found), answer, started, "the search returned no results page")
|
|
448
|
-
|
|
449
|
-
|
|
450
418
|
CONTRACTS = {
|
|
451
419
|
"systemone": _verify_decision,
|
|
452
420
|
"health": lambda root, p: remote_ops.emit(
|
|
@@ -456,5 +424,4 @@ CONTRACTS = {
|
|
|
456
424
|
"rerank": _verify_rerank,
|
|
457
425
|
"stt": _verify_stt,
|
|
458
426
|
"tts": _verify_tts,
|
|
459
|
-
"search": _verify_search,
|
|
460
427
|
}
|
|
@@ -32,7 +32,8 @@ DOCS: dict[str, tuple[str, str, list[tuple[str, str]]]] = {
|
|
|
32
32
|
'openai-compatible; openai-compatible also needs "baseUrl" (https, or http on loopback)\n'
|
|
33
33
|
'and "modelId", and for Codex "wireApi": "responses". Optional "contextWindow" is an\n'
|
|
34
34
|
"integer from 1 to 2147483647; otherwise probe /props then /models (5 s each, no\n"
|
|
35
|
-
"redirects or environment proxies), falling back to 32768 if unavailable.
|
|
35
|
+
"redirects or environment proxies), falling back to 32768 if unavailable. Optional\n"
|
|
36
|
+
'"vision" is a boolean; otherwise /props or /models determines image input. Other keys\n'
|
|
36
37
|
"are refused. Codex\n"
|
|
37
38
|
"takes openai or openai-compatible, Claude anthropic, pi any of them.",
|
|
38
39
|
[
|
|
@@ -204,6 +204,7 @@ def _validate_config(runtime: str, value: dict[str, Any]) -> None:
|
|
|
204
204
|
"modelId",
|
|
205
205
|
"wireApi",
|
|
206
206
|
"contextWindow",
|
|
207
|
+
"vision",
|
|
207
208
|
}:
|
|
208
209
|
raise ValueError("Invalid runtime credentials")
|
|
209
210
|
provider = value.get("provider")
|
|
@@ -220,7 +221,9 @@ def _validate_config(runtime: str, value: dict[str, Any]) -> None:
|
|
|
220
221
|
):
|
|
221
222
|
raise ValueError("Invalid runtime credentials")
|
|
222
223
|
if provider != "openai-compatible":
|
|
223
|
-
if any(
|
|
224
|
+
if any(
|
|
225
|
+
field in value for field in ("baseUrl", "modelId", "wireApi", "contextWindow", "vision")
|
|
226
|
+
):
|
|
224
227
|
raise ValueError("Invalid runtime model config")
|
|
225
228
|
return
|
|
226
229
|
if "contextWindow" in value and (
|
|
@@ -228,6 +231,8 @@ def _validate_config(runtime: str, value: dict[str, Any]) -> None:
|
|
|
228
231
|
or not 1 <= value["contextWindow"] <= MAX_CONTEXT_WINDOW
|
|
229
232
|
):
|
|
230
233
|
raise ValueError("contextWindow must be an integer between 1 and 2147483647")
|
|
234
|
+
if "vision" in value and type(value["vision"]) is not bool:
|
|
235
|
+
raise ValueError("vision must be a boolean")
|
|
231
236
|
base = value.get("baseUrl")
|
|
232
237
|
model = value.get("modelId")
|
|
233
238
|
if (
|
|
@@ -318,11 +323,59 @@ def _verify_config(value: dict[str, Any]) -> None:
|
|
|
318
323
|
) from None
|
|
319
324
|
|
|
320
325
|
|
|
321
|
-
def
|
|
326
|
+
def _props_metadata(result: dict[str, Any]) -> tuple[int | None, bool | None]:
|
|
327
|
+
settings = result.get("default_generation_settings")
|
|
328
|
+
raw_context = settings.get("n_ctx") if isinstance(settings, dict) else None
|
|
329
|
+
context = (
|
|
330
|
+
raw_context if type(raw_context) is int and 1 <= raw_context <= MAX_CONTEXT_WINDOW else None
|
|
331
|
+
)
|
|
332
|
+
modalities = result.get("modalities")
|
|
333
|
+
raw_vision = modalities.get("vision") if isinstance(modalities, dict) else None
|
|
334
|
+
vision = raw_vision if isinstance(raw_vision, bool) else None
|
|
335
|
+
return context, vision
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
def _model_vision(model: dict[str, Any]) -> bool:
|
|
339
|
+
if model.get("vision") is True:
|
|
340
|
+
return True
|
|
341
|
+
for key in ("modalities", "capabilities"):
|
|
342
|
+
section = model.get(key)
|
|
343
|
+
if isinstance(section, dict) and section.get("vision") is True:
|
|
344
|
+
return True
|
|
345
|
+
architecture = model.get("architecture")
|
|
346
|
+
for candidate in (
|
|
347
|
+
model.get("input_modalities"),
|
|
348
|
+
architecture.get("input_modalities") if isinstance(architecture, dict) else None,
|
|
349
|
+
):
|
|
350
|
+
if isinstance(candidate, list) and "image" in candidate:
|
|
351
|
+
return True
|
|
352
|
+
return False
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
def _models_metadata(result: dict[str, Any], model_id: object) -> tuple[int | None, bool | None]:
|
|
356
|
+
models = result.get("data")
|
|
357
|
+
if not isinstance(models, list):
|
|
358
|
+
return None, None
|
|
359
|
+
matched = next(
|
|
360
|
+
(model for model in models if isinstance(model, dict) and model.get("id") == model_id),
|
|
361
|
+
None,
|
|
362
|
+
)
|
|
363
|
+
if matched is None:
|
|
364
|
+
return None, None
|
|
365
|
+
raw_context = matched.get("max_model_len")
|
|
366
|
+
context = (
|
|
367
|
+
raw_context if type(raw_context) is int and 1 <= raw_context <= MAX_CONTEXT_WINDOW else None
|
|
368
|
+
)
|
|
369
|
+
return context, _model_vision(matched)
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
def _endpoint_metadata(value: dict[str, Any]) -> tuple[int, bool]:
|
|
373
|
+
explicit_vision: bool | None = bool(value["vision"]) if "vision" in value else None
|
|
322
374
|
if "contextWindow" in value:
|
|
323
|
-
return int(value["contextWindow"])
|
|
375
|
+
return int(value["contextWindow"]), bool(explicit_vision)
|
|
324
376
|
base = value["baseUrl"].rstrip("/")
|
|
325
377
|
opener = http_local.no_proxy_opener(allow_redirects=False)
|
|
378
|
+
probed_vision: bool | None = None
|
|
326
379
|
for url in (base.removesuffix("/v1") + "/props", base + "/models"):
|
|
327
380
|
try:
|
|
328
381
|
request = urllib.request.Request(
|
|
@@ -337,26 +390,20 @@ def _context_window(value: dict[str, Any]) -> int:
|
|
|
337
390
|
result = json.loads(body)
|
|
338
391
|
if not isinstance(result, dict):
|
|
339
392
|
continue
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
for model in models
|
|
351
|
-
if isinstance(model, dict) and model.get("id") == value["modelId"]
|
|
352
|
-
),
|
|
353
|
-
None,
|
|
393
|
+
context, found_vision = (
|
|
394
|
+
_props_metadata(result)
|
|
395
|
+
if url.endswith("/props")
|
|
396
|
+
else _models_metadata(result, value.get("modelId"))
|
|
397
|
+
)
|
|
398
|
+
if found_vision is not None and probed_vision is None:
|
|
399
|
+
probed_vision = found_vision
|
|
400
|
+
if context is not None:
|
|
401
|
+
return context, (
|
|
402
|
+
explicit_vision if explicit_vision is not None else bool(probed_vision)
|
|
354
403
|
)
|
|
355
|
-
if type(context) is int and 1 <= context <= MAX_CONTEXT_WINDOW:
|
|
356
|
-
return context
|
|
357
404
|
except (OSError, ValueError, http.client.HTTPException, RecursionError):
|
|
358
405
|
continue
|
|
359
|
-
return 32768
|
|
406
|
+
return 32768, (explicit_vision if explicit_vision is not None else bool(probed_vision))
|
|
360
407
|
|
|
361
408
|
|
|
362
409
|
def owned_files(directory: Path) -> dict[str, str]:
|
|
@@ -463,9 +510,10 @@ def save_config(root: Path, runtime: str, value: dict[str, Any]) -> None:
|
|
|
463
510
|
save_api_key(root, runtime, value["provider"], value["apiKey"])
|
|
464
511
|
_record_acceptance(root / "runtime" / runtime)
|
|
465
512
|
return
|
|
466
|
-
context_window =
|
|
513
|
+
context_window, supports_vision = _endpoint_metadata(value)
|
|
514
|
+
modalities = ["text", "image"] if supports_vision else ["text"]
|
|
467
515
|
if runtime == "codex":
|
|
468
|
-
_save_codex_model(root, value, context_window)
|
|
516
|
+
_save_codex_model(root, value, context_window, modalities)
|
|
469
517
|
_record_acceptance(root / "runtime" / runtime)
|
|
470
518
|
return
|
|
471
519
|
directory = root / "runtime" / "pi"
|
|
@@ -484,7 +532,7 @@ def save_config(root: Path, runtime: str, value: dict[str, Any]) -> None:
|
|
|
484
532
|
"id": value["modelId"],
|
|
485
533
|
"name": value["modelId"],
|
|
486
534
|
"reasoning": False,
|
|
487
|
-
"input":
|
|
535
|
+
"input": modalities,
|
|
488
536
|
"contextWindow": context_window,
|
|
489
537
|
"maxTokens": 4096,
|
|
490
538
|
"cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0},
|
|
@@ -502,7 +550,9 @@ def save_config(root: Path, runtime: str, value: dict[str, Any]) -> None:
|
|
|
502
550
|
_record_acceptance(directory)
|
|
503
551
|
|
|
504
552
|
|
|
505
|
-
def _save_codex_model(
|
|
553
|
+
def _save_codex_model(
|
|
554
|
+
root: Path, value: dict[str, Any], context_window: int, modalities: list[str]
|
|
555
|
+
) -> None:
|
|
506
556
|
directory = root / "runtime" / "codex"
|
|
507
557
|
_prepare_profile(directory, ("auth.json", "config.toml", "models.json", "model.json"))
|
|
508
558
|
_write_private(directory / "auth.json", {"OPENAI_API_KEY": value["apiKey"]})
|
|
@@ -532,7 +582,7 @@ def _save_codex_model(root: Path, value: dict[str, Any], context_window: int) ->
|
|
|
532
582
|
"context_window": context_window,
|
|
533
583
|
"effective_context_window_percent": 95,
|
|
534
584
|
"experimental_supported_tools": [],
|
|
535
|
-
"input_modalities":
|
|
585
|
+
"input_modalities": modalities,
|
|
536
586
|
}
|
|
537
587
|
]
|
|
538
588
|
},
|
|
@@ -257,11 +257,12 @@ def inspect_runtimes(
|
|
|
257
257
|
node: str | None = None,
|
|
258
258
|
launcher: str | None = None,
|
|
259
259
|
before_versions: dict[str, str] | None = None,
|
|
260
|
+
runtimes: tuple[str, ...] | None = None,
|
|
260
261
|
) -> dict[str, Any]:
|
|
261
262
|
"""Read-only local native status; auth output and key material remain private."""
|
|
262
263
|
validate_runtime_root(root)
|
|
263
264
|
rows: list[dict[str, Any]] = []
|
|
264
|
-
for runtime in RUNTIMES:
|
|
265
|
+
for runtime in RUNTIMES if runtimes is None else runtimes:
|
|
265
266
|
before_version = (before_versions or {}).get(runtime)
|
|
266
267
|
explicit = os.environ.get(f"SIMPLEX_{runtime.upper()}_PATH")
|
|
267
268
|
hosts = (
|
|
@@ -396,13 +397,9 @@ def build_plan(
|
|
|
396
397
|
raise ValueError("Unknown runtime")
|
|
397
398
|
if before_version is not None:
|
|
398
399
|
_stable_version(before_version)
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
root, before_versions={runtime: before_version} if before_version is not None else None
|
|
403
|
-
)["runtimes"]
|
|
404
|
-
if row["runtime"] == runtime
|
|
405
|
-
)
|
|
400
|
+
before = {runtime: before_version} if before_version is not None else None
|
|
401
|
+
rows = inspect_runtimes(root, before_versions=before, runtimes=(runtime,))["runtimes"]
|
|
402
|
+
status = next(row for row in rows if row["runtime"] == runtime)
|
|
406
403
|
if os.environ.get(f"SIMPLEX_{runtime.upper()}_PATH") is not None and status["executable"]:
|
|
407
404
|
if not _compatible_version(runtime, status["version"], before_version=before_version):
|
|
408
405
|
raise ValueError(
|
|
@@ -680,7 +677,10 @@ def _act(args: argparse.Namespace) -> dict[str, Any]:
|
|
|
680
677
|
"authenticated": True,
|
|
681
678
|
}
|
|
682
679
|
elif args.harness_action == "status":
|
|
683
|
-
|
|
680
|
+
selected = (args.runtime,) if args.runtime else None
|
|
681
|
+
value = inspect_runtimes(
|
|
682
|
+
args.root, node=args.node, launcher=args.launcher, runtimes=selected
|
|
683
|
+
)
|
|
684
684
|
if args.runtime:
|
|
685
685
|
value["runtimes"] = [row for row in value["runtimes"] if row["runtime"] == args.runtime]
|
|
686
686
|
elif args.harness_action == "plan":
|
|
@@ -38,6 +38,7 @@ def downloads_dir(root: Path, runtime: str) -> Path:
|
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
MODULE_DOWNLOADS = 8 # Pi's dependency tree is ~120 small tarballs; one at a time takes minutes
|
|
41
|
+
MODULE_EXTRACTS = 8 # Unpack independent verified archives in parallel into private staging dirs
|
|
41
42
|
|
|
42
43
|
|
|
43
44
|
def fetch_all(
|
|
@@ -83,7 +84,8 @@ def _fetch_modules(
|
|
|
83
84
|
nonlocal shown
|
|
84
85
|
with lock:
|
|
85
86
|
if update.get("kind") != "progress":
|
|
86
|
-
|
|
87
|
+
# ~120 modules download at once: per-module connects and reuse are noise
|
|
88
|
+
if update.get("state") not in ("reused", "connecting"):
|
|
87
89
|
event(update)
|
|
88
90
|
return
|
|
89
91
|
count = int(update["completed"])
|
|
@@ -141,6 +143,39 @@ def take(kept: Path, file: Path) -> None:
|
|
|
141
143
|
private_permissions(file, created=True)
|
|
142
144
|
|
|
143
145
|
|
|
146
|
+
def _run_extract_jobs(jobs: list[Callable[[], None]]) -> None:
|
|
147
|
+
if len(jobs) <= 1:
|
|
148
|
+
for job in jobs:
|
|
149
|
+
job()
|
|
150
|
+
return
|
|
151
|
+
pool = ThreadPoolExecutor(min(MODULE_EXTRACTS, len(jobs)))
|
|
152
|
+
try:
|
|
153
|
+
futures = [pool.submit(job) for job in jobs]
|
|
154
|
+
for future in as_completed(futures):
|
|
155
|
+
future.result()
|
|
156
|
+
finally:
|
|
157
|
+
pool.shutdown(wait=True, cancel_futures=True)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def _place_unpacked(tree: Path, unpacked: list[tuple[int, dict[str, Any], Path]]) -> None:
|
|
161
|
+
for _, artifact, unpack in unpacked:
|
|
162
|
+
if not artifact.get("destination"):
|
|
163
|
+
for entry in unpack.iterdir():
|
|
164
|
+
entry.rename(tree / entry.name)
|
|
165
|
+
modules = sorted(
|
|
166
|
+
(item for item in unpacked if item[1].get("destination")),
|
|
167
|
+
key=lambda item: (len(Path(item[1]["destination"]).parts), item[0]),
|
|
168
|
+
)
|
|
169
|
+
verified_parents: set[Path] = {tree}
|
|
170
|
+
for _, artifact, unpack in modules:
|
|
171
|
+
(top,) = unpack.iterdir() # npm drops the archive's one top directory
|
|
172
|
+
target = tree / artifact["destination"]
|
|
173
|
+
if target.parent not in verified_parents:
|
|
174
|
+
private_directory(target.parent)
|
|
175
|
+
verified_parents.add(target.parent)
|
|
176
|
+
top.rename(target)
|
|
177
|
+
|
|
178
|
+
|
|
144
179
|
def install_tree(
|
|
145
180
|
plan: dict[str, Any],
|
|
146
181
|
stage: Path,
|
|
@@ -151,33 +186,32 @@ def install_tree(
|
|
|
151
186
|
tree = stage / "t" # short: see apply_plan
|
|
152
187
|
private_directory(tree)
|
|
153
188
|
fetched = fetch_all(plan, event, download_fn=download_fn)
|
|
154
|
-
|
|
155
|
-
file = stage / f"artifact-{index}"
|
|
156
|
-
take(fetched[index], file)
|
|
189
|
+
if plan["artifacts"]:
|
|
157
190
|
event({"kind": "stage", "stage": "extract", "state": "running"})
|
|
191
|
+
unpacked: list[tuple[int, dict[str, Any], Path]] = []
|
|
192
|
+
jobs: list[Callable[[], None]] = []
|
|
193
|
+
for index, artifact in enumerate(plan["artifacts"]):
|
|
194
|
+
source = fetched[index]
|
|
158
195
|
if artifact["format"] == "binary":
|
|
159
|
-
|
|
160
|
-
(
|
|
161
|
-
|
|
196
|
+
destination = tree / artifact["executable"]
|
|
197
|
+
shutil.copyfile(source, destination)
|
|
198
|
+
destination.chmod(0o700)
|
|
199
|
+
private_permissions(destination, created=True)
|
|
162
200
|
else:
|
|
163
|
-
unpack = stage / f"
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
(top,) = unpack.iterdir() # npm drops the archive's one top directory
|
|
167
|
-
target = tree / artifact["destination"]
|
|
168
|
-
private_directory(target.parent)
|
|
169
|
-
top.rename(target)
|
|
170
|
-
else:
|
|
171
|
-
for entry in unpack.iterdir():
|
|
172
|
-
entry.rename(tree / entry.name)
|
|
201
|
+
unpack = stage / f"u{index}"
|
|
202
|
+
unpacked.append((index, artifact, unpack))
|
|
203
|
+
jobs.append(partial(extract_archive, source, unpack))
|
|
173
204
|
if plan.get("nodeArtifact"):
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
205
|
+
jobs.append(
|
|
206
|
+
partial(
|
|
207
|
+
extract_binary,
|
|
208
|
+
fetched[-2],
|
|
209
|
+
plan["nodeArtifact"]["member"],
|
|
210
|
+
tree / ("node.exe" if os.name == "nt" else "node"),
|
|
211
|
+
)
|
|
180
212
|
)
|
|
213
|
+
_run_extract_jobs(jobs)
|
|
214
|
+
_place_unpacked(tree, unpacked)
|
|
181
215
|
if plan.get("launcherArtifact"):
|
|
182
216
|
take(fetched[-1], tree / "pi.exe")
|
|
183
217
|
for item in plan["bootstrap"]:
|