@absolutejs/ai 0.0.52 → 0.0.53
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 +43 -3
- package/dist/ai/index.js +89 -1
- package/dist/ai/index.js.map +4 -4
- package/dist/ai/providers/openrouter.js +89 -1
- package/dist/ai/providers/openrouter.js.map +4 -4
- package/dist/ai/providers/openrouterSDK.js +37 -0
- package/dist/ai/providers/openrouterSDK.js.map +10 -0
- package/dist/src/ai/index.d.ts +1 -1
- package/dist/src/ai/providers/openrouter.d.ts +143 -4
- package/dist/src/ai/providers/openrouterClient.d.ts +13 -0
- package/dist/src/ai/providers/openrouterSDK.d.ts +21 -0
- package/package.json +10 -2
|
@@ -2256,6 +2256,13 @@ var createOpenRouterClient = (config2) => {
|
|
|
2256
2256
|
},
|
|
2257
2257
|
method: "POST"
|
|
2258
2258
|
}),
|
|
2259
|
+
chat: (body) => {
|
|
2260
|
+
assertAllowedModelsInValue(body, allowedModels);
|
|
2261
|
+
return request("/chat/completions", {
|
|
2262
|
+
body: { ...body, stream: false },
|
|
2263
|
+
method: "POST"
|
|
2264
|
+
});
|
|
2265
|
+
},
|
|
2259
2266
|
createPresetFromChatCompletions: (slug, body) => {
|
|
2260
2267
|
assertAllowedModelsInValue(body, allowedModels);
|
|
2261
2268
|
return request(`/presets/${encodeURIComponent(slug)}/chat/completions`, { body, method: "POST" });
|
|
@@ -2358,6 +2365,7 @@ var createOpenRouterClient = (config2) => {
|
|
|
2358
2365
|
getVideo: (id) => request(`/videos/${encodeURIComponent(id)}`),
|
|
2359
2366
|
getWorkspace: (id) => request(`/workspaces/${encodeURIComponent(id)}`),
|
|
2360
2367
|
listImageModels: async () => filterModelList(await request("/images/models")),
|
|
2368
|
+
listEmbeddingModels: async () => filterModelList(await request("/embeddings/models")),
|
|
2361
2369
|
listFiles: (query) => request("/files", {
|
|
2362
2370
|
query: {
|
|
2363
2371
|
...query,
|
|
@@ -2629,6 +2637,84 @@ var assertIndirectModels = (value, allowedModels, key = "") => {
|
|
|
2629
2637
|
assertIndirectModels(child, allowedModels, childKey);
|
|
2630
2638
|
}
|
|
2631
2639
|
};
|
|
2640
|
+
var assertIntegerRange = (label, value, minimum, maximum) => {
|
|
2641
|
+
if (value === undefined)
|
|
2642
|
+
return;
|
|
2643
|
+
if (!Number.isInteger(value) || value < minimum || maximum !== undefined && value > maximum)
|
|
2644
|
+
throw new Error(`OpenRouter ${label} must be an integer from ${minimum}${maximum === undefined ? " or greater" : ` to ${maximum}`}`);
|
|
2645
|
+
};
|
|
2646
|
+
var assertPluginOptions = (plugins) => {
|
|
2647
|
+
for (const plugin of plugins ?? []) {
|
|
2648
|
+
if (plugin.id === "response-healing")
|
|
2649
|
+
throw new Error("OpenRouter response-healing requires a non-streaming request; use createOpenRouterClient().chat()");
|
|
2650
|
+
if (plugin.id === "fusion") {
|
|
2651
|
+
const fusion = plugin;
|
|
2652
|
+
if (fusion.analysis_models && (fusion.analysis_models.length < 1 || fusion.analysis_models.length > 8))
|
|
2653
|
+
throw new Error("OpenRouter Fusion analysis_models must contain 1-8 models");
|
|
2654
|
+
assertIntegerRange("Fusion max_tool_calls", fusion.max_tool_calls, 1, 16);
|
|
2655
|
+
}
|
|
2656
|
+
if (plugin.id === "web") {
|
|
2657
|
+
const web = plugin;
|
|
2658
|
+
assertIntegerRange("web plugin max_results", web.max_results, 1, web.engine === "perplexity" ? 20 : 25);
|
|
2659
|
+
if (web.include_domains?.length && web.exclude_domains?.length && (web.engine === "firecrawl" || web.engine === "parallel" || web.engine === "perplexity"))
|
|
2660
|
+
throw new Error(`OpenRouter ${web.engine} web plugin cannot combine include_domains and exclude_domains`);
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
};
|
|
2664
|
+
var assertServerToolOptions = (tools) => {
|
|
2665
|
+
for (const tool of tools ?? []) {
|
|
2666
|
+
if (tool.type === "openrouter:web_search") {
|
|
2667
|
+
const parameters = tool.parameters;
|
|
2668
|
+
assertIntegerRange("web search max_results", parameters?.max_results, 1, 25);
|
|
2669
|
+
if (parameters?.engine === "perplexity" && (parameters.max_results ?? 0) > 20)
|
|
2670
|
+
throw new Error("OpenRouter Perplexity web search max_results must be at most 20");
|
|
2671
|
+
assertIntegerRange("web search max_characters", parameters?.max_characters, 1, 1e5);
|
|
2672
|
+
assertIntegerRange("web search max_total_results", parameters?.max_total_results, 1);
|
|
2673
|
+
}
|
|
2674
|
+
if (tool.type === "openrouter:web_fetch") {
|
|
2675
|
+
assertIntegerRange("web fetch max_uses", tool.parameters?.max_uses, 1);
|
|
2676
|
+
assertIntegerRange("web fetch max_content_tokens", tool.parameters?.max_content_tokens, 1);
|
|
2677
|
+
}
|
|
2678
|
+
if (tool.type === "openrouter:image_generation") {
|
|
2679
|
+
const compression = tool.parameters?.output_compression;
|
|
2680
|
+
if (compression !== undefined && (!Number.isFinite(compression) || compression < 0 || compression > 100))
|
|
2681
|
+
throw new Error("OpenRouter image generation output_compression must be 0-100");
|
|
2682
|
+
}
|
|
2683
|
+
if (tool.type === "openrouter:subagent") {
|
|
2684
|
+
assertIntegerRange("subagent max_completion_tokens", tool.parameters.max_completion_tokens, 1);
|
|
2685
|
+
assertIntegerRange("subagent max_tool_calls", tool.parameters.max_tool_calls, 1, 25);
|
|
2686
|
+
const temperature = tool.parameters.temperature;
|
|
2687
|
+
if (temperature !== undefined && (!Number.isFinite(temperature) || temperature < 0 || temperature > 2))
|
|
2688
|
+
throw new Error("OpenRouter subagent temperature must be 0-2");
|
|
2689
|
+
assertServerToolOptions(tool.parameters.tools);
|
|
2690
|
+
}
|
|
2691
|
+
if (tool.type === "openrouter:advisor") {
|
|
2692
|
+
assertIntegerRange("advisor max_completion_tokens", tool.parameters?.max_completion_tokens, 1);
|
|
2693
|
+
const temperature = tool.parameters?.temperature;
|
|
2694
|
+
if (temperature !== undefined && (!Number.isFinite(temperature) || temperature < 0 || temperature > 2))
|
|
2695
|
+
throw new Error("OpenRouter advisor temperature must be 0-2");
|
|
2696
|
+
}
|
|
2697
|
+
if (tool.type === "openrouter:fusion") {
|
|
2698
|
+
const analysisModels = tool.parameters?.analysis_models;
|
|
2699
|
+
if (analysisModels && (analysisModels.length < 1 || analysisModels.length > 8))
|
|
2700
|
+
throw new Error("OpenRouter Fusion server tool analysis_models must contain 1-8 models");
|
|
2701
|
+
assertIntegerRange("Fusion server tool max_completion_tokens", tool.parameters?.max_completion_tokens, 1);
|
|
2702
|
+
assertIntegerRange("Fusion server tool max_tool_calls", tool.parameters?.max_tool_calls, 1, 16);
|
|
2703
|
+
const temperature = tool.parameters?.temperature;
|
|
2704
|
+
if (temperature !== undefined && (!Number.isFinite(temperature) || temperature < 0 || temperature > 2))
|
|
2705
|
+
throw new Error("OpenRouter Fusion server tool temperature must be 0-2");
|
|
2706
|
+
assertServerToolOptions(tool.parameters?.tools);
|
|
2707
|
+
}
|
|
2708
|
+
if (tool.type === "openrouter:shell") {
|
|
2709
|
+
assertIntegerRange("shell sleep_after_seconds", tool.parameters?.sleep_after_seconds, 0, 2592000);
|
|
2710
|
+
const environment = tool.parameters?.environment;
|
|
2711
|
+
if (environment?.type === "container_reference" && (environment.container_id.length < 1 || environment.container_id.length > 20))
|
|
2712
|
+
throw new Error("OpenRouter shell container_id must contain 1-20 characters");
|
|
2713
|
+
}
|
|
2714
|
+
if (tool.type === "openrouter:experimental__search_models")
|
|
2715
|
+
assertIntegerRange("model search max_results", tool.parameters?.max_results, 1, 20);
|
|
2716
|
+
}
|
|
2717
|
+
};
|
|
2632
2718
|
var assertRequestOptions = (options, allowedModels, allowedPresets, allowedProviders) => {
|
|
2633
2719
|
assertAllowedPreset(options.preset, allowedPresets);
|
|
2634
2720
|
assertRequestRoutingPolicy(options.routing, allowedProviders);
|
|
@@ -2648,6 +2734,8 @@ var assertRequestOptions = (options, allowedModels, allowedPresets, allowedProvi
|
|
|
2648
2734
|
assertIndirectModels(options.serverTools, allowedModels);
|
|
2649
2735
|
assertIndirectModels(options.messagesTools, allowedModels);
|
|
2650
2736
|
assertIndirectModels(options.plugins, allowedModels);
|
|
2737
|
+
assertPluginOptions(options.plugins);
|
|
2738
|
+
assertServerToolOptions(options.serverTools);
|
|
2651
2739
|
if (options.extraBody) {
|
|
2652
2740
|
const unsafe = Object.keys(options.extraBody).find((key) => SECURITY_SENSITIVE_EXTRA_BODY_FIELDS.has(key));
|
|
2653
2741
|
if (unsafe)
|
|
@@ -2819,5 +2907,5 @@ export {
|
|
|
2819
2907
|
createOpenRouterAuthorizationUrl
|
|
2820
2908
|
};
|
|
2821
2909
|
|
|
2822
|
-
//# debugId=
|
|
2910
|
+
//# debugId=438B311BAC94C67664756E2164756E21
|
|
2823
2911
|
//# sourceMappingURL=openrouter.js.map
|