You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.2 KiB
TypeScript

import { Low } from "lowdb";
import { JSONFile } from "lowdb/node";
import type { CommittedMessage } from "../types";
export type Conversation = {
id: string;
title: string;
userId: string;
};
export type Fact = {
id: string;
userId: string;
sourceMessageId: string;
content: string;
createdAt: string;
};
export type FactTrigger = {
id: string;
sourceFactId: string;
content: string;
priorityMultiplier: number;
priorityMultiplierReason: string;
scopeConversationId: string;
createdAt: string;
};
type DB = {
conversations: Array<Conversation>;
messages: Array</*{
id: string;
conversationId: string;
content: string;
role: "user" | "assistant" | "system" | "data";
index: number;
createdAt: string;
runningSummary?: string;
}*/ CommittedMessage>;
facts: Array<Fact>;
factTriggers: Array<FactTrigger>;
};
export const db = new Low<DB>(new JSONFile("db.json"), {
conversations: [],
messages: [],
facts: [],
factTriggers: [],
});
/** Initialize the database. Sets `db.data` to the default state if the file doesn't exist. */
await db.read();
/** Write the database to the file, in case it didn't exist before. */
await db.write();