@retaw106/mmc-pi 2.4.0 → 2.6.0
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-zmx631ey.js → index-07rh0nr2.js} +333 -56
- package/dist/{index-cr4hzd76.js → index-vhs0y3s0.js} +214 -5
- package/dist/index.js +2588 -1661
- package/dist/{message-time-backfill-fvkrfyp4.js → message-time-backfill-y26yy5pp.js} +1 -1
- package/dist/{read-session-chunk-g164kwxz.js → read-session-chunk-qg5jfqjg.js} +2 -2
- package/dist/web/main.js +307 -12
- package/package.json +1 -1
|
@@ -24,8 +24,8 @@ import {
|
|
|
24
24
|
getRawSessionTagKeysThrough2,
|
|
25
25
|
getLegacyProtectedTailStartOrdinal2,
|
|
26
26
|
readSessionChunk2
|
|
27
|
-
} from "./index-
|
|
28
|
-
import"./index-
|
|
27
|
+
} from "./index-07rh0nr2.js";
|
|
28
|
+
import"./index-vhs0y3s0.js";
|
|
29
29
|
import"./index-83p1tc98.js";
|
|
30
30
|
export {
|
|
31
31
|
cleanUserText2 as cleanUserText,
|
package/dist/web/main.js
CHANGED
|
@@ -572,6 +572,174 @@ function topLevelCommaSegments(text) {
|
|
|
572
572
|
segments.push(text.slice(start));
|
|
573
573
|
return segments;
|
|
574
574
|
}
|
|
575
|
+
function literalBusyTimeout(sql) {
|
|
576
|
+
const head = BUSY_TIMEOUT_SETTER.exec(sql);
|
|
577
|
+
if (!head)
|
|
578
|
+
return;
|
|
579
|
+
const match = /^(?:=\s*|\(\s*)(?:'(-?\d+)'|"(-?\d+)"|(-?\d+))\s*\)?\s*;?\s*$/.exec(sql.slice(head[0].length));
|
|
580
|
+
if (!match)
|
|
581
|
+
return;
|
|
582
|
+
const value = Number(match[1] ?? match[2] ?? match[3]);
|
|
583
|
+
return value < 0 ? 0 : value <= 2147483647 ? value : undefined;
|
|
584
|
+
}
|
|
585
|
+
function busyTimeoutStatements(sql) {
|
|
586
|
+
const statements = [];
|
|
587
|
+
let statement = "";
|
|
588
|
+
let quote = "";
|
|
589
|
+
for (let i = 0;i < sql.length; i++) {
|
|
590
|
+
const char = sql[i];
|
|
591
|
+
if (quote) {
|
|
592
|
+
statement += char;
|
|
593
|
+
if (char === quote) {
|
|
594
|
+
if (sql[i + 1] === quote)
|
|
595
|
+
statement += sql[++i];
|
|
596
|
+
else
|
|
597
|
+
quote = "";
|
|
598
|
+
}
|
|
599
|
+
} else if (char === "'" || char === '"' || char === "`" || char === "[") {
|
|
600
|
+
quote = char === "[" ? "]" : char;
|
|
601
|
+
statement += char;
|
|
602
|
+
} else if (char === "-" && sql[i + 1] === "-") {
|
|
603
|
+
while (i + 1 < sql.length && sql[i + 1] !== `
|
|
604
|
+
`)
|
|
605
|
+
i++;
|
|
606
|
+
statement += " ";
|
|
607
|
+
} else if (char === "/" && sql[i + 1] === "*") {
|
|
608
|
+
i += 2;
|
|
609
|
+
while (i < sql.length && !(sql[i] === "*" && sql[i + 1] === "/"))
|
|
610
|
+
i++;
|
|
611
|
+
i++;
|
|
612
|
+
statement += " ";
|
|
613
|
+
} else if (char === ";") {
|
|
614
|
+
statements.push(statement);
|
|
615
|
+
statement = "";
|
|
616
|
+
} else
|
|
617
|
+
statement += char;
|
|
618
|
+
}
|
|
619
|
+
statements.push(statement);
|
|
620
|
+
return statements.filter((part) => part.trim().length > 0);
|
|
621
|
+
}
|
|
622
|
+
function installNativeDeadlineRouting(db) {
|
|
623
|
+
const rawExec = db.exec.bind(db);
|
|
624
|
+
const rawPrepare = db.prepare.bind(db);
|
|
625
|
+
const readTimeout = () => {
|
|
626
|
+
const statement = rawPrepare("PRAGMA busy_timeout");
|
|
627
|
+
try {
|
|
628
|
+
return Object.values(statement.get())[0];
|
|
629
|
+
} finally {
|
|
630
|
+
statement.finalize?.();
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
const timeoutState = { current: readTimeout() };
|
|
634
|
+
busyTimeoutStates.set(db, timeoutState);
|
|
635
|
+
const setBusyTimeout = (timeout) => {
|
|
636
|
+
rawExec(`PRAGMA busy_timeout=${timeout}`);
|
|
637
|
+
timeoutState.current = timeout;
|
|
638
|
+
};
|
|
639
|
+
const withinDeadline = (operation) => {
|
|
640
|
+
const deadline = nativeWaitScope?.getStore();
|
|
641
|
+
if (!deadline?.active || !deadline.remainingMs)
|
|
642
|
+
return operation();
|
|
643
|
+
const remaining = deadline.remainingMs();
|
|
644
|
+
if (remaining === Infinity)
|
|
645
|
+
return operation();
|
|
646
|
+
const previous = timeoutState.current;
|
|
647
|
+
const timeout = Math.min(previous, Math.max(0, Math.floor(remaining)));
|
|
648
|
+
if (timeout === previous)
|
|
649
|
+
return operation();
|
|
650
|
+
setBusyTimeout(timeout);
|
|
651
|
+
try {
|
|
652
|
+
return operation();
|
|
653
|
+
} finally {
|
|
654
|
+
setBusyTimeout(previous);
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
Object.defineProperty(db, "exec", {
|
|
658
|
+
configurable: true,
|
|
659
|
+
writable: true,
|
|
660
|
+
value: (sql) => {
|
|
661
|
+
const parts = /\bbusy_timeout\b/i.test(sql) ? busyTimeoutStatements(sql) : [];
|
|
662
|
+
if (parts.length === 1 && BUSY_TIMEOUT_QUERY.test(parts[0]))
|
|
663
|
+
return rawExec(sql);
|
|
664
|
+
const singleSetter = parts.length === 1 && BUSY_TIMEOUT_SETTER.test(parts[0]);
|
|
665
|
+
const setting = singleSetter ? literalBusyTimeout(parts[0]) : undefined;
|
|
666
|
+
if (singleSetter) {
|
|
667
|
+
const result = rawExec(sql);
|
|
668
|
+
timeoutState.current = setting ?? readTimeout();
|
|
669
|
+
return result;
|
|
670
|
+
}
|
|
671
|
+
if (!/\bbusy_timeout\b/i.test(sql))
|
|
672
|
+
return withinDeadline(() => rawExec(sql));
|
|
673
|
+
const setters = parts.filter((part) => BUSY_TIMEOUT_SETTER.test(part));
|
|
674
|
+
return withinDeadline(() => {
|
|
675
|
+
try {
|
|
676
|
+
const result = rawExec(sql);
|
|
677
|
+
if (setters.length)
|
|
678
|
+
timeoutState.current = literalBusyTimeout(setters[setters.length - 1]) ?? readTimeout();
|
|
679
|
+
return result;
|
|
680
|
+
} catch (error) {
|
|
681
|
+
if (setters.length)
|
|
682
|
+
timeoutState.current = readTimeout();
|
|
683
|
+
throw error;
|
|
684
|
+
}
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
});
|
|
688
|
+
const nativePrepare = (sql) => BUSY_TIMEOUT_QUERY.test(sql) || BUSY_TIMEOUT_SETTER.test(sql) ? rawPrepare(sql) : withinDeadline(() => rawPrepare(sql));
|
|
689
|
+
Object.defineProperty(db, "prepare", {
|
|
690
|
+
configurable: true,
|
|
691
|
+
writable: true,
|
|
692
|
+
value: (sql) => {
|
|
693
|
+
const statement = nativePrepare(sql);
|
|
694
|
+
const normalized = /\bbusy_timeout\b/i.test(sql) ? busyTimeoutStatements(sql)[0] ?? sql : sql;
|
|
695
|
+
const setting = literalBusyTimeout(normalized);
|
|
696
|
+
const timeoutSetter = BUSY_TIMEOUT_SETTER.test(normalized);
|
|
697
|
+
const timeoutQuery = BUSY_TIMEOUT_QUERY.test(normalized);
|
|
698
|
+
if (timeoutSetter)
|
|
699
|
+
timeoutState.current = setting ?? readTimeout();
|
|
700
|
+
for (const method of ["run", "get", "all", "values"]) {
|
|
701
|
+
const execute = statement[method]?.bind(statement);
|
|
702
|
+
if (!execute)
|
|
703
|
+
continue;
|
|
704
|
+
Object.defineProperty(statement, method, {
|
|
705
|
+
configurable: true,
|
|
706
|
+
value: (...args) => {
|
|
707
|
+
if (timeoutQuery)
|
|
708
|
+
return execute(...args);
|
|
709
|
+
if (!timeoutSetter)
|
|
710
|
+
return withinDeadline(() => execute(...args));
|
|
711
|
+
const result = execute(...args);
|
|
712
|
+
timeoutState.current = readTimeout();
|
|
713
|
+
return result;
|
|
714
|
+
}
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
if (typeof statement.iterate === "function") {
|
|
718
|
+
const iterate = statement.iterate.bind(statement);
|
|
719
|
+
Object.defineProperty(statement, "iterate", {
|
|
720
|
+
configurable: true,
|
|
721
|
+
value: (...args) => {
|
|
722
|
+
const iterator = !timeoutSetter && !timeoutQuery ? withinDeadline(() => iterate(...args)) : iterate(...args);
|
|
723
|
+
const next = iterator.next.bind(iterator);
|
|
724
|
+
if (timeoutSetter)
|
|
725
|
+
timeoutState.current = readTimeout();
|
|
726
|
+
iterator.next = () => {
|
|
727
|
+
if (timeoutQuery)
|
|
728
|
+
return next();
|
|
729
|
+
if (!timeoutSetter)
|
|
730
|
+
return withinDeadline(next);
|
|
731
|
+
const result = next();
|
|
732
|
+
timeoutState.current = readTimeout();
|
|
733
|
+
return result;
|
|
734
|
+
};
|
|
735
|
+
return iterator;
|
|
736
|
+
}
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
return statement;
|
|
740
|
+
}
|
|
741
|
+
});
|
|
742
|
+
}
|
|
575
743
|
function installTransactionRouting(db, readonly) {
|
|
576
744
|
const nativeExec = db.exec.bind(db);
|
|
577
745
|
Object.defineProperty(db, "exec", {
|
|
@@ -709,7 +877,7 @@ function wrapRemainingTagWriteForms(statement) {
|
|
|
709
877
|
});
|
|
710
878
|
}
|
|
711
879
|
}
|
|
712
|
-
function trackSqliteConnection(db, filename, options) {
|
|
880
|
+
function trackSqliteConnection(db, filename, options, turnDeadlines = false) {
|
|
713
881
|
const originalClose = db.close.bind(db);
|
|
714
882
|
const sequence = nextSqliteConnectionSequence++;
|
|
715
883
|
const metadata = {
|
|
@@ -717,6 +885,8 @@ function trackSqliteConnection(db, filename, options) {
|
|
|
717
885
|
filename: typeof filename === "string" ? filename : Buffer.isBuffer(filename) ? "<buffer>" : ":memory:",
|
|
718
886
|
readonly: Boolean(options) && typeof options === "object" && (options.readonly === true || options.readOnly === true)
|
|
719
887
|
};
|
|
888
|
+
if (turnDeadlines)
|
|
889
|
+
installNativeDeadlineRouting(db);
|
|
720
890
|
installTransactionRouting(db, metadata.readonly);
|
|
721
891
|
Object.defineProperty(db, "close", {
|
|
722
892
|
configurable: true,
|
|
@@ -769,6 +939,11 @@ function pragmaValue(db, name) {
|
|
|
769
939
|
return row[name] ?? Object.values(row)[0];
|
|
770
940
|
}
|
|
771
941
|
function pragmaNumber(db, name) {
|
|
942
|
+
if (name === "busy_timeout") {
|
|
943
|
+
const state = busyTimeoutStates.get(db);
|
|
944
|
+
if (state)
|
|
945
|
+
return state.current;
|
|
946
|
+
}
|
|
772
947
|
try {
|
|
773
948
|
const value = pragmaValue(db, name);
|
|
774
949
|
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
@@ -957,7 +1132,7 @@ function isInTransaction(db) {
|
|
|
957
1132
|
const candidate = db;
|
|
958
1133
|
return candidate.inTransaction === true || candidate.isTransaction === true;
|
|
959
1134
|
}
|
|
960
|
-
var resourceRoot, 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, SLOW_WRITER_LOG_MS = 100, WRITER_TRANSACTION_END, writerAcquisitionScope, openWriterTransactions, indexCoordinationKey, indexCoordinationHeap, indexCoordinationBuffer, indexCoordinationState;
|
|
1135
|
+
var resourceRoot, reportSlowPrivilegedWrite, sqliteDiagnosticSink, sqliteDiagnosticHost = () => "unknown", bunSpec, nodeSpec, SqliteRuntimeUnavailableError, detectedRuntime, isBun, sqliteModule, DatabaseImpl, trackedSqliteConnections, nextSqliteConnectionSequence = 1, TAG_COLUMNS_OUTSIDE_IDENTITY, tagIdentityWriteGeneration = 0, busyTimeoutStates, BUSY_TIMEOUT_QUERY, BUSY_TIMEOUT_SETTER, TrackedDatabase, Database, statementOwners, FIRST_PRUNE_AT = 256, privilegeDepth, nativeWaitScope, transformPassScope, admissionScope, backgroundWriterScope, SqliteAcquisitionBusyError, SHORT_BUSY_TIMEOUT_MS = 25, SLOW_WRITER_LOG_MS = 100, WRITER_TRANSACTION_END, writerAcquisitionScope, openWriterTransactions, indexCoordinationKey, indexCoordinationHeap, indexCoordinationBuffer, indexCoordinationState;
|
|
961
1136
|
var init_sqlite = __esm(async () => {
|
|
962
1137
|
resourceRoot = new AsyncResource("magic-context:root");
|
|
963
1138
|
bunSpec = "bun:" + "sqlite";
|
|
@@ -991,6 +1166,9 @@ var init_sqlite = __esm(async () => {
|
|
|
991
1166
|
"tool_name",
|
|
992
1167
|
"harness"
|
|
993
1168
|
]);
|
|
1169
|
+
busyTimeoutStates = new WeakMap;
|
|
1170
|
+
BUSY_TIMEOUT_QUERY = /^\s*PRAGMA\s+(?:(?:\w+|"[^"]+"|`[^`]+`|\[[^\]]+\])\s*\.\s*)?(?:busy_timeout|"busy_timeout"|`busy_timeout`|\[busy_timeout\])\s*;?\s*$/i;
|
|
1171
|
+
BUSY_TIMEOUT_SETTER = /^\s*PRAGMA\s+(?:(?:\w+|"[^"]+"|`[^`]+`|\[[^\]]+\])\s*\.\s*)?(?:busy_timeout|"busy_timeout"|`busy_timeout`|\[busy_timeout\])\s*(?==|\()/i;
|
|
994
1172
|
TrackedDatabase = new Proxy(DatabaseImpl, {
|
|
995
1173
|
construct(target, args) {
|
|
996
1174
|
const db = inRootAsyncContext(() => Reflect.construct(target, args, target));
|
|
@@ -1181,12 +1359,58 @@ var init_read_session_formatting = __esm(() => {
|
|
|
1181
1359
|
promptTokenCounts = new Map;
|
|
1182
1360
|
PROMPT_TOKEN_COUNT_BYTES = 8 * 1024 * 1024;
|
|
1183
1361
|
});
|
|
1362
|
+
|
|
1363
|
+
// ../plugin/src/shared/bounded-session-map.ts
|
|
1364
|
+
class BoundedSessionMap {
|
|
1365
|
+
maxEntries;
|
|
1366
|
+
store = new Map;
|
|
1367
|
+
constructor(maxEntries) {
|
|
1368
|
+
if (!Number.isFinite(maxEntries) || maxEntries < 1) {
|
|
1369
|
+
throw new Error(`BoundedSessionMap: maxEntries must be >= 1, got ${maxEntries}`);
|
|
1370
|
+
}
|
|
1371
|
+
this.maxEntries = maxEntries;
|
|
1372
|
+
}
|
|
1373
|
+
get(sessionId) {
|
|
1374
|
+
const value = this.store.get(sessionId);
|
|
1375
|
+
if (value === undefined)
|
|
1376
|
+
return;
|
|
1377
|
+
this.store.delete(sessionId);
|
|
1378
|
+
this.store.set(sessionId, value);
|
|
1379
|
+
return value;
|
|
1380
|
+
}
|
|
1381
|
+
peek(sessionId) {
|
|
1382
|
+
return this.store.get(sessionId);
|
|
1383
|
+
}
|
|
1384
|
+
has(sessionId) {
|
|
1385
|
+
return this.store.has(sessionId);
|
|
1386
|
+
}
|
|
1387
|
+
set(sessionId, value) {
|
|
1388
|
+
if (this.store.has(sessionId)) {
|
|
1389
|
+
this.store.delete(sessionId);
|
|
1390
|
+
} else if (this.store.size >= this.maxEntries) {
|
|
1391
|
+
const oldest = this.store.keys().next().value;
|
|
1392
|
+
if (oldest !== undefined)
|
|
1393
|
+
this.store.delete(oldest);
|
|
1394
|
+
}
|
|
1395
|
+
this.store.set(sessionId, value);
|
|
1396
|
+
}
|
|
1397
|
+
delete(sessionId) {
|
|
1398
|
+
return this.store.delete(sessionId);
|
|
1399
|
+
}
|
|
1400
|
+
clear() {
|
|
1401
|
+
this.store.clear();
|
|
1402
|
+
}
|
|
1403
|
+
get size() {
|
|
1404
|
+
return this.store.size;
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1184
1407
|
// ../plugin/src/features/magic-context/tool-definition-tokens.ts
|
|
1185
|
-
var
|
|
1408
|
+
var ACTIVITY_WINDOW_MS, routes, sessionFlights;
|
|
1186
1409
|
var init_tool_definition_tokens = __esm(() => {
|
|
1187
1410
|
init_read_session_formatting();
|
|
1188
|
-
|
|
1189
|
-
|
|
1411
|
+
ACTIVITY_WINDOW_MS = 10 * 60000;
|
|
1412
|
+
routes = new Map;
|
|
1413
|
+
sessionFlights = new BoundedSessionMap(1000);
|
|
1190
1414
|
});
|
|
1191
1415
|
|
|
1192
1416
|
// ../plugin/src/shared/opencode-db-path.ts
|
|
@@ -4436,6 +4660,13 @@ function closeConnection(connection) {
|
|
|
4436
4660
|
counters.readersClosed += 1;
|
|
4437
4661
|
}
|
|
4438
4662
|
}
|
|
4663
|
+
function messageTimesQuery(count, withVersions = false) {
|
|
4664
|
+
return `SELECT id, COALESCE(time_created, json_extract(data, '$.time.created')) AS created,
|
|
4665
|
+
json_extract(data, '$.time.completed') AS completed
|
|
4666
|
+
${withVersions ? ", type, seq, time_created AS version_created, time_updated AS version_updated" : ""}
|
|
4667
|
+
FROM session_message WHERE +session_id = ? AND id IN (${Array.from({ length: count }, () => "?").join(",")})`;
|
|
4668
|
+
}
|
|
4669
|
+
|
|
4439
4670
|
class V2StoreReader {
|
|
4440
4671
|
path;
|
|
4441
4672
|
pool;
|
|
@@ -4531,6 +4762,12 @@ class V2StoreReader {
|
|
|
4531
4762
|
return typeof row?.count === "number" ? row.count : 0;
|
|
4532
4763
|
});
|
|
4533
4764
|
}
|
|
4765
|
+
messageCountAfterSequence(sessionID, after, through) {
|
|
4766
|
+
const rawTypes = RAW_MESSAGE_TYPES.map(() => "?").join(", ");
|
|
4767
|
+
const row = this.prepare(`SELECT COUNT(*) AS count FROM session_message
|
|
4768
|
+
WHERE session_id = ? AND seq > ? AND seq <= ? AND type IN (${rawTypes})`).get(sessionID, after, through, ...RAW_MESSAGE_TYPES);
|
|
4769
|
+
return typeof row?.count === "number" ? row.count : 0;
|
|
4770
|
+
}
|
|
4534
4771
|
sessionDirectoryPage(afterSessionID, limit) {
|
|
4535
4772
|
const rows = this.prepare(`SELECT id, COALESCE(directory, '') AS directory FROM session_v2
|
|
4536
4773
|
WHERE id > ? ORDER BY id ASC LIMIT ?`).all(afterSessionID ?? "", limit);
|
|
@@ -4564,6 +4801,49 @@ class V2StoreReader {
|
|
|
4564
4801
|
return row ? decode(row) : null;
|
|
4565
4802
|
});
|
|
4566
4803
|
}
|
|
4804
|
+
messageTimeVersions(sessionID, ids, span) {
|
|
4805
|
+
const versions = new Map;
|
|
4806
|
+
if (ids.length > 0 && span && span.last - span.first < ids.length * 2) {
|
|
4807
|
+
const wanted = new Set(ids);
|
|
4808
|
+
const rows = this.prepare(`SELECT id, type, seq, time_created AS created, time_updated AS updated
|
|
4809
|
+
FROM session_message WHERE session_id = ? AND seq >= ? AND seq <= ?`).all(sessionID, span.first, span.last);
|
|
4810
|
+
for (const row of rows)
|
|
4811
|
+
if (wanted.has(row.id))
|
|
4812
|
+
versions.set(row.id, row);
|
|
4813
|
+
for (const [id, version] of this.messageTimeVersions(sessionID, ids.filter((id) => !versions.has(id))))
|
|
4814
|
+
versions.set(id, version);
|
|
4815
|
+
return versions;
|
|
4816
|
+
}
|
|
4817
|
+
for (let offset = 0;offset < ids.length; offset += 500) {
|
|
4818
|
+
const batch = ids.slice(offset, offset + 500);
|
|
4819
|
+
const rows = this.prepare(`SELECT id, type, seq, time_created AS created, time_updated AS updated
|
|
4820
|
+
FROM session_message WHERE +session_id = ? AND id IN (${batch.map(() => "?").join(",")})`).all(sessionID, ...batch);
|
|
4821
|
+
for (const row of rows)
|
|
4822
|
+
versions.set(row.id, row);
|
|
4823
|
+
}
|
|
4824
|
+
return versions;
|
|
4825
|
+
}
|
|
4826
|
+
messageTimes(sessionID, ids, versions) {
|
|
4827
|
+
const times = new Map;
|
|
4828
|
+
for (let offset = 0;offset < ids.length; offset += 500) {
|
|
4829
|
+
const batch = ids.slice(offset, offset + 500);
|
|
4830
|
+
const rows = this.prepare(messageTimesQuery(batch.length, versions !== undefined)).all(sessionID, ...batch);
|
|
4831
|
+
for (const row of rows) {
|
|
4832
|
+
times.set(row.id, {
|
|
4833
|
+
created: typeof row.created === "number" ? row.created : undefined,
|
|
4834
|
+
completed: typeof row.completed === "number" ? row.completed : undefined
|
|
4835
|
+
});
|
|
4836
|
+
versions?.set(row.id, {
|
|
4837
|
+
id: row.id,
|
|
4838
|
+
type: row.type,
|
|
4839
|
+
seq: row.seq,
|
|
4840
|
+
created: row.version_created,
|
|
4841
|
+
updated: row.version_updated
|
|
4842
|
+
});
|
|
4843
|
+
}
|
|
4844
|
+
}
|
|
4845
|
+
return times;
|
|
4846
|
+
}
|
|
4567
4847
|
messageExistsById(sessionID, id) {
|
|
4568
4848
|
return trackDecodeOperation("messageExistsById", () => {
|
|
4569
4849
|
const rawTypes = RAW_MESSAGE_TYPES.map(() => "?").join(", ");
|
|
@@ -4649,6 +4929,14 @@ class V2StoreReader {
|
|
|
4649
4929
|
ORDER BY seq DESC LIMIT ?`).all(sessionID, ...RAW_MESSAGE_TYPES, throughSeq, limit).map(decode);
|
|
4650
4930
|
});
|
|
4651
4931
|
}
|
|
4932
|
+
instructionRowsThrough(sessionID, throughSeq) {
|
|
4933
|
+
return trackDecodeOperation("instructionRowsThrough", () => {
|
|
4934
|
+
if (!Number.isSafeInteger(throughSeq))
|
|
4935
|
+
throw new Error("Invalid seq upper bound");
|
|
4936
|
+
return this.prepare(`SELECT id, session_id, type, seq, time_created, data FROM session_message
|
|
4937
|
+
WHERE session_id = ? AND type = 'system' AND seq <= ? ORDER BY seq ASC`).all(sessionID, throughSeq).map(decode);
|
|
4938
|
+
});
|
|
4939
|
+
}
|
|
4652
4940
|
sequenceForId(sessionID, id) {
|
|
4653
4941
|
if (!id)
|
|
4654
4942
|
return;
|
|
@@ -5322,24 +5610,31 @@ ${data.output?.output ?? ""}`
|
|
|
5322
5610
|
const sameModel = sameProvider && previousModel?.id === model.id;
|
|
5323
5611
|
const reuse = sameModel && data.error === undefined;
|
|
5324
5612
|
const metadata = (state) => state === undefined ? undefined : { [model.providerID]: state };
|
|
5613
|
+
const reasoningInterrupted = data.content?.some((part) => part.type === "reasoning" && part.time !== undefined && part.time.completed === undefined);
|
|
5325
5614
|
const content = [];
|
|
5326
5615
|
const results = [];
|
|
5327
5616
|
for (const part of data.content ?? []) {
|
|
5617
|
+
let native = "native" in part ? part.native : part.type === "tool" ? part.providerState : part.state;
|
|
5618
|
+
if (part.type === "tool" && part.providerResultState !== null && typeof part.providerResultState === "object" && !Array.isArray(part.providerResultState))
|
|
5619
|
+
native = {
|
|
5620
|
+
...native !== null && typeof native === "object" && !Array.isArray(native) ? native : {},
|
|
5621
|
+
...part.providerResultState
|
|
5622
|
+
};
|
|
5328
5623
|
if (part.type === "text") {
|
|
5329
5624
|
if (part.text !== "")
|
|
5330
5625
|
content.push({
|
|
5331
5626
|
type: "text",
|
|
5332
5627
|
text: part.text,
|
|
5333
|
-
providerMetadata: reuse ? metadata(
|
|
5628
|
+
providerMetadata: reuse ? metadata(native) : undefined
|
|
5334
5629
|
});
|
|
5335
5630
|
continue;
|
|
5336
5631
|
}
|
|
5337
5632
|
if (part.type === "reasoning") {
|
|
5338
|
-
if (part.text !== "" || reuse &&
|
|
5633
|
+
if (part.text !== "" || reuse && !reasoningInterrupted && native !== undefined)
|
|
5339
5634
|
content.push({
|
|
5340
|
-
type:
|
|
5635
|
+
type: data.error === undefined && !reasoningInterrupted ? "reasoning" : "text",
|
|
5341
5636
|
text: part.text,
|
|
5342
|
-
providerMetadata: reuse ? metadata(
|
|
5637
|
+
providerMetadata: reuse && !reasoningInterrupted ? metadata(native) : undefined
|
|
5343
5638
|
});
|
|
5344
5639
|
continue;
|
|
5345
5640
|
}
|
|
@@ -5358,7 +5653,7 @@ ${data.output?.output ?? ""}`
|
|
|
5358
5653
|
name: part.name,
|
|
5359
5654
|
input,
|
|
5360
5655
|
providerExecuted: part.executed,
|
|
5361
|
-
providerMetadata: toolReuse ? metadata(
|
|
5656
|
+
providerMetadata: toolReuse ? metadata(native) : undefined
|
|
5362
5657
|
});
|
|
5363
5658
|
if (!completed)
|
|
5364
5659
|
continue;
|
|
@@ -5369,7 +5664,7 @@ ${data.output?.output ?? ""}`
|
|
|
5369
5664
|
id: part.id,
|
|
5370
5665
|
name: part.name,
|
|
5371
5666
|
providerExecuted: part.executed,
|
|
5372
|
-
providerMetadata:
|
|
5667
|
+
providerMetadata: (part.executed === true ? sameProvider : reuse) ? metadata(native) : undefined,
|
|
5373
5668
|
result: state.status === "error" ? { error: state.error, content: toolContent } : single?.type === "text" ? { type: "text", value: single.text } : { type: "content", value: toolContent },
|
|
5374
5669
|
...state.status === "error" ? { resultType: "error" } : {}
|
|
5375
5670
|
};
|
|
@@ -5422,7 +5717,7 @@ function projectRawMessages(rows, ordinalFor) {
|
|
|
5422
5717
|
const message = {
|
|
5423
5718
|
id: row.id,
|
|
5424
5719
|
ordinal: ordinalFor(row, index),
|
|
5425
|
-
role: row.type === "assistant" ? "assistant" : "user",
|
|
5720
|
+
role: row.type === "assistant" ? "assistant" : row.type === "system" ? "system" : "user",
|
|
5426
5721
|
createdAt: row.time_created ?? row.data.time?.created,
|
|
5427
5722
|
parts: row.type === "assistant" ? (row.data.content ?? []).map((part) => {
|
|
5428
5723
|
if (part.type !== "tool")
|
package/package.json
CHANGED