@opengeni/worker-bundle 0.20.3 → 0.22.1-canary.0

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 (184) hide show
  1. package/dist/activities/agent-turn/admission.d.ts +52 -0
  2. package/dist/activities/agent-turn/agent-build.d.ts +89 -0
  3. package/dist/activities/agent-turn/claim.d.ts +67 -0
  4. package/dist/activities/agent-turn/codex-capacity.d.ts +40 -0
  5. package/dist/activities/agent-turn/codex.d.ts +32 -0
  6. package/dist/activities/agent-turn/compaction-prep.d.ts +88 -0
  7. package/dist/activities/agent-turn/credential-leases.d.ts +56 -0
  8. package/dist/activities/agent-turn/errors.d.ts +253 -0
  9. package/dist/activities/agent-turn/failure-settlement.d.ts +33 -0
  10. package/dist/activities/agent-turn/file-resources.d.ts +37 -0
  11. package/dist/activities/agent-turn/finalization.d.ts +42 -0
  12. package/dist/activities/agent-turn/github-repository-bindings.d.ts +105 -0
  13. package/dist/activities/agent-turn/governance-model.d.ts +66 -0
  14. package/dist/activities/agent-turn/history-sink.d.ts +52 -0
  15. package/dist/activities/agent-turn/history.d.ts +63 -0
  16. package/dist/activities/agent-turn/media-artifacts.d.ts +145 -0
  17. package/dist/activities/agent-turn/model-usage.d.ts +218 -0
  18. package/dist/activities/agent-turn/quiescence.d.ts +135 -0
  19. package/dist/activities/agent-turn/run-credentials.d.ts +84 -0
  20. package/dist/activities/agent-turn/run.d.ts +3 -0
  21. package/dist/activities/agent-turn/sandbox-establish.d.ts +93 -0
  22. package/dist/activities/agent-turn/sandbox-provision.d.ts +89 -0
  23. package/dist/activities/agent-turn/sandbox-route.d.ts +151 -0
  24. package/dist/activities/agent-turn/sandbox-runtime.d.ts +44 -0
  25. package/dist/activities/agent-turn/stream-attempt.d.ts +107 -0
  26. package/dist/activities/agent-turn/tool-environment.d.ts +142 -0
  27. package/dist/activities/agent-turn/tool-policy.d.ts +127 -0
  28. package/dist/activities/agent-turn/tool-result-spill.d.ts +59 -0
  29. package/dist/activities/agent-turn/turn-context.d.ts +144 -0
  30. package/dist/activities/agent-turn/xai-capacity.d.ts +2 -0
  31. package/dist/activities/agent-turn.d.ts +12 -954
  32. package/dist/activities/automations.d.ts +16 -0
  33. package/dist/activities/common.d.ts +1 -1
  34. package/dist/activities/connector-attachments.d.ts +13 -0
  35. package/dist/activities/documents.d.ts +1 -0
  36. package/dist/activities/environment.d.ts +26 -15
  37. package/dist/activities/generated-images.d.ts +1 -1
  38. package/dist/activities/git-credential-renewal.d.ts +3 -1
  39. package/dist/activities/goals.d.ts +4 -1
  40. package/dist/activities/google-drive-provider.d.ts +29 -0
  41. package/dist/activities/google-drive-publication.d.ts +17 -4
  42. package/dist/activities/incident-telemetry-authority.d.ts +52 -0
  43. package/dist/activities/incident-telemetry-preflight.d.ts +71 -0
  44. package/dist/activities/knowledge-source-sync.d.ts +4 -0
  45. package/dist/activities/mcp-credentials.d.ts +9 -3
  46. package/dist/activities/open-suffix-resume.d.ts +77 -0
  47. package/dist/activities/packs.d.ts +3 -11
  48. package/dist/activities/parent-wake.d.ts +19 -0
  49. package/dist/activities/retained-screenshot-reaper.d.ts +1 -1
  50. package/dist/activities/retained-screenshots.d.ts +1 -1
  51. package/dist/activities/rig-verification.d.ts +1 -1
  52. package/dist/activities/run-input.d.ts +9 -10
  53. package/dist/activities/sandbox-images.d.ts +1 -14
  54. package/dist/activities/sandbox-lease.d.ts +21 -3
  55. package/dist/activities/scheduled-tasks.d.ts +47 -0
  56. package/dist/activities/types.d.ts +23 -2
  57. package/dist/activities/video-media-validation.d.ts +1 -1
  58. package/dist/activities/video-output-retention.d.ts +1 -2
  59. package/dist/activities/xai-auth.d.ts +3 -0
  60. package/dist/{activities-control-BJSDRSIP.js → activities-control-DKG22ONJ.js} +2646 -551
  61. package/dist/activities-control-DKG22ONJ.js.map +1 -0
  62. package/dist/activities-control.d.ts +6 -2
  63. package/dist/activities-turn-4IMC3MAA.js +21326 -0
  64. package/dist/activities-turn-4IMC3MAA.js.map +1 -0
  65. package/dist/activities.d.ts +7 -3
  66. package/dist/artifact-materializer-entry.js +41 -22
  67. package/dist/artifact-materializer-entry.js.map +1 -1
  68. package/dist/{chunk-N5TJIFCE.js → chunk-CE7TPKBS.js} +468 -1
  69. package/dist/chunk-CE7TPKBS.js.map +1 -0
  70. package/dist/chunk-CNYGVRKF.js +4698 -0
  71. package/dist/chunk-CNYGVRKF.js.map +1 -0
  72. package/dist/connection-provider-use.d.ts +18 -0
  73. package/dist/editable-artifact-materializer.d.ts +4 -3
  74. package/dist/github-rest-mcp.d.ts +26 -0
  75. package/dist/index.d.ts +10 -2
  76. package/dist/index.js +58 -14
  77. package/dist/index.js.map +1 -1
  78. package/dist/knowledge-source-sync-activity-policy.d.ts +2 -0
  79. package/dist/model-context-contributions.d.ts +8 -4
  80. package/dist/observability-metrics.d.ts +63 -4
  81. package/dist/opensandbox-kubernetes-inventory.d.ts +21 -0
  82. package/dist/personal-github-git-credentials.d.ts +9 -0
  83. package/dist/pr-review-credentials.d.ts +6 -0
  84. package/dist/sandbox-archive-storage.d.ts +45 -0
  85. package/dist/sandbox-resume.d.ts +65 -6
  86. package/dist/sandbox-routing.d.ts +38 -2
  87. package/dist/scheduled-alert-occurrence.d.ts +33 -0
  88. package/dist/workflow-bundle.js +87 -28
  89. package/dist/workflows/activities.d.ts +1 -0
  90. package/dist/workflows/automations.d.ts +6 -0
  91. package/dist/workflows/document-index.d.ts +1 -0
  92. package/dist/workflows.d.ts +1 -0
  93. package/package.json +17 -17
  94. package/src/activities/agent-turn/admission.ts +292 -0
  95. package/src/activities/agent-turn/agent-build.ts +802 -0
  96. package/src/activities/agent-turn/claim.ts +590 -0
  97. package/src/activities/agent-turn/codex-capacity.ts +720 -0
  98. package/src/activities/agent-turn/codex.ts +94 -0
  99. package/src/activities/agent-turn/compaction-prep.ts +722 -0
  100. package/src/activities/agent-turn/credential-leases.ts +240 -0
  101. package/src/activities/agent-turn/errors.ts +1068 -0
  102. package/src/activities/agent-turn/failure-settlement.ts +1436 -0
  103. package/src/activities/agent-turn/file-resources.ts +227 -0
  104. package/src/activities/agent-turn/finalization.ts +754 -0
  105. package/src/activities/agent-turn/github-repository-bindings.ts +300 -0
  106. package/src/activities/agent-turn/governance-model.ts +465 -0
  107. package/src/activities/agent-turn/history-sink.ts +139 -0
  108. package/src/activities/agent-turn/history.ts +200 -0
  109. package/src/activities/agent-turn/media-artifacts.ts +359 -0
  110. package/src/activities/agent-turn/model-usage.ts +823 -0
  111. package/src/activities/agent-turn/quiescence.ts +353 -0
  112. package/src/activities/agent-turn/run-credentials.ts +761 -0
  113. package/src/activities/agent-turn/run.ts +1530 -0
  114. package/src/activities/agent-turn/sandbox-establish.ts +1207 -0
  115. package/src/activities/agent-turn/sandbox-provision.ts +569 -0
  116. package/src/activities/agent-turn/sandbox-route.ts +358 -0
  117. package/src/activities/agent-turn/sandbox-runtime.ts +731 -0
  118. package/src/activities/agent-turn/stream-attempt.ts +1670 -0
  119. package/src/activities/agent-turn/tool-environment.ts +729 -0
  120. package/src/activities/agent-turn/tool-policy.ts +216 -0
  121. package/src/activities/agent-turn/tool-result-spill.ts +265 -0
  122. package/src/activities/agent-turn/turn-context.ts +281 -0
  123. package/src/activities/agent-turn/xai-capacity.ts +229 -0
  124. package/src/activities/agent-turn.ts +12 -12701
  125. package/src/activities/api-integrations.ts +3 -0
  126. package/src/activities/automations.ts +214 -0
  127. package/src/activities/codemode-dispatcher.ts +12 -1
  128. package/src/activities/common.ts +1 -5
  129. package/src/activities/connector-attachments.ts +168 -0
  130. package/src/activities/context-compaction.ts +18 -0
  131. package/src/activities/environment.ts +151 -55
  132. package/src/activities/generated-images.ts +26 -11
  133. package/src/activities/git-credential-renewal.ts +13 -3
  134. package/src/activities/goals.ts +85 -19
  135. package/src/activities/google-drive-provider.ts +178 -0
  136. package/src/activities/google-drive-publication.ts +147 -49
  137. package/src/activities/incident-telemetry-authority.ts +327 -0
  138. package/src/activities/incident-telemetry-preflight.ts +317 -0
  139. package/src/activities/knowledge-source-sync.ts +178 -37
  140. package/src/activities/mcp-credentials.ts +191 -17
  141. package/src/activities/open-suffix-resume.ts +422 -0
  142. package/src/activities/packs.ts +12 -60
  143. package/src/activities/parent-wake.ts +64 -14
  144. package/src/activities/retained-screenshot-reaper.ts +6 -3
  145. package/src/activities/retained-screenshots.ts +15 -47
  146. package/src/activities/rig-verification.ts +1 -1
  147. package/src/activities/run-input.ts +102 -142
  148. package/src/activities/sandbox-images.ts +7 -166
  149. package/src/activities/sandbox-lease.ts +406 -15
  150. package/src/activities/scheduled-tasks.ts +2103 -411
  151. package/src/activities/session-state.ts +10 -2
  152. package/src/activities/types.ts +32 -2
  153. package/src/activities/video-media-validation.ts +3 -3
  154. package/src/activities/video-output-retention.ts +2 -57
  155. package/src/activities/xai-auth.ts +8 -0
  156. package/src/activities-control.ts +2 -0
  157. package/src/activities.ts +3 -0
  158. package/src/activity-services.ts +13 -4
  159. package/src/connection-provider-use.ts +36 -0
  160. package/src/editable-artifact-materializer-subprocess.ts +25 -14
  161. package/src/editable-artifact-materializer.ts +29 -18
  162. package/src/github-rest-mcp.ts +713 -0
  163. package/src/http.ts +16 -6
  164. package/src/index.ts +40 -5
  165. package/src/knowledge-source-sync-activity-policy.ts +2 -0
  166. package/src/model-context-contributions.ts +33 -10
  167. package/src/observability-metrics.ts +357 -0
  168. package/src/opensandbox-kubernetes-inventory.ts +292 -0
  169. package/src/personal-github-git-credentials.ts +331 -0
  170. package/src/pr-review-credentials.ts +163 -0
  171. package/src/sandbox-archive-storage.ts +159 -0
  172. package/src/sandbox-resume.ts +449 -63
  173. package/src/sandbox-routing.ts +314 -16
  174. package/src/scheduled-alert-occurrence.ts +176 -0
  175. package/src/workflows/activities.ts +18 -2
  176. package/src/workflows/automations.ts +11 -0
  177. package/src/workflows/session.ts +13 -3
  178. package/src/workflows.ts +1 -0
  179. package/dist/activities-control-BJSDRSIP.js.map +0 -1
  180. package/dist/activities-turn-J5YO7XXX.js +0 -17243
  181. package/dist/activities-turn-J5YO7XXX.js.map +0 -1
  182. package/dist/chunk-N5TJIFCE.js.map +0 -1
  183. package/dist/chunk-P6Z2SLAA.js +0 -3092
  184. package/dist/chunk-P6Z2SLAA.js.map +0 -1
@@ -20,6 +20,10 @@ import {
20
20
  import { publishDurableSessionEvents } from "@opengeni/events";
21
21
  import { deliverFailedChildTurnToParent, notifyParentOfChildIdle } from "./parent-wake";
22
22
  import { recordTurnsQueuedGauge } from "../observability-metrics";
23
+ import {
24
+ MAX_AUTOMATIC_PROVIDER_RECOVERIES,
25
+ providerRecoveryCountFromMetadata,
26
+ } from "./agent-turn/errors";
23
27
  import type {
24
28
  ControlActivityServices,
25
29
  ExpireSessionHumanInputInput,
@@ -370,7 +374,9 @@ export function createSessionStateActivities(
370
374
  turn.id !== input.turnId ||
371
375
  turn.triggerEventId !== input.triggerEventId ||
372
376
  turn.executionGeneration !== input.executionGeneration ||
373
- input.executionGeneration <= 1
377
+ input.executionGeneration <= 1 ||
378
+ input.providerRecoveryCount !== providerRecoveryCountFromMetadata(turn.metadata) + 1 ||
379
+ input.providerRecoveryCount > MAX_AUTOMATIC_PROVIDER_RECOVERIES
374
380
  ) {
375
381
  return { action: "ineligible" };
376
382
  }
@@ -380,10 +386,12 @@ export function createSessionStateActivities(
380
386
  triggerEventId: input.triggerEventId,
381
387
  attemptId: input.attemptId,
382
388
  reason: "mcp_transport_timeout",
389
+ providerRecoveryCount: input.providerRecoveryCount,
383
390
  detail: {
384
391
  code: "mcp_transport_timeout",
385
392
  retryable: true,
386
- continueDelayMs: 60_000,
393
+ continueDelayMs: input.continueDelayMs,
394
+ providerRecoveryCount: input.providerRecoveryCount,
387
395
  recoverySource: "workflow_activity_failure",
388
396
  },
389
397
  fromStatuses: ["running"],
@@ -122,6 +122,8 @@ export type SharedActivityServices = {
122
122
  // workspace BEFORE injecting `GH_TOKEN` (or applying decrypted values). A host
123
123
  // mapping bug returning tenant B's creds for a tenant-A run is caught here.
124
124
  connectionCredentials?: ConnectionCredentialsPort | null;
125
+ /** Standalone, default-off personal GitHub smart-HTTP broker consumer. */
126
+ personalGitHubCredentials?: ConnectionCredentialsPort["gitCredentials"] | null;
125
127
  };
126
128
 
127
129
  /** Control workers own short database and maintenance activities. Document
@@ -290,6 +292,8 @@ export type EscapedMcpTimeoutRecoveryDetail = {
290
292
  turnId: string;
291
293
  triggerEventId: string;
292
294
  executionGeneration: number;
295
+ providerRecoveryCount: number;
296
+ continueDelayMs: number;
293
297
  };
294
298
 
295
299
  export type RecoverEscapedMcpTimeoutInput = EscapedMcpTimeoutRecoveryDetail & {
@@ -343,7 +347,14 @@ export type MaybeContinueGoalInput = {
343
347
  };
344
348
 
345
349
  export type MaybeContinueGoalResult = {
346
- action: "none" | "queue" | "continue" | "paused";
350
+ // `held`: an agent-declared `goal_wait` hold is current. No continuation was
351
+ // materialized and the goal obligation stays armed; the workflow closes like
352
+ // `none` and the wake outbox (deadline) or any producer's signalWithStart
353
+ // restarts it.
354
+ // `deferred`: idle backoff between consecutive no-input continuations. Same
355
+ // shape as `held`: nothing materialized, obligation armed, a delayed outbox
356
+ // wake at the pacing deadline (pulled to now by any new input) restarts it.
357
+ action: "none" | "queue" | "continue" | "paused" | "held" | "deferred";
347
358
  };
348
359
 
349
360
  export type DispatchScheduledTaskRunInput = {
@@ -377,7 +388,14 @@ export type DispatchScheduledTaskRunResult =
377
388
  | "monthly_model_cost_limit"
378
389
  | "monthly_agent_run_limit"
379
390
  | "malformed_manual_trigger"
380
- | "knowledge_source_paused";
391
+ | "scheduled_task_paused"
392
+ | "scheduled_authority_exhausted"
393
+ | "scheduled_run_terminal"
394
+ | "scheduled_execution_unrepresentable"
395
+ | "knowledge_source_paused"
396
+ | "incident_preflight_metadata_missing"
397
+ | "incident_responder_under_capable"
398
+ | "incident_data_source_unsuitable";
381
399
  }
382
400
  | {
383
401
  action: "start" | "signal";
@@ -407,6 +425,18 @@ export type RunKnowledgeSourceSyncBatchInput = {
407
425
  overlapPolicy: "skip" | "buffer_one";
408
426
  };
409
427
 
428
+ export type DispatchAutomationRunInput = {
429
+ accountId: string;
430
+ workspaceId: string;
431
+ runId: string;
432
+ };
433
+
434
+ export type DispatchAutomationRunResult =
435
+ | { action: "started"; sessionId: string }
436
+ | { action: "already_dispatched"; sessionId: string }
437
+ | { action: "skipped"; reason: string }
438
+ | { action: "not_found" };
439
+
410
440
  export type RunKnowledgeSourceSyncBatchResult =
411
441
  | { action: "continue" }
412
442
  | {
@@ -1,5 +1,5 @@
1
1
  import type { GeneratedVideoFacts } from "@opengeni/contracts";
2
- import type { ObjectStorage } from "@opengeni/storage";
2
+ import { retryWhileMissing, type ObjectStorage } from "@opengeni/storage";
3
3
  import { createHash, randomUUID } from "node:crypto";
4
4
  import { open, mkdir, rm, stat } from "node:fs/promises";
5
5
  import { join } from "node:path";
@@ -42,7 +42,7 @@ export async function copyVersionedObjectToVerifiedTemp(input: {
42
42
  throw new Error("Media staging size is invalid");
43
43
  }
44
44
  throwIfAborted(input.signal);
45
- const head = await input.storage.headObject(input.key);
45
+ const head = await retryWhileMissing(async () => await input.storage.headObject!(input.key));
46
46
  if (
47
47
  !head ||
48
48
  head.ContentLength !== input.expectedSizeBytes ||
@@ -93,7 +93,7 @@ export async function copyVersionedObjectToVerifiedTemp(input: {
93
93
  await rm(directory, { recursive: true, force: true });
94
94
  throw new Error("Media staging bytes do not match their sealed digest");
95
95
  }
96
- const after = await input.storage.headObject(input.key);
96
+ const after = await retryWhileMissing(async () => await input.storage.headObject!(input.key));
97
97
  if (!after || after.VersionToken !== versionToken) {
98
98
  await rm(directory, { recursive: true, force: true });
99
99
  throw new Error("Media staging object changed after verification");
@@ -120,19 +120,14 @@ export async function downloadGeneratedVideoToVerifiedTemp(input: {
120
120
  }
121
121
  }
122
122
 
123
- /** Stream verified bytes into an immutable content-addressed object and hash
124
- * the stored generation back through version-fenced Range reads. */
123
+ /** Stream verified bytes into an immutable content-addressed object. */
125
124
  export async function retainVerifiedGeneratedVideo(input: {
126
125
  storage: ObjectStorage;
127
126
  temp: VerifiedTempFile;
128
127
  facts: GeneratedVideoFacts;
129
128
  signal?: AbortSignal;
130
129
  }): Promise<RetainedGeneratedVideo> {
131
- if (
132
- !input.storage.putObjectStreamIfAbsent ||
133
- !input.storage.headObject ||
134
- !input.storage.getObjectRange
135
- ) {
130
+ if (!input.storage.putObjectStreamIfAbsent) {
136
131
  throw new Error("Object storage lacks bounded immutable video primitives");
137
132
  }
138
133
  const objectKey = `video-generation/objects/sha256/${input.temp.sha256}.mp4`;
@@ -145,13 +140,6 @@ export async function retainVerifiedGeneratedVideo(input: {
145
140
  sha256: input.temp.sha256,
146
141
  ...(input.signal ? { signal: input.signal } : {}),
147
142
  });
148
- await verifyStoredObject({
149
- storage: input.storage,
150
- key: objectKey,
151
- expectedSizeBytes: input.temp.sizeBytes,
152
- expectedSha256: input.temp.sha256,
153
- ...(input.signal ? { signal: input.signal } : {}),
154
- });
155
143
  return Object.freeze({
156
144
  bucket: input.storage.bucket,
157
145
  objectKey,
@@ -205,49 +193,6 @@ function requireSafeOutputUrl(rawUrl: string): string {
205
193
  return url.toString();
206
194
  }
207
195
 
208
- async function verifyStoredObject(input: {
209
- storage: ObjectStorage;
210
- key: string;
211
- expectedSizeBytes: number;
212
- expectedSha256: string;
213
- signal?: AbortSignal;
214
- }): Promise<void> {
215
- const head = await input.storage.headObject!(input.key);
216
- if (
217
- !head ||
218
- head.ContentLength !== input.expectedSizeBytes ||
219
- head.ContentType !== "video/mp4" ||
220
- head.Metadata?.sha256 !== input.expectedSha256 ||
221
- !head.VersionToken
222
- ) {
223
- throw new Error("Retained video object metadata is inconsistent");
224
- }
225
- const hash = createHash("sha256");
226
- let offset = 0;
227
- while (offset < input.expectedSizeBytes) {
228
- throwIfAborted(input.signal);
229
- const endInclusive = Math.min(input.expectedSizeBytes - 1, offset + STORAGE_RANGE_BYTES - 1);
230
- const range = await input.storage.getObjectRange!({
231
- key: input.key,
232
- start: offset,
233
- endInclusive,
234
- expectedVersionToken: head.VersionToken,
235
- });
236
- if (
237
- !range ||
238
- range.versionToken !== head.VersionToken ||
239
- range.bytes.byteLength !== endInclusive - offset + 1
240
- ) {
241
- throw new Error("Retained video object changed during verification");
242
- }
243
- hash.update(range.bytes);
244
- offset += range.bytes.byteLength;
245
- }
246
- if (hash.digest("hex") !== input.expectedSha256) {
247
- throw new Error("Retained video object digest is inconsistent");
248
- }
249
- }
250
-
251
196
  async function* fileChunks(path: string, signal?: AbortSignal): AsyncIterable<Uint8Array> {
252
197
  const stream = createReadStream(path, { highWaterMark: STORAGE_RANGE_BYTES });
253
198
  try {
@@ -35,6 +35,9 @@ export async function buildXaiTurnRequestAuthorization(input: {
35
35
  hostedSearch?: XaiSubscriptionRequestContext["hostedSearch"];
36
36
  onFinalContextUsage?: XaiSubscriptionRequestContext["onFinalContextUsage"];
37
37
  nextRequestId?: XaiSubscriptionRequestContext["nextRequestId"];
38
+ streamIdleTimeoutMs?: XaiSubscriptionRequestContext["streamIdleTimeoutMs"];
39
+ onModelRequestDiagnostic?: XaiSubscriptionRequestContext["onModelRequestDiagnostic"];
40
+ onModelRequestEvent?: XaiSubscriptionRequestContext["onModelRequestEvent"];
38
41
  }): Promise<XaiTurnRequestAuthorization> {
39
42
  const encryptionKey = environmentsEncryptionKeyBytes(input.settings);
40
43
  if (!encryptionKey) {
@@ -117,6 +120,11 @@ export async function buildXaiTurnRequestAuthorization(input: {
117
120
  ...(input.hostedSearch ? { hostedSearch: input.hostedSearch } : {}),
118
121
  ...(input.onFinalContextUsage ? { onFinalContextUsage: input.onFinalContextUsage } : {}),
119
122
  ...(input.nextRequestId ? { nextRequestId: input.nextRequestId } : {}),
123
+ ...(input.streamIdleTimeoutMs ? { streamIdleTimeoutMs: input.streamIdleTimeoutMs } : {}),
124
+ ...(input.onModelRequestDiagnostic
125
+ ? { onModelRequestDiagnostic: input.onModelRequestDiagnostic }
126
+ : {}),
127
+ ...(input.onModelRequestEvent ? { onModelRequestEvent: input.onModelRequestEvent } : {}),
120
128
  },
121
129
  };
122
130
  }
@@ -1,6 +1,7 @@
1
1
  import { createSharedActivityServices } from "./activity-services";
2
2
  import { createCodexCapacityActivities } from "./activities/codex-capacity";
3
3
  import { createBrowserStateArtifactMaintenanceActivities } from "./activities/browser-state-artifact-reaper";
4
+ import { createAutomationActivities } from "./activities/automations";
4
5
  import { createDocumentActivities } from "./activities/documents";
5
6
  import { createFileUploadReaperActivities } from "./activities/file-upload-reaper";
6
7
  import { createGoalActivities } from "./activities/goals";
@@ -26,6 +27,7 @@ export function createControlActivitiesFromServices(
26
27
  resolveDocumentServices?: () => Promise<import("@opengeni/documents").DocumentServices>,
27
28
  ) {
28
29
  return {
30
+ ...createAutomationActivities(services),
29
31
  ...createDocumentActivities(services, resolveDocumentServices),
30
32
  ...createKnowledgeSourceSyncActivities(services, resolveDocumentServices),
31
33
  ...createSessionStateActivities(services),
package/src/activities.ts CHANGED
@@ -21,6 +21,8 @@ export type {
21
21
  ControlActivityServices,
22
22
  DispatchScheduledTaskRunInput,
23
23
  DispatchScheduledTaskRunResult,
24
+ DispatchAutomationRunInput,
25
+ DispatchAutomationRunResult,
24
26
  ExpireSessionHumanInputInput,
25
27
  ExpireSessionHumanInputResult,
26
28
  IndexDocumentInput,
@@ -104,6 +106,7 @@ export const expireSessionInteractionIntervention =
104
106
  defaultControlActivities.expireSessionInteractionIntervention;
105
107
  export const markSessionIdle = defaultControlActivities.markSessionIdle;
106
108
  export const dispatchScheduledTaskRun = defaultControlActivities.dispatchScheduledTaskRun;
109
+ export const dispatchAutomationRun = defaultControlActivities.dispatchAutomationRun;
107
110
  export const runKnowledgeSourceSyncBatch = defaultControlActivities.runKnowledgeSourceSyncBatch;
108
111
  export const enqueueGoalRetryWake = defaultControlActivities.enqueueGoalRetryWake;
109
112
  export const maybeContinueGoal = defaultControlActivities.maybeContinueGoal;
@@ -1,10 +1,12 @@
1
1
  import { dbSearchPath, getSettings, resolveNatsControlPlaneAuth } from "@opengeni/config";
2
- import { createDb } from "@opengeni/db";
2
+ import { configureChildLifecycleNotices, createDb } from "@opengeni/db";
3
3
  import { createNatsEventBus } from "@opengeni/events";
4
4
  import { createObservability } from "@opengeni/observability";
5
5
  import { createObjectStorage } from "@opengeni/storage";
6
6
  import type { ActivityDependencies, SharedActivityServices } from "./activities/types";
7
7
  import { observabilityEventLogger } from "./observability-metrics";
8
+ import { buildPersonalGitHubGitCredentials } from "./personal-github-git-credentials";
9
+ import { createStandaloneConnectionCredentialsPort } from "./pr-review-credentials";
8
10
 
9
11
  /**
10
12
  * Build the dependency graph common to both worker roles exactly once.
@@ -32,10 +34,13 @@ export function createSharedActivityServices(
32
34
  rlsStrategy: settings.rlsStrategy,
33
35
  });
34
36
  const controlPlaneAuth = resolveNatsControlPlaneAuth(settings);
35
-
37
+ const db = dependencies.db ?? dbClient!.db;
38
+ // Child lifecycle notice producers are process-global in @opengeni/db;
39
+ // install the boot-validated rollout flag once for this worker.
40
+ configureChildLifecycleNotices({ enabled: settings.childLifecycleNoticesEnabled });
36
41
  return {
37
42
  settings,
38
- db: dependencies.db ?? dbClient!.db,
43
+ db,
39
44
  bus:
40
45
  dependencies.bus ??
41
46
  (await createNatsEventBus(
@@ -54,7 +59,11 @@ export function createSharedActivityServices(
54
59
  startSandboxReaperWorkflow: dependencies.startSandboxReaperWorkflow ?? null,
55
60
  startVideoGenerationWorkflow: dependencies.startVideoGenerationWorkflow ?? null,
56
61
  entitlements: dependencies.entitlements ?? null,
57
- connectionCredentials: dependencies.connectionCredentials ?? null,
62
+ connectionCredentials:
63
+ dependencies.connectionCredentials ??
64
+ createStandaloneConnectionCredentialsPort(settings, db),
65
+ personalGitHubCredentials:
66
+ dependencies.personalGitHubCredentials ?? buildPersonalGitHubGitCredentials(db, settings),
58
67
  };
59
68
  })();
60
69
  return await servicesPromise;
@@ -0,0 +1,36 @@
1
+ import {
2
+ ConnectionUseAuthorizationResult,
3
+ ConnectionUseAuthoritySnapshot,
4
+ type ConnectionUseAttribution,
5
+ type ConnectionUseDenialReason,
6
+ } from "@opengeni/contracts/connection-authority";
7
+
8
+ export class ConnectionProviderUseDeniedError extends Error {
9
+ constructor(readonly reason: ConnectionUseDenialReason) {
10
+ super(`connection provider use denied: ${reason}`);
11
+ this.name = "ConnectionProviderUseDeniedError";
12
+ }
13
+ }
14
+
15
+ /**
16
+ * Performs one uncached authority resolution immediately before one provider
17
+ * request. It never decrypts credentials, retries provider effects, or replaces
18
+ * the frozen connection with another active connection.
19
+ */
20
+ export async function runAuthorizedConnectionProviderUse<T>(input: {
21
+ snapshot: unknown;
22
+ resolveAuthority: (
23
+ snapshot: ConnectionUseAuthoritySnapshot,
24
+ ) => Promise<ConnectionUseAuthorizationResult>;
25
+ invokeProvider: (attribution: ConnectionUseAttribution) => Promise<T>;
26
+ }): Promise<{ value: T; attribution: ConnectionUseAttribution }> {
27
+ const snapshot = ConnectionUseAuthoritySnapshot.parse(input.snapshot);
28
+ const authorization = ConnectionUseAuthorizationResult.parse(
29
+ await input.resolveAuthority(snapshot),
30
+ );
31
+ if (authorization.status === "denied") {
32
+ throw new ConnectionProviderUseDeniedError(authorization.reason);
33
+ }
34
+ const value = await input.invokeProvider(authorization.attribution);
35
+ return { value, attribution: authorization.attribution };
36
+ }
@@ -3,6 +3,11 @@ import { isAbsolute } from "node:path";
3
3
  import type { ChildProcessWithoutNullStreams } from "node:child_process";
4
4
 
5
5
  import { EDITABLE_ARTIFACT_KERNEL_VERSION_MAX_BYTES } from "@opengeni/contracts/editable-artifacts";
6
+ import {
7
+ COMMITTED_TRANSACTION_PROTOCOL_VERSION,
8
+ SPREADSHEET_ARTIFACT_MODEL_SCHEMA_VERSION,
9
+ SPREADSHEET_COLLABORATION_SNAPSHOT_VERSION,
10
+ } from "@opengeni/contracts/editable-artifact-versions";
6
11
 
7
12
  import {
8
13
  EditableArtifactMaterializerPermanentError,
@@ -69,9 +74,9 @@ type IdentityEnvelope = Readonly<{
69
74
  fontRegistryHash: string;
70
75
  policyHash: string;
71
76
  maxOutputBytes: number;
72
- supportedModelSchemaVersions: readonly number[];
73
- supportedOperationProtocolVersions: readonly number[];
74
- supportedSnapshotProtocolVersions: readonly number[];
77
+ supportedModelSchemaVersions: readonly [typeof SPREADSHEET_ARTIFACT_MODEL_SCHEMA_VERSION];
78
+ supportedOperationProtocolVersions: readonly [typeof COMMITTED_TRANSACTION_PROTOCOL_VERSION];
79
+ supportedSnapshotProtocolVersions: readonly [typeof SPREADSHEET_COLLABORATION_SNAPSHOT_VERSION];
75
80
  }>;
76
81
 
77
82
  export type NativeEditableArtifactSubprocessPort = NativeEditableArtifactMaterializerPort &
@@ -762,9 +767,18 @@ function validateIdentity(identity: IdentityEnvelope): void {
762
767
  !isHash(identity.fontRegistryHash) ||
763
768
  !isHash(identity.policyHash) ||
764
769
  !isCodecRegistry(identity.codecVersions) ||
765
- !isCanonicalPositiveVersionList(identity.supportedModelSchemaVersions) ||
766
- !isCanonicalPositiveVersionList(identity.supportedOperationProtocolVersions) ||
767
- !isCanonicalPositiveVersionList(identity.supportedSnapshotProtocolVersions)
770
+ !isCurrentSpreadsheetVersionList(
771
+ identity.supportedModelSchemaVersions,
772
+ SPREADSHEET_ARTIFACT_MODEL_SCHEMA_VERSION,
773
+ ) ||
774
+ !isCurrentSpreadsheetVersionList(
775
+ identity.supportedOperationProtocolVersions,
776
+ COMMITTED_TRANSACTION_PROTOCOL_VERSION,
777
+ ) ||
778
+ !isCurrentSpreadsheetVersionList(
779
+ identity.supportedSnapshotProtocolVersions,
780
+ SPREADSHEET_COLLABORATION_SNAPSHOT_VERSION,
781
+ )
768
782
  ) {
769
783
  throw new Error("native materializer capability identity is incomplete");
770
784
  }
@@ -817,14 +831,11 @@ function isCodecRegistry(value: unknown): value is Readonly<Record<string, strin
817
831
  return true;
818
832
  }
819
833
 
820
- function isCanonicalPositiveVersionList(value: unknown): value is readonly number[] {
821
- if (!Array.isArray(value) || value.length === 0 || value.length > 64) return false;
822
- let previous = 0;
823
- for (const version of value) {
824
- if (!Number.isSafeInteger(version) || version <= previous) return false;
825
- previous = version;
826
- }
827
- return true;
834
+ function isCurrentSpreadsheetVersionList<const Version extends number>(
835
+ value: unknown,
836
+ expected: Version,
837
+ ): value is readonly [Version] {
838
+ return Array.isArray(value) && value.length === 1 && value[0] === expected;
828
839
  }
829
840
 
830
841
  function isBoundedVersion(value: unknown): value is string {
@@ -1,6 +1,11 @@
1
1
  import { createHash } from "node:crypto";
2
2
 
3
3
  import { EDITABLE_ARTIFACT_KERNEL_VERSION_MAX_BYTES } from "@opengeni/contracts/editable-artifacts";
4
+ import {
5
+ COMMITTED_TRANSACTION_PROTOCOL_VERSION,
6
+ SPREADSHEET_ARTIFACT_MODEL_SCHEMA_VERSION,
7
+ SPREADSHEET_COLLABORATION_SNAPSHOT_VERSION,
8
+ } from "@opengeni/contracts/editable-artifact-versions";
4
9
 
5
10
  import type {
6
11
  BoundedImmutableObjectWritePort,
@@ -128,9 +133,9 @@ export type NativeEditableArtifactMaterializerIdentity = Readonly<{
128
133
  fontRegistryHash: string;
129
134
  policyHash: string;
130
135
  runtimeTarget: string;
131
- supportedModelSchemaVersions: readonly number[];
132
- supportedOperationProtocolVersions: readonly number[];
133
- supportedSnapshotProtocolVersions: readonly number[];
136
+ supportedModelSchemaVersions: readonly [typeof SPREADSHEET_ARTIFACT_MODEL_SCHEMA_VERSION];
137
+ supportedOperationProtocolVersions: readonly [typeof COMMITTED_TRANSACTION_PROTOCOL_VERSION];
138
+ supportedSnapshotProtocolVersions: readonly [typeof SPREADSHEET_COLLABORATION_SNAPSHOT_VERSION];
134
139
  }>;
135
140
 
136
141
  export type NativeEditableArtifactMaterializationResult = Readonly<{
@@ -894,19 +899,25 @@ function assertNativeKernelIdentity(
894
899
  boundedText(codecId, "codec id", 128);
895
900
  boundedText(version, "codec version", 128);
896
901
  }
897
- for (const [label, values] of [
898
- ["model schema versions", identity.supportedModelSchemaVersions],
899
- ["operation protocol versions", identity.supportedOperationProtocolVersions],
900
- ["snapshot protocol versions", identity.supportedSnapshotProtocolVersions],
902
+ for (const [label, values, expected] of [
903
+ [
904
+ "model schema versions",
905
+ identity.supportedModelSchemaVersions,
906
+ SPREADSHEET_ARTIFACT_MODEL_SCHEMA_VERSION,
907
+ ],
908
+ [
909
+ "operation protocol versions",
910
+ identity.supportedOperationProtocolVersions,
911
+ COMMITTED_TRANSACTION_PROTOCOL_VERSION,
912
+ ],
913
+ [
914
+ "snapshot protocol versions",
915
+ identity.supportedSnapshotProtocolVersions,
916
+ SPREADSHEET_COLLABORATION_SNAPSHOT_VERSION,
917
+ ],
901
918
  ] as const) {
902
- if (!Array.isArray(values) || values.length === 0 || values.length > 64) {
903
- throw new Error(`Editable artifact kernel ${label} are invalid`);
904
- }
905
- const unique = new Set<number>();
906
- for (const value of values) {
907
- positiveInteger(value, label);
908
- if (unique.has(value)) throw new Error(`Editable artifact kernel ${label} repeat`);
909
- unique.add(value);
919
+ if (!Array.isArray(values) || values.length !== 1 || values[0] !== expected) {
920
+ throw new Error(`Editable artifact kernel ${label} are not current-only`);
910
921
  }
911
922
  }
912
923
  }
@@ -920,9 +931,9 @@ function assertJobKernelCompatibility(
920
931
  identity.codecVersions[job.codecId] === job.codecVersion &&
921
932
  identity.fontRegistryHash === job.fontRegistryHash &&
922
933
  identity.policyHash === job.policyHash &&
923
- identity.supportedModelSchemaVersions.includes(job.modelSchemaVersion) &&
924
- identity.supportedOperationProtocolVersions.includes(job.operationProtocolVersion) &&
925
- identity.supportedSnapshotProtocolVersions.includes(job.snapshotProtocolVersion);
934
+ job.modelSchemaVersion === identity.supportedModelSchemaVersions[0] &&
935
+ job.operationProtocolVersion === identity.supportedOperationProtocolVersions[0] &&
936
+ job.snapshotProtocolVersion === identity.supportedSnapshotProtocolVersions[0];
926
937
  if (!compatible) throw new EditableArtifactMaterializerPermanentError("kernel_incompatible");
927
938
  }
928
939