@opengeni/runtime 0.14.1 → 0.14.15

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 (79) hide show
  1. package/dist/{chunk-4YJ5Z52Z.js → chunk-7E2ZSCZK.js} +6 -6
  2. package/dist/{chunk-4YJ5Z52Z.js.map → chunk-7E2ZSCZK.js.map} +1 -1
  3. package/dist/{chunk-HHWIZHQM.js → chunk-GNEGANUF.js} +942 -300
  4. package/dist/chunk-GNEGANUF.js.map +1 -0
  5. package/dist/codex-tool-search.d.ts +100 -0
  6. package/dist/context-compaction.d.ts +236 -0
  7. package/dist/history-sanitizer.d.ts +320 -0
  8. package/dist/index.d.ts +186 -718
  9. package/dist/index.js +612 -126
  10. package/dist/index.js.map +1 -1
  11. package/dist/{localSources-T3HZ6KY4.js → localSources-BXHBKGF4.js} +2 -2
  12. package/dist/mcp-network.d.ts +32 -35
  13. package/dist/metrics.d.ts +33 -0
  14. package/dist/sandbox/capabilities.d.ts +11 -0
  15. package/dist/sandbox/channel-a.d.ts +226 -0
  16. package/dist/sandbox/display-stack.d.ts +99 -0
  17. package/dist/sandbox/errors.d.ts +16 -0
  18. package/dist/sandbox/exec-banner.d.ts +19 -0
  19. package/dist/sandbox/index.d.ts +190 -6
  20. package/dist/sandbox/index.js +20 -4
  21. package/dist/sandbox/op-correlation.d.ts +24 -0
  22. package/dist/sandbox/provider-errors.d.ts +32 -0
  23. package/dist/sandbox/provider-operation-gate.d.ts +12 -0
  24. package/dist/sandbox/providers/blaxel.d.ts +2 -0
  25. package/dist/sandbox/providers/cloudflare.d.ts +2 -0
  26. package/dist/sandbox/providers/daytona.d.ts +2 -0
  27. package/dist/sandbox/providers/docker.d.ts +2 -0
  28. package/dist/sandbox/providers/e2b.d.ts +2 -0
  29. package/dist/sandbox/providers/index.d.ts +11 -0
  30. package/dist/sandbox/providers/local.d.ts +2 -0
  31. package/dist/sandbox/providers/modal.d.ts +132 -0
  32. package/dist/sandbox/providers/none.d.ts +2 -0
  33. package/dist/sandbox/providers/runloop.d.ts +2 -0
  34. package/dist/sandbox/providers/selfhosted.d.ts +2 -0
  35. package/dist/sandbox/providers/types.d.ts +30 -0
  36. package/dist/sandbox/providers/vercel.d.ts +2 -0
  37. package/dist/sandbox/recording.d.ts +80 -0
  38. package/dist/sandbox/routing/backend-resolver.d.ts +173 -0
  39. package/dist/sandbox/routing/routing-session.d.ts +401 -0
  40. package/dist/sandbox/run-credentials.d.ts +65 -0
  41. package/dist/sandbox/select.d.ts +120 -0
  42. package/dist/sandbox/selfhosted/capabilities.d.ts +91 -0
  43. package/dist/sandbox/selfhosted/control-rpc.d.ts +175 -0
  44. package/dist/sandbox/selfhosted/fault-rendering.d.ts +40 -0
  45. package/dist/sandbox/selfhosted/op-observer.d.ts +40 -0
  46. package/dist/sandbox/selfhosted/op-stream.d.ts +104 -0
  47. package/dist/sandbox/selfhosted/op-testing.d.ts +108 -0
  48. package/dist/sandbox/selfhosted/op-transport.d.ts +60 -0
  49. package/dist/sandbox/selfhosted/retry-policy.d.ts +106 -0
  50. package/dist/sandbox/selfhosted/session.d.ts +552 -0
  51. package/dist/sandbox/selfhosted/testing.d.ts +48 -0
  52. package/dist/sandbox/stream-port.d.ts +80 -0
  53. package/dist/sandbox/stream-token.d.ts +44 -0
  54. package/dist/sandbox/terminal-server.d.ts +67 -0
  55. package/dist/sandbox/toolspace-token.d.ts +23 -0
  56. package/dist/sandbox/turn-tool-cancellation.d.ts +72 -0
  57. package/dist/sandbox/workspace-archive.d.ts +39 -0
  58. package/dist/sandbox-computer.d.ts +227 -0
  59. package/dist/screenshot-error-card.d.ts +1 -0
  60. package/dist/skill-library.d.ts +10 -12
  61. package/dist/usage-telemetry.d.ts +45 -0
  62. package/dist/workspace-skills.d.ts +31 -0
  63. package/package.json +7 -7
  64. package/src/context-compaction.ts +600 -6
  65. package/src/history-sanitizer.ts +10 -92
  66. package/src/index.ts +301 -62
  67. package/src/sandbox/channel-a.ts +267 -81
  68. package/src/sandbox/index.ts +56 -94
  69. package/src/sandbox/provider-operation-gate.ts +110 -0
  70. package/src/sandbox/providers/docker.ts +13 -1
  71. package/src/sandbox/providers/modal.ts +433 -3
  72. package/src/sandbox/routing/routing-session.ts +84 -8
  73. package/src/sandbox/selfhosted/session.ts +7 -6
  74. package/src/sandbox/turn-tool-cancellation.ts +47 -7
  75. package/src/sandbox/workspace-archive.ts +176 -73
  76. package/src/sandbox-computer.ts +25 -75
  77. package/dist/chunk-HHWIZHQM.js.map +0 -1
  78. package/dist/index-BraazrAO.d.ts +0 -2931
  79. /package/dist/{localSources-T3HZ6KY4.js.map → localSources-BXHBKGF4.js.map} +0 -0
package/dist/index.js CHANGED
@@ -88,9 +88,12 @@ import {
88
88
  createTurnToolCancellationController,
89
89
  decideSelfhostedRetry,
90
90
  decodeModalSnapshotId,
91
+ decodeNativeSnapshotRef,
91
92
  defaultSelfhostedRetryClock,
92
- deletePriorPersistedSnapshot,
93
+ deleteModalCheckpointSnapshot,
93
94
  deleteRecordingArtifacts,
95
+ describeLegacyNativeSnapshotArchive,
96
+ describeNativeSnapshotArchive,
94
97
  deserializeSandboxSessionStateEnvelope,
95
98
  desktopCapableBackend,
96
99
  drainingExhaustedError,
@@ -104,6 +107,7 @@ import {
104
107
  extForCodec,
105
108
  fingerprintSandboxWorkspace,
106
109
  hasPersistableSandboxProviderIdentity,
110
+ inspectModalSandboxLifecycle,
107
111
  inspectRecordingArtifact,
108
112
  isExecSessionLostBanner,
109
113
  isProviderSandboxGoneDuringRoutedOperation,
@@ -116,6 +120,7 @@ import {
116
120
  mintStreamToken,
117
121
  modalSandboxAttributionEnvironment,
118
122
  modalSandboxAttributionTags,
123
+ modalSessionMatchesCheckpointProviderBinding,
119
124
  negotiateCapabilities,
120
125
  negotiateSelfhostedCapabilities,
121
126
  nextDurableOpId,
@@ -137,6 +142,9 @@ import {
137
142
  recordingStorageKey,
138
143
  renderSelfhostedFault,
139
144
  requirePersistableReplacementSandboxEnvelope,
145
+ resolveModalCheckpointProviderBinding,
146
+ resolveModalCheckpointProviderBindingForLiveSandbox,
147
+ resolveModalCheckpointProviderBindingForSession,
140
148
  restoredSandboxSessionStateFromEntry,
141
149
  runCredentialPointerFile,
142
150
  runCredentialRoot,
@@ -176,7 +184,7 @@ import {
176
184
  withToolspaceTokenEnvironment,
177
185
  withToolspaceTokenSession,
178
186
  wrapCapabilityToolsForTurnCancellation
179
- } from "./chunk-HHWIZHQM.js";
187
+ } from "./chunk-GNEGANUF.js";
180
188
  import {
181
189
  getSkillLibraryEntry,
182
190
  isSkillLibraryEntryId,
@@ -205,7 +213,7 @@ import {
205
213
  import {
206
214
  MemorySession,
207
215
  connectMcpServers
208
- } from "./chunk-4YJ5Z52Z.js";
216
+ } from "./chunk-7E2ZSCZK.js";
209
217
  import {
210
218
  Agent,
211
219
  AgentsError,
@@ -6436,6 +6444,9 @@ import {
6436
6444
  boundModelToolOutputItems,
6437
6445
  DEFAULT_MODEL_TOOL_OUTPUT_TRUNCATION_TOKENS
6438
6446
  } from "@opengeni/codex";
6447
+ function elideSupersededViewImagePairs(items) {
6448
+ return items;
6449
+ }
6439
6450
  var TOOL_CALL_RESULT_TYPE_BY_CALL_TYPE = {
6440
6451
  function_call: "function_call_result",
6441
6452
  computer_call: "computer_call_result",
@@ -6480,68 +6491,6 @@ function callIdOf(item) {
6480
6491
  }
6481
6492
  return void 0;
6482
6493
  }
6483
- function viewImagePathOf(item) {
6484
- if (!item || typeof item !== "object") {
6485
- return void 0;
6486
- }
6487
- const record = item;
6488
- if (record.type !== "function_call" || record.name !== "view_image" || typeof record.arguments !== "string") {
6489
- return void 0;
6490
- }
6491
- try {
6492
- const parsed = JSON.parse(record.arguments);
6493
- return typeof parsed.path === "string" && parsed.path.length > 0 ? parsed.path : void 0;
6494
- } catch {
6495
- return void 0;
6496
- }
6497
- }
6498
- function elideSupersededViewImagePairs(items) {
6499
- if (items.length === 0) {
6500
- return [];
6501
- }
6502
- const callIndexById = /* @__PURE__ */ new Map();
6503
- const resultIndexById = /* @__PURE__ */ new Map();
6504
- items.forEach((item, index) => {
6505
- const callId = callIdOf(item);
6506
- if (!callId) {
6507
- return;
6508
- }
6509
- if (itemType(item) === "function_call") {
6510
- callIndexById.set(callId, index);
6511
- } else if (itemType(item) === "function_call_result" || itemType(item) === "function_call_output") {
6512
- resultIndexById.set(callId, index);
6513
- }
6514
- });
6515
- const pairedByPath = /* @__PURE__ */ new Map();
6516
- for (const [callId, callIndex] of callIndexById) {
6517
- const path = viewImagePathOf(items[callIndex]);
6518
- const resultIndex = resultIndexById.get(callId);
6519
- if (!path || resultIndex === void 0 || resultIndex <= callIndex) {
6520
- continue;
6521
- }
6522
- const pairs = pairedByPath.get(path) ?? [];
6523
- pairs.push({ callIndex, resultIndex });
6524
- pairedByPath.set(path, pairs);
6525
- }
6526
- const dropped = /* @__PURE__ */ new Set();
6527
- for (const pairs of pairedByPath.values()) {
6528
- if (pairs.length < 2) {
6529
- continue;
6530
- }
6531
- pairs.sort((left, right) => left.callIndex - right.callIndex);
6532
- for (const pair of pairs.slice(0, -1)) {
6533
- dropped.add(pair.callIndex);
6534
- dropped.add(pair.resultIndex);
6535
- for (let index = pair.callIndex - 1; index >= 0; index -= 1) {
6536
- if (itemType(items[index]) !== "reasoning") {
6537
- break;
6538
- }
6539
- dropped.add(index);
6540
- }
6541
- }
6542
- }
6543
- return dropped.size === 0 ? items.slice() : items.filter((_item, index) => !dropped.has(index));
6544
- }
6545
6494
  function sanitizeHistoryItemsForModel(items, toolOutputTruncationTokens = DEFAULT_MODEL_TOOL_OUTPUT_TRUNCATION_TOKENS) {
6546
6495
  if (items.length === 0) {
6547
6496
  return [];
@@ -7176,6 +7125,9 @@ import { createHash } from "crypto";
7176
7125
  var COMPACTION_SUMMARY_MARKER = "opengeni_context_summary";
7177
7126
  var SUMMARY_BUFFER_TOKENS = 2e4;
7178
7127
  var COMPACT_USER_MESSAGE_MAX_TOKENS = 2e4;
7128
+ var REMOTE_V2_RETAINED_MESSAGE_TOKEN_BUDGET = 64e3;
7129
+ var REMOTE_COMPACTION_V2_IMPLEMENTATION = "responses_compaction_v2";
7130
+ var REMOTE_COMPACTION_V2_BETA_FEATURE = "remote_compaction_v2";
7179
7131
  var DEFAULT_COMPACTION_THRESHOLD_RATIO = 0.9;
7180
7132
  var MIN_COMPACTION_THRESHOLD_RATIO = 0.3;
7181
7133
  var MAX_COMPACTION_THRESHOLD_RATIO = 0.9;
@@ -7236,14 +7188,305 @@ function estimateTextTokens(text) {
7236
7188
  }
7237
7189
  return nonAsciiCodeUnits + Math.ceil(asciiCodeUnits / 4);
7238
7190
  }
7239
- function estimateItemTokens(item) {
7191
+ var IMAGE_LOW_DETAIL_TOKENS = 85;
7192
+ var IMAGE_HIGH_DETAIL_BASE_TOKENS = 85;
7193
+ var IMAGE_HIGH_DETAIL_TILE_TOKENS = 170;
7194
+ var IMAGE_HIGH_DETAIL_TILE_SIZE = 512;
7195
+ var IMAGE_HIGH_DETAIL_MAX_SIDE = 2048;
7196
+ var IMAGE_HIGH_DETAIL_TARGET_SHORT_SIDE = 768;
7197
+ var UNKNOWN_IMAGE_TOKENS = 4096;
7198
+ var MAX_NATIVE_IMAGE_TOKENS = 8192;
7199
+ function finitePositiveInteger(value) {
7200
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.floor(value) : null;
7201
+ }
7202
+ function dimensionsFromRecord(record) {
7203
+ const width = finitePositiveInteger(record.width);
7204
+ const height = finitePositiveInteger(record.height);
7205
+ if (width && height) return [width, height];
7206
+ if (Array.isArray(record.dimensions) && record.dimensions.length >= 2) {
7207
+ const dimensionsWidth = finitePositiveInteger(record.dimensions[0]);
7208
+ const dimensionsHeight = finitePositiveInteger(record.dimensions[1]);
7209
+ if (dimensionsWidth && dimensionsHeight) return [dimensionsWidth, dimensionsHeight];
7210
+ }
7211
+ return null;
7212
+ }
7213
+ function dataUrlBytesPrefix(value, maxBytes = 262144) {
7214
+ const match = /^data:image\/[a-z0-9.+-]+;base64,([a-z0-9+/=\r\n]+)$/i.exec(value);
7215
+ if (!match) return null;
7216
+ try {
7217
+ const maxBase64CodeUnits = Math.ceil(maxBytes / 3) * 4;
7218
+ return new Uint8Array(Buffer.from(match[1].slice(0, maxBase64CodeUnits), "base64"));
7219
+ } catch {
7220
+ return null;
7221
+ }
7222
+ }
7223
+ function base64BytesPrefix(value, maxBytes = 262144) {
7224
+ if (!/^[a-z0-9+/=\r\n]+$/i.test(value)) return null;
7225
+ try {
7226
+ const maxBase64CodeUnits = Math.ceil(maxBytes / 3) * 4;
7227
+ return new Uint8Array(Buffer.from(value.slice(0, maxBase64CodeUnits), "base64"));
7228
+ } catch {
7229
+ return null;
7230
+ }
7231
+ }
7232
+ function uint16BigEndian(bytes, offset) {
7233
+ return (bytes[offset] ?? 0) << 8 | (bytes[offset + 1] ?? 0);
7234
+ }
7235
+ function uint32BigEndian(bytes, offset) {
7236
+ return (bytes[offset] ?? 0) * 16777216 + ((bytes[offset + 1] ?? 0) << 16) + ((bytes[offset + 2] ?? 0) << 8) + (bytes[offset + 3] ?? 0) >>> 0;
7237
+ }
7238
+ function crc32(bytes, start, end) {
7239
+ let crc = 4294967295;
7240
+ for (let offset = start; offset < end; offset += 1) {
7241
+ crc ^= bytes[offset] ?? 0;
7242
+ for (let bit = 0; bit < 8; bit += 1) {
7243
+ crc = crc >>> 1 ^ (crc & 1 ? 3988292384 : 0);
7244
+ }
7245
+ }
7246
+ return (crc ^ 4294967295) >>> 0;
7247
+ }
7248
+ function dimensionsFromImageBytes(bytes) {
7249
+ if (bytes.length >= 33 && bytes[0] === 137 && bytes[1] === 80 && bytes[2] === 78 && bytes[3] === 71 && bytes[4] === 13 && bytes[5] === 10 && bytes[6] === 26 && bytes[7] === 10 && uint32BigEndian(bytes, 8) === 13 && bytes[12] === 73 && bytes[13] === 72 && bytes[14] === 68 && bytes[15] === 82 && crc32(bytes, 12, 29) === uint32BigEndian(bytes, 29)) {
7250
+ const width = uint32BigEndian(bytes, 16);
7251
+ const height = uint32BigEndian(bytes, 20);
7252
+ return width > 0 && height > 0 ? [width, height] : null;
7253
+ }
7254
+ if (bytes.length >= 10 && bytes[0] === 71 && bytes[1] === 73 && bytes[2] === 70 && bytes[3] === 56) {
7255
+ const width = (bytes[6] ?? 0) | (bytes[7] ?? 0) << 8;
7256
+ const height = (bytes[8] ?? 0) | (bytes[9] ?? 0) << 8;
7257
+ return width > 0 && height > 0 ? [width, height] : null;
7258
+ }
7259
+ if (bytes.length >= 30 && bytes[0] === 82 && bytes[1] === 73 && bytes[2] === 70 && bytes[3] === 70 && bytes[8] === 87 && bytes[9] === 69 && bytes[10] === 66 && bytes[11] === 80 && bytes[12] === 86 && bytes[13] === 80 && bytes[14] === 56 && bytes[15] === 88) {
7260
+ const width = 1 + (bytes[24] ?? 0) + ((bytes[25] ?? 0) << 8) + ((bytes[26] ?? 0) << 16);
7261
+ const height = 1 + (bytes[27] ?? 0) + ((bytes[28] ?? 0) << 8) + ((bytes[29] ?? 0) << 16);
7262
+ return width > 0 && height > 0 ? [width, height] : null;
7263
+ }
7264
+ if (bytes.length >= 4 && bytes[0] === 255 && bytes[1] === 216) {
7265
+ let offset = 2;
7266
+ while (offset + 8 < bytes.length) {
7267
+ if (bytes[offset] !== 255) {
7268
+ offset += 1;
7269
+ continue;
7270
+ }
7271
+ const marker = bytes[offset + 1] ?? 0;
7272
+ offset += 2;
7273
+ if (marker === 216 || marker === 217 || marker === 1) continue;
7274
+ if (marker >= 208 && marker <= 215) continue;
7275
+ if (offset + 2 > bytes.length) break;
7276
+ const segmentLength = uint16BigEndian(bytes, offset);
7277
+ if (segmentLength < 2 || offset + segmentLength > bytes.length) break;
7278
+ const isStartOfFrame = marker >= 192 && marker <= 195 || marker >= 197 && marker <= 199 || marker >= 201 && marker <= 203 || marker >= 205 && marker <= 207;
7279
+ if (isStartOfFrame && segmentLength >= 7) {
7280
+ const height = uint16BigEndian(bytes, offset + 3);
7281
+ const width = uint16BigEndian(bytes, offset + 5);
7282
+ return width > 0 && height > 0 ? [width, height] : null;
7283
+ }
7284
+ offset += segmentLength;
7285
+ }
7286
+ }
7287
+ return null;
7288
+ }
7289
+ function dimensionsFromImageSource(source) {
7290
+ if (source instanceof Uint8Array) {
7291
+ return dimensionsFromImageBytes(source);
7292
+ }
7293
+ if (typeof source === "string") {
7294
+ const bytes = dataUrlBytesPrefix(source);
7295
+ return bytes ? dimensionsFromImageBytes(bytes) : null;
7296
+ }
7297
+ if (!source || typeof source !== "object") return null;
7298
+ const record = source;
7299
+ const rawData = record.data;
7300
+ const mediaType = record.mediaType ?? record.media_type;
7301
+ const rawDataDimensions = rawData instanceof Uint8Array ? dimensionsFromImageBytes(rawData) : typeof rawData === "string" && typeof mediaType === "string" && mediaType.toLowerCase().startsWith("image/") ? dimensionsFromImageBytes(base64BytesPrefix(rawData) ?? new Uint8Array()) : null;
7302
+ return dimensionsFromRecord(record) ?? rawDataDimensions ?? dimensionsFromImageSource(record.url) ?? dimensionsFromImageSource(rawData);
7303
+ }
7304
+ function highDetailImageTokens(width, height) {
7305
+ let scaledWidth = width;
7306
+ let scaledHeight = height;
7307
+ const longest = Math.max(scaledWidth, scaledHeight);
7308
+ if (longest > IMAGE_HIGH_DETAIL_MAX_SIDE) {
7309
+ const scale = IMAGE_HIGH_DETAIL_MAX_SIDE / longest;
7310
+ scaledWidth *= scale;
7311
+ scaledHeight *= scale;
7312
+ }
7313
+ const shortest = Math.min(scaledWidth, scaledHeight);
7314
+ if (shortest > IMAGE_HIGH_DETAIL_TARGET_SHORT_SIDE) {
7315
+ const scale = IMAGE_HIGH_DETAIL_TARGET_SHORT_SIDE / shortest;
7316
+ scaledWidth *= scale;
7317
+ scaledHeight *= scale;
7318
+ }
7319
+ const tiles = Math.ceil(scaledWidth / IMAGE_HIGH_DETAIL_TILE_SIZE) * Math.ceil(scaledHeight / IMAGE_HIGH_DETAIL_TILE_SIZE);
7320
+ return Math.min(
7321
+ MAX_NATIVE_IMAGE_TOKENS,
7322
+ IMAGE_HIGH_DETAIL_BASE_TOKENS + IMAGE_HIGH_DETAIL_TILE_TOKENS * Math.max(1, tiles)
7323
+ );
7324
+ }
7325
+ function estimateNativeImageTokens(input) {
7326
+ const explicitWidth = finitePositiveInteger(input.width);
7327
+ const explicitHeight = finitePositiveInteger(input.height);
7328
+ const sourceDimensions = dimensionsFromImageSource(input.source);
7329
+ const width = explicitWidth ?? sourceDimensions?.[0] ?? null;
7330
+ const height = explicitHeight ?? sourceDimensions?.[1] ?? null;
7331
+ const detail = typeof input.detail === "string" && input.detail.length > 0 ? input.detail : "auto";
7332
+ if (detail === "low") {
7333
+ return { tokens: IMAGE_LOW_DETAIL_TOKENS, width, height, detail, reason: "dimensions" };
7334
+ }
7335
+ if (!width || !height) {
7336
+ return {
7337
+ tokens: UNKNOWN_IMAGE_TOKENS,
7338
+ width: null,
7339
+ height: null,
7340
+ detail,
7341
+ reason: "bounded_fallback"
7342
+ };
7343
+ }
7344
+ return {
7345
+ tokens: highDetailImageTokens(width, height),
7346
+ width,
7347
+ height,
7348
+ detail,
7349
+ reason: "dimensions"
7350
+ };
7351
+ }
7352
+ function imageDescriptor(record) {
7353
+ const type = typeof record.type === "string" ? record.type : "";
7354
+ if (!(/* @__PURE__ */ new Set(["input_image", "image_url", "image", "computer_screenshot"])).has(type)) {
7355
+ return null;
7356
+ }
7357
+ const imageUrl = record.image_url;
7358
+ const nestedImageUrl = imageUrl && typeof imageUrl === "object" ? imageUrl.url : imageUrl;
7359
+ const source = record.image ?? record.imageUrl ?? nestedImageUrl ?? record.data ?? record.url ?? record.fileId ?? record.file_id ?? record.artifact ?? record.artifactReference;
7360
+ const nestedDetail = imageUrl && typeof imageUrl === "object" ? imageUrl.detail : void 0;
7361
+ const dimensions = dimensionsFromRecord(record) ?? (source && typeof source === "object" ? dimensionsFromRecord(source) : null);
7362
+ return {
7363
+ source,
7364
+ detail: typeof record.detail === "string" ? record.detail : typeof nestedDetail === "string" ? nestedDetail : "auto",
7365
+ width: dimensions?.[0] ?? null,
7366
+ height: dimensions?.[1] ?? null
7367
+ };
7368
+ }
7369
+ function projectNativeImages(value, seen) {
7370
+ if (!value || typeof value !== "object") {
7371
+ return { value, imageTokens: 0, imageCount: 0, imageFallbackCount: 0 };
7372
+ }
7373
+ if (seen.has(value)) {
7374
+ return { value: "[circular]", imageTokens: 0, imageCount: 0, imageFallbackCount: 0 };
7375
+ }
7376
+ seen.add(value);
7377
+ if (Array.isArray(value)) {
7378
+ let imageTokens2 = 0;
7379
+ let imageCount2 = 0;
7380
+ let imageFallbackCount2 = 0;
7381
+ const projected2 = value.map((entry) => {
7382
+ const result = projectNativeImages(entry, seen);
7383
+ imageTokens2 += result.imageTokens;
7384
+ imageCount2 += result.imageCount;
7385
+ imageFallbackCount2 += result.imageFallbackCount;
7386
+ return result.value;
7387
+ });
7388
+ seen.delete(value);
7389
+ return { value: projected2, imageTokens: imageTokens2, imageCount: imageCount2, imageFallbackCount: imageFallbackCount2 };
7390
+ }
7391
+ const record = value;
7392
+ const descriptor = imageDescriptor(record);
7393
+ if (descriptor) {
7394
+ const estimate = estimateNativeImageTokens(descriptor);
7395
+ const projected2 = {};
7396
+ const payloadKeys = /* @__PURE__ */ new Set([
7397
+ "image",
7398
+ "image_url",
7399
+ "imageUrl",
7400
+ "data",
7401
+ "url",
7402
+ "fileId",
7403
+ "file_id",
7404
+ "artifact",
7405
+ "artifactReference"
7406
+ ]);
7407
+ for (const [key, entry] of Object.entries(record)) {
7408
+ projected2[key] = payloadKeys.has(key) ? "[native image]" : entry;
7409
+ }
7410
+ projected2.image_estimate = {
7411
+ width: estimate.width,
7412
+ height: estimate.height,
7413
+ detail: estimate.detail,
7414
+ reason: estimate.reason
7415
+ };
7416
+ seen.delete(value);
7417
+ return {
7418
+ value: projected2,
7419
+ imageTokens: estimate.tokens,
7420
+ imageCount: 1,
7421
+ imageFallbackCount: estimate.reason === "bounded_fallback" ? 1 : 0
7422
+ };
7423
+ }
7424
+ let imageTokens = 0;
7425
+ let imageCount = 0;
7426
+ let imageFallbackCount = 0;
7427
+ const projected = {};
7428
+ for (const [key, entry] of Object.entries(record)) {
7429
+ const result = projectNativeImages(entry, seen);
7430
+ projected[key] = result.value;
7431
+ imageTokens += result.imageTokens;
7432
+ imageCount += result.imageCount;
7433
+ imageFallbackCount += result.imageFallbackCount;
7434
+ }
7435
+ seen.delete(value);
7436
+ return { value: projected, imageTokens, imageCount, imageFallbackCount };
7437
+ }
7438
+ function estimateOpaqueEncryptedModelVisibleBytes(encodedLen) {
7439
+ const length = Math.max(0, Math.floor(encodedLen));
7440
+ return Math.max(0, Math.floor(length * 3 / 4) - 650);
7441
+ }
7442
+ function estimateOpaqueEncryptedTokens(encodedLen) {
7443
+ const bytes = estimateOpaqueEncryptedModelVisibleBytes(encodedLen);
7444
+ return bytes === 0 ? 0 : Math.ceil(bytes / 4);
7445
+ }
7446
+ function opaqueEncryptedContentLength(item) {
7447
+ if (!item || typeof item !== "object") return null;
7448
+ const record = item;
7449
+ const type = typeof record.type === "string" ? record.type : "";
7450
+ if ((type === "compaction" || type === "context_compaction" || type === "reasoning") && typeof record.encrypted_content === "string" && record.encrypted_content.length > 0) {
7451
+ return record.encrypted_content.length;
7452
+ }
7453
+ if (type === "reasoning") {
7454
+ const providerData = record.providerData && typeof record.providerData === "object" ? record.providerData : null;
7455
+ const nested = providerData && typeof providerData.encrypted_content === "string" ? providerData.encrypted_content : providerData && typeof providerData.encryptedContent === "string" ? providerData.encryptedContent : null;
7456
+ if (nested && nested.length > 0) return nested.length;
7457
+ }
7458
+ return null;
7459
+ }
7460
+ function estimateItemTokenBreakdown(item) {
7461
+ const opaqueLen = opaqueEncryptedContentLength(item);
7462
+ if (opaqueLen !== null) {
7463
+ const textTokens2 = estimateOpaqueEncryptedTokens(opaqueLen);
7464
+ return {
7465
+ totalTokens: textTokens2,
7466
+ textTokens: textTokens2,
7467
+ imageTokens: 0,
7468
+ imageCount: 0,
7469
+ imageFallbackCount: 0
7470
+ };
7471
+ }
7472
+ const projected = projectNativeImages(item, /* @__PURE__ */ new WeakSet());
7240
7473
  let text;
7241
7474
  try {
7242
- text = JSON.stringify(item);
7475
+ text = JSON.stringify(projected.value);
7243
7476
  } catch {
7244
- text = String(item);
7477
+ text = String(projected.value);
7245
7478
  }
7246
- return estimateTextTokens(text);
7479
+ const textTokens = estimateTextTokens(text);
7480
+ return {
7481
+ totalTokens: textTokens + projected.imageTokens,
7482
+ textTokens,
7483
+ imageTokens: projected.imageTokens,
7484
+ imageCount: projected.imageCount,
7485
+ imageFallbackCount: projected.imageFallbackCount
7486
+ };
7487
+ }
7488
+ function estimateItemTokens(item) {
7489
+ return estimateItemTokenBreakdown(item).totalTokens;
7247
7490
  }
7248
7491
  function estimateTokens(items) {
7249
7492
  let total = 0;
@@ -7252,6 +7495,24 @@ function estimateTokens(items) {
7252
7495
  }
7253
7496
  return total;
7254
7497
  }
7498
+ function estimateTokensBreakdown(items) {
7499
+ const total = {
7500
+ totalTokens: 0,
7501
+ textTokens: 0,
7502
+ imageTokens: 0,
7503
+ imageCount: 0,
7504
+ imageFallbackCount: 0
7505
+ };
7506
+ for (const item of items) {
7507
+ const estimate = estimateItemTokenBreakdown(item);
7508
+ total.totalTokens += estimate.totalTokens;
7509
+ total.textTokens += estimate.textTokens;
7510
+ total.imageTokens += estimate.imageTokens;
7511
+ total.imageCount += estimate.imageCount;
7512
+ total.imageFallbackCount += estimate.imageFallbackCount;
7513
+ }
7514
+ return total;
7515
+ }
7255
7516
  function estimateSerializedValueTokens(value) {
7256
7517
  let serialized;
7257
7518
  try {
@@ -7262,7 +7523,8 @@ function estimateSerializedValueTokens(value) {
7262
7523
  return estimateTextTokens(serialized ?? "");
7263
7524
  }
7264
7525
  function estimateCompleteModelInput(input) {
7265
- const inputTokens = estimateTokens(input.current.input);
7526
+ const inputEstimate = estimateTokensBreakdown(input.current.input);
7527
+ const inputTokens = inputEstimate.totalTokens;
7266
7528
  const instructionsTokens = input.current.instructionsTokens;
7267
7529
  const toolSchemaTokens = input.current.toolSchemaTokens;
7268
7530
  if (!input.provider || !input.providerRequestFootprint || input.provider.totalTokens <= 0) {
@@ -7270,6 +7532,10 @@ function estimateCompleteModelInput(input) {
7270
7532
  tokens: inputTokens + instructionsTokens + toolSchemaTokens,
7271
7533
  source: "complete_estimate",
7272
7534
  inputTokens,
7535
+ inputTextTokens: inputEstimate.textTokens,
7536
+ inputImageTokens: inputEstimate.imageTokens,
7537
+ inputImageCount: inputEstimate.imageCount,
7538
+ inputImageFallbackCount: inputEstimate.imageFallbackCount,
7273
7539
  instructionsTokens,
7274
7540
  toolSchemaTokens,
7275
7541
  appendedAfterModelTokens: 0
@@ -7289,6 +7555,10 @@ function estimateCompleteModelInput(input) {
7289
7555
  tokens: input.provider.totalTokens + appendedAfterModelTokens + instructionGrowth + toolSchemaGrowth,
7290
7556
  source: "provider_plus_local",
7291
7557
  inputTokens,
7558
+ inputTextTokens: inputEstimate.textTokens,
7559
+ inputImageTokens: inputEstimate.imageTokens,
7560
+ inputImageCount: inputEstimate.imageCount,
7561
+ inputImageFallbackCount: inputEstimate.imageFallbackCount,
7292
7562
  instructionsTokens,
7293
7563
  toolSchemaTokens,
7294
7564
  appendedAfterModelTokens
@@ -7514,6 +7784,66 @@ function buildCompactionReplacementHistory(items, summaryBody) {
7514
7784
  history.push(buildSummaryItem(summaryBody));
7515
7785
  return history;
7516
7786
  }
7787
+ function isRemoteCompactionItem(item) {
7788
+ if (!item || typeof item !== "object") return false;
7789
+ const record = item;
7790
+ return record.type === "compaction" && typeof record.encrypted_content === "string" && record.encrypted_content.length > 0;
7791
+ }
7792
+ function isRetainedRemoteV2Message(item) {
7793
+ if (isCompactionSummary(item) || itemType2(item) === "compaction") return false;
7794
+ const role = itemRole(item);
7795
+ return itemType2(item) === "message" && (role === "user" || role === "developer");
7796
+ }
7797
+ function buildRemoteV2ReplacementHistory(items, compactionItem) {
7798
+ if (!isRemoteCompactionItem(compactionItem)) {
7799
+ throw new EmptyCompactionSummaryError({ stage: "remote_v2_compaction_item" });
7800
+ }
7801
+ const retainedReversed = [];
7802
+ let remaining = REMOTE_V2_RETAINED_MESSAGE_TOKEN_BUDGET;
7803
+ for (let index = items.length - 1; index >= 0 && remaining > 0; index -= 1) {
7804
+ const item = items[index];
7805
+ if (!isRetainedRemoteV2Message(item)) continue;
7806
+ const textTokens = estimateTextTokens(messageText(item));
7807
+ retainedReversed.push(compactMessageToTokenBudget(item, remaining));
7808
+ if (textTokens > remaining) {
7809
+ remaining = 0;
7810
+ break;
7811
+ }
7812
+ remaining -= textTokens;
7813
+ }
7814
+ const history = retainedReversed.reverse();
7815
+ history.push({
7816
+ type: "compaction",
7817
+ encrypted_content: compactionItem.encrypted_content,
7818
+ ...typeof compactionItem.summary === "string" ? { summary: compactionItem.summary } : {}
7819
+ });
7820
+ return history;
7821
+ }
7822
+ function buildRemoteCompactionV2PromptInput(items) {
7823
+ return [
7824
+ ...items,
7825
+ {
7826
+ type: "unknown",
7827
+ providerData: { type: "compaction_trigger" }
7828
+ }
7829
+ ];
7830
+ }
7831
+ function extractRemoteCompactionV2OutputItem(response) {
7832
+ if (!response || typeof response !== "object") {
7833
+ throw new EmptyCompactionSummaryError({ stage: "remote_v2_extract", reason: "no_response" });
7834
+ }
7835
+ const record = response;
7836
+ const output = Array.isArray(record.output) ? record.output : [];
7837
+ const compactionItems = output.filter(isRemoteCompactionItem);
7838
+ if (compactionItems.length !== 1) {
7839
+ throw new EmptyCompactionSummaryError({
7840
+ stage: "remote_v2_extract",
7841
+ reason: "expected_exactly_one_compaction",
7842
+ found: compactionItems.length
7843
+ });
7844
+ }
7845
+ return compactionItems[0];
7846
+ }
7517
7847
  function compactionReplacementFingerprint(items) {
7518
7848
  const serialized = JSON.stringify(canonicalJsonValue(items));
7519
7849
  return createHash("sha256").update(serialized, "utf8").digest("hex");
@@ -8229,11 +8559,6 @@ function renderImageForTextTransport(output) {
8229
8559
  const mediaType = typeof image.mediaType === "string" ? image.mediaType : "application/octet-stream";
8230
8560
  return `data:${mediaType};base64,${Buffer.from(image.data).toString("base64")}`;
8231
8561
  }
8232
- function supportsStructuredToolOutputTransport(modelInstance) {
8233
- if (!modelInstance) return false;
8234
- const constructorName = typeof modelInstance === "object" && modelInstance && typeof modelInstance.constructor === "function" ? modelInstance.constructor.name ?? "" : "";
8235
- return !constructorName.includes("ChatCompletions");
8236
- }
8237
8562
  var COMPUTER_READ_ONLY_MESSAGE = "computer-use is read-only for this session \u2014 click, double_click, move, scroll, type, keypress, and drag are disabled. Call computer_screenshot to observe the desktop.";
8238
8563
  var COORD_PROPS = {
8239
8564
  x: {
@@ -8449,28 +8774,14 @@ var ComputerUseCapability = class extends Capability {
8449
8774
  this.args.needsApproval,
8450
8775
  true
8451
8776
  );
8777
+ case "disabled":
8452
8778
  case "function-text":
8453
- return computerFunctionTools(
8454
- computer,
8455
- this.args.readOnly ?? false,
8456
- this.args.needsApproval,
8457
- false
8458
- );
8459
8779
  case void 0:
8460
- break;
8461
- }
8462
- if (supportsStructuredToolOutputTransport(this._modelInstance)) {
8463
- return [this.hostedComputerTool(computer)];
8780
+ return [];
8464
8781
  }
8465
- return computerFunctionTools(
8466
- computer,
8467
- this.args.readOnly ?? false,
8468
- this.args.needsApproval,
8469
- this.args.imageFunctionResults ?? false
8470
- );
8782
+ return [];
8471
8783
  }
8472
- /** The single HOSTED `computer_use_preview` tool bound to `computer` — identical
8473
- * construction for the explicit "hosted" mode and the legacy structured-sniff path. */
8784
+ /** The single HOSTED `computer_use_preview` tool bound to `computer`. */
8474
8785
  hostedComputerTool(computer) {
8475
8786
  return computerTool({
8476
8787
  computer,
@@ -9323,6 +9634,50 @@ async function summarizeForCompaction(settings, input, options = {}) {
9323
9634
  }
9324
9635
  return summary;
9325
9636
  }
9637
+ async function requestRemoteCompactionV2(settings, input, options) {
9638
+ const promptInput = buildRemoteCompactionV2PromptInput(input);
9639
+ const request = {
9640
+ systemInstructions: "",
9641
+ input: promptInput,
9642
+ modelSettings: {
9643
+ // Azure rejects store:false; Codex transport enforces store:false itself.
9644
+ ...settings.openaiProvider === "azure" ? {} : { store: false },
9645
+ ...options.promptCacheKey ? { providerData: { prompt_cache_key: options.promptCacheKey } } : {}
9646
+ },
9647
+ tools: [],
9648
+ toolsExplicitlyProvided: true,
9649
+ outputType: "text",
9650
+ handoffs: [],
9651
+ tracing: false
9652
+ };
9653
+ let response;
9654
+ try {
9655
+ response = await new CompactionResponsesModel(options.client, options.model).fetchResponse(
9656
+ request
9657
+ );
9658
+ } catch (error) {
9659
+ throw new CompactionProviderResponseError(compactionProviderFailureDiagnostics(error), error);
9660
+ }
9661
+ const usage = modelResponseUsageFromResponse(response);
9662
+ if (usage) {
9663
+ await options.onUsage?.(usage);
9664
+ }
9665
+ if (isFailedCompactionProviderResponse(response)) {
9666
+ throw new CompactionProviderResponseError(compactionProviderFailureDiagnostics(response));
9667
+ }
9668
+ try {
9669
+ return extractRemoteCompactionV2OutputItem(response);
9670
+ } catch (error) {
9671
+ if (error instanceof EmptyCompactionSummaryError) {
9672
+ throw new EmptyCompactionSummaryError({
9673
+ ...compactionResponseDiagnostics(response, ""),
9674
+ ...error.diagnostics,
9675
+ stage: "remote_v2_extract"
9676
+ });
9677
+ }
9678
+ throw error;
9679
+ }
9680
+ }
9326
9681
  function isFailedCompactionProviderResponse(response) {
9327
9682
  if (!response || typeof response !== "object") return false;
9328
9683
  const record = response;
@@ -9622,9 +9977,11 @@ function buildOpenGeniAgent(settings, resources, options = {}) {
9622
9977
  }
9623
9978
  const hostedWebSearch = options.hostedWebSearch ?? settings.webSearchEnabled;
9624
9979
  const encryptedReasoning = options.encryptedReasoning ?? settings.openaiReasoningEncryptedContent;
9980
+ const serviceTier = options.serviceTier;
9625
9981
  const providerData = {
9626
9982
  ...encryptedReasoning ? { include: ["reasoning.encrypted_content"] } : {},
9627
- ...options.promptCacheKey ? { prompt_cache_key: options.promptCacheKey } : {}
9983
+ ...options.promptCacheKey ? { prompt_cache_key: options.promptCacheKey } : {},
9984
+ ...serviceTier ? { service_tier: serviceTier } : {}
9628
9985
  };
9629
9986
  const hostedTools = hostedWebSearch ? [webSearchTool()] : [];
9630
9987
  const humanInputTool = tool({
@@ -9943,24 +10300,12 @@ function buildAgentCapabilities(settings, packSkills, options = {}) {
9943
10300
  );
9944
10301
  }
9945
10302
  if (settings.computerUseEnabled && settings.sandboxDesktopEnabled && desktopCapableBackend(settings.sandboxBackend)) {
9946
- const explicitMode = options.computerToolMode;
9947
10303
  const computerCapability = computerUse({
9948
10304
  dimensions: [settings.streamResolutionWidth, settings.streamResolutionHeight],
9949
10305
  readOnly: settings.computerUseReadOnly,
9950
10306
  ...options.onComputerUseReady ? { onReady: options.onComputerUseReady } : {},
9951
- ...explicitMode ? { toolMode: explicitMode } : (
9952
- // Legacy (no explicit mode): on the codex path the function tools deliver
9953
- // screenshots as a real image the model can see. The ChatGPT/Codex backend
9954
- // rejects HOSTED tool types but DOES accept `input_image` content items inside a
9955
- // `function_call_output` (proven by openai/codex codex-rs, whose view_image tool
9956
- // ships exactly that shape) — so a structured image tool result is seen, where a
9957
- // text data-URL would be unreadable.
9958
- options.structuredToolTransport === false ? { imageFunctionResults: true } : {}
9959
- )
10307
+ toolMode: options.computerToolMode ?? "disabled"
9960
10308
  });
9961
- if (!explicitMode && options.structuredToolTransport === false) {
9962
- neutralizeStructuredToolTransport(computerCapability);
9963
- }
9964
10309
  caps.push(computerCapability);
9965
10310
  }
9966
10311
  if (toolCancellation) {
@@ -10371,16 +10716,20 @@ function parseWwwAuthenticate(header) {
10371
10716
  ...params.resource ? { resource: params.resource } : {}
10372
10717
  };
10373
10718
  }
10374
- var MCP_AUTH_NEEDED_ERROR_CODE = -32001;
10375
- var MCP_AUTH_NEEDED_MESSAGE = "Authentication required - a connection link was posted to the session.";
10719
+ var MCP_AUTH_NEEDED_ERROR = {
10720
+ // OpenGeni application-defined JSON-RPC code. Keep this positive so it cannot
10721
+ // collide with MCP SDK transport errors such as RequestTimeout (-32001).
10722
+ code: 40101,
10723
+ message: "Authentication required - a connection link was posted to the session."
10724
+ };
10376
10725
  function mcpToolAuthNeededResponse(id) {
10377
10726
  return new Response(
10378
10727
  JSON.stringify({
10379
10728
  jsonrpc: "2.0",
10380
10729
  id: id ?? null,
10381
10730
  error: {
10382
- code: MCP_AUTH_NEEDED_ERROR_CODE,
10383
- message: MCP_AUTH_NEEDED_MESSAGE
10731
+ code: MCP_AUTH_NEEDED_ERROR.code,
10732
+ message: MCP_AUTH_NEEDED_ERROR.message
10384
10733
  }
10385
10734
  }),
10386
10735
  {
@@ -10394,7 +10743,7 @@ function isAuthNeededMcpError(error) {
10394
10743
  return false;
10395
10744
  }
10396
10745
  const code = error.code;
10397
- return code === MCP_AUTH_NEEDED_ERROR_CODE || error.message.includes(MCP_AUTH_NEEDED_MESSAGE);
10746
+ return code === MCP_AUTH_NEEDED_ERROR.code && (error.message === MCP_AUTH_NEEDED_ERROR.message || error.message === `MCP error ${MCP_AUTH_NEEDED_ERROR.code}: ${MCP_AUTH_NEEDED_ERROR.message}`);
10398
10747
  }
10399
10748
  function mcpToolUnavailableMessage(reason) {
10400
10749
  return `This tool is unavailable for the rest of this turn (${reason}). Do not retry it \u2014 continue without it or use another approach.`;
@@ -10409,6 +10758,33 @@ function safeMcpErrorFields(error) {
10409
10758
  }
10410
10759
  return { errorClass, status };
10411
10760
  }
10761
+ function isMcpRequestTimeoutError(error, seen = /* @__PURE__ */ new WeakSet()) {
10762
+ if (!error || typeof error !== "object") {
10763
+ return false;
10764
+ }
10765
+ if (seen.has(error)) {
10766
+ return false;
10767
+ }
10768
+ seen.add(error);
10769
+ const record = error;
10770
+ if (record.mcpTransportFailureKind === "request_timeout") {
10771
+ return true;
10772
+ }
10773
+ const code = typeof record.code === "number" ? record.code : record.status;
10774
+ const message = typeof record.message === "string" ? record.message : "";
10775
+ const sdkTimeoutMessages = /* @__PURE__ */ new Set([
10776
+ "Request timed out",
10777
+ "MCP error -32001: Request timed out",
10778
+ "Maximum total timeout exceeded",
10779
+ "MCP error -32001: Maximum total timeout exceeded"
10780
+ ]);
10781
+ if (code === -32001 && sdkTimeoutMessages.has(message)) {
10782
+ return true;
10783
+ }
10784
+ return ["error", "cause", "response", "data"].some(
10785
+ (key) => isMcpRequestTimeoutError(record[key], seen)
10786
+ );
10787
+ }
10412
10788
  function safeMcpTransportError(error) {
10413
10789
  const fields = safeMcpErrorFields(error);
10414
10790
  const safeError = new Error(
@@ -10419,6 +10795,9 @@ function safeMcpTransportError(error) {
10419
10795
  safeError.status = fields.status;
10420
10796
  safeError.code = fields.status;
10421
10797
  }
10798
+ if (isMcpRequestTimeoutError(error)) {
10799
+ safeError.mcpTransportFailureKind = "request_timeout";
10800
+ }
10422
10801
  return safeError;
10423
10802
  }
10424
10803
  function safeMcpTransportLogger(serverId) {
@@ -10480,17 +10859,31 @@ async function signFirstPartyDelegatedBearer(settings, options) {
10480
10859
  if (!settings.delegationSecret || !options.accountId || !options.workspaceId) {
10481
10860
  return null;
10482
10861
  }
10862
+ const attemptClaims = [
10863
+ options.sessionId,
10864
+ options.turnId,
10865
+ options.attemptId,
10866
+ options.executionGeneration
10867
+ ];
10868
+ const hasAnyAttemptClaim = attemptClaims.some((claim) => claim !== void 0);
10869
+ const hasExactAttemptClaims = attemptClaims.every((claim) => claim !== void 0);
10870
+ if (hasAnyAttemptClaim && !hasExactAttemptClaims) {
10871
+ return null;
10872
+ }
10483
10873
  return await signDelegatedAccessToken(settings.delegationSecret, {
10484
10874
  accountId: options.accountId,
10485
10875
  workspaceId: options.workspaceId,
10486
10876
  subjectId: options.subjectId ?? "worker:first-party-mcp",
10487
10877
  ...options.subjectLabel ? { subjectLabel: options.subjectLabel } : {},
10488
10878
  permissions: options.firstPartyPermissions ?? [...DEFAULT_FIRST_PARTY_MCP_PERMISSIONS],
10879
+ principalKind: hasExactAttemptClaims ? "agent_attempt" : "service",
10489
10880
  firstPartyMcpTools: options.firstPartyTools ?? [...DEFAULT_FIRST_PARTY_MCP_TOOLS],
10490
- ...options.sessionId ? { sessionId: options.sessionId } : {},
10491
- ...options.turnId ? { turnId: options.turnId } : {},
10492
- ...options.attemptId ? { attemptId: options.attemptId } : {},
10493
- ...options.executionGeneration ? { executionGeneration: options.executionGeneration } : {},
10881
+ ...hasExactAttemptClaims ? {
10882
+ sessionId: options.sessionId,
10883
+ turnId: options.turnId,
10884
+ attemptId: options.attemptId,
10885
+ executionGeneration: options.executionGeneration
10886
+ } : {},
10494
10887
  exp: Math.floor(Date.now() / 1e3) + 60 * 60
10495
10888
  });
10496
10889
  }
@@ -10688,7 +11081,7 @@ var PrefixedMcpServer = class {
10688
11081
  if (isAuthNeededMcpError(error)) {
10689
11082
  return {
10690
11083
  isError: true,
10691
- content: [{ type: "text", text: MCP_AUTH_NEEDED_MESSAGE }]
11084
+ content: [{ type: "text", text: MCP_AUTH_NEEDED_ERROR.message }]
10692
11085
  };
10693
11086
  }
10694
11087
  if (this.bestEffort) {
@@ -10838,12 +11231,6 @@ var normalizeComputerCallsFilter = ({ modelData }) => ({
10838
11231
  modelData.input
10839
11232
  )
10840
11233
  });
10841
- var elideSupersededViewImagesFilter = ({ modelData }) => ({
10842
- ...modelData,
10843
- input: elideSupersededViewImagePairs(
10844
- modelData.input
10845
- )
10846
- });
10847
11234
  function boundModelToolOutputsFilterForSettings(settings) {
10848
11235
  return ({ modelData }) => ({
10849
11236
  ...modelData,
@@ -10927,7 +11314,6 @@ function composeCallModelInputFilters(filters) {
10927
11314
  function callModelInputFilterForSettings(settings, options = {}) {
10928
11315
  const filters = [
10929
11316
  normalizeComputerCallsFilter,
10930
- elideSupersededViewImagesFilter,
10931
11317
  boundModelToolOutputsFilterForSettings(settings)
10932
11318
  ];
10933
11319
  if (settings.openaiProviderItemIds === "strip") {
@@ -11614,6 +12000,39 @@ function normalizeToolOutputForEvent(output) {
11614
12000
  }
11615
12001
  return output;
11616
12002
  }
12003
+ function hostedWebSearchToolCallFromResponsesEvent(raw) {
12004
+ if (!raw || typeof raw !== "object") {
12005
+ return null;
12006
+ }
12007
+ const event = raw;
12008
+ const eventType = typeof event.type === "string" ? event.type : "";
12009
+ if (!((eventType === "response.output_item.added" || eventType === "response.output_item.done") && event.item?.type === "web_search_call")) {
12010
+ return null;
12011
+ }
12012
+ const item = event.item;
12013
+ const itemId = typeof item.id === "string" ? item.id : null;
12014
+ if (!itemId) {
12015
+ return null;
12016
+ }
12017
+ const status = typeof item.status === "string" ? item.status : eventType === "response.output_item.done" ? "completed" : "in_progress";
12018
+ const action = item.action ?? null;
12019
+ const { status: _status, ...providerData } = item;
12020
+ return {
12021
+ type: "agent.toolCall.created",
12022
+ payload: {
12023
+ id: itemId,
12024
+ name: "web_search_call",
12025
+ arguments: action,
12026
+ raw: {
12027
+ type: "hosted_tool_call",
12028
+ id: itemId,
12029
+ name: "web_search_call",
12030
+ status,
12031
+ providerData
12032
+ }
12033
+ }
12034
+ };
12035
+ }
11617
12036
  function normalizeSdkEvent(event) {
11618
12037
  const out = [];
11619
12038
  if (event.type === "raw_model_stream_event") {
@@ -11631,6 +12050,10 @@ function normalizeSdkEvent(event) {
11631
12050
  if (raw?.type === "response.reasoning_summary_text.delta" && typeof raw.delta === "string") {
11632
12051
  out.push({ type: "agent.reasoning.delta", payload: { text: raw.delta } });
11633
12052
  }
12053
+ const webSearch = hostedWebSearchToolCallFromResponsesEvent(raw);
12054
+ if (webSearch) {
12055
+ out.push(webSearch);
12056
+ }
11634
12057
  return out;
11635
12058
  }
11636
12059
  if (event.type === "agent_updated_stream_event") {
@@ -11710,11 +12133,47 @@ function modelResponseUsageFromResponse(response) {
11710
12133
  return null;
11711
12134
  }
11712
12135
  const responseId = typeof response?.id === "string" ? response.id : typeof response?.responseId === "string" ? response.responseId : void 0;
12136
+ const serviceTier = modelResponseServiceTierFromResponse(response);
11713
12137
  return {
11714
12138
  ...responseId ? { responseId } : {},
12139
+ ...serviceTier ? { serviceTier } : {},
11715
12140
  usage
11716
12141
  };
11717
12142
  }
12143
+ function modelResponseServiceTierFromSdkEvent(event) {
12144
+ if (event.type === "raw_model_stream_event") {
12145
+ const data = event.data;
12146
+ if (data?.type === "response_done") {
12147
+ return {
12148
+ source: "normalized",
12149
+ serviceTier: modelResponseServiceTierFromResponse(data.response)
12150
+ };
12151
+ }
12152
+ }
12153
+ if (isOpenAIResponsesRawModelStreamEvent(event)) {
12154
+ const raw = event.data?.event;
12155
+ if (raw?.type === "response.completed") {
12156
+ return {
12157
+ source: "provider",
12158
+ serviceTier: modelResponseServiceTierFromResponse(raw.response)
12159
+ };
12160
+ }
12161
+ }
12162
+ return null;
12163
+ }
12164
+ function modelResponseServiceTierFromResponse(response) {
12165
+ if (!response || typeof response !== "object") {
12166
+ return null;
12167
+ }
12168
+ const record = response;
12169
+ const direct = record.service_tier ?? record.serviceTier;
12170
+ if (typeof direct === "string" && direct.length > 0) {
12171
+ return direct;
12172
+ }
12173
+ const providerData = record.providerData && typeof record.providerData === "object" ? record.providerData : null;
12174
+ const nested = providerData?.service_tier ?? providerData?.serviceTier;
12175
+ return typeof nested === "string" && nested.length > 0 ? nested : null;
12176
+ }
11718
12177
  function modelResponseFromSdkEvent(event) {
11719
12178
  if (event.type === "raw_model_stream_event") {
11720
12179
  const data = event.data;
@@ -13648,6 +14107,7 @@ export {
13648
14107
  HUMAN_INPUT_TOOL_NAME,
13649
14108
  MAX_COMPACTION_THRESHOLD_RATIO,
13650
14109
  MAX_MODEL_USAGE_TOKEN_COUNT,
14110
+ MAX_NATIVE_IMAGE_TOKENS,
13651
14111
  MIN_COMPACTION_THRESHOLD_RATIO,
13652
14112
  MaxTurnsExceededError,
13653
14113
  MockAgentResponder,
@@ -13663,6 +14123,9 @@ export {
13663
14123
  OpenAIChatCompletionsModel,
13664
14124
  OpenAIResponsesModel,
13665
14125
  PROVIDER_REGISTRY,
14126
+ REMOTE_COMPACTION_V2_BETA_FEATURE,
14127
+ REMOTE_COMPACTION_V2_IMPLEMENTATION,
14128
+ REMOTE_V2_RETAINED_MESSAGE_TOKEN_BUDGET,
13666
14129
  REPOSITORY_DISCOVERY_LIMIT,
13667
14130
  RecordingError,
13668
14131
  RecordingUnavailableError,
@@ -13707,6 +14170,7 @@ export {
13707
14170
  TerminalServerUnsupportedError,
13708
14171
  ToolspaceTokenPathError,
13709
14172
  TurnSandboxCommandCancelledError,
14173
+ UNKNOWN_IMAGE_TOKENS,
13710
14174
  USER_MESSAGE_TRUNCATION_MARKER,
13711
14175
  WORKSPACE_ARCHIVE_DESCRIPTOR_VERSION,
13712
14176
  WorkspaceArchiveIntegrityError,
@@ -13737,6 +14201,8 @@ export {
13737
14201
  buildOpenAIClientFromSettings,
13738
14202
  buildOpenGeniAgent,
13739
14203
  buildProviderClient,
14204
+ buildRemoteCompactionV2PromptInput,
14205
+ buildRemoteV2ReplacementHistory,
13740
14206
  buildSelfhostedBackendSession,
13741
14207
  buildStreamUrl,
13742
14208
  buildSummaryItem,
@@ -13767,28 +14233,36 @@ export {
13767
14233
  decideCompaction,
13768
14234
  decideSelfhostedRetry,
13769
14235
  decodeModalSnapshotId,
14236
+ decodeNativeSnapshotRef,
13770
14237
  defaultSelfhostedRetryClock,
13771
- deletePriorPersistedSnapshot,
14238
+ deleteModalCheckpointSnapshot,
13772
14239
  deleteRecordingArtifacts,
14240
+ describeLegacyNativeSnapshotArchive,
14241
+ describeNativeSnapshotArchive,
13773
14242
  deserializeSandboxSessionStateEnvelope,
13774
14243
  desktopCapableBackend,
13775
14244
  drainingExhaustedError,
13776
14245
  drainingMessage,
13777
14246
  effectiveSkillSelectionsForAgent,
13778
14247
  elideSupersededViewImagePairs,
13779
- elideSupersededViewImagesFilter,
13780
14248
  ensureDisplayStack,
13781
14249
  ensureModalRegistryImage,
13782
14250
  ensureReadableStreamFrom,
13783
14251
  ensureTerminalServer,
13784
14252
  establishSandboxSessionFromEnvelope,
13785
14253
  estimateCompleteModelInput,
14254
+ estimateItemTokenBreakdown,
13786
14255
  estimateItemTokens,
14256
+ estimateNativeImageTokens,
14257
+ estimateOpaqueEncryptedModelVisibleBytes,
14258
+ estimateOpaqueEncryptedTokens,
13787
14259
  estimateSerializedValueTokens,
13788
14260
  estimateTokens,
14261
+ estimateTokensBreakdown,
13789
14262
  execDeadlineHint,
13790
14263
  exposeStreamPort,
13791
14264
  extForCodec,
14265
+ extractRemoteCompactionV2OutputItem,
13792
14266
  extractResponseOutputText,
13793
14267
  findCompactionNeededError,
13794
14268
  fingerprintSandboxWorkspace,
@@ -13798,12 +14272,16 @@ export {
13798
14272
  gitProviderTokenRefreshCommand,
13799
14273
  hasModelGeneratedItem,
13800
14274
  hasPersistableSandboxProviderIdentity,
14275
+ inspectModalSandboxLifecycle,
13801
14276
  inspectRecordingArtifact,
13802
14277
  isCompactionSummary,
13803
14278
  isExecSessionLostBanner,
14279
+ isMcpRequestTimeoutError,
13804
14280
  isProviderSandboxGoneDuringRoutedOperation,
13805
14281
  isProviderSandboxNotFoundError,
13806
14282
  isProviderSandboxTransientError,
14283
+ isRemoteCompactionItem,
14284
+ isRetainedRemoteV2Message,
13807
14285
  isSelfhostedProviderNotFoundError,
13808
14286
  isSkillLibraryEntryId,
13809
14287
  isUserMessage,
@@ -13820,7 +14298,9 @@ export {
13820
14298
  mintStreamToken,
13821
14299
  modalSandboxAttributionEnvironment,
13822
14300
  modalSandboxAttributionTags,
14301
+ modalSessionMatchesCheckpointProviderBinding,
13823
14302
  modelCallUsageTelemetry,
14303
+ modelResponseServiceTierFromSdkEvent,
13824
14304
  modelResponseUsageFromResponse,
13825
14305
  modelResponseUsageFromSdkEvent,
13826
14306
  modelUsageTokenCountOrNull,
@@ -13838,6 +14318,7 @@ export {
13838
14318
  oneShotGenesisTitleInputFilter,
13839
14319
  opAckSubject,
13840
14320
  opFrameSubject,
14321
+ opaqueEncryptedContentLength,
13841
14322
  parseExecBannerExitCode,
13842
14323
  parseExecBannerSessionId,
13843
14324
  parseExposedPorts,
@@ -13862,7 +14343,11 @@ export {
13862
14343
  repositoryCloneCommand,
13863
14344
  repositoryUsesSandboxClone,
13864
14345
  repositoryWorkspaceSkillPathsOption,
14346
+ requestRemoteCompactionV2,
13865
14347
  requirePersistableReplacementSandboxEnvelope,
14348
+ resolveModalCheckpointProviderBinding,
14349
+ resolveModalCheckpointProviderBindingForLiveSandbox,
14350
+ resolveModalCheckpointProviderBindingForSession,
13866
14351
  resolveTurnModel,
13867
14352
  restoredSandboxSessionStateFromEntry,
13868
14353
  rigInstructions,
@@ -13877,6 +14362,7 @@ export {
13877
14362
  runRigSetupHook,
13878
14363
  runToolspaceTokenSeedHook,
13879
14364
  runWithToolCallCorrelation,
14365
+ safeMcpTransportError,
13880
14366
  sandboxCommandExitCode,
13881
14367
  sandboxCommandOutput,
13882
14368
  sandboxCommandStillRunning,