@marimo-team/frontend 0.22.5-dev21 → 0.22.5-dev24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{CellStatus-CP1jrQ3A.js → CellStatus-CNNGwOIK.js} +1 -1
- package/dist/assets/{JsonOutput-Bk2by9qo.js → JsonOutput-9XtRRx5l.js} +2 -2
- package/dist/assets/{MarimoErrorOutput-Cyd8ikG3.js → MarimoErrorOutput-Bc9JufDr.js} +1 -1
- package/dist/assets/{RenderHTML-BOW_1WUn.js → RenderHTML-0dk6-mYI.js} +1 -1
- package/dist/assets/{add-cell-with-ai-DUq7Y523.js → add-cell-with-ai-CLklC7KS.js} +1 -1
- package/dist/assets/{add-connection-dialog-20N0EHLl.js → add-connection-dialog-ux7eCDRM.js} +1 -1
- package/dist/assets/{agent-panel-DEza5aFa.js → agent-panel-CiMrqUfl.js} +1 -1
- package/dist/assets/{ai-model-dropdown-B-sbS07W.js → ai-model-dropdown-CRtaHcCu.js} +1 -1
- package/dist/assets/{app-config-button-CJFpYJ_2.js → app-config-button-CnX21edo.js} +1 -1
- package/dist/assets/{cell-editor-DLL6kX__.js → cell-editor-D7IQ3F4W.js} +1 -1
- package/dist/assets/{cell-link-Dtonmtv_.js → cell-link-CcAqXeeg.js} +1 -1
- package/dist/assets/{cells-BVG4a-Qn.js → cells-EJo3u4za.js} +3 -3
- package/dist/assets/{chat-display-DsIGz-Wy.js → chat-display-BxDRpNsl.js} +1 -1
- package/dist/assets/{chat-panel-aXOgktdv.js → chat-panel-dBoLqgjH.js} +1 -1
- package/dist/assets/{chat-ui-C--RApyx.js → chat-ui-DdZo1L-v.js} +1 -1
- package/dist/assets/{column-preview-CB_HZPdz.js → column-preview-DrU255Z3.js} +1 -1
- package/dist/assets/{command-palette-DLKNdcX_.js → command-palette-n6NnK6GP.js} +1 -1
- package/dist/assets/{common-CLVI2BhO.js → common-Bty2yo-n.js} +1 -1
- package/dist/assets/{components-DiALLQRt.js → components-B8TZ_vT_.js} +1 -1
- package/dist/assets/{components-CGwwQ0Y4.js → components-Dh-L-jYg.js} +1 -1
- package/dist/assets/config-DoZCLcOb.js +1 -0
- package/dist/assets/{datasource-BzTPyEw3.js → datasource-DY0N42ZB.js} +1 -1
- package/dist/assets/{dependency-graph-panel-Pxmnzmd4.js → dependency-graph-panel-C23HsAdh.js} +1 -1
- package/dist/assets/{documentation-panel-bgaPBvan.js → documentation-panel-okcEKCQM.js} +1 -1
- package/dist/assets/{download-QIfZjflb.js → download-TSo32ofd.js} +1 -1
- package/dist/assets/{edit-page-DB_go-vo.js → edit-page-RhmoqI7E.js} +3 -3
- package/dist/assets/{error-panel-DfHzC7q-.js → error-panel-aq2j0jIa.js} +1 -1
- package/dist/assets/{file-explorer-panel-CEd-m832.js → file-explorer-panel-CzYUz358.js} +1 -1
- package/dist/assets/{file-icons-ma7AC7Pi.js → file-icons-DBaXCICA.js} +1 -1
- package/dist/assets/{floating-outline-BluCz3vD.js → floating-outline-BTmyhMGv.js} +1 -1
- package/dist/assets/{focus-BHXzPxK_.js → focus-DXeddo75.js} +1 -1
- package/dist/assets/{form-C0W8wa3f.js → form-BiDLPu7R.js} +1 -1
- package/dist/assets/{globals-Bh85lAn7.js → globals-DQM2RvzM.js} +1 -1
- package/dist/assets/{home-page-nNrKA7jH.js → home-page-BntiR5eS.js} +1 -1
- package/dist/assets/{hooks-C7qnb_ft.js → hooks-BgwM3Mb2.js} +1 -1
- package/dist/assets/{html-to-image-B3VySJ1_.js → html-to-image-BJiJlwQY.js} +1 -1
- package/dist/assets/{index-CLnKZIHZ.js → index-CMEhtk8a.js} +5 -5
- package/dist/assets/{kiosk-mode-BSY8y4kL.js → kiosk-mode-JCcLyeoQ.js} +1 -1
- package/dist/assets/{layout-V4eTNc4M.js → layout-CF-7BNtf.js} +1 -1
- package/dist/assets/{logs-panel-B1AysC8S.js → logs-panel-BzhPrie8.js} +1 -1
- package/dist/assets/{markdown-renderer-BiKTlki_.js → markdown-renderer-B9RsGqHb.js} +1 -1
- package/dist/assets/{name-cell-input-BA5B0KJl.js → name-cell-input-CYsY4A1G.js} +1 -1
- package/dist/assets/{outline-panel-BfGPA_Sj.js → outline-panel-BCAWCKi6.js} +1 -1
- package/dist/assets/{packages-panel-BgoT3rrV.js → packages-panel-5axf3DuF.js} +1 -1
- package/dist/assets/{panels-BeW4RaML.js → panels-7-kbDRzv.js} +1 -1
- package/dist/assets/{process-output-MnxG8jwi.js → process-output-DqiZsqG9.js} +1 -1
- package/dist/assets/{readonly-python-code-DuH_nOq_.js → readonly-python-code-D8ITm60r.js} +1 -1
- package/dist/assets/{run-page-kI3bwb2R.js → run-page-9OQqe8IY.js} +1 -1
- package/dist/assets/{scratchpad-panel-617FvSKA.js → scratchpad-panel-DkqxnSH6.js} +1 -1
- package/dist/assets/{session-panel-D6Sf5vhq.js → session-panel-BuzMiMf3.js} +1 -1
- package/dist/assets/{snippets-panel-DfWq0wh2.js → snippets-panel--mh2FUXA.js} +1 -1
- package/dist/assets/{state-urfwd716.js → state-6D_2UAw3.js} +1 -1
- package/dist/assets/{state-Blw6taKi.js → state-BDrig0S2.js} +1 -1
- package/dist/assets/{switch-C2idsSNO.js → switch-C6xjg01T.js} +1 -1
- package/dist/assets/{terminal-BBTjIXBz.js → terminal-BEaHyVIQ.js} +1 -1
- package/dist/assets/{textarea-B5p9_myy.js → textarea-Cfp3upzK.js} +1 -1
- package/dist/assets/{tracing-CazNvlp4.js → tracing-BExYhl1z.js} +1 -1
- package/dist/assets/{tracing-panel-Bj0Bx8ZJ.js → tracing-panel-Co5DeX-F.js} +2 -2
- package/dist/assets/{useAddCell-g3zSMJKs.js → useAddCell-BaTlDxTu.js} +1 -1
- package/dist/assets/{useBoolean-ugd5JdXd.js → useBoolean-BvsK1Xcs.js} +1 -1
- package/dist/assets/{useCellActionButton-DdsVswP2.js → useCellActionButton-DftkIqUl.js} +1 -1
- package/dist/assets/{useDeleteCell-CIdiI4Pk.js → useDeleteCell-d6yWnL3H.js} +1 -1
- package/dist/assets/{useDependencyPanelTab-DhXqfAqL.js → useDependencyPanelTab-BaVcOBM4.js} +1 -1
- package/dist/assets/{useNotebookActions-ULfiGMMl.js → useNotebookActions-DihtSJ4g.js} +1 -1
- package/dist/assets/{useRunCells-q5CA-QoL.js → useRunCells-d2edY6Tu.js} +1 -1
- package/dist/assets/{useSplitCell-B0jDwUEM.js → useSplitCell-DOiFyMgH.js} +1 -1
- package/dist/assets/{vega-component-B2_J2GQq.js → vega-component-CiVPyAwP.js} +1 -1
- package/dist/index.html +26 -26
- package/package.json +1 -1
- package/src/components/editor/Output.tsx +1 -1
- package/src/components/editor/__tests__/Output.test.tsx +36 -1
- package/src/core/cells/__tests__/cells.test.ts +41 -0
- package/src/core/cells/__tests__/collapseConsoleOutputs.test.ts +38 -0
- package/src/core/cells/cells.ts +1 -1
- package/src/core/cells/collapseConsoleOutputs.tsx +3 -0
- package/src/core/runtime/__tests__/runtime.test.ts +138 -2
- package/src/core/runtime/runtime.ts +25 -5
- package/dist/assets/config-Cgj0Ahvb.js +0 -1
|
@@ -86,6 +86,74 @@ describe("RuntimeManager", () => {
|
|
|
86
86
|
});
|
|
87
87
|
});
|
|
88
88
|
|
|
89
|
+
describe("cross-origin auth token in WS URLs", () => {
|
|
90
|
+
it("should add access_token to WS URL when cross-origin with authToken", () => {
|
|
91
|
+
// example.com is cross-origin relative to the test environment (localhost)
|
|
92
|
+
const runtime = new RuntimeManager(
|
|
93
|
+
{
|
|
94
|
+
url: "https://sandbox.example.com",
|
|
95
|
+
lazy: true,
|
|
96
|
+
authToken: "my-secret-token",
|
|
97
|
+
},
|
|
98
|
+
true,
|
|
99
|
+
);
|
|
100
|
+
const url = runtime.getWsURL("s_123" as SessionId);
|
|
101
|
+
|
|
102
|
+
expect(url.searchParams.get("access_token")).toBe("my-secret-token");
|
|
103
|
+
expect(url.searchParams.get("session_id")).toBe("s_123");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("should not add access_token to WS URL when same-origin", () => {
|
|
107
|
+
const runtime = new RuntimeManager(
|
|
108
|
+
{
|
|
109
|
+
url: window.location.origin,
|
|
110
|
+
lazy: true,
|
|
111
|
+
authToken: "my-secret-token",
|
|
112
|
+
},
|
|
113
|
+
true,
|
|
114
|
+
);
|
|
115
|
+
const url = runtime.getWsURL("s_123" as SessionId);
|
|
116
|
+
|
|
117
|
+
expect(url.searchParams.get("access_token")).toBeNull();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("should not add access_token when no authToken is configured", () => {
|
|
121
|
+
const runtime = new RuntimeManager(
|
|
122
|
+
{
|
|
123
|
+
url: "https://sandbox.example.com",
|
|
124
|
+
lazy: true,
|
|
125
|
+
},
|
|
126
|
+
true,
|
|
127
|
+
);
|
|
128
|
+
const url = runtime.getWsURL("s_123" as SessionId);
|
|
129
|
+
|
|
130
|
+
expect(url.searchParams.get("access_token")).toBeNull();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("should add access_token to all WS URL types when cross-origin", () => {
|
|
134
|
+
const runtime = new RuntimeManager(
|
|
135
|
+
{
|
|
136
|
+
url: "https://sandbox.example.com",
|
|
137
|
+
lazy: true,
|
|
138
|
+
authToken: "my-secret-token",
|
|
139
|
+
},
|
|
140
|
+
true,
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const wsUrl = runtime.getWsURL("s_123" as SessionId);
|
|
144
|
+
const wsSyncUrl = runtime.getWsSyncURL("s_123" as SessionId);
|
|
145
|
+
const terminalUrl = runtime.getTerminalWsURL();
|
|
146
|
+
|
|
147
|
+
expect(wsUrl.searchParams.get("access_token")).toBe("my-secret-token");
|
|
148
|
+
expect(wsSyncUrl.searchParams.get("access_token")).toBe(
|
|
149
|
+
"my-secret-token",
|
|
150
|
+
);
|
|
151
|
+
expect(terminalUrl.searchParams.get("access_token")).toBe(
|
|
152
|
+
"my-secret-token",
|
|
153
|
+
);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
89
157
|
describe("getWsSyncURL", () => {
|
|
90
158
|
it("should return WebSocket Sync URL", () => {
|
|
91
159
|
const runtime = new RuntimeManager(mockConfig);
|
|
@@ -117,12 +185,52 @@ describe("RuntimeManager", () => {
|
|
|
117
185
|
expect(url.pathname).toBe("/lsp/pylsp");
|
|
118
186
|
});
|
|
119
187
|
|
|
120
|
-
it("should return copilot URL", () => {
|
|
121
|
-
const runtime = new RuntimeManager(
|
|
188
|
+
it("should return copilot URL without non-auth query params", () => {
|
|
189
|
+
const runtime = new RuntimeManager({
|
|
190
|
+
url: "https://example.com?foo=bar&baz=qux",
|
|
191
|
+
lazy: true,
|
|
192
|
+
});
|
|
122
193
|
const url = runtime.getLSPURL("copilot");
|
|
123
194
|
|
|
124
195
|
expect(url.protocol).toBe("wss:");
|
|
125
196
|
expect(url.pathname).toBe("/lsp/copilot");
|
|
197
|
+
expect(url.searchParams.get("foo")).toBeNull();
|
|
198
|
+
expect(url.searchParams.get("baz")).toBeNull();
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("should preserve access_token on copilot URL when cross-origin", () => {
|
|
202
|
+
const runtime = new RuntimeManager(
|
|
203
|
+
{
|
|
204
|
+
url: "https://sandbox.example.com?foo=bar",
|
|
205
|
+
lazy: true,
|
|
206
|
+
authToken: "my-secret-token",
|
|
207
|
+
},
|
|
208
|
+
true,
|
|
209
|
+
);
|
|
210
|
+
const url = runtime.getLSPURL("copilot");
|
|
211
|
+
|
|
212
|
+
expect(url.protocol).toBe("wss:");
|
|
213
|
+
expect(url.pathname).toBe("/lsp/copilot");
|
|
214
|
+
expect(url.searchParams.get("access_token")).toBe("my-secret-token");
|
|
215
|
+
// Other params should be stripped
|
|
216
|
+
expect(url.searchParams.get("foo")).toBeNull();
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("should not have access_token on copilot URL when same-origin", () => {
|
|
220
|
+
const runtime = new RuntimeManager(
|
|
221
|
+
{
|
|
222
|
+
url: window.location.origin,
|
|
223
|
+
lazy: true,
|
|
224
|
+
authToken: "my-secret-token",
|
|
225
|
+
},
|
|
226
|
+
true,
|
|
227
|
+
);
|
|
228
|
+
const url = runtime.getLSPURL("copilot");
|
|
229
|
+
|
|
230
|
+
expect(url.protocol).toBe("ws:");
|
|
231
|
+
expect(url.pathname).toBe("/lsp/copilot");
|
|
232
|
+
expect(url.searchParams.get("access_token")).toBeNull();
|
|
233
|
+
expect(url.search).toBe("");
|
|
126
234
|
});
|
|
127
235
|
});
|
|
128
236
|
|
|
@@ -200,6 +308,34 @@ describe("RuntimeManager", () => {
|
|
|
200
308
|
|
|
201
309
|
expect(result).toBe(false);
|
|
202
310
|
});
|
|
311
|
+
|
|
312
|
+
it("should update config.url on redirect, stripping /health from pathname", async () => {
|
|
313
|
+
global.fetch = vi.fn().mockResolvedValue({
|
|
314
|
+
ok: true,
|
|
315
|
+
redirected: true,
|
|
316
|
+
url: "https://sandbox.example.com/health?some_value=abc123",
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
const runtime = new RuntimeManager(
|
|
320
|
+
{
|
|
321
|
+
...mockConfig,
|
|
322
|
+
url: "https://backend.example.com/lazy?some_value=abc123",
|
|
323
|
+
},
|
|
324
|
+
true, // lazy — don't call init() in constructor
|
|
325
|
+
);
|
|
326
|
+
const result = await runtime.isHealthy();
|
|
327
|
+
|
|
328
|
+
expect(result).toBe(true);
|
|
329
|
+
// Should strip /health from pathname but preserve query params
|
|
330
|
+
const wsUrl = runtime.getWsURL("s_test" as SessionId);
|
|
331
|
+
expect(wsUrl.pathname).toBe("/ws");
|
|
332
|
+
expect(wsUrl.hostname).toBe("sandbox.example.com");
|
|
333
|
+
expect(wsUrl.searchParams.get("some_value")).toBe("abc123");
|
|
334
|
+
|
|
335
|
+
// Clean up side effects
|
|
336
|
+
document.querySelectorAll("base").forEach((el) => el.remove());
|
|
337
|
+
global.fetch = vi.fn().mockResolvedValue({ ok: false });
|
|
338
|
+
});
|
|
203
339
|
});
|
|
204
340
|
|
|
205
341
|
describe("waitForHealthy", () => {
|
|
@@ -88,6 +88,15 @@ export class RuntimeManager {
|
|
|
88
88
|
searchParams,
|
|
89
89
|
/* restrictToKnownQueryParams =*/ false,
|
|
90
90
|
);
|
|
91
|
+
|
|
92
|
+
// For cross-origin runtimes, pass the auth token as a query parameter.
|
|
93
|
+
// WebSocket connections cannot send custom headers (no Authorization
|
|
94
|
+
// header), and cross-origin cookies are blocked by browsers, so the
|
|
95
|
+
// access_token query param is the only way to authenticate.
|
|
96
|
+
if (!this.isSameOrigin && this.config.authToken) {
|
|
97
|
+
url.searchParams.set(KnownQueryParams.accessToken, this.config.authToken);
|
|
98
|
+
}
|
|
99
|
+
|
|
91
100
|
return asWsUrl(url.toString());
|
|
92
101
|
}
|
|
93
102
|
|
|
@@ -143,9 +152,15 @@ export class RuntimeManager {
|
|
|
143
152
|
*/
|
|
144
153
|
getLSPURL(lsp: "pylsp" | "basedpyright" | "copilot" | "ty" | "pyrefly"): URL {
|
|
145
154
|
if (lsp === "copilot") {
|
|
146
|
-
// For copilot,
|
|
155
|
+
// For copilot, strip all query parameters except the auth token.
|
|
156
|
+
// Copilot doesn't understand arbitrary query params, but we still
|
|
157
|
+
// need access_token for cross-origin authentication.
|
|
147
158
|
const url = this.formatWsURL(`/lsp/${lsp}`);
|
|
159
|
+
const accessToken = url.searchParams.get(KnownQueryParams.accessToken);
|
|
148
160
|
url.search = "";
|
|
161
|
+
if (accessToken) {
|
|
162
|
+
url.searchParams.set(KnownQueryParams.accessToken, accessToken);
|
|
163
|
+
}
|
|
149
164
|
return url;
|
|
150
165
|
}
|
|
151
166
|
return this.formatWsURL(`/lsp/${lsp}`);
|
|
@@ -173,9 +188,10 @@ export class RuntimeManager {
|
|
|
173
188
|
// If there is a redirect, update the URL in the config
|
|
174
189
|
if (response.redirected) {
|
|
175
190
|
Logger.debug(`Runtime redirected to ${response.url}`);
|
|
176
|
-
// strip /health from the URL
|
|
177
|
-
const
|
|
178
|
-
|
|
191
|
+
// strip /health from the URL, using URL parsing to handle query params
|
|
192
|
+
const redirected = new URL(response.url);
|
|
193
|
+
redirected.pathname = redirected.pathname.replace(/\/health$/, "");
|
|
194
|
+
this.config.url = redirected.toString();
|
|
179
195
|
}
|
|
180
196
|
|
|
181
197
|
const success = response.ok;
|
|
@@ -183,7 +199,11 @@ export class RuntimeManager {
|
|
|
183
199
|
this.setDOMBaseUri(this.config.url);
|
|
184
200
|
}
|
|
185
201
|
return success;
|
|
186
|
-
} catch {
|
|
202
|
+
} catch (error) {
|
|
203
|
+
Logger.error(
|
|
204
|
+
`Failed to check health: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
205
|
+
{ cause: error },
|
|
206
|
+
);
|
|
187
207
|
return false;
|
|
188
208
|
}
|
|
189
209
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var w=Object.defineProperty;var S=(t,e,r)=>e in t?w(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var R=(t,e,r)=>S(t,typeof e!="symbol"?e+"":e,r);import{i as T,l as d,n as g,o as C,p as i,u as y}from"./useEvent-D91BmmQi.js";import{t as D}from"./compiler-runtime-B3qBwwSJ.js";import{_ as c}from"./useEventListener-DGjKht0c.js";import{t as I}from"./utils-8btzWeZg.js";import{r as l}from"./constants-tOPFFcLZ.js";import{t as A}from"./Deferred-DxQeE5uh.js";import{t as f}from"./session-DdnWW30b.js";function m(){return typeof document<"u"&&document.querySelector("marimo-wasm")!==null}const n={NOT_STARTED:"NOT_STARTED",CONNECTING:"CONNECTING",OPEN:"OPEN",CLOSING:"CLOSING",CLOSED:"CLOSED"},_={KERNEL_DISCONNECTED:"KERNEL_DISCONNECTED",ALREADY_RUNNING:"ALREADY_RUNNING",MALFORMED_QUERY:"MALFORMED_QUERY",KERNEL_STARTUP_ERROR:"KERNEL_STARTUP_ERROR"},o=i({state:n.NOT_STARTED});function P(){return C(o,t=>t.state===n.OPEN)}const b=i(t=>t(o).state===n.CONNECTING);i(t=>t(o).state===n.OPEN);const G=i(t=>{let e=t(o);return e.state===n.OPEN||e.state===n.NOT_STARTED}),W=i(t=>t(o).state===n.CLOSED),k=i(t=>t(o).state===n.NOT_STARTED);function H(t){return t===n.CLOSED}function $(t){return t===n.CONNECTING}function M(t){return t===n.OPEN}function v(t){return t===n.CLOSING}function L(t){return t===n.NOT_STARTED}function z(t){return t===n.CLOSED||t===n.CLOSING||t===n.CONNECTING}function F(t){switch(t){case n.CLOSED:return"App disconnected";case n.CONNECTING:return"Connecting to a runtime ...";case n.CLOSING:return"App disconnecting...";case n.OPEN:return"";case n.NOT_STARTED:return"Click to connect to a runtime";default:return""}}var x=class{constructor(t,e=!1){R(this,"initialHealthyCheck",new A);this.config=t,this.lazy=e;try{new URL(this.config.url)}catch(r){throw Error(`Invalid runtime URL: ${this.config.url}. ${r instanceof Error?r.message:"Unknown error"}`,{cause:r})}this.lazy||this.init()}get isLazy(){return this.lazy}get httpURL(){return new URL(this.config.url)}get isSameOrigin(){return this.httpURL.origin===window.location.origin}formatHttpURL(t,e,r=!0){t||(t="");let a=this.httpURL,s=new URLSearchParams(window.location.search);if(e)for(let[h,u]of e.entries())a.searchParams.set(h,u);for(let[h,u]of s.entries())r&&!Object.values(l).includes(h)||a.searchParams.set(h,u);return a.pathname=`${a.pathname.replace(/\/$/,"")}/${t.replace(/^\//,"")}`,a.hash="",a}formatWsURL(t,e){return K(this.formatHttpURL(t,e,!1).toString())}getWsURL(t){let e=new URL(this.config.url),r=new URLSearchParams(e.search);return new URLSearchParams(window.location.search).forEach((a,s)=>{r.has(s)||r.set(s,a)}),r.set(l.sessionId,t),this.formatWsURL("/ws",r)}getWsSyncURL(t){let e=new URL(this.config.url),r=new URLSearchParams(e.search);return new URLSearchParams(window.location.search).forEach((a,s)=>{r.has(s)||r.set(s,a)}),r.set(l.sessionId,t),this.formatWsURL("/ws_sync",r)}getTerminalWsURL(){return this.formatWsURL("/terminal/ws")}getLSPURL(t){if(t==="copilot"){let e=this.formatWsURL(`/lsp/${t}`);return e.search="",e}return this.formatWsURL(`/lsp/${t}`)}getAiURL(t){return this.formatHttpURL(`/api/ai/${t}`)}healthURL(){return this.formatHttpURL("/health")}async isHealthy(){if(m()||I())return!0;try{let t=await fetch(this.healthURL().toString());if(t.redirected){c.debug(`Runtime redirected to ${t.url}`);let r=t.url.replace(/\/health$/,"");this.config.url=r}let e=t.ok;return e&&this.setDOMBaseUri(this.config.url),e}catch{return!1}}setDOMBaseUri(t){t=t.split("?",1)[0],t.endsWith("/")||(t+="/");let e=document.querySelector("base");e?e.setAttribute("href",t):(e=document.createElement("base"),e.setAttribute("href",t),document.head.append(e))}async init(t){c.debug("Initializing runtime...");let e=0;for(;!await this.isHealthy();){if(e>=25){c.error("Failed to connect after 25 retries"),this.initialHealthyCheck.reject(Error("Failed to connect after 25 retries"));return}if(!(t!=null&&t.disableRetryDelay)){let r=Math.min(100*1.2**e,2e3);await new Promise(a=>setTimeout(a,r))}e++}c.debug("Runtime is healthy"),this.initialHealthyCheck.resolve()}async waitForHealthy(){return this.initialHealthyCheck.promise}headers(){let t={"Marimo-Session-Id":f(),"Marimo-Server-Token":this.config.serverToken??"","x-runtime-url":this.httpURL.toString()};return this.config.authToken&&(t.Authorization=`Bearer ${this.config.authToken}`),t}sessionHeaders(){return{"Marimo-Session-Id":f()}}};function K(t){if(!t.startsWith("http")){c.warn(`URL must start with http: ${t}`);let e=new URL(t);return e.protocol="ws",e}return new URL(t.replace(/^http/,"ws"))}var Y=D();function j(){let t=new URL(document.baseURI);return t.search="",t.hash="",t.toString()}const N={lazy:!0,url:j()},E=i(N);var U=i(t=>{let e=t(E);return new x(e,e.lazy)});function p(){return y(U)}function B(){let t=(0,Y.c)(4),e=p(),[r,a]=d(o),s;return t[0]!==r.state||t[1]!==e||t[2]!==a?(s=async()=>{L(r.state)?(a({state:n.CONNECTING}),await e.init()):c.log("Runtime already started or starting...")},t[0]=r.state,t[1]=e,t[2]=a,t[3]=s):s=t[3],g(s)}function O(){return T.get(U)}function q(t){if(t.startsWith("http"))return new URL(t);let e=O().httpURL.toString();return e.startsWith("blob:")&&(e=e.replace("blob:","")),new URL(t,e)}export{m as S,b as _,B as a,_ as b,H as c,$ as d,z as f,W as g,o as h,E as i,v as l,G as m,q as n,p as o,L as p,O as r,F as s,N as t,M as u,k as v,n as x,P as y};
|