@opengeni/worker-bundle 0.20.1 → 0.22.0-canary.0
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/admission.d.ts +52 -0
- package/dist/activities/agent-turn/agent-build.d.ts +89 -0
- package/dist/activities/agent-turn/claim.d.ts +67 -0
- package/dist/activities/agent-turn/codex-capacity.d.ts +40 -0
- package/dist/activities/agent-turn/codex.d.ts +32 -0
- package/dist/activities/agent-turn/compaction-prep.d.ts +88 -0
- package/dist/activities/agent-turn/credential-leases.d.ts +56 -0
- package/dist/activities/agent-turn/errors.d.ts +253 -0
- package/dist/activities/agent-turn/failure-settlement.d.ts +33 -0
- package/dist/activities/agent-turn/file-resources.d.ts +37 -0
- package/dist/activities/agent-turn/finalization.d.ts +42 -0
- package/dist/activities/agent-turn/github-repository-bindings.d.ts +105 -0
- package/dist/activities/agent-turn/governance-model.d.ts +66 -0
- package/dist/activities/agent-turn/history-sink.d.ts +52 -0
- package/dist/activities/agent-turn/history.d.ts +63 -0
- package/dist/activities/agent-turn/media-artifacts.d.ts +145 -0
- package/dist/activities/agent-turn/model-usage.d.ts +218 -0
- package/dist/activities/agent-turn/quiescence.d.ts +135 -0
- package/dist/activities/agent-turn/run-credentials.d.ts +84 -0
- package/dist/activities/agent-turn/run.d.ts +3 -0
- package/dist/activities/agent-turn/sandbox-establish.d.ts +93 -0
- package/dist/activities/agent-turn/sandbox-provision.d.ts +89 -0
- package/dist/activities/agent-turn/sandbox-route.d.ts +151 -0
- package/dist/activities/agent-turn/sandbox-runtime.d.ts +44 -0
- package/dist/activities/agent-turn/stream-attempt.d.ts +107 -0
- package/dist/activities/agent-turn/tool-environment.d.ts +142 -0
- package/dist/activities/agent-turn/tool-policy.d.ts +127 -0
- package/dist/activities/agent-turn/tool-result-spill.d.ts +59 -0
- package/dist/activities/agent-turn/turn-context.d.ts +144 -0
- package/dist/activities/agent-turn/xai-capacity.d.ts +2 -0
- package/dist/activities/agent-turn.d.ts +12 -954
- package/dist/activities/automations.d.ts +16 -0
- package/dist/activities/common.d.ts +1 -1
- package/dist/activities/connector-attachments.d.ts +13 -0
- package/dist/activities/documents.d.ts +1 -0
- package/dist/activities/environment.d.ts +26 -15
- package/dist/activities/generated-images.d.ts +1 -1
- package/dist/activities/git-credential-renewal.d.ts +3 -1
- package/dist/activities/goals.d.ts +4 -1
- package/dist/activities/google-drive-provider.d.ts +29 -0
- package/dist/activities/google-drive-publication.d.ts +66 -0
- package/dist/activities/image-generation-references.d.ts +2 -0
- package/dist/activities/incident-telemetry-authority.d.ts +52 -0
- package/dist/activities/incident-telemetry-preflight.d.ts +71 -0
- package/dist/activities/knowledge-source-sync-driver.d.ts +21 -0
- package/dist/activities/knowledge-source-sync.d.ts +33 -1
- package/dist/activities/mcp-credentials.d.ts +9 -3
- package/dist/activities/open-suffix-resume.d.ts +77 -0
- package/dist/activities/packs.d.ts +3 -11
- package/dist/activities/parent-wake.d.ts +19 -0
- package/dist/activities/retained-screenshot-reaper.d.ts +1 -1
- package/dist/activities/retained-screenshots.d.ts +1 -1
- package/dist/activities/rig-verification.d.ts +1 -1
- package/dist/activities/run-input.d.ts +16 -7
- package/dist/activities/sandbox-images.d.ts +1 -14
- package/dist/activities/sandbox-lease.d.ts +21 -3
- package/dist/activities/scheduled-tasks.d.ts +47 -0
- package/dist/activities/types.d.ts +23 -2
- package/dist/activities/video-media-validation.d.ts +1 -1
- package/dist/activities/video-output-retention.d.ts +1 -2
- package/dist/activities/xai-auth.d.ts +3 -0
- package/dist/{activities-control-SMKF2OBE.js → activities-control-DKG22ONJ.js} +2946 -549
- package/dist/activities-control-DKG22ONJ.js.map +1 -0
- package/dist/activities-control.d.ts +6 -2
- package/dist/activities-turn-4IMC3MAA.js +21326 -0
- package/dist/activities-turn-4IMC3MAA.js.map +1 -0
- package/dist/activities.d.ts +7 -3
- package/dist/artifact-materializer-entry.js +41 -22
- package/dist/artifact-materializer-entry.js.map +1 -1
- package/dist/{chunk-N5TJIFCE.js → chunk-CE7TPKBS.js} +468 -1
- package/dist/chunk-CE7TPKBS.js.map +1 -0
- package/dist/chunk-CNYGVRKF.js +4698 -0
- package/dist/chunk-CNYGVRKF.js.map +1 -0
- package/dist/connection-provider-use.d.ts +18 -0
- package/dist/editable-artifact-materializer.d.ts +4 -3
- package/dist/github-rest-mcp.d.ts +26 -0
- package/dist/index.d.ts +10 -2
- package/dist/index.js +58 -14
- package/dist/index.js.map +1 -1
- package/dist/knowledge-source-sync-activity-policy.d.ts +2 -0
- package/dist/model-context-contributions.d.ts +8 -4
- package/dist/observability-metrics.d.ts +63 -4
- package/dist/opensandbox-kubernetes-inventory.d.ts +21 -0
- package/dist/personal-github-git-credentials.d.ts +9 -0
- package/dist/pr-review-credentials.d.ts +6 -0
- package/dist/sandbox-archive-storage.d.ts +45 -0
- package/dist/sandbox-resume.d.ts +65 -6
- package/dist/sandbox-routing.d.ts +38 -2
- package/dist/scheduled-alert-occurrence.d.ts +33 -0
- package/dist/workflow-bundle.js +87 -28
- package/dist/workflows/activities.d.ts +1 -0
- package/dist/workflows/automations.d.ts +6 -0
- package/dist/workflows/document-index.d.ts +1 -0
- package/dist/workflows.d.ts +1 -0
- package/package.json +17 -17
- package/src/activities/agent-turn/admission.ts +292 -0
- package/src/activities/agent-turn/agent-build.ts +802 -0
- package/src/activities/agent-turn/claim.ts +590 -0
- package/src/activities/agent-turn/codex-capacity.ts +720 -0
- package/src/activities/agent-turn/codex.ts +94 -0
- package/src/activities/agent-turn/compaction-prep.ts +722 -0
- package/src/activities/agent-turn/credential-leases.ts +240 -0
- package/src/activities/agent-turn/errors.ts +1068 -0
- package/src/activities/agent-turn/failure-settlement.ts +1436 -0
- package/src/activities/agent-turn/file-resources.ts +227 -0
- package/src/activities/agent-turn/finalization.ts +754 -0
- package/src/activities/agent-turn/github-repository-bindings.ts +300 -0
- package/src/activities/agent-turn/governance-model.ts +465 -0
- package/src/activities/agent-turn/history-sink.ts +139 -0
- package/src/activities/agent-turn/history.ts +200 -0
- package/src/activities/agent-turn/media-artifacts.ts +359 -0
- package/src/activities/agent-turn/model-usage.ts +823 -0
- package/src/activities/agent-turn/quiescence.ts +353 -0
- package/src/activities/agent-turn/run-credentials.ts +761 -0
- package/src/activities/agent-turn/run.ts +1530 -0
- package/src/activities/agent-turn/sandbox-establish.ts +1207 -0
- package/src/activities/agent-turn/sandbox-provision.ts +569 -0
- package/src/activities/agent-turn/sandbox-route.ts +358 -0
- package/src/activities/agent-turn/sandbox-runtime.ts +731 -0
- package/src/activities/agent-turn/stream-attempt.ts +1670 -0
- package/src/activities/agent-turn/tool-environment.ts +729 -0
- package/src/activities/agent-turn/tool-policy.ts +216 -0
- package/src/activities/agent-turn/tool-result-spill.ts +265 -0
- package/src/activities/agent-turn/turn-context.ts +281 -0
- package/src/activities/agent-turn/xai-capacity.ts +229 -0
- package/src/activities/agent-turn.ts +12 -12575
- package/src/activities/api-integrations.ts +3 -0
- package/src/activities/automations.ts +214 -0
- package/src/activities/codemode-dispatcher.ts +12 -1
- package/src/activities/common.ts +1 -5
- package/src/activities/connector-attachments.ts +168 -0
- package/src/activities/context-compaction.ts +18 -0
- package/src/activities/documents.ts +6 -4
- package/src/activities/environment.ts +151 -55
- package/src/activities/generated-images.ts +26 -11
- package/src/activities/git-credential-renewal.ts +13 -3
- package/src/activities/goals.ts +85 -19
- package/src/activities/google-drive-provider.ts +178 -0
- package/src/activities/google-drive-publication.ts +938 -0
- package/src/activities/image-generation-references.ts +11 -2
- package/src/activities/incident-telemetry-authority.ts +327 -0
- package/src/activities/incident-telemetry-preflight.ts +317 -0
- package/src/activities/knowledge-source-sync-driver.ts +23 -0
- package/src/activities/knowledge-source-sync.ts +556 -40
- package/src/activities/mcp-credentials.ts +191 -17
- package/src/activities/open-suffix-resume.ts +422 -0
- package/src/activities/packs.ts +12 -60
- package/src/activities/parent-wake.ts +64 -14
- package/src/activities/retained-screenshot-reaper.ts +6 -3
- package/src/activities/retained-screenshots.ts +15 -47
- package/src/activities/rig-verification.ts +1 -1
- package/src/activities/run-input.ts +128 -136
- package/src/activities/sandbox-images.ts +7 -166
- package/src/activities/sandbox-lease.ts +406 -15
- package/src/activities/scheduled-tasks.ts +2103 -411
- package/src/activities/session-state.ts +10 -2
- package/src/activities/types.ts +32 -2
- package/src/activities/video-media-validation.ts +3 -3
- package/src/activities/video-output-retention.ts +2 -57
- package/src/activities/xai-auth.ts +8 -0
- package/src/activities-control.ts +2 -0
- package/src/activities.ts +3 -0
- package/src/activity-services.ts +13 -4
- package/src/connection-provider-use.ts +36 -0
- package/src/editable-artifact-materializer-subprocess.ts +25 -14
- package/src/editable-artifact-materializer.ts +29 -18
- package/src/github-rest-mcp.ts +713 -0
- package/src/http.ts +16 -6
- package/src/index.ts +40 -5
- package/src/knowledge-source-sync-activity-policy.ts +2 -0
- package/src/model-context-contributions.ts +33 -10
- package/src/observability-metrics.ts +357 -0
- package/src/opensandbox-kubernetes-inventory.ts +292 -0
- package/src/personal-github-git-credentials.ts +331 -0
- package/src/pr-review-credentials.ts +163 -0
- package/src/sandbox-archive-storage.ts +159 -0
- package/src/sandbox-resume.ts +449 -63
- package/src/sandbox-routing.ts +314 -16
- package/src/scheduled-alert-occurrence.ts +176 -0
- package/src/workflows/activities.ts +18 -2
- package/src/workflows/automations.ts +11 -0
- package/src/workflows/session.ts +13 -3
- package/src/workflows.ts +1 -0
- package/dist/activities-control-SMKF2OBE.js.map +0 -1
- package/dist/activities-turn-IDS3WEHA.js +0 -16532
- package/dist/activities-turn-IDS3WEHA.js.map +0 -1
- package/dist/chunk-N5TJIFCE.js.map +0 -1
- package/dist/chunk-P6Z2SLAA.js +0 -3092
- package/dist/chunk-P6Z2SLAA.js.map +0 -1
|
@@ -8,13 +8,11 @@ import {
|
|
|
8
8
|
import { createHash } from "node:crypto";
|
|
9
9
|
import {
|
|
10
10
|
getActiveSessionHistoryItemsPaged,
|
|
11
|
-
|
|
12
|
-
getLatestRunState,
|
|
13
|
-
getHumanInputResumeForEvent,
|
|
11
|
+
getFilesForSubject,
|
|
14
12
|
getSandboxSessionEnvelope,
|
|
15
13
|
getSessionEvent,
|
|
16
14
|
listSessionSystemUpdatesForTurn,
|
|
17
|
-
|
|
15
|
+
listTurnOpenSuffixToolCalls,
|
|
18
16
|
type Database,
|
|
19
17
|
} from "@opengeni/db";
|
|
20
18
|
import {
|
|
@@ -76,13 +74,15 @@ export type PreparedTurnInput = {
|
|
|
76
74
|
|
|
77
75
|
export type TurnInputOptions = {
|
|
78
76
|
turnId: string;
|
|
77
|
+
/** Frozen initiating-human authority for every model-visible file read. */
|
|
78
|
+
fileAuthority: { accountId: string; subjectId: string | null };
|
|
79
79
|
recovering?: boolean;
|
|
80
80
|
unavailableSandboxFilesNote?: string;
|
|
81
81
|
runCredentialsNote?: string;
|
|
82
|
+
mcpAvailabilityNote?: string;
|
|
82
83
|
providerApi: HistoryProviderApi;
|
|
83
84
|
projectCanonicalHistory?: ModelHistoryAttachmentProjector;
|
|
84
85
|
materializeModelHistory?: ModelHistoryAttachmentProjector;
|
|
85
|
-
materializeSerializedRunState?: (serialized: string) => Promise<string>;
|
|
86
86
|
projectModelHistory?: ModelHistoryAttachmentProjector;
|
|
87
87
|
loadActiveHistory?: typeof getActiveSessionHistoryItemsPaged;
|
|
88
88
|
/** Bounded critical-path timings; telemetry failures never affect preparation. */
|
|
@@ -145,8 +145,14 @@ export type ModelAttachmentContent = {
|
|
|
145
145
|
|
|
146
146
|
export type ModelHistoryAttachmentProjector = (
|
|
147
147
|
items: Array<Record<string, unknown>>,
|
|
148
|
+
options?: ModelHistoryAttachmentProjectionOptions,
|
|
148
149
|
) => Promise<Array<Record<string, unknown>>>;
|
|
149
150
|
|
|
151
|
+
export type ModelHistoryAttachmentProjectionOptions = {
|
|
152
|
+
/** Exact, already-authorized files attached to the triggering message. */
|
|
153
|
+
inlineFiles?: readonly FileAsset[];
|
|
154
|
+
};
|
|
155
|
+
|
|
150
156
|
export type ModelAttachmentInputPolicy = {
|
|
151
157
|
supportsImageInput: boolean;
|
|
152
158
|
inputFileMediaTypes: readonly string[];
|
|
@@ -209,6 +215,7 @@ export async function modelAttachmentContentForFiles(
|
|
|
209
215
|
if (
|
|
210
216
|
file.status !== "ready" ||
|
|
211
217
|
!descriptor ||
|
|
218
|
+
descriptor.kind !== "image" ||
|
|
212
219
|
file.sizeBytes > remainingBytes ||
|
|
213
220
|
!/^[a-f0-9]{64}$/.test(checksum)
|
|
214
221
|
) {
|
|
@@ -266,18 +273,6 @@ export async function modelAttachmentContentForFiles(
|
|
|
266
273
|
);
|
|
267
274
|
}
|
|
268
275
|
|
|
269
|
-
function modelAcceptsFileMediaType(
|
|
270
|
-
policy: ModelAttachmentInputPolicy,
|
|
271
|
-
contentType: string,
|
|
272
|
-
): boolean {
|
|
273
|
-
const normalized = contentType.toLowerCase().split(";", 1)[0]?.trim() ?? "";
|
|
274
|
-
return policy.inputFileMediaTypes.some(
|
|
275
|
-
(accepted) =>
|
|
276
|
-
accepted === normalized ||
|
|
277
|
-
(accepted.endsWith("/*") && normalized.startsWith(accepted.slice(0, -1))),
|
|
278
|
-
);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
276
|
function attachmentRefsFromItem(item: Record<string, unknown>): FileResourceRef[] {
|
|
282
277
|
const raw = item[MODEL_ATTACHMENT_REFS_FIELD];
|
|
283
278
|
if (!Array.isArray(raw)) return [];
|
|
@@ -289,34 +284,36 @@ function attachmentRefsFromItem(item: Record<string, unknown>): FileResourceRef[
|
|
|
289
284
|
return refs;
|
|
290
285
|
}
|
|
291
286
|
|
|
292
|
-
function
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
287
|
+
function attachmentReceiptText(ref: FileResourceRef, file: FileAsset | undefined): string {
|
|
288
|
+
if (!file) {
|
|
289
|
+
return (
|
|
290
|
+
`[Earlier attachment: fileId=${ref.fileId}; mountDirectory=${resourceMountPath(ref)}. ` +
|
|
291
|
+
`Use the existing file there, or call files__files_get_download_url with this fileId and ` +
|
|
292
|
+
`download it with the shell.]`
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
const path = sandboxFilePath(ref, file);
|
|
296
296
|
return (
|
|
297
|
-
`[Attachment
|
|
298
|
-
`
|
|
299
|
-
`
|
|
297
|
+
`[Attachment: ${file.safeFilename}; fileId=${file.id}; type=${file.contentType}; ` +
|
|
298
|
+
`bytes=${file.sizeBytes}; path=${path}. If the local path is absent, call ` +
|
|
299
|
+
`files__files_get_download_url with this fileId and download it with the shell.]`
|
|
300
300
|
);
|
|
301
301
|
}
|
|
302
302
|
|
|
303
303
|
/**
|
|
304
|
-
* Build one turn-scoped durable-attachment projector.
|
|
305
|
-
*
|
|
306
|
-
*
|
|
304
|
+
* Build one turn-scoped durable-attachment projector. Current attachment
|
|
305
|
+
* metadata arrives already authorized; bytes are memoized for same-turn retry.
|
|
306
|
+
* Historical projection has no database or object-storage path.
|
|
307
307
|
*/
|
|
308
308
|
export function createModelHistoryAttachmentProjector(
|
|
309
|
-
db: Database,
|
|
310
|
-
workspaceId: string,
|
|
311
309
|
policy: ModelAttachmentInputPolicy,
|
|
312
310
|
readFileBytes?: (file: FileAsset) => Promise<Uint8Array>,
|
|
313
311
|
): ModelHistoryAttachmentProjector {
|
|
314
|
-
const fileById = new Map<string, FileAsset>();
|
|
315
|
-
const missingFileIds = new Set<string>();
|
|
316
312
|
const contentById = new Map<string, ModelAttachmentContent>();
|
|
317
313
|
const attemptedContentIds = new Set<string>();
|
|
318
314
|
|
|
319
|
-
return async (items) => {
|
|
315
|
+
return async (items, options = {}) => {
|
|
316
|
+
const currentFileById = new Map((options.inlineFiles ?? []).map((file) => [file.id, file]));
|
|
320
317
|
const refsByIndex = new Map<number, FileResourceRef[]>();
|
|
321
318
|
const orderedFileIds: string[] = [];
|
|
322
319
|
const seenFileIds = new Set<string>();
|
|
@@ -332,29 +329,17 @@ export function createModelHistoryAttachmentProjector(
|
|
|
332
329
|
}
|
|
333
330
|
if (refsByIndex.size === 0) return items;
|
|
334
331
|
|
|
335
|
-
const unknownIds = orderedFileIds.filter((id) => !fileById.has(id) && !missingFileIds.has(id));
|
|
336
|
-
if (unknownIds.length > 0) {
|
|
337
|
-
const files = await getFiles(db, workspaceId, unknownIds);
|
|
338
|
-
for (const file of files) fileById.set(file.id, file);
|
|
339
|
-
for (const id of unknownIds) {
|
|
340
|
-
if (!fileById.has(id)) missingFileIds.add(id);
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
332
|
if (readFileBytes) {
|
|
345
|
-
//
|
|
346
|
-
//
|
|
333
|
+
// Only the triggering message's attachments cross the provider byte
|
|
334
|
+
// boundary. Historical messages retain compact durable receipts and can
|
|
335
|
+
// recover bytes explicitly through the existing Files MCP + shell path.
|
|
347
336
|
const readable = [...orderedFileIds]
|
|
348
337
|
.reverse()
|
|
349
|
-
.map((id) =>
|
|
338
|
+
.map((id) => currentFileById.get(id))
|
|
350
339
|
.filter((file): file is FileAsset => {
|
|
351
340
|
if (!file || attemptedContentIds.has(file.id)) return false;
|
|
352
341
|
const descriptor = modelAttachmentDescriptor(file.contentType);
|
|
353
|
-
return Boolean(
|
|
354
|
-
descriptor &&
|
|
355
|
-
((descriptor.kind === "image" && policy.supportsImageInput) ||
|
|
356
|
-
(descriptor.kind === "file" && modelAcceptsFileMediaType(policy, file.contentType))),
|
|
357
|
-
);
|
|
342
|
+
return Boolean(descriptor && descriptor.kind === "image" && policy.supportsImageInput);
|
|
358
343
|
});
|
|
359
344
|
for (const file of readable) attemptedContentIds.add(file.id);
|
|
360
345
|
const content = await modelAttachmentContentForFiles(readable, readFileBytes);
|
|
@@ -367,21 +352,17 @@ export function createModelHistoryAttachmentProjector(
|
|
|
367
352
|
const existingContent = Array.isArray(original.content)
|
|
368
353
|
? [...original.content]
|
|
369
354
|
: [{ type: "input_text", text: String(original.content ?? "") }];
|
|
370
|
-
const attachmentParts = refs.
|
|
371
|
-
const
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
355
|
+
const attachmentParts = refs.flatMap((ref) => {
|
|
356
|
+
const currentFile = currentFileById.get(ref.fileId);
|
|
357
|
+
const attachment = currentFile ? contentById.get(ref.fileId) : undefined;
|
|
358
|
+
const receipt = {
|
|
359
|
+
type: "input_text",
|
|
360
|
+
text: attachmentReceiptText(ref, currentFile),
|
|
361
|
+
};
|
|
362
|
+
if (!attachment || attachment.kind !== "image") {
|
|
363
|
+
return [receipt];
|
|
377
364
|
}
|
|
378
|
-
return
|
|
379
|
-
? { type: "input_image", image: attachment.dataUrl }
|
|
380
|
-
: {
|
|
381
|
-
type: "input_file",
|
|
382
|
-
file: attachment.dataUrl,
|
|
383
|
-
filename: attachment.filename,
|
|
384
|
-
};
|
|
365
|
+
return [receipt, { type: "input_image", image: attachment.dataUrl }];
|
|
385
366
|
});
|
|
386
367
|
const clone: Record<string, unknown> = {
|
|
387
368
|
...original,
|
|
@@ -452,6 +433,7 @@ export async function turnInput(
|
|
|
452
433
|
: undefined,
|
|
453
434
|
options.unavailableSandboxFilesNote,
|
|
454
435
|
options.runCredentialsNote,
|
|
436
|
+
options.mcpAvailabilityNote,
|
|
455
437
|
);
|
|
456
438
|
if (trigger.type === "user.message") {
|
|
457
439
|
const payload = trigger.payload as {
|
|
@@ -467,7 +449,14 @@ export async function turnInput(
|
|
|
467
449
|
const fileAttachments = await measureHistoryPreparationPhase(
|
|
468
450
|
options,
|
|
469
451
|
"current_attachment_resolution",
|
|
470
|
-
async () =>
|
|
452
|
+
async () =>
|
|
453
|
+
await resolveUserMessageFileAttachments(
|
|
454
|
+
db,
|
|
455
|
+
options.fileAuthority.accountId,
|
|
456
|
+
trigger.workspaceId,
|
|
457
|
+
options.fileAuthority.subjectId,
|
|
458
|
+
resources,
|
|
459
|
+
),
|
|
471
460
|
);
|
|
472
461
|
const attachmentContext = userMessageAttachmentsContext(fileAttachments);
|
|
473
462
|
return await messageInput(
|
|
@@ -477,7 +466,7 @@ export async function turnInput(
|
|
|
477
466
|
trigger,
|
|
478
467
|
undefined,
|
|
479
468
|
joinInternalContext(internalContext, attachmentContext),
|
|
480
|
-
fileAttachments
|
|
469
|
+
fileAttachments,
|
|
481
470
|
options.providerApi,
|
|
482
471
|
options.projectCanonicalHistory,
|
|
483
472
|
options.materializeModelHistory,
|
|
@@ -506,66 +495,8 @@ export async function turnInput(
|
|
|
506
495
|
options,
|
|
507
496
|
);
|
|
508
497
|
}
|
|
509
|
-
if (trigger.type === "user.approvalDecision") {
|
|
510
|
-
|
|
511
|
-
approvalId?: unknown;
|
|
512
|
-
decision?: unknown;
|
|
513
|
-
message?: unknown;
|
|
514
|
-
};
|
|
515
|
-
// Approvals are the one path that legitimately requires the RunState blob:
|
|
516
|
-
// a turn frozen mid-flight cannot be represented as plain history items.
|
|
517
|
-
const state = await getLatestRunState(db, trigger.workspaceId, trigger.sessionId);
|
|
518
|
-
if (!state) {
|
|
519
|
-
throw new Error("No saved run state is available for approval decision");
|
|
520
|
-
}
|
|
521
|
-
const serializedRunState = resumeRunState(state);
|
|
522
|
-
const prepared = await runtime.prepareInput(agent, {
|
|
523
|
-
kind: "approval",
|
|
524
|
-
serializedRunState: options.materializeSerializedRunState
|
|
525
|
-
? await options.materializeSerializedRunState(serializedRunState)
|
|
526
|
-
: serializedRunState,
|
|
527
|
-
approvalId: String(payload.approvalId ?? ""),
|
|
528
|
-
decision: payload.decision === "approve" ? "approve" : "reject",
|
|
529
|
-
...(typeof payload.message === "string" ? { message: payload.message } : {}),
|
|
530
|
-
});
|
|
531
|
-
return {
|
|
532
|
-
input: prepared,
|
|
533
|
-
persistedHistoryCount: prepared.persistedHistoryCount,
|
|
534
|
-
providerArtifactCandidates: {
|
|
535
|
-
knownHistoryItemIds: [],
|
|
536
|
-
historyItemIds: [],
|
|
537
|
-
runStateId: state.id,
|
|
538
|
-
},
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
if (trigger.type === "user.humanInputResponse") {
|
|
542
|
-
const [state, resume] = await Promise.all([
|
|
543
|
-
getLatestRunState(db, trigger.workspaceId, trigger.sessionId),
|
|
544
|
-
getHumanInputResumeForEvent(db, trigger.workspaceId, trigger.sessionId, trigger),
|
|
545
|
-
]);
|
|
546
|
-
if (!state) {
|
|
547
|
-
throw new Error("No saved run state is available for human-input response");
|
|
548
|
-
}
|
|
549
|
-
if (!resume) {
|
|
550
|
-
throw new Error("Human-input response does not resolve to a durable request");
|
|
551
|
-
}
|
|
552
|
-
const serializedRunState = resumeRunState(state);
|
|
553
|
-
const prepared = await runtime.prepareInput(agent, {
|
|
554
|
-
kind: "human_input",
|
|
555
|
-
serializedRunState: options.materializeSerializedRunState
|
|
556
|
-
? await options.materializeSerializedRunState(serializedRunState)
|
|
557
|
-
: serializedRunState,
|
|
558
|
-
toolCallId: resume.toolCallId,
|
|
559
|
-
});
|
|
560
|
-
return {
|
|
561
|
-
input: prepared,
|
|
562
|
-
persistedHistoryCount: prepared.persistedHistoryCount,
|
|
563
|
-
providerArtifactCandidates: {
|
|
564
|
-
knownHistoryItemIds: [],
|
|
565
|
-
historyItemIds: [],
|
|
566
|
-
runStateId: state.id,
|
|
567
|
-
},
|
|
568
|
-
};
|
|
498
|
+
if (trigger.type === "user.approvalDecision" || trigger.type === "user.humanInputResponse") {
|
|
499
|
+
return await openSuffixMessageInput(db, runtime, agent, trigger, internalContext, options);
|
|
569
500
|
}
|
|
570
501
|
throw new Error(`Unsupported trigger event type: ${trigger.type}`);
|
|
571
502
|
}
|
|
@@ -575,6 +506,43 @@ function joinInternalContext(...parts: Array<string | undefined>): string | unde
|
|
|
575
506
|
return content.length > 0 ? content.join("\n\n") : undefined;
|
|
576
507
|
}
|
|
577
508
|
|
|
509
|
+
async function openSuffixMessageInput(
|
|
510
|
+
db: Database,
|
|
511
|
+
runtime: OpenGeniRuntime,
|
|
512
|
+
agent: any,
|
|
513
|
+
trigger: NonNullable<Awaited<ReturnType<typeof getSessionEvent>>>,
|
|
514
|
+
internalContext: string | undefined,
|
|
515
|
+
options: TurnInputOptions,
|
|
516
|
+
): Promise<PreparedTurnInput> {
|
|
517
|
+
const suffixRows = await listTurnOpenSuffixToolCalls(
|
|
518
|
+
db,
|
|
519
|
+
trigger.workspaceId,
|
|
520
|
+
trigger.sessionId,
|
|
521
|
+
options.turnId,
|
|
522
|
+
);
|
|
523
|
+
if (suffixRows.length === 0) {
|
|
524
|
+
throw new Error("Open suffix resume has no interruption rows");
|
|
525
|
+
}
|
|
526
|
+
if (suffixRows.some((row) => row.resultItem == null)) {
|
|
527
|
+
throw new Error("Open suffix resume still has unresolved members");
|
|
528
|
+
}
|
|
529
|
+
return await messageInput(
|
|
530
|
+
db,
|
|
531
|
+
runtime,
|
|
532
|
+
agent,
|
|
533
|
+
trigger,
|
|
534
|
+
undefined,
|
|
535
|
+
internalContext,
|
|
536
|
+
[],
|
|
537
|
+
options.providerApi,
|
|
538
|
+
options.projectCanonicalHistory,
|
|
539
|
+
options.materializeModelHistory,
|
|
540
|
+
options.projectModelHistory,
|
|
541
|
+
options.loadActiveHistory,
|
|
542
|
+
options,
|
|
543
|
+
);
|
|
544
|
+
}
|
|
545
|
+
|
|
578
546
|
/** Build one inference from canonical history plus attempt-local operational context. */
|
|
579
547
|
async function messageInput(
|
|
580
548
|
db: Database,
|
|
@@ -583,7 +551,7 @@ async function messageInput(
|
|
|
583
551
|
trigger: NonNullable<Awaited<ReturnType<typeof getSessionEvent>>>,
|
|
584
552
|
text: string | undefined,
|
|
585
553
|
internalContext: string | undefined,
|
|
586
|
-
|
|
554
|
+
currentAttachments: UserMessageFileAttachment[] = [],
|
|
587
555
|
providerApi: HistoryProviderApi = "responses",
|
|
588
556
|
projectCanonicalHistory?: ModelHistoryAttachmentProjector,
|
|
589
557
|
materializeModelHistory?: ModelHistoryAttachmentProjector,
|
|
@@ -591,6 +559,7 @@ async function messageInput(
|
|
|
591
559
|
loadActiveHistory: typeof getActiveSessionHistoryItemsPaged = getActiveSessionHistoryItemsPaged,
|
|
592
560
|
preparationOptions: Pick<TurnInputOptions, "onPreparationPhase"> = {},
|
|
593
561
|
): Promise<PreparedTurnInput> {
|
|
562
|
+
const currentAttachmentRefs = currentAttachments.map((attachment) => attachment.resource);
|
|
594
563
|
const [stored, envelope] = await Promise.all([
|
|
595
564
|
measureHistoryPreparationPhase(preparationOptions, "durable_history_load", async () =>
|
|
596
565
|
loadActiveHistory(db, trigger.workspaceId, trigger.sessionId),
|
|
@@ -629,7 +598,11 @@ async function messageInput(
|
|
|
629
598
|
preparationOptions,
|
|
630
599
|
"model_attachment_projection",
|
|
631
600
|
async () =>
|
|
632
|
-
projectModelHistory
|
|
601
|
+
projectModelHistory
|
|
602
|
+
? await projectModelHistory(materializedHistory, {
|
|
603
|
+
inlineFiles: currentAttachments.map((attachment) => attachment.file),
|
|
604
|
+
})
|
|
605
|
+
: materializedHistory,
|
|
633
606
|
);
|
|
634
607
|
const prepared = await measureHistoryPreparationPhase(
|
|
635
608
|
preparationOptions,
|
|
@@ -673,11 +646,19 @@ async function messageInput(
|
|
|
673
646
|
|
|
674
647
|
export async function userMessageTextWithAttachments(
|
|
675
648
|
db: Database,
|
|
649
|
+
accountId: string,
|
|
676
650
|
workspaceId: string,
|
|
651
|
+
subjectId: string | null,
|
|
677
652
|
text: string,
|
|
678
653
|
resources: ResourceRef[],
|
|
679
654
|
): Promise<string> {
|
|
680
|
-
const fileAttachments = await resolveUserMessageFileAttachments(
|
|
655
|
+
const fileAttachments = await resolveUserMessageFileAttachments(
|
|
656
|
+
db,
|
|
657
|
+
accountId,
|
|
658
|
+
workspaceId,
|
|
659
|
+
subjectId,
|
|
660
|
+
resources,
|
|
661
|
+
);
|
|
681
662
|
const attachmentContext = userMessageAttachmentsContext(fileAttachments);
|
|
682
663
|
return attachmentContext ? [text, "", attachmentContext].join("\n") : text;
|
|
683
664
|
}
|
|
@@ -689,16 +670,27 @@ type UserMessageFileAttachment = {
|
|
|
689
670
|
|
|
690
671
|
async function resolveUserMessageFileAttachments(
|
|
691
672
|
db: Database,
|
|
673
|
+
accountId: string,
|
|
692
674
|
workspaceId: string,
|
|
675
|
+
subjectId: string | null,
|
|
693
676
|
resources: ResourceRef[],
|
|
694
677
|
): Promise<UserMessageFileAttachment[]> {
|
|
695
|
-
const
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
678
|
+
const fileResources = resources.filter(
|
|
679
|
+
(resource): resource is FileResourceRef => resource.kind === "file",
|
|
680
|
+
);
|
|
681
|
+
if (fileResources.length === 0) return [];
|
|
682
|
+
const files = await getFilesForSubject(db, {
|
|
683
|
+
accountId,
|
|
684
|
+
workspaceId,
|
|
685
|
+
subjectId,
|
|
686
|
+
fileIds: fileResources.map((resource) => resource.fileId),
|
|
687
|
+
});
|
|
688
|
+
const fileById = new Map(files.map((file) => [file.id, file]));
|
|
689
|
+
return fileResources.map((resource) => {
|
|
690
|
+
const file = fileById.get(resource.fileId);
|
|
691
|
+
if (!file) throw new Error(`File not found: ${resource.fileId}`);
|
|
692
|
+
return { resource, file };
|
|
693
|
+
});
|
|
702
694
|
}
|
|
703
695
|
|
|
704
696
|
function userMessageAttachmentsContext(
|
|
@@ -718,5 +710,5 @@ function sandboxFilePath(
|
|
|
718
710
|
resource: Extract<ResourceRef, { kind: "file" }>,
|
|
719
711
|
file: FileAsset,
|
|
720
712
|
): string {
|
|
721
|
-
return
|
|
713
|
+
return `${resourceMountPath(resource)}/${file.safeFilename}`;
|
|
722
714
|
}
|
|
@@ -1,167 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export {
|
|
2
|
+
resolveRigProviderImageSelection,
|
|
3
|
+
rigProviderImageSourceImage,
|
|
4
|
+
settingsWithPackSandboxImage,
|
|
5
|
+
settingsWithRigImage,
|
|
6
|
+
settingsWithRigProviderImage,
|
|
7
|
+
type RigProviderImageSelectionReason,
|
|
7
8
|
} from "@opengeni/core";
|
|
8
|
-
import { resolveModalCheckpointProviderBinding } from "@opengeni/runtime/sandbox";
|
|
9
|
-
|
|
10
|
-
export function settingsWithPackSandboxImage(
|
|
11
|
-
settings: Settings,
|
|
12
|
-
sandboxImage: string | null,
|
|
13
|
-
sandboxProviderImages: CapabilityPack["sandboxProviderImages"] | null = null,
|
|
14
|
-
): Settings {
|
|
15
|
-
if (!sandboxImage) return settings;
|
|
16
|
-
return {
|
|
17
|
-
...settings,
|
|
18
|
-
dockerImage: sandboxImage,
|
|
19
|
-
modalImageRef: sandboxImage,
|
|
20
|
-
modalImageId: sandboxProviderImages?.modal?.imageId,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function settingsWithRigImage(settings: Settings, rigImage: string | null): Settings {
|
|
25
|
-
if (!rigImage) return settings;
|
|
26
|
-
return {
|
|
27
|
-
...settings,
|
|
28
|
-
dockerImage: rigImage,
|
|
29
|
-
modalImageRef: rigImage,
|
|
30
|
-
// A logical rig image invalidates a lower-precedence pack/deployment
|
|
31
|
-
// provider ID. A verified version-bound provider ID is applied separately
|
|
32
|
-
// after this precedence step.
|
|
33
|
-
modalImageId: undefined,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function rigProviderImageSourceImage(
|
|
38
|
-
settings: Settings,
|
|
39
|
-
backend: SandboxBackend,
|
|
40
|
-
): string | null {
|
|
41
|
-
if (backend === "modal") return settings.modalImageId ?? settings.modalImageRef ?? null;
|
|
42
|
-
if (backend === "docker") return settings.dockerImage ?? null;
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export type RigProviderImageSelectionReason =
|
|
47
|
-
| "selected"
|
|
48
|
-
| "missing"
|
|
49
|
-
| "provider_unsupported"
|
|
50
|
-
| "not_ready"
|
|
51
|
-
| "not_cold_boot_validated"
|
|
52
|
-
| "content_mismatch"
|
|
53
|
-
| "provider_binding_unavailable"
|
|
54
|
-
| "provider_binding_mismatch";
|
|
55
|
-
|
|
56
|
-
export function resolveRigProviderImageSelection(
|
|
57
|
-
settings: Settings,
|
|
58
|
-
version: RigVersion | null,
|
|
59
|
-
backend: SandboxBackend,
|
|
60
|
-
currentProviderBindingKeyHash: string | null,
|
|
61
|
-
): {
|
|
62
|
-
settings: Settings;
|
|
63
|
-
reason: RigProviderImageSelectionReason;
|
|
64
|
-
contentHash: string | null;
|
|
65
|
-
imageId: string | null;
|
|
66
|
-
} {
|
|
67
|
-
if (!version) {
|
|
68
|
-
return { settings, reason: "missing", contentHash: null, imageId: null };
|
|
69
|
-
}
|
|
70
|
-
if (backend !== "modal") {
|
|
71
|
-
return { settings, reason: "provider_unsupported", contentHash: null, imageId: null };
|
|
72
|
-
}
|
|
73
|
-
const image = version.providerImages[backend];
|
|
74
|
-
if (!image) {
|
|
75
|
-
return { settings, reason: "missing", contentHash: null, imageId: null };
|
|
76
|
-
}
|
|
77
|
-
if (image.status !== "ready" || !image.imageId) {
|
|
78
|
-
return {
|
|
79
|
-
settings,
|
|
80
|
-
reason: "not_ready",
|
|
81
|
-
contentHash: image.contentHash,
|
|
82
|
-
imageId: image.imageId,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
if (image.coldBootValidation?.version !== 1) {
|
|
86
|
-
return {
|
|
87
|
-
settings,
|
|
88
|
-
reason: "not_cold_boot_validated",
|
|
89
|
-
contentHash: image.contentHash,
|
|
90
|
-
imageId: null,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
const sourceImage = rigProviderImageSourceImage(settings, backend);
|
|
94
|
-
const expectedContentHash = rigProviderImageContentHash({
|
|
95
|
-
backend,
|
|
96
|
-
sourceImage,
|
|
97
|
-
definition: version,
|
|
98
|
-
});
|
|
99
|
-
if (
|
|
100
|
-
image.sourceImage !== sourceImage ||
|
|
101
|
-
image.contentHash !== expectedContentHash ||
|
|
102
|
-
!rigProviderImageMatchesDefinition(image, version)
|
|
103
|
-
) {
|
|
104
|
-
return {
|
|
105
|
-
settings,
|
|
106
|
-
reason: "content_mismatch",
|
|
107
|
-
contentHash: expectedContentHash,
|
|
108
|
-
imageId: null,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
if (!image.providerBindingKeyHash || !currentProviderBindingKeyHash) {
|
|
112
|
-
return {
|
|
113
|
-
settings,
|
|
114
|
-
reason: "provider_binding_unavailable",
|
|
115
|
-
contentHash: expectedContentHash,
|
|
116
|
-
imageId: null,
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
if (image.providerBindingKeyHash !== currentProviderBindingKeyHash) {
|
|
120
|
-
return {
|
|
121
|
-
settings,
|
|
122
|
-
reason: "provider_binding_mismatch",
|
|
123
|
-
contentHash: expectedContentHash,
|
|
124
|
-
imageId: null,
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
return {
|
|
128
|
-
// Keep modalImageRef unchanged: the lease continues to fence the logical
|
|
129
|
-
// rig/pack/deployment image, so a newly available build optimization never
|
|
130
|
-
// rotates an already-warm or archive-backed box. modalImageId affects only
|
|
131
|
-
// genuinely fresh provider creation.
|
|
132
|
-
settings: { ...settings, modalImageId: image.imageId },
|
|
133
|
-
reason: "selected",
|
|
134
|
-
contentHash: expectedContentHash,
|
|
135
|
-
imageId: image.imageId,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export async function settingsWithRigProviderImage(
|
|
140
|
-
settings: Settings,
|
|
141
|
-
version: RigVersion | null,
|
|
142
|
-
backend: SandboxBackend,
|
|
143
|
-
resolveBinding: typeof resolveModalCheckpointProviderBinding = resolveModalCheckpointProviderBinding,
|
|
144
|
-
): Promise<Settings> {
|
|
145
|
-
const image = backend === "modal" ? version?.providerImages.modal : null;
|
|
146
|
-
if (image?.status !== "ready" || !image.providerBindingKeyHash) {
|
|
147
|
-
return resolveRigProviderImageSelection(settings, version, backend, null).settings;
|
|
148
|
-
}
|
|
149
|
-
const structural = resolveRigProviderImageSelection(
|
|
150
|
-
settings,
|
|
151
|
-
version,
|
|
152
|
-
backend,
|
|
153
|
-
image.providerBindingKeyHash,
|
|
154
|
-
);
|
|
155
|
-
if (structural.reason !== "selected") return structural.settings;
|
|
156
|
-
let currentProviderBindingKeyHash: string | null = null;
|
|
157
|
-
try {
|
|
158
|
-
const binding = await resolveBinding(settings);
|
|
159
|
-
currentProviderBindingKeyHash = rigProviderImageProviderBindingKeyHash(binding.key);
|
|
160
|
-
} catch {
|
|
161
|
-
// Provider identity is an authority check, not a reason to fail the turn.
|
|
162
|
-
// Preserve the logical image so fresh creation and runtime setup remain the
|
|
163
|
-
// truthful fallback when the identity lookup is unavailable.
|
|
164
|
-
}
|
|
165
|
-
return resolveRigProviderImageSelection(settings, version, backend, currentProviderBindingKeyHash)
|
|
166
|
-
.settings;
|
|
167
|
-
}
|