@opengeni/runtime 6.5.2-canary.41607687019001 → 6.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.
- package/dist/agent-instructions/modules/subagents.d.ts +4 -1
- package/dist/agent-instructions/tool-availability.d.ts +12 -0
- package/dist/agent-instructions/types.d.ts +16 -2
- package/dist/assets/codemode-client.json +1 -1
- package/dist/{chunk-HYSMFK7K.js → chunk-3MNZZ2B4.js} +34 -12
- package/dist/chunk-3MNZZ2B4.js.map +1 -0
- package/dist/{chunk-PZPM6Z62.js → chunk-77NQGL66.js} +4 -2
- package/dist/chunk-77NQGL66.js.map +1 -0
- package/dist/{chunk-AE7DWNDQ.js → chunk-FNAYH3SN.js} +572 -278
- package/dist/chunk-FNAYH3SN.js.map +1 -0
- package/dist/{chunk-RYNEQOTX.js → chunk-GFAFQMZV.js} +3 -3
- package/dist/{chunk-ZNFEE7S5.js → chunk-JF5UTPEU.js} +2 -2
- package/dist/{chunk-GRNURW7Y.js → chunk-JY5NSZ37.js} +294 -36
- package/dist/chunk-JY5NSZ37.js.map +1 -0
- package/dist/{chunk-XXCIHKHP.js → chunk-OAW6MMSY.js} +3 -3
- package/dist/{chunk-F62XZWUW.js → chunk-RZJXTSVA.js} +2 -2
- package/dist/command-completion-delivery.d.ts +130 -0
- package/dist/gmail-rest-mcp.js +3 -3
- package/dist/google-calendar-rest-mcp.js +2 -2
- package/dist/index.d.ts +8 -0
- package/dist/index.js +20 -8
- package/dist/interaction-tools.d.ts +9 -0
- package/dist/lazy-tool-transport.d.ts +2 -0
- package/dist/metrics.d.ts +9 -0
- package/dist/model-call.js +1 -1
- package/dist/provider-history-adapter.d.ts +6 -0
- package/dist/provider-invalid-request.d.ts +16 -0
- package/dist/provider-tool-names.d.ts +54 -0
- package/dist/sandbox/index.js +2 -2
- package/dist/sandbox/providers/modal-command-router-wire.d.ts +2 -0
- package/dist/slack-rest-mcp.js +3 -3
- package/dist/workspace-tool-gateway.js +8 -8
- package/package.json +16 -17
- package/src/agent-instructions/PROMPT_CHANGELOG.md +75 -3
- package/src/agent-instructions/modules/subagents.ts +43 -30
- package/src/agent-instructions/runtime-mechanics.ts +20 -2
- package/src/agent-instructions/tool-availability.ts +23 -2
- package/src/agent-instructions/types.ts +16 -2
- package/src/anthropic-messages.ts +4 -1
- package/src/command-completion-delivery.ts +388 -0
- package/src/index.ts +47 -7
- package/src/interaction-tools.ts +19 -2
- package/src/lazy-tool-transport.ts +48 -2
- package/src/metrics.ts +5 -0
- package/src/model-provider-client.ts +20 -0
- package/src/model-provider-routing.ts +2 -0
- package/src/provider-history-adapter.ts +23 -2
- package/src/provider-invalid-request.ts +77 -0
- package/src/provider-tool-names.ts +340 -0
- package/src/sandbox/providers/modal-command-control.ts +2 -1
- package/src/sandbox/providers/modal-command-router-wire.ts +3 -1
- package/src/sandbox/providers/modal-command-session.ts +54 -11
- package/dist/chunk-AE7DWNDQ.js.map +0 -1
- package/dist/chunk-GRNURW7Y.js.map +0 -1
- package/dist/chunk-HYSMFK7K.js.map +0 -1
- package/dist/chunk-PZPM6Z62.js.map +0 -1
- /package/dist/{chunk-RYNEQOTX.js.map → chunk-GFAFQMZV.js.map} +0 -0
- /package/dist/{chunk-ZNFEE7S5.js.map → chunk-JF5UTPEU.js.map} +0 -0
- /package/dist/{chunk-XXCIHKHP.js.map → chunk-OAW6MMSY.js.map} +0 -0
- /package/dist/{chunk-F62XZWUW.js.map → chunk-RZJXTSVA.js.map} +0 -0
|
@@ -47,14 +47,14 @@ function toolCallIdFromSdkItem(item) {
|
|
|
47
47
|
if (!item || typeof item !== "object" || Array.isArray(item)) {
|
|
48
48
|
return void 0;
|
|
49
49
|
}
|
|
50
|
-
const
|
|
51
|
-
if (typeof
|
|
52
|
-
return
|
|
50
|
+
const record4 = item;
|
|
51
|
+
if (typeof record4.callId === "string" && record4.callId.length > 0) {
|
|
52
|
+
return record4.callId;
|
|
53
53
|
}
|
|
54
|
-
if (typeof
|
|
55
|
-
return
|
|
54
|
+
if (typeof record4.call_id === "string" && record4.call_id.length > 0) {
|
|
55
|
+
return record4.call_id;
|
|
56
56
|
}
|
|
57
|
-
const provider =
|
|
57
|
+
const provider = record4.providerData;
|
|
58
58
|
if (provider && typeof provider === "object") {
|
|
59
59
|
if (typeof provider.call_id === "string" && provider.call_id.length > 0) {
|
|
60
60
|
return provider.call_id;
|
|
@@ -363,12 +363,12 @@ function projectRejectedProviderArtifactsFromSerializedRunState(serialized) {
|
|
|
363
363
|
}
|
|
364
364
|
function hasOpaqueProviderArtifact(item) {
|
|
365
365
|
if (!item || typeof item !== "object") return false;
|
|
366
|
-
const
|
|
367
|
-
if (
|
|
368
|
-
if (typeof
|
|
366
|
+
const record4 = item;
|
|
367
|
+
if (record4.type !== "reasoning" && record4.type !== "compaction") return false;
|
|
368
|
+
if (typeof record4.encrypted_content === "string" && record4.encrypted_content.length > 0) {
|
|
369
369
|
return true;
|
|
370
370
|
}
|
|
371
|
-
const providerData =
|
|
371
|
+
const providerData = record4.providerData && typeof record4.providerData === "object" ? record4.providerData : null;
|
|
372
372
|
return Boolean(
|
|
373
373
|
providerData && (typeof providerData.encrypted_content === "string" && providerData.encrypted_content.length > 0 || typeof providerData.encryptedContent === "string" && providerData.encryptedContent.length > 0)
|
|
374
374
|
);
|
|
@@ -409,11 +409,11 @@ function normalizeComputerCallActions(items) {
|
|
|
409
409
|
}
|
|
410
410
|
function normalizeComputerCallAction(item) {
|
|
411
411
|
if (itemType(item) !== "computer_call") return item;
|
|
412
|
-
const
|
|
413
|
-
const hasAction =
|
|
414
|
-
const hasActions = Array.isArray(
|
|
412
|
+
const record4 = item;
|
|
413
|
+
const hasAction = record4.action !== void 0 && record4.action !== null;
|
|
414
|
+
const hasActions = Array.isArray(record4.actions) && record4.actions.length > 0;
|
|
415
415
|
if (!hasAction || !hasActions) return item;
|
|
416
|
-
const { action: _droppedAction, ...rest } =
|
|
416
|
+
const { action: _droppedAction, ...rest } = record4;
|
|
417
417
|
return rest;
|
|
418
418
|
}
|
|
419
419
|
function rewriteComputerCallsToActionsOnly(body) {
|
|
@@ -429,22 +429,22 @@ function rewriteComputerCallsToActionsOnly(body) {
|
|
|
429
429
|
if (!item || typeof item !== "object") {
|
|
430
430
|
continue;
|
|
431
431
|
}
|
|
432
|
-
const
|
|
433
|
-
if (
|
|
432
|
+
const record4 = item;
|
|
433
|
+
if (record4.type !== "computer_call") {
|
|
434
434
|
continue;
|
|
435
435
|
}
|
|
436
|
-
const existingActions = Array.isArray(
|
|
437
|
-
const actions = existingActions ?? (
|
|
436
|
+
const existingActions = Array.isArray(record4.actions) && record4.actions.length > 0 ? record4.actions : void 0;
|
|
437
|
+
const actions = existingActions ?? (record4.action !== void 0 && record4.action !== null ? [record4.action] : void 0);
|
|
438
438
|
if (actions === void 0) {
|
|
439
439
|
continue;
|
|
440
440
|
}
|
|
441
|
-
const hadAction = "action" in
|
|
441
|
+
const hadAction = "action" in record4;
|
|
442
442
|
const actionsAlreadyExact = existingActions !== void 0 && !hadAction;
|
|
443
443
|
if (actionsAlreadyExact) {
|
|
444
444
|
continue;
|
|
445
445
|
}
|
|
446
|
-
delete
|
|
447
|
-
|
|
446
|
+
delete record4.action;
|
|
447
|
+
record4.actions = actions;
|
|
448
448
|
changed = true;
|
|
449
449
|
}
|
|
450
450
|
return changed;
|
|
@@ -462,11 +462,11 @@ function rewriteEmptyComputerCallOutputImageUrls(body) {
|
|
|
462
462
|
if (!item || typeof item !== "object") {
|
|
463
463
|
continue;
|
|
464
464
|
}
|
|
465
|
-
const
|
|
466
|
-
if (
|
|
465
|
+
const record4 = item;
|
|
466
|
+
if (record4.type !== "computer_call_output") {
|
|
467
467
|
continue;
|
|
468
468
|
}
|
|
469
|
-
const output =
|
|
469
|
+
const output = record4.output;
|
|
470
470
|
if (!output || typeof output !== "object") {
|
|
471
471
|
continue;
|
|
472
472
|
}
|
|
@@ -1223,13 +1223,13 @@ var MAX_NATIVE_IMAGE_TOKENS = 36e3;
|
|
|
1223
1223
|
function finitePositiveInteger(value) {
|
|
1224
1224
|
return typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.floor(value) : null;
|
|
1225
1225
|
}
|
|
1226
|
-
function dimensionsFromRecord(
|
|
1227
|
-
const width = finitePositiveInteger(
|
|
1228
|
-
const height = finitePositiveInteger(
|
|
1226
|
+
function dimensionsFromRecord(record4) {
|
|
1227
|
+
const width = finitePositiveInteger(record4.width);
|
|
1228
|
+
const height = finitePositiveInteger(record4.height);
|
|
1229
1229
|
if (width && height) return [width, height];
|
|
1230
|
-
if (Array.isArray(
|
|
1231
|
-
const dimensionsWidth = finitePositiveInteger(
|
|
1232
|
-
const dimensionsHeight = finitePositiveInteger(
|
|
1230
|
+
if (Array.isArray(record4.dimensions) && record4.dimensions.length >= 2) {
|
|
1231
|
+
const dimensionsWidth = finitePositiveInteger(record4.dimensions[0]);
|
|
1232
|
+
const dimensionsHeight = finitePositiveInteger(record4.dimensions[1]);
|
|
1233
1233
|
if (dimensionsWidth && dimensionsHeight) return [dimensionsWidth, dimensionsHeight];
|
|
1234
1234
|
}
|
|
1235
1235
|
return null;
|
|
@@ -1319,11 +1319,11 @@ function dimensionsFromImageSource(source) {
|
|
|
1319
1319
|
return bytes ? dimensionsFromImageBytes(bytes) : null;
|
|
1320
1320
|
}
|
|
1321
1321
|
if (!source || typeof source !== "object") return null;
|
|
1322
|
-
const
|
|
1323
|
-
const rawData =
|
|
1324
|
-
const mediaType =
|
|
1322
|
+
const record4 = source;
|
|
1323
|
+
const rawData = record4.data;
|
|
1324
|
+
const mediaType = record4.mediaType ?? record4.media_type;
|
|
1325
1325
|
const rawDataDimensions = rawData instanceof Uint8Array ? dimensionsFromImageBytes(rawData) : typeof rawData === "string" && typeof mediaType === "string" && mediaType.toLowerCase().startsWith("image/") ? dimensionsFromImageBytes(base64BytesPrefix(rawData) ?? new Uint8Array()) : null;
|
|
1326
|
-
return dimensionsFromRecord(
|
|
1326
|
+
return dimensionsFromRecord(record4) ?? rawDataDimensions ?? dimensionsFromImageSource(record4.url) ?? dimensionsFromImageSource(rawData);
|
|
1327
1327
|
}
|
|
1328
1328
|
function patchImageTokens(width, height) {
|
|
1329
1329
|
return Math.min(
|
|
@@ -1371,10 +1371,10 @@ function countModelInputImages(value) {
|
|
|
1371
1371
|
for (const entry of value) count2 += countModelInputImages(entry);
|
|
1372
1372
|
return count2;
|
|
1373
1373
|
}
|
|
1374
|
-
const
|
|
1375
|
-
if (typeof
|
|
1374
|
+
const record4 = value;
|
|
1375
|
+
if (typeof record4.type === "string" && NATIVE_IMAGE_PART_TYPES.has(record4.type)) return 1;
|
|
1376
1376
|
let count = 0;
|
|
1377
|
-
for (const [key, entry] of Object.entries(
|
|
1377
|
+
for (const [key, entry] of Object.entries(record4)) {
|
|
1378
1378
|
if (typeof entry === "string") {
|
|
1379
1379
|
if (key === "output" && entry.startsWith("data:image/")) count += 1;
|
|
1380
1380
|
} else {
|
|
@@ -1383,19 +1383,19 @@ function countModelInputImages(value) {
|
|
|
1383
1383
|
}
|
|
1384
1384
|
return count;
|
|
1385
1385
|
}
|
|
1386
|
-
function imageDescriptor(
|
|
1387
|
-
const type = typeof
|
|
1386
|
+
function imageDescriptor(record4) {
|
|
1387
|
+
const type = typeof record4.type === "string" ? record4.type : "";
|
|
1388
1388
|
if (!NATIVE_IMAGE_PART_TYPES.has(type)) {
|
|
1389
1389
|
return null;
|
|
1390
1390
|
}
|
|
1391
|
-
const imageUrl =
|
|
1391
|
+
const imageUrl = record4.image_url;
|
|
1392
1392
|
const nestedImageUrl = imageUrl && typeof imageUrl === "object" ? imageUrl.url : imageUrl;
|
|
1393
|
-
const source =
|
|
1393
|
+
const source = record4.image ?? record4.imageUrl ?? nestedImageUrl ?? record4.data ?? record4.url ?? record4.fileId ?? record4.file_id ?? record4.artifact ?? record4.artifactReference;
|
|
1394
1394
|
const nestedDetail = imageUrl && typeof imageUrl === "object" ? imageUrl.detail : void 0;
|
|
1395
|
-
const dimensions = dimensionsFromRecord(
|
|
1395
|
+
const dimensions = dimensionsFromRecord(record4) ?? (source && typeof source === "object" ? dimensionsFromRecord(source) : null);
|
|
1396
1396
|
return {
|
|
1397
1397
|
source,
|
|
1398
|
-
detail: typeof
|
|
1398
|
+
detail: typeof record4.detail === "string" ? record4.detail : typeof nestedDetail === "string" ? nestedDetail : "auto",
|
|
1399
1399
|
width: dimensions?.[0] ?? null,
|
|
1400
1400
|
height: dimensions?.[1] ?? null
|
|
1401
1401
|
};
|
|
@@ -1422,8 +1422,8 @@ function projectNativeImages(value, seen) {
|
|
|
1422
1422
|
seen.delete(value);
|
|
1423
1423
|
return { value: projected2, imageTokens: imageTokens2, imageCount: imageCount2, imageFallbackCount: imageFallbackCount2 };
|
|
1424
1424
|
}
|
|
1425
|
-
const
|
|
1426
|
-
const descriptor = imageDescriptor(
|
|
1425
|
+
const record4 = value;
|
|
1426
|
+
const descriptor = imageDescriptor(record4);
|
|
1427
1427
|
if (descriptor) {
|
|
1428
1428
|
const estimate = estimateNativeImageTokens(descriptor);
|
|
1429
1429
|
const projected2 = {};
|
|
@@ -1438,7 +1438,7 @@ function projectNativeImages(value, seen) {
|
|
|
1438
1438
|
"artifact",
|
|
1439
1439
|
"artifactReference"
|
|
1440
1440
|
]);
|
|
1441
|
-
for (const [key, entry] of Object.entries(
|
|
1441
|
+
for (const [key, entry] of Object.entries(record4)) {
|
|
1442
1442
|
projected2[key] = payloadKeys.has(key) ? "[native image]" : entry;
|
|
1443
1443
|
}
|
|
1444
1444
|
projected2.image_estimate = {
|
|
@@ -1459,7 +1459,7 @@ function projectNativeImages(value, seen) {
|
|
|
1459
1459
|
let imageCount = 0;
|
|
1460
1460
|
let imageFallbackCount = 0;
|
|
1461
1461
|
const projected = {};
|
|
1462
|
-
for (const [key, entry] of Object.entries(
|
|
1462
|
+
for (const [key, entry] of Object.entries(record4)) {
|
|
1463
1463
|
const result = projectNativeImages(entry, seen);
|
|
1464
1464
|
projected[key] = result.value;
|
|
1465
1465
|
imageTokens += result.imageTokens;
|
|
@@ -1479,13 +1479,13 @@ function estimateOpaqueEncryptedTokens(encodedLen) {
|
|
|
1479
1479
|
}
|
|
1480
1480
|
function opaqueEncryptedContentLength(item) {
|
|
1481
1481
|
if (!item || typeof item !== "object") return null;
|
|
1482
|
-
const
|
|
1483
|
-
const type = typeof
|
|
1484
|
-
if ((type === "compaction" || type === "context_compaction" || type === "reasoning") && typeof
|
|
1485
|
-
return
|
|
1482
|
+
const record4 = item;
|
|
1483
|
+
const type = typeof record4.type === "string" ? record4.type : "";
|
|
1484
|
+
if ((type === "compaction" || type === "context_compaction" || type === "reasoning") && typeof record4.encrypted_content === "string" && record4.encrypted_content.length > 0) {
|
|
1485
|
+
return record4.encrypted_content.length;
|
|
1486
1486
|
}
|
|
1487
1487
|
if (type === "reasoning") {
|
|
1488
|
-
const providerData =
|
|
1488
|
+
const providerData = record4.providerData && typeof record4.providerData === "object" ? record4.providerData : null;
|
|
1489
1489
|
const nested = providerData && typeof providerData.encrypted_content === "string" ? providerData.encrypted_content : providerData && typeof providerData.encryptedContent === "string" ? providerData.encryptedContent : null;
|
|
1490
1490
|
if (nested && nested.length > 0) return nested.length;
|
|
1491
1491
|
}
|
|
@@ -1775,8 +1775,8 @@ function findCompactionNeededError(error, seen = /* @__PURE__ */ new WeakSet())
|
|
|
1775
1775
|
return null;
|
|
1776
1776
|
}
|
|
1777
1777
|
seen.add(error);
|
|
1778
|
-
const
|
|
1779
|
-
return findCompactionNeededError(
|
|
1778
|
+
const record4 = error;
|
|
1779
|
+
return findCompactionNeededError(record4.cause, seen) ?? findCompactionNeededError(record4.error, seen);
|
|
1780
1780
|
}
|
|
1781
1781
|
function buildCompactionPromptInput(items) {
|
|
1782
1782
|
return [
|
|
@@ -1848,9 +1848,9 @@ function remoteCompactionShellOutputIsMinimal(output) {
|
|
|
1848
1848
|
if (!Array.isArray(output) || output.length !== 1) return false;
|
|
1849
1849
|
const result = output[0];
|
|
1850
1850
|
if (!result || typeof result !== "object" || Array.isArray(result)) return false;
|
|
1851
|
-
const
|
|
1852
|
-
const outcome =
|
|
1853
|
-
return
|
|
1851
|
+
const record4 = result;
|
|
1852
|
+
const outcome = record4.outcome;
|
|
1853
|
+
return record4.stdout === "" && record4.stderr === REMOTE_COMPACTION_TOOL_RESULT_OMISSION && outcome !== null && typeof outcome === "object" && !Array.isArray(outcome) && outcome.type === "exit" && outcome.exitCode === null && Object.keys(record4).length === 3 && Object.keys(outcome).length === 2;
|
|
1854
1854
|
}
|
|
1855
1855
|
function omitOpaqueArtifactsFromPortableCompactionHistory(items) {
|
|
1856
1856
|
let changed = false;
|
|
@@ -2141,8 +2141,8 @@ function rebuildAroundCheckpoint(items, checkpoint, options) {
|
|
|
2141
2141
|
}
|
|
2142
2142
|
function isRemoteCompactionItem(item) {
|
|
2143
2143
|
if (!item || typeof item !== "object") return false;
|
|
2144
|
-
const
|
|
2145
|
-
return
|
|
2144
|
+
const record4 = item;
|
|
2145
|
+
return record4.type === "compaction" && typeof record4.encrypted_content === "string" && record4.encrypted_content.length > 0;
|
|
2146
2146
|
}
|
|
2147
2147
|
function isRetainedRemoteV2Message(item) {
|
|
2148
2148
|
if (isCompactionSummary(item) || isAttachmentCatalog(item) || itemType2(item) === "compaction") {
|
|
@@ -2261,8 +2261,8 @@ function extractRemoteCompactionV2OutputItem(response) {
|
|
|
2261
2261
|
reason: "no_response"
|
|
2262
2262
|
});
|
|
2263
2263
|
}
|
|
2264
|
-
const
|
|
2265
|
-
const output = Array.isArray(
|
|
2264
|
+
const record4 = response;
|
|
2265
|
+
const output = Array.isArray(record4.output) ? record4.output : [];
|
|
2266
2266
|
const compactionItems = output.filter(isRemoteCompactionItem);
|
|
2267
2267
|
if (compactionItems.length !== 1) {
|
|
2268
2268
|
throw new EmptyCompactionSummaryError({
|
|
@@ -2402,12 +2402,12 @@ function messageText2(item) {
|
|
|
2402
2402
|
if (Array.isArray(content)) {
|
|
2403
2403
|
return content.map((part) => {
|
|
2404
2404
|
if (part && typeof part === "object") {
|
|
2405
|
-
const
|
|
2406
|
-
if (typeof
|
|
2407
|
-
return
|
|
2405
|
+
const record4 = part;
|
|
2406
|
+
if (typeof record4.text === "string") {
|
|
2407
|
+
return record4.text;
|
|
2408
2408
|
}
|
|
2409
|
-
if (typeof
|
|
2410
|
-
return
|
|
2409
|
+
if (typeof record4.content === "string") {
|
|
2410
|
+
return record4.content;
|
|
2411
2411
|
}
|
|
2412
2412
|
}
|
|
2413
2413
|
return "";
|
|
@@ -3211,11 +3211,11 @@ function mergeQueryParamsIntoURL(url, query) {
|
|
|
3211
3211
|
}
|
|
3212
3212
|
}
|
|
3213
3213
|
function ensureResponsesWebSocketPath(pathname) {
|
|
3214
|
-
const
|
|
3215
|
-
if (
|
|
3216
|
-
return
|
|
3214
|
+
const normalizedPath2 = pathname.replace(/\/+$/, "");
|
|
3215
|
+
if (normalizedPath2 === "/responses" || normalizedPath2.endsWith("/responses")) {
|
|
3216
|
+
return normalizedPath2;
|
|
3217
3217
|
}
|
|
3218
|
-
return `${
|
|
3218
|
+
return `${normalizedPath2}/responses`;
|
|
3219
3219
|
}
|
|
3220
3220
|
|
|
3221
3221
|
// ../../node_modules/.bun/@openai+agents-openai@0.14.3+933c5e7db4cd33c2/node_modules/@openai/agents-openai/dist/utils/providerData.mjs
|
|
@@ -4372,10 +4372,10 @@ function getProviderDataField(providerData, keys) {
|
|
|
4372
4372
|
if (!providerData || typeof providerData !== "object" || Array.isArray(providerData)) {
|
|
4373
4373
|
return void 0;
|
|
4374
4374
|
}
|
|
4375
|
-
const
|
|
4375
|
+
const record4 = providerData;
|
|
4376
4376
|
for (const key of keys) {
|
|
4377
|
-
if (typeof
|
|
4378
|
-
return
|
|
4377
|
+
if (typeof record4[key] !== "undefined") {
|
|
4378
|
+
return record4[key];
|
|
4379
4379
|
}
|
|
4380
4380
|
}
|
|
4381
4381
|
return void 0;
|
|
@@ -8010,11 +8010,11 @@ function stripConversationPersistenceMetadata(items) {
|
|
|
8010
8010
|
if (Array.isArray(item) || item === null || typeof item !== "object") {
|
|
8011
8011
|
return [item];
|
|
8012
8012
|
}
|
|
8013
|
-
const
|
|
8014
|
-
if (isUnpersistableReasoningItem(
|
|
8013
|
+
const record4 = item;
|
|
8014
|
+
if (isUnpersistableReasoningItem(record4)) {
|
|
8015
8015
|
return [];
|
|
8016
8016
|
}
|
|
8017
|
-
const { providerData: _providerData, provider_data: _provider_data, ...rest } =
|
|
8017
|
+
const { providerData: _providerData, provider_data: _provider_data, ...rest } = record4;
|
|
8018
8018
|
if (rest.type !== "reasoning") {
|
|
8019
8019
|
delete rest.id;
|
|
8020
8020
|
}
|
|
@@ -8028,11 +8028,11 @@ function stripAssistantReplayMetadata(item) {
|
|
|
8028
8028
|
if (Array.isArray(item) || item === null || typeof item !== "object") {
|
|
8029
8029
|
return item;
|
|
8030
8030
|
}
|
|
8031
|
-
const
|
|
8032
|
-
if (
|
|
8031
|
+
const record4 = item;
|
|
8032
|
+
if (record4.type !== "message" || record4.role !== "assistant") {
|
|
8033
8033
|
return item;
|
|
8034
8034
|
}
|
|
8035
|
-
const { id: _id, providerData, provider_data: _provider_data, ...rest } =
|
|
8035
|
+
const { id: _id, providerData, provider_data: _provider_data, ...rest } = record4;
|
|
8036
8036
|
if (typeof rest.phase === "undefined" && providerData && typeof providerData === "object" && !Array.isArray(providerData) && typeof providerData.phase !== "undefined") {
|
|
8037
8037
|
rest.phase = providerData.phase;
|
|
8038
8038
|
}
|
|
@@ -9532,6 +9532,25 @@ async function* streamWithPreemption(request, preemption, open) {
|
|
|
9532
9532
|
}
|
|
9533
9533
|
}
|
|
9534
9534
|
|
|
9535
|
+
// src/mcp-model-tool-name.ts
|
|
9536
|
+
import { createHash as createHash4 } from "crypto";
|
|
9537
|
+
import { prefixedMcpToolName as plainPrefixedMcpToolName } from "@opengeni/contracts";
|
|
9538
|
+
var ALIASED_MCP_TOOL_LEAF_LENGTH = 34;
|
|
9539
|
+
var ALIASED_MCP_TOOL_NAME = /^mcp_[0-9a-f]{24}__/;
|
|
9540
|
+
function prefixedMcpToolName(registryId, toolName) {
|
|
9541
|
+
const name = plainPrefixedMcpToolName(registryId, toolName);
|
|
9542
|
+
if (name.length <= 64 && /^[A-Za-z0-9_]+$/.test(name)) return name;
|
|
9543
|
+
const digest2 = legacyMcpToolDigest(registryId, toolName).slice(0, 24);
|
|
9544
|
+
const leaf = toolName.replace(/[^A-Za-z0-9_]/g, "_").slice(0, ALIASED_MCP_TOOL_LEAF_LENGTH) || "tool";
|
|
9545
|
+
return `mcp_${digest2}__${leaf}`;
|
|
9546
|
+
}
|
|
9547
|
+
function legacyMcpToolDigest(registryId, toolName) {
|
|
9548
|
+
return createHash4("sha256").update(JSON.stringify([registryId, toolName])).digest("hex");
|
|
9549
|
+
}
|
|
9550
|
+
function isAliasedMcpToolName(name) {
|
|
9551
|
+
return ALIASED_MCP_TOOL_NAME.test(name);
|
|
9552
|
+
}
|
|
9553
|
+
|
|
9535
9554
|
// src/provider-history-adapter.ts
|
|
9536
9555
|
import { collapseRepeatedSessionGoalContexts as collapseRepeatedSessionGoalContexts2 } from "@opengeni/contracts";
|
|
9537
9556
|
|
|
@@ -9544,9 +9563,9 @@ function primaryChatChoice(value) {
|
|
|
9544
9563
|
return Array.isArray(choices) ? choices.map(object).find((choice) => choice?.index === 0) : void 0;
|
|
9545
9564
|
}
|
|
9546
9565
|
function chatReasoning(value) {
|
|
9547
|
-
const
|
|
9566
|
+
const record4 = object(value);
|
|
9548
9567
|
for (const field2 of ["reasoning_content", "reasoning"]) {
|
|
9549
|
-
const text2 =
|
|
9568
|
+
const text2 = record4?.[field2];
|
|
9550
9569
|
if (typeof text2 === "string" && text2.length > 0) return { field: field2, text: text2 };
|
|
9551
9570
|
}
|
|
9552
9571
|
return void 0;
|
|
@@ -9700,8 +9719,211 @@ function joinChatReasoningMessages(messages) {
|
|
|
9700
9719
|
return result.length === messages.length ? messages : result;
|
|
9701
9720
|
}
|
|
9702
9721
|
|
|
9722
|
+
// src/provider-tool-names.ts
|
|
9723
|
+
import { createHash as createHash5 } from "crypto";
|
|
9724
|
+
import { SECRET_VALUE_MASK_MIN_CHARS } from "@opengeni/contracts";
|
|
9725
|
+
var PROVIDER_TOOL_NAME = /^[a-zA-Z0-9_-]{1,64}$/;
|
|
9726
|
+
var VALID_NAME_PART = /^[a-zA-Z0-9_-]*$/;
|
|
9727
|
+
var DOTTED_NAME = /^[a-zA-Z0-9_.-]+$/;
|
|
9728
|
+
var TOOL_NAME_SEPARATOR = "__";
|
|
9729
|
+
var ALIAS_READABLE_LENGTH = 40;
|
|
9730
|
+
var ALIAS_DIGEST_LENGTH = 16;
|
|
9731
|
+
var TOOL_DISCLOSURE_KEY_PREFIX = "opengeni.tool_disclosure";
|
|
9732
|
+
var MASKING_LABEL = /\{\{secret:[^{}]*\}\}|\[opengeni credential:[^\]]*\]|\[masked [^\]]*\]|\[redacted:[^\]]*\]|\[secret\]/g;
|
|
9733
|
+
function isProviderToolName(name) {
|
|
9734
|
+
return PROVIDER_TOOL_NAME.test(name);
|
|
9735
|
+
}
|
|
9736
|
+
function providerToolNameAlias(name) {
|
|
9737
|
+
const readable = name.replace(/[^a-zA-Z0-9_-]+/g, "_").slice(0, ALIAS_READABLE_LENGTH);
|
|
9738
|
+
const digest2 = createHash5("sha256").update(name).digest("hex").slice(0, ALIAS_DIGEST_LENGTH);
|
|
9739
|
+
return `${readable}_${digest2}`;
|
|
9740
|
+
}
|
|
9741
|
+
function escapeRegExp(text2) {
|
|
9742
|
+
return text2.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
9743
|
+
}
|
|
9744
|
+
function uniqueMatch(candidates, matches) {
|
|
9745
|
+
let match = null;
|
|
9746
|
+
for (const candidate of candidates) {
|
|
9747
|
+
if (!matches(candidate)) continue;
|
|
9748
|
+
if (match !== null && match !== candidate) return null;
|
|
9749
|
+
match = candidate;
|
|
9750
|
+
}
|
|
9751
|
+
return match;
|
|
9752
|
+
}
|
|
9753
|
+
function knownToolNameFor(name, known) {
|
|
9754
|
+
const valid = known.filter(isProviderToolName);
|
|
9755
|
+
if (name.includes(".") && DOTTED_NAME.test(name)) {
|
|
9756
|
+
const dotted = name.replaceAll(".", TOOL_NAME_SEPARATOR);
|
|
9757
|
+
if (valid.includes(dotted)) return dotted;
|
|
9758
|
+
const published = name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
9759
|
+
return uniqueMatch(valid, (candidate) => {
|
|
9760
|
+
const separator = candidate.lastIndexOf(TOOL_NAME_SEPARATOR);
|
|
9761
|
+
if (separator < 0) return false;
|
|
9762
|
+
const leaf = candidate.slice(separator + TOOL_NAME_SEPARATOR.length);
|
|
9763
|
+
return leaf === published || isAliasedMcpToolName(candidate) && leaf === published.slice(0, ALIASED_MCP_TOOL_LEAF_LENGTH);
|
|
9764
|
+
});
|
|
9765
|
+
}
|
|
9766
|
+
if (!name.match(MASKING_LABEL)) return null;
|
|
9767
|
+
const parts = name.split(MASKING_LABEL);
|
|
9768
|
+
if (!parts.every((part) => VALID_NAME_PART.test(part))) return null;
|
|
9769
|
+
if (parts.every((part) => part.length === 0)) return null;
|
|
9770
|
+
const pattern = new RegExp(
|
|
9771
|
+
`^${parts.map(escapeRegExp).join(`[a-zA-Z0-9_-]{${SECRET_VALUE_MASK_MIN_CHARS},}`)}$`
|
|
9772
|
+
);
|
|
9773
|
+
return uniqueMatch(valid, (candidate) => pattern.test(candidate));
|
|
9774
|
+
}
|
|
9775
|
+
function requestFunctionToolNames(tools) {
|
|
9776
|
+
const names = [];
|
|
9777
|
+
for (const tool2 of tools ?? []) {
|
|
9778
|
+
if (isRecord6(tool2) && tool2.type === "function" && typeof tool2.name === "string") {
|
|
9779
|
+
names.push(tool2.name);
|
|
9780
|
+
}
|
|
9781
|
+
}
|
|
9782
|
+
return names;
|
|
9783
|
+
}
|
|
9784
|
+
function isRecord6(value) {
|
|
9785
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9786
|
+
}
|
|
9787
|
+
var NAMED_CALL_TYPES = /* @__PURE__ */ new Set([
|
|
9788
|
+
"function_call",
|
|
9789
|
+
"function_call_result",
|
|
9790
|
+
"custom_tool_call"
|
|
9791
|
+
]);
|
|
9792
|
+
function hasNamespace(record4) {
|
|
9793
|
+
return typeof record4.namespace === "string" && record4.namespace.length > 0;
|
|
9794
|
+
}
|
|
9795
|
+
function rewriteNamed(record4, visit, scoped) {
|
|
9796
|
+
if (!isRecord6(record4)) return record4;
|
|
9797
|
+
const isNamespace = record4.type === "namespace";
|
|
9798
|
+
const nameScoped = scoped || isNamespace || hasNamespace(record4);
|
|
9799
|
+
let next = null;
|
|
9800
|
+
if (typeof record4.name === "string") {
|
|
9801
|
+
const definition = record4.type === "function" ? record4 : void 0;
|
|
9802
|
+
const valid = visit(record4.name, nameScoped ? "scoped" : "flat", definition);
|
|
9803
|
+
if (valid !== record4.name) next = { ...record4, name: valid };
|
|
9804
|
+
}
|
|
9805
|
+
if (typeof record4.namespace === "string") {
|
|
9806
|
+
const valid = visit(record4.namespace, "scoped");
|
|
9807
|
+
if (valid !== record4.namespace) next = { ...next ?? record4, namespace: valid };
|
|
9808
|
+
}
|
|
9809
|
+
if (Array.isArray(record4.tools)) {
|
|
9810
|
+
const tools = rewriteDefinitions(record4.tools, visit, scoped || isNamespace);
|
|
9811
|
+
if (tools !== record4.tools) next = { ...next ?? record4, tools };
|
|
9812
|
+
}
|
|
9813
|
+
return next ?? record4;
|
|
9814
|
+
}
|
|
9815
|
+
function rewriteDefinitions(tools, visit, scoped) {
|
|
9816
|
+
let changed = false;
|
|
9817
|
+
const rewritten = tools.map((tool2) => {
|
|
9818
|
+
const next = rewriteNamed(tool2, visit, scoped);
|
|
9819
|
+
if (next !== tool2) changed = true;
|
|
9820
|
+
return next;
|
|
9821
|
+
});
|
|
9822
|
+
if (!changed) return tools;
|
|
9823
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9824
|
+
return rewritten.filter((tool2) => {
|
|
9825
|
+
if (!isRecord6(tool2) || typeof tool2.name !== "string") return true;
|
|
9826
|
+
if (seen.has(tool2.name)) return false;
|
|
9827
|
+
seen.add(tool2.name);
|
|
9828
|
+
return true;
|
|
9829
|
+
});
|
|
9830
|
+
}
|
|
9831
|
+
function withRewrittenTools(record4, visit) {
|
|
9832
|
+
if (!Array.isArray(record4.tools)) return record4;
|
|
9833
|
+
const tools = rewriteDefinitions(record4.tools, visit, false);
|
|
9834
|
+
return tools === record4.tools ? record4 : { ...record4, tools };
|
|
9835
|
+
}
|
|
9836
|
+
function declaresTools(providerData) {
|
|
9837
|
+
return providerData.type === "additional_tools" || providerData.type === "tool_search_output";
|
|
9838
|
+
}
|
|
9839
|
+
function rewriteItem(item, visit) {
|
|
9840
|
+
if (!isRecord6(item)) return item;
|
|
9841
|
+
const type = typeof item.type === "string" ? item.type : "";
|
|
9842
|
+
if (NAMED_CALL_TYPES.has(type)) return rewriteNamed(item, visit, false);
|
|
9843
|
+
let next = type === "tool_search_output" ? withRewrittenTools(item, visit) : item;
|
|
9844
|
+
if (isRecord6(next.providerData)) {
|
|
9845
|
+
const providerData = next.providerData;
|
|
9846
|
+
let data = declaresTools(providerData) ? withRewrittenTools(providerData, visit) : providerData;
|
|
9847
|
+
for (const [key, value] of Object.entries(providerData)) {
|
|
9848
|
+
if (!key.startsWith(TOOL_DISCLOSURE_KEY_PREFIX) || !isRecord6(value)) continue;
|
|
9849
|
+
const rewritten = withRewrittenTools(value, visit);
|
|
9850
|
+
if (rewritten !== value) data = { ...data, [key]: rewritten };
|
|
9851
|
+
}
|
|
9852
|
+
if (data !== providerData) next = { ...next, providerData: data };
|
|
9853
|
+
}
|
|
9854
|
+
return next;
|
|
9855
|
+
}
|
|
9856
|
+
function invalidHistoryToolNames(items) {
|
|
9857
|
+
const names = /* @__PURE__ */ new Set();
|
|
9858
|
+
const collect = (name) => {
|
|
9859
|
+
if (!isProviderToolName(name)) names.add(name);
|
|
9860
|
+
return name;
|
|
9861
|
+
};
|
|
9862
|
+
for (const item of items) rewriteItem(item, collect);
|
|
9863
|
+
return [...names];
|
|
9864
|
+
}
|
|
9865
|
+
function stableJson(value) {
|
|
9866
|
+
if (Array.isArray(value)) return `[${value.map(stableJson).join(",")}]`;
|
|
9867
|
+
if (isRecord6(value)) {
|
|
9868
|
+
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${stableJson(value[key])}`).join(",")}}`;
|
|
9869
|
+
}
|
|
9870
|
+
return JSON.stringify(value) ?? "null";
|
|
9871
|
+
}
|
|
9872
|
+
var rewrittenItems = /* @__PURE__ */ new WeakMap();
|
|
9873
|
+
function withProviderValidToolNames(items, catalog = { names: [] }) {
|
|
9874
|
+
const known = new Set(catalog.names);
|
|
9875
|
+
const flat = /* @__PURE__ */ new Set();
|
|
9876
|
+
const scoped = /* @__PURE__ */ new Set();
|
|
9877
|
+
const storedParameters = /* @__PURE__ */ new Map();
|
|
9878
|
+
const collect = (name, position, definition) => {
|
|
9879
|
+
if (isProviderToolName(name) || known.has(name)) return name;
|
|
9880
|
+
(position === "flat" ? flat : scoped).add(name);
|
|
9881
|
+
if (position === "flat" && isRecord6(definition) && definition.parameters !== void 0) {
|
|
9882
|
+
const stored = storedParameters.get(name) ?? /* @__PURE__ */ new Set();
|
|
9883
|
+
stored.add(stableJson(definition.parameters));
|
|
9884
|
+
storedParameters.set(name, stored);
|
|
9885
|
+
}
|
|
9886
|
+
return name;
|
|
9887
|
+
};
|
|
9888
|
+
for (const item of items) rewriteItem(item, collect);
|
|
9889
|
+
if (flat.size === 0 && scoped.size === 0) return items;
|
|
9890
|
+
const aliasUnbound = catalog.aliasUnbound !== false;
|
|
9891
|
+
const flatNames = /* @__PURE__ */ new Map();
|
|
9892
|
+
for (const name of flat) {
|
|
9893
|
+
let denoted = catalog.denote ? knownToolNameFor(name, catalog.names) : null;
|
|
9894
|
+
const stored = storedParameters.get(name);
|
|
9895
|
+
if (denoted !== null && stored && catalog.parametersOf) {
|
|
9896
|
+
const parameters = catalog.parametersOf(denoted);
|
|
9897
|
+
if (parameters !== void 0 && [...stored].some((json) => json !== stableJson(parameters)))
|
|
9898
|
+
denoted = null;
|
|
9899
|
+
}
|
|
9900
|
+
flatNames.set(name, denoted ?? (aliasUnbound ? providerToolNameAlias(name) : name));
|
|
9901
|
+
}
|
|
9902
|
+
const rewrite = (name, position) => {
|
|
9903
|
+
if (isProviderToolName(name) || known.has(name)) return name;
|
|
9904
|
+
if (position === "flat") return flatNames.get(name) ?? providerToolNameAlias(name);
|
|
9905
|
+
return aliasUnbound ? providerToolNameAlias(name) : name;
|
|
9906
|
+
};
|
|
9907
|
+
const mapping = JSON.stringify([[...flatNames], [...scoped], aliasUnbound]);
|
|
9908
|
+
let changed = false;
|
|
9909
|
+
const next = items.map((item) => {
|
|
9910
|
+
if (item === null || typeof item !== "object") return item;
|
|
9911
|
+
const cached = rewrittenItems.get(item);
|
|
9912
|
+
let rewritten;
|
|
9913
|
+
if (cached?.mapping === mapping) {
|
|
9914
|
+
rewritten = cached.item;
|
|
9915
|
+
} else {
|
|
9916
|
+
rewritten = rewriteItem(item, rewrite);
|
|
9917
|
+
if (rewritten !== item) rewrittenItems.set(item, { mapping, item: rewritten });
|
|
9918
|
+
}
|
|
9919
|
+
if (rewritten !== item) changed = true;
|
|
9920
|
+
return rewritten;
|
|
9921
|
+
});
|
|
9922
|
+
return changed ? next : items;
|
|
9923
|
+
}
|
|
9924
|
+
|
|
9703
9925
|
// src/provider-history-adapter.ts
|
|
9704
|
-
var CHAT_FUNCTION_NAME = /^[a-zA-Z0-9_-]
|
|
9926
|
+
var CHAT_FUNCTION_NAME = /^[a-zA-Z0-9_-]{1,64}$/;
|
|
9705
9927
|
var HISTORICAL_FACT_MAX_CHARS = 32e3;
|
|
9706
9928
|
var TOOL_DISCLOSURE_KEY = "opengeni.tool_disclosure.v1";
|
|
9707
9929
|
var TOOL_DISCLOSURE_TEXT_WITH_INVOKE = "These tools are now available. Call one by its name, or through tool_invoke with its name and a nested arguments object. Definitions:";
|
|
@@ -9861,7 +10083,9 @@ function projectHistoryForProvider(items, providerApi, options = {}) {
|
|
|
9861
10083
|
})
|
|
9862
10084
|
);
|
|
9863
10085
|
const input = projected.every((item, index) => item === items[index]) ? items : projected;
|
|
9864
|
-
|
|
10086
|
+
const wireValid = withWireValidFunctionCallArguments(input);
|
|
10087
|
+
const named = providerApi === "chat" ? wireValid : withProviderValidToolNames(wireValid, { names: options.knownToolNames ?? [] });
|
|
10088
|
+
return projectWireHistory(named, providerApi, options);
|
|
9865
10089
|
}
|
|
9866
10090
|
function withoutClaudeCitationMetadata(item) {
|
|
9867
10091
|
if (item.type !== "message" || item.role !== "assistant" || !Array.isArray(item.content))
|
|
@@ -9995,10 +10219,10 @@ function splitStableSystemPromptPrefix(instructions) {
|
|
|
9995
10219
|
}
|
|
9996
10220
|
|
|
9997
10221
|
// src/anthropic-messages.ts
|
|
9998
|
-
import { createHash as
|
|
10222
|
+
import { createHash as createHash7, randomUUID as randomUUID3 } from "crypto";
|
|
9999
10223
|
|
|
10000
10224
|
// src/claude-code-identity.ts
|
|
10001
|
-
import { createHash as
|
|
10225
|
+
import { createHash as createHash6, randomUUID as randomUUID2 } from "crypto";
|
|
10002
10226
|
var CLAUDE_CODE_HEADERS = {
|
|
10003
10227
|
"user-agent": "claude-cli/2.1.285 (external, sdk-ts, agent-sdk/0.3.276)",
|
|
10004
10228
|
"x-app": "cli",
|
|
@@ -10021,7 +10245,7 @@ function claudeCodeFingerprint(input) {
|
|
|
10021
10245
|
const first = typeof content === "string" ? content : Array.isArray(content) ? content.find((block) => block.type === "input_text" || String(block.type) === "text") : void 0;
|
|
10022
10246
|
const prompt = typeof first === "string" ? first : first && "text" in first ? String(first.text) : "";
|
|
10023
10247
|
const sample = [4, 7, 20].map((index) => prompt[index] || "0").join("");
|
|
10024
|
-
return
|
|
10248
|
+
return createHash6("sha256").update(`59cf53e54c78${sample}2.1.285`).digest("hex").slice(0, 3);
|
|
10025
10249
|
}
|
|
10026
10250
|
function applyClaudeCodeIdentity(body, headers, url, request, account, identity) {
|
|
10027
10251
|
url.searchParams.set("beta", "true");
|
|
@@ -10188,12 +10412,12 @@ async function readErrorDetail(body, timeoutMs, signal) {
|
|
|
10188
10412
|
function anthropicToolUseId(id) {
|
|
10189
10413
|
if (/^[a-zA-Z0-9_-]+$/.test(id)) return id;
|
|
10190
10414
|
const readable = id.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 64);
|
|
10191
|
-
return `${readable}_${
|
|
10415
|
+
return `${readable}_${createHash7("sha256").update(id).digest("hex").slice(0, 16)}`;
|
|
10192
10416
|
}
|
|
10193
10417
|
function anthropicToolName(name, namespace) {
|
|
10194
10418
|
if (!namespace && /^[a-zA-Z0-9_-]{1,64}$/.test(name)) return name;
|
|
10195
10419
|
const identity = JSON.stringify([namespace ?? null, name]);
|
|
10196
|
-
return "og_" +
|
|
10420
|
+
return "og_" + createHash7("sha256").update(identity).digest("hex").slice(0, 60);
|
|
10197
10421
|
}
|
|
10198
10422
|
function toolNames(request) {
|
|
10199
10423
|
const names = /* @__PURE__ */ new Map();
|
|
@@ -10521,7 +10745,9 @@ function buildAnthropicRequest(request, model, provider, stream) {
|
|
|
10521
10745
|
);
|
|
10522
10746
|
return matches[0][0];
|
|
10523
10747
|
};
|
|
10524
|
-
const input = typeof request.input === "string" ? request.input : projectHistoryForProvider(request.input, "anthropic-messages"
|
|
10748
|
+
const input = typeof request.input === "string" ? request.input : projectHistoryForProvider(request.input, "anthropic-messages", {
|
|
10749
|
+
knownToolNames: requestFunctionToolNames(request.tools)
|
|
10750
|
+
});
|
|
10525
10751
|
const webSearch = request.tools.some(isHostedWebSearchTool);
|
|
10526
10752
|
let messages = anthropicMessages(input, {
|
|
10527
10753
|
webSearch,
|
|
@@ -12291,21 +12517,21 @@ function hostedToolRoute(type) {
|
|
|
12291
12517
|
if (type === "image_generation") return "image_generation.openai_hosted";
|
|
12292
12518
|
return null;
|
|
12293
12519
|
}
|
|
12294
|
-
function
|
|
12520
|
+
function isRecord7(value) {
|
|
12295
12521
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
12296
12522
|
}
|
|
12297
12523
|
function clientExecutedTool(tool2) {
|
|
12298
|
-
if (!
|
|
12524
|
+
if (!isRecord7(tool2)) return false;
|
|
12299
12525
|
const type = tool2.type;
|
|
12300
12526
|
if (type === void 0) {
|
|
12301
|
-
return typeof tool2.name === "string" &&
|
|
12527
|
+
return typeof tool2.name === "string" && isRecord7(tool2.input_schema);
|
|
12302
12528
|
}
|
|
12303
12529
|
if (typeof type !== "string") return false;
|
|
12304
12530
|
if (["function", "custom", "local_shell", "apply_patch"].includes(type)) return true;
|
|
12305
12531
|
if (/^(computer|bash_|text_editor_|memory_)/u.test(type)) return true;
|
|
12306
12532
|
if (type === "tool_search") return tool2.execution === "client";
|
|
12307
12533
|
if (type === "shell") {
|
|
12308
|
-
return tool2.environment === void 0 || tool2.environment === null ||
|
|
12534
|
+
return tool2.environment === void 0 || tool2.environment === null || isRecord7(tool2.environment) && tool2.environment.type === "local";
|
|
12309
12535
|
}
|
|
12310
12536
|
if (type === "namespace") {
|
|
12311
12537
|
return Array.isArray(tool2.tools) && tool2.tools.every(clientExecutedTool);
|
|
@@ -12313,7 +12539,7 @@ function clientExecutedTool(tool2) {
|
|
|
12313
12539
|
return false;
|
|
12314
12540
|
}
|
|
12315
12541
|
function toolLabel(tool2) {
|
|
12316
|
-
if (!
|
|
12542
|
+
if (!isRecord7(tool2)) return "tool";
|
|
12317
12543
|
if (typeof tool2.type === "string") return tool2.type;
|
|
12318
12544
|
const [key] = Object.keys(tool2);
|
|
12319
12545
|
return key ?? "tool";
|
|
@@ -12582,12 +12808,12 @@ function projectTextParts(parts, textType) {
|
|
|
12582
12808
|
let changed = false;
|
|
12583
12809
|
const projected = parts.map((part) => {
|
|
12584
12810
|
if (!part || typeof part !== "object" || Array.isArray(part)) return part;
|
|
12585
|
-
const
|
|
12586
|
-
if (
|
|
12587
|
-
const text2 = escapeGeminiFunctionResponseRefKeys(
|
|
12588
|
-
if (text2 ===
|
|
12811
|
+
const record4 = part;
|
|
12812
|
+
if (record4.type !== textType || typeof record4.text !== "string") return part;
|
|
12813
|
+
const text2 = escapeGeminiFunctionResponseRefKeys(record4.text);
|
|
12814
|
+
if (text2 === record4.text) return part;
|
|
12589
12815
|
changed = true;
|
|
12590
|
-
return { ...
|
|
12816
|
+
return { ...record4, text: text2 };
|
|
12591
12817
|
});
|
|
12592
12818
|
return changed ? projected : parts;
|
|
12593
12819
|
}
|
|
@@ -12603,14 +12829,14 @@ var geminiFunctionResponseRefPolicy = ({ body }) => {
|
|
|
12603
12829
|
let changed = false;
|
|
12604
12830
|
const input = body.input.map((item) => {
|
|
12605
12831
|
if (!item || typeof item !== "object" || Array.isArray(item)) return item;
|
|
12606
|
-
const
|
|
12607
|
-
if (typeof
|
|
12832
|
+
const record4 = item;
|
|
12833
|
+
if (typeof record4.type !== "string" || !RESPONSES_TOOL_OUTPUT_TYPES.has(record4.type)) {
|
|
12608
12834
|
return item;
|
|
12609
12835
|
}
|
|
12610
|
-
const output = projectToolResultValue(
|
|
12611
|
-
if (output ===
|
|
12836
|
+
const output = projectToolResultValue(record4.output, "input_text");
|
|
12837
|
+
if (output === record4.output) return item;
|
|
12612
12838
|
changed = true;
|
|
12613
|
-
return { ...
|
|
12839
|
+
return { ...record4, output };
|
|
12614
12840
|
});
|
|
12615
12841
|
return changed ? { body: { ...body, input } } : void 0;
|
|
12616
12842
|
}
|
|
@@ -12618,12 +12844,12 @@ var geminiFunctionResponseRefPolicy = ({ body }) => {
|
|
|
12618
12844
|
let changed = false;
|
|
12619
12845
|
const messages = body.messages.map((message) => {
|
|
12620
12846
|
if (!message || typeof message !== "object" || Array.isArray(message)) return message;
|
|
12621
|
-
const
|
|
12622
|
-
if (
|
|
12623
|
-
const content = projectToolResultValue(
|
|
12624
|
-
if (content ===
|
|
12847
|
+
const record4 = message;
|
|
12848
|
+
if (record4.role !== "tool") return message;
|
|
12849
|
+
const content = projectToolResultValue(record4.content, "text");
|
|
12850
|
+
if (content === record4.content) return message;
|
|
12625
12851
|
changed = true;
|
|
12626
|
-
return { ...
|
|
12852
|
+
return { ...record4, content };
|
|
12627
12853
|
});
|
|
12628
12854
|
return changed ? { body: { ...body, messages } } : void 0;
|
|
12629
12855
|
}
|
|
@@ -12759,10 +12985,10 @@ function azureModelRequestProjection({
|
|
|
12759
12985
|
return projectedBody === body ? void 0 : { body: projectedBody };
|
|
12760
12986
|
const projectedInput = input.map((item) => {
|
|
12761
12987
|
if (!item || typeof item !== "object" || Array.isArray(item)) return item;
|
|
12762
|
-
const
|
|
12763
|
-
if (
|
|
12764
|
-
if (
|
|
12765
|
-
return { ...
|
|
12988
|
+
const record4 = item;
|
|
12989
|
+
if (record4.type === "computer_call") return { ...record4 };
|
|
12990
|
+
if (record4.type === "computer_call_output" && record4.output && typeof record4.output === "object" && !Array.isArray(record4.output)) {
|
|
12991
|
+
return { ...record4, output: { ...record4.output } };
|
|
12766
12992
|
}
|
|
12767
12993
|
return item;
|
|
12768
12994
|
});
|
|
@@ -12900,10 +13126,10 @@ var chatModelRequestPolicy = ({ path, body }) => {
|
|
|
12900
13126
|
let retainedDetails = chatReasoningDetails(message);
|
|
12901
13127
|
const content = message.content.map((part) => {
|
|
12902
13128
|
if (!part || typeof part !== "object" || Array.isArray(part)) return part;
|
|
12903
|
-
const
|
|
12904
|
-
if (
|
|
12905
|
-
retainedReasoning ??= chatReasoning(
|
|
12906
|
-
retainedDetails ??= chatReasoningDetails(
|
|
13129
|
+
const record4 = part;
|
|
13130
|
+
if (record4.type !== "text" && record4.type !== "refusal") return part;
|
|
13131
|
+
retainedReasoning ??= chatReasoning(record4);
|
|
13132
|
+
retainedDetails ??= chatReasoningDetails(record4);
|
|
12907
13133
|
const outputOnlyKeys = [
|
|
12908
13134
|
"annotations",
|
|
12909
13135
|
"logprobs",
|
|
@@ -12915,10 +13141,10 @@ var chatModelRequestPolicy = ({ path, body }) => {
|
|
|
12915
13141
|
"reasoning_content",
|
|
12916
13142
|
"reasoning_details",
|
|
12917
13143
|
"tools",
|
|
12918
|
-
...
|
|
13144
|
+
...record4.type === "text" ? ["refusal"] : ["content"]
|
|
12919
13145
|
];
|
|
12920
|
-
if (!outputOnlyKeys.some((key) => Object.hasOwn(
|
|
12921
|
-
const projected = { ...
|
|
13146
|
+
if (!outputOnlyKeys.some((key) => Object.hasOwn(record4, key))) return part;
|
|
13147
|
+
const projected = { ...record4 };
|
|
12922
13148
|
for (const key of outputOnlyKeys) delete projected[key];
|
|
12923
13149
|
contentChanged = true;
|
|
12924
13150
|
return projected;
|
|
@@ -12992,7 +13218,7 @@ function isModelCallFetch(input) {
|
|
|
12992
13218
|
|
|
12993
13219
|
// src/prompt-cache-fingerprint.ts
|
|
12994
13220
|
import { AsyncLocalStorage as AsyncLocalStorage6 } from "async_hooks";
|
|
12995
|
-
import { createHash as
|
|
13221
|
+
import { createHash as createHash8 } from "crypto";
|
|
12996
13222
|
import {
|
|
12997
13223
|
PROMPT_CACHE_DIGEST_HEX_LENGTH
|
|
12998
13224
|
} from "@opengeni/contracts";
|
|
@@ -13047,15 +13273,15 @@ function messageHistoryUnits(messages) {
|
|
|
13047
13273
|
}
|
|
13048
13274
|
function promptCacheRequestFingerprint(body) {
|
|
13049
13275
|
if (!body || typeof body !== "object" || Array.isArray(body)) return null;
|
|
13050
|
-
const
|
|
13051
|
-
const history = Array.isArray(
|
|
13276
|
+
const record4 = body;
|
|
13277
|
+
const history = Array.isArray(record4.messages) ? messageHistoryUnits(record4.messages) : Array.isArray(record4.input) ? record4.input : typeof record4.input === "string" ? [record4.input] : null;
|
|
13052
13278
|
if (!history) return null;
|
|
13053
|
-
const system = Array.isArray(
|
|
13279
|
+
const system = Array.isArray(record4.system) ? record4.system.filter((block) => !isBillingBlock(block)) : typeof record4.system === "string" ? record4.system.startsWith(BILLING_HEADER_PREFIX) ? "" : record4.system : record4.instructions ?? null;
|
|
13054
13280
|
const checkpoints = [];
|
|
13055
|
-
const chain =
|
|
13281
|
+
const chain = createHash8("sha256");
|
|
13056
13282
|
let next = 1;
|
|
13057
13283
|
history.forEach((item, index) => {
|
|
13058
|
-
chain.update(
|
|
13284
|
+
chain.update(createHash8("sha256").update(canonical(item)).digest());
|
|
13059
13285
|
const count = index + 1;
|
|
13060
13286
|
if (count === next || count === history.length) {
|
|
13061
13287
|
checkpoints.push([count, digest(chain.copy())]);
|
|
@@ -13064,8 +13290,8 @@ function promptCacheRequestFingerprint(body) {
|
|
|
13064
13290
|
});
|
|
13065
13291
|
return {
|
|
13066
13292
|
v: 1,
|
|
13067
|
-
tools: digest(
|
|
13068
|
-
system: digest(
|
|
13293
|
+
tools: digest(createHash8("sha256").update(canonical(record4.tools ?? null))),
|
|
13294
|
+
system: digest(createHash8("sha256").update(canonical(system))),
|
|
13069
13295
|
items: history.length,
|
|
13070
13296
|
history: checkpoints
|
|
13071
13297
|
};
|
|
@@ -13407,12 +13633,12 @@ function errorTexts(value, out, seen) {
|
|
|
13407
13633
|
}
|
|
13408
13634
|
if (!value || typeof value !== "object" || seen.has(value)) return;
|
|
13409
13635
|
seen.add(value);
|
|
13410
|
-
const
|
|
13636
|
+
const record4 = value;
|
|
13411
13637
|
for (const key of ["message", "code", "type", "name", "param"]) {
|
|
13412
|
-
const field2 =
|
|
13638
|
+
const field2 = record4[key];
|
|
13413
13639
|
if (typeof field2 === "string" && field2.length > 0) out.push(field2);
|
|
13414
13640
|
}
|
|
13415
|
-
for (const key of ["error", "cause", "response", "data"]) errorTexts(
|
|
13641
|
+
for (const key of ["error", "cause", "response", "data"]) errorTexts(record4[key], out, seen);
|
|
13416
13642
|
}
|
|
13417
13643
|
function headerValue(headers, name) {
|
|
13418
13644
|
if (!headers || typeof headers !== "object") return null;
|
|
@@ -13510,7 +13736,7 @@ import {
|
|
|
13510
13736
|
isDirectOpenAiApiBaseUrl,
|
|
13511
13737
|
opperMaxOutputTokens
|
|
13512
13738
|
} from "@opengeni/config";
|
|
13513
|
-
import { createHash as
|
|
13739
|
+
import { createHash as createHash9 } from "crypto";
|
|
13514
13740
|
import {
|
|
13515
13741
|
CODEX_RESPONSE_SDK_OUTER_TIMEOUT_MS,
|
|
13516
13742
|
CODEX_PROVIDER_BASE_URL,
|
|
@@ -13533,6 +13759,50 @@ import {
|
|
|
13533
13759
|
XAI_RESPONSE_SDK_OUTER_TIMEOUT_MS,
|
|
13534
13760
|
xaiSubscriptionFetch
|
|
13535
13761
|
} from "@opengeni/xai-subscription";
|
|
13762
|
+
|
|
13763
|
+
// src/provider-invalid-request.ts
|
|
13764
|
+
var MAX_BODY_CHARACTERS = 64 * 1024;
|
|
13765
|
+
var MAX_PATH_CHARACTERS = 96;
|
|
13766
|
+
var PATH_CHARACTERS = /^[A-Za-z_][A-Za-z0-9_.[\]*]*$/;
|
|
13767
|
+
var CODE = /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/;
|
|
13768
|
+
var EMBEDDED_PATH = /\b((?:input|messages|tools|contents|system|instructions)(?:\[\d+\]|\.\d+|\.[A-Za-z_]\w*)+)/;
|
|
13769
|
+
function record2(value) {
|
|
13770
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
13771
|
+
}
|
|
13772
|
+
function normalizedPath(raw) {
|
|
13773
|
+
const path = raw.trim().replace(/\[\d+\]/g, "[]").replace(/\.\d+(?=\.|\[|$)/g, "[]").replace(/\.properties\.[A-Za-z0-9_-]+/g, ".properties.*");
|
|
13774
|
+
return path.length <= MAX_PATH_CHARACTERS && PATH_CHARACTERS.test(path) ? path : null;
|
|
13775
|
+
}
|
|
13776
|
+
function errorCode(error) {
|
|
13777
|
+
for (const candidate of [error.code, error.type]) {
|
|
13778
|
+
if (typeof candidate === "string" && CODE.test(candidate)) return candidate;
|
|
13779
|
+
}
|
|
13780
|
+
return "unknown";
|
|
13781
|
+
}
|
|
13782
|
+
function invalidRequestSignature(body) {
|
|
13783
|
+
const envelope = record2(body);
|
|
13784
|
+
const error = record2(envelope?.error) ?? envelope ?? {};
|
|
13785
|
+
const message = typeof error.message === "string" ? error.message : "";
|
|
13786
|
+
const raw = typeof error.param === "string" && error.param || EMBEDDED_PATH.exec(message)?.[1] || null;
|
|
13787
|
+
return { path: raw && normalizedPath(raw) || "unknown", code: errorCode(error) };
|
|
13788
|
+
}
|
|
13789
|
+
async function invalidRequestSignatureOfResponse(response) {
|
|
13790
|
+
try {
|
|
13791
|
+
const text2 = await response.clone().text();
|
|
13792
|
+
if (text2.length > MAX_BODY_CHARACTERS) return { path: "unknown", code: "unknown" };
|
|
13793
|
+
let body;
|
|
13794
|
+
try {
|
|
13795
|
+
body = JSON.parse(text2);
|
|
13796
|
+
} catch {
|
|
13797
|
+
body = { message: text2 };
|
|
13798
|
+
}
|
|
13799
|
+
return invalidRequestSignature(body);
|
|
13800
|
+
} catch {
|
|
13801
|
+
return null;
|
|
13802
|
+
}
|
|
13803
|
+
}
|
|
13804
|
+
|
|
13805
|
+
// src/model-provider-client.ts
|
|
13536
13806
|
var runtimeMetricsHooks = null;
|
|
13537
13807
|
function configureRuntimeMetricsHooks(hooks) {
|
|
13538
13808
|
runtimeMetricsHooks = hooks ?? null;
|
|
@@ -13669,8 +13939,8 @@ function providerClientCacheKey(provider, settings, gatewayPolicies, opperOutput
|
|
|
13669
13939
|
const sortedRecord = (value) => value ? Object.fromEntries(
|
|
13670
13940
|
Object.entries(value).sort(([left], [right]) => left.localeCompare(right))
|
|
13671
13941
|
) : null;
|
|
13672
|
-
const apiKeyDigest = provider.apiKey ?
|
|
13673
|
-
const digest2 =
|
|
13942
|
+
const apiKeyDigest = provider.apiKey ? createHash9("sha256").update(provider.apiKey, "utf8").digest("hex") : null;
|
|
13943
|
+
const digest2 = createHash9("sha256").update(
|
|
13674
13944
|
canonicalCacheJson({
|
|
13675
13945
|
provider: {
|
|
13676
13946
|
id: provider.id,
|
|
@@ -13707,7 +13977,7 @@ function providerClientCacheKey(provider, settings, gatewayPolicies, opperOutput
|
|
|
13707
13977
|
clientId: settings.azureClientId,
|
|
13708
13978
|
federatedTokenFile: settings.azureFederatedTokenFile,
|
|
13709
13979
|
authorityHost: settings.azureAuthorityHost,
|
|
13710
|
-
clientSecretDigest: settings.azureClientSecret ?
|
|
13980
|
+
clientSecretDigest: settings.azureClientSecret ? createHash9("sha256").update(settings.azureClientSecret).digest("hex") : null
|
|
13711
13981
|
}
|
|
13712
13982
|
} : null
|
|
13713
13983
|
}),
|
|
@@ -14094,6 +14364,7 @@ function instrumentedModelFetch(provider, inner, transportReportsDispatch = fals
|
|
|
14094
14364
|
}
|
|
14095
14365
|
}
|
|
14096
14366
|
recordModelCallMetric(provider, response.ok ? "completed" : "failed", started);
|
|
14367
|
+
if (response.status === 400) recordModelInvalidRequestMetric(provider, response);
|
|
14097
14368
|
return response;
|
|
14098
14369
|
} catch (error) {
|
|
14099
14370
|
capture.cancel();
|
|
@@ -14114,6 +14385,17 @@ function recordModelCallMetric(provider, outcome, started) {
|
|
|
14114
14385
|
} catch {
|
|
14115
14386
|
}
|
|
14116
14387
|
}
|
|
14388
|
+
function recordModelInvalidRequestMetric(provider, response) {
|
|
14389
|
+
const hook = runtimeMetricsHooks?.onModelInvalidRequest;
|
|
14390
|
+
if (!hook) return;
|
|
14391
|
+
void invalidRequestSignatureOfResponse(response).then((signature) => {
|
|
14392
|
+
if (!signature) return;
|
|
14393
|
+
try {
|
|
14394
|
+
hook({ provider, ...signature });
|
|
14395
|
+
} catch {
|
|
14396
|
+
}
|
|
14397
|
+
});
|
|
14398
|
+
}
|
|
14117
14399
|
function azureDeploymentBaseUrl(settings) {
|
|
14118
14400
|
const endpoint = settings.azureOpenaiEndpoint?.replace(/\/+$/, "");
|
|
14119
14401
|
if (!endpoint || !settings.azureOpenaiDeployment) {
|
|
@@ -14241,11 +14523,11 @@ function normalizeMcpResult(value) {
|
|
|
14241
14523
|
reason: "schema_mismatch",
|
|
14242
14524
|
issues: String(parsed.error.issues.length)
|
|
14243
14525
|
});
|
|
14244
|
-
const
|
|
14245
|
-
const { _meta: _resultMeta, ...visible } =
|
|
14526
|
+
const record4 = isPlainRecord(safe) ? safe : null;
|
|
14527
|
+
const { _meta: _resultMeta, ...visible } = record4 ?? {};
|
|
14246
14528
|
return {
|
|
14247
|
-
content: [{ type: "text", text: JSON.stringify(
|
|
14248
|
-
...
|
|
14529
|
+
content: [{ type: "text", text: JSON.stringify(record4 ? visible : safe) ?? "null" }],
|
|
14530
|
+
...record4?.isError === true ? { isError: true } : {}
|
|
14249
14531
|
};
|
|
14250
14532
|
}
|
|
14251
14533
|
function typeName(value) {
|
|
@@ -14779,25 +15061,6 @@ var ToolSearchIndex = class {
|
|
|
14779
15061
|
}
|
|
14780
15062
|
};
|
|
14781
15063
|
|
|
14782
|
-
// src/mcp-model-tool-name.ts
|
|
14783
|
-
import { createHash as createHash8 } from "crypto";
|
|
14784
|
-
import { prefixedMcpToolName as plainPrefixedMcpToolName } from "@opengeni/contracts";
|
|
14785
|
-
var ALIASED_MCP_TOOL_LEAF_LENGTH = 34;
|
|
14786
|
-
var ALIASED_MCP_TOOL_NAME = /^mcp_[0-9a-f]{24}__/;
|
|
14787
|
-
function prefixedMcpToolName(registryId, toolName) {
|
|
14788
|
-
const name = plainPrefixedMcpToolName(registryId, toolName);
|
|
14789
|
-
if (name.length <= 64 && /^[A-Za-z0-9_]+$/.test(name)) return name;
|
|
14790
|
-
const digest2 = legacyMcpToolDigest(registryId, toolName).slice(0, 24);
|
|
14791
|
-
const leaf = toolName.replace(/[^A-Za-z0-9_]/g, "_").slice(0, ALIASED_MCP_TOOL_LEAF_LENGTH) || "tool";
|
|
14792
|
-
return `mcp_${digest2}__${leaf}`;
|
|
14793
|
-
}
|
|
14794
|
-
function legacyMcpToolDigest(registryId, toolName) {
|
|
14795
|
-
return createHash8("sha256").update(JSON.stringify([registryId, toolName])).digest("hex");
|
|
14796
|
-
}
|
|
14797
|
-
function isAliasedMcpToolName(name) {
|
|
14798
|
-
return ALIASED_MCP_TOOL_NAME.test(name);
|
|
14799
|
-
}
|
|
14800
|
-
|
|
14801
15064
|
// src/codex-tool-search.ts
|
|
14802
15065
|
var DEFAULT_SEARCH_LIMIT = 8;
|
|
14803
15066
|
var MAX_SEARCH_LIMIT = 20;
|
|
@@ -15181,7 +15444,7 @@ function createToolSelector(model, options = {}) {
|
|
|
15181
15444
|
}
|
|
15182
15445
|
|
|
15183
15446
|
// src/tool-discovery-meaning.ts
|
|
15184
|
-
import { createHash as
|
|
15447
|
+
import { createHash as createHash10 } from "crypto";
|
|
15185
15448
|
var TOOL_MEANING_POLICY = {
|
|
15186
15449
|
/** A ranking still unanswered after this is skipped for keywords alone. */
|
|
15187
15450
|
deadlineMs: 1500,
|
|
@@ -15241,7 +15504,7 @@ function createEmbeddingToolRanker(embedder, options = {}) {
|
|
|
15241
15504
|
let computing;
|
|
15242
15505
|
let pausedUntil = 0;
|
|
15243
15506
|
let dimensions;
|
|
15244
|
-
const keyOf = (text2) =>
|
|
15507
|
+
const keyOf = (text2) => createHash10("sha256").update(embedder.space).update("\0").update(text2).digest("base64url");
|
|
15245
15508
|
const pause2 = (error) => {
|
|
15246
15509
|
pausedUntil = now() + TOOL_MEANING_POLICY.retryAfterMs;
|
|
15247
15510
|
options.onError?.(error);
|
|
@@ -15378,7 +15641,7 @@ function toolGroups(tools, serverIds) {
|
|
|
15378
15641
|
}
|
|
15379
15642
|
|
|
15380
15643
|
// src/deferred-tool-arguments.ts
|
|
15381
|
-
import { isRecord as
|
|
15644
|
+
import { isRecord as isRecord8 } from "@opengeni/contracts/values";
|
|
15382
15645
|
var NON_STRING_TYPES = /* @__PURE__ */ new Set(["integer", "number", "boolean", "null", "array", "object"]);
|
|
15383
15646
|
var MAX_DEPTH = 8;
|
|
15384
15647
|
function parseFiniteJson(text2) {
|
|
@@ -15390,7 +15653,7 @@ function parseFiniteJson(text2) {
|
|
|
15390
15653
|
});
|
|
15391
15654
|
}
|
|
15392
15655
|
function declaredTypes(schema) {
|
|
15393
|
-
if (!
|
|
15656
|
+
if (!isRecord8(schema)) return null;
|
|
15394
15657
|
const types = /* @__PURE__ */ new Set();
|
|
15395
15658
|
const type = schema.type;
|
|
15396
15659
|
if (typeof type === "string") types.add(type);
|
|
@@ -15438,11 +15701,11 @@ function coerceValue(value, schema, depth) {
|
|
|
15438
15701
|
}
|
|
15439
15702
|
return matchesAny(parsed, types) ? parsed : value;
|
|
15440
15703
|
}
|
|
15441
|
-
if (
|
|
15704
|
+
if (isRecord8(value)) return coerceObject(value, schema, depth + 1);
|
|
15442
15705
|
return value;
|
|
15443
15706
|
}
|
|
15444
15707
|
function coerceObject(value, schema, depth) {
|
|
15445
|
-
if (!
|
|
15708
|
+
if (!isRecord8(schema) || !isRecord8(schema.properties)) return value;
|
|
15446
15709
|
const properties = schema.properties;
|
|
15447
15710
|
let changed = false;
|
|
15448
15711
|
const next = /* @__PURE__ */ Object.create(null);
|
|
@@ -15461,13 +15724,13 @@ function restoreDeferredToolArgumentTypes(argumentsText, parameters) {
|
|
|
15461
15724
|
} catch {
|
|
15462
15725
|
return null;
|
|
15463
15726
|
}
|
|
15464
|
-
if (!
|
|
15727
|
+
if (!isRecord8(parsed)) return null;
|
|
15465
15728
|
const coerced = coerceObject(parsed, parameters, 0);
|
|
15466
15729
|
return coerced === parsed ? null : JSON.stringify(coerced);
|
|
15467
15730
|
}
|
|
15468
15731
|
|
|
15469
15732
|
// src/lazy-tool-transport.ts
|
|
15470
|
-
import { isRecord as
|
|
15733
|
+
import { isRecord as isRecord9 } from "@opengeni/contracts/values";
|
|
15471
15734
|
var TOOL_SEARCH_NAME = "tool_search";
|
|
15472
15735
|
var TOOL_LIST_NAME = "tool_list";
|
|
15473
15736
|
var TOOL_INVOKE_NAME = "tool_invoke";
|
|
@@ -15523,8 +15786,8 @@ var INTERNAL_REGISTRATION_TOOL_MARKER_KEY = "opengeni.internal_lazy_registration
|
|
|
15523
15786
|
var OPENING_TOOL_LOAD_MARKER_KEY = "opengeni.opening_tool_load.v1";
|
|
15524
15787
|
var OPENING_TOOL_LOAD_CALL_ID = "call_opening_tools";
|
|
15525
15788
|
function isOpeningToolLoadResponse(value) {
|
|
15526
|
-
const response =
|
|
15527
|
-
return
|
|
15789
|
+
const response = isRecord9(value) && value.type === "response_done" && isRecord9(value.response) ? value.response : value;
|
|
15790
|
+
return isRecord9(response) && isRecord9(response.providerData) && response.providerData[OPENING_TOOL_LOAD_MARKER_KEY] === true;
|
|
15528
15791
|
}
|
|
15529
15792
|
var INTERNAL_DISPATCH_REGISTRATION_CALL_PREFIX = "opengeni:lazy-dispatch:register:";
|
|
15530
15793
|
var SEARCH_DESCRIPTION = "Find currently authorized tools by capability. Describe the action and resource you need; separate independent tasks with semicolons and include useful context. Loads the strongest match and returns compact alternatives; ranking is not certainty, so check the match. If a decision model is configured, it can select tools for ambiguous searches. With schemasLoaded:true, only tools have loaded schemas; suggestions are unloaded alternatives. With schemasLoaded:false, load chosen exact names with query:'' before invoking. Known exact names bypass ranking and inference. Call loaded tools by name or through tool_invoke. Search is not exhaustive: tool_list view:'groups' shows available groups. Discovery never grants access.";
|
|
@@ -15618,22 +15881,22 @@ function alreadyAvailableNotice(names) {
|
|
|
15618
15881
|
return names.length === 1 ? `${names[0]} is already in your tool list; call it directly.` : `${names.join(", ")} are already in your tool list; call them directly.`;
|
|
15619
15882
|
}
|
|
15620
15883
|
function connectableIntegrationsFromCatalogResult(result) {
|
|
15621
|
-
const content = Array.isArray(result) ? result :
|
|
15622
|
-
if (
|
|
15884
|
+
const content = Array.isArray(result) ? result : isRecord9(result) && Array.isArray(result.content) ? result.content : [];
|
|
15885
|
+
if (isRecord9(result) && result.isError === true) return [];
|
|
15623
15886
|
const found = [];
|
|
15624
15887
|
for (const block of content) {
|
|
15625
|
-
if (!
|
|
15888
|
+
if (!isRecord9(block) || block.type !== "text" || typeof block.text !== "string") continue;
|
|
15626
15889
|
let parsed;
|
|
15627
15890
|
try {
|
|
15628
15891
|
parsed = JSON.parse(block.text);
|
|
15629
15892
|
} catch {
|
|
15630
15893
|
continue;
|
|
15631
15894
|
}
|
|
15632
|
-
if (!
|
|
15895
|
+
if (!isRecord9(parsed) || !Array.isArray(parsed.matches)) continue;
|
|
15633
15896
|
for (const match of parsed.matches) {
|
|
15634
|
-
if (!
|
|
15635
|
-
const setup =
|
|
15636
|
-
const next = setup &&
|
|
15897
|
+
if (!isRecord9(match) || match.approximate === true) continue;
|
|
15898
|
+
const setup = isRecord9(match.setup) ? match.setup : null;
|
|
15899
|
+
const next = setup && isRecord9(setup.nextAction) ? setup.nextAction : null;
|
|
15637
15900
|
if (next?.toolName !== "capability_authorization_request") continue;
|
|
15638
15901
|
if (setup.action === "enable") continue;
|
|
15639
15902
|
if (typeof match.capabilityId !== "string" || typeof match.name !== "string") continue;
|
|
@@ -15662,7 +15925,7 @@ function isFunctionTool(tool2) {
|
|
|
15662
15925
|
function parseJsonObject(value) {
|
|
15663
15926
|
try {
|
|
15664
15927
|
const parsed = JSON.parse(value);
|
|
15665
|
-
return
|
|
15928
|
+
return isRecord9(parsed) ? parsed : null;
|
|
15666
15929
|
} catch {
|
|
15667
15930
|
return null;
|
|
15668
15931
|
}
|
|
@@ -15678,7 +15941,7 @@ function modelVisibleToolDefinition(tool2) {
|
|
|
15678
15941
|
};
|
|
15679
15942
|
}
|
|
15680
15943
|
function unavailableToolResult(input) {
|
|
15681
|
-
const name =
|
|
15944
|
+
const name = isRecord9(input) && typeof input.name === "string" ? input.name : null;
|
|
15682
15945
|
return JSON.stringify({
|
|
15683
15946
|
ok: false,
|
|
15684
15947
|
error: {
|
|
@@ -15859,6 +16122,10 @@ var LazyToolRuntime = class {
|
|
|
15859
16122
|
resolveFunctionTool(name) {
|
|
15860
16123
|
return this.functionTools.get(name);
|
|
15861
16124
|
}
|
|
16125
|
+
/** Model names of every authorized function tool, deferred ones included. */
|
|
16126
|
+
knownFunctionToolNames() {
|
|
16127
|
+
return [...this.functionTools.keys()];
|
|
16128
|
+
}
|
|
15862
16129
|
/** True for a tool disclosed through search rather than sent on every request. */
|
|
15863
16130
|
isDeferredFunctionTool(name) {
|
|
15864
16131
|
return this.searchableToolNames.has(name);
|
|
@@ -16481,7 +16748,7 @@ ${result.notice}`
|
|
|
16481
16748
|
strict: false,
|
|
16482
16749
|
execute: async (input) => {
|
|
16483
16750
|
await this.ensurePrepared();
|
|
16484
|
-
const args =
|
|
16751
|
+
const args = isRecord9(input) ? input : {};
|
|
16485
16752
|
const prefix = typeof args.namePrefix === "string" ? args.namePrefix : "";
|
|
16486
16753
|
const group = typeof args.group === "string" ? args.group : void 0;
|
|
16487
16754
|
const serverIds = this.modelMcpServerIds();
|
|
@@ -16641,7 +16908,7 @@ ${result.notice}`
|
|
|
16641
16908
|
function createResolveMissingFunctionTool(runtime) {
|
|
16642
16909
|
return async ({ name, toolCall }) => {
|
|
16643
16910
|
const names = [name];
|
|
16644
|
-
if (
|
|
16911
|
+
if (isRecord9(toolCall) && typeof toolCall.name === "string" && toolCall.name !== name) {
|
|
16645
16912
|
names.push(toolCall.name);
|
|
16646
16913
|
}
|
|
16647
16914
|
for (const candidate of names) {
|
|
@@ -16709,7 +16976,7 @@ function installLazyToolRuntimeOnAgent(agent, runtime) {
|
|
|
16709
16976
|
}
|
|
16710
16977
|
}
|
|
16711
16978
|
function restoredProviderData(providerData) {
|
|
16712
|
-
if (!
|
|
16979
|
+
if (!isRecord9(providerData)) return void 0;
|
|
16713
16980
|
const restored = { ...providerData };
|
|
16714
16981
|
delete restored[DISPATCH_MARKER_KEY];
|
|
16715
16982
|
delete restored[SEARCH_MARKER_KEY];
|
|
@@ -16732,13 +16999,13 @@ function restoreGenericDispatchHistory(input) {
|
|
|
16732
16999
|
return changed ? restoredInput : input;
|
|
16733
17000
|
}
|
|
16734
17001
|
function restoreGenericDispatchHistoryItem(candidate) {
|
|
16735
|
-
if (!
|
|
17002
|
+
if (!isRecord9(candidate) || candidate.type !== "function_call" && candidate.type !== "tool_search_call")
|
|
16736
17003
|
return candidate;
|
|
16737
|
-
const providerData =
|
|
17004
|
+
const providerData = isRecord9(candidate.providerData) ? candidate.providerData : void 0;
|
|
16738
17005
|
const marker = providerData?.[DISPATCH_MARKER_KEY];
|
|
16739
|
-
const hasDispatchMarker =
|
|
17006
|
+
const hasDispatchMarker = isRecord9(marker) && marker.version === 1 && typeof marker.arguments === "string";
|
|
16740
17007
|
const searchMarker = providerData?.[SEARCH_MARKER_KEY];
|
|
16741
|
-
const hasSearchMarker =
|
|
17008
|
+
const hasSearchMarker = isRecord9(searchMarker) && (searchMarker.version === 1 || searchMarker.version === 2) && typeof searchMarker.output === "string";
|
|
16742
17009
|
const hasFamilyMarker = providerData !== void 0 && FAMILY_DISCLOSURE_MARKER_KEY in providerData;
|
|
16743
17010
|
if (!hasDispatchMarker && !hasSearchMarker && !hasFamilyMarker) {
|
|
16744
17011
|
return candidate;
|
|
@@ -16756,11 +17023,11 @@ function restoreGenericDispatchHistoryItem(candidate) {
|
|
|
16756
17023
|
function callId2(candidate) {
|
|
16757
17024
|
if (typeof candidate.callId === "string") return candidate.callId;
|
|
16758
17025
|
if (typeof candidate.call_id === "string") return candidate.call_id;
|
|
16759
|
-
const providerData =
|
|
17026
|
+
const providerData = isRecord9(candidate.providerData) ? candidate.providerData : null;
|
|
16760
17027
|
return providerData && typeof providerData.call_id === "string" ? providerData.call_id : null;
|
|
16761
17028
|
}
|
|
16762
17029
|
function isInternalGenericDispatchRegistrationItem(candidate) {
|
|
16763
|
-
if (!
|
|
17030
|
+
if (!isRecord9(candidate)) return false;
|
|
16764
17031
|
if (candidate.type !== "tool_search_call" && candidate.type !== "tool_search_output")
|
|
16765
17032
|
return false;
|
|
16766
17033
|
return callId2(candidate)?.startsWith(INTERNAL_DISPATCH_REGISTRATION_CALL_PREFIX) ?? false;
|
|
@@ -16769,17 +17036,17 @@ function restoreGenericSearchResults(input) {
|
|
|
16769
17036
|
if (!Array.isArray(input)) return input;
|
|
16770
17037
|
const disclosures = /* @__PURE__ */ new Map();
|
|
16771
17038
|
for (const candidate of input) {
|
|
16772
|
-
if (!
|
|
17039
|
+
if (!isRecord9(candidate) || candidate.type !== "function_call") continue;
|
|
16773
17040
|
const id = callId2(candidate);
|
|
16774
|
-
const marker =
|
|
16775
|
-
if (id &&
|
|
17041
|
+
const marker = isRecord9(candidate.providerData) ? candidate.providerData[SEARCH_MARKER_KEY] : void 0;
|
|
17042
|
+
if (id && isRecord9(marker) && (marker.version === 1 || marker.version === 2) && typeof marker.output === "string") {
|
|
16776
17043
|
disclosures.set(id, marker.output);
|
|
16777
17044
|
}
|
|
16778
17045
|
}
|
|
16779
17046
|
if (disclosures.size === 0) return input;
|
|
16780
17047
|
let changed = false;
|
|
16781
17048
|
const restored = input.map((candidate) => {
|
|
16782
|
-
if (!
|
|
17049
|
+
if (!isRecord9(candidate) || candidate.type !== "function_call_result") {
|
|
16783
17050
|
return candidate;
|
|
16784
17051
|
}
|
|
16785
17052
|
const id = callId2(candidate);
|
|
@@ -16794,9 +17061,9 @@ function restoreGenericDispatchHistoryItems(input) {
|
|
|
16794
17061
|
return restoreGenericDispatchHistory(input);
|
|
16795
17062
|
}
|
|
16796
17063
|
function transformGenericDispatchCall(candidate, runtime, preparedSearch) {
|
|
16797
|
-
if (!
|
|
17064
|
+
if (!isRecord9(candidate) || candidate.type !== "function_call") return [candidate];
|
|
16798
17065
|
if (candidate.name === TOOL_SEARCH_NAME && typeof candidate.arguments === "string") {
|
|
16799
|
-
const providerData2 =
|
|
17066
|
+
const providerData2 = isRecord9(candidate.providerData) ? candidate.providerData : {};
|
|
16800
17067
|
if (SEARCH_MARKER_KEY in providerData2) {
|
|
16801
17068
|
throw new Error("Provider function call collided with lazy-search metadata");
|
|
16802
17069
|
}
|
|
@@ -16821,10 +17088,10 @@ function transformGenericDispatchCall(candidate, runtime, preparedSearch) {
|
|
|
16821
17088
|
const name = dispatch2 && typeof dispatch2.name === "string" ? dispatch2.name : null;
|
|
16822
17089
|
const args = dispatch2?.arguments;
|
|
16823
17090
|
const originalCallId = callId2(candidate);
|
|
16824
|
-
if (!name || !
|
|
17091
|
+
if (!name || !isRecord9(args) || !runtime.resolveFunctionTool(name) || !originalCallId) {
|
|
16825
17092
|
return [candidate];
|
|
16826
17093
|
}
|
|
16827
|
-
const providerData =
|
|
17094
|
+
const providerData = isRecord9(candidate.providerData) ? candidate.providerData : {};
|
|
16828
17095
|
if (DISPATCH_MARKER_KEY in providerData) {
|
|
16829
17096
|
throw new Error("Provider function call collided with lazy-dispatch metadata");
|
|
16830
17097
|
}
|
|
@@ -16854,8 +17121,8 @@ function restoreDirectDeferredCallArgumentTypes(candidate, runtime) {
|
|
|
16854
17121
|
return restored === null ? candidate : { ...candidate, arguments: restored };
|
|
16855
17122
|
}
|
|
16856
17123
|
async function transformResponseItem(item, runtime, signal) {
|
|
16857
|
-
if (
|
|
16858
|
-
const providerData =
|
|
17124
|
+
if (isRecord9(item) && item.type === "tool_search_call") {
|
|
17125
|
+
const providerData = isRecord9(item.providerData) ? item.providerData : {};
|
|
16859
17126
|
if ((item.execution ?? providerData.execution) === "client") {
|
|
16860
17127
|
if (SEARCH_MARKER_KEY in providerData)
|
|
16861
17128
|
throw new Error("Provider tool-search call collided with lazy-search metadata");
|
|
@@ -16874,12 +17141,12 @@ async function transformResponseItem(item, runtime, signal) {
|
|
|
16874
17141
|
if (runtime.transport !== "generic_dispatch") {
|
|
16875
17142
|
return [
|
|
16876
17143
|
withFamilyDisclosure(
|
|
16877
|
-
|
|
17144
|
+
isRecord9(item) && item.type === "function_call" ? restoreDirectDeferredCallArgumentTypes(item, runtime) : item,
|
|
16878
17145
|
runtime
|
|
16879
17146
|
)
|
|
16880
17147
|
];
|
|
16881
17148
|
}
|
|
16882
|
-
const search =
|
|
17149
|
+
const search = isRecord9(item) && item.type === "function_call" && item.name === TOOL_SEARCH_NAME && typeof item.arguments === "string";
|
|
16883
17150
|
const items = transformGenericDispatchCall(
|
|
16884
17151
|
item,
|
|
16885
17152
|
runtime,
|
|
@@ -16893,11 +17160,11 @@ async function transformResponseOutput(output, runtime, signal) {
|
|
|
16893
17160
|
return unchanged ? output : transformed;
|
|
16894
17161
|
}
|
|
16895
17162
|
function withFamilyDisclosure(candidate, runtime) {
|
|
16896
|
-
if (!
|
|
17163
|
+
if (!isRecord9(candidate) || candidate.type !== "function_call") return candidate;
|
|
16897
17164
|
if (typeof candidate.name !== "string" || !isInteractionEntryToolName(candidate.name)) {
|
|
16898
17165
|
return candidate;
|
|
16899
17166
|
}
|
|
16900
|
-
const providerData =
|
|
17167
|
+
const providerData = isRecord9(candidate.providerData) ? candidate.providerData : {};
|
|
16901
17168
|
if (FAMILY_DISCLOSURE_MARKER_KEY in providerData) return candidate;
|
|
16902
17169
|
const tools = runtime.familyDisclosure(candidate.name);
|
|
16903
17170
|
if (tools.length === 0) return candidate;
|
|
@@ -16914,18 +17181,18 @@ function withFamilyDisclosure(candidate, runtime) {
|
|
|
16914
17181
|
};
|
|
16915
17182
|
}
|
|
16916
17183
|
function familyDisclosure(candidate) {
|
|
16917
|
-
const providerData =
|
|
17184
|
+
const providerData = isRecord9(candidate.providerData) ? candidate.providerData : null;
|
|
16918
17185
|
const marker = providerData?.[FAMILY_DISCLOSURE_MARKER_KEY];
|
|
16919
|
-
if (!
|
|
17186
|
+
if (!isRecord9(marker) || marker.version !== 1 || !Array.isArray(marker.tools)) return null;
|
|
16920
17187
|
const tools = marker.tools.filter(
|
|
16921
|
-
(tool2) =>
|
|
17188
|
+
(tool2) => isRecord9(tool2) && typeof tool2.name === "string"
|
|
16922
17189
|
);
|
|
16923
17190
|
return tools.length > 0 ? { tools, viaToolInvoke: marker.viaToolInvoke === true } : null;
|
|
16924
17191
|
}
|
|
16925
17192
|
function disclosedToolNames(tools) {
|
|
16926
17193
|
if (!Array.isArray(tools)) return [];
|
|
16927
17194
|
return tools.flatMap(
|
|
16928
|
-
(tool2) =>
|
|
17195
|
+
(tool2) => isRecord9(tool2) && typeof tool2.name === "string" ? [tool2.name] : []
|
|
16929
17196
|
);
|
|
16930
17197
|
}
|
|
16931
17198
|
function genericSearchOutputNames(output) {
|
|
@@ -16967,15 +17234,15 @@ function expandInteractionFamilyDisclosures(input) {
|
|
|
16967
17234
|
for (let index = 0; index < input.length; index += 1) {
|
|
16968
17235
|
const original = input[index];
|
|
16969
17236
|
const candidate = original;
|
|
16970
|
-
const result =
|
|
17237
|
+
const result = isRecord9(candidate) && STEP_RESULT_ITEM_TYPES.has(String(candidate.type));
|
|
16971
17238
|
if (!result) flush(index);
|
|
16972
17239
|
expanded?.push(original);
|
|
16973
|
-
if (!
|
|
17240
|
+
if (!isRecord9(candidate)) continue;
|
|
16974
17241
|
if (candidate.type === "tool_search_call") {
|
|
16975
|
-
const providerData =
|
|
17242
|
+
const providerData = isRecord9(candidate.providerData) ? candidate.providerData : null;
|
|
16976
17243
|
const searchMarker = providerData?.[SEARCH_MARKER_KEY];
|
|
16977
17244
|
const id2 = callId2(candidate);
|
|
16978
|
-
if (id2 &&
|
|
17245
|
+
if (id2 && isRecord9(searchMarker) && typeof searchMarker.notice === "string")
|
|
16979
17246
|
pendingNotices.set(id2, searchMarker.notice);
|
|
16980
17247
|
continue;
|
|
16981
17248
|
}
|
|
@@ -16991,15 +17258,15 @@ function expandInteractionFamilyDisclosures(input) {
|
|
|
16991
17258
|
continue;
|
|
16992
17259
|
}
|
|
16993
17260
|
if (candidate.type === "function_call") {
|
|
16994
|
-
const providerData =
|
|
17261
|
+
const providerData = isRecord9(candidate.providerData) ? candidate.providerData : null;
|
|
16995
17262
|
const searchMarker = providerData?.[SEARCH_MARKER_KEY];
|
|
16996
|
-
if (
|
|
17263
|
+
if (isRecord9(searchMarker) && typeof searchMarker.output === "string") {
|
|
16997
17264
|
if (searchMarker.version === 1) {
|
|
16998
17265
|
for (const name of genericSearchOutputNames(searchMarker.output)) disclosed.add(name);
|
|
16999
17266
|
} else if (searchMarker.version === 2 && Array.isArray(searchMarker.tools)) {
|
|
17000
17267
|
const id3 = callId2(candidate);
|
|
17001
17268
|
if (id3)
|
|
17002
|
-
pending.set(id3, { tools: searchMarker.tools.filter(
|
|
17269
|
+
pending.set(id3, { tools: searchMarker.tools.filter(isRecord9), viaToolInvoke: true });
|
|
17003
17270
|
}
|
|
17004
17271
|
}
|
|
17005
17272
|
const id2 = callId2(candidate);
|
|
@@ -17053,19 +17320,39 @@ function prepareLazyToolRequest(request, runtime) {
|
|
|
17053
17320
|
tools: request.tools.filter((tool2) => !runtime.shouldHideSerializedTool(tool2))
|
|
17054
17321
|
};
|
|
17055
17322
|
}
|
|
17323
|
+
async function withAuthorizedHistoryToolNames(request, runtime) {
|
|
17324
|
+
if (typeof request.input === "string") return request;
|
|
17325
|
+
if (invalidHistoryToolNames(request.input).length === 0) return request;
|
|
17326
|
+
let complete = true;
|
|
17327
|
+
try {
|
|
17328
|
+
await runtime.ensurePrepared();
|
|
17329
|
+
} catch {
|
|
17330
|
+
complete = false;
|
|
17331
|
+
}
|
|
17332
|
+
const input = withProviderValidToolNames(request.input, {
|
|
17333
|
+
names: runtime.knownFunctionToolNames(),
|
|
17334
|
+
denote: complete,
|
|
17335
|
+
aliasUnbound: false,
|
|
17336
|
+
parametersOf: (name) => {
|
|
17337
|
+
const tool2 = runtime.resolveFunctionTool(name);
|
|
17338
|
+
return tool2 && isFunctionTool(tool2) ? tool2.parameters : void 0;
|
|
17339
|
+
}
|
|
17340
|
+
});
|
|
17341
|
+
return input === request.input ? request : { ...request, input };
|
|
17342
|
+
}
|
|
17056
17343
|
function startsTurn(input) {
|
|
17057
17344
|
if (typeof input === "string") return true;
|
|
17058
17345
|
const items = input;
|
|
17059
17346
|
let lastUser = -1;
|
|
17060
17347
|
items.forEach((item, index) => {
|
|
17061
|
-
if (
|
|
17348
|
+
if (isRecord9(item) && item.role === "user") lastUser = index;
|
|
17062
17349
|
});
|
|
17063
|
-
return lastUser >= 0 && items.slice(lastUser + 1).every((item) =>
|
|
17350
|
+
return lastUser >= 0 && items.slice(lastUser + 1).every((item) => isRecord9(item) && (item.role === "developer" || item.role === "system"));
|
|
17064
17351
|
}
|
|
17065
17352
|
function holdsOpeningToolLoad(input) {
|
|
17066
17353
|
if (typeof input === "string") return false;
|
|
17067
17354
|
const items = input;
|
|
17068
|
-
return items.some((item) =>
|
|
17355
|
+
return items.some((item) => isRecord9(item) && callId2(item) === OPENING_TOOL_LOAD_CALL_ID);
|
|
17069
17356
|
}
|
|
17070
17357
|
var LazyToolModel = class {
|
|
17071
17358
|
constructor(inner, runtime) {
|
|
@@ -17076,7 +17363,10 @@ var LazyToolModel = class {
|
|
|
17076
17363
|
const opening = await this.openingToolLoad(request);
|
|
17077
17364
|
if (opening) return opening;
|
|
17078
17365
|
await beforeModelRequest("model_entry");
|
|
17079
|
-
const prepared = prepareLazyToolRequest(
|
|
17366
|
+
const prepared = prepareLazyToolRequest(
|
|
17367
|
+
await withAuthorizedHistoryToolNames(request, this.runtime),
|
|
17368
|
+
this.runtime
|
|
17369
|
+
);
|
|
17080
17370
|
rememberPreparedModelRequest(prepared);
|
|
17081
17371
|
void notifyModelRequestCapture(prepared);
|
|
17082
17372
|
const response = await this.inner.getResponse(prepared);
|
|
@@ -17104,7 +17394,10 @@ var LazyToolModel = class {
|
|
|
17104
17394
|
return;
|
|
17105
17395
|
}
|
|
17106
17396
|
await beforeModelRequest("model_entry");
|
|
17107
|
-
const prepared = prepareLazyToolRequest(
|
|
17397
|
+
const prepared = prepareLazyToolRequest(
|
|
17398
|
+
await withAuthorizedHistoryToolNames(request, this.runtime),
|
|
17399
|
+
this.runtime
|
|
17400
|
+
);
|
|
17108
17401
|
rememberPreparedModelRequest(prepared);
|
|
17109
17402
|
void notifyModelRequestCapture(prepared);
|
|
17110
17403
|
let responseStartedPreparation = false;
|
|
@@ -17158,7 +17451,7 @@ var LazyToolModel = class {
|
|
|
17158
17451
|
};
|
|
17159
17452
|
function responseRequiresToolPreparation(response, runtime) {
|
|
17160
17453
|
return response.output.some(
|
|
17161
|
-
(item) =>
|
|
17454
|
+
(item) => isRecord9(item) && item.type === "function_call" && typeof item.name === "string" && runtime.requiresPreparationForFunctionCall(item.name)
|
|
17162
17455
|
);
|
|
17163
17456
|
}
|
|
17164
17457
|
var LazyToolModelProvider = class {
|
|
@@ -17194,21 +17487,21 @@ var CLIENT_TOOL_CALL_ITEM_TYPES = /* @__PURE__ */ new Set([
|
|
|
17194
17487
|
]);
|
|
17195
17488
|
function isClientToolWork(item) {
|
|
17196
17489
|
if (!item || typeof item !== "object") return false;
|
|
17197
|
-
const
|
|
17198
|
-
if (
|
|
17199
|
-
return (
|
|
17490
|
+
const record4 = item;
|
|
17491
|
+
if (record4.type === "tool_search_call") {
|
|
17492
|
+
return (record4.execution ?? record4.providerData?.execution) !== "server";
|
|
17200
17493
|
}
|
|
17201
|
-
return CLIENT_TOOL_CALL_ITEM_TYPES.has(String(
|
|
17494
|
+
return CLIENT_TOOL_CALL_ITEM_TYPES.has(String(record4.type));
|
|
17202
17495
|
}
|
|
17203
17496
|
function isAssistantMessageItem(item) {
|
|
17204
17497
|
if (!item || typeof item !== "object") return false;
|
|
17205
|
-
const
|
|
17206
|
-
return
|
|
17498
|
+
const record4 = item;
|
|
17499
|
+
return record4.type === "message" && (record4.role === void 0 || record4.role === "assistant");
|
|
17207
17500
|
}
|
|
17208
17501
|
function declaredAssistantMessagePhase(item) {
|
|
17209
17502
|
if (!item || typeof item !== "object") return void 0;
|
|
17210
|
-
const
|
|
17211
|
-
const phase =
|
|
17503
|
+
const record4 = item;
|
|
17504
|
+
const phase = record4.phase ?? record4.providerData?.phase;
|
|
17212
17505
|
return phase === "commentary" || phase === "final_answer" ? phase : void 0;
|
|
17213
17506
|
}
|
|
17214
17507
|
function providerMessageId(item) {
|
|
@@ -17356,38 +17649,38 @@ function imageDataByteLength(data) {
|
|
|
17356
17649
|
return data.every((value) => typeof value === "number") ? data.length : null;
|
|
17357
17650
|
}
|
|
17358
17651
|
if (!data || typeof data !== "object") return null;
|
|
17359
|
-
const
|
|
17360
|
-
if (
|
|
17361
|
-
return
|
|
17652
|
+
const record4 = data;
|
|
17653
|
+
if (record4.type === "Buffer" && Array.isArray(record4.data)) {
|
|
17654
|
+
return record4.data.every((value) => typeof value === "number") ? record4.data.length : null;
|
|
17362
17655
|
}
|
|
17363
|
-
const keys = Object.keys(
|
|
17364
|
-
return keys.length > 0 && keys.every((key) => /^\d+$/.test(key) && typeof
|
|
17656
|
+
const keys = Object.keys(record4);
|
|
17657
|
+
return keys.length > 0 && keys.every((key) => /^\d+$/.test(key) && typeof record4[key] === "number") ? keys.length : null;
|
|
17365
17658
|
}
|
|
17366
17659
|
function toolOutputMediaPreview(value) {
|
|
17367
17660
|
if (typeof value === "string") {
|
|
17368
17661
|
return sessionEventMediaPreviewFromDataUrl(value);
|
|
17369
17662
|
}
|
|
17370
17663
|
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
17371
|
-
const
|
|
17372
|
-
if (
|
|
17373
|
-
const source =
|
|
17664
|
+
const record4 = value;
|
|
17665
|
+
if (record4.type === "input_image") {
|
|
17666
|
+
const source = record4.image ?? record4.image_url ?? record4.imageUrl;
|
|
17374
17667
|
const url = typeof source === "string" ? source : source && typeof source === "object" ? source.url : null;
|
|
17375
17668
|
if (typeof url !== "string" || url.length === 0) return null;
|
|
17376
17669
|
return sessionEventMediaPreviewFromDataUrl(url) ?? sessionEventMediaPreview("image/*", null);
|
|
17377
17670
|
}
|
|
17378
|
-
if ((
|
|
17379
|
-
const mediaType2 = typeof
|
|
17380
|
-
return sessionEventMediaPreviewFromDataUrl(
|
|
17671
|
+
if ((record4.type === "image" || record4.type === "audio") && typeof record4.data === "string") {
|
|
17672
|
+
const mediaType2 = typeof record4.mimeType === "string" && record4.mimeType.length > 0 ? record4.mimeType : record4.type === "audio" ? "audio/*" : "image/png";
|
|
17673
|
+
return sessionEventMediaPreviewFromDataUrl(record4.data) ?? sessionEventMediaPreview(mediaType2, base64DecodedByteLength(record4.data));
|
|
17381
17674
|
}
|
|
17382
|
-
if (
|
|
17383
|
-
const resource =
|
|
17675
|
+
if (record4.type === "resource" && record4.resource && typeof record4.resource === "object") {
|
|
17676
|
+
const resource = record4.resource;
|
|
17384
17677
|
if (typeof resource.blob === "string") {
|
|
17385
17678
|
const mediaType2 = typeof resource.mimeType === "string" && resource.mimeType.length > 0 ? resource.mimeType : "application/octet-stream";
|
|
17386
17679
|
return sessionEventMediaPreviewFromDataUrl(resource.blob) ?? sessionEventMediaPreview(mediaType2, base64DecodedByteLength(resource.blob));
|
|
17387
17680
|
}
|
|
17388
17681
|
}
|
|
17389
|
-
if (
|
|
17390
|
-
const image =
|
|
17682
|
+
if (record4.type !== "image" || !record4.image || typeof record4.image !== "object") return null;
|
|
17683
|
+
const image = record4.image;
|
|
17391
17684
|
const mediaType = typeof image.mediaType === "string" && image.mediaType.length > 0 ? image.mediaType : "image/png";
|
|
17392
17685
|
if (typeof image.url === "string" && image.url.length > 0) {
|
|
17393
17686
|
return sessionEventMediaPreviewFromDataUrl(image.url) ?? sessionEventMediaPreview(mediaType, null);
|
|
@@ -17411,11 +17704,11 @@ function normalizeToolOutputForEvent(output) {
|
|
|
17411
17704
|
return normalized;
|
|
17412
17705
|
}
|
|
17413
17706
|
if (output && typeof output === "object") {
|
|
17414
|
-
const
|
|
17415
|
-
if (Array.isArray(
|
|
17707
|
+
const record4 = output;
|
|
17708
|
+
if (Array.isArray(record4.content)) {
|
|
17416
17709
|
return {
|
|
17417
|
-
...
|
|
17418
|
-
content:
|
|
17710
|
+
...record4,
|
|
17711
|
+
content: record4.content.map((el) => toolOutputMediaPreview(el) ?? el)
|
|
17419
17712
|
};
|
|
17420
17713
|
}
|
|
17421
17714
|
}
|
|
@@ -17637,9 +17930,9 @@ function webSearchRequestsFromResponse(response) {
|
|
|
17637
17930
|
let count = 0;
|
|
17638
17931
|
for (const item of output) {
|
|
17639
17932
|
if (!item || typeof item !== "object") continue;
|
|
17640
|
-
const
|
|
17641
|
-
const searchCall =
|
|
17642
|
-
if (searchCall &&
|
|
17933
|
+
const record4 = item;
|
|
17934
|
+
const searchCall = record4.type === "web_search_call" || record4.type === "hosted_tool_call" && record4.name === "web_search_call";
|
|
17935
|
+
if (searchCall && record4.status !== "failed") count += 1;
|
|
17643
17936
|
}
|
|
17644
17937
|
return count > 0 ? Math.min(count, MAX_WEB_SEARCH_REQUESTS) : void 0;
|
|
17645
17938
|
}
|
|
@@ -17650,9 +17943,9 @@ function gatewayBillingFromResponse(response) {
|
|
|
17650
17943
|
if (!response || typeof response !== "object" || Array.isArray(response)) {
|
|
17651
17944
|
return null;
|
|
17652
17945
|
}
|
|
17653
|
-
const
|
|
17654
|
-
const providerData =
|
|
17655
|
-
const metadataCandidate =
|
|
17946
|
+
const record4 = response;
|
|
17947
|
+
const providerData = record4.providerData && typeof record4.providerData === "object" && !Array.isArray(record4.providerData) ? record4.providerData : null;
|
|
17948
|
+
const metadataCandidate = record4.provider_metadata ?? record4.providerMetadata ?? providerData?.provider_metadata ?? providerData?.providerMetadata;
|
|
17656
17949
|
if (!metadataCandidate || typeof metadataCandidate !== "object" || Array.isArray(metadataCandidate)) {
|
|
17657
17950
|
return null;
|
|
17658
17951
|
}
|
|
@@ -17700,12 +17993,12 @@ function modelResponseServiceTierFromResponse(response) {
|
|
|
17700
17993
|
if (!response || typeof response !== "object") {
|
|
17701
17994
|
return null;
|
|
17702
17995
|
}
|
|
17703
|
-
const
|
|
17704
|
-
const direct =
|
|
17996
|
+
const record4 = response;
|
|
17997
|
+
const direct = record4.service_tier ?? record4.serviceTier;
|
|
17705
17998
|
if (typeof direct === "string" && direct.length > 0) {
|
|
17706
17999
|
return direct;
|
|
17707
18000
|
}
|
|
17708
|
-
const providerData =
|
|
18001
|
+
const providerData = record4.providerData && typeof record4.providerData === "object" ? record4.providerData : null;
|
|
17709
18002
|
const nested = providerData?.service_tier ?? providerData?.serviceTier;
|
|
17710
18003
|
return typeof nested === "string" && nested.length > 0 ? nested : null;
|
|
17711
18004
|
}
|
|
@@ -17729,11 +18022,11 @@ function usageFromResponse(response) {
|
|
|
17729
18022
|
if (!raw || typeof raw !== "object") {
|
|
17730
18023
|
return null;
|
|
17731
18024
|
}
|
|
17732
|
-
const
|
|
18025
|
+
const record4 = raw;
|
|
17733
18026
|
const chatDetails = response?.providerData?.usage?.prompt_tokens_details;
|
|
17734
18027
|
const usage = {
|
|
17735
18028
|
...numberProp(
|
|
17736
|
-
|
|
18029
|
+
record4,
|
|
17737
18030
|
"inputTokens",
|
|
17738
18031
|
"inputTokens",
|
|
17739
18032
|
"input_tokens",
|
|
@@ -17741,19 +18034,19 @@ function usageFromResponse(response) {
|
|
|
17741
18034
|
"prompt_tokens"
|
|
17742
18035
|
),
|
|
17743
18036
|
...numberProp(
|
|
17744
|
-
|
|
18037
|
+
record4,
|
|
17745
18038
|
"outputTokens",
|
|
17746
18039
|
"outputTokens",
|
|
17747
18040
|
"output_tokens",
|
|
17748
18041
|
"completionTokens",
|
|
17749
18042
|
"completion_tokens"
|
|
17750
18043
|
),
|
|
17751
|
-
...numberProp(
|
|
18044
|
+
...numberProp(record4, "totalTokens", "totalTokens", "total_tokens"),
|
|
17752
18045
|
...inputTokenDetailsProp(
|
|
17753
|
-
chatDetails === void 0 ?
|
|
18046
|
+
chatDetails === void 0 ? record4 : { prompt_tokens_details: chatDetails }
|
|
17754
18047
|
),
|
|
17755
|
-
...outputTokenDetailsProp(
|
|
17756
|
-
...requestUsageEntriesProp(
|
|
18048
|
+
...outputTokenDetailsProp(record4),
|
|
18049
|
+
...requestUsageEntriesProp(record4)
|
|
17757
18050
|
};
|
|
17758
18051
|
return Object.keys(usage).length > 0 ? usage : null;
|
|
17759
18052
|
}
|
|
@@ -18051,9 +18344,9 @@ function responsesOutputText(response) {
|
|
|
18051
18344
|
return text2;
|
|
18052
18345
|
}
|
|
18053
18346
|
function responsesFinishReason(response) {
|
|
18054
|
-
const
|
|
18055
|
-
if (
|
|
18056
|
-
return
|
|
18347
|
+
const record4 = response;
|
|
18348
|
+
if (record4?.status !== "incomplete") return "stop";
|
|
18349
|
+
return record4.incomplete_details?.reason === "content_filter" ? "content_filter" : "length";
|
|
18057
18350
|
}
|
|
18058
18351
|
async function runResponsesCall(client, provider, modelId, request, options) {
|
|
18059
18352
|
if (request.stop?.length) {
|
|
@@ -18510,10 +18803,10 @@ function totalCoversKnownComponents(total, inputTokens, outputTokens) {
|
|
|
18510
18803
|
function rejectInconsistentRequestTotals(requestEntries, rejectedFields) {
|
|
18511
18804
|
let inconsistent = false;
|
|
18512
18805
|
for (const [index, entry] of requestEntries.entries()) {
|
|
18513
|
-
const
|
|
18514
|
-
const selectedInput = firstPresentEntry(
|
|
18515
|
-
const selectedOutput = firstPresentEntry(
|
|
18516
|
-
const selectedTotal = firstPresentEntry(
|
|
18806
|
+
const record4 = entry;
|
|
18807
|
+
const selectedInput = firstPresentEntry(record4, ["inputTokens", "input_tokens"]);
|
|
18808
|
+
const selectedOutput = firstPresentEntry(record4, ["outputTokens", "output_tokens"]);
|
|
18809
|
+
const selectedTotal = firstPresentEntry(record4, ["totalTokens", "total_tokens"]);
|
|
18517
18810
|
if (!selectedInput || !selectedOutput || !selectedTotal) continue;
|
|
18518
18811
|
const inputTokens = modelUsageTokenCountOrNull(selectedInput.value);
|
|
18519
18812
|
const outputTokens = modelUsageTokenCountOrNull(selectedOutput.value);
|
|
@@ -18593,10 +18886,10 @@ function detailRecords(details, path, rejectedFields) {
|
|
|
18593
18886
|
}
|
|
18594
18887
|
return { records, complete };
|
|
18595
18888
|
}
|
|
18596
|
-
function firstPresentEntry(
|
|
18889
|
+
function firstPresentEntry(record4, keys) {
|
|
18597
18890
|
for (const key of keys) {
|
|
18598
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
18599
|
-
return { key, value:
|
|
18891
|
+
if (Object.prototype.hasOwnProperty.call(record4, key) && record4[key] !== void 0) {
|
|
18892
|
+
return { key, value: record4[key] };
|
|
18600
18893
|
}
|
|
18601
18894
|
}
|
|
18602
18895
|
return null;
|
|
@@ -18643,7 +18936,7 @@ function boundedField(value, maxBytes) {
|
|
|
18643
18936
|
while (end > 0 && (bytes[end] & 192) === 128) end -= 1;
|
|
18644
18937
|
return `${new TextDecoder().decode(bytes.subarray(0, end))}${TRUNCATION_MARKER}`;
|
|
18645
18938
|
}
|
|
18646
|
-
function
|
|
18939
|
+
function record3(value) {
|
|
18647
18940
|
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
18648
18941
|
}
|
|
18649
18942
|
var SAFETY_CODES = /* @__PURE__ */ new Set([
|
|
@@ -18690,7 +18983,7 @@ var ResponsesStreamingTerminalError = class extends Error {
|
|
|
18690
18983
|
super(`Responses request terminated unsuccessfully (${eventType}).`);
|
|
18691
18984
|
this.eventType = eventType;
|
|
18692
18985
|
this.name = "ResponsesStreamingTerminalError";
|
|
18693
|
-
const error =
|
|
18986
|
+
const error = record3(source);
|
|
18694
18987
|
this.code = boundedField(error?.code, FIELD_MAX_BYTES);
|
|
18695
18988
|
this.type = boundedField(error?.type, FIELD_MAX_BYTES);
|
|
18696
18989
|
this.detail = boundedField(error?.message ?? source, DIAGNOSTIC_MAX_BYTES) ?? this.message;
|
|
@@ -18719,13 +19012,13 @@ var ResponsesStreamingTerminalError = class extends Error {
|
|
|
18719
19012
|
category;
|
|
18720
19013
|
};
|
|
18721
19014
|
function responsesStreamingTerminalError(event, headers) {
|
|
18722
|
-
const value =
|
|
19015
|
+
const value = record3(event);
|
|
18723
19016
|
if (value?.type !== "response.failed" && value?.type !== "response.error" && value?.type !== "error") {
|
|
18724
19017
|
return void 0;
|
|
18725
19018
|
}
|
|
18726
19019
|
return new ResponsesStreamingTerminalError(
|
|
18727
19020
|
value.type,
|
|
18728
|
-
value.error ??
|
|
19021
|
+
value.error ?? record3(value.response)?.error ?? value,
|
|
18729
19022
|
headers
|
|
18730
19023
|
);
|
|
18731
19024
|
}
|
|
@@ -19100,7 +19393,8 @@ var OpenGeniResponsesModel = class extends AppendOnlyOpenAIResponsesModel {
|
|
|
19100
19393
|
let outcome = "completed";
|
|
19101
19394
|
try {
|
|
19102
19395
|
const input = typeof request.input === "string" ? request.input : projectHistoryForProvider(request.input, "responses", {
|
|
19103
|
-
declaresAdditionalTools: responsesRouteDeclaresAdditionalTools(this.provider.kind)
|
|
19396
|
+
declaresAdditionalTools: responsesRouteDeclaresAdditionalTools(this.provider.kind),
|
|
19397
|
+
knownToolNames: requestFunctionToolNames(request.tools)
|
|
19104
19398
|
});
|
|
19105
19399
|
return super._buildResponsesCreateRequest(
|
|
19106
19400
|
input === request.input ? request : { ...request, input },
|
|
@@ -19348,6 +19642,8 @@ export {
|
|
|
19348
19642
|
isPreemptedModelResponse,
|
|
19349
19643
|
preemptedResponseCutOffText,
|
|
19350
19644
|
preemptedResponseDone,
|
|
19645
|
+
prefixedMcpToolName,
|
|
19646
|
+
legacyMcpToolDigest,
|
|
19351
19647
|
ProviderHistoryIncompatibleError,
|
|
19352
19648
|
projectHistoryForProvider,
|
|
19353
19649
|
recordStableSystemPromptPrefix,
|
|
@@ -19437,8 +19733,6 @@ export {
|
|
|
19437
19733
|
nextMcpInputRequiredStep,
|
|
19438
19734
|
MCP_INPUT_PENDING_RESULT,
|
|
19439
19735
|
withAccountLine,
|
|
19440
|
-
prefixedMcpToolName,
|
|
19441
|
-
legacyMcpToolDigest,
|
|
19442
19736
|
HARNESS_CONTROL_MCP_SERVER_ID,
|
|
19443
19737
|
HARNESS_CONTROL_FIRST_PARTY_TOOLS,
|
|
19444
19738
|
isHarnessControlMcpToolName,
|
|
@@ -19479,4 +19773,4 @@ export {
|
|
|
19479
19773
|
resolveTurnModel,
|
|
19480
19774
|
MultiProviderModelProvider
|
|
19481
19775
|
};
|
|
19482
|
-
//# sourceMappingURL=chunk-
|
|
19776
|
+
//# sourceMappingURL=chunk-FNAYH3SN.js.map
|