mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
* feat: add persistent model state storage with database backend - Create opencode_model_state table for storing user model preferences - Implement database-backed model state management (recent, favorite, variant) - Add atomic JSON file utilities with file locking for concurrent safety - Migrate providers routes from file-based to database storage - Add backfill migration to preserve existing model.json data - Include comprehensive tests for model-state and atomic-json modules - Refactor useSessionAgent hook to simplify agent/model resolution logic - Update getFileApiUrl to use consistent query parameter approach * fix: include workspace dependencies in Docker image * fix: overlay workspace node_modules after source to prevent layer overwrite * fix: ensure model state table exists for existing databases * feat: add model state persistence and improve model selection sync - Add setActiveModel to modelStore and useModelSelection for direct model updates - Sync session agent model/variant to store when messages load - Include model, agent, and variant in optimistic user messages - Fix useSessionAgent to check isFetching during message loading - Update env.ts to use getter for BASE_PATH for dynamic resolution - Fix test environment variable from OPENCODE_WORKSPACE_PATH to WORKSPACE_PATH
37 lines
859 B
TypeScript
37 lines
859 B
TypeScript
import DatabaseImpl from 'better-sqlite3'
|
|
import type { Database as BetterSqlite3Database } from 'better-sqlite3'
|
|
|
|
// Adapter to make better-sqlite3 compatible with bun:sqlite API
|
|
export class Database {
|
|
private db: BetterSqlite3Database
|
|
|
|
constructor(path: string) {
|
|
this.db = new DatabaseImpl(path)
|
|
}
|
|
|
|
prepare(sql: string) {
|
|
const stmt = this.db.prepare(sql)
|
|
return {
|
|
run: (...params: unknown[]) => stmt.run(...params),
|
|
get: (...params: unknown[]) => stmt.get(...params),
|
|
all: (...params: unknown[]) => stmt.all(...params),
|
|
}
|
|
}
|
|
|
|
exec(sql: string) {
|
|
this.db.exec(sql)
|
|
}
|
|
|
|
run(sql: string, ...params: unknown[]) {
|
|
return this.db.prepare(sql).run(...params)
|
|
}
|
|
|
|
transaction<T extends (...args: unknown[]) => void>(fn: T) {
|
|
return this.db.transaction(fn)
|
|
}
|
|
|
|
close() {
|
|
this.db.close()
|
|
}
|
|
}
|