@marimo-team/islands 0.25.3-dev388 → 0.25.3-dev391

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/{ErrorBoundary-_mFP3LkM.js → ErrorBoundary-DNRG0xHi.js} +1 -1
  2. package/dist/{chat-ui-BKSYhGMh.js → chat-ui-CWVNPm2l.js} +769 -769
  3. package/dist/{code-visibility-DkMNjdNe.js → code-visibility-Ca8sDptK.js} +10 -10
  4. package/dist/{common-Ces9ooG_.js → common-B3NYpak4.js} +4910 -4902
  5. package/dist/{data-grid-overlay-editor-uNMslVKY.js → data-grid-overlay-editor-Cz7uMmtm.js} +1 -1
  6. package/dist/{error-entries-rtPWQkJk.js → error-entries-CnXf4kpP.js} +821 -686
  7. package/dist/{feedback-button-i960qUnq.js → feedback-button-BQbnZsf5.js} +7 -7
  8. package/dist/{glide-data-editor-_EEhlGzS.js → glide-data-editor-Bxc30klU.js} +3 -3
  9. package/dist/{globals-DKkjIolp.js → globals-CDatnx0Y.js} +1 -1
  10. package/dist/{html-to-image-B5nTOeMI.js → html-to-image-Bu_-vH_Y.js} +4782 -4765
  11. package/dist/main.js +6233 -6172
  12. package/dist/{number-overlay-editor-D5U7jbrh.js → number-overlay-editor-ChGu5C-s.js} +1 -1
  13. package/dist/{process-output-DNxpsd4n.js → process-output-Rbqr1aYD.js} +2 -2
  14. package/dist/{reveal-component-BM9TozVQ.js → reveal-component-CSxWJFAP.js} +32 -32
  15. package/dist/style.css +1 -1
  16. package/package.json +1 -1
  17. package/src/__mocks__/executions.ts +48 -8
  18. package/src/__mocks__/notebook.ts +20 -42
  19. package/src/components/app-config/__tests__/add-model-discovery.test.tsx +255 -0
  20. package/src/components/app-config/__tests__/model-discovery.test.tsx +183 -0
  21. package/src/components/app-config/ai-config.tsx +20 -24
  22. package/src/components/app-config/model-discovery.tsx +118 -184
  23. package/src/components/app-config/model-provider-config.ts +25 -0
  24. package/src/components/editor/Output.tsx +5 -4
  25. package/src/components/editor/__tests__/data-attributes.test.tsx +1 -6
  26. package/src/components/editor/__tests__/dynamic-favicon.test.tsx +11 -16
  27. package/src/components/editor/__tests__/output-persistence.test.tsx +6 -24
  28. package/src/components/editor/actions/__tests__/useSetOutputsExpanded.test.ts +6 -8
  29. package/src/components/editor/actions/useSetOutputsExpanded.ts +12 -4
  30. package/src/components/editor/cell/cell-context-menu.tsx +3 -2
  31. package/src/components/editor/errors/__tests__/send-error-report-button.test.tsx +89 -72
  32. package/src/components/editor/notebook-cell.tsx +15 -10
  33. package/src/components/editor/output/console/process-output.ts +4 -2
  34. package/src/components/editor/renderers/cells-renderer.tsx +3 -1
  35. package/src/components/editor/renderers/grid-layout/__tests__/grid-layout.test.tsx +5 -11
  36. package/src/components/editor/renderers/grid-layout/grid-layout.tsx +9 -8
  37. package/src/components/editor/renderers/types.ts +2 -2
  38. package/src/components/editor/renderers/vertical-layout/utils.ts +4 -4
  39. package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +5 -8
  40. package/src/components/scratchpad/scratchpad.tsx +6 -2
  41. package/src/components/slides/__tests__/cell-output-block.test.tsx +7 -8
  42. package/src/components/slides/__tests__/minimap-actions.test.tsx +3 -3
  43. package/src/components/slides/__tests__/slide-cell-view.test.tsx +1 -0
  44. package/src/components/slides/slide-cell-view.tsx +1 -3
  45. package/src/components/slides/slide.tsx +3 -3
  46. package/src/core/ai/context/__tests__/registry.test.ts +7 -11
  47. package/src/core/ai/context/providers/__tests__/cell-output.test.ts +113 -35
  48. package/src/core/ai/context/providers/__tests__/error.test.ts +74 -191
  49. package/src/core/ai/context/providers/cell-output.ts +11 -6
  50. package/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap +8 -103
  51. package/src/core/cells/__tests__/cells.test.ts +40 -292
  52. package/src/core/cells/__tests__/clear-outputs.test.ts +151 -0
  53. package/src/core/cells/__tests__/harness.ts +14 -12
  54. package/src/core/cells/__tests__/layout.test.ts +20 -26
  55. package/src/core/cells/__tests__/notebook-outline.test.ts +49 -43
  56. package/src/core/cells/__tests__/session.test.ts +26 -146
  57. package/src/core/cells/actions.ts +49 -9
  58. package/src/core/cells/cell.ts +0 -13
  59. package/src/core/cells/cells.ts +53 -62
  60. package/src/core/cells/focus.ts +6 -1
  61. package/src/core/cells/layout.ts +2 -3
  62. package/src/core/cells/outputs.ts +2 -2
  63. package/src/core/cells/session.ts +3 -38
  64. package/src/core/cells/types.ts +6 -8
  65. package/src/core/cells/utils.ts +4 -3
  66. package/src/core/codemirror/ai/__tests__/resources.test.ts +7 -11
  67. package/src/core/errors/__tests__/error-entries.test.ts +52 -18
  68. package/src/core/errors/error-entries.ts +21 -11
  69. package/src/core/executions/__tests__/freshness.test.ts +7 -4
  70. package/src/core/executions/__tests__/hooks.test.tsx +5 -1
  71. package/src/core/executions/__tests__/interrupt.test.ts +2 -0
  72. package/src/core/executions/__tests__/output-lifecycle.test.ts +201 -0
  73. package/src/core/executions/__tests__/output.test.ts +87 -3
  74. package/src/core/executions/__tests__/select.test.ts +17 -10
  75. package/src/core/executions/atoms.ts +73 -15
  76. package/src/core/executions/freshness.ts +1 -1
  77. package/src/core/executions/hooks.ts +18 -8
  78. package/src/core/executions/index.ts +6 -0
  79. package/src/core/executions/output.ts +122 -38
  80. package/src/core/executions/select.ts +2 -2
  81. package/src/core/export/__tests__/hooks.test.ts +20 -29
  82. package/src/core/export/hooks.ts +7 -9
  83. package/src/core/islands/__tests__/iframe-resizer.test.ts +91 -0
  84. package/src/core/islands/__tests__/main.test.ts +17 -0
  85. package/src/core/islands/components/__tests__/web-components.test.tsx +13 -15
  86. package/src/core/islands/components/output-wrapper.tsx +15 -20
  87. package/src/core/islands/iframe-resizer.ts +38 -0
  88. package/src/core/islands/main.ts +3 -0
  89. package/src/core/lifecycle/render-policy.ts +7 -4
  90. package/src/core/network/__tests__/ai.test.ts +41 -0
  91. package/src/core/network/ai.ts +12 -0
  92. package/src/core/notebook/document/__tests__/codemirror.test.ts +2 -0
  93. package/src/core/notebook/replica/__tests__/replica.test.ts +19 -0
  94. package/src/core/notebook/replica/__tests__/results.test.ts +45 -16
  95. package/src/core/notebook/replica/index.ts +1 -1
  96. package/src/core/notebook/replica/replica.ts +19 -4
  97. package/src/core/notebook/replica/resources/executions.ts +100 -9
  98. package/src/core/notebook/replica/resources/results.ts +46 -31
  99. package/src/core/transports/__tests__/static.test.ts +5 -3
  100. package/src/stories/cell.stories.tsx +40 -30
  101. package/src/stories/layout/vertical/one-column.stories.tsx +15 -7
@@ -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 configurationPending = useAtomValue(pendingConfigSavesAtom) > 0;
1693
- const savedProviderConfig =
1694
- providerName === "openrouter"
1695
- ? config.ai?.openrouter
1696
- : providerName
1697
- ? config.ai?.custom_providers?.[providerName]
1698
- : undefined;
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
- configurationKey={configurationKey}
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 onClick={handleAddModel} disabled={!hasValidValues} size="xs">
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 { useEffect, useRef, useState } from "react";
4
- import { z } from "zod";
5
- import { API } from "@/core/network/api";
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
- configurationKey: string;
21
- configurationPending: boolean;
22
- onSelect?: (modelId: string) => void;
23
- disabled?: boolean;
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
- configurationKey,
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 [models, setModels] = useState<z.infer<typeof CatalogSchema>["models"]>(
43
- [],
36
+ const query = useDeepCompareMemoize({ provider, configuration });
37
+ const [requestedQuery, setRequestedQuery] = useState<typeof query | null>(
38
+ null,
44
39
  );
45
- const [query, setQuery] = useState("");
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 requestRef = useRef<AbortController | null>(null);
52
-
53
- useEffect(() => {
54
- requestRef.current?.abort();
55
- setModels([]);
56
- setQuery("");
57
- setOpen(false);
58
- setLoaded(false);
59
- setLoading(false);
60
- setError("");
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 search = (value ?? query).trim().toLowerCase();
65
- const filtered = models.filter((model) =>
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
- className="flex flex-col gap-2 sm:flex-row sm:items-end sm:gap-4"
130
- data-testid={`model-discovery-${provider}`}
131
- >
132
- <div className="relative min-w-0 flex-1">
133
- <Popover open={open && loaded} onOpenChange={setOpen}>
134
- <PopoverPrimitive.Anchor asChild={true}>
135
- <div>
136
- <Input
137
- ref={inputRef}
138
- id={inputId}
139
- className={inputClassName ?? "w-full"}
140
- aria-label={label}
141
- aria-haspopup="dialog"
142
- aria-expanded={open && loaded}
143
- placeholder="Type a model ID or search…"
144
- value={value ?? query}
145
- onChange={(event) => {
146
- setQuery(event.target.value);
147
- onValueChange?.(event.target.value);
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
- onFocus={() => setOpen(true)}
151
- onKeyDown={(event) => {
152
- if (event.key === "Escape") {
153
- setOpen(false);
154
- }
155
- if (event.key === "Enter") {
156
- event.preventDefault();
157
- }
158
- if (event.key === "ArrowDown" && loaded) {
159
- event.preventDefault();
160
- setOpen(true);
161
- }
162
- }}
163
- />
164
- </div>
165
- </PopoverPrimitive.Anchor>
166
- <PopoverContent
167
- align="start"
168
- className="w-[var(--radix-popover-trigger-width)] min-w-64 max-w-[calc(100vw-2rem)] p-1 text-sm"
169
- style={{
170
- maxHeight:
171
- "min(18rem, var(--radix-popover-content-available-height))",
172
- overflowY: "auto",
173
- }}
174
- onOpenAutoFocus={(event) => event.preventDefault()}
175
- onCloseAutoFocus={(event) => event.preventDefault()}
176
- onInteractOutside={(event) => {
177
- if (event.target === inputRef.current) {
178
- event.preventDefault();
179
- }
180
- }}
181
- >
182
- {filtered.length === 0 ? (
183
- <p className="px-2 py-1">No models found</p>
184
- ) : (
185
- filtered.map((model) => (
186
- <button
187
- type="button"
188
- key={model.id}
189
- className="block w-full cursor-pointer rounded-sm px-2 py-1 text-left hover:bg-accent focus:bg-accent focus:outline-hidden"
190
- onClick={() => {
191
- setQuery(model.id);
192
- onValueChange?.(model.id);
193
- setOpen(false);
194
- onSelect?.(model.id);
195
- inputRef.current?.focus();
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 sm:self-end"
216
- disabled={disabled || loading || configurationPending || isWasm()}
217
- onClick={load}
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
+ }
@@ -1,7 +1,8 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
  import React, { memo, Suspense, useMemo, useRef } from "react";
3
3
  import { type CellId, CellOutputId } from "@/core/cells/ids";
4
- import type { CellOutput, OutputMessage } from "@/core/kernel/messages";
4
+ import type { CellOutput } from "@/core/executions";
5
+ import type { OutputMessage } from "@/core/kernel/messages";
5
6
  import { cn } from "@/utils/cn";
6
7
  import { logNever } from "../../utils/assertNever";
7
8
  import { ErrorBoundary } from "./boundary/ErrorBoundary";
@@ -67,7 +68,7 @@ export type OnRefactorWithAI = (opts: {
67
68
  */
68
69
  export const OutputRenderer: React.FC<{
69
70
  message: Pick<
70
- OutputMessage,
71
+ CellOutput,
71
72
  "channel" | "data" | "mimetype" | "code" | "traceback_format"
72
73
  >;
73
74
  cellId?: CellId;
@@ -280,7 +281,7 @@ const MimeBundleOutputRenderer: React.FC<{
280
281
  // Filter out metadata from the mime entries and type narrow
281
282
  const rawEntries = Objects.entries(mimebundle as Record<string, unknown>)
282
283
  .filter(([key]) => key !== METADATA_KEY)
283
- .map(([mime, data]) => [mime, data] as [MimeType, CellOutput["data"]]);
284
+ .map(([mime, data]) => [mime, data] as [MimeType, OutputMessage["data"]]);
284
285
 
285
286
  // Apply precedence ordering and hiding rules
286
287
  const { entries: mimeEntries } = processMimeBundle(rawEntries);
@@ -351,7 +352,7 @@ const MimeBundleOutputRenderer: React.FC<{
351
352
  MimeBundleOutputRenderer.displayName = "MimeBundleOutputRenderer";
352
353
 
353
354
  interface OutputAreaProps {
354
- output: OutputMessage | null;
355
+ output: CellOutput | null;
355
356
  cellId: CellId;
356
357
  stale: boolean;
357
358
  loading: boolean;
@@ -109,12 +109,7 @@ describe("Cell data attributes", () => {
109
109
  },
110
110
  });
111
111
 
112
- notebook.cellRuntime[cid] = createCellRuntimeState({
113
- output: null,
114
- consoleOutputs: [],
115
- debuggerActive: false,
116
- outline: null,
117
- });
112
+ notebook.cellRuntime[cid] = createCellRuntimeState();
118
113
 
119
114
  store.set(notebookAtom, notebook);
120
115
 
@@ -8,6 +8,7 @@ import {
8
8
  import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
9
9
  import { Provider, createStore } from "jotai";
10
10
  import type { ReactNode } from "react";
11
+ import { MockExecutions } from "@/__mocks__/executions";
11
12
  import { MockNotebook } from "@/__mocks__/notebook";
12
13
  import { cellId } from "@/__tests__/branded";
13
14
  import { notebookAtom } from "@/core/cells/cells";
@@ -25,16 +26,13 @@ describe("DynamicFavicon", () => {
25
26
  }
26
27
 
27
28
  function setErrors() {
28
- store.set(
29
- notebookAtom,
30
- MockNotebook.notebookStateWithErrors([
31
- {
32
- cellId: id,
33
- cellName: "cell",
34
- errorData: [MockNotebook.errors.syntax("Invalid syntax")],
35
- },
36
- ]),
37
- );
29
+ MockNotebook.withErrors(store, [
30
+ {
31
+ cellId: id,
32
+ cellName: "cell",
33
+ error: { kind: "invalid-syntax", message: "Invalid syntax" },
34
+ },
35
+ ]);
38
36
  }
39
37
 
40
38
  beforeEach(() => {
@@ -211,12 +209,9 @@ describe("DynamicFavicon", () => {
211
209
  act(() => setErrors());
212
210
  await waitFor(() => expect(favicon.href).toContain("circle-x.ico"));
213
211
 
214
- act(() =>
215
- store.set(
216
- notebookAtom,
217
- MockNotebook.notebookState({ cellData: { [id]: {} } }),
218
- ),
219
- );
212
+ act(() => {
213
+ MockExecutions.seed(store, []);
214
+ });
220
215
  await waitFor(() => expect(favicon.href).toContain("circle-check.ico"));
221
216
  });
222
217
 
@@ -16,14 +16,13 @@ import {
16
16
  document as documentOf,
17
17
  withCells,
18
18
  } from "@/core/notebook/document/__tests__/fixtures";
19
- import type { CellRuntimeState } from "@/core/cells/types";
20
- import { createCellRuntimeState } from "@/core/cells/types";
21
19
  import { defaultUserConfig } from "@/core/config/config-schema";
22
20
  import type { AppMode } from "@/core/mode";
23
21
  import { requestClientAtom } from "@/core/network/requests";
24
22
  import { Cell } from "../notebook-cell";
25
23
 
26
24
  const cid = cellId("test");
25
+ const PERSIST = { mimetype: "text/html", data: "<span>persist me</span>" };
27
26
 
28
27
  function createTestWrapper() {
29
28
  const store = createStore();
@@ -37,10 +36,7 @@ function createTestWrapper() {
37
36
  return { wrapper, store };
38
37
  }
39
38
 
40
- function seedNotebook(
41
- store: ReturnType<typeof createStore>,
42
- runtimeOverrides: Partial<CellRuntimeState> = {},
43
- ) {
39
+ function seedNotebook(store: ReturnType<typeof createStore>) {
44
40
  const notebook = MockNotebook.notebookState({
45
41
  cellData: {
46
42
  [cid]: {
@@ -54,15 +50,6 @@ function seedNotebook(
54
50
  },
55
51
  },
56
52
  });
57
- notebook.cellRuntime[cid] = createCellRuntimeState({
58
- output: {
59
- channel: "output",
60
- mimetype: "text/html",
61
- data: "<span>persist me</span>",
62
- timestamp: 0,
63
- },
64
- ...runtimeOverrides,
65
- });
66
53
  store.set(notebookAtom, notebook);
67
54
  }
68
55
 
@@ -94,6 +81,7 @@ beforeAll(() => {
94
81
  describe("output persistence across mode changes", () => {
95
82
  it("preserves the output DOM node when toggling edit <-> present", () => {
96
83
  const { store, wrapper } = createTestWrapper();
84
+ MockExecutions.seed(store, [MockExecutions.shown(cid, PERSIST)]);
97
85
  seedNotebook(store);
98
86
 
99
87
  const { container, rerender } = render(renderCell("edit"), { wrapper });
@@ -144,6 +132,7 @@ describe("output persistence across mode changes", () => {
144
132
 
145
133
  it("hides all edit chrome while presenting", () => {
146
134
  const { store, wrapper } = createTestWrapper();
135
+ MockExecutions.seed(store, [MockExecutions.shown(cid, PERSIST)]);
147
136
  seedNotebook(store);
148
137
 
149
138
  const { container, rerender } = render(renderCell("edit"), { wrapper });
@@ -195,7 +184,7 @@ describe("output persistence across mode changes", () => {
195
184
  // The host holds newer source than the cell last ran with
196
185
  MockExecutions.seed(
197
186
  store,
198
- [MockExecutions.completed(cid, { code_fingerprint: "ran" })],
187
+ [MockExecutions.shown(cid, PERSIST, { code_fingerprint: "ran" })],
199
188
  null,
200
189
  withCells(
201
190
  documentOf(),
@@ -223,14 +212,7 @@ describe("output persistence across mode changes", () => {
223
212
  it("hides errored cells while presenting without unmounting them", () => {
224
213
  const { store, wrapper } = createTestWrapper();
225
214
  MockExecutions.seed(store, [MockExecutions.errored(cid)]);
226
- seedNotebook(store, {
227
- output: {
228
- channel: "marimo-error",
229
- mimetype: "application/vnd.marimo+error",
230
- data: [{ type: "exception", exception_type: "ValueError", msg: "!" }],
231
- timestamp: 0,
232
- },
233
- });
215
+ seedNotebook(store);
234
216
 
235
217
  const { container, rerender } = render(renderCell("edit"), { wrapper });
236
218