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