@dxos/plugin-script 0.6.13 → 0.6.14-main.1366248

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 (206) hide show
  1. package/README.md +1 -1
  2. package/dist/lib/browser/AutomationPanel-XLL2ZXGS.mjs +78 -0
  3. package/dist/lib/browser/AutomationPanel-XLL2ZXGS.mjs.map +7 -0
  4. package/dist/lib/browser/ScriptContainer-YXH4MFEO.mjs +415 -0
  5. package/dist/lib/browser/ScriptContainer-YXH4MFEO.mjs.map +7 -0
  6. package/dist/lib/browser/chunk-C7VBULMK.mjs +18 -0
  7. package/dist/lib/browser/chunk-C7VBULMK.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-NCZUJKJE.mjs +236 -0
  13. package/dist/lib/browser/chunk-NCZUJKJE.mjs.map +7 -0
  14. package/dist/lib/browser/{chunk-O4LWBX6A.mjs → chunk-USXWNH3S.mjs} +2 -2
  15. package/dist/lib/browser/{chunk-O4LWBX6A.mjs.map → chunk-USXWNH3S.mjs.map} +2 -2
  16. package/dist/lib/browser/edge/index.mjs +5 -1
  17. package/dist/lib/browser/index.mjs +185 -62
  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-OSPAFWZU.cjs +100 -0
  23. package/dist/lib/node/AutomationPanel-OSPAFWZU.cjs.map +7 -0
  24. package/dist/lib/node/ScriptContainer-FWHFEIHK.cjs +417 -0
  25. package/dist/lib/node/ScriptContainer-FWHFEIHK.cjs.map +7 -0
  26. package/dist/lib/node/{TypescriptEditor-M3WWFIP2.cjs → chunk-6LYX73ZT.cjs} +19 -8
  27. package/dist/lib/node/chunk-6LYX73ZT.cjs.map +7 -0
  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/chunk-BJ4WIWCP.cjs +265 -0
  31. package/dist/lib/node/chunk-BJ4WIWCP.cjs.map +7 -0
  32. package/dist/lib/node/{chunk-5RBVXKXT.cjs → chunk-CPNHUAFN.cjs} +6 -6
  33. package/dist/lib/node/{chunk-5RBVXKXT.cjs.map → chunk-CPNHUAFN.cjs.map} +2 -2
  34. package/dist/lib/node/{chunk-PFH3ROEH.cjs → chunk-FY5KKL5N.cjs} +22 -8
  35. package/dist/lib/node/chunk-FY5KKL5N.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 +196 -81
  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-KJNL6ARP.mjs +79 -0
  46. package/dist/lib/node-esm/AutomationPanel-KJNL6ARP.mjs.map +7 -0
  47. package/dist/lib/node-esm/ScriptContainer-6U5WJFRB.mjs +416 -0
  48. package/dist/lib/node-esm/ScriptContainer-6U5WJFRB.mjs.map +7 -0
  49. package/dist/lib/node-esm/chunk-2NPZGQGA.mjs +47 -0
  50. package/dist/lib/node-esm/chunk-2NPZGQGA.mjs.map +7 -0
  51. package/dist/lib/node-esm/chunk-DXWSRDEN.mjs +237 -0
  52. package/dist/lib/node-esm/chunk-DXWSRDEN.mjs.map +7 -0
  53. package/dist/lib/node-esm/chunk-LDLNTVAK.mjs +280 -0
  54. package/dist/lib/node-esm/chunk-LDLNTVAK.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-SLTZMY34.mjs +20 -0
  58. package/dist/lib/node-esm/chunk-SLTZMY34.mjs.map +7 -0
  59. package/dist/lib/node-esm/edge/index.mjs +24 -0
  60. package/dist/lib/node-esm/index.mjs +415 -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/DebugPanel.d.ts +7 -0
  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/ScriptSettingsPanel.d.ts +7 -0
  93. package/dist/types/src/components/ScriptSettingsPanel.d.ts.map +1 -0
  94. package/dist/types/src/components/Toolbar/Toolbar.d.ts +23 -0
  95. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -0
  96. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +14 -0
  97. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -0
  98. package/dist/types/src/components/Toolbar/index.d.ts +2 -0
  99. package/dist/types/src/components/Toolbar/index.d.ts.map +1 -0
  100. package/dist/types/src/components/{TypescriptEditor.d.ts → TypescriptEditor/TypescriptEditor.d.ts} +1 -2
  101. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -0
  102. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts +6 -0
  103. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts.map +1 -0
  104. package/dist/types/src/components/TypescriptEditor/index.d.ts +2 -0
  105. package/dist/types/src/components/TypescriptEditor/index.d.ts.map +1 -0
  106. package/dist/types/src/components/index.d.ts +4 -3
  107. package/dist/types/src/components/index.d.ts.map +1 -1
  108. package/dist/types/src/edge/functions.d.ts +7 -0
  109. package/dist/types/src/edge/functions.d.ts.map +1 -1
  110. package/dist/types/src/meta.d.ts +5 -9
  111. package/dist/types/src/meta.d.ts.map +1 -1
  112. package/dist/types/src/templates/chat.d.ts +6 -0
  113. package/dist/types/src/templates/chat.d.ts.map +1 -0
  114. package/dist/types/src/templates/chess.d.ts +6 -0
  115. package/dist/types/src/templates/chess.d.ts.map +1 -0
  116. package/dist/types/src/templates/echo.d.ts +6 -0
  117. package/dist/types/src/templates/echo.d.ts.map +1 -0
  118. package/dist/types/src/templates/email.d.ts +6 -0
  119. package/dist/types/src/templates/email.d.ts.map +1 -0
  120. package/dist/types/src/templates/forex.d.ts +6 -0
  121. package/dist/types/src/templates/forex.d.ts.map +1 -0
  122. package/dist/types/src/templates.d.ts +8 -0
  123. package/dist/types/src/templates.d.ts.map +1 -0
  124. package/dist/types/src/translations.d.ts +7 -0
  125. package/dist/types/src/translations.d.ts.map +1 -1
  126. package/dist/types/src/types/script.d.ts +4 -4
  127. package/dist/types/src/types/types.d.ts +4 -3
  128. package/dist/types/src/types/types.d.ts.map +1 -1
  129. package/package.json +59 -64
  130. package/src/ScriptPlugin.tsx +47 -41
  131. package/src/bundler/bundler.test.ts +12 -2
  132. package/src/components/AutomationPanel/AutomationPanel.tsx +101 -0
  133. package/src/components/AutomationPanel/index.ts +9 -0
  134. package/src/components/{DebugPanel.tsx → DebugPanel/DebugPanel.tsx} +74 -96
  135. package/src/components/DebugPanel/index.ts +5 -0
  136. package/src/components/{ScriptBlock/FrameContainer → FrameContainer}/FrameContainer.tsx +1 -1
  137. package/src/components/ScriptBlock/ScriptBlock.stories.tsx +15 -14
  138. package/src/components/ScriptBlock/ScriptBlock.tsx +23 -51
  139. package/src/components/ScriptContainer.tsx +22 -0
  140. package/src/components/ScriptEditor.tsx +51 -62
  141. package/src/components/ScriptSettings/ScriptSettings.tsx +47 -0
  142. package/src/components/ScriptSettings/index.ts +5 -0
  143. package/src/components/ScriptSettingsPanel.tsx +105 -0
  144. package/src/components/Toolbar/Toolbar.stories.tsx +30 -0
  145. package/src/components/Toolbar/Toolbar.tsx +177 -0
  146. package/src/components/{ScriptBlock/Splitter → Toolbar}/index.ts +1 -1
  147. package/src/components/{TypescriptEditor.stories.tsx → TypescriptEditor/TypescriptEditor.stories.tsx} +17 -35
  148. package/src/components/{TypescriptEditor.tsx → TypescriptEditor/TypescriptEditor.tsx} +1 -3
  149. package/src/components/TypescriptEditor/index.ts +5 -0
  150. package/src/components/index.ts +6 -3
  151. package/src/edge/functions.ts +19 -0
  152. package/src/meta.ts +16 -0
  153. package/src/templates/chat.ts +102 -0
  154. package/src/templates/chess.ts +41 -0
  155. package/src/templates/echo.ts +15 -0
  156. package/src/templates/email.ts +38 -0
  157. package/src/templates/forex.ts +21 -0
  158. package/src/templates.ts +54 -0
  159. package/src/translations.ts +7 -0
  160. package/src/types/types.ts +9 -5
  161. package/dist/lib/browser/ScriptEditor-5Y3EROG3.mjs +0 -513
  162. package/dist/lib/browser/ScriptEditor-5Y3EROG3.mjs.map +0 -7
  163. package/dist/lib/browser/TypescriptEditor-GPE72Y6I.mjs +0 -9
  164. package/dist/lib/browser/chunk-DL5XQRQM.mjs.map +0 -7
  165. package/dist/lib/browser/chunk-JBACGDOJ.mjs +0 -21
  166. package/dist/lib/browser/chunk-JBACGDOJ.mjs.map +0 -7
  167. package/dist/lib/browser/chunk-MRGOT5RF.mjs +0 -78
  168. package/dist/lib/browser/chunk-MRGOT5RF.mjs.map +0 -7
  169. package/dist/lib/node/ScriptEditor-YCUQFWQM.cjs +0 -526
  170. package/dist/lib/node/ScriptEditor-YCUQFWQM.cjs.map +0 -7
  171. package/dist/lib/node/TypescriptEditor-M3WWFIP2.cjs.map +0 -7
  172. package/dist/lib/node/chunk-4GTXIELQ.cjs.map +0 -7
  173. package/dist/lib/node/chunk-4VMNBXWU.cjs +0 -54
  174. package/dist/lib/node/chunk-4VMNBXWU.cjs.map +0 -7
  175. package/dist/lib/node/chunk-IMLDKD5Y.cjs +0 -111
  176. package/dist/lib/node/chunk-IMLDKD5Y.cjs.map +0 -7
  177. package/dist/lib/node/chunk-PFH3ROEH.cjs.map +0 -7
  178. package/dist/types/src/components/DebugPanel.d.ts +0 -9
  179. package/dist/types/src/components/DebugPanel.d.ts.map +0 -1
  180. package/dist/types/src/components/ScriptBlock/FrameContainer/FrameContainer.d.ts.map +0 -1
  181. package/dist/types/src/components/ScriptBlock/FrameContainer/frame.d.ts.map +0 -1
  182. package/dist/types/src/components/ScriptBlock/FrameContainer/index.d.ts.map +0 -1
  183. package/dist/types/src/components/ScriptBlock/Splitter/Splitter.d.ts +0 -15
  184. package/dist/types/src/components/ScriptBlock/Splitter/Splitter.d.ts.map +0 -1
  185. package/dist/types/src/components/ScriptBlock/Splitter/Splitter.stories.d.ts +0 -13
  186. package/dist/types/src/components/ScriptBlock/Splitter/Splitter.stories.d.ts.map +0 -1
  187. package/dist/types/src/components/ScriptBlock/Splitter/index.d.ts +0 -2
  188. package/dist/types/src/components/ScriptBlock/Splitter/index.d.ts.map +0 -1
  189. package/dist/types/src/components/Toolbar.d.ts +0 -13
  190. package/dist/types/src/components/Toolbar.d.ts.map +0 -1
  191. package/dist/types/src/components/Toolbar.stories.d.ts +0 -14
  192. package/dist/types/src/components/Toolbar.stories.d.ts.map +0 -1
  193. package/dist/types/src/components/TypescriptEditor.d.ts.map +0 -1
  194. package/dist/types/src/components/TypescriptEditor.stories.d.ts +0 -10
  195. package/dist/types/src/components/TypescriptEditor.stories.d.ts.map +0 -1
  196. package/src/components/ScriptBlock/Splitter/Splitter.stories.tsx +0 -37
  197. package/src/components/ScriptBlock/Splitter/Splitter.tsx +0 -52
  198. package/src/components/Toolbar.stories.tsx +0 -17
  199. package/src/components/Toolbar.tsx +0 -147
  200. package/src/meta.tsx +0 -19
  201. /package/dist/lib/{browser/TypescriptEditor-GPE72Y6I.mjs.map → node-esm/edge/index.mjs.map} +0 -0
  202. /package/dist/types/src/components/{ScriptBlock/FrameContainer → FrameContainer}/frame.d.ts +0 -0
  203. /package/dist/types/src/components/{ScriptBlock/FrameContainer → FrameContainer}/index.d.ts +0 -0
  204. /package/src/components/{ScriptBlock/FrameContainer → FrameContainer}/frame.html +0 -0
  205. /package/src/components/{ScriptBlock/FrameContainer → FrameContainer}/frame.tsx +0 -0
  206. /package/src/components/{ScriptBlock/FrameContainer → FrameContainer}/index.ts +0 -0
@@ -0,0 +1,47 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import React from 'react';
6
+
7
+ import { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
8
+ import { useClient } from '@dxos/react-client';
9
+ import { Button, useTranslation } from '@dxos/react-ui';
10
+ import { DeprecatedFormInput } from '@dxos/react-ui-data';
11
+
12
+ import { SCRIPT_PLUGIN } from '../../meta';
13
+ import { type ScriptSettingsProps } from '../../types';
14
+
15
+ export const ScriptSettings = ({ settings }: { settings: ScriptSettingsProps }) => {
16
+ const { t } = useTranslation(SCRIPT_PLUGIN);
17
+ const client = useClient();
18
+
19
+ // TODO(burdon): Check token.
20
+ const handleAuthenticate = async () => {
21
+ const { identityKey } = client.halo.identity.get()!;
22
+ await client.halo.writeCredentials([
23
+ {
24
+ issuer: identityKey,
25
+ issuanceDate: new Date(),
26
+ subject: {
27
+ id: identityKey,
28
+ assertion: {
29
+ '@type': 'dxos.halo.credentials.ServiceAccess',
30
+ serverName: 'hub.dxos.network',
31
+ serverKey: identityKey,
32
+ identityKey,
33
+ capabilities: ['composer:beta'],
34
+ },
35
+ },
36
+ } satisfies Credential,
37
+ ]);
38
+ };
39
+
40
+ return (
41
+ <>
42
+ <DeprecatedFormInput label={t('authenticate action label')}>
43
+ <Button onClick={handleAuthenticate}>{t('authenticate button label')}</Button>
44
+ </DeprecatedFormInput>
45
+ </>
46
+ );
47
+ };
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ export * from './ScriptSettings';
@@ -0,0 +1,105 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import React, { type ChangeEvent, useCallback } from 'react';
6
+
7
+ import { useClient } from '@dxos/react-client';
8
+ import { Filter, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';
9
+ import { Button, Icon, Input, useControlledValue, useTranslation } from '@dxos/react-ui';
10
+
11
+ import { getInvocationUrl, getUserFunctionUrlInMetadata } from '../edge';
12
+ import { SCRIPT_PLUGIN } from '../meta';
13
+ import { FunctionType, type ScriptType } from '../types';
14
+
15
+ export type ScriptSettingsPanelProps = {
16
+ script: ScriptType;
17
+ };
18
+
19
+ export const ScriptSettingsPanel = ({ script }: ScriptSettingsPanelProps) => {
20
+ const { t } = useTranslation(SCRIPT_PLUGIN);
21
+ const client = useClient();
22
+ const space = getSpace(script);
23
+ // TODO(dmaretskyi): Parametric query.
24
+ const [fn] = useQuery(
25
+ space,
26
+ Filter.schema(FunctionType, (fn) => fn.source === script),
27
+ );
28
+
29
+ const handleNameChange = useCallback(
30
+ (event: ChangeEvent<HTMLInputElement>) => {
31
+ script.name = event.target.value;
32
+ },
33
+ [script],
34
+ );
35
+
36
+ const [binding, setBinding] = useControlledValue(fn?.binding ?? '');
37
+ const handleBindingChange = useCallback(
38
+ (event: ChangeEvent<HTMLInputElement>) => {
39
+ setBinding(event.target.value);
40
+ },
41
+ [setBinding],
42
+ );
43
+ const handleBindingBlur = useCallback(() => {
44
+ fn.binding = binding;
45
+ }, [fn, binding]);
46
+
47
+ const functionPath = fn && getUserFunctionUrlInMetadata(getMeta(fn));
48
+ const functionUrl =
49
+ functionPath &&
50
+ getInvocationUrl(functionPath, client.config.values.runtime?.services?.edge?.url ?? '', {
51
+ spaceId: space?.id,
52
+ });
53
+
54
+ // TODO(wittjosiah): Use ClipboardProvider.
55
+ const handleCopy = useCallback(() => functionUrl && navigator.clipboard.writeText(functionUrl), [functionUrl]);
56
+
57
+ return (
58
+ <div role='form' className='flex flex-col w-full p-2 gap-4'>
59
+ <Input.Root>
60
+ <div role='none' className='flex flex-col gap-1'>
61
+ <Input.Label>{t('name label')}</Input.Label>
62
+ <Input.TextInput
63
+ placeholder={t('object title placeholder')}
64
+ value={script.name ?? ''}
65
+ onChange={handleNameChange}
66
+ />
67
+ </div>
68
+ </Input.Root>
69
+ {fn && (
70
+ <>
71
+ <hr className='border-separator' />
72
+ <h2>{t('remote function settings heading')}</h2>
73
+ <Input.Root>
74
+ <div role='none' className='flex flex-col gap-1'>
75
+ <Input.Label>{t('function url label')}</Input.Label>
76
+ <div role='none' className='flex gap-1'>
77
+ <Input.TextInput
78
+ disabled
79
+ value={functionUrl}
80
+ onChange={(event) => {
81
+ fn.name = event.target.value;
82
+ }}
83
+ />
84
+ <Button onClick={handleCopy}>
85
+ <Icon icon='ph--copy--regular' size={4} />
86
+ </Button>
87
+ </div>
88
+ </div>
89
+ </Input.Root>
90
+ <Input.Root>
91
+ <div role='none' className='flex flex-col gap-1'>
92
+ <Input.Label>{t('function binding label')}</Input.Label>
93
+ <Input.TextInput
94
+ placeholder={t('function binding placeholder')}
95
+ value={binding}
96
+ onChange={handleBindingChange}
97
+ onBlur={handleBindingBlur}
98
+ />
99
+ </div>
100
+ </Input.Root>
101
+ </>
102
+ )}
103
+ </div>
104
+ );
105
+ };
@@ -0,0 +1,30 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import '@dxos-theme';
6
+
7
+ import { type Meta } from '@storybook/react';
8
+
9
+ import { withLayout, withTheme } from '@dxos/storybook-utils';
10
+
11
+ import { Toolbar } from './Toolbar';
12
+ import { templates } from '../../templates';
13
+
14
+ export const Default = {
15
+ args: {
16
+ binding: 'example',
17
+ deployed: true,
18
+ templates,
19
+ onFormat: () => console.log('Format'),
20
+ onTogglePanel: () => {},
21
+ },
22
+ };
23
+
24
+ const meta: Meta = {
25
+ title: 'plugins/plugin-script/Toolbar',
26
+ component: Toolbar,
27
+ decorators: [withTheme, withLayout({ tooltips: true })],
28
+ };
29
+
30
+ export default meta;
@@ -0,0 +1,177 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import React, { useState } from 'react';
6
+
7
+ import {
8
+ ElevationProvider,
9
+ Icon,
10
+ Select,
11
+ type ThemedClassName,
12
+ ToggleGroup,
13
+ ToggleGroupItem,
14
+ type ToolbarButtonProps,
15
+ Toolbar as NaturalToolbar,
16
+ Tooltip,
17
+ useTranslation,
18
+ } from '@dxos/react-ui';
19
+
20
+ import { SCRIPT_PLUGIN } from '../../meta';
21
+ import { type Template } from '../../templates';
22
+
23
+ export type ToolbarProps = ThemedClassName<
24
+ {
25
+ deployed?: boolean;
26
+ error?: string;
27
+ functionUrl?: string;
28
+ onDeploy?: () => Promise<void>;
29
+ onFormat?: () => Promise<void>;
30
+ } & TemplateSelectProps &
31
+ ViewSelectorProps
32
+ >;
33
+
34
+ export const Toolbar = ({
35
+ classNames,
36
+ deployed,
37
+ error,
38
+ functionUrl,
39
+ view,
40
+ templates,
41
+ onDeploy,
42
+ onFormat,
43
+ onViewChange,
44
+ onTemplateSelect,
45
+ }: ToolbarProps) => {
46
+ const { t } = useTranslation(SCRIPT_PLUGIN);
47
+ const [pending, setPending] = useState(false);
48
+
49
+ const handleCopyLink = async () => {
50
+ if (!functionUrl) {
51
+ return;
52
+ }
53
+
54
+ await navigator.clipboard.writeText(functionUrl);
55
+ };
56
+
57
+ const handleDeploy = async () => {
58
+ if (!pending) {
59
+ setPending(true);
60
+ await onDeploy?.();
61
+ setPending(false);
62
+ }
63
+ };
64
+
65
+ // TODO(burdon): Factor out common toolbar components with sheet/editor?
66
+ return (
67
+ <ElevationProvider elevation='chrome'>
68
+ <NaturalToolbar.Root classNames={['p-1', classNames]} style={{ contain: 'layout' }}>
69
+ {templates && <TemplateSelect templates={templates} onTemplateSelect={onTemplateSelect} />}
70
+ {onFormat && <ToolbarIconButton icon='ph--magic-wand--regular' text={t('format label')} onClick={onFormat} />}
71
+
72
+ <div role='separator' className='grow' />
73
+
74
+ {error ? (
75
+ <Tooltip.Root>
76
+ <Tooltip.Trigger>
77
+ <Icon icon='ph--warning-circle--regular' size={4} />
78
+ </Tooltip.Trigger>
79
+ <Tooltip.Portal>
80
+ <Tooltip.Content>
81
+ <Tooltip.Arrow />
82
+ {error}
83
+ </Tooltip.Content>
84
+ </Tooltip.Portal>
85
+ </Tooltip.Root>
86
+ ) : null}
87
+
88
+ {functionUrl && deployed && (
89
+ <ToolbarIconButton icon='ph--link--regular' text={t('copy link label')} onClick={handleCopyLink} />
90
+ )}
91
+
92
+ {onDeploy && (
93
+ <ToolbarIconButton
94
+ icon={pending ? 'ph--spinner-gap--regular' : 'ph--cloud-arrow-up--regular'}
95
+ classNames={[pending && 'animate-spin']}
96
+ text={pending ? t('pending label') : t('deploy label')}
97
+ onClick={handleDeploy}
98
+ />
99
+ )}
100
+
101
+ <ViewSelector view={view} onViewChange={onViewChange} />
102
+ </NaturalToolbar.Root>
103
+ </ElevationProvider>
104
+ );
105
+ };
106
+
107
+ const ToolbarIconButton = ({
108
+ icon,
109
+ text,
110
+ classNames,
111
+ disabled,
112
+ onClick,
113
+ }: { icon: string; text: string } & Pick<ToolbarButtonProps, 'classNames' | 'disabled' | 'onClick'>) => {
114
+ return (
115
+ <Tooltip.Root>
116
+ <Tooltip.Trigger asChild>
117
+ <NaturalToolbar.Button variant='ghost' disabled={disabled} onClick={onClick}>
118
+ <Icon icon={icon} size={4} classNames={classNames} />
119
+ </NaturalToolbar.Button>
120
+ </Tooltip.Trigger>
121
+ <Tooltip.Portal>
122
+ <Tooltip.Content>
123
+ <Tooltip.Arrow />
124
+ {text}
125
+ </Tooltip.Content>
126
+ </Tooltip.Portal>
127
+ </Tooltip.Root>
128
+ );
129
+ };
130
+
131
+ export type ViewType = 'editor' | 'split' | 'preview';
132
+
133
+ export type TemplateSelectProps = {
134
+ templates?: Template[];
135
+ onTemplateSelect?: (id: string) => void;
136
+ };
137
+
138
+ export const TemplateSelect = ({ templates = [], onTemplateSelect }: TemplateSelectProps) => {
139
+ return (
140
+ <Select.Root value={''} onValueChange={onTemplateSelect}>
141
+ <Select.TriggerButton />
142
+ <Select.Portal>
143
+ <Select.Content>
144
+ <Select.Viewport>
145
+ <Select.Option value={''}>Template</Select.Option>
146
+ {templates.map(({ id, name }) => (
147
+ <Select.Option key={id} value={id}>
148
+ {name}
149
+ </Select.Option>
150
+ ))}
151
+ </Select.Viewport>
152
+ </Select.Content>
153
+ </Select.Portal>
154
+ </Select.Root>
155
+ );
156
+ };
157
+
158
+ export type ViewSelectorProps = {
159
+ view?: ViewType;
160
+ onViewChange?: (view: ViewType) => void;
161
+ };
162
+
163
+ export const ViewSelector = ({ view, onViewChange }: ViewSelectorProps) => {
164
+ return (
165
+ <ToggleGroup type='single' value={view} onValueChange={(value) => onViewChange?.(value as ViewType)}>
166
+ <ToggleGroupItem value='editor' classNames='bg-transparent text-subdued'>
167
+ <Icon icon='ph--code--regular' size={4} />
168
+ </ToggleGroupItem>
169
+ <ToggleGroupItem value='split' classNames='bg-transparent text-subdued'>
170
+ <Icon icon='ph--square-split-vertical--regular' size={4} />
171
+ </ToggleGroupItem>
172
+ <ToggleGroupItem value='preview' classNames='bg-transparent text-subdued'>
173
+ <Icon icon='ph--eye--regular' size={4} />
174
+ </ToggleGroupItem>
175
+ </ToggleGroup>
176
+ );
177
+ };
@@ -2,4 +2,4 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- export * from './Splitter';
5
+ export * from './Toolbar';
@@ -4,57 +4,39 @@
4
4
 
5
5
  import '@dxos-theme';
6
6
 
7
+ import { type Meta } from '@storybook/react';
7
8
  import React, { useMemo } from 'react';
8
9
 
9
- import { createDocAccessor, createEchoObject } from '@dxos/react-client/echo';
10
+ import { createDocAccessor, createObject } from '@dxos/react-client/echo';
10
11
  import { createDataExtensions } from '@dxos/react-ui-editor';
11
12
 
12
13
  import { TypescriptEditor } from './TypescriptEditor';
14
+ import { templates } from '../../templates';
13
15
 
14
- // TODO(burdon): Typescript.
15
- // TODO(burdon): Effect schema.
16
- // TODO(burdon): JSX.
17
- // TODO(burdon): react-buddy for storybook?
18
-
19
- // Marijn
16
+ // TODO(burdon): Features:
20
17
  // - language support for S
21
18
  // - hierarchical editor (DND)
22
19
  // - virtual document image rendering
23
20
  // - mobile rendering error
24
21
 
25
- const examples: string[] = [
26
- [
27
- '// Example function.',
28
- 'export default function() {',
29
- ' const value = 100',
30
- ' return <div>{value}</div>;',
31
- '}',
32
- ].join('\n'),
33
- [
34
- '// Example schema.',
35
- 'S.Struct({',
36
- ' timestamp: S.Date,',
37
- ' title: S.String,',
38
- ' content: R.Text,',
39
- "}).pipe(S.identifier('dxos.org/schema/Test'))",
40
- '',
41
- ].join('\n'),
42
- ];
43
-
44
- const Story = () => {
45
- const object = useMemo(() => createEchoObject({ content: examples[0] }), []);
22
+ // TODO(burdon): JSX.
23
+ // TODO(burdon): Effect schema.
24
+ // TODO(burdon): react-buddy for storybook?
25
+
26
+ const DefaultStory = () => {
27
+ const object = useMemo(() => createObject({ content: templates[0].source }), []);
46
28
  const initialValue = useMemo(() => object.content, [object]);
47
29
  const accessor = useMemo(() => createDocAccessor(object, ['content']), [object]);
48
30
  const extensions = useMemo(() => [createDataExtensions({ id: object.id, text: accessor })], [object.id, accessor]);
49
-
50
- // TODO(wittjosiah): Scroll past end breaks the editor.
51
- return <TypescriptEditor id='test' initialValue={initialValue} extensions={extensions} scrollPastEnd={false} />;
31
+ return <TypescriptEditor id='test' initialValue={initialValue} extensions={extensions} />;
52
32
  };
53
33
 
54
- export default {
55
- title: 'plugin-script/TypescriptEditor',
34
+ export const Default = {};
35
+
36
+ const meta: Meta = {
37
+ title: 'plugins/plugin-script/TypescriptEditor',
56
38
  component: TypescriptEditor,
57
- render: Story,
39
+ render: DefaultStory,
58
40
  };
59
41
 
60
- export const Default = {};
42
+ export default meta;
@@ -23,13 +23,11 @@ import { nonNullable } from '@dxos/util';
23
23
 
24
24
  export type TypescriptEditorProps = {
25
25
  id: string;
26
- scrollPastEnd?: boolean;
27
26
  env?: VirtualTypeScriptEnvironment;
28
27
  } & Pick<UseTextEditorProps, 'className' | 'initialValue' | 'extensions' | 'scrollTo' | 'selection'>;
29
28
 
30
29
  export const TypescriptEditor = ({
31
30
  id,
32
- scrollPastEnd,
33
31
  env,
34
32
  className,
35
33
  initialValue,
@@ -49,7 +47,7 @@ export const TypescriptEditor = ({
49
47
  indentWithTab: true,
50
48
  lineNumbers: true,
51
49
  lineWrapping: false,
52
- scrollPastEnd,
50
+ scrollPastEnd: true,
53
51
  }),
54
52
  createThemeExtensions({
55
53
  themeMode,
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ export * from './TypescriptEditor';
@@ -2,7 +2,10 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import React from 'react';
5
+ import { lazy } from 'react';
6
6
 
7
- export const ScriptEditor = React.lazy(() => import('./ScriptEditor'));
8
- export const TypescriptEditor = React.lazy(() => import('./TypescriptEditor'));
7
+ export * from './ScriptSettings';
8
+ export * from './ScriptSettingsPanel';
9
+
10
+ export const AutomationPanel = lazy(() => import('./AutomationPanel'));
11
+ export const ScriptContainer = lazy(() => import('./ScriptContainer'));
@@ -9,6 +9,7 @@ import { type Config } from '@dxos/client';
9
9
  import { type Halo } from '@dxos/client-protocol';
10
10
  import { type ObjectMeta } from '@dxos/echo-schema';
11
11
  import { invariant } from '@dxos/invariant';
12
+ import type { SpaceId } from '@dxos/keys';
12
13
  import { log } from '@dxos/log';
13
14
  import { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
14
15
 
@@ -17,6 +18,7 @@ import { matchServiceCredential } from './hub-protocol';
17
18
 
18
19
  // TODO: use URL scheme for source?
19
20
  const USERFUNCTIONS_META_KEY = 'dxos.org/service/function';
21
+ export const USERFUNCTIONS_PRESET_META_KEY = 'dxos.org/service/function-preset';
20
22
  const USERFUNCTIONS_CREDENTIAL_CAPABILITY = 'composer:beta';
21
23
 
22
24
  // TODO: Synchronize API types with server
@@ -132,3 +134,20 @@ const presentationForIdentity = async ({ halo, timeout }: { halo: Halo; timeout?
132
134
 
133
135
  return { Authorization: `Bearer ${codec.encode(presentation)}` };
134
136
  };
137
+
138
+ export type InvocationOptions = {
139
+ spaceId?: SpaceId;
140
+ subjectId?: string;
141
+ };
142
+
143
+ export const getInvocationUrl = (functionUrl: string, edgeUrl: string, options: InvocationOptions = {}) => {
144
+ const baseUrl = new URL('functions/', edgeUrl);
145
+
146
+ // Leading slashes cause the URL to be treated as an absolute path.
147
+ const relativeUrl = functionUrl.replace(/^\//, '');
148
+ const url = new URL(`./${relativeUrl}`, baseUrl.toString());
149
+ options.spaceId && url.searchParams.set('spaceId', options.spaceId);
150
+ options.subjectId && url.searchParams.set('subjectId', options.subjectId);
151
+ url.protocol = 'https';
152
+ return url.toString();
153
+ };
package/src/meta.ts ADDED
@@ -0,0 +1,16 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { type PluginMeta } from '@dxos/app-framework';
6
+
7
+ export const SCRIPT_PLUGIN = 'dxos.org/plugin/script';
8
+
9
+ export default {
10
+ id: SCRIPT_PLUGIN,
11
+ name: 'Scripts',
12
+ description: 'Distributed functions.',
13
+ icon: 'ph--code--regular',
14
+ source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/experimental/plugin-explorer',
15
+ tags: ['experimental'],
16
+ } satisfies PluginMeta;
@@ -0,0 +1,102 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ // @ts-ignore
6
+ import { transformServerSentEvents } from 'https://esm.sh/@dxos/script-toolbox';
7
+
8
+ /**
9
+ * Chatbot that answers questions based on the context data.
10
+ */
11
+ export default async ({
12
+ event: {
13
+ data: { request },
14
+ },
15
+ context: { space, ai },
16
+ }: any) => {
17
+ const textBody = await request.text();
18
+ let parsedRequest: any;
19
+ try {
20
+ parsedRequest = JSON.parse(textBody);
21
+ } catch (err) {
22
+ const answer = await ai.run('@cf/meta/llama-3.1-8b-instruct', {
23
+ stream: true,
24
+ prompt: `
25
+ Using only the context data below to answer the user's question.
26
+ If you cannot answer the question from the provided content, then reply with "I don't know."
27
+
28
+ CONTEXT:
29
+ ${await getContext({ space })}
30
+
31
+ QUESTION:
32
+ ${textBody}
33
+ `,
34
+ });
35
+ return new Response(transformServerSentEvents(answer));
36
+ }
37
+
38
+ const promptId = parsedRequest.trigger.promptId;
39
+ const promptObject = await space.crud.query({ id: promptId }).first();
40
+
41
+ if (parsedRequest.data.objects.length !== 1) {
42
+ return new Response('Message batches not supported.');
43
+ }
44
+
45
+ const messageId = parsedRequest.data.objects[0];
46
+ let message;
47
+ try {
48
+ message = await space.crud.query({ id: messageId }).first();
49
+ } catch (err) {
50
+ return new Response('Message not replicated yet.', { status: 409 });
51
+ }
52
+
53
+ if (message.text.includes('--------')) {
54
+ return new Response('Message was already processed.');
55
+ }
56
+
57
+ let prompt = promptObject.template;
58
+ for (const input of promptObject.inputs) {
59
+ let value: string | null = null;
60
+ if (input.type === ChainInputType.VALUE) {
61
+ value = String(input.value);
62
+ } else if (input.type === ChainInputType.RETRIEVER) {
63
+ value = await getContext({ space });
64
+ } else if (input.type === ChainInputType.PASS_THROUGH) {
65
+ value = message.text;
66
+ }
67
+ if (value) {
68
+ prompt = prompt.replaceAll(`{${input.name}}`, value);
69
+ }
70
+ }
71
+
72
+ const answer = await ai.run('@cf/meta/llama-3.1-8b-instruct', {
73
+ stream: false,
74
+ prompt,
75
+ });
76
+ const response = { response: answer.response, prompt, message };
77
+ const textWithAnswer = message.text + '\n--------\n\n' + answer.response;
78
+ await space.crud.update({ id: messageId }, { text: textWithAnswer });
79
+
80
+ return new Response(JSON.stringify(response));
81
+ };
82
+
83
+ const getContext = async ({ space }: any) => {
84
+ let context = '';
85
+ const { objects: docs } = await space.crud.query({ __typename: 'dxos.org/type/Document' }).run();
86
+ for (const doc of docs) {
87
+ const { content } = await space.crud.query({ id: doc.content }).first();
88
+ context += content + '\n\n';
89
+ }
90
+ return context;
91
+ };
92
+
93
+ enum ChainInputType {
94
+ VALUE = 0,
95
+ PASS_THROUGH = 1,
96
+ RETRIEVER = 2,
97
+ FUNCTION = 3,
98
+ QUERY = 4,
99
+ RESOLVER = 5,
100
+ CONTEXT = 6,
101
+ SCHEMA = 7,
102
+ }