@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
@@ -1,6 +1,8 @@
1
- import { listLiveModalSandboxLeaseAttributions, readLease, type RetainedProcessProviderProof, type SandboxRetainedProcess, type LeaseSnapshot } from "@opengeni/db";
2
- import { createSandboxClientForBackend, inspectModalSandboxLifecycle, resolveModalCheckpointProviderBindingForSession, type ModalOrphanSweepTermination, type ModalCheckpointProviderBinding, type WorkspaceArchiveDescriptor } from "@opengeni/runtime";
3
- import type { ActivityServices } from "./types";
1
+ import { listLiveModalSandboxLeaseAttributions, readLease, type ReapDrainable, type RetainedProcessProviderProof, type SandboxRetainedProcess, type LeaseSnapshot } from "@opengeni/db";
2
+ import { createSandboxClientForBackend, inspectModalSandboxLifecycle, resolveModalCheckpointProviderBindingForSession, terminateModalSandboxById, type ModalOrphanSweepTermination, type ModalCheckpointProviderBinding, type ProviderWorkspaceCapturePolicy, type WorkspaceArchiveDescriptor } from "@opengeni/runtime/sandbox";
3
+ import { type SandboxDrainActivityInput, type SandboxLeaseSweepMaintenanceInput } from "../sandbox-reaper-contract.js";
4
+ import type { ControlActivityServices as ActivityServices } from "./types.js";
5
+ export { sandboxLeaseTelemetryKey } from "@opengeni/observability";
4
6
  export type ReapSandboxLeasesResult = {
5
7
  /** Stale viewer holders + warming-death rows the sweep touched is folded into
6
8
  * the DB pass; here we report the terminate outcomes. */
@@ -45,6 +47,7 @@ export type ProviderTerminationOutcome = {
45
47
  * already vanished before this drain could capture its workspace. */
46
48
  providerMissingBeforeCapture: boolean;
47
49
  };
50
+ export type DrainCaptureDisposition = "capture_required" | "archive_published";
48
51
  /** The provider-terminate seam. Production wires the real resume-by-id ->
49
52
  * persistWorkspace -> persist-onto-lease (epoch-fenced) -> snapshot-GC ->
50
53
  * provider stop() (`terminateProviderBox`); a unit test injects a spy so the
@@ -52,7 +55,7 @@ export type ProviderTerminationOutcome = {
52
55
  * Test seams may return the legacy boolean shorthand. Production returns the
53
56
  * typed outcome so the cold commit can distinguish a clean stop from definitive
54
57
  * provider disappearance before capture. */
55
- export type TerminateBoxFn = (settings: ActivityServices["settings"], lease: NonNullable<Awaited<ReturnType<typeof readLease>>>, observability: ActivityServices["observability"], persistArchive: PersistArchiveFn) => Promise<boolean | ProviderTerminationOutcome>;
58
+ export type TerminateBoxFn = (settings: ActivityServices["settings"], lease: NonNullable<Awaited<ReturnType<typeof readLease>>>, observability: ActivityServices["observability"], persistArchive: PersistArchiveFn, providerCaptureRequestId?: string, captureDisposition?: DrainCaptureDisposition, capturePolicy?: ProviderWorkspaceCapturePolicy | null) => Promise<boolean | ProviderTerminationOutcome>;
56
59
  export type SweepModalOrphansFn = (settings: ActivityServices["settings"], db: ActivityServices["db"], observability: ActivityServices["observability"]) => Promise<number>;
57
60
  export type SandboxLeaseActivityOptions = {
58
61
  /** Override the provider terminate (tests spy this; defaults to the real
@@ -88,7 +91,41 @@ export type DrainableProviderProbeFn = (settings: ActivityServices["settings"],
88
91
  export declare const RETAINED_PROCESS_RECONCILIATION_LIMIT = 20;
89
92
  export declare const RETAINED_PROCESS_RECONCILIATION_CLAIM_TTL_MS: number;
90
93
  export declare const RETAINED_PROCESS_PROVIDER_PROBE_TIMEOUT_MS = 5000;
94
+ export declare class SandboxProviderCaptureTimeoutError extends Error {
95
+ readonly sandboxGroupId: string;
96
+ readonly backend: string;
97
+ readonly timeoutMs: number;
98
+ readonly leaseEpoch: number;
99
+ readonly instanceId: string;
100
+ readonly name = "SandboxProviderCaptureTimeoutError";
101
+ constructor(sandboxGroupId: string, backend: string, timeoutMs: number, leaseEpoch: number, instanceId: string);
102
+ }
103
+ export type SandboxLeaseSweepPlan = {
104
+ drainable: ReapDrainable[];
105
+ timeoutClass: SandboxDrainActivityInput["timeoutClass"];
106
+ snapshotTimeoutMs: number;
107
+ captureTimeoutMs: number;
108
+ /** Deadline rotations admitted immediately before inventory, so zero-holder
109
+ * boxes enter the same sweep instead of paying another schedule period. */
110
+ rotationsRequested: number;
111
+ };
112
+ export type SandboxLeaseSweepMaintenanceResult = {
113
+ metered: number;
114
+ forceDrained: number;
115
+ rotationsRequested: number;
116
+ modalOrphansTerminated: number;
117
+ };
118
+ export type SandboxDrainActivityResult = {
119
+ status: "terminated" | "skipped";
120
+ };
121
+ /** Stable UUID per logical operation + Temporal attempt. Attempt one uses the
122
+ * operation id itself; later attempts are SHA-256-derived UUIDv5-shaped values.
123
+ * This makes the DB receipt idempotent even if an activity delivery is replayed. */
124
+ export declare function sandboxDrainCaptureId(operationId: string, attempt: number): string;
91
125
  export declare function createSandboxLeaseActivities(services: () => Promise<ActivityServices>, options?: SandboxLeaseActivityOptions): {
126
+ prepareSandboxLeaseSweep: () => Promise<SandboxLeaseSweepPlan>;
127
+ drainSandboxLease: (input: SandboxDrainActivityInput) => Promise<SandboxDrainActivityResult>;
128
+ maintainSandboxLeaseSweep: (input: SandboxLeaseSweepMaintenanceInput) => Promise<SandboxLeaseSweepMaintenanceResult>;
92
129
  reapSandboxLeases: () => Promise<ReapSandboxLeasesResult>;
93
130
  };
94
131
  export declare function probeRetainedProcessAtProvider(settings: ActivityServices["settings"], lease: LeaseSnapshot, process: SandboxRetainedProcess): Promise<RetainedProcessProbeResult>;
@@ -107,7 +144,7 @@ export declare function modalOrphanTerminationStillEligible(latest: Awaited<Retu
107
144
  * - persistArchive(base64) -> CAS-fold it onto the lease and atomically mark
108
145
  * the displaced artifact delete-pending;
109
146
  * - the provider-bound global GC deletes that object asynchronously;
110
- * - terminate the live handle (client.delete / session kill|terminate|close).
147
+ * - terminate the live handle through the standard Agents SDK lifecycle.
111
148
  *
112
149
  * Returns true when the box was terminated (or was already gone), false when the
113
150
  * persist CAS found the lease re-armed and the box was deliberately LEFT RUNNING.
@@ -121,8 +158,9 @@ export declare function modalOrphanTerminationStillEligible(latest: Awaited<Retu
121
158
  * BEFORE any terminate, so the box is NOT torn down with un-captured files;
122
159
  * the next sweep retries, and the provider idle-timeout is the ultimate
123
160
  * backstop. We never terminate a box whose snapshot we could not capture.
124
- * For a draining lease with no envelope (a warming-death row that committed no
125
- * box, or a 'none'-backed group) there is no live box — a no-op (return true).
161
+ * A provider-backed row with instance_id but no envelope is never guessed away:
162
+ * Modal has an explicit by-id rescue adapter above; every other backend stays
163
+ * draining until its adapter can prove termination. A truly instance-less or
164
+ * `none`-backed row is a no-op.
126
165
  */
127
- export declare function terminateProviderBox(settings: ActivityServices["settings"], lease: NonNullable<Awaited<ReturnType<typeof readLease>>>, observability: ActivityServices["observability"], persistArchive: PersistArchiveFn, createClientForBackend?: CreateSandboxClientForBackendFn): Promise<ProviderTerminationOutcome>;
128
- export {};
166
+ export declare function terminateProviderBox(settings: ActivityServices["settings"], lease: NonNullable<Awaited<ReturnType<typeof readLease>>>, observability: ActivityServices["observability"], persistArchive: PersistArchiveFn, createClientForBackend?: CreateSandboxClientForBackendFn, terminateModalById?: typeof terminateModalSandboxById, providerCaptureRequestId?: string, captureDisposition?: DrainCaptureDisposition, claimedCapturePolicy?: ProviderWorkspaceCapturePolicy | null): Promise<ProviderTerminationOutcome>;
@@ -1,4 +1,4 @@
1
- import type { ActivityServices, DispatchScheduledTaskRunInput, DispatchScheduledTaskRunResult } from "./types";
2
- export declare function createScheduledTaskActivities(services: () => Promise<ActivityServices>): {
1
+ import type { ControlActivityServices, DispatchScheduledTaskRunInput, DispatchScheduledTaskRunResult } from "./types.js";
2
+ export declare function createScheduledTaskActivities(services: () => Promise<ControlActivityServices>): {
3
3
  dispatchScheduledTaskRun: (input: DispatchScheduledTaskRunInput) => Promise<DispatchScheduledTaskRunResult>;
4
4
  };
@@ -1,8 +1,8 @@
1
1
  import { settleSessionAttemptInterruptions, applySessionTurnSettlement, requestSessionTurnRecovery, recoverSessionDispatch, reconcileSessionAttemptQuiescence, peekSessionWork as peekSessionWorkDb, countQueuedTurns, getSessionAttemptActivityRef, getSessionEvent, getSessionTurnForAttempt, expireSessionHumanInputRequest, markSessionAttemptQuiesced, requireSession, settleSessionIdleWithParentOutbox } from "@opengeni/db";
2
2
  import { publishDurableSessionEvents } from "@opengeni/events";
3
- import { deliverFailedChildTurnToParent, notifyParentOfChildIdle } from "./parent-wake";
4
- import { recordTurnsQueuedGauge } from "../observability-metrics";
5
- import type { ActivityServices, ExpireSessionHumanInputInput, ExpireSessionHumanInputResult, PeekSessionWorkInput, FailSessionAttemptInput, SettleSessionInterruptionsInput, MarkSessionIdleInput, PersistSessionAttemptQuiescenceInput, ReconcileSessionAttemptQuiescenceInput, ReconcileSessionAttemptQuiescenceResult, RecoverDispatchInput, RecoverDispatchResult, RecoverEscapedMcpTimeoutInput, RecoverEscapedMcpTimeoutResult } from "./types";
3
+ import { deliverFailedChildTurnToParent, notifyParentOfChildIdle } from "./parent-wake.js";
4
+ import { recordTurnsQueuedGauge } from "../observability-metrics.js";
5
+ import type { ControlActivityServices, ExpireSessionHumanInputInput, ExpireSessionHumanInputResult, PeekSessionWorkInput, FailSessionAttemptInput, SettleSessionInterruptionsInput, MarkSessionIdleInput, PersistSessionAttemptQuiescenceInput, ReconcileSessionAttemptQuiescenceInput, ReconcileSessionAttemptQuiescenceResult, RecoverDispatchInput, RecoverDispatchResult, RecoverEscapedMcpTimeoutInput, RecoverEscapedMcpTimeoutResult } from "./types.js";
6
6
  export type SessionStateActivityOverrides = Partial<{
7
7
  settleSessionAttemptInterruptions: typeof settleSessionAttemptInterruptions;
8
8
  applySessionTurnSettlement: typeof applySessionTurnSettlement;
@@ -24,7 +24,7 @@ export type SessionStateActivityOverrides = Partial<{
24
24
  recordTurnsQueuedGauge: typeof recordTurnsQueuedGauge;
25
25
  }>;
26
26
  export declare const WORKER_DEATH_MAX_REDISPATCHES = 3;
27
- export declare function createSessionStateActivities(services: () => Promise<ActivityServices>, overrides?: SessionStateActivityOverrides): {
27
+ export declare function createSessionStateActivities(services: () => Promise<ControlActivityServices>, overrides?: SessionStateActivityOverrides): {
28
28
  failSessionAttempt: (input: FailSessionAttemptInput) => Promise<void>;
29
29
  settleSessionInterruptions: (input: SettleSessionInterruptionsInput) => Promise<{
30
30
  action: "paused" | "continue" | "stale";
@@ -20,5 +20,5 @@ export declare function createRuntimeBatcher(flushEvents: (events: AppendEventIn
20
20
  flush: () => Promise<void>;
21
21
  };
22
22
  export declare function currentActivityContext(): Context | null;
23
- export declare function startActivityHeartbeat(context: Context | null, details: Record<string, unknown>): ReturnType<typeof setInterval> | null;
23
+ export declare function startActivityHeartbeat(context: Context | null, details: Record<string, unknown>, schedule?: typeof setInterval): ReturnType<typeof setInterval> | null;
24
24
  export declare function nextStreamEvent<T>(iterator: AsyncIterator<T>, context: Context | null): Promise<IteratorResult<T>>;
@@ -21,6 +21,16 @@ export type SignalCodexCapacityWorkflow = (input: {
21
21
  workflowId: string;
22
22
  wakeRevision: number;
23
23
  }) => Promise<void>;
24
+ /** Start the versioned, per-box sandbox reaper from the history-stable legacy
25
+ * activity. The legacy Schedule workflow must keep its exact historical
26
+ * ScheduleActivity command across mixed-version worker pools. */
27
+ export type StartSandboxReaperWorkflow = () => Promise<"started" | "already_running">;
28
+ /** Start-or-observe the one durable reconciler for a paid video operation. */
29
+ export type StartVideoGenerationWorkflow = (input: {
30
+ accountId: string;
31
+ workspaceId: string;
32
+ operationId: string;
33
+ }) => Promise<"started" | "already_running">;
24
34
  /** Exact activity-owned proof that the hard sandbox/tool fence physically
25
35
  * drained. This is delivery evidence only: the workflow still validates the
26
36
  * persisted attempt dispatch and commits the authoritative Postgres receipt. */
@@ -39,13 +49,13 @@ export type InspectSessionAttemptActivity = (input: {
39
49
  workflowRunId: string;
40
50
  activityId: string;
41
51
  }) => Promise<"pending" | "settled">;
42
- export type ActivityServices = {
52
+ /** Services shared by both Temporal worker roles. Keep this graph free of the
53
+ * agent runtime and document parser so each process can load only its role. */
54
+ export type SharedActivityServices = {
43
55
  settings: Settings;
44
56
  db: Database;
45
57
  bus: EventBus;
46
- runtime: OpenGeniRuntime;
47
58
  objectStorage: ObjectStorage | null;
48
- documentServices: DocumentServices;
49
59
  observability: Observability;
50
60
  wakeSessionWorkflow: WakeSessionWorkflowSignal | null;
51
61
  /** Durable signalWithStart fallback used only after the activity's direct
@@ -56,9 +66,26 @@ export type ActivityServices = {
56
66
  inspectSessionAttemptActivity: InspectSessionAttemptActivity | null;
57
67
  /** Revision-carrying capacity nudge; generic outbox repair is also sufficient. */
58
68
  signalCodexCapacityWorkflow?: SignalCodexCapacityWorkflow | null;
69
+ /** Production control workers inject this Temporal client edge. A null edge
70
+ * deliberately retains the composite implementation for embedded/test hosts. */
71
+ startSandboxReaperWorkflow?: StartSandboxReaperWorkflow | null;
72
+ startVideoGenerationWorkflow?: StartVideoGenerationWorkflow | null;
59
73
  entitlements?: EntitlementsPort | null;
60
74
  connectionCredentials?: ConnectionCredentialsPort | null;
61
75
  };
76
+ /** Control workers own short database and maintenance activities. Document
77
+ * parsing is resolved lazily by the indexing activity itself. */
78
+ export type ControlActivityServices = SharedActivityServices;
79
+ /** Turn workers own the model loop and never construct document parsers. */
80
+ export type TurnActivityServices = SharedActivityServices & {
81
+ runtime: OpenGeniRuntime;
82
+ /** Provider-free test/profiling seam; production injects the real runtime summarizer. */
83
+ summarizeContextForCompaction: typeof import("@opengeni/runtime").summarizeForCompaction;
84
+ };
85
+ /** Full test/embedded harness retained as a source-compatible superset. */
86
+ export type ActivityServices = ControlActivityServices & TurnActivityServices & {
87
+ documentServices: DocumentServices;
88
+ };
62
89
  export type CodexCapacityWaitRef = {
63
90
  waiterId: string;
64
91
  generation: number;
@@ -83,6 +110,8 @@ export type ReconcileCodexCapacityWaitResult = ({
83
110
  action: "resumed" | "paused" | "superseded" | "stale";
84
111
  };
85
112
  export type ActivityDependencies = Partial<ActivityServices>;
113
+ export type ControlActivityDependencies = Partial<ControlActivityServices>;
114
+ export type TurnActivityDependencies = Partial<TurnActivityServices>;
86
115
  export type RunAgentTurnInput = {
87
116
  accountId: string;
88
117
  workspaceId: string;
@@ -97,6 +126,14 @@ export type RunAgentTurnInput = {
97
126
  triggerEventId: string;
98
127
  };
99
128
  };
129
+ export type VideoGenerationTerminalStatus = "completed" | "provider_failed" | "cancelled_before_submit" | "outcome_unknown" | "retention_failed";
130
+ export type VideoGenerationReconcileResult = {
131
+ action: "waiting";
132
+ delayMs: number;
133
+ } | {
134
+ action: "terminal";
135
+ status: VideoGenerationTerminalStatus;
136
+ };
100
137
  export type SettleSessionInterruptionsInput = {
101
138
  accountId: string;
102
139
  workspaceId: string;
@@ -200,7 +237,7 @@ export type DispatchScheduledTaskRunInput = {
200
237
  agentRunUsageIdempotencyKey?: never;
201
238
  initiator?: never;
202
239
  } | {
203
- triggerType: Extract<ScheduledTaskTriggerType, "manual">;
240
+ triggerType: Extract<ScheduledTaskTriggerType, "manual" | "initial" | "provider_event" | "retry" | "repair">;
204
241
  agentRunUsageIdempotencyKey: string;
205
242
  /** Exact identity used by the API-side charge for this same trigger. */
206
243
  initiator: TurnInitiator;
@@ -209,7 +246,7 @@ export type DispatchScheduledTaskRunResult = {
209
246
  action: "deleted";
210
247
  } | {
211
248
  action: "blocked";
212
- reason: "insufficient_credits" | "monthly_model_cost_limit" | "monthly_agent_run_limit" | "malformed_manual_trigger";
249
+ reason: "insufficient_credits" | "monthly_model_cost_limit" | "monthly_agent_run_limit" | "malformed_manual_trigger" | "knowledge_source_paused";
213
250
  } | {
214
251
  action: "start" | "signal";
215
252
  accountId: string;
@@ -218,6 +255,35 @@ export type DispatchScheduledTaskRunResult = {
218
255
  triggerEventId: string;
219
256
  workflowId: string;
220
257
  workflowWakeRevision: number | null;
258
+ } | {
259
+ action: "knowledge_source_sync";
260
+ accountId: string;
261
+ workspaceId: string;
262
+ taskId: string;
263
+ scheduledTaskRunId: string;
264
+ sourceId: string;
265
+ overlapPolicy: "skip" | "buffer_one";
266
+ };
267
+ export type RunKnowledgeSourceSyncBatchInput = {
268
+ accountId: string;
269
+ workspaceId: string;
270
+ taskId: string;
271
+ scheduledTaskRunId: string;
272
+ sourceId: string;
273
+ overlapPolicy: "skip" | "buffer_one";
274
+ };
275
+ export type RunKnowledgeSourceSyncBatchResult = {
276
+ action: "continue";
277
+ } | {
278
+ action: "complete";
279
+ bufferedWake: boolean;
280
+ bufferedScheduledTaskRunId?: string | null;
281
+ } | {
282
+ action: "skipped" | "buffered";
283
+ } | {
284
+ action: "failed";
285
+ bufferedWake: boolean;
286
+ bufferedScheduledTaskRunId?: string | null;
221
287
  };
222
288
  type DocumentIndexIdentity = {
223
289
  accountId: string;
@@ -0,0 +1,38 @@
1
+ import { VideoGenerationAcceptedReceipt, type GenerateVideoToolInput, type VideoGenerationCapabilities, type VideoGenerationPolicy } from "@opengeni/contracts";
2
+ import { type Database } from "@opengeni/db";
3
+ import { type Settings } from "@opengeni/config";
4
+ import type { ObjectStorage } from "@opengeni/storage";
5
+ import { type SandboxCommandRunner } from "./video-reference-staging.js";
6
+ export type VideoGenerationCredentialLease = Readonly<{
7
+ fundingSource: "opengeni_credits" | "workspace_gateway";
8
+ connectionId: string | null;
9
+ version: number;
10
+ credentialEncrypted: string;
11
+ apiKey: string;
12
+ }>;
13
+ export type AcceptedVideoGeneration = Readonly<{
14
+ receipt: ReturnType<typeof VideoGenerationAcceptedReceipt.parse>;
15
+ operationId: string;
16
+ requestDigest: string;
17
+ }>;
18
+ export declare function videoCapabilitiesForTurn(input: {
19
+ policy: VideoGenerationPolicy;
20
+ credential: VideoGenerationCredentialLease;
21
+ }): VideoGenerationCapabilities;
22
+ export declare function managedVideoGenerationCredentialLease(settings: Settings): VideoGenerationCredentialLease | null;
23
+ export declare function admitVideoGenerationRequest(input: {
24
+ db: Database;
25
+ storage: ObjectStorage;
26
+ settings: Settings;
27
+ accountId: string;
28
+ workspaceId: string;
29
+ sessionId: string;
30
+ turnId: string;
31
+ attemptId: string;
32
+ toolCallId: string;
33
+ toolInput: GenerateVideoToolInput;
34
+ policy: VideoGenerationPolicy;
35
+ credential: VideoGenerationCredentialLease;
36
+ runCommand?: SandboxCommandRunner;
37
+ signal?: AbortSignal;
38
+ }): Promise<AcceptedVideoGeneration>;
@@ -0,0 +1,7 @@
1
+ /** One frozen, provider-neutral credential envelope for every video funding route. */
2
+ export declare function encryptVideoGenerationApiKey(key: Uint8Array, apiKey: string): string;
3
+ /**
4
+ * Decrypt without ever attaching parser/decryption errors: JSON parser errors
5
+ * may quote plaintext and must not enter Temporal failure payloads or logs.
6
+ */
7
+ export declare function decryptVideoGenerationApiKey(key: Uint8Array, stored: string): string;
@@ -0,0 +1,13 @@
1
+ import type { TurnActivityServices, VideoGenerationReconcileResult } from "./types.js";
2
+ export declare function createVideoGenerationActivities(services: () => Promise<TurnActivityServices>): {
3
+ reconcileVideoGenerationOperation: (input: {
4
+ accountId: string;
5
+ workspaceId: string;
6
+ operationId: string;
7
+ }) => Promise<VideoGenerationReconcileResult>;
8
+ };
9
+ export declare function reconcileVideoGenerationOperation(service: TurnActivityServices, input: {
10
+ accountId: string;
11
+ workspaceId: string;
12
+ operationId: string;
13
+ }): Promise<VideoGenerationReconcileResult>;
@@ -0,0 +1,34 @@
1
+ import type { GeneratedVideoFacts } from "@opengeni/contracts";
2
+ import type { ObjectStorage } from "@opengeni/storage";
3
+ export type VerifiedTempFile = Readonly<{
4
+ directory: string;
5
+ path: string;
6
+ sizeBytes: number;
7
+ sha256: string;
8
+ contentType: string;
9
+ cleanup: () => Promise<void>;
10
+ }>;
11
+ export declare function copyVersionedObjectToVerifiedTemp(input: {
12
+ storage: ObjectStorage;
13
+ key: string;
14
+ expectedSizeBytes: number;
15
+ expectedSha256: string;
16
+ expectedContentType: string;
17
+ maxBytes: number;
18
+ tempRoot: string;
19
+ signal?: AbortSignal;
20
+ }): Promise<VerifiedTempFile>;
21
+ export declare function validateImageReference(path: string): Promise<{
22
+ contentType: "image/jpeg" | "image/png" | "image/webp";
23
+ width: number;
24
+ height: number;
25
+ }>;
26
+ export declare function validateGeneratedVideo(input: {
27
+ path: string;
28
+ ffprobePath: string;
29
+ expectedDurationSeconds?: number;
30
+ }): Promise<GeneratedVideoFacts>;
31
+ export declare function validateVideoReference(input: {
32
+ path: string;
33
+ ffprobePath: string;
34
+ }): Promise<GeneratedVideoFacts>;
@@ -0,0 +1,36 @@
1
+ import type { Settings } from "@opengeni/config";
2
+ import { type GeneratedVideoFacts } from "@opengeni/contracts";
3
+ import { type FetchLike } from "@opengeni/network";
4
+ import type { ObjectStorage } from "@opengeni/storage";
5
+ import { type VerifiedTempFile } from "./video-media-validation.js";
6
+ export type RetainedGeneratedVideo = Readonly<{
7
+ bucket: string;
8
+ objectKey: string;
9
+ sizeBytes: number;
10
+ sha256: string;
11
+ facts: GeneratedVideoFacts;
12
+ }>;
13
+ /**
14
+ * Treat the provider's result URL and bytes as hostile. DNS is pinned, every
15
+ * redirect is revalidated, and the body streams to a private temporary file
16
+ * under hard time/size limits before ffprobe sees it.
17
+ */
18
+ export declare function downloadGeneratedVideoToVerifiedTemp(input: {
19
+ url: string;
20
+ mediaType: string;
21
+ settings: Settings;
22
+ expectedDurationSeconds: number;
23
+ fetch?: FetchLike;
24
+ signal?: AbortSignal;
25
+ }): Promise<{
26
+ temp: VerifiedTempFile;
27
+ facts: GeneratedVideoFacts;
28
+ }>;
29
+ /** Stream verified bytes into an immutable content-addressed object and hash
30
+ * the stored generation back through version-fenced Range reads. */
31
+ export declare function retainVerifiedGeneratedVideo(input: {
32
+ storage: ObjectStorage;
33
+ temp: VerifiedTempFile;
34
+ facts: GeneratedVideoFacts;
35
+ signal?: AbortSignal;
36
+ }): Promise<RetainedGeneratedVideo>;
@@ -0,0 +1,49 @@
1
+ import { type GenerateVideoToolInput } from "@opengeni/contracts";
2
+ import type { SealedVideoReference, SealedVideoReferenceRole } from "@opengeni/core";
3
+ import type { ObjectStorage } from "@opengeni/storage";
4
+ export type SandboxCommandRunner = (input: {
5
+ cmd: string;
6
+ workdir: string;
7
+ maxOutputTokens: number;
8
+ }) => Promise<{
9
+ stdout: string;
10
+ stderr: string;
11
+ exitCode: number;
12
+ }>;
13
+ export type InspectedSandboxVideoReference = Readonly<{
14
+ ordinal: number;
15
+ role: SealedVideoReferenceRole;
16
+ path: string;
17
+ contentType: string;
18
+ sizeBytes: number;
19
+ sha256: string;
20
+ }>;
21
+ export declare function videoReferencePaths(request: GenerateVideoToolInput): Array<{
22
+ role: SealedVideoReferenceRole;
23
+ path: string;
24
+ }>;
25
+ export declare function inspectSandboxVideoReferences(input: {
26
+ request: GenerateVideoToolInput;
27
+ runCommand: SandboxCommandRunner;
28
+ }): Promise<InspectedSandboxVideoReference[]>;
29
+ export declare function uploadAndVerifyVideoReferences(input: {
30
+ storage: ObjectStorage;
31
+ references: readonly InspectedSandboxVideoReference[];
32
+ stagingKeys: readonly string[];
33
+ runCommand: SandboxCommandRunner;
34
+ tempRoot: string;
35
+ ffprobePath: string;
36
+ uploadTtlSeconds: number;
37
+ signal?: AbortSignal;
38
+ }): Promise<SealedVideoReference[]>;
39
+ export declare function videoReferenceStagingKey(input: {
40
+ workspaceId: string;
41
+ operationId: string;
42
+ ordinal: number;
43
+ sha256: string;
44
+ }): string;
45
+ export declare const VIDEO_REFERENCE_LIMITS: Readonly<{
46
+ imageBytes: number;
47
+ videoBytes: number;
48
+ outputBytes: number;
49
+ }>;
@@ -1,4 +1,4 @@
1
- import type { ActivityServices } from "./types";
1
+ import type { ControlActivityServices } from "./types.js";
2
2
  export type DispatchSessionWorkflowWakesResult = {
3
3
  claimed: number;
4
4
  delivered: number;
@@ -10,6 +10,6 @@ export type DispatchSessionWorkflowWakesResult = {
10
10
  * acknowledgement path used by immediate delivery. This is a repair path, not
11
11
  * an eligibility scan: producers have already decided what must be delivered.
12
12
  */
13
- export declare function createWorkflowWakeActivities(services: () => Promise<ActivityServices>): {
13
+ export declare function createWorkflowWakeActivities(services: () => Promise<ControlActivityServices>): {
14
14
  dispatchSessionWorkflowWakes(): Promise<DispatchSessionWorkflowWakesResult>;
15
15
  };
@@ -3,7 +3,7 @@ import type { Database } from "@opengeni/db";
3
3
  import type { ObjectStorage } from "@opengeni/storage";
4
4
  import type { Observability } from "@opengeni/observability";
5
5
  import { SandboxChannelAService, type ChannelASession } from "@opengeni/runtime/sandbox";
6
- import type { SessionEvent } from "@opengeni/contracts";
6
+ import type { SessionEvent, WorkspaceCaptureFile, WorkspaceCaptureRepo } from "@opengeni/contracts";
7
7
  export declare const CAPTURE_TIMEOUT_MS = 120000;
8
8
  export declare const PER_FILE_CONTENT_GUARD_BYTES: number;
9
9
  export declare const PER_FILE_DIFF_GUARD_BYTES: number;
@@ -99,6 +99,15 @@ export declare function readCaptureRepository(svc: Pick<SandboxChannelAService,
99
99
  * to release() regardless.
100
100
  */
101
101
  export declare function captureWorkspaceRevision(input: CaptureWorkspaceRevisionInput): Promise<void>;
102
+ /**
103
+ * sha256 over the CHANGE SURFACE only — per-file (path, status, hash, deleted,
104
+ * tooLarge), exact HEAD identity, the working diff summary, and exact committed
105
+ * branch changes.
106
+ * Deliberately excludes the tree index and file mtimes (which drift without a
107
+ * real change) so two turns that leave the workspace in the same state produce
108
+ * the same fingerprint (the empty-turn gate). Order-independent (sorted).
109
+ */
110
+ export declare function changeFingerprint(repos: WorkspaceCaptureRepo[], files: WorkspaceCaptureFile[]): string;
102
111
  /** Join a repo-root-relative path onto its workspace-relative repo root. */
103
112
  export declare function joinRepoPath(repoRoot: string, repoRelPath: string): string;
104
113
  /** Content-addressed after-image blob key (shared across revisions → GC input). */