@marimo-team/islands 0.25.3-dev402 → 0.25.3-dev408

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/{ConnectedDataExplorerComponent-1DGGwl88.js → ConnectedDataExplorerComponent-DCW4bXq-.js} +1 -1
  2. package/dist/{ErrorBoundary-DfbzIKA3.js → ErrorBoundary-W6a-7ong.js} +1 -1
  3. package/dist/{chat-ui-r3PPIMn0.js → chat-ui-BGEXB6V4.js} +1354 -1320
  4. package/dist/{code-visibility-CXijswY7.js → code-visibility-0v5rL9iu.js} +1 -1
  5. package/dist/{common-Cm5ENbUw.js → common-B7sS0asw.js} +1 -1
  6. package/dist/{data-grid-overlay-editor-Dv0TkGKt.js → data-grid-overlay-editor-DtWpYC-j.js} +1 -1
  7. package/dist/{feedback-button-Xk-mOev4.js → feedback-button-KVSGwnVr.js} +2 -2
  8. package/dist/{glide-data-editor-DdxBDWAj.js → glide-data-editor-D0dykzDr.js} +3 -3
  9. package/dist/{globals-DR3VVkF6.js → globals-DOi11Nup.js} +1 -1
  10. package/dist/main.js +6160 -6141
  11. package/dist/{number-overlay-editor-Cc5gJryh.js → number-overlay-editor-DoR-BTMn.js} +1 -1
  12. package/dist/{process-output-39KkAXSF.js → process-output-BvCDoG-m.js} +14 -25
  13. package/dist/{reveal-component-Dm5K9KPi.js → reveal-component-Vu8VncD4.js} +2 -2
  14. package/dist/{spec-Ww0JjShW.js → spec-DV8oNpRR.js} +46 -49
  15. package/dist/{semaphore-8KhQouXt.js → useDeepCompareMemoize-C90a6_io.js} +15 -5
  16. package/dist/{vega-component-DQZhTzVQ.js → vega-component-ArEoBGzQ.js} +197 -198
  17. package/package.json +1 -1
  18. package/src/components/chat/__tests__/chat-utils.test.ts +48 -0
  19. package/src/components/chat/__tests__/message-queue.test.tsx +94 -1
  20. package/src/components/chat/__tests__/pending-chat-prompt.test.tsx +568 -0
  21. package/src/components/chat/__tests__/useFileState.test.tsx +176 -15
  22. package/src/components/chat/chat-components.tsx +3 -2
  23. package/src/components/chat/chat-panel.tsx +199 -74
  24. package/src/components/chat/chat-utils.ts +148 -34
  25. package/src/components/chat/user-message.tsx +15 -6
  26. package/src/components/data-table/charts/__tests__/altair-generator.test.ts +42 -27
  27. package/src/components/data-table/charts/chart-spec/altair-generator.ts +2 -6
  28. package/src/core/ai/__tests__/attachments.test.ts +153 -0
  29. package/src/core/ai/attachments.ts +80 -0
  30. package/src/utils/python-poet/poet.ts +12 -2
  31. package/dist/useDeepCompareMemoize-Bvrue1iy.js +0 -11
@@ -4,7 +4,7 @@ import { act, renderHook } from "@testing-library/react";
4
4
  import { beforeEach, describe, expect, it, vi } from "vitest";
5
5
  import { MockModules } from "@/__mocks__/common";
6
6
  import { toast } from "@/components/ui/use-toast";
7
- import { useFileState } from "../chat-utils";
7
+ import { convertToFileUIPart, useFileState } from "../chat-utils";
8
8
 
9
9
  vi.mock("@/components/ui/use-toast", () => MockModules.toast());
10
10
 
@@ -18,46 +18,46 @@ describe("useFileState", () => {
18
18
  expect(result.current.files).toEqual([]);
19
19
  });
20
20
 
21
- it("adds files when under size limit", () => {
21
+ it("adds files when under size limit", async () => {
22
22
  const { result } = renderHook(() => useFileState());
23
23
  const fileA = { name: "a.txt", size: 10 } as File;
24
24
  const fileB = { name: "b.txt", size: 20 } as File;
25
25
 
26
- act(() => result.current.addFiles([fileA, fileB]));
26
+ await act(() => result.current.addFiles([fileA, fileB]));
27
27
 
28
28
  expect(result.current.files).toEqual([fileA, fileB]);
29
29
  expect(toast).not.toHaveBeenCalled();
30
30
  });
31
31
 
32
- it("appends new files to existing files", () => {
32
+ it("appends new files to existing files", async () => {
33
33
  const { result } = renderHook(() => useFileState());
34
34
  const fileA = { name: "a.txt", size: 10 } as File;
35
35
  const fileB = { name: "b.txt", size: 20 } as File;
36
36
 
37
- act(() => result.current.addFiles([fileA]));
38
- act(() => result.current.addFiles([fileB]));
37
+ await act(() => result.current.addFiles([fileA]));
38
+ await act(() => result.current.addFiles([fileB]));
39
39
 
40
40
  expect(result.current.files).toEqual([fileA, fileB]);
41
41
  });
42
42
 
43
- it("ignores empty file list", () => {
43
+ it("ignores empty file list", async () => {
44
44
  const { result } = renderHook(() => useFileState());
45
45
  const fileA = { name: "a.txt", size: 10 } as File;
46
46
 
47
- act(() => result.current.addFiles([fileA]));
48
- act(() => result.current.addFiles([]));
47
+ await act(() => result.current.addFiles([fileA]));
48
+ await act(() => result.current.addFiles([]));
49
49
 
50
50
  expect(result.current.files).toEqual([fileA]);
51
51
  });
52
52
 
53
- it("shows toast and skips adding when size exceeds limit", () => {
53
+ it("shows toast and skips adding when size exceeds limit", async () => {
54
54
  const { result } = renderHook(() => useFileState());
55
55
  const bigFile = {
56
56
  name: "big.txt",
57
57
  size: 1024 * 1024 * 50 + 1, // > 50MB
58
58
  } as File;
59
59
 
60
- act(() => result.current.addFiles([bigFile]));
60
+ await act(() => result.current.addFiles([bigFile]));
61
61
 
62
62
  expect(result.current.files).toEqual([]);
63
63
  expect(toast).toHaveBeenCalledWith({
@@ -67,26 +67,187 @@ describe("useFileState", () => {
67
67
  });
68
68
  });
69
69
 
70
- it("removes a file", () => {
70
+ it("removes a file", async () => {
71
71
  const { result } = renderHook(() => useFileState());
72
72
  const fileA = { name: "a.txt", size: 10 } as File;
73
73
  const fileB = { name: "b.txt", size: 20 } as File;
74
74
 
75
- act(() => result.current.addFiles([fileA, fileB]));
75
+ await act(() => result.current.addFiles([fileA, fileB]));
76
76
  act(() => result.current.removeFile(fileA));
77
77
 
78
78
  expect(result.current.files).toEqual([fileB]);
79
79
  });
80
80
 
81
- it("clears all files", () => {
81
+ it("clears all files", async () => {
82
82
  const { result } = renderHook(() => useFileState());
83
83
  const fileA = { name: "a.txt", size: 10 } as File;
84
84
  const fileB = { name: "b.txt", size: 20 } as File;
85
85
 
86
- act(() => result.current.addFiles([fileA, fileB]));
86
+ await act(() => result.current.addFiles([fileA, fileB]));
87
87
  expect(result.current.files).toEqual([fileA, fileB]);
88
88
 
89
89
  act(() => result.current.clearFiles());
90
90
  expect(result.current.files).toEqual([]);
91
91
  });
92
+
93
+ it("rejects files outside the selected model's input types", async () => {
94
+ const { result } = renderHook(() => useFileState(["text/*"]));
95
+ const image = new File(["image"], "chart.png", { type: "image/png" });
96
+
97
+ await act(() => result.current.addFiles([image]));
98
+
99
+ expect(result.current.files).toEqual([]);
100
+ expect(toast).toHaveBeenCalledWith({
101
+ title: "Unsupported attachment",
102
+ description:
103
+ "These files are not supported by the selected model: chart.png",
104
+ variant: "danger",
105
+ });
106
+ });
107
+
108
+ it.each([
109
+ ["application/toml", "pyproject.toml"],
110
+ ["application/xml", "data.xml"],
111
+ ["application/x-yaml", "config.yml"],
112
+ ["application/vnd.example+json", "data.json"],
113
+ ["application/javascript", "script.js"],
114
+ ["application/x-ndjson", "data.ndjson"],
115
+ ["", "script.py"],
116
+ ["application/octet-stream", "config.yaml"],
117
+ ["", "README"],
118
+ ["application/octet-stream", "file.unlisted-extension"],
119
+ ])("accepts and serializes textual files: %s, %s", async (type, name) => {
120
+ const { result } = renderHook(() => useFileState(["text/*"]));
121
+ const file = new File(["hello"], name, { type });
122
+
123
+ await act(() => result.current.addFiles([file]));
124
+
125
+ expect(
126
+ result.current.files.map((file) => ({
127
+ name: file.name,
128
+ type: file.type,
129
+ })),
130
+ ).toEqual([{ name, type: "text/plain" }]);
131
+ expect(await convertToFileUIPart(result.current.files)).toEqual([
132
+ {
133
+ type: "file",
134
+ mediaType: "text/plain",
135
+ filename: name,
136
+ url: "data:text/plain;base64,aGVsbG8=",
137
+ },
138
+ ]);
139
+ expect(toast).not.toHaveBeenCalled();
140
+ });
141
+
142
+ it("revalidates pending files after switching models without losing them", async () => {
143
+ const { result, rerender } = renderHook(
144
+ ({ types }) => useFileState(types),
145
+ { initialProps: { types: ["text/*", "image/png"] } },
146
+ );
147
+ const image = new File(["image"], "chart.png", { type: "image/png" });
148
+ await act(() => result.current.addFiles([image]));
149
+
150
+ rerender({ types: ["text/*"] });
151
+
152
+ expect(result.current.validateFiles(result.current.files)).toBe(false);
153
+ expect(result.current.files).toEqual([image]);
154
+ });
155
+
156
+ it("rejects binary files with missing MIME metadata", async () => {
157
+ const { result } = renderHook(() => useFileState(["text/*"]));
158
+ const file = new File([new Uint8Array([0, 255])], "README");
159
+
160
+ await act(() => result.current.addFiles([file]));
161
+
162
+ expect(result.current.files).toEqual([]);
163
+ expect(toast).toHaveBeenCalledWith(
164
+ expect.objectContaining({ title: "Unsupported attachment" }),
165
+ );
166
+ });
167
+
168
+ it("discards pending reads when files are cleared", async () => {
169
+ const { result } = renderHook(() => useFileState(["text/*"]));
170
+ const file = new File(["hello"], "README");
171
+ const read = Promise.withResolvers<ArrayBuffer>();
172
+ vi.spyOn(file, "arrayBuffer").mockReturnValue(read.promise);
173
+ const adding = result.current.addFiles([file]);
174
+
175
+ act(() => result.current.clearFiles());
176
+ await act(async () => {
177
+ read.resolve(new TextEncoder().encode("hello").buffer);
178
+ await adding;
179
+ });
180
+
181
+ expect(result.current.files).toEqual([]);
182
+ expect(toast).not.toHaveBeenCalled();
183
+ });
184
+
185
+ it("reports failures when serializing an attachment", async () => {
186
+ const read = vi
187
+ .spyOn(FileReader.prototype, "readAsDataURL")
188
+ .mockImplementation(function (this: FileReader) {
189
+ this.dispatchEvent(new Event("error"));
190
+ });
191
+ try {
192
+ await expect(
193
+ convertToFileUIPart([
194
+ new File(["hello"], "notes.txt", { type: "text/plain" }),
195
+ ]),
196
+ ).rejects.toThrow("Failed to read blob: error");
197
+ } finally {
198
+ read.mockRestore();
199
+ }
200
+ });
201
+
202
+ it("allows selecting files again after normalization fails", async () => {
203
+ const { result } = renderHook(() => useFileState(["text/*"]));
204
+ const file = new File(["hello"], "README");
205
+ vi.spyOn(file, "arrayBuffer").mockRejectedValue(new Error("Read failed"));
206
+
207
+ await act(() => result.current.addFiles([file]));
208
+
209
+ expect(result.current.isReadingFiles).toBe(false);
210
+ expect(result.current.files).toEqual([]);
211
+ expect(result.current.validateFiles([])).toBe(true);
212
+ expect(toast).toHaveBeenCalledWith({
213
+ title: "Could not read attachments",
214
+ description: "Try selecting the files again.",
215
+ variant: "danger",
216
+ });
217
+
218
+ const retry = new File(["hello"], "notes.txt", { type: "text/plain" });
219
+ await act(() => result.current.addFiles([retry]));
220
+ expect(result.current.files).toEqual([retry]);
221
+ });
222
+
223
+ it("keeps new reads pending when a cancelled read finishes", async () => {
224
+ const { result } = renderHook(() => useFileState(["text/*"]));
225
+ const oldFile = new File(["old"], "old");
226
+ const newFile = new File(["new"], "new");
227
+ const oldRead = Promise.withResolvers<ArrayBuffer>();
228
+ const newRead = Promise.withResolvers<ArrayBuffer>();
229
+ vi.spyOn(oldFile, "arrayBuffer").mockReturnValue(oldRead.promise);
230
+ vi.spyOn(newFile, "arrayBuffer").mockReturnValue(newRead.promise);
231
+ let addingOld: Promise<void>;
232
+ act(() => {
233
+ addingOld = result.current.addFiles([oldFile]);
234
+ });
235
+ act(() => result.current.clearFiles());
236
+ let addingNew: Promise<void>;
237
+ act(() => {
238
+ addingNew = result.current.addFiles([newFile]);
239
+ });
240
+ await act(async () => {
241
+ oldRead.resolve(new TextEncoder().encode("old").buffer);
242
+ await addingOld;
243
+ });
244
+ expect(result.current.isReadingFiles).toBe(true);
245
+ expect(result.current.validateFiles([])).toBe(false);
246
+ await act(async () => {
247
+ newRead.resolve(new TextEncoder().encode("new").buffer);
248
+ await addingNew;
249
+ });
250
+ expect(result.current.isReadingFiles).toBe(false);
251
+ expect(result.current.files.map((file) => file.name)).toEqual(["new"]);
252
+ });
92
253
  });
@@ -18,7 +18,6 @@ import { Spinner } from "../icons/spinner";
18
18
  import { Button } from "../ui/button";
19
19
  import { Input } from "../ui/input";
20
20
  import { Tooltip } from "../ui/tooltip";
21
- import { SUPPORTED_ATTACHMENT_TYPES } from "./chat-utils";
22
21
 
23
22
  export const AttachmentRenderer = ({
24
23
  attachment,
@@ -142,10 +141,12 @@ export const AttachFileButton = ({
142
141
  fileInputRef,
143
142
  isLoading,
144
143
  onAddFiles,
144
+ accept = "image/*,text/*",
145
145
  }: {
146
146
  fileInputRef: React.RefObject<HTMLInputElement | null>;
147
147
  isLoading: boolean;
148
148
  onAddFiles: (files: File[]) => void;
149
+ accept?: string;
149
150
  }) => {
150
151
  return (
151
152
  <>
@@ -171,7 +172,7 @@ export const AttachFileButton = ({
171
172
  onAddFiles([...event.target.files]);
172
173
  }
173
174
  }}
174
- accept={SUPPORTED_ATTACHMENT_TYPES.join(",")}
175
+ accept={accept}
175
176
  />
176
177
  </>
177
178
  );