@openrouter/ai-sdk-provider 2.10.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -1
- package/dist/index.d.ts +40 -40
- package/dist/index.js +706 -645
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +37 -37
- package/dist/internal/index.js +692 -634
- package/dist/internal/index.js.map +1 -1
- package/package.json +14 -15
- package/dist/index.d.mts +0 -880
- package/dist/index.mjs +0 -5307
- package/dist/index.mjs.map +0 -1
- package/dist/internal/index.d.mts +0 -723
- package/dist/internal/index.mjs +0 -5035
- package/dist/internal/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
1
|
var __defProp = Object.defineProperty;
|
|
4
2
|
var __defProps = Object.defineProperties;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
3
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
10
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
7
|
var __typeError = (msg) => {
|
|
@@ -37,41 +32,11 @@ var __objRest = (source, exclude) => {
|
|
|
37
32
|
}
|
|
38
33
|
return target;
|
|
39
34
|
};
|
|
40
|
-
var __export = (target, all) => {
|
|
41
|
-
for (var name15 in all)
|
|
42
|
-
__defProp(target, name15, { get: all[name15], enumerable: true });
|
|
43
|
-
};
|
|
44
|
-
var __copyProps = (to, from, except, desc) => {
|
|
45
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
46
|
-
for (let key of __getOwnPropNames(from))
|
|
47
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
48
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
49
|
-
}
|
|
50
|
-
return to;
|
|
51
|
-
};
|
|
52
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
53
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
54
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
55
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
56
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
57
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
58
|
-
mod
|
|
59
|
-
));
|
|
60
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
61
35
|
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
62
36
|
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
63
37
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
64
38
|
|
|
65
|
-
//
|
|
66
|
-
var index_exports = {};
|
|
67
|
-
__export(index_exports, {
|
|
68
|
-
OpenRouter: () => OpenRouter,
|
|
69
|
-
createOpenRouter: () => createOpenRouter,
|
|
70
|
-
openrouter: () => openrouter
|
|
71
|
-
});
|
|
72
|
-
module.exports = __toCommonJS(index_exports);
|
|
73
|
-
|
|
74
|
-
// node_modules/.pnpm/@ai-sdk+provider@3.0.8/node_modules/@ai-sdk/provider/dist/index.mjs
|
|
39
|
+
// node_modules/.pnpm/@ai-sdk+provider@4.0.0/node_modules/@ai-sdk/provider/dist/index.js
|
|
75
40
|
var marker = "vercel.ai.error";
|
|
76
41
|
var symbol = Symbol.for(marker);
|
|
77
42
|
var _a;
|
|
@@ -86,13 +51,13 @@ var AISDKError = class _AISDKError extends (_b = Error, _a = symbol, _b) {
|
|
|
86
51
|
* @param {unknown} [params.cause] - The underlying cause of the error.
|
|
87
52
|
*/
|
|
88
53
|
constructor({
|
|
89
|
-
name:
|
|
54
|
+
name: name152,
|
|
90
55
|
message,
|
|
91
56
|
cause
|
|
92
57
|
}) {
|
|
93
58
|
super(message);
|
|
94
59
|
this[_a] = true;
|
|
95
|
-
this.name =
|
|
60
|
+
this.name = name152;
|
|
96
61
|
this.cause = cause;
|
|
97
62
|
}
|
|
98
63
|
/**
|
|
@@ -103,8 +68,8 @@ var AISDKError = class _AISDKError extends (_b = Error, _a = symbol, _b) {
|
|
|
103
68
|
static isInstance(error) {
|
|
104
69
|
return _AISDKError.hasMarker(error, marker);
|
|
105
70
|
}
|
|
106
|
-
static hasMarker(error,
|
|
107
|
-
const markerSymbol = Symbol.for(
|
|
71
|
+
static hasMarker(error, marker162) {
|
|
72
|
+
const markerSymbol = Symbol.for(marker162);
|
|
108
73
|
return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
|
|
109
74
|
}
|
|
110
75
|
};
|
|
@@ -166,7 +131,7 @@ function getErrorMessage(error) {
|
|
|
166
131
|
return error;
|
|
167
132
|
}
|
|
168
133
|
if (error instanceof Error) {
|
|
169
|
-
return error.
|
|
134
|
+
return error.toString();
|
|
170
135
|
}
|
|
171
136
|
return JSON.stringify(error);
|
|
172
137
|
}
|
|
@@ -314,33 +279,53 @@ var NoSuchModelError = class extends (_b11 = AISDKError, _a11 = symbol11, _b11)
|
|
|
314
279
|
return AISDKError.hasMarker(error, marker11);
|
|
315
280
|
}
|
|
316
281
|
};
|
|
317
|
-
var name11 = "
|
|
282
|
+
var name11 = "AI_NoSuchProviderReferenceError";
|
|
318
283
|
var marker12 = `vercel.ai.error.${name11}`;
|
|
319
284
|
var symbol12 = Symbol.for(marker12);
|
|
320
285
|
var _a12;
|
|
321
286
|
var _b12;
|
|
322
|
-
var
|
|
287
|
+
var NoSuchProviderReferenceError = class extends (_b12 = AISDKError, _a12 = symbol12, _b12) {
|
|
288
|
+
constructor({
|
|
289
|
+
provider,
|
|
290
|
+
reference,
|
|
291
|
+
message = `No provider reference found for provider '${provider}'. Available providers: ${Object.keys(reference).join(", ")}`
|
|
292
|
+
}) {
|
|
293
|
+
super({ name: name11, message });
|
|
294
|
+
this[_a12] = true;
|
|
295
|
+
this.provider = provider;
|
|
296
|
+
this.reference = reference;
|
|
297
|
+
}
|
|
298
|
+
static isInstance(error) {
|
|
299
|
+
return AISDKError.hasMarker(error, marker12);
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
var name12 = "AI_TooManyEmbeddingValuesForCallError";
|
|
303
|
+
var marker13 = `vercel.ai.error.${name12}`;
|
|
304
|
+
var symbol13 = Symbol.for(marker13);
|
|
305
|
+
var _a13;
|
|
306
|
+
var _b13;
|
|
307
|
+
var TooManyEmbeddingValuesForCallError = class extends (_b13 = AISDKError, _a13 = symbol13, _b13) {
|
|
323
308
|
constructor(options) {
|
|
324
309
|
super({
|
|
325
|
-
name:
|
|
310
|
+
name: name12,
|
|
326
311
|
message: `Too many values for a single embedding call. The ${options.provider} model "${options.modelId}" can only embed up to ${options.maxEmbeddingsPerCall} values per call, but ${options.values.length} values were provided.`
|
|
327
312
|
});
|
|
328
|
-
this[
|
|
313
|
+
this[_a13] = true;
|
|
329
314
|
this.provider = options.provider;
|
|
330
315
|
this.modelId = options.modelId;
|
|
331
316
|
this.maxEmbeddingsPerCall = options.maxEmbeddingsPerCall;
|
|
332
317
|
this.values = options.values;
|
|
333
318
|
}
|
|
334
319
|
static isInstance(error) {
|
|
335
|
-
return AISDKError.hasMarker(error,
|
|
320
|
+
return AISDKError.hasMarker(error, marker13);
|
|
336
321
|
}
|
|
337
322
|
};
|
|
338
|
-
var
|
|
339
|
-
var
|
|
340
|
-
var
|
|
341
|
-
var
|
|
342
|
-
var
|
|
343
|
-
var TypeValidationError = class _TypeValidationError extends (
|
|
323
|
+
var name13 = "AI_TypeValidationError";
|
|
324
|
+
var marker14 = `vercel.ai.error.${name13}`;
|
|
325
|
+
var symbol14 = Symbol.for(marker14);
|
|
326
|
+
var _a14;
|
|
327
|
+
var _b14;
|
|
328
|
+
var TypeValidationError = class _TypeValidationError extends (_b14 = AISDKError, _a14 = symbol14, _b14) {
|
|
344
329
|
constructor({
|
|
345
330
|
value,
|
|
346
331
|
cause,
|
|
@@ -363,17 +348,17 @@ var TypeValidationError = class _TypeValidationError extends (_b13 = AISDKError,
|
|
|
363
348
|
contextPrefix += ")";
|
|
364
349
|
}
|
|
365
350
|
super({
|
|
366
|
-
name:
|
|
351
|
+
name: name13,
|
|
367
352
|
message: `${contextPrefix}: Value: ${JSON.stringify(value)}.
|
|
368
353
|
Error message: ${getErrorMessage(cause)}`,
|
|
369
354
|
cause
|
|
370
355
|
});
|
|
371
|
-
this[
|
|
356
|
+
this[_a14] = true;
|
|
372
357
|
this.value = value;
|
|
373
358
|
this.context = context;
|
|
374
359
|
}
|
|
375
360
|
static isInstance(error) {
|
|
376
|
-
return AISDKError.hasMarker(error,
|
|
361
|
+
return AISDKError.hasMarker(error, marker14);
|
|
377
362
|
}
|
|
378
363
|
/**
|
|
379
364
|
* Wraps an error into a TypeValidationError.
|
|
@@ -391,84 +376,170 @@ Error message: ${getErrorMessage(cause)}`,
|
|
|
391
376
|
cause,
|
|
392
377
|
context
|
|
393
378
|
}) {
|
|
394
|
-
var
|
|
395
|
-
if (_TypeValidationError.isInstance(cause) && cause.value === value && ((
|
|
379
|
+
var _a162, _b162, _c;
|
|
380
|
+
if (_TypeValidationError.isInstance(cause) && cause.value === value && ((_a162 = cause.context) == null ? void 0 : _a162.field) === (context == null ? void 0 : context.field) && ((_b162 = cause.context) == null ? void 0 : _b162.entityName) === (context == null ? void 0 : context.entityName) && ((_c = cause.context) == null ? void 0 : _c.entityId) === (context == null ? void 0 : context.entityId)) {
|
|
396
381
|
return cause;
|
|
397
382
|
}
|
|
398
383
|
return new _TypeValidationError({ value, cause, context });
|
|
399
384
|
}
|
|
400
385
|
};
|
|
401
|
-
var
|
|
402
|
-
var
|
|
403
|
-
var
|
|
404
|
-
var
|
|
405
|
-
var
|
|
406
|
-
var UnsupportedFunctionalityError = class extends (
|
|
386
|
+
var name14 = "AI_UnsupportedFunctionalityError";
|
|
387
|
+
var marker15 = `vercel.ai.error.${name14}`;
|
|
388
|
+
var symbol15 = Symbol.for(marker15);
|
|
389
|
+
var _a15;
|
|
390
|
+
var _b15;
|
|
391
|
+
var UnsupportedFunctionalityError = class extends (_b15 = AISDKError, _a15 = symbol15, _b15) {
|
|
407
392
|
constructor({
|
|
408
393
|
functionality,
|
|
409
394
|
message = `'${functionality}' functionality not supported.`
|
|
410
395
|
}) {
|
|
411
|
-
super({ name:
|
|
412
|
-
this[
|
|
396
|
+
super({ name: name14, message });
|
|
397
|
+
this[_a15] = true;
|
|
413
398
|
this.functionality = functionality;
|
|
414
399
|
}
|
|
415
400
|
static isInstance(error) {
|
|
416
|
-
return AISDKError.hasMarker(error,
|
|
401
|
+
return AISDKError.hasMarker(error, marker15);
|
|
417
402
|
}
|
|
418
403
|
};
|
|
419
404
|
|
|
420
|
-
// node_modules/.pnpm/@ai-sdk+provider-utils@
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
405
|
+
// node_modules/.pnpm/@ai-sdk+provider-utils@5.0.0_zod@4.3.5/node_modules/@ai-sdk/provider-utils/dist/index.js
|
|
406
|
+
import * as z4 from "zod/v4";
|
|
407
|
+
import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind3 } from "zod/v3";
|
|
408
|
+
import { ZodFirstPartyTypeKind } from "zod/v3";
|
|
409
|
+
import {
|
|
410
|
+
ZodFirstPartyTypeKind as ZodFirstPartyTypeKind2
|
|
411
|
+
} from "zod/v3";
|
|
425
412
|
|
|
426
|
-
// node_modules/.pnpm/eventsource-parser@3.0
|
|
413
|
+
// node_modules/.pnpm/eventsource-parser@3.1.0/node_modules/eventsource-parser/dist/index.js
|
|
427
414
|
var ParseError = class extends Error {
|
|
428
415
|
constructor(message, options) {
|
|
429
416
|
super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
|
|
430
417
|
}
|
|
431
418
|
};
|
|
419
|
+
var LF = 10;
|
|
420
|
+
var CR = 13;
|
|
421
|
+
var SPACE = 32;
|
|
432
422
|
function noop(_arg) {
|
|
433
423
|
}
|
|
434
|
-
function createParser(
|
|
435
|
-
if (typeof
|
|
424
|
+
function createParser(config) {
|
|
425
|
+
if (typeof config == "function")
|
|
436
426
|
throw new TypeError(
|
|
437
|
-
"`
|
|
427
|
+
"`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?"
|
|
438
428
|
);
|
|
439
|
-
const { onEvent = noop, onError = noop, onRetry = noop, onComment } =
|
|
440
|
-
let
|
|
441
|
-
function feed(
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
429
|
+
const { onEvent = noop, onError = noop, onRetry = noop, onComment, maxBufferSize } = config, pendingFragments = [];
|
|
430
|
+
let pendingFragmentsLength = 0, isFirstChunk = true, id, data = "", dataLines = 0, eventType, terminated = false;
|
|
431
|
+
function feed(chunk) {
|
|
432
|
+
if (terminated)
|
|
433
|
+
throw new Error(
|
|
434
|
+
"Cannot feed parser: it was terminated after exceeding the configured max buffer size. Call `reset()` to resume parsing."
|
|
435
|
+
);
|
|
436
|
+
if (isFirstChunk && (isFirstChunk = false, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
|
|
437
|
+
const trailing2 = processLines(chunk);
|
|
438
|
+
trailing2 !== "" && (pendingFragments.push(trailing2), pendingFragmentsLength = trailing2.length), checkBufferSize();
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
if (chunk.indexOf(`
|
|
442
|
+
`) === -1 && chunk.indexOf("\r") === -1) {
|
|
443
|
+
pendingFragments.push(chunk), pendingFragmentsLength += chunk.length, checkBufferSize();
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
pendingFragments.push(chunk);
|
|
447
|
+
const input = pendingFragments.join("");
|
|
448
|
+
pendingFragments.length = 0, pendingFragmentsLength = 0;
|
|
449
|
+
const trailing = processLines(input);
|
|
450
|
+
trailing !== "" && (pendingFragments.push(trailing), pendingFragmentsLength = trailing.length), checkBufferSize();
|
|
451
|
+
}
|
|
452
|
+
function checkBufferSize() {
|
|
453
|
+
maxBufferSize !== void 0 && (pendingFragmentsLength + data.length <= maxBufferSize || (terminated = true, pendingFragments.length = 0, pendingFragmentsLength = 0, id = void 0, data = "", dataLines = 0, eventType = void 0, onError(
|
|
454
|
+
new ParseError(`Buffered data exceeded max buffer size of ${maxBufferSize} characters`, {
|
|
455
|
+
type: "max-buffer-size-exceeded"
|
|
456
|
+
})
|
|
457
|
+
)));
|
|
458
|
+
}
|
|
459
|
+
function processLines(chunk) {
|
|
460
|
+
let searchIndex = 0;
|
|
461
|
+
if (chunk.indexOf("\r") === -1) {
|
|
462
|
+
let lfIndex = chunk.indexOf(`
|
|
463
|
+
`, searchIndex);
|
|
464
|
+
for (; lfIndex !== -1; ) {
|
|
465
|
+
if (searchIndex === lfIndex) {
|
|
466
|
+
dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
|
|
467
|
+
`, searchIndex);
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
const firstCharCode = chunk.charCodeAt(searchIndex);
|
|
471
|
+
if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
|
|
472
|
+
const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
|
|
473
|
+
if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
|
|
474
|
+
onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
|
|
475
|
+
`, searchIndex);
|
|
476
|
+
continue;
|
|
477
|
+
}
|
|
478
|
+
data = dataLines === 0 ? value : `${data}
|
|
479
|
+
${value}`, dataLines++;
|
|
480
|
+
} else isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
|
|
481
|
+
chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6,
|
|
482
|
+
lfIndex
|
|
483
|
+
) || void 0 : parseLine(chunk, searchIndex, lfIndex);
|
|
484
|
+
searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
|
|
485
|
+
`, searchIndex);
|
|
486
|
+
}
|
|
487
|
+
return chunk.slice(searchIndex);
|
|
488
|
+
}
|
|
489
|
+
for (; searchIndex < chunk.length; ) {
|
|
490
|
+
const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
|
|
491
|
+
`, searchIndex);
|
|
492
|
+
let lineEnd = -1;
|
|
493
|
+
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)
|
|
494
|
+
break;
|
|
495
|
+
parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
|
|
496
|
+
}
|
|
497
|
+
return chunk.slice(searchIndex);
|
|
498
|
+
}
|
|
499
|
+
function parseLine(chunk, start, end) {
|
|
500
|
+
if (start === end) {
|
|
449
501
|
dispatchEvent();
|
|
450
502
|
return;
|
|
451
503
|
}
|
|
452
|
-
|
|
453
|
-
|
|
504
|
+
const firstCharCode = chunk.charCodeAt(start);
|
|
505
|
+
if (isDataPrefix(chunk, start, firstCharCode)) {
|
|
506
|
+
const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
|
|
507
|
+
data = dataLines === 0 ? value2 : `${data}
|
|
508
|
+
${value2}`, dataLines++;
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
if (isEventPrefix(chunk, start, firstCharCode)) {
|
|
512
|
+
eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
|
|
454
513
|
return;
|
|
455
514
|
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
515
|
+
if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
|
|
516
|
+
const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
|
|
517
|
+
id = value2.includes("\0") ? void 0 : value2;
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
if (firstCharCode === 58) {
|
|
521
|
+
if (onComment) {
|
|
522
|
+
const line2 = chunk.slice(start, end);
|
|
523
|
+
onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
|
|
524
|
+
}
|
|
460
525
|
return;
|
|
461
526
|
}
|
|
462
|
-
|
|
527
|
+
const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
|
|
528
|
+
if (fieldSeparatorIndex === -1) {
|
|
529
|
+
processField(line, "", line);
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
|
|
533
|
+
processField(field, value, line);
|
|
463
534
|
}
|
|
464
535
|
function processField(field, value, line) {
|
|
465
536
|
switch (field) {
|
|
466
537
|
case "event":
|
|
467
|
-
eventType = value;
|
|
538
|
+
eventType = value || void 0;
|
|
468
539
|
break;
|
|
469
540
|
case "data":
|
|
470
|
-
data = `${data}
|
|
471
|
-
|
|
541
|
+
data = dataLines === 0 ? value : `${data}
|
|
542
|
+
${value}`, dataLines++;
|
|
472
543
|
break;
|
|
473
544
|
case "id":
|
|
474
545
|
id = value.includes("\0") ? void 0 : value;
|
|
@@ -493,42 +564,31 @@ function createParser(callbacks) {
|
|
|
493
564
|
}
|
|
494
565
|
}
|
|
495
566
|
function dispatchEvent() {
|
|
496
|
-
|
|
567
|
+
dataLines > 0 && onEvent({
|
|
497
568
|
id,
|
|
498
|
-
event: eventType
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
data: data.endsWith(`
|
|
502
|
-
`) ? data.slice(0, -1) : data
|
|
503
|
-
}), id = void 0, data = "", eventType = "";
|
|
569
|
+
event: eventType,
|
|
570
|
+
data
|
|
571
|
+
}), id = void 0, data = "", dataLines = 0, eventType = void 0;
|
|
504
572
|
}
|
|
505
573
|
function reset(options = {}) {
|
|
506
|
-
|
|
574
|
+
if (options.consume && pendingFragments.length > 0) {
|
|
575
|
+
const incompleteLine = pendingFragments.join("");
|
|
576
|
+
parseLine(incompleteLine, 0, incompleteLine.length);
|
|
577
|
+
}
|
|
578
|
+
isFirstChunk = true, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0, pendingFragmentsLength = 0, terminated = false;
|
|
507
579
|
}
|
|
508
580
|
return { feed, reset };
|
|
509
581
|
}
|
|
510
|
-
function
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
`, searchIndex);
|
|
516
|
-
let lineEnd = -1;
|
|
517
|
-
if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
|
|
518
|
-
incompleteLine = chunk.slice(searchIndex);
|
|
519
|
-
break;
|
|
520
|
-
} else {
|
|
521
|
-
const line = chunk.slice(searchIndex, lineEnd);
|
|
522
|
-
lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
|
|
523
|
-
` && searchIndex++;
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
return [lines, incompleteLine];
|
|
582
|
+
function isDataPrefix(chunk, i, firstCharCode) {
|
|
583
|
+
return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
|
|
584
|
+
}
|
|
585
|
+
function isEventPrefix(chunk, i, firstCharCode) {
|
|
586
|
+
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;
|
|
527
587
|
}
|
|
528
588
|
|
|
529
|
-
// node_modules/.pnpm/eventsource-parser@3.0
|
|
589
|
+
// node_modules/.pnpm/eventsource-parser@3.1.0/node_modules/eventsource-parser/dist/stream.js
|
|
530
590
|
var EventSourceParserStream = class extends TransformStream {
|
|
531
|
-
constructor({ onError, onRetry, onComment } = {}) {
|
|
591
|
+
constructor({ onError, onRetry, onComment, maxBufferSize } = {}) {
|
|
532
592
|
let parser;
|
|
533
593
|
super({
|
|
534
594
|
start(controller) {
|
|
@@ -537,10 +597,11 @@ var EventSourceParserStream = class extends TransformStream {
|
|
|
537
597
|
controller.enqueue(event);
|
|
538
598
|
},
|
|
539
599
|
onError(error) {
|
|
540
|
-
onError
|
|
600
|
+
typeof onError == "function" && onError(error), (onError === "terminate" || error.type === "max-buffer-size-exceeded") && controller.error(error);
|
|
541
601
|
},
|
|
542
602
|
onRetry,
|
|
543
|
-
onComment
|
|
603
|
+
onComment,
|
|
604
|
+
maxBufferSize
|
|
544
605
|
});
|
|
545
606
|
},
|
|
546
607
|
transform(chunk) {
|
|
@@ -550,13 +611,25 @@ var EventSourceParserStream = class extends TransformStream {
|
|
|
550
611
|
}
|
|
551
612
|
};
|
|
552
613
|
|
|
553
|
-
// node_modules/.pnpm/@
|
|
614
|
+
// node_modules/.pnpm/@workflow+serde@4.1.0/node_modules/@workflow/serde/dist/index.js
|
|
615
|
+
var WORKFLOW_SERIALIZE = Symbol.for("workflow-serialize");
|
|
616
|
+
var WORKFLOW_DESERIALIZE = Symbol.for("workflow-deserialize");
|
|
617
|
+
|
|
618
|
+
// node_modules/.pnpm/@ai-sdk+provider-utils@5.0.0_zod@4.3.5/node_modules/@ai-sdk/provider-utils/dist/index.js
|
|
554
619
|
function combineHeaders(...headers) {
|
|
555
620
|
return headers.reduce(
|
|
556
621
|
(combinedHeaders, currentHeaders) => __spreadValues(__spreadValues({}, combinedHeaders), currentHeaders != null ? currentHeaders : {}),
|
|
557
622
|
{}
|
|
558
623
|
);
|
|
559
624
|
}
|
|
625
|
+
var { btoa, atob } = globalThis;
|
|
626
|
+
function convertUint8ArrayToBase64(array) {
|
|
627
|
+
let latin1string = "";
|
|
628
|
+
for (let i = 0; i < array.length; i++) {
|
|
629
|
+
latin1string += String.fromCodePoint(array[i]);
|
|
630
|
+
}
|
|
631
|
+
return btoa(latin1string);
|
|
632
|
+
}
|
|
560
633
|
async function delay(delayInMs, options) {
|
|
561
634
|
if (delayInMs == null) {
|
|
562
635
|
return Promise.resolve();
|
|
@@ -585,23 +658,12 @@ async function delay(delayInMs, options) {
|
|
|
585
658
|
function createAbortError() {
|
|
586
659
|
return new DOMException("Delay was aborted", "AbortError");
|
|
587
660
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
var
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
for (let i = 0; i < array.length; i++) {
|
|
595
|
-
latin1string += String.fromCodePoint(array[i]);
|
|
596
|
-
}
|
|
597
|
-
return btoa(latin1string);
|
|
598
|
-
}
|
|
599
|
-
var name14 = "AI_DownloadError";
|
|
600
|
-
var marker15 = `vercel.ai.error.${name14}`;
|
|
601
|
-
var symbol15 = Symbol.for(marker15);
|
|
602
|
-
var _a15;
|
|
603
|
-
var _b15;
|
|
604
|
-
var DownloadError = class extends (_b15 = AISDKError, _a15 = symbol15, _b15) {
|
|
661
|
+
var name15 = "AI_DownloadError";
|
|
662
|
+
var marker16 = `vercel.ai.error.${name15}`;
|
|
663
|
+
var symbol16 = Symbol.for(marker16);
|
|
664
|
+
var _a16;
|
|
665
|
+
var _b16;
|
|
666
|
+
var DownloadError = class extends (_b16 = AISDKError, _a16 = symbol16, _b16) {
|
|
605
667
|
constructor({
|
|
606
668
|
url,
|
|
607
669
|
statusCode,
|
|
@@ -609,17 +671,20 @@ var DownloadError = class extends (_b15 = AISDKError, _a15 = symbol15, _b15) {
|
|
|
609
671
|
cause,
|
|
610
672
|
message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}`
|
|
611
673
|
}) {
|
|
612
|
-
super({ name:
|
|
613
|
-
this[
|
|
674
|
+
super({ name: name15, message, cause });
|
|
675
|
+
this[_a16] = true;
|
|
614
676
|
this.url = url;
|
|
615
677
|
this.statusCode = statusCode;
|
|
616
678
|
this.statusText = statusText;
|
|
617
679
|
}
|
|
618
680
|
static isInstance(error) {
|
|
619
|
-
return AISDKError.hasMarker(error,
|
|
681
|
+
return AISDKError.hasMarker(error, marker16);
|
|
620
682
|
}
|
|
621
683
|
};
|
|
622
684
|
var DEFAULT_MAX_DOWNLOAD_SIZE = 2 * 1024 * 1024 * 1024;
|
|
685
|
+
function extractResponseHeaders(response) {
|
|
686
|
+
return Object.fromEntries([...response.headers]);
|
|
687
|
+
}
|
|
623
688
|
var createIdGenerator = ({
|
|
624
689
|
prefix,
|
|
625
690
|
size = 16,
|
|
@@ -748,7 +813,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
748
813
|
);
|
|
749
814
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
750
815
|
}
|
|
751
|
-
var VERSION = true ? "
|
|
816
|
+
var VERSION = true ? "5.0.0" : "0.0.0-test";
|
|
752
817
|
var getOriginalFetch = () => globalThis.fetch;
|
|
753
818
|
var getFromApi = async ({
|
|
754
819
|
url,
|
|
@@ -965,7 +1030,7 @@ function parseArrayDef(def, refs) {
|
|
|
965
1030
|
const res = {
|
|
966
1031
|
type: "array"
|
|
967
1032
|
};
|
|
968
|
-
if (((_a22 = def.type) == null ? void 0 : _a22._def) && ((_c = (_b22 = def.type) == null ? void 0 : _b22._def) == null ? void 0 : _c.typeName) !==
|
|
1033
|
+
if (((_a22 = def.type) == null ? void 0 : _a22._def) && ((_c = (_b22 = def.type) == null ? void 0 : _b22._def) == null ? void 0 : _c.typeName) !== ZodFirstPartyTypeKind.ZodAny) {
|
|
969
1034
|
res.items = parseDef(def.type._def, __spreadProps(__spreadValues({}, refs), {
|
|
970
1035
|
currentPath: [...refs.currentPath, "items"]
|
|
971
1036
|
}));
|
|
@@ -1024,7 +1089,7 @@ function parseDateDef(def, refs, overrideDateStrategy) {
|
|
|
1024
1089
|
const strategy = overrideDateStrategy != null ? overrideDateStrategy : refs.dateStrategy;
|
|
1025
1090
|
if (Array.isArray(strategy)) {
|
|
1026
1091
|
return {
|
|
1027
|
-
anyOf: strategy.map((item
|
|
1092
|
+
anyOf: strategy.map((item) => parseDateDef(def, refs, item))
|
|
1028
1093
|
};
|
|
1029
1094
|
}
|
|
1030
1095
|
switch (strategy) {
|
|
@@ -1094,7 +1159,7 @@ function parseIntersectionDef(def, refs) {
|
|
|
1094
1159
|
} else {
|
|
1095
1160
|
let nestedSchema = schema;
|
|
1096
1161
|
if ("additionalProperties" in schema && schema.additionalProperties === false) {
|
|
1097
|
-
const
|
|
1162
|
+
const _a17 = schema, { additionalProperties: _additionalProperties } = _a17, rest = __objRest(_a17, ["additionalProperties"]);
|
|
1098
1163
|
nestedSchema = rest;
|
|
1099
1164
|
}
|
|
1100
1165
|
mergedAllOf.push(nestedSchema);
|
|
@@ -1454,22 +1519,22 @@ function parseRecordDef(def, refs) {
|
|
|
1454
1519
|
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1455
1520
|
}))) != null ? _a22 : refs.allowedAdditionalProperties
|
|
1456
1521
|
};
|
|
1457
|
-
if (((_b22 = def.keyType) == null ? void 0 : _b22._def.typeName) ===
|
|
1458
|
-
const
|
|
1522
|
+
if (((_b22 = def.keyType) == null ? void 0 : _b22._def.typeName) === ZodFirstPartyTypeKind2.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
|
|
1523
|
+
const _a17 = parseStringDef(def.keyType._def, refs), { type: _type } = _a17, keyType = __objRest(_a17, ["type"]);
|
|
1459
1524
|
return __spreadProps(__spreadValues({}, schema), {
|
|
1460
1525
|
propertyNames: keyType
|
|
1461
1526
|
});
|
|
1462
|
-
} else if (((_d = def.keyType) == null ? void 0 : _d._def.typeName) ===
|
|
1527
|
+
} else if (((_d = def.keyType) == null ? void 0 : _d._def.typeName) === ZodFirstPartyTypeKind2.ZodEnum) {
|
|
1463
1528
|
return __spreadProps(__spreadValues({}, schema), {
|
|
1464
1529
|
propertyNames: {
|
|
1465
1530
|
enum: def.keyType._def.values
|
|
1466
1531
|
}
|
|
1467
1532
|
});
|
|
1468
|
-
} else if (((_e = def.keyType) == null ? void 0 : _e._def.typeName) ===
|
|
1469
|
-
const
|
|
1533
|
+
} else if (((_e = def.keyType) == null ? void 0 : _e._def.typeName) === ZodFirstPartyTypeKind2.ZodBranded && def.keyType._def.type._def.typeName === ZodFirstPartyTypeKind2.ZodString && ((_f = def.keyType._def.type._def.checks) == null ? void 0 : _f.length)) {
|
|
1534
|
+
const _b17 = parseBrandedDef(
|
|
1470
1535
|
def.keyType._def,
|
|
1471
1536
|
refs
|
|
1472
|
-
), { type } =
|
|
1537
|
+
), { type: _type } = _b17, keyType = __objRest(_b17, ["type"]);
|
|
1473
1538
|
return __spreadProps(__spreadValues({}, schema), {
|
|
1474
1539
|
propertyNames: keyType
|
|
1475
1540
|
});
|
|
@@ -1715,14 +1780,16 @@ var parsePipelineDef = (def, refs) => {
|
|
|
1715
1780
|
} else if (refs.pipeStrategy === "output") {
|
|
1716
1781
|
return parseDef(def.out._def, refs);
|
|
1717
1782
|
}
|
|
1718
|
-
const
|
|
1783
|
+
const inputSchema = parseDef(def.in._def, __spreadProps(__spreadValues({}, refs), {
|
|
1719
1784
|
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
1720
1785
|
}));
|
|
1721
|
-
const
|
|
1722
|
-
currentPath: [...refs.currentPath, "allOf",
|
|
1786
|
+
const outputSchema = parseDef(def.out._def, __spreadProps(__spreadValues({}, refs), {
|
|
1787
|
+
currentPath: [...refs.currentPath, "allOf", inputSchema ? "1" : "0"]
|
|
1723
1788
|
}));
|
|
1724
1789
|
return {
|
|
1725
|
-
allOf: [
|
|
1790
|
+
allOf: [inputSchema, outputSchema].filter(
|
|
1791
|
+
(schema) => schema !== void 0
|
|
1792
|
+
)
|
|
1726
1793
|
};
|
|
1727
1794
|
};
|
|
1728
1795
|
function parsePromiseDef(def, refs) {
|
|
@@ -1791,73 +1858,73 @@ var parseReadonlyDef = (def, refs) => {
|
|
|
1791
1858
|
};
|
|
1792
1859
|
var selectParser = (def, typeName, refs) => {
|
|
1793
1860
|
switch (typeName) {
|
|
1794
|
-
case
|
|
1861
|
+
case ZodFirstPartyTypeKind3.ZodString:
|
|
1795
1862
|
return parseStringDef(def, refs);
|
|
1796
|
-
case
|
|
1863
|
+
case ZodFirstPartyTypeKind3.ZodNumber:
|
|
1797
1864
|
return parseNumberDef(def);
|
|
1798
|
-
case
|
|
1865
|
+
case ZodFirstPartyTypeKind3.ZodObject:
|
|
1799
1866
|
return parseObjectDef(def, refs);
|
|
1800
|
-
case
|
|
1867
|
+
case ZodFirstPartyTypeKind3.ZodBigInt:
|
|
1801
1868
|
return parseBigintDef(def);
|
|
1802
|
-
case
|
|
1869
|
+
case ZodFirstPartyTypeKind3.ZodBoolean:
|
|
1803
1870
|
return parseBooleanDef();
|
|
1804
|
-
case
|
|
1871
|
+
case ZodFirstPartyTypeKind3.ZodDate:
|
|
1805
1872
|
return parseDateDef(def, refs);
|
|
1806
|
-
case
|
|
1873
|
+
case ZodFirstPartyTypeKind3.ZodUndefined:
|
|
1807
1874
|
return parseUndefinedDef();
|
|
1808
|
-
case
|
|
1875
|
+
case ZodFirstPartyTypeKind3.ZodNull:
|
|
1809
1876
|
return parseNullDef();
|
|
1810
|
-
case
|
|
1877
|
+
case ZodFirstPartyTypeKind3.ZodArray:
|
|
1811
1878
|
return parseArrayDef(def, refs);
|
|
1812
|
-
case
|
|
1813
|
-
case
|
|
1879
|
+
case ZodFirstPartyTypeKind3.ZodUnion:
|
|
1880
|
+
case ZodFirstPartyTypeKind3.ZodDiscriminatedUnion:
|
|
1814
1881
|
return parseUnionDef(def, refs);
|
|
1815
|
-
case
|
|
1882
|
+
case ZodFirstPartyTypeKind3.ZodIntersection:
|
|
1816
1883
|
return parseIntersectionDef(def, refs);
|
|
1817
|
-
case
|
|
1884
|
+
case ZodFirstPartyTypeKind3.ZodTuple:
|
|
1818
1885
|
return parseTupleDef(def, refs);
|
|
1819
|
-
case
|
|
1886
|
+
case ZodFirstPartyTypeKind3.ZodRecord:
|
|
1820
1887
|
return parseRecordDef(def, refs);
|
|
1821
|
-
case
|
|
1888
|
+
case ZodFirstPartyTypeKind3.ZodLiteral:
|
|
1822
1889
|
return parseLiteralDef(def);
|
|
1823
|
-
case
|
|
1890
|
+
case ZodFirstPartyTypeKind3.ZodEnum:
|
|
1824
1891
|
return parseEnumDef(def);
|
|
1825
|
-
case
|
|
1892
|
+
case ZodFirstPartyTypeKind3.ZodNativeEnum:
|
|
1826
1893
|
return parseNativeEnumDef(def);
|
|
1827
|
-
case
|
|
1894
|
+
case ZodFirstPartyTypeKind3.ZodNullable:
|
|
1828
1895
|
return parseNullableDef(def, refs);
|
|
1829
|
-
case
|
|
1896
|
+
case ZodFirstPartyTypeKind3.ZodOptional:
|
|
1830
1897
|
return parseOptionalDef(def, refs);
|
|
1831
|
-
case
|
|
1898
|
+
case ZodFirstPartyTypeKind3.ZodMap:
|
|
1832
1899
|
return parseMapDef(def, refs);
|
|
1833
|
-
case
|
|
1900
|
+
case ZodFirstPartyTypeKind3.ZodSet:
|
|
1834
1901
|
return parseSetDef(def, refs);
|
|
1835
|
-
case
|
|
1902
|
+
case ZodFirstPartyTypeKind3.ZodLazy:
|
|
1836
1903
|
return () => def.getter()._def;
|
|
1837
|
-
case
|
|
1904
|
+
case ZodFirstPartyTypeKind3.ZodPromise:
|
|
1838
1905
|
return parsePromiseDef(def, refs);
|
|
1839
|
-
case
|
|
1840
|
-
case
|
|
1906
|
+
case ZodFirstPartyTypeKind3.ZodNaN:
|
|
1907
|
+
case ZodFirstPartyTypeKind3.ZodNever:
|
|
1841
1908
|
return parseNeverDef();
|
|
1842
|
-
case
|
|
1909
|
+
case ZodFirstPartyTypeKind3.ZodEffects:
|
|
1843
1910
|
return parseEffectsDef(def, refs);
|
|
1844
|
-
case
|
|
1911
|
+
case ZodFirstPartyTypeKind3.ZodAny:
|
|
1845
1912
|
return parseAnyDef();
|
|
1846
|
-
case
|
|
1913
|
+
case ZodFirstPartyTypeKind3.ZodUnknown:
|
|
1847
1914
|
return parseUnknownDef();
|
|
1848
|
-
case
|
|
1915
|
+
case ZodFirstPartyTypeKind3.ZodDefault:
|
|
1849
1916
|
return parseDefaultDef(def, refs);
|
|
1850
|
-
case
|
|
1917
|
+
case ZodFirstPartyTypeKind3.ZodBranded:
|
|
1851
1918
|
return parseBrandedDef(def, refs);
|
|
1852
|
-
case
|
|
1919
|
+
case ZodFirstPartyTypeKind3.ZodReadonly:
|
|
1853
1920
|
return parseReadonlyDef(def, refs);
|
|
1854
|
-
case
|
|
1921
|
+
case ZodFirstPartyTypeKind3.ZodCatch:
|
|
1855
1922
|
return parseCatchDef(def, refs);
|
|
1856
|
-
case
|
|
1923
|
+
case ZodFirstPartyTypeKind3.ZodPipeline:
|
|
1857
1924
|
return parsePipelineDef(def, refs);
|
|
1858
|
-
case
|
|
1859
|
-
case
|
|
1860
|
-
case
|
|
1925
|
+
case ZodFirstPartyTypeKind3.ZodFunction:
|
|
1926
|
+
case ZodFirstPartyTypeKind3.ZodVoid:
|
|
1927
|
+
case ZodFirstPartyTypeKind3.ZodSymbol:
|
|
1861
1928
|
return void 0;
|
|
1862
1929
|
default:
|
|
1863
1930
|
return /* @__PURE__ */ ((_) => void 0)(typeName);
|
|
@@ -2017,7 +2084,11 @@ function isSchema(value) {
|
|
|
2017
2084
|
return typeof value === "object" && value !== null && schemaSymbol in value && value[schemaSymbol] === true && "jsonSchema" in value && "validate" in value;
|
|
2018
2085
|
}
|
|
2019
2086
|
function asSchema(schema) {
|
|
2020
|
-
return schema == null ? jsonSchema({
|
|
2087
|
+
return schema == null ? jsonSchema({
|
|
2088
|
+
type: "object",
|
|
2089
|
+
properties: {},
|
|
2090
|
+
additionalProperties: false
|
|
2091
|
+
}) : isSchema(schema) ? schema : "~standard" in schema ? schema["~standard"].vendor === "zod" ? zodSchema(schema) : standardSchema(schema) : schema();
|
|
2021
2092
|
}
|
|
2022
2093
|
function standardSchema(standardSchema2) {
|
|
2023
2094
|
return jsonSchema(
|
|
@@ -2133,7 +2204,7 @@ async function parseJSON({
|
|
|
2133
2204
|
if (schema == null) {
|
|
2134
2205
|
return value;
|
|
2135
2206
|
}
|
|
2136
|
-
return validateTypes({ value, schema });
|
|
2207
|
+
return await validateTypes({ value, schema });
|
|
2137
2208
|
} catch (error) {
|
|
2138
2209
|
if (JSONParseError.isInstance(error) || TypeValidationError.isInstance(error)) {
|
|
2139
2210
|
throw error;
|
|
@@ -2191,7 +2262,7 @@ var postJsonToApi = async ({
|
|
|
2191
2262
|
successfulResponseHandler,
|
|
2192
2263
|
abortSignal,
|
|
2193
2264
|
fetch: fetch2
|
|
2194
|
-
}) => postToApi({
|
|
2265
|
+
}) => await postToApi({
|
|
2195
2266
|
url,
|
|
2196
2267
|
headers: __spreadValues({
|
|
2197
2268
|
"Content-Type": "application/json"
|
|
@@ -2277,12 +2348,12 @@ var postToApi = async ({
|
|
|
2277
2348
|
function tool(tool2) {
|
|
2278
2349
|
return tool2;
|
|
2279
2350
|
}
|
|
2280
|
-
function
|
|
2351
|
+
function createProviderDefinedToolFactory({
|
|
2281
2352
|
id,
|
|
2282
2353
|
inputSchema
|
|
2283
2354
|
}) {
|
|
2284
|
-
return (
|
|
2285
|
-
var
|
|
2355
|
+
return (_a17) => {
|
|
2356
|
+
var _b17 = _a17, {
|
|
2286
2357
|
execute,
|
|
2287
2358
|
outputSchema,
|
|
2288
2359
|
needsApproval,
|
|
@@ -2290,7 +2361,7 @@ function createProviderToolFactory({
|
|
|
2290
2361
|
onInputStart,
|
|
2291
2362
|
onInputDelta,
|
|
2292
2363
|
onInputAvailable
|
|
2293
|
-
} =
|
|
2364
|
+
} = _b17, args = __objRest(_b17, [
|
|
2294
2365
|
"execute",
|
|
2295
2366
|
"outputSchema",
|
|
2296
2367
|
"needsApproval",
|
|
@@ -2301,6 +2372,7 @@ function createProviderToolFactory({
|
|
|
2301
2372
|
]);
|
|
2302
2373
|
return tool({
|
|
2303
2374
|
type: "provider",
|
|
2375
|
+
isProviderExecuted: false,
|
|
2304
2376
|
id,
|
|
2305
2377
|
args,
|
|
2306
2378
|
inputSchema,
|
|
@@ -2353,7 +2425,7 @@ var createJsonErrorResponseHandler = ({
|
|
|
2353
2425
|
isRetryable: isRetryable == null ? void 0 : isRetryable(response, parsedError)
|
|
2354
2426
|
})
|
|
2355
2427
|
};
|
|
2356
|
-
} catch (
|
|
2428
|
+
} catch (e) {
|
|
2357
2429
|
return {
|
|
2358
2430
|
responseHeaders,
|
|
2359
2431
|
value: new APICallError({
|
|
@@ -2410,7 +2482,7 @@ function withoutTrailingSlash(url) {
|
|
|
2410
2482
|
}
|
|
2411
2483
|
|
|
2412
2484
|
// src/schemas/reasoning-details.ts
|
|
2413
|
-
|
|
2485
|
+
import { z } from "zod/v4";
|
|
2414
2486
|
|
|
2415
2487
|
// src/utils/type-guards.ts
|
|
2416
2488
|
function isDefinedOrNotNull(value) {
|
|
@@ -2430,63 +2502,63 @@ var ReasoningFormat = /* @__PURE__ */ ((ReasoningFormat2) => {
|
|
|
2430
2502
|
var DEFAULT_REASONING_FORMAT = "anthropic-claude-v1" /* AnthropicClaudeV1 */;
|
|
2431
2503
|
|
|
2432
2504
|
// src/schemas/reasoning-details.ts
|
|
2433
|
-
var CommonReasoningDetailSchema =
|
|
2434
|
-
id:
|
|
2435
|
-
format:
|
|
2436
|
-
index:
|
|
2505
|
+
var CommonReasoningDetailSchema = z.object({
|
|
2506
|
+
id: z.string().nullish(),
|
|
2507
|
+
format: z.enum(ReasoningFormat).nullish(),
|
|
2508
|
+
index: z.number().optional()
|
|
2437
2509
|
}).loose();
|
|
2438
|
-
var ReasoningDetailSummarySchema =
|
|
2439
|
-
type:
|
|
2440
|
-
summary:
|
|
2510
|
+
var ReasoningDetailSummarySchema = z.object({
|
|
2511
|
+
type: z.literal("reasoning.summary" /* Summary */),
|
|
2512
|
+
summary: z.string()
|
|
2441
2513
|
}).extend(CommonReasoningDetailSchema.shape);
|
|
2442
|
-
var ReasoningDetailEncryptedSchema =
|
|
2443
|
-
type:
|
|
2444
|
-
data:
|
|
2514
|
+
var ReasoningDetailEncryptedSchema = z.object({
|
|
2515
|
+
type: z.literal("reasoning.encrypted" /* Encrypted */),
|
|
2516
|
+
data: z.string()
|
|
2445
2517
|
}).extend(CommonReasoningDetailSchema.shape);
|
|
2446
|
-
var ReasoningDetailTextSchema =
|
|
2447
|
-
type:
|
|
2448
|
-
text:
|
|
2449
|
-
signature:
|
|
2518
|
+
var ReasoningDetailTextSchema = z.object({
|
|
2519
|
+
type: z.literal("reasoning.text" /* Text */),
|
|
2520
|
+
text: z.string().nullish(),
|
|
2521
|
+
signature: z.string().nullish()
|
|
2450
2522
|
}).extend(CommonReasoningDetailSchema.shape);
|
|
2451
|
-
var ReasoningDetailUnionSchema =
|
|
2523
|
+
var ReasoningDetailUnionSchema = z.union([
|
|
2452
2524
|
ReasoningDetailSummarySchema,
|
|
2453
2525
|
ReasoningDetailEncryptedSchema,
|
|
2454
2526
|
ReasoningDetailTextSchema
|
|
2455
2527
|
]);
|
|
2456
|
-
var ReasoningDetailsWithUnknownSchema =
|
|
2528
|
+
var ReasoningDetailsWithUnknownSchema = z.union([
|
|
2457
2529
|
ReasoningDetailUnionSchema,
|
|
2458
|
-
|
|
2530
|
+
z.unknown().transform(() => null)
|
|
2459
2531
|
]);
|
|
2460
|
-
var ReasoningDetailArraySchema =
|
|
2461
|
-
var OutputUnionToReasoningDetailsSchema =
|
|
2462
|
-
|
|
2463
|
-
delta:
|
|
2464
|
-
reasoning_details:
|
|
2532
|
+
var ReasoningDetailArraySchema = z.array(ReasoningDetailsWithUnknownSchema).transform((d) => d.filter((d2) => !!d2));
|
|
2533
|
+
var OutputUnionToReasoningDetailsSchema = z.union([
|
|
2534
|
+
z.object({
|
|
2535
|
+
delta: z.object({
|
|
2536
|
+
reasoning_details: z.array(ReasoningDetailsWithUnknownSchema)
|
|
2465
2537
|
})
|
|
2466
2538
|
}).transform(
|
|
2467
2539
|
(data) => data.delta.reasoning_details.filter(isDefinedOrNotNull)
|
|
2468
2540
|
),
|
|
2469
|
-
|
|
2470
|
-
message:
|
|
2471
|
-
reasoning_details:
|
|
2541
|
+
z.object({
|
|
2542
|
+
message: z.object({
|
|
2543
|
+
reasoning_details: z.array(ReasoningDetailsWithUnknownSchema)
|
|
2472
2544
|
})
|
|
2473
2545
|
}).transform(
|
|
2474
2546
|
(data) => data.message.reasoning_details.filter(isDefinedOrNotNull)
|
|
2475
2547
|
),
|
|
2476
|
-
|
|
2477
|
-
text:
|
|
2478
|
-
reasoning_details:
|
|
2548
|
+
z.object({
|
|
2549
|
+
text: z.string(),
|
|
2550
|
+
reasoning_details: z.array(ReasoningDetailsWithUnknownSchema)
|
|
2479
2551
|
}).transform((data) => data.reasoning_details.filter(isDefinedOrNotNull))
|
|
2480
2552
|
]);
|
|
2481
2553
|
|
|
2482
2554
|
// src/schemas/error-response.ts
|
|
2483
|
-
|
|
2484
|
-
var OpenRouterErrorResponseSchema =
|
|
2485
|
-
error:
|
|
2486
|
-
code:
|
|
2487
|
-
message:
|
|
2488
|
-
type:
|
|
2489
|
-
param:
|
|
2555
|
+
import { z as z2 } from "zod/v4";
|
|
2556
|
+
var OpenRouterErrorResponseSchema = z2.object({
|
|
2557
|
+
error: z2.object({
|
|
2558
|
+
code: z2.union([z2.string(), z2.number()]).nullable().optional().default(null),
|
|
2559
|
+
message: z2.string(),
|
|
2560
|
+
type: z2.string().nullable().optional().default(null),
|
|
2561
|
+
param: z2.any().nullable().optional().default(null)
|
|
2490
2562
|
}).passthrough()
|
|
2491
2563
|
}).passthrough();
|
|
2492
2564
|
function extractErrorMessage(data) {
|
|
@@ -2544,56 +2616,56 @@ var openrouterFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
2544
2616
|
});
|
|
2545
2617
|
|
|
2546
2618
|
// src/schemas/provider-metadata.ts
|
|
2547
|
-
|
|
2548
|
-
var FileAnnotationSchema =
|
|
2549
|
-
type:
|
|
2550
|
-
file:
|
|
2551
|
-
hash:
|
|
2552
|
-
name:
|
|
2553
|
-
content:
|
|
2554
|
-
|
|
2555
|
-
type:
|
|
2556
|
-
text:
|
|
2557
|
-
}).catchall(
|
|
2619
|
+
import { z as z3 } from "zod/v4";
|
|
2620
|
+
var FileAnnotationSchema = z3.object({
|
|
2621
|
+
type: z3.literal("file"),
|
|
2622
|
+
file: z3.object({
|
|
2623
|
+
hash: z3.string(),
|
|
2624
|
+
name: z3.string(),
|
|
2625
|
+
content: z3.array(
|
|
2626
|
+
z3.object({
|
|
2627
|
+
type: z3.string(),
|
|
2628
|
+
text: z3.string().optional()
|
|
2629
|
+
}).catchall(z3.any())
|
|
2558
2630
|
).optional()
|
|
2559
|
-
}).catchall(
|
|
2560
|
-
}).catchall(
|
|
2561
|
-
var OpenRouterProviderMetadataSchema =
|
|
2562
|
-
provider:
|
|
2563
|
-
reasoning_details:
|
|
2564
|
-
annotations:
|
|
2565
|
-
usage:
|
|
2566
|
-
promptTokens:
|
|
2567
|
-
promptTokensDetails:
|
|
2568
|
-
cachedTokens:
|
|
2569
|
-
}).catchall(
|
|
2570
|
-
completionTokens:
|
|
2571
|
-
completionTokensDetails:
|
|
2572
|
-
reasoningTokens:
|
|
2573
|
-
}).catchall(
|
|
2574
|
-
totalTokens:
|
|
2575
|
-
cost:
|
|
2576
|
-
costDetails:
|
|
2577
|
-
upstreamInferenceCost:
|
|
2578
|
-
}).catchall(
|
|
2579
|
-
}).catchall(
|
|
2580
|
-
}).catchall(
|
|
2581
|
-
var OpenRouterProviderOptionsSchema =
|
|
2582
|
-
openrouter:
|
|
2631
|
+
}).catchall(z3.any())
|
|
2632
|
+
}).catchall(z3.any());
|
|
2633
|
+
var OpenRouterProviderMetadataSchema = z3.object({
|
|
2634
|
+
provider: z3.string(),
|
|
2635
|
+
reasoning_details: z3.array(ReasoningDetailUnionSchema).optional(),
|
|
2636
|
+
annotations: z3.array(FileAnnotationSchema).optional(),
|
|
2637
|
+
usage: z3.object({
|
|
2638
|
+
promptTokens: z3.number(),
|
|
2639
|
+
promptTokensDetails: z3.object({
|
|
2640
|
+
cachedTokens: z3.number()
|
|
2641
|
+
}).catchall(z3.any()).optional(),
|
|
2642
|
+
completionTokens: z3.number(),
|
|
2643
|
+
completionTokensDetails: z3.object({
|
|
2644
|
+
reasoningTokens: z3.number()
|
|
2645
|
+
}).catchall(z3.any()).optional(),
|
|
2646
|
+
totalTokens: z3.number(),
|
|
2647
|
+
cost: z3.number().optional(),
|
|
2648
|
+
costDetails: z3.object({
|
|
2649
|
+
upstreamInferenceCost: z3.number()
|
|
2650
|
+
}).catchall(z3.any()).optional()
|
|
2651
|
+
}).catchall(z3.any())
|
|
2652
|
+
}).catchall(z3.any());
|
|
2653
|
+
var OpenRouterProviderOptionsSchema = z3.object({
|
|
2654
|
+
openrouter: z3.object({
|
|
2583
2655
|
// Use ReasoningDetailArraySchema (with unknown fallback) instead of
|
|
2584
2656
|
// z.array(ReasoningDetailUnionSchema) so that a single malformed entry
|
|
2585
2657
|
// (e.g., a future format not yet in the enum) is individually dropped
|
|
2586
2658
|
// rather than causing the entire array to fail parsing.
|
|
2587
2659
|
reasoning_details: ReasoningDetailArraySchema.optional(),
|
|
2588
|
-
annotations:
|
|
2660
|
+
annotations: z3.array(FileAnnotationSchema).optional()
|
|
2589
2661
|
}).optional()
|
|
2590
2662
|
}).optional();
|
|
2591
2663
|
|
|
2592
2664
|
// src/utils/compute-token-usage.ts
|
|
2593
2665
|
function computeTokenUsage(usage) {
|
|
2594
|
-
var
|
|
2595
|
-
const promptTokens = (
|
|
2596
|
-
const completionTokens = (
|
|
2666
|
+
var _a17, _b17, _c, _d, _e, _f, _g, _h;
|
|
2667
|
+
const promptTokens = (_a17 = usage.prompt_tokens) != null ? _a17 : 0;
|
|
2668
|
+
const completionTokens = (_b17 = usage.completion_tokens) != null ? _b17 : 0;
|
|
2597
2669
|
const cacheReadTokens = (_d = (_c = usage.prompt_tokens_details) == null ? void 0 : _c.cached_tokens) != null ? _d : 0;
|
|
2598
2670
|
const cacheWriteTokens = (_f = (_e = usage.prompt_tokens_details) == null ? void 0 : _e.cache_write_tokens) != null ? _f : void 0;
|
|
2599
2671
|
const reasoningTokens = (_h = (_g = usage.completion_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : 0;
|
|
@@ -2800,17 +2872,60 @@ function getFileUrl({
|
|
|
2800
2872
|
part,
|
|
2801
2873
|
defaultMediaType
|
|
2802
2874
|
}) {
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
data,
|
|
2875
|
+
return getFileDataUrl({
|
|
2876
|
+
data: part.data,
|
|
2806
2877
|
mediaType: part.mediaType,
|
|
2807
2878
|
defaultMediaType
|
|
2808
2879
|
});
|
|
2809
2880
|
}
|
|
2881
|
+
function getFileDataUrl({
|
|
2882
|
+
data,
|
|
2883
|
+
mediaType,
|
|
2884
|
+
defaultMediaType
|
|
2885
|
+
}) {
|
|
2886
|
+
switch (data.type) {
|
|
2887
|
+
case "data":
|
|
2888
|
+
return buildFileDataUrl({
|
|
2889
|
+
data: data.data,
|
|
2890
|
+
mediaType,
|
|
2891
|
+
defaultMediaType
|
|
2892
|
+
});
|
|
2893
|
+
case "url": {
|
|
2894
|
+
const url = data.url.toString();
|
|
2895
|
+
if (url.startsWith("data:") || isUrl({
|
|
2896
|
+
url,
|
|
2897
|
+
protocols: /* @__PURE__ */ new Set(["http:", "https:"])
|
|
2898
|
+
})) {
|
|
2899
|
+
return url;
|
|
2900
|
+
}
|
|
2901
|
+
throw new Error(
|
|
2902
|
+
"Only http(s) and data: file URLs are supported by OpenRouter"
|
|
2903
|
+
);
|
|
2904
|
+
}
|
|
2905
|
+
case "text": {
|
|
2906
|
+
const encoded = new TextEncoder().encode(data.text);
|
|
2907
|
+
return buildFileDataUrl({
|
|
2908
|
+
data: encoded,
|
|
2909
|
+
mediaType: mediaType != null ? mediaType : "text/plain",
|
|
2910
|
+
defaultMediaType
|
|
2911
|
+
});
|
|
2912
|
+
}
|
|
2913
|
+
case "reference":
|
|
2914
|
+
throw new Error(
|
|
2915
|
+
"Provider file references are not supported by OpenRouter"
|
|
2916
|
+
);
|
|
2917
|
+
}
|
|
2918
|
+
const _exhaustiveCheck = data;
|
|
2919
|
+
return buildFileDataUrl({
|
|
2920
|
+
data: _exhaustiveCheck,
|
|
2921
|
+
mediaType,
|
|
2922
|
+
defaultMediaType
|
|
2923
|
+
});
|
|
2924
|
+
}
|
|
2810
2925
|
function getMediaType(dataUrl, defaultMediaType) {
|
|
2811
|
-
var
|
|
2926
|
+
var _a17;
|
|
2812
2927
|
const match = dataUrl.match(/^data:([^;]+)/);
|
|
2813
|
-
return match ? (
|
|
2928
|
+
return match ? (_a17 = match[1]) != null ? _a17 : defaultMediaType : defaultMediaType;
|
|
2814
2929
|
}
|
|
2815
2930
|
function getBase64FromDataUrl(dataUrl) {
|
|
2816
2931
|
const match = dataUrl.match(/^data:[^;]*;base64,(.+)$/);
|
|
@@ -2885,13 +3000,13 @@ Learn more: https://openrouter.ai/docs/features/multimodal/audio`
|
|
|
2885
3000
|
|
|
2886
3001
|
// src/chat/convert-to-openrouter-chat-messages.ts
|
|
2887
3002
|
function getCacheControl(providerMetadata) {
|
|
2888
|
-
var
|
|
3003
|
+
var _a17, _b17, _c;
|
|
2889
3004
|
const anthropic = providerMetadata == null ? void 0 : providerMetadata.anthropic;
|
|
2890
3005
|
const openrouter2 = providerMetadata == null ? void 0 : providerMetadata.openrouter;
|
|
2891
|
-
return (_c = (
|
|
3006
|
+
return (_c = (_b17 = (_a17 = openrouter2 == null ? void 0 : openrouter2.cacheControl) != null ? _a17 : openrouter2 == null ? void 0 : openrouter2.cache_control) != null ? _b17 : anthropic == null ? void 0 : anthropic.cacheControl) != null ? _c : anthropic == null ? void 0 : anthropic.cache_control;
|
|
2892
3007
|
}
|
|
2893
3008
|
function convertToOpenRouterChatMessages(prompt) {
|
|
2894
|
-
var
|
|
3009
|
+
var _a17, _b17, _c, _d, _e, _f, _g, _h;
|
|
2895
3010
|
const messages = [];
|
|
2896
3011
|
const reasoningDetailsTracker = new ReasoningDetailsDuplicateTracker();
|
|
2897
3012
|
for (const { role, content, providerOptions } of prompt) {
|
|
@@ -2910,8 +3025,8 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
2910
3025
|
break;
|
|
2911
3026
|
}
|
|
2912
3027
|
case "user": {
|
|
2913
|
-
if (content.length === 1 && ((
|
|
2914
|
-
const cacheControl = (
|
|
3028
|
+
if (content.length === 1 && ((_a17 = content[0]) == null ? void 0 : _a17.type) === "text") {
|
|
3029
|
+
const cacheControl = (_b17 = getCacheControl(providerOptions)) != null ? _b17 : getCacheControl(content[0].providerOptions);
|
|
2915
3030
|
const contentWithCacheControl = cacheControl ? [
|
|
2916
3031
|
{
|
|
2917
3032
|
type: "text",
|
|
@@ -2935,7 +3050,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
2935
3050
|
}
|
|
2936
3051
|
const contentParts = content.map(
|
|
2937
3052
|
(part, index) => {
|
|
2938
|
-
var
|
|
3053
|
+
var _a18, _b18, _c2, _d2, _e2, _f2, _g2;
|
|
2939
3054
|
const isLastTextPart = part.type === "text" && index === lastTextPartIndex;
|
|
2940
3055
|
const partCacheControl = getCacheControl(part.providerOptions);
|
|
2941
3056
|
const cacheControl = part.type === "text" ? partCacheControl != null ? partCacheControl : isLastTextPart ? messageCacheControl : void 0 : partCacheControl;
|
|
@@ -2946,7 +3061,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
2946
3061
|
text: part.text
|
|
2947
3062
|
}, cacheControl && { cache_control: cacheControl });
|
|
2948
3063
|
case "file": {
|
|
2949
|
-
if ((
|
|
3064
|
+
if ((_a18 = part.mediaType) == null ? void 0 : _a18.startsWith("image/")) {
|
|
2950
3065
|
const url = getFileUrl({
|
|
2951
3066
|
part,
|
|
2952
3067
|
defaultMediaType: "image/jpeg"
|
|
@@ -2958,7 +3073,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
2958
3073
|
}
|
|
2959
3074
|
}, cacheControl && { cache_control: cacheControl });
|
|
2960
3075
|
}
|
|
2961
|
-
if ((
|
|
3076
|
+
if ((_b18 = part.mediaType) == null ? void 0 : _b18.startsWith("video/")) {
|
|
2962
3077
|
const url = getFileUrl({
|
|
2963
3078
|
part,
|
|
2964
3079
|
defaultMediaType: "video/mp4"
|
|
@@ -3057,11 +3172,11 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
3057
3172
|
let finalReasoningDetails;
|
|
3058
3173
|
if (candidateReasoningDetails) {
|
|
3059
3174
|
const validDetails = candidateReasoningDetails.filter((detail) => {
|
|
3060
|
-
var
|
|
3175
|
+
var _a18;
|
|
3061
3176
|
if (detail.type !== "reasoning.text" /* Text */) {
|
|
3062
3177
|
return true;
|
|
3063
3178
|
}
|
|
3064
|
-
const format = (
|
|
3179
|
+
const format = (_a18 = detail.format) != null ? _a18 : DEFAULT_REASONING_FORMAT;
|
|
3065
3180
|
if (format !== "anthropic-claude-v1" /* AnthropicClaudeV1 */ && format !== "google-gemini-v1" /* GoogleGeminiV1 */) {
|
|
3066
3181
|
return true;
|
|
3067
3182
|
}
|
|
@@ -3119,7 +3234,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
3119
3234
|
return messages;
|
|
3120
3235
|
}
|
|
3121
3236
|
function getToolResultContent(input) {
|
|
3122
|
-
var
|
|
3237
|
+
var _a17;
|
|
3123
3238
|
switch (input.output.type) {
|
|
3124
3239
|
case "text":
|
|
3125
3240
|
case "error-text":
|
|
@@ -3130,44 +3245,28 @@ function getToolResultContent(input) {
|
|
|
3130
3245
|
case "content":
|
|
3131
3246
|
return mapToolResultContentParts(input.output.value);
|
|
3132
3247
|
case "execution-denied":
|
|
3133
|
-
return (
|
|
3248
|
+
return (_a17 = input.output.reason) != null ? _a17 : "Tool execution denied";
|
|
3134
3249
|
}
|
|
3135
3250
|
}
|
|
3136
3251
|
function mapToolResultContentParts(parts) {
|
|
3137
3252
|
return parts.map((part) => {
|
|
3138
|
-
var
|
|
3253
|
+
var _a17, _b17, _c, _d;
|
|
3139
3254
|
switch (part.type) {
|
|
3140
3255
|
case "text":
|
|
3141
3256
|
return { type: "text", text: part.text };
|
|
3142
|
-
case "
|
|
3143
|
-
|
|
3144
|
-
type: "image_url",
|
|
3145
|
-
image_url: {
|
|
3146
|
-
url: buildFileDataUrl({
|
|
3147
|
-
data: part.data,
|
|
3148
|
-
mediaType: part.mediaType,
|
|
3149
|
-
defaultMediaType: "image/jpeg"
|
|
3150
|
-
})
|
|
3151
|
-
}
|
|
3152
|
-
};
|
|
3153
|
-
case "image-url":
|
|
3154
|
-
return {
|
|
3155
|
-
type: "image_url",
|
|
3156
|
-
image_url: { url: part.url }
|
|
3157
|
-
};
|
|
3158
|
-
case "file-data": {
|
|
3159
|
-
const dataUrl = buildFileDataUrl({
|
|
3257
|
+
case "file": {
|
|
3258
|
+
const dataUrl = getFileDataUrl({
|
|
3160
3259
|
data: part.data,
|
|
3161
3260
|
mediaType: part.mediaType,
|
|
3162
3261
|
defaultMediaType: "application/octet-stream"
|
|
3163
3262
|
});
|
|
3164
|
-
if ((
|
|
3263
|
+
if ((_a17 = part.mediaType) == null ? void 0 : _a17.startsWith("image/")) {
|
|
3165
3264
|
return {
|
|
3166
3265
|
type: "image_url",
|
|
3167
3266
|
image_url: { url: dataUrl }
|
|
3168
3267
|
};
|
|
3169
3268
|
}
|
|
3170
|
-
if ((
|
|
3269
|
+
if ((_b17 = part.mediaType) == null ? void 0 : _b17.startsWith("video/")) {
|
|
3171
3270
|
return {
|
|
3172
3271
|
type: "video_url",
|
|
3173
3272
|
video_url: { url: dataUrl }
|
|
@@ -3194,23 +3293,6 @@ function mapToolResultContentParts(parts) {
|
|
|
3194
3293
|
}
|
|
3195
3294
|
};
|
|
3196
3295
|
}
|
|
3197
|
-
case "file-url": {
|
|
3198
|
-
if (looksLikeImageUrl(part.url)) {
|
|
3199
|
-
return {
|
|
3200
|
-
type: "image_url",
|
|
3201
|
-
image_url: { url: part.url }
|
|
3202
|
-
};
|
|
3203
|
-
}
|
|
3204
|
-
return {
|
|
3205
|
-
type: "file",
|
|
3206
|
-
file: {
|
|
3207
|
-
filename: filenameFromUrl(part.url),
|
|
3208
|
-
file_data: part.url
|
|
3209
|
-
}
|
|
3210
|
-
};
|
|
3211
|
-
}
|
|
3212
|
-
case "file-id":
|
|
3213
|
-
case "image-file-id":
|
|
3214
3296
|
case "custom":
|
|
3215
3297
|
return { type: "text", text: JSON.stringify(part) };
|
|
3216
3298
|
default: {
|
|
@@ -3220,46 +3302,14 @@ function mapToolResultContentParts(parts) {
|
|
|
3220
3302
|
}
|
|
3221
3303
|
});
|
|
3222
3304
|
}
|
|
3223
|
-
var IMAGE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
3224
|
-
"jpg",
|
|
3225
|
-
"jpeg",
|
|
3226
|
-
"png",
|
|
3227
|
-
"gif",
|
|
3228
|
-
"webp",
|
|
3229
|
-
"svg",
|
|
3230
|
-
"bmp",
|
|
3231
|
-
"ico",
|
|
3232
|
-
"tif",
|
|
3233
|
-
"tiff",
|
|
3234
|
-
"avif"
|
|
3235
|
-
]);
|
|
3236
|
-
function looksLikeImageUrl(url) {
|
|
3237
|
-
var _a16;
|
|
3238
|
-
try {
|
|
3239
|
-
const pathname = new URL(url).pathname;
|
|
3240
|
-
const ext = (_a16 = pathname.split(".").pop()) == null ? void 0 : _a16.toLowerCase();
|
|
3241
|
-
return ext !== void 0 && IMAGE_EXTENSIONS.has(ext);
|
|
3242
|
-
} catch (e) {
|
|
3243
|
-
return false;
|
|
3244
|
-
}
|
|
3245
|
-
}
|
|
3246
|
-
function filenameFromUrl(url) {
|
|
3247
|
-
try {
|
|
3248
|
-
const pathname = new URL(url).pathname;
|
|
3249
|
-
const last = pathname.split("/").pop();
|
|
3250
|
-
return (last == null ? void 0 : last.includes(".")) ? last : "";
|
|
3251
|
-
} catch (e) {
|
|
3252
|
-
return "";
|
|
3253
|
-
}
|
|
3254
|
-
}
|
|
3255
3305
|
function findFirstReasoningDetails(content) {
|
|
3256
|
-
var
|
|
3306
|
+
var _a17, _b17, _c, _d;
|
|
3257
3307
|
for (const part of content) {
|
|
3258
3308
|
if (part.type === "tool-call") {
|
|
3259
3309
|
const parsed = OpenRouterProviderOptionsSchema.safeParse(
|
|
3260
3310
|
part.providerOptions
|
|
3261
3311
|
);
|
|
3262
|
-
if (parsed.success && ((
|
|
3312
|
+
if (parsed.success && ((_b17 = (_a17 = parsed.data) == null ? void 0 : _a17.openrouter) == null ? void 0 : _b17.reasoning_details) && parsed.data.openrouter.reasoning_details.length > 0) {
|
|
3263
3313
|
return parsed.data.openrouter.reasoning_details;
|
|
3264
3314
|
}
|
|
3265
3315
|
}
|
|
@@ -3278,15 +3328,15 @@ function findFirstReasoningDetails(content) {
|
|
|
3278
3328
|
}
|
|
3279
3329
|
|
|
3280
3330
|
// src/chat/get-tool-choice.ts
|
|
3281
|
-
|
|
3282
|
-
var ChatCompletionToolChoiceSchema =
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
type:
|
|
3288
|
-
function:
|
|
3289
|
-
name:
|
|
3331
|
+
import { z as z5 } from "zod/v4";
|
|
3332
|
+
var ChatCompletionToolChoiceSchema = z5.union([
|
|
3333
|
+
z5.literal("auto"),
|
|
3334
|
+
z5.literal("none"),
|
|
3335
|
+
z5.literal("required"),
|
|
3336
|
+
z5.object({
|
|
3337
|
+
type: z5.literal("function"),
|
|
3338
|
+
function: z5.object({
|
|
3339
|
+
name: z5.string()
|
|
3290
3340
|
})
|
|
3291
3341
|
})
|
|
3292
3342
|
]);
|
|
@@ -3313,97 +3363,97 @@ function getChatCompletionToolChoice(toolChoice) {
|
|
|
3313
3363
|
}
|
|
3314
3364
|
|
|
3315
3365
|
// src/chat/schemas.ts
|
|
3316
|
-
|
|
3366
|
+
import { z as z7 } from "zod/v4";
|
|
3317
3367
|
|
|
3318
3368
|
// src/schemas/image.ts
|
|
3319
|
-
|
|
3320
|
-
var ImageResponseSchema =
|
|
3321
|
-
type:
|
|
3322
|
-
image_url:
|
|
3323
|
-
url:
|
|
3369
|
+
import { z as z6 } from "zod/v4";
|
|
3370
|
+
var ImageResponseSchema = z6.object({
|
|
3371
|
+
type: z6.literal("image_url"),
|
|
3372
|
+
image_url: z6.object({
|
|
3373
|
+
url: z6.string()
|
|
3324
3374
|
}).passthrough()
|
|
3325
3375
|
}).passthrough();
|
|
3326
|
-
var ImageResponseWithUnknownSchema =
|
|
3376
|
+
var ImageResponseWithUnknownSchema = z6.union([
|
|
3327
3377
|
ImageResponseSchema,
|
|
3328
|
-
|
|
3378
|
+
z6.unknown().transform(() => null)
|
|
3329
3379
|
]);
|
|
3330
|
-
var ImageResponseArraySchema =
|
|
3380
|
+
var ImageResponseArraySchema = z6.array(ImageResponseWithUnknownSchema).transform((d) => d.filter((d2) => !!d2));
|
|
3331
3381
|
|
|
3332
3382
|
// src/chat/schemas.ts
|
|
3333
|
-
var OpenRouterChatCompletionBaseResponseSchema =
|
|
3334
|
-
id:
|
|
3335
|
-
model:
|
|
3336
|
-
provider:
|
|
3337
|
-
usage:
|
|
3338
|
-
prompt_tokens:
|
|
3339
|
-
prompt_tokens_details:
|
|
3340
|
-
cached_tokens:
|
|
3341
|
-
cache_write_tokens:
|
|
3383
|
+
var OpenRouterChatCompletionBaseResponseSchema = z7.object({
|
|
3384
|
+
id: z7.string().optional(),
|
|
3385
|
+
model: z7.string().optional(),
|
|
3386
|
+
provider: z7.string().optional(),
|
|
3387
|
+
usage: z7.object({
|
|
3388
|
+
prompt_tokens: z7.number(),
|
|
3389
|
+
prompt_tokens_details: z7.object({
|
|
3390
|
+
cached_tokens: z7.number(),
|
|
3391
|
+
cache_write_tokens: z7.number().nullish()
|
|
3342
3392
|
}).passthrough().nullish(),
|
|
3343
|
-
completion_tokens:
|
|
3344
|
-
completion_tokens_details:
|
|
3345
|
-
reasoning_tokens:
|
|
3393
|
+
completion_tokens: z7.number(),
|
|
3394
|
+
completion_tokens_details: z7.object({
|
|
3395
|
+
reasoning_tokens: z7.number()
|
|
3346
3396
|
}).passthrough().nullish(),
|
|
3347
|
-
total_tokens:
|
|
3348
|
-
cost:
|
|
3349
|
-
cost_details:
|
|
3350
|
-
upstream_inference_cost:
|
|
3397
|
+
total_tokens: z7.number(),
|
|
3398
|
+
cost: z7.number().optional(),
|
|
3399
|
+
cost_details: z7.object({
|
|
3400
|
+
upstream_inference_cost: z7.number().nullish()
|
|
3351
3401
|
}).passthrough().nullish()
|
|
3352
3402
|
}).passthrough().nullish()
|
|
3353
3403
|
}).passthrough();
|
|
3354
|
-
var OpenRouterNonStreamChatCompletionResponseSchema =
|
|
3404
|
+
var OpenRouterNonStreamChatCompletionResponseSchema = z7.union([
|
|
3355
3405
|
// Success response with choices
|
|
3356
3406
|
OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
3357
|
-
choices:
|
|
3358
|
-
|
|
3359
|
-
message:
|
|
3360
|
-
role:
|
|
3361
|
-
content:
|
|
3362
|
-
reasoning:
|
|
3407
|
+
choices: z7.array(
|
|
3408
|
+
z7.object({
|
|
3409
|
+
message: z7.object({
|
|
3410
|
+
role: z7.literal("assistant"),
|
|
3411
|
+
content: z7.string().nullable().optional(),
|
|
3412
|
+
reasoning: z7.string().nullable().optional(),
|
|
3363
3413
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
3364
3414
|
images: ImageResponseArraySchema.nullish(),
|
|
3365
|
-
tool_calls:
|
|
3366
|
-
|
|
3367
|
-
id:
|
|
3368
|
-
type:
|
|
3369
|
-
function:
|
|
3370
|
-
name:
|
|
3371
|
-
arguments:
|
|
3415
|
+
tool_calls: z7.array(
|
|
3416
|
+
z7.object({
|
|
3417
|
+
id: z7.string().optional().nullable(),
|
|
3418
|
+
type: z7.literal("function"),
|
|
3419
|
+
function: z7.object({
|
|
3420
|
+
name: z7.string(),
|
|
3421
|
+
arguments: z7.string().optional()
|
|
3372
3422
|
}).passthrough()
|
|
3373
3423
|
}).passthrough()
|
|
3374
3424
|
).optional(),
|
|
3375
|
-
annotations:
|
|
3376
|
-
|
|
3425
|
+
annotations: z7.array(
|
|
3426
|
+
z7.union([
|
|
3377
3427
|
// URL citation from web search
|
|
3378
3428
|
// title, start_index, end_index are optional as some upstream providers may omit them
|
|
3379
|
-
|
|
3380
|
-
type:
|
|
3381
|
-
url_citation:
|
|
3382
|
-
url:
|
|
3383
|
-
title:
|
|
3384
|
-
start_index:
|
|
3385
|
-
end_index:
|
|
3386
|
-
content:
|
|
3429
|
+
z7.object({
|
|
3430
|
+
type: z7.literal("url_citation"),
|
|
3431
|
+
url_citation: z7.object({
|
|
3432
|
+
url: z7.string(),
|
|
3433
|
+
title: z7.string().optional(),
|
|
3434
|
+
start_index: z7.number().optional(),
|
|
3435
|
+
end_index: z7.number().optional(),
|
|
3436
|
+
content: z7.string().optional()
|
|
3387
3437
|
}).passthrough()
|
|
3388
3438
|
}).passthrough(),
|
|
3389
3439
|
// File annotation from FileParserPlugin (old format)
|
|
3390
|
-
|
|
3391
|
-
type:
|
|
3392
|
-
file_annotation:
|
|
3393
|
-
file_id:
|
|
3394
|
-
quote:
|
|
3440
|
+
z7.object({
|
|
3441
|
+
type: z7.literal("file_annotation"),
|
|
3442
|
+
file_annotation: z7.object({
|
|
3443
|
+
file_id: z7.string(),
|
|
3444
|
+
quote: z7.string().optional()
|
|
3395
3445
|
}).passthrough()
|
|
3396
3446
|
}).passthrough(),
|
|
3397
3447
|
// File annotation from FileParserPlugin (new format)
|
|
3398
|
-
|
|
3399
|
-
type:
|
|
3400
|
-
file:
|
|
3401
|
-
hash:
|
|
3402
|
-
name:
|
|
3403
|
-
content:
|
|
3404
|
-
|
|
3405
|
-
type:
|
|
3406
|
-
text:
|
|
3448
|
+
z7.object({
|
|
3449
|
+
type: z7.literal("file"),
|
|
3450
|
+
file: z7.object({
|
|
3451
|
+
hash: z7.string(),
|
|
3452
|
+
name: z7.string(),
|
|
3453
|
+
content: z7.array(
|
|
3454
|
+
z7.object({
|
|
3455
|
+
type: z7.string(),
|
|
3456
|
+
text: z7.string().optional()
|
|
3407
3457
|
}).passthrough()
|
|
3408
3458
|
).optional()
|
|
3409
3459
|
}).passthrough()
|
|
@@ -3411,83 +3461,83 @@ var OpenRouterNonStreamChatCompletionResponseSchema = import_v46.z.union([
|
|
|
3411
3461
|
])
|
|
3412
3462
|
).nullish()
|
|
3413
3463
|
}).passthrough(),
|
|
3414
|
-
index:
|
|
3415
|
-
logprobs:
|
|
3416
|
-
content:
|
|
3417
|
-
|
|
3418
|
-
token:
|
|
3419
|
-
logprob:
|
|
3420
|
-
top_logprobs:
|
|
3421
|
-
|
|
3422
|
-
token:
|
|
3423
|
-
logprob:
|
|
3464
|
+
index: z7.number().nullish(),
|
|
3465
|
+
logprobs: z7.object({
|
|
3466
|
+
content: z7.array(
|
|
3467
|
+
z7.object({
|
|
3468
|
+
token: z7.string(),
|
|
3469
|
+
logprob: z7.number(),
|
|
3470
|
+
top_logprobs: z7.array(
|
|
3471
|
+
z7.object({
|
|
3472
|
+
token: z7.string(),
|
|
3473
|
+
logprob: z7.number()
|
|
3424
3474
|
}).passthrough()
|
|
3425
3475
|
)
|
|
3426
3476
|
}).passthrough()
|
|
3427
3477
|
).nullable()
|
|
3428
3478
|
}).passthrough().nullable().optional(),
|
|
3429
|
-
finish_reason:
|
|
3479
|
+
finish_reason: z7.string().optional().nullable()
|
|
3430
3480
|
}).passthrough()
|
|
3431
3481
|
)
|
|
3432
3482
|
}),
|
|
3433
3483
|
// Error response (HTTP 200 with error payload)
|
|
3434
3484
|
OpenRouterErrorResponseSchema.extend({
|
|
3435
|
-
user_id:
|
|
3485
|
+
user_id: z7.string().optional()
|
|
3436
3486
|
})
|
|
3437
3487
|
]);
|
|
3438
|
-
var OpenRouterStreamChatCompletionChunkSchema =
|
|
3488
|
+
var OpenRouterStreamChatCompletionChunkSchema = z7.union([
|
|
3439
3489
|
OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
3440
|
-
choices:
|
|
3441
|
-
|
|
3442
|
-
delta:
|
|
3443
|
-
role:
|
|
3444
|
-
content:
|
|
3445
|
-
reasoning:
|
|
3490
|
+
choices: z7.array(
|
|
3491
|
+
z7.object({
|
|
3492
|
+
delta: z7.object({
|
|
3493
|
+
role: z7.enum(["assistant"]).optional(),
|
|
3494
|
+
content: z7.string().nullish(),
|
|
3495
|
+
reasoning: z7.string().nullish().optional(),
|
|
3446
3496
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
3447
3497
|
images: ImageResponseArraySchema.nullish(),
|
|
3448
|
-
tool_calls:
|
|
3449
|
-
|
|
3450
|
-
index:
|
|
3451
|
-
id:
|
|
3452
|
-
type:
|
|
3453
|
-
function:
|
|
3454
|
-
name:
|
|
3455
|
-
arguments:
|
|
3498
|
+
tool_calls: z7.array(
|
|
3499
|
+
z7.object({
|
|
3500
|
+
index: z7.number().nullish(),
|
|
3501
|
+
id: z7.string().nullish(),
|
|
3502
|
+
type: z7.literal("function").optional(),
|
|
3503
|
+
function: z7.object({
|
|
3504
|
+
name: z7.string().nullish(),
|
|
3505
|
+
arguments: z7.string().nullish()
|
|
3456
3506
|
}).passthrough()
|
|
3457
3507
|
}).passthrough()
|
|
3458
3508
|
).nullish(),
|
|
3459
|
-
annotations:
|
|
3460
|
-
|
|
3509
|
+
annotations: z7.array(
|
|
3510
|
+
z7.union([
|
|
3461
3511
|
// URL citation from web search
|
|
3462
3512
|
// title, start_index, end_index are optional as some upstream providers may omit them
|
|
3463
|
-
|
|
3464
|
-
type:
|
|
3465
|
-
url_citation:
|
|
3466
|
-
url:
|
|
3467
|
-
title:
|
|
3468
|
-
start_index:
|
|
3469
|
-
end_index:
|
|
3470
|
-
content:
|
|
3513
|
+
z7.object({
|
|
3514
|
+
type: z7.literal("url_citation"),
|
|
3515
|
+
url_citation: z7.object({
|
|
3516
|
+
url: z7.string(),
|
|
3517
|
+
title: z7.string().optional(),
|
|
3518
|
+
start_index: z7.number().optional(),
|
|
3519
|
+
end_index: z7.number().optional(),
|
|
3520
|
+
content: z7.string().optional()
|
|
3471
3521
|
}).passthrough()
|
|
3472
3522
|
}).passthrough(),
|
|
3473
3523
|
// File annotation from FileParserPlugin (old format)
|
|
3474
|
-
|
|
3475
|
-
type:
|
|
3476
|
-
file_annotation:
|
|
3477
|
-
file_id:
|
|
3478
|
-
quote:
|
|
3524
|
+
z7.object({
|
|
3525
|
+
type: z7.literal("file_annotation"),
|
|
3526
|
+
file_annotation: z7.object({
|
|
3527
|
+
file_id: z7.string(),
|
|
3528
|
+
quote: z7.string().optional()
|
|
3479
3529
|
}).passthrough()
|
|
3480
3530
|
}).passthrough(),
|
|
3481
3531
|
// File annotation from FileParserPlugin (new format)
|
|
3482
|
-
|
|
3483
|
-
type:
|
|
3484
|
-
file:
|
|
3485
|
-
hash:
|
|
3486
|
-
name:
|
|
3487
|
-
content:
|
|
3488
|
-
|
|
3489
|
-
type:
|
|
3490
|
-
text:
|
|
3532
|
+
z7.object({
|
|
3533
|
+
type: z7.literal("file"),
|
|
3534
|
+
file: z7.object({
|
|
3535
|
+
hash: z7.string(),
|
|
3536
|
+
name: z7.string(),
|
|
3537
|
+
content: z7.array(
|
|
3538
|
+
z7.object({
|
|
3539
|
+
type: z7.string(),
|
|
3540
|
+
text: z7.string().optional()
|
|
3491
3541
|
}).passthrough()
|
|
3492
3542
|
).optional()
|
|
3493
3543
|
}).passthrough()
|
|
@@ -3495,22 +3545,22 @@ var OpenRouterStreamChatCompletionChunkSchema = import_v46.z.union([
|
|
|
3495
3545
|
])
|
|
3496
3546
|
).nullish()
|
|
3497
3547
|
}).passthrough().nullish(),
|
|
3498
|
-
logprobs:
|
|
3499
|
-
content:
|
|
3500
|
-
|
|
3501
|
-
token:
|
|
3502
|
-
logprob:
|
|
3503
|
-
top_logprobs:
|
|
3504
|
-
|
|
3505
|
-
token:
|
|
3506
|
-
logprob:
|
|
3548
|
+
logprobs: z7.object({
|
|
3549
|
+
content: z7.array(
|
|
3550
|
+
z7.object({
|
|
3551
|
+
token: z7.string(),
|
|
3552
|
+
logprob: z7.number(),
|
|
3553
|
+
top_logprobs: z7.array(
|
|
3554
|
+
z7.object({
|
|
3555
|
+
token: z7.string(),
|
|
3556
|
+
logprob: z7.number()
|
|
3507
3557
|
}).passthrough()
|
|
3508
3558
|
)
|
|
3509
3559
|
}).passthrough()
|
|
3510
3560
|
).nullable()
|
|
3511
3561
|
}).passthrough().nullish(),
|
|
3512
|
-
finish_reason:
|
|
3513
|
-
index:
|
|
3562
|
+
finish_reason: z7.string().nullable().optional(),
|
|
3563
|
+
index: z7.number().nullish()
|
|
3514
3564
|
}).passthrough()
|
|
3515
3565
|
)
|
|
3516
3566
|
}),
|
|
@@ -3520,7 +3570,7 @@ var OpenRouterStreamChatCompletionChunkSchema = import_v46.z.union([
|
|
|
3520
3570
|
// src/chat/index.ts
|
|
3521
3571
|
var OpenRouterChatLanguageModel = class {
|
|
3522
3572
|
constructor(modelId, settings, config) {
|
|
3523
|
-
this.specificationVersion = "
|
|
3573
|
+
this.specificationVersion = "v4";
|
|
3524
3574
|
this.provider = "openrouter";
|
|
3525
3575
|
this.defaultObjectGenerationMode = "tool";
|
|
3526
3576
|
this.supportsImageUrls = true;
|
|
@@ -3550,7 +3600,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3550
3600
|
tools,
|
|
3551
3601
|
toolChoice
|
|
3552
3602
|
}) {
|
|
3553
|
-
var
|
|
3603
|
+
var _a17, _b17, _c, _d;
|
|
3554
3604
|
const baseArgs = __spreadValues(__spreadValues({
|
|
3555
3605
|
// model id:
|
|
3556
3606
|
model: this.modelId,
|
|
@@ -3573,7 +3623,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3573
3623
|
type: "json_schema",
|
|
3574
3624
|
json_schema: __spreadValues({
|
|
3575
3625
|
schema: responseFormat.schema,
|
|
3576
|
-
strict: (
|
|
3626
|
+
strict: (_b17 = (_a17 = this.settings.structuredOutputs) == null ? void 0 : _a17.strict) != null ? _b17 : true,
|
|
3577
3627
|
name: (_c = responseFormat.name) != null ? _c : "response"
|
|
3578
3628
|
}, responseFormat.description && {
|
|
3579
3629
|
description: responseFormat.description
|
|
@@ -3624,10 +3674,10 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3624
3674
|
return baseArgs;
|
|
3625
3675
|
}
|
|
3626
3676
|
async doGenerate(options) {
|
|
3627
|
-
var
|
|
3677
|
+
var _b17, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
3628
3678
|
const providerOptions = options.providerOptions || {};
|
|
3629
3679
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
3630
|
-
const
|
|
3680
|
+
const _a17 = openrouterOptions, { cacheControl } = _a17, restOpenrouterOptions = __objRest(_a17, ["cacheControl"]);
|
|
3631
3681
|
const args = __spreadValues(__spreadValues(__spreadValues({}, this.getArgs(options)), restOpenrouterOptions), cacheControl != null && !("cache_control" in restOpenrouterOptions) ? { cache_control: cacheControl } : {});
|
|
3632
3682
|
const { value: responseValue, responseHeaders } = await postJsonToApi({
|
|
3633
3683
|
url: this.config.url({
|
|
@@ -3665,7 +3715,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3665
3715
|
});
|
|
3666
3716
|
}
|
|
3667
3717
|
const usageInfo = response.usage ? computeTokenUsage(response.usage) : emptyUsage();
|
|
3668
|
-
const reasoningDetails = (
|
|
3718
|
+
const reasoningDetails = (_b17 = choice.message.reasoning_details) != null ? _b17 : [];
|
|
3669
3719
|
const reasoning = reasoningDetails.length > 0 ? reasoningDetails.map((detail) => {
|
|
3670
3720
|
switch (detail.type) {
|
|
3671
3721
|
case "reasoning.text" /* Text */: {
|
|
@@ -3746,7 +3796,10 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3746
3796
|
content.push({
|
|
3747
3797
|
type: "file",
|
|
3748
3798
|
mediaType: getMediaType(image.image_url.url, "image/jpeg"),
|
|
3749
|
-
data:
|
|
3799
|
+
data: {
|
|
3800
|
+
type: "data",
|
|
3801
|
+
data: getBase64FromDataUrl(image.image_url.url)
|
|
3802
|
+
}
|
|
3750
3803
|
});
|
|
3751
3804
|
}
|
|
3752
3805
|
}
|
|
@@ -3819,10 +3872,10 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3819
3872
|
};
|
|
3820
3873
|
}
|
|
3821
3874
|
async doStream(options) {
|
|
3822
|
-
var
|
|
3875
|
+
var _b17;
|
|
3823
3876
|
const providerOptions = options.providerOptions || {};
|
|
3824
3877
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
3825
|
-
const
|
|
3878
|
+
const _a17 = openrouterOptions, { cacheControl } = _a17, restOpenrouterOptions = __objRest(_a17, ["cacheControl"]);
|
|
3826
3879
|
const args = __spreadValues(__spreadValues(__spreadValues({}, this.getArgs(options)), restOpenrouterOptions), cacheControl != null && !("cache_control" in restOpenrouterOptions) ? { cache_control: cacheControl } : {});
|
|
3827
3880
|
const { value: response, responseHeaders } = await postJsonToApi({
|
|
3828
3881
|
url: this.config.url({
|
|
@@ -3835,7 +3888,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3835
3888
|
// only include stream_options when in strict compatibility mode:
|
|
3836
3889
|
stream_options: this.config.compatibility === "strict" ? __spreadValues({
|
|
3837
3890
|
include_usage: true
|
|
3838
|
-
}, ((
|
|
3891
|
+
}, ((_b17 = this.settings.usage) == null ? void 0 : _b17.include) ? { include_usage: true } : {}) : void 0
|
|
3839
3892
|
}),
|
|
3840
3893
|
failedResponseHandler: openrouterFailedResponseHandler,
|
|
3841
3894
|
successfulResponseHandler: createEventSourceResponseHandler(
|
|
@@ -3876,11 +3929,15 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3876
3929
|
let reasoningId;
|
|
3877
3930
|
let openrouterResponseId;
|
|
3878
3931
|
let provider;
|
|
3932
|
+
const warnings = [];
|
|
3879
3933
|
return {
|
|
3880
3934
|
stream: safeResponse.pipeThrough(
|
|
3881
3935
|
new TransformStream({
|
|
3936
|
+
start(controller) {
|
|
3937
|
+
controller.enqueue({ type: "stream-start", warnings });
|
|
3938
|
+
},
|
|
3882
3939
|
transform(chunk, controller) {
|
|
3883
|
-
var
|
|
3940
|
+
var _a18, _b18, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
3884
3941
|
if (options.includeRawChunks) {
|
|
3885
3942
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
3886
3943
|
}
|
|
@@ -3916,8 +3973,8 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3916
3973
|
Object.assign(usage.inputTokens, computed.inputTokens);
|
|
3917
3974
|
Object.assign(usage.outputTokens, computed.outputTokens);
|
|
3918
3975
|
rawUsage = value.usage;
|
|
3919
|
-
const promptTokens = (
|
|
3920
|
-
const completionTokens = (
|
|
3976
|
+
const promptTokens = (_a18 = value.usage.prompt_tokens) != null ? _a18 : 0;
|
|
3977
|
+
const completionTokens = (_b18 = value.usage.completion_tokens) != null ? _b18 : 0;
|
|
3921
3978
|
openrouterUsage.promptTokens = promptTokens;
|
|
3922
3979
|
if (value.usage.prompt_tokens_details) {
|
|
3923
3980
|
openrouterUsage.promptTokensDetails = {
|
|
@@ -4195,7 +4252,10 @@ var OpenRouterChatLanguageModel = class {
|
|
|
4195
4252
|
controller.enqueue({
|
|
4196
4253
|
type: "file",
|
|
4197
4254
|
mediaType: getMediaType(image.image_url.url, "image/jpeg"),
|
|
4198
|
-
data:
|
|
4255
|
+
data: {
|
|
4256
|
+
type: "data",
|
|
4257
|
+
data: getBase64FromDataUrl(image.image_url.url)
|
|
4258
|
+
}
|
|
4199
4259
|
});
|
|
4200
4260
|
}
|
|
4201
4261
|
}
|
|
@@ -4299,7 +4359,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
4299
4359
|
}
|
|
4300
4360
|
})
|
|
4301
4361
|
),
|
|
4302
|
-
warnings
|
|
4362
|
+
warnings,
|
|
4303
4363
|
request: { body: args },
|
|
4304
4364
|
response: { headers: responseHeaders }
|
|
4305
4365
|
};
|
|
@@ -4370,38 +4430,36 @@ ${userMessage}
|
|
|
4370
4430
|
break;
|
|
4371
4431
|
}
|
|
4372
4432
|
case "assistant": {
|
|
4373
|
-
const assistantMessage = content.map(
|
|
4374
|
-
(part)
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
return "";
|
|
4401
|
-
}
|
|
4433
|
+
const assistantMessage = content.map((part) => {
|
|
4434
|
+
switch (part.type) {
|
|
4435
|
+
case "text": {
|
|
4436
|
+
return part.text;
|
|
4437
|
+
}
|
|
4438
|
+
case "tool-call": {
|
|
4439
|
+
throw new UnsupportedFunctionalityError({
|
|
4440
|
+
functionality: "tool-call messages"
|
|
4441
|
+
});
|
|
4442
|
+
}
|
|
4443
|
+
case "tool-result": {
|
|
4444
|
+
throw new UnsupportedFunctionalityError({
|
|
4445
|
+
functionality: "tool-result messages"
|
|
4446
|
+
});
|
|
4447
|
+
}
|
|
4448
|
+
case "reasoning": {
|
|
4449
|
+
throw new UnsupportedFunctionalityError({
|
|
4450
|
+
functionality: "reasoning messages"
|
|
4451
|
+
});
|
|
4452
|
+
}
|
|
4453
|
+
case "file": {
|
|
4454
|
+
throw new UnsupportedFunctionalityError({
|
|
4455
|
+
functionality: "file attachments"
|
|
4456
|
+
});
|
|
4457
|
+
}
|
|
4458
|
+
default: {
|
|
4459
|
+
return "";
|
|
4402
4460
|
}
|
|
4403
4461
|
}
|
|
4404
|
-
).join("");
|
|
4462
|
+
}).join("");
|
|
4405
4463
|
text += `${assistant}:
|
|
4406
4464
|
${assistantMessage}
|
|
4407
4465
|
|
|
@@ -4426,40 +4484,40 @@ ${assistantMessage}
|
|
|
4426
4484
|
}
|
|
4427
4485
|
|
|
4428
4486
|
// src/completion/schemas.ts
|
|
4429
|
-
|
|
4430
|
-
var OpenRouterCompletionChunkSchema =
|
|
4431
|
-
|
|
4432
|
-
id:
|
|
4433
|
-
model:
|
|
4434
|
-
provider:
|
|
4435
|
-
choices:
|
|
4436
|
-
|
|
4437
|
-
text:
|
|
4438
|
-
reasoning:
|
|
4487
|
+
import { z as z8 } from "zod/v4";
|
|
4488
|
+
var OpenRouterCompletionChunkSchema = z8.union([
|
|
4489
|
+
z8.object({
|
|
4490
|
+
id: z8.string().optional(),
|
|
4491
|
+
model: z8.string().optional(),
|
|
4492
|
+
provider: z8.string().optional(),
|
|
4493
|
+
choices: z8.array(
|
|
4494
|
+
z8.object({
|
|
4495
|
+
text: z8.string(),
|
|
4496
|
+
reasoning: z8.string().nullish().optional(),
|
|
4439
4497
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
4440
|
-
finish_reason:
|
|
4441
|
-
index:
|
|
4442
|
-
logprobs:
|
|
4443
|
-
tokens:
|
|
4444
|
-
token_logprobs:
|
|
4445
|
-
top_logprobs:
|
|
4498
|
+
finish_reason: z8.string().nullish(),
|
|
4499
|
+
index: z8.number().nullish(),
|
|
4500
|
+
logprobs: z8.object({
|
|
4501
|
+
tokens: z8.array(z8.string()),
|
|
4502
|
+
token_logprobs: z8.array(z8.number()),
|
|
4503
|
+
top_logprobs: z8.array(z8.record(z8.string(), z8.number())).nullable()
|
|
4446
4504
|
}).passthrough().nullable().optional()
|
|
4447
4505
|
}).passthrough()
|
|
4448
4506
|
),
|
|
4449
|
-
usage:
|
|
4450
|
-
prompt_tokens:
|
|
4451
|
-
prompt_tokens_details:
|
|
4452
|
-
cached_tokens:
|
|
4453
|
-
cache_write_tokens:
|
|
4507
|
+
usage: z8.object({
|
|
4508
|
+
prompt_tokens: z8.number(),
|
|
4509
|
+
prompt_tokens_details: z8.object({
|
|
4510
|
+
cached_tokens: z8.number(),
|
|
4511
|
+
cache_write_tokens: z8.number().nullish()
|
|
4454
4512
|
}).passthrough().nullish(),
|
|
4455
|
-
completion_tokens:
|
|
4456
|
-
completion_tokens_details:
|
|
4457
|
-
reasoning_tokens:
|
|
4513
|
+
completion_tokens: z8.number(),
|
|
4514
|
+
completion_tokens_details: z8.object({
|
|
4515
|
+
reasoning_tokens: z8.number()
|
|
4458
4516
|
}).passthrough().nullish(),
|
|
4459
|
-
total_tokens:
|
|
4460
|
-
cost:
|
|
4461
|
-
cost_details:
|
|
4462
|
-
upstream_inference_cost:
|
|
4517
|
+
total_tokens: z8.number(),
|
|
4518
|
+
cost: z8.number().optional(),
|
|
4519
|
+
cost_details: z8.object({
|
|
4520
|
+
upstream_inference_cost: z8.number().nullish()
|
|
4463
4521
|
}).passthrough().nullish()
|
|
4464
4522
|
}).passthrough().nullish()
|
|
4465
4523
|
}).passthrough(),
|
|
@@ -4469,7 +4527,7 @@ var OpenRouterCompletionChunkSchema = import_v47.z.union([
|
|
|
4469
4527
|
// src/completion/index.ts
|
|
4470
4528
|
var OpenRouterCompletionLanguageModel = class {
|
|
4471
4529
|
constructor(modelId, settings, config) {
|
|
4472
|
-
this.specificationVersion = "
|
|
4530
|
+
this.specificationVersion = "v4";
|
|
4473
4531
|
this.provider = "openrouter";
|
|
4474
4532
|
this.supportsImageUrls = true;
|
|
4475
4533
|
this.supportedUrls = {
|
|
@@ -4540,7 +4598,7 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
4540
4598
|
}, this.config.extraBody), this.settings.extraBody);
|
|
4541
4599
|
}
|
|
4542
4600
|
async doGenerate(options) {
|
|
4543
|
-
var
|
|
4601
|
+
var _a17, _b17, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
4544
4602
|
const providerOptions = options.providerOptions || {};
|
|
4545
4603
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
4546
4604
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
@@ -4582,7 +4640,7 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
4582
4640
|
content: [
|
|
4583
4641
|
{
|
|
4584
4642
|
type: "text",
|
|
4585
|
-
text: (
|
|
4643
|
+
text: (_a17 = choice.text) != null ? _a17 : ""
|
|
4586
4644
|
}
|
|
4587
4645
|
],
|
|
4588
4646
|
finishReason: mapOpenRouterFinishReason(choice.finish_reason),
|
|
@@ -4590,7 +4648,7 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
4590
4648
|
warnings: [],
|
|
4591
4649
|
providerMetadata: {
|
|
4592
4650
|
openrouter: OpenRouterProviderMetadataSchema.parse({
|
|
4593
|
-
provider: (
|
|
4651
|
+
provider: (_b17 = response.provider) != null ? _b17 : "",
|
|
4594
4652
|
usage: __spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
4595
4653
|
promptTokens: (_d = (_c = response.usage) == null ? void 0 : _c.prompt_tokens) != null ? _d : 0,
|
|
4596
4654
|
completionTokens: (_f = (_e = response.usage) == null ? void 0 : _e.completion_tokens) != null ? _f : 0,
|
|
@@ -4659,11 +4717,15 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
4659
4717
|
const openrouterUsage = {};
|
|
4660
4718
|
let provider;
|
|
4661
4719
|
let rawUsage;
|
|
4720
|
+
const warnings = [];
|
|
4662
4721
|
return {
|
|
4663
4722
|
stream: safeResponse.pipeThrough(
|
|
4664
4723
|
new TransformStream({
|
|
4724
|
+
start(controller) {
|
|
4725
|
+
controller.enqueue({ type: "stream-start", warnings });
|
|
4726
|
+
},
|
|
4665
4727
|
transform(chunk, controller) {
|
|
4666
|
-
var
|
|
4728
|
+
var _a17, _b17, _c, _d, _e;
|
|
4667
4729
|
if (options.includeRawChunks) {
|
|
4668
4730
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
4669
4731
|
}
|
|
@@ -4686,8 +4748,8 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
4686
4748
|
Object.assign(usage.inputTokens, computed.inputTokens);
|
|
4687
4749
|
Object.assign(usage.outputTokens, computed.outputTokens);
|
|
4688
4750
|
rawUsage = value.usage;
|
|
4689
|
-
const promptTokens = (
|
|
4690
|
-
const completionTokens = (
|
|
4751
|
+
const promptTokens = (_a17 = value.usage.prompt_tokens) != null ? _a17 : 0;
|
|
4752
|
+
const completionTokens = (_b17 = value.usage.completion_tokens) != null ? _b17 : 0;
|
|
4691
4753
|
openrouterUsage.promptTokens = promptTokens;
|
|
4692
4754
|
if (value.usage.prompt_tokens_details) {
|
|
4693
4755
|
openrouterUsage.promptTokensDetails = {
|
|
@@ -4754,30 +4816,30 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
4754
4816
|
};
|
|
4755
4817
|
|
|
4756
4818
|
// src/embedding/schemas.ts
|
|
4757
|
-
|
|
4758
|
-
var openrouterEmbeddingUsageSchema =
|
|
4759
|
-
prompt_tokens:
|
|
4760
|
-
total_tokens:
|
|
4761
|
-
cost:
|
|
4819
|
+
import { z as z9 } from "zod/v4";
|
|
4820
|
+
var openrouterEmbeddingUsageSchema = z9.object({
|
|
4821
|
+
prompt_tokens: z9.number(),
|
|
4822
|
+
total_tokens: z9.number(),
|
|
4823
|
+
cost: z9.number().optional()
|
|
4762
4824
|
});
|
|
4763
|
-
var openrouterEmbeddingDataSchema =
|
|
4764
|
-
object:
|
|
4765
|
-
embedding:
|
|
4766
|
-
index:
|
|
4825
|
+
var openrouterEmbeddingDataSchema = z9.object({
|
|
4826
|
+
object: z9.literal("embedding"),
|
|
4827
|
+
embedding: z9.array(z9.number()),
|
|
4828
|
+
index: z9.number().optional()
|
|
4767
4829
|
});
|
|
4768
|
-
var OpenRouterEmbeddingResponseSchema =
|
|
4769
|
-
id:
|
|
4770
|
-
object:
|
|
4771
|
-
data:
|
|
4772
|
-
model:
|
|
4773
|
-
provider:
|
|
4830
|
+
var OpenRouterEmbeddingResponseSchema = z9.object({
|
|
4831
|
+
id: z9.string().optional(),
|
|
4832
|
+
object: z9.literal("list"),
|
|
4833
|
+
data: z9.array(openrouterEmbeddingDataSchema),
|
|
4834
|
+
model: z9.string(),
|
|
4835
|
+
provider: z9.string().optional(),
|
|
4774
4836
|
usage: openrouterEmbeddingUsageSchema.optional()
|
|
4775
4837
|
});
|
|
4776
4838
|
|
|
4777
4839
|
// src/embedding/index.ts
|
|
4778
4840
|
var OpenRouterEmbeddingModel = class {
|
|
4779
4841
|
constructor(modelId, settings, config) {
|
|
4780
|
-
this.specificationVersion = "
|
|
4842
|
+
this.specificationVersion = "v4";
|
|
4781
4843
|
this.provider = "openrouter";
|
|
4782
4844
|
this.maxEmbeddingsPerCall = void 0;
|
|
4783
4845
|
this.supportsParallelCalls = true;
|
|
@@ -4786,7 +4848,7 @@ var OpenRouterEmbeddingModel = class {
|
|
|
4786
4848
|
this.config = config;
|
|
4787
4849
|
}
|
|
4788
4850
|
async doEmbed(options) {
|
|
4789
|
-
var
|
|
4851
|
+
var _a17, _b17, _c, _d, _e, _f;
|
|
4790
4852
|
const { values, abortSignal, headers } = options;
|
|
4791
4853
|
const args = __spreadValues(__spreadValues({
|
|
4792
4854
|
model: this.modelId,
|
|
@@ -4813,9 +4875,9 @@ var OpenRouterEmbeddingModel = class {
|
|
|
4813
4875
|
usage: responseValue.usage ? { tokens: responseValue.usage.prompt_tokens } : void 0,
|
|
4814
4876
|
providerMetadata: {
|
|
4815
4877
|
openrouter: OpenRouterProviderMetadataSchema.parse({
|
|
4816
|
-
provider: (
|
|
4878
|
+
provider: (_a17 = responseValue.provider) != null ? _a17 : "",
|
|
4817
4879
|
usage: __spreadValues({
|
|
4818
|
-
promptTokens: (_c = (
|
|
4880
|
+
promptTokens: (_c = (_b17 = responseValue.usage) == null ? void 0 : _b17.prompt_tokens) != null ? _c : 0,
|
|
4819
4881
|
completionTokens: 0,
|
|
4820
4882
|
totalTokens: (_e = (_d = responseValue.usage) == null ? void 0 : _d.total_tokens) != null ? _e : 0
|
|
4821
4883
|
}, ((_f = responseValue.usage) == null ? void 0 : _f.cost) != null ? { cost: responseValue.usage.cost } : {})
|
|
@@ -4836,8 +4898,8 @@ var OpenRouter = class {
|
|
|
4836
4898
|
* Creates a new OpenRouter provider instance.
|
|
4837
4899
|
*/
|
|
4838
4900
|
constructor(options = {}) {
|
|
4839
|
-
var
|
|
4840
|
-
this.baseURL = (
|
|
4901
|
+
var _a17, _b17;
|
|
4902
|
+
this.baseURL = (_b17 = withoutTrailingSlash((_a17 = options.baseURL) != null ? _a17 : options.baseUrl)) != null ? _b17 : "https://openrouter.ai/api/v1";
|
|
4841
4903
|
this.apiKey = options.apiKey;
|
|
4842
4904
|
this.headers = options.headers;
|
|
4843
4905
|
this.api_keys = options.api_keys;
|
|
@@ -4890,25 +4952,25 @@ var OpenRouter = class {
|
|
|
4890
4952
|
};
|
|
4891
4953
|
|
|
4892
4954
|
// src/image/schemas.ts
|
|
4893
|
-
|
|
4894
|
-
var OpenRouterImageResponseSchema =
|
|
4895
|
-
created:
|
|
4896
|
-
data:
|
|
4897
|
-
|
|
4898
|
-
b64_json:
|
|
4955
|
+
import { z as z10 } from "zod/v4";
|
|
4956
|
+
var OpenRouterImageResponseSchema = z10.object({
|
|
4957
|
+
created: z10.number().optional(),
|
|
4958
|
+
data: z10.array(
|
|
4959
|
+
z10.object({
|
|
4960
|
+
b64_json: z10.string()
|
|
4899
4961
|
}).passthrough()
|
|
4900
4962
|
),
|
|
4901
|
-
usage:
|
|
4902
|
-
prompt_tokens:
|
|
4903
|
-
completion_tokens:
|
|
4904
|
-
total_tokens:
|
|
4963
|
+
usage: z10.object({
|
|
4964
|
+
prompt_tokens: z10.number(),
|
|
4965
|
+
completion_tokens: z10.number(),
|
|
4966
|
+
total_tokens: z10.number()
|
|
4905
4967
|
}).passthrough().optional()
|
|
4906
4968
|
}).passthrough();
|
|
4907
4969
|
|
|
4908
4970
|
// src/image/index.ts
|
|
4909
4971
|
var OpenRouterImageModel = class {
|
|
4910
4972
|
constructor(modelId, settings, config) {
|
|
4911
|
-
this.specificationVersion = "
|
|
4973
|
+
this.specificationVersion = "v4";
|
|
4912
4974
|
this.provider = "openrouter";
|
|
4913
4975
|
this.maxImagesPerCall = 10;
|
|
4914
4976
|
this.modelId = modelId;
|
|
@@ -5002,12 +5064,12 @@ function convertFileToInputReference(file) {
|
|
|
5002
5064
|
}
|
|
5003
5065
|
|
|
5004
5066
|
// src/tool/web-search.ts
|
|
5005
|
-
|
|
5006
|
-
var webSearchInputSchema =
|
|
5067
|
+
import { z as z11 } from "zod/v4";
|
|
5068
|
+
var webSearchInputSchema = z11.object({
|
|
5007
5069
|
/** Search results returned by the server tool */
|
|
5008
|
-
results:
|
|
5070
|
+
results: z11.array(z11.unknown()).optional()
|
|
5009
5071
|
});
|
|
5010
|
-
var webSearch =
|
|
5072
|
+
var webSearch = createProviderDefinedToolFactory({
|
|
5011
5073
|
id: "openrouter.web_search",
|
|
5012
5074
|
inputSchema: webSearchInputSchema
|
|
5013
5075
|
});
|
|
@@ -5053,27 +5115,27 @@ function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
|
|
|
5053
5115
|
}
|
|
5054
5116
|
|
|
5055
5117
|
// src/version.ts
|
|
5056
|
-
var VERSION2 = false ? "0.0.0-test" : "
|
|
5118
|
+
var VERSION2 = false ? "0.0.0-test" : "3.0.0";
|
|
5057
5119
|
|
|
5058
5120
|
// src/video/schemas.ts
|
|
5059
|
-
|
|
5060
|
-
var VideoGenerationSubmitResponseSchema =
|
|
5061
|
-
id:
|
|
5062
|
-
generation_id:
|
|
5063
|
-
polling_url:
|
|
5064
|
-
status:
|
|
5121
|
+
import { z as z12 } from "zod/v4";
|
|
5122
|
+
var VideoGenerationSubmitResponseSchema = z12.object({
|
|
5123
|
+
id: z12.string(),
|
|
5124
|
+
generation_id: z12.string().optional(),
|
|
5125
|
+
polling_url: z12.string(),
|
|
5126
|
+
status: z12.string()
|
|
5065
5127
|
}).passthrough();
|
|
5066
|
-
var VideoGenerationPollResponseSchema =
|
|
5067
|
-
id:
|
|
5068
|
-
generation_id:
|
|
5069
|
-
polling_url:
|
|
5070
|
-
status:
|
|
5071
|
-
unsigned_urls:
|
|
5072
|
-
usage:
|
|
5073
|
-
cost:
|
|
5074
|
-
is_byok:
|
|
5128
|
+
var VideoGenerationPollResponseSchema = z12.object({
|
|
5129
|
+
id: z12.string(),
|
|
5130
|
+
generation_id: z12.string().optional(),
|
|
5131
|
+
polling_url: z12.string(),
|
|
5132
|
+
status: z12.string(),
|
|
5133
|
+
unsigned_urls: z12.array(z12.string()).optional(),
|
|
5134
|
+
usage: z12.object({
|
|
5135
|
+
cost: z12.number().optional(),
|
|
5136
|
+
is_byok: z12.boolean().optional()
|
|
5075
5137
|
}).passthrough().optional(),
|
|
5076
|
-
error:
|
|
5138
|
+
error: z12.string().optional()
|
|
5077
5139
|
}).passthrough();
|
|
5078
5140
|
|
|
5079
5141
|
// src/video/index.ts
|
|
@@ -5081,7 +5143,7 @@ var DEFAULT_POLL_INTERVAL_MS = 2e3;
|
|
|
5081
5143
|
var DEFAULT_MAX_POLL_TIME_MS = 6e5;
|
|
5082
5144
|
var OpenRouterVideoModel = class {
|
|
5083
5145
|
constructor(modelId, settings, config) {
|
|
5084
|
-
this.specificationVersion = "
|
|
5146
|
+
this.specificationVersion = "v4";
|
|
5085
5147
|
this.provider = "openrouter";
|
|
5086
5148
|
this.maxVideosPerCall = 1;
|
|
5087
5149
|
this.modelId = modelId;
|
|
@@ -5089,7 +5151,7 @@ var OpenRouterVideoModel = class {
|
|
|
5089
5151
|
this.config = config;
|
|
5090
5152
|
}
|
|
5091
5153
|
async doGenerate(options) {
|
|
5092
|
-
var
|
|
5154
|
+
var _a17, _b17, _c, _d, _e;
|
|
5093
5155
|
const {
|
|
5094
5156
|
prompt,
|
|
5095
5157
|
n,
|
|
@@ -5133,8 +5195,8 @@ var OpenRouterVideoModel = class {
|
|
|
5133
5195
|
abortSignal,
|
|
5134
5196
|
fetch: this.config.fetch
|
|
5135
5197
|
});
|
|
5136
|
-
const pollIntervalMs = (
|
|
5137
|
-
const maxPollTimeMs = (
|
|
5198
|
+
const pollIntervalMs = (_a17 = this.settings.pollIntervalMs) != null ? _a17 : DEFAULT_POLL_INTERVAL_MS;
|
|
5199
|
+
const maxPollTimeMs = (_b17 = this.settings.maxPollTimeMs) != null ? _b17 : DEFAULT_MAX_POLL_TIME_MS;
|
|
5138
5200
|
const pollResult = await this.pollUntilComplete({
|
|
5139
5201
|
jobId: submitResponse.id,
|
|
5140
5202
|
headers: mergedHeaders,
|
|
@@ -5176,7 +5238,7 @@ var OpenRouterVideoModel = class {
|
|
|
5176
5238
|
pollIntervalMs,
|
|
5177
5239
|
maxPollTimeMs
|
|
5178
5240
|
}) {
|
|
5179
|
-
var
|
|
5241
|
+
var _a17;
|
|
5180
5242
|
const startTime = Date.now();
|
|
5181
5243
|
while (Date.now() - startTime < maxPollTimeMs) {
|
|
5182
5244
|
abortSignal == null ? void 0 : abortSignal.throwIfAborted();
|
|
@@ -5204,7 +5266,7 @@ var OpenRouterVideoModel = class {
|
|
|
5204
5266
|
}
|
|
5205
5267
|
if (pollResponse.status === "failed" || pollResponse.status === "dead" || pollResponse.status === "cancelled" || pollResponse.status === "expired") {
|
|
5206
5268
|
throw new APICallError({
|
|
5207
|
-
message: (
|
|
5269
|
+
message: (_a17 = pollResponse.error) != null ? _a17 : `Video generation failed with status: ${pollResponse.status}`,
|
|
5208
5270
|
url: this.config.url({
|
|
5209
5271
|
path: `/videos/${jobId}`,
|
|
5210
5272
|
modelId: this.modelId
|
|
@@ -5249,8 +5311,8 @@ function convertImageToFrameImage(file) {
|
|
|
5249
5311
|
|
|
5250
5312
|
// src/provider.ts
|
|
5251
5313
|
function createOpenRouter(options = {}) {
|
|
5252
|
-
var
|
|
5253
|
-
const baseURL = (
|
|
5314
|
+
var _a17, _b17, _c;
|
|
5315
|
+
const baseURL = (_b17 = withoutTrailingSlash((_a17 = options.baseURL) != null ? _a17 : options.baseUrl)) != null ? _b17 : "https://openrouter.ai/api/v1";
|
|
5254
5316
|
const compatibility = (_c = options.compatibility) != null ? _c : "compatible";
|
|
5255
5317
|
const getHeaders = () => withUserAgentSuffix2(
|
|
5256
5318
|
__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
@@ -5332,10 +5394,9 @@ var openrouter = createOpenRouter({
|
|
|
5332
5394
|
compatibility: "strict"
|
|
5333
5395
|
// strict for OpenRouter API
|
|
5334
5396
|
});
|
|
5335
|
-
|
|
5336
|
-
0 && (module.exports = {
|
|
5397
|
+
export {
|
|
5337
5398
|
OpenRouter,
|
|
5338
5399
|
createOpenRouter,
|
|
5339
5400
|
openrouter
|
|
5340
|
-
}
|
|
5401
|
+
};
|
|
5341
5402
|
//# sourceMappingURL=index.js.map
|