+5
-2
@@ -38,2 +38,5 @@ declare enum ClaudeModel { | ||
| } | ||
| declare enum OpenRouterModel { | ||
| QWEN3_6_PLUS_FREE = "qwen/qwen3.6-plus:free" | ||
| } | ||
| declare enum GeminiModel { | ||
@@ -103,3 +106,3 @@ GEMINI_1_5_PRO = "gemini-1.5-pro-latest", | ||
| } | ||
| type AnyModel = GPTModel | ClaudeModel | GroqModel | GeminiModel; | ||
| type AnyModel = GPTModel | ClaudeModel | GroqModel | GeminiModel | OpenRouterModel; | ||
| interface GenericPayload { | ||
@@ -118,2 +121,2 @@ model: AnyModel; | ||
| export { type AnyModel, ClaudeModel, type FunctionDefinition, GPTModel, GeminiModel, type GenericMessage, type GenericPayload, GroqModel, type OpenAIConfig, callWithRetries }; | ||
| export { type AnyModel, ClaudeModel, type FunctionDefinition, GPTModel, GeminiModel, type GenericMessage, type GenericPayload, GroqModel, type OpenAIConfig, OpenRouterModel, callWithRetries }; |
+5
-2
@@ -38,2 +38,5 @@ declare enum ClaudeModel { | ||
| } | ||
| declare enum OpenRouterModel { | ||
| QWEN3_6_PLUS_FREE = "qwen/qwen3.6-plus:free" | ||
| } | ||
| declare enum GeminiModel { | ||
@@ -103,3 +106,3 @@ GEMINI_1_5_PRO = "gemini-1.5-pro-latest", | ||
| } | ||
| type AnyModel = GPTModel | ClaudeModel | GroqModel | GeminiModel; | ||
| type AnyModel = GPTModel | ClaudeModel | GroqModel | GeminiModel | OpenRouterModel; | ||
| interface GenericPayload { | ||
@@ -118,2 +121,2 @@ model: AnyModel; | ||
| export { type AnyModel, ClaudeModel, type FunctionDefinition, GPTModel, GeminiModel, type GenericMessage, type GenericPayload, GroqModel, type OpenAIConfig, callWithRetries }; | ||
| export { type AnyModel, ClaudeModel, type FunctionDefinition, GPTModel, GeminiModel, type GenericMessage, type GenericPayload, GroqModel, type OpenAIConfig, OpenRouterModel, callWithRetries }; |
+74
-0
@@ -37,2 +37,3 @@ "use strict"; | ||
| GroqModel: () => GroqModel, | ||
| OpenRouterModel: () => OpenRouterModel, | ||
| callWithRetries: () => callWithRetries | ||
@@ -83,2 +84,6 @@ }); | ||
| })(GroqModel || {}); | ||
| var OpenRouterModel = /* @__PURE__ */ ((OpenRouterModel2) => { | ||
| OpenRouterModel2["QWEN3_6_PLUS_FREE"] = "qwen/qwen3.6-plus:free"; | ||
| return OpenRouterModel2; | ||
| })(OpenRouterModel || {}); | ||
| var GeminiModel = /* @__PURE__ */ ((GeminiModel2) => { | ||
@@ -1034,2 +1039,60 @@ GeminiModel2["GEMINI_1_5_PRO"] = "gemini-1.5-pro-latest"; | ||
| } | ||
| function prepareOpenRouterPayload(payload) { | ||
| var _a; | ||
| return { | ||
| model: payload.model, | ||
| messages: payload.messages.map((message) => ({ | ||
| role: message.role, | ||
| content: normalizeMessageContent(message.content) | ||
| })), | ||
| tools: (_a = payload.functions) == null ? void 0 : _a.map((fn) => ({ | ||
| type: "function", | ||
| function: fn | ||
| })), | ||
| tool_choice: payload.function_call ? typeof payload.function_call === "string" ? payload.function_call : { type: "function", function: payload.function_call } : void 0, | ||
| temperature: payload.temperature | ||
| }; | ||
| } | ||
| async function callOpenRouter(id, payload) { | ||
| var _a, _b; | ||
| const response = await import_axios.default.post( | ||
| "https://openrouter.ai/api/v1/chat/completions", | ||
| payload, | ||
| { | ||
| headers: { | ||
| "content-type": "application/json", | ||
| Authorization: `Bearer ${process.env.OPENROUTER_API_KEY}` | ||
| } | ||
| } | ||
| ); | ||
| const answer = (_a = response.data.choices[0]) == null ? void 0 : _a.message; | ||
| if (!answer) { | ||
| logger_default.error(id, "Missing answer in OpenRouter API response:", response.data); | ||
| throw new Error("Missing answer in OpenRouter API"); | ||
| } | ||
| const functionCalls = []; | ||
| if ((_b = answer.tool_calls) == null ? void 0 : _b.length) { | ||
| for (const tc of answer.tool_calls) { | ||
| functionCalls.push({ | ||
| name: tc.function.name, | ||
| arguments: JSON.parse(tc.function.arguments) | ||
| }); | ||
| } | ||
| } | ||
| return { | ||
| role: "assistant", | ||
| content: answer.content || null, | ||
| function_call: functionCalls[0] || null, | ||
| function_calls: functionCalls, | ||
| files: [], | ||
| usage: response.data.usage ? { | ||
| prompt_tokens: response.data.usage.prompt_tokens, | ||
| completion_tokens: response.data.usage.completion_tokens, | ||
| total_tokens: response.data.usage.total_tokens | ||
| } : null | ||
| }; | ||
| } | ||
| async function callOpenRouterWithRetries(id, payload, retries = 5) { | ||
| return withRetries(id, "OpenRouter", () => callOpenRouter(id, payload), { retries }); | ||
| } | ||
| function isAnthropicPayload(payload) { | ||
@@ -1047,2 +1110,5 @@ return Object.values(ClaudeModel).includes(payload.model); | ||
| } | ||
| function isOpenRouterPayload(payload) { | ||
| return Object.values(OpenRouterModel).includes(payload.model); | ||
| } | ||
| async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeoutMs = 15e3) { | ||
@@ -1081,2 +1147,9 @@ try { | ||
| } | ||
| if (isOpenRouterPayload(aiPayload)) { | ||
| return await callOpenRouterWithRetries( | ||
| id, | ||
| prepareOpenRouterPayload(aiPayload), | ||
| retries | ||
| ); | ||
| } | ||
| throw new Error("Invalid AI payload: Unknown model type."); | ||
@@ -1114,4 +1187,5 @@ } catch (error2) { | ||
| GroqModel, | ||
| OpenRouterModel, | ||
| callWithRetries | ||
| }); | ||
| //# sourceMappingURL=index.js.map |
+73
-0
@@ -50,2 +50,6 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { | ||
| })(GroqModel || {}); | ||
| var OpenRouterModel = /* @__PURE__ */ ((OpenRouterModel2) => { | ||
| OpenRouterModel2["QWEN3_6_PLUS_FREE"] = "qwen/qwen3.6-plus:free"; | ||
| return OpenRouterModel2; | ||
| })(OpenRouterModel || {}); | ||
| var GeminiModel = /* @__PURE__ */ ((GeminiModel2) => { | ||
@@ -1004,2 +1008,60 @@ GeminiModel2["GEMINI_1_5_PRO"] = "gemini-1.5-pro-latest"; | ||
| } | ||
| function prepareOpenRouterPayload(payload) { | ||
| var _a; | ||
| return { | ||
| model: payload.model, | ||
| messages: payload.messages.map((message) => ({ | ||
| role: message.role, | ||
| content: normalizeMessageContent(message.content) | ||
| })), | ||
| tools: (_a = payload.functions) == null ? void 0 : _a.map((fn) => ({ | ||
| type: "function", | ||
| function: fn | ||
| })), | ||
| tool_choice: payload.function_call ? typeof payload.function_call === "string" ? payload.function_call : { type: "function", function: payload.function_call } : void 0, | ||
| temperature: payload.temperature | ||
| }; | ||
| } | ||
| async function callOpenRouter(id, payload) { | ||
| var _a, _b; | ||
| const response = await axios.post( | ||
| "https://openrouter.ai/api/v1/chat/completions", | ||
| payload, | ||
| { | ||
| headers: { | ||
| "content-type": "application/json", | ||
| Authorization: `Bearer ${process.env.OPENROUTER_API_KEY}` | ||
| } | ||
| } | ||
| ); | ||
| const answer = (_a = response.data.choices[0]) == null ? void 0 : _a.message; | ||
| if (!answer) { | ||
| logger_default.error(id, "Missing answer in OpenRouter API response:", response.data); | ||
| throw new Error("Missing answer in OpenRouter API"); | ||
| } | ||
| const functionCalls = []; | ||
| if ((_b = answer.tool_calls) == null ? void 0 : _b.length) { | ||
| for (const tc of answer.tool_calls) { | ||
| functionCalls.push({ | ||
| name: tc.function.name, | ||
| arguments: JSON.parse(tc.function.arguments) | ||
| }); | ||
| } | ||
| } | ||
| return { | ||
| role: "assistant", | ||
| content: answer.content || null, | ||
| function_call: functionCalls[0] || null, | ||
| function_calls: functionCalls, | ||
| files: [], | ||
| usage: response.data.usage ? { | ||
| prompt_tokens: response.data.usage.prompt_tokens, | ||
| completion_tokens: response.data.usage.completion_tokens, | ||
| total_tokens: response.data.usage.total_tokens | ||
| } : null | ||
| }; | ||
| } | ||
| async function callOpenRouterWithRetries(id, payload, retries = 5) { | ||
| return withRetries(id, "OpenRouter", () => callOpenRouter(id, payload), { retries }); | ||
| } | ||
| function isAnthropicPayload(payload) { | ||
@@ -1017,2 +1079,5 @@ return Object.values(ClaudeModel).includes(payload.model); | ||
| } | ||
| function isOpenRouterPayload(payload) { | ||
| return Object.values(OpenRouterModel).includes(payload.model); | ||
| } | ||
| async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeoutMs = 15e3) { | ||
@@ -1051,2 +1116,9 @@ try { | ||
| } | ||
| if (isOpenRouterPayload(aiPayload)) { | ||
| return await callOpenRouterWithRetries( | ||
| id, | ||
| prepareOpenRouterPayload(aiPayload), | ||
| retries | ||
| ); | ||
| } | ||
| throw new Error("Invalid AI payload: Unknown model type."); | ||
@@ -1083,4 +1155,5 @@ } catch (error2) { | ||
| GroqModel, | ||
| OpenRouterModel, | ||
| callWithRetries | ||
| }; | ||
| //# sourceMappingURL=index.mjs.map |
+1
-1
| { | ||
| "name": "190proof", | ||
| "version": "1.0.87", | ||
| "version": "1.0.88", | ||
| "description": "", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
+15
-1
| # 190proof | ||
| A unified interface for interacting with multiple AI providers including **OpenAI**, **Anthropic**, **Google**, **Groq**, and **AWS Bedrock**. This package provides a consistent API for making requests to different LLM providers while handling retries, streaming, and multimodal inputs. | ||
| A unified interface for interacting with multiple AI providers including **OpenAI**, **Anthropic**, **Google**, **Groq**, **OpenRouter**, and **AWS Bedrock**. This package provides a consistent API for making requests to different LLM providers while handling retries, streaming, and multimodal inputs. | ||
@@ -52,2 +52,3 @@ ## Features | ||
| GroqModel, | ||
| OpenRouterModel, | ||
| GenericPayload, | ||
@@ -74,2 +75,8 @@ } from "190proof/interfaces"; | ||
| // OpenRouter | ||
| const openRouterPayload: GenericPayload = { | ||
| model: OpenRouterModel.QWEN3_6_PLUS_FREE, | ||
| messages: [{ role: "user", content: "Hello!" }], | ||
| }; | ||
| const response = await callWithRetries("request-id", claudePayload); | ||
@@ -205,2 +212,6 @@ ``` | ||
| ### OpenRouter Models | ||
| - `qwen/qwen3.6-plus:free` | ||
| ## Environment Variables | ||
@@ -223,2 +234,5 @@ | ||
| # OpenRouter | ||
| OPENROUTER_API_KEY=your-openrouter-api-key | ||
| # AWS Bedrock (for Anthropic via Bedrock) | ||
@@ -225,0 +239,0 @@ AWS_ACCESS_KEY_ID=your-aws-access-key |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
248025
6.74%2441
6.55%306
4.79%12
20%