@dxos/plugin-script 0.6.10-main.e92b5eb → 0.6.10-staging.3cfcc89
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/README.md +45 -0
- package/dist/lib/browser/ScriptEditor-WNCGR5OU.mjs +452 -0
- package/dist/lib/browser/ScriptEditor-WNCGR5OU.mjs.map +7 -0
- package/dist/lib/browser/{TypescriptEditor-PIRIDDUS.mjs → TypescriptEditor-XTGRVCMY.mjs} +2 -2
- package/dist/lib/browser/{chunk-ISMNAD3P.mjs → chunk-DL5XQRQM.mjs} +13 -7
- package/dist/lib/browser/{chunk-ISMNAD3P.mjs.map → chunk-DL5XQRQM.mjs.map} +3 -3
- package/dist/lib/browser/{chunk-D4O723CR.mjs → chunk-DX5CSOBP.mjs} +22 -5
- package/dist/lib/browser/chunk-DX5CSOBP.mjs.map +7 -0
- package/dist/lib/browser/chunk-RHEZ5LUU.mjs +229 -0
- package/dist/lib/browser/chunk-RHEZ5LUU.mjs.map +7 -0
- package/dist/lib/browser/edge/index.mjs +1 -1
- package/dist/lib/browser/index.mjs +88 -195
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/ScriptEditor-RR7AVOQL.cjs +465 -0
- package/dist/lib/node/ScriptEditor-RR7AVOQL.cjs.map +7 -0
- package/dist/lib/node/{TypescriptEditor-OTWJUIWB.cjs → TypescriptEditor-CRONCQSI.cjs} +7 -7
- package/dist/lib/node/{TypescriptEditor-OTWJUIWB.cjs.map → TypescriptEditor-CRONCQSI.cjs.map} +2 -2
- package/dist/lib/node/chunk-4GTXIELQ.cjs +252 -0
- package/dist/lib/node/chunk-4GTXIELQ.cjs.map +7 -0
- package/dist/lib/node/{chunk-HN3AVLUL.cjs → chunk-PFH3ROEH.cjs} +16 -10
- package/dist/lib/node/{chunk-HN3AVLUL.cjs.map → chunk-PFH3ROEH.cjs.map} +3 -3
- package/dist/lib/node/{chunk-ITLHJMWP.cjs → chunk-RXI576K3.cjs} +24 -7
- package/dist/lib/node/chunk-RXI576K3.cjs.map +7 -0
- package/dist/lib/node/edge/index.cjs +8 -8
- package/dist/lib/node/edge/index.cjs.map +1 -1
- package/dist/lib/node/index.cjs +85 -194
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/ScriptPlugin.d.ts +1 -4
- package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
- package/dist/types/src/bundler/bundler.d.ts +39 -0
- package/dist/types/src/bundler/bundler.d.ts.map +1 -0
- package/dist/types/src/bundler/bundler.test.d.ts +2 -0
- package/dist/types/src/bundler/bundler.test.d.ts.map +1 -0
- package/dist/types/src/bundler/index.d.ts +2 -0
- package/dist/types/src/bundler/index.d.ts.map +1 -0
- package/dist/types/src/compiler/compiler.browser.test.d.ts +2 -0
- package/dist/types/src/compiler/compiler.browser.test.d.ts.map +1 -0
- package/dist/types/src/compiler/compiler.d.ts +9 -34
- package/dist/types/src/compiler/compiler.d.ts.map +1 -1
- package/dist/types/src/components/DetailsPanel.d.ts +9 -0
- package/dist/types/src/components/DetailsPanel.d.ts.map +1 -0
- package/dist/types/src/components/ScriptBlock/FrameContainer/FrameContainer.d.ts +2 -2
- package/dist/types/src/components/ScriptBlock/FrameContainer/FrameContainer.d.ts.map +1 -1
- package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts.map +1 -1
- package/dist/types/src/components/ScriptEditor.d.ts +3 -2
- package/dist/types/src/components/ScriptEditor.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar.d.ts +9 -7
- package/dist/types/src/components/Toolbar.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar.stories.d.ts +1 -1
- package/dist/types/src/components/TypescriptEditor.d.ts +3 -1
- package/dist/types/src/components/TypescriptEditor.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor.stories.d.ts +1 -1
- package/dist/types/src/components/index.d.ts +2 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/data/templates.md.d.ts +3 -0
- package/dist/types/src/data/templates.md.d.ts.map +1 -0
- package/dist/types/src/edge/functions.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +3 -2
- package/dist/types/src/translations.d.ts.map +1 -1
- package/package.json +38 -33
- package/src/ScriptPlugin.tsx +29 -10
- package/src/bundler/bundler.test.ts +44 -0
- package/src/bundler/bundler.ts +246 -0
- package/src/bundler/index.ts +5 -0
- package/src/compiler/compiler.browser.test.ts +18 -0
- package/src/compiler/compiler.ts +31 -190
- package/src/compiler/index.ts +1 -1
- package/src/components/DetailsPanel.tsx +218 -0
- package/src/components/ScriptBlock/FrameContainer/FrameContainer.tsx +2 -2
- package/src/components/ScriptBlock/ScriptBlock.tsx +10 -7
- package/src/components/ScriptEditor.tsx +71 -13
- package/src/components/Toolbar.tsx +69 -91
- package/src/components/TypescriptEditor.tsx +18 -4
- package/src/data/templates.md.ts +44 -0
- package/src/edge/functions.ts +9 -2
- package/src/index.ts +1 -0
- package/src/translations.ts +4 -3
- package/dist/lib/browser/ScriptEditor-MSQDR6D7.mjs +0 -241
- package/dist/lib/browser/ScriptEditor-MSQDR6D7.mjs.map +0 -7
- package/dist/lib/browser/chunk-D4O723CR.mjs.map +0 -7
- package/dist/lib/node/ScriptEditor-KBSACFYK.cjs +0 -258
- package/dist/lib/node/ScriptEditor-KBSACFYK.cjs.map +0 -7
- package/dist/lib/node/chunk-ITLHJMWP.cjs.map +0 -7
- package/dist/types/src/compiler/compiler.test.d.ts +0 -2
- package/dist/types/src/compiler/compiler.test.d.ts.map +0 -1
- package/src/compiler/compiler.test.ts +0 -17
- /package/dist/lib/browser/{TypescriptEditor-PIRIDDUS.mjs.map → TypescriptEditor-XTGRVCMY.mjs.map} +0 -0
package/README.md
CHANGED
|
@@ -2,3 +2,48 @@
|
|
|
2
2
|
|
|
3
3
|
Surface plugin for script editor.
|
|
4
4
|
|
|
5
|
+
Composer config:
|
|
6
|
+
|
|
7
|
+
```yml
|
|
8
|
+
# packages/app/composer-app/dx.local.yml
|
|
9
|
+
version: 1
|
|
10
|
+
runtime:
|
|
11
|
+
client:
|
|
12
|
+
edgeFeatures:
|
|
13
|
+
echoReplicator: true
|
|
14
|
+
services:
|
|
15
|
+
edge:
|
|
16
|
+
url: wss://edge.dxos.workers.dev/
|
|
17
|
+
agentHosting:
|
|
18
|
+
type: LOCAL_TESTING
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Test credentials:
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
await dxos.client.halo.writeCredentials([{
|
|
25
|
+
issuer: dxos.client.halo.identity.get().identityKey,
|
|
26
|
+
subject: {
|
|
27
|
+
id: dxos.client.halo.identity.get().identityKey,
|
|
28
|
+
assertion: {
|
|
29
|
+
'@type': 'dxos.halo.credentials.ServiceAccess',
|
|
30
|
+
serverName: 'hub.dxos.network',
|
|
31
|
+
serverKey: dxos.client.halo.identity.get().identityKey,
|
|
32
|
+
identityKey: dxos.client.halo.identity.get().identityKey,
|
|
33
|
+
capabilities: ['composer:beta']
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}])
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Start composer:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
DX_HUB_URL="https://hub-staging.dxos.workers.dev/" DX_ENVIRONMENT=test px serve composer-app
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Streaming request:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
curl -X POST -sN -d 'What is DXOS'
|
|
49
|
+
```
|
|
@@ -0,0 +1,452 @@
|
|
|
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-ZGCETT2W.mjs";
|
|
13
|
+
import {
|
|
14
|
+
SCRIPT_PLUGIN
|
|
15
|
+
} from "./chunk-JBACGDOJ.mjs";
|
|
16
|
+
import {
|
|
17
|
+
TypescriptEditor
|
|
18
|
+
} from "./chunk-DX5CSOBP.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, 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 { createDataExtensions, listener } from "@dxos/react-ui-editor";
|
|
31
|
+
import { mx as mx3 } from "@dxos/react-ui-theme";
|
|
32
|
+
|
|
33
|
+
// packages/plugins/experimental/plugin-script/src/components/DetailsPanel.tsx
|
|
34
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
35
|
+
import { log } from "@dxos/log";
|
|
36
|
+
import { Avatar, DensityProvider, Icon, Input, Toolbar, useControlledValue, useDynamicRef, useTranslation } from "@dxos/react-ui";
|
|
37
|
+
import { mx } from "@dxos/react-ui-theme";
|
|
38
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-script/src/components/DetailsPanel.tsx";
|
|
39
|
+
var DetailsPanel = ({ classNames, functionUrl, binding: _binding, onBindingChange }) => {
|
|
40
|
+
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
41
|
+
const bindingInputRef = useRef(null);
|
|
42
|
+
const [binding, setBinding] = useControlledValue(_binding ?? "");
|
|
43
|
+
const handleBlur = () => {
|
|
44
|
+
onBindingChange?.(binding);
|
|
45
|
+
};
|
|
46
|
+
const inputRef = useRef(null);
|
|
47
|
+
const [input, setInput] = useState("");
|
|
48
|
+
const [result, setResult] = useState("");
|
|
49
|
+
const resultRef = useDynamicRef(result);
|
|
50
|
+
const [state, setState] = useState(null);
|
|
51
|
+
const [history, setHistory] = useState([]);
|
|
52
|
+
const scrollerRef = useRef(null);
|
|
53
|
+
const handleScroll = () => {
|
|
54
|
+
if (scrollerRef.current) {
|
|
55
|
+
scrollerRef.current.scrollTop = scrollerRef.current.scrollHeight;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const controller = useRef();
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
return () => {
|
|
61
|
+
handleStop();
|
|
62
|
+
};
|
|
63
|
+
}, []);
|
|
64
|
+
const handleStop = () => {
|
|
65
|
+
controller.current?.abort("stop");
|
|
66
|
+
controller.current = void 0;
|
|
67
|
+
};
|
|
68
|
+
const handleClear = () => {
|
|
69
|
+
handleStop();
|
|
70
|
+
setInput("");
|
|
71
|
+
setResult("");
|
|
72
|
+
setHistory([]);
|
|
73
|
+
inputRef.current?.focus();
|
|
74
|
+
};
|
|
75
|
+
const handleDone = () => {
|
|
76
|
+
controller.current = void 0;
|
|
77
|
+
setHistory((history2) => [
|
|
78
|
+
...history2,
|
|
79
|
+
{
|
|
80
|
+
type: "response",
|
|
81
|
+
text: resultRef.current
|
|
82
|
+
}
|
|
83
|
+
]);
|
|
84
|
+
setResult("");
|
|
85
|
+
setState(null);
|
|
86
|
+
handleScroll();
|
|
87
|
+
};
|
|
88
|
+
const handleRun = async (input2) => {
|
|
89
|
+
if (input2.trim().length === 0) {
|
|
90
|
+
inputRef.current?.focus();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
setHistory((history2) => [
|
|
94
|
+
...history2,
|
|
95
|
+
{
|
|
96
|
+
type: "request",
|
|
97
|
+
text: input2
|
|
98
|
+
}
|
|
99
|
+
]);
|
|
100
|
+
setInput("");
|
|
101
|
+
setResult("");
|
|
102
|
+
try {
|
|
103
|
+
setState("pending");
|
|
104
|
+
controller.current = new AbortController();
|
|
105
|
+
const response = await fetch(functionUrl, {
|
|
106
|
+
signal: controller.current.signal,
|
|
107
|
+
method: "POST",
|
|
108
|
+
body: input2
|
|
109
|
+
});
|
|
110
|
+
if (!response.ok) {
|
|
111
|
+
setState(null);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
setState("responding");
|
|
115
|
+
const reader = response.body.getReader();
|
|
116
|
+
const pump = async ({ done, value }) => {
|
|
117
|
+
setResult((result2) => result2 + new TextDecoder().decode(value));
|
|
118
|
+
handleScroll();
|
|
119
|
+
if (!controller.current || done) {
|
|
120
|
+
handleDone();
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
return reader.read().then(pump);
|
|
124
|
+
};
|
|
125
|
+
void reader.read().then(pump).catch((err) => {
|
|
126
|
+
if (err.name !== "AbortError") {
|
|
127
|
+
log.catch(err, void 0, {
|
|
128
|
+
F: __dxlog_file,
|
|
129
|
+
L: 133,
|
|
130
|
+
S: void 0,
|
|
131
|
+
C: (f, a) => f(...a)
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
} catch (err) {
|
|
136
|
+
setState(null);
|
|
137
|
+
if (err !== "stop") {
|
|
138
|
+
log.catch(err, void 0, {
|
|
139
|
+
F: __dxlog_file,
|
|
140
|
+
L: 139,
|
|
141
|
+
S: void 0,
|
|
142
|
+
C: (f, a) => f(...a)
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
return /* @__PURE__ */ React.createElement(DensityProvider, {
|
|
148
|
+
density: "fine"
|
|
149
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
150
|
+
className: mx("flex flex-col h-full overflow-hidden", classNames)
|
|
151
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
152
|
+
ref: scrollerRef,
|
|
153
|
+
className: "flex flex-col gap-6 h-full p-4 overflow-x-hidden overflow-y-auto"
|
|
154
|
+
}, /* @__PURE__ */ React.createElement(MessageThread, {
|
|
155
|
+
state,
|
|
156
|
+
result,
|
|
157
|
+
history
|
|
158
|
+
})), /* @__PURE__ */ React.createElement(Toolbar.Root, {
|
|
159
|
+
classNames: "p-2"
|
|
160
|
+
}, /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement(Input.TextInput, {
|
|
161
|
+
ref: inputRef,
|
|
162
|
+
autoFocus: true,
|
|
163
|
+
placeholder: t("function request placeholder"),
|
|
164
|
+
value: input,
|
|
165
|
+
onChange: (ev) => setInput(ev.target.value),
|
|
166
|
+
onKeyDown: (ev) => ev.key === "Enter" && handleRun(input)
|
|
167
|
+
})), /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement(Input.TextInput, {
|
|
168
|
+
ref: bindingInputRef,
|
|
169
|
+
classNames: "!w-[10rem]",
|
|
170
|
+
placeholder: t("binding placeholder"),
|
|
171
|
+
value: binding,
|
|
172
|
+
onChange: (ev) => setBinding(ev.target.value.toUpperCase()),
|
|
173
|
+
onBlur: handleBlur
|
|
174
|
+
})), /* @__PURE__ */ React.createElement(Toolbar.Button, {
|
|
175
|
+
onClick: () => handleRun(input)
|
|
176
|
+
}, /* @__PURE__ */ React.createElement(Icon, {
|
|
177
|
+
icon: "ph--play--regular",
|
|
178
|
+
size: 4
|
|
179
|
+
})), /* @__PURE__ */ React.createElement(Toolbar.Button, {
|
|
180
|
+
onClick: () => state ? handleStop() : handleClear()
|
|
181
|
+
}, /* @__PURE__ */ React.createElement(Icon, {
|
|
182
|
+
icon: state ? "ph--stop--regular" : "ph--trash--regular",
|
|
183
|
+
size: 4
|
|
184
|
+
})))));
|
|
185
|
+
};
|
|
186
|
+
var RobotAvatar = () => /* @__PURE__ */ React.createElement(Avatar.Root, {
|
|
187
|
+
size: 6,
|
|
188
|
+
variant: "circle"
|
|
189
|
+
}, /* @__PURE__ */ React.createElement(Avatar.Frame, null, /* @__PURE__ */ React.createElement(Avatar.Icon, {
|
|
190
|
+
icon: "ph--robot--regular"
|
|
191
|
+
})));
|
|
192
|
+
var MessageThread = ({ state, result, history }) => {
|
|
193
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, history.map(({ type, text }, i) => /* @__PURE__ */ React.createElement("div", {
|
|
194
|
+
key: i,
|
|
195
|
+
className: "grid grid-cols-[3rem_1fr]"
|
|
196
|
+
}, /* @__PURE__ */ React.createElement("div", null, type === "response" && /* @__PURE__ */ React.createElement(RobotAvatar, null)), /* @__PURE__ */ React.createElement("div", {
|
|
197
|
+
className: mx("flex", type === "request" && "justify-end")
|
|
198
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
199
|
+
className: mx(type === "request" && "p-1 px-2 rounded-lg bg-hoverSurface")
|
|
200
|
+
}, text)))), /* @__PURE__ */ React.createElement("div", {
|
|
201
|
+
className: "grid grid-cols-[3rem_1fr]"
|
|
202
|
+
}, /* @__PURE__ */ React.createElement("div", null, state === "pending" && /* @__PURE__ */ React.createElement(Icon, {
|
|
203
|
+
icon: "ph--spinner--regular",
|
|
204
|
+
size: 6,
|
|
205
|
+
classNames: "animate-spin-slow"
|
|
206
|
+
}) || result.length > 0 && /* @__PURE__ */ React.createElement(RobotAvatar, null)), /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("span", null, result))));
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
// packages/plugins/experimental/plugin-script/src/components/Toolbar.tsx
|
|
210
|
+
import { Checks, CircleNotch, Link, MagicWand, UploadSimple, WarningCircle } from "@phosphor-icons/react";
|
|
211
|
+
import React2, { useState as useState2 } from "react";
|
|
212
|
+
import { DensityProvider as DensityProvider2, ElevationProvider, Icon as Icon2, Toolbar as NaturalToolbar, Tooltip, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
213
|
+
import { getSize, mx as mx2 } from "@dxos/react-ui-theme";
|
|
214
|
+
var Toolbar2 = ({ classNames, deployed, error, functionUrl, showPanel, onDeploy, onFormat, onTogglePanel }) => {
|
|
215
|
+
const { t } = useTranslation2(SCRIPT_PLUGIN);
|
|
216
|
+
const [pending, setPending] = useState2(false);
|
|
217
|
+
const handleCopyLink = async () => {
|
|
218
|
+
if (!functionUrl) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
await navigator.clipboard.writeText(functionUrl);
|
|
222
|
+
};
|
|
223
|
+
const handleDeploy = async () => {
|
|
224
|
+
setPending(true);
|
|
225
|
+
await onDeploy?.();
|
|
226
|
+
setPending(false);
|
|
227
|
+
};
|
|
228
|
+
return /* @__PURE__ */ React2.createElement(DensityProvider2, {
|
|
229
|
+
density: "fine"
|
|
230
|
+
}, /* @__PURE__ */ React2.createElement(ElevationProvider, {
|
|
231
|
+
elevation: "chrome"
|
|
232
|
+
}, /* @__PURE__ */ React2.createElement(NaturalToolbar.Root, {
|
|
233
|
+
classNames: [
|
|
234
|
+
"p-1",
|
|
235
|
+
classNames
|
|
236
|
+
],
|
|
237
|
+
style: {
|
|
238
|
+
contain: "layout"
|
|
239
|
+
}
|
|
240
|
+
}, onFormat && /* @__PURE__ */ React2.createElement(Tooltip.Root, null, /* @__PURE__ */ React2.createElement(Tooltip.Trigger, {
|
|
241
|
+
asChild: true
|
|
242
|
+
}, /* @__PURE__ */ React2.createElement(NaturalToolbar.Button, {
|
|
243
|
+
variant: "ghost",
|
|
244
|
+
onClick: onFormat
|
|
245
|
+
}, /* @__PURE__ */ React2.createElement(MagicWand, {
|
|
246
|
+
className: getSize(4)
|
|
247
|
+
}))), /* @__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", {
|
|
248
|
+
role: "separator",
|
|
249
|
+
className: "grow"
|
|
250
|
+
}), functionUrl && /* @__PURE__ */ React2.createElement(Tooltip.Root, null, /* @__PURE__ */ React2.createElement(Tooltip.Trigger, {
|
|
251
|
+
asChild: true
|
|
252
|
+
}, /* @__PURE__ */ React2.createElement(NaturalToolbar.Button, {
|
|
253
|
+
variant: "ghost",
|
|
254
|
+
onClick: handleCopyLink
|
|
255
|
+
}, /* @__PURE__ */ React2.createElement(Link, {
|
|
256
|
+
className: getSize(4)
|
|
257
|
+
}))), /* @__PURE__ */ React2.createElement(Tooltip.Portal, null, /* @__PURE__ */ React2.createElement(Tooltip.Content, null, /* @__PURE__ */ React2.createElement(Tooltip.Arrow, null), t("copy link label")))), error ? /* @__PURE__ */ React2.createElement(Tooltip.Root, null, /* @__PURE__ */ React2.createElement(Tooltip.Trigger, null, /* @__PURE__ */ React2.createElement(WarningCircle, {
|
|
258
|
+
className: getSize(4)
|
|
259
|
+
})), /* @__PURE__ */ React2.createElement(Tooltip.Portal, null, /* @__PURE__ */ React2.createElement(Tooltip.Content, null, /* @__PURE__ */ React2.createElement(Tooltip.Arrow, null), error))) : deployed ? /* @__PURE__ */ React2.createElement(Tooltip.Root, null, /* @__PURE__ */ React2.createElement(Tooltip.Trigger, null, /* @__PURE__ */ React2.createElement(Checks, {
|
|
260
|
+
className: getSize(4)
|
|
261
|
+
})), /* @__PURE__ */ React2.createElement(Tooltip.Portal, null, /* @__PURE__ */ React2.createElement(Tooltip.Content, null, /* @__PURE__ */ React2.createElement(Tooltip.Arrow, null), t("deployed label")))) : null, /* @__PURE__ */ React2.createElement(Tooltip.Root, null, /* @__PURE__ */ React2.createElement(Tooltip.Trigger, {
|
|
262
|
+
asChild: true
|
|
263
|
+
}, /* @__PURE__ */ React2.createElement(NaturalToolbar.Button, {
|
|
264
|
+
variant: "ghost",
|
|
265
|
+
onClick: handleDeploy,
|
|
266
|
+
disabled: pending
|
|
267
|
+
}, pending ? /* @__PURE__ */ React2.createElement(CircleNotch, {
|
|
268
|
+
className: mx2("spinner", getSize(4))
|
|
269
|
+
}) : /* @__PURE__ */ React2.createElement(UploadSimple, {
|
|
270
|
+
className: getSize(4)
|
|
271
|
+
}))), /* @__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, {
|
|
272
|
+
asChild: true
|
|
273
|
+
}, /* @__PURE__ */ React2.createElement(NaturalToolbar.Button, {
|
|
274
|
+
variant: "ghost",
|
|
275
|
+
onClick: onTogglePanel
|
|
276
|
+
}, /* @__PURE__ */ React2.createElement(Icon2, {
|
|
277
|
+
icon: showPanel ? "ph--caret-up--regular" : "ph--caret-down--regular",
|
|
278
|
+
size: 4
|
|
279
|
+
}))), /* @__PURE__ */ React2.createElement(Tooltip.Portal, null, /* @__PURE__ */ React2.createElement(Tooltip.Content, null, /* @__PURE__ */ React2.createElement(Tooltip.Arrow, null), t("toggle details label")))))));
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
// packages/plugins/experimental/plugin-script/src/components/ScriptEditor.tsx
|
|
283
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-script/src/components/ScriptEditor.tsx";
|
|
284
|
+
var ScriptEditor = ({ env, script, role }) => {
|
|
285
|
+
const { t } = useTranslation3(SCRIPT_PLUGIN);
|
|
286
|
+
const client = useClient();
|
|
287
|
+
const identity = useIdentity();
|
|
288
|
+
const space = getSpace(script);
|
|
289
|
+
const [fn] = useQuery(space, Filter.schema(FunctionType, (fn2) => fn2.source === script));
|
|
290
|
+
const extensions = useMemo(() => [
|
|
291
|
+
listener({
|
|
292
|
+
onChange: (text) => {
|
|
293
|
+
if (script.source && script.source?.content !== text) {
|
|
294
|
+
script.changed = true;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}),
|
|
298
|
+
createDataExtensions({
|
|
299
|
+
id: script.id,
|
|
300
|
+
text: script.source && createDocAccessor(script.source, [
|
|
301
|
+
"content"
|
|
302
|
+
]),
|
|
303
|
+
space,
|
|
304
|
+
identity
|
|
305
|
+
})
|
|
306
|
+
], [
|
|
307
|
+
script,
|
|
308
|
+
script.source,
|
|
309
|
+
space,
|
|
310
|
+
identity
|
|
311
|
+
]);
|
|
312
|
+
const [showPanel, setShowPanel] = useState3(false);
|
|
313
|
+
const initialValue = useMemo(() => script.source?.content, [
|
|
314
|
+
script.source
|
|
315
|
+
]);
|
|
316
|
+
const existingFunctionUrl = fn && getUserFunctionUrlInMetadata(getMeta(fn));
|
|
317
|
+
const [error, setError] = useState3();
|
|
318
|
+
const handleBindingChange = useCallback((binding) => {
|
|
319
|
+
fn.binding = binding;
|
|
320
|
+
}, [
|
|
321
|
+
fn
|
|
322
|
+
]);
|
|
323
|
+
const handleFormat = useCallback(async () => {
|
|
324
|
+
if (!script.source) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
try {
|
|
328
|
+
script.source.content = await format(script.source.content, {
|
|
329
|
+
parser: "typescript",
|
|
330
|
+
plugins: [
|
|
331
|
+
prettierPluginEstree,
|
|
332
|
+
prettierPluginTypescript
|
|
333
|
+
],
|
|
334
|
+
semi: true,
|
|
335
|
+
singleQuote: true
|
|
336
|
+
});
|
|
337
|
+
} catch (err) {
|
|
338
|
+
log2.catch(err, void 0, {
|
|
339
|
+
F: __dxlog_file2,
|
|
340
|
+
L: 92,
|
|
341
|
+
S: void 0,
|
|
342
|
+
C: (f, a) => f(...a)
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}, [
|
|
346
|
+
script.source
|
|
347
|
+
]);
|
|
348
|
+
const handleDeploy = useCallback(async () => {
|
|
349
|
+
if (!script.source || !identity || !space) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
setError(void 0);
|
|
353
|
+
try {
|
|
354
|
+
const existingFunctionId = existingFunctionUrl?.split("/").at(-1);
|
|
355
|
+
const ownerDid = existingFunctionUrl?.split("/").at(-2) ?? publicKeyToDid(identity.identityKey);
|
|
356
|
+
const bundler = new Bundler({
|
|
357
|
+
platform: "browser",
|
|
358
|
+
sandboxedModules: [],
|
|
359
|
+
remoteModules: {}
|
|
360
|
+
});
|
|
361
|
+
const buildResult = await bundler.bundle(script.source.content);
|
|
362
|
+
if (buildResult.error || !buildResult.bundle) {
|
|
363
|
+
throw buildResult.error;
|
|
364
|
+
}
|
|
365
|
+
const { result, functionId, functionVersionNumber, errorMessage } = await uploadWorkerFunction({
|
|
366
|
+
clientConfig: client.config,
|
|
367
|
+
halo: client.halo,
|
|
368
|
+
ownerDid,
|
|
369
|
+
functionId: existingFunctionId,
|
|
370
|
+
source: buildResult.bundle
|
|
371
|
+
});
|
|
372
|
+
if (result !== "success" || functionId === void 0 || functionVersionNumber === void 0) {
|
|
373
|
+
throw new Error(errorMessage);
|
|
374
|
+
}
|
|
375
|
+
log2.info("function uploaded", {
|
|
376
|
+
functionId,
|
|
377
|
+
functionVersionNumber
|
|
378
|
+
}, {
|
|
379
|
+
F: __dxlog_file2,
|
|
380
|
+
L: 127,
|
|
381
|
+
S: void 0,
|
|
382
|
+
C: (f, a) => f(...a)
|
|
383
|
+
});
|
|
384
|
+
if (fn) {
|
|
385
|
+
fn.version = functionVersionNumber;
|
|
386
|
+
}
|
|
387
|
+
const deployedFunction = fn ?? space.db.add(create(FunctionType, {
|
|
388
|
+
version: functionVersionNumber,
|
|
389
|
+
source: script
|
|
390
|
+
}));
|
|
391
|
+
const meta = getMeta(deployedFunction);
|
|
392
|
+
setUserFunctionUrlInMetadata(meta, `/${ownerDid}/${functionId}`);
|
|
393
|
+
script.changed = false;
|
|
394
|
+
} catch (err) {
|
|
395
|
+
log2.catch(err, void 0, {
|
|
396
|
+
F: __dxlog_file2,
|
|
397
|
+
L: 137,
|
|
398
|
+
S: void 0,
|
|
399
|
+
C: (f, a) => f(...a)
|
|
400
|
+
});
|
|
401
|
+
setError(t("upload failed label"));
|
|
402
|
+
}
|
|
403
|
+
}, [
|
|
404
|
+
fn,
|
|
405
|
+
existingFunctionUrl,
|
|
406
|
+
script,
|
|
407
|
+
script.name,
|
|
408
|
+
script.source
|
|
409
|
+
]);
|
|
410
|
+
const functionUrl = useMemo(() => {
|
|
411
|
+
if (!existingFunctionUrl) {
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
const baseUrl = new URL("functions/", client.config.values.runtime?.services?.edge?.url);
|
|
415
|
+
const relativeUrl = existingFunctionUrl.replace(/^\//, "");
|
|
416
|
+
const url = new URL(`./${relativeUrl}`, baseUrl.toString());
|
|
417
|
+
space && url.searchParams.set("spaceId", space.id);
|
|
418
|
+
url.protocol = "https";
|
|
419
|
+
return url.toString();
|
|
420
|
+
}, [
|
|
421
|
+
existingFunctionUrl,
|
|
422
|
+
space
|
|
423
|
+
]);
|
|
424
|
+
return /* @__PURE__ */ React3.createElement("div", {
|
|
425
|
+
role: "none",
|
|
426
|
+
className: mx3(role === "article" && "row-span-2", "flex flex-col is-full bs-full overflow-hidden")
|
|
427
|
+
}, /* @__PURE__ */ React3.createElement(TypescriptEditor, {
|
|
428
|
+
id: script.id,
|
|
429
|
+
env,
|
|
430
|
+
initialValue,
|
|
431
|
+
extensions,
|
|
432
|
+
className: "flex is-full bs-full overflow-hidden border-b border-separator"
|
|
433
|
+
}), /* @__PURE__ */ React3.createElement(Toolbar2, {
|
|
434
|
+
deployed: Boolean(existingFunctionUrl) && !script.changed,
|
|
435
|
+
functionUrl,
|
|
436
|
+
error,
|
|
437
|
+
showPanel,
|
|
438
|
+
onDeploy: handleDeploy,
|
|
439
|
+
onFormat: handleFormat,
|
|
440
|
+
onTogglePanel: async () => setShowPanel((showDetails) => !showDetails)
|
|
441
|
+
}), showPanel && /* @__PURE__ */ React3.createElement(DetailsPanel, {
|
|
442
|
+
functionUrl,
|
|
443
|
+
binding: fn?.binding,
|
|
444
|
+
onBindingChange: handleBindingChange
|
|
445
|
+
}));
|
|
446
|
+
};
|
|
447
|
+
var ScriptEditor_default = ScriptEditor;
|
|
448
|
+
export {
|
|
449
|
+
ScriptEditor,
|
|
450
|
+
ScriptEditor_default as default
|
|
451
|
+
};
|
|
452
|
+
//# sourceMappingURL=ScriptEditor-WNCGR5OU.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/ScriptEditor.tsx", "../../../src/components/DetailsPanel.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 { create, createDocAccessor, Filter, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';\nimport { useIdentity } from '@dxos/react-client/halo';\nimport { useTranslation } from '@dxos/react-ui';\nimport { createDataExtensions, listener } from '@dxos/react-ui-editor';\nimport { mx } from '@dxos/react-ui-theme';\n\nimport { DetailsPanel } from './DetailsPanel';\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 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(role === 'article' && 'row-span-2', 'flex flex-col is-full bs-full overflow-hidden')}\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 border-b border-separator'\n />\n\n <Toolbar\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 <DetailsPanel 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 useDynamicRef,\n useTranslation,\n} from '@dxos/react-ui';\nimport { mx } from '@dxos/react-ui-theme';\n\nimport { SCRIPT_PLUGIN } from '../meta';\n\ntype State = 'pending' | 'responding';\n\ntype Item = { type: 'request' | 'response'; text: string };\n\nexport type DetailsPanelProps = ThemedClassName<{\n functionUrl?: string;\n binding?: string;\n onBindingChange?: (binding: string) => void;\n}>;\n\nexport const DetailsPanel = ({ classNames, functionUrl, binding: _binding, onBindingChange }: DetailsPanelProps) => {\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 resultRef = useDynamicRef(result);\n const [state, setState] = useState<State | null>(null);\n\n // TODO(burdon): Persistent history (non-space ECHO data?)\n const [history, setHistory] = useState<Item[]>([]);\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 // TODO(burdon): Halt streaming request?\n const handleClear = () => {\n handleStop();\n setInput('');\n setResult('');\n setHistory([]);\n inputRef.current?.focus();\n };\n\n const handleDone = () => {\n controller.current = undefined;\n setHistory((history) => [...history, { type: 'response', text: resultRef.current }]);\n setResult('');\n setState(null);\n handleScroll();\n };\n\n const handleRun = async (input: string) => {\n if (input.trim().length === 0) {\n inputRef.current?.focus();\n return;\n }\n\n setHistory((history) => [...history, { type: 'request', text: input }]);\n setInput('');\n setResult('');\n\n // Returns a promise that resolves when a value has been received.\n try {\n setState('pending');\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 });\n\n // TODO(burdon): Error handling.\n if (!response.ok) {\n setState(null);\n return;\n }\n\n setState('responding');\n const reader = response.body!.getReader();\n const pump = async ({ done, value }: ReadableStreamReadResult<Uint8Array>): Promise<void> => {\n setResult((result) => result + new TextDecoder().decode(value));\n handleScroll();\n if (!controller.current || done) {\n handleDone();\n return;\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) {\n setState(null);\n if (err !== 'stop') {\n log.catch(err);\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' && handleRun(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={() => handleRun(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\n// TODO(burdon): Replace with thread.\n// TODO(burdon): Delete individual messages.\n// TODO(burdon): Re-run question.\nconst MessageThread = ({ state, result, history }: { state: State | null; result: string; history: Item[] }) => {\n return (\n <>\n {history.map(({ type, text }, i) => (\n <div key={i} className='grid grid-cols-[3rem_1fr]'>\n <div>{type === 'response' && <RobotAvatar />}</div>\n <div className={mx('flex', type === 'request' && 'justify-end')}>\n <span className={mx(type === 'request' && 'p-1 px-2 rounded-lg bg-hoverSurface')}>{text}</span>\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 { Checks, CircleNotch, Link, MagicWand, UploadSimple, WarningCircle } from '@phosphor-icons/react';\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';\nimport { getSize, mx } from '@dxos/react-ui-theme';\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): 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 <MagicWand className={getSize(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 {functionUrl && (\n <Tooltip.Root>\n <Tooltip.Trigger asChild>\n <NaturalToolbar.Button variant='ghost' onClick={handleCopyLink}>\n <Link className={getSize(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 {/* TODO(wittjosiah): Better treatment for status indicators in toolbar? */}\n {error ? (\n <Tooltip.Root>\n <Tooltip.Trigger>\n <WarningCircle className={getSize(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 ) : deployed ? (\n <Tooltip.Root>\n <Tooltip.Trigger>\n <Checks className={getSize(4)} />\n </Tooltip.Trigger>\n <Tooltip.Portal>\n <Tooltip.Content>\n <Tooltip.Arrow />\n {t('deployed label')}\n </Tooltip.Content>\n </Tooltip.Portal>\n </Tooltip.Root>\n ) : null}\n\n <Tooltip.Root>\n <Tooltip.Trigger asChild>\n <NaturalToolbar.Button variant='ghost' onClick={handleDeploy} disabled={pending}>\n {pending ? (\n <CircleNotch className={mx('spinner', getSize(4))} />\n ) : (\n <UploadSimple className={getSize(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-up--regular' : 'ph--caret-down--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,SAASC,QAAQC,mBAAmBC,QAAQC,SAASC,UAAUC,gBAAgB;AAC/E,SAASC,mBAAmB;AAC5B,SAASC,kBAAAA,uBAAsB;AAC/B,SAASC,sBAAsBC,gBAAgB;AAC/C,SAASC,MAAAA,WAAU;;;ACZnB,OAAOC,SAASC,WAAWC,QAAQC,gBAAgB;AAEnD,SAASC,WAAW;AACpB,SACEC,QACAC,iBACAC,MACAC,OAEAC,SACAC,oBACAC,eACAC,sBACK;AACP,SAASC,UAAU;;AAcZ,IAAMC,eAAe,CAAC,EAAEC,YAAYC,aAAaC,SAASC,UAAUC,gBAAe,MAAqB;AAC7G,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,sBAA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U;IACnB,SAASwB,KAAU;AACjBC,MAAAA,KAAIC,MAAMF,KAAAA,QAAAA;;;;;;AACVZ,eAASjC,EAAE,qBAAA,CAAA;IACb;EACF,GAAG;IAACS;IAAIoB;IAAqB/B;IAAQA,OAAOkF;IAAMlF,OAAOgB;GAAO;AAEhE,QAAMmE,cAAcjE,QAAQ,MAAA;AAC1B,QAAI,CAACa,qBAAqB;AACxB;IACF;AAEA,UAAMqD,UAAU,IAAIC,IAAI,cAAchF,OAAOkE,OAAOe,OAAOC,SAASC,UAAUC,MAAMC,GAAAA;AAGpF,UAAMC,cAAc5D,oBAAoB6D,QAAQ,OAAO,EAAA;AACvD,UAAMF,MAAM,IAAIL,IAAI,KAAKM,WAAAA,IAAeP,QAAQS,SAAQ,CAAA;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;IACCjG,MAAK;IACLkG,WAAWC,IAAGnG,SAAS,aAAa,cAAc,+CAAA;KAElD,gBAAAgG,OAAA,cAACI,kBAAAA;IACC5E,IAAIzB,OAAOyB;IACX1B;IACA+B;IACAb;IACAkF,WAAU;MAGZ,gBAAAF,OAAA,cAACK,UAAAA;IACCC,UAAUC,QAAQzE,mBAAAA,KAAwB,CAAC/B,OAAOuB;IAClD4D;IACAjD;IACAP;IACA8E,UAAUvD;IACVwD,UAAUnE;IACVoE,eAAe,YAAY/E,aAAa,CAACgF,gBAAgB,CAACA,WAAAA;MAG3DjF,aACC,gBAAAsE,OAAA,cAACY,cAAAA;IAAa1B;IAA0B7C,SAAS3B,IAAI2B;IAASwE,iBAAiB1E;;AAIvF;AAEA,IAAA,uBAAetC;",
|
|
6
|
+
"names": ["format", "prettierPluginEstree", "prettierPluginTypescript", "React", "useCallback", "useMemo", "useState", "log", "useClient", "create", "createDocAccessor", "Filter", "getMeta", "getSpace", "useQuery", "useIdentity", "useTranslation", "createDataExtensions", "listener", "mx", "React", "useEffect", "useRef", "useState", "log", "Avatar", "DensityProvider", "Icon", "Input", "Toolbar", "useControlledValue", "useDynamicRef", "useTranslation", "mx", "DetailsPanel", "classNames", "functionUrl", "binding", "_binding", "onBindingChange", "t", "useTranslation", "SCRIPT_PLUGIN", "bindingInputRef", "useRef", "setBinding", "useControlledValue", "handleBlur", "inputRef", "input", "setInput", "useState", "result", "setResult", "resultRef", "useDynamicRef", "state", "setState", "history", "setHistory", "scrollerRef", "handleScroll", "current", "scrollTop", "scrollHeight", "controller", "useEffect", "handleStop", "abort", "undefined", "handleClear", "focus", "handleDone", "type", "text", "handleRun", "trim", "length", "AbortController", "response", "fetch", "signal", "method", "body", "ok", "reader", "getReader", "pump", "done", "value", "TextDecoder", "decode", "read", "then", "catch", "err", "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", "map", "i", "span", "Checks", "CircleNotch", "Link", "MagicWand", "UploadSimple", "WarningCircle", "React", "useState", "DensityProvider", "ElevationProvider", "Icon", "Toolbar", "NaturalToolbar", "Tooltip", "useTranslation", "getSize", "mx", "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", "MagicWand", "className", "getSize", "Portal", "Content", "Arrow", "div", "role", "Link", "WarningCircle", "Checks", "disabled", "CircleNotch", "mx", "UploadSimple", "Icon", "icon", "size", "ScriptEditor", "env", "script", "role", "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", "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", "deployed", "Boolean", "onDeploy", "onFormat", "onTogglePanel", "showDetails", "DetailsPanel", "onBindingChange"]
|
|
7
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TypescriptEditor,
|
|
3
3
|
TypescriptEditor_default
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-DX5CSOBP.mjs";
|
|
5
5
|
export {
|
|
6
6
|
TypescriptEditor,
|
|
7
7
|
TypescriptEditor_default as default
|
|
8
8
|
};
|
|
9
|
-
//# sourceMappingURL=TypescriptEditor-
|
|
9
|
+
//# sourceMappingURL=TypescriptEditor-XTGRVCMY.mjs.map
|
|
@@ -108,9 +108,15 @@ var publicKeyToDid = (key) => {
|
|
|
108
108
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-script/src/edge/functions.ts";
|
|
109
109
|
var USERFUNCTIONS_META_KEY = "dxos.org/service/function";
|
|
110
110
|
var USERFUNCTIONS_CREDENTIAL_CAPABILITY = "composer:beta";
|
|
111
|
-
var defaultUserFunctionsBaseUrl = "https://edge-main.dxos.workers.dev";
|
|
111
|
+
var defaultUserFunctionsBaseUrl = "https://edge-main.dxos.workers.dev/functions";
|
|
112
112
|
var getBaseUrl = (config) => {
|
|
113
|
-
|
|
113
|
+
if (config.values.runtime?.services?.edge?.url) {
|
|
114
|
+
const url = new URL("/functions", config.values.runtime?.services?.edge?.url);
|
|
115
|
+
url.protocol = "https";
|
|
116
|
+
return url.toString();
|
|
117
|
+
} else {
|
|
118
|
+
return defaultUserFunctionsBaseUrl;
|
|
119
|
+
}
|
|
114
120
|
};
|
|
115
121
|
var uploadWorkerFunction = async ({ clientConfig, halo, name, source, ownerDid, functionId, credentialLoadTimeout }) => {
|
|
116
122
|
const identity = halo.identity.get();
|
|
@@ -127,7 +133,7 @@ var uploadWorkerFunction = async ({ clientConfig, halo, name, source, ownerDid,
|
|
|
127
133
|
uploadUrl: uploadUrl.toString()
|
|
128
134
|
}, {
|
|
129
135
|
F: __dxlog_file,
|
|
130
|
-
L:
|
|
136
|
+
L: 71,
|
|
131
137
|
S: void 0,
|
|
132
138
|
C: (f, a) => f(...a)
|
|
133
139
|
});
|
|
@@ -151,7 +157,7 @@ var uploadWorkerFunction = async ({ clientConfig, halo, name, source, ownerDid,
|
|
|
151
157
|
res
|
|
152
158
|
}, {
|
|
153
159
|
F: __dxlog_file,
|
|
154
|
-
L:
|
|
160
|
+
L: 82,
|
|
155
161
|
S: void 0,
|
|
156
162
|
C: (f, a) => f(...a)
|
|
157
163
|
});
|
|
@@ -200,13 +206,13 @@ var presentationForIdentity = async ({ halo, timeout }) => {
|
|
|
200
206
|
credential
|
|
201
207
|
}, {
|
|
202
208
|
F: __dxlog_file,
|
|
203
|
-
L:
|
|
209
|
+
L: 128,
|
|
204
210
|
S: void 0,
|
|
205
211
|
C: (f, a) => f(...a)
|
|
206
212
|
});
|
|
207
213
|
invariant(credential.id, "beta credential missing id", {
|
|
208
214
|
F: __dxlog_file,
|
|
209
|
-
L:
|
|
215
|
+
L: 130,
|
|
210
216
|
S: void 0,
|
|
211
217
|
A: [
|
|
212
218
|
"credential.id",
|
|
@@ -232,4 +238,4 @@ export {
|
|
|
232
238
|
getUserFunctionUrlInMetadata,
|
|
233
239
|
setUserFunctionUrlInMetadata
|
|
234
240
|
};
|
|
235
|
-
//# sourceMappingURL=chunk-
|
|
241
|
+
//# sourceMappingURL=chunk-DL5XQRQM.mjs.map
|