@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,31 @@
|
|
|
1
|
+
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import type { KernelConfig } from "../../config/schema.js";
|
|
4
|
+
import { type Principal } from "../../identity/principal.js";
|
|
5
|
+
import { type OrgContext } from "../../orgs/org.guard.js";
|
|
6
|
+
import { type OAuthFlow } from "./flow.js";
|
|
7
|
+
declare const ConnectBody: z.ZodObject<{
|
|
8
|
+
returnTo: z.ZodOptional<z.ZodString>;
|
|
9
|
+
}, z.core.$strict>;
|
|
10
|
+
/**
|
|
11
|
+
* 发起 OAuth 连接(`POST /orgs/:orgId/connectors/:connectorId/connect`,`connectors.use`,仅用户主体):返回授权 URL,并写浏览器绑定
|
|
12
|
+
* Cookie `cap_oauth`(HttpOnly、SameSite=Lax——授权服务器回跳是跨站顶级 GET 导航、Lax 会带上;Path 只到回调)。
|
|
13
|
+
*/
|
|
14
|
+
export declare class OAuthConnectController {
|
|
15
|
+
private readonly flow;
|
|
16
|
+
private readonly config;
|
|
17
|
+
constructor(flow: OAuthFlow, config: () => KernelConfig);
|
|
18
|
+
connect(principal: Principal, org: OrgContext, connectorId: string, body: z.infer<typeof ConnectBody>, req: FastifyRequest, reply: FastifyReply): Promise<{
|
|
19
|
+
authorizationUrl: string;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 授权服务器的回跳(`GET /api/v1/oauth/callback`,公开路由:浏览器从授权服务器跳回来,会话 Cookie 可能已过期;
|
|
24
|
+
* 身份由 state 与浏览器绑定 Cookie 确定)。总是 302 回网页,结果放在 `connected` / `oauth_error` 参数里。
|
|
25
|
+
*/
|
|
26
|
+
export declare class OAuthCallbackController {
|
|
27
|
+
private readonly flow;
|
|
28
|
+
constructor(flow: OAuthFlow);
|
|
29
|
+
callback(q: Record<string, unknown>, req: FastifyRequest, reply: FastifyReply): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
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 { Body, Controller, Get, HttpCode, Inject, Param, Post, Query, Req, Res, } from "@nestjs/common";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import { KERNEL_CONFIG, OAUTH_FLOW } from "../../http/tokens.js";
|
|
13
|
+
import { ZodPipe } from "../../http/zod.pipe.js";
|
|
14
|
+
import { CurrentPrincipal, Public, requireUser } from "../../identity/principal.js";
|
|
15
|
+
import { CurrentOrg, OrgAction } from "../../orgs/org.guard.js";
|
|
16
|
+
import { browserBinding, isSafeReturnPath, OAUTH_BINDING_COOKIE, OAUTH_CALLBACK_PATH, OAUTH_STATE_TTL_SECONDS, } from "./flow.js";
|
|
17
|
+
const ConnectBody = z
|
|
18
|
+
.object({
|
|
19
|
+
returnTo: z
|
|
20
|
+
.string()
|
|
21
|
+
.max(500)
|
|
22
|
+
.refine(isSafeReturnPath, { message: "returnTo must be a relative path on this site" })
|
|
23
|
+
.optional(),
|
|
24
|
+
})
|
|
25
|
+
.strict();
|
|
26
|
+
/** 查询参数只取单值字符串(重复参数 / 数组按缺失处理)。 */
|
|
27
|
+
const one = (v) => typeof v === "string" && v.length <= 4096 ? v : undefined;
|
|
28
|
+
/**
|
|
29
|
+
* 发起 OAuth 连接(`POST /orgs/:orgId/connectors/:connectorId/connect`,`connectors.use`,仅用户主体):返回授权 URL,并写浏览器绑定
|
|
30
|
+
* Cookie `cap_oauth`(HttpOnly、SameSite=Lax——授权服务器回跳是跨站顶级 GET 导航、Lax 会带上;Path 只到回调)。
|
|
31
|
+
*/
|
|
32
|
+
let OAuthConnectController = class OAuthConnectController {
|
|
33
|
+
flow;
|
|
34
|
+
config;
|
|
35
|
+
constructor(flow, config) {
|
|
36
|
+
this.flow = flow;
|
|
37
|
+
this.config = config;
|
|
38
|
+
}
|
|
39
|
+
async connect(principal, org, connectorId, body, req, reply) {
|
|
40
|
+
const p = requireUser(principal);
|
|
41
|
+
const binding = browserBinding(req.cookies[OAUTH_BINDING_COOKIE]);
|
|
42
|
+
const out = await this.flow.start(org.orgId, connectorId, p.account.id, body.returnTo, binding);
|
|
43
|
+
reply.setCookie(OAUTH_BINDING_COOKIE, binding, {
|
|
44
|
+
path: OAUTH_CALLBACK_PATH,
|
|
45
|
+
httpOnly: true,
|
|
46
|
+
sameSite: "lax",
|
|
47
|
+
secure: this.config().auth.cookieSecure,
|
|
48
|
+
maxAge: OAUTH_STATE_TTL_SECONDS,
|
|
49
|
+
});
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
__decorate([
|
|
54
|
+
Post(":connectorId/connect"),
|
|
55
|
+
HttpCode(200),
|
|
56
|
+
OrgAction("connectors.use"),
|
|
57
|
+
__param(0, CurrentPrincipal()),
|
|
58
|
+
__param(1, CurrentOrg()),
|
|
59
|
+
__param(2, Param("connectorId")),
|
|
60
|
+
__param(3, Body(new ZodPipe(ConnectBody))),
|
|
61
|
+
__param(4, Req()),
|
|
62
|
+
__param(5, Res({ passthrough: true }))
|
|
63
|
+
], OAuthConnectController.prototype, "connect", null);
|
|
64
|
+
OAuthConnectController = __decorate([
|
|
65
|
+
Controller("api/v1/orgs/:orgId/connectors"),
|
|
66
|
+
__param(0, Inject(OAUTH_FLOW)),
|
|
67
|
+
__param(1, Inject(KERNEL_CONFIG))
|
|
68
|
+
], OAuthConnectController);
|
|
69
|
+
export { OAuthConnectController };
|
|
70
|
+
/**
|
|
71
|
+
* 授权服务器的回跳(`GET /api/v1/oauth/callback`,公开路由:浏览器从授权服务器跳回来,会话 Cookie 可能已过期;
|
|
72
|
+
* 身份由 state 与浏览器绑定 Cookie 确定)。总是 302 回网页,结果放在 `connected` / `oauth_error` 参数里。
|
|
73
|
+
*/
|
|
74
|
+
let OAuthCallbackController = class OAuthCallbackController {
|
|
75
|
+
flow;
|
|
76
|
+
constructor(flow) {
|
|
77
|
+
this.flow = flow;
|
|
78
|
+
}
|
|
79
|
+
async callback(q, req, reply) {
|
|
80
|
+
const location = await this.flow.callback({ code: one(q.code), state: one(q.state), error: one(q.error), iss: one(q.iss) }, req.cookies[OAUTH_BINDING_COOKIE]);
|
|
81
|
+
await reply.header("cache-control", "no-store").redirect(location, 302);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
__decorate([
|
|
85
|
+
Get("callback"),
|
|
86
|
+
Public(),
|
|
87
|
+
__param(0, Query()),
|
|
88
|
+
__param(1, Req()),
|
|
89
|
+
__param(2, Res())
|
|
90
|
+
], OAuthCallbackController.prototype, "callback", null);
|
|
91
|
+
OAuthCallbackController = __decorate([
|
|
92
|
+
Controller("api/v1/oauth"),
|
|
93
|
+
__param(0, Inject(OAUTH_FLOW))
|
|
94
|
+
], OAuthCallbackController);
|
|
95
|
+
export { OAuthCallbackController };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { Logger } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { ToolError } from "@capybara-hq/plugin-sdk";
|
|
3
|
+
import type { Redis } from "ioredis";
|
|
4
|
+
import { type OAuthHttpOptions } from "./discovery.js";
|
|
5
|
+
export type TokenAuthMethod = "client_secret_basic" | "client_secret_post" | "none";
|
|
6
|
+
/**
|
|
7
|
+
* 一个连接器的 OAuth 客户端(组织级凭据,键 `credentials:app:<connectorId>:client`):DCR 注册所得或管理员手填,
|
|
8
|
+
* 连同发现得到的端点与资源标识。
|
|
9
|
+
*/
|
|
10
|
+
export interface OAuthClientRecord {
|
|
11
|
+
clientId: string;
|
|
12
|
+
clientSecret?: string;
|
|
13
|
+
authMethod: TokenAuthMethod;
|
|
14
|
+
/** 授权码流才有。 */
|
|
15
|
+
authorizationEndpoint?: string;
|
|
16
|
+
tokenEndpoint: string;
|
|
17
|
+
/** RFC 8707 `resource` 参数(MCP 发现所得)。 */
|
|
18
|
+
resource?: string;
|
|
19
|
+
scopes?: string[];
|
|
20
|
+
/** 授权服务器标识(MCP 发现所得):回调带 RFC 9207 `iss` 时与它核对。 */
|
|
21
|
+
issuer?: string;
|
|
22
|
+
/** DCR 返回的注册信息(`registration_access_token` 为密钥)。 */
|
|
23
|
+
registration?: {
|
|
24
|
+
accessToken?: string;
|
|
25
|
+
clientUri?: string;
|
|
26
|
+
issuedAt?: number;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** 令牌(个人凭据:授权码流;组织凭据:客户端凭据流的缓存)。`expires_at` 为毫秒时间戳,null = 未告知。 */
|
|
30
|
+
export interface OAuthTokenRecord {
|
|
31
|
+
access_token: string;
|
|
32
|
+
refresh_token?: string;
|
|
33
|
+
expires_at: number | null;
|
|
34
|
+
token_type: string;
|
|
35
|
+
scope?: string;
|
|
36
|
+
}
|
|
37
|
+
export type OAuthOwner = {
|
|
38
|
+
kind: "org";
|
|
39
|
+
} | {
|
|
40
|
+
kind: "user";
|
|
41
|
+
accountId: string;
|
|
42
|
+
};
|
|
43
|
+
/** 令牌端点以 400 / 401 + RFC 6749 错误码明确拒绝(如 `invalid_grant`)。 */
|
|
44
|
+
export declare class OAuthGrantError extends Error {
|
|
45
|
+
readonly error: string;
|
|
46
|
+
constructor(error: string);
|
|
47
|
+
}
|
|
48
|
+
/** 这些错误码说明凭据本身已失效(refresh token / 客户端),只有它们才作废令牌。 */
|
|
49
|
+
export declare const INVALIDATING_ERRORS: ReadonlySet<string>;
|
|
50
|
+
/** 授权服务器暂时不可用(网络、超时、5xx、畸形响应):模型可见的英文说明,计入「服务不可用」。 */
|
|
51
|
+
export declare class OAuthUnavailable extends ToolError {
|
|
52
|
+
constructor(message?: string);
|
|
53
|
+
}
|
|
54
|
+
/** 刷新失败且已把凭据删除:需要(重新)连接。Credentials 把它换成 CredentialMissing。 */
|
|
55
|
+
export declare class OAuthReconnectRequired extends Error {
|
|
56
|
+
readonly owner: OAuthOwner;
|
|
57
|
+
constructor(owner: OAuthOwner);
|
|
58
|
+
}
|
|
59
|
+
/** access token 过期前多久就刷新。 */
|
|
60
|
+
export declare const REFRESH_MARGIN_MS = 60000;
|
|
61
|
+
/**
|
|
62
|
+
* 调令牌端点(RFC 6749 §3.2):按客户端认证方式带 client_id / secret(Basic 按 §2.3.1 先表单编码)。
|
|
63
|
+
* 400 / 401 且正文带可解析的 RFC 6749 `error` 码 → OAuthGrantError;其余(网络错误、超时、429、408、
|
|
64
|
+
* 403 等其他 4xx、没有错误码的 4xx、5xx、3xx、畸形响应)→ OAuthUnavailable——网关限流或 WAF 拦截不能当成凭据失效。
|
|
65
|
+
*/
|
|
66
|
+
export declare function tokenRequest(client: OAuthClientRecord, params: Record<string, string | undefined>, http: OAuthHttpOptions): Promise<OAuthTokenRecord>;
|
|
67
|
+
/** 令牌与客户端的存取(由 Credentials 实现:信封加密存入 capybara.secrets)。 */
|
|
68
|
+
export interface OAuthStore {
|
|
69
|
+
readClient(orgId: string, connectorId: string): Promise<OAuthClientRecord | null>;
|
|
70
|
+
readTokens(orgId: string, connectorId: string, owner: OAuthOwner): Promise<OAuthTokenRecord | null>;
|
|
71
|
+
writeTokens(orgId: string, connectorId: string, owner: OAuthOwner, rec: OAuthTokenRecord): Promise<void>;
|
|
72
|
+
deleteTokens(orgId: string, connectorId: string, owner: OAuthOwner): Promise<void>;
|
|
73
|
+
}
|
|
74
|
+
/** 取 token 所需的认证方式字段(与 credentials.ts 的 OAuthAuth 对应)。 */
|
|
75
|
+
export type TokenAuth = {
|
|
76
|
+
type: "oauth_code";
|
|
77
|
+
} | {
|
|
78
|
+
type: "oauth_client";
|
|
79
|
+
scopes?: string[] | undefined;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* access token 的获取与刷新。
|
|
83
|
+
*
|
|
84
|
+
* - 调用前:未过期(距过期 > 60 秒或未告知过期时间)直接用;否则刷新(授权码流用 refresh token,客户端凭据流重新取)。
|
|
85
|
+
* - 收到 401:`forceRefresh(stale)`——只要库里的 token 仍是收到 401 的那个就刷新。
|
|
86
|
+
* - 刷新一律在 Redis 锁 `capk:oauth-refresh:<orgId>:<connectorId>:<owner>` 内进行(SET NX PX,值为本次随机 id,
|
|
87
|
+
* 只删除自己持有的锁);拿不到锁的轮询等锁消失后重读凭据,库里已是别的 token 就直接用(不并发刷新——授权服务器
|
|
88
|
+
* 轮换 refresh token 时,并发刷新的第二个必然失败)。
|
|
89
|
+
* - 令牌端点明确拒绝 → 删除该凭据并抛 OAuthReconnectRequired(需要重新连接);暂时不可用 → OAuthUnavailable,凭据保留。
|
|
90
|
+
*/
|
|
91
|
+
export declare class OAuthTokens {
|
|
92
|
+
private readonly store;
|
|
93
|
+
private readonly redis;
|
|
94
|
+
private readonly http;
|
|
95
|
+
private readonly log;
|
|
96
|
+
constructor(store: OAuthStore, redis: Redis, http: () => OAuthHttpOptions, log: Logger);
|
|
97
|
+
accessToken(orgId: string, connectorId: string, auth: TokenAuth, owner: OAuthOwner): Promise<string>;
|
|
98
|
+
/** 收到 401 后调用:`stale` 为收到 401 的那个 access token。 */
|
|
99
|
+
forceRefresh(orgId: string, connectorId: string, auth: TokenAuth, owner: OAuthOwner, stale: string | undefined): Promise<void>;
|
|
100
|
+
private lockKey;
|
|
101
|
+
/**
|
|
102
|
+
* 换掉 `stale`(null = 库里还没有 token):锁内先重读,已被别人换掉就直接用;否则向令牌端点要新的。
|
|
103
|
+
* 锁的 TTL = 往返限时 + 5 秒,持有者崩溃后锁自然过期;等锁最多一个 TTL。
|
|
104
|
+
*/
|
|
105
|
+
private renew;
|
|
106
|
+
/**
|
|
107
|
+
* 锁内:向令牌端点要新 token 并写回。作废前做围栏检查:锁仍归自己、库里的 token 仍是这次用掉的那组——
|
|
108
|
+
* 锁过期后另一个刷新者若已写入新 token,就直接用它而不是删掉它。
|
|
109
|
+
*/
|
|
110
|
+
private obtain;
|
|
111
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { ToolError } from "@capybara-hq/plugin-sdk";
|
|
3
|
+
import { OAuthSetupError, oauthFetch } from "./discovery.js";
|
|
4
|
+
/** 令牌端点以 400 / 401 + RFC 6749 错误码明确拒绝(如 `invalid_grant`)。 */
|
|
5
|
+
export class OAuthGrantError extends Error {
|
|
6
|
+
error;
|
|
7
|
+
constructor(error) {
|
|
8
|
+
super(`The authorization server rejected the token request (${error})`);
|
|
9
|
+
this.error = error;
|
|
10
|
+
this.name = "OAuthGrantError";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** 这些错误码说明凭据本身已失效(refresh token / 客户端),只有它们才作废令牌。 */
|
|
14
|
+
export const INVALIDATING_ERRORS = new Set([
|
|
15
|
+
"invalid_grant",
|
|
16
|
+
"invalid_client",
|
|
17
|
+
"unauthorized_client",
|
|
18
|
+
]);
|
|
19
|
+
/** 授权服务器暂时不可用(网络、超时、5xx、畸形响应):模型可见的英文说明,计入「服务不可用」。 */
|
|
20
|
+
export class OAuthUnavailable extends ToolError {
|
|
21
|
+
constructor(message = "Could not obtain an access token: the app's authorization server is unavailable. Try again later.") {
|
|
22
|
+
super(message, { kind: "unavailable" });
|
|
23
|
+
this.name = "OAuthUnavailable";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** 刷新失败且已把凭据删除:需要(重新)连接。Credentials 把它换成 CredentialMissing。 */
|
|
27
|
+
export class OAuthReconnectRequired extends Error {
|
|
28
|
+
owner;
|
|
29
|
+
constructor(owner) {
|
|
30
|
+
super("The OAuth credential is invalid and must be connected again");
|
|
31
|
+
this.owner = owner;
|
|
32
|
+
this.name = "OAuthReconnectRequired";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** access token 过期前多久就刷新。 */
|
|
36
|
+
export const REFRESH_MARGIN_MS = 60_000;
|
|
37
|
+
/** 等锁时的轮询间隔(本进程自己的等待)。 */
|
|
38
|
+
const LOCK_POLL_MS = 50;
|
|
39
|
+
const isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
40
|
+
/** RFC 6749 §5.2 形式的错误码(只有这种串才写进日志 / 错误,不回显对方任意文本)。 */
|
|
41
|
+
const OAUTH_ERROR_RE = /^[a-z][a-z0-9_]{0,63}$/;
|
|
42
|
+
/**
|
|
43
|
+
* 调令牌端点(RFC 6749 §3.2):按客户端认证方式带 client_id / secret(Basic 按 §2.3.1 先表单编码)。
|
|
44
|
+
* 400 / 401 且正文带可解析的 RFC 6749 `error` 码 → OAuthGrantError;其余(网络错误、超时、429、408、
|
|
45
|
+
* 403 等其他 4xx、没有错误码的 4xx、5xx、3xx、畸形响应)→ OAuthUnavailable——网关限流或 WAF 拦截不能当成凭据失效。
|
|
46
|
+
*/
|
|
47
|
+
export async function tokenRequest(client, params, http) {
|
|
48
|
+
const form = new URLSearchParams();
|
|
49
|
+
for (const [k, v] of Object.entries(params))
|
|
50
|
+
if (v !== undefined && v !== "")
|
|
51
|
+
form.set(k, v);
|
|
52
|
+
const headers = {
|
|
53
|
+
"content-type": "application/x-www-form-urlencoded",
|
|
54
|
+
accept: "application/json",
|
|
55
|
+
};
|
|
56
|
+
if (client.authMethod === "client_secret_basic" && client.clientSecret !== undefined) {
|
|
57
|
+
const enc = (s) => encodeURIComponent(s).replace(/%20/g, "+");
|
|
58
|
+
headers.authorization = `Basic ${Buffer.from(`${enc(client.clientId)}:${enc(client.clientSecret)}`).toString("base64")}`;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
form.set("client_id", client.clientId);
|
|
62
|
+
if (client.authMethod === "client_secret_post" && client.clientSecret !== undefined) {
|
|
63
|
+
form.set("client_secret", client.clientSecret);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
let res;
|
|
67
|
+
try {
|
|
68
|
+
res = await oauthFetch(client.tokenEndpoint, { method: "POST", headers, body: form }, http);
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
if (e instanceof OAuthSetupError)
|
|
72
|
+
throw e;
|
|
73
|
+
throw new OAuthUnavailable();
|
|
74
|
+
}
|
|
75
|
+
let body;
|
|
76
|
+
try {
|
|
77
|
+
body = JSON.parse(res.text);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
body = undefined;
|
|
81
|
+
}
|
|
82
|
+
if (res.status === 400 || res.status === 401) {
|
|
83
|
+
const code = isObj(body) ? body.error : undefined;
|
|
84
|
+
if (typeof code === "string" && OAUTH_ERROR_RE.test(code))
|
|
85
|
+
throw new OAuthGrantError(code);
|
|
86
|
+
}
|
|
87
|
+
if (res.status !== 200 || !isObj(body))
|
|
88
|
+
throw new OAuthUnavailable();
|
|
89
|
+
const { access_token, refresh_token, expires_in, token_type, scope } = body;
|
|
90
|
+
if (typeof access_token !== "string" || access_token === "")
|
|
91
|
+
throw new OAuthUnavailable();
|
|
92
|
+
const type = typeof token_type === "string" ? token_type : "Bearer";
|
|
93
|
+
if (type.toLowerCase() !== "bearer")
|
|
94
|
+
throw new OAuthGrantError("unsupported_token_type");
|
|
95
|
+
return {
|
|
96
|
+
access_token,
|
|
97
|
+
...(typeof refresh_token === "string" && refresh_token !== "" && { refresh_token }),
|
|
98
|
+
expires_at: typeof expires_in === "number" && Number.isFinite(expires_in) && expires_in > 0
|
|
99
|
+
? Date.now() + expires_in * 1000
|
|
100
|
+
: null,
|
|
101
|
+
token_type: "Bearer",
|
|
102
|
+
...(typeof scope === "string" && { scope }),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
const RELEASE = `
|
|
106
|
+
if redis.call('GET', KEYS[1]) == ARGV[1] then
|
|
107
|
+
return redis.call('DEL', KEYS[1])
|
|
108
|
+
end
|
|
109
|
+
return 0
|
|
110
|
+
`;
|
|
111
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
112
|
+
/**
|
|
113
|
+
* access token 的获取与刷新。
|
|
114
|
+
*
|
|
115
|
+
* - 调用前:未过期(距过期 > 60 秒或未告知过期时间)直接用;否则刷新(授权码流用 refresh token,客户端凭据流重新取)。
|
|
116
|
+
* - 收到 401:`forceRefresh(stale)`——只要库里的 token 仍是收到 401 的那个就刷新。
|
|
117
|
+
* - 刷新一律在 Redis 锁 `capk:oauth-refresh:<orgId>:<connectorId>:<owner>` 内进行(SET NX PX,值为本次随机 id,
|
|
118
|
+
* 只删除自己持有的锁);拿不到锁的轮询等锁消失后重读凭据,库里已是别的 token 就直接用(不并发刷新——授权服务器
|
|
119
|
+
* 轮换 refresh token 时,并发刷新的第二个必然失败)。
|
|
120
|
+
* - 令牌端点明确拒绝 → 删除该凭据并抛 OAuthReconnectRequired(需要重新连接);暂时不可用 → OAuthUnavailable,凭据保留。
|
|
121
|
+
*/
|
|
122
|
+
export class OAuthTokens {
|
|
123
|
+
store;
|
|
124
|
+
redis;
|
|
125
|
+
http;
|
|
126
|
+
log;
|
|
127
|
+
constructor(store, redis, http, log) {
|
|
128
|
+
this.store = store;
|
|
129
|
+
this.redis = redis;
|
|
130
|
+
this.http = http;
|
|
131
|
+
this.log = log;
|
|
132
|
+
}
|
|
133
|
+
async accessToken(orgId, connectorId, auth, owner) {
|
|
134
|
+
const rec = await this.store.readTokens(orgId, connectorId, owner);
|
|
135
|
+
if (rec) {
|
|
136
|
+
const fresh = rec.expires_at === null || rec.expires_at - Date.now() > REFRESH_MARGIN_MS;
|
|
137
|
+
// 没有 refresh token 的授权码凭据无法提前刷新:照用,过期由服务端 401 → forceRefresh 处理
|
|
138
|
+
if (fresh || (auth.type === "oauth_code" && rec.refresh_token === undefined)) {
|
|
139
|
+
return rec.access_token;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else if (auth.type === "oauth_code") {
|
|
143
|
+
throw new OAuthReconnectRequired(owner);
|
|
144
|
+
}
|
|
145
|
+
return this.renew(orgId, connectorId, auth, owner, rec?.access_token ?? null);
|
|
146
|
+
}
|
|
147
|
+
/** 收到 401 后调用:`stale` 为收到 401 的那个 access token。 */
|
|
148
|
+
async forceRefresh(orgId, connectorId, auth, owner, stale) {
|
|
149
|
+
const current = stale ?? (await this.store.readTokens(orgId, connectorId, owner))?.access_token;
|
|
150
|
+
if (current === undefined && auth.type === "oauth_code")
|
|
151
|
+
throw new OAuthReconnectRequired(owner);
|
|
152
|
+
await this.renew(orgId, connectorId, auth, owner, current ?? null);
|
|
153
|
+
}
|
|
154
|
+
lockKey(orgId, connectorId, owner) {
|
|
155
|
+
return `capk:oauth-refresh:${orgId}:${connectorId}:${owner.kind === "org" ? "org" : owner.accountId}`;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* 换掉 `stale`(null = 库里还没有 token):锁内先重读,已被别人换掉就直接用;否则向令牌端点要新的。
|
|
159
|
+
* 锁的 TTL = 往返限时 + 5 秒,持有者崩溃后锁自然过期;等锁最多一个 TTL。
|
|
160
|
+
*/
|
|
161
|
+
async renew(orgId, connectorId, auth, owner, stale) {
|
|
162
|
+
const key = this.lockKey(orgId, connectorId, owner);
|
|
163
|
+
const ttlMs = this.http().timeoutMs + 5_000;
|
|
164
|
+
const deadline = Date.now() + ttlMs * 2;
|
|
165
|
+
const replaced = (rec) => rec !== null && rec.access_token !== stale ? rec.access_token : undefined;
|
|
166
|
+
for (;;) {
|
|
167
|
+
const id = randomUUID();
|
|
168
|
+
if ((await this.redis.set(key, id, "PX", ttlMs, "NX")) === "OK") {
|
|
169
|
+
try {
|
|
170
|
+
const rec = await this.store.readTokens(orgId, connectorId, owner);
|
|
171
|
+
const done = replaced(rec);
|
|
172
|
+
if (done !== undefined)
|
|
173
|
+
return done;
|
|
174
|
+
if (rec === null && auth.type === "oauth_code")
|
|
175
|
+
throw new OAuthReconnectRequired(owner);
|
|
176
|
+
return await this.obtain(orgId, connectorId, auth, owner, rec, key, id);
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
await this.redis.eval(RELEASE, 1, key, id).catch((err) => {
|
|
180
|
+
this.log.warn("oauth refresh lock release failed", { connectorId, err });
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// 别的副本 / 请求正在刷新:等锁消失后重读
|
|
185
|
+
while ((await this.redis.exists(key)) === 1 && Date.now() < deadline)
|
|
186
|
+
await sleep(LOCK_POLL_MS);
|
|
187
|
+
const rec = await this.store.readTokens(orgId, connectorId, owner);
|
|
188
|
+
const done = replaced(rec);
|
|
189
|
+
if (done !== undefined)
|
|
190
|
+
return done;
|
|
191
|
+
if (rec === null && auth.type === "oauth_code")
|
|
192
|
+
throw new OAuthReconnectRequired(owner);
|
|
193
|
+
if (Date.now() >= deadline)
|
|
194
|
+
throw new OAuthUnavailable();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* 锁内:向令牌端点要新 token 并写回。作废前做围栏检查:锁仍归自己、库里的 token 仍是这次用掉的那组——
|
|
199
|
+
* 锁过期后另一个刷新者若已写入新 token,就直接用它而不是删掉它。
|
|
200
|
+
*/
|
|
201
|
+
async obtain(orgId, connectorId, auth, owner, rec, lockKey, lockId) {
|
|
202
|
+
const client = await this.store.readClient(orgId, connectorId);
|
|
203
|
+
if (!client)
|
|
204
|
+
throw new OAuthReconnectRequired({ kind: "org" });
|
|
205
|
+
const invalidate = async (reason) => {
|
|
206
|
+
const current = await this.store.readTokens(orgId, connectorId, owner);
|
|
207
|
+
const unchanged = current !== null &&
|
|
208
|
+
rec !== null &&
|
|
209
|
+
current.access_token === rec.access_token &&
|
|
210
|
+
current.refresh_token === rec.refresh_token;
|
|
211
|
+
if (current !== null && !unchanged)
|
|
212
|
+
return current.access_token;
|
|
213
|
+
if (current !== null && (await this.redis.get(lockKey)) !== lockId) {
|
|
214
|
+
// 锁已不归自己(过期):不删,交给持锁者;这次按暂时不可用处理
|
|
215
|
+
throw new OAuthUnavailable();
|
|
216
|
+
}
|
|
217
|
+
if (current !== null)
|
|
218
|
+
await this.store.deleteTokens(orgId, connectorId, owner);
|
|
219
|
+
this.log.warn("oauth credential invalidated", { connectorId, owner: owner.kind, reason });
|
|
220
|
+
throw new OAuthReconnectRequired(owner);
|
|
221
|
+
};
|
|
222
|
+
let next;
|
|
223
|
+
try {
|
|
224
|
+
if (auth.type === "oauth_code") {
|
|
225
|
+
if (rec?.refresh_token === undefined)
|
|
226
|
+
return await invalidate("no_refresh_token");
|
|
227
|
+
next = await tokenRequest(client, {
|
|
228
|
+
grant_type: "refresh_token",
|
|
229
|
+
refresh_token: rec.refresh_token,
|
|
230
|
+
resource: client.resource,
|
|
231
|
+
}, this.http());
|
|
232
|
+
// 授权服务器不轮换时沿用旧 refresh token
|
|
233
|
+
if (next.refresh_token === undefined)
|
|
234
|
+
next = { ...next, refresh_token: rec.refresh_token };
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
const scopes = auth.scopes ?? client.scopes;
|
|
238
|
+
next = await tokenRequest(client, { grant_type: "client_credentials", scope: scopes?.join(" "), resource: client.resource }, this.http());
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
catch (e) {
|
|
242
|
+
if (e instanceof OAuthGrantError) {
|
|
243
|
+
if (INVALIDATING_ERRORS.has(e.error))
|
|
244
|
+
return invalidate(e.error);
|
|
245
|
+
// invalid_scope / invalid_request 等:配置问题,凭据保留
|
|
246
|
+
this.log.warn("oauth token request rejected", { connectorId, error: e.error });
|
|
247
|
+
throw new OAuthUnavailable(`Could not obtain an access token: the authorization server rejected the request (${e.error}). Ask an administrator to check the app.`);
|
|
248
|
+
}
|
|
249
|
+
if (e instanceof OAuthUnavailable)
|
|
250
|
+
throw e;
|
|
251
|
+
// URL 校验失败等(配置问题):按不可用处理,不删凭据
|
|
252
|
+
this.log.warn("oauth token request failed", { connectorId, err: e });
|
|
253
|
+
throw new OAuthUnavailable();
|
|
254
|
+
}
|
|
255
|
+
await this.store.writeTokens(orgId, connectorId, owner, next);
|
|
256
|
+
return next.access_token;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { KernelConfig } from "../config/schema.js";
|
|
2
|
+
import type { KernelDb } from "../db/kernel-schema.js";
|
|
3
|
+
/** 文本行数(按 `\n` 切分;空串算 1 行,与按行分页读取一致)。 */
|
|
4
|
+
export declare function countLines(s: string): number;
|
|
5
|
+
export interface SavedOutput {
|
|
6
|
+
id: string;
|
|
7
|
+
sizeChars: number;
|
|
8
|
+
lineCount: number;
|
|
9
|
+
}
|
|
10
|
+
/** 读存档的范围:只能读产生它的那个会话(且组织一致)的存档。 */
|
|
11
|
+
export interface OutputScope {
|
|
12
|
+
orgId: string;
|
|
13
|
+
conversationId: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 输出存档(spec 5.4):超大工具结果的全文存进 `capybara.tool_outputs`,保留 `tools.outputRetentionDays` 天。
|
|
17
|
+
* 只能在产生它的会话里读取(同组织别的会话也不行:会话之间可见范围不同),过期即视为不存在(清理由维护任务负责)。
|
|
18
|
+
*/
|
|
19
|
+
export declare class ToolOutputs {
|
|
20
|
+
private readonly db;
|
|
21
|
+
private readonly config;
|
|
22
|
+
constructor(db: KernelDb, config: () => KernelConfig);
|
|
23
|
+
save(a: {
|
|
24
|
+
orgId: string;
|
|
25
|
+
conversationId: string;
|
|
26
|
+
callId: string;
|
|
27
|
+
content: string;
|
|
28
|
+
}): Promise<SavedOutput>;
|
|
29
|
+
/** 读本会话未过期的存档全文;不存在 / 过期 / 属于别的会话或组织 → null。 */
|
|
30
|
+
load(scope: OutputScope, id: string): Promise<string | null>;
|
|
31
|
+
}
|
|
32
|
+
/** 存档不存在 / 过期 / 不属于本会话(模型可见,英文;不区分几种情况,不泄露别处的存档是否存在)。 */
|
|
33
|
+
export declare const outputNotFoundText: (id: string) => string;
|
|
34
|
+
/**
|
|
35
|
+
* 管线第 1 阶段:把参数中任意位置的 `{"$output": "<id>"}`(对象恰好只有这一个键)替换为该存档全文。
|
|
36
|
+
* 不存在 / 过期 / 不属于本会话 → `ToolError`(给模型看的英文)。不修改传入的对象。
|
|
37
|
+
*/
|
|
38
|
+
export declare function resolveOutputRefs(input: unknown, load: (id: string) => Promise<string | null>): Promise<unknown>;
|
|
39
|
+
export interface RenderedResult {
|
|
40
|
+
/** 模型看到的文本(尚未转存)。 */
|
|
41
|
+
text: string;
|
|
42
|
+
/** 结果里出现的内容类型(按首次出现的顺序)。 */
|
|
43
|
+
contentTypes: string[];
|
|
44
|
+
isError: boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 管线第 5 阶段(渲染):文本块按行拼接;图片 → `[image <mimeType>, <n> bytes]`(M3 不把图片回传模型);
|
|
48
|
+
* `resource_link` → `[resource <uri>]`;未知块 → `[unsupported content <type>]`。
|
|
49
|
+
* 畸形结果(不是对象、content 不是数组)给出说明并标为错误,不抛错(Review Focus 5)。
|
|
50
|
+
*/
|
|
51
|
+
export declare function renderResult(result: unknown): RenderedResult;
|
|
52
|
+
/**
|
|
53
|
+
* 管线第 5 阶段(转存):超过 `spillChars` 的文本存为输出存档,模型只见前 `previewChars` 个字符与截断说明。
|
|
54
|
+
*/
|
|
55
|
+
export declare function spillIfLarge(text: string, opts: {
|
|
56
|
+
spillChars: number;
|
|
57
|
+
previewChars: number;
|
|
58
|
+
}, save: (content: string) => Promise<SavedOutput>): Promise<{
|
|
59
|
+
content: string;
|
|
60
|
+
outputId?: string;
|
|
61
|
+
}>;
|