From 79fe1c4b7b0fa51f1208ca402703ec05399e5c6e Mon Sep 17 00:00:00 2001 From: Shantur Rathore Date: Fri, 24 Oct 2025 00:55:20 +0100 Subject: [PATCH] Convert file paths to file:// URLs for server compatibility --- src/components/prompt-input.tsx | 4 ++-- src/types/attachment.ts | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/prompt-input.tsx b/src/components/prompt-input.tsx index 05220355..2fd69113 100644 --- a/src/components/prompt-input.tsx +++ b/src/components/prompt-input.tsx @@ -166,7 +166,7 @@ export default function PromptInput(props: PromptInputProps) { const alreadyAttached = existingAttachments.some((att) => att.source.type === "file" && att.source.path === path) if (!alreadyAttached) { - const attachment = createFileAttachment(path, filename) + const attachment = createFileAttachment(path, filename, "text/plain", undefined, props.instanceFolder) addAttachment(props.instanceId, props.sessionId, attachment) } @@ -237,7 +237,7 @@ export default function PromptInput(props: PromptInputProps) { const filename = file.name const mime = file.type || "text/plain" - const attachment = createFileAttachment(path, filename, mime) + const attachment = createFileAttachment(path, filename, mime, undefined, props.instanceFolder) addAttachment(props.instanceId, props.sessionId, attachment) } diff --git a/src/types/attachment.ts b/src/types/attachment.ts index f087b7cc..ce15cb04 100644 --- a/src/types/attachment.ts +++ b/src/types/attachment.ts @@ -52,12 +52,21 @@ export function createFileAttachment( filename: string, mime: string = "text/plain", data?: Uint8Array, + workspaceRoot?: string, ): Attachment { + let fileUrl = path + if (workspaceRoot && !path.startsWith("file://")) { + const absolutePath = path.startsWith("/") ? path : `${workspaceRoot}/${path}` + fileUrl = `file://${absolutePath}` + } else if (!path.startsWith("file://") && path.startsWith("/")) { + fileUrl = `file://${path}` + } + return { id: crypto.randomUUID(), type: "file", display: `@${filename}`, - url: path, + url: fileUrl, filename, mediaType: mime, source: {