@marimo-team/islands 0.23.10-dev34 → 0.23.10-dev36
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-DmBropAy.js → ConnectedDataExplorerComponent-Z3RP7Vmm.js} +1 -1
- package/dist/{any-language-editor-DNmoSiWL.js → any-language-editor-CAgFD4Kd.js} +1 -1
- package/dist/{chat-ui-D6oraHT2.js → chat-ui-CJOUDE_t.js} +3 -3
- package/dist/{code-visibility-D36VZAff.js → code-visibility-DC9HexXh.js} +3 -3
- package/dist/{error-banner-Cc0I3C9e.js → error-banner-CJXYJ6Sb.js} +10 -5
- package/dist/{html-to-image-UEH5lFDZ.js → html-to-image-D3CbHZwH.js} +1 -1
- package/dist/main.js +1030 -1020
- package/dist/{mermaid-zuLgJ8J8.js → mermaid-BotvIKg9.js} +1 -1
- package/dist/{process-output-CyMLTogj.js → process-output-MAetFLBT.js} +1 -1
- package/dist/{reveal-component-DyqkAt3A.js → reveal-component-BBpwXvOt.js} +2 -2
- package/dist/{vega-component-9h1ACS78.js → vega-component-DGPUhbDs.js} +1 -1
- package/package.json +1 -1
- package/src/plugins/core/__test__/registerReactComponent.test.ts +96 -0
- package/src/plugins/core/registerReactComponent.tsx +42 -10
- package/src/utils/errors.ts +9 -0
|
@@ -5,7 +5,7 @@ import { t as require_compiler_runtime } from "./compiler-runtime-CEbnTgxf.js";
|
|
|
5
5
|
import "./react-dom-BTJzcVJ9.js";
|
|
6
6
|
import { t as require_jsx_runtime } from "./jsx-runtime-DebpN0FN.js";
|
|
7
7
|
import "./zod-aLSua2NL.js";
|
|
8
|
-
import { n as ErrorBanner } from "./error-banner-
|
|
8
|
+
import { n as ErrorBanner } from "./error-banner-CJXYJ6Sb.js";
|
|
9
9
|
import { t as isEmpty_default } from "./isEmpty-CJJMn-QP.js";
|
|
10
10
|
import { n as useTheme } from "./useTheme-DEhDzATN.js";
|
|
11
11
|
import { t as purify } from "./purify.es-H92eMd9-.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { s as __toESM } from "./chunk-BNovOVIE.js";
|
|
2
2
|
import { t as require_compiler_runtime } from "./compiler-runtime-CEbnTgxf.js";
|
|
3
|
-
import { at as parseHtmlContent, it as ansiToPlainText } from "./html-to-image-
|
|
3
|
+
import { at as parseHtmlContent, it as ansiToPlainText } from "./html-to-image-D3CbHZwH.js";
|
|
4
4
|
import { u as createLucideIcon } from "./dist-Dk6PV_d3.js";
|
|
5
5
|
import { t as Strings } from "./strings-J57tzLr3.js";
|
|
6
6
|
import { t as require_jsx_runtime } from "./jsx-runtime-DebpN0FN.js";
|
|
@@ -6,10 +6,10 @@ import { s as __toESM } from "./chunk-BNovOVIE.js";
|
|
|
6
6
|
import { _ as Logger, g as cn, h as Events, l as useEventListener, t as Button } from "./button-C5K9fIPF.js";
|
|
7
7
|
import { t as require_react } from "./react-DA-nE2FX.js";
|
|
8
8
|
import { t as require_compiler_runtime } from "./compiler-runtime-CEbnTgxf.js";
|
|
9
|
-
import { lt as kioskModeAtom } from "./html-to-image-
|
|
9
|
+
import { lt as kioskModeAtom } from "./html-to-image-D3CbHZwH.js";
|
|
10
10
|
import "./chunk-5FQGJX7Z-BNjes6Yx.js";
|
|
11
11
|
import { u as createLucideIcon } from "./dist-Dk6PV_d3.js";
|
|
12
|
-
import { a as DEFAULT_SLIDE_TYPE, c as Slide, ct as PanelResizeHandle, i as DEFAULT_DECK_TRANSITION, in as Expand, ot as Panel, rn as EyeOff, s as SlideSidebar, sn as Code, st as PanelGroup, t as useNotebookCodeAvailable } from "./code-visibility-
|
|
12
|
+
import { a as DEFAULT_SLIDE_TYPE, c as Slide, ct as PanelResizeHandle, i as DEFAULT_DECK_TRANSITION, in as Expand, ot as Panel, rn as EyeOff, s as SlideSidebar, sn as Code, st as PanelGroup, t as useNotebookCodeAvailable } from "./code-visibility-DC9HexXh.js";
|
|
13
13
|
import { J as useDebouncedCallback } from "./input-CMYy4hzj.js";
|
|
14
14
|
import "./toDate-d8RCRrRd.js";
|
|
15
15
|
import "./react-dom-BTJzcVJ9.js";
|
|
@@ -6,7 +6,7 @@ import { c as asRemoteURL, v as CircleQuestionMark } from "./toDate-d8RCRrRd.js"
|
|
|
6
6
|
import "./react-dom-BTJzcVJ9.js";
|
|
7
7
|
import { t as require_jsx_runtime } from "./jsx-runtime-DebpN0FN.js";
|
|
8
8
|
import "./zod-aLSua2NL.js";
|
|
9
|
-
import { n as ErrorBanner } from "./error-banner-
|
|
9
|
+
import { n as ErrorBanner } from "./error-banner-CJXYJ6Sb.js";
|
|
10
10
|
import { t as Tooltip } from "./tooltip-DpcyNkQ2.js";
|
|
11
11
|
import { i as debounce_default } from "./constants-T20xxyNf.js";
|
|
12
12
|
import { T as useEvent_default, n as useTheme } from "./useTheme-DEhDzATN.js";
|
package/package.json
CHANGED
|
@@ -3,11 +3,20 @@
|
|
|
3
3
|
import ReactDOM from "react-dom/client";
|
|
4
4
|
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
|
5
5
|
import { z } from "zod";
|
|
6
|
+
import { FUNCTIONS_REGISTRY } from "@/core/functions/FunctionRegistry";
|
|
7
|
+
import type { FunctionCallResultMessage } from "@/core/kernel/messages";
|
|
8
|
+
import { FunctionNotFoundError } from "@/utils/errors";
|
|
6
9
|
import {
|
|
7
10
|
isCustomMarimoElement,
|
|
8
11
|
registerReactComponent,
|
|
9
12
|
} from "../registerReactComponent";
|
|
10
13
|
|
|
14
|
+
vi.mock("@/core/functions/FunctionRegistry", () => ({
|
|
15
|
+
FUNCTIONS_REGISTRY: { request: vi.fn() },
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
const requestMock = vi.mocked(FUNCTIONS_REGISTRY.request);
|
|
19
|
+
|
|
11
20
|
// Each custom element name can only be registered once per jsdom window,
|
|
12
21
|
// so we use a counter to generate unique tag names across tests.
|
|
13
22
|
let tagCounter = 0;
|
|
@@ -202,3 +211,90 @@ describe("connectedCallback - light DOM nesting detection", () => {
|
|
|
202
211
|
outer.remove();
|
|
203
212
|
});
|
|
204
213
|
});
|
|
214
|
+
|
|
215
|
+
describe("plugin function: not-found recovery", () => {
|
|
216
|
+
const NOT_FOUND: FunctionCallResultMessage = {
|
|
217
|
+
function_call_id:
|
|
218
|
+
"call-id" as FunctionCallResultMessage["function_call_id"],
|
|
219
|
+
status: { code: "error", message: "Function not found" },
|
|
220
|
+
found: false,
|
|
221
|
+
return_value: null,
|
|
222
|
+
};
|
|
223
|
+
const OK: FunctionCallResultMessage = {
|
|
224
|
+
function_call_id:
|
|
225
|
+
"call-id" as FunctionCallResultMessage["function_call_id"],
|
|
226
|
+
status: { code: "ok" },
|
|
227
|
+
found: true,
|
|
228
|
+
return_value: { ok: true },
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
// Mount a plugin exposing a single callable function and resolve the
|
|
232
|
+
// function map that PluginSlot hands to render(), so tests can invoke the
|
|
233
|
+
// request path directly.
|
|
234
|
+
async function mountWithFunction(): Promise<
|
|
235
|
+
(args: Record<string, unknown>) => Promise<unknown>
|
|
236
|
+
> {
|
|
237
|
+
const tag = uniqueTag("fn");
|
|
238
|
+
let captured:
|
|
239
|
+
| ((args: Record<string, unknown>) => Promise<unknown>)
|
|
240
|
+
| undefined;
|
|
241
|
+
registerReactComponent({
|
|
242
|
+
tagName: tag,
|
|
243
|
+
validator: z.any(),
|
|
244
|
+
functions: { run: { input: z.any(), output: z.any() } },
|
|
245
|
+
render: ({ functions }) => {
|
|
246
|
+
captured = (functions as Record<string, typeof captured>).run;
|
|
247
|
+
return null as never;
|
|
248
|
+
},
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
const wrapper = document.createElement("marimo-ui-element");
|
|
252
|
+
wrapper.setAttribute("object-id", "test-object-id");
|
|
253
|
+
const el = document.createElement(tag);
|
|
254
|
+
wrapper.append(el);
|
|
255
|
+
document.body.append(wrapper);
|
|
256
|
+
|
|
257
|
+
await vi.waitFor(() => expect(captured).toBeDefined());
|
|
258
|
+
return captured as (args: Record<string, unknown>) => Promise<unknown>;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
beforeEach(() => {
|
|
262
|
+
requestMock.mockReset();
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
afterEach(() => {
|
|
266
|
+
document.body.innerHTML = "";
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
test("retries on found:false and resolves once the function appears", async () => {
|
|
270
|
+
const run = await mountWithFunction();
|
|
271
|
+
requestMock.mockResolvedValueOnce(NOT_FOUND).mockResolvedValueOnce(OK);
|
|
272
|
+
|
|
273
|
+
await expect(run({})).resolves.toEqual({ ok: true });
|
|
274
|
+
expect(requestMock).toHaveBeenCalledTimes(2);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
test("throws FunctionNotFoundError after retries are exhausted", async () => {
|
|
278
|
+
const run = await mountWithFunction();
|
|
279
|
+
requestMock.mockResolvedValue(NOT_FOUND);
|
|
280
|
+
|
|
281
|
+
await expect(run({})).rejects.toBeInstanceOf(FunctionNotFoundError);
|
|
282
|
+
// Initial attempt plus three retries.
|
|
283
|
+
expect(requestMock).toHaveBeenCalledTimes(4);
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
test("does not retry once the function is found (found:true)", async () => {
|
|
287
|
+
const run = await mountWithFunction();
|
|
288
|
+
requestMock.mockResolvedValue({
|
|
289
|
+
function_call_id:
|
|
290
|
+
"call-id" as FunctionCallResultMessage["function_call_id"],
|
|
291
|
+
status: { code: "error", message: "boom" },
|
|
292
|
+
found: true,
|
|
293
|
+
return_value: null,
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
const promise = run({});
|
|
297
|
+
await expect(promise).rejects.toThrow("boom");
|
|
298
|
+
expect(requestMock).toHaveBeenCalledTimes(1);
|
|
299
|
+
});
|
|
300
|
+
});
|
|
@@ -40,7 +40,10 @@ import {
|
|
|
40
40
|
} from "@/hooks/useEventListener";
|
|
41
41
|
import { StyleNamespace } from "@/theme/namespace";
|
|
42
42
|
import { useTheme } from "@/theme/useTheme";
|
|
43
|
-
import {
|
|
43
|
+
import {
|
|
44
|
+
CellNotInitializedError,
|
|
45
|
+
FunctionNotFoundError,
|
|
46
|
+
} from "@/utils/errors.ts";
|
|
44
47
|
import { Functions } from "@/utils/functions";
|
|
45
48
|
import { shallowCompare } from "@/utils/shallow-compare";
|
|
46
49
|
import { defineCustomElement } from "../../core/dom/defineCustomElement";
|
|
@@ -80,6 +83,12 @@ export interface IMarimoHTMLElement extends HTMLElement {
|
|
|
80
83
|
rerender: () => void;
|
|
81
84
|
}
|
|
82
85
|
|
|
86
|
+
// Bounded exponential backoff for re-issuing a request whose function the
|
|
87
|
+
// kernel reported as not found. Short enough to fail fast on a genuinely
|
|
88
|
+
// missing function, long enough to outlast a transient object-id desync.
|
|
89
|
+
const FUNCTION_NOT_FOUND_MAX_RETRIES = 3;
|
|
90
|
+
const FUNCTION_NOT_FOUND_BASE_DELAY_MS = 150;
|
|
91
|
+
|
|
83
92
|
interface PluginSlotProps<T> {
|
|
84
93
|
hostElement: HTMLElement;
|
|
85
94
|
plugin: IPlugin<T, unknown>;
|
|
@@ -188,8 +197,6 @@ function PluginSlotInternal<T>(
|
|
|
188
197
|
args.length <= 1,
|
|
189
198
|
`Plugin functions only supports a single argument. Called ${key}`,
|
|
190
199
|
);
|
|
191
|
-
const objectId = getUIElementObjectId(hostElement);
|
|
192
|
-
invariant(objectId, "Object ID should exist");
|
|
193
200
|
|
|
194
201
|
const isStatic = isStaticNotebook();
|
|
195
202
|
|
|
@@ -218,16 +225,41 @@ function PluginSlotInternal<T>(
|
|
|
218
225
|
Logger.warn(`Cell ID ${cellId} cannot be found`);
|
|
219
226
|
}
|
|
220
227
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
228
|
+
// A "function not found" response means the kernel never ran the
|
|
229
|
+
// function, so re-issuing the request is side-effect-safe regardless
|
|
230
|
+
// of whether the function is idempotent. This recovers from a
|
|
231
|
+
// transient window where the frontend's object-id leads the kernel's
|
|
232
|
+
// registry. The object-id is re-read each attempt so a corrected id
|
|
233
|
+
// from a re-render is picked up. Once the function is found
|
|
234
|
+
// (found === true) the request is never retried, since the failure
|
|
235
|
+
// is unrelated to lookup and retrying would not help.
|
|
236
|
+
const parsedArgs = prettyParse(input, args[0]);
|
|
237
|
+
for (let attempt = 0; ; attempt++) {
|
|
238
|
+
const namespace = getUIElementObjectId(hostElement);
|
|
239
|
+
invariant(namespace, "Object ID should exist");
|
|
240
|
+
|
|
241
|
+
const response = await FUNCTIONS_REGISTRY.request({
|
|
242
|
+
args: parsedArgs,
|
|
243
|
+
functionName: key,
|
|
244
|
+
namespace,
|
|
245
|
+
});
|
|
246
|
+
if (response.status.code === "ok") {
|
|
247
|
+
return prettyParse(output, response.return_value);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const recoverable = response.found === false;
|
|
251
|
+
if (recoverable && attempt < FUNCTION_NOT_FOUND_MAX_RETRIES) {
|
|
252
|
+
const delay = FUNCTION_NOT_FOUND_BASE_DELAY_MS * 2 ** attempt;
|
|
253
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
|
|
227
257
|
Logger.error(response.status);
|
|
258
|
+
if (recoverable) {
|
|
259
|
+
throw new FunctionNotFoundError();
|
|
260
|
+
}
|
|
228
261
|
throw new Error(response.status.message || "Unknown error");
|
|
229
262
|
}
|
|
230
|
-
return prettyParse(output, response.return_value);
|
|
231
263
|
};
|
|
232
264
|
}
|
|
233
265
|
|
package/src/utils/errors.ts
CHANGED
|
@@ -71,6 +71,15 @@ export class CellNotInitializedError extends Error {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
export class FunctionNotFoundError extends Error {
|
|
75
|
+
constructor(
|
|
76
|
+
message = "This UI element could not reach its function on the kernel. Try re-running the cell.",
|
|
77
|
+
) {
|
|
78
|
+
super(message);
|
|
79
|
+
this.name = "FunctionNotFoundError";
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
74
83
|
export class NoKernelConnectedError extends Error {
|
|
75
84
|
constructor(message = "Not yet connected to a kernel.") {
|
|
76
85
|
super(message);
|