@dxos/plugin-script 0.6.11 → 0.6.12-main.5cc132e

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.
@@ -0,0 +1,513 @@
1
+ import {
2
+ getUserFunctionUrlInMetadata,
3
+ publicKeyToDid,
4
+ setUserFunctionUrlInMetadata,
5
+ uploadWorkerFunction
6
+ } from "./chunk-DL5XQRQM.mjs";
7
+ import {
8
+ Bundler
9
+ } from "./chunk-RHEZ5LUU.mjs";
10
+ import {
11
+ FunctionType
12
+ } from "./chunk-O4LWBX6A.mjs";
13
+ import {
14
+ SCRIPT_PLUGIN
15
+ } from "./chunk-JBACGDOJ.mjs";
16
+ import {
17
+ TypescriptEditor
18
+ } from "./chunk-MRGOT5RF.mjs";
19
+
20
+ // packages/plugins/experimental/plugin-script/src/components/ScriptEditor.tsx
21
+ import { format } from "prettier";
22
+ import prettierPluginEstree from "prettier/plugins/estree";
23
+ import prettierPluginTypescript from "prettier/plugins/typescript";
24
+ import React3, { useCallback, useMemo, useState as useState3 } from "react";
25
+ import { log as log2 } from "@dxos/log";
26
+ import { useClient } from "@dxos/react-client";
27
+ import { create, createDocAccessor, Filter, fullyQualifiedId, getMeta, getSpace, useQuery } from "@dxos/react-client/echo";
28
+ import { useIdentity } from "@dxos/react-client/halo";
29
+ import { useTranslation as useTranslation3 } from "@dxos/react-ui";
30
+ import { useHasAttention } from "@dxos/react-ui-attention";
31
+ import { createDataExtensions, listener } from "@dxos/react-ui-editor";
32
+ import { mx as mx2 } from "@dxos/react-ui-theme";
33
+
34
+ // packages/plugins/experimental/plugin-script/src/components/DebugPanel.tsx
35
+ import React, { useEffect, useRef, useState } from "react";
36
+ import { log } from "@dxos/log";
37
+ import { Avatar, DensityProvider, Icon, Input, Toolbar, useControlledValue, useTranslation } from "@dxos/react-ui";
38
+ import { SyntaxHighlighter } from "@dxos/react-ui-syntax-highlighter";
39
+ import { mx } from "@dxos/react-ui-theme";
40
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-script/src/components/DebugPanel.tsx";
41
+ var DebugPanel = ({ classNames, functionUrl, binding: _binding, onBindingChange }) => {
42
+ const { t } = useTranslation(SCRIPT_PLUGIN);
43
+ const bindingInputRef = useRef(null);
44
+ const [binding, setBinding] = useControlledValue(_binding ?? "");
45
+ const handleBlur = () => {
46
+ onBindingChange?.(binding);
47
+ };
48
+ const inputRef = useRef(null);
49
+ const [input, setInput] = useState("");
50
+ const [result, setResult] = useState("");
51
+ const [state, setState] = useState(null);
52
+ const [history, setHistory] = useState([]);
53
+ const scrollerRef = useRef(null);
54
+ const handleScroll = () => {
55
+ if (scrollerRef.current) {
56
+ scrollerRef.current.scrollTop = scrollerRef.current.scrollHeight;
57
+ }
58
+ };
59
+ const controller = useRef();
60
+ useEffect(() => {
61
+ return () => {
62
+ handleStop();
63
+ };
64
+ }, []);
65
+ const handleStop = () => {
66
+ controller.current?.abort("stop");
67
+ controller.current = void 0;
68
+ };
69
+ const handleClear = () => {
70
+ handleStop();
71
+ setInput("");
72
+ setResult("");
73
+ setHistory([]);
74
+ inputRef.current?.focus();
75
+ };
76
+ const handleResponse = ({ text, data, error } = {}) => {
77
+ controller.current = void 0;
78
+ setHistory((history2) => [
79
+ ...history2,
80
+ {
81
+ type: "response",
82
+ text,
83
+ data,
84
+ error
85
+ }
86
+ ]);
87
+ setResult("");
88
+ setState(null);
89
+ handleScroll();
90
+ };
91
+ const handleRequest = async (input2) => {
92
+ try {
93
+ setState("pending");
94
+ let data = null;
95
+ if (input2.charAt(0) === "{") {
96
+ try {
97
+ const validJsonString = input2.replace(/'/g, '"').replace(/([{,]\s*)([a-zA-Z0-9_]+)(\s*:)/g, '$1"$2"$3');
98
+ data = JSON.parse(validJsonString);
99
+ input2 = JSON.stringify(data, null, 2);
100
+ } catch (err) {
101
+ inputRef.current?.focus();
102
+ return;
103
+ }
104
+ }
105
+ setInput("");
106
+ setResult("");
107
+ setHistory((history2) => [
108
+ ...history2,
109
+ {
110
+ type: "request",
111
+ text: input2
112
+ }
113
+ ]);
114
+ setTimeout(() => {
115
+ handleScroll();
116
+ });
117
+ controller.current = new AbortController();
118
+ const response = await fetch(functionUrl, {
119
+ signal: controller.current.signal,
120
+ method: "POST",
121
+ body: input2,
122
+ headers: {
123
+ "Content-Type": data ? "application/json" : "text/plain"
124
+ }
125
+ });
126
+ if (!response.ok) {
127
+ const text2 = await response.text();
128
+ handleResponse({
129
+ error: new Error(text2 || response.statusText || String(response.status))
130
+ });
131
+ return;
132
+ }
133
+ const contentType = response.headers.get("content-type");
134
+ if (contentType === "application/json") {
135
+ const data2 = await response.json();
136
+ handleResponse({
137
+ data: data2
138
+ });
139
+ return;
140
+ }
141
+ setState("responding");
142
+ let text = "";
143
+ const reader = response.body.getReader();
144
+ const pump = async ({ done, value }) => {
145
+ text = text + new TextDecoder().decode(value);
146
+ if (!controller.current || done) {
147
+ handleResponse({
148
+ text
149
+ });
150
+ return;
151
+ }
152
+ setResult(text);
153
+ setTimeout(() => {
154
+ handleScroll();
155
+ });
156
+ return reader.read().then(pump);
157
+ };
158
+ void reader.read().then(pump).catch((err) => {
159
+ if (err.name !== "AbortError") {
160
+ log.catch(err, void 0, {
161
+ F: __dxlog_file,
162
+ L: 163,
163
+ S: void 0,
164
+ C: (f, a) => f(...a)
165
+ });
166
+ }
167
+ });
168
+ } catch (err) {
169
+ if (err !== "stop") {
170
+ const error = err instanceof Error ? err : new Error(err);
171
+ handleResponse({
172
+ error
173
+ });
174
+ log.catch(err, void 0, {
175
+ F: __dxlog_file,
176
+ L: 170,
177
+ S: void 0,
178
+ C: (f, a) => f(...a)
179
+ });
180
+ } else {
181
+ handleResponse();
182
+ }
183
+ }
184
+ };
185
+ return /* @__PURE__ */ React.createElement(DensityProvider, {
186
+ density: "fine"
187
+ }, /* @__PURE__ */ React.createElement("div", {
188
+ className: mx("flex flex-col h-full overflow-hidden", classNames)
189
+ }, /* @__PURE__ */ React.createElement("div", {
190
+ ref: scrollerRef,
191
+ className: "flex flex-col gap-6 h-full p-4 overflow-x-hidden overflow-y-auto"
192
+ }, /* @__PURE__ */ React.createElement(MessageThread, {
193
+ state,
194
+ result,
195
+ history
196
+ })), /* @__PURE__ */ React.createElement(Toolbar.Root, {
197
+ classNames: "p-2"
198
+ }, /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement(Input.TextInput, {
199
+ ref: inputRef,
200
+ autoFocus: true,
201
+ placeholder: t("function request placeholder"),
202
+ value: input,
203
+ onChange: (ev) => setInput(ev.target.value),
204
+ onKeyDown: (ev) => ev.key === "Enter" && handleRequest(input)
205
+ })), /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement(Input.TextInput, {
206
+ ref: bindingInputRef,
207
+ classNames: "!w-[10rem]",
208
+ placeholder: t("binding placeholder"),
209
+ value: binding,
210
+ onChange: (ev) => setBinding(ev.target.value.toUpperCase()),
211
+ onBlur: handleBlur
212
+ })), /* @__PURE__ */ React.createElement(Toolbar.Button, {
213
+ onClick: () => handleRequest(input)
214
+ }, /* @__PURE__ */ React.createElement(Icon, {
215
+ icon: "ph--play--regular",
216
+ size: 4
217
+ })), /* @__PURE__ */ React.createElement(Toolbar.Button, {
218
+ onClick: () => state ? handleStop() : handleClear()
219
+ }, /* @__PURE__ */ React.createElement(Icon, {
220
+ icon: state ? "ph--stop--regular" : "ph--trash--regular",
221
+ size: 4
222
+ })))));
223
+ };
224
+ var RobotAvatar = () => /* @__PURE__ */ React.createElement(Avatar.Root, {
225
+ size: 6,
226
+ variant: "circle"
227
+ }, /* @__PURE__ */ React.createElement(Avatar.Frame, null, /* @__PURE__ */ React.createElement(Avatar.Icon, {
228
+ icon: "ph--robot--regular"
229
+ })));
230
+ var MessageItem = ({ classNames, message }) => {
231
+ const { text, data, error } = message;
232
+ if (error) {
233
+ return /* @__PURE__ */ React.createElement("span", {
234
+ className: mx(classNames, "whitespace-pre text-error")
235
+ }, String(error));
236
+ } else if (data) {
237
+ return /* @__PURE__ */ React.createElement(SyntaxHighlighter, {
238
+ language: "json",
239
+ className: mx("text-xs", classNames)
240
+ }, JSON.stringify(data, null, 2));
241
+ }
242
+ return /* @__PURE__ */ React.createElement("span", {
243
+ className: mx(classNames)
244
+ }, text || "\xD8");
245
+ };
246
+ var MessageThread = ({ state, result, history }) => {
247
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, history.map((message, i) => /* @__PURE__ */ React.createElement("div", {
248
+ key: i,
249
+ className: "grid grid-cols-[3rem_1fr]"
250
+ }, /* @__PURE__ */ React.createElement("div", null, message.type === "response" && /* @__PURE__ */ React.createElement(RobotAvatar, null)), /* @__PURE__ */ React.createElement("div", {
251
+ className: mx("flex", message.type === "request" && "justify-end")
252
+ }, /* @__PURE__ */ React.createElement(MessageItem, {
253
+ classNames: [
254
+ message.type === "request" && "p-1 px-2 rounded-lg bg-hoverSurface"
255
+ ],
256
+ message
257
+ })))), /* @__PURE__ */ React.createElement("div", {
258
+ className: "grid grid-cols-[3rem_1fr]"
259
+ }, /* @__PURE__ */ React.createElement("div", null, state === "pending" && /* @__PURE__ */ React.createElement(Icon, {
260
+ icon: "ph--spinner--regular",
261
+ size: 6,
262
+ classNames: "animate-spin-slow"
263
+ }) || result.length > 0 && /* @__PURE__ */ React.createElement(RobotAvatar, null)), /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("span", null, result))));
264
+ };
265
+
266
+ // packages/plugins/experimental/plugin-script/src/components/Toolbar.tsx
267
+ import React2, { useState as useState2 } from "react";
268
+ import { DensityProvider as DensityProvider2, ElevationProvider, Icon as Icon2, Toolbar as NaturalToolbar, Tooltip, useTranslation as useTranslation2 } from "@dxos/react-ui";
269
+ var Toolbar2 = ({ classNames, deployed, error, functionUrl, showPanel, onDeploy, onFormat, onTogglePanel }) => {
270
+ const { t } = useTranslation2(SCRIPT_PLUGIN);
271
+ const [pending, setPending] = useState2(false);
272
+ const handleCopyLink = async () => {
273
+ if (!functionUrl) {
274
+ return;
275
+ }
276
+ await navigator.clipboard.writeText(functionUrl);
277
+ };
278
+ const handleDeploy = async () => {
279
+ setPending(true);
280
+ await onDeploy?.();
281
+ setPending(false);
282
+ };
283
+ return /* @__PURE__ */ React2.createElement(DensityProvider2, {
284
+ density: "fine"
285
+ }, /* @__PURE__ */ React2.createElement(ElevationProvider, {
286
+ elevation: "chrome"
287
+ }, /* @__PURE__ */ React2.createElement(NaturalToolbar.Root, {
288
+ classNames: [
289
+ "p-1",
290
+ classNames
291
+ ],
292
+ style: {
293
+ contain: "layout"
294
+ }
295
+ }, onFormat && /* @__PURE__ */ React2.createElement(Tooltip.Root, null, /* @__PURE__ */ React2.createElement(Tooltip.Trigger, {
296
+ asChild: true
297
+ }, /* @__PURE__ */ React2.createElement(NaturalToolbar.Button, {
298
+ variant: "ghost",
299
+ onClick: onFormat
300
+ }, /* @__PURE__ */ React2.createElement(Icon2, {
301
+ icon: "ph--magic-wand--regular",
302
+ size: 4
303
+ }))), /* @__PURE__ */ React2.createElement(Tooltip.Portal, null, /* @__PURE__ */ React2.createElement(Tooltip.Content, null, /* @__PURE__ */ React2.createElement(Tooltip.Arrow, null), t("format label")))), /* @__PURE__ */ React2.createElement("div", {
304
+ role: "separator",
305
+ className: "grow"
306
+ }), error ? /* @__PURE__ */ React2.createElement(Tooltip.Root, null, /* @__PURE__ */ React2.createElement(Tooltip.Trigger, null, /* @__PURE__ */ React2.createElement(Icon2, {
307
+ icon: "ph--warning-circle--regular",
308
+ size: 4
309
+ })), /* @__PURE__ */ React2.createElement(Tooltip.Portal, null, /* @__PURE__ */ React2.createElement(Tooltip.Content, null, /* @__PURE__ */ React2.createElement(Tooltip.Arrow, null), error))) : null, functionUrl && deployed && /* @__PURE__ */ React2.createElement(Tooltip.Root, null, /* @__PURE__ */ React2.createElement(Tooltip.Trigger, {
310
+ asChild: true
311
+ }, /* @__PURE__ */ React2.createElement(NaturalToolbar.Button, {
312
+ variant: "ghost",
313
+ onClick: handleCopyLink
314
+ }, /* @__PURE__ */ React2.createElement(Icon2, {
315
+ icon: "ph--link--regular",
316
+ size: 4
317
+ }))), /* @__PURE__ */ React2.createElement(Tooltip.Portal, null, /* @__PURE__ */ React2.createElement(Tooltip.Content, null, /* @__PURE__ */ React2.createElement(Tooltip.Arrow, null), t("copy link label")))), /* @__PURE__ */ React2.createElement(Tooltip.Root, null, /* @__PURE__ */ React2.createElement(Tooltip.Trigger, {
318
+ asChild: true
319
+ }, /* @__PURE__ */ React2.createElement(NaturalToolbar.Button, {
320
+ variant: "ghost",
321
+ onClick: handleDeploy,
322
+ disabled: pending
323
+ }, pending ? /* @__PURE__ */ React2.createElement(Icon2, {
324
+ icon: "ph--spinner--regular",
325
+ size: 4,
326
+ classNames: "animate-spin-slow"
327
+ }) : /* @__PURE__ */ React2.createElement(Icon2, {
328
+ icon: "ph--cloud-arrow-up--regular",
329
+ size: 4
330
+ }))), /* @__PURE__ */ React2.createElement(Tooltip.Portal, null, /* @__PURE__ */ React2.createElement(Tooltip.Content, null, /* @__PURE__ */ React2.createElement(Tooltip.Arrow, null), pending ? t("pending label") : t("deploy label")))), onTogglePanel && /* @__PURE__ */ React2.createElement(Tooltip.Root, null, /* @__PURE__ */ React2.createElement(Tooltip.Trigger, {
331
+ asChild: true
332
+ }, /* @__PURE__ */ React2.createElement(NaturalToolbar.Button, {
333
+ variant: "ghost",
334
+ onClick: onTogglePanel
335
+ }, /* @__PURE__ */ React2.createElement(Icon2, {
336
+ icon: showPanel ? "ph--caret-down--regular" : "ph--caret-up--regular",
337
+ size: 4
338
+ }))), /* @__PURE__ */ React2.createElement(Tooltip.Portal, null, /* @__PURE__ */ React2.createElement(Tooltip.Content, null, /* @__PURE__ */ React2.createElement(Tooltip.Arrow, null), t("toggle details label")))))));
339
+ };
340
+
341
+ // packages/plugins/experimental/plugin-script/src/components/ScriptEditor.tsx
342
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-script/src/components/ScriptEditor.tsx";
343
+ var ScriptEditor = ({ env, script, role }) => {
344
+ const { t } = useTranslation3(SCRIPT_PLUGIN);
345
+ const hasAttention = useHasAttention(fullyQualifiedId(script));
346
+ const client = useClient();
347
+ const identity = useIdentity();
348
+ const space = getSpace(script);
349
+ const [fn] = useQuery(space, Filter.schema(FunctionType, (fn2) => fn2.source === script));
350
+ const extensions = useMemo(() => [
351
+ listener({
352
+ onChange: (text) => {
353
+ if (script.source && script.source?.content !== text) {
354
+ script.changed = true;
355
+ }
356
+ }
357
+ }),
358
+ createDataExtensions({
359
+ id: script.id,
360
+ text: script.source && createDocAccessor(script.source, [
361
+ "content"
362
+ ]),
363
+ space,
364
+ identity
365
+ })
366
+ ], [
367
+ script,
368
+ script.source,
369
+ space,
370
+ identity
371
+ ]);
372
+ const [showPanel, setShowPanel] = useState3(false);
373
+ const initialValue = useMemo(() => script.source?.content, [
374
+ script.source
375
+ ]);
376
+ const existingFunctionUrl = fn && getUserFunctionUrlInMetadata(getMeta(fn));
377
+ const [error, setError] = useState3();
378
+ const handleBindingChange = useCallback((binding) => {
379
+ fn.binding = binding;
380
+ }, [
381
+ fn
382
+ ]);
383
+ const handleFormat = useCallback(async () => {
384
+ if (!script.source) {
385
+ return;
386
+ }
387
+ try {
388
+ script.source.content = await format(script.source.content, {
389
+ parser: "typescript",
390
+ plugins: [
391
+ prettierPluginEstree,
392
+ prettierPluginTypescript
393
+ ],
394
+ semi: true,
395
+ singleQuote: true
396
+ });
397
+ } catch (err) {
398
+ log2.catch(err, void 0, {
399
+ F: __dxlog_file2,
400
+ L: 102,
401
+ S: void 0,
402
+ C: (f, a) => f(...a)
403
+ });
404
+ }
405
+ }, [
406
+ script.source
407
+ ]);
408
+ const handleDeploy = useCallback(async () => {
409
+ if (!script.source || !identity || !space) {
410
+ return;
411
+ }
412
+ setError(void 0);
413
+ try {
414
+ const existingFunctionId = existingFunctionUrl?.split("/").at(-1);
415
+ const ownerDid = existingFunctionUrl?.split("/").at(-2) ?? publicKeyToDid(identity.identityKey);
416
+ const bundler = new Bundler({
417
+ platform: "browser",
418
+ sandboxedModules: [],
419
+ remoteModules: {}
420
+ });
421
+ const buildResult = await bundler.bundle(script.source.content);
422
+ if (buildResult.error || !buildResult.bundle) {
423
+ throw buildResult.error;
424
+ }
425
+ const { result, functionId, functionVersionNumber, errorMessage } = await uploadWorkerFunction({
426
+ clientConfig: client.config,
427
+ halo: client.halo,
428
+ ownerDid,
429
+ functionId: existingFunctionId,
430
+ source: buildResult.bundle
431
+ });
432
+ if (result !== "success" || functionId === void 0 || functionVersionNumber === void 0) {
433
+ throw new Error(errorMessage);
434
+ }
435
+ log2.info("function uploaded", {
436
+ functionId,
437
+ functionVersionNumber
438
+ }, {
439
+ F: __dxlog_file2,
440
+ L: 137,
441
+ S: void 0,
442
+ C: (f, a) => f(...a)
443
+ });
444
+ if (fn) {
445
+ fn.version = functionVersionNumber;
446
+ }
447
+ const deployedFunction = fn ?? space.db.add(create(FunctionType, {
448
+ version: functionVersionNumber,
449
+ source: script
450
+ }));
451
+ const meta = getMeta(deployedFunction);
452
+ setUserFunctionUrlInMetadata(meta, `/${ownerDid}/${functionId}`);
453
+ script.changed = false;
454
+ } catch (err) {
455
+ log2.catch(err, void 0, {
456
+ F: __dxlog_file2,
457
+ L: 147,
458
+ S: void 0,
459
+ C: (f, a) => f(...a)
460
+ });
461
+ setError(t("upload failed label"));
462
+ }
463
+ }, [
464
+ fn,
465
+ existingFunctionUrl,
466
+ script,
467
+ script.name,
468
+ script.source
469
+ ]);
470
+ const functionUrl = useMemo(() => {
471
+ if (!existingFunctionUrl) {
472
+ return;
473
+ }
474
+ const baseUrl = new URL("functions/", client.config.values.runtime?.services?.edge?.url);
475
+ const relativeUrl = existingFunctionUrl.replace(/^\//, "");
476
+ const url = new URL(`./${relativeUrl}`, baseUrl.toString());
477
+ space && url.searchParams.set("spaceId", space.id);
478
+ url.protocol = "https";
479
+ return url.toString();
480
+ }, [
481
+ existingFunctionUrl,
482
+ space
483
+ ]);
484
+ return /* @__PURE__ */ React3.createElement("div", {
485
+ role: "none",
486
+ className: mx2("flex flex-col is-full bs-full overflow-hidden", role === "article" && "row-span-2", hasAttention && "attention-surface")
487
+ }, /* @__PURE__ */ React3.createElement(TypescriptEditor, {
488
+ id: script.id,
489
+ env,
490
+ initialValue,
491
+ extensions,
492
+ className: "flex is-full bs-full overflow-hidden ch-focus-ring-inset-over-all"
493
+ }), /* @__PURE__ */ React3.createElement(Toolbar2, {
494
+ classNames: "border-t border-separator",
495
+ deployed: Boolean(existingFunctionUrl) && !script.changed,
496
+ functionUrl,
497
+ error,
498
+ showPanel,
499
+ onDeploy: handleDeploy,
500
+ onFormat: handleFormat,
501
+ onTogglePanel: async () => setShowPanel((showDetails) => !showDetails)
502
+ }), showPanel && /* @__PURE__ */ React3.createElement(DebugPanel, {
503
+ functionUrl,
504
+ binding: fn?.binding,
505
+ onBindingChange: handleBindingChange
506
+ }));
507
+ };
508
+ var ScriptEditor_default = ScriptEditor;
509
+ export {
510
+ ScriptEditor,
511
+ ScriptEditor_default as default
512
+ };
513
+ //# sourceMappingURL=ScriptEditor-5Y3EROG3.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/ScriptEditor.tsx", "../../../src/components/DebugPanel.tsx", "../../../src/components/Toolbar.tsx"],
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type DID } from 'iso-did/types';\nimport { format } from 'prettier';\nimport prettierPluginEstree from 'prettier/plugins/estree';\nimport prettierPluginTypescript from 'prettier/plugins/typescript';\nimport React, { useCallback, useMemo, useState } from 'react';\n\nimport { log } from '@dxos/log';\nimport { useClient } from '@dxos/react-client';\nimport {\n create,\n createDocAccessor,\n Filter,\n fullyQualifiedId,\n getMeta,\n getSpace,\n useQuery,\n} from '@dxos/react-client/echo';\nimport { useIdentity } from '@dxos/react-client/halo';\nimport { useTranslation } from '@dxos/react-ui';\nimport { useHasAttention } from '@dxos/react-ui-attention';\nimport { createDataExtensions, listener } from '@dxos/react-ui-editor';\nimport { mx } from '@dxos/react-ui-theme';\n\nimport { DebugPanel } from './DebugPanel';\nimport { Toolbar } from './Toolbar';\nimport { TypescriptEditor, type TypescriptEditorProps } from './TypescriptEditor';\nimport { Bundler } from '../bundler';\nimport {\n getUserFunctionUrlInMetadata,\n publicKeyToDid,\n setUserFunctionUrlInMetadata,\n uploadWorkerFunction,\n} from '../edge';\nimport { SCRIPT_PLUGIN } from '../meta';\nimport { FunctionType, type ScriptType } from '../types';\n\nexport type ScriptEditorProps = {\n script: ScriptType;\n role?: string;\n} & Pick<TypescriptEditorProps, 'env'>;\n\nexport const ScriptEditor = ({ env, script, role }: ScriptEditorProps) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n const hasAttention = useHasAttention(fullyQualifiedId(script));\n const client = useClient();\n const identity = useIdentity();\n const space = getSpace(script);\n const [fn] = useQuery(\n space,\n Filter.schema(FunctionType, (fn) => fn.source === script),\n );\n\n const extensions = useMemo(\n () => [\n listener({\n onChange: (text) => {\n if (script.source && script.source?.content !== text) {\n script.changed = true;\n }\n },\n }),\n createDataExtensions({\n id: script.id,\n text: script.source && createDocAccessor(script.source, ['content']),\n space,\n identity,\n }),\n ],\n [script, script.source, space, identity],\n );\n\n const [showPanel, setShowPanel] = useState(false);\n const initialValue = useMemo(() => script.source?.content, [script.source]);\n const existingFunctionUrl = fn && getUserFunctionUrlInMetadata(getMeta(fn));\n const [error, setError] = useState<string>();\n\n const handleBindingChange = useCallback(\n (binding: string) => {\n fn.binding = binding;\n },\n [fn],\n );\n\n const handleFormat = useCallback(async () => {\n if (!script.source) {\n return;\n }\n\n try {\n script.source.content = await format(script.source.content, {\n parser: 'typescript',\n plugins: [prettierPluginEstree, prettierPluginTypescript],\n semi: true,\n singleQuote: true,\n });\n } catch (err: any) {\n // TODO(wittjosiah): Show error in UI.\n log.catch(err);\n }\n }, [script.source]);\n\n const handleDeploy = useCallback(async () => {\n if (!script.source || !identity || !space) {\n return;\n }\n\n setError(undefined);\n\n try {\n const existingFunctionId = existingFunctionUrl?.split('/').at(-1);\n const ownerDid = (existingFunctionUrl?.split('/').at(-2) as DID) ?? publicKeyToDid(identity.identityKey);\n\n const bundler = new Bundler({\n platform: 'browser',\n sandboxedModules: [],\n remoteModules: {},\n });\n const buildResult = await bundler.bundle(script.source.content);\n if (buildResult.error || !buildResult.bundle) {\n throw buildResult.error;\n }\n\n const { result, functionId, functionVersionNumber, errorMessage } = await uploadWorkerFunction({\n clientConfig: client.config,\n halo: client.halo,\n ownerDid,\n functionId: existingFunctionId,\n source: buildResult.bundle,\n });\n if (result !== 'success' || functionId === undefined || functionVersionNumber === undefined) {\n throw new Error(errorMessage);\n }\n log.info('function uploaded', { functionId, functionVersionNumber });\n if (fn) {\n fn.version = functionVersionNumber;\n }\n const deployedFunction =\n fn ?? space.db.add(create(FunctionType, { version: functionVersionNumber, source: script }));\n const meta = getMeta(deployedFunction);\n setUserFunctionUrlInMetadata(meta, `/${ownerDid}/${functionId}`);\n script.changed = false;\n } catch (err: any) {\n log.catch(err);\n setError(t('upload failed label'));\n }\n }, [fn, existingFunctionUrl, script, script.name, script.source]);\n\n const functionUrl = useMemo(() => {\n if (!existingFunctionUrl) {\n return;\n }\n\n const baseUrl = new URL('functions/', client.config.values.runtime?.services?.edge?.url);\n\n // Leading slashes cause the URL to be treated as an absolute path.\n const relativeUrl = existingFunctionUrl.replace(/^\\//, '');\n const url = new URL(`./${relativeUrl}`, baseUrl.toString());\n space && url.searchParams.set('spaceId', space.id);\n url.protocol = 'https';\n return url.toString();\n }, [existingFunctionUrl, space]);\n\n return (\n <div\n role='none'\n className={mx(\n 'flex flex-col is-full bs-full overflow-hidden',\n role === 'article' && 'row-span-2',\n hasAttention && 'attention-surface',\n )}\n >\n <TypescriptEditor\n id={script.id}\n env={env}\n initialValue={initialValue}\n extensions={extensions}\n className='flex is-full bs-full overflow-hidden ch-focus-ring-inset-over-all'\n />\n\n <Toolbar\n classNames='border-t border-separator'\n deployed={Boolean(existingFunctionUrl) && !script.changed}\n functionUrl={functionUrl}\n error={error}\n showPanel={showPanel}\n onDeploy={handleDeploy}\n onFormat={handleFormat}\n onTogglePanel={async () => setShowPanel((showDetails) => !showDetails)}\n />\n\n {showPanel && (\n <DebugPanel functionUrl={functionUrl} binding={fn?.binding} onBindingChange={handleBindingChange} />\n )}\n </div>\n );\n};\n\nexport default ScriptEditor;\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { useEffect, useRef, useState } from 'react';\n\nimport { log } from '@dxos/log';\nimport {\n Avatar,\n DensityProvider,\n Icon,\n Input,\n type ThemedClassName,\n Toolbar,\n useControlledValue,\n useTranslation,\n} from '@dxos/react-ui';\nimport { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';\nimport { mx } from '@dxos/react-ui-theme';\n\nimport { SCRIPT_PLUGIN } from '../meta';\n\ntype State = 'pending' | 'responding';\n\n/**\n * Request or response.\n */\ntype Message = { type: 'request' | 'response'; text?: string; data?: any; error?: Error };\n\nexport type DebugPanelProps = ThemedClassName<{\n functionUrl?: string;\n binding?: string;\n onBindingChange?: (binding: string) => void;\n}>;\n\nexport const DebugPanel = ({ classNames, functionUrl, binding: _binding, onBindingChange }: DebugPanelProps) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n\n const bindingInputRef = useRef<HTMLInputElement>(null);\n const [binding, setBinding] = useControlledValue(_binding ?? '');\n const handleBlur = () => {\n onBindingChange?.(binding);\n };\n\n const inputRef = useRef<HTMLInputElement>(null);\n const [input, setInput] = useState('');\n const [result, setResult] = useState('');\n const [state, setState] = useState<State | null>(null);\n\n // TODO(burdon): Persistent history (non-space ECHO data?)\n const [history, setHistory] = useState<Message[]>([]);\n\n const scrollerRef = useRef<HTMLDivElement>(null);\n const handleScroll = () => {\n if (scrollerRef.current) {\n scrollerRef.current.scrollTop = scrollerRef.current.scrollHeight;\n }\n };\n\n const controller = useRef<AbortController>();\n useEffect(() => {\n return () => {\n handleStop();\n };\n }, []);\n\n const handleStop = () => {\n controller.current?.abort('stop');\n controller.current = undefined;\n };\n\n const handleClear = () => {\n handleStop();\n setInput('');\n setResult('');\n setHistory([]);\n inputRef.current?.focus();\n };\n\n const handleResponse = ({ text, data, error }: { text?: string; data?: any; error?: Error } = {}) => {\n controller.current = undefined;\n setHistory((history) => [...history, { type: 'response', text, data, error } satisfies Message]);\n setResult('');\n setState(null);\n handleScroll();\n };\n\n const handleRequest = async (input: string) => {\n // Returns a promise that resolves when a value has been received.\n try {\n setState('pending');\n\n let data = null;\n // Detect JSON input.\n if (input.charAt(0) === '{') {\n try {\n const validJsonString = input.replace(/'/g, '\"').replace(/([{,]\\s*)([a-zA-Z0-9_]+)(\\s*:)/g, '$1\"$2\"$3');\n data = JSON.parse(validJsonString);\n input = JSON.stringify(data, null, 2);\n } catch (err) {\n inputRef.current?.focus();\n return;\n }\n }\n\n setInput('');\n setResult('');\n setHistory((history) => [...history, { type: 'request', text: input }]);\n setTimeout(() => {\n handleScroll();\n });\n\n // Throws DOMException when aborted.\n controller.current = new AbortController();\n const response = await fetch(functionUrl!, {\n signal: controller.current.signal,\n method: 'POST',\n body: input,\n headers: {\n 'Content-Type': data ? 'application/json' : 'text/plain',\n },\n });\n\n // Check for error.\n if (!response.ok) {\n const text = await response.text();\n handleResponse({ error: new Error(text || response.statusText || String(response.status)) });\n return;\n }\n\n // Check for JSON.\n const contentType = response.headers.get('content-type');\n if (contentType === 'application/json') {\n const data = await response.json();\n handleResponse({ data });\n return;\n }\n\n // Text (including streaming).\n setState('responding');\n let text = '';\n const reader = response.body!.getReader();\n const pump = async ({ done, value }: ReadableStreamReadResult<Uint8Array>): Promise<void> => {\n text = text + new TextDecoder().decode(value);\n if (!controller.current || done) {\n handleResponse({ text });\n return;\n }\n\n setResult(text);\n setTimeout(() => {\n handleScroll();\n });\n\n return reader.read().then(pump);\n };\n\n void reader\n .read()\n .then(pump)\n .catch((err) => {\n if (err.name !== 'AbortError') {\n log.catch(err);\n }\n });\n } catch (err: any) {\n if (err !== 'stop') {\n const error = err instanceof Error ? err : new Error(err);\n handleResponse({ error });\n log.catch(err);\n } else {\n handleResponse();\n }\n }\n };\n\n return (\n <DensityProvider density='fine'>\n <div className={mx('flex flex-col h-full overflow-hidden', classNames)}>\n {/* TODO(burdon): Replace with Thread? */}\n <div ref={scrollerRef} className='flex flex-col gap-6 h-full p-4 overflow-x-hidden overflow-y-auto'>\n <MessageThread state={state} result={result} history={history} />\n </div>\n\n <Toolbar.Root classNames='p-2'>\n <Input.Root>\n <Input.TextInput\n ref={inputRef}\n autoFocus\n placeholder={t('function request placeholder')}\n value={input}\n onChange={(ev) => setInput(ev.target.value)}\n onKeyDown={(ev) => ev.key === 'Enter' && handleRequest(input)}\n />\n </Input.Root>\n <Input.Root>\n <Input.TextInput\n ref={bindingInputRef}\n classNames='!w-[10rem]'\n placeholder={t('binding placeholder')}\n value={binding}\n onChange={(ev) => setBinding(ev.target.value.toUpperCase())}\n onBlur={handleBlur}\n />\n </Input.Root>\n <Toolbar.Button onClick={() => handleRequest(input)}>\n <Icon icon='ph--play--regular' size={4} />\n </Toolbar.Button>\n <Toolbar.Button onClick={() => (state ? handleStop() : handleClear())}>\n <Icon icon={state ? 'ph--stop--regular' : 'ph--trash--regular'} size={4} />\n </Toolbar.Button>\n </Toolbar.Root>\n </div>\n </DensityProvider>\n );\n};\n\nconst RobotAvatar = () => (\n <Avatar.Root size={6} variant='circle'>\n <Avatar.Frame>\n <Avatar.Icon icon='ph--robot--regular' />\n </Avatar.Frame>\n </Avatar.Root>\n);\n\nconst MessageItem = ({ classNames, message }: ThemedClassName<{ message: Message }>) => {\n const { text, data, error } = message;\n if (error) {\n return <span className={mx(classNames, 'whitespace-pre text-error')}>{String(error)}</span>;\n } else if (data) {\n return (\n <SyntaxHighlighter language='json' className={mx('text-xs', classNames)}>\n {JSON.stringify(data, null, 2)}\n </SyntaxHighlighter>\n );\n }\n\n return <span className={mx(classNames)}>{text || '\\u00D8'}</span>;\n};\n\n// TODO(burdon): Replace with thread?\n// TODO(burdon): Button to delete individual messages.\n// TODO(burdon): Button to re-run question.\nconst MessageThread = ({ state, result, history }: { state: State | null; result: string; history: Message[] }) => {\n return (\n <>\n {history.map((message, i) => (\n <div key={i} className='grid grid-cols-[3rem_1fr]'>\n <div>{message.type === 'response' && <RobotAvatar />}</div>\n <div className={mx('flex', message.type === 'request' && 'justify-end')}>\n <MessageItem\n classNames={[message.type === 'request' && 'p-1 px-2 rounded-lg bg-hoverSurface']}\n message={message}\n />\n </div>\n </div>\n ))}\n <div className='grid grid-cols-[3rem_1fr]'>\n <div>\n {(state === 'pending' && <Icon icon='ph--spinner--regular' size={6} classNames='animate-spin-slow' />) ||\n (result.length > 0 && <RobotAvatar />)}\n </div>\n <div>\n <span>{result}</span>\n </div>\n </div>\n </>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { useState } from 'react';\n\nimport {\n DensityProvider,\n ElevationProvider,\n Icon,\n type ThemedClassName,\n Toolbar as NaturalToolbar,\n Tooltip,\n useTranslation,\n} from '@dxos/react-ui';\n\nimport { SCRIPT_PLUGIN } from '../meta';\n\nexport type ToolbarProps = ThemedClassName<{\n deployed?: boolean;\n error?: string;\n functionUrl?: string;\n showPanel?: boolean;\n onDeploy?: () => Promise<void>;\n onFormat?: () => Promise<void>;\n onTogglePanel?: () => Promise<void>;\n}>;\n\nexport const Toolbar = ({\n classNames,\n deployed,\n error,\n functionUrl,\n showPanel,\n onDeploy,\n onFormat,\n onTogglePanel,\n}: ToolbarProps) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n const [pending, setPending] = useState(false);\n\n const handleCopyLink = async () => {\n if (!functionUrl) {\n return;\n }\n\n await navigator.clipboard.writeText(functionUrl);\n };\n\n const handleDeploy = async () => {\n setPending(true);\n await onDeploy?.();\n setPending(false);\n };\n\n // TODO(burdon): Simplify tooltips.\n // TODO(burdon): Factor out common toolbar components with sheet/editor?\n return (\n <DensityProvider density='fine'>\n <ElevationProvider elevation='chrome'>\n <NaturalToolbar.Root classNames={['p-1', classNames]} style={{ contain: 'layout' }}>\n {onFormat && (\n <Tooltip.Root>\n <Tooltip.Trigger asChild>\n <NaturalToolbar.Button variant='ghost' onClick={onFormat}>\n <Icon icon='ph--magic-wand--regular' size={4} />\n </NaturalToolbar.Button>\n </Tooltip.Trigger>\n <Tooltip.Portal>\n <Tooltip.Content>\n <Tooltip.Arrow />\n {t('format label')}\n </Tooltip.Content>\n </Tooltip.Portal>\n </Tooltip.Root>\n )}\n\n <div role='separator' className='grow' />\n\n {error ? (\n <Tooltip.Root>\n <Tooltip.Trigger>\n <Icon icon='ph--warning-circle--regular' size={4} />\n </Tooltip.Trigger>\n <Tooltip.Portal>\n <Tooltip.Content>\n <Tooltip.Arrow />\n {error}\n </Tooltip.Content>\n </Tooltip.Portal>\n </Tooltip.Root>\n ) : null}\n\n {functionUrl && deployed && (\n <Tooltip.Root>\n <Tooltip.Trigger asChild>\n <NaturalToolbar.Button variant='ghost' onClick={handleCopyLink}>\n <Icon icon='ph--link--regular' size={4} />\n </NaturalToolbar.Button>\n </Tooltip.Trigger>\n <Tooltip.Portal>\n <Tooltip.Content>\n <Tooltip.Arrow />\n {t('copy link label')}\n </Tooltip.Content>\n </Tooltip.Portal>\n </Tooltip.Root>\n )}\n\n <Tooltip.Root>\n <Tooltip.Trigger asChild>\n <NaturalToolbar.Button variant='ghost' onClick={handleDeploy} disabled={pending}>\n {pending ? (\n <Icon icon='ph--spinner--regular' size={4} classNames='animate-spin-slow' />\n ) : (\n <Icon icon='ph--cloud-arrow-up--regular' size={4} />\n )}\n </NaturalToolbar.Button>\n </Tooltip.Trigger>\n <Tooltip.Portal>\n <Tooltip.Content>\n <Tooltip.Arrow />\n {pending ? t('pending label') : t('deploy label')}\n </Tooltip.Content>\n </Tooltip.Portal>\n </Tooltip.Root>\n\n {onTogglePanel && (\n <Tooltip.Root>\n <Tooltip.Trigger asChild>\n <NaturalToolbar.Button variant='ghost' onClick={onTogglePanel}>\n <Icon icon={showPanel ? 'ph--caret-down--regular' : 'ph--caret-up--regular'} size={4} />\n </NaturalToolbar.Button>\n </Tooltip.Trigger>\n <Tooltip.Portal>\n <Tooltip.Content>\n <Tooltip.Arrow />\n {t('toggle details label')}\n </Tooltip.Content>\n </Tooltip.Portal>\n </Tooltip.Root>\n )}\n </NaturalToolbar.Root>\n </ElevationProvider>\n </DensityProvider>\n );\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAKA,SAASA,cAAc;AACvB,OAAOC,0BAA0B;AACjC,OAAOC,8BAA8B;AACrC,OAAOC,UAASC,aAAaC,SAASC,YAAAA,iBAAgB;AAEtD,SAASC,OAAAA,YAAW;AACpB,SAASC,iBAAiB;AAC1B,SACEC,QACAC,mBACAC,QACAC,kBACAC,SACAC,UACAC,gBACK;AACP,SAASC,mBAAmB;AAC5B,SAASC,kBAAAA,uBAAsB;AAC/B,SAASC,uBAAuB;AAChC,SAASC,sBAAsBC,gBAAgB;AAC/C,SAASC,MAAAA,WAAU;;;ACrBnB,OAAOC,SAASC,WAAWC,QAAQC,gBAAgB;AAEnD,SAASC,WAAW;AACpB,SACEC,QACAC,iBACAC,MACAC,OAEAC,SACAC,oBACAC,sBACK;AACP,SAASC,yBAAyB;AAClC,SAASC,UAAU;;AAiBZ,IAAMC,aAAa,CAAC,EAAEC,YAAYC,aAAaC,SAASC,UAAUC,gBAAe,MAAmB;AACzG,QAAM,EAAEC,EAAC,IAAKC,eAAeC,aAAAA;AAE7B,QAAMC,kBAAkBC,OAAyB,IAAA;AACjD,QAAM,CAACP,SAASQ,UAAAA,IAAcC,mBAAmBR,YAAY,EAAA;AAC7D,QAAMS,aAAa,MAAA;AACjBR,sBAAkBF,OAAAA;EACpB;AAEA,QAAMW,WAAWJ,OAAyB,IAAA;AAC1C,QAAM,CAACK,OAAOC,QAAAA,IAAYC,SAAS,EAAA;AACnC,QAAM,CAACC,QAAQC,SAAAA,IAAaF,SAAS,EAAA;AACrC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AACxDpF,aAASiF,IAAII,aAAaC,IAAI,WAAWtF,MAAMgB,EAAE;AACjDiE,QAAIM,WAAW;AACf,WAAON,IAAIG,SAAQ;EACrB,GAAG;IAAC9D;IAAqBtB;GAAM;AAE/B,SACE,gBAAAwF,OAAA,cAACC,OAAAA;IACCpG,MAAK;IACLqG,WAAWC,IACT,iDACAtG,SAAS,aAAa,cACtBI,gBAAgB,mBAAA;KAGlB,gBAAA+F,OAAA,cAACI,kBAAAA;IACC5E,IAAI5B,OAAO4B;IACX7B;IACAkC;IACAb;IACAkF,WAAU;MAGZ,gBAAAF,OAAA,cAACK,UAAAA;IACCC,YAAW;IACXC,UAAUC,QAAQ1E,mBAAAA,KAAwB,CAAClC,OAAO0B;IAClD4D;IACAjD;IACAP;IACA+E,UAAUxD;IACVyD,UAAUpE;IACVqE,eAAe,YAAYhF,aAAa,CAACiF,gBAAgB,CAACA,WAAAA;MAG3DlF,aACC,gBAAAsE,OAAA,cAACa,YAAAA;IAAW3B;IAA0B7C,SAAS3B,IAAI2B;IAASyE,iBAAiB3E;;AAIrF;AAEA,IAAA,uBAAezC;",
6
+ "names": ["format", "prettierPluginEstree", "prettierPluginTypescript", "React", "useCallback", "useMemo", "useState", "log", "useClient", "create", "createDocAccessor", "Filter", "fullyQualifiedId", "getMeta", "getSpace", "useQuery", "useIdentity", "useTranslation", "useHasAttention", "createDataExtensions", "listener", "mx", "React", "useEffect", "useRef", "useState", "log", "Avatar", "DensityProvider", "Icon", "Input", "Toolbar", "useControlledValue", "useTranslation", "SyntaxHighlighter", "mx", "DebugPanel", "classNames", "functionUrl", "binding", "_binding", "onBindingChange", "t", "useTranslation", "SCRIPT_PLUGIN", "bindingInputRef", "useRef", "setBinding", "useControlledValue", "handleBlur", "inputRef", "input", "setInput", "useState", "result", "setResult", "state", "setState", "history", "setHistory", "scrollerRef", "handleScroll", "current", "scrollTop", "scrollHeight", "controller", "useEffect", "handleStop", "abort", "undefined", "handleClear", "focus", "handleResponse", "text", "data", "error", "type", "handleRequest", "charAt", "validJsonString", "replace", "JSON", "parse", "stringify", "err", "setTimeout", "AbortController", "response", "fetch", "signal", "method", "body", "headers", "ok", "Error", "statusText", "String", "status", "contentType", "get", "json", "reader", "getReader", "pump", "done", "value", "TextDecoder", "decode", "read", "then", "catch", "name", "log", "DensityProvider", "density", "div", "className", "mx", "ref", "MessageThread", "Toolbar", "Root", "Input", "TextInput", "autoFocus", "placeholder", "onChange", "ev", "target", "onKeyDown", "key", "toUpperCase", "onBlur", "Button", "onClick", "Icon", "icon", "size", "RobotAvatar", "Avatar", "variant", "Frame", "MessageItem", "message", "span", "SyntaxHighlighter", "language", "map", "i", "length", "React", "useState", "DensityProvider", "ElevationProvider", "Icon", "Toolbar", "NaturalToolbar", "Tooltip", "useTranslation", "Toolbar", "classNames", "deployed", "error", "functionUrl", "showPanel", "onDeploy", "onFormat", "onTogglePanel", "t", "useTranslation", "SCRIPT_PLUGIN", "pending", "setPending", "useState", "handleCopyLink", "navigator", "clipboard", "writeText", "handleDeploy", "React", "DensityProvider", "density", "ElevationProvider", "elevation", "NaturalToolbar", "Root", "style", "contain", "Tooltip", "Trigger", "asChild", "Button", "variant", "onClick", "Icon", "icon", "size", "Portal", "Content", "Arrow", "div", "role", "className", "disabled", "ScriptEditor", "env", "script", "role", "t", "useTranslation", "SCRIPT_PLUGIN", "hasAttention", "useHasAttention", "fullyQualifiedId", "client", "useClient", "identity", "useIdentity", "space", "getSpace", "fn", "useQuery", "Filter", "schema", "FunctionType", "source", "extensions", "useMemo", "listener", "onChange", "text", "content", "changed", "createDataExtensions", "id", "createDocAccessor", "showPanel", "setShowPanel", "useState", "initialValue", "existingFunctionUrl", "getUserFunctionUrlInMetadata", "getMeta", "error", "setError", "handleBindingChange", "useCallback", "binding", "handleFormat", "format", "parser", "plugins", "prettierPluginEstree", "prettierPluginTypescript", "semi", "singleQuote", "err", "log", "catch", "handleDeploy", "undefined", "existingFunctionId", "split", "at", "ownerDid", "publicKeyToDid", "identityKey", "bundler", "Bundler", "platform", "sandboxedModules", "remoteModules", "buildResult", "bundle", "result", "functionId", "functionVersionNumber", "errorMessage", "uploadWorkerFunction", "clientConfig", "config", "halo", "Error", "info", "version", "deployedFunction", "db", "add", "create", "meta", "setUserFunctionUrlInMetadata", "name", "functionUrl", "baseUrl", "URL", "values", "runtime", "services", "edge", "url", "relativeUrl", "replace", "toString", "searchParams", "set", "protocol", "React", "div", "className", "mx", "TypescriptEditor", "Toolbar", "classNames", "deployed", "Boolean", "onDeploy", "onFormat", "onTogglePanel", "showDetails", "DebugPanel", "onBindingChange"]
7
+ }
@@ -0,0 +1,9 @@
1
+ import {
2
+ TypescriptEditor,
3
+ TypescriptEditor_default
4
+ } from "./chunk-MRGOT5RF.mjs";
5
+ export {
6
+ TypescriptEditor,
7
+ TypescriptEditor_default as default
8
+ };
9
+ //# sourceMappingURL=TypescriptEditor-GPE72Y6I.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }