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