+4
-3
@@ -262,5 +262,6 @@ /** @deprecated Use provider prefix strings instead, e.g. `"anthropic:claude-sonnet-4-5"` */ | ||
| * Per-request HTTP timeout in ms for the underlying provider call (applied | ||
| * per attempt, not across retries). Currently honored by the Google adapter; | ||
| * defaults to 60s when omitted. Raise it for slow, large generations (e.g. | ||
| * single-file app codegen) so a long-but-valid response isn't cut short. | ||
| * per attempt, not across retries). Honored by all adapters (Anthropic, | ||
| * Google, OpenAI, OpenRouter, Groq); defaults to 120s when omitted. Raise it | ||
| * for slow, large generations (e.g. single-file app codegen) so a long-but- | ||
| * valid response isn't cut short. | ||
| */ | ||
@@ -267,0 +268,0 @@ requestTimeoutMs?: number; |
+4
-3
@@ -262,5 +262,6 @@ /** @deprecated Use provider prefix strings instead, e.g. `"anthropic:claude-sonnet-4-5"` */ | ||
| * Per-request HTTP timeout in ms for the underlying provider call (applied | ||
| * per attempt, not across retries). Currently honored by the Google adapter; | ||
| * defaults to 60s when omitted. Raise it for slow, large generations (e.g. | ||
| * single-file app codegen) so a long-but-valid response isn't cut short. | ||
| * per attempt, not across retries). Honored by all adapters (Anthropic, | ||
| * Google, OpenAI, OpenRouter, Groq); defaults to 120s when omitted. Raise it | ||
| * for slow, large generations (e.g. single-file app codegen) so a long-but- | ||
| * valid response isn't cut short. | ||
| */ | ||
@@ -267,0 +268,0 @@ requestTimeoutMs?: number; |
+83
-54
@@ -388,3 +388,3 @@ "use strict"; | ||
| } | ||
| async function callOpenAIStream(id, openAiPayload, openAiConfig, chunkTimeoutMs) { | ||
| async function callOpenAIStream(id, openAiPayload, openAiConfig, chunkTimeoutMs, requestTimeoutMs = 12e4) { | ||
| var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j; | ||
@@ -398,2 +398,9 @@ const functionNames = openAiPayload.tools ? new Set(openAiPayload.tools.map((fn) => fn.function.name)) : null; | ||
| const controller = new AbortController(); | ||
| const overallTimeout = setTimeout(() => { | ||
| logger_default.error(id, `Request timeout after ${requestTimeoutMs}ms`); | ||
| controller.abort(); | ||
| }, requestTimeoutMs); | ||
| if (typeof overallTimeout === "object" && "unref" in overallTimeout) { | ||
| overallTimeout.unref(); | ||
| } | ||
| const response = await fetch(endpoint, { | ||
@@ -440,2 +447,3 @@ method: "POST", | ||
| if (jsonString.includes("[DONE]")) { | ||
| clearTimeout(overallTimeout); | ||
| return parseStreamedResponse( | ||
@@ -493,3 +501,3 @@ id, | ||
| } | ||
| async function callOpenAI(id, openAiPayload, openAiConfig) { | ||
| async function callOpenAI(id, openAiPayload, openAiConfig, requestTimeoutMs = 12e4) { | ||
| var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j; | ||
@@ -501,13 +509,21 @@ const { endpoint, headers } = buildOpenAIRequestConfig( | ||
| ); | ||
| const response = await fetch(endpoint, { | ||
| method: "POST", | ||
| headers, | ||
| body: JSON.stringify({ ...openAiPayload, stream: false }) | ||
| }); | ||
| if (!response.ok) { | ||
| const errorData = await response.json(); | ||
| logger_default.error(id, "OpenAI API error:", errorData); | ||
| throw new Error(`OpenAI API Error: ${errorData.error.message}`); | ||
| const controller = new AbortController(); | ||
| const timer = setTimeout(() => controller.abort(), requestTimeoutMs); | ||
| let data; | ||
| try { | ||
| const response = await fetch(endpoint, { | ||
| method: "POST", | ||
| headers, | ||
| body: JSON.stringify({ ...openAiPayload, stream: false }), | ||
| signal: controller.signal | ||
| }); | ||
| if (!response.ok) { | ||
| const errorData = await response.json(); | ||
| logger_default.error(id, "OpenAI API error:", errorData); | ||
| throw new Error(`OpenAI API Error: ${errorData.error.message}`); | ||
| } | ||
| data = await response.json(); | ||
| } finally { | ||
| clearTimeout(timer); | ||
| } | ||
| const data = await response.json(); | ||
| if (!((_a = data.choices) == null ? void 0 : _a.length)) { | ||
@@ -565,3 +581,3 @@ if (data.error) { | ||
| } | ||
| async function callOpenAiWithRetries(id, openAiPayload, openAiConfig, retries = 5, chunkTimeoutMs = 15e3) { | ||
| async function callOpenAiWithRetries(id, openAiPayload, openAiConfig, retries = 5, chunkTimeoutMs = 15e3, requestTimeoutMs = 12e4) { | ||
| logger_default.log( | ||
@@ -584,6 +600,7 @@ id, | ||
| openAiConfig, | ||
| chunkTimeoutMs | ||
| chunkTimeoutMs, | ||
| requestTimeoutMs | ||
| ); | ||
| } else { | ||
| return callOpenAI(id, openAiPayload, openAiConfig); | ||
| return callOpenAI(id, openAiPayload, openAiConfig, requestTimeoutMs); | ||
| } | ||
@@ -724,3 +741,3 @@ }, | ||
| } | ||
| async function callAnthropic(id, payload, config) { | ||
| async function callAnthropic(id, payload, config, requestTimeoutMs = 12e4) { | ||
| var _a, _b, _c; | ||
@@ -775,3 +792,3 @@ const anthropicMessages = jigAnthropicMessages(payload.messages); | ||
| }, | ||
| timeout: 6e4 | ||
| timeout: requestTimeoutMs | ||
| } | ||
@@ -846,7 +863,7 @@ ); | ||
| } | ||
| async function callAnthropicWithRetries(id, payload, config, retries = 5) { | ||
| async function callAnthropicWithRetries(id, payload, config, retries = 5, requestTimeoutMs = 12e4) { | ||
| return withRetries( | ||
| id, | ||
| "Anthropic", | ||
| () => callAnthropic(id, payload, config), | ||
| () => callAnthropic(id, payload, config, requestTimeoutMs), | ||
| { | ||
@@ -887,3 +904,2 @@ retries | ||
| messages: [], | ||
| requestTimeoutMs: payload.requestTimeoutMs, | ||
| tools: payload.functions ? { | ||
@@ -973,4 +989,4 @@ functionDeclarations: payload.functions.map((fn) => ({ | ||
| } | ||
| async function callGoogleAI(id, payload) { | ||
| var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s; | ||
| async function callGoogleAI(id, payload, requestTimeoutMs = 12e4) { | ||
| var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r; | ||
| const contents = jigGoogleMessages(payload.messages); | ||
@@ -998,6 +1014,3 @@ const requestBody = { | ||
| }, | ||
| // Per-attempt timeout. Defaults to 60s; callers pass a larger value via | ||
| // payload.requestTimeoutMs for slow, large generations (e.g. single-file | ||
| // app codegen) so a long-but-valid response isn't cut short. | ||
| timeout: (_a = payload.requestTimeoutMs) != null ? _a : 6e4 | ||
| timeout: requestTimeoutMs | ||
| } | ||
@@ -1007,10 +1020,10 @@ ); | ||
| } catch (err) { | ||
| const apiError = (_c = (_b = err == null ? void 0 : err.response) == null ? void 0 : _b.data) == null ? void 0 : _c.error; | ||
| const apiError = (_b = (_a = err == null ? void 0 : err.response) == null ? void 0 : _a.data) == null ? void 0 : _b.error; | ||
| const wrapped = new Error( | ||
| (apiError == null ? void 0 : apiError.message) || (err == null ? void 0 : err.message) || "Google AI API request failed" | ||
| ); | ||
| wrapped.status = (_e = apiError == null ? void 0 : apiError.status) != null ? _e : (_d = err == null ? void 0 : err.response) == null ? void 0 : _d.status; | ||
| wrapped.status = (_d = apiError == null ? void 0 : apiError.status) != null ? _d : (_c = err == null ? void 0 : err.response) == null ? void 0 : _c.status; | ||
| wrapped.code = apiError == null ? void 0 : apiError.code; | ||
| wrapped.details = apiError == null ? void 0 : apiError.details; | ||
| wrapped.promptFeedback = (_g = (_f = err == null ? void 0 : err.response) == null ? void 0 : _f.data) == null ? void 0 : _g.promptFeedback; | ||
| wrapped.promptFeedback = (_f = (_e = err == null ? void 0 : err.response) == null ? void 0 : _e.data) == null ? void 0 : _f.promptFeedback; | ||
| throw wrapped; | ||
@@ -1022,3 +1035,3 @@ } | ||
| const functionCalls = []; | ||
| for (const part of ((_j = (_i = (_h = response.candidates) == null ? void 0 : _h[0]) == null ? void 0 : _i.content) == null ? void 0 : _j.parts) || []) { | ||
| for (const part of ((_i = (_h = (_g = response.candidates) == null ? void 0 : _g[0]) == null ? void 0 : _h.content) == null ? void 0 : _i.parts) || []) { | ||
| if (part.thought) { | ||
@@ -1030,5 +1043,5 @@ reasoningParts.push(part); | ||
| functionCalls.push({ | ||
| id: (_k = part.functionCall.id) != null ? _k : `call_${functionCalls.length}`, | ||
| name: (_l = part.functionCall.name) != null ? _l : "", | ||
| arguments: (_m = part.functionCall.args) != null ? _m : {}, | ||
| id: (_j = part.functionCall.id) != null ? _j : `call_${functionCalls.length}`, | ||
| name: (_k = part.functionCall.name) != null ? _k : "", | ||
| arguments: (_l = part.functionCall.args) != null ? _l : {}, | ||
| thoughtSignature: part.thoughtSignature | ||
@@ -1040,3 +1053,3 @@ }); | ||
| text += part.text; | ||
| if ((_n = part.inlineData) == null ? void 0 : _n.data) { | ||
| if ((_m = part.inlineData) == null ? void 0 : _m.data) { | ||
| files.push({ mimeType: "image/png", data: part.inlineData.data }); | ||
@@ -1046,3 +1059,3 @@ } | ||
| if (!text && !functionCalls.length && !files.length) { | ||
| const candidate = (_o = response.candidates) == null ? void 0 : _o[0]; | ||
| const candidate = (_n = response.candidates) == null ? void 0 : _n[0]; | ||
| const finishReason = candidate == null ? void 0 : candidate.finishReason; | ||
@@ -1082,6 +1095,6 @@ logger_default.error(id, "Missing text & functions in Google AI API response:", { | ||
| usage: response.usageMetadata ? { | ||
| prompt_tokens: (_p = response.usageMetadata.promptTokenCount) != null ? _p : 0, | ||
| completion_tokens: (_q = response.usageMetadata.candidatesTokenCount) != null ? _q : 0, | ||
| total_tokens: (_r = response.usageMetadata.totalTokenCount) != null ? _r : 0, | ||
| cached_tokens: (_s = response.usageMetadata.cachedContentTokenCount) != null ? _s : 0 | ||
| prompt_tokens: (_o = response.usageMetadata.promptTokenCount) != null ? _o : 0, | ||
| completion_tokens: (_p = response.usageMetadata.candidatesTokenCount) != null ? _p : 0, | ||
| total_tokens: (_q = response.usageMetadata.totalTokenCount) != null ? _q : 0, | ||
| cached_tokens: (_r = response.usageMetadata.cachedContentTokenCount) != null ? _r : 0 | ||
| } : null | ||
@@ -1107,5 +1120,5 @@ }; | ||
| } | ||
| async function callGoogleAIWithRetries(id, payload, retries = 5) { | ||
| async function callGoogleAIWithRetries(id, payload, retries = 5, requestTimeoutMs = 12e4) { | ||
| let hasTriedWithoutImages = false; | ||
| return withRetries(id, "Google AI", () => callGoogleAI(id, payload), { | ||
| return withRetries(id, "Google AI", () => callGoogleAI(id, payload, requestTimeoutMs), { | ||
| retries, | ||
@@ -1237,3 +1250,3 @@ onError: (error2, attempt) => { | ||
| } | ||
| async function callGroq(id, payload) { | ||
| async function callGroq(id, payload, requestTimeoutMs = 12e4) { | ||
| var _a, _b, _c, _d, _e, _f, _g; | ||
@@ -1247,3 +1260,4 @@ const response = await import_axios.default.post( | ||
| Authorization: `Bearer ${process.env.GROQ_API_KEY}` | ||
| } | ||
| }, | ||
| timeout: requestTimeoutMs | ||
| } | ||
@@ -1296,4 +1310,6 @@ ); | ||
| } | ||
| async function callGroqWithRetries(id, payload, retries = 5) { | ||
| return withRetries(id, "Groq", () => callGroq(id, payload), { retries }); | ||
| async function callGroqWithRetries(id, payload, retries = 5, requestTimeoutMs = 12e4) { | ||
| return withRetries(id, "Groq", () => callGroq(id, payload, requestTimeoutMs), { | ||
| retries | ||
| }); | ||
| } | ||
@@ -1314,3 +1330,3 @@ function prepareOpenRouterPayload(payload) { | ||
| } | ||
| async function callOpenRouter(id, payload) { | ||
| async function callOpenRouter(id, payload, requestTimeoutMs = 12e4) { | ||
| var _a, _b, _c, _d, _e, _f, _g, _h; | ||
@@ -1324,3 +1340,4 @@ const response = await import_axios.default.post( | ||
| Authorization: `Bearer ${process.env.OPENROUTER_API_KEY}` | ||
| } | ||
| }, | ||
| timeout: requestTimeoutMs | ||
| } | ||
@@ -1374,4 +1391,9 @@ ); | ||
| } | ||
| async function callOpenRouterWithRetries(id, payload, retries = 5) { | ||
| return withRetries(id, "OpenRouter", () => callOpenRouter(id, payload), { retries }); | ||
| async function callOpenRouterWithRetries(id, payload, retries = 5, requestTimeoutMs = 12e4) { | ||
| return withRetries( | ||
| id, | ||
| "OpenRouter", | ||
| () => callOpenRouter(id, payload, requestTimeoutMs), | ||
| { retries } | ||
| ); | ||
| } | ||
@@ -1416,5 +1438,7 @@ var VALID_PROVIDERS = ["openai", "anthropic", "google", "groq", "openrouter"]; | ||
| async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeoutMs = 15e3) { | ||
| var _a; | ||
| try { | ||
| const { provider, modelId } = parseModelString(aiPayload.model); | ||
| const routingPayload = { ...aiPayload, model: modelId }; | ||
| const requestTimeoutMs = (_a = aiPayload.requestTimeoutMs) != null ? _a : 12e4; | ||
| switch (provider) { | ||
@@ -1426,3 +1450,4 @@ case "anthropic": | ||
| aiConfig, | ||
| retries | ||
| retries, | ||
| requestTimeoutMs | ||
| ); | ||
@@ -1435,3 +1460,4 @@ case "openai": | ||
| retries, | ||
| chunkTimeoutMs | ||
| chunkTimeoutMs, | ||
| requestTimeoutMs | ||
| ); | ||
@@ -1442,3 +1468,4 @@ case "groq": | ||
| prepareGroqPayload(routingPayload), | ||
| retries | ||
| retries, | ||
| requestTimeoutMs | ||
| ); | ||
@@ -1449,3 +1476,4 @@ case "google": | ||
| await prepareGoogleAIPayload(id, routingPayload), | ||
| retries | ||
| retries, | ||
| requestTimeoutMs | ||
| ); | ||
@@ -1456,3 +1484,4 @@ case "openrouter": | ||
| prepareOpenRouterPayload(routingPayload), | ||
| retries | ||
| retries, | ||
| requestTimeoutMs | ||
| ); | ||
@@ -1459,0 +1488,0 @@ } |
+83
-54
@@ -357,3 +357,3 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { | ||
| } | ||
| async function callOpenAIStream(id, openAiPayload, openAiConfig, chunkTimeoutMs) { | ||
| async function callOpenAIStream(id, openAiPayload, openAiConfig, chunkTimeoutMs, requestTimeoutMs = 12e4) { | ||
| var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j; | ||
@@ -367,2 +367,9 @@ const functionNames = openAiPayload.tools ? new Set(openAiPayload.tools.map((fn) => fn.function.name)) : null; | ||
| const controller = new AbortController(); | ||
| const overallTimeout = setTimeout(() => { | ||
| logger_default.error(id, `Request timeout after ${requestTimeoutMs}ms`); | ||
| controller.abort(); | ||
| }, requestTimeoutMs); | ||
| if (typeof overallTimeout === "object" && "unref" in overallTimeout) { | ||
| overallTimeout.unref(); | ||
| } | ||
| const response = await fetch(endpoint, { | ||
@@ -409,2 +416,3 @@ method: "POST", | ||
| if (jsonString.includes("[DONE]")) { | ||
| clearTimeout(overallTimeout); | ||
| return parseStreamedResponse( | ||
@@ -462,3 +470,3 @@ id, | ||
| } | ||
| async function callOpenAI(id, openAiPayload, openAiConfig) { | ||
| async function callOpenAI(id, openAiPayload, openAiConfig, requestTimeoutMs = 12e4) { | ||
| var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j; | ||
@@ -470,13 +478,21 @@ const { endpoint, headers } = buildOpenAIRequestConfig( | ||
| ); | ||
| const response = await fetch(endpoint, { | ||
| method: "POST", | ||
| headers, | ||
| body: JSON.stringify({ ...openAiPayload, stream: false }) | ||
| }); | ||
| if (!response.ok) { | ||
| const errorData = await response.json(); | ||
| logger_default.error(id, "OpenAI API error:", errorData); | ||
| throw new Error(`OpenAI API Error: ${errorData.error.message}`); | ||
| const controller = new AbortController(); | ||
| const timer = setTimeout(() => controller.abort(), requestTimeoutMs); | ||
| let data; | ||
| try { | ||
| const response = await fetch(endpoint, { | ||
| method: "POST", | ||
| headers, | ||
| body: JSON.stringify({ ...openAiPayload, stream: false }), | ||
| signal: controller.signal | ||
| }); | ||
| if (!response.ok) { | ||
| const errorData = await response.json(); | ||
| logger_default.error(id, "OpenAI API error:", errorData); | ||
| throw new Error(`OpenAI API Error: ${errorData.error.message}`); | ||
| } | ||
| data = await response.json(); | ||
| } finally { | ||
| clearTimeout(timer); | ||
| } | ||
| const data = await response.json(); | ||
| if (!((_a = data.choices) == null ? void 0 : _a.length)) { | ||
@@ -534,3 +550,3 @@ if (data.error) { | ||
| } | ||
| async function callOpenAiWithRetries(id, openAiPayload, openAiConfig, retries = 5, chunkTimeoutMs = 15e3) { | ||
| async function callOpenAiWithRetries(id, openAiPayload, openAiConfig, retries = 5, chunkTimeoutMs = 15e3, requestTimeoutMs = 12e4) { | ||
| logger_default.log( | ||
@@ -553,6 +569,7 @@ id, | ||
| openAiConfig, | ||
| chunkTimeoutMs | ||
| chunkTimeoutMs, | ||
| requestTimeoutMs | ||
| ); | ||
| } else { | ||
| return callOpenAI(id, openAiPayload, openAiConfig); | ||
| return callOpenAI(id, openAiPayload, openAiConfig, requestTimeoutMs); | ||
| } | ||
@@ -693,3 +710,3 @@ }, | ||
| } | ||
| async function callAnthropic(id, payload, config) { | ||
| async function callAnthropic(id, payload, config, requestTimeoutMs = 12e4) { | ||
| var _a, _b, _c; | ||
@@ -744,3 +761,3 @@ const anthropicMessages = jigAnthropicMessages(payload.messages); | ||
| }, | ||
| timeout: 6e4 | ||
| timeout: requestTimeoutMs | ||
| } | ||
@@ -815,7 +832,7 @@ ); | ||
| } | ||
| async function callAnthropicWithRetries(id, payload, config, retries = 5) { | ||
| async function callAnthropicWithRetries(id, payload, config, retries = 5, requestTimeoutMs = 12e4) { | ||
| return withRetries( | ||
| id, | ||
| "Anthropic", | ||
| () => callAnthropic(id, payload, config), | ||
| () => callAnthropic(id, payload, config, requestTimeoutMs), | ||
| { | ||
@@ -856,3 +873,2 @@ retries | ||
| messages: [], | ||
| requestTimeoutMs: payload.requestTimeoutMs, | ||
| tools: payload.functions ? { | ||
@@ -942,4 +958,4 @@ functionDeclarations: payload.functions.map((fn) => ({ | ||
| } | ||
| async function callGoogleAI(id, payload) { | ||
| var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s; | ||
| async function callGoogleAI(id, payload, requestTimeoutMs = 12e4) { | ||
| var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r; | ||
| const contents = jigGoogleMessages(payload.messages); | ||
@@ -967,6 +983,3 @@ const requestBody = { | ||
| }, | ||
| // Per-attempt timeout. Defaults to 60s; callers pass a larger value via | ||
| // payload.requestTimeoutMs for slow, large generations (e.g. single-file | ||
| // app codegen) so a long-but-valid response isn't cut short. | ||
| timeout: (_a = payload.requestTimeoutMs) != null ? _a : 6e4 | ||
| timeout: requestTimeoutMs | ||
| } | ||
@@ -976,10 +989,10 @@ ); | ||
| } catch (err) { | ||
| const apiError = (_c = (_b = err == null ? void 0 : err.response) == null ? void 0 : _b.data) == null ? void 0 : _c.error; | ||
| const apiError = (_b = (_a = err == null ? void 0 : err.response) == null ? void 0 : _a.data) == null ? void 0 : _b.error; | ||
| const wrapped = new Error( | ||
| (apiError == null ? void 0 : apiError.message) || (err == null ? void 0 : err.message) || "Google AI API request failed" | ||
| ); | ||
| wrapped.status = (_e = apiError == null ? void 0 : apiError.status) != null ? _e : (_d = err == null ? void 0 : err.response) == null ? void 0 : _d.status; | ||
| wrapped.status = (_d = apiError == null ? void 0 : apiError.status) != null ? _d : (_c = err == null ? void 0 : err.response) == null ? void 0 : _c.status; | ||
| wrapped.code = apiError == null ? void 0 : apiError.code; | ||
| wrapped.details = apiError == null ? void 0 : apiError.details; | ||
| wrapped.promptFeedback = (_g = (_f = err == null ? void 0 : err.response) == null ? void 0 : _f.data) == null ? void 0 : _g.promptFeedback; | ||
| wrapped.promptFeedback = (_f = (_e = err == null ? void 0 : err.response) == null ? void 0 : _e.data) == null ? void 0 : _f.promptFeedback; | ||
| throw wrapped; | ||
@@ -991,3 +1004,3 @@ } | ||
| const functionCalls = []; | ||
| for (const part of ((_j = (_i = (_h = response.candidates) == null ? void 0 : _h[0]) == null ? void 0 : _i.content) == null ? void 0 : _j.parts) || []) { | ||
| for (const part of ((_i = (_h = (_g = response.candidates) == null ? void 0 : _g[0]) == null ? void 0 : _h.content) == null ? void 0 : _i.parts) || []) { | ||
| if (part.thought) { | ||
@@ -999,5 +1012,5 @@ reasoningParts.push(part); | ||
| functionCalls.push({ | ||
| id: (_k = part.functionCall.id) != null ? _k : `call_${functionCalls.length}`, | ||
| name: (_l = part.functionCall.name) != null ? _l : "", | ||
| arguments: (_m = part.functionCall.args) != null ? _m : {}, | ||
| id: (_j = part.functionCall.id) != null ? _j : `call_${functionCalls.length}`, | ||
| name: (_k = part.functionCall.name) != null ? _k : "", | ||
| arguments: (_l = part.functionCall.args) != null ? _l : {}, | ||
| thoughtSignature: part.thoughtSignature | ||
@@ -1009,3 +1022,3 @@ }); | ||
| text += part.text; | ||
| if ((_n = part.inlineData) == null ? void 0 : _n.data) { | ||
| if ((_m = part.inlineData) == null ? void 0 : _m.data) { | ||
| files.push({ mimeType: "image/png", data: part.inlineData.data }); | ||
@@ -1015,3 +1028,3 @@ } | ||
| if (!text && !functionCalls.length && !files.length) { | ||
| const candidate = (_o = response.candidates) == null ? void 0 : _o[0]; | ||
| const candidate = (_n = response.candidates) == null ? void 0 : _n[0]; | ||
| const finishReason = candidate == null ? void 0 : candidate.finishReason; | ||
@@ -1051,6 +1064,6 @@ logger_default.error(id, "Missing text & functions in Google AI API response:", { | ||
| usage: response.usageMetadata ? { | ||
| prompt_tokens: (_p = response.usageMetadata.promptTokenCount) != null ? _p : 0, | ||
| completion_tokens: (_q = response.usageMetadata.candidatesTokenCount) != null ? _q : 0, | ||
| total_tokens: (_r = response.usageMetadata.totalTokenCount) != null ? _r : 0, | ||
| cached_tokens: (_s = response.usageMetadata.cachedContentTokenCount) != null ? _s : 0 | ||
| prompt_tokens: (_o = response.usageMetadata.promptTokenCount) != null ? _o : 0, | ||
| completion_tokens: (_p = response.usageMetadata.candidatesTokenCount) != null ? _p : 0, | ||
| total_tokens: (_q = response.usageMetadata.totalTokenCount) != null ? _q : 0, | ||
| cached_tokens: (_r = response.usageMetadata.cachedContentTokenCount) != null ? _r : 0 | ||
| } : null | ||
@@ -1076,5 +1089,5 @@ }; | ||
| } | ||
| async function callGoogleAIWithRetries(id, payload, retries = 5) { | ||
| async function callGoogleAIWithRetries(id, payload, retries = 5, requestTimeoutMs = 12e4) { | ||
| let hasTriedWithoutImages = false; | ||
| return withRetries(id, "Google AI", () => callGoogleAI(id, payload), { | ||
| return withRetries(id, "Google AI", () => callGoogleAI(id, payload, requestTimeoutMs), { | ||
| retries, | ||
@@ -1206,3 +1219,3 @@ onError: (error2, attempt) => { | ||
| } | ||
| async function callGroq(id, payload) { | ||
| async function callGroq(id, payload, requestTimeoutMs = 12e4) { | ||
| var _a, _b, _c, _d, _e, _f, _g; | ||
@@ -1216,3 +1229,4 @@ const response = await axios.post( | ||
| Authorization: `Bearer ${process.env.GROQ_API_KEY}` | ||
| } | ||
| }, | ||
| timeout: requestTimeoutMs | ||
| } | ||
@@ -1265,4 +1279,6 @@ ); | ||
| } | ||
| async function callGroqWithRetries(id, payload, retries = 5) { | ||
| return withRetries(id, "Groq", () => callGroq(id, payload), { retries }); | ||
| async function callGroqWithRetries(id, payload, retries = 5, requestTimeoutMs = 12e4) { | ||
| return withRetries(id, "Groq", () => callGroq(id, payload, requestTimeoutMs), { | ||
| retries | ||
| }); | ||
| } | ||
@@ -1283,3 +1299,3 @@ function prepareOpenRouterPayload(payload) { | ||
| } | ||
| async function callOpenRouter(id, payload) { | ||
| async function callOpenRouter(id, payload, requestTimeoutMs = 12e4) { | ||
| var _a, _b, _c, _d, _e, _f, _g, _h; | ||
@@ -1293,3 +1309,4 @@ const response = await axios.post( | ||
| Authorization: `Bearer ${process.env.OPENROUTER_API_KEY}` | ||
| } | ||
| }, | ||
| timeout: requestTimeoutMs | ||
| } | ||
@@ -1343,4 +1360,9 @@ ); | ||
| } | ||
| async function callOpenRouterWithRetries(id, payload, retries = 5) { | ||
| return withRetries(id, "OpenRouter", () => callOpenRouter(id, payload), { retries }); | ||
| async function callOpenRouterWithRetries(id, payload, retries = 5, requestTimeoutMs = 12e4) { | ||
| return withRetries( | ||
| id, | ||
| "OpenRouter", | ||
| () => callOpenRouter(id, payload, requestTimeoutMs), | ||
| { retries } | ||
| ); | ||
| } | ||
@@ -1385,5 +1407,7 @@ var VALID_PROVIDERS = ["openai", "anthropic", "google", "groq", "openrouter"]; | ||
| async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeoutMs = 15e3) { | ||
| var _a; | ||
| try { | ||
| const { provider, modelId } = parseModelString(aiPayload.model); | ||
| const routingPayload = { ...aiPayload, model: modelId }; | ||
| const requestTimeoutMs = (_a = aiPayload.requestTimeoutMs) != null ? _a : 12e4; | ||
| switch (provider) { | ||
@@ -1395,3 +1419,4 @@ case "anthropic": | ||
| aiConfig, | ||
| retries | ||
| retries, | ||
| requestTimeoutMs | ||
| ); | ||
@@ -1404,3 +1429,4 @@ case "openai": | ||
| retries, | ||
| chunkTimeoutMs | ||
| chunkTimeoutMs, | ||
| requestTimeoutMs | ||
| ); | ||
@@ -1411,3 +1437,4 @@ case "groq": | ||
| prepareGroqPayload(routingPayload), | ||
| retries | ||
| retries, | ||
| requestTimeoutMs | ||
| ); | ||
@@ -1418,3 +1445,4 @@ case "google": | ||
| await prepareGoogleAIPayload(id, routingPayload), | ||
| retries | ||
| retries, | ||
| requestTimeoutMs | ||
| ); | ||
@@ -1425,3 +1453,4 @@ case "openrouter": | ||
| prepareOpenRouterPayload(routingPayload), | ||
| retries | ||
| retries, | ||
| requestTimeoutMs | ||
| ); | ||
@@ -1428,0 +1457,0 @@ } |
+1
-1
| { | ||
| "name": "190proof", | ||
| "version": "1.0.98", | ||
| "version": "1.0.99", | ||
| "description": "", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
361619
1.86%3212
1.87%