@marimo-team/islands 0.25.3-dev388 → 0.25.3-dev394
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/{ConnectedDataExplorerComponent-BpCrAeX0.js → ConnectedDataExplorerComponent-1DGGwl88.js} +9 -9
- package/dist/{ErrorBoundary-_mFP3LkM.js → ErrorBoundary-DDIASniH.js} +6 -6
- package/dist/{abnfDiagram-VCTEODGH-ZqNgGZlz.js → abnfDiagram-VCTEODGH-CeQEbVik.js} +2 -2
- package/dist/{any-language-editor-CFbAr7vc.js → any-language-editor-C_s_ZoaK.js} +2 -2
- package/dist/{architectureDiagram-5GKGNRK7-BEUaR96d.js → architectureDiagram-5GKGNRK7-C8xUpTAb.js} +1 -1
- package/dist/{assertNever-5uYEbJc8.js → assertNever-DXGfUmPW.js} +2 -2
- package/dist/assets/__vite-browser-external-C9HF3uHE.js +1 -0
- package/dist/assets/worker-B4Cpvr8b.js +171 -0
- package/dist/{chat-ui-BKSYhGMh.js → chat-ui-B6bY_0LF.js} +774 -774
- package/dist/{check-BbhVyViy.js → check-ywinAQy6.js} +1 -1
- package/dist/{chunk-IMKFNOWR-BdEPmWQI.js → chunk-IMKFNOWR-DY7AWyNi.js} +1 -1
- package/dist/{chunk-SHT3W25Y-IvvXM3xf.js → chunk-SHT3W25Y-D4epY9MY.js} +1 -1
- package/dist/{chunk-SVP7TREG-C_qpJUv1.js → chunk-SVP7TREG-CKsl2Q6r.js} +1 -1
- package/dist/{chunk-TICWLB2K-C4agYVWP.js → chunk-TICWLB2K-CMsD2y0F.js} +1 -1
- package/dist/{classDiagram-ZZMXUADV-CT2iq8uF.js → classDiagram-ZZMXUADV-C4FsLnvt.js} +2 -2
- package/dist/{classDiagram-v2-VYDZK3BY-Coe_dD0r.js → classDiagram-v2-VYDZK3BY-BJRuFZeI.js} +2 -2
- package/dist/{code-visibility-DkMNjdNe.js → code-visibility-CByYqwFv.js} +13 -13
- package/dist/{common-Ces9ooG_.js → common-KkgATX2Y.js} +4918 -4910
- package/dist/{config-DJ8M-gPL.js → config-DOwBtRkI.js} +3 -3
- package/dist/{copy-icon-xWvA8ybp.js → copy-icon-BKcX0ltw.js} +2 -2
- package/dist/{createReducer-fp0gX_9U.js → createReducer-Bjx6kuxh.js} +1 -1
- package/dist/{cynefinDiagram-5FMLGOSQ-D0LKziUu.js → cynefinDiagram-5FMLGOSQ-DyI_lSsn.js} +1 -1
- package/dist/{dagre-GXQ25YYZ-Cmgziaw8.js → dagre-GXQ25YYZ-Buoy6sX-.js} +1 -1
- package/dist/{data-grid-overlay-editor-uNMslVKY.js → data-grid-overlay-editor-BHrTJhN3.js} +1 -1
- package/dist/{diagram-S7CK7UJ4-D-lZsALU.js → diagram-S7CK7UJ4-CbSD1DUy.js} +1 -1
- package/dist/{diagram-UQ7AKVKN-TcbdsFoT.js → diagram-UQ7AKVKN-Dapj2rQm.js} +1 -1
- package/dist/{diagram-VX7I27RA-D5BqZi1q.js → diagram-VX7I27RA-CxA3txtC.js} +1 -1
- package/dist/{diagram-Z3DM3KII-MNc7jqvr.js → diagram-Z3DM3KII-BEZqz916.js} +1 -1
- package/dist/{dialog-Cm0VGdxc.js → dialog-mwa6XN15.js} +2 -2
- package/dist/{dropdown-menu-DfamXjVI.js → dropdown-menu-CmgUseHo.js} +5 -5
- package/dist/duckdb-keywords-CdzX4o33.js +3 -0
- package/dist/{ebnfDiagram-PWID7BFC-Cxt6ywyX.js → ebnfDiagram-PWID7BFC-Dmw-1JV3.js} +2 -2
- package/dist/{erDiagram-RLTQ6QDP-BLF-askI.js → erDiagram-RLTQ6QDP-DZpG4cbm.js} +1 -1
- package/dist/{error-banner-k06CAftu.js → error-banner-CHPLqogX.js} +1 -1
- package/dist/{error-entries-rtPWQkJk.js → error-entries-Bk96zt4w.js} +825 -690
- package/dist/{feedback-button-i960qUnq.js → feedback-button-2FaWjlaR.js} +12 -12
- package/dist/{flowDiagram-HODETNUW-CsLw2mWn.js → flowDiagram-HODETNUW-B02oHnBv.js} +2 -2
- package/dist/{formats-DQ-qq-dU.js → formats-BDqe9cfr.js} +1 -1
- package/dist/{glide-data-editor-_EEhlGzS.js → glide-data-editor-B9Yq6Wg1.js} +11 -11
- package/dist/{glide-utils-CHrghEu-.js → glide-utils-DYKWS2YV.js} +2 -2
- package/dist/{globals-DKkjIolp.js → globals-S4D5AVKN.js} +3 -3
- package/dist/{html-to-image-B5nTOeMI.js → html-to-image-BauFF9F_.js} +4842 -4821
- package/dist/{infoDiagram-27XIBGKW-CdSApBWg.js → infoDiagram-27XIBGKW-BPbQHO9m.js} +1 -1
- package/dist/{ishikawaDiagram-5VMMS53U-BnzQ8SI5.js → ishikawaDiagram-5VMMS53U-DmnKSNi7.js} +1 -1
- package/dist/{kanban-definition-UXKFOSKX-D2llTpeX.js → kanban-definition-UXKFOSKX-u5PZbsBe.js} +1 -1
- package/dist/main.js +6236 -6175
- package/dist/{mermaid-BcNMyKmf.js → mermaid-ffopDjig.js} +34 -34
- package/dist/{mindmap-definition-YA3MSWOX-uoEsfD5R.js → mindmap-definition-YA3MSWOX-CX187lhP.js} +1 -1
- package/dist/{number-overlay-editor-D5U7jbrh.js → number-overlay-editor-l7DB2HCO.js} +1 -1
- package/dist/{pegDiagram-XKGWAZYB-DTWrE0S4.js → pegDiagram-XKGWAZYB-Bj6HGPak.js} +2 -2
- package/dist/{pencil-weySvN0N.js → pencil-CijoRsa3.js} +1 -1
- package/dist/{pieDiagram-E7YTZNPT-COME2oGN.js → pieDiagram-E7YTZNPT-C_wIgDJM.js} +1 -1
- package/dist/{process-output-DNxpsd4n.js → process-output-Deae7dX1.js} +4 -4
- package/dist/{railroadDiagram-O6MQD6OU-CUeFcNTY.js → railroadDiagram-O6MQD6OU-CwoJvnvC.js} +2 -2
- package/dist/{requirementDiagram-BXWQKSXE-BUR4lDZG.js → requirementDiagram-BXWQKSXE-C8JuhLLL.js} +1 -1
- package/dist/{reveal-component-BM9TozVQ.js → reveal-component-VR4UzAUv.js} +37 -37
- package/dist/{select-Ca-POp4c.js → select-DW32QOzC.js} +4 -4
- package/dist/{sequenceDiagram-WJ2MYXX4-CSPmml3q.js → sequenceDiagram-WJ2MYXX4-RbrRdoiV.js} +1 -1
- package/dist/{spec-BgSMwzks.js → spec-Ww0JjShW.js} +4 -4
- package/dist/{stateDiagram-D77RDMKH-BDUC8Pi9.js → stateDiagram-D77RDMKH-DWdIvCnU.js} +2 -2
- package/dist/{stateDiagram-v2-MP3YSRHH-BH-qyk8a.js → stateDiagram-v2-MP3YSRHH-BG0j9crW.js} +2 -2
- package/dist/{static-state-Cqzv5X7B.js → static-state-CnQdTBTW.js} +1 -1
- package/dist/style.css +1 -1
- package/dist/{swimlanes-42K2YHIH-CLE9Kiir.js → swimlanes-42K2YHIH-B6zUw4gq.js} +1 -1
- package/dist/{swimlanesDiagram-VR7AAH4N-Cv8kWAeA.js → swimlanesDiagram-VR7AAH4N-DjVEnsIG.js} +2 -2
- package/dist/{timeline-definition-24CTP7MA-fbRGX21i.js → timeline-definition-24CTP7MA-DSAxwqnC.js} +1 -1
- package/dist/{toast-0xspcdmv.js → toast-Crofa36R.js} +3 -3
- package/dist/{tooltip-BwlFTaNy.js → tooltip-Bg-SDCwa.js} +1 -1
- package/dist/{use-restore-focus-fKgXR0nb.js → use-restore-focus-CE9Sflmg.js} +1298 -1283
- package/dist/{useDateFormatter-B7LvPmsw.js → useDateFormatter-D5fsC9ot.js} +2 -2
- package/dist/{useDeepCompareMemoize-OhBYt-q2.js → useDeepCompareMemoize-Bvrue1iy.js} +1 -1
- package/dist/{useLifecycle-D9xcFAIN.js → useLifecycle-Ctr5lECo.js} +1 -1
- package/dist/{vega-component-Chak9Aon.js → vega-component-DQZhTzVQ.js} +6 -6
- package/dist/{vennDiagram-4TSXK5OY-BzKtg8gL.js → vennDiagram-4TSXK5OY-FAGYRdBj.js} +1 -1
- package/dist/{wardleyDiagram-VM6X3IG4-R0SgDvz1.js → wardleyDiagram-VM6X3IG4-BlB973r1.js} +1 -1
- package/dist/{xychartDiagram-S5SC5T6Z-DRskTHEM.js → xychartDiagram-S5SC5T6Z-CywvmjIK.js} +1 -1
- package/package.json +2 -2
- package/src/__mocks__/executions.ts +48 -8
- package/src/__mocks__/notebook.ts +20 -42
- package/src/components/app-config/__tests__/add-model-discovery.test.tsx +255 -0
- package/src/components/app-config/__tests__/model-discovery.test.tsx +183 -0
- package/src/components/app-config/ai-config.tsx +20 -24
- package/src/components/app-config/model-discovery.tsx +118 -184
- package/src/components/app-config/model-provider-config.ts +25 -0
- package/src/components/editor/Output.tsx +5 -4
- package/src/components/editor/__tests__/data-attributes.test.tsx +1 -6
- package/src/components/editor/__tests__/dynamic-favicon.test.tsx +11 -16
- package/src/components/editor/__tests__/output-persistence.test.tsx +6 -24
- package/src/components/editor/actions/__tests__/useSetOutputsExpanded.test.ts +6 -8
- package/src/components/editor/actions/useSetOutputsExpanded.ts +12 -4
- package/src/components/editor/cell/cell-context-menu.tsx +3 -2
- package/src/components/editor/errors/__tests__/send-error-report-button.test.tsx +89 -72
- package/src/components/editor/notebook-cell.tsx +15 -10
- package/src/components/editor/output/console/process-output.ts +4 -2
- package/src/components/editor/renderers/cells-renderer.tsx +3 -1
- package/src/components/editor/renderers/grid-layout/__tests__/grid-layout.test.tsx +5 -11
- package/src/components/editor/renderers/grid-layout/grid-layout.tsx +9 -8
- package/src/components/editor/renderers/types.ts +2 -2
- package/src/components/editor/renderers/vertical-layout/utils.ts +4 -4
- package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +5 -8
- package/src/components/scratchpad/scratchpad.tsx +6 -2
- package/src/components/slides/__tests__/cell-output-block.test.tsx +7 -8
- package/src/components/slides/__tests__/minimap-actions.test.tsx +3 -3
- package/src/components/slides/__tests__/slide-cell-view.test.tsx +1 -0
- package/src/components/slides/slide-cell-view.tsx +1 -3
- package/src/components/slides/slide.tsx +3 -3
- package/src/core/ai/context/__tests__/registry.test.ts +7 -11
- package/src/core/ai/context/providers/__tests__/cell-output.test.ts +113 -35
- package/src/core/ai/context/providers/__tests__/error.test.ts +74 -191
- package/src/core/ai/context/providers/cell-output.ts +11 -6
- package/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap +8 -103
- package/src/core/cells/__tests__/cells.test.ts +40 -292
- package/src/core/cells/__tests__/clear-outputs.test.ts +151 -0
- package/src/core/cells/__tests__/harness.ts +14 -12
- package/src/core/cells/__tests__/layout.test.ts +20 -26
- package/src/core/cells/__tests__/notebook-outline.test.ts +49 -43
- package/src/core/cells/__tests__/session.test.ts +26 -146
- package/src/core/cells/actions.ts +49 -9
- package/src/core/cells/cell.ts +0 -13
- package/src/core/cells/cells.ts +53 -62
- package/src/core/cells/focus.ts +6 -1
- package/src/core/cells/layout.ts +2 -3
- package/src/core/cells/outputs.ts +2 -2
- package/src/core/cells/session.ts +3 -38
- package/src/core/cells/types.ts +6 -8
- package/src/core/cells/utils.ts +4 -3
- package/src/core/codemirror/ai/__tests__/resources.test.ts +7 -11
- package/src/core/config/config-schema.ts +15 -0
- package/src/core/errors/__tests__/error-entries.test.ts +52 -18
- package/src/core/errors/error-entries.ts +21 -11
- package/src/core/executions/__tests__/freshness.test.ts +7 -4
- package/src/core/executions/__tests__/hooks.test.tsx +5 -1
- package/src/core/executions/__tests__/interrupt.test.ts +2 -0
- package/src/core/executions/__tests__/output-lifecycle.test.ts +201 -0
- package/src/core/executions/__tests__/output.test.ts +87 -3
- package/src/core/executions/__tests__/select.test.ts +17 -10
- package/src/core/executions/atoms.ts +73 -15
- package/src/core/executions/freshness.ts +1 -1
- package/src/core/executions/hooks.ts +18 -8
- package/src/core/executions/index.ts +6 -0
- package/src/core/executions/output.ts +122 -38
- package/src/core/executions/select.ts +2 -2
- package/src/core/export/__tests__/hooks.test.ts +20 -29
- package/src/core/export/hooks.ts +7 -9
- package/src/core/islands/__tests__/iframe-resizer.test.ts +91 -0
- package/src/core/islands/__tests__/main.test.ts +17 -0
- package/src/core/islands/components/__tests__/web-components.test.tsx +13 -15
- package/src/core/islands/components/output-wrapper.tsx +15 -20
- package/src/core/islands/iframe-resizer.ts +38 -0
- package/src/core/islands/main.ts +3 -0
- package/src/core/lifecycle/render-policy.ts +7 -4
- package/src/core/network/__tests__/ai.test.ts +41 -0
- package/src/core/network/ai.ts +12 -0
- package/src/core/notebook/document/__tests__/codemirror.test.ts +2 -0
- package/src/core/notebook/replica/__tests__/replica.test.ts +19 -0
- package/src/core/notebook/replica/__tests__/results.test.ts +45 -16
- package/src/core/notebook/replica/index.ts +1 -1
- package/src/core/notebook/replica/replica.ts +19 -4
- package/src/core/notebook/replica/resources/executions.ts +100 -9
- package/src/core/notebook/replica/resources/results.ts +46 -31
- package/src/core/transports/__tests__/static.test.ts +5 -3
- package/src/stories/cell.stories.tsx +40 -30
- package/src/stories/layout/vertical/one-column.stories.tsx +15 -7
- package/dist/assets/__vite-browser-external-C5NhJPNJ.js +0 -1
- package/dist/assets/worker-D-n8vtGi.js +0 -171
- package/dist/duckdb-keywords-BGArYVVK.js +0 -3
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
act,
|
|
5
|
+
fireEvent,
|
|
6
|
+
render,
|
|
7
|
+
screen,
|
|
8
|
+
waitFor,
|
|
9
|
+
} from "@testing-library/react";
|
|
10
|
+
import { useState } from "react";
|
|
11
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
12
|
+
import { listProviderModels } from "@/core/network/ai";
|
|
13
|
+
import { HTTPError } from "@/utils/errors";
|
|
14
|
+
import { ModelDiscovery } from "../model-discovery";
|
|
15
|
+
|
|
16
|
+
vi.mock("@/core/network/ai", () => ({ listProviderModels: vi.fn() }));
|
|
17
|
+
vi.mock("@/core/wasm/utils", () => ({ isWasm: () => false }));
|
|
18
|
+
|
|
19
|
+
function Discovery({
|
|
20
|
+
configuration = "saved",
|
|
21
|
+
provider = "gateway",
|
|
22
|
+
disabled = false,
|
|
23
|
+
}) {
|
|
24
|
+
const [value, setValue] = useState("");
|
|
25
|
+
return (
|
|
26
|
+
<ModelDiscovery
|
|
27
|
+
provider={provider}
|
|
28
|
+
configuration={{ base_url: `https://${configuration}.example.com/v1` }}
|
|
29
|
+
label="Model"
|
|
30
|
+
inputId="model"
|
|
31
|
+
disabled={disabled}
|
|
32
|
+
value={value}
|
|
33
|
+
onValueChange={setValue}
|
|
34
|
+
/>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const search = () =>
|
|
39
|
+
screen.getByRole("button", { name: "Search available models" });
|
|
40
|
+
|
|
41
|
+
describe("ModelDiscovery", () => {
|
|
42
|
+
beforeEach(() => vi.mocked(listProviderModels).mockReset());
|
|
43
|
+
|
|
44
|
+
it("loads on demand and fills the editable model field on selection", async () => {
|
|
45
|
+
vi.mocked(listProviderModels).mockResolvedValue({
|
|
46
|
+
models: [{ id: "org/model", name: "Model name" }],
|
|
47
|
+
});
|
|
48
|
+
render(<Discovery />);
|
|
49
|
+
expect(listProviderModels).not.toHaveBeenCalled();
|
|
50
|
+
|
|
51
|
+
fireEvent.change(screen.getByLabelText("Model"), {
|
|
52
|
+
target: { value: "manual-id" },
|
|
53
|
+
});
|
|
54
|
+
expect(screen.getByLabelText("Model")).toHaveValue("manual-id");
|
|
55
|
+
fireEvent.change(screen.getByLabelText("Model"), { target: { value: "" } });
|
|
56
|
+
fireEvent.click(search());
|
|
57
|
+
await screen.findByRole("button", { name: "Model name — org/model" });
|
|
58
|
+
fireEvent.keyDown(screen.getByLabelText("Model"), { key: "Escape" });
|
|
59
|
+
fireEvent.keyDown(screen.getByLabelText("Model"), { key: "ArrowDown" });
|
|
60
|
+
await waitFor(() =>
|
|
61
|
+
expect(
|
|
62
|
+
screen.getByRole("button", { name: "Model name — org/model" }),
|
|
63
|
+
).toHaveFocus(),
|
|
64
|
+
);
|
|
65
|
+
fireEvent.click(
|
|
66
|
+
screen.getByRole("button", { name: "Model name — org/model" }),
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
expect(listProviderModels).toHaveBeenCalledExactlyOnceWith("gateway");
|
|
70
|
+
expect(screen.getByLabelText("Model")).toHaveValue("org/model");
|
|
71
|
+
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("shows backend error details and allows retrying", async () => {
|
|
75
|
+
vi.mocked(listProviderModels)
|
|
76
|
+
.mockRejectedValueOnce(
|
|
77
|
+
new HTTPError(400, "Bad Request", {
|
|
78
|
+
detail: "Provider rejected credentials.",
|
|
79
|
+
}),
|
|
80
|
+
)
|
|
81
|
+
.mockResolvedValueOnce({ models: [] });
|
|
82
|
+
render(<Discovery />);
|
|
83
|
+
fireEvent.click(search());
|
|
84
|
+
expect(await screen.findByRole("alert")).toHaveTextContent(
|
|
85
|
+
"Provider rejected credentials.",
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
fireEvent.click(search());
|
|
89
|
+
expect(await screen.findByText("No models found")).toBeInTheDocument();
|
|
90
|
+
expect(screen.queryByRole("alert")).not.toBeInTheDocument();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("keeps focus in the input when reopening after navigating an open catalog", async () => {
|
|
94
|
+
vi.mocked(listProviderModels).mockResolvedValue({
|
|
95
|
+
models: [{ id: "model-a", name: "Model A" }],
|
|
96
|
+
});
|
|
97
|
+
render(<Discovery />);
|
|
98
|
+
fireEvent.click(search());
|
|
99
|
+
const option = await screen.findByRole("button", {
|
|
100
|
+
name: "Model A — model-a",
|
|
101
|
+
});
|
|
102
|
+
const input = screen.getByLabelText("Model");
|
|
103
|
+
fireEvent.keyDown(input, { key: "ArrowDown" });
|
|
104
|
+
expect(option).toHaveFocus();
|
|
105
|
+
fireEvent.keyDown(input, { key: "Escape" });
|
|
106
|
+
await waitFor(() =>
|
|
107
|
+
expect(screen.queryByRole("dialog")).not.toBeInTheDocument(),
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
act(() => input.focus());
|
|
111
|
+
await screen.findByRole("dialog");
|
|
112
|
+
await waitFor(() => expect(input).toHaveFocus());
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("discards outstanding results when the saved configuration changes", async () => {
|
|
116
|
+
const pending =
|
|
117
|
+
Promise.withResolvers<Awaited<ReturnType<typeof listProviderModels>>>();
|
|
118
|
+
vi.mocked(listProviderModels).mockReturnValueOnce(pending.promise);
|
|
119
|
+
const { rerender } = render(<Discovery />);
|
|
120
|
+
fireEvent.click(search());
|
|
121
|
+
await waitFor(() => expect(listProviderModels).toHaveBeenCalledOnce());
|
|
122
|
+
const input = screen.getByLabelText("Model");
|
|
123
|
+
act(() => input.focus());
|
|
124
|
+
|
|
125
|
+
rerender(<Discovery configuration="changed" disabled={true} />);
|
|
126
|
+
expect(screen.getByLabelText("Model")).toBe(input);
|
|
127
|
+
expect(input).toHaveFocus();
|
|
128
|
+
expect(search()).toBeDisabled();
|
|
129
|
+
await act(async () =>
|
|
130
|
+
pending.resolve({ models: [{ id: "stale", name: "Stale model" }] }),
|
|
131
|
+
);
|
|
132
|
+
expect(screen.queryByText("Stale model — stale")).not.toBeInTheDocument();
|
|
133
|
+
|
|
134
|
+
rerender(<Discovery configuration="saved-again" />);
|
|
135
|
+
expect(search()).toBeEnabled();
|
|
136
|
+
expect(listProviderModels).toHaveBeenCalledOnce();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("discards a loaded catalog when settings change without replacing the input", async () => {
|
|
140
|
+
vi.mocked(listProviderModels).mockResolvedValue({
|
|
141
|
+
models: [{ id: "old-model", name: "Old model" }],
|
|
142
|
+
});
|
|
143
|
+
const { rerender } = render(<Discovery />);
|
|
144
|
+
fireEvent.click(search());
|
|
145
|
+
await screen.findByRole("button", { name: "Old model — old-model" });
|
|
146
|
+
const input = screen.getByLabelText("Model");
|
|
147
|
+
act(() => input.focus());
|
|
148
|
+
|
|
149
|
+
rerender(<Discovery configuration="changed" />);
|
|
150
|
+
expect(screen.getByLabelText("Model")).toBe(input);
|
|
151
|
+
expect(input).toHaveFocus();
|
|
152
|
+
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
|
153
|
+
expect(listProviderModels).toHaveBeenCalledOnce();
|
|
154
|
+
|
|
155
|
+
const pending =
|
|
156
|
+
Promise.withResolvers<Awaited<ReturnType<typeof listProviderModels>>>();
|
|
157
|
+
vi.mocked(listProviderModels).mockReturnValueOnce(pending.promise);
|
|
158
|
+
fireEvent.click(search());
|
|
159
|
+
await waitFor(() => expect(listProviderModels).toHaveBeenCalledTimes(2));
|
|
160
|
+
expect(screen.queryByText("Old model — old-model")).not.toBeInTheDocument();
|
|
161
|
+
|
|
162
|
+
await act(async () =>
|
|
163
|
+
pending.resolve({ models: [{ id: "new-model", name: "New model" }] }),
|
|
164
|
+
);
|
|
165
|
+
await screen.findByRole("button", { name: "New model — new-model" });
|
|
166
|
+
expect(screen.queryByText("Old model — old-model")).not.toBeInTheDocument();
|
|
167
|
+
expect(listProviderModels).toHaveBeenCalledTimes(2);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("requires a new search when the provider changes", async () => {
|
|
171
|
+
vi.mocked(listProviderModels).mockResolvedValue({ models: [] });
|
|
172
|
+
const { rerender } = render(<Discovery />);
|
|
173
|
+
fireEvent.click(search());
|
|
174
|
+
await screen.findByText("No models found");
|
|
175
|
+
|
|
176
|
+
rerender(<Discovery provider="another-provider" />);
|
|
177
|
+
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
|
178
|
+
expect(listProviderModels).toHaveBeenCalledOnce();
|
|
179
|
+
fireEvent.click(search());
|
|
180
|
+
await screen.findByText("No models found");
|
|
181
|
+
expect(listProviderModels).toHaveBeenLastCalledWith("another-provider");
|
|
182
|
+
});
|
|
183
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
|
+
import { dequal } from "dequal";
|
|
3
4
|
import { useAtom, useAtomValue } from "jotai";
|
|
4
5
|
import {
|
|
5
6
|
BotIcon,
|
|
@@ -85,6 +86,7 @@ import { Tooltip } from "../ui/tooltip";
|
|
|
85
86
|
import { formItemClasses, SettingSubtitle } from "./common";
|
|
86
87
|
import { AWS_REGIONS } from "./constants";
|
|
87
88
|
import { ModelDiscovery } from "./model-discovery";
|
|
89
|
+
import { getModelProviderConfig } from "./model-provider-config";
|
|
88
90
|
import { IncorrectModelId } from "./incorrect-model-id";
|
|
89
91
|
import {
|
|
90
92
|
IsOverridden,
|
|
@@ -1689,14 +1691,13 @@ export const AddModelForm: React.FC<{
|
|
|
1689
1691
|
!!providerName &&
|
|
1690
1692
|
(providerName === "openrouter" ||
|
|
1691
1693
|
customProviderNames.includes(providerName));
|
|
1692
|
-
const
|
|
1693
|
-
const
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
const configurationKey = JSON.stringify(savedProviderConfig ?? null);
|
|
1694
|
+
const draftAi = useWatch({ control: form.control, name: "ai" });
|
|
1695
|
+
const effectiveAi = useAtomValue(resolvedMarimoConfigAtom).ai;
|
|
1696
|
+
const savedProvider = getModelProviderConfig(config.ai, providerName);
|
|
1697
|
+
const draftProvider = getModelProviderConfig(draftAi, providerName);
|
|
1698
|
+
const effectiveProvider = getModelProviderConfig(effectiveAi, providerName);
|
|
1699
|
+
const isSaving = useAtomValue(pendingConfigSavesAtom) > 0;
|
|
1700
|
+
const hasUnsavedChanges = !dequal(savedProvider, draftProvider);
|
|
1700
1701
|
const hasValidValues = providerName?.trim() && modelName?.trim();
|
|
1701
1702
|
|
|
1702
1703
|
const resetForm = () => {
|
|
@@ -1833,10 +1834,7 @@ export const AddModelForm: React.FC<{
|
|
|
1833
1834
|
|
|
1834
1835
|
const modelInput = (
|
|
1835
1836
|
<div
|
|
1836
|
-
className={cn(
|
|
1837
|
-
"flex items-center gap-2",
|
|
1838
|
-
isCustomProvider && "self-start",
|
|
1839
|
-
)}
|
|
1837
|
+
className={cn("flex items-start gap-2", isCustomProvider && "self-start")}
|
|
1840
1838
|
>
|
|
1841
1839
|
<Label
|
|
1842
1840
|
htmlFor={modelNameInputId}
|
|
@@ -1846,11 +1844,10 @@ export const AddModelForm: React.FC<{
|
|
|
1846
1844
|
</Label>
|
|
1847
1845
|
{canDiscoverModels && providerName ? (
|
|
1848
1846
|
<ModelDiscovery
|
|
1849
|
-
key={providerName}
|
|
1850
1847
|
provider={providerName}
|
|
1848
|
+
configuration={effectiveProvider}
|
|
1851
1849
|
label="Model"
|
|
1852
|
-
|
|
1853
|
-
configurationPending={configurationPending}
|
|
1850
|
+
disabled={isSaving || hasUnsavedChanges}
|
|
1854
1851
|
inputId={modelNameInputId}
|
|
1855
1852
|
inputClassName="text-xs mb-0"
|
|
1856
1853
|
value={modelName}
|
|
@@ -1869,22 +1866,21 @@ export const AddModelForm: React.FC<{
|
|
|
1869
1866
|
);
|
|
1870
1867
|
|
|
1871
1868
|
const inputForm = (
|
|
1872
|
-
<div
|
|
1873
|
-
className={cn(
|
|
1874
|
-
"flex items-center gap-3 p-3 border border-border rounded-md",
|
|
1875
|
-
canDiscoverModels &&
|
|
1876
|
-
"relative pb-12 [&_[data-testid^='model-discovery-']>button]:absolute [&_[data-testid^='model-discovery-']>button]:right-3 [&_[data-testid^='model-discovery-']>button]:bottom-3",
|
|
1877
|
-
)}
|
|
1878
|
-
>
|
|
1869
|
+
<div className="flex flex-wrap items-start gap-3 p-3 border border-border rounded-md">
|
|
1879
1870
|
{providerSelect}
|
|
1880
1871
|
{modelInput}
|
|
1881
1872
|
<div
|
|
1882
1873
|
className={cn("flex gap-1.5 ml-auto", isCustomProvider && "self-end")}
|
|
1883
1874
|
>
|
|
1884
|
-
<Button
|
|
1875
|
+
<Button
|
|
1876
|
+
type="button"
|
|
1877
|
+
onClick={handleAddModel}
|
|
1878
|
+
disabled={!hasValidValues}
|
|
1879
|
+
size="xs"
|
|
1880
|
+
>
|
|
1885
1881
|
Add
|
|
1886
1882
|
</Button>
|
|
1887
|
-
<Button variant="outline" onClick={resetForm} size="xs">
|
|
1883
|
+
<Button type="button" variant="outline" onClick={resetForm} size="xs">
|
|
1888
1884
|
Cancel
|
|
1889
1885
|
</Button>
|
|
1890
1886
|
</div>
|
|
@@ -1,220 +1,154 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { getRuntimeManager } from "@/core/runtime/config";
|
|
3
|
+
import { Popover as PopoverPrimitive } from "radix-ui";
|
|
4
|
+
import { useRef, useState } from "react";
|
|
5
|
+
import { listProviderModels } from "@/core/network/ai";
|
|
7
6
|
import { isWasm } from "@/core/wasm/utils";
|
|
7
|
+
import { useAsyncData } from "@/hooks/useAsyncData";
|
|
8
|
+
import { useDeepCompareMemoize } from "@/hooks/useDeepCompareMemoize";
|
|
9
|
+
import { prettyError } from "@/utils/errors";
|
|
8
10
|
import { Button } from "../ui/button";
|
|
9
11
|
import { Input } from "../ui/input";
|
|
10
|
-
import { Popover as PopoverPrimitive } from "radix-ui";
|
|
11
12
|
import { Popover, PopoverContent } from "../ui/popover";
|
|
12
|
-
|
|
13
|
-
const CatalogSchema = z.object({
|
|
14
|
-
models: z.array(z.object({ id: z.string().min(1), name: z.string() })),
|
|
15
|
-
});
|
|
13
|
+
import type { ModelProviderConfig } from "./model-provider-config";
|
|
16
14
|
|
|
17
15
|
interface ModelDiscoveryProps {
|
|
18
16
|
provider: string;
|
|
17
|
+
configuration: ModelProviderConfig;
|
|
19
18
|
label: string;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
value?: string;
|
|
25
|
-
onValueChange?: (value: string) => void;
|
|
26
|
-
inputId?: string;
|
|
19
|
+
disabled: boolean;
|
|
20
|
+
value: string;
|
|
21
|
+
onValueChange: (value: string) => void;
|
|
22
|
+
inputId: string;
|
|
27
23
|
inputClassName?: string;
|
|
28
24
|
}
|
|
29
25
|
|
|
30
26
|
export function ModelDiscovery({
|
|
31
27
|
provider,
|
|
28
|
+
configuration,
|
|
32
29
|
label,
|
|
33
|
-
|
|
34
|
-
configurationPending,
|
|
35
|
-
onSelect,
|
|
36
|
-
disabled = false,
|
|
30
|
+
disabled,
|
|
37
31
|
value,
|
|
38
32
|
onValueChange,
|
|
39
33
|
inputId,
|
|
40
34
|
inputClassName,
|
|
41
35
|
}: ModelDiscoveryProps) {
|
|
42
|
-
const
|
|
43
|
-
|
|
36
|
+
const query = useDeepCompareMemoize({ provider, configuration });
|
|
37
|
+
const [requestedQuery, setRequestedQuery] = useState<typeof query | null>(
|
|
38
|
+
null,
|
|
44
39
|
);
|
|
45
|
-
const
|
|
46
|
-
const inputRef = useRef<HTMLInputElement | null>(null);
|
|
47
|
-
const [loading, setLoading] = useState(false);
|
|
48
|
-
const [loaded, setLoaded] = useState(false);
|
|
49
|
-
const [error, setError] = useState("");
|
|
40
|
+
const requested = requestedQuery === query;
|
|
50
41
|
const [open, setOpen] = useState(false);
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return () => requestRef.current?.abort();
|
|
62
|
-
}, [provider, configurationKey]);
|
|
42
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
43
|
+
const optionsRef = useRef<HTMLDivElement>(null);
|
|
44
|
+
const focusOptionsOnOpen = useRef(false);
|
|
45
|
+
const { data, error, isFetching, refetch } = useAsyncData(async () => {
|
|
46
|
+
if (!requested || disabled) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const catalog = await listProviderModels(provider);
|
|
50
|
+
return { query, ...catalog };
|
|
51
|
+
}, [query, requested, disabled]);
|
|
63
52
|
|
|
64
|
-
const
|
|
65
|
-
const
|
|
53
|
+
const catalog = requested && data?.query === query ? data : undefined;
|
|
54
|
+
const catalogError = requested ? error : undefined;
|
|
55
|
+
const loading = requested && !disabled && isFetching;
|
|
56
|
+
const search = value.trim().toLowerCase();
|
|
57
|
+
const filtered = catalog?.models.filter((model) =>
|
|
66
58
|
`${model.name} ${model.id}`.toLowerCase().includes(search),
|
|
67
59
|
);
|
|
68
60
|
|
|
69
|
-
const load = async () => {
|
|
70
|
-
requestRef.current?.abort();
|
|
71
|
-
const controller = new AbortController();
|
|
72
|
-
requestRef.current = controller;
|
|
73
|
-
setLoading(true);
|
|
74
|
-
setError("");
|
|
75
|
-
try {
|
|
76
|
-
const url = getRuntimeManager().httpURL;
|
|
77
|
-
url.search = "";
|
|
78
|
-
url.hash = "";
|
|
79
|
-
url.pathname = `${url.pathname.replace(/\/$/, "")}/api/ai/models/${encodeURIComponent(provider)}`;
|
|
80
|
-
const response = await fetch(url.toString(), {
|
|
81
|
-
headers: API.headers(),
|
|
82
|
-
signal: controller.signal,
|
|
83
|
-
});
|
|
84
|
-
if (!response.ok) {
|
|
85
|
-
const raw = await response.text();
|
|
86
|
-
let detail = "";
|
|
87
|
-
|
|
88
|
-
try {
|
|
89
|
-
const parsed = z
|
|
90
|
-
.object({ detail: z.string() })
|
|
91
|
-
.safeParse(JSON.parse(raw));
|
|
92
|
-
|
|
93
|
-
detail = parsed.success ? parsed.data.detail : "";
|
|
94
|
-
} catch {
|
|
95
|
-
// The backend may return a non-JSON error response.
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (!controller.signal.aborted) {
|
|
99
|
-
setError(
|
|
100
|
-
detail ||
|
|
101
|
-
"Unable to load the provider model catalog. Check the connection and retry.",
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
const catalog = CatalogSchema.parse(await response.json());
|
|
108
|
-
if (controller.signal.aborted) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
setModels(catalog.models);
|
|
112
|
-
setLoaded(true);
|
|
113
|
-
setOpen(true);
|
|
114
|
-
} catch {
|
|
115
|
-
if (!controller.signal.aborted) {
|
|
116
|
-
setError(
|
|
117
|
-
"Unable to load a valid catalog. Check the connection and retry.",
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
} finally {
|
|
121
|
-
if (!controller.signal.aborted) {
|
|
122
|
-
setLoading(false);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
|
|
127
61
|
return (
|
|
128
|
-
<div
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
62
|
+
<div className="flex min-w-0 flex-col gap-2">
|
|
63
|
+
<Popover open={open && !!catalog && !disabled} onOpenChange={setOpen}>
|
|
64
|
+
<PopoverPrimitive.Anchor asChild={true}>
|
|
65
|
+
<div>
|
|
66
|
+
<Input
|
|
67
|
+
ref={inputRef}
|
|
68
|
+
id={inputId}
|
|
69
|
+
className={inputClassName}
|
|
70
|
+
aria-label={label}
|
|
71
|
+
aria-haspopup="dialog"
|
|
72
|
+
aria-expanded={open && !!catalog && !disabled}
|
|
73
|
+
placeholder="Type a model ID or search…"
|
|
74
|
+
value={value}
|
|
75
|
+
onChange={(event) => {
|
|
76
|
+
onValueChange(event.target.value);
|
|
77
|
+
setOpen(true);
|
|
78
|
+
}}
|
|
79
|
+
onFocus={() => setOpen(true)}
|
|
80
|
+
onKeyDown={(event) => {
|
|
81
|
+
if (event.key === "Escape") {
|
|
82
|
+
setOpen(false);
|
|
83
|
+
}
|
|
84
|
+
if (event.key === "Enter") {
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
}
|
|
87
|
+
if (event.key === "ArrowDown" && catalog) {
|
|
88
|
+
event.preventDefault();
|
|
89
|
+
focusOptionsOnOpen.current = !open;
|
|
148
90
|
setOpen(true);
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
setOpen(false);
|
|
197
|
-
}}
|
|
198
|
-
>
|
|
199
|
-
{model.name} — {model.id}
|
|
200
|
-
</button>
|
|
201
|
-
))
|
|
202
|
-
)}
|
|
203
|
-
</PopoverContent>
|
|
204
|
-
</Popover>
|
|
205
|
-
{error && (
|
|
206
|
-
<p role="alert" className="mt-1 text-sm text-destructive">
|
|
207
|
-
{error}
|
|
208
|
-
</p>
|
|
209
|
-
)}
|
|
210
|
-
</div>
|
|
91
|
+
optionsRef.current?.querySelector("button")?.focus();
|
|
92
|
+
}
|
|
93
|
+
}}
|
|
94
|
+
/>
|
|
95
|
+
</div>
|
|
96
|
+
</PopoverPrimitive.Anchor>
|
|
97
|
+
<PopoverContent
|
|
98
|
+
ref={optionsRef}
|
|
99
|
+
align="start"
|
|
100
|
+
className="w-[var(--radix-popover-trigger-width)] min-w-64 max-w-[calc(100vw-2rem)] max-h-72 overflow-y-auto p-1 text-sm"
|
|
101
|
+
onOpenAutoFocus={(event) => {
|
|
102
|
+
if (!focusOptionsOnOpen.current) {
|
|
103
|
+
event.preventDefault();
|
|
104
|
+
}
|
|
105
|
+
focusOptionsOnOpen.current = false;
|
|
106
|
+
}}
|
|
107
|
+
onCloseAutoFocus={(event) => event.preventDefault()}
|
|
108
|
+
onInteractOutside={(event) => {
|
|
109
|
+
if (event.target === inputRef.current) {
|
|
110
|
+
event.preventDefault();
|
|
111
|
+
}
|
|
112
|
+
}}
|
|
113
|
+
>
|
|
114
|
+
{filtered?.length === 0 && (
|
|
115
|
+
<p className="px-2 py-1">No models found</p>
|
|
116
|
+
)}
|
|
117
|
+
{filtered?.map((model) => (
|
|
118
|
+
<button
|
|
119
|
+
type="button"
|
|
120
|
+
key={model.id}
|
|
121
|
+
className="block w-full cursor-pointer rounded-sm px-2 py-1 text-left hover:bg-accent focus:bg-accent focus:outline-hidden"
|
|
122
|
+
onClick={() => {
|
|
123
|
+
onValueChange(model.id);
|
|
124
|
+
inputRef.current?.focus();
|
|
125
|
+
setOpen(false);
|
|
126
|
+
}}
|
|
127
|
+
>
|
|
128
|
+
{model.name} — {model.id}
|
|
129
|
+
</button>
|
|
130
|
+
))}
|
|
131
|
+
</PopoverContent>
|
|
132
|
+
</Popover>
|
|
133
|
+
{catalogError && (
|
|
134
|
+
<p role="alert" className="text-sm text-destructive">
|
|
135
|
+
{prettyError(catalogError)}
|
|
136
|
+
</p>
|
|
137
|
+
)}
|
|
211
138
|
<Button
|
|
212
139
|
type="button"
|
|
213
140
|
variant="outline"
|
|
214
141
|
size="xs"
|
|
215
|
-
className="self-start
|
|
216
|
-
disabled={disabled || loading ||
|
|
217
|
-
onClick={
|
|
142
|
+
className="self-start"
|
|
143
|
+
disabled={disabled || loading || isWasm()}
|
|
144
|
+
onClick={() => {
|
|
145
|
+
setOpen(true);
|
|
146
|
+
if (requested) {
|
|
147
|
+
refetch();
|
|
148
|
+
} else {
|
|
149
|
+
setRequestedQuery(query);
|
|
150
|
+
}
|
|
151
|
+
}}
|
|
218
152
|
>
|
|
219
153
|
{loading ? "Loading models…" : "Search available models"}
|
|
220
154
|
</Button>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { omit } from "lodash-es";
|
|
4
|
+
import type { UserConfig } from "@/core/config/config-schema";
|
|
5
|
+
|
|
6
|
+
type AiConfig = NonNullable<UserConfig["ai"]>;
|
|
7
|
+
export type ModelProviderConfig = NonNullable<AiConfig["openrouter"]>;
|
|
8
|
+
|
|
9
|
+
export function getModelProviderConfig(
|
|
10
|
+
ai: UserConfig["ai"],
|
|
11
|
+
providerName: string | null,
|
|
12
|
+
): ModelProviderConfig {
|
|
13
|
+
let selected = providerName
|
|
14
|
+
? ai?.custom_providers?.[providerName]
|
|
15
|
+
: undefined;
|
|
16
|
+
if (!selected && providerName === "openrouter") {
|
|
17
|
+
selected = ai?.openrouter;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const config = selected ?? {};
|
|
21
|
+
const unsetKeys = Object.entries(config)
|
|
22
|
+
.filter(([, value]) => value === undefined)
|
|
23
|
+
.map(([key]) => key);
|
|
24
|
+
return omit(config, unsetKeys);
|
|
25
|
+
}
|