@opengeni/worker-bundle 0.20.1 → 0.20.3

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.
package/dist/index.js CHANGED
@@ -711,7 +711,7 @@ function temporalWorkflowExecutionNotFound(error) {
711
711
  return isGrpcServiceError(error) && error.code === 5;
712
712
  }
713
713
  async function createDefaultWorkerActivities(role, dependencies = {}) {
714
- return role === "control" ? (await import("./activities-control-SMKF2OBE.js")).createControlActivities(dependencies) : (await import("./activities-turn-IDS3WEHA.js")).createTurnActivities(dependencies);
714
+ return role === "control" ? (await import("./activities-control-BJSDRSIP.js")).createControlActivities(dependencies) : (await import("./activities-turn-J5YO7XXX.js")).createTurnActivities(dependencies);
715
715
  }
716
716
  function resolveOpenGeniWorkflowDefinition(moduleUrl = import.meta.url) {
717
717
  const modulePath = fileURLToPath(moduleUrl).replaceAll("\\", "/");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeni/worker-bundle",
3
- "version": "0.20.1",
3
+ "version": "0.20.3",
4
4
  "description": "OpenGeni worker entry and reusable embedded lifecycle, shipped with a release-coherent pre-bundled Temporal workflow artifact.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -56,19 +56,19 @@
56
56
  "@llamaindex/liteparse": "^1.5.3",
57
57
  "@opengeni/agent-proto": "^0.5.0",
58
58
  "@opengeni/capabilities": "^0.2.0",
59
- "@opengeni/codemode": "^0.4.2",
59
+ "@opengeni/codemode": "^0.4.4",
60
60
  "@opengeni/codex": "^0.2.17",
61
- "@opengeni/config": "^0.16.2",
62
- "@opengeni/contracts": "^0.50.0",
63
- "@opengeni/core": "^0.28.1",
64
- "@opengeni/db": "^0.36.1",
65
- "@opengeni/documents": "^0.5.39",
66
- "@opengeni/events": "^0.3.110",
67
- "@opengeni/github": "^0.4.57",
61
+ "@opengeni/config": "^0.16.4",
62
+ "@opengeni/contracts": "^1.0.1",
63
+ "@opengeni/core": "^1.0.1",
64
+ "@opengeni/db": "^1.0.1",
65
+ "@opengeni/documents": "^0.5.41",
66
+ "@opengeni/events": "^0.3.112",
67
+ "@opengeni/github": "^0.4.59",
68
68
  "@opengeni/network": "^0.2.2",
69
- "@opengeni/observability": "^0.7.5",
70
- "@opengeni/runtime": "^0.23.1",
71
- "@opengeni/storage": "^0.2.94",
69
+ "@opengeni/observability": "^0.7.7",
70
+ "@opengeni/runtime": "^1.0.1",
71
+ "@opengeni/storage": "^0.2.96",
72
72
  "@opengeni/xai-subscription": "^0.1.0",
73
73
  "@temporalio/activity": "^1.17.0",
74
74
  "@temporalio/client": "^1.17.0",
@@ -9,7 +9,9 @@ import {
9
9
  getRigName,
10
10
  getRigVersion,
11
11
  getSandbox,
12
+ getFilesForSubject,
12
13
  readActiveSandbox,
14
+ requireFileForSubject,
13
15
  setActiveSandbox,
14
16
  requireFile,
15
17
  getSessionEvent,
@@ -168,6 +170,7 @@ import {
168
170
  type ModelCallUsageInput,
169
171
  type ModelCallUsageNormalization,
170
172
  type BuildAgentOptions,
173
+ type AttemptConnectorActionBinding,
171
174
  type ConnectorActionPolicyHooks,
172
175
  type TurnToolCancellationFence,
173
176
  type BackendUnresolvableCode,
@@ -181,6 +184,12 @@ import {
181
184
  deleteRecordingArtifacts,
182
185
  stopRecording as stopRecordingOnBox,
183
186
  } from "@opengeni/runtime";
187
+ import {
188
+ authorizeGoogleDrivePublicationAttempt,
189
+ createGoogleDrivePublicationAttemptTool,
190
+ googleDrivePublicationConnectorCall,
191
+ resolveGoogleDrivePublicationTarget,
192
+ } from "./google-drive-publication";
184
193
  import { connectionTokenResolverForTurn } from "./mcp-credentials";
185
194
  import { buildApiIntegrationServersForTurn } from "./api-integrations";
186
195
  import {
@@ -668,7 +677,7 @@ export function providerRetryAfterMs(error: unknown, nowMs = Date.now()): number
668
677
  * this notice prevents a graceful runtime drop from becoming a silent source-
669
678
  * of-truth substitution or a false claim that the disconnected system was read.
670
679
  */
671
- export function unavailableMcpTurnInstructions(input: {
680
+ export function unavailableMcpOperationalContext(input: {
672
681
  droppedIds: readonly string[];
673
682
  droppedCount: number;
674
683
  }): string | undefined {
@@ -4183,6 +4192,7 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
4183
4192
  providerRecoveryCount = providerRecoveryCountFromMetadata(turn.metadata);
4184
4193
  let installedApiIntegrations: readonly ApiIntegrationRuntime[] = [];
4185
4194
  const credentialSubjectId = credentialSubjectIdForTurnInitiator(turn);
4195
+ const fileAuthoritySubjectId = turn.initiatingHumanSubjectId ?? null;
4186
4196
  const mcpSettings = await settingsWithEnabledCapabilityMcpServers(
4187
4197
  db,
4188
4198
  input.workspaceId,
@@ -5500,9 +5510,23 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
5500
5510
  modelCanReceiveRetainedSessionImages = supportsImageInput;
5501
5511
  const attachmentProjector = createModelHistoryAttachmentProjector(
5502
5512
  db,
5503
- input.workspaceId,
5513
+ {
5514
+ accountId: input.accountId,
5515
+ workspaceId: input.workspaceId,
5516
+ subjectId: fileAuthoritySubjectId,
5517
+ },
5504
5518
  modelInputPolicy,
5505
- objectStorage ? (file) => objectStorage.getFileBytes(file) : undefined,
5519
+ objectStorage
5520
+ ? async (file) => {
5521
+ await requireFileForSubject(db, {
5522
+ accountId: input.accountId,
5523
+ workspaceId: input.workspaceId,
5524
+ subjectId: fileAuthoritySubjectId,
5525
+ fileId: file.id,
5526
+ });
5527
+ return await objectStorage.getFileBytes(file);
5528
+ }
5529
+ : undefined,
5506
5530
  );
5507
5531
  const modelHistoryProjector = async (items: Array<Record<string, unknown>>) =>
5508
5532
  projectModelInputForCapabilities(await attachmentProjector(items), modelInputPolicy);
@@ -6103,7 +6127,7 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
6103
6127
  availableMcpServerIds: runSettings.mcpServers.map((server) => server.id),
6104
6128
  defaultMcpServerIds: defaultSessionMcpServerIds(capabilitySettings.mcpServers),
6105
6129
  });
6106
- const mcpAvailabilityInstructions = unavailableMcpTurnInstructions({
6130
+ const mcpAvailabilityNote = unavailableMcpOperationalContext({
6107
6131
  droppedIds: resolvedToolPolicy.effectivePolicy.droppedIds,
6108
6132
  droppedCount: resolvedToolPolicy.effectivePolicy.counts.dropped,
6109
6133
  });
@@ -6328,6 +6352,13 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
6328
6352
  if (activeSandboxBackend !== "selfhosted") {
6329
6353
  await assertGitHubResourcesRemainAuthorized(db, input.workspaceId, turnResources);
6330
6354
  }
6355
+ await assertFileResourcesRemainAuthorized(
6356
+ db,
6357
+ input.accountId,
6358
+ input.workspaceId,
6359
+ fileAuthoritySubjectId,
6360
+ turnResources,
6361
+ );
6331
6362
  const authorizeGitHubTokenMint: GitHubTokenMintAuthorization = async (selection) => {
6332
6363
  await assertGitHubTokenMintSelectionAuthorized(
6333
6364
  db,
@@ -7040,7 +7071,9 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
7040
7071
  runSettings,
7041
7072
  db,
7042
7073
  objectStorage,
7074
+ input.accountId,
7043
7075
  input.workspaceId,
7076
+ fileAuthoritySubjectId,
7044
7077
  turnResources,
7045
7078
  activeSandboxBackend ?? groupBoxBackend,
7046
7079
  ),
@@ -7131,6 +7164,37 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
7131
7164
  }
7132
7165
  return result;
7133
7166
  };
7167
+ const connectorActionIdentity = {
7168
+ accountId: input.accountId,
7169
+ workspaceId: input.workspaceId,
7170
+ sessionId: input.sessionId,
7171
+ turnId: turn.id,
7172
+ attemptId: input.attemptId,
7173
+ executionGeneration,
7174
+ initiator: {
7175
+ kind: turn.initiator.kind,
7176
+ subjectId: turn.initiator.subjectId,
7177
+ },
7178
+ } as const;
7179
+ const googleDrivePublicationTarget = objectStorage
7180
+ ? await resolveGoogleDrivePublicationTarget(
7181
+ db,
7182
+ input.workspaceId,
7183
+ personalConnectionDelegations,
7184
+ )
7185
+ : null;
7186
+ const googleDrivePublicationTool =
7187
+ objectStorage && googleDrivePublicationTarget
7188
+ ? createGoogleDrivePublicationAttemptTool({
7189
+ db,
7190
+ objectStorage,
7191
+ identity: connectorActionIdentity,
7192
+ subjectId: googleDrivePublicationTarget.ownerSubjectId,
7193
+ target: googleDrivePublicationTarget,
7194
+ resolveCredential,
7195
+ ...(runtimeCancellationSignal ? { signal: runtimeCancellationSignal } : {}),
7196
+ })
7197
+ : null;
7134
7198
  const publishToolAuthNeeded = async (payload: ToolAuthNeededPayload): Promise<void> => {
7135
7199
  if (!shouldPublishToolAuthNeededForTurn(payload, trigger, turn)) {
7136
7200
  return;
@@ -7189,6 +7253,51 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
7189
7253
  runSettings,
7190
7254
  session.firstPartyMcpTools,
7191
7255
  );
7256
+ const googleDrivePublicationAllowed =
7257
+ selectedFirstPartyMcpTools.includes("editable_artifact_export") &&
7258
+ selectedFirstPartyMcpTools.includes("editable_artifact_export_status") &&
7259
+ (!session.firstPartyMcpPermissions?.length ||
7260
+ (session.firstPartyMcpPermissions.includes("artifacts:read") &&
7261
+ session.firstPartyMcpPermissions.includes("artifacts:publish")));
7262
+ const googleDriveConnectorBindings: readonly AttemptConnectorActionBinding[] =
7263
+ googleDrivePublicationTool && googleDrivePublicationTarget && googleDrivePublicationAllowed
7264
+ ? [
7265
+ {
7266
+ modelName: googleDrivePublicationTool.modelName,
7267
+ call: (approvalId, arguments_) =>
7268
+ googleDrivePublicationConnectorCall(
7269
+ googleDrivePublicationTarget,
7270
+ arguments_,
7271
+ approvalId,
7272
+ ),
7273
+ },
7274
+ ]
7275
+ : [];
7276
+ const attemptToolDefinitions = [
7277
+ ...createFirstPartyInteractionAttemptToolDefinitions({
7278
+ settings: runSettings,
7279
+ scope: {
7280
+ accountId: input.accountId,
7281
+ workspaceId: input.workspaceId,
7282
+ sessionId: input.sessionId,
7283
+ turnId: turn.id,
7284
+ attemptId: input.attemptId,
7285
+ executionGeneration,
7286
+ },
7287
+ ...(session.firstPartyMcpPermissions?.length
7288
+ ? { permissions: session.firstPartyMcpPermissions }
7289
+ : {}),
7290
+ selectedTools: selectedFirstPartyMcpTools,
7291
+ subjectId: "worker:first-party-mcp",
7292
+ subjectLabel: "OpenGeni worker",
7293
+ ...(interactionInterventionResume
7294
+ ? { interventionResume: interactionInterventionResume }
7295
+ : {}),
7296
+ }),
7297
+ ...(googleDrivePublicationTool && googleDrivePublicationAllowed
7298
+ ? [googleDrivePublicationTool]
7299
+ : []),
7300
+ ];
7192
7301
  recordTurnStartupPhase(observability, {
7193
7302
  phase: "tool_context_preparation",
7194
7303
  provider: turnExecutionPolicy.providerId,
@@ -7239,26 +7348,27 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
7239
7348
  firstPartyTools: selectedFirstPartyMcpTools,
7240
7349
  nestedAgentDepth: session.nestedAgentDepth,
7241
7350
  effectiveMaxNestedAgentDepth: session.effectiveMaxNestedAgentDepth,
7242
- attemptToolDefinitions: createFirstPartyInteractionAttemptToolDefinitions({
7243
- settings: runSettings,
7244
- scope: {
7245
- accountId: input.accountId,
7246
- workspaceId: input.workspaceId,
7247
- sessionId: input.sessionId,
7248
- turnId: turn.id,
7249
- attemptId: input.attemptId,
7250
- executionGeneration,
7251
- },
7252
- ...(session.firstPartyMcpPermissions?.length
7253
- ? { permissions: session.firstPartyMcpPermissions }
7254
- : {}),
7255
- selectedTools: selectedFirstPartyMcpTools,
7256
- subjectId: "worker:first-party-mcp",
7257
- subjectLabel: "OpenGeni worker",
7258
- ...(interactionInterventionResume
7259
- ? { interventionResume: interactionInterventionResume }
7260
- : {}),
7261
- }),
7351
+ attemptToolDefinitions,
7352
+ ...(googleDrivePublicationTarget && googleDrivePublicationAllowed
7353
+ ? {
7354
+ attemptToolAuthorize: async ({ call }) => {
7355
+ if (
7356
+ call.caller.kind !== "codemode" ||
7357
+ call.identity.serverId !== "google-drive-publishing" ||
7358
+ call.identity.toolName !== "google_drive_publish_file"
7359
+ ) {
7360
+ return;
7361
+ }
7362
+ await authorizeGoogleDrivePublicationAttempt({
7363
+ db,
7364
+ identity: connectorActionIdentity,
7365
+ target: googleDrivePublicationTarget,
7366
+ approvalId: call.operationId,
7367
+ arguments: call.arguments,
7368
+ });
7369
+ },
7370
+ }
7371
+ : {}),
7262
7372
  }),
7263
7373
  cancellationSignal,
7264
7374
  async (latePreparedTools) => await latePreparedTools.close().catch(() => undefined),
@@ -7338,7 +7448,9 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
7338
7448
  await resolveImageGenerationReferences({
7339
7449
  db,
7340
7450
  objectStorage: objectStorage!,
7451
+ accountId: input.accountId,
7341
7452
  workspaceId: input.workspaceId,
7453
+ subjectId: fileAuthoritySubjectId,
7342
7454
  references,
7343
7455
  readSandboxFile: async (path, maxBytes) => {
7344
7456
  const imageReferenceSession = (setupBoxSession ??
@@ -7648,18 +7760,6 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
7648
7760
  turnExecutionPolicy.providerId,
7649
7761
  turnExecutionPolicy.latencyMode,
7650
7762
  );
7651
- const connectorActionIdentity = {
7652
- accountId: input.accountId,
7653
- workspaceId: input.workspaceId,
7654
- sessionId: input.sessionId,
7655
- turnId,
7656
- attemptId: input.attemptId,
7657
- executionGeneration,
7658
- initiator: {
7659
- kind: turn.initiator.kind,
7660
- subjectId: turn.initiator.subjectId,
7661
- },
7662
- } as const;
7663
7763
  const connectorActionPolicy: ConnectorActionPolicyHooks = {
7664
7764
  prepare: async (call) =>
7665
7765
  await prepareConnectorActionApproval(db, connectorActionIdentity, call),
@@ -7751,6 +7851,7 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
7751
7851
  mcpServers: preparedTools.mcpServers,
7752
7852
  resolvedMcpConnectionIds: preparedTools.resolvedMcpConnectionIds,
7753
7853
  connectorActionPolicy,
7854
+ attemptConnectorActionBindings: googleDriveConnectorBindings,
7754
7855
  // LIVE by-reference connector namespaces (fills during this turn's
7755
7856
  // codex_apps tools/list): the codex tool_search description reads it per
7756
7857
  // model call so the model sees the account's real connected sources.
@@ -7831,15 +7932,6 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
7831
7932
  // Composed system-level AFTER the workspace persona so it refines it for
7832
7933
  // this one session; absent ⇒ byte-identical to today's composition.
7833
7934
  ...(session.instructions ? { sessionInstructions: session.instructions } : {}),
7834
- // Exact host context captured when this turn was accepted. It is
7835
- // system-level and disappears with the turn rather than entering chat.
7836
- ...(turn.turnInstructions || mcpAvailabilityInstructions
7837
- ? {
7838
- turnInstructions: [turn.turnInstructions, mcpAvailabilityInstructions]
7839
- .filter((value): value is string => Boolean(value))
7840
- .join(" "),
7841
- }
7842
- : {}),
7843
7935
  ...workspaceEnvironmentOption,
7844
7936
  // RIG RUNTIME (M3): the doctrine block, the setup-script hook (only when
7845
7937
  // the frozen version carries a non-empty script), and the rig credential
@@ -8551,9 +8643,14 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
8551
8643
  try {
8552
8644
  const prepared = await turnInput(db, runtime, agent, trigger, {
8553
8645
  turnId: activeTurnId,
8646
+ fileAuthority: {
8647
+ accountId: input.accountId,
8648
+ subjectId: fileAuthoritySubjectId,
8649
+ },
8554
8650
  recovering: turn.executionGeneration > 1,
8555
8651
  ...(unavailableSandboxFilesNote ? { unavailableSandboxFilesNote } : {}),
8556
8652
  ...(runCredentialsNote ? { runCredentialsNote } : {}),
8653
+ ...(mcpAvailabilityNote ? { mcpAvailabilityNote } : {}),
8557
8654
  providerApi,
8558
8655
  projectCanonicalHistory: generatedImageHistoryProjector,
8559
8656
  materializeModelHistory: materializeScreenshotHistory,
@@ -11581,6 +11678,28 @@ async function assertGitHubResourcesRemainAuthorized(
11581
11678
  }
11582
11679
  }
11583
11680
 
11681
+ async function assertFileResourcesRemainAuthorized(
11682
+ db: ActivityServices["db"],
11683
+ accountId: string,
11684
+ workspaceId: string,
11685
+ subjectId: string | null,
11686
+ resources: ResourceRef[],
11687
+ ): Promise<void> {
11688
+ const fileIds = resources.flatMap((resource) =>
11689
+ resource.kind === "file" ? [resource.fileId] : [],
11690
+ );
11691
+ if (fileIds.length === 0) return;
11692
+ const authorized = await getFilesForSubject(db, {
11693
+ accountId,
11694
+ workspaceId,
11695
+ subjectId,
11696
+ fileIds,
11697
+ });
11698
+ if (authorized.length !== new Set(fileIds).size) {
11699
+ throw new Error("One or more file resources are unavailable or no longer authorized");
11700
+ }
11701
+ }
11702
+
11584
11703
  async function assertGitHubTokenMintSelectionAuthorized(
11585
11704
  db: Parameters<typeof areGitHubRepositoriesAllowedForWorkspace>[0],
11586
11705
  workspaceId: string,
@@ -12494,7 +12613,9 @@ async function sandboxFileDownloadsForRun(
12494
12613
  settings: Settings,
12495
12614
  db: ActivityServices["db"],
12496
12615
  objectStorage: ObjectStorage | null,
12616
+ accountId: string,
12497
12617
  workspaceId: string,
12618
+ subjectId: string | null,
12498
12619
  resources: ResourceRef[],
12499
12620
  activeSandboxBackend: Settings["sandboxBackend"] = settings.sandboxBackend,
12500
12621
  ): Promise<SandboxFileDownload[]> {
@@ -12515,7 +12636,12 @@ async function sandboxFileDownloadsForRun(
12515
12636
  const downloadStorage = objectStorageForSandboxDownloads(settings, objectStorage);
12516
12637
  const downloads: SandboxFileDownload[] = [];
12517
12638
  for (const resource of fileResources) {
12518
- const file = await requireFile(db, workspaceId, resource.fileId);
12639
+ const file = await requireFileForSubject(db, {
12640
+ accountId,
12641
+ workspaceId,
12642
+ subjectId,
12643
+ fileId: resource.fileId,
12644
+ });
12519
12645
  const url = await downloadStorage.createGetUrl({ key: file.objectKey });
12520
12646
  downloads.push({
12521
12647
  fileId: file.id,
@@ -23,7 +23,7 @@ export function createDocumentActivities(
23
23
  if (!resolveDocumentServices) {
24
24
  throw new Error("document services are not configured");
25
25
  }
26
- const [{ getDocument, indexDocumentNow }, documentServices] = await Promise.all([
26
+ const [{ getDocumentForIndexing, indexDocumentNow }, documentServices] = await Promise.all([
27
27
  import("@opengeni/documents"),
28
28
  resolveDocumentServices(),
29
29
  ]);
@@ -57,9 +57,11 @@ export function createDocumentActivities(
57
57
  if (suppliedCount !== 0 && suppliedCount !== suppliedAuthorityFields.length) {
58
58
  throw new Error("document authority tuple is partial");
59
59
  }
60
- const claimedDocument = await getDocument(lockedDb, input.workspaceId, input.documentId, {
61
- viewerSubjectId: storedAuthority.authoritySubjectId,
62
- });
60
+ const claimedDocument = await getDocumentForIndexing(
61
+ lockedDb,
62
+ input.workspaceId,
63
+ input.documentId,
64
+ );
63
65
  if (
64
66
  !claimedDocument ||
65
67
  claimedDocument.authorityKind !== storedAuthority.authorityKind ||