@capybara-hq/kernel 0.1.0-rc.36 → 0.1.0-rc.37
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 -3
- package/dist/admin/admin.module.js +6 -6
- 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/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 +53 -47
- package/dist/config/schema.js +190 -40
- 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/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.js +1 -2
- package/dist/ctx/secrets.d.ts +24 -7
- package/dist/ctx/secrets.js +97 -30
- package/dist/db/kernel-schema.d.ts +17 -6
- package/dist/errors.d.ts +5 -2
- package/dist/errors.js +5 -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/host.d.ts +2 -3
- package/dist/extensions/host.js +1 -5
- 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 +2 -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/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/orgs/orgs.module.d.ts +2 -2
- package/dist/orgs/orgs.module.js +2 -2
- 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 +3 -7
- package/dist/overrides.js +2 -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 +5 -3
- package/dist/platform/ops/orgs.ops.js +19 -4
- package/dist/platform/ops/outbox.ops.js +5 -5
- package/dist/roles/worker-role.d.ts +2 -3
- package/dist/roles/worker-role.js +3 -13
- 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 +1 -0
- 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.js +4 -3
- 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/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/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/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 +56 -0
- package/dist/tools/drift.d.ts +1 -1
- package/dist/tools/drift.js +1 -1
- 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 +16 -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/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,7 @@ export const KernelConfigSchema = z.object({
|
|
|
391
533
|
})
|
|
392
534
|
.prefault({}),
|
|
393
535
|
net: z
|
|
394
|
-
.
|
|
536
|
+
.strictObject({
|
|
395
537
|
httpsProxy: z
|
|
396
538
|
.string()
|
|
397
539
|
.superRefine((value, ctx) => {
|
|
@@ -422,7 +564,7 @@ export const KernelConfigSchema = z.object({
|
|
|
422
564
|
})
|
|
423
565
|
.prefault({}),
|
|
424
566
|
extensionPermissions: z
|
|
425
|
-
.
|
|
567
|
+
.strictObject({
|
|
426
568
|
autoApprove: z
|
|
427
569
|
.boolean()
|
|
428
570
|
.default(false)
|
|
@@ -432,7 +574,7 @@ export const KernelConfigSchema = z.object({
|
|
|
432
574
|
})
|
|
433
575
|
.default({ autoApprove: false }),
|
|
434
576
|
http: z
|
|
435
|
-
.
|
|
577
|
+
.strictObject({
|
|
436
578
|
port: z
|
|
437
579
|
.number()
|
|
438
580
|
.int()
|
|
@@ -510,7 +652,7 @@ export const KernelConfigSchema = z.object({
|
|
|
510
652
|
description: 'Roles this process runs: a JSON array or a comma-separated string, e.g. ["api"] or api,worker',
|
|
511
653
|
})),
|
|
512
654
|
auth: z
|
|
513
|
-
.
|
|
655
|
+
.strictObject({
|
|
514
656
|
accessTokenTtlSeconds: z
|
|
515
657
|
.number()
|
|
516
658
|
.int()
|
|
@@ -570,7 +712,7 @@ export const KernelConfigSchema = z.object({
|
|
|
570
712
|
trustedIdentitySources: [],
|
|
571
713
|
}),
|
|
572
714
|
runtime: z
|
|
573
|
-
.
|
|
715
|
+
.strictObject({
|
|
574
716
|
maxSteps: z
|
|
575
717
|
.number()
|
|
576
718
|
.int()
|
|
@@ -671,7 +813,7 @@ export const KernelConfigSchema = z.object({
|
|
|
671
813
|
sseRecheckMs: 60000,
|
|
672
814
|
}),
|
|
673
815
|
tools: z
|
|
674
|
-
.
|
|
816
|
+
.strictObject({
|
|
675
817
|
timeoutMs: z
|
|
676
818
|
.number()
|
|
677
819
|
.int()
|
|
@@ -761,7 +903,7 @@ export const KernelConfigSchema = z.object({
|
|
|
761
903
|
description: "Allow OAuth discovery, registration and token endpoints over plain http on loopback hosts (development and tests only; production requires https)",
|
|
762
904
|
})),
|
|
763
905
|
git: z
|
|
764
|
-
.
|
|
906
|
+
.strictObject({
|
|
765
907
|
enabled: z
|
|
766
908
|
.boolean()
|
|
767
909
|
.default(true)
|
|
@@ -845,7 +987,7 @@ export const KernelConfigSchema = z.object({
|
|
|
845
987
|
},
|
|
846
988
|
}),
|
|
847
989
|
channels: z
|
|
848
|
-
.
|
|
990
|
+
.strictObject({
|
|
849
991
|
leaseTtlMs: z
|
|
850
992
|
.number()
|
|
851
993
|
.int()
|
|
@@ -924,7 +1066,7 @@ export const KernelConfigSchema = z.object({
|
|
|
924
1066
|
webhookMaxBodyBytes: 1_048_576,
|
|
925
1067
|
}),
|
|
926
1068
|
storage: z
|
|
927
|
-
.
|
|
1069
|
+
.strictObject({
|
|
928
1070
|
purgeDeletedOrgsAfterDays: z
|
|
929
1071
|
.number()
|
|
930
1072
|
.int()
|
|
@@ -936,7 +1078,7 @@ export const KernelConfigSchema = z.object({
|
|
|
936
1078
|
})
|
|
937
1079
|
.default({ purgeDeletedOrgsAfterDays: 30 }),
|
|
938
1080
|
attachments: z
|
|
939
|
-
.
|
|
1081
|
+
.strictObject({
|
|
940
1082
|
maxBytes: z
|
|
941
1083
|
.number()
|
|
942
1084
|
.int()
|
|
@@ -946,10 +1088,18 @@ export const KernelConfigSchema = z.object({
|
|
|
946
1088
|
description: "Maximum size in bytes of one chat attachment (images are also capped at 5 MiB, the model input limit)",
|
|
947
1089
|
})),
|
|
948
1090
|
allowedTypes: z
|
|
949
|
-
.array(
|
|
1091
|
+
.array(contentType())
|
|
950
1092
|
.min(1)
|
|
951
|
-
.default([...
|
|
952
|
-
.meta(meta({
|
|
1093
|
+
.default([...DEFAULT_ATTACHMENT_TYPES])
|
|
1094
|
+
.meta(meta({
|
|
1095
|
+
description: "Content types accepted for chat attachments (lower-case type/subtype, no parameters)",
|
|
1096
|
+
})),
|
|
1097
|
+
allowedExtensions: z
|
|
1098
|
+
.array(z.string().regex(/^[a-z0-9]{1,12}$/, "must be a lower-case extension without a dot"))
|
|
1099
|
+
.default([...DEFAULT_ATTACHMENT_EXTENSIONS])
|
|
1100
|
+
.meta(meta({
|
|
1101
|
+
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",
|
|
1102
|
+
})),
|
|
953
1103
|
maxPerMessage: z
|
|
954
1104
|
.number()
|
|
955
1105
|
.int()
|
|
@@ -985,7 +1135,7 @@ export const KernelConfigSchema = z.object({
|
|
|
985
1135
|
})
|
|
986
1136
|
.prefault({}),
|
|
987
1137
|
subagents: z
|
|
988
|
-
.
|
|
1138
|
+
.strictObject({
|
|
989
1139
|
maxDepth: z
|
|
990
1140
|
.number()
|
|
991
1141
|
.int()
|
|
@@ -1029,7 +1179,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1029
1179
|
})
|
|
1030
1180
|
.prefault({}),
|
|
1031
1181
|
skills: z
|
|
1032
|
-
.
|
|
1182
|
+
.strictObject({
|
|
1033
1183
|
catalogBudgetChars: z
|
|
1034
1184
|
.number()
|
|
1035
1185
|
.int()
|
|
@@ -1043,7 +1193,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1043
1193
|
})
|
|
1044
1194
|
.prefault({}),
|
|
1045
1195
|
attribution: z
|
|
1046
|
-
.
|
|
1196
|
+
.strictObject({
|
|
1047
1197
|
commit: z
|
|
1048
1198
|
.string()
|
|
1049
1199
|
.max(500)
|
|
@@ -1072,9 +1222,9 @@ export const KernelConfigSchema = z.object({
|
|
|
1072
1222
|
})
|
|
1073
1223
|
.prefault({}),
|
|
1074
1224
|
web: z
|
|
1075
|
-
.
|
|
1225
|
+
.strictObject({
|
|
1076
1226
|
search: z
|
|
1077
|
-
.
|
|
1227
|
+
.strictObject({
|
|
1078
1228
|
maxResults: z
|
|
1079
1229
|
.number()
|
|
1080
1230
|
.int()
|
|
@@ -1088,7 +1238,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1088
1238
|
})
|
|
1089
1239
|
.prefault({}),
|
|
1090
1240
|
fetch: z
|
|
1091
|
-
.
|
|
1241
|
+
.strictObject({
|
|
1092
1242
|
maxPageChars: z
|
|
1093
1243
|
.number()
|
|
1094
1244
|
.int()
|
|
@@ -1130,7 +1280,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1130
1280
|
})
|
|
1131
1281
|
.prefault({}),
|
|
1132
1282
|
schedules: z
|
|
1133
|
-
.
|
|
1283
|
+
.strictObject({
|
|
1134
1284
|
minIntervalFloorMinutes: z
|
|
1135
1285
|
.number()
|
|
1136
1286
|
.int()
|
|
@@ -1170,7 +1320,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1170
1320
|
})
|
|
1171
1321
|
.prefault({}),
|
|
1172
1322
|
sandbox: z
|
|
1173
|
-
.
|
|
1323
|
+
.strictObject({
|
|
1174
1324
|
image: z
|
|
1175
1325
|
.string()
|
|
1176
1326
|
.min(1)
|
|
@@ -1204,7 +1354,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1204
1354
|
description: "Largest file in bytes an agent may deliver from its sandbox to the user as an artifact (Deliver)",
|
|
1205
1355
|
})),
|
|
1206
1356
|
background: z
|
|
1207
|
-
.
|
|
1357
|
+
.strictObject({
|
|
1208
1358
|
maxTasks: z
|
|
1209
1359
|
.number()
|
|
1210
1360
|
.int()
|
|
@@ -1238,7 +1388,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1238
1388
|
* purpose `review` no classifier runs and an unsure command is asked about.
|
|
1239
1389
|
*/
|
|
1240
1390
|
review: z
|
|
1241
|
-
.
|
|
1391
|
+
.strictObject({
|
|
1242
1392
|
timeoutMs: z
|
|
1243
1393
|
.number()
|
|
1244
1394
|
.int()
|
|
@@ -1260,7 +1410,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1260
1410
|
})
|
|
1261
1411
|
.prefault({}),
|
|
1262
1412
|
limits: z
|
|
1263
|
-
.
|
|
1413
|
+
.strictObject({
|
|
1264
1414
|
cpu: z
|
|
1265
1415
|
.number()
|
|
1266
1416
|
.positive()
|
|
@@ -1350,7 +1500,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1350
1500
|
})
|
|
1351
1501
|
.prefault({}),
|
|
1352
1502
|
devices: z
|
|
1353
|
-
.
|
|
1503
|
+
.strictObject({
|
|
1354
1504
|
/**
|
|
1355
1505
|
* The platform's auto-mode switch (auto mode spec §4.3): whether a device may run in auto
|
|
1356
1506
|
* mode; when off, a cloud device keeps its org's cloudNetwork (open by default). Also a deployment setting the super admin changes
|
|
@@ -1376,7 +1526,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1376
1526
|
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
1527
|
})),
|
|
1378
1528
|
local: z
|
|
1379
|
-
.
|
|
1529
|
+
.strictObject({
|
|
1380
1530
|
reconnectGraceSeconds: z
|
|
1381
1531
|
.number()
|
|
1382
1532
|
.int()
|
|
@@ -1423,7 +1573,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1423
1573
|
})
|
|
1424
1574
|
.prefault({}),
|
|
1425
1575
|
evals: z
|
|
1426
|
-
.
|
|
1576
|
+
.strictObject({
|
|
1427
1577
|
orgConcurrency: z
|
|
1428
1578
|
.number()
|
|
1429
1579
|
.int()
|
|
@@ -1489,7 +1639,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1489
1639
|
})
|
|
1490
1640
|
.prefault({}),
|
|
1491
1641
|
models: z
|
|
1492
|
-
.
|
|
1642
|
+
.strictObject({
|
|
1493
1643
|
listTimeoutMs: z
|
|
1494
1644
|
.number()
|
|
1495
1645
|
.int()
|
|
@@ -1513,7 +1663,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1513
1663
|
})
|
|
1514
1664
|
.prefault({}),
|
|
1515
1665
|
hooks: z
|
|
1516
|
-
.
|
|
1666
|
+
.strictObject({
|
|
1517
1667
|
timeoutMs: z
|
|
1518
1668
|
.number()
|
|
1519
1669
|
.int()
|
|
@@ -1535,7 +1685,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1535
1685
|
})
|
|
1536
1686
|
.prefault({}),
|
|
1537
1687
|
log: z
|
|
1538
|
-
.
|
|
1688
|
+
.strictObject({
|
|
1539
1689
|
level: z
|
|
1540
1690
|
.enum(LOG_LEVELS)
|
|
1541
1691
|
.default("info")
|
|
@@ -1547,7 +1697,7 @@ export const KernelConfigSchema = z.object({
|
|
|
1547
1697
|
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
1698
|
})),
|
|
1549
1699
|
loki: z
|
|
1550
|
-
.
|
|
1700
|
+
.strictObject({
|
|
1551
1701
|
url: z
|
|
1552
1702
|
.url({ protocol: /^https?$/ })
|
|
1553
1703
|
.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:没有行、对象已不在、
|