NakliTechie commited on
Commit
de40005
·
1 Parent(s): f8a3477

Sync from GitHub 2026-10-31T07:11:03Z

Browse files
Files changed (1) hide show
  1. index.html +36 -11
index.html CHANGED
@@ -63406,13 +63406,39 @@ function _adapterInferToolFromArgs(args, toolDefs) {
63406
  // — into a JS object. Strings may be single- or double-quoted; bare numbers
63407
  // and booleans/None are coerced. Splits on top-level commas only (quotes and
63408
  // nested brackets are respected so commas inside values don't split).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63409
  function _adapterParsePythonicArgs(s) {
63410
  const out = {};
63411
  if (!s || !s.trim()) return out;
63412
  const parts = [];
63413
  let depth = 0, cur = '', q = null;
63414
- for (const ch of s) {
63415
- if (q) { cur += ch; if (ch === q) q = null; continue; }
 
63416
  if (ch === '"' || ch === "'") { q = ch; cur += ch; continue; }
63417
  if (ch === '(' || ch === '[' || ch === '{') depth++;
63418
  else if (ch === ')' || ch === ']' || ch === '}') depth--;
@@ -63427,7 +63453,7 @@ function _adapterParsePythonicArgs(s) {
63427
  let v = p.slice(eq + 1).trim();
63428
  if (!k) continue;
63429
  if ((v.startsWith('"') && v.endsWith('"')) || (v.startsWith("'") && v.endsWith("'"))) {
63430
- v = v.slice(1, -1);
63431
  } else if (/^-?\d+(\.\d+)?$/.test(v)) {
63432
  v = Number(v);
63433
  } else if (v === 'true' || v === 'True') { v = true; }
@@ -63692,17 +63718,15 @@ function _adapterParseToolCalls(text, knownToolNames, toolDefs) {
63692
  // shown raw. Parse it here. Gated on the distinctive start marker AND a known
63693
  // tool name, so models that matched above never reach this and a hallucinated
63694
  // tool name (e.g. a nonexistent "translate") is ignored rather than executed.
 
63695
  if (toolCalls.length === 0 && text.indexOf('<|tool_call_start|>') !== -1) {
63696
- const seg = text.split('<|tool_call_start|>')[1] || '';
63697
- const callStr = seg.split('<|tool_call_end|>')[0];
63698
- const m = callStr.match(/([a-zA-Z_]\w*)\s*\(([\s\S]*?)\)\s*\]?\s*$/) || callStr.match(/([a-zA-Z_]\w*)\s*\(([\s\S]*)/);
63699
- if (m) {
63700
- const name = _adapterResolveToolName(m[1], knownToolNames);
63701
- if (name != null) {
63702
- toolCalls.push({ name, arguments: _adapterParsePythonicArgs(m[2]) });
63703
- cleanText = cleanText.replace(/<\|tool_call_start\|>[\s\S]*?(<\|tool_call_end\|>|$)/, '').trim();
63704
  }
63705
  }
 
63706
  }
63707
 
63708
  // 5. Native MiniCPM5-style call: <function name="fn"><param …>v</param></function>
@@ -63804,6 +63828,7 @@ export {
63804
  _adapterParseArgKeyCalls,
63805
  _adapterInferToolFromArgs,
63806
  _adapterParsePythonicArgs,
 
63807
  _adapterCoerceXmlParam,
63808
  _adapterParseXmlFunctionCalls,
63809
  _adapterExtractBalancedObject,
 
63406
  // — into a JS object. Strings may be single- or double-quoted; bare numbers
63407
  // and booleans/None are coerced. Splits on top-level commas only (quotes and
63408
  // nested brackets are respected so commas inside values don't split).
63409
+ // Split the body of a native LFM2 call block into its calls: "[a(x=1), b(y='p, q')]" → [{ name: 'a', args: 'x=1' },
63410
+ // { name: 'b', args: "y='p, q'" }]. Quote-aware (with backslash escapes) and bracket-aware; an unclosed last call keeps
63411
+ // what it has (a reply cut at max_tokens).
63412
+ function _adapterSplitPythonicCalls(s) {
63413
+ const calls = [];
63414
+ const body = String(s || '').trim().replace(/^\[/, '').replace(/\]\s*$/, '');
63415
+ let i = 0;
63416
+ while (i < body.length) {
63417
+ const head = /^[\s,]*([a-zA-Z_][\w.-]*)\s*\(/.exec(body.slice(i));
63418
+ if (!head) break;
63419
+ let j = i + head[0].length, depth = 1, q = null;
63420
+ const start = j;
63421
+ for (; j < body.length && depth > 0; j++) {
63422
+ const ch = body[j];
63423
+ if (q) { if (ch === '\\') { j++; continue; } if (ch === q) q = null; continue; }
63424
+ if (ch === '"' || ch === "'") q = ch;
63425
+ else if (ch === '(' || ch === '[' || ch === '{') depth++;
63426
+ else if (ch === ')' || ch === ']' || ch === '}') depth--;
63427
+ }
63428
+ calls.push({ name: head[1], args: body.slice(start, depth === 0 ? j - 1 : j) });
63429
+ i = j;
63430
+ }
63431
+ return calls;
63432
+ }
63433
+
63434
  function _adapterParsePythonicArgs(s) {
63435
  const out = {};
63436
  if (!s || !s.trim()) return out;
63437
  const parts = [];
63438
  let depth = 0, cur = '', q = null;
63439
+ for (let i = 0; i < s.length; i++) {
63440
+ const ch = s[i];
63441
+ if (q) { cur += ch; if (ch === '\\' && i + 1 < s.length) { cur += s[++i]; continue; } if (ch === q) q = null; continue; }
63442
  if (ch === '"' || ch === "'") { q = ch; cur += ch; continue; }
63443
  if (ch === '(' || ch === '[' || ch === '{') depth++;
63444
  else if (ch === ')' || ch === ']' || ch === '}') depth--;
 
63453
  let v = p.slice(eq + 1).trim();
63454
  if (!k) continue;
63455
  if ((v.startsWith('"') && v.endsWith('"')) || (v.startsWith("'") && v.endsWith("'"))) {
63456
+ v = v.slice(1, -1).replace(/\\(.)/g, (_, c) => (c === 'n' ? '\n' : c === 't' ? '\t' : c));
63457
  } else if (/^-?\d+(\.\d+)?$/.test(v)) {
63458
  v = Number(v);
63459
  } else if (v === 'true' || v === 'True') { v = true; }
 
63718
  // shown raw. Parse it here. Gated on the distinctive start marker AND a known
63719
  // tool name, so models that matched above never reach this and a hallucinated
63720
  // tool name (e.g. a nonexistent "translate") is ignored rather than executed.
63721
+ // Every block, and every call in a block's list ("[a(x=1), b(y=2)]", as LFM2.5-24B's Pi adapter writes them).
63722
  if (toolCalls.length === 0 && text.indexOf('<|tool_call_start|>') !== -1) {
63723
+ for (const seg of text.split('<|tool_call_start|>').slice(1)) {
63724
+ for (const c of _adapterSplitPythonicCalls(seg.split('<|tool_call_end|>')[0])) {
63725
+ const name = _adapterResolveToolName(c.name, knownToolNames);
63726
+ if (name != null) toolCalls.push({ name, arguments: _adapterParsePythonicArgs(c.args) });
 
 
 
 
63727
  }
63728
  }
63729
+ if (toolCalls.length) cleanText = cleanText.replace(/<\|tool_call_start\|>[\s\S]*?(<\|tool_call_end\|>|$)/g, '').trim();
63730
  }
63731
 
63732
  // 5. Native MiniCPM5-style call: <function name="fn"><param …>v</param></function>
 
63828
  _adapterParseArgKeyCalls,
63829
  _adapterInferToolFromArgs,
63830
  _adapterParsePythonicArgs,
63831
+ _adapterSplitPythonicCalls,
63832
  _adapterCoerceXmlParam,
63833
  _adapterParseXmlFunctionCalls,
63834
  _adapterExtractBalancedObject,