diff --git a/js/multimodaltextbox/shared/MultimodalTextbox.svelte b/js/multimodaltextbox/shared/MultimodalTextbox.svelte index 6a10fc5edb087..43dc342f8f72b 100644 --- a/js/multimodaltextbox/shared/MultimodalTextbox.svelte +++ b/js/multimodaltextbox/shared/MultimodalTextbox.svelte @@ -47,6 +47,7 @@ export let upload: Client["upload"]; export let stream_handler: Client["stream"]; export let file_count: "single" | "multiple" | "directory" = "multiple"; + export let max_text_length = 1000; let upload_component: Upload; let hidden_upload: HTMLInputElement; @@ -194,9 +195,23 @@ dispatch("submit"); } - function handle_paste(event: ClipboardEvent): void { + async function handle_paste(event: ClipboardEvent): Promise { if (!event.clipboardData) return; const items = event.clipboardData.items; + const text = event.clipboardData.getData("text"); + + if (text && text.length > max_text_length) { + event.preventDefault(); + const file = new window.File([text], "pasted_text.txt", { + type: "text/plain", + lastModified: Date.now() + }); + if (upload_component) { + upload_component.load_files([file]); + } + return; + } + for (let index in items) { const item = items[index]; if (item.kind === "file" && item.type.includes("image")) {