@providerprotocol/ai 0.0.26 → 0.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/anthropic/index.d.ts +1 -1
- package/dist/anthropic/index.js +38 -1
- package/dist/anthropic/index.js.map +1 -1
- package/dist/{chunk-6AZVUI6H.js → chunk-ILR2D5PN.js} +7 -1
- package/dist/chunk-ILR2D5PN.js.map +1 -0
- package/dist/{chunk-MKDLXV4O.js → chunk-NSE7QN3P.js} +1 -1
- package/dist/chunk-NSE7QN3P.js.map +1 -0
- package/dist/embedding-DtyOFIsS.d.ts +158 -0
- package/dist/google/index.d.ts +1 -1
- package/dist/google/index.js +41 -4
- package/dist/google/index.js.map +1 -1
- package/dist/http/index.d.ts +2 -2
- package/dist/index.d.ts +430 -669
- package/dist/index.js +627 -3
- package/dist/index.js.map +1 -1
- package/dist/llm-DgDEy9il.d.ts +3118 -0
- package/dist/ollama/index.d.ts +1 -1
- package/dist/ollama/index.js +2 -1
- package/dist/ollama/index.js.map +1 -1
- package/dist/openai/index.d.ts +1 -1
- package/dist/openai/index.js +70 -3
- package/dist/openai/index.js.map +1 -1
- package/dist/openrouter/index.d.ts +20 -2
- package/dist/openrouter/index.js +134 -13
- package/dist/openrouter/index.js.map +1 -1
- package/dist/proxy/index.d.ts +220 -3
- package/dist/proxy/index.js +817 -22
- package/dist/proxy/index.js.map +1 -1
- package/dist/{retry-DTfjXXPh.d.ts → retry-DXLQnTuU.d.ts} +1 -1
- package/dist/xai/index.d.ts +1 -1
- package/dist/xai/index.js +7 -3
- package/dist/xai/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-6AZVUI6H.js.map +0 -1
- package/dist/chunk-MKDLXV4O.js.map +0 -1
- package/dist/provider-x4RocsnK.d.ts +0 -1474
- package/dist/stream-ITNFNnO4.d.ts +0 -1080
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { P as Provider } from '../llm-DgDEy9il.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* OpenRouter-specific types for the Unified Provider Protocol.
|
|
@@ -287,6 +287,24 @@ type OpenRouterResponseFormat = {
|
|
|
287
287
|
strict?: boolean;
|
|
288
288
|
};
|
|
289
289
|
};
|
|
290
|
+
/**
|
|
291
|
+
* OpenRouter-specific HTTP headers for API requests.
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```typescript
|
|
295
|
+
* const headers: OpenRouterHeaders = {
|
|
296
|
+
* 'HTTP-Referer': 'https://myapp.example.com',
|
|
297
|
+
* 'X-Title': 'My Application',
|
|
298
|
+
* };
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
interface OpenRouterHeaders {
|
|
302
|
+
/** Application URL for analytics and leaderboard tracking. */
|
|
303
|
+
'HTTP-Referer'?: string;
|
|
304
|
+
/** Application name for analytics display. */
|
|
305
|
+
'X-Title'?: string;
|
|
306
|
+
[key: string]: string | undefined;
|
|
307
|
+
}
|
|
290
308
|
|
|
291
309
|
/**
|
|
292
310
|
* @fileoverview OpenRouter Embeddings API Handler
|
|
@@ -406,4 +424,4 @@ type OpenRouterProvider = Provider<OpenRouterProviderOptions>;
|
|
|
406
424
|
*/
|
|
407
425
|
declare const openrouter: OpenRouterProvider;
|
|
408
426
|
|
|
409
|
-
export { type OpenRouterAPIMode, type OpenRouterCompletionsParams, type OpenRouterConfig, type OpenRouterEmbedParams, type OpenRouterModelOptions, type OpenRouterModelReference, type OpenRouterProviderPreferences, type OpenRouterResponsesParams, openrouter };
|
|
427
|
+
export { type OpenRouterAPIMode, type OpenRouterCompletionsParams, type OpenRouterConfig, type OpenRouterEmbedParams, type OpenRouterHeaders, type OpenRouterImageConfig, type OpenRouterModelOptions, type OpenRouterModelReference, type OpenRouterProviderPreferences, type OpenRouterResponsesParams, openrouter };
|
package/dist/openrouter/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
isAssistantMessage,
|
|
12
12
|
isToolResultMessage,
|
|
13
13
|
isUserMessage
|
|
14
|
-
} from "../chunk-
|
|
14
|
+
} from "../chunk-ILR2D5PN.js";
|
|
15
15
|
import {
|
|
16
16
|
parseSSEStream
|
|
17
17
|
} from "../chunk-TOJCZMVU.js";
|
|
@@ -230,9 +230,7 @@ function transformContentBlock(block) {
|
|
|
230
230
|
} else if (imageBlock.source.type === "url") {
|
|
231
231
|
url = imageBlock.source.url;
|
|
232
232
|
} else if (imageBlock.source.type === "bytes") {
|
|
233
|
-
const base64 =
|
|
234
|
-
Array.from(imageBlock.source.data).map((b) => String.fromCharCode(b)).join("")
|
|
235
|
-
);
|
|
233
|
+
const base64 = Buffer.from(imageBlock.source.data).toString("base64");
|
|
236
234
|
url = `data:${imageBlock.mimeType};base64,${base64}`;
|
|
237
235
|
} else {
|
|
238
236
|
throw new Error("Unknown image source type");
|
|
@@ -242,6 +240,69 @@ function transformContentBlock(block) {
|
|
|
242
240
|
image_url: { url }
|
|
243
241
|
};
|
|
244
242
|
}
|
|
243
|
+
case "document": {
|
|
244
|
+
const documentBlock = block;
|
|
245
|
+
if (documentBlock.source.type === "text") {
|
|
246
|
+
if (!documentBlock.source.data) {
|
|
247
|
+
throw new UPPError(
|
|
248
|
+
"Text document source data is empty",
|
|
249
|
+
ErrorCode.InvalidRequest,
|
|
250
|
+
"openrouter",
|
|
251
|
+
ModalityType.LLM
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
const title = documentBlock.title ? `[Document: ${documentBlock.title}]
|
|
255
|
+
` : "";
|
|
256
|
+
return { type: "text", text: `${title}${documentBlock.source.data}` };
|
|
257
|
+
}
|
|
258
|
+
const filename = documentBlock.title ?? "document.pdf";
|
|
259
|
+
if (documentBlock.source.type === "base64") {
|
|
260
|
+
const fileData = `data:${documentBlock.mimeType};base64,${documentBlock.source.data}`;
|
|
261
|
+
return {
|
|
262
|
+
type: "file",
|
|
263
|
+
file: {
|
|
264
|
+
filename,
|
|
265
|
+
file_data: fileData
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
if (documentBlock.source.type === "url") {
|
|
270
|
+
return {
|
|
271
|
+
type: "file",
|
|
272
|
+
file: {
|
|
273
|
+
filename,
|
|
274
|
+
file_url: documentBlock.source.url
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
throw new UPPError(
|
|
279
|
+
"Unknown document source type",
|
|
280
|
+
ErrorCode.InvalidRequest,
|
|
281
|
+
"openrouter",
|
|
282
|
+
ModalityType.LLM
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
case "audio": {
|
|
286
|
+
const audioBlock = block;
|
|
287
|
+
const base64 = Buffer.from(audioBlock.data).toString("base64");
|
|
288
|
+
const format = audioBlock.mimeType.split("/")[1] ?? "mp3";
|
|
289
|
+
return {
|
|
290
|
+
type: "input_audio",
|
|
291
|
+
input_audio: {
|
|
292
|
+
data: base64,
|
|
293
|
+
format
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
case "video": {
|
|
298
|
+
const videoBlock = block;
|
|
299
|
+
const base64 = Buffer.from(videoBlock.data).toString("base64");
|
|
300
|
+
const url = `data:${videoBlock.mimeType};base64,${base64}`;
|
|
301
|
+
return {
|
|
302
|
+
type: "video_url",
|
|
303
|
+
video_url: { url }
|
|
304
|
+
};
|
|
305
|
+
}
|
|
245
306
|
default:
|
|
246
307
|
throw new Error(`Unsupported content type: ${block.type}`);
|
|
247
308
|
}
|
|
@@ -558,9 +619,10 @@ var OPENROUTER_CAPABILITIES = {
|
|
|
558
619
|
tools: true,
|
|
559
620
|
structuredOutput: true,
|
|
560
621
|
imageInput: true,
|
|
622
|
+
documentInput: true,
|
|
561
623
|
imageOutput: true,
|
|
562
|
-
videoInput:
|
|
563
|
-
audioInput:
|
|
624
|
+
videoInput: true,
|
|
625
|
+
audioInput: true
|
|
564
626
|
};
|
|
565
627
|
function createCompletionsLLMHandler() {
|
|
566
628
|
let providerRef = null;
|
|
@@ -942,9 +1004,7 @@ function transformContentPart(block) {
|
|
|
942
1004
|
};
|
|
943
1005
|
}
|
|
944
1006
|
if (imageBlock.source.type === "bytes") {
|
|
945
|
-
const base64 =
|
|
946
|
-
Array.from(imageBlock.source.data).map((b) => String.fromCharCode(b)).join("")
|
|
947
|
-
);
|
|
1007
|
+
const base64 = Buffer.from(imageBlock.source.data).toString("base64");
|
|
948
1008
|
return {
|
|
949
1009
|
type: "input_image",
|
|
950
1010
|
image_url: `data:${imageBlock.mimeType};base64,${base64}`,
|
|
@@ -953,6 +1013,65 @@ function transformContentPart(block) {
|
|
|
953
1013
|
}
|
|
954
1014
|
throw new Error("Unknown image source type");
|
|
955
1015
|
}
|
|
1016
|
+
case "document": {
|
|
1017
|
+
const documentBlock = block;
|
|
1018
|
+
if (documentBlock.source.type === "text") {
|
|
1019
|
+
if (!documentBlock.source.data) {
|
|
1020
|
+
throw new UPPError(
|
|
1021
|
+
"Text document source data is empty",
|
|
1022
|
+
ErrorCode.InvalidRequest,
|
|
1023
|
+
"openrouter",
|
|
1024
|
+
ModalityType.LLM
|
|
1025
|
+
);
|
|
1026
|
+
}
|
|
1027
|
+
const title = documentBlock.title ? `[Document: ${documentBlock.title}]
|
|
1028
|
+
` : "";
|
|
1029
|
+
return { type: "input_text", text: `${title}${documentBlock.source.data}` };
|
|
1030
|
+
}
|
|
1031
|
+
const filename = documentBlock.title ?? "document.pdf";
|
|
1032
|
+
if (documentBlock.source.type === "base64") {
|
|
1033
|
+
const fileData = `data:${documentBlock.mimeType};base64,${documentBlock.source.data}`;
|
|
1034
|
+
return {
|
|
1035
|
+
type: "input_file",
|
|
1036
|
+
filename,
|
|
1037
|
+
file_data: fileData
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
1040
|
+
if (documentBlock.source.type === "url") {
|
|
1041
|
+
return {
|
|
1042
|
+
type: "input_file",
|
|
1043
|
+
filename,
|
|
1044
|
+
file_url: documentBlock.source.url
|
|
1045
|
+
};
|
|
1046
|
+
}
|
|
1047
|
+
throw new UPPError(
|
|
1048
|
+
"Unknown document source type",
|
|
1049
|
+
ErrorCode.InvalidRequest,
|
|
1050
|
+
"openrouter",
|
|
1051
|
+
ModalityType.LLM
|
|
1052
|
+
);
|
|
1053
|
+
}
|
|
1054
|
+
case "audio": {
|
|
1055
|
+
const audioBlock = block;
|
|
1056
|
+
const base64 = Buffer.from(audioBlock.data).toString("base64");
|
|
1057
|
+
const format = audioBlock.mimeType.split("/")[1] ?? "mp3";
|
|
1058
|
+
return {
|
|
1059
|
+
type: "input_audio",
|
|
1060
|
+
input_audio: {
|
|
1061
|
+
data: base64,
|
|
1062
|
+
format
|
|
1063
|
+
}
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
1066
|
+
case "video": {
|
|
1067
|
+
const videoBlock = block;
|
|
1068
|
+
const base64 = Buffer.from(videoBlock.data).toString("base64");
|
|
1069
|
+
const url = `data:${videoBlock.mimeType};base64,${base64}`;
|
|
1070
|
+
return {
|
|
1071
|
+
type: "input_video",
|
|
1072
|
+
video_url: url
|
|
1073
|
+
};
|
|
1074
|
+
}
|
|
956
1075
|
default:
|
|
957
1076
|
throw new Error(`Unsupported content type: ${block.type}`);
|
|
958
1077
|
}
|
|
@@ -1400,9 +1519,10 @@ var OPENROUTER_CAPABILITIES2 = {
|
|
|
1400
1519
|
tools: true,
|
|
1401
1520
|
structuredOutput: true,
|
|
1402
1521
|
imageInput: true,
|
|
1522
|
+
documentInput: true,
|
|
1403
1523
|
imageOutput: true,
|
|
1404
|
-
videoInput:
|
|
1405
|
-
audioInput:
|
|
1524
|
+
videoInput: true,
|
|
1525
|
+
audioInput: true
|
|
1406
1526
|
};
|
|
1407
1527
|
function createResponsesLLMHandler() {
|
|
1408
1528
|
let providerRef = null;
|
|
@@ -1458,9 +1578,10 @@ function createResponsesLLMHandler() {
|
|
|
1458
1578
|
"llm"
|
|
1459
1579
|
);
|
|
1460
1580
|
const data = await parseJsonResponse(response, "openrouter", "llm");
|
|
1461
|
-
if (data.status === "failed"
|
|
1581
|
+
if (data.status === "failed") {
|
|
1582
|
+
const message = data.error?.message ?? "Provider returned a failed response.";
|
|
1462
1583
|
throw new UPPError(
|
|
1463
|
-
|
|
1584
|
+
message,
|
|
1464
1585
|
ErrorCode.ProviderError,
|
|
1465
1586
|
"openrouter",
|
|
1466
1587
|
ModalityType.LLM
|