@capybara-hq/kernel 0.1.0-rc.106 → 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/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
|
@@ -89,6 +89,9 @@ export declare const DeploymentSettingsBody: z.ZodObject<{
|
|
|
89
89
|
reserveTokens: z.ZodOptional<z.ZodNumber>;
|
|
90
90
|
maxOutputTokens: z.ZodOptional<z.ZodNumber>;
|
|
91
91
|
}, z.core.$strict>>;
|
|
92
|
+
promptCache: z.ZodOptional<z.ZodObject<{
|
|
93
|
+
longTtl: z.ZodOptional<z.ZodBoolean>;
|
|
94
|
+
}, z.core.$strict>>;
|
|
92
95
|
externalSharing: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
93
96
|
allow: "allow";
|
|
94
97
|
deny: "deny";
|
|
@@ -208,7 +208,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
|
|
|
208
208
|
/** The host versions (an entry's `minKernel` is judged against them). */
|
|
209
209
|
export declare const HOST_VERSIONS: {
|
|
210
210
|
readonly kernel: string;
|
|
211
|
-
readonly sdk: "0.1.0-rc.
|
|
211
|
+
readonly sdk: "0.1.0-rc.86";
|
|
212
212
|
};
|
|
213
213
|
/** Whether this deployment satisfies the entry's `minKernel`. */
|
|
214
214
|
export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
|
|
@@ -16,6 +16,7 @@ import { ConversationsModule } from "../conversations/conversations.module.js";
|
|
|
16
16
|
import { EventLogModule } from "../conversations/event-log.js";
|
|
17
17
|
import { DevicesModule } from "../devices/devices.module.js";
|
|
18
18
|
import { ExtensionsModule } from "../extensions/extensions.module.js";
|
|
19
|
+
import { LibraryFilesModule } from "../files/library.module.js";
|
|
19
20
|
import { IdentityModule } from "../identity/identity.module.js";
|
|
20
21
|
import { configuredProcessor, } from "../infra/queue/configured-processor.js";
|
|
21
22
|
import { QueueModule } from "../infra/queue/queue.module.js";
|
|
@@ -23,7 +24,6 @@ import { runJob } from "../infra/queue/run-job.js";
|
|
|
23
24
|
import { OrgLockModule } from "../orgs/org-lock.js";
|
|
24
25
|
import { OrgsModule } from "../orgs/orgs.module.js";
|
|
25
26
|
import { RuntimeModule } from "../runtime/runtime.module.js";
|
|
26
|
-
import { StorageModule } from "../storage/storage.module.js";
|
|
27
27
|
import { ToolsModule } from "../tools/tools.module.js";
|
|
28
28
|
import { ChannelConnections } from "./connections.service.js";
|
|
29
29
|
import { ChannelInbound } from "./inbound.js";
|
|
@@ -55,8 +55,9 @@ ChannelsModule = __decorate([
|
|
|
55
55
|
RuntimeModule,
|
|
56
56
|
// outbound pauses the automation of a run whose chat is gone (scheduled tasks spec §8)
|
|
57
57
|
AutomationsModule,
|
|
58
|
-
// outbound reads conversation files to send them into the chat (channel
|
|
59
|
-
|
|
58
|
+
// outbound reads conversation files from their blobs to send them into the chat (channel
|
|
59
|
+
// file delivery §4.2, file library spec §4)
|
|
60
|
+
LibraryFilesModule,
|
|
60
61
|
CHANNEL_QUEUE_MODULE,
|
|
61
62
|
],
|
|
62
63
|
providers: [
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { type Channel, type
|
|
1
|
+
import { type Channel, type ObjectHead } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import type { ConversationEvent } from "../conversations/events.js";
|
|
3
|
+
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
4
|
+
import type { BlobRef } from "../files/blobs.service.js";
|
|
3
5
|
import { type ChannelLocale } from "./phrases.js";
|
|
4
6
|
type ArtifactPayload = Extract<ConversationEvent, {
|
|
5
7
|
type: "artifact_created";
|
|
@@ -11,16 +13,18 @@ export type FileDeliveryPlan = {
|
|
|
11
13
|
cap: number;
|
|
12
14
|
} | {
|
|
13
15
|
mode: "link";
|
|
14
|
-
reason: "unsupported" | "disabled" | "too_large" | "empty" | "
|
|
16
|
+
reason: "unsupported" | "disabled" | "too_large" | "empty" | "unreferenced";
|
|
15
17
|
};
|
|
16
18
|
/**
|
|
17
|
-
* Decides native upload or a link line for one artifact. Order: a
|
|
18
|
-
*
|
|
19
|
-
* switch (`fileMaxBytes` 0), then the size cap (the smaller of the
|
|
19
|
+
* Decides native upload or a link line for one artifact. Order: a file the conversation does not
|
|
20
|
+
* reference ({@link referencedBlob}: file library spec §4), an empty file, a channel without
|
|
21
|
+
* `sendFile`, the deployment switch (`fileMaxBytes` 0), then the size cap (the smaller of the
|
|
22
|
+
* channel's and the deployment's).
|
|
20
23
|
*/
|
|
21
24
|
export declare function planFileDelivery(input: {
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
/** Whether the conversation references the artifact's file (a ready file on a ready blob). */
|
|
26
|
+
referenced: boolean;
|
|
27
|
+
artifact: Pick<ArtifactPayload, "size" | "contentType">;
|
|
24
28
|
features: Channel["features"];
|
|
25
29
|
canSendFile: boolean;
|
|
26
30
|
fileMaxBytes: number;
|
|
@@ -48,6 +52,12 @@ export declare function fileLinkText(input: {
|
|
|
48
52
|
}): string;
|
|
49
53
|
/** The root message text of a native file delivery. */
|
|
50
54
|
export declare function fileRootText(name: string, locale: ChannelLocale): string;
|
|
55
|
+
/**
|
|
56
|
+
* The blob of the file `fileId` when the conversation references it (a `conversation_files` row
|
|
57
|
+
* in the org) and both the file and its blob are ready; null otherwise. A channel sends only
|
|
58
|
+
* such a file (file library spec §4 "Channel delivery").
|
|
59
|
+
*/
|
|
60
|
+
export declare function referencedBlob(db: KernelSchemaDb, orgId: string, conversationId: string, fileId: string): Promise<BlobRef | null>;
|
|
51
61
|
export type CappedRead = {
|
|
52
62
|
kind: "ok";
|
|
53
63
|
data: Uint8Array;
|
|
@@ -58,12 +68,17 @@ export type CappedRead = {
|
|
|
58
68
|
} | {
|
|
59
69
|
kind: "unavailable";
|
|
60
70
|
};
|
|
71
|
+
/** Opens the bytes to read: null when they are gone (a blob read checks size and etag). */
|
|
72
|
+
export type OpenBytes = (signal: AbortSignal) => Promise<{
|
|
73
|
+
head: ObjectHead;
|
|
74
|
+
body: ReadableStream<Uint8Array>;
|
|
75
|
+
} | null>;
|
|
61
76
|
/**
|
|
62
|
-
* Reads
|
|
63
|
-
* `cap` while streaming, is `too_large` (the body is cancelled).
|
|
64
|
-
* store that is not there `unavailable`; any other error is rethrown (retryable).
|
|
77
|
+
* Reads bytes into memory, never more than `cap` bytes: a larger head, or a body that passes
|
|
78
|
+
* `cap` while streaming, is `too_large` (the body is cancelled). Bytes that are gone are
|
|
79
|
+
* `missing`, a store that is not there `unavailable`; any other error is rethrown (retryable).
|
|
65
80
|
*/
|
|
66
|
-
export declare function readArtifactCapped(
|
|
81
|
+
export declare function readArtifactCapped(open: OpenBytes, cap: number, signal: AbortSignal): Promise<CappedRead>;
|
|
67
82
|
/** A counting semaphore with a FIFO of waiters; one per worker replica (not a provider). */
|
|
68
83
|
export declare class FileSlots {
|
|
69
84
|
private free;
|
|
@@ -3,15 +3,15 @@ import { isStorageUnavailable } from "../storage/storage.service.js";
|
|
|
3
3
|
import { conversationUrl } from "./cards.js";
|
|
4
4
|
import { phrase } from "./phrases.js";
|
|
5
5
|
/**
|
|
6
|
-
* Decides native upload or a link line for one artifact. Order: a
|
|
7
|
-
*
|
|
8
|
-
* switch (`fileMaxBytes` 0), then the size cap (the smaller of the
|
|
6
|
+
* Decides native upload or a link line for one artifact. Order: a file the conversation does not
|
|
7
|
+
* reference ({@link referencedBlob}: file library spec §4), an empty file, a channel without
|
|
8
|
+
* `sendFile`, the deployment switch (`fileMaxBytes` 0), then the size cap (the smaller of the
|
|
9
|
+
* channel's and the deployment's).
|
|
9
10
|
*/
|
|
10
11
|
export function planFileDelivery(input) {
|
|
11
12
|
const { artifact, features, fileMaxBytes } = input;
|
|
12
|
-
if (!
|
|
13
|
-
return { mode: "link", reason: "
|
|
14
|
-
}
|
|
13
|
+
if (!input.referenced)
|
|
14
|
+
return { mode: "link", reason: "unreferenced" };
|
|
15
15
|
if (artifact.size === 0)
|
|
16
16
|
return { mode: "link", reason: "empty" };
|
|
17
17
|
const files = features.files;
|
|
@@ -87,13 +87,34 @@ export function fileRootText(name, locale) {
|
|
|
87
87
|
return fill(phrase("fileRoot", locale), { name: asCode(name), size: "", url: "" });
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
90
|
+
* The blob of the file `fileId` when the conversation references it (a `conversation_files` row
|
|
91
|
+
* in the org) and both the file and its blob are ready; null otherwise. A channel sends only
|
|
92
|
+
* such a file (file library spec §4 "Channel delivery").
|
|
93
|
+
*/
|
|
94
|
+
export async function referencedBlob(db, orgId, conversationId, fileId) {
|
|
95
|
+
const row = await db
|
|
96
|
+
.selectFrom("conversation_files as cf")
|
|
97
|
+
.innerJoin("files as f", (j) => j.onRef("f.id", "=", "cf.file_id").onRef("f.org_id", "=", "cf.org_id"))
|
|
98
|
+
.innerJoin("blobs as b", (j) => j.onRef("b.id", "=", "f.blob_id").onRef("b.org_id", "=", "cf.org_id"))
|
|
99
|
+
.select(["b.id", "b.object_key", "b.size", "b.etag"])
|
|
100
|
+
.where("cf.org_id", "=", orgId)
|
|
101
|
+
.where("cf.conversation_id", "=", conversationId)
|
|
102
|
+
.where("cf.file_id", "=", fileId)
|
|
103
|
+
.where("f.status", "=", "ready")
|
|
104
|
+
.where("b.status", "=", "ready")
|
|
105
|
+
.executeTakeFirst();
|
|
106
|
+
if (!row)
|
|
107
|
+
return null;
|
|
108
|
+
return { id: row.id, objectKey: row.object_key, size: Number(row.size), etag: row.etag };
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Reads bytes into memory, never more than `cap` bytes: a larger head, or a body that passes
|
|
112
|
+
* `cap` while streaming, is `too_large` (the body is cancelled). Bytes that are gone are
|
|
113
|
+
* `missing`, a store that is not there `unavailable`; any other error is rethrown (retryable).
|
|
93
114
|
*/
|
|
94
|
-
export async function readArtifactCapped(
|
|
115
|
+
export async function readArtifactCapped(open, cap, signal) {
|
|
95
116
|
try {
|
|
96
|
-
const got = await
|
|
117
|
+
const got = await open(signal);
|
|
97
118
|
if (got === null)
|
|
98
119
|
return { kind: "missing" };
|
|
99
120
|
const reader = got.body.getReader();
|
|
@@ -3,12 +3,12 @@ import { type Job, type Worker } from "bullmq";
|
|
|
3
3
|
import { AutomationsService } from "../automations/automations.service.js";
|
|
4
4
|
import { EventLog } from "../conversations/event-log.js";
|
|
5
5
|
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
6
|
+
import { BlobsService } from "../files/blobs.service.js";
|
|
6
7
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
7
8
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
8
9
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
9
10
|
import { ConversationLock } from "../runtime/conversation-lock.js";
|
|
10
11
|
import type { StreamBus } from "../runtime/stream.js";
|
|
11
|
-
import { StorageService } from "../storage/storage.service.js";
|
|
12
12
|
import { ApprovalsService } from "../tools/approvals.service.js";
|
|
13
13
|
import { QuestionsService } from "../tools/questions.service.js";
|
|
14
14
|
import { ToolRegistry } from "../tools/registry.js";
|
|
@@ -120,8 +120,8 @@ export declare class ChannelOutbound {
|
|
|
120
120
|
inbound: Pick<ChannelInbound, "handle">, jobs: Pick<ChannelJobs, "enqueue" | "resumeConnection">, config: Pick<KernelConfigService, "get">, log: Pick<Logger, "error" | "warn" | "info">, txHost: TransactionHost,
|
|
121
121
|
/** Pauses the task of a scheduled run whose chat is gone (scheduled tasks spec §8). */
|
|
122
122
|
automations: Pick<AutomationsService, "pauseFor">,
|
|
123
|
-
/**
|
|
124
|
-
|
|
123
|
+
/** The blobs of conversation files sent into the chat (channel file delivery spec §4.2). */
|
|
124
|
+
blobs: Pick<BlobsService, "open">);
|
|
125
125
|
/**
|
|
126
126
|
* Starts consuming (worker role only): `worker` is the `@Processor` worker of the channel queue
|
|
127
127
|
* (its job lock and stalled detection follow the run queue's config).
|
|
@@ -17,13 +17,13 @@ import { productName } from "../config/product-name.js";
|
|
|
17
17
|
import { conversationTopic, EventLog, } from "../conversations/event-log.js";
|
|
18
18
|
import { recipientLocale } from "../conversations/message-context.js";
|
|
19
19
|
import { ApiError } from "../errors.js";
|
|
20
|
+
import { BlobsService } from "../files/blobs.service.js";
|
|
20
21
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
21
22
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
22
23
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
23
24
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
24
25
|
import { KERNEL_BUS, KERNEL_LOGGER } from "../infra/tokens.js";
|
|
25
26
|
import { ConversationLock, } from "../runtime/conversation-lock.js";
|
|
26
|
-
import { StorageService } from "../storage/storage.service.js";
|
|
27
27
|
import { ApprovalsService } from "../tools/approvals.service.js";
|
|
28
28
|
import { toolInfo } from "../tools/info.js";
|
|
29
29
|
import { QuestionsService } from "../tools/questions.service.js";
|
|
@@ -31,7 +31,7 @@ import { ToolRegistry } from "../tools/registry.js";
|
|
|
31
31
|
import { approvalCard, callSummary, cardMessage, connectUrl, conversationUrl, personFieldsCard, questionCard, webBase, } from "./cards.js";
|
|
32
32
|
import { ChannelConnections, FILE_CALL_TIMEOUT_MS, } from "./connections.service.js";
|
|
33
33
|
import { processDisplayOf, progressCardMessage } from "./features.js";
|
|
34
|
-
import { FileSlots, fileKind, fileLinkText, fileRootText, planFileDelivery, pluginFileName, readArtifactCapped, } from "./file-delivery.js";
|
|
34
|
+
import { FileSlots, fileKind, fileLinkText, fileRootText, planFileDelivery, pluginFileName, readArtifactCapped, referencedBlob, } from "./file-delivery.js";
|
|
35
35
|
import { ChannelInbound } from "./inbound.js";
|
|
36
36
|
import { ChannelJobs, INBOUND_JOB, idempotencyKey, RESUME_JOB, } from "./jobs.js";
|
|
37
37
|
import { phrase } from "./phrases.js";
|
|
@@ -195,8 +195,8 @@ let ChannelOutbound = class ChannelOutbound {
|
|
|
195
195
|
inbound, jobs, config, log, txHost,
|
|
196
196
|
/** Pauses the task of a scheduled run whose chat is gone (scheduled tasks spec §8). */
|
|
197
197
|
automations,
|
|
198
|
-
/**
|
|
199
|
-
|
|
198
|
+
/** The blobs of conversation files sent into the chat (channel file delivery spec §4.2). */
|
|
199
|
+
blobs) {
|
|
200
200
|
this.kdb = kdb;
|
|
201
201
|
this.inbound = inbound;
|
|
202
202
|
this.jobs = jobs;
|
|
@@ -217,7 +217,7 @@ let ChannelOutbound = class ChannelOutbound {
|
|
|
217
217
|
questions,
|
|
218
218
|
config,
|
|
219
219
|
log,
|
|
220
|
-
|
|
220
|
+
blobs,
|
|
221
221
|
// one per process: it bounds this replica's memory (not shared state)
|
|
222
222
|
fileSlots: new FileSlots(config.get().channels.fileConcurrency),
|
|
223
223
|
writes: this,
|
|
@@ -544,7 +544,7 @@ ChannelOutbound = __decorate([
|
|
|
544
544
|
__param(11, Inject(KERNEL_LOGGER)),
|
|
545
545
|
__param(12, Inject(TransactionHost)),
|
|
546
546
|
__param(13, Inject(AutomationsService)),
|
|
547
|
-
__param(14, Inject(
|
|
547
|
+
__param(14, Inject(BlobsService))
|
|
548
548
|
], ChannelOutbound);
|
|
549
549
|
export { ChannelOutbound };
|
|
550
550
|
/** One `bind` card per handoff link, in one message (process blocks spec §6.2). */
|
|
@@ -1170,16 +1170,18 @@ class Delivery {
|
|
|
1170
1170
|
*/
|
|
1171
1171
|
async deliverArtifact(e) {
|
|
1172
1172
|
const a = e.payload;
|
|
1173
|
+
// the file the event created (its id is the artifact id; earlier events name no fileId)
|
|
1174
|
+
const blob = await referencedBlob(this.d.db, this.s.row.orgId, this.conversationId, a.fileId ?? a.artifactId);
|
|
1173
1175
|
const plan = planFileDelivery({
|
|
1174
|
-
|
|
1176
|
+
referenced: blob !== null,
|
|
1175
1177
|
artifact: a,
|
|
1176
1178
|
features: this.s.features,
|
|
1177
1179
|
canSendFile: this.s.sendFile !== undefined,
|
|
1178
1180
|
fileMaxBytes: this.d.config.get().channels.fileMaxBytes,
|
|
1179
1181
|
});
|
|
1180
|
-
if (plan.mode === "link") {
|
|
1181
|
-
if (
|
|
1182
|
-
this.d.log.warn("channel file
|
|
1182
|
+
if (plan.mode === "link" || blob === null) {
|
|
1183
|
+
if (blob === null) {
|
|
1184
|
+
this.d.log.warn("channel file not referenced by the conversation sent as a link", {
|
|
1183
1185
|
conversationId: this.conversationId,
|
|
1184
1186
|
seq: e.seq,
|
|
1185
1187
|
});
|
|
@@ -1198,7 +1200,7 @@ class Delivery {
|
|
|
1198
1200
|
}
|
|
1199
1201
|
let sent;
|
|
1200
1202
|
try {
|
|
1201
|
-
sent = await this.sendNative(e.seq, a, plan);
|
|
1203
|
+
sent = await this.sendNative(e.seq, a, blob, plan);
|
|
1202
1204
|
}
|
|
1203
1205
|
finally {
|
|
1204
1206
|
release();
|
|
@@ -1211,7 +1213,7 @@ class Delivery {
|
|
|
1211
1213
|
* Reads and sends one file while holding a file slot; false when the link line stands in for it
|
|
1212
1214
|
* (see {@link deliverArtifact}).
|
|
1213
1215
|
*/
|
|
1214
|
-
async sendNative(seq, a, plan) {
|
|
1216
|
+
async sendNative(seq, a, blob, plan) {
|
|
1215
1217
|
// the replica stopped while this delivery waited for its slot: hand the job back untouched
|
|
1216
1218
|
if (this.stopping.aborted)
|
|
1217
1219
|
throw new DeliveryShutdownError();
|
|
@@ -1225,7 +1227,7 @@ class Delivery {
|
|
|
1225
1227
|
let read;
|
|
1226
1228
|
try {
|
|
1227
1229
|
// the read stops with the replica: nothing has reached the platform yet
|
|
1228
|
-
read = await readArtifactCapped(this.d.
|
|
1230
|
+
read = await readArtifactCapped((signal) => this.d.blobs.open(this.s.row.orgId, blob, { signal }), plan.cap, AbortSignal.any([this.stopping, AbortSignal.timeout(FILE_CALL_TIMEOUT_MS)]));
|
|
1229
1231
|
}
|
|
1230
1232
|
catch (err) {
|
|
1231
1233
|
if (this.stopping.aborted)
|
package/dist/config/schema.d.ts
CHANGED
|
@@ -199,6 +199,9 @@ export declare const KernelConfigSchema: z.ZodObject<{
|
|
|
199
199
|
storage: z.ZodDefault<z.ZodObject<{
|
|
200
200
|
purgeDeletedOrgsAfterDays: z.ZodDefault<z.ZodNumber>;
|
|
201
201
|
}, z.core.$strict>>;
|
|
202
|
+
files: z.ZodDefault<z.ZodObject<{
|
|
203
|
+
deletedRetentionDays: z.ZodDefault<z.ZodNumber>;
|
|
204
|
+
}, z.core.$strict>>;
|
|
202
205
|
attachments: z.ZodPrefault<z.ZodObject<{
|
|
203
206
|
maxBytes: z.ZodDefault<z.ZodNumber>;
|
|
204
207
|
allowedTypes: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
package/dist/config/schema.js
CHANGED
|
@@ -1164,6 +1164,18 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
1164
1164
|
})),
|
|
1165
1165
|
})
|
|
1166
1166
|
.default({ purgeDeletedOrgsAfterDays: 30 }),
|
|
1167
|
+
files: z
|
|
1168
|
+
.strictObject({
|
|
1169
|
+
deletedRetentionDays: z
|
|
1170
|
+
.number()
|
|
1171
|
+
.int()
|
|
1172
|
+
.positive()
|
|
1173
|
+
.default(30)
|
|
1174
|
+
.meta(meta({
|
|
1175
|
+
description: "Days a deleted file keeps its bytes before the blob sweep may delete them.",
|
|
1176
|
+
})),
|
|
1177
|
+
})
|
|
1178
|
+
.default({ deletedRetentionDays: 30 }),
|
|
1167
1179
|
attachments: z
|
|
1168
1180
|
.strictObject({
|
|
1169
1181
|
maxBytes: z
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReferencedFiles } from "../files/referenced-files.js";
|
|
2
2
|
import { StorageService } from "../storage/storage.service.js";
|
|
3
3
|
import { ConversationAccess } from "./access.js";
|
|
4
4
|
/** 产物下载跳转的预签名有效期(秒)。 */
|
|
@@ -20,27 +20,30 @@ export interface ArtifactPreview {
|
|
|
20
20
|
truncated: boolean;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
23
|
+
* A conversation's files by id (M5 T8 / T11; file library spec §2): any file the conversation
|
|
24
|
+
* refers to (a delivery or an upload sent in it). The conversation must be visible by the event
|
|
25
|
+
* stream's rule (else `conversation.not_found`); the file must be one the conversation refers to,
|
|
26
|
+
* not deleted, its blob readable (else `conversation.artifact_not_found`). Bytes are read through
|
|
27
|
+
* the file's blob (size and etag checked), never an event's `objectKey`.
|
|
26
28
|
*
|
|
27
|
-
* -
|
|
28
|
-
*
|
|
29
|
-
* -
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* 查找走 `conversation_events` 的主键 `(conversation_id, seq)` 前缀,在 SQL 里按 `type` 与
|
|
34
|
-
* `payload->>'artifactId'` 过滤、`LIMIT 1`(只扫这一个会话的事件,不在 JS 里扫日志;不加迁移)。
|
|
29
|
+
* - Download: a 302 to a presigned address, `attachment` by default (with the file's name and
|
|
30
|
+
* type); `inline` only takes effect for bitmaps (the web's thumbnails).
|
|
31
|
+
* - Text preview: `text/*` and the text formats, the first {@link ARTIFACT_PREVIEW_MAX_BYTES} bytes
|
|
32
|
+
* by range, at most {@link ARTIFACT_PREVIEW_MAX_LINES} lines, as a JSON string (shown as plain
|
|
33
|
+
* text); other types, or NUL bytes in the head (binary after all) →
|
|
34
|
+
* `conversation.artifact_not_previewable`.
|
|
35
35
|
*/
|
|
36
36
|
export declare class ConversationArtifacts {
|
|
37
|
-
private readonly db;
|
|
38
37
|
private readonly storage;
|
|
39
|
-
/**
|
|
38
|
+
/** Conversation visibility (the same rule as the conversation's SSE stream). */
|
|
40
39
|
private readonly access;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
/** The files the conversation refers to, and their bytes. */
|
|
41
|
+
private readonly files;
|
|
42
|
+
constructor(storage: Pick<StorageService, "kernel">,
|
|
43
|
+
/** Conversation visibility (the same rule as the conversation's SSE stream). */
|
|
44
|
+
access: Pick<ConversationAccess, "isAccessible">,
|
|
45
|
+
/** The files the conversation refers to, and their bytes. */
|
|
46
|
+
files: Pick<ReferencedFiles, "references" | "open" | "head">);
|
|
44
47
|
private find;
|
|
45
48
|
downloadUrl(orgId: string, conversationId: string, viewerAccountId: string, artifactId: string, opts?: {
|
|
46
49
|
inline?: boolean;
|
|
@@ -8,9 +8,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
10
|
import { Inject, Injectable } from "@nestjs/common";
|
|
11
|
-
import { sql } from "kysely";
|
|
12
11
|
import { ApiError } from "../errors.js";
|
|
13
|
-
import {
|
|
12
|
+
import { isLive, ReferencedFiles } from "../files/referenced-files.js";
|
|
14
13
|
import { StorageService } from "../storage/storage.service.js";
|
|
15
14
|
import { UUID_RE } from "../ui/registry.js";
|
|
16
15
|
import { ConversationAccess } from "./access.js";
|
|
@@ -62,29 +61,31 @@ async function readPrefix(body, max) {
|
|
|
62
61
|
return out.subarray(0, n);
|
|
63
62
|
}
|
|
64
63
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
64
|
+
* A conversation's files by id (M5 T8 / T11; file library spec §2): any file the conversation
|
|
65
|
+
* refers to (a delivery or an upload sent in it). The conversation must be visible by the event
|
|
66
|
+
* stream's rule (else `conversation.not_found`); the file must be one the conversation refers to,
|
|
67
|
+
* not deleted, its blob readable (else `conversation.artifact_not_found`). Bytes are read through
|
|
68
|
+
* the file's blob (size and etag checked), never an event's `objectKey`.
|
|
68
69
|
*
|
|
69
|
-
* -
|
|
70
|
-
*
|
|
71
|
-
* -
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* 查找走 `conversation_events` 的主键 `(conversation_id, seq)` 前缀,在 SQL 里按 `type` 与
|
|
76
|
-
* `payload->>'artifactId'` 过滤、`LIMIT 1`(只扫这一个会话的事件,不在 JS 里扫日志;不加迁移)。
|
|
70
|
+
* - Download: a 302 to a presigned address, `attachment` by default (with the file's name and
|
|
71
|
+
* type); `inline` only takes effect for bitmaps (the web's thumbnails).
|
|
72
|
+
* - Text preview: `text/*` and the text formats, the first {@link ARTIFACT_PREVIEW_MAX_BYTES} bytes
|
|
73
|
+
* by range, at most {@link ARTIFACT_PREVIEW_MAX_LINES} lines, as a JSON string (shown as plain
|
|
74
|
+
* text); other types, or NUL bytes in the head (binary after all) →
|
|
75
|
+
* `conversation.artifact_not_previewable`.
|
|
77
76
|
*/
|
|
78
77
|
let ConversationArtifacts = class ConversationArtifacts {
|
|
79
|
-
db;
|
|
80
78
|
storage;
|
|
81
79
|
access;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
files;
|
|
81
|
+
constructor(storage,
|
|
82
|
+
/** Conversation visibility (the same rule as the conversation's SSE stream). */
|
|
83
|
+
access,
|
|
84
|
+
/** The files the conversation refers to, and their bytes. */
|
|
85
|
+
files) {
|
|
86
86
|
this.storage = storage;
|
|
87
87
|
this.access = access;
|
|
88
|
+
this.files = files;
|
|
88
89
|
}
|
|
89
90
|
async find(orgId, conversationId, viewerAccountId, artifactId) {
|
|
90
91
|
if (!UUID_RE.test(conversationId))
|
|
@@ -94,25 +95,17 @@ let ConversationArtifacts = class ConversationArtifacts {
|
|
|
94
95
|
}
|
|
95
96
|
if (!UUID_RE.test(artifactId))
|
|
96
97
|
throw artifactNotFound();
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
.select("payload")
|
|
100
|
-
.where("conversation_id", "=", conversationId)
|
|
101
|
-
.where("type", "=", "artifact_created")
|
|
102
|
-
.where(sql `payload->>'artifactId'`, "=", artifactId)
|
|
103
|
-
.limit(1)
|
|
104
|
-
.executeTakeFirst();
|
|
105
|
-
if (!row)
|
|
98
|
+
const [f] = await this.files.references(orgId, [conversationId], { ids: [artifactId] });
|
|
99
|
+
if (!f || !isLive(f))
|
|
106
100
|
throw artifactNotFound();
|
|
107
|
-
return
|
|
101
|
+
return f;
|
|
108
102
|
}
|
|
109
103
|
async downloadUrl(orgId, conversationId, viewerAccountId, artifactId, opts = {}) {
|
|
110
104
|
const a = await this.find(orgId, conversationId, viewerAccountId, artifactId);
|
|
111
|
-
|
|
112
|
-
if (!(await store.head(a.objectKey)))
|
|
105
|
+
if (!(await this.files.head(orgId, a)))
|
|
113
106
|
throw artifactNotFound();
|
|
114
107
|
const inline = opts.inline === true && isInlineArtifactType(a.contentType);
|
|
115
|
-
const url = await
|
|
108
|
+
const url = await this.storage.kernel(orgId).presignGet(a.blob.objectKey, {
|
|
116
109
|
ttlSeconds: ARTIFACT_DOWNLOAD_TTL_SECONDS,
|
|
117
110
|
downloadName: a.name,
|
|
118
111
|
disposition: inline ? "inline" : "attachment",
|
|
@@ -125,9 +118,9 @@ let ConversationArtifacts = class ConversationArtifacts {
|
|
|
125
118
|
if (!isTextArtifactType(a.contentType)) {
|
|
126
119
|
throw new ApiError("conversation.artifact_not_previewable", "Only text artifacts have a preview");
|
|
127
120
|
}
|
|
128
|
-
const got = await this.
|
|
129
|
-
|
|
130
|
-
|
|
121
|
+
const got = await this.files.open(orgId, a, {
|
|
122
|
+
range: { start: 0, end: ARTIFACT_PREVIEW_MAX_BYTES - 1 },
|
|
123
|
+
});
|
|
131
124
|
if (!got)
|
|
132
125
|
throw artifactNotFound();
|
|
133
126
|
const bytes = await readPrefix(got.body, ARTIFACT_PREVIEW_MAX_BYTES);
|
|
@@ -156,8 +149,8 @@ let ConversationArtifacts = class ConversationArtifacts {
|
|
|
156
149
|
};
|
|
157
150
|
ConversationArtifacts = __decorate([
|
|
158
151
|
Injectable(),
|
|
159
|
-
__param(0, Inject(
|
|
160
|
-
__param(1, Inject(
|
|
161
|
-
__param(2, Inject(
|
|
152
|
+
__param(0, Inject(StorageService)),
|
|
153
|
+
__param(1, Inject(ConversationAccess)),
|
|
154
|
+
__param(2, Inject(ReferencedFiles))
|
|
162
155
|
], ConversationArtifacts);
|
|
163
156
|
export { ConversationArtifacts };
|
|
@@ -2,35 +2,22 @@ import type { FastifyReply } from "fastify";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { type Principal } from "../identity/principal.js";
|
|
4
4
|
import { type OrgContext } from "../orgs/org.guard.js";
|
|
5
|
-
import {
|
|
6
|
-
declare const CreateBody: z.ZodObject<{
|
|
7
|
-
name: z.ZodString;
|
|
8
|
-
contentType: z.ZodString;
|
|
9
|
-
size: z.ZodNumber;
|
|
10
|
-
}, z.core.$strict>;
|
|
5
|
+
import { AttachmentsService } from "./attachments.service.js";
|
|
11
6
|
declare const DownloadQuery: z.ZodObject<{
|
|
12
7
|
as: z.ZodOptional<z.ZodEnum<{
|
|
13
8
|
url: "url";
|
|
14
9
|
}>>;
|
|
15
10
|
}, z.core.$strip>;
|
|
16
11
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* Download: `GET /:id/download` redirects (302) to the presigned URL (`Cache-Control: private,
|
|
23
|
-
* max-age=60`); `?as=url` answers `{ url }` with that address instead. Limits: `GET /limits` (types,
|
|
24
|
-
* per-file size, files per message, the media budget per request, whether storage is available; for the
|
|
25
|
-
* web's pre-checks; needs no object store). Without an object store the other routes answer 503
|
|
26
|
-
* `storage.unavailable`.
|
|
12
|
+
* Attachment downloads (`/api/v1/orgs/:orgId/attachments`, `agents.use`, people only): `GET
|
|
13
|
+
* /:id/download` redirects (302) to the presigned URL (`Cache-Control: private, max-age=60`) of a
|
|
14
|
+
* `read` copy (an image a tool showed the agent); `?as=url` answers `{ url }`
|
|
15
|
+
* with that address instead. Without an object store it answers 503 `storage.unavailable`. A
|
|
16
|
+
* person's uploads go through the file library (`/files`).
|
|
27
17
|
*/
|
|
28
18
|
export declare class AttachmentsController {
|
|
29
19
|
private readonly attachments;
|
|
30
20
|
constructor(attachments: AttachmentsService);
|
|
31
|
-
limits(principal: Principal): AttachmentLimits;
|
|
32
|
-
create(principal: Principal, org: OrgContext, body: z.infer<typeof CreateBody>): Promise<CreatedAttachment>;
|
|
33
|
-
finalize(principal: Principal, org: OrgContext, id: string): Promise<AttachmentView>;
|
|
34
21
|
download(principal: Principal, org: OrgContext, id: string, q: z.infer<typeof DownloadQuery>, reply: FastifyReply): Promise<void>;
|
|
35
22
|
}
|
|
36
23
|
export {};
|