fix: image handling in context
This commit is contained in:
parent
ba7a1dcc2c
commit
06dadf3a0b
@ -201,7 +201,8 @@ export default function ChatMessage({
|
|||||||
|
|
||||||
// Parse context to tabs for context tabs component
|
// Parse context to tabs for context tabs component
|
||||||
function parseContextToTabs(context: string) {
|
function parseContextToTabs(context: string) {
|
||||||
const sections = context.split(/(?=File |Code from )/)
|
// Use specific regex patterns to avoid matching import statements
|
||||||
|
const sections = context.split(/(?=File |Code from |Image \d{1,2}:)/)
|
||||||
return sections
|
return sections
|
||||||
.map((section, index) => {
|
.map((section, index) => {
|
||||||
const lines = section.trim().split("\n")
|
const lines = section.trim().split("\n")
|
||||||
@ -211,16 +212,29 @@ function parseContextToTabs(context: string) {
|
|||||||
// Remove code block markers for display
|
// Remove code block markers for display
|
||||||
content = content.replace(/^```[\w-]*\n/, "").replace(/\n```$/, "")
|
content = content.replace(/^```[\w-]*\n/, "").replace(/\n```$/, "")
|
||||||
|
|
||||||
// Determine if the context is a file or code
|
// Determine the type of context
|
||||||
const isFile = titleLine.startsWith("File ")
|
const isFile = titleLine.startsWith("File ")
|
||||||
const name = titleLine.replace(/^(File |Code from )/, "").replace(":", "")
|
const isImage = titleLine.startsWith("Image ")
|
||||||
|
const type = isFile ? "file" : isImage ? "image" : "code"
|
||||||
|
const name = titleLine
|
||||||
|
.replace(/^(File |Code from |Image )/, "")
|
||||||
|
.replace(":", "")
|
||||||
|
.trim()
|
||||||
|
|
||||||
|
// Skip if the content is empty or if it's just an import statement
|
||||||
|
if (!content || content.trim().startsWith('from "')) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: `context-${index}`,
|
id: `context-${index}`,
|
||||||
type: isFile ? ("file" as const) : ("code" as const),
|
type: type as "file" | "code" | "image",
|
||||||
name: name,
|
name: name,
|
||||||
content: content,
|
content: content,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.filter((tab) => tab.content.length > 0)
|
.filter(
|
||||||
|
(tab): tab is NonNullable<typeof tab> =>
|
||||||
|
tab !== null && tab.content.length > 0
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
@ -125,6 +125,8 @@ export default function AIChat({
|
|||||||
} else if (tab.type === "code") {
|
} else if (tab.type === "code") {
|
||||||
const cleanContent = formatCodeContent(tab.content)
|
const cleanContent = formatCodeContent(tab.content)
|
||||||
return `Code from ${tab.name}:\n\`\`\`typescript\n${cleanContent}\n\`\`\``
|
return `Code from ${tab.name}:\n\`\`\`typescript\n${cleanContent}\n\`\`\``
|
||||||
|
} else if (tab.type === "image") {
|
||||||
|
return `Image ${tab.name}:\n${tab.content}`
|
||||||
}
|
}
|
||||||
return `${tab.name}:\n${tab.content}`
|
return `${tab.name}:\n${tab.content}`
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user