@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.
Files changed (180) hide show
  1. package/dist/activities/agent-turn.d.ts +145 -32
  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 +3 -0
  8. package/dist/activities/documents.d.ts +3 -2
  9. package/dist/activities/environment.d.ts +11 -7
  10. package/dist/activities/expiring-material-renewal.d.ts +5 -3
  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 +2 -2
  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 +32 -0
  25. package/dist/activities/retained-screenshots.d.ts +129 -0
  26. package/dist/activities/rig-verification.d.ts +82 -5
  27. package/dist/activities/run-credential-renewal.d.ts +2 -2
  28. package/dist/activities/run-input.d.ts +5 -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 +11 -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 -147
  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/{chunk-BJUW5LCM.js → chunk-RAMNYSAW.js} +15 -12
  64. package/dist/chunk-RAMNYSAW.js.map +1 -0
  65. package/dist/concurrency.d.ts +108 -5
  66. package/dist/editable-artifact-hint-broker.d.ts +49 -0
  67. package/dist/editable-artifact-materializer-launcher.d.ts +49 -0
  68. package/dist/editable-artifact-materializer-service.d.ts +108 -0
  69. package/dist/editable-artifact-materializer-storage.d.ts +12 -0
  70. package/dist/editable-artifact-materializer-subprocess.d.ts +50 -0
  71. package/dist/editable-artifact-materializer.d.ts +262 -0
  72. package/dist/editable-artifact-outbox-dispatcher.d.ts +44 -0
  73. package/dist/editable-artifact-outbox-service.d.ts +70 -0
  74. package/dist/host-export.d.ts +1 -1
  75. package/dist/host-export.js +1 -1
  76. package/dist/index.d.ts +176 -10
  77. package/dist/index.js +675 -16460
  78. package/dist/index.js.map +1 -1
  79. package/dist/memory-pressure-guard.d.ts +57 -0
  80. package/dist/model-checkpoint-memory-collector.d.ts +22 -0
  81. package/dist/observability-metrics.d.ts +33 -0
  82. package/dist/sandbox-reaper-contract.d.ts +40 -0
  83. package/dist/sandbox-reaper-timeout.d.ts +14 -0
  84. package/dist/sandbox-resume.d.ts +40 -7
  85. package/dist/sandbox-routing.d.ts +13 -6
  86. package/dist/worker-service-lifecycle.d.ts +6 -2
  87. package/dist/workflow-bundle.js +1044 -363
  88. package/dist/workflows/activities.d.ts +7 -1
  89. package/dist/workflows/document-index.d.ts +1 -1
  90. package/dist/workflows/knowledge-source-sync.d.ts +13 -0
  91. package/dist/workflows/rig-verification.d.ts +1 -1
  92. package/dist/workflows/sandbox-reaper.d.ts +8 -0
  93. package/dist/workflows/scheduled-tasks.d.ts +1 -1
  94. package/dist/workflows/session.d.ts +2 -2
  95. package/dist/workflows/video-generation.d.ts +10 -0
  96. package/dist/workflows/workflow-wake.d.ts +1 -1
  97. package/dist/workflows.d.ts +9 -7
  98. package/package.json +34 -15
  99. package/src/activities/agent-turn.ts +1905 -559
  100. package/src/activities/api-integrations.ts +138 -0
  101. package/src/activities/codemode-dispatcher.ts +335 -0
  102. package/src/activities/codemode-token-renewal.ts +64 -0
  103. package/src/activities/codex-capacity.ts +16 -7
  104. package/src/activities/codex-image-generation.ts +56 -0
  105. package/src/activities/codex-rotation.ts +19 -5
  106. package/src/activities/context-compaction.ts +47 -6
  107. package/src/activities/documents.ts +14 -4
  108. package/src/activities/environment.ts +52 -60
  109. package/src/activities/expiring-material-renewal.ts +16 -7
  110. package/src/activities/file-upload-reaper.ts +34 -3
  111. package/src/activities/gateway-image-generation.ts +146 -0
  112. package/src/activities/gateway-video-generation.ts +298 -0
  113. package/src/activities/generated-images.ts +860 -0
  114. package/src/activities/git-credential-renewal.ts +3 -3
  115. package/src/activities/goals.ts +6 -2
  116. package/src/activities/google-drive-changes.ts +454 -0
  117. package/src/activities/image-generation-operation.ts +333 -0
  118. package/src/activities/image-generation-references.ts +118 -0
  119. package/src/activities/knowledge-source-sync-driver.ts +27 -0
  120. package/src/activities/knowledge-source-sync.ts +2840 -0
  121. package/src/activities/mcp-credentials.ts +1 -0
  122. package/src/activities/packs.ts +55 -55
  123. package/src/activities/recording.ts +4 -5
  124. package/src/activities/retained-screenshot-reaper.ts +202 -0
  125. package/src/activities/retained-screenshots.ts +1317 -0
  126. package/src/activities/rig-verification.ts +567 -77
  127. package/src/activities/run-credential-renewal.ts +9 -2
  128. package/src/activities/run-input.ts +40 -10
  129. package/src/activities/sandbox-images.ts +167 -0
  130. package/src/activities/sandbox-lease.ts +1065 -483
  131. package/src/activities/scheduled-tasks.ts +96 -7
  132. package/src/activities/session-state.ts +4 -4
  133. package/src/activities/streaming.ts +42 -3
  134. package/src/activities/types.ts +87 -5
  135. package/src/activities/video-generation-admission.ts +270 -0
  136. package/src/activities/video-generation-credential.ts +34 -0
  137. package/src/activities/video-generation-reconciliation.ts +578 -0
  138. package/src/activities/video-media-validation.ts +326 -0
  139. package/src/activities/video-output-retention.ts +314 -0
  140. package/src/activities/video-reference-staging.ts +263 -0
  141. package/src/activities/workflow-wake.ts +2 -2
  142. package/src/activities/workspace-capture.ts +77 -13
  143. package/src/activities-control.ts +54 -0
  144. package/src/activities-turn.ts +40 -0
  145. package/src/activities.ts +50 -118
  146. package/src/activity-services.ts +62 -0
  147. package/src/artifact-materializer-entry.ts +35 -0
  148. package/src/artifact-outbox-entry.ts +29 -0
  149. package/src/concurrency.ts +484 -6
  150. package/src/editable-artifact-hint-broker.ts +235 -0
  151. package/src/editable-artifact-materializer-launcher.ts +515 -0
  152. package/src/editable-artifact-materializer-service.ts +787 -0
  153. package/src/editable-artifact-materializer-storage.ts +413 -0
  154. package/src/editable-artifact-materializer-subprocess.ts +956 -0
  155. package/src/editable-artifact-materializer.ts +1289 -0
  156. package/src/editable-artifact-outbox-dispatcher.ts +244 -0
  157. package/src/editable-artifact-outbox-service.ts +438 -0
  158. package/src/host-export-pump.ts +28 -11
  159. package/src/http.ts +3 -6
  160. package/src/index.ts +277 -72
  161. package/src/memory-pressure-guard.ts +489 -0
  162. package/src/model-checkpoint-memory-collector.ts +116 -0
  163. package/src/observability-metrics.ts +202 -7
  164. package/src/sandbox-reaper-contract.ts +73 -0
  165. package/src/sandbox-reaper-timeout.ts +79 -0
  166. package/src/sandbox-resume.ts +331 -157
  167. package/src/sandbox-routing.ts +49 -39
  168. package/src/worker-service-lifecycle.ts +82 -12
  169. package/src/workflows/activities.ts +30 -0
  170. package/src/workflows/file-upload-reaper.ts +6 -1
  171. package/src/workflows/knowledge-source-sync.ts +83 -0
  172. package/src/workflows/sandbox-reaper.ts +183 -21
  173. package/src/workflows/scheduled-tasks.ts +42 -6
  174. package/src/workflows/video-generation.ts +36 -0
  175. package/src/workflows.ts +17 -1
  176. package/dist/activities/redaction.d.ts +0 -1
  177. package/dist/activities/toolspace-token-renewal.d.ts +0 -23
  178. package/dist/chunk-BJUW5LCM.js.map +0 -1
  179. package/src/activities/redaction.ts +0 -9
  180. package/src/activities/toolspace-token-renewal.ts +0 -57
@@ -1,28 +1,190 @@
1
- // apps/worker/src/workflows/sandbox-reaper.ts — the ONE global reaper workflow.
2
- //
3
- // This is the action the single global reaper Temporal Schedule starts
4
- // (registered in apps/worker/src/index.ts, gated on sandboxOwnershipEnabled). It
5
- // runs on the global task queue — the SAME queue the worker pool listens on,
6
- // because the worker carries the runtime needed to resume-by-id and terminate a
7
- // provider box. There is NO per-session worker, NO per-session/per-group queue.
8
- //
9
- // The workflow is intentionally trivial: it delegates the whole sweep to the
10
- // stateless `reapSandboxLeases` activity (the sweep is DB + provider IO that
11
- // must run in an activity, not in workflow-deterministic code). The Schedule's
12
- // SKIP overlap policy means a slow sweep never overlaps itself; the activity is
13
- // idempotent regardless.
14
-
15
- import { proxyActivities } from "@temporalio/workflow";
1
+ // The global schedule performs only bounded inventory/maintenance work and
2
+ // starts one durable child per exact (workspace, group, epoch). Provider I/O is
3
+ // therefore parallel at the Temporal worker's activity-concurrency limit; one
4
+ // slow snapshot can delay only its own box, never the global reaper or a sibling.
5
+
6
+ import {
7
+ ParentClosePolicy,
8
+ WorkflowIdReusePolicy,
9
+ log,
10
+ proxyActivities,
11
+ startChild,
12
+ uuid4,
13
+ workflowInfo,
14
+ } from "@temporalio/workflow";
16
15
  import type * as activities from "../activities";
16
+ import {
17
+ SANDBOX_DRAIN_EXTENDED_ACTIVITY_TIMEOUT_MS,
18
+ SANDBOX_DRAIN_FAST_ACTIVITY_TIMEOUT_MS,
19
+ SANDBOX_REAPER_ACTIVITY_HEARTBEAT_TIMEOUT_MS,
20
+ SANDBOX_REAPER_MAINTENANCE_WORKFLOW_ID,
21
+ SANDBOX_REAPER_SCAN_ACTIVITY_TIMEOUT_MS,
22
+ sandboxDrainWorkflowId,
23
+ sandboxLifecycleTaskQueue,
24
+ type SandboxDrainActivityInput,
25
+ type SandboxDrainWorkflowInput,
26
+ type SandboxLeaseSweepMaintenanceInput,
27
+ } from "../sandbox-reaper-contract";
28
+
29
+ function lifecycleTaskQueue(): string {
30
+ return sandboxLifecycleTaskQueue(workflowInfo().taskQueue);
31
+ }
32
+
33
+ function sweepActivities() {
34
+ return proxyActivities<Pick<typeof activities, "prepareSandboxLeaseSweep">>({
35
+ taskQueue: lifecycleTaskQueue(),
36
+ startToCloseTimeout: SANDBOX_REAPER_SCAN_ACTIVITY_TIMEOUT_MS,
37
+ heartbeatTimeout: SANDBOX_REAPER_ACTIVITY_HEARTBEAT_TIMEOUT_MS,
38
+ // Inventory is the admission edge for every per-box child. A worker crash
39
+ // must not silently consume the only scheduled sweep.
40
+ retry: {
41
+ initialInterval: "1 second",
42
+ backoffCoefficient: 2,
43
+ maximumInterval: "30 seconds",
44
+ },
45
+ });
46
+ }
47
+
48
+ function maintenanceActivity() {
49
+ return proxyActivities<Pick<typeof activities, "maintainSandboxLeaseSweep">>({
50
+ taskQueue: lifecycleTaskQueue(),
51
+ startToCloseTimeout: SANDBOX_REAPER_SCAN_ACTIVITY_TIMEOUT_MS,
52
+ heartbeatTimeout: SANDBOX_REAPER_ACTIVITY_HEARTBEAT_TIMEOUT_MS,
53
+ // Maintenance is ancillary and internally exact/idempotent. Never let one
54
+ // pathological pass keep the fixed-id V2 workflow open forever and thereby
55
+ // suppress all later drain inventories. The next Schedule tick retries it.
56
+ retry: { maximumAttempts: 1 },
57
+ });
58
+ }
59
+
60
+ function drainActivity(startToCloseTimeout: number) {
61
+ return proxyActivities<Pick<typeof activities, "drainSandboxLease">>({
62
+ taskQueue: lifecycleTaskQueue(),
63
+ startToCloseTimeout,
64
+ heartbeatTimeout: SANDBOX_REAPER_ACTIVITY_HEARTBEAT_TIMEOUT_MS,
65
+ // Each retry is a new exact DB capture attempt under one logical operation.
66
+ // Heartbeat timeout moves a crashed worker to a healthy poller promptly;
67
+ // exact-attempt CAS fencing makes late callbacks harmless.
68
+ retry: {
69
+ initialInterval: "1 second",
70
+ backoffCoefficient: 2,
71
+ maximumInterval: "30 seconds",
72
+ },
73
+ });
74
+ }
17
75
 
18
- // A short, bounded reaper activity. Unlike the 30-day agent turn, the sweep is a
19
- // fast DB pass + a handful of provider terminates; cap it well under the reaper
20
- // period so a wedged sweep is abandoned rather than blocking the next fire.
21
- const reaperActivity = proxyActivities<Pick<typeof activities, "reapSandboxLeases">>({
22
- startToCloseTimeout: "5 minutes",
76
+ // This proxy and workflow deliberately preserve the exact pre-refactor
77
+ // ScheduleActivity command. A patch marker would let a new binary replay old
78
+ // histories, but an old binary could not replay a history first executed by a
79
+ // new worker during a rolling deployment. Routing happens inside the activity,
80
+ // where changing implementation is safe and mixed old/new workers remain valid.
81
+ const legacyReaperActivity = proxyActivities<Pick<typeof activities, "reapSandboxLeases">>({
82
+ startToCloseTimeout: SANDBOX_DRAIN_EXTENDED_ACTIVITY_TIMEOUT_MS,
23
83
  retry: { maximumAttempts: 1 },
24
84
  });
25
85
 
86
+ export async function sandboxDrainWorkflow(input: SandboxDrainWorkflowInput): Promise<void> {
87
+ const activityInput: SandboxDrainActivityInput = {
88
+ ...input,
89
+ operationId: uuid4(),
90
+ };
91
+ if (input.timeoutClass === "fast") {
92
+ await drainActivity(SANDBOX_DRAIN_FAST_ACTIVITY_TIMEOUT_MS).drainSandboxLease(activityInput);
93
+ } else {
94
+ await drainActivity(SANDBOX_DRAIN_EXTENDED_ACTIVITY_TIMEOUT_MS).drainSandboxLease(
95
+ activityInput,
96
+ );
97
+ }
98
+ }
99
+
100
+ /** Ancillary billing/reconciliation/GC is durable but never allowed to hold the
101
+ * fixed-ID inventory workflow open behind a provider backlog. One singleton
102
+ * maintenance child may queue on the lifecycle workers while every schedule
103
+ * tick remains free to inventory and dispatch newly-drainable boxes. */
104
+ export async function sandboxReaperMaintenanceWorkflow(
105
+ input: SandboxLeaseSweepMaintenanceInput,
106
+ ): Promise<void> {
107
+ try {
108
+ await maintenanceActivity().maintainSandboxLeaseSweep(input);
109
+ } catch (error) {
110
+ // The next Schedule tick starts another singleton after this run closes.
111
+ // Drain children were already made durable before this workflow was started.
112
+ log.warn("sandbox reaper maintenance deferred to a later sweep", {
113
+ error: error instanceof Error ? error.message : String(error),
114
+ });
115
+ }
116
+ }
117
+
118
+ function alreadyRunningChild(error: unknown): boolean {
119
+ let current: unknown = error;
120
+ for (let depth = 0; depth < 4 && current && typeof current === "object"; depth += 1) {
121
+ const record = current as { name?: unknown; cause?: unknown };
122
+ if (record.name === "WorkflowExecutionAlreadyStartedError") return true;
123
+ current = record.cause;
124
+ }
125
+ return false;
126
+ }
127
+
26
128
  export async function sandboxReaperWorkflow(): Promise<void> {
27
- await reaperActivity.reapSandboxLeases();
129
+ await legacyReaperActivity.reapSandboxLeases();
130
+ }
131
+
132
+ export async function sandboxReaperWorkflowV2(): Promise<void> {
133
+ const sweep = sweepActivities();
134
+ const plan = await sweep.prepareSandboxLeaseSweep();
135
+ const starts = await Promise.all(
136
+ plan.drainable.map(async (target) => {
137
+ try {
138
+ await startChild(sandboxDrainWorkflow, {
139
+ workflowId: sandboxDrainWorkflowId(target),
140
+ taskQueue: lifecycleTaskQueue(),
141
+ workflowIdReusePolicy: WorkflowIdReusePolicy.ALLOW_DUPLICATE,
142
+ parentClosePolicy: ParentClosePolicy.ABANDON,
143
+ args: [
144
+ {
145
+ target,
146
+ timeoutClass: plan.timeoutClass,
147
+ snapshotTimeoutMs: plan.snapshotTimeoutMs,
148
+ captureTimeoutMs: plan.captureTimeoutMs,
149
+ },
150
+ ],
151
+ });
152
+ return "started" as const;
153
+ } catch (error) {
154
+ if (alreadyRunningChild(error)) return "already_running" as const;
155
+ log.error("sandbox reaper child start failed", {
156
+ workspaceId: target.workspaceId,
157
+ sandboxGroupId: target.sandboxGroupId,
158
+ leaseEpoch: target.leaseEpoch,
159
+ instanceId: target.instanceId,
160
+ error: error instanceof Error ? error.message : String(error),
161
+ });
162
+ return "failed" as const;
163
+ }
164
+ }),
165
+ );
166
+ try {
167
+ await startChild(sandboxReaperMaintenanceWorkflow, {
168
+ workflowId: SANDBOX_REAPER_MAINTENANCE_WORKFLOW_ID,
169
+ taskQueue: lifecycleTaskQueue(),
170
+ workflowIdReusePolicy: WorkflowIdReusePolicy.ALLOW_DUPLICATE,
171
+ parentClosePolicy: ParentClosePolicy.ABANDON,
172
+ args: [
173
+ {
174
+ examined: plan.drainable.length,
175
+ started: starts.filter((outcome) => outcome === "started").length,
176
+ alreadyRunning: starts.filter((outcome) => outcome === "already_running").length,
177
+ startFailed: starts.filter((outcome) => outcome === "failed").length,
178
+ rotationsRequested: plan.rotationsRequested,
179
+ },
180
+ ],
181
+ });
182
+ } catch (error) {
183
+ if (alreadyRunningChild(error)) return;
184
+ // Every drain child is already durable and this inventory workflow still
185
+ // completes, so the next Schedule tick can retry maintenance independently.
186
+ log.warn("sandbox reaper maintenance child start deferred to next sweep", {
187
+ error: error instanceof Error ? error.message : String(error),
188
+ });
189
+ }
28
190
  }
@@ -1,6 +1,18 @@
1
- import { patched, workflowInfo } from "@temporalio/workflow";
1
+ import {
2
+ getExternalWorkflowHandle,
3
+ ParentClosePolicy,
4
+ patched,
5
+ startChild,
6
+ workflowInfo,
7
+ WorkflowIdReusePolicy,
8
+ } from "@temporalio/workflow";
2
9
  import type { TurnInitiator } from "@opengeni/contracts";
3
10
  import { scheduledTaskActivity } from "./activities";
11
+ import {
12
+ knowledgeSourceSyncWake,
13
+ knowledgeSourceSyncWorkflow,
14
+ knowledgeSourceSyncWorkflowId,
15
+ } from "./knowledge-source-sync";
4
16
 
5
17
  type ScheduledTaskFireWorkflowBase = {
6
18
  accountId: string;
@@ -16,7 +28,7 @@ export type ScheduledTaskFireWorkflowInput = ScheduledTaskFireWorkflowBase &
16
28
  initiator?: never;
17
29
  }
18
30
  | {
19
- triggerType: "manual";
31
+ triggerType: "manual" | "initial" | "provider_event" | "retry" | "repair";
20
32
  agentRunUsageIdempotencyKey: string;
21
33
  initiator: TurnInitiator;
22
34
  }
@@ -30,7 +42,7 @@ export async function scheduledTaskFireWorkflow(
30
42
  // the exact charging identity.
31
43
  if (
32
44
  patched("scheduled-task-manual-initiator-v1") &&
33
- input.triggerType === "manual" &&
45
+ input.triggerType !== "scheduled" &&
34
46
  (!input.agentRunUsageIdempotencyKey || !input.initiator)
35
47
  ) {
36
48
  return;
@@ -40,14 +52,38 @@ export async function scheduledTaskFireWorkflow(
40
52
  taskId: input.taskId,
41
53
  producerKey: workflowInfo().workflowId,
42
54
  };
43
- await scheduledTaskActivity.dispatchScheduledTaskRun(
44
- input.triggerType === "manual"
55
+ const result = await scheduledTaskActivity.dispatchScheduledTaskRun(
56
+ input.triggerType !== "scheduled"
45
57
  ? {
46
58
  ...base,
47
- triggerType: "manual",
59
+ triggerType: input.triggerType,
48
60
  agentRunUsageIdempotencyKey: input.agentRunUsageIdempotencyKey,
49
61
  initiator: input.initiator,
50
62
  }
51
63
  : { ...base, triggerType: "scheduled" },
52
64
  );
65
+ if (result.action !== "knowledge_source_sync") return;
66
+
67
+ const workflowId = knowledgeSourceSyncWorkflowId(result.sourceId);
68
+ try {
69
+ await startChild(knowledgeSourceSyncWorkflow, {
70
+ workflowId,
71
+ workflowIdReusePolicy: WorkflowIdReusePolicy.ALLOW_DUPLICATE,
72
+ parentClosePolicy: ParentClosePolicy.ABANDON,
73
+ args: [result],
74
+ });
75
+ } catch (error) {
76
+ if (!alreadyRunningWorkflow(error)) throw error;
77
+ await getExternalWorkflowHandle(workflowId).signal(knowledgeSourceSyncWake, result);
78
+ }
79
+ }
80
+
81
+ function alreadyRunningWorkflow(error: unknown): boolean {
82
+ let current: unknown = error;
83
+ for (let depth = 0; depth < 4 && current && typeof current === "object"; depth += 1) {
84
+ const record = current as { name?: unknown; cause?: unknown };
85
+ if (record.name === "WorkflowExecutionAlreadyStartedError") return true;
86
+ current = record.cause;
87
+ }
88
+ return false;
53
89
  }
@@ -0,0 +1,36 @@
1
+ import { continueAsNew, sleep } from "@temporalio/workflow";
2
+ import { videoGenerationActivityForTaskQueue } from "./activities";
3
+
4
+ export type VideoGenerationWorkflowInput = {
5
+ accountId: string;
6
+ workspaceId: string;
7
+ operationId: string;
8
+ baseTaskQueue: string;
9
+ iterations?: number;
10
+ };
11
+
12
+ const CONTINUE_AS_NEW_AFTER = 100;
13
+
14
+ export function videoGenerationWorkflowId(operationId: string): string {
15
+ return `video-generation:${operationId}`;
16
+ }
17
+
18
+ /** Small deterministic orchestration; all private/provider state remains in Postgres. */
19
+ export async function videoGenerationWorkflow(input: VideoGenerationWorkflowInput): Promise<void> {
20
+ const activity = videoGenerationActivityForTaskQueue(input.baseTaskQueue);
21
+ let iterations = input.iterations ?? 0;
22
+ while (iterations < CONTINUE_AS_NEW_AFTER) {
23
+ const result = await activity.reconcileVideoGenerationOperation({
24
+ accountId: input.accountId,
25
+ workspaceId: input.workspaceId,
26
+ operationId: input.operationId,
27
+ });
28
+ if (result.action === "terminal") return;
29
+ await sleep(result.delayMs);
30
+ iterations += 1;
31
+ }
32
+ await continueAsNew<typeof videoGenerationWorkflow>({
33
+ ...input,
34
+ iterations: 0,
35
+ });
36
+ }
package/src/workflows.ts CHANGED
@@ -13,8 +13,24 @@ export {
13
13
  scheduledTaskFireWorkflow,
14
14
  type ScheduledTaskFireWorkflowInput,
15
15
  } from "./workflows/scheduled-tasks";
16
- export { sandboxReaperWorkflow } from "./workflows/sandbox-reaper";
16
+ export {
17
+ knowledgeSourceSyncWake,
18
+ knowledgeSourceSyncWorkflow,
19
+ knowledgeSourceSyncWorkflowId,
20
+ type KnowledgeSourceSyncWorkflowInput,
21
+ } from "./workflows/knowledge-source-sync";
22
+ export {
23
+ sandboxDrainWorkflow,
24
+ sandboxReaperMaintenanceWorkflow,
25
+ sandboxReaperWorkflow,
26
+ sandboxReaperWorkflowV2,
27
+ } from "./workflows/sandbox-reaper";
17
28
  export { fileUploadReaperWorkflow } from "./workflows/file-upload-reaper";
29
+ export {
30
+ videoGenerationWorkflow,
31
+ videoGenerationWorkflowId,
32
+ type VideoGenerationWorkflowInput,
33
+ } from "./workflows/video-generation";
18
34
  export { sessionWorkflowWakeDispatcherWorkflow } from "./workflows/workflow-wake";
19
35
  export {
20
36
  rigVerificationWorkflow,
@@ -1 +0,0 @@
1
- export { createSecretRedactor, identityRedactor, isCredentialHeaderName, redactSensitiveData, redactSensitiveText, redactSerializedJson, type SecretForRedaction, } from "@opengeni/contracts";
@@ -1,23 +0,0 @@
1
- import { type ExpiringMaterialRenewalController } from "./expiring-material-renewal";
2
- import type { MintedSandboxToolspaceToken } from "./environment";
3
- export declare const TOOLSPACE_TOKEN_DEFAULT_REFRESH_MS: number;
4
- export declare const TOOLSPACE_TOKEN_EXPIRY_LEAD_MS: number;
5
- export declare const TOOLSPACE_TOKEN_MIN_REFRESH_MS = 5000;
6
- export declare const TOOLSPACE_TOKEN_MAX_RETRY_MS: number;
7
- export type ToolspaceTokenRenewalController = ExpiringMaterialRenewalController;
8
- export type ToolspaceTokenRenewalOptions = {
9
- initialExpiresAt: Date;
10
- mint: () => Promise<MintedSandboxToolspaceToken | undefined>;
11
- write: (material: MintedSandboxToolspaceToken) => Promise<void>;
12
- now?: () => number;
13
- schedule?: (callback: () => void, delayMs: number) => unknown;
14
- clearSchedule?: (timer: unknown) => void;
15
- onSuccess?: (result: {
16
- nextDelayMs: number;
17
- }) => void;
18
- onFailure?: (failure: {
19
- retryDelayMs: number;
20
- errorClass: string;
21
- }) => void;
22
- };
23
- export declare function startToolspaceTokenRenewalLoop(options: ToolspaceTokenRenewalOptions): ToolspaceTokenRenewalController;
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/host-export-pump.ts"],"sourcesContent":["import type { HostEventSink, HostUsageSink } from \"@opengeni/contracts\";\nimport {\n acknowledgeHostExportBatch,\n claimHostExportBatch,\n disableHostExportConsumer,\n failHostExportBatch,\n getHostExportConsumerStatus,\n pruneHostExportOutbox,\n registerHostExportConsumer,\n retireHostExportConsumer,\n type Database,\n type HostExportConsumerStatus,\n type HostExportKind,\n} from \"@opengeni/db\";\nimport type { Observability } from \"@opengeni/observability\";\n\nexport type HostExportDrainResult =\n | { kind: HostExportKind; outcome: \"not_configured\" | \"idle\" }\n | { kind: HostExportKind; outcome: \"blocked\"; failures: number }\n | {\n kind: HostExportKind;\n outcome: \"delivered\";\n count: number;\n throughCursor: string;\n }\n | {\n kind: HostExportKind;\n outcome: \"failed\";\n failures: number;\n blocked: boolean;\n };\n\nexport type HostExportPumpOptions = {\n /** A handle authenticated as the separately provisioned host-export role. */\n db: Database;\n eventSink?: HostEventSink;\n usageSink?: HostUsageSink;\n observability?: Observability;\n instanceId?: string;\n pollIntervalMs?: number;\n leaseSeconds?: number;\n batchLimit?: number;\n batchMaxBytes?: number;\n maxFailures?: number;\n /** Maximum catch-up batches per poll tick; bounds one iteration's work. */\n maxBatchesPerPoll?: number;\n /** Acked rows younger than this remain available for replay. */\n pruneGraceSeconds?: number;\n /** Maximum rows pruned after one successful acknowledgement. */\n pruneLimit?: number;\n};\n\nexport type HostExportPump = {\n /** Register configured consumers and start the non-overlapping poll loop. */\n start: () => Promise<void>;\n /** Stop polling and wait for the currently executing sink call, if any. */\n stop: () => Promise<void>;\n /** Execute at most one bounded batch for each configured sink. */\n drainOnce: () => Promise<HostExportDrainResult[]>;\n /**\n * Disable this named consumer while retaining its replay checkpoint. If it is\n * the last enabled consumer of the kind, capture stops and that interval is\n * intentionally unrecoverable. Normal process shutdown must not call this.\n */\n disable: (kind: HostExportKind) => Promise<void>;\n /** Permanently remove a stopped consumer and release its retention floor. */\n retire: (kind: HostExportKind) => Promise<void>;\n status: (kind: HostExportKind) => Promise<HostExportConsumerStatus | null>;\n};\n\n/**\n * Build the durable delivery loop used by embedded hosts.\n *\n * The source transaction writes the outbox; this pump only leases, delivers,\n * and checkpoints it. Delivery is intentionally at least once: a process death\n * after sink success but before acknowledgement repeats the same idempotency\n * keys. Sink implementations must therefore deduplicate those keys.\n */\nexport function createHostExportPump(options: HostExportPumpOptions): HostExportPump {\n if (!options.eventSink && !options.usageSink) {\n throw new Error(\"createHostExportPump requires at least one host sink\");\n }\n const instanceId = validateInstanceId(\n options.instanceId ?? `worker-${process.pid}-${crypto.randomUUID()}`,\n );\n const pollIntervalMs = boundedInteger(options.pollIntervalMs, 1_000, 25, 60_000);\n const leaseSeconds = boundedInteger(options.leaseSeconds, 60, 5, 300);\n const batchLimit = boundedInteger(options.batchLimit, 100, 1, 256);\n const batchMaxBytes = boundedInteger(options.batchMaxBytes, 1_048_576, 98_304, 4_194_304);\n const maxFailures = boundedInteger(options.maxFailures, 20, 1, 1_000);\n const maxBatchesPerPoll = boundedInteger(options.maxBatchesPerPoll, 32, 1, 1_000);\n const pruneGraceSeconds = boundedInteger(options.pruneGraceSeconds, 3_600, 0, 604_800);\n const pruneLimit = boundedInteger(options.pruneLimit, 1_000, 1, 10_000);\n let running = false;\n let loopPromise: Promise<void> | null = null;\n let waitTimer: ReturnType<typeof setTimeout> | null = null;\n let wakeWait: (() => void) | null = null;\n let lifecycleTail: Promise<void> = Promise.resolve();\n let drainTail: Promise<void> = Promise.resolve();\n const retiringKinds = new Set<HostExportKind>();\n\n const configuredConsumer = (kind: HostExportKind): string | null =>\n kind === \"session_event\"\n ? (options.eventSink?.consumerId ?? null)\n : (options.usageSink?.consumerId ?? null);\n\n const recordResult = (result: HostExportDrainResult, durationSeconds: number) => {\n const labels = { kind: result.kind, outcome: result.outcome };\n options.observability?.incrementCounter({\n name: \"opengeni_host_export_batches_total\",\n help: \"Durable host export batch attempts by outcome.\",\n labels,\n });\n options.observability?.observeHistogram({\n name: \"opengeni_host_export_batch_duration_seconds\",\n help: \"Duration of durable host export batch attempts.\",\n labels: { kind: result.kind },\n value: durationSeconds,\n });\n if (result.outcome === \"delivered\") {\n options.observability?.incrementCounter({\n name: \"opengeni_host_export_records_total\",\n help: \"Durable host export records acknowledged by a host sink.\",\n labels: { kind: result.kind },\n amount: result.count,\n });\n options.observability?.setGauge({\n name: \"opengeni_host_export_consumer_blocked\",\n help: \"Whether the durable host export consumer is blocked.\",\n labels: { kind: result.kind },\n value: 0,\n });\n } else if (result.outcome === \"failed\") {\n options.observability?.setGauge({\n name: \"opengeni_host_export_consumer_blocked\",\n help: \"Whether the durable host export consumer is blocked.\",\n labels: { kind: result.kind },\n value: result.blocked ? 1 : 0,\n });\n } else if (result.outcome === \"blocked\") {\n options.observability?.setGauge({\n name: \"opengeni_host_export_consumer_blocked\",\n help: \"Whether the durable host export consumer is blocked.\",\n labels: { kind: result.kind },\n value: 1,\n });\n }\n };\n\n const drainKind = async (kind: HostExportKind): Promise<HostExportDrainResult> => {\n if (retiringKinds.has(kind)) return { kind, outcome: \"not_configured\" };\n const startedAt = performance.now();\n const consumerId = configuredConsumer(kind);\n if (!consumerId) {\n const result: HostExportDrainResult = { kind, outcome: \"not_configured\" };\n recordResult(result, (performance.now() - startedAt) / 1_000);\n return result;\n }\n const leaseToken = crypto.randomUUID();\n const common = {\n consumerId,\n leaseToken,\n leaseHolderId: instanceId,\n leaseSeconds,\n limit: batchLimit,\n maxBytes: batchMaxBytes,\n };\n const settleFailure = async (error: unknown): Promise<HostExportDrainResult> => {\n const message = safeErrorMessage(error);\n let failures = 0;\n try {\n failures = await failHostExportBatch(options.db, {\n kind,\n consumerId,\n leaseToken,\n error: message,\n maxFailures,\n });\n } catch (settlementError) {\n options.observability?.warn(\"host export failure settlement was stale\", {\n kind,\n consumerId,\n error: safeErrorMessage(settlementError),\n });\n }\n const blocked = failures >= maxFailures;\n options.observability?.warn(\"host export batch failed\", {\n kind,\n consumerId,\n failures,\n blocked,\n error: message,\n });\n const result: HostExportDrainResult = {\n kind,\n outcome: \"failed\",\n failures,\n blocked,\n };\n recordResult(result, (performance.now() - startedAt) / 1_000);\n return result;\n };\n const deliverClaim = async (\n count: number,\n deliver: () => Promise<void>,\n ): Promise<HostExportDrainResult> => {\n await deliver();\n const throughCursor = await acknowledgeHostExportBatch(options.db, {\n kind,\n consumerId,\n leaseToken,\n });\n try {\n await pruneHostExportOutbox(options.db, {\n kind,\n graceSeconds: pruneGraceSeconds,\n limit: pruneLimit,\n });\n } catch (error) {\n // The sink and checkpoint are already committed. A retention failure\n // must be visible, but must never turn into a false delivery failure or\n // a duplicate settlement attempt for the now-stale lease.\n options.observability?.error(\"host export retention prune failed\", {\n kind,\n consumerId,\n error: safeErrorMessage(error),\n });\n }\n const result: HostExportDrainResult = {\n kind,\n outcome: \"delivered\",\n count,\n throughCursor,\n };\n recordResult(result, (performance.now() - startedAt) / 1_000);\n return result;\n };\n\n try {\n if (kind === \"session_event\") {\n const sink = options.eventSink;\n if (!sink) return { kind, outcome: \"not_configured\" };\n const batch = await claimHostExportBatch(options.db, {\n kind,\n ...common,\n });\n if (batch) return await deliverClaim(batch.events.length, () => sink.deliverEvents(batch));\n } else {\n const sink = options.usageSink;\n if (!sink) return { kind, outcome: \"not_configured\" };\n const batch = await claimHostExportBatch(options.db, {\n kind,\n ...common,\n });\n if (batch) return await deliverClaim(batch.events.length, () => sink.deliverUsage(batch));\n }\n } catch (error) {\n return await settleFailure(error);\n }\n const status = await getHostExportConsumerStatus(options.db, {\n kind,\n consumerId,\n });\n if (status?.blockedAt) {\n const result: HostExportDrainResult = {\n kind,\n outcome: \"blocked\",\n failures: status.consecutiveFailures,\n };\n recordResult(result, (performance.now() - startedAt) / 1_000);\n return result;\n }\n const result: HostExportDrainResult = { kind, outcome: \"idle\" };\n recordResult(result, (performance.now() - startedAt) / 1_000);\n return result;\n };\n\n const drainConfiguredOnce = async (): Promise<HostExportDrainResult[]> => {\n const results: HostExportDrainResult[] = [];\n if (options.eventSink) results.push(await drainKind(\"session_event\"));\n if (options.usageSink) results.push(await drainKind(\"usage_event\"));\n return results;\n };\n\n const drainOnce = (): Promise<HostExportDrainResult[]> => {\n const next = drainTail.then(drainConfiguredOnce);\n drainTail = next.then(\n () => undefined,\n () => undefined,\n );\n return next;\n };\n\n const serializeLifecycle = <T>(operation: () => Promise<T>): Promise<T> => {\n const next = lifecycleTail.then(operation);\n lifecycleTail = next.then(\n () => undefined,\n () => undefined,\n );\n return next;\n };\n\n const waitForPoll = async (): Promise<void> => {\n await new Promise<void>((resolve) => {\n wakeWait = resolve;\n waitTimer = setTimeout(resolve, pollIntervalMs);\n waitTimer.unref?.();\n });\n wakeWait = null;\n if (waitTimer) clearTimeout(waitTimer);\n waitTimer = null;\n };\n\n return {\n start: () =>\n serializeLifecycle(async () => {\n if (running) return;\n await options.db.transaction(async (tx) => {\n const scoped = tx as unknown as Database;\n if (options.eventSink) {\n await registerHostExportConsumer(scoped, {\n kind: \"session_event\",\n consumerId: options.eventSink.consumerId,\n });\n }\n if (options.usageSink) {\n await registerHostExportConsumer(scoped, {\n kind: \"usage_event\",\n consumerId: options.usageSink.consumerId,\n });\n }\n });\n if (options.eventSink) retiringKinds.delete(\"session_event\");\n if (options.usageSink) retiringKinds.delete(\"usage_event\");\n running = true;\n loopPromise = (async () => {\n while (true) {\n if (!running) break;\n try {\n for (let batch = 0; batch < maxBatchesPerPoll; batch += 1) {\n if (!running) break;\n const results = await drainOnce();\n if (!results.some((result) => result.outcome === \"delivered\")) break;\n }\n } catch (error) {\n options.observability?.error(\"host export pump iteration failed\", {\n error: safeErrorMessage(error),\n });\n }\n if (running) await waitForPoll();\n }\n })();\n }),\n stop: () =>\n serializeLifecycle(async () => {\n running = false;\n if (waitTimer) clearTimeout(waitTimer);\n wakeWait?.();\n await loopPromise;\n loopPromise = null;\n }),\n drainOnce,\n disable: async (kind) => {\n const consumerId = configuredConsumer(kind);\n if (!consumerId) throw new Error(`No ${kind} sink is configured`);\n await disableHostExportConsumer(options.db, { kind, consumerId });\n },\n retire: (kind) =>\n serializeLifecycle(async () => {\n if (running) throw new Error(\"Stop the host export pump before retiring a consumer\");\n const consumerId = configuredConsumer(kind);\n if (!consumerId) throw new Error(`No ${kind} sink is configured`);\n retiringKinds.add(kind);\n try {\n await drainTail;\n await retireHostExportConsumer(options.db, { kind, consumerId });\n } catch (error) {\n retiringKinds.delete(kind);\n throw error;\n }\n }),\n status: async (kind) => {\n const consumerId = configuredConsumer(kind);\n if (!consumerId) return null;\n return await getHostExportConsumerStatus(options.db, {\n kind,\n consumerId,\n });\n },\n };\n}\n\nfunction boundedInteger(\n value: number | undefined,\n fallback: number,\n minimum: number,\n maximum: number,\n): number {\n const candidate = value ?? fallback;\n if (!Number.isInteger(candidate) || candidate < minimum || candidate > maximum) {\n throw new Error(`Expected an integer between ${minimum} and ${maximum}`);\n }\n return candidate;\n}\n\nfunction validateInstanceId(value: string): string {\n if (value.length < 1 || value.length > 128) {\n throw new Error(\"Host export instanceId must contain 1 to 128 characters\");\n }\n return value;\n}\n\nfunction safeErrorMessage(error: unknown): string {\n const message = error instanceof Error ? error.message : String(error);\n return message.trim().slice(0, 500) || \"host sink failed\";\n}\n"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAiEA,SAAS,qBAAqB,SAAgD;AACnF,MAAI,CAAC,QAAQ,aAAa,CAAC,QAAQ,WAAW;AAC5C,UAAM,IAAI,MAAM,sDAAsD;AAAA,EACxE;AACA,QAAM,aAAa;AAAA,IACjB,QAAQ,cAAc,UAAU,QAAQ,GAAG,IAAI,OAAO,WAAW,CAAC;AAAA,EACpE;AACA,QAAM,iBAAiB,eAAe,QAAQ,gBAAgB,KAAO,IAAI,GAAM;AAC/E,QAAM,eAAe,eAAe,QAAQ,cAAc,IAAI,GAAG,GAAG;AACpE,QAAM,aAAa,eAAe,QAAQ,YAAY,KAAK,GAAG,GAAG;AACjE,QAAM,gBAAgB,eAAe,QAAQ,eAAe,SAAW,OAAQ,OAAS;AACxF,QAAM,cAAc,eAAe,QAAQ,aAAa,IAAI,GAAG,GAAK;AACpE,QAAM,oBAAoB,eAAe,QAAQ,mBAAmB,IAAI,GAAG,GAAK;AAChF,QAAM,oBAAoB,eAAe,QAAQ,mBAAmB,MAAO,GAAG,MAAO;AACrF,QAAM,aAAa,eAAe,QAAQ,YAAY,KAAO,GAAG,GAAM;AACtE,MAAI,UAAU;AACd,MAAI,cAAoC;AACxC,MAAI,YAAkD;AACtD,MAAI,WAAgC;AACpC,MAAI,gBAA+B,QAAQ,QAAQ;AACnD,MAAI,YAA2B,QAAQ,QAAQ;AAC/C,QAAM,gBAAgB,oBAAI,IAAoB;AAE9C,QAAM,qBAAqB,CAAC,SAC1B,SAAS,kBACJ,QAAQ,WAAW,cAAc,OACjC,QAAQ,WAAW,cAAc;AAExC,QAAM,eAAe,CAAC,QAA+B,oBAA4B;AAC/E,UAAM,SA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;AACxB,aAAO,MAAM,4BAA4B,QAAQ,IAAI;AAAA,QACnD;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEA,SAAS,eACP,OACA,UACA,SACA,SACQ;AACR,QAAM,YAAY,SAAS;AAC3B,MAAI,CAAC,OAAO,UAAU,SAAS,KAAK,YAAY,WAAW,YAAY,SAAS;AAC9E,UAAM,IAAI,MAAM,+BAA+B,OAAO,QAAQ,OAAO,EAAE;AAAA,EACzE;AACA,SAAO;AACT;AAEA,SAAS,mBAAmB,OAAuB;AACjD,MAAI,MAAM,SAAS,KAAK,MAAM,SAAS,KAAK;AAC1C,UAAM,IAAI,MAAM,yDAAyD;AAAA,EAC3E;AACA,SAAO;AACT;AAEA,SAAS,iBAAiB,OAAwB;AAChD,QAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACrE,SAAO,QAAQ,KAAK,EAAE,MAAM,GAAG,GAAG,KAAK;AACzC;","names":["result"]}
@@ -1,9 +0,0 @@
1
- export {
2
- createSecretRedactor,
3
- identityRedactor,
4
- isCredentialHeaderName,
5
- redactSensitiveData,
6
- redactSensitiveText,
7
- redactSerializedJson,
8
- type SecretForRedaction,
9
- } from "@opengeni/contracts";
@@ -1,57 +0,0 @@
1
- import {
2
- startExpiringMaterialRenewalLoop,
3
- type ExpiringMaterialRenewalController,
4
- } from "./expiring-material-renewal";
5
- import type { MintedSandboxToolspaceToken } from "./environment";
6
-
7
- export const TOOLSPACE_TOKEN_DEFAULT_REFRESH_MS = 30 * 60_000;
8
- export const TOOLSPACE_TOKEN_EXPIRY_LEAD_MS = 5 * 60_000;
9
- export const TOOLSPACE_TOKEN_MIN_REFRESH_MS = 5_000;
10
- export const TOOLSPACE_TOKEN_MAX_RETRY_MS = 5 * 60_000;
11
-
12
- export type ToolspaceTokenRenewalController = ExpiringMaterialRenewalController;
13
-
14
- export type ToolspaceTokenRenewalOptions = {
15
- initialExpiresAt: Date;
16
- mint: () => Promise<MintedSandboxToolspaceToken | undefined>;
17
- write: (material: MintedSandboxToolspaceToken) => Promise<void>;
18
- now?: () => number;
19
- schedule?: (callback: () => void, delayMs: number) => unknown;
20
- clearSchedule?: (timer: unknown) => void;
21
- onSuccess?: (result: { nextDelayMs: number }) => void;
22
- onFailure?: (failure: { retryDelayMs: number; errorClass: string }) => void;
23
- };
24
-
25
- class ToolspaceTokenRenewalError extends Error {
26
- override readonly name = "ToolspaceTokenRenewalError";
27
- }
28
-
29
- export function startToolspaceTokenRenewalLoop(
30
- options: ToolspaceTokenRenewalOptions,
31
- ): ToolspaceTokenRenewalController {
32
- return startExpiringMaterialRenewalLoop<MintedSandboxToolspaceToken>({
33
- initialExpiresAt: options.initialExpiresAt,
34
- resolve: async () => {
35
- const minted = await options.mint();
36
- if (!minted) {
37
- throw new ToolspaceTokenRenewalError("Toolspace token mint is no longer available");
38
- }
39
- return minted;
40
- },
41
- write: options.write,
42
- expiresAt: (material) => material.expiresAt,
43
- policy: {
44
- defaultRefreshMs: TOOLSPACE_TOKEN_DEFAULT_REFRESH_MS,
45
- expiryLeadMs: TOOLSPACE_TOKEN_EXPIRY_LEAD_MS,
46
- minRefreshMs: TOOLSPACE_TOKEN_MIN_REFRESH_MS,
47
- maxRetryMs: TOOLSPACE_TOKEN_MAX_RETRY_MS,
48
- },
49
- ...(options.now ? { now: options.now } : {}),
50
- ...(options.schedule ? { schedule: options.schedule } : {}),
51
- ...(options.clearSchedule ? { clearSchedule: options.clearSchedule } : {}),
52
- ...(options.onSuccess
53
- ? { onSuccess: ({ nextDelayMs }) => options.onSuccess?.({ nextDelayMs }) }
54
- : {}),
55
- ...(options.onFailure ? { onFailure: options.onFailure } : {}),
56
- });
57
- }