@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,156 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { ToolError } from "@capybara-hq/plugin-sdk";
|
|
3
|
+
import { sql } from "kysely";
|
|
4
|
+
/** 文本行数(按 `\n` 切分;空串算 1 行,与按行分页读取一致)。 */
|
|
5
|
+
export function countLines(s) {
|
|
6
|
+
let n = 1;
|
|
7
|
+
for (let i = s.indexOf("\n"); i !== -1; i = s.indexOf("\n", i + 1))
|
|
8
|
+
n++;
|
|
9
|
+
return n;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 输出存档(spec 5.4):超大工具结果的全文存进 `capybara.tool_outputs`,保留 `tools.outputRetentionDays` 天。
|
|
13
|
+
* 只能在产生它的会话里读取(同组织别的会话也不行:会话之间可见范围不同),过期即视为不存在(清理由维护任务负责)。
|
|
14
|
+
*/
|
|
15
|
+
export class ToolOutputs {
|
|
16
|
+
db;
|
|
17
|
+
config;
|
|
18
|
+
constructor(db, config) {
|
|
19
|
+
this.db = db;
|
|
20
|
+
this.config = config;
|
|
21
|
+
}
|
|
22
|
+
async save(a) {
|
|
23
|
+
const id = randomUUID();
|
|
24
|
+
const sizeChars = a.content.length;
|
|
25
|
+
const lineCount = countLines(a.content);
|
|
26
|
+
const days = this.config().tools.outputRetentionDays;
|
|
27
|
+
await this.db
|
|
28
|
+
.insertInto("tool_outputs")
|
|
29
|
+
.values({
|
|
30
|
+
id,
|
|
31
|
+
org_id: a.orgId,
|
|
32
|
+
conversation_id: a.conversationId,
|
|
33
|
+
call_id: a.callId,
|
|
34
|
+
size_chars: sizeChars,
|
|
35
|
+
line_count: lineCount,
|
|
36
|
+
content: a.content,
|
|
37
|
+
expires_at: sql `now() + make_interval(days => ${days})`,
|
|
38
|
+
})
|
|
39
|
+
.execute();
|
|
40
|
+
return { id, sizeChars, lineCount };
|
|
41
|
+
}
|
|
42
|
+
/** 读本会话未过期的存档全文;不存在 / 过期 / 属于别的会话或组织 → null。 */
|
|
43
|
+
async load(scope, id) {
|
|
44
|
+
const row = await this.db
|
|
45
|
+
.selectFrom("tool_outputs")
|
|
46
|
+
.select("content")
|
|
47
|
+
.where("id", "=", id)
|
|
48
|
+
.where("org_id", "=", scope.orgId)
|
|
49
|
+
.where("conversation_id", "=", scope.conversationId)
|
|
50
|
+
.where("expires_at", ">", sql `now()`)
|
|
51
|
+
.executeTakeFirst();
|
|
52
|
+
return row?.content ?? null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** 存档不存在 / 过期 / 不属于本会话(模型可见,英文;不区分几种情况,不泄露别处的存档是否存在)。 */
|
|
56
|
+
export const outputNotFoundText = (id) => `Output ${id} not found or expired. Run the tool that produced it again to get a new output id.`;
|
|
57
|
+
const isPlainObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
58
|
+
/**
|
|
59
|
+
* 管线第 1 阶段:把参数中任意位置的 `{"$output": "<id>"}`(对象恰好只有这一个键)替换为该存档全文。
|
|
60
|
+
* 不存在 / 过期 / 不属于本会话 → `ToolError`(给模型看的英文)。不修改传入的对象。
|
|
61
|
+
*/
|
|
62
|
+
export async function resolveOutputRefs(input, load) {
|
|
63
|
+
const cache = new Map();
|
|
64
|
+
const walk = async (v) => {
|
|
65
|
+
if (Array.isArray(v)) {
|
|
66
|
+
const out = [];
|
|
67
|
+
for (const x of v)
|
|
68
|
+
out.push(await walk(x));
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
if (!isPlainObject(v))
|
|
72
|
+
return v;
|
|
73
|
+
const keys = Object.keys(v);
|
|
74
|
+
if (keys.length === 1 && keys[0] === "$output") {
|
|
75
|
+
const id = v.$output;
|
|
76
|
+
if (typeof id !== "string") {
|
|
77
|
+
throw new ToolError('Invalid {"$output": ...} reference: the output id must be a string.');
|
|
78
|
+
}
|
|
79
|
+
let text = cache.get(id);
|
|
80
|
+
if (text === undefined) {
|
|
81
|
+
const loaded = await load(id);
|
|
82
|
+
if (loaded === null)
|
|
83
|
+
throw new ToolError(outputNotFoundText(id));
|
|
84
|
+
text = loaded;
|
|
85
|
+
cache.set(id, text);
|
|
86
|
+
}
|
|
87
|
+
return text;
|
|
88
|
+
}
|
|
89
|
+
const out = {};
|
|
90
|
+
for (const k of keys)
|
|
91
|
+
out[k] = await walk(v[k]);
|
|
92
|
+
return out;
|
|
93
|
+
};
|
|
94
|
+
return walk(input);
|
|
95
|
+
}
|
|
96
|
+
/** base64 数据解码后的字节数。 */
|
|
97
|
+
function base64Bytes(data) {
|
|
98
|
+
const s = data.replace(/\s/g, "");
|
|
99
|
+
const pad = s.endsWith("==") ? 2 : s.endsWith("=") ? 1 : 0;
|
|
100
|
+
return Math.max(0, Math.floor((s.length * 3) / 4) - pad);
|
|
101
|
+
}
|
|
102
|
+
/** 空结果的文本(模型可见,英文;部分供应商不接受空的 tool_result)。 */
|
|
103
|
+
const NO_OUTPUT = "(no output)";
|
|
104
|
+
/**
|
|
105
|
+
* 管线第 5 阶段(渲染):文本块按行拼接;图片 → `[image <mimeType>, <n> bytes]`(M3 不把图片回传模型);
|
|
106
|
+
* `resource_link` → `[resource <uri>]`;未知块 → `[unsupported content <type>]`。
|
|
107
|
+
* 畸形结果(不是对象、content 不是数组)给出说明并标为错误,不抛错(Review Focus 5)。
|
|
108
|
+
*/
|
|
109
|
+
export function renderResult(result) {
|
|
110
|
+
if (!isPlainObject(result) || !Array.isArray(result.content)) {
|
|
111
|
+
return {
|
|
112
|
+
text: "The tool returned a malformed result (expected an object with a content array).",
|
|
113
|
+
contentTypes: [],
|
|
114
|
+
isError: true,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
const parts = [];
|
|
118
|
+
const types = [];
|
|
119
|
+
for (const block of result.content) {
|
|
120
|
+
const b = isPlainObject(block) ? block : {};
|
|
121
|
+
const type = typeof b.type === "string" ? b.type : "unknown";
|
|
122
|
+
if (!types.includes(type))
|
|
123
|
+
types.push(type);
|
|
124
|
+
if (type === "text" && typeof b.text === "string")
|
|
125
|
+
parts.push(b.text);
|
|
126
|
+
else if (type === "image" && typeof b.data === "string") {
|
|
127
|
+
const mime = typeof b.mimeType === "string" ? b.mimeType : "unknown";
|
|
128
|
+
parts.push(`[image ${mime}, ${base64Bytes(b.data)} bytes]`);
|
|
129
|
+
}
|
|
130
|
+
else if (type === "resource_link" && typeof b.uri === "string") {
|
|
131
|
+
parts.push(`[resource ${b.uri}]`);
|
|
132
|
+
}
|
|
133
|
+
else
|
|
134
|
+
parts.push(`[unsupported content ${type}]`);
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
text: parts.length === 0 ? NO_OUTPUT : parts.join("\n"),
|
|
138
|
+
contentTypes: types,
|
|
139
|
+
isError: result.isError === true,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* 管线第 5 阶段(转存):超过 `spillChars` 的文本存为输出存档,模型只见前 `previewChars` 个字符与截断说明。
|
|
144
|
+
*/
|
|
145
|
+
export async function spillIfLarge(text, opts, save) {
|
|
146
|
+
if (text.length <= opts.spillChars)
|
|
147
|
+
return { content: text };
|
|
148
|
+
const saved = await save(text);
|
|
149
|
+
const id = saved.id;
|
|
150
|
+
return {
|
|
151
|
+
content: `${text.slice(0, opts.previewChars)}\n…\n` +
|
|
152
|
+
`[Output truncated: ${saved.sizeChars} chars, ${saved.lineCount} lines. Full output id: ${id}. ` +
|
|
153
|
+
`Use read_tool_output to page through it, or pass {"$output":"${id}"} as a tool argument.]`,
|
|
154
|
+
outputId: id,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { type FormAnswer, type InputForm, type Logger } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import type { Transaction } from "kysely";
|
|
3
|
+
import { type AgentDefinition } from "../agents/definition.js";
|
|
4
|
+
import type { KernelConfig } from "../config/schema.js";
|
|
5
|
+
import type { EventLog } from "../conversations/event-log.js";
|
|
6
|
+
import type { KernelDatabase, KernelDb } from "../db/kernel-schema.js";
|
|
7
|
+
import type { OrgRole } from "../orgs/roles.js";
|
|
8
|
+
import { type ConversationKindForHooks, type HookRunner } from "../runtime/hook-calls.js";
|
|
9
|
+
import { type SubagentParent, type WaitingFor } from "../runtime/loop.js";
|
|
10
|
+
import type { DispatchOutcome } from "../runtime/subagents/dispatch.js";
|
|
11
|
+
import type { ApprovalsService } from "./approvals.service.js";
|
|
12
|
+
import { type Breaker } from "./breaker.js";
|
|
13
|
+
import { type AgentToolInputT } from "./builtins/agent.js";
|
|
14
|
+
import { type Credentials } from "./credentials.js";
|
|
15
|
+
import { type ToolOutputs } from "./outputs.js";
|
|
16
|
+
import type { QuestionsService } from "./questions.service.js";
|
|
17
|
+
import type { ResolvedTool, ToolRegistry } from "./registry.js";
|
|
18
|
+
/** 审批被拒绝。 */
|
|
19
|
+
export declare const APPROVAL_DENIED_TEXT = "The user denied this tool call.";
|
|
20
|
+
/**
|
|
21
|
+
* The denied call's result when the approver gave a reason (model-visible, in the log). "An
|
|
22
|
+
* approver": under role escalation an admin, not the requester, decides. Older logs keep the text
|
|
23
|
+
* they recorded ("The user denied this tool call. Reason: …"); only new denials use this one.
|
|
24
|
+
*/
|
|
25
|
+
export declare const approvalDeniedText: (reason: string | null) => string;
|
|
26
|
+
/** 审批超时(按拒绝)。 */
|
|
27
|
+
export declare const approvalExpiredText: (hours: number) => string;
|
|
28
|
+
/** 等待审批期间 run 被中止。 */
|
|
29
|
+
export declare const APPROVAL_CANCELLED_TEXT = "The run was stopped while waiting for approval.";
|
|
30
|
+
/** 等待用户输入期间 run 被中止。 */
|
|
31
|
+
export declare const INPUT_CANCELLED_TEXT = "The run was stopped while waiting for user input.";
|
|
32
|
+
/** 同一调用连续请求输入超过上限。 */
|
|
33
|
+
export declare const TOO_MANY_INPUT_REQUESTS_TEXT = "Tool requested user input too many times.";
|
|
34
|
+
/** run 已被中止 / 到达截止时间,调用尚未开始执行。 */
|
|
35
|
+
export declare const RUN_STOPPED_TEXT = "The run was stopped before this tool call was executed.";
|
|
36
|
+
/** 调用执行中 run 被中止 / 到达截止时间。 */
|
|
37
|
+
export declare const RUN_STOPPED_DURING_TEXT = "The run was stopped while this tool call was running; its outcome is unknown. Verify before retrying.";
|
|
38
|
+
/**
|
|
39
|
+
* A plugin policy hook denied the call (model-visible). `reason` is the sanitized deny reason, or the
|
|
40
|
+
* generic sentence for a hook error / timeout; truncated to 500 characters.
|
|
41
|
+
*/
|
|
42
|
+
export declare const hookDeniedText: (plugin: string, reason: string) => string;
|
|
43
|
+
/** 需要人审批的请求(`ApprovalsService.request` 据此建审批记录)。 */
|
|
44
|
+
export interface AskRequest {
|
|
45
|
+
toolKey: string;
|
|
46
|
+
/** 所批准的工具定义指纹(「本会话 / 以后都允许」授权按它匹配)。 */
|
|
47
|
+
specHash: string;
|
|
48
|
+
/** 连接器工具的来源连接器;插件 / 内置工具为 null。 */
|
|
49
|
+
connectorId: string | null;
|
|
50
|
+
/** 指定处理人(发起人本人);按角色升级时为 null。 */
|
|
51
|
+
requestedFor: string | null;
|
|
52
|
+
/** 按角色升级(R1)时所需的角色;否则为 null。 */
|
|
53
|
+
approverRole: OrgRole | null;
|
|
54
|
+
/** Which rule asked (display only, written to `approval_requested.policy`). */
|
|
55
|
+
policy: ApprovalPolicySource;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Which rule made a call need approval: role escalation, the agent's tool policy, the connector's
|
|
59
|
+
* policy, a fixed ask (R3, `requiresUserInteraction`), the org's `sandboxToolPolicy`, or the tool's
|
|
60
|
+
* own default. `org` and `fixed` were added after the first B events (older logs say `default`).
|
|
61
|
+
*/
|
|
62
|
+
export type ApprovalPolicySource = "agent" | "connector" | "default" | "role" | "org" | "fixed";
|
|
63
|
+
/**
|
|
64
|
+
* `unavailable`:调用那一刻工具已不可用(连接器 / 工具不存在、停用、删除、待审核),值为事实原因;
|
|
65
|
+
* 管线写「工具不可用」说明,而不是「策略拒绝」。
|
|
66
|
+
*/
|
|
67
|
+
export type PolicyDecision = "allow" | "deny" | {
|
|
68
|
+
ask: AskRequest;
|
|
69
|
+
} | {
|
|
70
|
+
unavailable: string;
|
|
71
|
+
}
|
|
72
|
+
/** 记住的授权把 `ask` 放行(按 allow 执行,审计记授权种类)。 */
|
|
73
|
+
| {
|
|
74
|
+
grant: "session" | "always";
|
|
75
|
+
};
|
|
76
|
+
export interface PolicyContext {
|
|
77
|
+
orgId: string;
|
|
78
|
+
/** 对话发起人。 */
|
|
79
|
+
accountId: string;
|
|
80
|
+
agentId: string;
|
|
81
|
+
conversationId: string;
|
|
82
|
+
runId: string;
|
|
83
|
+
/**
|
|
84
|
+
* A sub-agent's call: its parent conversation, where "approve for this conversation" grants are
|
|
85
|
+
* looked up (sub-agents spec §9).
|
|
86
|
+
*/
|
|
87
|
+
parentConversationId?: string;
|
|
88
|
+
/**
|
|
89
|
+
* False when the sub-agent runs its parent conversation's agent (a template or general-purpose
|
|
90
|
+
* child): the parent agent's policies were already read as its own, so no second read. Unset:
|
|
91
|
+
* read and compare.
|
|
92
|
+
*/
|
|
93
|
+
parentAgentDiffers?: boolean;
|
|
94
|
+
}
|
|
95
|
+
/** 管线第 3 阶段:策略判定。 */
|
|
96
|
+
export type DecidePolicy = (tool: ResolvedTool, agentDef: AgentDefinition, ctx: PolicyContext) => Promise<PolicyDecision>;
|
|
97
|
+
/** 测试钩子。 */
|
|
98
|
+
export interface ToolPipelineHooks {
|
|
99
|
+
/** 工具执行返回之后、结果写入日志之前调用:抛错即模拟「工具已执行、结果未记录」时进程崩溃。 */
|
|
100
|
+
afterExecute?(runId: string, callId: string): Promise<void>;
|
|
101
|
+
}
|
|
102
|
+
export interface ToolPipelineDeps {
|
|
103
|
+
db: KernelDb;
|
|
104
|
+
eventLog: EventLog;
|
|
105
|
+
registry: Pick<ToolRegistry, "forAgent" | "findConnector" | "handler">;
|
|
106
|
+
credentials: Pick<Credentials, "injection" | "onUnauthorized">;
|
|
107
|
+
breaker: Pick<Breaker, "check" | "failure" | "success">;
|
|
108
|
+
outputs: Pick<ToolOutputs, "save" | "load">;
|
|
109
|
+
/** 策略为 `ask` 时建审批;续跑时读该调用的审批结果。 */
|
|
110
|
+
approvals: Pick<ApprovalsService, "request" | "forCall">;
|
|
111
|
+
/** 处理函数返回 `input_required` 时建输入请求;续跑时读该调用的各轮输入请求。 */
|
|
112
|
+
questions: Pick<QuestionsService, "ask" | "forCall">;
|
|
113
|
+
config: () => KernelConfig;
|
|
114
|
+
log: Logger;
|
|
115
|
+
/** 默认 {@link createDecidePolicy}(执行时实时读取策略与授权)。 */
|
|
116
|
+
decidePolicy?: DecidePolicy;
|
|
117
|
+
hooks?: ToolPipelineHooks;
|
|
118
|
+
/**
|
|
119
|
+
* Plugin hooks (`tool.preExecute` policy / observe after policy and approval, `tool.postExecute`
|
|
120
|
+
* observe after the result). Only the chat pipeline gets it; the eval replay uses
|
|
121
|
+
* `RecordedToolPipeline`, which never runs hooks. Also needs `conversationKind: "chat"` (P-18).
|
|
122
|
+
*/
|
|
123
|
+
pluginHooks?: HookRunner;
|
|
124
|
+
/**
|
|
125
|
+
* Ids of an extension's `inline` ui contributions (read live): a plugin tool's `ToolResult.card`
|
|
126
|
+
* must name one of them, otherwise it is dropped with a warning. Absent: cards are dropped.
|
|
127
|
+
*/
|
|
128
|
+
inlineViews?: (plugin: string) => ReadonlySet<string>;
|
|
129
|
+
/**
|
|
130
|
+
* 连接器在调用途中报告工具清单变了(MCP `notifications/tools/list_changed`):内核安排一次该连接器的漂移检查。
|
|
131
|
+
* 不等待、不抛错(实现自己吞掉错误)。
|
|
132
|
+
*/
|
|
133
|
+
onToolsChanged?: (orgId: string, connectorId: string) => void;
|
|
134
|
+
/**
|
|
135
|
+
* Dispatches the sub-agent of an `agent` call (sub-agents spec §7.1; `dispatchSubagent`). Without
|
|
136
|
+
* it, `agent` calls reach the builtin's guard, which refuses them.
|
|
137
|
+
*/
|
|
138
|
+
subagents?: {
|
|
139
|
+
dispatch(a: {
|
|
140
|
+
ctx: ToolStepContext;
|
|
141
|
+
callId: string;
|
|
142
|
+
input: AgentToolInputT;
|
|
143
|
+
}): Promise<DispatchOutcome>;
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/** tools 节点处理一步工具调用所需的上下文。 */
|
|
147
|
+
export interface ToolStepContext {
|
|
148
|
+
orgId: string;
|
|
149
|
+
conversationId: string;
|
|
150
|
+
runId: string;
|
|
151
|
+
step: number;
|
|
152
|
+
agentId: string;
|
|
153
|
+
/** 运行所用的 agent 版本(审计链记录)。 */
|
|
154
|
+
agentVersion: number;
|
|
155
|
+
agent: AgentDefinition;
|
|
156
|
+
/** 对话发起人(取个人凭据、审计 actor)。 */
|
|
157
|
+
accountId: string;
|
|
158
|
+
/** run 的中止信号(用户中止 / 截止时间)。 */
|
|
159
|
+
signal: AbortSignal;
|
|
160
|
+
/** run 的截止时间(epoch 毫秒);传给内置工具(沙箱命令据此收紧超时,Ruling M20)。 */
|
|
161
|
+
deadline?: number;
|
|
162
|
+
/** Hooks fire only for `chat` conversations. */
|
|
163
|
+
conversationKind?: ConversationKindForHooks;
|
|
164
|
+
/**
|
|
165
|
+
* Set when the run is a sub-agent's: its builtin tools use the parent conversation's sandbox
|
|
166
|
+
* (spec §10.1) and it cannot dispatch sub-agents.
|
|
167
|
+
*/
|
|
168
|
+
parent?: SubagentParent;
|
|
169
|
+
}
|
|
170
|
+
/** tools 节点一步的结果:全部调用都有了结果,或某个调用需要等人处理(之后的调用留到续跑)。 */
|
|
171
|
+
export type ToolStepOutcome = {
|
|
172
|
+
kind: "done";
|
|
173
|
+
} | {
|
|
174
|
+
kind: "suspended";
|
|
175
|
+
waitingFor: WaitingFor;
|
|
176
|
+
};
|
|
177
|
+
/** 续跑时带给处理函数的上一轮输入请求结果(`ctx.resume`)。 */
|
|
178
|
+
export type ToolResume = {
|
|
179
|
+
state: unknown;
|
|
180
|
+
answer: FormAnswer | null;
|
|
181
|
+
};
|
|
182
|
+
/** 执行阶段的结果。 */
|
|
183
|
+
export type ExecOutcome =
|
|
184
|
+
/** 工具返回了结果(可能是工具自己报告的错误,或畸形结果,由渲染阶段处理)。 */
|
|
185
|
+
{
|
|
186
|
+
kind: "result";
|
|
187
|
+
result: unknown;
|
|
188
|
+
}
|
|
189
|
+
/** 处理函数需要用户输入(表单尚未校验)。 */
|
|
190
|
+
| {
|
|
191
|
+
kind: "input_required";
|
|
192
|
+
form: InputForm;
|
|
193
|
+
state: unknown;
|
|
194
|
+
}
|
|
195
|
+
/** 执行失败(超时、抛错、熔断、中止等),message 给模型看。 */
|
|
196
|
+
| {
|
|
197
|
+
kind: "error";
|
|
198
|
+
message: string;
|
|
199
|
+
}
|
|
200
|
+
/** 发起人未连接个人凭据:除错误结果外再写 `connection_required`。 */
|
|
201
|
+
| {
|
|
202
|
+
kind: "connection_required";
|
|
203
|
+
connectorId: string;
|
|
204
|
+
connectorName: string;
|
|
205
|
+
message: string;
|
|
206
|
+
};
|
|
207
|
+
type KernelTrx = Transaction<KernelDatabase>;
|
|
208
|
+
/**
|
|
209
|
+
* The wait of a step whose sub-agents still run (spec §7.2): id `sa-<runId>-<step>`, expiring after
|
|
210
|
+
* the approval timeout plus one run's duration plus 10 minutes (a child may itself wait for an
|
|
211
|
+
* approval); the timeout is a safety net.
|
|
212
|
+
*/
|
|
213
|
+
export declare function subagentsWait(runId: string, step: number, config: Pick<KernelConfig, "tools" | "runtime">, now?: number): WaitingFor;
|
|
214
|
+
/**
|
|
215
|
+
* 工具执行管线(spec 5.4 / 6.2):每个阶段是独立函数——
|
|
216
|
+
* `resolveOutputRefs` → `validateInput` → `decidePolicy` → `execute`(超时、熔断)→ `renderResult` / `spillIfLarge`
|
|
217
|
+
* → 写 `tool_result` 与审计。
|
|
218
|
+
*
|
|
219
|
+
* 有副作用不盲目重跑(spec 4.3):执行前写 `tool_call_started`;续跑时「有开始无结果」的调用记为结果未知,不再执行。
|
|
220
|
+
*/
|
|
221
|
+
export declare class ToolPipeline {
|
|
222
|
+
private readonly deps;
|
|
223
|
+
private readonly decide;
|
|
224
|
+
constructor(deps: ToolPipelineDeps);
|
|
225
|
+
/**
|
|
226
|
+
* tools 节点:按顺序处理本步 assistant 消息里的全部 `tool_call`,每个调用都以一条 `tool_result` 结束
|
|
227
|
+
* (之后才回到 prepare 构建下一次请求,保持「已记录调用、未记录结果之间不构建请求」的不变式)。
|
|
228
|
+
* 已有结果 → 跳过;有开始无结果 → 结果未知;run 已中止 → 不执行。
|
|
229
|
+
* 某个调用需要等人处理(审批 / 用户输入)→ 返回 `suspended`,之后的调用留到续跑时处理;
|
|
230
|
+
* 续跑时重新进入本函数,按 PG 里的审批 / 输入请求结果继续。
|
|
231
|
+
*/
|
|
232
|
+
runStep(ctx: ToolStepContext): Promise<ToolStepOutcome>;
|
|
233
|
+
/**
|
|
234
|
+
* An `agent` call that was dispatched (spec §7.1 "already dispatched"): when its child run is
|
|
235
|
+
* terminal, writes the parent's `subagent_finished` (if the child's finisher did not) and the
|
|
236
|
+
* call's `tool_result` from the child's log, and returns true; else false (still open).
|
|
237
|
+
*
|
|
238
|
+
* The call ran like any tool, so the result is audited `tool.called` (duration = the child's;
|
|
239
|
+
* the authorization is known only when an approval let it run: a policy or remembered grant at
|
|
240
|
+
* dispatch time is not recorded, so nothing is guessed) and fires `tool.postExecute` with the
|
|
241
|
+
* result, from the replica that writes it (spec §11).
|
|
242
|
+
*/
|
|
243
|
+
private finishAgentCall;
|
|
244
|
+
/**
|
|
245
|
+
* Writes, in `t`, the `tool_result` of every open `agent` call of a run that is being stopped
|
|
246
|
+
* (sub-agents spec §12: a person stopped it while it waited on sub-agents, or its deadline or a
|
|
247
|
+
* stop hit its tools node after a dispatch). A call whose child already ended gets the child's
|
|
248
|
+
* result (and the missing `subagent_finished`); one whose child is still active gets
|
|
249
|
+
* {@link AGENT_STOPPED_WITH_RUN_TEXT}. The caller stops those children after its commit.
|
|
250
|
+
*
|
|
251
|
+
* Like every `agent` result (see {@link finishAgentCall}), each is audited `tool.called` in `t`
|
|
252
|
+
* (duration: the child's, or the time since the dispatch) and fires `tool.postExecute`, through
|
|
253
|
+
* `fire()`, which the caller runs after its commit. Returns the steps and calls written (the
|
|
254
|
+
* caller must not write a "not executed" result for them) and the highest seq written.
|
|
255
|
+
*/
|
|
256
|
+
stopOpenAgentCalls(t: KernelTrx, runId: string, agent?: AgentDefinition): Promise<{
|
|
257
|
+
steps: number[];
|
|
258
|
+
callIds: Set<string>;
|
|
259
|
+
toSeq: number | null;
|
|
260
|
+
fire: () => void;
|
|
261
|
+
}>;
|
|
262
|
+
/**
|
|
263
|
+
* 处理一个尚无结果的调用。先看输入请求的轮次:最近一轮仍 pending → 继续等;否则本次是第
|
|
264
|
+
* `已有轮数 + 1` 次调用,已有轮次时带 `ctx.resume`(answered → 答案,expired / cancelled → null)。
|
|
265
|
+
* 本次调用「有开始无结果」→ 结果未知(spec 4.3)。返回需要等待的对象,或 undefined(已写结果)。
|
|
266
|
+
*/
|
|
267
|
+
private processCall;
|
|
268
|
+
private runCall;
|
|
269
|
+
/**
|
|
270
|
+
* 发出本步调用的请求里带了完整定义的工具 key:本步最后一次尝试的 `model_call.request.tools`
|
|
271
|
+
* (`assistant_message` 来自最后一次尝试)。该请求不在 tool_search 模式(没有 `catalog`,工具全部发送)
|
|
272
|
+
* 或找不到 model_call 时返回 null(不做加载检查)。已加载集合由此从日志得出,不放进程内存。
|
|
273
|
+
*/
|
|
274
|
+
private sentTools;
|
|
275
|
+
/** 审批的非批准结果 → 给模型的说明;仍 pending → null(继续等待)。 */
|
|
276
|
+
private refusalText;
|
|
277
|
+
/**
|
|
278
|
+
* 处理函数返回 `input_required`:超过轮次上限、表单不合规(`validateInputForm`)或 state 过大 → 返回给模型的错误说明;
|
|
279
|
+
* 否则建输入请求(写 `question_asked`)并返回等待对象。
|
|
280
|
+
*/
|
|
281
|
+
private askInput;
|
|
282
|
+
/**
|
|
283
|
+
* 管线第 4 阶段:执行。内置 / 插件工具直接调用处理函数,连接器工具经连接器(每次调用打开并关闭会话)。
|
|
284
|
+
* 带 `tools.timeoutMs` 超时与 run 的中止信号(合并后传给处理函数 / 连接器,不响应信号的也按时结束)。
|
|
285
|
+
* 熔断只作用于连接器工具(键为组织 × 连接器)。
|
|
286
|
+
*/
|
|
287
|
+
execute(tool: ResolvedTool, input: unknown, ctx: ToolStepContext, callId: string, resume?: ToolResume, stepTools?: readonly ResolvedTool[]): Promise<ExecOutcome>;
|
|
288
|
+
private executeConnector;
|
|
289
|
+
/** 抛出的错误 → 给模型的结果:ToolError 的消息原样(插件约定为英文、可操作),其他只给错误类名。 */
|
|
290
|
+
private thrown;
|
|
291
|
+
/**
|
|
292
|
+
* 带超时与中止执行 work:合并 run 信号与超时信号传给 work,并与之竞速(work 不响应信号也按时返回)。
|
|
293
|
+
* 返回 `{ value }`,或 `"timeout"` / `"aborted"`;work 自己的错误照常抛出。
|
|
294
|
+
*/
|
|
295
|
+
private bounded;
|
|
296
|
+
/** 关闭会话(打开仍在进行时等它完成后关闭),最多等 {@link CLOSE_WAIT_MS};失败只记日志。 */
|
|
297
|
+
private closeSession;
|
|
298
|
+
/**
|
|
299
|
+
* 工具结果里的显示摘要(`ToolResult.display`):合法时只取 `{ summary: { zh, en } }`,没有给返回 undefined,
|
|
300
|
+
* 不合法时记告警并丢弃(结果照常写入)。摘要只进事件日志给界面看,不进模型请求。
|
|
301
|
+
*/
|
|
302
|
+
private displayOf;
|
|
303
|
+
/**
|
|
304
|
+
* A plugin tool's inline card (`ToolResult.card` → `tool_result.card`, display only): `view` must
|
|
305
|
+
* be an `inline` ui contribution of the same extension and `key` at most 200 characters; anything
|
|
306
|
+
* else is dropped with a warning and the result is written as usual.
|
|
307
|
+
*/
|
|
308
|
+
private cardOf;
|
|
309
|
+
/**
|
|
310
|
+
* A builtin's structured view (`tool_result.view`, display only): checked against
|
|
311
|
+
* {@link ToolViewSchema}; an invalid one is dropped with a warning and the result is written as usual.
|
|
312
|
+
*/
|
|
313
|
+
private viewOf;
|
|
314
|
+
/**
|
|
315
|
+
* 管线第 6 阶段:写 `tool_result`(与 `connection_required` 同批)。传入 `callAudit`(即工具实际执行过;
|
|
316
|
+
* 耗时 null = 执行过但耗时未知,如续跑时「有开始无结果」的调用)时在同一事务里写审计 `tool.called`。
|
|
317
|
+
* 审计链(R6):actor = 发起人 → agent(id + 版本)→ 会话 / 运行 / 调用 / 工具(连接器工具带 connectorId)→
|
|
318
|
+
* 放行依据(审批人 / 授权 / 策略)。不含参数、结果与凭据。
|
|
319
|
+
*/
|
|
320
|
+
private writeResult;
|
|
321
|
+
}
|
|
322
|
+
export {};
|