Skip to content

text trigger attach file not working #93

@DimitriGilbert

Description

@DimitriGilbert

###Bug: File Protocol Fetch Blocked in Browsers

The FileControlModule's handleFileAttach method attempts to read local files using fetch('file://...'). This fails in browser environments due to security policies that block fetch requests to the file:// protocol, resulting in a network error and preventing file attachment.

src/controls/modules/FileControlModule.ts#L164-L204

// Read file from filesystem
const response = await fetch(`file://${filePath}`);
if (!response.ok) {
console.warn(`[FileControlModule] Could not read file: ${filePath}`);
continue;
}
const fileName = filePath.split('/').pop() || filePath;
const fileSize = parseInt(response.headers.get('content-length') || '0');
const mimeType = response.headers.get('content-type') || 'application/octet-stream';
let fileData: {
contentText?: string;
contentBase64?: string;
} = {};
const isText = this.isLikelyTextFile(fileName, mimeType);
const isImage = mimeType.startsWith("image/");
if (isText) {
fileData.contentText = await response.text();
} else if (isImage && this.modelSupportsNonText) {
const arrayBuffer = await response.arrayBuffer();
const base64 = btoa(String.fromCharCode(...new Uint8Array(arrayBuffer)));
fileData.contentBase64 = base64;
}
context.turnData.metadata.attachedFiles!.push({
id: nanoid(),
source: "direct",
name: fileName,
type: mimeType,
size: fileSize,
...fileData,
});
} catch (error) {
console.error(`[FileControlModule] Error reading file ${filePath}:`, error);
}
}
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions