Replace Bun.argv with process.argv, Bun.file() with fs/promises, Bun.stringWidth with string-width package, and Bun.wrapAnsi with wrap-ansi package for better compatibility.
38 lines
873 B
TypeScript
38 lines
873 B
TypeScript
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);
|
|
const convo: IConversation = JSON.parse(text.toString("utf8"));
|
|
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),
|
|
);
|
|
}
|
|
}
|