@simplexai/localmodels-linux-arm64 0.1.0-dev.60 → 0.1.0-dev.61

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 (74) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +73 -60
  3. package/modules/localmodels/__init__.py +1 -1
  4. package/modules/localmodels/__main__.py +5 -3
  5. package/modules/localmodels/auth_proxy.py +185 -19
  6. package/modules/localmodels/catalog.json +363 -0
  7. package/modules/localmodels/catalog.py +1 -1
  8. package/modules/localmodels/catalog_add.py +5 -5
  9. package/modules/localmodels/catalog_license.py +2 -0
  10. package/modules/localmodels/catalog_recipes.py +2 -0
  11. package/modules/localmodels/cli_parser.py +6 -2
  12. package/modules/localmodels/context_policy.py +40 -4
  13. package/modules/localmodels/debug_mode.py +13 -0
  14. package/modules/localmodels/debug_stub_server.py +156 -1
  15. package/modules/localmodels/deploy.py +11 -2
  16. package/modules/localmodels/download-mirrors.json +12 -0
  17. package/modules/localmodels/engines-b12757-mix-ef2df21.json +26 -0
  18. package/modules/localmodels/engines-whisper-b5454.json +120 -1
  19. package/modules/localmodels/gateway_app_bifrost.py +14 -14
  20. package/modules/localmodels/gateway_bifrost.py +4 -1
  21. package/modules/localmodels/gateway_cli.py +14 -80
  22. package/modules/localmodels/gateway_server.py +88 -16
  23. package/modules/localmodels/gpu_specs.py +35 -1
  24. package/modules/localmodels/harness.py +1 -2
  25. package/modules/localmodels/hf_repo.py +12 -4
  26. package/modules/localmodels/install.py +4 -4
  27. package/modules/localmodels/library_serve.py +69 -13
  28. package/modules/localmodels/npm_transport.py +4 -58
  29. package/modules/localmodels/recommend_cli.py +2 -1
  30. package/modules/localmodels/remote_ops.py +120 -713
  31. package/modules/localmodels/remote_ops_common.py +729 -0
  32. package/modules/localmodels/remote_ops_download.py +397 -381
  33. package/modules/localmodels/remote_ops_mirrors.py +26 -65
  34. package/modules/localmodels/remote_ops_prepare.py +43 -35
  35. package/modules/localmodels/remote_ops_ranges.py +98 -62
  36. package/modules/localmodels/remote_ops_remove.py +30 -22
  37. package/modules/localmodels/remote_ops_service.py +102 -95
  38. package/modules/localmodels/remote_ops_verify.py +94 -63
  39. package/modules/localmodels/runtime_cli.py +15 -5
  40. package/modules/localmodels/runtime_io.py +54 -1
  41. package/modules/localmodels/speech-sv.txt +93 -0
  42. package/modules/localmodels/speech_admission.py +437 -0
  43. package/modules/localmodels/speech_catalog.py +170 -0
  44. package/modules/localmodels/speech_cli.py +273 -0
  45. package/modules/localmodels/speech_jobs.py +772 -0
  46. package/modules/localmodels/speech_model.py +404 -0
  47. package/modules/localmodels/speech_serve.py +287 -0
  48. package/modules/localmodels/speech_server.py +837 -0
  49. package/modules/localmodels/speech_state.py +697 -0
  50. package/modules/localmodels/speech_worker_sensevoice.py +255 -0
  51. package/modules/localmodels/speech_workers.py +783 -0
  52. package/modules/localmodels/stack.py +0 -33
  53. package/modules/localmodels/stack_auto.py +5 -3
  54. package/modules/localmodels/stack_aux_gpu.py +45 -4
  55. package/modules/localmodels/stack_capacity.py +77 -8
  56. package/modules/localmodels/stack_cli.py +16 -1
  57. package/modules/localmodels/stack_compose.py +1 -1
  58. package/modules/localmodels/stack_down.py +24 -1
  59. package/modules/localmodels/stack_hardware.py +57 -88
  60. package/modules/localmodels/stack_hardware_text.py +4 -59
  61. package/modules/localmodels/stack_memory.py +13 -3
  62. package/modules/localmodels/stack_suite.py +9 -10
  63. package/modules/localmodels/stack_summary.py +4 -4
  64. package/modules/localmodels/stack_view_llm.py +1 -1
  65. package/modules/localmodels/transport.py +3 -2
  66. package/modules/localmodels/tui_views.py +2 -2
  67. package/modules/{simplex_localmodels-0.1.0.dev60.dist-info → simplex_localmodels-0.1.0.dev61.dist-info}/METADATA +1 -1
  68. package/modules/{simplex_localmodels-0.1.0.dev60.dist-info → simplex_localmodels-0.1.0.dev61.dist-info}/RECORD +70 -57
  69. package/modules/{simplex_localmodels-0.1.0.dev60.dist-info → simplex_localmodels-0.1.0.dev61.dist-info}/licenses/NOTICE +9 -0
  70. package/package.json +1 -1
  71. package/tool.json +1 -1
  72. /package/modules/{simplex_localmodels-0.1.0.dev60.dist-info → simplex_localmodels-0.1.0.dev61.dist-info}/WHEEL +0 -0
  73. /package/modules/{simplex_localmodels-0.1.0.dev60.dist-info → simplex_localmodels-0.1.0.dev61.dist-info}/entry_points.txt +0 -0
  74. /package/modules/{simplex_localmodels-0.1.0.dev60.dist-info → simplex_localmodels-0.1.0.dev61.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -2,9 +2,8 @@
2
2
  """remote_ops ``verify`` action: readiness is a real request for the contract, never /health alone.
3
3
 
4
4
  Part of the remote_ops bundle shipped to the target as one stdin payload (transport.BUNDLES):
5
- standard library only, Python 3.8+. Shared primitives stay in the entry module and are used
6
- here as ``remote_ops.<name>``, so the bundle keeps one patchable surface and needs no
7
- private-name imports.
5
+ standard library only, Python 3.8+. Shared primitives live in ``remote_ops_common`` and are used
6
+ here via ``remote_ops_common.<name>`` so the bundle stays acyclic with no private-name accesses.
8
7
  """
9
8
 
10
9
  from __future__ import annotations
@@ -19,16 +18,21 @@ import struct
19
18
  import sys
20
19
  import time
21
20
  import urllib.error
22
- import urllib.parse
23
21
  import wave
24
22
  import zlib
25
23
  from typing import Callable, cast
26
24
 
27
25
  try:
28
- from localmodels import process_identity, remote_ops, remote_ops_launchd
26
+ from localmodels import (
27
+ process_identity,
28
+ remote_ops_common,
29
+ remote_ops_download,
30
+ remote_ops_launchd,
31
+ )
29
32
  except ImportError: # run as a bare file from this directory
30
33
  import process_identity # type: ignore[import-not-found,no-redef]
31
- import remote_ops # type: ignore[import-not-found,no-redef]
34
+ import remote_ops_common # type: ignore[import-not-found,no-redef]
35
+ import remote_ops_download # type: ignore[import-not-found,no-redef]
32
36
  import remote_ops_launchd # type: ignore[import-not-found,no-redef]
33
37
 
34
38
 
@@ -37,24 +41,26 @@ LIMIT_UNIT = " apple" # repeated to size inputs; /tokenize gives the real count
37
41
  LIMIT_MARGIN = 32 # tokens either side of the limit: room for the special tokens added
38
42
 
39
43
 
40
- def _restarts(p: remote_ops.ServiceParams) -> int:
44
+ def _restarts(p: remote_ops_common.ServiceParams) -> int:
41
45
  """systemd's restart count for the unit; it survives stop/start, so callers take deltas."""
42
- _, out = remote_ops._systemctl("show", "-p", "NRestarts", "--value", p["service"] + ".service")
46
+ _, out = remote_ops_common.systemctl(
47
+ "show", "-p", "NRestarts", "--value", p["service"] + ".service"
48
+ )
43
49
  return int(out) if out.isdigit() else 0
44
50
 
45
51
 
46
- def _health_ready(root: str, health_path: str, p: remote_ops.VerifyParams) -> bool:
47
- if remote_ops.receipts():
52
+ def _health_ready(root: str, health_path: str, p: remote_ops_common.VerifyParams) -> bool:
53
+ if remote_ops_common.receipts():
48
54
  state, pid = (
49
55
  remote_ops_launchd.status(p["deploy_dir"])
50
56
  if p["service_kind"] == "launchd-user"
51
- else process_identity.status(remote_ops._paths(p)["pid"])
57
+ else process_identity.status(remote_ops_common.paths(p)["pid"])
52
58
  )
53
59
  if state != "active" or not process_identity.listener_owned(p["port"], pid):
54
60
  return False
55
61
  return (
56
- remote_ops._http(root + health_path, p["api_key"], timeout=5).get("status", "ok")
57
- in remote_ops.READY
62
+ remote_ops_common.http_json(root + health_path, p["api_key"], timeout=5).get("status", "ok")
63
+ in remote_ops_common.READY
58
64
  )
59
65
 
60
66
 
@@ -64,15 +70,15 @@ def _evaluate_chat_answer(content: str, reasoning: str, *, smoke: bool) -> tuple
64
70
  return bool(text), text[:200], "the smoke completion was empty"
65
71
  blob = content + " " + reasoning
66
72
  return (
67
- remote_ops.TOUCH_EXPECT in blob.lower(),
73
+ remote_ops_common.TOUCH_EXPECT in blob.lower(),
68
74
  content[:200],
69
- f"the answer lacks {remote_ops.TOUCH_EXPECT!r}",
75
+ f"the answer lacks {remote_ops_common.TOUCH_EXPECT!r}",
70
76
  )
71
77
 
72
78
 
73
- def act_verify(p: remote_ops.VerifyParams) -> None:
79
+ def act_verify(p: remote_ops_common.VerifyParams) -> None:
74
80
  """Readiness is a real generation, never /health alone (Hermes' touch generation)."""
75
- paths = remote_ops._paths(p)
81
+ paths = remote_ops_common.paths(p)
76
82
  base_restarts = _restarts(p) if p["service_kind"] == "systemd-user" else 0
77
83
  root = f"http://127.0.0.1:{p['port']}"
78
84
  deadline = time.monotonic() + p.get("timeout_s", 900)
@@ -84,30 +90,33 @@ def act_verify(p: remote_ops.VerifyParams) -> None:
84
90
  except (urllib.error.URLError, OSError, ValueError):
85
91
  pass
86
92
  if p["service_kind"] == "systemd-user":
87
- _, state = remote_ops._systemctl("is-active", p["service"] + ".service")
93
+ _, state = remote_ops_common.systemctl("is-active", p["service"] + ".service")
88
94
  if state in ("failed", "inactive"):
89
95
  raise RuntimeError(
90
- f"the service exited ({state}). Log tail:\n{remote_ops._log_tail(paths)}"
96
+ f"the service exited ({state}). Log tail:\n{remote_ops_common.log_tail(paths)}"
91
97
  )
92
98
  restarts = _restarts(p) - base_restarts
93
- if restarts >= remote_ops.CRASH_RESTARTS:
99
+ if restarts >= remote_ops_common.CRASH_RESTARTS:
94
100
  # Restart=on-failure would retry forever; this service is ours to stop.
95
- remote_ops._systemctl("stop", p["service"] + ".service")
101
+ remote_ops_common.systemctl("stop", p["service"] + ".service")
96
102
  raise RuntimeError(
97
103
  f"the service kept exiting after start ({restarts} restarts this time) and was stopped. "
98
- f"Log tail:\n{remote_ops._log_tail(paths)}"
104
+ f"Log tail:\n{remote_ops_common.log_tail(paths)}"
99
105
  )
100
106
  elif (
101
107
  remote_ops_launchd.status(p["deploy_dir"])[0] != "active"
102
108
  if p["service_kind"] == "launchd-user"
103
- else remote_ops._pid_alive(paths["pid"]) is None
109
+ else remote_ops_common.pid_alive(paths["pid"]) is None
104
110
  ):
105
- raise RuntimeError("the process exited. Log tail:\n" + remote_ops._log_tail(paths))
111
+ raise RuntimeError(
112
+ "the process exited. Log tail:\n" + remote_ops_common.log_tail(paths)
113
+ )
106
114
  if time.monotonic() > deadline:
107
115
  raise RuntimeError(
108
- "timed out waiting for the model to load. Log tail:\n" + remote_ops._log_tail(paths)
116
+ "timed out waiting for the model to load. Log tail:\n"
117
+ + remote_ops_common.log_tail(paths)
109
118
  )
110
- remote_ops.emit("progress", phase="loading")
119
+ remote_ops_common.emit("progress", phase="loading")
111
120
  time.sleep(3)
112
121
  contract = p.get("contract")
113
122
  if contract in CONTRACTS:
@@ -115,7 +124,7 @@ def act_verify(p: remote_ops.VerifyParams) -> None:
115
124
  return
116
125
  started = time.monotonic()
117
126
  smoke = bool(p.get("smoke"))
118
- prompt = "Reply with OK." if smoke else remote_ops.TOUCH_PROMPT
127
+ prompt = "Reply with OK." if smoke else remote_ops_common.TOUCH_PROMPT
119
128
  messages = [{"role": "user", "content": prompt}]
120
129
  body = {
121
130
  "model": p["model_alias"],
@@ -123,7 +132,9 @@ def act_verify(p: remote_ops.VerifyParams) -> None:
123
132
  "max_tokens": 16 if smoke else 512,
124
133
  "temperature": 0,
125
134
  }
126
- resp = remote_ops._http(root + "/v1/chat/completions", p["api_key"], body, timeout=300)
135
+ resp = remote_ops_common.http_json(
136
+ root + "/v1/chat/completions", p["api_key"], body, timeout=300
137
+ )
127
138
  choices = resp.get("choices")
128
139
  if not isinstance(choices, list) or not choices or not isinstance(choices[0], dict):
129
140
  raise ValueError("missing completion choices")
@@ -146,7 +157,7 @@ def act_verify(p: remote_ops.VerifyParams) -> None:
146
157
  _report(ok, answer, started, failure, timings=resp.get("timings"), **extra, **_released(ok, p))
147
158
 
148
159
 
149
- def _released(ok: bool, p: remote_ops.VerifyParams) -> dict[str, int]:
160
+ def _released(ok: bool, p: remote_ops_common.VerifyParams) -> dict[str, int]:
150
161
  """Windows keeps the pages a model was read through in the server's working set after the
151
162
  weights are in VRAM, until memory runs short: 4.9 GiB for a 4.1 GiB model. Given back once
152
163
  the server has answered, they left 4.5 GB more available in 0.4 s and the next request was
@@ -154,23 +165,23 @@ def _released(ok: bool, p: remote_ops.VerifyParams) -> dict[str, int]:
154
165
  for a model with weights in host memory, a failed check, or another system."""
155
166
  if not ok or not p.get("weights_on_gpu") or sys.platform != "win32":
156
167
  return {}
157
- state, pid = process_identity.status(remote_ops._paths(p)["pid"])
168
+ state, pid = process_identity.status(remote_ops_common.paths(p)["pid"])
158
169
  freed = process_identity.release_working_set(pid) if state == "active" and pid else 0
159
170
  return {"released_bytes": freed}
160
171
 
161
172
 
162
- def _served(root: str, p: remote_ops.VerifyParams) -> tuple[object, object]:
173
+ def _served(root: str, p: remote_ops_common.VerifyParams) -> tuple[object, object]:
163
174
  """llama-server's build and per-slot window from /props; (None, None) when it does not say."""
164
175
  props = {}
165
176
  try:
166
- props = remote_ops._http(root + "/props", p["api_key"], timeout=5)
177
+ props = remote_ops_common.http_json(root + "/props", p["api_key"], timeout=5)
167
178
  except (urllib.error.URLError, OSError, ValueError):
168
179
  pass
169
180
  dgs = props.get("default_generation_settings")
170
181
  return props.get("build_info"), dgs.get("n_ctx") if isinstance(dgs, dict) else None
171
182
 
172
183
 
173
- def _short_window(p: remote_ops.VerifyParams, n_ctx: object) -> str:
184
+ def _short_window(p: remote_ops_common.VerifyParams, n_ctx: object) -> str:
174
185
  """Why the served window falls short of the planned one, "" when it does not or is unknown.
175
186
  llama-server pads -c up to a multiple of 256 (200000 serves 200192), so at least the plan."""
176
187
  window = p.get("window")
@@ -198,7 +209,7 @@ def _solid_png(rgb: tuple[int, int, int], side: int = 224) -> bytes:
198
209
  )
199
210
 
200
211
 
201
- def _picture_answer(root: str, p: remote_ops.VerifyParams) -> str:
212
+ def _picture_answer(root: str, p: remote_ops_common.VerifyParams) -> str:
202
213
  """The model's answer, with its reasoning, about a synthetic red picture (decision 31)."""
203
214
  image = "data:image/png;base64," + base64.b64encode(_solid_png((220, 20, 20))).decode()
204
215
  parts = [
@@ -211,7 +222,9 @@ def _picture_answer(root: str, p: remote_ops.VerifyParams) -> str:
211
222
  "max_tokens": 512,
212
223
  "temperature": 0,
213
224
  }
214
- resp = remote_ops._http(root + "/v1/chat/completions", p["api_key"], body, timeout=300)
225
+ resp = remote_ops_common.http_json(
226
+ root + "/v1/chat/completions", p["api_key"], body, timeout=300
227
+ )
215
228
  choices = resp.get("choices")
216
229
  if not isinstance(choices, list) or not choices or not isinstance(choices[0], dict):
217
230
  raise ValueError("missing picture completion choices")
@@ -224,12 +237,16 @@ def _picture_answer(root: str, p: remote_ops.VerifyParams) -> str:
224
237
  return content + " " + reasoning
225
238
 
226
239
 
227
- def _verify_decision(root: str, p: remote_ops.VerifyParams) -> None:
240
+ def _verify_decision(root: str, p: remote_ops_common.VerifyParams) -> None:
228
241
  """Readiness of a System One model is a probability for an unambiguous question."""
229
242
  started = time.monotonic()
230
- body = {"model": p["model_alias"], "state": remote_ops.DECISION_STATE, "questions": {}}
231
- body["questions"] = {"outage": remote_ops.DECISION_QUESTION}
232
- resp = remote_ops._http(root + "/v1/systemone", p["api_key"], body, timeout=300)
243
+ body = {
244
+ "model": p["model_alias"],
245
+ "state": remote_ops_common.DECISION_STATE,
246
+ "questions": {},
247
+ }
248
+ body["questions"] = {"outage": remote_ops_common.DECISION_QUESTION}
249
+ resp = remote_ops_common.http_json(root + "/v1/systemone", p["api_key"], body, timeout=300)
233
250
  answers = resp.get("answers")
234
251
  answer = answers.get("outage") if isinstance(answers, dict) else None
235
252
  noul = answer.get("noul") if isinstance(answer, dict) else None
@@ -253,18 +270,20 @@ def _finite(values: object) -> list[float]:
253
270
 
254
271
 
255
272
  def _report(ok: bool, answer: str, started: float, failure: str, **extra: object) -> None:
256
- remote_ops.emit(
273
+ remote_ops_common.emit(
257
274
  "result", ready=ok, answer=answer, seconds=round(time.monotonic() - started, 2), **extra
258
275
  )
259
276
  if not ok:
260
277
  raise RuntimeError("readiness check failed: " + failure)
261
278
 
262
279
 
263
- def _sized(root: str, p: remote_ops.VerifyParams, tokens: int) -> tuple[str, int]:
280
+ def _sized(root: str, p: remote_ops_common.VerifyParams, tokens: int) -> tuple[str, int]:
264
281
  """Text of about ``tokens`` tokens and its count, both from the server's own tokenizer."""
265
282
 
266
283
  def count(text: str) -> int:
267
- found = remote_ops._http(root + "/tokenize", p["api_key"], {"content": text}, timeout=60)
284
+ found = remote_ops_common.http_json(
285
+ root + "/tokenize", p["api_key"], {"content": text}, timeout=60
286
+ )
268
287
  if not isinstance(found.get("tokens"), list):
269
288
  raise ValueError("invalid /tokenize response")
270
289
  return len(cast("list[object]", found["tokens"]))
@@ -273,7 +292,9 @@ def _sized(root: str, p: remote_ops.VerifyParams, tokens: int) -> tuple[str, int
273
292
  return text, count(text)
274
293
 
275
294
 
276
- def _input_limit(root: str, p: remote_ops.VerifyParams, send: Callable[[str], object]) -> str:
295
+ def _input_limit(
296
+ root: str, p: remote_ops_common.VerifyParams, send: Callable[[str], object]
297
+ ) -> str:
277
298
  """The declared token limit holds: an input just under it is served; one just over it
278
299
  refuses the whole request with an HTTP error instead of being truncated, and the service
279
300
  keeps answering."""
@@ -301,12 +322,18 @@ def _input_limit(root: str, p: remote_ops.VerifyParams, send: Callable[[str], ob
301
322
  return f" limit={limit}: {served} served, {refused} refused"
302
323
 
303
324
 
304
- def _verify_embedding(root: str, p: remote_ops.VerifyParams) -> None:
325
+ def _verify_embedding(root: str, p: remote_ops_common.VerifyParams) -> None:
305
326
  """Finite unit vectors of one width; a paraphrase lands nearer than an unrelated sentence."""
306
327
  started = time.monotonic()
307
- texts = [remote_ops.EMBED_QUERY, remote_ops.EMBED_NEAR, remote_ops.EMBED_FAR]
328
+ texts = [
329
+ remote_ops_common.EMBED_QUERY,
330
+ remote_ops_common.EMBED_NEAR,
331
+ remote_ops_common.EMBED_FAR,
332
+ ]
308
333
  body = {"model": p["model_alias"], "input": texts}
309
- data = remote_ops._http(root + "/v1/embeddings", p["api_key"], body, timeout=120).get("data")
334
+ data = remote_ops_common.http_json(
335
+ root + "/v1/embeddings", p["api_key"], body, timeout=120
336
+ ).get("data")
310
337
  if (
311
338
  not isinstance(data, list)
312
339
  or len(data) != len(texts)
@@ -332,24 +359,26 @@ def _verify_embedding(root: str, p: remote_ops.VerifyParams) -> None:
332
359
  answer += _input_limit(
333
360
  root,
334
361
  p,
335
- lambda text: remote_ops._http(
362
+ lambda text: remote_ops_common.http_json(
336
363
  root + "/v1/embeddings", p["api_key"], {**body, "input": [text]}, timeout=300
337
364
  ),
338
365
  )
339
366
  _report(all(abs(n - 1) < 1e-2 for n in norms) and near > far, answer, started, answer)
340
367
 
341
368
 
342
- def _verify_rerank(root: str, p: remote_ops.VerifyParams) -> None:
369
+ def _verify_rerank(root: str, p: remote_ops_common.VerifyParams) -> None:
343
370
  """The known relevant document, not placed first, must rank first. llama-server returns the
344
371
  results sorted by score and cut to ``top_n``, so ask for every document."""
345
- started, docs = time.monotonic(), remote_ops.RERANK_DOCS
372
+ started, docs = time.monotonic(), remote_ops_common.RERANK_DOCS
346
373
  body = {
347
374
  "model": p["model_alias"],
348
- "query": remote_ops.RERANK_QUERY,
375
+ "query": remote_ops_common.RERANK_QUERY,
349
376
  "documents": docs,
350
377
  "top_n": len(docs),
351
378
  }
352
- results = remote_ops._http(root + "/v1/rerank", p["api_key"], body, timeout=120).get("results")
379
+ results = remote_ops_common.http_json(root + "/v1/rerank", p["api_key"], body, timeout=120).get(
380
+ "results"
381
+ )
353
382
  if not isinstance(results, list) or not all(isinstance(r, dict) for r in results):
354
383
  raise ValueError("invalid rerank results")
355
384
  scored: list[tuple[float, int]] = []
@@ -358,7 +387,7 @@ def _verify_rerank(root: str, p: remote_ops.VerifyParams) -> None:
358
387
  if type(index) is not int:
359
388
  raise ValueError("invalid rerank index")
360
389
  scored.append((_finite([result.get("relevance_score")])[0], index))
361
- if sorted(i for _, i in scored) != list(range(len(remote_ops.RERANK_DOCS))):
390
+ if sorted(i for _, i in scored) != list(range(len(remote_ops_common.RERANK_DOCS))):
362
391
  raise ValueError("rerank indices do not cover every document")
363
392
  if any(scored[i][0] < scored[i + 1][0] for i in range(len(scored) - 1)):
364
393
  raise ValueError("rerank results are not sorted by descending score")
@@ -368,7 +397,7 @@ def _verify_rerank(root: str, p: remote_ops.VerifyParams) -> None:
368
397
  limit = _input_limit(
369
398
  root,
370
399
  p,
371
- lambda text: remote_ops._http(
400
+ lambda text: remote_ops_common.http_json(
372
401
  root + "/v1/rerank",
373
402
  p["api_key"],
374
403
  {**body, "documents": [text], "top_n": 1},
@@ -376,18 +405,20 @@ def _verify_rerank(root: str, p: remote_ops.VerifyParams) -> None:
376
405
  ),
377
406
  )
378
407
  _report(
379
- best == remote_ops.RERANK_RELEVANT,
408
+ best == remote_ops_common.RERANK_RELEVANT,
380
409
  f"top={best}{limit}",
381
410
  started,
382
411
  f"document {best} ranked first",
383
412
  )
384
413
 
385
414
 
386
- def _verify_stt(root: str, p: remote_ops.VerifyParams) -> None:
415
+ def verify_stt(root: str, p: remote_ops_common.VerifyParams) -> None:
387
416
  """A pinned recording transcribes to text containing its known phrase."""
388
417
  fx = p.get("fixture") or {}
389
- dest = os.path.join(remote_ops._expand(p["deploy_dir"]), str(fx["name"]))
390
- remote_ops.fetch(str(fx["url"]), dest, str(fx["sha256"]), int(str(fx["size_bytes"])), dest)
418
+ dest = os.path.join(remote_ops_common.expand(p["deploy_dir"]), str(fx["name"]))
419
+ remote_ops_download.fetch(
420
+ str(fx["url"]), dest, str(fx["sha256"]), int(str(fx["size_bytes"])), dest
421
+ )
391
422
  with open(dest, "rb") as f:
392
423
  audio = f.read()
393
424
  mark = "--localmodels" + hashlib.sha256(audio).hexdigest()[:16]
@@ -397,7 +428,7 @@ def _verify_stt(root: str, p: remote_ops.VerifyParams) -> None:
397
428
  body += f"\r\n{mark}--\r\n".encode()
398
429
  kind, started = "multipart/form-data; boundary=" + mark[2:], time.monotonic()
399
430
  resp = json.loads(
400
- remote_ops._request(root + str(fx["path"]), p["api_key"], body, kind, 300) or b"{}"
431
+ remote_ops_common.request(root + str(fx["path"]), p["api_key"], body, kind, 300) or b"{}"
401
432
  )
402
433
  text = resp.get("text") if isinstance(resp, dict) else None
403
434
  if not isinstance(text, str):
@@ -407,15 +438,15 @@ def _verify_stt(root: str, p: remote_ops.VerifyParams) -> None:
407
438
  _report(ok, text.strip()[:120], started, f"the transcript lacks {expect!r}")
408
439
 
409
440
 
410
- def _verify_tts(root: str, p: remote_ops.VerifyParams) -> None:
441
+ def _verify_tts(root: str, p: remote_ops_common.VerifyParams) -> None:
411
442
  """Each fixture sentence (Chinese and English: both G2P paths) comes back as audible 16-bit
412
443
  mono WAV of a sentence's length. Whether it says the words is a round trip through STT."""
413
444
  started, heard = time.monotonic(), []
414
445
  samples = cast("list[dict[str, str]]", (p.get("fixture") or {}).get("samples") or [])
415
446
  for s in samples:
416
447
  body = json.dumps({"model": p["model_alias"], "voice": s["voice"], "input": s["input"]})
417
- audio = remote_ops._request(
418
- root + "/v1/audio/speech", p["api_key"], body.encode(), remote_ops.JSON, 300
448
+ audio = remote_ops_common.request(
449
+ root + "/v1/audio/speech", p["api_key"], body.encode(), remote_ops_common.JSON, 300
419
450
  )
420
451
  with wave.open(io.BytesIO(audio)) as w:
421
452
  mono16, frames = (w.getnchannels(), w.getsampwidth()) == (1, 2), w.getnframes()
@@ -434,11 +465,11 @@ def _verify_tts(root: str, p: remote_ops.VerifyParams) -> None:
434
465
 
435
466
  CONTRACTS = {
436
467
  "systemone": _verify_decision,
437
- "health": lambda root, p: remote_ops.emit(
468
+ "health": lambda root, p: remote_ops_common.emit(
438
469
  "result", ready=True
439
470
  ), # behind a front that checks it
440
471
  "embedding": _verify_embedding,
441
472
  "rerank": _verify_rerank,
442
- "stt": _verify_stt,
473
+ "stt": verify_stt,
443
474
  "tts": _verify_tts,
444
475
  }
@@ -47,18 +47,25 @@ RUNTIMES = ("codex", "claude", "pi")
47
47
  LOCK = Path(__file__).with_name("runtime-lock.json")
48
48
  PROFILE_KEYS = {"codex": "CODEX_HOME", "claude": "CLAUDE_CONFIG_DIR", "pi": "PI_CODING_AGENT_DIR"}
49
49
  PROFILE_DIRS = {"codex": ".codex", "claude": ".claude", "pi": ".pi/agent"}
50
- _platform = runtime_discovery.platform_tag
50
+ platform = runtime_discovery.platform_tag
51
+ _platform = platform
51
52
 
52
53
 
53
- def _owned_profile(directory: Path) -> bool:
54
+ def owned_profile(directory: Path) -> bool:
54
55
  files = owned_files(directory) if _private_file(directory / "localmodels-auth.json") else {}
55
56
  return bool(files) and all(_private_file(directory / name) for name in files)
56
57
 
57
58
 
58
- def _active_profile(runtime: str, env: dict[str, str]) -> Path:
59
+ _owned_profile = owned_profile
60
+
61
+
62
+ def active_profile(runtime: str, env: dict[str, str]) -> Path:
59
63
  return Path(env.get(PROFILE_KEYS[runtime], str(Path.home() / PROFILE_DIRS[runtime])))
60
64
 
61
65
 
66
+ _active_profile = active_profile
67
+
68
+
62
69
  def _probe(
63
70
  argv: list[str], env: dict[str, str] | None = None, *, timeout: float = 5
64
71
  ) -> tuple[int, str]:
@@ -139,15 +146,18 @@ def _managed_command(root: Path, runtime: str, node: str | None = None) -> list[
139
146
  return [str(target / artifacts[0]["executable"])] if artifacts else []
140
147
 
141
148
 
142
- def _runtime_env(root: Path, runtime: str) -> dict[str, str]:
149
+ def runtime_env(root: Path, runtime: str) -> dict[str, str]:
143
150
  env = dict(os.environ)
144
151
  directory = root / "runtime" / runtime
145
152
  validate_runtime_root(directory)
146
- if _owned_profile(directory):
153
+ if owned_profile(directory):
147
154
  env[PROFILE_KEYS[runtime]] = str(directory)
148
155
  return env
149
156
 
150
157
 
158
+ _runtime_env = runtime_env
159
+
160
+
151
161
  def _credential_ambiguous(
152
162
  runtime: str, profile: Path, owned: dict[str, str], env: dict[str, str]
153
163
  ) -> bool:
@@ -21,7 +21,7 @@ import urllib.parse
21
21
  import urllib.request
22
22
  import zipfile
23
23
  from collections import deque
24
- from collections.abc import Callable
24
+ from collections.abc import Callable, Mapping
25
25
  from pathlib import Path
26
26
  from typing import Any, cast
27
27
 
@@ -654,6 +654,59 @@ def cached_download(
654
654
  return kept
655
655
 
656
656
 
657
+ def _archive_pin(build: Mapping[str, Any]) -> tuple[str, int]:
658
+ """The npm tarball's SHA256 and size, which every Bifrost build of the tool lock carries."""
659
+ pin = build["npm"]
660
+ digest, size = pin.get("sha256"), pin.get("bytes")
661
+ if (
662
+ not isinstance(digest, str)
663
+ or not re.fullmatch("[0-9a-f]{64}", digest)
664
+ or type(size) is not int
665
+ or not 0 < size <= npm_transport.archive_size_cap(build["size_bytes"])
666
+ ):
667
+ raise ValueError(
668
+ "Bifrost npm archive pin is missing or invalid (the tool lock needs npm sha256 and"
669
+ " bytes)"
670
+ )
671
+ return digest, size
672
+
673
+
674
+ def _sha256(path: Path) -> str:
675
+ digest = hashlib.sha256()
676
+ with path.open("rb") as stream:
677
+ for chunk in iter(lambda: stream.read(1 << 20), b""):
678
+ digest.update(chunk)
679
+ return digest.hexdigest()
680
+
681
+
682
+ def fetch_bifrost(
683
+ build: Mapping[str, Any],
684
+ destination: Path,
685
+ archive: Path,
686
+ event: Event,
687
+ ) -> None:
688
+ """Put the pinned Bifrost binary of ``build`` at ``destination``. The npm tarball downloads
689
+ to ``archive``, which must outlive this call: an interrupted download keeps
690
+ ``archive.part`` for the next call to resume (``download``, which also moves between the npm
691
+ registry and its mirror), and a complete tarball left by a crash before extraction is reused
692
+ when it matches the pin. The tarball is deleted once extracted."""
693
+ digest, size = _archive_pin(build)
694
+ if archive.exists() or archive.is_symlink():
695
+ if archive.is_file() and not archive.is_symlink() and _sha256(archive) == digest:
696
+ event({"kind": "stage", "stage": "download", "state": "reused"})
697
+ else:
698
+ archive.unlink()
699
+ if not archive.exists():
700
+ pin = build["npm"]
701
+ url = npm_transport.check_url(
702
+ npm_transport.package_url(pin["package"], pin["version"], "global", os.environ)
703
+ )
704
+ artifact = {"url": url, "algorithm": "sha256", "digest": digest, "maxBytes": size}
705
+ download(artifact, archive, event)
706
+ npm_transport.extract_bifrost(archive, destination, build["sha256"], build["size_bytes"])
707
+ archive.unlink()
708
+
709
+
657
710
  def error_cause(error: BaseException) -> str:
658
711
  """What went wrong, without native tool output or anything read from the network."""
659
712
  if isinstance(error, RuntimeDownloadError):
@@ -0,0 +1,93 @@
1
+ # sherpa-onnx 2.0.3 (k2-fsa/sherpa-onnx, Apache-2.0) CPU runtime for SenseVoice Small INT8
2
+ # (localmodels/speech_worker_sensevoice.py). Installed by localmodels/frontend.py into
3
+ # <base_dir>/frontends/speech-sv with --require-hashes --no-deps and CN PyPI mirror support.
4
+ # Regenerate with:
5
+ # uv pip compile --universal --python-version 3.10 --generate-hashes --no-header --no-annotate - <<< "sherpa-onnx==2.0.3"
6
+ sherpa-onnx==2.0.3 \
7
+ --hash=sha256:08c30ae72bad082b80efed73e325901aebeae881f9dcd486b5760878243f0e67 \
8
+ --hash=sha256:08d75133ba566ced86f666a6897ddcd0fc0d3dec306af03002637ae6a6a07499 \
9
+ --hash=sha256:0da110fefa9c29ce7c63bf8c70f1e5ab8fcef33d11f424eda92fef6898b11965 \
10
+ --hash=sha256:108539bc25cb1dce1cb4699b6ba47a97529f8d409ddca51ffb2aeace7b9796ce \
11
+ --hash=sha256:21113bf688e6ee539486bcf6c99d321ee88423cd3197b2e28820673faf25b5e1 \
12
+ --hash=sha256:23ee57087a398f761662983fb81a8adc00777714303983165d398c08f54a0fb0 \
13
+ --hash=sha256:261f1dd26199a41043938d1c8abe0817d33b2d77a7ca80617ce553c2aa0b5e81 \
14
+ --hash=sha256:288ef3e8c3693ab6e5a01793ca58fbd67a175a8131ec1a8032ef8aafb49f48b6 \
15
+ --hash=sha256:2cd31b9dd8d5bed1629905c15fbf16b9bba56e77a13eb9229674382afe324b93 \
16
+ --hash=sha256:2d04f1d1f70f87442305ba8ec3fb932eec572bd5105764e62939240c8639e289 \
17
+ --hash=sha256:314cbab4604d9f0ffcba701ce358acc78bc6dda02017faec195864b5b7828d84 \
18
+ --hash=sha256:31c64c724a12185309f5817b47b6a8b061d85e2b1d2ea2a10c01ce4e5b1a7af1 \
19
+ --hash=sha256:34de1389734e768d688505426f2cb585aeed6861af42a6eff2b4acdf4379316c \
20
+ --hash=sha256:385b8dc1390e424067d2d5eb5af365a52c30533cc39ee5023963ac6e5d2a1209 \
21
+ --hash=sha256:399b0e926a536081b96e7223597a9390abd69d3324179e00847e0fe2dc58a393 \
22
+ --hash=sha256:3bb7862b9e02c78deda2d201d56e1dacc203a1519d4b800782a471e1f0a9a18e \
23
+ --hash=sha256:3c71f5a25ab0383a86285c4d22af15fec95a963b5463d521066ac4b77f4dde3a \
24
+ --hash=sha256:3e5a64af244b192be833f4fc5c625c46bf6a2471d4ac2db82c8e30e87c99e1bd \
25
+ --hash=sha256:3f4dcc5a5935ab3b6e8e101a153980fa7d364a3f42c2a8a75e304b61880461b2 \
26
+ --hash=sha256:449cc737d771de3b930d54219bb9c33462f7874e4cbb183fcd3de0951a625f52 \
27
+ --hash=sha256:44d122a11529029e5ad72865a1366839c45c89c0631f0b0cbd0ee46a72512d70 \
28
+ --hash=sha256:472329ad2f8ca5e2d0e517cba279d61c86c23729060920abe6a5816fb6e50fab \
29
+ --hash=sha256:482e7f6a381b29c9b913724c8bff18def333949b8abd195764c7d7c68f44246a \
30
+ --hash=sha256:4b4812a7c11810065d68f8bc010248a147bdcafe6f0bfbc121b12697d856c165 \
31
+ --hash=sha256:4c74144cd396571196f19df08808d7e4cd70f77f088ba97b39cf1499311260ac \
32
+ --hash=sha256:4d2992af6eb2b546e90e966aba775fbe345bbf16bca061feb17f5f4e2cdd6bdb \
33
+ --hash=sha256:5097d113f23f76355e5517bddfb3a3fe398aba10a6eb4d9a492f0945214b2177 \
34
+ --hash=sha256:511d155a1442936eaf9daf2d0b00e89022510502fec7f495a3c5f6c4fb4e4014 \
35
+ --hash=sha256:52dda49a5772caaa7b43ef458832c3a863992a34790409ebe4ec435d2a08a226 \
36
+ --hash=sha256:534fc5bea0d9cb58146f581ad6c4cdb9ddf7d95b90f166edb06690512c83e25d \
37
+ --hash=sha256:5604055ec3f796f5f82641a28433733a00b05c209e1fdff2fda251852d093c42 \
38
+ --hash=sha256:561045f63d5c085029d5cfbd8b3eb1e039e0cd6dec4dddb17e319441835297cf \
39
+ --hash=sha256:56112cc366c21564158b33edceebd2e5ae5274a2afbc2f027a07129e8af6c305 \
40
+ --hash=sha256:5bab511b7d86244666aa336295d5b628055cee9a874ec54a353d58584ae1f910 \
41
+ --hash=sha256:5d8794b2ce86b5bc76f7e8a09ed13c174be5241b5f0428de76843c2739799b40 \
42
+ --hash=sha256:6030090e3a4d0b59acbbb827588c4f7127a02930801ca14df952ba31e230390e \
43
+ --hash=sha256:64e049c6fff00af3211be1f4babcfc2e769320f60791b83767fbbef8f7dc5f05 \
44
+ --hash=sha256:7e2a534057b52ba9a3c7f6c533375b58965e9e4c59c028573190e73d3df2952b \
45
+ --hash=sha256:88d399213a485f330a63a0551c296e0410980e0af51fad5264478b2e09ca28ae \
46
+ --hash=sha256:8fd88f9758ff544095a0eed8a991acbf8ae97b696afcd4de453d1db810c4c733 \
47
+ --hash=sha256:931b130db8cc6d1a8075588b55f2e0157cf293851c4251ffb6577e6f9a7fe87a \
48
+ --hash=sha256:99e2995be63751d86f9b79134dc02a3c787e1c4b8b1e3fe2ec6816caac985ef5 \
49
+ --hash=sha256:9d438f8fdc1fa0d3563577308135e8941569ff258f5dd941dc14e76af573ecc6 \
50
+ --hash=sha256:9d60e200ff971eae8b54f993de56067d9847a22bdf6a2d84597a29cfc67d571f \
51
+ --hash=sha256:a29ea5b3df4b28d8faf5445ee09be7eda2977235f7fe96add84106862493c75f \
52
+ --hash=sha256:a91aba083eba69b612c2b2fe3c74532958183d4decd3330bea2d567247d6b01c \
53
+ --hash=sha256:b6996fba6cc47b599ca0a43ddd7eff6476136c252f8eafe29e179e30cbd839df \
54
+ --hash=sha256:b7a18a957f1218db588e10335ca6ba310dc5724a2bfa9a22749f73a5f2113d66 \
55
+ --hash=sha256:be43b1a4801c4d8930e0af56d1e4c13781520f1c7b5866541c73f2efbdc2b313 \
56
+ --hash=sha256:bedc3fe6922f922453ae7389c3aa17997d571890d33e3112f80909cc80be892e \
57
+ --hash=sha256:bf9d33a3b6c648beeffe57fdba7ed3f0837eb96b64fa38201d47c963f7a6a5a7 \
58
+ --hash=sha256:c12c6b80501bc83c8a429fb2594f7e09d25c5e30c296258c54edb9306183b006 \
59
+ --hash=sha256:c6cdfce22f61090fa756c0ff21aa58df3ba556bbd6078efb08b665768f19caa4 \
60
+ --hash=sha256:c70c85b448593a26f7e98833bcb0332827fb72df9249c6aae768a1a239452387 \
61
+ --hash=sha256:c97638b24480fcc4d5c451606e5241a3133440614845e522d0b23a4f287892f9 \
62
+ --hash=sha256:ca2d06672d77f84955e1da51ccc76928a851e91bdf7bc3b6cba589302e4fd461 \
63
+ --hash=sha256:ca46747ce4c2ce65b7f1e5ac54004086ad2ca34d51e71eb0f062b46ca815da5e \
64
+ --hash=sha256:d659dd277c59318a40fa63e5429ae99be6671d210f6e20d381cb02046f1cfa58 \
65
+ --hash=sha256:ddbb9f6644f44756a54abf00c8e8631d962793f5b539051fc44f0d477b188e33 \
66
+ --hash=sha256:de9da572400be452acfbdecdb35eb760d56b1283285dd8693009cc54c7d645aa \
67
+ --hash=sha256:df5b341c9ac86ae1a56750c6149b3865f09e6dc1d2f0241ddc334bcffea256c6 \
68
+ --hash=sha256:e2c65b89e971ee21300cbb559aee1b4c0414b13cbcabb2bce0d83cac42d35bf5 \
69
+ --hash=sha256:e41466de65b2bded07f40963cdb53f96010fe04c307b27a4f9c4e538c4666326 \
70
+ --hash=sha256:e45a7d3b1e664b8ef684f86d85ef36e33bda75f3649428151d6fb896a75117d7 \
71
+ --hash=sha256:e94bdc0fdb901fa22b8ae277fd8ce2caecb8ce1164c2acd6e4465e9bdc484fb1 \
72
+ --hash=sha256:ebf5763f1c1a5a9fcb32f27e97978ca34d1e3666a73a4eae6d2ded1f5e06c480 \
73
+ --hash=sha256:ed20a772c6a2dc83de6099e7a5c5d5b8d3c21a5b67ec2175db0581c9685f6c5c \
74
+ --hash=sha256:ed572e9d2a25d1e2e27439e59e96eb24ee9c310ba8e93cd64f7001725da18d41 \
75
+ --hash=sha256:f0e84872b49ad8c8b6d85ccc38e0f6e8f2fcc1a204f7c6def1879c7da9018a1a \
76
+ --hash=sha256:f1f93ed6e3ec709ee0c60074de0bbd39c04ffd638c87687e801514f9ae83abc0 \
77
+ --hash=sha256:f6b9e3ae7cef3f8672a169bf4cf7a9f3f7d5d98f8961beceb694a066e3036532 \
78
+ --hash=sha256:f8f2accab6d2b350fefe62d474541bdd804b88345d22eae773e0b54b6e55e348 \
79
+ --hash=sha256:faff2dde113874c985654ebf8ac7f2542dc697a4591c26804c23a6eaabb9dc45 \
80
+ --hash=sha256:fd9ae354b544781399efb3302d5a822627b8be3971ea7671198af490dbb38408
81
+ sherpa-onnx-core==2.0.3 \
82
+ --hash=sha256:03efdd29b733c11dadb4764f009e6aecc78a865bdeae16ab2d1d7ecc3e54272f \
83
+ --hash=sha256:14f4a6674256d44fcb5c937ede7eb5c18a07eb6f75fd9169fafbea606e923e24 \
84
+ --hash=sha256:1694a672ffafcc21912e0cdfad0d9068e11e48738fe0b0528b18061ae6e5ffdf \
85
+ --hash=sha256:3c4e54ed9ac03ef8cc9b7340dc18a1203017bdd0e4ecc9923562560006d881e0 \
86
+ --hash=sha256:6a86b5dc271aca8aa69e8311cb6f1c0726cb6c0f94f1547b14e3eb9f9375c9fb \
87
+ --hash=sha256:6db4c9e70d49ba38f4cd54c121a05bb63b6085b42867216086144e445ac603c1 \
88
+ --hash=sha256:798ba3803b6461bac9eca5a7f3927f04e7a54173155e3f0479e6abd89bb4bc59 \
89
+ --hash=sha256:8553cca5084ea0c37951ce9a3667e7f8bfa873935c915b6c5c9d90f85a219953 \
90
+ --hash=sha256:867f910966e7eb22b6e7a52227b469eb6acd9a98536562655e4bc404cf017c9c \
91
+ --hash=sha256:90181ad82b519995d6ca846f9cafa71648f2ae9d3f5528579ddc401f16cbe75d \
92
+ --hash=sha256:ca19ab0ae8c78b9a0a987ebd1aa69b73e3b7490733646e831db46260dab85316 \
93
+ --hash=sha256:f1d5b68e26e8998c9f3055a4a21beaa7a78e70ec7fa1c01cf66cb6b5c33b1501