@opengeni/runtime 0.2.2 → 0.3.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.
@@ -3,6 +3,7 @@ export { collectSandboxEnvironment, parseExposedPorts } from '@opengeni/config';
3
3
  import { SandboxBackend, CapabilityDescriptor, SandboxOs, SessionCapabilities, StreamTokenPayload, SessionEventType, SessionStructuredCapabilities, FsListRequest, FsListResponse, FsReadRequest, FsReadResponse, FsWriteRequest, FsWriteResponse, FsDeleteRequest, FsDeleteResponse, FsMoveRequest, FsMoveResponse, FsMkdirRequest, FsMkdirResponse, GitStatusRequest, GitStatusResponse, GitDiffRequest, GitDiffResponse, GitLogRequest, GitLogResponse, GitShowRequest, GitShowResponse, TerminalExecRequest, TerminalExecResponse, PtyOpenRequest, PtyOpenResponse, PtyWriteRequest, PtyResizeRequest, PtyCloseRequest, GitChangedPayload, GitDiffHunk, GitFileStatusCode, CapabilityUnavailableReason } from '@opengeni/contracts';
4
4
  export { CAPABILITY_DESCRIPTORS, CapabilityDescriptor, DESKTOP_STREAM_PORT, StreamTokenPayload, StreamTokenPayload as StreamTokenPayloadType, TERMINAL_STREAM_PORT } from '@opengeni/contracts';
5
5
  import { Manifest, SandboxClient, SandboxSessionState } from '@openai/agents/sandbox';
6
+ import * as modal from 'modal';
6
7
  import { ControlRequest, ControlResponse, ErrorCode, AgentError, DesktopInputRequest, ExecRequest, ExecResponse } from '@opengeni/agent-proto';
7
8
 
8
9
  /**
@@ -61,6 +62,38 @@ declare const PROVIDER_REGISTRY: Record<SandboxBackend, ProviderRegistration>;
61
62
  */
62
63
  declare function assertProviderRegistryInvariants(): void;
63
64
 
65
+ type ModalSandboxAttribution = {
66
+ leaseId: string;
67
+ workspaceId: string;
68
+ sandboxGroupId: string;
69
+ };
70
+ type LiveModalSandboxLeaseAttribution = ModalSandboxAttribution & {
71
+ instanceId: string | null;
72
+ liveness?: string;
73
+ };
74
+ type ModalOrphanSweepTermination = {
75
+ sandboxId: string;
76
+ reason: "stale_attribution" | "unattributed";
77
+ tags: Record<string, string>;
78
+ };
79
+ type ModalOrphanSweepResult = {
80
+ examined: number;
81
+ terminated: ModalOrphanSweepTermination[];
82
+ skipped: number;
83
+ };
84
+ declare function modalSandboxAttributionEnvironment(input: ModalSandboxAttribution): Record<string, string>;
85
+ declare function modalSandboxAttributionTags(input: ModalSandboxAttribution): Record<string, string>;
86
+ type ModalModule = typeof modal;
87
+ type ModalClientLike = InstanceType<ModalModule["ModalClient"]>;
88
+ declare function tagModalSandbox(settings: Settings, sandboxId: string, attribution: ModalSandboxAttribution): Promise<boolean>;
89
+ declare function terminateModalSandboxById(settings: Settings, sandboxId: string): Promise<boolean>;
90
+ declare function sweepModalOrphanSandboxes(settings: Settings, liveLeases: LiveModalSandboxLeaseAttribution[], options?: {
91
+ now?: Date;
92
+ maxTerminations?: number;
93
+ unattributedGraceMs?: number;
94
+ client?: ModalClientLike;
95
+ }): Promise<ModalOrphanSweepResult>;
96
+
64
97
  interface NegotiationContext {
65
98
  sessionId: string;
66
99
  backend: SandboxBackend;
@@ -220,7 +253,7 @@ declare function mintStreamToken(secret: string, input: MintStreamTokenInput): P
220
253
  declare function verifyStreamToken(secret: string, token: string, nowSeconds?: number): Promise<StreamTokenPayload | null>;
221
254
 
222
255
  declare const STREAM_PORT = 6080;
223
- declare const DISPLAY_STACK_TIMEOUT_MS = 60000;
256
+ declare const DISPLAY_STACK_TIMEOUT_MS = 90000;
224
257
  /** Desktop geometry for the framebuffer. v1 has no live RANDR: a resolution
225
258
  * change is a full down -> up restart (a separate op). */
226
259
  type DesktopGeometry = {
@@ -230,11 +263,13 @@ type DesktopGeometry = {
230
263
  };
231
264
  declare const DEFAULT_DESKTOP_GEOMETRY: DesktopGeometry;
232
265
  /** Thrown when a stage of the launch script failed. exitCode 11/12/13 map to
233
- * Xvfb / x11vnc / websockify respectively (the stage that died). Degradation is
234
- * surfaced as a value to viewers by the caller; this error is for diagnostics. */
266
+ * Xvfb / x11vnc / websockify respectively (the stage that died); 14 is the
267
+ * PAINTABLE-FRAME gate (ports listening but scrot still yields an empty frame
268
+ * the display is up but not actually painting). Degradation is surfaced as a
269
+ * value to viewers by the caller; this error is for diagnostics. */
235
270
  declare class DisplayStackError extends Error {
236
271
  readonly exitCode: number;
237
- readonly stage: "xvfb" | "x11vnc" | "websockify" | "unknown";
272
+ readonly stage: "xvfb" | "x11vnc" | "websockify" | "paint" | "unknown";
238
273
  constructor(exitCode: number, output: string);
239
274
  }
240
275
  /** Thrown when the provider session cannot run commands (a headless-only
@@ -1049,11 +1084,18 @@ declare class SelfhostedSession {
1049
1084
  /** Computer-use VIEW op: capture a single PNG screenshot of the machine's desktop
1050
1085
  * plus its geometry (via ScreenCaptureKit / x11). NOT consent-gated (a view op —
1051
1086
  * the view/control decoupling), so it works with a display but no screen-control
1052
- * consent. Returns the raw encoded bytes + width/height. */
1087
+ * consent. Returns the raw encoded bytes + the ENCODED width/height, plus the
1088
+ * NATIVE (pre-downscale) geometry: when the agent had to downscale the PNG to fit
1089
+ * the transport's max payload, `nativeWidth`/`nativeHeight` carry the original
1090
+ * capture size so the computer-use layer can scale model clicks (in encoded-pixel
1091
+ * space) back to native pixels. An older agent leaves them 0 → read as "same as
1092
+ * width/height" (no downscale). */
1053
1093
  screenshot(): Promise<{
1054
1094
  png: Uint8Array;
1055
1095
  width: number;
1056
1096
  height: number;
1097
+ nativeWidth: number;
1098
+ nativeHeight: number;
1057
1099
  }>;
1058
1100
  /** A cheap liveness probe — request a Ping on the subject; returns true iff a
1059
1101
  * responder answered (no AgentError). Used by `negotiateSelfhostedCapabilities`.
@@ -1373,6 +1415,8 @@ interface RoutableBackendSession {
1373
1415
  png: Uint8Array;
1374
1416
  width: number;
1375
1417
  height: number;
1418
+ nativeWidth: number;
1419
+ nativeHeight: number;
1376
1420
  }>;
1377
1421
  }
1378
1422
  /** The resolved active backend for an epoch: the live session + the sandbox id it
@@ -1455,6 +1499,8 @@ declare class RoutingSandboxSession implements RoutableBackendSession {
1455
1499
  png: Uint8Array;
1456
1500
  width: number;
1457
1501
  height: number;
1502
+ nativeWidth: number;
1503
+ nativeHeight: number;
1458
1504
  }>;
1459
1505
  constructor(deps: RoutingSandboxSessionDeps);
1460
1506
  /**
@@ -1687,6 +1733,7 @@ type EstablishedSandboxSession = {
1687
1733
  instanceId: string;
1688
1734
  backendId: string;
1689
1735
  };
1736
+ type SandboxCreatedCallback = (established: EstablishedSandboxSession) => Promise<void>;
1690
1737
  /**
1691
1738
  * Per-provider NotFound discriminator. The @openai/agents-extensions
1692
1739
  * `isProviderSandboxNotFoundError` / `assertResumeRecreateAllowed` helpers live
@@ -1720,6 +1767,7 @@ declare function establishSandboxSessionFromEnvelope(settings: Settings, envelop
1720
1767
  sessionId: string;
1721
1768
  backendOverride?: SandboxBackend;
1722
1769
  environment?: Record<string, string>;
1770
+ onSandboxCreated?: SandboxCreatedCallback;
1723
1771
  }): Promise<EstablishedSandboxSession>;
1724
1772
  /**
1725
1773
  * Fold a freshly-established (or resumed) sandbox session into the persistable
@@ -1735,4 +1783,4 @@ declare function establishSandboxSessionFromEnvelope(settings: Settings, envelop
1735
1783
  */
1736
1784
  declare function serializeEstablishedSandboxEnvelope(established: EstablishedSandboxSession): Promise<Record<string, unknown> | null>;
1737
1785
 
1738
- export { type ActiveBackendResolverDeps, ActiveBackendUnresolvableError, type ActivePointer, ChannelAConflictError, type ChannelAEmitter, type ChannelAExecArgs, type ChannelAExecResult, ChannelANotFoundError, type ChannelASession, ChannelAUnsupportedError, ChannelAValidationError, type ControlRpc, DEFAULT_DESKTOP_GEOMETRY, DISPLAY_STACK_TIMEOUT_MS, type DesktopGeometry, DisplayStackError, DisplayStackUnsupportedError, type EnsureDisplayStackOptions, type EnsureDisplayStackResult, type EnsureTerminalServerOptions, type EnsureTerminalServerResult, type EstablishedSandboxSession, type ExposeStreamPortInput, type ExposeStreamPortResult, type ExposedPortEndpoint, type FinalizeRecordingResult, type MintStreamTokenInput, MockAgentResponder, type MockAgentResponderOptions, type MockExecHandler, NatsControlRpc, type NatsRequestConnection, type NegotiationContext, type NumstatEntry, PROVIDER_REGISTRY, type ProviderConstructionContext, type ProviderRegistration, type RecordingCodec, type RecordingContentType, RecordingError, type RecordingProcess, RecordingUnavailableError, type ResolvedActiveBackend, type RoutableBackendSession, type RoutableSandbox, RoutingSandboxSession, type RoutingSandboxSessionDeps, type RoutingTransitionEvent, RoutingUnsupportedError, SELFHOSTED_DEFAULT_TIMEOUT_MS, SELFHOSTED_RECONNECT_WINDOW_MS, SELFHOSTED_RELAY_STREAM_PATH, STREAM_PORT, STREAM_TOKEN_DEFAULT_TTL_SECONDS, SandboxChannelAService, type SandboxChannelAServiceOptions, SandboxConfigError, SandboxProviderUnavailableError, type SelfhostedApplyDiff, SelfhostedControlError, type SelfhostedEditor, type SelfhostedEnrollment, type SelfhostedExecArgs, type SelfhostedExecResult, type SelfhostedImageOutput, type SelfhostedLivenessState, type SelfhostedNegotiationInput, type SelfhostedRelayConfig, SelfhostedSandboxClient, SelfhostedSession, type SelfhostedSessionBuild, type SelfhostedSessionDeps, type SelfhostedSessionState, type SelfhostedUnavailableReason, type StartRecordingInput, StreamPortUnavailableError, TERMINAL_SERVER_TIMEOUT_MS, TerminalServerError, TerminalServerUnsupportedError, agentErrorToControlError, assertDescriptorRegistryInvariants, assertProviderRegistryInvariants, assertSafeRelPath, backendSupportsOs, buildDisplayStackScript, buildSelfhostedBackendSession, buildStreamUrl, buildTerminalServerScript, contentTypeForCodec, createSandboxClient, createSandboxClientForBackend, decodeModalSnapshotId, deletePriorPersistedSnapshot, deleteRecordingArtifacts, deserializeSandboxSessionStateEnvelope, desktopCapableBackend, ensureDisplayStack, ensureTerminalServer, establishSandboxSessionFromEnvelope, exposeStreamPort, extForCodec, isExecSessionLostBanner, isProviderSandboxNotFoundError, isSelfhostedProviderNotFoundError, isWorkspaceEscapeError, makeActiveBackendResolver, mintStreamToken, negotiateCapabilities, negotiateSelfhostedCapabilities, offlineAgentError, offlineControlResponse, parseExecBannerSessionId, parseNumstatZ, parsePorcelainV2, parseUnifiedPatch, readRecordingBytes, readWorkspaceArchiveFromEnvelopeSessionState, recordingStorageKey, restoredSandboxSessionStateFromEntry, sandboxStateEntryFromRunState, selectBackend, selfhostedLiveness, serializeEstablishedSandboxEnvelope, setSelfhostedApplyDiff, startRecording, stopRecording, stripExecBanner, subjectFor, tearDownDisplayStack, tearDownTerminalServer, timeoutAgentError, timeoutControlResponse, verifyStreamToken };
1786
+ export { type ActiveBackendResolverDeps, ActiveBackendUnresolvableError, type ActivePointer, ChannelAConflictError, type ChannelAEmitter, type ChannelAExecArgs, type ChannelAExecResult, ChannelANotFoundError, type ChannelASession, ChannelAUnsupportedError, ChannelAValidationError, type ControlRpc, DEFAULT_DESKTOP_GEOMETRY, DISPLAY_STACK_TIMEOUT_MS, type DesktopGeometry, DisplayStackError, DisplayStackUnsupportedError, type EnsureDisplayStackOptions, type EnsureDisplayStackResult, type EnsureTerminalServerOptions, type EnsureTerminalServerResult, type EstablishedSandboxSession, type ExposeStreamPortInput, type ExposeStreamPortResult, type ExposedPortEndpoint, type FinalizeRecordingResult, type LiveModalSandboxLeaseAttribution, type MintStreamTokenInput, MockAgentResponder, type MockAgentResponderOptions, type MockExecHandler, type ModalOrphanSweepResult, type ModalSandboxAttribution, NatsControlRpc, type NatsRequestConnection, type NegotiationContext, type NumstatEntry, PROVIDER_REGISTRY, type ProviderConstructionContext, type ProviderRegistration, type RecordingCodec, type RecordingContentType, RecordingError, type RecordingProcess, RecordingUnavailableError, type ResolvedActiveBackend, type RoutableBackendSession, type RoutableSandbox, RoutingSandboxSession, type RoutingSandboxSessionDeps, type RoutingTransitionEvent, RoutingUnsupportedError, SELFHOSTED_DEFAULT_TIMEOUT_MS, SELFHOSTED_RECONNECT_WINDOW_MS, SELFHOSTED_RELAY_STREAM_PATH, STREAM_PORT, STREAM_TOKEN_DEFAULT_TTL_SECONDS, SandboxChannelAService, type SandboxChannelAServiceOptions, SandboxConfigError, type SandboxCreatedCallback, SandboxProviderUnavailableError, type SelfhostedApplyDiff, SelfhostedControlError, type SelfhostedEditor, type SelfhostedEnrollment, type SelfhostedExecArgs, type SelfhostedExecResult, type SelfhostedImageOutput, type SelfhostedLivenessState, type SelfhostedNegotiationInput, type SelfhostedRelayConfig, SelfhostedSandboxClient, SelfhostedSession, type SelfhostedSessionBuild, type SelfhostedSessionDeps, type SelfhostedSessionState, type SelfhostedUnavailableReason, type StartRecordingInput, StreamPortUnavailableError, TERMINAL_SERVER_TIMEOUT_MS, TerminalServerError, TerminalServerUnsupportedError, agentErrorToControlError, assertDescriptorRegistryInvariants, assertProviderRegistryInvariants, assertSafeRelPath, backendSupportsOs, buildDisplayStackScript, buildSelfhostedBackendSession, buildStreamUrl, buildTerminalServerScript, contentTypeForCodec, createSandboxClient, createSandboxClientForBackend, decodeModalSnapshotId, deletePriorPersistedSnapshot, deleteRecordingArtifacts, deserializeSandboxSessionStateEnvelope, desktopCapableBackend, ensureDisplayStack, ensureTerminalServer, establishSandboxSessionFromEnvelope, exposeStreamPort, extForCodec, isExecSessionLostBanner, isProviderSandboxNotFoundError, isSelfhostedProviderNotFoundError, isWorkspaceEscapeError, makeActiveBackendResolver, mintStreamToken, modalSandboxAttributionEnvironment, modalSandboxAttributionTags, negotiateCapabilities, negotiateSelfhostedCapabilities, offlineAgentError, offlineControlResponse, parseExecBannerSessionId, parseNumstatZ, parsePorcelainV2, parseUnifiedPatch, readRecordingBytes, readWorkspaceArchiveFromEnvelopeSessionState, recordingStorageKey, restoredSandboxSessionStateFromEntry, sandboxStateEntryFromRunState, selectBackend, selfhostedLiveness, serializeEstablishedSandboxEnvelope, setSelfhostedApplyDiff, startRecording, stopRecording, stripExecBanner, subjectFor, sweepModalOrphanSandboxes, tagModalSandbox, tearDownDisplayStack, tearDownTerminalServer, terminateModalSandboxById, timeoutAgentError, timeoutControlResponse, verifyStreamToken };
@@ -63,6 +63,8 @@ import {
63
63
  isWorkspaceEscapeError,
64
64
  makeActiveBackendResolver,
65
65
  mintStreamToken,
66
+ modalSandboxAttributionEnvironment,
67
+ modalSandboxAttributionTags,
66
68
  negotiateCapabilities,
67
69
  negotiateSelfhostedCapabilities,
68
70
  offlineAgentError,
@@ -85,12 +87,15 @@ import {
85
87
  stopRecording,
86
88
  stripExecBanner,
87
89
  subjectFor,
90
+ sweepModalOrphanSandboxes,
91
+ tagModalSandbox,
88
92
  tearDownDisplayStack,
89
93
  tearDownTerminalServer,
94
+ terminateModalSandboxById,
90
95
  timeoutAgentError,
91
96
  timeoutControlResponse,
92
97
  verifyStreamToken
93
- } from "../chunk-2PO56VAL.js";
98
+ } from "../chunk-D5KU3QUC.js";
94
99
  export {
95
100
  ActiveBackendUnresolvableError,
96
101
  CAPABILITY_DESCRIPTORS,
@@ -156,6 +161,8 @@ export {
156
161
  isWorkspaceEscapeError,
157
162
  makeActiveBackendResolver,
158
163
  mintStreamToken,
164
+ modalSandboxAttributionEnvironment,
165
+ modalSandboxAttributionTags,
159
166
  negotiateCapabilities,
160
167
  negotiateSelfhostedCapabilities,
161
168
  offlineAgentError,
@@ -178,8 +185,11 @@ export {
178
185
  stopRecording,
179
186
  stripExecBanner,
180
187
  subjectFor,
188
+ sweepModalOrphanSandboxes,
189
+ tagModalSandbox,
181
190
  tearDownDisplayStack,
182
191
  tearDownTerminalServer,
192
+ terminateModalSandboxById,
183
193
  timeoutAgentError,
184
194
  timeoutControlResponse,
185
195
  verifyStreamToken
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeni/runtime",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -29,8 +29,8 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@opengeni/agent-proto": "^0.2.1",
32
- "@opengeni/config": "^0.2.2",
33
- "@opengeni/contracts": "^0.4.0",
32
+ "@opengeni/config": "^0.2.4",
33
+ "@opengeni/contracts": "^0.6.0",
34
34
  "@openai/agents": "^0.11.6",
35
35
  "@openai/agents-extensions": "^0.11.6",
36
36
  "modal": "^0.7.4",