andy-stack_vaultkeeper-ai/Conversations/Attachment.ts
Andrew Beal 3e013f6c9f refactor: migrate from flag-based content types to typed properties
Replace boolean flags (isFunctionCall, isFunctionCallResponse,
isProviderSpecificContent) with explicit typed properties (functionCall,
functionResponse, attachments) in ConversationContent. Introduce Attachment
class and BaseAIFileService. Update all AI providers (Claude, Gemini, OpenAI)
to use new attachment-based binary file handling with proper error handling,
retry logic, and AbortService integration.
Implement new Files API service for all providers (not yet integrated).
2025-12-19 12:30:51 +00:00

55 lines
No EOL
1.5 KiB
TypeScript

import type { AIProvider } from "Enums/ApiProvider";
export class Attachment {
public fileName: string;
public mimeType: string;
public base64: string;
public fileID: Partial<Record<AIProvider, string>>;
constructor(
fileName: string,
mimeType: string,
base64: string,
fileID: Partial<Record<AIProvider, string>> = {}
) {
this.fileName = fileName;
this.mimeType = mimeType;
this.base64 = base64;
this.fileID = fileID;
}
public getFileID(provider: AIProvider): string | undefined {
return this.fileID[provider];
}
public setFileID(provider: AIProvider, id: string): void {
this.fileID[provider] = id;
}
public deleteFileID(provider: AIProvider): boolean {
if (provider in this.fileID) {
delete this.fileID[provider];
return true;
}
return false;
}
public static isAttachmentData(this: void, data: unknown): data is {
fileName: string;
mimeType: string;
base64: string;
fileID?: Partial<Record<AIProvider, string>>;
} {
return (
data !== null &&
typeof data === "object" &&
"fileName" in data &&
"mimeType" in data &&
"base64" in data &&
typeof data.fileName === "string" &&
typeof data.mimeType === "string" &&
typeof data.base64 === "string" &&
(!("fileID" in data) || typeof data.fileID === "object")
);
}
}