@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,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 部署级插件配置某个字段的来源(D8 / C10):启动配置文件、Nacos,或环境变量(优先级最高)。
|
|
3
|
+
* 这些来源里有的字段在后台只读;PG 里的值(`db`)与 schema 默认值优先级更低。
|
|
4
|
+
*/
|
|
5
|
+
export type ConfigSourceKind = "file" | "nacos" | "env";
|
|
6
|
+
/**
|
|
7
|
+
* 启动配置里各插件部署配置的来源:`raw` 是配置来源(文件 / Nacos,`kind`)读出的原始对象,`env` 里
|
|
8
|
+
* `CAPYBARA_EXTENSION_CONFIG*` 推导出的覆盖(逐字段或整段 JSON)记为 `env`(优先级最高,覆盖同一路径的文件来源)。
|
|
9
|
+
* 返回插件名 → 叶子点路径 → 来源。只看路径,不含值。
|
|
10
|
+
*/
|
|
11
|
+
export declare function extensionConfigSources(raw: unknown, env: NodeJS.ProcessEnv, kind: "file" | "nacos"): Record<string, Record<string, ConfigSourceKind>>;
|
|
12
|
+
/** `CAPYBARA_CONFIG_SOURCE` 对应的来源种类(默认 file)。 */
|
|
13
|
+
export declare function configSourceKind(env: NodeJS.ProcessEnv): "file" | "nacos";
|
|
14
|
+
/**
|
|
15
|
+
* 某个配置字段(点路径)是否出现在来源里:来源路径等于它、在它下面(字段是 record / 数组等整体叶子),
|
|
16
|
+
* 或是它的祖先(来源在上层给了非对象值)。环境变量优先。返回来源种类,没有返回 undefined。
|
|
17
|
+
*/
|
|
18
|
+
export declare function fieldSource(sources: Record<string, ConfigSourceKind> | undefined, field: string): ConfigSourceKind | undefined;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { envOverrides } from "./env.js";
|
|
2
|
+
const isPlainObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
3
|
+
/** 把一份插件配置展开成叶子点路径(对象递归;数组、null 与标量是叶子;空对象没有叶子)。 */
|
|
4
|
+
function leafPaths(value, prefix, out) {
|
|
5
|
+
if (isPlainObject(value)) {
|
|
6
|
+
for (const [k, v] of Object.entries(value))
|
|
7
|
+
leafPaths(v, prefix ? `${prefix}.${k}` : k, out);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (prefix !== "")
|
|
11
|
+
out.push(prefix);
|
|
12
|
+
}
|
|
13
|
+
function mark(out, extensionConfig, kind) {
|
|
14
|
+
if (!isPlainObject(extensionConfig))
|
|
15
|
+
return;
|
|
16
|
+
for (const [plugin, value] of Object.entries(extensionConfig)) {
|
|
17
|
+
const paths = [];
|
|
18
|
+
leafPaths(value, "", paths);
|
|
19
|
+
if (paths.length === 0)
|
|
20
|
+
continue;
|
|
21
|
+
const target = out[plugin] ?? {};
|
|
22
|
+
out[plugin] = target;
|
|
23
|
+
for (const p of paths)
|
|
24
|
+
target[p] = kind;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 启动配置里各插件部署配置的来源:`raw` 是配置来源(文件 / Nacos,`kind`)读出的原始对象,`env` 里
|
|
29
|
+
* `CAPYBARA_EXTENSION_CONFIG*` 推导出的覆盖(逐字段或整段 JSON)记为 `env`(优先级最高,覆盖同一路径的文件来源)。
|
|
30
|
+
* 返回插件名 → 叶子点路径 → 来源。只看路径,不含值。
|
|
31
|
+
*/
|
|
32
|
+
export function extensionConfigSources(raw, env, kind) {
|
|
33
|
+
const out = {};
|
|
34
|
+
if (isPlainObject(raw))
|
|
35
|
+
mark(out, raw.extensionConfig, kind);
|
|
36
|
+
mark(out, envOverrides(env).extensionConfig, "env");
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
/** `CAPYBARA_CONFIG_SOURCE` 对应的来源种类(默认 file)。 */
|
|
40
|
+
export function configSourceKind(env) {
|
|
41
|
+
return env.CAPYBARA_CONFIG_SOURCE === "nacos" ? "nacos" : "file";
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 某个配置字段(点路径)是否出现在来源里:来源路径等于它、在它下面(字段是 record / 数组等整体叶子),
|
|
45
|
+
* 或是它的祖先(来源在上层给了非对象值)。环境变量优先。返回来源种类,没有返回 undefined。
|
|
46
|
+
*/
|
|
47
|
+
export function fieldSource(sources, field) {
|
|
48
|
+
if (!sources)
|
|
49
|
+
return undefined;
|
|
50
|
+
let found;
|
|
51
|
+
for (const [p, kind] of Object.entries(sources)) {
|
|
52
|
+
if (p === field || p.startsWith(`${field}.`) || field.startsWith(`${p}.`)) {
|
|
53
|
+
if (kind === "env")
|
|
54
|
+
return "env";
|
|
55
|
+
found = kind;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return found;
|
|
59
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** 配置来源:`load` 取原始配置,`watch` 可选地订阅变更并返回取消函数;`onError` 接收监听过程中的(已脱敏)错误。 */
|
|
2
|
+
export interface ConfigSource {
|
|
3
|
+
load(): Promise<unknown>;
|
|
4
|
+
watch?(onChange: (raw: unknown) => void, onError?: (err: Error) => void): () => void;
|
|
5
|
+
}
|
|
6
|
+
/** 配置加载或校验失败。 */
|
|
7
|
+
export declare class ConfigError extends Error {
|
|
8
|
+
constructor(message: string);
|
|
9
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { KernelDb } from "../db/kernel-schema.js";
|
|
2
|
+
import type { StorageService } from "../storage/storage.service.js";
|
|
3
|
+
/** 产物下载跳转的预签名有效期(秒)。 */
|
|
4
|
+
export declare const ARTIFACT_DOWNLOAD_TTL_SECONDS = 300;
|
|
5
|
+
/** 下载 302 的 `Cache-Control: private, max-age=…`(秒),不长于预签名有效期。 */
|
|
6
|
+
export declare const ARTIFACT_DOWNLOAD_CACHE_SECONDS = 60;
|
|
7
|
+
/** 文本预览最多读取的字节数(从对象开头按 Range 读)。 */
|
|
8
|
+
export declare const ARTIFACT_PREVIEW_MAX_BYTES = 8192;
|
|
9
|
+
/** 文本预览最多的行数。 */
|
|
10
|
+
export declare const ARTIFACT_PREVIEW_MAX_LINES = 40;
|
|
11
|
+
/** 产物能否以 `inline` 在页面里显示(只有位图)。 */
|
|
12
|
+
export declare const isInlineArtifactType: (ct: string) => boolean;
|
|
13
|
+
/** 产物能否给文本预览(`text/*` 与常见的文本格式;SVG 不算)。 */
|
|
14
|
+
export declare function isTextArtifactType(ct: string): boolean;
|
|
15
|
+
/** 文本预览:开头若干行(纯文本,网页按纯文本显示,从不当 HTML 渲染)。 */
|
|
16
|
+
export interface ArtifactPreview {
|
|
17
|
+
text: string;
|
|
18
|
+
/** 只截取了开头(文件更长)。 */
|
|
19
|
+
truncated: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface ConversationArtifactsDeps {
|
|
22
|
+
db: KernelDb;
|
|
23
|
+
storage: Pick<StorageService, "kernel">;
|
|
24
|
+
/** 会话可见性(与会话 SSE 流同一判定:`ConversationsService.isAccessible`)。 */
|
|
25
|
+
isAccessible(orgId: string, conversationId: string, viewerAccountId: string): Promise<boolean>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 产物(M5 T8 / T11):agent 经 `sandbox_deliver` 交付的文件。先按会话流的规则判定会话可见
|
|
29
|
+
* (不可见 → `conversation.not_found`),再只在这个会话的日志里找 `artifact_created`
|
|
30
|
+
* (没有 → `conversation.artifact_not_found`)。
|
|
31
|
+
*
|
|
32
|
+
* - 下载:302 到预签名地址,默认 `attachment`(带交付时的文件名与类型);`inline` 只对位图生效
|
|
33
|
+
* (网页的缩略图),其余类型即使要求 inline 也仍是 `attachment`。
|
|
34
|
+
* - 文本预览:`text/*` 等文本类,按 Range 读开头 {@link ARTIFACT_PREVIEW_MAX_BYTES} 字节、
|
|
35
|
+
* 至多 {@link ARTIFACT_PREVIEW_MAX_LINES} 行,以 JSON 字符串返回(网页按纯文本显示);
|
|
36
|
+
* 其他类型、或读到的开头里有 NUL 字节(其实是二进制)→ `conversation.artifact_not_previewable`。
|
|
37
|
+
*
|
|
38
|
+
* 查找走 `conversation_events` 的主键 `(conversation_id, seq)` 前缀,在 SQL 里按 `type` 与
|
|
39
|
+
* `payload->>'artifactId'` 过滤、`LIMIT 1`(只扫这一个会话的事件,不在 JS 里扫日志;不加迁移)。
|
|
40
|
+
*/
|
|
41
|
+
export declare class ConversationArtifacts {
|
|
42
|
+
private readonly d;
|
|
43
|
+
constructor(d: ConversationArtifactsDeps);
|
|
44
|
+
private find;
|
|
45
|
+
downloadUrl(orgId: string, conversationId: string, viewerAccountId: string, artifactId: string, opts?: {
|
|
46
|
+
inline?: boolean;
|
|
47
|
+
}): Promise<{
|
|
48
|
+
url: string;
|
|
49
|
+
name: string;
|
|
50
|
+
}>;
|
|
51
|
+
preview(orgId: string, conversationId: string, viewerAccountId: string, artifactId: string): Promise<ArtifactPreview>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { sql } from "kysely";
|
|
2
|
+
import { ApiError } from "../errors.js";
|
|
3
|
+
import { UUID_RE } from "../ui/registry.js";
|
|
4
|
+
/** 产物下载跳转的预签名有效期(秒)。 */
|
|
5
|
+
export const ARTIFACT_DOWNLOAD_TTL_SECONDS = 300;
|
|
6
|
+
/** 下载 302 的 `Cache-Control: private, max-age=…`(秒),不长于预签名有效期。 */
|
|
7
|
+
export const ARTIFACT_DOWNLOAD_CACHE_SECONDS = 60;
|
|
8
|
+
/** 文本预览最多读取的字节数(从对象开头按 Range 读)。 */
|
|
9
|
+
export const ARTIFACT_PREVIEW_MAX_BYTES = 8192;
|
|
10
|
+
/** 文本预览最多的行数。 */
|
|
11
|
+
export const ARTIFACT_PREVIEW_MAX_LINES = 40;
|
|
12
|
+
/** 可以 `inline` 打开的类型:只有位图(SVG 能执行脚本,HTML 更不行,一律下载)。 */
|
|
13
|
+
const INLINE_TYPES = new Set(["image/png", "image/jpeg", "image/gif", "image/webp"]);
|
|
14
|
+
/** `text/*` 之外也给文本预览的类型。 */
|
|
15
|
+
const TEXT_TYPES = new Set([
|
|
16
|
+
"application/json",
|
|
17
|
+
"application/xml",
|
|
18
|
+
"application/yaml",
|
|
19
|
+
"application/sql",
|
|
20
|
+
]);
|
|
21
|
+
const baseType = (ct) => (ct.split(";")[0] ?? "").trim().toLowerCase();
|
|
22
|
+
/** 产物能否以 `inline` 在页面里显示(只有位图)。 */
|
|
23
|
+
export const isInlineArtifactType = (ct) => INLINE_TYPES.has(baseType(ct));
|
|
24
|
+
/** 产物能否给文本预览(`text/*` 与常见的文本格式;SVG 不算)。 */
|
|
25
|
+
export function isTextArtifactType(ct) {
|
|
26
|
+
const t = baseType(ct);
|
|
27
|
+
return t.startsWith("text/") || TEXT_TYPES.has(t);
|
|
28
|
+
}
|
|
29
|
+
const conversationNotFound = () => new ApiError("conversation.not_found", "Conversation not found");
|
|
30
|
+
const artifactNotFound = () => new ApiError("conversation.artifact_not_found", "Artifact not found");
|
|
31
|
+
/** 从流里读最多 `max` 字节(存储忽略 Range 时 body 可能是整个对象,读够就取消)。 */
|
|
32
|
+
async function readPrefix(body, max) {
|
|
33
|
+
const reader = body.getReader();
|
|
34
|
+
const out = new Uint8Array(max);
|
|
35
|
+
let n = 0;
|
|
36
|
+
try {
|
|
37
|
+
while (n < max) {
|
|
38
|
+
const { done, value } = await reader.read();
|
|
39
|
+
if (done)
|
|
40
|
+
break;
|
|
41
|
+
const take = Math.min(value.byteLength, max - n);
|
|
42
|
+
out.set(value.subarray(0, take), n);
|
|
43
|
+
n += take;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
await reader.cancel().catch(() => { });
|
|
48
|
+
}
|
|
49
|
+
return out.subarray(0, n);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 产物(M5 T8 / T11):agent 经 `sandbox_deliver` 交付的文件。先按会话流的规则判定会话可见
|
|
53
|
+
* (不可见 → `conversation.not_found`),再只在这个会话的日志里找 `artifact_created`
|
|
54
|
+
* (没有 → `conversation.artifact_not_found`)。
|
|
55
|
+
*
|
|
56
|
+
* - 下载:302 到预签名地址,默认 `attachment`(带交付时的文件名与类型);`inline` 只对位图生效
|
|
57
|
+
* (网页的缩略图),其余类型即使要求 inline 也仍是 `attachment`。
|
|
58
|
+
* - 文本预览:`text/*` 等文本类,按 Range 读开头 {@link ARTIFACT_PREVIEW_MAX_BYTES} 字节、
|
|
59
|
+
* 至多 {@link ARTIFACT_PREVIEW_MAX_LINES} 行,以 JSON 字符串返回(网页按纯文本显示);
|
|
60
|
+
* 其他类型、或读到的开头里有 NUL 字节(其实是二进制)→ `conversation.artifact_not_previewable`。
|
|
61
|
+
*
|
|
62
|
+
* 查找走 `conversation_events` 的主键 `(conversation_id, seq)` 前缀,在 SQL 里按 `type` 与
|
|
63
|
+
* `payload->>'artifactId'` 过滤、`LIMIT 1`(只扫这一个会话的事件,不在 JS 里扫日志;不加迁移)。
|
|
64
|
+
*/
|
|
65
|
+
export class ConversationArtifacts {
|
|
66
|
+
d;
|
|
67
|
+
constructor(d) {
|
|
68
|
+
this.d = d;
|
|
69
|
+
}
|
|
70
|
+
async find(orgId, conversationId, viewerAccountId, artifactId) {
|
|
71
|
+
if (!UUID_RE.test(conversationId))
|
|
72
|
+
throw conversationNotFound();
|
|
73
|
+
if (!(await this.d.isAccessible(orgId, conversationId, viewerAccountId))) {
|
|
74
|
+
throw conversationNotFound();
|
|
75
|
+
}
|
|
76
|
+
if (!UUID_RE.test(artifactId))
|
|
77
|
+
throw artifactNotFound();
|
|
78
|
+
const row = await this.d.db
|
|
79
|
+
.selectFrom("conversation_events")
|
|
80
|
+
.select("payload")
|
|
81
|
+
.where("conversation_id", "=", conversationId)
|
|
82
|
+
.where("type", "=", "artifact_created")
|
|
83
|
+
.where(sql `payload->>'artifactId'`, "=", artifactId)
|
|
84
|
+
.limit(1)
|
|
85
|
+
.executeTakeFirst();
|
|
86
|
+
if (!row)
|
|
87
|
+
throw artifactNotFound();
|
|
88
|
+
return row.payload;
|
|
89
|
+
}
|
|
90
|
+
async downloadUrl(orgId, conversationId, viewerAccountId, artifactId, opts = {}) {
|
|
91
|
+
const a = await this.find(orgId, conversationId, viewerAccountId, artifactId);
|
|
92
|
+
const store = this.d.storage.kernel(orgId);
|
|
93
|
+
if (!(await store.head(a.objectKey)))
|
|
94
|
+
throw artifactNotFound();
|
|
95
|
+
const inline = opts.inline === true && isInlineArtifactType(a.contentType);
|
|
96
|
+
const url = await store.presignGet(a.objectKey, {
|
|
97
|
+
ttlSeconds: ARTIFACT_DOWNLOAD_TTL_SECONDS,
|
|
98
|
+
downloadName: a.name,
|
|
99
|
+
disposition: inline ? "inline" : "attachment",
|
|
100
|
+
responseContentType: a.contentType,
|
|
101
|
+
});
|
|
102
|
+
return { url, name: a.name };
|
|
103
|
+
}
|
|
104
|
+
async preview(orgId, conversationId, viewerAccountId, artifactId) {
|
|
105
|
+
const a = await this.find(orgId, conversationId, viewerAccountId, artifactId);
|
|
106
|
+
if (!isTextArtifactType(a.contentType)) {
|
|
107
|
+
throw new ApiError("conversation.artifact_not_previewable", "Only text artifacts have a preview");
|
|
108
|
+
}
|
|
109
|
+
const got = await this.d.storage
|
|
110
|
+
.kernel(orgId)
|
|
111
|
+
.get(a.objectKey, { range: { start: 0, end: ARTIFACT_PREVIEW_MAX_BYTES - 1 } });
|
|
112
|
+
if (!got)
|
|
113
|
+
throw artifactNotFound();
|
|
114
|
+
const bytes = await readPrefix(got.body, ARTIFACT_PREVIEW_MAX_BYTES);
|
|
115
|
+
// 类型说是文本、内容却是二进制(有 NUL):不给预览,界面显示「不能预览」
|
|
116
|
+
if (bytes.includes(0)) {
|
|
117
|
+
throw new ApiError("conversation.artifact_not_previewable", "This artifact contains binary data and has no text preview");
|
|
118
|
+
}
|
|
119
|
+
// stream: true 丢掉被截断在末尾的半个多字节字符
|
|
120
|
+
let text = new TextDecoder("utf-8").decode(bytes, { stream: true });
|
|
121
|
+
let truncated = got.head.size > bytes.byteLength;
|
|
122
|
+
if (truncated) {
|
|
123
|
+
// 只读了开头:去掉最后不完整的一行
|
|
124
|
+
const nl = text.lastIndexOf("\n");
|
|
125
|
+
if (nl >= 0)
|
|
126
|
+
text = text.slice(0, nl);
|
|
127
|
+
}
|
|
128
|
+
const lines = text.split("\n");
|
|
129
|
+
if (text.endsWith("\n"))
|
|
130
|
+
lines.pop();
|
|
131
|
+
if (lines.length > ARTIFACT_PREVIEW_MAX_LINES) {
|
|
132
|
+
text = lines.slice(0, ARTIFACT_PREVIEW_MAX_LINES).join("\n");
|
|
133
|
+
truncated = true;
|
|
134
|
+
}
|
|
135
|
+
return { text, truncated };
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { FastifyReply } from "fastify";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { type Principal } from "../identity/principal.js";
|
|
4
|
+
import { type OrgContext } from "../orgs/org.guard.js";
|
|
5
|
+
import { type AttachmentLimits, type AttachmentsService, type AttachmentView, type CreatedAttachment } from "./attachments.service.js";
|
|
6
|
+
declare const CreateBody: z.ZodObject<{
|
|
7
|
+
name: z.ZodString;
|
|
8
|
+
contentType: z.ZodString;
|
|
9
|
+
size: z.ZodNumber;
|
|
10
|
+
}, z.core.$strict>;
|
|
11
|
+
/**
|
|
12
|
+
* 对话附件(`/api/v1/orgs/:orgId/attachments`,`agents.use`,只接受人类用户):
|
|
13
|
+
* 1. `POST /` 登记并取预签名上传(`upload.method` 为 `POST` 时按 multipart 表单:先放 `fields`,最后放 `file`);
|
|
14
|
+
* 2. 浏览器直传对象存储;
|
|
15
|
+
* 3. `POST /:id/finalize` 核对大小与类型;
|
|
16
|
+
* 4. 发消息时在 `files` 里引用 id。
|
|
17
|
+
* 下载 `GET /:id/download` 302 到预签名地址(`Cache-Control: private, max-age=60`)。上限 `GET /limits`(类型、单个大小、
|
|
18
|
+
* 每条条数、单次请求的媒体预算、存储是否可用,供网页预检;不需要对象存储)。没有对象存储时其余接口 503 `storage.unavailable`。
|
|
19
|
+
*/
|
|
20
|
+
export declare class AttachmentsController {
|
|
21
|
+
private readonly attachments;
|
|
22
|
+
constructor(attachments: AttachmentsService);
|
|
23
|
+
limits(principal: Principal): AttachmentLimits;
|
|
24
|
+
create(principal: Principal, org: OrgContext, body: z.infer<typeof CreateBody>): Promise<CreatedAttachment>;
|
|
25
|
+
finalize(principal: Principal, org: OrgContext, id: string): Promise<AttachmentView>;
|
|
26
|
+
download(principal: Principal, org: OrgContext, id: string, reply: FastifyReply): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
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 { hasControlChars, MEDIA_NAME_MAX_CHARS } from "@capybara-hq/plugin-sdk";
|
|
11
|
+
import { Body, Controller, Get, HttpCode, Inject, Param, Post, Res } from "@nestjs/common";
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
import { ATTACHMENTS } from "../http/tokens.js";
|
|
14
|
+
import { ZodPipe } from "../http/zod.pipe.js";
|
|
15
|
+
import { CurrentPrincipal, requireUser } from "../identity/principal.js";
|
|
16
|
+
import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
|
|
17
|
+
import { ATTACHMENT_DOWNLOAD_CACHE_SECONDS, } from "./attachments.service.js";
|
|
18
|
+
const CreateBody = z
|
|
19
|
+
.object({
|
|
20
|
+
name: z
|
|
21
|
+
.string()
|
|
22
|
+
.min(1)
|
|
23
|
+
.max(MEDIA_NAME_MAX_CHARS)
|
|
24
|
+
.refine((s) => !hasControlChars(s), "name must not contain control characters"),
|
|
25
|
+
contentType: z.string().min(1).max(200),
|
|
26
|
+
size: z.number().int().min(1).max(Number.MAX_SAFE_INTEGER),
|
|
27
|
+
})
|
|
28
|
+
.strict();
|
|
29
|
+
/**
|
|
30
|
+
* 对话附件(`/api/v1/orgs/:orgId/attachments`,`agents.use`,只接受人类用户):
|
|
31
|
+
* 1. `POST /` 登记并取预签名上传(`upload.method` 为 `POST` 时按 multipart 表单:先放 `fields`,最后放 `file`);
|
|
32
|
+
* 2. 浏览器直传对象存储;
|
|
33
|
+
* 3. `POST /:id/finalize` 核对大小与类型;
|
|
34
|
+
* 4. 发消息时在 `files` 里引用 id。
|
|
35
|
+
* 下载 `GET /:id/download` 302 到预签名地址(`Cache-Control: private, max-age=60`)。上限 `GET /limits`(类型、单个大小、
|
|
36
|
+
* 每条条数、单次请求的媒体预算、存储是否可用,供网页预检;不需要对象存储)。没有对象存储时其余接口 503 `storage.unavailable`。
|
|
37
|
+
*/
|
|
38
|
+
let AttachmentsController = class AttachmentsController {
|
|
39
|
+
attachments;
|
|
40
|
+
constructor(attachments) {
|
|
41
|
+
this.attachments = attachments;
|
|
42
|
+
}
|
|
43
|
+
limits(principal) {
|
|
44
|
+
requireUser(principal);
|
|
45
|
+
return this.attachments.limits();
|
|
46
|
+
}
|
|
47
|
+
async create(principal, org, body) {
|
|
48
|
+
const p = requireUser(principal);
|
|
49
|
+
return this.attachments.create(org.orgId, p.account.id, body);
|
|
50
|
+
}
|
|
51
|
+
async finalize(principal, org, id) {
|
|
52
|
+
const p = requireUser(principal);
|
|
53
|
+
return this.attachments.finalize(org.orgId, p.account.id, id);
|
|
54
|
+
}
|
|
55
|
+
async download(principal, org, id, reply) {
|
|
56
|
+
const p = requireUser(principal);
|
|
57
|
+
const location = await this.attachments.downloadUrl(org.orgId, p.account.id, id);
|
|
58
|
+
// 浏览器可在短时间内复用跳转(同一页面的缩略图);预签名有效期不短于这段时间
|
|
59
|
+
await reply
|
|
60
|
+
.header("cache-control", `private, max-age=${ATTACHMENT_DOWNLOAD_CACHE_SECONDS}`)
|
|
61
|
+
.redirect(location, 302);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
__decorate([
|
|
65
|
+
Get("limits"),
|
|
66
|
+
OrgAction("agents.use"),
|
|
67
|
+
__param(0, CurrentPrincipal())
|
|
68
|
+
], AttachmentsController.prototype, "limits", null);
|
|
69
|
+
__decorate([
|
|
70
|
+
Post(),
|
|
71
|
+
OrgAction("agents.use"),
|
|
72
|
+
__param(0, CurrentPrincipal()),
|
|
73
|
+
__param(1, CurrentOrg()),
|
|
74
|
+
__param(2, Body(new ZodPipe(CreateBody)))
|
|
75
|
+
], AttachmentsController.prototype, "create", null);
|
|
76
|
+
__decorate([
|
|
77
|
+
Post(":id/finalize"),
|
|
78
|
+
HttpCode(200),
|
|
79
|
+
OrgAction("agents.use"),
|
|
80
|
+
__param(0, CurrentPrincipal()),
|
|
81
|
+
__param(1, CurrentOrg()),
|
|
82
|
+
__param(2, Param("id"))
|
|
83
|
+
], AttachmentsController.prototype, "finalize", null);
|
|
84
|
+
__decorate([
|
|
85
|
+
Get(":id/download"),
|
|
86
|
+
OrgAction("agents.use"),
|
|
87
|
+
__param(0, CurrentPrincipal()),
|
|
88
|
+
__param(1, CurrentOrg()),
|
|
89
|
+
__param(2, Param("id")),
|
|
90
|
+
__param(3, Res())
|
|
91
|
+
], AttachmentsController.prototype, "download", null);
|
|
92
|
+
AttachmentsController = __decorate([
|
|
93
|
+
Controller("api/v1/orgs/:orgId/attachments"),
|
|
94
|
+
__param(0, Inject(ATTACHMENTS))
|
|
95
|
+
], AttachmentsController);
|
|
96
|
+
export { AttachmentsController };
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { type Logger, type PresignedUpload } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { type Transaction } from "kysely";
|
|
3
|
+
import type { KernelConfig } from "../config/schema.js";
|
|
4
|
+
import type { AttachmentPurpose, KernelDatabase, KernelDb } from "../db/kernel-schema.js";
|
|
5
|
+
import type { MediaBytes, MediaInfo } from "../runtime/context/build.js";
|
|
6
|
+
import type { StorageService } from "../storage/storage.service.js";
|
|
7
|
+
import type { LogContentBlock } from "./events.js";
|
|
8
|
+
type Trx = Transaction<KernelDatabase>;
|
|
9
|
+
/** 预签名上传的有效期(秒)。尽量短:表单在有效期内可被再次使用(内容替换由 etag 核对兜底)。 */
|
|
10
|
+
export declare const ATTACHMENT_UPLOAD_TTL_SECONDS = 300;
|
|
11
|
+
/** 下载跳转的预签名有效期(秒);不短于 {@link ATTACHMENT_DOWNLOAD_CACHE_SECONDS}(浏览器缓存的跳转仍可用)。 */
|
|
12
|
+
export declare const ATTACHMENT_DOWNLOAD_TTL_SECONDS = 300;
|
|
13
|
+
/** 下载 302 的 `Cache-Control: private, max-age=…`(秒):同一页面里缩略图可复用跳转地址。 */
|
|
14
|
+
export declare const ATTACHMENT_DOWNLOAD_CACHE_SECONDS = 60;
|
|
15
|
+
/** 同一账号在一个组织里最多的未 finalize 附件数(超过 → 429 `attachment.too_many_pending`)。 */
|
|
16
|
+
export declare const MAX_PENDING_ATTACHMENTS = 50;
|
|
17
|
+
/** 技能包 zip 的内容类型(上传时一律按它签名,finalize 时核对 zip 文件头)。 */
|
|
18
|
+
export declare const SKILL_PACKAGE_CONTENT_TYPE = "application/zip";
|
|
19
|
+
/** 技能包 zip 的大小上限(字节)。 */
|
|
20
|
+
export declare const SKILL_PACKAGE_UPLOAD_MAX_BYTES: number;
|
|
21
|
+
/** 同一账号在一个组织里最多的未 finalize 技能包上传数(与对话附件分开计数)。 */
|
|
22
|
+
export declare const MAX_PENDING_SKILL_PACKAGES = 5;
|
|
23
|
+
/**
|
|
24
|
+
* 技能包上传的过期时间(小时):没被 `POST /skills` 用掉的由清理任务删除(不跟对话附件的 `unboundTtlHours`);
|
|
25
|
+
* `POST /skills` 开始处理时再顺延这么久,处理期间不会被清理。
|
|
26
|
+
*/
|
|
27
|
+
export declare const SKILL_PACKAGE_TTL_HOURS = 1;
|
|
28
|
+
/**
|
|
29
|
+
* 技能包解出的文件在 `kernel/<orgId>/` 下的前缀:按上传 id,同一上传重试写到同一批键(幂等),
|
|
30
|
+
* 并发处理同一上传也不会互相覆盖出不同内容。版本行记下这个前缀(`skill_versions.object_prefix`)。
|
|
31
|
+
*/
|
|
32
|
+
export declare const skillFilesPrefix: (uploadId: string) => string;
|
|
33
|
+
/** 维护任务:清理过期未绑定的附件(任务名与 scheduler id 不含 `:`)。 */
|
|
34
|
+
export declare const ATTACHMENT_CLEANUP_JOB = "attachment-cleanup";
|
|
35
|
+
export declare const ATTACHMENT_CLEANUP_SCHEDULER_ID = "attachment-cleanup-hourly";
|
|
36
|
+
export declare const ATTACHMENT_CLEANUP_EVERY_MS = 3600000;
|
|
37
|
+
/** 附件元数据(finalize 的返回)。 */
|
|
38
|
+
export interface AttachmentView {
|
|
39
|
+
id: string;
|
|
40
|
+
name: string;
|
|
41
|
+
contentType: string;
|
|
42
|
+
size: number;
|
|
43
|
+
}
|
|
44
|
+
/** 附件上限(`GET /attachments/limits`):网页据此在上传前预检。 */
|
|
45
|
+
export interface AttachmentLimits {
|
|
46
|
+
/** 允许的内容类型。 */
|
|
47
|
+
types: string[];
|
|
48
|
+
/** 非图片的单个上限(字节)。 */
|
|
49
|
+
maxBytes: number;
|
|
50
|
+
/** 图片的单个上限(字节,另受 `MEDIA_LIMITS.imageBytes` 限制)。 */
|
|
51
|
+
imageMaxBytes: number;
|
|
52
|
+
/** 单条消息最多附件数。 */
|
|
53
|
+
maxPerMessage: number;
|
|
54
|
+
/** 单次模型请求里媒体原始字节的预算(网页据此在发送前提醒总大小)。 */
|
|
55
|
+
requestMediaBytes: number;
|
|
56
|
+
/** 部署是否配置了对象存储;为 false 时上传不可用。 */
|
|
57
|
+
available: boolean;
|
|
58
|
+
}
|
|
59
|
+
/** {@link AttachmentsService.openForConversation} 的结果。 */
|
|
60
|
+
export interface OpenedAttachment {
|
|
61
|
+
name: string;
|
|
62
|
+
contentType: string;
|
|
63
|
+
size: number;
|
|
64
|
+
body: ReadableStream<Uint8Array>;
|
|
65
|
+
}
|
|
66
|
+
/** `POST /attachments` 的返回:浏览器按 `upload` 直传存储,然后调 finalize。 */
|
|
67
|
+
export interface CreatedAttachment {
|
|
68
|
+
id: string;
|
|
69
|
+
upload: PresignedUpload;
|
|
70
|
+
/** 预签名上传的过期时间(ISO 8601)。 */
|
|
71
|
+
expiresAt: string;
|
|
72
|
+
}
|
|
73
|
+
export interface AttachmentsDeps {
|
|
74
|
+
db: KernelDb;
|
|
75
|
+
storage: StorageService;
|
|
76
|
+
config: () => KernelConfig;
|
|
77
|
+
/** viewer 能否访问该会话(与会话流相同的规则)。 */
|
|
78
|
+
canAccessConversation: (orgId: string, conversationId: string, viewerAccountId: string) => Promise<boolean>;
|
|
79
|
+
log: Pick<Logger, "info" | "warn">;
|
|
80
|
+
}
|
|
81
|
+
/** 去掉参数、转小写:`Text/Plain; charset=utf-8` → `text/plain`。 */
|
|
82
|
+
export declare const normalizeContentType: (ct: string) => string;
|
|
83
|
+
/** 文件开头是否与声明的类型相符(图片与 PDF 看签名,文本不能含 NUL)。 */
|
|
84
|
+
export declare function sniffMatches(contentType: string, head: Uint8Array): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* PDF 的页数:数未压缩的页对象(`/Type /Page`,不含 `/Pages`)。页对象放在压缩的对象流里时数不到,返回 0。
|
|
87
|
+
*/
|
|
88
|
+
export declare function countPdfPages(bytes: Uint8Array): number;
|
|
89
|
+
/**
|
|
90
|
+
* 对话附件(M5 T3):登记 → 浏览器按预签名直传对象存储 → finalize 核对 → 发消息时绑定到会话。
|
|
91
|
+
* 字节只在对象存储(`kernel/<orgId>/attachments/<id>`),日志里只有引用;构建模型请求时经 {@link fetchMedia} 取字节。
|
|
92
|
+
* 无进程内状态,可多副本共用。
|
|
93
|
+
*/
|
|
94
|
+
export declare class AttachmentsService {
|
|
95
|
+
private readonly d;
|
|
96
|
+
constructor(d: AttachmentsDeps);
|
|
97
|
+
/** 单个附件的大小上限:配置的 `maxBytes`,图片再受 `MEDIA_LIMITS.imageBytes` 限制。 */
|
|
98
|
+
private limitFor;
|
|
99
|
+
/** 当前配置下的上限(不需要对象存储)。 */
|
|
100
|
+
limits(): AttachmentLimits;
|
|
101
|
+
/**
|
|
102
|
+
* 登记一个附件(`pending`)并返回预签名上传:存储端按声明的大小与类型限制上传。
|
|
103
|
+
* 类型不在 `attachments.allowedTypes` → `attachment.type_not_allowed`;超过上限 → `attachment.too_large`;
|
|
104
|
+
* 该账号在组织里已有 {@link MAX_PENDING_ATTACHMENTS} 个未 finalize 的附件 → `attachment.too_many_pending`
|
|
105
|
+
* (软上限:并发登记可能略超);没有对象存储 → `storage.unavailable`。
|
|
106
|
+
*/
|
|
107
|
+
create(orgId: string, accountId: string, input: {
|
|
108
|
+
name: string;
|
|
109
|
+
contentType: string;
|
|
110
|
+
size: number;
|
|
111
|
+
}, purpose?: AttachmentPurpose): Promise<CreatedAttachment>;
|
|
112
|
+
/**
|
|
113
|
+
* 上传完成后核对并标记为 `ready`(只有上传者能做;已 ready 时直接返回):
|
|
114
|
+
* - 对象还不存在 → `attachment.not_ready`;
|
|
115
|
+
* - 大小与声明不符 → 删除已传的对象,大了 `attachment.too_large`、小了 `attachment.not_ready`(可重传);
|
|
116
|
+
* - 存储记录的类型或文件开头的签名与声明不符 → 删除对象,`attachment.type_not_allowed`。
|
|
117
|
+
*/
|
|
118
|
+
finalize(orgId: string, accountId: string, id: string): Promise<AttachmentView>;
|
|
119
|
+
/**
|
|
120
|
+
* 下载地址(预签名,{@link ATTACHMENT_DOWNLOAD_TTL_SECONDS} 秒):已绑定的附件要求能访问其会话,
|
|
121
|
+
* 未绑定的只有上传者;否则 `attachment.not_found`。只有图片与 PDF 以 `inline` 打开,其余一律 `attachment`
|
|
122
|
+
* (即使存储里的类型被改成 text/html 也不会在页面里渲染);响应类型按 finalize 核对过的类型返回。
|
|
123
|
+
*/
|
|
124
|
+
downloadUrl(orgId: string, accountId: string, id: string): Promise<string>;
|
|
125
|
+
/**
|
|
126
|
+
* 绑定在该会话、已 ready 的附件(id 与原始文件名),按上传时间、id 排序(沙箱同步按这个顺序分配文件名)。
|
|
127
|
+
*/
|
|
128
|
+
listForConversation(orgId: string, conversationId: string): Promise<{
|
|
129
|
+
id: string;
|
|
130
|
+
name: string;
|
|
131
|
+
}[]>;
|
|
132
|
+
/**
|
|
133
|
+
* 读取一个绑定在该会话、已 ready 的附件(沙箱同步等内核内部用途):没有行、未绑定到该会话、对象已不在、
|
|
134
|
+
* 大小或 etag 与 finalize 时不符 → null。其余错误(存储不可用等)照常抛出。调用方负责读完或取消 `body`。
|
|
135
|
+
*/
|
|
136
|
+
openForConversation(orgId: string, conversationId: string, attachmentId: string): Promise<OpenedAttachment | null>;
|
|
137
|
+
/**
|
|
138
|
+
* 发消息时在调用方事务里绑定附件(行锁),返回写进 user_message 的媒体块(`ref`,按 ids 顺序):
|
|
139
|
+
* - 超过 `attachments.maxPerMessage`、或同一个 id 出现多次 → `validation_failed`;
|
|
140
|
+
* - 不存在、不是发送者上传的、已绑定到别的会话、未绑定且已过期 → `attachment.not_found`;
|
|
141
|
+
* - 还没 finalize → `attachment.not_ready`。
|
|
142
|
+
* 后两种的 details 为 `[{ path: "files", message, attachmentId }]`,网页据此标出对应条目。
|
|
143
|
+
* 已绑定到本会话的(重试)照常返回块。
|
|
144
|
+
*/
|
|
145
|
+
bindForMessage(trx: Trx, orgId: string, conversationId: string, accountId: string, ids: readonly string[]): Promise<LogContentBlock[]>;
|
|
146
|
+
/** 下载 / 取字节时核对 etag:finalize 记下的与当前对象的不一致 → 内容被替换(记 warn)。没有记录时不核对。 */
|
|
147
|
+
private sameContent;
|
|
148
|
+
/**
|
|
149
|
+
* 构建模型请求时查附件行的声明信息(只含绑定在该会话、已 ready 的):大小与 PDF 页数。
|
|
150
|
+
* 没有行的不在结果里;查询失败照常抛出。
|
|
151
|
+
*/
|
|
152
|
+
mediaInfo(orgId: string, conversationId: string, ids: readonly string[]): Promise<Map<string, MediaInfo>>;
|
|
153
|
+
/**
|
|
154
|
+
* 构建模型请求时取附件字节:只取绑定在该会话、已 ready 的附件。只有「确定不存在」才为 null:没有行、对象已不在、
|
|
155
|
+
* 大小或 etag 与 finalize 时不符(内容被替换,记 warn)。其余错误(存储不可用、网络错误)一律抛出(Ruling M4),
|
|
156
|
+
* 由调用方按可重试处理,不会变成占位。`caps` 里的附件只按范围读开头若干字节(`text/*` 封顶,更后面的不取)。
|
|
157
|
+
*/
|
|
158
|
+
fetchMedia(orgId: string, conversationId: string, ids: readonly string[], caps?: ReadonlyMap<string, number>): Promise<Map<string, MediaBytes | null>>;
|
|
159
|
+
/**
|
|
160
|
+
* 取一个技能包上传的字节,供 `POST /skills` 解包(只有上传者、只认 `skill-package` 用途):
|
|
161
|
+
* 还没 finalize 的先 finalize(核对大小与 zip 文件头);过期时间顺延 {@link SKILL_PACKAGE_TTL_HOURS} 小时,
|
|
162
|
+
* 处理期间不会被清理任务删掉。不存在、不是技能包、已用掉或已过期 → `attachment.not_found`;
|
|
163
|
+
* 对象已不在或内容与 finalize 时不符 → `attachment.not_found`。
|
|
164
|
+
*/
|
|
165
|
+
readSkillPackage(orgId: string, accountId: string, id: string): Promise<Uint8Array>;
|
|
166
|
+
/**
|
|
167
|
+
* 在调用方事务里把技能包上传标记为已用掉(行锁;之后由清理任务删 zip,解出的文件因被版本引用而保留)。
|
|
168
|
+
* 不是该账号的 ready 技能包(如已被并发的请求用掉)→ `attachment.not_found`。
|
|
169
|
+
*/
|
|
170
|
+
consumeSkillPackage(trx: Trx, orgId: string, accountId: string, id: string): Promise<void>;
|
|
171
|
+
/**
|
|
172
|
+
* 删除过期(`expires_at < now()`)且从未绑定到会话的附件:先把行认领为 `deleting`(`FOR UPDATE SKIP LOCKED`,
|
|
173
|
+
* 多副本并发时互不重复),再删对象、删行。删对象失败的行保持 `deleting`,下次运行重试。
|
|
174
|
+
* 技能包上传(过期未用掉的,或已被 `POST /skills` 用掉、`expires_at` 置为当时的)同样由这里删 zip;
|
|
175
|
+
* 解出的文件 `skills/<id>/` 只在没有任何技能版本引用时一并删除。
|
|
176
|
+
* 没有对象存储时什么也不做。返回删除的附件数。
|
|
177
|
+
*/
|
|
178
|
+
deleteExpired(): Promise<number>;
|
|
179
|
+
}
|
|
180
|
+
export {};
|