@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
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import type { BlobRef } from "../files/blobs.service.js";
|
|
2
|
+
import { ReferencedFiles } from "../files/referenced-files.js";
|
|
1
3
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
2
|
-
import { StorageService } from "../storage/storage.service.js";
|
|
3
4
|
import { ConversationAccess } from "./access.js";
|
|
4
|
-
import { AttachmentsService } from "./attachments.service.js";
|
|
5
5
|
/**
|
|
6
|
-
* A conversation's files (UI refresh B, spec §5.8 / §5.9): the files
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* cache); `status` comes from the
|
|
10
|
-
*
|
|
6
|
+
* A conversation's files (UI refresh B, spec §5.8 / §5.9; file library spec §2): the library files
|
|
7
|
+
* the conversation refers to (`conversation_files`). Files an agent delivered or generated are
|
|
8
|
+
* grouped by `source_path` into versions; files a person uploaded are listed one by one; newest
|
|
9
|
+
* first. Read on every request (no cache); `status` comes from the file and its blob (a deleted
|
|
10
|
+
* file, or a blob gone or replaced, is `removed`). Everything is read under the conversation's
|
|
11
|
+
* access: whoever may read the conversation may read the files it refers to, nobody else.
|
|
11
12
|
*/
|
|
12
13
|
/** Versions listed per file (newest first). */
|
|
13
14
|
export declare const FILE_VERSIONS_MAX = 20;
|
|
@@ -16,7 +17,7 @@ export declare const FILES_PAGE_MAX = 100;
|
|
|
16
17
|
/** Largest `limit` (bytes) of the text content route. */
|
|
17
18
|
export declare const FILE_CONTENT_MAX_BYTES: number;
|
|
18
19
|
export interface FileOutput {
|
|
19
|
-
/**
|
|
20
|
+
/** The file id of the latest version (an artifact id for a delivery). */
|
|
20
21
|
id: string;
|
|
21
22
|
name: string;
|
|
22
23
|
contentType: string;
|
|
@@ -32,18 +33,18 @@ export interface FileOutput {
|
|
|
32
33
|
}[];
|
|
33
34
|
callId: string;
|
|
34
35
|
createdAt: Date;
|
|
35
|
-
/** `removed`: the latest version's
|
|
36
|
+
/** `removed`: the latest version's file was deleted or its bytes are gone (decision 8). */
|
|
36
37
|
status: "available" | "removed";
|
|
37
38
|
previewable: "image" | "text" | null;
|
|
38
39
|
/**
|
|
39
|
-
* `delivered`:
|
|
40
|
-
*
|
|
41
|
-
*
|
|
40
|
+
* `delivered`: an agent delivered or generated it (`artifact_created`); `uploaded`: a person
|
|
41
|
+
* uploaded it and sent it with a message (one version, `sourcePath` is its name and `callId` is
|
|
42
|
+
* empty).
|
|
42
43
|
*/
|
|
43
44
|
origin: "delivered" | "uploaded";
|
|
44
45
|
/**
|
|
45
46
|
* The viewer has a share of this file that is not revoked or expired (file sharing spec §5): of
|
|
46
|
-
* its source path for a delivered file (any version), of the
|
|
47
|
+
* its source path for a delivered file (any version), of the file for an uploaded one.
|
|
47
48
|
*/
|
|
48
49
|
shared: boolean;
|
|
49
50
|
}
|
|
@@ -59,6 +60,24 @@ export interface FileContent {
|
|
|
59
60
|
originalType: string;
|
|
60
61
|
truncated: boolean;
|
|
61
62
|
}
|
|
63
|
+
/** One readable file version of the conversation, for the kernel only (the key never leaves it). */
|
|
64
|
+
export interface ResolvedConversationFile {
|
|
65
|
+
id: string;
|
|
66
|
+
name: string;
|
|
67
|
+
contentType: string;
|
|
68
|
+
size: number;
|
|
69
|
+
/** The blob's key (relative to the org's kernel prefix). */
|
|
70
|
+
objectKey: string;
|
|
71
|
+
/** The version group of a delivered file; null for an upload. */
|
|
72
|
+
sourcePath: string | null;
|
|
73
|
+
/** What a later read of the object must still match (`blobContentMatches`). */
|
|
74
|
+
recorded: {
|
|
75
|
+
size: number;
|
|
76
|
+
etag: string | null;
|
|
77
|
+
};
|
|
78
|
+
/** The blob, for `BlobsService.open` / `head`. */
|
|
79
|
+
blob: BlobRef;
|
|
80
|
+
}
|
|
62
81
|
/** The built-in preview kind of a content type (the files list's `previewable`; share metadata too). */
|
|
63
82
|
export declare const previewKind: (contentType: string) => FileOutput["previewable"];
|
|
64
83
|
/** Drops an incomplete UTF-8 sequence at the end of a cut buffer. */
|
|
@@ -69,31 +88,31 @@ export declare function readPrefix(body: ReadableStream<Uint8Array>, max: number
|
|
|
69
88
|
export declare const HEAD_CONCURRENCY = 8;
|
|
70
89
|
export declare class ConversationFiles {
|
|
71
90
|
private readonly db;
|
|
72
|
-
private readonly storage;
|
|
73
91
|
/** Same visibility as the event stream. */
|
|
74
92
|
private readonly access;
|
|
75
|
-
/** The
|
|
76
|
-
private readonly
|
|
77
|
-
constructor(db: KernelDb,
|
|
93
|
+
/** The files the conversation refers to, and their bytes (size and etag checked). */
|
|
94
|
+
private readonly files;
|
|
95
|
+
constructor(db: KernelDb,
|
|
78
96
|
/** Same visibility as the event stream. */
|
|
79
97
|
access: Pick<ConversationAccess, "isAccessible">,
|
|
80
|
-
/** The
|
|
81
|
-
|
|
98
|
+
/** The files the conversation refers to, and their bytes (size and etag checked). */
|
|
99
|
+
files: Pick<ReferencedFiles, "references" | "open" | "head">);
|
|
82
100
|
private checkAccess;
|
|
83
|
-
/**
|
|
84
|
-
private
|
|
101
|
+
/** Whether a reference can be read now: live, and its stored head still the recorded bytes. */
|
|
102
|
+
private available;
|
|
85
103
|
/**
|
|
86
|
-
* One file
|
|
87
|
-
*
|
|
88
|
-
* object must still match. Call after {@link checkAccess}.
|
|
104
|
+
* One file the conversation refers to by id (any status: a deleted file still resolves, so its
|
|
105
|
+
* shares are found); none → `conversation.artifact_not_found`. Call after {@link checkAccess}.
|
|
89
106
|
*/
|
|
90
107
|
private resolve;
|
|
108
|
+
/** The tool call of each delivery logged in the conversation, by artifact (= file) id. */
|
|
109
|
+
private callIds;
|
|
91
110
|
/**
|
|
92
111
|
* Files newest first: a delivered file by its **first** delivery, so a new version keeps the
|
|
93
112
|
* file's place and a cursor stays stable while files are re-delivered (review M2); an uploaded
|
|
94
|
-
* file by
|
|
95
|
-
* version's id finds its file); a cursor that names no file gives an
|
|
96
|
-
* at most {@link HEAD_CONCURRENCY} at a time.
|
|
113
|
+
* file by when the conversation started referring to it; equal times by id. `after` is a file id
|
|
114
|
+
* from the previous page (any version's id finds its file); a cursor that names no file gives an
|
|
115
|
+
* empty page. Storage HEADs run at most {@link HEAD_CONCURRENCY} at a time.
|
|
97
116
|
*/
|
|
98
117
|
list(orgId: string, conversationId: string, viewer: string, opts: {
|
|
99
118
|
after?: string;
|
|
@@ -103,29 +122,17 @@ export declare class ConversationFiles {
|
|
|
103
122
|
next: string | null;
|
|
104
123
|
}>;
|
|
105
124
|
/**
|
|
106
|
-
* One file version of the conversation (any version's id, or an
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
125
|
+
* One file version of the conversation (any version's id, or an upload sent in it) with its
|
|
126
|
+
* blob, after checking the viewer can read the conversation. For the kernel only (previewers,
|
|
127
|
+
* embed grants, documents): the key never leaves the kernel. A deleted file, or a blob gone or no
|
|
128
|
+
* longer the recorded bytes → `conversation.artifact_removed`; `recorded` is what a later read of
|
|
129
|
+
* the object must still match. `sourcePath` is the version group of a delivered file, null for
|
|
130
|
+
* an upload.
|
|
112
131
|
*/
|
|
113
|
-
file(orgId: string, conversationId: string, viewer: string, fileId: string): Promise<
|
|
114
|
-
id: string;
|
|
115
|
-
name: string;
|
|
116
|
-
contentType: string;
|
|
117
|
-
size: number;
|
|
118
|
-
objectKey: string;
|
|
119
|
-
/** The version group of a delivered file; null for an attachment. */
|
|
120
|
-
sourcePath: string | null;
|
|
121
|
-
recorded?: {
|
|
122
|
-
size: number;
|
|
123
|
-
etag: string | null;
|
|
124
|
-
};
|
|
125
|
-
}>;
|
|
132
|
+
file(orgId: string, conversationId: string, viewer: string, fileId: string): Promise<ResolvedConversationFile>;
|
|
126
133
|
/**
|
|
127
|
-
* Which file a file id names (any version's id, or an
|
|
128
|
-
* checking the viewer can read the conversation; storage is not read,
|
|
134
|
+
* Which file a file id names (any version's id, or an upload sent in the conversation), after
|
|
135
|
+
* checking the viewer can read the conversation; storage is not read, and a deleted file still
|
|
129
136
|
* resolves (its shares are listed and revoked by it).
|
|
130
137
|
*/
|
|
131
138
|
identify(orgId: string, conversationId: string, viewer: string, fileId: string): Promise<{
|
|
@@ -133,30 +140,25 @@ export declare class ConversationFiles {
|
|
|
133
140
|
sourcePath: string | null;
|
|
134
141
|
}>;
|
|
135
142
|
/**
|
|
136
|
-
* The newest delivered version of `sourcePath`
|
|
137
|
-
* viewer can read the conversation (a share's "update to latest",
|
|
138
|
-
* `after` (a version id), only versions delivered after it. Versions
|
|
139
|
-
* skipped; at most {@link FILE_VERSIONS_MAX} are looked at.
|
|
143
|
+
* The newest delivered version of `sourcePath` the conversation refers to that is still
|
|
144
|
+
* readable, after checking the viewer can read the conversation (a share's "update to latest",
|
|
145
|
+
* file sharing spec §2); with `after` (a version id), only versions delivered after it. Versions
|
|
146
|
+
* deleted or whose bytes are gone are skipped; at most {@link FILE_VERSIONS_MAX} are looked at.
|
|
147
|
+
* Null when none is available.
|
|
140
148
|
*/
|
|
141
149
|
latestAvailable(orgId: string, conversationId: string, viewer: string, sourcePath: string, opts?: {
|
|
142
150
|
after?: string;
|
|
143
|
-
}): Promise<
|
|
144
|
-
id: string;
|
|
145
|
-
name: string;
|
|
146
|
-
contentType: string;
|
|
147
|
-
size: number;
|
|
148
|
-
objectKey: string;
|
|
149
|
-
} | null>;
|
|
151
|
+
}): Promise<ResolvedConversationFile | null>;
|
|
150
152
|
/**
|
|
151
|
-
* The source paths and
|
|
153
|
+
* The source paths and uploads the viewer has a share of in the conversation that is not
|
|
152
154
|
* revoked or expired ({@link FileOutput.shared}).
|
|
153
155
|
*/
|
|
154
156
|
private viewerShares;
|
|
155
157
|
/**
|
|
156
|
-
* The first `limit` bytes of a text file version (any version's id, or an
|
|
157
|
-
* conversation). Not text, or NUL bytes in
|
|
158
|
-
*
|
|
159
|
-
*
|
|
158
|
+
* The first `limit` bytes of a text file version (any version's id, or an upload sent in the
|
|
159
|
+
* conversation). Not text, or NUL bytes in what was read → `conversation.artifact_not_previewable`;
|
|
160
|
+
* the file deleted or its bytes gone → `conversation.artifact_removed`. A cut never splits a
|
|
161
|
+
* UTF-8 character.
|
|
160
162
|
*/
|
|
161
163
|
content(orgId: string, conversationId: string, viewer: string, fileId: string, limit: number): Promise<FileContent>;
|
|
162
164
|
}
|
|
@@ -10,18 +10,18 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { Inject, Injectable } from "@nestjs/common";
|
|
11
11
|
import { sql } from "kysely";
|
|
12
12
|
import { ApiError } from "../errors.js";
|
|
13
|
+
import { isLive, ReferencedFiles, } from "../files/referenced-files.js";
|
|
13
14
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
14
|
-
import { StorageService } from "../storage/storage.service.js";
|
|
15
15
|
import { UUID_RE } from "../ui/registry.js";
|
|
16
16
|
import { ConversationAccess } from "./access.js";
|
|
17
17
|
import { isInlineArtifactType, isTextArtifactType } from "./artifacts.js";
|
|
18
|
-
import { AttachmentsService } from "./attachments.service.js";
|
|
19
18
|
/**
|
|
20
|
-
* A conversation's files (UI refresh B, spec §5.8 / §5.9): the files
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* cache); `status` comes from the
|
|
24
|
-
*
|
|
19
|
+
* A conversation's files (UI refresh B, spec §5.8 / §5.9; file library spec §2): the library files
|
|
20
|
+
* the conversation refers to (`conversation_files`). Files an agent delivered or generated are
|
|
21
|
+
* grouped by `source_path` into versions; files a person uploaded are listed one by one; newest
|
|
22
|
+
* first. Read on every request (no cache); `status` comes from the file and its blob (a deleted
|
|
23
|
+
* file, or a blob gone or replaced, is `removed`). Everything is read under the conversation's
|
|
24
|
+
* access: whoever may read the conversation may read the files it refers to, nobody else.
|
|
25
25
|
*/
|
|
26
26
|
/** Versions listed per file (newest first). */
|
|
27
27
|
export const FILE_VERSIONS_MAX = 20;
|
|
@@ -34,6 +34,30 @@ const artifactNotFound = () => new ApiError("conversation.artifact_not_found", "
|
|
|
34
34
|
const removed = () => new ApiError("conversation.artifact_removed", "The file is no longer available");
|
|
35
35
|
/** Whether `a` lists before `b`: newer first, then the larger id (a total, stable order). */
|
|
36
36
|
const before = (a, b) => a.at.getTime() !== b.at.getTime() ? a.at.getTime() > b.at.getTime() : a.id > b.id;
|
|
37
|
+
/**
|
|
38
|
+
* Whether a file is listed as an upload in this conversation (one version) rather than a version of
|
|
39
|
+
* one of its deliveries: everything the conversation got by a message (an upload, or a file another
|
|
40
|
+
* conversation delivered that the person sent here), and anything without a version group.
|
|
41
|
+
*/
|
|
42
|
+
const isUpload = (f) => f.role === "attached" || f.sourcePath === null;
|
|
43
|
+
/** Log order of two deliveries of one conversation: the event that referred to each, then time. */
|
|
44
|
+
const deliveryOrder = (a, b) => {
|
|
45
|
+
if (a.firstSeq !== null && b.firstSeq !== null && a.firstSeq !== b.firstSeq) {
|
|
46
|
+
return a.firstSeq - b.firstSeq;
|
|
47
|
+
}
|
|
48
|
+
const t = a.referencedAt.getTime() - b.referencedAt.getTime();
|
|
49
|
+
return t !== 0 ? t : a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
|
|
50
|
+
};
|
|
51
|
+
const resolvedOf = (f) => ({
|
|
52
|
+
id: f.id,
|
|
53
|
+
name: f.name,
|
|
54
|
+
contentType: f.contentType,
|
|
55
|
+
size: f.size,
|
|
56
|
+
objectKey: f.blob.objectKey,
|
|
57
|
+
sourcePath: isUpload(f) ? null : f.sourcePath,
|
|
58
|
+
recorded: { size: f.blob.size, etag: f.blob.etag },
|
|
59
|
+
blob: { id: f.blob.id, objectKey: f.blob.objectKey, size: f.blob.size, etag: f.blob.etag },
|
|
60
|
+
});
|
|
37
61
|
/** The built-in preview kind of a content type (the files list's `previewable`; share metadata too). */
|
|
38
62
|
export const previewKind = (contentType) => isInlineArtifactType(contentType) ? "image" : isTextArtifactType(contentType) ? "text" : null;
|
|
39
63
|
/** Drops an incomplete UTF-8 sequence at the end of a cut buffer. */
|
|
@@ -89,18 +113,16 @@ async function mapLimit(xs, limit, fn) {
|
|
|
89
113
|
}
|
|
90
114
|
let ConversationFiles = class ConversationFiles {
|
|
91
115
|
db;
|
|
92
|
-
storage;
|
|
93
116
|
access;
|
|
94
|
-
|
|
95
|
-
constructor(db,
|
|
117
|
+
files;
|
|
118
|
+
constructor(db,
|
|
96
119
|
/** Same visibility as the event stream. */
|
|
97
120
|
access,
|
|
98
|
-
/** The
|
|
99
|
-
|
|
121
|
+
/** The files the conversation refers to, and their bytes (size and etag checked). */
|
|
122
|
+
files) {
|
|
100
123
|
this.db = db;
|
|
101
|
-
this.storage = storage;
|
|
102
124
|
this.access = access;
|
|
103
|
-
this.
|
|
125
|
+
this.files = files;
|
|
104
126
|
}
|
|
105
127
|
async checkAccess(orgId, conversationId, viewer) {
|
|
106
128
|
if (!UUID_RE.test(conversationId))
|
|
@@ -108,88 +130,67 @@ let ConversationFiles = class ConversationFiles {
|
|
|
108
130
|
if (!(await this.access.isAccessible(orgId, conversationId, viewer)))
|
|
109
131
|
throw conversationNotFound();
|
|
110
132
|
}
|
|
111
|
-
/**
|
|
112
|
-
async
|
|
113
|
-
|
|
114
|
-
.selectFrom("conversation_events")
|
|
115
|
-
.select(["payload", "created_at"])
|
|
116
|
-
.where("conversation_id", "=", conversationId)
|
|
117
|
-
.where("type", "=", "artifact_created")
|
|
118
|
-
.orderBy("seq")
|
|
119
|
-
.execute();
|
|
120
|
-
return rows.map((r) => ({
|
|
121
|
-
...r.payload,
|
|
122
|
-
createdAt: r.created_at,
|
|
123
|
-
}));
|
|
133
|
+
/** Whether a reference can be read now: live, and its stored head still the recorded bytes. */
|
|
134
|
+
async available(orgId, f) {
|
|
135
|
+
return isLive(f) && (await this.files.head(orgId, f)) !== null;
|
|
124
136
|
}
|
|
125
137
|
/**
|
|
126
|
-
* One file
|
|
127
|
-
*
|
|
128
|
-
* object must still match. Call after {@link checkAccess}.
|
|
138
|
+
* One file the conversation refers to by id (any status: a deleted file still resolves, so its
|
|
139
|
+
* shares are found); none → `conversation.artifact_not_found`. Call after {@link checkAccess}.
|
|
129
140
|
*/
|
|
130
141
|
async resolve(orgId, conversationId, fileId) {
|
|
131
142
|
if (!UUID_RE.test(fileId))
|
|
132
143
|
throw artifactNotFound();
|
|
133
|
-
const
|
|
144
|
+
const [f] = await this.files.references(orgId, [conversationId], { ids: [fileId] });
|
|
145
|
+
if (!f)
|
|
146
|
+
throw artifactNotFound();
|
|
147
|
+
return f;
|
|
148
|
+
}
|
|
149
|
+
/** The tool call of each delivery logged in the conversation, by artifact (= file) id. */
|
|
150
|
+
async callIds(conversationId) {
|
|
151
|
+
const rows = await this.db
|
|
134
152
|
.selectFrom("conversation_events")
|
|
135
|
-
.select(
|
|
153
|
+
.select([
|
|
154
|
+
sql `payload->>'artifactId'`.as("id"),
|
|
155
|
+
sql `payload->>'callId'`.as("callId"),
|
|
156
|
+
])
|
|
136
157
|
.where("conversation_id", "=", conversationId)
|
|
137
158
|
.where("type", "=", "artifact_created")
|
|
138
|
-
.
|
|
139
|
-
|
|
140
|
-
.executeTakeFirst();
|
|
141
|
-
if (row) {
|
|
142
|
-
const a = row.payload;
|
|
143
|
-
return {
|
|
144
|
-
id: a.artifactId,
|
|
145
|
-
name: a.name,
|
|
146
|
-
contentType: a.contentType,
|
|
147
|
-
size: a.size,
|
|
148
|
-
objectKey: a.objectKey,
|
|
149
|
-
sourcePath: a.sourcePath,
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
const [u] = await this.attachments.boundRows(orgId, conversationId, fileId);
|
|
153
|
-
if (!u)
|
|
154
|
-
throw artifactNotFound();
|
|
155
|
-
return {
|
|
156
|
-
id: u.id,
|
|
157
|
-
name: u.name,
|
|
158
|
-
contentType: u.contentType,
|
|
159
|
-
size: u.size,
|
|
160
|
-
objectKey: u.objectKey,
|
|
161
|
-
sourcePath: null,
|
|
162
|
-
upload: u,
|
|
163
|
-
};
|
|
159
|
+
.execute();
|
|
160
|
+
return new Map(rows.map((r) => [r.id, r.callId]));
|
|
164
161
|
}
|
|
165
162
|
/**
|
|
166
163
|
* Files newest first: a delivered file by its **first** delivery, so a new version keeps the
|
|
167
164
|
* file's place and a cursor stays stable while files are re-delivered (review M2); an uploaded
|
|
168
|
-
* file by
|
|
169
|
-
* version's id finds its file); a cursor that names no file gives an
|
|
170
|
-
* at most {@link HEAD_CONCURRENCY} at a time.
|
|
165
|
+
* file by when the conversation started referring to it; equal times by id. `after` is a file id
|
|
166
|
+
* from the previous page (any version's id finds its file); a cursor that names no file gives an
|
|
167
|
+
* empty page. Storage HEADs run at most {@link HEAD_CONCURRENCY} at a time.
|
|
171
168
|
*/
|
|
172
169
|
async list(orgId, conversationId, viewer, opts) {
|
|
173
170
|
await this.checkAccess(orgId, conversationId, viewer);
|
|
171
|
+
const refs = await this.files.references(orgId, [conversationId]);
|
|
174
172
|
const groups = new Map();
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
173
|
+
const uploads = [];
|
|
174
|
+
for (const f of refs) {
|
|
175
|
+
if (isUpload(f)) {
|
|
176
|
+
uploads.push(f);
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
const g = groups.get(f.sourcePath) ?? [];
|
|
180
|
+
g.push(f);
|
|
181
|
+
groups.set(f.sourcePath, g);
|
|
180
182
|
}
|
|
181
|
-
const delivered = [...groups.values()]
|
|
183
|
+
const delivered = [...groups.values()]
|
|
184
|
+
.map((g) => g.sort(deliveryOrder))
|
|
185
|
+
.map((g) => {
|
|
182
186
|
const first = g[0];
|
|
183
|
-
return { origin: "delivered", at: first.
|
|
184
|
-
})
|
|
187
|
+
return { origin: "delivered", at: first.referencedAt, id: first.id, group: g };
|
|
188
|
+
})
|
|
189
|
+
.sort((a, b) => (before(a, b) ? -1 : 1));
|
|
185
190
|
// newest first, the larger id first at equal times
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
at: u.createdAt,
|
|
190
|
-
id: u.id,
|
|
191
|
-
upload: u,
|
|
192
|
-
}));
|
|
191
|
+
const uploaded = uploads
|
|
192
|
+
.map((u) => ({ origin: "uploaded", at: u.referencedAt, id: u.id, upload: u }))
|
|
193
|
+
.sort((a, b) => (before(a, b) ? -1 : 1));
|
|
193
194
|
// merge the two newest-first lists (each keeps its own order)
|
|
194
195
|
const ordered = [];
|
|
195
196
|
let i = 0;
|
|
@@ -209,19 +210,19 @@ let ConversationFiles = class ConversationFiles {
|
|
|
209
210
|
let start = 0;
|
|
210
211
|
if (opts.after !== undefined) {
|
|
211
212
|
const after = opts.after;
|
|
212
|
-
const at = ordered.findIndex((e) => e.origin === "delivered" ? e.group.some((d) => d.
|
|
213
|
+
const at = ordered.findIndex((e) => e.origin === "delivered" ? e.group.some((d) => d.id === after) : e.id === after);
|
|
213
214
|
if (at < 0)
|
|
214
215
|
return { files: [], next: null };
|
|
215
216
|
start = at + 1;
|
|
216
217
|
}
|
|
217
218
|
const page = ordered.slice(start, start + opts.limit);
|
|
218
219
|
const shares = await this.viewerShares(orgId, conversationId, viewer);
|
|
219
|
-
const
|
|
220
|
+
const calls = page.some((e) => e.origin === "delivered")
|
|
221
|
+
? await this.callIds(conversationId)
|
|
222
|
+
: new Map();
|
|
220
223
|
const files = await mapLimit(page, HEAD_CONCURRENCY, async (e) => {
|
|
221
224
|
if (e.origin === "uploaded") {
|
|
222
225
|
const u = e.upload;
|
|
223
|
-
const head = await store.head(u.objectKey);
|
|
224
|
-
const same = this.attachments.storedMatches(u, head, { orgId, conversationId });
|
|
225
226
|
return {
|
|
226
227
|
id: u.id,
|
|
227
228
|
name: u.name,
|
|
@@ -229,10 +230,10 @@ let ConversationFiles = class ConversationFiles {
|
|
|
229
230
|
size: u.size,
|
|
230
231
|
sourcePath: u.name,
|
|
231
232
|
version: 1,
|
|
232
|
-
versions: [{ id: u.id, size: u.size, createdAt: u.
|
|
233
|
+
versions: [{ id: u.id, size: u.size, createdAt: u.referencedAt }],
|
|
233
234
|
callId: "",
|
|
234
|
-
createdAt: u.
|
|
235
|
-
status:
|
|
235
|
+
createdAt: u.referencedAt,
|
|
236
|
+
status: (await this.available(orgId, u)) ? "available" : "removed",
|
|
236
237
|
previewable: previewKind(u.contentType),
|
|
237
238
|
origin: "uploaded",
|
|
238
239
|
shared: shares.uploads.has(u.id),
|
|
@@ -240,95 +241,81 @@ let ConversationFiles = class ConversationFiles {
|
|
|
240
241
|
}
|
|
241
242
|
const g = e.group;
|
|
242
243
|
const latest = g.at(-1);
|
|
243
|
-
const
|
|
244
|
+
const sourcePath = latest.sourcePath;
|
|
244
245
|
return {
|
|
245
|
-
id: latest.
|
|
246
|
+
id: latest.id,
|
|
246
247
|
name: latest.name,
|
|
247
248
|
contentType: latest.contentType,
|
|
248
249
|
size: latest.size,
|
|
249
|
-
sourcePath
|
|
250
|
+
sourcePath,
|
|
250
251
|
version: g.length,
|
|
251
252
|
versions: g
|
|
252
253
|
.slice(-FILE_VERSIONS_MAX)
|
|
253
254
|
.reverse()
|
|
254
|
-
.map((d) => ({ id: d.
|
|
255
|
-
callId: latest.
|
|
256
|
-
createdAt: latest.
|
|
257
|
-
status:
|
|
255
|
+
.map((d) => ({ id: d.id, size: d.size, createdAt: d.referencedAt })),
|
|
256
|
+
callId: calls.get(latest.id) ?? "",
|
|
257
|
+
createdAt: latest.referencedAt,
|
|
258
|
+
status: (await this.available(orgId, latest)) ? "available" : "removed",
|
|
258
259
|
previewable: previewKind(latest.contentType),
|
|
259
260
|
origin: "delivered",
|
|
260
|
-
shared: shares.paths.has(
|
|
261
|
+
shared: shares.paths.has(sourcePath),
|
|
261
262
|
};
|
|
262
263
|
});
|
|
263
264
|
const next = start + opts.limit < ordered.length ? (files.at(-1)?.id ?? null) : null;
|
|
264
265
|
return { files, next };
|
|
265
266
|
}
|
|
266
267
|
/**
|
|
267
|
-
* One file version of the conversation (any version's id, or an
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
268
|
+
* One file version of the conversation (any version's id, or an upload sent in it) with its
|
|
269
|
+
* blob, after checking the viewer can read the conversation. For the kernel only (previewers,
|
|
270
|
+
* embed grants, documents): the key never leaves the kernel. A deleted file, or a blob gone or no
|
|
271
|
+
* longer the recorded bytes → `conversation.artifact_removed`; `recorded` is what a later read of
|
|
272
|
+
* the object must still match. `sourcePath` is the version group of a delivered file, null for
|
|
273
|
+
* an upload.
|
|
273
274
|
*/
|
|
274
275
|
async file(orgId, conversationId, viewer, fileId) {
|
|
275
276
|
await this.checkAccess(orgId, conversationId, viewer);
|
|
276
|
-
const
|
|
277
|
-
if (!
|
|
278
|
-
return f;
|
|
279
|
-
const head = await this.storage.kernel(orgId).head(upload.objectKey);
|
|
280
|
-
if (!this.attachments.storedMatches(upload, head, { orgId, conversationId }))
|
|
277
|
+
const f = await this.resolve(orgId, conversationId, fileId);
|
|
278
|
+
if (!isLive(f) || (await this.files.head(orgId, f)) === null)
|
|
281
279
|
throw removed();
|
|
282
|
-
return
|
|
280
|
+
return resolvedOf(f);
|
|
283
281
|
}
|
|
284
282
|
/**
|
|
285
|
-
* Which file a file id names (any version's id, or an
|
|
286
|
-
* checking the viewer can read the conversation; storage is not read,
|
|
283
|
+
* Which file a file id names (any version's id, or an upload sent in the conversation), after
|
|
284
|
+
* checking the viewer can read the conversation; storage is not read, and a deleted file still
|
|
287
285
|
* resolves (its shares are listed and revoked by it).
|
|
288
286
|
*/
|
|
289
287
|
async identify(orgId, conversationId, viewer, fileId) {
|
|
290
288
|
await this.checkAccess(orgId, conversationId, viewer);
|
|
291
289
|
const f = await this.resolve(orgId, conversationId, fileId);
|
|
292
|
-
return { id: f.id, sourcePath: f.sourcePath };
|
|
290
|
+
return { id: f.id, sourcePath: isUpload(f) ? null : f.sourcePath };
|
|
293
291
|
}
|
|
294
292
|
/**
|
|
295
|
-
* The newest delivered version of `sourcePath`
|
|
296
|
-
* viewer can read the conversation (a share's "update to latest",
|
|
297
|
-
* `after` (a version id), only versions delivered after it. Versions
|
|
298
|
-
* skipped; at most {@link FILE_VERSIONS_MAX} are looked at.
|
|
293
|
+
* The newest delivered version of `sourcePath` the conversation refers to that is still
|
|
294
|
+
* readable, after checking the viewer can read the conversation (a share's "update to latest",
|
|
295
|
+
* file sharing spec §2); with `after` (a version id), only versions delivered after it. Versions
|
|
296
|
+
* deleted or whose bytes are gone are skipped; at most {@link FILE_VERSIONS_MAX} are looked at.
|
|
297
|
+
* Null when none is available.
|
|
299
298
|
*/
|
|
300
299
|
async latestAvailable(orgId, conversationId, viewer, sourcePath, opts = {}) {
|
|
301
300
|
await this.checkAccess(orgId, conversationId, viewer);
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
.
|
|
305
|
-
.
|
|
306
|
-
.
|
|
307
|
-
.where(sql `payload->>'sourcePath'`, "=", sourcePath)
|
|
308
|
-
.orderBy("seq", "desc")
|
|
309
|
-
.execute();
|
|
310
|
-
let candidates = rows.map((r) => r.payload);
|
|
301
|
+
const refs = await this.files.references(orgId, [conversationId]);
|
|
302
|
+
let candidates = refs
|
|
303
|
+
.filter((f) => !isUpload(f) && f.sourcePath === sourcePath)
|
|
304
|
+
.sort(deliveryOrder)
|
|
305
|
+
.reverse();
|
|
311
306
|
if (opts.after !== undefined) {
|
|
312
|
-
const at = candidates.findIndex((d) => d.
|
|
307
|
+
const at = candidates.findIndex((d) => d.id === opts.after);
|
|
313
308
|
if (at >= 0)
|
|
314
309
|
candidates = candidates.slice(0, at);
|
|
315
310
|
}
|
|
316
|
-
const store = this.storage.kernel(orgId);
|
|
317
311
|
for (const d of candidates.slice(0, FILE_VERSIONS_MAX)) {
|
|
318
|
-
if (await
|
|
319
|
-
return
|
|
320
|
-
id: d.artifactId,
|
|
321
|
-
name: d.name,
|
|
322
|
-
contentType: d.contentType,
|
|
323
|
-
size: d.size,
|
|
324
|
-
objectKey: d.objectKey,
|
|
325
|
-
};
|
|
326
|
-
}
|
|
312
|
+
if (isLive(d) && (await this.files.head(orgId, d)) !== null)
|
|
313
|
+
return resolvedOf(d);
|
|
327
314
|
}
|
|
328
315
|
return null;
|
|
329
316
|
}
|
|
330
317
|
/**
|
|
331
|
-
* The source paths and
|
|
318
|
+
* The source paths and uploads the viewer has a share of in the conversation that is not
|
|
332
319
|
* revoked or expired ({@link FileOutput.shared}).
|
|
333
320
|
*/
|
|
334
321
|
async viewerShares(orgId, conversationId, viewer) {
|
|
@@ -352,10 +339,10 @@ let ConversationFiles = class ConversationFiles {
|
|
|
352
339
|
return { paths, uploads };
|
|
353
340
|
}
|
|
354
341
|
/**
|
|
355
|
-
* The first `limit` bytes of a text file version (any version's id, or an
|
|
356
|
-
* conversation). Not text, or NUL bytes in
|
|
357
|
-
*
|
|
358
|
-
*
|
|
342
|
+
* The first `limit` bytes of a text file version (any version's id, or an upload sent in the
|
|
343
|
+
* conversation). Not text, or NUL bytes in what was read → `conversation.artifact_not_previewable`;
|
|
344
|
+
* the file deleted or its bytes gone → `conversation.artifact_removed`. A cut never splits a
|
|
345
|
+
* UTF-8 character.
|
|
359
346
|
*/
|
|
360
347
|
async content(orgId, conversationId, viewer, fileId, limit) {
|
|
361
348
|
await this.checkAccess(orgId, conversationId, viewer);
|
|
@@ -363,18 +350,12 @@ let ConversationFiles = class ConversationFiles {
|
|
|
363
350
|
if (!isTextArtifactType(a.contentType)) {
|
|
364
351
|
throw new ApiError("conversation.artifact_not_previewable", "Only text files have content");
|
|
365
352
|
}
|
|
353
|
+
if (!isLive(a))
|
|
354
|
+
throw removed();
|
|
366
355
|
const max = Math.min(limit, FILE_CONTENT_MAX_BYTES);
|
|
367
|
-
const got = await this.
|
|
368
|
-
.kernel(orgId)
|
|
369
|
-
.get(a.objectKey, { range: { start: 0, end: max - 1 } });
|
|
356
|
+
const got = await this.files.open(orgId, a, { range: { start: 0, end: max - 1 } });
|
|
370
357
|
if (!got)
|
|
371
358
|
throw removed();
|
|
372
|
-
// an attachment whose object changed after finalize is not the upload any more
|
|
373
|
-
if (a.upload &&
|
|
374
|
-
!this.attachments.storedMatches(a.upload, got.head, { orgId, conversationId })) {
|
|
375
|
-
await got.body.cancel().catch(() => { });
|
|
376
|
-
throw removed();
|
|
377
|
-
}
|
|
378
359
|
let body = await readPrefix(got.body, max);
|
|
379
360
|
if (body.includes(0)) {
|
|
380
361
|
throw new ApiError("conversation.artifact_not_previewable", "This file contains binary data and has no text content");
|
|
@@ -389,8 +370,7 @@ let ConversationFiles = class ConversationFiles {
|
|
|
389
370
|
ConversationFiles = __decorate([
|
|
390
371
|
Injectable(),
|
|
391
372
|
__param(0, Inject(KernelDb)),
|
|
392
|
-
__param(1, Inject(
|
|
393
|
-
__param(2, Inject(
|
|
394
|
-
__param(3, Inject(AttachmentsService))
|
|
373
|
+
__param(1, Inject(ConversationAccess)),
|
|
374
|
+
__param(2, Inject(ReferencedFiles))
|
|
395
375
|
], ConversationFiles);
|
|
396
376
|
export { ConversationFiles };
|