vessel-agent 0.0.0-stage → 2.3.0-beta.2
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/LICENSE +21 -0
- package/README.md +466 -2
- package/README.zh-CN.md +476 -0
- package/apps/web/dist/Vela.png +0 -0
- package/apps/web/dist/Vessel.svg +24 -0
- package/apps/web/dist/apple-touch-icon.png +0 -0
- package/apps/web/dist/assets/ConfigView-BKdxb1s5.js +1 -0
- package/apps/web/dist/assets/DesignLabContent-CY5HfVn_.js +4 -0
- package/apps/web/dist/assets/DesignLabView-DTBWv5-E.js +1 -0
- package/apps/web/dist/assets/action-menu.preview-CpIL3tay.js +1 -0
- package/apps/web/dist/assets/agent-message.preview-CSYnJxgr.js +1 -0
- package/apps/web/dist/assets/assistant-text.preview-Bc2Is6sW.js +2 -0
- package/apps/web/dist/assets/badges.preview-DP0oPcs5.js +1 -0
- package/apps/web/dist/assets/buttons.preview-Y84aT4k3.js +1 -0
- package/apps/web/dist/assets/card-shell.preview-mwRwhVb8.js +1 -0
- package/apps/web/dist/assets/chip-tones.preview-dQ_6pwft.js +1 -0
- package/apps/web/dist/assets/composer-controls.preview-CBtJVrMo.js +1 -0
- package/apps/web/dist/assets/confirm-dialog.preview-BkNEtLld.js +1 -0
- package/apps/web/dist/assets/data-table.preview-DPZ7Pnn8.js +1 -0
- package/apps/web/dist/assets/depth-color.preview-CtCbAgCH.js +1 -0
- package/apps/web/dist/assets/entity-header.preview-BxPLNUSH.js +1 -0
- package/apps/web/dist/assets/env-card.preview-Bv4UlMjr.js +1 -0
- package/apps/web/dist/assets/failure-card.preview-DD3-RMju.js +1 -0
- package/apps/web/dist/assets/filter-popover.preview-D7Q7Kws8.js +1 -0
- package/apps/web/dist/assets/form.preview-D_Qltx-j.js +1 -0
- package/apps/web/dist/assets/index-ee36IO2F.js +600 -0
- package/apps/web/dist/assets/index-uU9N5oTa.css +1 -0
- package/apps/web/dist/assets/key-value.preview-B0gzxwtK.js +1 -0
- package/apps/web/dist/assets/mention-popover.preview-Duza1RgL.js +1 -0
- package/apps/web/dist/assets/message-fold.preview-Cx-CD3Y4.js +1 -0
- package/apps/web/dist/assets/modal-shell.preview-DYKwUk2S.js +1 -0
- package/apps/web/dist/assets/nav-item.preview-FTbsBQ2g.js +1 -0
- package/apps/web/dist/assets/nav-status-legend.preview-bS4LDFbd.js +1 -0
- package/apps/web/dist/assets/page-scaffold.preview-bzBFkjZ6.js +1 -0
- package/apps/web/dist/assets/plugin-ui-BxTydP3l.js +1 -0
- package/apps/web/dist/assets/projection-card.preview-BV0P-y8e.js +6 -0
- package/apps/web/dist/assets/queued.preview-zQqFe4Zr.js +1 -0
- package/apps/web/dist/assets/react-vendor-CUu194FT.js +9 -0
- package/apps/web/dist/assets/reasoning.preview-DtHXgW_8.js +2 -0
- package/apps/web/dist/assets/section.preview-A-PRm-rh.js +1 -0
- package/apps/web/dist/assets/sidebar-shell.preview-DFKMwNoo.js +1 -0
- package/apps/web/dist/assets/stat.preview-BzChSFLL.js +1 -0
- package/apps/web/dist/assets/states.preview-CyXZWnZ-.js +1 -0
- package/apps/web/dist/assets/status-icons.preview-DHdWwUis.js +1 -0
- package/apps/web/dist/assets/tabs.preview-CHbK1Two.js +1 -0
- package/apps/web/dist/assets/tool-card.preview-Z48fekTD.js +2 -0
- package/apps/web/dist/assets/toolbar.preview-Bl6hLYXX.js +1 -0
- package/apps/web/dist/assets/tooltip.preview-GKGTGfMP.js +1 -0
- package/apps/web/dist/assets/user-bubble.preview-CHYvio9z.js +1 -0
- package/apps/web/dist/assets/vendor/jsx-runtime.mjs +7 -0
- package/apps/web/dist/assets/vendor/plugin-sdk.mjs +12 -0
- package/apps/web/dist/assets/vendor/react-dom-client.mjs +6 -0
- package/apps/web/dist/assets/vendor/react-dom.mjs +11 -0
- package/apps/web/dist/assets/vendor/react.mjs +39 -0
- package/apps/web/dist/build.json +5 -0
- package/apps/web/dist/favicon.ico +0 -0
- package/apps/web/dist/index.html +24 -0
- package/package.json +70 -4
- package/packages/agent/package.json +32 -0
- package/packages/agent/src/address-display.ts +141 -0
- package/packages/agent/src/conversation-budget.ts +651 -0
- package/packages/agent/src/conversation-store.ts +351 -0
- package/packages/agent/src/distress.ts +161 -0
- package/packages/agent/src/env-info-scope.ts +153 -0
- package/packages/agent/src/error-text.ts +28 -0
- package/packages/agent/src/inbox-source.ts +73 -0
- package/packages/agent/src/inbox.ts +2335 -0
- package/packages/agent/src/index.ts +273 -0
- package/packages/agent/src/member-cwd.ts +128 -0
- package/packages/agent/src/member-ports.ts +162 -0
- package/packages/agent/src/refs.ts +51 -0
- package/packages/agent/src/registry.ts +741 -0
- package/packages/agent/src/runtime.ts +2501 -0
- package/packages/agent/src/self-card-delta.ts +428 -0
- package/packages/agent/src/service.ts +9212 -0
- package/packages/agent/src/snapshot.ts +614 -0
- package/packages/agent/src/team-address.ts +96 -0
- package/packages/agent/src/team-log.ts +487 -0
- package/packages/agent/src/team-service.ts +1966 -0
- package/packages/agent/src/team-slug.ts +167 -0
- package/packages/agent/src/team-store.ts +619 -0
- package/packages/agent/src/tool.ts +1306 -0
- package/packages/agent/src/types/budget.ts +168 -0
- package/packages/agent/src/types/constants.ts +17 -0
- package/packages/agent/src/types/dispatch.ts +133 -0
- package/packages/agent/src/types/events.ts +132 -0
- package/packages/agent/src/types/execution.ts +289 -0
- package/packages/agent/src/types/lifecycle.ts +372 -0
- package/packages/agent/src/types/member.ts +221 -0
- package/packages/agent/src/types/message.ts +113 -0
- package/packages/agent/src/types/results.ts +64 -0
- package/packages/agent/src/types/roster.ts +137 -0
- package/packages/agent/src/types/service.ts +702 -0
- package/packages/agent/src/types/session.ts +102 -0
- package/packages/agent/src/types/team.ts +558 -0
- package/packages/agent/src/types.ts +22 -0
- package/packages/agent/tsconfig.json +8 -0
- package/packages/config/package.json +32 -0
- package/packages/config/src/auth-origins.ts +85 -0
- package/packages/config/src/auth-strategies/avatar-ref.ts +40 -0
- package/packages/config/src/auth-strategies/gitee.ts +72 -0
- package/packages/config/src/auth-strategies/github.ts +64 -0
- package/packages/config/src/auth-strategies/index.ts +47 -0
- package/packages/config/src/auth-strategies/match.ts +82 -0
- package/packages/config/src/auth-strategies/microsoft.ts +100 -0
- package/packages/config/src/auth-strategies/oauth-exchange.ts +192 -0
- package/packages/config/src/auth-strategies/password.ts +34 -0
- package/packages/config/src/auth-strategies/registry.ts +105 -0
- package/packages/config/src/auth-strategies/shapes.ts +138 -0
- package/packages/config/src/auth-strategies/types.ts +190 -0
- package/packages/config/src/auth.ts +305 -0
- package/packages/config/src/config-lock.ts +328 -0
- package/packages/config/src/defaults.ts +271 -0
- package/packages/config/src/env-file.ts +175 -0
- package/packages/config/src/env-injection.ts +117 -0
- package/packages/config/src/explain.ts +283 -0
- package/packages/config/src/gateway.ts +107 -0
- package/packages/config/src/index.ts +253 -0
- package/packages/config/src/loader.ts +871 -0
- package/packages/config/src/model-migration.ts +534 -0
- package/packages/config/src/model-registry.ts +374 -0
- package/packages/config/src/models-disk.ts +72 -0
- package/packages/config/src/models-validation.ts +467 -0
- package/packages/config/src/node-registration.ts +583 -0
- package/packages/config/src/root-secret.ts +402 -0
- package/packages/config/src/secrets.ts +452 -0
- package/packages/config/src/sources.ts +82 -0
- package/packages/config/src/team-policy.ts +422 -0
- package/packages/config/src/types/agent.ts +263 -0
- package/packages/config/src/types/attention.ts +28 -0
- package/packages/config/src/types/auth.ts +126 -0
- package/packages/config/src/types/connect.ts +21 -0
- package/packages/config/src/types/hub.ts +59 -0
- package/packages/config/src/types/models.ts +153 -0
- package/packages/config/src/types/node.ts +202 -0
- package/packages/config/src/types/observability.ts +84 -0
- package/packages/config/src/types/root.ts +240 -0
- package/packages/config/src/types/runtime.ts +123 -0
- package/packages/config/src/types/security.ts +43 -0
- package/packages/config/src/types/serve.ts +34 -0
- package/packages/config/src/types/snapshot.ts +28 -0
- package/packages/config/src/types/team.ts +112 -0
- package/packages/config/src/types/ui.ts +179 -0
- package/packages/config/src/types.ts +22 -0
- package/packages/config/src/user-config.ts +175 -0
- package/packages/config/src/utils.ts +55 -0
- package/packages/config/src/validator/auth.ts +302 -0
- package/packages/config/src/validator/hub.ts +329 -0
- package/packages/config/src/validator/models.ts +1304 -0
- package/packages/config/src/validator/serve.ts +784 -0
- package/packages/config/src/validator/settings.ts +244 -0
- package/packages/config/src/validator/shared.ts +304 -0
- package/packages/config/src/validator/tenant-keys.ts +91 -0
- package/packages/config/src/validator/unknown-keys.ts +452 -0
- package/packages/config/src/validator.ts +1146 -0
- package/packages/config/tsconfig.json +8 -0
- package/packages/core/package.json +38 -0
- package/packages/core/src/context/anchor.ts +57 -0
- package/packages/core/src/context/archive-notice.ts +283 -0
- package/packages/core/src/context/cleared-tool-result.ts +262 -0
- package/packages/core/src/context/compaction-index.ts +381 -0
- package/packages/core/src/context/composition.ts +251 -0
- package/packages/core/src/context/context-manager.ts +1585 -0
- package/packages/core/src/context/context-notice.ts +218 -0
- package/packages/core/src/context/index.ts +220 -0
- package/packages/core/src/context/model-change-notice.ts +81 -0
- package/packages/core/src/context/projection-policy.ts +719 -0
- package/packages/core/src/context/prompt-context.ts +66 -0
- package/packages/core/src/context/read-side-mask.ts +63 -0
- package/packages/core/src/context/request-sequence.ts +423 -0
- package/packages/core/src/context/request-view.ts +256 -0
- package/packages/core/src/context/session-breaker.ts +100 -0
- package/packages/core/src/context/tool-result-whitelist.ts +135 -0
- package/packages/core/src/events/event-stream.ts +271 -0
- package/packages/core/src/events/file-event-store.ts +119 -0
- package/packages/core/src/events/index.ts +15 -0
- package/packages/core/src/events/replay.ts +82 -0
- package/packages/core/src/events/summarize-event.ts +135 -0
- package/packages/core/src/index.ts +475 -0
- package/packages/core/src/kernel/cancellation.ts +54 -0
- package/packages/core/src/kernel/event-bus.ts +65 -0
- package/packages/core/src/kernel/index.ts +32 -0
- package/packages/core/src/kernel/internal.ts +32 -0
- package/packages/core/src/kernel/scheduler.ts +406 -0
- package/packages/core/src/kernel/types.ts +269 -0
- package/packages/core/src/limits/index.ts +23 -0
- package/packages/core/src/limits/limit-checker.ts +270 -0
- package/packages/core/src/limits/limit-error.ts +29 -0
- package/packages/core/src/log-format.ts +722 -0
- package/packages/core/src/log-hub.ts +278 -0
- package/packages/core/src/logging.ts +64 -0
- package/packages/core/src/observability/index.ts +24 -0
- package/packages/core/src/observability/metrics.ts +279 -0
- package/packages/core/src/observability/read-trace.ts +163 -0
- package/packages/core/src/observability/rebuild-metrics.ts +37 -0
- package/packages/core/src/observability/trace-prune.ts +248 -0
- package/packages/core/src/observability/trace-recorder.ts +484 -0
- package/packages/core/src/observability/trace-redactor.ts +93 -0
- package/packages/core/src/pii/index.ts +88 -0
- package/packages/core/src/pii/notice.ts +156 -0
- package/packages/core/src/pii/reveal.ts +198 -0
- package/packages/core/src/pii/rules.ts +545 -0
- package/packages/core/src/pii/types.ts +140 -0
- package/packages/core/src/pii/vault.ts +764 -0
- package/packages/core/src/provider/errors.ts +41 -0
- package/packages/core/src/provider/index.ts +19 -0
- package/packages/core/src/provider/providers.ts +1011 -0
- package/packages/core/src/provider/request-extras.ts +285 -0
- package/packages/core/src/provider/stream-accumulator.ts +168 -0
- package/packages/core/src/provider/usage.ts +112 -0
- package/packages/core/src/runtime/error-envelope.ts +451 -0
- package/packages/core/src/runtime/error-summary.ts +174 -0
- package/packages/core/src/runtime/execution-unit.ts +6675 -0
- package/packages/core/src/runtime/guardrail-runner.ts +86 -0
- package/packages/core/src/runtime/hook-runner.ts +137 -0
- package/packages/core/src/runtime/index.ts +123 -0
- package/packages/core/src/runtime/permission-policy.ts +267 -0
- package/packages/core/src/runtime/plugin-host.ts +489 -0
- package/packages/core/src/runtime/plugin-install.ts +144 -0
- package/packages/core/src/runtime/policy/index.ts +21 -0
- package/packages/core/src/runtime/prompt-prefix-guard.ts +166 -0
- package/packages/core/src/runtime/provider-retry.ts +220 -0
- package/packages/core/src/runtime/resume-markers.ts +114 -0
- package/packages/core/src/runtime/resume-recovery.ts +164 -0
- package/packages/core/src/runtime/run-journal.ts +382 -0
- package/packages/core/src/runtime/run-timing.ts +217 -0
- package/packages/core/src/runtime/runtime.ts +349 -0
- package/packages/core/src/runtime/safepoint-pause.ts +29 -0
- package/packages/core/src/runtime/tool-attachment.ts +170 -0
- package/packages/core/src/runtime/tool-calling-loop.ts +1219 -0
- package/packages/core/src/runtime/tool-name.ts +215 -0
- package/packages/core/src/runtime/tool-pipeline.ts +459 -0
- package/packages/core/src/runtime/tool-provenance.ts +48 -0
- package/packages/core/src/runtime/tool-result-gate.ts +329 -0
- package/packages/core/src/session/atomic-write.ts +335 -0
- package/packages/core/src/session/compaction-index-derive.ts +173 -0
- package/packages/core/src/session/compaction-index-store.ts +161 -0
- package/packages/core/src/session/compaction-recall.ts +375 -0
- package/packages/core/src/session/delete-session.ts +198 -0
- package/packages/core/src/session/file-backend.ts +1311 -0
- package/packages/core/src/session/index.ts +118 -0
- package/packages/core/src/session/message-identity.ts +272 -0
- package/packages/core/src/session/project-messages.ts +908 -0
- package/packages/core/src/session/projection-cache.ts +254 -0
- package/packages/core/src/session/prune.ts +153 -0
- package/packages/core/src/session/run-record-store.ts +307 -0
- package/packages/core/src/session/session-index.ts +158 -0
- package/packages/core/src/session/session-log-dir.ts +39 -0
- package/packages/core/src/session/session-store.ts +266 -0
- package/packages/core/src/session/sqlite-backend.ts +391 -0
- package/packages/core/src/socket-inherit-guard.ts +188 -0
- package/packages/core/src/storage/metadata-sidecar.ts +124 -0
- package/packages/core/src/tenant/index.ts +13 -0
- package/packages/core/src/tenant/resolve-tenant.ts +19 -0
- package/packages/core/src/tenant/tenant-paths.ts +83 -0
- package/packages/core/src/timeline/archive-audit.ts +316 -0
- package/packages/core/src/timeline/archive-lock.ts +124 -0
- package/packages/core/src/timeline/blocks.ts +1639 -0
- package/packages/core/src/timeline/enum-stats.ts +34 -0
- package/packages/core/src/timeline/holes.ts +431 -0
- package/packages/core/src/timeline/index.ts +387 -0
- package/packages/core/src/timeline/legacy-format.ts +97 -0
- package/packages/core/src/timeline/read-port.ts +582 -0
- package/packages/core/src/timeline/types.ts +371 -0
- package/packages/core/src/timeline/wal.ts +2485 -0
- package/packages/core/src/timeline/writer.ts +2079 -0
- package/packages/core/src/timeout.ts +93 -0
- package/packages/core/src/transport/in-process.ts +86 -0
- package/packages/core/src/transport/index.ts +6 -0
- package/packages/core/src/types/context.ts +229 -0
- package/packages/core/src/types/env-cadence.ts +35 -0
- package/packages/core/src/types/error-registry.ts +343 -0
- package/packages/core/src/types/error.ts +107 -0
- package/packages/core/src/types/event.ts +496 -0
- package/packages/core/src/types/guardrail.ts +35 -0
- package/packages/core/src/types/hook.ts +122 -0
- package/packages/core/src/types/index.ts +28 -0
- package/packages/core/src/types/lease.ts +91 -0
- package/packages/core/src/types/limits.ts +112 -0
- package/packages/core/src/types/logging.ts +54 -0
- package/packages/core/src/types/member-port.ts +194 -0
- package/packages/core/src/types/plugin.ts +392 -0
- package/packages/core/src/types/projection-cache.ts +80 -0
- package/packages/core/src/types/projection.ts +100 -0
- package/packages/core/src/types/provider.ts +319 -0
- package/packages/core/src/types/run-journal.ts +178 -0
- package/packages/core/src/types/run-record-store.ts +128 -0
- package/packages/core/src/types/run.ts +140 -0
- package/packages/core/src/types/session.ts +328 -0
- package/packages/core/src/types/source-module.ts +68 -0
- package/packages/core/src/types/tenant.ts +41 -0
- package/packages/core/src/types/tool-name.ts +57 -0
- package/packages/core/src/types/tool.ts +122 -0
- package/packages/core/src/types/trace.ts +38 -0
- package/packages/core/src/types/vision.ts +219 -0
- package/packages/core/src/vision/blobs.ts +328 -0
- package/packages/core/src/vision/index.ts +73 -0
- package/packages/core/src/vision/ingest.ts +126 -0
- package/packages/core/src/vision/notice.ts +58 -0
- package/packages/core/src/vision/plan.ts +358 -0
- package/packages/core/src/vision/staging.ts +81 -0
- package/packages/core/tsconfig.json +8 -0
- package/packages/permission/package.json +31 -0
- package/packages/permission/src/index.ts +60 -0
- package/packages/plugin-sdk/package.json +21 -0
- package/packages/plugin-sdk/src/index.ts +478 -0
- package/packages/plugin-sdk/src/semver.ts +154 -0
- package/packages/plugin-ui/package.json +33 -0
- package/packages/plugin-ui/src/Badge.tsx +41 -0
- package/packages/plugin-ui/src/Button.tsx +84 -0
- package/packages/plugin-ui/src/ComposerAttachments.tsx +87 -0
- package/packages/plugin-ui/src/ComposerContextMeter.tsx +209 -0
- package/packages/plugin-ui/src/ComposerToolbar.tsx +233 -0
- package/packages/plugin-ui/src/CountBadge.tsx +57 -0
- package/packages/plugin-ui/src/DataTable.tsx +168 -0
- package/packages/plugin-ui/src/Field.tsx +543 -0
- package/packages/plugin-ui/src/KeyValueList.tsx +32 -0
- package/packages/plugin-ui/src/Page.tsx +39 -0
- package/packages/plugin-ui/src/Pager.tsx +63 -0
- package/packages/plugin-ui/src/SearchInput.tsx +33 -0
- package/packages/plugin-ui/src/Section.tsx +47 -0
- package/packages/plugin-ui/src/Stat.tsx +25 -0
- package/packages/plugin-ui/src/TableToolbar.tsx +27 -0
- package/packages/plugin-ui/src/Tabs.tsx +77 -0
- package/packages/plugin-ui/src/card-surface.ts +11 -0
- package/packages/plugin-ui/src/cn.ts +7 -0
- package/packages/plugin-ui/src/dom-globals.d.ts +124 -0
- package/packages/plugin-ui/src/host.ts +270 -0
- package/packages/plugin-ui/src/index.ts +26 -0
- package/packages/plugin-ui/src/styles.css +386 -0
- package/packages/plugin-ui/src/useStaleWhileRevalidate.ts +211 -0
- package/packages/serve/package.json +32 -0
- package/packages/serve/src/agent-control.ts +595 -0
- package/packages/serve/src/agents-registry.ts +409 -0
- package/packages/serve/src/auth/avatar.ts +352 -0
- package/packages/serve/src/auth/bootstrap.ts +184 -0
- package/packages/serve/src/auth/credentials.ts +275 -0
- package/packages/serve/src/auth/github-oauth.ts +33 -0
- package/packages/serve/src/auth/index.ts +121 -0
- package/packages/serve/src/auth/oauth.ts +394 -0
- package/packages/serve/src/auth/origins.ts +145 -0
- package/packages/serve/src/auth/password.ts +187 -0
- package/packages/serve/src/auth/ratelimit.ts +249 -0
- package/packages/serve/src/auth/routes.ts +1757 -0
- package/packages/serve/src/auth/session.ts +407 -0
- package/packages/serve/src/auth/totp.ts +183 -0
- package/packages/serve/src/backpressure.ts +91 -0
- package/packages/serve/src/durable.ts +216 -0
- package/packages/serve/src/evals.ts +140 -0
- package/packages/serve/src/event-buffer.ts +92 -0
- package/packages/serve/src/event-summary.ts +11 -0
- package/packages/serve/src/federation.ts +1100 -0
- package/packages/serve/src/feishu.ts +51 -0
- package/packages/serve/src/gateway/auth.ts +773 -0
- package/packages/serve/src/gateway/errors.ts +21 -0
- package/packages/serve/src/gateway/frames.ts +195 -0
- package/packages/serve/src/gateway/methods/admin.ts +530 -0
- package/packages/serve/src/gateway/methods/agents.ts +1727 -0
- package/packages/serve/src/gateway/methods/attachments.ts +354 -0
- package/packages/serve/src/gateway/methods/common.ts +50 -0
- package/packages/serve/src/gateway/methods/config.ts +883 -0
- package/packages/serve/src/gateway/methods/evals.ts +87 -0
- package/packages/serve/src/gateway/methods/feishu.ts +52 -0
- package/packages/serve/src/gateway/methods/fleet.ts +225 -0
- package/packages/serve/src/gateway/methods/images.ts +196 -0
- package/packages/serve/src/gateway/methods/interactions.ts +721 -0
- package/packages/serve/src/gateway/methods/jobs.ts +148 -0
- package/packages/serve/src/gateway/methods/kanban.ts +637 -0
- package/packages/serve/src/gateway/methods/mcp.ts +82 -0
- package/packages/serve/src/gateway/methods/observability.ts +264 -0
- package/packages/serve/src/gateway/methods/permissions.ts +397 -0
- package/packages/serve/src/gateway/methods/rpc-namespaces.ts +80 -0
- package/packages/serve/src/gateway/methods/runs.ts +434 -0
- package/packages/serve/src/gateway/methods/schemas.ts +1196 -0
- package/packages/serve/src/gateway/methods/sessions.ts +2568 -0
- package/packages/serve/src/gateway/methods/subscription.ts +515 -0
- package/packages/serve/src/gateway/methods/teams.ts +638 -0
- package/packages/serve/src/gateway/sse.ts +130 -0
- package/packages/serve/src/gateway/static.ts +66 -0
- package/packages/serve/src/gateway/timeline-protocol.ts +532 -0
- package/packages/serve/src/gateway.ts +4974 -0
- package/packages/serve/src/hub-control.ts +86 -0
- package/packages/serve/src/hub-frames.ts +435 -0
- package/packages/serve/src/hub-protocol.ts +182 -0
- package/packages/serve/src/index.ts +511 -0
- package/packages/serve/src/interactions-registry.ts +1362 -0
- package/packages/serve/src/interactions-store.ts +360 -0
- package/packages/serve/src/local.ts +48 -0
- package/packages/serve/src/log-event.ts +57 -0
- package/packages/serve/src/mcp.ts +73 -0
- package/packages/serve/src/metrics.ts +137 -0
- package/packages/serve/src/platform/auth.ts +146 -0
- package/packages/serve/src/platform/index.ts +54 -0
- package/packages/serve/src/platform/listen-guard.ts +68 -0
- package/packages/serve/src/platform/metrics.ts +123 -0
- package/packages/serve/src/platform/proxy-config.ts +368 -0
- package/packages/serve/src/platform/proxy-ws.ts +737 -0
- package/packages/serve/src/platform/proxy.ts +909 -0
- package/packages/serve/src/platform/registry.ts +130 -0
- package/packages/serve/src/platform/rpc.ts +445 -0
- package/packages/serve/src/platform/server.ts +1148 -0
- package/packages/serve/src/platform/types.ts +276 -0
- package/packages/serve/src/plugin-host/catalog.ts +212 -0
- package/packages/serve/src/plugin-host/child.ts +767 -0
- package/packages/serve/src/plugin-host/dto.ts +191 -0
- package/packages/serve/src/plugin-host/errors.ts +50 -0
- package/packages/serve/src/plugin-host/events.ts +114 -0
- package/packages/serve/src/plugin-host/expose.ts +142 -0
- package/packages/serve/src/plugin-host/http.ts +823 -0
- package/packages/serve/src/plugin-host/index.ts +170 -0
- package/packages/serve/src/plugin-host/manager.ts +2027 -0
- package/packages/serve/src/plugin-host/ndjson.ts +136 -0
- package/packages/serve/src/plugin-host/proxy.ts +358 -0
- package/packages/serve/src/plugin-host/registry.ts +208 -0
- package/packages/serve/src/plugin-host/static.ts +162 -0
- package/packages/serve/src/plugin-host/types.ts +529 -0
- package/packages/serve/src/plugin-host/ws-proxy.ts +431 -0
- package/packages/serve/src/prometheus.ts +98 -0
- package/packages/serve/src/protocol.ts +332 -0
- package/packages/serve/src/replay-budget.ts +481 -0
- package/packages/serve/src/rpc.ts +614 -0
- package/packages/serve/src/run-control.ts +106 -0
- package/packages/serve/src/session-search.ts +142 -0
- package/packages/serve/src/shutdown-step.ts +128 -0
- package/packages/serve/src/team-control.ts +282 -0
- package/packages/serve/src/tenant-event-hub.ts +194 -0
- package/packages/serve/src/tenant.ts +169 -0
- package/packages/serve/src/tool-events.ts +244 -0
- package/packages/tui/package.json +40 -0
- package/packages/tui/src/commands/agents-command.ts +402 -0
- package/packages/tui/src/commands/capabilities-command.ts +356 -0
- package/packages/tui/src/commands/commands.ts +1361 -0
- package/packages/tui/src/commands/config-command.ts +541 -0
- package/packages/tui/src/commands/context-command.ts +348 -0
- package/packages/tui/src/commands/cost-command.ts +66 -0
- package/packages/tui/src/commands/details-command.ts +47 -0
- package/packages/tui/src/commands/errors-command.ts +205 -0
- package/packages/tui/src/commands/export-command.ts +193 -0
- package/packages/tui/src/commands/feishu-command.ts +101 -0
- package/packages/tui/src/commands/mcp-command.ts +319 -0
- package/packages/tui/src/commands/metrics-command.ts +314 -0
- package/packages/tui/src/commands/permissions-command.ts +117 -0
- package/packages/tui/src/commands/runs-command.ts +421 -0
- package/packages/tui/src/commands/sessions-command.ts +367 -0
- package/packages/tui/src/commands/settings-command.ts +180 -0
- package/packages/tui/src/commands/status-command.ts +30 -0
- package/packages/tui/src/commands/trace-command.ts +382 -0
- package/packages/tui/src/components/AskUserDialog.tsx +663 -0
- package/packages/tui/src/components/BottomBar.tsx +44 -0
- package/packages/tui/src/components/ConfirmDialog.tsx +175 -0
- package/packages/tui/src/components/DataTable.tsx +99 -0
- package/packages/tui/src/components/DetailPanel.tsx +80 -0
- package/packages/tui/src/components/EmptyState.tsx +27 -0
- package/packages/tui/src/components/InlineAutocomplete.tsx +319 -0
- package/packages/tui/src/components/InteractiveViewHost.tsx +652 -0
- package/packages/tui/src/components/KeyHints.tsx +41 -0
- package/packages/tui/src/components/Markdown.tsx +489 -0
- package/packages/tui/src/components/PanelFrame.tsx +113 -0
- package/packages/tui/src/components/QueuePreview.tsx +113 -0
- package/packages/tui/src/components/QuickHelp.tsx +91 -0
- package/packages/tui/src/components/ReasoningBlock.tsx +42 -0
- package/packages/tui/src/components/SessionTable.tsx +523 -0
- package/packages/tui/src/components/SpinnerWithVerb.tsx +116 -0
- package/packages/tui/src/components/StateTracker.ts +102 -0
- package/packages/tui/src/components/StatusBar.tsx +315 -0
- package/packages/tui/src/components/StreamOutput.tsx +302 -0
- package/packages/tui/src/components/SubagentActivity.tsx +57 -0
- package/packages/tui/src/components/TextViewer.tsx +100 -0
- package/packages/tui/src/components/ToolDisplay.tsx +248 -0
- package/packages/tui/src/components/ToolTrail.tsx +104 -0
- package/packages/tui/src/components/UiItemView.tsx +460 -0
- package/packages/tui/src/components/UpdateBanner.tsx +48 -0
- package/packages/tui/src/components/indicator.ts +61 -0
- package/packages/tui/src/error-classifier.ts +255 -0
- package/packages/tui/src/i18n/index.ts +67 -0
- package/packages/tui/src/i18n/messages/en.ts +543 -0
- package/packages/tui/src/i18n/messages/zh-CN.ts +528 -0
- package/packages/tui/src/index.ts +335 -0
- package/packages/tui/src/renderer/ask-user.ts +431 -0
- package/packages/tui/src/renderer/notify-user.ts +184 -0
- package/packages/tui/src/renderer/stream-renderer.ts +149 -0
- package/packages/tui/src/renderer/tool-confirm.ts +47 -0
- package/packages/tui/src/repl/agent-registry.ts +747 -0
- package/packages/tui/src/repl/cache-metrics.ts +241 -0
- package/packages/tui/src/repl/clear-on-start.ts +28 -0
- package/packages/tui/src/repl/error-archive.ts +95 -0
- package/packages/tui/src/repl/error-log.ts +212 -0
- package/packages/tui/src/repl/ink-repl.tsx +1735 -0
- package/packages/tui/src/repl/layout.ts +303 -0
- package/packages/tui/src/repl/limit-info.ts +630 -0
- package/packages/tui/src/repl/permission-pending.ts +49 -0
- package/packages/tui/src/repl/project/ui-item.ts +1307 -0
- package/packages/tui/src/repl/queue-info.ts +109 -0
- package/packages/tui/src/repl/resume-picker.ts +24 -0
- package/packages/tui/src/repl/run-turn.ts +60 -0
- package/packages/tui/src/repl/runtime-counters.ts +91 -0
- package/packages/tui/src/repl/startup-header.ts +144 -0
- package/packages/tui/src/repl/startup-notice.ts +100 -0
- package/packages/tui/src/repl/status-format.ts +513 -0
- package/packages/tui/src/repl/status-metrics.ts +88 -0
- package/packages/tui/src/repl/status-snapshot.ts +454 -0
- package/packages/tui/src/repl/use-repl-state.ts +548 -0
- package/packages/tui/src/repl-context.ts +349 -0
- package/packages/tui/src/rich-renderer.ts +63 -0
- package/packages/tui/src/rpc-events.ts +161 -0
- package/packages/tui/src/rpc.ts +149 -0
- package/packages/tui/src/theme.ts +180 -0
- package/packages/tui/src/types/events.ts +284 -0
- package/packages/tui/src/utils/dialog.ts +35 -0
- package/packages/tui/src/utils/diff.ts +124 -0
- package/packages/tui/src/utils/display-labels.ts +56 -0
- package/packages/tui/src/utils/file-reference.ts +180 -0
- package/packages/tui/src/utils/git.ts +24 -0
- package/packages/tui/src/utils/sanitize-terminal-text.ts +109 -0
- package/packages/tui/src/utils/text-layout.ts +127 -0
- package/packages/tui/src/utils/time.ts +25 -0
- package/packages/tui/src/utils/tool-input-summary.ts +70 -0
- package/packages/tui/src/views/keys.ts +344 -0
- package/packages/tui/src/views/layout.ts +224 -0
- package/packages/tui/src/views/render-text.ts +154 -0
- package/packages/tui/src/views/selection.ts +57 -0
- package/packages/tui/src/views/session-picker.ts +215 -0
- package/packages/tui/src/views/tones.ts +24 -0
- package/packages/tui/src/views/types.ts +200 -0
- package/packages/tui/src/wizard/setup-wizard.ts +439 -0
- package/packages/tui/tsconfig.json +10 -0
- package/plugins/context/doc-subscription/package.json +32 -0
- package/plugins/context/doc-subscription/src/agent.ts +151 -0
- package/plugins/context/doc-subscription/src/auto-sub.ts +80 -0
- package/plugins/context/doc-subscription/src/config.ts +358 -0
- package/plugins/context/doc-subscription/src/diff.ts +107 -0
- package/plugins/context/doc-subscription/src/friend-edges.ts +118 -0
- package/plugins/context/doc-subscription/src/health.ts +163 -0
- package/plugins/context/doc-subscription/src/hook.ts +1222 -0
- package/plugins/context/doc-subscription/src/implicit.ts +84 -0
- package/plugins/context/doc-subscription/src/index.ts +288 -0
- package/plugins/context/doc-subscription/src/lifecycle-listener.ts +58 -0
- package/plugins/context/doc-subscription/src/lifecycle.ts +186 -0
- package/plugins/context/doc-subscription/src/mute.ts +39 -0
- package/plugins/context/doc-subscription/src/notice.ts +347 -0
- package/plugins/context/doc-subscription/src/script.ts +288 -0
- package/plugins/context/doc-subscription/src/sources.ts +187 -0
- package/plugins/context/doc-subscription/src/store.ts +748 -0
- package/plugins/context/doc-subscription/src/team-log.ts +155 -0
- package/plugins/context/doc-subscription/src/tool.ts +2132 -0
- package/plugins/context/skills/package.json +182 -0
- package/plugins/context/skills/src/config.ts +178 -0
- package/plugins/context/skills/src/frontmatter.ts +166 -0
- package/plugins/context/skills/src/index.ts +144 -0
- package/plugins/context/skills/src/rpc.ts +274 -0
- package/plugins/context/skills/src/scanner.ts +262 -0
- package/plugins/context/skills/src/service.ts +277 -0
- package/plugins/context/skills/src/store.ts +333 -0
- package/plugins/context/skills/src/tool.ts +354 -0
- package/plugins/context/skills/src/trust.ts +71 -0
- package/plugins/context/skills/src/types.ts +130 -0
- package/plugins/context/skills/src/watch.ts +83 -0
- package/plugins/context/skills/tsconfig.web.json +29 -0
- package/plugins/context/skills/vite.config.embed.ts +107 -0
- package/plugins/context/skills/vite.config.ts +121 -0
- package/plugins/context/skills/web/assets/skills-8su2cNqF.css +2 -0
- package/plugins/context/skills/web/assets/skills-BhiDTAac.js +10 -0
- package/plugins/context/skills/web/embed/index.css +3 -0
- package/plugins/context/skills/web/embed/index.mjs +4251 -0
- package/plugins/context/skills/web/skills.html +13 -0
- package/plugins/context/skills/web-src/App.tsx +47 -0
- package/plugins/context/skills/web-src/SkillsView.tsx +649 -0
- package/plugins/context/skills/web-src/embed.css +153 -0
- package/plugins/context/skills/web-src/embed.tsx +36 -0
- package/plugins/context/skills/web-src/env.d.ts +2 -0
- package/plugins/context/skills/web-src/i18n.ts +195 -0
- package/plugins/context/skills/web-src/main.tsx +14 -0
- package/plugins/context/skills/web-src/shared.tsx +226 -0
- package/plugins/context/skills/web-src/skills.html +12 -0
- package/plugins/context/skills/web-src/styles.css +62 -0
- package/plugins/context/skills/web-src/types.ts +85 -0
- package/plugins/context/thinking-intensity/package.json +201 -0
- package/plugins/context/thinking-intensity/src/index.ts +285 -0
- package/plugins/context/thinking-intensity/src/mapping.ts +175 -0
- package/plugins/context/thinking-intensity/src/state.ts +134 -0
- package/plugins/evals/harness/package.json +32 -0
- package/plugins/evals/harness/src/assertions.ts +99 -0
- package/plugins/evals/harness/src/errors.ts +23 -0
- package/plugins/evals/harness/src/index.ts +48 -0
- package/plugins/evals/harness/src/mock-provider.ts +64 -0
- package/plugins/evals/harness/src/plugin.ts +48 -0
- package/plugins/evals/harness/src/report.ts +66 -0
- package/plugins/evals/harness/src/runner.ts +417 -0
- package/plugins/evals/harness/src/suite.ts +352 -0
- package/plugins/evals/harness/src/types.ts +154 -0
- package/plugins/fleet/compose/README.md +40 -0
- package/plugins/fleet/compose/package.json +172 -0
- package/plugins/fleet/compose/src/cli.ts +347 -0
- package/plugins/fleet/compose/src/i18n.ts +99 -0
- package/plugins/fleet/compose/src/index.ts +3 -0
- package/plugins/fleet/compose/src/manifest.ts +194 -0
- package/plugins/im/feishu/FEISHU.md +142 -0
- package/plugins/im/feishu/package.json +33 -0
- package/plugins/im/feishu/src/channel.ts +360 -0
- package/plugins/im/feishu/src/config.ts +133 -0
- package/plugins/im/feishu/src/dedupe.ts +30 -0
- package/plugins/im/feishu/src/errors.ts +21 -0
- package/plugins/im/feishu/src/index.ts +47 -0
- package/plugins/im/feishu/src/messages.ts +41 -0
- package/plugins/im/feishu/src/queue.ts +71 -0
- package/plugins/im/feishu/src/runner.ts +356 -0
- package/plugins/im/feishu/src/sdk-transport.ts +220 -0
- package/plugins/im/feishu/src/text.ts +56 -0
- package/plugins/im/feishu/src/types.ts +150 -0
- package/plugins/marketplace/marketplace/package.json +166 -0
- package/plugins/marketplace/marketplace/registry-template/README.md +105 -0
- package/plugins/marketplace/marketplace/registry-template/index.sample.json +71 -0
- package/plugins/marketplace/marketplace/registry-template/validate.mjs +272 -0
- package/plugins/marketplace/marketplace/registry-template/validate.yml +35 -0
- package/plugins/marketplace/marketplace/src/config-lock.ts +325 -0
- package/plugins/marketplace/marketplace/src/config.ts +432 -0
- package/plugins/marketplace/marketplace/src/errors.ts +79 -0
- package/plugins/marketplace/marketplace/src/index.ts +364 -0
- package/plugins/marketplace/marketplace/src/install.ts +930 -0
- package/plugins/marketplace/marketplace/src/jobs.ts +155 -0
- package/plugins/marketplace/marketplace/src/registry.ts +508 -0
- package/plugins/marketplace/marketplace/src/semver.ts +162 -0
- package/plugins/marketplace/marketplace/src/settings.ts +108 -0
- package/plugins/marketplace/marketplace/src/tar.ts +269 -0
- package/plugins/marketplace/marketplace/tsconfig.ui.json +26 -0
- package/plugins/marketplace/marketplace/vite.config.ts +107 -0
- package/plugins/marketplace/marketplace/web/assets/index-B2V7bx73.css +2 -0
- package/plugins/marketplace/marketplace/web/assets/index-B4NAz59m.js +13 -0
- package/plugins/marketplace/marketplace/web/index.html +13 -0
- package/plugins/marketplace/marketplace/web-src/App.tsx +193 -0
- package/plugins/marketplace/marketplace/web-src/api.ts +153 -0
- package/plugins/marketplace/marketplace/web-src/catalog.ts +27 -0
- package/plugins/marketplace/marketplace/web-src/components/ConfirmDialog.tsx +96 -0
- package/plugins/marketplace/marketplace/web-src/components/InstalledTable.tsx +152 -0
- package/plugins/marketplace/marketplace/web-src/components/JobStatus.tsx +70 -0
- package/plugins/marketplace/marketplace/web-src/components/Permissions.tsx +116 -0
- package/plugins/marketplace/marketplace/web-src/components/RegistryBanners.tsx +22 -0
- package/plugins/marketplace/marketplace/web-src/components/RegistrySetup.tsx +69 -0
- package/plugins/marketplace/marketplace/web-src/components/States.tsx +97 -0
- package/plugins/marketplace/marketplace/web-src/i18n.ts +337 -0
- package/plugins/marketplace/marketplace/web-src/index.html +12 -0
- package/plugins/marketplace/marketplace/web-src/main.tsx +17 -0
- package/plugins/marketplace/marketplace/web-src/styles.css +37 -0
- package/plugins/marketplace/marketplace/web-src/types.ts +175 -0
- package/plugins/marketplace/marketplace/web-src/views/InstalledView.tsx +150 -0
- package/plugins/marketplace/marketplace/web-src/views/MarketplaceView.tsx +479 -0
- package/plugins/marketplace/marketplace/web-src/views/UpdatesView.tsx +207 -0
- package/plugins/marketplace/marketplace/web-src/vite-env.d.ts +1 -0
- package/plugins/mcp/client/package.json +31 -0
- package/plugins/mcp/client/src/config-validate.ts +37 -0
- package/plugins/mcp/client/src/http-transport.ts +369 -0
- package/plugins/mcp/client/src/index.ts +35 -0
- package/plugins/mcp/client/src/json-rpc.ts +104 -0
- package/plugins/mcp/client/src/logging.ts +51 -0
- package/plugins/mcp/client/src/naming.ts +36 -0
- package/plugins/mcp/client/src/plugin.ts +310 -0
- package/plugins/mcp/client/src/registration.ts +143 -0
- package/plugins/mcp/client/src/server-connection.ts +556 -0
- package/plugins/mcp/client/src/stdio-transport.ts +377 -0
- package/plugins/mcp/client/src/transport.ts +11 -0
- package/plugins/mcp/client/src/types.ts +147 -0
- package/plugins/media/media/package.json +33 -0
- package/plugins/media/media/src/binaries.ts +88 -0
- package/plugins/media/media/src/config.ts +184 -0
- package/plugins/media/media/src/exec.ts +172 -0
- package/plugins/media/media/src/index.ts +125 -0
- package/plugins/media/media/src/tool.ts +640 -0
- package/plugins/observability/hook-logging/package.json +31 -0
- package/plugins/observability/hook-logging/src/index.ts +286 -0
- package/plugins/observability/usage/package.json +163 -0
- package/plugins/observability/usage/src/aggregate.ts +919 -0
- package/plugins/observability/usage/src/index.ts +362 -0
- package/plugins/observability/usage/src/query.ts +322 -0
- package/plugins/observability/usage/src/store.ts +1455 -0
- package/plugins/observability/usage/src/worker-client.ts +263 -0
- package/plugins/observability/usage/src/worker.ts +87 -0
- package/plugins/observability/usage/tsconfig.web.json +29 -0
- package/plugins/observability/usage/vite.config.embed.ts +105 -0
- package/plugins/observability/usage/vite.config.ts +121 -0
- package/plugins/observability/usage/web/assets/main-DD4g5VDL.css +2 -0
- package/plugins/observability/usage/web/assets/main-DVmWaf73.js +10 -0
- package/plugins/observability/usage/web/embed/index.css +3 -0
- package/plugins/observability/usage/web/embed/index.mjs +4560 -0
- package/plugins/observability/usage/web/logs.html +13 -0
- package/plugins/observability/usage/web/usage.html +13 -0
- package/plugins/observability/usage/web-src/App.tsx +54 -0
- package/plugins/observability/usage/web-src/LogsView.tsx +505 -0
- package/plugins/observability/usage/web-src/ModelTable.tsx +102 -0
- package/plugins/observability/usage/web-src/UsageView.tsx +210 -0
- package/plugins/observability/usage/web-src/embed.css +96 -0
- package/plugins/observability/usage/web-src/embed.tsx +75 -0
- package/plugins/observability/usage/web-src/env.d.ts +2 -0
- package/plugins/observability/usage/web-src/format.ts +88 -0
- package/plugins/observability/usage/web-src/i18n.ts +261 -0
- package/plugins/observability/usage/web-src/logs.html +12 -0
- package/plugins/observability/usage/web-src/main.tsx +19 -0
- package/plugins/observability/usage/web-src/shared.tsx +187 -0
- package/plugins/observability/usage/web-src/styles.css +22 -0
- package/plugins/observability/usage/web-src/usage.html +12 -0
- package/plugins/provider/anthropic/package.json +31 -0
- package/plugins/provider/anthropic/src/index.ts +75 -0
- package/plugins/provider/anthropic/src/retry.ts +266 -0
- package/plugins/provider/anthropic/src/timeout.ts +84 -0
- package/plugins/provider/model-registry/package.json +167 -0
- package/plugins/provider/model-registry/src/connectivity.ts +123 -0
- package/plugins/provider/model-registry/src/credential-store.ts +219 -0
- package/plugins/provider/model-registry/src/index.ts +453 -0
- package/plugins/provider/model-registry/src/registry-store.ts +223 -0
- package/plugins/provider/model-registry/tsconfig.web.json +29 -0
- package/plugins/provider/model-registry/vite.config.embed.ts +105 -0
- package/plugins/provider/model-registry/vite.config.ts +122 -0
- package/plugins/provider/model-registry/web/assets/main-BofPzD0n.js +10 -0
- package/plugins/provider/model-registry/web/assets/main-DkpGgdsZ.css +2 -0
- package/plugins/provider/model-registry/web/credentials.html +13 -0
- package/plugins/provider/model-registry/web/embed/index.css +3 -0
- package/plugins/provider/model-registry/web/embed/index.mjs +4887 -0
- package/plugins/provider/model-registry/web/models.html +13 -0
- package/plugins/provider/model-registry/web-src/App.tsx +54 -0
- package/plugins/provider/model-registry/web-src/CredentialsView.tsx +357 -0
- package/plugins/provider/model-registry/web-src/ModelForm.tsx +489 -0
- package/plugins/provider/model-registry/web-src/ModelsView.tsx +383 -0
- package/plugins/provider/model-registry/web-src/credentials.html +12 -0
- package/plugins/provider/model-registry/web-src/embed.css +96 -0
- package/plugins/provider/model-registry/web-src/embed.tsx +43 -0
- package/plugins/provider/model-registry/web-src/env.d.ts +2 -0
- package/plugins/provider/model-registry/web-src/i18n.ts +323 -0
- package/plugins/provider/model-registry/web-src/main.tsx +21 -0
- package/plugins/provider/model-registry/web-src/models.html +12 -0
- package/plugins/provider/model-registry/web-src/shared.tsx +147 -0
- package/plugins/provider/model-registry/web-src/styles.css +22 -0
- package/plugins/provider/model-registry/web-src/types.ts +120 -0
- package/plugins/provider/openai/package.json +31 -0
- package/plugins/provider/openai/src/index.ts +104 -0
- package/plugins/provider/openai/src/retry.ts +266 -0
- package/plugins/provider/openai/src/timeout.ts +84 -0
- package/plugins/provider/openai/src/vision.ts +121 -0
- package/plugins/security/guardrail-pii/package.json +31 -0
- package/plugins/security/guardrail-pii/src/index.ts +285 -0
- package/plugins/security/guardrail-pii/src/rules.ts +197 -0
- package/plugins/security/redact-secrets/package.json +31 -0
- package/plugins/security/redact-secrets/src/index.ts +145 -0
- package/plugins/security/redact-secrets/src/redactor.ts +83 -0
- package/plugins/security/redact-secrets/src/rules.ts +137 -0
- package/plugins/security/tool-policy/package.json +31 -0
- package/plugins/security/tool-policy/src/index.ts +184 -0
- package/plugins/tools/basic-tools/package.json +32 -0
- package/plugins/tools/basic-tools/src/background-jobs.ts +356 -0
- package/plugins/tools/basic-tools/src/bash-source.ts +58 -0
- package/plugins/tools/basic-tools/src/call-scope.ts +80 -0
- package/plugins/tools/basic-tools/src/config.ts +130 -0
- package/plugins/tools/basic-tools/src/index.ts +202 -0
- package/plugins/tools/basic-tools/src/path-boundary.ts +258 -0
- package/plugins/tools/basic-tools/src/shared.ts +221 -0
- package/plugins/tools/basic-tools/src/text.ts +49 -0
- package/plugins/tools/basic-tools/src/tools/bash-async.ts +1830 -0
- package/plugins/tools/basic-tools/src/tools/bash-exec.ts +567 -0
- package/plugins/tools/basic-tools/src/tools/bash.ts +300 -0
- package/plugins/tools/basic-tools/src/tools/edit.ts +160 -0
- package/plugins/tools/basic-tools/src/tools/grep.ts +601 -0
- package/plugins/tools/basic-tools/src/tools/read.ts +151 -0
- package/plugins/tools/basic-tools/src/tools/write.ts +494 -0
- package/plugins/tools/basic-tools/src/write-coord.ts +291 -0
- package/plugins/tools/basic-tools/src/write-lock.ts +353 -0
- package/plugins/tools/engine-client/package.json +34 -0
- package/plugins/tools/engine-client/src/client.ts +276 -0
- package/plugins/tools/engine-client/src/forward.ts +164 -0
- package/plugins/tools/engine-client/src/index.ts +18 -0
- package/plugins/tools/engine-client/src/pending.ts +101 -0
- package/plugins/tools/engine-client/src/pool.ts +1173 -0
- package/plugins/tools/engine-client/src/protocol.ts +249 -0
- package/plugins/tools/engine-client/src/registry.ts +138 -0
- package/plugins/tools/file-refs/README.md +68 -0
- package/plugins/tools/file-refs/package.json +135 -0
- package/plugins/tools/file-refs/src/index.ts +24 -0
- package/plugins/tools/file-refs/tsconfig.web.json +27 -0
- package/plugins/tools/file-refs/vite.config.embed.ts +88 -0
- package/plugins/tools/file-refs/web/embed/index.css +3 -0
- package/plugins/tools/file-refs/web/embed/index.mjs +879 -0
- package/plugins/tools/file-refs/web-src/AttachSheet.tsx +613 -0
- package/plugins/tools/file-refs/web-src/FileRefCard.tsx +206 -0
- package/plugins/tools/file-refs/web-src/FileRefLinkCard.tsx +90 -0
- package/plugins/tools/file-refs/web-src/attach-handler.tsx +116 -0
- package/plugins/tools/file-refs/web-src/attach-paths.ts +69 -0
- package/plugins/tools/file-refs/web-src/drop-handler.ts +15 -0
- package/plugins/tools/file-refs/web-src/embed.css +518 -0
- package/plugins/tools/file-refs/web-src/embed.tsx +18 -0
- package/plugins/tools/file-refs/web-src/env.d.ts +2 -0
- package/plugins/tools/file-refs/web-src/i18n.ts +137 -0
- package/plugins/tools/file-refs/web-src/icons.tsx +122 -0
- package/plugins/tools/file-refs/web-src/staging.ts +120 -0
- package/plugins/tools/file-refs/web-src/thumbnail.tsx +36 -0
- package/plugins/tools/recall/package.json +31 -0
- package/plugins/tools/recall/src/config.ts +74 -0
- package/plugins/tools/recall/src/index.ts +151 -0
- package/plugins/tools/recall/src/tool.ts +307 -0
- package/plugins/tools/web-tools/README.md +330 -0
- package/plugins/tools/web-tools/package.json +184 -0
- package/plugins/tools/web-tools/src/backends.ts +61 -0
- package/plugins/tools/web-tools/src/budget.ts +80 -0
- package/plugins/tools/web-tools/src/cache.ts +94 -0
- package/plugins/tools/web-tools/src/config.ts +412 -0
- package/plugins/tools/web-tools/src/deepseek-client.ts +406 -0
- package/plugins/tools/web-tools/src/deepseek-fetch.ts +168 -0
- package/plugins/tools/web-tools/src/extract.ts +373 -0
- package/plugins/tools/web-tools/src/fetch/local.ts +36 -0
- package/plugins/tools/web-tools/src/fetch/provider.ts +56 -0
- package/plugins/tools/web-tools/src/http.ts +415 -0
- package/plugins/tools/web-tools/src/index.ts +649 -0
- package/plugins/tools/web-tools/src/limits.ts +388 -0
- package/plugins/tools/web-tools/src/provider-http.ts +102 -0
- package/plugins/tools/web-tools/src/render.ts +248 -0
- package/plugins/tools/web-tools/src/robots.ts +187 -0
- package/plugins/tools/web-tools/src/search/custom.ts +595 -0
- package/plugins/tools/web-tools/src/search/deepseek.ts +111 -0
- package/plugins/tools/web-tools/src/search/index.ts +725 -0
- package/plugins/tools/web-tools/src/search/provider.ts +200 -0
- package/plugins/tools/web-tools/src/search/serper.ts +157 -0
- package/plugins/tools/web-tools/src/search/tavily.ts +146 -0
- package/plugins/tools/web-tools/src/secrets.ts +87 -0
- package/plugins/tools/web-tools/src/ssrf.ts +287 -0
- package/plugins/tools/web-tools/src/types.ts +137 -0
- package/skills/code-writing.md +33 -0
- package/src/agent/agent-control.ts +409 -0
- package/src/agent/agent-owner-client.ts +150 -0
- package/src/agent/agent-owner-server.ts +689 -0
- package/src/agent/agent-service-wiring.ts +675 -0
- package/src/agent/agent-wiring.ts +48 -0
- package/src/agent/ask-answer-delivery.ts +215 -0
- package/src/agent/local-run-adapter.ts +335 -0
- package/src/agent/peer-notices.ts +459 -0
- package/src/agent/peer-source.ts +63 -0
- package/src/agent/self-card.ts +52 -0
- package/src/agent/team-human-delivery.ts +144 -0
- package/src/assembly/collect.ts +161 -0
- package/src/assembly/feature.ts +133 -0
- package/src/assembly/features/attachments.ts +38 -0
- package/src/assembly/features/fleet.ts +31 -0
- package/src/assembly/features/jobs.ts +32 -0
- package/src/assembly/features/kanban.ts +56 -0
- package/src/assembly/features/restart.ts +35 -0
- package/src/assembly/features/subscription.ts +32 -0
- package/src/assembly/features.ts +30 -0
- package/src/cli/agent-call.ts +107 -0
- package/src/cli/args.ts +551 -0
- package/src/cli/ask-channel.ts +447 -0
- package/src/cli/command-spec/agent.ts +306 -0
- package/src/cli/command-spec/config.ts +179 -0
- package/src/cli/command-spec/define.ts +86 -0
- package/src/cli/command-spec/federation.ts +333 -0
- package/src/cli/command-spec/flags.ts +668 -0
- package/src/cli/command-spec/gateway.ts +350 -0
- package/src/cli/command-spec/hub.ts +290 -0
- package/src/cli/command-spec/kanban.ts +134 -0
- package/src/cli/command-spec/misc.ts +1032 -0
- package/src/cli/command-spec/model.ts +338 -0
- package/src/cli/command-spec/node.ts +160 -0
- package/src/cli/command-spec/plugin.ts +148 -0
- package/src/cli/command-spec/shared.ts +86 -0
- package/src/cli/command-spec/team.ts +582 -0
- package/src/cli/command-spec/token.ts +111 -0
- package/src/cli/command-spec.ts +270 -0
- package/src/cli/command-support.ts +53 -0
- package/src/cli/commands/agent/agent-command.ts +279 -0
- package/src/cli/commands/agent/agent-inbox-command.ts +141 -0
- package/src/cli/commands/agent/agents-command.ts +145 -0
- package/src/cli/commands/attention.ts +896 -0
- package/src/cli/commands/cli-update.ts +283 -0
- package/src/cli/commands/completion-command.ts +29 -0
- package/src/cli/commands/config-command.ts +545 -0
- package/src/cli/commands/dev-command.ts +429 -0
- package/src/cli/commands/doctor-command.ts +873 -0
- package/src/cli/commands/doctor-fleet.ts +410 -0
- package/src/cli/commands/errors-command.ts +469 -0
- package/src/cli/commands/eval-command.ts +168 -0
- package/src/cli/commands/federation-pair.ts +426 -0
- package/src/cli/commands/federation-peer.ts +445 -0
- package/src/cli/commands/federation.ts +527 -0
- package/src/cli/commands/fleet/fleet-inventory.ts +222 -0
- package/src/cli/commands/fleet/fleet-status-command.ts +433 -0
- package/src/cli/commands/fleet/ps-command.ts +387 -0
- package/src/cli/commands/fleet/restart-command.ts +745 -0
- package/src/cli/commands/fleet/start-command.ts +176 -0
- package/src/cli/commands/fleet/status-command.ts +318 -0
- package/src/cli/commands/fleet/stop-command.ts +548 -0
- package/src/cli/commands/gateway/gateway-command.ts +4204 -0
- package/src/cli/commands/gateway/gateway-nodes-command.ts +401 -0
- package/src/cli/commands/hub-command.ts +1007 -0
- package/src/cli/commands/kanban-command.ts +204 -0
- package/src/cli/commands/logs-command.ts +148 -0
- package/src/cli/commands/migrate-command.ts +131 -0
- package/src/cli/commands/model.ts +427 -0
- package/src/cli/commands/node-command.ts +805 -0
- package/src/cli/commands/permission/permission-show-command.ts +189 -0
- package/src/cli/commands/plugin/plugin-cli-command.ts +831 -0
- package/src/cli/commands/plugin/plugin-cli-local.ts +267 -0
- package/src/cli/commands/plugin/plugin-command.ts +407 -0
- package/src/cli/commands/prune-command.ts +233 -0
- package/src/cli/commands/resume-command.ts +100 -0
- package/src/cli/commands/rpc-command.ts +226 -0
- package/src/cli/commands/session/session-status-command.ts +352 -0
- package/src/cli/commands/team-command.ts +722 -0
- package/src/cli/commands/token-command.ts +494 -0
- package/src/cli/commands/trace-command.ts +133 -0
- package/src/cli/completion-script.ts +627 -0
- package/src/cli/completion-spec.ts +101 -0
- package/src/cli/control-plane-target.ts +295 -0
- package/src/cli/control-plane-types.ts +189 -0
- package/src/cli/feishu-command.ts +45 -0
- package/src/cli/headless-runner.ts +354 -0
- package/src/cli/help-search.ts +320 -0
- package/src/cli/help.ts +489 -0
- package/src/cli/output.ts +141 -0
- package/src/cli/parse-engine.ts +701 -0
- package/src/cli/parse-validators.ts +155 -0
- package/src/cli/project.ts +355 -0
- package/src/cli/registry.ts +25 -0
- package/src/cli.ts +2272 -0
- package/src/config/cli-overrides.ts +74 -0
- package/src/config/config-error-format.ts +44 -0
- package/src/config/config-snapshot.ts +15 -0
- package/src/config/config-watch.ts +436 -0
- package/src/config/config-write-apply.ts +98 -0
- package/src/config/empty-response-settings.ts +49 -0
- package/src/config/hot-apply-appliers.ts +527 -0
- package/src/config/hot-apply-assembly.ts +317 -0
- package/src/config/legacy-tool-names.ts +48 -0
- package/src/config/permission-defaults.ts +26 -0
- package/src/config/ui-settings.ts +568 -0
- package/src/config/vision-settings.ts +98 -0
- package/src/data/attachment-ingest.ts +101 -0
- package/src/data/attachment-staging.ts +377 -0
- package/src/data/attachments-list.ts +240 -0
- package/src/data/auto-prune.ts +342 -0
- package/src/data/data-lock.ts +580 -0
- package/src/data/data-paths.ts +265 -0
- package/src/data/image-blob-gc.ts +341 -0
- package/src/data/migrate.ts +480 -0
- package/src/data/path-resolution.ts +172 -0
- package/src/data/permission-store.ts +322 -0
- package/src/data/prune-wiring.ts +1037 -0
- package/src/data/refs-notice-hook.ts +417 -0
- package/src/federation/attention-client.ts +196 -0
- package/src/federation/attention-nodes.ts +142 -0
- package/src/federation/federation-address.ts +276 -0
- package/src/federation/federation-client.ts +620 -0
- package/src/federation/federation-config.ts +222 -0
- package/src/federation/federation-outbox.ts +374 -0
- package/src/federation/federation-pair-store.ts +236 -0
- package/src/federation/federation-pairing.ts +176 -0
- package/src/federation/federation-peer-store.ts +145 -0
- package/src/federation/federation-secrets.ts +140 -0
- package/src/federation/federation-send-port.ts +436 -0
- package/src/gateway/clean-spawn.ts +260 -0
- package/src/gateway/daemon.ts +336 -0
- package/src/gateway/fleet-index.ts +262 -0
- package/src/gateway/gateway-banner.ts +199 -0
- package/src/gateway/gateway-config-control.ts +53 -0
- package/src/gateway/gateway-reload-wiring.ts +512 -0
- package/src/gateway/gateway-wiring.ts +113 -0
- package/src/gateway/handoff.ts +131 -0
- package/src/gateway/instance-lock.ts +244 -0
- package/src/gateway/interactions-dir.ts +27 -0
- package/src/gateway/node-listen.ts +123 -0
- package/src/gateway/node-registry.ts +401 -0
- package/src/gateway/node-supervisor.ts +2226 -0
- package/src/gateway/pid.ts +827 -0
- package/src/gateway/pool-supervisor.ts +1150 -0
- package/src/gateway/reload.ts +238 -0
- package/src/gateway/restart-stop-exemption.ts +43 -0
- package/src/gateway/self-restart.ts +147 -0
- package/src/gateway/serve-auth.ts +184 -0
- package/src/gateway/serve-config.ts +135 -0
- package/src/gateway/service.ts +361 -0
- package/src/gateway/shutdown-report.ts +47 -0
- package/src/gateway/shutdown-sequence.ts +70 -0
- package/src/gateway/stop-drain.ts +299 -0
- package/src/gateway/stop-nodes-marker.ts +151 -0
- package/src/gateway/transport-factory.ts +53 -0
- package/src/gateway/watchdog.ts +622 -0
- package/src/gateway/web-dist.ts +1155 -0
- package/src/hub/client-protocol.ts +43 -0
- package/src/hub/derive-origins.ts +193 -0
- package/src/hub/hub-wiring.ts +310 -0
- package/src/hub/inbound-control.ts +432 -0
- package/src/hub/join-policy.ts +75 -0
- package/src/hub/join-store.ts +243 -0
- package/src/hub/node-credential-store.ts +295 -0
- package/src/hub/node-state.ts +279 -0
- package/src/hub/node-url.ts +33 -0
- package/src/hub/outbound-client.ts +509 -0
- package/src/hub/outbound-wiring.ts +168 -0
- package/src/hub/pairing-code.ts +27 -0
- package/src/hub/registry.ts +575 -0
- package/src/hub/runtime.ts +599 -0
- package/src/hub/secret-store.ts +571 -0
- package/src/hub/server.ts +1032 -0
- package/src/hub/snapshot-policy.ts +67 -0
- package/src/hub/types.ts +258 -0
- package/src/i18n/index.ts +94 -0
- package/src/i18n/messages/en.ts +1462 -0
- package/src/i18n/messages/zh-CN.ts +1323 -0
- package/src/mock/scenarios.ts +165 -0
- package/src/node/node-auto-resume.ts +264 -0
- package/src/node/node-drain.ts +520 -0
- package/src/node/node-identity.ts +240 -0
- package/src/node/node-resume.ts +511 -0
- package/src/node/resume-scan.ts +97 -0
- package/src/node/token-derive.ts +504 -0
- package/src/observability/logging.ts +72 -0
- package/src/observability/observability-wiring.ts +82 -0
- package/src/observability/startup-timing.ts +151 -0
- package/src/observability/trace-wiring.ts +250 -0
- package/src/observability/usage-pricing.ts +80 -0
- package/src/plugin/eval-wiring.ts +175 -0
- package/src/plugin/feishu-wiring.ts +250 -0
- package/src/plugin/mcp-wiring.ts +200 -0
- package/src/plugin/plugin-config.ts +491 -0
- package/src/plugin/plugin-host-assembly.ts +448 -0
- package/src/plugin/plugin-lifecycle.ts +130 -0
- package/src/plugin/plugin-loader.ts +788 -0
- package/src/plugin/plugin-manifest.ts +1936 -0
- package/src/plugin/plugin-selection.ts +200 -0
- package/src/plugin/plugin-surface.ts +207 -0
- package/src/plugin/plugin-watch.ts +114 -0
- package/src/rpc/http-client.ts +579 -0
- package/src/rpc/index.ts +34 -0
- package/src/rpc/local-client.ts +55 -0
- package/src/rpc/types.ts +125 -0
- package/src/run/connect-run-wait.ts +544 -0
- package/src/run/durable-wiring.ts +133 -0
- package/src/run/lease-service.ts +510 -0
- package/src/run/run-control.ts +160 -0
- package/src/run/run-record-store-factory.ts +89 -0
- package/src/runtime/agent-activity-watch.ts +335 -0
- package/src/runtime/agent-assembly.ts +818 -0
- package/src/runtime/agent-events-bridge.ts +86 -0
- package/src/runtime/bash-job-delivery.ts +291 -0
- package/src/runtime/bootstrap-connect.ts +644 -0
- package/src/runtime/bootstrap-types.ts +303 -0
- package/src/runtime/bootstrap.ts +1020 -0
- package/src/runtime/bus-source.ts +62 -0
- package/src/runtime/gc-assembly.ts +214 -0
- package/src/runtime/local-rpc-surface.ts +301 -0
- package/src/runtime/model-registry-wiring.ts +653 -0
- package/src/runtime/node-health-watch.ts +484 -0
- package/src/runtime/node-restart.ts +444 -0
- package/src/runtime/process-handlers.ts +164 -0
- package/src/runtime/provider-factory.ts +86 -0
- package/src/runtime/reasoning.ts +47 -0
- package/src/runtime/repl-context.ts +234 -0
- package/src/runtime/runtime-notice-hook.ts +357 -0
- package/src/runtime/runtime-notice.ts +273 -0
- package/src/runtime/session-id.ts +15 -0
- package/src/runtime/shutdown-sequence.ts +429 -0
- package/src/runtime/subscription-mute-bridge.ts +99 -0
- package/src/runtime/subscription-rpc-port.ts +597 -0
- package/src/runtime/team-log-bridge.ts +46 -0
- package/src/runtime/tenant-runtime-factory.ts +1838 -0
- package/src/runtime/thinking-agent-bridge.ts +57 -0
- package/src/runtime/tool-output-env.ts +80 -0
- package/src/runtime/vessel-meta.ts +338 -0
- package/src/session/context-composition.ts +147 -0
- package/src/session/context-ratio-source.ts +165 -0
- package/src/session/context-usage.ts +346 -0
- package/src/session/image-delivery.ts +297 -0
- package/src/session/session-control.ts +135 -0
- package/src/session/session-events.ts +144 -0
- package/src/session/session-factory.ts +73 -0
- package/src/session/session-liveness.ts +405 -0
- package/src/session/session-lock-runtime.ts +64 -0
- package/src/session/session-lock.ts +399 -0
- package/src/session/session-resume.ts +282 -0
- package/src/session/system-context.ts +235 -0
- package/src/session/timeline-dual-write.ts +2129 -0
- package/src/session/timeline-session-log.ts +140 -0
- package/src/shared/port-in-use.ts +27 -0
- package/src/shared/socket-inherit-guard.ts +13 -0
- package/src/shared/version.ts +38 -0
- package/src/tools-engine/engine.ts +286 -0
- package/src/tools-engine/entry.ts +757 -0
- package/src/tools-engine/mcp-engine-wiring.ts +354 -0
- package/src/tools-engine/mcp.ts +324 -0
- package/src/tools-engine/supervisor.ts +234 -0
- package/src/tools-engine/tools-list.ts +148 -0
- package/src/tools-engine/validate.ts +395 -0
- package/src/tools-engine/wiring.ts +88 -0
- package/src/tools-engine/worker.ts +110 -0
- package/src/update/background.ts +64 -0
- package/src/update/cache.ts +70 -0
- package/src/update/check.ts +138 -0
- package/src/update/gateway-check.ts +231 -0
- package/src/update/install-detect.ts +125 -0
- package/src/update/manifest.ts +132 -0
- package/src/update/semver.ts +70 -0
- package/src/update/stage.ts +219 -0
|
@@ -0,0 +1,1148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 0.49 G1:Platform Gateway 独立监听。
|
|
3
|
+
*
|
|
4
|
+
* 单一 `Bun.serve`:静态宿主 + `/health` + `POST /platform/rpc`。
|
|
5
|
+
* 路由表与 node 完全分离:`/v1/*`、`/plugins/*`、`/ws`、`/sse` 一律 404,不反代。
|
|
6
|
+
*
|
|
7
|
+
* @module @vessel-agent/serve/platform/server
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { existsSync } from 'node:fs';
|
|
11
|
+
import { resolve } from 'node:path';
|
|
12
|
+
import { guardListenerInheritance } from '@vessel-agent/core/socket-inherit-guard';
|
|
13
|
+
import { type AuthRequestContext, AuthService } from '../auth/index.js';
|
|
14
|
+
import {
|
|
15
|
+
buildContentSecurityPolicy,
|
|
16
|
+
corsHeaders,
|
|
17
|
+
hostAllowed,
|
|
18
|
+
isLoopbackAddress,
|
|
19
|
+
normalizeAllowedOrigins,
|
|
20
|
+
normalizeOriginPattern,
|
|
21
|
+
type OriginPattern,
|
|
22
|
+
originAllowed,
|
|
23
|
+
parseOriginPattern,
|
|
24
|
+
resolveHttpAllowedOrigins,
|
|
25
|
+
resolveRequestEdge,
|
|
26
|
+
} from '../gateway/auth.js';
|
|
27
|
+
import { serveStatic } from '../gateway/static.js';
|
|
28
|
+
import { logEvent } from '../log-event.js';
|
|
29
|
+
import { runShutdownStep, SHUTDOWN_STEP_EVENT, type ShutdownStepEmit } from '../shutdown-step.js';
|
|
30
|
+
import { platformTokenMatches, platformUnauthorizedMessage, resolvePlatformAuth } from './auth.js';
|
|
31
|
+
import { platformListenGuard } from './listen-guard.js';
|
|
32
|
+
import { createPlatformMetrics } from './metrics.js';
|
|
33
|
+
import { PlatformProxy } from './proxy.js';
|
|
34
|
+
import { PROXY_BASE_PATH, parseProxyRoute } from './proxy-config.js';
|
|
35
|
+
import type { ProxyWsClient } from './proxy-ws.js';
|
|
36
|
+
import { createPlatformRegistry } from './registry.js';
|
|
37
|
+
import { handlePlatformRpc } from './rpc.js';
|
|
38
|
+
import type {
|
|
39
|
+
PlatformAuthOptions,
|
|
40
|
+
PlatformGateway,
|
|
41
|
+
PlatformGatewayOptions,
|
|
42
|
+
WebBuildProbe,
|
|
43
|
+
WebDistProbe,
|
|
44
|
+
WebDistProbeResult,
|
|
45
|
+
} from './types.js';
|
|
46
|
+
|
|
47
|
+
const PLATFORM_RPC_PATH = '/platform/rpc';
|
|
48
|
+
/** 0.57:静态构建戳 + 服务端现场判断(见 `buildJsonResponse`)。 */
|
|
49
|
+
const BUILD_JSON_PATH = '/build.json';
|
|
50
|
+
/** 0.57:产物变更推送(SSE);`/build.json` 仍是唯一事实源。 */
|
|
51
|
+
const BUILD_EVENTS_PATH = '/web/build/events';
|
|
52
|
+
/** 长连接是资源:超过这个数直接 503,前端退回轮询。 */
|
|
53
|
+
const BUILD_EVENTS_MAX_CONNECTIONS = 32;
|
|
54
|
+
/** 判定节拍(与 probe 缓存 TTL 对齐:不存在更快的真相)。 */
|
|
55
|
+
const BUILD_EVENTS_TICK_MS = 5_000;
|
|
56
|
+
/** 每 N 个节拍发一帧注释保活(25s),防中间层掐断空闲连接。 */
|
|
57
|
+
const BUILD_EVENTS_PING_TICKS = 5;
|
|
58
|
+
/** 告诉浏览器断线后多久重连(毫秒)。 */
|
|
59
|
+
const BUILD_EVENTS_RETRY_MS = 5_000;
|
|
60
|
+
/** 现场判断要遍历源码树;多个标签页同时轮询不必各走一遍。 */
|
|
61
|
+
const BUILD_PROBE_TTL_MS = 5_000;
|
|
62
|
+
/** 0.61:运行中自查的缺省间隔(60s)与下限(再密就是在烧 CPU 跑 tsc)。 */
|
|
63
|
+
const WEB_BUILD_CHECK_DEFAULT_MS = 60_000;
|
|
64
|
+
const WEB_BUILD_CHECK_MIN_MS = 5_000;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 0.58:平台入口的 WS 连接数据。目前只有一种:node 事件流代理。
|
|
68
|
+
*
|
|
69
|
+
* Bun 的 `websocket` handler 需要单一 `data` 类型;用 `kind` 判别便于将来加第二条通道
|
|
70
|
+
* (例如 hub 代理)时不用改类型。
|
|
71
|
+
*/
|
|
72
|
+
interface PlatformWsData {
|
|
73
|
+
kind: 'node-proxy';
|
|
74
|
+
bridge: import('./proxy-ws.js').ProxyWsBridge;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* node 独占路径:平台**根**入口一律 404(不代理、不转发)。
|
|
79
|
+
* plugin-embed 契约 §4 的唯一例外走 `/nodes/<nodeId>/` 代理前缀:
|
|
80
|
+
* `/plugins/<id>/ui/**` 的 embed 静态资源仅 GET / HEAD 经代理同源转发
|
|
81
|
+
* (proxy-config.ts 白名单);根 `/plugins/*` 仍然 404。
|
|
82
|
+
*/
|
|
83
|
+
function isNodeOnlyPath(path: string): boolean {
|
|
84
|
+
return (
|
|
85
|
+
path === '/v1' ||
|
|
86
|
+
path.startsWith('/v1/') ||
|
|
87
|
+
path === '/plugins' ||
|
|
88
|
+
path.startsWith('/plugins/') ||
|
|
89
|
+
path === '/ws' ||
|
|
90
|
+
path.startsWith('/ws/') ||
|
|
91
|
+
path === '/sse' ||
|
|
92
|
+
path.startsWith('/sse/')
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 平台自己拥有的路径前缀:不参与 SPA 兜底。
|
|
98
|
+
*
|
|
99
|
+
* 0.58 修的是既有 bug:`/health` 曾经排在静态兜底之后,于是返回 `index.html`(200 HTML),
|
|
100
|
+
* `gateway status` 因此对平台实例恒显示「身份未确认」。判据用前缀而不是逐个端点:
|
|
101
|
+
* 兜底只该服务**前端路由**(`/sessions/xxx` 这种),任何平台路径拿到 HTML 都是错的。
|
|
102
|
+
*/
|
|
103
|
+
const RESERVED_PLATFORM_PREFIXES: readonly string[] = [
|
|
104
|
+
'/platform/',
|
|
105
|
+
`${PROXY_BASE_PATH}/`,
|
|
106
|
+
'/auth/',
|
|
107
|
+
'/web/',
|
|
108
|
+
'/health',
|
|
109
|
+
'/metrics',
|
|
110
|
+
'/build.json',
|
|
111
|
+
];
|
|
112
|
+
|
|
113
|
+
function isReservedPlatformPath(path: string): boolean {
|
|
114
|
+
return RESERVED_PLATFORM_PREFIXES.some((prefix) => {
|
|
115
|
+
if (path === prefix) return true;
|
|
116
|
+
return path.startsWith(prefix.endsWith('/') ? prefix : `${prefix}/`);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 现场判断的缓存:TTL + 同一判定函数的并发请求共用一次遍历。
|
|
122
|
+
*
|
|
123
|
+
* 为什么缓存:`inspectWebDist` 会 stat 源码树里的每个文件(上限 5000),而
|
|
124
|
+
* `/build.json` 是**每个标签页每 10 秒**拉一次的。5 秒 TTL 让一次重建之后
|
|
125
|
+
* 的 `stale: false` 最迟 5 秒可见,同时把遍历频率压到与标签页数量无关。
|
|
126
|
+
*
|
|
127
|
+
* 判定失败 = 「未知」:返回 undefined,不缓存(下次重试);调用方只省掉实时字段,
|
|
128
|
+
* 静态构建戳照发 —— 前端按「无法判断」处理,不误报过期。
|
|
129
|
+
*/
|
|
130
|
+
function createWebDistProbeCache(): (
|
|
131
|
+
probe: WebDistProbe,
|
|
132
|
+
) => Promise<WebDistProbeResult | undefined> {
|
|
133
|
+
const cache = new WeakMap<WebDistProbe, { at: number; result: WebDistProbeResult }>();
|
|
134
|
+
const inFlight = new WeakMap<WebDistProbe, Promise<WebDistProbeResult | undefined>>();
|
|
135
|
+
return (probe) => {
|
|
136
|
+
const cached = cache.get(probe);
|
|
137
|
+
if (cached !== undefined && Date.now() - cached.at < BUILD_PROBE_TTL_MS) {
|
|
138
|
+
return Promise.resolve(cached.result);
|
|
139
|
+
}
|
|
140
|
+
const pending = inFlight.get(probe);
|
|
141
|
+
if (pending !== undefined) return pending;
|
|
142
|
+
const task = (async (): Promise<WebDistProbeResult | undefined> => {
|
|
143
|
+
try {
|
|
144
|
+
const result = await probe();
|
|
145
|
+
cache.set(probe, { at: Date.now(), result });
|
|
146
|
+
return result;
|
|
147
|
+
} catch {
|
|
148
|
+
return undefined;
|
|
149
|
+
} finally {
|
|
150
|
+
inFlight.delete(probe);
|
|
151
|
+
}
|
|
152
|
+
})();
|
|
153
|
+
inFlight.set(probe, task);
|
|
154
|
+
return task;
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* `/build.json` 的响应体:磁盘上的构建戳**原样保留**,再叠加服务端现场判断的
|
|
160
|
+
* `stale` / `newestSource` / `building`。
|
|
161
|
+
*
|
|
162
|
+
* 为什么必须现场算:产物过期(dist 比源码旧)时,浏览器里那份 bundle 与磁盘上的
|
|
163
|
+
* `build.json` 来自**同一次构建**,前端比对 `builtAt` 永远一致 —— 只有服务端把
|
|
164
|
+
* 「我知道 dist 落后于源码」说出来,顶部提示才可能响。
|
|
165
|
+
*
|
|
166
|
+
* `building`(0.58):后台重建**此刻**是否在跑。少了这一项,提示条会在构建进行中
|
|
167
|
+
* 让用户「刷新以加载新版本」—— 而刷新那一刻磁盘上还是旧产物,是句废话。
|
|
168
|
+
*
|
|
169
|
+
* (0.60):「在不在建 / 建成了没有 / 上一次为什么失败 / 日志在哪」全部来自
|
|
170
|
+
* **同一份**构建状态(组合根注入的 `webBuild`),平台不自己拼第二套话。
|
|
171
|
+
*
|
|
172
|
+
* 返回 null = 没有可用的构建戳(文件缺失 / 读坏 / JSON 非对象):HTTP 端点交给静态
|
|
173
|
+
* 兜底,保住旧行为;任何读盘失败都**不 500**(页面不能被一个诊断文件打挂)。
|
|
174
|
+
*/
|
|
175
|
+
async function buildJsonPayload(
|
|
176
|
+
staticDir: string,
|
|
177
|
+
probe: WebDistProbe | undefined,
|
|
178
|
+
probeCached: (probe: WebDistProbe) => Promise<WebDistProbeResult | undefined>,
|
|
179
|
+
webBuild: WebBuildProbe | undefined,
|
|
180
|
+
): Promise<Record<string, unknown> | null> {
|
|
181
|
+
let base: Record<string, unknown>;
|
|
182
|
+
try {
|
|
183
|
+
const file = Bun.file(resolve(staticDir, 'build.json'));
|
|
184
|
+
if (!(await file.exists())) return null;
|
|
185
|
+
const raw: unknown = await file.json();
|
|
186
|
+
if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) return null;
|
|
187
|
+
base = { ...(raw as Record<string, unknown>) };
|
|
188
|
+
} catch {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
// 构建状态**不走缓存**:缓存里那份可能是构建开始前的快照,会让提示条在构建结束
|
|
192
|
+
// 之后继续说「正在构建」。
|
|
193
|
+
const build = webBuild?.();
|
|
194
|
+
const building = build?.phase === 'running';
|
|
195
|
+
const live = probe === undefined ? undefined : await probeCached(probe);
|
|
196
|
+
const body: Record<string, unknown> = { ...base, building };
|
|
197
|
+
if (build !== undefined && build.phase !== 'idle') {
|
|
198
|
+
// 同一份状态的两个派生视图:`building`(老字段,前端提示条在用)+ `build`(新字段,
|
|
199
|
+
// 说清「哪一步、多久、成没成、日志在哪」)。两者永远指向同一次构建。
|
|
200
|
+
body.build = {
|
|
201
|
+
phase: build.phase,
|
|
202
|
+
...(build.startedAt !== undefined
|
|
203
|
+
? { startedAt: new Date(build.startedAt).toISOString() }
|
|
204
|
+
: {}),
|
|
205
|
+
...(building && build.startedAt !== undefined
|
|
206
|
+
? { elapsedMs: Math.max(0, Date.now() - build.startedAt) }
|
|
207
|
+
: {}),
|
|
208
|
+
...(build.pid !== undefined ? { pid: build.pid } : {}),
|
|
209
|
+
...(build.reason !== undefined ? { reason: build.reason } : {}),
|
|
210
|
+
...(build.trigger !== undefined ? { check: build.trigger } : {}),
|
|
211
|
+
...(build.logPath !== undefined ? { log: build.logPath } : {}),
|
|
212
|
+
...(build.last !== undefined
|
|
213
|
+
? {
|
|
214
|
+
last: {
|
|
215
|
+
phase: build.last.phase,
|
|
216
|
+
at: new Date(build.last.at).toISOString(),
|
|
217
|
+
durMs: build.last.durMs,
|
|
218
|
+
...(build.last.exitCode !== undefined ? { exit: build.last.exitCode } : {}),
|
|
219
|
+
...(build.last.signal !== undefined ? { signal: build.last.signal } : {}),
|
|
220
|
+
...(build.last.assets !== undefined ? { assets: build.last.assets } : {}),
|
|
221
|
+
...(build.last.bytes !== undefined ? { bytes: build.last.bytes } : {}),
|
|
222
|
+
...(build.last.logPath !== undefined ? { log: build.last.logPath } : {}),
|
|
223
|
+
},
|
|
224
|
+
}
|
|
225
|
+
: {}),
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
if (live !== undefined) {
|
|
229
|
+
body.stale = live.stale;
|
|
230
|
+
if (live.newestSource !== undefined) {
|
|
231
|
+
body.newestSource = {
|
|
232
|
+
path: live.newestSource.path,
|
|
233
|
+
mtime: new Date(live.newestSource.mtimeMs).toISOString(),
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return body;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** `/build.json` 的 HTTP 响应(`no-store`;HEAD 只要头)。 */
|
|
241
|
+
async function buildJsonResponse(
|
|
242
|
+
staticDir: string,
|
|
243
|
+
method: string,
|
|
244
|
+
probe: WebDistProbe | undefined,
|
|
245
|
+
probeCached: (probe: WebDistProbe) => Promise<WebDistProbeResult | undefined>,
|
|
246
|
+
webBuild: WebBuildProbe | undefined,
|
|
247
|
+
onStale?: () => void,
|
|
248
|
+
): Promise<Response | null> {
|
|
249
|
+
const body = await buildJsonPayload(staticDir, probe, probeCached, webBuild);
|
|
250
|
+
if (body === null) return null;
|
|
251
|
+
// 0.61:观测到「产物旧了、又没在构建」就在这里叫一次自查(组合根那侧限频 + 互斥)。
|
|
252
|
+
// 这一行**不打日志**:真正起构建时才有 `web.build.start check=probe`。
|
|
253
|
+
if (body.stale === true && body.building !== true) onStale?.();
|
|
254
|
+
const headers: Record<string, string> = {
|
|
255
|
+
'Content-Type': 'application/json;charset=utf-8',
|
|
256
|
+
// 这个文件就是用来感知变化的:命中缓存等于没查(静态兜底那条是 immutable 一年)。
|
|
257
|
+
'Cache-Control': 'no-store',
|
|
258
|
+
'X-Content-Type-Options': 'nosniff',
|
|
259
|
+
};
|
|
260
|
+
// HEAD 只要头:Bun 不会替我们吞掉 body。
|
|
261
|
+
if (method === 'HEAD') return new Response(null, { headers });
|
|
262
|
+
return new Response(JSON.stringify(body, null, 2), { headers });
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* 0.57:产物变更的**推送**通道(`GET /web/build/events`,SSE)。
|
|
267
|
+
*
|
|
268
|
+
* 为什么要有:轮询 `/build.json` 是「每个标签页每 10 秒一次」—— 一天 8,640 次请求、
|
|
269
|
+
* 最多 10 秒的感知延迟,而且日志与唤醒都被这些空请求泡着。推送只保留一条空闲长
|
|
270
|
+
* 连接,产物一变就是毫秒级送达;`/build.json` 仍是唯一事实源(这里推的就是它的
|
|
271
|
+
* 同一份 payload),SSE 断了前端退回轮询,不会因为推送挂掉而瞎。
|
|
272
|
+
*
|
|
273
|
+
* 有界:最多 {@link BUILD_EVENTS_MAX_CONNECTIONS} 条长连接,超了直接 503 让调用方
|
|
274
|
+
* 退回轮询;不接受请求体、不产生业务状态。判定由**一个**节拍器驱动(与 probe 缓存
|
|
275
|
+
* TTL 对齐),所以连接数再多,遍历源码树的频率也不变。
|
|
276
|
+
*/
|
|
277
|
+
interface BuildEventStream {
|
|
278
|
+
/** 打开一条流;超过上限返回 null(调用方回 503)。 */
|
|
279
|
+
open(): Promise<Response | null>;
|
|
280
|
+
/** 停服:断开全部连接并停掉节拍器。 */
|
|
281
|
+
close(): void;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function createBuildEventStream(options: {
|
|
285
|
+
staticDir: string;
|
|
286
|
+
probe: WebDistProbe | undefined;
|
|
287
|
+
probeCached: (probe: WebDistProbe) => Promise<WebDistProbeResult | undefined>;
|
|
288
|
+
/** 后台构建状态快照(见 `PlatformGatewayOptions.webBuild`)。 */
|
|
289
|
+
webBuild: WebBuildProbe | undefined;
|
|
290
|
+
}): BuildEventStream {
|
|
291
|
+
const encoder = new TextEncoder();
|
|
292
|
+
const clients = new Set<ReadableStreamDefaultController<Uint8Array>>();
|
|
293
|
+
let ticker: ReturnType<typeof setInterval> | undefined;
|
|
294
|
+
let lastBody: string | undefined;
|
|
295
|
+
|
|
296
|
+
const write = (controller: ReadableStreamDefaultController<Uint8Array>, chunk: string): void => {
|
|
297
|
+
try {
|
|
298
|
+
controller.enqueue(encoder.encode(chunk));
|
|
299
|
+
} catch {
|
|
300
|
+
// 客户端已经走了(反代断开 / 浏览器关闭):悄悄摘掉,不抛给节拍器。
|
|
301
|
+
clients.delete(controller);
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
const broadcast = (chunk: string): void => {
|
|
306
|
+
for (const controller of [...clients]) write(controller, chunk);
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
const bodyNow = async (): Promise<string | undefined> => {
|
|
310
|
+
const payload = await buildJsonPayload(
|
|
311
|
+
options.staticDir,
|
|
312
|
+
options.probe,
|
|
313
|
+
options.probeCached,
|
|
314
|
+
options.webBuild,
|
|
315
|
+
);
|
|
316
|
+
return payload === null ? undefined : JSON.stringify(payload);
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
const startTicker = (): void => {
|
|
320
|
+
if (ticker !== undefined) return;
|
|
321
|
+
let ticks = 0;
|
|
322
|
+
ticker = setInterval(() => {
|
|
323
|
+
void (async () => {
|
|
324
|
+
ticks += 1;
|
|
325
|
+
// 保活:中间层(反代 / 浏览器)会把长时间没有字节的流掐掉,注释帧零语义。
|
|
326
|
+
if (ticks % BUILD_EVENTS_PING_TICKS === 0) broadcast(': ping\n\n');
|
|
327
|
+
if (clients.size === 0) {
|
|
328
|
+
// 没人听了就停表:空转的遍历没有意义,下一条连接会重新拉起。
|
|
329
|
+
if (ticker !== undefined) {
|
|
330
|
+
clearInterval(ticker);
|
|
331
|
+
ticker = undefined;
|
|
332
|
+
}
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
const body = await bodyNow();
|
|
336
|
+
if (body === undefined || body === lastBody) return;
|
|
337
|
+
lastBody = body;
|
|
338
|
+
broadcast(`data: ${body}\n\n`);
|
|
339
|
+
})();
|
|
340
|
+
}, BUILD_EVENTS_TICK_MS);
|
|
341
|
+
ticker.unref?.();
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
return {
|
|
345
|
+
async open(): Promise<Response | null> {
|
|
346
|
+
if (clients.size >= BUILD_EVENTS_MAX_CONNECTIONS) return null;
|
|
347
|
+
const initial = await bodyNow();
|
|
348
|
+
let self: ReadableStreamDefaultController<Uint8Array> | undefined;
|
|
349
|
+
const stream = new ReadableStream<Uint8Array>({
|
|
350
|
+
start: (controller) => {
|
|
351
|
+
self = controller;
|
|
352
|
+
clients.add(controller);
|
|
353
|
+
startTicker();
|
|
354
|
+
// 首帧立刻给:连上就有当前真相,不必等下一次变化。
|
|
355
|
+
write(controller, `retry: ${BUILD_EVENTS_RETRY_MS}\n\n`);
|
|
356
|
+
if (initial !== undefined) {
|
|
357
|
+
// 只记第一次:别让后连上的客户端把它「回拨」成旧快照,否则同一份
|
|
358
|
+
// 内容会被重复推给所有人。
|
|
359
|
+
if (lastBody === undefined) lastBody = initial;
|
|
360
|
+
write(controller, `data: ${initial}\n\n`);
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
cancel: () => {
|
|
364
|
+
// 客户端断开(浏览器关闭 / 反代断流):只摘掉自己,不惊动其它连接。
|
|
365
|
+
if (self !== undefined) clients.delete(self);
|
|
366
|
+
},
|
|
367
|
+
});
|
|
368
|
+
return new Response(stream, {
|
|
369
|
+
headers: {
|
|
370
|
+
'Content-Type': 'text/event-stream; charset=utf-8',
|
|
371
|
+
'Cache-Control': 'no-store, no-transform',
|
|
372
|
+
Connection: 'keep-alive',
|
|
373
|
+
// nginx 默认会缓冲上游响应:SSE 必须显式关掉,否则事件攒到连接结束才到。
|
|
374
|
+
'X-Accel-Buffering': 'no',
|
|
375
|
+
'X-Content-Type-Options': 'nosniff',
|
|
376
|
+
},
|
|
377
|
+
});
|
|
378
|
+
},
|
|
379
|
+
close(): void {
|
|
380
|
+
if (ticker !== undefined) {
|
|
381
|
+
clearInterval(ticker);
|
|
382
|
+
ticker = undefined;
|
|
383
|
+
}
|
|
384
|
+
for (const controller of [...clients]) {
|
|
385
|
+
try {
|
|
386
|
+
controller.close();
|
|
387
|
+
} catch {
|
|
388
|
+
// 已经关掉的就不用再关。
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
clients.clear();
|
|
392
|
+
},
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* 0.55 P0:401 文案必须能直接照做 —— 分清「缺反代密钥」与「缺平台 token」。
|
|
398
|
+
* 仍然只用 CONTRACT §7 的 `platform_unauthorized` 错误码(Web 端据此弹「需要 token」)。
|
|
399
|
+
* 0.55 拍板项 2:文案与 `rpc.ts` 的凭据端点共用(见 `auth.ts`),避免两处口径漂移。
|
|
400
|
+
*/
|
|
401
|
+
function json(data: unknown, status: number, extra: Record<string, string>): Response {
|
|
402
|
+
return new Response(JSON.stringify(data), {
|
|
403
|
+
status,
|
|
404
|
+
headers: {
|
|
405
|
+
'Content-Type': 'application/json',
|
|
406
|
+
'Cache-Control': 'no-store',
|
|
407
|
+
'X-Content-Type-Options': 'nosniff',
|
|
408
|
+
...extra,
|
|
409
|
+
},
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
function errorJson(
|
|
414
|
+
code: string,
|
|
415
|
+
message: string,
|
|
416
|
+
status: number,
|
|
417
|
+
extra: Record<string, string>,
|
|
418
|
+
): Response {
|
|
419
|
+
return json({ error: { code, message } }, status, extra);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/** 0.56:没有任何 auth 配置时的等价物 —— 空后端 = 行为退回 0.55。 */
|
|
423
|
+
const DISABLED_AUTH: PlatformAuthOptions = {
|
|
424
|
+
publicOrigin: null,
|
|
425
|
+
publicOrigins: [],
|
|
426
|
+
allowedHosts: [],
|
|
427
|
+
backends: [],
|
|
428
|
+
session: { idleMinutes: 30, absoluteHours: 12 },
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* 配置了登录后端、但本次数据面请求没有会话。
|
|
433
|
+
*
|
|
434
|
+
* 文案刻意做成「可照做」的 —— 因为它就是 8644 那类 401 的自解释入口:
|
|
435
|
+
* - 指到**当前这个来源**的 `/login`。会话 cookie 按 host 区分,换 origin 就换会话 ——
|
|
436
|
+
* 「在 127.0.0.1 登录过、又打开公网域名」看起来就是「突然全部 401」;
|
|
437
|
+
* - 不再承诺「本机直连可以免登录」:`localDirect` 只在显式打开
|
|
438
|
+
* `auth.allow_loopback_anonymous` 后才可能为真(缺省 false)。没打开时它是**恒假**的
|
|
439
|
+
* —— 不看配置就承诺免登录,只会让排障方向跑偏。
|
|
440
|
+
* 见 gateway/auth.ts 的 `resolveRequestEdge`。
|
|
441
|
+
*
|
|
442
|
+
* 只给可点击的入口与事实,不给命令行。
|
|
443
|
+
*/
|
|
444
|
+
export function sessionRequiredMessage(origin: string | null): string {
|
|
445
|
+
const where = origin === null ? '本站根路径' : origin;
|
|
446
|
+
return (
|
|
447
|
+
'session_required: 这个部署启用了 WebUI 登录(auth.backends),数据面请求必须带会话。' +
|
|
448
|
+
`请在**当前这个来源**打开登录页(${where}/login)登录后再调用 —— ` +
|
|
449
|
+
'会话 cookie 按 host 区分,在 127.0.0.1 与公网域名之间切换会丢会话,' +
|
|
450
|
+
'表现就是「登录过、却突然全部 401」。' +
|
|
451
|
+
'浏览器不会自动带着平台会话去访问 node 自己的端口(那也是同一种 401)。'
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/** 会话 cookie 在,但缺少或错误的 CSRF 同步令牌。 */
|
|
456
|
+
function csrfRejectedMessage(reason: 'csrf_missing' | 'csrf_failed'): string {
|
|
457
|
+
return (
|
|
458
|
+
(reason === 'csrf_missing' ? 'csrf_missing' : 'csrf_failed') +
|
|
459
|
+
': 变更类请求必须带 X-Vessel-CSRF 头(值取自 GET /auth/status 的 csrfToken)。' +
|
|
460
|
+
'缺它或值不匹配都会被拒 —— 这是防 CSRF 的同步令牌,不是登录凭据。'
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* 校验单个 `auth.public_origin` / `auth.public_origins[i]`:只接受
|
|
466
|
+
* `scheme://host[:port]`(**具体** origin),不接受路径/查询/凭据。
|
|
467
|
+
*
|
|
468
|
+
* 来源是 `redirect_uri` 的**唯一**来源(不许从请求头推导),配错就是登录后 404,
|
|
469
|
+
* 所以在启动时 fail-fast,而不是等用户点登录才发现。
|
|
470
|
+
*
|
|
471
|
+
* 0.61:**端口通配(`host:*`)在这里也 fail-fast** —— 它只属于 `http.allowed_origins`。
|
|
472
|
+
* `redirect_uri` 必须是具体 origin,接受通配只会让人以为「写了就能登」。
|
|
473
|
+
*/
|
|
474
|
+
function normalizePublicOrigin(
|
|
475
|
+
raw: string | null | undefined,
|
|
476
|
+
label = 'auth.publicOrigin',
|
|
477
|
+
): string | null {
|
|
478
|
+
if (raw === null || raw === undefined || raw.trim() === '') return null;
|
|
479
|
+
const trimmed = raw.trim();
|
|
480
|
+
if (trimmed.endsWith(':*')) {
|
|
481
|
+
throw new Error(
|
|
482
|
+
`${label} "${trimmed}" uses a port wildcard: a port wildcard is only allowed in ` +
|
|
483
|
+
'http.allowed_origins (access control), not in auth.public_origins — redirect_uri ' +
|
|
484
|
+
'needs a concrete origin.',
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
const pattern = normalizeOriginPattern(trimmed);
|
|
488
|
+
if (pattern !== null) return pattern;
|
|
489
|
+
let url: URL;
|
|
490
|
+
try {
|
|
491
|
+
url = new URL(trimmed);
|
|
492
|
+
} catch {
|
|
493
|
+
throw new Error(`${label} "${trimmed}" is not an absolute URL (expected https://host).`);
|
|
494
|
+
}
|
|
495
|
+
if (url.protocol !== 'https:' && url.protocol !== 'http:') {
|
|
496
|
+
throw new Error(`${label} "${trimmed}" must be http(s).`);
|
|
497
|
+
}
|
|
498
|
+
if (url.username !== '' || url.password !== '') {
|
|
499
|
+
throw new Error(`${label} "${trimmed}" must not carry credentials.`);
|
|
500
|
+
}
|
|
501
|
+
if (url.pathname !== '/' || url.search !== '' || url.hash !== '') {
|
|
502
|
+
throw new Error(`${label} "${trimmed}" must be scheme://host[:port] only.`);
|
|
503
|
+
}
|
|
504
|
+
return url.origin;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* 0.60:合并 `auth.public_origins`(并列白名单)与 `auth.public_origin`(单来源,兼容)。
|
|
509
|
+
*
|
|
510
|
+
* 顺序稳定(`public_origin` 在前、列表按配置顺序跟上)并去重。两条同时出现不是错误:
|
|
511
|
+
* `public_origin` 的语义就是「只有一个元素的 `public_origins`」,合并只是把这句话写实。
|
|
512
|
+
*/
|
|
513
|
+
export function resolvePlatformPublicOrigins(input: {
|
|
514
|
+
publicOrigin?: string | null | undefined;
|
|
515
|
+
publicOrigins?: readonly string[] | undefined;
|
|
516
|
+
}): string[] {
|
|
517
|
+
const merged: string[] = [];
|
|
518
|
+
const push = (origin: string | null): void => {
|
|
519
|
+
if (origin === null || merged.includes(origin)) return;
|
|
520
|
+
merged.push(origin);
|
|
521
|
+
};
|
|
522
|
+
push(normalizePublicOrigin(input.publicOrigin));
|
|
523
|
+
const list = input.publicOrigins ?? [];
|
|
524
|
+
list.forEach((entry, index) => {
|
|
525
|
+
push(normalizePublicOrigin(entry, `auth.publicOrigins[${String(index)}]`));
|
|
526
|
+
});
|
|
527
|
+
return merged;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* 启动平台监听。`staticDir/index.html` 缺失时 fail-fast(P10),错误信息带解析后路径。
|
|
532
|
+
*/
|
|
533
|
+
export function startPlatformGateway(opts: PlatformGatewayOptions): PlatformGateway {
|
|
534
|
+
// 0.55 P0:fail-closed。非回环监听 + 没有 platform token ⇒ 拒绝启动(不是警告)。
|
|
535
|
+
const listenGuard = platformListenGuard({
|
|
536
|
+
hostname: opts.hostname,
|
|
537
|
+
port: opts.port,
|
|
538
|
+
platformToken: opts.platformToken,
|
|
539
|
+
});
|
|
540
|
+
if (listenGuard !== null) throw new Error(listenGuard);
|
|
541
|
+
|
|
542
|
+
const staticDir = resolve(opts.staticDir);
|
|
543
|
+
const indexFile = resolve(staticDir, 'index.html');
|
|
544
|
+
if (!existsSync(indexFile)) {
|
|
545
|
+
throw new Error(
|
|
546
|
+
`Platform gateway requires a built web UI: missing ${indexFile}. ` +
|
|
547
|
+
'Build apps/web (npm run build) before starting the gateway.',
|
|
548
|
+
);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
const allowedOrigins = normalizeAllowedOrigins(opts.allowedOrigins);
|
|
552
|
+
const nodeOrigins = normalizeAllowedOrigins(opts.nodeOrigins);
|
|
553
|
+
const hubOrigins = normalizeAllowedOrigins(opts.hubOrigins);
|
|
554
|
+
// 0.61:派生来源集 D 的**全量**(回环 + 本机网卡验证过的私网)只进 CSP ——
|
|
555
|
+
// 否则「局域网 node 的页面调本机平台」会被 CSP 挡掉;CORS 侧只取回环子集(见下)。
|
|
556
|
+
const derivedOrigins = normalizeAllowedOrigins(
|
|
557
|
+
opts.derivedOrigins !== undefined ? [...opts.derivedOrigins] : undefined,
|
|
558
|
+
);
|
|
559
|
+
const cspNodeOrigins = [...new Set([...nodeOrigins, ...derivedOrigins])];
|
|
560
|
+
const registry = createPlatformRegistry(opts.nodes);
|
|
561
|
+
const version = opts.version ?? 'unknown';
|
|
562
|
+
const platformToken = opts.platformToken;
|
|
563
|
+
const proxySecret = opts.proxySecret;
|
|
564
|
+
|
|
565
|
+
// 0.56 登录基座。未配置 auth.backends 时后端列表为空 ⇒ AuthService 报
|
|
566
|
+
// `enabled === false`,不拦任何人,行为与 0.55 逐字一致(不锁死回环)。
|
|
567
|
+
const authOptions: PlatformAuthOptions = { ...DISABLED_AUTH, ...opts.auth };
|
|
568
|
+
// 0.60:来源白名单(`public_origins` 并列 + `public_origin` 单来源,合并去重)。
|
|
569
|
+
// 一个来源都没有 ⇒ 空列表 ⇒ 公网/Host 白名单不启用(与今天逐字一致)。
|
|
570
|
+
const publicOrigins = resolvePlatformPublicOrigins(authOptions);
|
|
571
|
+
// 0.61:回环端口通配条目(`http://127.0.0.1:*`)没有确定的 Host,进不了 Host 白名单
|
|
572
|
+
// (`hostAllowed` 本来就直接放行回环 hostname);其余条目照旧按 host 登记。
|
|
573
|
+
const publicHosts = [
|
|
574
|
+
...new Set(
|
|
575
|
+
publicOrigins
|
|
576
|
+
.map((origin) => parseOriginPattern(origin))
|
|
577
|
+
.filter((parts): parts is OriginPattern => parts !== null && !parts.wildcardPort)
|
|
578
|
+
.map((parts) => parts.host),
|
|
579
|
+
),
|
|
580
|
+
];
|
|
581
|
+
// 0.61:`http.allowed_origins`(访问控制)与 `auth.public_origins`(redirect_uri 来源)
|
|
582
|
+
// 分开:前者回答「浏览器能不能发 RPC」,后者回答「登录回跳到哪」。
|
|
583
|
+
// - `gateway.allowed_origins` / `public_origins` 永远生效(本部署自己的来源总能调 API);
|
|
584
|
+
// - `http.allowed_origins` 未配置 ⇒ 只补回环通配三条(老配置一字不改,本地任意端口的
|
|
585
|
+
// WebUI 立刻能用);显式配置 ⇒ 就是它(`[]` = 不再自动补通配)。
|
|
586
|
+
// 0.61:访问控制生效值 = `gateway.allowed_origins` ∪ `auth.public_origins` ∪
|
|
587
|
+
// (`http.allowed_origins` ?? 三条回环通配) ∪ **派生来源集 D 的回环部分**。
|
|
588
|
+
// 前两项在这里展开,后两项由 `resolveHttpAllowedOrigins` 这**一个实现**给出
|
|
589
|
+
// (派生集只加不减;私网部分在函数内部被挡在 CORS 之外,调用方传全量 D 也安全)。
|
|
590
|
+
const httpAllowedOrigins = normalizeAllowedOrigins([
|
|
591
|
+
...allowedOrigins,
|
|
592
|
+
...publicOrigins,
|
|
593
|
+
...resolveHttpAllowedOrigins({
|
|
594
|
+
...(opts.httpAllowedOrigins !== undefined ? { allowedOrigins: opts.httpAllowedOrigins } : {}),
|
|
595
|
+
publicOrigins,
|
|
596
|
+
...(opts.derivedOrigins !== undefined ? { derivedOrigins: opts.derivedOrigins } : {}),
|
|
597
|
+
}),
|
|
598
|
+
]);
|
|
599
|
+
const authService = new AuthService({
|
|
600
|
+
...authOptions,
|
|
601
|
+
publicOrigin: publicOrigins[0] ?? null,
|
|
602
|
+
publicOrigins,
|
|
603
|
+
env: authOptions.env ?? (process.env as Record<string, string | undefined>),
|
|
604
|
+
// 0.56 P2:`POST /auth/unlock` 要比对这个值(本机 + 平台 token 才能解锁登录限速)。
|
|
605
|
+
// 只比较、不回显、不落盘。
|
|
606
|
+
...(platformToken !== undefined ? { platformToken } : {}),
|
|
607
|
+
// 0.62:受信 relay 的「页面真实 origin」声明,只有在**反代密钥真的配了**时才可以
|
|
608
|
+
// 采信 —— 登录层因此需要知道「配没配」。这个值只用于那一个判断:不比较、不回显、
|
|
609
|
+
// 不进日志(比较本身由受信边缘 `resolveRequestEdge` 完成)。
|
|
610
|
+
...(proxySecret !== undefined ? { proxySecret } : {}),
|
|
611
|
+
log: (message: string) => {
|
|
612
|
+
// 只打非敏感事实:会话 id / csrf / token / secret / 口令 / TOTP 密钥 / 恢复码都不进这行。
|
|
613
|
+
console.warn(`[platform-auth] ${message}`);
|
|
614
|
+
},
|
|
615
|
+
});
|
|
616
|
+
const authCleanupTimer = setInterval(() => authService.cleanup(), 60_000);
|
|
617
|
+
authCleanupTimer.unref?.();
|
|
618
|
+
|
|
619
|
+
// 0.57:`/build.json` 的现场判断缓存(每个 server 一份,判定函数由组合根注入)。
|
|
620
|
+
const probeWebDist = createWebDistProbeCache();
|
|
621
|
+
// 0.60:构建状态的唯一来源。**不进上面那份缓存**:构建一结束就必须说「结束了」。
|
|
622
|
+
const webBuild = opts.webBuild;
|
|
623
|
+
// 0.61:低频自查(缺省 60s)。**定时器本身不打日志** —— 每 60s 一行会把日志刷满;
|
|
624
|
+
// 只有「因此真的起了构建」时,组合根那侧才会打 `web.build.start check=timer`。
|
|
625
|
+
const webBuildCheck = opts.webBuildCheck;
|
|
626
|
+
const webBuildCheckTimer =
|
|
627
|
+
webBuildCheck === undefined
|
|
628
|
+
? undefined
|
|
629
|
+
: setInterval(
|
|
630
|
+
() => {
|
|
631
|
+
// 自查失败不重要(下一轮还会再来),更不该冒泡成未处理拒绝。
|
|
632
|
+
void Promise.resolve()
|
|
633
|
+
.then(() => webBuildCheck('timer'))
|
|
634
|
+
.catch(() => undefined);
|
|
635
|
+
},
|
|
636
|
+
Math.max(WEB_BUILD_CHECK_MIN_MS, opts.webBuildCheckMs ?? WEB_BUILD_CHECK_DEFAULT_MS),
|
|
637
|
+
);
|
|
638
|
+
webBuildCheckTimer?.unref?.();
|
|
639
|
+
// 0.57:产物变更推送(SSE)。`/build.json` 仍是唯一事实源,这里只是加速通道。
|
|
640
|
+
const buildEvents = createBuildEventStream({
|
|
641
|
+
staticDir,
|
|
642
|
+
probe: opts.webDist,
|
|
643
|
+
probeCached: probeWebDist,
|
|
644
|
+
webBuild,
|
|
645
|
+
});
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* 0.58:代理门面。省略 `opts.proxy` = 关闭(组合根没接线时行为与 0.57 逐字一致)。
|
|
649
|
+
*
|
|
650
|
+
* 目标地址只从 `registry` 取(节点表的唯一真相源),凭据只从
|
|
651
|
+
* `opts.resolveNodeCredential` 取(不缓存、不落盘、不进响应体)。
|
|
652
|
+
*/
|
|
653
|
+
const proxy = new PlatformProxy({
|
|
654
|
+
enabled: opts.proxy !== undefined && opts.proxy.enabled !== false,
|
|
655
|
+
resolveNode: (nodeId) => registry.descriptor(nodeId),
|
|
656
|
+
resolveToken: (nodeId) => {
|
|
657
|
+
try {
|
|
658
|
+
// 0.58:`resolveNodeCredential` 从此是**内部**函数:只被代理层调用。
|
|
659
|
+
const credential = opts.resolveNodeCredential(nodeId);
|
|
660
|
+
return credential.found ? credential.token : undefined;
|
|
661
|
+
} catch {
|
|
662
|
+
// 读不到凭据 = 该 node 走回环匿名;不把底层错误带进响应。
|
|
663
|
+
return undefined;
|
|
664
|
+
}
|
|
665
|
+
},
|
|
666
|
+
...(opts.proxy?.limits !== undefined ? { limits: opts.proxy.limits } : {}),
|
|
667
|
+
// 记账出口不注入:用 PlatformProxy 的缺省(logEvent + 与 node 侧同一套
|
|
668
|
+
// ws.closed 级别规则),规则只有一份。
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* 平台数据面闸(`/platform/rpc` 与 `/nodes/**` 的**同一套**权威判定)。
|
|
673
|
+
*
|
|
674
|
+
* 抽出来不是为了少写几行:两处一旦各写一套,代理就会成为「比 RPC 更松的那个入口」——
|
|
675
|
+
* 那正是「不能变成新的穿通面」要防的事。
|
|
676
|
+
*/
|
|
677
|
+
type DataGate = { ok: true } | { ok: false; response: Response };
|
|
678
|
+
const dataGate = (
|
|
679
|
+
req: Request,
|
|
680
|
+
authCtx: AuthRequestContext,
|
|
681
|
+
auth: ReturnType<typeof resolvePlatformAuth>,
|
|
682
|
+
options: { mutating: boolean; localDirect: boolean },
|
|
683
|
+
extra: Record<string, string>,
|
|
684
|
+
): DataGate => {
|
|
685
|
+
// 1. Bearer token 成立 → 放行(令牌优先,不需要 CSRF)。
|
|
686
|
+
if (auth.ok) return { ok: true };
|
|
687
|
+
const gate = authService.authorize(req, authCtx, { mutating: options.mutating });
|
|
688
|
+
// 2. 会话 cookie 在但 CSRF 缺失 / 不匹配 → 403(cookie 不是能力凭证)。
|
|
689
|
+
if (!gate.ok && (gate.reason === 'csrf_missing' || gate.reason === 'csrf_failed')) {
|
|
690
|
+
return {
|
|
691
|
+
ok: false,
|
|
692
|
+
response: errorJson('csrf_failed', csrfRejectedMessage(gate.reason), 403, extra),
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
// 3. 配了登录后端且不是本机直连(公网/经反代)→ 401,让前端回登录页。
|
|
696
|
+
if (!gate.ok && authService.enabled && !options.localDirect) {
|
|
697
|
+
const origin =
|
|
698
|
+
authCtx.edge.host === null ? null : `${authCtx.edge.protocol}://${authCtx.edge.host}`;
|
|
699
|
+
return {
|
|
700
|
+
ok: false,
|
|
701
|
+
response: errorJson('session_required', sessionRequiredMessage(origin), 401, extra),
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
// 4. 非回环且未认证 → 401(旧行为)。
|
|
705
|
+
if (!gate.ok && !auth.loopback) {
|
|
706
|
+
return {
|
|
707
|
+
ok: false,
|
|
708
|
+
response: errorJson('platform_unauthorized', platformUnauthorizedMessage(auth), 401, extra),
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
// 5. 本机直连(未配 token 的回环)→ 匿名放行(旧行为,防锁死)。
|
|
712
|
+
return { ok: true };
|
|
713
|
+
};
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* WS 首帧里的 token 校验:浏览器 WS 带不了 `Authorization` 头,所以平台 token
|
|
717
|
+
* 允许走首帧(与 node 的 `{kind:'auth'}` 同形状)。**校验的是平台 token**,
|
|
718
|
+
* 平台 token 永远不会被转发给 node。
|
|
719
|
+
*/
|
|
720
|
+
const verifyPlatformToken = (provided: string): boolean => {
|
|
721
|
+
if (platformToken === undefined || platformToken === '') {
|
|
722
|
+
// 未配置平台 token:这条连接本来只可能是回环匿名(闸已放行)。
|
|
723
|
+
return provided === '';
|
|
724
|
+
}
|
|
725
|
+
return provided !== '' && platformTokenMatches(provided, platformToken);
|
|
726
|
+
};
|
|
727
|
+
|
|
728
|
+
/**
|
|
729
|
+
* 日志/指标分离:资源统计是**统计指标**,不是**时间事件**。
|
|
730
|
+
*
|
|
731
|
+
* 原先每 60s 打一行 `gateway.resources` WRN 进事件日志 —— 全是噪音,淹没有用的
|
|
732
|
+
* 时点事件与错误。现在登记进 Prometheus registry,经 `/metrics` 端点按 pull 模型
|
|
733
|
+
* 暴露(scrape 时求值):时序曲线交给外部 Prometheus/Grafana,事件日志不再出现
|
|
734
|
+
* 周期资源行,也没有周期定时器。见 `./metrics.ts`(指标族)与 `../prometheus.ts`。
|
|
735
|
+
*/
|
|
736
|
+
const metrics = createPlatformMetrics({ stats: () => proxy.stats(), version });
|
|
737
|
+
|
|
738
|
+
const server = Bun.serve<PlatformWsData>({
|
|
739
|
+
port: opts.port,
|
|
740
|
+
hostname: opts.hostname,
|
|
741
|
+
// 0.57:SSE 是长连接,Bun 默认 10 秒空闲就掐掉(只发保活帧也会被掐)。与
|
|
742
|
+
// node 侧 `/v1/events` / hub 同口径关掉空闲超时(`gateway.ts` 的 `idleTimeout: 0`),
|
|
743
|
+
// 连接的生命周期交给 SSE 自己的保活帧与客户端重连。
|
|
744
|
+
idleTimeout: 0,
|
|
745
|
+
// 0.58:代理 WS 的**唯一**入口。心跳、背压、close 记账都在 `ProxyWsBridge`,
|
|
746
|
+
// 这里只做分发(不在 handler 里加任何策略,避免两处判据漂移)。
|
|
747
|
+
websocket: {
|
|
748
|
+
data: {} as PlatformWsData,
|
|
749
|
+
open(ws: Bun.ServerWebSocket<PlatformWsData>) {
|
|
750
|
+
const { bridge } = ws.data;
|
|
751
|
+
proxy.wsOpen(bridge, ws as unknown as ProxyWsClient);
|
|
752
|
+
},
|
|
753
|
+
message(ws: Bun.ServerWebSocket<PlatformWsData>, message: string | Buffer) {
|
|
754
|
+
proxy.wsMessage(ws.data.bridge, message);
|
|
755
|
+
},
|
|
756
|
+
close(ws: Bun.ServerWebSocket<PlatformWsData>, code: number, reason: string) {
|
|
757
|
+
proxy.wsClose(ws.data.bridge, code, reason);
|
|
758
|
+
},
|
|
759
|
+
pong(ws: Bun.ServerWebSocket<PlatformWsData>) {
|
|
760
|
+
proxy.wsPong(ws.data.bridge);
|
|
761
|
+
},
|
|
762
|
+
},
|
|
763
|
+
fetch: async (req, srv) => {
|
|
764
|
+
const url = new URL(req.url);
|
|
765
|
+
const path = url.pathname;
|
|
766
|
+
const address = srv.requestIP(req)?.address ?? null;
|
|
767
|
+
|
|
768
|
+
// 0.56:先解析「受信边缘」。反代头(Host / X-Forwarded-Proto)只有在本请求
|
|
769
|
+
// 来自受信代理时才被采信;否则一律用请求自身,伪造 Host 拿不到公网身份。
|
|
770
|
+
const edge = resolveRequestEdge(req, {
|
|
771
|
+
address,
|
|
772
|
+
proxySecret,
|
|
773
|
+
...(authOptions.trustedProxies !== undefined
|
|
774
|
+
? { trustedProxies: authOptions.trustedProxies }
|
|
775
|
+
: {}),
|
|
776
|
+
// 0.63:`auth.allow_loopback_anonymous`(缺省 false)。只影响 `edge.localDirect`
|
|
777
|
+
// —— 也就是「回环匿名要不要身份」,不影响任何一道闸的次序。
|
|
778
|
+
...(opts.allowLoopbackAnonymous === true ? { allowLoopbackAnonymous: true } : {}),
|
|
779
|
+
});
|
|
780
|
+
const extra = corsHeaders(req, httpAllowedOrigins, { credentials: true });
|
|
781
|
+
|
|
782
|
+
if (req.method === 'OPTIONS') {
|
|
783
|
+
return new Response(null, {
|
|
784
|
+
status: 204,
|
|
785
|
+
headers: { Allow: 'GET, POST, OPTIONS', ...extra },
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
// 平台侧错误码只用 CONTRACT §7 表内项:Host/Origin 拒绝统一为 `forbidden`。
|
|
790
|
+
if (
|
|
791
|
+
!hostAllowed(req, {
|
|
792
|
+
listenHost: opts.hostname,
|
|
793
|
+
publicHosts,
|
|
794
|
+
additionalHosts: authOptions.allowedHosts,
|
|
795
|
+
edge,
|
|
796
|
+
})
|
|
797
|
+
) {
|
|
798
|
+
return errorJson('forbidden', 'Host header is not allowed', 403, extra);
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
// 0.61:鉴权先于 Origin 闸(Origin 闸需要一个「凭据是否验过」的事实)。
|
|
802
|
+
// `mode === 'token'` 不是配置开关:它只在 bearer 与平台 token **常量时间比较通过**
|
|
803
|
+
// 时出现(见 `resolvePlatformAuth`),也就是一次真校验的结果。
|
|
804
|
+
const auth = resolvePlatformAuth({
|
|
805
|
+
req,
|
|
806
|
+
address,
|
|
807
|
+
platformToken,
|
|
808
|
+
// 0.56:派生值不算「配置」——回环匿名必须保持(迁移安全)。
|
|
809
|
+
explicitPlatformToken: opts.platformTokenConfigured ?? true,
|
|
810
|
+
...(proxySecret !== undefined ? { proxySecret } : {}),
|
|
811
|
+
});
|
|
812
|
+
// cookie 会话路径**不**传 `credentialVerified`:浏览器会自动带 cookie,
|
|
813
|
+
// 那条路必须照旧过白名单(CSRF 面一点不放宽;写操作另有 CSRF 同步令牌)。
|
|
814
|
+
if (!originAllowed(req, httpAllowedOrigins, { credentialVerified: auth.mode === 'token' })) {
|
|
815
|
+
return errorJson('forbidden', 'Origin is not allowed', 403, extra);
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
const authCtx: AuthRequestContext = { edge, address };
|
|
819
|
+
|
|
820
|
+
// 0.56:登录端点(/auth/*)**在**鉴权闸之前。配了 token 的部署里,
|
|
821
|
+
// 浏览器必须能先打开登录页、走 OAuth 回来,才谈得上带 cookie 调 RPC。
|
|
822
|
+
const authRoute = await authService.handle(req, url, authCtx);
|
|
823
|
+
if (authRoute !== null) return authRoute;
|
|
824
|
+
|
|
825
|
+
if (isNodeOnlyPath(path)) {
|
|
826
|
+
return errorJson('not_found', `Not found: ${path}`, 404, extra);
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
// ---- 精确端点(全部在静态兜底之前;顺序判据:精确端点 → 明确 404 → SPA 兜底)----
|
|
830
|
+
|
|
831
|
+
// 0.55 口径不变:health 不放公网(回环或已认证才可读)。
|
|
832
|
+
// 0.58 修 bug:这一块原本排在静态兜底之后,于是 `/health` 被 SPA 回退成
|
|
833
|
+
// `index.html`(200 HTML),`gateway status` 对平台实例因此恒显示 unreachable。
|
|
834
|
+
if (path === '/health') {
|
|
835
|
+
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
|
836
|
+
return errorJson('not_found', `Not found: ${path}`, 404, extra);
|
|
837
|
+
}
|
|
838
|
+
if (!auth.loopback && !auth.ok) {
|
|
839
|
+
return errorJson('platform_unauthorized', platformUnauthorizedMessage(auth), 401, extra);
|
|
840
|
+
}
|
|
841
|
+
// 平台健康:不含 node runtime 数据;`role` 供 CLI 确定性区分平台/node health。
|
|
842
|
+
// `proxy` 是能力位(前端据此选择数据面),不含地址与凭据。
|
|
843
|
+
return json(
|
|
844
|
+
{
|
|
845
|
+
status: 'ok',
|
|
846
|
+
role: 'platform',
|
|
847
|
+
version,
|
|
848
|
+
proxy: { enabled: proxy.enabled, base_path: PROXY_BASE_PATH },
|
|
849
|
+
},
|
|
850
|
+
200,
|
|
851
|
+
extra,
|
|
852
|
+
);
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
// 日志/指标分离:`/metrics` 以 Prometheus exposition format 暴露资源指标(pull)。
|
|
856
|
+
// 与 `/health` 同口径:不放公网(回环或已认证才可读)—— 资源开销同样是内部事实。
|
|
857
|
+
// 本机 Prometheus 走回环匿名;远端 scrape 带平台 token(Bearer)。
|
|
858
|
+
if (path === '/metrics') {
|
|
859
|
+
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
|
860
|
+
return errorJson('not_found', `Not found: ${path}`, 404, extra);
|
|
861
|
+
}
|
|
862
|
+
if (!auth.loopback && !auth.ok) {
|
|
863
|
+
return errorJson('platform_unauthorized', platformUnauthorizedMessage(auth), 401, extra);
|
|
864
|
+
}
|
|
865
|
+
const body = metrics.render();
|
|
866
|
+
return new Response(req.method === 'HEAD' ? null : body, {
|
|
867
|
+
status: 200,
|
|
868
|
+
headers: {
|
|
869
|
+
// Prometheus text exposition format 的标准 Content-Type。
|
|
870
|
+
'Content-Type': 'text/plain; version=0.0.4; charset=utf-8',
|
|
871
|
+
'Cache-Control': 'no-store',
|
|
872
|
+
'X-Content-Type-Options': 'nosniff',
|
|
873
|
+
...extra,
|
|
874
|
+
},
|
|
875
|
+
});
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
// 0.57:`/build.json` 是**实时**响应(静态构建戳 + 服务端现场判断),必须自己
|
|
879
|
+
// 处理:交给 serveStatic 会带着 `immutable` 一年缓存头原样吐出去。
|
|
880
|
+
if (path === BUILD_JSON_PATH && (req.method === 'GET' || req.method === 'HEAD')) {
|
|
881
|
+
const buildResponse = await buildJsonResponse(
|
|
882
|
+
staticDir,
|
|
883
|
+
req.method,
|
|
884
|
+
opts.webDist,
|
|
885
|
+
probeWebDist,
|
|
886
|
+
webBuild,
|
|
887
|
+
// 0.61:探针看到 stale 就叫一次(限频在组合根)。没人开浏览器时靠定时器。
|
|
888
|
+
webBuildCheck === undefined ? undefined : () => void webBuildCheck('probe'),
|
|
889
|
+
);
|
|
890
|
+
if (buildResponse !== null) {
|
|
891
|
+
for (const [key, value] of Object.entries(extra)) {
|
|
892
|
+
buildResponse.headers.set(key, value);
|
|
893
|
+
}
|
|
894
|
+
return buildResponse;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
// 0.57:产物变更推送。**必须在静态兜底之前** —— 它没有扩展名,serveStatic
|
|
899
|
+
// 会把它当成 SPA 路由、返回 index.html。
|
|
900
|
+
//
|
|
901
|
+
// 鉴权:EventSource 带不了 Authorization 头,所以走**会话 cookie**(浏览器
|
|
902
|
+
// 同源自动带上)或回环/Bearer。token 绝不进 URL(会落进反代与浏览器历史)。
|
|
903
|
+
// 没配登录后端的部署(`authEnabled:false`)与 `/build.json` 保持同等开放:
|
|
904
|
+
// 静态站点本身就是匿名可读的,这里没有比对静态文件更多的信息。
|
|
905
|
+
if (path === BUILD_EVENTS_PATH) {
|
|
906
|
+
if (req.method !== 'GET') {
|
|
907
|
+
return errorJson('method_not_allowed', 'Only GET is allowed', 405, {
|
|
908
|
+
...extra,
|
|
909
|
+
Allow: 'GET',
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
const streamAllowed =
|
|
913
|
+
!authService.enabled ||
|
|
914
|
+
auth.loopback ||
|
|
915
|
+
auth.ok ||
|
|
916
|
+
authService.authorize(req, authCtx, { mutating: false }).ok;
|
|
917
|
+
if (!streamAllowed) {
|
|
918
|
+
return errorJson('platform_unauthorized', platformUnauthorizedMessage(auth), 401, extra);
|
|
919
|
+
}
|
|
920
|
+
const stream = await buildEvents.open();
|
|
921
|
+
if (stream === null) {
|
|
922
|
+
// 有界:长连接满了就让它退回轮询(前端按「推送不可用」处理)。
|
|
923
|
+
return errorJson(
|
|
924
|
+
'unavailable',
|
|
925
|
+
`Too many build event streams (max ${BUILD_EVENTS_MAX_CONNECTIONS}); poll /build.json instead.`,
|
|
926
|
+
503,
|
|
927
|
+
{ ...extra, 'Retry-After': '30' },
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
for (const [key, value] of Object.entries(extra)) stream.headers.set(key, value);
|
|
931
|
+
return stream;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
if (path === PLATFORM_RPC_PATH) {
|
|
935
|
+
if (req.method !== 'POST') {
|
|
936
|
+
return errorJson('method_not_allowed', 'Only POST is allowed', 405, {
|
|
937
|
+
...extra,
|
|
938
|
+
Allow: 'POST',
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
// 鉴权矩阵见 `dataGate`(与 `/nodes/**` 共用同一套:代理不许比 RPC 更松)。
|
|
942
|
+
const rpcGate = dataGate(
|
|
943
|
+
req,
|
|
944
|
+
authCtx,
|
|
945
|
+
auth,
|
|
946
|
+
{ mutating: true, localDirect: edge.localDirect },
|
|
947
|
+
extra,
|
|
948
|
+
);
|
|
949
|
+
if (!rpcGate.ok) return rpcGate.response;
|
|
950
|
+
return handlePlatformRpc(
|
|
951
|
+
req,
|
|
952
|
+
{
|
|
953
|
+
auth,
|
|
954
|
+
registry,
|
|
955
|
+
resolveNodeCredential: opts.resolveNodeCredential,
|
|
956
|
+
version,
|
|
957
|
+
proxy: { enabled: proxy.enabled, basePath: PROXY_BASE_PATH },
|
|
958
|
+
// Q4-C:优雅退出注入 + 反代密钥「已配置」位(远程闸 4 fail-closed 用)。
|
|
959
|
+
shutdown: opts.shutdown,
|
|
960
|
+
// q-start-semantics:down node 重拉注入(同步等 report;未注入 = not_found 零表面)。
|
|
961
|
+
respawn: opts.respawnNodes,
|
|
962
|
+
proxySecretConfigured: opts.proxySecret !== undefined && opts.proxySecret !== '',
|
|
963
|
+
// R1.2:原始 socket 回环(与 resolvePlatformAuth 同源 address;先于 proxySecretOk 合取)。
|
|
964
|
+
socketLoopback: isLoopbackAddress(address),
|
|
965
|
+
},
|
|
966
|
+
extra,
|
|
967
|
+
);
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
// ---- 0.58:`/nodes/:nodeId/**` 代理(HTTP + WS 升级)----
|
|
971
|
+
//
|
|
972
|
+
// 目标只来自注册表;客户端只提供 node_id。鉴权走**平台会话语义**
|
|
973
|
+
// (Bearer / 会话 cookie / 回环匿名),node token 永不出网关。
|
|
974
|
+
if (path === PROXY_BASE_PATH || path.startsWith(`${PROXY_BASE_PATH}/`)) {
|
|
975
|
+
const route = parseProxyRoute(path);
|
|
976
|
+
if (route === null) {
|
|
977
|
+
// 形状不对(含 `..` / `//host` / 非法 id):明确 404,不回落成 SPA。
|
|
978
|
+
return errorJson('not_found', `Not found: ${path}`, 404, extra);
|
|
979
|
+
}
|
|
980
|
+
if (!proxy.enabled) {
|
|
981
|
+
return errorJson(
|
|
982
|
+
'proxy_disabled',
|
|
983
|
+
'proxy_disabled: 这个部署关闭了 gateway.proxy_nodes(浏览器应直连 node)。',
|
|
984
|
+
404,
|
|
985
|
+
extra,
|
|
986
|
+
);
|
|
987
|
+
}
|
|
988
|
+
const isUpgrade = (req.headers.get('upgrade') ?? '').toLowerCase() === 'websocket';
|
|
989
|
+
// WS 升级不是变更类请求(握手时浏览器带不了 CSRF 头,带的是 cookie)。
|
|
990
|
+
const proxyGate = dataGate(
|
|
991
|
+
req,
|
|
992
|
+
authCtx,
|
|
993
|
+
auth,
|
|
994
|
+
{ mutating: false, localDirect: edge.localDirect },
|
|
995
|
+
extra,
|
|
996
|
+
);
|
|
997
|
+
if (!isUpgrade && !proxyGate.ok) return proxyGate.response;
|
|
998
|
+
if (isUpgrade) {
|
|
999
|
+
if (req.method !== 'GET') {
|
|
1000
|
+
return errorJson('method_not_allowed', 'WebSocket upgrade must be GET', 405, {
|
|
1001
|
+
...extra,
|
|
1002
|
+
Allow: 'GET',
|
|
1003
|
+
});
|
|
1004
|
+
}
|
|
1005
|
+
// 没有 cookie 也能升级的**唯一**情形:这个部署配了平台 token。
|
|
1006
|
+
//
|
|
1007
|
+
// 为什么必须留这条路:浏览器 WS 握手带不了 `Authorization` 头。远端用户
|
|
1008
|
+
// (没有 OAuth 会话、只有 `gateway.token`)在代理模式下全靠首帧
|
|
1009
|
+
// `{kind:'auth',token}` 证明身份 —— 直接 401 的话「HTTP 能用、WS 连不上」。
|
|
1010
|
+
// 代价有界:连接仍受 wsMaxConnections 限制,且首帧鉴权窗口 wsHandshakeTimeoutMs
|
|
1011
|
+
// (10s)内不通过就 4401 关闭。
|
|
1012
|
+
const deferredAuth = typeof platformToken === 'string' && platformToken !== '';
|
|
1013
|
+
if (!proxyGate.ok && !deferredAuth) return proxyGate.response;
|
|
1014
|
+
const upgrade = proxy.upgrade(route, url, {
|
|
1015
|
+
// 已在升级时通过平台鉴权(Bearer / 会话 cookie / 回环)⇒ 不必等首帧 token。
|
|
1016
|
+
preAuthenticated: proxyGate.ok,
|
|
1017
|
+
verifyPlatformToken,
|
|
1018
|
+
});
|
|
1019
|
+
if (!upgrade.ok) {
|
|
1020
|
+
for (const [key, value] of Object.entries(extra)) {
|
|
1021
|
+
upgrade.response.headers.set(key, value);
|
|
1022
|
+
}
|
|
1023
|
+
return upgrade.response;
|
|
1024
|
+
}
|
|
1025
|
+
const upgraded = srv.upgrade(req, {
|
|
1026
|
+
data: { kind: 'node-proxy' as const, bridge: upgrade.bridge },
|
|
1027
|
+
});
|
|
1028
|
+
if (!upgraded) {
|
|
1029
|
+
upgrade.bridge.failUpstream('upgrade_failed');
|
|
1030
|
+
return errorJson('invalid_request', 'WebSocket upgrade failed', 400, extra);
|
|
1031
|
+
}
|
|
1032
|
+
return undefined;
|
|
1033
|
+
}
|
|
1034
|
+
const proxied = await proxy.handleHttp(req, route, url);
|
|
1035
|
+
for (const [key, value] of Object.entries(extra)) proxied.headers.set(key, value);
|
|
1036
|
+
return proxied;
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
// 平台自有路径(`/auth/**`、`/web/**` 等)没命中精确端点 ⇒ 明确 404,
|
|
1040
|
+
// 绝不让 SPA 兜底把它们变成 index.html(那会让「路由写错」看起来像「页面正常」)。
|
|
1041
|
+
if (isReservedPlatformPath(path)) {
|
|
1042
|
+
return errorJson('not_found', `Not found: ${path}`, 404, extra);
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
// ---- 静态宿主(SPA 兜底)----
|
|
1046
|
+
// 静态宿主在闸之前:`index.html` 与 `/login` 是登录页本身,匿名也要拿得到
|
|
1047
|
+
// (否则「配了 token」⇒ 浏览器永远停在白屏)。数据面仍然要靠 RPC/代理鉴权。
|
|
1048
|
+
if (req.method === 'GET' || req.method === 'HEAD') {
|
|
1049
|
+
const staticResponse = await serveStatic(path, staticDir);
|
|
1050
|
+
if (staticResponse !== null) {
|
|
1051
|
+
const contentType = staticResponse.headers.get('content-type') ?? '';
|
|
1052
|
+
if (contentType.includes('text/html')) {
|
|
1053
|
+
staticResponse.headers.set(
|
|
1054
|
+
'Content-Security-Policy',
|
|
1055
|
+
buildContentSecurityPolicy(
|
|
1056
|
+
req,
|
|
1057
|
+
httpAllowedOrigins,
|
|
1058
|
+
{
|
|
1059
|
+
frameSrc: cspNodeOrigins,
|
|
1060
|
+
connectSrc: [...cspNodeOrigins, ...hubOrigins],
|
|
1061
|
+
},
|
|
1062
|
+
{ host: edge.host, protocol: edge.protocol },
|
|
1063
|
+
),
|
|
1064
|
+
);
|
|
1065
|
+
}
|
|
1066
|
+
for (const [key, value] of Object.entries(extra)) {
|
|
1067
|
+
staticResponse.headers.set(key, value);
|
|
1068
|
+
}
|
|
1069
|
+
return staticResponse;
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
return errorJson('not_found', `Not found: ${path}`, 404, extra);
|
|
1074
|
+
},
|
|
1075
|
+
});
|
|
1076
|
+
|
|
1077
|
+
// R-5 残余面根治(q-spawn-hardening):platform 主监听建立即清 HANDLE_FLAG_INHERIT。
|
|
1078
|
+
// node-supervisor 运行期重 spawn(R-3 退避重试 / node 崩溃补员)发生在本监听
|
|
1079
|
+
// 之后,未防护即继承本端口,平台非优雅死亡留僵尸端口。「spawn 先于监听」顺序
|
|
1080
|
+
// 缓解只覆盖首生 node,覆盖不到运行期重生。与 hub/server.ts 接线同形。
|
|
1081
|
+
guardListenerInheritance(server.port ?? opts.port, server);
|
|
1082
|
+
|
|
1083
|
+
return {
|
|
1084
|
+
// Bun 对 unix socket 返回 undefined;平台只走 TCP,回退到请求端口。
|
|
1085
|
+
port: server.port ?? opts.port,
|
|
1086
|
+
async stop(): Promise<void> {
|
|
1087
|
+
// DR15-1:退出步永久进度日志(与 node 侧同一事件名 node.shutdown.step)。
|
|
1088
|
+
const emit: ShutdownStepEmit = (level, event, fields) => logEvent(level, event, fields);
|
|
1089
|
+
// 先断开 SSE 长连接:`server.stop(true)` 会等活跃连接,长连接不关就等不完。
|
|
1090
|
+
buildEvents.close();
|
|
1091
|
+
// 0.58:代理 WS 同理 —— 不让一条事件流把停服卡死;关闭时按 `who: 'platform'` 记账。
|
|
1092
|
+
proxy.closeAll();
|
|
1093
|
+
// DR15-2:中止全部在途上游请求。node 先死后,代理里等死 node 回包的请求
|
|
1094
|
+
// 每请求最长挂 30s,把 Bun `pending_requests>0` 钉住 ⇒ stop promise 永不
|
|
1095
|
+
// settle(ISSUE-DR15-2:start 后 30s+ 无 done/timeout_bounded,看门狗 force)。
|
|
1096
|
+
// abort ⇒ fetch catch 立即 504/502 ⇒ handler 完成 ⇒ pending_requests 归零。
|
|
1097
|
+
const abortedInflight = proxy.abortInflight();
|
|
1098
|
+
// DR15-2:关 idle keep-alive HTTP(node 侧等满 5s 的那类残余)。Bun 1.3.9
|
|
1099
|
+
// 既有 API(server.zig closeIdleConnections);类型滞后时可选链安全 no-op。
|
|
1100
|
+
(server as { closeIdleConnections?: () => void }).closeIdleConnections?.();
|
|
1101
|
+
clearInterval(authCleanupTimer);
|
|
1102
|
+
// 0.61:自查定时器跟着平台一起停(网关停了不该还在跑 tsc)。
|
|
1103
|
+
if (webBuildCheckTimer !== undefined) clearInterval(webBuildCheckTimer);
|
|
1104
|
+
await runShutdownStep(emit, 'platform.auth.flush', () => authService.flush());
|
|
1105
|
+
// DR15-2 迭代2:不 await stop promise —— Bun 1.3.9 server-initiated WS
|
|
1106
|
+
// close 永久泄漏 active_connections(close()/terminate() 先置 flags.closed,
|
|
1107
|
+
// onClose 的 was_closed 分支不减计数,ServerWebSocket.zig:285-295),
|
|
1108
|
+
// promise 的 settle 条件 active_connections==0(server.zig:1493-1497)
|
|
1109
|
+
// 在发生过 server-initiated close 的进程里**不可达** ⇒ await(含 5s race)
|
|
1110
|
+
// 只是白等。native 关闭(stopListening → app.close → us_socket_context_close
|
|
1111
|
+
// 逐 socket closesocket)在 stop(true) **调用内同步完成**:调用返回 = 关闭
|
|
1112
|
+
// 已完成,立即推进 lock.release → process.exit。CLOSING 残留已由
|
|
1113
|
+
// terminate 预关消除(app.close 无半闭 WS 可搅 ⇒ 不再 native 卡死);
|
|
1114
|
+
// 万一仍同步卡死(不可静态定位帧),B 看门狗 30s 兜底保安全。
|
|
1115
|
+
// start/done 永久附分类诊断:真实未关 WS ≈ pending_ws - proxy_ws_closed
|
|
1116
|
+
// (泄漏计数如实显示,差值归因;lead 修正判据)。
|
|
1117
|
+
const serverDiag = server as { pendingRequests?: number; pendingWebSockets?: number };
|
|
1118
|
+
emit('info', SHUTDOWN_STEP_EVENT, {
|
|
1119
|
+
step: 'platform.server.stop',
|
|
1120
|
+
status: 'start',
|
|
1121
|
+
pending_requests: serverDiag.pendingRequests ?? -1,
|
|
1122
|
+
pending_ws: serverDiag.pendingWebSockets ?? -1,
|
|
1123
|
+
proxy_ws_live: proxy.liveWsBridges,
|
|
1124
|
+
proxy_ws_closed: proxy.serverClosedWs,
|
|
1125
|
+
aborted_inflight: abortedInflight,
|
|
1126
|
+
});
|
|
1127
|
+
const stopStartedAt = Date.now();
|
|
1128
|
+
try {
|
|
1129
|
+
const stopPromise = server.stop(true);
|
|
1130
|
+
emit('info', SHUTDOWN_STEP_EVENT, {
|
|
1131
|
+
step: 'platform.server.stop',
|
|
1132
|
+
status: 'done',
|
|
1133
|
+
duration_ms: Date.now() - stopStartedAt,
|
|
1134
|
+
});
|
|
1135
|
+
// promise 可能永不 resolve(计数泄漏);只挂 catch 防 unhandled rejection。
|
|
1136
|
+
void stopPromise.catch(() => undefined);
|
|
1137
|
+
} catch (error) {
|
|
1138
|
+
emit('warn', SHUTDOWN_STEP_EVENT, {
|
|
1139
|
+
step: 'platform.server.stop',
|
|
1140
|
+
status: 'failed',
|
|
1141
|
+
duration_ms: Date.now() - stopStartedAt,
|
|
1142
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1143
|
+
});
|
|
1144
|
+
throw error;
|
|
1145
|
+
}
|
|
1146
|
+
},
|
|
1147
|
+
};
|
|
1148
|
+
}
|