@dxos/plugin-script 0.10.0 → 0.11.0
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/ScriptPlugin.mjs +25 -0
- package/dist/lib/ScriptPlugin.mjs.map +1 -0
- package/dist/lib/ScriptPlugin.node.mjs +11 -0
- package/dist/lib/ScriptPlugin.node.mjs.map +1 -0
- package/dist/lib/ScriptPlugin.workerd.mjs +11 -0
- package/dist/lib/ScriptPlugin.workerd.mjs.map +1 -0
- package/dist/lib/capabilities/node.mjs +11 -0
- package/dist/lib/capabilities/node.mjs.map +1 -0
- package/dist/lib/capabilities.mjs +13 -0
- package/dist/lib/capabilities.mjs.map +1 -0
- package/dist/lib/chunk-DeploymentDialog.mjs +85 -0
- package/dist/lib/chunk-DeploymentDialog.mjs.map +1 -0
- package/dist/lib/chunk-NotebookArticle.mjs +719 -0
- package/dist/lib/chunk-NotebookArticle.mjs.map +1 -0
- package/dist/lib/chunk-ScriptArticle.mjs +67 -0
- package/dist/lib/chunk-ScriptArticle.mjs.map +1 -0
- package/dist/lib/chunk-ScriptProperties.mjs +240 -0
- package/dist/lib/chunk-ScriptProperties.mjs.map +1 -0
- package/dist/lib/chunk-ScriptSettings.mjs +40 -0
- package/dist/lib/chunk-ScriptSettings.mjs.map +1 -0
- package/dist/lib/chunk-TestContainer.mjs +40 -0
- package/dist/lib/chunk-TestContainer.mjs.map +1 -0
- package/dist/lib/chunk-app-graph-builder.mjs +33 -0
- package/dist/lib/chunk-app-graph-builder.mjs.map +1 -0
- package/dist/lib/chunk-compiler.mjs +60 -0
- package/dist/lib/chunk-compiler.mjs.map +1 -0
- package/dist/lib/chunk-compiler2.mjs +76 -0
- package/dist/lib/chunk-compiler2.mjs.map +1 -0
- package/dist/lib/chunk-create-object.mjs +36 -0
- package/dist/lib/chunk-create-object.mjs.map +1 -0
- package/dist/lib/chunk-create-script.mjs +32 -0
- package/dist/lib/chunk-create-script.mjs.map +1 -0
- package/dist/lib/chunk-create.mjs +34 -0
- package/dist/lib/chunk-create.mjs.map +1 -0
- package/dist/lib/chunk-delete.mjs +15 -0
- package/dist/lib/chunk-delete.mjs.map +1 -0
- package/dist/lib/chunk-deploy.mjs +53 -0
- package/dist/lib/chunk-deploy.mjs.map +1 -0
- package/dist/lib/chunk-functions.mjs +238 -0
- package/dist/lib/chunk-functions.mjs.map +1 -0
- package/dist/lib/chunk-inspect-invocations.mjs +42 -0
- package/dist/lib/chunk-inspect-invocations.mjs.map +1 -0
- package/dist/lib/chunk-install-function.mjs +40 -0
- package/dist/lib/chunk-install-function.mjs.map +1 -0
- package/dist/lib/chunk-invoke.mjs +25 -0
- package/dist/lib/chunk-invoke.mjs.map +1 -0
- package/dist/lib/chunk-meta.mjs +33 -0
- package/dist/lib/chunk-meta.mjs.map +1 -0
- package/dist/lib/chunk-operation-handler.mjs +13 -0
- package/dist/lib/chunk-operation-handler.mjs.map +1 -0
- package/dist/lib/chunk-query-deployed-functions.mjs +31 -0
- package/dist/lib/chunk-query-deployed-functions.mjs.map +1 -0
- package/dist/lib/chunk-react-surface.mjs +140 -0
- package/dist/lib/chunk-react-surface.mjs.map +1 -0
- package/dist/lib/chunk-read.mjs +20 -0
- package/dist/lib/chunk-read.mjs.map +1 -0
- package/dist/lib/chunk-settings.mjs +23 -0
- package/dist/lib/chunk-settings.mjs.map +1 -0
- package/dist/lib/chunk-skill-definition.mjs +10 -0
- package/dist/lib/chunk-skill-definition.mjs.map +1 -0
- package/dist/lib/chunk-skills.mjs +35 -0
- package/dist/lib/chunk-skills.mjs.map +1 -0
- package/dist/lib/{neutral/chunk-WAGQ77UQ.mjs → chunk-templates.mjs} +82 -84
- package/dist/lib/chunk-templates.mjs.map +1 -0
- package/dist/lib/chunk-types.mjs +90 -0
- package/dist/lib/chunk-types.mjs.map +1 -0
- package/dist/lib/chunk-update.mjs +27 -0
- package/dist/lib/chunk-update.mjs.map +1 -0
- package/dist/lib/chunk-util.mjs +146 -0
- package/dist/lib/chunk-util.mjs.map +1 -0
- package/dist/lib/components.mjs +618 -0
- package/dist/lib/components.mjs.map +1 -0
- package/dist/lib/containers.mjs +12 -0
- package/dist/lib/containers.mjs.map +1 -0
- package/dist/lib/hooks.mjs +307 -0
- package/dist/lib/hooks.mjs.map +1 -0
- package/dist/lib/index.mjs +5 -0
- package/dist/lib/meta.mjs +2 -0
- package/dist/lib/operations.mjs +7 -0
- package/dist/lib/operations.mjs.map +1 -0
- package/dist/lib/plugin.mjs +9 -0
- package/dist/lib/plugin.mjs.map +1 -0
- package/dist/lib/skills.mjs +2 -0
- package/dist/lib/templates.mjs +2 -0
- package/dist/lib/testing.mjs +75 -0
- package/dist/lib/testing.mjs.map +1 -0
- package/dist/lib/translations.mjs +98 -0
- package/dist/lib/translations.mjs.map +1 -0
- package/dist/lib/types.mjs +2 -0
- package/dist/types/src/capabilities/ScriptSurfaces.d.ts +28 -0
- package/dist/types/src/capabilities/ScriptSurfaces.d.ts.map +1 -0
- package/dist/types/src/capabilities/app-graph-builder.d.ts +1 -1
- package/dist/types/src/capabilities/compiler.d.ts +1 -1
- package/dist/types/src/capabilities/create-object.d.ts +1 -1
- package/dist/types/src/capabilities/operation-handler.d.ts +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/capabilities/settings.d.ts +1 -1
- package/dist/types/src/components/NotebookStack/NotebookStack.d.ts +1 -1
- package/dist/types/src/components/NotebookStack/NotebookStack.d.ts.map +1 -1
- package/dist/types/src/components/NotebookStack/NotebookStack.stories.d.ts.map +1 -1
- package/dist/types/src/components/QueryEditor/QueryEditor.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts.map +1 -1
- package/dist/types/src/components/TestPanel/TestPanel.d.ts +1 -1
- package/dist/types/src/components/TestPanel/TestPanel.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts +1 -1
- package/dist/types/src/containers/DeploymentDialog/DeploymentDialog.d.ts +5 -2
- package/dist/types/src/containers/DeploymentDialog/DeploymentDialog.d.ts.map +1 -1
- package/dist/types/src/containers/NotebookArticle/NotebookArticle.d.ts +4 -1
- package/dist/types/src/containers/NotebookArticle/NotebookArticle.d.ts.map +1 -1
- package/dist/types/src/containers/ScriptArticle/ScriptArticle.d.ts +4 -1
- package/dist/types/src/containers/ScriptArticle/ScriptArticle.d.ts.map +1 -1
- package/dist/types/src/containers/ScriptArticle/ScriptArticle.stories.d.ts.map +1 -1
- package/dist/types/src/containers/ScriptProperties/FunctionBinding.d.ts +4 -1
- package/dist/types/src/containers/ScriptProperties/FunctionBinding.d.ts.map +1 -1
- package/dist/types/src/containers/ScriptProperties/FunctionPublishing.d.ts +4 -1
- package/dist/types/src/containers/ScriptProperties/FunctionPublishing.d.ts.map +1 -1
- package/dist/types/src/containers/ScriptProperties/ScriptProperties.d.ts +4 -1
- package/dist/types/src/containers/ScriptProperties/ScriptProperties.d.ts.map +1 -1
- package/dist/types/src/containers/ScriptProperties/ScriptProperties.stories.d.ts.map +1 -1
- package/dist/types/src/containers/ScriptProperties/SkillEditor.d.ts +4 -1
- package/dist/types/src/containers/ScriptProperties/SkillEditor.d.ts.map +1 -1
- package/dist/types/src/containers/ScriptSettings/ScriptSettings.d.ts +4 -1
- package/dist/types/src/containers/ScriptSettings/ScriptSettings.d.ts.map +1 -1
- package/dist/types/src/containers/ScriptSettings/ScriptSettings.stories.d.ts +4 -1
- package/dist/types/src/containers/ScriptSettings/ScriptSettings.stories.d.ts.map +1 -1
- package/dist/types/src/containers/TestContainer/TestContainer.d.ts +4 -1
- package/dist/types/src/containers/TestContainer/TestContainer.d.ts.map +1 -1
- package/dist/types/src/hooks/deploy.d.ts +2 -35
- package/dist/types/src/hooks/deploy.d.ts.map +1 -1
- package/dist/types/src/hooks/format.d.ts +2 -23
- package/dist/types/src/hooks/format.d.ts.map +1 -1
- package/dist/types/src/hooks/template.d.ts +2 -18
- package/dist/types/src/hooks/template.d.ts.map +1 -1
- package/dist/types/src/hooks/useToolbarState.d.ts +1 -1
- package/dist/types/src/hooks/useToolbarState.d.ts.map +1 -1
- package/dist/types/src/notebook/compute-graph.d.ts +1 -1
- package/dist/types/src/notebook/compute-graph.d.ts.map +1 -1
- package/dist/types/src/skills/functions/deploy.d.ts.map +1 -1
- package/dist/types/src/skills/functions/inspect-invocations.d.ts.map +1 -1
- package/dist/types/src/templates/chess-bot.d.ts +2 -2
- package/dist/types/src/templates/chess-bot.d.ts.map +1 -1
- package/dist/types/src/templates/commentary.d.ts +2 -2
- package/dist/types/src/templates/commentary.d.ts.map +1 -1
- package/dist/types/src/types/ScriptCapabilities.d.ts +1 -1
- package/dist/types/src/types/ScriptCapabilities.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +88 -82
- package/src/capabilities/ScriptSurfaces.tsx +96 -0
- package/src/capabilities/app-graph-builder.ts +2 -2
- package/src/capabilities/compiler.ts +1 -1
- package/src/capabilities/react-surface.ts +82 -0
- package/src/components/NotebookStack/NotebookCell.tsx +9 -2
- package/src/components/NotebookStack/NotebookStack.stories.tsx +2 -0
- package/src/components/NotebookStack/NotebookStack.tsx +22 -14
- package/src/components/QueryEditor/QueryEditor.stories.tsx +1 -1
- package/src/components/QueryEditor/QueryEditor.tsx +1 -0
- package/src/components/ScriptToolbar/ScriptToolbar.stories.tsx +1 -1
- package/src/components/ScriptToolbar/ScriptToolbar.tsx +1 -1
- package/src/components/TestPanel/TestPanel.tsx +2 -2
- package/src/components/TypescriptEditor/TypescriptEditor.tsx +1 -1
- package/src/containers/DeploymentDialog/DeploymentDialog.stories.tsx +1 -1
- package/src/containers/DeploymentDialog/DeploymentDialog.tsx +3 -1
- package/src/containers/NotebookArticle/NotebookArticle.stories.tsx +1 -1
- package/src/containers/NotebookArticle/NotebookArticle.tsx +4 -2
- package/src/containers/ScriptArticle/ScriptArticle.stories.tsx +2 -1
- package/src/containers/ScriptArticle/ScriptArticle.tsx +3 -1
- package/src/containers/ScriptProperties/FunctionBinding.tsx +5 -3
- package/src/containers/ScriptProperties/FunctionPublishing.tsx +4 -2
- package/src/containers/ScriptProperties/ScriptProperties.stories.tsx +2 -1
- package/src/containers/ScriptProperties/ScriptProperties.tsx +2 -0
- package/src/containers/ScriptProperties/SkillEditor.tsx +3 -1
- package/src/containers/ScriptSettings/ScriptSettings.tsx +2 -0
- package/src/containers/TestContainer/TestContainer.tsx +4 -2
- package/src/e2e/ai.test.ts +2 -2
- package/src/e2e/deploy.test.ts +2 -2
- package/src/hooks/deploy.ts +13 -4
- package/src/hooks/format.ts +2 -2
- package/src/hooks/template.ts +3 -3
- package/src/hooks/useToolbarState.ts +1 -1
- package/src/notebook/compute-graph.test.ts +1 -1
- package/src/notebook/compute-graph.ts +1 -1
- package/src/skills/functions/deploy.ts +5 -6
- package/src/skills/functions/inspect-invocations.ts +2 -2
- package/src/skills/functions/install-function.ts +1 -1
- package/src/skills/functions/invoke.ts +1 -1
- package/src/skills/functions/query-deployed-functions.ts +1 -1
- package/src/templates/chess-bot.ts +3 -3
- package/src/templates/commentary.ts +3 -3
- package/src/testing/simulator.test.ts +1 -1
- package/src/types/ScriptCapabilities.ts +1 -1
- package/src/util/deploy.ts +3 -3
- package/src/util/functions.ts +2 -2
- package/dist/lib/neutral/DeploymentDialog-7OIIL7LB.mjs +0 -114
- package/dist/lib/neutral/DeploymentDialog-7OIIL7LB.mjs.map +0 -7
- package/dist/lib/neutral/NotebookArticle-AOBB3XGD.mjs +0 -745
- package/dist/lib/neutral/NotebookArticle-AOBB3XGD.mjs.map +0 -7
- package/dist/lib/neutral/ScriptArticle-I3DOJARR.mjs +0 -79
- package/dist/lib/neutral/ScriptArticle-I3DOJARR.mjs.map +0 -7
- package/dist/lib/neutral/ScriptPlugin.mjs +0 -51
- package/dist/lib/neutral/ScriptPlugin.mjs.map +0 -7
- package/dist/lib/neutral/ScriptPlugin.node.mjs +0 -27
- package/dist/lib/neutral/ScriptPlugin.node.mjs.map +0 -7
- package/dist/lib/neutral/ScriptPlugin.workerd.mjs +0 -21
- package/dist/lib/neutral/ScriptPlugin.workerd.mjs.map +0 -7
- package/dist/lib/neutral/ScriptProperties-RHDQGMGT.mjs +0 -296
- package/dist/lib/neutral/ScriptProperties-RHDQGMGT.mjs.map +0 -7
- package/dist/lib/neutral/ScriptSettings-NS3ZY7ZR.mjs +0 -35
- package/dist/lib/neutral/ScriptSettings-NS3ZY7ZR.mjs.map +0 -7
- package/dist/lib/neutral/TestContainer-AFVTBYSJ.mjs +0 -44
- package/dist/lib/neutral/TestContainer-AFVTBYSJ.mjs.map +0 -7
- package/dist/lib/neutral/app-graph-builder-POP3CX6G.mjs +0 -52
- package/dist/lib/neutral/app-graph-builder-POP3CX6G.mjs.map +0 -7
- package/dist/lib/neutral/capabilities/index.mjs +0 -21
- package/dist/lib/neutral/capabilities/index.mjs.map +0 -7
- package/dist/lib/neutral/capabilities/node.mjs +0 -17
- package/dist/lib/neutral/capabilities/node.mjs.map +0 -7
- package/dist/lib/neutral/chunk-2REUEDUA.mjs +0 -56
- package/dist/lib/neutral/chunk-2REUEDUA.mjs.map +0 -7
- package/dist/lib/neutral/chunk-652CIABA.mjs +0 -124
- package/dist/lib/neutral/chunk-652CIABA.mjs.map +0 -7
- package/dist/lib/neutral/chunk-6DOWVKIW.mjs +0 -344
- package/dist/lib/neutral/chunk-6DOWVKIW.mjs.map +0 -7
- package/dist/lib/neutral/chunk-CHNFYLKW.mjs +0 -52
- package/dist/lib/neutral/chunk-CHNFYLKW.mjs.map +0 -7
- package/dist/lib/neutral/chunk-INFWOSTM.mjs +0 -156
- package/dist/lib/neutral/chunk-INFWOSTM.mjs.map +0 -7
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +0 -10
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +0 -7
- package/dist/lib/neutral/chunk-KSVKXCTX.mjs +0 -8
- package/dist/lib/neutral/chunk-KSVKXCTX.mjs.map +0 -7
- package/dist/lib/neutral/chunk-NVV5UYY4.mjs +0 -50
- package/dist/lib/neutral/chunk-NVV5UYY4.mjs.map +0 -7
- package/dist/lib/neutral/chunk-USJ44FIU.mjs +0 -8
- package/dist/lib/neutral/chunk-USJ44FIU.mjs.map +0 -7
- package/dist/lib/neutral/chunk-WAGQ77UQ.mjs.map +0 -7
- package/dist/lib/neutral/compiler-ODK4UA2N.mjs +0 -101
- package/dist/lib/neutral/compiler-ODK4UA2N.mjs.map +0 -7
- package/dist/lib/neutral/components/index.mjs +0 -695
- package/dist/lib/neutral/components/index.mjs.map +0 -7
- package/dist/lib/neutral/containers/index.mjs +0 -19
- package/dist/lib/neutral/containers/index.mjs.map +0 -7
- package/dist/lib/neutral/create-SGHWWTET.mjs +0 -46
- package/dist/lib/neutral/create-SGHWWTET.mjs.map +0 -7
- package/dist/lib/neutral/create-object-QW66KQWS.mjs +0 -43
- package/dist/lib/neutral/create-object-QW66KQWS.mjs.map +0 -7
- package/dist/lib/neutral/create-script-CIEJOBIU.mjs +0 -45
- package/dist/lib/neutral/create-script-CIEJOBIU.mjs.map +0 -7
- package/dist/lib/neutral/delete-72RXVLVI.mjs +0 -21
- package/dist/lib/neutral/delete-72RXVLVI.mjs.map +0 -7
- package/dist/lib/neutral/deploy-PJTJAQZY.mjs +0 -67
- package/dist/lib/neutral/deploy-PJTJAQZY.mjs.map +0 -7
- package/dist/lib/neutral/hooks/index.mjs +0 -369
- package/dist/lib/neutral/hooks/index.mjs.map +0 -7
- package/dist/lib/neutral/index.mjs +0 -41
- package/dist/lib/neutral/index.mjs.map +0 -7
- package/dist/lib/neutral/inspect-invocations-ZUXVUAML.mjs +0 -59
- package/dist/lib/neutral/inspect-invocations-ZUXVUAML.mjs.map +0 -7
- package/dist/lib/neutral/install-function-YFDZLVMJ.mjs +0 -49
- package/dist/lib/neutral/install-function-YFDZLVMJ.mjs.map +0 -7
- package/dist/lib/neutral/invoke-CDRBQ2WA.mjs +0 -32
- package/dist/lib/neutral/invoke-CDRBQ2WA.mjs.map +0 -7
- package/dist/lib/neutral/meta.json +0 -1
- package/dist/lib/neutral/meta.mjs +0 -10
- package/dist/lib/neutral/meta.mjs.map +0 -7
- package/dist/lib/neutral/operation-handler-M3B6IRMV.mjs +0 -18
- package/dist/lib/neutral/operation-handler-M3B6IRMV.mjs.map +0 -7
- package/dist/lib/neutral/operations/index.mjs +0 -8
- package/dist/lib/neutral/operations/index.mjs.map +0 -7
- package/dist/lib/neutral/plugin.mjs +0 -16
- package/dist/lib/neutral/plugin.mjs.map +0 -7
- package/dist/lib/neutral/query-deployed-functions-RBQMGON2.mjs +0 -34
- package/dist/lib/neutral/query-deployed-functions-RBQMGON2.mjs.map +0 -7
- package/dist/lib/neutral/react-surface-GEXOZLBC.mjs +0 -120
- package/dist/lib/neutral/react-surface-GEXOZLBC.mjs.map +0 -7
- package/dist/lib/neutral/read-OY3K5R3V.mjs +0 -26
- package/dist/lib/neutral/read-OY3K5R3V.mjs.map +0 -7
- package/dist/lib/neutral/settings-FD7HXEY6.mjs +0 -30
- package/dist/lib/neutral/settings-FD7HXEY6.mjs.map +0 -7
- package/dist/lib/neutral/skill-definition-JZ7UYBT7.mjs +0 -15
- package/dist/lib/neutral/skill-definition-JZ7UYBT7.mjs.map +0 -7
- package/dist/lib/neutral/skills/index.mjs +0 -10
- package/dist/lib/neutral/skills/index.mjs.map +0 -7
- package/dist/lib/neutral/templates/index.mjs +0 -10
- package/dist/lib/neutral/templates/index.mjs.map +0 -7
- package/dist/lib/neutral/translations.mjs +0 -104
- package/dist/lib/neutral/translations.mjs.map +0 -7
- package/dist/lib/neutral/types/index.mjs +0 -17
- package/dist/lib/neutral/types/index.mjs.map +0 -7
- package/dist/lib/neutral/update-Z5VGOLBN.mjs +0 -44
- package/dist/lib/neutral/update-Z5VGOLBN.mjs.map +0 -7
- package/src/capabilities/react-surface.tsx +0 -132
|
@@ -0,0 +1,719 @@
|
|
|
1
|
+
import { Instructions, Operation, Skill } from "@dxos/compute";
|
|
2
|
+
import { isNonNullable, trim } from "@dxos/util";
|
|
3
|
+
import { Filter, Obj, Query, Ref } from "@dxos/echo";
|
|
4
|
+
import { Graph } from "@dxos/plugin-explorer";
|
|
5
|
+
import { Text, ViewModel } from "@dxos/schema";
|
|
6
|
+
import { meta } from "#meta";
|
|
7
|
+
import { log } from "@dxos/log";
|
|
8
|
+
import { useCallback, useContext, useMemo, useState } from "react";
|
|
9
|
+
import { DropdownMenu, IconButton, Panel, Toolbar, useTranslation } from "@dxos/react-ui";
|
|
10
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { useSpaceCallback } from "@dxos/app-framework/ui";
|
|
12
|
+
import { invariant } from "@dxos/invariant";
|
|
13
|
+
import ts from "typescript";
|
|
14
|
+
import { createSystem, createVirtualTypeScriptEnvironment } from "@typescript/vfs";
|
|
15
|
+
import { Atom } from "@effect-atom/atom";
|
|
16
|
+
import * as Effect from "effect/Effect";
|
|
17
|
+
import { RegistryContext } from "@effect-atom/atom-react";
|
|
18
|
+
import * as Cause from "effect/Cause";
|
|
19
|
+
import * as Exit from "effect/Exit";
|
|
20
|
+
import { RunInstructions } from "@dxos/assistant-toolkit";
|
|
21
|
+
import { QueryBuilder } from "@dxos/echo-query";
|
|
22
|
+
import { useAttention } from "@dxos/react-ui-attention";
|
|
23
|
+
import { NotebookMenu, NotebookStack } from "#components";
|
|
24
|
+
//#region src/notebook/eval.ts
|
|
25
|
+
/**
|
|
26
|
+
* Evaluate the script (with dependencies as arguments).
|
|
27
|
+
*/
|
|
28
|
+
var evalScript = async (code, deps = {}) => {
|
|
29
|
+
const sandbox = {
|
|
30
|
+
...deps,
|
|
31
|
+
console: void 0,
|
|
32
|
+
document: void 0,
|
|
33
|
+
global: void 0,
|
|
34
|
+
globalThis: void 0,
|
|
35
|
+
self: void 0,
|
|
36
|
+
window: void 0,
|
|
37
|
+
Array,
|
|
38
|
+
Boolean,
|
|
39
|
+
Date,
|
|
40
|
+
Error,
|
|
41
|
+
JSON,
|
|
42
|
+
Map,
|
|
43
|
+
Math,
|
|
44
|
+
Number,
|
|
45
|
+
Object,
|
|
46
|
+
Promise,
|
|
47
|
+
RegExp,
|
|
48
|
+
Set,
|
|
49
|
+
String,
|
|
50
|
+
isFinite,
|
|
51
|
+
isNaN,
|
|
52
|
+
parseFloat,
|
|
53
|
+
parseInt
|
|
54
|
+
};
|
|
55
|
+
const sandboxKeys = Object.keys(sandbox);
|
|
56
|
+
const sandboxValues = Object.values(sandbox);
|
|
57
|
+
return new Function(...sandboxKeys, trim`
|
|
58
|
+
'use strict';
|
|
59
|
+
return ${code};
|
|
60
|
+
`)(...sandboxValues);
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Globals.
|
|
64
|
+
*/
|
|
65
|
+
var builtIns = /* @__PURE__ */ new Set([
|
|
66
|
+
"Array",
|
|
67
|
+
"Date",
|
|
68
|
+
"Error",
|
|
69
|
+
"JSON",
|
|
70
|
+
"Map",
|
|
71
|
+
"Math",
|
|
72
|
+
"Number",
|
|
73
|
+
"Object",
|
|
74
|
+
"Promise",
|
|
75
|
+
"RegExp",
|
|
76
|
+
"Set",
|
|
77
|
+
"String",
|
|
78
|
+
"isFinite",
|
|
79
|
+
"isNaN",
|
|
80
|
+
"parseFloat",
|
|
81
|
+
"parseInt"
|
|
82
|
+
]);
|
|
83
|
+
/**
|
|
84
|
+
* Default system definitions.
|
|
85
|
+
*/
|
|
86
|
+
var systemDefinitions = trim`
|
|
87
|
+
interface Array<T> { length: number; [n: number]: T; }
|
|
88
|
+
interface Boolean {}
|
|
89
|
+
interface Function {}
|
|
90
|
+
interface IArguments {}
|
|
91
|
+
interface Number {}
|
|
92
|
+
interface Object {}
|
|
93
|
+
interface RegExp {}
|
|
94
|
+
interface String { length: number; }
|
|
95
|
+
|
|
96
|
+
interface CallableFunction extends Function {}
|
|
97
|
+
interface NewableFunction extends Function {}
|
|
98
|
+
|
|
99
|
+
declare var console: { log(...args: any[]): void };
|
|
100
|
+
`;
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/notebook/vfs-parser.ts
|
|
103
|
+
var __dxlog_file$2 = "/__w/dxos/dxos/packages/plugins/plugin-script/src/notebook/vfs-parser.ts";
|
|
104
|
+
/**
|
|
105
|
+
* Default system definitions.
|
|
106
|
+
*/
|
|
107
|
+
var systemFiles = [{
|
|
108
|
+
filename: "/lib.d.ts",
|
|
109
|
+
content: systemDefinitions
|
|
110
|
+
}];
|
|
111
|
+
/**
|
|
112
|
+
* TypeScript parser using Virtual File System for browser compatibility.
|
|
113
|
+
* This provides full TypeScript analysis including type information.
|
|
114
|
+
*/
|
|
115
|
+
var VirtualTypeScriptParser = class {
|
|
116
|
+
compilerOptions = {
|
|
117
|
+
target: ts.ScriptTarget.ES2020,
|
|
118
|
+
module: ts.ModuleKind.ESNext,
|
|
119
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
120
|
+
strict: true,
|
|
121
|
+
esModuleInterop: true,
|
|
122
|
+
skipLibCheck: true,
|
|
123
|
+
forceConsistentCasingInfilenames: true,
|
|
124
|
+
jsx: ts.JsxEmit.React,
|
|
125
|
+
noLib: true
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Parse a single expression or statement.
|
|
129
|
+
*/
|
|
130
|
+
parseExpression(input) {
|
|
131
|
+
invariant(input.trim() !== "", "input must not be empty", {
|
|
132
|
+
"~LogMeta": "~LogMeta",
|
|
133
|
+
F: __dxlog_file$2,
|
|
134
|
+
L: 58,
|
|
135
|
+
S: this,
|
|
136
|
+
A: ["input.trim() !== ''", "'input must not be empty'"]
|
|
137
|
+
});
|
|
138
|
+
const files = [{
|
|
139
|
+
filename: "/temp.ts",
|
|
140
|
+
content: input
|
|
141
|
+
}];
|
|
142
|
+
const analysis = this.analyzeFiles(files);
|
|
143
|
+
if (analysis.length === 0) {
|
|
144
|
+
const sourcefilename = "/temp.ts";
|
|
145
|
+
const env = this.createEnvironment([{
|
|
146
|
+
filename: sourcefilename,
|
|
147
|
+
content: input
|
|
148
|
+
}]);
|
|
149
|
+
const sourceFile = env.getSourceFile(sourcefilename);
|
|
150
|
+
const typeChecker = env.languageService.getProgram()?.getTypeChecker();
|
|
151
|
+
if (sourceFile && typeChecker) {
|
|
152
|
+
const assignmentInfo = this.findAssignmentExpression(sourceFile, typeChecker);
|
|
153
|
+
if (assignmentInfo) return assignmentInfo;
|
|
154
|
+
return { references: this.findAllReferences(sourceFile, typeChecker) };
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return analysis[0];
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Analyze multiple files with full type information.
|
|
161
|
+
*/
|
|
162
|
+
analyzeFiles(files) {
|
|
163
|
+
const env = this.createEnvironment(files);
|
|
164
|
+
const results = [];
|
|
165
|
+
const typeChecker = env.languageService.getProgram()?.getTypeChecker();
|
|
166
|
+
files.forEach((file) => {
|
|
167
|
+
const sourceFile = env.getSourceFile(file.filename);
|
|
168
|
+
if (!sourceFile || !typeChecker) return;
|
|
169
|
+
const fileResults = this.analyzeSourceFile(sourceFile, typeChecker);
|
|
170
|
+
results.push(...fileResults);
|
|
171
|
+
});
|
|
172
|
+
return results;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Analyze a source file with type information.
|
|
176
|
+
*/
|
|
177
|
+
analyzeSourceFile(sourceFile, typeChecker) {
|
|
178
|
+
const results = [];
|
|
179
|
+
const visit = (node) => {
|
|
180
|
+
if (ts.isFunctionDeclaration(node) && node.name) {
|
|
181
|
+
const symbol = typeChecker.getSymbolAtLocation(node.name);
|
|
182
|
+
const type = symbol && typeChecker.getTypeOfSymbolAtLocation(symbol, node);
|
|
183
|
+
const signature = type && typeChecker.getSignaturesOfType(type, ts.SignatureKind.Call)[0];
|
|
184
|
+
results.push({
|
|
185
|
+
name: node.name.text,
|
|
186
|
+
type: "function",
|
|
187
|
+
parameters: this.extractParameters(signature, typeChecker),
|
|
188
|
+
returnType: signature ? typeChecker.typeToString(signature.getReturnType()) : "any",
|
|
189
|
+
references: this.findReferences(node, sourceFile, typeChecker)
|
|
190
|
+
});
|
|
191
|
+
} else if (ts.isVariableStatement(node)) node.declarationList.declarations.forEach((declaration) => {
|
|
192
|
+
if (ts.isIdentifier(declaration.name)) {
|
|
193
|
+
const symbol = typeChecker.getSymbolAtLocation(declaration.name);
|
|
194
|
+
const type = symbol && typeChecker.getTypeOfSymbolAtLocation(symbol, declaration);
|
|
195
|
+
let kind = "variable";
|
|
196
|
+
let parameters;
|
|
197
|
+
let returnType;
|
|
198
|
+
let value;
|
|
199
|
+
const typeString = type ? typeChecker.typeToString(type) : "any";
|
|
200
|
+
if (declaration.initializer) {
|
|
201
|
+
if (ts.isArrowFunction(declaration.initializer) || ts.isFunctionExpression(declaration.initializer)) {
|
|
202
|
+
kind = "function";
|
|
203
|
+
const funcType = typeChecker.getTypeAtLocation(declaration.initializer);
|
|
204
|
+
const signature = typeChecker.getSignaturesOfType(funcType, ts.SignatureKind.Call)[0];
|
|
205
|
+
if (signature) {
|
|
206
|
+
parameters = this.extractParameters(signature, typeChecker);
|
|
207
|
+
returnType = typeChecker.typeToString(signature.getReturnType());
|
|
208
|
+
}
|
|
209
|
+
} else if (ts.isNumericLiteral(declaration.initializer)) value = Number(declaration.initializer.text);
|
|
210
|
+
else if (ts.isStringLiteral(declaration.initializer)) value = declaration.initializer.text;
|
|
211
|
+
}
|
|
212
|
+
const refs = declaration.initializer ? this.findReferences(declaration.initializer, sourceFile, typeChecker) : [];
|
|
213
|
+
results.push({
|
|
214
|
+
name: declaration.name.text,
|
|
215
|
+
type: kind,
|
|
216
|
+
valueType: typeString,
|
|
217
|
+
value,
|
|
218
|
+
parameters,
|
|
219
|
+
returnType,
|
|
220
|
+
references: refs
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
else if (ts.isClassDeclaration(node) && node.name) results.push({
|
|
225
|
+
name: node.name.text,
|
|
226
|
+
type: "class",
|
|
227
|
+
references: this.findReferences(node, sourceFile, typeChecker)
|
|
228
|
+
});
|
|
229
|
+
else if (ts.isInterfaceDeclaration(node)) results.push({
|
|
230
|
+
name: node.name.text,
|
|
231
|
+
type: "interface",
|
|
232
|
+
references: this.findReferences(node, sourceFile, typeChecker)
|
|
233
|
+
});
|
|
234
|
+
ts.forEachChild(node, visit);
|
|
235
|
+
};
|
|
236
|
+
visit(sourceFile);
|
|
237
|
+
return results;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Extract parameter information from a signature.
|
|
241
|
+
*/
|
|
242
|
+
extractParameters(signature, typeChecker) {
|
|
243
|
+
if (!signature) return [];
|
|
244
|
+
return signature.parameters.map((param) => ({
|
|
245
|
+
name: param.getName(),
|
|
246
|
+
type: typeChecker.typeToString(typeChecker.getTypeOfSymbolAtLocation(param, param.valueDeclaration))
|
|
247
|
+
}));
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Find all references to variables used in a node.
|
|
251
|
+
*/
|
|
252
|
+
findReferences(node, _sourceFile, _typeChecker) {
|
|
253
|
+
const references = /* @__PURE__ */ new Set();
|
|
254
|
+
const localSymbols = /* @__PURE__ */ new Set();
|
|
255
|
+
const collectLocalSymbols = (node) => {
|
|
256
|
+
if (ts.isFunctionDeclaration(node) || ts.isArrowFunction(node) || ts.isFunctionExpression(node)) node.parameters.forEach((param) => {
|
|
257
|
+
if (ts.isIdentifier(param.name)) localSymbols.add(param.name.text);
|
|
258
|
+
});
|
|
259
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name)) localSymbols.add(node.name.text);
|
|
260
|
+
ts.forEachChild(node, collectLocalSymbols);
|
|
261
|
+
};
|
|
262
|
+
collectLocalSymbols(node);
|
|
263
|
+
const findRefs = (node) => {
|
|
264
|
+
if (ts.isIdentifier(node)) {
|
|
265
|
+
if (!localSymbols.has(node.text)) {
|
|
266
|
+
const parent = node.parent;
|
|
267
|
+
if (!(ts.isVariableDeclaration(parent) && parent.name === node || ts.isFunctionDeclaration(parent) && parent.name === node || ts.isParameter(parent) && parent.name === node) && !this.isBuiltIn(node.text)) references.add(node.text);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
ts.forEachChild(node, findRefs);
|
|
271
|
+
};
|
|
272
|
+
findRefs(node);
|
|
273
|
+
return Array.from(references);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Check if a name is a built-in global.
|
|
277
|
+
*/
|
|
278
|
+
isBuiltIn(name) {
|
|
279
|
+
return builtIns.has(name);
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Find assignment expressions in a source file.
|
|
283
|
+
*/
|
|
284
|
+
findAssignmentExpression(sourceFile, typeChecker) {
|
|
285
|
+
let result = null;
|
|
286
|
+
const visit = (node) => {
|
|
287
|
+
if (ts.isExpressionStatement(node) && ts.isBinaryExpression(node.expression)) {
|
|
288
|
+
const expr = node.expression;
|
|
289
|
+
if (expr.operatorToken.kind === ts.SyntaxKind.EqualsToken && ts.isIdentifier(expr.left)) {
|
|
290
|
+
const type = typeChecker.getTypeAtLocation(expr.right);
|
|
291
|
+
const typeString = typeChecker.typeToString(type);
|
|
292
|
+
let value;
|
|
293
|
+
if (ts.isNumericLiteral(expr.right)) value = Number(expr.right.text);
|
|
294
|
+
else if (ts.isStringLiteral(expr.right)) value = expr.right.text;
|
|
295
|
+
const references = this.findReferences(expr.right, sourceFile, typeChecker);
|
|
296
|
+
result = {
|
|
297
|
+
name: expr.left.text,
|
|
298
|
+
type: "variable",
|
|
299
|
+
valueType: typeString,
|
|
300
|
+
value,
|
|
301
|
+
references
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
if (!result) ts.forEachChild(node, visit);
|
|
306
|
+
};
|
|
307
|
+
visit(sourceFile);
|
|
308
|
+
return result;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Find all identifier references in a source file.
|
|
312
|
+
*/
|
|
313
|
+
findAllReferences(sourceFile, _typeChecker) {
|
|
314
|
+
const references = /* @__PURE__ */ new Set();
|
|
315
|
+
const visit = (node) => {
|
|
316
|
+
if (ts.isIdentifier(node)) {
|
|
317
|
+
const parent = node.parent;
|
|
318
|
+
const isDeclaration = ts.isVariableDeclaration(parent) && parent.name === node || ts.isFunctionDeclaration(parent) && parent.name === node || ts.isParameter(parent) && parent.name === node;
|
|
319
|
+
const isAssignmentTarget = ts.isBinaryExpression(parent) && parent.operatorToken.kind === ts.SyntaxKind.EqualsToken && parent.left === node;
|
|
320
|
+
if (!isDeclaration && !isAssignmentTarget && !this.isBuiltIn(node.text)) references.add(node.text);
|
|
321
|
+
}
|
|
322
|
+
ts.forEachChild(node, visit);
|
|
323
|
+
};
|
|
324
|
+
visit(sourceFile);
|
|
325
|
+
return Array.from(references);
|
|
326
|
+
}
|
|
327
|
+
createEnvironment(files) {
|
|
328
|
+
const allFiles = [...systemFiles, ...files];
|
|
329
|
+
const fileMap = /* @__PURE__ */ new Map();
|
|
330
|
+
allFiles.forEach(({ filename, content }) => {
|
|
331
|
+
fileMap.set(filename, content);
|
|
332
|
+
});
|
|
333
|
+
return createVirtualTypeScriptEnvironment(createSystem(fileMap), allFiles.map(({ filename }) => filename), ts, this.compilerOptions);
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
//#endregion
|
|
337
|
+
//#region src/notebook/compute-graph.ts
|
|
338
|
+
var __dxlog_file$1 = "/__w/dxos/dxos/packages/plugins/plugin-script/src/notebook/compute-graph.ts";
|
|
339
|
+
/**
|
|
340
|
+
* Compute graph that evaluates the notebook cells.
|
|
341
|
+
*/
|
|
342
|
+
var ComputeGraph = class {
|
|
343
|
+
_notebook;
|
|
344
|
+
_registry;
|
|
345
|
+
_parser = new VirtualTypeScriptParser();
|
|
346
|
+
_expressionsAtom = Atom.make({});
|
|
347
|
+
_valuesByCellIdAtom = Atom.make({});
|
|
348
|
+
_valuesByNameAtom = Atom.make({});
|
|
349
|
+
constructor(_notebook, _registry) {
|
|
350
|
+
this._notebook = _notebook;
|
|
351
|
+
this._registry = _registry;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Atom for parsed expressions by cell ID.
|
|
355
|
+
*/
|
|
356
|
+
get expressions() {
|
|
357
|
+
return this._expressionsAtom;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Get current expressions by cell ID.
|
|
361
|
+
*/
|
|
362
|
+
getExpressions() {
|
|
363
|
+
return this._registry.get(this._expressionsAtom);
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Atom for computed values by cell ID.
|
|
367
|
+
*/
|
|
368
|
+
get values() {
|
|
369
|
+
return this._valuesByCellIdAtom;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Get computed values by cell ID.
|
|
373
|
+
*/
|
|
374
|
+
getValues() {
|
|
375
|
+
return this._registry.get(this._valuesByCellIdAtom);
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Atom for computed values by name.
|
|
379
|
+
*/
|
|
380
|
+
get valuesByName() {
|
|
381
|
+
return this._valuesByNameAtom;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Get current values by name.
|
|
385
|
+
*/
|
|
386
|
+
getValuesByName() {
|
|
387
|
+
return this._registry.get(this._valuesByNameAtom);
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Get computed value by cell ID.
|
|
391
|
+
*/
|
|
392
|
+
getValue(cellId) {
|
|
393
|
+
return this._registry.get(this._valuesByCellIdAtom)[cellId];
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Compute values.
|
|
397
|
+
*/
|
|
398
|
+
async evaluate() {
|
|
399
|
+
const { expressions, dependencyGraph } = this.parse();
|
|
400
|
+
this._registry.set(this._valuesByCellIdAtom, {});
|
|
401
|
+
this._registry.set(this._valuesByNameAtom, {});
|
|
402
|
+
const cellExpressions = /* @__PURE__ */ new Map();
|
|
403
|
+
Object.entries(expressions).forEach(([id, expr]) => {
|
|
404
|
+
cellExpressions.set(id, expr);
|
|
405
|
+
});
|
|
406
|
+
const evaluationOrder = this.topologicalSort(Object.keys(expressions), dependencyGraph);
|
|
407
|
+
const valuesByName = {};
|
|
408
|
+
const valuesByCellId = {};
|
|
409
|
+
for (const cellId of evaluationOrder) {
|
|
410
|
+
const expr = cellExpressions.get(cellId);
|
|
411
|
+
if (!expr) {
|
|
412
|
+
log.error("no expression for cell", { cellId }, {
|
|
413
|
+
"~LogMeta": "~LogMeta",
|
|
414
|
+
F: __dxlog_file$1,
|
|
415
|
+
L: 105,
|
|
416
|
+
S: this
|
|
417
|
+
});
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
const cellSource = this._notebook.cells.find((cell) => cell.id === cellId)?.source?.target?.content;
|
|
421
|
+
if (!cellSource) {
|
|
422
|
+
log.error("no source for cell", { cellId }, {
|
|
423
|
+
"~LogMeta": "~LogMeta",
|
|
424
|
+
F: __dxlog_file$1,
|
|
425
|
+
L: 111,
|
|
426
|
+
S: this
|
|
427
|
+
});
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
try {
|
|
431
|
+
if (expr.name && expr.value !== void 0) {
|
|
432
|
+
valuesByName[expr.name] = expr.value;
|
|
433
|
+
valuesByCellId[cellId] = expr.value;
|
|
434
|
+
} else if (expr.name) {
|
|
435
|
+
const equalIndex = cellSource.indexOf("=");
|
|
436
|
+
if (equalIndex !== -1) {
|
|
437
|
+
let rhs = cellSource.substring(equalIndex + 1).trim();
|
|
438
|
+
if (rhs.endsWith(";")) rhs = rhs.slice(0, -1).trim();
|
|
439
|
+
const result = await this.eval(rhs, valuesByName);
|
|
440
|
+
valuesByName[expr.name] = result;
|
|
441
|
+
if (typeof result !== "function") valuesByCellId[cellId] = result;
|
|
442
|
+
}
|
|
443
|
+
} else valuesByCellId[cellId] = await this.eval(cellSource, valuesByName);
|
|
444
|
+
} catch (error) {
|
|
445
|
+
log.error("error evaluating cell", {
|
|
446
|
+
cellId,
|
|
447
|
+
error
|
|
448
|
+
}, {
|
|
449
|
+
"~LogMeta": "~LogMeta",
|
|
450
|
+
F: __dxlog_file$1,
|
|
451
|
+
L: 147,
|
|
452
|
+
S: this
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
this._registry.set(this._valuesByCellIdAtom, valuesByCellId);
|
|
457
|
+
this._registry.set(this._valuesByNameAtom, valuesByName);
|
|
458
|
+
return valuesByCellId;
|
|
459
|
+
}
|
|
460
|
+
async eval(source, values) {
|
|
461
|
+
return evalScript(source, values);
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Parse expressions.
|
|
465
|
+
*/
|
|
466
|
+
parse() {
|
|
467
|
+
const expressions = this._notebook.cells.filter((cell) => cell.type === "script").reduce((acc, cell) => {
|
|
468
|
+
const text = cell.source?.target?.content.trim();
|
|
469
|
+
if (text) {
|
|
470
|
+
const parsed = this._parser.parseExpression(text);
|
|
471
|
+
acc[cell.id] = parsed;
|
|
472
|
+
}
|
|
473
|
+
return acc;
|
|
474
|
+
}, {});
|
|
475
|
+
const dependencyGraph = this.buildDependencyGraph(expressions);
|
|
476
|
+
this._registry.set(this._expressionsAtom, expressions);
|
|
477
|
+
return {
|
|
478
|
+
expressions,
|
|
479
|
+
dependencyGraph
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
topologicalSort(nodes, dependencies) {
|
|
483
|
+
const visited = /* @__PURE__ */ new Set();
|
|
484
|
+
const result = [];
|
|
485
|
+
const visit = (node) => {
|
|
486
|
+
if (visited.has(node)) return;
|
|
487
|
+
visited.add(node);
|
|
488
|
+
(dependencies[node] || []).forEach((dep) => visit(dep));
|
|
489
|
+
result.push(node);
|
|
490
|
+
};
|
|
491
|
+
nodes.forEach((node) => visit(node));
|
|
492
|
+
return result;
|
|
493
|
+
}
|
|
494
|
+
buildDependencyGraph(expressions) {
|
|
495
|
+
const nameToCellId = /* @__PURE__ */ new Map();
|
|
496
|
+
Object.entries(expressions).forEach(([id, expr]) => {
|
|
497
|
+
if (expr.name) nameToCellId.set(expr.name, id);
|
|
498
|
+
});
|
|
499
|
+
const graph = {};
|
|
500
|
+
Object.entries(expressions).forEach(([id, expr]) => {
|
|
501
|
+
if (expr.references && expr.references.length > 0) {
|
|
502
|
+
const dependencyCellIds = expr.references.map((ref) => nameToCellId.get(ref)).filter((cellId) => cellId !== void 0 && cellId !== id);
|
|
503
|
+
if (dependencyCellIds.length > 0) graph[id] = dependencyCellIds;
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
return graph;
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
//#endregion
|
|
510
|
+
//#region src/containers/NotebookArticle/NotebookArticle.tsx
|
|
511
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-script/src/containers/NotebookArticle/NotebookArticle.tsx";
|
|
512
|
+
var INCLUDE_SKILLS = [
|
|
513
|
+
"org.dxos.skill.assistant",
|
|
514
|
+
"org.dxos.skill.database",
|
|
515
|
+
"org.dxos.skill.markdown"
|
|
516
|
+
];
|
|
517
|
+
var NotebookArticle = ({ role, subject: notebook, attendableId, env }) => {
|
|
518
|
+
const { t } = useTranslation(meta.profile.key);
|
|
519
|
+
const registry = useContext(RegistryContext);
|
|
520
|
+
const db = notebook ? Obj.getDatabase(notebook) : void 0;
|
|
521
|
+
const { hasAttention } = useAttention(attendableId);
|
|
522
|
+
const graph = useMemo(() => notebook && new ComputeGraph(notebook, registry), [notebook, registry]);
|
|
523
|
+
const [queryValues, setQueryValues] = useState({});
|
|
524
|
+
const handleExecQueries = useCallback(async () => {
|
|
525
|
+
invariant(db, void 0, {
|
|
526
|
+
"~LogMeta": "~LogMeta",
|
|
527
|
+
F: __dxlog_file,
|
|
528
|
+
L: 51,
|
|
529
|
+
S: void 0,
|
|
530
|
+
A: ["db", ""]
|
|
531
|
+
});
|
|
532
|
+
const builder = new QueryBuilder();
|
|
533
|
+
for (const cell of notebook?.cells ?? []) if (cell.type === "query") {
|
|
534
|
+
if (cell.source?.target) {
|
|
535
|
+
const source = cell.source.target.content;
|
|
536
|
+
const { name, filter } = builder.build(source);
|
|
537
|
+
if (filter) {
|
|
538
|
+
const ast = Query.select(filter).ast;
|
|
539
|
+
const graph = cell.graph?.target;
|
|
540
|
+
if (!graph) {
|
|
541
|
+
const { view } = await ViewModel.makeFromDatabase({ db });
|
|
542
|
+
const newGraph = Graph.make({
|
|
543
|
+
query: { ast },
|
|
544
|
+
view
|
|
545
|
+
});
|
|
546
|
+
Obj.update(notebook, (obj) => {
|
|
547
|
+
const c = obj.cells.find((c) => c.id === cell.id);
|
|
548
|
+
if (c) {
|
|
549
|
+
c.graph = Ref.make(newGraph);
|
|
550
|
+
c.name = name;
|
|
551
|
+
}
|
|
552
|
+
});
|
|
553
|
+
} else Obj.update(graph, (graph) => {
|
|
554
|
+
graph.query.ast = ast;
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
if (cell.name && cell.graph?.target) {
|
|
559
|
+
const graph = Obj.getSnapshot(cell.graph?.target);
|
|
560
|
+
const query = Query.fromAst(graph.query.ast);
|
|
561
|
+
const objectIds = (await db.query(query).run())?.map((obj) => obj.id);
|
|
562
|
+
setQueryValues((prev) => ({
|
|
563
|
+
...prev,
|
|
564
|
+
[cell.name]: objectIds
|
|
565
|
+
}));
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
}, [
|
|
569
|
+
db,
|
|
570
|
+
notebook,
|
|
571
|
+
graph
|
|
572
|
+
]);
|
|
573
|
+
const [promptResults, setPromptResults] = useState({});
|
|
574
|
+
const handleExecPrompts = useSpaceCallback(db?.spaceId, [], Effect.fnUntraced(function* () {
|
|
575
|
+
invariant(graph, void 0, {
|
|
576
|
+
"~LogMeta": "~LogMeta",
|
|
577
|
+
F: __dxlog_file,
|
|
578
|
+
L: 96,
|
|
579
|
+
S: this,
|
|
580
|
+
A: ["graph", ""]
|
|
581
|
+
});
|
|
582
|
+
const allInstructions = notebook?.cells.filter((cell) => cell.type === "prompt").map((cell) => cell.prompt).filter(isNonNullable) ?? [];
|
|
583
|
+
for (const instructions of allInstructions) yield* runPrompt({
|
|
584
|
+
instructions,
|
|
585
|
+
input: {
|
|
586
|
+
...queryValues,
|
|
587
|
+
...graph.getValuesByName()
|
|
588
|
+
},
|
|
589
|
+
onResult: (result) => setPromptResults((prev) => ({
|
|
590
|
+
...prev,
|
|
591
|
+
[instructions.uri]: result
|
|
592
|
+
}))
|
|
593
|
+
});
|
|
594
|
+
}), [
|
|
595
|
+
notebook,
|
|
596
|
+
graph,
|
|
597
|
+
queryValues
|
|
598
|
+
]);
|
|
599
|
+
const handleCompute = useCallback(async () => {
|
|
600
|
+
await graph?.evaluate();
|
|
601
|
+
await handleExecQueries();
|
|
602
|
+
await handleExecPrompts();
|
|
603
|
+
}, [
|
|
604
|
+
graph,
|
|
605
|
+
handleExecQueries,
|
|
606
|
+
handleExecPrompts
|
|
607
|
+
]);
|
|
608
|
+
const handleCellInsert = useCallback(async (type, after) => {
|
|
609
|
+
invariant(notebook, void 0, {
|
|
610
|
+
"~LogMeta": "~LogMeta",
|
|
611
|
+
F: __dxlog_file,
|
|
612
|
+
L: 129,
|
|
613
|
+
S: void 0,
|
|
614
|
+
A: ["notebook", ""]
|
|
615
|
+
});
|
|
616
|
+
const cell = {
|
|
617
|
+
id: crypto.randomUUID(),
|
|
618
|
+
type
|
|
619
|
+
};
|
|
620
|
+
switch (type) {
|
|
621
|
+
case "markdown":
|
|
622
|
+
case "script":
|
|
623
|
+
case "query":
|
|
624
|
+
cell.source = Ref.make(Text.make());
|
|
625
|
+
break;
|
|
626
|
+
case "prompt":
|
|
627
|
+
if (db) {
|
|
628
|
+
const skills = (await db.query(Query.select(Filter.type(Skill.Skill))).run()).filter((skill) => {
|
|
629
|
+
const key = Obj.getMeta(skill).key;
|
|
630
|
+
return key !== void 0 && INCLUDE_SKILLS.includes(key);
|
|
631
|
+
}).map((skill) => Ref.make(skill));
|
|
632
|
+
cell.prompt = Ref.make(Instructions.make({
|
|
633
|
+
text: "",
|
|
634
|
+
skills
|
|
635
|
+
}));
|
|
636
|
+
}
|
|
637
|
+
break;
|
|
638
|
+
}
|
|
639
|
+
const idx = after ? notebook.cells.findIndex((cell) => cell.id === after) : notebook.cells.length;
|
|
640
|
+
Obj.update(notebook, (notebook) => {
|
|
641
|
+
notebook.cells.splice(idx, 0, cell);
|
|
642
|
+
});
|
|
643
|
+
}, [db, notebook]);
|
|
644
|
+
const handleCellDelete = useCallback((id) => {
|
|
645
|
+
invariant(notebook, void 0, {
|
|
646
|
+
"~LogMeta": "~LogMeta",
|
|
647
|
+
F: __dxlog_file,
|
|
648
|
+
L: 164,
|
|
649
|
+
S: void 0,
|
|
650
|
+
A: ["notebook", ""]
|
|
651
|
+
});
|
|
652
|
+
const idx = notebook.cells.findIndex((cell) => cell.id === id);
|
|
653
|
+
if (idx !== -1) Obj.update(notebook, (notebook) => {
|
|
654
|
+
notebook.cells.splice(idx, 1);
|
|
655
|
+
});
|
|
656
|
+
}, [notebook]);
|
|
657
|
+
return /* @__PURE__ */ jsxs(Panel.Root, {
|
|
658
|
+
role,
|
|
659
|
+
classNames: "dx-document",
|
|
660
|
+
children: [/* @__PURE__ */ jsx(Panel.Toolbar, {
|
|
661
|
+
asChild: true,
|
|
662
|
+
children: /* @__PURE__ */ jsxs(Toolbar.Root, {
|
|
663
|
+
disabled: !hasAttention,
|
|
664
|
+
children: [/* @__PURE__ */ jsxs(DropdownMenu.Root, { children: [/* @__PURE__ */ jsx(DropdownMenu.Trigger, {
|
|
665
|
+
asChild: true,
|
|
666
|
+
children: /* @__PURE__ */ jsx(IconButton, {
|
|
667
|
+
icon: "ph--plus--regular",
|
|
668
|
+
iconOnly: true,
|
|
669
|
+
label: t("notebook-cell-insert.label")
|
|
670
|
+
})
|
|
671
|
+
}), /* @__PURE__ */ jsx(NotebookMenu, { onCellInsert: handleCellInsert })] }), /* @__PURE__ */ jsx(Toolbar.IconButton, {
|
|
672
|
+
icon: "ph--play--fill",
|
|
673
|
+
iconOnly: true,
|
|
674
|
+
label: t("compute.label"),
|
|
675
|
+
classNames: "text-success-text",
|
|
676
|
+
onClick: handleCompute
|
|
677
|
+
})]
|
|
678
|
+
})
|
|
679
|
+
}), /* @__PURE__ */ jsx(Panel.Content, {
|
|
680
|
+
asChild: true,
|
|
681
|
+
children: /* @__PURE__ */ jsx(NotebookStack, {
|
|
682
|
+
db,
|
|
683
|
+
notebook,
|
|
684
|
+
graph,
|
|
685
|
+
env,
|
|
686
|
+
promptResults,
|
|
687
|
+
onCellInsert: handleCellInsert,
|
|
688
|
+
onCellDelete: handleCellDelete
|
|
689
|
+
})
|
|
690
|
+
})]
|
|
691
|
+
});
|
|
692
|
+
};
|
|
693
|
+
var runPrompt = Effect.fn(function* ({ instructions, input, onResult }) {
|
|
694
|
+
const inputData = {
|
|
695
|
+
instructions,
|
|
696
|
+
input
|
|
697
|
+
};
|
|
698
|
+
const result = yield* Operation.invoke(RunInstructions, inputData).pipe(Effect.orDie, Effect.exit);
|
|
699
|
+
Exit.match(result, {
|
|
700
|
+
onFailure: (cause) => {
|
|
701
|
+
const error = Cause.prettyErrors(cause)[0];
|
|
702
|
+
log.error(error.message, error.cause ?? error.stack, {
|
|
703
|
+
"~LogMeta": "~LogMeta",
|
|
704
|
+
F: __dxlog_file,
|
|
705
|
+
L: 226,
|
|
706
|
+
S: this
|
|
707
|
+
});
|
|
708
|
+
onResult(error.message);
|
|
709
|
+
},
|
|
710
|
+
onSuccess: (result) => {
|
|
711
|
+
onResult(result.note);
|
|
712
|
+
}
|
|
713
|
+
});
|
|
714
|
+
});
|
|
715
|
+
NotebookArticle.displayName = "NotebookArticle";
|
|
716
|
+
//#endregion
|
|
717
|
+
export { NotebookArticle as default };
|
|
718
|
+
|
|
719
|
+
//# sourceMappingURL=chunk-NotebookArticle.mjs.map
|