@opengeni/runtime 0.6.0 → 0.7.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.
Files changed (44) hide show
  1. package/dist/{chunk-BHA2SU3H.js → chunk-RYDCVTMW.js} +1959 -208
  2. package/dist/chunk-RYDCVTMW.js.map +1 -0
  3. package/dist/{index-otZkoLYq.d.ts → index-DIiiwQY2.d.ts} +693 -55
  4. package/dist/index.d.ts +293 -121
  5. package/dist/index.js +1819 -786
  6. package/dist/index.js.map +1 -1
  7. package/dist/sandbox/index.d.ts +1 -1
  8. package/dist/sandbox/index.js +79 -3
  9. package/package.json +21 -20
  10. package/src/codex-tool-search.ts +185 -31
  11. package/src/context-compaction.ts +78 -243
  12. package/src/history-sanitizer.ts +172 -20
  13. package/src/index.ts +2573 -897
  14. package/src/metrics.ts +28 -2
  15. package/src/sandbox/capabilities.ts +12 -3
  16. package/src/sandbox/channel-a.ts +420 -72
  17. package/src/sandbox/display-stack.ts +18 -4
  18. package/src/sandbox/errors.ts +13 -0
  19. package/src/sandbox/index.ts +398 -112
  20. package/src/sandbox/op-correlation.ts +70 -0
  21. package/src/sandbox/providers/index.ts +9 -3
  22. package/src/sandbox/providers/modal.ts +99 -24
  23. package/src/sandbox/providers/selfhosted.ts +1 -4
  24. package/src/sandbox/recording.ts +146 -90
  25. package/src/sandbox/routing/backend-resolver.ts +144 -10
  26. package/src/sandbox/routing/routing-session.ts +129 -25
  27. package/src/sandbox/select.ts +60 -8
  28. package/src/sandbox/selfhosted/capabilities.ts +59 -25
  29. package/src/sandbox/selfhosted/control-rpc.ts +160 -28
  30. package/src/sandbox/selfhosted/fault-rendering.ts +226 -0
  31. package/src/sandbox/selfhosted/op-observer.ts +54 -0
  32. package/src/sandbox/selfhosted/op-stream.ts +801 -0
  33. package/src/sandbox/selfhosted/op-testing.ts +468 -0
  34. package/src/sandbox/selfhosted/op-transport.ts +151 -0
  35. package/src/sandbox/selfhosted/retry-policy.ts +177 -0
  36. package/src/sandbox/selfhosted/session.ts +498 -55
  37. package/src/sandbox/selfhosted/testing.ts +60 -19
  38. package/src/sandbox/stream-port.ts +17 -5
  39. package/src/sandbox/stream-token.ts +8 -2
  40. package/src/sandbox/terminal-server.ts +18 -4
  41. package/src/sandbox-computer.ts +332 -70
  42. package/src/usage-telemetry.ts +73 -0
  43. package/dist/chunk-BHA2SU3H.js.map +0 -1
  44. package/src/image-history.ts +0 -149
package/dist/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  import * as _openai_agents from '@openai/agents';
2
2
  import { Tool, Computer, AgentInputItem, Model, MCPServer, ModelProvider, Agent, RunState, CallModelInputFilter, RunStreamEvent } from '@openai/agents';
3
3
  export { MaxTurnsExceededError, OpenAIChatCompletionsModel, OpenAIResponsesModel } from '@openai/agents';
4
- import { ContextCompactionMode, Settings, ResolvedModelProvider, ConfiguredModel, ModelProviderApi } from '@opengeni/config';
4
+ import { Settings, ResolvedModelProvider, ConfiguredModel, ModelProviderApi } from '@opengeni/config';
5
5
  export { collectSandboxEnvironment, parseExposedPorts } from '@opengeni/config';
6
- import { ReasoningEffort, SessionEventType, ResourceRef, ToolRef, Permission, McpServerConnectionRef, ToolAuthNeededPayload } from '@opengeni/contracts';
6
+ import { ReasoningEffort, GitCredentialProvider, SessionEventType, ResourceRef, ToolRef, Permission, McpServerConnectionRef, ToolAuthNeededPayload } from '@opengeni/contracts';
7
7
  export { CAPABILITY_DESCRIPTORS, CapabilityDescriptor, DESKTOP_STREAM_PORT, StreamTokenPayload, StreamTokenPayload as StreamTokenPayloadType, TERMINAL_STREAM_PORT } from '@opengeni/contracts';
8
- import { Capability, SandboxSessionLike, SandboxSessionState, Manifest, Capabilities, LocalDirLazySkillSource, SandboxClient } from '@openai/agents/sandbox';
8
+ import { SandboxSessionLike, Capability, SandboxSessionState, Manifest, Capabilities, LocalDirLazySkillSource, SandboxClient } from '@openai/agents/sandbox';
9
9
  import OpenAI from 'openai';
10
- import { R as RuntimeMetricsHooks } from './index-otZkoLYq.js';
11
- export { A as ActiveBackendResolverDeps, a as ActiveBackendUnresolvableError, b as ActivePointer, C as ChannelAConflictError, c as ChannelAEmitter, d as ChannelAExecArgs, e as ChannelAExecResult, f as ChannelANotFoundError, g as ChannelASession, h as ChannelAUnsupportedError, i as ChannelAValidationError, j as ControlRpc, D as DEFAULT_DESKTOP_GEOMETRY, k as DISPLAY_STACK_TIMEOUT_MS, l as DesktopGeometry, m as DisplayStackError, n as DisplayStackUnsupportedError, E as EnsureDisplayStackOptions, o as EnsureDisplayStackResult, p as EnsureTerminalServerOptions, q as EnsureTerminalServerResult, r as EstablishedSandboxSession, s as ExposeStreamPortInput, t as ExposeStreamPortResult, u as ExposedPortEndpoint, F as FinalizeRecordingResult, L as LiveModalSandboxLeaseAttribution, M as MintStreamTokenInput, v as MockAgentResponder, w as MockAgentResponderOptions, x as MockExecHandler, y as ModalModuleLoader, z as ModalOrphanSweepResult, B as ModalSandboxAttribution, N as NatsControlRpc, G as NatsRequestConnection, H as NegotiationContext, I as NumstatEntry, P as PROVIDER_REGISTRY, J as ProviderConstructionContext, K as ProviderRegistration, O as RecordingCodec, Q as RecordingContentType, S as RecordingError, T as RecordingProcess, U as RecordingUnavailableError, V as ResolvedActiveBackend, W as RoutableBackendSession, X as RoutableSandbox, Y as RoutingSandboxSession, Z as RoutingSandboxSessionDeps, _ as RoutingTransitionEvent, $ as RoutingUnsupportedError, a0 as SELFHOSTED_DEFAULT_TIMEOUT_MS, a1 as SELFHOSTED_RECONNECT_WINDOW_MS, a2 as SELFHOSTED_RELAY_STREAM_PATH, a3 as STREAM_PORT, a4 as STREAM_TOKEN_DEFAULT_TTL_SECONDS, a5 as SandboxChannelAService, a6 as SandboxChannelAServiceOptions, a7 as SandboxConfigError, a8 as SandboxCreatedCallback, a9 as SandboxProviderUnavailableError, aa as SelfhostedApplyDiff, ab as SelfhostedControlError, ac as SelfhostedEditor, ad as SelfhostedEnrollment, ae as SelfhostedExecArgs, af as SelfhostedExecResult, ag as SelfhostedImageOutput, ah as SelfhostedLivenessState, ai as SelfhostedNegotiationInput, aj as SelfhostedRelayConfig, ak as SelfhostedSandboxClient, al as SelfhostedSession, am as SelfhostedSessionBuild, an as SelfhostedSessionDeps, ao as SelfhostedSessionState, ap as SelfhostedUnavailableReason, aq as StartRecordingInput, ar as StreamPortUnavailableError, as as TERMINAL_SERVER_TIMEOUT_MS, at as TerminalServerError, au as TerminalServerUnsupportedError, av as agentErrorToControlError, aw as assertDescriptorRegistryInvariants, ax as assertProviderRegistryInvariants, ay as assertSafeRelPath, az as backendSupportsOs, aA as buildDisplayStackScript, aB as buildSelfhostedBackendSession, aC as buildStreamUrl, aD as buildTerminalServerScript, aE as contentTypeForCodec, aF as createSandboxClient, aG as createSandboxClientForBackend, aH as decodeModalSnapshotId, aI as deletePriorPersistedSnapshot, aJ as deleteRecordingArtifacts, aK as deserializeSandboxSessionStateEnvelope, aL as desktopCapableBackend, aM as ensureDisplayStack, aN as ensureModalRegistryImage, aO as ensureTerminalServer, aP as establishSandboxSessionFromEnvelope, aQ as exposeStreamPort, aR as extForCodec, aS as isExecSessionLostBanner, aT as isProviderSandboxNotFoundError, aU as isSelfhostedProviderNotFoundError, aV as isWorkspaceEscapeError, aW as makeActiveBackendResolver, aX as mintStreamToken, aY as modalSandboxAttributionEnvironment, aZ as modalSandboxAttributionTags, a_ as negotiateCapabilities, a$ as negotiateSelfhostedCapabilities, b0 as offlineAgentError, b1 as offlineControlResponse, b2 as parseExecBannerSessionId, b3 as parseNumstatZ, b4 as parsePorcelainV2, b5 as parseUnifiedPatch, b6 as readRecordingBytes, b7 as readWorkspaceArchiveFromEnvelopeSessionState, b8 as recordingStorageKey, b9 as restoredSandboxSessionStateFromEntry, ba as sandboxStateEntryFromRunState, bb as selectBackend, bc as selfhostedLiveness, bd as serializeEstablishedSandboxEnvelope, be as setSelfhostedApplyDiff, bf as startRecording, bg as stopRecording, bh as stripExecBanner, bi as subjectFor, bj as sweepModalOrphanSandboxes, bk as tagModalSandbox, bl as tearDownDisplayStack, bm as tearDownTerminalServer, bn as terminateModalSandboxById, bo as timeoutAgentError, bp as timeoutControlResponse, bq as verifyStreamToken } from './index-otZkoLYq.js';
10
+ import { R as RuntimeMetricsHooks } from './index-DIiiwQY2.js';
11
+ export { A as ActiveBackendResolverDeps, a as ActiveBackendUnresolvableError, b as ActivePointer, B as BackendUnresolvableCode, C as ChannelAConflictError, c as ChannelAEmitter, d as ChannelAExecArgs, e as ChannelAExecResult, f as ChannelANotFoundError, g as ChannelASession, h as ChannelAUnsupportedError, i as ChannelAValidationError, j as ControlRpc, D as DEFAULT_DESKTOP_GEOMETRY, k as DISPLAY_STACK_TIMEOUT_MS, l as DesktopGeometry, m as DisplayStackError, n as DisplayStackUnsupportedError, E as EnsureDisplayStackOptions, o as EnsureDisplayStackResult, p as EnsureTerminalServerOptions, q as EnsureTerminalServerResult, r as EstablishedSandboxSession, s as ExposeStreamPortInput, t as ExposeStreamPortResult, u as ExposedPortEndpoint, F as FAULT_FIELD_WHAT_HAPPENED, v as FAULT_FIELD_WHAT_PRESERVED, w as FAULT_FIELD_WHAT_TO_TRY, x as FAULT_FIELD_WHICH_LAYER, L as LiveModalSandboxLeaseAttribution, M as MintStreamTokenInput, y as MockAgentResponder, z as MockAgentResponderOptions, G as MockExecHandler, H as ModalModuleLoader, I as ModalOrphanSweepResult, J as ModalSandboxAttribution, N as NEVER_SENT_DETAIL_KEY, K as NatsControlRpc, O as NatsOpStreamConnection, P as NatsOpStreamTransport, Q as NatsRequestConnection, S as NegotiationContext, T as NumstatEntry, U as OP_STREAM_ACK_INTERVAL_MS, V as OP_STREAM_DEFAULT_WINDOW_BYTES, W as OP_STREAM_RECONNECT_HOLD_MS, X as OP_STREAM_SILENCE_TIMEOUT_MS, Y as OpStreamExecOutcome, Z as OpStreamJournal, _ as OpStreamSubscription, $ as OpStreamTransport, a0 as OpStreamUnavailableError, a1 as PROVIDER_REGISTRY, a2 as ProviderConstructionContext, a3 as ProviderRegistration, a4 as REPOSITORY_DISCOVERY_LIMIT, a5 as RecordingArtifactMetadata, a6 as RecordingCodec, a7 as RecordingContentType, a8 as RecordingError, a9 as RecordingProcess, aa as RecordingUnavailableError, ab as RepositoryDiscoveryDegradedReason, ac as RepositoryDiscoveryResult, ad as ResolvedActiveBackend, ae as RoutableBackendSession, af as RoutableSandbox, ag as RoutingSandboxSession, ah as RoutingSandboxSessionDeps, ai as RoutingTransitionEvent, aj as RoutingUnsupportedError, ak as SELFHOSTED_DEFAULT_TIMEOUT_MS, al as SELFHOSTED_DRAINING_MAX_RETRIES, am as SELFHOSTED_EXEC_DRAINING_MAX_RETRIES, an as SELFHOSTED_IDEMPOTENT_READONLY_OPS, ao as SELFHOSTED_INFRASTRUCTURE_FAULT_CLASSES, ap as SELFHOSTED_NEVER_SENT_MAX_RETRIES, aq as SELFHOSTED_RECONNECT_WINDOW_MS, ar as SELFHOSTED_RELAY_STREAM_PATH, as as SELFHOSTED_RETRY_BACKOFF_BASE_MS, at as SELFHOSTED_RETRY_BACKOFF_CAP_MS, au as SELFHOSTED_RETRY_BACKOFF_FACTOR, av as SELFHOSTED_TIMEOUT_MAX_RETRIES, aw as STREAM_PORT, ax as STREAM_TOKEN_DEFAULT_TTL_SECONDS, ay as SandboxChannelAService, az as SandboxChannelAServiceOptions, aA as SandboxConfigError, aB as SandboxCreatedCallback, aC as SandboxProviderUnavailableError, aD as SandboxResumeStateUnavailableError, aE as SelfhostedApplyDiff, aF as SelfhostedControlError, aG as SelfhostedEditor, aH as SelfhostedEnrollment, aI as SelfhostedExecArgs, aJ as SelfhostedExecResult, aK as SelfhostedImageOutput, aL as SelfhostedLivenessState, aM as SelfhostedNegotiationInput, aN as SelfhostedOpObservation, aO as SelfhostedOpObserver, aP as SelfhostedOpStreamDeps, aQ as SelfhostedRelayConfig, aR as SelfhostedRetryClock, aS as SelfhostedRetryDecision, aT as SelfhostedSandboxClient, aU as SelfhostedSession, aV as SelfhostedSessionBuild, aW as SelfhostedSessionDeps, aX as SelfhostedSessionState, aY as SelfhostedUnavailableReason, aZ as StartRecordingInput, a_ as StreamPortUnavailableError, a$ as SwapTargetEstablishability, b0 as TERMINAL_SERVER_TIMEOUT_MS, b1 as TerminalServerError, b2 as TerminalServerUnsupportedError, b3 as agentErrorToControlError, b4 as assertDescriptorRegistryInvariants, b5 as assertProviderRegistryInvariants, b6 as assertSafeRelPath, b7 as backendSupportsOs, b8 as buildDisplayStackScript, b9 as buildSelfhostedBackendSession, ba as buildStreamUrl, bb as buildTerminalServerScript, bc as contentTypeForCodec, bd as createSandboxClient, be as createSandboxClientForBackend, bf as decideSelfhostedRetry, bg as decodeModalSnapshotId, bh as defaultSelfhostedRetryClock, bi as deletePriorPersistedSnapshot, bj as deleteRecordingArtifacts, bk as deserializeSandboxSessionStateEnvelope, bl as desktopCapableBackend, bm as drainingExhaustedError, bn as drainingMessage, bo as ensureDisplayStack, bp as ensureModalRegistryImage, bq as ensureTerminalServer, br as establishSandboxSessionFromEnvelope, bs as execDeadlineHint, bt as exposeStreamPort, bu as extForCodec, bv as inspectRecordingArtifact, bw as isExecSessionLostBanner, bx as isProviderSandboxNotFoundError, by as isSelfhostedProviderNotFoundError, bz as isWorkspaceEscapeError, bA as makeActiveBackendResolver, bB as mintStreamToken, bC as modalSandboxAttributionEnvironment, bD as modalSandboxAttributionTags, bE as negotiateCapabilities, bF as negotiateSelfhostedCapabilities, bG as nextDurableOpId, bH as offlineAgentError, bI as offlineControlResponse, bJ as opAckSubject, bK as opFrameSubject, bL as parseExecBannerSessionId, bM as parseNumstatZ, bN as parsePorcelainV2, bO as parseUnifiedPatch, bP as payloadTooLargeMessage, bQ as readWorkspaceArchiveFromEnvelopeSessionState, bR as recordingStorageKey, bS as renderSelfhostedFault, bT as restoredSandboxSessionStateFromEntry, bU as runWithToolCallCorrelation, bV as sandboxStateEntryFromRunState, bW as sanitizeOpIdToken, bX as selectBackend, bY as selfhostedFaultClass, bZ as selfhostedLiveness, b_ as selfhostedRetryBackoffMs, b$ as serializeEstablishedSandboxEnvelope, c0 as setSelfhostedApplyDiff, c1 as startRecording, c2 as stopRecording, c3 as stripExecBanner, c4 as subjectFor, c5 as swapTargetEstablishability, c6 as sweepModalOrphanSandboxes, c7 as tagModalSandbox, c8 as tearDownDisplayStack, c9 as tearDownTerminalServer, ca as terminateModalSandboxById, cb as timeoutAgentError, cc as timeoutControlResponse, cd as uploadRecordingArtifact, ce as verifyStreamToken } from './index-DIiiwQY2.js';
12
12
  import 'modal';
13
13
  import '@opengeni/agent-proto';
14
14
 
@@ -22,6 +22,14 @@ type SandboxComputerOptions = {
22
22
  screenshotTmpDir?: string;
23
23
  screenshotWarmupBudgetMs?: number;
24
24
  screenshotRetryDelayMs?: number;
25
+ /**
26
+ * One turn-scoped preparation hook, invoked by the first real computer action.
27
+ * The agent may advertise computer-use on every turn, but merely advertising the
28
+ * tool must not boot Xvfb/XFCE or start a recording. The runtime capability owns
29
+ * this hook and uses it to bring up :0 (and optionally notify the worker) only
30
+ * after the model actually chooses a computer tool.
31
+ */
32
+ prepare?: (session: SandboxSessionLike) => Promise<void>;
25
33
  };
26
34
  /** No exec/execCommand on the session, or the display is not up. */
27
35
  declare class ComputerUnavailableError extends Error {
@@ -59,9 +67,13 @@ declare class SandboxComputer implements Computer {
59
67
  private readonly tmp;
60
68
  private readonly screenshotWarmupBudgetMs;
61
69
  private readonly screenshotRetryDelayMs;
70
+ private readonly prepare;
71
+ private prepared;
72
+ private preparation;
62
73
  constructor(session: SandboxSessionLike, opts?: SandboxComputerOptions);
63
74
  /** Rebind to a freshly resumed-by-id session after a box rollover / re-establish. */
64
75
  rebind(session: SandboxSessionLike): void;
76
+ private prepareOnce;
65
77
  private x;
66
78
  private guardWrite;
67
79
  private shq;
@@ -102,6 +114,8 @@ type ComputerUseArgs = {
102
114
  needsApproval?: boolean | ((ctx: unknown, action: unknown) => boolean | Promise<boolean>);
103
115
  imageFunctionResults?: boolean;
104
116
  toolMode?: ComputerToolMode;
117
+ /** Called after the display is ready on the first actual computer action. */
118
+ onReady?: (session: SandboxSessionLike) => Promise<void>;
105
119
  };
106
120
  declare function computerUse(args?: ComputerUseArgs): ComputerUseCapability;
107
121
  /**
@@ -162,6 +176,19 @@ declare class ComputerUseCapability extends Capability {
162
176
  */
163
177
  /** A history item is any JSON object; we only inspect a few discriminator fields. */
164
178
  type HistoryItem = Record<string, unknown>;
179
+ /**
180
+ * Remove superseded `view_image` call/result pairs for the SAME local path,
181
+ * retaining the newest fully-paired observation. A `view_image` result can be
182
+ * hundreds of kilobytes of base64. When a model re-opens the same attachment,
183
+ * replaying every older copy on each subsequent model call grows input
184
+ * quadratically and can trap a turn in context-compaction/requeue recovery.
185
+ *
186
+ * This is state-based rather than count-based: every distinct path is kept,
187
+ * and an older observation is removed only after a newer successful pair for
188
+ * that exact path exists. The reasoning items immediately attached to a
189
+ * removed call are removed with it, preserving Responses API item validity.
190
+ */
191
+ declare function elideSupersededViewImagePairs<T extends HistoryItem>(items: readonly T[]): T[];
165
192
  /**
166
193
  * Sanitize a replayed history item list into a sequence the Responses API
167
194
  * accepts. Pure: returns a new array of the same item references in order,
@@ -234,9 +261,8 @@ declare function stripReasoningEncryptedContent<T extends HistoryItem>(item: T):
234
261
  * a parse failure or a no-op returns the SAME string reference (so an unchanged
235
262
  * or non-codex run-state replays byte-for-byte).
236
263
  *
237
- * WHY (HOLE C — the run-state REPLAY paths). The approval-decision resume and the
238
- * items-mode run-state fallback replay the serialized RunState blob verbatim. That
239
- * blob round-trips `reasoning.encrypted_content` minted by the ChatGPT/Codex
264
+ * WHY (HOLE C — approval replay). An approval decision resumes the serialized
265
+ * RunState blob. That blob round-trips `reasoning.encrypted_content` minted by the ChatGPT/Codex
240
266
  * backend (bound to the freezing account/org — a foreign account 400s it) AND the
241
267
  * foreign `rs_…` reasoning ids the Responses backend validates (rejected once the
242
268
  * blob is gone). Unlike `session_history_items`, the blob carries NO per-item
@@ -287,11 +313,11 @@ declare function stripReasoningIdentityFromSerializedRunState(serialized: string
287
313
  declare function neutralizeToolSearchItemsInSerializedRunState(serialized: string): string;
288
314
 
289
315
  /**
290
- * Client-side conversation context compaction (the Azure/client path).
316
+ * Portable conversation context compaction, following Codex CLI's local path.
291
317
  *
292
- * This mirrors Codex CLI's compaction model: the checkpoint model sees the
293
- * current active history plus one fixed checkpoint prompt, then the active
294
- * history is rebuilt as all real user messages plus one summary message.
318
+ * The checkpoint model sees the current active history plus one fixed
319
+ * checkpoint prompt, then the active history is rebuilt from the newest real
320
+ * user messages within one cumulative 20k-token budget plus one summary.
295
321
  * Assistant messages, tool calls/results, reasoning, and images are removed
296
322
  * from the active model-facing history; the database audit rows remain.
297
323
  */
@@ -303,7 +329,7 @@ type CompactionItem = Record<string, unknown>;
303
329
  declare const COMPACTION_SUMMARY_MARKER = "opengeni_context_summary";
304
330
  declare const SUMMARY_BUFFER_TOKENS = 20000;
305
331
  declare const COMPACT_USER_MESSAGE_MAX_TOKENS = 20000;
306
- declare const DEFAULT_COMPACTION_THRESHOLD_RATIO = 0.6;
332
+ declare const DEFAULT_COMPACTION_THRESHOLD_RATIO = 0.9;
307
333
  declare const MIN_COMPACTION_THRESHOLD_RATIO = 0.3;
308
334
  declare const MAX_COMPACTION_THRESHOLD_RATIO = 0.9;
309
335
  declare const COMPACTION_PROMPT: string;
@@ -313,63 +339,49 @@ declare const USER_MESSAGE_TRUNCATION_MARKER = "\n[... middle truncated for cont
313
339
  declare function isUserMessage(item: unknown): boolean;
314
340
  /** True for our synthetic compaction summary item. */
315
341
  declare function isCompactionSummary(item: unknown): boolean;
342
+ /** Platform-authored system context exists for one inference and is never persisted. */
343
+ declare function isEphemeralInternalContext(item: unknown): boolean;
316
344
  /**
317
345
  * Rough token estimate for an item: char/4 over its serialized text. Used for
318
- * the pre-first-call fallback, per-user-message cap, and read-path airbag.
346
+ * the pre-first-call signal and the retained user-message budget.
319
347
  */
320
348
  declare function estimateItemTokens(item: CompactionItem): number;
321
349
  declare function estimateTokens(items: readonly CompactionItem[]): number;
322
350
  declare function clampCompactionThresholdRatio(value: number | undefined | null): number;
323
- declare function clientCompactionThresholdTokens(input: {
351
+ declare function compactionThresholdTokens(input: {
324
352
  contextWindowTokens: number;
325
353
  contextReservedOutputTokens: number;
326
- contextCompactionThresholdRatio?: number | null;
354
+ contextAutoCompactThresholdTokens?: number | null | undefined;
355
+ contextCompactionThresholdRatio?: number | null | undefined;
327
356
  }): number;
328
- type ClientCompactionDecision = {
357
+ type CompactionDecision = {
329
358
  shouldCompact: boolean;
330
359
  reason: "force" | "above_threshold" | "below_threshold" | "no_history";
331
360
  signalTokens: number;
332
361
  thresholdTokens: number;
333
362
  };
334
- declare function decideClientCompaction(input: {
363
+ declare function decideCompaction(input: {
335
364
  items: readonly CompactionItem[];
336
365
  lastInputTokens?: number | null;
337
366
  contextWindowTokens: number;
338
367
  contextReservedOutputTokens: number;
339
- contextCompactionThresholdRatio?: number | null;
368
+ contextAutoCompactThresholdTokens?: number | null | undefined;
369
+ contextCompactionThresholdRatio?: number | null | undefined;
340
370
  force?: boolean;
341
- }): ClientCompactionDecision;
371
+ }): CompactionDecision;
342
372
  declare class CompactionNeededError extends Error {
343
373
  readonly signalTokens: number;
344
374
  readonly thresholdTokens: number;
345
375
  readonly signalSource: "provider" | "estimate";
376
+ readonly trigger: "threshold" | "operator";
346
377
  constructor(input: {
347
378
  signalTokens: number;
348
379
  thresholdTokens: number;
349
380
  signalSource: "provider" | "estimate";
381
+ trigger?: "threshold" | "operator";
350
382
  });
351
383
  }
352
384
  declare function findCompactionNeededError(error: unknown, seen?: WeakSet<object>): CompactionNeededError | null;
353
- /**
354
- * Walk backwards from the end of `items` keeping whole turns until the kept
355
- * tail would exceed `keepRecentTokens`, and return the index of the first kept
356
- * item. Retained for the read-path budget guard only; the client compaction
357
- * rebuild no longer uses a keep-recent tail.
358
- */
359
- declare function findKeepBoundary(items: readonly CompactionItem[], keepRecentTokens: number): number;
360
- /**
361
- * READ-PATH BUDGET GUARD (last-resort backstop).
362
- *
363
- * Drops the oldest history at a clean user-message boundary until an assembled
364
- * input fits the request budget. This remains a request-local safety rail; it
365
- * is not the compaction strategy.
366
- */
367
- declare function enforceInputBudget<T extends CompactionItem>(items: readonly T[], maxTokens: number, trailingTokens?: number): {
368
- items: T[];
369
- trimmed: boolean;
370
- droppedCount: number;
371
- estimatedTokens: number;
372
- };
373
385
  /**
374
386
  * The exact checkpoint input shape: current active history followed by Codex's
375
387
  * checkpoint prompt as a synthesized user message.
@@ -377,42 +389,30 @@ declare function enforceInputBudget<T extends CompactionItem>(items: readonly T[
377
389
  declare function buildCompactionPromptInput(items: readonly CompactionItem[]): CompactionItem[];
378
390
  /**
379
391
  * Build the active history after compaction:
380
- * all real user messages (prior summaries excluded, images removed, each
381
- * message capped) plus one marked summary item.
392
+ * the newest real user messages that fit one cumulative 20k-token budget
393
+ * (prior summaries excluded, images removed) plus one marked summary item.
382
394
  */
383
395
  declare function buildCompactionReplacementHistory(items: readonly CompactionItem[], summaryBody: string): CompactionItem[];
384
- type DeterministicFallbackCompactionInput = {
385
- items: readonly CompactionItem[];
386
- cause?: string;
387
- targetTokens?: number;
388
- };
389
- declare function buildDeterministicFallbackCompactionHistory(input: DeterministicFallbackCompactionInput): CompactionItem[];
390
396
  /**
391
397
  * Build the synthetic summary item (a plain user message) appended to the
392
398
  * rebuilt active history.
393
399
  */
394
400
  declare function buildSummaryItem(summaryBody: string): CompactionItem;
395
- type RenderCompactionTranscriptOptions = {
396
- /**
397
- * Hard cap for a rendered transcript. When set, oldest rendered items are
398
- * dropped first while preserving the final checkpoint prompt; if the retained
399
- * item itself is too large, it is middle-truncated instead of looping.
400
- */
401
- maxEstimatedTokens?: number;
402
- };
403
- declare function renderCompactionPromptInputForChat(input: readonly CompactionItem[], options?: RenderCompactionTranscriptOptions): string;
401
+ declare function renderCompactionPromptInputForChat(input: readonly CompactionItem[]): string;
404
402
 
405
- declare const SCREENSHOT_OMITTED_PLACEHOLDER = "[screenshot omitted: an older desktop frame \u2014 the full image remains in the session event log]";
406
- type ElideStaleScreenshotsResult<T> = {
407
- items: T[];
408
- imageCount: number;
409
- elidedCount: number;
410
- };
411
- type ElideStaleScreenshotsOptions = {
412
- keepLast?: number;
413
- placeholder?: string;
403
+ type UsageDetails = Record<string, unknown> | Array<Record<string, unknown>>;
404
+ type ModelCallUsageTelemetry = {
405
+ inputTokens: number | null;
406
+ outputTokens: number | null;
407
+ cachedTokens: number | null;
408
+ reasoningTokens: number | null;
414
409
  };
415
- declare function elideStaleScreenshotImages<T extends AgentInputItem>(items: readonly T[], options?: ElideStaleScreenshotsOptions): ElideStaleScreenshotsResult<T>;
410
+ declare function modelCallUsageTelemetry(usage: {
411
+ inputTokens?: unknown;
412
+ outputTokens?: unknown;
413
+ inputTokensDetails?: UsageDetails | undefined;
414
+ outputTokensDetails?: UsageDetails | undefined;
415
+ } | null | undefined): ModelCallUsageTelemetry;
416
416
 
417
417
  type NormalizedRuntimeEvent = {
418
418
  type: SessionEventType;
@@ -425,6 +425,7 @@ type ModelResponseUsage = {
425
425
  outputTokens?: number;
426
426
  totalTokens?: number;
427
427
  inputTokensDetails?: Record<string, number> | Array<Record<string, number>>;
428
+ outputTokensDetails?: Record<string, number> | Array<Record<string, number>>;
428
429
  };
429
430
  };
430
431
  type ResolveConnectionCredentialInput = {
@@ -452,8 +453,10 @@ type ResolveConnectionCredentialResult = {
452
453
  declare function ensureReadableStreamFrom(): void;
453
454
  type AgentSegmentInput = {
454
455
  kind: "message";
455
- text: string;
456
- serializedRunState?: string | null;
456
+ /** A real human/API prompt. Omitted when resuming the same inference. */
457
+ text?: string;
458
+ /** Ephemeral platform context: system role, never conversation history. */
459
+ internalContext?: string;
457
460
  historyItems?: AgentInputItem[] | null;
458
461
  sandboxEnvelope?: Record<string, unknown> | null;
459
462
  } | {
@@ -466,7 +469,6 @@ type AgentSegmentInput = {
466
469
  type PreparedAgentInput = {
467
470
  input: string | AgentInputItem[] | RunState<any, any>;
468
471
  sandboxSessionState?: SandboxSessionState;
469
- serializedRunStateForSandbox?: string;
470
472
  };
471
473
  type SandboxFileDownload = {
472
474
  fileId: string;
@@ -477,6 +479,17 @@ type SandboxFileDownload = {
477
479
  expiresAt?: Date | string;
478
480
  sizeBytes?: number;
479
481
  };
482
+ type SandboxFileDownloadFailure = {
483
+ fileId: string;
484
+ filename: string;
485
+ path: string;
486
+ reason: string;
487
+ exitCode?: number;
488
+ output?: string;
489
+ };
490
+ type SandboxFileDownloadMaterializationResult = {
491
+ failures: SandboxFileDownloadFailure[];
492
+ };
480
493
  declare function configureRuntimeMetricsHooks(hooks: RuntimeMetricsHooks | null | undefined): void;
481
494
  type OpenGeniRuntime = {
482
495
  configure: (settings: Settings) => void;
@@ -564,14 +577,25 @@ declare class MultiProviderModelProvider implements ModelProvider {
564
577
  declare class CodexSubscriptionUnavailableError extends Error {
565
578
  constructor(modelName: string);
566
579
  }
580
+ /**
581
+ * The workspace's model policy blocks the provider/model this turn resolved
582
+ * to. Thrown at the worker's post-resolution gate INSTEAD of running the turn
583
+ * on the blocked provider — a policy-restricted workspace (e.g. fail-closed to
584
+ * the Codex subscription) must never silently remap to, or fall through to,
585
+ * the paid built-in client. Like CodexSubscriptionUnavailableError the message
586
+ * is user-actionable and surfaces verbatim as a non-retryable turn.failed.
587
+ */
588
+ declare class WorkspaceModelPolicyBlockedError extends Error {
589
+ constructor(modelName: string, providerId: string, reason: "provider" | "model");
590
+ }
567
591
  declare function configureOpenAI(settings: Settings): void;
568
592
  /**
569
593
  * Run the compaction summarizer as one plain, tool-less, non-streaming model
570
594
  * call against the resolved provider. `input` is the active history plus
571
- * Codex's checkpoint prompt. Returns the trimmed summary text, or null on any
572
- * failure (the caller can retry with a harder-trimmed transcript, then fall
573
- * back to deterministic non-LLM compaction). The call deliberately does NOT
574
- * request reasoning encryption, tools, or server-side compaction; it is a
595
+ * Codex's checkpoint prompt. Provider failures propagate to the compaction
596
+ * lifecycle; there is no non-model fallback that silently discards history.
597
+ * The call deliberately does NOT
598
+ * request reasoning encryption, tools, or inline provider compaction; it is a
575
599
  * self-contained summarize.
576
600
  *
577
601
  * Provider-aware: the summary always runs on the SAME provider that serves the
@@ -579,8 +603,7 @@ declare function configureOpenAI(settings: Settings): void;
579
603
  * versa). `api: "chat"` providers (Fireworks) speak /v1/chat/completions, where
580
604
  * the summary is choices[0].message.content; `api: "responses"` (the default,
581
605
  * built-in OpenAI/Azure) speaks /v1/responses as before. When no client/api is
582
- * supplied it falls back to the built-in OpenAI/Azure Responses path so the
583
- * legacy global-client callers are byte-for-byte unchanged. store:false is set
606
+ * supplied it uses the built-in OpenAI/Azure Responses path. store:false is set
584
607
  * only on the OpenAI-platform Responses path (Azure rejects it; chat ignores it).
585
608
  */
586
609
  declare function summarizeForCompaction(settings: Settings, input: Array<Record<string, unknown>>, options?: {
@@ -588,8 +611,10 @@ declare function summarizeForCompaction(settings: Settings, input: Array<Record<
588
611
  api?: ModelProviderApi;
589
612
  maxOutputTokens?: number;
590
613
  model?: string;
591
- maxTranscriptTokens?: number;
592
- }): Promise<string | null>;
614
+ promptCacheKey?: string;
615
+ systemInstructions?: string;
616
+ onUsage?: (usage: ModelResponseUsage) => void | Promise<void>;
617
+ }): Promise<string>;
593
618
  /**
594
619
  * Pull the assistant text out of a Responses API result, shape-tolerant. Only
595
620
  * `role === "assistant"` message items contribute: a provider whose Responses
@@ -599,24 +624,38 @@ declare function summarizeForCompaction(settings: Settings, input: Array<Record<
599
624
  * Responses API only emits assistant messages, so this guard is a no-op there.
600
625
  */
601
626
  declare function extractResponseOutputText(response: unknown): string;
627
+ type GitTokenSeeds = Partial<Record<GitCredentialProvider, string>>;
628
+ type GitCredentialTokenWriterSession = SandboxSessionLike;
602
629
  type BuildAgentOptions = {
603
630
  model?: Model;
604
631
  reasoningEffort?: ReasoningEffort;
605
- compactionMode?: ContextCompactionMode;
606
632
  hostedWebSearch?: boolean;
607
633
  encryptedReasoning?: boolean;
608
- contextWindowTokens?: number;
609
634
  structuredToolTransport?: boolean;
610
635
  computerToolMode?: ComputerToolMode;
636
+ /**
637
+ * Invoked once, immediately before the first real computer action and after
638
+ * the display is ready. Merely advertising computer-use does not call it.
639
+ * The worker uses this seam for computer-use-only recording; ordinary
640
+ * shell/filesystem turns never pay that cost.
641
+ */
642
+ onComputerUseReady?: (session: SandboxSessionLike) => Promise<void>;
611
643
  codexConnectorNamespaces?: ReadonlySet<string>;
644
+ promptCacheKey?: string;
612
645
  sandboxEnvironment?: Record<string, string>;
613
646
  activeSandboxBackend?: Settings["sandboxBackend"];
614
647
  fileResourceDownloads?: SandboxFileDownload[];
615
648
  mcpServers?: MCPServer[];
649
+ workspaceMemory?: string;
616
650
  workspaceEnvironment?: WorkspaceEnvironmentContext;
651
+ rig?: RigInstructionsContext;
652
+ rigSetup?: RigSetupDescriptor;
653
+ rigCredentialHookIds?: string[];
617
654
  gitTokenSeed?: string;
655
+ gitTokenSeeds?: GitTokenSeeds;
618
656
  toolspaceTokenSeed?: string;
619
657
  genesisTitleHint?: boolean;
658
+ persistentSessionSettings?: PersistentSessionSettings;
620
659
  instructionsTemplate?: string;
621
660
  sessionInstructions?: string;
622
661
  packSkills?: PackSkill[];
@@ -643,6 +682,22 @@ type WorkspaceEnvironmentContext = {
643
682
  description?: string | null;
644
683
  variableNames?: string[];
645
684
  };
685
+ type PersistentSessionSettings = {
686
+ titleIsSet: boolean;
687
+ childNotificationsMode?: "digest" | "passive";
688
+ };
689
+ /**
690
+ * The rig a session rides (M3): its name + the active version pinned onto the
691
+ * session. Surfaced verbatim in the non-bypassable CORE instructions so the
692
+ * agent understands its sandbox is a disposable fork of a shared, versioned
693
+ * machine definition and how to promote a durable change. Absent for rig-less
694
+ * sessions (the block never renders).
695
+ */
696
+ type RigInstructionsContext = {
697
+ name: string;
698
+ version: number;
699
+ };
700
+ declare function rigInstructions(rig: RigInstructionsContext): string[];
646
701
  declare function workspaceEnvironmentInstructions(environment: WorkspaceEnvironmentContext): string[];
647
702
  /**
648
703
  * The non-bypassable CORE of the agent instructions: the goal-loop ownership
@@ -655,7 +710,7 @@ declare function workspaceEnvironmentInstructions(environment: WorkspaceEnvironm
655
710
  * drop: composeAgentInstructions() substitutes it at the persona template's
656
711
  * {{core}} marker, and appends it when the marker is absent.
657
712
  */
658
- declare function coreInstructions(workspaceEnvironment?: WorkspaceEnvironmentContext): string[];
713
+ declare function coreInstructions(workspaceEnvironment?: WorkspaceEnvironmentContext, rig?: RigInstructionsContext): string[];
659
714
  /**
660
715
  * Composes the final agent instructions from a (possibly white-labelled)
661
716
  * persona template and the non-bypassable CORE. The CORE is substituted at the
@@ -664,7 +719,7 @@ declare function coreInstructions(workspaceEnvironment?: WorkspaceEnvironmentCon
664
719
  * and the append both join by " ", so the DEFAULT_AGENT_INSTRUCTIONS template
665
720
  * with an empty environment reproduces the historical preamble byte-for-byte.
666
721
  */
667
- declare function composeAgentInstructions(template: string, workspaceEnvironment?: WorkspaceEnvironmentContext): string;
722
+ declare function composeAgentInstructions(template: string, workspaceEnvironment?: WorkspaceEnvironmentContext, rig?: RigInstructionsContext): string;
668
723
  /**
669
724
  * Appends the per-session persona instructions to the already-composed
670
725
  * (workspace + CORE) instructions, joined by " " — exactly the join used
@@ -673,6 +728,22 @@ declare function composeAgentInstructions(template: string, workspaceEnvironment
673
728
  * is a no-op that returns the composed string byte-for-byte.
674
729
  */
675
730
  declare function appendSessionInstructions(composed: string, sessionInstructions?: string): string;
731
+ /**
732
+ * Append the durable session metadata the model otherwise cannot observe.
733
+ * This is deliberately declarative and excludes the title text: the title is
734
+ * user-controlled display metadata, while the agent only needs to know whether
735
+ * initialization has already happened. The block is present on every turn when
736
+ * supplied so compaction cannot erase knowledge that these settings persist.
737
+ */
738
+ declare function appendPersistentSessionSettings(composed: string, settings?: PersistentSessionSettings): string;
739
+ /**
740
+ * Appends the workspace memory working-set block to the already-composed
741
+ * (workspace + CORE + generic substrate) instructions, joined by " ". The
742
+ * memory slice is workspace-ground and intentionally lands before
743
+ * per-session instructions. An absent/blank value is a no-op that returns the
744
+ * composed string byte-for-byte.
745
+ */
746
+ declare function appendWorkspaceMemory(composed: string, workspaceMemory?: string): string;
676
747
  /**
677
748
  * Appends the generic programmatic-tool-calling (toolspace) directive to the
678
749
  * composed workspace + CORE instructions, joined by " ". This is GENERIC
@@ -728,34 +799,19 @@ declare function mcpToolErrorOutput(error: unknown): {
728
799
  };
729
800
  declare function buildOpenGeniAgent(settings: Settings, resources: ResourceRef[], options?: BuildAgentOptions): Agent<any, any>;
730
801
  /**
731
- * Build the SandboxAgent capability set provider-aware.
732
- *
733
- * The SDK's `Capabilities.default()` force-includes `compaction()`, whose
734
- * sampling params emit `context_management:[{type:'compaction', …}]` to the
735
- * Responses transport. The OpenAI platform honors that (server-side compaction);
736
- * AZURE rejects it with `400 unsupported_parameter` — which is exactly the live
737
- * production failure on Azure today. So we MUST NOT attach the compaction
738
- * capability on the Azure / client / off paths.
739
- *
740
- * We rebuild the base set explicitly (`filesystem()`, `shell()`, the same
741
- * factories the SDK default uses) and add `compaction()` ONLY on the server
742
- * path, with an explicit `StaticCompactionPolicy(threshold)` so gpt-5.5 — which
743
- * is absent from the SDK's hardcoded context-window map and would otherwise hit
744
- * the wrong 240k fallback — gets the correct threshold. The SDK has no
745
- * window-registration API, so an explicit threshold is the only way to fix it.
746
- *
747
- * The resolved compaction mode and the effective context window are now passed
748
- * IN (the multi-provider caller resolves them per provider/model) rather than
749
- * re-derived from settings here. Both default to the settings-derived value so
750
- * callers that don't route per-model (and the existing tests) keep today's exact
751
- * behaviour; the effective window only changes the server-path threshold when a
752
- * resolved model declares its own contextWindowTokens.
802
+ * Codex accepts ordinary FUNCTION tools but also accepts `input_image` content
803
+ * inside a function_call_output (the same transport used by codex-rs
804
+ * view_image). The SDK filesystem capability unnecessarily couples this choice
805
+ * to hosted apply_patch support; when hosted tools are disabled it degrades
806
+ * view_image to a giant text data URL, charging roughly one token per four
807
+ * base64 characters. Re-wrap only successful data-URL results as a structured
808
+ * image. Text errors remain text, and the tool itself remains a normal function.
753
809
  */
810
+ declare function withStructuredViewImageFunctionResults(tools: Tool<unknown>[]): Tool<unknown>[];
754
811
  declare function buildAgentCapabilities(settings: Settings, packSkills: PackSkill[], options?: {
755
- compactionMode?: ContextCompactionMode;
756
- contextWindowTokens?: number;
757
812
  structuredToolTransport?: boolean;
758
813
  computerToolMode?: ComputerToolMode;
814
+ onComputerUseReady?: (session: SandboxSessionLike) => Promise<void>;
759
815
  }): ReturnType<typeof Capabilities.default>;
760
816
  declare function sandboxRunAs(_settings: Settings): string | undefined;
761
817
  type PreparedAgentTools = {
@@ -767,6 +823,7 @@ type PrepareToolsOptions = {
767
823
  accountId?: string;
768
824
  workspaceId?: string;
769
825
  sessionId?: string;
826
+ turnId?: string;
770
827
  subjectId?: string;
771
828
  subjectLabel?: string;
772
829
  firstPartyPermissions?: Permission[];
@@ -777,14 +834,6 @@ declare function prepareAgentTools(settings: Settings, tools: ToolRef[], options
777
834
  declare function prefixedMcpToolName(registryId: string, toolName: string): string;
778
835
  type PrepareInputOptions = {
779
836
  sandboxClient?: unknown;
780
- /**
781
- * Usable input-token budget B (window - reserved output). When set, the
782
- * assembled history is passed through `enforceInputBudget` so a single
783
- * over-budget input can never be sent — the last-resort backstop behind the
784
- * best-effort pre-turn compaction. Omitted (undefined) disables the guard
785
- * (no behaviour change for callers that don't opt in).
786
- */
787
- inputBudgetTokens?: number;
788
837
  };
789
838
  declare function prepareRunInput(agent: Agent<any, any>, input: AgentSegmentInput, options?: PrepareInputOptions): Promise<PreparedAgentInput>;
790
839
  type RunAgentStreamOptions = {
@@ -792,19 +841,32 @@ type RunAgentStreamOptions = {
792
841
  sandboxEnvironment?: Record<string, string>;
793
842
  onRuntimeEvent?: (event: NormalizedRuntimeEvent) => Promise<void> | void;
794
843
  contextCompactionSignalTokens?: () => number | null | undefined;
844
+ contextCompactionRequested?: () => boolean | Promise<boolean>;
845
+ onGitCredentialSessionReady?: (session: GitCredentialTokenWriterSession) => Promise<void> | void;
795
846
  ownedSandbox?: {
796
847
  client: unknown;
797
848
  session: unknown;
798
849
  sessionState?: unknown;
799
850
  setupSession?: unknown;
851
+ fileDownloadsMaterialized?: boolean;
852
+ deferredSetup?: boolean;
800
853
  };
801
854
  callModelInputFilter?: CallModelInputFilter;
802
855
  };
803
856
  type ContextRobustnessFilterOptions = {
804
857
  contextCompactionSignalTokens?: () => number | null | undefined;
858
+ contextCompactionRequested?: () => boolean | Promise<boolean>;
805
859
  throwOnCompactionNeeded?: boolean;
806
860
  };
807
861
  declare const GENESIS_TITLE_DIRECTIVE = "This is the first turn of a new session. Before responding to the user, call the opengeni__set_session_title tool with a concise 3-7 word title that summarizes what this session is about, then address the user's request normally.";
862
+ /**
863
+ * Inject the genesis-title directive into exactly one model request. Agent
864
+ * instructions are reused for every model call in a tool loop, so placing this
865
+ * directive there turned a nominally one-shot setup action into repeated title
866
+ * calls. The closure is intentionally consumed even when the first request
867
+ * fails: a retry/recovery must continue the task, not restart setup.
868
+ */
869
+ declare function oneShotGenesisTitleInputFilter(): CallModelInputFilter;
808
870
  declare const TOOLSPACE_PROGRAMMATIC_DIRECTIVE = "Every tool on your MCP surface is also callable programmatically from the sandbox shell, so scripts can invoke tools without a model round trip per call. Run `ogtool list` to see the available tools and their input schemas (from tools/list), then `ogtool call <tool-name> '<json-args>'`; equivalently, POST MCP JSON-RPC to $OPENGENI_TOOLSPACE_URL with the bearer token read from $OPENGENI_TOOLSPACE_TOKEN_FILE. Prefer programmatic calls for loops, polling, and bulk filtering: their results stay in the sandbox and do not consume your context window. Tools that require human approval must still be invoked normally \u2014 called programmatically they return a typed error.";
809
871
  /**
810
872
  * callModelInputFilter that removes provider-assigned item ids (rs_/msg_/fc_…)
@@ -825,7 +887,7 @@ declare const stripProviderItemIdsFilter: CallModelInputFilter;
825
887
  * `action` and `actions` down to EXACTLY ONE (keeps `actions`, drops `action`).
826
888
  * The Azure computer-use endpoint rejects a request whose computer_call has
827
889
  * both with `400 Computer call input must include exactly one of `action` or
828
- * `actions``; and (live-proven against gpt-5.5's GA computer tool) it also
890
+ * `actions``; and (live-proven against gpt-5.6-sol's GA computer tool) it also
829
891
  * rejects the `action`-only form, accepting ONLY the batched plural `actions`.
830
892
  * The SDK 0.11.6 schema allows both, so a freshly-emitted
831
893
  * screenshot call carries the redundant pair. This filter runs before EVERY
@@ -835,13 +897,20 @@ declare const stripProviderItemIdsFilter: CallModelInputFilter;
835
897
  * never mutated.
836
898
  */
837
899
  declare const normalizeComputerCallsFilter: CallModelInputFilter;
900
+ /**
901
+ * Per-call state compaction for local image inspection. Re-opening the same
902
+ * path supersedes its prior base64 result; carrying both provides no newer
903
+ * information and can otherwise balloon every following model request.
904
+ */
905
+ declare const elideSupersededViewImagesFilter: CallModelInputFilter;
838
906
  declare function contextRobustnessFilterForSettings(settings: Settings, options?: ContextRobustnessFilterOptions): CallModelInputFilter;
839
907
  /**
840
908
  * The model-input filter applied before every model call. The computer_call
841
909
  * action/actions normalizer is ALWAYS on (the Azure endpoint 400s without it);
842
910
  * the provider-item-id strip is layered on top when the configured policy
843
- * selects it; the context-robustness guard then elides stale screenshots on
844
- * every mode and applies hard budget trimming only on the client-compaction path.
911
+ * selects it; the context-robustness guard then raises the proactive durable
912
+ * compaction signal on the client-compaction path. It never trims history from
913
+ * an individual request.
845
914
  */
846
915
  declare function callModelInputFilterForSettings(settings: Settings, options?: ContextRobustnessFilterOptions): CallModelInputFilter | undefined;
847
916
  declare function runAgentStream(agent: Agent<any, any>, input: PreparedAgentInput | string | RunState<any, any>, settings: Settings, overrides?: RunAgentStreamOptions): Promise<_openai_agents.StreamedRunResult<any, Agent<any, any>>>;
@@ -863,10 +932,63 @@ declare function maxTurnsExceededRunState(error: unknown): {
863
932
  * an error.
864
933
  */
865
934
  declare function agentsErrorRunState(error: unknown): string | null;
866
- declare function withManifestRefreshOnResume(client: SandboxClient, targetManifest: Manifest | undefined): SandboxClient;
867
- declare function applyMissingManifestEntries(session: SandboxSessionLike, targetManifest: Manifest): Promise<void>;
935
+ declare function withManifestRefreshOnResume(client: SandboxClient, targetManifest: Manifest | undefined, context?: Pick<SandboxLifecycleHookContext, "onRuntimeEvent">): SandboxClient;
936
+ declare function applyMissingManifestEntries(session: SandboxSessionLike, targetManifest: Manifest, context?: Pick<SandboxLifecycleHookContext, "onRuntimeEvent">): Promise<void>;
937
+ /**
938
+ * Key-level diff of the live box's baked manifest env vs the freshly recomputed
939
+ * target env. Returns null when identical. Key NAMES only — values are secrets
940
+ * and must never leave this function's comparison.
941
+ */
942
+ declare function manifestEnvironmentDrift(current: Manifest, target: Manifest): {
943
+ added: string[];
944
+ removed: string[];
945
+ changed: string[];
946
+ } | null;
947
+ /**
948
+ * ENV PIN for provided sessions (the ownership-inversion turn path). The SDK
949
+ * validates the FULL target manifest environment against a live provided
950
+ * session's baked env BEFORE reducing to its entry-only delta
951
+ * (validateNoEnvironmentDelta -> session-fatal UserError on ANY difference).
952
+ * So a turn resuming an existing box must declare the box's OWN env,
953
+ * byte-identical — never the fresh recompute. This replaces the agent's
954
+ * defaultManifest environment with the baked one and reports the drift (key
955
+ * names only) instead of letting it kill the session. Fresh env lands at the
956
+ * next cold-create; rotating values ride OFF-manifest (TOKEN-BROKER B1/B2).
957
+ */
958
+ declare function pinProvidedSessionManifestEnvironment(agent: Agent<any, any>, session: SandboxSessionLike, context?: Pick<SandboxLifecycleHookContext, "onRuntimeEvent">): Promise<void>;
959
+ /**
960
+ * The one-truth owned-path platform setup: the manifest-env pin (align the turn's
961
+ * manifest to the live box's baked env + report drift, NEVER die on it) plus the
962
+ * beforeAgentStart hooks (repository clone with B1 token/askpass seed, toolspace
963
+ * token seed, azure-cli-login) and signed-URL file materialization — all executed
964
+ * DIRECTLY against the pinned, UN-proxied established box (the SDK never calls
965
+ * client.create/resume for a provided session, so these decorations would never
966
+ * fire on their own).
967
+ *
968
+ * Extracted verbatim from `runStream`'s owned branch so both the EAGER path
969
+ * (runStream, before the run starts) and the LAZY path (the worker's first-op
970
+ * provisioner, after the box is established) run the IDENTICAL setup. A pure
971
+ * refactor for the eager path: same order, same gates, same idempotency
972
+ * (clone skips a materialized tree, token seed overwrites — the desired per-turn
973
+ * refresh, az login is idempotent). The connected-machine (selfhosted) branch
974
+ * keeps platform setup OFF the user's real box and seeds ONLY the toolspace token.
975
+ *
976
+ * `gitTokenSeedsOverride` lets the lazy provisioner pass its own freshly-minted
977
+ * run-scoped provider tokens (minted at establish time, not turn start);
978
+ * unset ⇒ read the seeds off the agent exactly as the eager path does.
979
+ */
980
+ declare function runOwnedSandboxSetup(agent: Agent<any, any>, session: SandboxSessionLike, setupSession: SandboxSessionLike, opts: {
981
+ settings: Settings;
982
+ environment: Record<string, string>;
983
+ preparedInput?: PreparedAgentInput;
984
+ fileDownloadsMaterialized?: boolean;
985
+ onRuntimeEvent?: SandboxLifecycleHookContext["onRuntimeEvent"];
986
+ gitTokenSeedsOverride?: GitTokenSeeds;
987
+ gitTokenSeedOverride?: string;
988
+ }): Promise<void>;
868
989
  declare function withSandboxFileDownloads(client: SandboxClient, downloads: SandboxFileDownload[], context?: Pick<SandboxLifecycleHookContext, "onRuntimeEvent" | "runAs">): SandboxClient;
869
- declare function materializeSandboxFileDownloads(session: SandboxSessionLike, downloads: SandboxFileDownload[], context?: Pick<SandboxLifecycleHookContext, "onRuntimeEvent" | "runAs">): Promise<void>;
990
+ declare function materializeSandboxFileDownloads(session: SandboxSessionLike, downloads: SandboxFileDownload[], context?: Pick<SandboxLifecycleHookContext, "onRuntimeEvent" | "runAs">): Promise<SandboxFileDownloadMaterializationResult>;
991
+ declare function sandboxFileDownloadFailureNote(failures: SandboxFileDownloadFailure[]): string;
870
992
  declare function sandboxFileDownloadsForAgent(agent: unknown): SandboxFileDownload[];
871
993
  /**
872
994
  * Compact a tool-call output for the `agent.toolCall.output` SESSION EVENT so it
@@ -886,6 +1008,8 @@ declare function sandboxFileDownloadsForAgent(agent: unknown): SandboxFileDownlo
886
1008
  declare function normalizeToolOutputForEvent(output: unknown): unknown;
887
1009
  declare function normalizeSdkEvent(event: RunStreamEvent): NormalizedRuntimeEvent[];
888
1010
  declare function modelResponseUsageFromSdkEvent(event: RunStreamEvent): ModelResponseUsage | null;
1011
+ /** Normalize usage from either a Responses or Chat Completions result. */
1012
+ declare function modelResponseUsageFromResponse(response: unknown): ModelResponseUsage | null;
889
1013
  declare function serializeApprovals(interruptions: unknown[]): unknown[];
890
1014
  declare function buildManifest(settings: Settings, resources: ResourceRef[], environment?: Record<string, string>, fileResourceDownloads?: SandboxFileDownload[]): Manifest;
891
1015
  type SandboxLifecycleHookPhase = "beforeAgentStart";
@@ -894,7 +1018,16 @@ type SandboxLifecycleHookContext = {
894
1018
  onRuntimeEvent?: (event: NormalizedRuntimeEvent) => Promise<void> | void;
895
1019
  runAs?: string;
896
1020
  gitTokenSeed?: string;
1021
+ gitTokenSeeds?: GitTokenSeeds;
897
1022
  toolspaceTokenSeed?: string;
1023
+ rigSetup?: RigSetupDescriptor;
1024
+ };
1025
+ type RigSetupDescriptor = {
1026
+ rigId: string;
1027
+ versionId: string;
1028
+ rigName: string;
1029
+ script: string;
1030
+ timeoutMs: number;
898
1031
  };
899
1032
  type SandboxLifecycleHook = {
900
1033
  id: string;
@@ -937,11 +1070,50 @@ declare function withSandboxLifecycleHooks(client: SandboxClient, hooks: Sandbox
937
1070
  declare function repositoryUsesSandboxClone(settings: Settings, resource: Extract<ResourceRef, {
938
1071
  kind: "repository";
939
1072
  }>, activeSandboxBackend?: Settings["sandboxBackend"]): boolean;
1073
+ /**
1074
+ * Build the off-manifest command used to atomically replace provider token files.
1075
+ *
1076
+ * Token values exist only in this one sandbox exec command. The stable askpass
1077
+ * and provider-CLI wrappers always read the files at invocation time, so an
1078
+ * in-flight multi-day turn observes the replacement without changing its
1079
+ * manifest environment or rebuilding the sandbox.
1080
+ */
1081
+ declare function gitProviderTokenRefreshCommand(seeds: GitTokenSeeds): string;
1082
+ declare function refreshGitProviderTokenFiles(session: GitCredentialTokenWriterSession, seeds: GitTokenSeeds, options?: {
1083
+ runAs?: string;
1084
+ }): Promise<void>;
940
1085
  declare function repositoryCloneCommand(resources: Extract<ResourceRef, {
941
1086
  kind: "repository";
942
1087
  }>[]): string;
943
1088
  declare function toolspaceTokenSeedCommand(): string;
944
1089
  declare function runToolspaceTokenSeedHook(session: SandboxSessionLike, context: SandboxLifecycleHookContext): Promise<void>;
1090
+ /**
1091
+ * The rig-setup command (M3). One idempotent bash program:
1092
+ * 1. `mkdir -p /var/opengeni` and, if the per-version marker already exists,
1093
+ * print the SKIP sentinel and exit 0 (a warm box re-running the hook).
1094
+ * 2. otherwise atomically claim a per-version lock directory. A loser waits
1095
+ * for the winner's marker, then skips; if the winner fails and releases the
1096
+ * lock, the loser retries the claim.
1097
+ * 3. the winner writes the rig's setup script to a temp file and runs it under
1098
+ * coreutils `timeout` (NOT `bash -e` — the script opts into `set -e`
1099
+ * itself if it wants), then captures the exit code and `touch`es the marker
1100
+ * ONLY on success (exit 0) so a failed/timed-out setup re-runs next turn.
1101
+ * The heredoc delimiter is quoted, so the script content is executed verbatim
1102
+ * with no host-side expansion.
1103
+ */
1104
+ declare function rigSetupScriptCommand(script: string, versionId: string, timeoutMs?: number, markerRoot?: string): string;
1105
+ /**
1106
+ * The rig-setup beforeAgentStart hook (M3). Runs the frozen rig version's setup
1107
+ * script exactly once per box (marker-guarded), under the RIG's own timeout
1108
+ * (context.rigSetup.timeoutMs, NOT the 120s lifecycle default). Emits
1109
+ * rig.setup.started, then one terminal event:
1110
+ * - rig.setup.skipped — marker already present,
1111
+ * - rig.setup.completed — script ran and exited 0,
1112
+ * - rig.setup.failed — nonzero exit / timeout,
1113
+ * and on failure THROWS (fail the turn closed) with a message naming the
1114
+ * rig/version and a bounded tail of the setup output.
1115
+ */
1116
+ declare function runRigSetupHook(session: SandboxSessionLike, context?: SandboxLifecycleHookContext): Promise<void>;
945
1117
  declare function runRepositoryCloneHook(session: SandboxSessionLike, resources: Extract<ResourceRef, {
946
1118
  kind: "repository";
947
1119
  }>[], context?: SandboxLifecycleHookContext): Promise<void>;
@@ -962,4 +1134,4 @@ declare function azureOpenAIDefaultQuery(settings: Pick<Settings, "azureOpenaiAp
962
1134
  */
963
1135
  declare function lazySkillSourceWithPackSkills(packSkills: PackSkill[]): LocalDirLazySkillSource;
964
1136
 
965
- export { type AgentSegmentInput, type BuildAgentOptions, COMPACTION_PROMPT, COMPACTION_SUMMARY_MARKER, COMPACT_USER_MESSAGE_MAX_TOKENS, type ClientCompactionDecision, CodexSubscriptionUnavailableError, type CompactionItem, CompactionNeededError, ComputerActionError, ComputerReadOnlyError, type ComputerToolMode, ComputerUnavailableError, type ComputerUseArgs, ComputerUseCapability, type ContextRobustnessFilterOptions, DEFAULT_COMPACTION_THRESHOLD_RATIO, type ElideStaleScreenshotsOptions, type ElideStaleScreenshotsResult, GENESIS_TITLE_DIRECTIVE, type HistoryItem, MAX_COMPACTION_THRESHOLD_RATIO, MIN_COMPACTION_THRESHOLD_RATIO, type ModelResponseUsage, MultiProviderModelProvider, type NormalizedRuntimeEvent, type OpenGeniRuntime, type PackSkill, type PackSkillFile, type PrepareInputOptions, type PrepareToolsOptions, type PreparedAgentInput, type PreparedAgentTools, type ProductionRuntimeOverrides, type ResolveConnectionCredentialInput, type ResolveConnectionCredentialResult, type RunAgentStreamOptions, RuntimeMetricsHooks, SCREENSHOT_OMITTED_PLACEHOLDER, SUMMARY_BUFFER_TOKENS, SUMMARY_PREFIX, SandboxComputer, type SandboxComputerOptions, type SandboxFileDownload, type SandboxLifecycleHook, type SandboxLifecycleHookContext, type SandboxLifecycleHookPhase, TOOLSPACE_PROGRAMMATIC_DIRECTIVE, USER_MESSAGE_TRUNCATION_MARKER, type WorkspaceEnvironmentContext, agentsErrorRunState, appendGenesisTitleDirective, appendSessionInstructions, appendToolspaceInstructions, applyMissingManifestEntries, azureCliLoginCommand, azureOpenAIDefaultQuery, buildAgentCapabilities, buildCompactionPromptInput, buildCompactionReplacementHistory, buildDeterministicFallbackCompactionHistory, buildManifest, buildModelInstance, buildOpenAIClientFromSettings, buildOpenGeniAgent, buildProviderClient, buildSummaryItem, callModelInputFilterForSettings, clampCompactionThresholdRatio, clientCompactionThresholdTokens, composeAgentInstructions, computerUse, configureOpenAI, configureRuntimeMetricsHooks, contextRobustnessFilterForSettings, coreInstructions, createProductionAgentRuntime, decideClientCompaction, elideStaleScreenshotImages, enforceInputBudget, ensureReadableStreamFrom, estimateItemTokens, estimateTokens, extractResponseOutputText, findCompactionNeededError, findKeepBoundary, isCompactionSummary, isUserMessage, lazySkillSourceWithPackSkills, materializeSandboxFileDownloads, maxTurnsExceededRunState, mcpToolErrorOutput, modelResponseUsageFromSdkEvent, neutralizeToolSearchItemsInSerializedRunState, normalizeComputerCallsFilter, normalizeSdkEvent, normalizeToolOutputForEvent, prefixedMcpToolName, prepareAgentTools, prepareRunInput, renderCompactionPromptInputForChat, repositoryCloneCommand, repositoryUsesSandboxClone, resolveTurnModel, runAgentStream, runAzureCliLoginHook, runBeforeAgentStartHooks, runRepositoryCloneHook, runToolspaceTokenSeedHook, sandboxCommandExitCode, sandboxCommandOutput, sandboxCommandStillRunning, sandboxFileDownloadsForAgent, sandboxLifecycleHooksForIds, sandboxRunAs, sanitizeHistoryItemsForModel, serializeApprovals, stripProviderItemIdsFilter, stripReasoningEncryptedContent, stripReasoningIdentityFromSerializedRunState, summarizeForCompaction, toolspaceTokenSeedCommand, withManifestRefreshOnResume, withSandboxFileDownloads, withSandboxLifecycleHooks, workspaceEnvironmentInstructions };
1137
+ export { type AgentSegmentInput, type BuildAgentOptions, COMPACTION_PROMPT, COMPACTION_SUMMARY_MARKER, COMPACT_USER_MESSAGE_MAX_TOKENS, CodexSubscriptionUnavailableError, type CompactionDecision, type CompactionItem, CompactionNeededError, ComputerActionError, ComputerReadOnlyError, type ComputerToolMode, ComputerUnavailableError, type ComputerUseArgs, ComputerUseCapability, type ContextRobustnessFilterOptions, DEFAULT_COMPACTION_THRESHOLD_RATIO, GENESIS_TITLE_DIRECTIVE, type GitCredentialTokenWriterSession, type GitTokenSeeds, type HistoryItem, MAX_COMPACTION_THRESHOLD_RATIO, MIN_COMPACTION_THRESHOLD_RATIO, type ModelCallUsageTelemetry, type ModelResponseUsage, MultiProviderModelProvider, type NormalizedRuntimeEvent, type OpenGeniRuntime, type PackSkill, type PackSkillFile, type PersistentSessionSettings, type PrepareInputOptions, type PrepareToolsOptions, type PreparedAgentInput, type PreparedAgentTools, type ProductionRuntimeOverrides, type ResolveConnectionCredentialInput, type ResolveConnectionCredentialResult, type RigInstructionsContext, type RigSetupDescriptor, type RunAgentStreamOptions, RuntimeMetricsHooks, SUMMARY_BUFFER_TOKENS, SUMMARY_PREFIX, SandboxComputer, type SandboxComputerOptions, type SandboxFileDownload, type SandboxFileDownloadFailure, type SandboxFileDownloadMaterializationResult, type SandboxLifecycleHook, type SandboxLifecycleHookContext, type SandboxLifecycleHookPhase, TOOLSPACE_PROGRAMMATIC_DIRECTIVE, USER_MESSAGE_TRUNCATION_MARKER, type WorkspaceEnvironmentContext, WorkspaceModelPolicyBlockedError, agentsErrorRunState, appendGenesisTitleDirective, appendPersistentSessionSettings, appendSessionInstructions, appendToolspaceInstructions, appendWorkspaceMemory, applyMissingManifestEntries, azureCliLoginCommand, azureOpenAIDefaultQuery, buildAgentCapabilities, buildCompactionPromptInput, buildCompactionReplacementHistory, buildManifest, buildModelInstance, buildOpenAIClientFromSettings, buildOpenGeniAgent, buildProviderClient, buildSummaryItem, callModelInputFilterForSettings, clampCompactionThresholdRatio, compactionThresholdTokens, composeAgentInstructions, computerUse, configureOpenAI, configureRuntimeMetricsHooks, contextRobustnessFilterForSettings, coreInstructions, createProductionAgentRuntime, decideCompaction, elideSupersededViewImagePairs, elideSupersededViewImagesFilter, ensureReadableStreamFrom, estimateItemTokens, estimateTokens, extractResponseOutputText, findCompactionNeededError, gitProviderTokenRefreshCommand, isCompactionSummary, isEphemeralInternalContext, isUserMessage, lazySkillSourceWithPackSkills, manifestEnvironmentDrift, materializeSandboxFileDownloads, maxTurnsExceededRunState, mcpToolErrorOutput, modelCallUsageTelemetry, modelResponseUsageFromResponse, modelResponseUsageFromSdkEvent, neutralizeToolSearchItemsInSerializedRunState, normalizeComputerCallsFilter, normalizeSdkEvent, normalizeToolOutputForEvent, oneShotGenesisTitleInputFilter, pinProvidedSessionManifestEnvironment, prefixedMcpToolName, prepareAgentTools, prepareRunInput, refreshGitProviderTokenFiles, renderCompactionPromptInputForChat, repositoryCloneCommand, repositoryUsesSandboxClone, resolveTurnModel, rigInstructions, rigSetupScriptCommand, runAgentStream, runAzureCliLoginHook, runBeforeAgentStartHooks, runOwnedSandboxSetup, runRepositoryCloneHook, runRigSetupHook, runToolspaceTokenSeedHook, sandboxCommandExitCode, sandboxCommandOutput, sandboxCommandStillRunning, sandboxFileDownloadFailureNote, sandboxFileDownloadsForAgent, sandboxLifecycleHooksForIds, sandboxRunAs, sanitizeHistoryItemsForModel, serializeApprovals, stripProviderItemIdsFilter, stripReasoningEncryptedContent, stripReasoningIdentityFromSerializedRunState, summarizeForCompaction, toolspaceTokenSeedCommand, withManifestRefreshOnResume, withSandboxFileDownloads, withSandboxLifecycleHooks, withStructuredViewImageFunctionResults, workspaceEnvironmentInstructions };