@marimo-team/islands 0.23.9-dev8 → 0.23.9

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 (101) hide show
  1. package/dist/{ConnectedDataExplorerComponent-OzrfMM5L.js → ConnectedDataExplorerComponent-CyV83R2m.js} +4 -4
  2. package/dist/assets/__vite-browser-external-Ci2ZQfXU.js +1 -0
  3. package/dist/assets/{worker-CpBbwbQo.js → worker-ip3AI_sN.js} +2 -2
  4. package/dist/{chat-ui-BDI3FMI8.js → chat-ui-ChD4VvCo.js} +3060 -3033
  5. package/dist/{code-visibility-SqsoLwxQ.js → code-visibility-BkuwTYAm.js} +1368 -1204
  6. package/dist/{formats-DQ5qjo_Q.js → formats-DHxc-FdY.js} +1 -1
  7. package/dist/{glide-data-editor-DqRY9naW.js → glide-data-editor-BOmK9ETQ.js} +2 -2
  8. package/dist/{html-to-image-CiSinpSR.js → html-to-image-BHv7CEU_.js} +2145 -2153
  9. package/dist/{input-CZD2z6X2.js → input-_2sjvfne.js} +1 -1
  10. package/dist/main.js +680 -705
  11. package/dist/{mermaid-IU93XzmY.js → mermaid-lXOw5Py9.js} +2 -2
  12. package/dist/{process-output-5qJjMRKh.js → process-output-BvySRgli.js} +33 -25
  13. package/dist/{reveal-component-v4zHgynl.js → reveal-component-DeBkkDcg.js} +312 -291
  14. package/dist/{spec-a6DaqW__.js → spec-B96zNUEA.js} +1 -1
  15. package/dist/style.css +1 -1
  16. package/dist/{toDate-ZVVIBmdk.js → toDate-x-WRDCH7.js} +1 -1
  17. package/dist/{useAsyncData-C008zUPi.js → useAsyncData-iRgKDT5s.js} +1 -1
  18. package/dist/{useDeepCompareMemoize-BrA3_n61.js → useDeepCompareMemoize-CkQ57VS2.js} +1 -1
  19. package/dist/{useLifecycle-BNaoJ5a4.js → useLifecycle-BBO9PIph.js} +1 -1
  20. package/dist/{useTheme-7O0YWlE5.js → useTheme-DHIrRQOe.js} +34 -21
  21. package/dist/{vega-component-DJNmOdUj.js → vega-component-Dq-SH463.js} +5 -5
  22. package/package.json +1 -1
  23. package/src/components/ai/__tests__/ai-utils.test.ts +43 -38
  24. package/src/components/ai/ai-model-dropdown.tsx +2 -2
  25. package/src/components/app-config/ai-config.tsx +147 -16
  26. package/src/components/app-config/user-config-form.tsx +37 -1
  27. package/src/components/chat/__tests__/chat-utils.test.ts +269 -0
  28. package/src/components/chat/chat-panel.tsx +38 -5
  29. package/src/components/chat/chat-utils.ts +14 -58
  30. package/src/components/data-table/TableBottomBar.tsx +5 -8
  31. package/src/components/data-table/__tests__/column-explorer.test.tsx +128 -0
  32. package/src/components/data-table/__tests__/header-items.test.tsx +220 -10
  33. package/src/components/data-table/column-explorer-panel/column-explorer.tsx +95 -29
  34. package/src/components/data-table/column-header.tsx +17 -12
  35. package/src/components/data-table/data-table.tsx +4 -0
  36. package/src/components/data-table/export-actions.tsx +19 -12
  37. package/src/components/data-table/header-items.tsx +40 -16
  38. package/src/components/data-table/hooks/use-column-visibility.ts +14 -0
  39. package/src/components/data-table/schemas.ts +2 -2
  40. package/src/components/data-table/table-explorer-panel/table-explorer-panel.tsx +16 -6
  41. package/src/components/databases/display.tsx +2 -0
  42. package/src/components/datasources/__tests__/utils.test.ts +82 -0
  43. package/src/components/datasources/utils.ts +16 -15
  44. package/src/components/editor/Disconnected.tsx +1 -60
  45. package/src/components/editor/__tests__/viewer-banner.test.tsx +89 -0
  46. package/src/components/editor/actions/pair-with-agent-modal.tsx +1 -0
  47. package/src/components/editor/actions/useCellActionButton.tsx +3 -3
  48. package/src/components/editor/actions/useNotebookActions.tsx +5 -2
  49. package/src/components/editor/cell/code/cell-editor.tsx +25 -5
  50. package/src/components/editor/chrome/types.ts +13 -6
  51. package/src/components/editor/chrome/wrapper/app-chrome.tsx +6 -4
  52. package/src/components/editor/chrome/wrapper/footer-items/ai-status.tsx +10 -1
  53. package/src/components/editor/chrome/wrapper/sidebar.tsx +7 -5
  54. package/src/components/editor/errors/auto-fix.tsx +3 -3
  55. package/src/components/editor/header/__tests__/status.test.tsx +0 -15
  56. package/src/components/editor/header/app-header.tsx +1 -4
  57. package/src/components/editor/header/status.tsx +4 -13
  58. package/src/components/editor/navigation/__tests__/navigation.test.ts +15 -0
  59. package/src/components/editor/navigation/navigation.ts +5 -0
  60. package/src/components/editor/output/MarimoErrorOutput.tsx +103 -25
  61. package/src/components/editor/output/MarimoTracebackOutput.tsx +28 -39
  62. package/src/components/editor/renderers/cell-array.tsx +27 -24
  63. package/src/components/editor/renderers/slides-layout/__tests__/compute-slide-cells.test.ts +30 -17
  64. package/src/components/editor/renderers/slides-layout/compute-slide-cells.ts +17 -8
  65. package/src/components/editor/renderers/slides-layout/slides-layout.tsx +10 -12
  66. package/src/components/editor/viewer-banner.tsx +82 -0
  67. package/src/components/slides/minimap.tsx +45 -9
  68. package/src/components/slides/reveal-component.tsx +82 -37
  69. package/src/components/slides/slide-cell-view.tsx +12 -1
  70. package/src/components/slides/slide-form.tsx +11 -3
  71. package/src/components/static-html/static-banner.tsx +28 -22
  72. package/src/core/ai/__tests__/model-registry.test.ts +72 -60
  73. package/src/core/ai/model-registry.ts +33 -28
  74. package/src/core/cells/__tests__/actions.test.ts +48 -0
  75. package/src/core/cells/actions.ts +5 -6
  76. package/src/core/codemirror/__tests__/setup.test.ts +29 -0
  77. package/src/core/codemirror/cells/traceback-decorations.ts +1 -1
  78. package/src/core/codemirror/cm.ts +50 -3
  79. package/src/core/codemirror/completion/hints.ts +4 -1
  80. package/src/core/codemirror/format.ts +1 -0
  81. package/src/core/codemirror/keymaps/vim.ts +63 -0
  82. package/src/core/codemirror/language/languages/sql/sql.ts +1 -0
  83. package/src/core/codemirror/language/languages/sql/utils.ts +2 -0
  84. package/src/core/config/__tests__/config-schema.test.ts +4 -0
  85. package/src/core/config/config-schema.ts +4 -0
  86. package/src/core/config/config.ts +16 -0
  87. package/src/core/edit-app.tsx +3 -0
  88. package/src/core/islands/bootstrap.ts +2 -0
  89. package/src/core/kernel/__tests__/handlers.test.ts +5 -0
  90. package/src/core/websocket/__tests__/useMarimoKernelConnection.test.ts +0 -13
  91. package/src/core/websocket/types.ts +0 -6
  92. package/src/core/websocket/useMarimoKernelConnection.tsx +3 -12
  93. package/src/css/app/Cell.css +0 -1
  94. package/src/plugins/impl/DataTablePlugin.tsx +48 -22
  95. package/src/plugins/impl/chat/ChatPlugin.tsx +7 -1
  96. package/src/plugins/impl/chat/__tests__/chat-ui.test.ts +278 -0
  97. package/src/plugins/impl/chat/chat-ui.tsx +106 -59
  98. package/src/plugins/impl/chat/types.ts +5 -0
  99. package/src/utils/__tests__/json-parser.test.ts +1 -69
  100. package/src/utils/json/json-parser.ts +0 -30
  101. package/dist/assets/__vite-browser-external-CAdMKBac.js +0 -1
@@ -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
+ });
@@ -15,11 +15,13 @@ import { useAtom, useAtomValue, useSetAtom, useStore } from "jotai";
15
15
  import {
16
16
  BotMessageSquareIcon,
17
17
  HatGlasses,
18
+ ArrowRightIcon,
18
19
  Loader2,
19
20
  type LucideIcon,
20
21
  MessageCircleIcon,
21
22
  NotebookText,
22
23
  PlusIcon,
24
+ SparklesIcon,
23
25
  SettingsIcon,
24
26
  } from "lucide-react";
25
27
  import { memo, useEffect, useRef, useState } from "react";
@@ -49,15 +51,17 @@ import {
49
51
  FRONTEND_TOOL_REGISTRY,
50
52
  } from "@/core/ai/tools/registry";
51
53
  import { useCellActions } from "@/core/cells/cells";
52
- import { aiAtom, aiEnabledAtom } from "@/core/config/config";
54
+ import { aiAtom, aiModelConfiguredAtom } from "@/core/config/config";
53
55
  import { DEFAULT_AI_MODEL } from "@/core/config/config-schema";
54
56
  import { useRequestClient } from "@/core/network/requests";
55
57
  import { useRuntimeManager } from "@/core/runtime/config";
58
+ import { isWasm } from "@/core/wasm/utils";
56
59
  import { ErrorBanner } from "@/plugins/impl/common/error-banner";
57
60
  import { cn } from "@/utils/cn";
58
61
  import { Logger } from "@/utils/Logger";
59
62
  import { AIModelDropdown } from "../ai/ai-model-dropdown";
60
63
  import { useOpenSettingsToTab } from "../app-config/state";
64
+ import { PairWithAgentModal } from "../editor/actions/pair-with-agent-modal";
61
65
  import { PromptInput } from "../editor/ai/add-cell-with-ai";
62
66
  import {
63
67
  addContextCompletion,
@@ -65,6 +69,7 @@ import {
65
69
  } from "../editor/ai/completion-utils";
66
70
  import { PanelEmptyState } from "../editor/chrome/panels/empty-state";
67
71
  import { CopyClipboardIcon } from "../icons/copy-icon";
72
+ import { useImperativeModal } from "../modal/ImperativeModal";
68
73
  import { MCPStatusIndicator } from "../mcp/mcp-status-indicator";
69
74
  import { Tooltip, TooltipProvider } from "../ui/tooltip";
70
75
  import {
@@ -416,8 +421,28 @@ const ChatInput: React.FC<ChatInputProps> = memo(
416
421
 
417
422
  ChatInput.displayName = "ChatInput";
418
423
 
424
+ const PairWithAgentCallout: React.FC<{
425
+ onPairWithAgent: () => void;
426
+ }> = ({ onPairWithAgent }) => {
427
+ if (isWasm()) {
428
+ return null;
429
+ }
430
+
431
+ return (
432
+ <Button
433
+ variant="text"
434
+ className="gap-1.5 text-sm text-link hover:underline"
435
+ onClick={onPairWithAgent}
436
+ >
437
+ <SparklesIcon className="h-3.5 w-3.5 shrink-0" />
438
+ <span>Work on this notebook with your own agent</span>
439
+ <ArrowRightIcon className="h-3 w-3 shrink-0" />
440
+ </Button>
441
+ );
442
+ };
443
+
419
444
  const ChatPanel = () => {
420
- const aiConfigured = useAtomValue(aiEnabledAtom);
445
+ const aiConfigured = useAtomValue(aiModelConfiguredAtom);
421
446
  const { handleClick } = useOpenSettingsToTab();
422
447
 
423
448
  if (!aiConfigured) {
@@ -455,6 +480,7 @@ const ChatPanelBody = () => {
455
480
  const messagesEndRef = useRef<HTMLDivElement>(null);
456
481
  const runtimeManager = useRuntimeManager();
457
482
  const { invokeAiTool, sendRun } = useRequestClient();
483
+ const { openModal, closeModal } = useImperativeModal();
458
484
 
459
485
  const activeChatId = activeChat?.id;
460
486
  const store = useStore();
@@ -614,6 +640,10 @@ const ChatPanelBody = () => {
614
640
  clearFiles();
615
641
  });
616
642
 
643
+ const handlePairWithAgent = useEvent(() => {
644
+ openModal(<PairWithAgentModal onClose={closeModal} />);
645
+ });
646
+
617
647
  const handleMessageEdit = useEvent((index: number, newValue: string) => {
618
648
  const editedMessage = messages[index];
619
649
  const fileParts = editedMessage.parts?.filter((p) => p.type === "file");
@@ -724,9 +754,12 @@ const ChatPanelBody = () => {
724
754
  ref={scrollContainerRef}
725
755
  >
726
756
  {isNewThread && (
727
- <div className="rounded-md border bg-background">
728
- {filesPills}
729
- {chatInput}
757
+ <div className="flex flex-col gap-2">
758
+ <div className="rounded-md border bg-background">
759
+ {filesPills}
760
+ {chatInput}
761
+ </div>
762
+ <PairWithAgentCallout onPairWithAgent={handlePairWithAgent} />
730
763
  </div>
731
764
  )}
732
765
 
@@ -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() {
@@ -13,7 +13,7 @@ import {
13
13
  } from "../editor/chrome/panels/context-aware-panel/context-aware-panel";
14
14
  import { Button } from "../ui/button";
15
15
  import { toast } from "../ui/use-toast";
16
- import { getUserColumnVisibilityCounts } from "./hooks/use-column-visibility";
16
+ import { getColumnCountForDisplay } from "./hooks/use-column-visibility";
17
17
  import { DataTablePagination, prettifyRowColumnCount } from "./pagination";
18
18
  import { CellSelectionStats } from "./range-focus/cell-selection-stats";
19
19
  import type { DataTableSelection } from "./types";
@@ -147,15 +147,12 @@ export const TableBottomBar = <TData,>({
147
147
  );
148
148
  }
149
149
 
150
- const counts = getUserColumnVisibilityCounts(table);
151
- // When columns are clipped, the table instance only has the rendered
152
- // subset, so the visible/hidden math must use that subset's total. The
153
- // dataset-wide `totalColumns` prop is only correct for the no-hidden
154
- // "N columns" label.
150
+ const { totalColumns: effectiveTotalColumns, hiddenColumns } =
151
+ getColumnCountForDisplay(table, totalColumns);
155
152
  const { rowsAndColumns, hiddenSuffix } = prettifyRowColumnCount({
156
153
  numRows: table.getRowCount(),
157
- totalColumns: counts.hidden > 0 ? counts.total : totalColumns,
158
- hiddenColumns: counts.hidden,
154
+ totalColumns: effectiveTotalColumns,
155
+ hiddenColumns,
159
156
  locale,
160
157
  });
161
158
 
@@ -0,0 +1,128 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import {
4
+ type ColumnDef,
5
+ getCoreRowModel,
6
+ useReactTable,
7
+ } from "@tanstack/react-table";
8
+ import { fireEvent, render, screen } from "@testing-library/react";
9
+ import { beforeAll, describe, expect, it, vi } from "vitest";
10
+ import { TooltipProvider } from "@/components/ui/tooltip";
11
+ import { ColumnExplorerPanel } from "../column-explorer-panel/column-explorer";
12
+ import type { FieldTypesWithExternalType } from "../types";
13
+
14
+ beforeAll(() => {
15
+ global.HTMLElement.prototype.scrollIntoView = () => {};
16
+ if (!global.HTMLElement.prototype.hasPointerCapture) {
17
+ global.HTMLElement.prototype.hasPointerCapture = () => false;
18
+ }
19
+ });
20
+
21
+ const FIELD_TYPES: FieldTypesWithExternalType = [
22
+ ["customer_name", ["string", "str"]],
23
+ ["cust_age", ["integer", "int"]],
24
+ ["order_total", ["number", "float"]],
25
+ ];
26
+
27
+ type Row = Record<string, unknown>;
28
+
29
+ const TEST_COLUMNS: ColumnDef<Row>[] = [
30
+ { id: "customer_name", accessorKey: "customer_name" },
31
+ { id: "cust_age", accessorKey: "cust_age" },
32
+ { id: "order_total", accessorKey: "order_total" },
33
+ ];
34
+
35
+ interface HarnessProps {
36
+ totalColumns?: number;
37
+ initiallyHidden?: string[];
38
+ }
39
+
40
+ function PanelHarness({
41
+ totalColumns = 3,
42
+ initiallyHidden = [],
43
+ }: HarnessProps) {
44
+ const table = useReactTable<Row>({
45
+ data: [],
46
+ columns: TEST_COLUMNS,
47
+ getCoreRowModel: getCoreRowModel(),
48
+ locale: "en-US",
49
+ state: {
50
+ columnVisibility: Object.fromEntries(
51
+ initiallyHidden.map((id) => [id, false]),
52
+ ),
53
+ },
54
+ });
55
+ return (
56
+ <ColumnExplorerPanel
57
+ previewColumn={vi.fn().mockResolvedValue({})}
58
+ fieldTypes={FIELD_TYPES}
59
+ totalRows={3}
60
+ totalColumns={totalColumns}
61
+ tableId="t1"
62
+ table={table}
63
+ />
64
+ );
65
+ }
66
+
67
+ function renderPanel(props?: HarnessProps) {
68
+ return render(
69
+ <TooltipProvider>
70
+ <PanelHarness {...(props ?? {})} />
71
+ </TooltipProvider>,
72
+ );
73
+ }
74
+
75
+ function getSearchInput() {
76
+ return screen.getByPlaceholderText("Search columns...");
77
+ }
78
+
79
+ describe("ColumnExplorerPanel search", () => {
80
+ it("shows all columns when search is empty", () => {
81
+ renderPanel();
82
+ expect(screen.getByText("customer_name")).toBeInTheDocument();
83
+ expect(screen.getByText("cust_age")).toBeInTheDocument();
84
+ expect(screen.getByText("order_total")).toBeInTheDocument();
85
+ });
86
+
87
+ it("matches a word prefix against any column word", () => {
88
+ renderPanel();
89
+ fireEvent.change(getSearchInput(), { target: { value: "cust" } });
90
+ expect(screen.getByText("customer_name")).toBeInTheDocument();
91
+ expect(screen.getByText("cust_age")).toBeInTheDocument();
92
+ expect(screen.queryByText("order_total")).not.toBeInTheDocument();
93
+ });
94
+
95
+ it("matches multi-word queries across column words in any order", () => {
96
+ renderPanel();
97
+ fireEvent.change(getSearchInput(), { target: { value: "name cust" } });
98
+ expect(screen.getByText("customer_name")).toBeInTheDocument();
99
+ expect(screen.queryByText("cust_age")).not.toBeInTheDocument();
100
+ expect(screen.queryByText("order_total")).not.toBeInTheDocument();
101
+ });
102
+
103
+ it("filters out columns that don't match any needle word", () => {
104
+ renderPanel();
105
+ fireEvent.change(getSearchInput(), { target: { value: "xyz" } });
106
+ expect(screen.queryByText("customer_name")).not.toBeInTheDocument();
107
+ expect(screen.queryByText("cust_age")).not.toBeInTheDocument();
108
+ expect(screen.queryByText("order_total")).not.toBeInTheDocument();
109
+ });
110
+ });
111
+
112
+ describe("ColumnExplorerPanel header counts", () => {
113
+ it("uses rendered-subset total when a clipped column is hidden", () => {
114
+ // Dataset has 100 columns server-side; only 3 are rendered into the
115
+ // TanStack table (the clipped subset). Hiding one of the rendered columns
116
+ // must report "2 visible (1 hidden)", not "99 visible (1 hidden)".
117
+ renderPanel({ totalColumns: 100, initiallyHidden: ["cust_age"] });
118
+ expect(screen.getByText(/2 visible/)).toBeInTheDocument();
119
+ expect(screen.getByText(/\(1 hidden\)/)).toBeInTheDocument();
120
+ expect(screen.queryByText(/99 visible/)).not.toBeInTheDocument();
121
+ });
122
+
123
+ it("uses dataset-wide total when no column is hidden", () => {
124
+ renderPanel({ totalColumns: 100 });
125
+ expect(screen.getByText(/100 columns/)).toBeInTheDocument();
126
+ expect(screen.queryByText(/hidden/)).not.toBeInTheDocument();
127
+ });
128
+ });