@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
|
@@ -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 };
|
|
@@ -107,7 +107,8 @@ export function buildSuggestionRequest(input) {
|
|
|
107
107
|
reference = ref.request;
|
|
108
108
|
// every event of the snapshot (it ends at the run's terminal event): absorbable events past
|
|
109
109
|
// the recorded absorbedUpToSeq stay out, anything else model-visible after the final reply
|
|
110
|
-
// breaks the check below
|
|
110
|
+
// breaks the check below. It keeps the baseline's recorded cacheTtl: the same tier as the
|
|
111
|
+
// last call keeps its cache entry whole (idle compaction spec §9.4)
|
|
111
112
|
extended = assembleModelRequest({ ...gathered.input, events });
|
|
112
113
|
}
|
|
113
114
|
catch (err) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ModelUsage } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import type { Job, Queue, Worker } from "bullmq";
|
|
3
|
+
import { ConversationMedia } from "../files/conversation-media.js";
|
|
3
4
|
import { SettingsService } from "../identity/settings.js";
|
|
4
5
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
5
6
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
@@ -9,7 +10,6 @@ import { OrgSettingsService } from "../orgs/settings.service.js";
|
|
|
9
10
|
import { type AuditEntry, type HookRunner } from "../runtime/hook-calls.js";
|
|
10
11
|
import { ProviderRegistry } from "../runtime/providers.js";
|
|
11
12
|
import { UsageReportJobs } from "../runtime/usage-report-jobs.js";
|
|
12
|
-
import { AttachmentsService } from "./attachments.service.js";
|
|
13
13
|
import { EventLog } from "./event-log.js";
|
|
14
14
|
import type { ConversationEvent, EventPayload } from "./events.js";
|
|
15
15
|
import { PromptSuggestionStore } from "./prompt-suggestion-store.js";
|
|
@@ -58,7 +58,7 @@ export declare class PromptSuggestionGenerator {
|
|
|
58
58
|
/** The platform's compaction settings (the org's reserve for the fit guard). */
|
|
59
59
|
private readonly settings;
|
|
60
60
|
/** The run's media, as the run's steps load it. */
|
|
61
|
-
private readonly
|
|
61
|
+
private readonly media;
|
|
62
62
|
private readonly store;
|
|
63
63
|
private readonly config;
|
|
64
64
|
private readonly log;
|
|
@@ -74,7 +74,7 @@ export declare class PromptSuggestionGenerator {
|
|
|
74
74
|
/** The platform's compaction settings (the org's reserve for the fit guard). */
|
|
75
75
|
settings: Pick<SettingsService, "get">,
|
|
76
76
|
/** The run's media, as the run's steps load it. */
|
|
77
|
-
|
|
77
|
+
media: Pick<ConversationMedia, "mediaInfo" | "fetchMedia">, store: Pick<PromptSuggestionStore, "isFresh" | "put">, config: KernelConfigService, log: Pick<KernelLogger, "debug" | "warn">, txHost: TransactionHost, timeoutMs?: () => number);
|
|
78
78
|
private get db();
|
|
79
79
|
/**
|
|
80
80
|
* One suggestion for the run (spec §1–§4); `shutdown` aborts the call (the worker stopping).
|
|
@@ -16,6 +16,8 @@ import { loadSnapshotMedia } from "../evals/reconstruct.js";
|
|
|
16
16
|
import { takeSnapshot, toEvents } from "../evals/snapshot.js";
|
|
17
17
|
import { ExtensionsModule } from "../extensions/extensions.module.js";
|
|
18
18
|
import { ExtensionHost } from "../extensions/host.js";
|
|
19
|
+
import { ConversationMedia } from "../files/conversation-media.js";
|
|
20
|
+
import { LibraryReadModule } from "../files/library-read.module.js";
|
|
19
21
|
import { audit } from "../identity/audit.js";
|
|
20
22
|
import { IdentityModule } from "../identity/identity.module.js";
|
|
21
23
|
import { SettingsService } from "../identity/settings.js";
|
|
@@ -31,8 +33,6 @@ import { fireObserve, hookDeniedAudit, hookDeniedEvent, hookRequestOf, } from ".
|
|
|
31
33
|
import { consumeModelStream, deltaChars } from "../runtime/model-call.js";
|
|
32
34
|
import { ProviderRegistry, ProvidersModule } from "../runtime/providers.js";
|
|
33
35
|
import { UsageReportJobs, UsageReportJobsModule } from "../runtime/usage-report-jobs.js";
|
|
34
|
-
import { AttachmentsModule } from "./attachments.module.js";
|
|
35
|
-
import { AttachmentsService } from "./attachments.service.js";
|
|
36
36
|
import { EventLog, EventLogModule } from "./event-log.js";
|
|
37
37
|
import { buildSuggestionRequest, cleanSuggestion, lastModelCallOf, PROMPT_SUGGESTION_TIMEOUT_MS, suggestionEligible, suggestionStale, } from "./prompt-suggestion-request.js";
|
|
38
38
|
import { PromptSuggestionStore } from "./prompt-suggestion-store.js";
|
|
@@ -98,7 +98,7 @@ let PromptSuggestionGenerator = class PromptSuggestionGenerator {
|
|
|
98
98
|
usage;
|
|
99
99
|
orgSettings;
|
|
100
100
|
settings;
|
|
101
|
-
|
|
101
|
+
media;
|
|
102
102
|
store;
|
|
103
103
|
config;
|
|
104
104
|
log;
|
|
@@ -112,7 +112,7 @@ let PromptSuggestionGenerator = class PromptSuggestionGenerator {
|
|
|
112
112
|
/** The platform's compaction settings (the org's reserve for the fit guard). */
|
|
113
113
|
settings,
|
|
114
114
|
/** The run's media, as the run's steps load it. */
|
|
115
|
-
|
|
115
|
+
media, store, config, log, txHost, timeoutMs = () => PROMPT_SUGGESTION_TIMEOUT_MS) {
|
|
116
116
|
this.kdb = kdb;
|
|
117
117
|
this.eventLog = eventLog;
|
|
118
118
|
this.registry = registry;
|
|
@@ -120,7 +120,7 @@ let PromptSuggestionGenerator = class PromptSuggestionGenerator {
|
|
|
120
120
|
this.usage = usage;
|
|
121
121
|
this.orgSettings = orgSettings;
|
|
122
122
|
this.settings = settings;
|
|
123
|
-
this.
|
|
123
|
+
this.media = media;
|
|
124
124
|
this.store = store;
|
|
125
125
|
this.config = config;
|
|
126
126
|
this.log = log;
|
|
@@ -177,8 +177,8 @@ let PromptSuggestionGenerator = class PromptSuggestionGenerator {
|
|
|
177
177
|
let media;
|
|
178
178
|
try {
|
|
179
179
|
media = await loadSnapshotMedia(snapshot, last.seq, info, {
|
|
180
|
-
info: (orgId, convId, ids) => this.
|
|
181
|
-
fetch: (orgId, convId, ids, caps) => this.
|
|
180
|
+
info: (orgId, convId, ids) => this.media.mediaInfo(orgId, convId, ids),
|
|
181
|
+
fetch: (orgId, convId, ids, caps) => this.media.fetchMedia(orgId, convId, ids, caps),
|
|
182
182
|
});
|
|
183
183
|
}
|
|
184
184
|
catch {
|
|
@@ -214,7 +214,7 @@ let PromptSuggestionGenerator = class PromptSuggestionGenerator {
|
|
|
214
214
|
try {
|
|
215
215
|
out = await consumeModelStream(provider, request, info.streamIdleTimeoutMs ?? this.config.get().runtime.streamIdleMs, signal, (ev) => {
|
|
216
216
|
streamedChars += deltaChars(ev);
|
|
217
|
-
});
|
|
217
|
+
}, this.log);
|
|
218
218
|
}
|
|
219
219
|
catch (err) {
|
|
220
220
|
if (shutdown.aborted) {
|
|
@@ -447,7 +447,7 @@ PromptSuggestionGenerator = __decorate([
|
|
|
447
447
|
__param(4, Inject(UsageReportJobs)),
|
|
448
448
|
__param(5, Inject(OrgSettingsService)),
|
|
449
449
|
__param(6, Inject(SettingsService)),
|
|
450
|
-
__param(7, Inject(
|
|
450
|
+
__param(7, Inject(ConversationMedia)),
|
|
451
451
|
__param(8, Inject(PromptSuggestionStore)),
|
|
452
452
|
__param(9, Inject(KernelConfigService)),
|
|
453
453
|
__param(10, Inject(KERNEL_LOGGER)),
|
|
@@ -555,7 +555,8 @@ PromptSuggestionsModule = __decorate([
|
|
|
555
555
|
UsageReportJobsModule,
|
|
556
556
|
OrgSettingsModule,
|
|
557
557
|
IdentityModule,
|
|
558
|
-
|
|
558
|
+
// the run's media: library files the conversation refers to, and `read` copies
|
|
559
|
+
LibraryReadModule,
|
|
559
560
|
PROMPT_SUGGESTION_QUEUE_MODULE,
|
|
560
561
|
],
|
|
561
562
|
providers: [PromptSuggestionStore, PromptSuggestionGenerator, PromptSuggestionQueue],
|
|
@@ -11,6 +11,7 @@ import { randomUUID } from "node:crypto";
|
|
|
11
11
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
12
|
import { sql } from "kysely";
|
|
13
13
|
import { releaseQueuedTaskRunIn } from "../automations/run-tracker.js";
|
|
14
|
+
import { ApiError } from "../errors.js";
|
|
14
15
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
15
16
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
16
17
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
@@ -114,8 +115,12 @@ let ConversationQueue = class ConversationQueue {
|
|
|
114
115
|
.select("last_seq")
|
|
115
116
|
.where("id", "=", conversationId)
|
|
116
117
|
.where("org_id", "=", orgId)
|
|
118
|
+
// deleted after the caller's check: no files are attached to it
|
|
119
|
+
.where("deleted_at", "is", null)
|
|
117
120
|
.forUpdate()
|
|
118
|
-
.
|
|
121
|
+
.executeTakeFirst();
|
|
122
|
+
if (!conv)
|
|
123
|
+
throw new ApiError("conversation.not_found", "Conversation not found");
|
|
119
124
|
const existing = await t
|
|
120
125
|
.selectFrom("conversation_queue")
|
|
121
126
|
.select(COLUMNS)
|
|
@@ -140,7 +145,7 @@ let ConversationQueue = class ConversationQueue {
|
|
|
140
145
|
const fileMeta = blocks.flatMap((b) => (b.type === "image" || b.type === "document" || b.type === "file") && b.source.kind === "ref"
|
|
141
146
|
? [
|
|
142
147
|
{
|
|
143
|
-
attachmentId: b.source.
|
|
148
|
+
attachmentId: b.source.fileId,
|
|
144
149
|
name: b.name ?? "",
|
|
145
150
|
mediaType: b.mediaType,
|
|
146
151
|
...(b.size !== undefined && { size: b.size }),
|
package/dist/ctx/create-ctx.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ import type { HookRunner } from "../runtime/hook-calls.js";
|
|
|
14
14
|
import type { DeviceReports } from "../sandbox/device-reports.js";
|
|
15
15
|
import type { ShareLiveness } from "../shares/liveness.js";
|
|
16
16
|
import type { EmbedTokens } from "../ui/embed-token.js";
|
|
17
|
-
import { type UiActionHandler, type UiRender } from "../ui/registry.js";
|
|
17
|
+
import { type UiActionHandler, type UiQueryHandler, type UiRender } from "../ui/registry.js";
|
|
18
18
|
import { type BusSubscriber } from "./bus.js";
|
|
19
19
|
import { type ExtensionNetServices } from "./net.js";
|
|
20
20
|
import { type Keyring } from "./secrets.js";
|
|
@@ -195,6 +195,8 @@ export type KernelExtensionContext = ExtensionContext & {
|
|
|
195
195
|
uiViews: ReadonlyMap<string, UiRender>;
|
|
196
196
|
/** 经 `ctx.ui.action` 注册的动作处理函数(按贡献 id)。 */
|
|
197
197
|
uiActions: ReadonlyMap<string, UiActionHandler>;
|
|
198
|
+
/** Query handlers registered through `ctx.ui.query`, by component id. */
|
|
199
|
+
uiQueries: ReadonlyMap<string, UiQueryHandler>;
|
|
198
200
|
/** Setup checks registered through `ctx.setup.check`, by id. */
|
|
199
201
|
setupChecks: ReadonlyMap<string, RegisteredSetupCheck>;
|
|
200
202
|
/**
|
package/dist/ctx/create-ctx.js
CHANGED
|
@@ -810,12 +810,29 @@ identity = { sha256: null }) {
|
|
|
810
810
|
},
|
|
811
811
|
});
|
|
812
812
|
},
|
|
813
|
+
query(id, handler) {
|
|
814
|
+
uiReg.query(id, handler);
|
|
815
|
+
ledger.add({
|
|
816
|
+
kind: "ui.query",
|
|
817
|
+
key: id,
|
|
818
|
+
dispose: async () => {
|
|
819
|
+
if (uiReg.queries.get(id) === handler)
|
|
820
|
+
uiReg.queries.delete(id);
|
|
821
|
+
},
|
|
822
|
+
});
|
|
823
|
+
},
|
|
813
824
|
// 目标先核对(一条查询):插件在 orgId 启用;带对话时对话属于 orgId。不满足就只记 debug、不发
|
|
814
825
|
// (插件拿着过期或别的组织的 id 调用不是错误,但不能借它往别的组织的流里发刷新)。A `platform.page`
|
|
815
826
|
// contribution takes no orgId and refreshes the platform stream (super admins only)
|
|
816
827
|
async invalidate(target) {
|
|
817
828
|
const t = uiReg.target(target, platformUi);
|
|
818
|
-
|
|
829
|
+
// `queries`: the contribution's component queries are refetched too (full pages spec §4.1)
|
|
830
|
+
const msg = {
|
|
831
|
+
kind: "ui",
|
|
832
|
+
plugin: name,
|
|
833
|
+
contribution: t.contribution,
|
|
834
|
+
queries: true,
|
|
835
|
+
};
|
|
819
836
|
if (t.scope === "platform") {
|
|
820
837
|
await kernelBus.publish(PLATFORM_UI_TOPIC, msg);
|
|
821
838
|
return;
|
|
@@ -874,6 +891,7 @@ identity = { sha256: null }) {
|
|
|
874
891
|
uiResolution,
|
|
875
892
|
uiViews: uiReg.views,
|
|
876
893
|
uiActions: uiReg.actions,
|
|
894
|
+
uiQueries: uiReg.queries,
|
|
877
895
|
setupChecks,
|
|
878
896
|
ledger,
|
|
879
897
|
async beginDispose(deadline) {
|