@marimo-team/islands 0.23.9-dev13 → 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/{chat-ui-xfKWgbtB.js → chat-ui-C-DXZYyv.js} +3057 -3030
- package/dist/{code-visibility-DjGqscP3.js → code-visibility-BnbZdQGR.js} +1 -1
- package/dist/main.js +10 -17
- package/dist/{process-output-Cz6wQSkL.js → process-output-CXn2mq3C.js} +32 -24
- package/dist/{reveal-component-Dins3DMl.js → reveal-component-CoucYkvH.js} +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
|
@@ -34996,7 +34996,7 @@ ${d}`,
|
|
|
34996
34996
|
return Logger.warn("Failed to get version from mount config"), null;
|
|
34997
34997
|
}
|
|
34998
34998
|
}
|
|
34999
|
-
marimoVersionAtom = atom(getVersionFromMountConfig() || "0.23.9-
|
|
34999
|
+
marimoVersionAtom = atom(getVersionFromMountConfig() || "0.23.9-dev14");
|
|
35000
35000
|
showCodeInRunModeAtom = atom(true);
|
|
35001
35001
|
atom(null);
|
|
35002
35002
|
var import_compiler_runtime = require_compiler_runtime();
|
package/dist/main.js
CHANGED
|
@@ -26,13 +26,13 @@ import { $ as useCellActions, At as DeferredRequestRegistry, B as safeExtractSet
|
|
|
26
26
|
import { __tla as __tla_1 } from "./chunk-5FQGJX7Z-BNjes6Yx.js";
|
|
27
27
|
import { o as useSize, s as Root$2, u as createLucideIcon } from "./dist-C1BYNeCR.js";
|
|
28
28
|
import { A as SquareFunction, C as DEFAULT_COLOR_SCHEME, D as SCALE_TYPE_DESCRIPTIONS, E as EMPTY_VALUE$1, O as TIME_UNIT_DESCRIPTIONS, S as DEFAULT_AGGREGATION, T as DEFAULT_TIME_UNIT, _ as AGGREGATION_TYPE_DESCRIPTIONS, a as AGGREGATION_FNS$1, b as COLOR_SCHEMES, c as COLOR_BY_FIELDS, d as NONE_VALUE, f as SELECTABLE_DATA_TYPES, g as TIME_UNITS, h as STRING_AGGREGATION_FNS, i as convertDataTypeToSelectable, j as ChartColumn, k as escapeFieldName, l as COMBINED_TIME_UNITS, m as SORT_TYPES, n as createSpecWithoutData, o as BIN_AGGREGATION, p as SINGLE_TIME_UNITS, r as isFieldSet, s as CHART_TYPES, t as augmentSpecWithData, u as ChartType, v as AGGREGATION_TYPE_ICON, w as DEFAULT_MAX_BINS_FACET, x as COUNT_FIELD, y as CHART_TYPE_ICON } from "./spec-BQbOvWbq.js";
|
|
29
|
-
import { $ as TableBody, $t as ChevronLeft, A as ComboboxItem, At as ChartErrorState, B as contextAwarePanelOpen, Bt as $fae977aafc393c5c$export$6b862160d295c8e, C as prettifyRowColumnCount, Ct as dateToLocalISODate, D as DatePicker, Dt as TabsContent, E as useInternalStateWithSync, Et as Tabs, F as CommandList, Ft as RenderTextWithLinks, G as slotsController, H as contextAwarePanelType, Ht as GripHorizontal, I as CommandSeparator, It as Kbd, Jt as Code, K as Toggle, Kt as Ellipsis, L as smartMatch, Lt as HtmlOutput, M as CommandEmpty, Mt as ChartLoadingState, N as CommandInput, Nt as LazyVegaEmbed, O as DateRangePicker, Ot as TabsList, P as CommandItem, Pt as useOverflowDetection, Q as Table, Qt as ChevronsDownUp, R as ContextAwarePanelItem, Rt as EmotionCacheProvider, S as downloadSizeLimitAtom, St as Maps, T as getColumnCountForDisplay, Tt as dateToLocalISOTime, U as isCellAwareAtom, Ut as Funnel, V as contextAwarePanelOwner, Vt as TextWrap, W as SlotNames, Wt as EyeOff, X as Fill, Xt as ChevronsRight, Yt as ChevronsUpDown, Z as Provider$1, Zt as ChevronsLeft, _ as downloadBlob, _t as SELECT_COLUMN_ID, at as generateColumns, b as Progress, bt as getMimeValues, c as Slide, ct as ColumnChartContext, d as JsonOutput, dt as useIntersectionObserver, en as ArrowDownWideNarrow, et as TableCell, f as OutputArea, ft as usePrevious$1, g as ADD_PRINTING_CLASS, gt as INDEX_COLUMN_NAME, h as InstallPackageButton, ht as loadTableData, it as NAMELESS_COLUMN_PREFIX, j as Command, jt as ChartInfoState, k as Combobox, kt as TabsTrigger, l as RadioGroup, lt as ColumnChartSpecModel, m as DataTable, mt as loadTableAndRawData, n as marimoVersionAtom, nt as TableHeader, o as SLIDE_TYPE_OPTIONS_BY_VALUE, ot as inferFieldTypes, p as OutputRenderer, pt as getPageIndexForRow, qt as Download, r as showCodeInRunModeAtom, rt as TableRow, st as renderCellValue, t as useNotebookCodeAvailable, tt as TableHead, u as RadioGroupItem, ut as DelayMount, v as downloadByURL, vt as TOO_MANY_ROWS, w as prettifyRowCount, wt as dateToLocalISODateTime, x as Filenames, xt as isNullishFilter, y as downloadHTMLAsImage, yt as toFieldTypes, z as PANEL_TYPES, zt as $fae977aafc393c5c$export$588937bcd60ade55, __tla as __tla_2 } from "./code-visibility-
|
|
29
|
+
import { $ as TableBody, $t as ChevronLeft, A as ComboboxItem, At as ChartErrorState, B as contextAwarePanelOpen, Bt as $fae977aafc393c5c$export$6b862160d295c8e, C as prettifyRowColumnCount, Ct as dateToLocalISODate, D as DatePicker, Dt as TabsContent, E as useInternalStateWithSync, Et as Tabs, F as CommandList, Ft as RenderTextWithLinks, G as slotsController, H as contextAwarePanelType, Ht as GripHorizontal, I as CommandSeparator, It as Kbd, Jt as Code, K as Toggle, Kt as Ellipsis, L as smartMatch, Lt as HtmlOutput, M as CommandEmpty, Mt as ChartLoadingState, N as CommandInput, Nt as LazyVegaEmbed, O as DateRangePicker, Ot as TabsList, P as CommandItem, Pt as useOverflowDetection, Q as Table, Qt as ChevronsDownUp, R as ContextAwarePanelItem, Rt as EmotionCacheProvider, S as downloadSizeLimitAtom, St as Maps, T as getColumnCountForDisplay, Tt as dateToLocalISOTime, U as isCellAwareAtom, Ut as Funnel, V as contextAwarePanelOwner, Vt as TextWrap, W as SlotNames, Wt as EyeOff, X as Fill, Xt as ChevronsRight, Yt as ChevronsUpDown, Z as Provider$1, Zt as ChevronsLeft, _ as downloadBlob, _t as SELECT_COLUMN_ID, at as generateColumns, b as Progress, bt as getMimeValues, c as Slide, ct as ColumnChartContext, d as JsonOutput, dt as useIntersectionObserver, en as ArrowDownWideNarrow, et as TableCell, f as OutputArea, ft as usePrevious$1, g as ADD_PRINTING_CLASS, gt as INDEX_COLUMN_NAME, h as InstallPackageButton, ht as loadTableData, it as NAMELESS_COLUMN_PREFIX, j as Command, jt as ChartInfoState, k as Combobox, kt as TabsTrigger, l as RadioGroup, lt as ColumnChartSpecModel, m as DataTable, mt as loadTableAndRawData, n as marimoVersionAtom, nt as TableHeader, o as SLIDE_TYPE_OPTIONS_BY_VALUE, ot as inferFieldTypes, p as OutputRenderer, pt as getPageIndexForRow, qt as Download, r as showCodeInRunModeAtom, rt as TableRow, st as renderCellValue, t as useNotebookCodeAvailable, tt as TableHead, u as RadioGroupItem, ut as DelayMount, v as downloadByURL, vt as TOO_MANY_ROWS, w as prettifyRowCount, wt as dateToLocalISODateTime, x as Filenames, xt as isNullishFilter, y as downloadHTMLAsImage, yt as toFieldTypes, z as PANEL_TYPES, zt as $fae977aafc393c5c$export$588937bcd60ade55, __tla as __tla_2 } from "./code-visibility-BnbZdQGR.js";
|
|
30
30
|
import { c as Calendar, i as createReducerAndAtoms, n as useOnUnmount, o as ToggleLeft, t as useOnMount } from "./useLifecycle-YLdDriVo.js";
|
|
31
31
|
import { t as Check } from "./check-DTbrK0zt.js";
|
|
32
32
|
import { A as Trigger$1, C as $a916eb452884faea$export$b7a616150fdb9f44, E as $18f2051aff69b9bf$export$a54013f0d02a8f82, F as X, L as ChevronDown, M as usePrevious$2, N as useDirection, P as createCollection, S as logNever, T as $18f2051aff69b9bf$export$43bb16f9c6d9e3f7, a as SelectGroup, c as SelectSeparator, d as NativeSelect, i as SelectContent, j as clamp$2, k as Icon, l as SelectTrigger, n as capitalize, o as SelectItem, r as Select, s as SelectLabel, t as Strings, u as SelectValue, x as assertNever } from "./strings-Bu3vlb6W.js";
|
|
33
33
|
import { I as $64fa3d84918910a7$export$29f1550f4b0d4415, K as useDebounceControlledState, L as $64fa3d84918910a7$export$4d86445c2cf5e3, Mt as $65484d02dcb7eb3e$export$457c3d6518dd4c6f, Nt as $3ef42575df84b30b$export$9d1611c77c2fe928, V as $64fa3d84918910a7$export$df3a06d6289f983e, Vt as $ff5963eb1fccf552$export$e08e3b67e392101e, a as NumberField, b as DropdownMenuTrigger, c as prettyNumber, d as DropdownMenuContent, f as DropdownMenuGroup, fn as Circle, g as DropdownMenuSeparator, i as OnBlurredInput, it as $701a24aa0da5b062$export$ea18c227d4417cc3, l as prettyScientificNumber, m as DropdownMenuLabel, n as DebouncedNumberInput, p as DropdownMenuItem, pn as ChevronRight, q as useDebouncedCallback, r as Input, rt as $f7dceffc5ad7768b$export$4e328f61c538687f, t as DebouncedInput, u as DropdownMenu, ut as $6179b936705e76d3$export$ae780daf29e6d456, vt as $458b0a5536c1a7cf$export$40bfa8c7b0832715 } from "./input-DBDlwwuD.js";
|
|
34
34
|
import { _ as isWasm, c as asRemoteURL, d as isStaticNotebook, f as appendQueryParams, g as Deferred, m as require_cuid2, u as getStaticVirtualFiles, v as CircleQuestionMark } from "./toDate-DqrFDZlc.js";
|
|
35
|
-
import { a as MarimoIncomingMessageEvent, c as MarimoValueUpdateEvent, d as File, i as PythonIcon, l as createInputEvent, n as blobToString, o as MarimoValueInputEvent, r as filesToBase64, s as MarimoValueReadyEvent, t as processOutput, u as deserializeBlob } from "./process-output-
|
|
35
|
+
import { a as MarimoIncomingMessageEvent, c as MarimoValueUpdateEvent, d as Square, f as File, i as PythonIcon, l as createInputEvent, n as blobToString, o as MarimoValueInputEvent, r as filesToBase64, s as MarimoValueReadyEvent, t as processOutput, u as deserializeBlob } from "./process-output-CXn2mq3C.js";
|
|
36
36
|
import { n as Trash, r as Pencil, t as BulkEdit } from "./types-CVvp1fKr.js";
|
|
37
37
|
import { n as require_prop_types, r as Plus, t as ErrorBoundary } from "./ErrorBoundary-rULOrC_p.js";
|
|
38
38
|
import { t as require_react_dom } from "./react-dom-BTJzcVJ9.js";
|
|
@@ -2372,18 +2372,6 @@ let __tla = Promise.all([
|
|
|
2372
2372
|
key: "napkw2"
|
|
2373
2373
|
}
|
|
2374
2374
|
]
|
|
2375
|
-
]), Square = createLucideIcon("square", [
|
|
2376
|
-
[
|
|
2377
|
-
"rect",
|
|
2378
|
-
{
|
|
2379
|
-
width: "18",
|
|
2380
|
-
height: "18",
|
|
2381
|
-
x: "3",
|
|
2382
|
-
y: "3",
|
|
2383
|
-
rx: "2",
|
|
2384
|
-
key: "afitv7"
|
|
2385
|
-
}
|
|
2386
|
-
]
|
|
2387
2375
|
]), TriangleAlert = createLucideIcon("triangle-alert", [
|
|
2388
2376
|
[
|
|
2389
2377
|
"path",
|
|
@@ -5602,7 +5590,7 @@ let __tla = Promise.all([
|
|
|
5602
5590
|
};
|
|
5603
5591
|
}
|
|
5604
5592
|
};
|
|
5605
|
-
var LazyChatbot = import_react.lazy(() => import("./chat-ui-
|
|
5593
|
+
var LazyChatbot = import_react.lazy(() => import("./chat-ui-C-DXZYyv.js").then((e) => ({
|
|
5606
5594
|
default: e.Chatbot
|
|
5607
5595
|
}))), messageSchema = array(object({
|
|
5608
5596
|
id: string(),
|
|
@@ -5641,9 +5629,13 @@ let __tla = Promise.all([
|
|
|
5641
5629
|
index: number()
|
|
5642
5630
|
})).output(_null()),
|
|
5643
5631
|
send_prompt: rpc.input(object({
|
|
5632
|
+
request_id: string(),
|
|
5644
5633
|
messages: messageSchema,
|
|
5645
5634
|
config: configSchema
|
|
5646
|
-
})).output(unknown())
|
|
5635
|
+
})).output(unknown()),
|
|
5636
|
+
cancel_prompt: rpc.input(object({
|
|
5637
|
+
request_id: string()
|
|
5638
|
+
})).output(_null())
|
|
5647
5639
|
}).renderer((e) => {
|
|
5648
5640
|
var _a3;
|
|
5649
5641
|
return (0, import_jsx_runtime.jsx)(import_react.Suspense, {
|
|
@@ -5658,6 +5650,7 @@ let __tla = Promise.all([
|
|
|
5658
5650
|
delete_chat_history: e.functions.delete_chat_history,
|
|
5659
5651
|
delete_chat_message: e.functions.delete_chat_message,
|
|
5660
5652
|
send_prompt: e.functions.send_prompt,
|
|
5653
|
+
cancel_prompt: e.functions.cancel_prompt,
|
|
5661
5654
|
value: ((_a3 = e.value) == null ? void 0 : _a3.messages) || Arrays.EMPTY,
|
|
5662
5655
|
setValue: (r) => e.setValue({
|
|
5663
5656
|
messages: r
|
|
@@ -36100,7 +36093,7 @@ ${c}
|
|
|
36100
36093
|
if (l && l !== "slide") return l;
|
|
36101
36094
|
if (c == null ? void 0 : c.has(e)) return "skip";
|
|
36102
36095
|
}
|
|
36103
|
-
var LazySlidesComponent = import_react.lazy(() => import("./reveal-component-
|
|
36096
|
+
var LazySlidesComponent = import_react.lazy(() => import("./reveal-component-CoucYkvH.js"));
|
|
36104
36097
|
const SlidesLayoutRenderer = ({ layout: e, setLayout: r, cells: c, mode: l }) => {
|
|
36105
36098
|
var _a3;
|
|
36106
36099
|
let u = useAtomValue(kioskModeAtom), d = l === "read" || u, f = useAtomValue(numColumnsAtom) > 1, [p, m] = (0, import_react.useState)(null), { cellsWithOutput: h, skippedIds: g, slideTypes: _, startCellIndex: v } = (0, import_react.useMemo)(() => computeSlideCellsInfo(c, e), [
|
|
@@ -11,67 +11,74 @@ var File = createLucideIcon("file", [["path", {
|
|
|
11
11
|
}], ["path", {
|
|
12
12
|
d: "M14 2v5a1 1 0 0 0 1 1h5",
|
|
13
13
|
key: "wfsgrz"
|
|
14
|
+
}]]), Square = createLucideIcon("square", [["rect", {
|
|
15
|
+
width: "18",
|
|
16
|
+
height: "18",
|
|
17
|
+
x: "3",
|
|
18
|
+
y: "3",
|
|
19
|
+
rx: "2",
|
|
20
|
+
key: "afitv7"
|
|
14
21
|
}]]);
|
|
15
22
|
function deserializeBlob(e) {
|
|
16
23
|
var _a;
|
|
17
|
-
let [
|
|
18
|
-
for (let e2 = 0; e2 <
|
|
19
|
-
return new Blob([
|
|
24
|
+
let [v, y] = e.split(",", 2), b = (_a = /^data:(.+);base64$/.exec(v)) == null ? void 0 : _a[1], x = atob(y), S = x.length, C = new Uint8Array(S);
|
|
25
|
+
for (let e2 = 0; e2 < S; e2++) C[e2] = x.charCodeAt(e2);
|
|
26
|
+
return new Blob([C], { type: b });
|
|
20
27
|
}
|
|
21
28
|
function defineCustomEvent(e) {
|
|
22
29
|
return () => ({
|
|
23
30
|
TYPE: e,
|
|
24
|
-
is(
|
|
25
|
-
return
|
|
31
|
+
is(v) {
|
|
32
|
+
return v.type === e;
|
|
26
33
|
},
|
|
27
|
-
create(
|
|
28
|
-
return new CustomEvent(e,
|
|
34
|
+
create(v) {
|
|
35
|
+
return new CustomEvent(e, v);
|
|
29
36
|
}
|
|
30
37
|
});
|
|
31
38
|
}
|
|
32
39
|
const MarimoValueInputEvent = defineCustomEvent("marimo-value-input")(), MarimoValueUpdateEvent = defineCustomEvent("marimo-value-update")(), MarimoValueReadyEvent = defineCustomEvent("marimo-value-ready")(), MarimoIncomingMessageEvent = defineCustomEvent("marimo-incoming-message")();
|
|
33
|
-
function createInputEvent(e,
|
|
40
|
+
function createInputEvent(e, v) {
|
|
34
41
|
return MarimoValueInputEvent.create({
|
|
35
42
|
bubbles: true,
|
|
36
43
|
composed: true,
|
|
37
44
|
detail: {
|
|
38
45
|
value: e,
|
|
39
|
-
element:
|
|
46
|
+
element: v
|
|
40
47
|
}
|
|
41
48
|
});
|
|
42
49
|
}
|
|
43
50
|
var import_compiler_runtime = require_compiler_runtime(), import_jsx_runtime = /* @__PURE__ */ __toESM(require_jsx_runtime(), 1);
|
|
44
51
|
const PythonIcon = (e) => {
|
|
45
|
-
let
|
|
46
|
-
|
|
47
|
-
let
|
|
48
|
-
return
|
|
52
|
+
let v = (0, import_compiler_runtime.c)(4), y, b;
|
|
53
|
+
v[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (y = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("title", { children: "Python Logo" }), b = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M439.8 200.5c-7.7-30.9-22.3-54.2-53.4-54.2h-40.1v47.4c0 36.8-31.2 67.8-66.8 67.8H172.7c-29.2 0-53.4 25-53.4 54.3v101.8c0 29 25.2 46 53.4 54.3 33.8 9.9 66.3 11.7 106.8 0 26.9-7.8 53.4-23.5 53.4-54.3v-40.7H226.2v-13.6h160.2c31.1 0 42.6-21.7 53.4-54.2 11.2-33.5 10.7-65.7 0-108.6zM286.2 404c11.1 0 20.1 9.1 20.1 20.3 0 11.3-9 20.4-20.1 20.4-11 0-20.1-9.2-20.1-20.4.1-11.3 9.1-20.3 20.1-20.3zM167.8 248.1h106.8c29.7 0 53.4-24.5 53.4-54.3V91.9c0-29-24.4-50.7-53.4-55.6-35.8-5.9-74.7-5.6-106.8.1-45.2 8-53.4 24.7-53.4 55.6v40.7h106.9v13.6h-147c-31.1 0-58.3 18.7-66.8 54.2-9.8 40.7-10.2 66.1 0 108.6 7.6 31.6 25.7 54.2 56.8 54.2H101v-48.8c0-35.3 30.5-66.4 66.8-66.4zm-6.7-142.6c-11.1 0-20.1-9.1-20.1-20.3.1-11.3 9-20.4 20.1-20.4 11 0 20.1 9.2 20.1 20.4s-9 20.3-20.1 20.3z" }), v[0] = y, v[1] = b) : (y = v[0], b = v[1]);
|
|
54
|
+
let x;
|
|
55
|
+
return v[2] === e ? x = v[3] : (x = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", {
|
|
49
56
|
xmlns: "http://www.w3.org/2000/svg",
|
|
50
57
|
width: "1em",
|
|
51
58
|
height: "1em",
|
|
52
59
|
fill: "currentColor",
|
|
53
60
|
viewBox: "0 0 448 512",
|
|
54
61
|
...e,
|
|
55
|
-
children: [
|
|
56
|
-
}),
|
|
62
|
+
children: [y, b]
|
|
63
|
+
}), v[2] = e, v[3] = x), x;
|
|
57
64
|
};
|
|
58
65
|
var FILE_READ_CONCURRENCY = 5;
|
|
59
|
-
function blobToString(e,
|
|
60
|
-
return new Promise((
|
|
61
|
-
let
|
|
62
|
-
|
|
66
|
+
function blobToString(e, v) {
|
|
67
|
+
return new Promise((y) => {
|
|
68
|
+
let b = new FileReader();
|
|
69
|
+
b.readAsDataURL(e), b.onload = (e2) => {
|
|
63
70
|
var _a;
|
|
64
71
|
if ((_a = e2.target) == null ? void 0 : _a.result) {
|
|
65
|
-
let
|
|
66
|
-
v
|
|
72
|
+
let b2 = e2.target.result;
|
|
73
|
+
y(v === "base64" ? b2.slice(b2.indexOf(",") + 1) : b2);
|
|
67
74
|
}
|
|
68
75
|
};
|
|
69
76
|
});
|
|
70
77
|
}
|
|
71
78
|
function filesToBase64(e) {
|
|
72
79
|
return mapWithConcurrency(e, FILE_READ_CONCURRENCY, async (e2) => {
|
|
73
|
-
let
|
|
74
|
-
return [e2.name,
|
|
80
|
+
let v = await blobToString(e2, "base64");
|
|
81
|
+
return [e2.name, v];
|
|
75
82
|
});
|
|
76
83
|
}
|
|
77
84
|
function processOutput(e) {
|
|
@@ -80,7 +87,8 @@ function processOutput(e) {
|
|
|
80
87
|
export {
|
|
81
88
|
MarimoIncomingMessageEvent as a,
|
|
82
89
|
MarimoValueUpdateEvent as c,
|
|
83
|
-
|
|
90
|
+
Square as d,
|
|
91
|
+
File as f,
|
|
84
92
|
PythonIcon as i,
|
|
85
93
|
createInputEvent as l,
|
|
86
94
|
blobToString as n,
|
|
@@ -9,7 +9,7 @@ import { t as require_compiler_runtime } from "./compiler-runtime-CEbnTgxf.js";
|
|
|
9
9
|
import { ct as kioskModeAtom } from "./html-to-image-DjEqYaQd.js";
|
|
10
10
|
import "./chunk-5FQGJX7Z-BNjes6Yx.js";
|
|
11
11
|
import { u as createLucideIcon } from "./dist-C1BYNeCR.js";
|
|
12
|
-
import { Gt as Expand, J as PanelGroup, Jt as Code, Wt as EyeOff, Y as PanelResizeHandle, a as DEFAULT_SLIDE_TYPE, c as Slide, i as DEFAULT_DECK_TRANSITION, q as Panel, s as SlideSidebar, t as useNotebookCodeAvailable } from "./code-visibility-
|
|
12
|
+
import { Gt as Expand, J as PanelGroup, Jt as Code, Wt as EyeOff, Y as PanelResizeHandle, a as DEFAULT_SLIDE_TYPE, c as Slide, i as DEFAULT_DECK_TRANSITION, q as Panel, s as SlideSidebar, t as useNotebookCodeAvailable } from "./code-visibility-BnbZdQGR.js";
|
|
13
13
|
import { q as useDebouncedCallback } from "./input-DBDlwwuD.js";
|
|
14
14
|
import "./toDate-DqrFDZlc.js";
|
|
15
15
|
import "./react-dom-BTJzcVJ9.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}
|