mirror of
https://github.com/andy-stack/vaultkeeper-ai.git
synced 2026-07-22 06:42:03 +00:00
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.
49 lines
No EOL
1.6 KiB
TypeScript
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;
|
|
}
|
|
}
|
|
} |