@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
|
@@ -0,0 +1,817 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NotebookMenu,
|
|
3
|
+
NotebookStack
|
|
4
|
+
} from "./chunk-ALS6X4HU.mjs";
|
|
5
|
+
import "./chunk-M6KJPUJK.mjs";
|
|
6
|
+
import {
|
|
7
|
+
meta
|
|
8
|
+
} from "./chunk-EB6AXFXO.mjs";
|
|
9
|
+
import "./chunk-J5LGTIGS.mjs";
|
|
10
|
+
|
|
11
|
+
// src/components/NotebookContainer.tsx
|
|
12
|
+
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
13
|
+
import * as Cause from "effect/Cause";
|
|
14
|
+
import * as Effect from "effect/Effect";
|
|
15
|
+
import * as Exit from "effect/Exit";
|
|
16
|
+
import React, { useCallback, useMemo, useState } from "react";
|
|
17
|
+
import { Agent } from "@dxos/assistant-toolkit";
|
|
18
|
+
import { Blueprint, Prompt } from "@dxos/blueprints";
|
|
19
|
+
import { Filter, Obj, Query, Ref } from "@dxos/echo";
|
|
20
|
+
import { QueryBuilder } from "@dxos/echo-query";
|
|
21
|
+
import { FunctionInvocationService } from "@dxos/functions";
|
|
22
|
+
import { InvocationTracer } from "@dxos/functions-runtime";
|
|
23
|
+
import { TracingServiceExt } from "@dxos/functions-runtime";
|
|
24
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
25
|
+
import { log as log2 } from "@dxos/log";
|
|
26
|
+
import { useComputeRuntimeCallback } from "@dxos/plugin-automation";
|
|
27
|
+
import { Graph } from "@dxos/plugin-explorer/types";
|
|
28
|
+
import { getSpace } from "@dxos/react-client/echo";
|
|
29
|
+
import { DropdownMenu, IconButton, Toolbar, useTranslation } from "@dxos/react-ui";
|
|
30
|
+
import { useAttention } from "@dxos/react-ui-attention";
|
|
31
|
+
import { StackItem } from "@dxos/react-ui-stack";
|
|
32
|
+
import { Text, View } from "@dxos/schema";
|
|
33
|
+
import { isNonNullable } from "@dxos/util";
|
|
34
|
+
|
|
35
|
+
// src/notebook/compute-graph.ts
|
|
36
|
+
import { signal } from "@preact/signals-core";
|
|
37
|
+
import { log } from "@dxos/log";
|
|
38
|
+
|
|
39
|
+
// src/notebook/eval.ts
|
|
40
|
+
import { trim } from "@dxos/util";
|
|
41
|
+
var evalScript = async (code, deps = {}) => {
|
|
42
|
+
const sandbox = {
|
|
43
|
+
...deps,
|
|
44
|
+
// Block access to global objects.
|
|
45
|
+
console: void 0,
|
|
46
|
+
document: void 0,
|
|
47
|
+
global: void 0,
|
|
48
|
+
globalThis: void 0,
|
|
49
|
+
self: void 0,
|
|
50
|
+
window: void 0,
|
|
51
|
+
// Allow some safe globals.
|
|
52
|
+
Array,
|
|
53
|
+
Boolean,
|
|
54
|
+
Date,
|
|
55
|
+
Error,
|
|
56
|
+
JSON,
|
|
57
|
+
Map,
|
|
58
|
+
Math,
|
|
59
|
+
Number,
|
|
60
|
+
Object,
|
|
61
|
+
Promise,
|
|
62
|
+
RegExp,
|
|
63
|
+
Set,
|
|
64
|
+
String,
|
|
65
|
+
// Functions.
|
|
66
|
+
isFinite,
|
|
67
|
+
isNaN,
|
|
68
|
+
parseFloat,
|
|
69
|
+
parseInt
|
|
70
|
+
};
|
|
71
|
+
const sandboxKeys = Object.keys(sandbox);
|
|
72
|
+
const sandboxValues = Object.values(sandbox);
|
|
73
|
+
const fn2 = new Function(...sandboxKeys, trim`
|
|
74
|
+
'use strict';
|
|
75
|
+
return ${code};
|
|
76
|
+
`);
|
|
77
|
+
return fn2(...sandboxValues);
|
|
78
|
+
};
|
|
79
|
+
var builtIns = /* @__PURE__ */ new Set([
|
|
80
|
+
// Types.
|
|
81
|
+
"Array",
|
|
82
|
+
"Date",
|
|
83
|
+
"Error",
|
|
84
|
+
"JSON",
|
|
85
|
+
"Map",
|
|
86
|
+
"Math",
|
|
87
|
+
"Number",
|
|
88
|
+
"Object",
|
|
89
|
+
"Promise",
|
|
90
|
+
"RegExp",
|
|
91
|
+
"Set",
|
|
92
|
+
"String",
|
|
93
|
+
// Functions.
|
|
94
|
+
"isFinite",
|
|
95
|
+
"isNaN",
|
|
96
|
+
"parseFloat",
|
|
97
|
+
"parseInt"
|
|
98
|
+
]);
|
|
99
|
+
var systemDefinitions = trim`
|
|
100
|
+
interface Array<T> { length: number; [n: number]: T; }
|
|
101
|
+
interface Boolean {}
|
|
102
|
+
interface Function {}
|
|
103
|
+
interface IArguments {}
|
|
104
|
+
interface Number {}
|
|
105
|
+
interface Object {}
|
|
106
|
+
interface RegExp {}
|
|
107
|
+
interface String { length: number; }
|
|
108
|
+
|
|
109
|
+
interface CallableFunction extends Function {}
|
|
110
|
+
interface NewableFunction extends Function {}
|
|
111
|
+
|
|
112
|
+
declare var console: { log(...args: any[]): void };
|
|
113
|
+
`;
|
|
114
|
+
|
|
115
|
+
// src/notebook/vfs-parser.ts
|
|
116
|
+
import { createSystem, createVirtualTypeScriptEnvironment } from "@typescript/vfs";
|
|
117
|
+
import ts from "typescript";
|
|
118
|
+
import { invariant } from "@dxos/invariant";
|
|
119
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-script/src/notebook/vfs-parser.ts";
|
|
120
|
+
var systemFiles = [
|
|
121
|
+
{
|
|
122
|
+
filename: "/lib.d.ts",
|
|
123
|
+
content: systemDefinitions
|
|
124
|
+
}
|
|
125
|
+
];
|
|
126
|
+
var VirtualTypeScriptParser = class {
|
|
127
|
+
compilerOptions = {
|
|
128
|
+
target: ts.ScriptTarget.ES2020,
|
|
129
|
+
module: ts.ModuleKind.ESNext,
|
|
130
|
+
strict: true,
|
|
131
|
+
esModuleInterop: true,
|
|
132
|
+
skipLibCheck: true,
|
|
133
|
+
forceConsistentCasingInfilenames: true,
|
|
134
|
+
jsx: ts.JsxEmit.React,
|
|
135
|
+
noLib: true
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Parse a single expression or statement.
|
|
139
|
+
*/
|
|
140
|
+
parseExpression(input) {
|
|
141
|
+
invariant(input.trim() !== "", "input must not be empty", {
|
|
142
|
+
F: __dxlog_file,
|
|
143
|
+
L: 57,
|
|
144
|
+
S: this,
|
|
145
|
+
A: [
|
|
146
|
+
"input.trim() !== ''",
|
|
147
|
+
"'input must not be empty'"
|
|
148
|
+
]
|
|
149
|
+
});
|
|
150
|
+
const files = [
|
|
151
|
+
{
|
|
152
|
+
filename: "/temp.ts",
|
|
153
|
+
content: input
|
|
154
|
+
}
|
|
155
|
+
];
|
|
156
|
+
const analysis = this.analyzeFiles(files);
|
|
157
|
+
if (analysis.length === 0) {
|
|
158
|
+
const sourcefilename = "/temp.ts";
|
|
159
|
+
const env = this.createEnvironment([
|
|
160
|
+
{
|
|
161
|
+
filename: sourcefilename,
|
|
162
|
+
content: input
|
|
163
|
+
}
|
|
164
|
+
]);
|
|
165
|
+
const sourceFile = env.getSourceFile(sourcefilename);
|
|
166
|
+
const typeChecker = env.languageService.getProgram()?.getTypeChecker();
|
|
167
|
+
if (sourceFile && typeChecker) {
|
|
168
|
+
const assignmentInfo = this.findAssignmentExpression(sourceFile, typeChecker);
|
|
169
|
+
if (assignmentInfo) {
|
|
170
|
+
return assignmentInfo;
|
|
171
|
+
}
|
|
172
|
+
const references = this.findAllReferences(sourceFile, typeChecker);
|
|
173
|
+
return {
|
|
174
|
+
references
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return analysis[0];
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Analyze multiple files with full type information.
|
|
182
|
+
*/
|
|
183
|
+
analyzeFiles(files) {
|
|
184
|
+
const env = this.createEnvironment(files);
|
|
185
|
+
const results = [];
|
|
186
|
+
const typeChecker = env.languageService.getProgram()?.getTypeChecker();
|
|
187
|
+
files.forEach((file) => {
|
|
188
|
+
const sourceFile = env.getSourceFile(file.filename);
|
|
189
|
+
if (!sourceFile || !typeChecker) return;
|
|
190
|
+
const fileResults = this.analyzeSourceFile(sourceFile, typeChecker);
|
|
191
|
+
results.push(...fileResults);
|
|
192
|
+
});
|
|
193
|
+
return results;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Analyze a source file with type information.
|
|
197
|
+
*/
|
|
198
|
+
analyzeSourceFile(sourceFile, typeChecker) {
|
|
199
|
+
const results = [];
|
|
200
|
+
const visit = (node) => {
|
|
201
|
+
if (ts.isFunctionDeclaration(node) && node.name) {
|
|
202
|
+
const symbol = typeChecker.getSymbolAtLocation(node.name);
|
|
203
|
+
const type = symbol && typeChecker.getTypeOfSymbolAtLocation(symbol, node);
|
|
204
|
+
const signature = type && typeChecker.getSignaturesOfType(type, ts.SignatureKind.Call)[0];
|
|
205
|
+
results.push({
|
|
206
|
+
name: node.name.text,
|
|
207
|
+
type: "function",
|
|
208
|
+
parameters: this.extractParameters(signature, typeChecker),
|
|
209
|
+
returnType: signature ? typeChecker.typeToString(signature.getReturnType()) : "any",
|
|
210
|
+
references: this.findReferences(node, sourceFile, typeChecker)
|
|
211
|
+
});
|
|
212
|
+
} else if (ts.isVariableStatement(node)) {
|
|
213
|
+
node.declarationList.declarations.forEach((declaration) => {
|
|
214
|
+
if (ts.isIdentifier(declaration.name)) {
|
|
215
|
+
const symbol = typeChecker.getSymbolAtLocation(declaration.name);
|
|
216
|
+
const type = symbol && typeChecker.getTypeOfSymbolAtLocation(symbol, declaration);
|
|
217
|
+
let kind = "variable";
|
|
218
|
+
let parameters;
|
|
219
|
+
let returnType;
|
|
220
|
+
let value;
|
|
221
|
+
const typeString = type ? typeChecker.typeToString(type) : "any";
|
|
222
|
+
if (declaration.initializer) {
|
|
223
|
+
if (ts.isArrowFunction(declaration.initializer) || ts.isFunctionExpression(declaration.initializer)) {
|
|
224
|
+
kind = "function";
|
|
225
|
+
const funcType = typeChecker.getTypeAtLocation(declaration.initializer);
|
|
226
|
+
const signature = typeChecker.getSignaturesOfType(funcType, ts.SignatureKind.Call)[0];
|
|
227
|
+
if (signature) {
|
|
228
|
+
parameters = this.extractParameters(signature, typeChecker);
|
|
229
|
+
returnType = typeChecker.typeToString(signature.getReturnType());
|
|
230
|
+
}
|
|
231
|
+
} else {
|
|
232
|
+
if (ts.isNumericLiteral(declaration.initializer)) {
|
|
233
|
+
value = Number(declaration.initializer.text);
|
|
234
|
+
} else if (ts.isStringLiteral(declaration.initializer)) {
|
|
235
|
+
value = declaration.initializer.text;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const refs = declaration.initializer ? this.findReferences(declaration.initializer, sourceFile, typeChecker) : [];
|
|
240
|
+
results.push({
|
|
241
|
+
name: declaration.name.text,
|
|
242
|
+
type: kind,
|
|
243
|
+
valueType: typeString,
|
|
244
|
+
value,
|
|
245
|
+
parameters,
|
|
246
|
+
returnType,
|
|
247
|
+
references: refs
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
} else if (ts.isClassDeclaration(node) && node.name) {
|
|
252
|
+
results.push({
|
|
253
|
+
name: node.name.text,
|
|
254
|
+
type: "class",
|
|
255
|
+
references: this.findReferences(node, sourceFile, typeChecker)
|
|
256
|
+
});
|
|
257
|
+
} else if (ts.isInterfaceDeclaration(node)) {
|
|
258
|
+
results.push({
|
|
259
|
+
name: node.name.text,
|
|
260
|
+
type: "interface",
|
|
261
|
+
references: this.findReferences(node, sourceFile, typeChecker)
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
ts.forEachChild(node, visit);
|
|
265
|
+
};
|
|
266
|
+
visit(sourceFile);
|
|
267
|
+
return results;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Extract parameter information from a signature.
|
|
271
|
+
*/
|
|
272
|
+
extractParameters(signature, typeChecker) {
|
|
273
|
+
if (!signature) return [];
|
|
274
|
+
return signature.parameters.map((param) => ({
|
|
275
|
+
name: param.getName(),
|
|
276
|
+
type: typeChecker.typeToString(typeChecker.getTypeOfSymbolAtLocation(param, param.valueDeclaration))
|
|
277
|
+
}));
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Find all references to variables used in a node.
|
|
281
|
+
*/
|
|
282
|
+
findReferences(node, _sourceFile, _typeChecker) {
|
|
283
|
+
const references = /* @__PURE__ */ new Set();
|
|
284
|
+
const localSymbols = /* @__PURE__ */ new Set();
|
|
285
|
+
const collectLocalSymbols = (node2) => {
|
|
286
|
+
if (ts.isFunctionDeclaration(node2) || ts.isArrowFunction(node2) || ts.isFunctionExpression(node2)) {
|
|
287
|
+
node2.parameters.forEach((param) => {
|
|
288
|
+
if (ts.isIdentifier(param.name)) {
|
|
289
|
+
localSymbols.add(param.name.text);
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
if (ts.isVariableDeclaration(node2) && ts.isIdentifier(node2.name)) {
|
|
294
|
+
localSymbols.add(node2.name.text);
|
|
295
|
+
}
|
|
296
|
+
ts.forEachChild(node2, collectLocalSymbols);
|
|
297
|
+
};
|
|
298
|
+
collectLocalSymbols(node);
|
|
299
|
+
const findRefs = (node2) => {
|
|
300
|
+
if (ts.isIdentifier(node2)) {
|
|
301
|
+
if (!localSymbols.has(node2.text)) {
|
|
302
|
+
const parent = node2.parent;
|
|
303
|
+
const isDeclaration = ts.isVariableDeclaration(parent) && parent.name === node2 || ts.isFunctionDeclaration(parent) && parent.name === node2 || ts.isParameter(parent) && parent.name === node2;
|
|
304
|
+
if (!isDeclaration && !this.isBuiltIn(node2.text)) {
|
|
305
|
+
references.add(node2.text);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
ts.forEachChild(node2, findRefs);
|
|
310
|
+
};
|
|
311
|
+
findRefs(node);
|
|
312
|
+
return Array.from(references);
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Check if a name is a built-in global.
|
|
316
|
+
*/
|
|
317
|
+
isBuiltIn(name) {
|
|
318
|
+
return builtIns.has(name);
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Find assignment expressions in a source file.
|
|
322
|
+
*/
|
|
323
|
+
findAssignmentExpression(sourceFile, typeChecker) {
|
|
324
|
+
let result = null;
|
|
325
|
+
const visit = (node) => {
|
|
326
|
+
if (ts.isExpressionStatement(node) && ts.isBinaryExpression(node.expression)) {
|
|
327
|
+
const expr = node.expression;
|
|
328
|
+
if (expr.operatorToken.kind === ts.SyntaxKind.EqualsToken && ts.isIdentifier(expr.left)) {
|
|
329
|
+
const type = typeChecker.getTypeAtLocation(expr.right);
|
|
330
|
+
const typeString = typeChecker.typeToString(type);
|
|
331
|
+
let value;
|
|
332
|
+
if (ts.isNumericLiteral(expr.right)) {
|
|
333
|
+
value = Number(expr.right.text);
|
|
334
|
+
} else if (ts.isStringLiteral(expr.right)) {
|
|
335
|
+
value = expr.right.text;
|
|
336
|
+
}
|
|
337
|
+
const references = this.findReferences(expr.right, sourceFile, typeChecker);
|
|
338
|
+
result = {
|
|
339
|
+
name: expr.left.text,
|
|
340
|
+
type: "variable",
|
|
341
|
+
valueType: typeString,
|
|
342
|
+
value,
|
|
343
|
+
references
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
if (!result) {
|
|
348
|
+
ts.forEachChild(node, visit);
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
visit(sourceFile);
|
|
352
|
+
return result;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Find all identifier references in a source file.
|
|
356
|
+
*/
|
|
357
|
+
findAllReferences(sourceFile, _typeChecker) {
|
|
358
|
+
const references = /* @__PURE__ */ new Set();
|
|
359
|
+
const visit = (node) => {
|
|
360
|
+
if (ts.isIdentifier(node)) {
|
|
361
|
+
const parent = node.parent;
|
|
362
|
+
const isDeclaration = ts.isVariableDeclaration(parent) && parent.name === node || ts.isFunctionDeclaration(parent) && parent.name === node || ts.isParameter(parent) && parent.name === node;
|
|
363
|
+
const isAssignmentTarget = ts.isBinaryExpression(parent) && parent.operatorToken.kind === ts.SyntaxKind.EqualsToken && parent.left === node;
|
|
364
|
+
if (!isDeclaration && !isAssignmentTarget && !this.isBuiltIn(node.text)) {
|
|
365
|
+
references.add(node.text);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
ts.forEachChild(node, visit);
|
|
369
|
+
};
|
|
370
|
+
visit(sourceFile);
|
|
371
|
+
return Array.from(references);
|
|
372
|
+
}
|
|
373
|
+
createEnvironment(files) {
|
|
374
|
+
const allFiles = [
|
|
375
|
+
...systemFiles,
|
|
376
|
+
...files
|
|
377
|
+
];
|
|
378
|
+
const fileMap = /* @__PURE__ */ new Map();
|
|
379
|
+
allFiles.forEach(({ filename, content }) => {
|
|
380
|
+
fileMap.set(filename, content);
|
|
381
|
+
});
|
|
382
|
+
const system = createSystem(fileMap);
|
|
383
|
+
return createVirtualTypeScriptEnvironment(system, allFiles.map(({ filename }) => filename), ts, this.compilerOptions);
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
// src/notebook/compute-graph.ts
|
|
388
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/plugins/plugin-script/src/notebook/compute-graph.ts";
|
|
389
|
+
var ComputeGraph = class {
|
|
390
|
+
_notebook;
|
|
391
|
+
_parser = new VirtualTypeScriptParser();
|
|
392
|
+
_expressions = signal({});
|
|
393
|
+
_valuesByCellId = signal({});
|
|
394
|
+
_valuesByName = signal({});
|
|
395
|
+
constructor(_notebook) {
|
|
396
|
+
this._notebook = _notebook;
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Parsed expressions by cell ID.
|
|
400
|
+
*/
|
|
401
|
+
get expressions() {
|
|
402
|
+
return this._expressions;
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Computed values by cell ID.
|
|
406
|
+
*/
|
|
407
|
+
get values() {
|
|
408
|
+
return this._valuesByCellId;
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Computed values by name.
|
|
412
|
+
*/
|
|
413
|
+
get valuesByName() {
|
|
414
|
+
return this._valuesByName;
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Get computed value by cell ID.
|
|
418
|
+
*/
|
|
419
|
+
getValue(cellId) {
|
|
420
|
+
return this._valuesByCellId.value[cellId];
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Compute values.
|
|
424
|
+
*/
|
|
425
|
+
async evaluate() {
|
|
426
|
+
const { expressions, dependencyGraph } = this.parse();
|
|
427
|
+
this._valuesByCellId.value = {};
|
|
428
|
+
this._valuesByName.value = {};
|
|
429
|
+
const cellExpressions = /* @__PURE__ */ new Map();
|
|
430
|
+
Object.entries(expressions).forEach(([id, expr]) => {
|
|
431
|
+
cellExpressions.set(id, expr);
|
|
432
|
+
});
|
|
433
|
+
const evaluationOrder = this.topologicalSort(Object.keys(expressions), dependencyGraph);
|
|
434
|
+
const valuesByName = {};
|
|
435
|
+
const valuesByCellId = {};
|
|
436
|
+
for (const cellId of evaluationOrder) {
|
|
437
|
+
const expr = cellExpressions.get(cellId);
|
|
438
|
+
if (!expr) {
|
|
439
|
+
log.error("no expression for cell", {
|
|
440
|
+
cellId
|
|
441
|
+
}, {
|
|
442
|
+
F: __dxlog_file2,
|
|
443
|
+
L: 81,
|
|
444
|
+
S: this,
|
|
445
|
+
C: (f, a) => f(...a)
|
|
446
|
+
});
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
const cellSource = this._notebook.cells.find((cell) => cell.id === cellId)?.source?.target?.content;
|
|
450
|
+
if (!cellSource) {
|
|
451
|
+
log.error("no source for cell", {
|
|
452
|
+
cellId
|
|
453
|
+
}, {
|
|
454
|
+
F: __dxlog_file2,
|
|
455
|
+
L: 87,
|
|
456
|
+
S: this,
|
|
457
|
+
C: (f, a) => f(...a)
|
|
458
|
+
});
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
try {
|
|
462
|
+
if (expr.name && expr.value !== void 0) {
|
|
463
|
+
valuesByName[expr.name] = expr.value;
|
|
464
|
+
valuesByCellId[cellId] = expr.value;
|
|
465
|
+
} else if (expr.name) {
|
|
466
|
+
const equalIndex = cellSource.indexOf("=");
|
|
467
|
+
if (equalIndex !== -1) {
|
|
468
|
+
let rhs = cellSource.substring(equalIndex + 1).trim();
|
|
469
|
+
if (rhs.endsWith(";")) {
|
|
470
|
+
rhs = rhs.slice(0, -1).trim();
|
|
471
|
+
}
|
|
472
|
+
const result = await this.eval(rhs, valuesByName);
|
|
473
|
+
valuesByName[expr.name] = result;
|
|
474
|
+
if (typeof result !== "function") {
|
|
475
|
+
valuesByCellId[cellId] = result;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
} else {
|
|
479
|
+
const result = await this.eval(cellSource, valuesByName);
|
|
480
|
+
valuesByCellId[cellId] = result;
|
|
481
|
+
}
|
|
482
|
+
} catch (error) {
|
|
483
|
+
log.error("error evaluating cell", {
|
|
484
|
+
cellId,
|
|
485
|
+
error
|
|
486
|
+
}, {
|
|
487
|
+
F: __dxlog_file2,
|
|
488
|
+
L: 123,
|
|
489
|
+
S: this,
|
|
490
|
+
C: (f, a) => f(...a)
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
this._valuesByCellId.value = valuesByCellId;
|
|
495
|
+
this._valuesByName.value = valuesByName;
|
|
496
|
+
return valuesByCellId;
|
|
497
|
+
}
|
|
498
|
+
async eval(source, values) {
|
|
499
|
+
return evalScript(source, values);
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Parse expressions.
|
|
503
|
+
*/
|
|
504
|
+
parse() {
|
|
505
|
+
const expressions = this._notebook.cells.filter((cell) => cell.type === "script").reduce((acc, cell) => {
|
|
506
|
+
const text = cell.source?.target?.content.trim();
|
|
507
|
+
if (text) {
|
|
508
|
+
const parsed = this._parser.parseExpression(text);
|
|
509
|
+
acc[cell.id] = parsed;
|
|
510
|
+
}
|
|
511
|
+
return acc;
|
|
512
|
+
}, {});
|
|
513
|
+
const dependencyGraph = this.buildDependencyGraph(expressions);
|
|
514
|
+
this._expressions.value = expressions;
|
|
515
|
+
return {
|
|
516
|
+
expressions,
|
|
517
|
+
dependencyGraph
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
topologicalSort(nodes, dependencies) {
|
|
521
|
+
const visited = /* @__PURE__ */ new Set();
|
|
522
|
+
const result = [];
|
|
523
|
+
const visit = (node) => {
|
|
524
|
+
if (visited.has(node)) {
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
visited.add(node);
|
|
528
|
+
const deps = dependencies[node] || [];
|
|
529
|
+
deps.forEach((dep) => visit(dep));
|
|
530
|
+
result.push(node);
|
|
531
|
+
};
|
|
532
|
+
nodes.forEach((node) => visit(node));
|
|
533
|
+
return result;
|
|
534
|
+
}
|
|
535
|
+
buildDependencyGraph(expressions) {
|
|
536
|
+
const nameToCellId = /* @__PURE__ */ new Map();
|
|
537
|
+
Object.entries(expressions).forEach(([id, expr]) => {
|
|
538
|
+
if (expr.name) {
|
|
539
|
+
nameToCellId.set(expr.name, id);
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
const graph = {};
|
|
543
|
+
Object.entries(expressions).forEach(([id, expr]) => {
|
|
544
|
+
if (expr.references && expr.references.length > 0) {
|
|
545
|
+
const dependencyCellIds = expr.references.map((ref) => nameToCellId.get(ref)).filter((cellId) => cellId !== void 0 && cellId !== id);
|
|
546
|
+
if (dependencyCellIds.length > 0) {
|
|
547
|
+
graph[id] = dependencyCellIds;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
return graph;
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
// src/components/NotebookContainer.tsx
|
|
556
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/plugins/plugin-script/src/components/NotebookContainer.tsx";
|
|
557
|
+
var INCLUDE_BLUEPRINTS = [
|
|
558
|
+
"dxos.org/blueprint/assistant",
|
|
559
|
+
"dxos.org/blueprint/markdown"
|
|
560
|
+
];
|
|
561
|
+
var NotebookContainer = ({ notebook, env }) => {
|
|
562
|
+
var _effect = _useSignals();
|
|
563
|
+
try {
|
|
564
|
+
const { t } = useTranslation(meta.id);
|
|
565
|
+
const space = getSpace(notebook);
|
|
566
|
+
const attendableId = notebook ? Obj.getDXN(notebook).toString() : "";
|
|
567
|
+
const { hasAttention } = useAttention(attendableId);
|
|
568
|
+
const graph = useMemo(() => notebook && new ComputeGraph(notebook), [
|
|
569
|
+
notebook
|
|
570
|
+
]);
|
|
571
|
+
const [queryValues, setQueryValues] = useState({});
|
|
572
|
+
const handleExecQueries = useCallback(async () => {
|
|
573
|
+
invariant2(space, void 0, {
|
|
574
|
+
F: __dxlog_file3,
|
|
575
|
+
L: 56,
|
|
576
|
+
S: void 0,
|
|
577
|
+
A: [
|
|
578
|
+
"space",
|
|
579
|
+
""
|
|
580
|
+
]
|
|
581
|
+
});
|
|
582
|
+
const builder = new QueryBuilder();
|
|
583
|
+
for (const cell of notebook?.cells ?? []) {
|
|
584
|
+
if (cell.type === "query") {
|
|
585
|
+
if (cell.source?.target) {
|
|
586
|
+
const source = cell.source.target.content;
|
|
587
|
+
const { name, filter } = builder.build(source);
|
|
588
|
+
if (filter) {
|
|
589
|
+
const ast = Query.select(filter).ast;
|
|
590
|
+
const graph2 = cell.graph?.target;
|
|
591
|
+
if (!graph2) {
|
|
592
|
+
const { view } = await View.makeFromSpace({
|
|
593
|
+
space
|
|
594
|
+
});
|
|
595
|
+
const graph3 = Graph.make({
|
|
596
|
+
query: {
|
|
597
|
+
ast
|
|
598
|
+
},
|
|
599
|
+
view
|
|
600
|
+
});
|
|
601
|
+
cell.graph = Ref.make(graph3);
|
|
602
|
+
cell.name = name;
|
|
603
|
+
} else {
|
|
604
|
+
graph2.query.ast = ast;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
if (cell.name && cell.graph?.target) {
|
|
609
|
+
const graph2 = Obj.getSnapshot(cell.graph?.target);
|
|
610
|
+
const query = Query.fromAst(graph2.query.ast);
|
|
611
|
+
const result = await space?.db.query(query).run();
|
|
612
|
+
const objectIds = result?.objects?.map((obj) => obj.id);
|
|
613
|
+
setQueryValues((prev) => ({
|
|
614
|
+
...prev,
|
|
615
|
+
[cell.name]: objectIds
|
|
616
|
+
}));
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
}, [
|
|
621
|
+
space,
|
|
622
|
+
notebook,
|
|
623
|
+
graph
|
|
624
|
+
]);
|
|
625
|
+
const [promptResults, setPromptResults] = useState({});
|
|
626
|
+
const handleExecPrompts = useComputeRuntimeCallback(space, Effect.fnUntraced(function* () {
|
|
627
|
+
invariant2(graph, void 0, {
|
|
628
|
+
F: __dxlog_file3,
|
|
629
|
+
L: 93,
|
|
630
|
+
S: this,
|
|
631
|
+
A: [
|
|
632
|
+
"graph",
|
|
633
|
+
""
|
|
634
|
+
]
|
|
635
|
+
});
|
|
636
|
+
const prompts = notebook?.cells.filter((cell) => cell.type === "prompt").map((cell) => cell.prompt).filter(isNonNullable) ?? [];
|
|
637
|
+
for (const prompt of prompts) {
|
|
638
|
+
yield* runPrompt({
|
|
639
|
+
prompt,
|
|
640
|
+
input: {
|
|
641
|
+
...queryValues,
|
|
642
|
+
...graph.valuesByName.value
|
|
643
|
+
},
|
|
644
|
+
onResult: (result) => setPromptResults((prev) => ({
|
|
645
|
+
...prev,
|
|
646
|
+
[prompt.dxn.toString()]: result
|
|
647
|
+
}))
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
}), [
|
|
651
|
+
notebook,
|
|
652
|
+
graph,
|
|
653
|
+
queryValues
|
|
654
|
+
]);
|
|
655
|
+
const handleCompute = useCallback(async () => {
|
|
656
|
+
await graph?.evaluate();
|
|
657
|
+
await handleExecQueries();
|
|
658
|
+
await handleExecPrompts();
|
|
659
|
+
}, [
|
|
660
|
+
graph,
|
|
661
|
+
handleExecQueries,
|
|
662
|
+
handleExecPrompts
|
|
663
|
+
]);
|
|
664
|
+
const handleRearrange = useCallback((source, target) => {
|
|
665
|
+
invariant2(notebook, void 0, {
|
|
666
|
+
F: __dxlog_file3,
|
|
667
|
+
L: 126,
|
|
668
|
+
S: void 0,
|
|
669
|
+
A: [
|
|
670
|
+
"notebook",
|
|
671
|
+
""
|
|
672
|
+
]
|
|
673
|
+
});
|
|
674
|
+
const from = notebook.cells.findIndex((cell) => cell.id === source.id);
|
|
675
|
+
const to = notebook.cells.findIndex((cell) => cell.id === target.id);
|
|
676
|
+
if (from != null && to != null) {
|
|
677
|
+
const cell = notebook.cells.splice(from, 1)[0];
|
|
678
|
+
if (cell) {
|
|
679
|
+
notebook.cells.splice(to, 0, cell);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
}, [
|
|
683
|
+
notebook
|
|
684
|
+
]);
|
|
685
|
+
const handleCellInsert = useCallback(async (type, after) => {
|
|
686
|
+
invariant2(notebook, void 0, {
|
|
687
|
+
F: __dxlog_file3,
|
|
688
|
+
L: 141,
|
|
689
|
+
S: void 0,
|
|
690
|
+
A: [
|
|
691
|
+
"notebook",
|
|
692
|
+
""
|
|
693
|
+
]
|
|
694
|
+
});
|
|
695
|
+
const cell = {
|
|
696
|
+
id: crypto.randomUUID(),
|
|
697
|
+
type
|
|
698
|
+
};
|
|
699
|
+
switch (type) {
|
|
700
|
+
case "markdown":
|
|
701
|
+
case "script":
|
|
702
|
+
case "query": {
|
|
703
|
+
cell.source = Ref.make(Text.make());
|
|
704
|
+
break;
|
|
705
|
+
}
|
|
706
|
+
case "prompt": {
|
|
707
|
+
if (space) {
|
|
708
|
+
const result = await space.db.query(Query.select(Filter.type(Blueprint.Blueprint))).run();
|
|
709
|
+
const blueprints = result.objects.filter((blueprint) => INCLUDE_BLUEPRINTS.includes(blueprint.key)).map((blueprint) => Ref.make(blueprint));
|
|
710
|
+
cell.prompt = Ref.make(Prompt.make({
|
|
711
|
+
instructions: "",
|
|
712
|
+
blueprints
|
|
713
|
+
}));
|
|
714
|
+
}
|
|
715
|
+
break;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
const idx = after ? notebook.cells.findIndex((cell2) => cell2.id === after) : notebook.cells.length;
|
|
719
|
+
notebook.cells.splice(idx, 0, cell);
|
|
720
|
+
}, [
|
|
721
|
+
space,
|
|
722
|
+
notebook
|
|
723
|
+
]);
|
|
724
|
+
const handleCellDelete = useCallback((id) => {
|
|
725
|
+
invariant2(notebook, void 0, {
|
|
726
|
+
F: __dxlog_file3,
|
|
727
|
+
L: 171,
|
|
728
|
+
S: void 0,
|
|
729
|
+
A: [
|
|
730
|
+
"notebook",
|
|
731
|
+
""
|
|
732
|
+
]
|
|
733
|
+
});
|
|
734
|
+
const idx = notebook.cells.findIndex((cell) => cell.id === id);
|
|
735
|
+
if (idx !== -1) {
|
|
736
|
+
notebook.cells.splice(idx, 1);
|
|
737
|
+
}
|
|
738
|
+
}, [
|
|
739
|
+
notebook
|
|
740
|
+
]);
|
|
741
|
+
return /* @__PURE__ */ React.createElement(StackItem.Content, {
|
|
742
|
+
toolbar: true
|
|
743
|
+
}, /* @__PURE__ */ React.createElement(Toolbar.Root, {
|
|
744
|
+
disabled: !hasAttention,
|
|
745
|
+
textBlockWidth: true
|
|
746
|
+
}, /* @__PURE__ */ React.createElement(DropdownMenu.Root, null, /* @__PURE__ */ React.createElement(DropdownMenu.Trigger, {
|
|
747
|
+
asChild: true
|
|
748
|
+
}, /* @__PURE__ */ React.createElement(IconButton, {
|
|
749
|
+
icon: "ph--plus--regular",
|
|
750
|
+
iconOnly: true,
|
|
751
|
+
label: t("notebook cell insert label")
|
|
752
|
+
})), /* @__PURE__ */ React.createElement(NotebookMenu, {
|
|
753
|
+
onCellInsert: handleCellInsert
|
|
754
|
+
})), /* @__PURE__ */ React.createElement(Toolbar.IconButton, {
|
|
755
|
+
icon: "ph--play--fill",
|
|
756
|
+
iconOnly: true,
|
|
757
|
+
label: t("compute label"),
|
|
758
|
+
classNames: "text-green-500",
|
|
759
|
+
onClick: handleCompute
|
|
760
|
+
})), /* @__PURE__ */ React.createElement("div", {
|
|
761
|
+
role: "none",
|
|
762
|
+
className: "flex bs-full overflow-hidden -mis-[1px] -mie-[1px]"
|
|
763
|
+
}, /* @__PURE__ */ React.createElement(NotebookStack, {
|
|
764
|
+
classNames: "container-max-width border-l border-r border-subduedSeparator",
|
|
765
|
+
space,
|
|
766
|
+
notebook,
|
|
767
|
+
graph,
|
|
768
|
+
env,
|
|
769
|
+
promptResults,
|
|
770
|
+
onRearrange: handleRearrange,
|
|
771
|
+
onCellInsert: handleCellInsert,
|
|
772
|
+
onCellDelete: handleCellDelete
|
|
773
|
+
})));
|
|
774
|
+
} finally {
|
|
775
|
+
_effect.f();
|
|
776
|
+
}
|
|
777
|
+
};
|
|
778
|
+
var NotebookContainer_default = NotebookContainer;
|
|
779
|
+
var runPrompt = Effect.fn(function* ({ prompt, input, onResult }) {
|
|
780
|
+
const inputData = {
|
|
781
|
+
prompt,
|
|
782
|
+
input
|
|
783
|
+
};
|
|
784
|
+
const tracer = yield* InvocationTracer;
|
|
785
|
+
const trace = yield* tracer.traceInvocationStart({
|
|
786
|
+
target: void 0,
|
|
787
|
+
payload: {
|
|
788
|
+
data: {}
|
|
789
|
+
}
|
|
790
|
+
});
|
|
791
|
+
const result = yield* FunctionInvocationService.invokeFunction(Agent.prompt, inputData).pipe(Effect.provide(TracingServiceExt.layerQueue(trace.invocationTraceQueue)), Effect.exit);
|
|
792
|
+
Exit.match(result, {
|
|
793
|
+
onFailure: (cause) => {
|
|
794
|
+
const error = Cause.prettyErrors(cause)[0];
|
|
795
|
+
log2.error(error.message, error.cause ?? error.stack, {
|
|
796
|
+
F: __dxlog_file3,
|
|
797
|
+
L: 247,
|
|
798
|
+
S: this,
|
|
799
|
+
C: (f, a) => f(...a)
|
|
800
|
+
});
|
|
801
|
+
onResult(error.message);
|
|
802
|
+
},
|
|
803
|
+
onSuccess: (result2) => {
|
|
804
|
+
onResult(result2.note);
|
|
805
|
+
}
|
|
806
|
+
});
|
|
807
|
+
yield* tracer.traceInvocationEnd({
|
|
808
|
+
trace,
|
|
809
|
+
// TODO(dmaretskyi): Might miss errors.
|
|
810
|
+
exception: Exit.isFailure(result) ? Cause.prettyErrors(result.cause)[0] : void 0
|
|
811
|
+
});
|
|
812
|
+
});
|
|
813
|
+
export {
|
|
814
|
+
NotebookContainer,
|
|
815
|
+
NotebookContainer_default as default
|
|
816
|
+
};
|
|
817
|
+
//# sourceMappingURL=NotebookContainer-MHY3DXDE.mjs.map
|