@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
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { GENERATED_VIDEO_MAX_BYTES, type GenerateVideoToolInput } from "@opengeni/contracts";
|
|
2
|
+
import type { SealedVideoReference, SealedVideoReferenceRole } from "@opengeni/core";
|
|
3
|
+
import type { ObjectStorage } from "@opengeni/storage";
|
|
4
|
+
import {
|
|
5
|
+
copyVersionedObjectToVerifiedTemp,
|
|
6
|
+
validateImageReference,
|
|
7
|
+
validateVideoReference,
|
|
8
|
+
} from "./video-media-validation";
|
|
9
|
+
|
|
10
|
+
const MAX_IMAGE_REFERENCE_BYTES = 30 * 1024 * 1024;
|
|
11
|
+
const MAX_VIDEO_REFERENCE_BYTES = 200 * 1024 * 1024;
|
|
12
|
+
const UPLOAD_TIMEOUT_SECONDS = 15 * 60;
|
|
13
|
+
|
|
14
|
+
export type SandboxCommandRunner = (input: {
|
|
15
|
+
cmd: string;
|
|
16
|
+
workdir: string;
|
|
17
|
+
maxOutputTokens: number;
|
|
18
|
+
}) => Promise<{ stdout: string; stderr: string; exitCode: number }>;
|
|
19
|
+
|
|
20
|
+
export type InspectedSandboxVideoReference = Readonly<{
|
|
21
|
+
ordinal: number;
|
|
22
|
+
role: SealedVideoReferenceRole;
|
|
23
|
+
path: string;
|
|
24
|
+
contentType: string;
|
|
25
|
+
sizeBytes: number;
|
|
26
|
+
sha256: string;
|
|
27
|
+
}>;
|
|
28
|
+
|
|
29
|
+
export function videoReferencePaths(
|
|
30
|
+
request: GenerateVideoToolInput,
|
|
31
|
+
): Array<{ role: SealedVideoReferenceRole; path: string }> {
|
|
32
|
+
const source = request.source;
|
|
33
|
+
if (!source || source.mode === "text") return [];
|
|
34
|
+
if (source.mode === "first_frame") return [{ role: "first_frame", path: source.imagePath }];
|
|
35
|
+
if (source.mode === "first_and_last_frames") {
|
|
36
|
+
return [
|
|
37
|
+
{ role: "first_frame", path: source.firstFramePath },
|
|
38
|
+
{ role: "last_frame", path: source.lastFramePath },
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
if (source.mode === "image_reference") {
|
|
42
|
+
return [{ role: "image_reference", path: source.imagePath }];
|
|
43
|
+
}
|
|
44
|
+
return [{ role: "video_reference", path: source.videoPath }];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function inspectSandboxVideoReferences(input: {
|
|
48
|
+
request: GenerateVideoToolInput;
|
|
49
|
+
runCommand: SandboxCommandRunner;
|
|
50
|
+
}): Promise<InspectedSandboxVideoReference[]> {
|
|
51
|
+
const paths = videoReferencePaths(input.request);
|
|
52
|
+
const inspected: InspectedSandboxVideoReference[] = [];
|
|
53
|
+
for (const [ordinal, reference] of paths.entries()) {
|
|
54
|
+
const result = await input.runCommand({
|
|
55
|
+
cmd: inspectCommand(reference.path),
|
|
56
|
+
workdir: "/workspace",
|
|
57
|
+
maxOutputTokens: 4_096,
|
|
58
|
+
});
|
|
59
|
+
if (result.exitCode !== 0) throw new Error("Video reference is not a stable workspace file");
|
|
60
|
+
const [sizeText, sha256, prefixBase64] = result.stdout.trim().split("\t");
|
|
61
|
+
const sizeBytes = Number(sizeText);
|
|
62
|
+
if (
|
|
63
|
+
!Number.isSafeInteger(sizeBytes) ||
|
|
64
|
+
sizeBytes <= 0 ||
|
|
65
|
+
!/^[0-9a-f]{64}$/u.test(sha256 ?? "")
|
|
66
|
+
) {
|
|
67
|
+
throw new Error("Video reference inspection returned invalid metadata");
|
|
68
|
+
}
|
|
69
|
+
const prefix = Buffer.from(prefixBase64 ?? "", "base64");
|
|
70
|
+
const contentType = sniffContentType(prefix);
|
|
71
|
+
const maxBytes =
|
|
72
|
+
reference.role === "video_reference" ? MAX_VIDEO_REFERENCE_BYTES : MAX_IMAGE_REFERENCE_BYTES;
|
|
73
|
+
if (sizeBytes > maxBytes) throw new Error("Video reference exceeds the supported size");
|
|
74
|
+
if (
|
|
75
|
+
(reference.role === "video_reference" && contentType !== "video/mp4") ||
|
|
76
|
+
(reference.role !== "video_reference" && !contentType.startsWith("image/"))
|
|
77
|
+
) {
|
|
78
|
+
throw new Error("Video reference media type does not match its semantic role");
|
|
79
|
+
}
|
|
80
|
+
inspected.push({
|
|
81
|
+
ordinal,
|
|
82
|
+
role: reference.role,
|
|
83
|
+
path: reference.path,
|
|
84
|
+
contentType,
|
|
85
|
+
sizeBytes,
|
|
86
|
+
sha256: sha256!,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return inspected;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export async function uploadAndVerifyVideoReferences(input: {
|
|
93
|
+
storage: ObjectStorage;
|
|
94
|
+
references: readonly InspectedSandboxVideoReference[];
|
|
95
|
+
stagingKeys: readonly string[];
|
|
96
|
+
runCommand: SandboxCommandRunner;
|
|
97
|
+
tempRoot: string;
|
|
98
|
+
ffprobePath: string;
|
|
99
|
+
uploadTtlSeconds: number;
|
|
100
|
+
signal?: AbortSignal;
|
|
101
|
+
}): Promise<SealedVideoReference[]> {
|
|
102
|
+
if (input.references.length !== input.stagingKeys.length) {
|
|
103
|
+
throw new Error("Video reference staging identities do not match");
|
|
104
|
+
}
|
|
105
|
+
const sealed: SealedVideoReference[] = [];
|
|
106
|
+
for (const [index, reference] of input.references.entries()) {
|
|
107
|
+
throwIfAborted(input.signal);
|
|
108
|
+
const key = input.stagingKeys[index]!;
|
|
109
|
+
const existing = input.storage.headObject ? await input.storage.headObject(key) : null;
|
|
110
|
+
if (!existing) {
|
|
111
|
+
const upload = await input.storage.createPutUrl({
|
|
112
|
+
key,
|
|
113
|
+
contentType: reference.contentType,
|
|
114
|
+
sha256: reference.sha256,
|
|
115
|
+
expiresInSeconds: Math.min(input.uploadTtlSeconds, UPLOAD_TIMEOUT_SECONDS),
|
|
116
|
+
});
|
|
117
|
+
const result = await input.runCommand({
|
|
118
|
+
cmd: uploadCommand(reference, upload),
|
|
119
|
+
workdir: "/workspace",
|
|
120
|
+
maxOutputTokens: 4_096,
|
|
121
|
+
});
|
|
122
|
+
if (result.exitCode !== 0) throw new Error("Video reference staging upload failed");
|
|
123
|
+
}
|
|
124
|
+
const verified = await copyVersionedObjectToVerifiedTemp({
|
|
125
|
+
storage: input.storage,
|
|
126
|
+
key,
|
|
127
|
+
expectedSizeBytes: reference.sizeBytes,
|
|
128
|
+
expectedSha256: reference.sha256,
|
|
129
|
+
expectedContentType: reference.contentType,
|
|
130
|
+
maxBytes:
|
|
131
|
+
reference.role === "video_reference"
|
|
132
|
+
? MAX_VIDEO_REFERENCE_BYTES
|
|
133
|
+
: MAX_IMAGE_REFERENCE_BYTES,
|
|
134
|
+
tempRoot: input.tempRoot,
|
|
135
|
+
...(input.signal ? { signal: input.signal } : {}),
|
|
136
|
+
});
|
|
137
|
+
try {
|
|
138
|
+
if (reference.role === "video_reference") {
|
|
139
|
+
await validateVideoReference({ path: verified.path, ffprobePath: input.ffprobePath });
|
|
140
|
+
} else {
|
|
141
|
+
const image = await validateImageReference(verified.path);
|
|
142
|
+
if (image.contentType !== reference.contentType) {
|
|
143
|
+
throw new Error("Video image reference MIME type changed during validation");
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
} finally {
|
|
147
|
+
await verified.cleanup();
|
|
148
|
+
}
|
|
149
|
+
sealed.push({
|
|
150
|
+
role: reference.role,
|
|
151
|
+
contentSha256: reference.sha256,
|
|
152
|
+
contentType: reference.contentType,
|
|
153
|
+
byteSize: reference.sizeBytes,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return sealed;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function videoReferenceStagingKey(input: {
|
|
160
|
+
workspaceId: string;
|
|
161
|
+
operationId: string;
|
|
162
|
+
ordinal: number;
|
|
163
|
+
sha256: string;
|
|
164
|
+
}): string {
|
|
165
|
+
if (!/^[0-9a-f]{64}$/u.test(input.sha256)) throw new Error("Video reference digest is invalid");
|
|
166
|
+
return `video-generation/staging/${input.workspaceId}/${input.operationId}/${input.ordinal}/${input.sha256}`;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function inspectCommand(path: string): string {
|
|
170
|
+
return [
|
|
171
|
+
"set -euo pipefail",
|
|
172
|
+
`requested=${shellQuote(path)}`,
|
|
173
|
+
'case "$requested" in /workspace/*) ;; *) exit 41 ;; esac',
|
|
174
|
+
'case "$requested" in *"/../"*|*"/./"*|*/..|*/.) exit 42 ;; esac',
|
|
175
|
+
'resolved=$(realpath -e -- "$requested")',
|
|
176
|
+
'[ "$resolved" = "$requested" ] || exit 43',
|
|
177
|
+
'exec 3<"$resolved"',
|
|
178
|
+
'fd_path=$(realpath -e -- "/proc/$$/fd/3" 2>/dev/null || realpath -e -- "/dev/fd/3")',
|
|
179
|
+
'case "$fd_path" in /workspace/*) ;; *) exit 44 ;; esac',
|
|
180
|
+
'[ -f "/proc/$$/fd/3" ] 2>/dev/null || [ -f "/dev/fd/3" ] || exit 45',
|
|
181
|
+
'fd=/proc/$$/fd/3; [ -e "$fd" ] || fd=/dev/fd/3',
|
|
182
|
+
'before=$(stat -Lc "%d:%i:%s:%Y" -- "$fd" 2>/dev/null || stat -f "%d:%i:%z:%m" "$fd")',
|
|
183
|
+
'size=$(stat -Lc "%s" -- "$fd" 2>/dev/null || stat -f "%z" "$fd")',
|
|
184
|
+
"sha=$(sha256sum -- \"$fd\" 2>/dev/null | awk '{print $1}' || shasum -a 256 \"$fd\" | awk '{print $1}')",
|
|
185
|
+
'exec 3<&-; exec 3<"$resolved"',
|
|
186
|
+
'fd=/proc/$$/fd/3; [ -e "$fd" ] || fd=/dev/fd/3',
|
|
187
|
+
'reopened=$(stat -Lc "%d:%i:%s:%Y" -- "$fd" 2>/dev/null || stat -f "%d:%i:%z:%m" "$fd")',
|
|
188
|
+
'[ "$before" = "$reopened" ] || exit 46',
|
|
189
|
+
'prefix=$(dd if="$fd" bs=32 count=1 2>/dev/null | base64 | tr -d "\\r\\n")',
|
|
190
|
+
'after=$(stat -Lc "%d:%i:%s:%Y" -- "$fd" 2>/dev/null || stat -f "%d:%i:%z:%m" "$fd")',
|
|
191
|
+
'[ "$before" = "$after" ] || exit 46',
|
|
192
|
+
'printf "%s\\t%s\\t%s\\n" "$size" "$sha" "$prefix"',
|
|
193
|
+
].join("\n");
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function uploadCommand(
|
|
197
|
+
reference: InspectedSandboxVideoReference,
|
|
198
|
+
upload: Awaited<ReturnType<ObjectStorage["createPutUrl"]>>,
|
|
199
|
+
): string {
|
|
200
|
+
const headers = Object.entries(upload.requiredHeaders)
|
|
201
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
202
|
+
.map(([name, value]) => `--header ${shellQuote(`${name}: ${value}`)}`)
|
|
203
|
+
.join(" ");
|
|
204
|
+
return [
|
|
205
|
+
"set -euo pipefail",
|
|
206
|
+
`requested=${shellQuote(reference.path)}`,
|
|
207
|
+
'resolved=$(realpath -e -- "$requested")',
|
|
208
|
+
'[ "$resolved" = "$requested" ] || exit 51',
|
|
209
|
+
'exec 3<"$resolved"',
|
|
210
|
+
'fd_path=$(realpath -e -- "/proc/$$/fd/3" 2>/dev/null || realpath -e -- "/dev/fd/3")',
|
|
211
|
+
'case "$fd_path" in /workspace/*) ;; *) exit 52 ;; esac',
|
|
212
|
+
'fd=/proc/$$/fd/3; [ -e "$fd" ] || fd=/dev/fd/3',
|
|
213
|
+
'before=$(stat -Lc "%d:%i:%s:%Y" -- "$fd" 2>/dev/null || stat -f "%d:%i:%z:%m" "$fd")',
|
|
214
|
+
'size=$(stat -Lc "%s" -- "$fd" 2>/dev/null || stat -f "%z" "$fd")',
|
|
215
|
+
`[ "$size" = ${shellQuote(String(reference.sizeBytes))} ] || exit 53`,
|
|
216
|
+
"sha=$(sha256sum -- \"$fd\" 2>/dev/null | awk '{print $1}' || shasum -a 256 \"$fd\" | awk '{print $1}')",
|
|
217
|
+
`[ "$sha" = ${shellQuote(reference.sha256)} ] || exit 54`,
|
|
218
|
+
'exec 3<&-; exec 3<"$resolved"',
|
|
219
|
+
'fd=/proc/$$/fd/3; [ -e "$fd" ] || fd=/dev/fd/3',
|
|
220
|
+
'reopened=$(stat -Lc "%d:%i:%s:%Y" -- "$fd" 2>/dev/null || stat -f "%d:%i:%z:%m" "$fd")',
|
|
221
|
+
'[ "$before" = "$reopened" ] || exit 55',
|
|
222
|
+
`curl --silent --show-error --fail --connect-timeout 20 --max-time ${UPLOAD_TIMEOUT_SECONDS} --request PUT ${headers} --upload-file "$fd" --output /dev/null ${shellQuote(upload.url)}`,
|
|
223
|
+
'after=$(stat -Lc "%d:%i:%s:%Y" -- "$fd" 2>/dev/null || stat -f "%d:%i:%z:%m" "$fd")',
|
|
224
|
+
'[ "$before" = "$after" ] || exit 56',
|
|
225
|
+
].join("\n");
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function sniffContentType(prefix: Uint8Array): string {
|
|
229
|
+
if (
|
|
230
|
+
prefix.byteLength >= 8 &&
|
|
231
|
+
Buffer.from(prefix.subarray(0, 8)).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))
|
|
232
|
+
) {
|
|
233
|
+
return "image/png";
|
|
234
|
+
}
|
|
235
|
+
if (prefix.byteLength >= 3 && prefix[0] === 0xff && prefix[1] === 0xd8 && prefix[2] === 0xff) {
|
|
236
|
+
return "image/jpeg";
|
|
237
|
+
}
|
|
238
|
+
if (
|
|
239
|
+
prefix.byteLength >= 12 &&
|
|
240
|
+
Buffer.from(prefix.subarray(0, 4)).toString("ascii") === "RIFF" &&
|
|
241
|
+
Buffer.from(prefix.subarray(8, 12)).toString("ascii") === "WEBP"
|
|
242
|
+
) {
|
|
243
|
+
return "image/webp";
|
|
244
|
+
}
|
|
245
|
+
if (prefix.byteLength >= 12 && Buffer.from(prefix.subarray(4, 8)).toString("ascii") === "ftyp") {
|
|
246
|
+
return "video/mp4";
|
|
247
|
+
}
|
|
248
|
+
throw new Error("Video reference has an unsupported media signature");
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function shellQuote(value: string): string {
|
|
252
|
+
return `'${value.replaceAll("'", `'"'"'`)}'`;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function throwIfAborted(signal?: AbortSignal): void {
|
|
256
|
+
if (signal?.aborted) throw signal.reason ?? new Error("Video reference staging was cancelled");
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export const VIDEO_REFERENCE_LIMITS = Object.freeze({
|
|
260
|
+
imageBytes: MAX_IMAGE_REFERENCE_BYTES,
|
|
261
|
+
videoBytes: MAX_VIDEO_REFERENCE_BYTES,
|
|
262
|
+
outputBytes: GENERATED_VIDEO_MAX_BYTES,
|
|
263
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ControlActivityServices } from "./types";
|
|
2
2
|
import { reconcilePendingSessionWorkflowWakes } from "./parent-wake";
|
|
3
3
|
|
|
4
4
|
const BATCH_SIZE = 1_000;
|
|
@@ -16,7 +16,7 @@ export type DispatchSessionWorkflowWakesResult = {
|
|
|
16
16
|
* acknowledgement path used by immediate delivery. This is a repair path, not
|
|
17
17
|
* an eligibility scan: producers have already decided what must be delivered.
|
|
18
18
|
*/
|
|
19
|
-
export function createWorkflowWakeActivities(services: () => Promise<
|
|
19
|
+
export function createWorkflowWakeActivities(services: () => Promise<ControlActivityServices>) {
|
|
20
20
|
return {
|
|
21
21
|
async dispatchSessionWorkflowWakes(): Promise<DispatchSessionWorkflowWakesResult> {
|
|
22
22
|
const service = await services();
|
|
@@ -221,6 +221,7 @@ type CaptureRepositoryReadResult =
|
|
|
221
221
|
complete: true;
|
|
222
222
|
status: Awaited<ReturnType<SandboxChannelAService["gitStatus"]>>;
|
|
223
223
|
diff: Awaited<ReturnType<SandboxChannelAService["gitDiff"]>>;
|
|
224
|
+
branchDiff?: Awaited<ReturnType<SandboxChannelAService["gitDiff"]>> | undefined;
|
|
224
225
|
}
|
|
225
226
|
| { complete: false; degradedReason: "repository_read_unavailable" };
|
|
226
227
|
|
|
@@ -304,7 +305,7 @@ export async function readCaptureRepository(
|
|
|
304
305
|
return { complete: false, degradedReason: "repository_read_unavailable" };
|
|
305
306
|
}
|
|
306
307
|
try {
|
|
307
|
-
const
|
|
308
|
+
const workingRequest = svc.gitDiff({
|
|
308
309
|
path: root,
|
|
309
310
|
staged: false,
|
|
310
311
|
includeUntracked: true,
|
|
@@ -313,7 +314,29 @@ export async function readCaptureRepository(
|
|
|
313
314
|
contextLines: 3,
|
|
314
315
|
maxBytesPerFile: PER_FILE_DIFF_GUARD_BYTES,
|
|
315
316
|
});
|
|
316
|
-
|
|
317
|
+
// Branch capture is additive. A repository without origin/HEAD must not
|
|
318
|
+
// degrade the authoritative working-tree capture.
|
|
319
|
+
const branchRequest = Promise.resolve()
|
|
320
|
+
.then(() =>
|
|
321
|
+
svc.gitDiff({
|
|
322
|
+
path: root,
|
|
323
|
+
staged: false,
|
|
324
|
+
includeUntracked: true,
|
|
325
|
+
fromRef: "origin/HEAD",
|
|
326
|
+
pathspec: [],
|
|
327
|
+
contextLines: 3,
|
|
328
|
+
maxBytesPerFile: PER_FILE_DIFF_GUARD_BYTES,
|
|
329
|
+
}),
|
|
330
|
+
)
|
|
331
|
+
.then((value) => value)
|
|
332
|
+
.catch(() => null);
|
|
333
|
+
const [diff, branchDiff] = await Promise.all([workingRequest, branchRequest]);
|
|
334
|
+
return {
|
|
335
|
+
complete: true,
|
|
336
|
+
status,
|
|
337
|
+
diff,
|
|
338
|
+
...(branchDiff ? { branchDiff } : {}),
|
|
339
|
+
};
|
|
317
340
|
} catch (error) {
|
|
318
341
|
const boxExiting = classifyCaptureEntryError(error);
|
|
319
342
|
if (boxExiting) throw boxExiting;
|
|
@@ -503,7 +526,7 @@ async function runCapture(
|
|
|
503
526
|
);
|
|
504
527
|
return;
|
|
505
528
|
}
|
|
506
|
-
const { status, diff } = repository;
|
|
529
|
+
const { status, diff, branchDiff } = repository;
|
|
507
530
|
// Drop residue churn from the review diff too. On a desktop box the seed's
|
|
508
531
|
// `git add -A` in $HOME commits ~/.config/xfce4/* into HEAD, so `git diff HEAD`
|
|
509
532
|
// lists the continuously-rewritten desktop dotfiles as changed — noise the
|
|
@@ -517,12 +540,20 @@ async function runCapture(
|
|
|
517
540
|
repos.push({
|
|
518
541
|
root,
|
|
519
542
|
head: status.head,
|
|
543
|
+
headOid: status.headOid ?? null,
|
|
520
544
|
detached: status.detached,
|
|
521
545
|
upstream: status.upstream,
|
|
522
546
|
ahead: status.ahead,
|
|
523
547
|
behind: status.behind,
|
|
524
548
|
status: statusFiles,
|
|
525
549
|
diff: diffFiles,
|
|
550
|
+
...(branchDiff
|
|
551
|
+
? {
|
|
552
|
+
branchDiff: branchDiff.files.filter(
|
|
553
|
+
(f) => !isUnderResidueDir(joinRepoPath(root, f.path)),
|
|
554
|
+
),
|
|
555
|
+
}
|
|
556
|
+
: {}),
|
|
526
557
|
});
|
|
527
558
|
for (const f of diffFiles) {
|
|
528
559
|
additions += f.additions;
|
|
@@ -1006,24 +1037,57 @@ function statusCodeOf(f: GitFileStatus): GitFileStatusCode {
|
|
|
1006
1037
|
|
|
1007
1038
|
/**
|
|
1008
1039
|
* sha256 over the CHANGE SURFACE only — per-file (path, status, hash, deleted,
|
|
1009
|
-
* tooLarge)
|
|
1040
|
+
* tooLarge), exact HEAD identity, the working diff summary, and exact committed
|
|
1041
|
+
* branch changes.
|
|
1010
1042
|
* Deliberately excludes the tree index and file mtimes (which drift without a
|
|
1011
1043
|
* real change) so two turns that leave the workspace in the same state produce
|
|
1012
1044
|
* the same fingerprint (the empty-turn gate). Order-independent (sorted).
|
|
1013
1045
|
*/
|
|
1014
|
-
function changeFingerprint(
|
|
1046
|
+
export function changeFingerprint(
|
|
1047
|
+
repos: WorkspaceCaptureRepo[],
|
|
1048
|
+
files: WorkspaceCaptureFile[],
|
|
1049
|
+
): string {
|
|
1015
1050
|
const fileParts = files
|
|
1016
1051
|
.map((f) => `${f.path}|${f.status}|${f.hash ?? ""}|${f.deleted ? 1 : 0}|${f.tooLarge ? 1 : 0}`)
|
|
1017
1052
|
.sort();
|
|
1053
|
+
const branchDiffPart = (diff: WorkspaceCaptureRepo["diff"][number]): string =>
|
|
1054
|
+
JSON.stringify([
|
|
1055
|
+
diff.path,
|
|
1056
|
+
diff.oldPath,
|
|
1057
|
+
diff.status,
|
|
1058
|
+
diff.isBinary,
|
|
1059
|
+
diff.isImage,
|
|
1060
|
+
diff.additions,
|
|
1061
|
+
diff.deletions,
|
|
1062
|
+
diff.truncated,
|
|
1063
|
+
diff.hunks.map((hunk) => [
|
|
1064
|
+
hunk.oldStart,
|
|
1065
|
+
hunk.oldLines,
|
|
1066
|
+
hunk.newStart,
|
|
1067
|
+
hunk.newLines,
|
|
1068
|
+
hunk.header,
|
|
1069
|
+
hunk.lines.map((line) => [line.type, line.oldNo, line.newNo, line.text]),
|
|
1070
|
+
]),
|
|
1071
|
+
]);
|
|
1018
1072
|
const repoParts = repos
|
|
1019
|
-
.map(
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1073
|
+
.map((repo) => {
|
|
1074
|
+
const workingDiff = repo.diff
|
|
1075
|
+
.map(
|
|
1076
|
+
(diff) =>
|
|
1077
|
+
`${diff.path}:${diff.status}:${diff.additions}:${diff.deletions}:${diff.truncated ? 1 : 0}`,
|
|
1078
|
+
)
|
|
1079
|
+
.sort();
|
|
1080
|
+
const branchDiff =
|
|
1081
|
+
repo.branchDiff === undefined ? null : repo.branchDiff.map(branchDiffPart).sort();
|
|
1082
|
+
return JSON.stringify([
|
|
1083
|
+
repo.root,
|
|
1084
|
+
repo.head,
|
|
1085
|
+
repo.headOid ?? null,
|
|
1086
|
+
repo.ahead,
|
|
1087
|
+
workingDiff,
|
|
1088
|
+
branchDiff,
|
|
1089
|
+
]);
|
|
1090
|
+
})
|
|
1027
1091
|
.sort();
|
|
1028
1092
|
return sha256(utf8(JSON.stringify({ files: fileParts, repos: repoParts })));
|
|
1029
1093
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { createSharedActivityServices } from "./activity-services";
|
|
2
|
+
import { createCodexCapacityActivities } from "./activities/codex-capacity";
|
|
3
|
+
import { createDocumentActivities } from "./activities/documents";
|
|
4
|
+
import { createFileUploadReaperActivities } from "./activities/file-upload-reaper";
|
|
5
|
+
import { createGoalActivities } from "./activities/goals";
|
|
6
|
+
import { createKnowledgeSourceSyncActivities } from "./activities/knowledge-source-sync";
|
|
7
|
+
import { createRetainedScreenshotMaintenanceActivities } from "./activities/retained-screenshot-reaper";
|
|
8
|
+
import { createRigVerificationActivities } from "./activities/rig-verification";
|
|
9
|
+
import { createSandboxLeaseActivities } from "./activities/sandbox-lease";
|
|
10
|
+
import { createScheduledTaskActivities } from "./activities/scheduled-tasks";
|
|
11
|
+
import { createSessionStateActivities } from "./activities/session-state";
|
|
12
|
+
import type { ActivityDependencies, ControlActivityServices } from "./activities/types";
|
|
13
|
+
import { createWorkflowWakeActivities } from "./activities/workflow-wake";
|
|
14
|
+
|
|
15
|
+
function createControlActivityServices(
|
|
16
|
+
dependencies: ActivityDependencies,
|
|
17
|
+
): () => Promise<ControlActivityServices> {
|
|
18
|
+
const shared = createSharedActivityServices(dependencies);
|
|
19
|
+
return shared;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function createControlActivitiesFromServices(
|
|
23
|
+
services: () => Promise<ControlActivityServices>,
|
|
24
|
+
resolveDocumentServices?: () => Promise<import("@opengeni/documents").DocumentServices>,
|
|
25
|
+
) {
|
|
26
|
+
return {
|
|
27
|
+
...createDocumentActivities(services, resolveDocumentServices),
|
|
28
|
+
...createKnowledgeSourceSyncActivities(services, resolveDocumentServices),
|
|
29
|
+
...createSessionStateActivities(services),
|
|
30
|
+
...createScheduledTaskActivities(services),
|
|
31
|
+
...createGoalActivities(services),
|
|
32
|
+
...createCodexCapacityActivities(services),
|
|
33
|
+
...createRigVerificationActivities(services),
|
|
34
|
+
...createFileUploadReaperActivities(services),
|
|
35
|
+
...createRetainedScreenshotMaintenanceActivities(services),
|
|
36
|
+
...createWorkflowWakeActivities(services),
|
|
37
|
+
...createSandboxLeaseActivities(services),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function createControlActivities(dependencies: ActivityDependencies = {}) {
|
|
42
|
+
const services = createControlActivityServices(dependencies);
|
|
43
|
+
let documentServicesPromise: Promise<import("@opengeni/documents").DocumentServices> | null =
|
|
44
|
+
null;
|
|
45
|
+
const resolveDocumentServices = async () => {
|
|
46
|
+
documentServicesPromise ??= dependencies.documentServices
|
|
47
|
+
? Promise.resolve(dependencies.documentServices)
|
|
48
|
+
: import("@opengeni/documents").then(async ({ createDocumentServices }) =>
|
|
49
|
+
createDocumentServices((await services()).settings),
|
|
50
|
+
);
|
|
51
|
+
return await documentServicesPromise;
|
|
52
|
+
};
|
|
53
|
+
return createControlActivitiesFromServices(services, resolveDocumentServices);
|
|
54
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createProductionAgentRuntime, summarizeForCompaction } from "@opengeni/runtime";
|
|
2
|
+
import { createSharedActivityServices } from "./activity-services";
|
|
3
|
+
import { createRunAgentTurnActivity } from "./activities/agent-turn";
|
|
4
|
+
import { createVideoGenerationActivities } from "./activities/video-generation-reconciliation";
|
|
5
|
+
import type { ActivityDependencies, TurnActivityServices } from "./activities/types";
|
|
6
|
+
import { runtimeMetricsHooksForObservability } from "./observability-metrics";
|
|
7
|
+
|
|
8
|
+
function createTurnActivityServices(
|
|
9
|
+
dependencies: ActivityDependencies,
|
|
10
|
+
): () => Promise<TurnActivityServices> {
|
|
11
|
+
const shared = createSharedActivityServices(dependencies);
|
|
12
|
+
let servicesPromise: Promise<TurnActivityServices> | null = null;
|
|
13
|
+
return async () => {
|
|
14
|
+
servicesPromise ??= (async () => {
|
|
15
|
+
const services = await shared();
|
|
16
|
+
return {
|
|
17
|
+
...services,
|
|
18
|
+
runtime:
|
|
19
|
+
dependencies.runtime ??
|
|
20
|
+
createProductionAgentRuntime({
|
|
21
|
+
metrics: runtimeMetricsHooksForObservability(services.observability),
|
|
22
|
+
}),
|
|
23
|
+
summarizeContextForCompaction:
|
|
24
|
+
dependencies.summarizeContextForCompaction ?? summarizeForCompaction,
|
|
25
|
+
};
|
|
26
|
+
})();
|
|
27
|
+
return await servicesPromise;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function createTurnActivities(dependencies: ActivityDependencies = {}) {
|
|
32
|
+
return createTurnActivitiesFromServices(createTurnActivityServices(dependencies));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function createTurnActivitiesFromServices(services: () => Promise<TurnActivityServices>) {
|
|
36
|
+
return {
|
|
37
|
+
runAgentTurn: createRunAgentTurnActivity(services),
|
|
38
|
+
...createVideoGenerationActivities(services),
|
|
39
|
+
};
|
|
40
|
+
}
|