@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,147 @@
|
|
|
1
|
+
import { Queue, Worker } from "bullmq";
|
|
2
|
+
import { sql } from "kysely";
|
|
3
|
+
import { bullConnection } from "./run-queue.js";
|
|
4
|
+
/**
|
|
5
|
+
* 内核维护队列(不含 `:`):等待超时任务(`wait-timeout`,见 waits.ts)与周期性维护(输出存档清理、
|
|
6
|
+
* 工具漂移检测(见 tools/drift.ts)、等待兜底扫描(`wait-sweep`,见 waits.ts)、沙箱的空闲休眠与不活跃销毁
|
|
7
|
+
* (见 sandbox/lifecycle.ts)等)。整个队列只有一个 Worker(只在 `worker` 角色上启动),
|
|
8
|
+
* 按任务名分派给登记的处理函数。
|
|
9
|
+
* 与运行队列分开:运行 worker 的处理函数、stalled / 失败处理都按「一个任务 = 一次运行」设计;
|
|
10
|
+
* 维护任务短、无会话锁与配额。
|
|
11
|
+
*/
|
|
12
|
+
export const MAINTENANCE_QUEUE_NAME = "cap-kernel-maintenance";
|
|
13
|
+
/** 输出存档清理:任务名、job scheduler id(不含 `:`)、周期与每批删除行数。 */
|
|
14
|
+
export const OUTPUT_CLEANUP_JOB = "output-cleanup";
|
|
15
|
+
export const OUTPUT_CLEANUP_SCHEDULER_ID = "output-cleanup-hourly";
|
|
16
|
+
export const OUTPUT_CLEANUP_EVERY_MS = 3_600_000;
|
|
17
|
+
export const OUTPUT_CLEANUP_BATCH = 1000;
|
|
18
|
+
/**
|
|
19
|
+
* Periodic marketplace refresh (C26): job name and job scheduler id (no `:`), every
|
|
20
|
+
* `marketplaces.refreshIntervalMinutes`. One scheduler for all replicas; the handler refreshes each
|
|
21
|
+
* enabled marketplace in turn (see catalog/marketplaces.service.ts). The values keep their old
|
|
22
|
+
* names: the scheduler id is stored in Redis, and renaming it would leave the old scheduler behind.
|
|
23
|
+
*/
|
|
24
|
+
export const MARKETPLACES_REFRESH_JOB = "catalogs-refresh";
|
|
25
|
+
export const MARKETPLACES_REFRESH_SCHEDULER_ID = "catalogs-refresh-every";
|
|
26
|
+
/**
|
|
27
|
+
* Cleanup of plugin (app bundle) import staging (T25, F-AE): job name and job scheduler id (no
|
|
28
|
+
* `:`), hourly; deletes expired (24-hour) staging rows and their object storage prefixes (see
|
|
29
|
+
* catalog/plugin-import.ts `PluginImport.cleanupExpired`). The values keep their old names: the
|
|
30
|
+
* scheduler id is stored in Redis, so renaming it would leave the old scheduler behind.
|
|
31
|
+
*/
|
|
32
|
+
export const PLUGIN_STAGING_CLEANUP_JOB = "app-staging-cleanup";
|
|
33
|
+
export const PLUGIN_STAGING_CLEANUP_SCHEDULER_ID = "app-staging-cleanup-hourly";
|
|
34
|
+
export const PLUGIN_STAGING_CLEANUP_EVERY_MS = 3_600_000;
|
|
35
|
+
/**
|
|
36
|
+
* 删除已过期(`expires_at < now()`)的输出存档,每批 `batch` 行,直到删完;返回删除的总行数。
|
|
37
|
+
* 每批一条独立语句(不开长事务);多个 worker 同时清理时 `SKIP LOCKED` 互不等待。
|
|
38
|
+
*/
|
|
39
|
+
export async function deleteExpiredOutputs(db, batch = OUTPUT_CLEANUP_BATCH) {
|
|
40
|
+
let total = 0;
|
|
41
|
+
for (;;) {
|
|
42
|
+
const r = await db
|
|
43
|
+
.deleteFrom("tool_outputs")
|
|
44
|
+
.where("id", "in", db
|
|
45
|
+
.selectFrom("tool_outputs")
|
|
46
|
+
.select("id")
|
|
47
|
+
.where("expires_at", "<", sql `now()`)
|
|
48
|
+
.limit(batch)
|
|
49
|
+
.forUpdate()
|
|
50
|
+
.skipLocked())
|
|
51
|
+
.executeTakeFirst();
|
|
52
|
+
const n = Number(r.numDeletedRows);
|
|
53
|
+
total += n;
|
|
54
|
+
if (n < batch)
|
|
55
|
+
return total;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 维护队列的生产方与(worker 角色上的)唯一 Worker。状态都在 Redis / PG,没有进程内定时器:
|
|
60
|
+
* 周期任务用 BullMQ job scheduler(`upsertJobScheduler` 幂等,多副本重复调用只有一个 scheduler)。
|
|
61
|
+
*/
|
|
62
|
+
export class Maintenance {
|
|
63
|
+
d;
|
|
64
|
+
queue;
|
|
65
|
+
queueConn;
|
|
66
|
+
worker;
|
|
67
|
+
workerConn;
|
|
68
|
+
closed = false;
|
|
69
|
+
handlers = new Map();
|
|
70
|
+
schedules = [];
|
|
71
|
+
constructor(d) {
|
|
72
|
+
this.d = d;
|
|
73
|
+
this.handle(OUTPUT_CLEANUP_JOB, async () => {
|
|
74
|
+
const n = await deleteExpiredOutputs(d.db);
|
|
75
|
+
if (n > 0)
|
|
76
|
+
d.log.info("expired tool outputs deleted", { count: n });
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/** 登记某个任务名的处理函数(构造期调用;Worker 启动前后都可)。 */
|
|
80
|
+
handle(name, fn) {
|
|
81
|
+
this.handlers.set(name, fn);
|
|
82
|
+
}
|
|
83
|
+
/** 登记一个周期任务(构造期调用;`ensureSchedules` 时一并 upsert)。 */
|
|
84
|
+
schedule(s) {
|
|
85
|
+
this.schedules.push(s);
|
|
86
|
+
}
|
|
87
|
+
/** 投递一个维护任务。 */
|
|
88
|
+
async add(name, data, opts) {
|
|
89
|
+
await this.getQueue().add(name, data, opts);
|
|
90
|
+
}
|
|
91
|
+
/** 登记周期任务的 job scheduler(幂等;worker 角色启动时调用)。 */
|
|
92
|
+
async ensureSchedules() {
|
|
93
|
+
await this.getQueue().upsertJobScheduler(OUTPUT_CLEANUP_SCHEDULER_ID, { every: OUTPUT_CLEANUP_EVERY_MS }, {
|
|
94
|
+
name: OUTPUT_CLEANUP_JOB,
|
|
95
|
+
data: {},
|
|
96
|
+
opts: { removeOnComplete: true, removeOnFail: 100 },
|
|
97
|
+
});
|
|
98
|
+
for (const s of this.schedules) {
|
|
99
|
+
await this.getQueue().upsertJobScheduler(s.id, { every: s.everyMs() }, { name: s.name, data: {}, opts: { removeOnComplete: true, removeOnFail: 100 } });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/** 启动维护队列的 Worker(只在含 `worker` 角色的进程)。 */
|
|
103
|
+
startWorker() {
|
|
104
|
+
if (this.worker || this.closed)
|
|
105
|
+
return;
|
|
106
|
+
this.workerConn = bullConnection(this.d.redisUrl, this.d.log);
|
|
107
|
+
this.worker = new Worker(MAINTENANCE_QUEUE_NAME, (job, token) => this.process(job, token), {
|
|
108
|
+
connection: this.workerConn,
|
|
109
|
+
concurrency: 5,
|
|
110
|
+
});
|
|
111
|
+
this.worker.on("error", (err) => this.d.log.error("maintenance worker error", { err }));
|
|
112
|
+
this.worker.on("failed", (job, err) => this.d.log.error("maintenance job failed", { name: job?.name, jobId: job?.id, err }));
|
|
113
|
+
}
|
|
114
|
+
async close() {
|
|
115
|
+
this.closed = true;
|
|
116
|
+
const w = this.worker;
|
|
117
|
+
const q = this.queue;
|
|
118
|
+
this.worker = undefined;
|
|
119
|
+
this.queue = undefined;
|
|
120
|
+
await w?.close().catch(() => { });
|
|
121
|
+
await q?.close().catch(() => { });
|
|
122
|
+
for (const c of [this.workerConn, this.queueConn]) {
|
|
123
|
+
if (c)
|
|
124
|
+
await c.quit().catch(() => c.disconnect());
|
|
125
|
+
}
|
|
126
|
+
this.workerConn = undefined;
|
|
127
|
+
this.queueConn = undefined;
|
|
128
|
+
}
|
|
129
|
+
getQueue() {
|
|
130
|
+
if (this.closed)
|
|
131
|
+
throw new Error("maintenance queue is closed");
|
|
132
|
+
if (!this.queue) {
|
|
133
|
+
this.queueConn = bullConnection(this.d.redisUrl, this.d.log);
|
|
134
|
+
this.queue = new Queue(MAINTENANCE_QUEUE_NAME, { connection: this.queueConn });
|
|
135
|
+
this.queue.on("error", (err) => this.d.log.error("maintenance queue error", { err }));
|
|
136
|
+
}
|
|
137
|
+
return this.queue;
|
|
138
|
+
}
|
|
139
|
+
async process(job, token) {
|
|
140
|
+
const fn = this.handlers.get(job.name);
|
|
141
|
+
if (!fn) {
|
|
142
|
+
this.d.log.warn("unknown maintenance job", { name: job.name, jobId: job.id });
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
await fn(job, token);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { MediaBytes, MediaInfo } from "./context/build.js";
|
|
2
|
+
/**
|
|
3
|
+
* 一次运行内的附件字节缓存(进程内,LRU,按总字节数封顶):同一次运行的后续步骤不再重复取同一附件。
|
|
4
|
+
* 上限取 `attachments.requestMediaBytes`:一次请求带的媒体字节不超过它,缓存再大也用不上。
|
|
5
|
+
*
|
|
6
|
+
* 多副本下允许:键含 finalize 时的 etag 与大小(内容不可变),只是优化——缓存未命中时照常从存储取,
|
|
7
|
+
* 不同副本之间不共享、也不需要一致;随运行结束丢弃。
|
|
8
|
+
*/
|
|
9
|
+
export declare class MediaCache {
|
|
10
|
+
private readonly maxBytes;
|
|
11
|
+
private readonly entries;
|
|
12
|
+
private total;
|
|
13
|
+
constructor(maxBytes: number);
|
|
14
|
+
/** 缓存键:附件 id、etag、声明大小与取的字节上限(`text/*` 只取开头)。 */
|
|
15
|
+
static key(attachmentId: string, info: MediaInfo, cap: number | undefined): string;
|
|
16
|
+
/** 已缓存的总字节数。 */
|
|
17
|
+
get size(): number;
|
|
18
|
+
get(key: string): MediaBytes | undefined;
|
|
19
|
+
/** 放入;比上限还大的不缓存。超出上限时淘汰最久未用的。 */
|
|
20
|
+
set(key: string, value: MediaBytes): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 一次运行内的附件字节缓存(进程内,LRU,按总字节数封顶):同一次运行的后续步骤不再重复取同一附件。
|
|
3
|
+
* 上限取 `attachments.requestMediaBytes`:一次请求带的媒体字节不超过它,缓存再大也用不上。
|
|
4
|
+
*
|
|
5
|
+
* 多副本下允许:键含 finalize 时的 etag 与大小(内容不可变),只是优化——缓存未命中时照常从存储取,
|
|
6
|
+
* 不同副本之间不共享、也不需要一致;随运行结束丢弃。
|
|
7
|
+
*/
|
|
8
|
+
export class MediaCache {
|
|
9
|
+
maxBytes;
|
|
10
|
+
entries = new Map();
|
|
11
|
+
total = 0;
|
|
12
|
+
constructor(maxBytes) {
|
|
13
|
+
this.maxBytes = maxBytes;
|
|
14
|
+
}
|
|
15
|
+
/** 缓存键:附件 id、etag、声明大小与取的字节上限(`text/*` 只取开头)。 */
|
|
16
|
+
static key(attachmentId, info, cap) {
|
|
17
|
+
return [attachmentId, info.etag ?? "", info.size, cap ?? ""].join("\u0000");
|
|
18
|
+
}
|
|
19
|
+
/** 已缓存的总字节数。 */
|
|
20
|
+
get size() {
|
|
21
|
+
return this.total;
|
|
22
|
+
}
|
|
23
|
+
get(key) {
|
|
24
|
+
const v = this.entries.get(key);
|
|
25
|
+
if (v === undefined)
|
|
26
|
+
return undefined;
|
|
27
|
+
// 最近使用的移到末尾
|
|
28
|
+
this.entries.delete(key);
|
|
29
|
+
this.entries.set(key, v);
|
|
30
|
+
return v;
|
|
31
|
+
}
|
|
32
|
+
/** 放入;比上限还大的不缓存。超出上限时淘汰最久未用的。 */
|
|
33
|
+
set(key, value) {
|
|
34
|
+
const n = value.data.byteLength;
|
|
35
|
+
if (n > this.maxBytes)
|
|
36
|
+
return;
|
|
37
|
+
const old = this.entries.get(key);
|
|
38
|
+
if (old) {
|
|
39
|
+
this.total -= old.data.byteLength;
|
|
40
|
+
this.entries.delete(key);
|
|
41
|
+
}
|
|
42
|
+
this.entries.set(key, value);
|
|
43
|
+
this.total += n;
|
|
44
|
+
for (const [k, v] of this.entries) {
|
|
45
|
+
if (this.total <= this.maxBytes)
|
|
46
|
+
break;
|
|
47
|
+
this.entries.delete(k);
|
|
48
|
+
this.total -= v.data.byteLength;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { type ContentBlock, type Logger, type ModelProvider, type ModelRequest, type ModelStreamEvent, type ModelUsage, type StopReason } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import type { AgentDefinition } from "../agents/definition.js";
|
|
3
|
+
import type { KernelConfig } from "../config/schema.js";
|
|
4
|
+
import type { EventLog } from "../conversations/event-log.js";
|
|
5
|
+
import type { KernelDb } from "../db/kernel-schema.js";
|
|
6
|
+
import type { ToolRegistry, UnavailableTool } from "../tools/registry.js";
|
|
7
|
+
import { type BuildModelRequestInput, type MediaBytes, type MediaInfo, type ModelCallMeta, type RequestTool } from "./context/build.js";
|
|
8
|
+
import { type ConversationKindForHooks, type HookRunner } from "./hook-calls.js";
|
|
9
|
+
import type { SubagentParent } from "./loop.js";
|
|
10
|
+
import { MediaCache } from "./media-cache.js";
|
|
11
|
+
import { type ProviderRegistry } from "./providers.js";
|
|
12
|
+
import type { UsageReporter } from "./usage-report.js";
|
|
13
|
+
/** 单轮收尾的尾部提醒(模型可见,英文;spec 6 轮次额度收尾)。 */
|
|
14
|
+
export declare const WRAP_UP_REMINDER = "Step limit reached. Do not call tools. Summarize what you found and what remains for the user.";
|
|
15
|
+
/** 所用模型不支持工具(`capabilities.tools` 为 false)时的提醒(模型可见,英文)。 */
|
|
16
|
+
export declare const TOOLS_UNSUPPORTED_REMINDER = "Tools are unavailable for this model. Answer without calling tools.";
|
|
17
|
+
/** 不可用工具提醒的前缀(模型可见,英文)。 */
|
|
18
|
+
export declare const TOOLS_UNAVAILABLE_PREFIX = "The following tools are unavailable in this run: ";
|
|
19
|
+
/** 本 run 中此前有工具不可用、现在全部恢复时的提醒(模型可见,英文)。 */
|
|
20
|
+
export declare const TOOLS_AVAILABLE_AGAIN = "All previously unavailable tools are available again.";
|
|
21
|
+
/** 不可用工具提醒:`The following tools are unavailable in this run: <ref> (<reason>), ...`。 */
|
|
22
|
+
export declare function toolsUnavailableReminder(unavailable: readonly UnavailableTool[]): string;
|
|
23
|
+
/** 流式增量的出口(推给前端等订阅方);`step_reset` 表示丢弃本步已推出的增量、重新开始。 */
|
|
24
|
+
export type StreamSink = (delta: {
|
|
25
|
+
kind: "text" | "thinking" | "step_reset";
|
|
26
|
+
runId: string;
|
|
27
|
+
step: number;
|
|
28
|
+
text?: string;
|
|
29
|
+
}) => void;
|
|
30
|
+
export interface ModelStepDeps {
|
|
31
|
+
db: KernelDb;
|
|
32
|
+
eventLog: EventLog;
|
|
33
|
+
registry: Pick<ProviderRegistry, "resolve">;
|
|
34
|
+
/** 工具注册表:每步开始时解析 agent 引用的工具(状态可能在步骤之间变化)。 */
|
|
35
|
+
tools: Pick<ToolRegistry, "forAgent">;
|
|
36
|
+
config: () => KernelConfig;
|
|
37
|
+
log: Logger;
|
|
38
|
+
/**
|
|
39
|
+
* 会话附件(构建请求时解析日志里的媒体引用;见 AttachmentsService)。未提供时媒体引用一律按「不再可用」处理。
|
|
40
|
+
* 两个方法都只对「确定不存在」返回缺省 / null;暂时故障(存储不可用、网络错误)一律抛错(Ruling M4)。
|
|
41
|
+
*/
|
|
42
|
+
media?: MediaSourceDeps;
|
|
43
|
+
/**
|
|
44
|
+
* Plugin hooks (`model.request` policy / observe before the call, `model.response` observe after it),
|
|
45
|
+
* for every attempt of a step and for the compaction call (`purpose: "compaction"`, I-1).
|
|
46
|
+
* Only chat runs get it: full-run and single-step eval replays omit it (P-18), and hooks also need
|
|
47
|
+
* `conversationKind: "chat"` on the step input.
|
|
48
|
+
*/
|
|
49
|
+
hooks?: HookRunner;
|
|
50
|
+
/**
|
|
51
|
+
* `usage.report` delivery (P-17): each written `usage` event is enqueued (chat runs and full-run eval
|
|
52
|
+
* replays, which both log usage). `enqueue` never throws and returns at once without handlers.
|
|
53
|
+
*/
|
|
54
|
+
usageReport?: Pick<UsageReporter, "enqueue">;
|
|
55
|
+
}
|
|
56
|
+
/** 构建请求用到的附件来源。 */
|
|
57
|
+
export interface MediaSourceDeps {
|
|
58
|
+
/** 附件行的声明信息(只含绑定在该会话、已 ready 的;没有行的不在结果里)。 */
|
|
59
|
+
info(orgId: string, conversationId: string, ids: readonly string[]): Promise<Map<string, MediaInfo>>;
|
|
60
|
+
/** 字节;对象已不在或内容被替换为 null。`caps` 里的附件只取开头若干字节(`text/*` 封顶,见 planMedia)。 */
|
|
61
|
+
fetch(orgId: string, conversationId: string, ids: readonly string[], caps?: ReadonlyMap<string, number>): Promise<Map<string, MediaBytes | null>>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* 取附件时存储暂时不可用(Ruling M4):不把它当成「附件不在」发占位,而是让本次尝试按可重试错误失败
|
|
65
|
+
* (`run.storage_unavailable`),走降级梯子的重试。
|
|
66
|
+
*/
|
|
67
|
+
export declare class MediaUnavailableError extends Error {
|
|
68
|
+
constructor(cause: unknown);
|
|
69
|
+
}
|
|
70
|
+
export interface ModelStepInput {
|
|
71
|
+
/** 会话所属组织(解析工具用)。 */
|
|
72
|
+
orgId: string;
|
|
73
|
+
conversationId: string;
|
|
74
|
+
runId: string;
|
|
75
|
+
step: number;
|
|
76
|
+
agent: AgentDefinition;
|
|
77
|
+
agentVersion: number;
|
|
78
|
+
signal: AbortSignal;
|
|
79
|
+
sink: StreamSink;
|
|
80
|
+
/**
|
|
81
|
+
* 本步开始时 loop 已吸收到的 user_message seq(R31):seq 更大的 user_message 不进本步请求,
|
|
82
|
+
* 由后续步骤吸收或触发下一轮;写入 `model_call.request.absorbedUpToSeq`,请求可由日志还原。
|
|
83
|
+
*/
|
|
84
|
+
absorbedUpToSeq: number;
|
|
85
|
+
/** 本次运行的附件字节缓存(同一次运行的各步共用,见 {@link MediaCache});缺省时只在本步内缓存。 */
|
|
86
|
+
mediaCache?: MediaCache;
|
|
87
|
+
/** Hook payload scope: the run's agent, its trigger account and the conversation kind. */
|
|
88
|
+
agentId?: string;
|
|
89
|
+
accountId?: string;
|
|
90
|
+
/** Hooks fire for `chat` and `subagent` (never for eval replays). */
|
|
91
|
+
conversationKind?: ConversationKindForHooks;
|
|
92
|
+
/** A sub-agent's run: where it was dispatched from (hook payloads carry it as `parent`). */
|
|
93
|
+
parent?: SubagentParent;
|
|
94
|
+
/**
|
|
95
|
+
* A sub-agent's run (phase C): the parent run whose `subagent_tokens_used` counts every usage
|
|
96
|
+
* event this step writes (step, wrap-up and compaction calls; spec §8.3).
|
|
97
|
+
*/
|
|
98
|
+
parentRunId?: string;
|
|
99
|
+
/**
|
|
100
|
+
* The run's step limit (`LoopContext.limits.maxSteps`) for the turn-limit reminder; a child's
|
|
101
|
+
* may be below `runtime.maxSteps` (final review m4). Defaults to `runtime.maxSteps`.
|
|
102
|
+
*/
|
|
103
|
+
maxSteps?: number;
|
|
104
|
+
}
|
|
105
|
+
export interface ModelStepResult {
|
|
106
|
+
content: ContentBlock[];
|
|
107
|
+
stopReason: StopReason | "aborted";
|
|
108
|
+
/** 本步的 `assistant_message` 已存在(幂等命中),未调用模型。 */
|
|
109
|
+
reused: boolean;
|
|
110
|
+
aborted: boolean;
|
|
111
|
+
usage: ModelUsage | null;
|
|
112
|
+
/**
|
|
113
|
+
* A sub-agent's step stopped before its request: the step's compaction call used up the
|
|
114
|
+
* parent run's token budget (spec §8.3: at most one call over per active child). The loop ends
|
|
115
|
+
* the run with `budget`.
|
|
116
|
+
*/
|
|
117
|
+
budget?: boolean;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* 运行级失败:`code` 写入 `run_failed.error.code`。模型错误为 `model.<kind>`,其余为
|
|
121
|
+
* `run.<reason>`(如 `run.model_unavailable`、`run.provider_unavailable`、`run.provider_error`)。
|
|
122
|
+
*/
|
|
123
|
+
export declare class RunError extends Error {
|
|
124
|
+
readonly code: string;
|
|
125
|
+
constructor(code: string, message: string);
|
|
126
|
+
}
|
|
127
|
+
/** 幂等键。`usage` 与 `assistant_message` 同批写入,带键保证重放时不重复记账。 */
|
|
128
|
+
/** 某步 assistant_message 的幂等键(tools 节点据此找到本步的工具调用)。 */
|
|
129
|
+
export declare const assistantIdemKey: (runId: string, step: number) => string;
|
|
130
|
+
/** 某步第 attempt 次模型调用的 model_call 幂等键(管线据此找到模型实际收到的工具)。 */
|
|
131
|
+
export declare const modelCallIdemKey: (runId: string, step: number, attempt: number) => string;
|
|
132
|
+
/** 一步最多的模型调用尝试次数(主模型、同模型重试、兜底,见 `ladder`)。 */
|
|
133
|
+
export declare const MAX_MODEL_ATTEMPTS = 3;
|
|
134
|
+
/** 一次模型流的结果({@link consumeModelStream})。 */
|
|
135
|
+
export interface StreamOutcome {
|
|
136
|
+
content: ContentBlock[];
|
|
137
|
+
stopReason: StopReason;
|
|
138
|
+
usage: ModelUsage;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* 一步模型调用:幂等 → 读日志 → 压缩 → 尾部提醒 → 构建请求 → 流式(看门狗)→ 降级梯子 → 写事件。
|
|
142
|
+
* 模型看到的一切先写进日志(`model_call` / `reminder` / `compaction_summary`),请求可由日志还原。
|
|
143
|
+
*/
|
|
144
|
+
export declare function runModelStep(deps: ModelStepDeps, input: ModelStepInput): Promise<ModelStepResult>;
|
|
145
|
+
/**
|
|
146
|
+
* 单轮收尾:到达步数上限时调用一次。写入收尾 `reminder`(位于请求末尾);照常带工具(历史里有工具调用时
|
|
147
|
+
* 部分供应商要求请求声明工具,也保持缓存前缀稳定),但 `toolChoice: "none"`——模型只能回复文本。
|
|
148
|
+
* 其余与 `runModelStep` 相同(幂等、降级、中止)。
|
|
149
|
+
*/
|
|
150
|
+
export declare function runFinalWrapUp(deps: ModelStepDeps, input: ModelStepInput): Promise<ModelStepResult>;
|
|
151
|
+
/** {@link assembleModelRequest} 的输入。 */
|
|
152
|
+
export interface AssembleModelRequestInput extends Omit<BuildModelRequestInput, "tools"> {
|
|
153
|
+
/** 本步解析出的工具;模型不支持工具(`capabilities.tools` 为 false)时不带。 */
|
|
154
|
+
tools: readonly RequestTool[];
|
|
155
|
+
/** 参数里没有 `maxOutputTokens` 旋钮时的输出上限(运行时为 `runtime.maxOutputTokens`)。 */
|
|
156
|
+
defaultMaxOutputTokens: number;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* 发给模型的请求(纯函数):`buildModelRequest`(注入 `params` 与本步工具:模型不支持工具时不带;收尾调用带
|
|
160
|
+
* `toolChoice: "none"`)→ `guardToolPairs`。输出上限:参数里有 `maxOutputTokens` 旋钮时取
|
|
161
|
+
* `min(模型上限, 旋钮)`,否则 `min(模型上限, defaultMaxOutputTokens)`。
|
|
162
|
+
* 运行时({@link runModelStep})与由日志还原请求(`evals/reconstruct.ts`)共用这一份,二者不会漂移。
|
|
163
|
+
*/
|
|
164
|
+
export declare function assembleModelRequest(input: AssembleModelRequestInput): {
|
|
165
|
+
request: ModelRequest;
|
|
166
|
+
meta: ModelCallMeta;
|
|
167
|
+
mediaTokens: number;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* 消费一次模型流,带空闲看门狗:两次事件之间超过 `idleMs` → 本地中止并按 `ModelError("timeout")` 抛出。
|
|
171
|
+
* 外部 `signal` 触发 → `StepAborted`。每次 `next()` 都与停止信号竞速,供应商不响应 signal 也不会卡住。
|
|
172
|
+
* 运行时与评测单步回放(`evals/step-replay.ts`)、评委共用。
|
|
173
|
+
*/
|
|
174
|
+
export declare function consumeModelStream(provider: ModelProvider, request: ModelRequest, idleMs: number, signal: AbortSignal, onDelta: (ev: Exclude<ModelStreamEvent, {
|
|
175
|
+
type: "message_complete";
|
|
176
|
+
}>) => void): Promise<StreamOutcome>;
|