@capybara-hq/kernel 0.0.0-stage → 0.1.0-rc.1
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 +26 -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 +1126 -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 +237 -0
- package/dist/config/schema.js +1192 -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 +423 -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 +151 -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 +211 -0
- package/dist/errors.js +213 -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 +790 -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 +176 -0
- package/dist/extensions/bootstrap.js +535 -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 +220 -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 +69 -0
- package/dist/index.js +67 -0
- package/dist/kernel.d.ts +259 -0
- package/dist/kernel.js +1326 -0
- package/dist/log-config.d.ts +9 -0
- package/dist/log-config.js +27 -0
- package/dist/log-context.d.ts +32 -0
- package/dist/log-context.js +40 -0
- package/dist/log-loki.d.ts +34 -0
- package/dist/log-loki.js +145 -0
- package/dist/log.d.ts +79 -0
- package/dist/log.js +303 -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 +272 -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 +148 -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 +806 -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 +551 -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 +116 -0
- package/dist/tools/builtins/sandbox/common.js +306 -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 +69 -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,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 对象存储的键前缀与校验(扩展模型 §5):插件 `plugins/<插件名>/<orgId>/`,内核 `kernel/<orgId>/`。
|
|
3
|
+
* 任何拼出来会落到前缀之外的键一律拒绝;校验发生在调用提供方之前。
|
|
4
|
+
*/
|
|
5
|
+
/** 加前缀后的键长度上限(S3 的键上限是 1024 字节,这里按 UTF-8 字节计)。 */
|
|
6
|
+
export const MAX_STORAGE_KEY_BYTES = 1024;
|
|
7
|
+
/** 键或前缀不合法(越出前缀、组织 id 不是 UUID 等)。消息为英文、不含键之外的内部信息。 */
|
|
8
|
+
export class StorageKeyError extends Error {
|
|
9
|
+
constructor(message) {
|
|
10
|
+
super(`invalid storage key: ${message}`);
|
|
11
|
+
this.name = "StorageKeyError";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
15
|
+
/** 插件名规则同清单(`defineExtension` 的 name 校验)。 */
|
|
16
|
+
const EXTENSION_NAME_RE = /^[a-z][a-z0-9-]{1,40}$/;
|
|
17
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: 正是要拒绝控制字符
|
|
18
|
+
const CONTROL_RE = /[\u0000-\u001f\u007f]/;
|
|
19
|
+
/** 字面的 `${`(POST 策略的变量起始符)。 */
|
|
20
|
+
const TEMPLATE_START = "${";
|
|
21
|
+
/**
|
|
22
|
+
* 组织 id 必须是 UUID;统一转成小写,同一组织不论大小写都落到同一个前缀
|
|
23
|
+
* (内核生成的组织 id 本来就是小写)。
|
|
24
|
+
*/
|
|
25
|
+
export function normalizeOrgId(orgId) {
|
|
26
|
+
if (typeof orgId !== "string" || !UUID_RE.test(orgId)) {
|
|
27
|
+
throw new StorageKeyError("organization id must be a UUID");
|
|
28
|
+
}
|
|
29
|
+
return orgId.toLowerCase();
|
|
30
|
+
}
|
|
31
|
+
/** 插件名必须符合清单规则(不含 `/`、`..`)。 */
|
|
32
|
+
export function assertPluginName(plugin) {
|
|
33
|
+
if (typeof plugin !== "string" || !EXTENSION_NAME_RE.test(plugin)) {
|
|
34
|
+
throw new StorageKeyError(`plugin name "${plugin}" is not valid`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 校验调用方给的相对键(`allowEmpty` 时是列举 / 批量删除的前缀,空串表示全部):
|
|
39
|
+
* 不能以 `/` 开头,不能有 `.` / `..` 段,不能含 `\`、控制字符与 `${`
|
|
40
|
+
* (S3 POST 策略会把键里的 `${filename}` 换成上传方给的文件名,键就不再是签名时的那个)。
|
|
41
|
+
*/
|
|
42
|
+
function assertRelative(key, allowEmpty) {
|
|
43
|
+
if (typeof key !== "string")
|
|
44
|
+
throw new StorageKeyError("key must be a string");
|
|
45
|
+
if (key === "") {
|
|
46
|
+
if (allowEmpty)
|
|
47
|
+
return;
|
|
48
|
+
throw new StorageKeyError("key must not be empty");
|
|
49
|
+
}
|
|
50
|
+
if (key.startsWith("/"))
|
|
51
|
+
throw new StorageKeyError("key must not start with '/'");
|
|
52
|
+
if (key.includes("\\"))
|
|
53
|
+
throw new StorageKeyError("key must not contain '\\'");
|
|
54
|
+
if (CONTROL_RE.test(key))
|
|
55
|
+
throw new StorageKeyError("key must not contain control characters");
|
|
56
|
+
if (key.includes(TEMPLATE_START))
|
|
57
|
+
throw new StorageKeyError(`key must not contain '${TEMPLATE_START}'`);
|
|
58
|
+
for (const seg of key.split("/")) {
|
|
59
|
+
if (seg === "." || seg === "..") {
|
|
60
|
+
throw new StorageKeyError("key must not contain '.' or '..' segments");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** 一个组织下的键空间:把相对键拼成完整键,把完整键还原成相对键。 */
|
|
65
|
+
export class KeySpace {
|
|
66
|
+
prefix;
|
|
67
|
+
/** @param prefix 以 `/` 结尾的完整前缀(如 `plugins/x/<orgId>/`)。 */
|
|
68
|
+
constructor(prefix) {
|
|
69
|
+
this.prefix = prefix;
|
|
70
|
+
}
|
|
71
|
+
/** 对象键:非空,拼接后不超过 {@link MAX_STORAGE_KEY_BYTES}。 */
|
|
72
|
+
key(key) {
|
|
73
|
+
assertRelative(key, false);
|
|
74
|
+
return this.checkLength(this.prefix + key);
|
|
75
|
+
}
|
|
76
|
+
/** 列举 / 批量删除的前缀:可以为空(表示该组织下的全部)。 */
|
|
77
|
+
listPrefix(prefix) {
|
|
78
|
+
assertRelative(prefix, true);
|
|
79
|
+
return this.checkLength(this.prefix + prefix);
|
|
80
|
+
}
|
|
81
|
+
/** 完整键是否在本前缀下。 */
|
|
82
|
+
owns(full) {
|
|
83
|
+
return full.startsWith(this.prefix) && full.length > this.prefix.length;
|
|
84
|
+
}
|
|
85
|
+
/** 去掉前缀(调用方先用 {@link owns} 过滤)。 */
|
|
86
|
+
strip(full) {
|
|
87
|
+
return full.slice(this.prefix.length);
|
|
88
|
+
}
|
|
89
|
+
checkLength(full) {
|
|
90
|
+
if (Buffer.byteLength(full, "utf8") > MAX_STORAGE_KEY_BYTES) {
|
|
91
|
+
throw new StorageKeyError(`key is longer than ${MAX_STORAGE_KEY_BYTES} bytes with its prefix`);
|
|
92
|
+
}
|
|
93
|
+
return full;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/** 插件在某组织下的前缀 `plugins/<插件>/<orgId>/`。 */
|
|
97
|
+
export function pluginPrefix(plugin, orgId) {
|
|
98
|
+
assertPluginName(plugin);
|
|
99
|
+
return `plugins/${plugin}/${normalizeOrgId(orgId)}/`;
|
|
100
|
+
}
|
|
101
|
+
/** 内核在某组织下的前缀 `kernel/<orgId>/`。 */
|
|
102
|
+
export function kernelPrefix(orgId) {
|
|
103
|
+
return `kernel/${normalizeOrgId(orgId)}/`;
|
|
104
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Logger } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import type { KernelDb } from "../db/kernel-schema.js";
|
|
3
|
+
import type { StorageService } from "./storage.service.js";
|
|
4
|
+
/** 维护任务:清理已删除组织的对象存储(任务名与 scheduler id 不含 `:`)。 */
|
|
5
|
+
export declare const STORAGE_PURGE_JOB = "storage-org-purge";
|
|
6
|
+
export declare const STORAGE_PURGE_SCHEDULER_ID = "storage-org-purge-hourly";
|
|
7
|
+
export declare const STORAGE_PURGE_EVERY_MS = 3600000;
|
|
8
|
+
/**
|
|
9
|
+
* 删除「软删除超过 `afterDays` 天、尚未清理存储」的组织的全部对象(`StorageService.deleteOrg`),
|
|
10
|
+
* 成功后写 `orgs.storage_purged_at`,之后不再处理。返回本次清理的组织数。
|
|
11
|
+
* 没有对象存储提供方时什么也不做(不认领、不标记,装上提供方后再清理)。
|
|
12
|
+
*
|
|
13
|
+
* 每个组织三步,不在事务里做网络调用:
|
|
14
|
+
* 1. 认领:一条 `UPDATE … RETURNING`(子查询 `FOR UPDATE SKIP LOCKED`)写 `storage_purge_claimed_at`,
|
|
15
|
+
* 只认领未被认领、或认领已超过 {@link CLAIM_STALE_MINUTES} 分钟的组织。同一时刻的并发认领只有一方成功;
|
|
16
|
+
* 但认领不是租约:持有方删得比 {@link CLAIM_STALE_MINUTES} 还久(或已退出)时,别的副本会重新认领,两方可能
|
|
17
|
+
* 同时删同一组织的对象,先结束的一方还会清掉对方的认领。这是可以接受的:`deleteOrg` 幂等,`storage_purged_at`
|
|
18
|
+
* 只在删除成功后写,最坏只是重复删除或下一轮再删一次;
|
|
19
|
+
* 2. 在事务外删除对象(`deleteOrg` 幂等);
|
|
20
|
+
* 3. 成功:写 `storage_purged_at` 并清空认领;失败:清空认领(下一次运行重试),本次运行不再碰它。
|
|
21
|
+
*/
|
|
22
|
+
export declare function purgeDeletedOrgStorage(d: {
|
|
23
|
+
db: KernelDb;
|
|
24
|
+
storage: StorageService;
|
|
25
|
+
afterDays: number;
|
|
26
|
+
log: Pick<Logger, "info" | "warn">;
|
|
27
|
+
}): Promise<number>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { sql } from "kysely";
|
|
2
|
+
/** 维护任务:清理已删除组织的对象存储(任务名与 scheduler id 不含 `:`)。 */
|
|
3
|
+
export const STORAGE_PURGE_JOB = "storage-org-purge";
|
|
4
|
+
export const STORAGE_PURGE_SCHEDULER_ID = "storage-org-purge-hourly";
|
|
5
|
+
export const STORAGE_PURGE_EVERY_MS = 3_600_000;
|
|
6
|
+
/** 每次运行最多处理的组织数(成功与失败合计)。 */
|
|
7
|
+
const PURGE_BATCH = 100;
|
|
8
|
+
/** 认领超过这么久仍未完成(运行中途退出)就可被重新认领。 */
|
|
9
|
+
const CLAIM_STALE_MINUTES = 60;
|
|
10
|
+
/**
|
|
11
|
+
* 删除「软删除超过 `afterDays` 天、尚未清理存储」的组织的全部对象(`StorageService.deleteOrg`),
|
|
12
|
+
* 成功后写 `orgs.storage_purged_at`,之后不再处理。返回本次清理的组织数。
|
|
13
|
+
* 没有对象存储提供方时什么也不做(不认领、不标记,装上提供方后再清理)。
|
|
14
|
+
*
|
|
15
|
+
* 每个组织三步,不在事务里做网络调用:
|
|
16
|
+
* 1. 认领:一条 `UPDATE … RETURNING`(子查询 `FOR UPDATE SKIP LOCKED`)写 `storage_purge_claimed_at`,
|
|
17
|
+
* 只认领未被认领、或认领已超过 {@link CLAIM_STALE_MINUTES} 分钟的组织。同一时刻的并发认领只有一方成功;
|
|
18
|
+
* 但认领不是租约:持有方删得比 {@link CLAIM_STALE_MINUTES} 还久(或已退出)时,别的副本会重新认领,两方可能
|
|
19
|
+
* 同时删同一组织的对象,先结束的一方还会清掉对方的认领。这是可以接受的:`deleteOrg` 幂等,`storage_purged_at`
|
|
20
|
+
* 只在删除成功后写,最坏只是重复删除或下一轮再删一次;
|
|
21
|
+
* 2. 在事务外删除对象(`deleteOrg` 幂等);
|
|
22
|
+
* 3. 成功:写 `storage_purged_at` 并清空认领;失败:清空认领(下一次运行重试),本次运行不再碰它。
|
|
23
|
+
*/
|
|
24
|
+
export async function purgeDeletedOrgStorage(d) {
|
|
25
|
+
if (!d.storage.available)
|
|
26
|
+
return 0;
|
|
27
|
+
let purged = 0;
|
|
28
|
+
const failed = [];
|
|
29
|
+
while (purged + failed.length < PURGE_BATCH) {
|
|
30
|
+
const claimed = await d.db
|
|
31
|
+
.updateTable("orgs")
|
|
32
|
+
.set({ storage_purge_claimed_at: sql `now()` })
|
|
33
|
+
.where("id", "=", d.db
|
|
34
|
+
.selectFrom("orgs")
|
|
35
|
+
.select("id")
|
|
36
|
+
.where("deleted_at", "is not", null)
|
|
37
|
+
.where("storage_purged_at", "is", null)
|
|
38
|
+
.where("deleted_at", "<", sql `now() - make_interval(days => ${d.afterDays})`)
|
|
39
|
+
.where((eb) => eb.or([
|
|
40
|
+
eb("storage_purge_claimed_at", "is", null),
|
|
41
|
+
eb("storage_purge_claimed_at", "<", sql `now() - make_interval(mins => ${CLAIM_STALE_MINUTES})`),
|
|
42
|
+
]))
|
|
43
|
+
.$if(failed.length > 0, (q) => q.where("id", "not in", failed))
|
|
44
|
+
.orderBy("deleted_at")
|
|
45
|
+
.limit(1)
|
|
46
|
+
.forUpdate()
|
|
47
|
+
.skipLocked())
|
|
48
|
+
.returning("id")
|
|
49
|
+
.executeTakeFirst();
|
|
50
|
+
if (!claimed)
|
|
51
|
+
return purged;
|
|
52
|
+
const orgId = claimed.id;
|
|
53
|
+
try {
|
|
54
|
+
const objects = await d.storage.deleteOrg(orgId);
|
|
55
|
+
await d.db
|
|
56
|
+
.updateTable("orgs")
|
|
57
|
+
.set({ storage_purged_at: sql `now()`, storage_purge_claimed_at: null })
|
|
58
|
+
.where("id", "=", orgId)
|
|
59
|
+
.execute();
|
|
60
|
+
purged++;
|
|
61
|
+
d.log.info("deleted organization storage purged", { orgId, objects });
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
failed.push(orgId);
|
|
65
|
+
d.log.warn("cannot purge deleted organization storage; will retry", { orgId, err });
|
|
66
|
+
await d.db
|
|
67
|
+
.updateTable("orgs")
|
|
68
|
+
.set({ storage_purge_claimed_at: null })
|
|
69
|
+
.where("id", "=", orgId)
|
|
70
|
+
.execute()
|
|
71
|
+
.catch((e) => d.log.warn("cannot release storage purge claim", { orgId, err: e }));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return purged;
|
|
75
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ExtensionPointUnavailableError, type ExtensionStorage, type ObjectStore } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
export { StorageKeyError } from "./prefix.js";
|
|
3
|
+
/** 部署级对象的键前缀(见 {@link StorageService.deployment})。 */
|
|
4
|
+
export declare const DEPLOYMENT_PREFIX = "deployment/";
|
|
5
|
+
/** 没有对象存储提供方时的错误(HTTP 层映射为 `storage.unavailable`,503)。 */
|
|
6
|
+
export declare const storageUnavailable: () => ExtensionPointUnavailableError;
|
|
7
|
+
/** 预签名 URL 的有效期上限(秒):SigV4 预签名最长 7 天。 */
|
|
8
|
+
export declare const MAX_PRESIGN_TTL_SECONDS = 604800;
|
|
9
|
+
/** 把预签名有效期取整并限制在 1..{@link MAX_PRESIGN_TTL_SECONDS};不是有限数时抛 RangeError。 */
|
|
10
|
+
export declare function clampPresignTtl(ttlSeconds: number): number;
|
|
11
|
+
export interface StorageServiceDeps {
|
|
12
|
+
/** 当前的 `object-store@1` 提供方;每次调用时取(提供方在插件加载过程中才就绪)。 */
|
|
13
|
+
provider: () => ObjectStore | undefined;
|
|
14
|
+
/** 可能存过数据的插件名(删除组织数据时逐个删 `plugins/<插件>/<orgId>/`)。 */
|
|
15
|
+
plugins: () => Promise<string[]>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 内核的对象存储服务(扩展模型 §5):在 `object-store@1` 提供方之上加前缀隔离。
|
|
19
|
+
* - 插件经 {@link forPlugin} 拿到 `ctx.storage`:键落在 `plugins/<插件>/<orgId>/` 下;
|
|
20
|
+
* - 内核功能经 {@link kernel} 用 `kernel/<orgId>/`;
|
|
21
|
+
* - 返回给调用方的键(`head` / `get` / `put` / `list`)都去掉前缀,列举结果只保留本前缀下的对象。
|
|
22
|
+
* 没有提供方时各方法 reject `storage.unavailable`({@link available} 为 false)。本身无状态,可多副本共用。
|
|
23
|
+
*/
|
|
24
|
+
export declare class StorageService {
|
|
25
|
+
private readonly d;
|
|
26
|
+
constructor(d: StorageServiceDeps);
|
|
27
|
+
/** 是否有对象存储提供方。 */
|
|
28
|
+
get available(): boolean;
|
|
29
|
+
/** 依赖存储的 HTTP 功能在入口调用:没有提供方时抛 `ApiError("storage.unavailable")`(503)。 */
|
|
30
|
+
assertAvailable(): void;
|
|
31
|
+
/** 插件的 `ctx.storage`:每个方法先校验 orgId 与键,再加前缀 `plugins/<plugin>/<orgId>/`。 */
|
|
32
|
+
forPlugin(plugin: string): ExtensionStorage;
|
|
33
|
+
/** 内核在该组织下的存储(前缀 `kernel/<orgId>/`)。orgId 不是 UUID 时立即抛 StorageKeyError。 */
|
|
34
|
+
kernel(orgId: string): ObjectStore;
|
|
35
|
+
/**
|
|
36
|
+
* 内核的部署级存储(前缀 {@link DEPLOYMENT_PREFIX},不属于任何组织,如插件包
|
|
37
|
+
* `deployment/plugins/blobs/<sha256>.tgz`)。{@link deleteOrg} 不触及。
|
|
38
|
+
*/
|
|
39
|
+
deployment(): ObjectStore;
|
|
40
|
+
private scopedStore;
|
|
41
|
+
/** 删除该组织的全部对象:`kernel/<orgId>/` 与每个插件的 `plugins/<插件>/<orgId>/`。返回删除数。 */
|
|
42
|
+
deleteOrg(orgId: string): Promise<number>;
|
|
43
|
+
private require;
|
|
44
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { ExtensionPointUnavailableError, } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { ApiError } from "../errors.js";
|
|
3
|
+
import { KeySpace, kernelPrefix, normalizeOrgId, pluginPrefix } from "./prefix.js";
|
|
4
|
+
export { StorageKeyError } from "./prefix.js";
|
|
5
|
+
/** 部署级对象的键前缀(见 {@link StorageService.deployment})。 */
|
|
6
|
+
export const DEPLOYMENT_PREFIX = "deployment/";
|
|
7
|
+
/** 没有对象存储提供方时的错误(HTTP 层映射为 `storage.unavailable`,503)。 */
|
|
8
|
+
export const storageUnavailable = () => new ExtensionPointUnavailableError("storage.unavailable: object storage is not available in this deployment");
|
|
9
|
+
/** 预签名 URL 的有效期上限(秒):SigV4 预签名最长 7 天。 */
|
|
10
|
+
export const MAX_PRESIGN_TTL_SECONDS = 604_800;
|
|
11
|
+
/** 把预签名有效期取整并限制在 1..{@link MAX_PRESIGN_TTL_SECONDS};不是有限数时抛 RangeError。 */
|
|
12
|
+
export function clampPresignTtl(ttlSeconds) {
|
|
13
|
+
if (typeof ttlSeconds !== "number" || !Number.isFinite(ttlSeconds)) {
|
|
14
|
+
throw new RangeError("storage: ttlSeconds must be a finite number");
|
|
15
|
+
}
|
|
16
|
+
return Math.min(MAX_PRESIGN_TTL_SECONDS, Math.max(1, Math.floor(ttlSeconds)));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 内核的对象存储服务(扩展模型 §5):在 `object-store@1` 提供方之上加前缀隔离。
|
|
20
|
+
* - 插件经 {@link forPlugin} 拿到 `ctx.storage`:键落在 `plugins/<插件>/<orgId>/` 下;
|
|
21
|
+
* - 内核功能经 {@link kernel} 用 `kernel/<orgId>/`;
|
|
22
|
+
* - 返回给调用方的键(`head` / `get` / `put` / `list`)都去掉前缀,列举结果只保留本前缀下的对象。
|
|
23
|
+
* 没有提供方时各方法 reject `storage.unavailable`({@link available} 为 false)。本身无状态,可多副本共用。
|
|
24
|
+
*/
|
|
25
|
+
export class StorageService {
|
|
26
|
+
d;
|
|
27
|
+
constructor(d) {
|
|
28
|
+
this.d = d;
|
|
29
|
+
}
|
|
30
|
+
/** 是否有对象存储提供方。 */
|
|
31
|
+
get available() {
|
|
32
|
+
return this.d.provider() !== undefined;
|
|
33
|
+
}
|
|
34
|
+
/** 依赖存储的 HTTP 功能在入口调用:没有提供方时抛 `ApiError("storage.unavailable")`(503)。 */
|
|
35
|
+
assertAvailable() {
|
|
36
|
+
if (!this.available) {
|
|
37
|
+
throw new ApiError("storage.unavailable", "Object storage is not available in this deployment; install an object-store plugin");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** 插件的 `ctx.storage`:每个方法先校验 orgId 与键,再加前缀 `plugins/<plugin>/<orgId>/`。 */
|
|
41
|
+
forPlugin(plugin) {
|
|
42
|
+
// 先按一个合法的组织 id 校验插件名:名字不合法时立即抛错,而不是等到第一次调用
|
|
43
|
+
pluginPrefix(plugin, "00000000-0000-0000-0000-000000000000");
|
|
44
|
+
const space = (orgId) => new KeySpace(pluginPrefix(plugin, orgId));
|
|
45
|
+
const run = async (orgId, fn) => {
|
|
46
|
+
const store = this.require();
|
|
47
|
+
return fn(new ScopedStore(store, space(orgId)));
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
put: (orgId, key, body, opts) => run(orgId, (s) => s.put(key, body, opts)),
|
|
51
|
+
get: (orgId, key, opts) => run(orgId, (s) => s.get(key, opts)),
|
|
52
|
+
head: (orgId, key) => run(orgId, (s) => s.head(key)),
|
|
53
|
+
delete: (orgId, key) => run(orgId, (s) => s.delete(key)),
|
|
54
|
+
deletePrefix: (orgId, prefix) => run(orgId, (s) => s.deletePrefix(prefix)),
|
|
55
|
+
list: (orgId, prefix, opts) => run(orgId, (s) => s.list(prefix, opts)),
|
|
56
|
+
presignGet: (orgId, key, opts) => run(orgId, (s) => s.presignGet(key, opts)),
|
|
57
|
+
presignPut: (orgId, key, opts) => run(orgId, (s) => s.presignPut(key, opts)),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** 内核在该组织下的存储(前缀 `kernel/<orgId>/`)。orgId 不是 UUID 时立即抛 StorageKeyError。 */
|
|
61
|
+
kernel(orgId) {
|
|
62
|
+
return this.scopedStore(new KeySpace(kernelPrefix(orgId)));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 内核的部署级存储(前缀 {@link DEPLOYMENT_PREFIX},不属于任何组织,如插件包
|
|
66
|
+
* `deployment/plugins/blobs/<sha256>.tgz`)。{@link deleteOrg} 不触及。
|
|
67
|
+
*/
|
|
68
|
+
deployment() {
|
|
69
|
+
return this.scopedStore(new KeySpace(DEPLOYMENT_PREFIX));
|
|
70
|
+
}
|
|
71
|
+
scopedStore(ks) {
|
|
72
|
+
const scoped = () => new ScopedStore(this.require(), ks);
|
|
73
|
+
return {
|
|
74
|
+
put: async (key, body, opts) => scoped().put(key, body, opts),
|
|
75
|
+
get: async (key, opts) => scoped().get(key, opts),
|
|
76
|
+
head: async (key) => scoped().head(key),
|
|
77
|
+
delete: async (key) => scoped().delete(key),
|
|
78
|
+
deletePrefix: async (prefix) => scoped().deletePrefix(prefix),
|
|
79
|
+
list: async (prefix, opts) => scoped().list(prefix, opts),
|
|
80
|
+
presignGet: async (key, opts) => scoped().presignGet(key, opts),
|
|
81
|
+
presignPut: async (key, opts) => scoped().presignPut(key, opts),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** 删除该组织的全部对象:`kernel/<orgId>/` 与每个插件的 `plugins/<插件>/<orgId>/`。返回删除数。 */
|
|
85
|
+
async deleteOrg(orgId) {
|
|
86
|
+
const store = this.require();
|
|
87
|
+
normalizeOrgId(orgId);
|
|
88
|
+
let n = await store.deletePrefix(kernelPrefix(orgId));
|
|
89
|
+
for (const plugin of new Set(await this.d.plugins())) {
|
|
90
|
+
n += await store.deletePrefix(pluginPrefix(plugin, orgId));
|
|
91
|
+
}
|
|
92
|
+
return n;
|
|
93
|
+
}
|
|
94
|
+
require() {
|
|
95
|
+
const store = this.d.provider();
|
|
96
|
+
if (!store)
|
|
97
|
+
throw storageUnavailable();
|
|
98
|
+
return store;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** 一个前缀下的 ObjectStore 视图:键先校验再拼接,返回的键去掉前缀。 */
|
|
102
|
+
class ScopedStore {
|
|
103
|
+
store;
|
|
104
|
+
space;
|
|
105
|
+
constructor(store, space) {
|
|
106
|
+
this.store = store;
|
|
107
|
+
this.space = space;
|
|
108
|
+
}
|
|
109
|
+
rel(h, key) {
|
|
110
|
+
return { ...h, key };
|
|
111
|
+
}
|
|
112
|
+
async put(key, body, opts) {
|
|
113
|
+
return this.rel(await this.store.put(this.space.key(key), body, opts), key);
|
|
114
|
+
}
|
|
115
|
+
async get(key, opts) {
|
|
116
|
+
const r = await this.store.get(this.space.key(key), opts);
|
|
117
|
+
return r ? { head: this.rel(r.head, key), body: r.body } : null;
|
|
118
|
+
}
|
|
119
|
+
async head(key) {
|
|
120
|
+
const h = await this.store.head(this.space.key(key));
|
|
121
|
+
return h ? this.rel(h, key) : null;
|
|
122
|
+
}
|
|
123
|
+
async delete(key) {
|
|
124
|
+
await this.store.delete(this.space.key(key));
|
|
125
|
+
}
|
|
126
|
+
async deletePrefix(prefix) {
|
|
127
|
+
return this.store.deletePrefix(this.space.listPrefix(prefix));
|
|
128
|
+
}
|
|
129
|
+
async list(prefix, opts) {
|
|
130
|
+
const r = await this.store.list(this.space.listPrefix(prefix), opts);
|
|
131
|
+
// 防御:提供方返回了前缀之外的键时丢掉,调用方永远看不到别的前缀
|
|
132
|
+
const items = r.items
|
|
133
|
+
.filter((i) => this.space.owns(i.key))
|
|
134
|
+
.map((i) => this.rel(i, this.space.strip(i.key)));
|
|
135
|
+
return r.cursor === undefined ? { items } : { items, cursor: r.cursor };
|
|
136
|
+
}
|
|
137
|
+
async presignGet(key, opts) {
|
|
138
|
+
const ttlSeconds = clampPresignTtl(opts.ttlSeconds);
|
|
139
|
+
return this.store.presignGet(this.space.key(key), { ...opts, ttlSeconds });
|
|
140
|
+
}
|
|
141
|
+
async presignPut(key, opts) {
|
|
142
|
+
const ttlSeconds = clampPresignTtl(opts.ttlSeconds);
|
|
143
|
+
return this.store.presignPut(this.space.key(key), { ...opts, ttlSeconds });
|
|
144
|
+
}
|
|
145
|
+
}
|
package/dist/text.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Characters people-facing one-line labels (conversation titles, tool titles) never carry: format
|
|
3
|
+
* characters (Unicode Cf: bidi marks, overrides and isolates U+061C, U+200E/F, U+202A–202E,
|
|
4
|
+
* U+2066–2069; zero-width and invisible ones like U+200B, U+2060, U+FEFF; tag characters) except
|
|
5
|
+
* ZWNJ (U+200C) and ZWJ (U+200D), which Persian and other scripts and emoji sequences need. The same
|
|
6
|
+
* rule as the plugin SDK's `validateToolPresentation` and connector-mcp's title cleaning.
|
|
7
|
+
*
|
|
8
|
+
* Global: for `String.replace` only. Never call `.test()` / `.exec()` on it (a global regex keeps
|
|
9
|
+
* `lastIndex` between calls); use {@link CONTROL_OR_HIDDEN_RE} to test.
|
|
10
|
+
*/
|
|
11
|
+
export declare const HIDDEN_FORMAT_RE: RegExp;
|
|
12
|
+
/** {@link HIDDEN_FORMAT_RE} plus control characters (Cc, newlines included). */
|
|
13
|
+
export declare const CONTROL_OR_HIDDEN_RE: RegExp;
|
package/dist/text.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Characters people-facing one-line labels (conversation titles, tool titles) never carry: format
|
|
3
|
+
* characters (Unicode Cf: bidi marks, overrides and isolates U+061C, U+200E/F, U+202A–202E,
|
|
4
|
+
* U+2066–2069; zero-width and invisible ones like U+200B, U+2060, U+FEFF; tag characters) except
|
|
5
|
+
* ZWNJ (U+200C) and ZWJ (U+200D), which Persian and other scripts and emoji sequences need. The same
|
|
6
|
+
* rule as the plugin SDK's `validateToolPresentation` and connector-mcp's title cleaning.
|
|
7
|
+
*
|
|
8
|
+
* Global: for `String.replace` only. Never call `.test()` / `.exec()` on it (a global regex keeps
|
|
9
|
+
* `lastIndex` between calls); use {@link CONTROL_OR_HIDDEN_RE} to test.
|
|
10
|
+
*/
|
|
11
|
+
export const HIDDEN_FORMAT_RE = /(?![\u200C\u200D])\p{Cf}/gu;
|
|
12
|
+
/** {@link HIDDEN_FORMAT_RE} plus control characters (Cc, newlines included). */
|
|
13
|
+
export const CONTROL_OR_HIDDEN_RE = /(?![\u200C\u200D])[\p{Cc}\p{Cf}]/u;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type Principal } from "../identity/principal.js";
|
|
3
|
+
import { type OrgContext } from "../orgs/org.guard.js";
|
|
4
|
+
import { type ApprovalRecord, type ApprovalsService, type ApprovalView, type ToolGrantView } from "./approvals.service.js";
|
|
5
|
+
declare const ListQuery: z.ZodObject<{
|
|
6
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
7
|
+
approved: "approved";
|
|
8
|
+
cancelled: "cancelled";
|
|
9
|
+
denied: "denied";
|
|
10
|
+
expired: "expired";
|
|
11
|
+
pending: "pending";
|
|
12
|
+
}>>;
|
|
13
|
+
}, z.core.$strict>;
|
|
14
|
+
declare const DecisionBody: z.ZodObject<{
|
|
15
|
+
decision: z.ZodEnum<{
|
|
16
|
+
approve: "approve";
|
|
17
|
+
deny: "deny";
|
|
18
|
+
}>;
|
|
19
|
+
scope: z.ZodOptional<z.ZodEnum<{
|
|
20
|
+
always: "always";
|
|
21
|
+
once: "once";
|
|
22
|
+
session: "session";
|
|
23
|
+
}>>;
|
|
24
|
+
note: z.ZodOptional<z.ZodString>;
|
|
25
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
26
|
+
}, z.core.$strict>;
|
|
27
|
+
/**
|
|
28
|
+
* 工具调用审批(`/api/v1/orgs/:orgId/approvals`,`approvals.decide`:访客起、仅限用户主体——agent 不能审批,R2)。
|
|
29
|
+
* 能否看到 / 处理某条审批由 `requested_for` / `approver_role` 判定(见 `ApprovalsService`),看不到的一律 404。
|
|
30
|
+
*/
|
|
31
|
+
export declare class ApprovalsController {
|
|
32
|
+
private readonly approvals;
|
|
33
|
+
constructor(approvals: ApprovalsService);
|
|
34
|
+
list(principal: Principal, org: OrgContext, q: z.infer<typeof ListQuery>): Promise<{
|
|
35
|
+
approvals: ApprovalView[];
|
|
36
|
+
}>;
|
|
37
|
+
get(principal: Principal, org: OrgContext, id: string): Promise<{
|
|
38
|
+
approval: ApprovalView;
|
|
39
|
+
}>;
|
|
40
|
+
decide(principal: Principal, org: OrgContext, id: string, body: z.infer<typeof DecisionBody>): Promise<{
|
|
41
|
+
approval: ApprovalRecord;
|
|
42
|
+
}>;
|
|
43
|
+
}
|
|
44
|
+
/** 本人的「以后都允许」授权(`/api/v1/orgs/:orgId/me/tool-grants`):查看与撤销,只动自己的。 */
|
|
45
|
+
export declare class ToolGrantsController {
|
|
46
|
+
private readonly approvals;
|
|
47
|
+
constructor(approvals: ApprovalsService);
|
|
48
|
+
list(principal: Principal, org: OrgContext): Promise<{
|
|
49
|
+
grants: ToolGrantView[];
|
|
50
|
+
}>;
|
|
51
|
+
revoke(principal: Principal, org: OrgContext, agentId: string, toolKey: string): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,128 @@
|
|
|
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 { Body, Controller, Delete, Get, HttpCode, Inject, Param, Post, Query, } from "@nestjs/common";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import { APPROVALS } from "../http/tokens.js";
|
|
13
|
+
import { ZodPipe } from "../http/zod.pipe.js";
|
|
14
|
+
import { CurrentPrincipal, patTokenId, requireUser, } from "../identity/principal.js";
|
|
15
|
+
import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
|
|
16
|
+
import { CONTROL_OR_HIDDEN_RE } from "../text.js";
|
|
17
|
+
import { APPROVAL_DENY_REASON_MAX_CHARS, } from "./approvals.service.js";
|
|
18
|
+
const ListQuery = z
|
|
19
|
+
.object({ status: z.enum(["pending", "approved", "denied", "expired", "cancelled"]).optional() })
|
|
20
|
+
.strict();
|
|
21
|
+
const DecisionBody = z
|
|
22
|
+
.object({
|
|
23
|
+
decision: z.enum(["approve", "deny"]),
|
|
24
|
+
scope: z.enum(["once", "session", "always"]).optional(),
|
|
25
|
+
note: z.string().max(1000).optional(),
|
|
26
|
+
/** Only with `deny`: passed to the model with the denied call's result. */
|
|
27
|
+
// no control characters but newline and tab, and no format characters (bidi, invisible; ZWNJ
|
|
28
|
+
// and ZWJ allowed): the title rule (final review m1; PG also rejects NUL)
|
|
29
|
+
reason: z
|
|
30
|
+
.string()
|
|
31
|
+
.trim()
|
|
32
|
+
.min(1)
|
|
33
|
+
.max(APPROVAL_DENY_REASON_MAX_CHARS)
|
|
34
|
+
.refine((r) => !CONTROL_OR_HIDDEN_RE.test(r.replace(/[\n\t]/g, " ")), "reason must not contain control or format characters")
|
|
35
|
+
.optional(),
|
|
36
|
+
})
|
|
37
|
+
.strict()
|
|
38
|
+
.refine((b) => b.reason === undefined || b.decision === "deny", {
|
|
39
|
+
path: ["reason"],
|
|
40
|
+
message: "A reason can only be given with deny",
|
|
41
|
+
});
|
|
42
|
+
/**
|
|
43
|
+
* 工具调用审批(`/api/v1/orgs/:orgId/approvals`,`approvals.decide`:访客起、仅限用户主体——agent 不能审批,R2)。
|
|
44
|
+
* 能否看到 / 处理某条审批由 `requested_for` / `approver_role` 判定(见 `ApprovalsService`),看不到的一律 404。
|
|
45
|
+
*/
|
|
46
|
+
let ApprovalsController = class ApprovalsController {
|
|
47
|
+
approvals;
|
|
48
|
+
constructor(approvals) {
|
|
49
|
+
this.approvals = approvals;
|
|
50
|
+
}
|
|
51
|
+
async list(principal, org, q) {
|
|
52
|
+
const p = requireUser(principal);
|
|
53
|
+
return { approvals: await this.approvals.list(org.orgId, p.account.id, q.status) };
|
|
54
|
+
}
|
|
55
|
+
async get(principal, org, id) {
|
|
56
|
+
const p = requireUser(principal);
|
|
57
|
+
return { approval: await this.approvals.get(org.orgId, id, p.account.id) };
|
|
58
|
+
}
|
|
59
|
+
async decide(principal, org, id, body) {
|
|
60
|
+
const p = requireUser(principal);
|
|
61
|
+
return {
|
|
62
|
+
approval: await this.approvals.decide(org.orgId, id, p.account.id, body, patTokenId(p)),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
__decorate([
|
|
67
|
+
Get(),
|
|
68
|
+
OrgAction("approvals.decide"),
|
|
69
|
+
__param(0, CurrentPrincipal()),
|
|
70
|
+
__param(1, CurrentOrg()),
|
|
71
|
+
__param(2, Query(new ZodPipe(ListQuery)))
|
|
72
|
+
], ApprovalsController.prototype, "list", null);
|
|
73
|
+
__decorate([
|
|
74
|
+
Get(":id"),
|
|
75
|
+
OrgAction("approvals.decide"),
|
|
76
|
+
__param(0, CurrentPrincipal()),
|
|
77
|
+
__param(1, CurrentOrg()),
|
|
78
|
+
__param(2, Param("id"))
|
|
79
|
+
], ApprovalsController.prototype, "get", null);
|
|
80
|
+
__decorate([
|
|
81
|
+
Post(":id/decision"),
|
|
82
|
+
HttpCode(200),
|
|
83
|
+
OrgAction("approvals.decide"),
|
|
84
|
+
__param(0, CurrentPrincipal()),
|
|
85
|
+
__param(1, CurrentOrg()),
|
|
86
|
+
__param(2, Param("id")),
|
|
87
|
+
__param(3, Body(new ZodPipe(DecisionBody)))
|
|
88
|
+
], ApprovalsController.prototype, "decide", null);
|
|
89
|
+
ApprovalsController = __decorate([
|
|
90
|
+
Controller("api/v1/orgs/:orgId/approvals"),
|
|
91
|
+
__param(0, Inject(APPROVALS))
|
|
92
|
+
], ApprovalsController);
|
|
93
|
+
export { ApprovalsController };
|
|
94
|
+
/** 本人的「以后都允许」授权(`/api/v1/orgs/:orgId/me/tool-grants`):查看与撤销,只动自己的。 */
|
|
95
|
+
let ToolGrantsController = class ToolGrantsController {
|
|
96
|
+
approvals;
|
|
97
|
+
constructor(approvals) {
|
|
98
|
+
this.approvals = approvals;
|
|
99
|
+
}
|
|
100
|
+
async list(principal, org) {
|
|
101
|
+
const p = requireUser(principal);
|
|
102
|
+
return { grants: await this.approvals.listGrants(org.orgId, p.account.id) };
|
|
103
|
+
}
|
|
104
|
+
async revoke(principal, org, agentId, toolKey) {
|
|
105
|
+
const p = requireUser(principal);
|
|
106
|
+
await this.approvals.revokeGrant(org.orgId, p.account.id, agentId, toolKey, patTokenId(p));
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
__decorate([
|
|
110
|
+
Get(),
|
|
111
|
+
OrgAction("approvals.decide"),
|
|
112
|
+
__param(0, CurrentPrincipal()),
|
|
113
|
+
__param(1, CurrentOrg())
|
|
114
|
+
], ToolGrantsController.prototype, "list", null);
|
|
115
|
+
__decorate([
|
|
116
|
+
Delete(":agentId/:toolKey"),
|
|
117
|
+
HttpCode(204),
|
|
118
|
+
OrgAction("approvals.decide"),
|
|
119
|
+
__param(0, CurrentPrincipal()),
|
|
120
|
+
__param(1, CurrentOrg()),
|
|
121
|
+
__param(2, Param("agentId")),
|
|
122
|
+
__param(3, Param("toolKey"))
|
|
123
|
+
], ToolGrantsController.prototype, "revoke", null);
|
|
124
|
+
ToolGrantsController = __decorate([
|
|
125
|
+
Controller("api/v1/orgs/:orgId/me/tool-grants"),
|
|
126
|
+
__param(0, Inject(APPROVALS))
|
|
127
|
+
], ToolGrantsController);
|
|
128
|
+
export { ToolGrantsController };
|