@dxos/plugin-script 0.6.13 → 0.6.14-main.7bd9c89

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-LJD3HE2U.mjs +78 -0
  3. package/dist/lib/browser/AutomationPanel-LJD3HE2U.mjs.map +7 -0
  4. package/dist/lib/browser/ScriptContainer-B3CPWXRE.mjs +423 -0
  5. package/dist/lib/browser/ScriptContainer-B3CPWXRE.mjs.map +7 -0
  6. package/dist/lib/browser/chunk-G66MXS4T.mjs +248 -0
  7. package/dist/lib/browser/chunk-G66MXS4T.mjs.map +7 -0
  8. package/dist/lib/browser/{chunk-RHEZ5LUU.mjs → chunk-G6H56WFS.mjs} +51 -2
  9. package/dist/lib/browser/{chunk-RHEZ5LUU.mjs.map → chunk-G6H56WFS.mjs.map} +4 -4
  10. package/dist/lib/browser/{chunk-DL5XQRQM.mjs → chunk-KHNN3F7J.mjs} +18 -6
  11. package/dist/lib/browser/chunk-KHNN3F7J.mjs.map +7 -0
  12. package/dist/lib/browser/{chunk-O4LWBX6A.mjs → chunk-KXVQPS4Y.mjs} +2 -2
  13. package/dist/lib/browser/{chunk-O4LWBX6A.mjs.map → chunk-KXVQPS4Y.mjs.map} +2 -2
  14. package/dist/lib/browser/chunk-SGQHRB4P.mjs +17 -0
  15. package/dist/lib/browser/chunk-SGQHRB4P.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-2U3LW3J4.cjs +100 -0
  23. package/dist/lib/node/AutomationPanel-2U3LW3J4.cjs.map +7 -0
  24. package/dist/lib/node/ScriptContainer-BV7HMUY5.cjs +425 -0
  25. package/dist/lib/node/ScriptContainer-BV7HMUY5.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/{chunk-4GTXIELQ.cjs → chunk-ACLCRWDB.cjs} +44 -6
  29. package/dist/lib/node/chunk-ACLCRWDB.cjs.map +7 -0
  30. package/dist/lib/node/{TypescriptEditor-M3WWFIP2.cjs → chunk-EJC55SDD.cjs} +18 -8
  31. package/dist/lib/node/chunk-EJC55SDD.cjs.map +7 -0
  32. package/dist/lib/node/{chunk-PFH3ROEH.cjs → chunk-FY5KKL5N.cjs} +22 -8
  33. package/dist/lib/node/chunk-FY5KKL5N.cjs.map +7 -0
  34. package/dist/lib/node/chunk-JWKMTYYH.cjs +277 -0
  35. package/dist/lib/node/chunk-JWKMTYYH.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-FS47OF3I.mjs +79 -0
  46. package/dist/lib/node-esm/AutomationPanel-FS47OF3I.mjs.map +7 -0
  47. package/dist/lib/node-esm/ScriptContainer-HSIOGVP3.mjs +424 -0
  48. package/dist/lib/node-esm/ScriptContainer-HSIOGVP3.mjs.map +7 -0
  49. package/dist/lib/node-esm/chunk-3QHVR4VV.mjs +249 -0
  50. package/dist/lib/node-esm/chunk-3QHVR4VV.mjs.map +7 -0
  51. package/dist/lib/node-esm/chunk-7EDYDVQH.mjs +47 -0
  52. package/dist/lib/node-esm/chunk-7EDYDVQH.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-LDLNTVAK.mjs +280 -0
  56. package/dist/lib/node-esm/chunk-LDLNTVAK.mjs.map +7 -0
  57. package/dist/lib/node-esm/chunk-QMTTZYLF.mjs +255 -0
  58. package/dist/lib/node-esm/chunk-QMTTZYLF.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 +61 -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 +14 -13
  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
@@ -2,7 +2,6 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { Code, type IconProps } from '@phosphor-icons/react';
6
5
  // @ts-ignore
7
6
  import wasmUrl from 'esbuild-wasm/esbuild.wasm?url';
8
7
  import React from 'react';
@@ -17,8 +16,9 @@ import { loadObjectReferences } from '@dxos/react-client/echo';
17
16
 
18
17
  import { initializeBundler } from './bundler';
19
18
  import { Compiler } from './compiler';
20
- import { ScriptEditor } from './components';
19
+ import { AutomationPanel, ScriptContainer, ScriptSettings } from './components';
21
20
  import meta, { SCRIPT_PLUGIN } from './meta';
21
+ import { templates } from './templates';
22
22
  import translations from './translations';
23
23
  import { FunctionType, ScriptType } from './types';
24
24
  import { ScriptAction, type ScriptPluginProvides } from './types';
@@ -45,12 +45,12 @@ export const ScriptPlugin = (): PluginDefinition<ScriptPluginProvides> => {
45
45
  await initializeBundler({ wasmUrl });
46
46
  },
47
47
  provides: {
48
+ settings: {},
48
49
  metadata: {
49
50
  records: {
50
51
  [ScriptType.typename]: {
51
52
  placeholder: ['object title placeholder', { ns: SCRIPT_PLUGIN }],
52
- icon: (props: IconProps) => <Code {...props} />,
53
- iconSymbol: 'ph--code--regular',
53
+ icon: 'ph--code--regular',
54
54
  // TODO(wittjosiah): Move out of metadata.
55
55
  loadReferences: (script: ScriptType) => loadObjectReferences(script, (script) => [script.source]),
56
56
  },
@@ -60,6 +60,12 @@ export const ScriptPlugin = (): PluginDefinition<ScriptPluginProvides> => {
60
60
  echo: {
61
61
  schema: [ScriptType, FunctionType],
62
62
  },
63
+ space: {
64
+ onSpaceCreate: {
65
+ label: ['create object label', { ns: SCRIPT_PLUGIN }],
66
+ action: ScriptAction.CREATE,
67
+ },
68
+ },
63
69
  graph: {
64
70
  builder: (plugins) => {
65
71
  const client = resolvePlugin(plugins, parseClientPlugin)?.provides.client;
@@ -93,8 +99,7 @@ export const ScriptPlugin = (): PluginDefinition<ScriptPluginProvides> => {
93
99
  },
94
100
  properties: {
95
101
  label: ['create object label', { ns: SCRIPT_PLUGIN }],
96
- icon: (props: IconProps) => <Code {...props} />,
97
- iconSymbol: 'ph--code--regular',
102
+ icon: 'ph--code--regular',
98
103
  testId: 'scriptPlugin.createObject',
99
104
  },
100
105
  },
@@ -103,31 +108,24 @@ export const ScriptPlugin = (): PluginDefinition<ScriptPluginProvides> => {
103
108
  });
104
109
  },
105
110
  },
106
- stack: {
107
- creators: [
108
- {
109
- id: 'create-stack-section-script',
110
- testId: 'scriptPlugin.createSection',
111
- type: ['plugin name', { ns: SCRIPT_PLUGIN }],
112
- label: ['create stack section label', { ns: SCRIPT_PLUGIN }],
113
- icon: (props: any) => <Code {...props} />,
114
- intent: {
115
- plugin: SCRIPT_PLUGIN,
116
- action: ScriptAction.CREATE,
117
- },
118
- },
119
- ],
120
- },
121
111
  surface: {
122
112
  component: ({ data, role }) => {
123
- if (role && !['article', 'section'].includes(role)) {
124
- return null;
125
- }
113
+ switch (role) {
114
+ case 'settings': {
115
+ return data.plugin === meta.id ? <ScriptSettings settings={{}} /> : null;
116
+ }
126
117
 
127
- if (data.object instanceof ScriptType) {
128
- return <ScriptEditor env={compiler.environment} script={data.object} role={role} />;
129
- }
118
+ case 'article': {
119
+ if (data.object instanceof ScriptType) {
120
+ return <ScriptContainer script={data.object} env={compiler.environment} />;
121
+ }
122
+ break;
123
+ }
130
124
 
125
+ case 'complementary--automation': {
126
+ return <AutomationPanel subject={data.subject as any} />;
127
+ }
128
+ }
131
129
  return null;
132
130
  },
133
131
  },
@@ -135,7 +133,7 @@ export const ScriptPlugin = (): PluginDefinition<ScriptPluginProvides> => {
135
133
  resolver: (intent) => {
136
134
  switch (intent.action) {
137
135
  case ScriptAction.CREATE: {
138
- return { data: create(ScriptType, { source: create(TextType, { content: example }) }) };
136
+ return { data: create(ScriptType, { source: create(TextType, { content: templates[0].source }) }) };
139
137
  }
140
138
  }
141
139
  },
@@ -143,14 +141,3 @@ export const ScriptPlugin = (): PluginDefinition<ScriptPluginProvides> => {
143
141
  },
144
142
  };
145
143
  };
146
-
147
- // TODO(burdon): Import.
148
- const example = [
149
- 'export default async ({ ',
150
- ' event: { data: { request } },',
151
- ' context: { space, ai } ',
152
- '}: any) => {',
153
- " return new Response('Hello DXOS!');",
154
- '};',
155
- '',
156
- ].join('\n');
@@ -2,11 +2,21 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
- import { describe, expect, test } from 'vitest';
5
+ // @ts-ignore
6
+ import wasmUrl from 'esbuild-wasm/esbuild.wasm?url';
7
+ import { beforeAll, describe, expect, test } from 'vitest';
6
8
 
7
- import { Bundler } from './bundler';
9
+ import { isNode } from '@dxos/util';
10
+
11
+ import { Bundler, initializeBundler } from './bundler';
8
12
 
9
13
  describe('Bundler', () => {
14
+ beforeAll(async () => {
15
+ if (!isNode()) {
16
+ await initializeBundler({ wasmUrl });
17
+ }
18
+ });
19
+
10
20
  test('Basic', async () => {
11
21
  const bundler = new Bundler({ platform: 'node', sandboxedModules: [], remoteModules: {} });
12
22
  const result = await bundler.bundle('const x = 100'); // TODO(burdon): Test import.
@@ -0,0 +1,101 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import React, { useMemo, useState } from 'react';
6
+
7
+ import type { EchoReactiveObject } from '@dxos/client/echo';
8
+ import { failUndefined } from '@dxos/debug';
9
+ import { useClient } from '@dxos/react-client';
10
+ import { Filter, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';
11
+ import { Select } from '@dxos/react-ui';
12
+
13
+ import { getInvocationUrl, getUserFunctionUrlInMetadata } from '../../edge';
14
+ import { FunctionType, ScriptType } from '../../types';
15
+ import { DebugPanel } from '../DebugPanel';
16
+
17
+ export interface AutomationPanelProps {
18
+ subject: EchoReactiveObject<any>;
19
+ }
20
+
21
+ export const AutomationPanel = ({ subject }: AutomationPanelProps) => {
22
+ const space = getSpace(subject);
23
+
24
+ // TODO(dmaretskyi): Parametric query.
25
+ const functions = useQuery(
26
+ space ?? undefined,
27
+ Filter.schema(FunctionType, (fn) => (subject instanceof ScriptType ? fn.source === subject : fn.binding != null)),
28
+ {},
29
+ [subject],
30
+ );
31
+ const [selectedFunction, setSelectedFunction] = useState<FunctionType | null>(null);
32
+ const functionToChatWith = subject instanceof ScriptType ? functions[0] : selectedFunction;
33
+
34
+ return (
35
+ <div className='h-full flex flex-col'>
36
+ {!(subject instanceof ScriptType) && (
37
+ <BindingSelect
38
+ selectedFunction={selectedFunction}
39
+ setSelectedFunction={setSelectedFunction}
40
+ functions={functions}
41
+ />
42
+ )}
43
+ {functionToChatWith && <ChatPanel fn={functionToChatWith} subject={subject} />}
44
+ {subject instanceof ScriptType && functions.length === 0 && <p>Deploy function to interact with it.</p>}
45
+ </div>
46
+ );
47
+ };
48
+
49
+ export interface ChatPanelProps {
50
+ fn: FunctionType;
51
+ subject: EchoReactiveObject<any>;
52
+ }
53
+
54
+ const ChatPanel = ({ fn, subject }: ChatPanelProps) => {
55
+ const client = useClient();
56
+ const space = getSpace(fn);
57
+ const existingFunctionUrl = getUserFunctionUrlInMetadata(getMeta(fn));
58
+ const functionUrl = useMemo(() => {
59
+ if (!existingFunctionUrl) {
60
+ return;
61
+ }
62
+
63
+ return getInvocationUrl(existingFunctionUrl, client.config.values.runtime?.services?.edge?.url ?? '', {
64
+ spaceId: space?.id,
65
+ subjectId: subject?.id,
66
+ });
67
+ }, [existingFunctionUrl, space, subject]);
68
+
69
+ return <DebugPanel functionUrl={functionUrl} classNames='flex-1' />;
70
+ };
71
+
72
+ export interface BindingSelectProps {
73
+ selectedFunction: FunctionType | null;
74
+ setSelectedFunction: (fn: FunctionType) => void;
75
+ functions: FunctionType[];
76
+ }
77
+
78
+ const BindingSelect = ({ selectedFunction, setSelectedFunction, functions }: BindingSelectProps) => {
79
+ return (
80
+ <Select.Root
81
+ value={selectedFunction?.id}
82
+ onValueChange={(id) => setSelectedFunction(functions.find((fn) => fn.id === id) ?? failUndefined())}
83
+ >
84
+ <Select.TriggerButton placeholder='Select value' />
85
+ <Select.Portal>
86
+ <Select.Content>
87
+ <Select.ScrollUpButton />
88
+ <Select.Viewport>
89
+ {functions.map(({ id, binding }) => (
90
+ <Select.Option key={id} value={id}>
91
+ {binding}
92
+ </Select.Option>
93
+ ))}
94
+ </Select.Viewport>
95
+ <Select.ScrollDownButton />
96
+ <Select.Arrow />
97
+ </Select.Content>
98
+ </Select.Portal>
99
+ </Select.Root>
100
+ );
101
+ };
@@ -0,0 +1,9 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { AutomationPanel } from './AutomationPanel';
6
+
7
+ export * from './AutomationPanel';
8
+
9
+ export default AutomationPanel;
@@ -5,20 +5,11 @@
5
5
  import React, { useEffect, useRef, useState } from 'react';
6
6
 
7
7
  import { log } from '@dxos/log';
8
- import {
9
- Avatar,
10
- DensityProvider,
11
- Icon,
12
- Input,
13
- type ThemedClassName,
14
- Toolbar,
15
- useControlledValue,
16
- useTranslation,
17
- } from '@dxos/react-ui';
8
+ import { Avatar, Icon, Input, type ThemedClassName, Toolbar, useControlledValue, useTranslation } from '@dxos/react-ui';
18
9
  import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
19
10
  import { mx } from '@dxos/react-ui-theme';
20
11
 
21
- import { SCRIPT_PLUGIN } from '../meta';
12
+ import { SCRIPT_PLUGIN } from '../../meta';
22
13
 
23
14
  type State = 'pending' | 'responding';
24
15
 
@@ -31,9 +22,16 @@ export type DebugPanelProps = ThemedClassName<{
31
22
  functionUrl?: string;
32
23
  binding?: string;
33
24
  onBindingChange?: (binding: string) => void;
25
+ showBindingConfig?: boolean;
34
26
  }>;
35
27
 
36
- export const DebugPanel = ({ classNames, functionUrl, binding: _binding, onBindingChange }: DebugPanelProps) => {
28
+ export const DebugPanel = ({
29
+ classNames,
30
+ functionUrl,
31
+ binding: _binding,
32
+ onBindingChange,
33
+ showBindingConfig = false,
34
+ }: DebugPanelProps) => {
37
35
  const { t } = useTranslation(SCRIPT_PLUGIN);
38
36
 
39
37
  const bindingInputRef = useRef<HTMLInputElement>(null);
@@ -47,7 +45,7 @@ export const DebugPanel = ({ classNames, functionUrl, binding: _binding, onBindi
47
45
  const [result, setResult] = useState('');
48
46
  const [state, setState] = useState<State | null>(null);
49
47
 
50
- // TODO(burdon): Persistent history (non-space ECHO data?)
48
+ // TODO(burdon): Persistent history -- at least for session (non-space ECHO data?)
51
49
  const [history, setHistory] = useState<Message[]>([]);
52
50
 
53
51
  const scrollerRef = useRef<HTMLDivElement>(null);
@@ -175,24 +173,24 @@ export const DebugPanel = ({ classNames, functionUrl, binding: _binding, onBindi
175
173
  };
176
174
 
177
175
  return (
178
- <DensityProvider density='fine'>
179
- <div className={mx('flex flex-col h-full overflow-hidden', classNames)}>
180
- {/* TODO(burdon): Replace with Thread? */}
181
- <div ref={scrollerRef} className='flex flex-col gap-6 h-full p-4 overflow-x-hidden overflow-y-auto'>
182
- <MessageThread state={state} result={result} history={history} />
183
- </div>
176
+ <div className={mx('flex flex-col h-full overflow-hidden', classNames)}>
177
+ {/* TODO(burdon): Replace with Thread? */}
178
+ <div ref={scrollerRef} className='flex flex-col gap-6 h-full p-2 overflow-x-hidden overflow-y-auto'>
179
+ <MessageThread state={state} result={result} history={history} />
180
+ </div>
184
181
 
185
- <Toolbar.Root classNames='p-2'>
186
- <Input.Root>
187
- <Input.TextInput
188
- ref={inputRef}
189
- autoFocus
190
- placeholder={t('function request placeholder')}
191
- value={input}
192
- onChange={(ev) => setInput(ev.target.value)}
193
- onKeyDown={(ev) => ev.key === 'Enter' && handleRequest(input)}
194
- />
195
- </Input.Root>
182
+ <Toolbar.Root classNames='p-2'>
183
+ <Input.Root>
184
+ <Input.TextInput
185
+ ref={inputRef}
186
+ autoFocus
187
+ placeholder={t('function request placeholder')}
188
+ value={input}
189
+ onChange={(ev) => setInput(ev.target.value)}
190
+ onKeyDown={(ev) => ev.key === 'Enter' && handleRequest(input)}
191
+ />
192
+ </Input.Root>
193
+ {showBindingConfig && (
196
194
  <Input.Root>
197
195
  <Input.TextInput
198
196
  ref={bindingInputRef}
@@ -203,67 +201,74 @@ export const DebugPanel = ({ classNames, functionUrl, binding: _binding, onBindi
203
201
  onBlur={handleBlur}
204
202
  />
205
203
  </Input.Root>
206
- <Toolbar.Button onClick={() => handleRequest(input)}>
207
- <Icon icon='ph--play--regular' size={4} />
208
- </Toolbar.Button>
209
- <Toolbar.Button onClick={() => (state ? handleStop() : handleClear())}>
210
- <Icon icon={state ? 'ph--stop--regular' : 'ph--trash--regular'} size={4} />
211
- </Toolbar.Button>
212
- </Toolbar.Root>
213
- </div>
214
- </DensityProvider>
204
+ )}
205
+ <Toolbar.Button onClick={() => handleRequest(input)}>
206
+ <Icon icon='ph--play--regular' size={4} />
207
+ </Toolbar.Button>
208
+ <Toolbar.Button onClick={() => (state ? handleStop() : handleClear())}>
209
+ <Icon icon={state ? 'ph--stop--regular' : 'ph--trash--regular'} size={4} />
210
+ </Toolbar.Button>
211
+ </Toolbar.Root>
212
+ </div>
215
213
  );
216
214
  };
217
215
 
218
- const RobotAvatar = () => (
219
- <Avatar.Root size={6} variant='circle'>
220
- <Avatar.Frame>
221
- <Avatar.Icon icon='ph--robot--regular' />
222
- </Avatar.Frame>
223
- </Avatar.Root>
224
- );
225
-
226
- const MessageItem = ({ classNames, message }: ThemedClassName<{ message: Message }>) => {
227
- const { text, data, error } = message;
228
- if (error) {
229
- return <span className={mx(classNames, 'whitespace-pre text-error')}>{String(error)}</span>;
230
- } else if (data) {
231
- return (
232
- <SyntaxHighlighter language='json' className={mx('text-xs', classNames)}>
233
- {JSON.stringify(data, null, 2)}
234
- </SyntaxHighlighter>
235
- );
236
- }
237
-
238
- return <span className={mx(classNames)}>{text || '\u00D8'}</span>;
239
- };
240
-
241
216
  // TODO(burdon): Replace with thread?
242
217
  // TODO(burdon): Button to delete individual messages.
243
- // TODO(burdon): Button to re-run question.
218
+ // TODO(burdon): Button to edit/re-run question.
244
219
  const MessageThread = ({ state, result, history }: { state: State | null; result: string; history: Message[] }) => {
245
220
  return (
246
221
  <>
247
222
  {history.map((message, i) => (
248
- <div key={i} className='grid grid-cols-[3rem_1fr]'>
249
- <div>{message.type === 'response' && <RobotAvatar />}</div>
250
- <div className={mx('flex', message.type === 'request' && 'justify-end')}>
251
- <MessageItem
252
- classNames={[message.type === 'request' && 'p-1 px-2 rounded-lg bg-hoverSurface']}
253
- message={message}
254
- />
223
+ <div key={i} className='grid grid-cols-[2rem_1fr_2rem]'>
224
+ <div className='p-1'>{message.type === 'response' && <RobotAvatar />}</div>
225
+ <div className='overflow-auto'>
226
+ <MessageItem message={message} />
255
227
  </div>
256
228
  </div>
257
229
  ))}
258
- <div className='grid grid-cols-[3rem_1fr]'>
259
- <div>
260
- {(state === 'pending' && <Icon icon='ph--spinner--regular' size={6} classNames='animate-spin-slow' />) ||
261
- (result.length > 0 && <RobotAvatar />)}
262
- </div>
263
- <div>
264
- <span>{result}</span>
230
+ {result?.length > 0 && (
231
+ <div className='grid grid-cols-[2rem_1fr_2rem]'>
232
+ <div className='p-1'>
233
+ {(state === 'pending' && <Icon icon='ph--spinner--regular' size={6} classNames='animate-spin' />) || (
234
+ <Icon icon='ph--robot--regular' size={6} classNames='animate-[pulse_1s_ease-in-out_infinite]' />
235
+ )}
236
+ </div>
237
+ <div className='overflow-auto'>
238
+ <MessageItem message={{ type: 'response', text: result }} />
239
+ </div>
265
240
  </div>
266
- </div>
241
+ )}
267
242
  </>
268
243
  );
269
244
  };
245
+
246
+ const MessageItem = ({ classNames, message }: ThemedClassName<{ message: Message }>) => {
247
+ const { type, text, data, error } = message;
248
+ const wrapper = 'p-1 px-2 rounded-lg bg-hoverSurface overflow-auto';
249
+ return (
250
+ <div className={mx('flex', type === 'request' ? 'ml-[1rem] justify-end' : 'mr-[1rem]', classNames)}>
251
+ {error && <div className={mx(wrapper, 'whitespace-pre text-error')}>{String(error)}</div>}
252
+
253
+ {text !== undefined && (
254
+ <div className={mx(wrapper, type === 'request' && 'bg-primary-400 dark:bg-primary-600')}>
255
+ {text || '\u00D8'}
256
+ </div>
257
+ )}
258
+
259
+ {data && (
260
+ <SyntaxHighlighter language='json' className={mx(wrapper, 'px-8 py-2 text-xs')}>
261
+ {JSON.stringify(data, null, 2)}
262
+ </SyntaxHighlighter>
263
+ )}
264
+ </div>
265
+ );
266
+ };
267
+
268
+ const RobotAvatar = () => (
269
+ <Avatar.Root size={6} variant='circle'>
270
+ <Avatar.Frame>
271
+ <Avatar.Icon icon='ph--robot--regular' />
272
+ </Avatar.Frame>
273
+ </Avatar.Root>
274
+ );
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ export * from './DebugPanel';
@@ -11,7 +11,7 @@ import { baseSurface, mx } from '@dxos/react-ui-theme';
11
11
  import { createProtoRpcPeer } from '@dxos/rpc';
12
12
  import { createIFramePort } from '@dxos/rpc-tunnel';
13
13
 
14
- import { type BundlerResult } from '../../../bundler';
14
+ import { type BundlerResult } from '../../bundler';
15
15
 
16
16
  export type FrameContainerProps = {
17
17
  containerUrl: string;
@@ -3,19 +3,21 @@
3
3
  //
4
4
 
5
5
  import '@dxos-theme';
6
+
7
+ import { type Meta } from '@storybook/react';
6
8
  import React, { useEffect, useMemo } from 'react';
7
9
 
8
10
  import { createSpaceObjectGenerator, TestSchemaType } from '@dxos/echo-generator';
9
11
  import { TextType } from '@dxos/plugin-markdown/types';
10
12
  import { useClient } from '@dxos/react-client';
11
- import { create, createEchoObject, useSpaces } from '@dxos/react-client/echo';
13
+ import { create, createObject, useSpaces } from '@dxos/react-client/echo';
12
14
  import { withClientProvider } from '@dxos/react-client/testing';
13
15
  import { withLayout, withTheme } from '@dxos/storybook-utils';
14
16
 
15
- // @ts-ignore
16
- import mainUrl from './FrameContainer/frame?url';
17
17
  import { ScriptBlock } from './ScriptBlock';
18
18
  import { ScriptType } from '../../types';
19
+ // @ts-ignore
20
+ import mainUrl from '../FrameContainer/frame?url';
19
21
 
20
22
  const code = [
21
23
  "import { Filter, useQuery, useSpaces} from '@dxos/react-client/echo';",
@@ -29,7 +31,7 @@ const code = [
29
31
  '}',
30
32
  ].join('\n');
31
33
 
32
- const Story = () => {
34
+ const DefaultStory = () => {
33
35
  const client = useClient();
34
36
  const spaces = useSpaces();
35
37
  console.log(spaces.length);
@@ -51,21 +53,20 @@ const Story = () => {
51
53
  }, [client]);
52
54
 
53
55
  // TODO(burdon): Review what's the right way to create automerge-backed objects.
54
- const object = useMemo(
55
- () => createEchoObject(create(ScriptType, { source: create(TextType, { content: code }) })),
56
- [],
57
- );
56
+ const object = useMemo(() => createObject(create(ScriptType, { source: create(TextType, { content: code }) })), []);
58
57
 
59
58
  // TODO(dmaretskyi): Not sure how to provide `containerUrl` here since the html now lives in composer-app.
60
59
  // TODO(burdon): Normalize html/frame.tsx with composer-app to test locally.
61
60
  return <ScriptBlock script={object} containerUrl={mainUrl} />;
62
61
  };
63
62
 
64
- export default {
65
- title: 'plugin-script/ScriptBlock',
63
+ export const Default = {};
64
+
65
+ const meta: Meta = {
66
+ title: 'plugins/plugin-script/ScriptBlock',
66
67
  component: ScriptBlock,
67
- decorators: [withTheme, withLayout({ fullscreen: true, tooltips: true }), withClientProvider({ createSpace: true })],
68
- render: Story,
68
+ render: DefaultStory,
69
+ decorators: [withClientProvider({ createSpace: true }), withTheme, withLayout({ fullscreen: true, tooltips: true })],
69
70
  };
70
71
 
71
- export const Default = {};
72
+ export default meta;