omnicell-router 0.8.2 → 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/auth/api-keys.js +11 -0
- package/backend/dist/auth/key-models.d.ts +36 -0
- package/backend/dist/auth/key-models.js +99 -0
- package/backend/dist/capture/recorder.d.ts +4 -10
- package/backend/dist/capture/recorder.js +6 -58
- package/backend/dist/cli/clients/activity.js +2 -0
- 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 +78 -0
- package/backend/dist/cli/clients/codex.js +475 -57
- 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/follow-catalog-sync.d.ts +62 -0
- package/backend/dist/cli/clients/follow-catalog-sync.js +435 -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 +8 -2
- package/backend/dist/cli/clients/pi.d.ts +6 -0
- package/backend/dist/cli/clients/pi.js +3 -0
- package/backend/dist/cli/clients/reserved.js +2 -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 +101 -16
- package/backend/dist/config/comments-en.js +34 -25
- package/backend/dist/config/comments-zh.js +33 -24
- package/backend/dist/config/defaults.d.ts +280 -22
- package/backend/dist/config/defaults.js +279 -21
- package/backend/dist/config/env.d.ts +10 -0
- package/backend/dist/config/env.js +3 -2
- package/backend/dist/config/index.d.ts +22 -1
- package/backend/dist/config/index.js +218 -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/v4-to-v5.d.ts +36 -0
- package/backend/dist/config/migrations/v4-to-v5.js +42 -0
- package/backend/dist/config/migrations/v5-to-v6.d.ts +27 -0
- package/backend/dist/config/migrations/v5-to-v6.js +29 -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 +18 -4
- package/backend/dist/config/types.d.ts +221 -41
- 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 +63 -17
- package/backend/dist/forward-proxy/h2-forward.js +42 -15
- package/backend/dist/forward-proxy/index.d.ts +11 -8
- package/backend/dist/forward-proxy/index.js +27 -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 +12 -16
- package/backend/dist/forward-proxy/server.js +237 -171
- package/backend/dist/harness/host/hosts.js +3 -2
- package/backend/dist/index.js +59 -19
- 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 +50 -6
- 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 +92 -1
- package/backend/dist/ir/adapters/openai-responses.js +163 -12
- package/backend/dist/ir/capabilities.js +4 -0
- 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/ir/validate.d.ts +24 -0
- package/backend/dist/ir/validate.js +113 -63
- 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 +284 -77
- package/backend/dist/opencode/catalog/ocr-store.d.ts +7 -6
- package/backend/dist/opencode/catalog/ocr-store.js +4 -2
- package/backend/dist/opencode/catalog/overrides-store.d.ts +15 -4
- package/backend/dist/opencode/catalog/overrides-store.js +28 -19
- 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 +28 -5
- package/backend/dist/opencode/catalog/sources/models-dev.d.ts +3 -3
- package/backend/dist/opencode/catalog/sources/models-dev.js +42 -14
- package/backend/dist/opencode/catalog/types.d.ts +42 -12
- package/backend/dist/opencode/catalog/types.js +38 -1
- package/backend/dist/opencode/credentials/def-materialize.js +27 -21
- 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/migrate/engine.d.ts +20 -0
- package/backend/dist/opencode/migrate/engine.js +71 -0
- package/backend/dist/opencode/migrate/migrator.d.ts +11 -0
- package/backend/dist/opencode/migrate/migrator.js +6 -0
- package/backend/dist/opencode/migrate/steps/overrides-v1-to-v2.d.ts +6 -0
- package/backend/dist/opencode/migrate/steps/overrides-v1-to-v2.js +31 -0
- package/backend/dist/opencode/migrate/steps/providers-v1-to-v2.d.ts +6 -0
- package/backend/dist/opencode/migrate/steps/providers-v1-to-v2.js +62 -0
- package/backend/dist/opencode/probe.d.ts +21 -4
- package/backend/dist/opencode/probe.js +34 -10
- package/backend/dist/opencode/provider-def-adapters.d.ts +12 -11
- package/backend/dist/opencode/provider-def-adapters.js +43 -27
- package/backend/dist/opencode/provider-defs.d.ts +10 -16
- package/backend/dist/opencode/provider-defs.js +45 -45
- package/backend/dist/opencode/user-config.d.ts +23 -26
- package/backend/dist/opencode/user-config.js +95 -77
- 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 +514 -172
- package/backend/dist/plugins/builtin/model-gateway.js +38 -12
- 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 +100 -16
- package/backend/dist/plugins/host.js +637 -99
- 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 +284 -44
- package/backend/dist/providers/compat/tool-markup-recovery.js +31 -6
- package/backend/dist/providers/dial-wire.d.ts +17 -0
- package/backend/dist/providers/dial-wire.js +49 -0
- 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/protocols-field.d.ts +24 -0
- package/backend/dist/providers/protocols-field.js +66 -0
- package/backend/dist/providers/provider-takedown.d.ts +5 -2
- package/backend/dist/providers/registry.d.ts +87 -26
- package/backend/dist/providers/registry.js +232 -121
- 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 +38 -6
- 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 +1043 -405
- 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 +409 -15
- 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/anthropic.js +4 -1
- package/backend/dist/surfaces/body-admission.d.ts +344 -0
- package/backend/dist/surfaces/body-admission.js +818 -0
- 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 +51 -6
- package/backend/dist/surfaces/transport-node-http.js +76 -16
- 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 +28 -0
- package/backend/dist/utils/server-liveness.js +32 -0
- 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-DxZ9MHKB.css → index-CqDSOPQ0.css} +1 -1
- package/frontend/dist/index.html +2 -2
- package/package.json +3 -1
- package/frontend/dist/assets/index-55VVwfFQ.js +0 -1521
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A staged part older than this is reclaimed. Deliberately longer than the
|
|
3
|
+
* 24 h resume TTL: past the TTL the prefix is already unusable, so reclaiming
|
|
4
|
+
* it is never a re-download the operator did not already pay for.
|
|
5
|
+
*/
|
|
6
|
+
export declare const ABANDONED_PART_AGE_MS: number;
|
|
7
|
+
export interface PartSweepStats {
|
|
8
|
+
removed: number;
|
|
9
|
+
bytes: number;
|
|
10
|
+
}
|
|
11
|
+
/** Both places the asset pipeline stages a transfer under this gateway. */
|
|
12
|
+
export declare function downloadStageDirs(): string[];
|
|
13
|
+
/**
|
|
14
|
+
* Delete staged parts under `dirs` older than `maxAgeMs`, plus the sidecars
|
|
15
|
+
* whose part is already gone (an orphan validator would make the next attempt
|
|
16
|
+
* look like a resume). Never throws: an unreadable directory is skipped, since
|
|
17
|
+
* a reclaimer must not break boot.
|
|
18
|
+
*/
|
|
19
|
+
export declare function sweepAbandonedParts(opts?: {
|
|
20
|
+
dirs?: string[];
|
|
21
|
+
now?: number;
|
|
22
|
+
maxAgeMs?: number;
|
|
23
|
+
}): PartSweepStats;
|
|
24
|
+
/** Staged bytes under `dirs` — what the sweep below would eventually reclaim. */
|
|
25
|
+
export declare function partBytesIn(dirs: string[]): number;
|
|
26
|
+
/** Unfinished downloads staged inside the models tree (the market's card). */
|
|
27
|
+
export declare function modelPartBytes(): number;
|
|
28
|
+
/** Engine archives staged under `engines/downloads` (the engines card). */
|
|
29
|
+
export declare function engineDownloadPartBytes(): number;
|
|
30
|
+
/** Boot pass plus the hourly beat; idempotent so a second registration (tests,
|
|
31
|
+
* a re-mounted router) does not stack timers. */
|
|
32
|
+
export declare function startAbandonedPartSweep(): void;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reclaim the staged `.part` files an ABANDONED transfer leaves behind.
|
|
3
|
+
*
|
|
4
|
+
* The asset pipeline (`egress-proxy/asset-download`) deliberately KEEPS a
|
|
5
|
+
* partial file when a transfer is cancelled or dropped (ADR-0022): the next
|
|
6
|
+
* click resumes from it instead of re-downloading tens of gigabytes. But that
|
|
7
|
+
* keep is conditional on a RETRY — `PART_TTL_MS` only decides whether a stored
|
|
8
|
+
* prefix may be spliced into a new attempt, and nothing deletes a part whose
|
|
9
|
+
* file is never fetched again. Such a part has no registry row, so neither
|
|
10
|
+
* `removeHfModel` nor the engine uninstall can reach it: it sits in
|
|
11
|
+
* `models/<owner>/<repo>/<file>.part` or `engines/downloads/<asset>.part`
|
|
12
|
+
* forever. This sweep is the missing other half.
|
|
13
|
+
*
|
|
14
|
+
* Two properties make it safe without consulting the downloader's state:
|
|
15
|
+
*
|
|
16
|
+
* - **Age, never a lock.** `withAssetLock` keys differ per caller (the model
|
|
17
|
+
* store locks the FINAL path, the engine installer locks a directory), so a
|
|
18
|
+
* lock probe would be wrong for at least one of them. A part whose mtime is
|
|
19
|
+
* older than the window cannot be mid-transfer — the write stream touches
|
|
20
|
+
* mtime on every chunk.
|
|
21
|
+
* - **Longer than the resume TTL.** `PART_TTL_MS` is 24 h: a part older than
|
|
22
|
+
* that is refused by the resume path and the next attempt deletes it anyway
|
|
23
|
+
* (`cleanupAssetPart` at `resumeFrom === 0`). Sweeping later than the TTL can
|
|
24
|
+
* never remove a prefix a retry would have used, so the sweep is a reclaimer,
|
|
25
|
+
* not a policy change.
|
|
26
|
+
*
|
|
27
|
+
* Deletion goes through `cleanupAssetPart`, so the `.part.json` sidecar travels
|
|
28
|
+
* with the file it describes and is never left behind alone.
|
|
29
|
+
*/
|
|
30
|
+
import fs from 'node:fs';
|
|
31
|
+
import path from 'node:path';
|
|
32
|
+
import { cleanupAssetPart } from '../egress-proxy/asset-download.js';
|
|
33
|
+
import { engineInstallRoot } from './engines.js';
|
|
34
|
+
import { modelsRoot } from './model-store.js';
|
|
35
|
+
/**
|
|
36
|
+
* A staged part older than this is reclaimed. Deliberately longer than the
|
|
37
|
+
* 24 h resume TTL: past the TTL the prefix is already unusable, so reclaiming
|
|
38
|
+
* it is never a re-download the operator did not already pay for.
|
|
39
|
+
*/
|
|
40
|
+
export const ABANDONED_PART_AGE_MS = 7 * 24 * 60 * 60 * 1000;
|
|
41
|
+
/** Boot sweep plus one pass an hour — the same reader-free beat the other
|
|
42
|
+
* retention sweeps use; a stale part costs nothing while it waits. */
|
|
43
|
+
const PART_SWEEP_INTERVAL_MS = 60 * 60 * 1000;
|
|
44
|
+
/** The models tree nests `<owner>/<repo>/…`; a ready-made pack adds `pack/`. */
|
|
45
|
+
const MAX_WALK_DEPTH = 6;
|
|
46
|
+
/** Both places the asset pipeline stages a transfer under this gateway. */
|
|
47
|
+
export function downloadStageDirs() {
|
|
48
|
+
return [modelsRoot(), path.join(engineInstallRoot(), 'downloads')];
|
|
49
|
+
}
|
|
50
|
+
function safeStat(target) {
|
|
51
|
+
try {
|
|
52
|
+
return fs.statSync(target);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** Every `.part` and `.part.json` under one staging root. */
|
|
59
|
+
function collectParts(dir, depth, parts, sidecars) {
|
|
60
|
+
if (depth > MAX_WALK_DEPTH)
|
|
61
|
+
return;
|
|
62
|
+
let entries;
|
|
63
|
+
try {
|
|
64
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
for (const entry of entries) {
|
|
70
|
+
const abs = path.join(dir, entry.name);
|
|
71
|
+
if (entry.isDirectory()) {
|
|
72
|
+
collectParts(abs, depth + 1, parts, sidecars);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (!entry.isFile())
|
|
76
|
+
continue;
|
|
77
|
+
if (entry.name.endsWith('.part.json'))
|
|
78
|
+
sidecars.push(abs);
|
|
79
|
+
else if (entry.name.endsWith('.part'))
|
|
80
|
+
parts.push(abs);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Delete staged parts under `dirs` older than `maxAgeMs`, plus the sidecars
|
|
85
|
+
* whose part is already gone (an orphan validator would make the next attempt
|
|
86
|
+
* look like a resume). Never throws: an unreadable directory is skipped, since
|
|
87
|
+
* a reclaimer must not break boot.
|
|
88
|
+
*/
|
|
89
|
+
export function sweepAbandonedParts(opts = {}) {
|
|
90
|
+
const now = opts.now ?? Date.now();
|
|
91
|
+
const maxAgeMs = opts.maxAgeMs ?? ABANDONED_PART_AGE_MS;
|
|
92
|
+
const stats = { removed: 0, bytes: 0 };
|
|
93
|
+
for (const dir of opts.dirs ?? downloadStageDirs()) {
|
|
94
|
+
const parts = [];
|
|
95
|
+
const sidecars = [];
|
|
96
|
+
collectParts(dir, 0, parts, sidecars);
|
|
97
|
+
for (const part of parts) {
|
|
98
|
+
const stat = safeStat(part);
|
|
99
|
+
if (!stat || now - stat.mtimeMs <= maxAgeMs)
|
|
100
|
+
continue;
|
|
101
|
+
stats.bytes += stat.size;
|
|
102
|
+
stats.removed += 1;
|
|
103
|
+
cleanupAssetPart(part);
|
|
104
|
+
}
|
|
105
|
+
for (const sidecar of sidecars) {
|
|
106
|
+
// The part it described is gone (a finished rename, a manual delete, or
|
|
107
|
+
// the pass above): the validator alone can only mislead a retry.
|
|
108
|
+
if (safeStat(sidecar.slice(0, -'.json'.length)))
|
|
109
|
+
continue;
|
|
110
|
+
const stat = safeStat(sidecar);
|
|
111
|
+
if (!stat || now - stat.mtimeMs <= maxAgeMs)
|
|
112
|
+
continue;
|
|
113
|
+
try {
|
|
114
|
+
fs.rmSync(sidecar, { force: true });
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
// Nothing to reclaim.
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return stats;
|
|
122
|
+
}
|
|
123
|
+
/** Staged bytes under `dirs` — what the sweep below would eventually reclaim. */
|
|
124
|
+
export function partBytesIn(dirs) {
|
|
125
|
+
let total = 0;
|
|
126
|
+
for (const dir of dirs) {
|
|
127
|
+
const parts = [];
|
|
128
|
+
collectParts(dir, 0, parts, []);
|
|
129
|
+
for (const part of parts) {
|
|
130
|
+
const stat = safeStat(part);
|
|
131
|
+
if (stat)
|
|
132
|
+
total += stat.size;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return total;
|
|
136
|
+
}
|
|
137
|
+
/** Unfinished downloads staged inside the models tree (the market's card). */
|
|
138
|
+
export function modelPartBytes() {
|
|
139
|
+
return partBytesIn([modelsRoot()]);
|
|
140
|
+
}
|
|
141
|
+
/** Engine archives staged under `engines/downloads` (the engines card). */
|
|
142
|
+
export function engineDownloadPartBytes() {
|
|
143
|
+
return partBytesIn([path.join(engineInstallRoot(), 'downloads')]);
|
|
144
|
+
}
|
|
145
|
+
let timer;
|
|
146
|
+
/** Boot pass plus the hourly beat; idempotent so a second registration (tests,
|
|
147
|
+
* a re-mounted router) does not stack timers. */
|
|
148
|
+
export function startAbandonedPartSweep() {
|
|
149
|
+
sweepAbandonedParts();
|
|
150
|
+
if (timer)
|
|
151
|
+
return;
|
|
152
|
+
timer = setInterval(() => {
|
|
153
|
+
sweepAbandonedParts();
|
|
154
|
+
}, PART_SWEEP_INTERVAL_MS);
|
|
155
|
+
timer.unref?.();
|
|
156
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { GgufMeta } from './gguf.js';
|
|
2
|
+
/** Context ladder for the Auto pick — the largest step that does not push the
|
|
3
|
+
* KV cache past its budget share wins. Capped at the model's own ceiling. */
|
|
4
|
+
export declare const CTX_LADDER: readonly [8192, 16384, 32768, 65536, 131072];
|
|
5
|
+
export interface PlanInput {
|
|
6
|
+
/** Model file size in bytes (the weights the loader maps). */
|
|
7
|
+
sizeBytes: number;
|
|
8
|
+
meta: GgufMeta | null;
|
|
9
|
+
/** Total discrete VRAM in MiB (absent = no GPU reading). */
|
|
10
|
+
vramMb?: number;
|
|
11
|
+
/** System RAM in bytes (os.totalmem when the caller does not override). */
|
|
12
|
+
ramBytes?: number;
|
|
13
|
+
/** Engine target backend (`cpu`, `vulkan`, `cuda`, …); `cpu` never layers. */
|
|
14
|
+
backend: string;
|
|
15
|
+
/** Requested context length (tokens). */
|
|
16
|
+
ctx: number;
|
|
17
|
+
/** KV cache element bytes: 2 for f16, ~1.125 for q8_0 (byte + scales). */
|
|
18
|
+
kvElemBytes?: number;
|
|
19
|
+
/** Operator-pinned GPU layer count; when set it replaces the budget-derived
|
|
20
|
+
* split (the budget still shows in the bars, so an oversized pick reads as
|
|
21
|
+
* the overcommit it is). Clamped to the declared layer count. */
|
|
22
|
+
gpuLayersOverride?: number;
|
|
23
|
+
/** Resource mode: true (default) reserves headroom for the desktop and OS;
|
|
24
|
+
* false budgets nearly everything for the model. */
|
|
25
|
+
headroom?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface PlacementPlan {
|
|
28
|
+
backend: string;
|
|
29
|
+
/** Transformer layers the header declared (0 when unparsed). */
|
|
30
|
+
layers: number;
|
|
31
|
+
/** Layers placed on the GPU — the `-ngl` value the runner passes. */
|
|
32
|
+
gpuLayers: number;
|
|
33
|
+
/** True when every layer fits in VRAM (gpuLayers covers the model). */
|
|
34
|
+
fullGpu: boolean;
|
|
35
|
+
ctx: number;
|
|
36
|
+
/** KV cache cost at `ctx` (bytes). */
|
|
37
|
+
kvBytes: number;
|
|
38
|
+
/** Estimated bytes resident in VRAM (weights share + KV + runtime). */
|
|
39
|
+
vramBytes: number;
|
|
40
|
+
vramTotalBytes: number;
|
|
41
|
+
/** Estimated bytes resident in RAM (the offloaded weight share). */
|
|
42
|
+
ramBytes: number;
|
|
43
|
+
ramTotalBytes: number;
|
|
44
|
+
/** RAM the plan refused to spend (the resource switch's reserve), so the
|
|
45
|
+
* console's detail line never hardcodes the figure. */
|
|
46
|
+
ramReserveBytes: number;
|
|
47
|
+
/** True when weights exceed VRAM+RAM budget and mmap streams from disk. */
|
|
48
|
+
diskStreamed: boolean;
|
|
49
|
+
/** Rough decode speed (tokens/s) — bandwidth over bytes touched per token. */
|
|
50
|
+
estTokPerSec: number;
|
|
51
|
+
/** The model's own context ceiling, when the header declared one. */
|
|
52
|
+
maxCtx?: number;
|
|
53
|
+
}
|
|
54
|
+
export declare function planPlacement(input: PlanInput): PlacementPlan;
|
|
55
|
+
/** KV element-size note: q8_0 stores a byte plus per-block scales (~1.125). */
|
|
56
|
+
export declare const KV_ELEM_F16 = 2;
|
|
57
|
+
export declare const KV_ELEM_Q8_0 = 1.125;
|
|
58
|
+
/**
|
|
59
|
+
* The auto context pick: the largest ladder step (clamped to the model's
|
|
60
|
+
* ceiling) whose KV cache stays under a quarter of the VRAM budget — or, on a
|
|
61
|
+
* CPU/RAM placement, under a tenth of spendable RAM. Always at least 8192.
|
|
62
|
+
*/
|
|
63
|
+
export declare function autoCtx(input: Omit<PlanInput, 'ctx'>): number;
|
|
64
|
+
/** The `-ngl` argument a plan maps to: 999 is llama.cpp's "every layer". */
|
|
65
|
+
export declare function nglForPlan(plan: PlacementPlan): number;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Placement planner for the Local Models run console (the automatic-layer-plan
|
|
3
|
+
* panel).
|
|
4
|
+
*
|
|
5
|
+
* Given one model file (size + parsed GGUF header) and one machine reading
|
|
6
|
+
* (VRAM, RAM), the planner answers: how many transformer layers fit in VRAM,
|
|
7
|
+
* what the KV cache costs at a chosen context, what spills to RAM, and what
|
|
8
|
+
* the disk ends up streaming. The output drives BOTH the console's bars and
|
|
9
|
+
* the runner's `-ngl` argument, so the picture the operator confirms is the
|
|
10
|
+
* launch that actually happens.
|
|
11
|
+
*
|
|
12
|
+
* Everything here is an ESTIMATE — the UI labels every number as estimated.
|
|
13
|
+
* The model is a
|
|
14
|
+
* uniform per-layer weight split (embedding/output ride with the on-GPU
|
|
15
|
+
* share) plus a KV term from the header's attention geometry; llama.cpp's own
|
|
16
|
+
* allocator decides the truth at load time.
|
|
17
|
+
*/
|
|
18
|
+
import os from 'node:os';
|
|
19
|
+
import { LOCAL_DEFAULT_CTX } from '../config/defaults.js';
|
|
20
|
+
/** Fraction of detected VRAM the planner may budget — the rest belongs to the
|
|
21
|
+
* desktop, the engine runtime and the allocator's slack. The console's
|
|
22
|
+
* resource switch ("leave room" vs "full performance") picks between the two;
|
|
23
|
+
* both stay here so the plan preview and the runner never disagree. */
|
|
24
|
+
const VRAM_BUDGET_RATIO = 0.92;
|
|
25
|
+
const VRAM_BUDGET_RATIO_PERFORMANCE = 0.97;
|
|
26
|
+
/** Engine/runtime resident cost charged to VRAM before weights (bytes). */
|
|
27
|
+
const GPU_RUNTIME_BYTES = 400 * 1024 * 1024;
|
|
28
|
+
/** RAM kept for the OS and the gateway itself; the plan may not spend it. */
|
|
29
|
+
const RAM_RESERVE_BYTES = 4 * 1024 * 1024 * 1024;
|
|
30
|
+
const RAM_RESERVE_PERFORMANCE_BYTES = 2 * 1024 * 1024 * 1024;
|
|
31
|
+
/** Context ladder for the Auto pick — the largest step that does not push the
|
|
32
|
+
* KV cache past its budget share wins. Capped at the model's own ceiling. */
|
|
33
|
+
export const CTX_LADDER = [8192, 16384, 32768, 65536, 131072];
|
|
34
|
+
/** Rough decode bandwidth (GB/s) per residency tier, for the speed estimate. */
|
|
35
|
+
const BANDWIDTH_GBPS = { vram: 250, split: 110, ram: 50 };
|
|
36
|
+
/** KV bytes per token from the header geometry; falls back to an embd guess. */
|
|
37
|
+
function kvBytesPerToken(meta, layers, elemBytes) {
|
|
38
|
+
if (!meta)
|
|
39
|
+
return 0;
|
|
40
|
+
const headDim = meta.headDim ?? (meta.heads && meta.embedding ? meta.embedding / meta.heads : 128);
|
|
41
|
+
const kvHeads = meta.kvHeads ?? meta.heads ?? 0;
|
|
42
|
+
if (!kvHeads || !headDim || !layers)
|
|
43
|
+
return 0;
|
|
44
|
+
// K and V per token per layer.
|
|
45
|
+
return layers * kvHeads * headDim * 2 * elemBytes;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Decode-side bytes one token touches: the resident weight share. A MoE
|
|
49
|
+
* checkpoint activates `expertsUsed / experts` of its routed expert mass;
|
|
50
|
+
* without the expert geometry the full file is touched.
|
|
51
|
+
*/
|
|
52
|
+
function bytesTouchedPerToken(sizeBytes, meta) {
|
|
53
|
+
if (meta?.experts && meta.expertsUsed && meta.experts > meta.expertsUsed) {
|
|
54
|
+
// Expert weights dominate an MoE file (~85-95% of bytes); treat the active
|
|
55
|
+
// fraction as expertsUsed/experts of 90% of the file plus the shared 10%.
|
|
56
|
+
return sizeBytes * (0.1 + 0.9 * (meta.expertsUsed / meta.experts));
|
|
57
|
+
}
|
|
58
|
+
return sizeBytes;
|
|
59
|
+
}
|
|
60
|
+
export function planPlacement(input) {
|
|
61
|
+
const layers = input.meta?.layers ?? 0;
|
|
62
|
+
const ctx = Math.max(256, Math.floor(input.ctx));
|
|
63
|
+
const kvElem = input.kvElemBytes ?? 2;
|
|
64
|
+
const vramTotal = input.vramMb ? input.vramMb * 1024 * 1024 : 0;
|
|
65
|
+
const ramTotal = input.ramBytes ?? os.totalmem();
|
|
66
|
+
const kvBytes = kvBytesPerToken(input.meta, layers, kvElem) * ctx;
|
|
67
|
+
const isCpu = input.backend === 'cpu' || vramTotal <= 0;
|
|
68
|
+
const perLayer = layers > 0 ? input.sizeBytes / layers : input.sizeBytes;
|
|
69
|
+
const vramRatio = input.headroom === false ? VRAM_BUDGET_RATIO_PERFORMANCE : VRAM_BUDGET_RATIO;
|
|
70
|
+
const ramReserve = input.headroom === false ? RAM_RESERVE_PERFORMANCE_BYTES : RAM_RESERVE_BYTES;
|
|
71
|
+
let gpuLayers = 0;
|
|
72
|
+
if (!isCpu && layers > 0) {
|
|
73
|
+
if (input.gpuLayersOverride != null) {
|
|
74
|
+
// The operator pinned the split — honor it as-is (clamped); the bars
|
|
75
|
+
// still charge it against the budget, so an overcommit is visible.
|
|
76
|
+
gpuLayers = Math.max(0, Math.min(layers, Math.floor(input.gpuLayersOverride)));
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
const vramBudget = vramTotal * vramRatio;
|
|
80
|
+
// KV rides with the GPU residency when any layer is on the GPU.
|
|
81
|
+
const forWeights = vramBudget - GPU_RUNTIME_BYTES - kvBytes;
|
|
82
|
+
gpuLayers = Math.max(0, Math.min(layers, Math.floor(forWeights / perLayer)));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const fullGpu = !isCpu && layers > 0 && gpuLayers >= layers;
|
|
86
|
+
const gpuWeightBytes = fullGpu ? input.sizeBytes : gpuLayers * perLayer;
|
|
87
|
+
const ramWeightBytes = input.sizeBytes - gpuWeightBytes;
|
|
88
|
+
const vramBytes = isCpu ? 0 : gpuWeightBytes + kvBytes + GPU_RUNTIME_BYTES;
|
|
89
|
+
// KV stays on the GPU whenever any layer is offloaded; a CPU-only run pays
|
|
90
|
+
// for it in RAM.
|
|
91
|
+
const ramBytes = ramWeightBytes + (isCpu ? kvBytes : 0);
|
|
92
|
+
const ramBudget = Math.max(0, ramTotal - ramReserve);
|
|
93
|
+
const diskStreamed = ramWeightBytes > ramBudget;
|
|
94
|
+
const touched = bytesTouchedPerToken(input.sizeBytes, input.meta);
|
|
95
|
+
const bandwidth = fullGpu ? BANDWIDTH_GBPS.vram : isCpu ? BANDWIDTH_GBPS.ram : BANDWIDTH_GBPS.split;
|
|
96
|
+
const estTokPerSec = Math.max(1, Math.round(bandwidth / Math.max(0.3, touched / 1e9)));
|
|
97
|
+
return {
|
|
98
|
+
backend: input.backend,
|
|
99
|
+
layers,
|
|
100
|
+
gpuLayers: isCpu ? 0 : gpuLayers,
|
|
101
|
+
fullGpu,
|
|
102
|
+
ctx,
|
|
103
|
+
kvBytes,
|
|
104
|
+
vramBytes,
|
|
105
|
+
vramTotalBytes: vramTotal,
|
|
106
|
+
ramBytes,
|
|
107
|
+
ramTotalBytes: ramTotal,
|
|
108
|
+
ramReserveBytes: ramReserve,
|
|
109
|
+
diskStreamed,
|
|
110
|
+
estTokPerSec,
|
|
111
|
+
...(input.meta?.maxCtx ? { maxCtx: input.meta.maxCtx } : {}),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/** KV element-size note: q8_0 stores a byte plus per-block scales (~1.125). */
|
|
115
|
+
export const KV_ELEM_F16 = 2;
|
|
116
|
+
export const KV_ELEM_Q8_0 = 1.125;
|
|
117
|
+
/**
|
|
118
|
+
* The auto context pick: the largest ladder step (clamped to the model's
|
|
119
|
+
* ceiling) whose KV cache stays under a quarter of the VRAM budget — or, on a
|
|
120
|
+
* CPU/RAM placement, under a tenth of spendable RAM. Always at least 8192.
|
|
121
|
+
*/
|
|
122
|
+
export function autoCtx(input) {
|
|
123
|
+
const ceiling = input.meta?.maxCtx ?? LOCAL_DEFAULT_CTX;
|
|
124
|
+
const ramReserve = input.headroom === false ? RAM_RESERVE_PERFORMANCE_BYTES : RAM_RESERVE_BYTES;
|
|
125
|
+
const vramRatio = input.headroom === false ? VRAM_BUDGET_RATIO_PERFORMANCE : VRAM_BUDGET_RATIO;
|
|
126
|
+
let pick = CTX_LADDER[0];
|
|
127
|
+
for (const step of CTX_LADDER) {
|
|
128
|
+
if (step > ceiling)
|
|
129
|
+
break;
|
|
130
|
+
const plan = planPlacement({ ...input, ctx: step });
|
|
131
|
+
const budget = plan.vramTotalBytes > 0 && plan.gpuLayers > 0
|
|
132
|
+
? plan.vramTotalBytes * vramRatio * 0.25
|
|
133
|
+
: Math.max(0, plan.ramTotalBytes - ramReserve) * 0.1;
|
|
134
|
+
if (plan.kvBytes <= budget)
|
|
135
|
+
pick = step;
|
|
136
|
+
else
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
return Math.min(pick, ceiling);
|
|
140
|
+
}
|
|
141
|
+
/** The `-ngl` argument a plan maps to: 999 is llama.cpp's "every layer". */
|
|
142
|
+
export function nglForPlan(plan) {
|
|
143
|
+
if (plan.backend === 'cpu')
|
|
144
|
+
return 0;
|
|
145
|
+
return plan.fullGpu ? 999 : plan.gpuLayers;
|
|
146
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The run console's resource switch ("leave room for my work" vs "full
|
|
3
|
+
* performance"), as the numbers an engine-owned placement writes into its
|
|
4
|
+
* launch input.
|
|
5
|
+
*
|
|
6
|
+
* The rule is the vendor's own (`native-resources.mjs` in the Strata app), not
|
|
7
|
+
* a gateway invention: the same floors, the same cap on a small card, the same
|
|
8
|
+
* RAM-keep figure. It exists because VRAM left below ~1-1.5 GiB makes the
|
|
9
|
+
* Windows display driver page GPU memory to system RAM, and decode then falls
|
|
10
|
+
* to a few tokens a second — the engine warns about exactly this in its log.
|
|
11
|
+
*
|
|
12
|
+
* Everything here is a machine fact + one operator choice; nothing is measured.
|
|
13
|
+
*/
|
|
14
|
+
export type ResourceMode = 'work' | 'performance';
|
|
15
|
+
export interface ResourcePlan {
|
|
16
|
+
mode: ResourceMode;
|
|
17
|
+
/** `--vram-reserve-mib` — VRAM left free for the desktop and the driver. */
|
|
18
|
+
reserveMib: number;
|
|
19
|
+
/** `STRATA_RAM_KEEP_GIB` — RAM kept free for the operator's other work. */
|
|
20
|
+
ramKeepGib?: number;
|
|
21
|
+
}
|
|
22
|
+
/** RAM "leave room" asks the engine to keep free: 20% of the PC, clamped 5-8 GiB. */
|
|
23
|
+
export declare function ramKeepGib(ramBytes: number): number;
|
|
24
|
+
export interface ResourceInput {
|
|
25
|
+
/** The console's switch; true = "leave room for my work". */
|
|
26
|
+
headroom: boolean;
|
|
27
|
+
/** Detected total VRAM in MiB; absent = no reading (treated as a display card). */
|
|
28
|
+
vramMb?: number;
|
|
29
|
+
/** Total system RAM in bytes. */
|
|
30
|
+
ramBytes: number;
|
|
31
|
+
/** A vision reader that runs on the GPU needs room of its own. Strata's
|
|
32
|
+
* encoder runs on the CPU in this gateway, so this is false unless an
|
|
33
|
+
* engine says otherwise. */
|
|
34
|
+
visionOnGpu?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The reserve pair for this machine, exactly as the vendor computes it:
|
|
38
|
+
* `headless` is unknown to us and therefore counts as a display card.
|
|
39
|
+
*/
|
|
40
|
+
export declare function resourceReserves(input: Pick<ResourceInput, 'vramMb' | 'visionOnGpu'>): {
|
|
41
|
+
work: number;
|
|
42
|
+
performance: number;
|
|
43
|
+
};
|
|
44
|
+
/** The plan one launch writes. Both modes always resolve a reserve, so the
|
|
45
|
+
* answer is never null — `resourceEnv` takes null only because a caller may
|
|
46
|
+
* have no plan at all (an engine that does not map the switch). */
|
|
47
|
+
export declare function resourcePlan(input: ResourceInput): ResourcePlan;
|
|
48
|
+
/** The engine environment a plan writes into the run config's `env` block. */
|
|
49
|
+
export declare function resourceEnv(plan: ResourcePlan | null): Record<string, string>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The run console's resource switch ("leave room for my work" vs "full
|
|
3
|
+
* performance"), as the numbers an engine-owned placement writes into its
|
|
4
|
+
* launch input.
|
|
5
|
+
*
|
|
6
|
+
* The rule is the vendor's own (`native-resources.mjs` in the Strata app), not
|
|
7
|
+
* a gateway invention: the same floors, the same cap on a small card, the same
|
|
8
|
+
* RAM-keep figure. It exists because VRAM left below ~1-1.5 GiB makes the
|
|
9
|
+
* Windows display driver page GPU memory to system RAM, and decode then falls
|
|
10
|
+
* to a few tokens a second — the engine warns about exactly this in its log.
|
|
11
|
+
*
|
|
12
|
+
* Everything here is a machine fact + one operator choice; nothing is measured.
|
|
13
|
+
*/
|
|
14
|
+
/** A display card of 16 GB or less keeps this free even at "full performance". */
|
|
15
|
+
const DISPLAY_RESERVE_MIB_SMALL = 1536;
|
|
16
|
+
/** Above 16 GB the same floor is one GiB. */
|
|
17
|
+
const DISPLAY_RESERVE_MIB_LARGE = 1024;
|
|
18
|
+
/** A GPU-side vision reader needs its own room on top of the floor. */
|
|
19
|
+
const PICTURES_RESERVE_MIB = 2048;
|
|
20
|
+
/** "Leave room" asks for a fifth of the card, but no more than this below 16 GB. */
|
|
21
|
+
const WORK_FIFTH_CAP_MIB = 1536;
|
|
22
|
+
/** Below this card size the fifth is capped (a fifth of 12 GB cost ~20% speed vs the cap). */
|
|
23
|
+
const SMALL_CARD_GB = 16;
|
|
24
|
+
/** RAM "leave room" asks the engine to keep free: 20% of the PC, clamped 5-8 GiB. */
|
|
25
|
+
export function ramKeepGib(ramBytes) {
|
|
26
|
+
const gb = ramBytes / 1_073_741_824;
|
|
27
|
+
return Math.min(8, Math.max(5, Math.ceil(gb * 0.2)));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The reserve pair for this machine, exactly as the vendor computes it:
|
|
31
|
+
* `headless` is unknown to us and therefore counts as a display card.
|
|
32
|
+
*/
|
|
33
|
+
export function resourceReserves(input) {
|
|
34
|
+
const vramGb = (input.vramMb ?? 0) / 1024;
|
|
35
|
+
const known = vramGb > 0;
|
|
36
|
+
const pictures = input.visionOnGpu === true;
|
|
37
|
+
const floor = !known
|
|
38
|
+
? DISPLAY_RESERVE_MIB_SMALL
|
|
39
|
+
: vramGb > SMALL_CARD_GB
|
|
40
|
+
? DISPLAY_RESERVE_MIB_LARGE
|
|
41
|
+
: DISPLAY_RESERVE_MIB_SMALL;
|
|
42
|
+
const safety = Math.max(pictures ? PICTURES_RESERVE_MIB : floor, 0);
|
|
43
|
+
if (!known)
|
|
44
|
+
return { work: safety, performance: safety };
|
|
45
|
+
const fifth = Math.floor(vramGb * 1024 * 0.2);
|
|
46
|
+
const cap = vramGb <= SMALL_CARD_GB ? WORK_FIFTH_CAP_MIB : Number.POSITIVE_INFINITY;
|
|
47
|
+
return { work: Math.max(safety, Math.min(fifth, cap)), performance: safety };
|
|
48
|
+
}
|
|
49
|
+
/** The plan one launch writes. Both modes always resolve a reserve, so the
|
|
50
|
+
* answer is never null — `resourceEnv` takes null only because a caller may
|
|
51
|
+
* have no plan at all (an engine that does not map the switch). */
|
|
52
|
+
export function resourcePlan(input) {
|
|
53
|
+
const reserves = resourceReserves(input);
|
|
54
|
+
if (input.headroom) {
|
|
55
|
+
return { mode: 'work', reserveMib: reserves.work, ramKeepGib: ramKeepGib(input.ramBytes) };
|
|
56
|
+
}
|
|
57
|
+
return { mode: 'performance', reserveMib: reserves.performance };
|
|
58
|
+
}
|
|
59
|
+
/** The engine environment a plan writes into the run config's `env` block. */
|
|
60
|
+
export function resourceEnv(plan) {
|
|
61
|
+
if (!plan?.ramKeepGib)
|
|
62
|
+
return {};
|
|
63
|
+
return { STRATA_RAM_KEEP_GIB: String(plan.ramKeepGib) };
|
|
64
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/** One timing observation — the rolling pair of §3 (aggregate + latest). */
|
|
2
|
+
export interface RateSample {
|
|
3
|
+
/** Number of observations folded into this sample. */
|
|
4
|
+
samples: number;
|
|
5
|
+
/** Mean over every observation since the run started. */
|
|
6
|
+
avg: number;
|
|
7
|
+
/** Most recent observation (what "right now" means). */
|
|
8
|
+
last: number;
|
|
9
|
+
}
|
|
10
|
+
export interface LocalRunStats {
|
|
11
|
+
runId: string;
|
|
12
|
+
/** Requests currently being served by this run (gauge). */
|
|
13
|
+
inFlight: number;
|
|
14
|
+
/** Requests completed successfully since this process started. */
|
|
15
|
+
requests: number;
|
|
16
|
+
/** Requests that threw before answering (breaker/route handled them). */
|
|
17
|
+
errors: number;
|
|
18
|
+
/** Token totals across completed requests. */
|
|
19
|
+
inputTokens: number;
|
|
20
|
+
outputTokens: number;
|
|
21
|
+
cachedInputTokens: number;
|
|
22
|
+
/** Request start → first streamed delta. Absent until one leg reports it. */
|
|
23
|
+
ttftMs: RateSample | null;
|
|
24
|
+
/** Output tokens ÷ decode window (first delta → end). Absent until one
|
|
25
|
+
* leg could measure a window (a buffered leg has none). */
|
|
26
|
+
decodeTps: RateSample | null;
|
|
27
|
+
/** True when every observation came from a buffered (non-streamed) leg, so
|
|
28
|
+
* the TTFT figure is "the whole response" rather than a first-token wait. */
|
|
29
|
+
bufferedOnly: boolean;
|
|
30
|
+
/** Wall-clock of the last completed request (0 = none yet). */
|
|
31
|
+
lastRequestAt: number;
|
|
32
|
+
/** Epoch ms this process began counting (a restart resets the window). */
|
|
33
|
+
since: number;
|
|
34
|
+
}
|
|
35
|
+
/** An in-flight request's start instant, keyed by run id. */
|
|
36
|
+
interface PendingMark {
|
|
37
|
+
startedAt: number;
|
|
38
|
+
firstDeltaAt: number | null;
|
|
39
|
+
/** Set on the first settle — a mark releases its gauge exactly once. */
|
|
40
|
+
released?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Register a request about to be served by `runId`. Returns the mark that
|
|
44
|
+
* `completeRequest` / `failRequest` must hand back, so two concurrent requests
|
|
45
|
+
* on the same run never overwrite each other's timing.
|
|
46
|
+
*/
|
|
47
|
+
export declare function beginRequest(runId: string): PendingMark;
|
|
48
|
+
/**
|
|
49
|
+
* Note the arrival of the first streamed delta for `mark` — the instant the
|
|
50
|
+
* TTFT window closes and the decode window opens. Idempotent: only the first
|
|
51
|
+
* call per request counts.
|
|
52
|
+
*/
|
|
53
|
+
export declare function markFirstDelta(mark: PendingMark): void;
|
|
54
|
+
/**
|
|
55
|
+
* The run answered 503 `local_run_inactive` before any dial: an operator's
|
|
56
|
+
* deliberate stop is NOT a failed request (ADR-0046 §2). The in-flight slot is
|
|
57
|
+
* released without touching `errors`, and the row a never-answering run created
|
|
58
|
+
* is dropped again — otherwise every attempt against a stopped model inflates
|
|
59
|
+
* the monitor's error count and the page blames the engine for a state the
|
|
60
|
+
* operator chose.
|
|
61
|
+
*/
|
|
62
|
+
export declare function skipRequest(runId: string, mark: PendingMark): void;
|
|
63
|
+
/**
|
|
64
|
+
* Record a completed request. `usage` is the canonical usage the provider
|
|
65
|
+
* returned (or the terminal event of a streamed call) — the single source of
|
|
66
|
+
* token facts, so a leg that forgets to expose usage is visibly a zero here
|
|
67
|
+
* rather than a plausible-looking estimate.
|
|
68
|
+
*/
|
|
69
|
+
export declare function completeRequest(runId: string, mark: PendingMark, usage: {
|
|
70
|
+
inputTokens?: number;
|
|
71
|
+
outputTokens?: number;
|
|
72
|
+
cachedInputTokens?: number;
|
|
73
|
+
}, options: {
|
|
74
|
+
streamed: boolean;
|
|
75
|
+
}): void;
|
|
76
|
+
/** Record a request that threw. The gauge is still released — a leaked slot
|
|
77
|
+
* would make the in-flight number climb forever and the page lie. */
|
|
78
|
+
export declare function failRequest(runId: string, mark: PendingMark, error?: unknown): void;
|
|
79
|
+
/** One run's counters, or a blank row for a run that served nothing yet. */
|
|
80
|
+
export declare function statsFor(runId: string): LocalRunStats;
|
|
81
|
+
/** Every run's counters (the monitor's merge source). READ ONLY — the map is
|
|
82
|
+
* the module's own state; a caller that prunes must use `pruneStats`, so a
|
|
83
|
+
* route never mutates state merely by rendering. */
|
|
84
|
+
export declare function allStats(): Map<string, LocalRunStats>;
|
|
85
|
+
/** Drop counters whose run the registry no longer knows (called by the monitor
|
|
86
|
+
* and the prune route). Returns how many rows went. */
|
|
87
|
+
export declare function pruneStats(known: ReadonlySet<string>): number;
|
|
88
|
+
/** Drop counters for runs that no longer exist (prune follows `runs.json`). */
|
|
89
|
+
export declare function dropStats(runId: string): void;
|
|
90
|
+
/**
|
|
91
|
+
* Test seam: wipe every counter. Production never clears the map wholesale —
|
|
92
|
+
* a run's counters die with the run (`dropStats`).
|
|
93
|
+
*/
|
|
94
|
+
export declare function resetStatsForTests(): void;
|
|
95
|
+
export {};
|