@opengeni/worker-bundle 0.15.0 → 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.
@@ -579,6 +579,8 @@ export declare function shouldStartOnTurnRecording(params: {
579
579
  * • a "chat" (OpenAIChatCompletionsModel wire) provider → "disabled": it cannot
580
580
  * receive a screenshot through a proven visual transport, so computer use fails
581
581
  * closed instead of serializing the image as text.
582
+ * • Vercel Gateway providers → "disabled": their curated models support ordinary
583
+ * function tools and vision input, not OpenAI's hosted computer tool.
582
584
  * • everything else — built-in Azure/OpenAI responses, registry "responses"
583
585
  * providers, AND the LEGACY global-client fallback (resolveTurnModel returned
584
586
  * null) — → "hosted": real Responses hosted-tool support.
@@ -591,6 +593,12 @@ export declare function computerToolModeForTurn(resolvedModel: {
591
593
  api: ModelProviderApi;
592
594
  };
593
595
  } | null): ComputerToolMode;
596
+ /** Gateway models do not advertise OpenAI's hosted apply_patch/view_image tool types. */
597
+ export declare function structuredToolTransportForTurn(resolvedModel: {
598
+ provider: {
599
+ kind: RegistryProviderKind;
600
+ };
601
+ } | null): boolean;
594
602
  /**
595
603
  * Native web search is a runtime capability, not part of the session's MCP
596
604
  * allow-list. Attach it whenever the resolved provider advertises runnable
@@ -16,3 +16,4 @@ export declare function settingsWithSessionMcpServers(settings: Settings, server
16
16
  export declare function settingsWithCodexCredential(db: Database, workspaceId: string, settings: Settings, activeOverride?: boolean): Promise<Settings>;
17
17
  /** Pure: append the synthetic codex-subscription provider, idempotently. */
18
18
  export declare function withCodexProvider(settings: Settings): Settings;
19
+ export declare function settingsWithWorkspaceGatewayCredential(db: Database, workspaceId: string, settings: Settings): Promise<Settings>;
package/dist/index.js CHANGED
@@ -134,6 +134,7 @@ import {
134
134
  composeAgentInstructions,
135
135
  summarizeForCompaction as summarizeForCompaction2,
136
136
  requestRemoteCompactionV2,
137
+ serializedToolsForRemoteCompaction,
137
138
  REMOTE_COMPACTION_V2_BETA_FEATURE,
138
139
  REMOTE_COMPACTION_V2_IMPLEMENTATION as REMOTE_COMPACTION_V2_IMPLEMENTATION2,
139
140
  CompactionProviderResponseError,
@@ -201,13 +202,16 @@ import { ApplicationFailure, CancelledFailure as CancelledFailure2 } from "@temp
201
202
  // src/activities/capabilities.ts
202
203
  import {
203
204
  environmentsEncryptionKeyBytes,
204
- withCodexCatalogProvider
205
+ withCodexCatalogProvider,
206
+ withWorkspaceGatewayCatalogProvider,
207
+ withWorkspaceGatewayCredential
205
208
  } from "@opengeni/config";
206
209
  import { settingsWithEnabledCapabilityMcpServers } from "@opengeni/core";
207
210
  import {
208
211
  listSessionMcpServerMetadata,
209
212
  listSessionMcpServersForRun,
210
- workspaceCodexSubscriptionActive
213
+ workspaceCodexSubscriptionActive,
214
+ loadWorkspaceVercelAiGatewayApiKey
211
215
  } from "@opengeni/db";
212
216
  async function settingsWithSessionMcpServersForRun(db, workspaceId, sessionId, attemptId, settings, options) {
213
217
  const encryptionKey = environmentsEncryptionKeyBytes(settings);
@@ -266,6 +270,11 @@ async function settingsWithCodexCredential(db, workspaceId, settings, activeOver
266
270
  function withCodexProvider(settings) {
267
271
  return withCodexCatalogProvider(settings);
268
272
  }
273
+ async function settingsWithWorkspaceGatewayCredential(db, workspaceId, settings) {
274
+ const catalogSettings = withWorkspaceGatewayCatalogProvider(settings);
275
+ const apiKey = await loadWorkspaceVercelAiGatewayApiKey(db, settings, workspaceId);
276
+ return apiKey ? withWorkspaceGatewayCredential(catalogSettings, apiKey) : catalogSettings;
277
+ }
269
278
 
270
279
  // src/activities/codex-rotation.ts
271
280
  function effectiveRotationStrategy(_stored) {
@@ -7067,11 +7076,20 @@ function computerToolModeForTurn(resolvedModel) {
7067
7076
  if (resolvedModel.provider.kind === "codex-subscription") {
7068
7077
  return "function-image";
7069
7078
  }
7079
+ if (resolvedModel.provider.kind === "vercel-gateway-managed" || resolvedModel.provider.kind === "vercel-gateway-workspace") {
7080
+ return "disabled";
7081
+ }
7070
7082
  if (resolvedModel.provider.api === "chat") {
7071
7083
  return "disabled";
7072
7084
  }
7073
7085
  return "hosted";
7074
7086
  }
7087
+ function structuredToolTransportForTurn(resolvedModel) {
7088
+ if (!resolvedModel) return true;
7089
+ return !["codex-subscription", "vercel-gateway-managed", "vercel-gateway-workspace"].includes(
7090
+ resolvedModel.provider.kind
7091
+ );
7092
+ }
7075
7093
  function hostedWebSearchForTurn(resolvedModel, deploymentWebSearchEnabled) {
7076
7094
  return resolvedModel?.configured.hostedWebSearch ?? deploymentWebSearchEnabled;
7077
7095
  }
@@ -7862,12 +7880,17 @@ function createRunAgentTurnActivity(services) {
7862
7880
  mcpSettings,
7863
7881
  input.workspaceId
7864
7882
  );
7865
- const capabilitySettings = await settingsWithCodexCredential(
7883
+ const codexSettings = await settingsWithCodexCredential(
7866
7884
  db,
7867
7885
  input.workspaceId,
7868
7886
  mcpSettings,
7869
7887
  codexSubscriptionActive
7870
7888
  );
7889
+ const capabilitySettings = await settingsWithWorkspaceGatewayCredential(
7890
+ db,
7891
+ input.workspaceId,
7892
+ codexSettings
7893
+ );
7871
7894
  runtime.configure(capabilitySettings);
7872
7895
  const session = await requireSession2(db, input.workspaceId, input.sessionId);
7873
7896
  const claim = await claimSessionWorkForAttempt(db, input.workspaceId, {
@@ -8840,14 +8863,44 @@ function createRunAgentTurnActivity(services) {
8840
8863
  ...systemInstructions ? { systemInstructions } : {},
8841
8864
  ...promptCacheKey ? { promptCacheKey } : {}
8842
8865
  });
8843
- const remoteCompactionRequester = resolvedModel && isCodexTurn ? (s, m) => withCodexRemoteCompaction(
8844
- () => requestRemoteCompactionV2(s, m, {
8866
+ let remoteCompactionTools = [];
8867
+ let remoteCompactionInstructions = "";
8868
+ let remoteCompactionToolsReady = false;
8869
+ let remoteCompactionAgent = null;
8870
+ const remoteCompactionRequester = resolvedModel && isCodexTurn ? (s, m) => withCodexRemoteCompaction(async () => {
8871
+ if (!remoteCompactionInstructions.trim()) {
8872
+ throw new EmptyCompactionSummaryError2({
8873
+ stage: "remote_v2_instructions",
8874
+ reason: "agent_missing_system_instructions"
8875
+ });
8876
+ }
8877
+ if (!remoteCompactionToolsReady) {
8878
+ if (!remoteCompactionAgent) {
8879
+ throw new EmptyCompactionSummaryError2({
8880
+ stage: "remote_v2_tools",
8881
+ reason: "agent_missing_for_tools"
8882
+ });
8883
+ }
8884
+ try {
8885
+ remoteCompactionTools = await serializedToolsForRemoteCompaction(remoteCompactionAgent);
8886
+ } catch (error) {
8887
+ throw new EmptyCompactionSummaryError2({
8888
+ stage: "remote_v2_tools",
8889
+ reason: "serialize_tools_failed",
8890
+ error: String(error)
8891
+ });
8892
+ }
8893
+ remoteCompactionToolsReady = true;
8894
+ }
8895
+ return requestRemoteCompactionV2(s, m, {
8845
8896
  client: resolvedModel.client,
8846
8897
  model: turnExecutionPolicy.upstreamModelId,
8898
+ systemInstructions: remoteCompactionInstructions,
8847
8899
  onUsage: recordCompactionUsage,
8900
+ tools: remoteCompactionTools,
8848
8901
  ...promptCacheKey ? { promptCacheKey } : {}
8849
- })
8850
- ) : void 0;
8902
+ });
8903
+ }) : void 0;
8851
8904
  const publishCompactionLiveEvents = async (events) => {
8852
8905
  await publishDurableSessionEvents(bus, input.workspaceId, input.sessionId, events);
8853
8906
  };
@@ -8866,7 +8919,9 @@ function createRunAgentTurnActivity(services) {
8866
8919
  ...remoteCompactionRequester ? { requestRemoteCompactionV2: remoteCompactionRequester } : {},
8867
8920
  ...effectiveCodexCredentialId ? { producerCodexCredentialId: effectiveCodexCredentialId } : {}
8868
8921
  };
8869
- if (turn.source === "compaction") {
8922
+ const compactionOnlyTurn = turn.source === "compaction";
8923
+ const remoteV2CompactionNeedsAgentPrefix = Boolean(remoteCompactionRequester) && session.codexCompactionMode === "remote_v2";
8924
+ if (compactionOnlyTurn && !remoteV2CompactionNeedsAgentPrefix) {
8870
8925
  const persistentSessionSettings = {
8871
8926
  titleIsSet: Boolean(session.title?.trim())
8872
8927
  };
@@ -9824,7 +9879,7 @@ function createRunAgentTurnActivity(services) {
9824
9879
  // (built-in OpenAI/Azure = real hosted support; registry "chat"
9825
9880
  // providers = the SDK's own ChatCompletions detection) keeps the SDK
9826
9881
  // default.
9827
- structuredToolTransport: resolvedModel.provider.kind !== "codex-subscription",
9882
+ structuredToolTransport: structuredToolTransportForTurn(resolvedModel),
9828
9883
  // EXPLICIT computer-use tool transport, derived from the resolved provider's
9829
9884
  // authoritative wire identity (codex → function-image, chat → disabled,
9830
9885
  // responses → hosted) so the runtime never string-sniffs the model instance's
@@ -10069,9 +10124,127 @@ function createRunAgentTurnActivity(services) {
10069
10124
  }
10070
10125
  );
10071
10126
  }
10127
+ const agentInstructions = typeof agent.instructions === "string" ? agent.instructions : "";
10072
10128
  const compactSummarizer = compactionSummarizerFor(
10073
- typeof agent.instructions === "string" ? agent.instructions : void 0
10129
+ agentInstructions.trim() ? agentInstructions : void 0
10074
10130
  );
10131
+ if (remoteCompactionRequester) {
10132
+ remoteCompactionInstructions = agentInstructions;
10133
+ remoteCompactionAgent = agent;
10134
+ }
10135
+ if (compactionOnlyTurn) {
10136
+ const requested = await isSessionCompactionRequested(
10137
+ db,
10138
+ input.workspaceId,
10139
+ input.sessionId
10140
+ );
10141
+ let outcome = null;
10142
+ if (requested) {
10143
+ try {
10144
+ outcome = await waitForTurnOperation(
10145
+ maybeCompactContext(
10146
+ db,
10147
+ modelRunSettings,
10148
+ {
10149
+ accountId: input.accountId,
10150
+ workspaceId: input.workspaceId,
10151
+ sessionId: input.sessionId,
10152
+ turnId: turn.id,
10153
+ executionGeneration,
10154
+ attemptId: input.attemptId
10155
+ },
10156
+ session.lastInputTokens,
10157
+ compactSummarizer,
10158
+ {
10159
+ force: true,
10160
+ clearRequestedCompaction: true,
10161
+ trigger: "operator",
10162
+ codexAccount: {
10163
+ currentCodexCredentialId: effectiveCodexCredentialId
10164
+ },
10165
+ ...compactionModeOptions
10166
+ }
10167
+ ),
10168
+ cancellationSignal,
10169
+ void 0
10170
+ );
10171
+ } catch (error) {
10172
+ if (shouldRecoverCompactionProviderFailure(error)) throw error;
10173
+ if (error instanceof TurnAttemptFencedError) throw error;
10174
+ const landmark = await settleFailedContextCompactionLandmark(
10175
+ db,
10176
+ {
10177
+ accountId: input.accountId,
10178
+ workspaceId: input.workspaceId,
10179
+ sessionId: input.sessionId,
10180
+ turnId: turn.id,
10181
+ executionGeneration,
10182
+ attemptId: input.attemptId
10183
+ },
10184
+ {
10185
+ clearRequestedCompaction: true,
10186
+ publishLiveEvents: publishCompactionLiveEvents
10187
+ }
10188
+ );
10189
+ if (!isCompactionSummaryFailure(error)) throw error;
10190
+ const errorMessage = String(redact(compactionFailureReasonFromError(error)));
10191
+ if (!await settle({
10192
+ events: [
10193
+ {
10194
+ type: "turn.failed",
10195
+ payload: {
10196
+ error: errorMessage,
10197
+ code: "context_compaction_failed",
10198
+ retryable: false,
10199
+ recovery: "user_message",
10200
+ compacted: false
10201
+ }
10202
+ },
10203
+ {
10204
+ type: "session.status.changed",
10205
+ payload: { status: "idle" }
10206
+ }
10207
+ ],
10208
+ turnStatus: "failed",
10209
+ sessionStatus: "idle",
10210
+ activeTurnId: null,
10211
+ ...landmark.requestConsumed ? {} : { consumeRequestedCompactionFailure: true }
10212
+ })) {
10213
+ return claimedResult({ status: "cancelled" });
10214
+ }
10215
+ turnMetricOutcome = "failed";
10216
+ activityStatus = "idle";
10217
+ activityError = error;
10218
+ return claimedResult({ status: "idle" });
10219
+ }
10220
+ if (outcome.events.length > 0) {
10221
+ if (outcome.compacted) {
10222
+ recordContextCompaction(observability, "operator");
10223
+ }
10224
+ await publishCompactionOutcomeEvents(outcome.events);
10225
+ }
10226
+ }
10227
+ if (!await settle({
10228
+ events: [
10229
+ {
10230
+ type: "turn.completed",
10231
+ payload: {
10232
+ maintenance: "context_compaction",
10233
+ result: outcome?.compacted ? "compacted" : outcome?.reason ?? "already_applied"
10234
+ }
10235
+ },
10236
+ { type: "session.status.changed", payload: { status: "idle" } }
10237
+ ],
10238
+ turnStatus: "completed",
10239
+ sessionStatus: "idle",
10240
+ activeTurnId: null
10241
+ })) {
10242
+ return claimedResult({ status: "cancelled" });
10243
+ }
10244
+ turnMetricOutcome = "completed";
10245
+ activityStatus = "idle";
10246
+ return claimedResult({ status: "idle" });
10247
+ }
10075
10248
  if (triggerType === "user.message" || triggerType === "system.update.delivered") {
10076
10249
  let forced = false;
10077
10250
  try {