@opengeni/worker-bundle 0.14.1 → 0.15.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.
- package/dist/activities/agent-turn.d.ts +13 -3
- package/dist/activities/capabilities.d.ts +1 -0
- package/dist/activities/packs.d.ts +2 -1
- package/dist/index.js +234 -16
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
- package/src/activities/agent-turn.ts +263 -12
- package/src/activities/capabilities.ts +13 -0
- package/src/activities/packs.ts +13 -1
- 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.1",
|
|
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.1",
|
|
45
|
+
"@opengeni/contracts": "^0.31.1",
|
|
46
|
+
"@opengeni/core": "^0.18.1",
|
|
47
|
+
"@opengeni/db": "^0.22.2",
|
|
48
|
+
"@opengeni/documents": "^0.2.70",
|
|
49
|
+
"@opengeni/events": "^0.3.60",
|
|
50
|
+
"@opengeni/github": "^0.4.17",
|
|
51
|
+
"@opengeni/observability": "^0.4.4",
|
|
52
|
+
"@opengeni/runtime": "^0.17.1",
|
|
53
|
+
"@opengeni/storage": "^0.2.54",
|
|
54
54
|
"@temporalio/activity": "^1.17.0",
|
|
55
55
|
"@temporalio/client": "^1.17.0",
|
|
56
56
|
"@temporalio/worker": "^1.17.0",
|
|
@@ -70,6 +70,9 @@ import {
|
|
|
70
70
|
getEnrollment,
|
|
71
71
|
abandonRecordingForTurnAttempt,
|
|
72
72
|
markSessionAttemptQuiesced,
|
|
73
|
+
beginConnectorActionExecution,
|
|
74
|
+
completeConnectorActionExecution,
|
|
75
|
+
prepareConnectorActionApproval,
|
|
73
76
|
type AppendEventInput,
|
|
74
77
|
type ActiveSandboxPointer,
|
|
75
78
|
type SandboxRecord,
|
|
@@ -94,6 +97,7 @@ import {
|
|
|
94
97
|
composeAgentInstructions,
|
|
95
98
|
summarizeForCompaction,
|
|
96
99
|
requestRemoteCompactionV2,
|
|
100
|
+
serializedToolsForRemoteCompaction,
|
|
97
101
|
REMOTE_COMPACTION_V2_BETA_FEATURE,
|
|
98
102
|
REMOTE_COMPACTION_V2_IMPLEMENTATION,
|
|
99
103
|
CompactionProviderResponseError,
|
|
@@ -123,6 +127,7 @@ import {
|
|
|
123
127
|
type ModelCallUsageInput,
|
|
124
128
|
type ModelCallUsageNormalization,
|
|
125
129
|
type BuildAgentOptions,
|
|
130
|
+
type ConnectorActionPolicyHooks,
|
|
126
131
|
type RunAgentStreamOptions,
|
|
127
132
|
type TurnToolCancellationFence,
|
|
128
133
|
type BackendUnresolvableCode,
|
|
@@ -156,6 +161,7 @@ import {
|
|
|
156
161
|
settingsWithCodexCredential,
|
|
157
162
|
settingsWithEnabledCapabilityMcpServers,
|
|
158
163
|
settingsWithSessionMcpServersForRun,
|
|
164
|
+
settingsWithWorkspaceGatewayCredential,
|
|
159
165
|
} from "./capabilities";
|
|
160
166
|
import {
|
|
161
167
|
CODEX_USAGE_EXHAUSTED_PCT,
|
|
@@ -1769,9 +1775,11 @@ export async function reconcileActiveSandboxPointer(
|
|
|
1769
1775
|
/**
|
|
1770
1776
|
* Warm the Modal private-registry image for the image ref this turn actually
|
|
1771
1777
|
* resolved, not only the deployment-global OPENGENI_MODAL_IMAGE_REF warmed at
|
|
1772
|
-
* worker boot.
|
|
1773
|
-
*
|
|
1774
|
-
*
|
|
1778
|
+
* worker boot. A provider-native modalImageId bypasses registry import and is
|
|
1779
|
+
* resolved by ModalImageSelector.fromId during create. Otherwise packs can
|
|
1780
|
+
* override `modalImageRef` per workspace/turn, so a private pack image must be
|
|
1781
|
+
* resolved before sandbox creation or Modal falls back to the unauthenticated
|
|
1782
|
+
* `fromTag` path.
|
|
1775
1783
|
*/
|
|
1776
1784
|
export async function ensureTurnModalRegistryImage(
|
|
1777
1785
|
runSettings: Settings,
|
|
@@ -1781,6 +1789,9 @@ export async function ensureTurnModalRegistryImage(
|
|
|
1781
1789
|
if (sandboxCreationBackend !== "modal") {
|
|
1782
1790
|
return;
|
|
1783
1791
|
}
|
|
1792
|
+
if (runSettings.modalImageId) {
|
|
1793
|
+
return;
|
|
1794
|
+
}
|
|
1784
1795
|
if (!runSettings.modalImageRegistrySecret || !runSettings.modalImageRef) {
|
|
1785
1796
|
return;
|
|
1786
1797
|
}
|
|
@@ -1841,6 +1852,8 @@ export function shouldStartOnTurnRecording(params: {
|
|
|
1841
1852
|
* • a "chat" (OpenAIChatCompletionsModel wire) provider → "disabled": it cannot
|
|
1842
1853
|
* receive a screenshot through a proven visual transport, so computer use fails
|
|
1843
1854
|
* closed instead of serializing the image as text.
|
|
1855
|
+
* • Vercel Gateway providers → "disabled": their curated models support ordinary
|
|
1856
|
+
* function tools and vision input, not OpenAI's hosted computer tool.
|
|
1844
1857
|
* • everything else — built-in Azure/OpenAI responses, registry "responses"
|
|
1845
1858
|
* providers, AND the LEGACY global-client fallback (resolveTurnModel returned
|
|
1846
1859
|
* null) — → "hosted": real Responses hosted-tool support.
|
|
@@ -1858,12 +1871,28 @@ export function computerToolModeForTurn(
|
|
|
1858
1871
|
if (resolvedModel.provider.kind === "codex-subscription") {
|
|
1859
1872
|
return "function-image";
|
|
1860
1873
|
}
|
|
1874
|
+
if (
|
|
1875
|
+
resolvedModel.provider.kind === "vercel-gateway-managed" ||
|
|
1876
|
+
resolvedModel.provider.kind === "vercel-gateway-workspace"
|
|
1877
|
+
) {
|
|
1878
|
+
return "disabled";
|
|
1879
|
+
}
|
|
1861
1880
|
if (resolvedModel.provider.api === "chat") {
|
|
1862
1881
|
return "disabled";
|
|
1863
1882
|
}
|
|
1864
1883
|
return "hosted";
|
|
1865
1884
|
}
|
|
1866
1885
|
|
|
1886
|
+
/** Gateway models do not advertise OpenAI's hosted apply_patch/view_image tool types. */
|
|
1887
|
+
export function structuredToolTransportForTurn(
|
|
1888
|
+
resolvedModel: { provider: { kind: RegistryProviderKind } } | null,
|
|
1889
|
+
): boolean {
|
|
1890
|
+
if (!resolvedModel) return true;
|
|
1891
|
+
return !["codex-subscription", "vercel-gateway-managed", "vercel-gateway-workspace"].includes(
|
|
1892
|
+
resolvedModel.provider.kind,
|
|
1893
|
+
);
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1867
1896
|
/**
|
|
1868
1897
|
* Native web search is a runtime capability, not part of the session's MCP
|
|
1869
1898
|
* allow-list. Attach it whenever the resolved provider advertises runnable
|
|
@@ -3077,12 +3106,17 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
3077
3106
|
mcpSettings,
|
|
3078
3107
|
input.workspaceId,
|
|
3079
3108
|
);
|
|
3080
|
-
const
|
|
3109
|
+
const codexSettings = await settingsWithCodexCredential(
|
|
3081
3110
|
db,
|
|
3082
3111
|
input.workspaceId,
|
|
3083
3112
|
mcpSettings,
|
|
3084
3113
|
codexSubscriptionActive,
|
|
3085
3114
|
);
|
|
3115
|
+
const capabilitySettings = await settingsWithWorkspaceGatewayCredential(
|
|
3116
|
+
db,
|
|
3117
|
+
input.workspaceId,
|
|
3118
|
+
codexSettings,
|
|
3119
|
+
);
|
|
3086
3120
|
runtime.configure(capabilitySettings);
|
|
3087
3121
|
const session = await requireSession(db, input.workspaceId, input.sessionId);
|
|
3088
3122
|
const claim = await claimSessionWorkForAttempt(db, input.workspaceId, {
|
|
@@ -4030,7 +4064,11 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
4030
4064
|
// deployment default; a rig with no image (or a rig-less turn) is a
|
|
4031
4065
|
// pass-through, leaving the pack/deployment chain exactly as today.
|
|
4032
4066
|
...settingsWithRigImage(
|
|
4033
|
-
settingsWithPackSandboxImage(
|
|
4067
|
+
settingsWithPackSandboxImage(
|
|
4068
|
+
capabilitySettings,
|
|
4069
|
+
packRuntime.sandboxImage,
|
|
4070
|
+
packRuntime.sandboxProviderImages,
|
|
4071
|
+
),
|
|
4034
4072
|
rigVersion?.image ?? null,
|
|
4035
4073
|
),
|
|
4036
4074
|
openaiModel: turn.model,
|
|
@@ -4299,17 +4337,61 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
4299
4337
|
...(systemInstructions ? { systemInstructions } : {}),
|
|
4300
4338
|
...(promptCacheKey ? { promptCacheKey } : {}),
|
|
4301
4339
|
});
|
|
4340
|
+
// Prompt-cache prefix for remote_v2 MUST match ordinary turns:
|
|
4341
|
+
// tools → instructions → history. Filled after buildAgent for every
|
|
4342
|
+
// compact path (including operator /compact, which now builds the agent
|
|
4343
|
+
// first so it does not send empty tools/instructions).
|
|
4344
|
+
let remoteCompactionTools: Awaited<ReturnType<typeof serializedToolsForRemoteCompaction>> =
|
|
4345
|
+
[];
|
|
4346
|
+
let remoteCompactionInstructions = "";
|
|
4347
|
+
let remoteCompactionToolsReady = false;
|
|
4348
|
+
let remoteCompactionAgent: Parameters<typeof serializedToolsForRemoteCompaction>[0] | null =
|
|
4349
|
+
null;
|
|
4302
4350
|
const remoteCompactionRequester =
|
|
4303
4351
|
resolvedModel && isCodexTurn
|
|
4304
4352
|
? (s: Settings, m: Array<Record<string, unknown>>) =>
|
|
4305
|
-
withCodexRemoteCompaction(() =>
|
|
4306
|
-
|
|
4353
|
+
withCodexRemoteCompaction(async () => {
|
|
4354
|
+
// Lazily serialize tools here so EmptyCompactionSummaryError is
|
|
4355
|
+
// thrown inside the compaction try/settlement handlers, not as a
|
|
4356
|
+
// raw activity failure before maybeCompactContext runs.
|
|
4357
|
+
if (!remoteCompactionInstructions.trim()) {
|
|
4358
|
+
throw new EmptyCompactionSummaryError({
|
|
4359
|
+
stage: "remote_v2_instructions",
|
|
4360
|
+
reason: "agent_missing_system_instructions",
|
|
4361
|
+
});
|
|
4362
|
+
}
|
|
4363
|
+
if (!remoteCompactionToolsReady) {
|
|
4364
|
+
if (!remoteCompactionAgent) {
|
|
4365
|
+
throw new EmptyCompactionSummaryError({
|
|
4366
|
+
stage: "remote_v2_tools",
|
|
4367
|
+
reason: "agent_missing_for_tools",
|
|
4368
|
+
});
|
|
4369
|
+
}
|
|
4370
|
+
try {
|
|
4371
|
+
remoteCompactionTools =
|
|
4372
|
+
await serializedToolsForRemoteCompaction(remoteCompactionAgent);
|
|
4373
|
+
} catch (error) {
|
|
4374
|
+
// Tool schemas sit before instructions in the cache prefix.
|
|
4375
|
+
// Failing open to [] would reintroduce a massive pre-compact
|
|
4376
|
+
// cache bust — fail closed so we never send a tools mismatch
|
|
4377
|
+
// on purpose.
|
|
4378
|
+
throw new EmptyCompactionSummaryError({
|
|
4379
|
+
stage: "remote_v2_tools",
|
|
4380
|
+
reason: "serialize_tools_failed",
|
|
4381
|
+
error: String(error),
|
|
4382
|
+
});
|
|
4383
|
+
}
|
|
4384
|
+
remoteCompactionToolsReady = true;
|
|
4385
|
+
}
|
|
4386
|
+
return requestRemoteCompactionV2(s, m, {
|
|
4307
4387
|
client: resolvedModel.client,
|
|
4308
4388
|
model: turnExecutionPolicy.upstreamModelId,
|
|
4389
|
+
systemInstructions: remoteCompactionInstructions,
|
|
4309
4390
|
onUsage: recordCompactionUsage,
|
|
4391
|
+
tools: remoteCompactionTools,
|
|
4310
4392
|
...(promptCacheKey ? { promptCacheKey } : {}),
|
|
4311
|
-
})
|
|
4312
|
-
)
|
|
4393
|
+
});
|
|
4394
|
+
})
|
|
4313
4395
|
: undefined;
|
|
4314
4396
|
const publishCompactionLiveEvents = async (events: SessionEvent[]) => {
|
|
4315
4397
|
await publishDurableSessionEvents(bus, input.workspaceId, input.sessionId, events);
|
|
@@ -4335,7 +4417,17 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
4335
4417
|
: {}),
|
|
4336
4418
|
} as const;
|
|
4337
4419
|
|
|
4338
|
-
|
|
4420
|
+
// Operator /compact:
|
|
4421
|
+
// - portable (incl. Codex portable): early maintenance path — no
|
|
4422
|
+
// prepareTools/sandbox; summarizer only needs composed instructions.
|
|
4423
|
+
// - remote_v2: fall through to prepareTools/buildAgent so the compact
|
|
4424
|
+
// request reuses the ordinary tools→instructions cache prefix, then
|
|
4425
|
+
// settle without inference. (Requester is also wired for Codex portable
|
|
4426
|
+
// turns but unused there — gate on the frozen session mode.)
|
|
4427
|
+
const compactionOnlyTurn = turn.source === "compaction";
|
|
4428
|
+
const remoteV2CompactionNeedsAgentPrefix =
|
|
4429
|
+
Boolean(remoteCompactionRequester) && session.codexCompactionMode === "remote_v2";
|
|
4430
|
+
if (compactionOnlyTurn && !remoteV2CompactionNeedsAgentPrefix) {
|
|
4339
4431
|
const persistentSessionSettings = {
|
|
4340
4432
|
titleIsSet: Boolean(session.title?.trim()),
|
|
4341
4433
|
};
|
|
@@ -5470,6 +5562,32 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
5470
5562
|
turnExecutionPolicy.providerId,
|
|
5471
5563
|
turnExecutionPolicy.latencyMode,
|
|
5472
5564
|
);
|
|
5565
|
+
const connectorActionIdentity = {
|
|
5566
|
+
accountId: input.accountId,
|
|
5567
|
+
workspaceId: input.workspaceId,
|
|
5568
|
+
sessionId: input.sessionId,
|
|
5569
|
+
turnId,
|
|
5570
|
+
attemptId: input.attemptId,
|
|
5571
|
+
executionGeneration,
|
|
5572
|
+
initiator: {
|
|
5573
|
+
kind: turn.initiator.kind,
|
|
5574
|
+
subjectId: turn.initiator.subjectId,
|
|
5575
|
+
},
|
|
5576
|
+
} as const;
|
|
5577
|
+
const connectorActionPolicy: ConnectorActionPolicyHooks = {
|
|
5578
|
+
prepare: async (call) =>
|
|
5579
|
+
await prepareConnectorActionApproval(db, connectorActionIdentity, call),
|
|
5580
|
+
begin: async (call) =>
|
|
5581
|
+
await beginConnectorActionExecution(db, connectorActionIdentity, call),
|
|
5582
|
+
complete: async ({ requestId, outcome }) =>
|
|
5583
|
+
await completeConnectorActionExecution(db, {
|
|
5584
|
+
accountId: input.accountId,
|
|
5585
|
+
workspaceId: input.workspaceId,
|
|
5586
|
+
requestId,
|
|
5587
|
+
attemptId: input.attemptId,
|
|
5588
|
+
outcome,
|
|
5589
|
+
}),
|
|
5590
|
+
};
|
|
5473
5591
|
const agent = runtime.buildAgent(modelRunSettings, turnResources, {
|
|
5474
5592
|
reasoningEffort: turn.reasoningEffort,
|
|
5475
5593
|
latencyMode: turnExecutionPolicy.latencyMode,
|
|
@@ -5516,6 +5634,8 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
5516
5634
|
...(activeSandboxBackend ? { activeSandboxBackend } : {}),
|
|
5517
5635
|
fileResourceDownloads,
|
|
5518
5636
|
mcpServers: preparedTools.mcpServers,
|
|
5637
|
+
resolvedMcpConnectionIds: preparedTools.resolvedMcpConnectionIds,
|
|
5638
|
+
connectorActionPolicy,
|
|
5519
5639
|
// LIVE by-reference connector namespaces (fills during this turn's
|
|
5520
5640
|
// codex_apps tools/list): the codex tool_search description reads it per
|
|
5521
5641
|
// model call so the model sees the account's real connected sources.
|
|
@@ -5551,7 +5671,7 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
5551
5671
|
// (built-in OpenAI/Azure = real hosted support; registry "chat"
|
|
5552
5672
|
// providers = the SDK's own ChatCompletions detection) keeps the SDK
|
|
5553
5673
|
// default.
|
|
5554
|
-
structuredToolTransport: resolvedModel
|
|
5674
|
+
structuredToolTransport: structuredToolTransportForTurn(resolvedModel),
|
|
5555
5675
|
// EXPLICIT computer-use tool transport, derived from the resolved provider's
|
|
5556
5676
|
// authoritative wire identity (codex → function-image, chat → disabled,
|
|
5557
5677
|
// responses → hosted) so the runtime never string-sniffs the model instance's
|
|
@@ -5836,9 +5956,140 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
5836
5956
|
},
|
|
5837
5957
|
);
|
|
5838
5958
|
}
|
|
5959
|
+
const agentInstructions = typeof agent.instructions === "string" ? agent.instructions : "";
|
|
5839
5960
|
const compactSummarizer = compactionSummarizerFor(
|
|
5840
|
-
|
|
5961
|
+
agentInstructions.trim() ? agentInstructions : undefined,
|
|
5841
5962
|
);
|
|
5963
|
+
if (remoteCompactionRequester) {
|
|
5964
|
+
// Exact byte match with the ordinary turn prefix (CLI base_instructions).
|
|
5965
|
+
// Tools serialize lazily inside the requester so setup failures settle as
|
|
5966
|
+
// compaction failures rather than raw activity crashes.
|
|
5967
|
+
remoteCompactionInstructions = agentInstructions;
|
|
5968
|
+
remoteCompactionAgent = agent;
|
|
5969
|
+
}
|
|
5970
|
+
|
|
5971
|
+
if (compactionOnlyTurn) {
|
|
5972
|
+
const requested = await isSessionCompactionRequested(
|
|
5973
|
+
db,
|
|
5974
|
+
input.workspaceId,
|
|
5975
|
+
input.sessionId,
|
|
5976
|
+
);
|
|
5977
|
+
let outcome: Awaited<ReturnType<typeof maybeCompactContext>> | null = null;
|
|
5978
|
+
if (requested) {
|
|
5979
|
+
try {
|
|
5980
|
+
outcome = await waitForTurnOperation(
|
|
5981
|
+
maybeCompactContext(
|
|
5982
|
+
db,
|
|
5983
|
+
modelRunSettings,
|
|
5984
|
+
{
|
|
5985
|
+
accountId: input.accountId,
|
|
5986
|
+
workspaceId: input.workspaceId,
|
|
5987
|
+
sessionId: input.sessionId,
|
|
5988
|
+
turnId: turn.id,
|
|
5989
|
+
executionGeneration,
|
|
5990
|
+
attemptId: input.attemptId,
|
|
5991
|
+
},
|
|
5992
|
+
session.lastInputTokens,
|
|
5993
|
+
compactSummarizer,
|
|
5994
|
+
{
|
|
5995
|
+
force: true,
|
|
5996
|
+
clearRequestedCompaction: true,
|
|
5997
|
+
trigger: "operator",
|
|
5998
|
+
codexAccount: {
|
|
5999
|
+
currentCodexCredentialId: effectiveCodexCredentialId,
|
|
6000
|
+
},
|
|
6001
|
+
...compactionModeOptions,
|
|
6002
|
+
},
|
|
6003
|
+
),
|
|
6004
|
+
cancellationSignal,
|
|
6005
|
+
undefined,
|
|
6006
|
+
);
|
|
6007
|
+
} catch (error) {
|
|
6008
|
+
// Codex retries retryable checkpoint-provider failures rather than
|
|
6009
|
+
// treating them as a semantic compaction result. Keep the operator
|
|
6010
|
+
// request pending and let the ordinary same-turn provider/capacity
|
|
6011
|
+
// recovery path re-dispatch this exact maintenance execution.
|
|
6012
|
+
if (shouldRecoverCompactionProviderFailure(error)) throw error;
|
|
6013
|
+
if (error instanceof TurnAttemptFencedError) throw error;
|
|
6014
|
+
const landmark = await settleFailedContextCompactionLandmark(
|
|
6015
|
+
db,
|
|
6016
|
+
{
|
|
6017
|
+
accountId: input.accountId,
|
|
6018
|
+
workspaceId: input.workspaceId,
|
|
6019
|
+
sessionId: input.sessionId,
|
|
6020
|
+
turnId: turn.id,
|
|
6021
|
+
executionGeneration,
|
|
6022
|
+
attemptId: input.attemptId,
|
|
6023
|
+
},
|
|
6024
|
+
{
|
|
6025
|
+
clearRequestedCompaction: true,
|
|
6026
|
+
publishLiveEvents: publishCompactionLiveEvents,
|
|
6027
|
+
},
|
|
6028
|
+
);
|
|
6029
|
+
if (!isCompactionSummaryFailure(error)) throw error;
|
|
6030
|
+
const errorMessage = String(redact(compactionFailureReasonFromError(error)));
|
|
6031
|
+
if (
|
|
6032
|
+
!(await settle!({
|
|
6033
|
+
events: [
|
|
6034
|
+
{
|
|
6035
|
+
type: "turn.failed",
|
|
6036
|
+
payload: {
|
|
6037
|
+
error: errorMessage,
|
|
6038
|
+
code: "context_compaction_failed",
|
|
6039
|
+
retryable: false,
|
|
6040
|
+
recovery: "user_message",
|
|
6041
|
+
compacted: false,
|
|
6042
|
+
},
|
|
6043
|
+
},
|
|
6044
|
+
{
|
|
6045
|
+
type: "session.status.changed",
|
|
6046
|
+
payload: { status: "idle" },
|
|
6047
|
+
},
|
|
6048
|
+
],
|
|
6049
|
+
turnStatus: "failed",
|
|
6050
|
+
sessionStatus: "idle",
|
|
6051
|
+
activeTurnId: null,
|
|
6052
|
+
...(landmark.requestConsumed ? {} : { consumeRequestedCompactionFailure: true }),
|
|
6053
|
+
}))
|
|
6054
|
+
) {
|
|
6055
|
+
return claimedResult({ status: "cancelled" });
|
|
6056
|
+
}
|
|
6057
|
+
turnMetricOutcome = "failed";
|
|
6058
|
+
activityStatus = "idle";
|
|
6059
|
+
activityError = error;
|
|
6060
|
+
return claimedResult({ status: "idle" });
|
|
6061
|
+
}
|
|
6062
|
+
if (outcome.events.length > 0) {
|
|
6063
|
+
if (outcome.compacted) {
|
|
6064
|
+
recordContextCompaction(observability, "operator");
|
|
6065
|
+
}
|
|
6066
|
+
await publishCompactionOutcomeEvents(outcome.events);
|
|
6067
|
+
}
|
|
6068
|
+
}
|
|
6069
|
+
if (
|
|
6070
|
+
!(await settle!({
|
|
6071
|
+
events: [
|
|
6072
|
+
{
|
|
6073
|
+
type: "turn.completed",
|
|
6074
|
+
payload: {
|
|
6075
|
+
maintenance: "context_compaction",
|
|
6076
|
+
result: outcome?.compacted ? "compacted" : (outcome?.reason ?? "already_applied"),
|
|
6077
|
+
},
|
|
6078
|
+
},
|
|
6079
|
+
{ type: "session.status.changed", payload: { status: "idle" } },
|
|
6080
|
+
],
|
|
6081
|
+
turnStatus: "completed",
|
|
6082
|
+
sessionStatus: "idle",
|
|
6083
|
+
activeTurnId: null,
|
|
6084
|
+
}))
|
|
6085
|
+
) {
|
|
6086
|
+
return claimedResult({ status: "cancelled" });
|
|
6087
|
+
}
|
|
6088
|
+
turnMetricOutcome = "completed";
|
|
6089
|
+
activityStatus = "idle";
|
|
6090
|
+
return claimedResult({ status: "idle" });
|
|
6091
|
+
}
|
|
6092
|
+
|
|
5842
6093
|
// Pre-turn durable context compaction. When the single Codex-parity
|
|
5843
6094
|
// threshold is crossed, this summarizes active history and rebuilds active
|
|
5844
6095
|
// history as [user messages..., summary] BEFORE the model input is read.
|
|
@@ -2,12 +2,15 @@ import {
|
|
|
2
2
|
environmentsEncryptionKeyBytes,
|
|
3
3
|
type Settings,
|
|
4
4
|
withCodexCatalogProvider,
|
|
5
|
+
withWorkspaceGatewayCatalogProvider,
|
|
6
|
+
withWorkspaceGatewayCredential,
|
|
5
7
|
} from "@opengeni/config";
|
|
6
8
|
import { settingsWithEnabledCapabilityMcpServers } from "@opengeni/core";
|
|
7
9
|
import {
|
|
8
10
|
listSessionMcpServerMetadata,
|
|
9
11
|
listSessionMcpServersForRun,
|
|
10
12
|
workspaceCodexSubscriptionActive,
|
|
13
|
+
loadWorkspaceVercelAiGatewayApiKey,
|
|
11
14
|
type Database,
|
|
12
15
|
type SessionMcpServerForRun,
|
|
13
16
|
} from "@opengeni/db";
|
|
@@ -110,3 +113,13 @@ export async function settingsWithCodexCredential(
|
|
|
110
113
|
export function withCodexProvider(settings: Settings): Settings {
|
|
111
114
|
return withCodexCatalogProvider(settings);
|
|
112
115
|
}
|
|
116
|
+
|
|
117
|
+
export async function settingsWithWorkspaceGatewayCredential(
|
|
118
|
+
db: Database,
|
|
119
|
+
workspaceId: string,
|
|
120
|
+
settings: Settings,
|
|
121
|
+
): Promise<Settings> {
|
|
122
|
+
const catalogSettings = withWorkspaceGatewayCatalogProvider(settings);
|
|
123
|
+
const apiKey = await loadWorkspaceVercelAiGatewayApiKey(db, settings, workspaceId);
|
|
124
|
+
return apiKey ? withWorkspaceGatewayCredential(catalogSettings, apiKey) : catalogSettings;
|
|
125
|
+
}
|
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
|
|
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",
|