@opengeni/worker-bundle 0.2.0 → 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.0",
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.0",
42
- "@opengeni/contracts": "^0.3.0",
43
- "@opengeni/db": "^0.2.0",
44
- "@opengeni/documents": "^0.2.0",
45
- "@opengeni/events": "^0.2.0",
46
- "@opengeni/observability": "^0.2.0",
47
- "@opengeni/runtime": "^0.2.0",
48
- "@opengeni/storage": "^0.2.0",
40
+ "@opengeni/codex": "^0.2.1",
41
+ "@opengeni/config": "^0.2.2",
42
+ "@opengeni/contracts": "^0.4.0",
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";
@@ -325,6 +326,82 @@ export async function resolveActiveSandboxBackend(
325
326
  }
326
327
  }
327
328
 
329
+ /**
330
+ * Decide whether to start on-turn desktop recording for THIS turn.
331
+ *
332
+ * On-turn recording runs ffmpeg/x11grab INSIDE the box and reads the .mp4 back
333
+ * out of the box's /tmp — plumbing that exists only for OpenGeni-operated cloud
334
+ * boxes (the Modal desktop backend). A turn whose EFFECTIVE backend is a connected
335
+ * machine ("selfhosted") runs on the user's REAL computer, which has none of that
336
+ * capture plumbing (and the platform must never shell ffmpeg onto a user's machine
337
+ * — the same reason the runtime skips its setup hooks for selfhosted). Left ungated
338
+ * it films nothing, finds no /tmp file, and emits recording.started followed by
339
+ * recording.failed{box-death} on EVERY machine-primary turn — misleading timeline
340
+ * noise + wasted work. So gate it off, exactly like a recording-disabled deployment:
341
+ * skip silently, emit nothing (no new event shape).
342
+ *
343
+ * `effectiveBackend` is the resolved ACTIVE backend for the turn
344
+ * (resolveActiveSandboxBackend) — NOT the session's home backend. A modal-home
345
+ * session actively swapped onto a machine resolves to "selfhosted" here and
346
+ * correctly skips; a machine-home turn that degraded back to its cloud group box
347
+ * (swap-away / flag-off) resolves to undefined and records as before.
348
+ *
349
+ * EDGE — mid-turn swap: this is evaluated ONCE at turn start (the box is only filmed
350
+ * for the duration of one turn). A swap AFTER the recording starts is deliberately
351
+ * ignored — a partial-turn recording already has defined failure semantics, so we do
352
+ * not add machinery to stop/restart it mid-turn.
353
+ */
354
+ export function shouldStartOnTurnRecording(params: {
355
+ recordingEnabled: boolean;
356
+ desktopEnabled: boolean;
357
+ establishedBackendId: string;
358
+ effectiveBackend: Settings["sandboxBackend"] | undefined;
359
+ }): boolean {
360
+ return (
361
+ params.recordingEnabled
362
+ && params.desktopEnabled
363
+ && desktopCapableBackend(params.establishedBackendId)
364
+ && params.effectiveBackend !== "selfhosted"
365
+ );
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
+
328
405
  /**
329
406
  * SELF-HEAL helper for the all-capped rotation idle (invariant 4: BOUNDED, no thrash).
330
407
  * The turn hot path never refreshes Codex usage — only the usage API route does — so a
@@ -1046,9 +1123,15 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
1046
1123
  // `finally` (read+PUT in this same activity — never a Temporal payload).
1047
1124
  if (
1048
1125
  resolvedSandbox
1049
- && settings.sandboxDesktopEnabled
1050
- && settings.recordingEnabled
1051
- && desktopCapableBackend(resolvedSandbox.established.backendId)
1126
+ && shouldStartOnTurnRecording({
1127
+ recordingEnabled: settings.recordingEnabled,
1128
+ desktopEnabled: settings.sandboxDesktopEnabled,
1129
+ establishedBackendId: resolvedSandbox.established.backendId,
1130
+ // EFFECTIVE (active) backend, not the session home: a machine-primary turn
1131
+ // resolves to "selfhosted" and skips; a swap back to the cloud group box
1132
+ // resolves to undefined and records as before.
1133
+ effectiveBackend: activeSandboxBackend,
1134
+ })
1052
1135
  ) {
1053
1136
  try {
1054
1137
  const begun = await beginRecording({
@@ -1155,8 +1238,17 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
1155
1238
  // providers = the SDK's own ChatCompletions detection) keeps the SDK
1156
1239
  // default.
1157
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),
1158
1246
  }
1159
- : {}),
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) }),
1160
1252
  ...(packRuntime.skills.length > 0 ? { packSkills: packRuntime.skills } : {}),
1161
1253
  ...(workspaceAgentInstructions ? { instructionsTemplate: workspaceAgentInstructions } : {}),
1162
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 };