@capybara-hq/kernel 0.1.0-rc.105 → 0.1.0-rc.107
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/dist/admin/admin.schemas.d.ts +3 -0
- package/dist/agents/agents.schemas.d.ts +9 -9
- package/dist/{schedules/schedules.controller.d.ts → automations/automations.controller.d.ts} +37 -32
- package/dist/{schedules/schedules.controller.js → automations/automations.controller.js} +68 -57
- package/dist/automations/automations.module.d.ts +16 -0
- package/dist/{schedules/schedules.module.js → automations/automations.module.js} +18 -15
- package/dist/{schedules/schedules.schemas.d.ts → automations/automations.schemas.d.ts} +151 -50
- package/dist/automations/automations.schemas.js +253 -0
- package/dist/{schedules/scheduled-tasks.service.d.ts → automations/automations.service.d.ts} +99 -52
- package/dist/{schedules/scheduled-tasks.service.js → automations/automations.service.js} +303 -134
- package/dist/{schedules → automations}/calendar.d.ts +8 -8
- package/dist/{schedules → automations}/calendar.js +2 -2
- package/dist/automations/effective-settings.d.ts +28 -0
- package/dist/automations/effective-settings.js +25 -0
- package/dist/automations/errors.d.ts +19 -0
- package/dist/automations/errors.js +19 -0
- package/dist/automations/events/coalesce.d.ts +28 -0
- package/dist/automations/events/coalesce.js +131 -0
- package/dist/automations/events/deadline.d.ts +10 -0
- package/dist/automations/events/deadline.js +24 -0
- package/dist/automations/events/dispatcher.d.ts +74 -0
- package/dist/automations/events/dispatcher.js +353 -0
- package/dist/automations/events/events.module.d.ts +7 -0
- package/dist/automations/events/events.module.js +26 -0
- package/dist/automations/events/guards.d.ts +32 -0
- package/dist/automations/events/guards.js +87 -0
- package/dist/automations/events/sweep.job.d.ts +49 -0
- package/dist/automations/events/sweep.job.js +202 -0
- package/dist/automations/events/token.d.ts +5 -0
- package/dist/automations/events/token.js +5 -0
- package/dist/automations/events/trigger-events.service.d.ts +47 -0
- package/dist/automations/events/trigger-events.service.js +254 -0
- package/dist/{schedules → automations}/fire.d.ts +57 -17
- package/dist/{schedules → automations}/fire.js +311 -79
- package/dist/{schedules → automations}/grant-rules.d.ts +1 -1
- package/dist/{schedules → automations}/grant-rules.js +5 -5
- package/dist/automations/job-ids.d.ts +113 -0
- package/dist/automations/job-ids.js +117 -0
- package/dist/{schedules → automations}/pause.d.ts +3 -3
- package/dist/{schedules → automations}/pause.js +3 -3
- package/dist/{schedules → automations}/run-tracker.d.ts +21 -10
- package/dist/{schedules → automations}/run-tracker.js +68 -56
- package/dist/{schedules → automations}/scan.job.d.ts +12 -8
- package/dist/{schedules → automations}/scan.job.js +39 -23
- package/dist/{schedules → automations}/schedule-math.d.ts +19 -12
- package/dist/{schedules → automations}/schedule-math.js +17 -7
- package/dist/{schedules → automations}/store.d.ts +57 -27
- package/dist/{schedules → automations}/store.js +102 -52
- package/dist/automations/store.module.d.ts +6 -0
- package/dist/{schedules → automations}/store.module.js +9 -9
- package/dist/automations/types.d.ts +178 -0
- package/dist/{schedules → automations}/unattended.d.ts +22 -11
- package/dist/{schedules → automations}/unattended.js +53 -30
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/channels/channels.module.js +7 -6
- package/dist/channels/file-delivery.d.ts +26 -11
- package/dist/channels/file-delivery.js +32 -11
- package/dist/channels/outbound.d.ts +8 -8
- package/dist/channels/outbound.js +32 -30
- package/dist/channels/threads.d.ts +1 -1
- package/dist/channels/threads.js +1 -1
- package/dist/config/schema.d.ts +8 -1
- package/dist/config/schema.js +56 -6
- package/dist/conversations/approval-profile.d.ts +2 -2
- package/dist/conversations/approval-profile.js +3 -3
- package/dist/conversations/artifacts.d.ts +20 -17
- package/dist/conversations/artifacts.js +30 -37
- package/dist/conversations/attachments.controller.d.ts +6 -19
- package/dist/conversations/attachments.controller.js +8 -59
- package/dist/conversations/attachments.service.d.ts +30 -74
- package/dist/conversations/attachments.service.js +51 -193
- package/dist/conversations/conversations.controller.d.ts +7 -1
- package/dist/conversations/conversations.controller.js +26 -10
- package/dist/conversations/conversations.module.js +4 -0
- package/dist/conversations/conversations.service.d.ts +112 -35
- package/dist/conversations/conversations.service.js +160 -43
- package/dist/conversations/event-log.d.ts +1 -0
- package/dist/conversations/events.d.ts +95 -27
- package/dist/conversations/events.js +108 -10
- package/dist/conversations/files.d.ts +66 -64
- package/dist/conversations/files.js +127 -147
- package/dist/conversations/message-context.d.ts +2 -2
- package/dist/conversations/message-context.js +1 -1
- package/dist/conversations/permission-profile-store.d.ts +2 -1
- package/dist/conversations/permission-profiles.controller.d.ts +3 -0
- package/dist/conversations/permission-profiles.service.js +1 -1
- package/dist/conversations/prompt-suggestion-request.d.ts +1 -1
- package/dist/conversations/prompt-suggestion-request.js +4 -2
- package/dist/conversations/prompt-suggestions.d.ts +3 -3
- package/dist/conversations/prompt-suggestions.js +11 -10
- package/dist/conversations/queue.d.ts +7 -4
- package/dist/conversations/queue.js +6 -2
- package/dist/conversations/queue.service.d.ts +5 -5
- package/dist/conversations/queue.service.js +27 -16
- package/dist/ctx/create-ctx.d.ts +23 -2
- package/dist/ctx/create-ctx.js +78 -3
- package/dist/db/kernel-schema.d.ts +184 -27
- package/dist/devices/device-project-files.service.d.ts +88 -0
- package/dist/devices/device-project-files.service.js +249 -0
- package/dist/devices/device-projects.service.d.ts +40 -0
- package/dist/devices/device-projects.service.js +16 -13
- package/dist/devices/devices.controller.d.ts +9 -3
- package/dist/devices/devices.controller.js +27 -5
- package/dist/devices/devices.module.js +9 -1
- package/dist/devices/devices.schemas.js +6 -1
- package/dist/devices/dto.d.ts +15 -0
- package/dist/devices/dto.js +11 -0
- package/dist/devices/project-paths.d.ts +29 -0
- package/dist/devices/project-paths.js +66 -0
- package/dist/devices/project-rules.d.ts +5 -1
- package/dist/devices/project-rules.js +5 -1
- package/dist/errors.d.ts +53 -13
- package/dist/errors.js +53 -13
- package/dist/evals/canonical-json.d.ts +7 -0
- package/dist/evals/canonical-json.js +21 -0
- package/dist/evals/reconstruct.d.ts +10 -1
- package/dist/evals/reconstruct.js +20 -1
- package/dist/evals/recorded-tools.d.ts +0 -2
- package/dist/evals/recorded-tools.js +1 -16
- package/dist/evals/snapshot.d.ts +26 -3
- package/dist/evals/snapshot.js +110 -57
- package/dist/evals/worker.d.ts +4 -3
- package/dist/evals/worker.js +8 -4
- package/dist/extensions/host.d.ts +9 -2
- package/dist/extensions/host.js +12 -0
- package/dist/extensions/instance.d.ts +3 -1
- package/dist/extensions/instance.js +4 -0
- package/dist/extensions/ledger.d.ts +1 -1
- package/dist/extensions/permission-set.d.ts +17 -1
- package/dist/extensions/permission-set.js +13 -1
- package/dist/extensions/permission-view.d.ts +1 -1
- package/dist/extensions/permission-view.js +4 -1
- package/dist/files/blob-objects.d.ts +124 -0
- package/dist/files/blob-objects.js +341 -0
- package/dist/files/blob-sweep.job.d.ts +122 -0
- package/dist/files/blob-sweep.job.js +389 -0
- package/dist/files/blobs.service.d.ts +135 -0
- package/dist/files/blobs.service.js +300 -0
- package/dist/files/conversation-media.d.ts +41 -0
- package/dist/files/conversation-media.js +124 -0
- package/dist/files/deliveries.d.ts +64 -0
- package/dist/files/deliveries.js +156 -0
- package/dist/files/deliveries.module.d.ts +6 -0
- package/dist/files/deliveries.module.js +24 -0
- package/dist/files/draft-cleanup.job.d.ts +26 -0
- package/dist/files/draft-cleanup.job.js +93 -0
- package/dist/files/files.module.d.ts +1 -1
- package/dist/files/files.module.js +3 -2
- package/dist/files/hash-job.d.ts +127 -0
- package/dist/files/hash-job.js +447 -0
- package/dist/files/library-backfill.d.ts +63 -0
- package/dist/files/library-backfill.js +143 -0
- package/dist/files/library-files.service.d.ts +255 -0
- package/dist/files/library-files.service.js +883 -0
- package/dist/files/library-jobs.module.d.ts +8 -0
- package/dist/files/library-jobs.module.js +27 -0
- package/dist/files/library-query.d.ts +127 -0
- package/dist/files/library-query.js +322 -0
- package/dist/files/library-read.module.d.ts +9 -0
- package/dist/files/library-read.module.js +30 -0
- package/dist/files/library.controller.d.ts +77 -0
- package/dist/files/library.controller.js +235 -0
- package/dist/files/library.module.d.ts +9 -0
- package/dist/files/library.module.js +29 -0
- package/dist/files/library.schemas.d.ts +46 -0
- package/dist/files/library.schemas.js +49 -0
- package/dist/files/previewers.controller.d.ts +20 -0
- package/dist/files/previewers.controller.js +47 -0
- package/dist/files/previewers.d.ts +25 -11
- package/dist/files/previewers.js +43 -27
- package/dist/files/referenced-files.d.ts +150 -0
- package/dist/files/referenced-files.js +234 -0
- package/dist/git/gateway.js +2 -2
- package/dist/html/html-document.controller.d.ts +8 -1
- package/dist/html/html-document.controller.js +19 -1
- package/dist/html/html-document.service.d.ts +19 -4
- package/dist/html/html-document.service.js +43 -22
- package/dist/html/html-token.d.ts +10 -1
- package/dist/html/html-token.js +14 -0
- package/dist/html/html.module.js +8 -1
- package/dist/http/api.module.js +10 -5
- package/dist/http/request-signal.d.ts +8 -0
- package/dist/http/request-signal.js +14 -0
- package/dist/identity/settings.d.ts +26 -0
- package/dist/identity/settings.js +33 -2
- package/dist/inbox/inbox.module.js +2 -2
- package/dist/inbox/inbox.service.d.ts +8 -8
- package/dist/inbox/inbox.service.js +7 -7
- package/dist/infra/config/kernel-config.service.js +10 -5
- package/dist/infra/outbox/registry.d.ts +111 -2
- package/dist/infra/outbox/registry.js +104 -9
- package/dist/infra/throttler/named-throttlers.d.ts +2 -0
- package/dist/infra/throttler/named-throttlers.js +14 -0
- package/dist/kernel.module.js +3 -0
- package/dist/lifecycle/kernel-lifecycle.js +6 -0
- package/dist/models/purposes.js +1 -1
- package/dist/orgs/offboarding.js +1 -1
- package/dist/orgs/roles.d.ts +1 -1
- package/dist/orgs/roles.js +3 -3
- package/dist/orgs/settings.controller.d.ts +1 -1
- package/dist/orgs/settings.service.d.ts +75 -13
- package/dist/orgs/settings.service.js +104 -26
- package/dist/platform/exclusions.js +45 -8
- package/dist/platform/file-ref.d.ts +18 -3
- package/dist/platform/file-ref.js +22 -11
- package/dist/platform/operation.js +6 -2
- package/dist/platform/ops/admin.ops.js +5 -2
- package/dist/platform/ops/{schedules.ops.d.ts → automations.ops.d.ts} +4 -4
- package/dist/platform/ops/automations.ops.js +560 -0
- package/dist/platform/ops/devices.ops.d.ts +3 -1
- package/dist/platform/ops/devices.ops.js +77 -3
- package/dist/platform/ops/files.ops.d.ts +18 -0
- package/dist/platform/ops/files.ops.js +267 -0
- package/dist/platform/ops/inbox.ops.js +4 -4
- package/dist/platform/ops/org-settings.ops.js +6 -2
- package/dist/platform/ops/orgs.ops.js +2 -1
- package/dist/platform/ops/platform.ops.js +4 -4
- package/dist/platform/ops/shares.ops.js +2 -2
- package/dist/platform/platform-ops.module.d.ts +3 -2
- package/dist/platform/platform-ops.module.js +10 -5
- package/dist/platform/route-schemas.js +6 -3
- package/dist/push/jobs.d.ts +3 -3
- package/dist/push/jobs.js +2 -2
- package/dist/push/preferences.service.js +1 -1
- package/dist/push/push-owed.d.ts +3 -3
- package/dist/push/push-owed.js +6 -6
- package/dist/push/push.schemas.d.ts +4 -4
- package/dist/push/push.schemas.js +3 -3
- package/dist/push/recipients.d.ts +4 -4
- package/dist/push/recipients.js +23 -23
- package/dist/push/texts.d.ts +3 -3
- package/dist/push/texts.js +2 -2
- package/dist/push/triggers.d.ts +1 -1
- package/dist/roles/worker.module.js +18 -4
- package/dist/runtime/compaction-settings.service.d.ts +13 -1
- package/dist/runtime/compaction-settings.service.js +16 -1
- package/dist/runtime/compaction.service.d.ts +3 -1
- package/dist/runtime/compaction.service.js +3 -1
- package/dist/runtime/context/build.d.ts +24 -1
- package/dist/runtime/context/build.js +33 -11
- package/dist/runtime/context/cache-expiry.d.ts +31 -0
- package/dist/runtime/context/cache-expiry.js +60 -0
- package/dist/runtime/context/cache-ttl.d.ts +18 -0
- package/dist/runtime/context/cache-ttl.js +30 -0
- package/dist/runtime/context/compaction.d.ts +9 -2
- package/dist/runtime/context/compaction.js +64 -21
- package/dist/runtime/context/in-context-compaction.d.ts +156 -0
- package/dist/runtime/context/in-context-compaction.js +310 -0
- package/dist/runtime/context/run-context.d.ts +38 -0
- package/dist/runtime/context/run-context.js +54 -0
- package/dist/runtime/hook-calls.d.ts +2 -1
- package/dist/runtime/hook-calls.js +5 -2
- package/dist/runtime/maintenance.d.ts +16 -4
- package/dist/runtime/maintenance.js +79 -18
- package/dist/runtime/model-call.d.ts +34 -5
- package/dist/runtime/model-call.js +207 -22
- package/dist/runtime/providers.js +11 -1
- package/dist/runtime/run-finish.d.ts +4 -4
- package/dist/runtime/run-finish.js +3 -3
- package/dist/runtime/run-queue.js +12 -7
- package/dist/runtime/run-steps.d.ts +4 -2
- package/dist/runtime/run-steps.js +10 -5
- package/dist/runtime/run-worker.js +7 -1
- package/dist/runtime/runtime.module.js +6 -3
- package/dist/runtime/subagents/dispatch.js +11 -3
- package/dist/sandbox/browse-roots.d.ts +8 -0
- package/dist/sandbox/browse-roots.js +22 -0
- package/dist/sandbox/network-grants.d.ts +4 -4
- package/dist/sandbox/network-grants.js +7 -7
- package/dist/sandbox/operation-authority.d.ts +10 -3
- package/dist/sandbox/operation-authority.js +20 -10
- package/dist/sandbox/operation-intents.d.ts +3 -1
- package/dist/sandbox/operation-intents.js +11 -4
- package/dist/sandbox/permission-call-grants.js +2 -2
- package/dist/sandbox/permission-facts.js +1 -1
- package/dist/sandbox/review/classifier.d.ts +2 -2
- package/dist/sandbox/review/classifier.js +22 -11
- package/dist/sandbox/review/permission-candidate.d.ts +1 -1
- package/dist/sandbox/review/permission-candidate.js +1 -1
- package/dist/sandbox/sandbox.service.d.ts +15 -5
- package/dist/sandbox/sandbox.service.js +14 -8
- package/dist/shares/liveness.d.ts +26 -12
- package/dist/shares/liveness.js +79 -20
- package/dist/shares/revoke.d.ts +16 -11
- package/dist/shares/revoke.js +18 -14
- package/dist/shares/share-objects.d.ts +16 -21
- package/dist/shares/share-objects.js +25 -55
- package/dist/shares/share-open.service.d.ts +8 -4
- package/dist/shares/share-open.service.js +14 -11
- package/dist/shares/shares.controller.d.ts +16 -5
- package/dist/shares/shares.controller.js +39 -5
- package/dist/shares/shares.module.d.ts +4 -4
- package/dist/shares/shares.module.js +7 -6
- package/dist/shares/shares.schemas.d.ts +4 -0
- package/dist/shares/shares.schemas.js +2 -0
- package/dist/shares/shares.service.d.ts +93 -54
- package/dist/shares/shares.service.js +292 -131
- package/dist/shares/sweep.job.d.ts +18 -39
- package/dist/shares/sweep.job.js +47 -206
- package/dist/storage/purge.d.ts +1 -1
- package/dist/storage/purge.js +2 -2
- package/dist/tools/approvals.service.d.ts +6 -6
- package/dist/tools/approvals.service.js +19 -19
- package/dist/tools/builtin-names.d.ts +12 -12
- package/dist/tools/builtin-names.js +29 -29
- package/dist/tools/builtins/artifacts.d.ts +21 -13
- package/dist/tools/builtins/artifacts.js +81 -51
- package/dist/tools/builtins/{schedules.d.ts → automations.d.ts} +35 -33
- package/dist/tools/builtins/{schedules.js → automations.js} +236 -105
- package/dist/tools/builtins/builtin-tools.d.ts +15 -9
- package/dist/tools/builtins/builtin-tools.js +33 -22
- package/dist/tools/builtins/conversation-files.d.ts +23 -13
- package/dist/tools/builtins/conversation-files.js +62 -83
- package/dist/tools/builtins/image/generate.d.ts +7 -1
- package/dist/tools/builtins/image/generate.js +1 -1
- package/dist/tools/builtins/platform.js +1 -0
- package/dist/tools/builtins/sandbox/common.d.ts +6 -2
- package/dist/tools/builtins/sandbox/deliver.js +6 -7
- package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +6 -5
- package/dist/tools/builtins/sandbox/fetch-attachment.js +19 -12
- package/dist/tools/call-scope.d.ts +1 -1
- package/dist/tools/git-asks.js +1 -1
- package/dist/tools/git-push-policy.d.ts +3 -3
- package/dist/tools/git-push-policy.js +6 -6
- package/dist/tools/network-asks.d.ts +3 -3
- package/dist/tools/network-asks.js +3 -3
- package/dist/tools/pipeline.d.ts +4 -4
- package/dist/tools/pipeline.js +2 -2
- package/dist/tools/policy.d.ts +3 -3
- package/dist/tools/policy.js +3 -3
- package/dist/tools/tools.module.js +15 -9
- package/dist/ui/call-extension.d.ts +6 -4
- package/dist/ui/call-extension.js +5 -4
- package/dist/ui/embed-token.js +6 -3
- package/dist/ui/registry.d.ts +21 -5
- package/dist/ui/registry.js +24 -6
- package/dist/ui/ui.schemas.d.ts +22 -0
- package/dist/ui/ui.schemas.js +22 -4
- package/dist/ui/views.controller.d.ts +13 -3
- package/dist/ui/views.controller.js +33 -2
- package/dist/ui/views.d.ts +29 -1
- package/dist/ui/views.js +131 -7
- package/package.json +3 -3
- package/src/migrations/0188_automations_rename.sql +309 -0
- package/src/migrations/0189_event_automations.sql +136 -0
- package/src/migrations/0190_file_library.sql +285 -0
- package/src/migrations/0191_file_library_copy.sql +4 -0
- package/dist/platform/ops/schedules.ops.js +0 -509
- package/dist/schedules/effective-settings.d.ts +0 -22
- package/dist/schedules/effective-settings.js +0 -18
- package/dist/schedules/errors.d.ts +0 -8
- package/dist/schedules/errors.js +0 -8
- package/dist/schedules/job-ids.d.ts +0 -81
- package/dist/schedules/job-ids.js +0 -95
- package/dist/schedules/schedules.module.d.ts +0 -16
- package/dist/schedules/schedules.schemas.js +0 -213
- package/dist/schedules/store.module.d.ts +0 -6
- package/dist/schedules/types.d.ts +0 -110
- /package/dist/{schedules → automations}/types.js +0 -0
|
@@ -8,7 +8,6 @@ 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 { MEDIA_LIMITS } from "@capybara-hq/plugin-sdk";
|
|
12
11
|
import { Inject, Injectable } from "@nestjs/common";
|
|
13
12
|
import { sql } from "kysely";
|
|
14
13
|
import { ApiError } from "../errors.js";
|
|
@@ -23,7 +22,7 @@ import { LockedCron } from "../infra/schedule/locked-cron.decorator.js";
|
|
|
23
22
|
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
24
23
|
import { StorageService } from "../storage/storage.service.js";
|
|
25
24
|
import { ConversationAccess } from "./access.js";
|
|
26
|
-
import {
|
|
25
|
+
import { isImageContentType } from "./media-types.js";
|
|
27
26
|
import { fitImageForModel, MODEL_IMAGE_CACHE_SECONDS, modelImageKey, parseModelImage, serializeModelImage, } from "./model-image.js";
|
|
28
27
|
/** 预签名上传的有效期(秒)。尽量短:表单在有效期内可被再次使用(内容替换由 etag 核对兜底)。 */
|
|
29
28
|
export const ATTACHMENT_UPLOAD_TTL_SECONDS = 300;
|
|
@@ -31,8 +30,6 @@ export const ATTACHMENT_UPLOAD_TTL_SECONDS = 300;
|
|
|
31
30
|
export const ATTACHMENT_DOWNLOAD_TTL_SECONDS = 300;
|
|
32
31
|
/** 下载 302 的 `Cache-Control: private, max-age=…`(秒):同一页面里缩略图可复用跳转地址。 */
|
|
33
32
|
export const ATTACHMENT_DOWNLOAD_CACHE_SECONDS = 60;
|
|
34
|
-
/** 同一账号在一个组织里最多的未 finalize 附件数(超过 → 429 `attachment.too_many_pending`)。 */
|
|
35
|
-
export const MAX_PENDING_ATTACHMENTS = 50;
|
|
36
33
|
/** 技能包 zip 的内容类型(上传时一律按它签名,finalize 时核对 zip 文件头)。 */
|
|
37
34
|
export const SKILL_PACKAGE_CONTENT_TYPE = "application/zip";
|
|
38
35
|
/** 技能包 zip 的大小上限(字节)。 */
|
|
@@ -83,23 +80,22 @@ export function attachmentContentMatches(recorded, head) {
|
|
|
83
80
|
}
|
|
84
81
|
const notFound = () => new ApiError("attachment.not_found", "Attachment not found");
|
|
85
82
|
/**
|
|
86
|
-
* The
|
|
87
|
-
*
|
|
83
|
+
* The one purpose conversations read here: the `read` copies of the builtin Read and of tool
|
|
84
|
+
* result images. A person's files (the `chat` rows the file library migrated) are read through the
|
|
85
|
+
* library (`ReferencedFiles`), never here.
|
|
88
86
|
*/
|
|
89
|
-
const
|
|
87
|
+
const READ_PURPOSE = "read";
|
|
90
88
|
/** 去掉参数、转小写:`Text/Plain; charset=utf-8` → `text/plain`。 */
|
|
91
89
|
export const normalizeContentType = (ct) => (ct.split(";")[0] ?? "").trim().toLowerCase();
|
|
92
90
|
/**
|
|
93
91
|
* The object key: the attachment id only (the user's file name never goes into a key), under one
|
|
94
|
-
* prefix per purpose.
|
|
92
|
+
* prefix per purpose this service still writes (legacy `chat` rows are the file library's).
|
|
95
93
|
*/
|
|
96
|
-
const objectKey = (id, purpose
|
|
97
|
-
? `
|
|
98
|
-
: purpose === "
|
|
99
|
-
? `
|
|
100
|
-
:
|
|
101
|
-
? `read-images/${id}`
|
|
102
|
-
: `skill-packages/${id}`;
|
|
94
|
+
const objectKey = (id, purpose) => purpose === "agent-avatar"
|
|
95
|
+
? `agent-avatars/${id}`
|
|
96
|
+
: purpose === "read"
|
|
97
|
+
? `read-images/${id}`
|
|
98
|
+
: `skill-packages/${id}`;
|
|
103
99
|
const startsWith = (b, sig, at = 0) => sig.every((x, i) => b[at + i] === x);
|
|
104
100
|
const ascii = (s) => [...s].map((c) => c.charCodeAt(0));
|
|
105
101
|
/**
|
|
@@ -143,9 +139,11 @@ async function readAll(body) {
|
|
|
143
139
|
return new Uint8Array(await new Response(body).arrayBuffer());
|
|
144
140
|
}
|
|
145
141
|
/**
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
142
|
+
* Uploads that are not a person's files (agent avatars, skill packages: register → the browser
|
|
143
|
+
* uploads with the presigned form → finalize checks) and the `read` copies of images the agent was
|
|
144
|
+
* shown (bound to their conversation; request building reads them through {@link fetchMedia}). A
|
|
145
|
+
* person's files are the file library's (`LibraryFilesService`, `ReferencedFiles`). Bytes live only
|
|
146
|
+
* in the object store; logs hold refs. No process state.
|
|
149
147
|
*/
|
|
150
148
|
let AttachmentsService = class AttachmentsService {
|
|
151
149
|
db;
|
|
@@ -168,31 +166,14 @@ let AttachmentsService = class AttachmentsService {
|
|
|
168
166
|
this.txHost = txHost;
|
|
169
167
|
this.cache = cache;
|
|
170
168
|
}
|
|
171
|
-
/** 单个附件的大小上限:配置的 `maxBytes`,图片再受 `MEDIA_LIMITS.imageBytes` 限制。 */
|
|
172
|
-
limitFor(contentType) {
|
|
173
|
-
const { maxBytes } = this.config.get().attachments;
|
|
174
|
-
return Math.min(maxBytes, isImageContentType(contentType) ? MEDIA_LIMITS.imageBytes : MEDIA_LIMITS.documentBytes);
|
|
175
|
-
}
|
|
176
|
-
/** 当前配置下的上限(不需要对象存储)。 */
|
|
177
|
-
limits() {
|
|
178
|
-
const cfg = this.config.get().attachments;
|
|
179
|
-
return {
|
|
180
|
-
types: [...cfg.allowedTypes],
|
|
181
|
-
extensions: [...cfg.allowedExtensions],
|
|
182
|
-
maxBytes: Math.min(cfg.maxBytes, MEDIA_LIMITS.documentBytes),
|
|
183
|
-
imageMaxBytes: Math.min(cfg.maxBytes, MEDIA_LIMITS.imageBytes),
|
|
184
|
-
maxPerMessage: cfg.maxPerMessage,
|
|
185
|
-
requestMediaBytes: cfg.requestMediaBytes,
|
|
186
|
-
available: this.storage.available,
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
169
|
/**
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
170
|
+
* Registers an agent avatar or skill package upload (`pending`) and returns its presigned form;
|
|
171
|
+
* the store enforces the declared size and type. A type or size the purpose does not take →
|
|
172
|
+
* `attachment.type_not_allowed` / `attachment.too_large`; too many unfinished uploads of the
|
|
173
|
+
* purpose → `attachment.too_many_pending` (a soft cap); no object store → `storage.unavailable`.
|
|
174
|
+
* A person's files go through the file library (`LibraryFilesService`), never here.
|
|
194
175
|
*/
|
|
195
|
-
async create(orgId, accountId, input, purpose
|
|
176
|
+
async create(orgId, accountId, input, purpose) {
|
|
196
177
|
this.storage.assertAvailable();
|
|
197
178
|
const { contentType, ttlHours } = await this.admit(orgId, accountId, purpose, input, false);
|
|
198
179
|
const id = randomUUID();
|
|
@@ -230,22 +211,14 @@ let AttachmentsService = class AttachmentsService {
|
|
|
230
211
|
* not stay pending).
|
|
231
212
|
*/
|
|
232
213
|
async admit(orgId, accountId, purpose, input, countStored) {
|
|
233
|
-
const cfg = this.config.get().attachments;
|
|
234
214
|
const contentType = normalizeContentType(input.contentType);
|
|
235
215
|
const skill = purpose === "skill-package";
|
|
236
|
-
const avatar = purpose === "agent-avatar";
|
|
237
216
|
if (skill
|
|
238
217
|
? contentType !== SKILL_PACKAGE_CONTENT_TYPE
|
|
239
|
-
:
|
|
240
|
-
? !AGENT_AVATAR_CONTENT_TYPES.includes(contentType)
|
|
241
|
-
: !cfg.allowedTypes.includes(contentType)) {
|
|
218
|
+
: !AGENT_AVATAR_CONTENT_TYPES.includes(contentType)) {
|
|
242
219
|
throw new ApiError("attachment.type_not_allowed", `Attachment type ${JSON.stringify(contentType)} is not allowed`);
|
|
243
220
|
}
|
|
244
|
-
const limit = skill
|
|
245
|
-
? SKILL_PACKAGE_UPLOAD_MAX_BYTES
|
|
246
|
-
: avatar
|
|
247
|
-
? AGENT_AVATAR_MAX_BYTES
|
|
248
|
-
: this.limitFor(contentType);
|
|
221
|
+
const limit = skill ? SKILL_PACKAGE_UPLOAD_MAX_BYTES : AGENT_AVATAR_MAX_BYTES;
|
|
249
222
|
if (input.size > limit) {
|
|
250
223
|
throw new ApiError("attachment.too_large", `Attachment is ${input.size} bytes, over the limit of ${limit} bytes`);
|
|
251
224
|
}
|
|
@@ -266,19 +239,11 @@ let AttachmentsService = class AttachmentsService {
|
|
|
266
239
|
])
|
|
267
240
|
: eb("status", "=", "pending"))
|
|
268
241
|
.executeTakeFirst();
|
|
269
|
-
const maxPending = skill
|
|
270
|
-
? MAX_PENDING_SKILL_PACKAGES
|
|
271
|
-
: avatar
|
|
272
|
-
? MAX_PENDING_AGENT_AVATARS
|
|
273
|
-
: MAX_PENDING_ATTACHMENTS;
|
|
242
|
+
const maxPending = skill ? MAX_PENDING_SKILL_PACKAGES : MAX_PENDING_AGENT_AVATARS;
|
|
274
243
|
if (Number(pending?.n ?? 0) >= maxPending) {
|
|
275
244
|
throw new ApiError("attachment.too_many_pending", `Too many unfinished uploads (at most ${maxPending}); finish or wait for them first`);
|
|
276
245
|
}
|
|
277
|
-
const ttlHours = skill
|
|
278
|
-
? SKILL_PACKAGE_TTL_HOURS
|
|
279
|
-
: avatar
|
|
280
|
-
? AGENT_AVATAR_TTL_HOURS
|
|
281
|
-
: cfg.unboundTtlHours;
|
|
246
|
+
const ttlHours = skill ? SKILL_PACKAGE_TTL_HOURS : AGENT_AVATAR_TTL_HOURS;
|
|
282
247
|
return { contentType, ttlHours };
|
|
283
248
|
}
|
|
284
249
|
/**
|
|
@@ -372,8 +337,9 @@ let AttachmentsService = class AttachmentsService {
|
|
|
372
337
|
.where("org_id", "=", orgId)
|
|
373
338
|
.where("account_id", "=", accountId)
|
|
374
339
|
.where("status", "in", ["pending", "ready"])
|
|
375
|
-
// read copies are the kernel's own (storeRead binds them);
|
|
376
|
-
|
|
340
|
+
// read copies are the kernel's own (storeRead binds them); a person's files are finalized
|
|
341
|
+
// by the file library
|
|
342
|
+
.where("purpose", "in", ["agent-avatar", "skill-package"])
|
|
377
343
|
.executeTakeFirst();
|
|
378
344
|
if (!row)
|
|
379
345
|
throw notFound();
|
|
@@ -420,12 +386,11 @@ let AttachmentsService = class AttachmentsService {
|
|
|
420
386
|
return view;
|
|
421
387
|
}
|
|
422
388
|
/**
|
|
423
|
-
*
|
|
424
|
-
*
|
|
425
|
-
*
|
|
426
|
-
*
|
|
427
|
-
*
|
|
428
|
-
* still never listed (lists and the device's attachments stay `chat` only).
|
|
389
|
+
* The download address (presigned, {@link ATTACHMENT_DOWNLOAD_TTL_SECONDS} seconds) of a `read`
|
|
390
|
+
* copy (an image a tool showed the agent), for whoever can open its conversation, so the web can
|
|
391
|
+
* show it on the call's row (tool result images design §4); anything else →
|
|
392
|
+
* `attachment.not_found` (a person's files are downloaded through the file library). Only images
|
|
393
|
+
* and PDFs open `inline`; the response type is the recorded one.
|
|
429
394
|
*/
|
|
430
395
|
async downloadUrl(orgId, accountId, id) {
|
|
431
396
|
this.storage.assertAvailable();
|
|
@@ -443,7 +408,7 @@ let AttachmentsService = class AttachmentsService {
|
|
|
443
408
|
.where("id", "=", id)
|
|
444
409
|
.where("org_id", "=", orgId)
|
|
445
410
|
.where("status", "=", "ready")
|
|
446
|
-
.where("purpose", "
|
|
411
|
+
.where("purpose", "=", READ_PURPOSE)
|
|
447
412
|
.executeTakeFirst();
|
|
448
413
|
if (!row)
|
|
449
414
|
throw notFound();
|
|
@@ -466,25 +431,17 @@ let AttachmentsService = class AttachmentsService {
|
|
|
466
431
|
});
|
|
467
432
|
}
|
|
468
433
|
/**
|
|
469
|
-
*
|
|
434
|
+
* The ready `read` copies bound to the conversation in this org (vision-read design §1.1), oldest
|
|
435
|
+
* first, then id; with `id`, only that one. Nothing here checks who reads them: callers check the
|
|
436
|
+
* conversation's access first.
|
|
470
437
|
*/
|
|
471
|
-
async
|
|
472
|
-
return (await this.boundRows(orgId, conversationId)).map((r) => ({ id: r.id, name: r.name }));
|
|
473
|
-
}
|
|
474
|
-
/**
|
|
475
|
-
* The ready `chat` attachments bound to the conversation in this org (never another purpose, a
|
|
476
|
-
* pending or an unbound upload), oldest first by upload time, then id; with `id`, only that one.
|
|
477
|
-
* Nothing here checks who reads them: callers check the conversation's access first. `purposes`
|
|
478
|
-
* widens it for a model-facing lookup only (`read` copies; vision-read design §1.1): every
|
|
479
|
-
* person- or device-facing caller keeps the default.
|
|
480
|
-
*/
|
|
481
|
-
async boundRows(orgId, conversationId, id, purposes = ["chat"]) {
|
|
438
|
+
async boundRows(orgId, conversationId, id) {
|
|
482
439
|
let q = this.db
|
|
483
440
|
.selectFrom("attachments")
|
|
484
441
|
.select(["id", "name", "content_type", "size", "object_key", "etag", "created_at"])
|
|
485
442
|
.where("org_id", "=", orgId)
|
|
486
443
|
.where("conversation_id", "=", conversationId)
|
|
487
|
-
.where("purpose", "
|
|
444
|
+
.where("purpose", "=", READ_PURPOSE)
|
|
488
445
|
.where("status", "=", "ready");
|
|
489
446
|
if (id !== undefined)
|
|
490
447
|
q = q.where("id", "=", id);
|
|
@@ -515,11 +472,12 @@ let AttachmentsService = class AttachmentsService {
|
|
|
515
472
|
return false;
|
|
516
473
|
}
|
|
517
474
|
/**
|
|
518
|
-
*
|
|
519
|
-
*
|
|
475
|
+
* Opens a ready `read` copy bound to the conversation (the model-facing file lookup): no row, not
|
|
476
|
+
* bound to it, the object gone, or its size or etag not the recorded one → null. Other errors
|
|
477
|
+
* (storage unavailable) throw. The caller reads or cancels `body`.
|
|
520
478
|
*/
|
|
521
479
|
async openForConversation(orgId, conversationId, attachmentId, opts = {}) {
|
|
522
|
-
const [row] = await this.boundRows(orgId, conversationId, attachmentId
|
|
480
|
+
const [row] = await this.boundRows(orgId, conversationId, attachmentId);
|
|
523
481
|
if (!row)
|
|
524
482
|
return null;
|
|
525
483
|
const got = await this.storage.kernel(orgId).get(row.objectKey, {
|
|
@@ -536,104 +494,6 @@ let AttachmentsService = class AttachmentsService {
|
|
|
536
494
|
}
|
|
537
495
|
return { name: row.name, contentType: row.contentType, size: row.size, body: got.body };
|
|
538
496
|
}
|
|
539
|
-
/**
|
|
540
|
-
* 发消息时在调用方事务里绑定附件(行锁),返回写进 user_message 的媒体块(`ref`,按 ids 顺序):
|
|
541
|
-
* - 超过 `attachments.maxPerMessage`、或同一个 id 出现多次 → `validation_failed`;
|
|
542
|
-
* - 不存在、不是发送者上传的、已绑定到别的会话、未绑定且已过期 → `attachment.not_found`;
|
|
543
|
-
* - 还没 finalize → `attachment.not_ready`。
|
|
544
|
-
* 后两种的 details 为 `[{ path: "files", message, attachmentId }]`,网页据此标出对应条目。
|
|
545
|
-
* 已绑定到本会话的(重试)照常返回块。
|
|
546
|
-
*/
|
|
547
|
-
async bindForMessage(orgId, conversationId, accountId, ids) {
|
|
548
|
-
const unique = [...new Set(ids)];
|
|
549
|
-
const max = this.config.get().attachments.maxPerMessage;
|
|
550
|
-
if (ids.length > max) {
|
|
551
|
-
throw new ApiError("validation_failed", "Request validation failed", [
|
|
552
|
-
{ path: "files", message: `At most ${max} files per message` },
|
|
553
|
-
]);
|
|
554
|
-
}
|
|
555
|
-
if (unique.length !== ids.length) {
|
|
556
|
-
throw new ApiError("validation_failed", "Request validation failed", [
|
|
557
|
-
{ path: "files", message: "Each file may appear only once per message" },
|
|
558
|
-
]);
|
|
559
|
-
}
|
|
560
|
-
if (unique.length === 0)
|
|
561
|
-
return [];
|
|
562
|
-
const trx = this.db.db;
|
|
563
|
-
const rows = await trx
|
|
564
|
-
.selectFrom("attachments")
|
|
565
|
-
.select([
|
|
566
|
-
"id",
|
|
567
|
-
"account_id",
|
|
568
|
-
"conversation_id",
|
|
569
|
-
"name",
|
|
570
|
-
"content_type",
|
|
571
|
-
"size",
|
|
572
|
-
"status",
|
|
573
|
-
sql `expires_at IS NOT NULL AND expires_at <= now()`.as("expired"),
|
|
574
|
-
])
|
|
575
|
-
.where("org_id", "=", orgId)
|
|
576
|
-
.where("id", "in", unique)
|
|
577
|
-
// 技能包上传不能当附件发出(当作不存在)
|
|
578
|
-
.where("purpose", "=", "chat")
|
|
579
|
-
.orderBy("id")
|
|
580
|
-
.forUpdate()
|
|
581
|
-
.execute();
|
|
582
|
-
const byId = new Map(rows.map((r) => [r.id, r]));
|
|
583
|
-
const blocks = [];
|
|
584
|
-
const toBind = [];
|
|
585
|
-
for (const id of unique) {
|
|
586
|
-
const r = byId.get(id);
|
|
587
|
-
if (!r ||
|
|
588
|
-
r.account_id !== accountId ||
|
|
589
|
-
r.status === "deleting" ||
|
|
590
|
-
(r.conversation_id !== null && r.conversation_id !== conversationId) ||
|
|
591
|
-
(r.conversation_id === null && r.expired)) {
|
|
592
|
-
const message = `Attachment ${id} not found, expired, or already used in another conversation`;
|
|
593
|
-
throw new ApiError("attachment.not_found", message, [
|
|
594
|
-
{ path: "files", message, attachmentId: id },
|
|
595
|
-
]);
|
|
596
|
-
}
|
|
597
|
-
if (r.status !== "ready") {
|
|
598
|
-
const message = `Attachment ${id} has not been finalized`;
|
|
599
|
-
throw new ApiError("attachment.not_ready", message, [
|
|
600
|
-
{ path: "files", message, attachmentId: id },
|
|
601
|
-
]);
|
|
602
|
-
}
|
|
603
|
-
if (r.conversation_id === null)
|
|
604
|
-
toBind.push(id);
|
|
605
|
-
const source = { kind: "ref", attachmentId: id };
|
|
606
|
-
const size = Number(r.size);
|
|
607
|
-
// The model reads images, PDFs and text files itself; every other accepted type becomes a
|
|
608
|
-
// `file` block the model only gets a reference to (the bytes stay in the object store).
|
|
609
|
-
blocks.push(isImageContentType(r.content_type)
|
|
610
|
-
? {
|
|
611
|
-
type: "image",
|
|
612
|
-
mediaType: r.content_type,
|
|
613
|
-
source,
|
|
614
|
-
name: r.name,
|
|
615
|
-
size,
|
|
616
|
-
}
|
|
617
|
-
: isMediaContentType(r.content_type)
|
|
618
|
-
? {
|
|
619
|
-
type: "document",
|
|
620
|
-
mediaType: r.content_type,
|
|
621
|
-
source,
|
|
622
|
-
name: r.name,
|
|
623
|
-
size,
|
|
624
|
-
}
|
|
625
|
-
: { type: "file", mediaType: r.content_type, source, name: r.name, size });
|
|
626
|
-
}
|
|
627
|
-
if (toBind.length > 0) {
|
|
628
|
-
await trx
|
|
629
|
-
.updateTable("attachments")
|
|
630
|
-
.set({ conversation_id: conversationId, expires_at: null })
|
|
631
|
-
.where("id", "in", toBind)
|
|
632
|
-
.where("org_id", "=", orgId)
|
|
633
|
-
.execute();
|
|
634
|
-
}
|
|
635
|
-
return blocks;
|
|
636
|
-
}
|
|
637
497
|
/** 下载 / 取字节时核对 etag:finalize 记下的与当前对象的不一致 → 内容被替换(记 warn)。没有记录时不核对。 */
|
|
638
498
|
sameContent(recorded, current, where) {
|
|
639
499
|
if (recorded === null || recorded === (current ?? null))
|
|
@@ -642,8 +502,8 @@ let AttachmentsService = class AttachmentsService {
|
|
|
642
502
|
return false;
|
|
643
503
|
}
|
|
644
504
|
/**
|
|
645
|
-
* The recorded facts request building needs about
|
|
646
|
-
*
|
|
505
|
+
* The recorded facts request building needs about `read` copies (only ready rows bound to this
|
|
506
|
+
* conversation; `ConversationMedia` asks here for the refs that are not library files): size, PDF page count, and the object's unsigned reference
|
|
647
507
|
* (`ObjectStore.uri`, falling back to `capybara://attachments/<id>`). An id with no row is left
|
|
648
508
|
* out; a failed query throws.
|
|
649
509
|
*/
|
|
@@ -655,7 +515,7 @@ let AttachmentsService = class AttachmentsService {
|
|
|
655
515
|
.select(["id", "size", "pages", "etag", "object_key"])
|
|
656
516
|
.where("org_id", "=", orgId)
|
|
657
517
|
.where("conversation_id", "=", conversationId)
|
|
658
|
-
.where("purpose", "
|
|
518
|
+
.where("purpose", "=", READ_PURPOSE)
|
|
659
519
|
.where("status", "=", "ready")
|
|
660
520
|
.where("id", "in", [...ids])
|
|
661
521
|
.execute();
|
|
@@ -671,8 +531,7 @@ let AttachmentsService = class AttachmentsService {
|
|
|
671
531
|
]));
|
|
672
532
|
}
|
|
673
533
|
/**
|
|
674
|
-
* The bytes request building sends, only of ready `
|
|
675
|
-
* conversation. Null only when certainly gone: no row, the object missing, or its size or etag
|
|
534
|
+
* The bytes request building sends, only of ready `read` copies bound to this conversation. Null only when certainly gone: no row, the object missing, or its size or etag
|
|
676
535
|
* not the recorded one (content replaced, logged as a warning). Every other error (storage
|
|
677
536
|
* unavailable, network) throws (Ruling M4) for the caller to treat as retryable, never a
|
|
678
537
|
* placeholder. An id in `caps` is read by range up to that many leading bytes (the `text/*` cap).
|
|
@@ -689,7 +548,7 @@ let AttachmentsService = class AttachmentsService {
|
|
|
689
548
|
.select(["id", "content_type", "object_key", "size", "etag"])
|
|
690
549
|
.where("org_id", "=", orgId)
|
|
691
550
|
.where("conversation_id", "=", conversationId)
|
|
692
|
-
.where("purpose", "
|
|
551
|
+
.where("purpose", "=", READ_PURPOSE)
|
|
693
552
|
.where("status", "=", "ready")
|
|
694
553
|
.where("id", "in", [...ids])
|
|
695
554
|
.execute();
|
|
@@ -1102,6 +961,8 @@ let AttachmentsService = class AttachmentsService {
|
|
|
1102
961
|
.selectFrom("attachments")
|
|
1103
962
|
.select("id")
|
|
1104
963
|
.where("conversation_id", "is", null)
|
|
964
|
+
// chat rows are the file library's now (a migrated draft's object is a blob's)
|
|
965
|
+
.where("purpose", "<>", "chat")
|
|
1105
966
|
.where("expires_at", "<", sql `now()`)
|
|
1106
967
|
.$if(failed.length > 0, (q) => q.where("id", "not in", failed))
|
|
1107
968
|
.orderBy("expires_at")
|
|
@@ -1158,9 +1019,6 @@ __decorate([
|
|
|
1158
1019
|
__decorate([
|
|
1159
1020
|
Transactional({ propagation: "requires_new" })
|
|
1160
1021
|
], AttachmentsService.prototype, "insertUploadIntent", null);
|
|
1161
|
-
__decorate([
|
|
1162
|
-
Transactional({ propagation: "mandatory" })
|
|
1163
|
-
], AttachmentsService.prototype, "bindForMessage", null);
|
|
1164
1022
|
__decorate([
|
|
1165
1023
|
Transactional({ propagation: "mandatory" })
|
|
1166
1024
|
], AttachmentsService.prototype, "consumeSkillPackage", null);
|
|
@@ -61,6 +61,9 @@ declare const MessageBody: z.ZodObject<{
|
|
|
61
61
|
uri: z.ZodString;
|
|
62
62
|
}, z.core.$strict>>>;
|
|
63
63
|
files: z.ZodOptional<z.ZodArray<z.ZodUUID>>;
|
|
64
|
+
projectFiles: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
65
|
+
path: z.ZodString;
|
|
66
|
+
}, z.core.$strict>>>;
|
|
64
67
|
model: z.ZodOptional<z.ZodObject<{
|
|
65
68
|
provider: z.ZodString;
|
|
66
69
|
model: z.ZodString;
|
|
@@ -102,6 +105,9 @@ export declare const CreateBody: z.ZodObject<{
|
|
|
102
105
|
uri: z.ZodString;
|
|
103
106
|
}, z.core.$strict>>>;
|
|
104
107
|
files: z.ZodOptional<z.ZodArray<z.ZodUUID>>;
|
|
108
|
+
projectFiles: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
109
|
+
path: z.ZodString;
|
|
110
|
+
}, z.core.$strict>>>;
|
|
105
111
|
model: z.ZodOptional<z.ZodObject<{
|
|
106
112
|
provider: z.ZodString;
|
|
107
113
|
model: z.ZodString;
|
|
@@ -270,7 +276,7 @@ export declare class ConversationsController {
|
|
|
270
276
|
tools(principal: Principal, org: OrgContext, id: string, q: z.infer<typeof ToolsQuery>): Promise<{
|
|
271
277
|
tools: ToolInfo[];
|
|
272
278
|
}>;
|
|
273
|
-
postMessage(principal: Principal, org: OrgContext, id: string, body: z.infer<typeof MessageBody
|
|
279
|
+
postMessage(principal: Principal, org: OrgContext, id: string, body: z.infer<typeof MessageBody>, reply: FastifyReply): Promise<{
|
|
274
280
|
event: ConversationEvent;
|
|
275
281
|
}>;
|
|
276
282
|
/**
|
|
@@ -11,6 +11,7 @@ import { isDeviceProjectName } from "@capybara-hq/plugin-sdk";
|
|
|
11
11
|
import { Controller, Delete, Get, Header, HttpCode, Inject, Param, Patch, Post, Res, } from "@nestjs/common";
|
|
12
12
|
import { z } from "zod";
|
|
13
13
|
import { ModelRef } from "../agents/definition.js";
|
|
14
|
+
import { requestSignal } from "../http/request-signal.js";
|
|
14
15
|
import { CurrentPrincipal, requireUser } from "../identity/principal.js";
|
|
15
16
|
import { createZodDto } from "../infra/validation/create-zod-dto.js";
|
|
16
17
|
import { ZBody, ZParam, ZQuery } from "../infra/validation/zod-params.js";
|
|
@@ -19,7 +20,7 @@ import { MAX_ATTACHMENTS } from "../tools/connector-content.js";
|
|
|
19
20
|
import { ConversationToolInfo, TOOL_INFO_KEY_MAX, TOOL_INFO_MAX_KEYS, } from "../tools/info.js";
|
|
20
21
|
import { ARTIFACT_DOWNLOAD_CACHE_SECONDS, ConversationArtifacts, } from "./artifacts.js";
|
|
21
22
|
import { CompactBody, DOWNLOAD_AS, EventsQuery, FilesQuery, IdParams, ListQuery, PatchBody, SubagentsQuery, searchFields, } from "./conversations.schemas.js";
|
|
22
|
-
import { ConversationsService, } from "./conversations.service.js";
|
|
23
|
+
import { ConversationsService, MAX_PROJECT_FILES, } from "./conversations.service.js";
|
|
23
24
|
import { ConversationDeviceStatus } from "./device-status.js";
|
|
24
25
|
import { ConversationFiles, FILE_CONTENT_MAX_BYTES } from "./files.js";
|
|
25
26
|
import { ConversationOutputs, OUTPUT_PAGE_MAX_CHARS } from "./outputs-read.js";
|
|
@@ -69,6 +70,17 @@ const MessageFields = z.object({
|
|
|
69
70
|
* 这里的 100 只是硬上限。
|
|
70
71
|
*/
|
|
71
72
|
files: z.array(z.uuid()).max(100).optional(),
|
|
73
|
+
/**
|
|
74
|
+
* Files of the conversation's device project, by path relative to its root (composer menus §5):
|
|
75
|
+
* checked on the device, never read or uploaded; each becomes a text block after the `@`
|
|
76
|
+
* resources' bodies. A path repeated (after normalization) is referenced once, so
|
|
77
|
+
* `payload.projectFiles` may be shorter than this list. A new conversation needs `project` in
|
|
78
|
+
* the create body.
|
|
79
|
+
*/
|
|
80
|
+
projectFiles: z
|
|
81
|
+
.array(z.object({ path: z.string().min(1).max(4096) }).strict())
|
|
82
|
+
.max(MAX_PROJECT_FILES)
|
|
83
|
+
.optional(),
|
|
72
84
|
/** Switch the conversation's model from the next run (UI refresh B); the agent's own = back. */
|
|
73
85
|
model: ModelRef.strict().optional(),
|
|
74
86
|
/** Switch the effort: one of the (selected) model's declared `effort` values. */
|
|
@@ -97,15 +109,16 @@ const MessageFields = z.object({
|
|
|
97
109
|
/** The sender's UI language (run context spec §3.4). */
|
|
98
110
|
locale: z.enum(["zh", "en"]).optional(),
|
|
99
111
|
});
|
|
100
|
-
// The body of `@` resource i is `content[i + 1]
|
|
101
|
-
//
|
|
102
|
-
// skill, so its text (the arguments) may
|
|
112
|
+
// The body of `@` resource i is `content[i + 1]` and project file i's block follows them, so
|
|
113
|
+
// `content[0]` must be the user's text: with `@` resources or project files the text must not be
|
|
114
|
+
// empty. A skill invocation's `content[0]` is the rendered skill, so its text (the arguments) may
|
|
115
|
+
// be empty.
|
|
103
116
|
const textRule = [
|
|
104
117
|
(b) => b.text.length > 0 ||
|
|
105
118
|
b.skill !== undefined ||
|
|
106
|
-
((b.files?.length ?? 0) > 0 && !b.attachments?.length),
|
|
119
|
+
((b.files?.length ?? 0) > 0 && !b.attachments?.length && !b.projectFiles?.length),
|
|
107
120
|
{
|
|
108
|
-
message: "Text is required unless the message invokes a skill or carries files (and no @ resources)",
|
|
121
|
+
message: "Text is required unless the message invokes a skill or carries files (and no @ resources or project files)",
|
|
109
122
|
path: ["text"],
|
|
110
123
|
},
|
|
111
124
|
];
|
|
@@ -213,12 +226,13 @@ let ConversationsController = class ConversationsController {
|
|
|
213
226
|
clientMessageId: m.clientMessageId,
|
|
214
227
|
...(m.attachments !== undefined && { attachments: m.attachments }),
|
|
215
228
|
...(m.files !== undefined && { files: m.files }),
|
|
229
|
+
...(m.projectFiles !== undefined && { projectFiles: m.projectFiles }),
|
|
216
230
|
...(m.model !== undefined && { model: m.model }),
|
|
217
231
|
...(m.effort !== undefined && { effort: m.effort }),
|
|
218
232
|
...(m.skill !== undefined && { skill: m.skill }),
|
|
219
233
|
...(m.timeZone !== undefined && { timeZone: m.timeZone }),
|
|
220
234
|
...(m.locale !== undefined && { locale: m.locale }),
|
|
221
|
-
}, pick, { source: "web" });
|
|
235
|
+
}, pick, { source: "web", signal: requestSignal(reply) });
|
|
222
236
|
reply.status(out.created ? 201 : 200);
|
|
223
237
|
return { conversation: out.conversation, event: out.event, events: out.events };
|
|
224
238
|
}
|
|
@@ -418,7 +432,7 @@ let ConversationsController = class ConversationsController {
|
|
|
418
432
|
const p = requireUser(principal);
|
|
419
433
|
return { tools: await this.toolInfo.get(org.orgId, id, p.account.id, q.keys) };
|
|
420
434
|
}
|
|
421
|
-
async postMessage(principal, org, id, body) {
|
|
435
|
+
async postMessage(principal, org, id, body, reply) {
|
|
422
436
|
const p = requireUser(principal);
|
|
423
437
|
return {
|
|
424
438
|
event: await this.conversations.postUserMessage(org.orgId, id, p.account.id, {
|
|
@@ -426,13 +440,14 @@ let ConversationsController = class ConversationsController {
|
|
|
426
440
|
...(body.clientMessageId !== undefined && { clientMessageId: body.clientMessageId }),
|
|
427
441
|
...(body.attachments !== undefined && { attachments: body.attachments }),
|
|
428
442
|
...(body.files !== undefined && { files: body.files }),
|
|
443
|
+
...(body.projectFiles !== undefined && { projectFiles: body.projectFiles }),
|
|
429
444
|
...(body.model !== undefined && { model: body.model }),
|
|
430
445
|
...(body.effort !== undefined && { effort: body.effort }),
|
|
431
446
|
...(body.retryOf !== undefined && { retryOf: body.retryOf }),
|
|
432
447
|
...(body.skill !== undefined && { skill: body.skill }),
|
|
433
448
|
...(body.timeZone !== undefined && { timeZone: body.timeZone }),
|
|
434
449
|
...(body.locale !== undefined && { locale: body.locale }),
|
|
435
|
-
}),
|
|
450
|
+
}, requestSignal(reply)),
|
|
436
451
|
};
|
|
437
452
|
}
|
|
438
453
|
/**
|
|
@@ -638,7 +653,8 @@ __decorate([
|
|
|
638
653
|
__param(0, CurrentPrincipal()),
|
|
639
654
|
__param(1, CurrentOrg()),
|
|
640
655
|
__param(2, Param("id")),
|
|
641
|
-
__param(3, ZBody(ConversationMessageBodyDto))
|
|
656
|
+
__param(3, ZBody(ConversationMessageBodyDto)),
|
|
657
|
+
__param(4, Res({ passthrough: true }))
|
|
642
658
|
], ConversationsController.prototype, "postMessage", null);
|
|
643
659
|
__decorate([
|
|
644
660
|
Get(":id/queue"),
|
|
@@ -8,6 +8,7 @@ import { Module } from "@nestjs/common";
|
|
|
8
8
|
import { AgentLookupModule } from "../agents/agent-lookup.js";
|
|
9
9
|
import { BackgroundModule } from "../background/background.module.js";
|
|
10
10
|
import { DevicesModule } from "../devices/devices.module.js";
|
|
11
|
+
import { LibraryReadModule } from "../files/library-read.module.js";
|
|
11
12
|
import { ProvidersModule } from "../runtime/providers.js";
|
|
12
13
|
import { RuntimeModule } from "../runtime/runtime.module.js";
|
|
13
14
|
import { OperationAuthorityModule } from "../sandbox/operation-authority.module.js";
|
|
@@ -46,6 +47,8 @@ ConversationsModule = __decorate([
|
|
|
46
47
|
EventLogModule,
|
|
47
48
|
ConversationAccessModule,
|
|
48
49
|
AttachmentsModule,
|
|
50
|
+
// the files messages attach and the conversation's files read (file library)
|
|
51
|
+
LibraryReadModule,
|
|
49
52
|
AgentLookupModule,
|
|
50
53
|
StorageModule,
|
|
51
54
|
SkillsModule,
|
|
@@ -75,6 +78,7 @@ ConversationsModule = __decorate([
|
|
|
75
78
|
EventLogModule,
|
|
76
79
|
ConversationAccessModule,
|
|
77
80
|
AttachmentsModule,
|
|
81
|
+
LibraryReadModule,
|
|
78
82
|
ConversationsService,
|
|
79
83
|
ConversationQueue,
|
|
80
84
|
ConversationOutputs,
|