@cortexkit/magic-context 0.49.25 → 0.49.26
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 +57 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -27289,6 +27289,9 @@ function readStoreStamp(db) {
|
|
|
27289
27289
|
function sameStoreStamp(left, right) {
|
|
27290
27290
|
return left !== null && right !== null && left.dataVersion === right.dataVersion && left.totalChanges === right.totalChanges && left.schemaVersion === right.schemaVersion;
|
|
27291
27291
|
}
|
|
27292
|
+
function forgetRawSessionOrdinalWatermark(sessionId) {
|
|
27293
|
+
ordinalWatermarkEpochs.set(sessionId, (ordinalWatermarkEpochs.get(sessionId) ?? 0) + 1);
|
|
27294
|
+
}
|
|
27292
27295
|
function compareOrdinalKeys(left, right) {
|
|
27293
27296
|
if (left.timeCreated !== right.timeCreated)
|
|
27294
27297
|
return left.timeCreated < right.timeCreated ? -1 : 1;
|
|
@@ -27306,12 +27309,31 @@ function countEligibleOrdinals(db, sessionId, after, through) {
|
|
|
27306
27309
|
ordinalJsonRowsRead += visited;
|
|
27307
27310
|
return typeof row?.eligible === "number" ? row.eligible : 0;
|
|
27308
27311
|
}
|
|
27312
|
+
function forgetRawSessionSummaryRows(sessionId) {
|
|
27313
|
+
summaryCandidateEpochs.set(sessionId, (summaryCandidateEpochs.get(sessionId) ?? 0) + 1);
|
|
27314
|
+
writtenSummaryIds.delete(sessionId);
|
|
27315
|
+
forgetRawSessionOrdinalWatermark(sessionId);
|
|
27316
|
+
}
|
|
27309
27317
|
function survivingAnchor(db, set) {
|
|
27310
27318
|
if (set.anchors.length === 0)
|
|
27311
27319
|
return null;
|
|
27312
27320
|
const current = new Map(db.prepare(ANCHOR_CHECK_SQL).all(JSON.stringify(set.anchors.map((anchor) => anchor.rowid))).map((row) => [row.rid, row.id]));
|
|
27313
27321
|
return set.anchors.find((anchor) => current.get(anchor.rowid) === anchor.id);
|
|
27314
27322
|
}
|
|
27323
|
+
function hasLateCommitBehindCheckpoint(db, sessionId, scan) {
|
|
27324
|
+
const tail = scan.checkpoints?.at(-1);
|
|
27325
|
+
if (!tail || scan.maxRowid === undefined)
|
|
27326
|
+
return false;
|
|
27327
|
+
const row = db.prepare(`SELECT COUNT(*) AS count FROM message
|
|
27328
|
+
WHERE rowid > ? AND +session_id = ?
|
|
27329
|
+
AND (time_created, id) <= (?, ?)
|
|
27330
|
+
AND NOT (${EXCLUDED_ROW_SQL})`).get(scan.maxRowid, sessionId, tail.timeCreated, tail.id);
|
|
27331
|
+
return typeof row?.count === "number" && row.count > 0;
|
|
27332
|
+
}
|
|
27333
|
+
function discardRetainedOrdinalRanks(db, sessionId) {
|
|
27334
|
+
ordinalCheckpoints.get(db)?.delete(sessionId);
|
|
27335
|
+
ordinalSummarySeeds.get(db)?.delete(sessionId);
|
|
27336
|
+
}
|
|
27315
27337
|
function currentOrdinalCheckpoints(db, sessionId) {
|
|
27316
27338
|
const cached = ordinalCheckpoints.get(db)?.get(sessionId);
|
|
27317
27339
|
if (!cached)
|
|
@@ -27341,10 +27363,16 @@ function extendOrdinalCheckpoints(db, sessionId, scan, limit) {
|
|
|
27341
27363
|
scan.sessionRows = points.at(-1)?.storedCount ?? 0;
|
|
27342
27364
|
}
|
|
27343
27365
|
const tail = points.at(-1);
|
|
27344
|
-
const rows = db.prepare(`SELECT id, time_created AS timeCreated, ${EXCLUDED_ROW_SQL} AS excluded FROM message
|
|
27366
|
+
const rows = db.prepare(`SELECT id, time_created AS timeCreated, rowid AS rowid, ${EXCLUDED_ROW_SQL} AS excluded FROM message
|
|
27345
27367
|
WHERE session_id=?${tail ? " AND (time_created,id) > (?,?)" : ""}
|
|
27346
27368
|
ORDER BY time_created,id${limit === undefined ? "" : ` LIMIT ${limit + 1}`}`).all(sessionId, ...tail ? [tail.timeCreated, tail.id] : []);
|
|
27347
27369
|
ordinalJsonRowsRead += rows.length;
|
|
27370
|
+
if (hasLateCommitBehindCheckpoint(db, sessionId, scan)) {
|
|
27371
|
+
discardRetainedOrdinalRanks(db, sessionId);
|
|
27372
|
+
if (isMainThread)
|
|
27373
|
+
forgetRawSessionSummaryRows(sessionId);
|
|
27374
|
+
return false;
|
|
27375
|
+
}
|
|
27348
27376
|
if (limit !== undefined && rows.length > limit)
|
|
27349
27377
|
return false;
|
|
27350
27378
|
let total = scan.total ?? 0;
|
|
@@ -27361,6 +27389,13 @@ function extendOrdinalCheckpoints(db, sessionId, scan, limit) {
|
|
|
27361
27389
|
scan.checkpoints = points;
|
|
27362
27390
|
scan.sessionRows += rows.length;
|
|
27363
27391
|
scan.total = total;
|
|
27392
|
+
if (rows.length > 0) {
|
|
27393
|
+
let maxRowid = scan.maxRowid ?? -1;
|
|
27394
|
+
for (const row of rows)
|
|
27395
|
+
if (row.rowid > maxRowid)
|
|
27396
|
+
maxRowid = row.rowid;
|
|
27397
|
+
scan.maxRowid = maxRowid;
|
|
27398
|
+
}
|
|
27364
27399
|
return true;
|
|
27365
27400
|
}
|
|
27366
27401
|
function rawOrdinalSummarySeed(db, sessionId) {
|
|
@@ -27413,8 +27448,7 @@ function boundedOrdinalPrefix(db, sessionId, through) {
|
|
|
27413
27448
|
}
|
|
27414
27449
|
function scanRawSessionSummaryRows(db, sessionId, previous) {
|
|
27415
27450
|
return withReadSnapshot(db, () => {
|
|
27416
|
-
if (previous?.checkpoints) {
|
|
27417
|
-
extendOrdinalCheckpoints(db, sessionId, previous);
|
|
27451
|
+
if (previous?.checkpoints && extendOrdinalCheckpoints(db, sessionId, previous)) {
|
|
27418
27452
|
return previous;
|
|
27419
27453
|
}
|
|
27420
27454
|
if (previous) {
|
|
@@ -27446,12 +27480,15 @@ function scanRawSessionSummaryRows(db, sessionId, previous) {
|
|
|
27446
27480
|
}
|
|
27447
27481
|
anchors.sort((left, right) => right.rowid - left.rowid);
|
|
27448
27482
|
anchors.length = Math.min(anchors.length, SUMMARY_ANCHOR_LIMIT);
|
|
27449
|
-
const keys = db.prepare(`SELECT id, time_created AS timeCreated, ${EXCLUDED_ROW_SQL} AS excluded FROM message WHERE session_id = ?
|
|
27483
|
+
const keys = db.prepare(`SELECT id, time_created AS timeCreated, rowid AS rowid, ${EXCLUDED_ROW_SQL} AS excluded FROM message WHERE session_id = ?
|
|
27450
27484
|
ORDER BY time_created, id`).all(sessionId);
|
|
27451
27485
|
const checkpoints = [];
|
|
27452
27486
|
let total = 0;
|
|
27487
|
+
let maxRowid;
|
|
27453
27488
|
for (let index = 0;index < keys.length; index++) {
|
|
27454
27489
|
const key = keys[index];
|
|
27490
|
+
if (typeof key.rowid === "number")
|
|
27491
|
+
maxRowid = maxRowid === undefined ? key.rowid : Math.max(maxRowid, key.rowid);
|
|
27455
27492
|
if (key.excluded !== 1)
|
|
27456
27493
|
total++;
|
|
27457
27494
|
if (index % 256 === 255 || index === keys.length - 1)
|
|
@@ -27462,7 +27499,7 @@ function scanRawSessionSummaryRows(db, sessionId, previous) {
|
|
|
27462
27499
|
storedCount: index + 1
|
|
27463
27500
|
});
|
|
27464
27501
|
}
|
|
27465
|
-
return { anchors, ids, sessionRows, checkpoints, total };
|
|
27502
|
+
return { anchors, ids, sessionRows, checkpoints, total, maxRowid };
|
|
27466
27503
|
});
|
|
27467
27504
|
}
|
|
27468
27505
|
function getRawSessionSummaryEpoch(sessionId) {
|
|
@@ -35081,6 +35118,7 @@ __export(exports_read_session_chunk, {
|
|
|
35081
35118
|
readRawSessionMessages: () => readRawSessionMessages,
|
|
35082
35119
|
readRawSessionSeedTail: () => readRawSessionSeedTail,
|
|
35083
35120
|
readSessionChunk: () => readSessionChunk,
|
|
35121
|
+
resolveHistorianChunkStart: () => resolveHistorianChunkStart,
|
|
35084
35122
|
resolveHostServedBoundaryId: () => resolveHostServedBoundaryId,
|
|
35085
35123
|
setBoundedRawMessageProvider: () => setBoundedRawMessageProvider,
|
|
35086
35124
|
setRawMessageProvider: () => setRawMessageProvider,
|
|
@@ -35553,6 +35591,20 @@ function readRawSessionMessageOrdinalById(sessionId, messageId) {
|
|
|
35553
35591
|
return null;
|
|
35554
35592
|
return withReadOnlySessionDb((db) => readRawSessionMessageOrdinalByIdFromDb(db, sessionId, messageId));
|
|
35555
35593
|
}
|
|
35594
|
+
function resolveHistorianChunkStart(sessionId, newest) {
|
|
35595
|
+
if (!newest)
|
|
35596
|
+
return 1;
|
|
35597
|
+
const fallback = newest.endMessage + 1;
|
|
35598
|
+
if (hasRawMessageProvider(sessionId))
|
|
35599
|
+
return fallback;
|
|
35600
|
+
const endId = newest.endMessageId;
|
|
35601
|
+
if (typeof endId !== "string" || endId.length === 0)
|
|
35602
|
+
return fallback;
|
|
35603
|
+
const ordinal = readRawSessionMessageOrdinalById(sessionId, endId);
|
|
35604
|
+
if (typeof ordinal !== "number" || !Number.isFinite(ordinal) || ordinal < 1)
|
|
35605
|
+
return fallback;
|
|
35606
|
+
return ordinal + 1;
|
|
35607
|
+
}
|
|
35556
35608
|
function readRawSessionMessageOrderPosition(sessionId, messageId) {
|
|
35557
35609
|
const provider = sessionProviders.get(sessionId)?.provider;
|
|
35558
35610
|
if (provider) {
|