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.mjs CHANGED
@@ -1274,8 +1274,56 @@ function prepareOpenRouterPayload(payload) {
1274
1274
  provider: payload.provider
1275
1275
  };
1276
1276
  }
1277
+ var DSML_ENVELOPE_RE = /<|+DSML|+tool_calls>/;
1278
+ var DSML_DELIMITER_RE = /<\/?|+DSML|+/;
1279
+ var DSML_INVOKE_RE = /<|+DSML|+invoke\s+name="([^"]+)"\s*>([\s\S]*?)<\/|+DSML|+invoke>/g;
1280
+ var DSML_PARAM_RE = /<|+DSML|+parameter\s+name="([^"]+)"(?:\s+string="(true|false)")?\s*>([\s\S]*?)<\/|+DSML|+parameter>/g;
1281
+ var DSML_ANY_TAG_RE = /<\/?|+DSML|+[^>]*>/g;
1282
+ function parseDsmlToolCalls(content) {
1283
+ const calls = [];
1284
+ DSML_INVOKE_RE.lastIndex = 0;
1285
+ let invokeMatch;
1286
+ while ((invokeMatch = DSML_INVOKE_RE.exec(content)) !== null) {
1287
+ const name = invokeMatch[1];
1288
+ const inner = invokeMatch[2];
1289
+ const args = {};
1290
+ let ok = true;
1291
+ DSML_PARAM_RE.lastIndex = 0;
1292
+ let paramMatch;
1293
+ while ((paramMatch = DSML_PARAM_RE.exec(inner)) !== null) {
1294
+ const [, paramName, stringAttr, rawValue] = paramMatch;
1295
+ if (stringAttr === "false") {
1296
+ try {
1297
+ args[paramName] = JSON.parse(rawValue);
1298
+ } catch (e) {
1299
+ ok = false;
1300
+ break;
1301
+ }
1302
+ } else {
1303
+ args[paramName] = rawValue;
1304
+ }
1305
+ }
1306
+ if (ok && name) {
1307
+ calls.push({ id: `call_${calls.length}`, name, arguments: args });
1308
+ }
1309
+ }
1310
+ if (!calls.length) {
1311
+ return { calls, remainingContent: content };
1312
+ }
1313
+ DSML_ANY_TAG_RE.lastIndex = 0;
1314
+ let first = -1;
1315
+ let last = -1;
1316
+ let tag;
1317
+ while ((tag = DSML_ANY_TAG_RE.exec(content)) !== null) {
1318
+ if (first === -1)
1319
+ first = tag.index;
1320
+ last = tag.index + tag[0].length;
1321
+ }
1322
+ const remaining = first === -1 ? content : (content.slice(0, first) + content.slice(last)).trim();
1323
+ return { calls, remainingContent: remaining.length ? remaining : null };
1324
+ }
1277
1325
  async function callOpenRouter(id, payload, requestTimeoutMs = 12e4) {
1278
- var _a, _b, _c, _d, _e, _f, _g, _h;
1326
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1279
1327
  const response = await axios.post(
1280
1328
  "https://openrouter.ai/api/v1/chat/completions",
1281
1329
  payload,
@@ -1307,29 +1355,38 @@ async function callOpenRouter(id, payload, requestTimeoutMs = 12e4) {
1307
1355
  });
1308
1356
  }
1309
1357
  }
1310
- if (!answer.content && !functionCalls.length) {
1358
+ let content = (_e = answer.content) != null ? _e : null;
1359
+ if (!functionCalls.length && content && DSML_ENVELOPE_RE.test(content)) {
1360
+ const { calls, remainingContent } = parseDsmlToolCalls(content);
1361
+ if (calls.length) {
1362
+ functionCalls.push(...calls);
1363
+ content = remainingContent;
1364
+ }
1365
+ }
1366
+ const hasUnparsedDsml = !!content && DSML_DELIMITER_RE.test(content);
1367
+ if (!functionCalls.length && (!content || hasUnparsedDsml)) {
1311
1368
  logger_default.error(
1312
1369
  id,
1313
- "OpenRouter: received message without content or function_call:",
1370
+ "OpenRouter: empty or unparseable completion:",
1314
1371
  JSON.stringify(response.data)
1315
1372
  );
1316
1373
  throw new Error(
1317
- "OpenRouter: received message without content or function_call"
1374
+ "OpenRouter: received message without usable content or function_call"
1318
1375
  );
1319
1376
  }
1320
1377
  return {
1321
1378
  role: "assistant",
1322
- content: answer.content || null,
1379
+ content: content || null,
1323
1380
  function_call: functionCalls[0] || null,
1324
1381
  function_calls: functionCalls,
1325
1382
  files: [],
1326
- reasoning: (_e = answer.reasoning) != null ? _e : void 0,
1327
- reasoningDetails: (_f = answer.reasoning_details) != null ? _f : void 0,
1383
+ reasoning: (_f = answer.reasoning) != null ? _f : void 0,
1384
+ reasoningDetails: (_g = answer.reasoning_details) != null ? _g : void 0,
1328
1385
  usage: response.data.usage ? {
1329
1386
  prompt_tokens: response.data.usage.prompt_tokens,
1330
1387
  completion_tokens: response.data.usage.completion_tokens,
1331
1388
  total_tokens: response.data.usage.total_tokens,
1332
- cached_tokens: (_h = (_g = response.data.usage.prompt_tokens_details) == null ? void 0 : _g.cached_tokens) != null ? _h : 0
1389
+ cached_tokens: (_i = (_h = response.data.usage.prompt_tokens_details) == null ? void 0 : _h.cached_tokens) != null ? _i : 0
1333
1390
  } : null
1334
1391
  };
1335
1392
  }