@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
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type { AuthInjection } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import type { Redis } from "ioredis";
|
|
3
|
+
import { type Transaction } from "kysely";
|
|
4
|
+
import type { KernelConfig } from "../config/schema.js";
|
|
5
|
+
import { type Keyring } from "../ctx/secrets.js";
|
|
6
|
+
import type { KernelDatabase, KernelDb } from "../db/kernel-schema.js";
|
|
7
|
+
import { ApiError } from "../errors.js";
|
|
8
|
+
import type { KernelLogger } from "../log.js";
|
|
9
|
+
import { type OAuthClientRecord, type OAuthTokenRecord } from "./oauth/tokens.js";
|
|
10
|
+
export type Ownership = "org" | "personal";
|
|
11
|
+
/** 静态认证方式(连接器安装时选定);`headers` 的值本身就是凭据。 */
|
|
12
|
+
export type StaticAuth = {
|
|
13
|
+
type: "none";
|
|
14
|
+
} | {
|
|
15
|
+
type: "bearer";
|
|
16
|
+
ownership: Ownership;
|
|
17
|
+
} | {
|
|
18
|
+
type: "api_key";
|
|
19
|
+
ownership: Ownership;
|
|
20
|
+
in: "header" | "query";
|
|
21
|
+
name: string;
|
|
22
|
+
} | {
|
|
23
|
+
type: "basic";
|
|
24
|
+
ownership: Ownership;
|
|
25
|
+
} | {
|
|
26
|
+
type: "headers";
|
|
27
|
+
ownership: Ownership;
|
|
28
|
+
names: string[];
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* OAuth 认证方式。授权码流为个人凭据(每个成员自己连接),`discovery: "mcp"` 时端点经 MCP OAuth 发现得到,
|
|
32
|
+
* `client: "dcr"` 时安装时动态注册客户端(只能配合 MCP 发现);客户端凭据流为组织凭据。
|
|
33
|
+
*/
|
|
34
|
+
export type OAuthAuth = {
|
|
35
|
+
type: "oauth_code";
|
|
36
|
+
ownership: "personal";
|
|
37
|
+
discovery: "mcp" | "manual";
|
|
38
|
+
authorizationUrl?: string | undefined;
|
|
39
|
+
tokenUrl?: string | undefined;
|
|
40
|
+
scopes?: string[] | undefined;
|
|
41
|
+
client: "dcr" | "manual";
|
|
42
|
+
/** 令牌端点的客户端认证方式(有密钥时),默认 client_secret_basic。 */
|
|
43
|
+
tokenAuthMethod?: "client_secret_basic" | "client_secret_post" | undefined;
|
|
44
|
+
} | {
|
|
45
|
+
type: "oauth_client";
|
|
46
|
+
ownership: "org";
|
|
47
|
+
tokenUrl: string;
|
|
48
|
+
scopes?: string[] | undefined;
|
|
49
|
+
tokenAuthMethod?: "client_secret_basic" | "client_secret_post" | undefined;
|
|
50
|
+
};
|
|
51
|
+
export type ConnectorAuth = StaticAuth | OAuthAuth;
|
|
52
|
+
export declare const isOAuth: (auth: ConnectorAuth) => auth is OAuthAuth;
|
|
53
|
+
/** 静态凭据的存储形态(JSON 序列化后信封加密)。 */
|
|
54
|
+
export type StaticSecret = {
|
|
55
|
+
token: string;
|
|
56
|
+
} | {
|
|
57
|
+
username: string;
|
|
58
|
+
password: string;
|
|
59
|
+
} | {
|
|
60
|
+
headers: Record<string, string>;
|
|
61
|
+
};
|
|
62
|
+
export type CredentialOwner = {
|
|
63
|
+
kind: "org";
|
|
64
|
+
} | {
|
|
65
|
+
kind: "user";
|
|
66
|
+
accountId: string;
|
|
67
|
+
};
|
|
68
|
+
/** 缺凭据:只带连接器 id 与归属,绝不带值。 */
|
|
69
|
+
export declare class CredentialMissing extends ApiError {
|
|
70
|
+
readonly connectorId: string;
|
|
71
|
+
readonly ownership: Ownership;
|
|
72
|
+
constructor(connectorId: string, ownership: Ownership);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 删除某账号在该组织所有连接器上的个人凭据(`credentials:app:<connectorId>:user:<accountId>`,含已删除连接器残留的),
|
|
76
|
+
* 成员离职时在其事务内调用(不解密,不需要密钥环)。返回删除条数。
|
|
77
|
+
*/
|
|
78
|
+
export declare function clearAccountCredentials(db: KernelDb | Transaction<KernelDatabase>, orgId: string, accountId: string): Promise<number>;
|
|
79
|
+
/** OAuth 刷新所需的依赖(锁在 Redis,往返限时与本机 http 放行取自配置)。 */
|
|
80
|
+
export interface CredentialsOAuthDeps {
|
|
81
|
+
redis: Redis;
|
|
82
|
+
config: () => KernelConfig;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 连接器凭据:信封加密存入 capybara.secrets,解密后只在构造注入头时出现。OAuth 连接器的 token 也存在这里
|
|
86
|
+
* (个人 / 组织键,同静态凭据),OAuth 客户端存组织级的 `:client` 键;刷新见 oauth/tokens.ts。
|
|
87
|
+
*/
|
|
88
|
+
export declare class Credentials {
|
|
89
|
+
private readonly db;
|
|
90
|
+
private readonly keyring;
|
|
91
|
+
private readonly log;
|
|
92
|
+
private readonly tokens;
|
|
93
|
+
constructor(db: KernelDb, keyring: Keyring, log: KernelLogger, oauth?: CredentialsOAuthDeps);
|
|
94
|
+
private oauth;
|
|
95
|
+
/** 读一条 JSON 凭据;不存在 / 解不开 → null(日志不带内容)。 */
|
|
96
|
+
private readJson;
|
|
97
|
+
/** OAuth 客户端与令牌里的密钥值登记日志打码(logger 只收 ≥ 12 的值)。 */
|
|
98
|
+
private registerSecrets;
|
|
99
|
+
oauthClient(orgId: string, connectorId: string): Promise<OAuthClientRecord | null>;
|
|
100
|
+
setOAuthClient(orgId: string, connectorId: string, client: OAuthClientRecord, trx?: Transaction<KernelDatabase>): Promise<void>;
|
|
101
|
+
oauthTokens(orgId: string, connectorId: string, owner: CredentialOwner): Promise<OAuthTokenRecord | null>;
|
|
102
|
+
setOAuthTokens(orgId: string, connectorId: string, owner: CredentialOwner, rec: OAuthTokenRecord, trx?: Transaction<KernelDatabase>): Promise<void>;
|
|
103
|
+
private secrets;
|
|
104
|
+
/**
|
|
105
|
+
* 按认证方式校验凭据形状与归属;错误(`validation_failed`)只含路径与英文说明,不回显值。
|
|
106
|
+
* 连接器创建时先用它校验、再拿内存中的值连接,连上之后才落库。
|
|
107
|
+
*/
|
|
108
|
+
validate(auth: ConnectorAuth, owner: CredentialOwner, value: unknown): asserts value is StaticSecret;
|
|
109
|
+
setStatic(orgId: string, connectorId: string, auth: ConnectorAuth, owner: CredentialOwner, value: StaticSecret,
|
|
110
|
+
/** 传入时在调用方事务内写入(与连接器行 / 审计同生共死)。 */
|
|
111
|
+
trx?: Transaction<KernelDatabase>): Promise<void>;
|
|
112
|
+
clear(orgId: string, connectorId: string, owner: CredentialOwner, trx?: Transaction<KernelDatabase>): Promise<void>;
|
|
113
|
+
/** 删除某连接器的全部凭据(组织凭据与所有成员的个人凭据),连接器删除时调用。 */
|
|
114
|
+
clearConnector(orgId: string, connectorId: string, trx?: Transaction<KernelDatabase>): Promise<void>;
|
|
115
|
+
/** 删除某账号在该组织所有连接器上的个人凭据,见 {@link clearAccountCredentials}。 */
|
|
116
|
+
clearAccount(orgId: string, accountId: string, trx?: Transaction<KernelDatabase>): Promise<number>;
|
|
117
|
+
/**
|
|
118
|
+
* 持有该连接器个人凭据的**现任成员**(不解密),按凭据最近写入时间倒序(保存静态凭据、OAuth 连接与刷新 token
|
|
119
|
+
* 都会更新写入时间),最多 `limit` 个。漂移检查用它挑个人凭据型连接器的凭据。
|
|
120
|
+
*/
|
|
121
|
+
personalHolders(orgId: string, connectorId: string, limit: number): Promise<string[]>;
|
|
122
|
+
/** 只看与 auth.ownership 对应的那一条凭据是否存在(不解密);none 恒为 connected。 */
|
|
123
|
+
status(orgId: string, connectorId: string, auth: ConnectorAuth, accountId: string, trx?: Transaction<KernelDatabase>): Promise<"connected" | "missing">;
|
|
124
|
+
/** 返回本次请求要注入的头 / 查询参数;缺凭据抛 CredentialMissing。 */
|
|
125
|
+
injection(orgId: string, connectorId: string, auth: ConnectorAuth, accountId: string): Promise<AuthInjection>;
|
|
126
|
+
/**
|
|
127
|
+
* 连接器收到 401 时调用(`stale` 为那次请求注入的鉴权):OAuth 连接器在刷新锁内强制刷新,之后的 `injection()`
|
|
128
|
+
* 返回新 token;refresh 被拒 → 凭据删除并抛 CredentialMissing。静态凭据无事可做。
|
|
129
|
+
*/
|
|
130
|
+
onUnauthorized(orgId: string, connectorId: string, auth: ConnectorAuth, accountId: string, stale?: AuthInjection): Promise<void>;
|
|
131
|
+
/** 「需要重新连接」→ CredentialMissing(个人凭据由管线转成 connection_required)。 */
|
|
132
|
+
private oauthCall;
|
|
133
|
+
/**
|
|
134
|
+
* 由凭据值构造注入(不读库);值登记日志打码。连接器创建时用请求里带的、尚未落库的凭据连接。
|
|
135
|
+
* 值缺字段 → CredentialMissing。
|
|
136
|
+
*/
|
|
137
|
+
injectionFor(connectorId: string, auth: ConnectorAuth, secret: StaticSecret): AuthInjection;
|
|
138
|
+
private build;
|
|
139
|
+
}
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { sql } from "kysely";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { createSecrets } from "../ctx/secrets.js";
|
|
4
|
+
import { ApiError } from "../errors.js";
|
|
5
|
+
import { oauthHttpOptions } from "./oauth/discovery.js";
|
|
6
|
+
import { OAuthReconnectRequired, OAuthTokens, } from "./oauth/tokens.js";
|
|
7
|
+
import { injectionSecrets } from "./redact.js";
|
|
8
|
+
export const isOAuth = (auth) => auth.type === "oauth_code" || auth.type === "oauth_client";
|
|
9
|
+
/** 缺凭据:只带连接器 id 与归属,绝不带值。 */
|
|
10
|
+
export class CredentialMissing extends ApiError {
|
|
11
|
+
connectorId;
|
|
12
|
+
ownership;
|
|
13
|
+
constructor(connectorId, ownership) {
|
|
14
|
+
super("credential.missing", `No credential configured for connector ${connectorId} (${ownership})`);
|
|
15
|
+
this.connectorId = connectorId;
|
|
16
|
+
this.ownership = ownership;
|
|
17
|
+
this.name = "CredentialMissing";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 内核自己的 secrets 命名空间:plugin-sdk 把 `kernel` 列为保留插件名,而 `credentials` 是合法插件名,
|
|
22
|
+
* 会与某个同名插件的 ctx.secrets 相撞,所以凭据用 `kernel` 命名空间加 `credentials:` 键前缀。
|
|
23
|
+
*/
|
|
24
|
+
const NAMESPACE = "kernel";
|
|
25
|
+
/* secrets 键沿用改名前的 `credentials:app:<connectorId>:…`(D17 / C27:已存数据不迁移)。 */
|
|
26
|
+
const NO_COLON = (label, v) => {
|
|
27
|
+
if (v.length === 0 || v.includes(":"))
|
|
28
|
+
throw new Error(`credentials: invalid ${label}`);
|
|
29
|
+
};
|
|
30
|
+
const orgKey = (connectorId) => {
|
|
31
|
+
NO_COLON("connectorId", connectorId);
|
|
32
|
+
return `credentials:app:${connectorId}:org`;
|
|
33
|
+
};
|
|
34
|
+
const userKey = (connectorId, accountId) => {
|
|
35
|
+
NO_COLON("connectorId", connectorId);
|
|
36
|
+
NO_COLON("accountId", accountId);
|
|
37
|
+
return `credentials:app:${connectorId}:user:${accountId}`;
|
|
38
|
+
};
|
|
39
|
+
const keyOf = (connectorId, owner) => owner.kind === "org" ? orgKey(connectorId) : userKey(connectorId, owner.accountId);
|
|
40
|
+
/** OAuth 客户端(组织级,按连接器一条)。 */
|
|
41
|
+
const clientKey = (connectorId) => {
|
|
42
|
+
NO_COLON("connectorId", connectorId);
|
|
43
|
+
return `credentials:app:${connectorId}:client`;
|
|
44
|
+
};
|
|
45
|
+
const ownerOf = (auth, accountId) => auth.type !== "none" && auth.ownership === "personal"
|
|
46
|
+
? { kind: "user", accountId }
|
|
47
|
+
: { kind: "org" };
|
|
48
|
+
const nonEmpty = z.string().min(1);
|
|
49
|
+
const secretSchemas = {
|
|
50
|
+
token: z.strictObject({ token: nonEmpty }),
|
|
51
|
+
basic: z.strictObject({ username: nonEmpty, password: nonEmpty }),
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* 删除某账号在该组织所有连接器上的个人凭据(`credentials:app:<connectorId>:user:<accountId>`,含已删除连接器残留的),
|
|
55
|
+
* 成员离职时在其事务内调用(不解密,不需要密钥环)。返回删除条数。
|
|
56
|
+
*/
|
|
57
|
+
export async function clearAccountCredentials(db, orgId, accountId) {
|
|
58
|
+
NO_COLON("accountId", accountId);
|
|
59
|
+
const prefix = "credentials:app:";
|
|
60
|
+
const suffix = `:user:${accountId}`;
|
|
61
|
+
const r = await db
|
|
62
|
+
.deleteFrom("secrets")
|
|
63
|
+
.where("namespace", "=", NAMESPACE)
|
|
64
|
+
.where("org_id", "=", orgId)
|
|
65
|
+
.where(sql `left(key, ${prefix.length})`, "=", prefix)
|
|
66
|
+
.where(sql `right(key, ${suffix.length})`, "=", suffix)
|
|
67
|
+
.executeTakeFirst();
|
|
68
|
+
return Number(r.numDeletedRows);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 连接器凭据:信封加密存入 capybara.secrets,解密后只在构造注入头时出现。OAuth 连接器的 token 也存在这里
|
|
72
|
+
* (个人 / 组织键,同静态凭据),OAuth 客户端存组织级的 `:client` 键;刷新见 oauth/tokens.ts。
|
|
73
|
+
*/
|
|
74
|
+
export class Credentials {
|
|
75
|
+
db;
|
|
76
|
+
keyring;
|
|
77
|
+
log;
|
|
78
|
+
tokens;
|
|
79
|
+
constructor(db, keyring, log, oauth) {
|
|
80
|
+
this.db = db;
|
|
81
|
+
this.keyring = keyring;
|
|
82
|
+
this.log = log;
|
|
83
|
+
if (oauth) {
|
|
84
|
+
const store = {
|
|
85
|
+
readClient: (orgId, connectorId) => this.oauthClient(orgId, connectorId),
|
|
86
|
+
readTokens: (orgId, connectorId, owner) => this.oauthTokens(orgId, connectorId, owner),
|
|
87
|
+
writeTokens: (orgId, connectorId, owner, rec) => this.setOAuthTokens(orgId, connectorId, owner, rec),
|
|
88
|
+
deleteTokens: (orgId, connectorId, owner) => this.clear(orgId, connectorId, owner),
|
|
89
|
+
};
|
|
90
|
+
this.tokens = new OAuthTokens(store, oauth.redis, () => oauthHttpOptions(oauth.config()), log);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
oauth() {
|
|
94
|
+
if (!this.tokens)
|
|
95
|
+
throw new Error("credentials: OAuth is not configured");
|
|
96
|
+
return this.tokens;
|
|
97
|
+
}
|
|
98
|
+
/** 读一条 JSON 凭据;不存在 / 解不开 → null(日志不带内容)。 */
|
|
99
|
+
async readJson(orgId, key, connectorId) {
|
|
100
|
+
const raw = await this.secrets().get(orgId, key);
|
|
101
|
+
if (raw === null)
|
|
102
|
+
return null;
|
|
103
|
+
try {
|
|
104
|
+
return JSON.parse(raw);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
this.log.warn("credential payload is corrupted", { connectorId });
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** OAuth 客户端与令牌里的密钥值登记日志打码(logger 只收 ≥ 12 的值)。 */
|
|
112
|
+
registerSecrets(values) {
|
|
113
|
+
this.log.addOrgSecrets(values.filter((v) => typeof v === "string" && v !== ""));
|
|
114
|
+
}
|
|
115
|
+
async oauthClient(orgId, connectorId) {
|
|
116
|
+
const v = (await this.readJson(orgId, clientKey(connectorId), connectorId));
|
|
117
|
+
if (v === null || typeof v !== "object" || typeof v.clientId !== "string")
|
|
118
|
+
return null;
|
|
119
|
+
this.registerSecrets([v.clientSecret, v.registration?.accessToken]);
|
|
120
|
+
return v;
|
|
121
|
+
}
|
|
122
|
+
async setOAuthClient(orgId, connectorId, client, trx) {
|
|
123
|
+
this.registerSecrets([client.clientSecret, client.registration?.accessToken]);
|
|
124
|
+
await this.secrets(trx).set(orgId, clientKey(connectorId), JSON.stringify(client));
|
|
125
|
+
}
|
|
126
|
+
async oauthTokens(orgId, connectorId, owner) {
|
|
127
|
+
const v = (await this.readJson(orgId, keyOf(connectorId, owner), connectorId));
|
|
128
|
+
if (v === null || typeof v !== "object" || typeof v.access_token !== "string")
|
|
129
|
+
return null;
|
|
130
|
+
this.registerSecrets([v.access_token, v.refresh_token]);
|
|
131
|
+
return v;
|
|
132
|
+
}
|
|
133
|
+
async setOAuthTokens(orgId, connectorId, owner, rec, trx) {
|
|
134
|
+
this.registerSecrets([rec.access_token, rec.refresh_token]);
|
|
135
|
+
await this.secrets(trx).set(orgId, keyOf(connectorId, owner), JSON.stringify(rec));
|
|
136
|
+
}
|
|
137
|
+
secrets(db = this.db) {
|
|
138
|
+
return createSecrets(db, this.keyring, NAMESPACE);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* 按认证方式校验凭据形状与归属;错误(`validation_failed`)只含路径与英文说明,不回显值。
|
|
142
|
+
* 连接器创建时先用它校验、再拿内存中的值连接,连上之后才落库。
|
|
143
|
+
*/
|
|
144
|
+
validate(auth, owner, value) {
|
|
145
|
+
const fail = (issues) => new ApiError("validation_failed", "Invalid credential", issues);
|
|
146
|
+
if (auth.type === "none")
|
|
147
|
+
throw fail([{ path: "", message: "Auth type none takes no credential" }]);
|
|
148
|
+
if (isOAuth(auth)) {
|
|
149
|
+
throw fail([
|
|
150
|
+
{
|
|
151
|
+
path: "",
|
|
152
|
+
message: "OAuth connectors get their tokens through the connect flow; credentials cannot be set directly",
|
|
153
|
+
},
|
|
154
|
+
]);
|
|
155
|
+
}
|
|
156
|
+
const want = auth.ownership === "org" ? "org" : "user";
|
|
157
|
+
if (owner.kind !== want) {
|
|
158
|
+
throw fail([
|
|
159
|
+
{
|
|
160
|
+
path: "owner",
|
|
161
|
+
message: `Credential owner must be ${want} for ${auth.ownership} ownership`,
|
|
162
|
+
},
|
|
163
|
+
]);
|
|
164
|
+
}
|
|
165
|
+
let schema;
|
|
166
|
+
if (auth.type === "bearer" || auth.type === "api_key")
|
|
167
|
+
schema = secretSchemas.token;
|
|
168
|
+
else if (auth.type === "basic")
|
|
169
|
+
schema = secretSchemas.basic;
|
|
170
|
+
else {
|
|
171
|
+
const names = auth.names;
|
|
172
|
+
schema = z.strictObject({ headers: z.record(z.string(), nonEmpty) }).superRefine((v, ctx) => {
|
|
173
|
+
for (const n of names) {
|
|
174
|
+
if (!(n in v.headers))
|
|
175
|
+
ctx.addIssue({
|
|
176
|
+
code: "custom",
|
|
177
|
+
path: ["headers", n],
|
|
178
|
+
message: "Required header is missing",
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
for (const n of Object.keys(v.headers)) {
|
|
182
|
+
if (!names.includes(n))
|
|
183
|
+
ctx.addIssue({ code: "custom", path: ["headers", n], message: "Unexpected header" });
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
const r = schema.safeParse(value);
|
|
188
|
+
if (!r.success) {
|
|
189
|
+
throw fail(r.error.issues.map((i) => ({ path: i.path.join("."), message: i.message })));
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
async setStatic(orgId, connectorId, auth, owner, value,
|
|
193
|
+
/** 传入时在调用方事务内写入(与连接器行 / 审计同生共死)。 */
|
|
194
|
+
trx) {
|
|
195
|
+
this.validate(auth, owner, value);
|
|
196
|
+
await this.secrets(trx).set(orgId, keyOf(connectorId, owner), JSON.stringify(value));
|
|
197
|
+
}
|
|
198
|
+
async clear(orgId, connectorId, owner, trx) {
|
|
199
|
+
await this.secrets(trx).delete(orgId, keyOf(connectorId, owner));
|
|
200
|
+
}
|
|
201
|
+
/** 删除某连接器的全部凭据(组织凭据与所有成员的个人凭据),连接器删除时调用。 */
|
|
202
|
+
async clearConnector(orgId, connectorId, trx) {
|
|
203
|
+
const prefix = orgKey(connectorId).slice(0, -"org".length);
|
|
204
|
+
await (trx ?? this.db)
|
|
205
|
+
.deleteFrom("secrets")
|
|
206
|
+
.where("namespace", "=", NAMESPACE)
|
|
207
|
+
.where("org_id", "=", orgId)
|
|
208
|
+
.where("key", "like", `${prefix}%`)
|
|
209
|
+
.execute();
|
|
210
|
+
}
|
|
211
|
+
/** 删除某账号在该组织所有连接器上的个人凭据,见 {@link clearAccountCredentials}。 */
|
|
212
|
+
async clearAccount(orgId, accountId, trx) {
|
|
213
|
+
return clearAccountCredentials(trx ?? this.db, orgId, accountId);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* 持有该连接器个人凭据的**现任成员**(不解密),按凭据最近写入时间倒序(保存静态凭据、OAuth 连接与刷新 token
|
|
217
|
+
* 都会更新写入时间),最多 `limit` 个。漂移检查用它挑个人凭据型连接器的凭据。
|
|
218
|
+
*/
|
|
219
|
+
async personalHolders(orgId, connectorId, limit) {
|
|
220
|
+
const prefix = userKey(connectorId, "x").slice(0, -1);
|
|
221
|
+
const rows = await sql `
|
|
222
|
+
SELECT m.account_id FROM capybara.secrets s
|
|
223
|
+
JOIN capybara.memberships m
|
|
224
|
+
ON m.org_id = s.org_id AND m.account_id = substr(s.key, ${prefix.length + 1})
|
|
225
|
+
WHERE s.namespace = ${NAMESPACE} AND s.org_id = ${orgId}
|
|
226
|
+
AND left(s.key, ${prefix.length}) = ${prefix}
|
|
227
|
+
ORDER BY s.updated_at DESC, m.account_id
|
|
228
|
+
LIMIT ${limit}`.execute(this.db);
|
|
229
|
+
return rows.rows.map((r) => r.account_id);
|
|
230
|
+
}
|
|
231
|
+
/** 只看与 auth.ownership 对应的那一条凭据是否存在(不解密);none 恒为 connected。 */
|
|
232
|
+
async status(orgId, connectorId, auth, accountId, trx) {
|
|
233
|
+
if (auth.type === "none")
|
|
234
|
+
return "connected";
|
|
235
|
+
// 客户端凭据流:有客户端即可按需取 token
|
|
236
|
+
const key = auth.type === "oauth_client"
|
|
237
|
+
? clientKey(connectorId)
|
|
238
|
+
: auth.ownership === "personal"
|
|
239
|
+
? userKey(connectorId, accountId)
|
|
240
|
+
: orgKey(connectorId);
|
|
241
|
+
const row = await (trx ?? this.db)
|
|
242
|
+
.selectFrom("secrets")
|
|
243
|
+
.select("key")
|
|
244
|
+
.where("namespace", "=", NAMESPACE)
|
|
245
|
+
.where("org_id", "=", orgId)
|
|
246
|
+
.where("key", "=", key)
|
|
247
|
+
.executeTakeFirst();
|
|
248
|
+
return row ? "connected" : "missing";
|
|
249
|
+
}
|
|
250
|
+
/** 返回本次请求要注入的头 / 查询参数;缺凭据抛 CredentialMissing。 */
|
|
251
|
+
async injection(orgId, connectorId, auth, accountId) {
|
|
252
|
+
if (auth.type === "none")
|
|
253
|
+
return { headers: {} };
|
|
254
|
+
const owner = ownerOf(auth, accountId);
|
|
255
|
+
if (isOAuth(auth)) {
|
|
256
|
+
const token = await this.oauthCall(connectorId, auth, () => this.oauth().accessToken(orgId, connectorId, auth, owner));
|
|
257
|
+
return this.injectionFor(connectorId, auth, { token });
|
|
258
|
+
}
|
|
259
|
+
const missing = () => new CredentialMissing(connectorId, auth.ownership);
|
|
260
|
+
const raw = await this.secrets().get(orgId, keyOf(connectorId, owner));
|
|
261
|
+
if (raw === null)
|
|
262
|
+
throw missing();
|
|
263
|
+
let value;
|
|
264
|
+
try {
|
|
265
|
+
value = JSON.parse(raw);
|
|
266
|
+
}
|
|
267
|
+
catch {
|
|
268
|
+
// 密文解开后不是合法 JSON:按缺失处理,日志不带内容
|
|
269
|
+
this.log.warn("credential payload is corrupted", { connectorId });
|
|
270
|
+
throw missing();
|
|
271
|
+
}
|
|
272
|
+
return this.injectionFor(connectorId, auth, value);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* 连接器收到 401 时调用(`stale` 为那次请求注入的鉴权):OAuth 连接器在刷新锁内强制刷新,之后的 `injection()`
|
|
276
|
+
* 返回新 token;refresh 被拒 → 凭据删除并抛 CredentialMissing。静态凭据无事可做。
|
|
277
|
+
*/
|
|
278
|
+
async onUnauthorized(orgId, connectorId, auth, accountId, stale) {
|
|
279
|
+
if (!isOAuth(auth))
|
|
280
|
+
return;
|
|
281
|
+
const header = stale?.headers.Authorization;
|
|
282
|
+
const token = header?.startsWith("Bearer ") ? header.slice("Bearer ".length) : undefined;
|
|
283
|
+
await this.oauthCall(connectorId, auth, () => this.oauth().forceRefresh(orgId, connectorId, auth, ownerOf(auth, accountId), token));
|
|
284
|
+
}
|
|
285
|
+
/** 「需要重新连接」→ CredentialMissing(个人凭据由管线转成 connection_required)。 */
|
|
286
|
+
async oauthCall(connectorId, auth, work) {
|
|
287
|
+
try {
|
|
288
|
+
return await work();
|
|
289
|
+
}
|
|
290
|
+
catch (e) {
|
|
291
|
+
if (e instanceof OAuthReconnectRequired) {
|
|
292
|
+
throw new CredentialMissing(connectorId, e.owner.kind === "user" ? "personal" : auth.ownership);
|
|
293
|
+
}
|
|
294
|
+
throw e;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* 由凭据值构造注入(不读库);值登记日志打码。连接器创建时用请求里带的、尚未落库的凭据连接。
|
|
299
|
+
* 值缺字段 → CredentialMissing。
|
|
300
|
+
*/
|
|
301
|
+
injectionFor(connectorId, auth, secret) {
|
|
302
|
+
const inj = this.build(connectorId, auth, secret);
|
|
303
|
+
// 与工具结果打码同一套展开(含 scheme 后的 token、Basic 解码串、百分号编码形式);logger 只收 ≥ 12 的值
|
|
304
|
+
this.log.addOrgSecrets(injectionSecrets(inj));
|
|
305
|
+
return inj;
|
|
306
|
+
}
|
|
307
|
+
build(connectorId, auth, secret) {
|
|
308
|
+
if (auth.type === "none")
|
|
309
|
+
return { headers: {} };
|
|
310
|
+
if (isOAuth(auth)) {
|
|
311
|
+
const token = secret.token;
|
|
312
|
+
if (typeof token !== "string" || token === "")
|
|
313
|
+
throw new CredentialMissing(connectorId, auth.ownership);
|
|
314
|
+
return { headers: { Authorization: `Bearer ${token}` } };
|
|
315
|
+
}
|
|
316
|
+
const missing = () => new CredentialMissing(connectorId, auth.ownership);
|
|
317
|
+
if (typeof secret !== "object" || secret === null)
|
|
318
|
+
throw missing();
|
|
319
|
+
const value = secret;
|
|
320
|
+
switch (auth.type) {
|
|
321
|
+
case "bearer": {
|
|
322
|
+
if (!value.token)
|
|
323
|
+
throw missing();
|
|
324
|
+
return { headers: { Authorization: `Bearer ${value.token}` } };
|
|
325
|
+
}
|
|
326
|
+
case "api_key": {
|
|
327
|
+
if (!value.token)
|
|
328
|
+
throw missing();
|
|
329
|
+
return auth.in === "header"
|
|
330
|
+
? { headers: { [auth.name]: value.token } }
|
|
331
|
+
: { headers: {}, query: { [auth.name]: value.token } };
|
|
332
|
+
}
|
|
333
|
+
case "basic": {
|
|
334
|
+
if (value.username === undefined || value.password === undefined)
|
|
335
|
+
throw missing();
|
|
336
|
+
const encoded = Buffer.from(`${value.username}:${value.password}`).toString("base64");
|
|
337
|
+
return { headers: { Authorization: `Basic ${encoded}` } };
|
|
338
|
+
}
|
|
339
|
+
case "headers": {
|
|
340
|
+
const headers = {};
|
|
341
|
+
for (const name of auth.names) {
|
|
342
|
+
const v = value.headers?.[name];
|
|
343
|
+
if (v === undefined)
|
|
344
|
+
throw missing();
|
|
345
|
+
headers[name] = v;
|
|
346
|
+
}
|
|
347
|
+
return { headers };
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { type AuthInjection, type Logger, type ToolSpec } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { type Transaction } from "kysely";
|
|
3
|
+
import type { KernelConfig } from "../config/schema.js";
|
|
4
|
+
import type { KernelDatabase, KernelDb } from "../db/kernel-schema.js";
|
|
5
|
+
import type { Maintenance } from "../runtime/maintenance.js";
|
|
6
|
+
import { type Credentials } from "./credentials.js";
|
|
7
|
+
import { type ToolRegistry } from "./registry.js";
|
|
8
|
+
/**
|
|
9
|
+
* 工具定义漂移检测(spec 7.3:新增 / 变化的工具在组织管理员复核前不可用,防 rug-pull / 工具投毒)。
|
|
10
|
+
*
|
|
11
|
+
* 与上次快照比对:新增 → 插入 `pending_review`;定义(spec_hash 或来源)变化 → `pending_review`,新定义存
|
|
12
|
+
* `pending_spec`,旧定义留在 `spec` 供对比,复核通过才采用;消失 → `disabled` 并记 `missing_since`(行保留,
|
|
13
|
+
* 又出现时按新增处理)。定义不合规(key 不合法等)的工具只能停用:新增时直接停用;复核过的工具变成不合规
|
|
14
|
+
* 定义时新定义同样只进 `pending_spec`(停用,approve 被拒),`spec` 始终是上次复核通过的定义。
|
|
15
|
+
* 从未复核过的工具(`reviewed_at` 为空)没有可比的旧定义:定义再变时直接替换 `spec`(仍待复核),不产生 pending。
|
|
16
|
+
* 连接器从未拍过快照(`tools_synced_at` 为空且没有工具行,即 OAuth 授权码连接器安装时不 listTools,A16)时,
|
|
17
|
+
* 首个快照按安装处理(直接启用)。
|
|
18
|
+
*
|
|
19
|
+
* 触发:维护队列的周期扫描(`tools.driftIntervalHours`)、连接器在会话中报告工具清单变了(MCP
|
|
20
|
+
* `notifications/tools/list_changed`)、管理员手动刷新(`ConnectorsService.refresh`,走同一套比对)。
|
|
21
|
+
* 授权(`tool_grants` / `conversation_tool_grants`)按 spec_hash 比对(D8),复核通过采用新指纹后旧授权自然失效。
|
|
22
|
+
*/
|
|
23
|
+
/** 周期扫描:任务名与 job scheduler id(不含 `:`)。 */
|
|
24
|
+
export declare const DRIFT_SCAN_JOB = "drift-scan";
|
|
25
|
+
export declare const DRIFT_SCHEDULER_ID = "drift-scan-interval";
|
|
26
|
+
/** 单个连接器的漂移检查任务名。 */
|
|
27
|
+
export declare const DRIFT_CONNECTOR_JOB = "drift-connector";
|
|
28
|
+
/**
|
|
29
|
+
* list_changed 触发的检查:jobId 按连接器与分钟桶去重(同一分钟内多次通知只检查一次;connectorId 为 UUID,不含 `:`)。
|
|
30
|
+
*/
|
|
31
|
+
export declare const listChangedJobId: (connectorId: string, now?: number) => string;
|
|
32
|
+
/** 周期扫描投递的检查:jobId 按连接器与扫描周期桶去重(同一周期内重复扫描只检查一次)。 */
|
|
33
|
+
export declare const driftScanJobId: (connectorId: string, bucket: number) => string;
|
|
34
|
+
/** 个人凭据型连接器:最多依次尝试几个成员的凭据。 */
|
|
35
|
+
export declare const PERSONAL_CANDIDATES = 3;
|
|
36
|
+
export type DriftTrigger = "schedule" | "list_changed";
|
|
37
|
+
export interface DriftChanges {
|
|
38
|
+
added: string[];
|
|
39
|
+
changed: string[];
|
|
40
|
+
removed: string[];
|
|
41
|
+
}
|
|
42
|
+
export type DriftCheckResult = {
|
|
43
|
+
status: "checked";
|
|
44
|
+
changes: DriftChanges;
|
|
45
|
+
} | {
|
|
46
|
+
status: "skipped";
|
|
47
|
+
reason: "not_found" | "inactive" | "no_connector" | "no_credential" | "connect_failed";
|
|
48
|
+
};
|
|
49
|
+
type Trx = Transaction<KernelDatabase>;
|
|
50
|
+
type ToolSource = "connector" | "resources";
|
|
51
|
+
/** 快照中被停用 / 跳过的工具及英文原因。 */
|
|
52
|
+
export interface ToolIssue {
|
|
53
|
+
name: string;
|
|
54
|
+
reason: string;
|
|
55
|
+
}
|
|
56
|
+
export interface SnapshotRow {
|
|
57
|
+
name: string;
|
|
58
|
+
spec: ToolSpec;
|
|
59
|
+
specHash: string;
|
|
60
|
+
/** key 不合法 / 定义不合规时为原因,此时工具只能停用。 */
|
|
61
|
+
issue: string | null;
|
|
62
|
+
source: ToolSource;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 连接 / 列工具失败的说明:ToolError 的消息是连接器写给人看的英文说明(如「Swagger 2.0 不支持」),
|
|
66
|
+
* 按本次注入的凭据打码、截断后带上;其他错误只给错误类名(详情进日志)。
|
|
67
|
+
*/
|
|
68
|
+
export declare function connectFailedMessage(e: unknown, redact: (s: string) => string): string;
|
|
69
|
+
/**
|
|
70
|
+
* 把连接器返回的工具清单整理成快照:只保留 `name / description / inputSchema / annotations / connectorData`
|
|
71
|
+
* 以及仅供显示的 `title / keyArgs`(不合规的这两项直接丢掉,不计入指纹;连接器工具不得自带 `defaultPolicy`),
|
|
72
|
+
* 同名的后者丢弃;key 超长 / 含非法字符或定义不合规的工具
|
|
73
|
+
* 照样入库但只能停用,并给出原因——一个坏工具不挡住整个连接器。名字不是非空字符串的无法入库,只报原因。
|
|
74
|
+
*/
|
|
75
|
+
export declare function snapshot(slug: string, specs: unknown, resources: boolean): {
|
|
76
|
+
rows: SnapshotRow[];
|
|
77
|
+
issues: ToolIssue[];
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Cleans a remote display title (UI refresh B, fix I2): removes format characters (Unicode Cf: bidi
|
|
81
|
+
* overrides and isolates, zero-width and other invisible ones), turns control characters (Cc,
|
|
82
|
+
* newlines included) into spaces, collapses whitespace runs to one space, trims and cuts to
|
|
83
|
+
* {@link TOOL_TITLE_MAX} code points. Undefined when nothing is left or the title is not a string.
|
|
84
|
+
* The title sits next to the reviewed tool key on the approval block, so it must not be able to
|
|
85
|
+
* reorder, hide or break that line.
|
|
86
|
+
*/
|
|
87
|
+
export declare function sanitizeToolTitle(raw: unknown): string | undefined;
|
|
88
|
+
/** 工具当前不能启用的原因(视图、启用与复核校验共用)。 */
|
|
89
|
+
export declare function toolIssue(slug: string, spec: ToolSpec): string | null;
|
|
90
|
+
export interface ToolDriftDeps {
|
|
91
|
+
db: KernelDb;
|
|
92
|
+
registry: Pick<ToolRegistry, "findConnector">;
|
|
93
|
+
credentials: Pick<Credentials, "injection" | "onUnauthorized" | "personalHolders">;
|
|
94
|
+
config: () => KernelConfig;
|
|
95
|
+
log: Logger;
|
|
96
|
+
/** 维护队列(登记周期扫描与检查任务的处理函数;不给时只能同步调用 `check`)。 */
|
|
97
|
+
maintenance?: Pick<Maintenance, "add" | "handle" | "schedule">;
|
|
98
|
+
}
|
|
99
|
+
export declare class ToolDrift {
|
|
100
|
+
private readonly d;
|
|
101
|
+
constructor(d: ToolDriftDeps);
|
|
102
|
+
private intervalMs;
|
|
103
|
+
/**
|
|
104
|
+
* 打开一次会话拉工具清单,无论成败都关闭会话;会话带 `listResources` 即视为支持 resources。
|
|
105
|
+
* 清单里回显的凭据按本次注入的值打码(见 redact.ts)。凭据缺失原样抛 `credential.missing`;
|
|
106
|
+
* 其余失败一律 502 `connector.connect_failed`,消息只带上游错误的类名(不带消息,消息里可能回显凭据)。
|
|
107
|
+
*/
|
|
108
|
+
listTools(connector: string, endpoint: unknown, auth: () => Promise<AuthInjection>, logCtx: Record<string, unknown>,
|
|
109
|
+
/** 收到 401:OAuth 连接器在刷新锁内刷新(参数为最后一次注入的鉴权)。 */
|
|
110
|
+
onUnauthorized?: (last: AuthInjection | undefined) => Promise<void>): Promise<{
|
|
111
|
+
specs: unknown;
|
|
112
|
+
resources: boolean;
|
|
113
|
+
}>;
|
|
114
|
+
/**
|
|
115
|
+
* 把新快照与当前工具行比对并写入(调用方已在事务内锁住连接器行);返回按名排序的变化。
|
|
116
|
+
* 规则见文件头。待复核的新定义也写进 `tool_specs`(内容寻址,只增不改)。
|
|
117
|
+
*/
|
|
118
|
+
apply(t: Trx, app: {
|
|
119
|
+
id: string;
|
|
120
|
+
tools_synced_at: Date | null;
|
|
121
|
+
}, rows: SnapshotRow[]): Promise<DriftChanges>;
|
|
122
|
+
/**
|
|
123
|
+
* 后台检查一个连接器(维护队列的 worker 上执行,没有发起人):拉工具清单 → 比对写入 → 有变化记审计
|
|
124
|
+
* `connector.tools_drifted`(detail 只有新增 / 变化 / 消失的个数与触发方式,不含定义与凭据)。
|
|
125
|
+
* 凭据:无需凭据 / 组织凭据型(含客户端凭据流)用组织凭据;个人凭据型(静态或 OAuth 授权码)依次尝试
|
|
126
|
+
* 至多 {@link PERSONAL_CANDIDATES} 个**现任成员**的个人凭据,按凭据最近写入时间倒序(连接 / 刷新 token
|
|
127
|
+
* 都会更新写入时间,即「最近连接成功的成员」优先),用第一个成功的;没有任何成员凭据 → 跳过并记日志。
|
|
128
|
+
* 连不上 / 都失败 → 跳过(不改快照,下个周期或下次通知再查)。
|
|
129
|
+
*/
|
|
130
|
+
check(orgId: string, connectorId: string, trigger: DriftTrigger): Promise<DriftCheckResult>;
|
|
131
|
+
/**
|
|
132
|
+
* 连接器在会话中报告工具清单变了:投递一次该连接器的检查(jobId 按分钟桶去重)。投递失败只记日志。
|
|
133
|
+
*/
|
|
134
|
+
onToolsChanged(orgId: string, connectorId: string): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* 周期扫描:给本周期内还没检查过的活动连接器(`tools_synced_at` 为空或早于半个周期)各投递一次检查,
|
|
137
|
+
* jobId 按周期桶去重——即使扫描在多个副本上重复执行,每个连接器每周期也只检查一次。返回投递数。
|
|
138
|
+
*/
|
|
139
|
+
scan(): Promise<number>;
|
|
140
|
+
}
|
|
141
|
+
export {};
|