@dxos/plugin-script 0.6.13-staging.1e988a3 → 0.6.14-main.2b6a0f3

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 (202) hide show
  1. package/README.md +1 -1
  2. package/dist/lib/browser/AutomationPanel-Y7LQYFOY.mjs +78 -0
  3. package/dist/lib/browser/AutomationPanel-Y7LQYFOY.mjs.map +7 -0
  4. package/dist/lib/browser/ScriptContainer-KGZGB5AY.mjs +423 -0
  5. package/dist/lib/browser/ScriptContainer-KGZGB5AY.mjs.map +7 -0
  6. package/dist/lib/browser/{chunk-RHEZ5LUU.mjs → chunk-C4AX55JL.mjs} +51 -2
  7. package/dist/lib/browser/{chunk-RHEZ5LUU.mjs.map → chunk-C4AX55JL.mjs.map} +4 -4
  8. package/dist/lib/browser/{chunk-DL5XQRQM.mjs → chunk-KHNN3F7J.mjs} +18 -6
  9. package/dist/lib/browser/chunk-KHNN3F7J.mjs.map +7 -0
  10. package/dist/lib/browser/{chunk-O4LWBX6A.mjs → chunk-KXVQPS4Y.mjs} +2 -2
  11. package/dist/lib/browser/{chunk-O4LWBX6A.mjs.map → chunk-KXVQPS4Y.mjs.map} +2 -2
  12. package/dist/lib/browser/chunk-SGQHRB4P.mjs +17 -0
  13. package/dist/lib/browser/chunk-SGQHRB4P.mjs.map +7 -0
  14. package/dist/lib/browser/chunk-SP3Q7BCM.mjs +248 -0
  15. package/dist/lib/browser/chunk-SP3Q7BCM.mjs.map +7 -0
  16. package/dist/lib/browser/edge/index.mjs +5 -1
  17. package/dist/lib/browser/index.mjs +86 -61
  18. package/dist/lib/browser/index.mjs.map +4 -4
  19. package/dist/lib/browser/meta.json +1 -1
  20. package/dist/lib/browser/meta.mjs +1 -1
  21. package/dist/lib/browser/types/index.mjs +2 -2
  22. package/dist/lib/node/AutomationPanel-UNLRYLMA.cjs +100 -0
  23. package/dist/lib/node/AutomationPanel-UNLRYLMA.cjs.map +7 -0
  24. package/dist/lib/node/ScriptContainer-BIBIIJHP.cjs +425 -0
  25. package/dist/lib/node/ScriptContainer-BIBIIJHP.cjs.map +7 -0
  26. package/dist/lib/node/{chunk-5RBVXKXT.cjs → chunk-25PQE7FL.cjs} +6 -6
  27. package/dist/lib/node/{chunk-5RBVXKXT.cjs.map → chunk-25PQE7FL.cjs.map} +2 -2
  28. package/dist/lib/node/{TypescriptEditor-M3WWFIP2.cjs → chunk-EJC55SDD.cjs} +18 -8
  29. package/dist/lib/node/chunk-EJC55SDD.cjs.map +7 -0
  30. package/dist/lib/node/{chunk-PFH3ROEH.cjs → chunk-FY5KKL5N.cjs} +22 -8
  31. package/dist/lib/node/chunk-FY5KKL5N.cjs.map +7 -0
  32. package/dist/lib/node/{chunk-4GTXIELQ.cjs → chunk-NKWNQMJH.cjs} +44 -6
  33. package/dist/lib/node/chunk-NKWNQMJH.cjs.map +7 -0
  34. package/dist/lib/node/chunk-NWBG5QDN.cjs +277 -0
  35. package/dist/lib/node/chunk-NWBG5QDN.cjs.map +7 -0
  36. package/dist/lib/node/edge/index.cjs +12 -8
  37. package/dist/lib/node/edge/index.cjs.map +2 -2
  38. package/dist/lib/node/index.cjs +103 -82
  39. package/dist/lib/node/index.cjs.map +4 -4
  40. package/dist/lib/node/meta.cjs +3 -3
  41. package/dist/lib/node/meta.cjs.map +1 -1
  42. package/dist/lib/node/meta.json +1 -1
  43. package/dist/lib/node/types/index.cjs +5 -5
  44. package/dist/lib/node/types/index.cjs.map +1 -1
  45. package/dist/lib/node-esm/AutomationPanel-D4NHEKM6.mjs +79 -0
  46. package/dist/lib/node-esm/AutomationPanel-D4NHEKM6.mjs.map +7 -0
  47. package/dist/lib/node-esm/ScriptContainer-4VQ46IAZ.mjs +424 -0
  48. package/dist/lib/node-esm/ScriptContainer-4VQ46IAZ.mjs.map +7 -0
  49. package/dist/lib/node-esm/chunk-7EDYDVQH.mjs +47 -0
  50. package/dist/lib/node-esm/chunk-7EDYDVQH.mjs.map +7 -0
  51. package/dist/lib/node-esm/chunk-EEDWDGZT.mjs +249 -0
  52. package/dist/lib/node-esm/chunk-EEDWDGZT.mjs.map +7 -0
  53. package/dist/lib/node-esm/chunk-GO7HYFM5.mjs +19 -0
  54. package/dist/lib/node-esm/chunk-GO7HYFM5.mjs.map +7 -0
  55. package/dist/lib/node-esm/chunk-QMTTZYLF.mjs +255 -0
  56. package/dist/lib/node-esm/chunk-QMTTZYLF.mjs.map +7 -0
  57. package/dist/lib/node-esm/chunk-YIISE4MX.mjs +280 -0
  58. package/dist/lib/node-esm/chunk-YIISE4MX.mjs.map +7 -0
  59. package/dist/lib/node-esm/edge/index.mjs +24 -0
  60. package/dist/lib/node-esm/index.mjs +317 -0
  61. package/dist/lib/node-esm/index.mjs.map +7 -0
  62. package/dist/lib/node-esm/meta.json +1 -0
  63. package/dist/lib/node-esm/meta.mjs +10 -0
  64. package/dist/lib/node-esm/meta.mjs.map +7 -0
  65. package/dist/lib/node-esm/types/index.mjs +13 -0
  66. package/dist/lib/node-esm/types/index.mjs.map +7 -0
  67. package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
  68. package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts +17 -0
  69. package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts.map +1 -0
  70. package/dist/types/src/components/AutomationPanel/index.d.ts +4 -0
  71. package/dist/types/src/components/AutomationPanel/index.d.ts.map +1 -0
  72. package/dist/types/src/components/{DebugPanel.d.ts → DebugPanel/DebugPanel.d.ts} +2 -1
  73. package/dist/types/src/components/DebugPanel/DebugPanel.d.ts.map +1 -0
  74. package/dist/types/src/components/DebugPanel/index.d.ts +2 -0
  75. package/dist/types/src/components/DebugPanel/index.d.ts.map +1 -0
  76. package/dist/types/src/components/{ScriptBlock/FrameContainer → FrameContainer}/FrameContainer.d.ts +1 -1
  77. package/dist/types/src/components/FrameContainer/FrameContainer.d.ts.map +1 -0
  78. package/dist/types/src/components/FrameContainer/frame.d.ts.map +1 -0
  79. package/dist/types/src/components/FrameContainer/index.d.ts.map +1 -0
  80. package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts +1 -3
  81. package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts.map +1 -1
  82. package/dist/types/src/components/ScriptBlock/ScriptBlock.stories.d.ts +3 -8
  83. package/dist/types/src/components/ScriptBlock/ScriptBlock.stories.d.ts.map +1 -1
  84. package/dist/types/src/components/ScriptContainer.d.ts +5 -0
  85. package/dist/types/src/components/ScriptContainer.d.ts.map +1 -0
  86. package/dist/types/src/components/ScriptEditor.d.ts +4 -5
  87. package/dist/types/src/components/ScriptEditor.d.ts.map +1 -1
  88. package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts +6 -0
  89. package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts.map +1 -0
  90. package/dist/types/src/components/ScriptSettings/index.d.ts +2 -0
  91. package/dist/types/src/components/ScriptSettings/index.d.ts.map +1 -0
  92. package/dist/types/src/components/Toolbar/Toolbar.d.ts +23 -0
  93. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -0
  94. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +14 -0
  95. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -0
  96. package/dist/types/src/components/Toolbar/index.d.ts +2 -0
  97. package/dist/types/src/components/Toolbar/index.d.ts.map +1 -0
  98. package/dist/types/src/components/{TypescriptEditor.d.ts → TypescriptEditor/TypescriptEditor.d.ts} +1 -2
  99. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -0
  100. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts +6 -0
  101. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts.map +1 -0
  102. package/dist/types/src/components/TypescriptEditor/index.d.ts +2 -0
  103. package/dist/types/src/components/TypescriptEditor/index.d.ts.map +1 -0
  104. package/dist/types/src/components/index.d.ts +3 -3
  105. package/dist/types/src/components/index.d.ts.map +1 -1
  106. package/dist/types/src/edge/functions.d.ts +7 -0
  107. package/dist/types/src/edge/functions.d.ts.map +1 -1
  108. package/dist/types/src/meta.d.ts +4 -9
  109. package/dist/types/src/meta.d.ts.map +1 -1
  110. package/dist/types/src/templates/chat.d.ts +6 -0
  111. package/dist/types/src/templates/chat.d.ts.map +1 -0
  112. package/dist/types/src/templates/chess.d.ts +6 -0
  113. package/dist/types/src/templates/chess.d.ts.map +1 -0
  114. package/dist/types/src/templates/echo.d.ts +6 -0
  115. package/dist/types/src/templates/echo.d.ts.map +1 -0
  116. package/dist/types/src/templates/email.d.ts +6 -0
  117. package/dist/types/src/templates/email.d.ts.map +1 -0
  118. package/dist/types/src/templates/forex.d.ts +6 -0
  119. package/dist/types/src/templates/forex.d.ts.map +1 -0
  120. package/dist/types/src/templates.d.ts +8 -0
  121. package/dist/types/src/templates.d.ts.map +1 -0
  122. package/dist/types/src/translations.d.ts +2 -0
  123. package/dist/types/src/translations.d.ts.map +1 -1
  124. package/dist/types/src/types/script.d.ts +4 -4
  125. package/dist/types/src/types/types.d.ts +4 -3
  126. package/dist/types/src/types/types.d.ts.map +1 -1
  127. package/package.json +62 -55
  128. package/src/ScriptPlugin.tsx +26 -39
  129. package/src/bundler/bundler.test.ts +12 -2
  130. package/src/components/AutomationPanel/AutomationPanel.tsx +101 -0
  131. package/src/components/AutomationPanel/index.ts +9 -0
  132. package/src/components/{DebugPanel.tsx → DebugPanel/DebugPanel.tsx} +83 -78
  133. package/src/components/DebugPanel/index.ts +5 -0
  134. package/src/components/{ScriptBlock/FrameContainer → FrameContainer}/FrameContainer.tsx +1 -1
  135. package/src/components/ScriptBlock/ScriptBlock.stories.tsx +15 -14
  136. package/src/components/ScriptBlock/ScriptBlock.tsx +23 -51
  137. package/src/components/ScriptContainer.tsx +22 -0
  138. package/src/components/ScriptEditor.tsx +58 -55
  139. package/src/components/ScriptSettings/ScriptSettings.tsx +47 -0
  140. package/src/components/ScriptSettings/index.ts +5 -0
  141. package/src/components/Toolbar/Toolbar.stories.tsx +30 -0
  142. package/src/components/Toolbar/Toolbar.tsx +177 -0
  143. package/src/components/{ScriptBlock/Splitter → Toolbar}/index.ts +1 -1
  144. package/src/components/{TypescriptEditor.stories.tsx → TypescriptEditor/TypescriptEditor.stories.tsx} +17 -35
  145. package/src/components/{TypescriptEditor.tsx → TypescriptEditor/TypescriptEditor.tsx} +1 -3
  146. package/src/components/TypescriptEditor/index.ts +5 -0
  147. package/src/components/index.ts +5 -3
  148. package/src/edge/functions.ts +19 -0
  149. package/src/meta.ts +15 -0
  150. package/src/templates/chat.ts +102 -0
  151. package/src/templates/chess.ts +41 -0
  152. package/src/templates/echo.ts +15 -0
  153. package/src/templates/email.ts +38 -0
  154. package/src/templates/forex.ts +21 -0
  155. package/src/templates.ts +54 -0
  156. package/src/translations.ts +2 -0
  157. package/src/types/types.ts +9 -5
  158. package/dist/lib/browser/ScriptEditor-5Y3EROG3.mjs +0 -513
  159. package/dist/lib/browser/ScriptEditor-5Y3EROG3.mjs.map +0 -7
  160. package/dist/lib/browser/TypescriptEditor-GPE72Y6I.mjs +0 -9
  161. package/dist/lib/browser/chunk-DL5XQRQM.mjs.map +0 -7
  162. package/dist/lib/browser/chunk-JBACGDOJ.mjs +0 -21
  163. package/dist/lib/browser/chunk-JBACGDOJ.mjs.map +0 -7
  164. package/dist/lib/browser/chunk-MRGOT5RF.mjs +0 -78
  165. package/dist/lib/browser/chunk-MRGOT5RF.mjs.map +0 -7
  166. package/dist/lib/node/ScriptEditor-YCUQFWQM.cjs +0 -526
  167. package/dist/lib/node/ScriptEditor-YCUQFWQM.cjs.map +0 -7
  168. package/dist/lib/node/TypescriptEditor-M3WWFIP2.cjs.map +0 -7
  169. package/dist/lib/node/chunk-4GTXIELQ.cjs.map +0 -7
  170. package/dist/lib/node/chunk-4VMNBXWU.cjs +0 -54
  171. package/dist/lib/node/chunk-4VMNBXWU.cjs.map +0 -7
  172. package/dist/lib/node/chunk-IMLDKD5Y.cjs +0 -111
  173. package/dist/lib/node/chunk-IMLDKD5Y.cjs.map +0 -7
  174. package/dist/lib/node/chunk-PFH3ROEH.cjs.map +0 -7
  175. package/dist/types/src/components/DebugPanel.d.ts.map +0 -1
  176. package/dist/types/src/components/ScriptBlock/FrameContainer/FrameContainer.d.ts.map +0 -1
  177. package/dist/types/src/components/ScriptBlock/FrameContainer/frame.d.ts.map +0 -1
  178. package/dist/types/src/components/ScriptBlock/FrameContainer/index.d.ts.map +0 -1
  179. package/dist/types/src/components/ScriptBlock/Splitter/Splitter.d.ts +0 -15
  180. package/dist/types/src/components/ScriptBlock/Splitter/Splitter.d.ts.map +0 -1
  181. package/dist/types/src/components/ScriptBlock/Splitter/Splitter.stories.d.ts +0 -13
  182. package/dist/types/src/components/ScriptBlock/Splitter/Splitter.stories.d.ts.map +0 -1
  183. package/dist/types/src/components/ScriptBlock/Splitter/index.d.ts +0 -2
  184. package/dist/types/src/components/ScriptBlock/Splitter/index.d.ts.map +0 -1
  185. package/dist/types/src/components/Toolbar.d.ts +0 -13
  186. package/dist/types/src/components/Toolbar.d.ts.map +0 -1
  187. package/dist/types/src/components/Toolbar.stories.d.ts +0 -14
  188. package/dist/types/src/components/Toolbar.stories.d.ts.map +0 -1
  189. package/dist/types/src/components/TypescriptEditor.d.ts.map +0 -1
  190. package/dist/types/src/components/TypescriptEditor.stories.d.ts +0 -10
  191. package/dist/types/src/components/TypescriptEditor.stories.d.ts.map +0 -1
  192. package/src/components/ScriptBlock/Splitter/Splitter.stories.tsx +0 -37
  193. package/src/components/ScriptBlock/Splitter/Splitter.tsx +0 -52
  194. package/src/components/Toolbar.stories.tsx +0 -17
  195. package/src/components/Toolbar.tsx +0 -147
  196. package/src/meta.tsx +0 -19
  197. /package/dist/lib/{browser/TypescriptEditor-GPE72Y6I.mjs.map → node-esm/edge/index.mjs.map} +0 -0
  198. /package/dist/types/src/components/{ScriptBlock/FrameContainer → FrameContainer}/frame.d.ts +0 -0
  199. /package/dist/types/src/components/{ScriptBlock/FrameContainer → FrameContainer}/index.d.ts +0 -0
  200. /package/src/components/{ScriptBlock/FrameContainer → FrameContainer}/frame.html +0 -0
  201. /package/src/components/{ScriptBlock/FrameContainer → FrameContainer}/frame.tsx +0 -0
  202. /package/src/components/{ScriptBlock/FrameContainer → FrameContainer}/index.ts +0 -0
@@ -0,0 +1,54 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ // @ts-ignore
6
+ import chat from './templates/chat.ts?raw';
7
+ // @ts-ignore
8
+ import chess from './templates/chess.ts?raw';
9
+ // @ts-ignore
10
+ import echo from './templates/echo.ts?raw';
11
+ // @ts-ignore
12
+ import email from './templates/email.ts?raw';
13
+ // @ts-ignore
14
+ import forex from './templates/forex.ts?raw';
15
+
16
+ const removeHeader = (str: string) => str.split('\n').slice(4).join('\n');
17
+
18
+ export type Template = {
19
+ id: string;
20
+ name: string;
21
+ source: string;
22
+ presetId?: string;
23
+ };
24
+
25
+ export const templates: Template[] = [
26
+ {
27
+ id: 'dxos.org/script/echo',
28
+ name: 'Echo',
29
+ source: removeHeader(echo),
30
+ },
31
+ {
32
+ id: 'dxos.org/script/forex',
33
+ name: 'Forex',
34
+ source: removeHeader(forex),
35
+ },
36
+ {
37
+ id: 'dxos.org/script/gpt',
38
+ name: 'Gpt',
39
+ source: removeHeader(chat),
40
+ presetId: 'dxos.org/function/gpt',
41
+ },
42
+ {
43
+ id: 'dxos.org/script/chess',
44
+ name: 'Chess',
45
+ source: removeHeader(chess),
46
+ presetId: 'dxos.org/function/chess',
47
+ },
48
+ {
49
+ id: 'dxos.org/script/email',
50
+ name: 'Email',
51
+ source: removeHeader(email),
52
+ presetId: 'dxos.org/function/email',
53
+ },
54
+ ];
@@ -20,6 +20,8 @@ export default [
20
20
  'copy link label': 'Copy function link',
21
21
  'format label': 'Format',
22
22
  'toggle details label': 'Toggle details panel',
23
+ 'authenticate action label': 'Authenticate functions service',
24
+ 'authenticate button label': 'Authenticate',
23
25
  },
24
26
  },
25
27
  },
@@ -6,11 +6,12 @@ import type {
6
6
  GraphBuilderProvides,
7
7
  IntentResolverProvides,
8
8
  MetadataRecordsProvides,
9
+ SettingsProvides,
9
10
  SurfaceProvides,
10
11
  TranslationsProvides,
11
12
  } from '@dxos/app-framework';
12
13
  import { type SchemaProvides } from '@dxos/plugin-client';
13
- import { type StackProvides } from '@dxos/plugin-stack';
14
+ import { type SpaceInitProvides } from '@dxos/plugin-space';
14
15
 
15
16
  import { SCRIPT_PLUGIN } from '../meta';
16
17
 
@@ -18,10 +19,13 @@ export enum ScriptAction {
18
19
  CREATE = `${SCRIPT_PLUGIN}/create`,
19
20
  }
20
21
 
21
- export type ScriptPluginProvides = SurfaceProvides &
22
+ export type ScriptSettingsProps = {};
23
+
24
+ export type ScriptPluginProvides = GraphBuilderProvides &
22
25
  IntentResolverProvides &
23
- GraphBuilderProvides &
24
26
  MetadataRecordsProvides &
25
- TranslationsProvides &
26
27
  SchemaProvides &
27
- StackProvides;
28
+ SettingsProvides<ScriptSettingsProps> &
29
+ SpaceInitProvides &
30
+ SurfaceProvides &
31
+ TranslationsProvides;
@@ -1,513 +0,0 @@
1
- import {
2
- getUserFunctionUrlInMetadata,
3
- publicKeyToDid,
4
- setUserFunctionUrlInMetadata,
5
- uploadWorkerFunction
6
- } from "./chunk-DL5XQRQM.mjs";
7
- import {
8
- Bundler
9
- } from "./chunk-RHEZ5LUU.mjs";
10
- import {
11
- FunctionType
12
- } from "./chunk-O4LWBX6A.mjs";
13
- import {
14
- SCRIPT_PLUGIN
15
- } from "./chunk-JBACGDOJ.mjs";
16
- import {
17
- TypescriptEditor
18
- } from "./chunk-MRGOT5RF.mjs";
19
-
20
- // packages/plugins/experimental/plugin-script/src/components/ScriptEditor.tsx
21
- import { format } from "prettier";
22
- import prettierPluginEstree from "prettier/plugins/estree";
23
- import prettierPluginTypescript from "prettier/plugins/typescript";
24
- import React3, { useCallback, useMemo, useState as useState3 } from "react";
25
- import { log as log2 } from "@dxos/log";
26
- import { useClient } from "@dxos/react-client";
27
- import { create, createDocAccessor, Filter, fullyQualifiedId, getMeta, getSpace, useQuery } from "@dxos/react-client/echo";
28
- import { useIdentity } from "@dxos/react-client/halo";
29
- import { useTranslation as useTranslation3 } from "@dxos/react-ui";
30
- import { useHasAttention } from "@dxos/react-ui-attention";
31
- import { createDataExtensions, listener } from "@dxos/react-ui-editor";
32
- import { mx as mx2 } from "@dxos/react-ui-theme";
33
-
34
- // packages/plugins/experimental/plugin-script/src/components/DebugPanel.tsx
35
- import React, { useEffect, useRef, useState } from "react";
36
- import { log } from "@dxos/log";
37
- import { Avatar, DensityProvider, Icon, Input, Toolbar, useControlledValue, useTranslation } from "@dxos/react-ui";
38
- import { SyntaxHighlighter } from "@dxos/react-ui-syntax-highlighter";
39
- import { mx } from "@dxos/react-ui-theme";
40
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-script/src/components/DebugPanel.tsx";
41
- var DebugPanel = ({ classNames, functionUrl, binding: _binding, onBindingChange }) => {
42
- const { t } = useTranslation(SCRIPT_PLUGIN);
43
- const bindingInputRef = useRef(null);
44
- const [binding, setBinding] = useControlledValue(_binding ?? "");
45
- const handleBlur = () => {
46
- onBindingChange?.(binding);
47
- };
48
- const inputRef = useRef(null);
49
- const [input, setInput] = useState("");
50
- const [result, setResult] = useState("");
51
- const [state, setState] = useState(null);
52
- const [history, setHistory] = useState([]);
53
- const scrollerRef = useRef(null);
54
- const handleScroll = () => {
55
- if (scrollerRef.current) {
56
- scrollerRef.current.scrollTop = scrollerRef.current.scrollHeight;
57
- }
58
- };
59
- const controller = useRef();
60
- useEffect(() => {
61
- return () => {
62
- handleStop();
63
- };
64
- }, []);
65
- const handleStop = () => {
66
- controller.current?.abort("stop");
67
- controller.current = void 0;
68
- };
69
- const handleClear = () => {
70
- handleStop();
71
- setInput("");
72
- setResult("");
73
- setHistory([]);
74
- inputRef.current?.focus();
75
- };
76
- const handleResponse = ({ text, data, error } = {}) => {
77
- controller.current = void 0;
78
- setHistory((history2) => [
79
- ...history2,
80
- {
81
- type: "response",
82
- text,
83
- data,
84
- error
85
- }
86
- ]);
87
- setResult("");
88
- setState(null);
89
- handleScroll();
90
- };
91
- const handleRequest = async (input2) => {
92
- try {
93
- setState("pending");
94
- let data = null;
95
- if (input2.charAt(0) === "{") {
96
- try {
97
- const validJsonString = input2.replace(/'/g, '"').replace(/([{,]\s*)([a-zA-Z0-9_]+)(\s*:)/g, '$1"$2"$3');
98
- data = JSON.parse(validJsonString);
99
- input2 = JSON.stringify(data, null, 2);
100
- } catch (err) {
101
- inputRef.current?.focus();
102
- return;
103
- }
104
- }
105
- setInput("");
106
- setResult("");
107
- setHistory((history2) => [
108
- ...history2,
109
- {
110
- type: "request",
111
- text: input2
112
- }
113
- ]);
114
- setTimeout(() => {
115
- handleScroll();
116
- });
117
- controller.current = new AbortController();
118
- const response = await fetch(functionUrl, {
119
- signal: controller.current.signal,
120
- method: "POST",
121
- body: input2,
122
- headers: {
123
- "Content-Type": data ? "application/json" : "text/plain"
124
- }
125
- });
126
- if (!response.ok) {
127
- const text2 = await response.text();
128
- handleResponse({
129
- error: new Error(text2 || response.statusText || String(response.status))
130
- });
131
- return;
132
- }
133
- const contentType = response.headers.get("content-type");
134
- if (contentType === "application/json") {
135
- const data2 = await response.json();
136
- handleResponse({
137
- data: data2
138
- });
139
- return;
140
- }
141
- setState("responding");
142
- let text = "";
143
- const reader = response.body.getReader();
144
- const pump = async ({ done, value }) => {
145
- text = text + new TextDecoder().decode(value);
146
- if (!controller.current || done) {
147
- handleResponse({
148
- text
149
- });
150
- return;
151
- }
152
- setResult(text);
153
- setTimeout(() => {
154
- handleScroll();
155
- });
156
- return reader.read().then(pump);
157
- };
158
- void reader.read().then(pump).catch((err) => {
159
- if (err.name !== "AbortError") {
160
- log.catch(err, void 0, {
161
- F: __dxlog_file,
162
- L: 163,
163
- S: void 0,
164
- C: (f, a) => f(...a)
165
- });
166
- }
167
- });
168
- } catch (err) {
169
- if (err !== "stop") {
170
- const error = err instanceof Error ? err : new Error(err);
171
- handleResponse({
172
- error
173
- });
174
- log.catch(err, void 0, {
175
- F: __dxlog_file,
176
- L: 170,
177
- S: void 0,
178
- C: (f, a) => f(...a)
179
- });
180
- } else {
181
- handleResponse();
182
- }
183
- }
184
- };
185
- return /* @__PURE__ */ React.createElement(DensityProvider, {
186
- density: "fine"
187
- }, /* @__PURE__ */ React.createElement("div", {
188
- className: mx("flex flex-col h-full overflow-hidden", classNames)
189
- }, /* @__PURE__ */ React.createElement("div", {
190
- ref: scrollerRef,
191
- className: "flex flex-col gap-6 h-full p-4 overflow-x-hidden overflow-y-auto"
192
- }, /* @__PURE__ */ React.createElement(MessageThread, {
193
- state,
194
- result,
195
- history
196
- })), /* @__PURE__ */ React.createElement(Toolbar.Root, {
197
- classNames: "p-2"
198
- }, /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement(Input.TextInput, {
199
- ref: inputRef,
200
- autoFocus: true,
201
- placeholder: t("function request placeholder"),
202
- value: input,
203
- onChange: (ev) => setInput(ev.target.value),
204
- onKeyDown: (ev) => ev.key === "Enter" && handleRequest(input)
205
- })), /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement(Input.TextInput, {
206
- ref: bindingInputRef,
207
- classNames: "!w-[10rem]",
208
- placeholder: t("binding placeholder"),
209
- value: binding,
210
- onChange: (ev) => setBinding(ev.target.value.toUpperCase()),
211
- onBlur: handleBlur
212
- })), /* @__PURE__ */ React.createElement(Toolbar.Button, {
213
- onClick: () => handleRequest(input)
214
- }, /* @__PURE__ */ React.createElement(Icon, {
215
- icon: "ph--play--regular",
216
- size: 4
217
- })), /* @__PURE__ */ React.createElement(Toolbar.Button, {
218
- onClick: () => state ? handleStop() : handleClear()
219
- }, /* @__PURE__ */ React.createElement(Icon, {
220
- icon: state ? "ph--stop--regular" : "ph--trash--regular",
221
- size: 4
222
- })))));
223
- };
224
- var RobotAvatar = () => /* @__PURE__ */ React.createElement(Avatar.Root, {
225
- size: 6,
226
- variant: "circle"
227
- }, /* @__PURE__ */ React.createElement(Avatar.Frame, null, /* @__PURE__ */ React.createElement(Avatar.Icon, {
228
- icon: "ph--robot--regular"
229
- })));
230
- var MessageItem = ({ classNames, message }) => {
231
- const { text, data, error } = message;
232
- if (error) {
233
- return /* @__PURE__ */ React.createElement("span", {
234
- className: mx(classNames, "whitespace-pre text-error")
235
- }, String(error));
236
- } else if (data) {
237
- return /* @__PURE__ */ React.createElement(SyntaxHighlighter, {
238
- language: "json",
239
- className: mx("text-xs", classNames)
240
- }, JSON.stringify(data, null, 2));
241
- }
242
- return /* @__PURE__ */ React.createElement("span", {
243
- className: mx(classNames)
244
- }, text || "\xD8");
245
- };
246
- var MessageThread = ({ state, result, history }) => {
247
- return /* @__PURE__ */ React.createElement(React.Fragment, null, history.map((message, i) => /* @__PURE__ */ React.createElement("div", {
248
- key: i,
249
- className: "grid grid-cols-[3rem_1fr]"
250
- }, /* @__PURE__ */ React.createElement("div", null, message.type === "response" && /* @__PURE__ */ React.createElement(RobotAvatar, null)), /* @__PURE__ */ React.createElement("div", {
251
- className: mx("flex", message.type === "request" && "justify-end")
252
- }, /* @__PURE__ */ React.createElement(MessageItem, {
253
- classNames: [
254
- message.type === "request" && "p-1 px-2 rounded-lg bg-hoverSurface"
255
- ],
256
- message
257
- })))), /* @__PURE__ */ React.createElement("div", {
258
- className: "grid grid-cols-[3rem_1fr]"
259
- }, /* @__PURE__ */ React.createElement("div", null, state === "pending" && /* @__PURE__ */ React.createElement(Icon, {
260
- icon: "ph--spinner--regular",
261
- size: 6,
262
- classNames: "animate-spin-slow"
263
- }) || result.length > 0 && /* @__PURE__ */ React.createElement(RobotAvatar, null)), /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("span", null, result))));
264
- };
265
-
266
- // packages/plugins/experimental/plugin-script/src/components/Toolbar.tsx
267
- import React2, { useState as useState2 } from "react";
268
- import { DensityProvider as DensityProvider2, ElevationProvider, Icon as Icon2, Toolbar as NaturalToolbar, Tooltip, useTranslation as useTranslation2 } from "@dxos/react-ui";
269
- var Toolbar2 = ({ classNames, deployed, error, functionUrl, showPanel, onDeploy, onFormat, onTogglePanel }) => {
270
- const { t } = useTranslation2(SCRIPT_PLUGIN);
271
- const [pending, setPending] = useState2(false);
272
- const handleCopyLink = async () => {
273
- if (!functionUrl) {
274
- return;
275
- }
276
- await navigator.clipboard.writeText(functionUrl);
277
- };
278
- const handleDeploy = async () => {
279
- setPending(true);
280
- await onDeploy?.();
281
- setPending(false);
282
- };
283
- return /* @__PURE__ */ React2.createElement(DensityProvider2, {
284
- density: "fine"
285
- }, /* @__PURE__ */ React2.createElement(ElevationProvider, {
286
- elevation: "chrome"
287
- }, /* @__PURE__ */ React2.createElement(NaturalToolbar.Root, {
288
- classNames: [
289
- "p-1",
290
- classNames
291
- ],
292
- style: {
293
- contain: "layout"
294
- }
295
- }, onFormat && /* @__PURE__ */ React2.createElement(Tooltip.Root, null, /* @__PURE__ */ React2.createElement(Tooltip.Trigger, {
296
- asChild: true
297
- }, /* @__PURE__ */ React2.createElement(NaturalToolbar.Button, {
298
- variant: "ghost",
299
- onClick: onFormat
300
- }, /* @__PURE__ */ React2.createElement(Icon2, {
301
- icon: "ph--magic-wand--regular",
302
- size: 4
303
- }))), /* @__PURE__ */ React2.createElement(Tooltip.Portal, null, /* @__PURE__ */ React2.createElement(Tooltip.Content, null, /* @__PURE__ */ React2.createElement(Tooltip.Arrow, null), t("format label")))), /* @__PURE__ */ React2.createElement("div", {
304
- role: "separator",
305
- className: "grow"
306
- }), error ? /* @__PURE__ */ React2.createElement(Tooltip.Root, null, /* @__PURE__ */ React2.createElement(Tooltip.Trigger, null, /* @__PURE__ */ React2.createElement(Icon2, {
307
- icon: "ph--warning-circle--regular",
308
- size: 4
309
- })), /* @__PURE__ */ React2.createElement(Tooltip.Portal, null, /* @__PURE__ */ React2.createElement(Tooltip.Content, null, /* @__PURE__ */ React2.createElement(Tooltip.Arrow, null), error))) : null, functionUrl && deployed && /* @__PURE__ */ React2.createElement(Tooltip.Root, null, /* @__PURE__ */ React2.createElement(Tooltip.Trigger, {
310
- asChild: true
311
- }, /* @__PURE__ */ React2.createElement(NaturalToolbar.Button, {
312
- variant: "ghost",
313
- onClick: handleCopyLink
314
- }, /* @__PURE__ */ React2.createElement(Icon2, {
315
- icon: "ph--link--regular",
316
- size: 4
317
- }))), /* @__PURE__ */ React2.createElement(Tooltip.Portal, null, /* @__PURE__ */ React2.createElement(Tooltip.Content, null, /* @__PURE__ */ React2.createElement(Tooltip.Arrow, null), t("copy link label")))), /* @__PURE__ */ React2.createElement(Tooltip.Root, null, /* @__PURE__ */ React2.createElement(Tooltip.Trigger, {
318
- asChild: true
319
- }, /* @__PURE__ */ React2.createElement(NaturalToolbar.Button, {
320
- variant: "ghost",
321
- onClick: handleDeploy,
322
- disabled: pending
323
- }, pending ? /* @__PURE__ */ React2.createElement(Icon2, {
324
- icon: "ph--spinner--regular",
325
- size: 4,
326
- classNames: "animate-spin-slow"
327
- }) : /* @__PURE__ */ React2.createElement(Icon2, {
328
- icon: "ph--cloud-arrow-up--regular",
329
- size: 4
330
- }))), /* @__PURE__ */ React2.createElement(Tooltip.Portal, null, /* @__PURE__ */ React2.createElement(Tooltip.Content, null, /* @__PURE__ */ React2.createElement(Tooltip.Arrow, null), pending ? t("pending label") : t("deploy label")))), onTogglePanel && /* @__PURE__ */ React2.createElement(Tooltip.Root, null, /* @__PURE__ */ React2.createElement(Tooltip.Trigger, {
331
- asChild: true
332
- }, /* @__PURE__ */ React2.createElement(NaturalToolbar.Button, {
333
- variant: "ghost",
334
- onClick: onTogglePanel
335
- }, /* @__PURE__ */ React2.createElement(Icon2, {
336
- icon: showPanel ? "ph--caret-down--regular" : "ph--caret-up--regular",
337
- size: 4
338
- }))), /* @__PURE__ */ React2.createElement(Tooltip.Portal, null, /* @__PURE__ */ React2.createElement(Tooltip.Content, null, /* @__PURE__ */ React2.createElement(Tooltip.Arrow, null), t("toggle details label")))))));
339
- };
340
-
341
- // packages/plugins/experimental/plugin-script/src/components/ScriptEditor.tsx
342
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-script/src/components/ScriptEditor.tsx";
343
- var ScriptEditor = ({ env, script, role }) => {
344
- const { t } = useTranslation3(SCRIPT_PLUGIN);
345
- const hasAttention = useHasAttention(fullyQualifiedId(script));
346
- const client = useClient();
347
- const identity = useIdentity();
348
- const space = getSpace(script);
349
- const [fn] = useQuery(space, Filter.schema(FunctionType, (fn2) => fn2.source === script));
350
- const extensions = useMemo(() => [
351
- listener({
352
- onChange: (text) => {
353
- if (script.source && script.source?.content !== text) {
354
- script.changed = true;
355
- }
356
- }
357
- }),
358
- createDataExtensions({
359
- id: script.id,
360
- text: script.source && createDocAccessor(script.source, [
361
- "content"
362
- ]),
363
- space,
364
- identity
365
- })
366
- ], [
367
- script,
368
- script.source,
369
- space,
370
- identity
371
- ]);
372
- const [showPanel, setShowPanel] = useState3(false);
373
- const initialValue = useMemo(() => script.source?.content, [
374
- script.source
375
- ]);
376
- const existingFunctionUrl = fn && getUserFunctionUrlInMetadata(getMeta(fn));
377
- const [error, setError] = useState3();
378
- const handleBindingChange = useCallback((binding) => {
379
- fn.binding = binding;
380
- }, [
381
- fn
382
- ]);
383
- const handleFormat = useCallback(async () => {
384
- if (!script.source) {
385
- return;
386
- }
387
- try {
388
- script.source.content = await format(script.source.content, {
389
- parser: "typescript",
390
- plugins: [
391
- prettierPluginEstree,
392
- prettierPluginTypescript
393
- ],
394
- semi: true,
395
- singleQuote: true
396
- });
397
- } catch (err) {
398
- log2.catch(err, void 0, {
399
- F: __dxlog_file2,
400
- L: 102,
401
- S: void 0,
402
- C: (f, a) => f(...a)
403
- });
404
- }
405
- }, [
406
- script.source
407
- ]);
408
- const handleDeploy = useCallback(async () => {
409
- if (!script.source || !identity || !space) {
410
- return;
411
- }
412
- setError(void 0);
413
- try {
414
- const existingFunctionId = existingFunctionUrl?.split("/").at(-1);
415
- const ownerDid = existingFunctionUrl?.split("/").at(-2) ?? publicKeyToDid(identity.identityKey);
416
- const bundler = new Bundler({
417
- platform: "browser",
418
- sandboxedModules: [],
419
- remoteModules: {}
420
- });
421
- const buildResult = await bundler.bundle(script.source.content);
422
- if (buildResult.error || !buildResult.bundle) {
423
- throw buildResult.error;
424
- }
425
- const { result, functionId, functionVersionNumber, errorMessage } = await uploadWorkerFunction({
426
- clientConfig: client.config,
427
- halo: client.halo,
428
- ownerDid,
429
- functionId: existingFunctionId,
430
- source: buildResult.bundle
431
- });
432
- if (result !== "success" || functionId === void 0 || functionVersionNumber === void 0) {
433
- throw new Error(errorMessage);
434
- }
435
- log2.info("function uploaded", {
436
- functionId,
437
- functionVersionNumber
438
- }, {
439
- F: __dxlog_file2,
440
- L: 137,
441
- S: void 0,
442
- C: (f, a) => f(...a)
443
- });
444
- if (fn) {
445
- fn.version = functionVersionNumber;
446
- }
447
- const deployedFunction = fn ?? space.db.add(create(FunctionType, {
448
- version: functionVersionNumber,
449
- source: script
450
- }));
451
- const meta = getMeta(deployedFunction);
452
- setUserFunctionUrlInMetadata(meta, `/${ownerDid}/${functionId}`);
453
- script.changed = false;
454
- } catch (err) {
455
- log2.catch(err, void 0, {
456
- F: __dxlog_file2,
457
- L: 147,
458
- S: void 0,
459
- C: (f, a) => f(...a)
460
- });
461
- setError(t("upload failed label"));
462
- }
463
- }, [
464
- fn,
465
- existingFunctionUrl,
466
- script,
467
- script.name,
468
- script.source
469
- ]);
470
- const functionUrl = useMemo(() => {
471
- if (!existingFunctionUrl) {
472
- return;
473
- }
474
- const baseUrl = new URL("functions/", client.config.values.runtime?.services?.edge?.url);
475
- const relativeUrl = existingFunctionUrl.replace(/^\//, "");
476
- const url = new URL(`./${relativeUrl}`, baseUrl.toString());
477
- space && url.searchParams.set("spaceId", space.id);
478
- url.protocol = "https";
479
- return url.toString();
480
- }, [
481
- existingFunctionUrl,
482
- space
483
- ]);
484
- return /* @__PURE__ */ React3.createElement("div", {
485
- role: "none",
486
- className: mx2("flex flex-col is-full bs-full overflow-hidden", role === "article" && "row-span-2", hasAttention && "attention-surface")
487
- }, /* @__PURE__ */ React3.createElement(TypescriptEditor, {
488
- id: script.id,
489
- env,
490
- initialValue,
491
- extensions,
492
- className: "flex is-full bs-full overflow-hidden ch-focus-ring-inset-over-all"
493
- }), /* @__PURE__ */ React3.createElement(Toolbar2, {
494
- classNames: "border-t border-separator",
495
- deployed: Boolean(existingFunctionUrl) && !script.changed,
496
- functionUrl,
497
- error,
498
- showPanel,
499
- onDeploy: handleDeploy,
500
- onFormat: handleFormat,
501
- onTogglePanel: async () => setShowPanel((showDetails) => !showDetails)
502
- }), showPanel && /* @__PURE__ */ React3.createElement(DebugPanel, {
503
- functionUrl,
504
- binding: fn?.binding,
505
- onBindingChange: handleBindingChange
506
- }));
507
- };
508
- var ScriptEditor_default = ScriptEditor;
509
- export {
510
- ScriptEditor,
511
- ScriptEditor_default as default
512
- };
513
- //# sourceMappingURL=ScriptEditor-5Y3EROG3.mjs.map