@opengeni/worker-bundle 0.16.29 → 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.
Files changed (168) hide show
  1. package/dist/activities/agent-turn.d.ts +85 -19
  2. package/dist/activities/api-integrations.d.ts +21 -0
  3. package/dist/activities/codemode-dispatcher.d.ts +35 -0
  4. package/dist/activities/codemode-token-renewal.d.ts +23 -0
  5. package/dist/activities/codex-capacity.d.ts +5 -5
  6. package/dist/activities/codex-image-generation.d.ts +21 -0
  7. package/dist/activities/context-compaction.d.ts +1 -0
  8. package/dist/activities/documents.d.ts +3 -2
  9. package/dist/activities/environment.d.ts +11 -8
  10. package/dist/activities/expiring-material-renewal.d.ts +1 -1
  11. package/dist/activities/file-upload-reaper.d.ts +7 -2
  12. package/dist/activities/gateway-image-generation.d.ts +39 -0
  13. package/dist/activities/gateway-video-generation.d.ts +53 -0
  14. package/dist/activities/generated-images.d.ts +112 -0
  15. package/dist/activities/git-credential-renewal.d.ts +1 -1
  16. package/dist/activities/goals.d.ts +2 -2
  17. package/dist/activities/google-drive-changes.d.ts +99 -0
  18. package/dist/activities/image-generation-operation.d.ts +74 -0
  19. package/dist/activities/image-generation-references.d.ts +25 -0
  20. package/dist/activities/knowledge-source-sync-driver.d.ts +23 -0
  21. package/dist/activities/knowledge-source-sync.d.ts +75 -0
  22. package/dist/activities/packs.d.ts +13 -26
  23. package/dist/activities/parent-wake.d.ts +1 -1
  24. package/dist/activities/retained-screenshot-reaper.d.ts +2 -2
  25. package/dist/activities/retained-screenshots.d.ts +36 -0
  26. package/dist/activities/rig-verification.d.ts +82 -5
  27. package/dist/activities/run-credential-renewal.d.ts +1 -1
  28. package/dist/activities/run-input.d.ts +3 -1
  29. package/dist/activities/sandbox-images.d.ts +14 -0
  30. package/dist/activities/sandbox-lease.d.ts +47 -9
  31. package/dist/activities/scheduled-tasks.d.ts +2 -2
  32. package/dist/activities/session-state.d.ts +4 -4
  33. package/dist/activities/streaming.d.ts +1 -1
  34. package/dist/activities/types.d.ts +71 -5
  35. package/dist/activities/video-generation-admission.d.ts +38 -0
  36. package/dist/activities/video-generation-credential.d.ts +7 -0
  37. package/dist/activities/video-generation-reconciliation.d.ts +13 -0
  38. package/dist/activities/video-media-validation.d.ts +34 -0
  39. package/dist/activities/video-output-retention.d.ts +36 -0
  40. package/dist/activities/video-reference-staging.d.ts +49 -0
  41. package/dist/activities/workflow-wake.d.ts +2 -2
  42. package/dist/activities/workspace-capture.d.ts +10 -1
  43. package/dist/activities-control-44KBWLSM.js +6885 -0
  44. package/dist/activities-control-44KBWLSM.js.map +1 -0
  45. package/dist/activities-control.d.ts +289 -0
  46. package/dist/activities-turn-K4CEDEGJ.js +14675 -0
  47. package/dist/activities-turn-K4CEDEGJ.js.map +1 -0
  48. package/dist/activities-turn.d.ts +17 -0
  49. package/dist/activities.d.ts +130 -150
  50. package/dist/activity-services.d.ts +10 -0
  51. package/dist/artifact-materializer-entry.d.ts +6 -0
  52. package/dist/artifact-materializer-entry.js +2662 -0
  53. package/dist/artifact-materializer-entry.js.map +1 -0
  54. package/dist/artifact-outbox-entry.d.ts +2 -0
  55. package/dist/artifact-outbox-entry.js +681 -0
  56. package/dist/artifact-outbox-entry.js.map +1 -0
  57. package/dist/chunk-E3RI3I33.js +828 -0
  58. package/dist/chunk-E3RI3I33.js.map +1 -0
  59. package/dist/chunk-GRFQTTSQ.js +448 -0
  60. package/dist/chunk-GRFQTTSQ.js.map +1 -0
  61. package/dist/chunk-KKCRGAGZ.js +3091 -0
  62. package/dist/chunk-KKCRGAGZ.js.map +1 -0
  63. package/dist/concurrency.d.ts +108 -5
  64. package/dist/editable-artifact-hint-broker.d.ts +49 -0
  65. package/dist/editable-artifact-materializer-launcher.d.ts +49 -0
  66. package/dist/editable-artifact-materializer-service.d.ts +108 -0
  67. package/dist/editable-artifact-materializer-storage.d.ts +12 -0
  68. package/dist/editable-artifact-materializer-subprocess.d.ts +50 -0
  69. package/dist/editable-artifact-materializer.d.ts +262 -0
  70. package/dist/editable-artifact-outbox-dispatcher.d.ts +44 -0
  71. package/dist/editable-artifact-outbox-service.d.ts +70 -0
  72. package/dist/host-export.d.ts +1 -1
  73. package/dist/index.d.ts +176 -10
  74. package/dist/index.js +662 -17374
  75. package/dist/index.js.map +1 -1
  76. package/dist/memory-pressure-guard.d.ts +57 -0
  77. package/dist/model-checkpoint-memory-collector.d.ts +22 -0
  78. package/dist/observability-metrics.d.ts +33 -0
  79. package/dist/sandbox-reaper-contract.d.ts +40 -0
  80. package/dist/sandbox-reaper-timeout.d.ts +14 -0
  81. package/dist/sandbox-resume.d.ts +34 -7
  82. package/dist/sandbox-routing.d.ts +2 -0
  83. package/dist/worker-service-lifecycle.d.ts +6 -2
  84. package/dist/workflow-bundle.js +1043 -363
  85. package/dist/workflows/activities.d.ts +7 -1
  86. package/dist/workflows/document-index.d.ts +1 -1
  87. package/dist/workflows/knowledge-source-sync.d.ts +13 -0
  88. package/dist/workflows/rig-verification.d.ts +1 -1
  89. package/dist/workflows/sandbox-reaper.d.ts +8 -0
  90. package/dist/workflows/scheduled-tasks.d.ts +1 -1
  91. package/dist/workflows/session.d.ts +2 -2
  92. package/dist/workflows/video-generation.d.ts +10 -0
  93. package/dist/workflows/workflow-wake.d.ts +1 -1
  94. package/dist/workflows.d.ts +9 -7
  95. package/package.json +34 -15
  96. package/src/activities/agent-turn.ts +1470 -246
  97. package/src/activities/api-integrations.ts +138 -0
  98. package/src/activities/codemode-dispatcher.ts +335 -0
  99. package/src/activities/codemode-token-renewal.ts +64 -0
  100. package/src/activities/codex-capacity.ts +6 -6
  101. package/src/activities/codex-image-generation.ts +56 -0
  102. package/src/activities/context-compaction.ts +38 -3
  103. package/src/activities/documents.ts +14 -4
  104. package/src/activities/environment.ts +45 -42
  105. package/src/activities/expiring-material-renewal.ts +1 -1
  106. package/src/activities/file-upload-reaper.ts +34 -3
  107. package/src/activities/gateway-image-generation.ts +146 -0
  108. package/src/activities/gateway-video-generation.ts +298 -0
  109. package/src/activities/generated-images.ts +860 -0
  110. package/src/activities/goals.ts +6 -2
  111. package/src/activities/google-drive-changes.ts +454 -0
  112. package/src/activities/image-generation-operation.ts +333 -0
  113. package/src/activities/image-generation-references.ts +118 -0
  114. package/src/activities/knowledge-source-sync-driver.ts +27 -0
  115. package/src/activities/knowledge-source-sync.ts +2840 -0
  116. package/src/activities/mcp-credentials.ts +1 -0
  117. package/src/activities/packs.ts +55 -55
  118. package/src/activities/retained-screenshot-reaper.ts +2 -2
  119. package/src/activities/retained-screenshots.ts +453 -28
  120. package/src/activities/rig-verification.ts +554 -43
  121. package/src/activities/run-input.ts +22 -6
  122. package/src/activities/sandbox-images.ts +167 -0
  123. package/src/activities/sandbox-lease.ts +1065 -483
  124. package/src/activities/scheduled-tasks.ts +77 -4
  125. package/src/activities/session-state.ts +4 -4
  126. package/src/activities/streaming.ts +42 -3
  127. package/src/activities/types.ts +87 -5
  128. package/src/activities/video-generation-admission.ts +270 -0
  129. package/src/activities/video-generation-credential.ts +34 -0
  130. package/src/activities/video-generation-reconciliation.ts +578 -0
  131. package/src/activities/video-media-validation.ts +326 -0
  132. package/src/activities/video-output-retention.ts +314 -0
  133. package/src/activities/video-reference-staging.ts +263 -0
  134. package/src/activities/workflow-wake.ts +2 -2
  135. package/src/activities/workspace-capture.ts +44 -10
  136. package/src/activities-control.ts +54 -0
  137. package/src/activities-turn.ts +40 -0
  138. package/src/activities.ts +48 -124
  139. package/src/activity-services.ts +62 -0
  140. package/src/artifact-materializer-entry.ts +35 -0
  141. package/src/artifact-outbox-entry.ts +29 -0
  142. package/src/concurrency.ts +484 -6
  143. package/src/editable-artifact-hint-broker.ts +235 -0
  144. package/src/editable-artifact-materializer-launcher.ts +515 -0
  145. package/src/editable-artifact-materializer-service.ts +787 -0
  146. package/src/editable-artifact-materializer-storage.ts +413 -0
  147. package/src/editable-artifact-materializer-subprocess.ts +956 -0
  148. package/src/editable-artifact-materializer.ts +1289 -0
  149. package/src/editable-artifact-outbox-dispatcher.ts +244 -0
  150. package/src/editable-artifact-outbox-service.ts +438 -0
  151. package/src/index.ts +277 -72
  152. package/src/memory-pressure-guard.ts +489 -0
  153. package/src/model-checkpoint-memory-collector.ts +116 -0
  154. package/src/observability-metrics.ts +199 -4
  155. package/src/sandbox-reaper-contract.ts +73 -0
  156. package/src/sandbox-reaper-timeout.ts +79 -0
  157. package/src/sandbox-resume.ts +294 -153
  158. package/src/sandbox-routing.ts +19 -24
  159. package/src/worker-service-lifecycle.ts +80 -14
  160. package/src/workflows/activities.ts +30 -0
  161. package/src/workflows/file-upload-reaper.ts +3 -1
  162. package/src/workflows/knowledge-source-sync.ts +83 -0
  163. package/src/workflows/sandbox-reaper.ts +183 -21
  164. package/src/workflows/scheduled-tasks.ts +42 -6
  165. package/src/workflows/video-generation.ts +36 -0
  166. package/src/workflows.ts +17 -1
  167. package/dist/activities/toolspace-token-renewal.d.ts +0 -23
  168. package/src/activities/toolspace-token-renewal.ts +0 -64
@@ -0,0 +1,298 @@
1
+ import type { CanonicalVideoGenerationRequest } from "@opengeni/core";
2
+ import { readResponseTextBounded, type FetchLike } from "@opengeni/network";
3
+
4
+ export const GATEWAY_VIDEO_PROVIDER_ID = "vercel-ai-gateway" as const;
5
+ export const GATEWAY_VIDEO_START_URL =
6
+ "https://ai-gateway.vercel.sh/v4/ai/video-model/start" as const;
7
+ export const GATEWAY_VIDEO_STATUS_URL =
8
+ "https://ai-gateway.vercel.sh/v4/ai/video-model/status" as const;
9
+
10
+ const PROTOCOL_VERSION = "0.0.1";
11
+ const VIDEO_SPECIFICATION_VERSION = "4";
12
+ const RESPONSE_MAX_BYTES = 1024 * 1024;
13
+ const ERROR_MAX_BYTES = 64 * 1024;
14
+
15
+ export type GatewayVideoReferenceGrant = Readonly<{
16
+ role: "first_frame" | "last_frame" | "image_reference" | "video_reference";
17
+ url: string;
18
+ mediaType: string;
19
+ }>;
20
+
21
+ export type GatewayVideoStartResult = Readonly<{ providerJobId: string }>;
22
+ export type GatewayVideoStatusResult =
23
+ | Readonly<{ status: "pending" }>
24
+ | Readonly<{ status: "completed"; outputUrl: string; mediaType: string }>
25
+ | Readonly<{ status: "error"; publicReason: string }>;
26
+
27
+ export class GatewayVideoApiError extends Error {
28
+ constructor(
29
+ readonly status: number | null,
30
+ readonly retryable: boolean,
31
+ message: string,
32
+ ) {
33
+ super(message);
34
+ this.name = "GatewayVideoApiError";
35
+ }
36
+ }
37
+
38
+ export async function startGatewayVideoGeneration(input: {
39
+ apiKey: string;
40
+ request: CanonicalVideoGenerationRequest;
41
+ idempotencyKey: string;
42
+ referenceGrants: readonly GatewayVideoReferenceGrant[];
43
+ signal?: AbortSignal;
44
+ fetch?: FetchLike;
45
+ }): Promise<GatewayVideoStartResult> {
46
+ return await startGatewayVideoGenerationWithBody({
47
+ apiKey: input.apiKey,
48
+ modelId: input.request.modelId,
49
+ body: buildGatewayVideoStartBody(input.request, input.referenceGrants),
50
+ idempotencyKey: input.idempotencyKey,
51
+ ...(input.signal ? { signal: input.signal } : {}),
52
+ ...(input.fetch ? { fetch: input.fetch } : {}),
53
+ });
54
+ }
55
+
56
+ /** Replay entrypoint for the encrypted, byte-stable provider request. */
57
+ export async function startGatewayVideoGenerationWithBody(input: {
58
+ apiKey: string;
59
+ modelId: string;
60
+ body: Record<string, unknown>;
61
+ idempotencyKey: string;
62
+ signal?: AbortSignal;
63
+ fetch?: FetchLike;
64
+ }): Promise<GatewayVideoStartResult> {
65
+ requireSecret(input.apiKey);
66
+ requireIdempotencyKey(input.idempotencyKey);
67
+ const response = await gatewayFetch({
68
+ url: GATEWAY_VIDEO_START_URL,
69
+ apiKey: input.apiKey,
70
+ modelId: input.modelId,
71
+ body: input.body,
72
+ idempotencyKey: input.idempotencyKey,
73
+ ...(input.signal ? { signal: input.signal } : {}),
74
+ ...(input.fetch ? { fetch: input.fetch } : {}),
75
+ });
76
+ const parsed = await readGatewayJson(response, "AI Gateway video start", input.signal);
77
+ const operation = record(parsed.operation);
78
+ const providerJobId = stringValue(operation?.gatewayJobId);
79
+ if (!providerJobId || providerJobId.length > 1_024) {
80
+ throw new GatewayVideoApiError(null, true, "AI Gateway video start response is malformed");
81
+ }
82
+ return Object.freeze({ providerJobId });
83
+ }
84
+
85
+ export async function getGatewayVideoGenerationStatus(input: {
86
+ apiKey: string;
87
+ modelId: string;
88
+ providerJobId: string;
89
+ signal?: AbortSignal;
90
+ fetch?: FetchLike;
91
+ }): Promise<GatewayVideoStatusResult> {
92
+ requireSecret(input.apiKey);
93
+ if (!input.providerJobId.trim() || input.providerJobId.length > 1_024) {
94
+ throw new Error("AI Gateway video job identity is invalid");
95
+ }
96
+ const response = await gatewayFetch({
97
+ url: GATEWAY_VIDEO_STATUS_URL,
98
+ apiKey: input.apiKey,
99
+ modelId: input.modelId,
100
+ body: { operation: { gatewayJobId: input.providerJobId } },
101
+ retryNotFound: true,
102
+ ...(input.signal ? { signal: input.signal } : {}),
103
+ ...(input.fetch ? { fetch: input.fetch } : {}),
104
+ });
105
+ const parsed = await readGatewayJson(response, "AI Gateway video status", input.signal);
106
+ const status = stringValue(parsed.status);
107
+ if (status === "pending" || status === "queued" || status === "running") {
108
+ return Object.freeze({ status: "pending" });
109
+ }
110
+ if (status === "error" || status === "cancelled") {
111
+ return Object.freeze({
112
+ status: "error",
113
+ publicReason: publicProviderReason(parsed.error, status === "cancelled"),
114
+ });
115
+ }
116
+ if (status !== "completed" || !Array.isArray(parsed.videos) || parsed.videos.length !== 1) {
117
+ throw new GatewayVideoApiError(null, true, "AI Gateway video status response is malformed");
118
+ }
119
+ const video = record(parsed.videos[0]);
120
+ const outputUrl = video?.type === "url" ? stringValue(video.url) : null;
121
+ const mediaType = stringValue(video?.mediaType);
122
+ if (!outputUrl || !mediaType || outputUrl.length > 8_192 || mediaType.length > 128) {
123
+ throw new GatewayVideoApiError(null, false, "AI Gateway returned an unsupported video result");
124
+ }
125
+ return Object.freeze({ status: "completed", outputUrl, mediaType });
126
+ }
127
+
128
+ export function buildGatewayVideoStartBody(
129
+ request: CanonicalVideoGenerationRequest,
130
+ referenceGrants: readonly GatewayVideoReferenceGrant[],
131
+ ): Record<string, unknown> {
132
+ const expectedRoles = request.references.map((reference) => reference.role);
133
+ if (
134
+ referenceGrants.length !== expectedRoles.length ||
135
+ referenceGrants.some((grant, index) => grant.role !== expectedRoles[index])
136
+ ) {
137
+ throw new Error("Video reference grants do not match the sealed request");
138
+ }
139
+ const files = referenceGrants.map((grant) => ({
140
+ role: grant.role,
141
+ file: {
142
+ type: "url" as const,
143
+ url: requireHttps(grant.url),
144
+ mediaType: grant.mediaType,
145
+ },
146
+ }));
147
+ return {
148
+ prompt: request.prompt,
149
+ n: 1,
150
+ aspectRatio: request.aspectRatio,
151
+ resolution: request.resolution,
152
+ duration: request.durationSeconds,
153
+ fps: 24,
154
+ generateAudio: request.generateAudio,
155
+ providerOptions: {},
156
+ ...(request.sourceMode === "first_frame" || request.sourceMode === "first_and_last_frames"
157
+ ? {
158
+ frameImages: files.map(({ role, file }) => ({
159
+ frameType: role,
160
+ image: file,
161
+ })),
162
+ }
163
+ : request.sourceMode === "image_reference" || request.sourceMode === "video_reference"
164
+ ? { inputReferences: files.map(({ file }) => file) }
165
+ : {}),
166
+ };
167
+ }
168
+
169
+ async function gatewayFetch(input: {
170
+ url: string;
171
+ apiKey: string;
172
+ modelId: string;
173
+ body: Record<string, unknown>;
174
+ idempotencyKey?: string;
175
+ retryNotFound?: boolean;
176
+ signal?: AbortSignal;
177
+ fetch?: FetchLike;
178
+ }): Promise<Response> {
179
+ const timeout = AbortSignal.timeout(60_000);
180
+ const signal = input.signal ? AbortSignal.any([input.signal, timeout]) : timeout;
181
+ let response: Response;
182
+ try {
183
+ response = await (input.fetch ?? globalThis.fetch)(input.url, {
184
+ method: "POST",
185
+ redirect: "error",
186
+ signal,
187
+ headers: {
188
+ Authorization: `Bearer ${input.apiKey}`,
189
+ accept: "application/json",
190
+ "content-type": "application/json",
191
+ "ai-gateway-auth-method": "api-key",
192
+ "ai-gateway-protocol-version": PROTOCOL_VERSION,
193
+ "ai-video-model-specification-version": VIDEO_SPECIFICATION_VERSION,
194
+ "ai-model-id": input.modelId,
195
+ "user-agent": "opengeni/video-generation",
196
+ ...(input.idempotencyKey ? { "idempotency-key": input.idempotencyKey } : {}),
197
+ },
198
+ body: JSON.stringify(input.body),
199
+ });
200
+ } catch (error) {
201
+ if (input.signal?.aborted) throw input.signal.reason;
202
+ throw new GatewayVideoApiError(
203
+ null,
204
+ true,
205
+ error instanceof Error ? error.message : "AI Gateway video request failed",
206
+ );
207
+ }
208
+ if (response.ok) return response;
209
+ const detail = await readResponseTextBounded(
210
+ response,
211
+ ERROR_MAX_BYTES,
212
+ "AI Gateway video error",
213
+ {
214
+ signal,
215
+ },
216
+ ).catch(() => "");
217
+ const retryable =
218
+ (input.retryNotFound === true && response.status === 404) ||
219
+ response.status === 408 ||
220
+ response.status === 429 ||
221
+ response.status >= 500;
222
+ throw new GatewayVideoApiError(
223
+ response.status,
224
+ retryable,
225
+ detail
226
+ ? `AI Gateway video request failed (${response.status}): ${boundedError(detail)}`
227
+ : `AI Gateway video request failed (${response.status})`,
228
+ );
229
+ }
230
+
231
+ async function readGatewayJson(
232
+ response: Response,
233
+ label: string,
234
+ signal?: AbortSignal,
235
+ ): Promise<Record<string, unknown>> {
236
+ const text = await readResponseTextBounded(response, RESPONSE_MAX_BYTES, label, {
237
+ ...(signal ? { signal } : {}),
238
+ });
239
+ let parsed: unknown;
240
+ try {
241
+ parsed = JSON.parse(text);
242
+ } catch {
243
+ throw new GatewayVideoApiError(null, true, `${label} response is not JSON`);
244
+ }
245
+ const value = record(parsed);
246
+ if (!value) throw new GatewayVideoApiError(null, true, `${label} response is malformed`);
247
+ return value;
248
+ }
249
+
250
+ function requireSecret(value: string): void {
251
+ if (!value.trim()) throw new Error("AI Gateway video generation credential is empty");
252
+ }
253
+
254
+ function requireIdempotencyKey(value: string): void {
255
+ if (!/^ogvid_[0-9a-f]{48}$/u.test(value)) {
256
+ throw new Error("AI Gateway video idempotency key is invalid");
257
+ }
258
+ }
259
+
260
+ function requireHttps(value: string): string {
261
+ const url = new URL(value);
262
+ if (url.protocol !== "https:" || url.username || url.password || url.hash) {
263
+ throw new Error("Video reference grant must be an HTTPS bearer URL");
264
+ }
265
+ return url.toString();
266
+ }
267
+
268
+ function record(value: unknown): Record<string, unknown> | null {
269
+ return value && typeof value === "object" && !Array.isArray(value)
270
+ ? (value as Record<string, unknown>)
271
+ : null;
272
+ }
273
+
274
+ function stringValue(value: unknown): string | null {
275
+ return typeof value === "string" && value.trim() ? value : null;
276
+ }
277
+
278
+ function boundedError(value: string): string {
279
+ let message = value;
280
+ try {
281
+ const parsed = record(JSON.parse(value));
282
+ const error = record(parsed?.error);
283
+ message = stringValue(error?.message) ?? stringValue(parsed?.message) ?? value;
284
+ } catch {
285
+ // Preserve the already-bounded non-JSON diagnostic.
286
+ }
287
+ return message.replace(/\s+/gu, " ").trim().slice(0, 1_000);
288
+ }
289
+
290
+ function publicProviderReason(error: unknown, cancelled: boolean): string {
291
+ if (cancelled) return "The video provider cancelled the generation.";
292
+ const message =
293
+ typeof error === "string"
294
+ ? error
295
+ : (stringValue(record(error)?.message) ??
296
+ "The video provider could not complete the generation.");
297
+ return message.replace(/\s+/gu, " ").trim().slice(0, 1_000);
298
+ }