@opengeni/worker-bundle 0.13.11 → 0.15.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.
- package/dist/activities/agent-turn.d.ts +8 -6
- package/dist/activities/packs.d.ts +2 -1
- package/dist/index.js +95 -15
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
- package/src/activities/agent-turn.ts +69 -11
- package/src/activities/packs.ts +13 -1
- package/src/activities/parent-wake.ts +8 -0
- package/src/activities/scheduled-tasks.ts +9 -0
- package/src/index.ts +4 -3
|
@@ -10,10 +10,10 @@ import { type SecretForRedaction } from "./redaction";
|
|
|
10
10
|
import { type TurnCodexAccount } from "./run-input";
|
|
11
11
|
import type { ActivityServices, EscapedMcpTimeoutRecoveryDetail, RunAgentTurnInput, RunAgentTurnResult, SessionAttemptQuiescenceProof } from "./types";
|
|
12
12
|
import { type TurnSandboxLeaseHolderId } from "../sandbox-resume";
|
|
13
|
-
import { type LatencyMode, type SessionEvent, type SessionEventType, type SessionTurn, type ToolAuthNeededPayload, type TurnExecutionPolicyV1
|
|
13
|
+
import { type LatencyMode, type SessionEvent, type SessionEventType, type SessionTurn, type ToolAuthNeededPayload, type TurnExecutionPolicyV1 } from "@opengeni/contracts";
|
|
14
14
|
export declare const PROVIDER_BACKPRESSURE_DELAY_MS = 60000;
|
|
15
|
-
/**
|
|
16
|
-
export declare function credentialSubjectIdForTurnInitiator(
|
|
15
|
+
/** Broad personal lookup is allowed only for a direct human/API command. */
|
|
16
|
+
export declare function credentialSubjectIdForTurnInitiator(turn: Pick<SessionTurn, "source" | "initiator" | "initiatorContext">): string | undefined;
|
|
17
17
|
/**
|
|
18
18
|
* Direct authenticated-human work is the persisted human source with subject
|
|
19
19
|
* authority and no inherited agent or legacy provenance. Use this complete
|
|
@@ -526,9 +526,11 @@ export declare function reconcileActiveSandboxPointer(db: ActivityServices["db"]
|
|
|
526
526
|
/**
|
|
527
527
|
* Warm the Modal private-registry image for the image ref this turn actually
|
|
528
528
|
* resolved, not only the deployment-global OPENGENI_MODAL_IMAGE_REF warmed at
|
|
529
|
-
* worker boot.
|
|
530
|
-
*
|
|
531
|
-
*
|
|
529
|
+
* worker boot. A provider-native modalImageId bypasses registry import and is
|
|
530
|
+
* resolved by ModalImageSelector.fromId during create. Otherwise packs can
|
|
531
|
+
* override `modalImageRef` per workspace/turn, so a private pack image must be
|
|
532
|
+
* resolved before sandbox creation or Modal falls back to the unauthenticated
|
|
533
|
+
* `fromTag` path.
|
|
532
534
|
*/
|
|
533
535
|
export declare function ensureTurnModalRegistryImage(runSettings: Settings, sandboxCreationBackend: Settings["sandboxBackend"] | undefined, ensureRegistryImage?: (settings: Settings) => Promise<void>): Promise<void>;
|
|
534
536
|
/**
|
|
@@ -9,6 +9,7 @@ import { type EffectiveSkillSelection, type PackSkill } from "@opengeni/runtime"
|
|
|
9
9
|
*/
|
|
10
10
|
export type WorkspacePackRuntime = {
|
|
11
11
|
sandboxImage: string | null;
|
|
12
|
+
sandboxProviderImages: CapabilityPack["sandboxProviderImages"] | null;
|
|
12
13
|
skills: PackSkill[];
|
|
13
14
|
};
|
|
14
15
|
export type WorkspaceSkillLibraryRuntime = {
|
|
@@ -54,7 +55,7 @@ export declare function resolveWorkspaceAgentInstructions(db: Database, workspac
|
|
|
54
55
|
* the settings pass through untouched, so deployments without packs keep the
|
|
55
56
|
* global OPENGENI_DOCKER_IMAGE / OPENGENI_MODAL_IMAGE_REF behavior exactly.
|
|
56
57
|
*/
|
|
57
|
-
export declare function settingsWithPackSandboxImage(settings: Settings, sandboxImage: string | null): Settings;
|
|
58
|
+
export declare function settingsWithPackSandboxImage(settings: Settings, sandboxImage: string | null, sandboxProviderImages?: CapabilityPack["sandboxProviderImages"] | null): Settings;
|
|
58
59
|
/**
|
|
59
60
|
* Applies the session's frozen rig-version image to run settings. Rig image is
|
|
60
61
|
* the TOP of the image precedence chain (rig > pack > deployment default): when
|
package/dist/index.js
CHANGED
|
@@ -71,6 +71,7 @@ import {
|
|
|
71
71
|
CODEX_CREDENTIAL_LEASE_TTL_MS,
|
|
72
72
|
getCodexRotationSettings,
|
|
73
73
|
getWorkspaceModelPolicy as getWorkspaceModelPolicy2,
|
|
74
|
+
getWorkspaceGrant,
|
|
74
75
|
listCodexAccountStatuses as listCodexAccountStatuses2,
|
|
75
76
|
fetchCodexUsageForAccount as fetchCodexUsageForAccount2,
|
|
76
77
|
getSessionCodexState,
|
|
@@ -112,7 +113,10 @@ import {
|
|
|
112
113
|
isSessionEventPersistenceError,
|
|
113
114
|
getEnrollment,
|
|
114
115
|
abandonRecordingForTurnAttempt,
|
|
115
|
-
markSessionAttemptQuiesced
|
|
116
|
+
markSessionAttemptQuiesced,
|
|
117
|
+
beginConnectorActionExecution,
|
|
118
|
+
completeConnectorActionExecution,
|
|
119
|
+
prepareConnectorActionApproval
|
|
116
120
|
} from "@opengeni/db";
|
|
117
121
|
import { appendAndPublishTurnEventsFenced, publishDurableSessionEvents } from "@opengeni/events";
|
|
118
122
|
import { sandboxOperationMetricObserver } from "@opengeni/observability";
|
|
@@ -1027,6 +1031,8 @@ function workflowIdForSession(sessionId) {
|
|
|
1027
1031
|
import {
|
|
1028
1032
|
assertSessionAllowsProductModel,
|
|
1029
1033
|
defaultSessionMcpServerIds,
|
|
1034
|
+
directPersonalConnectionSubjectId,
|
|
1035
|
+
withFrozenPersonalConnectionDelegations,
|
|
1030
1036
|
resolveSessionToolPolicy
|
|
1031
1037
|
} from "@opengeni/core";
|
|
1032
1038
|
|
|
@@ -2652,7 +2658,11 @@ import {
|
|
|
2652
2658
|
isSkillLibraryEntryId,
|
|
2653
2659
|
loadSkillLibrarySkill
|
|
2654
2660
|
} from "@opengeni/runtime";
|
|
2655
|
-
var emptyPackRuntime = {
|
|
2661
|
+
var emptyPackRuntime = {
|
|
2662
|
+
sandboxImage: null,
|
|
2663
|
+
sandboxProviderImages: null,
|
|
2664
|
+
skills: []
|
|
2665
|
+
};
|
|
2656
2666
|
async function resolveWorkspacePackRuntime(db, workspaceId) {
|
|
2657
2667
|
const installations = await listPackInstallations(db, workspaceId);
|
|
2658
2668
|
const active = installations.filter((installation) => installation.status === "active");
|
|
@@ -2768,6 +2778,7 @@ function workspacePackRuntimeFromPacks(packs) {
|
|
|
2768
2778
|
}
|
|
2769
2779
|
return {
|
|
2770
2780
|
sandboxImage: imagePacks[0]?.sandboxImage?.trim() ?? null,
|
|
2781
|
+
sandboxProviderImages: imagePacks[0]?.sandboxProviderImages ?? null,
|
|
2771
2782
|
skills
|
|
2772
2783
|
};
|
|
2773
2784
|
}
|
|
@@ -2775,14 +2786,15 @@ async function resolveWorkspaceAgentInstructions(db, workspaceId) {
|
|
|
2775
2786
|
const workspace = await getWorkspace(db, workspaceId);
|
|
2776
2787
|
return workspace?.agentInstructions ?? null;
|
|
2777
2788
|
}
|
|
2778
|
-
function settingsWithPackSandboxImage(settings, sandboxImage) {
|
|
2789
|
+
function settingsWithPackSandboxImage(settings, sandboxImage, sandboxProviderImages = null) {
|
|
2779
2790
|
if (!sandboxImage) {
|
|
2780
2791
|
return settings;
|
|
2781
2792
|
}
|
|
2782
2793
|
return {
|
|
2783
2794
|
...settings,
|
|
2784
2795
|
dockerImage: sandboxImage,
|
|
2785
|
-
modalImageRef: sandboxImage
|
|
2796
|
+
modalImageRef: sandboxImage,
|
|
2797
|
+
modalImageId: sandboxProviderImages?.modal?.imageId
|
|
2786
2798
|
};
|
|
2787
2799
|
}
|
|
2788
2800
|
function settingsWithRigImage(settings, rigImage) {
|
|
@@ -2792,7 +2804,11 @@ function settingsWithRigImage(settings, rigImage) {
|
|
|
2792
2804
|
return {
|
|
2793
2805
|
...settings,
|
|
2794
2806
|
dockerImage: rigImage,
|
|
2795
|
-
modalImageRef: rigImage
|
|
2807
|
+
modalImageRef: rigImage,
|
|
2808
|
+
// A rig image has no provider-native identity in the current rig contract.
|
|
2809
|
+
// Clear a lower-precedence pack/deployment ID so the rig cannot silently
|
|
2810
|
+
// run the wrong Modal image.
|
|
2811
|
+
modalImageId: void 0
|
|
2796
2812
|
};
|
|
2797
2813
|
}
|
|
2798
2814
|
function mergeRigDefaultVariableSetEnvironment(rigDefaultValues, sessionValues) {
|
|
@@ -2803,6 +2819,7 @@ function mergeRigDefaultVariableSetEnvironment(rigDefaultValues, sessionValues)
|
|
|
2803
2819
|
import {
|
|
2804
2820
|
getSession,
|
|
2805
2821
|
getSessionGoal as getSessionGoal2,
|
|
2822
|
+
getSessionParentPersonalConnectionDelegations,
|
|
2806
2823
|
addSessionSystemUpdateWithSourceMutation,
|
|
2807
2824
|
claimPendingSessionSystemUpdateOutbox,
|
|
2808
2825
|
claimPendingSessionWorkflowWakes,
|
|
@@ -2821,6 +2838,11 @@ async function notifyParentOfChildIdle(svc, workspaceId, childSessionId, episode
|
|
|
2821
2838
|
const goal = await getSessionGoal2(svc.db, workspaceId, childSessionId);
|
|
2822
2839
|
const clientEventId = `child-completion:${childSessionId}:${episodeKey}`;
|
|
2823
2840
|
const payload = childCompletionPayload(child, goal);
|
|
2841
|
+
const personalConnectionDelegations = await getSessionParentPersonalConnectionDelegations(
|
|
2842
|
+
svc.db,
|
|
2843
|
+
workspaceId,
|
|
2844
|
+
childSessionId
|
|
2845
|
+
);
|
|
2824
2846
|
const outbox = await getOrCreateSessionSystemUpdateOutbox(svc.db, {
|
|
2825
2847
|
accountId: child.accountId,
|
|
2826
2848
|
workspaceId,
|
|
@@ -2832,7 +2854,8 @@ async function notifyParentOfChildIdle(svc, workspaceId, childSessionId, episode
|
|
|
2832
2854
|
dedupeKey: clientEventId,
|
|
2833
2855
|
summary: childCompletionSummary(child, goal, "idle"),
|
|
2834
2856
|
payload,
|
|
2835
|
-
lineage: { childSessionId: child.id, parentSessionId: child.parentSessionId }
|
|
2857
|
+
lineage: { childSessionId: child.id, parentSessionId: child.parentSessionId },
|
|
2858
|
+
personalConnectionDelegations
|
|
2836
2859
|
});
|
|
2837
2860
|
if (outbox.status === "delivered") {
|
|
2838
2861
|
return;
|
|
@@ -2882,7 +2905,8 @@ async function deliverParentSystemUpdateOutbox(svc, outbox) {
|
|
|
2882
2905
|
dedupeKey: outbox.dedupeKey,
|
|
2883
2906
|
summary: outbox.summary,
|
|
2884
2907
|
payload: outbox.payload,
|
|
2885
|
-
lineage: outbox.lineage
|
|
2908
|
+
lineage: outbox.lineage,
|
|
2909
|
+
personalConnectionDelegations: outbox.personalConnectionDelegations
|
|
2886
2910
|
},
|
|
2887
2911
|
async (tx) => {
|
|
2888
2912
|
await markSessionSystemUpdateOutboxDeliveredInTransaction(tx, outbox);
|
|
@@ -6284,11 +6308,11 @@ import {
|
|
|
6284
6308
|
} from "@opengeni/contracts";
|
|
6285
6309
|
import { createHash as createHash4, randomUUID as randomUUID2 } from "crypto";
|
|
6286
6310
|
var PROVIDER_BACKPRESSURE_DELAY_MS = 6e4;
|
|
6287
|
-
function credentialSubjectIdForTurnInitiator(
|
|
6288
|
-
return
|
|
6311
|
+
function credentialSubjectIdForTurnInitiator(turn) {
|
|
6312
|
+
return directPersonalConnectionSubjectId(turn);
|
|
6289
6313
|
}
|
|
6290
6314
|
function isDirectHumanTurnInitiation(turn) {
|
|
6291
|
-
if (turn.source !== "user" || turn.initiator.kind !== "subject") {
|
|
6315
|
+
if (turn.source !== "user" && turn.source !== "api" || turn.initiator.kind !== "subject") {
|
|
6292
6316
|
return false;
|
|
6293
6317
|
}
|
|
6294
6318
|
return !["via", "viaTruncated", "provenanceError", "backfill"].some(
|
|
@@ -7025,6 +7049,9 @@ async function ensureTurnModalRegistryImage(runSettings, sandboxCreationBackend,
|
|
|
7025
7049
|
if (sandboxCreationBackend !== "modal") {
|
|
7026
7050
|
return;
|
|
7027
7051
|
}
|
|
7052
|
+
if (runSettings.modalImageId) {
|
|
7053
|
+
return;
|
|
7054
|
+
}
|
|
7028
7055
|
if (!runSettings.modalImageRegistrySecret || !runSettings.modalImageRef) {
|
|
7029
7056
|
return;
|
|
7030
7057
|
}
|
|
@@ -8606,7 +8633,11 @@ function createRunAgentTurnActivity(services) {
|
|
|
8606
8633
|
// deployment default; a rig with no image (or a rig-less turn) is a
|
|
8607
8634
|
// pass-through, leaving the pack/deployment chain exactly as today.
|
|
8608
8635
|
...settingsWithRigImage(
|
|
8609
|
-
settingsWithPackSandboxImage(
|
|
8636
|
+
settingsWithPackSandboxImage(
|
|
8637
|
+
capabilitySettings,
|
|
8638
|
+
packRuntime.sandboxImage,
|
|
8639
|
+
packRuntime.sandboxProviderImages
|
|
8640
|
+
),
|
|
8610
8641
|
rigVersion?.image ?? null
|
|
8611
8642
|
),
|
|
8612
8643
|
openaiModel: turn.model,
|
|
@@ -9630,8 +9661,23 @@ function createRunAgentTurnActivity(services) {
|
|
|
9630
9661
|
attemptId: input.attemptId,
|
|
9631
9662
|
turn
|
|
9632
9663
|
});
|
|
9664
|
+
const personalConnectionDelegations = turn.personalConnectionDelegations;
|
|
9665
|
+
const delegatedMembershipChecks = /* @__PURE__ */ new Map();
|
|
9666
|
+
const delegatedOwnerHasMembership = async (subjectId) => {
|
|
9667
|
+
const existing = delegatedMembershipChecks.get(subjectId);
|
|
9668
|
+
if (existing) return await existing;
|
|
9669
|
+
const check = getWorkspaceGrant(db, subjectId, input.workspaceId).then(Boolean);
|
|
9670
|
+
delegatedMembershipChecks.set(subjectId, check);
|
|
9671
|
+
return await check;
|
|
9672
|
+
};
|
|
9673
|
+
const resolveFrozenCredential = withFrozenPersonalConnectionDelegations({
|
|
9674
|
+
resolveCredential: rawResolveCredential,
|
|
9675
|
+
settings: runSettings,
|
|
9676
|
+
personalConnectionDelegations,
|
|
9677
|
+
ownerHasWorkspaceMembership: delegatedOwnerHasMembership
|
|
9678
|
+
});
|
|
9633
9679
|
const resolveCredential = async (request) => {
|
|
9634
|
-
const result = await
|
|
9680
|
+
const result = await resolveFrozenCredential(request);
|
|
9635
9681
|
if (result.status === "ok") {
|
|
9636
9682
|
registerSecretRedactions(
|
|
9637
9683
|
headerSecretRedactions("MCP", result.headers, Object.keys(result.headers))
|
|
@@ -9639,7 +9685,7 @@ function createRunAgentTurnActivity(services) {
|
|
|
9639
9685
|
}
|
|
9640
9686
|
return result;
|
|
9641
9687
|
};
|
|
9642
|
-
const credentialSubjectId = credentialSubjectIdForTurnInitiator(turn
|
|
9688
|
+
const credentialSubjectId = credentialSubjectIdForTurnInitiator(turn);
|
|
9643
9689
|
preparedTools = await waitForTurnOperation(
|
|
9644
9690
|
withCodex(
|
|
9645
9691
|
() => runtime.prepareTools(runSettings, turnTools, {
|
|
@@ -9684,6 +9730,29 @@ function createRunAgentTurnActivity(services) {
|
|
|
9684
9730
|
turnExecutionPolicy.providerId,
|
|
9685
9731
|
turnExecutionPolicy.latencyMode
|
|
9686
9732
|
);
|
|
9733
|
+
const connectorActionIdentity = {
|
|
9734
|
+
accountId: input.accountId,
|
|
9735
|
+
workspaceId: input.workspaceId,
|
|
9736
|
+
sessionId: input.sessionId,
|
|
9737
|
+
turnId,
|
|
9738
|
+
attemptId: input.attemptId,
|
|
9739
|
+
executionGeneration,
|
|
9740
|
+
initiator: {
|
|
9741
|
+
kind: turn.initiator.kind,
|
|
9742
|
+
subjectId: turn.initiator.subjectId
|
|
9743
|
+
}
|
|
9744
|
+
};
|
|
9745
|
+
const connectorActionPolicy = {
|
|
9746
|
+
prepare: async (call) => await prepareConnectorActionApproval(db, connectorActionIdentity, call),
|
|
9747
|
+
begin: async (call) => await beginConnectorActionExecution(db, connectorActionIdentity, call),
|
|
9748
|
+
complete: async ({ requestId, outcome }) => await completeConnectorActionExecution(db, {
|
|
9749
|
+
accountId: input.accountId,
|
|
9750
|
+
workspaceId: input.workspaceId,
|
|
9751
|
+
requestId,
|
|
9752
|
+
attemptId: input.attemptId,
|
|
9753
|
+
outcome
|
|
9754
|
+
})
|
|
9755
|
+
};
|
|
9687
9756
|
const agent = runtime.buildAgent(modelRunSettings, turnResources, {
|
|
9688
9757
|
reasoningEffort: turn.reasoningEffort,
|
|
9689
9758
|
latencyMode: turnExecutionPolicy.latencyMode,
|
|
@@ -9722,6 +9791,8 @@ function createRunAgentTurnActivity(services) {
|
|
|
9722
9791
|
...activeSandboxBackend ? { activeSandboxBackend } : {},
|
|
9723
9792
|
fileResourceDownloads,
|
|
9724
9793
|
mcpServers: preparedTools.mcpServers,
|
|
9794
|
+
resolvedMcpConnectionIds: preparedTools.resolvedMcpConnectionIds,
|
|
9795
|
+
connectorActionPolicy,
|
|
9725
9796
|
// LIVE by-reference connector namespaces (fills during this turn's
|
|
9726
9797
|
// codex_apps tools/list): the codex tool_search description reads it per
|
|
9727
9798
|
// model call so the model sees the account's real connected sources.
|
|
@@ -14009,6 +14080,7 @@ import {
|
|
|
14009
14080
|
enqueueSessionWorkflowWakeIfRunnable as enqueueSessionWorkflowWakeIfRunnable2,
|
|
14010
14081
|
getBillingBalance as getBillingBalance5,
|
|
14011
14082
|
getScheduledTask,
|
|
14083
|
+
getScheduledTaskPersonalConnectionDelegations,
|
|
14012
14084
|
getRig,
|
|
14013
14085
|
getVariableSet,
|
|
14014
14086
|
isCodexBilledTurn as isCodexBilledTurn2,
|
|
@@ -14035,6 +14107,11 @@ function createScheduledTaskActivities(services) {
|
|
|
14035
14107
|
if (!task) {
|
|
14036
14108
|
return { action: "deleted" };
|
|
14037
14109
|
}
|
|
14110
|
+
const taskPersonalConnectionDelegations = await getScheduledTaskPersonalConnectionDelegations(
|
|
14111
|
+
db,
|
|
14112
|
+
task.workspaceId,
|
|
14113
|
+
task.id
|
|
14114
|
+
);
|
|
14038
14115
|
const slackBotConnection = task.agentConfig.slackBotConnectionId ? await requireOpenGeniSlackBotConnection(
|
|
14039
14116
|
db,
|
|
14040
14117
|
task.workspaceId,
|
|
@@ -14180,6 +14257,7 @@ function createScheduledTaskActivities(services) {
|
|
|
14180
14257
|
variableSetId: task.variableSetId ?? null,
|
|
14181
14258
|
rigId: frozenRigId,
|
|
14182
14259
|
rigVersionId: frozenRigVersionId,
|
|
14260
|
+
personalConnectionDelegations: taskPersonalConnectionDelegations,
|
|
14183
14261
|
maxNestedAgentDepthOverride: task.agentConfig.maxNestedAgentDepth ?? null,
|
|
14184
14262
|
// The durable agent config was privilege-checked when the task
|
|
14185
14263
|
// was created/updated. Preserve that explicit policy if a broader
|
|
@@ -14262,7 +14340,8 @@ function createScheduledTaskActivities(services) {
|
|
|
14262
14340
|
task.id,
|
|
14263
14341
|
run.id
|
|
14264
14342
|
),
|
|
14265
|
-
lineage: { scheduledTaskId: task.id, scheduledTaskRunId: run.id }
|
|
14343
|
+
lineage: { scheduledTaskId: task.id, scheduledTaskRunId: run.id },
|
|
14344
|
+
personalConnectionDelegations: taskPersonalConnectionDelegations
|
|
14266
14345
|
},
|
|
14267
14346
|
async (tx, wakeEventId) => {
|
|
14268
14347
|
if (!wakeEventId) throw new Error("Scheduled delivery has no wake event");
|
|
@@ -14361,7 +14440,8 @@ function createScheduledTaskActivities(services) {
|
|
|
14361
14440
|
task.id,
|
|
14362
14441
|
run.id
|
|
14363
14442
|
),
|
|
14364
|
-
lineage: { scheduledTaskId: task.id, scheduledTaskRunId: run.id }
|
|
14443
|
+
lineage: { scheduledTaskId: task.id, scheduledTaskRunId: run.id },
|
|
14444
|
+
personalConnectionDelegations: taskPersonalConnectionDelegations
|
|
14365
14445
|
},
|
|
14366
14446
|
async (tx, wakeEventId) => {
|
|
14367
14447
|
if (!wakeEventId) throw new Error("Scheduled delivery has no wake event");
|