@openclaw/ai 2026.7.2-beta.3 → 2026.7.2-beta.4
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/README.md +6 -5
- package/dist/{anthropic-D7SyZQ5v.mjs → anthropic-CrUDIBpM.mjs} +123 -16
- package/dist/{api-registry-DXBIXISf.d.mts → api-registry-BMphkFf1.d.mts} +1 -2
- package/dist/{azure-openai-responses-BkZgyZ3I.mjs → azure-openai-responses-CbrpVeEv.mjs} +7 -10
- package/dist/{env-api-keys-DnhYpc27.mjs → env-api-keys-DrgeBuva.mjs} +1 -1
- package/dist/{event-stream-BPemFrFW.d.mts → event-stream-Douf9dob.d.mts} +1 -1
- package/dist/event-stream.d.mts +1 -1
- package/dist/{google-C_biGbV7.mjs → google-Cs62KA7t.mjs} +4 -4
- package/dist/{google-shared-BK-NoHl8.mjs → google-shared-CMLI-tCZ.mjs} +3 -3
- package/dist/{google-vertex-CvdzF1U7.mjs → google-vertex-B4SD3U0f.mjs} +3 -3
- package/dist/host-WvWBo4h8.d.mts +173 -0
- package/dist/host-XYGZcgO8.mjs +98 -0
- package/dist/index-BVVgDSdq.d.mts +1 -0
- package/dist/index.d.mts +7 -50
- package/dist/index.mjs +1 -1
- package/dist/internal/anthropic.d.mts +2 -2
- package/dist/internal/anthropic.mjs +2 -2
- package/dist/internal/openai.d.mts +2 -280
- package/dist/internal/openai.mjs +5 -5
- package/dist/internal/runtime.d.mts +8 -5
- package/dist/internal/runtime.mjs +19 -10
- package/dist/internal/shared.d.mts +1 -1
- package/dist/internal/shared.mjs +1 -1
- package/dist/{mistral-BdrQmDWp.mjs → mistral-D5Ps7Led.mjs} +4 -4
- package/dist/openai-CoGicoDt.d.mts +332 -0
- package/dist/{openai-chatgpt-responses-DP63Qt01.mjs → openai-chatgpt-responses-h0o5yV8Y.mjs} +40 -43
- package/dist/{openai-completions-zLDfebnN.mjs → openai-completions-exO8NFQf.mjs} +316 -100
- package/dist/{openai-responses-ClspWt4I.mjs → openai-responses-BHpmtUKo.mjs} +5 -5
- package/dist/{openai-responses-shared-CwnGU0KW.mjs → openai-responses-shared-CzCurmY1.mjs} +230 -71
- package/dist/{openai-tool-projection-WHf2nuOI.mjs → openai-tool-projection-ITOU9bG1.mjs} +1 -1
- package/dist/{provider-error-LMfTEkfO.mjs → provider-error-C4VvV_3t.mjs} +2 -1
- package/dist/providers.d.mts +1 -1
- package/dist/providers.mjs +8 -8
- package/dist/{stream-first-event-timeout-RjWszj8c.mjs → stream-first-event-timeout-DP4xEyBY.mjs} +45 -1
- package/dist/{transform-messages-eb6lxDLB.mjs → system-prompt-cache-boundary-CbHeV4_l.mjs} +164 -160
- package/dist/transports.d.mts +590 -0
- package/dist/transports.mjs +5701 -0
- package/dist/{types-CYORveZ7.d.mts → types-AFwwWium.d.mts} +1 -0
- package/dist/types.d.mts +4 -4
- package/dist/{validation-BX8euiDv.d.mts → validation-sxvxC8J-.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/npm-shrinkwrap.json +43 -50
- package/package.json +36 -10
- package/dist/host-4t713IeR.mjs +0 -37
- /package/dist/{index-BoTnz8cv.d.mts → anthropic-BoTnz8cv.d.mts} +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { n as getAiTransportHost } from "./host-
|
|
1
|
+
import { n as getAiTransportHost } from "./host-XYGZcgO8.mjs";
|
|
2
|
+
import { C as isImageWithMediaPayload, T as isRecord, _ as normalizeOptionalString, a as stripSystemPromptCacheBoundary, c as transformMessages, g as normalizeLowercaseStringOrEmpty, x as extractToolResultText, y as describeToolResultMediaPlaceholder } from "./system-prompt-cache-boundary-CbHeV4_l.mjs";
|
|
3
|
+
import { t as sanitizeSurrogates } from "./sanitize-unicode-DT5o51ur.mjs";
|
|
2
4
|
import { n as calculateCost, r as clampThinkingLevel } from "./model-utils-1GiZ2_rr.mjs";
|
|
3
5
|
import { t as headersToRecord } from "./headers-B_e4-1J0.mjs";
|
|
4
6
|
import { n as parseStreamingJson } from "./json-parse-BvXNt1-7.mjs";
|
|
5
|
-
import { t as sanitizeSurrogates } from "./sanitize-unicode-DT5o51ur.mjs";
|
|
6
|
-
import { D as normalizeLowercaseStringOrEmpty, O as normalizeOptionalString, f as isRecord, i as extractToolResultText, n as describeToolResultMediaPlaceholder, o as isImageWithMediaPayload, t as transformMessages, w as stripSystemPromptCacheBoundary } from "./transform-messages-eb6lxDLB.mjs";
|
|
7
|
-
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-RjWszj8c.mjs";
|
|
8
|
-
import { t as projectOpenAITools } from "./openai-tool-projection-WHf2nuOI.mjs";
|
|
9
7
|
import { t as shortHash } from "./hash-CHgqbJmD.mjs";
|
|
8
|
+
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-DP4xEyBY.mjs";
|
|
9
|
+
import { t as projectOpenAITools } from "./openai-tool-projection-ITOU9bG1.mjs";
|
|
10
10
|
import { createHash, randomUUID } from "node:crypto";
|
|
11
11
|
//#region packages/normalization-core/src/string-normalization.ts
|
|
12
12
|
/** Coerces entries to strings, trims them, and drops empty results. */
|
|
@@ -1076,6 +1076,66 @@ function resolveResponsesMessageSnapshotCollapse(params) {
|
|
|
1076
1076
|
return { kind: "keep" };
|
|
1077
1077
|
}
|
|
1078
1078
|
//#endregion
|
|
1079
|
+
//#region packages/ai/src/providers/openai-responses-terminal-usage.ts
|
|
1080
|
+
function readCount(value) {
|
|
1081
|
+
return typeof value === "number" && Number.isFinite(value) ? value : 0;
|
|
1082
|
+
}
|
|
1083
|
+
/**
|
|
1084
|
+
* Split a terminal usage payload into the priced buckets.
|
|
1085
|
+
*
|
|
1086
|
+
* OpenAI includes cache reads and writes in `input_tokens`, so both are subtracted out of the
|
|
1087
|
+
* billable input bucket. `total_tokens` comes from the payload, but never below the sum of the
|
|
1088
|
+
* split buckets: proxies routinely omit it (reporting 0 would understate the turn), and a payload
|
|
1089
|
+
* whose `cached_tokens` exceeds `input_tokens` clamps the input bucket, leaving the reported total
|
|
1090
|
+
* short of what the buckets actually price.
|
|
1091
|
+
*/
|
|
1092
|
+
function mapResponsesTerminalUsage(usage) {
|
|
1093
|
+
if (!usage) return;
|
|
1094
|
+
const cacheRead = readCount(usage.input_tokens_details?.cached_tokens);
|
|
1095
|
+
const cacheWrite = readCount(usage.input_tokens_details?.cache_write_tokens);
|
|
1096
|
+
const input = Math.max(0, readCount(usage.input_tokens) - cacheRead - cacheWrite);
|
|
1097
|
+
const output = readCount(usage.output_tokens);
|
|
1098
|
+
const bucketTotal = input + output + cacheRead + cacheWrite;
|
|
1099
|
+
return {
|
|
1100
|
+
input,
|
|
1101
|
+
output,
|
|
1102
|
+
cacheRead,
|
|
1103
|
+
cacheWrite,
|
|
1104
|
+
totalTokens: Math.max(bucketTotal, readCount(usage.total_tokens))
|
|
1105
|
+
};
|
|
1106
|
+
}
|
|
1107
|
+
/** Reasoning tokens are reported by the agent path only; the package path does not track them. */
|
|
1108
|
+
function readResponsesReasoningTokens(usage) {
|
|
1109
|
+
const reasoningTokens = usage?.output_tokens_details?.reasoning_tokens;
|
|
1110
|
+
return typeof reasoningTokens === "number" && Number.isFinite(reasoningTokens) ? reasoningTokens : void 0;
|
|
1111
|
+
}
|
|
1112
|
+
function mapResponsesTerminalStopReason(status) {
|
|
1113
|
+
if (!status) return "stop";
|
|
1114
|
+
switch (status) {
|
|
1115
|
+
case "completed": return "stop";
|
|
1116
|
+
case "incomplete": return "length";
|
|
1117
|
+
case "failed":
|
|
1118
|
+
case "cancelled": return "error";
|
|
1119
|
+
case "in_progress":
|
|
1120
|
+
case "queued": return "stop";
|
|
1121
|
+
default: throw new Error(`Unhandled stop reason: ${String(status)}`);
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
/**
|
|
1125
|
+
* Resolve the terminal stop reason, including the two overrides every Responses path shares: a
|
|
1126
|
+
* content-filtered turn is a provider error rather than a truncated answer, and a turn that
|
|
1127
|
+
* produced tool calls reports `toolUse` instead of a plain stop.
|
|
1128
|
+
*/
|
|
1129
|
+
function resolveResponsesTerminalStopReason(params) {
|
|
1130
|
+
if (params.status === "incomplete" && params.incompleteReason === "content_filter") return {
|
|
1131
|
+
stopReason: "error",
|
|
1132
|
+
errorMessage: "Provider incomplete_reason: content_filter"
|
|
1133
|
+
};
|
|
1134
|
+
const stopReason = mapResponsesTerminalStopReason(params.status);
|
|
1135
|
+
if (stopReason === "stop" && params.hasToolCall) return { stopReason: "toolUse" };
|
|
1136
|
+
return { stopReason };
|
|
1137
|
+
}
|
|
1138
|
+
//#endregion
|
|
1079
1139
|
//#region packages/ai/src/providers/openai-responses-tool-call-tracker.ts
|
|
1080
1140
|
function readIdentityValue(value) {
|
|
1081
1141
|
return (typeof value === "string" ? value.trim() : "") || void 0;
|
|
@@ -1152,6 +1212,151 @@ function createResponsesToolCallTracker() {
|
|
|
1152
1212
|
};
|
|
1153
1213
|
}
|
|
1154
1214
|
//#endregion
|
|
1215
|
+
//#region packages/ai/src/providers/openai-tool-schema-compat.ts
|
|
1216
|
+
const OPENAI_STRICT_COMPAT_SCHEMA_MAP_KEYS = /* @__PURE__ */ new Set([
|
|
1217
|
+
"$defs",
|
|
1218
|
+
"definitions",
|
|
1219
|
+
"dependentSchemas",
|
|
1220
|
+
"dependencies",
|
|
1221
|
+
"patternProperties",
|
|
1222
|
+
"properties"
|
|
1223
|
+
]);
|
|
1224
|
+
const OPENAI_NULLABLE_ANNOTATION_KEYS = /* @__PURE__ */ new Set([
|
|
1225
|
+
"default",
|
|
1226
|
+
"description",
|
|
1227
|
+
"examples",
|
|
1228
|
+
"format",
|
|
1229
|
+
"title"
|
|
1230
|
+
]);
|
|
1231
|
+
const OPENAI_STRICT_COMPAT_SCHEMA_NESTED_KEYS = /* @__PURE__ */ new Set([
|
|
1232
|
+
"additionalItems",
|
|
1233
|
+
"additionalProperties",
|
|
1234
|
+
"allOf",
|
|
1235
|
+
"anyOf",
|
|
1236
|
+
"contains",
|
|
1237
|
+
"contentSchema",
|
|
1238
|
+
"else",
|
|
1239
|
+
"if",
|
|
1240
|
+
"items",
|
|
1241
|
+
"not",
|
|
1242
|
+
"oneOf",
|
|
1243
|
+
"prefixItems",
|
|
1244
|
+
"propertyNames",
|
|
1245
|
+
"then",
|
|
1246
|
+
"unevaluatedItems",
|
|
1247
|
+
"unevaluatedProperties"
|
|
1248
|
+
]);
|
|
1249
|
+
function normalizeOpenAIStrictCompatSchemaMap(schema) {
|
|
1250
|
+
if (!schema || typeof schema !== "object" || Array.isArray(schema)) return schema;
|
|
1251
|
+
let changed = false;
|
|
1252
|
+
const normalized = {};
|
|
1253
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
1254
|
+
const next = normalizeOpenAIStrictCompatSchemaRecursive(value, { promoteEmptyObject: false });
|
|
1255
|
+
normalized[key] = next;
|
|
1256
|
+
changed ||= next !== value;
|
|
1257
|
+
}
|
|
1258
|
+
return changed ? normalized : schema;
|
|
1259
|
+
}
|
|
1260
|
+
function normalizeOpenAIStrictCompatSchemaRecursive(schema, options) {
|
|
1261
|
+
if (Array.isArray(schema)) {
|
|
1262
|
+
let changed = false;
|
|
1263
|
+
const normalized = schema.map((entry) => {
|
|
1264
|
+
const next = normalizeOpenAIStrictCompatSchemaRecursive(entry, { promoteEmptyObject: false });
|
|
1265
|
+
changed ||= next !== entry;
|
|
1266
|
+
return next;
|
|
1267
|
+
});
|
|
1268
|
+
return changed ? normalized : schema;
|
|
1269
|
+
}
|
|
1270
|
+
if (!schema || typeof schema !== "object") return schema;
|
|
1271
|
+
const record = schema;
|
|
1272
|
+
let changed = false;
|
|
1273
|
+
let hadNullType = false;
|
|
1274
|
+
const normalized = {};
|
|
1275
|
+
for (const [key, value] of Object.entries(record)) {
|
|
1276
|
+
if (value === null && OPENAI_NULLABLE_ANNOTATION_KEYS.has(key)) {
|
|
1277
|
+
changed = true;
|
|
1278
|
+
continue;
|
|
1279
|
+
}
|
|
1280
|
+
if (value === null && key === "type") {
|
|
1281
|
+
hadNullType = true;
|
|
1282
|
+
changed = true;
|
|
1283
|
+
continue;
|
|
1284
|
+
}
|
|
1285
|
+
const next = OPENAI_STRICT_COMPAT_SCHEMA_MAP_KEYS.has(key) ? normalizeOpenAIStrictCompatSchemaMap(value) : OPENAI_STRICT_COMPAT_SCHEMA_NESTED_KEYS.has(key) ? normalizeOpenAIStrictCompatSchemaRecursive(value, { promoteEmptyObject: false }) : value;
|
|
1286
|
+
normalized[key] = next;
|
|
1287
|
+
changed ||= next !== value;
|
|
1288
|
+
}
|
|
1289
|
+
if (Object.keys(normalized).length === 0) {
|
|
1290
|
+
if (!options.promoteEmptyObject) return schema;
|
|
1291
|
+
return {
|
|
1292
|
+
type: "object",
|
|
1293
|
+
properties: {},
|
|
1294
|
+
required: [],
|
|
1295
|
+
additionalProperties: false
|
|
1296
|
+
};
|
|
1297
|
+
}
|
|
1298
|
+
const hasObjectShapeHints = normalized.properties && typeof normalized.properties === "object" && !Array.isArray(normalized.properties) || Array.isArray(normalized.required);
|
|
1299
|
+
const hasArrayShapeHints = "items" in normalized;
|
|
1300
|
+
if (!("type" in normalized) && hasObjectShapeHints !== hasArrayShapeHints) {
|
|
1301
|
+
normalized.type = hasObjectShapeHints ? "object" : "array";
|
|
1302
|
+
changed = true;
|
|
1303
|
+
} else if (hadNullType && !("type" in normalized)) normalized.type = null;
|
|
1304
|
+
if (normalized.type === "object" && !("properties" in normalized)) {
|
|
1305
|
+
normalized.properties = {};
|
|
1306
|
+
changed = true;
|
|
1307
|
+
}
|
|
1308
|
+
const hasEmptyProperties = normalized.properties && typeof normalized.properties === "object" && !Array.isArray(normalized.properties) && Object.keys(normalized.properties).length === 0;
|
|
1309
|
+
if (normalized.type === "object" && !Array.isArray(normalized.required) && hasEmptyProperties) {
|
|
1310
|
+
normalized.required = [];
|
|
1311
|
+
changed = true;
|
|
1312
|
+
}
|
|
1313
|
+
if (normalized.type === "object" && hasEmptyProperties && !("additionalProperties" in normalized)) {
|
|
1314
|
+
normalized.additionalProperties = false;
|
|
1315
|
+
changed = true;
|
|
1316
|
+
}
|
|
1317
|
+
return changed ? normalized : schema;
|
|
1318
|
+
}
|
|
1319
|
+
/** Repairs recoverable OpenAI tool-schema shapes before canonical normalization. */
|
|
1320
|
+
function normalizeOpenAIStrictCompatSchema(schema) {
|
|
1321
|
+
return normalizeOpenAIStrictCompatSchemaRecursive(schema, { promoteEmptyObject: true });
|
|
1322
|
+
}
|
|
1323
|
+
/** Finds schema paths that violate OpenAI strict tool-schema requirements. */
|
|
1324
|
+
function findOpenAIStrictSchemaViolations(schema, path, options) {
|
|
1325
|
+
if (Array.isArray(schema)) {
|
|
1326
|
+
if (options?.requireObjectRoot) return [`${path}.type`];
|
|
1327
|
+
return schema.flatMap((item, index) => findOpenAIStrictSchemaViolations(item, `${path}[${index}]`));
|
|
1328
|
+
}
|
|
1329
|
+
if (!schema || typeof schema !== "object") return options?.requireObjectRoot ? [`${path}.type`] : [];
|
|
1330
|
+
const record = schema;
|
|
1331
|
+
const violations = [];
|
|
1332
|
+
for (const key of [
|
|
1333
|
+
"anyOf",
|
|
1334
|
+
"oneOf",
|
|
1335
|
+
"allOf"
|
|
1336
|
+
]) if (key in record) violations.push(`${path}.${key}`);
|
|
1337
|
+
if (Array.isArray(record.type)) violations.push(`${path}.type`);
|
|
1338
|
+
const properties = record.properties && typeof record.properties === "object" && !Array.isArray(record.properties) ? record.properties : void 0;
|
|
1339
|
+
if (record.type === "object") {
|
|
1340
|
+
if (record.additionalProperties !== false) violations.push(`${path}.additionalProperties`);
|
|
1341
|
+
const required = Array.isArray(record.required) ? record.required.filter((entry) => typeof entry === "string") : void 0;
|
|
1342
|
+
if (!required) violations.push(`${path}.required`);
|
|
1343
|
+
else if (properties) {
|
|
1344
|
+
const requiredSet = new Set(required);
|
|
1345
|
+
for (const key of Object.keys(properties)) if (!requiredSet.has(key)) violations.push(`${path}.required.${key}`);
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
for (const key of OPENAI_STRICT_COMPAT_SCHEMA_MAP_KEYS) {
|
|
1349
|
+
const schemaMap = record[key];
|
|
1350
|
+
if (!schemaMap || typeof schemaMap !== "object" || Array.isArray(schemaMap)) continue;
|
|
1351
|
+
for (const [entryKey, value] of Object.entries(schemaMap)) violations.push(...findOpenAIStrictSchemaViolations(value, `${path}.${key}.${entryKey}`));
|
|
1352
|
+
}
|
|
1353
|
+
for (const key of OPENAI_STRICT_COMPAT_SCHEMA_NESTED_KEYS) {
|
|
1354
|
+
const value = record[key];
|
|
1355
|
+
if (value && typeof value === "object") violations.push(...findOpenAIStrictSchemaViolations(value, `${path}.${key}`));
|
|
1356
|
+
}
|
|
1357
|
+
return violations;
|
|
1358
|
+
}
|
|
1359
|
+
//#endregion
|
|
1155
1360
|
//#region packages/ai/src/providers/openai-tool-schema.ts
|
|
1156
1361
|
/**
|
|
1157
1362
|
* OpenAI strict JSON-schema normalization for tool inventories and request payloads.
|
|
@@ -1245,7 +1450,7 @@ function findOpenAIStrictToolProjectionDiagnostics(projection) {
|
|
|
1245
1450
|
...diagnostic.toolName ? { toolName: diagnostic.toolName } : {},
|
|
1246
1451
|
violations: [...diagnostic.violations]
|
|
1247
1452
|
})), ...projection.tools.flatMap((tool) => {
|
|
1248
|
-
const violations =
|
|
1453
|
+
const violations = findOpenAIStrictSchemaViolations(normalizeStrictOpenAIJsonSchema(tool.parameters), `${tool.name}.parameters`);
|
|
1249
1454
|
return violations.length > 0 ? [{
|
|
1250
1455
|
toolIndex: tool.toolIndex,
|
|
1251
1456
|
toolName: tool.name,
|
|
@@ -1272,34 +1477,6 @@ function isStrictOpenAIJsonSchemaCompatibleRecursive(schema) {
|
|
|
1272
1477
|
return isStrictOpenAIJsonSchemaCompatibleRecursive(entry);
|
|
1273
1478
|
});
|
|
1274
1479
|
}
|
|
1275
|
-
function findStrictOpenAIJsonSchemaViolations(schema, path) {
|
|
1276
|
-
if (Array.isArray(schema)) return schema.flatMap((entry, index) => findStrictOpenAIJsonSchemaViolations(entry, `${path}[${index}]`));
|
|
1277
|
-
if (!schema || typeof schema !== "object") return [];
|
|
1278
|
-
const record = schema;
|
|
1279
|
-
const violations = [];
|
|
1280
|
-
for (const key of [
|
|
1281
|
-
"anyOf",
|
|
1282
|
-
"oneOf",
|
|
1283
|
-
"allOf"
|
|
1284
|
-
]) if (key in record) violations.push(`${path}.${key}`);
|
|
1285
|
-
if (Array.isArray(record.type)) violations.push(`${path}.type`);
|
|
1286
|
-
if (record.type === "object") {
|
|
1287
|
-
if (record.additionalProperties !== false) violations.push(`${path}.additionalProperties`);
|
|
1288
|
-
const properties = record.properties && typeof record.properties === "object" && !Array.isArray(record.properties) ? record.properties : {};
|
|
1289
|
-
const required = Array.isArray(record.required) ? record.required.filter((entry) => typeof entry === "string") : void 0;
|
|
1290
|
-
if (!required) violations.push(`${path}.required`);
|
|
1291
|
-
else {
|
|
1292
|
-
const requiredSet = new Set(required);
|
|
1293
|
-
for (const key of Object.keys(properties)) if (!requiredSet.has(key)) violations.push(`${path}.required.${key}`);
|
|
1294
|
-
}
|
|
1295
|
-
}
|
|
1296
|
-
if (record.properties && typeof record.properties === "object" && !Array.isArray(record.properties)) for (const [key, value] of Object.entries(record.properties)) violations.push(...findStrictOpenAIJsonSchemaViolations(value, `${path}.properties.${key}`));
|
|
1297
|
-
for (const [key, value] of Object.entries(record)) {
|
|
1298
|
-
if (key === "properties") continue;
|
|
1299
|
-
if (value && typeof value === "object") violations.push(...findStrictOpenAIJsonSchemaViolations(value, `${path}.${key}`));
|
|
1300
|
-
}
|
|
1301
|
-
return violations;
|
|
1302
|
-
}
|
|
1303
1480
|
/** Resolves strict mode for the projected tools that will be emitted in the request payload. */
|
|
1304
1481
|
function resolveOpenAIProjectedToolsStrictToolFlag(projection, strict) {
|
|
1305
1482
|
if (strict !== true) return strict === false ? false : void 0;
|
|
@@ -1874,35 +2051,29 @@ async function processResponsesStream(openaiStream, output, stream, model, optio
|
|
|
1874
2051
|
terminalResponseEvent = "finalized";
|
|
1875
2052
|
backfillReasoningSignatures(response.output ?? []);
|
|
1876
2053
|
if (response.id) output.responseId = response.id;
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
input: 0,
|
|
1889
|
-
output: 0,
|
|
1890
|
-
cacheRead: 0,
|
|
1891
|
-
cacheWrite: 0,
|
|
1892
|
-
total: 0
|
|
1893
|
-
}
|
|
1894
|
-
};
|
|
1895
|
-
}
|
|
2054
|
+
const mappedUsage = mapResponsesTerminalUsage(response.usage);
|
|
2055
|
+
if (mappedUsage) output.usage = {
|
|
2056
|
+
...mappedUsage,
|
|
2057
|
+
cost: {
|
|
2058
|
+
input: 0,
|
|
2059
|
+
output: 0,
|
|
2060
|
+
cacheRead: 0,
|
|
2061
|
+
cacheWrite: 0,
|
|
2062
|
+
total: 0
|
|
2063
|
+
}
|
|
2064
|
+
};
|
|
1896
2065
|
calculateCost(model, output.usage);
|
|
1897
2066
|
if (options?.applyServiceTierPricing) {
|
|
1898
2067
|
const serviceTier = options.resolveServiceTier ? options.resolveServiceTier(response.service_tier, options.serviceTier) : response.service_tier ?? options.serviceTier;
|
|
1899
2068
|
options.applyServiceTierPricing(output.usage, serviceTier);
|
|
1900
2069
|
}
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
2070
|
+
const terminal = resolveResponsesTerminalStopReason({
|
|
2071
|
+
status: response.status,
|
|
2072
|
+
incompleteReason: response.incomplete_details?.reason,
|
|
2073
|
+
hasToolCall: output.content.some((block) => block.type === "toolCall")
|
|
2074
|
+
});
|
|
2075
|
+
output.stopReason = terminal.stopReason;
|
|
2076
|
+
if (terminal.errorMessage) output.errorMessage = terminal.errorMessage;
|
|
1906
2077
|
};
|
|
1907
2078
|
const guardedStream = withFirstStreamEventTimeout(openaiStream, {
|
|
1908
2079
|
provider: model.provider,
|
|
@@ -2217,17 +2388,5 @@ async function processResponsesStream(openaiStream, output, stream, model, optio
|
|
|
2217
2388
|
if (streamingToolCalls.hasActive()) throw new Error("Responses stream ended with unresolved tool calls");
|
|
2218
2389
|
if (!terminalResponseEvent) throw new Error("OpenAI Responses stream ended before a terminal response event");
|
|
2219
2390
|
}
|
|
2220
|
-
function mapStopReason(status) {
|
|
2221
|
-
if (!status) return "stop";
|
|
2222
|
-
switch (status) {
|
|
2223
|
-
case "completed": return "stop";
|
|
2224
|
-
case "incomplete": return "length";
|
|
2225
|
-
case "failed":
|
|
2226
|
-
case "cancelled": return "error";
|
|
2227
|
-
case "in_progress":
|
|
2228
|
-
case "queued": return "stop";
|
|
2229
|
-
default: throw new Error(`Unhandled stop reason: ${String(status)}`);
|
|
2230
|
-
}
|
|
2231
|
-
}
|
|
2232
2391
|
//#endregion
|
|
2233
|
-
export {
|
|
2392
|
+
export { isOpenAIGpt54MiniModel as A, resolveUnsupportedToolSchemaKeywords as B, OPENAI_RESPONSES_OUTPUT_TEXT_CONTENT_PART_TYPE as C, isResponsesTextContentPartType as D, isAzureResponsesTextDeltaEventType as E, resolveOpenAISupportedReasoningEfforts as F, uniqueStrings as G, stripUnsupportedSchemaKeywords as H, supportsOpenAIReasoningEffort as I, supportsOpenAITemperature as L, isOpenAIGpt56Model as M, normalizeOpenAIReasoningEffort as N, isResponsesTextDeltaEventType as O, resolveOpenAIReasoningEffortForModel as P, extractToolSchemaModelCompat as R, AZURE_RESPONSES_TEXT_DELTA_EVENT_TYPE as S, isAzureResponsesTextDeltaEvent as T, GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS as U, shouldOmitEmptyArrayItems as V, cleanSchemaForGemini as W, readResponsesToolCallItemIdentity as _, resolveResponsesReasoningEffort as a, resolveResponsesTerminalStopReason as b, clearOpenAIToolSchemaCacheForTest as c, normalizeOpenAIStrictToolParameters as d, normalizeStrictOpenAIJsonSchema as f, createResponsesToolCallTracker as g, normalizeOpenAIStrictCompatSchema as h, processResponsesStream as i, isOpenAIGpt55Model as j, resolveResponsesMessageSnapshotCollapse as k, findOpenAIStrictToolProjectionDiagnostics as l, findOpenAIStrictSchemaViolations as m, convertResponsesMessages as n, runResponsesStreamLifecycle as o, resolveOpenAIProjectedToolsStrictToolFlag as p, createResponsesAssistantOutput as r, convertResponsesToolPayload as s, applyCommonResponsesParams as t, isStrictOpenAIJsonSchemaCompatible as u, mapResponsesTerminalUsage as v, OPENAI_RESPONSES_OUTPUT_TEXT_DELTA_EVENT_TYPE as w, AZURE_RESPONSES_TEXT_CONTENT_PART_TYPE as x, readResponsesReasoningTokens as y, normalizeToolParameterSchema as z };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { T as isRecord } from "./system-prompt-cache-boundary-CbHeV4_l.mjs";
|
|
2
2
|
import { t as projectRuntimeToolInputSchema } from "./tool-schema-json-projection-BwNu3nDi.mjs";
|
|
3
3
|
//#region packages/ai/src/providers/openai-prompt-cache.ts
|
|
4
4
|
/** Maximum prompt cache key length accepted by OpenAI-compatible request metadata. */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { w as truncateUtf16Safe } from "./system-prompt-cache-boundary-CbHeV4_l.mjs";
|
|
1
2
|
//#region packages/ai/src/utils/provider-error.ts
|
|
2
3
|
const MAX_ERROR_BODY_LENGTH = 4e3;
|
|
3
4
|
function stringify(value) {
|
|
@@ -25,7 +26,7 @@ function readBody(error) {
|
|
|
25
26
|
if (value === void 0 || value === null) continue;
|
|
26
27
|
if (typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0) continue;
|
|
27
28
|
const body = (typeof value === "string" ? value : stringify(value)).trim();
|
|
28
|
-
if (body.length > 0) return body.length <= MAX_ERROR_BODY_LENGTH ? body : `${body
|
|
29
|
+
if (body.length > 0) return body.length <= MAX_ERROR_BODY_LENGTH ? body : `${truncateUtf16Safe(body, MAX_ERROR_BODY_LENGTH)}... [truncated]`;
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
function formatProviderError(error) {
|
package/dist/providers.d.mts
CHANGED
package/dist/providers.mjs
CHANGED
|
@@ -63,35 +63,35 @@ function createLazyRegistration(api, importModule, select) {
|
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
const registerBuiltIns = [
|
|
66
|
-
createLazyRegistration("anthropic-messages", () => import("./anthropic-
|
|
66
|
+
createLazyRegistration("anthropic-messages", () => import("./anthropic-CrUDIBpM.mjs").then((n) => n.t), (module) => ({
|
|
67
67
|
stream: module.streamAnthropic,
|
|
68
68
|
streamSimple: module.streamSimpleAnthropic
|
|
69
69
|
})),
|
|
70
|
-
createLazyRegistration("openai-completions", () => import("./openai-completions-
|
|
70
|
+
createLazyRegistration("openai-completions", () => import("./openai-completions-exO8NFQf.mjs").then((n) => n.n), (module) => ({
|
|
71
71
|
stream: module.streamOpenAICompletions,
|
|
72
72
|
streamSimple: module.streamSimpleOpenAICompletions
|
|
73
73
|
})),
|
|
74
|
-
createLazyRegistration("mistral-conversations", () => import("./mistral-
|
|
74
|
+
createLazyRegistration("mistral-conversations", () => import("./mistral-D5Ps7Led.mjs"), (module) => ({
|
|
75
75
|
stream: module.streamMistral,
|
|
76
76
|
streamSimple: module.streamSimpleMistral
|
|
77
77
|
})),
|
|
78
|
-
createLazyRegistration("openai-responses", () => import("./openai-responses-
|
|
78
|
+
createLazyRegistration("openai-responses", () => import("./openai-responses-BHpmtUKo.mjs").then((n) => n.t), (module) => ({
|
|
79
79
|
stream: module.streamOpenAIResponses,
|
|
80
80
|
streamSimple: module.streamSimpleOpenAIResponses
|
|
81
81
|
})),
|
|
82
|
-
createLazyRegistration("azure-openai-responses", () => import("./azure-openai-responses-
|
|
82
|
+
createLazyRegistration("azure-openai-responses", () => import("./azure-openai-responses-CbrpVeEv.mjs"), (module) => ({
|
|
83
83
|
stream: module.streamAzureOpenAIResponses,
|
|
84
84
|
streamSimple: module.streamSimpleAzureOpenAIResponses
|
|
85
85
|
})),
|
|
86
|
-
createLazyRegistration("openai-chatgpt-responses", () => import("./openai-chatgpt-responses-
|
|
86
|
+
createLazyRegistration("openai-chatgpt-responses", () => import("./openai-chatgpt-responses-h0o5yV8Y.mjs"), (module) => ({
|
|
87
87
|
stream: module.streamOpenAICodexResponses,
|
|
88
88
|
streamSimple: module.streamSimpleOpenAICodexResponses
|
|
89
89
|
})),
|
|
90
|
-
createLazyRegistration("google-generative-ai", () => import("./google-
|
|
90
|
+
createLazyRegistration("google-generative-ai", () => import("./google-Cs62KA7t.mjs"), (module) => ({
|
|
91
91
|
stream: module.streamGoogle,
|
|
92
92
|
streamSimple: module.streamSimpleGoogle
|
|
93
93
|
})),
|
|
94
|
-
createLazyRegistration("google-vertex", () => import("./google-vertex-
|
|
94
|
+
createLazyRegistration("google-vertex", () => import("./google-vertex-B4SD3U0f.mjs"), (module) => ({
|
|
95
95
|
stream: module.streamGoogleVertex,
|
|
96
96
|
streamSimple: module.streamSimpleGoogleVertex
|
|
97
97
|
}))
|
package/dist/{stream-first-event-timeout-RjWszj8c.mjs → stream-first-event-timeout-DP4xEyBY.mjs}
RENAMED
|
@@ -3,6 +3,40 @@
|
|
|
3
3
|
function asFiniteNumber(value) {
|
|
4
4
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
5
5
|
}
|
|
6
|
+
/** Returns a finite number only when it satisfies the supplied inclusive/exclusive bounds. */
|
|
7
|
+
function asFiniteNumberInRange(value, range) {
|
|
8
|
+
const number = asFiniteNumber(value);
|
|
9
|
+
if (number === void 0) return;
|
|
10
|
+
if (range.min !== void 0) {
|
|
11
|
+
if (range.minExclusive ? number <= range.min : number < range.min) return;
|
|
12
|
+
}
|
|
13
|
+
if (range.max !== void 0) {
|
|
14
|
+
if (range.maxExclusive ? number >= range.max : number > range.max) return;
|
|
15
|
+
}
|
|
16
|
+
return number;
|
|
17
|
+
}
|
|
18
|
+
function normalizeNumericString(value) {
|
|
19
|
+
const trimmed = value.trim();
|
|
20
|
+
return trimmed ? trimmed : void 0;
|
|
21
|
+
}
|
|
22
|
+
/** Parses only safe integer numbers or base-10 integer strings. */
|
|
23
|
+
function parseStrictInteger(value) {
|
|
24
|
+
if (typeof value === "number") return Number.isSafeInteger(value) ? value : void 0;
|
|
25
|
+
if (typeof value !== "string") return;
|
|
26
|
+
const normalized = normalizeNumericString(value);
|
|
27
|
+
if (!normalized || !/^[+-]?\d+$/.test(normalized)) return;
|
|
28
|
+
const parsed = Number(normalized);
|
|
29
|
+
return Number.isSafeInteger(parsed) ? parsed : void 0;
|
|
30
|
+
}
|
|
31
|
+
/** Parses only finite decimal/scientific string tokens, rejecting partial numbers. */
|
|
32
|
+
function parseStrictFiniteNumber(value) {
|
|
33
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : void 0;
|
|
34
|
+
if (typeof value !== "string") return;
|
|
35
|
+
const normalized = normalizeNumericString(value);
|
|
36
|
+
if (!normalized || !/^[+-]?(?:(?:\d+\.?\d*)|(?:\.\d+))(?:e[+-]?\d+)?$/i.test(normalized)) return;
|
|
37
|
+
const parsed = Number(normalized);
|
|
38
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
39
|
+
}
|
|
6
40
|
/** Conservative upper bound for Node timer delays. */
|
|
7
41
|
const MAX_TIMER_TIMEOUT_MS = 2147e6;
|
|
8
42
|
/** Clamps finite millisecond values into the Node-safe timer range. */
|
|
@@ -18,6 +52,16 @@ function resolveTimerTimeoutMs(valueMs, fallbackMs, minMs = 1) {
|
|
|
18
52
|
if (value === void 0) return min;
|
|
19
53
|
return Math.min(Math.max(Math.floor(value), min), MAX_TIMER_TIMEOUT_MS);
|
|
20
54
|
}
|
|
55
|
+
/** Parses strict positive integer values from numbers or strings. */
|
|
56
|
+
function parseStrictPositiveInteger(value) {
|
|
57
|
+
const parsed = parseStrictInteger(value);
|
|
58
|
+
return parsed !== void 0 && parsed > 0 ? parsed : void 0;
|
|
59
|
+
}
|
|
60
|
+
/** Parses strict non-negative integer values from numbers or strings. */
|
|
61
|
+
function parseStrictNonNegativeInteger(value) {
|
|
62
|
+
const parsed = parseStrictInteger(value);
|
|
63
|
+
return parsed !== void 0 && parsed >= 0 ? parsed : void 0;
|
|
64
|
+
}
|
|
21
65
|
//#endregion
|
|
22
66
|
//#region packages/ai/src/utils/stream-first-event-timeout.ts
|
|
23
67
|
function getFirstStreamEventTimeoutMs(options) {
|
|
@@ -103,4 +147,4 @@ function withFirstStreamEventTimeout(stream, context) {
|
|
|
103
147
|
} };
|
|
104
148
|
}
|
|
105
149
|
//#endregion
|
|
106
|
-
export { withFirstStreamEventTimeout as a, getFirstStreamEventTimeoutMs as i, createFirstStreamEventTimeoutError as n,
|
|
150
|
+
export { withFirstStreamEventTimeout as a, parseStrictFiniteNumber as c, resolveTimerTimeoutMs as d, getFirstStreamEventTimeoutMs as i, parseStrictNonNegativeInteger as l, createFirstStreamEventTimeoutError as n, asFiniteNumberInRange as o, getFirstStreamEventTimeoutHandler as r, clampTimerTimeoutMs as s, createFirstStreamEventAbortController as t, parseStrictPositiveInteger as u };
|