190proof 1.0.100 → 1.0.101
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/dist/index.js +65 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1305,8 +1305,56 @@ function prepareOpenRouterPayload(payload) {
|
|
|
1305
1305
|
provider: payload.provider
|
|
1306
1306
|
};
|
|
1307
1307
|
}
|
|
1308
|
+
var DSML_ENVELOPE_RE = /<|+DSML|+tool_calls>/;
|
|
1309
|
+
var DSML_DELIMITER_RE = /<\/?|+DSML|+/;
|
|
1310
|
+
var DSML_INVOKE_RE = /<|+DSML|+invoke\s+name="([^"]+)"\s*>([\s\S]*?)<\/|+DSML|+invoke>/g;
|
|
1311
|
+
var DSML_PARAM_RE = /<|+DSML|+parameter\s+name="([^"]+)"(?:\s+string="(true|false)")?\s*>([\s\S]*?)<\/|+DSML|+parameter>/g;
|
|
1312
|
+
var DSML_ANY_TAG_RE = /<\/?|+DSML|+[^>]*>/g;
|
|
1313
|
+
function parseDsmlToolCalls(content) {
|
|
1314
|
+
const calls = [];
|
|
1315
|
+
DSML_INVOKE_RE.lastIndex = 0;
|
|
1316
|
+
let invokeMatch;
|
|
1317
|
+
while ((invokeMatch = DSML_INVOKE_RE.exec(content)) !== null) {
|
|
1318
|
+
const name = invokeMatch[1];
|
|
1319
|
+
const inner = invokeMatch[2];
|
|
1320
|
+
const args = {};
|
|
1321
|
+
let ok = true;
|
|
1322
|
+
DSML_PARAM_RE.lastIndex = 0;
|
|
1323
|
+
let paramMatch;
|
|
1324
|
+
while ((paramMatch = DSML_PARAM_RE.exec(inner)) !== null) {
|
|
1325
|
+
const [, paramName, stringAttr, rawValue] = paramMatch;
|
|
1326
|
+
if (stringAttr === "false") {
|
|
1327
|
+
try {
|
|
1328
|
+
args[paramName] = JSON.parse(rawValue);
|
|
1329
|
+
} catch (e) {
|
|
1330
|
+
ok = false;
|
|
1331
|
+
break;
|
|
1332
|
+
}
|
|
1333
|
+
} else {
|
|
1334
|
+
args[paramName] = rawValue;
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
if (ok && name) {
|
|
1338
|
+
calls.push({ id: `call_${calls.length}`, name, arguments: args });
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
if (!calls.length) {
|
|
1342
|
+
return { calls, remainingContent: content };
|
|
1343
|
+
}
|
|
1344
|
+
DSML_ANY_TAG_RE.lastIndex = 0;
|
|
1345
|
+
let first = -1;
|
|
1346
|
+
let last = -1;
|
|
1347
|
+
let tag;
|
|
1348
|
+
while ((tag = DSML_ANY_TAG_RE.exec(content)) !== null) {
|
|
1349
|
+
if (first === -1)
|
|
1350
|
+
first = tag.index;
|
|
1351
|
+
last = tag.index + tag[0].length;
|
|
1352
|
+
}
|
|
1353
|
+
const remaining = first === -1 ? content : (content.slice(0, first) + content.slice(last)).trim();
|
|
1354
|
+
return { calls, remainingContent: remaining.length ? remaining : null };
|
|
1355
|
+
}
|
|
1308
1356
|
async function callOpenRouter(id, payload, requestTimeoutMs = 12e4) {
|
|
1309
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1357
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1310
1358
|
const response = await import_axios.default.post(
|
|
1311
1359
|
"https://openrouter.ai/api/v1/chat/completions",
|
|
1312
1360
|
payload,
|
|
@@ -1338,29 +1386,38 @@ async function callOpenRouter(id, payload, requestTimeoutMs = 12e4) {
|
|
|
1338
1386
|
});
|
|
1339
1387
|
}
|
|
1340
1388
|
}
|
|
1341
|
-
|
|
1389
|
+
let content = (_e = answer.content) != null ? _e : null;
|
|
1390
|
+
if (!functionCalls.length && content && DSML_ENVELOPE_RE.test(content)) {
|
|
1391
|
+
const { calls, remainingContent } = parseDsmlToolCalls(content);
|
|
1392
|
+
if (calls.length) {
|
|
1393
|
+
functionCalls.push(...calls);
|
|
1394
|
+
content = remainingContent;
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
const hasUnparsedDsml = !!content && DSML_DELIMITER_RE.test(content);
|
|
1398
|
+
if (!functionCalls.length && (!content || hasUnparsedDsml)) {
|
|
1342
1399
|
logger_default.error(
|
|
1343
1400
|
id,
|
|
1344
|
-
"OpenRouter:
|
|
1401
|
+
"OpenRouter: empty or unparseable completion:",
|
|
1345
1402
|
JSON.stringify(response.data)
|
|
1346
1403
|
);
|
|
1347
1404
|
throw new Error(
|
|
1348
|
-
"OpenRouter: received message without content or function_call"
|
|
1405
|
+
"OpenRouter: received message without usable content or function_call"
|
|
1349
1406
|
);
|
|
1350
1407
|
}
|
|
1351
1408
|
return {
|
|
1352
1409
|
role: "assistant",
|
|
1353
|
-
content:
|
|
1410
|
+
content: content || null,
|
|
1354
1411
|
function_call: functionCalls[0] || null,
|
|
1355
1412
|
function_calls: functionCalls,
|
|
1356
1413
|
files: [],
|
|
1357
|
-
reasoning: (
|
|
1358
|
-
reasoningDetails: (
|
|
1414
|
+
reasoning: (_f = answer.reasoning) != null ? _f : void 0,
|
|
1415
|
+
reasoningDetails: (_g = answer.reasoning_details) != null ? _g : void 0,
|
|
1359
1416
|
usage: response.data.usage ? {
|
|
1360
1417
|
prompt_tokens: response.data.usage.prompt_tokens,
|
|
1361
1418
|
completion_tokens: response.data.usage.completion_tokens,
|
|
1362
1419
|
total_tokens: response.data.usage.total_tokens,
|
|
1363
|
-
cached_tokens: (
|
|
1420
|
+
cached_tokens: (_i = (_h = response.data.usage.prompt_tokens_details) == null ? void 0 : _h.cached_tokens) != null ? _i : 0
|
|
1364
1421
|
} : null
|
|
1365
1422
|
};
|
|
1366
1423
|
}
|