@dxos/plugin-script 0.8.4-main.5ea62a8 → 0.8.4-main.66e292d
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.
- package/dist/lib/browser/DeploymentDialog-5TKNGPVR.mjs +14 -0
- package/dist/lib/browser/NotebookContainer-MHY3DXDE.mjs +817 -0
- package/dist/lib/browser/NotebookContainer-MHY3DXDE.mjs.map +7 -0
- package/dist/lib/browser/ScriptContainer-CW6YN3DQ.mjs +148 -0
- package/dist/lib/browser/ScriptContainer-CW6YN3DQ.mjs.map +7 -0
- package/dist/lib/browser/{app-graph-builder-IABOSTBK.mjs → app-graph-builder-2WR2ATTJ.mjs} +11 -9
- package/dist/lib/browser/app-graph-builder-2WR2ATTJ.mjs.map +7 -0
- package/dist/lib/browser/{blueprint-definition-AR7ITBCD.mjs → blueprint-definition-6PZWZM2Y.mjs} +5 -3
- package/dist/lib/{node-esm/blueprint-definition-TJY4TX6S.mjs.map → browser/blueprint-definition-6PZWZM2Y.mjs.map} +1 -1
- package/dist/lib/browser/chunk-2G2NA6DQ.mjs +88 -0
- package/dist/lib/browser/chunk-2G2NA6DQ.mjs.map +7 -0
- package/dist/lib/browser/chunk-ALS6X4HU.mjs +304 -0
- package/dist/lib/browser/chunk-ALS6X4HU.mjs.map +7 -0
- package/dist/lib/browser/{chunk-QYAREHGH.mjs → chunk-EB6AXFXO.mjs} +8 -5
- package/dist/lib/browser/chunk-EB6AXFXO.mjs.map +7 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/browser/chunk-M6KJPUJK.mjs +111 -0
- package/dist/lib/browser/chunk-M6KJPUJK.mjs.map +7 -0
- package/dist/lib/browser/{chunk-TH7GXPE3.mjs → chunk-N5EYLQOT.mjs} +150 -59
- package/dist/lib/browser/chunk-N5EYLQOT.mjs.map +7 -0
- package/dist/lib/browser/chunk-QIZ3BPRK.mjs +103 -0
- package/dist/lib/browser/chunk-QIZ3BPRK.mjs.map +7 -0
- package/dist/lib/browser/{chunk-YCZPTTFO.mjs → chunk-SAN5Y7FI.mjs} +23 -21
- package/dist/lib/browser/chunk-SAN5Y7FI.mjs.map +7 -0
- package/dist/lib/browser/chunk-ULJFT73Q.mjs +513 -0
- package/dist/lib/browser/chunk-ULJFT73Q.mjs.map +7 -0
- package/dist/lib/browser/{chunk-5TVBECWH.mjs → chunk-UOQ6NCH3.mjs} +2 -2
- package/dist/lib/browser/{compiler-2HJH34GM.mjs → compiler-4KHRSX7J.mjs} +13 -25
- package/dist/lib/browser/compiler-4KHRSX7J.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +108 -50
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/{intent-resolver-YMK5SXVC.mjs → intent-resolver-TXTBWOVD.mjs} +38 -23
- package/dist/lib/browser/intent-resolver-TXTBWOVD.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-FEM5WWFH.mjs → react-surface-R245YN52.mjs} +45 -21
- package/dist/lib/browser/react-surface-R245YN52.mjs.map +7 -0
- package/dist/lib/browser/{settings-KCTBK5TY.mjs → settings-MHJXRGDF.mjs} +10 -8
- package/dist/lib/browser/settings-MHJXRGDF.mjs.map +7 -0
- package/dist/lib/browser/templates/index.mjs +2 -1
- package/dist/lib/browser/types/index.mjs +8 -4
- package/dist/lib/node-esm/DeploymentDialog-2ULNOZQH.mjs +15 -0
- package/dist/lib/node-esm/DeploymentDialog-2ULNOZQH.mjs.map +7 -0
- package/dist/lib/node-esm/NotebookContainer-U4C2HQ4T.mjs +818 -0
- package/dist/lib/node-esm/NotebookContainer-U4C2HQ4T.mjs.map +7 -0
- package/dist/lib/node-esm/ScriptContainer-VRPEKB4T.mjs +149 -0
- package/dist/lib/node-esm/ScriptContainer-VRPEKB4T.mjs.map +7 -0
- package/dist/lib/node-esm/{app-graph-builder-CQTTAYHP.mjs → app-graph-builder-NCVLUL5R.mjs} +11 -9
- package/dist/lib/node-esm/app-graph-builder-NCVLUL5R.mjs.map +7 -0
- package/dist/lib/node-esm/{blueprint-definition-TJY4TX6S.mjs → blueprint-definition-5R6YCSZZ.mjs} +4 -3
- package/dist/lib/{browser/blueprint-definition-AR7ITBCD.mjs.map → node-esm/blueprint-definition-5R6YCSZZ.mjs.map} +1 -1
- package/dist/lib/node-esm/{chunk-35M3CHYE.mjs → chunk-55JZVM6K.mjs} +2 -2
- package/dist/lib/node-esm/chunk-57JA6XL5.mjs +90 -0
- package/dist/lib/node-esm/chunk-57JA6XL5.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HDKR5WCD.mjs +113 -0
- package/dist/lib/node-esm/chunk-HDKR5WCD.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-AHXJ6NQU.mjs → chunk-IBV2DR36.mjs} +8 -5
- package/dist/lib/node-esm/chunk-IBV2DR36.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-ZA36GO4T.mjs → chunk-ND4BPYPR.mjs} +23 -21
- package/dist/lib/node-esm/chunk-ND4BPYPR.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-6M2R2FQF.mjs → chunk-UEVZP5DN.mjs} +150 -59
- package/dist/lib/node-esm/chunk-UEVZP5DN.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-VJSRZRLI.mjs +514 -0
- package/dist/lib/node-esm/chunk-VJSRZRLI.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-VTRMJSQL.mjs +305 -0
- package/dist/lib/node-esm/chunk-VTRMJSQL.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-XYKKDWUR.mjs +104 -0
- package/dist/lib/node-esm/chunk-XYKKDWUR.mjs.map +7 -0
- package/dist/lib/node-esm/{compiler-7SP27RA6.mjs → compiler-DU5NQISX.mjs} +13 -25
- package/dist/lib/node-esm/compiler-DU5NQISX.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +108 -50
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/{intent-resolver-SKRDYQCZ.mjs → intent-resolver-D6AVAQRA.mjs} +38 -23
- package/dist/lib/node-esm/intent-resolver-D6AVAQRA.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{react-surface-AOKMDJR4.mjs → react-surface-MHT3PJ6C.mjs} +45 -21
- package/dist/lib/node-esm/react-surface-MHT3PJ6C.mjs.map +7 -0
- package/dist/lib/node-esm/{settings-DXZ334A3.mjs → settings-BVJORMMJ.mjs} +10 -8
- package/dist/lib/node-esm/settings-BVJORMMJ.mjs.map +7 -0
- package/dist/lib/node-esm/templates/index.mjs +2 -1
- package/dist/lib/node-esm/types/index.mjs +8 -4
- package/dist/types/src/ScriptPlugin.d.ts +1 -1
- package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -1
- package/dist/types/src/capabilities/blueprint-definition.d.ts +1 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/components/DeploymentDialog/DeploymentDialog.d.ts +3 -3
- package/dist/types/src/components/DeploymentDialog/DeploymentDialog.d.ts.map +1 -1
- package/dist/types/src/components/DeploymentDialog/DeploymentDialog.stories.d.ts +113 -7
- package/dist/types/src/components/DeploymentDialog/DeploymentDialog.stories.d.ts.map +1 -1
- package/dist/types/src/components/FrameContainer/FrameContainer.d.ts +1 -1
- package/dist/types/src/components/FrameContainer/FrameContainer.d.ts.map +1 -1
- package/dist/types/src/components/NotebookContainer.d.ts +10 -0
- package/dist/types/src/components/NotebookContainer.d.ts.map +1 -0
- package/dist/types/src/components/NotebookContainer.stories.d.ts +254 -0
- package/dist/types/src/components/NotebookContainer.stories.d.ts.map +1 -0
- package/dist/types/src/components/NotebookStack/NotebookCell.d.ts +15 -0
- package/dist/types/src/components/NotebookStack/NotebookCell.d.ts.map +1 -0
- package/dist/types/src/components/NotebookStack/NotebookMenu.d.ts +9 -0
- package/dist/types/src/components/NotebookStack/NotebookMenu.d.ts.map +1 -0
- package/dist/types/src/components/NotebookStack/NotebookStack.d.ts +14 -0
- package/dist/types/src/components/NotebookStack/NotebookStack.d.ts.map +1 -0
- package/dist/types/src/components/NotebookStack/NotebookStack.stories.d.ts +248 -0
- package/dist/types/src/components/NotebookStack/NotebookStack.stories.d.ts.map +1 -0
- package/dist/types/src/components/NotebookStack/index.d.ts +3 -0
- package/dist/types/src/components/NotebookStack/index.d.ts.map +1 -0
- package/dist/types/src/components/ScriptContainer.d.ts +4 -4
- package/dist/types/src/components/ScriptContainer.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts +5 -6
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.stories.d.ts +240 -2
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.stories.d.ts.map +1 -1
- package/dist/types/src/components/Settings/ScriptObjectSettings.d.ts +2 -2
- package/dist/types/src/components/Settings/ScriptObjectSettings.d.ts.map +1 -1
- package/dist/types/src/components/Settings/ScriptPluginSettings.d.ts +2 -2
- package/dist/types/src/components/Settings/ScriptPluginSettings.d.ts.map +1 -1
- package/dist/types/src/components/TestPanel/TestContainer.d.ts +2 -2
- package/dist/types/src/components/TestPanel/TestContainer.d.ts.map +1 -1
- package/dist/types/src/components/TestPanel/TestPanel.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts +4 -2
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts +3 -3
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +2 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/events.d.ts.map +1 -1
- package/dist/types/src/hooks/deploy.d.ts +14 -12
- package/dist/types/src/hooks/deploy.d.ts.map +1 -1
- package/dist/types/src/hooks/format.d.ts +2 -2
- package/dist/types/src/hooks/format.d.ts.map +1 -1
- package/dist/types/src/hooks/template.d.ts +4 -14
- package/dist/types/src/hooks/template.d.ts.map +1 -1
- package/dist/types/src/hooks/useCreateAndDeployScriptTemplates.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +0 -1
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/notebook/compute-graph.d.ts +45 -0
- package/dist/types/src/notebook/compute-graph.d.ts.map +1 -0
- package/dist/types/src/notebook/compute-graph.test.d.ts +2 -0
- package/dist/types/src/notebook/compute-graph.test.d.ts.map +1 -0
- package/dist/types/src/notebook/eval.d.ts +13 -0
- package/dist/types/src/notebook/eval.d.ts.map +1 -0
- package/dist/types/src/notebook/index.d.ts +2 -0
- package/dist/types/src/notebook/index.d.ts.map +1 -0
- package/dist/types/src/notebook/vfs-parser.d.ts +74 -0
- package/dist/types/src/notebook/vfs-parser.d.ts.map +1 -0
- package/dist/types/src/notebook/vfs-parser.test.d.ts +2 -0
- package/dist/types/src/notebook/vfs-parser.test.d.ts.map +1 -0
- package/dist/types/src/templates/chess.d.ts.map +1 -1
- package/dist/types/src/templates/data-generator.d.ts.map +1 -1
- package/dist/types/src/templates/discord.d.ts.map +1 -1
- package/dist/types/src/templates/forex-effect.d.ts.map +1 -1
- package/dist/types/src/templates/forex.d.ts.map +1 -1
- package/dist/types/src/templates/gmail.d.ts.map +1 -1
- package/dist/types/src/templates/index.d.ts +43 -1
- package/dist/types/src/templates/index.d.ts.map +1 -1
- package/dist/types/src/templates/{echo.d.ts → ping.d.ts} +1 -1
- package/dist/types/src/templates/ping.d.ts.map +1 -0
- package/dist/types/src/testing/data.d.ts +3 -0
- package/dist/types/src/testing/data.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +2 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +31 -5
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Notebook.d.ts +31 -0
- package/dist/types/src/types/Notebook.d.ts.map +1 -0
- package/dist/types/src/types/actions.d.ts +54 -0
- package/dist/types/src/types/actions.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +3 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +6 -0
- package/dist/types/src/types/types.d.ts.map +1 -0
- package/dist/types/src/util/deploy.d.ts +4 -4
- package/dist/types/src/util/deploy.d.ts.map +1 -1
- package/dist/types/src/util/functions.d.ts +6 -3
- package/dist/types/src/util/functions.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +79 -69
- package/src/ScriptPlugin.tsx +79 -73
- package/src/capabilities/app-graph-builder.ts +10 -9
- package/src/capabilities/artifact-definition.ts +2 -3
- package/src/capabilities/compiler.ts +1 -1
- package/src/capabilities/intent-resolver.ts +20 -11
- package/src/capabilities/react-surface.tsx +30 -17
- package/src/capabilities/settings.ts +3 -3
- package/src/components/DeploymentDialog/DeploymentDialog.stories.tsx +13 -6
- package/src/components/DeploymentDialog/DeploymentDialog.tsx +41 -30
- package/src/components/FrameContainer/FrameContainer.tsx +2 -2
- package/src/components/NotebookContainer.stories.tsx +83 -0
- package/src/components/NotebookContainer.tsx +260 -0
- package/src/components/NotebookStack/NotebookCell.tsx +216 -0
- package/src/components/NotebookStack/NotebookMenu.tsx +47 -0
- package/src/components/NotebookStack/NotebookStack.stories.tsx +54 -0
- package/src/components/NotebookStack/NotebookStack.tsx +86 -0
- package/src/components/NotebookStack/index.ts +6 -0
- package/src/components/ScriptContainer.tsx +8 -7
- package/src/components/ScriptToolbar/ScriptToolbar.stories.tsx +22 -10
- package/src/components/ScriptToolbar/ScriptToolbar.tsx +30 -33
- package/src/components/Settings/ScriptObjectSettings.tsx +115 -19
- package/src/components/Settings/ScriptPluginSettings.tsx +4 -19
- package/src/components/TestPanel/TestContainer.tsx +2 -2
- package/src/components/TestPanel/TestPanel.tsx +42 -19
- package/src/components/TypescriptEditor/TypescriptEditor.stories.tsx +71 -16
- package/src/components/TypescriptEditor/TypescriptEditor.tsx +36 -35
- package/src/components/index.ts +3 -0
- package/src/events.ts +2 -2
- package/src/hooks/deploy.ts +17 -17
- package/src/hooks/format.ts +4 -4
- package/src/hooks/template.ts +6 -15
- package/src/hooks/useCreateAndDeployScriptTemplates.ts +10 -6
- package/src/index.ts +1 -0
- package/src/meta.ts +7 -5
- package/src/notebook/compute-graph.test.ts +70 -0
- package/src/notebook/compute-graph.ts +206 -0
- package/src/notebook/eval.ts +105 -0
- package/src/notebook/index.ts +5 -0
- package/src/notebook/vfs-parser.test.ts +149 -0
- package/src/notebook/vfs-parser.ts +451 -0
- package/src/templates/chess.ts +2 -0
- package/src/templates/data-generator.ts +2 -0
- package/src/templates/discord.ts +9 -1
- package/src/templates/forex-effect.ts +5 -1
- package/src/templates/forex.ts +2 -0
- package/src/templates/gmail.ts +22 -11
- package/src/templates/index.ts +6 -6
- package/src/testing/data.ts +72 -0
- package/src/testing/index.ts +5 -0
- package/src/translations.ts +34 -7
- package/src/types/Notebook.ts +42 -0
- package/src/types/actions.ts +53 -0
- package/src/types/index.ts +3 -1
- package/src/types/types.ts +15 -0
- package/src/util/deploy.ts +14 -18
- package/src/util/functions.ts +37 -6
- package/dist/lib/browser/DeploymentDialog-QZSTVNIS.mjs +0 -12
- package/dist/lib/browser/ScriptContainer-JUPCBUCP.mjs +0 -263
- package/dist/lib/browser/ScriptContainer-JUPCBUCP.mjs.map +0 -7
- package/dist/lib/browser/app-graph-builder-IABOSTBK.mjs.map +0 -7
- package/dist/lib/browser/chunk-6CAH7VIE.mjs +0 -283
- package/dist/lib/browser/chunk-6CAH7VIE.mjs.map +0 -7
- package/dist/lib/browser/chunk-IS4OG2UW.mjs +0 -39
- package/dist/lib/browser/chunk-IS4OG2UW.mjs.map +0 -7
- package/dist/lib/browser/chunk-NXKU3BNX.mjs +0 -222
- package/dist/lib/browser/chunk-NXKU3BNX.mjs.map +0 -7
- package/dist/lib/browser/chunk-QYAREHGH.mjs.map +0 -7
- package/dist/lib/browser/chunk-RNGIQIEJ.mjs +0 -88
- package/dist/lib/browser/chunk-RNGIQIEJ.mjs.map +0 -7
- package/dist/lib/browser/chunk-TH7GXPE3.mjs.map +0 -7
- package/dist/lib/browser/chunk-YCZPTTFO.mjs.map +0 -7
- package/dist/lib/browser/compiler-2HJH34GM.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-YMK5SXVC.mjs.map +0 -7
- package/dist/lib/browser/react-surface-FEM5WWFH.mjs.map +0 -7
- package/dist/lib/browser/settings-KCTBK5TY.mjs.map +0 -7
- package/dist/lib/node-esm/DeploymentDialog-G6EHEPXN.mjs +0 -13
- package/dist/lib/node-esm/ScriptContainer-UXZUDQF6.mjs +0 -264
- package/dist/lib/node-esm/ScriptContainer-UXZUDQF6.mjs.map +0 -7
- package/dist/lib/node-esm/app-graph-builder-CQTTAYHP.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-2GBESIHU.mjs +0 -284
- package/dist/lib/node-esm/chunk-2GBESIHU.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-6M2R2FQF.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-AHXJ6NQU.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-GWHLP5LM.mjs +0 -90
- package/dist/lib/node-esm/chunk-GWHLP5LM.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-JIPFLBYA.mjs +0 -40
- package/dist/lib/node-esm/chunk-JIPFLBYA.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-M642JUOZ.mjs +0 -223
- package/dist/lib/node-esm/chunk-M642JUOZ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ZA36GO4T.mjs.map +0 -7
- package/dist/lib/node-esm/compiler-7SP27RA6.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-SKRDYQCZ.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-AOKMDJR4.mjs.map +0 -7
- package/dist/lib/node-esm/settings-DXZ334A3.mjs.map +0 -7
- package/dist/types/src/templates/echo.d.ts.map +0 -1
- package/dist/types/src/types/schema.d.ts +0 -38
- package/dist/types/src/types/schema.d.ts.map +0 -1
- package/src/types/schema.ts +0 -37
- /package/dist/lib/browser/{DeploymentDialog-QZSTVNIS.mjs.map → DeploymentDialog-5TKNGPVR.mjs.map} +0 -0
- /package/dist/lib/{node-esm/DeploymentDialog-G6EHEPXN.mjs.map → browser/chunk-J5LGTIGS.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-5TVBECWH.mjs.map → chunk-UOQ6NCH3.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-35M3CHYE.mjs.map → chunk-55JZVM6K.mjs.map} +0 -0
- /package/src/templates/{echo.ts → ping.ts} +0 -0
|
@@ -5,31 +5,38 @@
|
|
|
5
5
|
import { Octokit } from '@octokit/core';
|
|
6
6
|
import React, { type ChangeEvent, useCallback, useState } from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { ToolId } from '@dxos/ai';
|
|
9
|
+
import { SettingsAction, createIntent } from '@dxos/app-framework';
|
|
10
|
+
import { useIntentDispatcher } from '@dxos/app-framework/react';
|
|
11
|
+
import { Blueprint, Template } from '@dxos/blueprints';
|
|
12
|
+
import { Filter, Obj, Ref } from '@dxos/echo';
|
|
13
|
+
import { Function, type Script, getUserFunctionIdInMetadata } from '@dxos/functions';
|
|
14
|
+
import { getInvocationUrl } from '@dxos/functions-runtime';
|
|
10
15
|
import { log } from '@dxos/log';
|
|
11
16
|
import { useClient } from '@dxos/react-client';
|
|
12
|
-
import {
|
|
17
|
+
import { getSpace, useQuery } from '@dxos/react-client/echo';
|
|
13
18
|
import { Button, Clipboard, Input, useAsyncEffect, useControlledState, useTranslation } from '@dxos/react-ui';
|
|
14
|
-
import {
|
|
19
|
+
import { AccessToken } from '@dxos/types';
|
|
20
|
+
import { kebabize } from '@dxos/util';
|
|
15
21
|
|
|
16
|
-
import {
|
|
22
|
+
import { meta } from '../../meta';
|
|
17
23
|
|
|
18
24
|
export type ScriptObjectSettingsProps = {
|
|
19
|
-
object:
|
|
25
|
+
object: Script.Script;
|
|
20
26
|
};
|
|
21
27
|
|
|
22
28
|
export const ScriptObjectSettings = ({ object }: ScriptObjectSettingsProps) => {
|
|
23
29
|
return (
|
|
24
30
|
<>
|
|
25
31
|
<Binding object={object} />
|
|
32
|
+
<BlueprintEditor object={object} />
|
|
26
33
|
<Publishing object={object} />
|
|
27
34
|
</>
|
|
28
35
|
);
|
|
29
36
|
};
|
|
30
37
|
|
|
31
38
|
export const ScriptProperties = ({ object }: ScriptObjectSettingsProps) => {
|
|
32
|
-
const { t } = useTranslation(
|
|
39
|
+
const { t } = useTranslation(meta.id);
|
|
33
40
|
return (
|
|
34
41
|
<Input.Root>
|
|
35
42
|
<Input.Label>{t('description label')}</Input.Label>
|
|
@@ -44,13 +51,101 @@ export const ScriptProperties = ({ object }: ScriptObjectSettingsProps) => {
|
|
|
44
51
|
);
|
|
45
52
|
};
|
|
46
53
|
|
|
54
|
+
const BlueprintEditor = ({ object }: ScriptObjectSettingsProps) => {
|
|
55
|
+
const { t } = useTranslation(meta.id);
|
|
56
|
+
const space = getSpace(object);
|
|
57
|
+
const [fn] = useQuery(space, Filter.type(Function.Function, { source: Ref.make(object) }));
|
|
58
|
+
const blueprints = useQuery(space, Filter.type(Blueprint.Blueprint));
|
|
59
|
+
|
|
60
|
+
const [creating, setCreating] = useState(false);
|
|
61
|
+
const [instructions, setInstructions] = useState<string>(`You can run the script "${object.name ?? 'script'}".`);
|
|
62
|
+
const blueprintKey = `dxos.org/blueprint/${kebabize(object.name ?? 'script')}`;
|
|
63
|
+
const existingBlueprint = blueprints.find((bp) => bp.key === blueprintKey);
|
|
64
|
+
|
|
65
|
+
useAsyncEffect(async () => {
|
|
66
|
+
if (!existingBlueprint) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const source = await existingBlueprint.instructions.source.load();
|
|
70
|
+
setInstructions(source.content ?? '');
|
|
71
|
+
}, [existingBlueprint]);
|
|
72
|
+
|
|
73
|
+
const handleSave = useCallback(async () => {
|
|
74
|
+
if (!space) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
setCreating(true);
|
|
79
|
+
try {
|
|
80
|
+
if (existingBlueprint) {
|
|
81
|
+
const text = await existingBlueprint.instructions.source.load();
|
|
82
|
+
text.content = instructions;
|
|
83
|
+
if (fn?.key) {
|
|
84
|
+
const toolId = ToolId.make(fn.key);
|
|
85
|
+
if (!existingBlueprint.tools?.includes(toolId)) {
|
|
86
|
+
existingBlueprint.tools = [...(existingBlueprint.tools ?? []), toolId];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
} else if (fn?.key) {
|
|
90
|
+
space.db.add(
|
|
91
|
+
Blueprint.make({
|
|
92
|
+
key: blueprintKey,
|
|
93
|
+
name: object.name ?? 'Script',
|
|
94
|
+
instructions: Template.make({
|
|
95
|
+
source: instructions,
|
|
96
|
+
}),
|
|
97
|
+
tools: [ToolId.make(fn.key)],
|
|
98
|
+
}),
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
await space.db.flush();
|
|
102
|
+
} finally {
|
|
103
|
+
setCreating(false);
|
|
104
|
+
}
|
|
105
|
+
}, [space, existingBlueprint, fn, blueprintKey, object.name, instructions]);
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<div className='flex flex-col gap-4 mlb-cardSpacingBlock'>
|
|
109
|
+
<div>
|
|
110
|
+
<h2>{t('blueprint editor label', { default: 'Blueprint' })}</h2>
|
|
111
|
+
<p className='text-description text-sm'>
|
|
112
|
+
{t('blueprint editor description', {
|
|
113
|
+
default: 'Create a blueprint that exposes this script as a tool.',
|
|
114
|
+
})}
|
|
115
|
+
</p>
|
|
116
|
+
</div>
|
|
117
|
+
<Input.Root>
|
|
118
|
+
<div role='none' className='flex flex-col gap-1'>
|
|
119
|
+
<Input.Label>{t('blueprint instructions label', { default: 'Instructions' })}</Input.Label>
|
|
120
|
+
<Input.TextArea
|
|
121
|
+
placeholder={t('blueprint instructions placeholder', {
|
|
122
|
+
default: 'Describe how this tool should be used.',
|
|
123
|
+
})}
|
|
124
|
+
rows={6}
|
|
125
|
+
value={instructions}
|
|
126
|
+
onChange={(event) => setInstructions(event.target.value)}
|
|
127
|
+
classNames='resize-y'
|
|
128
|
+
/>
|
|
129
|
+
</div>
|
|
130
|
+
</Input.Root>
|
|
131
|
+
<div className='flex justify-end gap-2'>
|
|
132
|
+
<Button disabled={(!existingBlueprint && !fn?.key) || creating} onClick={handleSave}>
|
|
133
|
+
{t(creating ? 'creating label' : 'create blueprint label', {
|
|
134
|
+
default: creating ? 'Creating…' : 'Create blueprint',
|
|
135
|
+
})}
|
|
136
|
+
</Button>
|
|
137
|
+
</div>
|
|
138
|
+
</div>
|
|
139
|
+
);
|
|
140
|
+
};
|
|
141
|
+
|
|
47
142
|
const Binding = ({ object }: ScriptObjectSettingsProps) => {
|
|
48
|
-
const { t } = useTranslation(
|
|
143
|
+
const { t } = useTranslation(meta.id);
|
|
49
144
|
const client = useClient();
|
|
50
145
|
const space = getSpace(object);
|
|
51
|
-
const [fn] = useQuery(space, Filter.type(
|
|
146
|
+
const [fn] = useQuery(space, Filter.type(Function.Function, { source: Ref.make(object) }));
|
|
52
147
|
|
|
53
|
-
const functionId = fn && getUserFunctionIdInMetadata(getMeta(fn));
|
|
148
|
+
const functionId = fn && getUserFunctionIdInMetadata(Obj.getMeta(fn));
|
|
54
149
|
const functionUrl =
|
|
55
150
|
functionId &&
|
|
56
151
|
getInvocationUrl(functionId, client.config.values.runtime?.services?.edge?.url ?? '', {
|
|
@@ -109,11 +204,11 @@ const Binding = ({ object }: ScriptObjectSettingsProps) => {
|
|
|
109
204
|
|
|
110
205
|
// TODO(burdon): Move to separate tab?
|
|
111
206
|
const Publishing = ({ object }: ScriptObjectSettingsProps) => {
|
|
112
|
-
const { t } = useTranslation(
|
|
207
|
+
const { t } = useTranslation(meta.id);
|
|
113
208
|
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
114
209
|
const space = getSpace(object);
|
|
115
|
-
const [githubToken] = useQuery(space, Filter.type(
|
|
116
|
-
const gistKey = getMeta(object).keys.find(({ source }) => source === 'github.com');
|
|
210
|
+
const [githubToken] = useQuery(space, Filter.type(AccessToken.AccessToken, { source: 'github.com' }));
|
|
211
|
+
const gistKey = Obj.getMeta(object).keys.find(({ source }) => source === 'github.com');
|
|
117
212
|
const [gistUrl, setGistUrl] = useState<string | undefined>();
|
|
118
213
|
|
|
119
214
|
useAsyncEffect(async () => {
|
|
@@ -137,7 +232,12 @@ const Publishing = ({ object }: ScriptObjectSettingsProps) => {
|
|
|
137
232
|
}, [githubToken, gistKey]);
|
|
138
233
|
|
|
139
234
|
const handleOpenTokenManager = useCallback(
|
|
140
|
-
() =>
|
|
235
|
+
() =>
|
|
236
|
+
dispatch(
|
|
237
|
+
createIntent(SettingsAction.Open, {
|
|
238
|
+
plugin: 'dxos.org/plugin/token-manager',
|
|
239
|
+
}),
|
|
240
|
+
),
|
|
141
241
|
[],
|
|
142
242
|
);
|
|
143
243
|
|
|
@@ -151,7 +251,7 @@ const Publishing = ({ object }: ScriptObjectSettingsProps) => {
|
|
|
151
251
|
|
|
152
252
|
try {
|
|
153
253
|
// TODO(wittjosiah): Factor out to intent.
|
|
154
|
-
const meta = getMeta(object);
|
|
254
|
+
const meta = Obj.getMeta(object);
|
|
155
255
|
const githubKey = meta.keys.find(({ source }) => source === 'github.com');
|
|
156
256
|
const gistId = githubKey?.id;
|
|
157
257
|
if (gistId) {
|
|
@@ -196,7 +296,3 @@ const Publishing = ({ object }: ScriptObjectSettingsProps) => {
|
|
|
196
296
|
</div>
|
|
197
297
|
);
|
|
198
298
|
};
|
|
199
|
-
|
|
200
|
-
// TODO(wittjosiah): Factor out.
|
|
201
|
-
// From https://stackoverflow.com/a/67243723/2804332
|
|
202
|
-
const kebabize = (str: string) => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? '-' : '') + $.toLowerCase());
|
|
@@ -4,38 +4,23 @@
|
|
|
4
4
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
7
|
-
import { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
8
7
|
import { useClient } from '@dxos/react-client';
|
|
9
8
|
import { Button, Select, useTranslation } from '@dxos/react-ui';
|
|
10
9
|
import { type EditorInputMode, EditorInputModes } from '@dxos/react-ui-editor';
|
|
11
10
|
import { ControlGroup, ControlItemInput, ControlPage, ControlSection } from '@dxos/react-ui-form';
|
|
12
11
|
|
|
13
12
|
import { meta } from '../../meta';
|
|
14
|
-
import { type
|
|
13
|
+
import { type ScriptSettings } from '../../types';
|
|
14
|
+
import { getAccessCredential } from '../../util';
|
|
15
15
|
|
|
16
|
-
export const ScriptPluginSettings = ({ settings }: { settings:
|
|
16
|
+
export const ScriptPluginSettings = ({ settings }: { settings: ScriptSettings }) => {
|
|
17
17
|
const { t } = useTranslation(meta.id);
|
|
18
18
|
const client = useClient();
|
|
19
19
|
|
|
20
20
|
// TODO(burdon): Check token.
|
|
21
21
|
const handleAuthenticate = async () => {
|
|
22
22
|
const { identityKey } = client.halo.identity.get()!;
|
|
23
|
-
await client.halo.writeCredentials([
|
|
24
|
-
{
|
|
25
|
-
issuer: identityKey,
|
|
26
|
-
issuanceDate: new Date(),
|
|
27
|
-
subject: {
|
|
28
|
-
id: identityKey,
|
|
29
|
-
assertion: {
|
|
30
|
-
'@type': 'dxos.halo.credentials.ServiceAccess',
|
|
31
|
-
serverName: 'hub.dxos.network',
|
|
32
|
-
serverKey: identityKey,
|
|
33
|
-
identityKey,
|
|
34
|
-
capabilities: ['composer:beta'],
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
} satisfies Credential,
|
|
38
|
-
]);
|
|
23
|
+
await client.halo.writeCredentials([getAccessCredential(identityKey)]);
|
|
39
24
|
};
|
|
40
25
|
|
|
41
26
|
return (
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
7
|
-
import { type
|
|
7
|
+
import { type Script } from '@dxos/functions';
|
|
8
8
|
import { StackItem } from '@dxos/react-ui-stack';
|
|
9
9
|
|
|
10
10
|
import { useDeployState, useToolbarState } from '../../hooks';
|
|
@@ -13,7 +13,7 @@ import { TestPanel } from './TestPanel';
|
|
|
13
13
|
|
|
14
14
|
export type TestContainerProps = {
|
|
15
15
|
role: string;
|
|
16
|
-
script:
|
|
16
|
+
script: Script.Script;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
export const TestContainer = ({ script }: TestContainerProps) => {
|
|
@@ -9,14 +9,19 @@ import { Avatar, Icon, Input, type ThemedClassName, Toolbar, useTranslation } fr
|
|
|
9
9
|
import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
10
10
|
import { errorText, mx } from '@dxos/react-ui-theme';
|
|
11
11
|
|
|
12
|
-
import {
|
|
12
|
+
import { meta } from '../../meta';
|
|
13
13
|
|
|
14
14
|
type State = 'pending' | 'responding';
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Request or response.
|
|
18
18
|
*/
|
|
19
|
-
type Message = {
|
|
19
|
+
type Message = {
|
|
20
|
+
type: 'request' | 'response';
|
|
21
|
+
text?: string;
|
|
22
|
+
data?: any;
|
|
23
|
+
error?: Error;
|
|
24
|
+
};
|
|
20
25
|
|
|
21
26
|
export type TestPanelProps = ThemedClassName<{
|
|
22
27
|
functionUrl?: string;
|
|
@@ -24,7 +29,7 @@ export type TestPanelProps = ThemedClassName<{
|
|
|
24
29
|
|
|
25
30
|
// TODO(burdon): Need persistent history (currently lost when switching tabs)..
|
|
26
31
|
export const TestPanel = ({ classNames, functionUrl }: TestPanelProps) => {
|
|
27
|
-
const { t } = useTranslation(
|
|
32
|
+
const { t } = useTranslation(meta.id);
|
|
28
33
|
|
|
29
34
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
30
35
|
const [input, setInput] = useState('');
|
|
@@ -41,7 +46,7 @@ export const TestPanel = ({ classNames, functionUrl }: TestPanelProps) => {
|
|
|
41
46
|
}
|
|
42
47
|
};
|
|
43
48
|
|
|
44
|
-
const controller = useRef<AbortController>();
|
|
49
|
+
const controller = useRef<AbortController>(null);
|
|
45
50
|
useEffect(() => {
|
|
46
51
|
return () => {
|
|
47
52
|
handleStop();
|
|
@@ -50,7 +55,7 @@ export const TestPanel = ({ classNames, functionUrl }: TestPanelProps) => {
|
|
|
50
55
|
|
|
51
56
|
const handleStop = () => {
|
|
52
57
|
controller.current?.abort('stop');
|
|
53
|
-
controller.current =
|
|
58
|
+
controller.current = null;
|
|
54
59
|
};
|
|
55
60
|
|
|
56
61
|
const handleClear = () => {
|
|
@@ -61,8 +66,16 @@ export const TestPanel = ({ classNames, functionUrl }: TestPanelProps) => {
|
|
|
61
66
|
inputRef.current?.focus();
|
|
62
67
|
};
|
|
63
68
|
|
|
64
|
-
const handleResponse = ({
|
|
65
|
-
|
|
69
|
+
const handleResponse = ({
|
|
70
|
+
text,
|
|
71
|
+
data,
|
|
72
|
+
error,
|
|
73
|
+
}: {
|
|
74
|
+
text?: string;
|
|
75
|
+
data?: any;
|
|
76
|
+
error?: Error;
|
|
77
|
+
} = {}) => {
|
|
78
|
+
controller.current = null;
|
|
66
79
|
setHistory((history) => [...history, { type: 'response', text, data, error } satisfies Message]);
|
|
67
80
|
setResult('');
|
|
68
81
|
setState(null);
|
|
@@ -108,7 +121,9 @@ export const TestPanel = ({ classNames, functionUrl }: TestPanelProps) => {
|
|
|
108
121
|
// Check for error.
|
|
109
122
|
if (!response.ok) {
|
|
110
123
|
const text = await response.text();
|
|
111
|
-
handleResponse({
|
|
124
|
+
handleResponse({
|
|
125
|
+
error: new Error(text || response.statusText || String(response.status)),
|
|
126
|
+
});
|
|
112
127
|
return;
|
|
113
128
|
}
|
|
114
129
|
|
|
@@ -159,11 +174,11 @@ export const TestPanel = ({ classNames, functionUrl }: TestPanelProps) => {
|
|
|
159
174
|
};
|
|
160
175
|
|
|
161
176
|
return (
|
|
162
|
-
<div className={mx('flex flex-col
|
|
177
|
+
<div className={mx('flex flex-col bs-full overflow-hidden', classNames)}>
|
|
163
178
|
{/* TODO(burdon): Replace with Thread. */}
|
|
164
179
|
<MessageThread ref={scrollerRef} state={state} result={result} history={history} />
|
|
165
180
|
{/* TODO(burdon): Replace with Form based on the function's input schema. */}
|
|
166
|
-
<Toolbar.Root
|
|
181
|
+
<Toolbar.Root>
|
|
167
182
|
<Input.Root>
|
|
168
183
|
<Input.TextInput
|
|
169
184
|
ref={inputRef}
|
|
@@ -174,12 +189,20 @@ export const TestPanel = ({ classNames, functionUrl }: TestPanelProps) => {
|
|
|
174
189
|
onKeyDown={(ev) => ev.key === 'Enter' && handleRequest(input)}
|
|
175
190
|
/>
|
|
176
191
|
</Input.Root>
|
|
177
|
-
<Toolbar.
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
192
|
+
<Toolbar.IconButton
|
|
193
|
+
icon='ph--play--regular'
|
|
194
|
+
size={4}
|
|
195
|
+
label='Execute'
|
|
196
|
+
iconOnly
|
|
197
|
+
onClick={() => handleRequest(input)}
|
|
198
|
+
/>
|
|
199
|
+
<Toolbar.IconButton
|
|
200
|
+
icon={state ? 'ph--stop--regular' : 'ph--trash--regular'}
|
|
201
|
+
size={4}
|
|
202
|
+
label={state ? 'Stop' : 'Clear'}
|
|
203
|
+
iconOnly
|
|
204
|
+
onClick={() => (state ? handleStop() : handleClear())}
|
|
205
|
+
/>
|
|
183
206
|
</Toolbar.Root>
|
|
184
207
|
</div>
|
|
185
208
|
);
|
|
@@ -196,7 +219,7 @@ type MessageThreadProps = {
|
|
|
196
219
|
const MessageThread = forwardRef<HTMLDivElement, MessageThreadProps>(
|
|
197
220
|
({ state, history, result }: MessageThreadProps, forwardedRef) => {
|
|
198
221
|
return (
|
|
199
|
-
<div ref={forwardedRef} className='flex flex-col gap-6
|
|
222
|
+
<div ref={forwardedRef} className='flex flex-col gap-6 bs-full p-2 overflow-x-hidden overflow-y-auto'>
|
|
200
223
|
{history.map((message, i) => (
|
|
201
224
|
<div key={i} className='grid grid-cols-[2rem_1fr_2rem]'>
|
|
202
225
|
<div className='p-1'>{message.type === 'response' && <RobotAvatar />}</div>
|
|
@@ -225,7 +248,7 @@ const MessageThread = forwardRef<HTMLDivElement, MessageThreadProps>(
|
|
|
225
248
|
|
|
226
249
|
const MessageItem = ({ classNames, message }: ThemedClassName<{ message: Message }>) => {
|
|
227
250
|
const { type, text, data, error } = message;
|
|
228
|
-
const wrapper = 'p-1
|
|
251
|
+
const wrapper = 'p-1 pli-2 rounded-md bg-hoverSurface overflow-auto';
|
|
229
252
|
return (
|
|
230
253
|
<div className={mx('flex', type === 'request' ? 'ml-[1rem] justify-end' : 'mr-[1rem]', classNames)}>
|
|
231
254
|
{error && <div className={mx(wrapper, 'whitespace-pre', errorText)}>{String(error)}</div>}
|
|
@@ -237,7 +260,7 @@ const MessageItem = ({ classNames, message }: ThemedClassName<{ message: Message
|
|
|
237
260
|
)}
|
|
238
261
|
|
|
239
262
|
{data && (
|
|
240
|
-
<SyntaxHighlighter language='json' className={mx(wrapper, '
|
|
263
|
+
<SyntaxHighlighter language='json' className={mx(wrapper, 'text-xs')}>
|
|
241
264
|
{JSON.stringify(data, null, 2)}
|
|
242
265
|
</SyntaxHighlighter>
|
|
243
266
|
)}
|
|
@@ -2,36 +2,91 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@dxos-theme';
|
|
6
|
-
|
|
7
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
|
-
import React, { useMemo } from 'react';
|
|
6
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
9
7
|
|
|
10
|
-
import { createDocAccessor
|
|
8
|
+
import { createDocAccessor } from '@dxos/echo-db';
|
|
9
|
+
import { createObject } from '@dxos/react-client/echo';
|
|
10
|
+
import { Toolbar } from '@dxos/react-ui';
|
|
11
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
11
12
|
import { createDataExtensions } from '@dxos/react-ui-editor';
|
|
12
|
-
import {
|
|
13
|
+
import { StackItem } from '@dxos/react-ui-stack';
|
|
14
|
+
import { Json } from '@dxos/react-ui-syntax-highlighter';
|
|
15
|
+
import { trim } from '@dxos/util';
|
|
16
|
+
|
|
17
|
+
import { TypescriptEditor, type TypescriptEditorProps } from './TypescriptEditor';
|
|
18
|
+
|
|
19
|
+
const SCRIPT = trim`
|
|
20
|
+
x * 2
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
const DefaultStory = (props: TypescriptEditorProps) => {
|
|
24
|
+
const object = useMemo(() => createObject({ content: SCRIPT }), []);
|
|
25
|
+
const [result, setResult] = useState<object | undefined>({});
|
|
13
26
|
|
|
14
|
-
|
|
27
|
+
// TODO(burdon): Make this work.
|
|
28
|
+
// const object = useMemo(() => Text.make(templates[1].source), []);
|
|
29
|
+
// const script = useMemo(
|
|
30
|
+
// () =>
|
|
31
|
+
// Obj.make(ScriptType, {
|
|
32
|
+
// source: Ref.make(createObject({ content: templates[0].source })),
|
|
33
|
+
// }),
|
|
34
|
+
// [object],
|
|
35
|
+
// );
|
|
15
36
|
|
|
16
|
-
|
|
37
|
+
const extensions = useMemo(
|
|
38
|
+
() => [createDataExtensions({ id: object.id, text: createDocAccessor(object, ['content']) })],
|
|
39
|
+
[],
|
|
40
|
+
);
|
|
17
41
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
42
|
+
const handleRun = useCallback(async () => {
|
|
43
|
+
try {
|
|
44
|
+
const definitions: [string, any][] = [['x', 100]];
|
|
45
|
+
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
47
|
+
const result = new Function(...definitions.map(([name]) => name), `return ${object.content.trim()}`)(
|
|
48
|
+
...definitions.map(([, value]) => value),
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
setResult({
|
|
52
|
+
timestamp: Date.now(),
|
|
53
|
+
result,
|
|
54
|
+
});
|
|
55
|
+
} catch (err) {
|
|
56
|
+
setResult({
|
|
57
|
+
timestamp: Date.now(),
|
|
58
|
+
error: String(err),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}, [object]);
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<StackItem.Content toolbar>
|
|
65
|
+
{/* <ScriptToolbar script={script} state={{}} /> */}
|
|
66
|
+
<Toolbar.Root>
|
|
67
|
+
<Toolbar.Button onClick={handleRun}>Run</Toolbar.Button>
|
|
68
|
+
</Toolbar.Root>
|
|
69
|
+
<div role='none' className='grid grid-rows-[1fr_min-content] bs-full overflow-hidden text-sm'>
|
|
70
|
+
<TypescriptEditor {...props} initialValue={object.content} extensions={extensions} />
|
|
71
|
+
<Json data={result} classNames='shrink-0 p-2 border-t border-subduedSeparator' />
|
|
72
|
+
</div>
|
|
73
|
+
</StackItem.Content>
|
|
74
|
+
);
|
|
24
75
|
};
|
|
25
76
|
|
|
26
77
|
const meta = {
|
|
27
78
|
title: 'plugins/plugin-script/TypescriptEditor',
|
|
28
|
-
component: TypescriptEditor
|
|
79
|
+
component: TypescriptEditor,
|
|
29
80
|
render: DefaultStory,
|
|
30
|
-
decorators: [withTheme],
|
|
81
|
+
decorators: [withTheme, withLayout({ container: 'column', classNames: 'is-prose' })],
|
|
31
82
|
} satisfies Meta<typeof DefaultStory>;
|
|
32
83
|
|
|
33
84
|
export default meta;
|
|
34
85
|
|
|
35
86
|
type Story = StoryObj<typeof meta>;
|
|
36
87
|
|
|
37
|
-
export const Default: Story = {
|
|
88
|
+
export const Default: Story = {
|
|
89
|
+
args: {
|
|
90
|
+
id: 'test',
|
|
91
|
+
},
|
|
92
|
+
};
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { autocompletion, completionKeymap } from '@codemirror/autocomplete';
|
|
5
6
|
import { javascript } from '@codemirror/lang-javascript';
|
|
6
|
-
import {
|
|
7
|
+
import { HighlightStyle } from '@codemirror/language';
|
|
7
8
|
import { lintKeymap } from '@codemirror/lint';
|
|
8
9
|
import { Prec } from '@codemirror/state';
|
|
9
|
-
import { oneDarkHighlightStyle } from '@codemirror/theme-one-dark';
|
|
10
10
|
import { keymap } from '@codemirror/view';
|
|
11
11
|
import { tags } from '@lezer/highlight';
|
|
12
12
|
import { type VirtualTypeScriptEnvironment } from '@typescript/vfs';
|
|
@@ -14,15 +14,15 @@ import { continueKeymap } from '@valtown/codemirror-continue';
|
|
|
14
14
|
import { type HoverInfo, tsAutocomplete, tsFacet, tsHover, tsLinter, tsSync } from '@valtown/codemirror-ts';
|
|
15
15
|
import React from 'react';
|
|
16
16
|
|
|
17
|
-
import { type ThemeMode, type ThemedClassName, useThemeContext } from '@dxos/react-ui';
|
|
17
|
+
import { Domino, type ThemeMode, type ThemedClassName, useThemeContext } from '@dxos/react-ui';
|
|
18
18
|
import {
|
|
19
|
+
type BasicExtensionsOptions,
|
|
19
20
|
type EditorInputMode,
|
|
20
21
|
InputModeExtensions,
|
|
21
22
|
type UseTextEditorProps,
|
|
22
|
-
autocomplete,
|
|
23
23
|
createBasicExtensions,
|
|
24
24
|
createThemeExtensions,
|
|
25
|
-
|
|
25
|
+
defaultStyles,
|
|
26
26
|
useTextEditor,
|
|
27
27
|
} from '@dxos/react-ui-editor';
|
|
28
28
|
import { mx } from '@dxos/react-ui-theme';
|
|
@@ -31,18 +31,21 @@ import { isNonNullable } from '@dxos/util';
|
|
|
31
31
|
export type TypescriptEditorProps = ThemedClassName<
|
|
32
32
|
{
|
|
33
33
|
id: string;
|
|
34
|
+
role?: string;
|
|
34
35
|
inputMode?: EditorInputMode;
|
|
35
36
|
toolbar?: boolean;
|
|
36
37
|
env?: VirtualTypeScriptEnvironment;
|
|
38
|
+
options?: BasicExtensionsOptions;
|
|
37
39
|
} & Pick<UseTextEditorProps, 'initialValue' | 'extensions' | 'scrollTo' | 'selection'>
|
|
38
40
|
>;
|
|
39
41
|
|
|
40
42
|
export const TypescriptEditor = ({
|
|
41
43
|
classNames,
|
|
42
44
|
id,
|
|
45
|
+
role = 'article',
|
|
43
46
|
inputMode = 'vscode',
|
|
44
|
-
toolbar,
|
|
45
47
|
env,
|
|
48
|
+
options,
|
|
46
49
|
initialValue,
|
|
47
50
|
extensions,
|
|
48
51
|
scrollTo,
|
|
@@ -62,21 +65,26 @@ export const TypescriptEditor = ({
|
|
|
62
65
|
indentWithTab: true,
|
|
63
66
|
lineNumbers: true,
|
|
64
67
|
lineWrapping: false,
|
|
65
|
-
|
|
66
|
-
scrollPastEnd: true,
|
|
68
|
+
scrollPastEnd: role !== 'section',
|
|
67
69
|
search: true,
|
|
70
|
+
...options,
|
|
71
|
+
}),
|
|
72
|
+
createThemeExtensions({
|
|
73
|
+
monospace: true,
|
|
74
|
+
themeMode,
|
|
75
|
+
syntaxHighlighting: true,
|
|
68
76
|
}),
|
|
69
|
-
createThemeExtensions({ themeMode, syntaxHighlighting: true }),
|
|
70
77
|
InputModeExtensions[inputMode],
|
|
71
|
-
|
|
78
|
+
|
|
79
|
+
javascript({ typescript: true }),
|
|
80
|
+
autocompletion({ override: env ? [tsAutocomplete()] : undefined }),
|
|
81
|
+
|
|
72
82
|
// Continues block comments when pressing Enter.
|
|
73
83
|
Prec.high(keymap.of(continueKeymap)),
|
|
84
|
+
keymap.of(completionKeymap),
|
|
85
|
+
keymap.of(lintKeymap),
|
|
74
86
|
|
|
75
|
-
// TODO(burdon): Factor out.
|
|
76
|
-
javascript({ typescript: true }),
|
|
77
87
|
// https://github.com/val-town/codemirror-ts
|
|
78
|
-
autocomplete({ override: env ? [tsAutocomplete()] : undefined }),
|
|
79
|
-
keymap.of(lintKeymap),
|
|
80
88
|
env && [
|
|
81
89
|
tsFacet.of({ env, path: `/src/${id}.ts` }),
|
|
82
90
|
tsSync(),
|
|
@@ -88,18 +96,13 @@ export const TypescriptEditor = ({
|
|
|
88
96
|
[id, extensions, themeMode, inputMode, selection, scrollTo],
|
|
89
97
|
);
|
|
90
98
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
ref={parentRef}
|
|
94
|
-
data-toolbar={toolbar ? 'enabled' : 'disabled'}
|
|
95
|
-
className={mx(classNames)}
|
|
96
|
-
{...focusAttributes}
|
|
97
|
-
/>
|
|
98
|
-
);
|
|
99
|
+
// TODO(brudon): Use react-ui-editor's Editor component.
|
|
100
|
+
return <div ref={parentRef} className={mx(classNames)} {...focusAttributes} />;
|
|
99
101
|
};
|
|
100
102
|
|
|
103
|
+
// TODO(burdon): Factor out (react-ui-editor).
|
|
101
104
|
const createTooltipRenderer = (themeMode: ThemeMode) => {
|
|
102
|
-
const theme = themeMode === 'dark' ?
|
|
105
|
+
const theme = HighlightStyle.define(themeMode === 'dark' ? defaultStyles.dark : defaultStyles.light);
|
|
103
106
|
|
|
104
107
|
const classFromKind = (_kind: string) => {
|
|
105
108
|
// E.g., localName, methodName, parameterName, etc.
|
|
@@ -118,18 +121,16 @@ const createTooltipRenderer = (themeMode: ThemeMode) => {
|
|
|
118
121
|
};
|
|
119
122
|
|
|
120
123
|
return (info: HoverInfo) => {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return { dom: div };
|
|
124
|
+
return {
|
|
125
|
+
dom: Domino.of('div')
|
|
126
|
+
.classNames('xs:max-is-80 max-is-lg p-1 bg-baseSurface rounded border border-separator')
|
|
127
|
+
.children(
|
|
128
|
+
...(info.quickInfo?.displayParts?.map(({ kind, text }) =>
|
|
129
|
+
Domino.of('span').classNames(classFromKind(kind)).text(text),
|
|
130
|
+
) ?? []),
|
|
131
|
+
)
|
|
132
|
+
.build(),
|
|
133
|
+
};
|
|
133
134
|
};
|
|
134
135
|
};
|
|
135
136
|
|
package/src/components/index.ts
CHANGED
|
@@ -4,9 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
import { lazy } from 'react';
|
|
6
6
|
|
|
7
|
+
export * from './NotebookStack';
|
|
7
8
|
export * from './Settings';
|
|
8
9
|
export * from './TestPanel';
|
|
10
|
+
|
|
9
11
|
export { DEPLOYMENT_DIALOG } from './DeploymentDialog';
|
|
10
12
|
|
|
11
13
|
export const ScriptContainer = lazy(() => import('./ScriptContainer'));
|
|
12
14
|
export const DeploymentDialog = lazy(() => import('./DeploymentDialog'));
|
|
15
|
+
export const NotebookContainer = lazy(() => import('./NotebookContainer'));
|
package/src/events.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
import { defineEvent } from '@dxos/app-framework';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { meta } from './meta';
|
|
8
8
|
|
|
9
9
|
export namespace ScriptEvents {
|
|
10
|
-
export const SetupCompiler = defineEvent(`${
|
|
10
|
+
export const SetupCompiler = defineEvent(`${meta.id}/event/setup-compiler`);
|
|
11
11
|
}
|