refactor(core): share sqlite boundary types

This commit is contained in:
tommy0103
2026-07-12 00:44:06 +08:00
parent 3a6e3a00a7
commit c4c458fa8f
8 changed files with 47 additions and 33 deletions
+4 -4
View File
@@ -1,8 +1,8 @@
// Query and attune sandbox helpers for the Core package.
import { readLines, fs, path } from './db.ts';
import type { SqliteDb, SqliteRow } from './sqlite-types.ts';
type SqliteDb = any;
type DbRow = Record<string, any>;
type DbRow = SqliteRow;
interface QueryOptions extends Record<string, any> {
limit?: number;
@@ -162,7 +162,7 @@ function createQueryApi(db: SqliteDb) {
if (!msg) return null;
const session = db.prepare('SELECT * FROM sessions WHERE id=?').get(msg.session_id);
const chain: DbRow[] = [];
let cur = msg;
let cur: DbRow | undefined = msg;
while (cur?.parent_uuid) { cur = db.prepare('SELECT * FROM messages WHERE uuid=?').get(cur.parent_uuid); if (cur) chain.unshift(cur); }
const subagent = msg.agent_id ? db.prepare('SELECT * FROM subagents WHERE agent_id=?').get(msg.agent_id) : null;
let workflow = null;
@@ -176,7 +176,7 @@ function createQueryApi(db: SqliteDb) {
const trace = (uuid: string) => {
const chain: DbRow[] = [];
let cur = db.prepare('SELECT * FROM messages WHERE uuid=?').get(uuid);
while (cur) { chain.unshift(cur); cur = cur.parent_uuid ? db.prepare('SELECT * FROM messages WHERE uuid=?').get(cur.parent_uuid) : null; }
while (cur) { chain.unshift(cur); cur = cur.parent_uuid ? db.prepare('SELECT * FROM messages WHERE uuid=?').get(cur.parent_uuid) : undefined; }
return chain;
};