@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,481 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { readOrgSettings } from "../orgs/settings.service.js";
|
|
3
|
+
import { estimateTokens } from "../runtime/context/tokens.js";
|
|
4
|
+
import { SUBAGENT_LIMIT_DEFAULTS, subagentLimits } from "../runtime/subagents/limits.js";
|
|
5
|
+
import { resolveRoster } from "../runtime/subagents/roster.js";
|
|
6
|
+
import { AGENT_TOOL, agentToolSpec } from "./builtins/agent.js";
|
|
7
|
+
import { SANDBOX_TOOL_NAMES } from "./builtins/sandbox/names.js";
|
|
8
|
+
import { toolKey, toolKeyIssue } from "./naming.js";
|
|
9
|
+
/**
|
|
10
|
+
* 内核内置工具的名字(Task 10 / Task 19 实现;M5 T8 加沙箱工具)。保存 agent 时内置工具引用按这份清单校验,
|
|
11
|
+
* 不依赖当前是否已注册,避免实现落地顺序影响已保存的定义;运行时未注册的照常报不可用。
|
|
12
|
+
* `skill_write`(M5 T15)由 agent 定义显式引用才可用(负责人决定 agent 能否改自己的技能)。
|
|
13
|
+
*/
|
|
14
|
+
export const BUILTIN_TOOL_NAMES = [
|
|
15
|
+
"ask_user",
|
|
16
|
+
"read_tool_output",
|
|
17
|
+
"tool_search",
|
|
18
|
+
"skill_load",
|
|
19
|
+
"skill_write",
|
|
20
|
+
...SANDBOX_TOOL_NAMES,
|
|
21
|
+
// phase C: dispatches sub-agents; its description is built per agent from the roster
|
|
22
|
+
"agent",
|
|
23
|
+
];
|
|
24
|
+
/** 键排序、去掉 undefined 的 JSON(jsonb 不保留键顺序,指纹必须与顺序无关)。 */
|
|
25
|
+
export function canonicalJson(v) {
|
|
26
|
+
if (Array.isArray(v))
|
|
27
|
+
return `[${v.map(canonicalJson).join(",")}]`;
|
|
28
|
+
if (v !== null && typeof v === "object") {
|
|
29
|
+
const entries = Object.entries(v)
|
|
30
|
+
.filter(([, x]) => x !== undefined)
|
|
31
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
|
|
32
|
+
return `{${entries.map(([k, x]) => `${JSON.stringify(k)}:${canonicalJson(x)}`).join(",")}}`;
|
|
33
|
+
}
|
|
34
|
+
return JSON.stringify(v);
|
|
35
|
+
}
|
|
36
|
+
/** The first 16 hex digits of sha256(canonicalJson(v)): a fingerprint independent of key order. */
|
|
37
|
+
export function contentHash(v) {
|
|
38
|
+
return createHash("sha256").update(canonicalJson(v)).digest("hex").slice(0, 16);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* `ToolSpec` fields that are display only (UI refresh B): never sent to the model and left out of
|
|
42
|
+
* the definition fingerprint, so adding or changing them never changes `model_call.request.tools`,
|
|
43
|
+
* never sends a connector tool to drift review and never invalidates a remembered grant.
|
|
44
|
+
*/
|
|
45
|
+
export const DISPLAY_ONLY_SPEC_FIELDS = ["title", "keyArgs"];
|
|
46
|
+
/** A tool spec without its {@link DISPLAY_ONLY_SPEC_FIELDS} (non-objects unchanged). */
|
|
47
|
+
export function withoutDisplayFields(spec) {
|
|
48
|
+
if (spec === null || typeof spec !== "object" || Array.isArray(spec))
|
|
49
|
+
return spec;
|
|
50
|
+
const out = { ...spec };
|
|
51
|
+
for (const f of DISPLAY_ONLY_SPEC_FIELDS)
|
|
52
|
+
delete out[f];
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Tool definition fingerprint: {@link contentHash} of the spec without its display-only fields
|
|
57
|
+
* (`title`, `keyArgs`). Specs without them hash exactly as before.
|
|
58
|
+
*/
|
|
59
|
+
export function specHash(spec) {
|
|
60
|
+
return contentHash(withoutDisplayFields(spec));
|
|
61
|
+
}
|
|
62
|
+
/** 由注解推导默认策略:只读 → allow;其余(破坏性 / 无注解)→ ask。 */
|
|
63
|
+
export function policyFromAnnotations(a) {
|
|
64
|
+
return a?.readOnlyHint === true ? "allow" : "ask";
|
|
65
|
+
}
|
|
66
|
+
/** 内置 `tool_search` 的名字(由注册表按组织设置与阈值自动加入,不进 agent 定义)。 */
|
|
67
|
+
const TOOL_SEARCH = "tool_search";
|
|
68
|
+
/** 内置 `skill_load` 的名字(对话日志里有技能目录快照时由注册表自动加入,不进 agent 定义)。 */
|
|
69
|
+
const SKILL_LOAD = "skill_load";
|
|
70
|
+
/** 工具定义(模型可见三项)的估算 token 数(与请求估算同一口径)。 */
|
|
71
|
+
function estimateToolTokens(tools) {
|
|
72
|
+
return estimateTokens([], [], tools.map((t) => ({
|
|
73
|
+
name: t.key,
|
|
74
|
+
description: t.spec.description,
|
|
75
|
+
inputSchema: t.spec.inputSchema,
|
|
76
|
+
})));
|
|
77
|
+
}
|
|
78
|
+
const sourceId = (s) => s.kind === "builtin"
|
|
79
|
+
? `builtin:${s.name}`
|
|
80
|
+
: s.kind === "plugin"
|
|
81
|
+
? `plugin:${s.plugin}:${s.name}`
|
|
82
|
+
: `connector:${s.connectorId}:${s.name}`;
|
|
83
|
+
/**
|
|
84
|
+
* Tool registry: resolves the references in an agent definition into the tools available for this
|
|
85
|
+
* run. Not cached (reads PG and the host live every time), so changes take effect right away across
|
|
86
|
+
* replicas.
|
|
87
|
+
*
|
|
88
|
+
* Availability:
|
|
89
|
+
* - builtin: in `builtins`;
|
|
90
|
+
* - extension tools: the extension is loaded and registered the tool, and this org enabled the
|
|
91
|
+
* extension (`extension_org_configs.enabled`, spec 2.2 "installed at deployment level, enabled at
|
|
92
|
+
* org level"; required bootstrap plugins are enabled in every org, `enabled.ts`);
|
|
93
|
+
* - connector tools: the connector belongs to this org, is not deleted or disabled, the connector is
|
|
94
|
+
* installed, the tool status is `enabled` and the key is valid.
|
|
95
|
+
* `tools: "all"` takes only enabled tools; disabled / pending-review ones count as deliberately
|
|
96
|
+
* turned off by an admin and are not reported; named tools report their reason one by one.
|
|
97
|
+
* Only the first of a key is kept; the same source referenced twice is deduplicated silently,
|
|
98
|
+
* different sources with the same key report a duplicate.
|
|
99
|
+
*/
|
|
100
|
+
export class ToolRegistry {
|
|
101
|
+
deps;
|
|
102
|
+
constructor(deps) {
|
|
103
|
+
this.deps = deps;
|
|
104
|
+
}
|
|
105
|
+
/** `host.list("connector")` 中 `kind` 匹配的第一个实现;未安装返回 undefined。 */
|
|
106
|
+
findConnector(kind) {
|
|
107
|
+
for (const e of this.deps.host.list("connector")) {
|
|
108
|
+
const impl = e.impl;
|
|
109
|
+
if (impl?.kind === kind)
|
|
110
|
+
return impl;
|
|
111
|
+
}
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
/** 同 {@link findConnector},未安装时抛错。 */
|
|
115
|
+
connector(kind) {
|
|
116
|
+
const c = this.findConnector(kind);
|
|
117
|
+
if (!c)
|
|
118
|
+
throw new Error(`connector ${kind} is not installed`);
|
|
119
|
+
return c;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The handler of a builtin / extension tool (for the execution pipeline); connector tools run
|
|
123
|
+
* through the connector and return undefined. Also undefined when the extension was unloaded and so
|
|
124
|
+
* on. Extension tools resolve the current instance live and call through the instance's in-flight
|
|
125
|
+
* tracker (C17): on revocation it drains first and aborts at the limit, ending with
|
|
126
|
+
* `ExtensionUnloadedError` (the pipeline turns it into an English error result for the model).
|
|
127
|
+
*/
|
|
128
|
+
handler(source) {
|
|
129
|
+
if (source.kind === "builtin") {
|
|
130
|
+
return this.deps.builtins.find((b) => b.spec.name === source.name)?.run;
|
|
131
|
+
}
|
|
132
|
+
if (source.kind === "plugin") {
|
|
133
|
+
const t = this.deps.host
|
|
134
|
+
.tools()
|
|
135
|
+
.find((x) => x.plugin === source.plugin && x.spec.name === source.name);
|
|
136
|
+
if (!t)
|
|
137
|
+
return undefined;
|
|
138
|
+
return (input, ctx) => t.inflight.run(ctx.signal, (signal) => t.handler(input, { ...ctx, signal }));
|
|
139
|
+
}
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
/** The registered builtin tools' specs (display metadata for `tools/info.ts`). */
|
|
143
|
+
builtinSpecs() {
|
|
144
|
+
return this.deps.builtins.map((b) => b.spec);
|
|
145
|
+
}
|
|
146
|
+
/** The loaded extensions' registered tool specs, with their extension's name. */
|
|
147
|
+
extensionToolSpecs() {
|
|
148
|
+
return this.deps.host.tools().map((t) => ({ plugin: t.plugin, spec: t.spec }));
|
|
149
|
+
}
|
|
150
|
+
/** 已安装连接器的 kind 列表(去重,按加载顺序)。 */
|
|
151
|
+
connectorKinds() {
|
|
152
|
+
return [...new Set(this.deps.host.list("connector").map((e) => e.impl.kind))];
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* 保存 agent 时校验工具引用(只看「存在」,停用 / 待复核 / 插件未启用等运行时状态不拒绝,由 `forAgent` 报不可用):
|
|
156
|
+
* - 内置:名字在 {@link BUILTIN_TOOL_NAMES} 中;
|
|
157
|
+
* - 插件:插件已加载且注册了该工具,key 合法;
|
|
158
|
+
* - 连接器:连接器属于本组织且未删除;点名的工具必须在连接器的工具快照中。
|
|
159
|
+
* 不同来源拼出同一个 key 也报出来(不截断、不猜)。
|
|
160
|
+
* 返回 `keys`:这些引用可能产生的全部工具 key(`"all"` 含连接器当前所有工具,不论状态),供校验 `toolPolicies`。
|
|
161
|
+
*/
|
|
162
|
+
async checkRefs(orgId, refs) {
|
|
163
|
+
const issues = [];
|
|
164
|
+
const owner = new Map();
|
|
165
|
+
const pluginTools = this.deps.host.tools();
|
|
166
|
+
const connectorIds = [
|
|
167
|
+
...new Set(refs.flatMap((r) => (r.kind === "connector" ? [r.connectorId] : []))),
|
|
168
|
+
];
|
|
169
|
+
const apps = await this.loadConnectors(orgId, connectorIds);
|
|
170
|
+
const claim = (path, key, source) => {
|
|
171
|
+
const prev = owner.get(key);
|
|
172
|
+
if (prev === undefined)
|
|
173
|
+
owner.set(key, source);
|
|
174
|
+
else if (prev !== source) {
|
|
175
|
+
issues.push({ path, message: `Tool key "${key}" is already used by another tool` });
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
refs.forEach((ref, i) => {
|
|
179
|
+
const path = `tools.${i}`;
|
|
180
|
+
if (ref.kind === "builtin") {
|
|
181
|
+
if (!BUILTIN_TOOL_NAMES.includes(ref.name)) {
|
|
182
|
+
issues.push({ path, message: `Built-in tool "${ref.name}" does not exist` });
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
claim(path, ref.name, `builtin:${ref.name}`);
|
|
186
|
+
}
|
|
187
|
+
else if (ref.kind === "plugin") {
|
|
188
|
+
const key = toolKey(ref.plugin, ref.name);
|
|
189
|
+
if (!pluginTools.some((x) => x.plugin === ref.plugin && x.spec.name === ref.name)) {
|
|
190
|
+
issues.push({ path, message: `Plugin tool "${key}" does not exist` });
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const issue = toolKeyIssue(key);
|
|
194
|
+
if (issue) {
|
|
195
|
+
issues.push({ path, message: issue });
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
claim(path, key, `plugin:${ref.plugin}:${ref.name}`);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
const app = apps.get(ref.connectorId);
|
|
202
|
+
if (!app || app.deleted) {
|
|
203
|
+
issues.push({ path, message: `Connector "${ref.connectorId}" does not exist` });
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const names = ref.tools === "all" ? app.tools.map((t) => t.name) : [...new Set(ref.tools)];
|
|
207
|
+
for (const name of names) {
|
|
208
|
+
if (!app.tools.some((t) => t.name === name)) {
|
|
209
|
+
issues.push({
|
|
210
|
+
path,
|
|
211
|
+
message: `Tool "${name}" does not exist in connector ${app.slug}`,
|
|
212
|
+
});
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
claim(path, toolKey(app.slug, name), `connector:${app.id}:${name}`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
return { keys: new Set(owner.keys()), issues };
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* 解析 agent 引用的工具(见类注释),再判定是否启用 `tool_search`:组织设置 `toolSearch === "on"`,且
|
|
223
|
+
* 可用工具数 > `tools.searchThresholdTools` 或其定义的估算 token > `tools.searchThresholdTokens`。
|
|
224
|
+
* 启用时把内置 `tool_search` 追加到末尾。定义里显式引用的 `tool_search` 忽略(由这里按设置管理)。
|
|
225
|
+
* `skillLoad`:对话日志里有技能目录快照(`skills_catalog`,Ruling M17)→ 加入内置 `skill_load`(始终完整加载);
|
|
226
|
+
* 定义里显式引用的 `skill_load` 同样忽略。
|
|
227
|
+
*/
|
|
228
|
+
async forAgent(orgId, def) {
|
|
229
|
+
const { tools, unavailable, hidden } = await this.resolve(orgId, def);
|
|
230
|
+
const sl = def.skillLoad === true && this.deps.builtins.find((x) => x.spec.name === SKILL_LOAD);
|
|
231
|
+
if (sl) {
|
|
232
|
+
tools.push({
|
|
233
|
+
key: SKILL_LOAD,
|
|
234
|
+
source: { kind: "builtin", name: SKILL_LOAD },
|
|
235
|
+
spec: sl.spec,
|
|
236
|
+
specHash: specHash(sl.spec),
|
|
237
|
+
defaultPolicy: sl.defaultPolicy,
|
|
238
|
+
...(sl.timeoutMs !== undefined && { timeoutMs: sl.timeoutMs }),
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
const toolSearch = await this.searchActive(orgId, tools);
|
|
242
|
+
if (toolSearch) {
|
|
243
|
+
const b = this.deps.builtins.find((x) => x.spec.name === TOOL_SEARCH);
|
|
244
|
+
tools.push({
|
|
245
|
+
key: TOOL_SEARCH,
|
|
246
|
+
source: { kind: "builtin", name: TOOL_SEARCH },
|
|
247
|
+
spec: b.spec,
|
|
248
|
+
specHash: specHash(b.spec),
|
|
249
|
+
defaultPolicy: b.defaultPolicy,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
return { tools, unavailable, hidden, toolSearch };
|
|
253
|
+
}
|
|
254
|
+
/** 是否启用 `tool_search`(见 {@link forAgent});先比阈值,超过才读组织设置。 */
|
|
255
|
+
async searchActive(orgId, tools) {
|
|
256
|
+
const cfg = this.deps.config?.().tools;
|
|
257
|
+
if (!cfg || !this.deps.builtins.some((b) => b.spec.name === TOOL_SEARCH))
|
|
258
|
+
return false;
|
|
259
|
+
const over = tools.length > cfg.searchThresholdTools ||
|
|
260
|
+
estimateToolTokens(tools) > cfg.searchThresholdTokens;
|
|
261
|
+
if (!over)
|
|
262
|
+
return false;
|
|
263
|
+
return (await readOrgSettings(this.deps.db, orgId)).toolSearch === "on";
|
|
264
|
+
}
|
|
265
|
+
async resolve(orgId, def) {
|
|
266
|
+
const tools = [];
|
|
267
|
+
const unavailable = [];
|
|
268
|
+
const hidden = [];
|
|
269
|
+
const seen = new Map();
|
|
270
|
+
const add = (t) => {
|
|
271
|
+
const id = sourceId(t.source);
|
|
272
|
+
const prev = seen.get(t.key);
|
|
273
|
+
if (prev === undefined) {
|
|
274
|
+
seen.set(t.key, id);
|
|
275
|
+
tools.push(t);
|
|
276
|
+
}
|
|
277
|
+
else if (prev !== id) {
|
|
278
|
+
unavailable.push({
|
|
279
|
+
ref: t.key,
|
|
280
|
+
reason: "Another tool with the same name is already loaded",
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
const enabledPlugins = def.tools.some((r) => r.kind === "plugin")
|
|
285
|
+
? await this.enabledPlugins(orgId)
|
|
286
|
+
: new Set();
|
|
287
|
+
const connectorIds = [
|
|
288
|
+
...new Set(def.tools.flatMap((r) => (r.kind === "connector" ? [r.connectorId] : []))),
|
|
289
|
+
];
|
|
290
|
+
const apps = await this.loadConnectors(orgId, connectorIds);
|
|
291
|
+
const pluginTools = this.deps.host.tools();
|
|
292
|
+
for (const ref of def.tools) {
|
|
293
|
+
if (ref.kind === "builtin") {
|
|
294
|
+
if (ref.name === TOOL_SEARCH || ref.name === SKILL_LOAD)
|
|
295
|
+
continue;
|
|
296
|
+
const b = this.deps.builtins.find((x) => x.spec.name === ref.name);
|
|
297
|
+
if (!b) {
|
|
298
|
+
unavailable.push({ ref: ref.name, reason: "Built-in tool does not exist" });
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
const why = b.unavailable?.() ?? null;
|
|
302
|
+
if (why !== null) {
|
|
303
|
+
unavailable.push({ ref: ref.name, reason: why });
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
// `agent`: the description lists this definition's roster (sub-agents spec §4.3); with an
|
|
307
|
+
// empty roster there is nothing to dispatch, so the tool is not offered at all
|
|
308
|
+
let spec = b.spec;
|
|
309
|
+
if (b.spec.name === AGENT_TOOL) {
|
|
310
|
+
const roster = await resolveRoster(this.deps.db, orgId, { subagents: def.subagents });
|
|
311
|
+
if (roster.length === 0)
|
|
312
|
+
continue;
|
|
313
|
+
spec = agentToolSpec(roster, await this.maxConcurrentSubagents(orgId));
|
|
314
|
+
}
|
|
315
|
+
add({
|
|
316
|
+
key: b.spec.name,
|
|
317
|
+
source: { kind: "builtin", name: b.spec.name },
|
|
318
|
+
spec,
|
|
319
|
+
specHash: specHash(spec),
|
|
320
|
+
defaultPolicy: b.defaultPolicy,
|
|
321
|
+
...(b.timeoutMs !== undefined && { timeoutMs: b.timeoutMs }),
|
|
322
|
+
...(b.spillChars !== undefined && { spillChars: b.spillChars }),
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
else if (ref.kind === "plugin") {
|
|
326
|
+
const key = toolKey(ref.plugin, ref.name);
|
|
327
|
+
const t = pluginTools.find((x) => x.plugin === ref.plugin && x.spec.name === ref.name);
|
|
328
|
+
if (!t) {
|
|
329
|
+
unavailable.push({ ref: key, reason: "Plugin tool does not exist" });
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
if (!enabledPlugins.has(ref.plugin)) {
|
|
333
|
+
unavailable.push({
|
|
334
|
+
ref: key,
|
|
335
|
+
reason: `Plugin ${ref.plugin} is not enabled in this organization`,
|
|
336
|
+
});
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
const issue = toolKeyIssue(key);
|
|
340
|
+
if (issue) {
|
|
341
|
+
unavailable.push({ ref: key, reason: issue });
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
add({
|
|
345
|
+
key,
|
|
346
|
+
source: { kind: "plugin", plugin: ref.plugin, name: ref.name },
|
|
347
|
+
spec: t.spec,
|
|
348
|
+
specHash: specHash(t.spec),
|
|
349
|
+
defaultPolicy: t.spec.defaultPolicy ?? policyFromAnnotations(t.spec.annotations),
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
const app = apps.get(ref.connectorId);
|
|
354
|
+
if (!app) {
|
|
355
|
+
unavailable.push({ ref: `app:${ref.connectorId}`, reason: "App does not exist" });
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
const all = toolKey(app.slug, "*");
|
|
359
|
+
if (app.deleted) {
|
|
360
|
+
unavailable.push({ ref: all, reason: `App ${app.slug} was deleted` });
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
if (app.status !== "active") {
|
|
364
|
+
unavailable.push({ ref: all, reason: `App ${app.slug} is disabled` });
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
if (!this.findConnector(app.connector)) {
|
|
368
|
+
unavailable.push({
|
|
369
|
+
ref: all,
|
|
370
|
+
reason: `Connector ${app.connector} for app ${app.slug} is not installed`,
|
|
371
|
+
});
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
const wanted = ref.tools === "all"
|
|
375
|
+
? app.tools
|
|
376
|
+
: ref.tools.map((name) => app.tools.find((t) => t.name === name) ?? { name, missing: true });
|
|
377
|
+
// 「all」里未启用的工具不算 agent 点名要的,不进 unavailable(不提醒),只记进 hidden 备查
|
|
378
|
+
const notEnabled = ref.tools === "all" ? hidden : unavailable;
|
|
379
|
+
for (const t of wanted) {
|
|
380
|
+
const key = toolKey(app.slug, t.name);
|
|
381
|
+
// 远端已不再提供(漂移检测置停用并标记,见 drift.ts):与「没有这一行」同一个事实
|
|
382
|
+
if ("missing" in t || t.gone) {
|
|
383
|
+
notEnabled.push({ ref: key, reason: `Tool no longer exists in app ${app.slug}` });
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
if (t.status === "disabled") {
|
|
387
|
+
notEnabled.push({ ref: key, reason: "Tool is disabled" });
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
if (t.status === "pending_review") {
|
|
391
|
+
notEnabled.push({ ref: key, reason: "Tool is pending review" });
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
const issue = toolKeyIssue(key);
|
|
395
|
+
if (issue) {
|
|
396
|
+
unavailable.push({ ref: key, reason: issue });
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
add({
|
|
400
|
+
key,
|
|
401
|
+
source: {
|
|
402
|
+
kind: "connector",
|
|
403
|
+
connectorId: app.id,
|
|
404
|
+
name: t.name,
|
|
405
|
+
...(t.source === "resources" && { resources: true }),
|
|
406
|
+
},
|
|
407
|
+
spec: t.spec,
|
|
408
|
+
specHash: t.specHash,
|
|
409
|
+
defaultPolicy: t.defaultPolicy,
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return { tools, unavailable, hidden };
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* `subagents.maxConcurrentPerRun` with the organization's override, for the `agent` tool's
|
|
418
|
+
* description (§4.3). A change of the limit changes the tool's spec hash; replays read the
|
|
419
|
+
* definition logged by hash, so no drift reason is involved. Without config (some tests): the
|
|
420
|
+
* schema default.
|
|
421
|
+
*/
|
|
422
|
+
async maxConcurrentSubagents(orgId) {
|
|
423
|
+
const config = this.deps.config ?? (() => ({ subagents: SUBAGENT_LIMIT_DEFAULTS }));
|
|
424
|
+
return (await subagentLimits(this.deps.db, config, orgId)).maxConcurrentPerRun;
|
|
425
|
+
}
|
|
426
|
+
/** Plugins the organization enabled (built-in plugins always count as enabled, C14). */
|
|
427
|
+
async enabledPlugins(orgId) {
|
|
428
|
+
return this.deps.host.enabledPlugins(orgId);
|
|
429
|
+
}
|
|
430
|
+
async loadConnectors(orgId, ids) {
|
|
431
|
+
const out = new Map();
|
|
432
|
+
if (ids.length === 0)
|
|
433
|
+
return out;
|
|
434
|
+
// 软删除的连接器也读出来,只为给出「已删除」这个更准确的原因(slug 可能已被新连接器复用,按 id 区分)
|
|
435
|
+
const apps = await this.deps.db
|
|
436
|
+
.selectFrom("connectors")
|
|
437
|
+
.select(["id", "slug", "connector", "status", "deleted_at"])
|
|
438
|
+
.where("org_id", "=", orgId)
|
|
439
|
+
.where("id", "in", ids)
|
|
440
|
+
.execute();
|
|
441
|
+
const live = apps.filter((a) => a.deleted_at === null).map((a) => a.id);
|
|
442
|
+
const toolRows = live.length === 0
|
|
443
|
+
? []
|
|
444
|
+
: await this.deps.db
|
|
445
|
+
.selectFrom("connector_tools")
|
|
446
|
+
.select([
|
|
447
|
+
"connector_id",
|
|
448
|
+
"name",
|
|
449
|
+
"spec",
|
|
450
|
+
"spec_hash",
|
|
451
|
+
"status",
|
|
452
|
+
"default_policy",
|
|
453
|
+
"source",
|
|
454
|
+
"missing_since",
|
|
455
|
+
])
|
|
456
|
+
.where("connector_id", "in", live)
|
|
457
|
+
.orderBy("name")
|
|
458
|
+
.execute();
|
|
459
|
+
for (const a of apps) {
|
|
460
|
+
out.set(a.id, {
|
|
461
|
+
id: a.id,
|
|
462
|
+
slug: a.slug,
|
|
463
|
+
connector: a.connector,
|
|
464
|
+
status: a.status,
|
|
465
|
+
deleted: a.deleted_at !== null,
|
|
466
|
+
tools: toolRows
|
|
467
|
+
.filter((t) => t.connector_id === a.id)
|
|
468
|
+
.map((t) => ({
|
|
469
|
+
name: t.name,
|
|
470
|
+
spec: t.spec,
|
|
471
|
+
specHash: t.spec_hash,
|
|
472
|
+
status: t.status,
|
|
473
|
+
defaultPolicy: t.default_policy,
|
|
474
|
+
source: t.source,
|
|
475
|
+
gone: t.missing_since !== null,
|
|
476
|
+
})),
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
return out;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ConnectorSession, type ToolResult, type ToolSpec } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* 连接器 resources 的两个内核工具(brief:`<connectorSlug>__list_resources`、`<connectorSlug>__read_resource {uri}`)。
|
|
4
|
+
*
|
|
5
|
+
* 设计:安装 / 刷新连接器时,连接器会话带 `listResources` 方法即视为支持 resources(不额外调用,免得多一次外连
|
|
6
|
+
* 和多一种失败),内核把这两个工具作为 `source = 'resources'` 的行写进 `connector_tools`(迁移 0013)。这样它们和
|
|
7
|
+
* 连接器工具走同一套机制:管理员可启停、改默认策略,agent 可点名引用或随 `tools: "all"` 带上,策略 / 授权 /
|
|
8
|
+
* 审批按 key 与指纹生效;执行时管线按 `source` 路由到会话的 `listResources` / `readResource`。
|
|
9
|
+
* 只读注解 → 默认 `allow`。连接器自己有同名工具时连接器的优先,内核的那个不加并报原因。
|
|
10
|
+
*/
|
|
11
|
+
export declare const LIST_RESOURCES = "list_resources";
|
|
12
|
+
export declare const READ_RESOURCE = "read_resource";
|
|
13
|
+
/** 两个工具的定义(与 slug 无关,指纹稳定)。 */
|
|
14
|
+
export declare function resourceToolSpecs(): ToolSpec[];
|
|
15
|
+
/** 执行 resources 工具:路由到会话的 listResources / readResource。 */
|
|
16
|
+
export declare function runResourceTool(session: ConnectorSession, name: string, input: unknown): Promise<ToolResult>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { ToolError, } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* 连接器 resources 的两个内核工具(brief:`<connectorSlug>__list_resources`、`<connectorSlug>__read_resource {uri}`)。
|
|
4
|
+
*
|
|
5
|
+
* 设计:安装 / 刷新连接器时,连接器会话带 `listResources` 方法即视为支持 resources(不额外调用,免得多一次外连
|
|
6
|
+
* 和多一种失败),内核把这两个工具作为 `source = 'resources'` 的行写进 `connector_tools`(迁移 0013)。这样它们和
|
|
7
|
+
* 连接器工具走同一套机制:管理员可启停、改默认策略,agent 可点名引用或随 `tools: "all"` 带上,策略 / 授权 /
|
|
8
|
+
* 审批按 key 与指纹生效;执行时管线按 `source` 路由到会话的 `listResources` / `readResource`。
|
|
9
|
+
* 只读注解 → 默认 `allow`。连接器自己有同名工具时连接器的优先,内核的那个不加并报原因。
|
|
10
|
+
*/
|
|
11
|
+
export const LIST_RESOURCES = "list_resources";
|
|
12
|
+
export const READ_RESOURCE = "read_resource";
|
|
13
|
+
/** 两个工具的定义(与 slug 无关,指纹稳定)。 */
|
|
14
|
+
export function resourceToolSpecs() {
|
|
15
|
+
return [
|
|
16
|
+
{
|
|
17
|
+
name: LIST_RESOURCES,
|
|
18
|
+
description: "List the resources (documents, files, records) this app exposes. Returns a JSON array of { uri, name, description?, mimeType? }; read one with this app's read_resource tool.",
|
|
19
|
+
inputSchema: { type: "object", properties: {}, additionalProperties: false },
|
|
20
|
+
annotations: { readOnlyHint: true },
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: READ_RESOURCE,
|
|
24
|
+
description: "Read the content of one of this app's resources by its URI (get URIs from this app's list_resources tool).",
|
|
25
|
+
inputSchema: {
|
|
26
|
+
type: "object",
|
|
27
|
+
properties: { uri: { type: "string", description: "Resource URI from list_resources" } },
|
|
28
|
+
required: ["uri"],
|
|
29
|
+
additionalProperties: false,
|
|
30
|
+
},
|
|
31
|
+
annotations: { readOnlyHint: true },
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
const NOT_SUPPORTED = "This app no longer supports resources; ask an administrator to refresh the app.";
|
|
36
|
+
/** 显示摘要里的资源地址上限(码点):摘要整体须 ≤ 200 码点。 */
|
|
37
|
+
const DISPLAY_URI_MAX = 150;
|
|
38
|
+
const shortUri = (uri) => {
|
|
39
|
+
const cps = [...uri.replace(/\s+/g, " ")];
|
|
40
|
+
return cps.length > DISPLAY_URI_MAX
|
|
41
|
+
? `${cps.slice(0, DISPLAY_URI_MAX - 1).join("")}…`
|
|
42
|
+
: cps.join("");
|
|
43
|
+
};
|
|
44
|
+
/** 执行 resources 工具:路由到会话的 listResources / readResource。 */
|
|
45
|
+
export async function runResourceTool(session, name, input) {
|
|
46
|
+
if (name === LIST_RESOURCES) {
|
|
47
|
+
if (!session.listResources)
|
|
48
|
+
throw new ToolError(NOT_SUPPORTED);
|
|
49
|
+
const items = await session.listResources();
|
|
50
|
+
return {
|
|
51
|
+
content: [
|
|
52
|
+
{
|
|
53
|
+
type: "text",
|
|
54
|
+
text: items.length === 0 ? "This app exposes no resources." : JSON.stringify(items),
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
display: {
|
|
58
|
+
summary: { zh: `列出资源 · ${items.length} 个`, en: `Listed resources · ${items.length}` },
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
if (name === READ_RESOURCE) {
|
|
63
|
+
if (!session.readResource)
|
|
64
|
+
throw new ToolError(NOT_SUPPORTED);
|
|
65
|
+
const uri = input?.uri;
|
|
66
|
+
if (typeof uri !== "string" || uri === "")
|
|
67
|
+
throw new ToolError("uri must be a non-empty string.");
|
|
68
|
+
// 摘要由内核给(覆盖连接器结果里可能带的 display:那来自外部服务,不采信)
|
|
69
|
+
const u = shortUri(uri);
|
|
70
|
+
return {
|
|
71
|
+
...(await session.readResource(uri)),
|
|
72
|
+
display: { summary: { zh: `读取资源 ${u}`, en: `Read resource ${u}` } },
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
throw new ToolError(`Unknown resource tool ${name}.`);
|
|
76
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ToolSpec } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import type { Transaction } from "kysely";
|
|
3
|
+
import type { KernelDatabase, KernelDb } from "../db/kernel-schema.js";
|
|
4
|
+
/**
|
|
5
|
+
* 把工具定义按指纹存进 `capybara.tool_specs`(内容寻址:同一指纹只存一次,已存在不改)。
|
|
6
|
+
* `model_call` 只记 `{key, specHash}`,定义本身存这里——连接器刷新 / 插件升级改了定义之后,早先请求用过的定义
|
|
7
|
+
* 仍可按指纹取回,模型请求可由日志还原。
|
|
8
|
+
*/
|
|
9
|
+
export declare function recordToolSpecs(db: KernelDb | Transaction<KernelDatabase>, specs: readonly {
|
|
10
|
+
specHash: string;
|
|
11
|
+
spec: ToolSpec;
|
|
12
|
+
}[]): Promise<void>;
|
|
13
|
+
/** 按指纹取回工具定义;没有记录 → null。 */
|
|
14
|
+
export declare function loadToolSpec(db: KernelDb, specHash: string): Promise<ToolSpec | null>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 把工具定义按指纹存进 `capybara.tool_specs`(内容寻址:同一指纹只存一次,已存在不改)。
|
|
3
|
+
* `model_call` 只记 `{key, specHash}`,定义本身存这里——连接器刷新 / 插件升级改了定义之后,早先请求用过的定义
|
|
4
|
+
* 仍可按指纹取回,模型请求可由日志还原。
|
|
5
|
+
*/
|
|
6
|
+
export async function recordToolSpecs(db, specs) {
|
|
7
|
+
const unique = new Map();
|
|
8
|
+
for (const s of specs)
|
|
9
|
+
if (!unique.has(s.specHash))
|
|
10
|
+
unique.set(s.specHash, s.spec);
|
|
11
|
+
if (unique.size === 0)
|
|
12
|
+
return;
|
|
13
|
+
// 按指纹排序插入:并发事务插入同一批指纹时加锁顺序一致,不会互相死锁
|
|
14
|
+
const rows = [...unique]
|
|
15
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
16
|
+
.map(([hash, spec]) => ({ spec_hash: hash, spec: JSON.stringify(spec) }));
|
|
17
|
+
await db
|
|
18
|
+
.insertInto("tool_specs")
|
|
19
|
+
.values(rows)
|
|
20
|
+
.onConflict((oc) => oc.column("spec_hash").doNothing())
|
|
21
|
+
.execute();
|
|
22
|
+
}
|
|
23
|
+
/** 按指纹取回工具定义;没有记录 → null。 */
|
|
24
|
+
export async function loadToolSpec(db, specHash) {
|
|
25
|
+
const row = await db
|
|
26
|
+
.selectFrom("tool_specs")
|
|
27
|
+
.select("spec")
|
|
28
|
+
.where("spec_hash", "=", specHash)
|
|
29
|
+
.executeTakeFirst();
|
|
30
|
+
return row ? row.spec : null;
|
|
31
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Logger, ToolSpec } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
/** 不受信任的 schema(连接器工具,来自连接器)JSON 序列化后的字节上限:超过不编译、不校验。 */
|
|
3
|
+
export declare const UNTRUSTED_SCHEMA_MAX_BYTES: number;
|
|
4
|
+
/** 不受信任的 schema 的嵌套层数上限(对象 / 数组层数):超过不编译、不校验。 */
|
|
5
|
+
export declare const UNTRUSTED_SCHEMA_MAX_DEPTH = 32;
|
|
6
|
+
export interface ValidateOptions {
|
|
7
|
+
/**
|
|
8
|
+
* schema 来自不受信任的来源(连接器工具,由连接器提供):编译前去掉 pattern / patternProperties / format,
|
|
9
|
+
* 并限制大小与嵌套层数(超限不校验)。
|
|
10
|
+
*/
|
|
11
|
+
untrusted?: boolean;
|
|
12
|
+
/** 跳过校验(超限 / 无法编译)时记 warn(只含 toolKey 与原因)。 */
|
|
13
|
+
log?: Pick<Logger, "warn">;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 管线第 2 阶段:按工具的 inputSchema 校验参数(ajv,JSON Schema 2020-12,`strict: false`,`allErrors: true`)。
|
|
17
|
+
* 合法 → null;不合法 → 给模型的英文说明:全部错误路径 + 完整 inputSchema(spec 6.3「给事实,不猜」)。
|
|
18
|
+
* schema 自身无法编译或超限时不拦截(返回 null)。
|
|
19
|
+
*/
|
|
20
|
+
export declare function validateInput(key: string, spec: ToolSpec, input: unknown, opts?: ValidateOptions): string | null;
|