@providerprotocol/ai 0.0.16 → 0.0.18
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 +111 -8
- package/dist/anthropic/index.d.ts +1 -1
- package/dist/anthropic/index.js +5 -3
- package/dist/anthropic/index.js.map +1 -1
- package/dist/{chunk-MOU4U3PO.js → chunk-5FEAOEXV.js} +4 -68
- package/dist/chunk-5FEAOEXV.js.map +1 -0
- package/dist/chunk-DZQHVGNV.js +71 -0
- package/dist/chunk-DZQHVGNV.js.map +1 -0
- package/dist/chunk-SKY2JLA7.js +59 -0
- package/dist/chunk-SKY2JLA7.js.map +1 -0
- package/dist/{chunk-SVYROCLD.js → chunk-UMKWXGO3.js} +1 -1
- package/dist/chunk-UMKWXGO3.js.map +1 -0
- package/dist/google/index.d.ts +29 -2
- package/dist/google/index.js +107 -4
- package/dist/google/index.js.map +1 -1
- package/dist/http/index.d.ts +2 -2
- package/dist/http/index.js +2 -1
- package/dist/index.d.ts +211 -1303
- package/dist/index.js +161 -58
- package/dist/index.js.map +1 -1
- package/dist/ollama/index.d.ts +26 -2
- package/dist/ollama/index.js +101 -4
- package/dist/ollama/index.js.map +1 -1
- package/dist/openai/index.d.ts +28 -3
- package/dist/openai/index.js +111 -4
- package/dist/openai/index.js.map +1 -1
- package/dist/openrouter/index.d.ts +29 -3
- package/dist/openrouter/index.js +118 -4
- package/dist/openrouter/index.js.map +1 -1
- package/dist/{provider-vTZ74u-w.d.ts → provider-D5MO3-pS.d.ts} +66 -1
- package/dist/proxy/index.d.ts +611 -0
- package/dist/proxy/index.js +565 -0
- package/dist/proxy/index.js.map +1 -0
- package/dist/{retry-CMdT0kD8.d.ts → retry-DZ4Sqmxp.d.ts} +1 -1
- package/dist/stream-BjyVzBxV.d.ts +1286 -0
- package/dist/xai/index.d.ts +1 -1
- package/dist/xai/index.js +5 -3
- package/dist/xai/index.js.map +1 -1
- package/package.json +6 -1
- package/dist/chunk-MOU4U3PO.js.map +0 -1
- package/dist/chunk-SVYROCLD.js.map +0 -1
|
@@ -1,4 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as Provider, f as ModelReference, b as LLMHandler, c as EmbeddingHandler } from '../provider-D5MO3-pS.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview OpenRouter Embeddings API Handler
|
|
5
|
+
*
|
|
6
|
+
* This module implements the embedding handler for OpenRouter's embeddings API.
|
|
7
|
+
* OpenRouter provides access to multiple embedding providers through an OpenAI-compatible endpoint.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link https://openrouter.ai/docs/api/reference/embeddings OpenRouter Embeddings API Reference}
|
|
10
|
+
* @module providers/openrouter/embed
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* OpenRouter embedding parameters.
|
|
15
|
+
* Passed through unchanged to the API.
|
|
16
|
+
*/
|
|
17
|
+
interface OpenRouterEmbedParams {
|
|
18
|
+
/** Output dimensions (model-dependent) */
|
|
19
|
+
dimensions?: number;
|
|
20
|
+
/** Encoding format: 'float' or 'base64' */
|
|
21
|
+
encoding_format?: 'float' | 'base64';
|
|
22
|
+
/** A unique identifier representing your end-user */
|
|
23
|
+
user?: string;
|
|
24
|
+
/** Input type hint for some models */
|
|
25
|
+
input_type?: string;
|
|
26
|
+
}
|
|
2
27
|
|
|
3
28
|
/**
|
|
4
29
|
* OpenRouter-specific types for the Unified Provider Protocol.
|
|
@@ -289,10 +314,11 @@ interface OpenRouterProvider extends Provider<OpenRouterProviderOptions> {
|
|
|
289
314
|
readonly version: string;
|
|
290
315
|
/**
|
|
291
316
|
* Supported modalities for this provider.
|
|
292
|
-
* OpenRouter
|
|
317
|
+
* OpenRouter supports LLM (text generation) and Embedding.
|
|
293
318
|
*/
|
|
294
319
|
readonly modalities: {
|
|
295
320
|
llm: LLMHandler<OpenRouterLLMParamsUnion>;
|
|
321
|
+
embedding: EmbeddingHandler<OpenRouterEmbedParams>;
|
|
296
322
|
};
|
|
297
323
|
}
|
|
298
324
|
/**
|
|
@@ -346,4 +372,4 @@ interface OpenRouterProvider extends Provider<OpenRouterProviderOptions> {
|
|
|
346
372
|
*/
|
|
347
373
|
declare const openrouter: OpenRouterProvider;
|
|
348
374
|
|
|
349
|
-
export { type OpenRouterAPIMode, type OpenRouterCompletionsParams, type OpenRouterConfig, type OpenRouterModelOptions, type OpenRouterModelReference, type OpenRouterProviderPreferences, type OpenRouterResponsesParams, openrouter };
|
|
375
|
+
export { type OpenRouterAPIMode, type OpenRouterCompletionsParams, type OpenRouterConfig, type OpenRouterEmbedParams, type OpenRouterModelOptions, type OpenRouterModelReference, type OpenRouterProviderPreferences, type OpenRouterResponsesParams, openrouter };
|
package/dist/openrouter/index.js
CHANGED
|
@@ -3,17 +3,19 @@ import {
|
|
|
3
3
|
isAssistantMessage,
|
|
4
4
|
isToolResultMessage,
|
|
5
5
|
isUserMessage
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-UMKWXGO3.js";
|
|
7
7
|
import {
|
|
8
8
|
parseSSEStream
|
|
9
9
|
} from "../chunk-Z7RBRCRN.js";
|
|
10
10
|
import {
|
|
11
|
-
UPPError,
|
|
12
11
|
doFetch,
|
|
13
12
|
doStreamFetch,
|
|
14
13
|
normalizeHttpError,
|
|
15
14
|
resolveApiKey
|
|
16
|
-
} from "../chunk-
|
|
15
|
+
} from "../chunk-5FEAOEXV.js";
|
|
16
|
+
import {
|
|
17
|
+
UPPError
|
|
18
|
+
} from "../chunk-DZQHVGNV.js";
|
|
17
19
|
|
|
18
20
|
// src/providers/openrouter/transform.completions.ts
|
|
19
21
|
function transformRequest(request, modelId) {
|
|
@@ -1336,11 +1338,121 @@ function createResponsesLLMHandler() {
|
|
|
1336
1338
|
};
|
|
1337
1339
|
}
|
|
1338
1340
|
|
|
1341
|
+
// src/providers/openrouter/embed.ts
|
|
1342
|
+
var OPENROUTER_EMBEDDINGS_API_URL = "https://openrouter.ai/api/v1/embeddings";
|
|
1343
|
+
function getDefaultDimensions(modelId) {
|
|
1344
|
+
if (modelId.includes("text-embedding-3-large")) {
|
|
1345
|
+
return 3072;
|
|
1346
|
+
}
|
|
1347
|
+
if (modelId.includes("text-embedding-3-small") || modelId.includes("ada-002")) {
|
|
1348
|
+
return 1536;
|
|
1349
|
+
}
|
|
1350
|
+
if (modelId.includes("gemini-embedding")) {
|
|
1351
|
+
return 3072;
|
|
1352
|
+
}
|
|
1353
|
+
return 1536;
|
|
1354
|
+
}
|
|
1355
|
+
function createEmbeddingHandler() {
|
|
1356
|
+
let providerRef = null;
|
|
1357
|
+
return {
|
|
1358
|
+
supportedInputs: ["text"],
|
|
1359
|
+
_setProvider(provider) {
|
|
1360
|
+
providerRef = provider;
|
|
1361
|
+
},
|
|
1362
|
+
bind(modelId) {
|
|
1363
|
+
if (!providerRef) {
|
|
1364
|
+
throw new UPPError(
|
|
1365
|
+
"Provider reference not set. Handler must be used with createProvider().",
|
|
1366
|
+
"INVALID_REQUEST",
|
|
1367
|
+
"openrouter",
|
|
1368
|
+
"embedding"
|
|
1369
|
+
);
|
|
1370
|
+
}
|
|
1371
|
+
const model = {
|
|
1372
|
+
modelId,
|
|
1373
|
+
maxBatchSize: 2048,
|
|
1374
|
+
maxInputLength: 8191,
|
|
1375
|
+
dimensions: getDefaultDimensions(modelId),
|
|
1376
|
+
get provider() {
|
|
1377
|
+
return providerRef;
|
|
1378
|
+
},
|
|
1379
|
+
async embed(request) {
|
|
1380
|
+
const apiKey = await resolveApiKey(
|
|
1381
|
+
request.config,
|
|
1382
|
+
"OPENROUTER_API_KEY",
|
|
1383
|
+
"openrouter",
|
|
1384
|
+
"embedding"
|
|
1385
|
+
);
|
|
1386
|
+
const baseUrl = request.config.baseUrl ?? OPENROUTER_EMBEDDINGS_API_URL;
|
|
1387
|
+
const inputTexts = request.inputs.map((input) => {
|
|
1388
|
+
if (typeof input === "string") {
|
|
1389
|
+
return input;
|
|
1390
|
+
}
|
|
1391
|
+
if ("text" in input) {
|
|
1392
|
+
return input.text;
|
|
1393
|
+
}
|
|
1394
|
+
throw new UPPError(
|
|
1395
|
+
"OpenRouter embeddings only support text input",
|
|
1396
|
+
"INVALID_REQUEST",
|
|
1397
|
+
"openrouter",
|
|
1398
|
+
"embedding"
|
|
1399
|
+
);
|
|
1400
|
+
});
|
|
1401
|
+
const body = {
|
|
1402
|
+
model: modelId,
|
|
1403
|
+
input: inputTexts
|
|
1404
|
+
};
|
|
1405
|
+
if (request.params?.dimensions !== void 0) {
|
|
1406
|
+
body.dimensions = request.params.dimensions;
|
|
1407
|
+
}
|
|
1408
|
+
if (request.params?.encoding_format !== void 0) {
|
|
1409
|
+
body.encoding_format = request.params.encoding_format;
|
|
1410
|
+
}
|
|
1411
|
+
if (request.params?.user !== void 0) {
|
|
1412
|
+
body.user = request.params.user;
|
|
1413
|
+
}
|
|
1414
|
+
if (request.params?.input_type !== void 0) {
|
|
1415
|
+
body.input_type = request.params.input_type;
|
|
1416
|
+
}
|
|
1417
|
+
const headers = {
|
|
1418
|
+
"Content-Type": "application/json",
|
|
1419
|
+
Authorization: `Bearer ${apiKey}`
|
|
1420
|
+
};
|
|
1421
|
+
if (request.config.headers) {
|
|
1422
|
+
for (const [key, value] of Object.entries(request.config.headers)) {
|
|
1423
|
+
if (value !== void 0) {
|
|
1424
|
+
headers[key] = value;
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
const response = await doFetch(baseUrl, {
|
|
1429
|
+
method: "POST",
|
|
1430
|
+
headers,
|
|
1431
|
+
body: JSON.stringify(body),
|
|
1432
|
+
signal: request.signal
|
|
1433
|
+
}, request.config, "openrouter", "embedding");
|
|
1434
|
+
const data = await response.json();
|
|
1435
|
+
return {
|
|
1436
|
+
embeddings: data.data.map((d) => ({
|
|
1437
|
+
vector: d.embedding,
|
|
1438
|
+
index: d.index
|
|
1439
|
+
})),
|
|
1440
|
+
usage: { totalTokens: data.usage.total_tokens },
|
|
1441
|
+
metadata: data.usage.cost !== void 0 ? { cost: data.usage.cost } : void 0
|
|
1442
|
+
};
|
|
1443
|
+
}
|
|
1444
|
+
};
|
|
1445
|
+
return model;
|
|
1446
|
+
}
|
|
1447
|
+
};
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1339
1450
|
// src/providers/openrouter/index.ts
|
|
1340
1451
|
function createOpenRouterProvider() {
|
|
1341
1452
|
let currentApiMode = "completions";
|
|
1342
1453
|
const completionsHandler = createCompletionsLLMHandler();
|
|
1343
1454
|
const responsesHandler = createResponsesLLMHandler();
|
|
1455
|
+
const embeddingHandler = createEmbeddingHandler();
|
|
1344
1456
|
const fn = function(modelId, options) {
|
|
1345
1457
|
const apiMode = options?.api ?? "completions";
|
|
1346
1458
|
currentApiMode = apiMode;
|
|
@@ -1349,7 +1461,8 @@ function createOpenRouterProvider() {
|
|
|
1349
1461
|
const modalities = {
|
|
1350
1462
|
get llm() {
|
|
1351
1463
|
return currentApiMode === "responses" ? responsesHandler : completionsHandler;
|
|
1352
|
-
}
|
|
1464
|
+
},
|
|
1465
|
+
embedding: embeddingHandler
|
|
1353
1466
|
};
|
|
1354
1467
|
Object.defineProperties(fn, {
|
|
1355
1468
|
name: {
|
|
@@ -1371,6 +1484,7 @@ function createOpenRouterProvider() {
|
|
|
1371
1484
|
const provider = fn;
|
|
1372
1485
|
completionsHandler._setProvider?.(provider);
|
|
1373
1486
|
responsesHandler._setProvider?.(provider);
|
|
1487
|
+
embeddingHandler._setProvider?.(provider);
|
|
1374
1488
|
return provider;
|
|
1375
1489
|
}
|
|
1376
1490
|
var openrouter = createOpenRouterProvider();
|