@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengeni/worker-bundle",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
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": {
|
|
@@ -41,16 +41,16 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@opengeni/agent-proto": "^0.3.0",
|
|
43
43
|
"@opengeni/codex": "^0.2.9",
|
|
44
|
-
"@opengeni/config": "^0.
|
|
45
|
-
"@opengeni/contracts": "^0.
|
|
46
|
-
"@opengeni/core": "^0.
|
|
47
|
-
"@opengeni/db": "^0.
|
|
48
|
-
"@opengeni/documents": "^0.2.
|
|
49
|
-
"@opengeni/events": "^0.3.
|
|
50
|
-
"@opengeni/github": "^0.4.
|
|
51
|
-
"@opengeni/observability": "^0.4.
|
|
52
|
-
"@opengeni/runtime": "^0.
|
|
53
|
-
"@opengeni/storage": "^0.2.
|
|
44
|
+
"@opengeni/config": "^0.10.0",
|
|
45
|
+
"@opengeni/contracts": "^0.31.0",
|
|
46
|
+
"@opengeni/core": "^0.18.0",
|
|
47
|
+
"@opengeni/db": "^0.22.1",
|
|
48
|
+
"@opengeni/documents": "^0.2.69",
|
|
49
|
+
"@opengeni/events": "^0.3.59",
|
|
50
|
+
"@opengeni/github": "^0.4.16",
|
|
51
|
+
"@opengeni/observability": "^0.4.3",
|
|
52
|
+
"@opengeni/runtime": "^0.17.0",
|
|
53
|
+
"@opengeni/storage": "^0.2.53",
|
|
54
54
|
"@temporalio/activity": "^1.17.0",
|
|
55
55
|
"@temporalio/client": "^1.17.0",
|
|
56
56
|
"@temporalio/worker": "^1.17.0",
|
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
CODEX_CREDENTIAL_LEASE_TTL_MS,
|
|
28
28
|
getCodexRotationSettings,
|
|
29
29
|
getWorkspaceModelPolicy,
|
|
30
|
+
getWorkspaceGrant,
|
|
30
31
|
listCodexAccountStatuses,
|
|
31
32
|
fetchCodexUsageForAccount,
|
|
32
33
|
getSessionCodexState,
|
|
@@ -69,6 +70,9 @@ import {
|
|
|
69
70
|
getEnrollment,
|
|
70
71
|
abandonRecordingForTurnAttempt,
|
|
71
72
|
markSessionAttemptQuiesced,
|
|
73
|
+
beginConnectorActionExecution,
|
|
74
|
+
completeConnectorActionExecution,
|
|
75
|
+
prepareConnectorActionApproval,
|
|
72
76
|
type AppendEventInput,
|
|
73
77
|
type ActiveSandboxPointer,
|
|
74
78
|
type SandboxRecord,
|
|
@@ -122,6 +126,7 @@ import {
|
|
|
122
126
|
type ModelCallUsageInput,
|
|
123
127
|
type ModelCallUsageNormalization,
|
|
124
128
|
type BuildAgentOptions,
|
|
129
|
+
type ConnectorActionPolicyHooks,
|
|
125
130
|
type RunAgentStreamOptions,
|
|
126
131
|
type TurnToolCancellationFence,
|
|
127
132
|
type BackendUnresolvableCode,
|
|
@@ -201,6 +206,8 @@ import { mergeResourceRefs } from "./common";
|
|
|
201
206
|
import {
|
|
202
207
|
assertSessionAllowsProductModel,
|
|
203
208
|
defaultSessionMcpServerIds,
|
|
209
|
+
directPersonalConnectionSubjectId,
|
|
210
|
+
withFrozenPersonalConnectionDelegations,
|
|
204
211
|
resolveSessionToolPolicy,
|
|
205
212
|
} from "@opengeni/core";
|
|
206
213
|
import { maybeCompactContext, settleFailedContextCompactionLandmark } from "./context-compaction";
|
|
@@ -327,7 +334,6 @@ import {
|
|
|
327
334
|
type SessionTurn,
|
|
328
335
|
type ToolAuthNeededPayload,
|
|
329
336
|
type TurnExecutionPolicyV1,
|
|
330
|
-
type TurnInitiator,
|
|
331
337
|
} from "@opengeni/contracts";
|
|
332
338
|
import { createHash, randomUUID } from "node:crypto";
|
|
333
339
|
|
|
@@ -337,11 +343,11 @@ import { createHash, randomUUID } from "node:crypto";
|
|
|
337
343
|
// budget against the same window.
|
|
338
344
|
export const PROVIDER_BACKPRESSURE_DELAY_MS = 60_000;
|
|
339
345
|
|
|
340
|
-
/**
|
|
346
|
+
/** Broad personal lookup is allowed only for a direct human/API command. */
|
|
341
347
|
export function credentialSubjectIdForTurnInitiator(
|
|
342
|
-
|
|
348
|
+
turn: Pick<SessionTurn, "source" | "initiator" | "initiatorContext">,
|
|
343
349
|
): string | undefined {
|
|
344
|
-
return
|
|
350
|
+
return directPersonalConnectionSubjectId(turn);
|
|
345
351
|
}
|
|
346
352
|
|
|
347
353
|
/**
|
|
@@ -353,7 +359,7 @@ export function credentialSubjectIdForTurnInitiator(
|
|
|
353
359
|
export function isDirectHumanTurnInitiation(
|
|
354
360
|
turn: Pick<SessionTurn, "source" | "initiator" | "initiatorContext">,
|
|
355
361
|
): boolean {
|
|
356
|
-
if (turn.source !== "user" || turn.initiator.kind !== "subject") {
|
|
362
|
+
if ((turn.source !== "user" && turn.source !== "api") || turn.initiator.kind !== "subject") {
|
|
357
363
|
return false;
|
|
358
364
|
}
|
|
359
365
|
return !["via", "viaTruncated", "provenanceError", "backfill"].some((key) =>
|
|
@@ -1767,9 +1773,11 @@ export async function reconcileActiveSandboxPointer(
|
|
|
1767
1773
|
/**
|
|
1768
1774
|
* Warm the Modal private-registry image for the image ref this turn actually
|
|
1769
1775
|
* resolved, not only the deployment-global OPENGENI_MODAL_IMAGE_REF warmed at
|
|
1770
|
-
* worker boot.
|
|
1771
|
-
*
|
|
1772
|
-
*
|
|
1776
|
+
* worker boot. A provider-native modalImageId bypasses registry import and is
|
|
1777
|
+
* resolved by ModalImageSelector.fromId during create. Otherwise packs can
|
|
1778
|
+
* override `modalImageRef` per workspace/turn, so a private pack image must be
|
|
1779
|
+
* resolved before sandbox creation or Modal falls back to the unauthenticated
|
|
1780
|
+
* `fromTag` path.
|
|
1773
1781
|
*/
|
|
1774
1782
|
export async function ensureTurnModalRegistryImage(
|
|
1775
1783
|
runSettings: Settings,
|
|
@@ -1779,6 +1787,9 @@ export async function ensureTurnModalRegistryImage(
|
|
|
1779
1787
|
if (sandboxCreationBackend !== "modal") {
|
|
1780
1788
|
return;
|
|
1781
1789
|
}
|
|
1790
|
+
if (runSettings.modalImageId) {
|
|
1791
|
+
return;
|
|
1792
|
+
}
|
|
1782
1793
|
if (!runSettings.modalImageRegistrySecret || !runSettings.modalImageRef) {
|
|
1783
1794
|
return;
|
|
1784
1795
|
}
|
|
@@ -4028,7 +4039,11 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
4028
4039
|
// deployment default; a rig with no image (or a rig-less turn) is a
|
|
4029
4040
|
// pass-through, leaving the pack/deployment chain exactly as today.
|
|
4030
4041
|
...settingsWithRigImage(
|
|
4031
|
-
settingsWithPackSandboxImage(
|
|
4042
|
+
settingsWithPackSandboxImage(
|
|
4043
|
+
capabilitySettings,
|
|
4044
|
+
packRuntime.sandboxImage,
|
|
4045
|
+
packRuntime.sandboxProviderImages,
|
|
4046
|
+
),
|
|
4032
4047
|
rigVersion?.image ?? null,
|
|
4033
4048
|
),
|
|
4034
4049
|
openaiModel: turn.model,
|
|
@@ -5368,8 +5383,23 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
5368
5383
|
attemptId: input.attemptId,
|
|
5369
5384
|
turn,
|
|
5370
5385
|
});
|
|
5386
|
+
const personalConnectionDelegations = turn.personalConnectionDelegations;
|
|
5387
|
+
const delegatedMembershipChecks = new Map<string, Promise<boolean>>();
|
|
5388
|
+
const delegatedOwnerHasMembership = async (subjectId: string): Promise<boolean> => {
|
|
5389
|
+
const existing = delegatedMembershipChecks.get(subjectId);
|
|
5390
|
+
if (existing) return await existing;
|
|
5391
|
+
const check = getWorkspaceGrant(db, subjectId, input.workspaceId).then(Boolean);
|
|
5392
|
+
delegatedMembershipChecks.set(subjectId, check);
|
|
5393
|
+
return await check;
|
|
5394
|
+
};
|
|
5395
|
+
const resolveFrozenCredential = withFrozenPersonalConnectionDelegations({
|
|
5396
|
+
resolveCredential: rawResolveCredential,
|
|
5397
|
+
settings: runSettings,
|
|
5398
|
+
personalConnectionDelegations,
|
|
5399
|
+
ownerHasWorkspaceMembership: delegatedOwnerHasMembership,
|
|
5400
|
+
});
|
|
5371
5401
|
const resolveCredential: typeof rawResolveCredential = async (request) => {
|
|
5372
|
-
const result = await
|
|
5402
|
+
const result = await resolveFrozenCredential(request);
|
|
5373
5403
|
if (result.status === "ok") {
|
|
5374
5404
|
registerSecretRedactions(
|
|
5375
5405
|
headerSecretRedactions("MCP", result.headers, Object.keys(result.headers)),
|
|
@@ -5377,7 +5407,7 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
5377
5407
|
}
|
|
5378
5408
|
return result;
|
|
5379
5409
|
};
|
|
5380
|
-
const credentialSubjectId = credentialSubjectIdForTurnInitiator(turn
|
|
5410
|
+
const credentialSubjectId = credentialSubjectIdForTurnInitiator(turn);
|
|
5381
5411
|
preparedTools = await waitForTurnOperation(
|
|
5382
5412
|
withCodex(() =>
|
|
5383
5413
|
runtime.prepareTools(runSettings, turnTools, {
|
|
@@ -5453,6 +5483,32 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
5453
5483
|
turnExecutionPolicy.providerId,
|
|
5454
5484
|
turnExecutionPolicy.latencyMode,
|
|
5455
5485
|
);
|
|
5486
|
+
const connectorActionIdentity = {
|
|
5487
|
+
accountId: input.accountId,
|
|
5488
|
+
workspaceId: input.workspaceId,
|
|
5489
|
+
sessionId: input.sessionId,
|
|
5490
|
+
turnId,
|
|
5491
|
+
attemptId: input.attemptId,
|
|
5492
|
+
executionGeneration,
|
|
5493
|
+
initiator: {
|
|
5494
|
+
kind: turn.initiator.kind,
|
|
5495
|
+
subjectId: turn.initiator.subjectId,
|
|
5496
|
+
},
|
|
5497
|
+
} as const;
|
|
5498
|
+
const connectorActionPolicy: ConnectorActionPolicyHooks = {
|
|
5499
|
+
prepare: async (call) =>
|
|
5500
|
+
await prepareConnectorActionApproval(db, connectorActionIdentity, call),
|
|
5501
|
+
begin: async (call) =>
|
|
5502
|
+
await beginConnectorActionExecution(db, connectorActionIdentity, call),
|
|
5503
|
+
complete: async ({ requestId, outcome }) =>
|
|
5504
|
+
await completeConnectorActionExecution(db, {
|
|
5505
|
+
accountId: input.accountId,
|
|
5506
|
+
workspaceId: input.workspaceId,
|
|
5507
|
+
requestId,
|
|
5508
|
+
attemptId: input.attemptId,
|
|
5509
|
+
outcome,
|
|
5510
|
+
}),
|
|
5511
|
+
};
|
|
5456
5512
|
const agent = runtime.buildAgent(modelRunSettings, turnResources, {
|
|
5457
5513
|
reasoningEffort: turn.reasoningEffort,
|
|
5458
5514
|
latencyMode: turnExecutionPolicy.latencyMode,
|
|
@@ -5499,6 +5555,8 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
5499
5555
|
...(activeSandboxBackend ? { activeSandboxBackend } : {}),
|
|
5500
5556
|
fileResourceDownloads,
|
|
5501
5557
|
mcpServers: preparedTools.mcpServers,
|
|
5558
|
+
resolvedMcpConnectionIds: preparedTools.resolvedMcpConnectionIds,
|
|
5559
|
+
connectorActionPolicy,
|
|
5502
5560
|
// LIVE by-reference connector namespaces (fills during this turn's
|
|
5503
5561
|
// codex_apps tools/list): the codex tool_search description reads it per
|
|
5504
5562
|
// model call so the model sees the account's real connected sources.
|
package/src/activities/packs.ts
CHANGED
|
@@ -21,10 +21,15 @@ import {
|
|
|
21
21
|
*/
|
|
22
22
|
export type WorkspacePackRuntime = {
|
|
23
23
|
sandboxImage: string | null;
|
|
24
|
+
sandboxProviderImages: CapabilityPack["sandboxProviderImages"] | null;
|
|
24
25
|
skills: PackSkill[];
|
|
25
26
|
};
|
|
26
27
|
|
|
27
|
-
const emptyPackRuntime: WorkspacePackRuntime = {
|
|
28
|
+
const emptyPackRuntime: WorkspacePackRuntime = {
|
|
29
|
+
sandboxImage: null,
|
|
30
|
+
sandboxProviderImages: null,
|
|
31
|
+
skills: [],
|
|
32
|
+
};
|
|
28
33
|
|
|
29
34
|
export type WorkspaceSkillLibraryRuntime = {
|
|
30
35
|
skillLibrarySkills: PackSkill[];
|
|
@@ -200,6 +205,7 @@ export function workspacePackRuntimeFromPacks(packs: CapabilityPack[]): Workspac
|
|
|
200
205
|
}
|
|
201
206
|
return {
|
|
202
207
|
sandboxImage: imagePacks[0]?.sandboxImage?.trim() ?? null,
|
|
208
|
+
sandboxProviderImages: imagePacks[0]?.sandboxProviderImages ?? null,
|
|
203
209
|
skills,
|
|
204
210
|
};
|
|
205
211
|
}
|
|
@@ -231,6 +237,7 @@ export async function resolveWorkspaceAgentInstructions(
|
|
|
231
237
|
export function settingsWithPackSandboxImage(
|
|
232
238
|
settings: Settings,
|
|
233
239
|
sandboxImage: string | null,
|
|
240
|
+
sandboxProviderImages: CapabilityPack["sandboxProviderImages"] | null = null,
|
|
234
241
|
): Settings {
|
|
235
242
|
if (!sandboxImage) {
|
|
236
243
|
return settings;
|
|
@@ -239,6 +246,7 @@ export function settingsWithPackSandboxImage(
|
|
|
239
246
|
...settings,
|
|
240
247
|
dockerImage: sandboxImage,
|
|
241
248
|
modalImageRef: sandboxImage,
|
|
249
|
+
modalImageId: sandboxProviderImages?.modal?.imageId,
|
|
242
250
|
};
|
|
243
251
|
}
|
|
244
252
|
|
|
@@ -260,6 +268,10 @@ export function settingsWithRigImage(settings: Settings, rigImage: string | null
|
|
|
260
268
|
...settings,
|
|
261
269
|
dockerImage: rigImage,
|
|
262
270
|
modalImageRef: rigImage,
|
|
271
|
+
// A rig image has no provider-native identity in the current rig contract.
|
|
272
|
+
// Clear a lower-precedence pack/deployment ID so the rig cannot silently
|
|
273
|
+
// run the wrong Modal image.
|
|
274
|
+
modalImageId: undefined,
|
|
263
275
|
};
|
|
264
276
|
}
|
|
265
277
|
|
|
@@ -3,6 +3,7 @@ import type { Session, SessionGoal, SessionSystemUpdatePayload } from "@opengeni
|
|
|
3
3
|
import {
|
|
4
4
|
getSession,
|
|
5
5
|
getSessionGoal,
|
|
6
|
+
getSessionParentPersonalConnectionDelegations,
|
|
6
7
|
addSessionSystemUpdateWithSourceMutation,
|
|
7
8
|
claimPendingSessionSystemUpdateOutbox,
|
|
8
9
|
claimPendingSessionWorkflowWakes,
|
|
@@ -57,6 +58,11 @@ export async function notifyParentOfChildIdle(
|
|
|
57
58
|
// guard so a nudge that slips through still cannot revive the goal.
|
|
58
59
|
const clientEventId = `child-completion:${childSessionId}:${episodeKey}`;
|
|
59
60
|
const payload = childCompletionPayload(child, goal);
|
|
61
|
+
const personalConnectionDelegations = await getSessionParentPersonalConnectionDelegations(
|
|
62
|
+
svc.db,
|
|
63
|
+
workspaceId,
|
|
64
|
+
childSessionId,
|
|
65
|
+
);
|
|
60
66
|
const outbox = await getOrCreateSessionSystemUpdateOutbox(svc.db, {
|
|
61
67
|
accountId: child.accountId,
|
|
62
68
|
workspaceId,
|
|
@@ -69,6 +75,7 @@ export async function notifyParentOfChildIdle(
|
|
|
69
75
|
summary: childCompletionSummary(child, goal, "idle"),
|
|
70
76
|
payload,
|
|
71
77
|
lineage: { childSessionId: child.id, parentSessionId: child.parentSessionId },
|
|
78
|
+
personalConnectionDelegations,
|
|
72
79
|
});
|
|
73
80
|
if (outbox.status === "delivered") {
|
|
74
81
|
return;
|
|
@@ -138,6 +145,7 @@ async function deliverParentSystemUpdateOutbox(
|
|
|
138
145
|
summary: outbox.summary,
|
|
139
146
|
payload: outbox.payload,
|
|
140
147
|
lineage: outbox.lineage,
|
|
148
|
+
personalConnectionDelegations: outbox.personalConnectionDelegations,
|
|
141
149
|
},
|
|
142
150
|
async (tx) => {
|
|
143
151
|
await markSessionSystemUpdateOutboxDeliveredInTransaction(tx, outbox);
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
enqueueSessionWorkflowWakeIfRunnable,
|
|
18
18
|
getBillingBalance,
|
|
19
19
|
getScheduledTask,
|
|
20
|
+
getScheduledTaskPersonalConnectionDelegations,
|
|
20
21
|
getRig,
|
|
21
22
|
getVariableSet,
|
|
22
23
|
isCodexBilledTurn,
|
|
@@ -63,6 +64,11 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
|
|
|
63
64
|
if (!task) {
|
|
64
65
|
return { action: "deleted" };
|
|
65
66
|
}
|
|
67
|
+
const taskPersonalConnectionDelegations = await getScheduledTaskPersonalConnectionDelegations(
|
|
68
|
+
db,
|
|
69
|
+
task.workspaceId,
|
|
70
|
+
task.id,
|
|
71
|
+
);
|
|
66
72
|
// A scheduled bot selection was authorized when the task was written,
|
|
67
73
|
// but connection status and tenant/role binding are mutable. Revalidate
|
|
68
74
|
// before any session/model cost and never fall back to a personal Slack
|
|
@@ -237,6 +243,7 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
|
|
|
237
243
|
variableSetId: task.variableSetId ?? null,
|
|
238
244
|
rigId: frozenRigId,
|
|
239
245
|
rigVersionId: frozenRigVersionId,
|
|
246
|
+
personalConnectionDelegations: taskPersonalConnectionDelegations,
|
|
240
247
|
maxNestedAgentDepthOverride: task.agentConfig.maxNestedAgentDepth ?? null,
|
|
241
248
|
// The durable agent config was privilege-checked when the task
|
|
242
249
|
// was created/updated. Preserve that explicit policy if a broader
|
|
@@ -328,6 +335,7 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
|
|
|
328
335
|
run.id,
|
|
329
336
|
),
|
|
330
337
|
lineage: { scheduledTaskId: task.id, scheduledTaskRunId: run.id },
|
|
338
|
+
personalConnectionDelegations: taskPersonalConnectionDelegations,
|
|
331
339
|
},
|
|
332
340
|
async (tx, wakeEventId) => {
|
|
333
341
|
if (!wakeEventId) throw new Error("Scheduled delivery has no wake event");
|
|
@@ -444,6 +452,7 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
|
|
|
444
452
|
run.id,
|
|
445
453
|
),
|
|
446
454
|
lineage: { scheduledTaskId: task.id, scheduledTaskRunId: run.id },
|
|
455
|
+
personalConnectionDelegations: taskPersonalConnectionDelegations,
|
|
447
456
|
},
|
|
448
457
|
async (tx, wakeEventId) => {
|
|
449
458
|
if (!wakeEventId) throw new Error("Scheduled delivery has no wake event");
|
package/src/index.ts
CHANGED
|
@@ -165,9 +165,10 @@ export async function createOpenGeniWorker(options: WorkerOptions): Promise<{
|
|
|
165
165
|
throw new Error("workflowBundle is valid only for the control worker role");
|
|
166
166
|
}
|
|
167
167
|
// Pre-resolve a PRIVATE-registry sandbox image before any turn creates a box.
|
|
168
|
-
//
|
|
169
|
-
//
|
|
170
|
-
//
|
|
168
|
+
// A provider-native OPENGENI_MODAL_IMAGE_ID intentionally bypasses this
|
|
169
|
+
// registry path and is resolved by ModalImageSelector.fromId at create time.
|
|
170
|
+
// Otherwise this is a no-op unless the registry secret + logical ref are both
|
|
171
|
+
// set. Memoized in the provider, so it runs once per process.
|
|
171
172
|
if (options.role === "turn") {
|
|
172
173
|
await retryStartupDependency(
|
|
173
174
|
"Modal private-registry image",
|