Parcourir la source

fix(ui): label reverted attachments by mime

David Hill il y a 1 mois
Parent
commit
1594fb962f

+ 15 - 2
packages/app/src/pages/session.tsx

@@ -1324,9 +1324,22 @@ export default function Page() {
       attachmentName: language.t("common.attachment"),
     })
 
+  const tag = (mime: string | undefined) => {
+    if (mime === "application/pdf") return "pdf"
+    if (mime?.startsWith("image/")) return "image"
+    return "file"
+  }
+
+  const chip = (part: { filename: string; mime: string }) => `[${tag(part.mime)}:${part.filename}]`
+
   const line = (id: string) => {
     const text = draft(id)
-      .map((part) => (part.type === "image" ? `[image:${part.filename}]` : part.content))
+      .map((part) => {
+        if (part.type === "image") return chip(part)
+        if (part.type === "file") return `[file:${part.path}]`
+        if (part.type === "agent") return `@${part.name}`
+        return part.content
+      })
       .join("")
       .replace(/\s+/g, " ")
       .trim()
@@ -1394,7 +1407,7 @@ export default function Page() {
   const followupText = (item: FollowupDraft) => {
     const text = item.prompt
       .map((part) => {
-        if (part.type === "image") return `[image:${part.filename}]`
+        if (part.type === "image") return chip(part)
         if (part.type === "file") return `[file:${part.path}]`
         if (part.type === "agent") return `@${part.name}`
         return part.content

+ 9 - 1
packages/app/src/pages/session/composer/session-composer-region.tsx

@@ -46,6 +46,14 @@ export function SessionComposerRegion(props: {
   const language = useLanguage()
   const route = useSessionKey()
 
+  const tag = (mime: string) => {
+    if (mime === "application/pdf") return "pdf"
+    if (mime.startsWith("image/")) return "image"
+    return "file"
+  }
+
+  const chip = (part: { filename: string; mime: string }) => `[${tag(part.mime)}:${part.filename}]`
+
   const handoffPrompt = createMemo(() => getSessionHandoff(route.sessionKey())?.prompt)
 
   const previewPrompt = () =>
@@ -54,7 +62,7 @@ export function SessionComposerRegion(props: {
       .map((part) => {
         if (part.type === "file") return `[file:${part.path}]`
         if (part.type === "agent") return `@${part.name}`
-        if (part.type === "image") return `[image:${part.filename}]`
+        if (part.type === "image") return chip(part)
         return part.content
       })
       .join("")