@dxos/plugin-script 0.6.12 → 0.6.13-main.041e8aa

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.
Files changed (182) hide show
  1. package/README.md +1 -1
  2. package/dist/lib/browser/{ScriptEditor-5Y3EROG3.mjs → ScriptContainer-M4MDQTBU.mjs} +258 -106
  3. package/dist/lib/browser/ScriptContainer-M4MDQTBU.mjs.map +7 -0
  4. package/dist/lib/browser/{chunk-DL5XQRQM.mjs → chunk-G6FWCTGT.mjs} +7 -5
  5. package/dist/lib/browser/chunk-G6FWCTGT.mjs.map +7 -0
  6. package/dist/lib/browser/{chunk-RHEZ5LUU.mjs → chunk-G6H56WFS.mjs} +51 -2
  7. package/dist/lib/browser/{chunk-RHEZ5LUU.mjs.map → chunk-G6H56WFS.mjs.map} +4 -4
  8. package/dist/lib/browser/{chunk-O4LWBX6A.mjs → chunk-KXVQPS4Y.mjs} +2 -2
  9. package/dist/lib/browser/{chunk-O4LWBX6A.mjs.map → chunk-KXVQPS4Y.mjs.map} +2 -2
  10. package/dist/lib/browser/chunk-SGQHRB4P.mjs +17 -0
  11. package/dist/lib/browser/chunk-SGQHRB4P.mjs.map +7 -0
  12. package/dist/lib/browser/edge/index.mjs +3 -1
  13. package/dist/lib/browser/index.mjs +80 -62
  14. package/dist/lib/browser/index.mjs.map +4 -4
  15. package/dist/lib/browser/meta.json +1 -1
  16. package/dist/lib/browser/meta.mjs +1 -1
  17. package/dist/lib/browser/types/index.mjs +2 -2
  18. package/dist/lib/node/ScriptContainer-KMIPKT3H.cjs +668 -0
  19. package/dist/lib/node/ScriptContainer-KMIPKT3H.cjs.map +7 -0
  20. package/dist/lib/node/{chunk-5RBVXKXT.cjs → chunk-25PQE7FL.cjs} +6 -6
  21. package/dist/lib/node/{chunk-5RBVXKXT.cjs.map → chunk-25PQE7FL.cjs.map} +2 -2
  22. package/dist/lib/node/{chunk-4GTXIELQ.cjs → chunk-ACLCRWDB.cjs} +44 -6
  23. package/dist/lib/node/chunk-ACLCRWDB.cjs.map +7 -0
  24. package/dist/lib/node/{TypescriptEditor-M3WWFIP2.cjs → chunk-EJC55SDD.cjs} +18 -8
  25. package/dist/lib/node/chunk-EJC55SDD.cjs.map +7 -0
  26. package/dist/lib/node/{chunk-PFH3ROEH.cjs → chunk-UZ3ZXEBF.cjs} +11 -8
  27. package/dist/lib/node/chunk-UZ3ZXEBF.cjs.map +7 -0
  28. package/dist/lib/node/edge/index.cjs +10 -8
  29. package/dist/lib/node/edge/index.cjs.map +2 -2
  30. package/dist/lib/node/index.cjs +95 -82
  31. package/dist/lib/node/index.cjs.map +4 -4
  32. package/dist/lib/node/meta.cjs +3 -3
  33. package/dist/lib/node/meta.cjs.map +1 -1
  34. package/dist/lib/node/meta.json +1 -1
  35. package/dist/lib/node/types/index.cjs +5 -5
  36. package/dist/lib/node/types/index.cjs.map +1 -1
  37. package/dist/lib/node-esm/ScriptContainer-EAE6L5JV.mjs +666 -0
  38. package/dist/lib/node-esm/ScriptContainer-EAE6L5JV.mjs.map +7 -0
  39. package/dist/lib/node-esm/chunk-2NX3HWPM.mjs +245 -0
  40. package/dist/lib/node-esm/chunk-2NX3HWPM.mjs.map +7 -0
  41. package/dist/lib/node-esm/chunk-7EDYDVQH.mjs +47 -0
  42. package/dist/lib/node-esm/chunk-7EDYDVQH.mjs.map +7 -0
  43. package/dist/lib/node-esm/chunk-GO7HYFM5.mjs +19 -0
  44. package/dist/lib/node-esm/chunk-GO7HYFM5.mjs.map +7 -0
  45. package/dist/lib/node-esm/chunk-LDLNTVAK.mjs +280 -0
  46. package/dist/lib/node-esm/chunk-LDLNTVAK.mjs.map +7 -0
  47. package/dist/lib/node-esm/edge/index.mjs +22 -0
  48. package/dist/lib/node-esm/index.mjs +310 -0
  49. package/dist/lib/node-esm/index.mjs.map +7 -0
  50. package/dist/lib/node-esm/meta.json +1 -0
  51. package/dist/lib/node-esm/meta.mjs +10 -0
  52. package/dist/lib/node-esm/meta.mjs.map +7 -0
  53. package/dist/lib/node-esm/types/index.mjs +13 -0
  54. package/dist/lib/node-esm/types/index.mjs.map +7 -0
  55. package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
  56. package/dist/types/src/components/DebugPanel/DebugPanel.d.ts.map +1 -0
  57. package/dist/types/src/components/DebugPanel/index.d.ts +2 -0
  58. package/dist/types/src/components/DebugPanel/index.d.ts.map +1 -0
  59. package/dist/types/src/components/{ScriptBlock/FrameContainer → FrameContainer}/FrameContainer.d.ts +1 -1
  60. package/dist/types/src/components/FrameContainer/FrameContainer.d.ts.map +1 -0
  61. package/dist/types/src/components/FrameContainer/frame.d.ts.map +1 -0
  62. package/dist/types/src/components/FrameContainer/index.d.ts.map +1 -0
  63. package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts +1 -3
  64. package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts.map +1 -1
  65. package/dist/types/src/components/ScriptBlock/ScriptBlock.stories.d.ts +1 -1
  66. package/dist/types/src/components/ScriptBlock/ScriptBlock.stories.d.ts.map +1 -1
  67. package/dist/types/src/components/ScriptContainer.d.ts +5 -0
  68. package/dist/types/src/components/ScriptContainer.d.ts.map +1 -0
  69. package/dist/types/src/components/ScriptEditor.d.ts +4 -5
  70. package/dist/types/src/components/ScriptEditor.d.ts.map +1 -1
  71. package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts +6 -0
  72. package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts.map +1 -0
  73. package/dist/types/src/components/ScriptSettings/index.d.ts +2 -0
  74. package/dist/types/src/components/ScriptSettings/index.d.ts.map +1 -0
  75. package/dist/types/src/components/Toolbar/Toolbar.d.ts +23 -0
  76. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -0
  77. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +17 -0
  78. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -0
  79. package/dist/types/src/components/Toolbar/index.d.ts +2 -0
  80. package/dist/types/src/components/Toolbar/index.d.ts.map +1 -0
  81. package/dist/types/src/components/{TypescriptEditor.d.ts → TypescriptEditor/TypescriptEditor.d.ts} +1 -2
  82. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -0
  83. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts +10 -0
  84. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts.map +1 -0
  85. package/dist/types/src/components/TypescriptEditor/index.d.ts +2 -0
  86. package/dist/types/src/components/TypescriptEditor/index.d.ts.map +1 -0
  87. package/dist/types/src/components/index.d.ts +2 -2
  88. package/dist/types/src/components/index.d.ts.map +1 -1
  89. package/dist/types/src/edge/functions.d.ts +1 -0
  90. package/dist/types/src/edge/functions.d.ts.map +1 -1
  91. package/dist/types/src/meta.d.ts +4 -9
  92. package/dist/types/src/meta.d.ts.map +1 -1
  93. package/dist/types/src/templates/chat.d.ts +6 -0
  94. package/dist/types/src/templates/chat.d.ts.map +1 -0
  95. package/dist/types/src/templates/chess.d.ts +6 -0
  96. package/dist/types/src/templates/chess.d.ts.map +1 -0
  97. package/dist/types/src/templates/echo.d.ts +6 -0
  98. package/dist/types/src/templates/echo.d.ts.map +1 -0
  99. package/dist/types/src/templates/email.d.ts +6 -0
  100. package/dist/types/src/templates/email.d.ts.map +1 -0
  101. package/dist/types/src/templates/forex.d.ts +6 -0
  102. package/dist/types/src/templates/forex.d.ts.map +1 -0
  103. package/dist/types/src/templates.d.ts +8 -0
  104. package/dist/types/src/templates.d.ts.map +1 -0
  105. package/dist/types/src/translations.d.ts +2 -0
  106. package/dist/types/src/translations.d.ts.map +1 -1
  107. package/dist/types/src/types/script.d.ts +4 -4
  108. package/dist/types/src/types/types.d.ts +4 -3
  109. package/dist/types/src/types/types.d.ts.map +1 -1
  110. package/package.json +61 -55
  111. package/src/ScriptPlugin.tsx +22 -38
  112. package/src/bundler/bundler.test.ts +12 -2
  113. package/src/components/{DebugPanel.tsx → DebugPanel/DebugPanel.tsx} +48 -41
  114. package/src/components/DebugPanel/index.ts +5 -0
  115. package/src/components/{ScriptBlock/FrameContainer → FrameContainer}/FrameContainer.tsx +1 -1
  116. package/src/components/ScriptBlock/ScriptBlock.stories.tsx +4 -3
  117. package/src/components/ScriptBlock/ScriptBlock.tsx +10 -36
  118. package/src/components/ScriptContainer.tsx +22 -0
  119. package/src/components/ScriptEditor.tsx +47 -46
  120. package/src/components/ScriptSettings/ScriptSettings.tsx +47 -0
  121. package/src/components/ScriptSettings/index.ts +5 -0
  122. package/src/components/{Toolbar.stories.tsx → Toolbar/Toolbar.stories.tsx} +10 -1
  123. package/src/components/Toolbar/Toolbar.tsx +180 -0
  124. package/src/components/{ScriptBlock/Splitter → Toolbar}/index.ts +1 -1
  125. package/src/components/{TypescriptEditor.stories.tsx → TypescriptEditor/TypescriptEditor.stories.tsx} +7 -28
  126. package/src/components/{TypescriptEditor.tsx → TypescriptEditor/TypescriptEditor.tsx} +1 -3
  127. package/src/components/TypescriptEditor/index.ts +5 -0
  128. package/src/components/index.ts +3 -2
  129. package/src/edge/functions.ts +1 -0
  130. package/src/meta.ts +15 -0
  131. package/src/templates/chat.ts +102 -0
  132. package/src/templates/chess.ts +41 -0
  133. package/src/templates/echo.ts +15 -0
  134. package/src/templates/email.ts +38 -0
  135. package/src/templates/forex.ts +21 -0
  136. package/src/templates.ts +54 -0
  137. package/src/translations.ts +2 -0
  138. package/src/types/types.ts +9 -5
  139. package/dist/lib/browser/ScriptEditor-5Y3EROG3.mjs.map +0 -7
  140. package/dist/lib/browser/TypescriptEditor-GPE72Y6I.mjs +0 -9
  141. package/dist/lib/browser/chunk-DL5XQRQM.mjs.map +0 -7
  142. package/dist/lib/browser/chunk-JBACGDOJ.mjs +0 -21
  143. package/dist/lib/browser/chunk-JBACGDOJ.mjs.map +0 -7
  144. package/dist/lib/browser/chunk-MRGOT5RF.mjs +0 -78
  145. package/dist/lib/browser/chunk-MRGOT5RF.mjs.map +0 -7
  146. package/dist/lib/node/ScriptEditor-YCUQFWQM.cjs +0 -526
  147. package/dist/lib/node/ScriptEditor-YCUQFWQM.cjs.map +0 -7
  148. package/dist/lib/node/TypescriptEditor-M3WWFIP2.cjs.map +0 -7
  149. package/dist/lib/node/chunk-4GTXIELQ.cjs.map +0 -7
  150. package/dist/lib/node/chunk-4VMNBXWU.cjs +0 -54
  151. package/dist/lib/node/chunk-4VMNBXWU.cjs.map +0 -7
  152. package/dist/lib/node/chunk-IMLDKD5Y.cjs +0 -111
  153. package/dist/lib/node/chunk-IMLDKD5Y.cjs.map +0 -7
  154. package/dist/lib/node/chunk-PFH3ROEH.cjs.map +0 -7
  155. package/dist/types/src/components/DebugPanel.d.ts.map +0 -1
  156. package/dist/types/src/components/ScriptBlock/FrameContainer/FrameContainer.d.ts.map +0 -1
  157. package/dist/types/src/components/ScriptBlock/FrameContainer/frame.d.ts.map +0 -1
  158. package/dist/types/src/components/ScriptBlock/FrameContainer/index.d.ts.map +0 -1
  159. package/dist/types/src/components/ScriptBlock/Splitter/Splitter.d.ts +0 -15
  160. package/dist/types/src/components/ScriptBlock/Splitter/Splitter.d.ts.map +0 -1
  161. package/dist/types/src/components/ScriptBlock/Splitter/Splitter.stories.d.ts +0 -13
  162. package/dist/types/src/components/ScriptBlock/Splitter/Splitter.stories.d.ts.map +0 -1
  163. package/dist/types/src/components/ScriptBlock/Splitter/index.d.ts +0 -2
  164. package/dist/types/src/components/ScriptBlock/Splitter/index.d.ts.map +0 -1
  165. package/dist/types/src/components/Toolbar.d.ts +0 -13
  166. package/dist/types/src/components/Toolbar.d.ts.map +0 -1
  167. package/dist/types/src/components/Toolbar.stories.d.ts +0 -14
  168. package/dist/types/src/components/Toolbar.stories.d.ts.map +0 -1
  169. package/dist/types/src/components/TypescriptEditor.d.ts.map +0 -1
  170. package/dist/types/src/components/TypescriptEditor.stories.d.ts +0 -10
  171. package/dist/types/src/components/TypescriptEditor.stories.d.ts.map +0 -1
  172. package/src/components/ScriptBlock/Splitter/Splitter.stories.tsx +0 -37
  173. package/src/components/ScriptBlock/Splitter/Splitter.tsx +0 -52
  174. package/src/components/Toolbar.tsx +0 -147
  175. package/src/meta.tsx +0 -19
  176. /package/dist/lib/{browser/TypescriptEditor-GPE72Y6I.mjs.map → node-esm/edge/index.mjs.map} +0 -0
  177. /package/dist/types/src/components/{DebugPanel.d.ts → DebugPanel/DebugPanel.d.ts} +0 -0
  178. /package/dist/types/src/components/{ScriptBlock/FrameContainer → FrameContainer}/frame.d.ts +0 -0
  179. /package/dist/types/src/components/{ScriptBlock/FrameContainer → FrameContainer}/index.d.ts +0 -0
  180. /package/src/components/{ScriptBlock/FrameContainer → FrameContainer}/frame.html +0 -0
  181. /package/src/components/{ScriptBlock/FrameContainer → FrameContainer}/frame.tsx +0 -0
  182. /package/src/components/{ScriptBlock/FrameContainer → FrameContainer}/index.ts +0 -0
@@ -18,13 +18,13 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var types_exports = {};
20
20
  __export(types_exports, {
21
- FunctionType: () => import_chunk_5RBVXKXT.FunctionType,
22
- ScriptAction: () => import_chunk_5RBVXKXT.ScriptAction,
23
- ScriptType: () => import_chunk_5RBVXKXT.ScriptType
21
+ FunctionType: () => import_chunk_25PQE7FL.FunctionType,
22
+ ScriptAction: () => import_chunk_25PQE7FL.ScriptAction,
23
+ ScriptType: () => import_chunk_25PQE7FL.ScriptType
24
24
  });
25
25
  module.exports = __toCommonJS(types_exports);
26
- var import_chunk_5RBVXKXT = require("../chunk-5RBVXKXT.cjs");
27
- var import_chunk_4VMNBXWU = require("../chunk-4VMNBXWU.cjs");
26
+ var import_chunk_25PQE7FL = require("../chunk-25PQE7FL.cjs");
27
+ var import_chunk_EJC55SDD = require("../chunk-EJC55SDD.cjs");
28
28
  // Annotate the CommonJS export names for ESM import in node:
29
29
  0 && (module.exports = {
30
30
  FunctionType,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["index.cjs"],
4
- "sourcesContent": ["import {\n FunctionType,\n ScriptAction,\n ScriptType\n} from \"../chunk-5RBVXKXT.cjs\";\nimport \"../chunk-4VMNBXWU.cjs\";\nexport {\n FunctionType,\n ScriptAction,\n ScriptType\n};\n//# sourceMappingURL=index.cjs.map\n"],
4
+ "sourcesContent": ["import {\n FunctionType,\n ScriptAction,\n ScriptType\n} from \"../chunk-25PQE7FL.cjs\";\nimport \"../chunk-EJC55SDD.cjs\";\nexport {\n FunctionType,\n ScriptAction,\n ScriptType\n};\n//# sourceMappingURL=index.cjs.map\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAIO;AACP,4BAAO;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,666 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+ import {
3
+ USERFUNCTIONS_PRESET_META_KEY,
4
+ getUserFunctionUrlInMetadata,
5
+ publicKeyToDid,
6
+ setUserFunctionUrlInMetadata,
7
+ uploadWorkerFunction
8
+ } from "./chunk-2NX3HWPM.mjs";
9
+ import {
10
+ Bundler,
11
+ templates
12
+ } from "./chunk-LDLNTVAK.mjs";
13
+ import {
14
+ FunctionType
15
+ } from "./chunk-7EDYDVQH.mjs";
16
+ import {
17
+ SCRIPT_PLUGIN
18
+ } from "./chunk-GO7HYFM5.mjs";
19
+
20
+ // packages/plugins/experimental/plugin-script/src/components/ScriptContainer.tsx
21
+ import React5 from "react";
22
+ import { fullyQualifiedId } from "@dxos/react-client/echo";
23
+ import { useAttendableAttributes } from "@dxos/react-ui-attention";
24
+ import { mx as mx3 } from "@dxos/react-ui-theme";
25
+
26
+ // packages/plugins/experimental/plugin-script/src/components/ScriptEditor.tsx
27
+ import { format } from "prettier";
28
+ import prettierPluginEstree from "prettier/plugins/estree";
29
+ import prettierPluginTypescript from "prettier/plugins/typescript";
30
+ import React4, { useCallback, useMemo, useState as useState3 } from "react";
31
+ import { log as log2 } from "@dxos/log";
32
+ import { useClient } from "@dxos/react-client";
33
+ import { create, createDocAccessor, Filter, getMeta, getSpace, useQuery } from "@dxos/react-client/echo";
34
+ import { useIdentity } from "@dxos/react-client/halo";
35
+ import { useTranslation as useTranslation3 } from "@dxos/react-ui";
36
+ import { createDataExtensions, listener } from "@dxos/react-ui-editor";
37
+ import { mx as mx2 } from "@dxos/react-ui-theme";
38
+
39
+ // packages/plugins/experimental/plugin-script/src/components/DebugPanel/DebugPanel.tsx
40
+ import React, { useEffect, useRef, useState } from "react";
41
+ import { log } from "@dxos/log";
42
+ import { Avatar, DensityProvider, Icon, Input, Toolbar, useControlledValue, useTranslation } from "@dxos/react-ui";
43
+ import { SyntaxHighlighter } from "@dxos/react-ui-syntax-highlighter";
44
+ import { mx } from "@dxos/react-ui-theme";
45
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-script/src/components/DebugPanel/DebugPanel.tsx";
46
+ var DebugPanel = ({ classNames, functionUrl, binding: _binding, onBindingChange }) => {
47
+ const { t } = useTranslation(SCRIPT_PLUGIN);
48
+ const bindingInputRef = useRef(null);
49
+ const [binding, setBinding] = useControlledValue(_binding ?? "");
50
+ const handleBlur = () => {
51
+ onBindingChange?.(binding);
52
+ };
53
+ const inputRef = useRef(null);
54
+ const [input, setInput] = useState("");
55
+ const [result, setResult] = useState("");
56
+ const [state, setState] = useState(null);
57
+ const [history, setHistory] = useState([]);
58
+ const scrollerRef = useRef(null);
59
+ const handleScroll = () => {
60
+ if (scrollerRef.current) {
61
+ scrollerRef.current.scrollTop = scrollerRef.current.scrollHeight;
62
+ }
63
+ };
64
+ const controller = useRef();
65
+ useEffect(() => {
66
+ return () => {
67
+ handleStop();
68
+ };
69
+ }, []);
70
+ const handleStop = () => {
71
+ controller.current?.abort("stop");
72
+ controller.current = void 0;
73
+ };
74
+ const handleClear = () => {
75
+ handleStop();
76
+ setInput("");
77
+ setResult("");
78
+ setHistory([]);
79
+ inputRef.current?.focus();
80
+ };
81
+ const handleResponse = ({ text, data, error } = {}) => {
82
+ controller.current = void 0;
83
+ setHistory((history2) => [
84
+ ...history2,
85
+ {
86
+ type: "response",
87
+ text,
88
+ data,
89
+ error
90
+ }
91
+ ]);
92
+ setResult("");
93
+ setState(null);
94
+ handleScroll();
95
+ };
96
+ const handleRequest = async (input2) => {
97
+ try {
98
+ setState("pending");
99
+ let data = null;
100
+ if (input2.charAt(0) === "{") {
101
+ try {
102
+ const validJsonString = input2.replace(/'/g, '"').replace(/([{,]\s*)([a-zA-Z0-9_]+)(\s*:)/g, '$1"$2"$3');
103
+ data = JSON.parse(validJsonString);
104
+ input2 = JSON.stringify(data, null, 2);
105
+ } catch (err) {
106
+ inputRef.current?.focus();
107
+ return;
108
+ }
109
+ }
110
+ setInput("");
111
+ setResult("");
112
+ setHistory((history2) => [
113
+ ...history2,
114
+ {
115
+ type: "request",
116
+ text: input2
117
+ }
118
+ ]);
119
+ setTimeout(() => {
120
+ handleScroll();
121
+ });
122
+ controller.current = new AbortController();
123
+ const response = await fetch(functionUrl, {
124
+ signal: controller.current.signal,
125
+ method: "POST",
126
+ body: input2,
127
+ headers: {
128
+ "Content-Type": data ? "application/json" : "text/plain"
129
+ }
130
+ });
131
+ if (!response.ok) {
132
+ const text2 = await response.text();
133
+ handleResponse({
134
+ error: new Error(text2 || response.statusText || String(response.status))
135
+ });
136
+ return;
137
+ }
138
+ const contentType = response.headers.get("content-type");
139
+ if (contentType === "application/json") {
140
+ const data2 = await response.json();
141
+ handleResponse({
142
+ data: data2
143
+ });
144
+ return;
145
+ }
146
+ setState("responding");
147
+ let text = "";
148
+ const reader = response.body.getReader();
149
+ const pump = async ({ done, value }) => {
150
+ text = text + new TextDecoder().decode(value);
151
+ if (!controller.current || done) {
152
+ handleResponse({
153
+ text
154
+ });
155
+ return;
156
+ }
157
+ setResult(text);
158
+ setTimeout(() => {
159
+ handleScroll();
160
+ });
161
+ return reader.read().then(pump);
162
+ };
163
+ void reader.read().then(pump).catch((err) => {
164
+ if (err.name !== "AbortError") {
165
+ log.catch(err, void 0, {
166
+ F: __dxlog_file,
167
+ L: 163,
168
+ S: void 0,
169
+ C: (f, a) => f(...a)
170
+ });
171
+ }
172
+ });
173
+ } catch (err) {
174
+ if (err !== "stop") {
175
+ const error = err instanceof Error ? err : new Error(err);
176
+ handleResponse({
177
+ error
178
+ });
179
+ log.catch(err, void 0, {
180
+ F: __dxlog_file,
181
+ L: 170,
182
+ S: void 0,
183
+ C: (f, a) => f(...a)
184
+ });
185
+ } else {
186
+ handleResponse();
187
+ }
188
+ }
189
+ };
190
+ return /* @__PURE__ */ React.createElement(DensityProvider, {
191
+ density: "fine"
192
+ }, /* @__PURE__ */ React.createElement("div", {
193
+ className: mx("flex flex-col h-full overflow-hidden", classNames)
194
+ }, /* @__PURE__ */ React.createElement("div", {
195
+ ref: scrollerRef,
196
+ className: "flex flex-col gap-6 h-full p-4 overflow-x-hidden overflow-y-auto"
197
+ }, /* @__PURE__ */ React.createElement(MessageThread, {
198
+ state,
199
+ result,
200
+ history
201
+ })), /* @__PURE__ */ React.createElement(Toolbar.Root, {
202
+ classNames: "p-2"
203
+ }, /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement(Input.TextInput, {
204
+ ref: inputRef,
205
+ autoFocus: true,
206
+ placeholder: t("function request placeholder"),
207
+ value: input,
208
+ onChange: (ev) => setInput(ev.target.value),
209
+ onKeyDown: (ev) => ev.key === "Enter" && handleRequest(input)
210
+ })), /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement(Input.TextInput, {
211
+ ref: bindingInputRef,
212
+ classNames: "!w-[10rem]",
213
+ placeholder: t("binding placeholder"),
214
+ value: binding,
215
+ onChange: (ev) => setBinding(ev.target.value.toUpperCase()),
216
+ onBlur: handleBlur
217
+ })), /* @__PURE__ */ React.createElement(Toolbar.Button, {
218
+ onClick: () => handleRequest(input)
219
+ }, /* @__PURE__ */ React.createElement(Icon, {
220
+ icon: "ph--play--regular",
221
+ size: 4
222
+ })), /* @__PURE__ */ React.createElement(Toolbar.Button, {
223
+ onClick: () => state ? handleStop() : handleClear()
224
+ }, /* @__PURE__ */ React.createElement(Icon, {
225
+ icon: state ? "ph--stop--regular" : "ph--trash--regular",
226
+ size: 4
227
+ })))));
228
+ };
229
+ var MessageThread = ({ state, result, history }) => {
230
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, history.map((message, i) => /* @__PURE__ */ React.createElement("div", {
231
+ key: i,
232
+ className: "grid grid-cols-[3rem_1fr_3rem]"
233
+ }, /* @__PURE__ */ React.createElement("div", {
234
+ className: "p-1"
235
+ }, message.type === "response" && /* @__PURE__ */ React.createElement(RobotAvatar, null)), /* @__PURE__ */ React.createElement("div", {
236
+ className: "overflow-auto"
237
+ }, /* @__PURE__ */ React.createElement(MessageItem, {
238
+ message
239
+ })))), result?.length > 0 && /* @__PURE__ */ React.createElement("div", {
240
+ className: "grid grid-cols-[3rem_1fr_3rem]"
241
+ }, /* @__PURE__ */ React.createElement("div", {
242
+ className: "p-1"
243
+ }, state === "pending" && /* @__PURE__ */ React.createElement(Icon, {
244
+ icon: "ph--spinner--regular",
245
+ size: 6,
246
+ classNames: "animate-spin"
247
+ }) || /* @__PURE__ */ React.createElement(Icon, {
248
+ icon: "ph--robot--regular",
249
+ size: 6,
250
+ classNames: "animate-[pulse_1s_ease-in-out_infinite]"
251
+ })), /* @__PURE__ */ React.createElement("div", {
252
+ className: "overflow-auto"
253
+ }, /* @__PURE__ */ React.createElement(MessageItem, {
254
+ message: {
255
+ type: "response",
256
+ text: result
257
+ }
258
+ }))));
259
+ };
260
+ var MessageItem = ({ classNames, message }) => {
261
+ const { type, text, data, error } = message;
262
+ const wrapper = "p-1 px-2 rounded-lg bg-hoverSurface overflow-auto";
263
+ return /* @__PURE__ */ React.createElement("div", {
264
+ className: mx("flex", type === "request" ? "ml-[8rem] justify-end" : "mr-[8rem]", classNames)
265
+ }, error && /* @__PURE__ */ React.createElement("div", {
266
+ className: mx(wrapper, "whitespace-pre text-error")
267
+ }, String(error)), text !== void 0 && /* @__PURE__ */ React.createElement("div", {
268
+ className: mx(wrapper, type === "request" && "bg-primary-400 dark:bg-primary-600")
269
+ }, text || "\xD8"), data && /* @__PURE__ */ React.createElement(SyntaxHighlighter, {
270
+ language: "json",
271
+ className: mx(wrapper, "px-8 py-2 text-xs")
272
+ }, JSON.stringify(data, null, 2)));
273
+ };
274
+ var RobotAvatar = () => /* @__PURE__ */ React.createElement(Avatar.Root, {
275
+ size: 6,
276
+ variant: "circle"
277
+ }, /* @__PURE__ */ React.createElement(Avatar.Frame, null, /* @__PURE__ */ React.createElement(Avatar.Icon, {
278
+ icon: "ph--robot--regular"
279
+ })));
280
+
281
+ // packages/plugins/experimental/plugin-script/src/components/Toolbar/Toolbar.tsx
282
+ import React2, { useState as useState2 } from "react";
283
+ import { DensityProvider as DensityProvider2, ElevationProvider, Icon as Icon2, Select, ToggleGroup, ToggleGroupItem, Toolbar as NaturalToolbar, Tooltip, useTranslation as useTranslation2 } from "@dxos/react-ui";
284
+ var Toolbar2 = ({ classNames, deployed, error, functionUrl, view, templates: templates2, onDeploy, onFormat, onViewChange, onTemplateSelect }) => {
285
+ const { t } = useTranslation2(SCRIPT_PLUGIN);
286
+ const [pending, setPending] = useState2(false);
287
+ const handleCopyLink = async () => {
288
+ if (!functionUrl) {
289
+ return;
290
+ }
291
+ await navigator.clipboard.writeText(functionUrl);
292
+ };
293
+ const handleDeploy = async () => {
294
+ if (!pending) {
295
+ setPending(true);
296
+ await onDeploy?.();
297
+ setPending(false);
298
+ }
299
+ };
300
+ return /* @__PURE__ */ React2.createElement(DensityProvider2, {
301
+ density: "fine"
302
+ }, /* @__PURE__ */ React2.createElement(ElevationProvider, {
303
+ elevation: "chrome"
304
+ }, /* @__PURE__ */ React2.createElement(NaturalToolbar.Root, {
305
+ classNames: [
306
+ "p-1",
307
+ classNames
308
+ ],
309
+ style: {
310
+ contain: "layout"
311
+ }
312
+ }, templates2 && /* @__PURE__ */ React2.createElement(TemplateSelect, {
313
+ templates: templates2,
314
+ onTemplateSelect
315
+ }), onFormat && /* @__PURE__ */ React2.createElement(ToolbarIconButton, {
316
+ icon: "ph--magic-wand--regular",
317
+ text: t("format label"),
318
+ onClick: onFormat
319
+ }), /* @__PURE__ */ React2.createElement("div", {
320
+ role: "separator",
321
+ className: "grow"
322
+ }), error ? /* @__PURE__ */ React2.createElement(Tooltip.Root, null, /* @__PURE__ */ React2.createElement(Tooltip.Trigger, null, /* @__PURE__ */ React2.createElement(Icon2, {
323
+ icon: "ph--warning-circle--regular",
324
+ size: 4
325
+ })), /* @__PURE__ */ React2.createElement(Tooltip.Portal, null, /* @__PURE__ */ React2.createElement(Tooltip.Content, null, /* @__PURE__ */ React2.createElement(Tooltip.Arrow, null), error))) : null, functionUrl && deployed && /* @__PURE__ */ React2.createElement(ToolbarIconButton, {
326
+ icon: "ph--link--regular",
327
+ text: t("copy link label"),
328
+ onClick: handleCopyLink
329
+ }), onDeploy && /* @__PURE__ */ React2.createElement(ToolbarIconButton, {
330
+ icon: pending ? "ph--spinner-gap--regular" : "ph--cloud-arrow-up--regular",
331
+ classNames: [
332
+ pending && "animate-spin"
333
+ ],
334
+ text: pending ? t("pending label") : t("deploy label"),
335
+ onClick: handleDeploy
336
+ }), /* @__PURE__ */ React2.createElement(ViewSelector, {
337
+ view,
338
+ onViewChange
339
+ }))));
340
+ };
341
+ var ToolbarIconButton = ({ icon, text, classNames, disabled, onClick }) => {
342
+ return /* @__PURE__ */ React2.createElement(Tooltip.Root, null, /* @__PURE__ */ React2.createElement(Tooltip.Trigger, {
343
+ asChild: true
344
+ }, /* @__PURE__ */ React2.createElement(NaturalToolbar.Button, {
345
+ variant: "ghost",
346
+ disabled,
347
+ onClick
348
+ }, /* @__PURE__ */ React2.createElement(Icon2, {
349
+ icon,
350
+ size: 4,
351
+ classNames
352
+ }))), /* @__PURE__ */ React2.createElement(Tooltip.Portal, null, /* @__PURE__ */ React2.createElement(Tooltip.Content, null, /* @__PURE__ */ React2.createElement(Tooltip.Arrow, null), text)));
353
+ };
354
+ var TemplateSelect = ({ templates: templates2 = [], onTemplateSelect }) => {
355
+ return /* @__PURE__ */ React2.createElement(Select.Root, {
356
+ value: "",
357
+ onValueChange: onTemplateSelect
358
+ }, /* @__PURE__ */ React2.createElement(Select.TriggerButton, null), /* @__PURE__ */ React2.createElement(Select.Portal, null, /* @__PURE__ */ React2.createElement(Select.Content, null, /* @__PURE__ */ React2.createElement(Select.Viewport, null, /* @__PURE__ */ React2.createElement(Select.Option, {
359
+ value: ""
360
+ }, "Template"), templates2.map(({ id, name }) => /* @__PURE__ */ React2.createElement(Select.Option, {
361
+ key: id,
362
+ value: id
363
+ }, name))))));
364
+ };
365
+ var ViewSelector = ({ view, onViewChange }) => {
366
+ return /* @__PURE__ */ React2.createElement(ToggleGroup, {
367
+ type: "single",
368
+ value: view,
369
+ onValueChange: (value) => onViewChange?.(value)
370
+ }, /* @__PURE__ */ React2.createElement(ToggleGroupItem, {
371
+ value: "editor",
372
+ classNames: "bg-transparent text-subdued"
373
+ }, /* @__PURE__ */ React2.createElement(Icon2, {
374
+ icon: "ph--code--regular",
375
+ size: 4
376
+ })), /* @__PURE__ */ React2.createElement(ToggleGroupItem, {
377
+ value: "split",
378
+ classNames: "bg-transparent text-subdued"
379
+ }, /* @__PURE__ */ React2.createElement(Icon2, {
380
+ icon: "ph--square-split-vertical--regular",
381
+ size: 4
382
+ })), /* @__PURE__ */ React2.createElement(ToggleGroupItem, {
383
+ value: "preview",
384
+ classNames: "bg-transparent text-subdued"
385
+ }, /* @__PURE__ */ React2.createElement(Icon2, {
386
+ icon: "ph--eye--regular",
387
+ size: 4
388
+ })));
389
+ };
390
+
391
+ // packages/plugins/experimental/plugin-script/src/components/TypescriptEditor/TypescriptEditor.tsx
392
+ import { javascript } from "@codemirror/lang-javascript";
393
+ import { tsSync, tsFacet, tsLinter, tsAutocomplete, tsHover } from "@valtown/codemirror-ts";
394
+ import React3 from "react";
395
+ import { useThemeContext } from "@dxos/react-ui";
396
+ import { autocomplete, createBasicExtensions, createThemeExtensions, editorFullWidth, editorGutter, editorMonospace, InputModeExtensions, useTextEditor } from "@dxos/react-ui-editor";
397
+ import { nonNullable } from "@dxos/util";
398
+ var TypescriptEditor = ({ id, env, className, initialValue, extensions, scrollTo, selection }) => {
399
+ const { themeMode } = useThemeContext();
400
+ const { parentRef, focusAttributes } = useTextEditor(() => ({
401
+ id,
402
+ initialValue,
403
+ extensions: [
404
+ extensions,
405
+ createBasicExtensions({
406
+ highlightActiveLine: true,
407
+ indentWithTab: true,
408
+ lineNumbers: true,
409
+ lineWrapping: false,
410
+ scrollPastEnd: true
411
+ }),
412
+ createThemeExtensions({
413
+ themeMode,
414
+ syntaxHighlighting: true,
415
+ slots: {
416
+ content: {
417
+ className: editorFullWidth
418
+ }
419
+ }
420
+ }),
421
+ editorGutter,
422
+ // TODO(burdon): Factor out.
423
+ [
424
+ editorMonospace,
425
+ javascript({
426
+ typescript: true
427
+ }),
428
+ // https://github.com/val-town/codemirror-ts
429
+ autocomplete({
430
+ override: env ? [
431
+ tsAutocomplete()
432
+ ] : []
433
+ }),
434
+ env ? [
435
+ tsFacet.of({
436
+ env,
437
+ path: `/src/${id}.ts`
438
+ }),
439
+ tsSync(),
440
+ tsLinter(),
441
+ tsHover()
442
+ ] : [],
443
+ InputModeExtensions.vscode
444
+ ]
445
+ ].filter(nonNullable),
446
+ selection,
447
+ scrollTo
448
+ }), [
449
+ id,
450
+ initialValue,
451
+ extensions,
452
+ themeMode,
453
+ selection,
454
+ scrollTo
455
+ ]);
456
+ return /* @__PURE__ */ React3.createElement("div", {
457
+ ref: parentRef,
458
+ className,
459
+ ...focusAttributes
460
+ });
461
+ };
462
+
463
+ // packages/plugins/experimental/plugin-script/src/components/ScriptEditor.tsx
464
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-script/src/components/ScriptEditor.tsx";
465
+ var ScriptEditor = ({ classNames, script, env }) => {
466
+ const { t } = useTranslation3(SCRIPT_PLUGIN);
467
+ const client = useClient();
468
+ const identity = useIdentity();
469
+ const space = getSpace(script);
470
+ const [fn] = useQuery(space, Filter.schema(FunctionType, (fn2) => fn2.source === script));
471
+ const extensions = useMemo(() => [
472
+ listener({
473
+ onChange: (text) => {
474
+ if (script.source && script.source?.content !== text) {
475
+ script.changed = true;
476
+ }
477
+ }
478
+ }),
479
+ createDataExtensions({
480
+ id: script.id,
481
+ text: script.source && createDocAccessor(script.source, [
482
+ "content"
483
+ ]),
484
+ space,
485
+ identity
486
+ })
487
+ ], [
488
+ script,
489
+ script.source,
490
+ space,
491
+ identity
492
+ ]);
493
+ const [view, setView] = useState3("editor");
494
+ const initialValue = useMemo(() => script.source?.content, [
495
+ script.source
496
+ ]);
497
+ const existingFunctionUrl = fn && getUserFunctionUrlInMetadata(getMeta(fn));
498
+ const [error, setError] = useState3();
499
+ const handleBindingChange = useCallback((binding) => {
500
+ fn.binding = binding;
501
+ }, [
502
+ fn
503
+ ]);
504
+ const handleFormat = useCallback(async () => {
505
+ if (!script.source) {
506
+ return;
507
+ }
508
+ try {
509
+ script.source.content = await format(script.source.content, {
510
+ parser: "typescript",
511
+ plugins: [
512
+ prettierPluginEstree,
513
+ prettierPluginTypescript
514
+ ],
515
+ semi: true,
516
+ singleQuote: true
517
+ });
518
+ } catch (err) {
519
+ log2.catch(err, void 0, {
520
+ F: __dxlog_file2,
521
+ L: 94,
522
+ S: void 0,
523
+ C: (f, a) => f(...a)
524
+ });
525
+ }
526
+ }, [
527
+ script.source
528
+ ]);
529
+ const handleTemplateChange = (id) => {
530
+ const template = templates.find((template2) => template2.id === id);
531
+ if (template) {
532
+ script.name = template.name;
533
+ script.source.content = template.source;
534
+ const metaKeys = getMeta(script).keys;
535
+ const oldPresetIndex = metaKeys.findIndex((key) => key.source === USERFUNCTIONS_PRESET_META_KEY);
536
+ if (oldPresetIndex >= 0) {
537
+ metaKeys.splice(oldPresetIndex, 1);
538
+ }
539
+ if (template.presetId) {
540
+ metaKeys.push({
541
+ source: USERFUNCTIONS_PRESET_META_KEY,
542
+ id: template.presetId
543
+ });
544
+ }
545
+ }
546
+ };
547
+ const handleDeploy = useCallback(async () => {
548
+ if (!script.source || !identity || !space) {
549
+ return;
550
+ }
551
+ setError(void 0);
552
+ try {
553
+ const existingFunctionId = existingFunctionUrl?.split("/").at(-1);
554
+ const ownerDid = existingFunctionUrl?.split("/").at(-2) ?? publicKeyToDid(identity.identityKey);
555
+ const bundler = new Bundler({
556
+ platform: "browser",
557
+ sandboxedModules: [],
558
+ remoteModules: {}
559
+ });
560
+ const buildResult = await bundler.bundle(script.source.content);
561
+ if (buildResult.error || !buildResult.bundle) {
562
+ throw buildResult.error;
563
+ }
564
+ const { result, functionId, functionVersionNumber, errorMessage } = await uploadWorkerFunction({
565
+ clientConfig: client.config,
566
+ halo: client.halo,
567
+ ownerDid,
568
+ functionId: existingFunctionId,
569
+ source: buildResult.bundle
570
+ });
571
+ if (result !== "success" || functionId === void 0 || functionVersionNumber === void 0) {
572
+ throw new Error(errorMessage);
573
+ }
574
+ log2.info("function uploaded", {
575
+ functionId,
576
+ functionVersionNumber
577
+ }, {
578
+ F: __dxlog_file2,
579
+ L: 142,
580
+ S: void 0,
581
+ C: (f, a) => f(...a)
582
+ });
583
+ if (fn) {
584
+ fn.version = functionVersionNumber;
585
+ }
586
+ const deployedFunction = fn ?? space.db.add(create(FunctionType, {
587
+ version: functionVersionNumber,
588
+ source: script
589
+ }));
590
+ const meta = getMeta(deployedFunction);
591
+ script.changed = false;
592
+ setUserFunctionUrlInMetadata(meta, `/${ownerDid}/${functionId}`);
593
+ setView("split");
594
+ } catch (err) {
595
+ log2.catch(err, void 0, {
596
+ F: __dxlog_file2,
597
+ L: 154,
598
+ S: void 0,
599
+ C: (f, a) => f(...a)
600
+ });
601
+ setError(t("upload failed label"));
602
+ }
603
+ }, [
604
+ fn,
605
+ existingFunctionUrl,
606
+ script,
607
+ script.name,
608
+ script.source
609
+ ]);
610
+ const functionUrl = useMemo(() => {
611
+ if (!existingFunctionUrl) {
612
+ return;
613
+ }
614
+ const baseUrl = new URL("functions/", client.config.values.runtime?.services?.edge?.url);
615
+ const relativeUrl = existingFunctionUrl.replace(/^\//, "");
616
+ const url = new URL(`./${relativeUrl}`, baseUrl.toString());
617
+ space && url.searchParams.set("spaceId", space.id);
618
+ url.protocol = "https";
619
+ return url.toString();
620
+ }, [
621
+ existingFunctionUrl,
622
+ space
623
+ ]);
624
+ return /* @__PURE__ */ React4.createElement("div", {
625
+ role: "none",
626
+ className: mx2("flex flex-col w-full overflow-hidden divide-y divide-separator", classNames)
627
+ }, /* @__PURE__ */ React4.createElement(Toolbar2, {
628
+ deployed: Boolean(existingFunctionUrl) && !script.changed,
629
+ functionUrl,
630
+ error,
631
+ view,
632
+ templates,
633
+ onDeploy: handleDeploy,
634
+ onFormat: handleFormat,
635
+ onViewChange: setView,
636
+ onTemplateSelect: handleTemplateChange
637
+ }), view !== "preview" && /* @__PURE__ */ React4.createElement(TypescriptEditor, {
638
+ id: script.id,
639
+ env,
640
+ initialValue,
641
+ extensions,
642
+ className: "flex is-full bs-full overflow-hidden ch-focus-ring-inset-over-all"
643
+ }), view !== "editor" && /* @__PURE__ */ React4.createElement(DebugPanel, {
644
+ functionUrl,
645
+ binding: fn?.binding,
646
+ onBindingChange: handleBindingChange
647
+ }));
648
+ };
649
+
650
+ // packages/plugins/experimental/plugin-script/src/components/ScriptContainer.tsx
651
+ var ScriptContainer = ({ script, ...props }) => {
652
+ const attendableAttrs = useAttendableAttributes(fullyQualifiedId(script));
653
+ return /* @__PURE__ */ React5.createElement("div", {
654
+ role: "none",
655
+ className: mx3("flex row-span-2 w-full overflow-hidden attention-surface"),
656
+ ...attendableAttrs
657
+ }, /* @__PURE__ */ React5.createElement(ScriptEditor, {
658
+ ...props,
659
+ script
660
+ }));
661
+ };
662
+ var ScriptContainer_default = ScriptContainer;
663
+ export {
664
+ ScriptContainer_default as default
665
+ };
666
+ //# sourceMappingURL=ScriptContainer-EAE6L5JV.mjs.map