omnicell-router 0.8.4 → 0.10.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.
- package/README.md +26 -7
- package/README.zh-CN.md +18 -5
- package/backend/dist/capture/recorder.d.ts +4 -10
- package/backend/dist/capture/recorder.js +6 -58
- package/backend/dist/cli/clients/base.d.ts +36 -11
- package/backend/dist/cli/clients/base.js +31 -15
- package/backend/dist/cli/clients/claude.d.ts +9 -0
- package/backend/dist/cli/clients/claude.js +6 -0
- package/backend/dist/cli/clients/codex.d.ts +8 -0
- package/backend/dist/cli/clients/codex.js +5 -0
- package/backend/dist/cli/clients/core-adapters.d.ts +1 -1
- package/backend/dist/cli/clients/core-adapters.js +1 -1
- package/backend/dist/cli/clients/dsh.d.ts +8 -0
- package/backend/dist/cli/clients/dsh.js +5 -0
- package/backend/dist/cli/clients/grok.d.ts +15 -1
- package/backend/dist/cli/clients/grok.js +16 -2
- package/backend/dist/cli/clients/index.d.ts +13 -1
- package/backend/dist/cli/clients/index.js +97 -19
- package/backend/dist/cli/clients/kimi.d.ts +6 -0
- package/backend/dist/cli/clients/kimi.js +3 -0
- package/backend/dist/cli/clients/launcher.d.ts +1 -1
- package/backend/dist/cli/clients/model-meta.js +6 -3
- package/backend/dist/cli/clients/omp.d.ts +6 -0
- package/backend/dist/cli/clients/omp.js +3 -0
- package/backend/dist/cli/clients/openclaw.d.ts +6 -0
- package/backend/dist/cli/clients/openclaw.js +3 -0
- package/backend/dist/cli/clients/opencode.d.ts +8 -0
- package/backend/dist/cli/clients/opencode.js +5 -0
- package/backend/dist/cli/clients/pi.d.ts +6 -0
- package/backend/dist/cli/clients/pi.js +3 -0
- package/backend/dist/cli/clients/update-check.d.ts +37 -0
- package/backend/dist/cli/clients/update-check.js +309 -0
- package/backend/dist/cli/clients/workbuddy.d.ts +19 -0
- package/backend/dist/cli/clients/workbuddy.js +66 -0
- package/backend/dist/cli/index.js +5 -4
- package/backend/dist/cli/paths.js +8 -0
- package/backend/dist/cli/types.d.ts +92 -16
- package/backend/dist/config/comments-en.js +31 -26
- package/backend/dist/config/comments-zh.js +29 -24
- package/backend/dist/config/defaults.d.ts +194 -33
- package/backend/dist/config/defaults.js +193 -32
- package/backend/dist/config/env.d.ts +10 -0
- package/backend/dist/config/env.js +3 -2
- package/backend/dist/config/index.d.ts +7 -0
- package/backend/dist/config/index.js +184 -43
- package/backend/dist/config/migrations/v0-to-v1.d.ts +2 -2
- package/backend/dist/config/migrations/v10-to-v11.d.ts +38 -0
- package/backend/dist/config/migrations/v10-to-v11.js +43 -0
- package/backend/dist/config/migrations/v6-to-v7.d.ts +45 -0
- package/backend/dist/config/migrations/v6-to-v7.js +97 -0
- package/backend/dist/config/migrations/v7-to-v8.d.ts +36 -0
- package/backend/dist/config/migrations/v7-to-v8.js +43 -0
- package/backend/dist/config/migrations/v8-to-v9.d.ts +38 -0
- package/backend/dist/config/migrations/v8-to-v9.js +43 -0
- package/backend/dist/config/migrations/v9-to-v10.d.ts +51 -0
- package/backend/dist/config/migrations/v9-to-v10.js +71 -0
- package/backend/dist/config/runtime.js +1 -1
- package/backend/dist/config/schema.d.ts +3 -3
- package/backend/dist/config/schema.js +14 -4
- package/backend/dist/config/types.d.ts +167 -38
- package/backend/dist/egress-proxy/asset-download.d.ts +54 -0
- package/backend/dist/egress-proxy/asset-download.js +420 -0
- package/backend/dist/egress-proxy/manual-node-spec.d.ts +92 -0
- package/backend/dist/egress-proxy/manual-node-spec.js +408 -0
- package/backend/dist/egress-proxy/mihomo-binary.d.ts +54 -0
- package/backend/dist/egress-proxy/mihomo-binary.js +278 -0
- package/backend/dist/egress-proxy/mihomo-client.d.ts +94 -0
- package/backend/dist/egress-proxy/mihomo-client.js +308 -0
- package/backend/dist/egress-proxy/mihomo-config.d.ts +40 -0
- package/backend/dist/egress-proxy/mihomo-config.js +161 -0
- package/backend/dist/egress-proxy/mihomo-geo.d.ts +87 -0
- package/backend/dist/egress-proxy/mihomo-geo.js +213 -0
- package/backend/dist/egress-proxy/mihomo-logs.d.ts +43 -0
- package/backend/dist/egress-proxy/mihomo-logs.js +84 -0
- package/backend/dist/egress-proxy/mihomo-pac.d.ts +37 -0
- package/backend/dist/egress-proxy/mihomo-pac.js +75 -0
- package/backend/dist/egress-proxy/mihomo-rules-import.d.ts +43 -0
- package/backend/dist/egress-proxy/mihomo-rules-import.js +193 -0
- package/backend/dist/egress-proxy/mihomo-sidecar.d.ts +81 -0
- package/backend/dist/egress-proxy/mihomo-sidecar.js +637 -0
- package/backend/dist/forward-proxy/egress.d.ts +50 -11
- package/backend/dist/forward-proxy/egress.js +50 -17
- package/backend/dist/forward-proxy/h2-forward.js +36 -10
- package/backend/dist/forward-proxy/index.d.ts +11 -8
- package/backend/dist/forward-proxy/index.js +22 -60
- package/backend/dist/forward-proxy/interceptor.d.ts +3 -2
- package/backend/dist/forward-proxy/interceptor.js +4 -4
- package/backend/dist/forward-proxy/relay.js +3 -3
- package/backend/dist/forward-proxy/rules.d.ts +4 -4
- package/backend/dist/forward-proxy/rules.js +25 -4
- package/backend/dist/forward-proxy/server.d.ts +0 -16
- package/backend/dist/forward-proxy/server.js +124 -156
- package/backend/dist/harness/host/hosts.js +3 -2
- package/backend/dist/index.js +53 -18
- package/backend/dist/ingress-proxy/access-log.d.ts +176 -0
- package/backend/dist/ingress-proxy/access-log.js +774 -0
- package/backend/dist/ingress-proxy/ca-inventory.d.ts +106 -0
- package/backend/dist/ingress-proxy/ca-inventory.js +525 -0
- package/backend/dist/ingress-proxy/ca-trust.d.ts +96 -0
- package/backend/dist/ingress-proxy/ca-trust.js +315 -0
- package/backend/dist/ingress-proxy/ca.d.ts +104 -0
- package/backend/dist/ingress-proxy/ca.js +273 -0
- package/backend/dist/ingress-proxy/data-dir.d.ts +28 -0
- package/backend/dist/ingress-proxy/data-dir.js +45 -0
- package/backend/dist/ingress-proxy/egress.d.ts +151 -0
- package/backend/dist/ingress-proxy/egress.js +364 -0
- package/backend/dist/ingress-proxy/h2-forward.d.ts +66 -0
- package/backend/dist/ingress-proxy/h2-forward.js +561 -0
- package/backend/dist/ingress-proxy/index.d.ts +24 -0
- package/backend/dist/ingress-proxy/index.js +144 -0
- package/backend/dist/ingress-proxy/interceptor.d.ts +25 -0
- package/backend/dist/ingress-proxy/interceptor.js +52 -0
- package/backend/dist/ingress-proxy/ordered-relay.d.ts +29 -0
- package/backend/dist/ingress-proxy/ordered-relay.js +46 -0
- package/backend/dist/ingress-proxy/relay.d.ts +54 -0
- package/backend/dist/ingress-proxy/relay.js +188 -0
- package/backend/dist/ingress-proxy/rules.d.ts +195 -0
- package/backend/dist/ingress-proxy/rules.js +348 -0
- package/backend/dist/ingress-proxy/server.d.ts +153 -0
- package/backend/dist/ingress-proxy/server.js +2065 -0
- package/backend/dist/ingress-proxy/sni.d.ts +35 -0
- package/backend/dist/ingress-proxy/sni.js +124 -0
- package/backend/dist/ingress-proxy/status.d.ts +32 -0
- package/backend/dist/ingress-proxy/status.js +15 -0
- package/backend/dist/ingress-proxy/system-proxy.d.ts +112 -0
- package/backend/dist/ingress-proxy/system-proxy.js +481 -0
- package/backend/dist/ingress-proxy/traffic-delete.d.ts +21 -0
- package/backend/dist/ingress-proxy/traffic-delete.js +64 -0
- package/backend/dist/ingress-proxy/traffic-delete.worker.d.ts +44 -0
- package/backend/dist/ingress-proxy/traffic-delete.worker.js +228 -0
- package/backend/dist/ingress-proxy/traffic-files.d.ts +10 -0
- package/backend/dist/ingress-proxy/traffic-files.js +10 -0
- package/backend/dist/ingress-proxy/upstream-tls.d.ts +46 -0
- package/backend/dist/ingress-proxy/upstream-tls.js +105 -0
- package/backend/dist/ingress-proxy/ws-frames.d.ts +45 -0
- package/backend/dist/ingress-proxy/ws-frames.js +153 -0
- package/backend/dist/ir/adapters/anthropic-messages-stream.js +6 -1
- package/backend/dist/ir/adapters/anthropic-messages.js +12 -5
- package/backend/dist/ir/adapters/google-gemini-stream.js +7 -2
- package/backend/dist/ir/adapters/google-gemini.js +5 -2
- package/backend/dist/ir/adapters/openai-chat-stream.js +5 -1
- package/backend/dist/ir/adapters/openai-chat.d.ts +25 -0
- package/backend/dist/ir/adapters/openai-chat.js +45 -3
- package/backend/dist/ir/adapters/openai-responses-output.d.ts +1 -0
- package/backend/dist/ir/adapters/openai-responses-output.js +67 -21
- package/backend/dist/ir/adapters/openai-responses-stream.d.ts +13 -0
- package/backend/dist/ir/adapters/openai-responses-stream.js +34 -1
- package/backend/dist/ir/adapters/openai-responses.d.ts +82 -24
- package/backend/dist/ir/adapters/openai-responses.js +146 -37
- package/backend/dist/ir/media.d.ts +20 -0
- package/backend/dist/ir/media.js +41 -0
- package/backend/dist/ir/tool-identity.d.ts +35 -0
- package/backend/dist/ir/tool-identity.js +40 -0
- package/backend/dist/ir/types.d.ts +9 -1
- package/backend/dist/local/build-jobs.d.ts +66 -0
- package/backend/dist/local/build-jobs.js +243 -0
- package/backend/dist/local/detect.d.ts +32 -0
- package/backend/dist/local/detect.js +145 -0
- package/backend/dist/local/draft-match.d.ts +58 -0
- package/backend/dist/local/draft-match.js +124 -0
- package/backend/dist/local/engine-runtime.d.ts +522 -0
- package/backend/dist/local/engine-runtime.js +1 -0
- package/backend/dist/local/engines.d.ts +241 -0
- package/backend/dist/local/engines.js +651 -0
- package/backend/dist/local/gguf.d.ts +35 -0
- package/backend/dist/local/gguf.js +314 -0
- package/backend/dist/local/hf.d.ts +120 -0
- package/backend/dist/local/hf.js +304 -0
- package/backend/dist/local/install.d.ts +90 -0
- package/backend/dist/local/install.js +421 -0
- package/backend/dist/local/llamacpp.d.ts +55 -0
- package/backend/dist/local/llamacpp.js +177 -0
- package/backend/dist/local/local-provider.d.ts +81 -0
- package/backend/dist/local/local-provider.js +301 -0
- package/backend/dist/local/machine-stats.d.ts +87 -0
- package/backend/dist/local/machine-stats.js +332 -0
- package/backend/dist/local/model-store.d.ts +347 -0
- package/backend/dist/local/model-store.js +1215 -0
- package/backend/dist/local/part-sweep.d.ts +32 -0
- package/backend/dist/local/part-sweep.js +156 -0
- package/backend/dist/local/plan.d.ts +65 -0
- package/backend/dist/local/plan.js +146 -0
- package/backend/dist/local/resources.d.ts +49 -0
- package/backend/dist/local/resources.js +64 -0
- package/backend/dist/local/run-stats.d.ts +95 -0
- package/backend/dist/local/run-stats.js +195 -0
- package/backend/dist/local/runner.d.ts +235 -0
- package/backend/dist/local/runner.js +1392 -0
- package/backend/dist/local/settings.d.ts +79 -0
- package/backend/dist/local/settings.js +180 -0
- package/backend/dist/local/strata-catalog.d.ts +30 -0
- package/backend/dist/local/strata-catalog.js +511 -0
- package/backend/dist/local/strata-drafting.d.ts +46 -0
- package/backend/dist/local/strata-drafting.js +265 -0
- package/backend/dist/local/strata.d.ts +278 -0
- package/backend/dist/local/strata.js +1392 -0
- package/backend/dist/local/tar.d.ts +20 -0
- package/backend/dist/local/tar.js +367 -0
- package/backend/dist/local/transport.d.ts +35 -0
- package/backend/dist/local/transport.js +89 -0
- package/backend/dist/local/tune.d.ts +58 -0
- package/backend/dist/local/tune.js +324 -0
- package/backend/dist/observability/http-exchange.d.ts +2 -2
- package/backend/dist/opencode/catalog/auto-pull.d.ts +14 -3
- package/backend/dist/opencode/catalog/auto-pull.js +276 -70
- package/backend/dist/opencode/catalog/ocr-store.js +3 -1
- package/backend/dist/opencode/catalog/overrides-store.d.ts +10 -1
- package/backend/dist/opencode/catalog/overrides-store.js +6 -0
- package/backend/dist/opencode/catalog/reasoning-declaration.d.ts +35 -0
- package/backend/dist/opencode/catalog/reasoning-declaration.js +66 -0
- package/backend/dist/opencode/catalog/repository.js +25 -2
- package/backend/dist/opencode/catalog/sources/models-dev.js +13 -3
- package/backend/dist/opencode/catalog/types.d.ts +35 -3
- package/backend/dist/opencode/catalog/types.js +38 -1
- package/backend/dist/opencode/credentials/ocr-store.js +11 -2
- package/backend/dist/opencode/credentials/sync.js +12 -3
- package/backend/dist/opencode/credentials/types.d.ts +31 -4
- package/backend/dist/opencode/credentials/types.js +25 -0
- package/backend/dist/opencode/probe.d.ts +21 -4
- package/backend/dist/opencode/probe.js +34 -10
- package/backend/dist/pipeline/directives.d.ts +9 -4
- package/backend/dist/pipeline/directives.js +14 -10
- package/backend/dist/pipeline/orchestrator.d.ts +42 -13
- package/backend/dist/pipeline/orchestrator.js +497 -165
- package/backend/dist/plugins/environment-ack.d.ts +51 -0
- package/backend/dist/plugins/environment-ack.js +81 -0
- package/backend/dist/plugins/gateways.d.ts +6 -6
- package/backend/dist/plugins/gateways.js +2 -2
- package/backend/dist/plugins/host.d.ts +98 -14
- package/backend/dist/plugins/host.js +622 -87
- package/backend/dist/plugins/install-run.d.ts +27 -0
- package/backend/dist/plugins/install-run.js +99 -0
- package/backend/dist/plugins/manifest.d.ts +84 -32
- package/backend/dist/plugins/manifest.js +149 -45
- package/backend/dist/plugins/market-install.d.ts +18 -0
- package/backend/dist/plugins/market-install.js +111 -0
- package/backend/dist/plugins/market-source.d.ts +100 -0
- package/backend/dist/plugins/market-source.js +449 -0
- package/backend/dist/plugins/market-updates.d.ts +70 -0
- package/backend/dist/plugins/market-updates.js +97 -0
- package/backend/dist/plugins/market.d.ts +677 -0
- package/backend/dist/plugins/market.js +2113 -0
- package/backend/dist/plugins/source-index.d.ts +155 -0
- package/backend/dist/plugins/source-index.js +217 -0
- package/backend/dist/plugins/types.d.ts +402 -37
- package/backend/dist/projects/worktrees.d.ts +88 -0
- package/backend/dist/projects/worktrees.js +220 -0
- package/backend/dist/providers/boot-direct.d.ts +41 -7
- package/backend/dist/providers/boot-direct.js +252 -36
- package/backend/dist/providers/compat/tool-markup-recovery.js +31 -6
- package/backend/dist/providers/executors/dispatch.d.ts +17 -7
- package/backend/dist/providers/executors/dispatch.js +28 -9
- package/backend/dist/providers/executors/openai-chat.js +14 -2
- package/backend/dist/providers/executors/plugin-adapter.d.ts +23 -1
- package/backend/dist/providers/executors/plugin-adapter.js +59 -3
- package/backend/dist/providers/member-match.d.ts +32 -9
- package/backend/dist/providers/member-match.js +65 -21
- package/backend/dist/providers/model-resolution.d.ts +62 -0
- package/backend/dist/providers/model-resolution.js +62 -0
- package/backend/dist/providers/price-order.d.ts +51 -0
- package/backend/dist/providers/price-order.js +54 -0
- package/backend/dist/providers/provider-takedown.d.ts +5 -2
- package/backend/dist/providers/registry.d.ts +84 -25
- package/backend/dist/providers/registry.js +209 -114
- package/backend/dist/providers/selection.d.ts +91 -0
- package/backend/dist/providers/selection.js +158 -0
- package/backend/dist/providers/virtual-meta.d.ts +33 -2
- package/backend/dist/providers/virtual-meta.js +74 -18
- package/backend/dist/quota/cli-login.d.ts +25 -4
- package/backend/dist/quota/cli-login.js +35 -5
- package/backend/dist/quota/coverage-generation.d.ts +24 -0
- package/backend/dist/quota/coverage-generation.js +29 -0
- package/backend/dist/quota/declarations.js +8 -4
- package/backend/dist/quota/engine.js +2 -2
- package/backend/dist/quota/prober.d.ts +43 -2
- package/backend/dist/quota/prober.js +97 -22
- package/backend/dist/ratelimit/rate-limiter.d.ts +1 -1
- package/backend/dist/resilience/error-classifier.js +29 -0
- package/backend/dist/router/index.d.ts +1 -1
- package/backend/dist/router/index.js +17 -1
- package/backend/dist/router/layer2-decision.d.ts +1 -1
- package/backend/dist/router/layer2-decision.js +2 -2
- package/backend/dist/routes/console.js +928 -310
- package/backend/dist/routes/environments.js +1 -1
- package/backend/dist/routes/local-models.d.ts +2 -0
- package/backend/dist/routes/local-models.js +1414 -0
- package/backend/dist/routes/mihomo.d.ts +2 -2
- package/backend/dist/routes/mihomo.js +20 -11
- package/backend/dist/routes/projects.js +121 -0
- package/backend/dist/server.js +318 -13
- package/backend/dist/session/session-manager.d.ts +42 -5
- package/backend/dist/session/session-manager.js +64 -11
- package/backend/dist/session/session-row.d.ts +29 -8
- package/backend/dist/session/session-row.js +18 -13
- package/backend/dist/snapshot/bundle.d.ts +40 -0
- package/backend/dist/snapshot/bundle.js +177 -0
- package/backend/dist/snapshot/handoff/compress.d.ts +46 -0
- package/backend/dist/snapshot/handoff/compress.js +77 -0
- package/backend/dist/snapshot/handoff/index.d.ts +119 -0
- package/backend/dist/snapshot/handoff/index.js +160 -0
- package/backend/dist/snapshot/handoff/jsonl-writer.d.ts +78 -0
- package/backend/dist/snapshot/handoff/jsonl-writer.js +175 -0
- package/backend/dist/snapshot/handoff/opencode-writer.d.ts +51 -0
- package/backend/dist/snapshot/handoff/opencode-writer.js +214 -0
- package/backend/dist/snapshot/handoff/summarize.d.ts +39 -0
- package/backend/dist/snapshot/handoff/summarize.js +118 -0
- package/backend/dist/snapshot/handoff/transcript.d.ts +71 -0
- package/backend/dist/snapshot/handoff/transcript.js +167 -0
- package/backend/dist/snapshot/media-fs.d.ts +10 -0
- package/backend/dist/snapshot/media-fs.js +50 -0
- package/backend/dist/snapshot/media.d.ts +32 -0
- package/backend/dist/snapshot/media.js +87 -0
- package/backend/dist/snapshot/store.d.ts +226 -0
- package/backend/dist/snapshot/store.js +887 -0
- package/backend/dist/snapshot/tree.d.ts +112 -0
- package/backend/dist/snapshot/tree.js +207 -0
- package/backend/dist/snapshot/types.d.ts +212 -0
- package/backend/dist/snapshot/types.js +14 -0
- package/backend/dist/snapshot/view.d.ts +19 -0
- package/backend/dist/snapshot/view.js +57 -0
- package/backend/dist/snapshot/write-worker.d.ts +67 -0
- package/backend/dist/snapshot/write-worker.js +129 -0
- package/backend/dist/surfaces/body-admission.d.ts +67 -2
- package/backend/dist/surfaces/body-admission.js +218 -13
- package/backend/dist/surfaces/chat-pipeline.js +8 -0
- package/backend/dist/surfaces/decision-pipeline.js +10 -7
- package/backend/dist/surfaces/gateway-catalog.d.ts +26 -0
- package/backend/dist/surfaces/gateway-catalog.js +202 -0
- package/backend/dist/surfaces/gateway-chat.d.ts +7 -11
- package/backend/dist/surfaces/gateway-chat.js +50 -12
- package/backend/dist/surfaces/ocr-headers.d.ts +6 -4
- package/backend/dist/surfaces/ocr-headers.js +11 -7
- package/backend/dist/surfaces/systemone.js +1 -1
- package/backend/dist/surfaces/transport-fastify.js +32 -5
- package/backend/dist/surfaces/transport-node-http.d.ts +9 -3
- package/backend/dist/surfaces/transport-node-http.js +6 -19
- package/backend/dist/surfaces/types.d.ts +11 -3
- package/backend/dist/trace/persist.js +21 -1
- package/backend/dist/trace/tracker.d.ts +35 -3
- package/backend/dist/trace/tracker.js +23 -0
- package/backend/dist/types/openai.d.ts +8 -0
- package/backend/dist/types/router.d.ts +17 -6
- package/backend/dist/types/router.js +14 -2
- package/backend/dist/utils/client-families.d.ts +66 -0
- package/backend/dist/utils/client-families.js +127 -0
- package/backend/dist/utils/event-ring.d.ts +1 -1
- package/backend/dist/utils/event-ring.js +1 -1
- package/backend/dist/utils/proxy-node.js +1 -1
- package/backend/dist/utils/proxy.d.ts +135 -11
- package/backend/dist/utils/proxy.js +144 -29
- package/backend/dist/utils/run-command.d.ts +21 -1
- package/backend/dist/utils/run-command.js +64 -4
- package/backend/dist/utils/server-liveness.d.ts +3 -2
- package/backend/dist/utils/server-liveness.js +3 -2
- package/backend/dist/utils/session-file.d.ts +28 -0
- package/backend/dist/utils/session-file.js +34 -0
- package/frontend/dist/assets/antigravity.color-DXFfVr6X.svg +39 -0
- package/frontend/dist/assets/gemini-cli.color-BfquLd1p.svg +1 -0
- package/frontend/dist/assets/index-CTZNvn1d.js +1707 -0
- package/frontend/dist/assets/{index-KI1OW5x6.css → index-CqDSOPQ0.css} +1 -1
- package/frontend/dist/index.html +2 -2
- package/package.json +3 -1
- package/frontend/dist/assets/index-Dk76uc7e.js +0 -1522
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Download + unpack + record an inference engine install (Local Models).
|
|
3
|
+
*
|
|
4
|
+
* Flow per install: resolve the release → match the platform's assets →
|
|
5
|
+
* stream each asset into a `.part` file (resumable, `proxy/asset-download`)
|
|
6
|
+
* → unpack into `<ocrHome>/engines/<engine>/<version>/` → locate the server
|
|
7
|
+
* binaries → persist one record in `engines/installed.json`. Concurrent
|
|
8
|
+
* installs of the same engine serialise on the destination path, mirroring
|
|
9
|
+
* the mihomo core installer.
|
|
10
|
+
*
|
|
11
|
+
* The caller (the admin route) owns progress reporting: every stage change
|
|
12
|
+
* and download tick goes out as one callback event, and an abort leaves the
|
|
13
|
+
* `.part` files on disk so the next click resumes instead of restarting a
|
|
14
|
+
* 700MB CUDA archive.
|
|
15
|
+
*/
|
|
16
|
+
import fs from 'node:fs';
|
|
17
|
+
import path from 'node:path';
|
|
18
|
+
import { unzipSync } from 'fflate';
|
|
19
|
+
import { downloadAssetToFile, cleanupAssetPart, withAssetLock, } from '../egress-proxy/asset-download.js';
|
|
20
|
+
import { engineById, engineInstallKey, engineInstallRoot, readInstalledEngines, writeInstalledEngines, } from './engines.js';
|
|
21
|
+
import { extractTarGz, safeEntryPath } from './tar.js';
|
|
22
|
+
import { localTransport } from './transport.js';
|
|
23
|
+
/** A 4GB ceiling: the biggest current engine asset is ~0.8GB compressed. */
|
|
24
|
+
const MAX_ASSET_BYTES = 4 * 1024 * 1024 * 1024;
|
|
25
|
+
const USER_AGENT = 'omnicell-router';
|
|
26
|
+
/** `<root>/downloads/<asset>.part` — staged beside, never inside, a version dir. */
|
|
27
|
+
function partPathFor(asset) {
|
|
28
|
+
return path.join(engineInstallRoot(), 'downloads', `${asset}.part`);
|
|
29
|
+
}
|
|
30
|
+
/** Release asset download URL (canonical GitHub spelling, tag-encoded). */
|
|
31
|
+
function assetUrl(repo, tag, asset) {
|
|
32
|
+
return `https://github.com/${repo}/releases/download/${encodeURIComponent(tag)}/${encodeURIComponent(asset)}`;
|
|
33
|
+
}
|
|
34
|
+
/** Where one resolved asset lives: the channel's explicit URL when it named
|
|
35
|
+
* one (a feed pins packages to the releases that built them), else the
|
|
36
|
+
* canonical URL on the resolved tag. */
|
|
37
|
+
function downloadUrl(release, repo, asset) {
|
|
38
|
+
return release.assetUrls?.[asset] ?? assetUrl(repo, release.tag, asset);
|
|
39
|
+
}
|
|
40
|
+
/** Look for the engine's server binaries among the unpacked files. */
|
|
41
|
+
function findBinaries(engine, installDir) {
|
|
42
|
+
const wanted = new Set(engine.binaryNames.map((name) => name.toLowerCase()));
|
|
43
|
+
const found = [];
|
|
44
|
+
const visit = (dir, depth) => {
|
|
45
|
+
if (depth > 4)
|
|
46
|
+
return;
|
|
47
|
+
let entries;
|
|
48
|
+
try {
|
|
49
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
for (const entry of entries) {
|
|
55
|
+
const abs = path.join(dir, entry.name);
|
|
56
|
+
if (entry.isDirectory()) {
|
|
57
|
+
visit(abs, depth + 1);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (!entry.isFile())
|
|
61
|
+
continue;
|
|
62
|
+
const base = entry.name.toLowerCase().replace(/\.(exe|bat|cmd)$/i, '');
|
|
63
|
+
if (wanted.has(base))
|
|
64
|
+
found.push(abs);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
visit(installDir, 0);
|
|
68
|
+
return found;
|
|
69
|
+
}
|
|
70
|
+
/** Extract one downloaded asset into the install dir (tar.gz or zip). */
|
|
71
|
+
function extractAsset(asset, partPath, installDir, onProgress) {
|
|
72
|
+
if (asset.endsWith('.tar.gz') || asset.endsWith('.tgz')) {
|
|
73
|
+
return extractTarGz(partPath, installDir, onProgress).then(() => undefined);
|
|
74
|
+
}
|
|
75
|
+
if (asset.endsWith('.zip')) {
|
|
76
|
+
// Buffered: Windows archives ship as zip (llama.cpp builds, Strata's
|
|
77
|
+
// control bundle). A one-shot buffer, not a steady cost.
|
|
78
|
+
const packed = unzipSync(new Uint8Array(fs.readFileSync(partPath)));
|
|
79
|
+
for (const [name, bytes] of Object.entries(packed)) {
|
|
80
|
+
if (name.endsWith('/')) {
|
|
81
|
+
const dir = safeEntryPath(name);
|
|
82
|
+
if (dir)
|
|
83
|
+
fs.mkdirSync(path.join(installDir, dir), { recursive: true });
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const rel = safeEntryPath(name);
|
|
87
|
+
if (!rel)
|
|
88
|
+
continue;
|
|
89
|
+
const dest = path.join(installDir, rel);
|
|
90
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
91
|
+
fs.writeFileSync(dest, bytes);
|
|
92
|
+
}
|
|
93
|
+
return Promise.resolve();
|
|
94
|
+
}
|
|
95
|
+
// Unknown packaging: install the file as-is (single-binary archives).
|
|
96
|
+
const rel = safeEntryPath(asset) ?? 'engine-binary';
|
|
97
|
+
const dest = path.join(installDir, rel);
|
|
98
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
99
|
+
fs.copyFileSync(partPath, dest);
|
|
100
|
+
if (process.platform !== 'win32')
|
|
101
|
+
fs.chmodSync(dest, 0o755);
|
|
102
|
+
return Promise.resolve();
|
|
103
|
+
}
|
|
104
|
+
/** Files an extracted engine tree is recognised by, when an archive wraps
|
|
105
|
+
* everything in one top-level folder. */
|
|
106
|
+
const BUNDLE_MARKERS = ['serve', 'BUNDLE.json', 'VERSION'];
|
|
107
|
+
/**
|
|
108
|
+
* A release archive may wrap its tree in a single top-level folder
|
|
109
|
+
* (`strata-terminal-0.1.69/…` — the vendor's own installer hoists exactly that
|
|
110
|
+
* case). Nothing else in the gateway looks one level down (the front-end is
|
|
111
|
+
* `serve/server.py` at the root of the runtime dir), so the wrapper is HOISTED
|
|
112
|
+
* after extraction. Only a directory that is the sole entry AND looks like a
|
|
113
|
+
* bundle is hoisted — a stray `bin/` from a real archive is left alone, and a
|
|
114
|
+
* bundle already at the root is untouched.
|
|
115
|
+
*/
|
|
116
|
+
export function hoistSingleRoot(dest) {
|
|
117
|
+
let entries;
|
|
118
|
+
try {
|
|
119
|
+
entries = fs.readdirSync(dest, { withFileTypes: true });
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (entries.length !== 1 || !entries[0].isDirectory())
|
|
125
|
+
return;
|
|
126
|
+
const inner = path.join(dest, entries[0].name);
|
|
127
|
+
let names;
|
|
128
|
+
try {
|
|
129
|
+
names = fs.readdirSync(inner);
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (!BUNDLE_MARKERS.some((marker) => names.includes(marker)))
|
|
135
|
+
return;
|
|
136
|
+
for (const name of names) {
|
|
137
|
+
fs.renameSync(path.join(inner, name), path.join(dest, name));
|
|
138
|
+
}
|
|
139
|
+
fs.rmdirSync(inner);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Download and unpack one companion archive — an asset that belongs somewhere
|
|
143
|
+
* OTHER than the engine install directory (Strata's Python front-end lands in
|
|
144
|
+
* the shared runtime directory, versioned with the engine build). Same staging
|
|
145
|
+
* rules as a main asset: resumable `.part`, the destination is cleared only
|
|
146
|
+
* after the download has completed, and an unpack failure drops the part so
|
|
147
|
+
* the next attempt refetches instead of replaying a corrupt archive.
|
|
148
|
+
*
|
|
149
|
+
* @returns the failure result to propagate, or null on success.
|
|
150
|
+
*/
|
|
151
|
+
async function installCompanion(engine, url, asset, dest, position, emit, signal) {
|
|
152
|
+
emit({ type: 'stage', stage: 'download', asset, ...position });
|
|
153
|
+
const partPath = partPathFor(asset);
|
|
154
|
+
const downloaded = await downloadAssetToFile({
|
|
155
|
+
url,
|
|
156
|
+
partPath,
|
|
157
|
+
fetchImpl: localTransport(),
|
|
158
|
+
maxBytes: MAX_ASSET_BYTES,
|
|
159
|
+
headers: { 'User-Agent': USER_AGENT },
|
|
160
|
+
...(signal ? { signal } : {}),
|
|
161
|
+
onProgress: (downloadedBytes, total) => {
|
|
162
|
+
emit({ type: 'progress', asset, downloaded: downloadedBytes, total });
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
if (!downloaded.ok) {
|
|
166
|
+
return { ok: false, code: downloaded.code, error: `${engine.name} ${asset}: ${downloaded.error}` };
|
|
167
|
+
}
|
|
168
|
+
emit({ type: 'stage', stage: 'extract', asset, ...position });
|
|
169
|
+
try {
|
|
170
|
+
fs.rmSync(dest, { recursive: true, force: true });
|
|
171
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
172
|
+
await extractAsset(asset, partPath, dest, (read, total) => {
|
|
173
|
+
emit({ type: 'progress', asset, downloaded: read, total });
|
|
174
|
+
});
|
|
175
|
+
hoistSingleRoot(dest);
|
|
176
|
+
}
|
|
177
|
+
catch (err) {
|
|
178
|
+
cleanupAssetPart(partPath);
|
|
179
|
+
const message = err instanceof Error ? err.message : 'unpack failed';
|
|
180
|
+
// A Windows path over 260 characters fails here without saying why; the
|
|
181
|
+
// vendor's own installer answers it the same way (move the data folder).
|
|
182
|
+
const hint = /ENAMETOOLONG|path too long|too long/i.test(message)
|
|
183
|
+
? ` — the path is too long for this system; point OCR_HOME at a shorter folder (for example C:\\OmniCellRouter) and install again`
|
|
184
|
+
: '';
|
|
185
|
+
return { ok: false, code: 'unpack-failed', error: `${engine.name} ${asset}: ${message}${hint}` };
|
|
186
|
+
}
|
|
187
|
+
cleanupAssetPart(partPath);
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
export async function installEngine(opts) {
|
|
191
|
+
const engine = engineById(opts.engineId);
|
|
192
|
+
if (!engine)
|
|
193
|
+
return { ok: false, code: 'unknown-engine', error: `unknown engine '${opts.engineId}'` };
|
|
194
|
+
const targets = engine.targets(process.platform, process.arch);
|
|
195
|
+
if (targets.length === 0) {
|
|
196
|
+
return { ok: false, code: 'unsupported-platform', error: `no ${engine.name} build for ${process.platform}/${process.arch}` };
|
|
197
|
+
}
|
|
198
|
+
const target = targets.find((item) => item.id === opts.target) ?? targets[0];
|
|
199
|
+
const emit = (event) => opts.onEvent?.(event);
|
|
200
|
+
// Serialise per engine+target: a CUDA reinstall and a first CPU install of
|
|
201
|
+
// the SAME engine share no files and may run side by side.
|
|
202
|
+
return withAssetLock(path.join(engineInstallRoot(), opts.engineId, target.id), async () => {
|
|
203
|
+
emit({ type: 'stage', stage: 'resolve' });
|
|
204
|
+
let release;
|
|
205
|
+
try {
|
|
206
|
+
release = await engine.resolveRelease(localTransport(), opts.signal);
|
|
207
|
+
}
|
|
208
|
+
catch (err) {
|
|
209
|
+
const aborted = opts.signal?.aborted;
|
|
210
|
+
const message = err instanceof Error ? err.message : 'release lookup failed';
|
|
211
|
+
return { ok: false, code: aborted ? 'download-aborted' : 'release-lookup-failed', error: message };
|
|
212
|
+
}
|
|
213
|
+
if (opts.version && opts.version !== release.tag) {
|
|
214
|
+
return { ok: false, code: 'version-missing', error: `${engine.name} ${opts.version} is not the offered release (${release.tag})` };
|
|
215
|
+
}
|
|
216
|
+
const matched = engine.matchAssets({
|
|
217
|
+
platform: process.platform,
|
|
218
|
+
arch: process.arch,
|
|
219
|
+
targetId: target.id,
|
|
220
|
+
tag: release.tag,
|
|
221
|
+
assets: release.assets,
|
|
222
|
+
});
|
|
223
|
+
if (!matched) {
|
|
224
|
+
return { ok: false, code: 'asset-missing', error: `release ${release.tag} has no ${engine.name} asset for target '${target.id}'` };
|
|
225
|
+
}
|
|
226
|
+
emit({ type: 'resolve', tag: release.tag, version: matched.version });
|
|
227
|
+
const installDir = path.join(engineInstallRoot(), engine.id, `${matched.version}-${target.id}`);
|
|
228
|
+
let resumedTotal = 0;
|
|
229
|
+
let extractedOnce = false;
|
|
230
|
+
try {
|
|
231
|
+
for (let assetIndex = 0; assetIndex < matched.assets.length; assetIndex += 1) {
|
|
232
|
+
const asset = matched.assets[assetIndex];
|
|
233
|
+
// Position in a multi-asset install (llama.cpp CUDA = main archive +
|
|
234
|
+
// cudart): without it the second asset's 0→100% looks like the install
|
|
235
|
+
// restarted.
|
|
236
|
+
const position = { assetIndex: assetIndex + 1, assetTotal: matched.assets.length };
|
|
237
|
+
emit({ type: 'stage', stage: 'download', asset, ...position });
|
|
238
|
+
const partPath = partPathFor(asset);
|
|
239
|
+
const downloaded = await downloadAssetToFile({
|
|
240
|
+
url: downloadUrl(release, engine.repo, asset),
|
|
241
|
+
partPath,
|
|
242
|
+
fetchImpl: localTransport(),
|
|
243
|
+
maxBytes: MAX_ASSET_BYTES,
|
|
244
|
+
headers: { 'User-Agent': USER_AGENT },
|
|
245
|
+
...(opts.signal ? { signal: opts.signal } : {}),
|
|
246
|
+
onProgress: (downloadedBytes, total) => {
|
|
247
|
+
emit({ type: 'progress', asset, downloaded: downloadedBytes, total });
|
|
248
|
+
},
|
|
249
|
+
});
|
|
250
|
+
if (!downloaded.ok) {
|
|
251
|
+
return { ok: false, code: downloaded.code, error: `${engine.name} ${asset}: ${downloaded.error}` };
|
|
252
|
+
}
|
|
253
|
+
resumedTotal += downloaded.resumedFrom;
|
|
254
|
+
emit({ type: 'stage', stage: 'extract', asset, ...position });
|
|
255
|
+
try {
|
|
256
|
+
// Clear once, before the FIRST asset lands: a multi-asset install
|
|
257
|
+
// (llama.cpp CUDA = main archive + cudart runtime) unpacks both into
|
|
258
|
+
// the same fresh directory.
|
|
259
|
+
if (!extractedOnce) {
|
|
260
|
+
fs.rmSync(installDir, { recursive: true, force: true });
|
|
261
|
+
fs.mkdirSync(installDir, { recursive: true });
|
|
262
|
+
extractedOnce = true;
|
|
263
|
+
}
|
|
264
|
+
await extractAsset(asset, partPath, installDir, (read, total) => {
|
|
265
|
+
// Same event shape as the download leg: stage stays 'extract'
|
|
266
|
+
// (stamped above), downloaded/total become archive-read bytes.
|
|
267
|
+
emit({ type: 'progress', asset, downloaded: read, total });
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
catch (err) {
|
|
271
|
+
// An archive that downloads but will not unpack is dead weight: drop
|
|
272
|
+
// the part so the next attempt refetches instead of replaying it.
|
|
273
|
+
cleanupAssetPart(partPath);
|
|
274
|
+
fs.rmSync(installDir, { recursive: true, force: true });
|
|
275
|
+
const message = err instanceof Error ? err.message : 'unpack failed';
|
|
276
|
+
return { ok: false, code: 'unpack-failed', error: `${engine.name} ${asset}: ${message}` };
|
|
277
|
+
}
|
|
278
|
+
cleanupAssetPart(partPath);
|
|
279
|
+
}
|
|
280
|
+
const companions = matched.companions ?? [];
|
|
281
|
+
for (let i = 0; i < companions.length; i += 1) {
|
|
282
|
+
const companion = companions[i];
|
|
283
|
+
// Companion legs extend the SAME position counter, so a strata install
|
|
284
|
+
// reads "1/2, 2/2" instead of the front-end restarting the bar at 1/1.
|
|
285
|
+
const position = {
|
|
286
|
+
assetIndex: matched.assets.length + i + 1,
|
|
287
|
+
assetTotal: matched.assets.length + companions.length,
|
|
288
|
+
};
|
|
289
|
+
const failed = await installCompanion(engine, downloadUrl(release, engine.repo, companion.asset), companion.asset, companion.dest, position, emit, opts.signal);
|
|
290
|
+
if (failed)
|
|
291
|
+
return failed;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
catch (err) {
|
|
295
|
+
if (opts.signal?.aborted)
|
|
296
|
+
return { ok: false, code: 'download-aborted', error: 'download cancelled' };
|
|
297
|
+
const message = err instanceof Error ? err.message : 'install failed';
|
|
298
|
+
return { ok: false, code: 'install-failed', error: message };
|
|
299
|
+
}
|
|
300
|
+
emit({ type: 'stage', stage: 'finalize' });
|
|
301
|
+
if (process.platform !== 'win32') {
|
|
302
|
+
// tar modes may arrive masked; make anything executable-looking runnable.
|
|
303
|
+
try {
|
|
304
|
+
for (const binary of findBinaries(engine, installDir))
|
|
305
|
+
fs.chmodSync(binary, 0o755);
|
|
306
|
+
}
|
|
307
|
+
catch {
|
|
308
|
+
// A non-executable binary surfaces at launch, not here.
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
const binaries = findBinaries(engine, installDir);
|
|
312
|
+
const installed = {
|
|
313
|
+
engine: engine.id,
|
|
314
|
+
version: matched.version,
|
|
315
|
+
target: target.id,
|
|
316
|
+
installDir,
|
|
317
|
+
binaries,
|
|
318
|
+
installedAt: Date.now(),
|
|
319
|
+
};
|
|
320
|
+
let supersededDir = null;
|
|
321
|
+
try {
|
|
322
|
+
const state = readInstalledEngines();
|
|
323
|
+
const key = engineInstallKey(engine.id, target.id);
|
|
324
|
+
// An UPGRADE shares the state key with the build it replaces (the key is
|
|
325
|
+
// engine:target, never engine:version), so the outgoing record is the only
|
|
326
|
+
// pointer to a version directory that becomes unreachable at this write.
|
|
327
|
+
// Report it instead of deleting here: whether that directory may go is
|
|
328
|
+
// run knowledge (a live engine may be serving its binary), and this module
|
|
329
|
+
// deliberately knows nothing about runs.
|
|
330
|
+
const previous = state[key];
|
|
331
|
+
if (previous
|
|
332
|
+
&& path.resolve(previous.installDir) !== path.resolve(installDir)
|
|
333
|
+
&& fs.existsSync(previous.installDir)) {
|
|
334
|
+
supersededDir = previous.installDir;
|
|
335
|
+
}
|
|
336
|
+
state[key] = installed;
|
|
337
|
+
writeInstalledEngines(state);
|
|
338
|
+
}
|
|
339
|
+
catch (err) {
|
|
340
|
+
const message = err instanceof Error ? err.message : 'state write failed';
|
|
341
|
+
return { ok: false, code: 'install-failed', error: `engine installed but the record write failed (${message})` };
|
|
342
|
+
}
|
|
343
|
+
return {
|
|
344
|
+
ok: true,
|
|
345
|
+
installed,
|
|
346
|
+
resumedFrom: resumedTotal,
|
|
347
|
+
...(supersededDir ? { supersededDir } : {}),
|
|
348
|
+
};
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Delete the version directory an upgrade replaced, unless a caller-supplied
|
|
353
|
+
* check says something still needs it.
|
|
354
|
+
*
|
|
355
|
+
* The install record is keyed `engine:target` (never `engine:version`), so an
|
|
356
|
+
* upgrade overwrites the only pointer to the outgoing directory: it survives as
|
|
357
|
+
* an orphan — hundreds of MB per CUDA build — that no UI can reach or remove.
|
|
358
|
+
* Settling the state record IS the upgrade; this is the second half.
|
|
359
|
+
*
|
|
360
|
+
* `inUse` is the caller's knowledge (the route asks the runner), so this module
|
|
361
|
+
* stays run-agnostic. A skipped directory is only wasted disk, never a broken
|
|
362
|
+
* install: the record already points at the new build.
|
|
363
|
+
*
|
|
364
|
+
* @returns true when the directory was deleted.
|
|
365
|
+
*/
|
|
366
|
+
export function pruneSupersededInstall(dir, inUse = () => false) {
|
|
367
|
+
if (!dir)
|
|
368
|
+
return false;
|
|
369
|
+
// Only ever delete inside the engines root: the path comes from a record we
|
|
370
|
+
// wrote, but a corrupt one must not aim the deletion at an arbitrary folder.
|
|
371
|
+
const root = path.resolve(engineInstallRoot());
|
|
372
|
+
const target = path.resolve(dir);
|
|
373
|
+
if (!target.startsWith(root + path.sep))
|
|
374
|
+
return false;
|
|
375
|
+
if (path.basename(target) === path.basename(root))
|
|
376
|
+
return false;
|
|
377
|
+
// Nothing there to reclaim (an interrupted sweep, or an upgrade whose old
|
|
378
|
+
// directory was already removed by hand). Explicit, so callers can tell
|
|
379
|
+
// "swept it" from "there was nothing to sweep".
|
|
380
|
+
if (!fs.existsSync(target))
|
|
381
|
+
return false;
|
|
382
|
+
try {
|
|
383
|
+
if (inUse(target))
|
|
384
|
+
return false;
|
|
385
|
+
fs.rmSync(target, { recursive: true, force: true, maxRetries: 2 });
|
|
386
|
+
return true;
|
|
387
|
+
}
|
|
388
|
+
catch {
|
|
389
|
+
return false;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
/** Remove one engine install (one build target) and its state record. */
|
|
393
|
+
export function uninstallEngine(engineId, target) {
|
|
394
|
+
const state = readInstalledEngines();
|
|
395
|
+
const key = engineInstallKey(engineId, target);
|
|
396
|
+
const record = state[key];
|
|
397
|
+
if (!record)
|
|
398
|
+
return { ok: false, error: 'engine is not installed' };
|
|
399
|
+
// Only ever delete inside the engines root — the record is a file we wrote,
|
|
400
|
+
// but a corrupt one must not point the deletion at an arbitrary directory.
|
|
401
|
+
const root = path.resolve(engineInstallRoot());
|
|
402
|
+
const dir = path.resolve(record.installDir);
|
|
403
|
+
if (!dir.startsWith(root + path.sep)) {
|
|
404
|
+
return { ok: false, error: 'install record points outside the engines root; remove it manually' };
|
|
405
|
+
}
|
|
406
|
+
try {
|
|
407
|
+
fs.rmSync(dir, { recursive: true, force: true, maxRetries: 2 });
|
|
408
|
+
}
|
|
409
|
+
catch (err) {
|
|
410
|
+
const message = err instanceof Error ? err.message : 'delete failed';
|
|
411
|
+
return { ok: false, error: `could not delete the install directory (${message})` };
|
|
412
|
+
}
|
|
413
|
+
delete state[key];
|
|
414
|
+
try {
|
|
415
|
+
writeInstalledEngines(state);
|
|
416
|
+
}
|
|
417
|
+
catch {
|
|
418
|
+
// Directory gone; a failed state write only leaves a stale row.
|
|
419
|
+
}
|
|
420
|
+
return { ok: true };
|
|
421
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { EngineRuntime } from './engine-runtime.js';
|
|
2
|
+
/** The run-option slice llama.cpp's argv reads. */
|
|
3
|
+
export interface LlamaRunOptionsLike {
|
|
4
|
+
flashAttn: boolean;
|
|
5
|
+
kvCacheQ8: boolean;
|
|
6
|
+
reasoning: boolean;
|
|
7
|
+
threads: number;
|
|
8
|
+
extraArgs: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface LlamaLaunchFacts {
|
|
11
|
+
port: number;
|
|
12
|
+
host: string;
|
|
13
|
+
ctx: number;
|
|
14
|
+
ngl: number;
|
|
15
|
+
/** The operator-chosen model name (ADR-0044 §7) — served as `--alias`. */
|
|
16
|
+
servedName?: string;
|
|
17
|
+
options: LlamaRunOptionsLike;
|
|
18
|
+
/** Already validated (`llamaDraftArgs`). Empty when the draft is off. */
|
|
19
|
+
draftArgs?: string[];
|
|
20
|
+
}
|
|
21
|
+
/** llama-server argument list for one launch — the plan made literal. */
|
|
22
|
+
export declare function llamaServerArgs(run: LlamaLaunchFacts, modelPath: string): string[];
|
|
23
|
+
/** `--spec-type` values this build accepts, minus `none` (the empty choice).
|
|
24
|
+
* Names match llama.cpp's speculative doc. A separate GGUF is required for
|
|
25
|
+
* every drafter except MTP (heads inside the main file) and n-gram.
|
|
26
|
+
* `draft-dspine` is not in this build. */
|
|
27
|
+
export declare const LLAMA_SPEC_TYPES: ReadonlyArray<{
|
|
28
|
+
value: string;
|
|
29
|
+
label: string;
|
|
30
|
+
labelKey?: string;
|
|
31
|
+
needsModel: boolean;
|
|
32
|
+
}>;
|
|
33
|
+
export interface LlamaProfile {
|
|
34
|
+
specType?: string;
|
|
35
|
+
draftModel?: string;
|
|
36
|
+
}
|
|
37
|
+
export declare function normalizeLlamaProfile(raw: unknown): {
|
|
38
|
+
ok: true;
|
|
39
|
+
profile: LlamaProfile;
|
|
40
|
+
} | {
|
|
41
|
+
ok: false;
|
|
42
|
+
code: string;
|
|
43
|
+
error: string;
|
|
44
|
+
};
|
|
45
|
+
/** Flags for one draft choice. A `draft-*` type with no file is a launch error. */
|
|
46
|
+
export declare function llamaDraftArgs(profile: LlamaProfile): {
|
|
47
|
+
ok: true;
|
|
48
|
+
args: string[];
|
|
49
|
+
} | {
|
|
50
|
+
ok: false;
|
|
51
|
+
error: string;
|
|
52
|
+
};
|
|
53
|
+
export declare const LLAMACPP_RUNTIME: EngineRuntime;
|
|
54
|
+
/** Directory a llama.cpp binary's runtime DLLs live in. */
|
|
55
|
+
export declare function llamacppCwd(binary: string): string;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* llama.cpp runtime — the reference implementation of `EngineRuntime`.
|
|
3
|
+
*
|
|
4
|
+
* llama-server is the permissive engine: any GGUF, gateway-owned placement
|
|
5
|
+
* (`-ngl N` is literally the plan made literal), and every shared run control
|
|
6
|
+
* maps onto a flag. It therefore declares `placement: 'gateway'` and one leg.
|
|
7
|
+
* The only profile it keeps is the draft choice: `--spec-type` plus, for a
|
|
8
|
+
* `draft-*` type, `--spec-draft-model`. The list is what build b12728's
|
|
9
|
+
* `--help` prints. `draft-dspine` is not in that list.
|
|
10
|
+
*/
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
/** llama-server argument list for one launch — the plan made literal. */
|
|
13
|
+
export function llamaServerArgs(run, modelPath) {
|
|
14
|
+
const args = [
|
|
15
|
+
'-m', modelPath,
|
|
16
|
+
'--host', run.host,
|
|
17
|
+
'--port', String(run.port),
|
|
18
|
+
'-c', String(run.ctx),
|
|
19
|
+
'-ngl', String(run.ngl),
|
|
20
|
+
// Verbosity 4 keeps the device enumeration and memory breakdown in the
|
|
21
|
+
// log ring (recent llama.cpp builds print them only at -lv ≥ 4); the
|
|
22
|
+
// console's log viewer is how operators verify GPU offload.
|
|
23
|
+
'-lv', '4',
|
|
24
|
+
];
|
|
25
|
+
// The server answers as the operator's name, so its /v1/models and the
|
|
26
|
+
// gateway's `local/<name>` registration never disagree.
|
|
27
|
+
if (run.servedName)
|
|
28
|
+
args.push('--alias', run.servedName);
|
|
29
|
+
if (run.options.flashAttn)
|
|
30
|
+
args.push('--flash-attn', 'on');
|
|
31
|
+
if (run.options.kvCacheQ8)
|
|
32
|
+
args.push('--cache-type-k', 'q8_0', '--cache-type-v', 'q8_0');
|
|
33
|
+
if (run.options.reasoning)
|
|
34
|
+
args.push('--jinja', '--reasoning-format', 'auto');
|
|
35
|
+
if (run.options.threads > 0)
|
|
36
|
+
args.push('-t', String(run.options.threads));
|
|
37
|
+
if (run.draftArgs)
|
|
38
|
+
args.push(...run.draftArgs);
|
|
39
|
+
args.push(...run.options.extraArgs);
|
|
40
|
+
return args;
|
|
41
|
+
}
|
|
42
|
+
/** `--spec-type` values this build accepts, minus `none` (the empty choice).
|
|
43
|
+
* Names match llama.cpp's speculative doc. A separate GGUF is required for
|
|
44
|
+
* every drafter except MTP (heads inside the main file) and n-gram.
|
|
45
|
+
* `draft-dspine` is not in this build. */
|
|
46
|
+
export const LLAMA_SPEC_TYPES = [
|
|
47
|
+
{ value: 'draft-simple', label: 'draft-simple', labelKey: 'localModels.runSpecDraftSimple', needsModel: true },
|
|
48
|
+
{ value: 'draft-eagle3', label: 'EAGLE-3', needsModel: true },
|
|
49
|
+
{ value: 'draft-mtp', label: 'MTP', needsModel: false },
|
|
50
|
+
{ value: 'draft-dflash', label: 'DFlash', needsModel: true },
|
|
51
|
+
{ value: 'draft-dflash2', label: 'DFlash2', needsModel: true },
|
|
52
|
+
{ value: 'draft-dspark', label: 'DSpark', needsModel: true },
|
|
53
|
+
{ value: 'draft-lilicorr', label: 'LiliCorr', needsModel: true },
|
|
54
|
+
{ value: 'ngram-simple', label: 'ngram-simple', labelKey: 'localModels.runSpecNgramSimple', needsModel: false },
|
|
55
|
+
{ value: 'ngram-cache', label: 'ngram-cache', labelKey: 'localModels.runSpecNgramCache', needsModel: false },
|
|
56
|
+
{ value: 'ngram-map-k', label: 'ngram-map-k', labelKey: 'localModels.runSpecNgramMapK', needsModel: false },
|
|
57
|
+
{ value: 'ngram-map-k4v', label: 'ngram-map-k4v', labelKey: 'localModels.runSpecNgramMapK4v', needsModel: false },
|
|
58
|
+
{ value: 'ngram-mod', label: 'ngram-mod', labelKey: 'localModels.runSpecNgramMod', needsModel: false },
|
|
59
|
+
];
|
|
60
|
+
const LLAMA_SPEC_VALUES = new Set(LLAMA_SPEC_TYPES.map((row) => row.value));
|
|
61
|
+
function llamaStr(value) {
|
|
62
|
+
if (typeof value !== 'string')
|
|
63
|
+
return undefined;
|
|
64
|
+
const trimmed = value.trim();
|
|
65
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
66
|
+
}
|
|
67
|
+
export function normalizeLlamaProfile(raw) {
|
|
68
|
+
if (raw === undefined || raw === null)
|
|
69
|
+
return { ok: true, profile: {} };
|
|
70
|
+
if (typeof raw !== 'object' || Array.isArray(raw)) {
|
|
71
|
+
return { ok: false, code: 'profile-invalid', error: 'llama.cpp profile must be an object' };
|
|
72
|
+
}
|
|
73
|
+
const src = raw;
|
|
74
|
+
const profile = {};
|
|
75
|
+
const specType = llamaStr(src.specType);
|
|
76
|
+
if (specType && LLAMA_SPEC_VALUES.has(specType))
|
|
77
|
+
profile.specType = specType;
|
|
78
|
+
const draftModel = llamaStr(src.draftModel);
|
|
79
|
+
if (draftModel)
|
|
80
|
+
profile.draftModel = draftModel;
|
|
81
|
+
return { ok: true, profile };
|
|
82
|
+
}
|
|
83
|
+
/** Flags for one draft choice. A `draft-*` type with no file is a launch error. */
|
|
84
|
+
export function llamaDraftArgs(profile) {
|
|
85
|
+
if (!profile.specType)
|
|
86
|
+
return { ok: true, args: [] };
|
|
87
|
+
const row = LLAMA_SPEC_TYPES.find((item) => item.value === profile.specType);
|
|
88
|
+
if (!row)
|
|
89
|
+
return { ok: true, args: [] };
|
|
90
|
+
if (row.needsModel && !profile.draftModel) {
|
|
91
|
+
return { ok: false, error: `spec-type ${row.value} needs a draft GGUF (the draft-model path)` };
|
|
92
|
+
}
|
|
93
|
+
const args = ['--spec-type', row.value];
|
|
94
|
+
if (row.needsModel && profile.draftModel)
|
|
95
|
+
args.push('-md', profile.draftModel);
|
|
96
|
+
return { ok: true, args };
|
|
97
|
+
}
|
|
98
|
+
const LLAMA_PROFILE = {
|
|
99
|
+
intro: 'localModels.llamacppProfileIntro',
|
|
100
|
+
groups: [{
|
|
101
|
+
id: 'draft',
|
|
102
|
+
label: 'localModels.runSpec',
|
|
103
|
+
fields: [
|
|
104
|
+
{
|
|
105
|
+
key: 'specType',
|
|
106
|
+
label: 'localModels.runSpec',
|
|
107
|
+
hint: 'localModels.runSpecLlamaHint',
|
|
108
|
+
kind: 'select',
|
|
109
|
+
// The run page owns the draft select (it is where the paired draft GGUF
|
|
110
|
+
// is picked alongside it); the drawer must not paint a second copy.
|
|
111
|
+
runPageOwned: true,
|
|
112
|
+
placeholderKey: 'localModels.runSpecOff',
|
|
113
|
+
options: LLAMA_SPEC_TYPES.map((row) => ({
|
|
114
|
+
value: row.value,
|
|
115
|
+
label: row.label,
|
|
116
|
+
...(row.labelKey ? { labelKey: row.labelKey } : {}),
|
|
117
|
+
...(row.needsModel ? { needsModel: true } : {}),
|
|
118
|
+
})),
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
key: 'draftModel',
|
|
122
|
+
label: 'localModels.runDraftModel',
|
|
123
|
+
hint: 'localModels.runDraftModelHint',
|
|
124
|
+
kind: 'text',
|
|
125
|
+
runPageOwned: true,
|
|
126
|
+
mono: true,
|
|
127
|
+
picker: 'file',
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
}],
|
|
131
|
+
normalize: (raw) => normalizeLlamaProfile(raw),
|
|
132
|
+
paths: (raw) => {
|
|
133
|
+
const profile = normalizeLlamaProfile(raw);
|
|
134
|
+
if (!profile.ok || !profile.profile.draftModel)
|
|
135
|
+
return [];
|
|
136
|
+
const row = LLAMA_SPEC_TYPES.find((item) => item.value === profile.profile.specType);
|
|
137
|
+
return row?.needsModel ? [profile.profile.draftModel] : [];
|
|
138
|
+
},
|
|
139
|
+
describe: () => ({ argv: [], features: [] }),
|
|
140
|
+
};
|
|
141
|
+
export const LLAMACPP_RUNTIME = {
|
|
142
|
+
// The layer planner computes the split; `-ngl` is how it is handed over.
|
|
143
|
+
placement: 'gateway',
|
|
144
|
+
accepts: { ngl: true, threads: true, flashAttn: true, kv: true, reasoning: true, spec: true, vision: false },
|
|
145
|
+
profile: LLAMA_PROFILE,
|
|
146
|
+
serves: ({ modelPath }) => (modelPath.toLowerCase().endsWith('.gguf')
|
|
147
|
+
? { serves: true, family: true }
|
|
148
|
+
: { serves: false, reason: 'llama.cpp loads GGUF checkpoints; this file is not one, so this engine cannot serve it' }),
|
|
149
|
+
legs: async (facts) => {
|
|
150
|
+
const normalized = normalizeLlamaProfile(facts.profile);
|
|
151
|
+
if (!normalized.ok)
|
|
152
|
+
return { error: normalized.error };
|
|
153
|
+
const draft = llamaDraftArgs(normalized.profile);
|
|
154
|
+
if (!draft.ok)
|
|
155
|
+
return { error: draft.error };
|
|
156
|
+
const leg = {
|
|
157
|
+
key: facts.runId,
|
|
158
|
+
cmd: facts.binary,
|
|
159
|
+
args: llamaServerArgs({
|
|
160
|
+
port: facts.port,
|
|
161
|
+
host: facts.host,
|
|
162
|
+
ctx: facts.ctx,
|
|
163
|
+
ngl: facts.ngl,
|
|
164
|
+
...(facts.servedName ? { servedName: facts.servedName } : {}),
|
|
165
|
+
options: facts.options,
|
|
166
|
+
...(draft.args.length > 0 ? { draftArgs: draft.args } : {}),
|
|
167
|
+
}, facts.modelPath),
|
|
168
|
+
cwd: path.dirname(facts.binary),
|
|
169
|
+
aux: false,
|
|
170
|
+
};
|
|
171
|
+
return [leg];
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
/** Directory a llama.cpp binary's runtime DLLs live in. */
|
|
175
|
+
export function llamacppCwd(binary) {
|
|
176
|
+
return path.dirname(binary);
|
|
177
|
+
}
|