@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,34 @@
|
|
|
1
|
+
import { type OnModuleDestroy } from "@nestjs/common";
|
|
2
|
+
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import type { ConversationsService } from "../conversations/conversations.service.js";
|
|
5
|
+
import type { ApiTokenService } from "../identity/api-tokens.js";
|
|
6
|
+
import { type Principal } from "../identity/principal.js";
|
|
7
|
+
import type { SessionService } from "../identity/sessions.js";
|
|
8
|
+
import { type OrgContext } from "../orgs/org.guard.js";
|
|
9
|
+
import type { ConversationStreams } from "./stream.js";
|
|
10
|
+
declare const StreamQuery: z.ZodObject<{
|
|
11
|
+
after: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
/**
|
|
14
|
+
* 会话事件流(SSE):`GET /api/v1/orgs/:orgId/conversations/:id/stream?after=<seq>`,`agents.use`,只有会话所有者可用。
|
|
15
|
+
* - 打开时不阻塞地调用一次 ensureRun(`ConversationsService.kickRun`),停在「运行中」的孤儿运行由此被清理;
|
|
16
|
+
* - 先订阅会话频道、再回放 `after`(或优先的 `Last-Event-ID`)之后的事件:`id: <seq>` / `event: event`;
|
|
17
|
+
* 之后收到 `events` 通知就补读新事件(按 seq 去重),收到增量就发 `event: delta`,收到界面刷新
|
|
18
|
+
* (插件 `ctx.ui.invalidate`)就发 `event: ui`(`data: {"plugin","contribution"}`);
|
|
19
|
+
* - 每 `runtime.sseHeartbeatMs` 发 `: ping` 注释;每 `runtime.sseRecheckMs` 复核凭据(会话未吊销 / 令牌仍有效,
|
|
20
|
+
* access token 到期本身不算失效)与可见性,失败时发 `event: error`(`data: {"code"}`)后关闭流;
|
|
21
|
+
* - 用 `@Res()` + `reply.hijack()` 直接写原始响应,绕开 Nest / Fastify 的响应处理与缓冲。
|
|
22
|
+
* 代理(Web 层)需透传 `x-accel-buffering: no`、`cache-control: no-cache`。
|
|
23
|
+
*/
|
|
24
|
+
export declare class ConversationStreamController implements OnModuleDestroy {
|
|
25
|
+
private readonly streams;
|
|
26
|
+
private readonly sessions;
|
|
27
|
+
private readonly tokens;
|
|
28
|
+
private readonly conversations;
|
|
29
|
+
constructor(streams: ConversationStreams, sessions: SessionService, tokens: ApiTokenService, conversations: ConversationsService);
|
|
30
|
+
stream(principal: Principal, org: OrgContext, id: string, q: z.infer<typeof StreamQuery>, lastEventId: string | undefined, req: FastifyRequest, reply: FastifyReply): Promise<void>;
|
|
31
|
+
/** 停机:关闭本进程的全部流,否则 HTTP 关闭要等到这些长连接超时。 */
|
|
32
|
+
onModuleDestroy(): void;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
+
};
|
|
10
|
+
import { Controller, Get, Headers, Inject, Param, Query, Req, Res, } from "@nestjs/common";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import { ApiError } from "../errors.js";
|
|
13
|
+
import { API_TOKENS, CONVERSATION_STREAMS, CONVERSATIONS, SESSIONS } from "../http/tokens.js";
|
|
14
|
+
import { ZodPipe } from "../http/zod.pipe.js";
|
|
15
|
+
import { credentialCheck } from "../identity/credential-check.js";
|
|
16
|
+
import { CurrentPrincipal, requireUser } from "../identity/principal.js";
|
|
17
|
+
import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
|
|
18
|
+
const BEARER_RE = /^Bearer\s+(\S+)$/i;
|
|
19
|
+
const StreamQuery = z.object({
|
|
20
|
+
after: z.coerce.number().int().min(0).max(Number.MAX_SAFE_INTEGER).default(0),
|
|
21
|
+
});
|
|
22
|
+
/** `Last-Event-ID`:非负整数(客户端回传的最后一条事件 seq)。 */
|
|
23
|
+
function parseLastEventId(v) {
|
|
24
|
+
const t = v.trim();
|
|
25
|
+
const n = Number(t);
|
|
26
|
+
if (!/^\d+$/.test(t) || !Number.isSafeInteger(n)) {
|
|
27
|
+
throw new ApiError("validation_failed", "Last-Event-ID must be a non-negative integer");
|
|
28
|
+
}
|
|
29
|
+
return n;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 会话事件流(SSE):`GET /api/v1/orgs/:orgId/conversations/:id/stream?after=<seq>`,`agents.use`,只有会话所有者可用。
|
|
33
|
+
* - 打开时不阻塞地调用一次 ensureRun(`ConversationsService.kickRun`),停在「运行中」的孤儿运行由此被清理;
|
|
34
|
+
* - 先订阅会话频道、再回放 `after`(或优先的 `Last-Event-ID`)之后的事件:`id: <seq>` / `event: event`;
|
|
35
|
+
* 之后收到 `events` 通知就补读新事件(按 seq 去重),收到增量就发 `event: delta`,收到界面刷新
|
|
36
|
+
* (插件 `ctx.ui.invalidate`)就发 `event: ui`(`data: {"plugin","contribution"}`);
|
|
37
|
+
* - 每 `runtime.sseHeartbeatMs` 发 `: ping` 注释;每 `runtime.sseRecheckMs` 复核凭据(会话未吊销 / 令牌仍有效,
|
|
38
|
+
* access token 到期本身不算失效)与可见性,失败时发 `event: error`(`data: {"code"}`)后关闭流;
|
|
39
|
+
* - 用 `@Res()` + `reply.hijack()` 直接写原始响应,绕开 Nest / Fastify 的响应处理与缓冲。
|
|
40
|
+
* 代理(Web 层)需透传 `x-accel-buffering: no`、`cache-control: no-cache`。
|
|
41
|
+
*/
|
|
42
|
+
let ConversationStreamController = class ConversationStreamController {
|
|
43
|
+
streams;
|
|
44
|
+
sessions;
|
|
45
|
+
tokens;
|
|
46
|
+
conversations;
|
|
47
|
+
constructor(streams, sessions, tokens, conversations) {
|
|
48
|
+
this.streams = streams;
|
|
49
|
+
this.sessions = sessions;
|
|
50
|
+
this.tokens = tokens;
|
|
51
|
+
this.conversations = conversations;
|
|
52
|
+
}
|
|
53
|
+
async stream(principal, org, id, q, lastEventId, req, reply) {
|
|
54
|
+
const p = requireUser(principal);
|
|
55
|
+
const afterSeq = lastEventId !== undefined ? parseLastEventId(lastEventId) : q.after;
|
|
56
|
+
const res = reply.raw;
|
|
57
|
+
// 到这里为止的错误(不可见、订阅失败)尚未写响应,由错误过滤器按普通错误返回。
|
|
58
|
+
const handle = await this.streams.open({
|
|
59
|
+
orgId: org.orgId,
|
|
60
|
+
conversationId: id,
|
|
61
|
+
viewerAccountId: p.account.id,
|
|
62
|
+
afterSeq,
|
|
63
|
+
// 个人令牌要保留明文以便复核时重新 authenticate(只在本连接的闭包里,不落日志)
|
|
64
|
+
credential: credentialCheck(p, BEARER_RE.exec(req.headers.authorization ?? "")?.[1], {
|
|
65
|
+
sessions: this.sessions,
|
|
66
|
+
tokens: this.tokens,
|
|
67
|
+
}),
|
|
68
|
+
}, {
|
|
69
|
+
write: (chunk) => {
|
|
70
|
+
res.write(chunk);
|
|
71
|
+
},
|
|
72
|
+
backlog: () => res.writableLength,
|
|
73
|
+
end: () => {
|
|
74
|
+
res.end();
|
|
75
|
+
},
|
|
76
|
+
abort: () => {
|
|
77
|
+
res.destroy();
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
reply.hijack();
|
|
81
|
+
// 可见性已通过:不阻塞地 ensureRun(清理孤儿运行、投递等待中的消息),见 ConversationsService.kickRun。
|
|
82
|
+
this.conversations.kickRun(id);
|
|
83
|
+
res.on("close", () => handle.close());
|
|
84
|
+
// 订阅期间客户端已断开:close 事件可能已经错过
|
|
85
|
+
if (res.destroyed || !res.socket || res.socket.destroyed) {
|
|
86
|
+
handle.close();
|
|
87
|
+
res.destroy();
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
res.writeHead(200, {
|
|
91
|
+
"content-type": "text/event-stream; charset=utf-8",
|
|
92
|
+
"cache-control": "no-cache",
|
|
93
|
+
"x-accel-buffering": "no",
|
|
94
|
+
connection: "keep-alive",
|
|
95
|
+
});
|
|
96
|
+
res.flushHeaders();
|
|
97
|
+
handle.begin();
|
|
98
|
+
}
|
|
99
|
+
/** 停机:关闭本进程的全部流,否则 HTTP 关闭要等到这些长连接超时。 */
|
|
100
|
+
onModuleDestroy() {
|
|
101
|
+
this.streams.closeAll();
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
__decorate([
|
|
105
|
+
Get(":id/stream"),
|
|
106
|
+
OrgAction("agents.use"),
|
|
107
|
+
__param(0, CurrentPrincipal()),
|
|
108
|
+
__param(1, CurrentOrg()),
|
|
109
|
+
__param(2, Param("id")),
|
|
110
|
+
__param(3, Query(new ZodPipe(StreamQuery))),
|
|
111
|
+
__param(4, Headers("last-event-id")),
|
|
112
|
+
__param(5, Req()),
|
|
113
|
+
__param(6, Res())
|
|
114
|
+
], ConversationStreamController.prototype, "stream", null);
|
|
115
|
+
ConversationStreamController = __decorate([
|
|
116
|
+
Controller("api/v1/orgs/:orgId/conversations"),
|
|
117
|
+
__param(0, Inject(CONVERSATION_STREAMS)),
|
|
118
|
+
__param(1, Inject(SESSIONS)),
|
|
119
|
+
__param(2, Inject(API_TOKENS)),
|
|
120
|
+
__param(3, Inject(CONVERSATIONS))
|
|
121
|
+
], ConversationStreamController);
|
|
122
|
+
export { ConversationStreamController };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Logger } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import type { KernelConfig } from "../config/schema.js";
|
|
3
|
+
import { type EventLog } from "../conversations/event-log.js";
|
|
4
|
+
import type { CredentialCheck } from "../identity/credential-check.js";
|
|
5
|
+
/** 一次 SSE 连接的输出端(由 HTTP 层包装原始响应)。 */
|
|
6
|
+
export interface SseOutput {
|
|
7
|
+
write(chunk: string): void;
|
|
8
|
+
/** 已写入但尚未发出的字节数(慢客户端积压)。 */
|
|
9
|
+
backlog(): number;
|
|
10
|
+
/** 正常结束(发完已缓冲的数据后 FIN)。 */
|
|
11
|
+
end(): void;
|
|
12
|
+
/** 立即销毁连接并释放已缓冲的数据(慢客户端、内部故障)。 */
|
|
13
|
+
abort(): void;
|
|
14
|
+
}
|
|
15
|
+
/** 流用到的总线:内核 bus(命名空间 `kernel`)。 */
|
|
16
|
+
export interface StreamBus {
|
|
17
|
+
subscribe(topic: string, handler: (payload: unknown) => unknown): Promise<() => Promise<void>>;
|
|
18
|
+
}
|
|
19
|
+
export interface ConversationStreamsDeps {
|
|
20
|
+
eventLog: Pick<EventLog, "readAfter">;
|
|
21
|
+
bus: StreamBus;
|
|
22
|
+
/** 轻量可见性判定:连接建立时与每 `sseRecheckMs` 复核一次。 */
|
|
23
|
+
access(orgId: string, conversationId: string, viewerAccountId: string): Promise<boolean>;
|
|
24
|
+
config: () => KernelConfig;
|
|
25
|
+
log: Pick<Logger, "warn">;
|
|
26
|
+
}
|
|
27
|
+
export interface StreamParams {
|
|
28
|
+
orgId: string;
|
|
29
|
+
conversationId: string;
|
|
30
|
+
viewerAccountId: string;
|
|
31
|
+
/** 只发送 seq 大于它的事件。 */
|
|
32
|
+
afterSeq: number;
|
|
33
|
+
/** 复核建立连接时使用的凭据(会话未吊销 / 令牌仍有效),与可见性一起在建立时与每次复核时检查。 */
|
|
34
|
+
credential: CredentialCheck;
|
|
35
|
+
}
|
|
36
|
+
/** 一条已订阅、尚未开始输出的流:HTTP 层写完响应头后调用 `begin`。 */
|
|
37
|
+
export interface StreamHandle {
|
|
38
|
+
begin(): void;
|
|
39
|
+
/**
|
|
40
|
+
* 关闭流:`end` 正常结束响应,`abort` 销毁连接。`begin()` 之前不碰输出端
|
|
41
|
+
* (响应还没开始,由 HTTP 层按普通错误返回)。
|
|
42
|
+
*/
|
|
43
|
+
close(mode?: "end" | "abort"): void;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 会话事件流(SSE):本进程持有的连接集合,停机时一并关闭。
|
|
47
|
+
* 跨副本的数据只经 PG(事件日志)与内核 bus(`conv.<id>`)流动,进程内只保存连接本身的资源
|
|
48
|
+
* (订阅、心跳与复核定时器)。
|
|
49
|
+
*/
|
|
50
|
+
export declare class ConversationStreams {
|
|
51
|
+
private readonly d;
|
|
52
|
+
private readonly active;
|
|
53
|
+
constructor(d: ConversationStreamsDeps);
|
|
54
|
+
/**
|
|
55
|
+
* 复核凭据与可见性,并先订阅会话频道(之后再回放,避免遗漏两者之间提交的事件)。
|
|
56
|
+
* 凭据失效 → 对应的 `auth.*`;不可见 → `conversation.not_found`;订阅失败照常抛出。此时尚未写任何响应,调用方可以按普通错误返回。
|
|
57
|
+
*/
|
|
58
|
+
open(p: StreamParams, out: SseOutput): Promise<StreamHandle>;
|
|
59
|
+
/** 关闭本进程的全部流(停机时调用)。 */
|
|
60
|
+
closeAll(): void;
|
|
61
|
+
/** 当前打开的流数(测试用)。 */
|
|
62
|
+
get size(): number;
|
|
63
|
+
}
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { CONVERSATION_CHANGES, conversationTopic, } from "../conversations/event-log.js";
|
|
2
|
+
import { ApiError } from "../errors.js";
|
|
3
|
+
import { isUiBusMessage, uiFrame } from "../ui/registry.js";
|
|
4
|
+
/** 补读事件的分页大小。 */
|
|
5
|
+
const PAGE = 500;
|
|
6
|
+
/** 慢客户端的积压上限:超过即关闭流,客户端带 Last-Event-ID 重连补读。 */
|
|
7
|
+
const MAX_BACKLOG_BYTES = 4 * 1024 * 1024;
|
|
8
|
+
/** 授权失败时随错误返回的英文说明(建立连接时作为普通错误响应)。 */
|
|
9
|
+
const DENIAL_MESSAGES = {
|
|
10
|
+
"conversation.not_found": "Conversation not found",
|
|
11
|
+
"auth.session_revoked": "Session has been revoked",
|
|
12
|
+
"auth.required": "Authentication required",
|
|
13
|
+
};
|
|
14
|
+
/** 凭据仍有效且会话仍可见返回 null,否则返回错误码(凭据优先)。 */
|
|
15
|
+
async function authorize(d, p) {
|
|
16
|
+
const denied = await p.credential();
|
|
17
|
+
if (denied !== null)
|
|
18
|
+
return denied;
|
|
19
|
+
const ok = await d.access(p.orgId, p.conversationId, p.viewerAccountId);
|
|
20
|
+
return ok ? null : "conversation.not_found";
|
|
21
|
+
}
|
|
22
|
+
const errorFrame = (code) => `event: error\ndata: ${JSON.stringify({ code })}\n\n`;
|
|
23
|
+
function isBusMessage(m) {
|
|
24
|
+
if (typeof m !== "object" || m === null)
|
|
25
|
+
return false;
|
|
26
|
+
const k = m.kind;
|
|
27
|
+
if (k === "events")
|
|
28
|
+
return typeof m.toSeq === "number";
|
|
29
|
+
if (k === "ui")
|
|
30
|
+
return isUiBusMessage(m);
|
|
31
|
+
if (k === "changed") {
|
|
32
|
+
const what = m.what;
|
|
33
|
+
return CONVERSATION_CHANGES.includes(what);
|
|
34
|
+
}
|
|
35
|
+
if (k === "subagent_progress") {
|
|
36
|
+
const x = m;
|
|
37
|
+
return (typeof x.subagentId === "string" &&
|
|
38
|
+
typeof x.step === "number" &&
|
|
39
|
+
typeof x.toolCalls === "number");
|
|
40
|
+
}
|
|
41
|
+
return k === "delta" && typeof m.runId === "string";
|
|
42
|
+
}
|
|
43
|
+
const eventFrame = (e) => `id: ${e.seq}\nevent: event\ndata: ${JSON.stringify(e)}\n\n`;
|
|
44
|
+
/**
|
|
45
|
+
* 会话事件流(SSE):本进程持有的连接集合,停机时一并关闭。
|
|
46
|
+
* 跨副本的数据只经 PG(事件日志)与内核 bus(`conv.<id>`)流动,进程内只保存连接本身的资源
|
|
47
|
+
* (订阅、心跳与复核定时器)。
|
|
48
|
+
*/
|
|
49
|
+
export class ConversationStreams {
|
|
50
|
+
d;
|
|
51
|
+
active = new Set();
|
|
52
|
+
constructor(d) {
|
|
53
|
+
this.d = d;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 复核凭据与可见性,并先订阅会话频道(之后再回放,避免遗漏两者之间提交的事件)。
|
|
57
|
+
* 凭据失效 → 对应的 `auth.*`;不可见 → `conversation.not_found`;订阅失败照常抛出。此时尚未写任何响应,调用方可以按普通错误返回。
|
|
58
|
+
*/
|
|
59
|
+
async open(p, out) {
|
|
60
|
+
const denied = await authorize(this.d, p);
|
|
61
|
+
if (denied !== null)
|
|
62
|
+
throw new ApiError(denied, DENIAL_MESSAGES[denied] ?? "Access denied");
|
|
63
|
+
const conn = new Connection(this.d, p, out, () => this.active.delete(conn));
|
|
64
|
+
this.active.add(conn);
|
|
65
|
+
try {
|
|
66
|
+
await conn.subscribe();
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
conn.close();
|
|
70
|
+
throw e;
|
|
71
|
+
}
|
|
72
|
+
return conn;
|
|
73
|
+
}
|
|
74
|
+
/** 关闭本进程的全部流(停机时调用)。 */
|
|
75
|
+
closeAll() {
|
|
76
|
+
for (const c of [...this.active])
|
|
77
|
+
c.close();
|
|
78
|
+
}
|
|
79
|
+
/** 当前打开的流数(测试用)。 */
|
|
80
|
+
get size() {
|
|
81
|
+
return this.active.size;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
class Connection {
|
|
85
|
+
d;
|
|
86
|
+
p;
|
|
87
|
+
out;
|
|
88
|
+
onClosed;
|
|
89
|
+
lastSeq;
|
|
90
|
+
closed = false;
|
|
91
|
+
chain;
|
|
92
|
+
openGate;
|
|
93
|
+
unsubscribe;
|
|
94
|
+
timers = [];
|
|
95
|
+
rechecking = false;
|
|
96
|
+
begun = false;
|
|
97
|
+
constructor(d, p, out, onClosed) {
|
|
98
|
+
this.d = d;
|
|
99
|
+
this.p = p;
|
|
100
|
+
this.out = out;
|
|
101
|
+
this.onClosed = onClosed;
|
|
102
|
+
this.lastSeq = p.afterSeq;
|
|
103
|
+
// 所有输出串行:先回放,之后按到达顺序处理频道消息;begin() 之前闸门关着。
|
|
104
|
+
this.chain = new Promise((resolve) => {
|
|
105
|
+
this.openGate = resolve;
|
|
106
|
+
});
|
|
107
|
+
this.enqueue(() => this.catchUp());
|
|
108
|
+
}
|
|
109
|
+
async subscribe() {
|
|
110
|
+
const un = await this.d.bus.subscribe(conversationTopic(this.p.conversationId), (m) => this.onMessage(m));
|
|
111
|
+
if (this.closed)
|
|
112
|
+
await un();
|
|
113
|
+
else
|
|
114
|
+
this.unsubscribe = un;
|
|
115
|
+
}
|
|
116
|
+
begin() {
|
|
117
|
+
if (this.closed)
|
|
118
|
+
return;
|
|
119
|
+
this.begun = true;
|
|
120
|
+
const { sseHeartbeatMs, sseRecheckMs } = this.d.config().runtime;
|
|
121
|
+
this.timers.push(setInterval(() => this.write(": ping\n\n"), sseHeartbeatMs), setInterval(() => void this.recheck(), sseRecheckMs));
|
|
122
|
+
this.openGate();
|
|
123
|
+
}
|
|
124
|
+
close(mode = "end") {
|
|
125
|
+
if (this.closed)
|
|
126
|
+
return;
|
|
127
|
+
this.closed = true;
|
|
128
|
+
for (const t of this.timers)
|
|
129
|
+
clearInterval(t);
|
|
130
|
+
this.timers = [];
|
|
131
|
+
this.openGate();
|
|
132
|
+
const un = this.unsubscribe;
|
|
133
|
+
this.unsubscribe = undefined;
|
|
134
|
+
un?.().catch((err) => this.d.log.warn("conversation stream unsubscribe failed", {
|
|
135
|
+
conversationId: this.p.conversationId,
|
|
136
|
+
err,
|
|
137
|
+
}));
|
|
138
|
+
if (this.begun) {
|
|
139
|
+
try {
|
|
140
|
+
if (mode === "abort")
|
|
141
|
+
this.out.abort();
|
|
142
|
+
else
|
|
143
|
+
this.out.end();
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
// 连接已断开
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
this.onClosed();
|
|
150
|
+
}
|
|
151
|
+
onMessage(m) {
|
|
152
|
+
if (this.closed || !isBusMessage(m))
|
|
153
|
+
return;
|
|
154
|
+
if (m.kind === "events") {
|
|
155
|
+
const toSeq = m.toSeq;
|
|
156
|
+
this.enqueue(async () => {
|
|
157
|
+
if (toSeq > this.lastSeq)
|
|
158
|
+
await this.catchUp();
|
|
159
|
+
});
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (m.kind === "ui") {
|
|
163
|
+
// 界面刷新:只是「去重新取视图」的提示,网页按 plugin + contribution 重新请求(那里再鉴权)
|
|
164
|
+
const frame = uiFrame(m);
|
|
165
|
+
this.enqueue(() => this.write(frame));
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (m.kind === "changed") {
|
|
169
|
+
// a hint to refetch that part of the conversation (the HTTP read checks access again)
|
|
170
|
+
const frame = `event: changed\ndata: ${JSON.stringify({ what: m.what })}\n\n`;
|
|
171
|
+
this.enqueue(() => this.write(frame));
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (m.kind === "subagent_progress") {
|
|
175
|
+
// a sub-agent's step (spec §14.2): only on its parent's topic, which this viewer may read
|
|
176
|
+
const { kind: _k, ...progress } = m;
|
|
177
|
+
const frame = `event: subagent_progress\ndata: ${JSON.stringify(progress)}\n\n`;
|
|
178
|
+
this.enqueue(() => this.write(frame));
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const { kind: _kind, ...delta } = m;
|
|
182
|
+
this.enqueue(() => this.write(`event: delta\ndata: ${JSON.stringify(delta)}\n\n`));
|
|
183
|
+
}
|
|
184
|
+
enqueue(fn) {
|
|
185
|
+
this.chain = this.chain
|
|
186
|
+
.then(async () => {
|
|
187
|
+
if (!this.closed)
|
|
188
|
+
await fn();
|
|
189
|
+
})
|
|
190
|
+
.catch((err) => {
|
|
191
|
+
this.d.log.warn("conversation stream failed; closing", {
|
|
192
|
+
conversationId: this.p.conversationId,
|
|
193
|
+
err,
|
|
194
|
+
});
|
|
195
|
+
this.close("abort");
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
/** 读 lastSeq 之后的全部事件并发送(按 seq 去重:只发大于已发送值的)。 */
|
|
199
|
+
async catchUp() {
|
|
200
|
+
for (;;) {
|
|
201
|
+
const evs = await this.d.eventLog.readAfter(this.p.conversationId, this.lastSeq, PAGE);
|
|
202
|
+
for (const e of evs) {
|
|
203
|
+
if (this.closed)
|
|
204
|
+
return;
|
|
205
|
+
if (e.seq <= this.lastSeq)
|
|
206
|
+
continue;
|
|
207
|
+
this.write(eventFrame(e));
|
|
208
|
+
this.lastSeq = e.seq;
|
|
209
|
+
}
|
|
210
|
+
if (evs.length < PAGE || this.closed)
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/** 发最后一帧错误并关闭(未发完的排队输出随关闭丢弃)。 */
|
|
215
|
+
fail(code) {
|
|
216
|
+
if (this.closed)
|
|
217
|
+
return;
|
|
218
|
+
try {
|
|
219
|
+
this.out.write(errorFrame(code));
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
// 连接已断开
|
|
223
|
+
}
|
|
224
|
+
this.close();
|
|
225
|
+
}
|
|
226
|
+
write(chunk) {
|
|
227
|
+
if (this.closed)
|
|
228
|
+
return;
|
|
229
|
+
this.out.write(chunk);
|
|
230
|
+
if (this.out.backlog() > MAX_BACKLOG_BYTES) {
|
|
231
|
+
this.d.log.warn("conversation stream client too slow; closing", {
|
|
232
|
+
conversationId: this.p.conversationId,
|
|
233
|
+
});
|
|
234
|
+
// end() 会把 FIN 排在未发出的数据之后,零窗口的客户端会一直占着连接与缓冲区:直接销毁
|
|
235
|
+
this.close("abort");
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* 复核凭据与可见性;失败时先发最后一帧 `event: error`(`data: {"code"}`)再关闭。
|
|
240
|
+
* 复核本身出错按失败关闭处理(`internal`)。
|
|
241
|
+
*/
|
|
242
|
+
async recheck() {
|
|
243
|
+
if (this.closed || this.rechecking)
|
|
244
|
+
return;
|
|
245
|
+
this.rechecking = true;
|
|
246
|
+
try {
|
|
247
|
+
const denied = await authorize(this.d, this.p);
|
|
248
|
+
if (denied !== null)
|
|
249
|
+
this.fail(denied);
|
|
250
|
+
}
|
|
251
|
+
catch (err) {
|
|
252
|
+
this.d.log.warn("conversation stream access re-check failed; closing", {
|
|
253
|
+
conversationId: this.p.conversationId,
|
|
254
|
+
err,
|
|
255
|
+
});
|
|
256
|
+
this.fail("internal");
|
|
257
|
+
}
|
|
258
|
+
finally {
|
|
259
|
+
this.rechecking = false;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { Logger } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import type { AppendEvent, EventLog } from "../../conversations/event-log.js";
|
|
3
|
+
import type { EventPayload } from "../../conversations/events.js";
|
|
4
|
+
import type { KernelDb } from "../../db/kernel-schema.js";
|
|
5
|
+
import type { RunAbort, RunAbortDetail } from "../abort.js";
|
|
6
|
+
import { type RunQueue } from "../run-queue.js";
|
|
7
|
+
import type { Waits } from "../waits.js";
|
|
8
|
+
/** Idempotency key of the parent's `subagent_finished` event. */
|
|
9
|
+
export declare const finishedIdemKey: (childRunId: string) => string;
|
|
10
|
+
/** A dispatch row, by its child run. */
|
|
11
|
+
export interface DispatchRow {
|
|
12
|
+
parentRunId: string;
|
|
13
|
+
parentCallId: string;
|
|
14
|
+
parentConversationId: string;
|
|
15
|
+
childConversationId: string;
|
|
16
|
+
childRunId: string;
|
|
17
|
+
}
|
|
18
|
+
/** The dispatch that started `childRunId`, or null (not a sub-agent run). */
|
|
19
|
+
export declare function dispatchOfChildRun(db: KernelDb, childRunId: string): Promise<DispatchRow | null>;
|
|
20
|
+
/** The dispatch of the parent call `(runId, callId)`, or null (not dispatched yet). */
|
|
21
|
+
export declare function dispatchOfCall(db: KernelDb, runId: string, callId: string): Promise<DispatchRow | null>;
|
|
22
|
+
/**
|
|
23
|
+
* The tool result of a finished child run (spec §4.4) and its `subagent_finished` payload, from
|
|
24
|
+
* the child's log only: the status from its terminal event, the reply from its last
|
|
25
|
+
* `assistant_message` (text blocks), the tool call count from its `tool_result` events, the usage
|
|
26
|
+
* from its `usage` events (compaction included) and the duration from `run_started` to the
|
|
27
|
+
* terminal event. Null while the run has no terminal event.
|
|
28
|
+
*
|
|
29
|
+
* `modelGiven`: the parent's call named a `model`; for an org agent, which runs on its own model
|
|
30
|
+
* (§5.4, §5.5), the status line then says `model: the agent's own`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function childResult(eventLog: EventLog, row: DispatchRow,
|
|
33
|
+
/** `forSkill`: a fork invocation's report (no resume hint, see `agentResultText`). */
|
|
34
|
+
opts?: {
|
|
35
|
+
modelGiven?: boolean;
|
|
36
|
+
forSkill?: boolean;
|
|
37
|
+
}): Promise<{
|
|
38
|
+
content: string;
|
|
39
|
+
isError: boolean;
|
|
40
|
+
finished: EventPayload<"subagent_finished">;
|
|
41
|
+
} | null>;
|
|
42
|
+
/** The parent's `subagent_finished` event for a finished child (idempotent by its key). */
|
|
43
|
+
export declare const finishedEvent: (row: DispatchRow, finished: EventPayload<"subagent_finished">) => AppendEvent;
|
|
44
|
+
export interface ChildDeps {
|
|
45
|
+
db: KernelDb;
|
|
46
|
+
eventLog: EventLog;
|
|
47
|
+
waits: Pick<Waits, "resume">;
|
|
48
|
+
log: Pick<Logger, "warn">;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* After a child run's terminal state committed (spec §7.3): appends `subagent_finished` to the
|
|
52
|
+
* parent log (idempotent; allowed while the parent waits, it is not model-visible) and tries
|
|
53
|
+
* `Waits.resume(parentRunId, childRunId)`. Every finishing child tries; the conditional resume lets
|
|
54
|
+
* exactly one succeed, the last to see all its siblings terminal. A run that is not a dispatched
|
|
55
|
+
* child, or not terminal yet, is left alone. A crash in between is repaired by the wait sweep and
|
|
56
|
+
* by the parent's tools node, which writes a missing `subagent_finished` itself.
|
|
57
|
+
*/
|
|
58
|
+
export declare function onChildFinished(d: ChildDeps, childRunId: string): Promise<void>;
|
|
59
|
+
export interface StopChildrenDeps extends ChildDeps {
|
|
60
|
+
waits: Pick<Waits, "resume" | "abortWaiting">;
|
|
61
|
+
runQueue: Pick<RunQueue, "abortIfOrphaned">;
|
|
62
|
+
abort: Pick<RunAbort, "request">;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Stops the active children of a parent run (sub-agents spec §12), or only those dispatched in
|
|
66
|
+
* `opts.step`: a `waiting` child through its own `abortWaiting`, a `queued` / `running` one that
|
|
67
|
+
* no worker holds directly (`abortIfOrphaned`), any other through `RunAbort.request` (the
|
|
68
|
+
* cross-replica broadcast plus the marker key, so a child that starts later still sees it), after
|
|
69
|
+
* which a child found `waiting` is stopped through `abortWaiting` too. A child stopped here is
|
|
70
|
+
* reported to the parent at once (by `abortWaiting` itself, or {@link onChildFinished} after
|
|
71
|
+
* `abortIfOrphaned`); one stopped by its worker is reported by that worker. Returns the number of
|
|
72
|
+
* children asked to stop.
|
|
73
|
+
*
|
|
74
|
+
* `byAccountId` is the person whose action stops them, or null when the kernel stops them on the
|
|
75
|
+
* parent's behalf; a child stopped with null reports the §4.4 "parent's stop" text.
|
|
76
|
+
*/
|
|
77
|
+
export declare function stopChildren(d: StopChildrenDeps, parentRunId: string, byAccountId: string | null, opts?: {
|
|
78
|
+
step?: number;
|
|
79
|
+
detail?: RunAbortDetail;
|
|
80
|
+
}): Promise<number>;
|