@cortexkit/magic-context 0.49.6 → 0.49.7
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 +63 -20
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12838,12 +12838,14 @@ import { statSync as statSync4 } from "node:fs";
|
|
|
12838
12838
|
function registerSlowWriteReporter(reporter) {
|
|
12839
12839
|
reportSlowPrivilegedWrite = reporter;
|
|
12840
12840
|
}
|
|
12841
|
-
function registerSqliteDiagnosticSink(sink) {
|
|
12841
|
+
function registerSqliteDiagnosticSink(sink, host) {
|
|
12842
12842
|
sqliteDiagnosticSink = sink;
|
|
12843
|
+
if (host)
|
|
12844
|
+
sqliteDiagnosticHost = host;
|
|
12843
12845
|
}
|
|
12844
12846
|
function reportSqliteDiagnostic(message) {
|
|
12845
12847
|
try {
|
|
12846
|
-
sqliteDiagnosticSink?.(`[magic-context] ${message}`);
|
|
12848
|
+
sqliteDiagnosticSink?.(`[magic-context] ${message} pid=${process.pid} host=${sqliteDiagnosticHost()}`);
|
|
12847
12849
|
} catch {}
|
|
12848
12850
|
}
|
|
12849
12851
|
function detectSqliteRuntime() {
|
|
@@ -12968,10 +12970,18 @@ function installTransactionRouting(db, readonly) {
|
|
|
12968
12970
|
assertTransformWrite();
|
|
12969
12971
|
if (/^\s*BEGIN\s+(?:IMMEDIATE|EXCLUSIVE)(?:\s+TRANSACTION)?\s*;?\s*$/i.test(sql)) {
|
|
12970
12972
|
openWriterTransactions.delete(db);
|
|
12971
|
-
if (transformPassScope.getStore()?.active || backgroundWriterScope.getStore())
|
|
12973
|
+
if (transformPassScope.getStore()?.active || backgroundWriterScope.getStore()) {
|
|
12972
12974
|
acquireShort(db, () => nativeExec(sql), sql.trim());
|
|
12973
|
-
else
|
|
12975
|
+
} else {
|
|
12974
12976
|
nativeExec(sql);
|
|
12977
|
+
openWriterTransactions.set(db, {
|
|
12978
|
+
site: sql.trim(),
|
|
12979
|
+
lane: "background",
|
|
12980
|
+
acquireMs: 0,
|
|
12981
|
+
attempts: 1,
|
|
12982
|
+
acquiredAt: performance.now()
|
|
12983
|
+
});
|
|
12984
|
+
}
|
|
12975
12985
|
return db;
|
|
12976
12986
|
}
|
|
12977
12987
|
if (WRITER_TRANSACTION_END.test(sql) && openWriterTransactions.has(db))
|
|
@@ -13342,22 +13352,30 @@ function foregroundWaitLease() {
|
|
|
13342
13352
|
function withAutocommitTimeout(db, operation) {
|
|
13343
13353
|
assertTransformWrite();
|
|
13344
13354
|
const lease = foregroundWaitLease();
|
|
13345
|
-
if (isInTransaction(db)
|
|
13355
|
+
if (isInTransaction(db))
|
|
13346
13356
|
return operation();
|
|
13347
|
-
const
|
|
13348
|
-
|
|
13357
|
+
const scoped = lease || backgroundWriterScope.getStore();
|
|
13358
|
+
const previous = scoped ? pragmaNumber(db, "busy_timeout") : null;
|
|
13359
|
+
if (scoped)
|
|
13360
|
+
db.exec(`PRAGMA busy_timeout=${lease ? Math.floor(Math.min(lease.remainingWaitMs, lease.guard?.remainingMs() ?? Infinity)) : SHORT_BUSY_TIMEOUT_MS}`);
|
|
13349
13361
|
const started = performance.now();
|
|
13362
|
+
let completed = false;
|
|
13350
13363
|
try {
|
|
13351
|
-
|
|
13364
|
+
const result = operation();
|
|
13365
|
+
completed = true;
|
|
13366
|
+
return result;
|
|
13352
13367
|
} catch (error) {
|
|
13353
13368
|
if (lease && isTransientSqliteError(error))
|
|
13354
13369
|
throw new SqliteAcquisitionBusyError(error, "autocommit");
|
|
13355
13370
|
throw error;
|
|
13356
13371
|
} finally {
|
|
13372
|
+
const elapsed = performance.now() - started;
|
|
13357
13373
|
if (lease)
|
|
13358
|
-
lease.remainingWaitMs = Math.max(0, lease.remainingWaitMs -
|
|
13374
|
+
lease.remainingWaitMs = Math.max(0, lease.remainingWaitMs - elapsed);
|
|
13359
13375
|
if (previous !== null)
|
|
13360
13376
|
db.exec(`PRAGMA busy_timeout=${previous}`);
|
|
13377
|
+
if (elapsed >= SLOW_WRITER_LOG_MS)
|
|
13378
|
+
reportSqliteDiagnostic(`sqlite writer site=autocommit lane=${lease ? "foreground" : "background"} elapsed_ms=${Math.round(elapsed)} timing=statement_including_acquisition outcome=${completed ? "completed" : "failed"} caller=${writerCaller()}`);
|
|
13361
13379
|
}
|
|
13362
13380
|
}
|
|
13363
13381
|
function acquireShort(db, acquire, site) {
|
|
@@ -13403,24 +13421,26 @@ function acquireShort(db, acquire, site) {
|
|
|
13403
13421
|
}
|
|
13404
13422
|
function endWriterTransaction(db, end, sql) {
|
|
13405
13423
|
let ended = false;
|
|
13406
|
-
const endStarted = performance.now();
|
|
13407
13424
|
try {
|
|
13408
13425
|
const result = end();
|
|
13409
13426
|
ended = true;
|
|
13410
13427
|
return result;
|
|
13411
13428
|
} finally {
|
|
13412
13429
|
const open = openWriterTransactions.get(db);
|
|
13413
|
-
const endMs = performance.now() - endStarted;
|
|
13414
13430
|
if (open && !isInTransaction(db)) {
|
|
13415
13431
|
openWriterTransactions.delete(db);
|
|
13416
13432
|
const holdMs = performance.now() - open.acquiredAt;
|
|
13417
13433
|
if (open.acquireMs >= SLOW_WRITER_LOG_MS || holdMs >= SLOW_WRITER_LOG_MS) {
|
|
13418
13434
|
const outcome = /^\s*ROLLBACK/i.test(sql) ? "rolled_back" : ended ? "committed" : "failed";
|
|
13419
|
-
reportSqliteDiagnostic(`sqlite writer site=${open.site} lane=${open.lane} acquire_ms=${Math.round(open.acquireMs)} hold_ms=${Math.round(holdMs)}
|
|
13435
|
+
reportSqliteDiagnostic(`sqlite writer site=${open.site} lane=${open.lane} acquire_ms=${Math.round(open.acquireMs)} hold_ms=${Math.round(holdMs)} attempts=${open.attempts} outcome=${outcome} timing=through_commit_upper_bound caller=${writerCaller()}`);
|
|
13420
13436
|
}
|
|
13421
13437
|
}
|
|
13422
13438
|
}
|
|
13423
13439
|
}
|
|
13440
|
+
function writerCaller() {
|
|
13441
|
+
return new Error().stack?.split(`
|
|
13442
|
+
`).find((line) => line.includes(" at ") && !/[/\\]sqlite\.[tj]s[:)]/.test(line) && !/\b(?:writerCaller|endWriterTransaction|withAutocommitTimeout|value)\b/.test(line))?.trim().replace(/\s+/g, "_") ?? "unknown";
|
|
13443
|
+
}
|
|
13424
13444
|
async function beginSqliteWriterAsync(db, site) {
|
|
13425
13445
|
const started = performance.now();
|
|
13426
13446
|
let attempts = 0;
|
|
@@ -13604,7 +13624,7 @@ async function withIndexChunk(input, operation) {
|
|
|
13604
13624
|
async function yieldIndexChunk() {
|
|
13605
13625
|
await yieldIndexTurn();
|
|
13606
13626
|
}
|
|
13607
|
-
var reportSlowPrivilegedWrite, sqliteDiagnosticSink, bunSpec, nodeSpec, SqliteRuntimeUnavailableError, detectedRuntime, isBun, sqliteModule, DatabaseImpl, trackedSqliteConnections, nextSqliteConnectionSequence = 1, TAG_COLUMNS_OUTSIDE_IDENTITY, tagIdentityWriteGeneration = 0, TrackedDatabase, Database, statementOwners, FIRST_PRUNE_AT = 256, privilegeDepth, transformPassScope, admissionScope, backgroundWriterScope, SqliteAcquisitionBusyError, SHORT_BUSY_TIMEOUT_MS = 25, FOREGROUND_IN_PASS_BUSY_TIMEOUT_MS = 2000, FOREGROUND_ACQUISITION_BUDGET_MS = 16500, SLOW_WRITER_LOG_MS =
|
|
13627
|
+
var reportSlowPrivilegedWrite, sqliteDiagnosticSink, sqliteDiagnosticHost = () => "unknown", bunSpec, nodeSpec, SqliteRuntimeUnavailableError, detectedRuntime, isBun, sqliteModule, DatabaseImpl, trackedSqliteConnections, nextSqliteConnectionSequence = 1, TAG_COLUMNS_OUTSIDE_IDENTITY, tagIdentityWriteGeneration = 0, TrackedDatabase, Database, statementOwners, FIRST_PRUNE_AT = 256, privilegeDepth, transformPassScope, admissionScope, backgroundWriterScope, SqliteAcquisitionBusyError, SHORT_BUSY_TIMEOUT_MS = 25, FOREGROUND_IN_PASS_BUSY_TIMEOUT_MS = 2000, FOREGROUND_ACQUISITION_BUDGET_MS = 16500, SLOW_WRITER_LOG_MS = 100, WRITER_TRANSACTION_END, writerAcquisitionScope, openWriterTransactions, indexCoordinationKey, indexCoordinationHeap, indexCoordinationBuffer, indexCoordinationState, yieldIndexTurn = () => new Promise((resolve) => setTimeout(resolve, 1));
|
|
13608
13628
|
var init_sqlite = __esm(async () => {
|
|
13609
13629
|
bunSpec = "bun:" + "sqlite";
|
|
13610
13630
|
nodeSpec = "node:" + "sqlite";
|
|
@@ -32644,11 +32664,13 @@ var init_storage_meta_shared = __esm(async () => {
|
|
|
32644
32664
|
});
|
|
32645
32665
|
|
|
32646
32666
|
// ../plugin/src/features/magic-context/storage-replay-document.ts
|
|
32647
|
-
|
|
32667
|
+
import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
|
|
32668
|
+
var MISSING_REPLAY_DOCUMENT_COLUMN, replaySnapshots, decisionTablePresent, trailingBlankReadCache, TRAILING_BLANK_CACHE_MAX_CHARS, DECISION_CONFLICT;
|
|
32648
32669
|
var init_storage_replay_document = __esm(async () => {
|
|
32649
32670
|
init_logger();
|
|
32650
32671
|
await init_storage_meta_shared();
|
|
32651
32672
|
MISSING_REPLAY_DOCUMENT_COLUMN = Symbol("missing replay document column");
|
|
32673
|
+
replaySnapshots = new AsyncLocalStorage2;
|
|
32652
32674
|
decisionTablePresent = new WeakMap;
|
|
32653
32675
|
trailingBlankReadCache = new WeakMap;
|
|
32654
32676
|
TRAILING_BLANK_CACHE_MAX_CHARS = 4 * 1024 * 1024;
|
|
@@ -32726,9 +32748,8 @@ var init_sentinel = __esm(() => {
|
|
|
32726
32748
|
var init_active_anthropic_turn = __esm(() => {
|
|
32727
32749
|
init_sentinel();
|
|
32728
32750
|
});
|
|
32729
|
-
|
|
32730
32751
|
// ../plugin/src/hooks/magic-context/strip-content.ts
|
|
32731
|
-
var METADATA_PART_TYPES, CLEARED_REASONING_TYPES, REASONING_IGNORED_PART_TYPES, REASONING_PART_TYPES;
|
|
32752
|
+
var METADATA_PART_TYPES, CLEARED_REASONING_TYPES, REASONING_IGNORED_PART_TYPES, REASONING_PART_TYPES, emptyImageParts;
|
|
32732
32753
|
var init_strip_content = __esm(() => {
|
|
32733
32754
|
init_merged_reasoning_decisions();
|
|
32734
32755
|
init_sentinel();
|
|
@@ -32755,6 +32776,7 @@ var init_strip_content = __esm(() => {
|
|
|
32755
32776
|
"compaction"
|
|
32756
32777
|
]);
|
|
32757
32778
|
REASONING_PART_TYPES = new Set(["reasoning", "thinking", "redacted_thinking"]);
|
|
32779
|
+
emptyImageParts = new WeakMap;
|
|
32758
32780
|
});
|
|
32759
32781
|
|
|
32760
32782
|
// ../plugin/src/hooks/magic-context/reasoning-budget.ts
|
|
@@ -32874,6 +32896,7 @@ __export(exports_read_session_chunk, {
|
|
|
32874
32896
|
setBoundedRawMessageProvider: () => setBoundedRawMessageProvider,
|
|
32875
32897
|
setRawMessageProvider: () => setRawMessageProvider,
|
|
32876
32898
|
visitRawSessionMessages: () => visitRawSessionMessages,
|
|
32899
|
+
visitRawSessionMessagesAsync: () => visitRawSessionMessagesAsync,
|
|
32877
32900
|
withRawMessageProvider: () => withRawMessageProvider,
|
|
32878
32901
|
withRawSessionMessageCache: () => withRawSessionMessageCache
|
|
32879
32902
|
});
|
|
@@ -33103,6 +33126,21 @@ function visitRawSessionMessages(sessionId, fromOrdinal, toOrdinal, visit, optio
|
|
|
33103
33126
|
after = last ? { timeCreated: last.createdAt ?? 0, id: last.id } : undefined;
|
|
33104
33127
|
}
|
|
33105
33128
|
}
|
|
33129
|
+
async function visitRawSessionMessagesAsync(sessionId, fromOrdinal, toOrdinal, visit, options = {}) {
|
|
33130
|
+
const from = Math.max(1, Math.floor(fromOrdinal));
|
|
33131
|
+
const to = Math.floor(toOrdinal);
|
|
33132
|
+
if (to < from)
|
|
33133
|
+
return;
|
|
33134
|
+
const provider = sessionProviders.get(sessionId)?.provider;
|
|
33135
|
+
if (!provider?.iterateMessageRangeAsync) {
|
|
33136
|
+
visitRawSessionMessages(sessionId, from, to, visit, options);
|
|
33137
|
+
return;
|
|
33138
|
+
}
|
|
33139
|
+
for await (const message of provider.iterateMessageRangeAsync(from, to)) {
|
|
33140
|
+
if (!visit(message))
|
|
33141
|
+
return;
|
|
33142
|
+
}
|
|
33143
|
+
}
|
|
33106
33144
|
function readRawSessionMessageRange(sessionId, fromOrdinal, toOrdinal) {
|
|
33107
33145
|
const from = Math.max(1, Math.floor(fromOrdinal));
|
|
33108
33146
|
const to = Math.floor(toOrdinal);
|
|
@@ -33522,7 +33560,10 @@ function readSessionChunk(sessionId, tokenBudget, offset = 1, eligibleEndOrdinal
|
|
|
33522
33560
|
if (state?.input === undefined && state?.output !== undefined && typeof p.callID === "string") {
|
|
33523
33561
|
const call = calls.get(p.callID);
|
|
33524
33562
|
if (call) {
|
|
33525
|
-
const expansion = expandToolPart({
|
|
33563
|
+
const expansion = expandToolPart({
|
|
33564
|
+
...call,
|
|
33565
|
+
state: { ...call.state, output: state.output }
|
|
33566
|
+
}, options.expandTools);
|
|
33526
33567
|
if (expansion !== null) {
|
|
33527
33568
|
expandedParts.set(call, expansion);
|
|
33528
33569
|
expandedResults.add(part);
|
|
@@ -35813,7 +35854,7 @@ var init_storage_db = __esm(async () => {
|
|
|
35813
35854
|
init_migrations()
|
|
35814
35855
|
]);
|
|
35815
35856
|
registerSlowWriteReporter(logSlowWriteTransaction);
|
|
35816
|
-
registerSqliteDiagnosticSink((message) => log(message));
|
|
35857
|
+
registerSqliteDiagnosticSink((message) => log(message), getHarness);
|
|
35817
35858
|
databases = new Map;
|
|
35818
35859
|
pendingAsyncOpens = new Map;
|
|
35819
35860
|
persistenceByDatabase = new WeakMap;
|
|
@@ -49362,14 +49403,16 @@ function formatSharedDbRowCounts(db) {
|
|
|
49362
49403
|
}
|
|
49363
49404
|
function findUndeclaredConfiguredVariants(configured, catalog) {
|
|
49364
49405
|
return configured.filter((entry) => {
|
|
49365
|
-
const [providerID,
|
|
49406
|
+
const [providerID, ...modelParts] = entry.model.split("/");
|
|
49407
|
+
const id = modelParts.join("/");
|
|
49366
49408
|
const model = catalog.find((item) => item.providerID === providerID && item.id === id);
|
|
49367
49409
|
return model !== undefined && !Object.hasOwn(model.variants, entry.variant);
|
|
49368
49410
|
});
|
|
49369
49411
|
}
|
|
49370
49412
|
function findUnknownConfiguredModels(configured, catalog) {
|
|
49371
49413
|
return configured.flatMap((entry) => {
|
|
49372
|
-
const [providerID,
|
|
49414
|
+
const [providerID, ...modelParts] = entry.model.split("/");
|
|
49415
|
+
const id = modelParts.join("/");
|
|
49373
49416
|
if (!catalog.some((item) => item.providerID === providerID)) {
|
|
49374
49417
|
return [{ ...entry, unknown: "provider" }];
|
|
49375
49418
|
}
|