@opengeni/worker-bundle 0.17.2 → 0.20.1

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 (78) hide show
  1. package/dist/activities/agent-run-admission.d.ts +12 -0
  2. package/dist/activities/agent-turn.d.ts +49 -1
  3. package/dist/activities/browser-state-artifact-reaper.d.ts +29 -0
  4. package/dist/activities/capabilities.d.ts +6 -0
  5. package/dist/activities/codex-capacity.d.ts +1 -0
  6. package/dist/activities/environment.d.ts +7 -1
  7. package/dist/activities/packs.d.ts +8 -10
  8. package/dist/activities/run-input.d.ts +8 -0
  9. package/dist/activities/session-state.d.ts +7 -3
  10. package/dist/activities/site-auth-maintenance.d.ts +27 -0
  11. package/dist/activities/types.d.ts +43 -0
  12. package/dist/activities/video-generation-admission.d.ts +9 -4
  13. package/dist/activities/video-generation-credential.d.ts +17 -0
  14. package/dist/activities/video-reference-staging.d.ts +7 -1
  15. package/dist/activities/xai-auth.d.ts +23 -0
  16. package/dist/activities/xai-image-generation.d.ts +26 -0
  17. package/dist/activities/xai-video-generation.d.ts +18 -0
  18. package/dist/{activities-control-44KBWLSM.js → activities-control-SMKF2OBE.js} +438 -55
  19. package/dist/activities-control-SMKF2OBE.js.map +1 -0
  20. package/dist/activities-control.d.ts +10 -2
  21. package/dist/{activities-turn-K4CEDEGJ.js → activities-turn-IDS3WEHA.js} +6704 -4847
  22. package/dist/activities-turn-IDS3WEHA.js.map +1 -0
  23. package/dist/activities.d.ts +11 -3
  24. package/dist/{chunk-E3RI3I33.js → chunk-N5TJIFCE.js} +156 -10
  25. package/dist/chunk-N5TJIFCE.js.map +1 -0
  26. package/dist/{chunk-KKCRGAGZ.js → chunk-P6Z2SLAA.js} +99 -98
  27. package/dist/chunk-P6Z2SLAA.js.map +1 -0
  28. package/dist/index.d.ts +14 -1
  29. package/dist/index.js +49 -2
  30. package/dist/index.js.map +1 -1
  31. package/dist/model-checkpoint-memory-collector.d.ts +1 -0
  32. package/dist/model-context-contributions.d.ts +40 -0
  33. package/dist/observability-metrics.d.ts +57 -1
  34. package/dist/sandbox-routing.d.ts +4 -0
  35. package/dist/workflow-bundle.js +232 -18
  36. package/dist/workflows/activities.d.ts +1 -1
  37. package/dist/workflows/session.d.ts +17 -1
  38. package/dist/workflows/site-auth-maintenance.d.ts +2 -0
  39. package/dist/workflows.d.ts +1 -0
  40. package/package.json +16 -15
  41. package/src/activities/agent-run-admission.ts +76 -0
  42. package/src/activities/agent-turn.ts +2777 -1241
  43. package/src/activities/browser-state-artifact-reaper.ts +120 -0
  44. package/src/activities/capabilities.ts +10 -0
  45. package/src/activities/codex-capacity.ts +48 -1
  46. package/src/activities/environment.ts +14 -8
  47. package/src/activities/goals.ts +2 -1
  48. package/src/activities/packs.ts +45 -122
  49. package/src/activities/parent-wake.ts +13 -1
  50. package/src/activities/run-input.ts +137 -45
  51. package/src/activities/scheduled-tasks.ts +30 -73
  52. package/src/activities/session-state.ts +87 -5
  53. package/src/activities/site-auth-maintenance.ts +269 -0
  54. package/src/activities/types.ts +44 -0
  55. package/src/activities/video-generation-admission.ts +37 -4
  56. package/src/activities/video-generation-credential.ts +84 -6
  57. package/src/activities/video-generation-reconciliation.ts +212 -19
  58. package/src/activities/video-media-validation.ts +8 -2
  59. package/src/activities/video-reference-staging.ts +121 -34
  60. package/src/activities/xai-auth.ts +122 -0
  61. package/src/activities/xai-image-generation.ts +86 -0
  62. package/src/activities/xai-video-generation.ts +69 -0
  63. package/src/activities-control.ts +4 -0
  64. package/src/activities.ts +7 -0
  65. package/src/index.ts +51 -0
  66. package/src/model-checkpoint-memory-collector.ts +8 -1
  67. package/src/model-context-contributions.ts +159 -0
  68. package/src/observability-metrics.ts +282 -12
  69. package/src/sandbox-routing.ts +13 -0
  70. package/src/workflows/activities.ts +1 -0
  71. package/src/workflows/file-upload-reaper.ts +8 -2
  72. package/src/workflows/session.ts +219 -14
  73. package/src/workflows/site-auth-maintenance.ts +14 -0
  74. package/src/workflows.ts +1 -0
  75. package/dist/activities-control-44KBWLSM.js.map +0 -1
  76. package/dist/activities-turn-K4CEDEGJ.js.map +0 -1
  77. package/dist/chunk-E3RI3I33.js.map +0 -1
  78. package/dist/chunk-KKCRGAGZ.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  observabilityEventLogger
3
- } from "./chunk-E3RI3I33.js";
3
+ } from "./chunk-N5TJIFCE.js";
4
4
 
5
5
  // src/activity-services.ts
6
6
  import { dbSearchPath, getSettings, resolveNatsControlPlaneAuth } from "@opengeni/config";
@@ -48,9 +48,11 @@ function createSharedActivityServices(dependencies) {
48
48
  import {
49
49
  fetchCodexUsageForAccount,
50
50
  getCodexCapacityWaitForSession,
51
+ getXaiCapacityWaitForSession,
51
52
  listCodexAccountStatuses,
52
53
  listPendingCodexCapacityWakeTargets,
53
- reconcileCodexCapacityWait as reconcileCodexCapacityWaitDb
54
+ reconcileCodexCapacityWait as reconcileCodexCapacityWaitDb,
55
+ reconcileXaiCapacityWait as reconcileXaiCapacityWaitDb
54
56
  } from "@opengeni/db";
55
57
 
56
58
  // src/activities/codex-rotation.ts
@@ -476,8 +478,15 @@ async function refreshCapacityMetadata(services, workspaceId) {
476
478
  function createCodexCapacityActivities(services) {
477
479
  async function getCodexCapacityWait(input) {
478
480
  const { db } = await services();
479
- const waiter = await getCodexCapacityWaitForSession(db, input.workspaceId, input.sessionId);
481
+ const codexWaiter = await getCodexCapacityWaitForSession(
482
+ db,
483
+ input.workspaceId,
484
+ input.sessionId
485
+ );
486
+ const xaiWaiter = codexWaiter ? null : await getXaiCapacityWaitForSession(db, input.workspaceId, input.sessionId);
487
+ const waiter = codexWaiter ?? xaiWaiter;
480
488
  return waiter ? {
489
+ ...xaiWaiter ? { provider: "xai" } : {},
481
490
  waiterId: waiter.id,
482
491
  generation: waiter.generation,
483
492
  // A capacity mutation may have committed while its Temporal signal
@@ -490,6 +499,41 @@ function createCodexCapacityActivities(services) {
490
499
  }
491
500
  async function reconcileCodexCapacityWait(input) {
492
501
  const resolved = await services();
502
+ if (input.provider === "xai") {
503
+ const current2 = await getXaiCapacityWaitForSession(
504
+ resolved.db,
505
+ input.workspaceId,
506
+ input.sessionId
507
+ );
508
+ if (!current2 || current2.id !== input.waiterId || current2.generation !== input.generation) {
509
+ return { action: "stale" };
510
+ }
511
+ const result2 = await reconcileXaiCapacityWaitDb(resolved.db, {
512
+ accountId: input.accountId,
513
+ workspaceId: input.workspaceId,
514
+ sessionId: input.sessionId,
515
+ waiterId: input.waiterId,
516
+ generation: input.generation
517
+ });
518
+ if (result2.events.length > 0) {
519
+ try {
520
+ await resolved.bus.publish(input.workspaceId, input.sessionId, result2.events);
521
+ } catch {
522
+ }
523
+ }
524
+ if (result2.action === "resumed") return { action: "resumed" };
525
+ if (result2.action === "waiting") {
526
+ return {
527
+ action: "waiting",
528
+ provider: "xai",
529
+ waiterId: result2.waiter.id,
530
+ generation: result2.waiter.generation,
531
+ nextCheckAt: result2.waiter.nextCheckAt.toISOString(),
532
+ wakeRevision: result2.waiter.wakeRevision
533
+ };
534
+ }
535
+ return { action: result2.action };
536
+ }
493
537
  const current = await getCodexCapacityWaitForSession(
494
538
  resolved.db,
495
539
  input.workspaceId,
@@ -653,10 +697,11 @@ function goalContinuationPrompt(goal, autoContinuation, cap) {
653
697
  return [
654
698
  `[GOAL CONTINUATION ${counter}] The session goal is not done. Goal: ${goal.text}.`,
655
699
  `Success criteria: ${goal.successCriteria ?? "none specified"}.`,
700
+ `Objective revision: ${goal.objectiveRevision}. Mutation policy: ${goal.mutationPolicy}.`,
656
701
  "Continue from the existing conversation state. Do not repeat completed session setup, persistent metadata settings, or context checks merely because this is a new continuation turn.",
657
702
  "Continue working toward the goal now. If it is actually complete, call opengeni__goal_complete with concrete evidence.",
658
703
  "If you are blocked or continuing is not productive, call opengeni__goal_pause with your rationale.",
659
- "You may revise the goal with opengeni__goal_update. Do not stop without one of these explicit actions."
704
+ "Record concrete progress with opengeni__goal_progress. Revise the goal only when explicit user direction or material new evidence justifies the declared change kind; use opengeni__goal_update with this objective revision and a rationale. A rewrite alone is not progress. Do not stop without goal_complete, goal_pause, or concrete continued work."
660
705
  ].join("\n");
661
706
  }
662
707
  function withFirstPartyTools(settings, tools) {
@@ -830,18 +875,15 @@ import {
830
875
  getWorkspace,
831
876
  getWorkspacePack,
832
877
  listInstalledPortableSkills,
833
- listCapabilityInstallations,
834
878
  listPackInstallations
835
879
  } from "@opengeni/db";
836
880
  import {
837
- buildPortableSkillArtifact,
838
- isSkillLibraryEntryId,
839
- loadSkillLibrarySkill
881
+ buildPortableSkillArtifact
840
882
  } from "@opengeni/runtime";
841
883
  var emptyPackRuntime = {
842
884
  sandboxImage: null,
843
885
  sandboxProviderImages: null,
844
- skills: []
886
+ skillActivations: []
845
887
  };
846
888
  async function resolveWorkspacePackRuntime(db, workspaceId) {
847
889
  const installations = await listPackInstallations(db, workspaceId);
@@ -868,92 +910,30 @@ async function resolveWorkspacePackRuntime(db, workspaceId) {
868
910
  function packInstallationUsesLegacyRuntime(installation) {
869
911
  return installation.manifestSnapshot === null && installation.manifestDigest === null;
870
912
  }
871
- async function resolveWorkspaceSkillLibraryRuntime(db, workspaceId) {
872
- const installations = await listCapabilityInstallations(db, workspaceId);
873
- const activeSkills = installations.filter(
874
- (installation) => installation.status === "active" && installation.kind === "skill" && installation.capabilityId.startsWith("skill:") && isSkillLibraryEntryId(installation.capabilityId.slice("skill:".length))
875
- ).sort((a, b) => a.capabilityId.localeCompare(b.capabilityId));
876
- const skillLibrarySkills = [];
877
- const skillLibrarySelections = [];
878
- for (const installation of activeSkills) {
879
- const metadata = parseSkillLibraryInstallationMetadata(
880
- installation.metadata,
881
- installation.capabilityId
882
- );
883
- if (installation.capabilityId !== `skill:${metadata.libraryId}`) {
884
- throw new Error(
885
- `Skill installation id does not match its library entry: ${installation.capabilityId} -> ${metadata.libraryId}`
886
- );
887
- }
888
- const loaded = loadSkillLibrarySkill(metadata.libraryId, metadata.libraryVersion);
889
- if (installation.config.version !== metadata.libraryVersion) {
913
+ async function resolveWorkspaceInstalledSkillRuntime(db, workspaceId) {
914
+ const installedSkills = await listInstalledPortableSkills(db, workspaceId);
915
+ const activations = [];
916
+ for (const installed of installedSkills) {
917
+ const artifact = buildPortableSkillArtifact(installed.files);
918
+ if (artifact.name !== installed.name || artifact.description !== installed.description || artifact.contentSha256 !== installed.contentSha256) {
890
919
  throw new Error(
891
- `Skill installation version mismatch for ${metadata.libraryId}@${metadata.libraryVersion}: config has ${String(installation.config.version)}`
920
+ `Installed Skill artifact verification failed for ${installed.capabilityId}; reinstall it from the pinned source`
892
921
  );
893
922
  }
894
- if (loaded.entry.contentSha256 !== metadata.contentSha256) {
895
- throw new Error(
896
- `Skill installation hash mismatch for ${metadata.libraryId}@${metadata.libraryVersion}: expected ${metadata.contentSha256}, catalog has ${loaded.entry.contentSha256}`
897
- );
898
- }
899
- if (loaded.entry.sourceCommit !== metadata.sourceCommit || loaded.entry.provenance !== metadata.provenance) {
900
- throw new Error(
901
- `Skill installation provenance mismatch for ${metadata.libraryId}@${metadata.libraryVersion}; re-enable the skill from the current catalog`
902
- );
903
- }
904
- skillLibrarySkills.push({
905
- name: loaded.skill.name,
906
- description: loaded.skill.description,
907
- files: loaded.skill.files.map((file) => ({ path: file.path, content: file.content }))
908
- });
909
- skillLibrarySelections.push({
910
- id: loaded.entry.id,
911
- name: loaded.entry.name,
912
- source: "library",
913
- version: loaded.entry.version,
914
- contentSha256: loaded.entry.contentSha256,
915
- reason: "enabled workspace capability installation"
916
- });
917
- }
918
- const importedSkills = await listInstalledPortableSkills(db, workspaceId);
919
- for (const imported of importedSkills) {
920
- const artifact = buildPortableSkillArtifact(imported.files);
921
- if (artifact.name !== imported.name || artifact.description !== imported.description || artifact.contentSha256 !== imported.contentSha256) {
922
- throw new Error(
923
- `Imported Skill artifact verification failed for ${imported.capabilityId}; reinstall it from the pinned source`
924
- );
925
- }
926
- skillLibrarySkills.push({
927
- name: artifact.name,
928
- description: artifact.description,
929
- files: artifact.files.map((file) => ({ path: file.path, content: file.content }))
930
- });
931
- skillLibrarySelections.push({
932
- id: imported.capabilityId,
933
- name: artifact.name,
934
- source: "imported",
935
- version: imported.sourceCommit,
923
+ activations.push({
924
+ source: "installation",
925
+ id: installed.capabilityId,
926
+ artifact: {
927
+ name: artifact.name,
928
+ description: artifact.description,
929
+ files: artifact.files.map((file) => ({ path: file.path, content: file.content }))
930
+ },
931
+ version: installed.version,
936
932
  contentSha256: artifact.contentSha256,
937
- reason: `installed from ${imported.sourceUrl}`
933
+ reason: installed.source === "library" ? "installed from the curated Skill library" : installed.source === "pack" ? "installed as a Pack-owned Skill" : `installed from ${installed.sourceUrl}`
938
934
  });
939
935
  }
940
- return { skillLibrarySkills, skillLibrarySelections };
941
- }
942
- function parseSkillLibraryInstallationMetadata(metadata, capabilityId) {
943
- const libraryId = stringMetadata(metadata.libraryId);
944
- const libraryVersion = stringMetadata(metadata.libraryVersion);
945
- const contentSha256 = stringMetadata(metadata.contentSha256);
946
- const sourceCommit = stringMetadata(metadata.sourceCommit);
947
- const provenance = stringMetadata(metadata.provenance);
948
- if (!libraryId || !libraryVersion || !contentSha256 || !sourceCommit || !provenance) {
949
- throw new Error(
950
- `Skill installation ${capabilityId} is missing immutable library metadata; re-enable the skill from the current catalog`
951
- );
952
- }
953
- return { libraryId, libraryVersion, contentSha256, sourceCommit, provenance };
954
- }
955
- function stringMetadata(value) {
956
- return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
936
+ return { activations };
957
937
  }
958
938
  function workspacePackRuntimeFromPacks(packs) {
959
939
  const imagePacks = packs.filter(
@@ -965,7 +945,7 @@ function workspacePackRuntimeFromPacks(packs) {
965
945
  `Multiple enabled packs declare a sandbox image (${ids}). Only one enabled pack per workspace may declare sandboxImage; disable the others and retry.`
966
946
  );
967
947
  }
968
- const skills = [];
948
+ const skillActivations = [];
969
949
  const skillOwners = /* @__PURE__ */ new Map();
970
950
  for (const pack of [...packs].sort((a, b) => a.id.localeCompare(b.id))) {
971
951
  for (const skill of pack.skills) {
@@ -977,17 +957,23 @@ function workspacePackRuntimeFromPacks(packs) {
977
957
  );
978
958
  }
979
959
  skillOwners.set(key, pack.id);
980
- skills.push({
960
+ const artifact = {
981
961
  name: skill.name,
982
962
  description: skill.description ?? null,
983
963
  files: skill.files.map((file) => ({ path: file.path, content: file.content }))
964
+ };
965
+ skillActivations.push({
966
+ source: "pack",
967
+ id: `pack:${pack.id}:${skill.name}`,
968
+ artifact,
969
+ reason: `active legacy Pack ${pack.id}`
984
970
  });
985
971
  }
986
972
  }
987
973
  return {
988
974
  sandboxImage: imagePacks[0]?.sandboxImage?.trim() ?? null,
989
975
  sandboxProviderImages: imagePacks[0]?.sandboxProviderImages ?? null,
990
- skills
976
+ skillActivations
991
977
  };
992
978
  }
993
979
  function mergeRigDefaultVariableSetEnvironment(rigDefaultValues, sessionValues) {
@@ -1173,6 +1159,7 @@ import {
1173
1159
  getSession,
1174
1160
  getSessionGoal as getSessionGoal2,
1175
1161
  getSessionParentPersonalConnectionDelegations,
1162
+ getSessionParentXaiProviderAccountAuthority,
1176
1163
  addSessionSystemUpdateWithSourceMutation,
1177
1164
  claimPendingSessionSystemUpdateOutbox,
1178
1165
  claimPendingSessionWorkflowWakes,
@@ -1196,6 +1183,11 @@ async function notifyParentOfChildIdle(svc, workspaceId, childSessionId, episode
1196
1183
  workspaceId,
1197
1184
  childSessionId
1198
1185
  );
1186
+ const xaiAuthority = await getSessionParentXaiProviderAccountAuthority(
1187
+ svc.db,
1188
+ workspaceId,
1189
+ childSessionId
1190
+ );
1199
1191
  const outbox = await getOrCreateSessionSystemUpdateOutbox(svc.db, {
1200
1192
  accountId: child.accountId,
1201
1193
  workspaceId,
@@ -1207,8 +1199,13 @@ async function notifyParentOfChildIdle(svc, workspaceId, childSessionId, episode
1207
1199
  dedupeKey: clientEventId,
1208
1200
  summary: childCompletionSummary(child, goal, "idle"),
1209
1201
  payload,
1210
- lineage: { childSessionId: child.id, parentSessionId: child.parentSessionId },
1211
- personalConnectionDelegations
1202
+ lineage: {
1203
+ childSessionId: child.id,
1204
+ parentSessionId: child.parentSessionId,
1205
+ ...xaiAuthority.subjectId ? { xaiAuthoritySubjectId: xaiAuthority.subjectId } : {}
1206
+ },
1207
+ personalConnectionDelegations,
1208
+ xaiProviderAccountAuthoritySnapshot: xaiAuthority.snapshot
1212
1209
  });
1213
1210
  if (outbox.status === "delivered") {
1214
1211
  return;
@@ -1259,7 +1256,8 @@ async function deliverParentSystemUpdateOutbox(svc, outbox) {
1259
1256
  summary: outbox.summary,
1260
1257
  payload: outbox.payload,
1261
1258
  lineage: outbox.lineage,
1262
- personalConnectionDelegations: outbox.personalConnectionDelegations
1259
+ personalConnectionDelegations: outbox.personalConnectionDelegations,
1260
+ xaiProviderAccountAuthoritySnapshot: outbox.xaiProviderAccountAuthoritySnapshot
1263
1261
  },
1264
1262
  async (tx) => {
1265
1263
  await markSessionSystemUpdateOutboxDeliveredInTransaction(tx, outbox);
@@ -2738,6 +2736,7 @@ function wrapTurnBoxWithRouting(services, ids, established) {
2738
2736
  // environment variables" throw when the turn pins to a vm). Mirrors the group
2739
2737
  // box, which is created WITH this same environment (resumeBoxForTurn).
2740
2738
  ...ids.environment !== void 0 ? { environment: ids.environment } : {},
2739
+ ...ids.transientExecEnvironment !== void 0 ? { transientExecEnvironment: ids.transientExecEnvironment } : {},
2741
2740
  // Stage D machine-primary: pin THIS established SelfhostedSession for the machine
2742
2741
  // pointer so the resolver returns the SAME instance (no two-instance manifest
2743
2742
  // divergence). `established.session` is the SelfhostedSession the establish branch
@@ -2878,7 +2877,8 @@ function wrapLazyTurnBoxWithRouting(services, ids, args) {
2878
2877
  relay: relayConfigFromSettings(settings),
2879
2878
  ...selfhostedResolverTimeouts(settings),
2880
2879
  ...onOp !== void 0 ? { selfhostedOnOp: onOp } : {},
2881
- ...ids.environment !== void 0 ? { environment: ids.environment } : {}
2880
+ ...ids.environment !== void 0 ? { environment: ids.environment } : {},
2881
+ ...ids.transientExecEnvironment !== void 0 ? { transientExecEnvironment: ids.transientExecEnvironment } : {}
2882
2882
  });
2883
2883
  const proxy = new RoutingSandboxSession({
2884
2884
  // Before the first op the SDK reads `state.manifest`; the synthetic backend
@@ -2987,6 +2987,7 @@ async function establishSelfhostedTurnSession(services, args) {
2987
2987
  controlRpcFactory: controlRpcFactory(bus),
2988
2988
  epoch: args.epoch,
2989
2989
  environment: args.environment,
2990
+ ...args.transientExecEnvironment !== void 0 ? { transientExecEnvironment: args.transientExecEnvironment } : {},
2990
2991
  workingDir: args.workingDir,
2991
2992
  // Give this turn's exec ops the long deadline (control ops stay short) so a real
2992
2993
  // command is not killed at the control wall.
@@ -3062,7 +3063,7 @@ export {
3062
3063
  rigProviderImageSourceImage,
3063
3064
  settingsWithRigProviderImage,
3064
3065
  resolveWorkspacePackRuntime,
3065
- resolveWorkspaceSkillLibraryRuntime,
3066
+ resolveWorkspaceInstalledSkillRuntime,
3066
3067
  mergeRigDefaultVariableSetEnvironment,
3067
3068
  createRuntimeBatcher,
3068
3069
  currentActivityContext,
@@ -3088,4 +3089,4 @@ export {
3088
3089
  workflowIdForSession,
3089
3090
  mergeResourceRefs
3090
3091
  };
3091
- //# sourceMappingURL=chunk-KKCRGAGZ.js.map
3092
+ //# sourceMappingURL=chunk-P6Z2SLAA.js.map