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
|
@@ -5,25 +5,27 @@ import { dirname, join, resolve, sep } from 'node:path';
|
|
|
5
5
|
import { pathToFileURL } from 'node:url';
|
|
6
6
|
import { getOcrHomeDir } from '../cli/paths.js';
|
|
7
7
|
import { UpstreamError } from '../resilience/error-classifier.js';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { IrUnsupportedError } from '../ir/errors.js';
|
|
9
|
+
import { DEFAULT_STREAM_TIMEOUT_MS, PLUGIN_ENVIRONMENT_PROBE_TIMEOUT_MS, PLUGIN_ENVIRONMENT_TTL_MS } from '../config/defaults.js';
|
|
10
|
+
import { acknowledgeEnvironment, activeEnvironmentAcks, clearEnvironmentAcks, readEnvironmentAcks, } from './environment-ack.js';
|
|
10
11
|
import { emitUpstreamRequestOnce, emitUpstreamResponseOnce, emitUpstreamFailureOnce, withUpstreamFailureGuard, } from '../observability/upstream-events.js';
|
|
11
12
|
import { beginPluginClientAdapterRebuild, commitPluginClientAdapterRebuild, registerPluginClientAdapter } from '../cli/clients/plugin-adapters.js';
|
|
12
13
|
import { commitGateways, removeGateway, retainStagedGateways, setGatewayOperatorEgress, stageGateway, getGatewayById, WILDCARD_HOST_CLAIM } from './gateways.js';
|
|
13
14
|
import { getGatewayChatServices } from '../surfaces/gateway-chat.js';
|
|
14
|
-
import { invalidatePluginConfigCache, mergedPluginConfig, pluginConfigPath, writePluginConfig } from './config.js';
|
|
15
|
-
import { assertSupportedPluginApi, isValidPluginId, normalizePluginParts, operatorEgressChoice, pluginEngineRefusal, validatePluginManifest,
|
|
15
|
+
import { invalidatePluginConfigCache, mergedPluginConfig, pluginConfigPath, readStoredConfig, writePluginConfig } from './config.js';
|
|
16
|
+
import { assertInstallablePluginApi, assertSupportedPluginApi, isValidPluginId, normalizePluginParts, operatorEgressChoice, pluginEngineRefusal, resolvePluginStatePath, validatePluginManifest, withPluginEgressField, } from './manifest.js';
|
|
16
17
|
import { compareVersions } from '../utils/semver.js';
|
|
17
18
|
import { seedBundledPlugins } from './seed.js';
|
|
18
|
-
import { forwardH2 } from '../
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import { resolveUpstreamTls } from '../
|
|
22
|
-
import { isRuleRejected } from '../
|
|
19
|
+
import { forwardH2 } from '../ingress-proxy/h2-forward.js';
|
|
20
|
+
import { forwardTo, proxyFail, RULE_REJECTED_MESSAGE } from '../ingress-proxy/server.js';
|
|
21
|
+
import { isEgressProxyEnabled } from '../ingress-proxy/egress.js';
|
|
22
|
+
import { resolveUpstreamTls } from '../ingress-proxy/upstream-tls.js';
|
|
23
|
+
import { isRuleRejected } from '../ingress-proxy/egress.js';
|
|
23
24
|
import { claimPluginWires, isCoreWire, isPluginWire } from '../providers/plugin-wires.js';
|
|
25
|
+
import { noteQuotaCoverageInputsChanged } from '../quota/coverage-generation.js';
|
|
24
26
|
import { currentProtocol } from '../providers/protocol.js';
|
|
25
27
|
import { wireFor } from '../providers/wire.js';
|
|
26
|
-
import { proxiedFetch,
|
|
28
|
+
import { proxiedFetch, resolveEgress } from '../utils/proxy.js';
|
|
27
29
|
/**
|
|
28
30
|
* Plugin host: discovers, unpacks and loads plugins. Two types today
|
|
29
31
|
* (ADR-0017): 'model-service' (outbound executors, registry below) and
|
|
@@ -89,35 +91,61 @@ const nextRegistry = new Map();
|
|
|
89
91
|
let rebuildInFlight = Promise.resolve([]);
|
|
90
92
|
/** Set by the tail of a completed `loadInstalledPlugins()`. */
|
|
91
93
|
let hostInitialized = false;
|
|
94
|
+
/**
|
|
95
|
+
* Resolves when the FIRST full plugin load commits its registry. The model-pull
|
|
96
|
+
* sweep is void-fired from `catalogRepository.start()`, which boots BEFORE the
|
|
97
|
+
* plugin host is loaded — without this gate the plug-in dispatch would always
|
|
98
|
+
* read "plugin is not installed" on the boot sweep.
|
|
99
|
+
*/
|
|
100
|
+
let signalPluginsReady;
|
|
101
|
+
export const pluginsReady = new Promise((resolve) => {
|
|
102
|
+
signalPluginsReady = resolve;
|
|
103
|
+
});
|
|
92
104
|
/** The backend capabilities handed to every model-service plugin at load time.
|
|
93
105
|
* `dir` is the plugin's load root — the only asset root a packaged plugin has.
|
|
94
106
|
*
|
|
95
|
-
* Exported as a test seam: the
|
|
96
|
-
*
|
|
97
|
-
* the registry-filled ``pull`` block is wired separately
|
|
98
|
-
* ``pluginPullServices()``. */
|
|
107
|
+
* Exported as a test seam: `fetch` is the ONE way a plugin reaches its
|
|
108
|
+
* upstream (`egressProxyFor` only reports the same decision), and it has no
|
|
109
|
+
* other side effects — the registry-filled ``pull`` block is wired separately
|
|
110
|
+
* by ``pluginPullServices()``. */
|
|
99
111
|
export function buildHostSdkForTests(manifest, dir) {
|
|
100
112
|
return buildHostSdk(manifest, dir);
|
|
101
113
|
}
|
|
102
114
|
function buildHostSdk(manifest, dir) {
|
|
115
|
+
/**
|
|
116
|
+
* The plugin-level egress mode handed to the resolver.
|
|
117
|
+
*
|
|
118
|
+
* The SDK does NOT read this package's config: the switch is the package's
|
|
119
|
+
* business — a daemon-backed plugin has to hand the leg to the process it
|
|
120
|
+
* spawns, which the core never sees — and omitting the argument keeps the
|
|
121
|
+
* historical behaviour, FOLLOW (the provider/model split alone decides).
|
|
122
|
+
*/
|
|
123
|
+
const egressFor = (requested) => requested ?? 'inherit';
|
|
103
124
|
return {
|
|
104
125
|
UpstreamError: UpstreamError,
|
|
126
|
+
IrUnsupportedError: IrUnsupportedError,
|
|
105
127
|
upstream: {
|
|
106
128
|
requestOnce: emitUpstreamRequestOnce,
|
|
107
129
|
responseOnce: emitUpstreamResponseOnce,
|
|
108
130
|
failureOnce: emitUpstreamFailureOnce,
|
|
109
131
|
failureGuard: withUpstreamFailureGuard,
|
|
110
132
|
},
|
|
111
|
-
|
|
133
|
+
// A plugin wire enforces this as a per-STEP wall clock with no progress
|
|
134
|
+
// renewal, so it must clear the largest legitimate step. Reuse the streamed
|
|
135
|
+
// leg's cap (60 min), NOT the smaller buffered one (30 min) — 30 min kills a
|
|
136
|
+
// healthy long tool loop, and its 504 cools the whole tier (ADR-0005 §5).
|
|
137
|
+
constants: { providerTimeoutMs: DEFAULT_STREAM_TIMEOUT_MS },
|
|
112
138
|
config: () => mergedPluginConfig(manifest.id, manifest.configSchema),
|
|
113
139
|
ocrHome: () => getOcrHomeDir(),
|
|
114
140
|
pluginDir: () => dir,
|
|
115
141
|
// Egress policy is CORE-owned (ADR-0022): a plugin wire reaches its upstream
|
|
116
142
|
// through this seam, never the global `fetch`, so `proxy.includes` /
|
|
117
143
|
// `proxy.excludes` govern plugin traffic exactly as they govern the four
|
|
118
|
-
// built-in transports. `match` carries the logical caller for the lists
|
|
119
|
-
|
|
120
|
-
|
|
144
|
+
// built-in transports. `match` carries the logical caller for the lists; the
|
|
145
|
+
// optional `egress` is the plugin-level mode folded above (`egressFor`) —
|
|
146
|
+
// absent means FOLLOW, and the same `resolveEgress` decides either way.
|
|
147
|
+
fetch: (url, init, match, egress) => proxiedFetch(url, init, match, egressFor(egress)),
|
|
148
|
+
egressProxyFor: (target, match, egress) => resolveEgress(target, match, egressFor(egress)),
|
|
121
149
|
// Filled by pluginPullServices() BEFORE createPlugin is invoked.
|
|
122
150
|
pull: {
|
|
123
151
|
getProviderNode: () => undefined,
|
|
@@ -137,6 +165,7 @@ async function pluginPullServices() {
|
|
|
137
165
|
const providerDefs = await import('../opencode/provider-defs.js');
|
|
138
166
|
const autoPull = await import('../opencode/catalog/auto-pull.js');
|
|
139
167
|
const credentials = await import('../opencode/credentials/index.js');
|
|
168
|
+
const { isMachineLoginValue } = await import('../opencode/credentials/types.js');
|
|
140
169
|
const store = await credentials.getCredentialStore();
|
|
141
170
|
return {
|
|
142
171
|
getProviderNode: (id) => userConfig.getProviderNodeById(id),
|
|
@@ -144,7 +173,16 @@ async function pluginPullServices() {
|
|
|
144
173
|
upsertModel: (id, mid, def) => userConfig.upsertProviderModel(id, mid, def),
|
|
145
174
|
matchesGlob: (pattern, id) => userConfig.matchesGlobPattern(pattern, id),
|
|
146
175
|
expandEnvTemplate: (v) => userConfig.expandEnvTemplate(v ?? undefined),
|
|
147
|
-
|
|
176
|
+
// The machine-login marker is NOT a secret (ADR-0006 amendment). A plugin
|
|
177
|
+
// that signs an upstream request with this value gets a guaranteed 401, and
|
|
178
|
+
// its own door (a web login / device bundle) is the honest alternative —
|
|
179
|
+
// "no credential" is the truthful answer for a marker-only head. Plugins
|
|
180
|
+
// whose transport maps the marker to "borrow the machine login" read the
|
|
181
|
+
// value through `createProvider`'s credential instead, so nothing loses it.
|
|
182
|
+
resolveCredentialKey: (id) => {
|
|
183
|
+
const key = store.resolveKey(id)?.key;
|
|
184
|
+
return key && !isMachineLoginValue(key) ? key : undefined;
|
|
185
|
+
},
|
|
148
186
|
catalogToDef: (m) => providerDefs.catalogModelToDef(m),
|
|
149
187
|
enrichFromCatalog: (models, excludeId) => autoPull.enrichFromCatalog(models, excludeId),
|
|
150
188
|
};
|
|
@@ -154,11 +192,11 @@ async function pluginPullServices() {
|
|
|
154
192
|
* config/CA modules, which are imported lazily so the plugin host never
|
|
155
193
|
* depends on the Client Hub at module-init time. */
|
|
156
194
|
export async function buildClientAdapterHostSdk(manifest, dir) {
|
|
157
|
-
const [{
|
|
195
|
+
const [{ resolveIngressProxyEndpoint, probeClientVersion, resolveGatewayBaseUrl }, { caCertPath, CA_CN }, { getIngressProxyStatus }, { probeCaTrustedCached }, { createApiKey, listApiKeys },] = await Promise.all([
|
|
158
196
|
import('../cli/clients/base.js'),
|
|
159
|
-
import('../
|
|
160
|
-
import('../
|
|
161
|
-
import('../
|
|
197
|
+
import('../ingress-proxy/ca.js'),
|
|
198
|
+
import('../ingress-proxy/status.js'),
|
|
199
|
+
import('../ingress-proxy/ca-trust.js'),
|
|
162
200
|
import('../auth/api-keys.js'),
|
|
163
201
|
]);
|
|
164
202
|
return {
|
|
@@ -166,9 +204,9 @@ export async function buildClientAdapterHostSdk(manifest, dir) {
|
|
|
166
204
|
ocrHome: () => getOcrHomeDir(),
|
|
167
205
|
pluginDir: () => dir,
|
|
168
206
|
config: () => mergedPluginConfig(manifest.id, manifest.configSchema),
|
|
169
|
-
|
|
207
|
+
ingressProxy: () => resolveIngressProxyEndpoint(),
|
|
170
208
|
caCertPath: () => caCertPath(),
|
|
171
|
-
|
|
209
|
+
ingressProxyStatus: () => getIngressProxyStatus(),
|
|
172
210
|
caTrust: (caPath, opts) => probeCaTrustedCached(caPath || caCertPath(), opts).then((r) => ({ trusted: r.trusted })),
|
|
173
211
|
caCommonName: () => CA_CN,
|
|
174
212
|
probeVersion: (cmd) => probeClientVersion(cmd),
|
|
@@ -178,6 +216,14 @@ export async function buildClientAdapterHostSdk(manifest, dir) {
|
|
|
178
216
|
const created = createApiKey(opts);
|
|
179
217
|
return created.success && created.data?.key ? { key: created.data.key } : null;
|
|
180
218
|
},
|
|
219
|
+
// Same egress seam a model-service wire gets (ADR-0022): a hook's artifact
|
|
220
|
+
// download is a real outbound request, so the operator's split and this
|
|
221
|
+
// package's leg switch must govern it. Without this a filtered network
|
|
222
|
+
// makes setup fail with no console-visible reason.
|
|
223
|
+
fetch: (url, init, match, egress) => proxiedFetch(url, init, match, egress ?? 'inherit'),
|
|
224
|
+
// Same snapshot the gateway half sees: an adapter materializing model
|
|
225
|
+
// files per gateway id needs the declared window per id (ADR-0041).
|
|
226
|
+
catalog: () => getGatewayChatServices()?.catalog() ?? { virtualModels: [], models: [] },
|
|
181
227
|
};
|
|
182
228
|
}
|
|
183
229
|
/** The capabilities handed to every client-gateway plugin at load time.
|
|
@@ -195,20 +241,17 @@ export function buildGatewayHostSdk(manifest, dir) {
|
|
|
195
241
|
chat: (body, sink, signal) => {
|
|
196
242
|
const svc = getGatewayChatServices();
|
|
197
243
|
if (!svc)
|
|
198
|
-
return Promise.reject(new Error('gateway chat services not wired (
|
|
199
|
-
// Identity
|
|
200
|
-
//
|
|
201
|
-
// key; with
|
|
202
|
-
// native requests never reach this seam.
|
|
203
|
-
// not only at admission: a tunnel admitted before the operator enabled
|
|
204
|
-
// `requireCredential` must not keep spending the bound key.
|
|
205
|
-
const caller = getProxyCaller();
|
|
244
|
+
return Promise.reject(new Error('gateway chat services not wired (ingress proxy disabled?)'));
|
|
245
|
+
// Identity (ADR-0008 §3 / ADR-0017): the plugin's own console-picked
|
|
246
|
+
// binding, read live. Proxy admission carries no identity, so the bound
|
|
247
|
+
// key is the ONLY source; with no binding, gateway-chat refuses the OCR
|
|
248
|
+
// turn (401). Vendor-native requests never reach this seam.
|
|
206
249
|
const bound = mergedPluginConfig(manifest.id, manifest.configSchema).accountKeyId;
|
|
207
|
-
const
|
|
208
|
-
const keyId = caller?.keyId ?? (strict ? '' : (typeof bound === 'string' ? bound : ''));
|
|
250
|
+
const keyId = typeof bound === 'string' ? bound : '';
|
|
209
251
|
return svc.run(body, sink, signal, { keyId });
|
|
210
252
|
},
|
|
211
253
|
catalog: () => getGatewayChatServices()?.catalog() ?? { virtualModels: [], models: [] },
|
|
254
|
+
resolveModel: (modelId) => getGatewayChatServices()?.resolveModel?.(modelId) ?? { kind: 'unresolved' },
|
|
212
255
|
relayUpstream: async (req, res, opts) => {
|
|
213
256
|
// Transport policy lives in core: the claimed host's rule-table egress
|
|
214
257
|
// (`direct` / `proxy.url`) and upstream TLS trust (ADR-0019) are applied
|
|
@@ -221,7 +264,7 @@ export function buildGatewayHostSdk(manifest, dir) {
|
|
|
221
264
|
// forwarder would dial the host DIRECT.
|
|
222
265
|
if (isRuleRejected(opts.host)) {
|
|
223
266
|
opts.tap?.finish(403, undefined, 'rejected by rule');
|
|
224
|
-
// The
|
|
267
|
+
// The ingress proxy's own refusal envelope (`proxyFail`), so a gateway
|
|
225
268
|
// route and the transparent leg answer identically — the core keeps
|
|
226
269
|
// ownership of its error surface.
|
|
227
270
|
proxyFail(res, 403, RULE_REJECTED_MESSAGE);
|
|
@@ -259,7 +302,7 @@ export function buildGatewayHostSdk(manifest, dir) {
|
|
|
259
302
|
* so the seams are handed over as one union rather than one host per part.
|
|
260
303
|
*
|
|
261
304
|
* The union is safe because the seams are ADDITIVE: each part type reads a
|
|
262
|
-
* different subset (`chat`/`relayUpstream` for a gateway, `
|
|
305
|
+
* different subset (`chat`/`relayUpstream` for a gateway, `ingressProxy`/
|
|
263
306
|
* `caCertPath` for an adapter, `pull`/`upstream` for a model service), and no
|
|
264
307
|
* seam can be used to do another part's job. The alternative — calling
|
|
265
308
|
* `createPlugin` once per part — would break the one-invocation contract that
|
|
@@ -306,7 +349,7 @@ function readManifest(dir) {
|
|
|
306
349
|
// console drawer, the config merge, and a plugin's own `config()` closure —
|
|
307
350
|
// then sees the SAME schema. Injected later, the drawer would offer a control
|
|
308
351
|
// the merge drops.
|
|
309
|
-
return
|
|
352
|
+
return withPluginEgressField(raw);
|
|
310
353
|
}
|
|
311
354
|
/** `readManifest`, with an unreadable/invalid manifest answered as `undefined`
|
|
312
355
|
* instead of thrown. The engine gate (ADR-0036) only needs the DECLARATION — a
|
|
@@ -378,6 +421,10 @@ export function pluginEntrySpecifier(entry, mtimeMs, bun) {
|
|
|
378
421
|
* for a part the package actually returned), plus the console row. */
|
|
379
422
|
async function importPlugin(dir, source) {
|
|
380
423
|
const manifest = readManifest(dir);
|
|
424
|
+
// The LOAD gate (ADR-0036 §4): refused code never reaches the module cache.
|
|
425
|
+
// An incompatible package is refused at install too, but only when it would
|
|
426
|
+
// displace a working install; otherwise it is parked and this is the gate
|
|
427
|
+
// that keeps it dormant until the mismatch is resolved.
|
|
381
428
|
assertSupportedPluginApi(manifest);
|
|
382
429
|
// Dev tree is source-first; a package carries the BUNDLED entry. A package
|
|
383
430
|
// without one is source-only and cannot load in a compiled sidecar, so fail
|
|
@@ -510,6 +557,19 @@ async function importPlugin(dir, source) {
|
|
|
510
557
|
});
|
|
511
558
|
}
|
|
512
559
|
manifestsById.set(manifest.id, manifest);
|
|
560
|
+
// The environment probe rides the SAME staging map as the registry (ADR-0042):
|
|
561
|
+
// a package that failed past this point never contributes a probe, and a
|
|
562
|
+
// rebuild that throws leaves the previous probe set live.
|
|
563
|
+
//
|
|
564
|
+
// Read from `returned`, not `loaded`: a single-part package returns its plugin
|
|
565
|
+
// OBJECT directly, and `asEntryResult` reshapes that into `{ provider }`,
|
|
566
|
+
// dropping every method the shape test does not name. `environment` is on both
|
|
567
|
+
// spellings at the top level, so this one read covers single- and multi-part.
|
|
568
|
+
const returnedEnvironment = returned.environment;
|
|
569
|
+
if (typeof returnedEnvironment === 'function') {
|
|
570
|
+
const probe = returnedEnvironment.bind(returned);
|
|
571
|
+
nextEnvironment.set(manifest.id, () => probe());
|
|
572
|
+
}
|
|
513
573
|
return { ...loaded, view };
|
|
514
574
|
}
|
|
515
575
|
function viewWireKey(view) {
|
|
@@ -587,6 +647,15 @@ function incompatibleView(id, source, path, declared, reason) {
|
|
|
587
647
|
export async function loadInstalledPlugins() {
|
|
588
648
|
const run = rebuildInFlight.then(doLoadInstalledPlugins);
|
|
589
649
|
rebuildInFlight = run.catch(() => []);
|
|
650
|
+
// The boot auto-pull sweeps only after this promise resolves, and the happy
|
|
651
|
+
// path signals from the tail of `doLoadInstalledPlugins`. A rebuild that THROWS
|
|
652
|
+
// would otherwise leave that sweep waiting for the lifetime of the process —
|
|
653
|
+
// signal here as well so a failed load degrades to "no plugins", not "no
|
|
654
|
+
// catalog sweep, forever, silently".
|
|
655
|
+
void run.catch(() => []).then(() => {
|
|
656
|
+
signalPluginsReady?.();
|
|
657
|
+
signalPluginsReady = undefined;
|
|
658
|
+
});
|
|
590
659
|
return run;
|
|
591
660
|
}
|
|
592
661
|
async function doLoadInstalledPlugins() {
|
|
@@ -763,14 +832,46 @@ async function doLoadInstalledPlugins() {
|
|
|
763
832
|
for (const [k, v] of nextRegistry)
|
|
764
833
|
registry.set(k, v);
|
|
765
834
|
nextRegistry.clear();
|
|
835
|
+
// Environment probes swap at the same commit point (ADR-0042). Answers for
|
|
836
|
+
// packages that are gone are dropped so a stale badge cannot outlive its
|
|
837
|
+
// package; one that merely lost its `environment()` loses its probe with it.
|
|
838
|
+
environmentProbes.clear();
|
|
839
|
+
for (const [id, probe] of nextEnvironment)
|
|
840
|
+
environmentProbes.set(id, probe);
|
|
841
|
+
nextEnvironment.clear();
|
|
842
|
+
for (const id of [...environmentCache.keys()]) {
|
|
843
|
+
if (!environmentProbes.has(id)) {
|
|
844
|
+
environmentCache.delete(id);
|
|
845
|
+
environmentVersions.delete(id);
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
// A package whose VERSION changed has a different machine contract (new
|
|
849
|
+
// requirements, or a fixed probe), so the previous answer — and the
|
|
850
|
+
// acknowledgements it was reconciled against — describe a build that is no
|
|
851
|
+
// longer installed. Dropping the cached answer makes the next console pass
|
|
852
|
+
// re-ask instead of showing an upgrade's old verdict for up to a TTL.
|
|
853
|
+
for (const view of views) {
|
|
854
|
+
if (!view.loaded)
|
|
855
|
+
continue;
|
|
856
|
+
const previous = environmentVersions.get(view.id);
|
|
857
|
+
if (previous !== undefined && previous !== view.version)
|
|
858
|
+
environmentCache.delete(view.id);
|
|
859
|
+
environmentVersions.set(view.id, view.version);
|
|
860
|
+
}
|
|
766
861
|
// The wire vocabulary follows the same commit point: the protocol decision
|
|
767
862
|
// points (`wireFor`, the dispatch tables, the console vocabulary) read this
|
|
768
863
|
// set instead of enumerating vendor protocols, so a loaded/removed plugin
|
|
769
864
|
// adds/removes its wires atomically with the registry swap.
|
|
770
865
|
claimPluginWires([...registry.values()].flatMap((entry) => entry.view.wires));
|
|
866
|
+
// Quota coverage follows the plugin set (ADR-0009 §5): which wires have a
|
|
867
|
+
// `quotaCheck` capability changes right here, atomically with the swap, so a
|
|
868
|
+
// plan built before this commit must not keep describing the old universe.
|
|
869
|
+
noteQuotaCoverageInputsChanged();
|
|
771
870
|
commitGateways();
|
|
772
871
|
commitPluginClientAdapterRebuild();
|
|
773
872
|
hostInitialized = true;
|
|
873
|
+
signalPluginsReady?.();
|
|
874
|
+
signalPluginsReady = undefined;
|
|
774
875
|
return views;
|
|
775
876
|
}
|
|
776
877
|
/** True once a full load has completed in this process. Callers that may run
|
|
@@ -816,6 +917,200 @@ let disabledViews = [];
|
|
|
816
917
|
* load — the console listing derives from this, NOT from the model-service
|
|
817
918
|
* registry, so gateways and boot-time failures stay visible (ADR-0017). */
|
|
818
919
|
let lastViews = [];
|
|
920
|
+
/**
|
|
921
|
+
* The `environment()` closures of packages that loaded with one (ADR-0042).
|
|
922
|
+
*
|
|
923
|
+
* Staged exactly like `registry` (build into `nextEnvironment`, swap at the
|
|
924
|
+
* commit point) so a rebuild that throws leaves the previous probe set live
|
|
925
|
+
* instead of half-populated — a console refresh must never be answered from a
|
|
926
|
+
* map that a failed load emptied.
|
|
927
|
+
*/
|
|
928
|
+
const environmentProbes = new Map();
|
|
929
|
+
const nextEnvironment = new Map();
|
|
930
|
+
/** Last answer per plugin, with the single-flight latch. Holds the package's
|
|
931
|
+
* OWN reports; acknowledgements are layered on at read time so a dismissal
|
|
932
|
+
* never contaminates a fresh probe's answer. */
|
|
933
|
+
const environmentCache = new Map();
|
|
934
|
+
/** Version each cached answer was produced for. An upgrade invalidates the
|
|
935
|
+
* answer at the commit point — the cache is keyed by plugin id, and an id
|
|
936
|
+
* outlives the build its verdict described. */
|
|
937
|
+
const environmentVersions = new Map();
|
|
938
|
+
function isEnvironmentReport(value) {
|
|
939
|
+
if (!value || typeof value !== 'object')
|
|
940
|
+
return false;
|
|
941
|
+
const r = value;
|
|
942
|
+
return typeof r.code === 'string' && r.code !== '';
|
|
943
|
+
}
|
|
944
|
+
/** Normalize whatever a package returned. A malformed list is NOT an error to
|
|
945
|
+
* surface as a package failure: the engine answers `unknown` for it, because
|
|
946
|
+
* "the probe is broken" and "the machine is not ready" are different facts and
|
|
947
|
+
* only one of them is the operator's to act on. */
|
|
948
|
+
function normalizeEnvironmentReports(raw) {
|
|
949
|
+
if (!Array.isArray(raw))
|
|
950
|
+
return [];
|
|
951
|
+
return raw.filter(isEnvironmentReport).map((report) => ({
|
|
952
|
+
code: report.code,
|
|
953
|
+
// `outdated` is NOT `missing`: "installed but not good enough" and "not
|
|
954
|
+
// installed" carry opposite remedies (upgrade vs install), and the plugin's
|
|
955
|
+
// path does not always make them distinguishable — qoder's CLIs are found
|
|
956
|
+
// by a login record as much as by a binary. Keeping the status token shows
|
|
957
|
+
// that fact without the engine deciding which one it is.
|
|
958
|
+
status: STATUS_TOKENS.has(report.status) ? report.status : 'unknown',
|
|
959
|
+
...(report.params ? { params: report.params } : {}),
|
|
960
|
+
}));
|
|
961
|
+
}
|
|
962
|
+
const STATUS_TOKENS = new Set(['present', 'missing', 'outdated', 'unsupported', 'unknown']);
|
|
963
|
+
async function runEnvironmentProbe(id, probe) {
|
|
964
|
+
let timer;
|
|
965
|
+
try {
|
|
966
|
+
// The bound lives HERE, once, for every package. A probe is a read of local
|
|
967
|
+
// state (a file, a `--version` banner), so it can never legitimately need
|
|
968
|
+
// longer than a version spawn; one that does is a package bug and must not
|
|
969
|
+
// hold the console for it.
|
|
970
|
+
const timeout = new Promise((_resolve, reject) => {
|
|
971
|
+
// NOT unref'd, deliberately: this timer is the ONLY thing that can settle
|
|
972
|
+
// a probe that never answers. An unref'd timer lets Bun park the loop with
|
|
973
|
+
// nothing pending and never fire (observed: a hung `environment()` hung
|
|
974
|
+
// the caller for the whole test run), which defeats the bound entirely.
|
|
975
|
+
timer = setTimeout(() => reject(new Error(`environment() did not answer within ${PLUGIN_ENVIRONMENT_PROBE_TIMEOUT_MS} ms`)), PLUGIN_ENVIRONMENT_PROBE_TIMEOUT_MS);
|
|
976
|
+
});
|
|
977
|
+
const reports = await Promise.race([probe(), timeout]);
|
|
978
|
+
return { reports: normalizeEnvironmentReports(reports), checkedAt: Date.now() };
|
|
979
|
+
}
|
|
980
|
+
catch (err) {
|
|
981
|
+
// A thrown/timed-out probe is `unknown`, never `missing`: the package code
|
|
982
|
+
// may simply have failed, and calling that "your machine is missing a
|
|
983
|
+
// dependency" is an accusation the engine cannot support.
|
|
984
|
+
console.warn(`[OCR] plugins: ${id} environment() probe failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
985
|
+
return { reports: [{ code: 'probe_failed', status: 'unknown' }], checkedAt: Date.now() };
|
|
986
|
+
}
|
|
987
|
+
finally {
|
|
988
|
+
if (timer)
|
|
989
|
+
clearTimeout(timer);
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* Ask one package's `environment()` (ADR-0042), cached stale-while-revalidate.
|
|
994
|
+
*
|
|
995
|
+
* `fresh` (the console's single re-check button) re-runs the probe. Without it a
|
|
996
|
+
* report younger than `PLUGIN_ENVIRONMENT_TTL_MS` answers from cache, and an
|
|
997
|
+
* older one answers from cache WITH a background refresh — the same contract
|
|
998
|
+
* `probeClientVersion` follows. The console calls this on mount, so a cached
|
|
999
|
+
* answer must be the normal case and a probe must never be the reason a page
|
|
1000
|
+
* stalls.
|
|
1001
|
+
*
|
|
1002
|
+
* A probe's answer is committed only if the installed VERSION is still the one
|
|
1003
|
+
* it was asked for: an upgrade can land while a probe is in flight, and the
|
|
1004
|
+
* previous build's verdict is not a fact about the new one.
|
|
1005
|
+
*/
|
|
1006
|
+
function probeEnvironmentFor(id, fresh) {
|
|
1007
|
+
const probe = environmentProbes.get(id);
|
|
1008
|
+
if (!probe)
|
|
1009
|
+
return Promise.resolve({ reports: [], checkedAt: 0 });
|
|
1010
|
+
const version = environmentVersions.get(id);
|
|
1011
|
+
const commit = (running) => running.then((state) => {
|
|
1012
|
+
// Dropped when a reload replaced the package: whatever this probe saw is
|
|
1013
|
+
// about code that is no longer installed.
|
|
1014
|
+
if (environmentVersions.get(id) === version)
|
|
1015
|
+
environmentCache.set(id, state);
|
|
1016
|
+
return state;
|
|
1017
|
+
});
|
|
1018
|
+
const hit = environmentCache.get(id);
|
|
1019
|
+
if (hit) {
|
|
1020
|
+
if (hit.probing)
|
|
1021
|
+
return hit.probing;
|
|
1022
|
+
if (fresh || Date.now() - hit.checkedAt >= PLUGIN_ENVIRONMENT_TTL_MS) {
|
|
1023
|
+
const running = commit(runEnvironmentProbe(id, probe));
|
|
1024
|
+
environmentCache.set(id, { ...hit, probing: running });
|
|
1025
|
+
void running.finally(() => {
|
|
1026
|
+
const current = environmentCache.get(id);
|
|
1027
|
+
if (current?.probing === running)
|
|
1028
|
+
environmentCache.set(id, { ...current, probing: undefined });
|
|
1029
|
+
});
|
|
1030
|
+
// A re-check waits for the answer; a TTL expiry does not.
|
|
1031
|
+
return fresh ? running : Promise.resolve({ ...hit, stale: true });
|
|
1032
|
+
}
|
|
1033
|
+
return Promise.resolve(hit);
|
|
1034
|
+
}
|
|
1035
|
+
const running = commit(runEnvironmentProbe(id, probe));
|
|
1036
|
+
environmentCache.set(id, { reports: [], checkedAt: 0, probing: running });
|
|
1037
|
+
return running;
|
|
1038
|
+
}
|
|
1039
|
+
/**
|
|
1040
|
+
* Probe every loaded package that declares `environment()` and return the
|
|
1041
|
+
* answers, keyed by plugin id. `ids` narrows the set (the acknowledgement
|
|
1042
|
+
* round-trip re-reads one package); `fresh` bypasses the TTL.
|
|
1043
|
+
*
|
|
1044
|
+
* Never called from `loadInstalledPlugins()`: a load is a filesystem walk plus
|
|
1045
|
+
* module imports, and adding subprocess spawns to it would make every boot and
|
|
1046
|
+
* every dev edit pay for a check nobody asked to see. The console reaches it on
|
|
1047
|
+
* mount and on every package-set change, which is cheap because the answers are
|
|
1048
|
+
* cached and only a package with no answer spawns anything.
|
|
1049
|
+
*/
|
|
1050
|
+
export async function refreshPluginEnvironment(opts = {}) {
|
|
1051
|
+
const wanted = opts.ids ? opts.ids.filter((id) => environmentProbes.has(id)) : [...environmentProbes.keys()];
|
|
1052
|
+
const entries = await Promise.all(wanted.map(async (id) => [id, await probeEnvironmentFor(id, opts.fresh === true)]));
|
|
1053
|
+
const out = {};
|
|
1054
|
+
for (const [id, state] of entries)
|
|
1055
|
+
out[id] = withAcknowledgements(id, state);
|
|
1056
|
+
return out;
|
|
1057
|
+
}
|
|
1058
|
+
/**
|
|
1059
|
+
* Layer the operator's acknowledgements onto one cached answer (ADR-0042).
|
|
1060
|
+
*
|
|
1061
|
+
* Applied at READ time, never stored: an acknowledgement is a statement about
|
|
1062
|
+
* the operator, and the probe's answer is a statement about the machine — folding
|
|
1063
|
+
* one into the other would make a re-armed probe inherit an old dismissal, and
|
|
1064
|
+
* would lose which is which. Acknowledged reports stay in `reports` (the panel
|
|
1065
|
+
* lists them as ignored); the badge is what stops counting them.
|
|
1066
|
+
*/
|
|
1067
|
+
function withAcknowledgements(id, state) {
|
|
1068
|
+
const view = lastViews.find((v) => v.id === id) ?? disabledViews.find((v) => v.id === id);
|
|
1069
|
+
const acks = new Set(view ? activeEnvironmentAcks(environmentAckPath(), id, view.version) : []);
|
|
1070
|
+
const reports = state.reports.map((report) => acks.has(report.code) ? { ...report, acknowledged: true } : report);
|
|
1071
|
+
return { reports, checkedAt: state.checkedAt, ...(state.stale ? { stale: true } : {}) };
|
|
1072
|
+
}
|
|
1073
|
+
/** The acknowledgement ledger's path — one root for every plugin artifact. */
|
|
1074
|
+
function environmentAckPath() {
|
|
1075
|
+
return join(pluginsRoot(), 'environment-ack.json');
|
|
1076
|
+
}
|
|
1077
|
+
/**
|
|
1078
|
+
* Dismiss one package's advisories for the INSTALLED version (ADR-0042).
|
|
1079
|
+
*
|
|
1080
|
+
* The escape hatch: a package's environment verdict can be wrong, and without
|
|
1081
|
+
* this a wrong verdict is a badge the operator can never clear. It changes no
|
|
1082
|
+
* lifecycle state — the package was, and stays, loaded and usable.
|
|
1083
|
+
*/
|
|
1084
|
+
export function acknowledgePluginEnvironment(id, codes) {
|
|
1085
|
+
const view = lastViews.find((v) => v.id === id) ?? disabledViews.find((v) => v.id === id);
|
|
1086
|
+
if (!view)
|
|
1087
|
+
throw new Error(`unknown plugin '${id}'`);
|
|
1088
|
+
const book = acknowledgeEnvironment(environmentAckPath(), id, view.version, codes);
|
|
1089
|
+
const entry = book[id];
|
|
1090
|
+
const cached = environmentCache.get(id);
|
|
1091
|
+
return {
|
|
1092
|
+
acknowledged: entry?.codes ?? [],
|
|
1093
|
+
environment: cached && cached.checkedAt !== 0 ? withAcknowledgements(id, cached) : undefined,
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
/** Re-arm every advisory for one package (forget its acknowledgements). */
|
|
1097
|
+
export function clearPluginEnvironmentAcks(id) {
|
|
1098
|
+
clearEnvironmentAcks(environmentAckPath(), id);
|
|
1099
|
+
}
|
|
1100
|
+
/** The ledger as the console reads it, keyed by package id. */
|
|
1101
|
+
export function listPluginEnvironmentAcks() {
|
|
1102
|
+
return readEnvironmentAcks(environmentAckPath());
|
|
1103
|
+
}
|
|
1104
|
+
/** The cached environment answer for one plugin, without probing. */
|
|
1105
|
+
function environmentFor(id) {
|
|
1106
|
+
const hit = environmentCache.get(id);
|
|
1107
|
+
if (!hit)
|
|
1108
|
+
return undefined;
|
|
1109
|
+
// A cache entry created only to hold the in-flight probe has nothing to show.
|
|
1110
|
+
if (hit.checkedAt === 0)
|
|
1111
|
+
return undefined;
|
|
1112
|
+
return withAcknowledgements(id, hit);
|
|
1113
|
+
}
|
|
819
1114
|
/** Facts for a disabled plugin, WITHOUT importing its code: the manifest from
|
|
820
1115
|
* the load dir when it was unpacked, else straight out of the package zip (a
|
|
821
1116
|
* tombstoned app-owned package may never have been extracted), else a bare id
|
|
@@ -899,14 +1194,52 @@ export function pluginDeclinesCredentials(plugin) {
|
|
|
899
1194
|
const types = plugin?.authTypes;
|
|
900
1195
|
return Array.isArray(types) && types.includes('none') && !types.some((t) => t === 'key' || t === 'webLogin');
|
|
901
1196
|
}
|
|
902
|
-
/**
|
|
903
|
-
|
|
1197
|
+
/**
|
|
1198
|
+
* True when `none` is AMONG the declared methods, whether or not a key or a web
|
|
1199
|
+
* login sits beside it: this provider may run on the login the plugin owns, so a
|
|
1200
|
+
* missing OCR credential is a supported state rather than a reason to drop the
|
|
1201
|
+
* provider. `pluginDeclinesCredentials` asks the narrower question "does a stored
|
|
1202
|
+
* key mean anything here?" — a plugin can answer NO to that and YES to this, and
|
|
1203
|
+
* that combination is exactly one provider with two doors.
|
|
1204
|
+
*/
|
|
1205
|
+
export function pluginRunsCredentialless(plugin) {
|
|
1206
|
+
return Array.isArray(plugin?.authTypes) && plugin.authTypes.includes('none');
|
|
1207
|
+
}
|
|
1208
|
+
/** The model-service plugin owning one provider id, found through its presets. */
|
|
1209
|
+
function providerPluginFor(providerId) {
|
|
904
1210
|
for (const { plugin, view } of registry.values()) {
|
|
905
|
-
if ((view.presets ?? []).some((preset) => preset.providerId === providerId))
|
|
906
|
-
return
|
|
907
|
-
}
|
|
1211
|
+
if ((view.presets ?? []).some((preset) => preset.providerId === providerId))
|
|
1212
|
+
return plugin;
|
|
908
1213
|
}
|
|
909
|
-
return
|
|
1214
|
+
return undefined;
|
|
1215
|
+
}
|
|
1216
|
+
/**
|
|
1217
|
+
* The plugin whose PRESET owns `providerId`, for a caller that must ask the
|
|
1218
|
+
* plugin a question rather than read a boolean.
|
|
1219
|
+
*
|
|
1220
|
+
* Exported because the console asks "is this machine's plugin login usable?"
|
|
1221
|
+
* BEFORE the connect writes the provider's def — at that moment there is no def
|
|
1222
|
+
* to resolve a wire from, and the preset map is the only handle on the plugin.
|
|
1223
|
+
*/
|
|
1224
|
+
export function presetServicePlugin(providerId) {
|
|
1225
|
+
return providerPluginFor(providerId);
|
|
1226
|
+
}
|
|
1227
|
+
/** True when `providerId` is a preset of a plugin that ignores OCR credentials. */
|
|
1228
|
+
export function providerDeclinesCredentials(providerId) {
|
|
1229
|
+
return pluginDeclinesCredentials(providerPluginFor(providerId));
|
|
1230
|
+
}
|
|
1231
|
+
/**
|
|
1232
|
+
* True when `providerId` may run on its plugin's own login (no OCR key), found
|
|
1233
|
+
* through the plugin PRESETS.
|
|
1234
|
+
*
|
|
1235
|
+
* Preset-scoped on purpose: the console's connect doors and provider cards are
|
|
1236
|
+
* preset-driven, and `connect-local` refuses a provider that is not a preset
|
|
1237
|
+
* before it ever asks this. A consumer that needs the wire-first answer for a
|
|
1238
|
+
* hand-authored def (the quota layer does) calls
|
|
1239
|
+
* `quota/cli-login.ts#providerMayUseLocalLogin` instead.
|
|
1240
|
+
*/
|
|
1241
|
+
export function providerRunsCredentialless(providerId) {
|
|
1242
|
+
return pluginRunsCredentialless(providerPluginFor(providerId));
|
|
910
1243
|
}
|
|
911
1244
|
/** Manifest id of an uploaded package, read WITHOUT touching disk. The install
|
|
912
1245
|
* route needs it up front to snapshot the version it is about to replace, so a
|
|
@@ -937,6 +1270,11 @@ export function packageIdOf(bytes) {
|
|
|
937
1270
|
* mistake or a deliberate rollback, and the console's upload button cannot tell
|
|
938
1271
|
* the two apart. "Uninstall first" is the explicit path.
|
|
939
1272
|
*
|
|
1273
|
+
* An ENGINE-INCOMPATIBLE package is stored, not refused (ADR-0036 §5): it lands
|
|
1274
|
+
* as a disabled `incompatible` row that answers no traffic and adopts the
|
|
1275
|
+
* package once the mismatch is resolved. The one exception is a swap that would
|
|
1276
|
+
* displace a package this host CAN run — see `assertInstallablePluginApi`.
|
|
1277
|
+
*
|
|
940
1278
|
* Returns the id plus the version it replaced, so the route can report what it
|
|
941
1279
|
* actually did.
|
|
942
1280
|
*/
|
|
@@ -960,7 +1298,6 @@ export function installPluginPackage(bytes, opts = {}) {
|
|
|
960
1298
|
// produced "invalid plugin.json: invalid plugin.json: ..." in the console.
|
|
961
1299
|
throw new Error(err instanceof Error ? err.message : String(err));
|
|
962
1300
|
}
|
|
963
|
-
assertSupportedPluginApi(manifest);
|
|
964
1301
|
// Ownership refusals come FIRST: a rejected install must not touch a single
|
|
965
1302
|
// plugin artifact. (Clearing the disabled ledger before this point used to
|
|
966
1303
|
// resurrect a tombstoned app-owned package on the next reload.) Both answers
|
|
@@ -971,15 +1308,24 @@ export function installPluginPackage(bytes, opts = {}) {
|
|
|
971
1308
|
if (manifest.id.startsWith('ocr-')) {
|
|
972
1309
|
throw new Error(`plugin id 'ocr-*' is reserved for app-owned packages`);
|
|
973
1310
|
}
|
|
1311
|
+
// The package this upload would replace, read BEFORE anything lands. The
|
|
1312
|
+
// engine gate needs it (a parked package may not displace a working one —
|
|
1313
|
+
// `assertInstallablePluginApi`), and the version gate below needs it too.
|
|
1314
|
+
const existingManifest = (() => {
|
|
1315
|
+
const packaged = packagePathIn(pluginsRoot(), manifest.id);
|
|
1316
|
+
return packaged ? readPackagedManifest(packaged) : undefined;
|
|
1317
|
+
})();
|
|
1318
|
+
// ENGINE-COMPATIBILITY at INSTALL (ADR-0036 §5): incompatible is PARKED, not
|
|
1319
|
+
// refused — the bytes land and the loader lists them as a disabled
|
|
1320
|
+
// `incompatible` row, which is also how a package already on disk is treated
|
|
1321
|
+
// once the gateway is downgraded under it. Its code is never imported: the
|
|
1322
|
+
// load gate runs before `importPlugin` and before `ensureUnpacked`.
|
|
1323
|
+
assertInstallablePluginApi(manifest, existingManifest);
|
|
974
1324
|
// Version gate BEFORE anything lands on disk. A same-version upload is a
|
|
975
1325
|
// rebuild (allowed — that is how a broken build gets replaced), a higher one
|
|
976
1326
|
// is an upgrade, a lower one is refused so a stale download cannot silently
|
|
977
1327
|
// roll a fixed install back.
|
|
978
1328
|
let replacedVersion;
|
|
979
|
-
const existingManifest = (() => {
|
|
980
|
-
const packaged = packagePathIn(pluginsRoot(), manifest.id);
|
|
981
|
-
return packaged ? readPackagedManifest(packaged) : undefined;
|
|
982
|
-
})();
|
|
983
1329
|
if (existingManifest) {
|
|
984
1330
|
replacedVersion = existingManifest.version;
|
|
985
1331
|
if (!opts.allowDowngrade && compareVersions(manifest.version, existingManifest.version) < 0) {
|
|
@@ -1064,24 +1410,88 @@ export function discardPluginPackage(id) {
|
|
|
1064
1410
|
rmSync(join(root, `${id}.zip`), { force: true });
|
|
1065
1411
|
rmSync(join(root, 'unpacked', id), { recursive: true, force: true });
|
|
1066
1412
|
}
|
|
1067
|
-
/**
|
|
1068
|
-
*
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1413
|
+
/** The OCR home a package's own state lives under — the root the documented
|
|
1414
|
+
* `state`-path convention resolves against. */
|
|
1415
|
+
function pluginStateRoot() {
|
|
1416
|
+
return getOcrHomeDir();
|
|
1417
|
+
}
|
|
1418
|
+
/** A declared `state` path, resolved against the OCR home, or undefined when the
|
|
1419
|
+
* declaration would reach outside what uninstall owns. The RULE lives in
|
|
1420
|
+
* `manifest.ts` (`resolvePluginStatePath`) so the packager's refusal and this
|
|
1421
|
+
* sweep can never drift into two answers for one declaration. */
|
|
1422
|
+
function resolveStateTarget(id, raw) {
|
|
1423
|
+
const rel = resolvePluginStatePath(id, raw);
|
|
1424
|
+
if (!rel)
|
|
1425
|
+
return undefined;
|
|
1426
|
+
const abs = join(pluginStateRoot(), ...rel);
|
|
1427
|
+
const root = pluginStateRoot();
|
|
1428
|
+
return abs !== root && abs.startsWith(root + sep) ? abs : undefined;
|
|
1429
|
+
}
|
|
1430
|
+
/** Every artifact a package declared under `state`, resolved. */
|
|
1431
|
+
function declaredStateTargets(id, declared) {
|
|
1432
|
+
return (declared ?? []).map((raw) => resolveStateTarget(id, raw)).filter((p) => p !== undefined);
|
|
1433
|
+
}
|
|
1434
|
+
/**
|
|
1435
|
+
* Absolute state paths a DIFFERENT loaded package also declares — the ones
|
|
1436
|
+
* uninstall must keep so removing one plugin never deletes another's live
|
|
1437
|
+
* state. `plugins/clients` is the canonical shared path (every gateway hook
|
|
1438
|
+
* writes its launcher there, and a package cannot name a sibling's `<id>-` file),
|
|
1439
|
+
* so the directory itself must survive any single uninstall.
|
|
1440
|
+
*/
|
|
1441
|
+
function sharedDeclaredStatePaths(excludingId) {
|
|
1442
|
+
const paths = new Set();
|
|
1443
|
+
for (const [otherId, manifest] of manifestsById) {
|
|
1444
|
+
if (otherId === excludingId)
|
|
1445
|
+
continue;
|
|
1446
|
+
for (const target of declaredStateTargets(otherId, manifest.state))
|
|
1447
|
+
paths.add(target);
|
|
1448
|
+
}
|
|
1449
|
+
return paths;
|
|
1450
|
+
}
|
|
1451
|
+
/** Uninstall a plugin: remove its package, unpacked copy, every artifact it
|
|
1452
|
+
* wrote `state`, registered preset providers and the console's traffic feed,
|
|
1453
|
+
* then the caller reloads — the plugin leaves NOTHING behind except what the
|
|
1454
|
+
* caller chose to keep (a shipped package is tombstoned instead, because the
|
|
1455
|
+
* app owns the file; dev-tree plugins are OWNED by the operator's checkout).
|
|
1456
|
+
*
|
|
1457
|
+
* The operator's SETTINGS (`config/<id>.json`) are KEPT by default: a
|
|
1458
|
+
* reinstall is how a plugin is upgraded or restored, and it must land on the
|
|
1459
|
+
* operator's values instead of the manifest defaults. `purgeConfig` is the
|
|
1460
|
+
* explicit "remove them too" choice the console offers in the same dialog.
|
|
1461
|
+
*/
|
|
1462
|
+
export async function uninstallPlugin(id, opts = {}) {
|
|
1074
1463
|
if (!isValidPluginId(id))
|
|
1075
1464
|
throw new Error('invalid plugin id');
|
|
1076
1465
|
const removed = [];
|
|
1466
|
+
const kept = [];
|
|
1077
1467
|
const packRoot = pluginsRoot();
|
|
1468
|
+
// What the package declared it writes, resolved BEFORE the tombstone branch
|
|
1469
|
+
// so both branches agree on it (`incompatibleView` registers the manifest, so
|
|
1470
|
+
// this works for a refused package too).
|
|
1471
|
+
const declaredState = manifestsById.get(id)?.state;
|
|
1078
1472
|
// Packages shipped WITH the app are not operator-owned files: uninstall is a
|
|
1079
1473
|
// TOMBSTONE in the disabled ledger, so an upgrade that re-seeds the same
|
|
1080
1474
|
// package does not silently bring it back. That IS `setPluginDisabled(id,
|
|
1081
1475
|
// true)` — delegate, so a tombstone and a disable can never drift apart.
|
|
1082
1476
|
if (bundledPackagePath(id)) {
|
|
1083
1477
|
const { providersRemoved } = await setPluginDisabled(id, true);
|
|
1084
|
-
|
|
1478
|
+
// The app owns the FILE, not the extraction tree: a tombstoned package must
|
|
1479
|
+
// not leave its unpacked copy behind, or re-enabling (or a later release)
|
|
1480
|
+
// would adopt code extracted from the copy that was tombstoned. `removed`
|
|
1481
|
+
// stays empty on purpose — the response reports OPERATOR artifacts, and
|
|
1482
|
+
// this one is core scratch.
|
|
1483
|
+
const tombstonedUnpacked = join(packRoot, 'unpacked', id);
|
|
1484
|
+
if (existsSync(tombstonedUnpacked)) {
|
|
1485
|
+
rmSync(tombstonedUnpacked, { recursive: true, force: true });
|
|
1486
|
+
try {
|
|
1487
|
+
if (readdirSync(join(packRoot, 'unpacked')).length === 0)
|
|
1488
|
+
rmSync(join(packRoot, 'unpacked'), { recursive: true, force: true });
|
|
1489
|
+
}
|
|
1490
|
+
catch {
|
|
1491
|
+
// absent — nothing to prune
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
return { removed: [], providersRemoved, kept, devOnly: false };
|
|
1085
1495
|
}
|
|
1086
1496
|
// Free-form names, same as discovery: every package that CLAIMS the id is
|
|
1087
1497
|
// operator state, so all of them go — not just the first one found.
|
|
@@ -1104,25 +1514,66 @@ export async function uninstallPlugin(id) {
|
|
|
1104
1514
|
}
|
|
1105
1515
|
}
|
|
1106
1516
|
const providersRemoved = await removePluginRegistrations(id);
|
|
1107
|
-
//
|
|
1108
|
-
//
|
|
1109
|
-
//
|
|
1110
|
-
//
|
|
1517
|
+
// Everything the package wrote under the OCR home: its declared artifacts
|
|
1518
|
+
// (`state`, resolved against the same rules the packager enforces) plus the
|
|
1519
|
+
// console-owned traffic feed, which the package never declares because the
|
|
1520
|
+
// CONSOLE writes it — and which `traffic-clear` can no longer reach once
|
|
1521
|
+
// uninstall has dropped the gateway from the registry.
|
|
1522
|
+
const stateTargets = [...declaredStateTargets(id, declaredState), join(pluginStateRoot(), 'plugins', 'traffic', id)];
|
|
1523
|
+
// A `state` path may be SHARED — e.g. `plugins/clients` (the launcher dir the
|
|
1524
|
+
// gateway hooks write their scripts into) is declared by every gateway
|
|
1525
|
+
// package, because a package CANNOT name a sibling's `<id>-` file and the
|
|
1526
|
+
// directory is the shared home. Deleting such a path while another loaded
|
|
1527
|
+
// package still declares it would remove ANOTHER plugin's live state (a
|
|
1528
|
+
// surviving gateway's launcher). So a target also named by a DIFFERENT loaded
|
|
1529
|
+
// manifest is KEPT, not swept — the safety the packager's "never another
|
|
1530
|
+
// plugin's file" note promises. The traffic feed is unique by id and never
|
|
1531
|
+
// shared, so it is exempt.
|
|
1532
|
+
const sharedStatePaths = sharedDeclaredStatePaths(id);
|
|
1533
|
+
for (const target of stateTargets) {
|
|
1534
|
+
if (!existsSync(target))
|
|
1535
|
+
continue;
|
|
1536
|
+
if (sharedStatePaths.has(target)) {
|
|
1537
|
+
kept.push(target);
|
|
1538
|
+
continue;
|
|
1539
|
+
}
|
|
1540
|
+
rmSync(target, { recursive: true, force: true });
|
|
1541
|
+
removed.push(target);
|
|
1542
|
+
}
|
|
1543
|
+
// Operator settings are plugin state too, but they are the ONE thing a
|
|
1544
|
+
// reinstall is supposed to inherit (an UPGRADE is a plain install OVER the
|
|
1545
|
+
// existing id and never touches this file). So they are kept unless the
|
|
1546
|
+
// operator asked for the clean slate.
|
|
1111
1547
|
const configFile = pluginConfigPath(id);
|
|
1112
1548
|
if (existsSync(configFile)) {
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1549
|
+
if (opts.purgeConfig) {
|
|
1550
|
+
rmSync(configFile, { force: true });
|
|
1551
|
+
removed.push(configFile);
|
|
1552
|
+
const configDir = dirname(configFile);
|
|
1553
|
+
// Leave no empty `plugins/config/` behind either.
|
|
1554
|
+
try {
|
|
1555
|
+
if (readdirSync(configDir).length === 0)
|
|
1556
|
+
rmSync(configDir, { recursive: true, force: true });
|
|
1557
|
+
}
|
|
1558
|
+
catch {
|
|
1559
|
+
// absent or unreadable — nothing to prune
|
|
1560
|
+
}
|
|
1120
1561
|
}
|
|
1121
|
-
|
|
1122
|
-
|
|
1562
|
+
else {
|
|
1563
|
+
kept.push(configFile);
|
|
1123
1564
|
}
|
|
1124
1565
|
}
|
|
1125
1566
|
invalidatePluginConfigCache(id);
|
|
1567
|
+
// Provenance outlives nothing: a plugin id that is no longer installed must
|
|
1568
|
+
// not keep pointing the updates panel at a repository (ADR-0037 §7). A
|
|
1569
|
+
// reinstall records its own source again.
|
|
1570
|
+
try {
|
|
1571
|
+
const { forgetPluginSource } = await import('./market.js');
|
|
1572
|
+
forgetPluginSource(id);
|
|
1573
|
+
}
|
|
1574
|
+
catch {
|
|
1575
|
+
// A provenance write failure must not fail an uninstall.
|
|
1576
|
+
}
|
|
1126
1577
|
removeGateway(id); // stop answering immediately; the caller's reload commits the full rebuild
|
|
1127
1578
|
// An uninstalled plugin must not linger as a disabled stub row.
|
|
1128
1579
|
const disabled = readDisabled();
|
|
@@ -1132,7 +1583,7 @@ export async function uninstallPlugin(id) {
|
|
|
1132
1583
|
// Dev-tree plugin: its source directory is operator-owned, but any preset
|
|
1133
1584
|
// providers it had registered are cleanly unregistered.
|
|
1134
1585
|
if (providersRemoved.length > 0)
|
|
1135
|
-
return { removed, providersRemoved, devOnly: true };
|
|
1586
|
+
return { removed, providersRemoved, kept, devOnly: true };
|
|
1136
1587
|
// A row the host is CURRENTLY SHOWING that owns no artifact on disk: its
|
|
1137
1588
|
// package was removed out from under us (an operator cleanup of
|
|
1138
1589
|
// `plugins/`, a package the install route already discarded on load
|
|
@@ -1143,10 +1594,10 @@ export async function uninstallPlugin(id) {
|
|
|
1143
1594
|
// directory the operator owns and must delete themselves.
|
|
1144
1595
|
const shown = lastViews.find((v) => v.id === id);
|
|
1145
1596
|
if (shown && shown.source !== 'dev')
|
|
1146
|
-
return { removed, providersRemoved };
|
|
1597
|
+
return { removed, providersRemoved, kept };
|
|
1147
1598
|
throw new Error(`no installed package for '${id}' — unknown id, or a dev-tree plugin (delete its directory to remove it)`);
|
|
1148
1599
|
}
|
|
1149
|
-
return { removed, providersRemoved };
|
|
1600
|
+
return { removed, providersRemoved, kept };
|
|
1150
1601
|
}
|
|
1151
1602
|
function registrationsPath() {
|
|
1152
1603
|
return join(pluginsRoot(), 'registrations.json');
|
|
@@ -1291,17 +1742,17 @@ function matchesRegistration(snapshot, current) {
|
|
|
1291
1742
|
}
|
|
1292
1743
|
/** A MEANINGFUL def is operator-owned and never overwritten/deleted, and
|
|
1293
1744
|
* joins the ledger (provenance tag/filter). A bare stub (New-custom leftover:
|
|
1294
|
-
* only a
|
|
1295
|
-
* operator file node the plugin never created; an existing node is NEVER
|
|
1745
|
+
* only a protocol-slot field) is left un-ledgered so uninstall never deletes
|
|
1746
|
+
* an operator file node the plugin never created; an existing node is NEVER
|
|
1296
1747
|
* taken over by a preset (syncPluginPresets skips every id already present).
|
|
1297
1748
|
* Reads the RAW defs-file node:
|
|
1298
|
-
* getProviderNodeById returns a normalized view that derives
|
|
1299
|
-
*
|
|
1749
|
+
* getProviderNodeById returns a normalized view that derives protocols/options
|
|
1750
|
+
* from settings, which would make even a bare stub look meaningful. */
|
|
1300
1751
|
function isMeaningfulDef(raw) {
|
|
1301
1752
|
return Boolean(raw &&
|
|
1302
1753
|
Object.entries(raw).some(([key, value]) => {
|
|
1303
|
-
if (key === 'package')
|
|
1304
|
-
return false; // a New-custom stub is ONLY a
|
|
1754
|
+
if (key === 'package' || key === 'protocols')
|
|
1755
|
+
return false; // a New-custom stub is ONLY a protocol-slot field
|
|
1305
1756
|
if (key === 'models')
|
|
1306
1757
|
return Boolean(value && typeof value === 'object' && Object.keys(value).length > 0);
|
|
1307
1758
|
return value !== undefined && value !== null && value !== '' && !(typeof value === 'object' && Object.keys(value).length === 0);
|
|
@@ -1311,7 +1762,8 @@ function isMeaningfulDef(raw) {
|
|
|
1311
1762
|
* the console probe and the web-login resolver use (`wireFor(npm)` first,
|
|
1312
1763
|
* baseURL fingerprint only when no package is declared). */
|
|
1313
1764
|
function defWireOf(raw) {
|
|
1314
|
-
const
|
|
1765
|
+
const protocols = Array.isArray(raw.protocols) ? raw.protocols.filter((x) => typeof x === 'string') : [];
|
|
1766
|
+
const pkg = protocols[0] ?? (typeof raw.package === 'string' ? raw.package : typeof raw.npm === 'string' ? raw.npm : '');
|
|
1315
1767
|
if (pkg)
|
|
1316
1768
|
return wireFor(pkg);
|
|
1317
1769
|
const settings = raw.settings && typeof raw.settings === 'object' ? raw.settings : {};
|
|
@@ -1331,13 +1783,54 @@ function presetWireIsBroken(raw) {
|
|
|
1331
1783
|
return false; // v1 node shape: the import owns it
|
|
1332
1784
|
return defWireOf(raw) === 'unroutable';
|
|
1333
1785
|
}
|
|
1786
|
+
/** The baseURL a RAW defs-file node dials — same slot precedence as
|
|
1787
|
+
* `defWireOf`, normalized so case and a trailing slash never split a match. */
|
|
1788
|
+
function defBaseUrlOf(raw) {
|
|
1789
|
+
const settings = raw.settings && typeof raw.settings === 'object' ? raw.settings : {};
|
|
1790
|
+
const options = raw.options && typeof raw.options === 'object' ? raw.options : {};
|
|
1791
|
+
return String(settings.baseURL ?? options.baseURL ?? raw.baseURL ?? '')
|
|
1792
|
+
.trim()
|
|
1793
|
+
.toLowerCase()
|
|
1794
|
+
.replace(/\/+$/, '');
|
|
1795
|
+
}
|
|
1796
|
+
/** A preset provider whose wire the CLIENT MATERIALIZER downgraded.
|
|
1797
|
+
*
|
|
1798
|
+
* The opencode client has no SDK package for a plugin wire, so the materializer
|
|
1799
|
+
* writes the compatible fallback (`CLIENT_COMPATIBLE_PACKAGE`, see
|
|
1800
|
+
* `def-materialize.ts#clientPackageFallbackFor`) into the client copy. The
|
|
1801
|
+
* one-shot boot import then reads that client file back as truth and lands the
|
|
1802
|
+
* fallback wire in `providers.json`, where the def IS routable — so
|
|
1803
|
+
* `presetWireIsBroken` never fires — but can never reach its plugin: no
|
|
1804
|
+
* executor on the wire, and the console answers "not on a plugin wire with a
|
|
1805
|
+
* web-login capability".
|
|
1806
|
+
*
|
|
1807
|
+
* Scope is deliberately the PRESET'S OWN endpoint: a fallback-wired def at any
|
|
1808
|
+
* other baseURL is an operator's routing choice and stays untouched. A retired
|
|
1809
|
+
* node shape stays with the defs import, same as `presetWireIsBroken`.
|
|
1810
|
+
*
|
|
1811
|
+
* `compatibleWire` is `CLIENT_COMPATIBLE_PACKAGE`, read from the SAME dynamic
|
|
1812
|
+
* user-config import `syncPluginPresets` already makes: a test that mocks that
|
|
1813
|
+
* module without the constant simply never matches here (it is exercising the
|
|
1814
|
+
* boot pool, not presets), instead of dying on a missing named export. */
|
|
1815
|
+
function presetWireWasDowngraded(raw, presetWire, presetBaseUrl, compatibleWire) {
|
|
1816
|
+
if (!isPluginWire(presetWire))
|
|
1817
|
+
return false;
|
|
1818
|
+
if (raw.npm !== undefined || raw.options !== undefined)
|
|
1819
|
+
return false;
|
|
1820
|
+
if (!compatibleWire || defWireOf(raw) !== compatibleWire)
|
|
1821
|
+
return false;
|
|
1822
|
+
const base = defBaseUrlOf(raw);
|
|
1823
|
+
return base !== '' && base === presetBaseUrl.trim().toLowerCase().replace(/\/+$/, '');
|
|
1824
|
+
}
|
|
1334
1825
|
/** Rewrite ONLY the routing slot of a broken preset def. Every other slot the
|
|
1335
1826
|
* operator owns (name, baseURL/settings, headers, env, body, models) rides
|
|
1336
1827
|
* through untouched — the def could not have routed anywhere before, so no
|
|
1337
1828
|
* working configuration is lost. */
|
|
1338
1829
|
function repairPresetWire(raw, presetWire) {
|
|
1339
|
-
const next = { ...raw,
|
|
1830
|
+
const next = { ...raw, protocols: [presetWire] };
|
|
1340
1831
|
delete next.npm;
|
|
1832
|
+
delete next.package;
|
|
1833
|
+
delete next.protocol;
|
|
1341
1834
|
return next;
|
|
1342
1835
|
}
|
|
1343
1836
|
/** Def name a preset registers: the manifest's `displayName` (plain string) or
|
|
@@ -1350,7 +1843,7 @@ function presetDefName(preset) {
|
|
|
1350
1843
|
/** Register every not-yet-defined preset of every loaded plugin, and RETIRE the
|
|
1351
1844
|
* ones the plugin no longer declares. A preset is skipped whenever the defs
|
|
1352
1845
|
* file already holds a MEANINGFUL node with that id, so presets never take
|
|
1353
|
-
* over operator file state; a bare
|
|
1846
|
+
* over operator file state; a bare protocol-only stub (the New-custom form or
|
|
1354
1847
|
* the boot bind sweep's node — machine-written, no operator content) is fair
|
|
1355
1848
|
* game and the preset overwrites it. The ONE exception is an unroutable wire
|
|
1356
1849
|
* spelling (an older plugin generation's SDK package, e.g.
|
|
@@ -1363,7 +1856,7 @@ function presetDefName(preset) {
|
|
|
1363
1856
|
* just stops being claimed.
|
|
1364
1857
|
* Returns the provider ids registered or wire-repaired (boot/reload logging). */
|
|
1365
1858
|
export async function syncPluginPresets() {
|
|
1366
|
-
const { upsertProviderDef, deleteProviderDef } = await import('../opencode/user-config.js');
|
|
1859
|
+
const { upsertProviderDef, deleteProviderDef, CLIENT_COMPATIBLE_PACKAGE } = await import('../opencode/user-config.js');
|
|
1367
1860
|
const { readProviderDefsFile, writeProviderDefs } = await import('../opencode/provider-defs.js');
|
|
1368
1861
|
const created = [];
|
|
1369
1862
|
const ledger = readRegistrations();
|
|
@@ -1416,7 +1909,8 @@ export async function syncPluginPresets() {
|
|
|
1416
1909
|
// it only joins the ledger, so uninstall leaves it alone. A BARE
|
|
1417
1910
|
// stub (isMeaningfulDef === false) is machine residue, not operator
|
|
1418
1911
|
// state: fall through and let the preset take the id over.
|
|
1419
|
-
|
|
1912
|
+
const downgraded = presetWireWasDowngraded(raw, presetWire, preset.baseUrl, CLIENT_COMPATIBLE_PACKAGE);
|
|
1913
|
+
if (presetWireIsBroken(raw) || downgraded) {
|
|
1420
1914
|
const repaired = repairPresetWire(raw, presetWire);
|
|
1421
1915
|
const providers = { ...(readProviderDefsFile()?.providers ?? {}) };
|
|
1422
1916
|
providers[preset.providerId] = repaired;
|
|
@@ -1424,23 +1918,30 @@ export async function syncPluginPresets() {
|
|
|
1424
1918
|
mine.add(preset.providerId);
|
|
1425
1919
|
written[preset.providerId] = repaired;
|
|
1426
1920
|
created.push(preset.providerId);
|
|
1427
|
-
console.warn(`[OCR] plugins: repaired provider '${preset.providerId}' (plugin ${view.id}) — wire '${defWireOf(raw)}' -> '${presetWire}'`);
|
|
1428
|
-
continue;
|
|
1429
|
-
}
|
|
1430
|
-
if (entry.written?.[preset.providerId] !== undefined) {
|
|
1431
|
-
mine.add(preset.providerId);
|
|
1432
|
-
written[preset.providerId] = entry.written[preset.providerId];
|
|
1921
|
+
console.warn(`[OCR] plugins: repaired provider '${preset.providerId}' (plugin ${view.id}) — wire '${defWireOf(raw)}' -> '${presetWire}'${downgraded ? ' (client-compatible fallback read back by the importer)' : ''}`);
|
|
1433
1922
|
continue;
|
|
1434
1923
|
}
|
|
1924
|
+
// Meaningful content is ALWAYS operator-owned, snapshot or not: a
|
|
1925
|
+
// def we once wrote that has since been edited (own baseURL/models)
|
|
1926
|
+
// must never be clobbered. The snapshot rides along so uninstall can
|
|
1927
|
+
// still tell a pristine def apart from the edit.
|
|
1435
1928
|
if (isMeaningfulDef(raw)) {
|
|
1436
1929
|
mine.add(preset.providerId);
|
|
1930
|
+
if (entry.written?.[preset.providerId] !== undefined) {
|
|
1931
|
+
written[preset.providerId] = entry.written[preset.providerId];
|
|
1932
|
+
}
|
|
1437
1933
|
continue;
|
|
1438
1934
|
}
|
|
1935
|
+
// A bare stub is machine residue even when a STALE snapshot exists:
|
|
1936
|
+
// the boot credential-bind sweep can overwrite a def we wrote with
|
|
1937
|
+
// `{"protocols":["openai-chat"]}`, and consulting the ledger first
|
|
1938
|
+
// would skip it forever (the provider then answers "not on a plugin
|
|
1939
|
+
// wire with a web-login capability"). Fall through and take it over.
|
|
1439
1940
|
}
|
|
1440
1941
|
const result = upsertProviderDef({
|
|
1441
1942
|
id: preset.providerId,
|
|
1442
1943
|
name: presetDefName(preset),
|
|
1443
|
-
|
|
1944
|
+
protocols: [presetWire],
|
|
1444
1945
|
baseURL: preset.baseUrl,
|
|
1445
1946
|
});
|
|
1446
1947
|
if (result.success) {
|
|
@@ -1504,7 +2005,7 @@ export async function ensurePresetProvider(providerId) {
|
|
|
1504
2005
|
return upsertProviderDef({
|
|
1505
2006
|
id: preset.providerId,
|
|
1506
2007
|
name: presetDefName(preset),
|
|
1507
|
-
|
|
2008
|
+
protocols: [presetWire],
|
|
1508
2009
|
baseURL: preset.baseUrl,
|
|
1509
2010
|
}).success;
|
|
1510
2011
|
}
|
|
@@ -1581,10 +2082,15 @@ const LANG_TO_BCP47 = {
|
|
|
1581
2082
|
export async function pluginPresetCatalogEntries(lang) {
|
|
1582
2083
|
const { getCredentialStore } = await import('../opencode/credentials/index.js');
|
|
1583
2084
|
const { readProviderDefsFile } = await import('../opencode/provider-defs.js');
|
|
1584
|
-
|
|
2085
|
+
// ITERATE FIRST, await after. A registry rebuild swaps `registry` at a commit
|
|
2086
|
+
// point, so awaiting between the loop and the reads let a request render rows
|
|
2087
|
+
// from the OLD registry against the NEW credential store — a card that says
|
|
2088
|
+
// "connected" for a package that was just uninstalled, or vice versa.
|
|
2089
|
+
const views = [...registry.values()];
|
|
1585
2090
|
const defs = readProviderDefsFile()?.providers ?? {};
|
|
2091
|
+
const store = await getCredentialStore();
|
|
1586
2092
|
const out = [];
|
|
1587
|
-
for (const { plugin, view } of
|
|
2093
|
+
for (const { plugin, view } of views) {
|
|
1588
2094
|
const logoUrl = view.logo ? `/api/admin/plugins/${view.id}/logo` : undefined;
|
|
1589
2095
|
for (const preset of view.presets ?? []) {
|
|
1590
2096
|
const key = lang ? (LANG_TO_BCP47[lang] ?? (lang.includes('-') ? lang : undefined)) : undefined;
|
|
@@ -1601,13 +2107,14 @@ export async function pluginPresetCatalogEntries(lang) {
|
|
|
1601
2107
|
name,
|
|
1602
2108
|
defaultName,
|
|
1603
2109
|
logo: logoUrl,
|
|
1604
|
-
|
|
2110
|
+
protocols: [currentProtocol(preset.protocol || preset.npm)],
|
|
1605
2111
|
baseURL: preset.baseUrl,
|
|
1606
2112
|
custom: true,
|
|
1607
|
-
// A plugin that
|
|
1608
|
-
//
|
|
1609
|
-
//
|
|
1610
|
-
connected
|
|
2113
|
+
// A plugin that can run on its own login is connected when its def exists:
|
|
2114
|
+
// for it a stored key is optional, and demanding one would keep the card on
|
|
2115
|
+
// the connect form while the machine login is already serving traffic. A
|
|
2116
|
+
// plugin that needs a credential is connected only when it holds one.
|
|
2117
|
+
connected: pluginRunsCredentialless(plugin)
|
|
1611
2118
|
? Boolean(defs[preset.providerId])
|
|
1612
2119
|
: Boolean(store.resolveKey(preset.providerId)?.key),
|
|
1613
2120
|
// Console connect card offers the web-authorization button when the
|
|
@@ -1696,6 +2203,19 @@ export function getPluginConfig(id) {
|
|
|
1696
2203
|
export function getPluginWarningLabels(id) {
|
|
1697
2204
|
return manifestsById.get(id)?.warningLabels;
|
|
1698
2205
|
}
|
|
2206
|
+
/** Console listing WITH the cached environment answer attached (ADR-0042).
|
|
2207
|
+
*
|
|
2208
|
+
* A separate reader from `listInstalledPlugins()` on purpose: that one is used
|
|
2209
|
+
* by dispatch, uninstall and the API-key routes, none of which should start
|
|
2210
|
+
* carrying a probe's timestamp, and the console is the only caller that wants
|
|
2211
|
+
* one. The cached answer is attached; probing is the caller's explicit step
|
|
2212
|
+
* (`refreshPluginEnvironment`), never a side effect of listing. */
|
|
2213
|
+
export function listInstalledPluginsWithEnvironment() {
|
|
2214
|
+
return listInstalledPlugins().map((view) => {
|
|
2215
|
+
const environment = environmentFor(view.id);
|
|
2216
|
+
return environment ? { ...view, environment } : view;
|
|
2217
|
+
});
|
|
2218
|
+
}
|
|
1699
2219
|
/** Console config write: validate + persist + fire the plugin's optional
|
|
1700
2220
|
* onConfigChange. Returns the merged values and any validation warnings. */
|
|
1701
2221
|
export async function applyPluginConfig(id, values) {
|
|
@@ -1704,6 +2224,24 @@ export async function applyPluginConfig(id, values) {
|
|
|
1704
2224
|
throw new Error('unknown or unloaded plugin');
|
|
1705
2225
|
if (!manifest.configSchema?.length)
|
|
1706
2226
|
throw new Error('plugin declares no configurable fields');
|
|
2227
|
+
// A gateway that must go through the outbound proxy, while none is
|
|
2228
|
+
// configured, is a contradictory config: the leg would be REFUSED at dial
|
|
2229
|
+
// time (502), so SETTING it is rejected here with the same sentence instead
|
|
2230
|
+
// of letting the operator discover it from a broken host. Refused BEFORE any
|
|
2231
|
+
// write, so a rejected save changes nothing.
|
|
2232
|
+
//
|
|
2233
|
+
// Only a TRANSITION is refused. A config already on disk (a hand edit, an
|
|
2234
|
+
// older install, a proxy that was on when it was saved) must stay editable —
|
|
2235
|
+
// otherwise this guard would block every unrelated field on that plugin until
|
|
2236
|
+
// the operator turned the outbound proxy back on.
|
|
2237
|
+
const nextEgress = operatorEgressChoice(values);
|
|
2238
|
+
if (nextEgress === 'proxy' && !isEgressProxyEnabled()) {
|
|
2239
|
+
const storedEgress = operatorEgressChoice(readStoredConfig(id));
|
|
2240
|
+
if (storedEgress !== 'proxy') {
|
|
2241
|
+
throw new Error('this plugin is set to route through the outbound proxy, but no outbound proxy is configured — ' +
|
|
2242
|
+
'enable `proxy.enabled` on the Proxy page first, or pick "direct" / "follow" for this plugin');
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
1707
2245
|
const result = writePluginConfig(id, manifest.configSchema, values);
|
|
1708
2246
|
// The leg switch is the one config value CORE consumes rather than forwards:
|
|
1709
2247
|
// replacing the registry tier makes the operator's pick authoritative from the
|