@opengeni/worker-bundle 0.16.21 → 0.17.2
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 +145 -32
- package/dist/activities/api-integrations.d.ts +21 -0
- package/dist/activities/codemode-dispatcher.d.ts +35 -0
- package/dist/activities/codemode-token-renewal.d.ts +23 -0
- package/dist/activities/codex-capacity.d.ts +5 -5
- package/dist/activities/codex-image-generation.d.ts +21 -0
- package/dist/activities/context-compaction.d.ts +3 -0
- package/dist/activities/documents.d.ts +3 -2
- package/dist/activities/environment.d.ts +11 -7
- package/dist/activities/expiring-material-renewal.d.ts +5 -3
- package/dist/activities/file-upload-reaper.d.ts +7 -2
- package/dist/activities/gateway-image-generation.d.ts +39 -0
- package/dist/activities/gateway-video-generation.d.ts +53 -0
- package/dist/activities/generated-images.d.ts +112 -0
- package/dist/activities/git-credential-renewal.d.ts +2 -2
- package/dist/activities/goals.d.ts +2 -2
- package/dist/activities/google-drive-changes.d.ts +99 -0
- package/dist/activities/image-generation-operation.d.ts +74 -0
- package/dist/activities/image-generation-references.d.ts +25 -0
- package/dist/activities/knowledge-source-sync-driver.d.ts +23 -0
- package/dist/activities/knowledge-source-sync.d.ts +75 -0
- package/dist/activities/packs.d.ts +13 -26
- package/dist/activities/parent-wake.d.ts +1 -1
- package/dist/activities/retained-screenshot-reaper.d.ts +32 -0
- package/dist/activities/retained-screenshots.d.ts +129 -0
- package/dist/activities/rig-verification.d.ts +82 -5
- package/dist/activities/run-credential-renewal.d.ts +2 -2
- package/dist/activities/run-input.d.ts +5 -1
- package/dist/activities/sandbox-images.d.ts +14 -0
- package/dist/activities/sandbox-lease.d.ts +47 -9
- package/dist/activities/scheduled-tasks.d.ts +2 -2
- package/dist/activities/session-state.d.ts +4 -4
- package/dist/activities/streaming.d.ts +1 -1
- package/dist/activities/types.d.ts +71 -5
- package/dist/activities/video-generation-admission.d.ts +38 -0
- package/dist/activities/video-generation-credential.d.ts +7 -0
- package/dist/activities/video-generation-reconciliation.d.ts +13 -0
- package/dist/activities/video-media-validation.d.ts +34 -0
- package/dist/activities/video-output-retention.d.ts +36 -0
- package/dist/activities/video-reference-staging.d.ts +49 -0
- package/dist/activities/workflow-wake.d.ts +2 -2
- package/dist/activities/workspace-capture.d.ts +11 -1
- package/dist/activities-control-44KBWLSM.js +6885 -0
- package/dist/activities-control-44KBWLSM.js.map +1 -0
- package/dist/activities-control.d.ts +289 -0
- package/dist/activities-turn-K4CEDEGJ.js +14675 -0
- package/dist/activities-turn-K4CEDEGJ.js.map +1 -0
- package/dist/activities-turn.d.ts +17 -0
- package/dist/activities.d.ts +130 -147
- package/dist/activity-services.d.ts +10 -0
- package/dist/artifact-materializer-entry.d.ts +6 -0
- package/dist/artifact-materializer-entry.js +2662 -0
- package/dist/artifact-materializer-entry.js.map +1 -0
- package/dist/artifact-outbox-entry.d.ts +2 -0
- package/dist/artifact-outbox-entry.js +681 -0
- package/dist/artifact-outbox-entry.js.map +1 -0
- package/dist/chunk-E3RI3I33.js +828 -0
- package/dist/chunk-E3RI3I33.js.map +1 -0
- package/dist/chunk-GRFQTTSQ.js +448 -0
- package/dist/chunk-GRFQTTSQ.js.map +1 -0
- package/dist/chunk-KKCRGAGZ.js +3091 -0
- package/dist/chunk-KKCRGAGZ.js.map +1 -0
- package/dist/{chunk-BJUW5LCM.js → chunk-RAMNYSAW.js} +15 -12
- package/dist/chunk-RAMNYSAW.js.map +1 -0
- package/dist/concurrency.d.ts +108 -5
- package/dist/editable-artifact-hint-broker.d.ts +49 -0
- package/dist/editable-artifact-materializer-launcher.d.ts +49 -0
- package/dist/editable-artifact-materializer-service.d.ts +108 -0
- package/dist/editable-artifact-materializer-storage.d.ts +12 -0
- package/dist/editable-artifact-materializer-subprocess.d.ts +50 -0
- package/dist/editable-artifact-materializer.d.ts +262 -0
- package/dist/editable-artifact-outbox-dispatcher.d.ts +44 -0
- package/dist/editable-artifact-outbox-service.d.ts +70 -0
- package/dist/host-export.d.ts +1 -1
- package/dist/host-export.js +1 -1
- package/dist/index.d.ts +176 -10
- package/dist/index.js +675 -16460
- package/dist/index.js.map +1 -1
- package/dist/memory-pressure-guard.d.ts +57 -0
- package/dist/model-checkpoint-memory-collector.d.ts +22 -0
- package/dist/observability-metrics.d.ts +33 -0
- package/dist/sandbox-reaper-contract.d.ts +40 -0
- package/dist/sandbox-reaper-timeout.d.ts +14 -0
- package/dist/sandbox-resume.d.ts +40 -7
- package/dist/sandbox-routing.d.ts +13 -6
- package/dist/worker-service-lifecycle.d.ts +6 -2
- package/dist/workflow-bundle.js +1044 -363
- package/dist/workflows/activities.d.ts +7 -1
- package/dist/workflows/document-index.d.ts +1 -1
- package/dist/workflows/knowledge-source-sync.d.ts +13 -0
- package/dist/workflows/rig-verification.d.ts +1 -1
- package/dist/workflows/sandbox-reaper.d.ts +8 -0
- package/dist/workflows/scheduled-tasks.d.ts +1 -1
- package/dist/workflows/session.d.ts +2 -2
- package/dist/workflows/video-generation.d.ts +10 -0
- package/dist/workflows/workflow-wake.d.ts +1 -1
- package/dist/workflows.d.ts +9 -7
- package/package.json +34 -15
- package/src/activities/agent-turn.ts +1905 -559
- package/src/activities/api-integrations.ts +138 -0
- package/src/activities/codemode-dispatcher.ts +335 -0
- package/src/activities/codemode-token-renewal.ts +64 -0
- package/src/activities/codex-capacity.ts +16 -7
- package/src/activities/codex-image-generation.ts +56 -0
- package/src/activities/codex-rotation.ts +19 -5
- package/src/activities/context-compaction.ts +47 -6
- package/src/activities/documents.ts +14 -4
- package/src/activities/environment.ts +52 -60
- package/src/activities/expiring-material-renewal.ts +16 -7
- package/src/activities/file-upload-reaper.ts +34 -3
- package/src/activities/gateway-image-generation.ts +146 -0
- package/src/activities/gateway-video-generation.ts +298 -0
- package/src/activities/generated-images.ts +860 -0
- package/src/activities/git-credential-renewal.ts +3 -3
- package/src/activities/goals.ts +6 -2
- package/src/activities/google-drive-changes.ts +454 -0
- package/src/activities/image-generation-operation.ts +333 -0
- package/src/activities/image-generation-references.ts +118 -0
- package/src/activities/knowledge-source-sync-driver.ts +27 -0
- package/src/activities/knowledge-source-sync.ts +2840 -0
- package/src/activities/mcp-credentials.ts +1 -0
- package/src/activities/packs.ts +55 -55
- package/src/activities/recording.ts +4 -5
- package/src/activities/retained-screenshot-reaper.ts +202 -0
- package/src/activities/retained-screenshots.ts +1317 -0
- package/src/activities/rig-verification.ts +567 -77
- package/src/activities/run-credential-renewal.ts +9 -2
- package/src/activities/run-input.ts +40 -10
- package/src/activities/sandbox-images.ts +167 -0
- package/src/activities/sandbox-lease.ts +1065 -483
- package/src/activities/scheduled-tasks.ts +96 -7
- package/src/activities/session-state.ts +4 -4
- package/src/activities/streaming.ts +42 -3
- package/src/activities/types.ts +87 -5
- package/src/activities/video-generation-admission.ts +270 -0
- package/src/activities/video-generation-credential.ts +34 -0
- package/src/activities/video-generation-reconciliation.ts +578 -0
- package/src/activities/video-media-validation.ts +326 -0
- package/src/activities/video-output-retention.ts +314 -0
- package/src/activities/video-reference-staging.ts +263 -0
- package/src/activities/workflow-wake.ts +2 -2
- package/src/activities/workspace-capture.ts +77 -13
- package/src/activities-control.ts +54 -0
- package/src/activities-turn.ts +40 -0
- package/src/activities.ts +50 -118
- package/src/activity-services.ts +62 -0
- package/src/artifact-materializer-entry.ts +35 -0
- package/src/artifact-outbox-entry.ts +29 -0
- package/src/concurrency.ts +484 -6
- package/src/editable-artifact-hint-broker.ts +235 -0
- package/src/editable-artifact-materializer-launcher.ts +515 -0
- package/src/editable-artifact-materializer-service.ts +787 -0
- package/src/editable-artifact-materializer-storage.ts +413 -0
- package/src/editable-artifact-materializer-subprocess.ts +956 -0
- package/src/editable-artifact-materializer.ts +1289 -0
- package/src/editable-artifact-outbox-dispatcher.ts +244 -0
- package/src/editable-artifact-outbox-service.ts +438 -0
- package/src/host-export-pump.ts +28 -11
- package/src/http.ts +3 -6
- package/src/index.ts +277 -72
- package/src/memory-pressure-guard.ts +489 -0
- package/src/model-checkpoint-memory-collector.ts +116 -0
- package/src/observability-metrics.ts +202 -7
- package/src/sandbox-reaper-contract.ts +73 -0
- package/src/sandbox-reaper-timeout.ts +79 -0
- package/src/sandbox-resume.ts +331 -157
- package/src/sandbox-routing.ts +49 -39
- package/src/worker-service-lifecycle.ts +82 -12
- package/src/workflows/activities.ts +30 -0
- package/src/workflows/file-upload-reaper.ts +6 -1
- package/src/workflows/knowledge-source-sync.ts +83 -0
- package/src/workflows/sandbox-reaper.ts +183 -21
- package/src/workflows/scheduled-tasks.ts +42 -6
- package/src/workflows/video-generation.ts +36 -0
- package/src/workflows.ts +17 -1
- package/dist/activities/redaction.d.ts +0 -1
- package/dist/activities/toolspace-token-renewal.d.ts +0 -23
- package/dist/chunk-BJUW5LCM.js.map +0 -1
- package/src/activities/redaction.ts +0 -9
- package/src/activities/toolspace-token-renewal.ts +0 -57
|
@@ -22,7 +22,10 @@ export type RunCredentialRenewalOptions = {
|
|
|
22
22
|
schedule?: (callback: () => void, delayMs: number) => RenewalTimer;
|
|
23
23
|
clearSchedule?: (timer: RenewalTimer) => void;
|
|
24
24
|
onSuccess?: (result: { nextDelayMs: number; authNeeded: boolean }) => void;
|
|
25
|
-
onFailure?: (failure: {
|
|
25
|
+
onFailure?: (failure: {
|
|
26
|
+
retryDelayMs: number;
|
|
27
|
+
errorClass: "RunCredentialRenewalOperationError";
|
|
28
|
+
}) => void;
|
|
26
29
|
};
|
|
27
30
|
|
|
28
31
|
export function nextRunCredentialRenewalDelay(expiresAt: Date | null, nowMs = Date.now()): number {
|
|
@@ -42,11 +45,15 @@ export function nextRunCredentialRenewalDelay(expiresAt: Date | null, nowMs = Da
|
|
|
42
45
|
export function startRunCredentialRenewalLoop(
|
|
43
46
|
options: RunCredentialRenewalOptions,
|
|
44
47
|
): RunCredentialRenewalController {
|
|
45
|
-
return startExpiringMaterialRenewalLoop<
|
|
48
|
+
return startExpiringMaterialRenewalLoop<
|
|
49
|
+
NormalizedRunCredentialMaterial | null,
|
|
50
|
+
"RunCredentialRenewalOperationError"
|
|
51
|
+
>({
|
|
46
52
|
initialExpiresAt: options.initialExpiresAt,
|
|
47
53
|
resolve: options.resolve,
|
|
48
54
|
write: options.write,
|
|
49
55
|
expiresAt: (material) => material?.expiresAt ?? null,
|
|
56
|
+
publicErrorClass: "RunCredentialRenewalOperationError",
|
|
50
57
|
policy: {
|
|
51
58
|
defaultRefreshMs: RUN_CREDENTIAL_DEFAULT_REFRESH_MS,
|
|
52
59
|
expiryLeadMs: RUN_CREDENTIAL_EXPIRY_LEAD_MS,
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "@opengeni/contracts";
|
|
8
8
|
import { createHash } from "node:crypto";
|
|
9
9
|
import {
|
|
10
|
-
|
|
10
|
+
getActiveSessionHistoryItemsPaged,
|
|
11
11
|
getFiles,
|
|
12
12
|
getLatestRunState,
|
|
13
13
|
getHumanInputResumeForEvent,
|
|
@@ -80,7 +80,11 @@ export type TurnInputOptions = {
|
|
|
80
80
|
unavailableSandboxFilesNote?: string;
|
|
81
81
|
runCredentialsNote?: string;
|
|
82
82
|
providerApi: HistoryProviderApi;
|
|
83
|
+
projectCanonicalHistory?: ModelHistoryAttachmentProjector;
|
|
84
|
+
materializeModelHistory?: ModelHistoryAttachmentProjector;
|
|
85
|
+
materializeSerializedRunState?: (serialized: string) => Promise<string>;
|
|
83
86
|
projectModelHistory?: ModelHistoryAttachmentProjector;
|
|
87
|
+
loadActiveHistory?: typeof getActiveSessionHistoryItemsPaged;
|
|
84
88
|
};
|
|
85
89
|
|
|
86
90
|
export const MAX_INLINE_MODEL_ATTACHMENT_BYTES = 20 * 1024 * 1024;
|
|
@@ -399,9 +403,14 @@ export async function turnInput(
|
|
|
399
403
|
options.runCredentialsNote,
|
|
400
404
|
);
|
|
401
405
|
if (trigger.type === "user.message") {
|
|
402
|
-
const payload = trigger.payload as {
|
|
403
|
-
|
|
404
|
-
|
|
406
|
+
const payload = trigger.payload as {
|
|
407
|
+
text?: unknown;
|
|
408
|
+
annotations?: unknown;
|
|
409
|
+
resources?: unknown;
|
|
410
|
+
};
|
|
411
|
+
const hasAnnotations = Array.isArray(payload.annotations) && payload.annotations.length > 0;
|
|
412
|
+
if (typeof payload.text !== "string" || (payload.text.trim().length === 0 && !hasAnnotations)) {
|
|
413
|
+
throw new Error("user.message payload is missing text and annotations");
|
|
405
414
|
}
|
|
406
415
|
const resources = Array.isArray(payload.resources) ? (payload.resources as ResourceRef[]) : [];
|
|
407
416
|
const fileAttachments = await resolveUserMessageFileAttachments(
|
|
@@ -419,7 +428,10 @@ export async function turnInput(
|
|
|
419
428
|
joinInternalContext(internalContext, attachmentContext),
|
|
420
429
|
fileAttachments.map((attachment) => attachment.resource),
|
|
421
430
|
options.providerApi,
|
|
431
|
+
options.projectCanonicalHistory,
|
|
432
|
+
options.materializeModelHistory,
|
|
422
433
|
options.projectModelHistory,
|
|
434
|
+
options.loadActiveHistory,
|
|
423
435
|
);
|
|
424
436
|
}
|
|
425
437
|
if (trigger.type === "system.update.delivered") {
|
|
@@ -435,7 +447,10 @@ export async function turnInput(
|
|
|
435
447
|
internalContext,
|
|
436
448
|
[],
|
|
437
449
|
options.providerApi,
|
|
450
|
+
options.projectCanonicalHistory,
|
|
451
|
+
options.materializeModelHistory,
|
|
438
452
|
options.projectModelHistory,
|
|
453
|
+
options.loadActiveHistory,
|
|
439
454
|
);
|
|
440
455
|
}
|
|
441
456
|
if (trigger.type === "user.approvalDecision") {
|
|
@@ -450,9 +465,12 @@ export async function turnInput(
|
|
|
450
465
|
if (!state) {
|
|
451
466
|
throw new Error("No saved run state is available for approval decision");
|
|
452
467
|
}
|
|
468
|
+
const serializedRunState = resumeRunState(state);
|
|
453
469
|
const prepared = await runtime.prepareInput(agent, {
|
|
454
470
|
kind: "approval",
|
|
455
|
-
serializedRunState:
|
|
471
|
+
serializedRunState: options.materializeSerializedRunState
|
|
472
|
+
? await options.materializeSerializedRunState(serializedRunState)
|
|
473
|
+
: serializedRunState,
|
|
456
474
|
approvalId: String(payload.approvalId ?? ""),
|
|
457
475
|
decision: payload.decision === "approve" ? "approve" : "reject",
|
|
458
476
|
...(typeof payload.message === "string" ? { message: payload.message } : {}),
|
|
@@ -478,9 +496,12 @@ export async function turnInput(
|
|
|
478
496
|
if (!resume) {
|
|
479
497
|
throw new Error("Human-input response does not resolve to a durable request");
|
|
480
498
|
}
|
|
499
|
+
const serializedRunState = resumeRunState(state);
|
|
481
500
|
const prepared = await runtime.prepareInput(agent, {
|
|
482
501
|
kind: "human_input",
|
|
483
|
-
serializedRunState:
|
|
502
|
+
serializedRunState: options.materializeSerializedRunState
|
|
503
|
+
? await options.materializeSerializedRunState(serializedRunState)
|
|
504
|
+
: serializedRunState,
|
|
484
505
|
toolCallId: resume.toolCallId,
|
|
485
506
|
});
|
|
486
507
|
return {
|
|
@@ -511,16 +532,25 @@ async function messageInput(
|
|
|
511
532
|
internalContext: string | undefined,
|
|
512
533
|
currentAttachmentRefs: FileResourceRef[] = [],
|
|
513
534
|
providerApi: HistoryProviderApi = "responses",
|
|
535
|
+
projectCanonicalHistory?: ModelHistoryAttachmentProjector,
|
|
536
|
+
materializeModelHistory?: ModelHistoryAttachmentProjector,
|
|
514
537
|
projectModelHistory?: ModelHistoryAttachmentProjector,
|
|
538
|
+
loadActiveHistory: typeof getActiveSessionHistoryItemsPaged = getActiveSessionHistoryItemsPaged,
|
|
515
539
|
): Promise<PreparedTurnInput> {
|
|
516
|
-
const stored = await
|
|
540
|
+
const stored = await loadActiveHistory(db, trigger.workspaceId, trigger.sessionId);
|
|
517
541
|
const envelope = await getSandboxSessionEnvelope(db, trigger.workspaceId, trigger.sessionId);
|
|
518
542
|
const canonicalView = projectRejectedProviderArtifacts(stored);
|
|
519
|
-
const
|
|
543
|
+
const canonicalProviderView = projectCanonicalHistory
|
|
544
|
+
? await projectCanonicalHistory(canonicalView)
|
|
545
|
+
: canonicalView;
|
|
546
|
+
const providerView = projectHistoryForProvider(canonicalProviderView, providerApi);
|
|
520
547
|
const referencedHistory = withCurrentUserAttachmentRefs(providerView, currentAttachmentRefs);
|
|
521
|
-
const
|
|
522
|
-
? await
|
|
548
|
+
const materializedHistory = materializeModelHistory
|
|
549
|
+
? await materializeModelHistory(referencedHistory)
|
|
523
550
|
: referencedHistory;
|
|
551
|
+
const historyItems = projectModelHistory
|
|
552
|
+
? await projectModelHistory(materializedHistory)
|
|
553
|
+
: materializedHistory;
|
|
524
554
|
const prepared = await runtime.prepareInput(agent, {
|
|
525
555
|
kind: "message",
|
|
526
556
|
...(text ? { text } : {}),
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import type { Settings } from "@opengeni/config";
|
|
2
|
+
import type { CapabilityPack, RigVersion, SandboxBackend } from "@opengeni/contracts";
|
|
3
|
+
import {
|
|
4
|
+
rigProviderImageContentHash,
|
|
5
|
+
rigProviderImageMatchesDefinition,
|
|
6
|
+
rigProviderImageProviderBindingKeyHash,
|
|
7
|
+
} 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
|
+
}
|