omnicell-router 0.8.4 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -7
- package/README.zh-CN.md +18 -5
- package/backend/dist/capture/recorder.d.ts +4 -10
- package/backend/dist/capture/recorder.js +6 -58
- package/backend/dist/cli/clients/base.d.ts +36 -11
- package/backend/dist/cli/clients/base.js +31 -15
- package/backend/dist/cli/clients/claude.d.ts +9 -0
- package/backend/dist/cli/clients/claude.js +6 -0
- package/backend/dist/cli/clients/codex.d.ts +8 -0
- package/backend/dist/cli/clients/codex.js +5 -0
- package/backend/dist/cli/clients/core-adapters.d.ts +1 -1
- package/backend/dist/cli/clients/core-adapters.js +1 -1
- package/backend/dist/cli/clients/dsh.d.ts +8 -0
- package/backend/dist/cli/clients/dsh.js +5 -0
- package/backend/dist/cli/clients/grok.d.ts +15 -1
- package/backend/dist/cli/clients/grok.js +16 -2
- package/backend/dist/cli/clients/index.d.ts +13 -1
- package/backend/dist/cli/clients/index.js +97 -19
- package/backend/dist/cli/clients/kimi.d.ts +6 -0
- package/backend/dist/cli/clients/kimi.js +3 -0
- package/backend/dist/cli/clients/launcher.d.ts +1 -1
- package/backend/dist/cli/clients/model-meta.js +6 -3
- package/backend/dist/cli/clients/omp.d.ts +6 -0
- package/backend/dist/cli/clients/omp.js +3 -0
- package/backend/dist/cli/clients/openclaw.d.ts +6 -0
- package/backend/dist/cli/clients/openclaw.js +3 -0
- package/backend/dist/cli/clients/opencode.d.ts +8 -0
- package/backend/dist/cli/clients/opencode.js +5 -0
- package/backend/dist/cli/clients/pi.d.ts +6 -0
- package/backend/dist/cli/clients/pi.js +3 -0
- package/backend/dist/cli/clients/update-check.d.ts +37 -0
- package/backend/dist/cli/clients/update-check.js +309 -0
- package/backend/dist/cli/clients/workbuddy.d.ts +19 -0
- package/backend/dist/cli/clients/workbuddy.js +66 -0
- package/backend/dist/cli/index.js +5 -4
- package/backend/dist/cli/paths.js +8 -0
- package/backend/dist/cli/types.d.ts +92 -16
- package/backend/dist/config/comments-en.js +31 -26
- package/backend/dist/config/comments-zh.js +29 -24
- package/backend/dist/config/defaults.d.ts +194 -33
- package/backend/dist/config/defaults.js +193 -32
- package/backend/dist/config/env.d.ts +10 -0
- package/backend/dist/config/env.js +3 -2
- package/backend/dist/config/index.d.ts +7 -0
- package/backend/dist/config/index.js +184 -43
- package/backend/dist/config/migrations/v0-to-v1.d.ts +2 -2
- package/backend/dist/config/migrations/v10-to-v11.d.ts +38 -0
- package/backend/dist/config/migrations/v10-to-v11.js +43 -0
- package/backend/dist/config/migrations/v6-to-v7.d.ts +45 -0
- package/backend/dist/config/migrations/v6-to-v7.js +97 -0
- package/backend/dist/config/migrations/v7-to-v8.d.ts +36 -0
- package/backend/dist/config/migrations/v7-to-v8.js +43 -0
- package/backend/dist/config/migrations/v8-to-v9.d.ts +38 -0
- package/backend/dist/config/migrations/v8-to-v9.js +43 -0
- package/backend/dist/config/migrations/v9-to-v10.d.ts +51 -0
- package/backend/dist/config/migrations/v9-to-v10.js +71 -0
- package/backend/dist/config/runtime.js +1 -1
- package/backend/dist/config/schema.d.ts +3 -3
- package/backend/dist/config/schema.js +14 -4
- package/backend/dist/config/types.d.ts +167 -38
- package/backend/dist/egress-proxy/asset-download.d.ts +54 -0
- package/backend/dist/egress-proxy/asset-download.js +420 -0
- package/backend/dist/egress-proxy/manual-node-spec.d.ts +92 -0
- package/backend/dist/egress-proxy/manual-node-spec.js +408 -0
- package/backend/dist/egress-proxy/mihomo-binary.d.ts +54 -0
- package/backend/dist/egress-proxy/mihomo-binary.js +278 -0
- package/backend/dist/egress-proxy/mihomo-client.d.ts +94 -0
- package/backend/dist/egress-proxy/mihomo-client.js +308 -0
- package/backend/dist/egress-proxy/mihomo-config.d.ts +40 -0
- package/backend/dist/egress-proxy/mihomo-config.js +161 -0
- package/backend/dist/egress-proxy/mihomo-geo.d.ts +87 -0
- package/backend/dist/egress-proxy/mihomo-geo.js +213 -0
- package/backend/dist/egress-proxy/mihomo-logs.d.ts +43 -0
- package/backend/dist/egress-proxy/mihomo-logs.js +84 -0
- package/backend/dist/egress-proxy/mihomo-pac.d.ts +37 -0
- package/backend/dist/egress-proxy/mihomo-pac.js +75 -0
- package/backend/dist/egress-proxy/mihomo-rules-import.d.ts +43 -0
- package/backend/dist/egress-proxy/mihomo-rules-import.js +193 -0
- package/backend/dist/egress-proxy/mihomo-sidecar.d.ts +81 -0
- package/backend/dist/egress-proxy/mihomo-sidecar.js +637 -0
- package/backend/dist/forward-proxy/egress.d.ts +50 -11
- package/backend/dist/forward-proxy/egress.js +50 -17
- package/backend/dist/forward-proxy/h2-forward.js +36 -10
- package/backend/dist/forward-proxy/index.d.ts +11 -8
- package/backend/dist/forward-proxy/index.js +22 -60
- package/backend/dist/forward-proxy/interceptor.d.ts +3 -2
- package/backend/dist/forward-proxy/interceptor.js +4 -4
- package/backend/dist/forward-proxy/relay.js +3 -3
- package/backend/dist/forward-proxy/rules.d.ts +4 -4
- package/backend/dist/forward-proxy/rules.js +25 -4
- package/backend/dist/forward-proxy/server.d.ts +0 -16
- package/backend/dist/forward-proxy/server.js +124 -156
- package/backend/dist/harness/host/hosts.js +3 -2
- package/backend/dist/index.js +53 -18
- package/backend/dist/ingress-proxy/access-log.d.ts +176 -0
- package/backend/dist/ingress-proxy/access-log.js +774 -0
- package/backend/dist/ingress-proxy/ca-inventory.d.ts +106 -0
- package/backend/dist/ingress-proxy/ca-inventory.js +525 -0
- package/backend/dist/ingress-proxy/ca-trust.d.ts +96 -0
- package/backend/dist/ingress-proxy/ca-trust.js +315 -0
- package/backend/dist/ingress-proxy/ca.d.ts +104 -0
- package/backend/dist/ingress-proxy/ca.js +273 -0
- package/backend/dist/ingress-proxy/data-dir.d.ts +28 -0
- package/backend/dist/ingress-proxy/data-dir.js +45 -0
- package/backend/dist/ingress-proxy/egress.d.ts +151 -0
- package/backend/dist/ingress-proxy/egress.js +364 -0
- package/backend/dist/ingress-proxy/h2-forward.d.ts +66 -0
- package/backend/dist/ingress-proxy/h2-forward.js +561 -0
- package/backend/dist/ingress-proxy/index.d.ts +24 -0
- package/backend/dist/ingress-proxy/index.js +144 -0
- package/backend/dist/ingress-proxy/interceptor.d.ts +25 -0
- package/backend/dist/ingress-proxy/interceptor.js +52 -0
- package/backend/dist/ingress-proxy/ordered-relay.d.ts +29 -0
- package/backend/dist/ingress-proxy/ordered-relay.js +46 -0
- package/backend/dist/ingress-proxy/relay.d.ts +54 -0
- package/backend/dist/ingress-proxy/relay.js +188 -0
- package/backend/dist/ingress-proxy/rules.d.ts +195 -0
- package/backend/dist/ingress-proxy/rules.js +348 -0
- package/backend/dist/ingress-proxy/server.d.ts +153 -0
- package/backend/dist/ingress-proxy/server.js +2065 -0
- package/backend/dist/ingress-proxy/sni.d.ts +35 -0
- package/backend/dist/ingress-proxy/sni.js +124 -0
- package/backend/dist/ingress-proxy/status.d.ts +32 -0
- package/backend/dist/ingress-proxy/status.js +15 -0
- package/backend/dist/ingress-proxy/system-proxy.d.ts +112 -0
- package/backend/dist/ingress-proxy/system-proxy.js +481 -0
- package/backend/dist/ingress-proxy/traffic-delete.d.ts +21 -0
- package/backend/dist/ingress-proxy/traffic-delete.js +64 -0
- package/backend/dist/ingress-proxy/traffic-delete.worker.d.ts +44 -0
- package/backend/dist/ingress-proxy/traffic-delete.worker.js +228 -0
- package/backend/dist/ingress-proxy/traffic-files.d.ts +10 -0
- package/backend/dist/ingress-proxy/traffic-files.js +10 -0
- package/backend/dist/ingress-proxy/upstream-tls.d.ts +46 -0
- package/backend/dist/ingress-proxy/upstream-tls.js +105 -0
- package/backend/dist/ingress-proxy/ws-frames.d.ts +45 -0
- package/backend/dist/ingress-proxy/ws-frames.js +153 -0
- package/backend/dist/ir/adapters/anthropic-messages-stream.js +6 -1
- package/backend/dist/ir/adapters/anthropic-messages.js +12 -5
- package/backend/dist/ir/adapters/google-gemini-stream.js +7 -2
- package/backend/dist/ir/adapters/google-gemini.js +5 -2
- package/backend/dist/ir/adapters/openai-chat-stream.js +5 -1
- package/backend/dist/ir/adapters/openai-chat.d.ts +25 -0
- package/backend/dist/ir/adapters/openai-chat.js +45 -3
- package/backend/dist/ir/adapters/openai-responses-output.d.ts +1 -0
- package/backend/dist/ir/adapters/openai-responses-output.js +67 -21
- package/backend/dist/ir/adapters/openai-responses-stream.d.ts +13 -0
- package/backend/dist/ir/adapters/openai-responses-stream.js +34 -1
- package/backend/dist/ir/adapters/openai-responses.d.ts +82 -24
- package/backend/dist/ir/adapters/openai-responses.js +146 -37
- package/backend/dist/ir/media.d.ts +20 -0
- package/backend/dist/ir/media.js +41 -0
- package/backend/dist/ir/tool-identity.d.ts +35 -0
- package/backend/dist/ir/tool-identity.js +40 -0
- package/backend/dist/ir/types.d.ts +9 -1
- package/backend/dist/local/build-jobs.d.ts +66 -0
- package/backend/dist/local/build-jobs.js +243 -0
- package/backend/dist/local/detect.d.ts +32 -0
- package/backend/dist/local/detect.js +145 -0
- package/backend/dist/local/draft-match.d.ts +58 -0
- package/backend/dist/local/draft-match.js +124 -0
- package/backend/dist/local/engine-runtime.d.ts +522 -0
- package/backend/dist/local/engine-runtime.js +1 -0
- package/backend/dist/local/engines.d.ts +241 -0
- package/backend/dist/local/engines.js +651 -0
- package/backend/dist/local/gguf.d.ts +35 -0
- package/backend/dist/local/gguf.js +314 -0
- package/backend/dist/local/hf.d.ts +120 -0
- package/backend/dist/local/hf.js +304 -0
- package/backend/dist/local/install.d.ts +90 -0
- package/backend/dist/local/install.js +421 -0
- package/backend/dist/local/llamacpp.d.ts +55 -0
- package/backend/dist/local/llamacpp.js +177 -0
- package/backend/dist/local/local-provider.d.ts +81 -0
- package/backend/dist/local/local-provider.js +301 -0
- package/backend/dist/local/machine-stats.d.ts +87 -0
- package/backend/dist/local/machine-stats.js +332 -0
- package/backend/dist/local/model-store.d.ts +347 -0
- package/backend/dist/local/model-store.js +1215 -0
- package/backend/dist/local/part-sweep.d.ts +32 -0
- package/backend/dist/local/part-sweep.js +156 -0
- package/backend/dist/local/plan.d.ts +65 -0
- package/backend/dist/local/plan.js +146 -0
- package/backend/dist/local/resources.d.ts +49 -0
- package/backend/dist/local/resources.js +64 -0
- package/backend/dist/local/run-stats.d.ts +95 -0
- package/backend/dist/local/run-stats.js +195 -0
- package/backend/dist/local/runner.d.ts +235 -0
- package/backend/dist/local/runner.js +1392 -0
- package/backend/dist/local/settings.d.ts +79 -0
- package/backend/dist/local/settings.js +180 -0
- package/backend/dist/local/strata-catalog.d.ts +30 -0
- package/backend/dist/local/strata-catalog.js +511 -0
- package/backend/dist/local/strata-drafting.d.ts +46 -0
- package/backend/dist/local/strata-drafting.js +265 -0
- package/backend/dist/local/strata.d.ts +278 -0
- package/backend/dist/local/strata.js +1392 -0
- package/backend/dist/local/tar.d.ts +20 -0
- package/backend/dist/local/tar.js +367 -0
- package/backend/dist/local/transport.d.ts +35 -0
- package/backend/dist/local/transport.js +89 -0
- package/backend/dist/local/tune.d.ts +58 -0
- package/backend/dist/local/tune.js +324 -0
- package/backend/dist/observability/http-exchange.d.ts +2 -2
- package/backend/dist/opencode/catalog/auto-pull.d.ts +14 -3
- package/backend/dist/opencode/catalog/auto-pull.js +276 -70
- package/backend/dist/opencode/catalog/ocr-store.js +3 -1
- package/backend/dist/opencode/catalog/overrides-store.d.ts +10 -1
- package/backend/dist/opencode/catalog/overrides-store.js +6 -0
- package/backend/dist/opencode/catalog/reasoning-declaration.d.ts +35 -0
- package/backend/dist/opencode/catalog/reasoning-declaration.js +66 -0
- package/backend/dist/opencode/catalog/repository.js +25 -2
- package/backend/dist/opencode/catalog/sources/models-dev.js +13 -3
- package/backend/dist/opencode/catalog/types.d.ts +35 -3
- package/backend/dist/opencode/catalog/types.js +38 -1
- package/backend/dist/opencode/credentials/ocr-store.js +11 -2
- package/backend/dist/opencode/credentials/sync.js +12 -3
- package/backend/dist/opencode/credentials/types.d.ts +31 -4
- package/backend/dist/opencode/credentials/types.js +25 -0
- package/backend/dist/opencode/probe.d.ts +21 -4
- package/backend/dist/opencode/probe.js +34 -10
- package/backend/dist/pipeline/directives.d.ts +9 -4
- package/backend/dist/pipeline/directives.js +14 -10
- package/backend/dist/pipeline/orchestrator.d.ts +42 -13
- package/backend/dist/pipeline/orchestrator.js +497 -165
- package/backend/dist/plugins/environment-ack.d.ts +51 -0
- package/backend/dist/plugins/environment-ack.js +81 -0
- package/backend/dist/plugins/gateways.d.ts +6 -6
- package/backend/dist/plugins/gateways.js +2 -2
- package/backend/dist/plugins/host.d.ts +98 -14
- package/backend/dist/plugins/host.js +622 -87
- package/backend/dist/plugins/install-run.d.ts +27 -0
- package/backend/dist/plugins/install-run.js +99 -0
- package/backend/dist/plugins/manifest.d.ts +84 -32
- package/backend/dist/plugins/manifest.js +149 -45
- package/backend/dist/plugins/market-install.d.ts +18 -0
- package/backend/dist/plugins/market-install.js +111 -0
- package/backend/dist/plugins/market-source.d.ts +100 -0
- package/backend/dist/plugins/market-source.js +449 -0
- package/backend/dist/plugins/market-updates.d.ts +70 -0
- package/backend/dist/plugins/market-updates.js +97 -0
- package/backend/dist/plugins/market.d.ts +677 -0
- package/backend/dist/plugins/market.js +2113 -0
- package/backend/dist/plugins/source-index.d.ts +155 -0
- package/backend/dist/plugins/source-index.js +217 -0
- package/backend/dist/plugins/types.d.ts +402 -37
- package/backend/dist/projects/worktrees.d.ts +88 -0
- package/backend/dist/projects/worktrees.js +220 -0
- package/backend/dist/providers/boot-direct.d.ts +41 -7
- package/backend/dist/providers/boot-direct.js +252 -36
- package/backend/dist/providers/compat/tool-markup-recovery.js +31 -6
- package/backend/dist/providers/executors/dispatch.d.ts +17 -7
- package/backend/dist/providers/executors/dispatch.js +28 -9
- package/backend/dist/providers/executors/openai-chat.js +14 -2
- package/backend/dist/providers/executors/plugin-adapter.d.ts +23 -1
- package/backend/dist/providers/executors/plugin-adapter.js +59 -3
- package/backend/dist/providers/member-match.d.ts +32 -9
- package/backend/dist/providers/member-match.js +65 -21
- package/backend/dist/providers/model-resolution.d.ts +62 -0
- package/backend/dist/providers/model-resolution.js +62 -0
- package/backend/dist/providers/price-order.d.ts +51 -0
- package/backend/dist/providers/price-order.js +54 -0
- package/backend/dist/providers/provider-takedown.d.ts +5 -2
- package/backend/dist/providers/registry.d.ts +84 -25
- package/backend/dist/providers/registry.js +209 -114
- package/backend/dist/providers/selection.d.ts +91 -0
- package/backend/dist/providers/selection.js +158 -0
- package/backend/dist/providers/virtual-meta.d.ts +33 -2
- package/backend/dist/providers/virtual-meta.js +74 -18
- package/backend/dist/quota/cli-login.d.ts +25 -4
- package/backend/dist/quota/cli-login.js +35 -5
- package/backend/dist/quota/coverage-generation.d.ts +24 -0
- package/backend/dist/quota/coverage-generation.js +29 -0
- package/backend/dist/quota/declarations.js +8 -4
- package/backend/dist/quota/engine.js +2 -2
- package/backend/dist/quota/prober.d.ts +43 -2
- package/backend/dist/quota/prober.js +97 -22
- package/backend/dist/ratelimit/rate-limiter.d.ts +1 -1
- package/backend/dist/resilience/error-classifier.js +29 -0
- package/backend/dist/router/index.d.ts +1 -1
- package/backend/dist/router/index.js +17 -1
- package/backend/dist/router/layer2-decision.d.ts +1 -1
- package/backend/dist/router/layer2-decision.js +2 -2
- package/backend/dist/routes/console.js +928 -310
- package/backend/dist/routes/environments.js +1 -1
- package/backend/dist/routes/local-models.d.ts +2 -0
- package/backend/dist/routes/local-models.js +1414 -0
- package/backend/dist/routes/mihomo.d.ts +2 -2
- package/backend/dist/routes/mihomo.js +20 -11
- package/backend/dist/routes/projects.js +121 -0
- package/backend/dist/server.js +318 -13
- package/backend/dist/session/session-manager.d.ts +42 -5
- package/backend/dist/session/session-manager.js +64 -11
- package/backend/dist/session/session-row.d.ts +29 -8
- package/backend/dist/session/session-row.js +18 -13
- package/backend/dist/snapshot/bundle.d.ts +40 -0
- package/backend/dist/snapshot/bundle.js +177 -0
- package/backend/dist/snapshot/handoff/compress.d.ts +46 -0
- package/backend/dist/snapshot/handoff/compress.js +77 -0
- package/backend/dist/snapshot/handoff/index.d.ts +119 -0
- package/backend/dist/snapshot/handoff/index.js +160 -0
- package/backend/dist/snapshot/handoff/jsonl-writer.d.ts +78 -0
- package/backend/dist/snapshot/handoff/jsonl-writer.js +175 -0
- package/backend/dist/snapshot/handoff/opencode-writer.d.ts +51 -0
- package/backend/dist/snapshot/handoff/opencode-writer.js +214 -0
- package/backend/dist/snapshot/handoff/summarize.d.ts +39 -0
- package/backend/dist/snapshot/handoff/summarize.js +118 -0
- package/backend/dist/snapshot/handoff/transcript.d.ts +71 -0
- package/backend/dist/snapshot/handoff/transcript.js +167 -0
- package/backend/dist/snapshot/media-fs.d.ts +10 -0
- package/backend/dist/snapshot/media-fs.js +50 -0
- package/backend/dist/snapshot/media.d.ts +32 -0
- package/backend/dist/snapshot/media.js +87 -0
- package/backend/dist/snapshot/store.d.ts +226 -0
- package/backend/dist/snapshot/store.js +887 -0
- package/backend/dist/snapshot/tree.d.ts +112 -0
- package/backend/dist/snapshot/tree.js +207 -0
- package/backend/dist/snapshot/types.d.ts +212 -0
- package/backend/dist/snapshot/types.js +14 -0
- package/backend/dist/snapshot/view.d.ts +19 -0
- package/backend/dist/snapshot/view.js +57 -0
- package/backend/dist/snapshot/write-worker.d.ts +67 -0
- package/backend/dist/snapshot/write-worker.js +129 -0
- package/backend/dist/surfaces/body-admission.d.ts +67 -2
- package/backend/dist/surfaces/body-admission.js +218 -13
- package/backend/dist/surfaces/chat-pipeline.js +8 -0
- package/backend/dist/surfaces/decision-pipeline.js +10 -7
- package/backend/dist/surfaces/gateway-catalog.d.ts +26 -0
- package/backend/dist/surfaces/gateway-catalog.js +202 -0
- package/backend/dist/surfaces/gateway-chat.d.ts +7 -11
- package/backend/dist/surfaces/gateway-chat.js +50 -12
- package/backend/dist/surfaces/ocr-headers.d.ts +6 -4
- package/backend/dist/surfaces/ocr-headers.js +11 -7
- package/backend/dist/surfaces/systemone.js +1 -1
- package/backend/dist/surfaces/transport-fastify.js +32 -5
- package/backend/dist/surfaces/transport-node-http.d.ts +9 -3
- package/backend/dist/surfaces/transport-node-http.js +6 -19
- package/backend/dist/surfaces/types.d.ts +11 -3
- package/backend/dist/trace/persist.js +21 -1
- package/backend/dist/trace/tracker.d.ts +35 -3
- package/backend/dist/trace/tracker.js +23 -0
- package/backend/dist/types/openai.d.ts +8 -0
- package/backend/dist/types/router.d.ts +17 -6
- package/backend/dist/types/router.js +14 -2
- package/backend/dist/utils/client-families.d.ts +66 -0
- package/backend/dist/utils/client-families.js +127 -0
- package/backend/dist/utils/event-ring.d.ts +1 -1
- package/backend/dist/utils/event-ring.js +1 -1
- package/backend/dist/utils/proxy-node.js +1 -1
- package/backend/dist/utils/proxy.d.ts +135 -11
- package/backend/dist/utils/proxy.js +144 -29
- package/backend/dist/utils/run-command.d.ts +21 -1
- package/backend/dist/utils/run-command.js +64 -4
- package/backend/dist/utils/server-liveness.d.ts +3 -2
- package/backend/dist/utils/server-liveness.js +3 -2
- package/backend/dist/utils/session-file.d.ts +28 -0
- package/backend/dist/utils/session-file.js +34 -0
- package/frontend/dist/assets/antigravity.color-DXFfVr6X.svg +39 -0
- package/frontend/dist/assets/gemini-cli.color-BfquLd1p.svg +1 -0
- package/frontend/dist/assets/index-CTZNvn1d.js +1707 -0
- package/frontend/dist/assets/{index-KI1OW5x6.css → index-CqDSOPQ0.css} +1 -1
- package/frontend/dist/index.html +2 -2
- package/package.json +3 -1
- package/frontend/dist/assets/index-Dk76uc7e.js +0 -1522
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { findMarketRow, prepareMarketPackage, readPluginSources, recordPluginSource } from './market.js';
|
|
2
|
+
import { packageIdOf } from './host.js';
|
|
3
|
+
import { installPluginBytes } from './install-run.js';
|
|
4
|
+
/**
|
|
5
|
+
* ONE market install, reached from three verbs (ADR-0037 §5/§7): the market
|
|
6
|
+
* card's Install, one plugin's Upgrade, and the bulk upgrade run. All three do
|
|
7
|
+
* exactly this — resolve the registry row, obtain the bytes by the row's
|
|
8
|
+
* method, verify the zip declares the row's id, land it through the shared
|
|
9
|
+
* install pipeline, and record where it came from.
|
|
10
|
+
*
|
|
11
|
+
* Keeping it in one function is the same rule the upload path follows: two
|
|
12
|
+
* copies of "download, verify, install, remember" would agree today and drift
|
|
13
|
+
* the day one of them learns a new gate.
|
|
14
|
+
*/
|
|
15
|
+
export async function installFromMarket(repo, opts = {}, registry) {
|
|
16
|
+
const row = await findMarketRow(repo, { refresh: true });
|
|
17
|
+
if (!row)
|
|
18
|
+
return { statusCode: 404, body: { status: 'error', error: `'${repo}' is not in the plugin registry` } };
|
|
19
|
+
if (row.error || !row.id) {
|
|
20
|
+
return {
|
|
21
|
+
statusCode: 422,
|
|
22
|
+
body: { status: 'error', error: row.error ?? 'the repository publishes no readable plugin.json' },
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
// A registry has no ProviderRegistry to refresh (only a test would omit it);
|
|
26
|
+
// `installPluginBytes` needs one, so a missing caller is a programming error.
|
|
27
|
+
if (!registry) {
|
|
28
|
+
return { statusCode: 500, body: { status: 'error', error: 'install requires the provider registry' } };
|
|
29
|
+
}
|
|
30
|
+
// `code` refuses here, before a clone, when the build toolchain is absent.
|
|
31
|
+
const prepared = await prepareMarketPackage(row, {
|
|
32
|
+
...(opts.ref ? { ref: opts.ref } : {}),
|
|
33
|
+
...(opts.upgrade ? { upgrade: true } : {}),
|
|
34
|
+
});
|
|
35
|
+
if ('error' in prepared)
|
|
36
|
+
return { statusCode: 502, body: { status: 'error', error: prepared.error } };
|
|
37
|
+
let actualId;
|
|
38
|
+
try {
|
|
39
|
+
actualId = packageIdOf(new Uint8Array(prepared.bytes));
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
return {
|
|
43
|
+
statusCode: 422,
|
|
44
|
+
body: {
|
|
45
|
+
status: 'error',
|
|
46
|
+
error: `the package obtained for ${row.repo} is not a plugin zip: ${err instanceof Error ? err.message : String(err)}`,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (actualId !== row.id) {
|
|
51
|
+
return {
|
|
52
|
+
statusCode: 422,
|
|
53
|
+
body: {
|
|
54
|
+
status: 'error',
|
|
55
|
+
error: `the package built/downloaded for ${row.repo} declares '${actualId}' but the registry advertises '${row.id}' — refusing to install a different plugin`,
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
// A row that shares its id with another repository is never installable: the
|
|
60
|
+
// id is the install identity, so landing it would SILENTLY replace the other
|
|
61
|
+
// repository's plugin and rewrite its provenance. The market already marks
|
|
62
|
+
// such rows (`row.conflict`) and the console disables the button — this is the
|
|
63
|
+
// enforcing half, for a caller that gets here anyway (a stale page, a script).
|
|
64
|
+
if (row.conflict) {
|
|
65
|
+
const peers = row.conflict.repos.filter((repo) => repo !== row.repo);
|
|
66
|
+
return {
|
|
67
|
+
statusCode: 409,
|
|
68
|
+
body: {
|
|
69
|
+
status: 'error',
|
|
70
|
+
error: `'${row.conflict.id}' is declared by more than one repository (${row.conflict.repos.join(', ')}) — one id must come from one repository. Remove one of them from the registry or the sources, then install.`,
|
|
71
|
+
conflict: { id: row.conflict.id, repos: row.conflict.repos, peers },
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
// Provenance is the OTHER half of "one id, one repository": a plugin installed
|
|
76
|
+
// from repository A must not be replaced by repository B's package, even when
|
|
77
|
+
// B is the only card in the CURRENT market (A may have been removed from the
|
|
78
|
+
// sources while its plugin is still installed).
|
|
79
|
+
const provenance = readPluginSources()[actualId];
|
|
80
|
+
if (provenance && provenance.repo !== row.repo) {
|
|
81
|
+
return {
|
|
82
|
+
statusCode: 409,
|
|
83
|
+
body: {
|
|
84
|
+
status: 'error',
|
|
85
|
+
error: `'${actualId}' is currently installed from ${provenance.repo} — installing ${row.repo}'s package would replace it. Uninstall the installed copy first, or keep using its repository.`,
|
|
86
|
+
conflict: { id: actualId, repos: [provenance.repo, row.repo], peers: [provenance.repo] },
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
const outcome = await installPluginBytes(new Uint8Array(prepared.bytes), registry, opts.allowDowngrade ? { allowDowngrade: true } : {});
|
|
92
|
+
// Provenance is written for a row that LANDED, including a parked
|
|
93
|
+
// (engine-incompatible) one: the bytes are on disk, and the updates panel
|
|
94
|
+
// must be able to say where they came from so a later upgrade can fix it.
|
|
95
|
+
if (outcome.statusCode === 200) {
|
|
96
|
+
recordPluginSource(row.id, {
|
|
97
|
+
repo: row.repo,
|
|
98
|
+
...(row.subdir ? { subdir: row.subdir } : {}),
|
|
99
|
+
method: row.method,
|
|
100
|
+
...(row.ref ? { ref: row.ref } : {}),
|
|
101
|
+
...(opts.ref ? { ref: opts.ref } : {}),
|
|
102
|
+
version: prepared.version ?? row.version ?? '',
|
|
103
|
+
installedAt: new Date().toISOString(),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return outcome;
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
return { statusCode: 400, body: { status: 'error', error: err instanceof Error ? err.message : String(err) } };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
interface CommandResult {
|
|
2
|
+
ok: boolean;
|
|
3
|
+
stdout: string;
|
|
4
|
+
stderr: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Run one command under a deadline. `spawnSync` is used on purpose: a build is
|
|
8
|
+
* a bounded, sequential affair on a request nobody is streaming, and a
|
|
9
|
+
* synchronous child keeps the "one build at a time per call" story simple (no
|
|
10
|
+
* orphaned pipes, no interleaved output).
|
|
11
|
+
*/
|
|
12
|
+
declare function run(command: string, args: string[], cwd: string, timeoutMs: number, env?: NodeJS.ProcessEnv): CommandResult;
|
|
13
|
+
export declare function sourceBuildReady(): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Build one plugin from a GitHub repository's source and return an installable
|
|
16
|
+
* zip. Never throws on a build/tool failure — it answers a reason the console
|
|
17
|
+
* shows on the card.
|
|
18
|
+
*
|
|
19
|
+
* `ref` selection, per ADR-0037 §4a:
|
|
20
|
+
* - a caller-supplied ref (the console's version picker) is used verbatim;
|
|
21
|
+
* - otherwise the repository's DEFAULT BRANCH is the latest version — the
|
|
22
|
+
* source tree is the product, and a repository that ships no release has no
|
|
23
|
+
* "latest release" to compare against;
|
|
24
|
+
* - an OLDER version can only be reached by a TAG (`v0.8.0`), which the card
|
|
25
|
+
* offers from the repository's own tag list.
|
|
26
|
+
*
|
|
27
|
+
* WORKSPACE LAYOUT. A plugin source tree is built as if it sat in a checkout's
|
|
28
|
+
* `plugins/<id>/`, because that is the layout every published plugin is written
|
|
29
|
+
* for: the reference packages import shared core helpers as
|
|
30
|
+
* `../../backend/src/…` (`qoder-models` pulls `plugins/catalog-def.js`, the
|
|
31
|
+
* ADR-0035 mapper, at RUNTIME), and they import the gateway's OWN dependencies
|
|
32
|
+
* (`protobufjs` in `cursor-gateway`) by bare specifier. Bundling such a tree in
|
|
33
|
+
* a flat temp dir fails with `Could not resolve: …`, which is not a repository
|
|
34
|
+
* error but a LAYOUT one. So the workspace root is linked the way a checkout
|
|
35
|
+
* root is: `<parent>/plugins/<id>/` beside `<parent>/backend` (THIS gateway's
|
|
36
|
+
* backend) and `<parent>/node_modules` (THIS gateway's dependency tree).
|
|
37
|
+
*
|
|
38
|
+
* The host may carry no TypeScript: a prebuilt distribution and the desktop
|
|
39
|
+
* installer both ship `backend/dist` with no `src` (the sidecar is a compiled
|
|
40
|
+
* binary). There `gatewayBackendDir()` is named by `OCR_BACKEND_DIR` and the
|
|
41
|
+
* workspace's `backend/src` links to the COMPILED tree, so the plugin's
|
|
42
|
+
* `../../backend/src/…` specifier still resolves.
|
|
43
|
+
*
|
|
44
|
+
* PRIVATE REPOSITORIES. Everything the card read with rides the build too: the
|
|
45
|
+
* source's token authenticates the clone (`x-access-token`, delivered through
|
|
46
|
+
* the child's environment, never argv), and `egress: 'proxy'` sends the clone
|
|
47
|
+
* and the dependency install down the same outbound leg the card was read on.
|
|
48
|
+
*/
|
|
49
|
+
export declare function buildPackageFromSource(repo: string, opts: {
|
|
50
|
+
ref?: string;
|
|
51
|
+
subdir?: string;
|
|
52
|
+
/** The default branch, resolved by the caller from the repository metadata. */
|
|
53
|
+
defaultBranch: string;
|
|
54
|
+
/** This gateway's backend directory. The plugin's `../../backend/src/…`
|
|
55
|
+
* imports are resolved against it. */
|
|
56
|
+
backendDir: string;
|
|
57
|
+
/** The credential that read this row's card (ADR-0037 §8). Omitted or empty
|
|
58
|
+
* = anonymous, which is what a public source is. A private source's token
|
|
59
|
+
* must ride the clone too: the card's reads succeeding and the clone then
|
|
60
|
+
* failing with `Invalid username or token` is a half-working install. */
|
|
61
|
+
token?: string;
|
|
62
|
+
/**
|
|
63
|
+
* The outbound leg the market is set to, resolved by the caller from
|
|
64
|
+
* `utils/proxy.ts` (`proxy.url` in manual mode, the Clash mixed port in
|
|
65
|
+
* mihomo mode). Omitted = direct: a market read and the build it starts
|
|
66
|
+
* must not leave the machine on two different routes.
|
|
67
|
+
*
|
|
68
|
+
* Set through `git`'s OWN `http.proxy` rather than the ambient `https_proxy`
|
|
69
|
+
* variable: git honours BOTH, so an inherited `https_proxy` pointing at THIS
|
|
70
|
+
* gateway's ingress proxy would send the gateway through itself, and the
|
|
71
|
+
* child must not inherit a route the operator did not choose for it.
|
|
72
|
+
*/
|
|
73
|
+
egressProxy?: string;
|
|
74
|
+
/** Test seam: the real `bun install` on a third-party tree is the one step a
|
|
75
|
+
* unit test must not run. */
|
|
76
|
+
runCommand?: typeof run;
|
|
77
|
+
onLog?: (line: string) => void;
|
|
78
|
+
}): Promise<{
|
|
79
|
+
zip: Uint8Array;
|
|
80
|
+
version: string;
|
|
81
|
+
} | {
|
|
82
|
+
error: string;
|
|
83
|
+
}>;
|
|
84
|
+
/**
|
|
85
|
+
* This gateway's `backend/` directory, as the source build must expose it at
|
|
86
|
+
* the workspace root (module location is `<root>/backend/{src|dist}/plugins/`).
|
|
87
|
+
*
|
|
88
|
+
* `import.meta.url` is only meaningful in a source-launched host. A compiled
|
|
89
|
+
* Bun binary reports `file:///…/~BUN/root/…`, which exists nowhere on disk, and
|
|
90
|
+
* the desktop sidecar additionally has no checkout beside it — so the shells
|
|
91
|
+
* that carry their backend name it as `OCR_BACKEND_DIR`, and the executable /
|
|
92
|
+
* cwd fallbacks cover a portable unpacks-next-to-the-binary layout. A
|
|
93
|
+
* candidate wins only when it actually carries a backend tree, so a moved or
|
|
94
|
+
* half-installed override is skipped instead of trusted.
|
|
95
|
+
*/
|
|
96
|
+
export declare function gatewayBackendDir(): string;
|
|
97
|
+
/** Whether a ref looks like a version tag (so the console can distinguish "the
|
|
98
|
+
* latest source" from "an older published version"). */
|
|
99
|
+
export declare function isVersionRef(ref: string | undefined): boolean;
|
|
100
|
+
export {};
|
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { PLUGIN_PACKAGE_MAX_BYTES } from '../config/defaults.js';
|
|
6
|
+
import { listInstalledPlugins } from './host.js';
|
|
7
|
+
import { validatePluginManifest } from './manifest.js';
|
|
8
|
+
import { bundlePluginDir } from './pack.js';
|
|
9
|
+
/**
|
|
10
|
+
* The `method: 'code'` half of the plugin market (ADR-0037 §4a).
|
|
11
|
+
*
|
|
12
|
+
* A repository that publishes no release zip can still be installed from its
|
|
13
|
+
* SOURCE, the way `bun run plugins:build` builds a checkout: clone at a ref,
|
|
14
|
+
* install the plugin's own dependencies, run the SAME packager
|
|
15
|
+
* (`bundlePluginDir` — one bundler, so a market-built package is byte-for-byte
|
|
16
|
+
* the artifact `plugins:build` would produce), then hand the zip to the SAME
|
|
17
|
+
* install pipeline an upload takes.
|
|
18
|
+
*
|
|
19
|
+
* Two consequences are deliberate and stated to the operator, never hidden:
|
|
20
|
+
*
|
|
21
|
+
* - it needs `git` and `bun` on THIS machine (a packaged gateway is a compiled
|
|
22
|
+
* Bun binary, but its plugin builds still shell out to the real toolchain;
|
|
23
|
+
* a missing tool is a refusal naming which one);
|
|
24
|
+
* - it RUNS the dependency install of a third-party repository. That is the
|
|
25
|
+
* same trust the operator extends by installing the package at all, but it
|
|
26
|
+
* is why `code` is opt-in PER ENTRY and never the default.
|
|
27
|
+
*/
|
|
28
|
+
/** How long one source build may take, wall clock. A dependency install over a
|
|
29
|
+
* slow link is the long pole; the packager itself is seconds. */
|
|
30
|
+
const BUILD_TOTAL_TIMEOUT_MS = 8 * 60_000;
|
|
31
|
+
/** `bun install` alone gets the biggest slice. */
|
|
32
|
+
const INSTALL_TIMEOUT_MS = 5 * 60_000;
|
|
33
|
+
/** A tag an operator would paste for an OLDER version: `0.8.0` or `v0.8.0`. */
|
|
34
|
+
const VERSION_TAG_RE = /^v?\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/;
|
|
35
|
+
/**
|
|
36
|
+
* Run one command under a deadline. `spawnSync` is used on purpose: a build is
|
|
37
|
+
* a bounded, sequential affair on a request nobody is streaming, and a
|
|
38
|
+
* synchronous child keeps the "one build at a time per call" story simple (no
|
|
39
|
+
* orphaned pipes, no interleaved output).
|
|
40
|
+
*/
|
|
41
|
+
function run(command, args, cwd, timeoutMs, env) {
|
|
42
|
+
const result = spawnSync(command, args, {
|
|
43
|
+
cwd,
|
|
44
|
+
encoding: 'utf8',
|
|
45
|
+
timeout: timeoutMs,
|
|
46
|
+
windowsHide: true,
|
|
47
|
+
env: env ?? process.env,
|
|
48
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
ok: result.status === 0 && !result.error,
|
|
52
|
+
stdout: result.stdout ?? '',
|
|
53
|
+
stderr: `${result.stderr ?? ''}${result.error ? String(result.error.message) : ''}`,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** A one-line, operator-legible reason from a failed child. Child output is
|
|
57
|
+
* verbose and mostly noise; the LAST line usually names the real cause. */
|
|
58
|
+
function failureLine(command, result) {
|
|
59
|
+
const text = `${result.stderr}\n${result.stdout}`
|
|
60
|
+
.split(/\r?\n/)
|
|
61
|
+
.map((line) => line.trim())
|
|
62
|
+
.filter(Boolean);
|
|
63
|
+
const tail = text.slice(-3).join(' | ');
|
|
64
|
+
return tail ? `${command} failed: ${tail}` : `${command} failed`;
|
|
65
|
+
}
|
|
66
|
+
function toolMissing(command) {
|
|
67
|
+
const probe = run(command, ['--version'], process.cwd(), 15_000);
|
|
68
|
+
if (probe.ok)
|
|
69
|
+
return undefined;
|
|
70
|
+
return `${command} is required to build a plugin from source but is not available on this machine`;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Git configuration for ONE child, delivered through the ENVIRONMENT
|
|
74
|
+
* (`GIT_CONFIG_COUNT` / `GIT_CONFIG_KEY_n` / `GIT_CONFIG_VALUE_n`) instead of the
|
|
75
|
+
* command line.
|
|
76
|
+
*
|
|
77
|
+
* A private plugin repository's card reads fine — every one of those reads
|
|
78
|
+
* carries its source's token — but `git clone` is a SEPARATE process that knows
|
|
79
|
+
* nothing about the market's credential model, so an anonymous clone of a
|
|
80
|
+
* private repository answers `Invalid username or token` on a machine where the
|
|
81
|
+
* card looked perfectly healthy (ADR-0037 §8). That is the half that used to be
|
|
82
|
+
* missing.
|
|
83
|
+
*
|
|
84
|
+
* `-c http.<url>.extraheader=…` would work too, and it is deliberately NOT used:
|
|
85
|
+
* argv is readable by any process on the machine and lands in crash reports and
|
|
86
|
+
* shell history. An env var is inherited by the single child and printed by
|
|
87
|
+
* nothing.
|
|
88
|
+
*
|
|
89
|
+
* The identity is `x-access-token`, GitHub's own spelling for "an OAuth/PAT used
|
|
90
|
+
* as a git password" — a PAT sent as a username half is rejected by some
|
|
91
|
+
* endpoints and confuses the ones that accept it.
|
|
92
|
+
*
|
|
93
|
+
* `http.proxy` rides the same channel so git has exactly ONE route: `git` honours
|
|
94
|
+
* both this and the ambient `https_proxy` (which the caller strips), so a
|
|
95
|
+
* gateway running with `HTTPS_PROXY` pointed at its own ingress proxy can no
|
|
96
|
+
* longer send a clone back through itself. `credential.helper` is emptied for
|
|
97
|
+
* the same reason a prompt is disabled — a stored credential or an interactive
|
|
98
|
+
* prompt would add a second, silent path to the same repository.
|
|
99
|
+
*/
|
|
100
|
+
function gitEnv(host, authorization, proxy) {
|
|
101
|
+
const config = [];
|
|
102
|
+
if (authorization)
|
|
103
|
+
config.push([`http.https://${host}/.extraheader`, authorization]);
|
|
104
|
+
if (proxy)
|
|
105
|
+
config.push(['http.proxy', proxy]);
|
|
106
|
+
// A gateway is behind a proxy more often than a laptop is, and flaky TLS
|
|
107
|
+
// through one reset git's HTTP/2 multiplexed upload mid-pack far more readily
|
|
108
|
+
// than a plain HTTP/1.1 body (`Recv failure: Connection was reset`,
|
|
109
|
+
// `expected flush after ref listing`). One connection per request is slower
|
|
110
|
+
// and vastly more reliable — this is a bounded build, not a hot path.
|
|
111
|
+
config.push(['http.version', 'HTTP/1.1']);
|
|
112
|
+
config.push(['credential.helper', '']);
|
|
113
|
+
const env = {
|
|
114
|
+
GIT_CONFIG_COUNT: String(config.length),
|
|
115
|
+
// A gateway has no terminal: a prompt would hang the build forever.
|
|
116
|
+
GIT_TERMINAL_PROMPT: '0',
|
|
117
|
+
};
|
|
118
|
+
config.forEach(([key, value], index) => {
|
|
119
|
+
env[`GIT_CONFIG_KEY_${index}`] = key;
|
|
120
|
+
env[`GIT_CONFIG_VALUE_${index}`] = value;
|
|
121
|
+
});
|
|
122
|
+
return env;
|
|
123
|
+
}
|
|
124
|
+
/** The `Authorization` header value git sends for one token (base64 of
|
|
125
|
+
* `x-access-token:<token>`). Built here so the token VALUE never has to travel
|
|
126
|
+
* as its own argument past this point. */
|
|
127
|
+
function gitAuthorization(token) {
|
|
128
|
+
return `Authorization: Basic ${Buffer.from(`x-access-token:${token}`, 'utf8').toString('base64')}`;
|
|
129
|
+
}
|
|
130
|
+
/** Whether a failed clone was refused by AUTHENTICATION rather than by a bad
|
|
131
|
+
* ref. The distinction is the whole operator-facing value here: the two
|
|
132
|
+
* answers ask for opposite fixes (issue/grant a token versus pick another
|
|
133
|
+
* branch), and git's own messages put them in different halves. */
|
|
134
|
+
function cloneRefusedAuth(result) {
|
|
135
|
+
return /authentication failed|could not read (username|password)|invalid username or (token|password)|terminal prompts disabled|support for password authentication|access denied|403/i.test(`${result.stderr}\n${result.stdout}`);
|
|
136
|
+
}
|
|
137
|
+
/** Whether git said the BRANCH/TAG itself does not exist. Only this answer earns
|
|
138
|
+
* the "ref is not a branch or tag" tail — a TLS or DNS failure appended that
|
|
139
|
+
* sentence sends the operator to rename a branch that was never the problem. */
|
|
140
|
+
function cloneRefMissingRef(result) {
|
|
141
|
+
return /remote branch .* not found|couldn't find remote ref|could not find remote branch|not a valid name|unknown revision/i.test(`${result.stderr}\n${result.stdout}`);
|
|
142
|
+
}
|
|
143
|
+
/** Whether the child never reached the server (TLS, DNS, proxy, packet loss).
|
|
144
|
+
* Reported as a transport failure, naming the leg so a proxy misconfiguration
|
|
145
|
+
* is visible instead of hiding behind a clone error. */
|
|
146
|
+
function cloneTransportFailure(result) {
|
|
147
|
+
return /ssl_error|openssl|curl \d+|could not resolve host|failed to connect|connection (refused|reset|timed out)|rpc failed|expected flush after ref listing|network is unreachable/i.test(`${result.stderr}\n${result.stdout}`);
|
|
148
|
+
}
|
|
149
|
+
/** Whether this machine can build from source at all (`git` + `bun` present).
|
|
150
|
+
* The card reads it so a build the gateway would refuse is stated BEFORE the
|
|
151
|
+
* operator clicks, instead of failing after a clone. Cached after the first
|
|
152
|
+
* probe: the answer cannot change under a running process in a way that
|
|
153
|
+
* matters, and the probe spawns two children. */
|
|
154
|
+
let buildReadyCache;
|
|
155
|
+
export function sourceBuildReady() {
|
|
156
|
+
if (buildReadyCache === undefined) {
|
|
157
|
+
buildReadyCache = toolMissing('git') === undefined && toolMissing('bun') === undefined;
|
|
158
|
+
}
|
|
159
|
+
return buildReadyCache;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Build one plugin from a GitHub repository's source and return an installable
|
|
163
|
+
* zip. Never throws on a build/tool failure — it answers a reason the console
|
|
164
|
+
* shows on the card.
|
|
165
|
+
*
|
|
166
|
+
* `ref` selection, per ADR-0037 §4a:
|
|
167
|
+
* - a caller-supplied ref (the console's version picker) is used verbatim;
|
|
168
|
+
* - otherwise the repository's DEFAULT BRANCH is the latest version — the
|
|
169
|
+
* source tree is the product, and a repository that ships no release has no
|
|
170
|
+
* "latest release" to compare against;
|
|
171
|
+
* - an OLDER version can only be reached by a TAG (`v0.8.0`), which the card
|
|
172
|
+
* offers from the repository's own tag list.
|
|
173
|
+
*
|
|
174
|
+
* WORKSPACE LAYOUT. A plugin source tree is built as if it sat in a checkout's
|
|
175
|
+
* `plugins/<id>/`, because that is the layout every published plugin is written
|
|
176
|
+
* for: the reference packages import shared core helpers as
|
|
177
|
+
* `../../backend/src/…` (`qoder-models` pulls `plugins/catalog-def.js`, the
|
|
178
|
+
* ADR-0035 mapper, at RUNTIME), and they import the gateway's OWN dependencies
|
|
179
|
+
* (`protobufjs` in `cursor-gateway`) by bare specifier. Bundling such a tree in
|
|
180
|
+
* a flat temp dir fails with `Could not resolve: …`, which is not a repository
|
|
181
|
+
* error but a LAYOUT one. So the workspace root is linked the way a checkout
|
|
182
|
+
* root is: `<parent>/plugins/<id>/` beside `<parent>/backend` (THIS gateway's
|
|
183
|
+
* backend) and `<parent>/node_modules` (THIS gateway's dependency tree).
|
|
184
|
+
*
|
|
185
|
+
* The host may carry no TypeScript: a prebuilt distribution and the desktop
|
|
186
|
+
* installer both ship `backend/dist` with no `src` (the sidecar is a compiled
|
|
187
|
+
* binary). There `gatewayBackendDir()` is named by `OCR_BACKEND_DIR` and the
|
|
188
|
+
* workspace's `backend/src` links to the COMPILED tree, so the plugin's
|
|
189
|
+
* `../../backend/src/…` specifier still resolves.
|
|
190
|
+
*
|
|
191
|
+
* PRIVATE REPOSITORIES. Everything the card read with rides the build too: the
|
|
192
|
+
* source's token authenticates the clone (`x-access-token`, delivered through
|
|
193
|
+
* the child's environment, never argv), and `egress: 'proxy'` sends the clone
|
|
194
|
+
* and the dependency install down the same outbound leg the card was read on.
|
|
195
|
+
*/
|
|
196
|
+
export async function buildPackageFromSource(repo, opts) {
|
|
197
|
+
const exec = opts.runCommand ?? run;
|
|
198
|
+
// The toolchain probe honours the SAME seam: a test that stubs `git`/`bun`
|
|
199
|
+
// must not be answered by the machine's real ones.
|
|
200
|
+
const missing = exec === run ? toolMissing('git') ?? toolMissing('bun') : undefined;
|
|
201
|
+
if (missing)
|
|
202
|
+
return { error: missing };
|
|
203
|
+
const ref = opts.ref ?? opts.defaultBranch;
|
|
204
|
+
const workdir = fs.mkdtempSync(path.join(os.tmpdir(), 'ocr-market-src-'));
|
|
205
|
+
// The checkout lives inside the workspace so a plugin's `../../backend/src/…`
|
|
206
|
+
// resolves: `<workspace>/plugins/<id>` sits beside `<workspace>/backend`.
|
|
207
|
+
const workspace = path.join(workdir, 'ws');
|
|
208
|
+
fs.mkdirSync(path.join(workspace, 'plugins'), { recursive: true });
|
|
209
|
+
try {
|
|
210
|
+
const token = opts.token?.trim() || undefined;
|
|
211
|
+
// `git` gets the credential and the proxy; the dependency install gets ONLY
|
|
212
|
+
// the proxy — a GitHub token has no business in an npm/bun dependency
|
|
213
|
+
// resolver, and `GIT_CONFIG_*` would leak it to every `git` a package's
|
|
214
|
+
// prepare script might spawn.
|
|
215
|
+
//
|
|
216
|
+
// The ambient `https_proxy`/`HTTPS_PROXY` are DROPPED from both children:
|
|
217
|
+
// this gateway commonly runs with them pointed at its own ingress proxy, and
|
|
218
|
+
// an inherited value would silently override the market's choice — for git it
|
|
219
|
+
// would even route the clone back through the gateway itself.
|
|
220
|
+
const env = { ...process.env };
|
|
221
|
+
delete env.https_proxy;
|
|
222
|
+
delete env.HTTPS_PROXY;
|
|
223
|
+
const proxyEnv = opts.egressProxy ? { https_proxy: opts.egressProxy, HTTPS_PROXY: opts.egressProxy } : {};
|
|
224
|
+
// The dependency install rides the same leg but never the credential: a
|
|
225
|
+
// GitHub PAT is meaningless to an npm resolver, and `GIT_CONFIG_*` (carrying
|
|
226
|
+
// the extraheader) would hand it to any `git` a prepare script spawns.
|
|
227
|
+
const installEnv = { ...env, ...proxyEnv };
|
|
228
|
+
const cloneArgs = ['clone', '--depth', '1', '--branch', ref, '--single-branch', `https://github.com/${repo}.git`, 'checkout'];
|
|
229
|
+
const cloneAs = (extraheader) => exec('git', cloneArgs, workspace, BUILD_TOTAL_TIMEOUT_MS / 2,
|
|
230
|
+
// No credential means no extraheader AT ALL — `x-access-token:` with an
|
|
231
|
+
// empty password is a 401, not "anonymous".
|
|
232
|
+
{ ...env, ...gitEnv('github.com', extraheader, opts.egressProxy), ...proxyEnv });
|
|
233
|
+
const withToken = token ? gitAuthorization(token) : undefined;
|
|
234
|
+
let clone = cloneAs(withToken);
|
|
235
|
+
if (!clone.ok && withToken && cloneRefusedAuth(clone)) {
|
|
236
|
+
// GITHUB ANSWERS 401 TO A BAD CREDENTIAL EVEN FOR A PUBLIC REPOSITORY, so a
|
|
237
|
+
// token that expired (or a fine-grained one that lost repository access)
|
|
238
|
+
// would break an install that needs no credential at all. One anonymous
|
|
239
|
+
// retry costs nothing when the repository really is private — that clone
|
|
240
|
+
// fails exactly as it would have — and turns a stale token from "nothing
|
|
241
|
+
// installs" into "everything public still installs".
|
|
242
|
+
//
|
|
243
|
+
// A TRANSPORT failure is never retried: the token was not the problem, and
|
|
244
|
+
// a second attempt would only double a slow timeout.
|
|
245
|
+
opts.onLog?.(`the credential for ${repo} was refused; retrying the clone anonymously`);
|
|
246
|
+
fs.rmSync(path.join(workspace, 'checkout'), { recursive: true, force: true });
|
|
247
|
+
clone = cloneAs(undefined);
|
|
248
|
+
if (clone.ok) {
|
|
249
|
+
opts.onLog?.(`${repo} cloned ANONYMOUSLY — it is readable without the token that was supplied, so that token is expired, revoked, or not scoped to it`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (!clone.ok) {
|
|
253
|
+
// THREE different failures leave this line, and collapsing them lies:
|
|
254
|
+
// a missing toolchain is not a bad ref, a TLS/DNS failure is not a bad ref,
|
|
255
|
+
// and only the server's own "remote branch not found" earns the ref tail.
|
|
256
|
+
const missingTool = /command not found|not recognized|ENOENT/i.test(clone.stderr);
|
|
257
|
+
const refusal = failureLine(`git clone ${repo}@${ref}`, clone);
|
|
258
|
+
if (cloneRefusedAuth(clone)) {
|
|
259
|
+
// The token said "no", or there was none to say anything. Naming the
|
|
260
|
+
// SCOPE (this row's source, or the env tier for a registry entry) is the
|
|
261
|
+
// actionable half — a bare "not a branch" here reads as a wrong ref.
|
|
262
|
+
return {
|
|
263
|
+
error: `${refusal} — GitHub refused the clone. ` +
|
|
264
|
+
(token
|
|
265
|
+
? 'the token that read this card could not clone the repository: a fine-grained token must list it under Repository access with Contents: Read-only, and it must not be expired'
|
|
266
|
+
: 'no token was available for this row — add one to the SOURCE that found this repository, or set GITHUB_TOKEN for a registry entry'),
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
if (cloneTransportFailure(clone)) {
|
|
270
|
+
return {
|
|
271
|
+
error: `${refusal} — the clone never reached GitHub (TLS/DNS/connection). ` +
|
|
272
|
+
(opts.egressProxy
|
|
273
|
+
? `this build was set to leave through ${opts.egressProxy}; a proxy that cannot reach github.com fails here, and the clone is NOT retried directly`
|
|
274
|
+
: 'no outbound proxy was used for this build — if this machine needs one, set the market egress to `proxy`'),
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
return {
|
|
278
|
+
error: refusal +
|
|
279
|
+
(missingTool || VERSION_TAG_RE.test(ref) || !cloneRefMissingRef(clone)
|
|
280
|
+
? ''
|
|
281
|
+
: ` — ref '${ref}' is not a branch or tag of the repository`),
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
const checkout = path.join(workspace, 'checkout');
|
|
285
|
+
const repoPluginDir = opts.subdir ? path.join(checkout, ...opts.subdir.split('/')) : checkout;
|
|
286
|
+
const manifestPath = path.join(repoPluginDir, 'plugin.json');
|
|
287
|
+
if (!fs.existsSync(manifestPath)) {
|
|
288
|
+
return { error: `${repo}${opts.subdir ? `/${opts.subdir}` : ''} has no plugin.json at ref '${ref}'` };
|
|
289
|
+
}
|
|
290
|
+
let manifest;
|
|
291
|
+
try {
|
|
292
|
+
const parsed = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
293
|
+
validatePluginManifest(parsed, 'plugin.json');
|
|
294
|
+
manifest = parsed;
|
|
295
|
+
}
|
|
296
|
+
catch (err) {
|
|
297
|
+
return { error: `invalid plugin.json at '${ref}': ${err instanceof Error ? err.message : String(err)}` };
|
|
298
|
+
}
|
|
299
|
+
const existing = listInstalledPlugins().find((view) => view.id === manifest.id);
|
|
300
|
+
if (existing && existing.version === manifest.version && !opts.ref) {
|
|
301
|
+
return { error: `'${manifest.id}' ${manifest.version} is already installed — rebuild only after the repository moves` };
|
|
302
|
+
}
|
|
303
|
+
// The checkout-shaped workspace: the plugin becomes `<workspace>/plugins/<id>`
|
|
304
|
+
// with `<workspace>/backend` pointing at this gateway. A monorepo `subdir`
|
|
305
|
+
// is moved whole, so the tree keeps its own relative layout.
|
|
306
|
+
const pluginDir = path.join(workspace, 'plugins', manifest.id);
|
|
307
|
+
fs.renameSync(repoPluginDir, pluginDir);
|
|
308
|
+
try {
|
|
309
|
+
linkWorkspaceRoot(workdir, opts.backendDir);
|
|
310
|
+
}
|
|
311
|
+
catch (err) {
|
|
312
|
+
// A host that cannot expose its backend is a fact about THIS deployment,
|
|
313
|
+
// not about the repository: answer it as a reason instead of throwing.
|
|
314
|
+
return { error: err instanceof Error ? err.message : String(err) };
|
|
315
|
+
}
|
|
316
|
+
// Dependencies are the plugin's OWN (`bun install` beside its manifest). The
|
|
317
|
+
// packager inlines them into the bundle, so this step is what makes the
|
|
318
|
+
// result self-contained (ADR-0017 §6).
|
|
319
|
+
if (fs.existsSync(path.join(pluginDir, 'package.json'))) {
|
|
320
|
+
opts.onLog?.(`bun install in ${repo}`);
|
|
321
|
+
// The dependency install leaves the machine too, so it rides the SAME leg
|
|
322
|
+
// and the same credential-free environment as the clone (a registry that
|
|
323
|
+
// needs a token is a `registry` setting in the plugin's own .npmrc).
|
|
324
|
+
const install = exec('bun', ['install', '--no-env-file'], pluginDir, INSTALL_TIMEOUT_MS, installEnv);
|
|
325
|
+
if (!install.ok)
|
|
326
|
+
return { error: failureLine('bun install', install) };
|
|
327
|
+
}
|
|
328
|
+
opts.onLog?.(`bundling ${manifest.id} ${manifest.version}`);
|
|
329
|
+
let zip;
|
|
330
|
+
try {
|
|
331
|
+
// `bundlePluginDir` resolves this module's own imports from ITS location;
|
|
332
|
+
// the plugin dir only has to be walkable, so the workspace layout above
|
|
333
|
+
// is all it needs.
|
|
334
|
+
zip = await bundlePluginDir(pluginDir);
|
|
335
|
+
}
|
|
336
|
+
catch (err) {
|
|
337
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
338
|
+
const unresolvable = /Could not resolve: "([^"]+)"/.exec(message);
|
|
339
|
+
if (unresolvable && unresolvable[1].includes('backend/')) {
|
|
340
|
+
return {
|
|
341
|
+
error: `this plugin imports a core helper by a checkout-relative path (${unresolvable[1]}) that this build could not ` +
|
|
342
|
+
'satisfy — the plugin repository must be laid out as `plugins/<id>/` beside a `backend/`, or publish a release zip instead',
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
return { error: `the packager refused this source tree: ${message}` };
|
|
346
|
+
}
|
|
347
|
+
if (zip.byteLength > PLUGIN_PACKAGE_MAX_BYTES) {
|
|
348
|
+
return { error: `the built package exceeds the ${Math.round(PLUGIN_PACKAGE_MAX_BYTES / 1024 / 1024)} MiB cap` };
|
|
349
|
+
}
|
|
350
|
+
return { zip, version: manifest.version };
|
|
351
|
+
}
|
|
352
|
+
finally {
|
|
353
|
+
fs.rmSync(workdir, { recursive: true, force: true });
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
/** Whether a directory carries the backend tree a source build can expose:
|
|
357
|
+
* the sources of a checkout, or the compiled output a prebuilt/packaged host
|
|
358
|
+
* carries instead. */
|
|
359
|
+
function carriesBackend(dir) {
|
|
360
|
+
return (fs.existsSync(path.join(dir, 'src', 'plugins')) || fs.existsSync(path.join(dir, 'dist', 'plugins')));
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* This gateway's `backend/` directory, as the source build must expose it at
|
|
364
|
+
* the workspace root (module location is `<root>/backend/{src|dist}/plugins/`).
|
|
365
|
+
*
|
|
366
|
+
* `import.meta.url` is only meaningful in a source-launched host. A compiled
|
|
367
|
+
* Bun binary reports `file:///…/~BUN/root/…`, which exists nowhere on disk, and
|
|
368
|
+
* the desktop sidecar additionally has no checkout beside it — so the shells
|
|
369
|
+
* that carry their backend name it as `OCR_BACKEND_DIR`, and the executable /
|
|
370
|
+
* cwd fallbacks cover a portable unpacks-next-to-the-binary layout. A
|
|
371
|
+
* candidate wins only when it actually carries a backend tree, so a moved or
|
|
372
|
+
* half-installed override is skipped instead of trusted.
|
|
373
|
+
*/
|
|
374
|
+
export function gatewayBackendDir() {
|
|
375
|
+
const here = path.dirname(new URL(import.meta.url).pathname.replace(/^\/([A-Za-z]:)/, '$1'));
|
|
376
|
+
const moduleRelative = path.resolve(here, '../..');
|
|
377
|
+
const candidates = [
|
|
378
|
+
process.env.OCR_BACKEND_DIR?.trim(),
|
|
379
|
+
moduleRelative,
|
|
380
|
+
path.join(path.dirname(process.execPath), 'backend'),
|
|
381
|
+
path.join(process.cwd(), 'backend'),
|
|
382
|
+
];
|
|
383
|
+
for (const candidate of candidates) {
|
|
384
|
+
if (candidate && carriesBackend(candidate))
|
|
385
|
+
return path.resolve(candidate);
|
|
386
|
+
}
|
|
387
|
+
return moduleRelative;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Give the workspace the checkout's shape at its root, so what resolves in a
|
|
391
|
+
* real checkout resolves in a market build too:
|
|
392
|
+
*
|
|
393
|
+
* - `backend/src` (and `backend/dist`) — a plugin's `../../backend/src/…`
|
|
394
|
+
* specifier (the ADR-0035 mapper, and every core helper the reference
|
|
395
|
+
* packages import). The host may carry no sources, so `src` links to the
|
|
396
|
+
* COMPILED tree when that is all there is; the compiled output stays
|
|
397
|
+
* reachable at `backend/dist` either way;
|
|
398
|
+
* - `node_modules/` — the GATEWAY's dependencies. A source tree carries no
|
|
399
|
+
* `package.json` of its own in the reference repositories, and one of them
|
|
400
|
+
* imports `protobufjs`, which is the gateway's dependency, not the plugin's:
|
|
401
|
+
* in a checkout `<workspace>/plugins/<id>` walks up to `<workspace>`'s
|
|
402
|
+
* `node_modules` and finds it. Without the link the same tree fails with
|
|
403
|
+
* `Could not resolve: "protobufjs"`, which reads as a missing dependency the
|
|
404
|
+
* plugin author cannot fix.
|
|
405
|
+
*
|
|
406
|
+
* All are junctions/links (one hop, no copying of this gateway's sources); a
|
|
407
|
+
* platform that cannot make one gets a REFUSAL that says why, never a
|
|
408
|
+
* half-linked tree that fails later inside the bundler with an unrelated
|
|
409
|
+
* message. A gateway installed without `node_modules` (a self-contained build)
|
|
410
|
+
* simply has none to expose, and the plugin's own `bun install` covers it.
|
|
411
|
+
*/
|
|
412
|
+
function linkWorkspaceRoot(workdir, backendDir) {
|
|
413
|
+
// Junction targets must be absolute on Windows.
|
|
414
|
+
const backendRoot = path.resolve(backendDir);
|
|
415
|
+
const ws = path.join(workdir, 'ws');
|
|
416
|
+
const source = path.join(backendRoot, 'src');
|
|
417
|
+
const compiled = path.join(backendRoot, 'dist');
|
|
418
|
+
const srcTarget = fs.existsSync(path.join(source, 'plugins')) ? source : compiled;
|
|
419
|
+
if (!fs.existsSync(path.join(srcTarget, 'plugins'))) {
|
|
420
|
+
throw new Error(`this host carries no gateway backend at ${backendRoot}: neither src/plugins nor dist/plugins exists, so a plugin's \`../../backend/src/…\` import cannot resolve`);
|
|
421
|
+
}
|
|
422
|
+
const backendLink = path.join(ws, 'backend');
|
|
423
|
+
fs.mkdirSync(backendLink, { recursive: true });
|
|
424
|
+
const links = [
|
|
425
|
+
// `<backend>/../node_modules` is the checkout root's dependency tree.
|
|
426
|
+
{ from: path.join(backendRoot, '..', 'node_modules'), to: path.join(ws, 'node_modules'), required: false },
|
|
427
|
+
{ from: srcTarget, to: path.join(backendLink, 'src'), required: true },
|
|
428
|
+
...(fs.existsSync(compiled)
|
|
429
|
+
? [{ from: compiled, to: path.join(backendLink, 'dist'), required: true }]
|
|
430
|
+
: []),
|
|
431
|
+
];
|
|
432
|
+
for (const link of links) {
|
|
433
|
+
if (!link.required && !fs.existsSync(link.from))
|
|
434
|
+
continue;
|
|
435
|
+
if (fs.existsSync(link.to))
|
|
436
|
+
continue;
|
|
437
|
+
try {
|
|
438
|
+
fs.symlinkSync(link.from, link.to, process.platform === 'win32' ? 'junction' : 'dir');
|
|
439
|
+
}
|
|
440
|
+
catch (err) {
|
|
441
|
+
throw new Error(`cannot expose ${link.from} to the build at ${link.to}: ${err instanceof Error ? err.message : String(err)}`);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
/** Whether a ref looks like a version tag (so the console can distinguish "the
|
|
446
|
+
* latest source" from "an older published version"). */
|
|
447
|
+
export function isVersionRef(ref) {
|
|
448
|
+
return typeof ref === 'string' && VERSION_TAG_RE.test(ref.trim());
|
|
449
|
+
}
|