@simplexai/localmodels-linux-x64 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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""BYOK endpoint
|
|
1
|
+
"""BYOK endpoint checks: one request to the address the user built, and its model list."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
@@ -8,24 +8,20 @@ import urllib.error
|
|
|
8
8
|
import urllib.request
|
|
9
9
|
from typing import Any, TypedDict
|
|
10
10
|
|
|
11
|
-
from localmodels import bifrost_provider
|
|
12
11
|
from localmodels.source_byok import (
|
|
13
12
|
CREDENTIALS_SCHEMA,
|
|
14
13
|
MAX_CONTEXT_WINDOW,
|
|
15
|
-
PROTOCOL_ORDER,
|
|
16
14
|
ByokCredentials,
|
|
17
15
|
ByokEndpoint,
|
|
18
16
|
ByokError,
|
|
19
17
|
Protocol,
|
|
20
|
-
|
|
18
|
+
models_url,
|
|
19
|
+
request_url,
|
|
21
20
|
validate_url,
|
|
22
21
|
)
|
|
23
22
|
|
|
24
23
|
MAX_PROBE_BYTES = 1 << 20
|
|
25
24
|
MAX_LISTED_MODELS = 1000
|
|
26
|
-
# Gateways that serve both API families often put OpenAI under /v1 and Anthropic under
|
|
27
|
-
# /anthropic on one host, so a format missing at the entered URL is also tried there.
|
|
28
|
-
ANTHROPIC_SUFFIX = "/anthropic"
|
|
29
25
|
# The list field each wire format's reply carries, which tells a real reply from a page
|
|
30
26
|
# that answers any path.
|
|
31
27
|
_REPLY_FIELD: dict[Protocol, str] = {
|
|
@@ -33,8 +29,6 @@ _REPLY_FIELD: dict[Protocol, str] = {
|
|
|
33
29
|
"openai-responses": "output",
|
|
34
30
|
"anthropic": "content",
|
|
35
31
|
}
|
|
36
|
-
# Which failure explains a refused endpoint best when nothing answered.
|
|
37
|
-
_FAILURE_RANK = ("BYOK_AUTH_FAILED", "BYOK_MODEL_NOT_FOUND", "BYOK_UPSTREAM_REJECTED")
|
|
38
32
|
_WINDOW_FIELDS = ("context_length", "context_window", "max_input_tokens")
|
|
39
33
|
|
|
40
34
|
|
|
@@ -51,22 +45,6 @@ class _NoRedirect(urllib.request.HTTPRedirectHandler):
|
|
|
51
45
|
return None
|
|
52
46
|
|
|
53
47
|
|
|
54
|
-
def _alternate(root: str) -> str:
|
|
55
|
-
"""The other half of the /v1 and /anthropic layout."""
|
|
56
|
-
if root.endswith(ANTHROPIC_SUFFIX):
|
|
57
|
-
return root.removesuffix(ANTHROPIC_SUFFIX)
|
|
58
|
-
return root + ANTHROPIC_SUFFIX
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def _roots(base_url: str, protocol: Protocol) -> list[str]:
|
|
62
|
-
"""Where ``protocol`` may be served: the entered URL first, then the alternate when the
|
|
63
|
-
entered URL names the other API family."""
|
|
64
|
-
root = bifrost_provider.origin(base_url)
|
|
65
|
-
if root.endswith(ANTHROPIC_SUFFIX) == (protocol == "anthropic"):
|
|
66
|
-
return [root]
|
|
67
|
-
return [root, _alternate(root)]
|
|
68
|
-
|
|
69
|
-
|
|
70
48
|
def _headers(protocol: Protocol, api_key: str) -> dict[str, str]:
|
|
71
49
|
headers = {"Accept": "application/json", "Content-Type": "application/json"}
|
|
72
50
|
if protocol == "anthropic":
|
|
@@ -97,18 +75,17 @@ def _call(
|
|
|
97
75
|
except urllib.error.HTTPError as exc:
|
|
98
76
|
if exc.code in (401, 403):
|
|
99
77
|
raise ByokError(
|
|
100
|
-
"BYOK_AUTH_FAILED", "
|
|
78
|
+
"BYOK_AUTH_FAILED", f"{url} rejected the API key (HTTP {exc.code})."
|
|
101
79
|
) from None
|
|
102
80
|
if exc.code == 404:
|
|
103
81
|
raise ByokError(
|
|
104
|
-
"
|
|
82
|
+
"BYOK_NOT_FOUND",
|
|
83
|
+
f"{url} returned HTTP 404: the address or the model was not found.",
|
|
105
84
|
) from None
|
|
106
|
-
raise ByokError(
|
|
107
|
-
"BYOK_UPSTREAM_REJECTED", f"Upstream endpoint returned HTTP {exc.code}."
|
|
108
|
-
) from None
|
|
85
|
+
raise ByokError("BYOK_UPSTREAM_REJECTED", f"{url} returned HTTP {exc.code}.") from None
|
|
109
86
|
except (urllib.error.URLError, TimeoutError, OSError) as exc:
|
|
110
87
|
raise ByokError(
|
|
111
|
-
"BYOK_UNREACHABLE", f"Could not reach
|
|
88
|
+
"BYOK_UNREACHABLE", f"Could not reach {url} ({type(exc).__name__})."
|
|
112
89
|
) from None
|
|
113
90
|
try:
|
|
114
91
|
return json.loads(raw) if len(raw) <= MAX_PROBE_BYTES else None
|
|
@@ -143,34 +120,35 @@ def _model_rows(doc: Any) -> list[ByokModel] | None:
|
|
|
143
120
|
return models
|
|
144
121
|
|
|
145
122
|
|
|
146
|
-
def
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
path, body = {
|
|
152
|
-
"anthropic": ("messages", {"model": model, "max_tokens": 16}),
|
|
153
|
-
"openai-responses": ("responses", {"model": model, "max_output_tokens": 16}),
|
|
154
|
-
"openai-chat": ("chat/completions", {"model": model, "max_tokens": 16}),
|
|
155
|
-
}[protocol]
|
|
123
|
+
def _probe_request(endpoint: ByokEndpoint, private: bool, timeout: float) -> None:
|
|
124
|
+
"""Send one small request in the endpoint's wire format; raise ByokError unless it is
|
|
125
|
+
answered."""
|
|
126
|
+
protocol = endpoint["protocol"]
|
|
127
|
+
body: dict[str, Any] = {"model": endpoint["model_id"]}
|
|
156
128
|
if protocol == "openai-responses":
|
|
157
|
-
body
|
|
129
|
+
body |= {"input": "Reply with OK.", "max_output_tokens": 16, "stream": False}
|
|
158
130
|
else:
|
|
159
|
-
body
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
doc = _call(
|
|
131
|
+
body |= {"messages": [{"role": "user", "content": "Reply with OK."}], "max_tokens": 16}
|
|
132
|
+
if protocol == "openai-chat":
|
|
133
|
+
body["stream"] = False
|
|
134
|
+
url = request_url(endpoint)
|
|
135
|
+
doc = _call(url, _headers(protocol, endpoint["api_key"]), private, timeout, body)
|
|
164
136
|
if not isinstance(doc, dict) or not isinstance(doc.get(_REPLY_FIELD[protocol]), list):
|
|
165
|
-
raise ByokError(
|
|
166
|
-
|
|
167
|
-
|
|
137
|
+
raise ByokError("BYOK_UPSTREAM_REJECTED", f"{url} answered in an unexpected format.")
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _listed(endpoint: ByokEndpoint, private: bool, timeout: float) -> list[ByokModel]:
|
|
141
|
+
url = models_url(endpoint)
|
|
142
|
+
headers = _headers(endpoint["protocol"], endpoint["api_key"])
|
|
143
|
+
rows = _model_rows(_call(url, headers, private, timeout))
|
|
144
|
+
if not rows:
|
|
145
|
+
raise ByokError("BYOK_UPSTREAM_REJECTED", f"{url} listed no models.")
|
|
146
|
+
return rows
|
|
168
147
|
|
|
169
148
|
|
|
170
149
|
def _window_for(rows: list[ByokModel], target: str) -> int | None:
|
|
171
150
|
"""The listed window of ``target``, matching an exact ID first and then an ID with one
|
|
172
|
-
more provider prefix on either side, since
|
|
173
|
-
under different IDs."""
|
|
151
|
+
more provider prefix on either side, since gateways list one model under several IDs."""
|
|
174
152
|
exact = [row for row in rows if row["id"] == target]
|
|
175
153
|
loose = [
|
|
176
154
|
row
|
|
@@ -180,96 +158,34 @@ def _window_for(rows: list[ByokModel], target: str) -> int | None:
|
|
|
180
158
|
return next((row["context_window"] for row in exact + loose if row["context_window"]), None)
|
|
181
159
|
|
|
182
160
|
|
|
183
|
-
def
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
the other half of a /v1 and /anthropic gateway, whose list may carry windows when the
|
|
188
|
-
answering half's does not."""
|
|
161
|
+
def probe_upstream(endpoint: ByokEndpoint, *, timeout: float = 35.0) -> ByokCredentials:
|
|
162
|
+
"""Check that the endpoint answers one request at its address, and read the model's
|
|
163
|
+
context window from its model list when it reports one."""
|
|
164
|
+
_, private = validate_url(endpoint["base_url"])
|
|
189
165
|
deadline = time.monotonic() + timeout
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
for listing_root, style in ((root, protocol), (alternate, alternate_style)):
|
|
195
|
-
remaining = deadline - time.monotonic()
|
|
196
|
-
if remaining <= 0:
|
|
197
|
-
return None
|
|
198
|
-
headers = _headers(style, endpoint["api_key"])
|
|
166
|
+
_probe_request(endpoint, private, timeout)
|
|
167
|
+
remaining = min(deadline - time.monotonic(), 8.0)
|
|
168
|
+
window = None
|
|
169
|
+
if remaining > 1:
|
|
199
170
|
try:
|
|
200
|
-
|
|
171
|
+
window = _window_for(_listed(endpoint, private, remaining), endpoint["model_id"])
|
|
201
172
|
except ByokError:
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
173
|
+
window = None
|
|
174
|
+
return {
|
|
175
|
+
"schema": CREDENTIALS_SCHEMA,
|
|
176
|
+
"protocol": endpoint["protocol"],
|
|
177
|
+
"base_url": endpoint["base_url"],
|
|
178
|
+
"path": endpoint["path"],
|
|
179
|
+
"endpoint": endpoint["endpoint"],
|
|
180
|
+
"api_key": endpoint["api_key"],
|
|
181
|
+
"model_id": endpoint["model_id"],
|
|
182
|
+
"context_window": window or endpoint["context_window"],
|
|
183
|
+
"key_saved": bool(endpoint["api_key"]),
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def list_models(endpoint: ByokEndpoint, *, timeout: float = 20.0) -> list[ByokModel]:
|
|
188
|
+
"""The models the endpoint lists at its model address, sorted by ID."""
|
|
217
189
|
_, private = validate_url(endpoint["base_url"])
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
for protocol in PROTOCOL_ORDER[runtime]:
|
|
221
|
-
for root in _roots(endpoint["base_url"], protocol):
|
|
222
|
-
remaining = deadline - time.monotonic()
|
|
223
|
-
if remaining <= 0:
|
|
224
|
-
raise ByokError("BYOK_UNREACHABLE", "Upstream endpoint did not answer in time.")
|
|
225
|
-
try:
|
|
226
|
-
_probe_format(root, endpoint, protocol, private, remaining)
|
|
227
|
-
except ByokError as exc:
|
|
228
|
-
if exc.code == "BYOK_UNREACHABLE":
|
|
229
|
-
raise
|
|
230
|
-
failures.append(exc)
|
|
231
|
-
continue
|
|
232
|
-
remaining = deadline - time.monotonic()
|
|
233
|
-
discovered = (
|
|
234
|
-
_discover_window(root, endpoint, protocol, private, min(remaining, 8.0))
|
|
235
|
-
if remaining > 1
|
|
236
|
-
else None
|
|
237
|
-
)
|
|
238
|
-
return {
|
|
239
|
-
"schema": CREDENTIALS_SCHEMA,
|
|
240
|
-
"protocol": protocol,
|
|
241
|
-
"base_url": endpoint["base_url"],
|
|
242
|
-
"upstream_url": root,
|
|
243
|
-
"api_key": endpoint["api_key"],
|
|
244
|
-
"model_id": endpoint["model_id"],
|
|
245
|
-
"context_window": discovered or endpoint["context_window"],
|
|
246
|
-
"key_saved": bool(endpoint["api_key"]),
|
|
247
|
-
}
|
|
248
|
-
raise min(failures, key=lambda exc: _FAILURE_RANK.index(exc.code))
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
def list_models(endpoint: ByokEndpoint, *, timeout: float = 20.0) -> tuple[str, list[ByokModel]]:
|
|
252
|
-
"""The models the endpoint lists, sorted by ID, and the address that listed them."""
|
|
253
|
-
_, private = validate_url(endpoint["base_url"])
|
|
254
|
-
deadline = time.monotonic() + timeout
|
|
255
|
-
failures: list[ByokError] = []
|
|
256
|
-
entered = bifrost_provider.origin(endpoint["base_url"])
|
|
257
|
-
for root in (entered, _alternate(entered)):
|
|
258
|
-
for protocol in ("openai-chat", "anthropic"):
|
|
259
|
-
remaining = deadline - time.monotonic()
|
|
260
|
-
if remaining <= 0:
|
|
261
|
-
raise ByokError("BYOK_UNREACHABLE", "Upstream endpoint did not answer in time.")
|
|
262
|
-
headers = _headers(protocol, endpoint["api_key"])
|
|
263
|
-
try:
|
|
264
|
-
rows = _model_rows(_call(f"{root}/v1/models", headers, private, remaining))
|
|
265
|
-
except ByokError as exc:
|
|
266
|
-
if exc.code == "BYOK_UNREACHABLE":
|
|
267
|
-
raise
|
|
268
|
-
failures.append(exc)
|
|
269
|
-
continue
|
|
270
|
-
if rows:
|
|
271
|
-
return root, sorted(rows, key=lambda row: row["id"])[:MAX_LISTED_MODELS]
|
|
272
|
-
failures.append(
|
|
273
|
-
ByokError("BYOK_UPSTREAM_REJECTED", "Upstream endpoint listed no models.")
|
|
274
|
-
)
|
|
275
|
-
raise min(failures, key=lambda exc: _FAILURE_RANK.index(exc.code))
|
|
190
|
+
rows = _listed(endpoint, private, timeout)
|
|
191
|
+
return sorted(rows, key=lambda row: row["id"])[:MAX_LISTED_MODELS]
|
|
@@ -64,18 +64,13 @@ def add_parser(sub: argparse._SubParsersAction[argparse.ArgumentParser]) -> None
|
|
|
64
64
|
required=True,
|
|
65
65
|
help="read BYOK configuration JSON from standard input",
|
|
66
66
|
)
|
|
67
|
-
check.add_argument(
|
|
68
|
-
"--runtime",
|
|
69
|
-
choices=source_byok.RUNTIMES,
|
|
70
|
-
required=True,
|
|
71
|
-
help="agent runtime the endpoint will serve; its own wire format is tried first",
|
|
72
|
-
)
|
|
73
67
|
check.add_argument("--json", action="store_true", help="accepted; output is JSON")
|
|
74
68
|
cli_help.document(
|
|
75
69
|
check,
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
|
|
70
|
+
"Send one request in the given wire format (OpenAI chat, OpenAI responses, or "
|
|
71
|
+
"Anthropic) to base URL + path + endpoint, without saving credentials or changing the "
|
|
72
|
+
"active model source.",
|
|
73
|
+
examples=[("%(prog)s --config-stdin --json", "")],
|
|
79
74
|
)
|
|
80
75
|
|
|
81
76
|
models = verbs.add_parser("models", help="list the models a BYOK endpoint serves")
|
|
@@ -88,8 +83,8 @@ def add_parser(sub: argparse._SubParsersAction[argparse.ArgumentParser]) -> None
|
|
|
88
83
|
models.add_argument("--json", action="store_true", help="accepted; output is JSON")
|
|
89
84
|
cli_help.document(
|
|
90
85
|
models,
|
|
91
|
-
"List the models
|
|
92
|
-
"
|
|
86
|
+
"List the models at base URL + path + /models, with their names and context windows "
|
|
87
|
+
"when the endpoint reports them, without saving credentials.",
|
|
93
88
|
examples=[("%(prog)s --config-stdin --json", "")],
|
|
94
89
|
)
|
|
95
90
|
|
|
@@ -266,13 +261,20 @@ def _ensure_runtime_installed(
|
|
|
266
261
|
runtime_cli.apply_plan(plan, str(plan["id"]))
|
|
267
262
|
|
|
268
263
|
|
|
264
|
+
def _stderr_event(event: dict[str, Any]) -> None:
|
|
265
|
+
"""One JSON line per event on stderr, written at once: stdout carries only the final
|
|
266
|
+
document, which the installer parses whole."""
|
|
267
|
+
sys.stderr.write(json.dumps(event, ensure_ascii=False) + "\n")
|
|
268
|
+
sys.stderr.flush()
|
|
269
|
+
|
|
270
|
+
|
|
269
271
|
def _apply_byok(args: argparse.Namespace, runtime: Runtime) -> SourceState:
|
|
270
272
|
payload = _read_stdin_json() if args.config_stdin else None
|
|
271
|
-
creds = source_byok_probe.probe_upstream(source_byok.resolve_endpoint(payload)
|
|
273
|
+
creds = source_byok_probe.probe_upstream(source_byok.resolve_endpoint(payload))
|
|
272
274
|
_unload_loaded_local_models(args.base_dir)
|
|
273
275
|
source_byok.save_credentials(creds)
|
|
274
276
|
facts = library_jobs.probe()
|
|
275
|
-
gateway_url, env = source_byok.mount_byok(creds, facts)
|
|
277
|
+
gateway_url, env = source_byok.mount_byok(creds, facts, _stderr_event)
|
|
276
278
|
return source_byok.save_source_state(
|
|
277
279
|
{
|
|
278
280
|
"schema": source_byok.SOURCE_SCHEMA,
|
|
@@ -344,14 +346,13 @@ def cli(args: argparse.Namespace) -> int:
|
|
|
344
346
|
print(json.dumps(doc, ensure_ascii=False, indent=1))
|
|
345
347
|
return 0
|
|
346
348
|
if verb == "check":
|
|
347
|
-
runtime = cast(Runtime, args.runtime)
|
|
348
349
|
|
|
349
350
|
def check(payload: dict[str, Any]) -> dict[str, Any]:
|
|
350
351
|
endpoint = source_byok.resolve_endpoint(payload, require_input=True)
|
|
351
|
-
creds = source_byok_probe.probe_upstream(endpoint
|
|
352
|
+
creds = source_byok_probe.probe_upstream(endpoint)
|
|
352
353
|
return {
|
|
353
354
|
"protocol": creds["protocol"],
|
|
354
|
-
"
|
|
355
|
+
"url": source_byok.request_url(creds),
|
|
355
356
|
"model_id": creds["model_id"],
|
|
356
357
|
"context_window": creds["context_window"],
|
|
357
358
|
}
|
|
@@ -363,8 +364,8 @@ def cli(args: argparse.Namespace) -> int:
|
|
|
363
364
|
endpoint = source_byok.resolve_endpoint(
|
|
364
365
|
payload, require_input=True, require_model=False
|
|
365
366
|
)
|
|
366
|
-
|
|
367
|
-
return {"
|
|
367
|
+
listed = source_byok_probe.list_models(endpoint)
|
|
368
|
+
return {"url": source_byok.models_url(endpoint), "models": listed}
|
|
368
369
|
|
|
369
370
|
return _endpoint_command(source_byok.MODELS_SCHEMA, models)
|
|
370
371
|
|
|
@@ -202,11 +202,7 @@ def _deploy(component: str, plan: Plan, key: str, log: Log) -> Component:
|
|
|
202
202
|
)
|
|
203
203
|
if record["ok"]:
|
|
204
204
|
return _ok(component, f"{plan['endpoint']['base_url']} ({plan['service']['name']})")
|
|
205
|
-
return _failed(
|
|
206
|
-
component,
|
|
207
|
-
record.get("error", "unknown failure"),
|
|
208
|
-
stack_run.search_failure_checks(component, record),
|
|
209
|
-
)
|
|
205
|
+
return _failed(component, record.get("error", "unknown failure"))
|
|
210
206
|
|
|
211
207
|
|
|
212
208
|
@dataclass(frozen=True)
|
|
@@ -340,6 +336,14 @@ def _deploy_aux(task: str, part: Plan, key: str, log: Log, do: Effects) -> Compo
|
|
|
340
336
|
return do.deploy(task, part, key, log)
|
|
341
337
|
|
|
342
338
|
|
|
339
|
+
def _sync_library(plan: StackPlan, attempt_id: str | None) -> None:
|
|
340
|
+
"""Keep an already-used model library in step with a newly accepted stack apply."""
|
|
341
|
+
from localmodels import library_convert
|
|
342
|
+
|
|
343
|
+
if library_convert.initialized():
|
|
344
|
+
library_convert.sync_stack(plan, attempt_id=attempt_id, if_initialized=True)
|
|
345
|
+
|
|
346
|
+
|
|
343
347
|
def execute(
|
|
344
348
|
plan: StackPlan,
|
|
345
349
|
log: Log,
|
|
@@ -374,11 +378,14 @@ def execute(
|
|
|
374
378
|
journal = stack_journal.Journal(plan["plan_id"], session["attempt_id"]) # for stack view
|
|
375
379
|
try:
|
|
376
380
|
with stack_run.checkpointed(session):
|
|
377
|
-
|
|
381
|
+
result = _run_components(
|
|
378
382
|
plan, log, steps, session, parts, persist, journal.tee(on_progress)
|
|
379
383
|
)
|
|
380
384
|
finally:
|
|
381
385
|
journal.close()
|
|
386
|
+
if result["ok"]:
|
|
387
|
+
_sync_library(plan, result.get("attempt_id"))
|
|
388
|
+
return result
|
|
382
389
|
|
|
383
390
|
|
|
384
391
|
def _run_components(
|
|
@@ -67,8 +67,8 @@ GROUPS = (
|
|
|
67
67
|
)
|
|
68
68
|
STACK = """\
|
|
69
69
|
Plan, install and run the local agent stack on this computer: the smartest LLM that fits,
|
|
70
|
-
a gateway (Bifrost by default) and the pi agent. A GPU decision model, embedding/reranker/STT
|
|
71
|
-
|
|
70
|
+
a gateway (Bifrost by default) and the pi agent. A GPU decision model, embedding/reranker/STT
|
|
71
|
+
and TTS are optional and off by default (--decision, --aux, --tts).
|
|
72
72
|
Nothing is downloaded or started until you approve a saved plan.
|
|
73
73
|
|
|
74
74
|
typical flow:
|
|
@@ -87,9 +87,9 @@ AGENTS = """\
|
|
|
87
87
|
Read-only: hardware, memory, what-if, decisions, plan (saves a file), status, view, verify, doctor,
|
|
88
88
|
commands, clients, mcp (read-only stdio JSON-RPC), ledger, arena leaderboard, card (writes a local
|
|
89
89
|
SVG), remove --dry-run, and rollback without --approve. warm sends each installed LLM two short
|
|
90
|
-
requests (--sudo also runs macOS purge); try sends one demo request through the local gateway
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
requests (--sudo also runs macOS purge); try sends one demo request through the local gateway and
|
|
91
|
+
changes nothing installed. arena compares two local LLMs blindly and writes only model IDs and Elo
|
|
92
|
+
counts.
|
|
93
93
|
Installs only an approved plan: apply PLAN --approve ID, rollback --approve ID; install asks
|
|
94
94
|
y/N (--yes skips). Also changes things: up (starts what was installed), down (stops it), remove, prune --yes.
|
|
95
95
|
Machine output: --json on plan, hardware, memory, what-if, status, view, verify, doctor, up, down, apply,
|
|
@@ -209,8 +209,7 @@ def add_plan_arguments(plan: argparse.ArgumentParser) -> None:
|
|
|
209
209
|
"--gateway",
|
|
210
210
|
choices=list(harness.GATEWAYS),
|
|
211
211
|
help="the gateway clients reach the local models through: bifrost (this tool's own "
|
|
212
|
-
"instance, the default) or magpie (the user's Magpie, with reasoning-effort routing
|
|
213
|
-
"web search)",
|
|
212
|
+
"instance, the default) or magpie (the user's Magpie, with reasoning-effort routing)",
|
|
214
213
|
)
|
|
215
214
|
choose.add_argument(
|
|
216
215
|
"--vision",
|
|
@@ -405,7 +404,6 @@ def _plan(actions: Parsers) -> None:
|
|
|
405
404
|
("%(prog)s", "recommended stack for this computer"),
|
|
406
405
|
("%(prog)s --llm qwen3.8-27b --decision none", "pin the LLM, no decision model"),
|
|
407
406
|
("%(prog)s --aux embedding,reranker", "opt in to some auxiliaries"),
|
|
408
|
-
("%(prog)s --search", "add the free web search"),
|
|
409
407
|
("%(prog)s --gpu 1 --share-gpu", "a card that already runs something"),
|
|
410
408
|
("%(prog)s --update", "replace only what changed in the installed stack"),
|
|
411
409
|
("%(prog)s --facts host.json --offline --json", "price saved facts, no network"),
|
|
@@ -117,9 +117,9 @@ def _deployments_ready(
|
|
|
117
117
|
required = stack_run.required_components(plan)
|
|
118
118
|
for name, part in parts.items():
|
|
119
119
|
if (
|
|
120
|
-
part["endpoint"].get("contract") ==
|
|
121
|
-
and
|
|
122
|
-
and stack_run.
|
|
120
|
+
part["endpoint"].get("contract") == stack_run.SEARCH
|
|
121
|
+
and stack_run.SEARCH not in required
|
|
122
|
+
and stack_run.search_unavailable(by_name[name])
|
|
123
123
|
):
|
|
124
124
|
continue
|
|
125
125
|
row, entry = rows.get(name), owned["deployments"].get(name)
|
|
@@ -12,7 +12,7 @@ import argparse
|
|
|
12
12
|
import json
|
|
13
13
|
import urllib.parse
|
|
14
14
|
|
|
15
|
-
from localmodels import bifrost_models, gateway_bifrost, harness, hosts, stack_update
|
|
15
|
+
from localmodels import bifrost_models, gateway_bifrost, harness, hosts, stack_update, vision
|
|
16
16
|
from localmodels.bifrost_models import StackClients
|
|
17
17
|
from localmodels.stack_plan import StackError, command
|
|
18
18
|
|
|
@@ -53,6 +53,13 @@ def settings(base: str | None = None) -> StackClients:
|
|
|
53
53
|
f" proven this tool's); start it with {command()} stack up"
|
|
54
54
|
)
|
|
55
55
|
listed = bifrost_models.listed(record["addr"])
|
|
56
|
+
if "vision" not in gw:
|
|
57
|
+
fast = plan.get("llm_fast")
|
|
58
|
+
gw = {
|
|
59
|
+
**gw,
|
|
60
|
+
"vision": vision.reads_pictures(plan["llm"]["launch"])
|
|
61
|
+
and (fast is None or vision.reads_pictures(fast["launch"])),
|
|
62
|
+
}
|
|
56
63
|
return bifrost_models.clients(
|
|
57
64
|
plan["plan_id"],
|
|
58
65
|
gw,
|
|
@@ -283,6 +283,8 @@ def _llama_quality(
|
|
|
283
283
|
except StackError:
|
|
284
284
|
return -1, ""
|
|
285
285
|
entry = next(e for e in cat.load_catalog_file() if e.id == llm_id)
|
|
286
|
+
if llm_rank.windows_fallback(entry, facts):
|
|
287
|
+
return 0, llm_id # an editorial anchor, not an installed score, as in the card lists
|
|
286
288
|
return entry.quality, llm_id
|
|
287
289
|
|
|
288
290
|
|
|
@@ -685,6 +687,7 @@ def assemble(
|
|
|
685
687
|
# A plan saved before the choice existed has no gateway option: it used Magpie.
|
|
686
688
|
gateway_kind=options.get("gateway", "magpie"),
|
|
687
689
|
context=int(str(llm["launch"].get("window") or 0)) or None,
|
|
690
|
+
vision=stack_route.reads_images(llm),
|
|
688
691
|
)
|
|
689
692
|
if fast is not None:
|
|
690
693
|
tools_plan["gateway"]["llm_fast"] = {
|
|
@@ -697,14 +700,7 @@ def assemble(
|
|
|
697
700
|
w.replace("so all hit one LLM at client effort", "each LLM uses client effort")
|
|
698
701
|
for w in tools_plan["warnings"]
|
|
699
702
|
]
|
|
700
|
-
if harness.gateway_kind(tools_plan["gateway"])
|
|
701
|
-
if any(p["endpoint"].get("contract") == "search" for p in aux):
|
|
702
|
-
tools_plan["warnings"].append(
|
|
703
|
-
"Bifrost runs the web search service as an MCP tool: it replaces native web search"
|
|
704
|
-
" in the LLM's requests (Codex, Claude Code, pi) with an injected web_search and"
|
|
705
|
-
" runs the calls itself, so every LLM request offers it"
|
|
706
|
-
)
|
|
707
|
-
else:
|
|
703
|
+
if harness.gateway_kind(tools_plan["gateway"]) != "bifrost":
|
|
708
704
|
tools_plan = gateway_keys.with_caller_key(tools_plan)
|
|
709
705
|
warnings += tools_plan["warnings"]
|
|
710
706
|
|
|
@@ -31,9 +31,10 @@ APPLY_ORDER = (
|
|
|
31
31
|
"rerank",
|
|
32
32
|
"stt",
|
|
33
33
|
"tts",
|
|
34
|
-
"search",
|
|
35
34
|
"gateway",
|
|
36
35
|
)
|
|
36
|
+
# Every component a run record may name. ``search`` is the web search service runs recorded
|
|
37
|
+
# while the stack could install it (stack_run.SEARCH): their records stay readable.
|
|
37
38
|
COMPONENTS = frozenset(
|
|
38
39
|
{
|
|
39
40
|
"tools",
|
|
@@ -117,7 +117,6 @@ class _OptionsSince20261022(TypedDict, total=False):
|
|
|
117
117
|
offline: bool # since 2026-10-24: pins from the catalog, no Hub request, at plan and apply
|
|
118
118
|
slots: int # concurrent sequences on the LLM's unified KV (agent posture); default 2
|
|
119
119
|
tts: bool # since 2026-10-27: the opt-in debug TTS joins the auxiliaries; default off
|
|
120
|
-
search: bool # since 2026-10-31: False leaves out the free web search; absent: planned
|
|
121
120
|
defer_services: bool # foundation services install independently of Runtime readiness
|
|
122
121
|
gpu: int # since 2026-10-28: the card for the LLM and the decision model; absent: auto
|
|
123
122
|
# Since 2026-10-31: the auxiliary tasks `--aux` named, in AUX_TASKS order; absent: all of
|
|
@@ -431,7 +430,6 @@ def default_options() -> StackOptions:
|
|
|
431
430
|
"offline": False,
|
|
432
431
|
"slots": 2,
|
|
433
432
|
"tts": False,
|
|
434
|
-
"search": False,
|
|
435
433
|
"reasoning_budget": REASONING_BUDGET,
|
|
436
434
|
"gateway": default_gateway(),
|
|
437
435
|
"vision": vision.DEFAULT,
|
|
@@ -441,7 +439,7 @@ def default_options() -> StackOptions:
|
|
|
441
439
|
def gateway_lines(plan: StackPlan) -> list[str]:
|
|
442
440
|
"""The plan summary's gateway lines: what is registered where, the routed model pi gets, and
|
|
443
441
|
each native client whose default changes."""
|
|
444
|
-
from localmodels import gateway_clients
|
|
442
|
+
from localmodels import gateway_clients
|
|
445
443
|
|
|
446
444
|
gw = plan["harness"]["gateway"]
|
|
447
445
|
aux_providers = [
|
|
@@ -460,7 +458,6 @@ def gateway_lines(plan: StackPlan) -> list[str]:
|
|
|
460
458
|
+ (" (tiered by the decision model)" if gw["decision"] else "")
|
|
461
459
|
if bifrost
|
|
462
460
|
else f", routing group group/{gw['group']}"
|
|
463
|
-
+ gateway_search.summary(plan.get("aux", []))
|
|
464
461
|
)
|
|
465
462
|
+ f"; pi default model {gw['pi_model_before'] or 'not set'} → {gw['pi_model']}"
|
|
466
463
|
]
|
|
@@ -187,11 +187,7 @@ def add(
|
|
|
187
187
|
|
|
188
188
|
|
|
189
189
|
def reads_images(part: Plan) -> bool:
|
|
190
|
-
return vision.reads_pictures(part["launch"])
|
|
191
|
-
None,
|
|
192
|
-
"",
|
|
193
|
-
"off",
|
|
194
|
-
)
|
|
190
|
+
return vision.reads_pictures(part["launch"])
|
|
195
191
|
|
|
196
192
|
|
|
197
193
|
def _target_vram(facts: HostFacts, placement: str, primary: Plan) -> int:
|