ltcai 11.1.0 → 11.4.0

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 (289) hide show
  1. package/README.md +47 -54
  2. package/docs/CHANGELOG.md +94 -0
  3. package/docs/COMMUNITY_AND_PLUGINS.md +1 -1
  4. package/docs/DEVELOPMENT.md +1 -1
  5. package/docs/FEATURE_AUDIT_v11.2.0.md +393 -0
  6. package/docs/LAYOUT_REBUILD_SPEC.md +9 -1
  7. package/docs/MULTI_AGENT_RUNTIME.md +1 -1
  8. package/docs/ONBOARDING.md +1 -1
  9. package/docs/OPERATIONS.md +6 -2
  10. package/docs/PERMISSION_MODE.md +1 -1
  11. package/docs/TRUST_MODEL.md +1 -1
  12. package/docs/WHY_LATTICE.md +1 -1
  13. package/docs/architecture.md +6 -2
  14. package/docs/kg-schema.md +2 -2
  15. package/docs/v11.3.0_PLAN.md +202 -0
  16. package/docs/v11.4.0_RUST_FOUNDATION_PLAN.md +176 -0
  17. package/lattice_brain/__init__.py +1 -1
  18. package/lattice_brain/gates.py +125 -0
  19. package/lattice_brain/graph/_kg_common/__init__.py +287 -0
  20. package/lattice_brain/graph/_kg_common/extraction.py +516 -0
  21. package/lattice_brain/graph/_kg_common/relations.py +161 -0
  22. package/lattice_brain/graph/_kg_common/text.py +479 -0
  23. package/lattice_brain/graph/discovery_index/__init__.py +35 -0
  24. package/lattice_brain/graph/discovery_index/cleanup.py +182 -0
  25. package/lattice_brain/graph/discovery_index/extract.py +137 -0
  26. package/lattice_brain/graph/discovery_index/scan.py +411 -0
  27. package/lattice_brain/graph/discovery_index/upsert.py +495 -0
  28. package/lattice_brain/graph/fusion.py +35 -4
  29. package/lattice_brain/graph/projection/__init__.py +42 -0
  30. package/lattice_brain/graph/projection/curation.py +500 -0
  31. package/lattice_brain/graph/{projection.py → projection/v2_schema.py} +81 -485
  32. package/lattice_brain/graph/retrieval/__init__.py +54 -0
  33. package/lattice_brain/graph/retrieval/context.py +197 -0
  34. package/lattice_brain/graph/retrieval/graph_view.py +319 -0
  35. package/lattice_brain/graph/retrieval/hybrid.py +488 -0
  36. package/lattice_brain/graph/retrieval/maintenance.py +121 -0
  37. package/lattice_brain/graph/retrieval/signals.py +95 -0
  38. package/lattice_brain/graph/retrieval_vector/__init__.py +42 -0
  39. package/lattice_brain/graph/retrieval_vector/fingerprint.py +97 -0
  40. package/lattice_brain/graph/retrieval_vector/indexing.py +347 -0
  41. package/lattice_brain/graph/retrieval_vector/search.py +560 -0
  42. package/lattice_brain/graph/retrieval_vector/status.py +374 -0
  43. package/lattice_brain/graph/schema.py +9 -0
  44. package/lattice_brain/graph/store.py +9 -0
  45. package/lattice_brain/graph/vector_index/selector.py +32 -2
  46. package/lattice_brain/ingestion/__init__.py +130 -0
  47. package/lattice_brain/ingestion/_contract.py +90 -0
  48. package/lattice_brain/ingestion/constants.py +127 -0
  49. package/lattice_brain/ingestion/folder_scan.py +57 -0
  50. package/lattice_brain/ingestion/folders.py +258 -0
  51. package/lattice_brain/ingestion/hashing.py +26 -0
  52. package/lattice_brain/ingestion/jobs_api.py +107 -0
  53. package/lattice_brain/ingestion/models.py +80 -0
  54. package/lattice_brain/ingestion/pipeline.py +486 -0
  55. package/lattice_brain/ingestion/quality.py +209 -0
  56. package/lattice_brain/ingestion/routing.py +295 -0
  57. package/lattice_brain/multimodal/__init__.py +164 -0
  58. package/lattice_brain/multimodal/audio.py +77 -0
  59. package/lattice_brain/multimodal/common.py +118 -0
  60. package/lattice_brain/{multimodal.py → multimodal/images.py} +22 -262
  61. package/lattice_brain/multimodal/ports.py +169 -0
  62. package/lattice_brain/multimodal/video.py +410 -0
  63. package/lattice_brain/portability/__init__.py +90 -0
  64. package/lattice_brain/portability/_contract.py +42 -0
  65. package/lattice_brain/portability/backups.py +338 -0
  66. package/lattice_brain/portability/bundles.py +136 -0
  67. package/lattice_brain/portability/constants.py +93 -0
  68. package/lattice_brain/portability/fsops.py +138 -0
  69. package/lattice_brain/portability/service.py +41 -0
  70. package/lattice_brain/portability/sharing.py +714 -0
  71. package/lattice_brain/runtime/__init__.py +1 -1
  72. package/lattice_brain/runtime/multi_agent.py +1 -1
  73. package/lattice_brain/sealed_box.py +244 -0
  74. package/lattice_brain/synthesis.py +24 -1
  75. package/latticeai/__init__.py +1 -1
  76. package/latticeai/api/brain_intelligence.py +4 -0
  77. package/latticeai/api/chat.py +11 -0
  78. package/latticeai/api/chat_helpers.py +16 -3
  79. package/latticeai/api/chat_hybrid.py +32 -1
  80. package/latticeai/api/chronicle.py +63 -0
  81. package/latticeai/api/features.py +70 -0
  82. package/latticeai/api/local_files.py +102 -0
  83. package/latticeai/api/portability.py +39 -4
  84. package/latticeai/api/review_queue.py +126 -0
  85. package/latticeai/api/search.py +16 -2
  86. package/latticeai/core/agent/__init__.py +93 -0
  87. package/latticeai/core/agent/_contract.py +79 -0
  88. package/latticeai/core/agent/context.py +57 -0
  89. package/latticeai/core/agent/deps.py +125 -0
  90. package/latticeai/core/agent/execution.py +622 -0
  91. package/latticeai/core/agent/planning.py +145 -0
  92. package/latticeai/core/agent/recovery.py +157 -0
  93. package/latticeai/core/agent/runtime.py +210 -0
  94. package/latticeai/core/agent/verification.py +231 -0
  95. package/latticeai/core/config.py +4 -1
  96. package/latticeai/core/context_builder.py +6 -3
  97. package/latticeai/core/embedding_providers/__init__.py +151 -0
  98. package/latticeai/core/embedding_providers/base.py +199 -0
  99. package/latticeai/core/embedding_providers/captions.py +162 -0
  100. package/latticeai/core/embedding_providers/profiles.py +126 -0
  101. package/latticeai/core/embedding_providers/text.py +350 -0
  102. package/latticeai/core/embedding_providers/vision.py +352 -0
  103. package/latticeai/core/file_generation/__init__.py +115 -0
  104. package/latticeai/core/file_generation/bundles.py +76 -0
  105. package/latticeai/core/file_generation/extraction.py +154 -0
  106. package/latticeai/core/file_generation/inference.py +235 -0
  107. package/latticeai/core/file_generation/orchestration.py +152 -0
  108. package/latticeai/core/file_generation/prompting.py +117 -0
  109. package/latticeai/core/file_generation/repair.py +114 -0
  110. package/latticeai/core/file_generation/sanitize.py +61 -0
  111. package/latticeai/core/file_generation/validation.py +201 -0
  112. package/latticeai/core/legacy_compatibility.py +1 -1
  113. package/latticeai/core/marketplace.py +1 -1
  114. package/latticeai/core/messages.py +152 -0
  115. package/latticeai/core/model_compat.py +73 -2
  116. package/latticeai/core/workspace_os_constants.py +1 -1
  117. package/latticeai/integrations/telegram_bot/__init__.py +123 -0
  118. package/latticeai/integrations/telegram_bot/__main__.py +17 -0
  119. package/latticeai/integrations/telegram_bot/config.py +86 -0
  120. package/latticeai/integrations/telegram_bot/dispatch.py +311 -0
  121. package/latticeai/integrations/telegram_bot/flows.py +478 -0
  122. package/latticeai/integrations/telegram_bot/helpers.py +322 -0
  123. package/latticeai/integrations/telegram_bot/screens.py +394 -0
  124. package/latticeai/models/model_providers.py +12 -4
  125. package/latticeai/models/router/__init__.py +88 -0
  126. package/latticeai/models/router/_contract.py +66 -0
  127. package/latticeai/models/router/branding.py +56 -0
  128. package/latticeai/models/router/catalog.py +69 -0
  129. package/latticeai/models/router/documents.py +199 -0
  130. package/latticeai/models/router/errors.py +37 -0
  131. package/latticeai/models/router/generation.py +258 -0
  132. package/latticeai/models/router/loading.py +291 -0
  133. package/latticeai/models/router/local_models.py +85 -0
  134. package/latticeai/models/router/registry.py +147 -0
  135. package/latticeai/runtime/build_phases/__init__.py +82 -0
  136. package/latticeai/runtime/build_phases/features.py +407 -0
  137. package/latticeai/runtime/build_phases/foundation.py +555 -0
  138. package/latticeai/runtime/build_phases/web.py +492 -0
  139. package/latticeai/runtime/chat_wiring.py +4 -0
  140. package/latticeai/runtime/feature_toggle_wiring.py +163 -0
  141. package/latticeai/runtime/router_registration.py +11 -0
  142. package/latticeai/runtime/runtime_context.py +1 -0
  143. package/latticeai/services/app_context.py +8 -0
  144. package/latticeai/services/architecture_readiness.py +48 -19
  145. package/latticeai/services/automation_intelligence.py +22 -2
  146. package/latticeai/services/brain_intelligence/__init__.py +58 -0
  147. package/latticeai/services/brain_intelligence/_contract.py +71 -0
  148. package/latticeai/services/brain_intelligence/consistency.py +193 -0
  149. package/latticeai/services/brain_intelligence/constants.py +47 -0
  150. package/latticeai/services/brain_intelligence/digest.py +258 -0
  151. package/latticeai/services/brain_intelligence/health.py +331 -0
  152. package/latticeai/services/brain_intelligence/proposals.py +264 -0
  153. package/latticeai/services/brain_intelligence/sampling.py +84 -0
  154. package/latticeai/services/brain_intelligence/service.py +48 -0
  155. package/latticeai/services/chronicle.py +557 -0
  156. package/latticeai/services/command_center.py +10 -4
  157. package/latticeai/services/feature_toggles.py +502 -0
  158. package/latticeai/services/folder_watch.py +122 -1
  159. package/latticeai/services/hybrid_chat.py +56 -5
  160. package/latticeai/services/interop_bridges.py +978 -0
  161. package/latticeai/services/memory_service/__init__.py +52 -0
  162. package/latticeai/services/memory_service/_contract.py +100 -0
  163. package/latticeai/services/memory_service/brief.py +431 -0
  164. package/latticeai/services/memory_service/constants.py +57 -0
  165. package/latticeai/services/memory_service/maintenance.py +138 -0
  166. package/latticeai/services/memory_service/manager.py +186 -0
  167. package/latticeai/services/memory_service/proof.py +136 -0
  168. package/latticeai/services/memory_service/recall.py +225 -0
  169. package/latticeai/services/memory_service/service.py +48 -0
  170. package/latticeai/services/memory_service/stores.py +110 -0
  171. package/latticeai/services/model_capability_registry.py +434 -261
  172. package/latticeai/services/model_catalog.py +95 -61
  173. package/latticeai/services/model_recommendation.py +18 -11
  174. package/latticeai/services/model_runtime/__init__.py +322 -0
  175. package/latticeai/services/model_runtime/cloud.py +87 -0
  176. package/latticeai/services/model_runtime/download.py +282 -0
  177. package/latticeai/services/model_runtime/engines.py +341 -0
  178. package/latticeai/services/model_runtime/loading.py +178 -0
  179. package/latticeai/services/model_runtime/service.py +129 -0
  180. package/latticeai/services/model_runtime/state.py +131 -0
  181. package/latticeai/services/model_runtime/status.py +255 -0
  182. package/latticeai/services/multimodal_ports.py +26 -1
  183. package/latticeai/services/obsidian_bridge.py +16 -25
  184. package/latticeai/services/product_readiness.py +15 -7
  185. package/latticeai/services/search_service.py +149 -2
  186. package/latticeai/services/tool_dispatch.py +4 -0
  187. package/latticeai/setup/auto_setup.py +27 -30
  188. package/latticeai/setup/wizard/__init__.py +126 -0
  189. package/latticeai/setup/wizard/catalog.py +172 -0
  190. package/latticeai/setup/wizard/detect.py +323 -0
  191. package/latticeai/setup/wizard/install.py +348 -0
  192. package/latticeai/setup/wizard/paths.py +168 -0
  193. package/latticeai/setup/wizard/plans.py +74 -0
  194. package/latticeai/setup/wizard/recommend.py +320 -0
  195. package/package.json +6 -2
  196. package/scripts/bump_version.py +14 -0
  197. package/scripts/capture_release_evidence.mjs +33 -21
  198. package/scripts/check_current_release_docs.mjs +1 -1
  199. package/scripts/check_i18n_namespace_coverage.mjs +41 -4
  200. package/scripts/check_max_file_lines.mjs +102 -0
  201. package/scripts/check_release_evidence_bound.mjs +30 -15
  202. package/scripts/check_screenshot_pixel_delta.py +34 -4
  203. package/scripts/check_server_i18n.mjs +2 -0
  204. package/scripts/generate_rust_parity_fixtures.py +562 -0
  205. package/scripts/lib/mock_server_fingerprint.mjs +94 -0
  206. package/scripts/release_screen_claims.json +44 -2
  207. package/scripts/verify_hf_model_registry.py +253 -218
  208. package/src-tauri/Cargo.lock +361 -3
  209. package/src-tauri/Cargo.toml +6 -1
  210. package/src-tauri/src/backend.rs +349 -0
  211. package/src-tauri/src/folder.rs +33 -0
  212. package/src-tauri/src/main.rs +97 -399
  213. package/src-tauri/tauri.conf.json +1 -1
  214. package/static/app/asset-manifest.json +41 -37
  215. package/static/app/assets/Act-yYpYnn0v.js +1 -0
  216. package/static/app/assets/AdminConsole-DL3Cr5pL.js +1 -0
  217. package/static/app/assets/{Brain-CzCsI1mi.js → Brain-C1HBN0Wf.js} +2 -2
  218. package/static/app/assets/BrainHome-DoXRhUUC.js +2 -0
  219. package/static/app/assets/BrainSignals-6yR6ir5t.js +1 -0
  220. package/static/app/assets/Capture-CFIRsFNE.js +1 -0
  221. package/static/app/assets/Chronicle-BZbEgiwN.js +1 -0
  222. package/static/app/assets/CommandPalette-D2pMxC2I.js +1 -0
  223. package/static/app/assets/Library-DwO3yZST.js +1 -0
  224. package/static/app/assets/{LivingBrain-BXMWIK_2.js → LivingBrain-Jn1GK0-S.js} +1 -1
  225. package/static/app/assets/ProductFlow-B-w1R4Oo.js +1 -0
  226. package/static/app/assets/ReviewCard-6B27X8Vg.js +3 -0
  227. package/static/app/assets/System-DW8F-2xL.js +1 -0
  228. package/static/app/assets/arrow-left-DXvKg9U6.js +1 -0
  229. package/static/app/assets/{bot-4BvN07ux.js → bot-IM_E_Y12.js} +1 -1
  230. package/static/app/assets/brain-Ci1CkWjM.js +1 -0
  231. package/static/app/assets/{button-CDjtnAoU.js → button-COwyqfHM.js} +1 -1
  232. package/static/app/assets/circle-check-DfInj-qD.js +1 -0
  233. package/static/app/assets/{circle-pause-D_RMn7tp.js → circle-pause-DEM4A1Y5.js} +1 -1
  234. package/static/app/assets/{circle-play-B5OpB8ae.js → circle-play-C9djDuLd.js} +1 -1
  235. package/static/app/assets/{cpu-BIlWInHf.js → cpu-DFdo1gw-.js} +1 -1
  236. package/static/app/assets/{download-BtjXfL3z.js → download-SnJL6oqk.js} +1 -1
  237. package/static/app/assets/{folder-open-DefMpxI2.js → folder-open-CqZeDkjE.js} +1 -1
  238. package/static/app/assets/{hard-drive-BQ8NZVkw.js → hard-drive-j1jJXYYf.js} +1 -1
  239. package/static/app/assets/{index-vtEfYvQY.css → index-BLPb5lmE.css} +1 -1
  240. package/static/app/assets/index-_u5iUHDr.js +10 -0
  241. package/static/app/assets/input-B0lPdRQZ.js +1 -0
  242. package/static/app/assets/link-2-CoFbooHS.js +1 -0
  243. package/static/app/assets/{permissionCopy-BqZ5tsgL.js → permissionCopy-BsyLxtao.js} +1 -1
  244. package/static/app/assets/primitives-DEbN-d6p.js +1 -0
  245. package/static/app/assets/search-BybIWPNd.js +1 -0
  246. package/static/app/assets/{share-2-D5zg_0fY.js → share-2-CVtZ_ewX.js} +1 -1
  247. package/static/app/assets/{shield-alert-B5pZzkUb.js → shield-alert-CBi2GNWM.js} +1 -1
  248. package/static/app/assets/{textarea-nEVIweKY.js → textarea-DNMpB5ih.js} +1 -1
  249. package/static/app/assets/{useFocusTrap-Cm99AHlz.js → useFocusTrap-C83t3GXF.js} +1 -1
  250. package/static/app/assets/useMutation-DtbJDoyz.js +1 -0
  251. package/static/app/assets/{useQuery-Dm__N6bL.js → useQuery-Dcp1OChy.js} +1 -1
  252. package/static/app/assets/utils-BlZr7Pd4.js +4 -0
  253. package/static/app/assets/workspace-jJY4RuAV.js +1 -0
  254. package/static/app/index.html +4 -4
  255. package/static/sw.js +1 -1
  256. package/lattice_brain/graph/_kg_common.py +0 -1331
  257. package/lattice_brain/graph/discovery_index.py +0 -1141
  258. package/lattice_brain/graph/retrieval.py +0 -1120
  259. package/lattice_brain/graph/retrieval_vector.py +0 -1293
  260. package/lattice_brain/ingestion.py +0 -1377
  261. package/lattice_brain/portability.py +0 -1210
  262. package/latticeai/core/agent.py +0 -1412
  263. package/latticeai/core/embedding_providers.py +0 -1196
  264. package/latticeai/core/file_generation.py +0 -1047
  265. package/latticeai/integrations/telegram_bot.py +0 -1390
  266. package/latticeai/models/router.py +0 -1007
  267. package/latticeai/runtime/build_phases.py +0 -1422
  268. package/latticeai/services/brain_intelligence.py +0 -967
  269. package/latticeai/services/memory_service.py +0 -1177
  270. package/latticeai/services/model_runtime.py +0 -1281
  271. package/latticeai/setup/wizard.py +0 -1277
  272. package/static/app/assets/Act-D0HWqtn0.js +0 -1
  273. package/static/app/assets/AdminConsole-D-QDW-A4.js +0 -1
  274. package/static/app/assets/BrainHome-Btns-_TA.js +0 -2
  275. package/static/app/assets/BrainSignals-2dHQNkns.js +0 -1
  276. package/static/app/assets/Capture-CT8v1StE.js +0 -1
  277. package/static/app/assets/CommandPalette-DoLXC2KH.js +0 -1
  278. package/static/app/assets/Library-DDoxFE5c.js +0 -1
  279. package/static/app/assets/ProductFlow-DOYf7JIs.js +0 -1
  280. package/static/app/assets/ReviewCard-COQsqidK.js +0 -3
  281. package/static/app/assets/System-BRllvYXd.js +0 -1
  282. package/static/app/assets/arrow-left-DnyMzss-.js +0 -1
  283. package/static/app/assets/brain-uMb_5hnO.js +0 -1
  284. package/static/app/assets/index-0AvoEBzJ.js +0 -10
  285. package/static/app/assets/input-B_5ZJ9oy.js +0 -1
  286. package/static/app/assets/primitives-CVwew78r.js +0 -1
  287. package/static/app/assets/search-DkhnOKZt.js +0 -1
  288. package/static/app/assets/utils-DcDMoZIe.js +0 -4
  289. package/static/app/assets/workspace-LtRRSKTf.js +0 -1
@@ -94,64 +94,83 @@ _RAW_ENGINE_MODEL_CATALOG: Dict[str, List[Dict[str, Any]]] = _build_engine_model
94
94
  # are all defined; declared here so the public name exists for static readers.
95
95
  ENGINE_MODEL_CATALOG: Dict[str, List[Dict[str, Any]]] = {}
96
96
 
97
- # Historical aliases preserved (used by _recommended_with_engine_options and resolution).
98
- # These can be enriched later from registry if needed; kept verbatim for safety.
99
- MODEL_ENGINE_ALIASES = {
100
- "gemma-4-12b-it-4bit": {
101
- "local_mlx": "mlx-community/gemma-4-12b-it-4bit",
102
- "ollama": "hf.co/ggml-org/gemma-4-12B-it-GGUF:Q4_K_M",
103
- "vllm": "google/gemma-4-12b-it",
104
- "lmstudio": "ggml-org/gemma-4-12B-it-GGUF",
105
- "llamacpp": "ggml-org/gemma-4-12B-it-GGUF",
106
- },
107
- "mlx-community/gemma-4-12b-it-4bit": {
108
- "local_mlx": "mlx-community/gemma-4-12b-it-4bit",
109
- "ollama": "hf.co/ggml-org/gemma-4-12B-it-GGUF:Q4_K_M",
110
- "vllm": "google/gemma-4-12b-it",
111
- "lmstudio": "ggml-org/gemma-4-12B-it-GGUF",
112
- "llamacpp": "ggml-org/gemma-4-12B-it-GGUF",
113
- },
114
- "gemma-4-26b-it-4bit": {
115
- "local_mlx": "mlx-community/gemma-4-26b-a4b-it-4bit",
116
- },
117
- "mlx-community/gemma-4-26b-a4b-it-4bit": {
118
- "local_mlx": "mlx-community/gemma-4-26b-a4b-it-4bit",
119
- },
120
- "gemma-4-31b-it-4bit": {
121
- "local_mlx": "mlx-community/gemma-4-31b-it-4bit",
122
- "ollama": "hf.co/ggml-org/gemma-4-31B-it-GGUF:Q4_K_M",
123
- "vllm": "suitch/gemma-4-31B-it-4bit",
124
- "lmstudio": "ggml-org/gemma-4-31B-it-GGUF",
125
- "llamacpp": "ggml-org/gemma-4-31B-it-GGUF",
126
- },
127
- "suitch/gemma-4-31b-it-4bit": {
128
- "local_mlx": "mlx-community/gemma-4-31b-it-4bit",
129
- "ollama": "hf.co/ggml-org/gemma-4-31B-it-GGUF:Q4_K_M",
130
- "vllm": "suitch/gemma-4-31B-it-4bit",
131
- "lmstudio": "ggml-org/gemma-4-31B-it-GGUF",
132
- "llamacpp": "ggml-org/gemma-4-31B-it-GGUF",
133
- },
134
- "mlx-community/gemma-4-31b-it-4bit": {
135
- "local_mlx": "mlx-community/gemma-4-31b-it-4bit",
136
- "ollama": "hf.co/ggml-org/gemma-4-31B-it-GGUF:Q4_K_M",
137
- "vllm": "suitch/gemma-4-31B-it-4bit",
138
- "lmstudio": "ggml-org/gemma-4-31B-it-GGUF",
139
- "llamacpp": "ggml-org/gemma-4-31B-it-GGUF",
97
+ # Per-engine repo ids for the recommended catalog. Every repo below was resolved
98
+ # through the HF API on 2026-08-10 and is stored in the Hub's canonical casing
99
+ # (`google/gemma-4-12b-it` answers as `google/gemma-4-12B-it`; `ggml-org/
100
+ # gemma-4-26b-a4b-it-GGUF` answers as `ggml-org/gemma-4-26B-A4B-it-GGUF`).
101
+ # Lookups are lowercase, so each model is keyed by both its short name and its
102
+ # full mlx repo id — see `_normalize_engine_entry` and `ModelResolution`.
103
+ #
104
+ # Removed in 11.2.0: `qwen3-vl-8b` and `llama-4-scout`. Their vllm/lmstudio
105
+ # targets pointed at `meta-llama/Llama-4-Scout-17B-16E-Instruct`, which is
106
+ # gated — the download could never succeed without Hub credentials.
107
+
108
+
109
+ def _gguf_routes(mlx_repo: str, gguf_repo: str, hf_repo: str) -> Dict[str, str]:
110
+ """One model's engine map: MLX weights, a GGUF repo, and the upstream HF repo."""
111
+ return {
112
+ "local_mlx": mlx_repo,
113
+ "ollama": f"hf.co/{gguf_repo}:Q4_K_M",
114
+ "vllm": hf_repo,
115
+ "lmstudio": gguf_repo,
116
+ "llamacpp": gguf_repo,
117
+ }
118
+
119
+
120
+ _ENGINE_ROUTES: Dict[str, Dict[str, str]] = {
121
+ "mlx-community/LFM2.5-2.6B-4bit": _gguf_routes(
122
+ "mlx-community/LFM2.5-2.6B-4bit", "LiquidAI/LFM2.5-2.6B-GGUF", "LiquidAI/LFM2.5-2.6B",
123
+ ),
124
+ "mlx-community/gemma-4-e2b-it-4bit": _gguf_routes(
125
+ "mlx-community/gemma-4-e2b-it-4bit", "ggml-org/gemma-4-E2B-it-GGUF", "google/gemma-4-E2B-it",
126
+ ),
127
+ "mlx-community/gemma-4-e4b-it-4bit": _gguf_routes(
128
+ "mlx-community/gemma-4-e4b-it-4bit", "ggml-org/gemma-4-E4B-it-GGUF", "google/gemma-4-E4B-it",
129
+ ),
130
+ "mlx-community/gemma-4-12B-it-4bit": _gguf_routes(
131
+ "mlx-community/gemma-4-12B-it-4bit", "ggml-org/gemma-4-12B-it-GGUF", "google/gemma-4-12B-it",
132
+ ),
133
+ "mlx-community/gemma-4-26b-a4b-it-4bit": _gguf_routes(
134
+ "mlx-community/gemma-4-26b-a4b-it-4bit", "ggml-org/gemma-4-26B-A4B-it-GGUF",
135
+ "google/gemma-4-26B-A4B-it",
136
+ ),
137
+ "mlx-community/gemma-4-31b-it-4bit": _gguf_routes(
138
+ "mlx-community/gemma-4-31b-it-4bit", "ggml-org/gemma-4-31B-it-GGUF", "google/gemma-4-31B-it",
139
+ ),
140
+ "mlx-community/Qwen3.6-27B-4bit": _gguf_routes(
141
+ "mlx-community/Qwen3.6-27B-4bit", "ggml-org/Qwen3.6-27B-GGUF", "Qwen/Qwen3.6-27B",
142
+ ),
143
+ "mlx-community/gpt-oss-20b-MXFP4-Q8": _gguf_routes(
144
+ "mlx-community/gpt-oss-20b-MXFP4-Q8", "ggml-org/gpt-oss-20b-GGUF", "openai/gpt-oss-20b",
145
+ ),
146
+ # No community GGUF build verified for these two, so they offer the MLX
147
+ # weights and the upstream repo only rather than a route that would 404.
148
+ "mlx-community/Qwen3.5-9B-MLX-4bit": {
149
+ "local_mlx": "mlx-community/Qwen3.5-9B-MLX-4bit",
150
+ "vllm": "Qwen/Qwen3.5-9B",
140
151
  },
141
- "qwen3-vl-8b": {
142
- "local_mlx": "mlx-community/Qwen3-VL-8B-Instruct-4bit",
143
- "ollama": "qwen3-vl:8b",
144
- "vllm": "Qwen/Qwen3-VL-8B-Instruct",
145
- "lmstudio": "Qwen/Qwen3-VL-8B-Instruct",
146
- "llamacpp": "Qwen/Qwen3-VL-8B-Instruct-GGUF",
152
+ "mlx-community/Qwen3.6-35B-A3B-4bit": {
153
+ "local_mlx": "mlx-community/Qwen3.6-35B-A3B-4bit",
154
+ "vllm": "Qwen/Qwen3.6-35B-A3B",
147
155
  },
148
- "llama-4-scout": {
149
- "local_mlx": "mlx-community/Llama-4-Scout-17B-16E-Instruct-4bit",
150
- "ollama": "hf.co/ggml-org/Llama-4-Scout-17B-16E-Instruct-GGUF:Q4_K_M",
151
- "vllm": "meta-llama/Llama-4-Scout-17B-16E-Instruct",
152
- "lmstudio": "meta-llama/Llama-4-Scout-17B-16E-Instruct",
153
- "llamacpp": "ggml-org/Llama-4-Scout-17B-16E-Instruct-GGUF",
156
+ }
157
+
158
+ # Names people actually type that are not the repo's own short name. Kept
159
+ # because a user who asks for "gemma-4-26b-it-4bit" means the A4B build — there
160
+ # is no other Gemma 4 26B — and resolving that to nothing would be pedantry.
161
+ _COMMON_MISNAMES: Dict[str, str] = {
162
+ "gemma-4-26b-it-4bit": "mlx-community/gemma-4-26b-a4b-it-4bit",
163
+ }
164
+
165
+ # Keyed by both the lowercase short name ("gemma-4-12b-it-4bit") and the
166
+ # lowercase full repo id, because callers reach this map from both directions.
167
+ MODEL_ENGINE_ALIASES: Dict[str, Dict[str, str]] = {
168
+ **{
169
+ key: routes
170
+ for repo, routes in _ENGINE_ROUTES.items()
171
+ for key in (repo.split("/")[-1].lower(), repo.lower())
154
172
  },
173
+ **{alias: _ENGINE_ROUTES[repo] for alias, repo in _COMMON_MISNAMES.items()},
155
174
  }
156
175
 
157
176
  # Also expose registry helpers directly from here for consumers who want the rich objects
@@ -181,7 +200,14 @@ def _model_family_version(model: Dict[str, Any]) -> Optional[tuple[str, tuple[in
181
200
  # Every pattern captures at least one decimal digit and no other
182
201
  # character but ``.``, so the parsed tuple is never empty — the
183
202
  # old ``if version:`` guard could not fire and is gone.
184
- return family, _version_tuple(match.group(1))
203
+ #
204
+ # Compared at *major* granularity only (``[:1]``). The filter exists
205
+ # to hide superseded generations — Qwen 2.5 behind Qwen 3, Gemma 3
206
+ # behind Gemma 4 — not to pick a winner inside one generation.
207
+ # Comparing minors made Qwen3.5 9B (the mid VLM) vanish the moment
208
+ # Qwen3.6 27B joined the catalog, even though they fill different
209
+ # RAM tiers and ship side by side.
210
+ return family, _version_tuple(match.group(1))[:1]
185
211
  return None
186
212
 
187
213
 
@@ -202,16 +228,24 @@ def filter_lower_family_versions(models: List[Dict[str, Any]]) -> List[Dict[str,
202
228
  ]
203
229
 
204
230
 
205
- # ── 5.2.0 user-facing catalog assembly ────────────────────────────────────────
206
- # Legacy/text-only generations stay in the capability registry (for transparency
207
- # and HF verification) but must never be surfaced in the model picker. Anything
208
- # whose id contains one of these fragments is dropped from ENGINE_MODEL_CATALOG.
231
+ # ── User-facing catalog assembly ──────────────────────────────────────────────
232
+ # The capability registry already keeps superseded generations out of the
233
+ # catalog by lifecycle (they live in its LEGACY list, recognised but never
234
+ # offered). This blocklist is the second lock: a regression guard so a retired
235
+ # generation cannot creep back into the model picker through a hand-edited
236
+ # entry. Anything whose id contains one of these fragments is dropped from
237
+ # ENGINE_MODEL_CATALOG.
238
+ #
239
+ # 11.2.0 removed ``gpt-oss`` from this list — GPT-OSS 20B is now a recommended
240
+ # entry, not a retired one — and added the generations retired this release.
209
241
  _BLOCKED_CATALOG_FRAGMENTS = (
210
242
  "gemma-3", "gemma3", "gemma-2", "gemma2",
211
243
  "qwen2.5", "qwen-2.5", "qwen2-5",
244
+ "qwen3-vl", "qwen3vl",
212
245
  "llama-3", "llama3.2", "llama-3.2",
246
+ "llama-4", "llama4",
213
247
  "pixtral", "mistral",
214
- "smollm", "gpt-oss", "phi-",
248
+ "smollm", "phi-", "moondream",
215
249
  )
216
250
 
217
251
 
@@ -3,8 +3,8 @@
3
3
  Given a detected system profile (from :func:`auto_setup.probe`) this module
4
4
  classifies every model in :data:`model_catalog.ENGINE_MODEL_CATALOG` into one of
5
5
  three states — **recommended**, **compatible**, or **not_recommended** — and
6
- groups the result by current multimodal model family (Gemma 4, Qwen3-VL,
7
- Llama 4).
6
+ groups the result by current model family (Gemma 4, Qwen3.6, Qwen3.5, GPT-OSS,
7
+ LFM2.5).
8
8
 
9
9
  It is intentionally pure and dependency-light: the only input is a plain dict
10
10
  describing the machine, so it is fully unit-testable without touching real
@@ -30,18 +30,25 @@ NOT_RECOMMENDED = "not_recommended"
30
30
  # Apple-Silicon only. Used to decide platform availability before sizing.
31
31
  _APPLE_ONLY_ENGINES = {"local_mlx"}
32
32
 
33
- # Family display order for the grouped view (newest multimodal generations first).
33
+ # Family display order for the grouped view (current generations, largest
34
+ # lineup first). Superseded families are not listed because the capability
35
+ # registry never lets them reach the catalog — they are recognised for loading
36
+ # only. A family missing from this list still renders, it just sorts last.
34
37
  _FAMILY_ORDER = [
35
38
  "Gemma 4",
36
- "Qwen3-VL",
37
- "Qwen2.5-VL",
38
- "Llama 4",
39
- "Llama 3.2 Vision",
40
- "Phi Vision",
41
- "Moondream",
42
- "Pixtral",
39
+ "Qwen3.6",
40
+ "Qwen3.5",
41
+ "GPT-OSS",
42
+ "LFM2.5",
43
43
  ]
44
44
 
45
+ # Modalities the recommender will surface. Text-only models earn their place —
46
+ # LFM2.5 is the only thing that runs comfortably on 8GB, and GPT-OSS 20B is the
47
+ # most-downloaded entry in the catalog — so filtering to `multimodal` would have
48
+ # hidden two of the tiers. Each row still reports its own `modality`, so a UI
49
+ # that wants to badge "reads pictures" can, honestly.
50
+ _RECOMMENDABLE_MODALITIES = {"multimodal", "text"}
51
+
45
52
  _SIZE_RE = re.compile(r"([\d.]+)\s*(TB|GB|MB)", re.IGNORECASE)
46
53
  _UNIT_GB = {"TB": 1024.0, "GB": 1.0, "MB": 1.0 / 1024.0}
47
54
 
@@ -165,7 +172,7 @@ def recommend_catalog(profile: Dict[str, Any], *, engine: str = "local_mlx") ->
165
172
  """
166
173
  models = [
167
174
  model for model in ENGINE_MODEL_CATALOG.get(engine, [])
168
- if str(model.get("modality") or "").lower() == "multimodal"
175
+ if str(model.get("modality") or "").lower() in _RECOMMENDABLE_MODALITIES
169
176
  ]
170
177
  engine_available = _engine_available(engine, profile)
171
178
  ram_gb = _ram_gb(profile)
@@ -0,0 +1,322 @@
1
+ """Model runtime and provider helpers for Lattice AI.
2
+
3
+ This module owns local/cloud model preparation, engine detection, model download,
4
+ provider-specific server startup, smoke tests, and runtime feature payloads. It is
5
+ configured by ``server_app`` with app-level state but has no FastAPI app import.
6
+
7
+ Split into cohesive submodules in v11.3.0 (no behaviour change): ``state`` (the
8
+ immutable ``ModelRuntimeState`` and the consent gates), ``engines`` (engine
9
+ wrappers + the LM Studio client), ``download`` (Hugging Face readiness and
10
+ fetch), ``status`` (``engine_status`` / ``runtime_features`` / ``install_engine``),
11
+ ``loading`` (identity resolution and the load entrypoints), ``cloud`` (cloud key
12
+ verification) and ``service`` (the bound ``ModelRuntimeService``). This module
13
+ re-exports every name the single file exposed, so
14
+ ``latticeai.services.model_runtime.X`` keeps working — including the private
15
+ names ``model_loading._get_model_runtime_deps`` imports.
16
+
17
+ Two deliberate omissions: ``engines._LMSTUDIO_MODELS_CACHE`` and
18
+ ``_LMSTUDIO_MODELS_CACHE_TS`` are *rebound* by ``get_lmstudio_models``, so a
19
+ re-export here would be a snapshot frozen at import time. They stay reachable
20
+ at ``latticeai.services.model_runtime.engines``, which is where the live values
21
+ are.
22
+
23
+ Stubbing note: rebinding a name *here* changes only this module's name — the
24
+ lazy ``from latticeai.services.model_runtime import …`` calls in
25
+ ``model_engines`` and ``model_loading`` read it, but a submodule that uses the
26
+ name holds its own reference. A test standing in for a helper patches the
27
+ submodule that uses it.
28
+ """
29
+
30
+ from __future__ import annotations
31
+
32
+ # The single file had no ``__all__``, so its public surface was "every module
33
+ # global" — including the names it imported for its own use. Every re-export
34
+ # below therefore uses the redundant-alias form: it reproduces exactly that
35
+ # surface, and it marks each name as deliberate rather than a leftover import.
36
+ from latticeai.core.quiet import quiet as quiet
37
+ from latticeai.models.router import HF_MODELS_ROOT as HF_MODELS_ROOT
38
+ from latticeai.models.router import (
39
+ OPENAI_COMPATIBLE_PROVIDERS as OPENAI_COMPATIBLE_PROVIDERS,
40
+ )
41
+ from latticeai.models.router import AsyncOpenAI as AsyncOpenAI
42
+ from latticeai.models.router import ensure_mlx_runtime as ensure_mlx_runtime
43
+ from latticeai.models.router import hf_cache_model_dir as hf_cache_model_dir
44
+ from latticeai.models.router import hf_model_dir as hf_model_dir
45
+ from latticeai.models.router import parse_model_ref as parse_model_ref
46
+
47
+ # Catalog data + version-dedup helpers live in ``model_catalog``; re-exported
48
+ # here so existing ``from ...model_runtime import ENGINE_MODEL_CATALOG`` imports
49
+ # keep working.
50
+ from latticeai.services.model_catalog import (
51
+ _VERSIONED_MODEL_PATTERNS as _VERSIONED_MODEL_PATTERNS,
52
+ )
53
+ from latticeai.services.model_catalog import (
54
+ ENGINE_INSTALLERS as ENGINE_INSTALLERS,
55
+ )
56
+ from latticeai.services.model_catalog import (
57
+ ENGINE_MODEL_CATALOG as ENGINE_MODEL_CATALOG,
58
+ )
59
+ from latticeai.services.model_catalog import (
60
+ MODEL_ENGINE_ALIASES as MODEL_ENGINE_ALIASES,
61
+ )
62
+ from latticeai.services.model_catalog import (
63
+ _model_family_version as _model_family_version,
64
+ )
65
+ from latticeai.services.model_catalog import (
66
+ _version_tuple as _version_tuple,
67
+ )
68
+ from latticeai.services.model_catalog import (
69
+ filter_lower_family_versions as filter_lower_family_versions,
70
+ )
71
+ from latticeai.services.model_errors import ModelRuntimeError as ModelRuntimeError
72
+ from latticeai.services.model_runtime.cloud import (
73
+ CLOUD_VERIFY_TTL_SECONDS as CLOUD_VERIFY_TTL_SECONDS,
74
+ )
75
+ from latticeai.services.model_runtime.cloud import (
76
+ _probe_cloud_model as _probe_cloud_model,
77
+ )
78
+ from latticeai.services.model_runtime.cloud import (
79
+ verify_cloud_models as verify_cloud_models,
80
+ )
81
+ from latticeai.services.model_runtime.download import (
82
+ download_hf_model as download_hf_model,
83
+ )
84
+ from latticeai.services.model_runtime.download import (
85
+ estimate_eta_seconds as estimate_eta_seconds,
86
+ )
87
+ from latticeai.services.model_runtime.download import (
88
+ hf_model_ready as hf_model_ready,
89
+ )
90
+ from latticeai.services.model_runtime.download import (
91
+ hf_repo_files_with_sizes as hf_repo_files_with_sizes,
92
+ )
93
+ from latticeai.services.model_runtime.download import (
94
+ model_download_progress_payload as model_download_progress_payload,
95
+ )
96
+ from latticeai.services.model_runtime.engines import (
97
+ _LMSTUDIO_MODELS_CACHE_TTL as _LMSTUDIO_MODELS_CACHE_TTL,
98
+ )
99
+
100
+ # The private aliases the historical module bound for its own use — including
101
+ # the ones ``model_loading._get_model_runtime_deps`` imports by name. They are
102
+ # re-exported from the submodule that already binds them under exactly these
103
+ # names, which is ruff's redundant-alias re-export form.
104
+ from latticeai.services.model_runtime.engines import (
105
+ _LOCAL_SERVER_PROCESSES as _LOCAL_SERVER_PROCESSES,
106
+ )
107
+ from latticeai.services.model_runtime.engines import (
108
+ LMSTUDIO_BUNDLED_CLI as LMSTUDIO_BUNDLED_CLI,
109
+ )
110
+ from latticeai.services.model_runtime.engines import (
111
+ LOCAL_SERVER_PROCESSES as LOCAL_SERVER_PROCESSES,
112
+ )
113
+ from latticeai.services.model_runtime.engines import (
114
+ VLLM_METAL_BIN as VLLM_METAL_BIN,
115
+ )
116
+ from latticeai.services.model_runtime.engines import (
117
+ VLLM_METAL_ENV as VLLM_METAL_ENV,
118
+ )
119
+ from latticeai.services.model_runtime.engines import (
120
+ VLLM_METAL_PYTHON as VLLM_METAL_PYTHON,
121
+ )
122
+ from latticeai.services.model_runtime.engines import (
123
+ _engine_install_plan as _engine_install_plan,
124
+ )
125
+ from latticeai.services.model_runtime.engines import (
126
+ _engine_support_status as _engine_support_status,
127
+ )
128
+ from latticeai.services.model_runtime.engines import (
129
+ _ensure_llamacpp_server as _ensure_llamacpp_server,
130
+ )
131
+ from latticeai.services.model_runtime.engines import (
132
+ _ensure_lmstudio_server as _ensure_lmstudio_server,
133
+ )
134
+ from latticeai.services.model_runtime.engines import (
135
+ _ensure_ollama_server as _ensure_ollama_server,
136
+ )
137
+ from latticeai.services.model_runtime.engines import (
138
+ _ensure_vllm_server as _ensure_vllm_server,
139
+ )
140
+ from latticeai.services.model_runtime.engines import (
141
+ _find_lmstudio_cli as _find_lmstudio_cli,
142
+ )
143
+ from latticeai.services.model_runtime.engines import (
144
+ _find_lmstudio_model_key as _find_lmstudio_model_key,
145
+ )
146
+ from latticeai.services.model_runtime.engines import (
147
+ _get_ollama_pulled_models as _get_ollama_pulled_models,
148
+ )
149
+ from latticeai.services.model_runtime.engines import (
150
+ _get_openai_compatible_server_models as _get_openai_compatible_server_models,
151
+ )
152
+ from latticeai.services.model_runtime.engines import (
153
+ _json_request as _json_request,
154
+ )
155
+ from latticeai.services.model_runtime.engines import (
156
+ _lmstudio_candidate_keys as _lmstudio_candidate_keys,
157
+ )
158
+ from latticeai.services.model_runtime.engines import (
159
+ _local_binary as _local_binary,
160
+ )
161
+ from latticeai.services.model_runtime.engines import (
162
+ _pull_ollama_model_with_progress as _pull_ollama_model_with_progress,
163
+ )
164
+ from latticeai.services.model_runtime.engines import (
165
+ _safe_engine_install_plan as _safe_engine_install_plan,
166
+ )
167
+ from latticeai.services.model_runtime.engines import (
168
+ _update_env_file as _update_env_file,
169
+ )
170
+ from latticeai.services.model_runtime.engines import (
171
+ _vllm_executable as _vllm_executable,
172
+ )
173
+ from latticeai.services.model_runtime.engines import (
174
+ _vllm_metal_python as _vllm_metal_python,
175
+ )
176
+ from latticeai.services.model_runtime.engines import (
177
+ _wait_for_openai_compatible_server as _wait_for_openai_compatible_server,
178
+ )
179
+ from latticeai.services.model_runtime.engines import (
180
+ _windows_binary_candidates as _windows_binary_candidates,
181
+ )
182
+ from latticeai.services.model_runtime.engines import (
183
+ engine_installed as engine_installed,
184
+ )
185
+ from latticeai.services.model_runtime.engines import (
186
+ engine_support_status as engine_support_status,
187
+ )
188
+ from latticeai.services.model_runtime.engines import (
189
+ ensure_llamacpp_server as ensure_llamacpp_server,
190
+ )
191
+ from latticeai.services.model_runtime.engines import (
192
+ ensure_lmstudio_model as ensure_lmstudio_model,
193
+ )
194
+ from latticeai.services.model_runtime.engines import (
195
+ ensure_lmstudio_server as ensure_lmstudio_server,
196
+ )
197
+ from latticeai.services.model_runtime.engines import (
198
+ ensure_ollama_server as ensure_ollama_server,
199
+ )
200
+ from latticeai.services.model_runtime.engines import (
201
+ ensure_vllm_server as ensure_vllm_server,
202
+ )
203
+ from latticeai.services.model_runtime.engines import (
204
+ find_lmstudio_cli as find_lmstudio_cli,
205
+ )
206
+ from latticeai.services.model_runtime.engines import (
207
+ get_lmstudio_models as get_lmstudio_models,
208
+ )
209
+ from latticeai.services.model_runtime.engines import (
210
+ get_ollama_pulled_models as get_ollama_pulled_models,
211
+ )
212
+ from latticeai.services.model_runtime.engines import (
213
+ get_openai_compatible_server_models as get_openai_compatible_server_models,
214
+ )
215
+ from latticeai.services.model_runtime.engines import (
216
+ lmstudio_api_base as lmstudio_api_base,
217
+ )
218
+ from latticeai.services.model_runtime.engines import (
219
+ lmstudio_native_api_base as lmstudio_native_api_base,
220
+ )
221
+ from latticeai.services.model_runtime.engines import (
222
+ local_binary as local_binary,
223
+ )
224
+ from latticeai.services.model_runtime.engines import (
225
+ pull_ollama_model_with_progress as pull_ollama_model_with_progress,
226
+ )
227
+ from latticeai.services.model_runtime.engines import (
228
+ vllm_executable as vllm_executable,
229
+ )
230
+ from latticeai.services.model_runtime.engines import (
231
+ vllm_metal_python as vllm_metal_python,
232
+ )
233
+ from latticeai.services.model_runtime.engines import (
234
+ wait_for_openai_compatible_server as wait_for_openai_compatible_server,
235
+ )
236
+ from latticeai.services.model_runtime.engines import (
237
+ windows_binary_candidates as windows_binary_candidates,
238
+ )
239
+ from latticeai.services.model_runtime.loading import (
240
+ _LOCAL_SMOKE_ENGINES as _LOCAL_SMOKE_ENGINES,
241
+ )
242
+ from latticeai.services.model_runtime.loading import (
243
+ _ModelResolution as _ModelResolution,
244
+ )
245
+ from latticeai.services.model_runtime.loading import (
246
+ _resolve_model_alias as _resolve_model_alias,
247
+ )
248
+ from latticeai.services.model_runtime.loading import (
249
+ _smoke_test_loaded_model as _smoke_test_loaded_model,
250
+ )
251
+ from latticeai.services.model_runtime.loading import (
252
+ build_model_resolution as build_model_resolution,
253
+ )
254
+ from latticeai.services.model_runtime.loading import (
255
+ ensure_engine_ready as ensure_engine_ready,
256
+ )
257
+ from latticeai.services.model_runtime.loading import (
258
+ normalize_local_model_request as normalize_local_model_request,
259
+ )
260
+ from latticeai.services.model_runtime.loading import (
261
+ prepare_and_load_model as prepare_and_load_model,
262
+ )
263
+ from latticeai.services.model_runtime.loading import (
264
+ prepare_and_load_model_stream as prepare_and_load_model_stream,
265
+ )
266
+ from latticeai.services.model_runtime.loading import (
267
+ sse_event as sse_event,
268
+ )
269
+ from latticeai.services.model_runtime.service import (
270
+ ModelRuntimeService as ModelRuntimeService,
271
+ )
272
+ from latticeai.services.model_runtime.service import (
273
+ build_model_runtime as build_model_runtime,
274
+ )
275
+ from latticeai.services.model_runtime.service import (
276
+ configure_model_runtime as configure_model_runtime,
277
+ )
278
+ from latticeai.services.model_runtime.state import (
279
+ _MODEL_LOADING_COMPAT_EXPORTS as _MODEL_LOADING_COMPAT_EXPORTS,
280
+ )
281
+ from latticeai.services.model_runtime.state import (
282
+ _SMOKE_PROMPT as _SMOKE_PROMPT,
283
+ )
284
+ from latticeai.services.model_runtime.state import (
285
+ ModelRuntimeState as ModelRuntimeState,
286
+ )
287
+ from latticeai.services.model_runtime.state import (
288
+ _download_allowed as _download_allowed,
289
+ )
290
+ from latticeai.services.model_runtime.state import (
291
+ _download_block as _download_block,
292
+ )
293
+ from latticeai.services.model_runtime.state import (
294
+ _engine_install_block as _engine_install_block,
295
+ )
296
+ from latticeai.services.model_runtime.state import (
297
+ _friendly_model_runtime_error as _friendly_model_runtime_error,
298
+ )
299
+ from latticeai.services.model_runtime.state import (
300
+ _missing_current_user as _missing_current_user,
301
+ )
302
+ from latticeai.services.model_runtime.state import (
303
+ _missing_user_api_key as _missing_user_api_key,
304
+ )
305
+ from latticeai.services.model_runtime.state import (
306
+ _model_runtime_compatibility as _model_runtime_compatibility,
307
+ )
308
+ from latticeai.services.model_runtime.state import (
309
+ create_model_runtime_state as create_model_runtime_state,
310
+ )
311
+ from latticeai.services.model_runtime.status import (
312
+ _install_engine as _install_engine,
313
+ )
314
+ from latticeai.services.model_runtime.status import (
315
+ engine_status as engine_status,
316
+ )
317
+ from latticeai.services.model_runtime.status import (
318
+ install_engine as install_engine,
319
+ )
320
+ from latticeai.services.model_runtime.status import (
321
+ runtime_features as runtime_features,
322
+ )
@@ -0,0 +1,87 @@
1
+ """Cloud model verification — does this key actually answer for this model?
2
+
3
+ A one-token chat completion per configured cloud model, cached per service
4
+ instance for :data:`CLOUD_VERIFY_TTL_SECONDS`. A model the router already knows
5
+ is unavailable is recorded as such without a network call.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import asyncio
11
+ import os
12
+ import time
13
+ from typing import Any, Dict, Optional
14
+
15
+ from latticeai.models.router import (
16
+ OPENAI_COMPATIBLE_PROVIDERS,
17
+ AsyncOpenAI,
18
+ parse_model_ref,
19
+ )
20
+ from latticeai.services.model_runtime.state import ModelRuntimeState
21
+
22
+ CLOUD_VERIFY_TTL_SECONDS = 600
23
+
24
+ async def _probe_cloud_model(model_ref: str) -> Dict[str, Any]:
25
+ provider, model_name = parse_model_ref(model_ref)
26
+ config = OPENAI_COMPATIBLE_PROVIDERS.get(provider)
27
+ if not config:
28
+ return {"ok": False, "reason": f"Unsupported provider: {provider}"}
29
+
30
+ api_key = os.getenv(config["env_key"]) or config.get("api_key_fallback")
31
+ if not api_key:
32
+ return {"ok": False, "reason": f"Missing API key: {config['env_key']}"}
33
+
34
+ base_url = os.getenv(config.get("base_url_env", "")) if config.get("base_url_env") else None
35
+ base_url = base_url or config.get("base_url")
36
+ try:
37
+ # base_url is passed only when configured: an explicit None is not
38
+ # the same as omitting the argument.
39
+ client = (
40
+ AsyncOpenAI(api_key=api_key, base_url=base_url)
41
+ if base_url
42
+ else AsyncOpenAI(api_key=api_key)
43
+ )
44
+ await asyncio.wait_for(
45
+ client.chat.completions.create(
46
+ model=model_name,
47
+ messages=[{"role": "user", "content": "ping"}],
48
+ max_tokens=1,
49
+ temperature=0,
50
+ ),
51
+ timeout=15,
52
+ )
53
+ return {"ok": True, "reason": "ok"}
54
+ except Exception as e:
55
+ return {"ok": False, "reason": str(e)[:220]}
56
+
57
+
58
+ async def verify_cloud_models(
59
+ force: bool = False,
60
+ provider_filter: Optional[str] = None,
61
+ *,
62
+ state: ModelRuntimeState,
63
+ cache: Dict[str, Dict[str, Any]],
64
+ ) -> Dict[str, Dict]:
65
+ now = time.time()
66
+ r = state.router
67
+ cloud_items = [item for item in (r.detected_cloud_models() if r else []) if item.get("tag") == "cloud"]
68
+ if provider_filter:
69
+ cloud_items = [item for item in cloud_items if item.get("provider") == provider_filter]
70
+
71
+ results: Dict[str, Dict] = {}
72
+ for item in cloud_items:
73
+ model_ref = item["id"]
74
+ cached = cache.get(model_ref)
75
+ if not force and cached and (now - cached.get("ts", 0) <= CLOUD_VERIFY_TTL_SECONDS):
76
+ results[model_ref] = cached
77
+ continue
78
+ if item.get("available") is False:
79
+ record = {"ok": False, "reason": item.get("requires") or "API key missing", "ts": now}
80
+ cache[model_ref] = record
81
+ results[model_ref] = record
82
+ continue
83
+ probe = await _probe_cloud_model(model_ref)
84
+ record = {"ok": bool(probe.get("ok")), "reason": probe.get("reason", ""), "ts": now}
85
+ cache[model_ref] = record
86
+ results[model_ref] = record
87
+ return results