@capybara-hq/kernel 0.1.0-rc.106 → 0.1.0-rc.108
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bootstrap.json +13 -13
- package/dist/admin/admin.schemas.d.ts +3 -0
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/channels/channels.module.js +4 -3
- package/dist/channels/file-delivery.d.ts +26 -11
- package/dist/channels/file-delivery.js +32 -11
- package/dist/channels/outbound.d.ts +3 -3
- package/dist/channels/outbound.js +15 -13
- package/dist/config/schema.d.ts +3 -0
- package/dist/config/schema.js +12 -0
- 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.module.js +4 -0
- package/dist/conversations/conversations.service.d.ts +10 -9
- package/dist/conversations/conversations.service.js +28 -11
- package/dist/conversations/event-log.d.ts +1 -0
- package/dist/conversations/events.d.ts +49 -27
- package/dist/conversations/events.js +54 -7
- package/dist/conversations/files.d.ts +66 -64
- package/dist/conversations/files.js +127 -147
- package/dist/conversations/prompt-suggestion-request.js +2 -1
- package/dist/conversations/prompt-suggestions.d.ts +3 -3
- package/dist/conversations/prompt-suggestions.js +11 -10
- package/dist/conversations/queue.service.js +7 -2
- package/dist/ctx/create-ctx.d.ts +3 -1
- package/dist/ctx/create-ctx.js +19 -1
- package/dist/db/kernel-schema.d.ts +80 -2
- package/dist/errors.d.ts +19 -0
- package/dist/errors.js +19 -0
- package/dist/evals/canonical-json.d.ts +7 -0
- package/dist/evals/canonical-json.js +21 -0
- package/dist/evals/reconstruct.js +13 -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 +3 -1
- package/dist/extensions/host.js +2 -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/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/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 +5 -0
- package/dist/identity/settings.d.ts +26 -0
- package/dist/identity/settings.js +33 -2
- package/dist/infra/outbox/registry.d.ts +82 -0
- package/dist/infra/outbox/registry.js +74 -2
- package/dist/infra/throttler/named-throttlers.d.ts +2 -0
- package/dist/infra/throttler/named-throttlers.js +14 -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/settings.service.d.ts +48 -2
- package/dist/orgs/settings.service.js +63 -3
- 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 +4 -0
- package/dist/platform/ops/admin.ops.js +5 -2
- package/dist/platform/ops/files.ops.d.ts +18 -0
- package/dist/platform/ops/files.ops.js +267 -0
- package/dist/platform/ops/org-settings.ops.js +6 -2
- package/dist/platform/ops/orgs.ops.js +1 -0
- package/dist/platform/ops/shares.ops.js +2 -2
- package/dist/platform/platform-ops.module.d.ts +2 -1
- package/dist/platform/platform-ops.module.js +5 -0
- package/dist/platform/route-schemas.js +3 -0
- package/dist/roles/worker.module.js +15 -1
- 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 +18 -1
- package/dist/runtime/context/build.js +19 -8
- 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 +50 -17
- package/dist/runtime/context/in-context-compaction.d.ts +156 -0
- package/dist/runtime/context/in-context-compaction.js +310 -0
- package/dist/runtime/hook-calls.d.ts +2 -1
- package/dist/runtime/hook-calls.js +5 -2
- package/dist/runtime/maintenance.d.ts +10 -2
- package/dist/runtime/maintenance.js +48 -8
- 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-steps.d.ts +4 -2
- package/dist/runtime/run-steps.js +10 -5
- package/dist/runtime/runtime.module.js +3 -0
- 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/tools/builtins/artifacts.d.ts +21 -13
- package/dist/tools/builtins/artifacts.js +81 -51
- package/dist/tools/builtins/builtin-tools.d.ts +7 -1
- package/dist/tools/builtins/builtin-tools.js +17 -6
- 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/tools.module.js +6 -0
- 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/0190_file_library.sql +285 -0
- package/src/migrations/0191_file_library_copy.sql +4 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { type PresignedUpload } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { EventLog } from "../conversations/event-log.js";
|
|
3
|
+
import type { LogContentBlock } from "../conversations/events.js";
|
|
4
|
+
import type { FileStatus } from "../db/kernel-schema.js";
|
|
5
|
+
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
6
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
7
|
+
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
8
|
+
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
9
|
+
import { StorageService } from "../storage/storage.service.js";
|
|
10
|
+
import { BlobsService } from "./blobs.service.js";
|
|
11
|
+
export type { FileOrigin, FileStatus } from "../db/kernel-schema.js";
|
|
12
|
+
/** Unfinished uploads (`uploading` + `draft`) one account may have in an org. */
|
|
13
|
+
export declare const MAX_PENDING_FILES = 50;
|
|
14
|
+
/**
|
|
15
|
+
* {@link LibraryFilesService.addFromBytes} found the blob of these bytes claimed by a deletion
|
|
16
|
+
* {@link ADD_BLOB_ATTEMPTS} times in a row (nothing written): a transient race, worth a retry.
|
|
17
|
+
*/
|
|
18
|
+
export declare class FileBlobClaimedError extends Error {
|
|
19
|
+
constructor();
|
|
20
|
+
}
|
|
21
|
+
/** Where an upload is made: the composer (a draft until sent) or the Files page (ready at once). */
|
|
22
|
+
export type UploadPurpose = "composer" | "library";
|
|
23
|
+
/** A file as the upload routes answer it. */
|
|
24
|
+
export interface FileView {
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
contentType: string;
|
|
28
|
+
size: number;
|
|
29
|
+
status: Exclude<FileStatus, "deleted">;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* `POST /files`: `upload` is the presigned form to send the bytes with (then finalize), or null
|
|
33
|
+
* when the caller already holds these bytes in one of their own files (the file is created at
|
|
34
|
+
* once; nothing to upload or finalize). `expiresAt`: the form's expiry, null without a form.
|
|
35
|
+
*/
|
|
36
|
+
export interface CreatedFile {
|
|
37
|
+
file: FileView;
|
|
38
|
+
upload: PresignedUpload | null;
|
|
39
|
+
expiresAt: string | null;
|
|
40
|
+
}
|
|
41
|
+
/** The upload limits (`GET /files/limits`): the web's pre-checks. */
|
|
42
|
+
export interface FileLimits {
|
|
43
|
+
/** The accepted content types. */
|
|
44
|
+
types: string[];
|
|
45
|
+
/** The accepted extensions next to `types` (lower case, no dot). */
|
|
46
|
+
extensions: string[];
|
|
47
|
+
/** The size limit of a file that is not an image (bytes). */
|
|
48
|
+
maxBytes: number;
|
|
49
|
+
/** The size limit of an image (bytes; also bound by `MEDIA_LIMITS.imageBytes`). */
|
|
50
|
+
imageMaxBytes: number;
|
|
51
|
+
/** Files per message. */
|
|
52
|
+
maxPerMessage: number;
|
|
53
|
+
/** The media budget of one model request (raw bytes). */
|
|
54
|
+
requestMediaBytes: number;
|
|
55
|
+
/** Whether the deployment has an object store; uploads are unavailable without one. */
|
|
56
|
+
available: boolean;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The content block a message carries for a file (a `ref` to its id, never bytes): images, PDFs
|
|
60
|
+
* and text become blocks the model reads itself; every other accepted type a `file` block the
|
|
61
|
+
* model only gets a reference to.
|
|
62
|
+
*/
|
|
63
|
+
export declare function fileContentBlock(f: {
|
|
64
|
+
id: string;
|
|
65
|
+
name: string;
|
|
66
|
+
contentType: string;
|
|
67
|
+
size: number;
|
|
68
|
+
}): LogContentBlock;
|
|
69
|
+
/**
|
|
70
|
+
* The files of the file library (file library spec §2–§4 with the builder amendment of §3):
|
|
71
|
+
* account-owned rows over blobs.
|
|
72
|
+
*
|
|
73
|
+
* Uploading: `create` admits the upload and, unless the caller already holds the same bytes in a
|
|
74
|
+
* file of their own, inserts an `uploading` row (with the declared sha256 and the purpose) before
|
|
75
|
+
* presigning `uploads/<fileId>`. `finalize` checks the staging object (size, type, signature, PDF
|
|
76
|
+
* pages), reads it whole, compares its sha256 with the declared one, copies the verified bytes to a
|
|
77
|
+
* kernel-owned blob (`blobs/<blobId>`, intent first) and settles that blob in one transaction
|
|
78
|
+
* ({@link BlobsService.settle}); the staging object's deletion is always owed. No form can write a
|
|
79
|
+
* blob's key, and every branch does the same work, so nothing the caller can observe depends on
|
|
80
|
+
* whether another account stored the same bytes. `discard` drops a composer upload before it is
|
|
81
|
+
* sent; expired uploads and drafts go with {@link expireBatch}.
|
|
82
|
+
*
|
|
83
|
+
* Sending: {@link attachForMessage} turns the sender's drafts into `ready` files and records the
|
|
84
|
+
* conversation's reference, in the message's transaction. No process state.
|
|
85
|
+
*/
|
|
86
|
+
export declare class LibraryFilesService {
|
|
87
|
+
private readonly db;
|
|
88
|
+
readonly txHost: TransactionHost;
|
|
89
|
+
private readonly storage;
|
|
90
|
+
private readonly config;
|
|
91
|
+
private readonly blobs;
|
|
92
|
+
private readonly outbox;
|
|
93
|
+
/** The `files` change of the conversations that referred to a deleted file. */
|
|
94
|
+
private readonly eventLog;
|
|
95
|
+
constructor(db: KernelDb, txHost: TransactionHost, storage: Pick<StorageService, "available" | "assertAvailable" | "kernel">, config: Pick<KernelConfigService, "get">, blobs: Pick<BlobsService, "writeVerified" | "settle" | "lockReady" | "ensureFromBytes">, outbox: Pick<OutboxService, "add">,
|
|
96
|
+
/** The `files` change of the conversations that referred to a deleted file. */
|
|
97
|
+
eventLog: Pick<EventLog, "publishChanged">);
|
|
98
|
+
/** This replica's bound on finalizes reading and copying at once ({@link LocalSlots}). */
|
|
99
|
+
private readonly finalizeSlots;
|
|
100
|
+
/** The upload limits under the current config (needs no object store). */
|
|
101
|
+
limits(): FileLimits;
|
|
102
|
+
/** One file's size limit: the configured `maxBytes`, an image also `MEDIA_LIMITS.imageBytes`. */
|
|
103
|
+
limitFor(contentType: string): number;
|
|
104
|
+
/**
|
|
105
|
+
* Starts an upload. Admission: a type outside `attachments.allowedTypes` →
|
|
106
|
+
* `file.type_not_allowed`; over the size limit → `file.too_large`; {@link MAX_PENDING_FILES}
|
|
107
|
+
* unfinished files (`uploading` + `draft`) of the account in the org → `file.too_many_pending`
|
|
108
|
+
* (a soft cap); no object store → `storage.unavailable`.
|
|
109
|
+
*
|
|
110
|
+
* When one of the caller's own `ready` or unexpired `draft` files of the same type and size has
|
|
111
|
+
* this sha256 and a `ready` blob, the new file is created on that blob at once (`upload: null`):
|
|
112
|
+
* the caller already holds those bytes, so nothing is learned. In every other case (another
|
|
113
|
+
* account's bytes included) an `uploading` row is inserted with the declared sha256 and purpose
|
|
114
|
+
* (expiring after `attachments.unboundTtlHours`) before a form for `uploads/<fileId>` is
|
|
115
|
+
* presigned, the store enforcing the declared size and type.
|
|
116
|
+
*/
|
|
117
|
+
create(orgId: string, accountId: string, input: {
|
|
118
|
+
name: string;
|
|
119
|
+
contentType: string;
|
|
120
|
+
size: number;
|
|
121
|
+
sha256: string;
|
|
122
|
+
purpose: UploadPurpose;
|
|
123
|
+
}): Promise<CreatedFile>;
|
|
124
|
+
/** The admission checks of {@link create}; returns the normalized content type. */
|
|
125
|
+
private admit;
|
|
126
|
+
/** The type and size checks of an upload; returns the normalized content type. */
|
|
127
|
+
private admitType;
|
|
128
|
+
/**
|
|
129
|
+
* The owner of a library file of the org that is not deleted, or null (no such file: a `read`
|
|
130
|
+
* copy, another org's id). A file has one owner (file library spec §2).
|
|
131
|
+
*/
|
|
132
|
+
ownerOf(orgId: string, fileId: string): Promise<string | null>;
|
|
133
|
+
/**
|
|
134
|
+
* Adds bytes the kernel already holds (a conversation file the `Platform` tool resolved, never
|
|
135
|
+
* another account's library file: the caller refuses those) to the account's library as an
|
|
136
|
+
* upload, `ready` at once.
|
|
137
|
+
*
|
|
138
|
+
* - `referencedId` already one of the account's `ready` files: returned as it is
|
|
139
|
+
* (`existing: true`), or, with a `rename` other than its name, a new entry on its blob.
|
|
140
|
+
* - Otherwise: no object store → `storage.unavailable`, the upload's type and size checks, the
|
|
141
|
+
* signature check of finalize (`file.type_not_allowed`); the account's own `ready` file of the
|
|
142
|
+
* same name, type and sha256 is returned as it is (`existing: true`; a repeated call adds
|
|
143
|
+
* nothing). Else the bytes go through {@link BlobsService.ensureFromBytes} (the org's ready
|
|
144
|
+
* blob of this hash, else a new one written intent first and settled) and the file row is
|
|
145
|
+
* inserted on it behind {@link BlobsService.lockReady}; a blob a deletion claimed meanwhile is
|
|
146
|
+
* ensured again, and {@link FileBlobClaimedError} is thrown after
|
|
147
|
+
* {@link ADD_BLOB_ATTEMPTS} tries. No presigned form is involved.
|
|
148
|
+
*/
|
|
149
|
+
addFromBytes(orgId: string, accountId: string, input: {
|
|
150
|
+
/** The id the bytes were referenced by. */
|
|
151
|
+
referencedId?: string;
|
|
152
|
+
/** The referenced file's name. */
|
|
153
|
+
name: string;
|
|
154
|
+
/** The name the new entry takes instead of {@link name}. */
|
|
155
|
+
rename?: string;
|
|
156
|
+
contentType: string;
|
|
157
|
+
bytes: Uint8Array;
|
|
158
|
+
sha256: string;
|
|
159
|
+
signal?: AbortSignal;
|
|
160
|
+
}): Promise<FileView & {
|
|
161
|
+
existing: boolean;
|
|
162
|
+
}>;
|
|
163
|
+
/**
|
|
164
|
+
* The transaction of {@link addFromBytes}: the blob locked ready, then a `ready` upload file of
|
|
165
|
+
* the account on it. Null when a deletion claimed the blob (nothing written).
|
|
166
|
+
*/
|
|
167
|
+
private insertReady;
|
|
168
|
+
/**
|
|
169
|
+
* The instant path of {@link create}: a new file on the blob of one of the caller's own files
|
|
170
|
+
* with this sha256, or undefined. The blob passes {@link BlobsService.lockReady}, so a deletion
|
|
171
|
+
* claiming it concurrently either waits for this file or makes the caller upload.
|
|
172
|
+
*/
|
|
173
|
+
private createOnOwnBlob;
|
|
174
|
+
/**
|
|
175
|
+
* Finishes an upload (the uploader only; a file already `draft` or `ready` is answered as it
|
|
176
|
+
* is; an expired upload is `file.not_found`):
|
|
177
|
+
*
|
|
178
|
+
* - the staging object missing, or smaller than declared → `file.not_ready` (upload again);
|
|
179
|
+
* - larger than declared, a stored type or a signature that does not match →
|
|
180
|
+
* `file.type_not_allowed` / `file.too_large`, and the upload is rejected;
|
|
181
|
+
* - the whole object is read; a sha256 other than the declared one → `file.hash_mismatch`, and
|
|
182
|
+
* the upload is rejected.
|
|
183
|
+
*
|
|
184
|
+
* A rejected upload expires at once and owes its staging object's deletion (no direct delete:
|
|
185
|
+
* the outbox handler re-reads the row). Otherwise the verified bytes are copied to a new
|
|
186
|
+
* kernel-owned blob (intent first) and one transaction, holding the file row, settles that blob
|
|
187
|
+
* and makes the file `draft` (composer, expiring after `attachments.unboundTtlHours`) or `ready`
|
|
188
|
+
* (library), owing the staging object's deletion. The same work runs whether or not the org held
|
|
189
|
+
* these bytes already.
|
|
190
|
+
*/
|
|
191
|
+
finalize(orgId: string, accountId: string, fileId: string): Promise<FileView>;
|
|
192
|
+
/**
|
|
193
|
+
* The bounded part of {@link finalize}: reads the staging object, checks its signature and hash,
|
|
194
|
+
* copies the verified bytes to a new blob and commits.
|
|
195
|
+
*/
|
|
196
|
+
private verifyAndCopy;
|
|
197
|
+
/**
|
|
198
|
+
* Streams the whole staging object once (bounded by the declared size and a timeout): its bytes,
|
|
199
|
+
* sha256, leading bytes' signature check and, for a PDF, its page count. Null when the object
|
|
200
|
+
* vanished or is not the declared size.
|
|
201
|
+
*/
|
|
202
|
+
private readUpload;
|
|
203
|
+
/**
|
|
204
|
+
* A rejected upload: under the file row's lock, an upload still in progress expires now and its
|
|
205
|
+
* staging object's deletion is owed (the cleanup job then drops the row).
|
|
206
|
+
*/
|
|
207
|
+
private reject;
|
|
208
|
+
/**
|
|
209
|
+
* The transaction of {@link finalize}: the file row locked and still an unexpired upload, the new
|
|
210
|
+
* blob settled ({@link BlobsService.settle}), the file pointed at the result and set `draft` /
|
|
211
|
+
* `ready` with the verified hash, the staging object's deletion owed. When the file is no longer
|
|
212
|
+
* an upload in progress (a concurrent finalize, a discard, the cleanup) the new blob is released
|
|
213
|
+
* instead (`deleting`, its deletion owed); the answer is then the file as it is, or null when it
|
|
214
|
+
* expired or is gone.
|
|
215
|
+
*/
|
|
216
|
+
private commitFinalize;
|
|
217
|
+
/**
|
|
218
|
+
* A composer upload removed before it was sent (the uploader only; an `uploading` or `draft`
|
|
219
|
+
* file no conversation refers to, else `file.not_found`): `deleted`, with the deferred release of
|
|
220
|
+
* what it held owed (`file-release`, run by `BlobObjects.releaseFile`): the request does the same
|
|
221
|
+
* work whatever else points at its blob.
|
|
222
|
+
*/
|
|
223
|
+
discard(orgId: string, accountId: string, fileId: string): Promise<void>;
|
|
224
|
+
/**
|
|
225
|
+
* Expires one batch of the org's `uploading` / `draft` files past `expires_at` (`FOR UPDATE SKIP
|
|
226
|
+
* LOCKED`, so concurrent runs never share a row): each becomes `deleted` with the deferred release
|
|
227
|
+
* of what it held owed (`file-release`). Returns how many it took.
|
|
228
|
+
*/
|
|
229
|
+
expireBatch(orgId: string): Promise<number>;
|
|
230
|
+
/**
|
|
231
|
+
* Attaches the sender's files to a message, in the message's transaction (rows `FOR UPDATE`, in
|
|
232
|
+
* id order). The caller has already checked that the sender may write to the conversation (this
|
|
233
|
+
* checks only the files' ownership). Returns the content blocks the `user_message` carries
|
|
234
|
+
* (`ref`, in `ids` order):
|
|
235
|
+
*
|
|
236
|
+
* - more than `attachments.maxPerMessage`, or an id twice → `validation_failed` (path `files`);
|
|
237
|
+
* - not found, another account's, deleted, or an expired draft → `file.not_found`;
|
|
238
|
+
* - still uploading → `file.not_ready`;
|
|
239
|
+
* both with details `[{ path: "files", message, fileId }]`, for the web to mark the entry.
|
|
240
|
+
*
|
|
241
|
+
* Drafts become `ready` (no expiry; `source_conversation_id` set when it has none), and each
|
|
242
|
+
* file gets the conversation's `attached` reference (`first_seq` when given; an existing one is
|
|
243
|
+
* kept). A file may be attached in any number of the owner's conversations.
|
|
244
|
+
*/
|
|
245
|
+
attachForMessage(orgId: string, conversationId: string, accountId: string, ids: readonly string[], firstSeq?: number): Promise<LogContentBlock[]>;
|
|
246
|
+
/**
|
|
247
|
+
* Deletes one of the account's ready files from the library (file library spec §6; the owner
|
|
248
|
+
* only, else `file.not_found`): `deleted` with `deleted_at`, its shares revoked
|
|
249
|
+
* (`file_deleted`) in the same transaction. Its bytes stay until the blob sweep frees them after
|
|
250
|
+
* `files.deletedRetentionDays`; conversations that referred to it show it as no longer available
|
|
251
|
+
* and later model requests render the placeholder. Each referring conversation gets a `files`
|
|
252
|
+
* change after the commit (a lost publish only delays the panel's refresh).
|
|
253
|
+
*/
|
|
254
|
+
delete(orgId: string, accountId: string, fileId: string): Promise<void>;
|
|
255
|
+
}
|