Files
Courtney SimsandGitHub f8d9ba2fdf Update container read tool call (#54)
* Update read tool call

* forgot a test

* prettier
2025-04-21 09:31:50 -05:00

20 lines
628 B
TypeScript

export async function fileToBase64(blob: Blob): Promise<string> {
// Use ArrayBuffer instead of text() for binary data
const arrayBuffer = await blob.arrayBuffer()
const byteArray = new Uint8Array(arrayBuffer)
// Convert byte array to base64 string
let binary = ''
byteArray.forEach((byte) => {
binary += String.fromCharCode(byte)
})
// Apply base64 encoding
return btoa(binary)
}
// Used for file related tool calls in case the llm sends a full resource URI
export async function stripProtocolFromFilePath(path: string): Promise<string> {
return path.startsWith('file://') ? path.replace('file://', '') : path
}