@opengeni/worker-bundle 0.20.1 → 0.20.3
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/activities/agent-turn.d.ts +1 -1
- package/dist/activities/google-drive-publication.d.ts +53 -0
- package/dist/activities/image-generation-references.d.ts +2 -0
- package/dist/activities/knowledge-source-sync-driver.d.ts +21 -0
- package/dist/activities/knowledge-source-sync.d.ts +29 -1
- package/dist/activities/run-input.d.ts +12 -2
- package/dist/{activities-control-SMKF2OBE.js → activities-control-BJSDRSIP.js} +316 -14
- package/dist/{activities-control-SMKF2OBE.js.map → activities-control-BJSDRSIP.js.map} +1 -1
- package/dist/{activities-turn-IDS3WEHA.js → activities-turn-J5YO7XXX.js} +848 -137
- package/dist/activities-turn-J5YO7XXX.js.map +1 -0
- package/dist/index.js +1 -1
- package/package.json +12 -12
- package/src/activities/agent-turn.ts +172 -46
- package/src/activities/documents.ts +6 -4
- package/src/activities/google-drive-publication.ts +840 -0
- package/src/activities/image-generation-references.ts +11 -2
- package/src/activities/knowledge-source-sync-driver.ts +23 -0
- package/src/activities/knowledge-source-sync.ts +384 -9
- package/src/activities/run-input.ts +39 -7
- package/dist/activities-turn-IDS3WEHA.js.map +0 -1
|
@@ -8,13 +8,13 @@ import {
|
|
|
8
8
|
import { createHash } from "node:crypto";
|
|
9
9
|
import {
|
|
10
10
|
getActiveSessionHistoryItemsPaged,
|
|
11
|
-
|
|
11
|
+
getFilesForSubject,
|
|
12
12
|
getLatestRunState,
|
|
13
13
|
getHumanInputResumeForEvent,
|
|
14
14
|
getSandboxSessionEnvelope,
|
|
15
15
|
getSessionEvent,
|
|
16
16
|
listSessionSystemUpdatesForTurn,
|
|
17
|
-
|
|
17
|
+
requireFileForSubject,
|
|
18
18
|
type Database,
|
|
19
19
|
} from "@opengeni/db";
|
|
20
20
|
import {
|
|
@@ -76,9 +76,12 @@ export type PreparedTurnInput = {
|
|
|
76
76
|
|
|
77
77
|
export type TurnInputOptions = {
|
|
78
78
|
turnId: string;
|
|
79
|
+
/** Frozen initiating-human authority for every model-visible file read. */
|
|
80
|
+
fileAuthority: { accountId: string; subjectId: string | null };
|
|
79
81
|
recovering?: boolean;
|
|
80
82
|
unavailableSandboxFilesNote?: string;
|
|
81
83
|
runCredentialsNote?: string;
|
|
84
|
+
mcpAvailabilityNote?: string;
|
|
82
85
|
providerApi: HistoryProviderApi;
|
|
83
86
|
projectCanonicalHistory?: ModelHistoryAttachmentProjector;
|
|
84
87
|
materializeModelHistory?: ModelHistoryAttachmentProjector;
|
|
@@ -290,6 +293,9 @@ function attachmentRefsFromItem(item: Record<string, unknown>): FileResourceRef[
|
|
|
290
293
|
}
|
|
291
294
|
|
|
292
295
|
function attachmentUnavailableText(ref: FileResourceRef, file: FileAsset | undefined): string {
|
|
296
|
+
if (!file) {
|
|
297
|
+
return `[Attachment unavailable or no longer authorized: ${ref.fileId}.]`;
|
|
298
|
+
}
|
|
293
299
|
const filename = file?.safeFilename ?? ref.fileId;
|
|
294
300
|
const mediaType = file?.contentType ?? "unknown type";
|
|
295
301
|
const path = file ? sandboxFilePath(ref, file) : `/workspace/${resourceMountPath(ref)}`;
|
|
@@ -307,7 +313,7 @@ function attachmentUnavailableText(ref: FileResourceRef, file: FileAsset | undef
|
|
|
307
313
|
*/
|
|
308
314
|
export function createModelHistoryAttachmentProjector(
|
|
309
315
|
db: Database,
|
|
310
|
-
workspaceId: string,
|
|
316
|
+
authority: { accountId: string; workspaceId: string; subjectId: string | null },
|
|
311
317
|
policy: ModelAttachmentInputPolicy,
|
|
312
318
|
readFileBytes?: (file: FileAsset) => Promise<Uint8Array>,
|
|
313
319
|
): ModelHistoryAttachmentProjector {
|
|
@@ -334,7 +340,10 @@ export function createModelHistoryAttachmentProjector(
|
|
|
334
340
|
|
|
335
341
|
const unknownIds = orderedFileIds.filter((id) => !fileById.has(id) && !missingFileIds.has(id));
|
|
336
342
|
if (unknownIds.length > 0) {
|
|
337
|
-
const files = await
|
|
343
|
+
const files = await getFilesForSubject(db, {
|
|
344
|
+
...authority,
|
|
345
|
+
fileIds: unknownIds,
|
|
346
|
+
});
|
|
338
347
|
for (const file of files) fileById.set(file.id, file);
|
|
339
348
|
for (const id of unknownIds) {
|
|
340
349
|
if (!fileById.has(id)) missingFileIds.add(id);
|
|
@@ -452,6 +461,7 @@ export async function turnInput(
|
|
|
452
461
|
: undefined,
|
|
453
462
|
options.unavailableSandboxFilesNote,
|
|
454
463
|
options.runCredentialsNote,
|
|
464
|
+
options.mcpAvailabilityNote,
|
|
455
465
|
);
|
|
456
466
|
if (trigger.type === "user.message") {
|
|
457
467
|
const payload = trigger.payload as {
|
|
@@ -467,7 +477,14 @@ export async function turnInput(
|
|
|
467
477
|
const fileAttachments = await measureHistoryPreparationPhase(
|
|
468
478
|
options,
|
|
469
479
|
"current_attachment_resolution",
|
|
470
|
-
async () =>
|
|
480
|
+
async () =>
|
|
481
|
+
await resolveUserMessageFileAttachments(
|
|
482
|
+
db,
|
|
483
|
+
options.fileAuthority.accountId,
|
|
484
|
+
trigger.workspaceId,
|
|
485
|
+
options.fileAuthority.subjectId,
|
|
486
|
+
resources,
|
|
487
|
+
),
|
|
471
488
|
);
|
|
472
489
|
const attachmentContext = userMessageAttachmentsContext(fileAttachments);
|
|
473
490
|
return await messageInput(
|
|
@@ -673,11 +690,19 @@ async function messageInput(
|
|
|
673
690
|
|
|
674
691
|
export async function userMessageTextWithAttachments(
|
|
675
692
|
db: Database,
|
|
693
|
+
accountId: string,
|
|
676
694
|
workspaceId: string,
|
|
695
|
+
subjectId: string | null,
|
|
677
696
|
text: string,
|
|
678
697
|
resources: ResourceRef[],
|
|
679
698
|
): Promise<string> {
|
|
680
|
-
const fileAttachments = await resolveUserMessageFileAttachments(
|
|
699
|
+
const fileAttachments = await resolveUserMessageFileAttachments(
|
|
700
|
+
db,
|
|
701
|
+
accountId,
|
|
702
|
+
workspaceId,
|
|
703
|
+
subjectId,
|
|
704
|
+
resources,
|
|
705
|
+
);
|
|
681
706
|
const attachmentContext = userMessageAttachmentsContext(fileAttachments);
|
|
682
707
|
return attachmentContext ? [text, "", attachmentContext].join("\n") : text;
|
|
683
708
|
}
|
|
@@ -689,13 +714,20 @@ type UserMessageFileAttachment = {
|
|
|
689
714
|
|
|
690
715
|
async function resolveUserMessageFileAttachments(
|
|
691
716
|
db: Database,
|
|
717
|
+
accountId: string,
|
|
692
718
|
workspaceId: string,
|
|
719
|
+
subjectId: string | null,
|
|
693
720
|
resources: ResourceRef[],
|
|
694
721
|
): Promise<UserMessageFileAttachment[]> {
|
|
695
722
|
const attachments: UserMessageFileAttachment[] = [];
|
|
696
723
|
for (const resource of resources) {
|
|
697
724
|
if (resource.kind !== "file") continue;
|
|
698
|
-
const file = await
|
|
725
|
+
const file = await requireFileForSubject(db, {
|
|
726
|
+
accountId,
|
|
727
|
+
workspaceId,
|
|
728
|
+
subjectId,
|
|
729
|
+
fileId: resource.fileId,
|
|
730
|
+
});
|
|
699
731
|
attachments.push({ resource, file });
|
|
700
732
|
}
|
|
701
733
|
return attachments;
|