@simplexai/localmodels-linux-x64 0.1.0-dev.51 → 0.1.0-dev.52

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 (22) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +21 -21
  3. package/modules/localmodels/__init__.py +1 -1
  4. package/modules/localmodels/catalog_recipes.py +47 -8
  5. package/modules/localmodels/contracts.py +96 -37
  6. package/modules/localmodels/engines.py +18 -2
  7. package/modules/localmodels/gateway_bifrost.py +9 -0
  8. package/modules/localmodels/library_gateway.py +115 -0
  9. package/modules/localmodels/library_poly.py +58 -0
  10. package/modules/localmodels/source_cli.py +9 -1
  11. package/modules/localmodels/stack.py +0 -5
  12. package/modules/localmodels/stack_binding.py +6 -2
  13. package/modules/localmodels/stack_plan.py +3 -2
  14. package/modules/localmodels/suite.py +19 -7
  15. package/modules/{simplex_localmodels-0.1.0.dev51.dist-info → simplex_localmodels-0.1.0.dev52.dist-info}/METADATA +1 -1
  16. package/modules/{simplex_localmodels-0.1.0.dev51.dist-info → simplex_localmodels-0.1.0.dev52.dist-info}/RECORD +18 -18
  17. package/package.json +1 -1
  18. package/tool.json +1 -1
  19. /package/modules/{simplex_localmodels-0.1.0.dev51.dist-info → simplex_localmodels-0.1.0.dev52.dist-info}/WHEEL +0 -0
  20. /package/modules/{simplex_localmodels-0.1.0.dev51.dist-info → simplex_localmodels-0.1.0.dev52.dist-info}/entry_points.txt +0 -0
  21. /package/modules/{simplex_localmodels-0.1.0.dev51.dist-info → simplex_localmodels-0.1.0.dev52.dist-info}/licenses/NOTICE +0 -0
  22. /package/modules/{simplex_localmodels-0.1.0.dev51.dist-info → simplex_localmodels-0.1.0.dev52.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -1 +1 @@
1
- linux-x64 e6e8e77b5f87413272de2f649fd992006689f823 0.1.0.dev51 python/bin/python3.12 modules
1
+ linux-x64 6bd2c899cd22f98ffddb5e85618ce87fec73dacd 0.1.0.dev52 python/bin/python3.12 modules
package/bootstrap.sha256 CHANGED
@@ -1,7 +1,7 @@
1
- 976d45f5f7f64fed3bd3bf203363a35e693a6c79ead99a47e1dc58405903c3ba bootstrap.identity
1
+ ccc3ef967bdd20cbbf10686184f74cc3f9a318c9db41c5559a903c78e5b39579 bootstrap.identity
2
2
  15f49306ae54bb208f5a65763f59522a9193d5b01b31279c9bab116bba7ffe5c kit.py
3
3
  821556e6336796450ab852d375117b48a4887e71d255794fd6318d99982a5ab6 modules/localmodels/HERMES-LICENSE
4
- fae3ab64e3aa03e244514b2aed39da191c7cc886a09ff0ee85bb3d655821b9ad modules/localmodels/__init__.py
4
+ 9461cd61ab1d80a47fe953e442eda2e4c101a8bdca188098eb940688fe362662 modules/localmodels/__init__.py
5
5
  621e43ff0982247fb512979ef5d26d0b8c12f5d058669fd10dc220f2b6e92779 modules/localmodels/__main__.py
6
6
  d58431790b752ed9c5819872e8a237c49d3c0e15d8b5b4d4be24a61e504d4a56 modules/localmodels/app.py
7
7
  411de68b0ef44694442bacbe20cb4be1e3e4f29f6d533fdc8192174f15e57243 modules/localmodels/approval.py
@@ -23,7 +23,7 @@ e1666d11575ac2590e7c92cdc1751de78633cb3c410698db7d5a06c46b1bfcbc modules/localm
23
23
  1e3f37817db776704e92576c8c04bbc1bd47b8bc4d32e8609c72acb4bcd82f58 modules/localmodels/catalog.py
24
24
  969006f2f57c8d5f454d84e6d9589d925219da92f75696add3cbd0497c9e8726 modules/localmodels/catalog_add.py
25
25
  eef0cd1dc8df8b9606b434585ca26d027a4d52927c005d8d822ccd08d9bc9406 modules/localmodels/catalog_license.py
26
- d7925e184dacefc15ba465151781c67d7266b1771057ba548851b86c44185643 modules/localmodels/catalog_recipes.py
26
+ 655c0e50ebbbb4b63866f310b2c8fcf19f8d88323af8dd9215139c39855f03ae modules/localmodels/catalog_recipes.py
27
27
  962a1b38405afa335fe5ce74d8f496f60cafac9678c7f9c84dca399c92700cf2 modules/localmodels/chat_template.py
28
28
  ee4884b3b976b3d31b47e33420fdb29a324f12058a4436178690044e43eab96b modules/localmodels/chat_templates/qwen3.8-27b.jinja
29
29
  5e011976073062e9ad423e383b51ebd257be13c64aa903de5fe8799bc5d7230d modules/localmodels/cli_help.py
@@ -31,7 +31,7 @@ b1c7d13ac7f1e8536437179669e74a5247a972e42691b4de9ece2a1e719a64e0 modules/localm
31
31
  8242cc85bc75504c12037a135b2e5ddc0d560fbbc87c0e99140e40e4e15efc8c modules/localmodels/component.py
32
32
  42bbe61e8d4e57ae401b12d5b698e0b39c499b77e0882f2f27ff14cfd6ba2c42 modules/localmodels/console.py
33
33
  72c744f3923a305123572cd335f19735dbc237f092e5e44240f531c817d2f81d modules/localmodels/context_policy.py
34
- e01d7d20d6a3e61328569598a022ada7ed45f67a19e064297112a0b8dad8ef84 modules/localmodels/contracts.py
34
+ 04a8a80c7436614dc7705e378318d9773647b7175bedba5936bb777b26234f13 modules/localmodels/contracts.py
35
35
  6f3a13d048eea5d67bee8dbc760b07623fa81557824d72353c86f7043d223309 modules/localmodels/debug_cli.py
36
36
  29825ac5e66ec163c21e668ee4ea369c18a0933c1b1298e629f01add64c2d6c4 modules/localmodels/debug_mode.py
37
37
  10b9fe767087740931cb3698d864872692d772a7455cc575dc0a7f5c1fb24702 modules/localmodels/debug_stub_server.py
@@ -52,7 +52,7 @@ ae497546f518e6c8f99d2e7e051487a0c94c1df83e4acf4ed3aeb68f12eae21b modules/localm
52
52
  970143361bcc272a3e5547f947f3f5588878dce4262582b3b4a242a16fafd9e6 modules/localmodels/engines-strata-poly-0.2.20-poly.1.json
53
53
  fade27ca119b66aeeb80d36a2af6e192ccb7d4dc8d6bedbc7a9a354e5b55092d modules/localmodels/engines-whisper-b5454.json
54
54
  f83b086fb074f5487b1498dffbe25ac9a2324cfbbfe83d4f42a238a0fa0dd526 modules/localmodels/engines.json
55
- 57e9cbee0e53f8e2c62ad13fa7605ed42df49199c0a492429918515a9f207aaf modules/localmodels/engines.py
55
+ 20b2990d906cbec543cf8dcb2d235c96edc45211bfced8cba65d8c15054f7afd modules/localmodels/engines.py
56
56
  28fa1f7d466184a5f98ad29740d2003d51e776d25260823754aabcb4b46b0819 modules/localmodels/estimator.py
57
57
  59dfb9a4acb36fe2a2affc14bacbee2920ff435cb13cc314a08c13f66ba7860e modules/localmodels/fixtures/jfk.wav
58
58
  7a49e928bb35cb2ae70a4c1288ce371b381f52b3ed2e64a36f58006a0c741a0d modules/localmodels/fixtures/stack-research-demo-plan.json
@@ -61,7 +61,7 @@ fff4343321a2cb00d759d4afcf2fda0559736f7abd02c130b8920cc732c6fd4b modules/localm
61
61
  d32bd8b2802b338d37d3cb7bd42fe1d33c0d955af5f9b02fa67f9c35a3a8859b modules/localmodels/gateway_accept.py
62
62
  977a5a05dd792a61b81b2a12326257d9b83d3fe4355fa5cffbae3dd756ff81c4 modules/localmodels/gateway_admin.py
63
63
  d494471dc8c1733be3bee92ad5305f8e0ce4c7f333b29c59ec2ceb3dc6c2ff15 modules/localmodels/gateway_app_bifrost.py
64
- 215d18bc0962b97f805024f155062eabf6c2ec8336ad4787424f627fda079240 modules/localmodels/gateway_bifrost.py
64
+ 75861a29bd027910d9f275a9afd294d3b7655d297c16b3d3e8f89d5b52a5f215 modules/localmodels/gateway_bifrost.py
65
65
  edfcae45788203bf2aecfd1aeb679303444ab9f7ea7924d35ce996b10892cc24 modules/localmodels/gateway_cli.py
66
66
  c1a5228bc8463087a975fedc917f3e0e5a92149ba2e7bf3d490e7ce7331de65c modules/localmodels/gateway_clients.py
67
67
  382d7410df8d09f69172c362478efeef5bacb079b7cd5ccd0371650c08fafc51 modules/localmodels/gateway_foundations.py
@@ -89,10 +89,10 @@ ec5614a8c16f13866d25ed907647296c81a29d20ca7eb74933ce802bc4b6c3b6 modules/localm
89
89
  639d1e31d09603cbd64c90748f981b185476611dc266e574388faac9e4f78b9e modules/localmodels/library_cli.py
90
90
  38fa164918f3bc5ed1f0c7dd90fa2ad087bee44d79aa1a1966de41738a3af117 modules/localmodels/library_convert.py
91
91
  0df6a5a32e3da198768efed25f9fd4c98b2d2a69db5ea3fe4c42c4212a670192 modules/localmodels/library_floor.py
92
- 11f1cab6c83a44b1d629e169122cdd8e5d7ccadb6a6b2a3b0ac3fae883f61804 modules/localmodels/library_gateway.py
92
+ 7c11cb38cc0e3f1a0d174f61e6b18f9e231fa81fb7052f16e621f22dff5b3547 modules/localmodels/library_gateway.py
93
93
  d58b1e61c92b8d6af893b35ea60821c9f0be9ff825199b9cdfd191a754eca1e4 modules/localmodels/library_jobs.py
94
94
  179d097332903b85da0bb79edc36417df361bcae8d7d6fe91c37f3c8df3ab48e modules/localmodels/library_model.py
95
- a602329c5d66d4f2ecf49ee362af3568400b4b5023b6d86f2c82da63ad4c3ddd modules/localmodels/library_poly.py
95
+ 79aabc278bce37b073a49bbc845dd9acd352fe7a92fed23a6f2c34355e5ace45 modules/localmodels/library_poly.py
96
96
  6189dc1d8a7acd0eda62ada88a91ee61a06f250b29e5f066f65ce8e678380b4c modules/localmodels/library_pricing.py
97
97
  c2b7eb40d29f9311f840ea0a58976e0ae0c5e8846508b886a6d2115f2e433f6f modules/localmodels/library_serve.py
98
98
  bf9cee40547d79915ad89b7e23dfe839872ad64e61905b88f98ac7f9f0c1371e modules/localmodels/library_state.py
@@ -167,13 +167,13 @@ ae907b9ea8b6cd729266750ca0bdf5d1deefc9fce9c685521fe9a5576ed524eb modules/localm
167
167
  77247b3d4e8fe49a20bc29548fa999f95d40db4c08f17baf218e177783c52f4d modules/localmodels/slot_cache.py
168
168
  1c774a5cc27dfec9efb696580915b02876609a1d046e5458d1078109afd61625 modules/localmodels/source_byok.py
169
169
  fc51f2a5814159fedf7a5c9e52f181adc65bf7bcb7d6e7a7f987b71cd22a4f09 modules/localmodels/source_byok_probe.py
170
- 258fa1dbacda0d70ebe6a61e41b7390b2decdc8b9644322eeb8bcdcf23113e68 modules/localmodels/source_cli.py
171
- 3e221a7b4dfb18ff0f5698eec8c72d29a552965f23ad411ce59bebb9e8d00cf9 modules/localmodels/stack.py
170
+ e161aa5bed4df6d564b982be9fb2d7f7fb3c30c70df3622f2ed3b99da170b83c modules/localmodels/source_cli.py
171
+ 1f78ae7a6c8a333196dd30b7ec355b9b084ffffe3e103d2a9fb34d2089741ef3 modules/localmodels/stack.py
172
172
  4050964f9be097eeb4576486af02d57eb157ffa21cf71aaca88592036327f166 modules/localmodels/stack_arena.py
173
173
  7552531dd59454e29e548a70b6c33390559b4a2000fa5814deb424ae19657de5 modules/localmodels/stack_args.py
174
174
  c6730c6e437644b550225b0f9cffc9448ac20f2cdcd935350c2853c9e2ea4a71 modules/localmodels/stack_auto.py
175
175
  3a038bcdcf5954c0daad0d619153ab1c9d9083904c9f73bae1733fc667cf1992 modules/localmodels/stack_aux_gpu.py
176
- 46c06dcec00cd710632c444d6975e9b105d3c73793bdd6c99eb749509d17929c modules/localmodels/stack_binding.py
176
+ 64988f34df98af4da439a17c1da6b5706f6a3f69c6d39283dc7e3981daa0fb67 modules/localmodels/stack_binding.py
177
177
  16570ee078cbe3fb1bfaa3a26a14ec203c322e62e3894b9ecfd922f9f5092d19 modules/localmodels/stack_capacity.py
178
178
  edc0e7d2b168e6a5a11f565cadb268f72dba4de261cfa7cb3c14f671ef0c29df modules/localmodels/stack_card.py
179
179
  e6364b4fa45c5f2234b9213736711a4e303f455444762b916d75b8353b804666 modules/localmodels/stack_cleanup.py
@@ -198,7 +198,7 @@ a690c3d68aa60a6cbcd3202b96187d2cb37b3b869740870dce51790040049068 modules/localm
198
198
  a4e4c64fec78dd463eab69fb90e3ce534c6f3c2abe97fb8ea5ca187620ad885e modules/localmodels/stack_memory.py
199
199
  73c85d9b48e14871106775b41ac4ddb01842879108675eed8712529ed89edbae modules/localmodels/stack_mlx.py
200
200
  0f00c61ca52d2c688ced1220f56ee824ecb4df99c4f204f8144120a1e3535425 modules/localmodels/stack_picks.py
201
- c83798c51a2a069484550f4fde6b92fe9c4678e0e086e7bbb19bdfdf5ce8306c modules/localmodels/stack_plan.py
201
+ 0e53fc79a59cc4da46246a42b3490574adc2b2fdfa5ea2ea71fee0e13b302daa modules/localmodels/stack_plan.py
202
202
  b33413954b9ffef629bf9f7bafc59d5761a58f45b28c6ce0cd638103e5cffbc4 modules/localmodels/stack_ports.py
203
203
  84eecf29fec533ea16f3447db9099aaa281d888c1c4b186fa84c25d76c508168 modules/localmodels/stack_preflight.py
204
204
  036065514fa52129efd8ea08356f7382649efb76aedd00655ff64fbdede45d28 modules/localmodels/stack_progress.py
@@ -243,7 +243,7 @@ aa2496ee31f531000907de70ff117909d24c07d989b7315d429a648350a97eba modules/localm
243
243
  f3d38c36851d44341fe02f93ad1a7d6c469d1f51f1fa6df1f1b6656864ea6ada modules/localmodels/strata-poly-serve-0.2.19-poly.1.txt
244
244
  94158929dcf13d1e189b8e552ae3f646fc484767e4d47eecf2c37cbf47130816 modules/localmodels/strata-poly-serve-0.2.20-poly.1.txt
245
245
  c9a84cfa4e4dfad81510fc6f111c7db76929d566cd96c49fafdc5f8e5447f5b1 modules/localmodels/strata_poly_server.py
246
- 8a4299b295f2ca7979a92ab99ea7d1d0d3a4a718afc6c19a2ae422ddf32ec772 modules/localmodels/suite.py
246
+ b9462839aa5bb336a31afa263dffe06028eb0ce4ab468ef723f4e91f378cb80f modules/localmodels/suite.py
247
247
  22be2d2d6303c7714503bbe72d5d4788eb070b9939f6ec81ebd947eb45f53f8b modules/localmodels/tool_archive.py
248
248
  3fc53d0e9ae000e7b8e81b4a14a1e3627c366517ebd39da22aedaa81dfbafd25 modules/localmodels/tools.json
249
249
  2fb2de6cb840f2a19f90dafb3d649ff741978ba71349a6c7d112e641a79ac338 modules/localmodels/transport.py
@@ -274,13 +274,13 @@ f79c861df0b16c8cd05872d88f1fc2910023336519131671a0cd64cb490af17e modules/localm
274
274
  1f24f15ba0c87178716d1552484be55a6a775231f4468fc95c4177f6dffbd081 modules/localmodels/web/view/view.js
275
275
  84535ea1c54aeb68bfbfbe357b7f19e7a2d69b9ce9ff2f4f7e8b6a668f76eb3f modules/localmodels/win_probe.py
276
276
  d3be4542d9b3f32a61bc65cc4264a74301b0eab6f302a30f43e878e9e9b228d6 modules/localmodels/windows_job.py
277
- 71c0668d6ed053ed9c3bf92a46cd0c7329389cab0bd5dc19da379d5bc52d47ed modules/simplex_localmodels-0.1.0.dev51.dist-info/METADATA
278
- d1d891874889170f098c43ac2e042976e40d537a39ecb19a351d3d4d0eb721e4 modules/simplex_localmodels-0.1.0.dev51.dist-info/RECORD
279
- d5d0ff1a812a108c50ed59eb504c60763fde1316386f85207d1d2206518a55a7 modules/simplex_localmodels-0.1.0.dev51.dist-info/WHEEL
280
- 3a3059212ac60178113110eaaeafa6dbafe72c598d64d3616cbb498ae9c881f7 modules/simplex_localmodels-0.1.0.dev51.dist-info/entry_points.txt
281
- b57710affc4ca11c13057cf73ff661bcd50fba0455d2ebe0e23b40cb11c5a6eb modules/simplex_localmodels-0.1.0.dev51.dist-info/licenses/NOTICE
282
- 821556e6336796450ab852d375117b48a4887e71d255794fd6318d99982a5ab6 modules/simplex_localmodels-0.1.0.dev51.dist-info/licenses/localmodels/HERMES-LICENSE
283
- 7224f17b3ef37c8fdfc2db201e966ac129c3a18b09c1c5800ec83302d94caf6c package.json
277
+ 5e4d7a4e78a362ca31b1e15c140b390bfd822e0230e26f6e5576f623f863b4ab modules/simplex_localmodels-0.1.0.dev52.dist-info/METADATA
278
+ ed68ed46a22a5cbc1397e7969b9ea87d1f33bc4eb56e1977f4fea06880ff54d2 modules/simplex_localmodels-0.1.0.dev52.dist-info/RECORD
279
+ d5d0ff1a812a108c50ed59eb504c60763fde1316386f85207d1d2206518a55a7 modules/simplex_localmodels-0.1.0.dev52.dist-info/WHEEL
280
+ 3a3059212ac60178113110eaaeafa6dbafe72c598d64d3616cbb498ae9c881f7 modules/simplex_localmodels-0.1.0.dev52.dist-info/entry_points.txt
281
+ b57710affc4ca11c13057cf73ff661bcd50fba0455d2ebe0e23b40cb11c5a6eb modules/simplex_localmodels-0.1.0.dev52.dist-info/licenses/NOTICE
282
+ 821556e6336796450ab852d375117b48a4887e71d255794fd6318d99982a5ab6 modules/simplex_localmodels-0.1.0.dev52.dist-info/licenses/localmodels/HERMES-LICENSE
283
+ 954e44925089012b68ed88e3f7e05da13c161ecdba3a8f8be6db3f8320cb9b84 package.json
284
284
  23bc148d2b48964b621c5561ff2b81c1d9c7b717967a7491efbf12f4304882b5 python/bin/python3.12
285
285
  3b2f81fe21d181c499c59a256c8e1968455d6689d269aa85373bfb6af41da3bf python/lib/python3.12/LICENSE.txt
286
286
  981d4c398849f9ebcab72300d9c1fe288fd6d7f28957b3b3fa3a493a5836d95c python/lib/python3.12/__future__.py
@@ -4245,4 +4245,4 @@ df828a376c73cadc0f03b447cdcde54d4a552b10bfd51bf1349d95ae27760155 python/share/t
4245
4245
  4908bd229176dcb81a0c54e087cc725040988babad9e806a5052fb722cf5b511 python/share/terminfo/z/ztx
4246
4246
  4908bd229176dcb81a0c54e087cc725040988babad9e806a5052fb722cf5b511 python/share/terminfo/z/ztx-1-a
4247
4247
  4908bd229176dcb81a0c54e087cc725040988babad9e806a5052fb722cf5b511 python/share/terminfo/z/ztx11
4248
- d7a08c70518f2b33d8f64e59a5b26a52dd7a714dac197a9dc2e27328a856f452 tool.json
4248
+ 782852b304a166f5b08e4f0a74a1fcefe88dbfcd447921d738b8cdb2ac04f2b5 tool.json
@@ -3,4 +3,4 @@
3
3
  See docs/local-models/architecture.md.
4
4
  """
5
5
 
6
- __version__ = "0.1.0.dev51"
6
+ __version__ = "0.1.0.dev52"
@@ -3,6 +3,7 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import base64
6
+ import copy
6
7
  import json
7
8
  import re
8
9
  from pathlib import Path
@@ -214,11 +215,38 @@ class DecisionRecipe(LlamaComponentRecipe, _DecisionOptional):
214
215
  cons: list[str]
215
216
 
216
217
 
218
+ _COMPONENTS_CACHE: dict[
219
+ Path,
220
+ tuple[
221
+ int,
222
+ int,
223
+ list[ComponentRecipe],
224
+ dict[str, list[LlamaComponentRecipe]],
225
+ list[DecisionRecipe] | None,
226
+ ],
227
+ ] = {}
228
+
229
+
230
+ def _components_entry() -> tuple[
231
+ list[ComponentRecipe], dict[str, list[LlamaComponentRecipe]], list[DecisionRecipe] | None
232
+ ]:
233
+ resolved = CATALOG_PATH.resolve()
234
+ stat = resolved.stat()
235
+ cached = _COMPONENTS_CACHE.get(resolved)
236
+ if cached is not None and cached[0] == stat.st_mtime_ns and cached[1] == stat.st_size:
237
+ return cached[2], cached[3], cached[4]
238
+ raw = json.loads(resolved.read_text(encoding="utf-8"))
239
+ all_components = decode(raw.get("components", []), list[ComponentRecipe])
240
+ by_task: dict[str, list[LlamaComponentRecipe]] = {}
241
+ _COMPONENTS_CACHE[resolved] = (stat.st_mtime_ns, stat.st_size, all_components, by_task, None)
242
+ return all_components, by_task, None
243
+
244
+
217
245
  def components() -> list[ComponentRecipe]:
218
246
  """Every task recipe in catalog order. Task recipes share the catalog, but never enter the
219
247
  GGUF recommender."""
220
- raw = json.loads(CATALOG_PATH.read_text(encoding="utf-8"))
221
- return decode(raw.get("components", []), list[ComponentRecipe])
248
+ all_components, _, _ = _components_entry()
249
+ return copy.deepcopy(all_components)
222
250
 
223
251
 
224
252
  def component_recipe(model_id: str) -> ComponentRecipe:
@@ -227,16 +255,27 @@ def component_recipe(model_id: str) -> ComponentRecipe:
227
255
 
228
256
  def llama_components(task: str) -> list[LlamaComponentRecipe]:
229
257
  """llama-server task components in catalog order (the first is the default)."""
230
- return [
231
- decode(recipe, LlamaComponentRecipe)
232
- for recipe in components()
233
- if recipe["task"] == task and recipe["runtime"] in ("llama.cpp-cpu", "llama.cpp")
234
- ]
258
+ all_components, by_task, _ = _components_entry()
259
+ found = by_task.get(task)
260
+ if found is None:
261
+ found = [
262
+ decode(recipe, LlamaComponentRecipe)
263
+ for recipe in all_components
264
+ if recipe["task"] == task and recipe["runtime"] in ("llama.cpp-cpu", "llama.cpp")
265
+ ]
266
+ by_task[task] = found
267
+ return copy.deepcopy(found)
235
268
 
236
269
 
237
270
  def decision_components() -> list[DecisionRecipe]:
238
271
  """Jev-like decision models in catalog order."""
239
- return [decode(recipe, DecisionRecipe) for recipe in llama_components("decision")]
272
+ resolved = CATALOG_PATH.resolve()
273
+ all_components, by_task, decisions = _components_entry()
274
+ if decisions is None:
275
+ decisions = [decode(recipe, DecisionRecipe) for recipe in llama_components("decision")]
276
+ cached = _COMPONENTS_CACHE[resolved]
277
+ _COMPONENTS_CACHE[resolved] = (cached[0], cached[1], all_components, by_task, decisions)
278
+ return copy.deepcopy(decisions)
240
279
 
241
280
 
242
281
  _REQUIRED_PROVENANCE = ("license", "license_url", "status", "tasks", "evidence")
@@ -4,9 +4,11 @@ from __future__ import annotations
4
4
 
5
5
  import functools
6
6
  import types
7
+ from collections.abc import Callable
7
8
  from typing import Any, TypeVar, Union, cast, get_args, get_origin, get_type_hints, is_typeddict
8
9
 
9
10
  T = TypeVar("T")
11
+ _Validator = Callable[[object, str], None]
10
12
 
11
13
 
12
14
  @functools.cache
@@ -18,57 +20,114 @@ def _record_fields(schema: Any) -> tuple[frozenset[str], tuple[tuple[str, object
18
20
  )
19
21
 
20
22
 
21
- def decode(value: object, schema: type[T]) -> T:
22
- """Reject malformed external data before it reaches typed application code.
23
+ def _validate_object(_value: object, _path: str) -> None:
24
+ return None
23
25
 
24
- Unknown object fields are retained for forward compatibility. Error messages
25
- contain field names and types, never values (facts may contain private data).
26
- """
27
- _validate(value, schema, "$")
28
- return cast(T, value)
29
26
 
27
+ def _validate_float(value: object, path: str) -> None:
28
+ kind = type(value)
29
+ if kind is not float and kind is not int:
30
+ raise ValueError(f"{path}: unexpected type")
30
31
 
31
- def _validate(value: object, schema: object, path: str) -> None:
32
- origin, args = get_origin(schema), get_args(schema)
33
- if schema is object:
34
- return
35
- if origin in (Union, types.UnionType):
36
- for option in args:
32
+
33
+ def _exact_validator(schema: type[object]) -> _Validator:
34
+ def check_exact(value: object, path: str) -> None:
35
+ if type(value) is not schema:
36
+ raise ValueError(f"{path}: unexpected type")
37
+
38
+ return check_exact
39
+
40
+
41
+ def _union_validator(args: tuple[object, ...]) -> _Validator:
42
+ options = tuple(_compile(option) for option in args)
43
+
44
+ def check_union(value: object, path: str) -> None:
45
+ for option in options:
37
46
  try:
38
- _validate(value, option, path)
47
+ option(value, path)
39
48
  return
40
49
  except ValueError:
41
50
  pass
42
51
  raise ValueError(f"{path}: unexpected type")
43
- if is_typeddict(schema):
44
- _validate_record(value, schema, path)
45
- return
46
- if origin is list:
52
+
53
+ return check_union
54
+
55
+
56
+ def _record_validator(schema: object) -> _Validator:
57
+ required, raw_fields = _record_fields(schema)
58
+ compiled_fields = tuple((key, _compile(field)) for key, field in raw_fields)
59
+
60
+ def check_record(value: object, path: str) -> None:
61
+ if not isinstance(value, dict):
62
+ raise ValueError(f"{path}: expected object")
63
+ for key, check_field in compiled_fields:
64
+ if key in value:
65
+ check_field(value[key], f"{path}.{key}")
66
+ elif key in required:
67
+ raise ValueError(f"{path}.{key}: missing field")
68
+
69
+ return check_record
70
+
71
+
72
+ def _list_validator(item_schema: object) -> _Validator:
73
+ check_item = _compile(item_schema)
74
+
75
+ def check_list(value: object, path: str) -> None:
47
76
  if not isinstance(value, list):
48
77
  raise ValueError(f"{path}: expected array")
78
+ item_path = f"{path}[]"
49
79
  for item in value:
50
- _validate(item, args[0], f"{path}[]")
51
- return
52
- if origin is dict:
80
+ check_item(item, item_path)
81
+
82
+ return check_list
83
+
84
+
85
+ def _dict_validator(key_schema: object, val_schema: object) -> _Validator:
86
+ check_key, check_val = _compile(key_schema), _compile(val_schema)
87
+
88
+ def check_dict(value: object, path: str) -> None:
53
89
  if not isinstance(value, dict):
54
90
  raise ValueError(f"{path}: expected object")
91
+ val_path = f"{path}.*"
55
92
  for key, item in value.items():
56
- _validate(key, args[0], path)
57
- _validate(item, args[1], f"{path}.*")
58
- return
59
- if isinstance(schema, type) and (
60
- type(value) is schema or schema is float and type(value) is int
61
- ):
62
- return
93
+ check_key(key, path)
94
+ check_val(item, val_path)
95
+
96
+ return check_dict
97
+
98
+
99
+ def _reject_value(_value: object, path: str) -> None:
63
100
  raise ValueError(f"{path}: unexpected type")
64
101
 
65
102
 
66
- def _validate_record(value: object, schema: object, path: str) -> None:
67
- if not isinstance(value, dict):
68
- raise ValueError(f"{path}: expected object")
69
- required, fields = _record_fields(schema)
70
- for key, field in fields:
71
- if key in value:
72
- _validate(value[key], field, f"{path}.{key}")
73
- elif key in required:
74
- raise ValueError(f"{path}.{key}: missing field")
103
+ @functools.cache
104
+ def _compile(schema: object) -> _Validator:
105
+ """Compile a reusable validator for ``schema`` so hot decodes skip typing introspection."""
106
+ if schema is object:
107
+ return _validate_object
108
+ if schema is float:
109
+ return _validate_float
110
+ if schema in (str, int, bool, type(None)):
111
+ return _exact_validator(cast(type[object], schema))
112
+ origin, args = get_origin(schema), get_args(schema)
113
+ if origin in (Union, types.UnionType):
114
+ return _union_validator(args)
115
+ if is_typeddict(schema):
116
+ return _record_validator(schema)
117
+ if origin is list:
118
+ return _list_validator(args[0])
119
+ if origin is dict:
120
+ return _dict_validator(args[0], args[1])
121
+ if isinstance(schema, type):
122
+ return _exact_validator(schema)
123
+ return _reject_value
124
+
125
+
126
+ def decode(value: object, schema: type[T]) -> T:
127
+ """Reject malformed external data before it reaches typed application code.
128
+
129
+ Unknown object fields are retained for forward compatibility. Error messages
130
+ contain field names and types, never values (facts may contain private data).
131
+ """
132
+ _compile(cast(Any, schema))(value, "$")
133
+ return cast(T, value)
@@ -11,6 +11,7 @@ supports every option the plan uses. ``build_number`` (catalog.py) is the one pa
11
11
 
12
12
  from __future__ import annotations
13
13
 
14
+ import copy
14
15
  import json
15
16
  import os
16
17
  import re
@@ -77,12 +78,26 @@ def engine_lock_path(tag: str | None = None) -> Path:
77
78
  return ENGINE_LOCK if tag is None else ENGINE_LOCK.with_name(f"engines-{tag}.json")
78
79
 
79
80
 
81
+ _ENGINE_LOCK_CACHE: dict[Path, tuple[int, int, EngineLock]] = {}
82
+
83
+
84
+ def _load_engine_lock(lock_path: Path) -> EngineLock:
85
+ resolved = lock_path.resolve()
86
+ stat = resolved.stat()
87
+ cached = _ENGINE_LOCK_CACHE.get(resolved)
88
+ if cached is not None and cached[0] == stat.st_mtime_ns and cached[1] == stat.st_size:
89
+ return cached[2]
90
+ lock = decode(json.loads(resolved.read_text(encoding="utf-8")), EngineLock)
91
+ _ENGINE_LOCK_CACHE[resolved] = (stat.st_mtime_ns, stat.st_size, lock)
92
+ return lock
93
+
94
+
80
95
  def select_engine_build(
81
96
  facts: HostFacts, backend: str, lock_path: Path = ENGINE_LOCK
82
97
  ) -> SelectedBuild:
83
98
  """The pinned build for the host: newest CUDA build the driver supports, and among those
84
99
  the one needing the newest glibc the host has (upstream's own archive before a rebuild)."""
85
- lock = decode(json.loads(lock_path.read_text(encoding="utf-8")), EngineLock)
100
+ lock = _load_engine_lock(lock_path)
86
101
  platform = (
87
102
  "darwin"
88
103
  if facts.get("platform") == "darwin"
@@ -167,7 +182,8 @@ def select_engine_build(
167
182
  raise PlanError(
168
183
  f"no {lock['tag']} prebuilt engine for {platform}/{facts.get('arch')}/{backend}"
169
184
  )
170
- return {"tag": lock["tag"], "commit": lock["commit"], **builds[0]}
185
+ selected: SelectedBuild = {"tag": lock["tag"], "commit": lock["commit"], **builds[0]}
186
+ return copy.deepcopy(selected)
171
187
 
172
188
 
173
189
  def host_engine(
@@ -37,6 +37,7 @@ from localmodels.bifrost_config import DECISION_TIMEOUT as DECISION_TIMEOUT
37
37
  from localmodels.bifrost_config import FAST_PROVIDER as FAST_PROVIDER
38
38
  from localmodels.bifrost_config import LOG_BATCH_INTERVAL as LOG_BATCH_INTERVAL
39
39
  from localmodels.bifrost_config import STORE as STORE
40
+ from localmodels.bifrost_config import differs as _config_differs
40
41
  from localmodels.bifrost_config import read_config as read_config
41
42
  from localmodels.bifrost_config import render as render
42
43
  from localmodels.bifrost_config import render_config as render_config
@@ -65,6 +66,8 @@ PI_PROVIDER = "localmodels"
65
66
  PI_MODEL = f"{PI_PROVIDER}/{AGENT_MODEL}"
66
67
  CALLER_KEY = gateway_keys.CALLER_KEY # clients send it; loopback inference checks no key
67
68
  HEALTH_TIMEOUT_S = 180.0
69
+ # Windows cannot delete config.db while a running Bifrost holds it open: stop it before a change.
70
+ STOP_BEFORE_CONFIG_CHANGE = os.name == "nt"
68
71
 
69
72
 
70
73
  def plan_tools(
@@ -592,6 +595,12 @@ def wire(
592
595
  FAST_PROVIDER, (fast["model"], AGENT_MODEL), gw.get("context")
593
596
  )
594
597
  sheets[bifrost_datasheet.DATASHEET].update(extra[bifrost_datasheet.DATASHEET])
598
+ if (
599
+ STOP_BEFORE_CONFIG_CHANGE
600
+ and record["how"] != "unit"
601
+ and _config_differs(app, config, sheets)
602
+ ):
603
+ _stop_owned_serve(record)
595
604
  changed = _write_config(app, config, sheets)
596
605
  if changed or not _healthy_owned(record):
597
606
  _start(record, restart=changed)
@@ -409,6 +409,113 @@ def model_facts(model: str, entry: cat.CatalogEntry, plan: Plan) -> bifrost_mode
409
409
  }
410
410
 
411
411
 
412
+ def _pi_drop_magpie_provider(profile: Path) -> None:
413
+ """Remove a dead legacy ``magpie`` provider from ``models.json`` in our private profile."""
414
+ path = profile / "models.json"
415
+ try:
416
+ models = _read(path)
417
+ except LibraryError:
418
+ return
419
+ providers = models.get("providers")
420
+ if isinstance(providers, dict) and "magpie" in providers:
421
+ del providers["magpie"]
422
+ _write(path, models)
423
+
424
+
425
+ def _clear_legacy_magpie_pi_record(tools_dir: str) -> None:
426
+ """Drop an orphaned ``magpie/...`` pi ownership entry when transitioning to Bifrost."""
427
+
428
+ def clear(doc: hosts.Owned) -> None:
429
+ pi = doc.get("pi")
430
+ if pi and str(pi.get("model") or "").startswith("magpie/"):
431
+ doc["pi"] = None
432
+
433
+ with contextlib.suppress(OSError, ValueError):
434
+ hosts.update_owned(clear, tools_dir)
435
+
436
+
437
+ def _retire_legacy_magpie(tools_dir: str) -> bool:
438
+ """Undo owned Magpie wiring before moving pi onto Bifrost (WHI-973).
439
+
440
+ Returns True when this computer had owned Magpie wiring or a started Magpie gateway.
441
+ When Magpie was already stopped (for example by ``stack down``) or its earlier plan/binary
442
+ is unavailable, ``leave_magpie`` cannot invoke the Magpie CLI; we still proceed so Bifrost
443
+ registration and pi recovery succeed rather than leaving the user stuck on a dead port.
444
+ """
445
+ from localmodels import bifrost_clients, gateway_switch
446
+
447
+ doc = hosts.load_owned(tools_dir)
448
+ had_magpie = bool(
449
+ bifrost_clients.magpie_wired(doc)
450
+ or doc["gateway"]["started"]
451
+ or doc["gateway"].get("magpie")
452
+ )
453
+ if not had_magpie:
454
+ return False
455
+ try:
456
+ gateway_switch.leave_magpie(tools_dir)
457
+ except (harness.HarnessError, OSError, ValueError):
458
+ _clear_legacy_magpie_pi_record(tools_dir)
459
+ return True
460
+
461
+
462
+ def _sync_pi_default(
463
+ profile: Path,
464
+ pi_provider: str,
465
+ gateway_model: str,
466
+ *,
467
+ stack_provider: str | None,
468
+ retired_magpie: bool = False,
469
+ ) -> None:
470
+ """Keep pi's ``settings.json`` off a dead legacy ``magpie`` default (and restore the
471
+ Quick Install default when an adopted stack LLM is reloaded after ``unpoint_pi``).
472
+ Never overwrites a user-chosen non-magpie default."""
473
+ settings_path = profile / "settings.json"
474
+ try:
475
+ settings = _read(settings_path)
476
+ except LibraryError:
477
+ return
478
+ current_provider = settings.get("defaultProvider")
479
+ current_model = settings.get("defaultModel")
480
+ was_magpie = current_provider == "magpie" or (
481
+ not current_provider
482
+ and isinstance(current_model, str)
483
+ and current_model.startswith("magpie/")
484
+ )
485
+ if was_magpie or (stack_provider is not None and not current_model):
486
+ settings["defaultProvider"] = pi_provider
487
+ settings["defaultModel"] = gateway_model
488
+ _write(settings_path, settings)
489
+ if was_magpie or retired_magpie:
490
+ _pi_drop_magpie_provider(profile)
491
+
492
+
493
+ def reconcile_pi_default(registration: Registration) -> None:
494
+ """Ensure pi's private profile is not left pointing at a dead legacy Magpie gateway when
495
+ a loaded library model is active on Bifrost (WHI-973)."""
496
+ with gateway_locked():
497
+ if ensure_instance(None) is None:
498
+ return
499
+ tools_dir = hosts.tools_dir()
500
+ retired = _retire_legacy_magpie(tools_dir)
501
+ profile = pi_profile()
502
+ pi_provider = registration.get("pi_provider") or (
503
+ gateway_bifrost.PI_PROVIDER
504
+ if registration.get("kind") in ("stack", "agent")
505
+ else PI_PROVIDER
506
+ )
507
+ stack_provider = (
508
+ registration["provider"] if registration.get("kind") in ("stack", "agent") else None
509
+ )
510
+ _sync_pi_default(
511
+ profile,
512
+ pi_provider,
513
+ registration["model"],
514
+ stack_provider=stack_provider,
515
+ retired_magpie=retired,
516
+ )
517
+
518
+
412
519
  def _register(
413
520
  model: str,
414
521
  entry: cat.CatalogEntry,
@@ -449,11 +556,19 @@ def _register(
449
556
  try:
450
557
  if listed_as not in bifrost_models.listed(record["addr"]):
451
558
  raise _fail(f"Bifrost does not list {listed_as}")
559
+ retired_magpie = _retire_legacy_magpie(hosts.tools_dir())
452
560
  facts_ = model_facts(model, entry, plan)
453
561
  base = f"http://{record['addr']}"
454
562
  pi_entry = bifrost_models.pi_provider(facts_, gateway_model, base)["models"][0]
455
563
  if not shared: # the stack's own pi entry already names localmodels-agent
456
564
  _pi_add(pi_provider, pi_entry, base)
565
+ _sync_pi_default(
566
+ pi_profile(),
567
+ pi_provider,
568
+ gateway_model,
569
+ stack_provider=stack_provider,
570
+ retired_magpie=retired_magpie,
571
+ )
457
572
  except BaseException: # roll the gateway back to what it was before this call
458
573
  with contextlib.suppress(harness.HarnessError, OSError, ValueError, LibraryError):
459
574
  apply_config(record, before, before_sheet)