Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/elements/src/prompt-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ import {
// ============================================================================

export type AttachmentsContext = {
files: (FileUIPart & { id: string })[];
files: (FileUIPart & { id: string, file: File })[];
add: (files: File[] | FileList) => void;
remove: (id: string) => void;
clear: () => void;
Expand Down Expand Up @@ -151,7 +151,7 @@ export function PromptInputProvider({

// ----- attachments state (global when wrapped)
const [attachements, setAttachements] = useState<
(FileUIPart & { id: string })[]
(FileUIPart & { id: string, file: File })[]
>([]);
const fileInputRef = useRef<HTMLInputElement | null>(null);
const openRef = useRef<() => void>(() => {});
Expand All @@ -170,6 +170,7 @@ export function PromptInputProvider({
url: URL.createObjectURL(file),
mediaType: file.type,
filename: file.name,
file,
}))
)
);
Expand Down Expand Up @@ -471,7 +472,7 @@ export const PromptInput = ({
}, []);

// ----- Local attachments (only used when no provider)
const [items, setItems] = useState<(FileUIPart & { id: string })[]>([]);
const [items, setItems] = useState<(FileUIPart & { id: string; file: File })[]>([]);
const files = usingProvider ? controller.attachments.files : items;

const openFileDialogLocal = useCallback(() => {
Expand Down Expand Up @@ -527,14 +528,15 @@ export const PromptInput = ({
message: "Too many files. Some were not added.",
});
}
const next: (FileUIPart & { id: string })[] = [];
const next: (FileUIPart & { id: string, file: File })[] = [];
for (const file of capped) {
next.push({
id: nanoid(),
type: "file",
url: URL.createObjectURL(file),
mediaType: file.type,
filename: file.name,
file,
});
}
return prev.concat(next);
Expand Down