@opengeni/worker-bundle 0.2.1 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeni/worker-bundle",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "OpenGeni worker entry: runOpenGeniWorker/createOpenGeniWorker(deps) + the un-bundled Temporal workflow source tree. An engine-distribution surface — its runtime closure includes engine-internal packages and the workflow bundle ships as on-disk TS source.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -37,15 +37,15 @@
37
37
  "build": "tsup"
38
38
  },
39
39
  "dependencies": {
40
- "@opengeni/codex": "^0.2.0",
41
- "@opengeni/config": "^0.2.1",
40
+ "@opengeni/codex": "^0.2.1",
41
+ "@opengeni/config": "^0.2.2",
42
42
  "@opengeni/contracts": "^0.4.0",
43
- "@opengeni/db": "^0.2.1",
44
- "@opengeni/documents": "^0.2.1",
45
- "@opengeni/events": "^0.2.1",
46
- "@opengeni/observability": "^0.2.0",
47
- "@opengeni/runtime": "^0.2.1",
48
- "@opengeni/storage": "^0.2.1",
43
+ "@opengeni/db": "^0.2.2",
44
+ "@opengeni/documents": "^0.2.2",
45
+ "@opengeni/events": "^0.2.2",
46
+ "@opengeni/observability": "^0.2.1",
47
+ "@opengeni/runtime": "^0.2.2",
48
+ "@opengeni/storage": "^0.2.2",
49
49
  "@temporalio/activity": "^1.17.0",
50
50
  "@temporalio/client": "^1.17.0",
51
51
  "@temporalio/worker": "^1.17.0",
@@ -51,8 +51,9 @@ import {
51
51
  summarizeForCompaction,
52
52
  type SandboxFileDownload,
53
53
  type OpenGeniRuntime,
54
+ type ComputerToolMode,
54
55
  } from "@opengeni/runtime";
55
- import { calculateModelUsageCostMicros, configuredModelPricing, configuredStaticUsageLimits, sandboxWarmRateMicrosPerSecond, type ModelUsageInput, type Settings } from "@opengeni/config";
56
+ import { calculateModelUsageCostMicros, configuredModelPricing, configuredStaticUsageLimits, sandboxWarmRateMicrosPerSecond, type ModelUsageInput, type ModelProviderApi, type RegistryProviderKind, type Settings } from "@opengeni/config";
56
57
  import { CancelledFailure } from "@temporalio/activity";
57
58
  import { settingsWithCodexCredential, settingsWithEnabledCapabilityMcpServers } from "./capabilities";
58
59
  import { chooseRotationActive, computeIdleDelayMs, computeReactiveRotationResume, type CodexRotationStrategy, type RotationDecision } from "./codex-rotation";
@@ -364,6 +365,43 @@ export function shouldStartOnTurnRecording(params: {
364
365
  );
365
366
  }
366
367
 
368
+ /**
369
+ * Decide the EXPLICIT computer-use tool transport for THIS turn.
370
+ *
371
+ * The runtime's SDK-mirrored capability would otherwise pick hosted-vs-function
372
+ * tools by string-sniffing the bound model instance's constructor name for
373
+ * "ChatCompletions" (supportsStructuredToolOutputTransport). That is fragile: a
374
+ * wrapped / proxied / minified model instance defeats the sniff and a
375
+ * chat-completions provider would silently get the HOSTED `computer_use_preview`
376
+ * tool it 400s on every turn. So the mode is decided HERE — the worker's model
377
+ * resolution is the ONE place a provider's true wire identity is authoritative —
378
+ * and threaded to the runtime as an explicit flag (buildAgent → computerToolMode):
379
+ * • codex-subscription → "function-image": the ChatGPT/Codex backend rejects
380
+ * hosted tool types but SEES structured `input_image` tool results.
381
+ * • a "chat" (OpenAIChatCompletionsModel wire) provider → "function-text": it takes
382
+ * function tools but can't read structured image results, so screenshots render
383
+ * as a text data-URL.
384
+ * • everything else — built-in Azure/OpenAI responses, registry "responses"
385
+ * providers, AND the LEGACY global-client fallback (resolveTurnModel returned
386
+ * null) — → "hosted": real Responses hosted-tool support.
387
+ *
388
+ * Pure + exported so the mapping is unit-testable without a live turn.
389
+ */
390
+ export function computerToolModeForTurn(
391
+ resolvedModel: { provider: { kind: RegistryProviderKind; api: ModelProviderApi } } | null,
392
+ ): ComputerToolMode {
393
+ if (!resolvedModel) {
394
+ return "hosted"; // legacy built-in Responses client — real hosted support
395
+ }
396
+ if (resolvedModel.provider.kind === "codex-subscription") {
397
+ return "function-image";
398
+ }
399
+ if (resolvedModel.provider.api === "chat") {
400
+ return "function-text";
401
+ }
402
+ return "hosted";
403
+ }
404
+
367
405
  /**
368
406
  * SELF-HEAL helper for the all-capped rotation idle (invariant 4: BOUNDED, no thrash).
369
407
  * The turn hot path never refreshes Codex usage — only the usage API route does — so a
@@ -1200,8 +1238,17 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
1200
1238
  // providers = the SDK's own ChatCompletions detection) keeps the SDK
1201
1239
  // default.
1202
1240
  structuredToolTransport: resolvedModel.provider.kind !== "codex-subscription",
1241
+ // EXPLICIT computer-use tool transport, derived from the resolved provider's
1242
+ // authoritative wire identity (codex → function-image, chat → function-text,
1243
+ // responses → hosted) so the runtime never string-sniffs the model instance's
1244
+ // constructor name. See {@link computerToolModeForTurn}.
1245
+ computerToolMode: computerToolModeForTurn(resolvedModel),
1203
1246
  }
1204
- : {}),
1247
+ // LEGACY global-client fallback (resolveTurnModel returned null → the model
1248
+ // is not in the registry, served by the built-in OpenAI/Azure Responses
1249
+ // client). That backend has real hosted support, so pin computerToolMode to
1250
+ // "hosted" EXPLICITLY rather than leaving the runtime to sniff the instance.
1251
+ : { computerToolMode: computerToolModeForTurn(null) }),
1205
1252
  ...(packRuntime.skills.length > 0 ? { packSkills: packRuntime.skills } : {}),
1206
1253
  ...(workspaceAgentInstructions ? { instructionsTemplate: workspaceAgentInstructions } : {}),
1207
1254
  ...(workspaceEnvironment
package/src/index.ts CHANGED
@@ -16,6 +16,11 @@ export type WorkerOptions = {
16
16
  settings?: Settings;
17
17
  activities?: ReturnType<typeof createActivities>;
18
18
  activityDependencies?: ActivityDependencies;
19
+ // Embedded hosts install @opengeni/worker-bundle under node_modules, where
20
+ // Temporal's workflow webpack refuses to transpile TS. They relocate
21
+ // src/workflows.ts to a host-owned path and point the worker at it here.
22
+ // Unset (standalone) keeps today's in-package path byte-for-byte.
23
+ workflowsPath?: string;
19
24
  };
20
25
 
21
26
  export async function createOpenGeniWorker(options: WorkerOptions = {}): Promise<{
@@ -41,7 +46,7 @@ export async function createOpenGeniWorker(options: WorkerOptions = {}): Promise
41
46
  connection,
42
47
  namespace: settings.temporalNamespace,
43
48
  taskQueue: settings.temporalTaskQueue,
44
- workflowsPath: new URL("../src/workflows.ts", import.meta.url).pathname,
49
+ workflowsPath: options.workflowsPath ?? new URL("../src/workflows.ts", import.meta.url).pathname,
45
50
  activities,
46
51
  });
47
52
  return { worker, connection };