import fs from "node:fs/promises"; import os from "node:os"; import type { ModelMessage } from "ai"; const home = os.homedir(); const convoPath = `${home}/.lmc_convo.json`; export interface IConversation { model: string; messages: ModelMessage[]; } export class Conversation implements IConversation { messages: ModelMessage[] = []; constructor(public model: string) {} async load() { try { const text = await fs.readFile(convoPath, "utf8"); const convo: IConversation = JSON.parse(text); this.model = convo.model; this.messages = convo.messages; } catch { console.error("No conversation found, starting one."); } } async save() { await fs.writeFile( convoPath, JSON.stringify({ model: this.model, messages: this.messages, } satisfies IConversation), ); } }