@marimo-team/frontend 0.23.9-dev12 → 0.23.9-dev14
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.
- package/dist/assets/{add-cell-with-ai-D80JrWq3.js → add-cell-with-ai-D1jxCPJO.js} +21 -21
- package/dist/assets/{agent-panel-C-u_vOoE.js → agent-panel-CpIV_DqD.js} +1 -1
- package/dist/assets/{cell-editor-n3uoR3fW.js → cell-editor-ZXtJmHGk.js} +1 -1
- package/dist/assets/{chat-display-Ddsm0CG8.js → chat-display-BMhts-zk.js} +1 -1
- package/dist/assets/{chat-panel-75Zw468n.js → chat-panel-DFUZtZ-k.js} +1 -1
- package/dist/assets/chat-ui-BI5R0EXe.js +4 -0
- package/dist/assets/{command-palette-B-4BGife.js → command-palette-iuVfnoC1.js} +1 -1
- package/dist/assets/{edit-page-OW7p7hhZ.js → edit-page-BNOeCxsX.js} +3 -3
- package/dist/assets/{hooks-C1JamGaP.js → hooks-CruASyNm.js} +1 -1
- package/dist/assets/{index-f36_4Wqc.js → index-DgPMgX6h.js} +7 -7
- package/dist/assets/{layout-CURagHSL.js → layout-C6gvBnql.js} +2 -2
- package/dist/assets/{panels-Cmkyo_Ic.js → panels-CZG1Uvis.js} +1 -1
- package/dist/assets/{reveal-component-bk9gf4uY.js → reveal-component-C2Iz--Ic.js} +1 -1
- package/dist/assets/{run-page-BPJqsadV.js → run-page-C9ZCaia_.js} +1 -1
- package/dist/assets/{scratchpad-panel-M7BhoesO.js → scratchpad-panel-r6WbM6OM.js} +1 -1
- package/dist/assets/{useNotebookActions-DFRxa9MH.js → useNotebookActions-Bp3KLWjp.js} +1 -1
- package/dist/index.html +1 -1
- package/package.json +1 -1
- package/src/components/chat/__tests__/chat-utils.test.ts +269 -0
- package/src/components/chat/chat-utils.ts +14 -58
- package/src/plugins/impl/chat/ChatPlugin.tsx +7 -1
- package/src/plugins/impl/chat/__tests__/chat-ui.test.ts +278 -0
- package/src/plugins/impl/chat/chat-ui.tsx +106 -59
- package/src/plugins/impl/chat/types.ts +5 -0
- package/dist/assets/chat-ui-Dk62XQcq.js +0 -4
package/dist/index.html
CHANGED
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
<marimo-server-token data-token="{{ server_token }}" hidden></marimo-server-token>
|
|
67
67
|
<!-- /TODO -->
|
|
68
68
|
<title>{{ title }}</title>
|
|
69
|
-
<script type="module" crossorigin src="./assets/index-
|
|
69
|
+
<script type="module" crossorigin src="./assets/index-DgPMgX6h.js"></script>
|
|
70
70
|
<link rel="modulepreload" crossorigin href="./assets/preload-helper-BPPi7vOr.js">
|
|
71
71
|
<link rel="modulepreload" crossorigin href="./assets/chunk-LvLJmgfZ.js">
|
|
72
72
|
<link rel="modulepreload" crossorigin href="./assets/react-Bj1aDYRI.js">
|
package/package.json
CHANGED
|
@@ -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
|
-
|
|
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
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
|
|
176
|
-
|
|
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
|
-
|
|
201
|
-
|
|
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
|
-
|
|
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
|
-
|
|
224
|
-
|
|
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() {
|
|
@@ -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}
|