@marimo-team/islands 0.19.8-dev40 → 0.19.8-dev48
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/__vite-browser-external-WSlCcXn_.js +1 -0
- package/dist/assets/worker-DUYMdbtA.js +73 -0
- package/dist/main.js +1740 -1691
- package/dist/style.css +1 -1
- package/dist/{useDeepCompareMemoize-CMGprt3H.js → useDeepCompareMemoize-BhZZsis0.js} +7 -3
- package/dist/{vega-component-DU3aSp4m.js → vega-component-DCxUyPnb.js} +1 -1
- package/package.json +1 -1
- package/src/components/app-config/optional-features.tsx +1 -1
- package/src/components/chat/__tests__/useFileState.test.tsx +93 -0
- package/src/components/chat/acp/agent-panel.tsx +26 -77
- package/src/components/chat/chat-components.tsx +114 -1
- package/src/components/chat/chat-panel.tsx +32 -104
- package/src/components/chat/chat-utils.ts +42 -0
- package/src/components/editor/ai/add-cell-with-ai.tsx +85 -53
- package/src/components/editor/ai/ai-completion-editor.tsx +15 -38
- package/src/components/editor/chrome/panels/packages-panel.tsx +12 -9
- package/src/core/islands/__tests__/bridge.test.ts +7 -2
- package/src/core/islands/bridge.ts +1 -1
- package/src/core/islands/main.ts +7 -0
- package/src/core/network/types.ts +2 -2
- package/src/core/wasm/bridge.ts +1 -1
- package/src/core/websocket/useMarimoKernelConnection.tsx +5 -15
- package/src/plugins/impl/anywidget/AnyWidgetPlugin.tsx +86 -167
- package/src/plugins/impl/anywidget/__tests__/AnyWidgetPlugin.test.tsx +37 -123
- package/src/plugins/impl/anywidget/__tests__/model.test.ts +128 -122
- package/src/{utils/__tests__/data-views.test.ts → plugins/impl/anywidget/__tests__/serialization.test.ts} +42 -96
- package/src/plugins/impl/anywidget/model.ts +348 -223
- package/src/plugins/impl/anywidget/schemas.ts +32 -0
- package/src/{utils/data-views.ts → plugins/impl/anywidget/serialization.ts} +13 -36
- package/src/plugins/impl/anywidget/types.ts +27 -0
- package/src/plugins/impl/chat/chat-ui.tsx +22 -20
- package/src/utils/Deferred.ts +21 -0
- package/src/utils/json/base64.ts +38 -8
- package/dist/assets/__vite-browser-external-6-UwTyQC.js +0 -1
- package/dist/assets/worker-D3e5wDxM.js +0 -73
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
const BufferPathSchema = z.array(z.array(z.union([z.string(), z.number()])));
|
|
5
|
+
const StateSchema = z.record(z.string(), z.any());
|
|
6
|
+
|
|
7
|
+
export const AnyWidgetMessageSchema = z.discriminatedUnion("method", [
|
|
8
|
+
z.object({
|
|
9
|
+
method: z.literal("open"),
|
|
10
|
+
state: StateSchema,
|
|
11
|
+
buffer_paths: BufferPathSchema.optional(),
|
|
12
|
+
}),
|
|
13
|
+
z.object({
|
|
14
|
+
method: z.literal("update"),
|
|
15
|
+
state: StateSchema,
|
|
16
|
+
buffer_paths: BufferPathSchema.optional(),
|
|
17
|
+
}),
|
|
18
|
+
z.object({
|
|
19
|
+
method: z.literal("custom"),
|
|
20
|
+
content: z.any(),
|
|
21
|
+
}),
|
|
22
|
+
z.object({
|
|
23
|
+
method: z.literal("echo_update"),
|
|
24
|
+
buffer_paths: BufferPathSchema,
|
|
25
|
+
state: StateSchema,
|
|
26
|
+
}),
|
|
27
|
+
z.object({
|
|
28
|
+
method: z.literal("close"),
|
|
29
|
+
}),
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
export type AnyWidgetMessage = z.infer<typeof AnyWidgetMessageSchema>;
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
import { get, set } from "lodash-es";
|
|
3
|
-
import { invariant } from "
|
|
3
|
+
import { invariant } from "../../../utils/invariant";
|
|
4
4
|
import {
|
|
5
5
|
type Base64String,
|
|
6
6
|
base64ToDataView,
|
|
7
7
|
dataViewToBase64,
|
|
8
|
-
} from "
|
|
9
|
-
import { Logger } from "
|
|
8
|
+
} from "../../../utils/json/base64";
|
|
9
|
+
import { Logger } from "../../../utils/Logger";
|
|
10
|
+
import type { WireFormat } from "./types";
|
|
11
|
+
|
|
12
|
+
type Path = (string | number)[];
|
|
10
13
|
|
|
11
14
|
/**
|
|
12
15
|
* Recursively find all DataViews in an object and return their paths.
|
|
13
16
|
*
|
|
14
17
|
* This mirrors ipywidgets' _separate_buffers logic.
|
|
15
18
|
*/
|
|
16
|
-
function findDataViewPaths(
|
|
17
|
-
|
|
18
|
-
currentPath: (string | number)[] = [],
|
|
19
|
-
): (string | number)[][] {
|
|
20
|
-
const paths: (string | number)[][] = [];
|
|
19
|
+
function findDataViewPaths(obj: unknown, currentPath: Path = []): Path[] {
|
|
20
|
+
const paths: Path[] = [];
|
|
21
21
|
|
|
22
22
|
if (obj instanceof DataView) {
|
|
23
23
|
paths.push(currentPath);
|
|
@@ -51,7 +51,7 @@ export function serializeBuffersToBase64<T extends Record<string, unknown>>(
|
|
|
51
51
|
|
|
52
52
|
const state = structuredClone(inputObject);
|
|
53
53
|
const buffers: Base64String[] = [];
|
|
54
|
-
const bufferPaths:
|
|
54
|
+
const bufferPaths: Path[] = [];
|
|
55
55
|
|
|
56
56
|
for (const bufferPath of dataViewPaths) {
|
|
57
57
|
const dataView = get(inputObject, bufferPath);
|
|
@@ -66,31 +66,6 @@ export function serializeBuffersToBase64<T extends Record<string, unknown>>(
|
|
|
66
66
|
return { state, buffers, bufferPaths };
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
/**
|
|
70
|
-
* Wire format for anywidget state with binary data.
|
|
71
|
-
* Buffers can be either base64 strings (from network) or DataViews (in-memory).
|
|
72
|
-
*/
|
|
73
|
-
export interface WireFormat<T = Record<string, unknown>> {
|
|
74
|
-
state: T;
|
|
75
|
-
bufferPaths: (string | number)[][];
|
|
76
|
-
buffers: Base64String[];
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Check if an object is in wire format.
|
|
81
|
-
*/
|
|
82
|
-
export function isWireFormat<T = Record<string, unknown>>(
|
|
83
|
-
obj: unknown,
|
|
84
|
-
): obj is WireFormat<T> {
|
|
85
|
-
return (
|
|
86
|
-
obj !== null &&
|
|
87
|
-
typeof obj === "object" &&
|
|
88
|
-
"state" in obj &&
|
|
89
|
-
"bufferPaths" in obj &&
|
|
90
|
-
"buffers" in obj
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
69
|
/**
|
|
95
70
|
* Decode wire format or insert DataViews at specified paths.
|
|
96
71
|
*
|
|
@@ -103,7 +78,7 @@ export function isWireFormat<T = Record<string, unknown>>(
|
|
|
103
78
|
*/
|
|
104
79
|
export function decodeFromWire<T extends Record<string, unknown>>(input: {
|
|
105
80
|
state: T;
|
|
106
|
-
bufferPaths?:
|
|
81
|
+
bufferPaths?: Path[];
|
|
107
82
|
buffers?: readonly (DataView | Base64String)[];
|
|
108
83
|
}): T {
|
|
109
84
|
const { state, bufferPaths, buffers } = input;
|
|
@@ -121,7 +96,9 @@ export function decodeFromWire<T extends Record<string, unknown>>(input: {
|
|
|
121
96
|
);
|
|
122
97
|
}
|
|
123
98
|
|
|
124
|
-
|
|
99
|
+
// We should avoid using structuredClone if possible since
|
|
100
|
+
// it can be very slow. If mutability is a concern, we should use a different approach.
|
|
101
|
+
const out = state;
|
|
125
102
|
|
|
126
103
|
for (const [i, bufferPath] of bufferPaths.entries()) {
|
|
127
104
|
const buffer = buffers?.[i];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
import type { Base64String } from "@/utils/json/base64";
|
|
3
|
+
import type { TypedString } from "@/utils/typed";
|
|
4
|
+
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
|
+
export type EventHandler = (...args: any[]) => void;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Type-safe widget model id.
|
|
10
|
+
*/
|
|
11
|
+
export type WidgetModelId = TypedString<"WidgetModelId">;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* AnyWidget model state with buffers.
|
|
15
|
+
*/
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
export type ModelState = Record<string | number, any>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Wire format for anywidget state with binary data.
|
|
21
|
+
* Buffers can be either base64 strings (from network) or DataViews (in-memory).
|
|
22
|
+
*/
|
|
23
|
+
export interface WireFormat<T = Record<string, unknown>> {
|
|
24
|
+
state: T;
|
|
25
|
+
bufferPaths: (string | number)[][];
|
|
26
|
+
buffers: Base64String[];
|
|
27
|
+
}
|
|
@@ -16,12 +16,13 @@ import {
|
|
|
16
16
|
HelpCircleIcon,
|
|
17
17
|
PaperclipIcon,
|
|
18
18
|
RotateCwIcon,
|
|
19
|
-
|
|
19
|
+
SendHorizontalIcon,
|
|
20
20
|
SettingsIcon,
|
|
21
21
|
Trash2Icon,
|
|
22
22
|
X,
|
|
23
23
|
} from "lucide-react";
|
|
24
24
|
import React, { useEffect, useRef, useState } from "react";
|
|
25
|
+
import { z } from "zod";
|
|
25
26
|
import { renderUIMessage } from "@/components/chat/chat-display";
|
|
26
27
|
import { convertToFileUIPart } from "@/components/chat/chat-utils";
|
|
27
28
|
import {
|
|
@@ -71,6 +72,16 @@ interface Props extends PluginFunctions {
|
|
|
71
72
|
host: HTMLElement;
|
|
72
73
|
}
|
|
73
74
|
|
|
75
|
+
const ChatMessageIncomingSchema = z.object({
|
|
76
|
+
type: z.literal("stream_chunk"),
|
|
77
|
+
message_id: z.string(),
|
|
78
|
+
content: z
|
|
79
|
+
.any()
|
|
80
|
+
.nullable()
|
|
81
|
+
.transform((val) => val as UIMessageChunk | null),
|
|
82
|
+
is_final: z.boolean().optional(),
|
|
83
|
+
});
|
|
84
|
+
|
|
74
85
|
export const Chatbot: React.FC<Props> = (props) => {
|
|
75
86
|
const [input, setInput] = useState("");
|
|
76
87
|
const [config, setConfig] = useState<ChatConfig>(props.config);
|
|
@@ -252,15 +263,13 @@ export const Chatbot: React.FC<Props> = (props) => {
|
|
|
252
263
|
props.host as HTMLElementNotDerivedFromRef,
|
|
253
264
|
MarimoIncomingMessageEvent.TYPE,
|
|
254
265
|
(e) => {
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
!("type" in message) ||
|
|
260
|
-
message.type !== "stream_chunk"
|
|
261
|
-
) {
|
|
266
|
+
const parsedMessage = ChatMessageIncomingSchema.safeParse(
|
|
267
|
+
e.detail.message,
|
|
268
|
+
);
|
|
269
|
+
if (!parsedMessage.success) {
|
|
262
270
|
return;
|
|
263
271
|
}
|
|
272
|
+
const message = parsedMessage.data;
|
|
264
273
|
|
|
265
274
|
// Push to the stream for useChat to process
|
|
266
275
|
const controller = frontendStreamControllerRef.current;
|
|
@@ -268,17 +277,10 @@ export const Chatbot: React.FC<Props> = (props) => {
|
|
|
268
277
|
return;
|
|
269
278
|
}
|
|
270
279
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
message_id: string;
|
|
274
|
-
content?: UIMessageChunk;
|
|
275
|
-
is_final?: boolean;
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
if (frontendMessage.content) {
|
|
279
|
-
controller.enqueue(frontendMessage.content);
|
|
280
|
+
if (message.content) {
|
|
281
|
+
controller.enqueue(message.content);
|
|
280
282
|
}
|
|
281
|
-
if (
|
|
283
|
+
if (message.is_final) {
|
|
282
284
|
controller.close();
|
|
283
285
|
frontendStreamControllerRef.current = null;
|
|
284
286
|
}
|
|
@@ -559,10 +561,10 @@ export const Chatbot: React.FC<Props> = (props) => {
|
|
|
559
561
|
type="submit"
|
|
560
562
|
disabled={isLoading || !input}
|
|
561
563
|
variant="outline"
|
|
562
|
-
size="
|
|
564
|
+
size="xs"
|
|
563
565
|
className="text-(--slate-11)"
|
|
564
566
|
>
|
|
565
|
-
<
|
|
567
|
+
<SendHorizontalIcon className="h-4 w-4" />
|
|
566
568
|
</Button>
|
|
567
569
|
</form>
|
|
568
570
|
</div>
|
package/src/utils/Deferred.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A deferred promise that can be resolved or rejected externally.
|
|
5
|
+
*
|
|
6
|
+
* Provides synchronous access to status and resolved value, useful for
|
|
7
|
+
* cases where you need to check if a promise has settled without awaiting it.
|
|
8
|
+
*/
|
|
2
9
|
export class Deferred<T> {
|
|
3
10
|
promise: Promise<T>;
|
|
4
11
|
resolve!: (value: T | PromiseLike<T>) => void;
|
|
5
12
|
reject!: (reason?: unknown) => void;
|
|
6
13
|
status: "pending" | "resolved" | "rejected" = "pending";
|
|
14
|
+
value: T | undefined = undefined;
|
|
7
15
|
|
|
8
16
|
constructor() {
|
|
9
17
|
this.promise = new Promise<T>((resolve, reject) => {
|
|
@@ -13,8 +21,21 @@ export class Deferred<T> {
|
|
|
13
21
|
};
|
|
14
22
|
this.resolve = (value) => {
|
|
15
23
|
this.status = "resolved";
|
|
24
|
+
// Store the value for synchronous access
|
|
25
|
+
if (!isPromiseLike(value)) {
|
|
26
|
+
this.value = value;
|
|
27
|
+
}
|
|
16
28
|
resolve(value);
|
|
17
29
|
};
|
|
18
30
|
});
|
|
19
31
|
}
|
|
20
32
|
}
|
|
33
|
+
|
|
34
|
+
function isPromiseLike(value: unknown): value is PromiseLike<unknown> {
|
|
35
|
+
return (
|
|
36
|
+
typeof value === "object" &&
|
|
37
|
+
value !== null &&
|
|
38
|
+
"then" in value &&
|
|
39
|
+
typeof value.then === "function"
|
|
40
|
+
);
|
|
41
|
+
}
|
package/src/utils/json/base64.ts
CHANGED
|
@@ -52,13 +52,27 @@ export function extractBase64FromDataURL(str: DataURLString): Base64String {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
|
-
* Convert a base64 string to a Uint8Array.
|
|
55
|
+
* Convert a base64 string to a Uint8Array (fallback implementation).
|
|
56
|
+
* See benchmarks/base64-conversion.bench.ts for why we use a manual loop.
|
|
56
57
|
*/
|
|
57
|
-
|
|
58
|
-
const binary =
|
|
59
|
-
|
|
58
|
+
function base64ToUint8ArrayFallback(bytes: string): Uint8Array {
|
|
59
|
+
const binary = globalThis.atob(bytes);
|
|
60
|
+
const len = binary.length;
|
|
61
|
+
const uint8Array = new Uint8Array(len);
|
|
62
|
+
for (let i = 0; i < len; i++) {
|
|
63
|
+
uint8Array[i] = binary.charCodeAt(i);
|
|
64
|
+
}
|
|
65
|
+
return uint8Array;
|
|
60
66
|
}
|
|
61
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Convert a base64 string to a Uint8Array.
|
|
70
|
+
* Uses native Uint8Array.fromBase64 if available, otherwise falls back to manual implementation.
|
|
71
|
+
*/
|
|
72
|
+
export const base64ToUint8Array: (bytes: Base64String) => Uint8Array =
|
|
73
|
+
// @ts-expect-error - Uint8Array.fromBase64 types coming in TypeScript 5.10+
|
|
74
|
+
Uint8Array.fromBase64 ?? base64ToUint8ArrayFallback;
|
|
75
|
+
|
|
62
76
|
/**
|
|
63
77
|
* Convert a base64 string to a DataView.
|
|
64
78
|
*/
|
|
@@ -68,13 +82,29 @@ export function base64ToDataView(bytes: Base64String): DataView {
|
|
|
68
82
|
}
|
|
69
83
|
|
|
70
84
|
/**
|
|
71
|
-
* Convert a Uint8Array to a base64 string.
|
|
85
|
+
* Convert a Uint8Array to a base64 string (fallback implementation).
|
|
86
|
+
* See benchmarks/uint8array-to-base64.bench.ts for why we use a manual loop.
|
|
72
87
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
88
|
+
function uint8ArrayToBase64Fallback(binary: Uint8Array): Base64String {
|
|
89
|
+
let binaryString = "";
|
|
90
|
+
const len = binary.length;
|
|
91
|
+
for (let i = 0; i < len; i++) {
|
|
92
|
+
binaryString += String.fromCharCode(binary[i]);
|
|
93
|
+
}
|
|
94
|
+
return globalThis.btoa(binaryString) as Base64String;
|
|
76
95
|
}
|
|
77
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Convert a Uint8Array to a base64 string.
|
|
99
|
+
* Uses native Uint8Array.prototype.toBase64 if available, otherwise falls back to manual implementation.
|
|
100
|
+
*/
|
|
101
|
+
export const uint8ArrayToBase64: (binary: Uint8Array) => Base64String =
|
|
102
|
+
// @ts-expect-error - Uint8Array.prototype.toBase64 types coming in TypeScript 5.10+
|
|
103
|
+
Uint8Array.prototype.toBase64
|
|
104
|
+
? // @ts-expect-error - Uint8Array.prototype.toBase64 types coming in TypeScript 5.10+
|
|
105
|
+
(binary) => binary.toBase64()
|
|
106
|
+
: uint8ArrayToBase64Fallback;
|
|
107
|
+
|
|
78
108
|
/**
|
|
79
109
|
* Convert a DataView to a base64 string.
|
|
80
110
|
*/
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./worker-D3e5wDxM.js";var t=e(((e,t)=>{t.exports={}}));export default t();
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,a)=>(a=n==null?{}:e(i(n)),s(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n)),l=e=>t=>c(t.default,e),u=(e=>typeof require<`u`?require:typeof Proxy<`u`?new Proxy(e,{get:(e,t)=>(typeof require<`u`?require:e)[t]}):e)(function(e){if(typeof require<`u`)return require.apply(this,arguments);throw Error('Calling `require` for "'+e+"\" in an environment that doesn't expose the `require` function.")});function d(e){return e}function f(e,t){let n=e.map(e=>`"${e}"`).join(`, `);return Error(`This RPC instance cannot ${t} because the transport did not provide one or more of these methods: ${n}`)}function p(e={}){let t={};function n(e){t=e}let r={};function i(e){r.unregisterHandler&&r.unregisterHandler(),r=e,r.registerHandler?.(se)}let a;function o(e){if(typeof e==`function`){a=e;return}a=(t,n)=>{let r=e[t];if(r)return r(n);let i=e._;if(!i)throw Error(`The requested method has no handler: ${t}`);return i(t,n)}}let{maxRequestTime:s=1e3}=e;e.transport&&i(e.transport),e.requestHandler&&o(e.requestHandler),e._debugHooks&&n(e._debugHooks);let c=0;function l(){return c<=1e10?++c:c=0}let u=new Map,d=new Map;function p(e,...n){let i=n[0];return new Promise((n,a)=>{if(!r.send)throw f([`send`],`make requests`);let o=l(),c={type:`request`,id:o,method:e,params:i};u.set(o,{resolve:n,reject:a}),s!==1/0&&d.set(o,setTimeout(()=>{d.delete(o),a(Error(`RPC request timed out.`))},s)),t.onSend?.(c),r.send(c)})}let ee=new Proxy(p,{get:(e,t,n)=>t in e?Reflect.get(e,t,n):e=>p(t,e)}),te=ee;function ne(e,...n){let i=n[0];if(!r.send)throw f([`send`],`send messages`);let a={type:`message`,id:e,payload:i};t.onSend?.(a),r.send(a)}let re=new Proxy(ne,{get:(e,t,n)=>t in e?Reflect.get(e,t,n):e=>ne(t,e)}),ie=re,m=new Map,ae=new Set;function h(e,t){if(!r.registerHandler)throw f([`registerHandler`],`register message listeners`);if(e===`*`){ae.add(t);return}m.has(e)||m.set(e,new Set),m.get(e)?.add(t)}function oe(e,t){if(e===`*`){ae.delete(t);return}m.get(e)?.delete(t),m.get(e)?.size===0&&m.delete(e)}async function se(e){if(t.onReceive?.(e),!(`type`in e))throw Error(`Message does not contain a type.`);if(e.type===`request`){if(!r.send||!a)throw f([`send`,`requestHandler`],`handle requests`);let{id:n,method:i,params:o}=e,s;try{s={type:`response`,id:n,success:!0,payload:await a(i,o)}}catch(e){if(!(e instanceof Error))throw e;s={type:`response`,id:n,success:!1,error:e.message}}t.onSend?.(s),r.send(s);return}if(e.type===`response`){let t=d.get(e.id);t!=null&&clearTimeout(t);let{resolve:n,reject:r}=u.get(e.id)??{};e.success?n?.(e.payload):r?.(Error(e.error));return}if(e.type===`message`){for(let t of ae)t(e.id,e.payload);let t=m.get(e.id);if(!t)return;for(let n of t)n(e.payload);return}throw Error(`Unexpected RPC message type: ${e.type}`)}return{setTransport:i,setRequestHandler:o,request:ee,requestProxy:te,send:re,sendProxy:ie,addMessageListener:h,removeMessageListener:oe,proxy:{send:ie,request:te},_setDebugHooks:n}}function ee(e){return p(e)}const te=`[transport-id]`;function ne(e,t){let{transportId:n}=t;return n==null?e:{[te]:n,data:e}}function re(e,t){let{transportId:n,filter:r}=t,i=r?.();if(n!=null&&i!=null)throw Error("Cannot use both `transportId` and `filter` at the same time");let a=e;if(n){if(e[te]!==n)return[!0];a=e.data}return i===!1?[!0]:[!1,a]}function ie(e,t={}){let{transportId:n,filter:r,remotePort:i}=t,a=e,o=i??e,s;return{send(e){o.postMessage(ne(e,{transportId:n}))},registerHandler(e){s=t=>{let i=t.data,[a,o]=re(i,{transportId:n,filter:()=>r?.(t)});a||e(o)},a.addEventListener(`message`,s)},unregisterHandler(){s&&a.removeEventListener(`message`,s)}}}function m(e){return ie(self,e)}var ae=Object.defineProperty,h=(e,t)=>ae(e,`name`,{value:t,configurable:!0}),oe=(e=>typeof u<`u`?u:typeof Proxy<`u`?new Proxy(e,{get:(e,t)=>(typeof u<`u`?u:e)[t]}):e)(function(e){if(typeof u<`u`)return u.apply(this,arguments);throw Error(`Dynamic require of "`+e+`" is not supported`)});function se(e){return!isNaN(parseFloat(e))&&isFinite(e)}h(se,`_isNumber`);function g(e){return e.charAt(0).toUpperCase()+e.substring(1)}h(g,`_capitalize`);function ce(e){return function(){return this[e]}}h(ce,`_getter`);var _=[`isConstructor`,`isEval`,`isNative`,`isToplevel`],v=[`columnNumber`,`lineNumber`],y=[`fileName`,`functionName`,`source`],le=_.concat(v,y,[`args`],[`evalOrigin`]);function b(e){if(e)for(var t=0;t<le.length;t++)e[le[t]]!==void 0&&this[`set`+g(le[t])](e[le[t]])}for(h(b,`StackFrame`),b.prototype={getArgs:function(){return this.args},setArgs:function(e){if(Object.prototype.toString.call(e)!==`[object Array]`)throw TypeError(`Args must be an Array`);this.args=e},getEvalOrigin:function(){return this.evalOrigin},setEvalOrigin:function(e){if(e instanceof b)this.evalOrigin=e;else if(e instanceof Object)this.evalOrigin=new b(e);else throw TypeError(`Eval Origin must be an Object or StackFrame`)},toString:function(){var e=this.getFileName()||``,t=this.getLineNumber()||``,n=this.getColumnNumber()||``,r=this.getFunctionName()||``;return this.getIsEval()?e?`[eval] (`+e+`:`+t+`:`+n+`)`:`[eval]:`+t+`:`+n:r?r+` (`+e+`:`+t+`:`+n+`)`:e+`:`+t+`:`+n}},b.fromString=h(function(e){var t=e.indexOf(`(`),n=e.lastIndexOf(`)`),r=e.substring(0,t),i=e.substring(t+1,n).split(`,`),a=e.substring(n+1);if(a.indexOf(`@`)===0)var o=/@(.+?)(?::(\d+))?(?::(\d+))?$/.exec(a,``),s=o[1],c=o[2],l=o[3];return new b({functionName:r,args:i||void 0,fileName:s,lineNumber:c||void 0,columnNumber:l||void 0})},`StackFrame$$fromString`),x=0;x<_.length;x++)b.prototype[`get`+g(_[x])]=ce(_[x]),b.prototype[`set`+g(_[x])]=function(e){return function(t){this[e]=!!t}}(_[x]);var x;for(S=0;S<v.length;S++)b.prototype[`get`+g(v[S])]=ce(v[S]),b.prototype[`set`+g(v[S])]=function(e){return function(t){if(!se(t))throw TypeError(e+` must be a Number`);this[e]=Number(t)}}(v[S]);var S;for(C=0;C<y.length;C++)b.prototype[`get`+g(y[C])]=ce(y[C]),b.prototype[`set`+g(y[C])]=function(e){return function(t){this[e]=String(t)}}(y[C]);var C,ue=b;function de(){var e=/^\s*at .*(\S+:\d+|\(native\))/m,t=/^(eval@)?(\[native code])?$/;return{parse:h(function(t){if(t.stack&&t.stack.match(e))return this.parseV8OrIE(t);if(t.stack)return this.parseFFOrSafari(t);throw Error(`Cannot parse given Error object`)},`ErrorStackParser$$parse`),extractLocation:h(function(e){if(e.indexOf(`:`)===-1)return[e];var t=/(.+?)(?::(\d+))?(?::(\d+))?$/.exec(e.replace(/[()]/g,``));return[t[1],t[2]||void 0,t[3]||void 0]},`ErrorStackParser$$extractLocation`),parseV8OrIE:h(function(t){return t.stack.split(`
|
|
2
|
-
`).filter(function(t){return!!t.match(e)},this).map(function(e){e.indexOf(`(eval `)>-1&&(e=e.replace(/eval code/g,`eval`).replace(/(\(eval at [^()]*)|(,.*$)/g,``));var t=e.replace(/^\s+/,``).replace(/\(eval code/g,`(`).replace(/^.*?\s+/,``),n=t.match(/ (\(.+\)$)/);t=n?t.replace(n[0],``):t;var r=this.extractLocation(n?n[1]:t);return new ue({functionName:n&&t||void 0,fileName:[`eval`,`<anonymous>`].indexOf(r[0])>-1?void 0:r[0],lineNumber:r[1],columnNumber:r[2],source:e})},this)},`ErrorStackParser$$parseV8OrIE`),parseFFOrSafari:h(function(e){return e.stack.split(`
|
|
3
|
-
`).filter(function(e){return!e.match(t)},this).map(function(e){if(e.indexOf(` > eval`)>-1&&(e=e.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g,`:$1`)),e.indexOf(`@`)===-1&&e.indexOf(`:`)===-1)return new ue({functionName:e});var t=/((.*".+"[^@]*)?[^@]*)(?:@)/,n=e.match(t),r=n&&n[1]?n[1]:void 0,i=this.extractLocation(e.replace(t,``));return new ue({functionName:r,fileName:i[0],lineNumber:i[1],columnNumber:i[2],source:e})},this)},`ErrorStackParser$$parseFFOrSafari`)}}h(de,`ErrorStackParser`);var fe=new de,w=typeof process==`object`&&typeof process.versions==`object`&&typeof process.versions.node==`string`&&!process.browser,pe=w&&typeof module<`u`&&typeof module.exports<`u`&&typeof oe<`u`&&typeof __dirname<`u`,me=w&&!pe;globalThis.Bun;var he=!w&&!(typeof Deno<`u`),ge=he&&typeof window==`object`&&typeof document==`object`&&typeof document.createElement==`function`&&`sessionStorage`in window&&typeof importScripts!=`function`,_e=he&&typeof importScripts==`function`&&typeof self==`object`;typeof navigator==`object`&&typeof navigator.userAgent==`string`&&navigator.userAgent.indexOf(`Chrome`)==-1&&navigator.userAgent.indexOf(`Safari`);var ve,ye,be,xe,Se;async function Ce(){if(!w||(ve=(await import(`./__vite-browser-external-6-UwTyQC.js`).then(l(1))).default,xe=await import(`./__vite-browser-external-6-UwTyQC.js`).then(l(1)),Se=await import(`./__vite-browser-external-6-UwTyQC.js`).then(l(1)),be=(await import(`./__vite-browser-external-6-UwTyQC.js`).then(l(1))).default,ye=await import(`./__vite-browser-external-6-UwTyQC.js`).then(l(1)),De=ye.sep,typeof oe<`u`))return;let e={fs:xe,crypto:await import(`./__vite-browser-external-6-UwTyQC.js`).then(l(1)),ws:await import(`./__vite-browser-external-6-UwTyQC.js`).then(l(1)),child_process:await import(`./__vite-browser-external-6-UwTyQC.js`).then(l(1))};globalThis.require=function(t){return e[t]}}h(Ce,`initNodeModules`);function we(e,t){return ye.resolve(t||`.`,e)}h(we,`node_resolvePath`);function Te(e,t){return t===void 0&&(t=location),new URL(e,t).toString()}h(Te,`browser_resolvePath`);var Ee=w?we:Te,De;w||(De=`/`);function Oe(e,t){return e.startsWith(`file://`)&&(e=e.slice(7)),e.includes(`://`)?{response:fetch(e)}:{binary:Se.readFile(e).then(e=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength))}}h(Oe,`node_getBinaryResponse`);function ke(e,t){let n=new URL(e,location);return{response:fetch(n,t?{integrity:t}:{})}}h(ke,`browser_getBinaryResponse`);var Ae=w?Oe:ke;async function je(e,t){let{response:n,binary:r}=Ae(e,t);if(r)return r;let i=await n;if(!i.ok)throw Error(`Failed to load '${e}': request failed.`);return new Uint8Array(await i.arrayBuffer())}h(je,`loadBinaryFile`);var Me;if(ge)Me=h(async e=>await import(e),`loadScript`);else if(_e)Me=h(async e=>{try{globalThis.importScripts(e)}catch(t){if(t instanceof TypeError)await import(e);else throw t}},`loadScript`);else if(w)Me=Ne;else throw Error(`Cannot determine runtime environment`);async function Ne(e){e.startsWith(`file://`)&&(e=e.slice(7)),e.includes(`://`)?be.runInThisContext(await(await fetch(e)).text()):await import(ve.pathToFileURL(e).href)}h(Ne,`nodeLoadScript`);async function Pe(e){if(w){await Ce();let t=await Se.readFile(e,{encoding:`utf8`});return JSON.parse(t)}else return await(await fetch(e)).json()}h(Pe,`loadLockFile`);async function Fe(){if(pe)return __dirname;let e;try{throw Error()}catch(t){e=t}let t=fe.parse(e)[0].fileName;if(w&&!t.startsWith(`file://`)&&(t=`file://${t}`),me){let e=await import(`./__vite-browser-external-6-UwTyQC.js`).then(l(1));return(await import(`./__vite-browser-external-6-UwTyQC.js`).then(l(1))).fileURLToPath(e.dirname(t))}let n=t.lastIndexOf(De);if(n===-1)throw Error(`Could not extract indexURL path from pyodide module location`);return t.slice(0,n)}h(Fe,`calculateDirname`);function Ie(e){let t=e.FS,n=e.FS.filesystems.MEMFS,r=e.PATH,i={DIR_MODE:16895,FILE_MODE:33279,mount:function(e){if(!e.opts.fileSystemHandle)throw Error(`opts.fileSystemHandle is required`);return n.mount.apply(null,arguments)},syncfs:async(e,t,n)=>{try{let r=i.getLocalSet(e),a=await i.getRemoteSet(e),o=t?a:r,s=t?r:a;await i.reconcile(e,o,s),n(null)}catch(e){n(e)}},getLocalSet:e=>{let n=Object.create(null);function i(e){return e!==`.`&&e!==`..`}h(i,`isRealDir`);function a(e){return t=>r.join2(e,t)}h(a,`toAbsolute`);let o=t.readdir(e.mountpoint).filter(i).map(a(e.mountpoint));for(;o.length;){let e=o.pop(),r=t.stat(e);t.isDir(r.mode)&&o.push.apply(o,t.readdir(e).filter(i).map(a(e))),n[e]={timestamp:r.mtime,mode:r.mode}}return{type:`local`,entries:n}},getRemoteSet:async e=>{let t=Object.create(null),n=await Le(e.opts.fileSystemHandle);for(let[a,o]of n)a!==`.`&&(t[r.join2(e.mountpoint,a)]={timestamp:o.kind===`file`?new Date((await o.getFile()).lastModified):new Date,mode:o.kind===`file`?i.FILE_MODE:i.DIR_MODE});return{type:`remote`,entries:t,handles:n}},loadLocalEntry:e=>{let r=t.lookupPath(e).node,i=t.stat(e);if(t.isDir(i.mode))return{timestamp:i.mtime,mode:i.mode};if(t.isFile(i.mode))return r.contents=n.getFileDataAsTypedArray(r),{timestamp:i.mtime,mode:i.mode,contents:r.contents};throw Error(`node type not supported`)},storeLocalEntry:(e,n)=>{if(t.isDir(n.mode))t.mkdirTree(e,n.mode);else if(t.isFile(n.mode))t.writeFile(e,n.contents,{canOwn:!0});else throw Error(`node type not supported`);t.chmod(e,n.mode),t.utime(e,n.timestamp,n.timestamp)},removeLocalEntry:e=>{var n=t.stat(e);t.isDir(n.mode)?t.rmdir(e):t.isFile(n.mode)&&t.unlink(e)},loadRemoteEntry:async e=>{if(e.kind===`file`){let t=await e.getFile();return{contents:new Uint8Array(await t.arrayBuffer()),mode:i.FILE_MODE,timestamp:new Date(t.lastModified)}}else{if(e.kind===`directory`)return{mode:i.DIR_MODE,timestamp:new Date};throw Error(`unknown kind: `+e.kind)}},storeRemoteEntry:async(e,n,i)=>{let a=e.get(r.dirname(n)),o=t.isFile(i.mode)?await a.getFileHandle(r.basename(n),{create:!0}):await a.getDirectoryHandle(r.basename(n),{create:!0});if(o.kind===`file`){let e=await o.createWritable();await e.write(i.contents),await e.close()}e.set(n,o)},removeRemoteEntry:async(e,t)=>{await e.get(r.dirname(t)).removeEntry(r.basename(t)),e.delete(t)},reconcile:async(e,n,a)=>{let o=0,s=[];Object.keys(n.entries).forEach(function(e){let r=n.entries[e],i=a.entries[e];(!i||t.isFile(r.mode)&&r.timestamp.getTime()>i.timestamp.getTime())&&(s.push(e),o++)}),s.sort();let c=[];if(Object.keys(a.entries).forEach(function(e){n.entries[e]||(c.push(e),o++)}),c.sort().reverse(),!o)return;let l=n.type===`remote`?n.handles:a.handles;for(let t of s){let n=r.normalize(t.replace(e.mountpoint,`/`)).substring(1);if(a.type===`local`){let e=l.get(n),r=await i.loadRemoteEntry(e);i.storeLocalEntry(t,r)}else{let e=i.loadLocalEntry(t);await i.storeRemoteEntry(l,n,e)}}for(let t of c)if(a.type===`local`)i.removeLocalEntry(t);else{let n=r.normalize(t.replace(e.mountpoint,`/`)).substring(1);await i.removeRemoteEntry(l,n)}}};e.FS.filesystems.NATIVEFS_ASYNC=i}h(Ie,`initializeNativeFS`);var Le=h(async e=>{let t=[];async function n(e){for await(let r of e.values())t.push(r),r.kind===`directory`&&await n(r)}h(n,`collect`),await n(e);let r=new Map;r.set(`.`,e);for(let n of t){let t=(await e.resolve(n)).join(`/`);r.set(t,n)}return r},`getFsHandles`);function Re(e){let t={noImageDecoding:!0,noAudioDecoding:!0,noWasmDecoding:!1,preRun:Ue(e),quit(e,n){throw t.exited={status:e,toThrow:n},n},print:e.stdout,printErr:e.stderr,thisProgram:e._sysExecutable,arguments:e.args,API:{config:e},locateFile:t=>e.indexURL+t,instantiateWasm:We(e.indexURL)};return t}h(Re,`createSettings`);function ze(e){return function(t){try{t.FS.mkdirTree(e)}catch(t){console.error(`Error occurred while making a home directory '${e}':`),console.error(t),console.error(`Using '/' for a home directory instead`),e=`/`}t.FS.chdir(e)}}h(ze,`createHomeDirectory`);function Be(e){return function(t){Object.assign(t.ENV,e)}}h(Be,`setEnvironment`);function Ve(e){return e?[async t=>{t.addRunDependency(`fsInitHook`);try{await e(t.FS,{sitePackages:t.API.sitePackages})}finally{t.removeRunDependency(`fsInitHook`)}}]:[]}h(Ve,`callFsInitHook`);function He(e){let t=je(e);return async e=>{let n=e._py_version_major(),r=e._py_version_minor();e.FS.mkdirTree(`/lib`),e.API.sitePackages=`/lib/python${n}.${r}/site-packages`,e.FS.mkdirTree(e.API.sitePackages),e.addRunDependency(`install-stdlib`);try{let i=await t;e.FS.writeFile(`/lib/python${n}${r}.zip`,i)}catch(e){console.error(`Error occurred while installing the standard library:`),console.error(e)}finally{e.removeRunDependency(`install-stdlib`)}}}h(He,`installStdlib`);function Ue(e){let t;return t=e.stdLibURL==null?e.indexURL+`python_stdlib.zip`:e.stdLibURL,[...Ve(e.fsInit),He(t),ze(e.env.HOME),Be(e.env),Ie]}h(Ue,`getFileSystemInitializationFuncs`);function We(e){if(typeof WasmOffsetConverter<`u`)return;let{binary:t,response:n}=Ae(e+`pyodide.asm.wasm`);return function(e,r){return async function(){try{let i;i=n?await WebAssembly.instantiateStreaming(n,e):await WebAssembly.instantiate(await t,e);let{instance:a,module:o}=i;r(a,o)}catch(e){console.warn(`wasm instantiation failed!`),console.warn(e)}}(),{}}}h(We,`getInstantiateWasmFunc`);var Ge=`0.27.7`;async function Ke(e={}){var t,n;await Ce();let r=e.indexURL||await Fe();r=Ee(r),r.endsWith(`/`)||(r+=`/`),e.indexURL=r;let i={fullStdLib:!1,jsglobals:globalThis,stdin:globalThis.prompt?globalThis.prompt:void 0,lockFileURL:r+`pyodide-lock.json`,args:[],env:{},packageCacheDir:r,packages:[],enableRunUntilComplete:!0,checkAPIVersion:!0,BUILD_ID:`e94377f5ce7dcf67e0417b69a0016733c2cfb6b4622ee8c490a6f17eb58e863b`},a=Object.assign(i,e);(t=a.env).HOME??(t.HOME=`/home/pyodide`),(n=a.env).PYTHONINSPECT??(n.PYTHONINSPECT=`1`);let o=Re(a),s=o.API;if(s.lockFilePromise=Pe(a.lockFileURL),typeof _createPyodideModule!=`function`){let e=`${a.indexURL}pyodide.asm.js`;await Me(e)}let c;if(e._loadSnapshot){let t=await e._loadSnapshot;c=ArrayBuffer.isView(t)?t:new Uint8Array(t),o.noInitialRun=!0,o.INITIAL_MEMORY=c.length}let l=await _createPyodideModule(o);if(o.exited)throw o.exited.toThrow;if(e.pyproxyToStringRepr&&s.setPyProxyToStringMethod(!0),s.version!==Ge&&a.checkAPIVersion)throw Error(`Pyodide version does not match: '${Ge}' <==> '${s.version}'. If you updated the Pyodide version, make sure you also updated the 'indexURL' parameter passed to loadPyodide.`);l.locateFile=e=>{throw Error(`Didn't expect to load any more file_packager files!`)};let u;c&&(u=s.restoreSnapshot(c));let d=s.finalizeBootstrap(u,e._snapshotDeserializer);return s.sys.path.insert(0,``),d.version.includes(`dev`)||s.setCdnUrl(`https://cdn.jsdelivr.net/pyodide/v${d.version}/full/`),s._pyodide.set_excepthook(),await s.packageIndexReady,s.initializeStreams(a.stdin,a.stdout,a.stderr),d}h(Ke,`loadPyodide`);function qe(e){return e.includes(`dev`),`v${Ge}`}var Je=class{buffer;started=!1;onMessage;constructor(e){this.onMessage=e,this.buffer=[]}push=e=>{this.started?this.onMessage(e):this.buffer.push(e)};start=()=>{this.started=!0,this.buffer.forEach(e=>this.onMessage(e)),this.buffer=[]}};const Ye={NOOP:()=>{},ASYNC_NOOP:async()=>{},THROW:()=>{throw Error(`Should not be called`)},asUpdater:e=>typeof e==`function`?e:()=>e,identity:e=>e},Xe=(e,t)=>{let n=`[${e}]`;return{debug:(...e)=>console.debug(n,...e),log:(...e)=>t.log(n,...e),warn:(...e)=>t.warn(n,...e),error:(...e)=>t.error(n,...e),trace:(...e)=>t.trace(n,...e),get:n=>Xe(`${e}:${n}`,t),disabled:(e=!0)=>e?Qe:t}},Ze={debug:(...e)=>{console.debug(...e)},log:(...e)=>{console.log(...e)},warn:(...e)=>{console.warn(...e)},error:(...e)=>{console.error(...e)},trace:(...e)=>{console.trace(...e)},get:e=>Xe(`marimo:${e}`,Ze),disabled:(e=!0)=>e?Qe:Ze},Qe={debug:()=>Ye.NOOP,log:()=>Ye.NOOP,warn:()=>Ye.NOOP,error:()=>Ye.NOOP,trace:()=>Ye.NOOP,get:()=>Qe,disabled:()=>Qe};function $e(){return typeof window<`u`&&window.Logger||Ze}const T=$e();var et=class{promise;resolve;reject;status=`pending`;constructor(){this.promise=new Promise((e,t)=>{this.reject=e=>{this.status=`rejected`,t(e)},this.resolve=t=>{this.status=`resolved`,e(t)}})}};Object.freeze({status:`aborted`});function E(e,t,n){function r(n,r){if(n._zod||Object.defineProperty(n,`_zod`,{value:{def:r,constr:o,traits:new Set},enumerable:!1}),n._zod.traits.has(e))return;n._zod.traits.add(e),t(n,r);let i=o.prototype,a=Object.keys(i);for(let e=0;e<a.length;e++){let t=a[e];t in n||(n[t]=i[t].bind(n))}}let i=n?.Parent??Object;class a extends i{}Object.defineProperty(a,`name`,{value:e});function o(e){var t;let i=n?.Parent?new a:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(let e of i._zod.deferred)e();return i}return Object.defineProperty(o,`init`,{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:t=>n?.Parent&&t instanceof n.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(o,`name`,{value:e}),o}var D=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}},tt=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name=`ZodEncodeError`}};const nt={};function O(e){return e&&Object.assign(nt,e),nt}function rt(e){let t=Object.values(e).filter(e=>typeof e==`number`);return Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t)}function it(e,t){return typeof t==`bigint`?t.toString():t}function at(e){return{get value(){{let t=e();return Object.defineProperty(this,`value`,{value:t}),t}throw Error(`cached value already set`)}}}function ot(e){return e==null}function st(e){let t=e.startsWith(`^`)?1:0,n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function ct(e,t){let n=(e.toString().split(`.`)[1]||``).length,r=t.toString(),i=(r.split(`.`)[1]||``).length;if(i===0&&/\d?e-\d?/.test(r)){let e=r.match(/\d?e-(\d?)/);e?.[1]&&(i=Number.parseInt(e[1]))}let a=n>i?n:i;return Number.parseInt(e.toFixed(a).replace(`.`,``))%Number.parseInt(t.toFixed(a).replace(`.`,``))/10**a}const lt=Symbol(`evaluating`);function k(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==lt)return r===void 0&&(r=lt,r=n()),r},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function A(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function j(...e){let t={};for(let n of e){let e=Object.getOwnPropertyDescriptors(n);Object.assign(t,e)}return Object.defineProperties({},t)}function ut(e){return JSON.stringify(e)}function dt(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,``).replace(/[\s_-]+/g,`-`).replace(/^-+|-+$/g,``)}const ft=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{};function pt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const mt=at(()=>{if(typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{return Function(``),!0}catch{return!1}});function M(e){if(pt(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return!(pt(n)===!1||Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)===!1)}function ht(e){return M(e)?{...e}:Array.isArray(e)?[...e]:e}const gt=new Set([`string`,`number`,`symbol`]);function _t(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function N(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function P(e){let t=e;if(!t)return{};if(typeof t==`string`)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error==`string`?{...t,error:()=>t.error}:t}function vt(e){return Object.keys(e).filter(t=>e[t]._zod.optin===`optional`&&e[t]._zod.optout===`optional`)}const yt={safeint:[-(2**53-1),2**53-1],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function bt(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.pick() cannot be used on object schemas containing refinements`);return N(e,j(e._zod.def,{get shape(){let e={};for(let r in t){if(!(r in n.shape))throw Error(`Unrecognized key: "${r}"`);t[r]&&(e[r]=n.shape[r])}return A(this,`shape`,e),e},checks:[]}))}function xt(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.omit() cannot be used on object schemas containing refinements`);return N(e,j(e._zod.def,{get shape(){let r={...e._zod.def.shape};for(let e in t){if(!(e in n.shape))throw Error(`Unrecognized key: "${e}"`);t[e]&&delete r[e]}return A(this,`shape`,r),r},checks:[]}))}function St(e,t){if(!M(t))throw Error(`Invalid input to extend: expected a plain object`);let n=e._zod.def.checks;if(n&&n.length>0){let n=e._zod.def.shape;for(let e in t)if(Object.getOwnPropertyDescriptor(n,e)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return N(e,j(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t};return A(this,`shape`,n),n}}))}function Ct(e,t){if(!M(t))throw Error(`Invalid input to safeExtend: expected a plain object`);return N(e,j(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t};return A(this,`shape`,n),n}}))}function wt(e,t){return N(e,j(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t._zod.def.shape};return A(this,`shape`,n),n},get catchall(){return t._zod.def.catchall},checks:[]}))}function Tt(e,t,n){let r=t._zod.def.checks;if(r&&r.length>0)throw Error(`.partial() cannot be used on object schemas containing refinements`);return N(t,j(t._zod.def,{get shape(){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in r))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t])}else for(let t in r)i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t];return A(this,`shape`,i),i},checks:[]}))}function Et(e,t,n){return N(t,j(t._zod.def,{get shape(){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in i))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=new e({type:`nonoptional`,innerType:r[t]}))}else for(let t in r)i[t]=new e({type:`nonoptional`,innerType:r[t]});return A(this,`shape`,i),i}}))}function Dt(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function Ot(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function kt(e){return typeof e==`string`?e:e?.message}function F(e,t,n){let r={...e,path:e.path??[]};return e.message||(r.message=kt(e.inst?._zod.def?.error?.(e))??kt(t?.error?.(e))??kt(n.customError?.(e))??kt(n.localeError?.(e))??`Invalid input`),delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function At(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function jt(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}const Mt=(e,t)=>{e.name=`$ZodError`,Object.defineProperty(e,`_zod`,{value:e._zod,enumerable:!1}),Object.defineProperty(e,`issues`,{value:t,enumerable:!1}),e.message=JSON.stringify(t,it,2),Object.defineProperty(e,`toString`,{value:()=>e.message,enumerable:!1})},Nt=E(`$ZodError`,Mt),Pt=E(`$ZodError`,Mt,{Parent:Error});function Ft(e,t=e=>e.message){let n={},r=[];for(let i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}function It(e,t=e=>e.message){let n={_errors:[]},r=e=>{for(let i of e.issues)if(i.code===`invalid_union`&&i.errors.length)i.errors.map(e=>r({issues:e}));else if(i.code===`invalid_key`)r({issues:i.issues});else if(i.code===`invalid_element`)r({issues:i.issues});else if(i.path.length===0)n._errors.push(t(i));else{let e=n,r=0;for(;r<i.path.length;){let n=i.path[r];r===i.path.length-1?(e[n]=e[n]||{_errors:[]},e[n]._errors.push(t(i))):e[n]=e[n]||{_errors:[]},e=e[n],r++}}};return r(e),n}const Lt=e=>(t,n,r,i)=>{let a=r?Object.assign(r,{async:!1}):{async:!1},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise)throw new D;if(o.issues.length){let t=new(i?.Err??e)(o.issues.map(e=>F(e,a,O())));throw ft(t,i?.callee),t}return o.value},Rt=e=>async(t,n,r,i)=>{let a=r?Object.assign(r,{async:!0}):{async:!0},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise&&(o=await o),o.issues.length){let t=new(i?.Err??e)(o.issues.map(e=>F(e,a,O())));throw ft(t,i?.callee),t}return o.value},zt=e=>(t,n,r)=>{let i=r?{...r,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new D;return a.issues.length?{success:!1,error:new(e??Nt)(a.issues.map(e=>F(e,i,O())))}:{success:!0,data:a.value}},Bt=zt(Pt),Vt=e=>async(t,n,r)=>{let i=r?Object.assign(r,{async:!0}):{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new e(a.issues.map(e=>F(e,i,O())))}:{success:!0,data:a.value}},Ht=Vt(Pt),Ut=e=>(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return Lt(e)(t,n,i)},Wt=e=>(t,n,r)=>Lt(e)(t,n,r),Gt=e=>async(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return Rt(e)(t,n,i)},Kt=e=>async(t,n,r)=>Rt(e)(t,n,r),qt=e=>(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return zt(e)(t,n,i)},Jt=e=>(t,n,r)=>zt(e)(t,n,r),Yt=e=>async(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return Vt(e)(t,n,i)},Xt=e=>async(t,n,r)=>Vt(e)(t,n,r),Zt=/^[cC][^\s-]{8,}$/,Qt=/^[0-9a-z]+$/,$t=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,en=/^[0-9a-vA-V]{20}$/,tn=/^[A-Za-z0-9]{27}$/,nn=/^[a-zA-Z0-9_-]{21}$/,rn=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,an=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,on=e=>e?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,sn=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;function cn(){return RegExp(`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`,`u`)}const ln=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,un=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,dn=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,fn=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,pn=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,mn=/^[A-Za-z0-9_-]*$/,hn=/^\+[1-9]\d{6,14}$/,gn=`(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`,_n=RegExp(`^${gn}$`);function vn(e){let t=`(?:[01]\\d|2[0-3]):[0-5]\\d`;return typeof e.precision==`number`?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function yn(e){return RegExp(`^${vn(e)}$`)}function bn(e){let t=vn({precision:e.precision}),n=[`Z`];e.local&&n.push(``),e.offset&&n.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);let r=`${t}(?:${n.join(`|`)})`;return RegExp(`^${gn}T(?:${r})$`)}const xn=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??``}}`:`[\\s\\S]*`;return RegExp(`^${t}$`)},Sn=/^-?\d+$/,Cn=/^-?\d+(?:\.\d+)?$/,wn=/^(?:true|false)$/i,Tn=/^[^A-Z]*$/,En=/^[^a-z]*$/,I=E(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Dn={number:`number`,bigint:`bigint`,object:`date`},On=E(`$ZodCheckLessThan`,(e,t)=>{I.init(e,t);let n=Dn[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??1/0;t.value<r&&(t.inclusive?n.maximum=t.value:n.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:`too_big`,maximum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),kn=E(`$ZodCheckGreaterThan`,(e,t)=>{I.init(e,t);let n=Dn[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??-1/0;t.value>r&&(t.inclusive?n.minimum=t.value:n.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:`too_small`,minimum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),An=E(`$ZodCheckMultipleOf`,(e,t)=>{I.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw Error(`Cannot mix number and bigint in multiple_of check.`);(typeof n.value==`bigint`?n.value%t.value===BigInt(0):ct(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:`not_multiple_of`,divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),jn=E(`$ZodCheckNumberFormat`,(e,t)=>{I.init(e,t),t.format=t.format||`float64`;let n=t.format?.includes(`int`),r=n?`int`:`number`,[i,a]=yt[t.format];e._zod.onattach.push(e=>{let r=e._zod.bag;r.format=t.format,r.minimum=i,r.maximum=a,n&&(r.pattern=Sn)}),e._zod.check=o=>{let s=o.value;if(n){if(!Number.isInteger(s)){o.issues.push({expected:r,format:t.format,code:`invalid_type`,continue:!1,input:s,inst:e});return}if(!Number.isSafeInteger(s)){s>0?o.issues.push({input:s,code:`too_big`,maximum:2**53-1,note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort}):o.issues.push({input:s,code:`too_small`,minimum:-(2**53-1),note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort});return}}s<i&&o.issues.push({origin:`number`,input:s,code:`too_small`,minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>a&&o.issues.push({origin:`number`,input:s,code:`too_big`,maximum:a,inclusive:!0,inst:e,continue:!t.abort})}}),Mn=E(`$ZodCheckMaxLength`,(e,t)=>{var n;I.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!ot(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.maximum??1/0;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{let r=n.value;if(r.length<=t.maximum)return;let i=At(r);n.issues.push({origin:i,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Nn=E(`$ZodCheckMinLength`,(e,t)=>{var n;I.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!ot(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.minimum??-1/0;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{let r=n.value;if(r.length>=t.minimum)return;let i=At(r);n.issues.push({origin:i,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Pn=E(`$ZodCheckLengthEquals`,(e,t)=>{var n;I.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!ot(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{let r=n.value,i=r.length;if(i===t.length)return;let a=At(r),o=i>t.length;n.issues.push({origin:a,...o?{code:`too_big`,maximum:t.length}:{code:`too_small`,minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),Fn=E(`$ZodCheckStringFormat`,(e,t)=>{var n,r;I.init(e,t),e._zod.onattach.push(e=>{let n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??=new Set,n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),In=E(`$ZodCheckRegex`,(e,t)=>{Fn.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:`regex`,input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),Ln=E(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=Tn,Fn.init(e,t)}),Rn=E(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=En,Fn.init(e,t)}),zn=E(`$ZodCheckIncludes`,(e,t)=>{I.init(e,t);let n=_t(t.includes),r=new RegExp(typeof t.position==`number`?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(r)}),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:`string`,code:`invalid_format`,format:`includes`,includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),Bn=E(`$ZodCheckStartsWith`,(e,t)=>{I.init(e,t);let n=RegExp(`^${_t(t.prefix)}.*`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`starts_with`,prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),Vn=E(`$ZodCheckEndsWith`,(e,t)=>{I.init(e,t);let n=RegExp(`.*${_t(t.suffix)}$`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`ends_with`,suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),Hn=E(`$ZodCheckOverwrite`,(e,t)=>{I.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});var Un=class{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),--this.indent}write(e){if(typeof e==`function`){e(this,{execution:`sync`}),e(this,{execution:`async`});return}let t=e.split(`
|
|
4
|
-
`).filter(e=>e),n=Math.min(...t.map(e=>e.length-e.trimStart().length)),r=t.map(e=>e.slice(n)).map(e=>` `.repeat(this.indent*2)+e);for(let e of r)this.content.push(e)}compile(){let e=Function,t=this?.args,n=[...(this?.content??[``]).map(e=>` ${e}`)];return new e(...t,n.join(`
|
|
5
|
-
`))}};const Wn={major:4,minor:3,patch:6},L=E(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Wn;let r=[...e._zod.def.checks??[]];e._zod.traits.has(`$ZodCheck`)&&r.unshift(e);for(let t of r)for(let n of t._zod.onattach)n(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(e,t,n)=>{let r=Dt(e),i;for(let a of t){if(a._zod.def.when){if(!a._zod.def.when(e))continue}else if(r)continue;let t=e.issues.length,o=a._zod.check(e);if(o instanceof Promise&&n?.async===!1)throw new D;if(i||o instanceof Promise)i=(i??Promise.resolve()).then(async()=>{await o,e.issues.length!==t&&(r||=Dt(e,t))});else{if(e.issues.length===t)continue;r||=Dt(e,t)}}return i?i.then(()=>e):e},n=(n,i,a)=>{if(Dt(n))return n.aborted=!0,n;let o=t(i,r,a);if(o instanceof Promise){if(a.async===!1)throw new D;return o.then(t=>e._zod.parse(t,a))}return e._zod.parse(o,a)};e._zod.run=(i,a)=>{if(a.skipChecks)return e._zod.parse(i,a);if(a.direction===`backward`){let t=e._zod.parse({value:i.value,issues:[]},{...a,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,i,a)):n(t,i,a)}let o=e._zod.parse(i,a);if(o instanceof Promise){if(a.async===!1)throw new D;return o.then(e=>t(e,r,a))}return t(o,r,a)}}k(e,`~standard`,()=>({validate:t=>{try{let n=Bt(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch{return Ht(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:`zod`,version:1}))}),Gn=E(`$ZodString`,(e,t)=>{L.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??xn(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value==`string`||n.issues.push({expected:`string`,code:`invalid_type`,input:n.value,inst:e}),n}}),R=E(`$ZodStringFormat`,(e,t)=>{Fn.init(e,t),Gn.init(e,t)}),Kn=E(`$ZodGUID`,(e,t)=>{t.pattern??=an,R.init(e,t)}),qn=E(`$ZodUUID`,(e,t)=>{if(t.version){let e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(e===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??=on(e)}else t.pattern??=on();R.init(e,t)}),Jn=E(`$ZodEmail`,(e,t)=>{t.pattern??=sn,R.init(e,t)}),Yn=E(`$ZodURL`,(e,t)=>{R.init(e,t),e._zod.check=n=>{try{let r=n.value.trim(),i=new URL(r);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.hostname)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid hostname`,pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(i.protocol.endsWith(`:`)?i.protocol.slice(0,-1):i.protocol)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid protocol`,pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),t.normalize?n.value=i.href:n.value=r;return}catch{n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort})}}}),Xn=E(`$ZodEmoji`,(e,t)=>{t.pattern??=cn(),R.init(e,t)}),Zn=E(`$ZodNanoID`,(e,t)=>{t.pattern??=nn,R.init(e,t)}),Qn=E(`$ZodCUID`,(e,t)=>{t.pattern??=Zt,R.init(e,t)}),$n=E(`$ZodCUID2`,(e,t)=>{t.pattern??=Qt,R.init(e,t)}),er=E(`$ZodULID`,(e,t)=>{t.pattern??=$t,R.init(e,t)}),tr=E(`$ZodXID`,(e,t)=>{t.pattern??=en,R.init(e,t)}),nr=E(`$ZodKSUID`,(e,t)=>{t.pattern??=tn,R.init(e,t)}),rr=E(`$ZodISODateTime`,(e,t)=>{t.pattern??=bn(t),R.init(e,t)}),ir=E(`$ZodISODate`,(e,t)=>{t.pattern??=_n,R.init(e,t)}),ar=E(`$ZodISOTime`,(e,t)=>{t.pattern??=yn(t),R.init(e,t)}),or=E(`$ZodISODuration`,(e,t)=>{t.pattern??=rn,R.init(e,t)}),sr=E(`$ZodIPv4`,(e,t)=>{t.pattern??=ln,R.init(e,t),e._zod.bag.format=`ipv4`}),cr=E(`$ZodIPv6`,(e,t)=>{t.pattern??=un,R.init(e,t),e._zod.bag.format=`ipv6`,e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:`invalid_format`,format:`ipv6`,input:n.value,inst:e,continue:!t.abort})}}}),lr=E(`$ZodCIDRv4`,(e,t)=>{t.pattern??=dn,R.init(e,t)}),ur=E(`$ZodCIDRv6`,(e,t)=>{t.pattern??=fn,R.init(e,t),e._zod.check=n=>{let r=n.value.split(`/`);try{if(r.length!==2)throw Error();let[e,t]=r;if(!t)throw Error();let n=Number(t);if(`${n}`!==t||n<0||n>128)throw Error();new URL(`http://[${e}]`)}catch{n.issues.push({code:`invalid_format`,format:`cidrv6`,input:n.value,inst:e,continue:!t.abort})}}});function dr(e){if(e===``)return!0;if(e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}const fr=E(`$ZodBase64`,(e,t)=>{t.pattern??=pn,R.init(e,t),e._zod.bag.contentEncoding=`base64`,e._zod.check=n=>{dr(n.value)||n.issues.push({code:`invalid_format`,format:`base64`,input:n.value,inst:e,continue:!t.abort})}});function pr(e){if(!mn.test(e))return!1;let t=e.replace(/[-_]/g,e=>e===`-`?`+`:`/`);return dr(t.padEnd(Math.ceil(t.length/4)*4,`=`))}const mr=E(`$ZodBase64URL`,(e,t)=>{t.pattern??=mn,R.init(e,t),e._zod.bag.contentEncoding=`base64url`,e._zod.check=n=>{pr(n.value)||n.issues.push({code:`invalid_format`,format:`base64url`,input:n.value,inst:e,continue:!t.abort})}}),hr=E(`$ZodE164`,(e,t)=>{t.pattern??=hn,R.init(e,t)});function gr(e,t=null){try{let n=e.split(`.`);if(n.length!==3)return!1;let[r]=n;if(!r)return!1;let i=JSON.parse(atob(r));return!(`typ`in i&&i?.typ!==`JWT`||!i.alg||t&&(!(`alg`in i)||i.alg!==t))}catch{return!1}}const _r=E(`$ZodJWT`,(e,t)=>{R.init(e,t),e._zod.check=n=>{gr(n.value,t.alg)||n.issues.push({code:`invalid_format`,format:`jwt`,input:n.value,inst:e,continue:!t.abort})}}),vr=E(`$ZodNumber`,(e,t)=>{L.init(e,t),e._zod.pattern=e._zod.bag.pattern??Cn,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}let i=n.value;if(typeof i==`number`&&!Number.isNaN(i)&&Number.isFinite(i))return n;let a=typeof i==`number`?Number.isNaN(i)?`NaN`:Number.isFinite(i)?void 0:`Infinity`:void 0;return n.issues.push({expected:`number`,code:`invalid_type`,input:i,inst:e,...a?{received:a}:{}}),n}}),yr=E(`$ZodNumberFormat`,(e,t)=>{jn.init(e,t),vr.init(e,t)}),br=E(`$ZodBoolean`,(e,t)=>{L.init(e,t),e._zod.pattern=wn,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}let i=n.value;return typeof i==`boolean`||n.issues.push({expected:`boolean`,code:`invalid_type`,input:i,inst:e}),n}}),xr=E(`$ZodUnknown`,(e,t)=>{L.init(e,t),e._zod.parse=e=>e}),Sr=E(`$ZodNever`,(e,t)=>{L.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:`never`,code:`invalid_type`,input:t.value,inst:e}),t)});function Cr(e,t,n){e.issues.length&&t.issues.push(...Ot(n,e.issues)),t.value[n]=e.value}const wr=E(`$ZodArray`,(e,t)=>{L.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Array.isArray(i))return n.issues.push({expected:`array`,code:`invalid_type`,input:i,inst:e}),n;n.value=Array(i.length);let a=[];for(let e=0;e<i.length;e++){let o=i[e],s=t.element._zod.run({value:o,issues:[]},r);s instanceof Promise?a.push(s.then(t=>Cr(t,n,e))):Cr(s,n,e)}return a.length?Promise.all(a).then(()=>n):n}});function Tr(e,t,n,r,i){if(e.issues.length){if(i&&!(n in r))return;t.issues.push(...Ot(n,e.issues))}e.value===void 0?n in r&&(t.value[n]=void 0):t.value[n]=e.value}function Er(e){let t=Object.keys(e.shape);for(let n of t)if(!e.shape?.[n]?._zod?.traits?.has(`$ZodType`))throw Error(`Invalid element at key "${n}": expected a Zod schema`);let n=vt(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function Dr(e,t,n,r,i,a){let o=[],s=i.keySet,c=i.catchall._zod,l=c.def.type,u=c.optout===`optional`;for(let i in t){if(s.has(i))continue;if(l===`never`){o.push(i);continue}let a=c.run({value:t[i],issues:[]},r);a instanceof Promise?e.push(a.then(e=>Tr(e,n,i,t,u))):Tr(a,n,i,t,u)}return o.length&&n.issues.push({code:`unrecognized_keys`,keys:o,input:t,inst:a}),e.length?Promise.all(e).then(()=>n):n}const Or=E(`$ZodObject`,(e,t)=>{if(L.init(e,t),!Object.getOwnPropertyDescriptor(t,`shape`)?.get){let e=t.shape;Object.defineProperty(t,`shape`,{get:()=>{let n={...e};return Object.defineProperty(t,`shape`,{value:n}),n}})}let n=at(()=>Er(t));k(e._zod,`propValues`,()=>{let e=t.shape,n={};for(let t in e){let r=e[t]._zod;if(r.values){n[t]??(n[t]=new Set);for(let e of r.values)n[t].add(e)}}return n});let r=pt,i=t.catchall,a;e._zod.parse=(t,o)=>{a??=n.value;let s=t.value;if(!r(s))return t.issues.push({expected:`object`,code:`invalid_type`,input:s,inst:e}),t;t.value={};let c=[],l=a.shape;for(let e of a.keys){let n=l[e],r=n._zod.optout===`optional`,i=n._zod.run({value:s[e],issues:[]},o);i instanceof Promise?c.push(i.then(n=>Tr(n,t,e,s,r))):Tr(i,t,e,s,r)}return i?Dr(c,s,t,o,n.value,e):c.length?Promise.all(c).then(()=>t):t}}),kr=E(`$ZodObjectJIT`,(e,t)=>{Or.init(e,t);let n=e._zod.parse,r=at(()=>Er(t)),i=e=>{let t=new Un([`shape`,`payload`,`ctx`]),n=r.value,i=e=>{let t=ut(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write(`const input = payload.value;`);let a=Object.create(null),o=0;for(let e of n.keys)a[e]=`key_${o++}`;t.write(`const newResult = {};`);for(let r of n.keys){let n=a[r],o=ut(r),s=e[r]?._zod?.optout===`optional`;t.write(`const ${n} = ${i(r)};`),s?t.write(`
|
|
6
|
-
if (${n}.issues.length) {
|
|
7
|
-
if (${o} in input) {
|
|
8
|
-
payload.issues = payload.issues.concat(${n}.issues.map(iss => ({
|
|
9
|
-
...iss,
|
|
10
|
-
path: iss.path ? [${o}, ...iss.path] : [${o}]
|
|
11
|
-
})));
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (${n}.value === undefined) {
|
|
16
|
-
if (${o} in input) {
|
|
17
|
-
newResult[${o}] = undefined;
|
|
18
|
-
}
|
|
19
|
-
} else {
|
|
20
|
-
newResult[${o}] = ${n}.value;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
`):t.write(`
|
|
24
|
-
if (${n}.issues.length) {
|
|
25
|
-
payload.issues = payload.issues.concat(${n}.issues.map(iss => ({
|
|
26
|
-
...iss,
|
|
27
|
-
path: iss.path ? [${o}, ...iss.path] : [${o}]
|
|
28
|
-
})));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (${n}.value === undefined) {
|
|
32
|
-
if (${o} in input) {
|
|
33
|
-
newResult[${o}] = undefined;
|
|
34
|
-
}
|
|
35
|
-
} else {
|
|
36
|
-
newResult[${o}] = ${n}.value;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
`)}t.write(`payload.value = newResult;`),t.write(`return payload;`);let s=t.compile();return(t,n)=>s(e,t,n)},a,o=pt,s=!nt.jitless,c=s&&mt.value,l=t.catchall,u;e._zod.parse=(d,f)=>{u??=r.value;let p=d.value;return o(p)?s&&c&&f?.async===!1&&f.jitless!==!0?(a||=i(t.shape),d=a(d,f),l?Dr([],p,d,f,u,e):d):n(d,f):(d.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),d)}});function Ar(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!Dt(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>F(e,r,O())))}),t)}const jr=E(`$ZodUnion`,(e,t)=>{L.init(e,t),k(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),k(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),k(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),k(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>st(e.source)).join(`|`)})$`)}});let n=t.options.length===1,r=t.options[0]._zod.run;e._zod.parse=(i,a)=>{if(n)return r(i,a);let o=!1,s=[];for(let e of t.options){let t=e._zod.run({value:i.value,issues:[]},a);if(t instanceof Promise)s.push(t),o=!0;else{if(t.issues.length===0)return t;s.push(t)}}return o?Promise.all(s).then(t=>Ar(t,i,e,a)):Ar(s,i,e,a)}}),Mr=E(`$ZodIntersection`,(e,t)=>{L.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([t,n])=>Pr(e,t,n)):Pr(e,i,a)}});function Nr(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(M(e)&&M(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};for(let n of r){let r=Nr(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=Nr(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function Pr(e,t,n){let r=new Map,i;for(let n of t.issues)if(n.code===`unrecognized_keys`){i??=n;for(let e of n.keys)r.has(e)||r.set(e,{}),r.get(e).l=!0}else e.issues.push(n);for(let t of n.issues)if(t.code===`unrecognized_keys`)for(let e of t.keys)r.has(e)||r.set(e,{}),r.get(e).r=!0;else e.issues.push(t);let a=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(a.length&&i&&e.issues.push({...i,keys:a}),Dt(e))return e;let o=Nr(t.value,n.value);if(!o.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}const Fr=E(`$ZodRecord`,(e,t)=>{L.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!M(i))return n.issues.push({expected:`record`,code:`invalid_type`,input:i,inst:e}),n;let a=[],o=t.keyType._zod.values;if(o){n.value={};let s=new Set;for(let e of o)if(typeof e==`string`||typeof e==`number`||typeof e==`symbol`){s.add(typeof e==`number`?e.toString():e);let o=t.valueType._zod.run({value:i[e],issues:[]},r);o instanceof Promise?a.push(o.then(t=>{t.issues.length&&n.issues.push(...Ot(e,t.issues)),n.value[e]=t.value})):(o.issues.length&&n.issues.push(...Ot(e,o.issues)),n.value[e]=o.value)}let c;for(let e in i)s.has(e)||(c??=[],c.push(e));c&&c.length>0&&n.issues.push({code:`unrecognized_keys`,input:i,inst:e,keys:c})}else{n.value={};for(let o of Reflect.ownKeys(i)){if(o===`__proto__`)continue;let s=t.keyType._zod.run({value:o,issues:[]},r);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof o==`string`&&Cn.test(o)&&s.issues.length){let e=t.keyType._zod.run({value:Number(o),issues:[]},r);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(s=e)}if(s.issues.length){t.mode===`loose`?n.value[o]=i[o]:n.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>F(e,r,O())),input:o,path:[o],inst:e});continue}let c=t.valueType._zod.run({value:i[o],issues:[]},r);c instanceof Promise?a.push(c.then(e=>{e.issues.length&&n.issues.push(...Ot(o,e.issues)),n.value[s.value]=e.value})):(c.issues.length&&n.issues.push(...Ot(o,c.issues)),n.value[s.value]=c.value)}}return a.length?Promise.all(a).then(()=>n):n}}),Ir=E(`$ZodEnum`,(e,t)=>{L.init(e,t);let n=rt(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=RegExp(`^(${n.filter(e=>gt.has(typeof e)).map(e=>typeof e==`string`?_t(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),Lr=E(`$ZodTransform`,(e,t)=>{L.init(e,t),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new tt(e.constructor.name);let i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n));if(i instanceof Promise)throw new D;return n.value=i,n}});function Rr(e,t){return e.issues.length&&t===void 0?{issues:[],value:void 0}:e}const zr=E(`$ZodOptional`,(e,t)=>{L.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,k(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),k(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${st(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(t.innerType._zod.optin===`optional`){let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(t=>Rr(t,e.value)):Rr(r,e.value)}return e.value===void 0?e:t.innerType._zod.run(e,n)}}),Br=E(`$ZodExactOptional`,(e,t)=>{zr.init(e,t),k(e._zod,`values`,()=>t.innerType._zod.values),k(e._zod,`pattern`,()=>t.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),Vr=E(`$ZodNullable`,(e,t)=>{L.init(e,t),k(e._zod,`optin`,()=>t.innerType._zod.optin),k(e._zod,`optout`,()=>t.innerType._zod.optout),k(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${st(e.source)}|null)$`):void 0}),k(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),Hr=E(`$ZodDefault`,(e,t)=>{L.init(e,t),e._zod.optin=`optional`,k(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>Ur(e,t)):Ur(r,t)}});function Ur(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const Wr=E(`$ZodPrefault`,(e,t)=>{L.init(e,t),e._zod.optin=`optional`,k(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(n.direction===`backward`||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),Gr=E(`$ZodNonOptional`,(e,t)=>{L.init(e,t),k(e._zod,`values`,()=>{let e=t.innerType._zod.values;return e?new Set([...e].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>Kr(t,e)):Kr(i,e)}});function Kr(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}const qr=E(`$ZodCatch`,(e,t)=>{L.init(e,t),k(e._zod,`optin`,()=>t.innerType._zod.optin),k(e._zod,`optout`,()=>t.innerType._zod.optout),k(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>F(e,n,O()))},input:e.value}),e.issues=[]),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>F(e,n,O()))},input:e.value}),e.issues=[]),e)}}),Jr=E(`$ZodPipe`,(e,t)=>{L.init(e,t),k(e._zod,`values`,()=>t.in._zod.values),k(e._zod,`optin`,()=>t.in._zod.optin),k(e._zod,`optout`,()=>t.out._zod.optout),k(e._zod,`propValues`,()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>Yr(e,t.in,n)):Yr(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>Yr(e,t.out,n)):Yr(r,t.out,n)}});function Yr(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const Xr=E(`$ZodReadonly`,(e,t)=>{L.init(e,t),k(e._zod,`propValues`,()=>t.innerType._zod.propValues),k(e._zod,`values`,()=>t.innerType._zod.values),k(e._zod,`optin`,()=>t.innerType?._zod?.optin),k(e._zod,`optout`,()=>t.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(Zr):Zr(r)}});function Zr(e){return e.value=Object.freeze(e.value),e}const Qr=E(`$ZodCustom`,(e,t)=>{I.init(e,t),L.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>$r(t,n,r,e));$r(i,n,r,e)}});function $r(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(jt(e))}}var ei,ti=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];return this._map.set(e,n),n&&typeof n==`object`&&`id`in n&&this._idmap.set(n.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}};function ni(){return new ti}(ei=globalThis).__zod_globalRegistry??(ei.__zod_globalRegistry=ni());const ri=globalThis.__zod_globalRegistry;function ii(e,t){return new e({type:`string`,...P(t)})}function ai(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...P(t)})}function oi(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...P(t)})}function si(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...P(t)})}function ci(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...P(t)})}function li(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...P(t)})}function ui(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...P(t)})}function di(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...P(t)})}function fi(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...P(t)})}function pi(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...P(t)})}function mi(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...P(t)})}function hi(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...P(t)})}function gi(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...P(t)})}function _i(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...P(t)})}function vi(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...P(t)})}function yi(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...P(t)})}function bi(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...P(t)})}function xi(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...P(t)})}function Si(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...P(t)})}function Ci(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...P(t)})}function wi(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...P(t)})}function Ti(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...P(t)})}function Ei(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...P(t)})}function Di(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...P(t)})}function Oi(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...P(t)})}function ki(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...P(t)})}function Ai(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...P(t)})}function ji(e,t){return new e({type:`number`,checks:[],...P(t)})}function Mi(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...P(t)})}function Ni(e,t){return new e({type:`boolean`,...P(t)})}function Pi(e){return new e({type:`unknown`})}function Fi(e,t){return new e({type:`never`,...P(t)})}function Ii(e,t){return new On({check:`less_than`,...P(t),value:e,inclusive:!1})}function Li(e,t){return new On({check:`less_than`,...P(t),value:e,inclusive:!0})}function Ri(e,t){return new kn({check:`greater_than`,...P(t),value:e,inclusive:!1})}function zi(e,t){return new kn({check:`greater_than`,...P(t),value:e,inclusive:!0})}function Bi(e,t){return new An({check:`multiple_of`,...P(t),value:e})}function Vi(e,t){return new Mn({check:`max_length`,...P(t),maximum:e})}function Hi(e,t){return new Nn({check:`min_length`,...P(t),minimum:e})}function Ui(e,t){return new Pn({check:`length_equals`,...P(t),length:e})}function Wi(e,t){return new In({check:`string_format`,format:`regex`,...P(t),pattern:e})}function Gi(e){return new Ln({check:`string_format`,format:`lowercase`,...P(e)})}function Ki(e){return new Rn({check:`string_format`,format:`uppercase`,...P(e)})}function qi(e,t){return new zn({check:`string_format`,format:`includes`,...P(t),includes:e})}function Ji(e,t){return new Bn({check:`string_format`,format:`starts_with`,...P(t),prefix:e})}function Yi(e,t){return new Vn({check:`string_format`,format:`ends_with`,...P(t),suffix:e})}function z(e){return new Hn({check:`overwrite`,tx:e})}function Xi(e){return z(t=>t.normalize(e))}function Zi(){return z(e=>e.trim())}function Qi(){return z(e=>e.toLowerCase())}function $i(){return z(e=>e.toUpperCase())}function ea(){return z(e=>dt(e))}function ta(e,t,n){return new e({type:`array`,element:t,...P(n)})}function na(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...P(n)})}function ra(e){let t=ia(n=>(n.addIssue=e=>{if(typeof e==`string`)n.issues.push(jt(e,n.value,t._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,r.input??=n.value,r.inst??=t,r.continue??=!t._zod.def.abort,n.issues.push(jt(r))}},e(n.value,n)));return t}function ia(e,t){let n=new I({check:`custom`,...P(t)});return n._zod.check=e,n}function aa(e){let t=e?.target??`draft-2020-12`;return t===`draft-4`&&(t=`draft-04`),t===`draft-7`&&(t=`draft-07`),{processors:e.processors??{},metadataRegistry:e?.metadata??ri,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:new Map,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,external:e?.external??void 0}}function B(e,t,n={path:[],schemaPath:[]}){var r;let i=e._zod.def,a=t.seen.get(e);if(a)return a.count++,n.schemaPath.includes(e)&&(a.cycle=n.path),a.schema;let o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o);let s=e._zod.toJSONSchema?.();if(s)o.schema=s;else{let r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,r);else{let n=o.schema,a=t.processors[i.type];if(!a)throw Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);a(e,t,n,r)}let a=e._zod.parent;a&&(o.ref||=a,B(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&Object.assign(o.schema,c),t.io===`input`&&V(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&o.schema._prefault&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function oa(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=new Map;for(let t of e.seen.entries()){let n=e.metadataRegistry.get(t[0])?.id;if(n){let e=r.get(n);if(e&&e!==t[0])throw Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}let i=t=>{let r=e.target===`draft-2020-12`?`$defs`:`definitions`;if(e.external){let n=e.external.registry.get(t[0])?.id,i=e.external.uri??(e=>e);if(n)return{ref:i(n)};let a=t[1].defId??t[1].schema.id??`schema${e.counter++}`;return t[1].defId=a,{defId:a,ref:`${i(`__shared`)}#/${r}/${a}`}}if(t[1]===n)return{ref:`#`};let i=`#/${r}/`,a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+a}},a=e=>{if(e[1].schema.$ref)return;let t=e[1],{ref:n,defId:r}=i(e);t.def={...t.schema},r&&(t.defId=r);let a=t.schema;for(let e in a)delete a[e];a.$ref=n};if(e.cycles===`throw`)for(let t of e.seen.entries()){let e=t[1];if(e.cycle)throw Error(`Cycle detected: #/${e.cycle?.join(`/`)}/<root>
|
|
40
|
-
|
|
41
|
-
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}if(r.count>1&&e.reused===`ref`){a(n);continue}}}function sa(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):Object.assign(i,s),Object.assign(i,a),t._zod.parent===o)for(let e in i)e===`$ref`||e===`allOf`||e in a||delete i[e];if(s.$ref&&n.def)for(let e in i)e===`$ref`||e===`allOf`||e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e===`$ref`||e===`allOf`||e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};for(let t of[...e.seen.entries()].reverse())r(t[0]);let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}Object.assign(i,n.def??n.schema);let a=e.external?.defs??{};for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(a[e.defId]=e.def)}e.external||Object.keys(a).length>0&&(e.target===`draft-2020-12`?i.$defs=a:i.definitions=a);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,`~standard`,{value:{...t[`~standard`],jsonSchema:{input:la(t,`input`,e.processors),output:la(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function V(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return V(r.element,n);if(r.type===`set`)return V(r.valueType,n);if(r.type===`lazy`)return V(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type===`default`||r.type===`prefault`)return V(r.innerType,n);if(r.type===`intersection`)return V(r.left,n)||V(r.right,n);if(r.type===`record`||r.type===`map`)return V(r.keyType,n)||V(r.valueType,n);if(r.type===`pipe`)return V(r.in,n)||V(r.out,n);if(r.type===`object`){for(let e in r.shape)if(V(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(V(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(V(e,n))return!0;return!!(r.rest&&V(r.rest,n))}return!1}const ca=(e,t={})=>n=>{let r=aa({...n,processors:t});return B(e,r),oa(r,e),sa(r,e)},la=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=aa({...i??{},target:a,io:t,processors:n});return B(e,o),oa(o,e),sa(o,e)},ua={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},da=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=ua[s]??s,i.format===``&&delete i.format,s===`time`&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c];e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},fa=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,format:s,multipleOf:c,exclusiveMaximum:l,exclusiveMinimum:u}=e._zod.bag;typeof s==`string`&&s.includes(`int`)?i.type=`integer`:i.type=`number`,typeof u==`number`&&(t.target===`draft-04`||t.target===`openapi-3.0`?(i.minimum=u,i.exclusiveMinimum=!0):i.exclusiveMinimum=u),typeof a==`number`&&(i.minimum=a,typeof u==`number`&&t.target!==`draft-04`&&(u>=a?delete i.minimum:delete i.exclusiveMinimum)),typeof l==`number`&&(t.target===`draft-04`||t.target===`openapi-3.0`?(i.maximum=l,i.exclusiveMaximum=!0):i.exclusiveMaximum=l),typeof o==`number`&&(i.maximum=o,typeof l==`number`&&t.target!==`draft-04`&&(l<=o?delete i.maximum:delete i.exclusiveMaximum)),typeof c==`number`&&(i.multipleOf=c)},pa=(e,t,n,r)=>{n.type=`boolean`},ma=(e,t,n,r)=>{n.not={}},ha=(e,t,n,r)=>{let i=e._zod.def,a=rt(i.entries);a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},ga=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Custom types cannot be represented in JSON Schema`)},_a=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Transforms cannot be represented in JSON Schema`)},va=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=e._zod.bag;typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=B(a.element,t,{...r,path:[...r.path,`items`]})},ya=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`,i.properties={};let o=a.shape;for(let e in o)i.properties[e]=B(o[e],t,{...r,path:[...r.path,`properties`,e]});let s=new Set(Object.keys(o)),c=new Set([...s].filter(e=>{let n=a.shape[e]._zod;return t.io===`input`?n.optin===void 0:n.optout===void 0}));c.size>0&&(i.required=Array.from(c)),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=B(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},ba=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>B(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},xa=(e,t,n,r)=>{let i=e._zod.def,a=B(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=B(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1;n.allOf=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]]},Sa=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=o._zod.bag?.patterns;if(a.mode===`loose`&&s&&s.size>0){let e=B(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)i.patternProperties[t.source]=e}else (t.target===`draft-07`||t.target===`draft-2020-12`)&&(i.propertyNames=B(a.keyType,t,{...r,path:[...r.path,`propertyNames`]})),i.additionalProperties=B(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]});let c=o._zod.values;if(c){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e)}},Ca=(e,t,n,r)=>{let i=e._zod.def,a=B(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},wa=(e,t,n,r)=>{let i=e._zod.def;B(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Ta=(e,t,n,r)=>{let i=e._zod.def;B(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))},Ea=(e,t,n,r)=>{let i=e._zod.def;B(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,t.io===`input`&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},Da=(e,t,n,r)=>{let i=e._zod.def;B(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw Error(`Dynamic catch values are not supported in JSON Schema`)}n.default=o},Oa=(e,t,n,r)=>{let i=e._zod.def,a=t.io===`input`?i.in._zod.def.type===`transform`?i.out:i.in:i.out;B(a,t,r);let o=t.seen.get(e);o.ref=a},ka=(e,t,n,r)=>{let i=e._zod.def;B(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},Aa=(e,t,n,r)=>{let i=e._zod.def;B(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},ja=E(`ZodISODateTime`,(e,t)=>{rr.init(e,t),G.init(e,t)});function Ma(e){return Di(ja,e)}const Na=E(`ZodISODate`,(e,t)=>{ir.init(e,t),G.init(e,t)});function Pa(e){return Oi(Na,e)}const Fa=E(`ZodISOTime`,(e,t)=>{ar.init(e,t),G.init(e,t)});function Ia(e){return ki(Fa,e)}const La=E(`ZodISODuration`,(e,t)=>{or.init(e,t),G.init(e,t)});function Ra(e){return Ai(La,e)}const za=(e,t)=>{Nt.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>It(e,t)},flatten:{value:t=>Ft(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,it,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,it,2)}},isEmpty:{get(){return e.issues.length===0}}})};E(`ZodError`,za);const H=E(`ZodError`,za,{Parent:Error}),Ba=Lt(H),Va=Rt(H),Ha=zt(H),Ua=Vt(H),Wa=Ut(H),Ga=Wt(H),Ka=Gt(H),qa=Kt(H),Ja=qt(H),Ya=Jt(H),Xa=Yt(H),Za=Xt(H),U=E(`ZodType`,(e,t)=>(L.init(e,t),Object.assign(e[`~standard`],{jsonSchema:{input:la(e,`input`),output:la(e,`output`)}}),e.toJSONSchema=ca(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,`_def`,{value:t}),e.check=(...n)=>e.clone(j(t,{checks:[...t.checks??[],...n.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0}),e.with=e.check,e.clone=(t,n)=>N(e,t,n),e.brand=()=>e,e.register=((t,n)=>(t.add(e,n),e)),e.parse=(t,n)=>Ba(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>Ha(e,t,n),e.parseAsync=async(t,n)=>Va(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>Ua(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>Wa(e,t,n),e.decode=(t,n)=>Ga(e,t,n),e.encodeAsync=async(t,n)=>Ka(e,t,n),e.decodeAsync=async(t,n)=>qa(e,t,n),e.safeEncode=(t,n)=>Ja(e,t,n),e.safeDecode=(t,n)=>Ya(e,t,n),e.safeEncodeAsync=async(t,n)=>Xa(e,t,n),e.safeDecodeAsync=async(t,n)=>Za(e,t,n),e.refine=(t,n)=>e.check(as(t,n)),e.superRefine=t=>e.check(os(t)),e.overwrite=t=>e.check(z(t)),e.optional=()=>Vo(e),e.exactOptional=()=>Uo(e),e.nullable=()=>Go(e),e.nullish=()=>Vo(Go(e)),e.nonoptional=t=>Zo(e,t),e.array=()=>q(e),e.or=t=>Mo([e,t]),e.and=t=>Po(e,t),e.transform=t=>ts(e,zo(t)),e.default=t=>qo(e,t),e.prefault=t=>Yo(e,t),e.catch=t=>$o(e,t),e.pipe=t=>ts(e,t),e.readonly=()=>rs(e),e.describe=t=>{let n=e.clone();return ri.add(n,{description:t}),n},Object.defineProperty(e,`description`,{get(){return ri.get(e)?.description},configurable:!0}),e.meta=(...t)=>{if(t.length===0)return ri.get(e);let n=e.clone();return ri.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=t=>t(e),e)),Qa=E(`_ZodString`,(e,t)=>{Gn.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>da(e,t,n,r);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(Wi(...t)),e.includes=(...t)=>e.check(qi(...t)),e.startsWith=(...t)=>e.check(Ji(...t)),e.endsWith=(...t)=>e.check(Yi(...t)),e.min=(...t)=>e.check(Hi(...t)),e.max=(...t)=>e.check(Vi(...t)),e.length=(...t)=>e.check(Ui(...t)),e.nonempty=(...t)=>e.check(Hi(1,...t)),e.lowercase=t=>e.check(Gi(t)),e.uppercase=t=>e.check(Ki(t)),e.trim=()=>e.check(Zi()),e.normalize=(...t)=>e.check(Xi(...t)),e.toLowerCase=()=>e.check(Qi()),e.toUpperCase=()=>e.check($i()),e.slugify=()=>e.check(ea())}),$a=E(`ZodString`,(e,t)=>{Gn.init(e,t),Qa.init(e,t),e.email=t=>e.check(ai(eo,t)),e.url=t=>e.check(di(ro,t)),e.jwt=t=>e.check(Ei(yo,t)),e.emoji=t=>e.check(fi(io,t)),e.guid=t=>e.check(oi(to,t)),e.uuid=t=>e.check(si(no,t)),e.uuidv4=t=>e.check(ci(no,t)),e.uuidv6=t=>e.check(li(no,t)),e.uuidv7=t=>e.check(ui(no,t)),e.nanoid=t=>e.check(pi(ao,t)),e.guid=t=>e.check(oi(to,t)),e.cuid=t=>e.check(mi(oo,t)),e.cuid2=t=>e.check(hi(so,t)),e.ulid=t=>e.check(gi(co,t)),e.base64=t=>e.check(Ci(go,t)),e.base64url=t=>e.check(wi(_o,t)),e.xid=t=>e.check(_i(lo,t)),e.ksuid=t=>e.check(vi(uo,t)),e.ipv4=t=>e.check(yi(fo,t)),e.ipv6=t=>e.check(bi(po,t)),e.cidrv4=t=>e.check(xi(mo,t)),e.cidrv6=t=>e.check(Si(ho,t)),e.e164=t=>e.check(Ti(vo,t)),e.datetime=t=>e.check(Ma(t)),e.date=t=>e.check(Pa(t)),e.time=t=>e.check(Ia(t)),e.duration=t=>e.check(Ra(t))});function W(e){return ii($a,e)}const G=E(`ZodStringFormat`,(e,t)=>{R.init(e,t),Qa.init(e,t)}),eo=E(`ZodEmail`,(e,t)=>{Jn.init(e,t),G.init(e,t)}),to=E(`ZodGUID`,(e,t)=>{Kn.init(e,t),G.init(e,t)}),no=E(`ZodUUID`,(e,t)=>{qn.init(e,t),G.init(e,t)}),ro=E(`ZodURL`,(e,t)=>{Yn.init(e,t),G.init(e,t)}),io=E(`ZodEmoji`,(e,t)=>{Xn.init(e,t),G.init(e,t)}),ao=E(`ZodNanoID`,(e,t)=>{Zn.init(e,t),G.init(e,t)}),oo=E(`ZodCUID`,(e,t)=>{Qn.init(e,t),G.init(e,t)}),so=E(`ZodCUID2`,(e,t)=>{$n.init(e,t),G.init(e,t)}),co=E(`ZodULID`,(e,t)=>{er.init(e,t),G.init(e,t)}),lo=E(`ZodXID`,(e,t)=>{tr.init(e,t),G.init(e,t)}),uo=E(`ZodKSUID`,(e,t)=>{nr.init(e,t),G.init(e,t)}),fo=E(`ZodIPv4`,(e,t)=>{sr.init(e,t),G.init(e,t)}),po=E(`ZodIPv6`,(e,t)=>{cr.init(e,t),G.init(e,t)}),mo=E(`ZodCIDRv4`,(e,t)=>{lr.init(e,t),G.init(e,t)}),ho=E(`ZodCIDRv6`,(e,t)=>{ur.init(e,t),G.init(e,t)}),go=E(`ZodBase64`,(e,t)=>{fr.init(e,t),G.init(e,t)}),_o=E(`ZodBase64URL`,(e,t)=>{mr.init(e,t),G.init(e,t)}),vo=E(`ZodE164`,(e,t)=>{hr.init(e,t),G.init(e,t)}),yo=E(`ZodJWT`,(e,t)=>{_r.init(e,t),G.init(e,t)}),bo=E(`ZodNumber`,(e,t)=>{vr.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>fa(e,t,n,r),e.gt=(t,n)=>e.check(Ri(t,n)),e.gte=(t,n)=>e.check(zi(t,n)),e.min=(t,n)=>e.check(zi(t,n)),e.lt=(t,n)=>e.check(Ii(t,n)),e.lte=(t,n)=>e.check(Li(t,n)),e.max=(t,n)=>e.check(Li(t,n)),e.int=t=>e.check(Co(t)),e.safe=t=>e.check(Co(t)),e.positive=t=>e.check(Ri(0,t)),e.nonnegative=t=>e.check(zi(0,t)),e.negative=t=>e.check(Ii(0,t)),e.nonpositive=t=>e.check(Li(0,t)),e.multipleOf=(t,n)=>e.check(Bi(t,n)),e.step=(t,n)=>e.check(Bi(t,n)),e.finite=()=>e;let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function xo(e){return ji(bo,e)}const So=E(`ZodNumberFormat`,(e,t)=>{yr.init(e,t),bo.init(e,t)});function Co(e){return Mi(So,e)}const wo=E(`ZodBoolean`,(e,t)=>{br.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>pa(e,t,n,r)});function K(e){return Ni(wo,e)}const To=E(`ZodUnknown`,(e,t)=>{xr.init(e,t),U.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function Eo(){return Pi(To)}const Do=E(`ZodNever`,(e,t)=>{Sr.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ma(e,t,n,r)});function Oo(e){return Fi(Do,e)}const ko=E(`ZodArray`,(e,t)=>{wr.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>va(e,t,n,r),e.element=t.element,e.min=(t,n)=>e.check(Hi(t,n)),e.nonempty=t=>e.check(Hi(1,t)),e.max=(t,n)=>e.check(Vi(t,n)),e.length=(t,n)=>e.check(Ui(t,n)),e.unwrap=()=>e.element});function q(e,t){return ta(ko,e,t)}const Ao=E(`ZodObject`,(e,t)=>{kr.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ya(e,t,n,r),k(e,`shape`,()=>t.shape),e.keyof=()=>X(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Eo()}),e.loose=()=>e.clone({...e._zod.def,catchall:Eo()}),e.strict=()=>e.clone({...e._zod.def,catchall:Oo()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>St(e,t),e.safeExtend=t=>Ct(e,t),e.merge=t=>wt(e,t),e.pick=t=>bt(e,t),e.omit=t=>xt(e,t),e.partial=(...t)=>Tt(Bo,e,t[0]),e.required=(...t)=>Et(Xo,e,t[0])});function J(e,t){return new Ao({type:`object`,shape:e??{},...P(t)})}function Y(e,t){return new Ao({type:`object`,shape:e,catchall:Eo(),...P(t)})}const jo=E(`ZodUnion`,(e,t)=>{jr.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ba(e,t,n,r),e.options=t.options});function Mo(e,t){return new jo({type:`union`,options:e,...P(t)})}const No=E(`ZodIntersection`,(e,t)=>{Mr.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>xa(e,t,n,r)});function Po(e,t){return new No({type:`intersection`,left:e,right:t})}const Fo=E(`ZodRecord`,(e,t)=>{Fr.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Sa(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function Io(e,t,n){return new Fo({type:`record`,keyType:e,valueType:t,...P(n)})}const Lo=E(`ZodEnum`,(e,t)=>{Ir.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ha(e,t,n,r),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new Lo({...t,checks:[],...P(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new Lo({...t,checks:[],...P(r),entries:i})}});function X(e,t){return new Lo({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...P(t)})}const Ro=E(`ZodTransform`,(e,t)=>{Lr.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>_a(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new tt(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(jt(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,n.issues.push(jt(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function zo(e){return new Ro({type:`transform`,transform:e})}const Bo=E(`ZodOptional`,(e,t)=>{zr.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Aa(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Vo(e){return new Bo({type:`optional`,innerType:e})}const Ho=E(`ZodExactOptional`,(e,t)=>{Br.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Aa(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Uo(e){return new Ho({type:`optional`,innerType:e})}const Wo=E(`ZodNullable`,(e,t)=>{Vr.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ca(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Go(e){return new Wo({type:`nullable`,innerType:e})}const Ko=E(`ZodDefault`,(e,t)=>{Hr.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ta(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function qo(e,t){return new Ko({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():ht(t)}})}const Jo=E(`ZodPrefault`,(e,t)=>{Wr.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ea(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Yo(e,t){return new Jo({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():ht(t)}})}const Xo=E(`ZodNonOptional`,(e,t)=>{Gr.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>wa(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Zo(e,t){return new Xo({type:`nonoptional`,innerType:e,...P(t)})}const Qo=E(`ZodCatch`,(e,t)=>{qr.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Da(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function $o(e,t){return new Qo({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}const es=E(`ZodPipe`,(e,t)=>{Jr.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Oa(e,t,n,r),e.in=t.in,e.out=t.out});function ts(e,t){return new es({type:`pipe`,in:e,out:t})}const ns=E(`ZodReadonly`,(e,t)=>{Xr.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ka(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function rs(e){return new ns({type:`readonly`,innerType:e})}const is=E(`ZodCustom`,(e,t)=>{Qr.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ga(e,t,n,r)});function as(e,t={}){return na(is,e,t)}function os(e){return ra(e)}const ss=J({detail:W()}),cs=J({error:W()});function ls(e){if(!e)return`Unknown error`;if(e instanceof Error){let t=ss.safeParse(e.cause);return t.success?t.data.detail:us(e.message)}if(typeof e==`object`){let t=ss.safeParse(e);if(t.success)return t.data.detail;let n=cs.safeParse(e);if(n.success)return n.data.error}try{return JSON.stringify(e)}catch{return String(e)}}function us(e){let t=ds(e);if(!t)return e;let n=ss.safeParse(t);if(n.success)return n.data.detail;let r=cs.safeParse(t);return r.success?r.data.error:e}function ds(e){try{return JSON.parse(e)}catch{return e}}function fs(e,t){if(!e)throw Error(t)}const ps=[`pip`,`uv`,`rye`,`poetry`,`pixi`],ms=[`normal`,`compact`,`medium`,`full`,`columns`],hs=[`auto`,`native`,`polars`,`lazy-polars`,`pandas`],gs=[`html`,`markdown`,`ipynb`],_s=[`manual`,`ask`,`agent`],Z=J({api_key:W().optional(),base_url:W().optional(),project:W().optional()}).loose(),vs=J({chat_model:W().nullish(),edit_model:W().nullish(),autocomplete_model:W().nullish(),displayed_models:q(W()).default([]),custom_models:q(W()).default([])}),ys=Y({completion:J({activate_on_typing:K().prefault(!0),signature_hint_on_typing:K().prefault(!1),copilot:Mo([K(),X([`github`,`codeium`,`custom`])]).prefault(!1).transform(e=>e===!0?`github`:e),codeium_api_key:W().nullish()}).prefault({}),save:Y({autosave:X([`off`,`after_delay`]).prefault(`after_delay`),autosave_delay:xo().nonnegative().transform(e=>Math.max(e,1e3)).prefault(1e3),format_on_save:K().prefault(!1)}).prefault({}),formatting:Y({line_length:xo().nonnegative().prefault(79).transform(e=>Math.min(e,1e3))}).prefault({}),keymap:Y({preset:X([`default`,`vim`]).prefault(`default`),overrides:Io(W(),W()).prefault({}),destructive_delete:K().prefault(!0)}).prefault({}),runtime:Y({auto_instantiate:K().prefault(!0),on_cell_change:X([`lazy`,`autorun`]).prefault(`autorun`),auto_reload:X([`off`,`lazy`,`autorun`]).prefault(`off`),reactive_tests:K().prefault(!0),watcher_on_save:X([`lazy`,`autorun`]).prefault(`lazy`),default_sql_output:X(hs).prefault(`auto`),default_auto_download:q(X(gs)).prefault([])}).prefault({}),display:Y({theme:X([`light`,`dark`,`system`]).prefault(`light`),code_editor_font_size:xo().nonnegative().prefault(14),cell_output:X([`above`,`below`]).prefault(`below`),dataframes:X([`rich`,`plain`]).prefault(`rich`),default_table_page_size:xo().prefault(10),default_table_max_columns:xo().prefault(50),default_width:X(ms).prefault(`medium`).transform(e=>e===`normal`?`compact`:e),locale:W().nullable().optional(),reference_highlighting:K().prefault(!0)}).prefault({}),package_management:Y({manager:X(ps).prefault(`pip`)}).prefault({}),ai:Y({rules:W().prefault(``),mode:X(_s).prefault(`manual`),inline_tooltip:K().prefault(!1),open_ai:Z.optional(),anthropic:Z.optional(),google:Z.optional(),ollama:Z.optional(),openrouter:Z.optional(),wandb:Z.optional(),open_ai_compatible:Z.optional(),azure:Z.optional(),bedrock:Y({region_name:W().optional(),profile_name:W().optional(),aws_access_key_id:W().optional(),aws_secret_access_key:W().optional()}).optional(),custom_providers:Io(W(),Z).prefault({}),models:vs.prefault({displayed_models:[],custom_models:[]})}).prefault({}),experimental:Y({markdown:K().optional(),rtc:K().optional()}).prefault(()=>({})),server:Y({disable_file_downloads:K().optional()}).prefault(()=>({})),diagnostics:Y({enabled:K().optional(),sql_linter:K().optional()}).prefault(()=>({})),sharing:Y({html:K().optional(),wasm:K().optional()}).optional(),mcp:Y({presets:q(X([`marimo`,`context7`])).optional()}).optional().prefault({})}).partial().prefault(()=>({completion:{},save:{},formatting:{},keymap:{},runtime:{},display:{},diagnostics:{},experimental:{},server:{},ai:{},package_management:{},mcp:{}})),bs=W(),xs=X(hs).prefault(`auto`);J({width:X(ms).prefault(`medium`).transform(e=>e===`normal`?`compact`:e),app_title:bs.nullish(),css_file:W().nullish(),html_head_file:W().nullish(),auto_download:q(X(gs)).prefault([]),sql_output:xs}).prefault(()=>({width:`medium`,auto_download:[],sql_output:`auto`}));function Ss(){return ys.parse({completion:{},save:{},formatting:{},keymap:{},runtime:{},display:{},diagnostics:{},experimental:{},server:{},ai:{},package_management:{},mcp:{}})}const Cs=e=>new TextDecoder().decode(e);function ws(e){return e.FS}const Ts=`notebook.py`,Es=`/marimo`,Q={NOTEBOOK_FILENAME:Ts,HOME_DIR:Es,createHomeDir:e=>{let t=ws(e);try{t.mkdirTree(Es)}catch{}t.chdir(Es)},mountFS:e=>{ws(e).mount(e.FS.filesystems.IDBFS,{root:`.`},Es)},populateFilesToMemory:async e=>{await Ds(e,!0)},persistFilesToRemote:async e=>{await Ds(e,!1)},readNotebook:e=>{let t=ws(e),n=`${Es}/${Ts}`;return Cs(t.readFile(n))},initNotebookCode:e=>{let{pyodide:t,filename:n,code:r}=e,i=ws(t),a=e=>{try{return Cs(i.readFile(e))}catch{return null}};if(n&&n!==Ts){let e=a(n);if(e)return{code:e,filename:n}}return i.writeFile(Ts,r),{code:r,filename:Ts}}};function Ds(e,t){return new Promise((n,r)=>{ws(e).syncfs(t,e=>{if(e instanceof Error){r(e);return}n()})})}function Os(e){return`marimo-base`}const ks=new class{spans=[];startSpan(e,t={}){let n={name:e,startTime:Date.now(),attributes:t,end:(e=`ok`)=>this.endSpan(n,e)};return this.spans.push(n),n}endSpan(e,t=`ok`){e.endTime=Date.now(),e.status=t}getSpans(){return this.spans}wrap(e,t,n={}){let r=this.startSpan(t||e.name,n);try{let t=e();return this.endSpan(r),t}catch(e){throw this.endSpan(r,`error`),e}}wrapAsync(e,t,n={}){return(async(...r)=>{let i=this.startSpan(t||e.name,n);try{let t=await e(...r);return this.endSpan(i),t}catch(e){throw this.endSpan(i,`error`),e}})}logSpans(){}};globalThis.t=ks;var As=class{pyodide=null;get requirePyodide(){return fs(this.pyodide,`Pyodide not loaded`),this.pyodide}async bootstrap(e){return await this.loadPyodideAndPackages(e)}async loadPyodideAndPackages(e){if(!Ke)throw Error(`loadPyodide is not defined`);let t=ks.startSpan(`loadPyodide`);try{let n=await Ke({packages:[`micropip`,`msgspec`,Os(e.version),`Markdown`,`pymdown-extensions`,`narwhals`,`packaging`],_makeSnapshot:!1,lockFileURL:`https://wasm.marimo.app/pyodide-lock.json?v=${e.version}&pyodide=${e.pyodideVersion}`,indexURL:`https://cdn.jsdelivr.net/pyodide/${e.pyodideVersion}/full/`});return this.pyodide=n,t.end(`ok`),n}catch(e){throw T.error(`Failed to load Pyodide`,e),e}}async mountFilesystem(e){let t=ks.startSpan(`mountFilesystem`);return Q.createHomeDir(this.requirePyodide),Q.mountFS(this.requirePyodide),await Q.populateFilesToMemory(this.requirePyodide),t.end(`ok`),Q.initNotebookCode({pyodide:this.requirePyodide,code:e.code,filename:e.filename})}async startSession(e){let{code:t,filename:n,onMessage:r,queryParameters:i,userConfig:a}=e;self.messenger={callback:r},self.query_params=i,self.user_config=a;let o=ks.startSpan(`startSession.runPython`),s=n||Q.NOTEBOOK_FILENAME,[c,l,u]=this.requirePyodide.runPython(`
|
|
42
|
-
print("[py] Starting marimo...")
|
|
43
|
-
import asyncio
|
|
44
|
-
import js
|
|
45
|
-
from marimo._pyodide.bootstrap import create_session, instantiate
|
|
46
|
-
|
|
47
|
-
assert js.messenger, "messenger is not defined"
|
|
48
|
-
assert js.query_params, "query_params is not defined"
|
|
49
|
-
|
|
50
|
-
session, bridge = create_session(
|
|
51
|
-
filename="${s}",
|
|
52
|
-
query_params=js.query_params.to_py(),
|
|
53
|
-
message_callback=js.messenger.callback,
|
|
54
|
-
user_config=js.user_config.to_py(),
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
def init(auto_instantiate=True):
|
|
58
|
-
instantiate(session, auto_instantiate)
|
|
59
|
-
asyncio.create_task(session.start())
|
|
60
|
-
|
|
61
|
-
# Find the packages to install
|
|
62
|
-
with open("${s}", "r") as f:
|
|
63
|
-
packages = session.find_packages(f.read())
|
|
64
|
-
|
|
65
|
-
bridge, init, packages`);o.end();let d=new Set(u.toJs());return this.loadNotebookDeps(t,d).then(()=>l(a.runtime.auto_instantiate)),c}async loadNotebookDeps(e,t){let n=this.requirePyodide;e.includes(`mo.sql`)&&(e=`import pandas\n${e}`,e=`import duckdb\n${e}`,e=`import sqlglot\n${e}`,e.includes(`polars`)&&(e=`import pyarrow\n${e}`)),e=`import docutils\n${e}`,e=`import pygments\n${e}`,e=`import jedi\n${e}`,e=`import pyodide_http\n${e}`;let r=[...t],i=ks.startSpan(`pyodide.loadPackage`);await n.loadPackagesFromImports(e,{errorCallback:T.error,messageCallback:T.log}),i.end(),i=ks.startSpan(`micropip.install`);let a=r.filter(e=>!n.loadedPackages[e]);a.length>0&&await n.runPythonAsync(`
|
|
66
|
-
import micropip
|
|
67
|
-
import sys
|
|
68
|
-
# Filter out builtins
|
|
69
|
-
missing = [p for p in ${JSON.stringify(a)} if p not in sys.modules]
|
|
70
|
-
if len(missing) > 0:
|
|
71
|
-
print("Loading from micropip:", missing)
|
|
72
|
-
await micropip.install(missing)
|
|
73
|
-
`).catch(e=>{T.error(`Failed to load packages from micropip`,e)}),i.end()}},js=class extends As{async bootstrap(e){return await super.bootstrap(e)}async mountFilesystem(e){let{code:t,filename:n}=e;try{return Q.createHomeDir(this.requirePyodide),Q.initNotebookCode({pyodide:this.requirePyodide,code:t,filename:n})}catch(e){T.error(e)}return{code:t,filename:n}}async startSession(e){return super.startSession({queryParameters:{},code:e.code,filename:e.filename,onMessage:e.onMessage,userConfig:Ss()})}};async function Ms(){let e=Ls(),t=qe(e);try{self.controller=new js,self.pyodide=await self.controller.bootstrap({version:e,pyodideVersion:t})}catch(e){T.error(`Error bootstrapping`,e),$.send.initializedError({error:ls(e)})}}const Ns=Ms(),Ps=new Je(e=>{$.send.kernelMessage({message:e})}),Fs=new et,Is=d({startSession:async e=>{await Ns;try{fs(self.controller,`Controller not loaded`);let t=await self.controller.mountFilesystem({code:e.code,filename:`app-${e.appId}.py`}),n=await self.controller.startSession({...t,onMessage:Ps.push});Fs.resolve(n),$.send.initialized({})}catch(e){$.send.initializedError({error:ls(e)})}},loadPackages:async e=>{await Ns,e.includes(`mo.sql`)&&(e=`import pandas\n${e}`,e=`import duckdb\n${e}`,e=`import sqlglot\n${e}`,e.includes(`polars`)&&(e=`import pyarrow\n${e}`)),await self.pyodide.loadPackagesFromImports(e,{messageCallback:T.log,errorCallback:T.error})},bridge:async e=>{await Ns;let{functionName:t,payload:n}=e,r=await Fs.promise,i=n==null?null:typeof n==`string`?n:JSON.stringify(n),a=i==null?await r[t]():await r[t](i);return typeof a==`string`?JSON.parse(a):a}}),$=ee({transport:m({transportId:`marimo-transport`}),requestHandler:Is});$.send(`ready`,{}),$.addMessageListener(`consumerReady`,async()=>{await Ns,Ps.start()});function Ls(){return self.name}export{o as t};
|