@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/internal/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,43 +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
|
-
OpenRouterChatLanguageModel: () => OpenRouterChatLanguageModel,
|
|
69
|
-
OpenRouterCompletionLanguageModel: () => OpenRouterCompletionLanguageModel,
|
|
70
|
-
OpenRouterEmbeddingModel: () => OpenRouterEmbeddingModel,
|
|
71
|
-
OpenRouterImageModel: () => OpenRouterImageModel,
|
|
72
|
-
OpenRouterVideoModel: () => OpenRouterVideoModel
|
|
73
|
-
});
|
|
74
|
-
module.exports = __toCommonJS(index_exports);
|
|
75
|
-
|
|
76
|
-
// 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
|
|
77
40
|
var marker = "vercel.ai.error";
|
|
78
41
|
var symbol = Symbol.for(marker);
|
|
79
42
|
var _a;
|
|
@@ -88,13 +51,13 @@ var AISDKError = class _AISDKError extends (_b = Error, _a = symbol, _b) {
|
|
|
88
51
|
* @param {unknown} [params.cause] - The underlying cause of the error.
|
|
89
52
|
*/
|
|
90
53
|
constructor({
|
|
91
|
-
name:
|
|
54
|
+
name: name152,
|
|
92
55
|
message,
|
|
93
56
|
cause
|
|
94
57
|
}) {
|
|
95
58
|
super(message);
|
|
96
59
|
this[_a] = true;
|
|
97
|
-
this.name =
|
|
60
|
+
this.name = name152;
|
|
98
61
|
this.cause = cause;
|
|
99
62
|
}
|
|
100
63
|
/**
|
|
@@ -105,8 +68,8 @@ var AISDKError = class _AISDKError extends (_b = Error, _a = symbol, _b) {
|
|
|
105
68
|
static isInstance(error) {
|
|
106
69
|
return _AISDKError.hasMarker(error, marker);
|
|
107
70
|
}
|
|
108
|
-
static hasMarker(error,
|
|
109
|
-
const markerSymbol = Symbol.for(
|
|
71
|
+
static hasMarker(error, marker162) {
|
|
72
|
+
const markerSymbol = Symbol.for(marker162);
|
|
110
73
|
return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
|
|
111
74
|
}
|
|
112
75
|
};
|
|
@@ -168,7 +131,7 @@ function getErrorMessage(error) {
|
|
|
168
131
|
return error;
|
|
169
132
|
}
|
|
170
133
|
if (error instanceof Error) {
|
|
171
|
-
return error.
|
|
134
|
+
return error.toString();
|
|
172
135
|
}
|
|
173
136
|
return JSON.stringify(error);
|
|
174
137
|
}
|
|
@@ -316,33 +279,53 @@ var NoSuchModelError = class extends (_b11 = AISDKError, _a11 = symbol11, _b11)
|
|
|
316
279
|
return AISDKError.hasMarker(error, marker11);
|
|
317
280
|
}
|
|
318
281
|
};
|
|
319
|
-
var name11 = "
|
|
282
|
+
var name11 = "AI_NoSuchProviderReferenceError";
|
|
320
283
|
var marker12 = `vercel.ai.error.${name11}`;
|
|
321
284
|
var symbol12 = Symbol.for(marker12);
|
|
322
285
|
var _a12;
|
|
323
286
|
var _b12;
|
|
324
|
-
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) {
|
|
325
308
|
constructor(options) {
|
|
326
309
|
super({
|
|
327
|
-
name:
|
|
310
|
+
name: name12,
|
|
328
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.`
|
|
329
312
|
});
|
|
330
|
-
this[
|
|
313
|
+
this[_a13] = true;
|
|
331
314
|
this.provider = options.provider;
|
|
332
315
|
this.modelId = options.modelId;
|
|
333
316
|
this.maxEmbeddingsPerCall = options.maxEmbeddingsPerCall;
|
|
334
317
|
this.values = options.values;
|
|
335
318
|
}
|
|
336
319
|
static isInstance(error) {
|
|
337
|
-
return AISDKError.hasMarker(error,
|
|
320
|
+
return AISDKError.hasMarker(error, marker13);
|
|
338
321
|
}
|
|
339
322
|
};
|
|
340
|
-
var
|
|
341
|
-
var
|
|
342
|
-
var
|
|
343
|
-
var
|
|
344
|
-
var
|
|
345
|
-
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) {
|
|
346
329
|
constructor({
|
|
347
330
|
value,
|
|
348
331
|
cause,
|
|
@@ -365,17 +348,17 @@ var TypeValidationError = class _TypeValidationError extends (_b13 = AISDKError,
|
|
|
365
348
|
contextPrefix += ")";
|
|
366
349
|
}
|
|
367
350
|
super({
|
|
368
|
-
name:
|
|
351
|
+
name: name13,
|
|
369
352
|
message: `${contextPrefix}: Value: ${JSON.stringify(value)}.
|
|
370
353
|
Error message: ${getErrorMessage(cause)}`,
|
|
371
354
|
cause
|
|
372
355
|
});
|
|
373
|
-
this[
|
|
356
|
+
this[_a14] = true;
|
|
374
357
|
this.value = value;
|
|
375
358
|
this.context = context;
|
|
376
359
|
}
|
|
377
360
|
static isInstance(error) {
|
|
378
|
-
return AISDKError.hasMarker(error,
|
|
361
|
+
return AISDKError.hasMarker(error, marker14);
|
|
379
362
|
}
|
|
380
363
|
/**
|
|
381
364
|
* Wraps an error into a TypeValidationError.
|
|
@@ -393,84 +376,170 @@ Error message: ${getErrorMessage(cause)}`,
|
|
|
393
376
|
cause,
|
|
394
377
|
context
|
|
395
378
|
}) {
|
|
396
|
-
var
|
|
397
|
-
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)) {
|
|
398
381
|
return cause;
|
|
399
382
|
}
|
|
400
383
|
return new _TypeValidationError({ value, cause, context });
|
|
401
384
|
}
|
|
402
385
|
};
|
|
403
|
-
var
|
|
404
|
-
var
|
|
405
|
-
var
|
|
406
|
-
var
|
|
407
|
-
var
|
|
408
|
-
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) {
|
|
409
392
|
constructor({
|
|
410
393
|
functionality,
|
|
411
394
|
message = `'${functionality}' functionality not supported.`
|
|
412
395
|
}) {
|
|
413
|
-
super({ name:
|
|
414
|
-
this[
|
|
396
|
+
super({ name: name14, message });
|
|
397
|
+
this[_a15] = true;
|
|
415
398
|
this.functionality = functionality;
|
|
416
399
|
}
|
|
417
400
|
static isInstance(error) {
|
|
418
|
-
return AISDKError.hasMarker(error,
|
|
401
|
+
return AISDKError.hasMarker(error, marker15);
|
|
419
402
|
}
|
|
420
403
|
};
|
|
421
404
|
|
|
422
|
-
// node_modules/.pnpm/@ai-sdk+provider-utils@
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
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";
|
|
427
412
|
|
|
428
|
-
// node_modules/.pnpm/eventsource-parser@3.0
|
|
413
|
+
// node_modules/.pnpm/eventsource-parser@3.1.0/node_modules/eventsource-parser/dist/index.js
|
|
429
414
|
var ParseError = class extends Error {
|
|
430
415
|
constructor(message, options) {
|
|
431
416
|
super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
|
|
432
417
|
}
|
|
433
418
|
};
|
|
419
|
+
var LF = 10;
|
|
420
|
+
var CR = 13;
|
|
421
|
+
var SPACE = 32;
|
|
434
422
|
function noop(_arg) {
|
|
435
423
|
}
|
|
436
|
-
function createParser(
|
|
437
|
-
if (typeof
|
|
424
|
+
function createParser(config) {
|
|
425
|
+
if (typeof config == "function")
|
|
438
426
|
throw new TypeError(
|
|
439
|
-
"`
|
|
427
|
+
"`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?"
|
|
440
428
|
);
|
|
441
|
-
const { onEvent = noop, onError = noop, onRetry = noop, onComment } =
|
|
442
|
-
let
|
|
443
|
-
function feed(
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
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) {
|
|
451
501
|
dispatchEvent();
|
|
452
502
|
return;
|
|
453
503
|
}
|
|
454
|
-
|
|
455
|
-
|
|
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++;
|
|
456
509
|
return;
|
|
457
510
|
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
const field = line.slice(0, fieldSeparatorIndex), offset = line[fieldSeparatorIndex + 1] === " " ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
|
|
461
|
-
processField(field, value, line);
|
|
511
|
+
if (isEventPrefix(chunk, start, firstCharCode)) {
|
|
512
|
+
eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
|
|
462
513
|
return;
|
|
463
514
|
}
|
|
464
|
-
|
|
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
|
+
}
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
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);
|
|
465
534
|
}
|
|
466
535
|
function processField(field, value, line) {
|
|
467
536
|
switch (field) {
|
|
468
537
|
case "event":
|
|
469
|
-
eventType = value;
|
|
538
|
+
eventType = value || void 0;
|
|
470
539
|
break;
|
|
471
540
|
case "data":
|
|
472
|
-
data = `${data}
|
|
473
|
-
|
|
541
|
+
data = dataLines === 0 ? value : `${data}
|
|
542
|
+
${value}`, dataLines++;
|
|
474
543
|
break;
|
|
475
544
|
case "id":
|
|
476
545
|
id = value.includes("\0") ? void 0 : value;
|
|
@@ -495,42 +564,31 @@ function createParser(callbacks) {
|
|
|
495
564
|
}
|
|
496
565
|
}
|
|
497
566
|
function dispatchEvent() {
|
|
498
|
-
|
|
567
|
+
dataLines > 0 && onEvent({
|
|
499
568
|
id,
|
|
500
|
-
event: eventType
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
data: data.endsWith(`
|
|
504
|
-
`) ? data.slice(0, -1) : data
|
|
505
|
-
}), id = void 0, data = "", eventType = "";
|
|
569
|
+
event: eventType,
|
|
570
|
+
data
|
|
571
|
+
}), id = void 0, data = "", dataLines = 0, eventType = void 0;
|
|
506
572
|
}
|
|
507
573
|
function reset(options = {}) {
|
|
508
|
-
|
|
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;
|
|
509
579
|
}
|
|
510
580
|
return { feed, reset };
|
|
511
581
|
}
|
|
512
|
-
function
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
`, searchIndex);
|
|
518
|
-
let lineEnd = -1;
|
|
519
|
-
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) {
|
|
520
|
-
incompleteLine = chunk.slice(searchIndex);
|
|
521
|
-
break;
|
|
522
|
-
} else {
|
|
523
|
-
const line = chunk.slice(searchIndex, lineEnd);
|
|
524
|
-
lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
|
|
525
|
-
` && searchIndex++;
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
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;
|
|
529
587
|
}
|
|
530
588
|
|
|
531
|
-
// node_modules/.pnpm/eventsource-parser@3.0
|
|
589
|
+
// node_modules/.pnpm/eventsource-parser@3.1.0/node_modules/eventsource-parser/dist/stream.js
|
|
532
590
|
var EventSourceParserStream = class extends TransformStream {
|
|
533
|
-
constructor({ onError, onRetry, onComment } = {}) {
|
|
591
|
+
constructor({ onError, onRetry, onComment, maxBufferSize } = {}) {
|
|
534
592
|
let parser;
|
|
535
593
|
super({
|
|
536
594
|
start(controller) {
|
|
@@ -539,10 +597,11 @@ var EventSourceParserStream = class extends TransformStream {
|
|
|
539
597
|
controller.enqueue(event);
|
|
540
598
|
},
|
|
541
599
|
onError(error) {
|
|
542
|
-
onError
|
|
600
|
+
typeof onError == "function" && onError(error), (onError === "terminate" || error.type === "max-buffer-size-exceeded") && controller.error(error);
|
|
543
601
|
},
|
|
544
602
|
onRetry,
|
|
545
|
-
onComment
|
|
603
|
+
onComment,
|
|
604
|
+
maxBufferSize
|
|
546
605
|
});
|
|
547
606
|
},
|
|
548
607
|
transform(chunk) {
|
|
@@ -552,13 +611,25 @@ var EventSourceParserStream = class extends TransformStream {
|
|
|
552
611
|
}
|
|
553
612
|
};
|
|
554
613
|
|
|
555
|
-
// 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
|
|
556
619
|
function combineHeaders(...headers) {
|
|
557
620
|
return headers.reduce(
|
|
558
621
|
(combinedHeaders, currentHeaders) => __spreadValues(__spreadValues({}, combinedHeaders), currentHeaders != null ? currentHeaders : {}),
|
|
559
622
|
{}
|
|
560
623
|
);
|
|
561
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
|
+
}
|
|
562
633
|
async function delay(delayInMs, options) {
|
|
563
634
|
if (delayInMs == null) {
|
|
564
635
|
return Promise.resolve();
|
|
@@ -587,23 +658,12 @@ async function delay(delayInMs, options) {
|
|
|
587
658
|
function createAbortError() {
|
|
588
659
|
return new DOMException("Delay was aborted", "AbortError");
|
|
589
660
|
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
var
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
for (let i = 0; i < array.length; i++) {
|
|
597
|
-
latin1string += String.fromCodePoint(array[i]);
|
|
598
|
-
}
|
|
599
|
-
return btoa(latin1string);
|
|
600
|
-
}
|
|
601
|
-
var name14 = "AI_DownloadError";
|
|
602
|
-
var marker15 = `vercel.ai.error.${name14}`;
|
|
603
|
-
var symbol15 = Symbol.for(marker15);
|
|
604
|
-
var _a15;
|
|
605
|
-
var _b15;
|
|
606
|
-
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) {
|
|
607
667
|
constructor({
|
|
608
668
|
url,
|
|
609
669
|
statusCode,
|
|
@@ -611,17 +671,20 @@ var DownloadError = class extends (_b15 = AISDKError, _a15 = symbol15, _b15) {
|
|
|
611
671
|
cause,
|
|
612
672
|
message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}`
|
|
613
673
|
}) {
|
|
614
|
-
super({ name:
|
|
615
|
-
this[
|
|
674
|
+
super({ name: name15, message, cause });
|
|
675
|
+
this[_a16] = true;
|
|
616
676
|
this.url = url;
|
|
617
677
|
this.statusCode = statusCode;
|
|
618
678
|
this.statusText = statusText;
|
|
619
679
|
}
|
|
620
680
|
static isInstance(error) {
|
|
621
|
-
return AISDKError.hasMarker(error,
|
|
681
|
+
return AISDKError.hasMarker(error, marker16);
|
|
622
682
|
}
|
|
623
683
|
};
|
|
624
684
|
var DEFAULT_MAX_DOWNLOAD_SIZE = 2 * 1024 * 1024 * 1024;
|
|
685
|
+
function extractResponseHeaders(response) {
|
|
686
|
+
return Object.fromEntries([...response.headers]);
|
|
687
|
+
}
|
|
625
688
|
var createIdGenerator = ({
|
|
626
689
|
prefix,
|
|
627
690
|
size = 16,
|
|
@@ -750,7 +813,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
750
813
|
);
|
|
751
814
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
752
815
|
}
|
|
753
|
-
var VERSION = true ? "
|
|
816
|
+
var VERSION = true ? "5.0.0" : "0.0.0-test";
|
|
754
817
|
var getOriginalFetch = () => globalThis.fetch;
|
|
755
818
|
var getFromApi = async ({
|
|
756
819
|
url,
|
|
@@ -935,7 +998,7 @@ function parseArrayDef(def, refs) {
|
|
|
935
998
|
const res = {
|
|
936
999
|
type: "array"
|
|
937
1000
|
};
|
|
938
|
-
if (((_a22 = def.type) == null ? void 0 : _a22._def) && ((_c = (_b22 = def.type) == null ? void 0 : _b22._def) == null ? void 0 : _c.typeName) !==
|
|
1001
|
+
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) {
|
|
939
1002
|
res.items = parseDef(def.type._def, __spreadProps(__spreadValues({}, refs), {
|
|
940
1003
|
currentPath: [...refs.currentPath, "items"]
|
|
941
1004
|
}));
|
|
@@ -994,7 +1057,7 @@ function parseDateDef(def, refs, overrideDateStrategy) {
|
|
|
994
1057
|
const strategy = overrideDateStrategy != null ? overrideDateStrategy : refs.dateStrategy;
|
|
995
1058
|
if (Array.isArray(strategy)) {
|
|
996
1059
|
return {
|
|
997
|
-
anyOf: strategy.map((item
|
|
1060
|
+
anyOf: strategy.map((item) => parseDateDef(def, refs, item))
|
|
998
1061
|
};
|
|
999
1062
|
}
|
|
1000
1063
|
switch (strategy) {
|
|
@@ -1064,7 +1127,7 @@ function parseIntersectionDef(def, refs) {
|
|
|
1064
1127
|
} else {
|
|
1065
1128
|
let nestedSchema = schema;
|
|
1066
1129
|
if ("additionalProperties" in schema && schema.additionalProperties === false) {
|
|
1067
|
-
const
|
|
1130
|
+
const _a17 = schema, { additionalProperties: _additionalProperties } = _a17, rest = __objRest(_a17, ["additionalProperties"]);
|
|
1068
1131
|
nestedSchema = rest;
|
|
1069
1132
|
}
|
|
1070
1133
|
mergedAllOf.push(nestedSchema);
|
|
@@ -1424,22 +1487,22 @@ function parseRecordDef(def, refs) {
|
|
|
1424
1487
|
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1425
1488
|
}))) != null ? _a22 : refs.allowedAdditionalProperties
|
|
1426
1489
|
};
|
|
1427
|
-
if (((_b22 = def.keyType) == null ? void 0 : _b22._def.typeName) ===
|
|
1428
|
-
const
|
|
1490
|
+
if (((_b22 = def.keyType) == null ? void 0 : _b22._def.typeName) === ZodFirstPartyTypeKind2.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
|
|
1491
|
+
const _a17 = parseStringDef(def.keyType._def, refs), { type: _type } = _a17, keyType = __objRest(_a17, ["type"]);
|
|
1429
1492
|
return __spreadProps(__spreadValues({}, schema), {
|
|
1430
1493
|
propertyNames: keyType
|
|
1431
1494
|
});
|
|
1432
|
-
} else if (((_d = def.keyType) == null ? void 0 : _d._def.typeName) ===
|
|
1495
|
+
} else if (((_d = def.keyType) == null ? void 0 : _d._def.typeName) === ZodFirstPartyTypeKind2.ZodEnum) {
|
|
1433
1496
|
return __spreadProps(__spreadValues({}, schema), {
|
|
1434
1497
|
propertyNames: {
|
|
1435
1498
|
enum: def.keyType._def.values
|
|
1436
1499
|
}
|
|
1437
1500
|
});
|
|
1438
|
-
} else if (((_e = def.keyType) == null ? void 0 : _e._def.typeName) ===
|
|
1439
|
-
const
|
|
1501
|
+
} 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)) {
|
|
1502
|
+
const _b17 = parseBrandedDef(
|
|
1440
1503
|
def.keyType._def,
|
|
1441
1504
|
refs
|
|
1442
|
-
), { type } =
|
|
1505
|
+
), { type: _type } = _b17, keyType = __objRest(_b17, ["type"]);
|
|
1443
1506
|
return __spreadProps(__spreadValues({}, schema), {
|
|
1444
1507
|
propertyNames: keyType
|
|
1445
1508
|
});
|
|
@@ -1685,14 +1748,16 @@ var parsePipelineDef = (def, refs) => {
|
|
|
1685
1748
|
} else if (refs.pipeStrategy === "output") {
|
|
1686
1749
|
return parseDef(def.out._def, refs);
|
|
1687
1750
|
}
|
|
1688
|
-
const
|
|
1751
|
+
const inputSchema = parseDef(def.in._def, __spreadProps(__spreadValues({}, refs), {
|
|
1689
1752
|
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
1690
1753
|
}));
|
|
1691
|
-
const
|
|
1692
|
-
currentPath: [...refs.currentPath, "allOf",
|
|
1754
|
+
const outputSchema = parseDef(def.out._def, __spreadProps(__spreadValues({}, refs), {
|
|
1755
|
+
currentPath: [...refs.currentPath, "allOf", inputSchema ? "1" : "0"]
|
|
1693
1756
|
}));
|
|
1694
1757
|
return {
|
|
1695
|
-
allOf: [
|
|
1758
|
+
allOf: [inputSchema, outputSchema].filter(
|
|
1759
|
+
(schema) => schema !== void 0
|
|
1760
|
+
)
|
|
1696
1761
|
};
|
|
1697
1762
|
};
|
|
1698
1763
|
function parsePromiseDef(def, refs) {
|
|
@@ -1761,73 +1826,73 @@ var parseReadonlyDef = (def, refs) => {
|
|
|
1761
1826
|
};
|
|
1762
1827
|
var selectParser = (def, typeName, refs) => {
|
|
1763
1828
|
switch (typeName) {
|
|
1764
|
-
case
|
|
1829
|
+
case ZodFirstPartyTypeKind3.ZodString:
|
|
1765
1830
|
return parseStringDef(def, refs);
|
|
1766
|
-
case
|
|
1831
|
+
case ZodFirstPartyTypeKind3.ZodNumber:
|
|
1767
1832
|
return parseNumberDef(def);
|
|
1768
|
-
case
|
|
1833
|
+
case ZodFirstPartyTypeKind3.ZodObject:
|
|
1769
1834
|
return parseObjectDef(def, refs);
|
|
1770
|
-
case
|
|
1835
|
+
case ZodFirstPartyTypeKind3.ZodBigInt:
|
|
1771
1836
|
return parseBigintDef(def);
|
|
1772
|
-
case
|
|
1837
|
+
case ZodFirstPartyTypeKind3.ZodBoolean:
|
|
1773
1838
|
return parseBooleanDef();
|
|
1774
|
-
case
|
|
1839
|
+
case ZodFirstPartyTypeKind3.ZodDate:
|
|
1775
1840
|
return parseDateDef(def, refs);
|
|
1776
|
-
case
|
|
1841
|
+
case ZodFirstPartyTypeKind3.ZodUndefined:
|
|
1777
1842
|
return parseUndefinedDef();
|
|
1778
|
-
case
|
|
1843
|
+
case ZodFirstPartyTypeKind3.ZodNull:
|
|
1779
1844
|
return parseNullDef();
|
|
1780
|
-
case
|
|
1845
|
+
case ZodFirstPartyTypeKind3.ZodArray:
|
|
1781
1846
|
return parseArrayDef(def, refs);
|
|
1782
|
-
case
|
|
1783
|
-
case
|
|
1847
|
+
case ZodFirstPartyTypeKind3.ZodUnion:
|
|
1848
|
+
case ZodFirstPartyTypeKind3.ZodDiscriminatedUnion:
|
|
1784
1849
|
return parseUnionDef(def, refs);
|
|
1785
|
-
case
|
|
1850
|
+
case ZodFirstPartyTypeKind3.ZodIntersection:
|
|
1786
1851
|
return parseIntersectionDef(def, refs);
|
|
1787
|
-
case
|
|
1852
|
+
case ZodFirstPartyTypeKind3.ZodTuple:
|
|
1788
1853
|
return parseTupleDef(def, refs);
|
|
1789
|
-
case
|
|
1854
|
+
case ZodFirstPartyTypeKind3.ZodRecord:
|
|
1790
1855
|
return parseRecordDef(def, refs);
|
|
1791
|
-
case
|
|
1856
|
+
case ZodFirstPartyTypeKind3.ZodLiteral:
|
|
1792
1857
|
return parseLiteralDef(def);
|
|
1793
|
-
case
|
|
1858
|
+
case ZodFirstPartyTypeKind3.ZodEnum:
|
|
1794
1859
|
return parseEnumDef(def);
|
|
1795
|
-
case
|
|
1860
|
+
case ZodFirstPartyTypeKind3.ZodNativeEnum:
|
|
1796
1861
|
return parseNativeEnumDef(def);
|
|
1797
|
-
case
|
|
1862
|
+
case ZodFirstPartyTypeKind3.ZodNullable:
|
|
1798
1863
|
return parseNullableDef(def, refs);
|
|
1799
|
-
case
|
|
1864
|
+
case ZodFirstPartyTypeKind3.ZodOptional:
|
|
1800
1865
|
return parseOptionalDef(def, refs);
|
|
1801
|
-
case
|
|
1866
|
+
case ZodFirstPartyTypeKind3.ZodMap:
|
|
1802
1867
|
return parseMapDef(def, refs);
|
|
1803
|
-
case
|
|
1868
|
+
case ZodFirstPartyTypeKind3.ZodSet:
|
|
1804
1869
|
return parseSetDef(def, refs);
|
|
1805
|
-
case
|
|
1870
|
+
case ZodFirstPartyTypeKind3.ZodLazy:
|
|
1806
1871
|
return () => def.getter()._def;
|
|
1807
|
-
case
|
|
1872
|
+
case ZodFirstPartyTypeKind3.ZodPromise:
|
|
1808
1873
|
return parsePromiseDef(def, refs);
|
|
1809
|
-
case
|
|
1810
|
-
case
|
|
1874
|
+
case ZodFirstPartyTypeKind3.ZodNaN:
|
|
1875
|
+
case ZodFirstPartyTypeKind3.ZodNever:
|
|
1811
1876
|
return parseNeverDef();
|
|
1812
|
-
case
|
|
1877
|
+
case ZodFirstPartyTypeKind3.ZodEffects:
|
|
1813
1878
|
return parseEffectsDef(def, refs);
|
|
1814
|
-
case
|
|
1879
|
+
case ZodFirstPartyTypeKind3.ZodAny:
|
|
1815
1880
|
return parseAnyDef();
|
|
1816
|
-
case
|
|
1881
|
+
case ZodFirstPartyTypeKind3.ZodUnknown:
|
|
1817
1882
|
return parseUnknownDef();
|
|
1818
|
-
case
|
|
1883
|
+
case ZodFirstPartyTypeKind3.ZodDefault:
|
|
1819
1884
|
return parseDefaultDef(def, refs);
|
|
1820
|
-
case
|
|
1885
|
+
case ZodFirstPartyTypeKind3.ZodBranded:
|
|
1821
1886
|
return parseBrandedDef(def, refs);
|
|
1822
|
-
case
|
|
1887
|
+
case ZodFirstPartyTypeKind3.ZodReadonly:
|
|
1823
1888
|
return parseReadonlyDef(def, refs);
|
|
1824
|
-
case
|
|
1889
|
+
case ZodFirstPartyTypeKind3.ZodCatch:
|
|
1825
1890
|
return parseCatchDef(def, refs);
|
|
1826
|
-
case
|
|
1891
|
+
case ZodFirstPartyTypeKind3.ZodPipeline:
|
|
1827
1892
|
return parsePipelineDef(def, refs);
|
|
1828
|
-
case
|
|
1829
|
-
case
|
|
1830
|
-
case
|
|
1893
|
+
case ZodFirstPartyTypeKind3.ZodFunction:
|
|
1894
|
+
case ZodFirstPartyTypeKind3.ZodVoid:
|
|
1895
|
+
case ZodFirstPartyTypeKind3.ZodSymbol:
|
|
1831
1896
|
return void 0;
|
|
1832
1897
|
default:
|
|
1833
1898
|
return /* @__PURE__ */ ((_) => void 0)(typeName);
|
|
@@ -1987,7 +2052,11 @@ function isSchema(value) {
|
|
|
1987
2052
|
return typeof value === "object" && value !== null && schemaSymbol in value && value[schemaSymbol] === true && "jsonSchema" in value && "validate" in value;
|
|
1988
2053
|
}
|
|
1989
2054
|
function asSchema(schema) {
|
|
1990
|
-
return schema == null ? jsonSchema({
|
|
2055
|
+
return schema == null ? jsonSchema({
|
|
2056
|
+
type: "object",
|
|
2057
|
+
properties: {},
|
|
2058
|
+
additionalProperties: false
|
|
2059
|
+
}) : isSchema(schema) ? schema : "~standard" in schema ? schema["~standard"].vendor === "zod" ? zodSchema(schema) : standardSchema(schema) : schema();
|
|
1991
2060
|
}
|
|
1992
2061
|
function standardSchema(standardSchema2) {
|
|
1993
2062
|
return jsonSchema(
|
|
@@ -2103,7 +2172,7 @@ async function parseJSON({
|
|
|
2103
2172
|
if (schema == null) {
|
|
2104
2173
|
return value;
|
|
2105
2174
|
}
|
|
2106
|
-
return validateTypes({ value, schema });
|
|
2175
|
+
return await validateTypes({ value, schema });
|
|
2107
2176
|
} catch (error) {
|
|
2108
2177
|
if (JSONParseError.isInstance(error) || TypeValidationError.isInstance(error)) {
|
|
2109
2178
|
throw error;
|
|
@@ -2161,7 +2230,7 @@ var postJsonToApi = async ({
|
|
|
2161
2230
|
successfulResponseHandler,
|
|
2162
2231
|
abortSignal,
|
|
2163
2232
|
fetch: fetch2
|
|
2164
|
-
}) => postToApi({
|
|
2233
|
+
}) => await postToApi({
|
|
2165
2234
|
url,
|
|
2166
2235
|
headers: __spreadValues({
|
|
2167
2236
|
"Content-Type": "application/json"
|
|
@@ -2283,7 +2352,7 @@ var createJsonErrorResponseHandler = ({
|
|
|
2283
2352
|
isRetryable: isRetryable == null ? void 0 : isRetryable(response, parsedError)
|
|
2284
2353
|
})
|
|
2285
2354
|
};
|
|
2286
|
-
} catch (
|
|
2355
|
+
} catch (e) {
|
|
2287
2356
|
return {
|
|
2288
2357
|
responseHeaders,
|
|
2289
2358
|
value: new APICallError({
|
|
@@ -2337,7 +2406,7 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
|
|
|
2337
2406
|
};
|
|
2338
2407
|
|
|
2339
2408
|
// src/schemas/reasoning-details.ts
|
|
2340
|
-
|
|
2409
|
+
import { z } from "zod/v4";
|
|
2341
2410
|
|
|
2342
2411
|
// src/utils/type-guards.ts
|
|
2343
2412
|
function isDefinedOrNotNull(value) {
|
|
@@ -2357,63 +2426,63 @@ var ReasoningFormat = /* @__PURE__ */ ((ReasoningFormat2) => {
|
|
|
2357
2426
|
var DEFAULT_REASONING_FORMAT = "anthropic-claude-v1" /* AnthropicClaudeV1 */;
|
|
2358
2427
|
|
|
2359
2428
|
// src/schemas/reasoning-details.ts
|
|
2360
|
-
var CommonReasoningDetailSchema =
|
|
2361
|
-
id:
|
|
2362
|
-
format:
|
|
2363
|
-
index:
|
|
2429
|
+
var CommonReasoningDetailSchema = z.object({
|
|
2430
|
+
id: z.string().nullish(),
|
|
2431
|
+
format: z.enum(ReasoningFormat).nullish(),
|
|
2432
|
+
index: z.number().optional()
|
|
2364
2433
|
}).loose();
|
|
2365
|
-
var ReasoningDetailSummarySchema =
|
|
2366
|
-
type:
|
|
2367
|
-
summary:
|
|
2434
|
+
var ReasoningDetailSummarySchema = z.object({
|
|
2435
|
+
type: z.literal("reasoning.summary" /* Summary */),
|
|
2436
|
+
summary: z.string()
|
|
2368
2437
|
}).extend(CommonReasoningDetailSchema.shape);
|
|
2369
|
-
var ReasoningDetailEncryptedSchema =
|
|
2370
|
-
type:
|
|
2371
|
-
data:
|
|
2438
|
+
var ReasoningDetailEncryptedSchema = z.object({
|
|
2439
|
+
type: z.literal("reasoning.encrypted" /* Encrypted */),
|
|
2440
|
+
data: z.string()
|
|
2372
2441
|
}).extend(CommonReasoningDetailSchema.shape);
|
|
2373
|
-
var ReasoningDetailTextSchema =
|
|
2374
|
-
type:
|
|
2375
|
-
text:
|
|
2376
|
-
signature:
|
|
2442
|
+
var ReasoningDetailTextSchema = z.object({
|
|
2443
|
+
type: z.literal("reasoning.text" /* Text */),
|
|
2444
|
+
text: z.string().nullish(),
|
|
2445
|
+
signature: z.string().nullish()
|
|
2377
2446
|
}).extend(CommonReasoningDetailSchema.shape);
|
|
2378
|
-
var ReasoningDetailUnionSchema =
|
|
2447
|
+
var ReasoningDetailUnionSchema = z.union([
|
|
2379
2448
|
ReasoningDetailSummarySchema,
|
|
2380
2449
|
ReasoningDetailEncryptedSchema,
|
|
2381
2450
|
ReasoningDetailTextSchema
|
|
2382
2451
|
]);
|
|
2383
|
-
var ReasoningDetailsWithUnknownSchema =
|
|
2452
|
+
var ReasoningDetailsWithUnknownSchema = z.union([
|
|
2384
2453
|
ReasoningDetailUnionSchema,
|
|
2385
|
-
|
|
2454
|
+
z.unknown().transform(() => null)
|
|
2386
2455
|
]);
|
|
2387
|
-
var ReasoningDetailArraySchema =
|
|
2388
|
-
var OutputUnionToReasoningDetailsSchema =
|
|
2389
|
-
|
|
2390
|
-
delta:
|
|
2391
|
-
reasoning_details:
|
|
2456
|
+
var ReasoningDetailArraySchema = z.array(ReasoningDetailsWithUnknownSchema).transform((d) => d.filter((d2) => !!d2));
|
|
2457
|
+
var OutputUnionToReasoningDetailsSchema = z.union([
|
|
2458
|
+
z.object({
|
|
2459
|
+
delta: z.object({
|
|
2460
|
+
reasoning_details: z.array(ReasoningDetailsWithUnknownSchema)
|
|
2392
2461
|
})
|
|
2393
2462
|
}).transform(
|
|
2394
2463
|
(data) => data.delta.reasoning_details.filter(isDefinedOrNotNull)
|
|
2395
2464
|
),
|
|
2396
|
-
|
|
2397
|
-
message:
|
|
2398
|
-
reasoning_details:
|
|
2465
|
+
z.object({
|
|
2466
|
+
message: z.object({
|
|
2467
|
+
reasoning_details: z.array(ReasoningDetailsWithUnknownSchema)
|
|
2399
2468
|
})
|
|
2400
2469
|
}).transform(
|
|
2401
2470
|
(data) => data.message.reasoning_details.filter(isDefinedOrNotNull)
|
|
2402
2471
|
),
|
|
2403
|
-
|
|
2404
|
-
text:
|
|
2405
|
-
reasoning_details:
|
|
2472
|
+
z.object({
|
|
2473
|
+
text: z.string(),
|
|
2474
|
+
reasoning_details: z.array(ReasoningDetailsWithUnknownSchema)
|
|
2406
2475
|
}).transform((data) => data.reasoning_details.filter(isDefinedOrNotNull))
|
|
2407
2476
|
]);
|
|
2408
2477
|
|
|
2409
2478
|
// src/schemas/error-response.ts
|
|
2410
|
-
|
|
2411
|
-
var OpenRouterErrorResponseSchema =
|
|
2412
|
-
error:
|
|
2413
|
-
code:
|
|
2414
|
-
message:
|
|
2415
|
-
type:
|
|
2416
|
-
param:
|
|
2479
|
+
import { z as z2 } from "zod/v4";
|
|
2480
|
+
var OpenRouterErrorResponseSchema = z2.object({
|
|
2481
|
+
error: z2.object({
|
|
2482
|
+
code: z2.union([z2.string(), z2.number()]).nullable().optional().default(null),
|
|
2483
|
+
message: z2.string(),
|
|
2484
|
+
type: z2.string().nullable().optional().default(null),
|
|
2485
|
+
param: z2.any().nullable().optional().default(null)
|
|
2417
2486
|
}).passthrough()
|
|
2418
2487
|
}).passthrough();
|
|
2419
2488
|
function extractErrorMessage(data) {
|
|
@@ -2471,56 +2540,56 @@ var openrouterFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
2471
2540
|
});
|
|
2472
2541
|
|
|
2473
2542
|
// src/schemas/provider-metadata.ts
|
|
2474
|
-
|
|
2475
|
-
var FileAnnotationSchema =
|
|
2476
|
-
type:
|
|
2477
|
-
file:
|
|
2478
|
-
hash:
|
|
2479
|
-
name:
|
|
2480
|
-
content:
|
|
2481
|
-
|
|
2482
|
-
type:
|
|
2483
|
-
text:
|
|
2484
|
-
}).catchall(
|
|
2543
|
+
import { z as z3 } from "zod/v4";
|
|
2544
|
+
var FileAnnotationSchema = z3.object({
|
|
2545
|
+
type: z3.literal("file"),
|
|
2546
|
+
file: z3.object({
|
|
2547
|
+
hash: z3.string(),
|
|
2548
|
+
name: z3.string(),
|
|
2549
|
+
content: z3.array(
|
|
2550
|
+
z3.object({
|
|
2551
|
+
type: z3.string(),
|
|
2552
|
+
text: z3.string().optional()
|
|
2553
|
+
}).catchall(z3.any())
|
|
2485
2554
|
).optional()
|
|
2486
|
-
}).catchall(
|
|
2487
|
-
}).catchall(
|
|
2488
|
-
var OpenRouterProviderMetadataSchema =
|
|
2489
|
-
provider:
|
|
2490
|
-
reasoning_details:
|
|
2491
|
-
annotations:
|
|
2492
|
-
usage:
|
|
2493
|
-
promptTokens:
|
|
2494
|
-
promptTokensDetails:
|
|
2495
|
-
cachedTokens:
|
|
2496
|
-
}).catchall(
|
|
2497
|
-
completionTokens:
|
|
2498
|
-
completionTokensDetails:
|
|
2499
|
-
reasoningTokens:
|
|
2500
|
-
}).catchall(
|
|
2501
|
-
totalTokens:
|
|
2502
|
-
cost:
|
|
2503
|
-
costDetails:
|
|
2504
|
-
upstreamInferenceCost:
|
|
2505
|
-
}).catchall(
|
|
2506
|
-
}).catchall(
|
|
2507
|
-
}).catchall(
|
|
2508
|
-
var OpenRouterProviderOptionsSchema =
|
|
2509
|
-
openrouter:
|
|
2555
|
+
}).catchall(z3.any())
|
|
2556
|
+
}).catchall(z3.any());
|
|
2557
|
+
var OpenRouterProviderMetadataSchema = z3.object({
|
|
2558
|
+
provider: z3.string(),
|
|
2559
|
+
reasoning_details: z3.array(ReasoningDetailUnionSchema).optional(),
|
|
2560
|
+
annotations: z3.array(FileAnnotationSchema).optional(),
|
|
2561
|
+
usage: z3.object({
|
|
2562
|
+
promptTokens: z3.number(),
|
|
2563
|
+
promptTokensDetails: z3.object({
|
|
2564
|
+
cachedTokens: z3.number()
|
|
2565
|
+
}).catchall(z3.any()).optional(),
|
|
2566
|
+
completionTokens: z3.number(),
|
|
2567
|
+
completionTokensDetails: z3.object({
|
|
2568
|
+
reasoningTokens: z3.number()
|
|
2569
|
+
}).catchall(z3.any()).optional(),
|
|
2570
|
+
totalTokens: z3.number(),
|
|
2571
|
+
cost: z3.number().optional(),
|
|
2572
|
+
costDetails: z3.object({
|
|
2573
|
+
upstreamInferenceCost: z3.number()
|
|
2574
|
+
}).catchall(z3.any()).optional()
|
|
2575
|
+
}).catchall(z3.any())
|
|
2576
|
+
}).catchall(z3.any());
|
|
2577
|
+
var OpenRouterProviderOptionsSchema = z3.object({
|
|
2578
|
+
openrouter: z3.object({
|
|
2510
2579
|
// Use ReasoningDetailArraySchema (with unknown fallback) instead of
|
|
2511
2580
|
// z.array(ReasoningDetailUnionSchema) so that a single malformed entry
|
|
2512
2581
|
// (e.g., a future format not yet in the enum) is individually dropped
|
|
2513
2582
|
// rather than causing the entire array to fail parsing.
|
|
2514
2583
|
reasoning_details: ReasoningDetailArraySchema.optional(),
|
|
2515
|
-
annotations:
|
|
2584
|
+
annotations: z3.array(FileAnnotationSchema).optional()
|
|
2516
2585
|
}).optional()
|
|
2517
2586
|
}).optional();
|
|
2518
2587
|
|
|
2519
2588
|
// src/utils/compute-token-usage.ts
|
|
2520
2589
|
function computeTokenUsage(usage) {
|
|
2521
|
-
var
|
|
2522
|
-
const promptTokens = (
|
|
2523
|
-
const completionTokens = (
|
|
2590
|
+
var _a17, _b17, _c, _d, _e, _f, _g, _h;
|
|
2591
|
+
const promptTokens = (_a17 = usage.prompt_tokens) != null ? _a17 : 0;
|
|
2592
|
+
const completionTokens = (_b17 = usage.completion_tokens) != null ? _b17 : 0;
|
|
2524
2593
|
const cacheReadTokens = (_d = (_c = usage.prompt_tokens_details) == null ? void 0 : _c.cached_tokens) != null ? _d : 0;
|
|
2525
2594
|
const cacheWriteTokens = (_f = (_e = usage.prompt_tokens_details) == null ? void 0 : _e.cache_write_tokens) != null ? _f : void 0;
|
|
2526
2595
|
const reasoningTokens = (_h = (_g = usage.completion_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : 0;
|
|
@@ -2727,17 +2796,60 @@ function getFileUrl({
|
|
|
2727
2796
|
part,
|
|
2728
2797
|
defaultMediaType
|
|
2729
2798
|
}) {
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
data,
|
|
2799
|
+
return getFileDataUrl({
|
|
2800
|
+
data: part.data,
|
|
2733
2801
|
mediaType: part.mediaType,
|
|
2734
2802
|
defaultMediaType
|
|
2735
2803
|
});
|
|
2736
2804
|
}
|
|
2805
|
+
function getFileDataUrl({
|
|
2806
|
+
data,
|
|
2807
|
+
mediaType,
|
|
2808
|
+
defaultMediaType
|
|
2809
|
+
}) {
|
|
2810
|
+
switch (data.type) {
|
|
2811
|
+
case "data":
|
|
2812
|
+
return buildFileDataUrl({
|
|
2813
|
+
data: data.data,
|
|
2814
|
+
mediaType,
|
|
2815
|
+
defaultMediaType
|
|
2816
|
+
});
|
|
2817
|
+
case "url": {
|
|
2818
|
+
const url = data.url.toString();
|
|
2819
|
+
if (url.startsWith("data:") || isUrl({
|
|
2820
|
+
url,
|
|
2821
|
+
protocols: /* @__PURE__ */ new Set(["http:", "https:"])
|
|
2822
|
+
})) {
|
|
2823
|
+
return url;
|
|
2824
|
+
}
|
|
2825
|
+
throw new Error(
|
|
2826
|
+
"Only http(s) and data: file URLs are supported by OpenRouter"
|
|
2827
|
+
);
|
|
2828
|
+
}
|
|
2829
|
+
case "text": {
|
|
2830
|
+
const encoded = new TextEncoder().encode(data.text);
|
|
2831
|
+
return buildFileDataUrl({
|
|
2832
|
+
data: encoded,
|
|
2833
|
+
mediaType: mediaType != null ? mediaType : "text/plain",
|
|
2834
|
+
defaultMediaType
|
|
2835
|
+
});
|
|
2836
|
+
}
|
|
2837
|
+
case "reference":
|
|
2838
|
+
throw new Error(
|
|
2839
|
+
"Provider file references are not supported by OpenRouter"
|
|
2840
|
+
);
|
|
2841
|
+
}
|
|
2842
|
+
const _exhaustiveCheck = data;
|
|
2843
|
+
return buildFileDataUrl({
|
|
2844
|
+
data: _exhaustiveCheck,
|
|
2845
|
+
mediaType,
|
|
2846
|
+
defaultMediaType
|
|
2847
|
+
});
|
|
2848
|
+
}
|
|
2737
2849
|
function getMediaType(dataUrl, defaultMediaType) {
|
|
2738
|
-
var
|
|
2850
|
+
var _a17;
|
|
2739
2851
|
const match = dataUrl.match(/^data:([^;]+)/);
|
|
2740
|
-
return match ? (
|
|
2852
|
+
return match ? (_a17 = match[1]) != null ? _a17 : defaultMediaType : defaultMediaType;
|
|
2741
2853
|
}
|
|
2742
2854
|
function getBase64FromDataUrl(dataUrl) {
|
|
2743
2855
|
const match = dataUrl.match(/^data:[^;]*;base64,(.+)$/);
|
|
@@ -2812,13 +2924,13 @@ Learn more: https://openrouter.ai/docs/features/multimodal/audio`
|
|
|
2812
2924
|
|
|
2813
2925
|
// src/chat/convert-to-openrouter-chat-messages.ts
|
|
2814
2926
|
function getCacheControl(providerMetadata) {
|
|
2815
|
-
var
|
|
2927
|
+
var _a17, _b17, _c;
|
|
2816
2928
|
const anthropic = providerMetadata == null ? void 0 : providerMetadata.anthropic;
|
|
2817
2929
|
const openrouter = providerMetadata == null ? void 0 : providerMetadata.openrouter;
|
|
2818
|
-
return (_c = (
|
|
2930
|
+
return (_c = (_b17 = (_a17 = openrouter == null ? void 0 : openrouter.cacheControl) != null ? _a17 : openrouter == null ? void 0 : openrouter.cache_control) != null ? _b17 : anthropic == null ? void 0 : anthropic.cacheControl) != null ? _c : anthropic == null ? void 0 : anthropic.cache_control;
|
|
2819
2931
|
}
|
|
2820
2932
|
function convertToOpenRouterChatMessages(prompt) {
|
|
2821
|
-
var
|
|
2933
|
+
var _a17, _b17, _c, _d, _e, _f, _g, _h;
|
|
2822
2934
|
const messages = [];
|
|
2823
2935
|
const reasoningDetailsTracker = new ReasoningDetailsDuplicateTracker();
|
|
2824
2936
|
for (const { role, content, providerOptions } of prompt) {
|
|
@@ -2837,8 +2949,8 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
2837
2949
|
break;
|
|
2838
2950
|
}
|
|
2839
2951
|
case "user": {
|
|
2840
|
-
if (content.length === 1 && ((
|
|
2841
|
-
const cacheControl = (
|
|
2952
|
+
if (content.length === 1 && ((_a17 = content[0]) == null ? void 0 : _a17.type) === "text") {
|
|
2953
|
+
const cacheControl = (_b17 = getCacheControl(providerOptions)) != null ? _b17 : getCacheControl(content[0].providerOptions);
|
|
2842
2954
|
const contentWithCacheControl = cacheControl ? [
|
|
2843
2955
|
{
|
|
2844
2956
|
type: "text",
|
|
@@ -2862,7 +2974,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
2862
2974
|
}
|
|
2863
2975
|
const contentParts = content.map(
|
|
2864
2976
|
(part, index) => {
|
|
2865
|
-
var
|
|
2977
|
+
var _a18, _b18, _c2, _d2, _e2, _f2, _g2;
|
|
2866
2978
|
const isLastTextPart = part.type === "text" && index === lastTextPartIndex;
|
|
2867
2979
|
const partCacheControl = getCacheControl(part.providerOptions);
|
|
2868
2980
|
const cacheControl = part.type === "text" ? partCacheControl != null ? partCacheControl : isLastTextPart ? messageCacheControl : void 0 : partCacheControl;
|
|
@@ -2873,7 +2985,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
2873
2985
|
text: part.text
|
|
2874
2986
|
}, cacheControl && { cache_control: cacheControl });
|
|
2875
2987
|
case "file": {
|
|
2876
|
-
if ((
|
|
2988
|
+
if ((_a18 = part.mediaType) == null ? void 0 : _a18.startsWith("image/")) {
|
|
2877
2989
|
const url = getFileUrl({
|
|
2878
2990
|
part,
|
|
2879
2991
|
defaultMediaType: "image/jpeg"
|
|
@@ -2885,7 +2997,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
2885
2997
|
}
|
|
2886
2998
|
}, cacheControl && { cache_control: cacheControl });
|
|
2887
2999
|
}
|
|
2888
|
-
if ((
|
|
3000
|
+
if ((_b18 = part.mediaType) == null ? void 0 : _b18.startsWith("video/")) {
|
|
2889
3001
|
const url = getFileUrl({
|
|
2890
3002
|
part,
|
|
2891
3003
|
defaultMediaType: "video/mp4"
|
|
@@ -2984,11 +3096,11 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
2984
3096
|
let finalReasoningDetails;
|
|
2985
3097
|
if (candidateReasoningDetails) {
|
|
2986
3098
|
const validDetails = candidateReasoningDetails.filter((detail) => {
|
|
2987
|
-
var
|
|
3099
|
+
var _a18;
|
|
2988
3100
|
if (detail.type !== "reasoning.text" /* Text */) {
|
|
2989
3101
|
return true;
|
|
2990
3102
|
}
|
|
2991
|
-
const format = (
|
|
3103
|
+
const format = (_a18 = detail.format) != null ? _a18 : DEFAULT_REASONING_FORMAT;
|
|
2992
3104
|
if (format !== "anthropic-claude-v1" /* AnthropicClaudeV1 */ && format !== "google-gemini-v1" /* GoogleGeminiV1 */) {
|
|
2993
3105
|
return true;
|
|
2994
3106
|
}
|
|
@@ -3046,7 +3158,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
3046
3158
|
return messages;
|
|
3047
3159
|
}
|
|
3048
3160
|
function getToolResultContent(input) {
|
|
3049
|
-
var
|
|
3161
|
+
var _a17;
|
|
3050
3162
|
switch (input.output.type) {
|
|
3051
3163
|
case "text":
|
|
3052
3164
|
case "error-text":
|
|
@@ -3057,44 +3169,28 @@ function getToolResultContent(input) {
|
|
|
3057
3169
|
case "content":
|
|
3058
3170
|
return mapToolResultContentParts(input.output.value);
|
|
3059
3171
|
case "execution-denied":
|
|
3060
|
-
return (
|
|
3172
|
+
return (_a17 = input.output.reason) != null ? _a17 : "Tool execution denied";
|
|
3061
3173
|
}
|
|
3062
3174
|
}
|
|
3063
3175
|
function mapToolResultContentParts(parts) {
|
|
3064
3176
|
return parts.map((part) => {
|
|
3065
|
-
var
|
|
3177
|
+
var _a17, _b17, _c, _d;
|
|
3066
3178
|
switch (part.type) {
|
|
3067
3179
|
case "text":
|
|
3068
3180
|
return { type: "text", text: part.text };
|
|
3069
|
-
case "
|
|
3070
|
-
|
|
3071
|
-
type: "image_url",
|
|
3072
|
-
image_url: {
|
|
3073
|
-
url: buildFileDataUrl({
|
|
3074
|
-
data: part.data,
|
|
3075
|
-
mediaType: part.mediaType,
|
|
3076
|
-
defaultMediaType: "image/jpeg"
|
|
3077
|
-
})
|
|
3078
|
-
}
|
|
3079
|
-
};
|
|
3080
|
-
case "image-url":
|
|
3081
|
-
return {
|
|
3082
|
-
type: "image_url",
|
|
3083
|
-
image_url: { url: part.url }
|
|
3084
|
-
};
|
|
3085
|
-
case "file-data": {
|
|
3086
|
-
const dataUrl = buildFileDataUrl({
|
|
3181
|
+
case "file": {
|
|
3182
|
+
const dataUrl = getFileDataUrl({
|
|
3087
3183
|
data: part.data,
|
|
3088
3184
|
mediaType: part.mediaType,
|
|
3089
3185
|
defaultMediaType: "application/octet-stream"
|
|
3090
3186
|
});
|
|
3091
|
-
if ((
|
|
3187
|
+
if ((_a17 = part.mediaType) == null ? void 0 : _a17.startsWith("image/")) {
|
|
3092
3188
|
return {
|
|
3093
3189
|
type: "image_url",
|
|
3094
3190
|
image_url: { url: dataUrl }
|
|
3095
3191
|
};
|
|
3096
3192
|
}
|
|
3097
|
-
if ((
|
|
3193
|
+
if ((_b17 = part.mediaType) == null ? void 0 : _b17.startsWith("video/")) {
|
|
3098
3194
|
return {
|
|
3099
3195
|
type: "video_url",
|
|
3100
3196
|
video_url: { url: dataUrl }
|
|
@@ -3121,23 +3217,6 @@ function mapToolResultContentParts(parts) {
|
|
|
3121
3217
|
}
|
|
3122
3218
|
};
|
|
3123
3219
|
}
|
|
3124
|
-
case "file-url": {
|
|
3125
|
-
if (looksLikeImageUrl(part.url)) {
|
|
3126
|
-
return {
|
|
3127
|
-
type: "image_url",
|
|
3128
|
-
image_url: { url: part.url }
|
|
3129
|
-
};
|
|
3130
|
-
}
|
|
3131
|
-
return {
|
|
3132
|
-
type: "file",
|
|
3133
|
-
file: {
|
|
3134
|
-
filename: filenameFromUrl(part.url),
|
|
3135
|
-
file_data: part.url
|
|
3136
|
-
}
|
|
3137
|
-
};
|
|
3138
|
-
}
|
|
3139
|
-
case "file-id":
|
|
3140
|
-
case "image-file-id":
|
|
3141
3220
|
case "custom":
|
|
3142
3221
|
return { type: "text", text: JSON.stringify(part) };
|
|
3143
3222
|
default: {
|
|
@@ -3147,46 +3226,14 @@ function mapToolResultContentParts(parts) {
|
|
|
3147
3226
|
}
|
|
3148
3227
|
});
|
|
3149
3228
|
}
|
|
3150
|
-
var IMAGE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
3151
|
-
"jpg",
|
|
3152
|
-
"jpeg",
|
|
3153
|
-
"png",
|
|
3154
|
-
"gif",
|
|
3155
|
-
"webp",
|
|
3156
|
-
"svg",
|
|
3157
|
-
"bmp",
|
|
3158
|
-
"ico",
|
|
3159
|
-
"tif",
|
|
3160
|
-
"tiff",
|
|
3161
|
-
"avif"
|
|
3162
|
-
]);
|
|
3163
|
-
function looksLikeImageUrl(url) {
|
|
3164
|
-
var _a16;
|
|
3165
|
-
try {
|
|
3166
|
-
const pathname = new URL(url).pathname;
|
|
3167
|
-
const ext = (_a16 = pathname.split(".").pop()) == null ? void 0 : _a16.toLowerCase();
|
|
3168
|
-
return ext !== void 0 && IMAGE_EXTENSIONS.has(ext);
|
|
3169
|
-
} catch (e) {
|
|
3170
|
-
return false;
|
|
3171
|
-
}
|
|
3172
|
-
}
|
|
3173
|
-
function filenameFromUrl(url) {
|
|
3174
|
-
try {
|
|
3175
|
-
const pathname = new URL(url).pathname;
|
|
3176
|
-
const last = pathname.split("/").pop();
|
|
3177
|
-
return (last == null ? void 0 : last.includes(".")) ? last : "";
|
|
3178
|
-
} catch (e) {
|
|
3179
|
-
return "";
|
|
3180
|
-
}
|
|
3181
|
-
}
|
|
3182
3229
|
function findFirstReasoningDetails(content) {
|
|
3183
|
-
var
|
|
3230
|
+
var _a17, _b17, _c, _d;
|
|
3184
3231
|
for (const part of content) {
|
|
3185
3232
|
if (part.type === "tool-call") {
|
|
3186
3233
|
const parsed = OpenRouterProviderOptionsSchema.safeParse(
|
|
3187
3234
|
part.providerOptions
|
|
3188
3235
|
);
|
|
3189
|
-
if (parsed.success && ((
|
|
3236
|
+
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) {
|
|
3190
3237
|
return parsed.data.openrouter.reasoning_details;
|
|
3191
3238
|
}
|
|
3192
3239
|
}
|
|
@@ -3205,15 +3252,15 @@ function findFirstReasoningDetails(content) {
|
|
|
3205
3252
|
}
|
|
3206
3253
|
|
|
3207
3254
|
// src/chat/get-tool-choice.ts
|
|
3208
|
-
|
|
3209
|
-
var ChatCompletionToolChoiceSchema =
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
type:
|
|
3215
|
-
function:
|
|
3216
|
-
name:
|
|
3255
|
+
import { z as z5 } from "zod/v4";
|
|
3256
|
+
var ChatCompletionToolChoiceSchema = z5.union([
|
|
3257
|
+
z5.literal("auto"),
|
|
3258
|
+
z5.literal("none"),
|
|
3259
|
+
z5.literal("required"),
|
|
3260
|
+
z5.object({
|
|
3261
|
+
type: z5.literal("function"),
|
|
3262
|
+
function: z5.object({
|
|
3263
|
+
name: z5.string()
|
|
3217
3264
|
})
|
|
3218
3265
|
})
|
|
3219
3266
|
]);
|
|
@@ -3240,97 +3287,97 @@ function getChatCompletionToolChoice(toolChoice) {
|
|
|
3240
3287
|
}
|
|
3241
3288
|
|
|
3242
3289
|
// src/chat/schemas.ts
|
|
3243
|
-
|
|
3290
|
+
import { z as z7 } from "zod/v4";
|
|
3244
3291
|
|
|
3245
3292
|
// src/schemas/image.ts
|
|
3246
|
-
|
|
3247
|
-
var ImageResponseSchema =
|
|
3248
|
-
type:
|
|
3249
|
-
image_url:
|
|
3250
|
-
url:
|
|
3293
|
+
import { z as z6 } from "zod/v4";
|
|
3294
|
+
var ImageResponseSchema = z6.object({
|
|
3295
|
+
type: z6.literal("image_url"),
|
|
3296
|
+
image_url: z6.object({
|
|
3297
|
+
url: z6.string()
|
|
3251
3298
|
}).passthrough()
|
|
3252
3299
|
}).passthrough();
|
|
3253
|
-
var ImageResponseWithUnknownSchema =
|
|
3300
|
+
var ImageResponseWithUnknownSchema = z6.union([
|
|
3254
3301
|
ImageResponseSchema,
|
|
3255
|
-
|
|
3302
|
+
z6.unknown().transform(() => null)
|
|
3256
3303
|
]);
|
|
3257
|
-
var ImageResponseArraySchema =
|
|
3304
|
+
var ImageResponseArraySchema = z6.array(ImageResponseWithUnknownSchema).transform((d) => d.filter((d2) => !!d2));
|
|
3258
3305
|
|
|
3259
3306
|
// src/chat/schemas.ts
|
|
3260
|
-
var OpenRouterChatCompletionBaseResponseSchema =
|
|
3261
|
-
id:
|
|
3262
|
-
model:
|
|
3263
|
-
provider:
|
|
3264
|
-
usage:
|
|
3265
|
-
prompt_tokens:
|
|
3266
|
-
prompt_tokens_details:
|
|
3267
|
-
cached_tokens:
|
|
3268
|
-
cache_write_tokens:
|
|
3307
|
+
var OpenRouterChatCompletionBaseResponseSchema = z7.object({
|
|
3308
|
+
id: z7.string().optional(),
|
|
3309
|
+
model: z7.string().optional(),
|
|
3310
|
+
provider: z7.string().optional(),
|
|
3311
|
+
usage: z7.object({
|
|
3312
|
+
prompt_tokens: z7.number(),
|
|
3313
|
+
prompt_tokens_details: z7.object({
|
|
3314
|
+
cached_tokens: z7.number(),
|
|
3315
|
+
cache_write_tokens: z7.number().nullish()
|
|
3269
3316
|
}).passthrough().nullish(),
|
|
3270
|
-
completion_tokens:
|
|
3271
|
-
completion_tokens_details:
|
|
3272
|
-
reasoning_tokens:
|
|
3317
|
+
completion_tokens: z7.number(),
|
|
3318
|
+
completion_tokens_details: z7.object({
|
|
3319
|
+
reasoning_tokens: z7.number()
|
|
3273
3320
|
}).passthrough().nullish(),
|
|
3274
|
-
total_tokens:
|
|
3275
|
-
cost:
|
|
3276
|
-
cost_details:
|
|
3277
|
-
upstream_inference_cost:
|
|
3321
|
+
total_tokens: z7.number(),
|
|
3322
|
+
cost: z7.number().optional(),
|
|
3323
|
+
cost_details: z7.object({
|
|
3324
|
+
upstream_inference_cost: z7.number().nullish()
|
|
3278
3325
|
}).passthrough().nullish()
|
|
3279
3326
|
}).passthrough().nullish()
|
|
3280
3327
|
}).passthrough();
|
|
3281
|
-
var OpenRouterNonStreamChatCompletionResponseSchema =
|
|
3328
|
+
var OpenRouterNonStreamChatCompletionResponseSchema = z7.union([
|
|
3282
3329
|
// Success response with choices
|
|
3283
3330
|
OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
3284
|
-
choices:
|
|
3285
|
-
|
|
3286
|
-
message:
|
|
3287
|
-
role:
|
|
3288
|
-
content:
|
|
3289
|
-
reasoning:
|
|
3331
|
+
choices: z7.array(
|
|
3332
|
+
z7.object({
|
|
3333
|
+
message: z7.object({
|
|
3334
|
+
role: z7.literal("assistant"),
|
|
3335
|
+
content: z7.string().nullable().optional(),
|
|
3336
|
+
reasoning: z7.string().nullable().optional(),
|
|
3290
3337
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
3291
3338
|
images: ImageResponseArraySchema.nullish(),
|
|
3292
|
-
tool_calls:
|
|
3293
|
-
|
|
3294
|
-
id:
|
|
3295
|
-
type:
|
|
3296
|
-
function:
|
|
3297
|
-
name:
|
|
3298
|
-
arguments:
|
|
3339
|
+
tool_calls: z7.array(
|
|
3340
|
+
z7.object({
|
|
3341
|
+
id: z7.string().optional().nullable(),
|
|
3342
|
+
type: z7.literal("function"),
|
|
3343
|
+
function: z7.object({
|
|
3344
|
+
name: z7.string(),
|
|
3345
|
+
arguments: z7.string().optional()
|
|
3299
3346
|
}).passthrough()
|
|
3300
3347
|
}).passthrough()
|
|
3301
3348
|
).optional(),
|
|
3302
|
-
annotations:
|
|
3303
|
-
|
|
3349
|
+
annotations: z7.array(
|
|
3350
|
+
z7.union([
|
|
3304
3351
|
// URL citation from web search
|
|
3305
3352
|
// title, start_index, end_index are optional as some upstream providers may omit them
|
|
3306
|
-
|
|
3307
|
-
type:
|
|
3308
|
-
url_citation:
|
|
3309
|
-
url:
|
|
3310
|
-
title:
|
|
3311
|
-
start_index:
|
|
3312
|
-
end_index:
|
|
3313
|
-
content:
|
|
3353
|
+
z7.object({
|
|
3354
|
+
type: z7.literal("url_citation"),
|
|
3355
|
+
url_citation: z7.object({
|
|
3356
|
+
url: z7.string(),
|
|
3357
|
+
title: z7.string().optional(),
|
|
3358
|
+
start_index: z7.number().optional(),
|
|
3359
|
+
end_index: z7.number().optional(),
|
|
3360
|
+
content: z7.string().optional()
|
|
3314
3361
|
}).passthrough()
|
|
3315
3362
|
}).passthrough(),
|
|
3316
3363
|
// File annotation from FileParserPlugin (old format)
|
|
3317
|
-
|
|
3318
|
-
type:
|
|
3319
|
-
file_annotation:
|
|
3320
|
-
file_id:
|
|
3321
|
-
quote:
|
|
3364
|
+
z7.object({
|
|
3365
|
+
type: z7.literal("file_annotation"),
|
|
3366
|
+
file_annotation: z7.object({
|
|
3367
|
+
file_id: z7.string(),
|
|
3368
|
+
quote: z7.string().optional()
|
|
3322
3369
|
}).passthrough()
|
|
3323
3370
|
}).passthrough(),
|
|
3324
3371
|
// File annotation from FileParserPlugin (new format)
|
|
3325
|
-
|
|
3326
|
-
type:
|
|
3327
|
-
file:
|
|
3328
|
-
hash:
|
|
3329
|
-
name:
|
|
3330
|
-
content:
|
|
3331
|
-
|
|
3332
|
-
type:
|
|
3333
|
-
text:
|
|
3372
|
+
z7.object({
|
|
3373
|
+
type: z7.literal("file"),
|
|
3374
|
+
file: z7.object({
|
|
3375
|
+
hash: z7.string(),
|
|
3376
|
+
name: z7.string(),
|
|
3377
|
+
content: z7.array(
|
|
3378
|
+
z7.object({
|
|
3379
|
+
type: z7.string(),
|
|
3380
|
+
text: z7.string().optional()
|
|
3334
3381
|
}).passthrough()
|
|
3335
3382
|
).optional()
|
|
3336
3383
|
}).passthrough()
|
|
@@ -3338,83 +3385,83 @@ var OpenRouterNonStreamChatCompletionResponseSchema = import_v46.z.union([
|
|
|
3338
3385
|
])
|
|
3339
3386
|
).nullish()
|
|
3340
3387
|
}).passthrough(),
|
|
3341
|
-
index:
|
|
3342
|
-
logprobs:
|
|
3343
|
-
content:
|
|
3344
|
-
|
|
3345
|
-
token:
|
|
3346
|
-
logprob:
|
|
3347
|
-
top_logprobs:
|
|
3348
|
-
|
|
3349
|
-
token:
|
|
3350
|
-
logprob:
|
|
3388
|
+
index: z7.number().nullish(),
|
|
3389
|
+
logprobs: z7.object({
|
|
3390
|
+
content: z7.array(
|
|
3391
|
+
z7.object({
|
|
3392
|
+
token: z7.string(),
|
|
3393
|
+
logprob: z7.number(),
|
|
3394
|
+
top_logprobs: z7.array(
|
|
3395
|
+
z7.object({
|
|
3396
|
+
token: z7.string(),
|
|
3397
|
+
logprob: z7.number()
|
|
3351
3398
|
}).passthrough()
|
|
3352
3399
|
)
|
|
3353
3400
|
}).passthrough()
|
|
3354
3401
|
).nullable()
|
|
3355
3402
|
}).passthrough().nullable().optional(),
|
|
3356
|
-
finish_reason:
|
|
3403
|
+
finish_reason: z7.string().optional().nullable()
|
|
3357
3404
|
}).passthrough()
|
|
3358
3405
|
)
|
|
3359
3406
|
}),
|
|
3360
3407
|
// Error response (HTTP 200 with error payload)
|
|
3361
3408
|
OpenRouterErrorResponseSchema.extend({
|
|
3362
|
-
user_id:
|
|
3409
|
+
user_id: z7.string().optional()
|
|
3363
3410
|
})
|
|
3364
3411
|
]);
|
|
3365
|
-
var OpenRouterStreamChatCompletionChunkSchema =
|
|
3412
|
+
var OpenRouterStreamChatCompletionChunkSchema = z7.union([
|
|
3366
3413
|
OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
3367
|
-
choices:
|
|
3368
|
-
|
|
3369
|
-
delta:
|
|
3370
|
-
role:
|
|
3371
|
-
content:
|
|
3372
|
-
reasoning:
|
|
3414
|
+
choices: z7.array(
|
|
3415
|
+
z7.object({
|
|
3416
|
+
delta: z7.object({
|
|
3417
|
+
role: z7.enum(["assistant"]).optional(),
|
|
3418
|
+
content: z7.string().nullish(),
|
|
3419
|
+
reasoning: z7.string().nullish().optional(),
|
|
3373
3420
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
3374
3421
|
images: ImageResponseArraySchema.nullish(),
|
|
3375
|
-
tool_calls:
|
|
3376
|
-
|
|
3377
|
-
index:
|
|
3378
|
-
id:
|
|
3379
|
-
type:
|
|
3380
|
-
function:
|
|
3381
|
-
name:
|
|
3382
|
-
arguments:
|
|
3422
|
+
tool_calls: z7.array(
|
|
3423
|
+
z7.object({
|
|
3424
|
+
index: z7.number().nullish(),
|
|
3425
|
+
id: z7.string().nullish(),
|
|
3426
|
+
type: z7.literal("function").optional(),
|
|
3427
|
+
function: z7.object({
|
|
3428
|
+
name: z7.string().nullish(),
|
|
3429
|
+
arguments: z7.string().nullish()
|
|
3383
3430
|
}).passthrough()
|
|
3384
3431
|
}).passthrough()
|
|
3385
3432
|
).nullish(),
|
|
3386
|
-
annotations:
|
|
3387
|
-
|
|
3433
|
+
annotations: z7.array(
|
|
3434
|
+
z7.union([
|
|
3388
3435
|
// URL citation from web search
|
|
3389
3436
|
// title, start_index, end_index are optional as some upstream providers may omit them
|
|
3390
|
-
|
|
3391
|
-
type:
|
|
3392
|
-
url_citation:
|
|
3393
|
-
url:
|
|
3394
|
-
title:
|
|
3395
|
-
start_index:
|
|
3396
|
-
end_index:
|
|
3397
|
-
content:
|
|
3437
|
+
z7.object({
|
|
3438
|
+
type: z7.literal("url_citation"),
|
|
3439
|
+
url_citation: z7.object({
|
|
3440
|
+
url: z7.string(),
|
|
3441
|
+
title: z7.string().optional(),
|
|
3442
|
+
start_index: z7.number().optional(),
|
|
3443
|
+
end_index: z7.number().optional(),
|
|
3444
|
+
content: z7.string().optional()
|
|
3398
3445
|
}).passthrough()
|
|
3399
3446
|
}).passthrough(),
|
|
3400
3447
|
// File annotation from FileParserPlugin (old format)
|
|
3401
|
-
|
|
3402
|
-
type:
|
|
3403
|
-
file_annotation:
|
|
3404
|
-
file_id:
|
|
3405
|
-
quote:
|
|
3448
|
+
z7.object({
|
|
3449
|
+
type: z7.literal("file_annotation"),
|
|
3450
|
+
file_annotation: z7.object({
|
|
3451
|
+
file_id: z7.string(),
|
|
3452
|
+
quote: z7.string().optional()
|
|
3406
3453
|
}).passthrough()
|
|
3407
3454
|
}).passthrough(),
|
|
3408
3455
|
// File annotation from FileParserPlugin (new format)
|
|
3409
|
-
|
|
3410
|
-
type:
|
|
3411
|
-
file:
|
|
3412
|
-
hash:
|
|
3413
|
-
name:
|
|
3414
|
-
content:
|
|
3415
|
-
|
|
3416
|
-
type:
|
|
3417
|
-
text:
|
|
3456
|
+
z7.object({
|
|
3457
|
+
type: z7.literal("file"),
|
|
3458
|
+
file: z7.object({
|
|
3459
|
+
hash: z7.string(),
|
|
3460
|
+
name: z7.string(),
|
|
3461
|
+
content: z7.array(
|
|
3462
|
+
z7.object({
|
|
3463
|
+
type: z7.string(),
|
|
3464
|
+
text: z7.string().optional()
|
|
3418
3465
|
}).passthrough()
|
|
3419
3466
|
).optional()
|
|
3420
3467
|
}).passthrough()
|
|
@@ -3422,22 +3469,22 @@ var OpenRouterStreamChatCompletionChunkSchema = import_v46.z.union([
|
|
|
3422
3469
|
])
|
|
3423
3470
|
).nullish()
|
|
3424
3471
|
}).passthrough().nullish(),
|
|
3425
|
-
logprobs:
|
|
3426
|
-
content:
|
|
3427
|
-
|
|
3428
|
-
token:
|
|
3429
|
-
logprob:
|
|
3430
|
-
top_logprobs:
|
|
3431
|
-
|
|
3432
|
-
token:
|
|
3433
|
-
logprob:
|
|
3472
|
+
logprobs: z7.object({
|
|
3473
|
+
content: z7.array(
|
|
3474
|
+
z7.object({
|
|
3475
|
+
token: z7.string(),
|
|
3476
|
+
logprob: z7.number(),
|
|
3477
|
+
top_logprobs: z7.array(
|
|
3478
|
+
z7.object({
|
|
3479
|
+
token: z7.string(),
|
|
3480
|
+
logprob: z7.number()
|
|
3434
3481
|
}).passthrough()
|
|
3435
3482
|
)
|
|
3436
3483
|
}).passthrough()
|
|
3437
3484
|
).nullable()
|
|
3438
3485
|
}).passthrough().nullish(),
|
|
3439
|
-
finish_reason:
|
|
3440
|
-
index:
|
|
3486
|
+
finish_reason: z7.string().nullable().optional(),
|
|
3487
|
+
index: z7.number().nullish()
|
|
3441
3488
|
}).passthrough()
|
|
3442
3489
|
)
|
|
3443
3490
|
}),
|
|
@@ -3447,7 +3494,7 @@ var OpenRouterStreamChatCompletionChunkSchema = import_v46.z.union([
|
|
|
3447
3494
|
// src/chat/index.ts
|
|
3448
3495
|
var OpenRouterChatLanguageModel = class {
|
|
3449
3496
|
constructor(modelId, settings, config) {
|
|
3450
|
-
this.specificationVersion = "
|
|
3497
|
+
this.specificationVersion = "v4";
|
|
3451
3498
|
this.provider = "openrouter";
|
|
3452
3499
|
this.defaultObjectGenerationMode = "tool";
|
|
3453
3500
|
this.supportsImageUrls = true;
|
|
@@ -3477,7 +3524,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3477
3524
|
tools,
|
|
3478
3525
|
toolChoice
|
|
3479
3526
|
}) {
|
|
3480
|
-
var
|
|
3527
|
+
var _a17, _b17, _c, _d;
|
|
3481
3528
|
const baseArgs = __spreadValues(__spreadValues({
|
|
3482
3529
|
// model id:
|
|
3483
3530
|
model: this.modelId,
|
|
@@ -3500,7 +3547,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3500
3547
|
type: "json_schema",
|
|
3501
3548
|
json_schema: __spreadValues({
|
|
3502
3549
|
schema: responseFormat.schema,
|
|
3503
|
-
strict: (
|
|
3550
|
+
strict: (_b17 = (_a17 = this.settings.structuredOutputs) == null ? void 0 : _a17.strict) != null ? _b17 : true,
|
|
3504
3551
|
name: (_c = responseFormat.name) != null ? _c : "response"
|
|
3505
3552
|
}, responseFormat.description && {
|
|
3506
3553
|
description: responseFormat.description
|
|
@@ -3551,10 +3598,10 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3551
3598
|
return baseArgs;
|
|
3552
3599
|
}
|
|
3553
3600
|
async doGenerate(options) {
|
|
3554
|
-
var
|
|
3601
|
+
var _b17, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
3555
3602
|
const providerOptions = options.providerOptions || {};
|
|
3556
3603
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
3557
|
-
const
|
|
3604
|
+
const _a17 = openrouterOptions, { cacheControl } = _a17, restOpenrouterOptions = __objRest(_a17, ["cacheControl"]);
|
|
3558
3605
|
const args = __spreadValues(__spreadValues(__spreadValues({}, this.getArgs(options)), restOpenrouterOptions), cacheControl != null && !("cache_control" in restOpenrouterOptions) ? { cache_control: cacheControl } : {});
|
|
3559
3606
|
const { value: responseValue, responseHeaders } = await postJsonToApi({
|
|
3560
3607
|
url: this.config.url({
|
|
@@ -3592,7 +3639,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3592
3639
|
});
|
|
3593
3640
|
}
|
|
3594
3641
|
const usageInfo = response.usage ? computeTokenUsage(response.usage) : emptyUsage();
|
|
3595
|
-
const reasoningDetails = (
|
|
3642
|
+
const reasoningDetails = (_b17 = choice.message.reasoning_details) != null ? _b17 : [];
|
|
3596
3643
|
const reasoning = reasoningDetails.length > 0 ? reasoningDetails.map((detail) => {
|
|
3597
3644
|
switch (detail.type) {
|
|
3598
3645
|
case "reasoning.text" /* Text */: {
|
|
@@ -3673,7 +3720,10 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3673
3720
|
content.push({
|
|
3674
3721
|
type: "file",
|
|
3675
3722
|
mediaType: getMediaType(image.image_url.url, "image/jpeg"),
|
|
3676
|
-
data:
|
|
3723
|
+
data: {
|
|
3724
|
+
type: "data",
|
|
3725
|
+
data: getBase64FromDataUrl(image.image_url.url)
|
|
3726
|
+
}
|
|
3677
3727
|
});
|
|
3678
3728
|
}
|
|
3679
3729
|
}
|
|
@@ -3746,10 +3796,10 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3746
3796
|
};
|
|
3747
3797
|
}
|
|
3748
3798
|
async doStream(options) {
|
|
3749
|
-
var
|
|
3799
|
+
var _b17;
|
|
3750
3800
|
const providerOptions = options.providerOptions || {};
|
|
3751
3801
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
3752
|
-
const
|
|
3802
|
+
const _a17 = openrouterOptions, { cacheControl } = _a17, restOpenrouterOptions = __objRest(_a17, ["cacheControl"]);
|
|
3753
3803
|
const args = __spreadValues(__spreadValues(__spreadValues({}, this.getArgs(options)), restOpenrouterOptions), cacheControl != null && !("cache_control" in restOpenrouterOptions) ? { cache_control: cacheControl } : {});
|
|
3754
3804
|
const { value: response, responseHeaders } = await postJsonToApi({
|
|
3755
3805
|
url: this.config.url({
|
|
@@ -3762,7 +3812,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3762
3812
|
// only include stream_options when in strict compatibility mode:
|
|
3763
3813
|
stream_options: this.config.compatibility === "strict" ? __spreadValues({
|
|
3764
3814
|
include_usage: true
|
|
3765
|
-
}, ((
|
|
3815
|
+
}, ((_b17 = this.settings.usage) == null ? void 0 : _b17.include) ? { include_usage: true } : {}) : void 0
|
|
3766
3816
|
}),
|
|
3767
3817
|
failedResponseHandler: openrouterFailedResponseHandler,
|
|
3768
3818
|
successfulResponseHandler: createEventSourceResponseHandler(
|
|
@@ -3803,11 +3853,15 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3803
3853
|
let reasoningId;
|
|
3804
3854
|
let openrouterResponseId;
|
|
3805
3855
|
let provider;
|
|
3856
|
+
const warnings = [];
|
|
3806
3857
|
return {
|
|
3807
3858
|
stream: safeResponse.pipeThrough(
|
|
3808
3859
|
new TransformStream({
|
|
3860
|
+
start(controller) {
|
|
3861
|
+
controller.enqueue({ type: "stream-start", warnings });
|
|
3862
|
+
},
|
|
3809
3863
|
transform(chunk, controller) {
|
|
3810
|
-
var
|
|
3864
|
+
var _a18, _b18, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
3811
3865
|
if (options.includeRawChunks) {
|
|
3812
3866
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
3813
3867
|
}
|
|
@@ -3843,8 +3897,8 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3843
3897
|
Object.assign(usage.inputTokens, computed.inputTokens);
|
|
3844
3898
|
Object.assign(usage.outputTokens, computed.outputTokens);
|
|
3845
3899
|
rawUsage = value.usage;
|
|
3846
|
-
const promptTokens = (
|
|
3847
|
-
const completionTokens = (
|
|
3900
|
+
const promptTokens = (_a18 = value.usage.prompt_tokens) != null ? _a18 : 0;
|
|
3901
|
+
const completionTokens = (_b18 = value.usage.completion_tokens) != null ? _b18 : 0;
|
|
3848
3902
|
openrouterUsage.promptTokens = promptTokens;
|
|
3849
3903
|
if (value.usage.prompt_tokens_details) {
|
|
3850
3904
|
openrouterUsage.promptTokensDetails = {
|
|
@@ -4122,7 +4176,10 @@ var OpenRouterChatLanguageModel = class {
|
|
|
4122
4176
|
controller.enqueue({
|
|
4123
4177
|
type: "file",
|
|
4124
4178
|
mediaType: getMediaType(image.image_url.url, "image/jpeg"),
|
|
4125
|
-
data:
|
|
4179
|
+
data: {
|
|
4180
|
+
type: "data",
|
|
4181
|
+
data: getBase64FromDataUrl(image.image_url.url)
|
|
4182
|
+
}
|
|
4126
4183
|
});
|
|
4127
4184
|
}
|
|
4128
4185
|
}
|
|
@@ -4226,7 +4283,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
4226
4283
|
}
|
|
4227
4284
|
})
|
|
4228
4285
|
),
|
|
4229
|
-
warnings
|
|
4286
|
+
warnings,
|
|
4230
4287
|
request: { body: args },
|
|
4231
4288
|
response: { headers: responseHeaders }
|
|
4232
4289
|
};
|
|
@@ -4297,38 +4354,36 @@ ${userMessage}
|
|
|
4297
4354
|
break;
|
|
4298
4355
|
}
|
|
4299
4356
|
case "assistant": {
|
|
4300
|
-
const assistantMessage = content.map(
|
|
4301
|
-
(part)
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
return "";
|
|
4328
|
-
}
|
|
4357
|
+
const assistantMessage = content.map((part) => {
|
|
4358
|
+
switch (part.type) {
|
|
4359
|
+
case "text": {
|
|
4360
|
+
return part.text;
|
|
4361
|
+
}
|
|
4362
|
+
case "tool-call": {
|
|
4363
|
+
throw new UnsupportedFunctionalityError({
|
|
4364
|
+
functionality: "tool-call messages"
|
|
4365
|
+
});
|
|
4366
|
+
}
|
|
4367
|
+
case "tool-result": {
|
|
4368
|
+
throw new UnsupportedFunctionalityError({
|
|
4369
|
+
functionality: "tool-result messages"
|
|
4370
|
+
});
|
|
4371
|
+
}
|
|
4372
|
+
case "reasoning": {
|
|
4373
|
+
throw new UnsupportedFunctionalityError({
|
|
4374
|
+
functionality: "reasoning messages"
|
|
4375
|
+
});
|
|
4376
|
+
}
|
|
4377
|
+
case "file": {
|
|
4378
|
+
throw new UnsupportedFunctionalityError({
|
|
4379
|
+
functionality: "file attachments"
|
|
4380
|
+
});
|
|
4381
|
+
}
|
|
4382
|
+
default: {
|
|
4383
|
+
return "";
|
|
4329
4384
|
}
|
|
4330
4385
|
}
|
|
4331
|
-
).join("");
|
|
4386
|
+
}).join("");
|
|
4332
4387
|
text += `${assistant}:
|
|
4333
4388
|
${assistantMessage}
|
|
4334
4389
|
|
|
@@ -4353,40 +4408,40 @@ ${assistantMessage}
|
|
|
4353
4408
|
}
|
|
4354
4409
|
|
|
4355
4410
|
// src/completion/schemas.ts
|
|
4356
|
-
|
|
4357
|
-
var OpenRouterCompletionChunkSchema =
|
|
4358
|
-
|
|
4359
|
-
id:
|
|
4360
|
-
model:
|
|
4361
|
-
provider:
|
|
4362
|
-
choices:
|
|
4363
|
-
|
|
4364
|
-
text:
|
|
4365
|
-
reasoning:
|
|
4411
|
+
import { z as z8 } from "zod/v4";
|
|
4412
|
+
var OpenRouterCompletionChunkSchema = z8.union([
|
|
4413
|
+
z8.object({
|
|
4414
|
+
id: z8.string().optional(),
|
|
4415
|
+
model: z8.string().optional(),
|
|
4416
|
+
provider: z8.string().optional(),
|
|
4417
|
+
choices: z8.array(
|
|
4418
|
+
z8.object({
|
|
4419
|
+
text: z8.string(),
|
|
4420
|
+
reasoning: z8.string().nullish().optional(),
|
|
4366
4421
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
4367
|
-
finish_reason:
|
|
4368
|
-
index:
|
|
4369
|
-
logprobs:
|
|
4370
|
-
tokens:
|
|
4371
|
-
token_logprobs:
|
|
4372
|
-
top_logprobs:
|
|
4422
|
+
finish_reason: z8.string().nullish(),
|
|
4423
|
+
index: z8.number().nullish(),
|
|
4424
|
+
logprobs: z8.object({
|
|
4425
|
+
tokens: z8.array(z8.string()),
|
|
4426
|
+
token_logprobs: z8.array(z8.number()),
|
|
4427
|
+
top_logprobs: z8.array(z8.record(z8.string(), z8.number())).nullable()
|
|
4373
4428
|
}).passthrough().nullable().optional()
|
|
4374
4429
|
}).passthrough()
|
|
4375
4430
|
),
|
|
4376
|
-
usage:
|
|
4377
|
-
prompt_tokens:
|
|
4378
|
-
prompt_tokens_details:
|
|
4379
|
-
cached_tokens:
|
|
4380
|
-
cache_write_tokens:
|
|
4431
|
+
usage: z8.object({
|
|
4432
|
+
prompt_tokens: z8.number(),
|
|
4433
|
+
prompt_tokens_details: z8.object({
|
|
4434
|
+
cached_tokens: z8.number(),
|
|
4435
|
+
cache_write_tokens: z8.number().nullish()
|
|
4381
4436
|
}).passthrough().nullish(),
|
|
4382
|
-
completion_tokens:
|
|
4383
|
-
completion_tokens_details:
|
|
4384
|
-
reasoning_tokens:
|
|
4437
|
+
completion_tokens: z8.number(),
|
|
4438
|
+
completion_tokens_details: z8.object({
|
|
4439
|
+
reasoning_tokens: z8.number()
|
|
4385
4440
|
}).passthrough().nullish(),
|
|
4386
|
-
total_tokens:
|
|
4387
|
-
cost:
|
|
4388
|
-
cost_details:
|
|
4389
|
-
upstream_inference_cost:
|
|
4441
|
+
total_tokens: z8.number(),
|
|
4442
|
+
cost: z8.number().optional(),
|
|
4443
|
+
cost_details: z8.object({
|
|
4444
|
+
upstream_inference_cost: z8.number().nullish()
|
|
4390
4445
|
}).passthrough().nullish()
|
|
4391
4446
|
}).passthrough().nullish()
|
|
4392
4447
|
}).passthrough(),
|
|
@@ -4396,7 +4451,7 @@ var OpenRouterCompletionChunkSchema = import_v47.z.union([
|
|
|
4396
4451
|
// src/completion/index.ts
|
|
4397
4452
|
var OpenRouterCompletionLanguageModel = class {
|
|
4398
4453
|
constructor(modelId, settings, config) {
|
|
4399
|
-
this.specificationVersion = "
|
|
4454
|
+
this.specificationVersion = "v4";
|
|
4400
4455
|
this.provider = "openrouter";
|
|
4401
4456
|
this.supportsImageUrls = true;
|
|
4402
4457
|
this.supportedUrls = {
|
|
@@ -4467,7 +4522,7 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
4467
4522
|
}, this.config.extraBody), this.settings.extraBody);
|
|
4468
4523
|
}
|
|
4469
4524
|
async doGenerate(options) {
|
|
4470
|
-
var
|
|
4525
|
+
var _a17, _b17, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
4471
4526
|
const providerOptions = options.providerOptions || {};
|
|
4472
4527
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
4473
4528
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
@@ -4509,7 +4564,7 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
4509
4564
|
content: [
|
|
4510
4565
|
{
|
|
4511
4566
|
type: "text",
|
|
4512
|
-
text: (
|
|
4567
|
+
text: (_a17 = choice.text) != null ? _a17 : ""
|
|
4513
4568
|
}
|
|
4514
4569
|
],
|
|
4515
4570
|
finishReason: mapOpenRouterFinishReason(choice.finish_reason),
|
|
@@ -4517,7 +4572,7 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
4517
4572
|
warnings: [],
|
|
4518
4573
|
providerMetadata: {
|
|
4519
4574
|
openrouter: OpenRouterProviderMetadataSchema.parse({
|
|
4520
|
-
provider: (
|
|
4575
|
+
provider: (_b17 = response.provider) != null ? _b17 : "",
|
|
4521
4576
|
usage: __spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
4522
4577
|
promptTokens: (_d = (_c = response.usage) == null ? void 0 : _c.prompt_tokens) != null ? _d : 0,
|
|
4523
4578
|
completionTokens: (_f = (_e = response.usage) == null ? void 0 : _e.completion_tokens) != null ? _f : 0,
|
|
@@ -4586,11 +4641,15 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
4586
4641
|
const openrouterUsage = {};
|
|
4587
4642
|
let provider;
|
|
4588
4643
|
let rawUsage;
|
|
4644
|
+
const warnings = [];
|
|
4589
4645
|
return {
|
|
4590
4646
|
stream: safeResponse.pipeThrough(
|
|
4591
4647
|
new TransformStream({
|
|
4648
|
+
start(controller) {
|
|
4649
|
+
controller.enqueue({ type: "stream-start", warnings });
|
|
4650
|
+
},
|
|
4592
4651
|
transform(chunk, controller) {
|
|
4593
|
-
var
|
|
4652
|
+
var _a17, _b17, _c, _d, _e;
|
|
4594
4653
|
if (options.includeRawChunks) {
|
|
4595
4654
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
4596
4655
|
}
|
|
@@ -4613,8 +4672,8 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
4613
4672
|
Object.assign(usage.inputTokens, computed.inputTokens);
|
|
4614
4673
|
Object.assign(usage.outputTokens, computed.outputTokens);
|
|
4615
4674
|
rawUsage = value.usage;
|
|
4616
|
-
const promptTokens = (
|
|
4617
|
-
const completionTokens = (
|
|
4675
|
+
const promptTokens = (_a17 = value.usage.prompt_tokens) != null ? _a17 : 0;
|
|
4676
|
+
const completionTokens = (_b17 = value.usage.completion_tokens) != null ? _b17 : 0;
|
|
4618
4677
|
openrouterUsage.promptTokens = promptTokens;
|
|
4619
4678
|
if (value.usage.prompt_tokens_details) {
|
|
4620
4679
|
openrouterUsage.promptTokensDetails = {
|
|
@@ -4681,30 +4740,30 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
4681
4740
|
};
|
|
4682
4741
|
|
|
4683
4742
|
// src/embedding/schemas.ts
|
|
4684
|
-
|
|
4685
|
-
var openrouterEmbeddingUsageSchema =
|
|
4686
|
-
prompt_tokens:
|
|
4687
|
-
total_tokens:
|
|
4688
|
-
cost:
|
|
4743
|
+
import { z as z9 } from "zod/v4";
|
|
4744
|
+
var openrouterEmbeddingUsageSchema = z9.object({
|
|
4745
|
+
prompt_tokens: z9.number(),
|
|
4746
|
+
total_tokens: z9.number(),
|
|
4747
|
+
cost: z9.number().optional()
|
|
4689
4748
|
});
|
|
4690
|
-
var openrouterEmbeddingDataSchema =
|
|
4691
|
-
object:
|
|
4692
|
-
embedding:
|
|
4693
|
-
index:
|
|
4749
|
+
var openrouterEmbeddingDataSchema = z9.object({
|
|
4750
|
+
object: z9.literal("embedding"),
|
|
4751
|
+
embedding: z9.array(z9.number()),
|
|
4752
|
+
index: z9.number().optional()
|
|
4694
4753
|
});
|
|
4695
|
-
var OpenRouterEmbeddingResponseSchema =
|
|
4696
|
-
id:
|
|
4697
|
-
object:
|
|
4698
|
-
data:
|
|
4699
|
-
model:
|
|
4700
|
-
provider:
|
|
4754
|
+
var OpenRouterEmbeddingResponseSchema = z9.object({
|
|
4755
|
+
id: z9.string().optional(),
|
|
4756
|
+
object: z9.literal("list"),
|
|
4757
|
+
data: z9.array(openrouterEmbeddingDataSchema),
|
|
4758
|
+
model: z9.string(),
|
|
4759
|
+
provider: z9.string().optional(),
|
|
4701
4760
|
usage: openrouterEmbeddingUsageSchema.optional()
|
|
4702
4761
|
});
|
|
4703
4762
|
|
|
4704
4763
|
// src/embedding/index.ts
|
|
4705
4764
|
var OpenRouterEmbeddingModel = class {
|
|
4706
4765
|
constructor(modelId, settings, config) {
|
|
4707
|
-
this.specificationVersion = "
|
|
4766
|
+
this.specificationVersion = "v4";
|
|
4708
4767
|
this.provider = "openrouter";
|
|
4709
4768
|
this.maxEmbeddingsPerCall = void 0;
|
|
4710
4769
|
this.supportsParallelCalls = true;
|
|
@@ -4713,7 +4772,7 @@ var OpenRouterEmbeddingModel = class {
|
|
|
4713
4772
|
this.config = config;
|
|
4714
4773
|
}
|
|
4715
4774
|
async doEmbed(options) {
|
|
4716
|
-
var
|
|
4775
|
+
var _a17, _b17, _c, _d, _e, _f;
|
|
4717
4776
|
const { values, abortSignal, headers } = options;
|
|
4718
4777
|
const args = __spreadValues(__spreadValues({
|
|
4719
4778
|
model: this.modelId,
|
|
@@ -4740,9 +4799,9 @@ var OpenRouterEmbeddingModel = class {
|
|
|
4740
4799
|
usage: responseValue.usage ? { tokens: responseValue.usage.prompt_tokens } : void 0,
|
|
4741
4800
|
providerMetadata: {
|
|
4742
4801
|
openrouter: OpenRouterProviderMetadataSchema.parse({
|
|
4743
|
-
provider: (
|
|
4802
|
+
provider: (_a17 = responseValue.provider) != null ? _a17 : "",
|
|
4744
4803
|
usage: __spreadValues({
|
|
4745
|
-
promptTokens: (_c = (
|
|
4804
|
+
promptTokens: (_c = (_b17 = responseValue.usage) == null ? void 0 : _b17.prompt_tokens) != null ? _c : 0,
|
|
4746
4805
|
completionTokens: 0,
|
|
4747
4806
|
totalTokens: (_e = (_d = responseValue.usage) == null ? void 0 : _d.total_tokens) != null ? _e : 0
|
|
4748
4807
|
}, ((_f = responseValue.usage) == null ? void 0 : _f.cost) != null ? { cost: responseValue.usage.cost } : {})
|
|
@@ -4758,25 +4817,25 @@ var OpenRouterEmbeddingModel = class {
|
|
|
4758
4817
|
};
|
|
4759
4818
|
|
|
4760
4819
|
// src/image/schemas.ts
|
|
4761
|
-
|
|
4762
|
-
var OpenRouterImageResponseSchema =
|
|
4763
|
-
created:
|
|
4764
|
-
data:
|
|
4765
|
-
|
|
4766
|
-
b64_json:
|
|
4820
|
+
import { z as z10 } from "zod/v4";
|
|
4821
|
+
var OpenRouterImageResponseSchema = z10.object({
|
|
4822
|
+
created: z10.number().optional(),
|
|
4823
|
+
data: z10.array(
|
|
4824
|
+
z10.object({
|
|
4825
|
+
b64_json: z10.string()
|
|
4767
4826
|
}).passthrough()
|
|
4768
4827
|
),
|
|
4769
|
-
usage:
|
|
4770
|
-
prompt_tokens:
|
|
4771
|
-
completion_tokens:
|
|
4772
|
-
total_tokens:
|
|
4828
|
+
usage: z10.object({
|
|
4829
|
+
prompt_tokens: z10.number(),
|
|
4830
|
+
completion_tokens: z10.number(),
|
|
4831
|
+
total_tokens: z10.number()
|
|
4773
4832
|
}).passthrough().optional()
|
|
4774
4833
|
}).passthrough();
|
|
4775
4834
|
|
|
4776
4835
|
// src/image/index.ts
|
|
4777
4836
|
var OpenRouterImageModel = class {
|
|
4778
4837
|
constructor(modelId, settings, config) {
|
|
4779
|
-
this.specificationVersion = "
|
|
4838
|
+
this.specificationVersion = "v4";
|
|
4780
4839
|
this.provider = "openrouter";
|
|
4781
4840
|
this.maxImagesPerCall = 10;
|
|
4782
4841
|
this.modelId = modelId;
|
|
@@ -4870,24 +4929,24 @@ function convertFileToInputReference(file) {
|
|
|
4870
4929
|
}
|
|
4871
4930
|
|
|
4872
4931
|
// src/video/schemas.ts
|
|
4873
|
-
|
|
4874
|
-
var VideoGenerationSubmitResponseSchema =
|
|
4875
|
-
id:
|
|
4876
|
-
generation_id:
|
|
4877
|
-
polling_url:
|
|
4878
|
-
status:
|
|
4932
|
+
import { z as z11 } from "zod/v4";
|
|
4933
|
+
var VideoGenerationSubmitResponseSchema = z11.object({
|
|
4934
|
+
id: z11.string(),
|
|
4935
|
+
generation_id: z11.string().optional(),
|
|
4936
|
+
polling_url: z11.string(),
|
|
4937
|
+
status: z11.string()
|
|
4879
4938
|
}).passthrough();
|
|
4880
|
-
var VideoGenerationPollResponseSchema =
|
|
4881
|
-
id:
|
|
4882
|
-
generation_id:
|
|
4883
|
-
polling_url:
|
|
4884
|
-
status:
|
|
4885
|
-
unsigned_urls:
|
|
4886
|
-
usage:
|
|
4887
|
-
cost:
|
|
4888
|
-
is_byok:
|
|
4939
|
+
var VideoGenerationPollResponseSchema = z11.object({
|
|
4940
|
+
id: z11.string(),
|
|
4941
|
+
generation_id: z11.string().optional(),
|
|
4942
|
+
polling_url: z11.string(),
|
|
4943
|
+
status: z11.string(),
|
|
4944
|
+
unsigned_urls: z11.array(z11.string()).optional(),
|
|
4945
|
+
usage: z11.object({
|
|
4946
|
+
cost: z11.number().optional(),
|
|
4947
|
+
is_byok: z11.boolean().optional()
|
|
4889
4948
|
}).passthrough().optional(),
|
|
4890
|
-
error:
|
|
4949
|
+
error: z11.string().optional()
|
|
4891
4950
|
}).passthrough();
|
|
4892
4951
|
|
|
4893
4952
|
// src/video/index.ts
|
|
@@ -4895,7 +4954,7 @@ var DEFAULT_POLL_INTERVAL_MS = 2e3;
|
|
|
4895
4954
|
var DEFAULT_MAX_POLL_TIME_MS = 6e5;
|
|
4896
4955
|
var OpenRouterVideoModel = class {
|
|
4897
4956
|
constructor(modelId, settings, config) {
|
|
4898
|
-
this.specificationVersion = "
|
|
4957
|
+
this.specificationVersion = "v4";
|
|
4899
4958
|
this.provider = "openrouter";
|
|
4900
4959
|
this.maxVideosPerCall = 1;
|
|
4901
4960
|
this.modelId = modelId;
|
|
@@ -4903,7 +4962,7 @@ var OpenRouterVideoModel = class {
|
|
|
4903
4962
|
this.config = config;
|
|
4904
4963
|
}
|
|
4905
4964
|
async doGenerate(options) {
|
|
4906
|
-
var
|
|
4965
|
+
var _a17, _b17, _c, _d, _e;
|
|
4907
4966
|
const {
|
|
4908
4967
|
prompt,
|
|
4909
4968
|
n,
|
|
@@ -4947,8 +5006,8 @@ var OpenRouterVideoModel = class {
|
|
|
4947
5006
|
abortSignal,
|
|
4948
5007
|
fetch: this.config.fetch
|
|
4949
5008
|
});
|
|
4950
|
-
const pollIntervalMs = (
|
|
4951
|
-
const maxPollTimeMs = (
|
|
5009
|
+
const pollIntervalMs = (_a17 = this.settings.pollIntervalMs) != null ? _a17 : DEFAULT_POLL_INTERVAL_MS;
|
|
5010
|
+
const maxPollTimeMs = (_b17 = this.settings.maxPollTimeMs) != null ? _b17 : DEFAULT_MAX_POLL_TIME_MS;
|
|
4952
5011
|
const pollResult = await this.pollUntilComplete({
|
|
4953
5012
|
jobId: submitResponse.id,
|
|
4954
5013
|
headers: mergedHeaders,
|
|
@@ -4990,7 +5049,7 @@ var OpenRouterVideoModel = class {
|
|
|
4990
5049
|
pollIntervalMs,
|
|
4991
5050
|
maxPollTimeMs
|
|
4992
5051
|
}) {
|
|
4993
|
-
var
|
|
5052
|
+
var _a17;
|
|
4994
5053
|
const startTime = Date.now();
|
|
4995
5054
|
while (Date.now() - startTime < maxPollTimeMs) {
|
|
4996
5055
|
abortSignal == null ? void 0 : abortSignal.throwIfAborted();
|
|
@@ -5018,7 +5077,7 @@ var OpenRouterVideoModel = class {
|
|
|
5018
5077
|
}
|
|
5019
5078
|
if (pollResponse.status === "failed" || pollResponse.status === "dead" || pollResponse.status === "cancelled" || pollResponse.status === "expired") {
|
|
5020
5079
|
throw new APICallError({
|
|
5021
|
-
message: (
|
|
5080
|
+
message: (_a17 = pollResponse.error) != null ? _a17 : `Video generation failed with status: ${pollResponse.status}`,
|
|
5022
5081
|
url: this.config.url({
|
|
5023
5082
|
path: `/videos/${jobId}`,
|
|
5024
5083
|
modelId: this.modelId
|
|
@@ -5060,12 +5119,11 @@ function convertImageToFrameImage(file) {
|
|
|
5060
5119
|
frame_type: "first_frame"
|
|
5061
5120
|
};
|
|
5062
5121
|
}
|
|
5063
|
-
|
|
5064
|
-
0 && (module.exports = {
|
|
5122
|
+
export {
|
|
5065
5123
|
OpenRouterChatLanguageModel,
|
|
5066
5124
|
OpenRouterCompletionLanguageModel,
|
|
5067
5125
|
OpenRouterEmbeddingModel,
|
|
5068
5126
|
OpenRouterImageModel,
|
|
5069
5127
|
OpenRouterVideoModel
|
|
5070
|
-
}
|
|
5128
|
+
};
|
|
5071
5129
|
//# sourceMappingURL=index.js.map
|