@dxos/plugin-script 0.7.5-labs.a279d8c → 0.7.5-labs.a8b535d

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 (245) hide show
  1. package/dist/lib/browser/ScriptContainer-3RFMYKTV.mjs +258 -0
  2. package/dist/lib/browser/ScriptContainer-3RFMYKTV.mjs.map +7 -0
  3. package/dist/lib/browser/artifact-definition-4LWPD3DH.mjs +251 -0
  4. package/dist/lib/browser/artifact-definition-4LWPD3DH.mjs.map +7 -0
  5. package/dist/lib/browser/{chunk-SJ4J527G.mjs → chunk-5SXOHNAK.mjs} +4 -4
  6. package/dist/lib/browser/chunk-5SXOHNAK.mjs.map +7 -0
  7. package/dist/lib/browser/{chunk-ZM6T4HPR.mjs → chunk-6MOQ4BP3.mjs} +2 -2
  8. package/dist/lib/browser/chunk-FVVCAWNP.mjs +21 -0
  9. package/dist/lib/browser/chunk-FVVCAWNP.mjs.map +7 -0
  10. package/dist/lib/browser/{ScriptContainer-T2AOMDT3.mjs → chunk-G2FYNDU4.mjs} +94 -304
  11. package/dist/lib/browser/chunk-G2FYNDU4.mjs.map +7 -0
  12. package/dist/lib/browser/{chunk-XPGBHZ3L.mjs → chunk-N46LE7FS.mjs} +2 -2
  13. package/dist/lib/browser/chunk-PZPYF7M4.mjs +69 -0
  14. package/dist/lib/browser/chunk-PZPYF7M4.mjs.map +7 -0
  15. package/dist/lib/browser/{chunk-SIOGRRPF.mjs → chunk-VTWBVFBK.mjs} +20 -10
  16. package/dist/lib/browser/chunk-VTWBVFBK.mjs.map +7 -0
  17. package/dist/lib/browser/{compiler-HT53ILG7.mjs → compiler-YY2XSKHQ.mjs} +4 -6
  18. package/dist/lib/browser/compiler-YY2XSKHQ.mjs.map +7 -0
  19. package/dist/lib/browser/index.mjs +72 -39
  20. package/dist/lib/browser/index.mjs.map +4 -4
  21. package/dist/lib/browser/intent-resolver-D6FPY5ZA.mjs +45 -0
  22. package/dist/lib/browser/intent-resolver-D6FPY5ZA.mjs.map +7 -0
  23. package/dist/lib/browser/meta.json +1 -1
  24. package/dist/lib/browser/{react-surface-GAWVYTJ5.mjs → react-surface-G4C2PZ2K.mjs} +33 -19
  25. package/dist/lib/browser/react-surface-G4C2PZ2K.mjs.map +7 -0
  26. package/dist/lib/browser/{settings-YQQEU3DF.mjs → settings-SZCDKHWO.mjs} +3 -3
  27. package/dist/lib/browser/types.mjs +2 -2
  28. package/dist/lib/node/ScriptContainer-G6FZU4AM.cjs +274 -0
  29. package/dist/lib/node/ScriptContainer-G6FZU4AM.cjs.map +7 -0
  30. package/dist/lib/node/artifact-definition-BXQCFPAH.cjs +267 -0
  31. package/dist/lib/node/artifact-definition-BXQCFPAH.cjs.map +7 -0
  32. package/dist/lib/node/{chunk-EFTZN5X7.cjs → chunk-5UH3F7TA.cjs} +8 -5
  33. package/dist/lib/node/chunk-5UH3F7TA.cjs.map +7 -0
  34. package/dist/lib/node/{chunk-A2DI2G4D.cjs → chunk-ALY3N6PW.cjs} +6 -6
  35. package/dist/lib/node/{chunk-6VKZJ4MH.cjs → chunk-DJGLGRQV.cjs} +6 -6
  36. package/dist/lib/node/chunk-ITAJ3WRW.cjs +77 -0
  37. package/dist/lib/node/chunk-ITAJ3WRW.cjs.map +7 -0
  38. package/dist/lib/node/{chunk-DQRAVZM7.cjs → chunk-K3ZZWVXS.cjs} +7 -7
  39. package/dist/lib/node/chunk-K3ZZWVXS.cjs.map +7 -0
  40. package/dist/lib/node/{chunk-5V3XGLTR.cjs → chunk-TOXBGIEI.cjs} +23 -14
  41. package/dist/lib/node/chunk-TOXBGIEI.cjs.map +7 -0
  42. package/dist/lib/node/chunk-XKYJYY3T.cjs +498 -0
  43. package/dist/lib/node/chunk-XKYJYY3T.cjs.map +7 -0
  44. package/dist/lib/node/{compiler-457ZR24G.cjs → compiler-UIBLKJKG.cjs} +9 -9
  45. package/dist/lib/node/compiler-UIBLKJKG.cjs.map +7 -0
  46. package/dist/lib/node/index.cjs +81 -50
  47. package/dist/lib/node/index.cjs.map +4 -4
  48. package/dist/lib/node/{intent-resolver-SUAPE7H3.cjs → intent-resolver-NYJFPD5B.cjs} +31 -28
  49. package/dist/lib/node/intent-resolver-NYJFPD5B.cjs.map +7 -0
  50. package/dist/lib/node/meta.json +1 -1
  51. package/dist/lib/node/{react-surface-OMBMSFZT.cjs → react-surface-EGSE3FMN.cjs} +38 -28
  52. package/dist/lib/node/react-surface-EGSE3FMN.cjs.map +7 -0
  53. package/dist/lib/node/{settings-NGHDYAVK.cjs → settings-SZFSMSKM.cjs} +9 -9
  54. package/dist/lib/node/types.cjs +4 -4
  55. package/dist/lib/node/types.cjs.map +1 -1
  56. package/dist/lib/node-esm/ScriptContainer-7FTCFIF3.mjs +259 -0
  57. package/dist/lib/node-esm/ScriptContainer-7FTCFIF3.mjs.map +7 -0
  58. package/dist/lib/node-esm/artifact-definition-KT4DK2LQ.mjs +252 -0
  59. package/dist/lib/node-esm/artifact-definition-KT4DK2LQ.mjs.map +7 -0
  60. package/dist/lib/node-esm/{chunk-XUWS7OTK.mjs → chunk-2AFXX34U.mjs} +4 -4
  61. package/dist/lib/node-esm/chunk-2AFXX34U.mjs.map +7 -0
  62. package/dist/lib/node-esm/{chunk-675XSDRN.mjs → chunk-CP5LXTK5.mjs} +2 -2
  63. package/dist/lib/node-esm/{ScriptContainer-3S5VHJVR.mjs → chunk-NRICF4KE.mjs} +94 -304
  64. package/dist/lib/node-esm/chunk-NRICF4KE.mjs.map +7 -0
  65. package/dist/lib/node-esm/{chunk-BHP545D7.mjs → chunk-P2V2Y5LV.mjs} +5 -2
  66. package/dist/lib/node-esm/chunk-P2V2Y5LV.mjs.map +7 -0
  67. package/dist/lib/node-esm/{chunk-XPIKUBGS.mjs → chunk-S64WSJQK.mjs} +20 -10
  68. package/dist/lib/node-esm/chunk-S64WSJQK.mjs.map +7 -0
  69. package/dist/lib/node-esm/{chunk-JHGOPQVO.mjs → chunk-UNQFIERE.mjs} +2 -2
  70. package/dist/lib/node-esm/chunk-YIWRJ25J.mjs +71 -0
  71. package/dist/lib/node-esm/chunk-YIWRJ25J.mjs.map +7 -0
  72. package/dist/lib/node-esm/{compiler-PEARFTFR.mjs → compiler-XTXFGZJM.mjs} +4 -6
  73. package/dist/lib/node-esm/compiler-XTXFGZJM.mjs.map +7 -0
  74. package/dist/lib/node-esm/index.mjs +72 -39
  75. package/dist/lib/node-esm/index.mjs.map +4 -4
  76. package/dist/lib/node-esm/intent-resolver-KLBHSMW4.mjs +46 -0
  77. package/dist/lib/node-esm/intent-resolver-KLBHSMW4.mjs.map +7 -0
  78. package/dist/lib/node-esm/meta.json +1 -1
  79. package/dist/lib/node-esm/{react-surface-J7NLV2V4.mjs → react-surface-7YSGHZQM.mjs} +33 -19
  80. package/dist/lib/node-esm/react-surface-7YSGHZQM.mjs.map +7 -0
  81. package/dist/lib/node-esm/{settings-XGXDY4NI.mjs → settings-GR4O2WHZ.mjs} +3 -3
  82. package/dist/lib/node-esm/types.mjs +2 -2
  83. package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
  84. package/dist/types/src/capabilities/artifact-definition.d.ts +11 -0
  85. package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -0
  86. package/dist/types/src/capabilities/index.d.ts +5 -4
  87. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  88. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
  89. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  90. package/dist/types/src/components/DebugPanel/DebugPanel.d.ts +1 -2
  91. package/dist/types/src/components/DebugPanel/DebugPanel.d.ts.map +1 -1
  92. package/dist/types/src/components/FrameContainer/FrameContainer.d.ts +3 -4
  93. package/dist/types/src/components/FrameContainer/FrameContainer.d.ts.map +1 -1
  94. package/dist/types/src/components/ScriptContainer.d.ts +2 -3
  95. package/dist/types/src/components/ScriptContainer.d.ts.map +1 -1
  96. package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts +1 -2
  97. package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts.map +1 -1
  98. package/dist/types/src/components/ScriptSettingsPanel.d.ts +1 -2
  99. package/dist/types/src/components/ScriptSettingsPanel.d.ts.map +1 -1
  100. package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts +2 -3
  101. package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts.map +1 -1
  102. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts +1 -2
  103. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -1
  104. package/dist/types/src/components/index.d.ts +2 -2
  105. package/dist/types/src/components/index.d.ts.map +1 -1
  106. package/dist/types/src/events.d.ts +4 -0
  107. package/dist/types/src/events.d.ts.map +1 -0
  108. package/dist/types/src/hooks/deploy.d.ts.map +1 -0
  109. package/dist/types/src/hooks/format.d.ts.map +1 -0
  110. package/dist/types/src/hooks/index.d.ts +7 -0
  111. package/dist/types/src/hooks/index.d.ts.map +1 -0
  112. package/dist/types/src/{components/ScriptToolbar/templateSelect.d.ts → hooks/template.d.ts} +2 -2
  113. package/dist/types/src/hooks/template.d.ts.map +1 -0
  114. package/dist/types/src/{components/ScriptToolbar → hooks}/useToolbarAction.d.ts +1 -1
  115. package/dist/types/src/hooks/useToolbarAction.d.ts.map +1 -0
  116. package/dist/types/src/hooks/useToolbarState.d.ts.map +1 -0
  117. package/dist/types/src/{components/ScriptToolbar → hooks}/view.d.ts +1 -1
  118. package/dist/types/src/hooks/view.d.ts.map +1 -0
  119. package/dist/types/src/index.d.ts +0 -1
  120. package/dist/types/src/index.d.ts.map +1 -1
  121. package/dist/types/src/meta.d.ts +1 -0
  122. package/dist/types/src/meta.d.ts.map +1 -1
  123. package/dist/types/src/templates/chess.d.ts +1 -4
  124. package/dist/types/src/templates/chess.d.ts.map +1 -1
  125. package/dist/types/src/templates/discord.d.ts +3 -0
  126. package/dist/types/src/templates/discord.d.ts.map +1 -0
  127. package/dist/types/src/templates/echo.d.ts.map +1 -1
  128. package/dist/types/src/templates/forex-effect.d.ts +3 -0
  129. package/dist/types/src/templates/forex-effect.d.ts.map +1 -0
  130. package/dist/types/src/templates/forex.d.ts +1 -4
  131. package/dist/types/src/templates/forex.d.ts.map +1 -1
  132. package/dist/types/src/templates/index.d.ts.map +1 -1
  133. package/dist/types/src/translations.d.ts +9 -0
  134. package/dist/types/src/translations.d.ts.map +1 -1
  135. package/dist/types/src/types.d.ts +1 -1
  136. package/dist/types/tsconfig.tsbuildinfo +1 -1
  137. package/package.json +43 -41
  138. package/src/ScriptPlugin.tsx +43 -26
  139. package/src/capabilities/artifact-definition.ts +224 -0
  140. package/src/capabilities/compiler.ts +1 -1
  141. package/src/capabilities/index.ts +1 -0
  142. package/src/capabilities/intent-resolver.ts +25 -22
  143. package/src/capabilities/react-surface.tsx +17 -11
  144. package/src/components/DebugPanel/DebugPanel.tsx +2 -2
  145. package/src/components/FrameContainer/FrameContainer.tsx +5 -4
  146. package/src/components/ScriptContainer.tsx +10 -5
  147. package/src/components/ScriptSettings/ScriptSettings.tsx +3 -3
  148. package/src/components/ScriptSettingsPanel.tsx +16 -2
  149. package/src/components/ScriptToolbar/ScriptToolbar.tsx +8 -6
  150. package/src/components/TypescriptEditor/TypescriptEditor.tsx +3 -3
  151. package/src/components/index.ts +1 -1
  152. package/src/events.ts +11 -0
  153. package/src/{components/ScriptToolbar → hooks}/deploy.ts +16 -4
  154. package/src/{components/ScriptToolbar → hooks}/format.ts +1 -1
  155. package/src/hooks/index.ts +11 -0
  156. package/src/{components/ScriptToolbar/templateSelect.ts → hooks/template.ts} +2 -2
  157. package/src/{components/ScriptToolbar → hooks}/useToolbarAction.ts +1 -1
  158. package/src/{components/ScriptToolbar → hooks}/view.ts +5 -2
  159. package/src/index.ts +0 -1
  160. package/src/meta.ts +3 -1
  161. package/src/templates/chat.ts +4 -4
  162. package/src/templates/chess.ts +42 -35
  163. package/src/templates/discord.ts +103 -0
  164. package/src/templates/echo.ts +5 -1
  165. package/src/templates/forex-effect.ts +41 -0
  166. package/src/templates/forex.ts +23 -16
  167. package/src/templates/index.ts +15 -0
  168. package/src/translations.ts +5 -0
  169. package/dist/lib/browser/AutomationPanel-OOIRJFPJ.mjs +0 -78
  170. package/dist/lib/browser/AutomationPanel-OOIRJFPJ.mjs.map +0 -7
  171. package/dist/lib/browser/ScriptContainer-T2AOMDT3.mjs.map +0 -7
  172. package/dist/lib/browser/chunk-5BU5ERNU.mjs +0 -18
  173. package/dist/lib/browser/chunk-5BU5ERNU.mjs.map +0 -7
  174. package/dist/lib/browser/chunk-REL2R7SB.mjs +0 -52
  175. package/dist/lib/browser/chunk-REL2R7SB.mjs.map +0 -7
  176. package/dist/lib/browser/chunk-SDHKTS6H.mjs +0 -237
  177. package/dist/lib/browser/chunk-SDHKTS6H.mjs.map +0 -7
  178. package/dist/lib/browser/chunk-SIOGRRPF.mjs.map +0 -7
  179. package/dist/lib/browser/chunk-SJ4J527G.mjs.map +0 -7
  180. package/dist/lib/browser/compiler-HT53ILG7.mjs.map +0 -7
  181. package/dist/lib/browser/intent-resolver-YPHT6HDZ.mjs +0 -42
  182. package/dist/lib/browser/intent-resolver-YPHT6HDZ.mjs.map +0 -7
  183. package/dist/lib/browser/react-surface-GAWVYTJ5.mjs.map +0 -7
  184. package/dist/lib/node/AutomationPanel-EPRDDR3A.cjs +0 -104
  185. package/dist/lib/node/AutomationPanel-EPRDDR3A.cjs.map +0 -7
  186. package/dist/lib/node/ScriptContainer-BV56I4OL.cjs +0 -689
  187. package/dist/lib/node/ScriptContainer-BV56I4OL.cjs.map +0 -7
  188. package/dist/lib/node/chunk-5V3XGLTR.cjs.map +0 -7
  189. package/dist/lib/node/chunk-DQRAVZM7.cjs.map +0 -7
  190. package/dist/lib/node/chunk-EFTZN5X7.cjs.map +0 -7
  191. package/dist/lib/node/chunk-T4TXCRN5.cjs +0 -260
  192. package/dist/lib/node/chunk-T4TXCRN5.cjs.map +0 -7
  193. package/dist/lib/node/chunk-TJ4BTPOS.cjs +0 -64
  194. package/dist/lib/node/chunk-TJ4BTPOS.cjs.map +0 -7
  195. package/dist/lib/node/compiler-457ZR24G.cjs.map +0 -7
  196. package/dist/lib/node/intent-resolver-SUAPE7H3.cjs.map +0 -7
  197. package/dist/lib/node/react-surface-OMBMSFZT.cjs.map +0 -7
  198. package/dist/lib/node-esm/AutomationPanel-DMLAGQS5.mjs +0 -79
  199. package/dist/lib/node-esm/AutomationPanel-DMLAGQS5.mjs.map +0 -7
  200. package/dist/lib/node-esm/ScriptContainer-3S5VHJVR.mjs.map +0 -7
  201. package/dist/lib/node-esm/chunk-BHP545D7.mjs.map +0 -7
  202. package/dist/lib/node-esm/chunk-G76M6O46.mjs +0 -239
  203. package/dist/lib/node-esm/chunk-G76M6O46.mjs.map +0 -7
  204. package/dist/lib/node-esm/chunk-JJZYWSD7.mjs +0 -54
  205. package/dist/lib/node-esm/chunk-JJZYWSD7.mjs.map +0 -7
  206. package/dist/lib/node-esm/chunk-XPIKUBGS.mjs.map +0 -7
  207. package/dist/lib/node-esm/chunk-XUWS7OTK.mjs.map +0 -7
  208. package/dist/lib/node-esm/compiler-PEARFTFR.mjs.map +0 -7
  209. package/dist/lib/node-esm/intent-resolver-SZJXQ3CW.mjs +0 -43
  210. package/dist/lib/node-esm/intent-resolver-SZJXQ3CW.mjs.map +0 -7
  211. package/dist/lib/node-esm/react-surface-J7NLV2V4.mjs.map +0 -7
  212. package/dist/types/src/bundler/bundler.d.ts +0 -39
  213. package/dist/types/src/bundler/bundler.d.ts.map +0 -1
  214. package/dist/types/src/bundler/bundler.test.d.ts +0 -2
  215. package/dist/types/src/bundler/bundler.test.d.ts.map +0 -1
  216. package/dist/types/src/bundler/index.d.ts +0 -2
  217. package/dist/types/src/bundler/index.d.ts.map +0 -1
  218. package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts +0 -17
  219. package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts.map +0 -1
  220. package/dist/types/src/components/AutomationPanel/index.d.ts +0 -4
  221. package/dist/types/src/components/AutomationPanel/index.d.ts.map +0 -1
  222. package/dist/types/src/components/ScriptToolbar/deploy.d.ts.map +0 -1
  223. package/dist/types/src/components/ScriptToolbar/format.d.ts.map +0 -1
  224. package/dist/types/src/components/ScriptToolbar/templateSelect.d.ts.map +0 -1
  225. package/dist/types/src/components/ScriptToolbar/useToolbarAction.d.ts.map +0 -1
  226. package/dist/types/src/components/ScriptToolbar/useToolbarState.d.ts.map +0 -1
  227. package/dist/types/src/components/ScriptToolbar/view.d.ts.map +0 -1
  228. package/src/bundler/bundler.test.ts +0 -55
  229. package/src/bundler/bundler.ts +0 -250
  230. package/src/bundler/index.ts +0 -5
  231. package/src/components/AutomationPanel/AutomationPanel.tsx +0 -104
  232. package/src/components/AutomationPanel/index.ts +0 -9
  233. /package/dist/lib/browser/{chunk-ZM6T4HPR.mjs.map → chunk-6MOQ4BP3.mjs.map} +0 -0
  234. /package/dist/lib/browser/{chunk-XPGBHZ3L.mjs.map → chunk-N46LE7FS.mjs.map} +0 -0
  235. /package/dist/lib/browser/{settings-YQQEU3DF.mjs.map → settings-SZCDKHWO.mjs.map} +0 -0
  236. /package/dist/lib/node/{chunk-A2DI2G4D.cjs.map → chunk-ALY3N6PW.cjs.map} +0 -0
  237. /package/dist/lib/node/{chunk-6VKZJ4MH.cjs.map → chunk-DJGLGRQV.cjs.map} +0 -0
  238. /package/dist/lib/node/{settings-NGHDYAVK.cjs.map → settings-SZFSMSKM.cjs.map} +0 -0
  239. /package/dist/lib/node-esm/{chunk-675XSDRN.mjs.map → chunk-CP5LXTK5.mjs.map} +0 -0
  240. /package/dist/lib/node-esm/{chunk-JHGOPQVO.mjs.map → chunk-UNQFIERE.mjs.map} +0 -0
  241. /package/dist/lib/node-esm/{settings-XGXDY4NI.mjs.map → settings-GR4O2WHZ.mjs.map} +0 -0
  242. /package/dist/types/src/{components/ScriptToolbar → hooks}/deploy.d.ts +0 -0
  243. /package/dist/types/src/{components/ScriptToolbar → hooks}/format.d.ts +0 -0
  244. /package/dist/types/src/{components/ScriptToolbar → hooks}/useToolbarState.d.ts +0 -0
  245. /package/src/{components/ScriptToolbar → hooks}/useToolbarState.ts +0 -0
@@ -0,0 +1,224 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { Capabilities, contributes, createIntent, type PromiseIntentDispatcher } from '@dxos/app-framework';
6
+ import { defineArtifact, defineTool, ToolResult } from '@dxos/artifact';
7
+ import { createArtifactElement } from '@dxos/assistant';
8
+ import { ObjectId, S } from '@dxos/echo-schema';
9
+ import { ScriptType } from '@dxos/functions';
10
+ import { invariant } from '@dxos/invariant';
11
+ import { SpaceAction } from '@dxos/plugin-space/types';
12
+ import { create, makeRef, type Space } from '@dxos/react-client/echo';
13
+ import { TextType } from '@dxos/schema';
14
+
15
+ import { meta } from '../meta';
16
+ // TODO(burdon): Factor out.
17
+ declare global {
18
+ interface ToolContextExtensions {
19
+ space?: Space;
20
+ dispatch?: PromiseIntentDispatcher;
21
+ }
22
+ }
23
+
24
+ export default () => {
25
+ const definition = defineArtifact({
26
+ id: meta.id,
27
+ name: meta.name,
28
+ // TODO(dmaretskyi): Since writing scripts requires a lot of domain knowledge,
29
+ // we should offload the work of synthesizing the code to a separate model.
30
+ // The main reasoning model will give it a concrete task and the script model will synthesize the code, knowing all the docs.
31
+ instructions: `
32
+ If the user explicitly requests you to write a script, you can create one.
33
+ If the user requests you to change one of the existing script, you can update it.
34
+ Scripts are short code pieces of executable code that can be used to perform computations, integrate with external systems, and perform automated tasks.
35
+ Each script must follow as strict shape for the definition but the body can contain any valid executable code.
36
+ Scripts are written in JavaScript or TypeScript.
37
+ Each script must define an input schema and output schema.
38
+ Each script must have its own detailed description.
39
+
40
+ Important: You cannot execute scripts. Scripts are only available as tools after the user deploys them. You must only call the available tools.
41
+
42
+ Description:
43
+ The description is a detailed description of the script.
44
+ It is used to describe the script's purpose, input, and output.
45
+ The description is used to generate the script's documentation.
46
+ The description is also goes into the script metadata.
47
+ The description is used by AI to understand the script and its purpose.
48
+ The description must provide cases on when the script should be used.
49
+
50
+ Schema:
51
+ The schema is defined using a schema-DSL library called Effect Schema.
52
+ The input schema describes the arguments that the script accepts.
53
+ The output schema describes the result that the script produces.
54
+ The schema is used to validate the script's input and output.
55
+ The schema is also goes into the script metadata.
56
+ The properties in the schema must have valid descriptions.
57
+ The input and output schemas must both be a struct of fields.
58
+
59
+ Restricts:
60
+ The scripts can only import code from "dxos:functions" module. No other modules are allowed.
61
+ Some web APIs are available - like fetch.
62
+
63
+ Reasoning:
64
+ Before writing a script, synthesize the following information:
65
+ - Description
66
+ - What APIs will be used.
67
+ - Detailed input schema
68
+ - Detailed output schema
69
+
70
+ <apis>
71
+ export function defineFunction(params: {
72
+ description: string,
73
+ inputSchema: S.Schema,
74
+ outputSchema: S.Schema,
75
+ handler: (params: { event: { data: TInput } }) => Promise<TOutput>
76
+ }): FunctionDefinition
77
+ /**
78
+ * Effect Schema
79
+ */
80
+ export const S;
81
+
82
+ // Examples:
83
+
84
+ S.String
85
+ S.Number
86
+ S.Boolean
87
+ S.Struct({
88
+ from: S.String.annotations({ description: 'The source currency' }),
89
+ to: S.String.annotations({ description: 'The target currency' }),
90
+ })
91
+ S.Array(S.String)
92
+ S.Union(S.String, S.Number)
93
+ S.optional(S.String)
94
+ S.String.annotations({ description: 'The source currency' })
95
+ </apis>
96
+
97
+ <handler_function>
98
+ Async function that takes the argument in the form of:
99
+
100
+ type HandlerFunctionParam = {
101
+ event: {
102
+ data: T // The input schema
103
+ },
104
+ }
105
+
106
+ The function must return the result that matches the output schema.
107
+ </handler_function>
108
+
109
+ <example>
110
+ import { defineFunction, S } from 'dxos:functions';
111
+
112
+ export default defineFunction({
113
+ description: 'Returns the exchange rate between two currencies.',
114
+
115
+ inputSchema: S.Struct({
116
+ from: S.String.annotations({ description: 'The source currency' }),
117
+ to: S.String.annotations({ description: 'The target currency' }),
118
+ }),
119
+
120
+ outputSchema: S.Struct({
121
+ rate: S.String.annotations({ description: 'The exchange rate' }),
122
+ }),
123
+
124
+ handler: async ({
125
+ event: {
126
+ data: { from, to },
127
+ },
128
+ }: any) => {
129
+ const res = await fetch(\`https://free.ratesdb.com/v1/rates?from=\${from}&to=\${to}\`);
130
+ const {
131
+ data: { rates },
132
+ } = await res.json();
133
+
134
+ return { rate: rates[to].toString() };
135
+ },
136
+ });
137
+ </example>
138
+ `,
139
+ schema: ScriptType,
140
+ tools: [
141
+ defineTool(meta.id, {
142
+ name: 'create',
143
+ description: 'Create a new script. Returns the artifact definition for the script',
144
+ caption: 'Creating script...',
145
+ schema: S.Struct({
146
+ name: S.String.annotations({ description: 'The name of the script' }),
147
+ code: S.String.annotations({
148
+ description: 'The full code of the script in JavaScript or TypeScript. Must be valid executable code.',
149
+ }),
150
+ }),
151
+ execute: async ({ name, code }, { extensions }) => {
152
+ invariant(extensions?.space, 'No space');
153
+ invariant(extensions?.dispatch, 'No intent dispatcher');
154
+ const script = create(ScriptType, {
155
+ name,
156
+ source: makeRef(
157
+ create(TextType, {
158
+ content: code,
159
+ }),
160
+ ),
161
+ });
162
+ extensions.space.db.add(script);
163
+ await extensions.space.db.flush();
164
+
165
+ const intent = createIntent(SpaceAction.AddObject, { target: extensions.space, object: script });
166
+ const { data, error } = await extensions.dispatch(intent);
167
+ if (!data || error) {
168
+ return ToolResult.Error(error?.message ?? 'Failed to create chess game');
169
+ }
170
+
171
+ return ToolResult.Success(createArtifactElement(script.id));
172
+ },
173
+ }),
174
+ defineTool(meta.id, {
175
+ name: 'inspect',
176
+ description: 'Inspect a script. Returns the artifact definition for the script',
177
+ caption: 'Inspecting script...',
178
+ schema: S.Struct({
179
+ id: ObjectId,
180
+ }),
181
+ execute: async ({ id }, { extensions }) => {
182
+ invariant(extensions?.space, 'No space');
183
+
184
+ const script = (await extensions.space.db.query({ id }).first()) as ScriptType;
185
+ const { content } = await script.source.load();
186
+
187
+ return ToolResult.Success({
188
+ name: script.name,
189
+ code: content,
190
+ });
191
+ },
192
+ }),
193
+ defineTool(meta.id, {
194
+ name: 'update',
195
+ description: 'Update a script. Returns the artifact definition for the script',
196
+ caption: 'Updating script...',
197
+ schema: S.Struct({
198
+ id: ObjectId,
199
+ code: S.String.annotations({
200
+ description: 'The full code of the script in JavaScript or TypeScript. Must be valid executable code.',
201
+ }),
202
+ }),
203
+ execute: async ({ id, code }, { extensions }) => {
204
+ invariant(extensions?.space, 'No space');
205
+
206
+ const script = (await extensions.space.db.query({ id }).first()) as ScriptType;
207
+ const source = await script.source.load();
208
+ if (!source) {
209
+ return ToolResult.Error('Script not found');
210
+ }
211
+
212
+ source.content = code;
213
+ await extensions.space?.db.flush();
214
+
215
+ return ToolResult.Success({
216
+ name: script.name,
217
+ });
218
+ },
219
+ }),
220
+ ],
221
+ });
222
+
223
+ return contributes(Capabilities.ArtifactDefinition, definition);
224
+ };
@@ -6,9 +6,9 @@
6
6
  import wasmUrl from 'esbuild-wasm/esbuild.wasm?url';
7
7
 
8
8
  import { contributes } from '@dxos/app-framework';
9
+ import { initializeBundler } from '@dxos/functions/bundler';
9
10
 
10
11
  import { ScriptCapabilities } from './capabilities';
11
- import { initializeBundler } from '../bundler';
12
12
  import { Compiler } from '../compiler';
13
13
 
14
14
  export default async () => {
@@ -8,5 +8,6 @@ export const Compiler = lazy(() => import('./compiler'));
8
8
  export const IntentResolver = lazy(() => import('./intent-resolver'));
9
9
  export const ReactSurface = lazy(() => import('./react-surface'));
10
10
  export const ScriptSettings = lazy(() => import('./settings'));
11
+ export const ArtifactDefinition = lazy(() => import('./artifact-definition'));
11
12
 
12
13
  export * from './capabilities';
@@ -15,29 +15,32 @@ import { ScriptAction } from '../types';
15
15
  export default () =>
16
16
  contributes(
17
17
  Capabilities.IntentResolver,
18
- createResolver(ScriptAction.Create, async ({ name, gistUrl, space }) => {
19
- let content = templates[0].source;
20
- const gistId = gistUrl?.split('/').at(-1);
21
- if (gistId) {
22
- // TODO(wittjosiah): Capability which contributes Octokit?
23
- // NOTE: AccessToken not needed to read public gists.
24
- const octokit = new Octokit();
25
- const response = await octokit.request('GET /gists/{gist_id}', {
26
- gist_id: gistId,
27
- });
28
- const gistContent = Object.values(response.data.files ?? {})[0]?.content;
29
- if (gistContent) {
30
- content = gistContent;
18
+ createResolver({
19
+ intent: ScriptAction.Create,
20
+ resolve: async ({ name, gistUrl }) => {
21
+ let content = templates[0].source;
22
+ const gistId = gistUrl?.split('/').at(-1);
23
+ if (gistId) {
24
+ // TODO(wittjosiah): Capability which contributes Octokit?
25
+ // NOTE: AccessToken not needed to read public gists.
26
+ const octokit = new Octokit();
27
+ const response = await octokit.request('GET /gists/{gist_id}', {
28
+ gist_id: gistId,
29
+ });
30
+ const gistContent = Object.values(response.data.files ?? {})[0]?.content;
31
+ if (gistContent) {
32
+ content = gistContent;
33
+ }
31
34
  }
32
- }
33
35
 
34
- return {
35
- data: {
36
- object: create(ScriptType, {
37
- name,
38
- source: makeRef(create(TextType, { content })),
39
- }),
40
- },
41
- };
36
+ return {
37
+ data: {
38
+ object: create(ScriptType, {
39
+ name,
40
+ source: makeRef(create(TextType, { content })),
41
+ }),
42
+ },
43
+ };
44
+ },
42
45
  }),
43
46
  );
@@ -6,10 +6,12 @@ import React from 'react';
6
6
 
7
7
  import { Capabilities, contributes, createSurface, useCapability } from '@dxos/app-framework';
8
8
  import { ScriptType } from '@dxos/functions';
9
+ import { SettingsStore } from '@dxos/local-storage';
9
10
  import { Clipboard } from '@dxos/react-ui';
10
11
 
11
12
  import { ScriptCapabilities } from './capabilities';
12
- import { AutomationPanel, ScriptSettings, ScriptContainer, ScriptSettingsPanel } from '../components';
13
+ import { DebugPanel, ScriptSettings, ScriptContainer, ScriptSettingsPanel } from '../components';
14
+ import { useDeployState, useToolbarState } from '../hooks';
13
15
  import { SCRIPT_PLUGIN } from '../meta';
14
16
  import { type ScriptSettingsProps } from '../types';
15
17
 
@@ -17,12 +19,10 @@ export default () =>
17
19
  contributes(Capabilities.ReactSurface, [
18
20
  createSurface({
19
21
  id: `${SCRIPT_PLUGIN}/settings`,
20
- role: 'settings',
21
- filter: (data): data is any => data.subject === SCRIPT_PLUGIN,
22
- component: () => {
23
- const settings = useCapability(Capabilities.SettingsStore).getStore<ScriptSettingsProps>(SCRIPT_PLUGIN)!.value;
24
- return <ScriptSettings settings={settings} />;
25
- },
22
+ role: 'article',
23
+ filter: (data): data is { subject: SettingsStore<ScriptSettingsProps> } =>
24
+ data.subject instanceof SettingsStore && data.subject.prefix === SCRIPT_PLUGIN,
25
+ component: ({ data: { subject } }) => <ScriptSettings settings={subject.value} />,
26
26
  }),
27
27
  createSurface({
28
28
  id: `${SCRIPT_PLUGIN}/article`,
@@ -30,16 +30,22 @@ export default () =>
30
30
  filter: (data): data is { subject: ScriptType } => data.subject instanceof ScriptType,
31
31
  component: ({ data, role }) => {
32
32
  const compiler = useCapability(ScriptCapabilities.Compiler);
33
- const settings = useCapability(Capabilities.SettingsStore).getStore<ScriptSettingsProps>(SCRIPT_PLUGIN)!.value;
33
+ // TODO(dmaretskyi): Since settings store is not reactive, this would break on the script plugin being enabled without a page reload.
34
+ const settings = useCapability(Capabilities.SettingsStore).getStore<ScriptSettingsProps>(SCRIPT_PLUGIN)?.value;
34
35
  return <ScriptContainer role={role} script={data.subject} settings={settings} env={compiler.environment} />;
35
36
  },
36
37
  }),
37
38
  createSurface({
38
39
  id: `${SCRIPT_PLUGIN}/automation`,
39
- role: 'complementary--automation',
40
- disposition: 'hoist',
40
+ role: 'complementary--function',
41
+ position: 'hoist',
41
42
  filter: (data): data is { subject: ScriptType } => data.subject instanceof ScriptType,
42
- component: ({ data }) => <AutomationPanel subject={data.subject} />,
43
+ component: ({ data }) => {
44
+ // TODO(wittjosiah): Decouple hooks from toolbar state.
45
+ const state = useToolbarState({ view: 'editor' });
46
+ useDeployState({ state, script: data.subject });
47
+ return <DebugPanel functionUrl={state.functionUrl} />;
48
+ },
43
49
  }),
44
50
  createSurface({
45
51
  id: `${SCRIPT_PLUGIN}/settings-panel`,
@@ -7,7 +7,7 @@ import React, { forwardRef, useEffect, useRef, useState } from 'react';
7
7
  import { log } from '@dxos/log';
8
8
  import { Avatar, Icon, Input, type ThemedClassName, Toolbar, useTranslation } from '@dxos/react-ui';
9
9
  import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
10
- import { mx } from '@dxos/react-ui-theme';
10
+ import { errorText, mx } from '@dxos/react-ui-theme';
11
11
 
12
12
  import { SCRIPT_PLUGIN } from '../../meta';
13
13
 
@@ -232,7 +232,7 @@ const MessageItem = ({ classNames, message }: ThemedClassName<{ message: Message
232
232
  const wrapper = 'p-1 px-2 rounded-lg bg-hoverSurface overflow-auto';
233
233
  return (
234
234
  <div className={mx('flex', type === 'request' ? 'ml-[1rem] justify-end' : 'mr-[1rem]', classNames)}>
235
- {error && <div className={mx(wrapper, 'whitespace-pre text-error')}>{String(error)}</div>}
235
+ {error && <div className={mx(wrapper, 'whitespace-pre', errorText)}>{String(error)}</div>}
236
236
 
237
237
  {text !== undefined && (
238
238
  <div className={mx(wrapper, type === 'request' && 'bg-primary-400 dark:bg-primary-600')}>
@@ -5,17 +5,17 @@
5
5
  import React, { useEffect, useRef } from 'react';
6
6
 
7
7
  import { clientServiceBundle } from '@dxos/client-protocol';
8
+ import { type BundleResult } from '@dxos/functions/bundler';
9
+ import { invariant } from '@dxos/invariant';
8
10
  import { log } from '@dxos/log';
9
11
  import { useClient } from '@dxos/react-client';
10
12
  import { baseSurface, mx } from '@dxos/react-ui-theme';
11
13
  import { createProtoRpcPeer } from '@dxos/rpc';
12
14
  import { createIFramePort } from '@dxos/rpc-tunnel';
13
15
 
14
- import { type BundlerResult } from '../../bundler';
15
-
16
16
  export type FrameContainerProps = {
17
17
  containerUrl: string;
18
- result: BundlerResult;
18
+ result: BundleResult;
19
19
  debug?: boolean;
20
20
  };
21
21
 
@@ -46,6 +46,7 @@ export const FrameContainer = ({ containerUrl, result, debug = true }: FrameCont
46
46
  }, [iframeRef]);
47
47
 
48
48
  // Encodes compiled code via URL.
49
+ invariant(result.sourceHash, 'Source hash is required.');
49
50
  const sourceHash = Buffer.from(result.sourceHash).toString('hex');
50
51
  const src = result.bundle && `${containerUrl}?ts=${sourceHash}#code=${encodeURIComponent(result.bundle)}`;
51
52
 
@@ -58,7 +59,7 @@ export const FrameContainer = ({ containerUrl, result, debug = true }: FrameCont
58
59
  <div
59
60
  className={mx(
60
61
  baseSurface,
61
- 'flex absolute right-2 bottom-2 w-[400px] h-[200px] ring rounded',
62
+ 'flex absolute right-2 bottom-2 w-[30rem] h-[200px] ring rounded',
62
63
  'z-20 overflow-x-hidden overflow-y-auto',
63
64
  )}
64
65
  >
@@ -14,19 +14,24 @@ import { mx } from '@dxos/react-ui-theme';
14
14
 
15
15
  import { DebugPanel } from './DebugPanel';
16
16
  import { ScriptToolbar } from './ScriptToolbar';
17
- import { useDeployState } from './ScriptToolbar/deploy';
18
- import { useToolbarState } from './ScriptToolbar/useToolbarState';
19
17
  import { TypescriptEditor, type TypescriptEditorProps } from './TypescriptEditor';
18
+ import { useDeployState, useToolbarState } from '../hooks';
20
19
  import { type ScriptSettingsProps } from '../types';
21
20
 
22
21
  export type ScriptEditorProps = ThemedClassName<{
23
22
  script: ScriptType;
24
- settings: ScriptSettingsProps;
23
+ settings?: ScriptSettingsProps;
25
24
  role?: string;
26
25
  }> &
27
26
  Pick<TypescriptEditorProps, 'env'>;
28
27
 
29
- export const ScriptContainer = ({ role, classNames, script, settings, env }: ScriptEditorProps) => {
28
+ export const ScriptContainer = ({
29
+ role,
30
+ classNames,
31
+ script,
32
+ settings = { editorInputMode: 'vscode' },
33
+ env,
34
+ }: ScriptEditorProps) => {
30
35
  const identity = useIdentity();
31
36
  const space = getSpace(script);
32
37
 
@@ -49,7 +54,7 @@ export const ScriptContainer = ({ role, classNames, script, settings, env }: Scr
49
54
  [script, script.source.target, space, identity],
50
55
  );
51
56
 
52
- const state = useToolbarState({ view: 'split' });
57
+ const state = useToolbarState({ view: 'editor' });
53
58
  useDeployState({ state, script });
54
59
 
55
60
  return (
@@ -8,7 +8,7 @@ import { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
8
8
  import { useClient } from '@dxos/react-client';
9
9
  import { Button, Select, useTranslation } from '@dxos/react-ui';
10
10
  import { type EditorInputMode, EditorInputModes } from '@dxos/react-ui-editor';
11
- import { DeprecatedFormInput } from '@dxos/react-ui-form';
11
+ import { DeprecatedFormContainer, DeprecatedFormInput } from '@dxos/react-ui-form';
12
12
 
13
13
  import { SCRIPT_PLUGIN } from '../../meta';
14
14
  import { type ScriptSettingsProps } from '../../types';
@@ -39,7 +39,7 @@ export const ScriptSettings = ({ settings }: { settings: ScriptSettingsProps })
39
39
  };
40
40
 
41
41
  return (
42
- <>
42
+ <DeprecatedFormContainer>
43
43
  {/* TODO(wittjosiah): Hide outside of dev environments. */}
44
44
  <DeprecatedFormInput label={t('authenticate action label')}>
45
45
  <Button onClick={handleAuthenticate}>{t('authenticate button label')}</Button>
@@ -66,6 +66,6 @@ export const ScriptSettings = ({ settings }: { settings: ScriptSettingsProps })
66
66
  </Select.Portal>
67
67
  </Select.Root>
68
68
  </DeprecatedFormInput>
69
- </>
69
+ </DeprecatedFormContainer>
70
70
  );
71
71
  };
@@ -10,7 +10,7 @@ import { FunctionType, type ScriptType, getInvocationUrl, getUserFunctionUrlInMe
10
10
  import { log } from '@dxos/log';
11
11
  import { useClient } from '@dxos/react-client';
12
12
  import { Filter, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';
13
- import { Button, Clipboard, Input, Separator, useControlledValue, useTranslation } from '@dxos/react-ui';
13
+ import { Button, Clipboard, Input, Separator, useControlledState, useTranslation } from '@dxos/react-ui';
14
14
  import { AccessTokenType } from '@dxos/schema';
15
15
 
16
16
  import { SCRIPT_PLUGIN } from '../meta';
@@ -57,7 +57,7 @@ export const ScriptSettingsPanel = ({ script }: ScriptSettingsPanelProps) => {
57
57
  return () => clearTimeout(timeout);
58
58
  }, [githubToken, gistKey]);
59
59
 
60
- const [binding, setBinding] = useControlledValue(fn?.binding ?? '');
60
+ const [binding, setBinding] = useControlledState(fn?.binding ?? '');
61
61
  const handleBindingChange = useCallback(
62
62
  (event: ChangeEvent<HTMLInputElement>) => {
63
63
  setBinding(event.target.value);
@@ -114,6 +114,20 @@ export const ScriptSettingsPanel = ({ script }: ScriptSettingsPanelProps) => {
114
114
 
115
115
  return (
116
116
  <>
117
+ <div role='form' className='flex flex-col w-full p-2 gap-4'>
118
+ <Input.Root>
119
+ <div role='none' className='flex flex-col gap-1'>
120
+ <Input.Label>{t('description label')}</Input.Label>
121
+ <Input.TextInput
122
+ placeholder={t('description placeholder')}
123
+ value={script.description ?? ''}
124
+ onChange={(event) => {
125
+ script.description = event.target.value;
126
+ }}
127
+ />
128
+ </div>
129
+ </Input.Root>
130
+ </div>
117
131
  {fn && functionUrl && (
118
132
  <>
119
133
  <Separator />
@@ -10,12 +10,14 @@ import { ElevationProvider, type ThemedClassName } from '@dxos/react-ui';
10
10
  import { stackItemContentToolbarClassNames } from '@dxos/react-ui-editor';
11
11
  import { createGapSeparator, MenuProvider, ToolbarMenu, useMenuActions } from '@dxos/react-ui-menu';
12
12
 
13
- import { createDeploy } from './deploy';
14
- import { createFormat } from './format';
15
- import { createTemplateSelect } from './templateSelect';
16
- import { useToolbarAction } from './useToolbarAction';
17
- import { type ScriptToolbarState } from './useToolbarState';
18
- import { createView } from './view';
13
+ import {
14
+ type ScriptToolbarState,
15
+ createDeploy,
16
+ createFormat,
17
+ createTemplateSelect,
18
+ createView,
19
+ useToolbarAction,
20
+ } from '../../hooks';
19
21
 
20
22
  export type ScriptToolbarProps = ThemedClassName<{
21
23
  role?: string;
@@ -27,7 +27,7 @@ import {
27
27
  useTextEditor,
28
28
  type UseTextEditorProps,
29
29
  } from '@dxos/react-ui-editor';
30
- import { nonNullable } from '@dxos/util';
30
+ import { isNonNullable } from '@dxos/util';
31
31
 
32
32
  export type TypescriptEditorProps = {
33
33
  id: string;
@@ -94,7 +94,7 @@ export const TypescriptEditor = ({
94
94
  ]
95
95
  : [],
96
96
  ],
97
- ].filter(nonNullable),
97
+ ].filter(isNonNullable),
98
98
  selection,
99
99
  scrollTo,
100
100
  }),
@@ -127,7 +127,7 @@ const createTooltipRenderer = (themeMode: ThemeMode) => {
127
127
 
128
128
  return (info: HoverInfo) => {
129
129
  const div = document.createElement('div');
130
- div.className = 'p-1 rounded border border-separator bg-base xs:max-w-80 max-w-lg';
130
+ div.className = 'p-1 rounded border border-separator bg-baseSurface xs:max-w-80 max-w-lg';
131
131
 
132
132
  if (info.quickInfo?.displayParts) {
133
133
  for (const part of info.quickInfo.displayParts) {
@@ -4,8 +4,8 @@
4
4
 
5
5
  import { lazy } from 'react';
6
6
 
7
+ export * from './DebugPanel';
7
8
  export * from './ScriptSettings';
8
9
  export * from './ScriptSettingsPanel';
9
10
 
10
- export const AutomationPanel = lazy(() => import('./AutomationPanel'));
11
11
  export const ScriptContainer = lazy(() => import('./ScriptContainer'));
package/src/events.ts ADDED
@@ -0,0 +1,11 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { defineEvent } from '@dxos/app-framework';
6
+
7
+ import { SCRIPT_PLUGIN } from './meta';
8
+
9
+ export namespace ScriptEvents {
10
+ export const SetupCompiler = defineEvent(`${SCRIPT_PLUGIN}/event/setup-compiler`);
11
+ }
@@ -6,13 +6,14 @@ import { useCallback, useEffect, useMemo } from 'react';
6
6
 
7
7
  import {
8
8
  FunctionType,
9
+ type ScriptType,
9
10
  getInvocationUrl,
10
11
  getUserFunctionUrlInMetadata,
11
12
  incrementSemverPatch,
12
- type ScriptType,
13
13
  setUserFunctionUrlInMetadata,
14
14
  uploadWorkerFunction,
15
15
  } from '@dxos/functions';
16
+ import { Bundler } from '@dxos/functions/bundler';
16
17
  import { log } from '@dxos/log';
17
18
  import { useClient } from '@dxos/react-client';
18
19
  import { Filter, create, getMeta, getSpace, makeRef, useQuery } from '@dxos/react-client/echo';
@@ -20,8 +21,7 @@ import { useTranslation } from '@dxos/react-ui';
20
21
  import { createMenuAction } from '@dxos/react-ui-menu';
21
22
 
22
23
  import { type ViewState } from './view';
23
- import { Bundler } from '../../bundler';
24
- import { SCRIPT_PLUGIN } from '../../meta';
24
+ import { SCRIPT_PLUGIN } from '../meta';
25
25
 
26
26
  export type DeployActionProperties = { type: 'deploy' } | { type: 'copy' };
27
27
 
@@ -105,7 +105,7 @@ export const useDeployHandler = ({ state, script }: { state: Partial<DeployState
105
105
  const existingFunctionId = existingFunctionUrl?.split('/').at(-1);
106
106
 
107
107
  const bundler = new Bundler({ platform: 'browser', sandboxedModules: [], remoteModules: {} });
108
- const buildResult = await bundler.bundle(script.source.target!.content);
108
+ const buildResult = await bundler.bundle({ source: script.source.target!.content });
109
109
  if (buildResult.error || !buildResult.bundle) {
110
110
  throw buildResult.error;
111
111
  }
@@ -130,12 +130,24 @@ export const useDeployHandler = ({ state, script }: { state: Partial<DeployState
130
130
  fn ?? space.db.add(create(FunctionType, { name: functionId, version, source: makeRef(script) }));
131
131
 
132
132
  script.changed = false;
133
+ if (script.description !== undefined && script.description.trim() !== '') {
134
+ deployedFunction.description = script.description;
135
+ } else if (meta.description) {
136
+ deployedFunction.description = meta.description;
137
+ } else {
138
+ log.verbose('no description in function metadata', { functionId });
139
+ }
133
140
 
134
141
  if (meta.inputSchema) {
135
142
  deployedFunction.inputSchema = meta.inputSchema;
136
143
  } else {
137
144
  log.verbose('no input schema in function metadata', { functionId });
138
145
  }
146
+ if (meta.outputSchema) {
147
+ deployedFunction.outputSchema = meta.outputSchema;
148
+ } else {
149
+ log.verbose('no output schema in function metadata', { functionId });
150
+ }
139
151
 
140
152
  setUserFunctionUrlInMetadata(getMeta(deployedFunction), `/${space.id}/${functionId}`);
141
153
 
@@ -11,7 +11,7 @@ import { type ScriptType } from '@dxos/functions';
11
11
  import { log } from '@dxos/log';
12
12
  import { createMenuAction } from '@dxos/react-ui-menu';
13
13
 
14
- import { SCRIPT_PLUGIN } from '../../meta';
14
+ import { SCRIPT_PLUGIN } from '../meta';
15
15
 
16
16
  export type FormatActionProperties = { type: 'format' };
17
17