@marimo-team/islands 0.23.9-dev13 → 0.23.9-dev17

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 (33) hide show
  1. package/dist/{ConnectedDataExplorerComponent-DFQ1yVhp.js → ConnectedDataExplorerComponent-DSyAzzpW.js} +4 -4
  2. package/dist/assets/__vite-browser-external-Ddfz4Fpd.js +1 -0
  3. package/dist/assets/{worker-CpBbwbQo.js → worker-CgL6N0XX.js} +2 -2
  4. package/dist/{chat-ui-xfKWgbtB.js → chat-ui-s5fKbcIr.js} +3061 -3034
  5. package/dist/{code-visibility-DjGqscP3.js → code-visibility-Bx9sVDMN.js} +8 -8
  6. package/dist/{formats-BHOojBDG.js → formats-BiH6HX1V.js} +1 -1
  7. package/dist/{glide-data-editor-CpzEdx8N.js → glide-data-editor-Ck-MRdns.js} +2 -2
  8. package/dist/{html-to-image-DjEqYaQd.js → html-to-image-CTU_-PnW.js} +5 -5
  9. package/dist/{input-DBDlwwuD.js → input-BwcGY_X1.js} +1 -1
  10. package/dist/main.js +24 -31
  11. package/dist/{mermaid-D00onudG.js → mermaid-YK4c8MNC.js} +2 -2
  12. package/dist/{process-output-Cz6wQSkL.js → process-output-CVDHJqo6.js} +33 -25
  13. package/dist/{reveal-component-Dins3DMl.js → reveal-component-2Yl05c4Y.js} +5 -5
  14. package/dist/{spec-BQbOvWbq.js → spec-CyLiCjSf.js} +1 -1
  15. package/dist/{toDate-DqrFDZlc.js → toDate-DNWCUEQp.js} +1 -1
  16. package/dist/{useAsyncData-4lY05iWF.js → useAsyncData-xWFWzCee.js} +1 -1
  17. package/dist/{useDeepCompareMemoize-C5Zu9gK6.js → useDeepCompareMemoize-DSChED4g.js} +1 -1
  18. package/dist/{useLifecycle-YLdDriVo.js → useLifecycle-B81PFEja.js} +1 -1
  19. package/dist/{useTheme-u3PW8S24.js → useTheme-EmVyK9N9.js} +1 -0
  20. package/dist/{vega-component-CdQu2ErN.js → vega-component-BCunE3-9.js} +5 -5
  21. package/package.json +1 -1
  22. package/src/components/app-config/user-config-form.tsx +36 -0
  23. package/src/components/chat/__tests__/chat-utils.test.ts +269 -0
  24. package/src/components/chat/chat-utils.ts +14 -58
  25. package/src/core/codemirror/__tests__/setup.test.ts +29 -0
  26. package/src/core/codemirror/cm.ts +3 -2
  27. package/src/core/config/__tests__/config-schema.test.ts +2 -0
  28. package/src/core/config/config-schema.ts +1 -0
  29. package/src/plugins/impl/chat/ChatPlugin.tsx +7 -1
  30. package/src/plugins/impl/chat/__tests__/chat-ui.test.ts +278 -0
  31. package/src/plugins/impl/chat/chat-ui.tsx +106 -59
  32. package/src/plugins/impl/chat/types.ts +5 -0
  33. package/dist/assets/__vite-browser-external-CAdMKBac.js +0 -1
@@ -503,6 +503,42 @@ export const UserConfigForm: React.FC = () => {
503
503
  </div>
504
504
  )}
505
505
  />
506
+ <FormField
507
+ control={form.control}
508
+ name="completion.auto_close_pairs"
509
+ render={({ field }) => (
510
+ <div className="flex flex-col space-y-1">
511
+ <FormItem className={formItemClasses}>
512
+ <FormLabel className="font-normal">
513
+ Auto-close pairs
514
+ </FormLabel>
515
+ <FormControl>
516
+ <Checkbox
517
+ data-testid="auto-close-pairs-checkbox"
518
+ checked={field.value ?? true}
519
+ disabled={field.disabled}
520
+ onCheckedChange={(checked) => {
521
+ field.onChange(Boolean(checked));
522
+ }}
523
+ />
524
+ </FormControl>
525
+ <FormMessage />
526
+ <IsOverridden
527
+ userConfig={config}
528
+ name="completion.auto_close_pairs"
529
+ />
530
+ </FormItem>
531
+ <FormDescription>
532
+ Automatically insert closing brackets{" "}
533
+ <code className="text-xs">{"()"}</code>,{" "}
534
+ <code className="text-xs">{"[]"}</code>,{" "}
535
+ <code className="text-xs">{"{}"}</code>, and quotes{" "}
536
+ <code className="text-xs">{`""`}</code>,{" "}
537
+ <code className="text-xs">{`''`}</code> when opening one.
538
+ </FormDescription>
539
+ </div>
540
+ )}
541
+ />
506
542
  </SettingGroup>
507
543
  <SettingGroup title="Language Servers">
508
544
  <FormDescription>
@@ -0,0 +1,269 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import type { UIMessage } from "ai";
4
+ import { describe, expect, it } from "vitest";
5
+ import { hasPendingToolCalls } from "../chat-utils";
6
+
7
+ /**
8
+ * `hasPendingToolCalls` powers `sendAutomaticallyWhen` in `mo.ui.chat`:
9
+ * returns true only when the last assistant message *ends* with a tool
10
+ * call in a ready-to-round-trip state. Any trailing non-tool part (text,
11
+ * file, source-*, reasoning, data-*, new step-start) means the assistant
12
+ * has already answered and we leave the next turn to the user. The
13
+ * approval flow relies on this firing for `approval-responded`.
14
+ */
15
+
16
+ const userMessage = (text: string): UIMessage => ({
17
+ id: `user-${text}`,
18
+ role: "user",
19
+ parts: [{ type: "text", text }],
20
+ });
21
+
22
+ const assistantToolMessage = (
23
+ parts: UIMessage["parts"],
24
+ id = "assistant-1",
25
+ ): UIMessage => ({
26
+ id,
27
+ role: "assistant",
28
+ parts,
29
+ });
30
+
31
+ describe("hasPendingToolCalls", () => {
32
+ it("returns false when there are no messages", () => {
33
+ expect(hasPendingToolCalls([])).toBe(false);
34
+ });
35
+
36
+ it("returns false when the last message is a user message", () => {
37
+ expect(hasPendingToolCalls([userMessage("hi")])).toBe(false);
38
+ });
39
+
40
+ it("returns false when the last assistant message has no tool parts", () => {
41
+ expect(
42
+ hasPendingToolCalls([
43
+ userMessage("hi"),
44
+ assistantToolMessage([{ type: "text", text: "hello!" }]),
45
+ ]),
46
+ ).toBe(false);
47
+ });
48
+
49
+ it("returns false while a tool is still streaming or awaiting approval", () => {
50
+ expect(
51
+ hasPendingToolCalls([
52
+ userMessage("delete it"),
53
+ assistantToolMessage([
54
+ {
55
+ type: "tool-delete_file",
56
+ toolCallId: "call-1",
57
+ state: "approval-requested",
58
+ input: { path: "secrets.env" },
59
+ approval: { id: "approval-1" },
60
+ } as unknown as UIMessage["parts"][number],
61
+ ]),
62
+ ]),
63
+ ).toBe(false);
64
+ });
65
+
66
+ it("returns true when the user has responded to an approval request", () => {
67
+ // The chat must auto-resume as soon as Approve/Deny is clicked.
68
+ expect(
69
+ hasPendingToolCalls([
70
+ userMessage("delete it"),
71
+ assistantToolMessage([
72
+ {
73
+ type: "tool-delete_file",
74
+ toolCallId: "call-1",
75
+ state: "approval-responded",
76
+ input: { path: "secrets.env" },
77
+ approval: { id: "approval-1", approved: true },
78
+ } as unknown as UIMessage["parts"][number],
79
+ ]),
80
+ ]),
81
+ ).toBe(true);
82
+ });
83
+
84
+ it("returns true when a tool reached a terminal output state", () => {
85
+ expect(
86
+ hasPendingToolCalls([
87
+ userMessage("run it"),
88
+ assistantToolMessage([
89
+ {
90
+ type: "tool-run_query",
91
+ toolCallId: "call-1",
92
+ state: "output-available",
93
+ input: { sql: "select 1" },
94
+ output: 1,
95
+ } as unknown as UIMessage["parts"][number],
96
+ ]),
97
+ ]),
98
+ ).toBe(true);
99
+ });
100
+
101
+ it("returns false when only some tool calls are ready", () => {
102
+ expect(
103
+ hasPendingToolCalls([
104
+ userMessage("two things"),
105
+ assistantToolMessage([
106
+ {
107
+ type: "tool-first",
108
+ toolCallId: "call-1",
109
+ state: "output-available",
110
+ input: {},
111
+ output: 1,
112
+ } as unknown as UIMessage["parts"][number],
113
+ {
114
+ type: "tool-second",
115
+ toolCallId: "call-2",
116
+ state: "input-available",
117
+ input: {},
118
+ } as unknown as UIMessage["parts"][number],
119
+ ]),
120
+ ]),
121
+ ).toBe(false);
122
+ });
123
+
124
+ it("returns false once the assistant has appended text after the tool result", () => {
125
+ expect(
126
+ hasPendingToolCalls([
127
+ userMessage("run it"),
128
+ assistantToolMessage([
129
+ {
130
+ type: "tool-run_query",
131
+ toolCallId: "call-1",
132
+ state: "output-available",
133
+ input: {},
134
+ output: 1,
135
+ } as unknown as UIMessage["parts"][number],
136
+ { type: "text", text: "The query returned 1." },
137
+ ]),
138
+ ]),
139
+ ).toBe(false);
140
+ });
141
+
142
+ it("returns false when a file part trails the completed tool call", () => {
143
+ // Regression: tool → text → file used to loop because only trailing
144
+ // text counted as "the assistant has answered".
145
+ expect(
146
+ hasPendingToolCalls([
147
+ userMessage("show me Starry Night"),
148
+ assistantToolMessage([
149
+ { type: "step-start" },
150
+ {
151
+ type: "tool-search_artwork",
152
+ toolCallId: "call-1",
153
+ state: "output-available",
154
+ input: { artist: "Van Gogh" },
155
+ output: { title: "The Starry Night" },
156
+ } as unknown as UIMessage["parts"][number],
157
+ { type: "text", text: "Here is the painting:" },
158
+ {
159
+ type: "file",
160
+ mediaType: "image/jpeg",
161
+ url: "https://example.com/starry-night.jpg",
162
+ } as unknown as UIMessage["parts"][number],
163
+ ]),
164
+ ]),
165
+ ).toBe(false);
166
+ });
167
+
168
+ it("returns false when a source-url part trails the completed tool call", () => {
169
+ expect(
170
+ hasPendingToolCalls([
171
+ userMessage("cite your sources"),
172
+ assistantToolMessage([
173
+ {
174
+ type: "tool-web_search",
175
+ toolCallId: "call-1",
176
+ state: "output-available",
177
+ input: { q: "marimo notebook" },
178
+ output: "found",
179
+ } as unknown as UIMessage["parts"][number],
180
+ { type: "text", text: "marimo is a reactive notebook." },
181
+ {
182
+ type: "source-url",
183
+ sourceId: "src-1",
184
+ url: "https://marimo.io",
185
+ } as unknown as UIMessage["parts"][number],
186
+ ]),
187
+ ]),
188
+ ).toBe(false);
189
+ });
190
+
191
+ it("returns false when a reasoning part trails the completed tool call", () => {
192
+ expect(
193
+ hasPendingToolCalls([
194
+ userMessage("explain"),
195
+ assistantToolMessage([
196
+ {
197
+ type: "tool-lookup",
198
+ toolCallId: "call-1",
199
+ state: "output-available",
200
+ input: {},
201
+ output: 1,
202
+ } as unknown as UIMessage["parts"][number],
203
+ {
204
+ type: "reasoning",
205
+ text: "Now I'll summarize.",
206
+ } as unknown as UIMessage["parts"][number],
207
+ ]),
208
+ ]),
209
+ ).toBe(false);
210
+ });
211
+
212
+ it("returns false when a new step-start follows the completed tool call", () => {
213
+ expect(
214
+ hasPendingToolCalls([
215
+ userMessage("multi-step"),
216
+ assistantToolMessage([
217
+ { type: "step-start" },
218
+ {
219
+ type: "tool-run_query",
220
+ toolCallId: "call-1",
221
+ state: "output-available",
222
+ input: {},
223
+ output: 1,
224
+ } as unknown as UIMessage["parts"][number],
225
+ { type: "step-start" },
226
+ ]),
227
+ ]),
228
+ ).toBe(false);
229
+ });
230
+
231
+ it("ignores providerExecuted tools", () => {
232
+ // Provider-side tools are resolved by the model, not the runtime, so
233
+ // they must not drive an auto-resume.
234
+ expect(
235
+ hasPendingToolCalls([
236
+ userMessage("hi"),
237
+ assistantToolMessage([
238
+ {
239
+ type: "tool-web_search",
240
+ toolCallId: "call-1",
241
+ state: "output-available",
242
+ input: {},
243
+ output: 1,
244
+ providerExecuted: true,
245
+ } as unknown as UIMessage["parts"][number],
246
+ ]),
247
+ ]),
248
+ ).toBe(false);
249
+ });
250
+
251
+ it("returns true for dynamic-tool parts in a terminal state", () => {
252
+ // `dynamic-tool` parts must drive auto-resume alongside `tool-*`.
253
+ expect(
254
+ hasPendingToolCalls([
255
+ userMessage("run it"),
256
+ assistantToolMessage([
257
+ {
258
+ type: "dynamic-tool",
259
+ toolName: "run_query",
260
+ toolCallId: "call-1",
261
+ state: "output-available",
262
+ input: {},
263
+ output: 1,
264
+ } as unknown as UIMessage["parts"][number],
265
+ ]),
266
+ ]),
267
+ ).toBe(true);
268
+ });
269
+ });
@@ -5,7 +5,8 @@ import {
5
5
  type ChatAddToolOutputFunction,
6
6
  type FileUIPart,
7
7
  isToolUIPart,
8
- type ToolUIPart,
8
+ lastAssistantMessageIsCompleteWithApprovalResponses,
9
+ lastAssistantMessageIsCompleteWithToolCalls,
9
10
  type UIMessage,
10
11
  } from "ai";
11
12
  import { useState } from "react";
@@ -17,7 +18,6 @@ import type {
17
18
  InvokeAiToolRequest,
18
19
  InvokeAiToolResponse,
19
20
  } from "@/core/network/types";
20
- import { logNever } from "@/utils/assertNever";
21
21
  import { blobToString } from "@/utils/fileToBase64";
22
22
  import { Logger } from "@/utils/Logger";
23
23
  import { getAICompletionBodyWithAttachments } from "../editor/ai/completion-utils";
@@ -169,69 +169,25 @@ export async function handleToolCall({
169
169
  }
170
170
 
171
171
  /**
172
- * Returns true if a tool call is "ready to be sent back to the server" — i.e.
173
- * either it has reached a terminal output state, or the user has just supplied
174
- * an approval response that the server hasn't seen yet.
175
- */
176
- function isToolCallReadyToSend(state: ToolUIPart["state"]): boolean {
177
- switch (state) {
178
- case "output-available":
179
- case "output-error":
180
- case "output-denied":
181
- case "approval-responded":
182
- return true;
183
- case "input-streaming":
184
- case "input-available":
185
- case "approval-requested":
186
- return false;
187
- default:
188
- logNever(state);
189
- return false;
190
- }
191
- }
192
-
193
- /**
194
- * Checks if we should send a message automatically based on the messages.
195
- * We auto-send when every tool call on the last assistant message has either
196
- * finished (output-available/error/denied) or has just received a user
197
- * approval response, and the assistant hasn't replied yet.
172
+ * Auto-send the next turn when the last assistant message ends with a
173
+ * tool call ready to round-trip. Any non-tool trailing part (text, file,
174
+ * source-*, reasoning, data-*, new step-start) means the assistant has
175
+ * already answered, so we leave the next turn to the user. State checks
176
+ * are delegated to the SDK to stay in sync with upstream.
198
177
  */
199
178
  export function hasPendingToolCalls(messages: UIMessage[]): boolean {
200
- if (messages.length === 0) {
201
- return false;
202
- }
203
-
204
- const lastMessage = messages[messages.length - 1];
205
- const parts = lastMessage.parts;
206
-
207
- if (parts.length === 0) {
208
- return false;
209
- }
210
-
211
- // Only auto-send if the last message is an assistant message
212
- // Because assistant messages are the ones that can have tool calls
213
- if (lastMessage.role !== "assistant") {
179
+ const lastMessage = messages.at(-1);
180
+ if (!lastMessage || lastMessage.role !== "assistant") {
214
181
  return false;
215
182
  }
216
-
217
- const toolParts = parts.filter(isToolUIPart);
218
-
219
- if (toolParts.length === 0) {
183
+ const lastPart = lastMessage.parts.at(-1);
184
+ if (!lastPart || !isToolUIPart(lastPart)) {
220
185
  return false;
221
186
  }
222
-
223
- const allToolCallsReady = toolParts.every((part) =>
224
- isToolCallReadyToSend(part.state),
187
+ return (
188
+ lastAssistantMessageIsCompleteWithToolCalls({ messages }) ||
189
+ lastAssistantMessageIsCompleteWithApprovalResponses({ messages })
225
190
  );
226
-
227
- // Check if the last part has any text content
228
- const lastPart = parts[parts.length - 1];
229
- const hasTextContent =
230
- lastPart.type === "text" && lastPart.text?.trim().length > 0;
231
-
232
- Logger.debug("All tool calls ready to send: %s", allToolCallsReady);
233
-
234
- return allToolCallsReady && !hasTextContent;
235
191
  }
236
192
 
237
193
  export function useFileState() {
@@ -134,6 +134,35 @@ describe("snapshot all duplicate keymaps", () => {
134
134
  });
135
135
  });
136
136
 
137
+ test("auto_close_pairs: false removes closeBrackets keymaps", () => {
138
+ const withAutoClose = EditorState.create({
139
+ extensions: setup(),
140
+ });
141
+ const withoutAutoClose = EditorState.create({
142
+ extensions: setup({
143
+ completionConfig: {
144
+ ...getOpts().completionConfig,
145
+ auto_close_pairs: false,
146
+ },
147
+ }),
148
+ });
149
+
150
+ const keysWith = withAutoClose.facet(keymap).flat();
151
+ const keysWithout = withoutAutoClose.facet(keymap).flat();
152
+
153
+ // closeBracketsKeymap contributes Backspace and Enter handlers
154
+ expect(keysWith.length).toBeGreaterThan(keysWithout.length);
155
+
156
+ const hasBracketPairHandler = (state: EditorState) =>
157
+ state
158
+ .facet(keymap)
159
+ .flat()
160
+ .some((k) => k.run?.name === "deleteBracketPair");
161
+
162
+ expect(hasBracketPairHandler(withAutoClose)).toBe(true);
163
+ expect(hasBracketPairHandler(withoutAutoClose)).toBe(false);
164
+ });
165
+
137
166
  test("placeholder adds another extension", () => {
138
167
  const opts = getOpts();
139
168
  const withAI = new PythonLanguageAdapter()
@@ -182,6 +182,7 @@ export const basicBundle = (opts: CodeMirrorSetupOpts): Extension[] => {
182
182
  diagnosticsConfig,
183
183
  } = opts;
184
184
  const placeholderType = getPlaceholderType(opts);
185
+ const autoClosePairs = completionConfig.auto_close_pairs !== false;
185
186
 
186
187
  return [
187
188
  ///// View
@@ -208,10 +209,10 @@ export const basicBundle = (opts: CodeMirrorSetupOpts): Extension[] => {
208
209
  copilotBundle(completionConfig),
209
210
  foldGutter(),
210
211
  stringsAutoCloseBraces(),
211
- closeBrackets(),
212
+ autoClosePairs ? closeBrackets() : [],
212
213
  completionKeymap(acceptCompletionOnEnter),
213
214
  // to avoid clash with charDeleteBackward keymap
214
- Prec.high(keymap.of(closeBracketsKeymap)),
215
+ autoClosePairs ? Prec.high(keymap.of(closeBracketsKeymap)) : [],
215
216
  bracketMatching(),
216
217
  indentOnInput(),
217
218
  indentUnit.of(" "),
@@ -56,6 +56,7 @@ test("default UserConfig - empty", () => {
56
56
  },
57
57
  "completion": {
58
58
  "activate_on_typing": true,
59
+ "auto_close_pairs": true,
59
60
  "copilot": false,
60
61
  "signature_hint_on_typing": false,
61
62
  },
@@ -127,6 +128,7 @@ test("default UserConfig - one level", () => {
127
128
  },
128
129
  "completion": {
129
130
  "activate_on_typing": true,
131
+ "auto_close_pairs": true,
130
132
  "copilot": false,
131
133
  "signature_hint_on_typing": false,
132
134
  },
@@ -75,6 +75,7 @@ export const UserConfigSchema = z
75
75
  .object({
76
76
  activate_on_typing: z.boolean().prefault(true),
77
77
  signature_hint_on_typing: z.boolean().prefault(false),
78
+ auto_close_pairs: z.boolean().prefault(true),
78
79
  copilot: z
79
80
  .union([z.boolean(), z.enum(["github", "codeium", "custom"])])
80
81
  .prefault(false)
@@ -6,7 +6,7 @@ import { z } from "zod";
6
6
  import { createPlugin } from "@/plugins/core/builder";
7
7
  import { rpc } from "@/plugins/core/rpc";
8
8
  import { Arrays } from "@/utils/arrays";
9
- import type { SendMessageRequest } from "./types";
9
+ import type { CancelPromptRequest, SendMessageRequest } from "./types";
10
10
 
11
11
  const LazyChatbot = React.lazy(() =>
12
12
  import("./chat-ui").then((m) => ({ default: m.Chatbot })),
@@ -18,6 +18,7 @@ export type PluginFunctions = {
18
18
  delete_chat_history: (req: {}) => Promise<null>;
19
19
  delete_chat_message: (req: { index: number }) => Promise<null>;
20
20
  send_prompt: (req: SendMessageRequest) => Promise<unknown>;
21
+ cancel_prompt: (req: CancelPromptRequest) => Promise<null>;
21
22
  };
22
23
 
23
24
  const messageSchema = z.array(
@@ -65,11 +66,15 @@ export const ChatPlugin = createPlugin<{ messages: UIMessage[] }>(
65
66
  send_prompt: rpc
66
67
  .input(
67
68
  z.object({
69
+ request_id: z.string(),
68
70
  messages: messageSchema,
69
71
  config: configSchema,
70
72
  }),
71
73
  )
72
74
  .output(z.unknown()),
75
+ cancel_prompt: rpc
76
+ .input(z.object({ request_id: z.string() }))
77
+ .output(z.null()),
73
78
  })
74
79
  .renderer((props) => (
75
80
  <Suspense>
@@ -84,6 +89,7 @@ export const ChatPlugin = createPlugin<{ messages: UIMessage[] }>(
84
89
  delete_chat_history={props.functions.delete_chat_history}
85
90
  delete_chat_message={props.functions.delete_chat_message}
86
91
  send_prompt={props.functions.send_prompt}
92
+ cancel_prompt={props.functions.cancel_prompt}
87
93
  value={props.value?.messages || Arrays.EMPTY}
88
94
  setValue={(messages) => props.setValue({ messages })}
89
95
  host={props.host}