Spaces:
Runtime error
Runtime error
Thomas G. Lopes
commited on
Commit
·
bee7674
1
Parent(s):
893f195
file upload wip
Browse files
src/routes/canvas/chat-node.svelte
CHANGED
|
@@ -20,9 +20,12 @@
|
|
| 20 |
import ProviderPicker from "./provider-picker.svelte";
|
| 21 |
import { ElementSize } from "runed";
|
| 22 |
import { marked } from "marked";
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
type Props = Omit<NodeProps, "data"> & {
|
| 25 |
-
data: { query: string; response: string; modelId?: Model["id"]; provider?: string };
|
| 26 |
};
|
| 27 |
let { id, data }: Props = $props();
|
| 28 |
|
|
@@ -265,6 +268,25 @@
|
|
| 265 |
// Fallback: return original position with larger offset
|
| 266 |
return { x: x + 150, y: y + 150 };
|
| 267 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
</script>
|
| 269 |
|
| 270 |
<div
|
|
|
|
| 20 |
import ProviderPicker from "./provider-picker.svelte";
|
| 21 |
import { ElementSize } from "runed";
|
| 22 |
import { marked } from "marked";
|
| 23 |
+
import { images } from "$lib/state/images.svelte.js";
|
| 24 |
+
import { AsyncQueue } from "$lib/utils/queue.js";
|
| 25 |
+
import { FileUpload } from "melt/builders";
|
| 26 |
|
| 27 |
type Props = Omit<NodeProps, "data"> & {
|
| 28 |
+
data: { query: string; response: string; modelId?: Model["id"]; provider?: string; imageIds?: string[] };
|
| 29 |
};
|
| 30 |
let { id, data }: Props = $props();
|
| 31 |
|
|
|
|
| 268 |
// Fallback: return original position with larger offset
|
| 269 |
return { x: x + 150, y: y + 150 };
|
| 270 |
}
|
| 271 |
+
|
| 272 |
+
const fileQueue = new AsyncQueue();
|
| 273 |
+
const fileUpload = new FileUpload({
|
| 274 |
+
accept: "image/*",
|
| 275 |
+
multiple: true,
|
| 276 |
+
async onAccept(file) {
|
| 277 |
+
fileQueue.add(async () => {
|
| 278 |
+
const key = await images.upload(file);
|
| 279 |
+
|
| 280 |
+
const prev = data.imageIds ?? [];
|
| 281 |
+
await updateNodeData(id, { imageIds: [...prev, key] });
|
| 282 |
+
|
| 283 |
+
// We're dealing with files ourselves, so we don't want fileUpload to have any internal state,
|
| 284 |
+
// to avoid conflicts
|
| 285 |
+
if (fileQueue.queue.length <= 1) fileUpload.clear();
|
| 286 |
+
});
|
| 287 |
+
},
|
| 288 |
+
// TODO: disable on models that don't support img upload
|
| 289 |
+
});
|
| 290 |
</script>
|
| 291 |
|
| 292 |
<div
|