@dxos/plugin-script 0.7.2 → 0.7.3-staging.971cd8d
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/lib/browser/{AutomationPanel-BZCRRLOQ.mjs → AutomationPanel-PMTZROAZ.mjs} +18 -11
- package/dist/lib/browser/AutomationPanel-PMTZROAZ.mjs.map +7 -0
- package/dist/lib/browser/{ScriptContainer-GQ2KJ5BM.mjs → ScriptContainer-RYZFYCNK.mjs} +27 -25
- package/dist/lib/browser/ScriptContainer-RYZFYCNK.mjs.map +7 -0
- package/dist/lib/browser/{chunk-NCZUJKJE.mjs → chunk-K7KY6YMG.mjs} +14 -10
- package/dist/lib/browser/chunk-K7KY6YMG.mjs.map +7 -0
- package/dist/lib/browser/{chunk-DTVOXLPP.mjs → chunk-QFZUFT5G.mjs} +2 -2
- package/dist/lib/browser/{chunk-DTVOXLPP.mjs.map → chunk-QFZUFT5G.mjs.map} +3 -3
- package/dist/lib/browser/chunk-U3OP64V4.mjs +123 -0
- package/dist/lib/browser/chunk-U3OP64V4.mjs.map +7 -0
- package/dist/lib/browser/edge/index.mjs +5 -9
- package/dist/lib/browser/index.mjs +15 -18
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/types/index.mjs +1 -1
- package/dist/lib/node/{AutomationPanel-VNLNP3EE.cjs → AutomationPanel-AAGQREH7.cjs} +21 -16
- package/dist/lib/node/AutomationPanel-AAGQREH7.cjs.map +7 -0
- package/dist/lib/node/{ScriptContainer-K67ZWCKL.cjs → ScriptContainer-FZ44UIRC.cjs} +32 -30
- package/dist/lib/node/ScriptContainer-FZ44UIRC.cjs.map +7 -0
- package/dist/lib/node/{chunk-BJ4WIWCP.cjs → chunk-4INUJLXL.cjs} +16 -12
- package/dist/lib/node/chunk-4INUJLXL.cjs.map +7 -0
- package/dist/lib/node/chunk-CS25QNKZ.cjs +151 -0
- package/dist/lib/node/chunk-CS25QNKZ.cjs.map +7 -0
- package/dist/lib/node/{chunk-T4PYTKIW.cjs → chunk-DQYAU2CJ.cjs} +5 -5
- package/dist/lib/node/{chunk-T4PYTKIW.cjs.map → chunk-DQYAU2CJ.cjs.map} +3 -3
- package/dist/lib/node/edge/index.cjs +10 -14
- package/dist/lib/node/edge/index.cjs.map +2 -2
- package/dist/lib/node/index.cjs +30 -33
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/types/index.cjs +4 -4
- package/dist/lib/node/types/index.cjs.map +1 -1
- package/dist/lib/node-esm/{AutomationPanel-NWE2QCOE.mjs → AutomationPanel-ETQEDY5I.mjs} +18 -11
- package/dist/lib/node-esm/AutomationPanel-ETQEDY5I.mjs.map +7 -0
- package/dist/lib/node-esm/{ScriptContainer-BVDYLJZI.mjs → ScriptContainer-3PKDW34A.mjs} +27 -25
- package/dist/lib/node-esm/ScriptContainer-3PKDW34A.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-36DLLQ6E.mjs +125 -0
- package/dist/lib/node-esm/chunk-36DLLQ6E.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-2HYWFUEN.mjs → chunk-GMVPKT6A.mjs} +2 -2
- package/dist/lib/node-esm/{chunk-2HYWFUEN.mjs.map → chunk-GMVPKT6A.mjs.map} +3 -3
- package/dist/lib/node-esm/{chunk-DXWSRDEN.mjs → chunk-OFYGBUNI.mjs} +14 -10
- package/dist/lib/node-esm/chunk-OFYGBUNI.mjs.map +7 -0
- package/dist/lib/node-esm/edge/index.mjs +5 -9
- package/dist/lib/node-esm/index.mjs +15 -18
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/types/index.mjs +1 -1
- package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts.map +1 -1
- package/dist/types/src/components/DebugPanel/DebugPanel.d.ts.map +1 -1
- package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts +1 -5
- package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts.map +1 -1
- package/dist/types/src/components/ScriptBlock/ScriptBlock.stories.d.ts.map +1 -1
- package/dist/types/src/components/ScriptEditor.d.ts.map +1 -1
- package/dist/types/src/components/ScriptSettingsPanel.d.ts.map +1 -1
- package/dist/types/src/edge/functions.d.ts +13 -21
- package/dist/types/src/edge/functions.d.ts.map +1 -1
- package/dist/types/src/edge/index.d.ts +0 -3
- package/dist/types/src/edge/index.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +43 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/schema.d.ts +2 -2
- package/dist/types/src/types/types.d.ts +2 -3
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/package.json +37 -36
- package/src/ScriptPlugin.tsx +4 -8
- package/src/components/AutomationPanel/AutomationPanel.tsx +10 -5
- package/src/components/DebugPanel/DebugPanel.tsx +41 -30
- package/src/components/ScriptBlock/ScriptBlock.stories.tsx +5 -25
- package/src/components/ScriptBlock/ScriptBlock.tsx +3 -8
- package/src/components/ScriptEditor.tsx +16 -23
- package/src/components/ScriptSettingsPanel.tsx +1 -5
- package/src/edge/functions.ts +69 -109
- package/src/edge/index.ts +0 -3
- package/src/translations.ts +4 -0
- package/src/types/schema.ts +1 -1
- package/src/types/types.ts +1 -3
- package/dist/lib/browser/AutomationPanel-BZCRRLOQ.mjs.map +0 -7
- package/dist/lib/browser/ScriptContainer-GQ2KJ5BM.mjs.map +0 -7
- package/dist/lib/browser/chunk-5GGRYRS4.mjs +0 -253
- package/dist/lib/browser/chunk-5GGRYRS4.mjs.map +0 -7
- package/dist/lib/browser/chunk-NCZUJKJE.mjs.map +0 -7
- package/dist/lib/node/AutomationPanel-VNLNP3EE.cjs.map +0 -7
- package/dist/lib/node/ScriptContainer-K67ZWCKL.cjs.map +0 -7
- package/dist/lib/node/chunk-BJ4WIWCP.cjs.map +0 -7
- package/dist/lib/node/chunk-XS6GEYYH.cjs +0 -273
- package/dist/lib/node/chunk-XS6GEYYH.cjs.map +0 -7
- package/dist/lib/node-esm/AutomationPanel-NWE2QCOE.mjs.map +0 -7
- package/dist/lib/node-esm/ScriptContainer-BVDYLJZI.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-DXWSRDEN.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-V74XKPLC.mjs +0 -255
- package/dist/lib/node-esm/chunk-V74XKPLC.mjs.map +0 -7
- package/dist/types/src/edge/codec.d.ts +0 -4
- package/dist/types/src/edge/codec.d.ts.map +0 -1
- package/dist/types/src/edge/header-codec.d.ts +0 -24
- package/dist/types/src/edge/header-codec.d.ts.map +0 -1
- package/dist/types/src/edge/hub-protocol.d.ts +0 -6
- package/dist/types/src/edge/hub-protocol.d.ts.map +0 -1
- package/src/edge/codec.ts +0 -13
- package/src/edge/header-codec.ts +0 -97
- package/src/edge/hub-protocol.ts +0 -27
|
@@ -1,40 +1,47 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
DebugPanel
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-OFYGBUNI.mjs";
|
|
5
5
|
import {
|
|
6
6
|
getInvocationUrl,
|
|
7
7
|
getUserFunctionUrlInMetadata
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-36DLLQ6E.mjs";
|
|
9
9
|
import {
|
|
10
10
|
FunctionType,
|
|
11
11
|
ScriptType
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import
|
|
12
|
+
} from "./chunk-GMVPKT6A.mjs";
|
|
13
|
+
import {
|
|
14
|
+
SCRIPT_PLUGIN
|
|
15
|
+
} from "./chunk-SLTZMY34.mjs";
|
|
14
16
|
|
|
15
17
|
// packages/plugins/experimental/plugin-script/src/components/AutomationPanel/AutomationPanel.tsx
|
|
16
18
|
import React, { useMemo, useState } from "react";
|
|
17
19
|
import { failUndefined } from "@dxos/debug";
|
|
18
20
|
import { useClient } from "@dxos/react-client";
|
|
19
21
|
import { Filter, getMeta, getSpace, useQuery } from "@dxos/react-client/echo";
|
|
20
|
-
import { Select } from "@dxos/react-ui";
|
|
22
|
+
import { Select, useTranslation } from "@dxos/react-ui";
|
|
21
23
|
var AutomationPanel = ({ subject }) => {
|
|
24
|
+
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
22
25
|
const space = getSpace(subject);
|
|
23
|
-
const functions = useQuery(space ?? void 0,
|
|
26
|
+
const functions = useQuery(space ?? void 0, subject instanceof ScriptType ? Filter.schema(FunctionType, {
|
|
27
|
+
source: subject
|
|
28
|
+
}) : Filter.schema(FunctionType, (fn) => fn.binding != null), {}, [
|
|
24
29
|
subject
|
|
25
30
|
]);
|
|
26
31
|
const [selectedFunction, setSelectedFunction] = useState(null);
|
|
27
|
-
const
|
|
32
|
+
const chatFunction = subject instanceof ScriptType ? functions[0] : selectedFunction;
|
|
28
33
|
return /* @__PURE__ */ React.createElement("div", {
|
|
29
34
|
className: "h-full flex flex-col"
|
|
30
35
|
}, !(subject instanceof ScriptType) && /* @__PURE__ */ React.createElement(BindingSelect, {
|
|
31
36
|
selectedFunction,
|
|
32
37
|
setSelectedFunction,
|
|
33
38
|
functions
|
|
34
|
-
}),
|
|
35
|
-
fn:
|
|
39
|
+
}), chatFunction && /* @__PURE__ */ React.createElement(ChatPanel, {
|
|
40
|
+
fn: chatFunction,
|
|
36
41
|
subject
|
|
37
|
-
}), subject instanceof ScriptType && functions.length === 0 && /* @__PURE__ */ React.createElement("
|
|
42
|
+
}), subject instanceof ScriptType && functions.length === 0 && /* @__PURE__ */ React.createElement("div", {
|
|
43
|
+
className: "p-1"
|
|
44
|
+
}, t("not deployed")));
|
|
38
45
|
};
|
|
39
46
|
var ChatPanel = ({ fn, subject }) => {
|
|
40
47
|
const client = useClient();
|
|
@@ -76,4 +83,4 @@ export {
|
|
|
76
83
|
AutomationPanel,
|
|
77
84
|
AutomationPanel_default as default
|
|
78
85
|
};
|
|
79
|
-
//# sourceMappingURL=AutomationPanel-
|
|
86
|
+
//# sourceMappingURL=AutomationPanel-ETQEDY5I.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/AutomationPanel/AutomationPanel.tsx", "../../../src/components/AutomationPanel/index.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { useMemo, useState } from 'react';\n\nimport { type ReactiveEchoObject } from '@dxos/client/echo';\nimport { failUndefined } from '@dxos/debug';\nimport { useClient } from '@dxos/react-client';\nimport { Filter, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';\nimport { Select, useTranslation } from '@dxos/react-ui';\n\nimport { getInvocationUrl, getUserFunctionUrlInMetadata } from '../../edge';\nimport { SCRIPT_PLUGIN } from '../../meta';\nimport { FunctionType, ScriptType } from '../../types';\nimport { DebugPanel } from '../DebugPanel';\n\nexport interface AutomationPanelProps {\n subject: ReactiveEchoObject<any>;\n}\n\nexport const AutomationPanel = ({ subject }: AutomationPanelProps) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n const space = getSpace(subject);\n\n // TODO(dmaretskyi): Parametric query.\n const functions = useQuery(\n space ?? undefined,\n subject instanceof ScriptType\n ? Filter.schema(FunctionType, { source: subject })\n : Filter.schema(FunctionType, (fn) => fn.binding != null),\n {},\n [subject],\n );\n\n const [selectedFunction, setSelectedFunction] = useState<FunctionType | null>(null);\n const chatFunction = subject instanceof ScriptType ? functions[0] : selectedFunction;\n\n return (\n <div className='h-full flex flex-col'>\n {!(subject instanceof ScriptType) && (\n <BindingSelect\n selectedFunction={selectedFunction}\n setSelectedFunction={setSelectedFunction}\n functions={functions}\n />\n )}\n {chatFunction && <ChatPanel fn={chatFunction} subject={subject} />}\n {subject instanceof ScriptType && functions.length === 0 && <div className='p-1'>{t('not deployed')}</div>}\n </div>\n );\n};\n\nexport interface ChatPanelProps {\n fn: FunctionType;\n subject: ReactiveEchoObject<any>;\n}\n\nconst ChatPanel = ({ fn, subject }: ChatPanelProps) => {\n const client = useClient();\n const space = getSpace(fn);\n const existingFunctionUrl = getUserFunctionUrlInMetadata(getMeta(fn));\n const functionUrl = useMemo(() => {\n if (!existingFunctionUrl) {\n return;\n }\n\n return getInvocationUrl(existingFunctionUrl, client.config.values.runtime?.services?.edge?.url ?? '', {\n spaceId: space?.id,\n subjectId: subject?.id,\n });\n }, [existingFunctionUrl, space, subject]);\n\n return <DebugPanel functionUrl={functionUrl} classNames='flex-1' />;\n};\n\nexport interface BindingSelectProps {\n selectedFunction: FunctionType | null;\n setSelectedFunction: (fn: FunctionType) => void;\n functions: FunctionType[];\n}\n\nconst BindingSelect = ({ selectedFunction, setSelectedFunction, functions }: BindingSelectProps) => {\n return (\n <Select.Root\n value={selectedFunction?.id}\n onValueChange={(id) => setSelectedFunction(functions.find((fn) => fn.id === id) ?? failUndefined())}\n >\n <Select.TriggerButton placeholder='Select value' />\n <Select.Portal>\n <Select.Content>\n <Select.ScrollUpButton />\n <Select.Viewport>\n {functions.map(({ id, binding }) => (\n <Select.Option key={id} value={id}>\n {binding}\n </Select.Option>\n ))}\n </Select.Viewport>\n <Select.ScrollDownButton />\n <Select.Arrow />\n </Select.Content>\n </Select.Portal>\n </Select.Root>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AutomationPanel } from './AutomationPanel';\n\nexport * from './AutomationPanel';\n\nexport default AutomationPanel;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAIA,OAAOA,SAASC,SAASC,gBAAgB;AAGzC,SAASC,qBAAqB;AAC9B,SAASC,iBAAiB;AAC1B,SAASC,QAAQC,SAASC,UAAUC,gBAAgB;AACpD,SAASC,QAAQC,sBAAsB;AAWhC,IAAMC,kBAAkB,CAAC,EAAEC,QAAO,MAAwB;AAC/D,QAAM,EAAEC,EAAC,IA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SACE,sBAAA,cAACsC,OAAOC,MAAI;IACVC,OAAO9B,kBAAkBwB;IACzBO,eAAe,CAACP,OAAOvB,oBAAoBX,UAAU0C,KAAK,CAAClC,OAAOA,GAAG0B,OAAOA,EAAAA,KAAOS,cAAAA,CAAAA;KAEnF,sBAAA,cAACL,OAAOM,eAAa;IAACC,aAAY;MAClC,sBAAA,cAACP,OAAOQ,QAAM,MACZ,sBAAA,cAACR,OAAOS,SAAO,MACb,sBAAA,cAACT,OAAOU,gBAAc,IAAA,GACtB,sBAAA,cAACV,OAAOW,UAAQ,MACbjD,UAAUkD,IAAI,CAAC,EAAEhB,IAAIzB,QAAO,MAC3B,sBAAA,cAAC6B,OAAOa,QAAM;IAACC,KAAKlB;IAAIM,OAAON;KAC5BzB,OAAAA,CAAAA,CAAAA,GAIP,sBAAA,cAAC6B,OAAOe,kBAAgB,IAAA,GACxB,sBAAA,cAACf,OAAOgB,OAAK,IAAA,CAAA,CAAA,CAAA;AAKvB;;;ACjGA,IAAA,0BAAeC;",
|
|
6
|
+
"names": ["React", "useMemo", "useState", "failUndefined", "useClient", "Filter", "getMeta", "getSpace", "useQuery", "Select", "useTranslation", "AutomationPanel", "subject", "t", "useTranslation", "SCRIPT_PLUGIN", "space", "getSpace", "functions", "useQuery", "undefined", "ScriptType", "Filter", "schema", "FunctionType", "source", "fn", "binding", "selectedFunction", "setSelectedFunction", "useState", "chatFunction", "div", "className", "BindingSelect", "ChatPanel", "length", "client", "useClient", "existingFunctionUrl", "getUserFunctionUrlInMetadata", "getMeta", "functionUrl", "useMemo", "getInvocationUrl", "config", "values", "runtime", "services", "edge", "url", "spaceId", "id", "subjectId", "DebugPanel", "classNames", "Select", "Root", "value", "onValueChange", "find", "failUndefined", "TriggerButton", "placeholder", "Portal", "Content", "ScrollUpButton", "Viewport", "map", "Option", "key", "ScrollDownButton", "Arrow", "AutomationPanel"]
|
|
7
|
+
}
|
|
@@ -5,18 +5,18 @@ import {
|
|
|
5
5
|
} from "./chunk-4SRPREUK.mjs";
|
|
6
6
|
import {
|
|
7
7
|
DebugPanel
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-OFYGBUNI.mjs";
|
|
9
9
|
import {
|
|
10
|
-
|
|
10
|
+
FUNCTIONS_PRESET_META_KEY,
|
|
11
11
|
getInvocationUrl,
|
|
12
12
|
getUserFunctionUrlInMetadata,
|
|
13
|
-
|
|
13
|
+
incrementSemverPatch,
|
|
14
14
|
setUserFunctionUrlInMetadata,
|
|
15
15
|
uploadWorkerFunction
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-36DLLQ6E.mjs";
|
|
17
17
|
import {
|
|
18
18
|
FunctionType
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-GMVPKT6A.mjs";
|
|
20
20
|
import {
|
|
21
21
|
SCRIPT_PLUGIN
|
|
22
22
|
} from "./chunk-SLTZMY34.mjs";
|
|
@@ -226,7 +226,9 @@ var ScriptEditor = ({ classNames, script, env }) => {
|
|
|
226
226
|
const client = useClient();
|
|
227
227
|
const identity = useIdentity();
|
|
228
228
|
const space = getSpace(script);
|
|
229
|
-
const [fn] = useQuery(space, Filter.schema(FunctionType,
|
|
229
|
+
const [fn] = useQuery(space, Filter.schema(FunctionType, {
|
|
230
|
+
source: script
|
|
231
|
+
}));
|
|
230
232
|
const extensions = useMemo(() => [
|
|
231
233
|
listener({
|
|
232
234
|
onChange: (text) => {
|
|
@@ -269,7 +271,7 @@ var ScriptEditor = ({ classNames, script, env }) => {
|
|
|
269
271
|
} catch (err) {
|
|
270
272
|
log.catch(err, void 0, {
|
|
271
273
|
F: __dxlog_file,
|
|
272
|
-
L:
|
|
274
|
+
L: 83,
|
|
273
275
|
S: void 0,
|
|
274
276
|
C: (f, a) => f(...a)
|
|
275
277
|
});
|
|
@@ -283,13 +285,13 @@ var ScriptEditor = ({ classNames, script, env }) => {
|
|
|
283
285
|
script.name = template.name;
|
|
284
286
|
script.source.content = template.source;
|
|
285
287
|
const metaKeys = getMeta(script).keys;
|
|
286
|
-
const oldPresetIndex = metaKeys.findIndex((key) => key.source ===
|
|
288
|
+
const oldPresetIndex = metaKeys.findIndex((key) => key.source === FUNCTIONS_PRESET_META_KEY);
|
|
287
289
|
if (oldPresetIndex >= 0) {
|
|
288
290
|
metaKeys.splice(oldPresetIndex, 1);
|
|
289
291
|
}
|
|
290
292
|
if (template.presetId) {
|
|
291
293
|
metaKeys.push({
|
|
292
|
-
source:
|
|
294
|
+
source: FUNCTIONS_PRESET_META_KEY,
|
|
293
295
|
id: template.presetId
|
|
294
296
|
});
|
|
295
297
|
}
|
|
@@ -302,7 +304,6 @@ var ScriptEditor = ({ classNames, script, env }) => {
|
|
|
302
304
|
setError(void 0);
|
|
303
305
|
try {
|
|
304
306
|
const existingFunctionId = existingFunctionUrl?.split("/").at(-1);
|
|
305
|
-
const ownerDid = existingFunctionUrl?.split("/").at(-2) ?? publicKeyToDid(identity.identityKey);
|
|
306
307
|
const bundler = new Bundler({
|
|
307
308
|
platform: "browser",
|
|
308
309
|
sandboxedModules: [],
|
|
@@ -312,31 +313,31 @@ var ScriptEditor = ({ classNames, script, env }) => {
|
|
|
312
313
|
if (buildResult.error || !buildResult.bundle) {
|
|
313
314
|
throw buildResult.error;
|
|
314
315
|
}
|
|
315
|
-
const {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
316
|
+
const { functionId, version, meta } = await uploadWorkerFunction({
|
|
317
|
+
client,
|
|
318
|
+
spaceId: space.id,
|
|
319
|
+
version: fn ? incrementSemverPatch(fn.version) : "0.0.1",
|
|
319
320
|
functionId: existingFunctionId,
|
|
320
321
|
source: buildResult.bundle
|
|
321
322
|
});
|
|
322
|
-
if (
|
|
323
|
-
throw new Error(
|
|
323
|
+
if (functionId === void 0 || version === void 0) {
|
|
324
|
+
throw new Error(`Upload didn't return expected data: functionId=${functionId}, version=${version}`);
|
|
324
325
|
}
|
|
325
326
|
log.info("function uploaded", {
|
|
326
327
|
functionId,
|
|
327
|
-
|
|
328
|
+
version
|
|
328
329
|
}, {
|
|
329
330
|
F: __dxlog_file,
|
|
330
|
-
L:
|
|
331
|
+
L: 130,
|
|
331
332
|
S: void 0,
|
|
332
333
|
C: (f, a) => f(...a)
|
|
333
334
|
});
|
|
334
335
|
if (fn) {
|
|
335
|
-
fn.version =
|
|
336
|
+
fn.version = version;
|
|
336
337
|
}
|
|
337
338
|
const deployedFunction = fn ?? space.db.add(create(FunctionType, {
|
|
338
339
|
name: functionId,
|
|
339
|
-
version
|
|
340
|
+
version,
|
|
340
341
|
source: script
|
|
341
342
|
}));
|
|
342
343
|
script.changed = false;
|
|
@@ -347,17 +348,17 @@ var ScriptEditor = ({ classNames, script, env }) => {
|
|
|
347
348
|
functionId
|
|
348
349
|
}, {
|
|
349
350
|
F: __dxlog_file,
|
|
350
|
-
L:
|
|
351
|
+
L: 142,
|
|
351
352
|
S: void 0,
|
|
352
353
|
C: (f, a) => f(...a)
|
|
353
354
|
});
|
|
354
355
|
}
|
|
355
|
-
setUserFunctionUrlInMetadata(getMeta(deployedFunction), `/${
|
|
356
|
+
setUserFunctionUrlInMetadata(getMeta(deployedFunction), `/${space.id}/${functionId}`);
|
|
356
357
|
setView("split");
|
|
357
358
|
} catch (err) {
|
|
358
359
|
log.catch(err, void 0, {
|
|
359
360
|
F: __dxlog_file,
|
|
360
|
-
L:
|
|
361
|
+
L: 149,
|
|
361
362
|
S: void 0,
|
|
362
363
|
C: (f, a) => f(...a)
|
|
363
364
|
});
|
|
@@ -368,7 +369,8 @@ var ScriptEditor = ({ classNames, script, env }) => {
|
|
|
368
369
|
existingFunctionUrl,
|
|
369
370
|
script,
|
|
370
371
|
script.name,
|
|
371
|
-
script.source
|
|
372
|
+
script.source,
|
|
373
|
+
space?.id ?? null
|
|
372
374
|
]);
|
|
373
375
|
const functionUrl = useMemo(() => {
|
|
374
376
|
if (!existingFunctionUrl) {
|
|
@@ -421,4 +423,4 @@ var ScriptContainer_default = ScriptContainer;
|
|
|
421
423
|
export {
|
|
422
424
|
ScriptContainer_default as default
|
|
423
425
|
};
|
|
424
|
-
//# sourceMappingURL=ScriptContainer-
|
|
426
|
+
//# sourceMappingURL=ScriptContainer-3PKDW34A.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/ScriptContainer.tsx", "../../../src/components/ScriptEditor.tsx", "../../../src/components/Toolbar/Toolbar.tsx", "../../../src/components/TypescriptEditor/TypescriptEditor.tsx"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React from 'react';\n\nimport { fullyQualifiedId } from '@dxos/react-client/echo';\nimport { useAttendableAttributes } from '@dxos/react-ui-attention';\nimport { mx } from '@dxos/react-ui-theme';\n\nimport { ScriptEditor, type ScriptEditorProps } from './ScriptEditor';\n\nconst ScriptContainer = ({ script, ...props }: ScriptEditorProps) => {\n const attendableAttrs = useAttendableAttributes(fullyQualifiedId(script));\n return (\n <div role='none' className={mx('flex row-span-2 w-full overflow-hidden attention-surface')} {...attendableAttrs}>\n <ScriptEditor {...props} script={script} />\n </div>\n );\n};\n\nexport default ScriptContainer;\n", "//\n// Copyright 2023 DXOS.org\n//\n\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 { create, createDocAccessor, Filter, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';\nimport { useIdentity } from '@dxos/react-client/halo';\nimport { useTranslation, type ThemedClassName } from '@dxos/react-ui';\nimport { createDataExtensions, listener } from '@dxos/react-ui-editor';\nimport { mx } from '@dxos/react-ui-theme';\n\nimport { DebugPanel } from './DebugPanel';\nimport { type TemplateSelectProps, Toolbar, type ViewType } from './Toolbar';\nimport { TypescriptEditor, type TypescriptEditorProps } from './TypescriptEditor';\nimport { Bundler } from '../bundler';\nimport {\n getInvocationUrl,\n getUserFunctionUrlInMetadata,\n setUserFunctionUrlInMetadata,\n uploadWorkerFunction,\n FUNCTIONS_PRESET_META_KEY,\n incrementSemverPatch,\n} from '../edge';\nimport { SCRIPT_PLUGIN } from '../meta';\nimport { templates } from '../templates';\nimport { FunctionType, type ScriptType } from '../types';\n\nexport type ScriptEditorProps = ThemedClassName<{\n script: ScriptType;\n}> &\n Pick<TypescriptEditorProps, 'env'>;\n\nexport const ScriptEditor = ({ classNames, script, env }: ScriptEditorProps) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n const client = useClient();\n const identity = useIdentity();\n const space = getSpace(script);\n const [fn] = useQuery(space, Filter.schema(FunctionType, { source: script }));\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 [view, setView] = useState<ViewType>('editor');\n const existingFunctionUrl = fn && getUserFunctionUrlInMetadata(getMeta(fn));\n const [error, setError] = useState<string>();\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 handleTemplateChange: TemplateSelectProps['onTemplateSelect'] = (id) => {\n const template = templates.find((template) => template.id === id);\n if (template) {\n script.name = template.name;\n script.source!.content = template.source;\n const metaKeys = getMeta(script).keys;\n const oldPresetIndex = metaKeys.findIndex((key) => key.source === FUNCTIONS_PRESET_META_KEY);\n if (oldPresetIndex >= 0) {\n metaKeys.splice(oldPresetIndex, 1);\n }\n if (template.presetId) {\n metaKeys.push({ source: FUNCTIONS_PRESET_META_KEY, id: template.presetId });\n }\n }\n };\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\n const bundler = new Bundler({ platform: 'browser', sandboxedModules: [], remoteModules: {} });\n const buildResult = await bundler.bundle(script.source.content);\n if (buildResult.error || !buildResult.bundle) {\n throw buildResult.error;\n }\n\n const { functionId, version, meta } = await uploadWorkerFunction({\n client,\n spaceId: space.id,\n version: fn ? incrementSemverPatch(fn.version) : '0.0.1',\n functionId: existingFunctionId,\n source: buildResult.bundle,\n });\n if (functionId === undefined || version === undefined) {\n throw new Error(`Upload didn't return expected data: functionId=${functionId}, version=${version}`);\n }\n\n log.info('function uploaded', { functionId, version });\n if (fn) {\n fn.version = version;\n }\n\n const deployedFunction = fn ?? space.db.add(create(FunctionType, { name: functionId, version, source: script }));\n\n script.changed = false;\n\n if (meta.inputSchema) {\n deployedFunction.inputSchema = meta.inputSchema;\n } else {\n log.verbose('no input schema in function metadata', { functionId });\n }\n\n setUserFunctionUrlInMetadata(getMeta(deployedFunction), `/${space.id}/${functionId}`);\n\n setView('split');\n } catch (err: any) {\n log.catch(err);\n setError(t('upload failed label'));\n }\n }, [fn, existingFunctionUrl, script, script.name, script.source, space?.id ?? null]);\n\n const functionUrl = useMemo(() => {\n if (!existingFunctionUrl) {\n return;\n }\n\n return getInvocationUrl(existingFunctionUrl, client.config.values.runtime?.services?.edge?.url ?? '', {\n spaceId: space?.id,\n });\n }, [existingFunctionUrl, space]);\n\n return (\n <div role='none' className={mx('flex flex-col w-full overflow-hidden divide-y divide-separator', classNames)}>\n <Toolbar\n deployed={Boolean(existingFunctionUrl) && !script.changed}\n functionUrl={functionUrl}\n error={error}\n view={view}\n templates={templates}\n onDeploy={handleDeploy}\n onFormat={handleFormat}\n onViewChange={setView}\n onTemplateSelect={handleTemplateChange}\n />\n\n {view !== 'preview' && (\n <TypescriptEditor\n id={script.id}\n env={env}\n initialValue={script.source?.content}\n extensions={extensions}\n className='flex is-full bs-full overflow-hidden ch-focus-ring-inset-over-all'\n />\n )}\n\n {view !== 'editor' && <DebugPanel functionUrl={functionUrl} />}\n </div>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { useState } from 'react';\n\nimport {\n ElevationProvider,\n Icon,\n Select,\n type ThemedClassName,\n ToggleGroup,\n ToggleGroupItem,\n type ToolbarButtonProps,\n Toolbar as NaturalToolbar,\n Tooltip,\n useTranslation,\n} from '@dxos/react-ui';\n\nimport { SCRIPT_PLUGIN } from '../../meta';\nimport { type Template } from '../../templates';\n\nexport type ToolbarProps = ThemedClassName<\n {\n deployed?: boolean;\n error?: string;\n functionUrl?: string;\n onDeploy?: () => Promise<void>;\n onFormat?: () => Promise<void>;\n } & TemplateSelectProps &\n ViewSelectorProps\n>;\n\nexport const Toolbar = ({\n classNames,\n deployed,\n error,\n functionUrl,\n view,\n templates,\n onDeploy,\n onFormat,\n onViewChange,\n onTemplateSelect,\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 if (!pending) {\n setPending(true);\n await onDeploy?.();\n setPending(false);\n }\n };\n\n // TODO(burdon): Factor out common toolbar components with sheet/editor?\n return (\n <ElevationProvider elevation='chrome'>\n <NaturalToolbar.Root classNames={['p-1', classNames]} style={{ contain: 'layout' }}>\n {templates && <TemplateSelect templates={templates} onTemplateSelect={onTemplateSelect} />}\n {onFormat && <ToolbarIconButton icon='ph--magic-wand--regular' text={t('format label')} onClick={onFormat} />}\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 <ToolbarIconButton icon='ph--link--regular' text={t('copy link label')} onClick={handleCopyLink} />\n )}\n\n {onDeploy && (\n <ToolbarIconButton\n icon={pending ? 'ph--spinner-gap--regular' : 'ph--cloud-arrow-up--regular'}\n classNames={[pending && 'animate-spin']}\n text={pending ? t('pending label') : t('deploy label')}\n onClick={handleDeploy}\n />\n )}\n\n <ViewSelector view={view} onViewChange={onViewChange} />\n </NaturalToolbar.Root>\n </ElevationProvider>\n );\n};\n\nconst ToolbarIconButton = ({\n icon,\n text,\n classNames,\n disabled,\n onClick,\n}: { icon: string; text: string } & Pick<ToolbarButtonProps, 'classNames' | 'disabled' | 'onClick'>) => {\n return (\n <Tooltip.Root>\n <Tooltip.Trigger asChild>\n <NaturalToolbar.Button variant='ghost' disabled={disabled} onClick={onClick}>\n <Icon icon={icon} size={4} classNames={classNames} />\n </NaturalToolbar.Button>\n </Tooltip.Trigger>\n <Tooltip.Portal>\n <Tooltip.Content>\n <Tooltip.Arrow />\n {text}\n </Tooltip.Content>\n </Tooltip.Portal>\n </Tooltip.Root>\n );\n};\n\nexport type ViewType = 'editor' | 'split' | 'preview';\n\nexport type TemplateSelectProps = {\n templates?: Template[];\n onTemplateSelect?: (id: string) => void;\n};\n\nexport const TemplateSelect = ({ templates = [], onTemplateSelect }: TemplateSelectProps) => {\n return (\n <Select.Root value={''} onValueChange={onTemplateSelect}>\n <Select.TriggerButton />\n <Select.Portal>\n <Select.Content>\n <Select.Viewport>\n <Select.Option value={''}>Template</Select.Option>\n {templates.map(({ id, name }) => (\n <Select.Option key={id} value={id}>\n {name}\n </Select.Option>\n ))}\n </Select.Viewport>\n </Select.Content>\n </Select.Portal>\n </Select.Root>\n );\n};\n\nexport type ViewSelectorProps = {\n view?: ViewType;\n onViewChange?: (view: ViewType) => void;\n};\n\nexport const ViewSelector = ({ view, onViewChange }: ViewSelectorProps) => {\n return (\n <ToggleGroup type='single' value={view} onValueChange={(value) => onViewChange?.(value as ViewType)}>\n <ToggleGroupItem value='editor' classNames='bg-transparent text-subdued'>\n <Icon icon='ph--code--regular' size={4} />\n </ToggleGroupItem>\n <ToggleGroupItem value='split' classNames='bg-transparent text-subdued'>\n <Icon icon='ph--square-split-vertical--regular' size={4} />\n </ToggleGroupItem>\n <ToggleGroupItem value='preview' classNames='bg-transparent text-subdued'>\n <Icon icon='ph--eye--regular' size={4} />\n </ToggleGroupItem>\n </ToggleGroup>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { javascript } from '@codemirror/lang-javascript';\nimport { type VirtualTypeScriptEnvironment } from '@typescript/vfs';\nimport { tsSync, tsFacet, tsLinter, tsAutocomplete, tsHover } from '@valtown/codemirror-ts';\nimport React from 'react';\n\nimport { useThemeContext } from '@dxos/react-ui';\nimport {\n autocomplete,\n createBasicExtensions,\n createThemeExtensions,\n editorFullWidth,\n editorGutter,\n editorMonospace,\n InputModeExtensions,\n useTextEditor,\n type UseTextEditorProps,\n} from '@dxos/react-ui-editor';\nimport { nonNullable } from '@dxos/util';\n\nexport type TypescriptEditorProps = {\n id: string;\n env?: VirtualTypeScriptEnvironment;\n} & Pick<UseTextEditorProps, 'className' | 'initialValue' | 'extensions' | 'scrollTo' | 'selection'>;\n\nexport const TypescriptEditor = ({\n id,\n env,\n className,\n initialValue,\n extensions,\n scrollTo,\n selection,\n}: TypescriptEditorProps) => {\n const { themeMode } = useThemeContext();\n const { parentRef, focusAttributes } = useTextEditor(\n () => ({\n id,\n initialValue,\n extensions: [\n extensions,\n createBasicExtensions({\n highlightActiveLine: true,\n indentWithTab: true,\n lineNumbers: true,\n lineWrapping: false,\n scrollPastEnd: true,\n }),\n createThemeExtensions({\n themeMode,\n syntaxHighlighting: true,\n slots: {\n content: { className: editorFullWidth },\n },\n }),\n editorGutter,\n // TODO(burdon): Factor out.\n [\n editorMonospace,\n javascript({ typescript: true }),\n // https://github.com/val-town/codemirror-ts\n autocomplete({ override: env ? [tsAutocomplete()] : [] }),\n env ? [tsFacet.of({ env, path: `/src/${id}.ts` }), tsSync(), tsLinter(), tsHover()] : [],\n InputModeExtensions.vscode,\n ],\n ].filter(nonNullable),\n selection,\n scrollTo,\n }),\n [id, extensions, themeMode, selection, scrollTo],\n );\n\n return <div ref={parentRef} className={className} {...focusAttributes} />;\n};\n\nexport default TypescriptEditor;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAIA,OAAOA,YAAW;AAElB,SAASC,wBAAwB;AACjC,SAASC,+BAA+B;AACxC,SAASC,MAAAA,WAAU;;;ACJnB,SAASC,cAAc;AACvB,OAAOC,0BAA0B;AACjC,OAAOC,8BAA8B;AACrC,OAAOC,UAASC,aAAaC,SAASC,YAAAA,iBAAgB;AAEtD,SAASC,WAAW;AACpB,SAASC,iBAAiB;AAC1B,SAASC,QAAQC,mBAAmBC,QAAQC,SAASC,UAAUC,gBAAgB;AAC/E,SAASC,mBAAmB;AAC5B,SAASC,kBAAAA,uBAA4C;AACrD,SAASC,sBAAsBC,gBAAgB;AAC/C,SAASC,UAAU;;;ACXnB,OAAOC,SAASC,gBAAgB;AAEhC,SACEC,mBACAC,MACAC,QAEAC,aACAC,iBAEAC,WAAWC,gBACXC,SACAC,sBACK;AAgBA,IAAMC,UAAU,CAAC,EACtBC,YACAC,UACAC,OACAC,aACAC,MACAC,WAAAA,YACAC,UACAC,UACAC,cACAC,iBAAgB,MACH;AACb,QAAM,EAAEC,EAAC,IAAKC,eAAeC,aAAAA;AAC7B,QAAM,CAACC,SAASC,UAAAA,IAAcC,SAAS,KAAA;AAEvC,QAAMC,iBAAiB,YAAA;AACrB,QAAI,CAACb,aAAa;AAChB;IACF;AAEA,UAAMc,UAAUC,UAAUC,UAAUhB,WAAAA;EACtC;AAEA,QAAMiB,eAAe,YAAA;AACnB,QAAI,CAACP,SAAS;AACZC,iBAAW,IAAA;AACX,YAAMR,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QAAMC,kBAAkBC,wBAAwBC,iBAAiBJ,MAAAA,CAAAA;AACjE,SACE,gBAAAK,OAAA,cAACC,OAAAA;IAAIC,MAAK;IAAOC,WAAWC,IAAG,0DAAA;IAA8D,GAAGP;KAC9F,gBAAAG,OAAA,cAACK,cAAAA;IAAc,GAAGT;IAAOD;;AAG/B;AAEA,IAAA,0BAAeD;",
|
|
6
|
+
"names": ["React", "fullyQualifiedId", "useAttendableAttributes", "mx", "format", "prettierPluginEstree", "prettierPluginTypescript", "React", "useCallback", "useMemo", "useState", "log", "useClient", "create", "createDocAccessor", "Filter", "getMeta", "getSpace", "useQuery", "useIdentity", "useTranslation", "createDataExtensions", "listener", "mx", "React", "useState", "ElevationProvider", "Icon", "Select", "ToggleGroup", "ToggleGroupItem", "Toolbar", "NaturalToolbar", "Tooltip", "useTranslation", "Toolbar", "classNames", "deployed", "error", "functionUrl", "view", "templates", "onDeploy", "onFormat", "onViewChange", "onTemplateSelect", "t", "useTranslation", "SCRIPT_PLUGIN", "pending", "setPending", "useState", "handleCopyLink", "navigator", "clipboard", "writeText", "handleDeploy", "ElevationProvider", "elevation", "NaturalToolbar", "Root", "style", "contain", "TemplateSelect", "ToolbarIconButton", "icon", "text", "onClick", "div", "role", "className", "Tooltip", "Trigger", "Icon", "size", "Portal", "Content", "Arrow", "ViewSelector", "disabled", "asChild", "Button", "variant", "Select", "value", "onValueChange", "TriggerButton", "Viewport", "Option", "map", "id", "name", "key", "ToggleGroup", "type", "ToggleGroupItem", "javascript", "tsSync", "tsFacet", "tsLinter", "tsAutocomplete", "tsHover", "React", "useThemeContext", "autocomplete", "createBasicExtensions", "createThemeExtensions", "editorFullWidth", "editorGutter", "editorMonospace", "InputModeExtensions", "useTextEditor", "nonNullable", "TypescriptEditor", "id", "env", "className", "initialValue", "extensions", "scrollTo", "selection", "themeMode", "useThemeContext", "parentRef", "focusAttributes", "useTextEditor", "createBasicExtensions", "highlightActiveLine", "indentWithTab", "lineNumbers", "lineWrapping", "scrollPastEnd", "createThemeExtensions", "syntaxHighlighting", "slots", "content", "editorFullWidth", "editorGutter", "editorMonospace", "javascript", "typescript", "autocomplete", "override", "tsAutocomplete", "tsFacet", "of", "path", "tsSync", "tsLinter", "tsHover", "InputModeExtensions", "vscode", "filter", "nonNullable", "React", "div", "ref", "ScriptEditor", "classNames", "script", "env", "t", "useTranslation", "SCRIPT_PLUGIN", "client", "useClient", "identity", "useIdentity", "space", "getSpace", "fn", "useQuery", "Filter", "schema", "FunctionType", "source", "extensions", "useMemo", "listener", "onChange", "text", "content", "changed", "createDataExtensions", "id", "createDocAccessor", "view", "setView", "useState", "existingFunctionUrl", "getUserFunctionUrlInMetadata", "getMeta", "error", "setError", "handleFormat", "useCallback", "format", "parser", "plugins", "prettierPluginEstree", "prettierPluginTypescript", "semi", "singleQuote", "err", "log", "catch", "handleTemplateChange", "template", "templates", "find", "name", "metaKeys", "keys", "oldPresetIndex", "findIndex", "key", "FUNCTIONS_PRESET_META_KEY", "splice", "presetId", "push", "handleDeploy", "undefined", "existingFunctionId", "split", "at", "bundler", "Bundler", "platform", "sandboxedModules", "remoteModules", "buildResult", "bundle", "functionId", "version", "meta", "uploadWorkerFunction", "spaceId", "incrementSemverPatch", "Error", "info", "deployedFunction", "db", "add", "create", "inputSchema", "verbose", "setUserFunctionUrlInMetadata", "functionUrl", "getInvocationUrl", "config", "values", "runtime", "services", "edge", "url", "React", "div", "role", "className", "mx", "Toolbar", "deployed", "Boolean", "onDeploy", "onFormat", "onViewChange", "onTemplateSelect", "TypescriptEditor", "initialValue", "DebugPanel", "ScriptContainer", "script", "props", "attendableAttrs", "useAttendableAttributes", "fullyQualifiedId", "React", "div", "role", "className", "mx", "ScriptEditor"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// packages/plugins/experimental/plugin-script/src/edge/functions.ts
|
|
4
|
+
import { EdgeHttpClient } from "@dxos/edge-client";
|
|
5
|
+
import { invariant } from "@dxos/invariant";
|
|
6
|
+
import { log } from "@dxos/log";
|
|
7
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-script/src/edge/functions.ts";
|
|
8
|
+
var FUNCTIONS_META_KEY = "dxos.org/service/function";
|
|
9
|
+
var FUNCTIONS_PRESET_META_KEY = "dxos.org/service/function-preset";
|
|
10
|
+
var uploadWorkerFunction = async ({ client, name, version, source, spaceId, functionId }) => {
|
|
11
|
+
const edgeUrl = client.config.values.runtime?.services?.edge?.url;
|
|
12
|
+
invariant(edgeUrl, "Edge is not configured.", {
|
|
13
|
+
F: __dxlog_file,
|
|
14
|
+
L: 38,
|
|
15
|
+
S: void 0,
|
|
16
|
+
A: [
|
|
17
|
+
"edgeUrl",
|
|
18
|
+
"'Edge is not configured.'"
|
|
19
|
+
]
|
|
20
|
+
});
|
|
21
|
+
const edgeClient = new EdgeHttpClient(edgeUrl);
|
|
22
|
+
const edgeIdentity = createEdgeIdentity(client);
|
|
23
|
+
edgeClient.setIdentity(edgeIdentity);
|
|
24
|
+
const response = await edgeClient.uploadFunction({
|
|
25
|
+
spaceId,
|
|
26
|
+
functionId
|
|
27
|
+
}, {
|
|
28
|
+
name,
|
|
29
|
+
version,
|
|
30
|
+
script: source
|
|
31
|
+
});
|
|
32
|
+
log("Uploaded", {
|
|
33
|
+
functionId,
|
|
34
|
+
source,
|
|
35
|
+
name,
|
|
36
|
+
identityKey: edgeIdentity.identityKey,
|
|
37
|
+
response
|
|
38
|
+
}, {
|
|
39
|
+
F: __dxlog_file,
|
|
40
|
+
L: 44,
|
|
41
|
+
S: void 0,
|
|
42
|
+
C: (f, a) => f(...a)
|
|
43
|
+
});
|
|
44
|
+
return response;
|
|
45
|
+
};
|
|
46
|
+
var getUserFunctionUrlInMetadata = (meta) => {
|
|
47
|
+
return meta.keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;
|
|
48
|
+
};
|
|
49
|
+
var setUserFunctionUrlInMetadata = (meta, functionUrl) => {
|
|
50
|
+
const key = meta.keys.find((key2) => key2.source === FUNCTIONS_META_KEY);
|
|
51
|
+
if (key) {
|
|
52
|
+
if (key.id !== functionUrl) {
|
|
53
|
+
throw new Error("Metadata mismatch");
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
meta.keys.push({
|
|
57
|
+
source: FUNCTIONS_META_KEY,
|
|
58
|
+
id: functionUrl
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var getInvocationUrl = (functionUrl, edgeUrl, options = {}) => {
|
|
63
|
+
const baseUrl = new URL("functions/", edgeUrl);
|
|
64
|
+
const relativeUrl = functionUrl.replace(/^\//, "");
|
|
65
|
+
const url = new URL(`./${relativeUrl}`, baseUrl.toString());
|
|
66
|
+
options.spaceId && url.searchParams.set("spaceId", options.spaceId);
|
|
67
|
+
options.subjectId && url.searchParams.set("subjectId", options.subjectId);
|
|
68
|
+
url.protocol = "https";
|
|
69
|
+
return url.toString();
|
|
70
|
+
};
|
|
71
|
+
var createEdgeIdentity = (client) => {
|
|
72
|
+
const identity = client.halo.identity.get();
|
|
73
|
+
const device = client.halo.device;
|
|
74
|
+
if (!identity || !device) {
|
|
75
|
+
throw new Error("Identity not available");
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
identityKey: identity.identityKey.toHex(),
|
|
79
|
+
peerKey: device.deviceKey.toHex(),
|
|
80
|
+
presentCredentials: async ({ challenge }) => {
|
|
81
|
+
const identityService = client.services.services.IdentityService;
|
|
82
|
+
const authCredential = await identityService.createAuthCredential();
|
|
83
|
+
return identityService.signPresentation({
|
|
84
|
+
presentation: {
|
|
85
|
+
credentials: [
|
|
86
|
+
authCredential
|
|
87
|
+
]
|
|
88
|
+
},
|
|
89
|
+
nonce: challenge
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
var incrementSemverPatch = (version) => {
|
|
95
|
+
const [major, minor, patch] = version.split(".");
|
|
96
|
+
const patchNum = Number(patch);
|
|
97
|
+
invariant(!Number.isNaN(patchNum), "Unexpected function version format.", {
|
|
98
|
+
F: __dxlog_file,
|
|
99
|
+
L: 105,
|
|
100
|
+
S: void 0,
|
|
101
|
+
A: [
|
|
102
|
+
"!Number.isNaN(patchNum)",
|
|
103
|
+
"'Unexpected function version format.'"
|
|
104
|
+
]
|
|
105
|
+
});
|
|
106
|
+
return [
|
|
107
|
+
major,
|
|
108
|
+
minor,
|
|
109
|
+
String(patchNum + 1)
|
|
110
|
+
].join(".");
|
|
111
|
+
};
|
|
112
|
+
var publicKeyToDid = (key) => {
|
|
113
|
+
return `did:key:${key.toHex()}`;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export {
|
|
117
|
+
FUNCTIONS_PRESET_META_KEY,
|
|
118
|
+
uploadWorkerFunction,
|
|
119
|
+
getUserFunctionUrlInMetadata,
|
|
120
|
+
setUserFunctionUrlInMetadata,
|
|
121
|
+
getInvocationUrl,
|
|
122
|
+
incrementSemverPatch,
|
|
123
|
+
publicKeyToDid
|
|
124
|
+
};
|
|
125
|
+
//# sourceMappingURL=chunk-36DLLQ6E.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/edge/functions.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { type DID } from 'iso-did/types';\n\nimport { type Client } from '@dxos/client';\nimport { type ObjectMeta } from '@dxos/echo-schema';\nimport { EdgeHttpClient, type EdgeIdentity } from '@dxos/edge-client';\nimport { invariant } from '@dxos/invariant';\nimport type { PublicKey, SpaceId } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type UploadFunctionResponseBody } from '@dxos/protocols';\n\n// TODO: use URL scheme for source?\nconst FUNCTIONS_META_KEY = 'dxos.org/service/function';\n\nexport const FUNCTIONS_PRESET_META_KEY = 'dxos.org/service/function-preset';\n\nexport type UploadWorkerArgs = {\n client: Client;\n name?: string;\n source: string;\n version: string;\n functionId?: string;\n spaceId: SpaceId;\n};\n\nexport const uploadWorkerFunction = async ({\n client,\n name,\n version,\n source,\n spaceId,\n functionId,\n}: UploadWorkerArgs): Promise<UploadFunctionResponseBody> => {\n const edgeUrl = client.config.values.runtime?.services?.edge?.url;\n invariant(edgeUrl, 'Edge is not configured.');\n const edgeClient = new EdgeHttpClient(edgeUrl);\n const edgeIdentity = createEdgeIdentity(client);\n edgeClient.setIdentity(edgeIdentity);\n const response = await edgeClient.uploadFunction({ spaceId, functionId }, { name, version, script: source });\n\n log('Uploaded', {\n functionId,\n source,\n name,\n identityKey: edgeIdentity.identityKey,\n response,\n });\n\n return response;\n};\n\nexport const getUserFunctionUrlInMetadata = (meta: ObjectMeta) => {\n return meta.keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;\n};\n\nexport const setUserFunctionUrlInMetadata = (meta: ObjectMeta, functionUrl: string) => {\n const key = meta.keys.find((key) => key.source === FUNCTIONS_META_KEY);\n if (key) {\n if (key.id !== functionUrl) {\n throw new Error('Metadata mismatch');\n }\n } else {\n meta.keys.push({ source: FUNCTIONS_META_KEY, id: functionUrl });\n }\n};\n\nexport const getInvocationUrl = (functionUrl: string, edgeUrl: string, options: InvocationOptions = {}) => {\n const baseUrl = new URL('functions/', edgeUrl);\n\n // Leading slashes cause the URL to be treated as an absolute path.\n const relativeUrl = functionUrl.replace(/^\\//, '');\n const url = new URL(`./${relativeUrl}`, baseUrl.toString());\n options.spaceId && url.searchParams.set('spaceId', options.spaceId);\n options.subjectId && url.searchParams.set('subjectId', options.subjectId);\n url.protocol = 'https';\n return url.toString();\n};\n\nconst createEdgeIdentity = (client: Client): EdgeIdentity => {\n const identity = client.halo.identity.get();\n const device = client.halo.device;\n if (!identity || !device) {\n throw new Error('Identity not available');\n }\n return {\n identityKey: identity.identityKey.toHex(),\n peerKey: device.deviceKey.toHex(),\n presentCredentials: async ({ challenge }) => {\n const identityService = client.services.services.IdentityService!;\n const authCredential = await identityService.createAuthCredential();\n return identityService.signPresentation({\n presentation: { credentials: [authCredential] },\n nonce: challenge,\n });\n },\n };\n};\n\nexport const incrementSemverPatch = (version: string): string => {\n const [major, minor, patch] = version.split('.');\n const patchNum = Number(patch);\n invariant(!Number.isNaN(patchNum), 'Unexpected function version format.');\n return [major, minor, String(patchNum + 1)].join('.');\n};\n\nexport const publicKeyToDid = (key: PublicKey): DID => {\n return `did:key:${key.toHex()}`;\n};\n\nexport type InvocationOptions = {\n spaceId?: SpaceId;\n subjectId?: string;\n};\n"],
|
|
5
|
+
"mappings": ";;;AAQA,SAASA,sBAAyC;AAClD,SAASC,iBAAiB;AAE1B,SAASC,WAAW;;AAIpB,IAAMC,qBAAqB;AAEpB,IAAMC,4BAA4B;AAWlC,IAAMC,uBAAuB,OAAO,EACzCC,QACAC,MACAC,SACAC,QACAC,SACAC,WAAU,MACO;AACjB,QAAMC,UAAUN,OAAOO,OAAOC,OAAOC,SAASC,UAAUC,MAAMC;AAC9DjB,YAAUW,SAAS,2BAAA;;;;;;;;;AACnB,QAAMO,aAAa,IAAInB,eAAeY,OAAAA;AACtC,QAAMQ,eAAeC,mBAAmBf,MAAAA;AACxCa,aAAWG,YAAYF,YAAAA;AACvB,QAAMG,WAAW,MAAMJ,WAAWK,eAAe;IAAEd;IAASC;EAAW,GAAG;IAAEJ;IAAMC;IAASiB,QAAQhB;EAAO,CAAA;AAE1GP,MAAI,YAAY;IACdS;IACAF;IACAF;IACAmB,aAAaN,aAAaM;IAC1BH;EACF,GAAA;;;;;;AAEA,SAAOA;AACT;AAEO,IAAMI,+BAA+B,CAACC,SAAAA;AAC3C,SAAOA,KAAKC,KAAKC,KAAK,CAACC,QAAQA,IAAItB,WAAWN,kBAAAA,GAAqB6B;AACrE;AAEO,IAAMC,+BAA+B,CAACL,MAAkBM,gBAAAA;AAC7D,QAAMH,MAAMH,KAAKC,KAAKC,KAAK,CAAC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QAAM,CAAC0D,OAAOC,OAAOC,KAAAA,IAAS5D,QAAQ6D,MAAM,GAAA;AAC5C,QAAMC,WAAWC,OAAOH,KAAAA;AACxBnE,YAAU,CAACsE,OAAOC,MAAMF,QAAAA,GAAW,uCAAA;;;;;;;;;AACnC,SAAO;IAACJ;IAAOC;IAAOM,OAAOH,WAAW,CAAA;IAAII,KAAK,GAAA;AACnD;AAEO,IAAMC,iBAAiB,CAAC5C,QAAAA;AAC7B,SAAO,WAAWA,IAAIqB,MAAK,CAAA;AAC7B;",
|
|
6
|
+
"names": ["EdgeHttpClient", "invariant", "log", "FUNCTIONS_META_KEY", "FUNCTIONS_PRESET_META_KEY", "uploadWorkerFunction", "client", "name", "version", "source", "spaceId", "functionId", "edgeUrl", "config", "values", "runtime", "services", "edge", "url", "edgeClient", "edgeIdentity", "createEdgeIdentity", "setIdentity", "response", "uploadFunction", "script", "identityKey", "getUserFunctionUrlInMetadata", "meta", "keys", "find", "key", "id", "setUserFunctionUrlInMetadata", "functionUrl", "Error", "push", "getInvocationUrl", "options", "baseUrl", "URL", "relativeUrl", "replace", "toString", "searchParams", "set", "subjectId", "protocol", "identity", "halo", "get", "device", "toHex", "peerKey", "deviceKey", "presentCredentials", "challenge", "identityService", "IdentityService", "authCredential", "createAuthCredential", "signPresentation", "presentation", "credentials", "nonce", "incrementSemverPatch", "major", "minor", "patch", "split", "patchNum", "Number", "isNaN", "String", "join", "publicKeyToDid"]
|
|
7
|
+
}
|
|
@@ -25,7 +25,7 @@ var FunctionType = class extends TypedObject({
|
|
|
25
25
|
})({
|
|
26
26
|
// TODO(burdon): Rename to id/uri?
|
|
27
27
|
name: S.NonEmptyString,
|
|
28
|
-
version: S.
|
|
28
|
+
version: S.String,
|
|
29
29
|
// Reference to a source script if it exists within ECHO.
|
|
30
30
|
// TODO(burdon): Don't ref ScriptType directly (core).
|
|
31
31
|
source: S.optional(ref(ScriptType)),
|
|
@@ -46,4 +46,4 @@ export {
|
|
|
46
46
|
FunctionType,
|
|
47
47
|
ScriptAction
|
|
48
48
|
};
|
|
49
|
-
//# sourceMappingURL=chunk-
|
|
49
|
+
//# sourceMappingURL=chunk-GMVPKT6A.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/types/schema.ts", "../../../src/types/types.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { JsonSchemaType, ref, S, TypedObject } from '@dxos/echo-schema';\nimport { TextType } from '@dxos/plugin-markdown/types';\n\n/**\n * Source script.\n */\nexport class ScriptType extends TypedObject({\n typename: 'dxos.org/type/Script',\n version: '0.1.0',\n})({\n // TODO(burdon): Change to URI?\n name: S.optional(S.String),\n description: S.optional(S.String),\n // TODO(burdon): Change to hash of deployed content.\n // Whether source has changed since last deploy.\n changed: S.optional(S.Boolean),\n source: ref(TextType),\n}) {}\n\n/**\n * Function deployment.\n */\n// TODO(burdon): Move to core/functions.\nexport class FunctionType extends TypedObject({\n typename: 'dxos.org/type/Function',\n version: '0.1.0',\n})({\n // TODO(burdon): Rename to id/uri?\n name: S.NonEmptyString,\n version: S.
|
|
5
|
-
"mappings": ";;;;;;AAIA,SAASA,gBAAgBC,KAAKC,GAAGC,mBAAmB;AACpD,SAASC,gBAAgB;AAKlB,IAAMC,aAAN,cAAyBC,YAAY;EAC1CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;;EAEDC,MAAMC,EAAEC,SAASD,EAAEE,MAAM;EACzBC,aAAaH,EAAEC,SAASD,EAAEE,MAAM;;;EAGhCE,SAASJ,EAAEC,SAASD,EAAEK,OAAO;EAC7BC,QAAQC,IAAIC,QAAAA;AACd,CAAA,EAAA;AAAI;AAMG,IAAMC,eAAN,cAA2Bb,YAAY;EAC5CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;;EAEDC,MAAMC,EAAEU;EACRZ,SAASE,
|
|
6
|
-
"names": ["JsonSchemaType", "ref", "S", "TypedObject", "TextType", "ScriptType", "TypedObject", "typename", "version", "name", "S", "optional", "String", "description", "changed", "Boolean", "source", "ref", "TextType", "FunctionType", "NonEmptyString", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { JsonSchemaType, ref, S, TypedObject } from '@dxos/echo-schema';\nimport { TextType } from '@dxos/plugin-markdown/types';\n\n/**\n * Source script.\n */\nexport class ScriptType extends TypedObject({\n typename: 'dxos.org/type/Script',\n version: '0.1.0',\n})({\n // TODO(burdon): Change to URI?\n name: S.optional(S.String),\n description: S.optional(S.String),\n // TODO(burdon): Change to hash of deployed content.\n // Whether source has changed since last deploy.\n changed: S.optional(S.Boolean),\n source: ref(TextType),\n}) {}\n\n/**\n * Function deployment.\n */\n// TODO(burdon): Move to core/functions.\nexport class FunctionType extends TypedObject({\n typename: 'dxos.org/type/Function',\n version: '0.1.0',\n})({\n // TODO(burdon): Rename to id/uri?\n name: S.NonEmptyString,\n version: S.String,\n\n // Reference to a source script if it exists within ECHO.\n // TODO(burdon): Don't ref ScriptType directly (core).\n source: S.optional(ref(ScriptType)),\n\n inputSchema: S.optional(JsonSchemaType),\n\n // Local binding to a function name.\n binding: S.optional(S.String),\n}) {}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport type {\n GraphBuilderProvides,\n IntentResolverProvides,\n MetadataRecordsProvides,\n SettingsProvides,\n SurfaceProvides,\n TranslationsProvides,\n} from '@dxos/app-framework';\nimport { type SchemaProvides } from '@dxos/plugin-space';\n\nimport { SCRIPT_PLUGIN } from '../meta';\n\nexport enum ScriptAction {\n CREATE = `${SCRIPT_PLUGIN}/create`,\n}\n\nexport type ScriptSettingsProps = {};\n\nexport type ScriptPluginProvides = GraphBuilderProvides &\n IntentResolverProvides &\n MetadataRecordsProvides &\n SchemaProvides &\n SettingsProvides<ScriptSettingsProps> &\n SurfaceProvides &\n TranslationsProvides;\n"],
|
|
5
|
+
"mappings": ";;;;;;AAIA,SAASA,gBAAgBC,KAAKC,GAAGC,mBAAmB;AACpD,SAASC,gBAAgB;AAKlB,IAAMC,aAAN,cAAyBC,YAAY;EAC1CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;;EAEDC,MAAMC,EAAEC,SAASD,EAAEE,MAAM;EACzBC,aAAaH,EAAEC,SAASD,EAAEE,MAAM;;;EAGhCE,SAASJ,EAAEC,SAASD,EAAEK,OAAO;EAC7BC,QAAQC,IAAIC,QAAAA;AACd,CAAA,EAAA;AAAI;AAMG,IAAMC,eAAN,cAA2Bb,YAAY;EAC5CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;;EAEDC,MAAMC,EAAEU;EACRZ,SAASE,EAAEE;;;EAIXI,QAAQN,EAAEC,SAASM,IAAIZ,UAAAA,CAAAA;EAEvBgB,aAAaX,EAAEC,SAASW,cAAAA;;EAGxBC,SAASb,EAAEC,SAASD,EAAEE,MAAM;AAC9B,CAAA,EAAA;AAAI;;;;UC3BQY,eAAAA;0CACD,GAAGC,aAAAA,SAAsB,IAAA;GADxBD,iBAAAA,eAAAA,CAAAA,EAAAA;",
|
|
6
|
+
"names": ["JsonSchemaType", "ref", "S", "TypedObject", "TextType", "ScriptType", "TypedObject", "typename", "version", "name", "S", "optional", "String", "description", "changed", "Boolean", "source", "ref", "TextType", "FunctionType", "NonEmptyString", "inputSchema", "JsonSchemaType", "binding", "ScriptAction", "SCRIPT_PLUGIN"]
|
|
7
7
|
}
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "./chunk-SLTZMY34.mjs";
|
|
5
5
|
|
|
6
6
|
// packages/plugins/experimental/plugin-script/src/components/DebugPanel/DebugPanel.tsx
|
|
7
|
-
import React, { useEffect, useRef, useState } from "react";
|
|
7
|
+
import React, { forwardRef, useEffect, useRef, useState } from "react";
|
|
8
8
|
import { log } from "@dxos/log";
|
|
9
9
|
import { Avatar, Icon, Input, Toolbar, useTranslation } from "@dxos/react-ui";
|
|
10
10
|
import { SyntaxHighlighter } from "@dxos/react-ui-syntax-highlighter";
|
|
@@ -151,15 +151,13 @@ var DebugPanel = ({ classNames, functionUrl }) => {
|
|
|
151
151
|
};
|
|
152
152
|
return /* @__PURE__ */ React.createElement("div", {
|
|
153
153
|
className: mx("flex flex-col h-full overflow-hidden", classNames)
|
|
154
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
155
|
-
ref: scrollerRef,
|
|
156
|
-
className: "flex flex-col gap-6 h-full p-2 overflow-x-hidden overflow-y-auto"
|
|
157
154
|
}, /* @__PURE__ */ React.createElement(MessageThread, {
|
|
155
|
+
ref: scrollerRef,
|
|
158
156
|
state,
|
|
159
157
|
result,
|
|
160
158
|
history
|
|
161
|
-
})
|
|
162
|
-
classNames: "p-
|
|
159
|
+
}), /* @__PURE__ */ React.createElement(Toolbar.Root, {
|
|
160
|
+
classNames: "p-1"
|
|
163
161
|
}, /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement(Input.TextInput, {
|
|
164
162
|
ref: inputRef,
|
|
165
163
|
autoFocus: true,
|
|
@@ -179,8 +177,14 @@ var DebugPanel = ({ classNames, functionUrl }) => {
|
|
|
179
177
|
size: 4
|
|
180
178
|
}))));
|
|
181
179
|
};
|
|
182
|
-
var MessageThread = ({ state,
|
|
183
|
-
|
|
180
|
+
var MessageThread = /* @__PURE__ */ forwardRef(({ state, history, result }, forwardedRef) => {
|
|
181
|
+
if (!history.length && !result.length) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
185
|
+
ref: forwardedRef,
|
|
186
|
+
className: "flex flex-col gap-6 h-full p-2 overflow-x-hidden overflow-y-auto"
|
|
187
|
+
}, history.map((message, i) => /* @__PURE__ */ React.createElement("div", {
|
|
184
188
|
key: i,
|
|
185
189
|
className: "grid grid-cols-[2rem_1fr_2rem]"
|
|
186
190
|
}, /* @__PURE__ */ React.createElement("div", {
|
|
@@ -209,7 +213,7 @@ var MessageThread = ({ state, result, history }) => {
|
|
|
209
213
|
text: result
|
|
210
214
|
}
|
|
211
215
|
}))));
|
|
212
|
-
};
|
|
216
|
+
});
|
|
213
217
|
var MessageItem = ({ classNames, message }) => {
|
|
214
218
|
const { type, text, data, error } = message;
|
|
215
219
|
const wrapper = "p-1 px-2 rounded-lg bg-hoverSurface overflow-auto";
|
|
@@ -234,4 +238,4 @@ var RobotAvatar = () => /* @__PURE__ */ React.createElement(Avatar.Root, {
|
|
|
234
238
|
export {
|
|
235
239
|
DebugPanel
|
|
236
240
|
};
|
|
237
|
-
//# sourceMappingURL=chunk-
|
|
241
|
+
//# sourceMappingURL=chunk-OFYGBUNI.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/DebugPanel/DebugPanel.tsx"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { forwardRef, useEffect, useRef, useState } from 'react';\n\nimport { log } from '@dxos/log';\nimport { Avatar, Icon, Input, type ThemedClassName, Toolbar, useTranslation } 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}>;\n\nexport const DebugPanel = ({ classNames, functionUrl }: DebugPanelProps) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\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 -- at least for session (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 <div className={mx('flex flex-col h-full overflow-hidden', classNames)}>\n {/* TODO(burdon): Replace with Thread. */}\n <MessageThread ref={scrollerRef} state={state} result={result} history={history} />\n\n <Toolbar.Root classNames='p-1'>\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 <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 );\n};\n\n// TODO(burdon): Replace with thread?\n// TODO(burdon): Button to delete individual messages.\n// TODO(burdon): Button to edit/re-run question.\ntype MessageThreadProps = {\n state: State | null;\n history: Message[];\n result: string;\n};\n\nconst MessageThread = forwardRef<HTMLDivElement, MessageThreadProps>(\n ({ state, history, result }: MessageThreadProps, forwardedRef) => {\n if (!history.length && !result.length) {\n return null;\n }\n\n return (\n <div ref={forwardedRef} className='flex flex-col gap-6 h-full p-2 overflow-x-hidden overflow-y-auto'>\n {history.map((message, i) => (\n <div key={i} className='grid grid-cols-[2rem_1fr_2rem]'>\n <div className='p-1'>{message.type === 'response' && <RobotAvatar />}</div>\n <div className='overflow-auto'>\n <MessageItem message={message} />\n </div>\n </div>\n ))}\n\n {result?.length > 0 && (\n <div className='grid grid-cols-[2rem_1fr_2rem]'>\n <div className='p-1'>\n {(state === 'pending' && <Icon icon='ph--spinner--regular' size={6} classNames='animate-spin' />) || (\n <Icon icon='ph--robot--regular' size={6} classNames='animate-[pulse_1s_ease-in-out_infinite]' />\n )}\n </div>\n <div className='overflow-auto'>\n <MessageItem message={{ type: 'response', text: result }} />\n </div>\n </div>\n )}\n </div>\n );\n },\n);\n\nconst MessageItem = ({ classNames, message }: ThemedClassName<{ message: Message }>) => {\n const { type, text, data, error } = message;\n const wrapper = 'p-1 px-2 rounded-lg bg-hoverSurface overflow-auto';\n return (\n <div className={mx('flex', type === 'request' ? 'ml-[1rem] justify-end' : 'mr-[1rem]', classNames)}>\n {error && <div className={mx(wrapper, 'whitespace-pre text-error')}>{String(error)}</div>}\n\n {text !== undefined && (\n <div className={mx(wrapper, type === 'request' && 'bg-primary-400 dark:bg-primary-600')}>\n {text || '\\u00D8'}\n </div>\n )}\n\n {data && (\n <SyntaxHighlighter language='json' className={mx(wrapper, 'px-8 py-2 text-xs')}>\n {JSON.stringify(data, null, 2)}\n </SyntaxHighlighter>\n )}\n </div>\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"],
|
|
5
|
+
"mappings": ";;;;;;AAIA,OAAOA,SAASC,YAAYC,WAAWC,QAAQC,gBAAgB;AAE/D,SAASC,WAAW;AACpB,SAASC,QAAQC,MAAMC,OAA6BC,SAASC,sBAAsB;AACnF,SAASC,yBAAyB;AAClC,SAASC,UAAU;;AAeZ,IAAMC,aAAa,CAAC,EAAEC,YAAYC,YAAW,MAAmB;AACrE,QAAM,EAAEC,EAAC,IAAKC,eAAeC,aAAAA;AAE7B,QAAMC,WAAWC,OAAyB,IAAA;AAC1C,QAAM,CAACC,OAAOC,QAAAA,IAAYC,SAAS,EAAA;AACnC,QAAM,CAACC,QAAQC,SAAAA,IAAaF,SAAS,EAAA;AACrC,QAAM,CAACG,OAAOC,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AA,CAAA,CAAA;AAKtC;AAEA,IAAMkE,cAAc,MAClB,sBAAA,cAACK,OAAO1B,MAAI;EAACc,MAAM;EAAGa,SAAQ;GAC5B,sBAAA,cAACD,OAAOE,OAAK,MACX,sBAAA,cAACF,OAAOd,MAAI;EAACC,MAAK;;",
|
|
6
|
+
"names": ["React", "forwardRef", "useEffect", "useRef", "useState", "log", "Avatar", "Icon", "Input", "Toolbar", "useTranslation", "SyntaxHighlighter", "mx", "DebugPanel", "classNames", "functionUrl", "t", "useTranslation", "SCRIPT_PLUGIN", "inputRef", "useRef", "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", "div", "className", "mx", "MessageThread", "ref", "Toolbar", "Root", "Input", "TextInput", "autoFocus", "placeholder", "onChange", "ev", "target", "onKeyDown", "key", "Button", "onClick", "Icon", "icon", "size", "forwardRef", "forwardedRef", "length", "map", "message", "i", "RobotAvatar", "MessageItem", "wrapper", "SyntaxHighlighter", "language", "Avatar", "variant", "Frame"]
|
|
7
|
+
}
|
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
USERFUNCTIONS_PRESET_META_KEY,
|
|
5
|
-
codec,
|
|
3
|
+
FUNCTIONS_PRESET_META_KEY,
|
|
6
4
|
getInvocationUrl,
|
|
7
5
|
getUserFunctionUrlInMetadata,
|
|
8
|
-
|
|
6
|
+
incrementSemverPatch,
|
|
9
7
|
publicKeyToDid,
|
|
10
8
|
setUserFunctionUrlInMetadata,
|
|
11
9
|
uploadWorkerFunction
|
|
12
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-36DLLQ6E.mjs";
|
|
13
11
|
export {
|
|
14
|
-
|
|
15
|
-
USERFUNCTIONS_PRESET_META_KEY,
|
|
16
|
-
codec,
|
|
12
|
+
FUNCTIONS_PRESET_META_KEY,
|
|
17
13
|
getInvocationUrl,
|
|
18
14
|
getUserFunctionUrlInMetadata,
|
|
19
|
-
|
|
15
|
+
incrementSemverPatch,
|
|
20
16
|
publicKeyToDid,
|
|
21
17
|
setUserFunctionUrlInMetadata,
|
|
22
18
|
uploadWorkerFunction
|