@probelabs/probe 0.6.0-rc334 → 0.6.0-rc335
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/bin/binaries/{probe-v0.6.0-rc334-aarch64-apple-darwin.tar.gz → probe-v0.6.0-rc335-aarch64-apple-darwin.tar.gz} +0 -0
- package/bin/binaries/{probe-v0.6.0-rc334-aarch64-unknown-linux-musl.tar.gz → probe-v0.6.0-rc335-aarch64-unknown-linux-musl.tar.gz} +0 -0
- package/bin/binaries/{probe-v0.6.0-rc334-x86_64-apple-darwin.tar.gz → probe-v0.6.0-rc335-x86_64-apple-darwin.tar.gz} +0 -0
- package/bin/binaries/{probe-v0.6.0-rc334-x86_64-pc-windows-msvc.zip → probe-v0.6.0-rc335-x86_64-pc-windows-msvc.zip} +0 -0
- package/bin/binaries/{probe-v0.6.0-rc334-x86_64-unknown-linux-musl.tar.gz → probe-v0.6.0-rc335-x86_64-unknown-linux-musl.tar.gz} +0 -0
- package/build/utils/provider.js +11 -1
- package/cjs/agent/ProbeAgent.cjs +2524 -65
- package/cjs/index.cjs +2524 -65
- package/package.json +2 -1
- package/src/utils/provider.js +11 -1
package/cjs/agent/ProbeAgent.cjs
CHANGED
|
@@ -16070,6 +16070,218 @@ var init_v3 = __esm({
|
|
|
16070
16070
|
}
|
|
16071
16071
|
});
|
|
16072
16072
|
|
|
16073
|
+
// node_modules/eventsource-parser/dist/index.js
|
|
16074
|
+
function noop(_arg) {
|
|
16075
|
+
}
|
|
16076
|
+
function createParser(config2) {
|
|
16077
|
+
if (typeof config2 == "function")
|
|
16078
|
+
throw new TypeError(
|
|
16079
|
+
"`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?"
|
|
16080
|
+
);
|
|
16081
|
+
const { onEvent = noop, onError = noop, onRetry = noop, onComment, maxBufferSize } = config2, pendingFragments = [];
|
|
16082
|
+
let pendingFragmentsLength = 0, isFirstChunk = true, id, data2 = "", dataLines = 0, eventType, terminated = false;
|
|
16083
|
+
function feed(chunk) {
|
|
16084
|
+
if (terminated)
|
|
16085
|
+
throw new Error(
|
|
16086
|
+
"Cannot feed parser: it was terminated after exceeding the configured max buffer size. Call `reset()` to resume parsing."
|
|
16087
|
+
);
|
|
16088
|
+
if (isFirstChunk && (isFirstChunk = false, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
|
|
16089
|
+
const trailing2 = processLines(chunk);
|
|
16090
|
+
trailing2 !== "" && (pendingFragments.push(trailing2), pendingFragmentsLength = trailing2.length), checkBufferSize();
|
|
16091
|
+
return;
|
|
16092
|
+
}
|
|
16093
|
+
if (chunk.indexOf(`
|
|
16094
|
+
`) === -1 && chunk.indexOf("\r") === -1) {
|
|
16095
|
+
pendingFragments.push(chunk), pendingFragmentsLength += chunk.length, checkBufferSize();
|
|
16096
|
+
return;
|
|
16097
|
+
}
|
|
16098
|
+
pendingFragments.push(chunk);
|
|
16099
|
+
const input = pendingFragments.join("");
|
|
16100
|
+
pendingFragments.length = 0, pendingFragmentsLength = 0;
|
|
16101
|
+
const trailing = processLines(input);
|
|
16102
|
+
trailing !== "" && (pendingFragments.push(trailing), pendingFragmentsLength = trailing.length), checkBufferSize();
|
|
16103
|
+
}
|
|
16104
|
+
function checkBufferSize() {
|
|
16105
|
+
maxBufferSize !== void 0 && (pendingFragmentsLength + data2.length <= maxBufferSize || (terminated = true, pendingFragments.length = 0, pendingFragmentsLength = 0, id = void 0, data2 = "", dataLines = 0, eventType = void 0, onError(
|
|
16106
|
+
new ParseError(`Buffered data exceeded max buffer size of ${maxBufferSize} characters`, {
|
|
16107
|
+
type: "max-buffer-size-exceeded"
|
|
16108
|
+
})
|
|
16109
|
+
)));
|
|
16110
|
+
}
|
|
16111
|
+
function processLines(chunk) {
|
|
16112
|
+
let searchIndex = 0;
|
|
16113
|
+
if (chunk.indexOf("\r") === -1) {
|
|
16114
|
+
let lfIndex = chunk.indexOf(`
|
|
16115
|
+
`, searchIndex);
|
|
16116
|
+
for (; lfIndex !== -1; ) {
|
|
16117
|
+
if (searchIndex === lfIndex) {
|
|
16118
|
+
dataLines > 0 && onEvent({ id, event: eventType, data: data2 }), id = void 0, data2 = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
|
|
16119
|
+
`, searchIndex);
|
|
16120
|
+
continue;
|
|
16121
|
+
}
|
|
16122
|
+
const firstCharCode = chunk.charCodeAt(searchIndex);
|
|
16123
|
+
if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
|
|
16124
|
+
const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
|
|
16125
|
+
if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
|
|
16126
|
+
onEvent({ id, event: eventType, data: value }), id = void 0, data2 = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
|
|
16127
|
+
`, searchIndex);
|
|
16128
|
+
continue;
|
|
16129
|
+
}
|
|
16130
|
+
data2 = dataLines === 0 ? value : `${data2}
|
|
16131
|
+
${value}`, dataLines++;
|
|
16132
|
+
} else isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
|
|
16133
|
+
chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6,
|
|
16134
|
+
lfIndex
|
|
16135
|
+
) || void 0 : parseLine(chunk, searchIndex, lfIndex);
|
|
16136
|
+
searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
|
|
16137
|
+
`, searchIndex);
|
|
16138
|
+
}
|
|
16139
|
+
return chunk.slice(searchIndex);
|
|
16140
|
+
}
|
|
16141
|
+
for (; searchIndex < chunk.length; ) {
|
|
16142
|
+
const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
|
|
16143
|
+
`, searchIndex);
|
|
16144
|
+
let lineEnd = -1;
|
|
16145
|
+
if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = crIndex < lfIndex ? crIndex : lfIndex : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1)
|
|
16146
|
+
break;
|
|
16147
|
+
parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
|
|
16148
|
+
}
|
|
16149
|
+
return chunk.slice(searchIndex);
|
|
16150
|
+
}
|
|
16151
|
+
function parseLine(chunk, start, end) {
|
|
16152
|
+
if (start === end) {
|
|
16153
|
+
dispatchEvent();
|
|
16154
|
+
return;
|
|
16155
|
+
}
|
|
16156
|
+
const firstCharCode = chunk.charCodeAt(start);
|
|
16157
|
+
if (isDataPrefix(chunk, start, firstCharCode)) {
|
|
16158
|
+
const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
|
|
16159
|
+
data2 = dataLines === 0 ? value2 : `${data2}
|
|
16160
|
+
${value2}`, dataLines++;
|
|
16161
|
+
return;
|
|
16162
|
+
}
|
|
16163
|
+
if (isEventPrefix(chunk, start, firstCharCode)) {
|
|
16164
|
+
eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
|
|
16165
|
+
return;
|
|
16166
|
+
}
|
|
16167
|
+
if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
|
|
16168
|
+
const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
|
|
16169
|
+
value2.includes("\0") || (id = value2);
|
|
16170
|
+
return;
|
|
16171
|
+
}
|
|
16172
|
+
if (firstCharCode === 58) {
|
|
16173
|
+
if (onComment) {
|
|
16174
|
+
const line2 = chunk.slice(start, end);
|
|
16175
|
+
onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
|
|
16176
|
+
}
|
|
16177
|
+
return;
|
|
16178
|
+
}
|
|
16179
|
+
const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
|
|
16180
|
+
if (fieldSeparatorIndex === -1) {
|
|
16181
|
+
processField(line, "", line);
|
|
16182
|
+
return;
|
|
16183
|
+
}
|
|
16184
|
+
const field = line.slice(0, fieldSeparatorIndex), offset2 = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset2);
|
|
16185
|
+
processField(field, value, line);
|
|
16186
|
+
}
|
|
16187
|
+
function processField(field, value, line) {
|
|
16188
|
+
switch (field) {
|
|
16189
|
+
case "event":
|
|
16190
|
+
eventType = value || void 0;
|
|
16191
|
+
break;
|
|
16192
|
+
case "data":
|
|
16193
|
+
data2 = dataLines === 0 ? value : `${data2}
|
|
16194
|
+
${value}`, dataLines++;
|
|
16195
|
+
break;
|
|
16196
|
+
case "id":
|
|
16197
|
+
value.includes("\0") || (id = value);
|
|
16198
|
+
break;
|
|
16199
|
+
case "retry":
|
|
16200
|
+
/^\d+$/.test(value) ? onRetry(parseInt(value, 10)) : onError(
|
|
16201
|
+
new ParseError(`Invalid \`retry\` value: "${value}"`, {
|
|
16202
|
+
type: "invalid-retry",
|
|
16203
|
+
value,
|
|
16204
|
+
line
|
|
16205
|
+
})
|
|
16206
|
+
);
|
|
16207
|
+
break;
|
|
16208
|
+
default:
|
|
16209
|
+
onError(
|
|
16210
|
+
new ParseError(
|
|
16211
|
+
`Unknown field "${field.length > 20 ? `${field.slice(0, 20)}\u2026` : field}"`,
|
|
16212
|
+
{ type: "unknown-field", field, value, line }
|
|
16213
|
+
)
|
|
16214
|
+
);
|
|
16215
|
+
break;
|
|
16216
|
+
}
|
|
16217
|
+
}
|
|
16218
|
+
function dispatchEvent() {
|
|
16219
|
+
dataLines > 0 && onEvent({
|
|
16220
|
+
id,
|
|
16221
|
+
event: eventType,
|
|
16222
|
+
data: data2
|
|
16223
|
+
}), id = void 0, data2 = "", dataLines = 0, eventType = void 0;
|
|
16224
|
+
}
|
|
16225
|
+
function reset2(options = {}) {
|
|
16226
|
+
if (options.consume && pendingFragments.length > 0) {
|
|
16227
|
+
const incompleteLine = pendingFragments.join("");
|
|
16228
|
+
parseLine(incompleteLine, 0, incompleteLine.length);
|
|
16229
|
+
}
|
|
16230
|
+
isFirstChunk = true, id = void 0, data2 = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0, pendingFragmentsLength = 0, terminated = false;
|
|
16231
|
+
}
|
|
16232
|
+
return { feed, reset: reset2 };
|
|
16233
|
+
}
|
|
16234
|
+
function isDataPrefix(chunk, i, firstCharCode) {
|
|
16235
|
+
return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
|
|
16236
|
+
}
|
|
16237
|
+
function isEventPrefix(chunk, i, firstCharCode) {
|
|
16238
|
+
return firstCharCode === 101 && chunk.charCodeAt(i + 1) === 118 && chunk.charCodeAt(i + 2) === 101 && chunk.charCodeAt(i + 3) === 110 && chunk.charCodeAt(i + 4) === 116 && chunk.charCodeAt(i + 5) === 58;
|
|
16239
|
+
}
|
|
16240
|
+
var ParseError, LF, CR, SPACE;
|
|
16241
|
+
var init_dist2 = __esm({
|
|
16242
|
+
"node_modules/eventsource-parser/dist/index.js"() {
|
|
16243
|
+
ParseError = class extends Error {
|
|
16244
|
+
constructor(message, options) {
|
|
16245
|
+
super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
|
|
16246
|
+
}
|
|
16247
|
+
};
|
|
16248
|
+
LF = 10;
|
|
16249
|
+
CR = 13;
|
|
16250
|
+
SPACE = 32;
|
|
16251
|
+
}
|
|
16252
|
+
});
|
|
16253
|
+
|
|
16254
|
+
// node_modules/eventsource-parser/dist/stream.js
|
|
16255
|
+
var EventSourceParserStream;
|
|
16256
|
+
var init_stream = __esm({
|
|
16257
|
+
"node_modules/eventsource-parser/dist/stream.js"() {
|
|
16258
|
+
init_dist2();
|
|
16259
|
+
EventSourceParserStream = class extends TransformStream {
|
|
16260
|
+
constructor({ onError, onRetry, onComment, maxBufferSize } = {}) {
|
|
16261
|
+
let parser;
|
|
16262
|
+
super({
|
|
16263
|
+
start(controller) {
|
|
16264
|
+
parser = createParser({
|
|
16265
|
+
onEvent: (event) => {
|
|
16266
|
+
controller.enqueue(event);
|
|
16267
|
+
},
|
|
16268
|
+
onError(error40) {
|
|
16269
|
+
typeof onError == "function" && onError(error40), (onError === "terminate" || error40.type === "max-buffer-size-exceeded") && controller.error(error40);
|
|
16270
|
+
},
|
|
16271
|
+
onRetry,
|
|
16272
|
+
onComment,
|
|
16273
|
+
maxBufferSize
|
|
16274
|
+
});
|
|
16275
|
+
},
|
|
16276
|
+
transform(chunk) {
|
|
16277
|
+
parser.feed(chunk);
|
|
16278
|
+
}
|
|
16279
|
+
});
|
|
16280
|
+
}
|
|
16281
|
+
};
|
|
16282
|
+
}
|
|
16283
|
+
});
|
|
16284
|
+
|
|
16073
16285
|
// node_modules/@ai-sdk/provider-utils/dist/index.mjs
|
|
16074
16286
|
function combineHeaders(...headers) {
|
|
16075
16287
|
return headers.reduce(
|
|
@@ -16083,6 +16295,11 @@ function combineHeaders(...headers) {
|
|
|
16083
16295
|
function extractResponseHeaders(response) {
|
|
16084
16296
|
return Object.fromEntries([...response.headers]);
|
|
16085
16297
|
}
|
|
16298
|
+
function convertBase64ToUint8Array(base64String) {
|
|
16299
|
+
const base64Url = base64String.replace(/-/g, "+").replace(/_/g, "/");
|
|
16300
|
+
const latin1string = atob2(base64Url);
|
|
16301
|
+
return Uint8Array.from(latin1string, (byte) => byte.codePointAt(0));
|
|
16302
|
+
}
|
|
16086
16303
|
function convertUint8ArrayToBase64(array2) {
|
|
16087
16304
|
let latin1string = "";
|
|
16088
16305
|
for (let i = 0; i < array2.length; i++) {
|
|
@@ -16093,6 +16310,28 @@ function convertUint8ArrayToBase64(array2) {
|
|
|
16093
16310
|
function convertToBase64(value) {
|
|
16094
16311
|
return value instanceof Uint8Array ? convertUint8ArrayToBase64(value) : value;
|
|
16095
16312
|
}
|
|
16313
|
+
function convertToFormData(input, options = {}) {
|
|
16314
|
+
const { useArrayBrackets = true } = options;
|
|
16315
|
+
const formData = new FormData();
|
|
16316
|
+
for (const [key, value] of Object.entries(input)) {
|
|
16317
|
+
if (value == null) {
|
|
16318
|
+
continue;
|
|
16319
|
+
}
|
|
16320
|
+
if (Array.isArray(value)) {
|
|
16321
|
+
if (value.length === 1) {
|
|
16322
|
+
formData.append(key, value[0]);
|
|
16323
|
+
continue;
|
|
16324
|
+
}
|
|
16325
|
+
const arrayKey = useArrayBrackets ? `${key}[]` : key;
|
|
16326
|
+
for (const item of value) {
|
|
16327
|
+
formData.append(arrayKey, item);
|
|
16328
|
+
}
|
|
16329
|
+
continue;
|
|
16330
|
+
}
|
|
16331
|
+
formData.append(key, value);
|
|
16332
|
+
}
|
|
16333
|
+
return formData;
|
|
16334
|
+
}
|
|
16096
16335
|
async function cancelResponseBody(response) {
|
|
16097
16336
|
var _a22;
|
|
16098
16337
|
try {
|
|
@@ -16100,6 +16339,202 @@ async function cancelResponseBody(response) {
|
|
|
16100
16339
|
} catch (e) {
|
|
16101
16340
|
}
|
|
16102
16341
|
}
|
|
16342
|
+
function isBrowserRuntime(globalThisAny = globalThis) {
|
|
16343
|
+
return globalThisAny.window != null;
|
|
16344
|
+
}
|
|
16345
|
+
function validateDownloadUrl(url2) {
|
|
16346
|
+
let parsed;
|
|
16347
|
+
try {
|
|
16348
|
+
parsed = new URL(url2);
|
|
16349
|
+
} catch (e) {
|
|
16350
|
+
throw new DownloadError({
|
|
16351
|
+
url: url2,
|
|
16352
|
+
message: `Invalid URL: ${url2}`
|
|
16353
|
+
});
|
|
16354
|
+
}
|
|
16355
|
+
if (parsed.protocol === "data:") {
|
|
16356
|
+
return;
|
|
16357
|
+
}
|
|
16358
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
16359
|
+
throw new DownloadError({
|
|
16360
|
+
url: url2,
|
|
16361
|
+
message: `URL scheme must be http, https, or data, got ${parsed.protocol}`
|
|
16362
|
+
});
|
|
16363
|
+
}
|
|
16364
|
+
const hostname2 = parsed.hostname.toLowerCase().replace(/\.+$/, "");
|
|
16365
|
+
if (!hostname2) {
|
|
16366
|
+
throw new DownloadError({
|
|
16367
|
+
url: url2,
|
|
16368
|
+
message: `URL must have a hostname`
|
|
16369
|
+
});
|
|
16370
|
+
}
|
|
16371
|
+
if (hostname2 === "localhost" || hostname2.endsWith(".local") || hostname2.endsWith(".localhost")) {
|
|
16372
|
+
throw new DownloadError({
|
|
16373
|
+
url: url2,
|
|
16374
|
+
message: `URL with hostname ${hostname2} is not allowed`
|
|
16375
|
+
});
|
|
16376
|
+
}
|
|
16377
|
+
if (hostname2.startsWith("[") && hostname2.endsWith("]")) {
|
|
16378
|
+
const ipv63 = hostname2.slice(1, -1);
|
|
16379
|
+
if (isPrivateIPv6(ipv63)) {
|
|
16380
|
+
throw new DownloadError({
|
|
16381
|
+
url: url2,
|
|
16382
|
+
message: `URL with IPv6 address ${hostname2} is not allowed`
|
|
16383
|
+
});
|
|
16384
|
+
}
|
|
16385
|
+
return;
|
|
16386
|
+
}
|
|
16387
|
+
if (isIPv4(hostname2)) {
|
|
16388
|
+
if (isPrivateIPv4(hostname2)) {
|
|
16389
|
+
throw new DownloadError({
|
|
16390
|
+
url: url2,
|
|
16391
|
+
message: `URL with IP address ${hostname2} is not allowed`
|
|
16392
|
+
});
|
|
16393
|
+
}
|
|
16394
|
+
return;
|
|
16395
|
+
}
|
|
16396
|
+
}
|
|
16397
|
+
function validateDownloadAddress({
|
|
16398
|
+
address,
|
|
16399
|
+
family,
|
|
16400
|
+
hostname: hostname2
|
|
16401
|
+
}) {
|
|
16402
|
+
const isUnsafe = family === 4 ? !isIPv4(address) || isPrivateIPv4(address) : family === 6 ? isPrivateIPv6(address) : true;
|
|
16403
|
+
if (isUnsafe) {
|
|
16404
|
+
throw new DownloadError({
|
|
16405
|
+
url: hostname2,
|
|
16406
|
+
message: `Hostname ${hostname2} resolved to disallowed IP address ${address}`
|
|
16407
|
+
});
|
|
16408
|
+
}
|
|
16409
|
+
}
|
|
16410
|
+
function isIPv4(hostname2) {
|
|
16411
|
+
const parts = hostname2.split(".");
|
|
16412
|
+
if (parts.length !== 4) return false;
|
|
16413
|
+
return parts.every((part) => {
|
|
16414
|
+
const num = Number(part);
|
|
16415
|
+
return Number.isInteger(num) && num >= 0 && num <= 255 && String(num) === part;
|
|
16416
|
+
});
|
|
16417
|
+
}
|
|
16418
|
+
function isPrivateIPv4(ip) {
|
|
16419
|
+
const parts = ip.split(".").map(Number);
|
|
16420
|
+
const [a, b, c] = parts;
|
|
16421
|
+
if (a === 0) return true;
|
|
16422
|
+
if (a === 10) return true;
|
|
16423
|
+
if (a === 100 && b >= 64 && b <= 127) return true;
|
|
16424
|
+
if (a === 127) return true;
|
|
16425
|
+
if (a === 169 && b === 254) return true;
|
|
16426
|
+
if (a === 172 && b >= 16 && b <= 31) return true;
|
|
16427
|
+
if (a === 192 && b === 0 && c === 0) return true;
|
|
16428
|
+
if (a === 192 && b === 168) return true;
|
|
16429
|
+
if (a === 198 && (b === 18 || b === 19)) return true;
|
|
16430
|
+
if (a >= 240) return true;
|
|
16431
|
+
return false;
|
|
16432
|
+
}
|
|
16433
|
+
function parseIPv6(ip) {
|
|
16434
|
+
let address = ip.toLowerCase();
|
|
16435
|
+
const zoneIndex = address.indexOf("%");
|
|
16436
|
+
if (zoneIndex !== -1) {
|
|
16437
|
+
address = address.slice(0, zoneIndex);
|
|
16438
|
+
}
|
|
16439
|
+
const halves = address.split("::");
|
|
16440
|
+
if (halves.length > 2) return null;
|
|
16441
|
+
const toGroups = (segment) => {
|
|
16442
|
+
if (segment === "") return [];
|
|
16443
|
+
const groups = [];
|
|
16444
|
+
const parts = segment.split(":");
|
|
16445
|
+
for (let i = 0; i < parts.length; i++) {
|
|
16446
|
+
const part = parts[i];
|
|
16447
|
+
if (part.includes(".")) {
|
|
16448
|
+
if (i !== parts.length - 1 || !isIPv4(part)) return null;
|
|
16449
|
+
const [a, b, c, d] = part.split(".").map(Number);
|
|
16450
|
+
groups.push(a << 8 | b, c << 8 | d);
|
|
16451
|
+
continue;
|
|
16452
|
+
}
|
|
16453
|
+
if (!/^[0-9a-f]{1,4}$/.test(part)) return null;
|
|
16454
|
+
groups.push(parseInt(part, 16));
|
|
16455
|
+
}
|
|
16456
|
+
return groups;
|
|
16457
|
+
};
|
|
16458
|
+
const head2 = toGroups(halves[0]);
|
|
16459
|
+
if (head2 === null) return null;
|
|
16460
|
+
if (halves.length === 2) {
|
|
16461
|
+
const tail = toGroups(halves[1]);
|
|
16462
|
+
if (tail === null) return null;
|
|
16463
|
+
const fill = 8 - head2.length - tail.length;
|
|
16464
|
+
if (fill < 0) return null;
|
|
16465
|
+
return [...head2, ...new Array(fill).fill(0), ...tail];
|
|
16466
|
+
}
|
|
16467
|
+
return head2.length === 8 ? head2 : null;
|
|
16468
|
+
}
|
|
16469
|
+
function isPrivateIPv6(ip) {
|
|
16470
|
+
const groups = parseIPv6(ip);
|
|
16471
|
+
if (groups === null) return true;
|
|
16472
|
+
const topZero = (count) => groups.slice(0, count).every((group) => group === 0);
|
|
16473
|
+
if (topZero(7) && (groups[7] === 0 || groups[7] === 1)) return true;
|
|
16474
|
+
if ((groups[0] & 65024) === 64512) return true;
|
|
16475
|
+
if ((groups[0] & 65472) === 65152) return true;
|
|
16476
|
+
if ((groups[0] & 65472) === 65216) return true;
|
|
16477
|
+
if ((groups[0] & 65280) === 65280) return true;
|
|
16478
|
+
const embedsIPv4 = (
|
|
16479
|
+
// ::/96 — IPv4-compatible (deprecated)
|
|
16480
|
+
topZero(6) || // ::ffff:0:0/96 — IPv4-mapped (ffff in group 5)
|
|
16481
|
+
topZero(5) && groups[5] === 65535 || // ::ffff:0:0/96 — IPv4-translated form (ffff in group 4, group 5 zero)
|
|
16482
|
+
topZero(4) && groups[4] === 65535 && groups[5] === 0 || // 64:ff9b::/96 — NAT64 well-known prefix
|
|
16483
|
+
groups[0] === 100 && groups[1] === 65435 && groups[2] === 0 && groups[3] === 0 && groups[4] === 0 && groups[5] === 0 || // 64:ff9b:1::/48 — NAT64 local-use prefix
|
|
16484
|
+
groups[0] === 100 && groups[1] === 65435 && groups[2] === 1
|
|
16485
|
+
);
|
|
16486
|
+
if (embedsIPv4) {
|
|
16487
|
+
const a = groups[6] >> 8 & 255;
|
|
16488
|
+
const b = groups[6] & 255;
|
|
16489
|
+
const c = groups[7] >> 8 & 255;
|
|
16490
|
+
const d = groups[7] & 255;
|
|
16491
|
+
return isPrivateIPv4(`${a}.${b}.${c}.${d}`);
|
|
16492
|
+
}
|
|
16493
|
+
return false;
|
|
16494
|
+
}
|
|
16495
|
+
function createSafeLookup(lookup) {
|
|
16496
|
+
return ((hostname2, options, callback) => {
|
|
16497
|
+
lookup(hostname2, { ...options, all: true }, (error40, addresses) => {
|
|
16498
|
+
if (error40) {
|
|
16499
|
+
callback(error40);
|
|
16500
|
+
return;
|
|
16501
|
+
}
|
|
16502
|
+
try {
|
|
16503
|
+
const [firstAddress] = addresses;
|
|
16504
|
+
if (firstAddress == null) {
|
|
16505
|
+
throw new Error(`Hostname ${hostname2} did not resolve to an address`);
|
|
16506
|
+
}
|
|
16507
|
+
for (const { address, family } of addresses) {
|
|
16508
|
+
validateDownloadAddress({ address, family, hostname: hostname2 });
|
|
16509
|
+
}
|
|
16510
|
+
if (options.all === true) {
|
|
16511
|
+
callback(null, addresses);
|
|
16512
|
+
} else {
|
|
16513
|
+
callback(
|
|
16514
|
+
null,
|
|
16515
|
+
firstAddress.address,
|
|
16516
|
+
firstAddress.family
|
|
16517
|
+
);
|
|
16518
|
+
}
|
|
16519
|
+
} catch (error210) {
|
|
16520
|
+
callback(
|
|
16521
|
+
error210 instanceof Error ? error210 : new Error(String(error210))
|
|
16522
|
+
);
|
|
16523
|
+
}
|
|
16524
|
+
});
|
|
16525
|
+
});
|
|
16526
|
+
}
|
|
16527
|
+
function isNodeRuntime() {
|
|
16528
|
+
var _a22, _b22;
|
|
16529
|
+
const runtimeProcess = globalThis.process;
|
|
16530
|
+
return ((_a22 = runtimeProcess == null ? void 0 : runtimeProcess.release) == null ? void 0 : _a22.name) === "node" && ((_b22 = runtimeProcess.versions) == null ? void 0 : _b22.bun) == null;
|
|
16531
|
+
}
|
|
16532
|
+
async function getDefaultDownloadFetch() {
|
|
16533
|
+
if (!isNodeRuntime() || !initialGlobalFetchIsNodeDefault || globalThis.fetch !== initialGlobalFetch) {
|
|
16534
|
+
return globalThis.fetch;
|
|
16535
|
+
}
|
|
16536
|
+
return safeNodeFetchPromise != null ? safeNodeFetchPromise : safeNodeFetchPromise = createSafeNodeFetch();
|
|
16537
|
+
}
|
|
16103
16538
|
function isNodeDefaultFetch(fetch2) {
|
|
16104
16539
|
if (typeof fetch2 !== "function") {
|
|
16105
16540
|
return false;
|
|
@@ -16107,6 +16542,92 @@ function isNodeDefaultFetch(fetch2) {
|
|
|
16107
16542
|
const source = Function.prototype.toString.call(fetch2);
|
|
16108
16543
|
return source.includes("internal/deps/undici") || source.includes("lazy loading of undici");
|
|
16109
16544
|
}
|
|
16545
|
+
async function createSafeNodeFetch() {
|
|
16546
|
+
const [{ createRequire: createRequire2 }, { lookup }] = await Promise.all([
|
|
16547
|
+
loadNodeModule("node:module"),
|
|
16548
|
+
loadNodeModule("node:dns")
|
|
16549
|
+
]);
|
|
16550
|
+
const { Agent, fetch: fetch2 } = createRequire2(getCurrentModulePath())(
|
|
16551
|
+
"undici"
|
|
16552
|
+
);
|
|
16553
|
+
const dispatcher = new Agent({
|
|
16554
|
+
connect: {
|
|
16555
|
+
lookup: createSafeLookup(lookup)
|
|
16556
|
+
}
|
|
16557
|
+
});
|
|
16558
|
+
return ((input, init) => fetch2(
|
|
16559
|
+
input,
|
|
16560
|
+
{
|
|
16561
|
+
...init,
|
|
16562
|
+
dispatcher
|
|
16563
|
+
}
|
|
16564
|
+
));
|
|
16565
|
+
}
|
|
16566
|
+
async function loadNodeModule(id) {
|
|
16567
|
+
var _a22;
|
|
16568
|
+
const processWithBuiltins = globalThis.process;
|
|
16569
|
+
const builtinModule = (_a22 = processWithBuiltins == null ? void 0 : processWithBuiltins.getBuiltinModule) == null ? void 0 : _a22.call(processWithBuiltins, id);
|
|
16570
|
+
if (builtinModule == null) {
|
|
16571
|
+
throw new Error(`Node.js built-in module ${id} is unavailable`);
|
|
16572
|
+
}
|
|
16573
|
+
return builtinModule;
|
|
16574
|
+
}
|
|
16575
|
+
function getCurrentModulePath() {
|
|
16576
|
+
const originalPrepareStackTrace = Error.prepareStackTrace;
|
|
16577
|
+
try {
|
|
16578
|
+
Error.prepareStackTrace = (_error, callSites) => callSites;
|
|
16579
|
+
const error40 = new Error("Capture current module path");
|
|
16580
|
+
Error.captureStackTrace(error40, getCurrentModulePath);
|
|
16581
|
+
const [caller] = error40.stack;
|
|
16582
|
+
const fileName = caller == null ? void 0 : caller.getFileName();
|
|
16583
|
+
if (fileName == null) {
|
|
16584
|
+
throw new Error("Unable to determine the current module path");
|
|
16585
|
+
}
|
|
16586
|
+
return fileName;
|
|
16587
|
+
} finally {
|
|
16588
|
+
Error.prepareStackTrace = originalPrepareStackTrace;
|
|
16589
|
+
}
|
|
16590
|
+
}
|
|
16591
|
+
async function fetchWithValidatedRedirects({
|
|
16592
|
+
url: url2,
|
|
16593
|
+
headers,
|
|
16594
|
+
abortSignal,
|
|
16595
|
+
maxRedirects = MAX_DOWNLOAD_REDIRECTS
|
|
16596
|
+
}) {
|
|
16597
|
+
const baseInit = { signal: abortSignal };
|
|
16598
|
+
if (headers !== void 0) {
|
|
16599
|
+
baseInit.headers = headers;
|
|
16600
|
+
}
|
|
16601
|
+
let currentUrl = url2;
|
|
16602
|
+
for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {
|
|
16603
|
+
validateDownloadUrl(currentUrl);
|
|
16604
|
+
const fetch2 = await getDefaultDownloadFetch();
|
|
16605
|
+
const response = await fetch2(currentUrl, {
|
|
16606
|
+
...baseInit,
|
|
16607
|
+
redirect: "manual"
|
|
16608
|
+
});
|
|
16609
|
+
if (response.type === "opaqueredirect") {
|
|
16610
|
+
if (!isBrowserRuntime()) {
|
|
16611
|
+
throw new DownloadError({
|
|
16612
|
+
url: url2,
|
|
16613
|
+
message: `Redirect from ${currentUrl} could not be validated and was blocked`
|
|
16614
|
+
});
|
|
16615
|
+
}
|
|
16616
|
+
return await fetch2(currentUrl, { ...baseInit, redirect: "follow" });
|
|
16617
|
+
}
|
|
16618
|
+
const location = response.headers.get("location");
|
|
16619
|
+
if (response.status >= 300 && response.status < 400 && location) {
|
|
16620
|
+
await cancelResponseBody(response);
|
|
16621
|
+
currentUrl = new URL(location, currentUrl).toString();
|
|
16622
|
+
continue;
|
|
16623
|
+
}
|
|
16624
|
+
return response;
|
|
16625
|
+
}
|
|
16626
|
+
throw new DownloadError({
|
|
16627
|
+
url: url2,
|
|
16628
|
+
message: `Too many redirects (max ${maxRedirects})`
|
|
16629
|
+
});
|
|
16630
|
+
}
|
|
16110
16631
|
async function readResponseWithSizeLimit({
|
|
16111
16632
|
response,
|
|
16112
16633
|
url: url2,
|
|
@@ -16161,6 +16682,35 @@ async function readResponseWithSizeLimit({
|
|
|
16161
16682
|
}
|
|
16162
16683
|
return result;
|
|
16163
16684
|
}
|
|
16685
|
+
async function downloadBlob(url2, options) {
|
|
16686
|
+
var _a22, _b22;
|
|
16687
|
+
try {
|
|
16688
|
+
const response = await fetchWithValidatedRedirects({
|
|
16689
|
+
url: url2,
|
|
16690
|
+
abortSignal: options == null ? void 0 : options.abortSignal
|
|
16691
|
+
});
|
|
16692
|
+
if (!response.ok) {
|
|
16693
|
+
await cancelResponseBody(response);
|
|
16694
|
+
throw new DownloadError({
|
|
16695
|
+
url: url2,
|
|
16696
|
+
statusCode: response.status,
|
|
16697
|
+
statusText: response.statusText
|
|
16698
|
+
});
|
|
16699
|
+
}
|
|
16700
|
+
const data2 = await readResponseWithSizeLimit({
|
|
16701
|
+
response,
|
|
16702
|
+
url: url2,
|
|
16703
|
+
maxBytes: (_a22 = options == null ? void 0 : options.maxBytes) != null ? _a22 : DEFAULT_MAX_DOWNLOAD_SIZE
|
|
16704
|
+
});
|
|
16705
|
+
const contentType = (_b22 = response.headers.get("content-type")) != null ? _b22 : void 0;
|
|
16706
|
+
return new Blob([data2], contentType ? { type: contentType } : void 0);
|
|
16707
|
+
} catch (error40) {
|
|
16708
|
+
if (DownloadError.isInstance(error40)) {
|
|
16709
|
+
throw error40;
|
|
16710
|
+
}
|
|
16711
|
+
throw new DownloadError({ url: url2, cause: error40 });
|
|
16712
|
+
}
|
|
16713
|
+
}
|
|
16164
16714
|
function isAbortError(error40) {
|
|
16165
16715
|
return (error40 instanceof Error || error40 instanceof DOMException) && (error40.name === "AbortError" || error40.name === "ResponseAborted" || // Next.js
|
|
16166
16716
|
error40.name === "TimeoutError");
|
|
@@ -17380,6 +17930,21 @@ async function safeParseJSON({
|
|
|
17380
17930
|
};
|
|
17381
17931
|
}
|
|
17382
17932
|
}
|
|
17933
|
+
function parseJsonEventStream({
|
|
17934
|
+
stream: stream2,
|
|
17935
|
+
schema
|
|
17936
|
+
}) {
|
|
17937
|
+
return stream2.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream()).pipeThrough(
|
|
17938
|
+
new TransformStream({
|
|
17939
|
+
async transform({ data: data2 }, controller) {
|
|
17940
|
+
if (data2 === "[DONE]") {
|
|
17941
|
+
return;
|
|
17942
|
+
}
|
|
17943
|
+
controller.enqueue(await safeParseJSON({ text: data2, schema }));
|
|
17944
|
+
}
|
|
17945
|
+
})
|
|
17946
|
+
);
|
|
17947
|
+
}
|
|
17383
17948
|
async function parseProviderOptions({
|
|
17384
17949
|
provider,
|
|
17385
17950
|
providerOptions,
|
|
@@ -17407,6 +17972,62 @@ async function resolve(value) {
|
|
|
17407
17972
|
}
|
|
17408
17973
|
return Promise.resolve(value);
|
|
17409
17974
|
}
|
|
17975
|
+
function wrapResponseBodyStream({
|
|
17976
|
+
stream: stream2,
|
|
17977
|
+
url: url2,
|
|
17978
|
+
requestBodyValues,
|
|
17979
|
+
statusCode,
|
|
17980
|
+
responseHeaders
|
|
17981
|
+
}) {
|
|
17982
|
+
const reader = stream2.getReader();
|
|
17983
|
+
let readerReleased = false;
|
|
17984
|
+
const releaseReader = () => {
|
|
17985
|
+
if (!readerReleased) {
|
|
17986
|
+
reader.releaseLock();
|
|
17987
|
+
readerReleased = true;
|
|
17988
|
+
}
|
|
17989
|
+
};
|
|
17990
|
+
return new ReadableStream({
|
|
17991
|
+
async pull(controller) {
|
|
17992
|
+
try {
|
|
17993
|
+
const { done, value } = await reader.read();
|
|
17994
|
+
if (done) {
|
|
17995
|
+
releaseReader();
|
|
17996
|
+
controller.close();
|
|
17997
|
+
} else {
|
|
17998
|
+
controller.enqueue(value);
|
|
17999
|
+
}
|
|
18000
|
+
} catch (error40) {
|
|
18001
|
+
releaseReader();
|
|
18002
|
+
if (isAbortError(error40)) {
|
|
18003
|
+
controller.error(error40);
|
|
18004
|
+
return;
|
|
18005
|
+
}
|
|
18006
|
+
controller.error(
|
|
18007
|
+
handleFetchError({
|
|
18008
|
+
error: new APICallError({
|
|
18009
|
+
message: "Failed to process successful response",
|
|
18010
|
+
cause: error40,
|
|
18011
|
+
statusCode,
|
|
18012
|
+
url: url2,
|
|
18013
|
+
responseHeaders,
|
|
18014
|
+
requestBodyValues
|
|
18015
|
+
}),
|
|
18016
|
+
url: url2,
|
|
18017
|
+
requestBodyValues
|
|
18018
|
+
})
|
|
18019
|
+
);
|
|
18020
|
+
}
|
|
18021
|
+
},
|
|
18022
|
+
async cancel(reason) {
|
|
18023
|
+
try {
|
|
18024
|
+
await reader.cancel(reason);
|
|
18025
|
+
} finally {
|
|
18026
|
+
releaseReader();
|
|
18027
|
+
}
|
|
18028
|
+
}
|
|
18029
|
+
});
|
|
18030
|
+
}
|
|
17410
18031
|
async function readResponseBodyAsText({
|
|
17411
18032
|
response,
|
|
17412
18033
|
url: url2
|
|
@@ -17425,8 +18046,8 @@ function stripFileExtension(filename) {
|
|
|
17425
18046
|
function withoutTrailingSlash(url2) {
|
|
17426
18047
|
return url2 == null ? void 0 : url2.replace(/\/$/, "");
|
|
17427
18048
|
}
|
|
17428
|
-
var btoa2, atob2, name14, marker15, symbol16, _a15, _b15, DownloadError, initialGlobalFetch, initialGlobalFetchIsNodeDefault, DEFAULT_MAX_DOWNLOAD_SIZE, createIdGenerator, generateId, FETCH_FAILED_ERROR_MESSAGES, RETRYABLE_NETWORK_ERROR_CODES, VERSION, DEFAULT_SCHEMA_PREFIX, DEFAULT_SCHEMA_SUFFIX, DEFAULT_GENERIC_SUFFIX, suspectProtoRx, suspectConstructorRx, ignoreOverride, defaultOptions, getDefaultOptions, parseCatchDef, integerDateParser, isJsonSchema7AllOfType, emojiRegex2, zodPatterns, ALPHA_NUMERIC, primitiveMappings, asAnyOf, parseOptionalDef, parsePipelineDef, parseReadonlyDef, selectParser, getRelativePath, get$ref, addMeta, getRefs, zod3ToJsonSchema, schemaSymbol, getOriginalFetch2, postJsonToApi, postToApi, textDecoder, createJsonErrorResponseHandler, createJsonResponseHandler;
|
|
17429
|
-
var
|
|
18049
|
+
var btoa2, atob2, name14, marker15, symbol16, _a15, _b15, DownloadError, safeNodeFetchPromise, initialGlobalFetch, initialGlobalFetchIsNodeDefault, MAX_DOWNLOAD_REDIRECTS, DEFAULT_MAX_DOWNLOAD_SIZE, createIdGenerator, generateId, FETCH_FAILED_ERROR_MESSAGES, RETRYABLE_NETWORK_ERROR_CODES, VERSION, DEFAULT_SCHEMA_PREFIX, DEFAULT_SCHEMA_SUFFIX, DEFAULT_GENERIC_SUFFIX, suspectProtoRx, suspectConstructorRx, ignoreOverride, defaultOptions, getDefaultOptions, parseCatchDef, integerDateParser, isJsonSchema7AllOfType, emojiRegex2, zodPatterns, ALPHA_NUMERIC, primitiveMappings, asAnyOf, parseOptionalDef, parsePipelineDef, parseReadonlyDef, selectParser, getRelativePath, get$ref, addMeta, getRefs, zod3ToJsonSchema, schemaSymbol, getOriginalFetch2, postJsonToApi, postFormDataToApi, postToApi, textDecoder, createJsonErrorResponseHandler, createEventSourceResponseHandler, createJsonResponseHandler;
|
|
18050
|
+
var init_dist3 = __esm({
|
|
17430
18051
|
"node_modules/@ai-sdk/provider-utils/dist/index.mjs"() {
|
|
17431
18052
|
init_dist();
|
|
17432
18053
|
init_dist();
|
|
@@ -17439,6 +18060,7 @@ var init_dist2 = __esm({
|
|
|
17439
18060
|
init_v3();
|
|
17440
18061
|
init_v3();
|
|
17441
18062
|
init_v3();
|
|
18063
|
+
init_stream();
|
|
17442
18064
|
init_dist();
|
|
17443
18065
|
init_dist();
|
|
17444
18066
|
init_dist();
|
|
@@ -17466,6 +18088,7 @@ var init_dist2 = __esm({
|
|
|
17466
18088
|
};
|
|
17467
18089
|
initialGlobalFetch = globalThis.fetch;
|
|
17468
18090
|
initialGlobalFetchIsNodeDefault = isNodeDefaultFetch(initialGlobalFetch);
|
|
18091
|
+
MAX_DOWNLOAD_REDIRECTS = 10;
|
|
17469
18092
|
DEFAULT_MAX_DOWNLOAD_SIZE = 2 * 1024 * 1024 * 1024;
|
|
17470
18093
|
createIdGenerator = ({
|
|
17471
18094
|
prefix,
|
|
@@ -17874,6 +18497,26 @@ var init_dist2 = __esm({
|
|
|
17874
18497
|
abortSignal,
|
|
17875
18498
|
fetch: fetch2
|
|
17876
18499
|
});
|
|
18500
|
+
postFormDataToApi = async ({
|
|
18501
|
+
url: url2,
|
|
18502
|
+
headers,
|
|
18503
|
+
formData,
|
|
18504
|
+
failedResponseHandler,
|
|
18505
|
+
successfulResponseHandler,
|
|
18506
|
+
abortSignal,
|
|
18507
|
+
fetch: fetch2
|
|
18508
|
+
}) => postToApi({
|
|
18509
|
+
url: url2,
|
|
18510
|
+
headers,
|
|
18511
|
+
body: {
|
|
18512
|
+
content: formData,
|
|
18513
|
+
values: Object.fromEntries(formData.entries())
|
|
18514
|
+
},
|
|
18515
|
+
failedResponseHandler,
|
|
18516
|
+
successfulResponseHandler,
|
|
18517
|
+
abortSignal,
|
|
18518
|
+
fetch: fetch2
|
|
18519
|
+
});
|
|
17877
18520
|
postToApi = async ({
|
|
17878
18521
|
url: url2,
|
|
17879
18522
|
headers = {},
|
|
@@ -17998,6 +18641,25 @@ var init_dist2 = __esm({
|
|
|
17998
18641
|
};
|
|
17999
18642
|
}
|
|
18000
18643
|
};
|
|
18644
|
+
createEventSourceResponseHandler = (chunkSchema) => async ({ response, url: url2, requestBodyValues }) => {
|
|
18645
|
+
const responseHeaders = extractResponseHeaders(response);
|
|
18646
|
+
if (response.body == null) {
|
|
18647
|
+
throw new EmptyResponseBodyError({});
|
|
18648
|
+
}
|
|
18649
|
+
return {
|
|
18650
|
+
responseHeaders,
|
|
18651
|
+
value: parseJsonEventStream({
|
|
18652
|
+
stream: wrapResponseBodyStream({
|
|
18653
|
+
stream: response.body,
|
|
18654
|
+
url: url2,
|
|
18655
|
+
requestBodyValues,
|
|
18656
|
+
statusCode: response.status,
|
|
18657
|
+
responseHeaders
|
|
18658
|
+
}),
|
|
18659
|
+
schema: chunkSchema
|
|
18660
|
+
})
|
|
18661
|
+
};
|
|
18662
|
+
};
|
|
18001
18663
|
createJsonResponseHandler = (responseSchema) => async ({ response, url: url2, requestBodyValues }) => {
|
|
18002
18664
|
const responseBody = await readResponseBodyAsText({ response, url: url2 });
|
|
18003
18665
|
const parsedResult = await safeParseJSON({
|
|
@@ -18025,6 +18687,1758 @@ var init_dist2 = __esm({
|
|
|
18025
18687
|
}
|
|
18026
18688
|
});
|
|
18027
18689
|
|
|
18690
|
+
// node_modules/@ai-sdk/openai-compatible/dist/index.mjs
|
|
18691
|
+
function toCamelCase(str) {
|
|
18692
|
+
return str.replace(/[_-]([a-z])/g, (g) => g[1].toUpperCase());
|
|
18693
|
+
}
|
|
18694
|
+
function resolveProviderOptionsKey(rawName, providerOptions) {
|
|
18695
|
+
const camelName = toCamelCase(rawName);
|
|
18696
|
+
if (camelName !== rawName && (providerOptions == null ? void 0 : providerOptions[camelName]) != null) {
|
|
18697
|
+
return camelName;
|
|
18698
|
+
}
|
|
18699
|
+
return rawName;
|
|
18700
|
+
}
|
|
18701
|
+
function convertOpenAICompatibleChatUsage(usage) {
|
|
18702
|
+
var _a17, _b16, _c, _d, _e, _f;
|
|
18703
|
+
if (usage == null) {
|
|
18704
|
+
return {
|
|
18705
|
+
inputTokens: {
|
|
18706
|
+
total: void 0,
|
|
18707
|
+
noCache: void 0,
|
|
18708
|
+
cacheRead: void 0,
|
|
18709
|
+
cacheWrite: void 0
|
|
18710
|
+
},
|
|
18711
|
+
outputTokens: {
|
|
18712
|
+
total: void 0,
|
|
18713
|
+
text: void 0,
|
|
18714
|
+
reasoning: void 0
|
|
18715
|
+
},
|
|
18716
|
+
raw: void 0
|
|
18717
|
+
};
|
|
18718
|
+
}
|
|
18719
|
+
const promptTokens = (_a17 = usage.prompt_tokens) != null ? _a17 : 0;
|
|
18720
|
+
const completionTokens = (_b16 = usage.completion_tokens) != null ? _b16 : 0;
|
|
18721
|
+
const cacheReadTokens = (_d = (_c = usage.prompt_tokens_details) == null ? void 0 : _c.cached_tokens) != null ? _d : 0;
|
|
18722
|
+
const reasoningTokens = (_f = (_e = usage.completion_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : 0;
|
|
18723
|
+
return {
|
|
18724
|
+
inputTokens: {
|
|
18725
|
+
total: promptTokens,
|
|
18726
|
+
noCache: promptTokens - cacheReadTokens,
|
|
18727
|
+
cacheRead: cacheReadTokens,
|
|
18728
|
+
cacheWrite: void 0
|
|
18729
|
+
},
|
|
18730
|
+
outputTokens: {
|
|
18731
|
+
total: completionTokens,
|
|
18732
|
+
text: Math.max(0, completionTokens - reasoningTokens),
|
|
18733
|
+
reasoning: reasoningTokens
|
|
18734
|
+
},
|
|
18735
|
+
raw: usage
|
|
18736
|
+
};
|
|
18737
|
+
}
|
|
18738
|
+
function getOpenAIMetadata(message) {
|
|
18739
|
+
var _a17, _b16;
|
|
18740
|
+
return (_b16 = (_a17 = message == null ? void 0 : message.providerOptions) == null ? void 0 : _a17.openaiCompatible) != null ? _b16 : {};
|
|
18741
|
+
}
|
|
18742
|
+
function getAudioFormat(mediaType) {
|
|
18743
|
+
switch (mediaType) {
|
|
18744
|
+
case "audio/wav":
|
|
18745
|
+
return "wav";
|
|
18746
|
+
case "audio/mp3":
|
|
18747
|
+
case "audio/mpeg":
|
|
18748
|
+
return "mp3";
|
|
18749
|
+
default:
|
|
18750
|
+
return null;
|
|
18751
|
+
}
|
|
18752
|
+
}
|
|
18753
|
+
function convertToOpenAICompatibleChatMessages(prompt) {
|
|
18754
|
+
var _a17, _b16, _c;
|
|
18755
|
+
const messages = [];
|
|
18756
|
+
for (const { role, content, ...message } of prompt) {
|
|
18757
|
+
const metadata = getOpenAIMetadata({ ...message });
|
|
18758
|
+
switch (role) {
|
|
18759
|
+
case "system": {
|
|
18760
|
+
messages.push({ role: "system", content, ...metadata });
|
|
18761
|
+
break;
|
|
18762
|
+
}
|
|
18763
|
+
case "user": {
|
|
18764
|
+
if (content.length === 1 && content[0].type === "text") {
|
|
18765
|
+
messages.push({
|
|
18766
|
+
role: "user",
|
|
18767
|
+
content: content[0].text,
|
|
18768
|
+
...getOpenAIMetadata(content[0])
|
|
18769
|
+
});
|
|
18770
|
+
break;
|
|
18771
|
+
}
|
|
18772
|
+
messages.push({
|
|
18773
|
+
role: "user",
|
|
18774
|
+
content: content.map((part) => {
|
|
18775
|
+
var _a22;
|
|
18776
|
+
const partMetadata = getOpenAIMetadata(part);
|
|
18777
|
+
switch (part.type) {
|
|
18778
|
+
case "text": {
|
|
18779
|
+
return { type: "text", text: part.text, ...partMetadata };
|
|
18780
|
+
}
|
|
18781
|
+
case "file": {
|
|
18782
|
+
if (part.mediaType.startsWith("image/")) {
|
|
18783
|
+
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
18784
|
+
return {
|
|
18785
|
+
type: "image_url",
|
|
18786
|
+
image_url: {
|
|
18787
|
+
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`
|
|
18788
|
+
},
|
|
18789
|
+
...partMetadata
|
|
18790
|
+
};
|
|
18791
|
+
}
|
|
18792
|
+
if (part.mediaType.startsWith("audio/")) {
|
|
18793
|
+
if (part.data instanceof URL) {
|
|
18794
|
+
throw new UnsupportedFunctionalityError({
|
|
18795
|
+
functionality: "audio file parts with URLs"
|
|
18796
|
+
});
|
|
18797
|
+
}
|
|
18798
|
+
const format2 = getAudioFormat(part.mediaType);
|
|
18799
|
+
if (format2 === null) {
|
|
18800
|
+
throw new UnsupportedFunctionalityError({
|
|
18801
|
+
functionality: `audio media type ${part.mediaType}`
|
|
18802
|
+
});
|
|
18803
|
+
}
|
|
18804
|
+
return {
|
|
18805
|
+
type: "input_audio",
|
|
18806
|
+
input_audio: {
|
|
18807
|
+
data: convertToBase64(part.data),
|
|
18808
|
+
format: format2
|
|
18809
|
+
},
|
|
18810
|
+
...partMetadata
|
|
18811
|
+
};
|
|
18812
|
+
}
|
|
18813
|
+
if (part.mediaType === "application/pdf") {
|
|
18814
|
+
if (part.data instanceof URL) {
|
|
18815
|
+
throw new UnsupportedFunctionalityError({
|
|
18816
|
+
functionality: "PDF file parts with URLs"
|
|
18817
|
+
});
|
|
18818
|
+
}
|
|
18819
|
+
return {
|
|
18820
|
+
type: "file",
|
|
18821
|
+
file: {
|
|
18822
|
+
filename: (_a22 = part.filename) != null ? _a22 : "document.pdf",
|
|
18823
|
+
file_data: `data:application/pdf;base64,${convertToBase64(part.data)}`
|
|
18824
|
+
},
|
|
18825
|
+
...partMetadata
|
|
18826
|
+
};
|
|
18827
|
+
}
|
|
18828
|
+
if (part.mediaType.startsWith("text/")) {
|
|
18829
|
+
const textContent = part.data instanceof URL ? part.data.toString() : typeof part.data === "string" ? new TextDecoder().decode(
|
|
18830
|
+
convertBase64ToUint8Array(part.data)
|
|
18831
|
+
) : new TextDecoder().decode(part.data);
|
|
18832
|
+
return {
|
|
18833
|
+
type: "text",
|
|
18834
|
+
text: textContent,
|
|
18835
|
+
...partMetadata
|
|
18836
|
+
};
|
|
18837
|
+
}
|
|
18838
|
+
throw new UnsupportedFunctionalityError({
|
|
18839
|
+
functionality: `file part media type ${part.mediaType}`
|
|
18840
|
+
});
|
|
18841
|
+
}
|
|
18842
|
+
}
|
|
18843
|
+
}),
|
|
18844
|
+
...metadata
|
|
18845
|
+
});
|
|
18846
|
+
break;
|
|
18847
|
+
}
|
|
18848
|
+
case "assistant": {
|
|
18849
|
+
let text = "";
|
|
18850
|
+
let reasoning = "";
|
|
18851
|
+
const toolCalls = [];
|
|
18852
|
+
for (const part of content) {
|
|
18853
|
+
const partMetadata = getOpenAIMetadata(part);
|
|
18854
|
+
switch (part.type) {
|
|
18855
|
+
case "text": {
|
|
18856
|
+
text += part.text;
|
|
18857
|
+
break;
|
|
18858
|
+
}
|
|
18859
|
+
case "reasoning": {
|
|
18860
|
+
reasoning += part.text;
|
|
18861
|
+
break;
|
|
18862
|
+
}
|
|
18863
|
+
case "tool-call": {
|
|
18864
|
+
const thoughtSignature = (_b16 = (_a17 = part.providerOptions) == null ? void 0 : _a17.google) == null ? void 0 : _b16.thoughtSignature;
|
|
18865
|
+
toolCalls.push({
|
|
18866
|
+
id: part.toolCallId,
|
|
18867
|
+
type: "function",
|
|
18868
|
+
function: {
|
|
18869
|
+
name: part.toolName,
|
|
18870
|
+
arguments: JSON.stringify(part.input)
|
|
18871
|
+
},
|
|
18872
|
+
...partMetadata,
|
|
18873
|
+
// Include extra_content for Google Gemini thought signatures
|
|
18874
|
+
...thoughtSignature ? {
|
|
18875
|
+
extra_content: {
|
|
18876
|
+
google: {
|
|
18877
|
+
thought_signature: String(thoughtSignature)
|
|
18878
|
+
}
|
|
18879
|
+
}
|
|
18880
|
+
} : {}
|
|
18881
|
+
});
|
|
18882
|
+
break;
|
|
18883
|
+
}
|
|
18884
|
+
}
|
|
18885
|
+
}
|
|
18886
|
+
messages.push({
|
|
18887
|
+
role: "assistant",
|
|
18888
|
+
content: toolCalls.length > 0 ? text || null : text,
|
|
18889
|
+
...reasoning.length > 0 ? { reasoning_content: reasoning } : {},
|
|
18890
|
+
tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
|
|
18891
|
+
...metadata
|
|
18892
|
+
});
|
|
18893
|
+
break;
|
|
18894
|
+
}
|
|
18895
|
+
case "tool": {
|
|
18896
|
+
for (const toolResponse of content) {
|
|
18897
|
+
if (toolResponse.type === "tool-approval-response") {
|
|
18898
|
+
continue;
|
|
18899
|
+
}
|
|
18900
|
+
const output = toolResponse.output;
|
|
18901
|
+
let contentValue;
|
|
18902
|
+
switch (output.type) {
|
|
18903
|
+
case "text":
|
|
18904
|
+
case "error-text":
|
|
18905
|
+
contentValue = output.value;
|
|
18906
|
+
break;
|
|
18907
|
+
case "execution-denied":
|
|
18908
|
+
contentValue = (_c = output.reason) != null ? _c : "Tool call execution denied.";
|
|
18909
|
+
break;
|
|
18910
|
+
case "content":
|
|
18911
|
+
case "json":
|
|
18912
|
+
case "error-json":
|
|
18913
|
+
contentValue = JSON.stringify(output.value);
|
|
18914
|
+
break;
|
|
18915
|
+
}
|
|
18916
|
+
const toolResponseMetadata = getOpenAIMetadata(toolResponse);
|
|
18917
|
+
messages.push({
|
|
18918
|
+
role: "tool",
|
|
18919
|
+
tool_call_id: toolResponse.toolCallId,
|
|
18920
|
+
content: contentValue,
|
|
18921
|
+
...toolResponseMetadata
|
|
18922
|
+
});
|
|
18923
|
+
}
|
|
18924
|
+
break;
|
|
18925
|
+
}
|
|
18926
|
+
default: {
|
|
18927
|
+
const _exhaustiveCheck = role;
|
|
18928
|
+
throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
|
|
18929
|
+
}
|
|
18930
|
+
}
|
|
18931
|
+
}
|
|
18932
|
+
return messages;
|
|
18933
|
+
}
|
|
18934
|
+
function getResponseMetadata({
|
|
18935
|
+
id,
|
|
18936
|
+
model,
|
|
18937
|
+
created
|
|
18938
|
+
}) {
|
|
18939
|
+
return {
|
|
18940
|
+
id: id != null ? id : void 0,
|
|
18941
|
+
modelId: model != null ? model : void 0,
|
|
18942
|
+
timestamp: created != null ? new Date(created * 1e3) : void 0
|
|
18943
|
+
};
|
|
18944
|
+
}
|
|
18945
|
+
function mapOpenAICompatibleFinishReason(finishReason) {
|
|
18946
|
+
switch (finishReason) {
|
|
18947
|
+
case "stop":
|
|
18948
|
+
return "stop";
|
|
18949
|
+
case "length":
|
|
18950
|
+
return "length";
|
|
18951
|
+
case "content_filter":
|
|
18952
|
+
return "content-filter";
|
|
18953
|
+
case "function_call":
|
|
18954
|
+
case "tool_calls":
|
|
18955
|
+
return "tool-calls";
|
|
18956
|
+
default:
|
|
18957
|
+
return "other";
|
|
18958
|
+
}
|
|
18959
|
+
}
|
|
18960
|
+
function prepareTools({
|
|
18961
|
+
tools,
|
|
18962
|
+
toolChoice
|
|
18963
|
+
}) {
|
|
18964
|
+
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
18965
|
+
const toolWarnings = [];
|
|
18966
|
+
if (tools == null) {
|
|
18967
|
+
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
18968
|
+
}
|
|
18969
|
+
const openaiCompatTools = [];
|
|
18970
|
+
for (const tool6 of tools) {
|
|
18971
|
+
if (tool6.type === "provider") {
|
|
18972
|
+
toolWarnings.push({
|
|
18973
|
+
type: "unsupported",
|
|
18974
|
+
feature: `provider-defined tool ${tool6.id}`
|
|
18975
|
+
});
|
|
18976
|
+
} else {
|
|
18977
|
+
openaiCompatTools.push({
|
|
18978
|
+
type: "function",
|
|
18979
|
+
function: {
|
|
18980
|
+
name: tool6.name,
|
|
18981
|
+
description: tool6.description,
|
|
18982
|
+
parameters: tool6.inputSchema,
|
|
18983
|
+
...tool6.strict != null ? { strict: tool6.strict } : {}
|
|
18984
|
+
}
|
|
18985
|
+
});
|
|
18986
|
+
}
|
|
18987
|
+
}
|
|
18988
|
+
if (toolChoice == null) {
|
|
18989
|
+
return { tools: openaiCompatTools, toolChoice: void 0, toolWarnings };
|
|
18990
|
+
}
|
|
18991
|
+
const type = toolChoice.type;
|
|
18992
|
+
switch (type) {
|
|
18993
|
+
case "auto":
|
|
18994
|
+
case "none":
|
|
18995
|
+
case "required":
|
|
18996
|
+
return { tools: openaiCompatTools, toolChoice: type, toolWarnings };
|
|
18997
|
+
case "tool":
|
|
18998
|
+
return {
|
|
18999
|
+
tools: openaiCompatTools,
|
|
19000
|
+
toolChoice: {
|
|
19001
|
+
type: "function",
|
|
19002
|
+
function: { name: toolChoice.toolName }
|
|
19003
|
+
},
|
|
19004
|
+
toolWarnings
|
|
19005
|
+
};
|
|
19006
|
+
default: {
|
|
19007
|
+
const _exhaustiveCheck = type;
|
|
19008
|
+
throw new UnsupportedFunctionalityError({
|
|
19009
|
+
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
19010
|
+
});
|
|
19011
|
+
}
|
|
19012
|
+
}
|
|
19013
|
+
}
|
|
19014
|
+
function convertOpenAICompatibleContent(content) {
|
|
19015
|
+
if (content == null) {
|
|
19016
|
+
return [];
|
|
19017
|
+
}
|
|
19018
|
+
if (typeof content === "string") {
|
|
19019
|
+
return content.length > 0 ? [{ type: "text", text: content }] : [];
|
|
19020
|
+
}
|
|
19021
|
+
const result = [];
|
|
19022
|
+
for (const part of content) {
|
|
19023
|
+
if (part.type === "text" && typeof part.text === "string") {
|
|
19024
|
+
if (part.text.length > 0) {
|
|
19025
|
+
result.push({ type: "text", text: part.text });
|
|
19026
|
+
}
|
|
19027
|
+
} else if (part.type === "thinking" && Array.isArray(part.thinking)) {
|
|
19028
|
+
const reasoningText = part.thinking.filter(
|
|
19029
|
+
(chunk) => chunk != null && typeof chunk === "object" && "type" in chunk && chunk.type === "text" && "text" in chunk && typeof chunk.text === "string"
|
|
19030
|
+
).map((chunk) => chunk.text).join("");
|
|
19031
|
+
if (reasoningText.length > 0) {
|
|
19032
|
+
result.push({ type: "reasoning", text: reasoningText });
|
|
19033
|
+
}
|
|
19034
|
+
}
|
|
19035
|
+
}
|
|
19036
|
+
return result;
|
|
19037
|
+
}
|
|
19038
|
+
function convertOpenAICompatibleCompletionUsage(usage) {
|
|
19039
|
+
var _a17, _b16;
|
|
19040
|
+
if (usage == null) {
|
|
19041
|
+
return {
|
|
19042
|
+
inputTokens: {
|
|
19043
|
+
total: void 0,
|
|
19044
|
+
noCache: void 0,
|
|
19045
|
+
cacheRead: void 0,
|
|
19046
|
+
cacheWrite: void 0
|
|
19047
|
+
},
|
|
19048
|
+
outputTokens: {
|
|
19049
|
+
total: void 0,
|
|
19050
|
+
text: void 0,
|
|
19051
|
+
reasoning: void 0
|
|
19052
|
+
},
|
|
19053
|
+
raw: void 0
|
|
19054
|
+
};
|
|
19055
|
+
}
|
|
19056
|
+
const promptTokens = (_a17 = usage.prompt_tokens) != null ? _a17 : 0;
|
|
19057
|
+
const completionTokens = (_b16 = usage.completion_tokens) != null ? _b16 : 0;
|
|
19058
|
+
return {
|
|
19059
|
+
inputTokens: {
|
|
19060
|
+
total: promptTokens,
|
|
19061
|
+
noCache: promptTokens,
|
|
19062
|
+
cacheRead: void 0,
|
|
19063
|
+
cacheWrite: void 0
|
|
19064
|
+
},
|
|
19065
|
+
outputTokens: {
|
|
19066
|
+
total: completionTokens,
|
|
19067
|
+
text: completionTokens,
|
|
19068
|
+
reasoning: void 0
|
|
19069
|
+
},
|
|
19070
|
+
raw: usage
|
|
19071
|
+
};
|
|
19072
|
+
}
|
|
19073
|
+
function convertToOpenAICompatibleCompletionPrompt({
|
|
19074
|
+
prompt,
|
|
19075
|
+
user = "user",
|
|
19076
|
+
assistant = "assistant"
|
|
19077
|
+
}) {
|
|
19078
|
+
let text = "";
|
|
19079
|
+
if (prompt[0].role === "system") {
|
|
19080
|
+
text += `${prompt[0].content}
|
|
19081
|
+
|
|
19082
|
+
`;
|
|
19083
|
+
prompt = prompt.slice(1);
|
|
19084
|
+
}
|
|
19085
|
+
for (const { role, content } of prompt) {
|
|
19086
|
+
switch (role) {
|
|
19087
|
+
case "system": {
|
|
19088
|
+
throw new InvalidPromptError({
|
|
19089
|
+
message: "Unexpected system message in prompt: ${content}",
|
|
19090
|
+
prompt
|
|
19091
|
+
});
|
|
19092
|
+
}
|
|
19093
|
+
case "user": {
|
|
19094
|
+
const userMessage = content.map((part) => {
|
|
19095
|
+
switch (part.type) {
|
|
19096
|
+
case "text": {
|
|
19097
|
+
return part.text;
|
|
19098
|
+
}
|
|
19099
|
+
}
|
|
19100
|
+
}).filter(Boolean).join("");
|
|
19101
|
+
text += `${user}:
|
|
19102
|
+
${userMessage}
|
|
19103
|
+
|
|
19104
|
+
`;
|
|
19105
|
+
break;
|
|
19106
|
+
}
|
|
19107
|
+
case "assistant": {
|
|
19108
|
+
const assistantMessage = content.map((part) => {
|
|
19109
|
+
switch (part.type) {
|
|
19110
|
+
case "text": {
|
|
19111
|
+
return part.text;
|
|
19112
|
+
}
|
|
19113
|
+
case "tool-call": {
|
|
19114
|
+
throw new UnsupportedFunctionalityError({
|
|
19115
|
+
functionality: "tool-call messages"
|
|
19116
|
+
});
|
|
19117
|
+
}
|
|
19118
|
+
}
|
|
19119
|
+
}).join("");
|
|
19120
|
+
text += `${assistant}:
|
|
19121
|
+
${assistantMessage}
|
|
19122
|
+
|
|
19123
|
+
`;
|
|
19124
|
+
break;
|
|
19125
|
+
}
|
|
19126
|
+
case "tool": {
|
|
19127
|
+
throw new UnsupportedFunctionalityError({
|
|
19128
|
+
functionality: "tool messages"
|
|
19129
|
+
});
|
|
19130
|
+
}
|
|
19131
|
+
default: {
|
|
19132
|
+
const _exhaustiveCheck = role;
|
|
19133
|
+
throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
|
|
19134
|
+
}
|
|
19135
|
+
}
|
|
19136
|
+
}
|
|
19137
|
+
text += `${assistant}:
|
|
19138
|
+
`;
|
|
19139
|
+
return {
|
|
19140
|
+
prompt: text,
|
|
19141
|
+
stopSequences: [`
|
|
19142
|
+
${user}:`]
|
|
19143
|
+
};
|
|
19144
|
+
}
|
|
19145
|
+
function getResponseMetadata2({
|
|
19146
|
+
id,
|
|
19147
|
+
model,
|
|
19148
|
+
created
|
|
19149
|
+
}) {
|
|
19150
|
+
return {
|
|
19151
|
+
id: id != null ? id : void 0,
|
|
19152
|
+
modelId: model != null ? model : void 0,
|
|
19153
|
+
timestamp: created != null ? new Date(created * 1e3) : void 0
|
|
19154
|
+
};
|
|
19155
|
+
}
|
|
19156
|
+
function mapOpenAICompatibleFinishReason2(finishReason) {
|
|
19157
|
+
switch (finishReason) {
|
|
19158
|
+
case "stop":
|
|
19159
|
+
return "stop";
|
|
19160
|
+
case "length":
|
|
19161
|
+
return "length";
|
|
19162
|
+
case "content_filter":
|
|
19163
|
+
return "content-filter";
|
|
19164
|
+
case "function_call":
|
|
19165
|
+
case "tool_calls":
|
|
19166
|
+
return "tool-calls";
|
|
19167
|
+
default:
|
|
19168
|
+
return "other";
|
|
19169
|
+
}
|
|
19170
|
+
}
|
|
19171
|
+
async function fileToBlob(file2) {
|
|
19172
|
+
if (file2.type === "url") {
|
|
19173
|
+
return downloadBlob(file2.url);
|
|
19174
|
+
}
|
|
19175
|
+
const data2 = file2.data instanceof Uint8Array ? file2.data : convertBase64ToUint8Array(file2.data);
|
|
19176
|
+
return new Blob([data2], { type: file2.mediaType });
|
|
19177
|
+
}
|
|
19178
|
+
function createOpenAICompatible(options) {
|
|
19179
|
+
const baseURL = withoutTrailingSlash(options.baseURL);
|
|
19180
|
+
const providerName = options.name;
|
|
19181
|
+
const headers = {
|
|
19182
|
+
...options.apiKey && { Authorization: `Bearer ${options.apiKey}` },
|
|
19183
|
+
...options.headers
|
|
19184
|
+
};
|
|
19185
|
+
const getHeaders = () => withUserAgentSuffix(headers, `ai-sdk/openai-compatible/${VERSION2}`);
|
|
19186
|
+
const getCommonModelConfig = (modelType) => ({
|
|
19187
|
+
provider: `${providerName}.${modelType}`,
|
|
19188
|
+
url: ({ path: path9 }) => {
|
|
19189
|
+
const url2 = new URL(`${baseURL}${path9}`);
|
|
19190
|
+
if (options.queryParams) {
|
|
19191
|
+
url2.search = new URLSearchParams(options.queryParams).toString();
|
|
19192
|
+
}
|
|
19193
|
+
return url2.toString();
|
|
19194
|
+
},
|
|
19195
|
+
headers: getHeaders,
|
|
19196
|
+
fetch: options.fetch
|
|
19197
|
+
});
|
|
19198
|
+
const createLanguageModel2 = (modelId) => createChatModel(modelId);
|
|
19199
|
+
const createChatModel = (modelId) => new OpenAICompatibleChatLanguageModel(modelId, {
|
|
19200
|
+
...getCommonModelConfig("chat"),
|
|
19201
|
+
includeUsage: options.includeUsage,
|
|
19202
|
+
supportsStructuredOutputs: options.supportsStructuredOutputs,
|
|
19203
|
+
supportedUrls: options.supportedUrls,
|
|
19204
|
+
transformRequestBody: options.transformRequestBody,
|
|
19205
|
+
metadataExtractor: options.metadataExtractor,
|
|
19206
|
+
convertUsage: options.convertUsage
|
|
19207
|
+
});
|
|
19208
|
+
const createCompletionModel = (modelId) => new OpenAICompatibleCompletionLanguageModel(modelId, {
|
|
19209
|
+
...getCommonModelConfig("completion"),
|
|
19210
|
+
includeUsage: options.includeUsage
|
|
19211
|
+
});
|
|
19212
|
+
const createEmbeddingModel = (modelId) => new OpenAICompatibleEmbeddingModel(modelId, {
|
|
19213
|
+
...getCommonModelConfig("embedding")
|
|
19214
|
+
});
|
|
19215
|
+
const createImageModel = (modelId) => new OpenAICompatibleImageModel(modelId, getCommonModelConfig("image"));
|
|
19216
|
+
const provider = (modelId) => createLanguageModel2(modelId);
|
|
19217
|
+
provider.specificationVersion = "v3";
|
|
19218
|
+
provider.languageModel = createLanguageModel2;
|
|
19219
|
+
provider.chatModel = createChatModel;
|
|
19220
|
+
provider.completionModel = createCompletionModel;
|
|
19221
|
+
provider.embeddingModel = createEmbeddingModel;
|
|
19222
|
+
provider.textEmbeddingModel = createEmbeddingModel;
|
|
19223
|
+
provider.imageModel = createImageModel;
|
|
19224
|
+
return provider;
|
|
19225
|
+
}
|
|
19226
|
+
var openaiCompatibleErrorDataSchema, defaultOpenAICompatibleErrorStructure, openaiCompatibleLanguageModelChatOptions, OpenAICompatibleChatLanguageModel, openaiCompatibleTokenUsageSchema, openAICompatibleContentSchema, OpenAICompatibleChatResponseSchema, chunkBaseSchema, createOpenAICompatibleChatChunkSchema, openaiCompatibleLanguageModelCompletionOptions, OpenAICompatibleCompletionLanguageModel, usageSchema, openaiCompatibleCompletionResponseSchema, createOpenAICompatibleCompletionChunkSchema, openaiCompatibleEmbeddingModelOptions, OpenAICompatibleEmbeddingModel, openaiTextEmbeddingResponseSchema, OpenAICompatibleImageModel, openaiCompatibleImageResponseSchema, VERSION2;
|
|
19227
|
+
var init_dist4 = __esm({
|
|
19228
|
+
"node_modules/@ai-sdk/openai-compatible/dist/index.mjs"() {
|
|
19229
|
+
init_dist();
|
|
19230
|
+
init_dist3();
|
|
19231
|
+
init_v4();
|
|
19232
|
+
init_v4();
|
|
19233
|
+
init_dist();
|
|
19234
|
+
init_dist3();
|
|
19235
|
+
init_v4();
|
|
19236
|
+
init_dist();
|
|
19237
|
+
init_dist3();
|
|
19238
|
+
init_v4();
|
|
19239
|
+
init_dist();
|
|
19240
|
+
init_v4();
|
|
19241
|
+
init_dist();
|
|
19242
|
+
init_dist3();
|
|
19243
|
+
init_v4();
|
|
19244
|
+
init_v4();
|
|
19245
|
+
init_dist3();
|
|
19246
|
+
init_v4();
|
|
19247
|
+
init_dist3();
|
|
19248
|
+
openaiCompatibleErrorDataSchema = external_exports.object({
|
|
19249
|
+
error: external_exports.object({
|
|
19250
|
+
message: external_exports.string(),
|
|
19251
|
+
// The additional information below is handled loosely to support
|
|
19252
|
+
// OpenAI-compatible providers that have slightly different error
|
|
19253
|
+
// responses:
|
|
19254
|
+
type: external_exports.string().nullish(),
|
|
19255
|
+
param: external_exports.any().nullish(),
|
|
19256
|
+
code: external_exports.union([external_exports.string(), external_exports.number()]).nullish()
|
|
19257
|
+
})
|
|
19258
|
+
});
|
|
19259
|
+
defaultOpenAICompatibleErrorStructure = {
|
|
19260
|
+
errorSchema: openaiCompatibleErrorDataSchema,
|
|
19261
|
+
errorToMessage: (data2) => data2.error.message
|
|
19262
|
+
};
|
|
19263
|
+
openaiCompatibleLanguageModelChatOptions = external_exports.object({
|
|
19264
|
+
/**
|
|
19265
|
+
* A unique identifier representing your end-user, which can help the provider to
|
|
19266
|
+
* monitor and detect abuse.
|
|
19267
|
+
*/
|
|
19268
|
+
user: external_exports.string().optional(),
|
|
19269
|
+
/**
|
|
19270
|
+
* Reasoning effort for reasoning models. Defaults to `medium`.
|
|
19271
|
+
*/
|
|
19272
|
+
reasoningEffort: external_exports.string().optional(),
|
|
19273
|
+
/**
|
|
19274
|
+
* Controls the verbosity of the generated text. Defaults to `medium`.
|
|
19275
|
+
*/
|
|
19276
|
+
textVerbosity: external_exports.string().optional(),
|
|
19277
|
+
/**
|
|
19278
|
+
* Whether to use strict JSON schema validation.
|
|
19279
|
+
* When true, the model uses constrained decoding to guarantee schema compliance.
|
|
19280
|
+
* Only used when the provider supports structured outputs and a schema is provided.
|
|
19281
|
+
*
|
|
19282
|
+
* @default true
|
|
19283
|
+
*/
|
|
19284
|
+
strictJsonSchema: external_exports.boolean().optional()
|
|
19285
|
+
});
|
|
19286
|
+
OpenAICompatibleChatLanguageModel = class {
|
|
19287
|
+
// type inferred via constructor
|
|
19288
|
+
constructor(modelId, config2) {
|
|
19289
|
+
this.specificationVersion = "v3";
|
|
19290
|
+
var _a17, _b16;
|
|
19291
|
+
this.modelId = modelId;
|
|
19292
|
+
this.config = config2;
|
|
19293
|
+
const errorStructure = (_a17 = config2.errorStructure) != null ? _a17 : defaultOpenAICompatibleErrorStructure;
|
|
19294
|
+
this.chunkSchema = createOpenAICompatibleChatChunkSchema(
|
|
19295
|
+
errorStructure.errorSchema
|
|
19296
|
+
);
|
|
19297
|
+
this.failedResponseHandler = createJsonErrorResponseHandler(errorStructure);
|
|
19298
|
+
this.supportsStructuredOutputs = (_b16 = config2.supportsStructuredOutputs) != null ? _b16 : false;
|
|
19299
|
+
}
|
|
19300
|
+
get provider() {
|
|
19301
|
+
return this.config.provider;
|
|
19302
|
+
}
|
|
19303
|
+
get providerOptionsName() {
|
|
19304
|
+
return this.config.provider.split(".")[0].trim();
|
|
19305
|
+
}
|
|
19306
|
+
get supportedUrls() {
|
|
19307
|
+
var _a17, _b16, _c;
|
|
19308
|
+
return (_c = (_b16 = (_a17 = this.config).supportedUrls) == null ? void 0 : _b16.call(_a17)) != null ? _c : {};
|
|
19309
|
+
}
|
|
19310
|
+
transformRequestBody(args) {
|
|
19311
|
+
var _a17, _b16, _c;
|
|
19312
|
+
return (_c = (_b16 = (_a17 = this.config).transformRequestBody) == null ? void 0 : _b16.call(_a17, args)) != null ? _c : args;
|
|
19313
|
+
}
|
|
19314
|
+
convertUsage(usage) {
|
|
19315
|
+
var _a17, _b16, _c;
|
|
19316
|
+
return (_c = (_b16 = (_a17 = this.config).convertUsage) == null ? void 0 : _b16.call(_a17, usage)) != null ? _c : convertOpenAICompatibleChatUsage(usage);
|
|
19317
|
+
}
|
|
19318
|
+
async getArgs({
|
|
19319
|
+
prompt,
|
|
19320
|
+
maxOutputTokens,
|
|
19321
|
+
temperature,
|
|
19322
|
+
topP,
|
|
19323
|
+
topK,
|
|
19324
|
+
frequencyPenalty,
|
|
19325
|
+
presencePenalty,
|
|
19326
|
+
providerOptions,
|
|
19327
|
+
stopSequences,
|
|
19328
|
+
responseFormat,
|
|
19329
|
+
seed,
|
|
19330
|
+
toolChoice,
|
|
19331
|
+
tools
|
|
19332
|
+
}) {
|
|
19333
|
+
var _a17, _b16, _c, _d, _e;
|
|
19334
|
+
const warnings = [];
|
|
19335
|
+
const deprecatedOptions = await parseProviderOptions({
|
|
19336
|
+
provider: "openai-compatible",
|
|
19337
|
+
providerOptions,
|
|
19338
|
+
schema: openaiCompatibleLanguageModelChatOptions
|
|
19339
|
+
});
|
|
19340
|
+
if (deprecatedOptions != null) {
|
|
19341
|
+
warnings.push({
|
|
19342
|
+
type: "other",
|
|
19343
|
+
message: `The 'openai-compatible' key in providerOptions is deprecated. Use 'openaiCompatible' instead.`
|
|
19344
|
+
});
|
|
19345
|
+
}
|
|
19346
|
+
const compatibleOptions = Object.assign(
|
|
19347
|
+
deprecatedOptions != null ? deprecatedOptions : {},
|
|
19348
|
+
(_a17 = await parseProviderOptions({
|
|
19349
|
+
provider: "openaiCompatible",
|
|
19350
|
+
providerOptions,
|
|
19351
|
+
schema: openaiCompatibleLanguageModelChatOptions
|
|
19352
|
+
})) != null ? _a17 : {},
|
|
19353
|
+
(_b16 = await parseProviderOptions({
|
|
19354
|
+
provider: this.providerOptionsName,
|
|
19355
|
+
providerOptions,
|
|
19356
|
+
schema: openaiCompatibleLanguageModelChatOptions
|
|
19357
|
+
})) != null ? _b16 : {},
|
|
19358
|
+
(_c = await parseProviderOptions({
|
|
19359
|
+
provider: toCamelCase(this.providerOptionsName),
|
|
19360
|
+
providerOptions,
|
|
19361
|
+
schema: openaiCompatibleLanguageModelChatOptions
|
|
19362
|
+
})) != null ? _c : {}
|
|
19363
|
+
);
|
|
19364
|
+
const strictJsonSchema = (_d = compatibleOptions == null ? void 0 : compatibleOptions.strictJsonSchema) != null ? _d : true;
|
|
19365
|
+
if (topK != null) {
|
|
19366
|
+
warnings.push({ type: "unsupported", feature: "topK" });
|
|
19367
|
+
}
|
|
19368
|
+
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !this.supportsStructuredOutputs) {
|
|
19369
|
+
warnings.push({
|
|
19370
|
+
type: "unsupported",
|
|
19371
|
+
feature: "responseFormat",
|
|
19372
|
+
details: "JSON response format schema is only supported with structuredOutputs"
|
|
19373
|
+
});
|
|
19374
|
+
}
|
|
19375
|
+
const {
|
|
19376
|
+
tools: openaiTools,
|
|
19377
|
+
toolChoice: openaiToolChoice,
|
|
19378
|
+
toolWarnings
|
|
19379
|
+
} = prepareTools({
|
|
19380
|
+
tools,
|
|
19381
|
+
toolChoice
|
|
19382
|
+
});
|
|
19383
|
+
const metadataKey = resolveProviderOptionsKey(
|
|
19384
|
+
this.providerOptionsName,
|
|
19385
|
+
providerOptions
|
|
19386
|
+
);
|
|
19387
|
+
return {
|
|
19388
|
+
metadataKey,
|
|
19389
|
+
args: {
|
|
19390
|
+
// model id:
|
|
19391
|
+
model: this.modelId,
|
|
19392
|
+
// model specific settings:
|
|
19393
|
+
user: compatibleOptions.user,
|
|
19394
|
+
// standardized settings:
|
|
19395
|
+
max_tokens: maxOutputTokens,
|
|
19396
|
+
temperature,
|
|
19397
|
+
top_p: topP,
|
|
19398
|
+
frequency_penalty: frequencyPenalty,
|
|
19399
|
+
presence_penalty: presencePenalty,
|
|
19400
|
+
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? this.supportsStructuredOutputs === true && responseFormat.schema != null ? {
|
|
19401
|
+
type: "json_schema",
|
|
19402
|
+
json_schema: {
|
|
19403
|
+
schema: responseFormat.schema,
|
|
19404
|
+
strict: strictJsonSchema,
|
|
19405
|
+
name: (_e = responseFormat.name) != null ? _e : "response",
|
|
19406
|
+
description: responseFormat.description
|
|
19407
|
+
}
|
|
19408
|
+
} : { type: "json_object" } : void 0,
|
|
19409
|
+
stop: stopSequences,
|
|
19410
|
+
seed,
|
|
19411
|
+
...Object.fromEntries(
|
|
19412
|
+
Object.entries({
|
|
19413
|
+
...providerOptions == null ? void 0 : providerOptions[this.providerOptionsName],
|
|
19414
|
+
...providerOptions == null ? void 0 : providerOptions[toCamelCase(this.providerOptionsName)]
|
|
19415
|
+
}).filter(
|
|
19416
|
+
([key]) => !Object.keys(
|
|
19417
|
+
openaiCompatibleLanguageModelChatOptions.shape
|
|
19418
|
+
).includes(key)
|
|
19419
|
+
)
|
|
19420
|
+
),
|
|
19421
|
+
reasoning_effort: compatibleOptions.reasoningEffort,
|
|
19422
|
+
verbosity: compatibleOptions.textVerbosity,
|
|
19423
|
+
// messages:
|
|
19424
|
+
messages: convertToOpenAICompatibleChatMessages(prompt),
|
|
19425
|
+
// tools:
|
|
19426
|
+
tools: openaiTools,
|
|
19427
|
+
tool_choice: openaiToolChoice
|
|
19428
|
+
},
|
|
19429
|
+
warnings: [...warnings, ...toolWarnings]
|
|
19430
|
+
};
|
|
19431
|
+
}
|
|
19432
|
+
async doGenerate(options) {
|
|
19433
|
+
var _a17, _b16, _c, _d, _e, _f, _g, _h;
|
|
19434
|
+
const { args, warnings, metadataKey } = await this.getArgs({ ...options });
|
|
19435
|
+
const transformedBody = this.transformRequestBody(args);
|
|
19436
|
+
const body = JSON.stringify(transformedBody);
|
|
19437
|
+
const {
|
|
19438
|
+
responseHeaders,
|
|
19439
|
+
value: responseBody,
|
|
19440
|
+
rawValue: rawResponse
|
|
19441
|
+
} = await postJsonToApi({
|
|
19442
|
+
url: this.config.url({
|
|
19443
|
+
path: "/chat/completions",
|
|
19444
|
+
modelId: this.modelId
|
|
19445
|
+
}),
|
|
19446
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
19447
|
+
body: transformedBody,
|
|
19448
|
+
failedResponseHandler: this.failedResponseHandler,
|
|
19449
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
19450
|
+
OpenAICompatibleChatResponseSchema
|
|
19451
|
+
),
|
|
19452
|
+
abortSignal: options.abortSignal,
|
|
19453
|
+
fetch: this.config.fetch
|
|
19454
|
+
});
|
|
19455
|
+
const choice = responseBody.choices[0];
|
|
19456
|
+
const content = [];
|
|
19457
|
+
content.push(...convertOpenAICompatibleContent(choice.message.content));
|
|
19458
|
+
const reasoning = (_a17 = choice.message.reasoning_content) != null ? _a17 : choice.message.reasoning;
|
|
19459
|
+
if (reasoning != null && reasoning.length > 0) {
|
|
19460
|
+
content.push({
|
|
19461
|
+
type: "reasoning",
|
|
19462
|
+
text: reasoning
|
|
19463
|
+
});
|
|
19464
|
+
}
|
|
19465
|
+
if (choice.message.tool_calls != null) {
|
|
19466
|
+
for (const toolCall of choice.message.tool_calls) {
|
|
19467
|
+
const thoughtSignature = (_c = (_b16 = toolCall.extra_content) == null ? void 0 : _b16.google) == null ? void 0 : _c.thought_signature;
|
|
19468
|
+
content.push({
|
|
19469
|
+
type: "tool-call",
|
|
19470
|
+
toolCallId: (_d = toolCall.id) != null ? _d : generateId(),
|
|
19471
|
+
toolName: toolCall.function.name,
|
|
19472
|
+
input: toolCall.function.arguments,
|
|
19473
|
+
...thoughtSignature ? {
|
|
19474
|
+
providerMetadata: {
|
|
19475
|
+
[metadataKey]: { thoughtSignature }
|
|
19476
|
+
}
|
|
19477
|
+
} : {}
|
|
19478
|
+
});
|
|
19479
|
+
}
|
|
19480
|
+
}
|
|
19481
|
+
const providerMetadata = {
|
|
19482
|
+
[metadataKey]: {},
|
|
19483
|
+
...await ((_f = (_e = this.config.metadataExtractor) == null ? void 0 : _e.extractMetadata) == null ? void 0 : _f.call(_e, {
|
|
19484
|
+
parsedBody: rawResponse
|
|
19485
|
+
}))
|
|
19486
|
+
};
|
|
19487
|
+
const completionTokenDetails = (_g = responseBody.usage) == null ? void 0 : _g.completion_tokens_details;
|
|
19488
|
+
if ((completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens) != null) {
|
|
19489
|
+
providerMetadata[metadataKey].acceptedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens;
|
|
19490
|
+
}
|
|
19491
|
+
if ((completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens) != null) {
|
|
19492
|
+
providerMetadata[metadataKey].rejectedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens;
|
|
19493
|
+
}
|
|
19494
|
+
return {
|
|
19495
|
+
content,
|
|
19496
|
+
finishReason: {
|
|
19497
|
+
unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
|
|
19498
|
+
raw: (_h = choice.finish_reason) != null ? _h : void 0
|
|
19499
|
+
},
|
|
19500
|
+
usage: this.convertUsage(responseBody.usage),
|
|
19501
|
+
providerMetadata,
|
|
19502
|
+
request: { body },
|
|
19503
|
+
response: {
|
|
19504
|
+
...getResponseMetadata(responseBody),
|
|
19505
|
+
headers: responseHeaders,
|
|
19506
|
+
body: rawResponse
|
|
19507
|
+
},
|
|
19508
|
+
warnings
|
|
19509
|
+
};
|
|
19510
|
+
}
|
|
19511
|
+
async doStream(options) {
|
|
19512
|
+
var _a17;
|
|
19513
|
+
const { args, warnings, metadataKey } = await this.getArgs({ ...options });
|
|
19514
|
+
const body = this.transformRequestBody({
|
|
19515
|
+
...args,
|
|
19516
|
+
stream: true,
|
|
19517
|
+
// only include stream_options when in strict compatibility mode:
|
|
19518
|
+
stream_options: this.config.includeUsage ? { include_usage: true } : void 0
|
|
19519
|
+
});
|
|
19520
|
+
const metadataExtractor = (_a17 = this.config.metadataExtractor) == null ? void 0 : _a17.createStreamExtractor();
|
|
19521
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
19522
|
+
url: this.config.url({
|
|
19523
|
+
path: "/chat/completions",
|
|
19524
|
+
modelId: this.modelId
|
|
19525
|
+
}),
|
|
19526
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
19527
|
+
body,
|
|
19528
|
+
failedResponseHandler: this.failedResponseHandler,
|
|
19529
|
+
successfulResponseHandler: createEventSourceResponseHandler(
|
|
19530
|
+
this.chunkSchema
|
|
19531
|
+
),
|
|
19532
|
+
abortSignal: options.abortSignal,
|
|
19533
|
+
fetch: this.config.fetch
|
|
19534
|
+
});
|
|
19535
|
+
const toolCalls = [];
|
|
19536
|
+
const pendingToolCalls = /* @__PURE__ */ new Map();
|
|
19537
|
+
let finishReason;
|
|
19538
|
+
let usage = void 0;
|
|
19539
|
+
let isFirstChunk = true;
|
|
19540
|
+
const providerOptionsName = metadataKey;
|
|
19541
|
+
let isActiveReasoning = false;
|
|
19542
|
+
let isActiveText = false;
|
|
19543
|
+
const convertUsage = (usage2) => this.convertUsage(usage2);
|
|
19544
|
+
return {
|
|
19545
|
+
stream: response.pipeThrough(
|
|
19546
|
+
new TransformStream({
|
|
19547
|
+
start(controller) {
|
|
19548
|
+
controller.enqueue({ type: "stream-start", warnings });
|
|
19549
|
+
},
|
|
19550
|
+
transform(chunk, controller) {
|
|
19551
|
+
var _a22, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
19552
|
+
if (options.includeRawChunks) {
|
|
19553
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
19554
|
+
}
|
|
19555
|
+
if (!chunk.success) {
|
|
19556
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
19557
|
+
controller.enqueue({ type: "error", error: chunk.error });
|
|
19558
|
+
return;
|
|
19559
|
+
}
|
|
19560
|
+
metadataExtractor == null ? void 0 : metadataExtractor.processChunk(chunk.rawValue);
|
|
19561
|
+
if ("error" in chunk.value) {
|
|
19562
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
19563
|
+
controller.enqueue({
|
|
19564
|
+
type: "error",
|
|
19565
|
+
error: chunk.value.error
|
|
19566
|
+
});
|
|
19567
|
+
return;
|
|
19568
|
+
}
|
|
19569
|
+
const value = chunk.value;
|
|
19570
|
+
if (isFirstChunk) {
|
|
19571
|
+
isFirstChunk = false;
|
|
19572
|
+
controller.enqueue({
|
|
19573
|
+
type: "response-metadata",
|
|
19574
|
+
...getResponseMetadata(value)
|
|
19575
|
+
});
|
|
19576
|
+
}
|
|
19577
|
+
if (value.usage != null) {
|
|
19578
|
+
usage = value.usage;
|
|
19579
|
+
}
|
|
19580
|
+
const choice = value.choices[0];
|
|
19581
|
+
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
19582
|
+
finishReason = {
|
|
19583
|
+
unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
|
|
19584
|
+
raw: (_a22 = choice.finish_reason) != null ? _a22 : void 0
|
|
19585
|
+
};
|
|
19586
|
+
}
|
|
19587
|
+
if ((choice == null ? void 0 : choice.delta) == null) {
|
|
19588
|
+
return;
|
|
19589
|
+
}
|
|
19590
|
+
const delta = choice.delta;
|
|
19591
|
+
const enqueueReasoningDelta = (reasoningDelta) => {
|
|
19592
|
+
if (isActiveText) {
|
|
19593
|
+
controller.enqueue({ type: "text-end", id: "txt-0" });
|
|
19594
|
+
isActiveText = false;
|
|
19595
|
+
}
|
|
19596
|
+
if (!isActiveReasoning) {
|
|
19597
|
+
controller.enqueue({
|
|
19598
|
+
type: "reasoning-start",
|
|
19599
|
+
id: "reasoning-0"
|
|
19600
|
+
});
|
|
19601
|
+
isActiveReasoning = true;
|
|
19602
|
+
}
|
|
19603
|
+
controller.enqueue({
|
|
19604
|
+
type: "reasoning-delta",
|
|
19605
|
+
id: "reasoning-0",
|
|
19606
|
+
delta: reasoningDelta
|
|
19607
|
+
});
|
|
19608
|
+
};
|
|
19609
|
+
const enqueueTextDelta = (textDelta) => {
|
|
19610
|
+
if (isActiveReasoning) {
|
|
19611
|
+
controller.enqueue({
|
|
19612
|
+
type: "reasoning-end",
|
|
19613
|
+
id: "reasoning-0"
|
|
19614
|
+
});
|
|
19615
|
+
isActiveReasoning = false;
|
|
19616
|
+
}
|
|
19617
|
+
if (!isActiveText) {
|
|
19618
|
+
controller.enqueue({ type: "text-start", id: "txt-0" });
|
|
19619
|
+
isActiveText = true;
|
|
19620
|
+
}
|
|
19621
|
+
controller.enqueue({
|
|
19622
|
+
type: "text-delta",
|
|
19623
|
+
id: "txt-0",
|
|
19624
|
+
delta: textDelta
|
|
19625
|
+
});
|
|
19626
|
+
};
|
|
19627
|
+
const reasoningContent = (_b16 = delta.reasoning_content) != null ? _b16 : delta.reasoning;
|
|
19628
|
+
if (reasoningContent) {
|
|
19629
|
+
enqueueReasoningDelta(reasoningContent);
|
|
19630
|
+
}
|
|
19631
|
+
for (const contentPart of convertOpenAICompatibleContent(
|
|
19632
|
+
delta.content
|
|
19633
|
+
)) {
|
|
19634
|
+
if (contentPart.type === "reasoning") {
|
|
19635
|
+
enqueueReasoningDelta(contentPart.text);
|
|
19636
|
+
} else {
|
|
19637
|
+
enqueueTextDelta(contentPart.text);
|
|
19638
|
+
}
|
|
19639
|
+
}
|
|
19640
|
+
if (delta.tool_calls != null) {
|
|
19641
|
+
if (isActiveReasoning) {
|
|
19642
|
+
controller.enqueue({
|
|
19643
|
+
type: "reasoning-end",
|
|
19644
|
+
id: "reasoning-0"
|
|
19645
|
+
});
|
|
19646
|
+
isActiveReasoning = false;
|
|
19647
|
+
}
|
|
19648
|
+
for (const toolCallDelta of delta.tool_calls) {
|
|
19649
|
+
const index = (_c = toolCallDelta.index) != null ? _c : toolCalls.length;
|
|
19650
|
+
if (toolCalls[index] == null) {
|
|
19651
|
+
if (toolCallDelta.index != null) {
|
|
19652
|
+
let pending = pendingToolCalls.get(index);
|
|
19653
|
+
if (pending == null) {
|
|
19654
|
+
pending = {
|
|
19655
|
+
id: (_d = toolCallDelta.id) != null ? _d : null,
|
|
19656
|
+
bufferedArguments: "",
|
|
19657
|
+
thoughtSignature: (_g = (_f = (_e = toolCallDelta.extra_content) == null ? void 0 : _e.google) == null ? void 0 : _f.thought_signature) != null ? _g : void 0
|
|
19658
|
+
};
|
|
19659
|
+
pendingToolCalls.set(index, pending);
|
|
19660
|
+
} else {
|
|
19661
|
+
if (pending.id == null && toolCallDelta.id != null) {
|
|
19662
|
+
pending.id = toolCallDelta.id;
|
|
19663
|
+
}
|
|
19664
|
+
if (pending.thoughtSignature == null && ((_i = (_h = toolCallDelta.extra_content) == null ? void 0 : _h.google) == null ? void 0 : _i.thought_signature) != null) {
|
|
19665
|
+
pending.thoughtSignature = toolCallDelta.extra_content.google.thought_signature;
|
|
19666
|
+
}
|
|
19667
|
+
}
|
|
19668
|
+
const argumentsDelta = (_j = toolCallDelta.function) == null ? void 0 : _j.arguments;
|
|
19669
|
+
if (argumentsDelta != null) {
|
|
19670
|
+
pending.bufferedArguments += argumentsDelta;
|
|
19671
|
+
}
|
|
19672
|
+
const name15 = (_k = toolCallDelta.function) == null ? void 0 : _k.name;
|
|
19673
|
+
if (name15 == null) {
|
|
19674
|
+
continue;
|
|
19675
|
+
}
|
|
19676
|
+
pendingToolCalls.delete(index);
|
|
19677
|
+
if (pending.id == null) {
|
|
19678
|
+
throw new InvalidResponseDataError({
|
|
19679
|
+
data: toolCallDelta,
|
|
19680
|
+
message: `Expected 'id' to be a string.`
|
|
19681
|
+
});
|
|
19682
|
+
}
|
|
19683
|
+
controller.enqueue({
|
|
19684
|
+
type: "tool-input-start",
|
|
19685
|
+
id: pending.id,
|
|
19686
|
+
toolName: name15
|
|
19687
|
+
});
|
|
19688
|
+
toolCalls[index] = {
|
|
19689
|
+
id: pending.id,
|
|
19690
|
+
type: "function",
|
|
19691
|
+
function: {
|
|
19692
|
+
name: name15,
|
|
19693
|
+
arguments: pending.bufferedArguments
|
|
19694
|
+
},
|
|
19695
|
+
hasFinished: false,
|
|
19696
|
+
thoughtSignature: pending.thoughtSignature
|
|
19697
|
+
};
|
|
19698
|
+
} else {
|
|
19699
|
+
if (toolCallDelta.id == null) {
|
|
19700
|
+
throw new InvalidResponseDataError({
|
|
19701
|
+
data: toolCallDelta,
|
|
19702
|
+
message: `Expected 'id' to be a string.`
|
|
19703
|
+
});
|
|
19704
|
+
}
|
|
19705
|
+
if (((_l = toolCallDelta.function) == null ? void 0 : _l.name) == null) {
|
|
19706
|
+
throw new InvalidResponseDataError({
|
|
19707
|
+
data: toolCallDelta,
|
|
19708
|
+
message: `Expected 'function.name' to be a string.`
|
|
19709
|
+
});
|
|
19710
|
+
}
|
|
19711
|
+
controller.enqueue({
|
|
19712
|
+
type: "tool-input-start",
|
|
19713
|
+
id: toolCallDelta.id,
|
|
19714
|
+
toolName: toolCallDelta.function.name
|
|
19715
|
+
});
|
|
19716
|
+
toolCalls[index] = {
|
|
19717
|
+
id: toolCallDelta.id,
|
|
19718
|
+
type: "function",
|
|
19719
|
+
function: {
|
|
19720
|
+
name: toolCallDelta.function.name,
|
|
19721
|
+
arguments: (_m = toolCallDelta.function.arguments) != null ? _m : ""
|
|
19722
|
+
},
|
|
19723
|
+
hasFinished: false,
|
|
19724
|
+
thoughtSignature: (_p = (_o = (_n = toolCallDelta.extra_content) == null ? void 0 : _n.google) == null ? void 0 : _o.thought_signature) != null ? _p : void 0
|
|
19725
|
+
};
|
|
19726
|
+
}
|
|
19727
|
+
const toolCall2 = toolCalls[index];
|
|
19728
|
+
if (((_q = toolCall2.function) == null ? void 0 : _q.name) != null && ((_r = toolCall2.function) == null ? void 0 : _r.arguments) != null) {
|
|
19729
|
+
if (toolCall2.function.arguments.length > 0) {
|
|
19730
|
+
controller.enqueue({
|
|
19731
|
+
type: "tool-input-delta",
|
|
19732
|
+
id: toolCall2.id,
|
|
19733
|
+
delta: toolCall2.function.arguments
|
|
19734
|
+
});
|
|
19735
|
+
}
|
|
19736
|
+
}
|
|
19737
|
+
continue;
|
|
19738
|
+
}
|
|
19739
|
+
const toolCall = toolCalls[index];
|
|
19740
|
+
if (toolCall.hasFinished) {
|
|
19741
|
+
continue;
|
|
19742
|
+
}
|
|
19743
|
+
if (((_s = toolCallDelta.function) == null ? void 0 : _s.arguments) != null) {
|
|
19744
|
+
toolCall.function.arguments += (_u = (_t = toolCallDelta.function) == null ? void 0 : _t.arguments) != null ? _u : "";
|
|
19745
|
+
}
|
|
19746
|
+
controller.enqueue({
|
|
19747
|
+
type: "tool-input-delta",
|
|
19748
|
+
id: toolCall.id,
|
|
19749
|
+
delta: (_v = toolCallDelta.function.arguments) != null ? _v : ""
|
|
19750
|
+
});
|
|
19751
|
+
}
|
|
19752
|
+
}
|
|
19753
|
+
},
|
|
19754
|
+
flush(controller) {
|
|
19755
|
+
var _a22, _b16, _c, _d, _e;
|
|
19756
|
+
if (isActiveReasoning) {
|
|
19757
|
+
controller.enqueue({ type: "reasoning-end", id: "reasoning-0" });
|
|
19758
|
+
}
|
|
19759
|
+
if (isActiveText) {
|
|
19760
|
+
controller.enqueue({ type: "text-end", id: "txt-0" });
|
|
19761
|
+
}
|
|
19762
|
+
for (const [index, pending] of pendingToolCalls) {
|
|
19763
|
+
throw new InvalidResponseDataError({
|
|
19764
|
+
data: {
|
|
19765
|
+
index,
|
|
19766
|
+
id: pending.id,
|
|
19767
|
+
function: { arguments: pending.bufferedArguments }
|
|
19768
|
+
},
|
|
19769
|
+
message: `Expected 'function.name' to be a string.`
|
|
19770
|
+
});
|
|
19771
|
+
}
|
|
19772
|
+
for (const toolCall of toolCalls.filter(
|
|
19773
|
+
(toolCall2) => !toolCall2.hasFinished
|
|
19774
|
+
)) {
|
|
19775
|
+
controller.enqueue({
|
|
19776
|
+
type: "tool-input-end",
|
|
19777
|
+
id: toolCall.id
|
|
19778
|
+
});
|
|
19779
|
+
controller.enqueue({
|
|
19780
|
+
type: "tool-call",
|
|
19781
|
+
toolCallId: (_a22 = toolCall.id) != null ? _a22 : generateId(),
|
|
19782
|
+
toolName: toolCall.function.name,
|
|
19783
|
+
input: toolCall.function.arguments,
|
|
19784
|
+
...toolCall.thoughtSignature ? {
|
|
19785
|
+
providerMetadata: {
|
|
19786
|
+
[providerOptionsName]: {
|
|
19787
|
+
thoughtSignature: toolCall.thoughtSignature
|
|
19788
|
+
}
|
|
19789
|
+
}
|
|
19790
|
+
} : {}
|
|
19791
|
+
});
|
|
19792
|
+
}
|
|
19793
|
+
if (finishReason == null) {
|
|
19794
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
19795
|
+
controller.enqueue({
|
|
19796
|
+
type: "error",
|
|
19797
|
+
error: new InvalidResponseDataError({
|
|
19798
|
+
data: void 0,
|
|
19799
|
+
message: "Response stream ended without a finish reason."
|
|
19800
|
+
})
|
|
19801
|
+
});
|
|
19802
|
+
}
|
|
19803
|
+
const providerMetadata = {
|
|
19804
|
+
[providerOptionsName]: {},
|
|
19805
|
+
...metadataExtractor == null ? void 0 : metadataExtractor.buildMetadata()
|
|
19806
|
+
};
|
|
19807
|
+
if (((_b16 = usage == null ? void 0 : usage.completion_tokens_details) == null ? void 0 : _b16.accepted_prediction_tokens) != null) {
|
|
19808
|
+
providerMetadata[providerOptionsName].acceptedPredictionTokens = (_c = usage == null ? void 0 : usage.completion_tokens_details) == null ? void 0 : _c.accepted_prediction_tokens;
|
|
19809
|
+
}
|
|
19810
|
+
if (((_d = usage == null ? void 0 : usage.completion_tokens_details) == null ? void 0 : _d.rejected_prediction_tokens) != null) {
|
|
19811
|
+
providerMetadata[providerOptionsName].rejectedPredictionTokens = (_e = usage == null ? void 0 : usage.completion_tokens_details) == null ? void 0 : _e.rejected_prediction_tokens;
|
|
19812
|
+
}
|
|
19813
|
+
controller.enqueue({
|
|
19814
|
+
type: "finish",
|
|
19815
|
+
finishReason,
|
|
19816
|
+
usage: convertUsage(usage),
|
|
19817
|
+
providerMetadata
|
|
19818
|
+
});
|
|
19819
|
+
}
|
|
19820
|
+
})
|
|
19821
|
+
),
|
|
19822
|
+
request: { body },
|
|
19823
|
+
response: { headers: responseHeaders }
|
|
19824
|
+
};
|
|
19825
|
+
}
|
|
19826
|
+
};
|
|
19827
|
+
openaiCompatibleTokenUsageSchema = external_exports.looseObject({
|
|
19828
|
+
prompt_tokens: external_exports.number().nullish(),
|
|
19829
|
+
completion_tokens: external_exports.number().nullish(),
|
|
19830
|
+
total_tokens: external_exports.number().nullish(),
|
|
19831
|
+
prompt_tokens_details: external_exports.looseObject({
|
|
19832
|
+
cached_tokens: external_exports.number().nullish()
|
|
19833
|
+
}).nullish(),
|
|
19834
|
+
completion_tokens_details: external_exports.looseObject({
|
|
19835
|
+
reasoning_tokens: external_exports.number().nullish(),
|
|
19836
|
+
accepted_prediction_tokens: external_exports.number().nullish(),
|
|
19837
|
+
rejected_prediction_tokens: external_exports.number().nullish()
|
|
19838
|
+
}).nullish()
|
|
19839
|
+
}).nullish();
|
|
19840
|
+
openAICompatibleContentSchema = external_exports.union([
|
|
19841
|
+
external_exports.string(),
|
|
19842
|
+
external_exports.array(
|
|
19843
|
+
external_exports.looseObject({
|
|
19844
|
+
type: external_exports.string()
|
|
19845
|
+
})
|
|
19846
|
+
)
|
|
19847
|
+
]).nullish();
|
|
19848
|
+
OpenAICompatibleChatResponseSchema = external_exports.looseObject({
|
|
19849
|
+
id: external_exports.string().nullish(),
|
|
19850
|
+
created: external_exports.number().nullish(),
|
|
19851
|
+
model: external_exports.string().nullish(),
|
|
19852
|
+
choices: external_exports.array(
|
|
19853
|
+
external_exports.object({
|
|
19854
|
+
message: external_exports.object({
|
|
19855
|
+
role: external_exports.literal("assistant").nullish(),
|
|
19856
|
+
content: openAICompatibleContentSchema,
|
|
19857
|
+
reasoning_content: external_exports.string().nullish(),
|
|
19858
|
+
reasoning: external_exports.string().nullish(),
|
|
19859
|
+
tool_calls: external_exports.array(
|
|
19860
|
+
external_exports.object({
|
|
19861
|
+
id: external_exports.string().nullish(),
|
|
19862
|
+
function: external_exports.object({
|
|
19863
|
+
name: external_exports.string(),
|
|
19864
|
+
arguments: external_exports.string()
|
|
19865
|
+
}),
|
|
19866
|
+
// Support for Google Gemini thought signatures via OpenAI compatibility
|
|
19867
|
+
extra_content: external_exports.object({
|
|
19868
|
+
google: external_exports.object({
|
|
19869
|
+
thought_signature: external_exports.string().nullish()
|
|
19870
|
+
}).nullish()
|
|
19871
|
+
}).nullish()
|
|
19872
|
+
})
|
|
19873
|
+
).nullish()
|
|
19874
|
+
}),
|
|
19875
|
+
finish_reason: external_exports.string().nullish()
|
|
19876
|
+
})
|
|
19877
|
+
),
|
|
19878
|
+
usage: openaiCompatibleTokenUsageSchema
|
|
19879
|
+
});
|
|
19880
|
+
chunkBaseSchema = external_exports.looseObject({
|
|
19881
|
+
id: external_exports.string().nullish(),
|
|
19882
|
+
created: external_exports.number().nullish(),
|
|
19883
|
+
model: external_exports.string().nullish(),
|
|
19884
|
+
choices: external_exports.array(
|
|
19885
|
+
external_exports.object({
|
|
19886
|
+
delta: external_exports.object({
|
|
19887
|
+
role: external_exports.enum(["assistant", ""]).nullish(),
|
|
19888
|
+
content: openAICompatibleContentSchema,
|
|
19889
|
+
// Most openai-compatible models set `reasoning_content`, but some
|
|
19890
|
+
// providers serving `gpt-oss` set `reasoning`. See #7866
|
|
19891
|
+
reasoning_content: external_exports.string().nullish(),
|
|
19892
|
+
reasoning: external_exports.string().nullish(),
|
|
19893
|
+
tool_calls: external_exports.array(
|
|
19894
|
+
external_exports.object({
|
|
19895
|
+
index: external_exports.number().nullish(),
|
|
19896
|
+
//google does not send index
|
|
19897
|
+
id: external_exports.string().nullish(),
|
|
19898
|
+
function: external_exports.object({
|
|
19899
|
+
name: external_exports.string().nullish(),
|
|
19900
|
+
arguments: external_exports.string().nullish()
|
|
19901
|
+
}),
|
|
19902
|
+
// Support for Google Gemini thought signatures via OpenAI compatibility
|
|
19903
|
+
extra_content: external_exports.object({
|
|
19904
|
+
google: external_exports.object({
|
|
19905
|
+
thought_signature: external_exports.string().nullish()
|
|
19906
|
+
}).nullish()
|
|
19907
|
+
}).nullish()
|
|
19908
|
+
})
|
|
19909
|
+
).nullish()
|
|
19910
|
+
}).nullish(),
|
|
19911
|
+
finish_reason: external_exports.string().nullish()
|
|
19912
|
+
})
|
|
19913
|
+
),
|
|
19914
|
+
usage: openaiCompatibleTokenUsageSchema
|
|
19915
|
+
});
|
|
19916
|
+
createOpenAICompatibleChatChunkSchema = (errorSchema) => external_exports.union([chunkBaseSchema, errorSchema]);
|
|
19917
|
+
openaiCompatibleLanguageModelCompletionOptions = external_exports.object({
|
|
19918
|
+
/**
|
|
19919
|
+
* Echo back the prompt in addition to the completion.
|
|
19920
|
+
*/
|
|
19921
|
+
echo: external_exports.boolean().optional(),
|
|
19922
|
+
/**
|
|
19923
|
+
* Modify the likelihood of specified tokens appearing in the completion.
|
|
19924
|
+
*
|
|
19925
|
+
* Accepts a JSON object that maps tokens (specified by their token ID in
|
|
19926
|
+
* the GPT tokenizer) to an associated bias value from -100 to 100.
|
|
19927
|
+
*/
|
|
19928
|
+
logitBias: external_exports.record(external_exports.string(), external_exports.number()).optional(),
|
|
19929
|
+
/**
|
|
19930
|
+
* The suffix that comes after a completion of inserted text.
|
|
19931
|
+
*/
|
|
19932
|
+
suffix: external_exports.string().optional(),
|
|
19933
|
+
/**
|
|
19934
|
+
* A unique identifier representing your end-user, which can help providers to
|
|
19935
|
+
* monitor and detect abuse.
|
|
19936
|
+
*/
|
|
19937
|
+
user: external_exports.string().optional()
|
|
19938
|
+
});
|
|
19939
|
+
OpenAICompatibleCompletionLanguageModel = class {
|
|
19940
|
+
// type inferred via constructor
|
|
19941
|
+
constructor(modelId, config2) {
|
|
19942
|
+
this.specificationVersion = "v3";
|
|
19943
|
+
var _a17;
|
|
19944
|
+
this.modelId = modelId;
|
|
19945
|
+
this.config = config2;
|
|
19946
|
+
const errorStructure = (_a17 = config2.errorStructure) != null ? _a17 : defaultOpenAICompatibleErrorStructure;
|
|
19947
|
+
this.chunkSchema = createOpenAICompatibleCompletionChunkSchema(
|
|
19948
|
+
errorStructure.errorSchema
|
|
19949
|
+
);
|
|
19950
|
+
this.failedResponseHandler = createJsonErrorResponseHandler(errorStructure);
|
|
19951
|
+
}
|
|
19952
|
+
get provider() {
|
|
19953
|
+
return this.config.provider;
|
|
19954
|
+
}
|
|
19955
|
+
get providerOptionsName() {
|
|
19956
|
+
return this.config.provider.split(".")[0].trim();
|
|
19957
|
+
}
|
|
19958
|
+
get supportedUrls() {
|
|
19959
|
+
var _a17, _b16, _c;
|
|
19960
|
+
return (_c = (_b16 = (_a17 = this.config).supportedUrls) == null ? void 0 : _b16.call(_a17)) != null ? _c : {};
|
|
19961
|
+
}
|
|
19962
|
+
async getArgs({
|
|
19963
|
+
prompt,
|
|
19964
|
+
maxOutputTokens,
|
|
19965
|
+
temperature,
|
|
19966
|
+
topP,
|
|
19967
|
+
topK,
|
|
19968
|
+
frequencyPenalty,
|
|
19969
|
+
presencePenalty,
|
|
19970
|
+
stopSequences: userStopSequences,
|
|
19971
|
+
responseFormat,
|
|
19972
|
+
seed,
|
|
19973
|
+
providerOptions,
|
|
19974
|
+
tools,
|
|
19975
|
+
toolChoice
|
|
19976
|
+
}) {
|
|
19977
|
+
var _a17, _b16;
|
|
19978
|
+
const warnings = [];
|
|
19979
|
+
const completionOptions = Object.assign(
|
|
19980
|
+
(_a17 = await parseProviderOptions({
|
|
19981
|
+
provider: this.providerOptionsName,
|
|
19982
|
+
providerOptions,
|
|
19983
|
+
schema: openaiCompatibleLanguageModelCompletionOptions
|
|
19984
|
+
})) != null ? _a17 : {},
|
|
19985
|
+
(_b16 = await parseProviderOptions({
|
|
19986
|
+
provider: toCamelCase(this.providerOptionsName),
|
|
19987
|
+
providerOptions,
|
|
19988
|
+
schema: openaiCompatibleLanguageModelCompletionOptions
|
|
19989
|
+
})) != null ? _b16 : {}
|
|
19990
|
+
);
|
|
19991
|
+
if (topK != null) {
|
|
19992
|
+
warnings.push({ type: "unsupported", feature: "topK" });
|
|
19993
|
+
}
|
|
19994
|
+
if (tools == null ? void 0 : tools.length) {
|
|
19995
|
+
warnings.push({ type: "unsupported", feature: "tools" });
|
|
19996
|
+
}
|
|
19997
|
+
if (toolChoice != null) {
|
|
19998
|
+
warnings.push({ type: "unsupported", feature: "toolChoice" });
|
|
19999
|
+
}
|
|
20000
|
+
if (responseFormat != null && responseFormat.type !== "text") {
|
|
20001
|
+
warnings.push({
|
|
20002
|
+
type: "unsupported",
|
|
20003
|
+
feature: "responseFormat",
|
|
20004
|
+
details: "JSON response format is not supported."
|
|
20005
|
+
});
|
|
20006
|
+
}
|
|
20007
|
+
const { prompt: completionPrompt, stopSequences } = convertToOpenAICompatibleCompletionPrompt({ prompt });
|
|
20008
|
+
const stop = [...stopSequences != null ? stopSequences : [], ...userStopSequences != null ? userStopSequences : []];
|
|
20009
|
+
return {
|
|
20010
|
+
args: {
|
|
20011
|
+
// model id:
|
|
20012
|
+
model: this.modelId,
|
|
20013
|
+
// model specific settings:
|
|
20014
|
+
echo: completionOptions.echo,
|
|
20015
|
+
logit_bias: completionOptions.logitBias,
|
|
20016
|
+
suffix: completionOptions.suffix,
|
|
20017
|
+
user: completionOptions.user,
|
|
20018
|
+
// standardized settings:
|
|
20019
|
+
max_tokens: maxOutputTokens,
|
|
20020
|
+
temperature,
|
|
20021
|
+
top_p: topP,
|
|
20022
|
+
frequency_penalty: frequencyPenalty,
|
|
20023
|
+
presence_penalty: presencePenalty,
|
|
20024
|
+
seed,
|
|
20025
|
+
...providerOptions == null ? void 0 : providerOptions[this.providerOptionsName],
|
|
20026
|
+
...providerOptions == null ? void 0 : providerOptions[toCamelCase(this.providerOptionsName)],
|
|
20027
|
+
// prompt:
|
|
20028
|
+
prompt: completionPrompt,
|
|
20029
|
+
// stop sequences:
|
|
20030
|
+
stop: stop.length > 0 ? stop : void 0
|
|
20031
|
+
},
|
|
20032
|
+
warnings
|
|
20033
|
+
};
|
|
20034
|
+
}
|
|
20035
|
+
async doGenerate(options) {
|
|
20036
|
+
const { args, warnings } = await this.getArgs(options);
|
|
20037
|
+
const {
|
|
20038
|
+
responseHeaders,
|
|
20039
|
+
value: response,
|
|
20040
|
+
rawValue: rawResponse
|
|
20041
|
+
} = await postJsonToApi({
|
|
20042
|
+
url: this.config.url({
|
|
20043
|
+
path: "/completions",
|
|
20044
|
+
modelId: this.modelId
|
|
20045
|
+
}),
|
|
20046
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
20047
|
+
body: args,
|
|
20048
|
+
failedResponseHandler: this.failedResponseHandler,
|
|
20049
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
20050
|
+
openaiCompatibleCompletionResponseSchema
|
|
20051
|
+
),
|
|
20052
|
+
abortSignal: options.abortSignal,
|
|
20053
|
+
fetch: this.config.fetch
|
|
20054
|
+
});
|
|
20055
|
+
const choice = response.choices[0];
|
|
20056
|
+
const content = [];
|
|
20057
|
+
if (choice.text != null && choice.text.length > 0) {
|
|
20058
|
+
content.push({ type: "text", text: choice.text });
|
|
20059
|
+
}
|
|
20060
|
+
return {
|
|
20061
|
+
content,
|
|
20062
|
+
usage: convertOpenAICompatibleCompletionUsage(response.usage),
|
|
20063
|
+
finishReason: {
|
|
20064
|
+
unified: mapOpenAICompatibleFinishReason2(choice.finish_reason),
|
|
20065
|
+
raw: choice.finish_reason
|
|
20066
|
+
},
|
|
20067
|
+
request: { body: args },
|
|
20068
|
+
response: {
|
|
20069
|
+
...getResponseMetadata2(response),
|
|
20070
|
+
headers: responseHeaders,
|
|
20071
|
+
body: rawResponse
|
|
20072
|
+
},
|
|
20073
|
+
warnings
|
|
20074
|
+
};
|
|
20075
|
+
}
|
|
20076
|
+
async doStream(options) {
|
|
20077
|
+
const { args, warnings } = await this.getArgs(options);
|
|
20078
|
+
const body = {
|
|
20079
|
+
...args,
|
|
20080
|
+
stream: true,
|
|
20081
|
+
// only include stream_options when in strict compatibility mode:
|
|
20082
|
+
stream_options: this.config.includeUsage ? { include_usage: true } : void 0
|
|
20083
|
+
};
|
|
20084
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
20085
|
+
url: this.config.url({
|
|
20086
|
+
path: "/completions",
|
|
20087
|
+
modelId: this.modelId
|
|
20088
|
+
}),
|
|
20089
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
20090
|
+
body,
|
|
20091
|
+
failedResponseHandler: this.failedResponseHandler,
|
|
20092
|
+
successfulResponseHandler: createEventSourceResponseHandler(
|
|
20093
|
+
this.chunkSchema
|
|
20094
|
+
),
|
|
20095
|
+
abortSignal: options.abortSignal,
|
|
20096
|
+
fetch: this.config.fetch
|
|
20097
|
+
});
|
|
20098
|
+
let finishReason = {
|
|
20099
|
+
unified: "other",
|
|
20100
|
+
raw: void 0
|
|
20101
|
+
};
|
|
20102
|
+
let usage = void 0;
|
|
20103
|
+
let isFirstChunk = true;
|
|
20104
|
+
return {
|
|
20105
|
+
stream: response.pipeThrough(
|
|
20106
|
+
new TransformStream({
|
|
20107
|
+
start(controller) {
|
|
20108
|
+
controller.enqueue({ type: "stream-start", warnings });
|
|
20109
|
+
},
|
|
20110
|
+
transform(chunk, controller) {
|
|
20111
|
+
var _a17;
|
|
20112
|
+
if (options.includeRawChunks) {
|
|
20113
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
20114
|
+
}
|
|
20115
|
+
if (!chunk.success) {
|
|
20116
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
20117
|
+
controller.enqueue({ type: "error", error: chunk.error });
|
|
20118
|
+
return;
|
|
20119
|
+
}
|
|
20120
|
+
const value = chunk.value;
|
|
20121
|
+
if ("error" in value) {
|
|
20122
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
20123
|
+
controller.enqueue({ type: "error", error: value.error });
|
|
20124
|
+
return;
|
|
20125
|
+
}
|
|
20126
|
+
if (isFirstChunk) {
|
|
20127
|
+
isFirstChunk = false;
|
|
20128
|
+
controller.enqueue({
|
|
20129
|
+
type: "response-metadata",
|
|
20130
|
+
...getResponseMetadata2(value)
|
|
20131
|
+
});
|
|
20132
|
+
controller.enqueue({
|
|
20133
|
+
type: "text-start",
|
|
20134
|
+
id: "0"
|
|
20135
|
+
});
|
|
20136
|
+
}
|
|
20137
|
+
if (value.usage != null) {
|
|
20138
|
+
usage = value.usage;
|
|
20139
|
+
}
|
|
20140
|
+
const choice = value.choices[0];
|
|
20141
|
+
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
20142
|
+
finishReason = {
|
|
20143
|
+
unified: mapOpenAICompatibleFinishReason2(choice.finish_reason),
|
|
20144
|
+
raw: (_a17 = choice.finish_reason) != null ? _a17 : void 0
|
|
20145
|
+
};
|
|
20146
|
+
}
|
|
20147
|
+
if ((choice == null ? void 0 : choice.text) != null) {
|
|
20148
|
+
controller.enqueue({
|
|
20149
|
+
type: "text-delta",
|
|
20150
|
+
id: "0",
|
|
20151
|
+
delta: choice.text
|
|
20152
|
+
});
|
|
20153
|
+
}
|
|
20154
|
+
},
|
|
20155
|
+
flush(controller) {
|
|
20156
|
+
if (!isFirstChunk) {
|
|
20157
|
+
controller.enqueue({ type: "text-end", id: "0" });
|
|
20158
|
+
}
|
|
20159
|
+
controller.enqueue({
|
|
20160
|
+
type: "finish",
|
|
20161
|
+
finishReason,
|
|
20162
|
+
usage: convertOpenAICompatibleCompletionUsage(usage)
|
|
20163
|
+
});
|
|
20164
|
+
}
|
|
20165
|
+
})
|
|
20166
|
+
),
|
|
20167
|
+
request: { body },
|
|
20168
|
+
response: { headers: responseHeaders }
|
|
20169
|
+
};
|
|
20170
|
+
}
|
|
20171
|
+
};
|
|
20172
|
+
usageSchema = external_exports.looseObject({
|
|
20173
|
+
prompt_tokens: external_exports.number(),
|
|
20174
|
+
completion_tokens: external_exports.number(),
|
|
20175
|
+
total_tokens: external_exports.number()
|
|
20176
|
+
});
|
|
20177
|
+
openaiCompatibleCompletionResponseSchema = external_exports.object({
|
|
20178
|
+
id: external_exports.string().nullish(),
|
|
20179
|
+
created: external_exports.number().nullish(),
|
|
20180
|
+
model: external_exports.string().nullish(),
|
|
20181
|
+
choices: external_exports.array(
|
|
20182
|
+
external_exports.object({
|
|
20183
|
+
text: external_exports.string(),
|
|
20184
|
+
finish_reason: external_exports.string()
|
|
20185
|
+
})
|
|
20186
|
+
),
|
|
20187
|
+
usage: usageSchema.nullish()
|
|
20188
|
+
});
|
|
20189
|
+
createOpenAICompatibleCompletionChunkSchema = (errorSchema) => external_exports.union([
|
|
20190
|
+
external_exports.object({
|
|
20191
|
+
id: external_exports.string().nullish(),
|
|
20192
|
+
created: external_exports.number().nullish(),
|
|
20193
|
+
model: external_exports.string().nullish(),
|
|
20194
|
+
choices: external_exports.array(
|
|
20195
|
+
external_exports.object({
|
|
20196
|
+
text: external_exports.string(),
|
|
20197
|
+
finish_reason: external_exports.string().nullish(),
|
|
20198
|
+
index: external_exports.number()
|
|
20199
|
+
})
|
|
20200
|
+
),
|
|
20201
|
+
usage: usageSchema.nullish()
|
|
20202
|
+
}),
|
|
20203
|
+
errorSchema
|
|
20204
|
+
]);
|
|
20205
|
+
openaiCompatibleEmbeddingModelOptions = external_exports.object({
|
|
20206
|
+
/**
|
|
20207
|
+
* The number of dimensions the resulting output embeddings should have.
|
|
20208
|
+
* Only supported in text-embedding-3 and later models.
|
|
20209
|
+
*/
|
|
20210
|
+
dimensions: external_exports.number().optional(),
|
|
20211
|
+
/**
|
|
20212
|
+
* A unique identifier representing your end-user, which can help providers to
|
|
20213
|
+
* monitor and detect abuse.
|
|
20214
|
+
*/
|
|
20215
|
+
user: external_exports.string().optional()
|
|
20216
|
+
});
|
|
20217
|
+
OpenAICompatibleEmbeddingModel = class {
|
|
20218
|
+
constructor(modelId, config2) {
|
|
20219
|
+
this.specificationVersion = "v3";
|
|
20220
|
+
this.modelId = modelId;
|
|
20221
|
+
this.config = config2;
|
|
20222
|
+
}
|
|
20223
|
+
get provider() {
|
|
20224
|
+
return this.config.provider;
|
|
20225
|
+
}
|
|
20226
|
+
get maxEmbeddingsPerCall() {
|
|
20227
|
+
var _a17;
|
|
20228
|
+
return (_a17 = this.config.maxEmbeddingsPerCall) != null ? _a17 : 2048;
|
|
20229
|
+
}
|
|
20230
|
+
get supportsParallelCalls() {
|
|
20231
|
+
var _a17;
|
|
20232
|
+
return (_a17 = this.config.supportsParallelCalls) != null ? _a17 : true;
|
|
20233
|
+
}
|
|
20234
|
+
get providerOptionsName() {
|
|
20235
|
+
return this.config.provider.split(".")[0].trim();
|
|
20236
|
+
}
|
|
20237
|
+
async doEmbed({
|
|
20238
|
+
values: values2,
|
|
20239
|
+
headers,
|
|
20240
|
+
abortSignal,
|
|
20241
|
+
providerOptions
|
|
20242
|
+
}) {
|
|
20243
|
+
var _a17, _b16, _c;
|
|
20244
|
+
const warnings = [];
|
|
20245
|
+
const deprecatedOptions = await parseProviderOptions({
|
|
20246
|
+
provider: "openai-compatible",
|
|
20247
|
+
providerOptions,
|
|
20248
|
+
schema: openaiCompatibleEmbeddingModelOptions
|
|
20249
|
+
});
|
|
20250
|
+
if (deprecatedOptions != null) {
|
|
20251
|
+
warnings.push({
|
|
20252
|
+
type: "other",
|
|
20253
|
+
message: `The 'openai-compatible' key in providerOptions is deprecated. Use 'openaiCompatible' instead.`
|
|
20254
|
+
});
|
|
20255
|
+
}
|
|
20256
|
+
const compatibleOptions = Object.assign(
|
|
20257
|
+
deprecatedOptions != null ? deprecatedOptions : {},
|
|
20258
|
+
(_a17 = await parseProviderOptions({
|
|
20259
|
+
provider: "openaiCompatible",
|
|
20260
|
+
providerOptions,
|
|
20261
|
+
schema: openaiCompatibleEmbeddingModelOptions
|
|
20262
|
+
})) != null ? _a17 : {},
|
|
20263
|
+
(_b16 = await parseProviderOptions({
|
|
20264
|
+
provider: this.providerOptionsName,
|
|
20265
|
+
providerOptions,
|
|
20266
|
+
schema: openaiCompatibleEmbeddingModelOptions
|
|
20267
|
+
})) != null ? _b16 : {}
|
|
20268
|
+
);
|
|
20269
|
+
if (values2.length > this.maxEmbeddingsPerCall) {
|
|
20270
|
+
throw new TooManyEmbeddingValuesForCallError({
|
|
20271
|
+
provider: this.provider,
|
|
20272
|
+
modelId: this.modelId,
|
|
20273
|
+
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
20274
|
+
values: values2
|
|
20275
|
+
});
|
|
20276
|
+
}
|
|
20277
|
+
const {
|
|
20278
|
+
responseHeaders,
|
|
20279
|
+
value: response,
|
|
20280
|
+
rawValue
|
|
20281
|
+
} = await postJsonToApi({
|
|
20282
|
+
url: this.config.url({
|
|
20283
|
+
path: "/embeddings",
|
|
20284
|
+
modelId: this.modelId
|
|
20285
|
+
}),
|
|
20286
|
+
headers: combineHeaders(this.config.headers(), headers),
|
|
20287
|
+
body: {
|
|
20288
|
+
model: this.modelId,
|
|
20289
|
+
input: values2,
|
|
20290
|
+
encoding_format: "float",
|
|
20291
|
+
dimensions: compatibleOptions.dimensions,
|
|
20292
|
+
user: compatibleOptions.user
|
|
20293
|
+
},
|
|
20294
|
+
failedResponseHandler: createJsonErrorResponseHandler(
|
|
20295
|
+
(_c = this.config.errorStructure) != null ? _c : defaultOpenAICompatibleErrorStructure
|
|
20296
|
+
),
|
|
20297
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
20298
|
+
openaiTextEmbeddingResponseSchema
|
|
20299
|
+
),
|
|
20300
|
+
abortSignal,
|
|
20301
|
+
fetch: this.config.fetch
|
|
20302
|
+
});
|
|
20303
|
+
return {
|
|
20304
|
+
warnings,
|
|
20305
|
+
embeddings: response.data.map((item) => item.embedding),
|
|
20306
|
+
usage: response.usage ? { tokens: response.usage.prompt_tokens } : void 0,
|
|
20307
|
+
providerMetadata: response.providerMetadata,
|
|
20308
|
+
response: { headers: responseHeaders, body: rawValue }
|
|
20309
|
+
};
|
|
20310
|
+
}
|
|
20311
|
+
};
|
|
20312
|
+
openaiTextEmbeddingResponseSchema = external_exports.object({
|
|
20313
|
+
data: external_exports.array(external_exports.object({ embedding: external_exports.array(external_exports.number()) })),
|
|
20314
|
+
usage: external_exports.object({ prompt_tokens: external_exports.number() }).nullish(),
|
|
20315
|
+
providerMetadata: external_exports.record(external_exports.string(), external_exports.record(external_exports.string(), external_exports.any())).optional()
|
|
20316
|
+
});
|
|
20317
|
+
OpenAICompatibleImageModel = class {
|
|
20318
|
+
constructor(modelId, config2) {
|
|
20319
|
+
this.modelId = modelId;
|
|
20320
|
+
this.config = config2;
|
|
20321
|
+
this.specificationVersion = "v3";
|
|
20322
|
+
this.maxImagesPerCall = 10;
|
|
20323
|
+
}
|
|
20324
|
+
get provider() {
|
|
20325
|
+
return this.config.provider;
|
|
20326
|
+
}
|
|
20327
|
+
/**
|
|
20328
|
+
* The provider options key used to extract provider-specific options.
|
|
20329
|
+
*/
|
|
20330
|
+
get providerOptionsKey() {
|
|
20331
|
+
return this.config.provider.split(".")[0].trim();
|
|
20332
|
+
}
|
|
20333
|
+
// TODO: deprecate non-camelCase keys and remove in future major version
|
|
20334
|
+
getArgs(providerOptions) {
|
|
20335
|
+
return {
|
|
20336
|
+
...providerOptions[this.providerOptionsKey],
|
|
20337
|
+
...providerOptions[toCamelCase(this.providerOptionsKey)]
|
|
20338
|
+
};
|
|
20339
|
+
}
|
|
20340
|
+
async doGenerate({
|
|
20341
|
+
prompt,
|
|
20342
|
+
n,
|
|
20343
|
+
size,
|
|
20344
|
+
aspectRatio,
|
|
20345
|
+
seed,
|
|
20346
|
+
providerOptions,
|
|
20347
|
+
headers,
|
|
20348
|
+
abortSignal,
|
|
20349
|
+
files,
|
|
20350
|
+
mask
|
|
20351
|
+
}) {
|
|
20352
|
+
var _a17, _b16, _c, _d, _e;
|
|
20353
|
+
const warnings = [];
|
|
20354
|
+
if (aspectRatio != null) {
|
|
20355
|
+
warnings.push({
|
|
20356
|
+
type: "unsupported",
|
|
20357
|
+
feature: "aspectRatio",
|
|
20358
|
+
details: "This model does not support aspect ratio. Use `size` instead."
|
|
20359
|
+
});
|
|
20360
|
+
}
|
|
20361
|
+
if (seed != null) {
|
|
20362
|
+
warnings.push({ type: "unsupported", feature: "seed" });
|
|
20363
|
+
}
|
|
20364
|
+
const currentDate = (_c = (_b16 = (_a17 = this.config._internal) == null ? void 0 : _a17.currentDate) == null ? void 0 : _b16.call(_a17)) != null ? _c : /* @__PURE__ */ new Date();
|
|
20365
|
+
const args = this.getArgs(providerOptions);
|
|
20366
|
+
if (files != null && files.length > 0) {
|
|
20367
|
+
const { value: response2, responseHeaders: responseHeaders2 } = await postFormDataToApi({
|
|
20368
|
+
url: this.config.url({
|
|
20369
|
+
path: "/images/edits",
|
|
20370
|
+
modelId: this.modelId
|
|
20371
|
+
}),
|
|
20372
|
+
headers: combineHeaders(this.config.headers(), headers),
|
|
20373
|
+
formData: convertToFormData({
|
|
20374
|
+
model: this.modelId,
|
|
20375
|
+
prompt,
|
|
20376
|
+
image: await Promise.all(files.map((file2) => fileToBlob(file2))),
|
|
20377
|
+
mask: mask != null ? await fileToBlob(mask) : void 0,
|
|
20378
|
+
n,
|
|
20379
|
+
size,
|
|
20380
|
+
...args
|
|
20381
|
+
}),
|
|
20382
|
+
failedResponseHandler: createJsonErrorResponseHandler(
|
|
20383
|
+
(_d = this.config.errorStructure) != null ? _d : defaultOpenAICompatibleErrorStructure
|
|
20384
|
+
),
|
|
20385
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
20386
|
+
openaiCompatibleImageResponseSchema
|
|
20387
|
+
),
|
|
20388
|
+
abortSignal,
|
|
20389
|
+
fetch: this.config.fetch
|
|
20390
|
+
});
|
|
20391
|
+
return {
|
|
20392
|
+
images: response2.data.map((item) => item.b64_json),
|
|
20393
|
+
warnings,
|
|
20394
|
+
response: {
|
|
20395
|
+
timestamp: currentDate,
|
|
20396
|
+
modelId: this.modelId,
|
|
20397
|
+
headers: responseHeaders2
|
|
20398
|
+
}
|
|
20399
|
+
};
|
|
20400
|
+
}
|
|
20401
|
+
const { value: response, responseHeaders } = await postJsonToApi({
|
|
20402
|
+
url: this.config.url({
|
|
20403
|
+
path: "/images/generations",
|
|
20404
|
+
modelId: this.modelId
|
|
20405
|
+
}),
|
|
20406
|
+
headers: combineHeaders(this.config.headers(), headers),
|
|
20407
|
+
body: {
|
|
20408
|
+
model: this.modelId,
|
|
20409
|
+
prompt,
|
|
20410
|
+
n,
|
|
20411
|
+
size,
|
|
20412
|
+
...args,
|
|
20413
|
+
response_format: "b64_json"
|
|
20414
|
+
},
|
|
20415
|
+
failedResponseHandler: createJsonErrorResponseHandler(
|
|
20416
|
+
(_e = this.config.errorStructure) != null ? _e : defaultOpenAICompatibleErrorStructure
|
|
20417
|
+
),
|
|
20418
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
20419
|
+
openaiCompatibleImageResponseSchema
|
|
20420
|
+
),
|
|
20421
|
+
abortSignal,
|
|
20422
|
+
fetch: this.config.fetch
|
|
20423
|
+
});
|
|
20424
|
+
return {
|
|
20425
|
+
images: response.data.map((item) => item.b64_json),
|
|
20426
|
+
warnings,
|
|
20427
|
+
response: {
|
|
20428
|
+
timestamp: currentDate,
|
|
20429
|
+
modelId: this.modelId,
|
|
20430
|
+
headers: responseHeaders
|
|
20431
|
+
}
|
|
20432
|
+
};
|
|
20433
|
+
}
|
|
20434
|
+
};
|
|
20435
|
+
openaiCompatibleImageResponseSchema = external_exports.object({
|
|
20436
|
+
data: external_exports.array(external_exports.object({ b64_json: external_exports.string() }))
|
|
20437
|
+
});
|
|
20438
|
+
VERSION2 = true ? "2.0.74" : "0.0.0-test";
|
|
20439
|
+
}
|
|
20440
|
+
});
|
|
20441
|
+
|
|
18028
20442
|
// node_modules/@smithy/core/dist-es/submodules/serde/is-array-buffer/is-array-buffer.js
|
|
18029
20443
|
var isArrayBuffer;
|
|
18030
20444
|
var init_is_array_buffer = __esm({
|
|
@@ -22662,16 +25076,17 @@ var init_aws4fetch_esm = __esm({
|
|
|
22662
25076
|
|
|
22663
25077
|
// node_modules/@ai-sdk/amazon-bedrock/dist/index.mjs
|
|
22664
25078
|
function supportsStrictTools(modelId) {
|
|
22665
|
-
return !
|
|
25079
|
+
return !matchesModel(modelId, MODELS_WITHOUT_STRICT_TOOL_SUPPORT);
|
|
22666
25080
|
}
|
|
22667
25081
|
function supportsNativeStructuredOutput(modelId) {
|
|
22668
|
-
return !
|
|
22669
|
-
|
|
22670
|
-
|
|
22671
|
-
return MODELS_REJECTING_NEWER_SCHEMA_FIELDS.some(
|
|
22672
|
-
(model) => modelId.includes(model)
|
|
25082
|
+
return !matchesModel(
|
|
25083
|
+
modelId,
|
|
25084
|
+
MODELS_WITHOUT_RELIABLE_NATIVE_STRUCTURED_OUTPUT
|
|
22673
25085
|
);
|
|
22674
25086
|
}
|
|
25087
|
+
function matchesModel(modelId, models) {
|
|
25088
|
+
return models.some((model) => modelId.includes(model));
|
|
25089
|
+
}
|
|
22675
25090
|
function createBedrockEventStreamDecoder(body, processEvent) {
|
|
22676
25091
|
const codec = new import_eventstream_codec.EventStreamCodec(import_util_utf8.toUtf8, import_util_utf8.fromUtf8);
|
|
22677
25092
|
let buffer = new Uint8Array(0);
|
|
@@ -22716,7 +25131,7 @@ function createBedrockEventStreamDecoder(body, processEvent) {
|
|
|
22716
25131
|
})
|
|
22717
25132
|
);
|
|
22718
25133
|
}
|
|
22719
|
-
async function
|
|
25134
|
+
async function prepareTools2({
|
|
22720
25135
|
tools,
|
|
22721
25136
|
toolChoice,
|
|
22722
25137
|
modelId,
|
|
@@ -23369,6 +25784,9 @@ function mapBedrockFinishReason(finishReason, isJsonResponseFromTool) {
|
|
|
23369
25784
|
return "other";
|
|
23370
25785
|
}
|
|
23371
25786
|
}
|
|
25787
|
+
function isJsonResponseToolName(name15) {
|
|
25788
|
+
return name15 === "json" || name15 === "json<|channel|>commentary";
|
|
25789
|
+
}
|
|
23372
25790
|
function isCohereEmbeddingModel(modelId) {
|
|
23373
25791
|
return modelId.includes("cohere.embed-");
|
|
23374
25792
|
}
|
|
@@ -23400,7 +25818,7 @@ function createSigV4FetchFunction(getCredentials, fetch2, service = "bedrock") {
|
|
|
23400
25818
|
);
|
|
23401
25819
|
const headersWithUserAgent = withUserAgentSuffix(
|
|
23402
25820
|
originalHeaders,
|
|
23403
|
-
`ai-sdk/amazon-bedrock/${
|
|
25821
|
+
`ai-sdk/amazon-bedrock/${VERSION3}`,
|
|
23404
25822
|
getRuntimeEnvironmentUserAgent()
|
|
23405
25823
|
);
|
|
23406
25824
|
let effectiveBody = (_a17 = init == null ? void 0 : init.body) != null ? _a17 : void 0;
|
|
@@ -23458,7 +25876,7 @@ function createApiKeyFetchFunction(apiKey, fetch2) {
|
|
|
23458
25876
|
const originalHeaders = normalizeHeaders(init == null ? void 0 : init.headers);
|
|
23459
25877
|
const headersWithUserAgent = withUserAgentSuffix(
|
|
23460
25878
|
originalHeaders,
|
|
23461
|
-
`ai-sdk/amazon-bedrock/${
|
|
25879
|
+
`ai-sdk/amazon-bedrock/${VERSION3}`,
|
|
23462
25880
|
getRuntimeEnvironmentUserAgent()
|
|
23463
25881
|
);
|
|
23464
25882
|
const finalHeaders = combineHeaders(headersWithUserAgent, {
|
|
@@ -23540,7 +25958,7 @@ Original error: ${errorMessage}`
|
|
|
23540
25958
|
const getHeaders = () => {
|
|
23541
25959
|
var _a17;
|
|
23542
25960
|
const baseHeaders = (_a17 = options.headers) != null ? _a17 : {};
|
|
23543
|
-
return withUserAgentSuffix(baseHeaders, `ai-sdk/amazon-bedrock/${
|
|
25961
|
+
return withUserAgentSuffix(baseHeaders, `ai-sdk/amazon-bedrock/${VERSION3}`);
|
|
23544
25962
|
};
|
|
23545
25963
|
const getBedrockRuntimeBaseUrl = () => {
|
|
23546
25964
|
var _a17, _b16;
|
|
@@ -23613,38 +26031,38 @@ Original error: ${errorMessage}`
|
|
|
23613
26031
|
provider.tools = import_internal.anthropicTools;
|
|
23614
26032
|
return provider;
|
|
23615
26033
|
}
|
|
23616
|
-
var import_internal, import_internal2, import_eventstream_codec, import_util_utf8, import_internal3, BEDROCK_STOP_REASONS, BEDROCK_IMAGE_MIME_TYPES, BEDROCK_DOCUMENT_MIME_TYPES, bedrockFilePartProviderOptions, amazonBedrockLanguageModelOptions,
|
|
23617
|
-
var
|
|
26034
|
+
var import_internal, import_internal2, import_eventstream_codec, import_util_utf8, import_internal3, BEDROCK_STOP_REASONS, BEDROCK_IMAGE_MIME_TYPES, BEDROCK_DOCUMENT_MIME_TYPES, bedrockFilePartProviderOptions, amazonBedrockLanguageModelOptions, MODELS_WITHOUT_STRICT_TOOL_SUPPORT, MODELS_WITHOUT_RELIABLE_NATIVE_STRUCTURED_OUTPUT, BedrockErrorSchema, createBedrockEventStreamResponseHandler, bedrockReasoningMetadataSchema, anthropicProviderOptions, BedrockChatLanguageModel, JsonObjectTextExtractor, BedrockStopReasonSchema, BedrockAdditionalModelResponseFieldsSchema, BedrockToolUseSchema, BedrockReasoningTextSchema, BedrockRedactedReasoningSchema, AmazonBedrockCacheDetailSchema, BedrockResponseSchema, BedrockStreamSchema, amazonBedrockEmbeddingModelOptionsSchema, BedrockEmbeddingModel, BedrockEmbeddingResponseSchema, modelMaxImagesPerCall, BedrockImageModel, bedrockImageResponseSchema, VERSION3, bedrockRerankingResponseSchema, amazonBedrockRerankingModelOptionsSchema, BedrockRerankingModel, bedrock;
|
|
26035
|
+
var init_dist5 = __esm({
|
|
23618
26036
|
"node_modules/@ai-sdk/amazon-bedrock/dist/index.mjs"() {
|
|
23619
26037
|
import_internal = require("@ai-sdk/anthropic/internal");
|
|
23620
|
-
|
|
23621
|
-
|
|
26038
|
+
init_dist3();
|
|
26039
|
+
init_dist3();
|
|
23622
26040
|
import_internal2 = require("@ai-sdk/anthropic/internal");
|
|
23623
26041
|
init_v4();
|
|
23624
26042
|
init_v4();
|
|
23625
26043
|
init_v4();
|
|
23626
26044
|
init_dist();
|
|
23627
|
-
|
|
26045
|
+
init_dist3();
|
|
23628
26046
|
import_eventstream_codec = __toESM(require_dist_cjs2(), 1);
|
|
23629
26047
|
import_util_utf8 = __toESM(require_dist_cjs3(), 1);
|
|
23630
26048
|
init_dist();
|
|
23631
|
-
|
|
26049
|
+
init_dist3();
|
|
23632
26050
|
import_internal3 = require("@ai-sdk/anthropic/internal");
|
|
23633
26051
|
init_dist();
|
|
23634
|
-
|
|
26052
|
+
init_dist3();
|
|
23635
26053
|
init_v4();
|
|
23636
26054
|
init_dist();
|
|
23637
|
-
|
|
26055
|
+
init_dist3();
|
|
23638
26056
|
init_v4();
|
|
23639
26057
|
init_v4();
|
|
23640
|
-
|
|
26058
|
+
init_dist3();
|
|
23641
26059
|
init_v4();
|
|
23642
|
-
|
|
26060
|
+
init_dist3();
|
|
23643
26061
|
init_aws4fetch_esm();
|
|
23644
|
-
|
|
23645
|
-
|
|
26062
|
+
init_dist3();
|
|
26063
|
+
init_dist3();
|
|
23646
26064
|
init_v4();
|
|
23647
|
-
|
|
26065
|
+
init_dist3();
|
|
23648
26066
|
init_v4();
|
|
23649
26067
|
BEDROCK_STOP_REASONS = [
|
|
23650
26068
|
"stop",
|
|
@@ -23688,6 +26106,14 @@ var init_dist3 = __esm({
|
|
|
23688
26106
|
}).optional()
|
|
23689
26107
|
});
|
|
23690
26108
|
amazonBedrockLanguageModelOptions = external_exports.object({
|
|
26109
|
+
/**
|
|
26110
|
+
* Determines how structured outputs are generated for Anthropic models.
|
|
26111
|
+
*
|
|
26112
|
+
* - `outputFormat`: Use the native `output_config.format` parameter.
|
|
26113
|
+
* - `jsonTool`: Use a special 'json' tool to specify the structured output format.
|
|
26114
|
+
* - `auto`: Use `outputFormat` when supported, otherwise use `jsonTool` (default).
|
|
26115
|
+
*/
|
|
26116
|
+
structuredOutputMode: external_exports.enum(["outputFormat", "jsonTool", "auto"]).optional(),
|
|
23691
26117
|
/**
|
|
23692
26118
|
* Additional inference parameters that the model supports,
|
|
23693
26119
|
* beyond the base set of inference parameters that Converse
|
|
@@ -23719,13 +26145,18 @@ var init_dist3 = __esm({
|
|
|
23719
26145
|
*/
|
|
23720
26146
|
serviceTier: external_exports.enum(["reserved", "priority", "default", "flex"]).optional()
|
|
23721
26147
|
});
|
|
23722
|
-
|
|
26148
|
+
MODELS_WITHOUT_STRICT_TOOL_SUPPORT = [
|
|
23723
26149
|
"claude-opus-4-7",
|
|
23724
26150
|
"claude-opus-4-8",
|
|
23725
26151
|
"claude-opus-5",
|
|
23726
26152
|
"claude-fable-5",
|
|
23727
26153
|
"claude-sonnet-5"
|
|
23728
26154
|
];
|
|
26155
|
+
MODELS_WITHOUT_RELIABLE_NATIVE_STRUCTURED_OUTPUT = [
|
|
26156
|
+
...MODELS_WITHOUT_STRICT_TOOL_SUPPORT,
|
|
26157
|
+
"claude-sonnet-4-6",
|
|
26158
|
+
"claude-haiku-4-5"
|
|
26159
|
+
];
|
|
23729
26160
|
BedrockErrorSchema = external_exports.object({
|
|
23730
26161
|
message: external_exports.string(),
|
|
23731
26162
|
type: external_exports.string().nullish()
|
|
@@ -23776,7 +26207,8 @@ var init_dist3 = __esm({
|
|
|
23776
26207
|
redactedContent: external_exports.string().optional()
|
|
23777
26208
|
});
|
|
23778
26209
|
anthropicProviderOptions = external_exports.object({
|
|
23779
|
-
disableParallelToolUse: external_exports.boolean().optional()
|
|
26210
|
+
disableParallelToolUse: external_exports.boolean().optional(),
|
|
26211
|
+
structuredOutputMode: external_exports.enum(["outputFormat", "jsonTool", "auto"]).optional()
|
|
23780
26212
|
});
|
|
23781
26213
|
BedrockChatLanguageModel = class {
|
|
23782
26214
|
constructor(modelId, config2) {
|
|
@@ -23803,7 +26235,7 @@ var init_dist3 = __esm({
|
|
|
23803
26235
|
toolChoice,
|
|
23804
26236
|
providerOptions
|
|
23805
26237
|
}) {
|
|
23806
|
-
var _a17, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
26238
|
+
var _a17, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
23807
26239
|
const bedrockOptions = (_a17 = await parseProviderOptions({
|
|
23808
26240
|
provider: "bedrock",
|
|
23809
26241
|
providerOptions,
|
|
@@ -23861,15 +26293,33 @@ var init_dist3 = __esm({
|
|
|
23861
26293
|
const isOpenAIGptOssModel = (_d = openAIModelId == null ? void 0 : openAIModelId.startsWith("openai.gpt-oss-")) != null ? _d : false;
|
|
23862
26294
|
const isThinkingEnabled = ((_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.type) === "enabled" || ((_f = bedrockOptions.reasoningConfig) == null ? void 0 : _f.type) === "adaptive";
|
|
23863
26295
|
const { supportsStructuredOutput: modelSupportsStructuredOutput } = (0, import_internal2.getModelCapabilities)(this.modelId);
|
|
23864
|
-
const
|
|
23865
|
-
|
|
26296
|
+
const structuredOutputMode = (_h = (_g = bedrockOptions.structuredOutputMode) != null ? _g : anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _h : "auto";
|
|
26297
|
+
if (structuredOutputMode === "jsonTool") {
|
|
26298
|
+
const additionalModelRequestFields = {
|
|
26299
|
+
...bedrockOptions.additionalModelRequestFields
|
|
26300
|
+
};
|
|
26301
|
+
const outputConfig = additionalModelRequestFields.output_config;
|
|
26302
|
+
if (outputConfig != null && typeof outputConfig === "object" && !Array.isArray(outputConfig)) {
|
|
26303
|
+
const outputConfigWithoutFormat = { ...outputConfig };
|
|
26304
|
+
delete outputConfigWithoutFormat.format;
|
|
26305
|
+
if (Object.keys(outputConfigWithoutFormat).length > 0) {
|
|
26306
|
+
additionalModelRequestFields.output_config = outputConfigWithoutFormat;
|
|
26307
|
+
} else {
|
|
26308
|
+
delete additionalModelRequestFields.output_config;
|
|
26309
|
+
}
|
|
26310
|
+
bedrockOptions.additionalModelRequestFields = additionalModelRequestFields;
|
|
26311
|
+
}
|
|
26312
|
+
}
|
|
26313
|
+
const modelSupportsNativeStructuredOutput = supportsNativeStructuredOutput(this.modelId) && (modelSupportsStructuredOutput || isThinkingEnabled);
|
|
26314
|
+
const useNativeStructuredOutput = isAnthropicModel && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && (structuredOutputMode === "outputFormat" || structuredOutputMode === "auto" && modelSupportsNativeStructuredOutput);
|
|
26315
|
+
const useJsonInstructionForStructuredOutput = !useNativeStructuredOutput && structuredOutputMode !== "jsonTool" && isAnthropicModel && !supportsStrictTools(this.modelId) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && tools != null && tools.length > 0;
|
|
23866
26316
|
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput && !useJsonInstructionForStructuredOutput ? {
|
|
23867
26317
|
type: "function",
|
|
23868
26318
|
name: "json",
|
|
23869
26319
|
description: "Respond with a JSON object.",
|
|
23870
26320
|
inputSchema: responseFormat.schema
|
|
23871
26321
|
} : void 0;
|
|
23872
|
-
const { toolConfig, additionalTools, toolWarnings, betas } = await
|
|
26322
|
+
const { toolConfig, additionalTools, toolWarnings, betas } = await prepareTools2({
|
|
23873
26323
|
tools: jsonResponseTool ? [...tools != null ? tools : [], jsonResponseTool] : tools,
|
|
23874
26324
|
toolChoice: jsonResponseTool != null ? { type: "required" } : toolChoice,
|
|
23875
26325
|
modelId: this.modelId,
|
|
@@ -23883,16 +26333,16 @@ var init_dist3 = __esm({
|
|
|
23883
26333
|
};
|
|
23884
26334
|
}
|
|
23885
26335
|
if (betas.size > 0 || bedrockOptions.anthropicBeta) {
|
|
23886
|
-
const existingBetas = (
|
|
26336
|
+
const existingBetas = (_i = bedrockOptions.anthropicBeta) != null ? _i : [];
|
|
23887
26337
|
const mergedBetas = betas.size > 0 ? [...existingBetas, ...Array.from(betas)] : existingBetas;
|
|
23888
26338
|
bedrockOptions.additionalModelRequestFields = {
|
|
23889
26339
|
...bedrockOptions.additionalModelRequestFields,
|
|
23890
26340
|
anthropic_beta: mergedBetas
|
|
23891
26341
|
};
|
|
23892
26342
|
}
|
|
23893
|
-
const thinkingType = (
|
|
23894
|
-
const thinkingBudget = thinkingType === "enabled" ? (
|
|
23895
|
-
const thinkingDisplay = thinkingType === "adaptive" ? (
|
|
26343
|
+
const thinkingType = (_j = bedrockOptions.reasoningConfig) == null ? void 0 : _j.type;
|
|
26344
|
+
const thinkingBudget = thinkingType === "enabled" ? (_k = bedrockOptions.reasoningConfig) == null ? void 0 : _k.budgetTokens : void 0;
|
|
26345
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_l = bedrockOptions.reasoningConfig) == null ? void 0 : _l.display : void 0;
|
|
23896
26346
|
const isAnthropicThinkingEnabled = isAnthropicModel && isThinkingEnabled;
|
|
23897
26347
|
const inferenceConfig = {
|
|
23898
26348
|
...maxOutputTokens != null && { maxTokens: maxOutputTokens },
|
|
@@ -23925,7 +26375,7 @@ var init_dist3 = __esm({
|
|
|
23925
26375
|
};
|
|
23926
26376
|
}
|
|
23927
26377
|
} else if (!isAnthropicModel) {
|
|
23928
|
-
if (((
|
|
26378
|
+
if (((_m = bedrockOptions.reasoningConfig) == null ? void 0 : _m.budgetTokens) != null) {
|
|
23929
26379
|
warnings.push({
|
|
23930
26380
|
type: "unsupported",
|
|
23931
26381
|
feature: "budgetTokens",
|
|
@@ -23940,13 +26390,13 @@ var init_dist3 = __esm({
|
|
|
23940
26390
|
});
|
|
23941
26391
|
}
|
|
23942
26392
|
}
|
|
23943
|
-
const maxReasoningEffort = (
|
|
26393
|
+
const maxReasoningEffort = (_n = bedrockOptions.reasoningConfig) == null ? void 0 : _n.maxReasoningEffort;
|
|
23944
26394
|
if (maxReasoningEffort != null) {
|
|
23945
26395
|
if (isAnthropicModel) {
|
|
23946
26396
|
bedrockOptions.additionalModelRequestFields = {
|
|
23947
26397
|
...bedrockOptions.additionalModelRequestFields,
|
|
23948
26398
|
output_config: {
|
|
23949
|
-
...(
|
|
26399
|
+
...(_o = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _o.output_config,
|
|
23950
26400
|
effort: maxReasoningEffort
|
|
23951
26401
|
}
|
|
23952
26402
|
};
|
|
@@ -23957,7 +26407,7 @@ var init_dist3 = __esm({
|
|
|
23957
26407
|
} : {
|
|
23958
26408
|
...bedrockOptions.additionalModelRequestFields,
|
|
23959
26409
|
reasoning: {
|
|
23960
|
-
...(
|
|
26410
|
+
...(_p = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _p.reasoning,
|
|
23961
26411
|
effort: maxReasoningEffort
|
|
23962
26412
|
}
|
|
23963
26413
|
};
|
|
@@ -23976,7 +26426,7 @@ var init_dist3 = __esm({
|
|
|
23976
26426
|
bedrockOptions.additionalModelRequestFields = {
|
|
23977
26427
|
...bedrockOptions.additionalModelRequestFields,
|
|
23978
26428
|
output_config: {
|
|
23979
|
-
...(
|
|
26429
|
+
...(_q = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _q.output_config,
|
|
23980
26430
|
format: {
|
|
23981
26431
|
type: "json_schema",
|
|
23982
26432
|
schema: (0, import_internal2.sanitizeJsonSchema)(responseFormat.schema)
|
|
@@ -24008,7 +26458,7 @@ var init_dist3 = __esm({
|
|
|
24008
26458
|
details: "topK is not supported when thinking is enabled"
|
|
24009
26459
|
});
|
|
24010
26460
|
}
|
|
24011
|
-
const hasAnyTools = ((
|
|
26461
|
+
const hasAnyTools = ((_s = (_r = toolConfig.tools) == null ? void 0 : _r.length) != null ? _s : 0) > 0 || additionalTools;
|
|
24012
26462
|
let filteredPrompt = prompt;
|
|
24013
26463
|
if (!hasAnyTools) {
|
|
24014
26464
|
const hasToolContent = prompt.some(
|
|
@@ -24050,6 +26500,7 @@ var init_dist3 = __esm({
|
|
|
24050
26500
|
reasoningConfig: _,
|
|
24051
26501
|
additionalModelRequestFields: __,
|
|
24052
26502
|
serviceTier: ___,
|
|
26503
|
+
structuredOutputMode: ____,
|
|
24053
26504
|
...filteredBedrockOptions
|
|
24054
26505
|
} = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
|
|
24055
26506
|
const additionalModelResponseFieldPaths = isAnthropicModel ? ["/delta/stop_sequence"] : void 0;
|
|
@@ -24156,7 +26607,7 @@ var init_dist3 = __esm({
|
|
|
24156
26607
|
}
|
|
24157
26608
|
}
|
|
24158
26609
|
if (part.toolUse) {
|
|
24159
|
-
const isJsonResponseTool = usesJsonResponseTool && part.toolUse.name
|
|
26610
|
+
const isJsonResponseTool = usesJsonResponseTool && isJsonResponseToolName(part.toolUse.name);
|
|
24160
26611
|
if (isJsonResponseTool) {
|
|
24161
26612
|
isJsonResponseFromTool = true;
|
|
24162
26613
|
content.push({
|
|
@@ -24491,7 +26942,7 @@ var init_dist3 = __esm({
|
|
|
24491
26942
|
if (((_q = contentBlockStart == null ? void 0 : contentBlockStart.start) == null ? void 0 : _q.toolUse) != null) {
|
|
24492
26943
|
const toolUse = contentBlockStart.start.toolUse;
|
|
24493
26944
|
const blockIndex = contentBlockStart.contentBlockIndex;
|
|
24494
|
-
const isJsonResponseTool = usesJsonResponseTool && toolUse.name
|
|
26945
|
+
const isJsonResponseTool = usesJsonResponseTool && isJsonResponseToolName(toolUse.name);
|
|
24495
26946
|
const normalizedToolCallId = normalizeToolCallId(
|
|
24496
26947
|
toolUse.toolUseId,
|
|
24497
26948
|
isMistral
|
|
@@ -25113,7 +27564,7 @@ var init_dist3 = __esm({
|
|
|
25113
27564
|
details: external_exports.record(external_exports.string(), external_exports.unknown()).optional(),
|
|
25114
27565
|
preview: external_exports.unknown().optional()
|
|
25115
27566
|
});
|
|
25116
|
-
|
|
27567
|
+
VERSION3 = true ? "4.0.169" : "0.0.0-test";
|
|
25117
27568
|
bedrockRerankingResponseSchema = lazySchema(
|
|
25118
27569
|
() => zodSchema(
|
|
25119
27570
|
external_exports.object({
|
|
@@ -25231,10 +27682,17 @@ function createProviderInstance(config2) {
|
|
|
25231
27682
|
...config2.baseURL && { baseURL: config2.baseURL }
|
|
25232
27683
|
});
|
|
25233
27684
|
case "openai": {
|
|
27685
|
+
if (config2.baseURL) {
|
|
27686
|
+
const provider = createOpenAICompatible({
|
|
27687
|
+
name: "openai-compatible",
|
|
27688
|
+
baseURL: config2.baseURL,
|
|
27689
|
+
apiKey: config2.apiKey
|
|
27690
|
+
});
|
|
27691
|
+
return provider;
|
|
27692
|
+
}
|
|
25234
27693
|
const openai = (0, import_openai.createOpenAI)({
|
|
25235
27694
|
compatibility: "strict",
|
|
25236
|
-
apiKey: config2.apiKey
|
|
25237
|
-
...config2.baseURL && { baseURL: config2.baseURL }
|
|
27695
|
+
apiKey: config2.apiKey
|
|
25238
27696
|
});
|
|
25239
27697
|
const chatProvider = (modelId, settings) => openai.chat(modelId, settings);
|
|
25240
27698
|
chatProvider.chat = openai.chat.bind(openai);
|
|
@@ -25314,8 +27772,9 @@ var init_provider = __esm({
|
|
|
25314
27772
|
"use strict";
|
|
25315
27773
|
import_anthropic = require("@ai-sdk/anthropic");
|
|
25316
27774
|
import_openai = require("@ai-sdk/openai");
|
|
27775
|
+
init_dist4();
|
|
25317
27776
|
import_google = require("@ai-sdk/google");
|
|
25318
|
-
|
|
27777
|
+
init_dist5();
|
|
25319
27778
|
DEFAULT_MODELS = {
|
|
25320
27779
|
anthropic: "claude-sonnet-4-6",
|
|
25321
27780
|
openai: "gpt-5.2",
|
|
@@ -33854,7 +36313,7 @@ var require_parser = __commonJS({
|
|
|
33854
36313
|
/* LispType.None */
|
|
33855
36314
|
});
|
|
33856
36315
|
var lispTypes = /* @__PURE__ */ new Map();
|
|
33857
|
-
var
|
|
36316
|
+
var ParseError2 = class extends Error {
|
|
33858
36317
|
constructor(message, code) {
|
|
33859
36318
|
super(message + ": " + code.substring(0, 40));
|
|
33860
36319
|
this.code = code;
|
|
@@ -34789,7 +37248,7 @@ var require_parser = __commonJS({
|
|
|
34789
37248
|
lispTypes.get(type)?.(constants, type, part, res, expect, ctx);
|
|
34790
37249
|
} catch (e) {
|
|
34791
37250
|
if (topLevel && e instanceof SyntaxError) {
|
|
34792
|
-
throw new
|
|
37251
|
+
throw new ParseError2(e.message, str);
|
|
34793
37252
|
}
|
|
34794
37253
|
throw e;
|
|
34795
37254
|
}
|
|
@@ -34801,7 +37260,7 @@ var require_parser = __commonJS({
|
|
|
34801
37260
|
}
|
|
34802
37261
|
if (!res && part.length) {
|
|
34803
37262
|
if (topLevel) {
|
|
34804
|
-
throw new
|
|
37263
|
+
throw new ParseError2(`Unexpected token after ${lastType}: ${part.char(0)}`, str);
|
|
34805
37264
|
}
|
|
34806
37265
|
throw new SyntaxError(`Unexpected token after ${lastType}: ${part.char(0)}`);
|
|
34807
37266
|
}
|
|
@@ -35096,7 +37555,7 @@ var require_parser = __commonJS({
|
|
|
35096
37555
|
}
|
|
35097
37556
|
function parse11(code, eager = false, expression = false) {
|
|
35098
37557
|
if (typeof code !== "string")
|
|
35099
|
-
throw new
|
|
37558
|
+
throw new ParseError2(`Cannot parse ${code}`, code);
|
|
35100
37559
|
let str = " " + code;
|
|
35101
37560
|
const constants = { strings: [], literals: [], regexes: [], eager };
|
|
35102
37561
|
str = extractConstants(constants, str).str;
|
|
@@ -35106,7 +37565,7 @@ var require_parser = __commonJS({
|
|
|
35106
37565
|
}
|
|
35107
37566
|
return { tree: lispifyFunction(new utils.CodeString(str), constants, expression), constants };
|
|
35108
37567
|
}
|
|
35109
|
-
exports2.ParseError =
|
|
37568
|
+
exports2.ParseError = ParseError2;
|
|
35110
37569
|
exports2.checkRegex = checkRegex;
|
|
35111
37570
|
exports2.default = parse11;
|
|
35112
37571
|
exports2.expectTypes = expectTypes;
|
|
@@ -55320,12 +57779,12 @@ var init_apply = __esm({
|
|
|
55320
57779
|
});
|
|
55321
57780
|
|
|
55322
57781
|
// node_modules/lodash-es/noop.js
|
|
55323
|
-
function
|
|
57782
|
+
function noop2() {
|
|
55324
57783
|
}
|
|
55325
57784
|
var noop_default;
|
|
55326
57785
|
var init_noop = __esm({
|
|
55327
57786
|
"node_modules/lodash-es/noop.js"() {
|
|
55328
|
-
noop_default =
|
|
57787
|
+
noop_default = noop2;
|
|
55329
57788
|
}
|
|
55330
57789
|
});
|
|
55331
57790
|
|
|
@@ -77274,9 +79733,9 @@ var require_arrayIncludesWith = __commonJS({
|
|
|
77274
79733
|
// node_modules/lodash/noop.js
|
|
77275
79734
|
var require_noop = __commonJS({
|
|
77276
79735
|
"node_modules/lodash/noop.js"(exports2, module2) {
|
|
77277
|
-
function
|
|
79736
|
+
function noop3() {
|
|
77278
79737
|
}
|
|
77279
|
-
module2.exports =
|
|
79738
|
+
module2.exports = noop3;
|
|
77280
79739
|
}
|
|
77281
79740
|
});
|
|
77282
79741
|
|
|
@@ -77284,10 +79743,10 @@ var require_noop = __commonJS({
|
|
|
77284
79743
|
var require_createSet = __commonJS({
|
|
77285
79744
|
"node_modules/lodash/_createSet.js"(exports2, module2) {
|
|
77286
79745
|
var Set3 = require_Set();
|
|
77287
|
-
var
|
|
79746
|
+
var noop3 = require_noop();
|
|
77288
79747
|
var setToArray2 = require_setToArray();
|
|
77289
79748
|
var INFINITY5 = 1 / 0;
|
|
77290
|
-
var createSet2 = !(Set3 && 1 / setToArray2(new Set3([, -0]))[1] == INFINITY5) ?
|
|
79749
|
+
var createSet2 = !(Set3 && 1 / setToArray2(new Set3([, -0]))[1] == INFINITY5) ? noop3 : function(values2) {
|
|
77291
79750
|
return new Set3(values2);
|
|
77292
79751
|
};
|
|
77293
79752
|
module2.exports = createSet2;
|
|
@@ -88404,7 +90863,7 @@ var require_utils2 = __commonJS({
|
|
|
88404
90863
|
"node_modules/fast-uri/lib/utils.js"(exports2, module2) {
|
|
88405
90864
|
"use strict";
|
|
88406
90865
|
var isUUID = RegExp.prototype.test.bind(/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu);
|
|
88407
|
-
var
|
|
90866
|
+
var isIPv42 = RegExp.prototype.test.bind(/^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/u);
|
|
88408
90867
|
var isHexPair = RegExp.prototype.test.bind(/^[\da-f]{2}$/iu);
|
|
88409
90868
|
var isUnreserved = RegExp.prototype.test.bind(/^[\da-z\-._~]$/iu);
|
|
88410
90869
|
var isPathCharacter = RegExp.prototype.test.bind(/^[A-Za-z0-9\-._~!$&'()*+,;=:@/]$/u);
|
|
@@ -88504,7 +90963,7 @@ var require_utils2 = __commonJS({
|
|
|
88504
90963
|
const part = parts[i];
|
|
88505
90964
|
if (part === "") return void 0;
|
|
88506
90965
|
if (part.indexOf(".") !== -1) {
|
|
88507
|
-
if (i !== parts.length - 1 || compression !== -1 && right.length === 0 || !
|
|
90966
|
+
if (i !== parts.length - 1 || compression !== -1 && right.length === 0 || !isIPv42(part)) return void 0;
|
|
88508
90967
|
hextetCount += 2;
|
|
88509
90968
|
continue;
|
|
88510
90969
|
}
|
|
@@ -88855,7 +91314,7 @@ var require_utils2 = __commonJS({
|
|
|
88855
91314
|
}
|
|
88856
91315
|
if (component.host !== void 0) {
|
|
88857
91316
|
let host = component.host;
|
|
88858
|
-
if (!
|
|
91317
|
+
if (!isIPv42(host)) {
|
|
88859
91318
|
let ipV6res = normalizeIPv6(host);
|
|
88860
91319
|
if (ipV6res.isIPV6 !== true && ipV6res.isIPVFuture !== true) {
|
|
88861
91320
|
host = normalizePercentEncoding(host, true);
|
|
@@ -88888,7 +91347,7 @@ var require_utils2 = __commonJS({
|
|
|
88888
91347
|
encodeFragment,
|
|
88889
91348
|
escapePreservingEscapes,
|
|
88890
91349
|
removeDotSegments,
|
|
88891
|
-
isIPv4,
|
|
91350
|
+
isIPv4: isIPv42,
|
|
88892
91351
|
isUUID,
|
|
88893
91352
|
normalizeIPv6,
|
|
88894
91353
|
stringArrayToHexStripped
|
|
@@ -89111,7 +91570,7 @@ var require_schemes = __commonJS({
|
|
|
89111
91570
|
var require_fast_uri = __commonJS({
|
|
89112
91571
|
"node_modules/fast-uri/index.js"(exports2, module2) {
|
|
89113
91572
|
"use strict";
|
|
89114
|
-
var { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizePercentEncoding, normalizePathEncoding, serializePathEncoding, normalizeQueryFragmentEncoding, encodeQuery, encodeFragment, reescapeHostDelimiters, isIPv4, nonSimpleDomain } = require_utils2();
|
|
91573
|
+
var { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizePercentEncoding, normalizePathEncoding, serializePathEncoding, normalizeQueryFragmentEncoding, encodeQuery, encodeFragment, reescapeHostDelimiters, isIPv4: isIPv42, nonSimpleDomain } = require_utils2();
|
|
89115
91574
|
var { SCHEMES, getSchemeHandler } = require_schemes();
|
|
89116
91575
|
var VALID_SCHEME = /^[A-Za-z][A-Za-z0-9+.-]*$/u;
|
|
89117
91576
|
var MALFORMED_SCHEME_ERROR = "URI scheme is malformed.";
|
|
@@ -89156,7 +91615,7 @@ var require_fast_uri = __commonJS({
|
|
|
89156
91615
|
const resolved = resolveComponent(baseParsed, relativeParsed, schemelessOptions, true);
|
|
89157
91616
|
const resolvedSchemeHandler = getSchemeHandler(options && options.scheme || resolved.scheme);
|
|
89158
91617
|
const resolvedHost = resolved.host;
|
|
89159
|
-
const resolvedHostIsIP = resolvedHost !== void 0 && resolvedHost !== "" && (
|
|
91618
|
+
const resolvedHostIsIP = resolvedHost !== void 0 && resolvedHost !== "" && (isIPv42(resolvedHost) || normalizeIPv6(resolvedHost).isIPV6);
|
|
89160
91619
|
canonicalizeHost(resolved, options || {}, resolvedSchemeHandler, resolvedHostIsIP);
|
|
89161
91620
|
const encodedASCIIHost = resolvedHost && resolvedHost.indexOf("%") !== -1 && !/\P{ASCII}/u.test(resolvedHost);
|
|
89162
91621
|
if (resolved.error && !encodedASCIIHost) {
|
|
@@ -89404,7 +91863,7 @@ var require_fast_uri = __commonJS({
|
|
|
89404
91863
|
malformedAuthorityOrPort = true;
|
|
89405
91864
|
}
|
|
89406
91865
|
if (parsed.host) {
|
|
89407
|
-
const ipv4result =
|
|
91866
|
+
const ipv4result = isIPv42(parsed.host);
|
|
89408
91867
|
if (ipv4result === false) {
|
|
89409
91868
|
const bracketedIPLiteral = parsed.host[0] === "[" && parsed.host[parsed.host.length - 1] === "]";
|
|
89410
91869
|
const ipv6result = normalizeIPv6(parsed.host);
|