fix: drain accepted exports and close failed store initialization
This commit is contained in:
1 parent
54e5bafd86
commit
a420d2d9fb
12 files changed
+204
-71
No files matched your search
@@ -9,12 +9,18 @@ function installedRuntime(dir){try{
|
||||
}catch{return '';}}
|
||||
class AssistantStore{
|
||||
constructor(dir){
|
||||
this.dir=path.resolve(dir);this.defaultRuntime=installedRuntime(this.dir);this.vault=new BpmVault({stateDir:this.dir});this.db=new DatabaseSync(path.join(this.dir,'assistant.sqlite'));
|
||||
this.db.exec(`PRAGMA journal_mode=WAL; PRAGMA busy_timeout=5000; PRAGMA secure_delete=ON;
|
||||
CREATE TABLE IF NOT EXISTS config(id INTEGER PRIMARY KEY,version INTEGER NOT NULL,payload BLOB NOT NULL);
|
||||
CREATE TABLE IF NOT EXISTS conversations(id TEXT PRIMARY KEY,owner TEXT NOT NULL,payload BLOB NOT NULL,created_at TEXT NOT NULL,updated_at TEXT NOT NULL);
|
||||
CREATE TABLE IF NOT EXISTS turns(id TEXT PRIMARY KEY,conversation_id TEXT NOT NULL,status TEXT NOT NULL,payload BLOB NOT NULL,day TEXT NOT NULL,created_at TEXT NOT NULL);
|
||||
CREATE INDEX IF NOT EXISTS conversation_turns ON turns(conversation_id,created_at);`);
|
||||
try {
|
||||
this.dir=path.resolve(dir);this.defaultRuntime=installedRuntime(this.dir);this.vault=new BpmVault({stateDir:this.dir});this.db=new DatabaseSync(path.join(this.dir,'assistant.sqlite'));
|
||||
this.db.exec(`PRAGMA journal_mode=WAL; PRAGMA busy_timeout=5000; PRAGMA secure_delete=ON;
|
||||
CREATE TABLE IF NOT EXISTS config(id INTEGER PRIMARY KEY,version INTEGER NOT NULL,payload BLOB NOT NULL);
|
||||
CREATE TABLE IF NOT EXISTS conversations(id TEXT PRIMARY KEY,owner TEXT NOT NULL,payload BLOB NOT NULL,created_at TEXT NOT NULL,updated_at TEXT NOT NULL);
|
||||
CREATE TABLE IF NOT EXISTS turns(id TEXT PRIMARY KEY,conversation_id TEXT NOT NULL,status TEXT NOT NULL,payload BLOB NOT NULL,day TEXT NOT NULL,created_at TEXT NOT NULL);
|
||||
CREATE INDEX IF NOT EXISTS conversation_turns ON turns(conversation_id,created_at);`);
|
||||
} catch(error) {
|
||||
try { this.db?.close(); } catch {}
|
||||
try { this.vault?.destroy(); } catch {}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
transaction(work){this.db.exec('BEGIN IMMEDIATE');try{const result=work();this.db.exec('COMMIT');return result;}catch(e){this.db.exec('ROLLBACK');throw e;}}
|
||||
encode(id,value){return this.vault.encode('assistant:'+id,value);}
|
||||
|
||||
Reference in new issue
Block a user