andy-stack_vaultkeeper-ai/Conversations/Conversation.ts
Andrew Beal 3bc2b34aa2 feat: add web viewer content retrieval tool for AI agents
Add new get_web_viewer_content tool that allows AI agents to retrieve
text content or screenshots from open web views. Refactor AIToolResponse
to use AIToolResponsePayload class for structured responses with attachment
support. Update tool service to handle binary file attachments consistently
across read_vault_files and new web viewer tool.
2026-04-08 21:00:23 +01:00

57 lines
No EOL
1.9 KiB
TypeScript

import { StringTools } from "Helpers/StringTools";
import { ConversationContent } from "./ConversationContent";
import type { AIToolResponse } from "AIClasses/ToolDefinitions/AIToolResponse";
import { Role } from "Enums/Role";
export class Conversation {
title: string;
created: Date;
updated: Date;
contents: ConversationContent[] = [];
constructor() {
const timestamp = new Date();
this.created = timestamp;
this.updated = timestamp;
this.title = `${StringTools.dateToString(this.created)}`;
}
public hasAttachments(): boolean {
return this.contents.some(c => c.attachments.length > 0);
}
public addFunctionResponse(functionResponse: AIToolResponse): void {
this.contents.push(new ConversationContent({
role: Role.User,
functionResponse: functionResponse.toConversationString(),
shouldDisplayContent: false,
toolId: functionResponse.toolId
}));
if (functionResponse.payload.attachments.length > 0) {
this.contents.push(new ConversationContent({
role: Role.User,
attachments: functionResponse.payload.attachments,
shouldDisplayContent: false
}));
}
}
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)
);
}
}