@dxos/plugin-script 0.8.4-main.406dc2a → 0.8.4-main.548089c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/DeploymentDialog-MZX4T77L.mjs +14 -0
- package/dist/lib/browser/{NotebookContainer-LVGRPFY3.mjs → NotebookContainer-S6GUYCUE.mjs} +216 -82
- package/dist/lib/browser/NotebookContainer-S6GUYCUE.mjs.map +7 -0
- package/dist/lib/browser/{ScriptContainer-LRTRN7JW.mjs → ScriptContainer-3JQSTDFZ.mjs} +16 -18
- package/dist/lib/browser/ScriptContainer-3JQSTDFZ.mjs.map +7 -0
- package/dist/lib/browser/{app-graph-builder-DPYULSME.mjs → app-graph-builder-2WR2ATTJ.mjs} +7 -6
- package/dist/lib/browser/app-graph-builder-2WR2ATTJ.mjs.map +7 -0
- package/dist/lib/browser/{blueprint-definition-ET5KZ46I.mjs → blueprint-definition-6PZWZM2Y.mjs} +3 -1
- package/dist/lib/browser/{chunk-ST3ACVUC.mjs → chunk-2G2NA6DQ.mjs} +2 -2
- package/dist/lib/browser/{chunk-ST3ACVUC.mjs.map → chunk-2G2NA6DQ.mjs.map} +1 -1
- package/dist/lib/browser/{chunk-NM4WQS4F.mjs → chunk-3IJASGG5.mjs} +12 -10
- package/dist/lib/browser/chunk-3IJASGG5.mjs.map +7 -0
- package/dist/lib/browser/chunk-5JSNQYZZ.mjs +517 -0
- package/dist/lib/browser/chunk-5JSNQYZZ.mjs.map +7 -0
- package/dist/lib/browser/{chunk-EZVXV6DA.mjs → chunk-EB6AXFXO.mjs} +7 -2
- package/dist/lib/browser/chunk-EB6AXFXO.mjs.map +7 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/browser/{chunk-I3QSGUFJ.mjs → chunk-JRF6FHYQ.mjs} +33 -33
- package/dist/lib/browser/chunk-JRF6FHYQ.mjs.map +7 -0
- package/dist/lib/browser/{chunk-5CYLWXRH.mjs → chunk-LNNCD2H4.mjs} +51 -38
- package/dist/lib/browser/chunk-LNNCD2H4.mjs.map +7 -0
- package/dist/lib/browser/{chunk-N6M34EUC.mjs → chunk-M6KJPUJK.mjs} +3 -4
- package/dist/lib/browser/chunk-M6KJPUJK.mjs.map +7 -0
- package/dist/lib/browser/{chunk-75LH4EUR.mjs → chunk-RXLF2X2R.mjs} +58 -80
- package/dist/lib/browser/chunk-RXLF2X2R.mjs.map +7 -0
- package/dist/lib/browser/{chunk-OKXN2N7M.mjs → chunk-UOQ6NCH3.mjs} +2 -2
- package/dist/lib/browser/{compiler-G2N2CG63.mjs → compiler-4KHRSX7J.mjs} +11 -23
- package/dist/lib/browser/compiler-4KHRSX7J.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +27 -33
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/{intent-resolver-JLU7DVLQ.mjs → intent-resolver-PUMSYKVB.mjs} +19 -20
- package/dist/lib/browser/intent-resolver-PUMSYKVB.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-76SDTUYG.mjs → react-surface-DLRMWFTN.mjs} +22 -21
- package/dist/lib/browser/react-surface-DLRMWFTN.mjs.map +7 -0
- package/dist/lib/browser/{settings-ERFKVNUK.mjs → settings-LNLSTZM4.mjs} +5 -4
- package/dist/lib/browser/templates/index.mjs +2 -1
- package/dist/lib/browser/types/index.mjs +6 -5
- package/dist/lib/node-esm/DeploymentDialog-GL5AUWMR.mjs +15 -0
- package/dist/lib/node-esm/DeploymentDialog-GL5AUWMR.mjs.map +7 -0
- package/dist/lib/node-esm/{NotebookContainer-QY5NJGJI.mjs → NotebookContainer-RTUHQN25.mjs} +216 -82
- package/dist/lib/node-esm/NotebookContainer-RTUHQN25.mjs.map +7 -0
- package/dist/lib/node-esm/{ScriptContainer-SVXCSLNH.mjs → ScriptContainer-SSLISMLS.mjs} +16 -18
- package/dist/lib/node-esm/ScriptContainer-SSLISMLS.mjs.map +7 -0
- package/dist/lib/node-esm/{app-graph-builder-UXJGHXSL.mjs → app-graph-builder-NCVLUL5R.mjs} +7 -6
- package/dist/lib/node-esm/app-graph-builder-NCVLUL5R.mjs.map +7 -0
- package/dist/lib/node-esm/{blueprint-definition-AIYFOT7Q.mjs → blueprint-definition-5R6YCSZZ.mjs} +2 -1
- package/dist/lib/{browser/blueprint-definition-ET5KZ46I.mjs.map → node-esm/blueprint-definition-5R6YCSZZ.mjs.map} +1 -1
- package/dist/lib/node-esm/{chunk-NUXZQQ6P.mjs → chunk-55JZVM6K.mjs} +2 -2
- package/dist/lib/node-esm/{chunk-2GVTWESW.mjs → chunk-57JA6XL5.mjs} +2 -2
- package/dist/lib/node-esm/{chunk-2GVTWESW.mjs.map → chunk-57JA6XL5.mjs.map} +1 -1
- package/dist/lib/node-esm/{chunk-SMFPSKQT.mjs → chunk-ASPYIAYG.mjs} +33 -33
- package/dist/lib/node-esm/chunk-ASPYIAYG.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-VRSDE4CI.mjs → chunk-HDKR5WCD.mjs} +3 -4
- package/dist/lib/node-esm/chunk-HDKR5WCD.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-OG2SIKHE.mjs → chunk-IBV2DR36.mjs} +7 -2
- package/dist/lib/node-esm/chunk-IBV2DR36.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-IQTBVH4L.mjs +518 -0
- package/dist/lib/node-esm/chunk-IQTBVH4L.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-4X375PGY.mjs → chunk-NNHWLRHT.mjs} +51 -38
- package/dist/lib/node-esm/chunk-NNHWLRHT.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-67OVZHI3.mjs → chunk-Q5XB7DD4.mjs} +58 -80
- package/dist/lib/node-esm/chunk-Q5XB7DD4.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-C2ORIPKH.mjs → chunk-RIE676OW.mjs} +12 -10
- package/dist/lib/node-esm/chunk-RIE676OW.mjs.map +7 -0
- package/dist/lib/node-esm/{compiler-PLDAZ5GJ.mjs → compiler-DU5NQISX.mjs} +11 -23
- package/dist/lib/node-esm/compiler-DU5NQISX.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +27 -33
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/{intent-resolver-SFGTIFOG.mjs → intent-resolver-JK7J6JQB.mjs} +19 -20
- package/dist/lib/node-esm/intent-resolver-JK7J6JQB.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{react-surface-SHEBNW4R.mjs → react-surface-BPQLLTT4.mjs} +22 -21
- package/dist/lib/node-esm/react-surface-BPQLLTT4.mjs.map +7 -0
- package/dist/lib/node-esm/{settings-5TYXQ42N.mjs → settings-IUFMOCXY.mjs} +5 -4
- package/dist/lib/{browser/settings-ERFKVNUK.mjs.map → node-esm/settings-IUFMOCXY.mjs.map} +1 -1
- package/dist/lib/node-esm/templates/index.mjs +2 -1
- package/dist/lib/node-esm/types/index.mjs +6 -5
- package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/components/DeploymentDialog/DeploymentDialog.d.ts +2 -2
- package/dist/types/src/components/DeploymentDialog/DeploymentDialog.d.ts.map +1 -1
- package/dist/types/src/components/DeploymentDialog/DeploymentDialog.stories.d.ts +0 -3
- package/dist/types/src/components/DeploymentDialog/DeploymentDialog.stories.d.ts.map +1 -1
- package/dist/types/src/components/FrameContainer/FrameContainer.d.ts +1 -1
- package/dist/types/src/components/FrameContainer/FrameContainer.d.ts.map +1 -1
- package/dist/types/src/components/NotebookContainer.d.ts.map +1 -1
- package/dist/types/src/components/NotebookContainer.stories.d.ts +7 -4
- package/dist/types/src/components/NotebookContainer.stories.d.ts.map +1 -1
- package/dist/types/src/components/NotebookStack/NotebookCell.d.ts +2 -1
- package/dist/types/src/components/NotebookStack/NotebookCell.d.ts.map +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 +0 -3
- package/dist/types/src/components/NotebookStack/NotebookStack.stories.d.ts.map +1 -1
- package/dist/types/src/components/ScriptContainer.d.ts +2 -2
- package/dist/types/src/components/ScriptContainer.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts +5 -6
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.stories.d.ts +1 -4
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.stories.d.ts.map +1 -1
- package/dist/types/src/components/Settings/ScriptObjectSettings.d.ts +2 -2
- package/dist/types/src/components/Settings/ScriptObjectSettings.d.ts.map +1 -1
- package/dist/types/src/components/TestPanel/TestContainer.d.ts +2 -2
- package/dist/types/src/components/TestPanel/TestContainer.d.ts.map +1 -1
- package/dist/types/src/components/TestPanel/TestPanel.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts +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/hooks/deploy.d.ts +8 -7
- package/dist/types/src/hooks/deploy.d.ts.map +1 -1
- package/dist/types/src/hooks/format.d.ts +2 -2
- package/dist/types/src/hooks/format.d.ts.map +1 -1
- package/dist/types/src/hooks/template.d.ts +4 -14
- package/dist/types/src/hooks/template.d.ts.map +1 -1
- package/dist/types/src/hooks/useCreateAndDeployScriptTemplates.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/notebook/{notebook.d.ts → compute-graph.d.ts} +13 -3
- package/dist/types/src/notebook/compute-graph.d.ts.map +1 -0
- package/dist/types/src/notebook/compute-graph.test.d.ts +2 -0
- package/dist/types/src/notebook/compute-graph.test.d.ts.map +1 -0
- package/dist/types/src/notebook/eval.d.ts +1 -1
- package/dist/types/src/notebook/eval.d.ts.map +1 -1
- package/dist/types/src/notebook/index.d.ts +1 -1
- package/dist/types/src/notebook/index.d.ts.map +1 -1
- package/dist/types/src/testing/data.d.ts +2 -18
- package/dist/types/src/testing/data.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +2 -3
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Notebook.d.ts +31 -0
- package/dist/types/src/types/Notebook.d.ts.map +1 -0
- package/dist/types/src/types/actions.d.ts +5 -17
- package/dist/types/src/types/actions.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +2 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +6 -0
- package/dist/types/src/types/types.d.ts.map +1 -0
- package/dist/types/src/util/deploy.d.ts +4 -4
- package/dist/types/src/util/deploy.d.ts.map +1 -1
- package/dist/types/src/util/functions.d.ts +3 -3
- package/dist/types/src/util/functions.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +61 -56
- package/src/ScriptPlugin.tsx +6 -10
- package/src/capabilities/app-graph-builder.ts +6 -6
- package/src/capabilities/artifact-definition.ts +1 -2
- package/src/capabilities/compiler.ts +1 -1
- package/src/capabilities/intent-resolver.ts +6 -7
- package/src/capabilities/react-surface.tsx +13 -12
- package/src/components/DeploymentDialog/DeploymentDialog.stories.tsx +8 -3
- package/src/components/DeploymentDialog/DeploymentDialog.tsx +30 -13
- package/src/components/FrameContainer/FrameContainer.tsx +1 -1
- package/src/components/NotebookContainer.stories.tsx +58 -7
- package/src/components/NotebookContainer.tsx +150 -11
- package/src/components/NotebookStack/NotebookCell.tsx +63 -66
- package/src/components/NotebookStack/NotebookStack.stories.tsx +24 -2
- package/src/components/NotebookStack/NotebookStack.tsx +12 -5
- package/src/components/ScriptContainer.tsx +3 -3
- package/src/components/ScriptToolbar/ScriptToolbar.stories.tsx +6 -6
- package/src/components/ScriptToolbar/ScriptToolbar.tsx +12 -12
- package/src/components/Settings/ScriptObjectSettings.tsx +21 -10
- package/src/components/TestPanel/TestContainer.tsx +2 -2
- package/src/components/TestPanel/TestPanel.tsx +36 -13
- package/src/components/TypescriptEditor/TypescriptEditor.stories.tsx +1 -1
- package/src/components/TypescriptEditor/TypescriptEditor.tsx +6 -11
- package/src/hooks/deploy.ts +6 -6
- package/src/hooks/format.ts +2 -2
- package/src/hooks/template.ts +5 -15
- package/src/hooks/useCreateAndDeployScriptTemplates.ts +8 -4
- package/src/meta.ts +6 -2
- package/src/notebook/{notebook.test.ts → compute-graph.test.ts} +19 -19
- package/src/notebook/{notebook.ts → compute-graph.ts} +32 -9
- package/src/notebook/eval.ts +1 -1
- package/src/notebook/index.ts +1 -1
- package/src/templates/gmail.ts +1 -2
- package/src/testing/data.ts +34 -9
- package/src/translations.ts +2 -3
- package/src/types/Notebook.ts +41 -0
- package/src/types/actions.ts +3 -3
- package/src/types/index.ts +2 -1
- package/src/types/types.ts +15 -0
- package/src/util/deploy.ts +13 -17
- package/src/util/functions.ts +5 -4
- package/dist/lib/browser/DeploymentDialog-65TWT6S5.mjs +0 -13
- package/dist/lib/browser/NotebookContainer-LVGRPFY3.mjs.map +0 -7
- package/dist/lib/browser/ScriptContainer-LRTRN7JW.mjs.map +0 -7
- package/dist/lib/browser/app-graph-builder-DPYULSME.mjs.map +0 -7
- package/dist/lib/browser/chunk-5CYLWXRH.mjs.map +0 -7
- package/dist/lib/browser/chunk-75LH4EUR.mjs.map +0 -7
- package/dist/lib/browser/chunk-E7DXDICD.mjs +0 -282
- package/dist/lib/browser/chunk-E7DXDICD.mjs.map +0 -7
- package/dist/lib/browser/chunk-EZVXV6DA.mjs.map +0 -7
- package/dist/lib/browser/chunk-I3QSGUFJ.mjs.map +0 -7
- package/dist/lib/browser/chunk-JO2O7W6J.mjs +0 -254
- package/dist/lib/browser/chunk-JO2O7W6J.mjs.map +0 -7
- package/dist/lib/browser/chunk-N6M34EUC.mjs.map +0 -7
- package/dist/lib/browser/chunk-NM4WQS4F.mjs.map +0 -7
- package/dist/lib/browser/compiler-G2N2CG63.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-JLU7DVLQ.mjs.map +0 -7
- package/dist/lib/browser/react-surface-76SDTUYG.mjs.map +0 -7
- package/dist/lib/node-esm/DeploymentDialog-I63ZC2HH.mjs +0 -14
- package/dist/lib/node-esm/NotebookContainer-QY5NJGJI.mjs.map +0 -7
- package/dist/lib/node-esm/ScriptContainer-SVXCSLNH.mjs.map +0 -7
- package/dist/lib/node-esm/app-graph-builder-UXJGHXSL.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-4X375PGY.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-67OVZHI3.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-C2ORIPKH.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-OG2SIKHE.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-SMFPSKQT.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-VRSDE4CI.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-VZAFGLD7.mjs +0 -283
- package/dist/lib/node-esm/chunk-VZAFGLD7.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-YW36TZ7K.mjs +0 -255
- package/dist/lib/node-esm/chunk-YW36TZ7K.mjs.map +0 -7
- package/dist/lib/node-esm/compiler-PLDAZ5GJ.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-SFGTIFOG.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-SHEBNW4R.mjs.map +0 -7
- package/dist/types/src/notebook/notebook.d.ts.map +0 -1
- package/dist/types/src/notebook/notebook.test.d.ts +0 -2
- package/dist/types/src/notebook/notebook.test.d.ts.map +0 -1
- package/dist/types/src/types/schema.d.ts +0 -61
- package/dist/types/src/types/schema.d.ts.map +0 -1
- package/src/types/schema.ts +0 -48
- /package/dist/lib/browser/{DeploymentDialog-65TWT6S5.mjs.map → DeploymentDialog-MZX4T77L.mjs.map} +0 -0
- /package/dist/lib/{node-esm/blueprint-definition-AIYFOT7Q.mjs.map → browser/blueprint-definition-6PZWZM2Y.mjs.map} +0 -0
- /package/dist/lib/{node-esm/DeploymentDialog-I63ZC2HH.mjs.map → browser/chunk-J5LGTIGS.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-OKXN2N7M.mjs.map → chunk-UOQ6NCH3.mjs.map} +0 -0
- /package/dist/lib/{node-esm/settings-5TYXQ42N.mjs.map → browser/settings-LNLSTZM4.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-NUXZQQ6P.mjs.map → chunk-55JZVM6K.mjs.map} +0 -0
|
@@ -6,20 +6,22 @@ import { Octokit } from '@octokit/core';
|
|
|
6
6
|
import React, { type ChangeEvent, useCallback, useState } from 'react';
|
|
7
7
|
|
|
8
8
|
import { ToolId } from '@dxos/ai';
|
|
9
|
-
import { SettingsAction, createIntent
|
|
9
|
+
import { SettingsAction, createIntent } from '@dxos/app-framework';
|
|
10
|
+
import { useIntentDispatcher } from '@dxos/app-framework/react';
|
|
10
11
|
import { Blueprint, Template } from '@dxos/blueprints';
|
|
11
|
-
import {
|
|
12
|
+
import { Function, type Script, getUserFunctionIdInMetadata } from '@dxos/functions';
|
|
13
|
+
import { getInvocationUrl } from '@dxos/functions-runtime';
|
|
12
14
|
import { log } from '@dxos/log';
|
|
13
15
|
import { useClient } from '@dxos/react-client';
|
|
14
16
|
import { Filter, Ref, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';
|
|
15
17
|
import { Button, Clipboard, Input, useAsyncEffect, useControlledState, useTranslation } from '@dxos/react-ui';
|
|
16
|
-
import {
|
|
18
|
+
import { AccessToken } from '@dxos/types';
|
|
17
19
|
import { kebabize } from '@dxos/util';
|
|
18
20
|
|
|
19
21
|
import { meta } from '../../meta';
|
|
20
22
|
|
|
21
23
|
export type ScriptObjectSettingsProps = {
|
|
22
|
-
object:
|
|
24
|
+
object: Script.Script;
|
|
23
25
|
};
|
|
24
26
|
|
|
25
27
|
export const ScriptObjectSettings = ({ object }: ScriptObjectSettingsProps) => {
|
|
@@ -51,7 +53,7 @@ export const ScriptProperties = ({ object }: ScriptObjectSettingsProps) => {
|
|
|
51
53
|
const BlueprintEditor = ({ object }: ScriptObjectSettingsProps) => {
|
|
52
54
|
const { t } = useTranslation(meta.id);
|
|
53
55
|
const space = getSpace(object);
|
|
54
|
-
const [fn] = useQuery(space, Filter.type(
|
|
56
|
+
const [fn] = useQuery(space, Filter.type(Function.Function, { source: Ref.make(object) }));
|
|
55
57
|
const blueprints = useQuery(space, Filter.type(Blueprint.Blueprint));
|
|
56
58
|
|
|
57
59
|
const [creating, setCreating] = useState(false);
|
|
@@ -106,14 +108,18 @@ const BlueprintEditor = ({ object }: ScriptObjectSettingsProps) => {
|
|
|
106
108
|
<div>
|
|
107
109
|
<h2>{t('blueprint editor label', { default: 'Blueprint' })}</h2>
|
|
108
110
|
<p className='text-description text-sm'>
|
|
109
|
-
{t('blueprint editor description', {
|
|
111
|
+
{t('blueprint editor description', {
|
|
112
|
+
default: 'Create a blueprint that exposes this script as a tool.',
|
|
113
|
+
})}
|
|
110
114
|
</p>
|
|
111
115
|
</div>
|
|
112
116
|
<Input.Root>
|
|
113
117
|
<div role='none' className='flex flex-col gap-1'>
|
|
114
118
|
<Input.Label>{t('blueprint instructions label', { default: 'Instructions' })}</Input.Label>
|
|
115
119
|
<Input.TextArea
|
|
116
|
-
placeholder={t('blueprint instructions placeholder', {
|
|
120
|
+
placeholder={t('blueprint instructions placeholder', {
|
|
121
|
+
default: 'Describe how this tool should be used.',
|
|
122
|
+
})}
|
|
117
123
|
rows={6}
|
|
118
124
|
value={instructions}
|
|
119
125
|
onChange={(event) => setInstructions(event.target.value)}
|
|
@@ -136,7 +142,7 @@ const Binding = ({ object }: ScriptObjectSettingsProps) => {
|
|
|
136
142
|
const { t } = useTranslation(meta.id);
|
|
137
143
|
const client = useClient();
|
|
138
144
|
const space = getSpace(object);
|
|
139
|
-
const [fn] = useQuery(space, Filter.type(
|
|
145
|
+
const [fn] = useQuery(space, Filter.type(Function.Function, { source: Ref.make(object) }));
|
|
140
146
|
|
|
141
147
|
const functionId = fn && getUserFunctionIdInMetadata(getMeta(fn));
|
|
142
148
|
const functionUrl =
|
|
@@ -200,7 +206,7 @@ const Publishing = ({ object }: ScriptObjectSettingsProps) => {
|
|
|
200
206
|
const { t } = useTranslation(meta.id);
|
|
201
207
|
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
202
208
|
const space = getSpace(object);
|
|
203
|
-
const [githubToken] = useQuery(space, Filter.type(
|
|
209
|
+
const [githubToken] = useQuery(space, Filter.type(AccessToken.AccessToken, { source: 'github.com' }));
|
|
204
210
|
const gistKey = getMeta(object).keys.find(({ source }) => source === 'github.com');
|
|
205
211
|
const [gistUrl, setGistUrl] = useState<string | undefined>();
|
|
206
212
|
|
|
@@ -225,7 +231,12 @@ const Publishing = ({ object }: ScriptObjectSettingsProps) => {
|
|
|
225
231
|
}, [githubToken, gistKey]);
|
|
226
232
|
|
|
227
233
|
const handleOpenTokenManager = useCallback(
|
|
228
|
-
() =>
|
|
234
|
+
() =>
|
|
235
|
+
dispatch(
|
|
236
|
+
createIntent(SettingsAction.Open, {
|
|
237
|
+
plugin: 'dxos.org/plugin/token-manager',
|
|
238
|
+
}),
|
|
239
|
+
),
|
|
229
240
|
[],
|
|
230
241
|
);
|
|
231
242
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
7
|
-
import { type
|
|
7
|
+
import { type Script } from '@dxos/functions';
|
|
8
8
|
import { StackItem } from '@dxos/react-ui-stack';
|
|
9
9
|
|
|
10
10
|
import { useDeployState, useToolbarState } from '../../hooks';
|
|
@@ -13,7 +13,7 @@ import { TestPanel } from './TestPanel';
|
|
|
13
13
|
|
|
14
14
|
export type TestContainerProps = {
|
|
15
15
|
role: string;
|
|
16
|
-
script:
|
|
16
|
+
script: Script.Script;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
export const TestContainer = ({ script }: TestContainerProps) => {
|
|
@@ -16,7 +16,12 @@ type State = 'pending' | 'responding';
|
|
|
16
16
|
/**
|
|
17
17
|
* Request or response.
|
|
18
18
|
*/
|
|
19
|
-
type Message = {
|
|
19
|
+
type Message = {
|
|
20
|
+
type: 'request' | 'response';
|
|
21
|
+
text?: string;
|
|
22
|
+
data?: any;
|
|
23
|
+
error?: Error;
|
|
24
|
+
};
|
|
20
25
|
|
|
21
26
|
export type TestPanelProps = ThemedClassName<{
|
|
22
27
|
functionUrl?: string;
|
|
@@ -61,7 +66,15 @@ export const TestPanel = ({ classNames, functionUrl }: TestPanelProps) => {
|
|
|
61
66
|
inputRef.current?.focus();
|
|
62
67
|
};
|
|
63
68
|
|
|
64
|
-
const handleResponse = ({
|
|
69
|
+
const handleResponse = ({
|
|
70
|
+
text,
|
|
71
|
+
data,
|
|
72
|
+
error,
|
|
73
|
+
}: {
|
|
74
|
+
text?: string;
|
|
75
|
+
data?: any;
|
|
76
|
+
error?: Error;
|
|
77
|
+
} = {}) => {
|
|
65
78
|
controller.current = null;
|
|
66
79
|
setHistory((history) => [...history, { type: 'response', text, data, error } satisfies Message]);
|
|
67
80
|
setResult('');
|
|
@@ -108,7 +121,9 @@ export const TestPanel = ({ classNames, functionUrl }: TestPanelProps) => {
|
|
|
108
121
|
// Check for error.
|
|
109
122
|
if (!response.ok) {
|
|
110
123
|
const text = await response.text();
|
|
111
|
-
handleResponse({
|
|
124
|
+
handleResponse({
|
|
125
|
+
error: new Error(text || response.statusText || String(response.status)),
|
|
126
|
+
});
|
|
112
127
|
return;
|
|
113
128
|
}
|
|
114
129
|
|
|
@@ -159,11 +174,11 @@ export const TestPanel = ({ classNames, functionUrl }: TestPanelProps) => {
|
|
|
159
174
|
};
|
|
160
175
|
|
|
161
176
|
return (
|
|
162
|
-
<div className={mx('flex flex-col
|
|
177
|
+
<div className={mx('flex flex-col bs-full overflow-hidden', classNames)}>
|
|
163
178
|
{/* TODO(burdon): Replace with Thread. */}
|
|
164
179
|
<MessageThread ref={scrollerRef} state={state} result={result} history={history} />
|
|
165
180
|
{/* TODO(burdon): Replace with Form based on the function's input schema. */}
|
|
166
|
-
<Toolbar.Root
|
|
181
|
+
<Toolbar.Root>
|
|
167
182
|
<Input.Root>
|
|
168
183
|
<Input.TextInput
|
|
169
184
|
ref={inputRef}
|
|
@@ -174,12 +189,20 @@ export const TestPanel = ({ classNames, functionUrl }: TestPanelProps) => {
|
|
|
174
189
|
onKeyDown={(ev) => ev.key === 'Enter' && handleRequest(input)}
|
|
175
190
|
/>
|
|
176
191
|
</Input.Root>
|
|
177
|
-
<Toolbar.
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
192
|
+
<Toolbar.IconButton
|
|
193
|
+
icon='ph--play--regular'
|
|
194
|
+
size={4}
|
|
195
|
+
label='Execute'
|
|
196
|
+
iconOnly
|
|
197
|
+
onClick={() => handleRequest(input)}
|
|
198
|
+
/>
|
|
199
|
+
<Toolbar.IconButton
|
|
200
|
+
icon={state ? 'ph--stop--regular' : 'ph--trash--regular'}
|
|
201
|
+
size={4}
|
|
202
|
+
label={state ? 'Stop' : 'Clear'}
|
|
203
|
+
iconOnly
|
|
204
|
+
onClick={() => (state ? handleStop() : handleClear())}
|
|
205
|
+
/>
|
|
183
206
|
</Toolbar.Root>
|
|
184
207
|
</div>
|
|
185
208
|
);
|
|
@@ -196,7 +219,7 @@ type MessageThreadProps = {
|
|
|
196
219
|
const MessageThread = forwardRef<HTMLDivElement, MessageThreadProps>(
|
|
197
220
|
({ state, history, result }: MessageThreadProps, forwardedRef) => {
|
|
198
221
|
return (
|
|
199
|
-
<div ref={forwardedRef} className='flex flex-col gap-6
|
|
222
|
+
<div ref={forwardedRef} className='flex flex-col gap-6 bs-full p-2 overflow-x-hidden overflow-y-auto'>
|
|
200
223
|
{history.map((message, i) => (
|
|
201
224
|
<div key={i} className='grid grid-cols-[2rem_1fr_2rem]'>
|
|
202
225
|
<div className='p-1'>{message.type === 'response' && <RobotAvatar />}</div>
|
|
@@ -225,7 +248,7 @@ const MessageThread = forwardRef<HTMLDivElement, MessageThreadProps>(
|
|
|
225
248
|
|
|
226
249
|
const MessageItem = ({ classNames, message }: ThemedClassName<{ message: Message }>) => {
|
|
227
250
|
const { type, text, data, error } = message;
|
|
228
|
-
const wrapper = 'p-1
|
|
251
|
+
const wrapper = 'p-1 pli-2 rounded-md bg-hoverSurface overflow-auto';
|
|
229
252
|
return (
|
|
230
253
|
<div className={mx('flex', type === 'request' ? 'ml-[1rem] justify-end' : 'mr-[1rem]', classNames)}>
|
|
231
254
|
{error && <div className={mx(wrapper, 'whitespace-pre', errorText)}>{String(error)}</div>}
|
|
@@ -25,7 +25,7 @@ const DefaultStory = (props: TypescriptEditorProps) => {
|
|
|
25
25
|
const [result, setResult] = useState<object | undefined>({});
|
|
26
26
|
|
|
27
27
|
// TODO(burdon): Make this work.
|
|
28
|
-
// const object = useMemo(() =>
|
|
28
|
+
// const object = useMemo(() => Text.make(templates[1].source), []);
|
|
29
29
|
// const script = useMemo(
|
|
30
30
|
// () =>
|
|
31
31
|
// Obj.make(ScriptType, {
|
|
@@ -44,7 +44,6 @@ export const TypescriptEditor = ({
|
|
|
44
44
|
id,
|
|
45
45
|
role = 'article',
|
|
46
46
|
inputMode = 'vscode',
|
|
47
|
-
toolbar,
|
|
48
47
|
env,
|
|
49
48
|
options,
|
|
50
49
|
initialValue,
|
|
@@ -66,12 +65,15 @@ export const TypescriptEditor = ({
|
|
|
66
65
|
indentWithTab: true,
|
|
67
66
|
lineNumbers: true,
|
|
68
67
|
lineWrapping: false,
|
|
69
|
-
monospace: true,
|
|
70
68
|
scrollPastEnd: role !== 'section',
|
|
71
69
|
search: true,
|
|
72
70
|
...options,
|
|
73
71
|
}),
|
|
74
|
-
createThemeExtensions({
|
|
72
|
+
createThemeExtensions({
|
|
73
|
+
monospace: true,
|
|
74
|
+
themeMode,
|
|
75
|
+
syntaxHighlighting: true,
|
|
76
|
+
}),
|
|
75
77
|
InputModeExtensions[inputMode],
|
|
76
78
|
|
|
77
79
|
javascript({ typescript: true }),
|
|
@@ -95,14 +97,7 @@ export const TypescriptEditor = ({
|
|
|
95
97
|
);
|
|
96
98
|
|
|
97
99
|
// TODO(brudon): Use react-ui-editor's Editor component.
|
|
98
|
-
return (
|
|
99
|
-
<div
|
|
100
|
-
ref={parentRef}
|
|
101
|
-
data-toolbar={toolbar ? 'enabled' : 'disabled'}
|
|
102
|
-
className={mx(classNames)}
|
|
103
|
-
{...focusAttributes}
|
|
104
|
-
/>
|
|
105
|
-
);
|
|
100
|
+
return <div ref={parentRef} className={mx(classNames)} {...focusAttributes} />;
|
|
106
101
|
};
|
|
107
102
|
|
|
108
103
|
// TODO(burdon): Factor out (react-ui-editor).
|
package/src/hooks/deploy.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { useEffect, useMemo } from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { Function, type Script, getUserFunctionIdInMetadata } from '@dxos/functions';
|
|
8
8
|
import { log } from '@dxos/log';
|
|
9
9
|
import { type Client, useClient } from '@dxos/react-client';
|
|
10
10
|
import { Query, Ref, type Space, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';
|
|
@@ -26,8 +26,8 @@ export type DeployState = {
|
|
|
26
26
|
|
|
27
27
|
export type CreateDeployOptions = {
|
|
28
28
|
state: Partial<DeployState>;
|
|
29
|
-
script:
|
|
30
|
-
fn:
|
|
29
|
+
script: Script.Script;
|
|
30
|
+
fn: Function.Function;
|
|
31
31
|
space?: Space;
|
|
32
32
|
existingFunctionId?: string;
|
|
33
33
|
client: Client;
|
|
@@ -96,7 +96,7 @@ export const createDeploy = ({ state, script, space, fn, client, existingFunctio
|
|
|
96
96
|
};
|
|
97
97
|
};
|
|
98
98
|
|
|
99
|
-
export const useDeployState = ({ state, script }: { state: Partial<DeployState>; script:
|
|
99
|
+
export const useDeployState = ({ state, script }: { state: Partial<DeployState>; script: Script.Script }) => {
|
|
100
100
|
const { space, client, fn, existingFunctionId } = useDeployDeps({ script });
|
|
101
101
|
useEffect(() => {
|
|
102
102
|
if (!existingFunctionId) {
|
|
@@ -115,10 +115,10 @@ export const useDeployState = ({ state, script }: { state: Partial<DeployState>;
|
|
|
115
115
|
}, [script.changed, existingFunctionId, fn, script]);
|
|
116
116
|
};
|
|
117
117
|
|
|
118
|
-
export const useDeployDeps = ({ script }: { script:
|
|
118
|
+
export const useDeployDeps = ({ script }: { script: Script.Script }) => {
|
|
119
119
|
const client = useClient();
|
|
120
120
|
const space = getSpace(script);
|
|
121
|
-
const [fn] = useQuery(space, Query.type(
|
|
121
|
+
const [fn] = useQuery(space, Query.type(Function.Function, { source: Ref.make(script) }));
|
|
122
122
|
const existingFunctionId = useMemo(() => fn && getUserFunctionIdInMetadata(getMeta(fn)), [fn]);
|
|
123
123
|
return { client, space, fn, existingFunctionId };
|
|
124
124
|
};
|
package/src/hooks/format.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { format } from 'prettier';
|
|
|
6
6
|
import prettierPluginEstree from 'prettier/plugins/estree';
|
|
7
7
|
import prettierPluginTypescript from 'prettier/plugins/typescript';
|
|
8
8
|
|
|
9
|
-
import { type
|
|
9
|
+
import { type Script } from '@dxos/functions';
|
|
10
10
|
import { log } from '@dxos/log';
|
|
11
11
|
import { createMenuAction } from '@dxos/react-ui-menu';
|
|
12
12
|
|
|
@@ -14,7 +14,7 @@ import { meta } from '../meta';
|
|
|
14
14
|
|
|
15
15
|
export type FormatActionProperties = { type: 'format' };
|
|
16
16
|
|
|
17
|
-
export const createFormat = (script:
|
|
17
|
+
export const createFormat = (script: Script.Script) => {
|
|
18
18
|
const formatAction = createMenuAction(
|
|
19
19
|
'format',
|
|
20
20
|
async () => {
|
package/src/hooks/template.ts
CHANGED
|
@@ -3,23 +3,14 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { Obj } from '@dxos/echo';
|
|
6
|
-
import { FUNCTIONS_PRESET_META_KEY, type
|
|
7
|
-
import { createMenuAction
|
|
6
|
+
import { FUNCTIONS_PRESET_META_KEY, type Script } from '@dxos/functions';
|
|
7
|
+
import { createMenuAction } from '@dxos/react-ui-menu';
|
|
8
8
|
|
|
9
|
-
import { meta } from '../meta';
|
|
10
9
|
import { templates } from '../templates';
|
|
11
10
|
|
|
12
11
|
export type TemplateActionProperties = { type: 'template'; value: string };
|
|
13
12
|
|
|
14
|
-
const
|
|
15
|
-
// TODO(burdon): This should not be in the toolbar (move to create Object dialog).
|
|
16
|
-
return createMenuItemGroup('template-select', {
|
|
17
|
-
label: ['template select group label', { ns: meta.id }],
|
|
18
|
-
variant: 'dropdownMenu',
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const createTemplateSelectActions = (script: ScriptType) => {
|
|
13
|
+
const createTemplateSelectActions = (script: Script.Script) => {
|
|
23
14
|
return templates.map((template) => {
|
|
24
15
|
return createMenuAction<TemplateActionProperties>(
|
|
25
16
|
`template--${template.id}`,
|
|
@@ -44,11 +35,10 @@ const createTemplateSelectActions = (script: ScriptType) => {
|
|
|
44
35
|
});
|
|
45
36
|
};
|
|
46
37
|
|
|
47
|
-
export const createTemplateSelect = (script:
|
|
48
|
-
const templateSelectGroup = createTemplateSelectGroup();
|
|
38
|
+
export const createTemplateSelect = (script: Script.Script) => {
|
|
49
39
|
const templateSelectActions = createTemplateSelectActions(script);
|
|
50
40
|
return {
|
|
51
|
-
nodes: [
|
|
41
|
+
nodes: [...templateSelectActions],
|
|
52
42
|
edges: [
|
|
53
43
|
{ source: 'root', target: 'template-select' },
|
|
54
44
|
...templateSelectActions.map((action) => ({ source: 'template-select', target: action.id })),
|
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
import * as Function from 'effect/Function';
|
|
6
6
|
import { useCallback, useState } from 'react';
|
|
7
7
|
|
|
8
|
-
import { chain, createIntent
|
|
8
|
+
import { chain, createIntent } from '@dxos/app-framework';
|
|
9
|
+
import { useIntentDispatcher } from '@dxos/app-framework/react';
|
|
9
10
|
import { Obj } from '@dxos/echo';
|
|
10
|
-
import {
|
|
11
|
+
import { Script } from '@dxos/functions';
|
|
11
12
|
import { invariant } from '@dxos/invariant';
|
|
12
13
|
import { SpaceAction } from '@dxos/plugin-space/types';
|
|
13
14
|
import { useClient } from '@dxos/react-client';
|
|
@@ -41,11 +42,14 @@ export const useCreateAndDeployScriptTemplates = (space: Space | undefined, scri
|
|
|
41
42
|
scriptTemplates.map(async (template) => {
|
|
42
43
|
const result = await dispatch(
|
|
43
44
|
Function.pipe(
|
|
44
|
-
createIntent(ScriptAction.CreateScript, {
|
|
45
|
+
createIntent(ScriptAction.CreateScript, {
|
|
46
|
+
space,
|
|
47
|
+
initialTemplateId: template.id as any,
|
|
48
|
+
}),
|
|
45
49
|
chain(SpaceAction.AddObject, { target: space }),
|
|
46
50
|
),
|
|
47
51
|
);
|
|
48
|
-
invariant(Obj.instanceOf(
|
|
52
|
+
invariant(Obj.instanceOf(Script.Script, result.data?.object));
|
|
49
53
|
|
|
50
54
|
return deployScript({ space, client, script: result.data.object });
|
|
51
55
|
}),
|
package/src/meta.ts
CHANGED
|
@@ -3,13 +3,17 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type PluginMeta } from '@dxos/app-framework';
|
|
6
|
+
import { trim } from '@dxos/util';
|
|
6
7
|
|
|
7
8
|
export const meta: PluginMeta = {
|
|
8
9
|
id: 'dxos.org/plugin/script',
|
|
9
10
|
name: 'Scripts',
|
|
10
|
-
description:
|
|
11
|
-
|
|
11
|
+
description: trim`
|
|
12
|
+
Write and deploy custom JavaScript functions that extend your workspace capabilities.
|
|
13
|
+
Create AI agent tools, spreadsheet formulas, and automation scripts that integrate seamlessly with other plugins.
|
|
14
|
+
`,
|
|
12
15
|
icon: 'ph--code--regular',
|
|
16
|
+
iconHue: 'sky',
|
|
13
17
|
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-explorer',
|
|
14
18
|
tags: ['labs'],
|
|
15
19
|
screenshots: ['https://dxos.network/plugin-details-scripts-dark.png'],
|
|
@@ -6,13 +6,13 @@ import { describe, expect, test } from 'vitest';
|
|
|
6
6
|
|
|
7
7
|
import { createNotebook } from '../testing';
|
|
8
8
|
|
|
9
|
-
import { ComputeGraph } from './
|
|
9
|
+
import { ComputeGraph } from './compute-graph';
|
|
10
10
|
|
|
11
11
|
describe('notebook', () => {
|
|
12
|
-
test('parse dependency graph', () => {
|
|
12
|
+
test('parse dependency graph', async () => {
|
|
13
13
|
const notebook = createNotebook();
|
|
14
|
-
const
|
|
15
|
-
const result =
|
|
14
|
+
const graph = new ComputeGraph(notebook);
|
|
15
|
+
const result = graph.parse();
|
|
16
16
|
|
|
17
17
|
const getId = (i: number) => notebook.cells[i].id;
|
|
18
18
|
|
|
@@ -24,7 +24,7 @@ describe('notebook', () => {
|
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
// Compute values.
|
|
27
|
-
const values =
|
|
27
|
+
const values = await graph.evaluate();
|
|
28
28
|
expect(values).toEqual({
|
|
29
29
|
[getId(0)]: 300,
|
|
30
30
|
[getId(2)]: 200,
|
|
@@ -33,36 +33,36 @@ describe('notebook', () => {
|
|
|
33
33
|
});
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
test('evalScript blocks access to window and document', () => {
|
|
36
|
+
test('evalScript blocks access to window and document', async () => {
|
|
37
37
|
const notebook = createNotebook();
|
|
38
38
|
// Replace one of the cells with code that tries to access window/document.
|
|
39
|
-
if (notebook.cells[2].
|
|
40
|
-
notebook.cells[2].
|
|
39
|
+
if (notebook.cells[2].source?.target) {
|
|
40
|
+
notebook.cells[2].source.target.content = 'b = typeof window';
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
const values =
|
|
43
|
+
const graph = new ComputeGraph(notebook);
|
|
44
|
+
graph.parse();
|
|
45
|
+
const values = await graph.evaluate();
|
|
46
46
|
|
|
47
47
|
// Should evaluate to 'undefined' since window is blocked.
|
|
48
48
|
expect(values[notebook.cells[2].id]).toBe('undefined');
|
|
49
49
|
|
|
50
50
|
// Test document access.
|
|
51
|
-
if (notebook.cells[2].
|
|
52
|
-
notebook.cells[2].
|
|
51
|
+
if (notebook.cells[2].source?.target) {
|
|
52
|
+
notebook.cells[2].source.target.content = 'b = typeof document';
|
|
53
53
|
}
|
|
54
|
-
|
|
55
|
-
const values2 =
|
|
54
|
+
graph.parse();
|
|
55
|
+
const values2 = await graph.evaluate();
|
|
56
56
|
|
|
57
57
|
// Should evaluate to 'undefined' since document is blocked.
|
|
58
58
|
expect(values2[notebook.cells[2].id]).toBe('undefined');
|
|
59
59
|
|
|
60
60
|
// Test that safe globals still work.
|
|
61
|
-
if (notebook.cells[2].
|
|
62
|
-
notebook.cells[2].
|
|
61
|
+
if (notebook.cells[2].source?.target) {
|
|
62
|
+
notebook.cells[2].source.target.content = 'b = Math.max(100, 200)';
|
|
63
63
|
}
|
|
64
|
-
|
|
65
|
-
const values3 =
|
|
64
|
+
graph.parse();
|
|
65
|
+
const values3 = await graph.evaluate();
|
|
66
66
|
|
|
67
67
|
// Should evaluate correctly.
|
|
68
68
|
expect(values3[notebook.cells[2].id]).toBe(200);
|
|
@@ -14,11 +14,13 @@ import { type ParsedExpression, VirtualTypeScriptParser } from './vfs-parser';
|
|
|
14
14
|
/**
|
|
15
15
|
* Compute graph that evaluates the notebook cells.
|
|
16
16
|
*/
|
|
17
|
+
// TODO(burdon): Reconcile with @dxos/conductor.
|
|
17
18
|
export class ComputeGraph {
|
|
18
19
|
private readonly _parser = new VirtualTypeScriptParser();
|
|
19
20
|
|
|
20
21
|
private _expressions = signal<Record<string, ParsedExpression>>({});
|
|
21
|
-
private
|
|
22
|
+
private _valuesByCellId = signal<Record<string, any>>({});
|
|
23
|
+
private _valuesByName = signal<Record<string, any>>({});
|
|
22
24
|
|
|
23
25
|
constructor(private readonly _notebook: Notebook.Notebook) {}
|
|
24
26
|
|
|
@@ -33,16 +35,31 @@ export class ComputeGraph {
|
|
|
33
35
|
* Computed values by cell ID.
|
|
34
36
|
*/
|
|
35
37
|
get values(): Signal<Record<string, any>> {
|
|
36
|
-
return this.
|
|
38
|
+
return this._valuesByCellId;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Computed values by name.
|
|
43
|
+
*/
|
|
44
|
+
get valuesByName(): Signal<Record<string, any>> {
|
|
45
|
+
return this._valuesByName;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Get computed value by cell ID.
|
|
50
|
+
*/
|
|
51
|
+
getValue(cellId: string) {
|
|
52
|
+
return this._valuesByCellId.value[cellId];
|
|
37
53
|
}
|
|
38
54
|
|
|
39
55
|
/**
|
|
40
56
|
* Compute values.
|
|
41
57
|
*/
|
|
42
|
-
evaluate() {
|
|
58
|
+
async evaluate() {
|
|
43
59
|
// Parse expressions.
|
|
44
60
|
const { expressions, dependencyGraph } = this.parse();
|
|
45
|
-
this.
|
|
61
|
+
this._valuesByCellId.value = {};
|
|
62
|
+
this._valuesByName.value = {};
|
|
46
63
|
|
|
47
64
|
// Create a map of cell IDs to expressions for easy lookup.
|
|
48
65
|
const cellExpressions = new Map<string, ParsedExpression>();
|
|
@@ -65,7 +82,7 @@ export class ComputeGraph {
|
|
|
65
82
|
continue;
|
|
66
83
|
}
|
|
67
84
|
|
|
68
|
-
const cellSource = this._notebook.cells.find((cell) => cell.id === cellId)?.
|
|
85
|
+
const cellSource = this._notebook.cells.find((cell) => cell.id === cellId)?.source?.target?.content;
|
|
69
86
|
if (!cellSource) {
|
|
70
87
|
log.error('no source for cell', { cellId });
|
|
71
88
|
continue;
|
|
@@ -90,7 +107,7 @@ export class ComputeGraph {
|
|
|
90
107
|
rhs = rhs.slice(0, -1).trim();
|
|
91
108
|
}
|
|
92
109
|
|
|
93
|
-
const result =
|
|
110
|
+
const result = await this.eval(rhs, valuesByName);
|
|
94
111
|
valuesByName[expr.name] = result;
|
|
95
112
|
if (typeof result !== 'function') {
|
|
96
113
|
valuesByCellId[cellId] = result;
|
|
@@ -98,18 +115,24 @@ export class ComputeGraph {
|
|
|
98
115
|
}
|
|
99
116
|
} else {
|
|
100
117
|
// For expressions without assignment, just evaluate.
|
|
101
|
-
const result =
|
|
118
|
+
const result = await this.eval(cellSource, valuesByName);
|
|
102
119
|
valuesByCellId[cellId] = result;
|
|
103
120
|
}
|
|
104
121
|
} catch (error) {
|
|
122
|
+
// TODO(burdon): Set error state.
|
|
105
123
|
log.error('error evaluating cell', { cellId, error });
|
|
106
124
|
}
|
|
107
125
|
}
|
|
108
126
|
|
|
109
|
-
this.
|
|
127
|
+
this._valuesByCellId.value = valuesByCellId;
|
|
128
|
+
this._valuesByName.value = valuesByName;
|
|
110
129
|
return valuesByCellId;
|
|
111
130
|
}
|
|
112
131
|
|
|
132
|
+
private async eval(source: string, values: Record<string, any>) {
|
|
133
|
+
return evalScript(source, values);
|
|
134
|
+
}
|
|
135
|
+
|
|
113
136
|
/**
|
|
114
137
|
* Parse expressions.
|
|
115
138
|
*/
|
|
@@ -117,7 +140,7 @@ export class ComputeGraph {
|
|
|
117
140
|
const expressions = this._notebook.cells
|
|
118
141
|
.filter((cell) => cell.type === 'script')
|
|
119
142
|
.reduce<Record<string, ParsedExpression>>((acc, cell) => {
|
|
120
|
-
const text = cell.
|
|
143
|
+
const text = cell.source?.target?.content.trim();
|
|
121
144
|
if (text) {
|
|
122
145
|
const parsed = this._parser.parseExpression(text);
|
|
123
146
|
acc[cell.id] = parsed;
|
package/src/notebook/eval.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { trim } from '@dxos/util';
|
|
|
7
7
|
/**
|
|
8
8
|
* Evaluate the script (with dependencies as arguments).
|
|
9
9
|
*/
|
|
10
|
-
export const evalScript = (code: string, deps: Record<string, any> = {}) => {
|
|
10
|
+
export const evalScript = async (code: string, deps: Record<string, any> = {}) => {
|
|
11
11
|
// Create a sandboxed environment that blocks access to window and document.
|
|
12
12
|
const sandbox = {
|
|
13
13
|
...deps,
|
package/src/notebook/index.ts
CHANGED
package/src/templates/gmail.ts
CHANGED
|
@@ -175,8 +175,7 @@ const parseFromHeader = (value: string): { name?: string; email: string } | unde
|
|
|
175
175
|
// TODO(wittjosiah): These schemas should be imported from @dxos/schema.
|
|
176
176
|
//
|
|
177
177
|
|
|
178
|
-
const
|
|
179
|
-
const ActorRole = S.Literal(...ActorRoles);
|
|
178
|
+
const ActorRole = S.Literal('user', 'assistant');
|
|
180
179
|
type ActorRole = S.Schema.Type<typeof ActorRole>;
|
|
181
180
|
|
|
182
181
|
const ActorSchema = S.Struct({
|