@capybara-hq/kernel 0.1.0-rc.36 → 0.1.0-rc.38
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/bootstrap.json +5 -5
- package/dist/admin/admin.module.d.ts +3 -2
- package/dist/admin/admin.module.js +9 -5
- package/dist/admin/audit-log.service.d.ts +51 -0
- package/dist/admin/{platform-audit.service.js → audit-log.service.js} +20 -12
- package/dist/admin/audit.controller.d.ts +18 -6
- package/dist/admin/audit.controller.js +36 -6
- package/dist/admin/audit.schemas.d.ts +9 -1
- package/dist/admin/audit.schemas.js +22 -2
- package/dist/admin/org-network.controller.d.ts +30 -0
- package/dist/admin/org-network.controller.js +77 -0
- package/dist/admin/org-network.schemas.d.ts +16 -0
- package/dist/admin/org-network.schemas.js +27 -0
- package/dist/admin/org-network.service.d.ts +41 -0
- package/dist/admin/org-network.service.js +101 -0
- package/dist/admin/outbox-dead.controller.d.ts +4 -6
- package/dist/admin/outbox-dead.controller.js +9 -6
- package/dist/admin/outbox-dead.schemas.d.ts +16 -0
- package/dist/admin/outbox-dead.schemas.js +25 -1
- package/dist/admin/outbox-dead.service.d.ts +16 -7
- package/dist/admin/outbox-dead.service.js +34 -10
- package/dist/admin/overview.service.d.ts +3 -3
- package/dist/admin/overview.service.js +0 -1
- package/dist/agents/agent-lookup.js +2 -10
- package/dist/agents/agents.service.js +9 -20
- package/dist/agents/definition.d.ts +3 -51
- package/dist/agents/definition.js +4 -254
- package/dist/agents/org-templates.js +2 -6
- package/dist/agents/readiness.controller.d.ts +4 -12
- package/dist/agents/readiness.controller.js +4 -12
- package/dist/agents/readiness.service.d.ts +23 -11
- package/dist/agents/readiness.service.js +31 -14
- package/dist/agents/templates.d.ts +0 -6
- package/dist/agents/templates.js +8 -34
- package/dist/background/store.d.ts +2 -0
- package/dist/background/store.js +3 -1
- package/dist/background/wake-rules.js +2 -1
- package/dist/catalog/admin-catalog.controller.d.ts +1 -2
- package/dist/catalog/admin-catalog.controller.js +1 -2
- package/dist/catalog/appearance.service.js +1 -3
- package/dist/catalog/catalog-content.d.ts +1 -1
- package/dist/catalog/catalog-content.js +1 -4
- package/dist/catalog/catalog-items.js +3 -3
- package/dist/catalog/catalog-scope.service.d.ts +10 -28
- package/dist/catalog/catalog-scope.service.js +22 -73
- package/dist/catalog/cli.d.ts +0 -11
- package/dist/catalog/cli.js +0 -20
- package/dist/catalog/component-scope.service.js +0 -2
- package/dist/catalog/component-state.js +2 -2
- package/dist/catalog/install-status.d.ts +6 -0
- package/dist/catalog/install-status.js +6 -0
- package/dist/catalog/job-ids.d.ts +0 -4
- package/dist/catalog/job-ids.js +0 -4
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.service.d.ts +2 -0
- package/dist/catalog/org-catalog.service.js +8 -3
- package/dist/catalog/org-extension-switch.d.ts +7 -2
- package/dist/catalog/org-extension-switch.js +56 -9
- package/dist/catalog/org-plugin-uploads.d.ts +6 -15
- package/dist/catalog/org-plugin-uploads.js +9 -27
- package/dist/catalog/owned-items.js +1 -3
- package/dist/catalog/platform-import-update.js +1 -1
- package/dist/catalog/plugin-import.d.ts +15 -13
- package/dist/catalog/plugin-import.js +21 -30
- package/dist/catalog/plugin-install.d.ts +3 -43
- package/dist/catalog/plugin-install.js +8 -150
- package/dist/catalog/plugin-package.d.ts +5 -10
- package/dist/catalog/plugin-package.js +12 -33
- package/dist/catalog/plugin-upgrade.js +5 -4
- package/dist/catalog/scope-jobs.d.ts +34 -34
- package/dist/catalog/scope-jobs.js +50 -37
- package/dist/catalog/scope-orgs.d.ts +1 -1
- package/dist/catalog/scope-orgs.js +1 -2
- package/dist/catalog/scope-sync-workers.d.ts +4 -3
- package/dist/catalog/scope-sync-workers.js +18 -6
- package/dist/catalog/scope-sync.d.ts +56 -59
- package/dist/catalog/scope-sync.js +96 -166
- package/dist/catalog/unshare.d.ts +3 -4
- package/dist/catalog/unshare.js +5 -8
- package/dist/channels/job-ids.d.ts +2 -6
- package/dist/channels/job-ids.js +2 -6
- package/dist/channels/outbound.d.ts +1 -1
- package/dist/channels/outbound.js +1 -1
- package/dist/channels/supervisor.d.ts +2 -3
- package/dist/channels/supervisor.js +2 -3
- package/dist/client/client-access.service.js +1 -1
- package/dist/config/env.js +19 -1
- package/dist/config/load.d.ts +0 -6
- package/dist/config/load.js +8 -27
- package/dist/config/schema.d.ts +54 -47
- package/dist/config/schema.js +198 -42
- package/dist/conversations/attachments.service.d.ts +10 -3
- package/dist/conversations/attachments.service.js +49 -16
- package/dist/conversations/conversations.controller.d.ts +0 -39
- package/dist/conversations/conversations.controller.js +0 -39
- package/dist/conversations/event-log.js +4 -1
- package/dist/conversations/events.d.ts +71 -46
- package/dist/conversations/events.js +124 -112
- package/dist/conversations/media-types.d.ts +25 -0
- package/dist/conversations/media-types.js +38 -0
- package/dist/conversations/queue.d.ts +3 -1
- package/dist/conversations/queue.service.js +9 -2
- package/dist/conversations/titles.js +6 -0
- package/dist/ctx/create-ctx.d.ts +8 -1
- package/dist/ctx/create-ctx.js +13 -3
- package/dist/ctx/net.d.ts +50 -0
- package/dist/ctx/net.js +67 -0
- package/dist/ctx/secrets.d.ts +24 -7
- package/dist/ctx/secrets.js +97 -30
- package/dist/db/kernel-schema.d.ts +27 -6
- package/dist/devices/devices.service.js +2 -1
- package/dist/errors.d.ts +10 -2
- package/dist/errors.js +10 -2
- package/dist/evals/reconstruct.d.ts +4 -17
- package/dist/evals/reconstruct.js +13 -53
- package/dist/evals/recorded-tools.d.ts +0 -27
- package/dist/evals/recorded-tools.js +2 -92
- package/dist/evals/run-replay.d.ts +1 -6
- package/dist/evals/run-replay.js +10 -17
- package/dist/evals/sets.service.d.ts +17 -5
- package/dist/evals/sets.service.js +33 -12
- package/dist/evals/snapshot.d.ts +1 -2
- package/dist/evals/snapshot.js +4 -17
- package/dist/extensions/admin-ops.d.ts +6 -1
- package/dist/extensions/admin-ops.js +17 -4
- package/dist/extensions/admin-view.d.ts +7 -4
- package/dist/extensions/admin-view.js +27 -21
- package/dist/extensions/bootstrap.js +0 -1
- package/dist/extensions/cli.js +0 -1
- package/dist/extensions/extensions.module.js +3 -0
- package/dist/extensions/host.d.ts +9 -4
- package/dist/extensions/host.js +14 -8
- package/dist/extensions/installs.d.ts +1 -3
- package/dist/extensions/instance.d.ts +0 -2
- package/dist/extensions/instance.js +0 -3
- package/dist/extensions/org-config.d.ts +4 -4
- package/dist/extensions/org-config.js +13 -22
- package/dist/extensions/package.d.ts +6 -6
- package/dist/extensions/package.js +3 -7
- package/dist/extensions/permission-view.d.ts +2 -4
- package/dist/extensions/plugin-items.d.ts +21 -1
- package/dist/extensions/plugin-items.js +28 -0
- package/dist/extensions/sync.js +5 -10
- package/dist/extensions/unavailable.js +0 -1
- package/dist/http/api.module.js +4 -1
- package/dist/identity/audit.d.ts +0 -12
- package/dist/identity/audit.js +0 -27
- package/dist/identity/auth.controller.js +5 -9
- package/dist/identity/cookies.d.ts +4 -9
- package/dist/identity/cookies.js +8 -32
- package/dist/identity/initial-passwords.d.ts +1 -1
- package/dist/identity/initial-passwords.js +1 -2
- package/dist/identity/sessions.d.ts +0 -6
- package/dist/identity/sessions.js +0 -18
- package/dist/inbox/platform-inbox.service.d.ts +33 -1
- package/dist/inbox/platform-inbox.service.js +56 -6
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/infra/cli/master-key-rewrap.d.ts +15 -0
- package/dist/infra/cli/master-key-rewrap.js +24 -0
- package/dist/infra/config/kernel-config.service.js +0 -17
- package/dist/infra/database/transaction-host.d.ts +32 -1
- package/dist/infra/database/transaction-host.js +30 -4
- package/dist/infra/database/xact-lock.d.ts +16 -0
- package/dist/infra/database/xact-lock.js +28 -1
- package/dist/infra/health/health.controller.js +8 -0
- package/dist/infra/health/process-fault.d.ts +16 -0
- package/dist/infra/health/process-fault.js +49 -0
- package/dist/infra/lifecycle/process-guards.d.ts +8 -2
- package/dist/infra/lifecycle/process-guards.js +12 -3
- package/dist/infra/lifecycle/shutdown-signals.d.ts +10 -1
- package/dist/infra/lifecycle/shutdown-signals.js +28 -13
- package/dist/infra/outbox/outbox.service.d.ts +12 -9
- package/dist/infra/outbox/outbox.service.js +22 -26
- package/dist/infra/outbox/registry.d.ts +15 -7
- package/dist/infra/outbox/registry.js +39 -23
- package/dist/lifecycle/kernel-lifecycle.js +1 -7
- package/dist/models/enablement.d.ts +5 -6
- package/dist/models/enablement.js +7 -14
- package/dist/net/public-address.d.ts +21 -1
- package/dist/net/public-address.js +56 -10
- package/dist/net/safe-fetch.d.ts +4 -1
- package/dist/net/safe-fetch.js +15 -4
- package/dist/orgs/directory-sync.js +2 -0
- package/dist/orgs/members.service.js +5 -0
- package/dist/orgs/network-allowances.service.d.ts +79 -0
- package/dist/orgs/network-allowances.service.js +371 -0
- package/dist/orgs/offboarding.d.ts +3 -1
- package/dist/orgs/offboarding.js +9 -2
- package/dist/orgs/org-lock.d.ts +28 -2
- package/dist/orgs/org-lock.js +59 -4
- package/dist/orgs/orgs.controller.d.ts +11 -2
- package/dist/orgs/orgs.controller.js +19 -3
- package/dist/orgs/orgs.module.d.ts +3 -2
- package/dist/orgs/orgs.module.js +6 -2
- package/dist/orgs/orgs.schemas.d.ts +12 -0
- package/dist/orgs/orgs.schemas.js +5 -0
- package/dist/orgs/orgs.service.js +6 -1
- package/dist/orgs/settings.controller.d.ts +3 -2
- package/dist/orgs/settings.service.d.ts +59 -14
- package/dist/orgs/settings.service.js +102 -20
- package/dist/overrides.d.ts +7 -7
- package/dist/overrides.js +4 -4
- package/dist/packages/tgz.d.ts +0 -2
- package/dist/packages/tgz.js +0 -2
- package/dist/platform/exclusions.js +0 -5
- package/dist/platform/operation.js +1 -1
- package/dist/platform/ops/admin.ops.d.ts +2 -2
- package/dist/platform/ops/admin.ops.js +9 -6
- package/dist/platform/ops/agents.ops.js +1 -1
- package/dist/platform/ops/connectors.ops.js +46 -1
- package/dist/platform/ops/evals.ops.js +1 -64
- package/dist/platform/ops/extensions-admin.ops.js +1 -1
- package/dist/platform/ops/inbox.ops.js +16 -3
- package/dist/platform/ops/org-plugins.ops.js +1 -1
- package/dist/platform/ops/orgs.ops.d.ts +11 -3
- package/dist/platform/ops/orgs.ops.js +139 -5
- package/dist/platform/ops/outbox.ops.js +5 -5
- package/dist/platform/route-schemas.js +3 -0
- package/dist/roles/worker-role.d.ts +2 -3
- package/dist/roles/worker-role.js +3 -13
- package/dist/runtime/checkpointer.d.ts +3 -0
- package/dist/runtime/checkpointer.js +7 -4
- package/dist/runtime/context/build.d.ts +56 -18
- package/dist/runtime/context/build.js +143 -50
- package/dist/runtime/context/compaction.d.ts +1 -3
- package/dist/runtime/context/compaction.js +42 -8
- package/dist/runtime/context/run-context.js +1 -2
- package/dist/runtime/context/skills.d.ts +27 -56
- package/dist/runtime/context/skills.js +42 -114
- package/dist/runtime/context/tool-changes.d.ts +3 -3
- package/dist/runtime/context/tool-changes.js +6 -16
- package/dist/runtime/hook-calls.d.ts +6 -6
- package/dist/runtime/hook-calls.js +7 -7
- package/dist/runtime/langgraph-loop.js +9 -3
- package/dist/runtime/maintenance.d.ts +3 -11
- package/dist/runtime/maintenance.js +5 -20
- package/dist/runtime/model-call.d.ts +5 -0
- package/dist/runtime/model-call.js +48 -36
- package/dist/runtime/providers.d.ts +33 -35
- package/dist/runtime/providers.js +64 -109
- package/dist/runtime/run-context.service.js +7 -22
- package/dist/runtime/run-deletion.d.ts +6 -0
- package/dist/runtime/run-deletion.js +39 -16
- package/dist/runtime/run-execution.d.ts +56 -3
- package/dist/runtime/run-execution.js +81 -11
- package/dist/runtime/run-finish.js +2 -1
- package/dist/runtime/run-liveness.d.ts +11 -0
- package/dist/runtime/run-liveness.js +19 -0
- package/dist/runtime/run-orphan-check.job.js +2 -1
- package/dist/runtime/run-queue.js +8 -16
- package/dist/runtime/run-worker.d.ts +2 -2
- package/dist/runtime/run-worker.js +8 -6
- package/dist/runtime/step-log.d.ts +5 -0
- package/dist/runtime/step-log.js +9 -4
- package/dist/runtime/subagents/definition.d.ts +16 -20
- package/dist/runtime/subagents/definition.js +27 -27
- package/dist/runtime/subagents/dispatch.d.ts +6 -2
- package/dist/runtime/subagents/dispatch.js +17 -3
- package/dist/runtime/subagents/org-agents.js +1 -2
- package/dist/runtime/subagents/preamble.d.ts +3 -2
- package/dist/runtime/subagents/preamble.js +3 -2
- package/dist/runtime/subagents/render.d.ts +1 -2
- package/dist/runtime/subagents/render.js +1 -2
- package/dist/runtime/subagents/skill-fork.d.ts +2 -4
- package/dist/runtime/subagents/template-skills.d.ts +47 -0
- package/dist/runtime/subagents/template-skills.js +76 -0
- package/dist/runtime/waits.js +3 -1
- package/dist/schedules/effective-settings.d.ts +9 -3
- package/dist/schedules/effective-settings.js +5 -4
- package/dist/schedules/fire.js +11 -0
- package/dist/schedules/scheduled-tasks.service.js +5 -0
- package/dist/schedules/unattended.d.ts +2 -0
- package/dist/schedules/unattended.js +6 -1
- package/dist/skills/agent-skills.service.js +1 -2
- package/dist/skills/catalog.d.ts +1 -3
- package/dist/skills/catalog.js +1 -3
- package/dist/skills/conversation-catalog.d.ts +1 -2
- package/dist/skills/conversation-catalog.js +1 -2
- package/dist/skills/usable.js +2 -3
- package/dist/storage/storage.service.js +9 -1
- package/dist/tools/approvals.service.js +2 -4
- package/dist/tools/builtin-names.d.ts +2 -9
- package/dist/tools/builtin-names.js +4 -13
- package/dist/tools/builtins/sandbox/bash.js +3 -3
- package/dist/tools/builtins/sandbox/common.d.ts +7 -13
- package/dist/tools/builtins/sandbox/common.js +8 -115
- package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +10 -0
- package/dist/tools/builtins/sandbox/fetch-attachment.js +119 -0
- package/dist/tools/builtins/sandbox/glob.js +1 -3
- package/dist/tools/builtins/sandbox/grep.js +3 -5
- package/dist/tools/builtins/sandbox/index.d.ts +8 -5
- package/dist/tools/builtins/sandbox/index.js +10 -5
- package/dist/tools/builtins/sandbox/read.js +3 -2
- package/dist/tools/builtins/tool-search.d.ts +4 -7
- package/dist/tools/builtins/tool-search.js +6 -10
- package/dist/tools/connector-account-policies.d.ts +30 -3
- package/dist/tools/connector-account-policies.js +54 -7
- package/dist/tools/connector-content.js +1 -0
- package/dist/tools/connectors.controller.d.ts +24 -11
- package/dist/tools/connectors.controller.js +35 -6
- package/dist/tools/connectors.schemas.d.ts +14 -1
- package/dist/tools/connectors.schemas.js +14 -2
- package/dist/tools/connectors.service.d.ts +22 -0
- package/dist/tools/connectors.service.js +65 -6
- package/dist/tools/drift.d.ts +6 -2
- package/dist/tools/drift.js +10 -5
- package/dist/tools/git-push-policy.d.ts +4 -1
- package/dist/tools/git-push-policy.js +3 -1
- package/dist/tools/info.d.ts +1 -7
- package/dist/tools/info.js +5 -18
- package/dist/tools/job-ids.d.ts +0 -4
- package/dist/tools/job-ids.js +1 -6
- package/dist/tools/pipeline.d.ts +4 -10
- package/dist/tools/pipeline.js +17 -62
- package/dist/tools/policy.d.ts +6 -2
- package/dist/tools/policy.js +14 -12
- package/dist/tools/registry.js +1 -5
- package/dist/ui/views.d.ts +5 -5
- package/dist/ui/views.js +10 -16
- package/package.json +3 -3
- package/src/migrations/0137_audit_org_idx.sql +5 -0
- package/src/migrations/0138_plugin_install_status_no_upgrading.sql +18 -0
- package/src/migrations/0139_retire_legacy_forms.sql +183 -0
- package/src/migrations/0140_retire_history_forms.sql +148 -0
- package/src/migrations/0141_install_ledger_promoted_rows.sql +36 -0
- package/src/migrations/0142_backfill_event_fields.sql +74 -0
- package/src/migrations/0143_backfill_model_call_fields.sql +105 -0
- package/src/migrations/0144_retire_frozen_definition_keys.sql +163 -0
- package/src/migrations/0145_org_network_allowances.sql +12 -0
- package/dist/admin/platform-audit.service.d.ts +0 -41
- package/dist/conversations/job-ids.d.ts +0 -6
- package/dist/conversations/job-ids.js +0 -6
- package/dist/extensions/job-ids.d.ts +0 -6
- package/dist/extensions/job-ids.js +0 -6
- package/dist/infra/queue/retired-schedulers.d.ts +0 -7
- package/dist/infra/queue/retired-schedulers.js +0 -9
- package/dist/orgs/job-ids.d.ts +0 -8
- package/dist/orgs/job-ids.js +0 -8
- package/dist/runtime/context/legacy-text.d.ts +0 -22
- package/dist/runtime/context/legacy-text.js +0 -37
- package/dist/runtime/job-ids.d.ts +0 -10
- package/dist/runtime/job-ids.js +0 -10
- package/dist/runtime/retired-schedulers.d.ts +0 -7
- package/dist/runtime/retired-schedulers.js +0 -31
- package/dist/storage/job-ids.d.ts +0 -6
- package/dist/storage/job-ids.js +0 -6
- package/dist/tools/legacy-data.d.ts +0 -34
- package/dist/tools/legacy-data.js +0 -76
- package/dist/tools/legacy-keys.d.ts +0 -51
- package/dist/tools/legacy-keys.js +0 -114
package/dist/config/schema.js
CHANGED
|
@@ -28,6 +28,148 @@ export const DEFAULT_MAX_COMMAND_SECONDS = 7200;
|
|
|
28
28
|
export const ACCESS_TOKEN_TTL_MAX_SECONDS = 3600;
|
|
29
29
|
/** `attachments.requestMediaBytes` 的上限(24 MiB):base64 后约 32 MiB,是常见供应商的请求上限。 */
|
|
30
30
|
export const REQUEST_MEDIA_BYTES_MAX = 25_165_824;
|
|
31
|
+
/**
|
|
32
|
+
* The content types accepted for chat attachments by default: the model's media types, plus the
|
|
33
|
+
* office and archive formats people hand an agent to process with code (the model only gets a
|
|
34
|
+
* reference to those). Deployments extend or narrow the list in `attachments.allowedTypes`.
|
|
35
|
+
*/
|
|
36
|
+
export const DEFAULT_ATTACHMENT_TYPES = [
|
|
37
|
+
...IMAGE_MEDIA_TYPES,
|
|
38
|
+
...DOCUMENT_MEDIA_TYPES,
|
|
39
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
40
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
41
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
42
|
+
"application/zip",
|
|
43
|
+
"application/json",
|
|
44
|
+
];
|
|
45
|
+
/**
|
|
46
|
+
* The default file extensions a chat attachment may carry (lower case, no dot). Source files and
|
|
47
|
+
* office documents arrive with content types that disagree across browsers and operating systems
|
|
48
|
+
* (`text/x-python`, `application/x-python`, `application/octet-stream`; a `.ts` can come as
|
|
49
|
+
* `video/mp2t`), so the extension is the reliable half of the accept rule. Executables are
|
|
50
|
+
* deliberately absent.
|
|
51
|
+
*/
|
|
52
|
+
export const DEFAULT_ATTACHMENT_EXTENSIONS = [
|
|
53
|
+
// office documents
|
|
54
|
+
"doc",
|
|
55
|
+
"docx",
|
|
56
|
+
"xls",
|
|
57
|
+
"xlsx",
|
|
58
|
+
"ppt",
|
|
59
|
+
"pptx",
|
|
60
|
+
"odt",
|
|
61
|
+
"ods",
|
|
62
|
+
"odp",
|
|
63
|
+
"rtf",
|
|
64
|
+
// archives
|
|
65
|
+
"zip",
|
|
66
|
+
"tar",
|
|
67
|
+
"gz",
|
|
68
|
+
"tgz",
|
|
69
|
+
"bz2",
|
|
70
|
+
"xz",
|
|
71
|
+
"7z",
|
|
72
|
+
// documents and text
|
|
73
|
+
"txt",
|
|
74
|
+
"md",
|
|
75
|
+
"markdown",
|
|
76
|
+
"rst",
|
|
77
|
+
"tex",
|
|
78
|
+
"adoc",
|
|
79
|
+
"csv",
|
|
80
|
+
"tsv",
|
|
81
|
+
"html",
|
|
82
|
+
"htm",
|
|
83
|
+
"xhtml",
|
|
84
|
+
"xml",
|
|
85
|
+
"xsd",
|
|
86
|
+
"xsl",
|
|
87
|
+
"svg",
|
|
88
|
+
"css",
|
|
89
|
+
"scss",
|
|
90
|
+
"sass",
|
|
91
|
+
"less",
|
|
92
|
+
// data and configuration
|
|
93
|
+
"json",
|
|
94
|
+
"jsonl",
|
|
95
|
+
"yaml",
|
|
96
|
+
"yml",
|
|
97
|
+
"toml",
|
|
98
|
+
"ini",
|
|
99
|
+
"cfg",
|
|
100
|
+
"conf",
|
|
101
|
+
"env",
|
|
102
|
+
"properties",
|
|
103
|
+
"sql",
|
|
104
|
+
// source code
|
|
105
|
+
"py",
|
|
106
|
+
"pyi",
|
|
107
|
+
"ipynb",
|
|
108
|
+
"js",
|
|
109
|
+
"mjs",
|
|
110
|
+
"cjs",
|
|
111
|
+
"jsx",
|
|
112
|
+
"ts",
|
|
113
|
+
"mts",
|
|
114
|
+
"cts",
|
|
115
|
+
"tsx",
|
|
116
|
+
"vue",
|
|
117
|
+
"svelte",
|
|
118
|
+
"java",
|
|
119
|
+
"kt",
|
|
120
|
+
"kts",
|
|
121
|
+
"scala",
|
|
122
|
+
"groovy",
|
|
123
|
+
"gradle",
|
|
124
|
+
"go",
|
|
125
|
+
"rs",
|
|
126
|
+
"c",
|
|
127
|
+
"h",
|
|
128
|
+
"cc",
|
|
129
|
+
"cpp",
|
|
130
|
+
"cxx",
|
|
131
|
+
"hpp",
|
|
132
|
+
"cs",
|
|
133
|
+
"fs",
|
|
134
|
+
"vb",
|
|
135
|
+
"rb",
|
|
136
|
+
"php",
|
|
137
|
+
"pl",
|
|
138
|
+
"swift",
|
|
139
|
+
"lua",
|
|
140
|
+
"r",
|
|
141
|
+
"jl",
|
|
142
|
+
"dart",
|
|
143
|
+
"ex",
|
|
144
|
+
"exs",
|
|
145
|
+
"erl",
|
|
146
|
+
"hs",
|
|
147
|
+
"clj",
|
|
148
|
+
"cljs",
|
|
149
|
+
"sh",
|
|
150
|
+
"bash",
|
|
151
|
+
"zsh",
|
|
152
|
+
"fish",
|
|
153
|
+
"ps1",
|
|
154
|
+
"bat",
|
|
155
|
+
"cmd",
|
|
156
|
+
"diff",
|
|
157
|
+
"patch",
|
|
158
|
+
"log",
|
|
159
|
+
"graphql",
|
|
160
|
+
"gql",
|
|
161
|
+
"proto",
|
|
162
|
+
"tf",
|
|
163
|
+
"tfvars",
|
|
164
|
+
"mk",
|
|
165
|
+
];
|
|
166
|
+
/**
|
|
167
|
+
* A chat attachment content type: a lower-case `type/subtype` (RFC 6838 restricted names), with no
|
|
168
|
+
* parameters and no whitespace.
|
|
169
|
+
*/
|
|
170
|
+
const contentType = () => z
|
|
171
|
+
.string()
|
|
172
|
+
.regex(/^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+-]*$/, "must be a lower-case content type (type/subtype, no parameters)");
|
|
31
173
|
/**
|
|
32
174
|
* The default host list of the allowlist (`sandbox.limits.allowHosts`): the common package
|
|
33
175
|
* registries and source hosts (git clone, archive downloads, raw files, release assets). It is the
|
|
@@ -161,9 +303,9 @@ export function trustProxyEntryProblem(entry) {
|
|
|
161
303
|
return `"${entry}" has an out-of-range prefix`;
|
|
162
304
|
return undefined;
|
|
163
305
|
}
|
|
164
|
-
export const KernelConfigSchema = z.
|
|
306
|
+
export const KernelConfigSchema = z.strictObject({
|
|
165
307
|
db: z
|
|
166
|
-
.
|
|
308
|
+
.strictObject({
|
|
167
309
|
url: z
|
|
168
310
|
.string()
|
|
169
311
|
.min(1)
|
|
@@ -191,7 +333,7 @@ export const KernelConfigSchema = z.object({
|
|
|
191
333
|
})
|
|
192
334
|
.prefault({}),
|
|
193
335
|
redis: z
|
|
194
|
-
.
|
|
336
|
+
.strictObject({
|
|
195
337
|
url: z
|
|
196
338
|
.string()
|
|
197
339
|
.min(1)
|
|
@@ -212,7 +354,7 @@ export const KernelConfigSchema = z.object({
|
|
|
212
354
|
.default({})
|
|
213
355
|
.meta(meta({ description: "Deployment-level config keyed by extension name" })),
|
|
214
356
|
extensionHost: z
|
|
215
|
-
.
|
|
357
|
+
.strictObject({
|
|
216
358
|
dir: z
|
|
217
359
|
.string()
|
|
218
360
|
.min(1)
|
|
@@ -263,7 +405,7 @@ export const KernelConfigSchema = z.object({
|
|
|
263
405
|
})
|
|
264
406
|
.prefault({}),
|
|
265
407
|
packages: z
|
|
266
|
-
.
|
|
408
|
+
.strictObject({
|
|
267
409
|
npmRegistry: z
|
|
268
410
|
.url()
|
|
269
411
|
.default("https://registry.npmjs.org")
|
|
@@ -287,7 +429,7 @@ export const KernelConfigSchema = z.object({
|
|
|
287
429
|
})
|
|
288
430
|
.prefault({}),
|
|
289
431
|
bootstrap: z
|
|
290
|
-
.
|
|
432
|
+
.strictObject({
|
|
291
433
|
dir: z
|
|
292
434
|
.string()
|
|
293
435
|
.min(1)
|
|
@@ -298,7 +440,7 @@ export const KernelConfigSchema = z.object({
|
|
|
298
440
|
})
|
|
299
441
|
.prefault({}),
|
|
300
442
|
catalog: z
|
|
301
|
-
.
|
|
443
|
+
.strictObject({
|
|
302
444
|
staleInstallMinutes: z
|
|
303
445
|
.number()
|
|
304
446
|
.int()
|
|
@@ -310,9 +452,9 @@ export const KernelConfigSchema = z.object({
|
|
|
310
452
|
})
|
|
311
453
|
.prefault({}),
|
|
312
454
|
marketplaces: z
|
|
313
|
-
.
|
|
455
|
+
.strictObject({
|
|
314
456
|
official: z
|
|
315
|
-
.
|
|
457
|
+
.strictObject({
|
|
316
458
|
enabled: z
|
|
317
459
|
.boolean()
|
|
318
460
|
.default(true)
|
|
@@ -391,7 +533,13 @@ export const KernelConfigSchema = z.object({
|
|
|
391
533
|
})
|
|
392
534
|
.prefault({}),
|
|
393
535
|
net: z
|
|
394
|
-
.
|
|
536
|
+
.strictObject({
|
|
537
|
+
allowInsecureLoopback: z
|
|
538
|
+
.boolean()
|
|
539
|
+
.default(false)
|
|
540
|
+
.meta(meta({
|
|
541
|
+
description: "Testing only: lift every loopback and unspecified-address refusal for extensions' ctx.net.fetch (127.0.0.0/8, ::1, 0.0.0.0/8, ::), including plain http to them (fake servers in test stacks). Link-local and cloud metadata addresses stay refused. Never set it in production",
|
|
542
|
+
})),
|
|
395
543
|
httpsProxy: z
|
|
396
544
|
.string()
|
|
397
545
|
.superRefine((value, ctx) => {
|
|
@@ -402,7 +550,7 @@ export const KernelConfigSchema = z.object({
|
|
|
402
550
|
.optional()
|
|
403
551
|
.meta(meta({
|
|
404
552
|
secret: true,
|
|
405
|
-
description: "HTTP(S) egress proxy for marketplace, archive and git downloads, npm registry downloads (packages, provenance, bootstrap plugins)
|
|
553
|
+
description: "HTTP(S) egress proxy for marketplace, archive and git downloads, npm registry downloads (packages, provenance, bootstrap plugins) OAuth requests (discovery, registration, token endpoints) and extensions' ctx.net.fetch requests (person-supplied URLs such as connector endpoints), e.g. http://user:password@proxy.internal:3128. https downloads tunnel through it with CONNECT and the kernel no longer resolves their hosts: the proxy does, so blocking private and internal addresses becomes the proxy's job, including for organizations' ctx.net requests (IP-literal URLs are still checked against marketplaces.allowPrivateHosts, or for ctx.net against the organization's allowed internal endpoints). Loopback hosts never use it, nor does an http:// npm registry; list an internal https registry in net.noProxy, and likewise every internal https host an organization's allowed internal endpoints name (with a proxy set the proxy resolves it, so the organization's allowances do not apply unless the host is in net.noProxy). HTTPS_PROXY / NODE_USE_ENV_PROXY are not read. Credentials in the URL are sent as Basic Proxy-Authorization and never logged",
|
|
406
554
|
})),
|
|
407
555
|
noProxy: z
|
|
408
556
|
.array(z
|
|
@@ -417,12 +565,12 @@ export const KernelConfigSchema = z.object({
|
|
|
417
565
|
.max(100)
|
|
418
566
|
.default([])
|
|
419
567
|
.meta(meta({
|
|
420
|
-
description: "Hostnames or IP addresses that bypass net.httpsProxy (an entry also matches its subdomains; a leading dot is allowed). These hosts are resolved locally and must resolve to public addresses unless listed in marketplaces.allowPrivateHosts",
|
|
568
|
+
description: "Hostnames or IP addresses that bypass net.httpsProxy (an entry also matches its subdomains; a leading dot is allowed). These hosts are resolved locally and must resolve to public addresses unless listed in marketplaces.allowPrivateHosts (marketplace downloads) or in an organization's allowed internal endpoints (ctx.net.fetch). List an organization's allowed internal https hosts here when net.httpsProxy is set, otherwise the proxy resolves them and the allowances do not apply",
|
|
421
569
|
})),
|
|
422
570
|
})
|
|
423
571
|
.prefault({}),
|
|
424
572
|
extensionPermissions: z
|
|
425
|
-
.
|
|
573
|
+
.strictObject({
|
|
426
574
|
autoApprove: z
|
|
427
575
|
.boolean()
|
|
428
576
|
.default(false)
|
|
@@ -432,7 +580,7 @@ export const KernelConfigSchema = z.object({
|
|
|
432
580
|
})
|
|
433
581
|
.default({ autoApprove: false }),
|
|
434
582
|
http: z
|
|
435
|
-
.
|
|
583
|
+
.strictObject({
|
|
436
584
|
port: z
|
|
437
585
|
.number()
|
|
438
586
|
.int()
|
|
@@ -510,7 +658,7 @@ export const KernelConfigSchema = z.object({
|
|
|
510
658
|
description: 'Roles this process runs: a JSON array or a comma-separated string, e.g. ["api"] or api,worker',
|
|
511
659
|
})),
|
|
512
660
|
auth: z
|
|
513
|
-
.
|
|
661
|
+
.strictObject({
|
|
514
662
|
accessTokenTtlSeconds: z
|
|
515
663
|
.number()
|
|
516
664
|
.int()
|
|
@@ -570,7 +718,7 @@ export const KernelConfigSchema = z.object({
|
|
|
570
718
|
trustedIdentitySources: [],
|
|
571
719
|
}),
|
|
572
720
|
runtime: z
|
|
573
|
-
.
|
|
721
|
+
.strictObject({
|
|
574
722
|
maxSteps: z
|
|
575
723
|
.number()
|
|
576
724
|
.int()
|
|
@@ -671,7 +819,7 @@ export const KernelConfigSchema = z.object({
|
|
|
671
819
|
sseRecheckMs: 60000,
|
|
672
820
|
}),
|
|
673
821
|
tools: z
|
|
674
|
-
.
|
|
822
|
+
.strictObject({
|
|
675
823
|
timeoutMs: z
|
|
676
824
|
.number()
|
|
677
825
|
.int()
|
|
@@ -761,7 +909,7 @@ export const KernelConfigSchema = z.object({
|
|
|
761
909
|
description: "Allow OAuth discovery, registration and token endpoints over plain http on loopback hosts (development and tests only; production requires https)",
|
|
762
910
|
})),
|
|
763
911
|
git: z
|
|
764
|
-
.
|
|
912
|
+
.strictObject({
|
|
765
913
|
enabled: z
|
|
766
914
|
.boolean()
|
|
767
915
|
.default(true)
|
|
@@ -845,7 +993,7 @@ export const KernelConfigSchema = z.object({
|
|
|
845
993
|
},
|
|
846
994
|
}),
|
|
847
995
|
channels: z
|
|
848
|
-
.
|
|
996
|
+
.strictObject({
|
|
849
997
|
leaseTtlMs: z
|
|
850
998
|
.number()
|
|
851
999
|
.int()
|
|
@@ -924,7 +1072,7 @@ export const KernelConfigSchema = z.object({
|
|
|
924
1072
|
webhookMaxBodyBytes: 1_048_576,
|
|
925
1073
|
}),
|
|
926
1074
|
storage: z
|
|
927
|
-
.
|
|
1075
|
+
.strictObject({
|
|
928
1076
|
purgeDeletedOrgsAfterDays: z
|
|
929
1077
|
.number()
|
|
930
1078
|
.int()
|
|
@@ -936,7 +1084,7 @@ export const KernelConfigSchema = z.object({
|
|
|
936
1084
|
})
|
|
937
1085
|
.default({ purgeDeletedOrgsAfterDays: 30 }),
|
|
938
1086
|
attachments: z
|
|
939
|
-
.
|
|
1087
|
+
.strictObject({
|
|
940
1088
|
maxBytes: z
|
|
941
1089
|
.number()
|
|
942
1090
|
.int()
|
|
@@ -946,10 +1094,18 @@ export const KernelConfigSchema = z.object({
|
|
|
946
1094
|
description: "Maximum size in bytes of one chat attachment (images are also capped at 5 MiB, the model input limit)",
|
|
947
1095
|
})),
|
|
948
1096
|
allowedTypes: z
|
|
949
|
-
.array(
|
|
1097
|
+
.array(contentType())
|
|
950
1098
|
.min(1)
|
|
951
|
-
.default([...
|
|
952
|
-
.meta(meta({
|
|
1099
|
+
.default([...DEFAULT_ATTACHMENT_TYPES])
|
|
1100
|
+
.meta(meta({
|
|
1101
|
+
description: "Content types accepted for chat attachments (lower-case type/subtype, no parameters)",
|
|
1102
|
+
})),
|
|
1103
|
+
allowedExtensions: z
|
|
1104
|
+
.array(z.string().regex(/^[a-z0-9]{1,12}$/, "must be a lower-case extension without a dot"))
|
|
1105
|
+
.default([...DEFAULT_ATTACHMENT_EXTENSIONS])
|
|
1106
|
+
.meta(meta({
|
|
1107
|
+
description: "File extensions accepted for chat attachments in addition to allowedTypes (lower case, no dot): office documents, archives and source files, whose content types differ between browsers and systems",
|
|
1108
|
+
})),
|
|
953
1109
|
maxPerMessage: z
|
|
954
1110
|
.number()
|
|
955
1111
|
.int()
|
|
@@ -985,7 +1141,7 @@ export const KernelConfigSchema = z.object({
|
|
|
985
1141
|
})
|
|
986
1142
|
.prefault({}),
|
|
987
1143
|
subagents: z
|
|
988
|
-
.
|
|
1144
|
+
.strictObject({
|
|
989
1145
|
maxDepth: z
|
|
990
1146
|
.number()
|
|
991
1147
|
.int()
|
|
@@ -1029,7 +1185,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1029
1185
|
})
|
|
1030
1186
|
.prefault({}),
|
|
1031
1187
|
skills: z
|
|
1032
|
-
.
|
|
1188
|
+
.strictObject({
|
|
1033
1189
|
catalogBudgetChars: z
|
|
1034
1190
|
.number()
|
|
1035
1191
|
.int()
|
|
@@ -1043,7 +1199,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1043
1199
|
})
|
|
1044
1200
|
.prefault({}),
|
|
1045
1201
|
attribution: z
|
|
1046
|
-
.
|
|
1202
|
+
.strictObject({
|
|
1047
1203
|
commit: z
|
|
1048
1204
|
.string()
|
|
1049
1205
|
.max(500)
|
|
@@ -1072,9 +1228,9 @@ export const KernelConfigSchema = z.object({
|
|
|
1072
1228
|
})
|
|
1073
1229
|
.prefault({}),
|
|
1074
1230
|
web: z
|
|
1075
|
-
.
|
|
1231
|
+
.strictObject({
|
|
1076
1232
|
search: z
|
|
1077
|
-
.
|
|
1233
|
+
.strictObject({
|
|
1078
1234
|
maxResults: z
|
|
1079
1235
|
.number()
|
|
1080
1236
|
.int()
|
|
@@ -1088,7 +1244,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1088
1244
|
})
|
|
1089
1245
|
.prefault({}),
|
|
1090
1246
|
fetch: z
|
|
1091
|
-
.
|
|
1247
|
+
.strictObject({
|
|
1092
1248
|
maxPageChars: z
|
|
1093
1249
|
.number()
|
|
1094
1250
|
.int()
|
|
@@ -1130,7 +1286,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1130
1286
|
})
|
|
1131
1287
|
.prefault({}),
|
|
1132
1288
|
schedules: z
|
|
1133
|
-
.
|
|
1289
|
+
.strictObject({
|
|
1134
1290
|
minIntervalFloorMinutes: z
|
|
1135
1291
|
.number()
|
|
1136
1292
|
.int()
|
|
@@ -1170,7 +1326,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1170
1326
|
})
|
|
1171
1327
|
.prefault({}),
|
|
1172
1328
|
sandbox: z
|
|
1173
|
-
.
|
|
1329
|
+
.strictObject({
|
|
1174
1330
|
image: z
|
|
1175
1331
|
.string()
|
|
1176
1332
|
.min(1)
|
|
@@ -1204,7 +1360,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1204
1360
|
description: "Largest file in bytes an agent may deliver from its sandbox to the user as an artifact (Deliver)",
|
|
1205
1361
|
})),
|
|
1206
1362
|
background: z
|
|
1207
|
-
.
|
|
1363
|
+
.strictObject({
|
|
1208
1364
|
maxTasks: z
|
|
1209
1365
|
.number()
|
|
1210
1366
|
.int()
|
|
@@ -1238,7 +1394,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1238
1394
|
* purpose `review` no classifier runs and an unsure command is asked about.
|
|
1239
1395
|
*/
|
|
1240
1396
|
review: z
|
|
1241
|
-
.
|
|
1397
|
+
.strictObject({
|
|
1242
1398
|
timeoutMs: z
|
|
1243
1399
|
.number()
|
|
1244
1400
|
.int()
|
|
@@ -1260,7 +1416,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1260
1416
|
})
|
|
1261
1417
|
.prefault({}),
|
|
1262
1418
|
limits: z
|
|
1263
|
-
.
|
|
1419
|
+
.strictObject({
|
|
1264
1420
|
cpu: z
|
|
1265
1421
|
.number()
|
|
1266
1422
|
.positive()
|
|
@@ -1350,7 +1506,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1350
1506
|
})
|
|
1351
1507
|
.prefault({}),
|
|
1352
1508
|
devices: z
|
|
1353
|
-
.
|
|
1509
|
+
.strictObject({
|
|
1354
1510
|
/**
|
|
1355
1511
|
* The platform's auto-mode switch (auto mode spec §4.3): whether a device may run in auto
|
|
1356
1512
|
* mode; when off, a cloud device keeps its org's cloudNetwork (open by default). Also a deployment setting the super admin changes
|
|
@@ -1376,7 +1532,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1376
1532
|
description: "Most personal devices a member may have in one org, the default one and local devices included; creating one more fails with device.limit_reached",
|
|
1377
1533
|
})),
|
|
1378
1534
|
local: z
|
|
1379
|
-
.
|
|
1535
|
+
.strictObject({
|
|
1380
1536
|
reconnectGraceSeconds: z
|
|
1381
1537
|
.number()
|
|
1382
1538
|
.int()
|
|
@@ -1423,7 +1579,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1423
1579
|
})
|
|
1424
1580
|
.prefault({}),
|
|
1425
1581
|
evals: z
|
|
1426
|
-
.
|
|
1582
|
+
.strictObject({
|
|
1427
1583
|
orgConcurrency: z
|
|
1428
1584
|
.number()
|
|
1429
1585
|
.int()
|
|
@@ -1489,7 +1645,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1489
1645
|
})
|
|
1490
1646
|
.prefault({}),
|
|
1491
1647
|
models: z
|
|
1492
|
-
.
|
|
1648
|
+
.strictObject({
|
|
1493
1649
|
listTimeoutMs: z
|
|
1494
1650
|
.number()
|
|
1495
1651
|
.int()
|
|
@@ -1513,7 +1669,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1513
1669
|
})
|
|
1514
1670
|
.prefault({}),
|
|
1515
1671
|
hooks: z
|
|
1516
|
-
.
|
|
1672
|
+
.strictObject({
|
|
1517
1673
|
timeoutMs: z
|
|
1518
1674
|
.number()
|
|
1519
1675
|
.int()
|
|
@@ -1535,7 +1691,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1535
1691
|
})
|
|
1536
1692
|
.prefault({}),
|
|
1537
1693
|
log: z
|
|
1538
|
-
.
|
|
1694
|
+
.strictObject({
|
|
1539
1695
|
level: z
|
|
1540
1696
|
.enum(LOG_LEVELS)
|
|
1541
1697
|
.default("info")
|
|
@@ -1547,7 +1703,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1547
1703
|
description: "Console log format: pretty (one readable line per record, colored on a terminal), json (one JSON line per record) or auto (pretty when stdout is a terminal, else json, so containers log JSON)",
|
|
1548
1704
|
})),
|
|
1549
1705
|
loki: z
|
|
1550
|
-
.
|
|
1706
|
+
.strictObject({
|
|
1551
1707
|
url: z
|
|
1552
1708
|
.url({ protocol: /^https?$/ })
|
|
1553
1709
|
.optional()
|
|
@@ -56,6 +56,8 @@ export interface AttachmentView {
|
|
|
56
56
|
export interface AttachmentLimits {
|
|
57
57
|
/** 允许的内容类型。 */
|
|
58
58
|
types: string[];
|
|
59
|
+
/** 与 `types` 并列的允许扩展名(小写、不带点)。 */
|
|
60
|
+
extensions: string[];
|
|
59
61
|
/** 非图片的单个上限(字节)。 */
|
|
60
62
|
maxBytes: number;
|
|
61
63
|
/** 图片的单个上限(字节,另受 `MEDIA_LIMITS.imageBytes` 限制)。 */
|
|
@@ -83,7 +85,12 @@ export interface CreatedAttachment {
|
|
|
83
85
|
}
|
|
84
86
|
/** 去掉参数、转小写:`Text/Plain; charset=utf-8` → `text/plain`。 */
|
|
85
87
|
export declare const normalizeContentType: (ct: string) => string;
|
|
86
|
-
/**
|
|
88
|
+
/**
|
|
89
|
+
* Whether the head of the file matches the declared content type. Images, a PDF, a zip and the
|
|
90
|
+
* Office formats (which are zips themselves) are checked by signature; text and JSON must not
|
|
91
|
+
* contain a NUL byte. Any other accepted type has no signature to check, so it passes (its bytes are
|
|
92
|
+
* never rendered: only images and a PDF are served inline).
|
|
93
|
+
*/
|
|
87
94
|
export declare function sniffMatches(contentType: string, head: Uint8Array): boolean;
|
|
88
95
|
/**
|
|
89
96
|
* PDF 的页数:数未压缩的页对象(`/Type /Page`,不含 `/Pages`)。页对象放在压缩的对象流里时数不到,返回 0。
|
|
@@ -157,8 +164,8 @@ export declare class AttachmentsService {
|
|
|
157
164
|
/** 下载 / 取字节时核对 etag:finalize 记下的与当前对象的不一致 → 内容被替换(记 warn)。没有记录时不核对。 */
|
|
158
165
|
private sameContent;
|
|
159
166
|
/**
|
|
160
|
-
* 构建模型请求时查附件行的声明信息(只含绑定在该会话、已 ready
|
|
161
|
-
*
|
|
167
|
+
* 构建模型请求时查附件行的声明信息(只含绑定在该会话、已 ready 的):大小、PDF 页数,以及对象的无签名引用
|
|
168
|
+
* (`ObjectStore.uri`,存储没有时退回 `capybara://attachments/<id>`)。没有行的不在结果里;查询失败照常抛出。
|
|
162
169
|
*/
|
|
163
170
|
mediaInfo(orgId: string, conversationId: string, ids: readonly string[]): Promise<Map<string, MediaInfo>>;
|
|
164
171
|
/**
|
|
@@ -8,7 +8,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
10
|
import { randomUUID } from "node:crypto";
|
|
11
|
-
import {
|
|
11
|
+
import { MEDIA_LIMITS } from "@capybara-hq/plugin-sdk";
|
|
12
12
|
import { Inject, Injectable } from "@nestjs/common";
|
|
13
13
|
import { sql } from "kysely";
|
|
14
14
|
import { ApiError } from "../errors.js";
|
|
@@ -21,6 +21,7 @@ import { LockedCron } from "../infra/schedule/locked-cron.decorator.js";
|
|
|
21
21
|
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
22
22
|
import { StorageService } from "../storage/storage.service.js";
|
|
23
23
|
import { ConversationAccess } from "./access.js";
|
|
24
|
+
import { acceptedContent, isImageContentType, isMediaContentType } from "./media-types.js";
|
|
24
25
|
/** 预签名上传的有效期(秒)。尽量短:表单在有效期内可被再次使用(内容替换由 etag 核对兜底)。 */
|
|
25
26
|
export const ATTACHMENT_UPLOAD_TTL_SECONDS = 300;
|
|
26
27
|
/** 下载跳转的预签名有效期(秒);不短于 {@link ATTACHMENT_DOWNLOAD_CACHE_SECONDS}(浏览器缓存的跳转仍可用)。 */
|
|
@@ -64,7 +65,6 @@ const SNIFF_BYTES = 1024;
|
|
|
64
65
|
const notFound = () => new ApiError("attachment.not_found", "Attachment not found");
|
|
65
66
|
/** 去掉参数、转小写:`Text/Plain; charset=utf-8` → `text/plain`。 */
|
|
66
67
|
export const normalizeContentType = (ct) => (ct.split(";")[0] ?? "").trim().toLowerCase();
|
|
67
|
-
const isImage = (ct) => IMAGE_MEDIA_TYPES.includes(ct);
|
|
68
68
|
/** 对象键:只用附件 id,用户的文件名不进键。技能包另放 `skill-packages/<id>`。 */
|
|
69
69
|
const objectKey = (id, purpose = "chat") => purpose === "chat"
|
|
70
70
|
? `attachments/${id}`
|
|
@@ -73,7 +73,12 @@ const objectKey = (id, purpose = "chat") => purpose === "chat"
|
|
|
73
73
|
: `skill-packages/${id}`;
|
|
74
74
|
const startsWith = (b, sig, at = 0) => sig.every((x, i) => b[at + i] === x);
|
|
75
75
|
const ascii = (s) => [...s].map((c) => c.charCodeAt(0));
|
|
76
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* Whether the head of the file matches the declared content type. Images, a PDF, a zip and the
|
|
78
|
+
* Office formats (which are zips themselves) are checked by signature; text and JSON must not
|
|
79
|
+
* contain a NUL byte. Any other accepted type has no signature to check, so it passes (its bytes are
|
|
80
|
+
* never rendered: only images and a PDF are served inline).
|
|
81
|
+
*/
|
|
77
82
|
export function sniffMatches(contentType, head) {
|
|
78
83
|
switch (contentType) {
|
|
79
84
|
case "image/png":
|
|
@@ -87,10 +92,15 @@ export function sniffMatches(contentType, head) {
|
|
|
87
92
|
case "application/pdf":
|
|
88
93
|
return Buffer.from(head.buffer, head.byteOffset, head.byteLength).includes("%PDF-");
|
|
89
94
|
case "application/zip":
|
|
90
|
-
|
|
95
|
+
case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
|
|
96
|
+
case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
|
|
97
|
+
case "application/vnd.openxmlformats-officedocument.presentationml.presentation":
|
|
98
|
+
// the local file header, or an empty zip's end of central directory (OOXML files are zips)
|
|
91
99
|
return (startsWith(head, [0x50, 0x4b, 0x03, 0x04]) || startsWith(head, [0x50, 0x4b, 0x05, 0x06]));
|
|
92
|
-
|
|
100
|
+
case "application/json":
|
|
93
101
|
return !head.includes(0);
|
|
102
|
+
default:
|
|
103
|
+
return contentType.startsWith("text/") ? !head.includes(0) : true;
|
|
94
104
|
}
|
|
95
105
|
}
|
|
96
106
|
/**
|
|
@@ -128,13 +138,14 @@ let AttachmentsService = class AttachmentsService {
|
|
|
128
138
|
/** 单个附件的大小上限:配置的 `maxBytes`,图片再受 `MEDIA_LIMITS.imageBytes` 限制。 */
|
|
129
139
|
limitFor(contentType) {
|
|
130
140
|
const { maxBytes } = this.config.get().attachments;
|
|
131
|
-
return Math.min(maxBytes,
|
|
141
|
+
return Math.min(maxBytes, isImageContentType(contentType) ? MEDIA_LIMITS.imageBytes : MEDIA_LIMITS.documentBytes);
|
|
132
142
|
}
|
|
133
143
|
/** 当前配置下的上限(不需要对象存储)。 */
|
|
134
144
|
limits() {
|
|
135
145
|
const cfg = this.config.get().attachments;
|
|
136
146
|
return {
|
|
137
147
|
types: [...cfg.allowedTypes],
|
|
148
|
+
extensions: [...cfg.allowedExtensions],
|
|
138
149
|
maxBytes: Math.min(cfg.maxBytes, MEDIA_LIMITS.documentBytes),
|
|
139
150
|
imageMaxBytes: Math.min(cfg.maxBytes, MEDIA_LIMITS.imageBytes),
|
|
140
151
|
maxPerMessage: cfg.maxPerMessage,
|
|
@@ -304,7 +315,7 @@ let AttachmentsService = class AttachmentsService {
|
|
|
304
315
|
if (!head || !this.sameContent(row.etag, head.etag, { orgId, attachmentId: id })) {
|
|
305
316
|
throw notFound();
|
|
306
317
|
}
|
|
307
|
-
const inline =
|
|
318
|
+
const inline = isImageContentType(row.content_type) || row.content_type === "application/pdf";
|
|
308
319
|
return store.presignGet(row.object_key, {
|
|
309
320
|
ttlSeconds: ATTACHMENT_DOWNLOAD_TTL_SECONDS,
|
|
310
321
|
downloadName: row.name,
|
|
@@ -386,6 +397,7 @@ let AttachmentsService = class AttachmentsService {
|
|
|
386
397
|
"conversation_id",
|
|
387
398
|
"name",
|
|
388
399
|
"content_type",
|
|
400
|
+
"size",
|
|
389
401
|
"status",
|
|
390
402
|
sql `expires_at IS NOT NULL AND expires_at <= now()`.as("expired"),
|
|
391
403
|
])
|
|
@@ -420,14 +432,26 @@ let AttachmentsService = class AttachmentsService {
|
|
|
420
432
|
if (r.conversation_id === null)
|
|
421
433
|
toBind.push(id);
|
|
422
434
|
const source = { kind: "ref", attachmentId: id };
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
435
|
+
const size = Number(r.size);
|
|
436
|
+
// The model reads images, PDFs and text files itself; every other accepted type becomes a
|
|
437
|
+
// `file` block the model only gets a reference to (the bytes stay in the object store).
|
|
438
|
+
blocks.push(isImageContentType(r.content_type)
|
|
439
|
+
? {
|
|
440
|
+
type: "image",
|
|
427
441
|
mediaType: r.content_type,
|
|
428
442
|
source,
|
|
429
443
|
name: r.name,
|
|
430
|
-
|
|
444
|
+
size,
|
|
445
|
+
}
|
|
446
|
+
: isMediaContentType(r.content_type)
|
|
447
|
+
? {
|
|
448
|
+
type: "document",
|
|
449
|
+
mediaType: r.content_type,
|
|
450
|
+
source,
|
|
451
|
+
name: r.name,
|
|
452
|
+
size,
|
|
453
|
+
}
|
|
454
|
+
: { type: "file", mediaType: r.content_type, source, name: r.name, size });
|
|
431
455
|
}
|
|
432
456
|
if (toBind.length > 0) {
|
|
433
457
|
await trx
|
|
@@ -446,22 +470,31 @@ let AttachmentsService = class AttachmentsService {
|
|
|
446
470
|
return false;
|
|
447
471
|
}
|
|
448
472
|
/**
|
|
449
|
-
* 构建模型请求时查附件行的声明信息(只含绑定在该会话、已 ready
|
|
450
|
-
*
|
|
473
|
+
* 构建模型请求时查附件行的声明信息(只含绑定在该会话、已 ready 的):大小、PDF 页数,以及对象的无签名引用
|
|
474
|
+
* (`ObjectStore.uri`,存储没有时退回 `capybara://attachments/<id>`)。没有行的不在结果里;查询失败照常抛出。
|
|
451
475
|
*/
|
|
452
476
|
async mediaInfo(orgId, conversationId, ids) {
|
|
453
477
|
if (ids.length === 0)
|
|
454
478
|
return new Map();
|
|
455
479
|
const rows = await this.db
|
|
456
480
|
.selectFrom("attachments")
|
|
457
|
-
.select(["id", "size", "pages", "etag"])
|
|
481
|
+
.select(["id", "size", "pages", "etag", "object_key"])
|
|
458
482
|
.where("org_id", "=", orgId)
|
|
459
483
|
.where("conversation_id", "=", conversationId)
|
|
460
484
|
.where("purpose", "=", "chat")
|
|
461
485
|
.where("status", "=", "ready")
|
|
462
486
|
.where("id", "in", [...ids])
|
|
463
487
|
.execute();
|
|
464
|
-
|
|
488
|
+
const store = this.storage.kernel(orgId);
|
|
489
|
+
return new Map(rows.map((r) => [
|
|
490
|
+
r.id,
|
|
491
|
+
{
|
|
492
|
+
size: Number(r.size),
|
|
493
|
+
pages: r.pages,
|
|
494
|
+
etag: r.etag,
|
|
495
|
+
uri: store.uri?.(r.object_key) ?? `capybara://attachments/${r.id}`,
|
|
496
|
+
},
|
|
497
|
+
]));
|
|
465
498
|
}
|
|
466
499
|
/**
|
|
467
500
|
* 构建模型请求时取附件字节:只取绑定在该会话、已 ready 的附件。只有「确定不存在」才为 null:没有行、对象已不在、
|