@capybara-hq/kernel 0.0.0-stage → 0.1.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +2 -0
- package/README.md +20 -2
- package/bootstrap.json +22 -0
- package/dist/admin/admin.controller.d.ts +139 -0
- package/dist/admin/admin.controller.js +238 -0
- package/dist/admin/extensions.controller.d.ts +100 -0
- package/dist/admin/extensions.controller.js +226 -0
- package/dist/admin/setup.controller.d.ts +36 -0
- package/dist/admin/setup.controller.js +106 -0
- package/dist/admin/setup.service.d.ts +47 -0
- package/dist/admin/setup.service.js +90 -0
- package/dist/agents/agents.controller.d.ts +205 -0
- package/dist/agents/agents.controller.js +144 -0
- package/dist/agents/agents.service.d.ts +177 -0
- package/dist/agents/agents.service.js +677 -0
- package/dist/agents/definition.d.ts +198 -0
- package/dist/agents/definition.js +152 -0
- package/dist/agents/models.controller.d.ts +13 -0
- package/dist/agents/models.controller.js +31 -0
- package/dist/agents/templates.controller.d.ts +15 -0
- package/dist/agents/templates.controller.js +37 -0
- package/dist/agents/templates.d.ts +83 -0
- package/dist/agents/templates.js +173 -0
- package/dist/catalog/admin-catalog.controller.d.ts +143 -0
- package/dist/catalog/admin-catalog.controller.js +245 -0
- package/dist/catalog/catalog.service.d.ts +430 -0
- package/dist/catalog/catalog.service.js +882 -0
- package/dist/catalog/claude/agents.d.ts +27 -0
- package/dist/catalog/claude/agents.js +270 -0
- package/dist/catalog/claude/commands.d.ts +50 -0
- package/dist/catalog/claude/commands.js +179 -0
- package/dist/catalog/claude/manifest.d.ts +69 -0
- package/dist/catalog/claude/manifest.js +134 -0
- package/dist/catalog/claude/marketplace.d.ts +35 -0
- package/dist/catalog/claude/marketplace.js +194 -0
- package/dist/catalog/claude/mcp.d.ts +33 -0
- package/dist/catalog/claude/mcp.js +226 -0
- package/dist/catalog/claude/report.d.ts +86 -0
- package/dist/catalog/claude/report.js +121 -0
- package/dist/catalog/claude/translate.d.ts +56 -0
- package/dist/catalog/claude/translate.js +857 -0
- package/dist/catalog/cli.d.ts +46 -0
- package/dist/catalog/cli.js +211 -0
- package/dist/catalog/git-source.d.ts +127 -0
- package/dist/catalog/git-source.js +520 -0
- package/dist/catalog/marketplace-fetch.d.ts +99 -0
- package/dist/catalog/marketplace-fetch.js +203 -0
- package/dist/catalog/marketplaces.controller.d.ts +97 -0
- package/dist/catalog/marketplaces.controller.js +197 -0
- package/dist/catalog/marketplaces.service.d.ts +340 -0
- package/dist/catalog/marketplaces.service.js +1217 -0
- package/dist/catalog/org-catalog.controller.d.ts +128 -0
- package/dist/catalog/org-catalog.controller.js +277 -0
- package/dist/catalog/org-catalog.service.d.ts +246 -0
- package/dist/catalog/org-catalog.service.js +625 -0
- package/dist/catalog/plugin-import.d.ts +436 -0
- package/dist/catalog/plugin-import.js +1069 -0
- package/dist/catalog/plugin-install.d.ts +447 -0
- package/dist/catalog/plugin-install.js +1333 -0
- package/dist/catalog/plugin-package.d.ts +143 -0
- package/dist/catalog/plugin-package.js +382 -0
- package/dist/catalog/plugin-upgrade.d.ts +222 -0
- package/dist/catalog/plugin-upgrade.js +1219 -0
- package/dist/catalog/requests.service.d.ts +162 -0
- package/dist/catalog/requests.service.js +504 -0
- package/dist/catalog/schema-path.d.ts +7 -0
- package/dist/catalog/schema-path.js +63 -0
- package/dist/catalog/upgrade-targets.d.ts +59 -0
- package/dist/catalog/upgrade-targets.js +90 -0
- package/dist/catalog/versions.d.ts +31 -0
- package/dist/catalog/versions.js +44 -0
- package/dist/channels/actions.d.ts +37 -0
- package/dist/channels/actions.js +121 -0
- package/dist/channels/cards.d.ts +44 -0
- package/dist/channels/cards.js +156 -0
- package/dist/channels/connections.controller.d.ts +59 -0
- package/dist/channels/connections.controller.js +115 -0
- package/dist/channels/connections.service.d.ts +187 -0
- package/dist/channels/connections.service.js +534 -0
- package/dist/channels/features.d.ts +12 -0
- package/dist/channels/features.js +22 -0
- package/dist/channels/inbound.d.ts +120 -0
- package/dist/channels/inbound.js +332 -0
- package/dist/channels/outbound.d.ts +140 -0
- package/dist/channels/outbound.js +1125 -0
- package/dist/channels/phrases.d.ts +100 -0
- package/dist/channels/phrases.js +81 -0
- package/dist/channels/supervisor.d.ts +182 -0
- package/dist/channels/supervisor.js +625 -0
- package/dist/channels/threads.d.ts +29 -0
- package/dist/channels/threads.js +104 -0
- package/dist/channels/webhook-url.d.ts +16 -0
- package/dist/channels/webhook-url.js +34 -0
- package/dist/channels/webhook.controller.d.ts +19 -0
- package/dist/channels/webhook.controller.js +72 -0
- package/dist/channels/webhook.d.ts +73 -0
- package/dist/channels/webhook.js +274 -0
- package/dist/config/docs.d.ts +9 -0
- package/dist/config/docs.js +85 -0
- package/dist/config/env.d.ts +6 -0
- package/dist/config/env.js +73 -0
- package/dist/config/fields.d.ts +42 -0
- package/dist/config/fields.js +214 -0
- package/dist/config/file-source.d.ts +3 -0
- package/dist/config/file-source.js +31 -0
- package/dist/config/load.d.ts +20 -0
- package/dist/config/load.js +98 -0
- package/dist/config/nacos-source.d.ts +31 -0
- package/dist/config/nacos-source.js +229 -0
- package/dist/config/schema.d.ts +223 -0
- package/dist/config/schema.js +1151 -0
- package/dist/config/sources.d.ts +18 -0
- package/dist/config/sources.js +59 -0
- package/dist/config/types.d.ts +9 -0
- package/dist/config/types.js +7 -0
- package/dist/conversations/artifacts.d.ts +52 -0
- package/dist/conversations/artifacts.js +137 -0
- package/dist/conversations/attachments.controller.d.ts +28 -0
- package/dist/conversations/attachments.controller.js +96 -0
- package/dist/conversations/attachments.service.d.ts +180 -0
- package/dist/conversations/attachments.service.js +578 -0
- package/dist/conversations/conversations.controller.d.ts +288 -0
- package/dist/conversations/conversations.controller.js +607 -0
- package/dist/conversations/conversations.service.d.ts +321 -0
- package/dist/conversations/conversations.service.js +754 -0
- package/dist/conversations/event-log.d.ts +122 -0
- package/dist/conversations/event-log.js +259 -0
- package/dist/conversations/events.d.ts +856 -0
- package/dist/conversations/events.js +639 -0
- package/dist/conversations/files.d.ts +92 -0
- package/dist/conversations/files.js +213 -0
- package/dist/conversations/outputs-read.d.ts +34 -0
- package/dist/conversations/outputs-read.js +37 -0
- package/dist/conversations/queue.d.ts +169 -0
- package/dist/conversations/queue.js +527 -0
- package/dist/conversations/sandbox-status.d.ts +21 -0
- package/dist/conversations/sandbox-status.js +24 -0
- package/dist/conversations/selection.d.ts +46 -0
- package/dist/conversations/selection.js +75 -0
- package/dist/conversations/titles.d.ts +93 -0
- package/dist/conversations/titles.js +422 -0
- package/dist/ctx/bus.d.ts +16 -0
- package/dist/ctx/bus.js +101 -0
- package/dist/ctx/create-ctx.d.ts +109 -0
- package/dist/ctx/create-ctx.js +592 -0
- package/dist/ctx/kv.d.ts +4 -0
- package/dist/ctx/kv.js +31 -0
- package/dist/ctx/lock.d.ts +4 -0
- package/dist/ctx/lock.js +39 -0
- package/dist/ctx/namespace.d.ts +6 -0
- package/dist/ctx/namespace.js +12 -0
- package/dist/ctx/queue.d.ts +25 -0
- package/dist/ctx/queue.js +150 -0
- package/dist/ctx/secrets.d.ts +45 -0
- package/dist/ctx/secrets.js +175 -0
- package/dist/db/kernel-schema.d.ts +1122 -0
- package/dist/db/kernel-schema.js +5 -0
- package/dist/db/migrator.d.ts +28 -0
- package/dist/db/migrator.js +140 -0
- package/dist/db/pool.d.ts +21 -0
- package/dist/db/pool.js +28 -0
- package/dist/db/sql-statements.d.ts +34 -0
- package/dist/db/sql-statements.js +168 -0
- package/dist/errors.d.ts +210 -0
- package/dist/errors.js +212 -0
- package/dist/evals/budget.d.ts +61 -0
- package/dist/evals/budget.js +181 -0
- package/dist/evals/diff.d.ts +55 -0
- package/dist/evals/diff.js +133 -0
- package/dist/evals/judge.d.ts +53 -0
- package/dist/evals/judge.js +149 -0
- package/dist/evals/plan.d.ts +47 -0
- package/dist/evals/plan.js +77 -0
- package/dist/evals/reconstruct.d.ts +137 -0
- package/dist/evals/reconstruct.js +322 -0
- package/dist/evals/recorded-tools.d.ts +54 -0
- package/dist/evals/recorded-tools.js +167 -0
- package/dist/evals/run-replay.d.ts +86 -0
- package/dist/evals/run-replay.js +502 -0
- package/dist/evals/runs.controller.d.ts +100 -0
- package/dist/evals/runs.controller.js +199 -0
- package/dist/evals/runs.service.d.ts +275 -0
- package/dist/evals/runs.service.js +836 -0
- package/dist/evals/sets.controller.d.ts +61 -0
- package/dist/evals/sets.controller.js +183 -0
- package/dist/evals/sets.service.d.ts +128 -0
- package/dist/evals/sets.service.js +558 -0
- package/dist/evals/snapshot.d.ts +76 -0
- package/dist/evals/snapshot.js +207 -0
- package/dist/evals/step-replay.d.ts +113 -0
- package/dist/evals/step-replay.js +181 -0
- package/dist/evals/trajectory.controller.d.ts +41 -0
- package/dist/evals/trajectory.controller.js +88 -0
- package/dist/evals/trajectory.d.ts +144 -0
- package/dist/evals/trajectory.js +338 -0
- package/dist/evals/trajectory.service.d.ts +108 -0
- package/dist/evals/trajectory.service.js +323 -0
- package/dist/evals/worker.d.ts +101 -0
- package/dist/evals/worker.js +789 -0
- package/dist/extensions/admin-ops.d.ts +105 -0
- package/dist/extensions/admin-ops.js +353 -0
- package/dist/extensions/admin-view.d.ts +79 -0
- package/dist/extensions/admin-view.js +327 -0
- package/dist/extensions/approvals.d.ts +119 -0
- package/dist/extensions/approvals.js +205 -0
- package/dist/extensions/blobs.d.ts +45 -0
- package/dist/extensions/blobs.js +160 -0
- package/dist/extensions/bootstrap.d.ts +149 -0
- package/dist/extensions/bootstrap.js +441 -0
- package/dist/extensions/cli.d.ts +61 -0
- package/dist/extensions/cli.js +165 -0
- package/dist/extensions/config-json-schema.d.ts +9 -0
- package/dist/extensions/config-json-schema.js +73 -0
- package/dist/extensions/deployment-config.d.ts +138 -0
- package/dist/extensions/deployment-config.js +394 -0
- package/dist/extensions/enabled.d.ts +31 -0
- package/dist/extensions/enabled.js +55 -0
- package/dist/extensions/hooks.d.ts +161 -0
- package/dist/extensions/hooks.js +425 -0
- package/dist/extensions/host.d.ts +577 -0
- package/dist/extensions/host.js +2071 -0
- package/dist/extensions/inflight.d.ts +69 -0
- package/dist/extensions/inflight.js +277 -0
- package/dist/extensions/installs.d.ts +166 -0
- package/dist/extensions/installs.js +253 -0
- package/dist/extensions/instance.d.ts +167 -0
- package/dist/extensions/instance.js +329 -0
- package/dist/extensions/ledger.d.ts +30 -0
- package/dist/extensions/ledger.js +50 -0
- package/dist/extensions/lifecycle.d.ts +80 -0
- package/dist/extensions/lifecycle.js +152 -0
- package/dist/extensions/migrate-lock.d.ts +51 -0
- package/dist/extensions/migrate-lock.js +100 -0
- package/dist/extensions/org-config.controller.d.ts +24 -0
- package/dist/extensions/org-config.controller.js +59 -0
- package/dist/extensions/org-config.d.ts +169 -0
- package/dist/extensions/org-config.js +520 -0
- package/dist/extensions/package.d.ts +115 -0
- package/dist/extensions/package.js +246 -0
- package/dist/extensions/permission-set.d.ts +117 -0
- package/dist/extensions/permission-set.js +184 -0
- package/dist/extensions/permission-view.d.ts +194 -0
- package/dist/extensions/permission-view.js +284 -0
- package/dist/extensions/registry.d.ts +24 -0
- package/dist/extensions/registry.js +56 -0
- package/dist/extensions/resolve.d.ts +12 -0
- package/dist/extensions/resolve.js +71 -0
- package/dist/extensions/sources.d.ts +69 -0
- package/dist/extensions/sources.js +120 -0
- package/dist/extensions/sync.d.ts +40 -0
- package/dist/extensions/sync.js +242 -0
- package/dist/files/previewers.controller.d.ts +46 -0
- package/dist/files/previewers.controller.js +105 -0
- package/dist/files/previewers.d.ts +100 -0
- package/dist/files/previewers.js +250 -0
- package/dist/http/api.module.d.ts +114 -0
- package/dist/http/api.module.js +448 -0
- package/dist/http/app.d.ts +77 -0
- package/dist/http/app.js +170 -0
- package/dist/http/error.filter.d.ts +21 -0
- package/dist/http/error.filter.js +85 -0
- package/dist/http/gateway.module.d.ts +15 -0
- package/dist/http/gateway.module.js +13 -0
- package/dist/http/health.controller.d.ts +26 -0
- package/dist/http/health.controller.js +79 -0
- package/dist/http/nest-logger.d.ts +20 -0
- package/dist/http/nest-logger.js +28 -0
- package/dist/http/plugin-dispatch.d.ts +68 -0
- package/dist/http/plugin-dispatch.js +200 -0
- package/dist/http/tokens.d.ts +131 -0
- package/dist/http/tokens.js +131 -0
- package/dist/http/zod.pipe.d.ts +8 -0
- package/dist/http/zod.pipe.js +14 -0
- package/dist/identity/accounts.d.ts +93 -0
- package/dist/identity/accounts.js +367 -0
- package/dist/identity/api-tokens.d.ts +73 -0
- package/dist/identity/api-tokens.js +197 -0
- package/dist/identity/audit.d.ts +23 -0
- package/dist/identity/audit.js +41 -0
- package/dist/identity/auth.controller.d.ts +40 -0
- package/dist/identity/auth.controller.js +130 -0
- package/dist/identity/auth.guard.d.ts +41 -0
- package/dist/identity/auth.guard.js +162 -0
- package/dist/identity/binding.d.ts +47 -0
- package/dist/identity/binding.js +84 -0
- package/dist/identity/cookies.d.ts +16 -0
- package/dist/identity/cookies.js +32 -0
- package/dist/identity/credential-check.d.ts +17 -0
- package/dist/identity/credential-check.js +24 -0
- package/dist/identity/enterprise-admin.d.ts +14 -0
- package/dist/identity/enterprise-admin.js +27 -0
- package/dist/identity/external.d.ts +106 -0
- package/dist/identity/external.js +337 -0
- package/dist/identity/hash.d.ts +2 -0
- package/dist/identity/hash.js +3 -0
- package/dist/identity/login.d.ts +6 -0
- package/dist/identity/login.js +20 -0
- package/dist/identity/me.controller.d.ts +61 -0
- package/dist/identity/me.controller.js +159 -0
- package/dist/identity/passwords.d.ts +6 -0
- package/dist/identity/passwords.js +37 -0
- package/dist/identity/principal.d.ts +56 -0
- package/dist/identity/principal.js +38 -0
- package/dist/identity/rate-limit.d.ts +55 -0
- package/dist/identity/rate-limit.js +121 -0
- package/dist/identity/sessions.d.ts +84 -0
- package/dist/identity/sessions.js +306 -0
- package/dist/identity/settings.d.ts +121 -0
- package/dist/identity/settings.js +248 -0
- package/dist/identity/sso.controller.d.ts +59 -0
- package/dist/identity/sso.controller.js +192 -0
- package/dist/identity/sso.d.ts +83 -0
- package/dist/identity/sso.js +202 -0
- package/dist/inbox/inbox.service.d.ts +43 -0
- package/dist/inbox/inbox.service.js +57 -0
- package/dist/index.d.ts +67 -0
- package/dist/index.js +65 -0
- package/dist/kernel.d.ts +256 -0
- package/dist/kernel.js +1326 -0
- package/dist/log.d.ts +48 -0
- package/dist/log.js +229 -0
- package/dist/models/prices.d.ts +53 -0
- package/dist/models/prices.js +121 -0
- package/dist/models/purposes.controller.d.ts +19 -0
- package/dist/models/purposes.controller.js +56 -0
- package/dist/models/purposes.d.ts +140 -0
- package/dist/models/purposes.js +267 -0
- package/dist/net/proxy.d.ts +44 -0
- package/dist/net/proxy.js +162 -0
- package/dist/net/public-address.d.ts +60 -0
- package/dist/net/public-address.js +271 -0
- package/dist/net/safe-fetch.d.ts +38 -0
- package/dist/net/safe-fetch.js +140 -0
- package/dist/orgs/directory-sync.controller.d.ts +14 -0
- package/dist/orgs/directory-sync.controller.js +40 -0
- package/dist/orgs/directory-sync.d.ts +166 -0
- package/dist/orgs/directory-sync.js +558 -0
- package/dist/orgs/invitations.controller.d.ts +58 -0
- package/dist/orgs/invitations.controller.js +137 -0
- package/dist/orgs/invitations.service.d.ts +80 -0
- package/dist/orgs/invitations.service.js +217 -0
- package/dist/orgs/members.service.d.ts +63 -0
- package/dist/orgs/members.service.js +234 -0
- package/dist/orgs/offboarding.d.ts +141 -0
- package/dist/orgs/offboarding.js +398 -0
- package/dist/orgs/org-lock.d.ts +32 -0
- package/dist/orgs/org-lock.js +46 -0
- package/dist/orgs/org.guard.d.ts +35 -0
- package/dist/orgs/org.guard.js +95 -0
- package/dist/orgs/orgs.controller.d.ts +78 -0
- package/dist/orgs/orgs.controller.js +192 -0
- package/dist/orgs/orgs.service.d.ts +61 -0
- package/dist/orgs/orgs.service.js +209 -0
- package/dist/orgs/roles.d.ts +13 -0
- package/dist/orgs/roles.js +58 -0
- package/dist/orgs/settings.controller.d.ts +20 -0
- package/dist/orgs/settings.controller.js +53 -0
- package/dist/orgs/settings.service.d.ts +120 -0
- package/dist/orgs/settings.service.js +178 -0
- package/dist/packages/npm.d.ts +50 -0
- package/dist/packages/npm.js +218 -0
- package/dist/packages/provenance.d.ts +47 -0
- package/dist/packages/provenance.js +147 -0
- package/dist/packages/tgz.d.ts +76 -0
- package/dist/packages/tgz.js +225 -0
- package/dist/runtime/abort.d.ts +32 -0
- package/dist/runtime/abort.js +71 -0
- package/dist/runtime/checkpointer.d.ts +32 -0
- package/dist/runtime/checkpointer.js +243 -0
- package/dist/runtime/context/build.d.ts +254 -0
- package/dist/runtime/context/build.js +693 -0
- package/dist/runtime/context/claude-tools.d.ts +11 -0
- package/dist/runtime/context/claude-tools.js +24 -0
- package/dist/runtime/context/compaction.d.ts +26 -0
- package/dist/runtime/context/compaction.js +195 -0
- package/dist/runtime/context/pairing.d.ts +11 -0
- package/dist/runtime/context/pairing.js +82 -0
- package/dist/runtime/context/reminders.d.ts +5 -0
- package/dist/runtime/context/reminders.js +11 -0
- package/dist/runtime/context/skills.d.ts +105 -0
- package/dist/runtime/context/skills.js +283 -0
- package/dist/runtime/context/tokens.d.ts +19 -0
- package/dist/runtime/context/tokens.js +104 -0
- package/dist/runtime/conversation-lock.d.ts +40 -0
- package/dist/runtime/conversation-lock.js +97 -0
- package/dist/runtime/hook-calls.d.ts +84 -0
- package/dist/runtime/hook-calls.js +136 -0
- package/dist/runtime/langgraph-loop.d.ts +52 -0
- package/dist/runtime/langgraph-loop.js +247 -0
- package/dist/runtime/loop.d.ts +93 -0
- package/dist/runtime/loop.js +7 -0
- package/dist/runtime/maintenance.d.ts +80 -0
- package/dist/runtime/maintenance.js +147 -0
- package/dist/runtime/media-cache.d.ts +21 -0
- package/dist/runtime/media-cache.js +51 -0
- package/dist/runtime/model-call.d.ts +176 -0
- package/dist/runtime/model-call.js +1049 -0
- package/dist/runtime/providers.d.ts +86 -0
- package/dist/runtime/providers.js +224 -0
- package/dist/runtime/quota.d.ts +29 -0
- package/dist/runtime/quota.js +70 -0
- package/dist/runtime/run-finish.d.ts +45 -0
- package/dist/runtime/run-finish.js +69 -0
- package/dist/runtime/run-queue.d.ts +121 -0
- package/dist/runtime/run-queue.js +493 -0
- package/dist/runtime/run-worker.d.ts +138 -0
- package/dist/runtime/run-worker.js +805 -0
- package/dist/runtime/stream.controller.d.ts +34 -0
- package/dist/runtime/stream.controller.js +122 -0
- package/dist/runtime/stream.d.ts +63 -0
- package/dist/runtime/stream.js +262 -0
- package/dist/runtime/subagents/child.d.ts +80 -0
- package/dist/runtime/subagents/child.js +225 -0
- package/dist/runtime/subagents/definition.d.ts +103 -0
- package/dist/runtime/subagents/definition.js +392 -0
- package/dist/runtime/subagents/dispatch.d.ts +69 -0
- package/dist/runtime/subagents/dispatch.js +502 -0
- package/dist/runtime/subagents/limits.d.ts +23 -0
- package/dist/runtime/subagents/limits.js +34 -0
- package/dist/runtime/subagents/org-agents.d.ts +50 -0
- package/dist/runtime/subagents/org-agents.js +70 -0
- package/dist/runtime/subagents/preamble.d.ts +7 -0
- package/dist/runtime/subagents/preamble.js +11 -0
- package/dist/runtime/subagents/progress.d.ts +26 -0
- package/dist/runtime/subagents/progress.js +36 -0
- package/dist/runtime/subagents/roster.d.ts +55 -0
- package/dist/runtime/subagents/roster.js +111 -0
- package/dist/runtime/subagents/skill-fork.d.ts +123 -0
- package/dist/runtime/subagents/skill-fork.js +259 -0
- package/dist/runtime/usage-report.d.ts +163 -0
- package/dist/runtime/usage-report.js +550 -0
- package/dist/runtime/waits.d.ts +233 -0
- package/dist/runtime/waits.js +883 -0
- package/dist/sandbox/leases.d.ts +169 -0
- package/dist/sandbox/leases.js +515 -0
- package/dist/sandbox/lifecycle.d.ts +21 -0
- package/dist/sandbox/lifecycle.js +68 -0
- package/dist/sandbox/sandbox.service.d.ts +249 -0
- package/dist/sandbox/sandbox.service.js +908 -0
- package/dist/skills/catalog.d.ts +149 -0
- package/dist/skills/catalog.js +405 -0
- package/dist/skills/changes.controller.d.ts +56 -0
- package/dist/skills/changes.controller.js +136 -0
- package/dist/skills/changes.service.d.ts +175 -0
- package/dist/skills/changes.service.js +805 -0
- package/dist/skills/invocable.controller.d.ts +23 -0
- package/dist/skills/invocable.controller.js +50 -0
- package/dist/skills/invocation-keys.d.ts +23 -0
- package/dist/skills/invocation-keys.js +44 -0
- package/dist/skills/invoke.d.ts +135 -0
- package/dist/skills/invoke.js +286 -0
- package/dist/skills/package.d.ts +87 -0
- package/dist/skills/package.js +227 -0
- package/dist/skills/skills.controller.d.ts +40 -0
- package/dist/skills/skills.controller.js +110 -0
- package/dist/skills/skills.service.d.ts +192 -0
- package/dist/skills/skills.service.js +567 -0
- package/dist/storage/prefix.d.ts +36 -0
- package/dist/storage/prefix.js +104 -0
- package/dist/storage/purge.d.ts +27 -0
- package/dist/storage/purge.js +75 -0
- package/dist/storage/storage.service.d.ts +44 -0
- package/dist/storage/storage.service.js +145 -0
- package/dist/text.d.ts +13 -0
- package/dist/text.js +13 -0
- package/dist/tools/approvals.controller.d.ts +53 -0
- package/dist/tools/approvals.controller.js +128 -0
- package/dist/tools/approvals.service.d.ts +172 -0
- package/dist/tools/approvals.service.js +568 -0
- package/dist/tools/breaker.d.ts +28 -0
- package/dist/tools/breaker.js +72 -0
- package/dist/tools/builtins/agent.d.ts +81 -0
- package/dist/tools/builtins/agent.js +223 -0
- package/dist/tools/builtins/ask-user.d.ts +28 -0
- package/dist/tools/builtins/ask-user.js +139 -0
- package/dist/tools/builtins/read-tool-output.d.ts +18 -0
- package/dist/tools/builtins/read-tool-output.js +108 -0
- package/dist/tools/builtins/sandbox/bash.d.ts +16 -0
- package/dist/tools/builtins/sandbox/bash.js +137 -0
- package/dist/tools/builtins/sandbox/common.d.ts +114 -0
- package/dist/tools/builtins/sandbox/common.js +304 -0
- package/dist/tools/builtins/sandbox/deliver.d.ts +5 -0
- package/dist/tools/builtins/sandbox/deliver.js +180 -0
- package/dist/tools/builtins/sandbox/edit.d.ts +4 -0
- package/dist/tools/builtins/sandbox/edit.js +98 -0
- package/dist/tools/builtins/sandbox/glob-match.d.ts +25 -0
- package/dist/tools/builtins/sandbox/glob-match.js +240 -0
- package/dist/tools/builtins/sandbox/glob.d.ts +4 -0
- package/dist/tools/builtins/sandbox/glob.js +104 -0
- package/dist/tools/builtins/sandbox/grep.d.ts +9 -0
- package/dist/tools/builtins/sandbox/grep.js +133 -0
- package/dist/tools/builtins/sandbox/index.d.ts +12 -0
- package/dist/tools/builtins/sandbox/index.js +27 -0
- package/dist/tools/builtins/sandbox/names.d.ts +7 -0
- package/dist/tools/builtins/sandbox/names.js +20 -0
- package/dist/tools/builtins/sandbox/read.d.ts +8 -0
- package/dist/tools/builtins/sandbox/read.js +121 -0
- package/dist/tools/builtins/sandbox/write.d.ts +4 -0
- package/dist/tools/builtins/sandbox/write.js +88 -0
- package/dist/tools/builtins/skill-load.d.ts +53 -0
- package/dist/tools/builtins/skill-load.js +446 -0
- package/dist/tools/builtins/skill-write.d.ts +59 -0
- package/dist/tools/builtins/skill-write.js +244 -0
- package/dist/tools/builtins/tool-search.d.ts +31 -0
- package/dist/tools/builtins/tool-search.js +171 -0
- package/dist/tools/connector-content.controller.d.ts +34 -0
- package/dist/tools/connector-content.controller.js +78 -0
- package/dist/tools/connector-content.d.ts +104 -0
- package/dist/tools/connector-content.js +267 -0
- package/dist/tools/connectors.controller.d.ts +210 -0
- package/dist/tools/connectors.controller.js +234 -0
- package/dist/tools/connectors.service.d.ts +303 -0
- package/dist/tools/connectors.service.js +1102 -0
- package/dist/tools/credentials.d.ts +139 -0
- package/dist/tools/credentials.js +351 -0
- package/dist/tools/drift.d.ts +141 -0
- package/dist/tools/drift.js +539 -0
- package/dist/tools/elicitation.d.ts +81 -0
- package/dist/tools/elicitation.js +266 -0
- package/dist/tools/endpoint.d.ts +18 -0
- package/dist/tools/endpoint.js +115 -0
- package/dist/tools/info.d.ts +67 -0
- package/dist/tools/info.js +113 -0
- package/dist/tools/naming.d.ts +27 -0
- package/dist/tools/naming.js +47 -0
- package/dist/tools/oauth/discovery.d.ts +65 -0
- package/dist/tools/oauth/discovery.js +307 -0
- package/dist/tools/oauth/flow.d.ts +63 -0
- package/dist/tools/oauth/flow.js +237 -0
- package/dist/tools/oauth/oauth.controller.d.ts +31 -0
- package/dist/tools/oauth/oauth.controller.js +95 -0
- package/dist/tools/oauth/tokens.d.ts +111 -0
- package/dist/tools/oauth/tokens.js +258 -0
- package/dist/tools/outputs.d.ts +61 -0
- package/dist/tools/outputs.js +156 -0
- package/dist/tools/pipeline.d.ts +322 -0
- package/dist/tools/pipeline.js +1236 -0
- package/dist/tools/policy.d.ts +60 -0
- package/dist/tools/policy.js +236 -0
- package/dist/tools/questions.controller.d.ts +24 -0
- package/dist/tools/questions.controller.js +58 -0
- package/dist/tools/questions.service.d.ts +103 -0
- package/dist/tools/questions.service.js +295 -0
- package/dist/tools/redact.d.ts +20 -0
- package/dist/tools/redact.js +60 -0
- package/dist/tools/registry.d.ts +246 -0
- package/dist/tools/registry.js +481 -0
- package/dist/tools/resources.d.ts +16 -0
- package/dist/tools/resources.js +76 -0
- package/dist/tools/specs.d.ts +14 -0
- package/dist/tools/specs.js +31 -0
- package/dist/tools/validate.d.ts +20 -0
- package/dist/tools/validate.js +183 -0
- package/dist/tools/view.d.ts +43 -0
- package/dist/tools/view.js +225 -0
- package/dist/ui/embed-token.d.ts +31 -0
- package/dist/ui/embed-token.js +132 -0
- package/dist/ui/registry.d.ts +58 -0
- package/dist/ui/registry.js +90 -0
- package/dist/ui/ui-stream.d.ts +37 -0
- package/dist/ui/ui-stream.js +162 -0
- package/dist/ui/views.controller.d.ts +81 -0
- package/dist/ui/views.controller.js +261 -0
- package/dist/ui/views.d.ts +155 -0
- package/dist/ui/views.js +306 -0
- package/dist/version.d.ts +5 -0
- package/dist/version.js +6 -0
- package/package.json +67 -3
- package/src/migrations/0001_init.sql +8 -0
- package/src/migrations/0002_secrets.sql +8 -0
- package/src/migrations/0003_identity.sql +117 -0
- package/src/migrations/0004_plugin_org_config_nullable.sql +3 -0
- package/src/migrations/0005_agents.sql +27 -0
- package/src/migrations/0006_conversations.sql +37 -0
- package/src/migrations/0007_checkpoints.sql +26 -0
- package/src/migrations/0008_runs_trigger_seq.sql +3 -0
- package/src/migrations/0009_runs_active_unique.sql +4 -0
- package/src/migrations/0010_tools.sql +125 -0
- package/src/migrations/0011_approvals_spec.sql +10 -0
- package/src/migrations/0012_run_waits.sql +24 -0
- package/src/migrations/0013_app_tools_source.sql +4 -0
- package/src/migrations/0014_tool_specs.sql +8 -0
- package/src/migrations/0015_tool_drift.sql +20 -0
- package/src/migrations/0016_plugin_permissions.sql +11 -0
- package/src/migrations/0017_identity_sources.sql +6 -0
- package/src/migrations/0018_channels.sql +74 -0
- package/src/migrations/0019_identity_trust.sql +17 -0
- package/src/migrations/0020_channel_card_lookup.sql +10 -0
- package/src/migrations/0021_org_storage_purge.sql +9 -0
- package/src/migrations/0022_attachments.sql +29 -0
- package/src/migrations/0023_sandboxes.sql +37 -0
- package/src/migrations/0024_skills.sql +46 -0
- package/src/migrations/0025_skills_catalog_idx.sql +6 -0
- package/src/migrations/0026_skill_changes.sql +34 -0
- package/src/migrations/0027_model_prices.sql +18 -0
- package/src/migrations/0028_evals.sql +105 -0
- package/src/migrations/0029_model_purposes.sql +18 -0
- package/src/migrations/0030_plugin_installs.sql +73 -0
- package/src/migrations/0031_plugin_snapshot_source.sql +6 -0
- package/src/migrations/0032_plugin_deployment_configs.sql +10 -0
- package/src/migrations/0033_rename_apps_to_connectors.sql +25 -0
- package/src/migrations/0034_directory.sql +49 -0
- package/src/migrations/0035_catalogs.sql +40 -0
- package/src/migrations/0036_app_import_staging.sql +17 -0
- package/src/migrations/0037_directory_installs.sql +92 -0
- package/src/migrations/0038_channel_inbound_mode.sql +6 -0
- package/src/migrations/0039_channel_card_pending.sql +8 -0
- package/src/migrations/0040_usage_report_sweep.sql +10 -0
- package/src/migrations/0041_rename_plugins_to_extensions.sql +38 -0
- package/src/migrations/0042_rename_directory_to_catalog.sql +80 -0
- package/src/migrations/0043_rename_app_installs_to_plugin_installs.sql +20 -0
- package/src/migrations/0044_catalog_one_kind.sql +90 -0
- package/src/migrations/0045_plugin_dependencies.sql +9 -0
- package/src/migrations/0046_git_sources.sql +25 -0
- package/src/migrations/0047_marketplace_entry_heads.sql +7 -0
- package/src/migrations/0048_marketplace_entry_trees.sql +8 -0
- package/src/migrations/0049_plugin_upgrades.sql +37 -0
- package/src/migrations/0050_bootstrap.sql +53 -0
- package/src/migrations/0051_claude_compat.sql +26 -0
- package/src/migrations/0052_conversations_account_agent_idx.sql +5 -0
- package/src/migrations/0053_subagents.sql +73 -0
- package/src/migrations/0054_subagent_wait_expiry.sql +7 -0
- package/src/migrations/0055_subagent_parent_indexes.sql +10 -0
- package/src/migrations/0056_approval_reason.sql +3 -0
- package/src/migrations/0057_conversation_titles.sql +11 -0
- package/src/migrations/0058_conversation_selection.sql +4 -0
- package/src/migrations/0059_conversation_queue.sql +22 -0
- package/src/migrations/0060_file_previewers.sql +10 -0
- package/src/migrations/0061_queue_selection.sql +5 -0
- package/src/migrations/0062_queued_skill.sql +8 -0
package/dist/http/app.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import "reflect-metadata";
|
|
8
|
+
import fastifyCookie from "@fastify/cookie";
|
|
9
|
+
import { Module } from "@nestjs/common";
|
|
10
|
+
import { APP_FILTER, NestFactory } from "@nestjs/core";
|
|
11
|
+
import { FastifyAdapter } from "@nestjs/platform-fastify";
|
|
12
|
+
import { ApiError, errorBody } from "../errors.js";
|
|
13
|
+
import { authorizeEnterpriseAdmin } from "../identity/auth.guard.js";
|
|
14
|
+
import { ErrorFilter, redactPath } from "./error.filter.js";
|
|
15
|
+
import { registerGatewayRoutes } from "./gateway.module.js";
|
|
16
|
+
import { HealthController } from "./health.controller.js";
|
|
17
|
+
import { NestLogAdapter } from "./nest-logger.js";
|
|
18
|
+
import { createPluginRouter, registerPluginDispatch, staticRouteTable, } from "./plugin-dispatch.js";
|
|
19
|
+
import { ACCOUNTS, API_TOKENS, HEALTH_OPTIONS, KERNEL_LOG, SESSIONS } from "./tokens.js";
|
|
20
|
+
/** The extension package upload route (Fastify route template). */
|
|
21
|
+
export const EXTENSION_PACKAGE_UPLOAD_ROUTE = "/api/v1/admin/extensions/packages/file";
|
|
22
|
+
/** The plugin package upload route of the catalog import (Fastify route template). */
|
|
23
|
+
export const CATALOG_UPLOAD_ROUTE = "/api/v1/admin/catalog/import/file";
|
|
24
|
+
/**
|
|
25
|
+
* The upload routes that take raw bytes (`application/octet-stream`, limit `packages.maxBytes`,
|
|
26
|
+
* the enterprise admin is authenticated before the body is read).
|
|
27
|
+
*/
|
|
28
|
+
export const PACKAGE_UPLOAD_ROUTES = new Set([
|
|
29
|
+
EXTENSION_PACKAGE_UPLOAD_ROUTE,
|
|
30
|
+
CATALOG_UPLOAD_ROUTE,
|
|
31
|
+
]);
|
|
32
|
+
/**
|
|
33
|
+
* 把 `http.trustProxy` 配置转成 Fastify 的 trustProxy。布尔与 IP / CIDR 列表原样传入;
|
|
34
|
+
* 跳数转成 `(addr, hop) => hop < n`:Fastify 5.12 起对 number 一律 fail closed(不信任任何一跳),
|
|
35
|
+
* 所以由这里实现跳数语义——前提是服务只能经由这 n 层代理访问(配置说明里已写明,并推荐 CIDR 列表)。
|
|
36
|
+
*/
|
|
37
|
+
function fastifyTrustProxy(tp) {
|
|
38
|
+
return typeof tp === "number" ? (_addr, hop) => hop < tp : tp;
|
|
39
|
+
}
|
|
40
|
+
/** 允许较大请求体的路由(Fastify 路由模板,只读常量表)及其上限。 */
|
|
41
|
+
const LARGE_BODY_ROUTES = new Set([
|
|
42
|
+
"/api/v1/orgs/:orgId/connectors",
|
|
43
|
+
"/api/v1/orgs/:orgId/connectors/preview",
|
|
44
|
+
]);
|
|
45
|
+
const LARGE_BODY_LIMIT = 6 * 1024 * 1024;
|
|
46
|
+
/** 根模块:总是含健康检查;`serveApi` 时 import `apiModule`;全局错误过滤器。 */
|
|
47
|
+
function rootModule(opts) {
|
|
48
|
+
let RootModule = class RootModule {
|
|
49
|
+
};
|
|
50
|
+
RootModule = __decorate([
|
|
51
|
+
Module({})
|
|
52
|
+
], RootModule);
|
|
53
|
+
return {
|
|
54
|
+
module: RootModule,
|
|
55
|
+
imports: opts.serveApi && opts.apiModule ? [opts.apiModule] : [],
|
|
56
|
+
controllers: [HealthController],
|
|
57
|
+
providers: [
|
|
58
|
+
{ provide: KERNEL_LOG, useValue: opts.log },
|
|
59
|
+
{ provide: HEALTH_OPTIONS, useValue: opts.health },
|
|
60
|
+
{ provide: APP_FILTER, useClass: ErrorFilter },
|
|
61
|
+
],
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 创建并初始化内核 HTTP 应用(NestJS + Fastify),不连接任何外部资源。
|
|
66
|
+
* 插件路由不经过 Nest:在 Fastify 的独立作用域里统一转发 `/plugins/*`(见 plugin-dispatch.ts);
|
|
67
|
+
* 插件加载前 `/plugins/*` 一律 404。未匹配的内核路由同样返回 404 错误信封。
|
|
68
|
+
*/
|
|
69
|
+
export async function createHttpApp(opts) {
|
|
70
|
+
const app = await NestFactory.create(rootModule(opts), new FastifyAdapter({ trustProxy: fastifyTrustProxy(opts.trustProxy ?? false) }), { logger: new NestLogAdapter(opts.log), abortOnError: false });
|
|
71
|
+
// Cookie 解析(会话 Cookie);必须在 init 之前注册
|
|
72
|
+
await app.register(fastifyCookie);
|
|
73
|
+
const fastify = app.getHttpAdapter().getInstance();
|
|
74
|
+
const replicaId = opts.replicaId;
|
|
75
|
+
if (replicaId !== undefined) {
|
|
76
|
+
// 直接设在原始响应上:hijack 后自己 writeHead 的 SSE 流也会带上(writeHead 合并已 setHeader 的头)
|
|
77
|
+
fastify.addHook("onRequest", async (_req, reply) => {
|
|
78
|
+
reply.raw.setHeader("x-capybara-replica", replicaId);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
const routes = [];
|
|
82
|
+
fastify.addHook("onRoute", (r) => {
|
|
83
|
+
for (const method of [r.method].flat())
|
|
84
|
+
routes.push({ method, url: r.url });
|
|
85
|
+
// 安装 / 预览连接器的请求体可带最大 2 MB 的 OpenAPI 文档(JSON 转义后更大),其余路由保持默认 1 MiB
|
|
86
|
+
if (LARGE_BODY_ROUTES.has(r.url) && [r.method].flat().includes("POST")) {
|
|
87
|
+
r.bodyLimit = LARGE_BODY_LIMIT;
|
|
88
|
+
}
|
|
89
|
+
if (PACKAGE_UPLOAD_ROUTES.has(r.url) && opts.packageMaxBytes !== undefined) {
|
|
90
|
+
r.bodyLimit = opts.packageMaxBytes + 1;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
// 读请求体之前:包上传(插件包、企业目录包)先认证(未认证 / 非企业管理员的大请求体不读进内存);其余内核路由不收
|
|
94
|
+
// application/octet-stream(415)。插件路由 /plugins/* 在自己的作用域里收任何类型,不受影响
|
|
95
|
+
let authServices;
|
|
96
|
+
const services = () => {
|
|
97
|
+
authServices ??= {
|
|
98
|
+
accounts: app.get(ACCOUNTS, { strict: false }),
|
|
99
|
+
sessions: app.get(SESSIONS, { strict: false }),
|
|
100
|
+
tokens: app.get(API_TOKENS, { strict: false }),
|
|
101
|
+
};
|
|
102
|
+
return authServices;
|
|
103
|
+
};
|
|
104
|
+
const sendError = (reply, e, method, url) => {
|
|
105
|
+
if (e instanceof ApiError) {
|
|
106
|
+
return reply.code(e.status).send(errorBody(e.code, e.message, e.details));
|
|
107
|
+
}
|
|
108
|
+
opts.log.error("http handler failed", { method, path: redactPath(url), err: e });
|
|
109
|
+
return reply.code(500).send(errorBody("internal", "Internal error"));
|
|
110
|
+
};
|
|
111
|
+
fastify.addHook("onRequest", async (req, reply) => {
|
|
112
|
+
if (!req.url.startsWith("/api/"))
|
|
113
|
+
return;
|
|
114
|
+
if (req.method === "POST" && PACKAGE_UPLOAD_ROUTES.has(req.routeOptions.url ?? "")) {
|
|
115
|
+
try {
|
|
116
|
+
await authorizeEnterpriseAdmin(req, services());
|
|
117
|
+
}
|
|
118
|
+
catch (e) {
|
|
119
|
+
return sendError(reply, e, req.method, req.url);
|
|
120
|
+
}
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const type = String(req.headers["content-type"] ?? "")
|
|
124
|
+
.split(";")[0]
|
|
125
|
+
?.trim()
|
|
126
|
+
.toLowerCase();
|
|
127
|
+
if (type === "application/octet-stream") {
|
|
128
|
+
return reply
|
|
129
|
+
.code(415)
|
|
130
|
+
.send(errorBody("unsupported_media_type", "This endpoint does not accept application/octet-stream request bodies"));
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
// 原始字节的请求体(只有包上传路由能走到这里,见上面的 onRequest):交给处理函数一个 Buffer
|
|
134
|
+
fastify.addContentTypeParser("application/octet-stream", { parseAs: "buffer" }, (_req, body, done) => done(null, body));
|
|
135
|
+
let table;
|
|
136
|
+
let unwatch;
|
|
137
|
+
const dispatch = opts.servePlugins
|
|
138
|
+
? await registerPluginDispatch(fastify, () => table, opts.log)
|
|
139
|
+
: undefined;
|
|
140
|
+
if (opts.gateway)
|
|
141
|
+
await registerGatewayRoutes(fastify, opts.gateway, opts.log);
|
|
142
|
+
await app.init();
|
|
143
|
+
return {
|
|
144
|
+
inject: (o) => fastify.inject(o),
|
|
145
|
+
routes: () => [...routes],
|
|
146
|
+
connections: () => new Promise((resolve, reject) => fastify.server.getConnections((err, n) => (err ? reject(err) : resolve(n)))),
|
|
147
|
+
mountPlugins(pluginRoutes) {
|
|
148
|
+
if (table)
|
|
149
|
+
throw new Error("plugin routes already mounted");
|
|
150
|
+
const t = Array.isArray(pluginRoutes) ? staticRouteTable(pluginRoutes) : pluginRoutes;
|
|
151
|
+
// 先建一次:路径不在 /plugins/ 下的立即报错
|
|
152
|
+
createPluginRouter(t.routes());
|
|
153
|
+
table = t;
|
|
154
|
+
// 插件实例撤销 / 替换:中止它进行中的请求(SSE 等长连接不留在旧实例上)
|
|
155
|
+
unwatch = t.onChange?.((plugin) => dispatch?.abortPlugin(plugin));
|
|
156
|
+
},
|
|
157
|
+
async listen(port) {
|
|
158
|
+
await app.listen(port, "0.0.0.0");
|
|
159
|
+
const addr = fastify.server.address();
|
|
160
|
+
return addr && typeof addr === "object" ? addr.port : port;
|
|
161
|
+
},
|
|
162
|
+
close: () => {
|
|
163
|
+
unwatch?.();
|
|
164
|
+
dispatch?.abortAll();
|
|
165
|
+
return app.close();
|
|
166
|
+
},
|
|
167
|
+
abortPluginRequests: () => dispatch?.abortAll(),
|
|
168
|
+
closeAllConnections: () => fastify.server.closeAllConnections(),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Logger } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { type ArgumentsHost, type ExceptionFilter } from "@nestjs/common";
|
|
3
|
+
import { type ErrorCode } from "../errors.js";
|
|
4
|
+
/** 框架错误的状态码 → 通用错误码(插件分发作用域的 Fastify 错误处理同样使用)。 */
|
|
5
|
+
export declare function codeForStatus(status: number): ErrorCode;
|
|
6
|
+
/**
|
|
7
|
+
* 记日志用的请求路径:去掉查询串,公开邀请路由 `/api/v1/invitations/<token>` 的令牌段换成 `:token`,
|
|
8
|
+
* 其他任何以 `cap_` 开头的路径段(内核各类令牌的前缀)换成 `:redacted`,令牌不落日志。
|
|
9
|
+
*/
|
|
10
|
+
export declare function redactPath(url: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* 全局错误过滤器:一切异常都转成错误信封 `{ error: { code, message, details? } }`。
|
|
13
|
+
* `ApiError` 原样给出;Nest `HttpException`(含路由不存在的 404)按状态码映射;
|
|
14
|
+
* 其他异常一律 500 `internal` 并记日志,不回显错误信息。
|
|
15
|
+
*/
|
|
16
|
+
export declare class ErrorFilter implements ExceptionFilter {
|
|
17
|
+
private readonly log;
|
|
18
|
+
constructor(log: Logger);
|
|
19
|
+
catch(exception: unknown, host: ArgumentsHost): void;
|
|
20
|
+
private logFailure;
|
|
21
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
+
};
|
|
10
|
+
import { Catch, HttpException, Inject, } from "@nestjs/common";
|
|
11
|
+
import { ApiError, errorBody } from "../errors.js";
|
|
12
|
+
import { KERNEL_LOG } from "./tokens.js";
|
|
13
|
+
/**
|
|
14
|
+
* Nest `HttpException`(框架自身抛出,如路由不存在、请求体解析失败)的状态码 → 通用错误码。
|
|
15
|
+
* 显式列出而不是反查 `ERROR_CODES`:同一状态码下有多个业务码,反查会误取到业务码。
|
|
16
|
+
* 表外的状态一律 `internal`(状态码本身保留)。
|
|
17
|
+
*/
|
|
18
|
+
const GENERIC_CODE_BY_STATUS = new Map([
|
|
19
|
+
[400, "validation_failed"],
|
|
20
|
+
[401, "auth.required"],
|
|
21
|
+
[403, "forbidden"],
|
|
22
|
+
[404, "not_found"],
|
|
23
|
+
[409, "conflict"],
|
|
24
|
+
[413, "payload_too_large"],
|
|
25
|
+
[415, "unsupported_media_type"],
|
|
26
|
+
[429, "rate_limited"],
|
|
27
|
+
]);
|
|
28
|
+
/** 框架错误的状态码 → 通用错误码(插件分发作用域的 Fastify 错误处理同样使用)。 */
|
|
29
|
+
export function codeForStatus(status) {
|
|
30
|
+
return GENERIC_CODE_BY_STATUS.get(status) ?? "internal";
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 记日志用的请求路径:去掉查询串,公开邀请路由 `/api/v1/invitations/<token>` 的令牌段换成 `:token`,
|
|
34
|
+
* 其他任何以 `cap_` 开头的路径段(内核各类令牌的前缀)换成 `:redacted`,令牌不落日志。
|
|
35
|
+
*/
|
|
36
|
+
export function redactPath(url) {
|
|
37
|
+
const path = url.split("?")[0] ?? "";
|
|
38
|
+
return path
|
|
39
|
+
.replace(/^\/api\/v1\/invitations\/[^/]+/, "/api/v1/invitations/:token")
|
|
40
|
+
.replace(/\/cap_[^/]*/g, "/:redacted");
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 全局错误过滤器:一切异常都转成错误信封 `{ error: { code, message, details? } }`。
|
|
44
|
+
* `ApiError` 原样给出;Nest `HttpException`(含路由不存在的 404)按状态码映射;
|
|
45
|
+
* 其他异常一律 500 `internal` 并记日志,不回显错误信息。
|
|
46
|
+
*/
|
|
47
|
+
let ErrorFilter = class ErrorFilter {
|
|
48
|
+
log;
|
|
49
|
+
constructor(log) {
|
|
50
|
+
this.log = log;
|
|
51
|
+
}
|
|
52
|
+
catch(exception, host) {
|
|
53
|
+
const http = host.switchToHttp();
|
|
54
|
+
const reply = http.getResponse();
|
|
55
|
+
const req = http.getRequest();
|
|
56
|
+
if (exception instanceof ApiError) {
|
|
57
|
+
if (exception.status >= 500)
|
|
58
|
+
this.logFailure(req, exception);
|
|
59
|
+
reply
|
|
60
|
+
.code(exception.status)
|
|
61
|
+
.send(errorBody(exception.code, exception.message, exception.details));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (exception instanceof HttpException) {
|
|
65
|
+
const status = exception.getStatus();
|
|
66
|
+
if (status < 500) {
|
|
67
|
+
reply.code(status).send(errorBody(codeForStatus(status), exception.message));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
this.logFailure(req, exception);
|
|
71
|
+
reply.code(status).send(errorBody(codeForStatus(status), "Internal error"));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
this.logFailure(req, exception);
|
|
75
|
+
reply.code(500).send(errorBody("internal", "Internal error"));
|
|
76
|
+
}
|
|
77
|
+
logFailure(req, err) {
|
|
78
|
+
this.log.error("http handler failed", { method: req.method, path: redactPath(req.url), err });
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
ErrorFilter = __decorate([
|
|
82
|
+
Catch(),
|
|
83
|
+
__param(0, Inject(KERNEL_LOG))
|
|
84
|
+
], ErrorFilter);
|
|
85
|
+
export { ErrorFilter };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Logger } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import type { FastifyInstance } from "fastify";
|
|
3
|
+
import type { ChannelWebhooks } from "../channels/webhook.js";
|
|
4
|
+
/** What the gateway role serves over HTTP besides health and plugin routes. */
|
|
5
|
+
export interface GatewayRoutes {
|
|
6
|
+
webhooks: Pick<ChannelWebhooks, "handle">;
|
|
7
|
+
/** `channels.webhookMaxBodyBytes`. */
|
|
8
|
+
webhookMaxBodyBytes: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Registers the gateway role's HTTP routes (`serveGateway = roles.includes("gateway")`): today the
|
|
12
|
+
* channel webhook. These are raw Fastify routes, not a Nest module, so the API's global guard and
|
|
13
|
+
* CSRF check do not apply (P-4); each route does its own (plugin-side) verification.
|
|
14
|
+
*/
|
|
15
|
+
export declare function registerGatewayRoutes(fastify: FastifyInstance, routes: GatewayRoutes, log: Pick<Logger, "error">): Promise<void>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { registerChannelWebhookRoute } from "../channels/webhook.controller.js";
|
|
2
|
+
/**
|
|
3
|
+
* Registers the gateway role's HTTP routes (`serveGateway = roles.includes("gateway")`): today the
|
|
4
|
+
* channel webhook. These are raw Fastify routes, not a Nest module, so the API's global guard and
|
|
5
|
+
* CSRF check do not apply (P-4); each route does its own (plugin-side) verification.
|
|
6
|
+
*/
|
|
7
|
+
export async function registerGatewayRoutes(fastify, routes, log) {
|
|
8
|
+
await registerChannelWebhookRoute(fastify, {
|
|
9
|
+
webhooks: routes.webhooks,
|
|
10
|
+
maxBodyBytes: routes.webhookMaxBodyBytes,
|
|
11
|
+
log,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Logger } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import type { FastifyReply } from "fastify";
|
|
3
|
+
/** 一项就绪检查:成功 resolve,失败 reject。 */
|
|
4
|
+
export type ReadinessCheck = () => Promise<void>;
|
|
5
|
+
/** 健康检查参数。 */
|
|
6
|
+
export interface HealthOptions {
|
|
7
|
+
checks: Record<string, ReadinessCheck>;
|
|
8
|
+
isStopping: () => boolean;
|
|
9
|
+
log: Logger;
|
|
10
|
+
/** 单项检查超时,默认 2s。 */
|
|
11
|
+
timeoutMs?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* `GET /healthz`(进程存活,恒 200)与 `GET /readyz`(依赖就绪)。
|
|
15
|
+
* readyz 的 body 只给出每项检查的 `"ok"` / `"error"`,失败原因只进日志(已打码),不进响应——
|
|
16
|
+
* 驱动的错误信息可能带连接串。停机开始后 readyz 立即 503,不再执行检查。
|
|
17
|
+
* 标为 `@Public()`:挂载内核 API 时全局 AuthGuard 也作用于这里。
|
|
18
|
+
*/
|
|
19
|
+
export declare class HealthController {
|
|
20
|
+
private readonly opts;
|
|
21
|
+
constructor(opts: HealthOptions);
|
|
22
|
+
healthz(): {
|
|
23
|
+
ok: true;
|
|
24
|
+
};
|
|
25
|
+
readyz(reply: FastifyReply): Promise<Record<string, unknown>>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
+
};
|
|
10
|
+
import { Controller, Get, Inject, Res } from "@nestjs/common";
|
|
11
|
+
import { Public } from "../identity/principal.js";
|
|
12
|
+
import { HEALTH_OPTIONS } from "./tokens.js";
|
|
13
|
+
/** 单项检查的超时:依赖挂起(如 Redis 正在重连、命令进了离线队列)时也要尽快给出 503。 */
|
|
14
|
+
const CHECK_TIMEOUT_MS = 2_000;
|
|
15
|
+
function withTimeout(p, ms) {
|
|
16
|
+
let timer;
|
|
17
|
+
const timeout = new Promise((_, reject) => {
|
|
18
|
+
timer = setTimeout(() => reject(new Error(`timed out after ${ms}ms`)), ms);
|
|
19
|
+
timer.unref();
|
|
20
|
+
});
|
|
21
|
+
return Promise.race([p, timeout]).finally(() => clearTimeout(timer));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* `GET /healthz`(进程存活,恒 200)与 `GET /readyz`(依赖就绪)。
|
|
25
|
+
* readyz 的 body 只给出每项检查的 `"ok"` / `"error"`,失败原因只进日志(已打码),不进响应——
|
|
26
|
+
* 驱动的错误信息可能带连接串。停机开始后 readyz 立即 503,不再执行检查。
|
|
27
|
+
* 标为 `@Public()`:挂载内核 API 时全局 AuthGuard 也作用于这里。
|
|
28
|
+
*/
|
|
29
|
+
let HealthController = class HealthController {
|
|
30
|
+
opts;
|
|
31
|
+
constructor(opts) {
|
|
32
|
+
this.opts = opts;
|
|
33
|
+
}
|
|
34
|
+
healthz() {
|
|
35
|
+
return { ok: true };
|
|
36
|
+
}
|
|
37
|
+
async readyz(reply) {
|
|
38
|
+
const { opts } = this;
|
|
39
|
+
const stopping = () => {
|
|
40
|
+
reply.code(503);
|
|
41
|
+
return { ok: false, stopping: true };
|
|
42
|
+
};
|
|
43
|
+
if (opts.isStopping())
|
|
44
|
+
return stopping();
|
|
45
|
+
const timeoutMs = opts.timeoutMs ?? CHECK_TIMEOUT_MS;
|
|
46
|
+
const names = Object.keys(opts.checks);
|
|
47
|
+
const results = await Promise.allSettled(names.map((n) => withTimeout(opts.checks[n](), timeoutMs)));
|
|
48
|
+
const body = {};
|
|
49
|
+
let ok = true;
|
|
50
|
+
results.forEach((r, i) => {
|
|
51
|
+
const name = names[i];
|
|
52
|
+
if (r.status === "fulfilled") {
|
|
53
|
+
body[name] = "ok";
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
ok = false;
|
|
57
|
+
body[name] = "error";
|
|
58
|
+
opts.log.warn("readiness check failed", { check: name, err: r.reason });
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
if (opts.isStopping())
|
|
62
|
+
return stopping();
|
|
63
|
+
reply.code(ok ? 200 : 503);
|
|
64
|
+
return { ok, ...body };
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
__decorate([
|
|
68
|
+
Get("healthz")
|
|
69
|
+
], HealthController.prototype, "healthz", null);
|
|
70
|
+
__decorate([
|
|
71
|
+
Get("readyz"),
|
|
72
|
+
__param(0, Res({ passthrough: true }))
|
|
73
|
+
], HealthController.prototype, "readyz", null);
|
|
74
|
+
HealthController = __decorate([
|
|
75
|
+
Controller(),
|
|
76
|
+
Public(),
|
|
77
|
+
__param(0, Inject(HEALTH_OPTIONS))
|
|
78
|
+
], HealthController);
|
|
79
|
+
export { HealthController };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Logger } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import type { LoggerService } from "@nestjs/common";
|
|
3
|
+
/** 可选带 debug 的 logger(内核 logger 有 debug;插件契约的 Logger 没有)。 */
|
|
4
|
+
type MaybeDebugLogger = Logger & {
|
|
5
|
+
debug?: (msg: string, fields?: Record<string, unknown>) => void;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* 把 Nest 自身的日志转给内核 logger:`log`(启动时的模块加载、路由映射等,每次启动几十行)降为 debug,
|
|
9
|
+
* `warn` / `error` 原级别转发,`debug` / `verbose` 丢弃。logger 没有 debug 时 `log` 也丢弃。
|
|
10
|
+
*/
|
|
11
|
+
export declare class NestLogAdapter implements LoggerService {
|
|
12
|
+
private readonly logger;
|
|
13
|
+
constructor(logger: MaybeDebugLogger);
|
|
14
|
+
log(message: unknown, ...params: unknown[]): void;
|
|
15
|
+
warn(message: unknown, ...params: unknown[]): void;
|
|
16
|
+
error(message: unknown, ...params: unknown[]): void;
|
|
17
|
+
debug(): void;
|
|
18
|
+
verbose(): void;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 把 Nest 自身的日志转给内核 logger:`log`(启动时的模块加载、路由映射等,每次启动几十行)降为 debug,
|
|
3
|
+
* `warn` / `error` 原级别转发,`debug` / `verbose` 丢弃。logger 没有 debug 时 `log` 也丢弃。
|
|
4
|
+
*/
|
|
5
|
+
export class NestLogAdapter {
|
|
6
|
+
logger;
|
|
7
|
+
constructor(logger) {
|
|
8
|
+
this.logger = logger;
|
|
9
|
+
}
|
|
10
|
+
log(message, ...params) {
|
|
11
|
+
this.logger.debug?.(String(message), fields(params));
|
|
12
|
+
}
|
|
13
|
+
warn(message, ...params) {
|
|
14
|
+
this.logger.warn(String(message), fields(params));
|
|
15
|
+
}
|
|
16
|
+
error(message, ...params) {
|
|
17
|
+
this.logger.error(String(message), fields(params));
|
|
18
|
+
}
|
|
19
|
+
debug() { }
|
|
20
|
+
verbose() { }
|
|
21
|
+
}
|
|
22
|
+
/** Nest 把上下文名(如 `RoutesResolver`)、错误堆栈作为额外参数传入。 */
|
|
23
|
+
function fields(params) {
|
|
24
|
+
const ctx = params.filter((p) => p !== undefined);
|
|
25
|
+
if (ctx.length === 0)
|
|
26
|
+
return undefined;
|
|
27
|
+
return { nest: ctx.length === 1 ? ctx[0] : ctx };
|
|
28
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Logger } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import type { FastifyInstance } from "fastify";
|
|
3
|
+
import type { Route } from "../ctx/create-ctx.js";
|
|
4
|
+
/** 插件路由都在此前缀下(ctx.http.route 已加 `/plugins/<name>` 前缀)。 */
|
|
5
|
+
export declare const PLUGIN_PREFIX = "/plugins/";
|
|
6
|
+
/** 插件路由表:按方法与路径(不含查询串)找到插件 handler;HEAD 没有专门路由时按 GET 匹配。 */
|
|
7
|
+
export interface PluginRouter {
|
|
8
|
+
find(method: string, path: string): Route["handler"] | undefined;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The live source of extension routes (C17): routes change as extension instances are revoked /
|
|
12
|
+
* replaced, and the route table is rebuilt when `revision()` changes.
|
|
13
|
+
* `unavailable(plugin)`: the extension belongs to this deployment but is not in the registry right
|
|
14
|
+
* now (revoked / pending approval / failed to load), and its `/plugins/<plugin>/*` all answer 503
|
|
15
|
+
* `extension.unavailable` (the routes stay mounted and only gate).
|
|
16
|
+
*/
|
|
17
|
+
export interface PluginRouteTable {
|
|
18
|
+
routes(): Route[];
|
|
19
|
+
revision(): number;
|
|
20
|
+
unavailable(plugin: string): boolean | Promise<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* 插件实例变化(撤销 / 替换)的通知:转发层据此中止该插件进行中请求的 `req.signal`
|
|
23
|
+
* (SSE 等长连接随之收尾,不留在旧实例上)。返回取消订阅函数。
|
|
24
|
+
*/
|
|
25
|
+
onChange?(listener: (plugin: string) => void): () => void;
|
|
26
|
+
}
|
|
27
|
+
/** 固定的路由列表(测试与只挂一次的调用方):版本不变、没有不可用的插件。 */
|
|
28
|
+
export declare function staticRouteTable(routes: Route[]): PluginRouteTable;
|
|
29
|
+
/** 路径里的插件名(`/plugins/<name>/...` 的 `<name>`);不在插件前缀下返回 undefined。 */
|
|
30
|
+
export declare function pluginOfPath(path: string): string | undefined;
|
|
31
|
+
/** 用 find-my-way 建立插件路由表,路径语法与 Fastify 相同;路径不在 `/plugins/` 下时抛错。 */
|
|
32
|
+
export declare function createPluginRouter(routes: Route[]): PluginRouter;
|
|
33
|
+
/**
|
|
34
|
+
* Registers `/plugins/*` in its own encapsulated scope and hands each request to the extension handler
|
|
35
|
+
* as a Web `Request`: the scope removes the default parsers and takes every content type as a raw
|
|
36
|
+
* Buffer, so the body the extension gets is the bytes the client sent.
|
|
37
|
+
* - The extension belongs to this deployment but is not in the registry (revoked and so on) -> 503
|
|
38
|
+
* `extension.unavailable`; when an extension instance is revoked or replaced, the `req.signal` of
|
|
39
|
+
* that extension's in-progress requests is aborted (`abortPlugin`, triggered by the route source's
|
|
40
|
+
* `onChange`);
|
|
41
|
+
* - not mounted or no match -> 404 `not_found`; HEAD without its own route is handled as GET, with no
|
|
42
|
+
* body in the response.
|
|
43
|
+
* - A `Request` that cannot be built (e.g. a malformed Host) -> 400 `validation_failed`, not logged as
|
|
44
|
+
* an error.
|
|
45
|
+
* - `req.signal` aborts only when the client disconnects before the response is written (not on
|
|
46
|
+
* normal completion); long-lived handlers use it to unsubscribe;
|
|
47
|
+
* - a throwing handler is logged (path redacted with `redactPath`) and returns 500 `internal` (the
|
|
48
|
+
* error message is not echoed).
|
|
49
|
+
* - Fastify's own errors (a body over 1 MiB and so on) are mapped to the error envelope by the
|
|
50
|
+
* scope's error handler: 4xx by the common error code table (413 `payload_too_large`, 415
|
|
51
|
+
* `unsupported_media_type` and so on), 5xx are logged and return `internal`.
|
|
52
|
+
* - Shutdown: the returned `abortAll()` aborts the `req.signal` of every in-progress request (the
|
|
53
|
+
* extension's SSE and other long connections wind down by it without using the http shutdown
|
|
54
|
+
* budget); requests arriving afterwards start with an aborted `req.signal`. In-progress
|
|
55
|
+
* AbortControllers are held only for the request's lifetime.
|
|
56
|
+
* So extension handlers either finish quickly or tolerate the abort (see
|
|
57
|
+
* .agents/skills/writing-extensions "Extension route matching semantics").
|
|
58
|
+
* Must be called before Nest `app.init()`.
|
|
59
|
+
*/
|
|
60
|
+
export declare function registerPluginDispatch(fastify: FastifyInstance, getTable: () => PluginRouteTable | undefined, log: Logger): Promise<{
|
|
61
|
+
abortAll(): void;
|
|
62
|
+
abortPlugin(plugin: string): void;
|
|
63
|
+
}>;
|
|
64
|
+
/**
|
|
65
|
+
* 从 Cookie 头里去掉内核会话 Cookie(`cap_at` / `cap_rt`):插件 handler 不经内核鉴权,
|
|
66
|
+
* 拿到这两个 Cookie 就能冒充用户调内核 API。全部去掉后返回 undefined(不传 Cookie 头)。
|
|
67
|
+
*/
|
|
68
|
+
export declare function stripKernelCookies(cookie: string): string | undefined;
|