@ai-matrx/content-ir 0.18.5 → 0.18.6

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/source.cjs CHANGED
@@ -1241,10 +1241,13 @@ var Tokenizer = class {
1241
1241
  /**
1242
1242
  * Streaming: an open block that may still turn back into prose — a `$$`
1243
1243
  * pair whose closer is on the open last line (prose after it makes it
1244
- * inline), or a JSON head whose braces have not balanced (it may never parse).
1244
+ * inline), a JSON head whose braces have not balanced (it may never parse),
1245
+ * or any opener that is itself still arriving on the open last line.
1245
1246
  */
1246
1247
  mayDissolve(block) {
1247
- return this.streaming && !block.complete && (block.type === "math_block" || block.type === "json");
1248
+ if (!this.streaming || block.complete) return false;
1249
+ if (block.type === "math_block" || block.type === "json") return true;
1250
+ return this.isOpenTail(this.lineOf(block.start));
1248
1251
  }
1249
1252
  /** Streaming: paragraph ends where an undecided, dissolvable block cut them short. */
1250
1253
  undecidedBreaks = /* @__PURE__ */ new Set();
@@ -1265,6 +1268,12 @@ var Tokenizer = class {
1265
1268
  }
1266
1269
  return lo;
1267
1270
  }
1271
+ /** How many whitespace characters open the text at `from` (up to `to`). */
1272
+ leadingSpace(from, to) {
1273
+ let k = from;
1274
+ while (k < to && /\s/.test(this.text[k])) k++;
1275
+ return k - from;
1276
+ }
1268
1277
  isBlank(from, to) {
1269
1278
  return !NOT_WHITESPACE.test(this.text.slice(from, to));
1270
1279
  }
@@ -1289,6 +1298,10 @@ var Tokenizer = class {
1289
1298
  break;
1290
1299
  }
1291
1300
  const island = this.detectBlock(pos, li, true);
1301
+ if (island && pos + this.leadingSpace(pos, this.contentEnds[li]) >= this.provisionalFrom) {
1302
+ this.push({ kind: "prose", start: pos, end: this.n, island: null, inlines: [] });
1303
+ break;
1304
+ }
1292
1305
  if (island) {
1293
1306
  this.push({ kind: "island", start: island.start, end: island.end, island, inlines: [] });
1294
1307
  pos = island.end;
@@ -1349,36 +1362,55 @@ var Tokenizer = class {
1349
1362
  * region…) is never a tree line nor a root label, so it stops the walk.
1350
1363
  */
1351
1364
  treeRootHoldFrom() {
1352
- const claimable = (k2) => {
1365
+ const claimFrom = (k2) => {
1366
+ const lineStart = this.lineStarts[k2];
1367
+ const lineEnd = this.contentEnds[k2];
1368
+ let pos = lineStart;
1353
1369
  for (; ; ) {
1354
- const block = this.blockAt(this.lineStarts[k2]);
1355
- if (!block || block.kind !== "island" || block.island?.fromParagraph === true) return true;
1356
- const opened = this.lineOf(block.start);
1357
- if (this.lineStarts[opened] === block.start || opened === k2) return false;
1358
- k2 = opened;
1370
+ const block = this.blockAt(pos);
1371
+ if (!block || block.kind !== "island" || !block.island) return pos;
1372
+ if (block.island.fromParagraph === true || this.mayDissolve(block.island)) return pos;
1373
+ if (block.start < lineStart) {
1374
+ const opened = this.lineOf(block.start);
1375
+ if (this.lineStarts[opened] !== block.start && claimFrom(opened) !== -1) return pos;
1376
+ if (block.end >= lineEnd) return -1;
1377
+ pos = block.end;
1378
+ continue;
1379
+ }
1380
+ if (block.end >= lineEnd) return -1;
1381
+ pos = block.end;
1359
1382
  }
1360
1383
  };
1361
1384
  let k = this.lineCount - 1;
1362
1385
  let start = this.lineCount;
1386
+ let startPos = this.n;
1363
1387
  if (k >= 0 && this.isOpenTail(k)) {
1364
- if (!claimable(k)) return this.n;
1388
+ const at = claimFrom(k);
1389
+ if (at === -1) return this.n;
1365
1390
  start = k;
1391
+ startPos = at;
1366
1392
  k--;
1367
1393
  }
1368
- for (; k >= 0 && claimable(k); k--) {
1394
+ for (; k >= 0; k--) {
1369
1395
  this.tick(1);
1396
+ const at = claimFrom(k);
1397
+ if (at === -1) break;
1370
1398
  if (this.lineIsBlank(k)) continue;
1371
1399
  if (!TREE_GLYPHS.test(this.lineText(k))) break;
1372
1400
  start = k;
1401
+ startPos = at;
1373
1402
  }
1374
- let root = start;
1375
- for (let j = start - 1; j >= 0 && claimable(j); j--) {
1403
+ let rootPos = startPos;
1404
+ for (let j = start - 1; j >= 0; j--) {
1405
+ const at = claimFrom(j);
1406
+ if (at === -1) break;
1376
1407
  const trimmed = this.lineText(j).trim();
1377
1408
  this.tick(trimmed.length + 1);
1378
1409
  if (!trimmed || isSplitterTreeLine(trimmed) || /^#{1,6}\s/.test(trimmed)) break;
1379
- root = j;
1410
+ rootPos = at;
1411
+ if (at > this.lineStarts[j]) break;
1380
1412
  }
1381
- return root < this.lineCount ? this.lineStarts[root] : this.n;
1413
+ return rootPos;
1382
1414
  }
1383
1415
  /** The block (so far) containing offset `pos`, or null. */
1384
1416
  blockAt(pos) {
@@ -2148,6 +2180,10 @@ var Tokenizer = class {
2148
2180
  const closer = `</${name}>`;
2149
2181
  const close = this.next(closer, tagEnd);
2150
2182
  const blockType = isAttr ? "xml_attr" : "xml_region";
2183
+ if (close === -1 && isThinking && !this.streaming) {
2184
+ i = tagEnd;
2185
+ continue;
2186
+ }
2151
2187
  if (close === -1) return stop(this.island(blockType, i, this.n, false, { tag: name }));
2152
2188
  const end = close + closer.length;
2153
2189
  if (end > pe) return stop(this.spill(blockType, i, end, pe, { tag: name }));