Skip to content

Commit fad2b83

Browse files
committed
fix(chat): validate marker file parts before rebuilding user message
1 parent 55f96d4 commit fad2b83

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

src/app/(app)/projects/[projectId]/chat/chat-client.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,19 @@ function isUserMessageMarker(data: unknown): data is UserMessageMarker {
154154
);
155155
}
156156

157+
function isFileUIPart(part: unknown): part is FileUIPart {
158+
if (!part || typeof part !== "object") return false;
159+
const value = part as Partial<FileUIPart>;
160+
const hasValidFilename =
161+
value.filename === undefined || typeof value.filename === "string";
162+
return (
163+
value.type === "file" &&
164+
typeof value.mediaType === "string" &&
165+
hasValidFilename &&
166+
typeof value.url === "string"
167+
);
168+
}
169+
157170
function ChatComposerAttachments() {
158171
const attachments = usePromptInputAttachments();
159172

@@ -222,7 +235,7 @@ function reconstructMessages(
222235
if (!seenUserMessageIds.has(marker.id)) {
223236
seenUserMessageIds.add(marker.id);
224237
const markerParts: AppUIMessage["parts"] = [
225-
...(marker.files ?? []),
238+
...(marker.files?.filter(isFileUIPart) ?? []),
226239
...(marker.content.length > 0
227240
? [{ text: marker.content, type: "text" as const }]
228241
: []),

0 commit comments

Comments
 (0)