refactor: extract config and conversation handling into separate modules
This commit is contained in:
parent
f50280364d
commit
6dc55bc3f3
3 changed files with 64 additions and 23 deletions
26
src/config/index.ts
Normal file
26
src/config/index.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import os from "node:os";
|
||||
import chalk from "chalk";
|
||||
|
||||
const home = os.homedir();
|
||||
const configFile = Bun.file(`${home}/.aicl_config.json`);
|
||||
|
||||
export interface AppConfig {
|
||||
model?: string;
|
||||
}
|
||||
|
||||
export async function loadConfig(): Promise<{
|
||||
config: AppConfig;
|
||||
}> {
|
||||
let config: AppConfig;
|
||||
try {
|
||||
config = await configFile.json();
|
||||
} catch {
|
||||
config = {};
|
||||
}
|
||||
return { config };
|
||||
}
|
||||
|
||||
export async function saveConfig(config: AppConfig): Promise<void> {
|
||||
await configFile.write(JSON.stringify(config, null, " "));
|
||||
console.log(chalk.green("Configuration saved!"));
|
||||
}
|
||||
24
src/conversation/index.ts
Normal file
24
src/conversation/index.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import os from "node:os";
|
||||
import type { ModelMessage } from "ai";
|
||||
|
||||
const home = os.homedir();
|
||||
export const convoFile = Bun.file(`${home}/.aicl_convo.json`);
|
||||
|
||||
export interface Conversation {
|
||||
model: string;
|
||||
messages: ModelMessage[];
|
||||
}
|
||||
|
||||
export async function loadConversation(
|
||||
defaultModel: string,
|
||||
): Promise<Conversation> {
|
||||
try {
|
||||
return await convoFile.json();
|
||||
} catch {
|
||||
return { model: defaultModel, messages: [] };
|
||||
}
|
||||
}
|
||||
|
||||
export async function saveConversation(convo: Conversation): Promise<void> {
|
||||
await convoFile.write(JSON.stringify(convo));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue