@simplexai/localmodels-darwin-x64 0.1.0-dev.59 → 0.1.0-dev.60

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 (87) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +79 -73
  3. package/modules/localmodels/__init__.py +1 -1
  4. package/modules/localmodels/__main__.py +104 -43
  5. package/modules/localmodels/apple_sensors.py +431 -0
  6. package/modules/localmodels/bifrost_admin.py +30 -0
  7. package/modules/localmodels/bifrost_checks.py +2 -2
  8. package/modules/localmodels/bifrost_config.py +132 -9
  9. package/modules/localmodels/bifrost_models.py +1 -1
  10. package/modules/localmodels/catalog.json +146 -54
  11. package/modules/localmodels/catalog.py +20 -3
  12. package/modules/localmodels/catalog_add.py +42 -11
  13. package/modules/localmodels/custom_hub.py +983 -0
  14. package/modules/localmodels/custom_hub_http.py +579 -0
  15. package/modules/localmodels/custom_probe.py +451 -0
  16. package/modules/localmodels/deploy.py +27 -5
  17. package/modules/localmodels/deploy_steps.py +5 -0
  18. package/modules/localmodels/download-mirrors.json +8 -0
  19. package/modules/localmodels/engines-prism-b12178-03ec600.json +131 -0
  20. package/modules/localmodels/engines-strata-poly-0.2.20-poly.6.json +94 -0
  21. package/modules/localmodels/engines.py +38 -8
  22. package/modules/localmodels/estimator.py +60 -7
  23. package/modules/localmodels/gateway.py +48 -3
  24. package/modules/localmodels/gateway_app_bifrost.py +4 -4
  25. package/modules/localmodels/gateway_bifrost.py +98 -15
  26. package/modules/localmodels/gguf.py +6 -0
  27. package/modules/localmodels/host_sensors.py +704 -0
  28. package/modules/localmodels/library_cli.py +181 -3
  29. package/modules/localmodels/library_custom.py +831 -0
  30. package/modules/localmodels/library_elastic.py +35 -7
  31. package/modules/localmodels/library_gateway.py +94 -32
  32. package/modules/localmodels/library_jobs.py +76 -11
  33. package/modules/localmodels/library_kept.py +50 -6
  34. package/modules/localmodels/library_model.py +254 -2
  35. package/modules/localmodels/library_pricing.py +83 -4
  36. package/modules/localmodels/library_serve.py +112 -50
  37. package/modules/localmodels/library_smoke.py +315 -0
  38. package/modules/localmodels/library_state.py +77 -1
  39. package/modules/localmodels/library_status.py +126 -4
  40. package/modules/localmodels/nvml_ctypes.py +431 -0
  41. package/modules/localmodels/plan_envelope.py +14 -6
  42. package/modules/localmodels/records.py +1 -0
  43. package/modules/localmodels/remote_ops.py +53 -5
  44. package/modules/localmodels/remote_ops_download.py +168 -29
  45. package/modules/localmodels/remote_ops_ranges.py +2 -5
  46. package/modules/localmodels/remote_ops_service.py +2 -1
  47. package/modules/localmodels/remote_ops_verify.py +22 -5
  48. package/modules/localmodels/runtime-lock.json +19 -19
  49. package/modules/localmodels/service_control.py +32 -1
  50. package/modules/localmodels/service_wiring.py +2 -3
  51. package/modules/localmodels/service_worker.py +6 -2
  52. package/modules/localmodels/services_cli.py +35 -27
  53. package/modules/localmodels/source_byok.py +3 -5
  54. package/modules/localmodels/stack_lifecycle.py +2 -2
  55. package/modules/localmodels/stack_memory.py +1 -0
  56. package/modules/localmodels/stack_view.py +77 -53
  57. package/modules/localmodels/stack_view_demo.py +36 -5
  58. package/modules/localmodels/stack_view_events.py +147 -12
  59. package/modules/localmodels/stack_view_gpu.py +97 -17
  60. package/modules/localmodels/stack_view_llm.py +15 -0
  61. package/modules/localmodels/stack_view_measure.py +4 -1
  62. package/modules/localmodels/stack_view_schema.py +54 -8
  63. package/modules/localmodels/stack_view_serve.py +40 -3
  64. package/modules/localmodels/stack_view_slots.py +89 -10
  65. package/modules/localmodels/stack_view_telemetry.py +163 -0
  66. package/modules/localmodels/stack_view_text.py +5 -2
  67. package/modules/localmodels/stack_view_tick.py +658 -0
  68. package/modules/localmodels/stack_view_words.py +4 -0
  69. package/modules/localmodels/{strata-poly-serve-0.2.20-poly.5.txt → strata-poly-serve-0.2.20-poly.6.txt} +1 -1
  70. package/modules/localmodels/suite.py +3 -1
  71. package/modules/localmodels/telemetry_math.py +538 -0
  72. package/modules/localmodels/web/view/view.js +1 -1
  73. package/modules/{simplex_localmodels-0.1.0.dev59.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/METADATA +1 -1
  74. package/modules/{simplex_localmodels-0.1.0.dev59.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/RECORD +76 -70
  75. package/package.json +1 -1
  76. package/tool.json +1 -1
  77. package/modules/localmodels/bifrost_datasheet.py +0 -53
  78. package/modules/localmodels/bifrost_provider.py +0 -88
  79. package/modules/localmodels/bifrost_unit.py +0 -99
  80. package/modules/localmodels/engines-strata-poly-0.2.20-poly.5.json +0 -94
  81. package/modules/localmodels/gateway_switch.py +0 -51
  82. package/modules/localmodels/library_floor.py +0 -78
  83. package/modules/localmodels/service_stop.py +0 -52
  84. /package/modules/{simplex_localmodels-0.1.0.dev59.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/WHEEL +0 -0
  85. /package/modules/{simplex_localmodels-0.1.0.dev59.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/entry_points.txt +0 -0
  86. /package/modules/{simplex_localmodels-0.1.0.dev59.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/licenses/NOTICE +0 -0
  87. /package/modules/{simplex_localmodels-0.1.0.dev59.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -1,21 +1,27 @@
1
- """Configuration rendering and private config/datasheet storage for the Bifrost gateway."""
1
+ """Configuration, provider and datasheet rendering for the Bifrost gateway."""
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
5
  import contextlib
6
6
  import copy
7
+ import ipaddress
7
8
  import json
8
9
  import os
10
+ import urllib.parse
11
+ from collections.abc import Iterable
9
12
  from pathlib import Path
10
13
  from typing import Any
11
14
 
12
- from localmodels import bifrost_datasheet, bifrost_provider
15
+ from localmodels import harness
13
16
  from localmodels.gateway_requests import AuxEndpoint
14
17
  from localmodels.harness import GatewayPlan, HarnessError
15
18
 
16
19
  ADMIN_USER = "localmodels"
17
20
  LOG_BATCH_INTERVAL = "250ms" # logs_store.writer.batch_interval; Bifrost's default is 5s
18
21
  STORE = ("config.db", "config.db-wal", "config.db-shm") # derived from config.json and datasheets
22
+ DATASHEET = "datasheet.json"
23
+ PARAMETERS = "model-parameters.json"
24
+ FILES = (DATASHEET, PARAMETERS)
19
25
  COMPLEX_RULE = "localmodels-agent-complex"
20
26
  AGENT_RULE = "localmodels-agent"
21
27
  BYOK_PROVIDER = "localmodels-byok"
@@ -30,6 +36,32 @@ AUX_PROVIDERS = {
30
36
  "rerank": "localmodels-rerank",
31
37
  "stt": "localmodels-stt",
32
38
  }
39
+ # Loopback upstreams (llama-server uses cpp-httplib's 5 s keep-alive timeout; auth_proxy fronts
40
+ # local services) sit on 127.0.0.1 where a fresh dial costs microseconds, while Bifrost's
41
+ # fasthttp pool defaults to a 30 s idle timeout and its StaleConnectionRetryIfErr only matches
42
+ # POSIX "broken pipe" / "connection reset by peer", not Windows Winsock WSAECONNABORTED (10053)
43
+ # or WSAECONNRESET (10054). Closing loopback connections after each response, capping idle
44
+ # keep-alive below 5 s, and allowing 2 fast retries on pre-response transport failures prevents
45
+ # Windows 502 wsasend aborts (evidence/2026-11-19-linger-agentic-batch1/REPORT.md, Issue #3).
46
+ LOOPBACK_KEEP_ALIVE_S = 2
47
+ LOOPBACK_MAX_RETRIES = 2
48
+ LOOPBACK_RETRY_INITIAL_MS = 100
49
+ LOOPBACK_RETRY_MAX_MS = 500
50
+
51
+ # What each provider may be asked: everything else Bifrost refuses before it reaches the
52
+ # service. The LLM speaks chat only, so Bifrost turns Responses (Codex) and Anthropic Messages
53
+ # (Claude Code) requests into chat completions instead of calling /v1/responses upstream.
54
+ _ALLOWED = {
55
+ "llm": {"list_models": True, "chat_completion": True, "chat_completion_stream": True},
56
+ "decision": {"list_models": True, "decisions": True},
57
+ "embedding": {"list_models": True, "embedding": True},
58
+ # Bifrost's openai-type rerank sends documents as {"text": ...} objects, which llama-server
59
+ # refuses; its cohere type sends the plain strings llama-server reads.
60
+ "rerank": {"rerank": True},
61
+ "stt": {"list_models": True, "transcription": True, "transcription_stream": True},
62
+ }
63
+ _BASE_TYPE = {"decision": "typesafe", "rerank": "cohere"}
64
+
33
65
  # The analyzer requires keyword lists even when the decision model classifies; they only decide
34
66
  # when it does not answer, so a few plain words suffice.
35
67
  _KEYWORDS = {
@@ -41,6 +73,92 @@ _AGENT_MATCH = "model == 'localmodels-agent'"
41
73
  _MANAGED_RULES = frozenset({COMPLEX_RULE, AGENT_RULE, BYOK_RULE})
42
74
 
43
75
 
76
+ def _is_loopback(url: str) -> bool:
77
+ host = (urllib.parse.urlsplit(url).hostname or "").strip().lower()
78
+ if host == "localhost":
79
+ return True
80
+ try:
81
+ return ipaddress.ip_address(host).is_loopback
82
+ except ValueError:
83
+ return False
84
+
85
+
86
+ def origin(url: str) -> str:
87
+ """Bifrost appends the API path (/v1/...) to a provider's base URL itself."""
88
+ url = url.rstrip("/")
89
+ return url[: -len("/v1")] if url.endswith("/v1") else url
90
+
91
+
92
+ def render_provider(role: str, url: str, model: str, key: str, pid: str) -> dict[str, Any]:
93
+ """Render one Bifrost provider entry shared by stack and standalone app gateways."""
94
+ custom: dict[str, Any] = {
95
+ "base_provider_type": _BASE_TYPE.get(role, "openai"),
96
+ "allowed_requests": _ALLOWED[role],
97
+ }
98
+ if role == "rerank":
99
+ custom["request_path_overrides"] = {"rerank": "/v1/rerank"}
100
+ entry: dict[str, Any] = {"id": pid, "name": pid, "value": key, "models": [model], "weight": 1}
101
+ if role == "llm":
102
+ # Bifrost v2.3.0 lists (/v1/models as <pid>/<name>, /anthropic/v1/models bare) and routes
103
+ # a name only when the key has it in both ``models`` and ``aliases``; either alone does not.
104
+ entry["models"] = [model, harness.GROUP]
105
+ entry["aliases"] = {harness.GROUP: model}
106
+ network_config: dict[str, Any] = {
107
+ "base_url": origin(url),
108
+ "allow_private_network": True,
109
+ "max_retries": 0,
110
+ "default_request_timeout_in_seconds": 600,
111
+ "stream_idle_timeout_in_seconds": 600,
112
+ }
113
+ if _is_loopback(url):
114
+ network_config.update(
115
+ {
116
+ "max_retries": LOOPBACK_MAX_RETRIES,
117
+ "retry_backoff_initial": LOOPBACK_RETRY_INITIAL_MS,
118
+ "retry_backoff_max": LOOPBACK_RETRY_MAX_MS,
119
+ "keep_alive_timeout_in_seconds": LOOPBACK_KEEP_ALIVE_S,
120
+ "extra_headers": {"Connection": "close"},
121
+ }
122
+ )
123
+ return {
124
+ "keys": [entry],
125
+ "network_config": network_config,
126
+ "custom_provider_config": custom,
127
+ }
128
+
129
+
130
+ def file_url(app: Path, name: str, windows: bool = os.name == "nt") -> str:
131
+ """A file URL for a sheet in ``app`` that Bifrost can open. Bifrost reads a file URL's path
132
+ as it stands, so ``file:///C:/x/datasheet.json`` is ``/C:/x/...`` on Windows, which does
133
+ not open, and Bifrost exits at start (dev38 Windows library load). On Windows the URL is
134
+ relative to its working directory, ``app`` (gateway_bifrost._start, the only way Bifrost
135
+ runs there); elsewhere absolute, as a systemd unit's working directory is not ``app``."""
136
+ return f"file:./{name}" if windows else (app / name).as_uri()
137
+
138
+
139
+ def framework(app: Path) -> dict[str, Any]:
140
+ """config.json's ``framework``: the datasheets from ``app``, and no MCP library sync (0 is
141
+ Bifrost's off switch; any other interval fetches it)."""
142
+ return {
143
+ "pricing": {
144
+ "pricing_url": file_url(app, DATASHEET),
145
+ "model_parameters_url": file_url(app, PARAMETERS),
146
+ "mcp_library_sync_interval": 0,
147
+ }
148
+ }
149
+
150
+
151
+ def sheets(provider: str, names: Iterable[str], context: int | None) -> dict[str, Any]:
152
+ """The files ``framework`` names. One pricing row per name the LLM's key lists, keyed as
153
+ Bifrost looks rows up (provider, the name after the first slash, a mode), with the window the
154
+ LLM launches with (``-c``; one request may fill it); a plan without a window has none."""
155
+ row = {"provider": provider, "mode": "chat", "context_length": context}
156
+ return {
157
+ DATASHEET: {f"{provider}/{name}": row for name in names} if context else {},
158
+ PARAMETERS: {},
159
+ }
160
+
161
+
44
162
  def render(
45
163
  gw: GatewayPlan,
46
164
  llm_key: str,
@@ -56,18 +174,18 @@ def render(
56
174
  this call does not manage (a re-sync keeps the STT provider)."""
57
175
  llm = gw["llm"]
58
176
  providers: dict[str, Any] = dict(keep or {})
59
- providers[gw["llm_provider"]] = bifrost_provider.render(
177
+ providers[gw["llm_provider"]] = render_provider(
60
178
  "llm", llm["url"], llm["model"], llm_key, gw["llm_provider"]
61
179
  )
62
180
  decision = gw["decision"] if decision_key is not None else None
63
181
  if decision is not None and decision_key is not None:
64
- providers[gw["decision_provider"]] = bifrost_provider.render(
182
+ providers[gw["decision_provider"]] = render_provider(
65
183
  "decision", decision["url"], decision["model"], decision_key, gw["decision_provider"]
66
184
  )
67
185
  for ep in aux:
68
186
  pid = AUX_PROVIDERS.get(str(ep.get("contract")))
69
187
  if pid:
70
- providers[pid] = bifrost_provider.render(
188
+ providers[pid] = render_provider(
71
189
  str(ep["contract"]), str(ep["url"]), str(ep["model"]), str(ep["key"]), pid
72
190
  )
73
191
  target = {"provider": gw["llm_provider"], "model": llm["model"], "weight": 1}
@@ -75,7 +193,7 @@ def render(
75
193
  if fast := gw.get("llm_fast"):
76
194
  if decision is None or not fast_key:
77
195
  raise HarnessError("two-LLM routing requires both LLM keys and a ready decision model")
78
- providers[FAST_PROVIDER] = bifrost_provider.render(
196
+ providers[FAST_PROVIDER] = render_provider(
79
197
  "llm", fast["url"], fast["model"], fast_key, FAST_PROVIDER
80
198
  )
81
199
  default_target = {"provider": FAST_PROVIDER, "model": fast["model"], "weight": 1}
@@ -126,7 +244,7 @@ def render(
126
244
  rules.append(byok_rule(str(models[0])))
127
245
  governance["routing_rules"] = normalize_routing_rules(rules)
128
246
  config = render_config(providers, governance, app)
129
- config["framework"] = bifrost_datasheet.framework(app)
247
+ config["framework"] = framework(app)
130
248
  return config
131
249
 
132
250
 
@@ -295,6 +413,12 @@ def _text(value: Any) -> str:
295
413
  return json.dumps(value, ensure_ascii=False, indent=1) + "\n"
296
414
 
297
415
 
416
+ def clear_store(app: Path) -> None:
417
+ """Delete Bifrost's derived SQLite config store so the next start rebuilds it from config.json."""
418
+ for name in STORE:
419
+ (app / name).unlink(missing_ok=True)
420
+
421
+
298
422
  def write_config(
299
423
  app: Path,
300
424
  config: dict[str, Any],
@@ -324,6 +448,5 @@ def write_config(
324
448
  os.replace(tmp, path)
325
449
  changed = True
326
450
  if changed and drop_store:
327
- for name in STORE:
328
- (app / name).unlink(missing_ok=True)
451
+ clear_store(app)
329
452
  return changed
@@ -2,7 +2,7 @@
2
2
 
3
3
  Codex (``model_catalog_json``), pi (``models.json``) and Claude Code (its settings ``env``) each
4
4
  take their model and its window from their own settings, and Bifrost's ``/v1/models`` has ids,
5
- the LLM's window (``context_length``, from the datasheet ``bifrost_datasheet`` makes) and no
5
+ the LLM's window (``context_length``, from the datasheet ``bifrost_config`` makes) and no
6
6
  reasoning levels. This module is the one place that joins the live listing with the
7
7
  plan's LLM facts (display name, window, reasoning efforts), for the stack's own wiring
8
8
  (``bifrost_pi``, ``bifrost_clients``) and for ``stack clients`` (consumers on other machines).