Convert file paths to file:// URLs for server compatibility
This commit is contained in:
@@ -166,7 +166,7 @@ export default function PromptInput(props: PromptInputProps) {
|
|||||||
const alreadyAttached = existingAttachments.some((att) => att.source.type === "file" && att.source.path === path)
|
const alreadyAttached = existingAttachments.some((att) => att.source.type === "file" && att.source.path === path)
|
||||||
|
|
||||||
if (!alreadyAttached) {
|
if (!alreadyAttached) {
|
||||||
const attachment = createFileAttachment(path, filename)
|
const attachment = createFileAttachment(path, filename, "text/plain", undefined, props.instanceFolder)
|
||||||
addAttachment(props.instanceId, props.sessionId, attachment)
|
addAttachment(props.instanceId, props.sessionId, attachment)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,7 +237,7 @@ export default function PromptInput(props: PromptInputProps) {
|
|||||||
const filename = file.name
|
const filename = file.name
|
||||||
const mime = file.type || "text/plain"
|
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)
|
addAttachment(props.instanceId, props.sessionId, attachment)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,12 +52,21 @@ export function createFileAttachment(
|
|||||||
filename: string,
|
filename: string,
|
||||||
mime: string = "text/plain",
|
mime: string = "text/plain",
|
||||||
data?: Uint8Array,
|
data?: Uint8Array,
|
||||||
|
workspaceRoot?: string,
|
||||||
): Attachment {
|
): 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 {
|
return {
|
||||||
id: crypto.randomUUID(),
|
id: crypto.randomUUID(),
|
||||||
type: "file",
|
type: "file",
|
||||||
display: `@${filename}`,
|
display: `@${filename}`,
|
||||||
url: path,
|
url: fileUrl,
|
||||||
filename,
|
filename,
|
||||||
mediaType: mime,
|
mediaType: mime,
|
||||||
source: {
|
source: {
|
||||||
|
|||||||
Reference in New Issue
Block a user