@dxos/plugin-script 0.8.4-main.dedc0f3 → 0.8.4-main.ead640a
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-65TWT6S5.mjs +13 -0
- package/dist/lib/browser/NotebookContainer-LVGRPFY3.mjs +683 -0
- package/dist/lib/browser/NotebookContainer-LVGRPFY3.mjs.map +7 -0
- package/dist/lib/browser/ScriptContainer-LRTRN7JW.mjs +149 -0
- package/dist/lib/browser/ScriptContainer-LRTRN7JW.mjs.map +7 -0
- package/dist/lib/browser/{app-graph-builder-IABOSTBK.mjs → app-graph-builder-DPYULSME.mjs} +8 -7
- package/dist/lib/browser/app-graph-builder-DPYULSME.mjs.map +7 -0
- package/dist/lib/browser/{blueprint-definition-AR7ITBCD.mjs → blueprint-definition-ET5KZ46I.mjs} +3 -3
- package/dist/lib/browser/{blueprint-definition-AR7ITBCD.mjs.map → blueprint-definition-ET5KZ46I.mjs.map} +1 -1
- package/dist/lib/browser/chunk-5CYLWXRH.mjs +89 -0
- package/dist/lib/browser/chunk-5CYLWXRH.mjs.map +7 -0
- package/dist/lib/browser/chunk-75LH4EUR.mjs +326 -0
- package/dist/lib/browser/chunk-75LH4EUR.mjs.map +7 -0
- package/dist/lib/browser/{chunk-6CAH7VIE.mjs → chunk-E7DXDICD.mjs} +18 -19
- package/dist/lib/browser/chunk-E7DXDICD.mjs.map +7 -0
- package/dist/lib/browser/{chunk-QYAREHGH.mjs → chunk-EZVXV6DA.mjs} +3 -5
- package/dist/lib/browser/chunk-EZVXV6DA.mjs.map +7 -0
- package/dist/lib/browser/{chunk-GZKWMME3.mjs → chunk-I3QSGUFJ.mjs} +122 -32
- package/dist/lib/browser/chunk-I3QSGUFJ.mjs.map +7 -0
- package/dist/lib/browser/{chunk-NXKU3BNX.mjs → chunk-JO2O7W6J.mjs} +39 -7
- package/dist/lib/browser/chunk-JO2O7W6J.mjs.map +7 -0
- package/dist/lib/browser/chunk-N6M34EUC.mjs +112 -0
- package/dist/lib/browser/chunk-N6M34EUC.mjs.map +7 -0
- package/dist/lib/browser/{chunk-YCZPTTFO.mjs → chunk-NM4WQS4F.mjs} +14 -14
- package/dist/lib/browser/chunk-NM4WQS4F.mjs.map +7 -0
- package/dist/lib/browser/{chunk-5TVBECWH.mjs → chunk-OKXN2N7M.mjs} +2 -2
- package/dist/lib/browser/chunk-ST3ACVUC.mjs +88 -0
- package/dist/lib/browser/chunk-ST3ACVUC.mjs.map +7 -0
- package/dist/lib/browser/{compiler-2HJH34GM.mjs → compiler-G2N2CG63.mjs} +5 -5
- package/dist/lib/browser/{compiler-2HJH34GM.mjs.map → compiler-G2N2CG63.mjs.map} +1 -1
- package/dist/lib/browser/index.mjs +107 -36
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/{intent-resolver-F4YSRPJI.mjs → intent-resolver-JLU7DVLQ.mjs} +31 -15
- package/dist/lib/browser/intent-resolver-JLU7DVLQ.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-BBHFU6MI.mjs → react-surface-76SDTUYG.mjs} +36 -13
- package/dist/lib/browser/react-surface-76SDTUYG.mjs.map +7 -0
- package/dist/lib/browser/{settings-KCTBK5TY.mjs → settings-ERFKVNUK.mjs} +9 -8
- package/dist/lib/browser/settings-ERFKVNUK.mjs.map +7 -0
- package/dist/lib/browser/templates/index.mjs +1 -1
- package/dist/lib/browser/types/index.mjs +7 -4
- package/dist/lib/node-esm/{DeploymentDialog-G6EHEPXN.mjs → DeploymentDialog-I63ZC2HH.mjs} +6 -5
- package/dist/lib/node-esm/NotebookContainer-QY5NJGJI.mjs +684 -0
- package/dist/lib/node-esm/NotebookContainer-QY5NJGJI.mjs.map +7 -0
- package/dist/lib/node-esm/ScriptContainer-SVXCSLNH.mjs +150 -0
- package/dist/lib/node-esm/ScriptContainer-SVXCSLNH.mjs.map +7 -0
- package/dist/lib/node-esm/{app-graph-builder-CQTTAYHP.mjs → app-graph-builder-UXJGHXSL.mjs} +8 -7
- package/dist/lib/node-esm/app-graph-builder-UXJGHXSL.mjs.map +7 -0
- package/dist/lib/node-esm/{blueprint-definition-TJY4TX6S.mjs → blueprint-definition-AIYFOT7Q.mjs} +3 -3
- package/dist/lib/node-esm/{blueprint-definition-TJY4TX6S.mjs.map → blueprint-definition-AIYFOT7Q.mjs.map} +1 -1
- package/dist/lib/node-esm/chunk-2GVTWESW.mjs +90 -0
- package/dist/lib/node-esm/chunk-2GVTWESW.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-4X375PGY.mjs +90 -0
- package/dist/lib/node-esm/chunk-4X375PGY.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-67OVZHI3.mjs +327 -0
- package/dist/lib/node-esm/chunk-67OVZHI3.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-ZA36GO4T.mjs → chunk-C2ORIPKH.mjs} +14 -14
- package/dist/lib/node-esm/chunk-C2ORIPKH.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-35M3CHYE.mjs → chunk-NUXZQQ6P.mjs} +2 -2
- package/dist/lib/node-esm/{chunk-AHXJ6NQU.mjs → chunk-OG2SIKHE.mjs} +3 -5
- package/dist/lib/node-esm/chunk-OG2SIKHE.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-HUHVIOL5.mjs → chunk-SMFPSKQT.mjs} +122 -32
- package/dist/lib/node-esm/chunk-SMFPSKQT.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-VRSDE4CI.mjs +114 -0
- package/dist/lib/node-esm/chunk-VRSDE4CI.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-2GBESIHU.mjs → chunk-VZAFGLD7.mjs} +18 -19
- package/dist/lib/node-esm/chunk-VZAFGLD7.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-M642JUOZ.mjs → chunk-YW36TZ7K.mjs} +39 -7
- package/dist/lib/node-esm/chunk-YW36TZ7K.mjs.map +7 -0
- package/dist/lib/node-esm/{compiler-7SP27RA6.mjs → compiler-PLDAZ5GJ.mjs} +5 -5
- package/dist/lib/node-esm/{compiler-7SP27RA6.mjs.map → compiler-PLDAZ5GJ.mjs.map} +1 -1
- package/dist/lib/node-esm/index.mjs +107 -36
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/{intent-resolver-CGQYRWWD.mjs → intent-resolver-SFGTIFOG.mjs} +31 -15
- package/dist/lib/node-esm/intent-resolver-SFGTIFOG.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{react-surface-UWIWPKZD.mjs → react-surface-SHEBNW4R.mjs} +36 -13
- package/dist/lib/node-esm/react-surface-SHEBNW4R.mjs.map +7 -0
- package/dist/lib/node-esm/{settings-DXZ334A3.mjs → settings-5TYXQ42N.mjs} +9 -8
- package/dist/lib/node-esm/settings-5TYXQ42N.mjs.map +7 -0
- package/dist/lib/node-esm/templates/index.mjs +1 -1
- package/dist/lib/node-esm/types/index.mjs +7 -4
- package/dist/types/src/ScriptPlugin.d.ts +1 -1
- package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/capabilities/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 +1 -1
- package/dist/types/src/components/DeploymentDialog/DeploymentDialog.d.ts.map +1 -1
- package/dist/types/src/components/DeploymentDialog/DeploymentDialog.stories.d.ts +111 -5
- package/dist/types/src/components/DeploymentDialog/DeploymentDialog.stories.d.ts.map +1 -1
- package/dist/types/src/components/NotebookContainer.d.ts +10 -0
- package/dist/types/src/components/NotebookContainer.d.ts.map +1 -0
- package/dist/types/src/components/NotebookContainer.stories.d.ts +248 -0
- package/dist/types/src/components/NotebookContainer.stories.d.ts.map +1 -0
- package/dist/types/src/components/NotebookStack/NotebookCell.d.ts +14 -0
- package/dist/types/src/components/NotebookStack/NotebookCell.d.ts.map +1 -0
- package/dist/types/src/components/NotebookStack/NotebookMenu.d.ts +9 -0
- package/dist/types/src/components/NotebookStack/NotebookMenu.d.ts.map +1 -0
- package/dist/types/src/components/NotebookStack/NotebookStack.d.ts +14 -0
- package/dist/types/src/components/NotebookStack/NotebookStack.d.ts.map +1 -0
- package/dist/types/src/components/NotebookStack/NotebookStack.stories.d.ts +248 -0
- package/dist/types/src/components/NotebookStack/NotebookStack.stories.d.ts.map +1 -0
- package/dist/types/src/components/NotebookStack/index.d.ts +3 -0
- package/dist/types/src/components/NotebookStack/index.d.ts.map +1 -0
- package/dist/types/src/components/ScriptContainer.d.ts +2 -2
- package/dist/types/src/components/ScriptContainer.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.stories.d.ts +239 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.stories.d.ts.map +1 -1
- package/dist/types/src/components/Settings/ScriptObjectSettings.d.ts.map +1 -1
- package/dist/types/src/components/Settings/ScriptPluginSettings.d.ts +2 -2
- package/dist/types/src/components/Settings/ScriptPluginSettings.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts +4 -2
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts +3 -3
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +2 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/events.d.ts.map +1 -1
- package/dist/types/src/hooks/deploy.d.ts +6 -6
- package/dist/types/src/hooks/deploy.d.ts.map +1 -1
- package/dist/types/src/hooks/template.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +0 -1
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/notebook/eval.d.ts +13 -0
- package/dist/types/src/notebook/eval.d.ts.map +1 -0
- package/dist/types/src/notebook/index.d.ts +2 -0
- package/dist/types/src/notebook/index.d.ts.map +1 -0
- package/dist/types/src/notebook/notebook.d.ts +35 -0
- package/dist/types/src/notebook/notebook.d.ts.map +1 -0
- package/dist/types/src/notebook/notebook.test.d.ts +2 -0
- package/dist/types/src/notebook/notebook.test.d.ts.map +1 -0
- package/dist/types/src/notebook/vfs-parser.d.ts +74 -0
- package/dist/types/src/notebook/vfs-parser.d.ts.map +1 -0
- package/dist/types/src/notebook/vfs-parser.test.d.ts +2 -0
- package/dist/types/src/notebook/vfs-parser.test.d.ts.map +1 -0
- package/dist/types/src/templates/chess.d.ts.map +1 -1
- package/dist/types/src/templates/data-generator.d.ts.map +1 -1
- package/dist/types/src/templates/discord.d.ts.map +1 -1
- package/dist/types/src/templates/forex-effect.d.ts.map +1 -1
- package/dist/types/src/templates/forex.d.ts.map +1 -1
- package/dist/types/src/templates/gmail.d.ts.map +1 -1
- package/dist/types/src/templates/index.d.ts +43 -1
- package/dist/types/src/templates/index.d.ts.map +1 -1
- package/dist/types/src/templates/{echo.d.ts → ping.d.ts} +1 -1
- package/dist/types/src/templates/ping.d.ts.map +1 -0
- package/dist/types/src/testing/data.d.ts +19 -0
- package/dist/types/src/testing/data.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +2 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +27 -2
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/actions.d.ts +66 -0
- package/dist/types/src/types/actions.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +1 -0
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/schema.d.ts +54 -31
- package/dist/types/src/types/schema.d.ts.map +1 -1
- package/dist/types/src/util/functions.d.ts +5 -2
- package/dist/types/src/util/functions.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +67 -63
- package/src/ScriptPlugin.tsx +93 -68
- package/src/capabilities/app-graph-builder.ts +4 -3
- package/src/capabilities/artifact-definition.ts +1 -1
- package/src/capabilities/intent-resolver.ts +14 -4
- package/src/capabilities/react-surface.tsx +17 -5
- package/src/capabilities/settings.ts +3 -3
- package/src/components/DeploymentDialog/DeploymentDialog.stories.tsx +6 -4
- package/src/components/DeploymentDialog/DeploymentDialog.tsx +11 -17
- package/src/components/NotebookContainer.stories.tsx +32 -0
- package/src/components/NotebookContainer.tsx +124 -0
- package/src/components/NotebookStack/NotebookCell.tsx +217 -0
- package/src/components/NotebookStack/NotebookMenu.tsx +47 -0
- package/src/components/NotebookStack/NotebookStack.stories.tsx +32 -0
- package/src/components/NotebookStack/NotebookStack.tsx +79 -0
- package/src/components/NotebookStack/index.ts +6 -0
- package/src/components/ScriptContainer.tsx +2 -2
- package/src/components/ScriptToolbar/ScriptToolbar.stories.tsx +17 -5
- package/src/components/ScriptToolbar/ScriptToolbar.tsx +21 -24
- package/src/components/Settings/ScriptObjectSettings.tsx +92 -8
- package/src/components/Settings/ScriptPluginSettings.tsx +4 -19
- package/src/components/TestPanel/TestPanel.tsx +5 -5
- package/src/components/TypescriptEditor/TypescriptEditor.stories.tsx +71 -16
- package/src/components/TypescriptEditor/TypescriptEditor.tsx +29 -24
- package/src/components/index.ts +3 -0
- package/src/events.ts +2 -2
- package/src/hooks/deploy.ts +8 -9
- package/src/hooks/format.ts +2 -2
- package/src/hooks/template.ts +4 -3
- package/src/hooks/useCreateAndDeployScriptTemplates.ts +3 -3
- package/src/index.ts +1 -0
- package/src/meta.ts +2 -4
- package/src/notebook/eval.ts +105 -0
- package/src/notebook/index.ts +5 -0
- package/src/notebook/notebook.test.ts +70 -0
- package/src/notebook/notebook.ts +183 -0
- package/src/notebook/vfs-parser.test.ts +149 -0
- package/src/notebook/vfs-parser.ts +451 -0
- package/src/templates/chess.ts +2 -0
- package/src/templates/data-generator.ts +2 -0
- package/src/templates/discord.ts +9 -1
- package/src/templates/forex-effect.ts +5 -1
- package/src/templates/forex.ts +2 -0
- package/src/templates/gmail.ts +21 -9
- package/src/templates/index.ts +6 -6
- package/src/testing/data.ts +47 -0
- package/src/testing/index.ts +5 -0
- package/src/translations.ts +30 -4
- package/src/types/actions.ts +53 -0
- package/src/types/index.ts +1 -0
- package/src/types/schema.ts +30 -19
- package/src/util/functions.ts +32 -3
- package/dist/lib/browser/DeploymentDialog-QZSTVNIS.mjs +0 -12
- package/dist/lib/browser/ScriptContainer-DNNA6XC6.mjs +0 -265
- package/dist/lib/browser/ScriptContainer-DNNA6XC6.mjs.map +0 -7
- package/dist/lib/browser/app-graph-builder-IABOSTBK.mjs.map +0 -7
- package/dist/lib/browser/chunk-6CAH7VIE.mjs.map +0 -7
- package/dist/lib/browser/chunk-GZKWMME3.mjs.map +0 -7
- package/dist/lib/browser/chunk-IS4OG2UW.mjs +0 -39
- package/dist/lib/browser/chunk-IS4OG2UW.mjs.map +0 -7
- package/dist/lib/browser/chunk-NXKU3BNX.mjs.map +0 -7
- package/dist/lib/browser/chunk-QYAREHGH.mjs.map +0 -7
- package/dist/lib/browser/chunk-RNGIQIEJ.mjs +0 -88
- package/dist/lib/browser/chunk-RNGIQIEJ.mjs.map +0 -7
- package/dist/lib/browser/chunk-YCZPTTFO.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-F4YSRPJI.mjs.map +0 -7
- package/dist/lib/browser/react-surface-BBHFU6MI.mjs.map +0 -7
- package/dist/lib/browser/settings-KCTBK5TY.mjs.map +0 -7
- package/dist/lib/node-esm/ScriptContainer-KPYZN2KY.mjs +0 -266
- package/dist/lib/node-esm/ScriptContainer-KPYZN2KY.mjs.map +0 -7
- package/dist/lib/node-esm/app-graph-builder-CQTTAYHP.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-2GBESIHU.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-AHXJ6NQU.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-GWHLP5LM.mjs +0 -90
- package/dist/lib/node-esm/chunk-GWHLP5LM.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-HUHVIOL5.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-JIPFLBYA.mjs +0 -40
- package/dist/lib/node-esm/chunk-JIPFLBYA.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-M642JUOZ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ZA36GO4T.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-CGQYRWWD.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-UWIWPKZD.mjs.map +0 -7
- package/dist/lib/node-esm/settings-DXZ334A3.mjs.map +0 -7
- package/dist/types/src/templates/echo.d.ts.map +0 -1
- /package/dist/lib/browser/{DeploymentDialog-QZSTVNIS.mjs.map → DeploymentDialog-65TWT6S5.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-5TVBECWH.mjs.map → chunk-OKXN2N7M.mjs.map} +0 -0
- /package/dist/lib/node-esm/{DeploymentDialog-G6EHEPXN.mjs.map → DeploymentDialog-I63ZC2HH.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-35M3CHYE.mjs.map → chunk-NUXZQQ6P.mjs.map} +0 -0
- /package/src/templates/{echo.ts → ping.ts} +0 -0
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { createSystem, createVirtualTypeScriptEnvironment } from '@typescript/vfs';
|
|
6
|
+
import ts from 'typescript';
|
|
7
|
+
|
|
8
|
+
import { invariant } from '@dxos/invariant';
|
|
9
|
+
|
|
10
|
+
import { builtIns, systemDefinitions } from './eval';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Default system definitions.
|
|
14
|
+
*/
|
|
15
|
+
const systemFiles: VirtualFile[] = [
|
|
16
|
+
{
|
|
17
|
+
filename: '/lib.d.ts',
|
|
18
|
+
content: systemDefinitions,
|
|
19
|
+
},
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
export type ParsedExpression = {
|
|
23
|
+
name?: string;
|
|
24
|
+
type?: 'function' | 'variable' | 'class' | 'interface';
|
|
25
|
+
value?: any;
|
|
26
|
+
valueType?: string;
|
|
27
|
+
parameters?: Array<{ name: string; type: string }>;
|
|
28
|
+
returnType?: string;
|
|
29
|
+
references?: string[];
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type VirtualFile = {
|
|
33
|
+
filename: string;
|
|
34
|
+
content: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* TypeScript parser using Virtual File System for browser compatibility.
|
|
39
|
+
* This provides full TypeScript analysis including type information.
|
|
40
|
+
*/
|
|
41
|
+
export class VirtualTypeScriptParser {
|
|
42
|
+
protected compilerOptions: ts.CompilerOptions = {
|
|
43
|
+
target: ts.ScriptTarget.ES2020,
|
|
44
|
+
module: ts.ModuleKind.ESNext,
|
|
45
|
+
strict: true,
|
|
46
|
+
esModuleInterop: true,
|
|
47
|
+
skipLibCheck: true,
|
|
48
|
+
forceConsistentCasingInfilenames: true,
|
|
49
|
+
jsx: ts.JsxEmit.React,
|
|
50
|
+
noLib: true, // Don't automatically include default lib files.
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Parse a single expression or statement.
|
|
55
|
+
*/
|
|
56
|
+
parseExpression(input: string): ParsedExpression {
|
|
57
|
+
invariant(input.trim() !== '', 'input must not be empty');
|
|
58
|
+
const files: VirtualFile[] = [{ filename: '/temp.ts', content: input }];
|
|
59
|
+
const analysis = this.analyzeFiles(files);
|
|
60
|
+
|
|
61
|
+
// If no declarations found, check for standalone expression references.
|
|
62
|
+
if (analysis.length === 0) {
|
|
63
|
+
const sourcefilename = '/temp.ts';
|
|
64
|
+
const env = this.createEnvironment([{ filename: sourcefilename, content: input }]);
|
|
65
|
+
const sourceFile = env.getSourceFile(sourcefilename);
|
|
66
|
+
const typeChecker = env.languageService.getProgram()?.getTypeChecker();
|
|
67
|
+
|
|
68
|
+
if (sourceFile && typeChecker) {
|
|
69
|
+
// Check for assignment expressions.
|
|
70
|
+
const assignmentInfo = this.findAssignmentExpression(sourceFile, typeChecker);
|
|
71
|
+
if (assignmentInfo) {
|
|
72
|
+
return assignmentInfo;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const references = this.findAllReferences(sourceFile, typeChecker);
|
|
76
|
+
return { references };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return analysis[0];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Analyze multiple files with full type information.
|
|
85
|
+
*/
|
|
86
|
+
analyzeFiles(files: VirtualFile[]): ParsedExpression[] {
|
|
87
|
+
const env = this.createEnvironment(files);
|
|
88
|
+
const results: ParsedExpression[] = [];
|
|
89
|
+
const typeChecker = env.languageService.getProgram()?.getTypeChecker();
|
|
90
|
+
|
|
91
|
+
// Analyze each file.
|
|
92
|
+
files.forEach((file) => {
|
|
93
|
+
const sourceFile = env.getSourceFile(file.filename);
|
|
94
|
+
if (!sourceFile || !typeChecker) return;
|
|
95
|
+
|
|
96
|
+
const fileResults = this.analyzeSourceFile(sourceFile, typeChecker);
|
|
97
|
+
results.push(...fileResults);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
return results;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Analyze a source file with type information.
|
|
105
|
+
*/
|
|
106
|
+
protected analyzeSourceFile(sourceFile: ts.SourceFile, typeChecker: ts.TypeChecker): ParsedExpression[] {
|
|
107
|
+
const results: ParsedExpression[] = [];
|
|
108
|
+
|
|
109
|
+
const visit = (node: ts.Node) => {
|
|
110
|
+
// Function declarations.
|
|
111
|
+
if (ts.isFunctionDeclaration(node) && node.name) {
|
|
112
|
+
const symbol = typeChecker.getSymbolAtLocation(node.name);
|
|
113
|
+
const type = symbol && typeChecker.getTypeOfSymbolAtLocation(symbol, node);
|
|
114
|
+
const signature = type && typeChecker.getSignaturesOfType(type, ts.SignatureKind.Call)[0];
|
|
115
|
+
|
|
116
|
+
results.push({
|
|
117
|
+
name: node.name.text,
|
|
118
|
+
type: 'function',
|
|
119
|
+
parameters: this.extractParameters(signature, typeChecker),
|
|
120
|
+
returnType: signature ? typeChecker.typeToString(signature.getReturnType()) : 'any',
|
|
121
|
+
references: this.findReferences(node, sourceFile, typeChecker),
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Variable declarations.
|
|
126
|
+
else if (ts.isVariableStatement(node)) {
|
|
127
|
+
node.declarationList.declarations.forEach((declaration) => {
|
|
128
|
+
if (ts.isIdentifier(declaration.name)) {
|
|
129
|
+
const symbol = typeChecker.getSymbolAtLocation(declaration.name);
|
|
130
|
+
const type = symbol && typeChecker.getTypeOfSymbolAtLocation(symbol, declaration);
|
|
131
|
+
|
|
132
|
+
let kind: 'function' | 'variable' = 'variable';
|
|
133
|
+
let parameters: Array<{ name: string; type: string }> | undefined;
|
|
134
|
+
let returnType: string | undefined;
|
|
135
|
+
let value: any;
|
|
136
|
+
|
|
137
|
+
// Get the type string.
|
|
138
|
+
const typeString = type ? typeChecker.typeToString(type) : 'any';
|
|
139
|
+
|
|
140
|
+
// Check if it's a function.
|
|
141
|
+
if (declaration.initializer) {
|
|
142
|
+
if (ts.isArrowFunction(declaration.initializer) || ts.isFunctionExpression(declaration.initializer)) {
|
|
143
|
+
kind = 'function';
|
|
144
|
+
const funcType = typeChecker.getTypeAtLocation(declaration.initializer);
|
|
145
|
+
const signature = typeChecker.getSignaturesOfType(funcType, ts.SignatureKind.Call)[0];
|
|
146
|
+
if (signature) {
|
|
147
|
+
parameters = this.extractParameters(signature, typeChecker);
|
|
148
|
+
returnType = typeChecker.typeToString(signature.getReturnType());
|
|
149
|
+
}
|
|
150
|
+
} else {
|
|
151
|
+
// Extract literal values
|
|
152
|
+
if (ts.isNumericLiteral(declaration.initializer)) {
|
|
153
|
+
value = Number(declaration.initializer.text);
|
|
154
|
+
} else if (ts.isStringLiteral(declaration.initializer)) {
|
|
155
|
+
value = declaration.initializer.text;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Find references in the initializer only.
|
|
161
|
+
const refs = declaration.initializer
|
|
162
|
+
? this.findReferences(declaration.initializer, sourceFile, typeChecker)
|
|
163
|
+
: [];
|
|
164
|
+
|
|
165
|
+
results.push({
|
|
166
|
+
name: declaration.name.text,
|
|
167
|
+
type: kind,
|
|
168
|
+
valueType: typeString,
|
|
169
|
+
value,
|
|
170
|
+
parameters,
|
|
171
|
+
returnType,
|
|
172
|
+
references: refs,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Class declarations.
|
|
179
|
+
else if (ts.isClassDeclaration(node) && node.name) {
|
|
180
|
+
results.push({
|
|
181
|
+
name: node.name.text,
|
|
182
|
+
type: 'class',
|
|
183
|
+
references: this.findReferences(node, sourceFile, typeChecker),
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Interface declarations.
|
|
188
|
+
else if (ts.isInterfaceDeclaration(node)) {
|
|
189
|
+
results.push({
|
|
190
|
+
name: node.name.text,
|
|
191
|
+
type: 'interface',
|
|
192
|
+
references: this.findReferences(node, sourceFile, typeChecker),
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
ts.forEachChild(node, visit);
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
visit(sourceFile);
|
|
200
|
+
return results;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Extract parameter information from a signature.
|
|
205
|
+
*/
|
|
206
|
+
private extractParameters(
|
|
207
|
+
signature: ts.Signature | undefined,
|
|
208
|
+
typeChecker: ts.TypeChecker,
|
|
209
|
+
): Array<{ name: string; type: string }> {
|
|
210
|
+
if (!signature) return [];
|
|
211
|
+
|
|
212
|
+
return signature.parameters.map((param) => ({
|
|
213
|
+
name: param.getName(),
|
|
214
|
+
type: typeChecker.typeToString(typeChecker.getTypeOfSymbolAtLocation(param, param.valueDeclaration!)),
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Find all references to variables used in a node.
|
|
220
|
+
*/
|
|
221
|
+
private findReferences(node: ts.Node, _sourceFile: ts.SourceFile, _typeChecker: ts.TypeChecker): string[] {
|
|
222
|
+
const references = new Set<string>();
|
|
223
|
+
const localSymbols = new Set<string>();
|
|
224
|
+
|
|
225
|
+
// First, collect local symbols (parameters, local variables).
|
|
226
|
+
const collectLocalSymbols = (node: ts.Node) => {
|
|
227
|
+
if (ts.isFunctionDeclaration(node) || ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
|
|
228
|
+
node.parameters.forEach((param) => {
|
|
229
|
+
if (ts.isIdentifier(param.name)) {
|
|
230
|
+
localSymbols.add(param.name.text);
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name)) {
|
|
236
|
+
localSymbols.add(node.name.text);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
ts.forEachChild(node, collectLocalSymbols);
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
collectLocalSymbols(node);
|
|
243
|
+
|
|
244
|
+
// Then find all identifier references.
|
|
245
|
+
const findRefs = (node: ts.Node) => {
|
|
246
|
+
if (ts.isIdentifier(node)) {
|
|
247
|
+
// Skip if it's a local symbol.
|
|
248
|
+
if (!localSymbols.has(node.text)) {
|
|
249
|
+
// Check if it's a reference (not a declaration).
|
|
250
|
+
const parent = node.parent;
|
|
251
|
+
const isDeclaration =
|
|
252
|
+
(ts.isVariableDeclaration(parent) && parent.name === node) ||
|
|
253
|
+
(ts.isFunctionDeclaration(parent) && parent.name === node) ||
|
|
254
|
+
(ts.isParameter(parent) && parent.name === node);
|
|
255
|
+
|
|
256
|
+
if (!isDeclaration && !this.isBuiltIn(node.text)) {
|
|
257
|
+
references.add(node.text);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
ts.forEachChild(node, findRefs);
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
findRefs(node);
|
|
265
|
+
return Array.from(references);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Check if a name is a built-in global.
|
|
270
|
+
*/
|
|
271
|
+
protected isBuiltIn(name: string): boolean {
|
|
272
|
+
return builtIns.has(name);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Find assignment expressions in a source file.
|
|
277
|
+
*/
|
|
278
|
+
private findAssignmentExpression(sourceFile: ts.SourceFile, typeChecker: ts.TypeChecker): ParsedExpression | null {
|
|
279
|
+
let result: ParsedExpression | null = null;
|
|
280
|
+
|
|
281
|
+
const visit = (node: ts.Node) => {
|
|
282
|
+
if (ts.isExpressionStatement(node) && ts.isBinaryExpression(node.expression)) {
|
|
283
|
+
const expr = node.expression;
|
|
284
|
+
if (expr.operatorToken.kind === ts.SyntaxKind.EqualsToken && ts.isIdentifier(expr.left)) {
|
|
285
|
+
const type = typeChecker.getTypeAtLocation(expr.right);
|
|
286
|
+
const typeString = typeChecker.typeToString(type);
|
|
287
|
+
|
|
288
|
+
// Get the literal value if it's a literal.
|
|
289
|
+
let value: any;
|
|
290
|
+
if (ts.isNumericLiteral(expr.right)) {
|
|
291
|
+
value = Number(expr.right.text);
|
|
292
|
+
} else if (ts.isStringLiteral(expr.right)) {
|
|
293
|
+
value = expr.right.text;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Find references in the right-hand side.
|
|
297
|
+
const references = this.findReferences(expr.right, sourceFile, typeChecker);
|
|
298
|
+
|
|
299
|
+
result = {
|
|
300
|
+
name: expr.left.text,
|
|
301
|
+
type: 'variable',
|
|
302
|
+
valueType: typeString,
|
|
303
|
+
value,
|
|
304
|
+
references,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
if (!result) {
|
|
309
|
+
ts.forEachChild(node, visit);
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
visit(sourceFile);
|
|
314
|
+
return result;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Find all identifier references in a source file.
|
|
319
|
+
*/
|
|
320
|
+
protected findAllReferences(sourceFile: ts.SourceFile, _typeChecker: ts.TypeChecker): string[] {
|
|
321
|
+
const references = new Set<string>();
|
|
322
|
+
|
|
323
|
+
const visit = (node: ts.Node) => {
|
|
324
|
+
if (ts.isIdentifier(node)) {
|
|
325
|
+
// Skip if it's a declaration.
|
|
326
|
+
const parent = node.parent;
|
|
327
|
+
const isDeclaration =
|
|
328
|
+
(ts.isVariableDeclaration(parent) && parent.name === node) ||
|
|
329
|
+
(ts.isFunctionDeclaration(parent) && parent.name === node) ||
|
|
330
|
+
(ts.isParameter(parent) && parent.name === node);
|
|
331
|
+
|
|
332
|
+
// Skip if it's the left-hand side of an assignment.
|
|
333
|
+
const isAssignmentTarget =
|
|
334
|
+
ts.isBinaryExpression(parent) &&
|
|
335
|
+
parent.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
|
|
336
|
+
parent.left === node;
|
|
337
|
+
|
|
338
|
+
if (!isDeclaration && !isAssignmentTarget && !this.isBuiltIn(node.text)) {
|
|
339
|
+
references.add(node.text);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
ts.forEachChild(node, visit);
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
visit(sourceFile);
|
|
346
|
+
return Array.from(references);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
protected createEnvironment(files: VirtualFile[]) {
|
|
350
|
+
const allFiles = [...systemFiles, ...files];
|
|
351
|
+
|
|
352
|
+
const fileMap = new Map<string, string>();
|
|
353
|
+
allFiles.forEach(({ filename, content }) => {
|
|
354
|
+
fileMap.set(filename, content);
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
const system = createSystem(fileMap);
|
|
358
|
+
return createVirtualTypeScriptEnvironment(
|
|
359
|
+
system,
|
|
360
|
+
allFiles.map(({ filename }) => filename),
|
|
361
|
+
ts,
|
|
362
|
+
this.compilerOptions,
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Notebook-specific parser with dependency analysis.
|
|
369
|
+
*/
|
|
370
|
+
export class NotebookVirtualParser extends VirtualTypeScriptParser {
|
|
371
|
+
/**
|
|
372
|
+
* Analyze notebook cells with full type checking.
|
|
373
|
+
*/
|
|
374
|
+
analyzeNotebook(cells: Array<{ id: string; code: string }>) {
|
|
375
|
+
// Create cumulative environment where each cell can see previous cells.
|
|
376
|
+
const cumulativeCode: string[] = [];
|
|
377
|
+
const cellAnalysis: Map<
|
|
378
|
+
string,
|
|
379
|
+
{
|
|
380
|
+
exports: ParsedExpression[];
|
|
381
|
+
imports: string[];
|
|
382
|
+
errors: ts.Diagnostic[];
|
|
383
|
+
}
|
|
384
|
+
> = new Map();
|
|
385
|
+
|
|
386
|
+
cells.forEach((cell) => {
|
|
387
|
+
// Create files for all cells up to current.
|
|
388
|
+
const files: VirtualFile[] = [];
|
|
389
|
+
|
|
390
|
+
// Add previous cells as context.
|
|
391
|
+
if (cumulativeCode.length > 0) {
|
|
392
|
+
files.push({
|
|
393
|
+
filename: '/context.ts',
|
|
394
|
+
content: cumulativeCode.join('\n'),
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// Add current cell.
|
|
399
|
+
const filename = `/cell/${cell.id}.ts`;
|
|
400
|
+
files.push({
|
|
401
|
+
filename,
|
|
402
|
+
content: cell.code,
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
// Create environment.
|
|
406
|
+
const env = this.createEnvironment(files);
|
|
407
|
+
|
|
408
|
+
// Get diagnostics (errors).
|
|
409
|
+
const diagnostics = env.languageService.getSemanticDiagnostics(filename);
|
|
410
|
+
|
|
411
|
+
// Analyze current cell.
|
|
412
|
+
const sourceFile = env.getSourceFile(filename);
|
|
413
|
+
const typeChecker = env.languageService.getProgram()?.getTypeChecker();
|
|
414
|
+
|
|
415
|
+
if (sourceFile && typeChecker) {
|
|
416
|
+
const exports = this.analyzeSourceFile(sourceFile, typeChecker);
|
|
417
|
+
|
|
418
|
+
// Find all references in the current cell.
|
|
419
|
+
const allRefs = new Set<string>();
|
|
420
|
+
exports.forEach((exp) => {
|
|
421
|
+
exp.references?.forEach((ref) => allRefs.add(ref));
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
// Also check for references not in exports (e.g., console.log(y)).
|
|
425
|
+
const additionalRefs = this.findAllReferences(sourceFile, typeChecker);
|
|
426
|
+
additionalRefs.forEach((ref) => allRefs.add(ref));
|
|
427
|
+
|
|
428
|
+
// Determine which references are imports from previous cells.
|
|
429
|
+
const previousExports = new Set<string>();
|
|
430
|
+
for (const [_prevCellId, prevAnalysis] of cellAnalysis) {
|
|
431
|
+
prevAnalysis.exports.forEach((exp) => {
|
|
432
|
+
if (exp.name) previousExports.add(exp.name);
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const imports = Array.from(allRefs).filter((ref) => previousExports.has(ref));
|
|
437
|
+
|
|
438
|
+
cellAnalysis.set(cell.id, {
|
|
439
|
+
exports,
|
|
440
|
+
imports,
|
|
441
|
+
errors: diagnostics,
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// Add current cell code to cumulative.
|
|
446
|
+
cumulativeCode.push(cell.code);
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
return cellAnalysis;
|
|
450
|
+
}
|
|
451
|
+
}
|
package/src/templates/chess.ts
CHANGED
|
@@ -8,6 +8,8 @@ import { S, defineFunction } from 'dxos:functions';
|
|
|
8
8
|
import { Chess } from 'https://esm.sh/chess.js@0.13.1?bundle=false';
|
|
9
9
|
|
|
10
10
|
export default defineFunction({
|
|
11
|
+
key: 'dxos.org/script/chess',
|
|
12
|
+
name: 'Chess',
|
|
11
13
|
description: 'Plays a random move in a chess game.',
|
|
12
14
|
|
|
13
15
|
inputSchema: S.Struct({
|
|
@@ -8,6 +8,8 @@ import { Expando, S, create, defineFunction } from 'dxos:functions';
|
|
|
8
8
|
import { randText } from 'https://esm.sh/@ngneat/falso@7.1.1?bundle=false';
|
|
9
9
|
|
|
10
10
|
export default defineFunction({
|
|
11
|
+
key: 'dxos.org/script/data-generator',
|
|
12
|
+
name: 'Data Generator',
|
|
11
13
|
inputSchema: S.Struct({
|
|
12
14
|
documentAmount: S.optional(S.Number),
|
|
13
15
|
textSize: S.optional(S.Number),
|
package/src/templates/discord.ts
CHANGED
|
@@ -13,7 +13,13 @@ import {
|
|
|
13
13
|
// @ts-ignore
|
|
14
14
|
} from 'https://esm.sh/dfx@0.113.0?deps=effect@3.17.0&bundle=false';
|
|
15
15
|
// @ts-ignore
|
|
16
|
-
import
|
|
16
|
+
import * as Config from 'https://esm.sh/effect@3.17.0/Config?bundle=false';
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
import * as Effect from 'https://esm.sh/effect@3.17.0/Effect?bundle=false';
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
import * as Redacted from 'https://esm.sh/effect@3.17.0/Redacted?bundle=false';
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
import * as Ref from 'https://esm.sh/effect@3.17.0/Ref?bundle=false';
|
|
17
23
|
|
|
18
24
|
const MessageSchema = S.Struct({
|
|
19
25
|
id: ObjectId,
|
|
@@ -36,6 +42,8 @@ const generateSnowflake = (unixTimestamp: number): bigint => {
|
|
|
36
42
|
};
|
|
37
43
|
|
|
38
44
|
export default defineFunction({
|
|
45
|
+
key: 'dxos.org/script/discord',
|
|
46
|
+
name: 'Discord',
|
|
39
47
|
inputSchema: S.Struct({
|
|
40
48
|
// TODO(wittjosiah): Remove. This is used to provide a terminal for a cron trigger.
|
|
41
49
|
tick: S.optional(S.String),
|
|
@@ -11,9 +11,13 @@ import {
|
|
|
11
11
|
// @ts-ignore
|
|
12
12
|
} from 'https://esm.sh/@effect/platform@0.89.0?deps=effect@3.17.0&bundle=false';
|
|
13
13
|
// @ts-ignore
|
|
14
|
-
import
|
|
14
|
+
import * as Effect from 'https://esm.sh/effect@3.17.0/Effect?bundle=false';
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
import * as Schedule from 'https://esm.sh/effect@3.17.0/Schedule?bundle=false';
|
|
15
17
|
|
|
16
18
|
export default defineFunction({
|
|
19
|
+
key: 'dxos.org/script/forex-effect',
|
|
20
|
+
name: 'Forex Effect',
|
|
17
21
|
description: 'Returns the exchange rate between two currencies.',
|
|
18
22
|
|
|
19
23
|
inputSchema: S.Struct({
|
package/src/templates/forex.ts
CHANGED
package/src/templates/gmail.ts
CHANGED
|
@@ -14,9 +14,21 @@ import {
|
|
|
14
14
|
// @ts-ignore
|
|
15
15
|
import { format, subDays } from 'https://esm.sh/date-fns@3.3.1?bundle=false';
|
|
16
16
|
// @ts-ignore
|
|
17
|
-
import
|
|
17
|
+
import * as Chunk from 'https://esm.sh/effect@3.17.0/Chunk?bundle=false';
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
import * as Effect from 'https://esm.sh/effect@3.17.0/Effect?bundle=false';
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
import * as Function from 'https://esm.sh/effect@3.17.0/Function?bundle=false';
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
import * as Ref from 'https://esm.sh/effect@3.17.0/Ref?bundle=false';
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
import * as Schedule from 'https://esm.sh/effect@3.17.0/Schedule?bundle=false';
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
import * as Stream from 'https://esm.sh/effect@3.17.0/Stream?bundle=false';
|
|
18
28
|
|
|
19
29
|
export default defineFunction({
|
|
30
|
+
key: 'dxos.org/script/gmail',
|
|
31
|
+
name: 'Gmail',
|
|
20
32
|
inputSchema: S.Struct({
|
|
21
33
|
mailboxId: S.String,
|
|
22
34
|
userId: S.optional(S.String).pipe(S.withDecodingDefault(() => 'me')),
|
|
@@ -41,7 +53,7 @@ export default defineFunction({
|
|
|
41
53
|
|
|
42
54
|
// NOTE: Google API bundles size is v. large and caused runtime issues.
|
|
43
55
|
const makeRequest = (url: string) =>
|
|
44
|
-
pipe(
|
|
56
|
+
Function.pipe(
|
|
45
57
|
url,
|
|
46
58
|
HttpClientRequest.get,
|
|
47
59
|
HttpClientRequest.setHeaders({ Authorization: `Bearer ${token}`, Accept: 'application/json' }),
|
|
@@ -80,7 +92,7 @@ export default defineFunction({
|
|
|
80
92
|
const messageDetails = yield* getMessage(userId, message.id);
|
|
81
93
|
const created = new Date(parseInt(messageDetails.internalDate)).toISOString();
|
|
82
94
|
const from = messageDetails.payload.headers.find((h: any) => h.name === 'From');
|
|
83
|
-
const sender = from &&
|
|
95
|
+
const sender = from && parseFromHeader(from.value);
|
|
84
96
|
// TODO(wittjosiah): Improve parsing of email contents.
|
|
85
97
|
const content =
|
|
86
98
|
messageDetails.payload.body?.data ??
|
|
@@ -114,7 +126,7 @@ export default defineFunction({
|
|
|
114
126
|
|
|
115
127
|
const queueMessages = yield* Ref.get(newMessages);
|
|
116
128
|
if (queueMessages.length > 0) {
|
|
117
|
-
yield* pipe(
|
|
129
|
+
yield* Function.pipe(
|
|
118
130
|
queueMessages,
|
|
119
131
|
Stream.fromIterable,
|
|
120
132
|
Stream.grouped(10),
|
|
@@ -145,17 +157,17 @@ const getUrl = (userId: string, messageId?: string, params?: Record<string, any>
|
|
|
145
157
|
/**
|
|
146
158
|
* Parses an email string in the format "Name <email@example.com>" into separate name and email components.
|
|
147
159
|
*/
|
|
148
|
-
const
|
|
149
|
-
const
|
|
160
|
+
const parseFromHeader = (value: string): { name?: string; email: string } | undefined => {
|
|
161
|
+
const EMAIL_REGEX = /^([^<]+?)\s*<([^>]+@[^>]+)>$/;
|
|
162
|
+
const removeOuterQuotes = (str: string) => str.replace(/^['"]|['"]$/g, '');
|
|
163
|
+
const match = value.match(EMAIL_REGEX);
|
|
150
164
|
if (match) {
|
|
151
165
|
const [, name, email] = match;
|
|
152
166
|
return {
|
|
153
|
-
name: name.trim(),
|
|
167
|
+
name: removeOuterQuotes(name.trim()),
|
|
154
168
|
email: email.trim(),
|
|
155
169
|
};
|
|
156
170
|
}
|
|
157
|
-
|
|
158
|
-
return undefined;
|
|
159
171
|
};
|
|
160
172
|
|
|
161
173
|
//
|
package/src/templates/index.ts
CHANGED
|
@@ -6,11 +6,11 @@ import chat from './chat.ts?raw';
|
|
|
6
6
|
import chess from './chess.ts?raw';
|
|
7
7
|
import dataGenerator from './data-generator.ts?raw';
|
|
8
8
|
import discord from './discord.ts?raw';
|
|
9
|
-
import echo from './echo.ts?raw';
|
|
10
9
|
import email from './email.ts?raw';
|
|
11
10
|
import forexEffect from './forex-effect.ts?raw';
|
|
12
11
|
import forex from './forex.ts?raw';
|
|
13
12
|
import gmail from './gmail.ts?raw';
|
|
13
|
+
import ping from './ping.ts?raw';
|
|
14
14
|
|
|
15
15
|
const removeHeader = (str: string) => str.split('\n').slice(4).join('\n');
|
|
16
16
|
|
|
@@ -23,11 +23,11 @@ export type Template = {
|
|
|
23
23
|
presetId?: string;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
export const templates
|
|
26
|
+
export const templates = [
|
|
27
27
|
{
|
|
28
|
-
id: 'dxos.org/script/
|
|
29
|
-
name: '
|
|
30
|
-
source: removeHeader(
|
|
28
|
+
id: 'dxos.org/script/ping',
|
|
29
|
+
name: 'Ping',
|
|
30
|
+
source: removeHeader(ping),
|
|
31
31
|
},
|
|
32
32
|
{
|
|
33
33
|
id: 'dxos.org/script/forex',
|
|
@@ -75,4 +75,4 @@ export const templates: Template[] = [
|
|
|
75
75
|
source: removeHeader(dataGenerator),
|
|
76
76
|
presetId: 'dxos.org/function/data-generator',
|
|
77
77
|
},
|
|
78
|
-
];
|
|
78
|
+
] as const;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Ref } from '@dxos/echo';
|
|
6
|
+
import { createObject } from '@dxos/echo-db';
|
|
7
|
+
import { PublicKey } from '@dxos/keys';
|
|
8
|
+
import { DataType } from '@dxos/schema';
|
|
9
|
+
|
|
10
|
+
import { Notebook } from '../types';
|
|
11
|
+
|
|
12
|
+
// NOTE: createObject(DataType.makeText is required to make codemirror work.
|
|
13
|
+
export const createNotebook = () =>
|
|
14
|
+
Notebook.make({
|
|
15
|
+
cells: [
|
|
16
|
+
{
|
|
17
|
+
id: PublicKey.random().toString(),
|
|
18
|
+
type: 'script',
|
|
19
|
+
script: Ref.make(createObject(DataType.makeText(['c = a() + b', '', ''].join('\n')))),
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: PublicKey.random().toString(),
|
|
23
|
+
type: 'script',
|
|
24
|
+
script: Ref.make(createObject(DataType.makeText(['a = () => 100', ''].join('\n')))),
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
id: PublicKey.random().toString(),
|
|
28
|
+
type: 'script',
|
|
29
|
+
script: Ref.make(createObject(DataType.makeText(['b = 200'].join('\n')))),
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: PublicKey.random().toString(),
|
|
33
|
+
type: 'script',
|
|
34
|
+
script: Ref.make(createObject(DataType.makeText(['d = a() * 2'].join('\n')))),
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: PublicKey.random().toString(),
|
|
38
|
+
type: 'script',
|
|
39
|
+
script: Ref.make(createObject(DataType.makeText(['c + d', '', '', ''].join('\n')))),
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: PublicKey.random().toString(),
|
|
43
|
+
type: 'query',
|
|
44
|
+
script: Ref.make(createObject(DataType.makeText('#test'))),
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
});
|