+65
-8
@@ -1308,4 +1308,52 @@ "use strict"; | ||
| } | ||
| var DSML_ENVELOPE_RE = /<|+DSML|+tool_calls>/; | ||
| var DSML_DELIMITER_RE = /<\/?|+DSML|+/; | ||
| var DSML_INVOKE_RE = /<|+DSML|+invoke\s+name="([^"]+)"\s*>([\s\S]*?)<\/|+DSML|+invoke>/g; | ||
| var DSML_PARAM_RE = /<|+DSML|+parameter\s+name="([^"]+)"(?:\s+string="(true|false)")?\s*>([\s\S]*?)<\/|+DSML|+parameter>/g; | ||
| var DSML_ANY_TAG_RE = /<\/?|+DSML|+[^>]*>/g; | ||
| function parseDsmlToolCalls(content) { | ||
| const calls = []; | ||
| DSML_INVOKE_RE.lastIndex = 0; | ||
| let invokeMatch; | ||
| while ((invokeMatch = DSML_INVOKE_RE.exec(content)) !== null) { | ||
| const name = invokeMatch[1]; | ||
| const inner = invokeMatch[2]; | ||
| const args = {}; | ||
| let ok = true; | ||
| DSML_PARAM_RE.lastIndex = 0; | ||
| let paramMatch; | ||
| while ((paramMatch = DSML_PARAM_RE.exec(inner)) !== null) { | ||
| const [, paramName, stringAttr, rawValue] = paramMatch; | ||
| if (stringAttr === "false") { | ||
| try { | ||
| args[paramName] = JSON.parse(rawValue); | ||
| } catch (e) { | ||
| ok = false; | ||
| break; | ||
| } | ||
| } else { | ||
| args[paramName] = rawValue; | ||
| } | ||
| } | ||
| if (ok && name) { | ||
| calls.push({ id: `call_${calls.length}`, name, arguments: args }); | ||
| } | ||
| } | ||
| if (!calls.length) { | ||
| return { calls, remainingContent: content }; | ||
| } | ||
| DSML_ANY_TAG_RE.lastIndex = 0; | ||
| let first = -1; | ||
| let last = -1; | ||
| let tag; | ||
| while ((tag = DSML_ANY_TAG_RE.exec(content)) !== null) { | ||
| if (first === -1) | ||
| first = tag.index; | ||
| last = tag.index + tag[0].length; | ||
| } | ||
| const remaining = first === -1 ? content : (content.slice(0, first) + content.slice(last)).trim(); | ||
| return { calls, remainingContent: remaining.length ? remaining : null }; | ||
| } | ||
| async function callOpenRouter(id, payload, requestTimeoutMs = 12e4) { | ||
| var _a, _b, _c, _d, _e, _f, _g, _h; | ||
| var _a, _b, _c, _d, _e, _f, _g, _h, _i; | ||
| const response = await import_axios.default.post( | ||
@@ -1342,10 +1390,19 @@ "https://openrouter.ai/api/v1/chat/completions", | ||
| } | ||
| if (!answer.content && !functionCalls.length) { | ||
| let content = (_e = answer.content) != null ? _e : null; | ||
| if (!functionCalls.length && content && DSML_ENVELOPE_RE.test(content)) { | ||
| const { calls, remainingContent } = parseDsmlToolCalls(content); | ||
| if (calls.length) { | ||
| functionCalls.push(...calls); | ||
| content = remainingContent; | ||
| } | ||
| } | ||
| const hasUnparsedDsml = !!content && DSML_DELIMITER_RE.test(content); | ||
| if (!functionCalls.length && (!content || hasUnparsedDsml)) { | ||
| logger_default.error( | ||
| id, | ||
| "OpenRouter: received message without content or function_call:", | ||
| "OpenRouter: empty or unparseable completion:", | ||
| JSON.stringify(response.data) | ||
| ); | ||
| throw new Error( | ||
| "OpenRouter: received message without content or function_call" | ||
| "OpenRouter: received message without usable content or function_call" | ||
| ); | ||
@@ -1355,8 +1412,8 @@ } | ||
| role: "assistant", | ||
| content: answer.content || null, | ||
| content: content || null, | ||
| function_call: functionCalls[0] || null, | ||
| function_calls: functionCalls, | ||
| files: [], | ||
| reasoning: (_e = answer.reasoning) != null ? _e : void 0, | ||
| reasoningDetails: (_f = answer.reasoning_details) != null ? _f : void 0, | ||
| reasoning: (_f = answer.reasoning) != null ? _f : void 0, | ||
| reasoningDetails: (_g = answer.reasoning_details) != null ? _g : void 0, | ||
| usage: response.data.usage ? { | ||
@@ -1366,3 +1423,3 @@ prompt_tokens: response.data.usage.prompt_tokens, | ||
| total_tokens: response.data.usage.total_tokens, | ||
| cached_tokens: (_h = (_g = response.data.usage.prompt_tokens_details) == null ? void 0 : _g.cached_tokens) != null ? _h : 0 | ||
| cached_tokens: (_i = (_h = response.data.usage.prompt_tokens_details) == null ? void 0 : _h.cached_tokens) != null ? _i : 0 | ||
| } : null | ||
@@ -1369,0 +1426,0 @@ }; |
+65
-8
@@ -1277,4 +1277,52 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { | ||
| } | ||
| var DSML_ENVELOPE_RE = /<|+DSML|+tool_calls>/; | ||
| var DSML_DELIMITER_RE = /<\/?|+DSML|+/; | ||
| var DSML_INVOKE_RE = /<|+DSML|+invoke\s+name="([^"]+)"\s*>([\s\S]*?)<\/|+DSML|+invoke>/g; | ||
| var DSML_PARAM_RE = /<|+DSML|+parameter\s+name="([^"]+)"(?:\s+string="(true|false)")?\s*>([\s\S]*?)<\/|+DSML|+parameter>/g; | ||
| var DSML_ANY_TAG_RE = /<\/?|+DSML|+[^>]*>/g; | ||
| function parseDsmlToolCalls(content) { | ||
| const calls = []; | ||
| DSML_INVOKE_RE.lastIndex = 0; | ||
| let invokeMatch; | ||
| while ((invokeMatch = DSML_INVOKE_RE.exec(content)) !== null) { | ||
| const name = invokeMatch[1]; | ||
| const inner = invokeMatch[2]; | ||
| const args = {}; | ||
| let ok = true; | ||
| DSML_PARAM_RE.lastIndex = 0; | ||
| let paramMatch; | ||
| while ((paramMatch = DSML_PARAM_RE.exec(inner)) !== null) { | ||
| const [, paramName, stringAttr, rawValue] = paramMatch; | ||
| if (stringAttr === "false") { | ||
| try { | ||
| args[paramName] = JSON.parse(rawValue); | ||
| } catch (e) { | ||
| ok = false; | ||
| break; | ||
| } | ||
| } else { | ||
| args[paramName] = rawValue; | ||
| } | ||
| } | ||
| if (ok && name) { | ||
| calls.push({ id: `call_${calls.length}`, name, arguments: args }); | ||
| } | ||
| } | ||
| if (!calls.length) { | ||
| return { calls, remainingContent: content }; | ||
| } | ||
| DSML_ANY_TAG_RE.lastIndex = 0; | ||
| let first = -1; | ||
| let last = -1; | ||
| let tag; | ||
| while ((tag = DSML_ANY_TAG_RE.exec(content)) !== null) { | ||
| if (first === -1) | ||
| first = tag.index; | ||
| last = tag.index + tag[0].length; | ||
| } | ||
| const remaining = first === -1 ? content : (content.slice(0, first) + content.slice(last)).trim(); | ||
| return { calls, remainingContent: remaining.length ? remaining : null }; | ||
| } | ||
| async function callOpenRouter(id, payload, requestTimeoutMs = 12e4) { | ||
| var _a, _b, _c, _d, _e, _f, _g, _h; | ||
| var _a, _b, _c, _d, _e, _f, _g, _h, _i; | ||
| const response = await axios.post( | ||
@@ -1311,10 +1359,19 @@ "https://openrouter.ai/api/v1/chat/completions", | ||
| } | ||
| if (!answer.content && !functionCalls.length) { | ||
| let content = (_e = answer.content) != null ? _e : null; | ||
| if (!functionCalls.length && content && DSML_ENVELOPE_RE.test(content)) { | ||
| const { calls, remainingContent } = parseDsmlToolCalls(content); | ||
| if (calls.length) { | ||
| functionCalls.push(...calls); | ||
| content = remainingContent; | ||
| } | ||
| } | ||
| const hasUnparsedDsml = !!content && DSML_DELIMITER_RE.test(content); | ||
| if (!functionCalls.length && (!content || hasUnparsedDsml)) { | ||
| logger_default.error( | ||
| id, | ||
| "OpenRouter: received message without content or function_call:", | ||
| "OpenRouter: empty or unparseable completion:", | ||
| JSON.stringify(response.data) | ||
| ); | ||
| throw new Error( | ||
| "OpenRouter: received message without content or function_call" | ||
| "OpenRouter: received message without usable content or function_call" | ||
| ); | ||
@@ -1324,8 +1381,8 @@ } | ||
| role: "assistant", | ||
| content: answer.content || null, | ||
| content: content || null, | ||
| function_call: functionCalls[0] || null, | ||
| function_calls: functionCalls, | ||
| files: [], | ||
| reasoning: (_e = answer.reasoning) != null ? _e : void 0, | ||
| reasoningDetails: (_f = answer.reasoning_details) != null ? _f : void 0, | ||
| reasoning: (_f = answer.reasoning) != null ? _f : void 0, | ||
| reasoningDetails: (_g = answer.reasoning_details) != null ? _g : void 0, | ||
| usage: response.data.usage ? { | ||
@@ -1335,3 +1392,3 @@ prompt_tokens: response.data.usage.prompt_tokens, | ||
| total_tokens: response.data.usage.total_tokens, | ||
| cached_tokens: (_h = (_g = response.data.usage.prompt_tokens_details) == null ? void 0 : _g.cached_tokens) != null ? _h : 0 | ||
| cached_tokens: (_i = (_h = response.data.usage.prompt_tokens_details) == null ? void 0 : _h.cached_tokens) != null ? _i : 0 | ||
| } : null | ||
@@ -1338,0 +1395,0 @@ }; |
+1
-1
| { | ||
| "name": "190proof", | ||
| "version": "1.0.100", | ||
| "version": "1.0.101", | ||
| "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
379216
4.37%3328
3.55%