Files
opencode-manager/backend/test/mocks/bun-sqlite.ts
Chris Scott dbd6866682 feat(assistant): self-configuring assistant mode (#244)
* test(backend): replace better-sqlite3 test mock with node:sqlite

Reimplement the bun:sqlite test mock on top of node:sqlite with an
explicit BEGIN/COMMIT/ROLLBACK transaction wrapper.

* feat(assistant): self-configuring assistant mode

Add a self-editable assistant workspace and the APIs that support it:
- POST /assistant/reload disposes and re-bootstraps the assistant
  instance (directory-scoped, rate-limited) so agent.md edits apply.
- Internal settings API accepts non-secret TTS/STT patches via
  dedicated partial schemas.
- Strip the generated agent persona from opencode.json on repair so
  user-customized agents are preserved across config recovery.
- Cache the last assistant session id to avoid redundant session
  listing on launch.

* style(repo): align worktree and workspace tabs with primary/orange theme
2026-05-31 11:38:02 -04:00

47 lines
1.1 KiB
TypeScript

import { DatabaseSync } from 'node:sqlite'
// Adapter to make node:sqlite compatible with bun:sqlite API
export class Database {
private db: DatabaseSync
constructor(path: string) {
this.db = new DatabaseSync(path)
}
prepare(sql: string) {
const stmt = this.db.prepare(sql)
return {
run: (...params: unknown[]) => (stmt.run as (...args: unknown[]) => void)(...params),
get: (...params: unknown[]) => (stmt.get as (...args: unknown[]) => unknown)(...params),
all: (...params: unknown[]) => (stmt.all as (...args: unknown[]) => unknown[])(...params),
}
}
exec(sql: string) {
this.db.exec(sql)
}
run(sql: string, ...params: unknown[]) {
const stmt = this.db.prepare(sql)
return (stmt.run as (...args: unknown[]) => void)(...params)
}
transaction<T extends (...args: unknown[]) => void>(fn: T) {
return (...args: unknown[]) => {
this.db.exec('BEGIN')
try {
const result = fn(...args)
this.db.exec('COMMIT')
return result
} catch (e) {
this.db.exec('ROLLBACK')
throw e
}
}
}
close() {
this.db.close()
}
}