@capybara-hq/kernel 0.0.0-stage → 0.1.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +2 -0
- package/README.md +20 -2
- package/bootstrap.json +22 -0
- package/dist/admin/admin.controller.d.ts +139 -0
- package/dist/admin/admin.controller.js +238 -0
- package/dist/admin/extensions.controller.d.ts +100 -0
- package/dist/admin/extensions.controller.js +226 -0
- package/dist/admin/setup.controller.d.ts +36 -0
- package/dist/admin/setup.controller.js +106 -0
- package/dist/admin/setup.service.d.ts +47 -0
- package/dist/admin/setup.service.js +90 -0
- package/dist/agents/agents.controller.d.ts +205 -0
- package/dist/agents/agents.controller.js +144 -0
- package/dist/agents/agents.service.d.ts +177 -0
- package/dist/agents/agents.service.js +677 -0
- package/dist/agents/definition.d.ts +198 -0
- package/dist/agents/definition.js +152 -0
- package/dist/agents/models.controller.d.ts +13 -0
- package/dist/agents/models.controller.js +31 -0
- package/dist/agents/templates.controller.d.ts +15 -0
- package/dist/agents/templates.controller.js +37 -0
- package/dist/agents/templates.d.ts +83 -0
- package/dist/agents/templates.js +173 -0
- package/dist/catalog/admin-catalog.controller.d.ts +143 -0
- package/dist/catalog/admin-catalog.controller.js +245 -0
- package/dist/catalog/catalog.service.d.ts +430 -0
- package/dist/catalog/catalog.service.js +882 -0
- package/dist/catalog/claude/agents.d.ts +27 -0
- package/dist/catalog/claude/agents.js +270 -0
- package/dist/catalog/claude/commands.d.ts +50 -0
- package/dist/catalog/claude/commands.js +179 -0
- package/dist/catalog/claude/manifest.d.ts +69 -0
- package/dist/catalog/claude/manifest.js +134 -0
- package/dist/catalog/claude/marketplace.d.ts +35 -0
- package/dist/catalog/claude/marketplace.js +194 -0
- package/dist/catalog/claude/mcp.d.ts +33 -0
- package/dist/catalog/claude/mcp.js +226 -0
- package/dist/catalog/claude/report.d.ts +86 -0
- package/dist/catalog/claude/report.js +121 -0
- package/dist/catalog/claude/translate.d.ts +56 -0
- package/dist/catalog/claude/translate.js +857 -0
- package/dist/catalog/cli.d.ts +46 -0
- package/dist/catalog/cli.js +211 -0
- package/dist/catalog/git-source.d.ts +127 -0
- package/dist/catalog/git-source.js +520 -0
- package/dist/catalog/marketplace-fetch.d.ts +99 -0
- package/dist/catalog/marketplace-fetch.js +203 -0
- package/dist/catalog/marketplaces.controller.d.ts +97 -0
- package/dist/catalog/marketplaces.controller.js +197 -0
- package/dist/catalog/marketplaces.service.d.ts +340 -0
- package/dist/catalog/marketplaces.service.js +1217 -0
- package/dist/catalog/org-catalog.controller.d.ts +128 -0
- package/dist/catalog/org-catalog.controller.js +277 -0
- package/dist/catalog/org-catalog.service.d.ts +246 -0
- package/dist/catalog/org-catalog.service.js +625 -0
- package/dist/catalog/plugin-import.d.ts +436 -0
- package/dist/catalog/plugin-import.js +1069 -0
- package/dist/catalog/plugin-install.d.ts +447 -0
- package/dist/catalog/plugin-install.js +1333 -0
- package/dist/catalog/plugin-package.d.ts +143 -0
- package/dist/catalog/plugin-package.js +382 -0
- package/dist/catalog/plugin-upgrade.d.ts +222 -0
- package/dist/catalog/plugin-upgrade.js +1219 -0
- package/dist/catalog/requests.service.d.ts +162 -0
- package/dist/catalog/requests.service.js +504 -0
- package/dist/catalog/schema-path.d.ts +7 -0
- package/dist/catalog/schema-path.js +63 -0
- package/dist/catalog/upgrade-targets.d.ts +59 -0
- package/dist/catalog/upgrade-targets.js +90 -0
- package/dist/catalog/versions.d.ts +31 -0
- package/dist/catalog/versions.js +44 -0
- package/dist/channels/actions.d.ts +37 -0
- package/dist/channels/actions.js +121 -0
- package/dist/channels/cards.d.ts +44 -0
- package/dist/channels/cards.js +156 -0
- package/dist/channels/connections.controller.d.ts +59 -0
- package/dist/channels/connections.controller.js +115 -0
- package/dist/channels/connections.service.d.ts +187 -0
- package/dist/channels/connections.service.js +534 -0
- package/dist/channels/features.d.ts +12 -0
- package/dist/channels/features.js +22 -0
- package/dist/channels/inbound.d.ts +120 -0
- package/dist/channels/inbound.js +332 -0
- package/dist/channels/outbound.d.ts +140 -0
- package/dist/channels/outbound.js +1125 -0
- package/dist/channels/phrases.d.ts +100 -0
- package/dist/channels/phrases.js +81 -0
- package/dist/channels/supervisor.d.ts +182 -0
- package/dist/channels/supervisor.js +625 -0
- package/dist/channels/threads.d.ts +29 -0
- package/dist/channels/threads.js +104 -0
- package/dist/channels/webhook-url.d.ts +16 -0
- package/dist/channels/webhook-url.js +34 -0
- package/dist/channels/webhook.controller.d.ts +19 -0
- package/dist/channels/webhook.controller.js +72 -0
- package/dist/channels/webhook.d.ts +73 -0
- package/dist/channels/webhook.js +274 -0
- package/dist/config/docs.d.ts +9 -0
- package/dist/config/docs.js +85 -0
- package/dist/config/env.d.ts +6 -0
- package/dist/config/env.js +73 -0
- package/dist/config/fields.d.ts +42 -0
- package/dist/config/fields.js +214 -0
- package/dist/config/file-source.d.ts +3 -0
- package/dist/config/file-source.js +31 -0
- package/dist/config/load.d.ts +20 -0
- package/dist/config/load.js +98 -0
- package/dist/config/nacos-source.d.ts +31 -0
- package/dist/config/nacos-source.js +229 -0
- package/dist/config/schema.d.ts +223 -0
- package/dist/config/schema.js +1151 -0
- package/dist/config/sources.d.ts +18 -0
- package/dist/config/sources.js +59 -0
- package/dist/config/types.d.ts +9 -0
- package/dist/config/types.js +7 -0
- package/dist/conversations/artifacts.d.ts +52 -0
- package/dist/conversations/artifacts.js +137 -0
- package/dist/conversations/attachments.controller.d.ts +28 -0
- package/dist/conversations/attachments.controller.js +96 -0
- package/dist/conversations/attachments.service.d.ts +180 -0
- package/dist/conversations/attachments.service.js +578 -0
- package/dist/conversations/conversations.controller.d.ts +288 -0
- package/dist/conversations/conversations.controller.js +607 -0
- package/dist/conversations/conversations.service.d.ts +321 -0
- package/dist/conversations/conversations.service.js +754 -0
- package/dist/conversations/event-log.d.ts +122 -0
- package/dist/conversations/event-log.js +259 -0
- package/dist/conversations/events.d.ts +856 -0
- package/dist/conversations/events.js +639 -0
- package/dist/conversations/files.d.ts +92 -0
- package/dist/conversations/files.js +213 -0
- package/dist/conversations/outputs-read.d.ts +34 -0
- package/dist/conversations/outputs-read.js +37 -0
- package/dist/conversations/queue.d.ts +169 -0
- package/dist/conversations/queue.js +527 -0
- package/dist/conversations/sandbox-status.d.ts +21 -0
- package/dist/conversations/sandbox-status.js +24 -0
- package/dist/conversations/selection.d.ts +46 -0
- package/dist/conversations/selection.js +75 -0
- package/dist/conversations/titles.d.ts +93 -0
- package/dist/conversations/titles.js +422 -0
- package/dist/ctx/bus.d.ts +16 -0
- package/dist/ctx/bus.js +101 -0
- package/dist/ctx/create-ctx.d.ts +109 -0
- package/dist/ctx/create-ctx.js +592 -0
- package/dist/ctx/kv.d.ts +4 -0
- package/dist/ctx/kv.js +31 -0
- package/dist/ctx/lock.d.ts +4 -0
- package/dist/ctx/lock.js +39 -0
- package/dist/ctx/namespace.d.ts +6 -0
- package/dist/ctx/namespace.js +12 -0
- package/dist/ctx/queue.d.ts +25 -0
- package/dist/ctx/queue.js +150 -0
- package/dist/ctx/secrets.d.ts +45 -0
- package/dist/ctx/secrets.js +175 -0
- package/dist/db/kernel-schema.d.ts +1122 -0
- package/dist/db/kernel-schema.js +5 -0
- package/dist/db/migrator.d.ts +28 -0
- package/dist/db/migrator.js +140 -0
- package/dist/db/pool.d.ts +21 -0
- package/dist/db/pool.js +28 -0
- package/dist/db/sql-statements.d.ts +34 -0
- package/dist/db/sql-statements.js +168 -0
- package/dist/errors.d.ts +210 -0
- package/dist/errors.js +212 -0
- package/dist/evals/budget.d.ts +61 -0
- package/dist/evals/budget.js +181 -0
- package/dist/evals/diff.d.ts +55 -0
- package/dist/evals/diff.js +133 -0
- package/dist/evals/judge.d.ts +53 -0
- package/dist/evals/judge.js +149 -0
- package/dist/evals/plan.d.ts +47 -0
- package/dist/evals/plan.js +77 -0
- package/dist/evals/reconstruct.d.ts +137 -0
- package/dist/evals/reconstruct.js +322 -0
- package/dist/evals/recorded-tools.d.ts +54 -0
- package/dist/evals/recorded-tools.js +167 -0
- package/dist/evals/run-replay.d.ts +86 -0
- package/dist/evals/run-replay.js +502 -0
- package/dist/evals/runs.controller.d.ts +100 -0
- package/dist/evals/runs.controller.js +199 -0
- package/dist/evals/runs.service.d.ts +275 -0
- package/dist/evals/runs.service.js +836 -0
- package/dist/evals/sets.controller.d.ts +61 -0
- package/dist/evals/sets.controller.js +183 -0
- package/dist/evals/sets.service.d.ts +128 -0
- package/dist/evals/sets.service.js +558 -0
- package/dist/evals/snapshot.d.ts +76 -0
- package/dist/evals/snapshot.js +207 -0
- package/dist/evals/step-replay.d.ts +113 -0
- package/dist/evals/step-replay.js +181 -0
- package/dist/evals/trajectory.controller.d.ts +41 -0
- package/dist/evals/trajectory.controller.js +88 -0
- package/dist/evals/trajectory.d.ts +144 -0
- package/dist/evals/trajectory.js +338 -0
- package/dist/evals/trajectory.service.d.ts +108 -0
- package/dist/evals/trajectory.service.js +323 -0
- package/dist/evals/worker.d.ts +101 -0
- package/dist/evals/worker.js +789 -0
- package/dist/extensions/admin-ops.d.ts +105 -0
- package/dist/extensions/admin-ops.js +353 -0
- package/dist/extensions/admin-view.d.ts +79 -0
- package/dist/extensions/admin-view.js +327 -0
- package/dist/extensions/approvals.d.ts +119 -0
- package/dist/extensions/approvals.js +205 -0
- package/dist/extensions/blobs.d.ts +45 -0
- package/dist/extensions/blobs.js +160 -0
- package/dist/extensions/bootstrap.d.ts +149 -0
- package/dist/extensions/bootstrap.js +441 -0
- package/dist/extensions/cli.d.ts +61 -0
- package/dist/extensions/cli.js +165 -0
- package/dist/extensions/config-json-schema.d.ts +9 -0
- package/dist/extensions/config-json-schema.js +73 -0
- package/dist/extensions/deployment-config.d.ts +138 -0
- package/dist/extensions/deployment-config.js +394 -0
- package/dist/extensions/enabled.d.ts +31 -0
- package/dist/extensions/enabled.js +55 -0
- package/dist/extensions/hooks.d.ts +161 -0
- package/dist/extensions/hooks.js +425 -0
- package/dist/extensions/host.d.ts +577 -0
- package/dist/extensions/host.js +2071 -0
- package/dist/extensions/inflight.d.ts +69 -0
- package/dist/extensions/inflight.js +277 -0
- package/dist/extensions/installs.d.ts +166 -0
- package/dist/extensions/installs.js +253 -0
- package/dist/extensions/instance.d.ts +167 -0
- package/dist/extensions/instance.js +329 -0
- package/dist/extensions/ledger.d.ts +30 -0
- package/dist/extensions/ledger.js +50 -0
- package/dist/extensions/lifecycle.d.ts +80 -0
- package/dist/extensions/lifecycle.js +152 -0
- package/dist/extensions/migrate-lock.d.ts +51 -0
- package/dist/extensions/migrate-lock.js +100 -0
- package/dist/extensions/org-config.controller.d.ts +24 -0
- package/dist/extensions/org-config.controller.js +59 -0
- package/dist/extensions/org-config.d.ts +169 -0
- package/dist/extensions/org-config.js +520 -0
- package/dist/extensions/package.d.ts +115 -0
- package/dist/extensions/package.js +246 -0
- package/dist/extensions/permission-set.d.ts +117 -0
- package/dist/extensions/permission-set.js +184 -0
- package/dist/extensions/permission-view.d.ts +194 -0
- package/dist/extensions/permission-view.js +284 -0
- package/dist/extensions/registry.d.ts +24 -0
- package/dist/extensions/registry.js +56 -0
- package/dist/extensions/resolve.d.ts +12 -0
- package/dist/extensions/resolve.js +71 -0
- package/dist/extensions/sources.d.ts +69 -0
- package/dist/extensions/sources.js +120 -0
- package/dist/extensions/sync.d.ts +40 -0
- package/dist/extensions/sync.js +242 -0
- package/dist/files/previewers.controller.d.ts +46 -0
- package/dist/files/previewers.controller.js +105 -0
- package/dist/files/previewers.d.ts +100 -0
- package/dist/files/previewers.js +250 -0
- package/dist/http/api.module.d.ts +114 -0
- package/dist/http/api.module.js +448 -0
- package/dist/http/app.d.ts +77 -0
- package/dist/http/app.js +170 -0
- package/dist/http/error.filter.d.ts +21 -0
- package/dist/http/error.filter.js +85 -0
- package/dist/http/gateway.module.d.ts +15 -0
- package/dist/http/gateway.module.js +13 -0
- package/dist/http/health.controller.d.ts +26 -0
- package/dist/http/health.controller.js +79 -0
- package/dist/http/nest-logger.d.ts +20 -0
- package/dist/http/nest-logger.js +28 -0
- package/dist/http/plugin-dispatch.d.ts +68 -0
- package/dist/http/plugin-dispatch.js +200 -0
- package/dist/http/tokens.d.ts +131 -0
- package/dist/http/tokens.js +131 -0
- package/dist/http/zod.pipe.d.ts +8 -0
- package/dist/http/zod.pipe.js +14 -0
- package/dist/identity/accounts.d.ts +93 -0
- package/dist/identity/accounts.js +367 -0
- package/dist/identity/api-tokens.d.ts +73 -0
- package/dist/identity/api-tokens.js +197 -0
- package/dist/identity/audit.d.ts +23 -0
- package/dist/identity/audit.js +41 -0
- package/dist/identity/auth.controller.d.ts +40 -0
- package/dist/identity/auth.controller.js +130 -0
- package/dist/identity/auth.guard.d.ts +41 -0
- package/dist/identity/auth.guard.js +162 -0
- package/dist/identity/binding.d.ts +47 -0
- package/dist/identity/binding.js +84 -0
- package/dist/identity/cookies.d.ts +16 -0
- package/dist/identity/cookies.js +32 -0
- package/dist/identity/credential-check.d.ts +17 -0
- package/dist/identity/credential-check.js +24 -0
- package/dist/identity/enterprise-admin.d.ts +14 -0
- package/dist/identity/enterprise-admin.js +27 -0
- package/dist/identity/external.d.ts +106 -0
- package/dist/identity/external.js +337 -0
- package/dist/identity/hash.d.ts +2 -0
- package/dist/identity/hash.js +3 -0
- package/dist/identity/login.d.ts +6 -0
- package/dist/identity/login.js +20 -0
- package/dist/identity/me.controller.d.ts +61 -0
- package/dist/identity/me.controller.js +159 -0
- package/dist/identity/passwords.d.ts +6 -0
- package/dist/identity/passwords.js +37 -0
- package/dist/identity/principal.d.ts +56 -0
- package/dist/identity/principal.js +38 -0
- package/dist/identity/rate-limit.d.ts +55 -0
- package/dist/identity/rate-limit.js +121 -0
- package/dist/identity/sessions.d.ts +84 -0
- package/dist/identity/sessions.js +306 -0
- package/dist/identity/settings.d.ts +121 -0
- package/dist/identity/settings.js +248 -0
- package/dist/identity/sso.controller.d.ts +59 -0
- package/dist/identity/sso.controller.js +192 -0
- package/dist/identity/sso.d.ts +83 -0
- package/dist/identity/sso.js +202 -0
- package/dist/inbox/inbox.service.d.ts +43 -0
- package/dist/inbox/inbox.service.js +57 -0
- package/dist/index.d.ts +67 -0
- package/dist/index.js +65 -0
- package/dist/kernel.d.ts +256 -0
- package/dist/kernel.js +1326 -0
- package/dist/log.d.ts +48 -0
- package/dist/log.js +229 -0
- package/dist/models/prices.d.ts +53 -0
- package/dist/models/prices.js +121 -0
- package/dist/models/purposes.controller.d.ts +19 -0
- package/dist/models/purposes.controller.js +56 -0
- package/dist/models/purposes.d.ts +140 -0
- package/dist/models/purposes.js +267 -0
- package/dist/net/proxy.d.ts +44 -0
- package/dist/net/proxy.js +162 -0
- package/dist/net/public-address.d.ts +60 -0
- package/dist/net/public-address.js +271 -0
- package/dist/net/safe-fetch.d.ts +38 -0
- package/dist/net/safe-fetch.js +140 -0
- package/dist/orgs/directory-sync.controller.d.ts +14 -0
- package/dist/orgs/directory-sync.controller.js +40 -0
- package/dist/orgs/directory-sync.d.ts +166 -0
- package/dist/orgs/directory-sync.js +558 -0
- package/dist/orgs/invitations.controller.d.ts +58 -0
- package/dist/orgs/invitations.controller.js +137 -0
- package/dist/orgs/invitations.service.d.ts +80 -0
- package/dist/orgs/invitations.service.js +217 -0
- package/dist/orgs/members.service.d.ts +63 -0
- package/dist/orgs/members.service.js +234 -0
- package/dist/orgs/offboarding.d.ts +141 -0
- package/dist/orgs/offboarding.js +398 -0
- package/dist/orgs/org-lock.d.ts +32 -0
- package/dist/orgs/org-lock.js +46 -0
- package/dist/orgs/org.guard.d.ts +35 -0
- package/dist/orgs/org.guard.js +95 -0
- package/dist/orgs/orgs.controller.d.ts +78 -0
- package/dist/orgs/orgs.controller.js +192 -0
- package/dist/orgs/orgs.service.d.ts +61 -0
- package/dist/orgs/orgs.service.js +209 -0
- package/dist/orgs/roles.d.ts +13 -0
- package/dist/orgs/roles.js +58 -0
- package/dist/orgs/settings.controller.d.ts +20 -0
- package/dist/orgs/settings.controller.js +53 -0
- package/dist/orgs/settings.service.d.ts +120 -0
- package/dist/orgs/settings.service.js +178 -0
- package/dist/packages/npm.d.ts +50 -0
- package/dist/packages/npm.js +218 -0
- package/dist/packages/provenance.d.ts +47 -0
- package/dist/packages/provenance.js +147 -0
- package/dist/packages/tgz.d.ts +76 -0
- package/dist/packages/tgz.js +225 -0
- package/dist/runtime/abort.d.ts +32 -0
- package/dist/runtime/abort.js +71 -0
- package/dist/runtime/checkpointer.d.ts +32 -0
- package/dist/runtime/checkpointer.js +243 -0
- package/dist/runtime/context/build.d.ts +254 -0
- package/dist/runtime/context/build.js +693 -0
- package/dist/runtime/context/claude-tools.d.ts +11 -0
- package/dist/runtime/context/claude-tools.js +24 -0
- package/dist/runtime/context/compaction.d.ts +26 -0
- package/dist/runtime/context/compaction.js +195 -0
- package/dist/runtime/context/pairing.d.ts +11 -0
- package/dist/runtime/context/pairing.js +82 -0
- package/dist/runtime/context/reminders.d.ts +5 -0
- package/dist/runtime/context/reminders.js +11 -0
- package/dist/runtime/context/skills.d.ts +105 -0
- package/dist/runtime/context/skills.js +283 -0
- package/dist/runtime/context/tokens.d.ts +19 -0
- package/dist/runtime/context/tokens.js +104 -0
- package/dist/runtime/conversation-lock.d.ts +40 -0
- package/dist/runtime/conversation-lock.js +97 -0
- package/dist/runtime/hook-calls.d.ts +84 -0
- package/dist/runtime/hook-calls.js +136 -0
- package/dist/runtime/langgraph-loop.d.ts +52 -0
- package/dist/runtime/langgraph-loop.js +247 -0
- package/dist/runtime/loop.d.ts +93 -0
- package/dist/runtime/loop.js +7 -0
- package/dist/runtime/maintenance.d.ts +80 -0
- package/dist/runtime/maintenance.js +147 -0
- package/dist/runtime/media-cache.d.ts +21 -0
- package/dist/runtime/media-cache.js +51 -0
- package/dist/runtime/model-call.d.ts +176 -0
- package/dist/runtime/model-call.js +1049 -0
- package/dist/runtime/providers.d.ts +86 -0
- package/dist/runtime/providers.js +224 -0
- package/dist/runtime/quota.d.ts +29 -0
- package/dist/runtime/quota.js +70 -0
- package/dist/runtime/run-finish.d.ts +45 -0
- package/dist/runtime/run-finish.js +69 -0
- package/dist/runtime/run-queue.d.ts +121 -0
- package/dist/runtime/run-queue.js +493 -0
- package/dist/runtime/run-worker.d.ts +138 -0
- package/dist/runtime/run-worker.js +805 -0
- package/dist/runtime/stream.controller.d.ts +34 -0
- package/dist/runtime/stream.controller.js +122 -0
- package/dist/runtime/stream.d.ts +63 -0
- package/dist/runtime/stream.js +262 -0
- package/dist/runtime/subagents/child.d.ts +80 -0
- package/dist/runtime/subagents/child.js +225 -0
- package/dist/runtime/subagents/definition.d.ts +103 -0
- package/dist/runtime/subagents/definition.js +392 -0
- package/dist/runtime/subagents/dispatch.d.ts +69 -0
- package/dist/runtime/subagents/dispatch.js +502 -0
- package/dist/runtime/subagents/limits.d.ts +23 -0
- package/dist/runtime/subagents/limits.js +34 -0
- package/dist/runtime/subagents/org-agents.d.ts +50 -0
- package/dist/runtime/subagents/org-agents.js +70 -0
- package/dist/runtime/subagents/preamble.d.ts +7 -0
- package/dist/runtime/subagents/preamble.js +11 -0
- package/dist/runtime/subagents/progress.d.ts +26 -0
- package/dist/runtime/subagents/progress.js +36 -0
- package/dist/runtime/subagents/roster.d.ts +55 -0
- package/dist/runtime/subagents/roster.js +111 -0
- package/dist/runtime/subagents/skill-fork.d.ts +123 -0
- package/dist/runtime/subagents/skill-fork.js +259 -0
- package/dist/runtime/usage-report.d.ts +163 -0
- package/dist/runtime/usage-report.js +550 -0
- package/dist/runtime/waits.d.ts +233 -0
- package/dist/runtime/waits.js +883 -0
- package/dist/sandbox/leases.d.ts +169 -0
- package/dist/sandbox/leases.js +515 -0
- package/dist/sandbox/lifecycle.d.ts +21 -0
- package/dist/sandbox/lifecycle.js +68 -0
- package/dist/sandbox/sandbox.service.d.ts +249 -0
- package/dist/sandbox/sandbox.service.js +908 -0
- package/dist/skills/catalog.d.ts +149 -0
- package/dist/skills/catalog.js +405 -0
- package/dist/skills/changes.controller.d.ts +56 -0
- package/dist/skills/changes.controller.js +136 -0
- package/dist/skills/changes.service.d.ts +175 -0
- package/dist/skills/changes.service.js +805 -0
- package/dist/skills/invocable.controller.d.ts +23 -0
- package/dist/skills/invocable.controller.js +50 -0
- package/dist/skills/invocation-keys.d.ts +23 -0
- package/dist/skills/invocation-keys.js +44 -0
- package/dist/skills/invoke.d.ts +135 -0
- package/dist/skills/invoke.js +286 -0
- package/dist/skills/package.d.ts +87 -0
- package/dist/skills/package.js +227 -0
- package/dist/skills/skills.controller.d.ts +40 -0
- package/dist/skills/skills.controller.js +110 -0
- package/dist/skills/skills.service.d.ts +192 -0
- package/dist/skills/skills.service.js +567 -0
- package/dist/storage/prefix.d.ts +36 -0
- package/dist/storage/prefix.js +104 -0
- package/dist/storage/purge.d.ts +27 -0
- package/dist/storage/purge.js +75 -0
- package/dist/storage/storage.service.d.ts +44 -0
- package/dist/storage/storage.service.js +145 -0
- package/dist/text.d.ts +13 -0
- package/dist/text.js +13 -0
- package/dist/tools/approvals.controller.d.ts +53 -0
- package/dist/tools/approvals.controller.js +128 -0
- package/dist/tools/approvals.service.d.ts +172 -0
- package/dist/tools/approvals.service.js +568 -0
- package/dist/tools/breaker.d.ts +28 -0
- package/dist/tools/breaker.js +72 -0
- package/dist/tools/builtins/agent.d.ts +81 -0
- package/dist/tools/builtins/agent.js +223 -0
- package/dist/tools/builtins/ask-user.d.ts +28 -0
- package/dist/tools/builtins/ask-user.js +139 -0
- package/dist/tools/builtins/read-tool-output.d.ts +18 -0
- package/dist/tools/builtins/read-tool-output.js +108 -0
- package/dist/tools/builtins/sandbox/bash.d.ts +16 -0
- package/dist/tools/builtins/sandbox/bash.js +137 -0
- package/dist/tools/builtins/sandbox/common.d.ts +114 -0
- package/dist/tools/builtins/sandbox/common.js +304 -0
- package/dist/tools/builtins/sandbox/deliver.d.ts +5 -0
- package/dist/tools/builtins/sandbox/deliver.js +180 -0
- package/dist/tools/builtins/sandbox/edit.d.ts +4 -0
- package/dist/tools/builtins/sandbox/edit.js +98 -0
- package/dist/tools/builtins/sandbox/glob-match.d.ts +25 -0
- package/dist/tools/builtins/sandbox/glob-match.js +240 -0
- package/dist/tools/builtins/sandbox/glob.d.ts +4 -0
- package/dist/tools/builtins/sandbox/glob.js +104 -0
- package/dist/tools/builtins/sandbox/grep.d.ts +9 -0
- package/dist/tools/builtins/sandbox/grep.js +133 -0
- package/dist/tools/builtins/sandbox/index.d.ts +12 -0
- package/dist/tools/builtins/sandbox/index.js +27 -0
- package/dist/tools/builtins/sandbox/names.d.ts +7 -0
- package/dist/tools/builtins/sandbox/names.js +20 -0
- package/dist/tools/builtins/sandbox/read.d.ts +8 -0
- package/dist/tools/builtins/sandbox/read.js +121 -0
- package/dist/tools/builtins/sandbox/write.d.ts +4 -0
- package/dist/tools/builtins/sandbox/write.js +88 -0
- package/dist/tools/builtins/skill-load.d.ts +53 -0
- package/dist/tools/builtins/skill-load.js +446 -0
- package/dist/tools/builtins/skill-write.d.ts +59 -0
- package/dist/tools/builtins/skill-write.js +244 -0
- package/dist/tools/builtins/tool-search.d.ts +31 -0
- package/dist/tools/builtins/tool-search.js +171 -0
- package/dist/tools/connector-content.controller.d.ts +34 -0
- package/dist/tools/connector-content.controller.js +78 -0
- package/dist/tools/connector-content.d.ts +104 -0
- package/dist/tools/connector-content.js +267 -0
- package/dist/tools/connectors.controller.d.ts +210 -0
- package/dist/tools/connectors.controller.js +234 -0
- package/dist/tools/connectors.service.d.ts +303 -0
- package/dist/tools/connectors.service.js +1102 -0
- package/dist/tools/credentials.d.ts +139 -0
- package/dist/tools/credentials.js +351 -0
- package/dist/tools/drift.d.ts +141 -0
- package/dist/tools/drift.js +539 -0
- package/dist/tools/elicitation.d.ts +81 -0
- package/dist/tools/elicitation.js +266 -0
- package/dist/tools/endpoint.d.ts +18 -0
- package/dist/tools/endpoint.js +115 -0
- package/dist/tools/info.d.ts +67 -0
- package/dist/tools/info.js +113 -0
- package/dist/tools/naming.d.ts +27 -0
- package/dist/tools/naming.js +47 -0
- package/dist/tools/oauth/discovery.d.ts +65 -0
- package/dist/tools/oauth/discovery.js +307 -0
- package/dist/tools/oauth/flow.d.ts +63 -0
- package/dist/tools/oauth/flow.js +237 -0
- package/dist/tools/oauth/oauth.controller.d.ts +31 -0
- package/dist/tools/oauth/oauth.controller.js +95 -0
- package/dist/tools/oauth/tokens.d.ts +111 -0
- package/dist/tools/oauth/tokens.js +258 -0
- package/dist/tools/outputs.d.ts +61 -0
- package/dist/tools/outputs.js +156 -0
- package/dist/tools/pipeline.d.ts +322 -0
- package/dist/tools/pipeline.js +1236 -0
- package/dist/tools/policy.d.ts +60 -0
- package/dist/tools/policy.js +236 -0
- package/dist/tools/questions.controller.d.ts +24 -0
- package/dist/tools/questions.controller.js +58 -0
- package/dist/tools/questions.service.d.ts +103 -0
- package/dist/tools/questions.service.js +295 -0
- package/dist/tools/redact.d.ts +20 -0
- package/dist/tools/redact.js +60 -0
- package/dist/tools/registry.d.ts +246 -0
- package/dist/tools/registry.js +481 -0
- package/dist/tools/resources.d.ts +16 -0
- package/dist/tools/resources.js +76 -0
- package/dist/tools/specs.d.ts +14 -0
- package/dist/tools/specs.js +31 -0
- package/dist/tools/validate.d.ts +20 -0
- package/dist/tools/validate.js +183 -0
- package/dist/tools/view.d.ts +43 -0
- package/dist/tools/view.js +225 -0
- package/dist/ui/embed-token.d.ts +31 -0
- package/dist/ui/embed-token.js +132 -0
- package/dist/ui/registry.d.ts +58 -0
- package/dist/ui/registry.js +90 -0
- package/dist/ui/ui-stream.d.ts +37 -0
- package/dist/ui/ui-stream.js +162 -0
- package/dist/ui/views.controller.d.ts +81 -0
- package/dist/ui/views.controller.js +261 -0
- package/dist/ui/views.d.ts +155 -0
- package/dist/ui/views.js +306 -0
- package/dist/version.d.ts +5 -0
- package/dist/version.js +6 -0
- package/package.json +67 -3
- package/src/migrations/0001_init.sql +8 -0
- package/src/migrations/0002_secrets.sql +8 -0
- package/src/migrations/0003_identity.sql +117 -0
- package/src/migrations/0004_plugin_org_config_nullable.sql +3 -0
- package/src/migrations/0005_agents.sql +27 -0
- package/src/migrations/0006_conversations.sql +37 -0
- package/src/migrations/0007_checkpoints.sql +26 -0
- package/src/migrations/0008_runs_trigger_seq.sql +3 -0
- package/src/migrations/0009_runs_active_unique.sql +4 -0
- package/src/migrations/0010_tools.sql +125 -0
- package/src/migrations/0011_approvals_spec.sql +10 -0
- package/src/migrations/0012_run_waits.sql +24 -0
- package/src/migrations/0013_app_tools_source.sql +4 -0
- package/src/migrations/0014_tool_specs.sql +8 -0
- package/src/migrations/0015_tool_drift.sql +20 -0
- package/src/migrations/0016_plugin_permissions.sql +11 -0
- package/src/migrations/0017_identity_sources.sql +6 -0
- package/src/migrations/0018_channels.sql +74 -0
- package/src/migrations/0019_identity_trust.sql +17 -0
- package/src/migrations/0020_channel_card_lookup.sql +10 -0
- package/src/migrations/0021_org_storage_purge.sql +9 -0
- package/src/migrations/0022_attachments.sql +29 -0
- package/src/migrations/0023_sandboxes.sql +37 -0
- package/src/migrations/0024_skills.sql +46 -0
- package/src/migrations/0025_skills_catalog_idx.sql +6 -0
- package/src/migrations/0026_skill_changes.sql +34 -0
- package/src/migrations/0027_model_prices.sql +18 -0
- package/src/migrations/0028_evals.sql +105 -0
- package/src/migrations/0029_model_purposes.sql +18 -0
- package/src/migrations/0030_plugin_installs.sql +73 -0
- package/src/migrations/0031_plugin_snapshot_source.sql +6 -0
- package/src/migrations/0032_plugin_deployment_configs.sql +10 -0
- package/src/migrations/0033_rename_apps_to_connectors.sql +25 -0
- package/src/migrations/0034_directory.sql +49 -0
- package/src/migrations/0035_catalogs.sql +40 -0
- package/src/migrations/0036_app_import_staging.sql +17 -0
- package/src/migrations/0037_directory_installs.sql +92 -0
- package/src/migrations/0038_channel_inbound_mode.sql +6 -0
- package/src/migrations/0039_channel_card_pending.sql +8 -0
- package/src/migrations/0040_usage_report_sweep.sql +10 -0
- package/src/migrations/0041_rename_plugins_to_extensions.sql +38 -0
- package/src/migrations/0042_rename_directory_to_catalog.sql +80 -0
- package/src/migrations/0043_rename_app_installs_to_plugin_installs.sql +20 -0
- package/src/migrations/0044_catalog_one_kind.sql +90 -0
- package/src/migrations/0045_plugin_dependencies.sql +9 -0
- package/src/migrations/0046_git_sources.sql +25 -0
- package/src/migrations/0047_marketplace_entry_heads.sql +7 -0
- package/src/migrations/0048_marketplace_entry_trees.sql +8 -0
- package/src/migrations/0049_plugin_upgrades.sql +37 -0
- package/src/migrations/0050_bootstrap.sql +53 -0
- package/src/migrations/0051_claude_compat.sql +26 -0
- package/src/migrations/0052_conversations_account_agent_idx.sql +5 -0
- package/src/migrations/0053_subagents.sql +73 -0
- package/src/migrations/0054_subagent_wait_expiry.sql +7 -0
- package/src/migrations/0055_subagent_parent_indexes.sql +10 -0
- package/src/migrations/0056_approval_reason.sql +3 -0
- package/src/migrations/0057_conversation_titles.sql +11 -0
- package/src/migrations/0058_conversation_selection.sql +4 -0
- package/src/migrations/0059_conversation_queue.sql +22 -0
- package/src/migrations/0060_file_previewers.sql +10 -0
- package/src/migrations/0061_queue_selection.sql +5 -0
- package/src/migrations/0062_queued_skill.sql +8 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { validateAnswer, } from "@capybara-hq/plugin-sdk";
|
|
3
|
+
import { sql } from "kysely";
|
|
4
|
+
import { ApiError } from "../errors.js";
|
|
5
|
+
const notFound = () => new ApiError("question.not_found", "Question not found");
|
|
6
|
+
const notInitiator = () => new ApiError("forbidden", "Only the user who started the run can answer this question");
|
|
7
|
+
const toView = ({ state: _state, ...rest }) => rest;
|
|
8
|
+
const iso = (v) => new Date(v).toISOString();
|
|
9
|
+
function toRecord(r) {
|
|
10
|
+
const spec = r.spec;
|
|
11
|
+
return {
|
|
12
|
+
id: r.id,
|
|
13
|
+
orgId: r.org_id,
|
|
14
|
+
conversationId: r.conversation_id,
|
|
15
|
+
runId: r.run_id,
|
|
16
|
+
callId: r.call_id,
|
|
17
|
+
attempt: r.attempt,
|
|
18
|
+
toolKey: spec.toolKey,
|
|
19
|
+
step: spec.step,
|
|
20
|
+
form: spec.form,
|
|
21
|
+
state: spec.state ?? null,
|
|
22
|
+
status: r.status,
|
|
23
|
+
answer: (r.answer ?? null),
|
|
24
|
+
answeredBy: r.answered_by,
|
|
25
|
+
answeredAt: r.answered_at === null ? null : iso(r.answered_at),
|
|
26
|
+
expiresAt: iso(r.expires_at),
|
|
27
|
+
createdAt: iso(r.created_at),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const isPlainObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
31
|
+
/**
|
|
32
|
+
* 输入请求:新建(tools 节点)、回答(只有对话发起人)、超时与取消(等待机制)。
|
|
33
|
+
* 状态全部在 PG:回答 / 超时 / 取消都在事务里 `SELECT … FOR UPDATE` 该行,多副本并发时恰好一个生效,
|
|
34
|
+
* 只有生效的那次写 `question_answered`。HTTP 接口见 questions.controller.ts。
|
|
35
|
+
*/
|
|
36
|
+
export class QuestionsService {
|
|
37
|
+
deps;
|
|
38
|
+
constructor(deps) {
|
|
39
|
+
this.deps = deps;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 新建 pending 输入请求(`expires_at` = 现在 + `tools.approvalTimeoutHours`)并写 `question_asked`,同一事务。
|
|
43
|
+
* 按 (run_id, call_id, attempt) 幂等:已存在则返回已有记录,事件按 `question_asked:<id>` 幂等。
|
|
44
|
+
*/
|
|
45
|
+
async ask(input) {
|
|
46
|
+
const { db, eventLog, config } = this.deps;
|
|
47
|
+
const hours = config().tools.approvalTimeoutHours;
|
|
48
|
+
const spec = {
|
|
49
|
+
form: input.form,
|
|
50
|
+
state: input.state ?? null,
|
|
51
|
+
toolKey: input.toolKey,
|
|
52
|
+
step: input.step,
|
|
53
|
+
};
|
|
54
|
+
const { record, toSeq } = await db.transaction().execute(async (t) => {
|
|
55
|
+
await t
|
|
56
|
+
.insertInto("questions")
|
|
57
|
+
.values({
|
|
58
|
+
id: randomUUID(),
|
|
59
|
+
org_id: input.orgId,
|
|
60
|
+
conversation_id: input.conversationId,
|
|
61
|
+
run_id: input.runId,
|
|
62
|
+
call_id: input.callId,
|
|
63
|
+
attempt: input.attempt,
|
|
64
|
+
spec: JSON.stringify(spec),
|
|
65
|
+
answer: null,
|
|
66
|
+
answered_by: null,
|
|
67
|
+
expires_at: sql `now() + ${hours}::integer * interval '1 hour'`,
|
|
68
|
+
})
|
|
69
|
+
.onConflict((oc) => oc.columns(["run_id", "call_id", "attempt"]).doNothing())
|
|
70
|
+
.execute();
|
|
71
|
+
const row = await t
|
|
72
|
+
.selectFrom("questions")
|
|
73
|
+
.selectAll()
|
|
74
|
+
.where("run_id", "=", input.runId)
|
|
75
|
+
.where("call_id", "=", input.callId)
|
|
76
|
+
.where("attempt", "=", input.attempt)
|
|
77
|
+
.executeTakeFirstOrThrow();
|
|
78
|
+
const rec = toRecord(row);
|
|
79
|
+
const written = await eventLog.append(rec.conversationId, [
|
|
80
|
+
{
|
|
81
|
+
type: "question_asked",
|
|
82
|
+
runId: rec.runId,
|
|
83
|
+
idemKey: `question_asked:${rec.id}`,
|
|
84
|
+
payload: {
|
|
85
|
+
step: rec.step,
|
|
86
|
+
callId: rec.callId,
|
|
87
|
+
questionId: rec.id,
|
|
88
|
+
form: rec.form,
|
|
89
|
+
expiresAt: rec.expiresAt,
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
], t);
|
|
93
|
+
return { record: rec, toSeq: Math.max(...written.map((e) => e.seq)) };
|
|
94
|
+
});
|
|
95
|
+
await eventLog.notify(record.conversationId, toSeq);
|
|
96
|
+
return record;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* 读一条输入请求(网页展示表单用):只有该运行的发起人(其他人 → 403 `forbidden`);
|
|
100
|
+
* 不属于该组织 / 不存在 → `question.not_found`。
|
|
101
|
+
*/
|
|
102
|
+
async get(orgId, questionId, accountId) {
|
|
103
|
+
const row = await this.deps.db
|
|
104
|
+
.selectFrom("questions")
|
|
105
|
+
.innerJoin("runs", "runs.id", "questions.run_id")
|
|
106
|
+
.selectAll("questions")
|
|
107
|
+
.select("runs.trigger_account_id")
|
|
108
|
+
.where("questions.id", "=", questionId)
|
|
109
|
+
.where("questions.org_id", "=", orgId)
|
|
110
|
+
.executeTakeFirst();
|
|
111
|
+
if (!row)
|
|
112
|
+
throw notFound();
|
|
113
|
+
if (row.trigger_account_id !== accountId)
|
|
114
|
+
throw notInitiator();
|
|
115
|
+
return toView(toRecord(row));
|
|
116
|
+
}
|
|
117
|
+
/** 某个调用的全部输入请求(按轮次升序)。 */
|
|
118
|
+
async forCall(runId, callId) {
|
|
119
|
+
const rows = await this.deps.db
|
|
120
|
+
.selectFrom("questions")
|
|
121
|
+
.selectAll()
|
|
122
|
+
.where("run_id", "=", runId)
|
|
123
|
+
.where("call_id", "=", callId)
|
|
124
|
+
.orderBy("attempt")
|
|
125
|
+
.execute();
|
|
126
|
+
return rows.map(toRecord);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* 回答:只有该运行的发起人(其他人 → 403 `forbidden`;传 `orgId` 时别的组织的输入请求 → `question.not_found`);非 pending 或已到期 →
|
|
130
|
+
* `question.already_answered`;答案不符合表单(`validateAnswer`)→ `validation_failed`。
|
|
131
|
+
* 同一事务写状态与 `question_answered`(幂等键 `question_answered:<id>`);提交后发布事件并调用 `onAnswered`(续跑)。
|
|
132
|
+
* 传 `orgId` 时还要求输入请求属于该组织(HTTP 接口用)。
|
|
133
|
+
*/
|
|
134
|
+
async answer(questionId, accountId, answer, orgId) {
|
|
135
|
+
const { db, eventLog } = this.deps;
|
|
136
|
+
const { record, toSeq } = await db.transaction().execute(async (t) => {
|
|
137
|
+
let q = t
|
|
138
|
+
.selectFrom("questions")
|
|
139
|
+
.selectAll()
|
|
140
|
+
.select(sql `expires_at <= now()`.as("expired"))
|
|
141
|
+
.where("id", "=", questionId);
|
|
142
|
+
if (orgId !== undefined)
|
|
143
|
+
q = q.where("org_id", "=", orgId);
|
|
144
|
+
const locked = await q.forUpdate().executeTakeFirst();
|
|
145
|
+
if (!locked)
|
|
146
|
+
throw notFound();
|
|
147
|
+
const run = await t
|
|
148
|
+
.selectFrom("runs")
|
|
149
|
+
.select("trigger_account_id")
|
|
150
|
+
.where("id", "=", locked.run_id)
|
|
151
|
+
.executeTakeFirst();
|
|
152
|
+
if (run?.trigger_account_id !== accountId)
|
|
153
|
+
throw notInitiator();
|
|
154
|
+
const before = toRecord(locked);
|
|
155
|
+
if (before.status !== "pending") {
|
|
156
|
+
throw new ApiError("question.already_answered", "Question has already been answered");
|
|
157
|
+
}
|
|
158
|
+
if (locked.expired) {
|
|
159
|
+
throw new ApiError("question.already_answered", "Question has expired");
|
|
160
|
+
}
|
|
161
|
+
const problems = isPlainObject(answer)
|
|
162
|
+
? validateAnswer(before.form, answer)
|
|
163
|
+
: ["answer must be an object"];
|
|
164
|
+
if (problems.length > 0) {
|
|
165
|
+
throw new ApiError("validation_failed", "Answer does not match the form", problems.map((message) => ({ path: "answer", message })));
|
|
166
|
+
}
|
|
167
|
+
const updated = await t
|
|
168
|
+
.updateTable("questions")
|
|
169
|
+
.set({
|
|
170
|
+
status: "answered",
|
|
171
|
+
answer: JSON.stringify(answer),
|
|
172
|
+
answered_by: accountId,
|
|
173
|
+
answered_at: sql `now()`,
|
|
174
|
+
})
|
|
175
|
+
.where("id", "=", questionId)
|
|
176
|
+
.returningAll()
|
|
177
|
+
.executeTakeFirstOrThrow();
|
|
178
|
+
const toSeq = await this.answeredEvent(t, before, answer, accountId, "answered");
|
|
179
|
+
return { record: toRecord(updated), toSeq };
|
|
180
|
+
});
|
|
181
|
+
await eventLog.notify(record.conversationId, toSeq);
|
|
182
|
+
if (this.deps.onAnswered) {
|
|
183
|
+
try {
|
|
184
|
+
await this.deps.onAnswered(record);
|
|
185
|
+
}
|
|
186
|
+
catch (err) {
|
|
187
|
+
this.deps.log.warn("question onAnswered hook failed", { questionId: record.id, err });
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return record;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* 超时(等待机制的超时任务调用):仍 pending 且已到期 → 置 expired、写 `question_answered{expired}`。
|
|
194
|
+
* 返回 `expired`(本次生效)/ `not_due`(尚未到期)/ `settled`(已回答、已取消或不存在)。
|
|
195
|
+
*/
|
|
196
|
+
async expire(questionId) {
|
|
197
|
+
const { db, eventLog } = this.deps;
|
|
198
|
+
const r = await db.transaction().execute(async (t) => {
|
|
199
|
+
const locked = await t
|
|
200
|
+
.selectFrom("questions")
|
|
201
|
+
.selectAll()
|
|
202
|
+
.select(sql `expires_at <= now()`.as("expired"))
|
|
203
|
+
.where("id", "=", questionId)
|
|
204
|
+
.forUpdate()
|
|
205
|
+
.executeTakeFirst();
|
|
206
|
+
if (!locked)
|
|
207
|
+
return { outcome: "settled" };
|
|
208
|
+
const before = toRecord(locked);
|
|
209
|
+
if (before.status !== "pending")
|
|
210
|
+
return { outcome: "settled", record: before };
|
|
211
|
+
if (!locked.expired)
|
|
212
|
+
return { outcome: "not_due", record: before };
|
|
213
|
+
const updated = await t
|
|
214
|
+
.updateTable("questions")
|
|
215
|
+
.set({ status: "expired", answered_at: sql `now()` })
|
|
216
|
+
.where("id", "=", questionId)
|
|
217
|
+
.returningAll()
|
|
218
|
+
.executeTakeFirstOrThrow();
|
|
219
|
+
const toSeq = await this.answeredEvent(t, before, null, null, "expired");
|
|
220
|
+
return { outcome: "expired", record: toRecord(updated), toSeq };
|
|
221
|
+
});
|
|
222
|
+
if ("toSeq" in r && r.toSeq !== undefined && r.record) {
|
|
223
|
+
await eventLog.notify(r.record.conversationId, r.toSeq);
|
|
224
|
+
}
|
|
225
|
+
return r.record ? { outcome: r.outcome, record: r.record } : { outcome: r.outcome };
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* 在事务 `t` 内取消运行的全部 pending 输入请求(运行在等待中被中止),各写 `question_answered{cancelled}`。
|
|
229
|
+
* 返回被取消的记录;调用方提交后发布事件。
|
|
230
|
+
*/
|
|
231
|
+
async cancelPendingIn(t, runId) {
|
|
232
|
+
const rows = await t
|
|
233
|
+
.selectFrom("questions")
|
|
234
|
+
.selectAll()
|
|
235
|
+
.where("run_id", "=", runId)
|
|
236
|
+
.where("status", "=", "pending")
|
|
237
|
+
.orderBy("created_at")
|
|
238
|
+
.forUpdate()
|
|
239
|
+
.execute();
|
|
240
|
+
const out = [];
|
|
241
|
+
for (const row of rows) {
|
|
242
|
+
const updated = await t
|
|
243
|
+
.updateTable("questions")
|
|
244
|
+
.set({ status: "cancelled", answered_at: sql `now()` })
|
|
245
|
+
.where("id", "=", row.id)
|
|
246
|
+
.returningAll()
|
|
247
|
+
.executeTakeFirstOrThrow();
|
|
248
|
+
const rec = toRecord(row);
|
|
249
|
+
await this.answeredEvent(t, rec, null, null, "cancelled");
|
|
250
|
+
out.push(toRecord(updated));
|
|
251
|
+
}
|
|
252
|
+
return out;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* 在事务 `t` 内取消某组织里由 `accountId` 发起的运行上的全部 pending 输入请求(只有运行发起人能回答,
|
|
256
|
+
* 即「其作为处理人」的提问;成员离职时调用),走与 {@link cancelPendingIn} 相同的取消路径:置 cancelled、
|
|
257
|
+
* 写 `question_answered{cancelled}`。返回被取消的记录与各会话写到的最大 seq;调用方提交后发布事件。
|
|
258
|
+
*/
|
|
259
|
+
async cancelPendingFor(t, orgId, accountId) {
|
|
260
|
+
const rows = await t
|
|
261
|
+
.selectFrom("questions")
|
|
262
|
+
.selectAll()
|
|
263
|
+
.where("org_id", "=", orgId)
|
|
264
|
+
.where("status", "=", "pending")
|
|
265
|
+
.where("run_id", "in", (eb) => eb.selectFrom("runs").select("id").where("trigger_account_id", "=", accountId))
|
|
266
|
+
.orderBy("created_at")
|
|
267
|
+
.forUpdate()
|
|
268
|
+
.execute();
|
|
269
|
+
const records = [];
|
|
270
|
+
const seqs = new Map();
|
|
271
|
+
for (const row of rows) {
|
|
272
|
+
const updated = await t
|
|
273
|
+
.updateTable("questions")
|
|
274
|
+
.set({ status: "cancelled", answered_at: sql `now()` })
|
|
275
|
+
.where("id", "=", row.id)
|
|
276
|
+
.returningAll()
|
|
277
|
+
.executeTakeFirstOrThrow();
|
|
278
|
+
const seq = await this.answeredEvent(t, toRecord(row), null, null, "cancelled");
|
|
279
|
+
seqs.set(row.conversation_id, Math.max(seqs.get(row.conversation_id) ?? 0, seq));
|
|
280
|
+
records.push(toRecord(updated));
|
|
281
|
+
}
|
|
282
|
+
return { records, seqs };
|
|
283
|
+
}
|
|
284
|
+
async answeredEvent(t, q, answer, byAccountId, outcome) {
|
|
285
|
+
const written = await this.deps.eventLog.append(q.conversationId, [
|
|
286
|
+
{
|
|
287
|
+
type: "question_answered",
|
|
288
|
+
runId: q.runId,
|
|
289
|
+
idemKey: `question_answered:${q.id}`,
|
|
290
|
+
payload: { questionId: q.id, callId: q.callId, answer, byAccountId, outcome },
|
|
291
|
+
},
|
|
292
|
+
], t);
|
|
293
|
+
return Math.max(...written.map((e) => e.seq));
|
|
294
|
+
}
|
|
295
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AuthInjection } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* 工具结果打码(Review Focus 3):远端服务可能把收到的凭据回显在结果或错误里,而工具结果会进事件日志、
|
|
4
|
+
* 工具输出存档并发给模型。管线在写入之前,用「本次调用实际注入的凭据」打码——值是精确已知的(不依赖进程内
|
|
5
|
+
* logger 的打码集合,多副本下同样成立),匹配器与 logger 共用(`createRedactor`)。
|
|
6
|
+
*
|
|
7
|
+
* 下限(Ruling A12):按调用打码只用这一次调用自己的凭据,不存在「租户用短值遮蔽别人」的问题,所以下限取
|
|
8
|
+
* {@link RESULT_REDACT_MIN} = 6(短 API key 也遮住);logger 的组织来源集合仍是 12(Ruling A2)。
|
|
9
|
+
*/
|
|
10
|
+
/** 按调用打码工具结果的最短值长度。 */
|
|
11
|
+
export declare const RESULT_REDACT_MIN = 6;
|
|
12
|
+
/**
|
|
13
|
+
* 一次注入里可能被回显的凭据值:头 / query 的值,`<scheme> <token>` 里的 token,Basic 解码后的串与密码,
|
|
14
|
+
* 以及它们的 `encodeURIComponent` 形式(query 参数、URL 里的回显是百分号编码的)。
|
|
15
|
+
*/
|
|
16
|
+
export declare function injectionSecrets(inj: AuthInjection): string[];
|
|
17
|
+
/** 递归替换值里所有字符串(对象键不动)。 */
|
|
18
|
+
export declare function redactDeep(value: unknown, redact: (s: string) => string): unknown;
|
|
19
|
+
/** 由若干次注入构造打码函数。 */
|
|
20
|
+
export declare function redactorFor(injections: readonly AuthInjection[]): (s: string) => string;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { createRedactor } from "../log.js";
|
|
2
|
+
/**
|
|
3
|
+
* 工具结果打码(Review Focus 3):远端服务可能把收到的凭据回显在结果或错误里,而工具结果会进事件日志、
|
|
4
|
+
* 工具输出存档并发给模型。管线在写入之前,用「本次调用实际注入的凭据」打码——值是精确已知的(不依赖进程内
|
|
5
|
+
* logger 的打码集合,多副本下同样成立),匹配器与 logger 共用(`createRedactor`)。
|
|
6
|
+
*
|
|
7
|
+
* 下限(Ruling A12):按调用打码只用这一次调用自己的凭据,不存在「租户用短值遮蔽别人」的问题,所以下限取
|
|
8
|
+
* {@link RESULT_REDACT_MIN} = 6(短 API key 也遮住);logger 的组织来源集合仍是 12(Ruling A2)。
|
|
9
|
+
*/
|
|
10
|
+
/** 按调用打码工具结果的最短值长度。 */
|
|
11
|
+
export const RESULT_REDACT_MIN = 6;
|
|
12
|
+
const SCHEME = /^(?:Bearer|Basic|Token)\s+(.+)$/i;
|
|
13
|
+
/**
|
|
14
|
+
* 一次注入里可能被回显的凭据值:头 / query 的值,`<scheme> <token>` 里的 token,Basic 解码后的串与密码,
|
|
15
|
+
* 以及它们的 `encodeURIComponent` 形式(query 参数、URL 里的回显是百分号编码的)。
|
|
16
|
+
*/
|
|
17
|
+
export function injectionSecrets(inj) {
|
|
18
|
+
const raw = rawSecrets(inj);
|
|
19
|
+
const out = new Set(raw);
|
|
20
|
+
for (const v of raw)
|
|
21
|
+
out.add(encodeURIComponent(v));
|
|
22
|
+
return [...out];
|
|
23
|
+
}
|
|
24
|
+
function rawSecrets(inj) {
|
|
25
|
+
const out = [];
|
|
26
|
+
for (const v of [...Object.values(inj.headers), ...Object.values(inj.query ?? {})]) {
|
|
27
|
+
out.push(v);
|
|
28
|
+
const m = SCHEME.exec(v);
|
|
29
|
+
if (!m)
|
|
30
|
+
continue;
|
|
31
|
+
const token = m[1];
|
|
32
|
+
out.push(token);
|
|
33
|
+
if (/^basic\s/i.test(v)) {
|
|
34
|
+
const decoded = Buffer.from(token, "base64").toString("utf8");
|
|
35
|
+
out.push(decoded);
|
|
36
|
+
const i = decoded.indexOf(":");
|
|
37
|
+
if (i >= 0)
|
|
38
|
+
out.push(decoded.slice(i + 1));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
/** 递归替换值里所有字符串(对象键不动)。 */
|
|
44
|
+
export function redactDeep(value, redact) {
|
|
45
|
+
if (typeof value === "string")
|
|
46
|
+
return redact(value);
|
|
47
|
+
if (Array.isArray(value))
|
|
48
|
+
return value.map((v) => redactDeep(v, redact));
|
|
49
|
+
if (typeof value === "object" && value !== null) {
|
|
50
|
+
const out = {};
|
|
51
|
+
for (const [k, v] of Object.entries(value))
|
|
52
|
+
out[k] = redactDeep(v, redact);
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
/** 由若干次注入构造打码函数。 */
|
|
58
|
+
export function redactorFor(injections) {
|
|
59
|
+
return createRedactor(injections.flatMap(injectionSecrets), RESULT_REDACT_MIN);
|
|
60
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import type { Connector, InputRequired, Logger, ToolAnnotations, ToolCallContext, ToolResult, ToolSpec } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import type { AgentDefinition } from "../agents/definition.js";
|
|
3
|
+
import type { KernelConfig } from "../config/schema.js";
|
|
4
|
+
import type { ToolView } from "../conversations/events.js";
|
|
5
|
+
import type { KernelDb } from "../db/kernel-schema.js";
|
|
6
|
+
import type { ExtensionHost } from "../extensions/host.js";
|
|
7
|
+
import type { OrgRole } from "../orgs/roles.js";
|
|
8
|
+
import type { Credentials } from "./credentials.js";
|
|
9
|
+
/**
|
|
10
|
+
* 内核内置工具的名字(Task 10 / Task 19 实现;M5 T8 加沙箱工具)。保存 agent 时内置工具引用按这份清单校验,
|
|
11
|
+
* 不依赖当前是否已注册,避免实现落地顺序影响已保存的定义;运行时未注册的照常报不可用。
|
|
12
|
+
* `skill_write`(M5 T15)由 agent 定义显式引用才可用(负责人决定 agent 能否改自己的技能)。
|
|
13
|
+
*/
|
|
14
|
+
export declare const BUILTIN_TOOL_NAMES: readonly ["ask_user", "read_tool_output", "tool_search", "skill_load", "skill_write", "sandbox_bash", "sandbox_read", "sandbox_write", "sandbox_edit", "sandbox_glob", "sandbox_grep", "sandbox_deliver", "agent"];
|
|
15
|
+
/** 保存 agent 时引用校验的问题(`path` 为 `tools.<i>`)。 */
|
|
16
|
+
export interface ToolRefIssue {
|
|
17
|
+
path: string;
|
|
18
|
+
message: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 内置工具处理函数的上下文:在 SDK 的 `ToolCallContext` 之上,管线额外传入本步解析出的工具
|
|
22
|
+
* (`tool_search` 据此搜索)。插件处理函数收到的仍是 `ToolCallContext`。
|
|
23
|
+
*/
|
|
24
|
+
export interface BuiltinCallContext extends ToolCallContext {
|
|
25
|
+
tools?: readonly ResolvedTool[];
|
|
26
|
+
/** 本次运行 id(内置工具写自己的事件时用,如沙箱 deliver 的 `artifact_created`)。 */
|
|
27
|
+
runId?: string;
|
|
28
|
+
/**
|
|
29
|
+
* 本次运行的截止时间(epoch 毫秒,`runtime.maxRunSeconds` 起算,Ruling M20)。到点运行被中止;
|
|
30
|
+
* 沙箱命令按它收紧超时,赶在截止前自己超时、给模型可执行的说明。
|
|
31
|
+
*/
|
|
32
|
+
runDeadline?: number;
|
|
33
|
+
/**
|
|
34
|
+
* The conversation whose sandbox this call uses (sub-agents spec §10.1): the parent conversation
|
|
35
|
+
* for a sub-agent's call, the conversation itself otherwise (the default when absent).
|
|
36
|
+
*/
|
|
37
|
+
sandboxConversationId?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 内置工具的结果:`ToolResult` 之外可带 `loadedTools`(`tool_search` 加载的工具 key,
|
|
41
|
+
* 管线写进 `tool_result.loadedTools`)。
|
|
42
|
+
*/
|
|
43
|
+
export type BuiltinResult = (ToolResult & {
|
|
44
|
+
loadedTools?: string[];
|
|
45
|
+
/**
|
|
46
|
+
* Structured display view (UI refresh B; the pipeline writes it to `tool_result.view` after
|
|
47
|
+
* checking it against `ToolViewSchema`). Builtins only: extension tools cannot set it.
|
|
48
|
+
*/
|
|
49
|
+
view?: ToolView;
|
|
50
|
+
}) | InputRequired;
|
|
51
|
+
/** 内置工具的处理函数(插件的 `ToolHandler` 可直接赋给它)。 */
|
|
52
|
+
export type BuiltinHandler = (input: unknown, ctx: BuiltinCallContext) => Promise<BuiltinResult>;
|
|
53
|
+
/** 内核内置工具(`ask_user` 等,Task 10 实现具体工具);key 就是 `spec.name`。 */
|
|
54
|
+
export interface BuiltinTool {
|
|
55
|
+
spec: ToolSpec;
|
|
56
|
+
defaultPolicy: "allow" | "ask";
|
|
57
|
+
run: BuiltinHandler;
|
|
58
|
+
/**
|
|
59
|
+
* 本次调用的执行时限(毫秒,按已校验的输入算);缺省为 `tools.timeoutMs`。沙箱 `bash` 按命令自己的超时加余量。
|
|
60
|
+
*/
|
|
61
|
+
timeoutMs?: (input: unknown) => number;
|
|
62
|
+
/** 结果转存阈值(字符):与 `tools.outputSpillChars` 取小者。缺省只用配置。 */
|
|
63
|
+
spillChars?: number;
|
|
64
|
+
/** 本部署当前不可用时返回事实原因(英文、可执行,进「工具不可用」提醒);可用返回 null。 */
|
|
65
|
+
unavailable?: () => string | null;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* agent 定义里对工具的引用(Task 6 在 `AgentDefinitionSchema` 中落地同形的 zod schema)。
|
|
69
|
+
* 连接器工具按连接器 id 引用,`tools: "all"` = 该连接器当前所有启用的工具。
|
|
70
|
+
*/
|
|
71
|
+
export type AgentToolRef = {
|
|
72
|
+
kind: "builtin";
|
|
73
|
+
name: string;
|
|
74
|
+
} | {
|
|
75
|
+
kind: "plugin";
|
|
76
|
+
plugin: string;
|
|
77
|
+
name: string;
|
|
78
|
+
} | {
|
|
79
|
+
kind: "connector";
|
|
80
|
+
connectorId: string;
|
|
81
|
+
tools: "all" | readonly string[];
|
|
82
|
+
};
|
|
83
|
+
export type ToolPolicy = "allow" | "ask" | "deny";
|
|
84
|
+
export interface ResolvedTool {
|
|
85
|
+
/** 模型可见名。 */
|
|
86
|
+
key: string;
|
|
87
|
+
source: {
|
|
88
|
+
kind: "builtin";
|
|
89
|
+
name: string;
|
|
90
|
+
} | {
|
|
91
|
+
kind: "plugin";
|
|
92
|
+
plugin: string;
|
|
93
|
+
name: string;
|
|
94
|
+
}
|
|
95
|
+
/** `resources`:内核补上的 list_resources / read_resource(见 resources.ts),执行时路由到会话的 resources 方法。 */
|
|
96
|
+
| {
|
|
97
|
+
kind: "connector";
|
|
98
|
+
connectorId: string;
|
|
99
|
+
name: string;
|
|
100
|
+
resources?: true;
|
|
101
|
+
};
|
|
102
|
+
/** 存储 / 注册时的定义(`name` 为来源内的原名,description 与 inputSchema 原样);模型可见名用 `key`。 */
|
|
103
|
+
spec: ToolSpec;
|
|
104
|
+
/** sha256(canonical spec) 前 16 位。 */
|
|
105
|
+
specHash: string;
|
|
106
|
+
defaultPolicy: ToolPolicy;
|
|
107
|
+
/** 内置工具的执行时限(见 {@link BuiltinTool.timeoutMs});缺省为 `tools.timeoutMs`。 */
|
|
108
|
+
timeoutMs?: (input: unknown) => number;
|
|
109
|
+
/** 内置工具的结果转存阈值(见 {@link BuiltinTool.spillChars})。 */
|
|
110
|
+
spillChars?: number;
|
|
111
|
+
/**
|
|
112
|
+
* 执行所需的最低组织角色(spec 3.6 R1)。发起人当前角色不足时转为按角色升级的审批
|
|
113
|
+
* (推给持有该角色的人)。M3 的内置与连接器工具都不设。
|
|
114
|
+
*/
|
|
115
|
+
requiredRole?: OrgRole;
|
|
116
|
+
}
|
|
117
|
+
/** 不可用的引用:`ref` 尽量写成模型认识的工具 key(`docs__search`、`docs__*`),否则 `app:<id>`。 */
|
|
118
|
+
export interface UnavailableTool {
|
|
119
|
+
ref: string;
|
|
120
|
+
reason: string;
|
|
121
|
+
}
|
|
122
|
+
/** 键排序、去掉 undefined 的 JSON(jsonb 不保留键顺序,指纹必须与顺序无关)。 */
|
|
123
|
+
export declare function canonicalJson(v: unknown): string;
|
|
124
|
+
/** The first 16 hex digits of sha256(canonicalJson(v)): a fingerprint independent of key order. */
|
|
125
|
+
export declare function contentHash(v: unknown): string;
|
|
126
|
+
/**
|
|
127
|
+
* `ToolSpec` fields that are display only (UI refresh B): never sent to the model and left out of
|
|
128
|
+
* the definition fingerprint, so adding or changing them never changes `model_call.request.tools`,
|
|
129
|
+
* never sends a connector tool to drift review and never invalidates a remembered grant.
|
|
130
|
+
*/
|
|
131
|
+
export declare const DISPLAY_ONLY_SPEC_FIELDS: readonly ["title", "keyArgs"];
|
|
132
|
+
/** A tool spec without its {@link DISPLAY_ONLY_SPEC_FIELDS} (non-objects unchanged). */
|
|
133
|
+
export declare function withoutDisplayFields<T>(spec: T): T;
|
|
134
|
+
/**
|
|
135
|
+
* Tool definition fingerprint: {@link contentHash} of the spec without its display-only fields
|
|
136
|
+
* (`title`, `keyArgs`). Specs without them hash exactly as before.
|
|
137
|
+
*/
|
|
138
|
+
export declare function specHash(spec: unknown): string;
|
|
139
|
+
/** 由注解推导默认策略:只读 → allow;其余(破坏性 / 无注解)→ ask。 */
|
|
140
|
+
export declare function policyFromAnnotations(a: ToolAnnotations | undefined): "allow" | "ask";
|
|
141
|
+
export interface ToolRegistryDeps {
|
|
142
|
+
db: KernelDb;
|
|
143
|
+
host: ExtensionHost;
|
|
144
|
+
credentials: Credentials;
|
|
145
|
+
log: Logger;
|
|
146
|
+
builtins: BuiltinTool[];
|
|
147
|
+
/**
|
|
148
|
+
* 当前配置(`tools.searchThreshold*`)。不提供时从不启用 `tool_search`(只用于不关心它的测试 / 调用方)。
|
|
149
|
+
*/
|
|
150
|
+
config?: () => KernelConfig;
|
|
151
|
+
}
|
|
152
|
+
/** `forAgent` 的结果。 */
|
|
153
|
+
export interface AgentTools {
|
|
154
|
+
tools: ResolvedTool[];
|
|
155
|
+
unavailable: UnavailableTool[];
|
|
156
|
+
/**
|
|
157
|
+
* `tools: "all"` 引用的连接器里未启用的工具(待复核 / 停用 / 已消失)及事实原因。不进 `unavailable`
|
|
158
|
+
* (那会让每步都写「工具不可用」提醒),只在模型点名调用时用来给事实说明(spec 6.3)。缺省视为空。
|
|
159
|
+
*/
|
|
160
|
+
hidden?: UnavailableTool[];
|
|
161
|
+
/**
|
|
162
|
+
* 本步是否启用 `tool_search`(spec 5.5):启用时 `tools` 末尾含 `tool_search`,构建请求时只放内置工具
|
|
163
|
+
* 与已加载工具的完整定义,其余进目录。缺省视为未启用。
|
|
164
|
+
*/
|
|
165
|
+
toolSearch?: boolean;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Tool registry: resolves the references in an agent definition into the tools available for this
|
|
169
|
+
* run. Not cached (reads PG and the host live every time), so changes take effect right away across
|
|
170
|
+
* replicas.
|
|
171
|
+
*
|
|
172
|
+
* Availability:
|
|
173
|
+
* - builtin: in `builtins`;
|
|
174
|
+
* - extension tools: the extension is loaded and registered the tool, and this org enabled the
|
|
175
|
+
* extension (`extension_org_configs.enabled`, spec 2.2 "installed at deployment level, enabled at
|
|
176
|
+
* org level"; required bootstrap plugins are enabled in every org, `enabled.ts`);
|
|
177
|
+
* - connector tools: the connector belongs to this org, is not deleted or disabled, the connector is
|
|
178
|
+
* installed, the tool status is `enabled` and the key is valid.
|
|
179
|
+
* `tools: "all"` takes only enabled tools; disabled / pending-review ones count as deliberately
|
|
180
|
+
* turned off by an admin and are not reported; named tools report their reason one by one.
|
|
181
|
+
* Only the first of a key is kept; the same source referenced twice is deduplicated silently,
|
|
182
|
+
* different sources with the same key report a duplicate.
|
|
183
|
+
*/
|
|
184
|
+
export declare class ToolRegistry {
|
|
185
|
+
private readonly deps;
|
|
186
|
+
constructor(deps: ToolRegistryDeps);
|
|
187
|
+
/** `host.list("connector")` 中 `kind` 匹配的第一个实现;未安装返回 undefined。 */
|
|
188
|
+
findConnector(kind: string): Connector | undefined;
|
|
189
|
+
/** 同 {@link findConnector},未安装时抛错。 */
|
|
190
|
+
connector(kind: string): Connector;
|
|
191
|
+
/**
|
|
192
|
+
* The handler of a builtin / extension tool (for the execution pipeline); connector tools run
|
|
193
|
+
* through the connector and return undefined. Also undefined when the extension was unloaded and so
|
|
194
|
+
* on. Extension tools resolve the current instance live and call through the instance's in-flight
|
|
195
|
+
* tracker (C17): on revocation it drains first and aborts at the limit, ending with
|
|
196
|
+
* `ExtensionUnloadedError` (the pipeline turns it into an English error result for the model).
|
|
197
|
+
*/
|
|
198
|
+
handler(source: ResolvedTool["source"]): BuiltinHandler | undefined;
|
|
199
|
+
/** The registered builtin tools' specs (display metadata for `tools/info.ts`). */
|
|
200
|
+
builtinSpecs(): ToolSpec[];
|
|
201
|
+
/** The loaded extensions' registered tool specs, with their extension's name. */
|
|
202
|
+
extensionToolSpecs(): {
|
|
203
|
+
plugin: string;
|
|
204
|
+
spec: ToolSpec;
|
|
205
|
+
}[];
|
|
206
|
+
/** 已安装连接器的 kind 列表(去重,按加载顺序)。 */
|
|
207
|
+
connectorKinds(): string[];
|
|
208
|
+
/**
|
|
209
|
+
* 保存 agent 时校验工具引用(只看「存在」,停用 / 待复核 / 插件未启用等运行时状态不拒绝,由 `forAgent` 报不可用):
|
|
210
|
+
* - 内置:名字在 {@link BUILTIN_TOOL_NAMES} 中;
|
|
211
|
+
* - 插件:插件已加载且注册了该工具,key 合法;
|
|
212
|
+
* - 连接器:连接器属于本组织且未删除;点名的工具必须在连接器的工具快照中。
|
|
213
|
+
* 不同来源拼出同一个 key 也报出来(不截断、不猜)。
|
|
214
|
+
* 返回 `keys`:这些引用可能产生的全部工具 key(`"all"` 含连接器当前所有工具,不论状态),供校验 `toolPolicies`。
|
|
215
|
+
*/
|
|
216
|
+
checkRefs(orgId: string, refs: readonly AgentToolRef[]): Promise<{
|
|
217
|
+
keys: Set<string>;
|
|
218
|
+
issues: ToolRefIssue[];
|
|
219
|
+
}>;
|
|
220
|
+
/**
|
|
221
|
+
* 解析 agent 引用的工具(见类注释),再判定是否启用 `tool_search`:组织设置 `toolSearch === "on"`,且
|
|
222
|
+
* 可用工具数 > `tools.searchThresholdTools` 或其定义的估算 token > `tools.searchThresholdTokens`。
|
|
223
|
+
* 启用时把内置 `tool_search` 追加到末尾。定义里显式引用的 `tool_search` 忽略(由这里按设置管理)。
|
|
224
|
+
* `skillLoad`:对话日志里有技能目录快照(`skills_catalog`,Ruling M17)→ 加入内置 `skill_load`(始终完整加载);
|
|
225
|
+
* 定义里显式引用的 `skill_load` 同样忽略。
|
|
226
|
+
*/
|
|
227
|
+
forAgent(orgId: string, def: {
|
|
228
|
+
tools: readonly AgentToolRef[];
|
|
229
|
+
skillLoad?: boolean;
|
|
230
|
+
/** The definition's sub-agent roster source: the `agent` tool's description lists it. */
|
|
231
|
+
subagents?: AgentDefinition["subagents"];
|
|
232
|
+
}): Promise<AgentTools>;
|
|
233
|
+
/** 是否启用 `tool_search`(见 {@link forAgent});先比阈值,超过才读组织设置。 */
|
|
234
|
+
private searchActive;
|
|
235
|
+
private resolve;
|
|
236
|
+
/**
|
|
237
|
+
* `subagents.maxConcurrentPerRun` with the organization's override, for the `agent` tool's
|
|
238
|
+
* description (§4.3). A change of the limit changes the tool's spec hash; replays read the
|
|
239
|
+
* definition logged by hash, so no drift reason is involved. Without config (some tests): the
|
|
240
|
+
* schema default.
|
|
241
|
+
*/
|
|
242
|
+
private maxConcurrentSubagents;
|
|
243
|
+
/** Plugins the organization enabled (built-in plugins always count as enabled, C14). */
|
|
244
|
+
private enabledPlugins;
|
|
245
|
+
private loadConnectors;
|
|
246
|
+
}
|