andy-stack_vaultkeeper-ai/Conversations/Conversation.ts
Andrew Beal fbe5766d03 refactor: consolidate string utilities into StringTools class
Move isValidJson, dateToString, and escapeRegex from Helpers to new StringTools class. Add asRegex method for parsing regex literals with /pattern/flags format. Update all imports and usages across codebase.
2025-11-12 21:12:36 +00:00

49 lines
No EOL
1.6 KiB
TypeScript

import { StringTools } from "Helpers/StringTools";
import { ConversationContent } from "./ConversationContent";
export class Conversation {
title: string;
created: Date;
updated: Date;
path: string;
contents: ConversationContent[] = [];
constructor() {
this.created = new Date();
this.updated = new Date();
this.title = `${StringTools.dateToString(this.created)}`;
}
public static isConversationData(data: unknown): data is { title: string; created: string; updated: string; contents: ConversationContent[] } {
return (
typeof data === "object" &&
data !== null &&
"title" in data &&
"created" in data &&
"updated" in data &&
"contents" in data &&
typeof data.title === "string" &&
typeof data.created === "string" &&
typeof data.updated === "string" &&
Array.isArray(data.contents) &&
data.contents.every(ConversationContent.isConversationContentData)
);
}
public setMostRecentContent(content: string) {
const conversationContent: ConversationContent | undefined = this.contents[this.contents.length - 1];
if (conversationContent) {
conversationContent.content = content;
}
}
public setMostRecentFunctionCall(functionCall: string) {
const conversationContent: ConversationContent | undefined = this.contents[this.contents.length - 1];
if (conversationContent) {
conversationContent.functionCall = functionCall;
conversationContent.isFunctionCall = true;
}
}
}