@dxos/plugin-script 0.9.1-main.c7dcc2e112 → 0.10.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/PLUGIN.mdl +9 -9
- package/dist/lib/neutral/{NotebookArticle-E35G2Y2I.mjs → NotebookArticle-AOBB3XGD.mjs} +27 -45
- package/dist/lib/neutral/NotebookArticle-AOBB3XGD.mjs.map +7 -0
- package/dist/lib/neutral/{ScriptArticle-QW26LOKU.mjs → ScriptArticle-I3DOJARR.mjs} +4 -4
- package/dist/lib/neutral/ScriptArticle-I3DOJARR.mjs.map +7 -0
- package/dist/lib/neutral/ScriptPlugin.mjs +4 -4
- package/dist/lib/neutral/ScriptPlugin.mjs.map +3 -3
- package/dist/lib/neutral/ScriptPlugin.node.mjs +3 -3
- package/dist/lib/neutral/ScriptPlugin.node.mjs.map +3 -3
- package/dist/lib/neutral/{ScriptProperties-ADTWXG6O.mjs → ScriptProperties-RHDQGMGT.mjs} +148 -148
- package/dist/lib/neutral/ScriptProperties-RHDQGMGT.mjs.map +7 -0
- package/dist/lib/neutral/ScriptSettings-NS3ZY7ZR.mjs +35 -0
- package/dist/lib/neutral/ScriptSettings-NS3ZY7ZR.mjs.map +7 -0
- package/dist/lib/neutral/capabilities/index.mjs +6 -6
- package/dist/lib/neutral/capabilities/index.mjs.map +3 -3
- package/dist/lib/neutral/capabilities/node.mjs +5 -5
- package/dist/lib/neutral/capabilities/node.mjs.map +3 -3
- package/dist/lib/neutral/{chunk-ZPFRRBZW.mjs → chunk-652CIABA.mjs} +10 -9
- package/dist/lib/neutral/chunk-652CIABA.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-TRKXIP2Q.mjs → chunk-6DOWVKIW.mjs} +4 -5
- package/dist/lib/neutral/chunk-6DOWVKIW.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-BDHDBPVM.mjs → chunk-CHNFYLKW.mjs} +12 -12
- package/dist/lib/neutral/chunk-CHNFYLKW.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-VXDJH6OL.mjs → chunk-INFWOSTM.mjs} +14 -8
- package/dist/lib/neutral/chunk-INFWOSTM.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-JAJ64B3E.mjs → chunk-KSVKXCTX.mjs} +2 -2
- package/dist/lib/neutral/chunk-USJ44FIU.mjs +8 -0
- package/dist/lib/neutral/{chunk-O6A5PTB3.mjs.map → chunk-USJ44FIU.mjs.map} +1 -1
- package/dist/lib/neutral/{chunk-QV6NCUGM.mjs → chunk-WAGQ77UQ.mjs} +6 -6
- package/dist/lib/neutral/chunk-WAGQ77UQ.mjs.map +7 -0
- package/dist/lib/neutral/components/index.mjs +120 -91
- package/dist/lib/neutral/components/index.mjs.map +4 -4
- package/dist/lib/neutral/containers/index.mjs +5 -3
- package/dist/lib/neutral/containers/index.mjs.map +3 -3
- package/dist/lib/neutral/{create-6LC57CCC.mjs → create-SGHWWTET.mjs} +4 -4
- package/dist/lib/neutral/{create-6LC57CCC.mjs.map → create-SGHWWTET.mjs.map} +4 -4
- package/dist/lib/neutral/{create-object-FZM5ASWM.mjs → create-object-QW66KQWS.mjs} +1 -3
- package/dist/lib/neutral/{create-object-FZM5ASWM.mjs.map → create-object-QW66KQWS.mjs.map} +3 -3
- package/dist/lib/neutral/{create-script-YW437XYZ.mjs → create-script-CIEJOBIU.mjs} +4 -4
- package/dist/lib/neutral/{create-script-YW437XYZ.mjs.map → create-script-CIEJOBIU.mjs.map} +3 -3
- package/dist/lib/neutral/{delete-HCQIQFVP.mjs → delete-72RXVLVI.mjs} +3 -3
- package/dist/lib/neutral/{delete-HCQIQFVP.mjs.map → delete-72RXVLVI.mjs.map} +1 -1
- package/dist/lib/neutral/{deploy-7JVMMHSH.mjs → deploy-PJTJAQZY.mjs} +10 -6
- package/dist/lib/neutral/deploy-PJTJAQZY.mjs.map +7 -0
- package/dist/lib/neutral/hooks/index.mjs +2 -2
- package/dist/lib/neutral/hooks/index.mjs.map +2 -2
- package/dist/lib/neutral/index.mjs +8 -8
- package/dist/lib/neutral/{inspect-invocations-TAOYDT4H.mjs → inspect-invocations-ZUXVUAML.mjs} +5 -5
- package/dist/lib/neutral/inspect-invocations-ZUXVUAML.mjs.map +7 -0
- package/dist/lib/neutral/{install-function-FJIE2JAI.mjs → install-function-YFDZLVMJ.mjs} +4 -4
- package/dist/lib/neutral/{install-function-FJIE2JAI.mjs.map → install-function-YFDZLVMJ.mjs.map} +1 -1
- package/dist/lib/neutral/{invoke-3HVWY2KF.mjs → invoke-CDRBQ2WA.mjs} +4 -4
- package/dist/lib/neutral/{invoke-3HVWY2KF.mjs.map → invoke-CDRBQ2WA.mjs.map} +1 -1
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/lib/neutral/{operation-handler-6IZ7L4L2.mjs → operation-handler-M3B6IRMV.mjs} +3 -3
- package/dist/lib/neutral/{operation-handler-6IZ7L4L2.mjs.map → operation-handler-M3B6IRMV.mjs.map} +1 -1
- package/dist/lib/neutral/operations/index.mjs +1 -1
- package/dist/lib/neutral/plugin.mjs +1 -1
- package/dist/lib/neutral/{query-deployed-functions-F4FHJNWO.mjs → query-deployed-functions-RBQMGON2.mjs} +4 -4
- package/dist/lib/neutral/{query-deployed-functions-F4FHJNWO.mjs.map → query-deployed-functions-RBQMGON2.mjs.map} +1 -1
- package/dist/lib/neutral/{react-surface-2TZDZQYA.mjs → react-surface-GEXOZLBC.mjs} +4 -5
- package/dist/lib/neutral/react-surface-GEXOZLBC.mjs.map +7 -0
- package/dist/lib/neutral/{read-RQESBAQI.mjs → read-OY3K5R3V.mjs} +3 -3
- package/dist/lib/neutral/{read-RQESBAQI.mjs.map → read-OY3K5R3V.mjs.map} +3 -3
- package/dist/lib/neutral/skill-definition-JZ7UYBT7.mjs +15 -0
- package/dist/lib/neutral/skill-definition-JZ7UYBT7.mjs.map +7 -0
- package/dist/lib/neutral/skills/index.mjs +10 -0
- package/dist/lib/neutral/templates/index.mjs +1 -1
- package/dist/lib/neutral/translations.mjs +6 -7
- package/dist/lib/neutral/translations.mjs.map +2 -2
- package/dist/lib/neutral/types/index.mjs +2 -2
- package/dist/lib/neutral/update-Z5VGOLBN.mjs +44 -0
- package/dist/lib/neutral/update-Z5VGOLBN.mjs.map +7 -0
- package/dist/types/src/capabilities/app-graph-builder.d.ts +1 -2
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/capabilities/compiler.d.ts +1 -2
- package/dist/types/src/capabilities/compiler.d.ts.map +1 -1
- package/dist/types/src/capabilities/create-object.d.ts +1 -12
- package/dist/types/src/capabilities/create-object.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +1 -1
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/node.d.ts +1 -1
- package/dist/types/src/capabilities/node.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts +1 -1
- package/dist/types/src/capabilities/settings.d.ts +1 -3
- package/dist/types/src/capabilities/settings.d.ts.map +1 -1
- package/dist/types/src/capabilities/skill-definition.d.ts +5 -0
- package/dist/types/src/capabilities/skill-definition.d.ts.map +1 -0
- package/dist/types/src/components/NotebookStack/NotebookCell.d.ts.map +1 -1
- package/dist/types/src/components/NotebookStack/NotebookStack.d.ts +2 -3
- package/dist/types/src/components/NotebookStack/NotebookStack.d.ts.map +1 -1
- package/dist/types/src/components/NotebookStack/NotebookStack.stories.d.ts +18 -21
- package/dist/types/src/components/NotebookStack/NotebookStack.stories.d.ts.map +1 -1
- package/dist/types/src/components/QueryEditor/QueryEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.stories.d.ts +18 -21
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.stories.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +0 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/containers/DeploymentDialog/DeploymentDialog.stories.d.ts +18 -21
- package/dist/types/src/containers/DeploymentDialog/DeploymentDialog.stories.d.ts.map +1 -1
- package/dist/types/src/containers/NotebookArticle/NotebookArticle.d.ts.map +1 -1
- package/dist/types/src/containers/ScriptArticle/ScriptArticle.stories.d.ts +20 -23
- package/dist/types/src/containers/ScriptArticle/ScriptArticle.stories.d.ts.map +1 -1
- package/dist/types/src/containers/ScriptProperties/ScriptProperties.stories.d.ts +20 -23
- package/dist/types/src/containers/ScriptProperties/ScriptProperties.stories.d.ts.map +1 -1
- package/dist/types/src/containers/ScriptProperties/SkillEditor.d.ts +7 -0
- package/dist/types/src/containers/ScriptProperties/SkillEditor.d.ts.map +1 -0
- package/dist/types/src/containers/ScriptSettings/ScriptSettings.d.ts +8 -0
- package/dist/types/src/containers/ScriptSettings/ScriptSettings.d.ts.map +1 -0
- package/dist/types/src/{components/ScriptPluginSettings/ScriptPluginSettings.stories.d.ts → containers/ScriptSettings/ScriptSettings.stories.d.ts} +20 -23
- package/dist/types/src/containers/ScriptSettings/ScriptSettings.stories.d.ts.map +1 -0
- package/dist/types/src/containers/ScriptSettings/index.d.ts +2 -0
- package/dist/types/src/containers/ScriptSettings/index.d.ts.map +1 -0
- package/dist/types/src/containers/index.d.ts +1 -0
- package/dist/types/src/containers/index.d.ts.map +1 -1
- package/dist/types/src/hooks/deploy.d.ts +6 -15
- package/dist/types/src/hooks/deploy.d.ts.map +1 -1
- package/dist/types/src/hooks/format.d.ts +2 -1
- package/dist/types/src/hooks/format.d.ts.map +1 -1
- package/dist/types/src/hooks/template.d.ts +2 -1
- package/dist/types/src/hooks/template.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +4 -0
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/operations/create-script.d.ts.map +1 -1
- package/dist/types/src/skills/functions/create.d.ts.map +1 -0
- package/dist/types/src/skills/functions/definitions.d.ts +75 -0
- package/dist/types/src/skills/functions/definitions.d.ts.map +1 -0
- package/dist/types/src/skills/functions/delete.d.ts +7 -0
- package/dist/types/src/skills/functions/delete.d.ts.map +1 -0
- package/dist/types/src/skills/functions/deploy.d.ts +11 -0
- package/dist/types/src/skills/functions/deploy.d.ts.map +1 -0
- package/dist/types/src/skills/functions/index.d.ts.map +1 -0
- package/dist/types/src/skills/functions/inspect-invocations.d.ts +18 -0
- package/dist/types/src/skills/functions/inspect-invocations.d.ts.map +1 -0
- package/dist/types/src/skills/functions/install-function.d.ts.map +1 -0
- package/dist/types/src/skills/functions/invoke.d.ts +11 -0
- package/dist/types/src/skills/functions/invoke.d.ts.map +1 -0
- package/dist/types/src/skills/functions/query-deployed-functions.d.ts.map +1 -0
- package/dist/types/src/skills/functions/read.d.ts +11 -0
- package/dist/types/src/skills/functions/read.d.ts.map +1 -0
- package/dist/types/src/skills/functions/update.d.ts +16 -0
- package/dist/types/src/skills/functions/update.d.ts.map +1 -0
- package/dist/types/src/skills/index.d.ts +2 -0
- package/dist/types/src/skills/index.d.ts.map +1 -0
- package/dist/types/src/skills/script-skill.d.ts +4 -0
- package/dist/types/src/skills/script-skill.d.ts.map +1 -0
- package/dist/types/src/templates/chess-bot.d.ts +1 -4
- package/dist/types/src/templates/chess-bot.d.ts.map +1 -1
- package/dist/types/src/templates/commentary.d.ts +1 -4
- package/dist/types/src/templates/commentary.d.ts.map +1 -1
- package/dist/types/src/testing/test-script.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +18 -21
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Notebook.d.ts +11 -81
- package/dist/types/src/types/Notebook.d.ts.map +1 -1
- package/dist/types/src/types/ScriptOperation.d.ts +2 -10
- package/dist/types/src/types/ScriptOperation.d.ts.map +1 -1
- package/dist/types/src/util/deploy.d.ts +1 -1
- package/dist/types/src/util/deploy.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +75 -74
- package/src/ScriptPlugin.node.ts +2 -2
- package/src/ScriptPlugin.test.ts +1 -1
- package/src/ScriptPlugin.tsx +2 -2
- package/src/capabilities/create-object.ts +0 -2
- package/src/capabilities/index.ts +1 -1
- package/src/capabilities/node.ts +1 -1
- package/src/capabilities/operation-handler.ts +1 -1
- package/src/capabilities/react-surface.tsx +9 -7
- package/src/capabilities/skill-definition.ts +14 -0
- package/src/components/NotebookStack/NotebookCell.tsx +11 -29
- package/src/components/NotebookStack/NotebookStack.stories.tsx +3 -3
- package/src/components/NotebookStack/NotebookStack.tsx +101 -43
- package/src/components/QueryEditor/QueryEditor.stories.tsx +2 -7
- package/src/components/TypescriptEditor/TypescriptEditor.stories.tsx +2 -2
- package/src/components/TypescriptEditor/TypescriptEditor.tsx +7 -8
- package/src/components/index.ts +0 -4
- package/src/containers/NotebookArticle/NotebookArticle.stories.tsx +4 -4
- package/src/containers/NotebookArticle/NotebookArticle.tsx +20 -42
- package/src/containers/ScriptArticle/ScriptArticle.stories.tsx +5 -5
- package/src/containers/ScriptArticle/ScriptArticle.tsx +3 -3
- package/src/containers/ScriptProperties/FunctionBinding.tsx +1 -1
- package/src/containers/ScriptProperties/FunctionPublishing.tsx +1 -1
- package/src/containers/ScriptProperties/ScriptProperties.stories.tsx +5 -5
- package/src/containers/ScriptProperties/ScriptProperties.tsx +2 -2
- package/src/containers/ScriptProperties/{BlueprintEditor.tsx → SkillEditor.tsx} +22 -22
- package/src/{components/ScriptPluginSettings/ScriptPluginSettings.stories.tsx → containers/ScriptSettings/ScriptSettings.stories.tsx} +4 -4
- package/src/containers/ScriptSettings/ScriptSettings.tsx +47 -0
- package/src/containers/ScriptSettings/index.ts +5 -0
- package/src/containers/index.ts +1 -0
- package/src/e2e/ai.test.ts +14 -11
- package/src/e2e/deploy.test.ts +5 -1
- package/src/hooks/deploy.ts +1 -1
- package/src/index.ts +1 -1
- package/src/operations/create-script.ts +1 -1
- package/src/{blueprints → skills}/functions/create.ts +1 -1
- package/src/{blueprints → skills}/functions/definitions.ts +4 -2
- package/src/{blueprints → skills}/functions/deploy.ts +7 -2
- package/src/{blueprints → skills}/functions/inspect-invocations.ts +2 -2
- package/src/{blueprints → skills}/functions/read.ts +1 -1
- package/src/skills/functions/update.ts +48 -0
- package/src/skills/index.ts +5 -0
- package/src/{blueprints/script-blueprint.ts → skills/script-skill.ts} +12 -12
- package/src/templates/anthropic.ts +1 -1
- package/src/templates/chess-bot.ts +2 -2
- package/src/templates/commentary.ts +4 -4
- package/src/templates/discord.ts +1 -1
- package/src/templates/gmail.ts +1 -1
- package/src/testing/test-notebook.ts +5 -5
- package/src/testing/test-script.ts +1 -1
- package/src/translations.ts +6 -7
- package/src/types/Notebook.ts +9 -13
- package/src/types/ScriptOperation.ts +2 -2
- package/src/util/deploy.ts +7 -3
- package/src/util/functions.ts +3 -3
- package/dist/lib/neutral/NotebookArticle-E35G2Y2I.mjs.map +0 -7
- package/dist/lib/neutral/ScriptArticle-QW26LOKU.mjs.map +0 -7
- package/dist/lib/neutral/ScriptPluginSettings-5AURDJTI.mjs +0 -31
- package/dist/lib/neutral/ScriptPluginSettings-5AURDJTI.mjs.map +0 -7
- package/dist/lib/neutral/ScriptProperties-ADTWXG6O.mjs.map +0 -7
- package/dist/lib/neutral/blueprint-definition-PJ7I3JIQ.mjs +0 -15
- package/dist/lib/neutral/blueprint-definition-PJ7I3JIQ.mjs.map +0 -7
- package/dist/lib/neutral/blueprints/index.mjs +0 -10
- package/dist/lib/neutral/chunk-BDHDBPVM.mjs.map +0 -7
- package/dist/lib/neutral/chunk-O6A5PTB3.mjs +0 -8
- package/dist/lib/neutral/chunk-QV6NCUGM.mjs.map +0 -7
- package/dist/lib/neutral/chunk-TRKXIP2Q.mjs.map +0 -7
- package/dist/lib/neutral/chunk-VXDJH6OL.mjs.map +0 -7
- package/dist/lib/neutral/chunk-ZPFRRBZW.mjs.map +0 -7
- package/dist/lib/neutral/deploy-7JVMMHSH.mjs.map +0 -7
- package/dist/lib/neutral/inspect-invocations-TAOYDT4H.mjs.map +0 -7
- package/dist/lib/neutral/react-surface-2TZDZQYA.mjs.map +0 -7
- package/dist/lib/neutral/update-CO7B6UBS.mjs +0 -63
- package/dist/lib/neutral/update-CO7B6UBS.mjs.map +0 -7
- package/dist/types/src/blueprints/functions/create.d.ts.map +0 -1
- package/dist/types/src/blueprints/functions/definitions.d.ts +0 -135
- package/dist/types/src/blueprints/functions/definitions.d.ts.map +0 -1
- package/dist/types/src/blueprints/functions/delete.d.ts +0 -17
- package/dist/types/src/blueprints/functions/delete.d.ts.map +0 -1
- package/dist/types/src/blueprints/functions/deploy.d.ts +0 -21
- package/dist/types/src/blueprints/functions/deploy.d.ts.map +0 -1
- package/dist/types/src/blueprints/functions/index.d.ts.map +0 -1
- package/dist/types/src/blueprints/functions/inspect-invocations.d.ts +0 -28
- package/dist/types/src/blueprints/functions/inspect-invocations.d.ts.map +0 -1
- package/dist/types/src/blueprints/functions/install-function.d.ts.map +0 -1
- package/dist/types/src/blueprints/functions/invoke.d.ts +0 -21
- package/dist/types/src/blueprints/functions/invoke.d.ts.map +0 -1
- package/dist/types/src/blueprints/functions/query-deployed-functions.d.ts.map +0 -1
- package/dist/types/src/blueprints/functions/read.d.ts +0 -21
- package/dist/types/src/blueprints/functions/read.d.ts.map +0 -1
- package/dist/types/src/blueprints/functions/update.d.ts +0 -26
- package/dist/types/src/blueprints/functions/update.d.ts.map +0 -1
- package/dist/types/src/blueprints/index.d.ts +0 -2
- package/dist/types/src/blueprints/index.d.ts.map +0 -1
- package/dist/types/src/blueprints/script-blueprint.d.ts +0 -4
- package/dist/types/src/blueprints/script-blueprint.d.ts.map +0 -1
- package/dist/types/src/capabilities/blueprint-definition.d.ts +0 -6
- package/dist/types/src/capabilities/blueprint-definition.d.ts.map +0 -1
- package/dist/types/src/components/ScriptPluginSettings/ScriptPluginSettings.d.ts +0 -8
- package/dist/types/src/components/ScriptPluginSettings/ScriptPluginSettings.d.ts.map +0 -1
- package/dist/types/src/components/ScriptPluginSettings/ScriptPluginSettings.stories.d.ts.map +0 -1
- package/dist/types/src/components/ScriptPluginSettings/index.d.ts +0 -2
- package/dist/types/src/components/ScriptPluginSettings/index.d.ts.map +0 -1
- package/dist/types/src/containers/ScriptProperties/BlueprintEditor.d.ts +0 -7
- package/dist/types/src/containers/ScriptProperties/BlueprintEditor.d.ts.map +0 -1
- package/src/blueprints/functions/update.ts +0 -68
- package/src/blueprints/index.ts +0 -5
- package/src/capabilities/blueprint-definition.ts +0 -19
- package/src/components/ScriptPluginSettings/ScriptPluginSettings.tsx +0 -42
- package/src/components/ScriptPluginSettings/index.ts +0 -5
- /package/dist/lib/neutral/{chunk-JAJ64B3E.mjs.map → chunk-KSVKXCTX.mjs.map} +0 -0
- /package/dist/lib/neutral/{blueprints → skills}/index.mjs.map +0 -0
- /package/dist/types/src/{blueprints → skills}/functions/create.d.ts +0 -0
- /package/dist/types/src/{blueprints → skills}/functions/index.d.ts +0 -0
- /package/dist/types/src/{blueprints → skills}/functions/install-function.d.ts +0 -0
- /package/dist/types/src/{blueprints → skills}/functions/query-deployed-functions.d.ts +0 -0
- /package/src/{blueprints → skills}/functions/delete.ts +0 -0
- /package/src/{blueprints → skills}/functions/index.ts +0 -0
- /package/src/{blueprints → skills}/functions/install-function.ts +0 -0
- /package/src/{blueprints → skills}/functions/invoke.ts +0 -0
- /package/src/{blueprints → skills}/functions/query-deployed-functions.ts +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
templates
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-WAGQ77UQ.mjs";
|
|
4
4
|
import {
|
|
5
5
|
__export
|
|
6
6
|
} from "./chunk-J5LGTIGS.mjs";
|
|
@@ -27,8 +27,8 @@ __export(Notebook_exports, {
|
|
|
27
27
|
make: () => make
|
|
28
28
|
});
|
|
29
29
|
import * as Schema2 from "effect/Schema";
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
30
|
+
import { Instructions } from "@dxos/compute";
|
|
31
|
+
import { Annotation, DXN, Obj, Ref, Type } from "@dxos/echo";
|
|
32
32
|
import { FormInputAnnotation } from "@dxos/echo/Annotation";
|
|
33
33
|
import { LabelAnnotation } from "@dxos/echo/Annotation";
|
|
34
34
|
import { Graph } from "@dxos/plugin-explorer";
|
|
@@ -39,10 +39,10 @@ var Cell = Schema2.Struct({
|
|
|
39
39
|
name: Schema2.optional(Schema2.String),
|
|
40
40
|
// TODO(burdon): Union type.
|
|
41
41
|
source: Schema2.optional(Ref.Ref(Text.Text)),
|
|
42
|
-
prompt: Schema2.optional(Ref.Ref(
|
|
42
|
+
prompt: Schema2.optional(Ref.Ref(Instructions.Instructions)),
|
|
43
43
|
graph: Schema2.optional(Ref.Ref(Graph.Graph))
|
|
44
44
|
});
|
|
45
|
-
var Notebook = Schema2.Struct({
|
|
45
|
+
var Notebook = class extends Type.makeObject(DXN.make("org.dxos.type.notebook", "0.1.0"))(Schema2.Struct({
|
|
46
46
|
name: Schema2.String.pipe(Schema2.optional),
|
|
47
47
|
cells: Cell.pipe(Schema2.Array, FormInputAnnotation.set(false))
|
|
48
48
|
}).pipe(LabelAnnotation.set([
|
|
@@ -50,7 +50,8 @@ var Notebook = Schema2.Struct({
|
|
|
50
50
|
]), Annotation.IconAnnotation.set({
|
|
51
51
|
icon: "ph--notebook--regular",
|
|
52
52
|
hue: "sky"
|
|
53
|
-
})
|
|
53
|
+
}))) {
|
|
54
|
+
};
|
|
54
55
|
var make = (props = {
|
|
55
56
|
cells: []
|
|
56
57
|
}) => Obj.make(Notebook, props);
|
|
@@ -83,8 +84,8 @@ __export(ScriptOperation_exports, {
|
|
|
83
84
|
ScriptProps: () => ScriptProps
|
|
84
85
|
});
|
|
85
86
|
import * as Schema3 from "effect/Schema";
|
|
86
|
-
import {
|
|
87
|
-
import { Database,
|
|
87
|
+
import { Operation, Script } from "@dxos/compute";
|
|
88
|
+
import { Database, DXN as DXN2, Type as Type2 } from "@dxos/echo";
|
|
88
89
|
import { meta as meta3 } from "#meta";
|
|
89
90
|
var makeKey = (name) => DXN2.make(`${meta3.profile.key}.operation.${name}`);
|
|
90
91
|
var ScriptProps = Schema3.Struct({
|
|
@@ -120,4 +121,4 @@ export {
|
|
|
120
121
|
ScriptEvents_exports,
|
|
121
122
|
ScriptOperation_exports
|
|
122
123
|
};
|
|
123
|
-
//# sourceMappingURL=chunk-
|
|
124
|
+
//# sourceMappingURL=chunk-652CIABA.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/types/Settings.ts", "../../../src/types/Notebook.ts", "../../../src/types/ScriptCapabilities.ts", "../../../src/types/ScriptEvents.ts", "../../../src/types/ScriptOperation.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Schema from 'effect/Schema';\n\nimport { EditorInputMode } from '@dxos/ui-editor/types';\n\nexport const Settings = Schema.mutable(\n Schema.Struct({\n editorInputMode: EditorInputMode.annotations({\n title: 'Editor input mode',\n description: 'Choose the keybinding style for the script editor.',\n }),\n }),\n);\n\nexport interface Settings extends Schema.Schema.Type<typeof Settings> {}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { Instructions } from '@dxos/compute';\nimport { Annotation, DXN, Obj, Ref, Type } from '@dxos/echo';\nimport { FormInputAnnotation } from '@dxos/echo/Annotation';\nimport { LabelAnnotation } from '@dxos/echo/Annotation';\nimport { Graph } from '@dxos/plugin-explorer';\nimport { Text } from '@dxos/schema';\n\nexport type CellType = 'markdown' | 'script' | 'query' | 'prompt' | 'view';\n\nexport const Cell = Schema.Struct({\n id: Schema.String,\n type: Schema.String,\n name: Schema.optional(Schema.String),\n // TODO(burdon): Union type.\n source: Schema.optional(Ref.Ref(Text.Text)),\n prompt: Schema.optional(Ref.Ref(Instructions.Instructions)),\n graph: Schema.optional(Ref.Ref(Graph.Graph)),\n});\n\nexport type Cell = Schema.Schema.Type<typeof Cell>;\n\nexport class Notebook extends Type.makeObject<Notebook>(DXN.make('org.dxos.type.notebook', '0.1.0'))(\n Schema.Struct({\n name: Schema.String.pipe(Schema.optional),\n cells: Cell.pipe(Schema.Array, FormInputAnnotation.set(false)),\n }).pipe(LabelAnnotation.set(['name']), Annotation.IconAnnotation.set({ icon: 'ph--notebook--regular', hue: 'sky' })),\n) {}\n\nexport const make = (props: Obj.MakeProps<typeof Notebook> = { cells: [] }): Notebook => Obj.make(Notebook, props);\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport { type Atom } from '@effect-atom/atom-react';\n\nimport { Capability } from '@dxos/app-framework';\n\nimport { meta } from '#meta';\n\nimport { type Compiler as CompilerType } from '../compiler';\n\n// Inline import to avoid `Settings` namespace alias colliding with the\n// `Settings` capability export below.\nexport const Settings = Capability.make<Atom.Writable<import('./Settings').Settings>>(\n `${meta.profile.key}.capability.settings`,\n);\nexport const Compiler = Capability.make<CompilerType>(`${meta.profile.key}.capability.compiler`);\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport { ActivationEvent } from '@dxos/app-framework';\n\nimport { meta } from '#meta';\n\nexport const SetupCompiler = ActivationEvent.make(`${meta.profile.key}.event.setupCompiler`);\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Schema from 'effect/Schema';\n\nimport { Operation, Script } from '@dxos/compute';\nimport { Database, DXN, Type } from '@dxos/echo';\n\nimport { meta } from '#meta';\n\nimport { templates } from '../templates';\n\nconst makeKey = (name: string) => DXN.make(`${meta.profile.key}.operation.${name}`);\n\nexport const ScriptProps = Schema.Struct({\n name: Schema.optional(Schema.String),\n gistUrl: Schema.optional(Schema.String.annotations({ title: 'Import from Gist (url)' })),\n initialTemplateId: Schema.Literal(...templates.map(({ id }) => id)).pipe(\n Schema.annotations({ title: 'Template' }),\n Schema.optional,\n ),\n});\n\nexport const NotebookProps = Schema.Struct({\n name: Schema.optional(Schema.String),\n});\n\nexport const CreateScript = Operation.make({\n meta: { key: makeKey('createScript'), name: 'Create Script', icon: 'ph--code--regular' },\n input: Schema.extend(\n ScriptProps,\n Schema.Struct({\n db: Database.Database,\n }),\n ),\n output: Schema.Struct({\n object: Type.getSchema(Script.Script),\n }),\n});\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAAA;;;;AAMA,YAAYA,YAAY;AAExB,SAASC,uBAAuB;AAEzB,IAAMC,WAAkBC,eACtBC,cAAO;EACZC,iBAAiBJ,gBAAgBK,YAAY;IAC3CC,OAAO;IACPC,aAAa;EACf,CAAA;AACF,CAAA,CAAA;;;AChBF;;;;;;AAIA,YAAYC,aAAY;AAExB,SAASC,oBAAoB;AAC7B,SAASC,YAAYC,KAAKC,KAAKC,KAAKC,YAAY;AAChD,SAASC,2BAA2B;AACpC,SAASC,uBAAuB;AAChC,SAASC,aAAa;AACtB,SAASC,YAAY;AAId,IAAMC,OAAcC,eAAO;EAChCC,IAAWC;EACXC,MAAaD;EACbE,MAAaC,iBAAgBH,cAAM;;EAEnCI,QAAeD,iBAASZ,IAAIA,IAAIK,KAAKA,IAAI,CAAA;EACzCS,QAAeF,iBAASZ,IAAIA,IAAIJ,aAAaA,YAAY,CAAA;EACzDmB,OAAcH,iBAASZ,IAAIA,IAAII,MAAMA,KAAK,CAAA;AAC5C,CAAA;AAIO,IAAMY,WAAN,cAAuBf,KAAKgB,WAAqBnB,IAAIoB,KAAK,0BAA0B,OAAA,CAAA,EAClFX,eAAO;EACZI,MAAaF,eAAOU,KAAYP,gBAAQ;EACxCQ,OAAOd,KAAKa,KAAYE,eAAOnB,oBAAoBoB,IAAI,KAAA,CAAA;AACzD,CAAA,EAAGH,KAAKhB,gBAAgBmB,IAAI;EAAC;CAAO,GAAGzB,WAAW0B,eAAeD,IAAI;EAAEE,MAAM;EAAyBC,KAAK;AAAM,CAAA,CAAA,CAAA,EAAA;AAChH;AAEI,IAAMP,OAAO,CAACQ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AAKC,UAAUC,OAAOA,MAAM;EACtC,CAAA;AACF,CAAA;",
|
|
6
|
+
"names": ["Schema", "EditorInputMode", "Settings", "mutable", "Struct", "editorInputMode", "annotations", "title", "description", "Schema", "Instructions", "Annotation", "DXN", "Obj", "Ref", "Type", "FormInputAnnotation", "LabelAnnotation", "Graph", "Text", "Cell", "Struct", "id", "String", "type", "name", "optional", "source", "prompt", "graph", "Notebook", "makeObject", "make", "pipe", "cells", "Array", "set", "IconAnnotation", "icon", "hue", "props", "Settings", "Capability", "meta", "make", "profile", "key", "Compiler", "ActivationEvent", "meta", "SetupCompiler", "make", "profile", "key", "Schema", "Operation", "Script", "Database", "DXN", "Type", "meta", "makeKey", "name", "DXN", "make", "meta", "profile", "key", "ScriptProps", "Struct", "optional", "String", "gistUrl", "annotations", "title", "initialTemplateId", "Literal", "templates", "map", "id", "pipe", "NotebookProps", "CreateScript", "Operation", "icon", "input", "extend", "db", "Database", "output", "object", "Type", "getSchema", "Script"]
|
|
7
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/skills/functions/definitions.ts
|
|
2
2
|
import * as Schema from "effect/Schema";
|
|
3
3
|
import { ClientService } from "@dxos/client";
|
|
4
4
|
import { Operation } from "@dxos/compute";
|
|
5
|
-
import { Database,
|
|
5
|
+
import { Database, DXN, Ref } from "@dxos/echo";
|
|
6
6
|
import { trim } from "@dxos/util";
|
|
7
7
|
var FunctionRef = Ref.Ref(Operation.PersistentOperation).annotations({
|
|
8
8
|
description: "The ID of the function."
|
|
@@ -267,8 +267,7 @@ var InspectInvocations = Operation.make({
|
|
|
267
267
|
})
|
|
268
268
|
}),
|
|
269
269
|
services: [
|
|
270
|
-
Database.Service
|
|
271
|
-
Feed.FeedService
|
|
270
|
+
Database.Service
|
|
272
271
|
]
|
|
273
272
|
});
|
|
274
273
|
var DeployedFunctionSchema = Schema.Struct({
|
|
@@ -342,4 +341,4 @@ export {
|
|
|
342
341
|
QueryDeployedFunctions,
|
|
343
342
|
InstallFunction
|
|
344
343
|
};
|
|
345
|
-
//# sourceMappingURL=chunk-
|
|
344
|
+
//# sourceMappingURL=chunk-6DOWVKIW.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/skills/functions/definitions.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { ClientService } from '@dxos/client';\nimport { Operation } from '@dxos/compute';\nimport { Database, DXN, Ref } from '@dxos/echo';\nimport { trim } from '@dxos/util';\n\nconst FunctionRef = Ref.Ref(Operation.PersistentOperation).annotations({\n description: 'The ID of the function.',\n});\n\nconst FunctionId = Schema.String.annotations({\n description: 'The ID of the function. Can be passed as the function parameter to other operations.',\n});\n\nconst FUNCTION_FORMAT = trim`\n IMPORTANT: Every function MUST follow this exact pattern — define an Operation, then export default the handler:\n\n \\`\\`\\`typescript\n import * as Effect from 'effect/Effect';\n import * as Schema from 'effect/Schema';\n\n import { Operation } from '@dxos/compute';\n\n const MyFunction = Operation.make({\n meta: {\n key: DXN.make('org.dxos.script.myFunction'),\n name: 'My Function',\n },\n input: Schema.Struct({\n city: Schema.String.annotations({ description: 'City name' }),\n }),\n output: Schema.Any,\n });\n\n export default MyFunction.pipe(\n Operation.withHandler(\n Effect.fn(function* ({ city }) {\n const res = yield* Effect.promise(() =>\n fetch(\\`https://wttr.in/\\${city}?format=j1\\`)\n );\n const data = yield* Effect.promise(() => res.json());\n return data;\n }),\n ),\n );\n \\`\\`\\`\n\n Key rules:\n - The file MUST have a single \\`export default\\` of Operation.pipe(Operation.withHandler(...)).\n - Use \\`Effect.fn(function* (...) { ... })\\` for the handler body.\n - Wrap async calls with \\`yield* Effect.promise(() => ...)\\`.\n - Do NOT use top-level await; do NOT export named functions; do NOT use module.exports.\n`;\n\nconst AVAILABLE_PACKAGES = trim`\n Scripts run in an Edge runtime (Cloudflare Workers) with the following pre-bundled packages:\n\n DXOS SDK:\n - \\`@dxos/echo\\` — Reactive local-first database: query, filter, and mutate ECHO objects in spaces.\n - \\`@dxos/functions\\` — Edge function framework: triggers, queues, and function definitions.\n - \\`@dxos/ai\\` — AI/LLM integration via AiService (access models like Claude, GPT).\n - \\`@dxos/schema\\` — Schema utilities and built-in DXOS types.\n - \\`@dxos/types\\` — DXOS type definitions.\n - \\`@dxos/operation\\` — Define and handle typed operations with input/output schemas.\n - \\`@dxos/util\\` — General utility functions.\n - \\`@dxos/log\\` — Structured logging.\n\n Effect-TS (functional programming toolkit):\n - \\`effect\\` — Core effect system with sub-modules: Effect, Schema, Stream, Schedule, Array, Record, Option, Either, Match, etc.\n - \\`@effect/platform\\` — HTTP client (\\`HttpClient\\`), platform abstractions for making typed API requests.\n\n Data format parsing & querying:\n - \\`jsonata\\` — Powerful query and transformation expressions for JSON data (filter, sort, group, aggregate, reshape).\n - \\`yaml\\` — Parse and stringify YAML documents.\n - \\`fast-xml-parser\\` — Fast XML parser and builder; convert between XML and JSON.\n - \\`papaparse\\` — CSV parsing and serialization; stream large files, auto-detect delimiters.\n\n Text & markup processing:\n - \\`turndown\\` — HTML to Markdown converter (useful for feeding web content to LLMs).\n\n HTML/DOM parsing:\n - \\`linkedom\\` — Lightweight DOM parser for worker environments; parse and query HTML documents.\n\n Data processing & utilities:\n - \\`date-fns\\` — Comprehensive date utility library: parsing, formatting, comparison, arithmetic, time zones.\n\n Other:\n - \\`@automerge/automerge\\` — CRDT library for conflict-free collaborative data structures.\n - \\`chess.js\\` — Chess game logic, move generation, and validation.\n`;\n\nexport const Create = Operation.make({\n meta: {\n key: DXN.make('org.dxos.function.script.create'),\n name: 'Create',\n description: `Creates a new function with TypeScript source code and adds it to the space. ${FUNCTION_FORMAT} ${AVAILABLE_PACKAGES}`,\n icon: 'ph--code--regular',\n },\n input: Schema.Struct({\n name: Schema.String.annotations({\n description: 'Name of the function.',\n }),\n source: Schema.optional(Schema.String).annotations({\n description: 'TypeScript source code for the function.',\n }),\n templateId: Schema.optional(Schema.String).annotations({\n description: 'ID of a template to use as the initial source.',\n }),\n }),\n output: Schema.Struct({\n function: FunctionId,\n }),\n services: [Database.Service],\n});\n\nexport const Read = Operation.make({\n meta: {\n key: DXN.make('org.dxos.function.script.read'),\n name: 'Read',\n description: 'Reads the source code and metadata of a function.',\n icon: 'ph--file-text--regular',\n },\n input: Schema.Struct({\n function: FunctionRef,\n }),\n output: Schema.Struct({\n name: Schema.optional(Schema.String),\n source: Schema.String,\n description: Schema.optional(Schema.String),\n }),\n services: [Database.Service],\n});\n\n// The edit descriptions feed the script skill's LLM tool definition (and its memoized\n// fixtures), so the schema stays local and context-tuned; the apply logic is shared via `Doc.applyEdits`.\nconst Edit = Schema.Struct({\n oldString: Schema.String.annotations({\n description: 'The text to find in the source.',\n }),\n newString: Schema.String.annotations({\n description: 'The text to replace it with.',\n }),\n replaceAll: Schema.optional(Schema.Boolean).annotations({\n description: 'If true, replaces all occurrences. Defaults to false (first occurrence only).',\n }),\n});\n\nexport const Update = Operation.make({\n meta: {\n key: DXN.make('org.dxos.function.script.update'),\n name: 'Update',\n description: `Updates the source code or metadata of a function. ${FUNCTION_FORMAT}`,\n icon: 'ph--pencil--regular',\n },\n input: Schema.Struct({\n function: FunctionRef,\n name: Schema.optional(Schema.String).annotations({\n description: 'New name for the function.',\n }),\n description: Schema.optional(Schema.String).annotations({\n description: 'New description for the function.',\n }),\n edits: Schema.optional(Schema.Array(Edit)).annotations({\n description: 'Edits to apply to the source. Each edit finds oldString and replaces it with newString.',\n }),\n }),\n output: Schema.Struct({\n function: FunctionId,\n }),\n services: [Database.Service],\n});\n\nexport const Delete = Operation.make({\n meta: {\n key: DXN.make('org.dxos.function.script.delete'),\n name: 'Delete',\n description: 'Deletes a function and its source from the space.',\n icon: 'ph--trash--regular',\n },\n input: Schema.Struct({\n function: FunctionRef,\n }),\n output: Schema.Void,\n services: [Database.Service],\n});\n\nexport const Deploy = Operation.make({\n meta: {\n key: DXN.make('org.dxos.function.script.deploy'),\n name: 'Deploy',\n description: `Deploys a function to the Edge runtime. The function source must follow the required format: a single export default of Operation.pipe(Operation.withHandler(Effect.fn(function* (...) { ... }))). See the Create operation description for a full example.`,\n icon: 'ph--rocket-launch--regular',\n },\n input: Schema.Struct({\n function: FunctionRef,\n }),\n output: Schema.Struct({\n function: FunctionId,\n functionUrl: Schema.optional(Schema.String).annotations({\n description: 'The URL of the deployed function.',\n }),\n }),\n services: [Database.Service, ClientService],\n});\n\nexport const Invoke = Operation.make({\n meta: {\n key: DXN.make('org.dxos.function.script.invoke'),\n name: 'Invoke',\n description: 'Invokes a deployed Edge function with the given payload.',\n icon: 'ph--play--regular',\n },\n input: Schema.Struct({\n function: FunctionRef,\n payload: Schema.optional(Schema.Unknown).annotations({\n description: 'The input payload to pass to the function.',\n }),\n }),\n output: Schema.Struct({\n response: Schema.Unknown.annotations({\n description: 'The response from the function.',\n }),\n }),\n services: [Database.Service, ClientService],\n});\n\nconst InvocationSpanSchema = Schema.Struct({\n id: Schema.String.annotations({\n description: 'The invocation ID.',\n }),\n timestamp: Schema.Number.annotations({\n description: 'Start time of the invocation (epoch ms).',\n }),\n duration: Schema.Number.annotations({\n description: 'Duration in milliseconds.',\n }),\n outcome: Schema.String.annotations({\n description: 'Invocation outcome: success, failure, or pending.',\n }),\n input: Schema.Object.annotations({\n description: 'The input payload passed to the function.',\n }),\n error: Schema.optional(Schema.Object).annotations({\n description: 'Error details if the invocation failed.',\n }),\n});\n\nexport const InspectInvocations = Operation.make({\n meta: {\n key: DXN.make('org.dxos.function.script.inspectInvocations'),\n name: 'InspectInvocations',\n description: 'Queries the invocation trace feed for a function, returning its invocation history.',\n icon: 'ph--magnifying-glass--regular',\n },\n input: Schema.Struct({\n function: FunctionRef,\n limit: Schema.optional(Schema.Number).annotations({\n description: 'Maximum number of invocations to return. Defaults to 20.',\n }),\n }),\n output: Schema.Struct({\n invocations: Schema.Array(InvocationSpanSchema).annotations({\n description: 'List of invocation spans, most recent first.',\n }),\n total: Schema.Number.annotations({\n description: 'Total number of invocations found.',\n }),\n }),\n services: [Database.Service],\n});\n\nconst DeployedFunctionSchema = Schema.Struct({\n key: Schema.optional(Schema.String).annotations({\n description: 'Unique key identifying the function. Pass to InstallFunction to install it.',\n }),\n name: Schema.String.annotations({\n description: 'Display name of the function.',\n }),\n version: Schema.String.annotations({\n description: 'Semantic version of the deployed function.',\n }),\n description: Schema.optional(Schema.String).annotations({\n description: 'Description of what the function does.',\n }),\n updated: Schema.optional(Schema.String).annotations({\n description: 'ISO timestamp of the last deployment.',\n }),\n});\n\nexport const QueryDeployedFunctions = Operation.make({\n meta: {\n key: DXN.make('org.dxos.function.script.queryDeployed'),\n name: 'QueryDeployedFunctions',\n description: 'Lists all functions deployed to the EDGE runtime. Use InstallFunction to add one to the space.',\n icon: 'ph--list--regular',\n },\n input: Schema.Void,\n output: Schema.Struct({\n functions: Schema.Array(DeployedFunctionSchema).annotations({\n description: 'List of deployed functions.',\n }),\n }),\n services: [ClientService],\n});\n\nexport const InstallFunction = Operation.make({\n meta: {\n key: DXN.make('org.dxos.function.script.install'),\n name: 'InstallFunction',\n description:\n 'Installs a deployed EDGE function into the current space by key. The returned function ID can be passed directly to Invoke.',\n icon: 'ph--download--regular',\n },\n input: Schema.Struct({\n key: Schema.String.annotations({\n description: 'The unique key of the deployed function to install (from QueryDeployedFunctions).',\n }),\n }),\n output: Schema.Struct({\n function: FunctionId,\n name: Schema.String.annotations({\n description: 'Name of the installed function.',\n }),\n version: Schema.String.annotations({\n description: 'Version of the installed function.',\n }),\n }),\n services: [ClientService],\n});\n"],
|
|
5
|
+
"mappings": ";AAIA,YAAYA,YAAY;AAExB,SAASC,qBAAqB;AAC9B,SAASC,iBAAiB;AAC1B,SAASC,UAAUC,KAAKC,WAAW;AACnC,SAASC,YAAY;AAErB,IAAMC,cAAcF,IAAIA,IAAIH,UAAUM,mBAAmB,EAAEC,YAAY;EACrEC,aAAa;AAC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AA,aAAoBc,gBAAgBZ,aAAM,EAAEH,YAAY;IACtDC,aAAa;EACf,CAAA;EACAmD,SAAgBrC,gBAAgBZ,aAAM,EAAEH,YAAY;IAClDC,aAAa;EACf,CAAA;AACF,CAAA;AAEO,IAAMoD,yBAAyB5D,UAAUc,KAAK;EACnDC,MAAM;IACJC,KAAKd,IAAIY,KAAK,wCAAA;IACdG,MAAM;IACNT,aAAa;IACbU,MAAM;EACR;EACAC,OAAcmB;EACdd,QAAeJ,cAAO;IACpByC,WAAkBzB,aAAMqB,sBAAAA,EAAwBlD,YAAY;MAC1DC,aAAa;IACf,CAAA;EACF,CAAA;EACAkB,UAAU;IAAC3B;;AACb,CAAA;AAEO,IAAM+D,kBAAkB9D,UAAUc,KAAK;EAC5CC,MAAM;IACJC,KAAKd,IAAIY,KAAK,kCAAA;IACdG,MAAM;IACNT,aACE;IACFU,MAAM;EACR;EACAC,OAAcC,cAAO;IACnBJ,KAAYN,cAAOH,YAAY;MAC7BC,aAAa;IACf,CAAA;EACF,CAAA;EACAgB,QAAeJ,cAAO;IACpBK,UAAUhB;IACVQ,MAAaP,cAAOH,YAAY;MAC9BC,aAAa;IACf,CAAA;IACAkD,SAAgBhD,cAAOH,YAAY;MACjCC,aAAa;IACf,CAAA;EACF,CAAA;EACAkB,UAAU;IAAC3B;;AACb,CAAA;",
|
|
6
|
+
"names": ["Schema", "ClientService", "Operation", "Database", "DXN", "Ref", "trim", "FunctionRef", "PersistentOperation", "annotations", "description", "FunctionId", "String", "FUNCTION_FORMAT", "AVAILABLE_PACKAGES", "Create", "make", "meta", "key", "name", "icon", "input", "Struct", "source", "optional", "templateId", "output", "function", "services", "Service", "Read", "Edit", "oldString", "newString", "replaceAll", "Boolean", "Update", "edits", "Array", "Delete", "Void", "Deploy", "functionUrl", "Invoke", "payload", "Unknown", "response", "InvocationSpanSchema", "id", "timestamp", "Number", "duration", "outcome", "Object", "error", "InspectInvocations", "limit", "invocations", "total", "DeployedFunctionSchema", "version", "updated", "QueryDeployedFunctions", "functions", "InstallFunction"]
|
|
7
|
+
}
|
|
@@ -8,17 +8,17 @@ import {
|
|
|
8
8
|
QueryDeployedFunctions,
|
|
9
9
|
Read,
|
|
10
10
|
Update
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-6DOWVKIW.mjs";
|
|
12
12
|
|
|
13
|
-
// src/
|
|
14
|
-
import {
|
|
13
|
+
// src/skills/script-skill.ts
|
|
14
|
+
import { Skill, Template } from "@dxos/compute";
|
|
15
15
|
import { trim } from "@dxos/util";
|
|
16
|
-
var
|
|
17
|
-
var make = () =>
|
|
18
|
-
key:
|
|
16
|
+
var SKILL_KEY = "org.dxos.skill.script";
|
|
17
|
+
var make = () => Skill.make({
|
|
18
|
+
key: SKILL_KEY,
|
|
19
19
|
name: "Script",
|
|
20
20
|
agentCanEnable: true,
|
|
21
|
-
tools:
|
|
21
|
+
tools: Skill.toolDefinitions({
|
|
22
22
|
operations: [
|
|
23
23
|
Create,
|
|
24
24
|
Read,
|
|
@@ -40,13 +40,13 @@ var make = () => Blueprint.make({
|
|
|
40
40
|
`
|
|
41
41
|
})
|
|
42
42
|
});
|
|
43
|
-
var
|
|
44
|
-
key:
|
|
43
|
+
var skill = {
|
|
44
|
+
key: SKILL_KEY,
|
|
45
45
|
make
|
|
46
46
|
};
|
|
47
|
-
var
|
|
47
|
+
var script_skill_default = skill;
|
|
48
48
|
|
|
49
49
|
export {
|
|
50
|
-
|
|
50
|
+
script_skill_default
|
|
51
51
|
};
|
|
52
|
-
//# sourceMappingURL=chunk-
|
|
52
|
+
//# sourceMappingURL=chunk-CHNFYLKW.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/skills/script-skill.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Skill, Template } from '@dxos/compute';\nimport { trim } from '@dxos/util';\n\nimport {\n Create,\n Delete,\n Deploy,\n InspectInvocations,\n InstallFunction,\n Invoke,\n QueryDeployedFunctions,\n Read,\n Update,\n} from './functions';\n\nconst SKILL_KEY = 'org.dxos.skill.script';\n\nconst make = () =>\n Skill.make({\n key: SKILL_KEY,\n name: 'Script',\n agentCanEnable: true,\n tools: Skill.toolDefinitions({\n operations: [\n Create,\n Read,\n Update,\n Delete,\n Deploy,\n Invoke,\n InspectInvocations,\n QueryDeployedFunctions,\n InstallFunction,\n ],\n }),\n instructions: Template.make({\n source: trim`\n You can create, read, update, and delete scripts which contain TypeScript code.\n You can deploy scripts to the Edge runtime and invoke deployed scripts.\n You can inspect the invocation history of a deployed script.\n You can query all functions deployed to the EDGE runtime and install them into the current space.\n `,\n }),\n });\n\nconst skill: Skill.Definition = {\n key: SKILL_KEY,\n make,\n};\n\nexport default skill;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;AAIA,SAASA,OAAOC,gBAAgB;AAChC,SAASC,YAAY;AAcrB,IAAMC,YAAY;AAElB,IAAMC,OAAO,MACXC,MAAMD,KAAK;EACTE,KAAKH;EACLI,MAAM;EACNC,gBAAgB;EAChBC,OAAOJ,MAAMK,gBAAgB;IAC3BC,YAAY;MACVC;MACAC;MACAC;MACAC;MACAC;MACAC;MACAC;MACAC;MACAC;;EAEJ,CAAA;EACAC,cAAcC,SAASlB,KAAK;IAC1BmB,QAAQC;;;;;;EAMV,CAAA;AACF,CAAA;AAEF,IAAMC,QAA0B;EAC9BnB,KAAKH;EACLC;AACF;AAEA,IAAA,uBAAeqB;",
|
|
6
|
+
"names": ["Skill", "Template", "trim", "SKILL_KEY", "make", "Skill", "key", "name", "agentCanEnable", "tools", "toolDefinitions", "operations", "Create", "Read", "Update", "Delete", "Deploy", "Invoke", "InspectInvocations", "QueryDeployedFunctions", "InstallFunction", "instructions", "Template", "source", "trim", "skill"]
|
|
7
|
+
}
|
|
@@ -20,6 +20,13 @@ var deployScript = async ({ script, client, space, fn, existingFunctionId }) =>
|
|
|
20
20
|
error: validationError
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
+
const identity = client.halo.identity.get();
|
|
24
|
+
if (!identity) {
|
|
25
|
+
return {
|
|
26
|
+
success: false,
|
|
27
|
+
error: new Error("Identity not available.")
|
|
28
|
+
};
|
|
29
|
+
}
|
|
23
30
|
try {
|
|
24
31
|
const buildResult = await bundleFunction({
|
|
25
32
|
source: script.source.target.content
|
|
@@ -28,9 +35,8 @@ var deployScript = async ({ script, client, space, fn, existingFunctionId }) =>
|
|
|
28
35
|
throw buildResult.error || new Error("Bundle creation failed");
|
|
29
36
|
}
|
|
30
37
|
const functionsServiceClient = FunctionsServiceClient.fromClient(client);
|
|
31
|
-
const newFunction = await functionsServiceClient.deploy(Context.default(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L:
|
|
32
|
-
|
|
33
|
-
ownerPublicKey: space.key,
|
|
38
|
+
const newFunction = await functionsServiceClient.deploy(Context.default(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 41 }), {
|
|
39
|
+
ownerUri: identity.did,
|
|
34
40
|
version: fn ? incrementSemverPatch(Obj.getMeta(fn).version ?? "0.0.0") : "0.0.1",
|
|
35
41
|
functionId: existingFunctionId,
|
|
36
42
|
entryPoint: buildResult.entryPoint,
|
|
@@ -46,7 +52,7 @@ var deployScript = async ({ script, client, space, fn, existingFunctionId }) =>
|
|
|
46
52
|
functionId: getUserFunctionIdInMetadata(Obj.getMeta(storedFunction))
|
|
47
53
|
};
|
|
48
54
|
} catch (err) {
|
|
49
|
-
log.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L:
|
|
55
|
+
log.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 58, S: void 0 });
|
|
50
56
|
return {
|
|
51
57
|
success: false,
|
|
52
58
|
error: err
|
|
@@ -129,10 +135,10 @@ var getAccessCredential = (identityKey) => {
|
|
|
129
135
|
id: identityKey,
|
|
130
136
|
assertion: {
|
|
131
137
|
"@type": "dxos.halo.credentials.ServiceAccess",
|
|
132
|
-
serverName: "hub.dxos.network",
|
|
133
|
-
serverKey: identityKey,
|
|
138
|
+
"serverName": "hub.dxos.network",
|
|
139
|
+
"serverKey": identityKey,
|
|
134
140
|
identityKey,
|
|
135
|
-
capabilities: [
|
|
141
|
+
"capabilities": [
|
|
136
142
|
"composer:beta"
|
|
137
143
|
]
|
|
138
144
|
}
|
|
@@ -147,4 +153,4 @@ export {
|
|
|
147
153
|
updateFunctionMetadata,
|
|
148
154
|
getAccessCredential
|
|
149
155
|
};
|
|
150
|
-
//# sourceMappingURL=chunk-
|
|
156
|
+
//# sourceMappingURL=chunk-INFWOSTM.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/util/deploy.ts", "../../../src/util/functions.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Client } from '@dxos/client';\nimport { Operation, Script } from '@dxos/compute';\nimport { Context } from '@dxos/context';\nimport { Obj, Ref } from '@dxos/echo';\nimport { getUserFunctionIdInMetadata } from '@dxos/functions';\nimport { bundleFunction } from '@dxos/functions-runtime/bundler';\nimport { FunctionsServiceClient, incrementSemverPatch } from '@dxos/functions-runtime/edge';\nimport { log } from '@dxos/log';\nimport { FunctionRuntimeKind } from '@dxos/protocols';\nimport { type Space } from '@dxos/react-client/echo';\n\nexport const isScriptDeployed = ({ script, fn }: { script: Script.Script; fn: any }): boolean => {\n const existingFunctionId = fn && getUserFunctionIdInMetadata(Obj.getMeta(fn));\n return Boolean(existingFunctionId) && !script.changed;\n};\n\ntype DeployScriptProps = {\n script: Script.Script;\n client: Client;\n space: Space;\n fn?: Operation.PersistentOperation;\n existingFunctionId?: string;\n};\n\ntype DeployScriptResult = { success: boolean; error?: Error; functionId?: string };\n\n/**\n * Deploy a script to a space, handling bundling and uploading to the FaaS infrastructure.\n */\nexport const deployScript = async ({\n script,\n client,\n space,\n fn,\n existingFunctionId,\n}: DeployScriptProps): Promise<DeployScriptResult> => {\n const validationError = validateDeployInputs(script, space);\n if (validationError) {\n return { success: false, error: validationError };\n }\n\n const identity = client.halo.identity.get();\n if (!identity) {\n return { success: false, error: new Error('Identity not available.') };\n }\n\n try {\n const buildResult = await bundleFunction({\n source: script.source!.target!.content,\n });\n if ('error' in buildResult) {\n throw buildResult.error || new Error('Bundle creation failed');\n }\n\n const functionsServiceClient = FunctionsServiceClient.fromClient(client);\n const newFunction = await functionsServiceClient.deploy(Context.default(), {\n ownerUri: identity.did,\n version: fn ? incrementSemverPatch(Obj.getMeta(fn).version ?? '0.0.0') : '0.0.1',\n functionId: existingFunctionId,\n entryPoint: buildResult.entryPoint,\n assets: buildResult.assets,\n runtime: FunctionRuntimeKind.enums.WORKER_LOADER,\n });\n\n const storedFunction = createOrUpdateFunctionInSpace(space, fn, script, newFunction);\n Obj.update(script, (script) => {\n script.changed = false;\n });\n\n return { success: true, functionId: getUserFunctionIdInMetadata(Obj.getMeta(storedFunction)) };\n } catch (err: any) {\n log.catch(err);\n return { success: false, error: err };\n }\n};\n\n/**\n * Validate inputs for script deployment.\n */\nconst validateDeployInputs = (script: Script.Script, space: Space): Error | null => {\n if (!script.source || !space) {\n return new Error('Script source or space not available');\n }\n return null;\n};\n\nconst createOrUpdateFunctionInSpace = (\n space: Space,\n fn: Operation.PersistentOperation | undefined,\n script: Script.Script,\n newFunction: Operation.PersistentOperation,\n): Operation.PersistentOperation => {\n if (fn) {\n Operation.setFrom(fn, newFunction);\n return fn;\n } else {\n Obj.update(newFunction, (newFunction) => {\n newFunction.source = Ref.make(script);\n });\n return space.db.add(newFunction);\n }\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Operation, Script } from '@dxos/compute';\nimport { Obj } from '@dxos/echo';\nimport { getUserFunctionIdInMetadata } from '@dxos/functions';\nimport { getInvocationUrl } from '@dxos/functions-runtime';\nimport { type PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';\n\n/**\n * Get the function URL for a given script and client configuration\n */\nexport const getFunctionUrl = ({\n script,\n fn,\n edgeUrl,\n}: {\n script: Script.Script;\n fn: any;\n edgeUrl: string;\n}): string | undefined => {\n const spaceId = Obj.getDatabase(script)?.spaceId;\n const existingFunctionId = fn && getUserFunctionIdInMetadata(Obj.getMeta(fn));\n\n if (!existingFunctionId) {\n return undefined;\n }\n\n return getInvocationUrl(existingFunctionId, edgeUrl, {\n spaceId,\n });\n};\n\nexport const updateFunctionMetadata = (\n script: Script.Script,\n storedFunction: Operation.PersistentOperation,\n meta: any,\n functionId: string,\n) => {\n Obj.update(storedFunction, (storedFunction) => {\n if (script.description !== undefined && script.description.trim() !== '') {\n storedFunction.description = script.description;\n } else if (meta.description) {\n storedFunction.description = meta.description;\n } else {\n log.verbose('no description in function metadata', { functionId });\n }\n\n if (meta.inputSchema) {\n storedFunction.inputSchema = meta.inputSchema;\n } else {\n log.verbose('no input schema in function metadata', { functionId });\n }\n\n if (meta.outputSchema) {\n storedFunction.outputSchema = meta.outputSchema;\n } else {\n log.verbose('no output schema in function metadata', { functionId });\n }\n\n if (meta.key) {\n Obj.getMeta(storedFunction).key = meta.key;\n } else {\n log.verbose('no key in function metadata', { functionId });\n }\n });\n};\n\nexport const getAccessCredential = (identityKey: PublicKey): Credential => {\n return {\n issuer: identityKey,\n issuanceDate: new Date(),\n subject: {\n id: identityKey,\n assertion: {\n '@type': 'dxos.halo.credentials.ServiceAccess',\n 'serverName': 'hub.dxos.network',\n 'serverKey': identityKey,\n identityKey,\n 'capabilities': ['composer:beta'],\n },\n },\n };\n};\n"],
|
|
5
|
+
"mappings": ";AAKA,SAASA,iBAAyB;AAClC,SAASC,eAAe;AACxB,SAASC,KAAKC,WAAW;AACzB,SAASC,mCAAmC;AAC5C,SAASC,sBAAsB;AAC/B,SAASC,wBAAwBC,4BAA4B;AAC7D,SAASC,WAAW;AACp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KAAA,QAAA,wCAAA;QACnE;MAEIS,GAAAA,EAAAA,YAAKE,YAAc,GAAAV,eAAA,GAAA,IAAA,GAAA,OAAA,CAAA;;AAEvB,QAAA,KAAO,cAAA;AACLD,MAAAA,gBAAY,eAAA,KAAA;;AAAsD,MAAAA,KAAA,QAAA,yCAAA;QACpE;MAEIS,GAAAA,EAAAA,YAAU,YAAA,GAAAR,eAAA,GAAA,IAAA,GAAA,OAAA,CAAA;;AAEd,QAAA,KAAO,KAAA;AACLD,MAAAA,KAAIY,QAAQJ,eAAA,EAAA,MAAA,KAAA;;AAA4C,MAAAR,KAAA,QAAA,+BAAA;QAC1D;MACF,GAAA,EAAA,YAAA,YAAA,GAAAC,eAAA,GAAA,IAAA,GAAA,OAAA,CAAA;IACA;EAEF,CAAA;;IAEIY,sBAAQC,CAAAA,gBAAAA;SACRC;IACAC,QAAAA;kBACMF,oBAAAA,KAAAA;aACJG;UACE;iBACA;QACA,SAAA;QACAH,cAAAA;QACA,aAAA;;wBAAiC;UACnC;QACF;MACF;IACA;;;",
|
|
6
|
+
"names": ["Operation", "Context", "Obj", "Ref", "getUserFunctionIdInMetadata", "bundleFunction", "FunctionsServiceClient", "incrementSemverPatch", "log", "FunctionRuntimeKind", "isScriptDeployed", "Boolean", "existingFunctionId", "script", "changed", "validationError", "error", "success", "buildResult", "functionsServiceClient", "client", "ownerUri", "version", "getMeta", "functionId", "entryPoint", "assets", "runtime", "storedFunction", "createOrUpdateFunctionInSpace", "newFunction", "update", "add", "Obj", "getUserFunctionIdInMetadata", "getInvocationUrl", "log", "__dxlog_file", "existingFunctionId", "fn", "undefined", "script", "description", "trim", "storedFunction", "meta", "inputSchema", "outputSchema", "verbose", "issuer", "identityKey", "issuanceDate", "subject", "assertion"]
|
|
7
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/operations/index.ts
|
|
2
2
|
import { OperationHandlerSet } from "@dxos/compute";
|
|
3
|
-
var ScriptOperationHandlerSet = OperationHandlerSet.lazy(() => import("./create-script-
|
|
3
|
+
var ScriptOperationHandlerSet = OperationHandlerSet.lazy(() => import("./create-script-CIEJOBIU.mjs"));
|
|
4
4
|
|
|
5
5
|
export {
|
|
6
6
|
ScriptOperationHandlerSet
|
|
7
7
|
};
|
|
8
|
-
//# sourceMappingURL=chunk-
|
|
8
|
+
//# sourceMappingURL=chunk-KSVKXCTX.mjs.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// src/skills/functions/index.ts
|
|
2
|
+
import { OperationHandlerSet } from "@dxos/compute";
|
|
3
|
+
var ScriptHandlers = OperationHandlerSet.lazy(() => import("./create-SGHWWTET.mjs"), () => import("./read-OY3K5R3V.mjs"), () => import("./update-Z5VGOLBN.mjs"), () => import("./delete-72RXVLVI.mjs"), () => import("./deploy-PJTJAQZY.mjs"), () => import("./invoke-CDRBQ2WA.mjs"), () => import("./inspect-invocations-ZUXVUAML.mjs"), () => import("./query-deployed-functions-RBQMGON2.mjs"), () => import("./install-function-YFDZLVMJ.mjs"));
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
ScriptHandlers
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=chunk-USJ44FIU.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/
|
|
3
|
+
"sources": ["../../../src/skills/functions/index.ts"],
|
|
4
4
|
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { OperationHandlerSet } from '@dxos/compute';\n\nexport * from './definitions';\n\nexport const ScriptHandlers = OperationHandlerSet.lazy(\n () => import('./create'),\n () => import('./read'),\n () => import('./update'),\n () => import('./delete'),\n () => import('./deploy'),\n () => import('./invoke'),\n () => import('./inspect-invocations'),\n () => import('./query-deployed-functions'),\n () => import('./install-function'),\n);\n"],
|
|
5
5
|
"mappings": ";AAIA,SAASA,2BAA2B;AAI7B,IAAMC,iBAAiBD,oBAAoBE,KAChD,MAAM,OAAO,uBAAA,GACb,MAAM,OAAO,qBAAA,GACb,MAAM,OAAO,uBAAA,GACb,MAAM,OAAO,uBAAA,GACb,MAAM,OAAO,uBAAA,GACb,MAAM,OAAO,uBAAA,GACb,MAAM,OAAO,oCAAA,GACb,MAAM,OAAO,yCAAA,GACb,MAAM,OAAO,iCAAA,CAAA;",
|
|
6
6
|
"names": ["OperationHandlerSet", "ScriptHandlers", "lazy"]
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
// raw-loader:/__w/dxos/dxos/packages/plugins/plugin-script/src/templates/anthropic.ts
|
|
2
|
-
var anthropic_default = "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as LanguageModel from '@effect/ai/LanguageModel';\nimport * as Chunk from 'effect/Chunk';\nimport * as Effect from 'effect/Effect';\nimport * as Schema from 'effect/Schema';\nimport * as Stream from 'effect/Stream';\n\nimport { AiService } from '@dxos/ai';\nimport { Operation } from '@dxos/compute';\nimport { DXN } from '@dxos/keys';\n\nconst Anthropic = Operation.make({\n meta: {\n key: DXN.make('org.dxos.script.anthropic'),\n name: 'Anthropic Chat',\n description: 'Chat with Anthropic',\n },\n input: Schema.Struct({\n message: Schema.String,\n }),\n output: Schema.Any,\n services: [AiService.AiService],\n});\n\nexport default Anthropic.pipe(\n Operation.withHandler(\n Effect.fn(function* ({ message }) {\n const model =
|
|
2
|
+
var anthropic_default = "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as LanguageModel from '@effect/ai/LanguageModel';\nimport * as Chunk from 'effect/Chunk';\nimport * as Effect from 'effect/Effect';\nimport * as Schema from 'effect/Schema';\nimport * as Stream from 'effect/Stream';\n\nimport { AiService } from '@dxos/ai';\nimport { Operation } from '@dxos/compute';\nimport { DXN } from '@dxos/keys';\n\nconst Anthropic = Operation.make({\n meta: {\n key: DXN.make('org.dxos.script.anthropic'),\n name: 'Anthropic Chat',\n description: 'Chat with Anthropic',\n },\n input: Schema.Struct({\n message: Schema.String,\n }),\n output: Schema.Any,\n services: [AiService.AiService],\n});\n\nexport default Anthropic.pipe(\n Operation.withHandler(\n Effect.fn(function* ({ message }) {\n const model = AiService.model('com.anthropic.model.claude-sonnet-4-6.default');\n\n //\n // Basic example.\n //\n const { text } = yield* LanguageModel.generateText({ prompt: message }).pipe(Effect.provide(model));\n\n //\n // Streaming example.\n //\n const parts = yield* LanguageModel.streamText({\n prompt: 'Count from 1 to 5, one number per line.',\n }).pipe(Stream.runCollect, Effect.map(Chunk.toArray), Effect.provide(model));\n const textDeltas = parts.filter((p) => p.type === 'text-delta');\n const fullText = textDeltas.map((p) => (p as { delta: string }).delta).join('');\n\n return { response: text, streamText: fullText };\n }),\n ),\n);\n";
|
|
3
3
|
|
|
4
4
|
// raw-loader:/__w/dxos/dxos/packages/plugins/plugin-script/src/templates/chess-bot.ts
|
|
5
|
-
var chess_bot_default = "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Chess as ChessJS } from 'chess.js';\nimport * as Effect from 'effect/Effect';\nimport * as Schema from 'effect/Schema';\n\nimport { Operation } from '@dxos/compute';\nimport { Database,
|
|
5
|
+
var chess_bot_default = "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Chess as ChessJS } from 'chess.js';\nimport * as Effect from 'effect/Effect';\nimport * as Schema from 'effect/Schema';\n\nimport { Operation } from '@dxos/compute';\nimport { Database, DXN, Obj } from '@dxos/echo';\nimport { Chess } from '@dxos/plugin-chess';\nimport { Game, GameRef, loadGame } from '@dxos/plugin-game';\n\nconst ChessBot = Operation.make({\n meta: {\n key: DXN.make('org.dxos.script.chessBot'),\n name: 'Chess Bot',\n description: 'Plays a random move in a chess game.',\n },\n input: Schema.Struct({\n game: GameRef(Chess.State).annotations({\n description: 'The chess game to comment on.',\n }),\n player: Schema.optional(Schema.Literal('white', 'black')).annotations({\n description: 'The player to play the game as.',\n }),\n }),\n output: Schema.Struct({\n state: Schema.String.annotations({\n description: 'The state of the game as an ASCII art board.',\n }),\n }),\n types: [Game, Chess.State],\n services: [Database.Service],\n});\n\nexport default ChessBot.pipe(\n Operation.withHandler(\n Effect.fnUntraced(function* ({ game, player = 'black' }) {\n const { variant } = yield* loadGame(game, Chess.State);\n const chess = new ChessJS();\n chess.loadPgn(variant.pgn ?? '');\n if (chess.turn() !== (player === 'white' ? 'w' : 'b')) {\n return { state: chess.ascii() };\n }\n\n const moves = chess.moves({ verbose: true });\n const move = moves[Math.floor(Math.random() * moves.length)];\n if (!move) {\n return { state: chess.ascii() };\n }\n\n chess.move(move.san);\n const newPgn = chess.pgn();\n Obj.update(variant, (variant) => {\n const mutable = variant as Obj.Mutable<typeof variant>;\n mutable.pgn = newPgn;\n });\n yield* Database.flush();\n return { state: chess.ascii() };\n }),\n ),\n);\n";
|
|
6
6
|
|
|
7
7
|
// raw-loader:/__w/dxos/dxos/packages/plugins/plugin-script/src/templates/commentary.ts
|
|
8
|
-
var commentary_default = "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as A from '@automerge/automerge';\nimport { Chess as ChessJS } from 'chess.js';\nimport * as Array from 'effect/Array';\nimport * as Effect from 'effect/Effect';\nimport * as Function from 'effect/Function';\nimport * as Layer from 'effect/Layer';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\n\nimport { AiService, ConsolePrinter, ToolExecutionService, ToolResolverService } from '@dxos/ai';\nimport { AppAnnotation } from '@dxos/app-toolkit';\nimport { AiRequest, GenerationObserver } from '@dxos/assistant';\nimport { Trace, Operation } from '@dxos/compute';\nimport { Annotation, Collection, Database, DXN, Filter, Obj, Ref, Relation, URI } from '@dxos/echo';\nimport { createDocAccessor } from '@dxos/echo-client';\nimport { registryLayerNoop } from '@dxos/echo/testing';\nimport { log } from '@dxos/log';\nimport { Chess } from '@dxos/plugin-chess';\nimport { Game, GameRef, loadGame } from '@dxos/plugin-game';\nimport { Markdown } from '@dxos/plugin-markdown';\nimport { Text } from '@dxos/schema';\nimport { HasSubject } from '@dxos/types';\nimport { trim } from '@dxos/util';\n\nconst Commentary = Operation.make({\n meta: {\n key: DXN.make('org.dxos.function.chess.commentary'),\n name: 'Commentary',\n description: 'Adds commentary about the most recent move to a markdown document associated with the chess game.',\n },\n input: Schema.Struct({\n game: GameRef(Chess.State).annotations({\n description: 'The chess game to comment on.',\n }),\n }),\n output: Schema.Union(\n Schema.Struct({\n documentId: URI.Schema.annotations({\n description: 'The ID of the markdown document that was updated or created.',\n }),\n commentary: Schema.String.annotations({\n description: 'The commentary that was added.',\n }),\n }),\n Schema.Void.annotations({\n description: 'Function did not find anything to comment on.',\n }),\n ),\n types: [Game, Chess.State, Markdown.Document, Text.Text, HasSubject.HasSubject, Collection.Collection],\n services: [AiService.AiService, Database.Service],\n});\n\nexport default Commentary.pipe(\n Operation.withHandler(\n Effect.fnUntraced(\n function* ({ game: gameRef }) {\n // Load the game and its Chess variant state.\n log.info('load game', { gameRef });\n const { game: chessGame, variant: chessState } = yield* loadGame(gameRef, Chess.State);\n\n // Load the chess position from PGN or FEN.\n const chess = new ChessJS();\n if (chessState.pgn) {\n chess.loadPgn(chessState.pgn);\n } else if (chessState.fen) {\n chess.load(chessState.fen);\n } else {\n log.info('Early return: no pgn or fen');\n return;\n }\n\n // Get the most recent move\n const history = chess.history({ verbose: true });\n if (history.length === 0) {\n throw new Error('No moves have been played yet');\n }\n const lastMove = history[history.length - 1];\n const moveNumber = Math.ceil(history.length / 2);\n const isWhiteMove = history.length % 2 === 1;\n const player = isWhiteMove ? 'White' : 'Black';\n const moveNotation = lastMove.san;\n\n // Generate AI commentary about the move\n const result = yield* new AiRequest.Request({\n observer: GenerationObserver.fromPrinter(new ConsolePrinter({ tag: 'chess-commentary' })),\n }).run({\n prompt:\n `Comment on this chess move as if you're commentating a live match for an audience:\\n\\n` +\n `Move ${moveNumber}: ${player} plays ${moveNotation} (${lastMove.from} to ${lastMove.to})${lastMove.captured ? `, capturing ${lastMove.captured}` : ''}\\n` +\n `Current position: ${chess.fen()}\\n` +\n `${chess.isCheck() ? 'The king is in check! ' : ''}` +\n `${chess.isCheckmate() ? 'CHECKMATE! ' : ''}` +\n `${chess.isStalemate() ? 'STALEMATE! ' : ''}` +\n `\\nGame so far:\\n${chess.pgn()}`,\n system: COMMENTARY_SYSTEM_PROMPT,\n history: [],\n });\n\n const commentaryText = Function.pipe(\n result,\n Array.findLast((msg) => msg.sender.role === 'assistant' && msg.blocks.some((block) => block._tag === 'text')),\n Option.flatMap((msg) =>\n Function.pipe(\n msg.blocks,\n Array.findLast((block) => block._tag === 'text'),\n Option.map((block) => block.text),\n ),\n ),\n Option.getOrThrowWith(() => new Error('No commentary generated')),\n );\n\n const commentary = `## Move ${moveNumber}: ${player} plays ${moveNotation}\\n\\n${commentaryText}\\n\\n`;\n log.info('commentary', { commentary });\n\n // TODO(wittjosiah): Functions currently don't support traversals.\n // const docs = yield* Database.query(\n // Query.select(Filter.id(chessGame.id)).targetOf(HasSubject.HasSubject).source(),\n // ).run.pipe(Effect.map((objects) => objects.filter((object) => Obj.instanceOf(Markdown.Document, object))));\n const docs = yield* Database.query(Filter.type(HasSubject.HasSubject)).run.pipe(\n Effect.map((relations) =>\n relations.filter((relation) => {\n // TODO(wittjosiah): This is a workaround for getTarget not handling deleted objects.\n try {\n log.info('relation', {\n source: Obj.getURI(Relation.getTarget(relation)),\n game: Obj.getURI(chessGame),\n });\n return Obj.getURI(Relation.getTarget(relation)) === Obj.getURI(chessGame);\n } catch {\n return false;\n }\n }),\n ),\n Effect.map((relations) =>\n relations\n .map((relation) => {\n // TODO(wittjosiah): This is a workaround for getSource not handling deleted objects.\n try {\n return Relation.getSource(relation);\n } catch {\n return undefined;\n }\n })\n .filter((source) => source !== undefined),\n ),\n Effect.map((sources) => {\n const docs = sources.filter((source) => Obj.instanceOf(Markdown.Document, source));\n log.info('docs', { sources, docs });\n return docs;\n }),\n );\n log.info('docs', { count: docs.length });\n\n let document: Markdown.Document;\n if (docs.length === 0) {\n // TODO(wittjosiah): Deploy fails if `SpaceProperties` schema is imported because its from `client-protocol`.\n const [properties] = yield* Database.query(Filter.type(DXN.make('org.dxos.type.spaceProperties'))).run;\n const rootCollectionRef = Annotation.get(properties, AppAnnotation.RootCollectionAnnotation).pipe(\n Option.getOrUndefined,\n );\n const rootCollection = rootCollectionRef\n ? yield* Database.load<Collection.Collection>(rootCollectionRef)\n : undefined;\n\n log.info('rootCollection', { rootCollection });\n\n // Create a new markdown document\n const gameName = chessGame.name || 'Chess Game';\n document = yield* Database.add(\n Markdown.make({\n name: `${gameName} Commentary`,\n content: `# ${gameName} Commentary\\n\\n${commentary}`,\n }),\n );\n\n const documentRef = Ref.make(document);\n if (rootCollection) {\n Obj.update(rootCollection, (rootCollection) => {\n rootCollection.objects.push(documentRef);\n });\n }\n\n // Create the HasSubject relation\n yield* Database.add(\n Relation.make(HasSubject.HasSubject, {\n [Relation.Source]: document,\n [Relation.Target]: chessGame,\n }),\n );\n } else {\n document = docs[0];\n\n // Load the text content and append the commentary\n const text = yield* Database.load(document.content);\n const accessor = createDocAccessor(text, ['content']);\n accessor.handle.change((doc: A.Doc<Text.Text>) => {\n A.splice(doc, accessor.path.slice(), text.content.length, 0, commentary);\n });\n }\n\n log.info('result', { documentId: Obj.getURI(document), commentary });\n\n yield* Database.flush();\n\n return {\n documentId: Obj.getURI(document),\n commentary,\n };\n },\n Effect.provide(\n Layer.mergeAll(\n AiService.model('ai.claude.model.claude-haiku-4-5'),\n ToolResolverService.layerEmpty,\n ToolExecutionService.layerEmpty,\n Trace.writerLayerNoop,\n Database.notAvailable,\n Layer.succeed(Operation.Service, {\n invoke: () => Effect.die('Not available.'),\n schedule: () => Effect.die('Not available.'),\n invokePromise: async () => ({ error: new Error('Not available.') }),\n } as any),\n registryLayerNoop,\n ),\n ),\n ),\n ),\n);\n\nconst COMMENTARY_SYSTEM_PROMPT = trim`\n You are a professional chess commentator providing live commentary for a chess match.\n\n # Style\n - Write in an engaging, enthusiastic style as if commentating for a live audience\n - Be concise but informative (2-4 sentences)\n - Explain the strategic implications of the move\n - Note any tactical elements (captures, threats, checks)\n - Comment on the position and what it means for the game\n\n # Format\n - Write in plain text (no markdown formatting in the commentary itself)\n - Be natural and conversational\n - Use chess terminology appropriately but keep it accessible\n\n # Special Situations\n - If it's checkmate, express excitement about the conclusion\n - If it's check, note the pressure on the king\n - If a piece is captured, mention the material exchange\n - Comment on the development of pieces and control of key squares when relevant\n`;\n";
|
|
8
|
+
var commentary_default = "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as A from '@automerge/automerge';\nimport { Chess as ChessJS } from 'chess.js';\nimport * as Array from 'effect/Array';\nimport * as Effect from 'effect/Effect';\nimport * as Function from 'effect/Function';\nimport * as Layer from 'effect/Layer';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\n\nimport { AiService, ConsolePrinter, ToolExecutionService, ToolResolverService } from '@dxos/ai';\nimport { AppAnnotation } from '@dxos/app-toolkit';\nimport { AiRequest, GenerationObserver } from '@dxos/assistant';\nimport { Operation, Trace } from '@dxos/compute';\nimport { Annotation, Collection, Database, DXN, Filter, Obj, Ref, Relation, URI } from '@dxos/echo';\nimport { Doc } from '@dxos/echo-doc';\nimport { registryLayerNoop } from '@dxos/echo/testing';\nimport { log } from '@dxos/log';\nimport { Chess } from '@dxos/plugin-chess';\nimport { Game, GameRef, loadGame } from '@dxos/plugin-game';\nimport { Markdown } from '@dxos/plugin-markdown';\nimport { Text } from '@dxos/schema';\nimport { HasSubject } from '@dxos/types';\nimport { trim } from '@dxos/util';\n\nconst Commentary = Operation.make({\n meta: {\n key: DXN.make('org.dxos.function.chess.commentary'),\n name: 'Commentary',\n description: 'Adds commentary about the most recent move to a markdown document associated with the chess game.',\n },\n input: Schema.Struct({\n game: GameRef(Chess.State).annotations({\n description: 'The chess game to comment on.',\n }),\n }),\n output: Schema.Union(\n Schema.Struct({\n documentId: URI.Schema.annotations({\n description: 'The ID of the markdown document that was updated or created.',\n }),\n commentary: Schema.String.annotations({\n description: 'The commentary that was added.',\n }),\n }),\n Schema.Void.annotations({\n description: 'Function did not find anything to comment on.',\n }),\n ),\n types: [Game, Chess.State, Markdown.Document, Text.Text, HasSubject.HasSubject, Collection.Collection],\n services: [AiService.AiService, Database.Service],\n});\n\nexport default Commentary.pipe(\n Operation.withHandler(\n Effect.fnUntraced(\n function* ({ game: gameRef }) {\n // Load the game and its Chess variant state.\n log.info('load game', { gameRef });\n const { game: chessGame, variant: chessState } = yield* loadGame(gameRef, Chess.State);\n\n // Load the chess position from PGN or FEN.\n const chess = new ChessJS();\n if (chessState.pgn) {\n chess.loadPgn(chessState.pgn);\n } else if (chessState.fen) {\n chess.load(chessState.fen);\n } else {\n log.info('Early return: no pgn or fen');\n return;\n }\n\n // Get the most recent move\n const history = chess.history({ verbose: true });\n if (history.length === 0) {\n throw new Error('No moves have been played yet');\n }\n const lastMove = history[history.length - 1];\n const moveNumber = Math.ceil(history.length / 2);\n const isWhiteMove = history.length % 2 === 1;\n const player = isWhiteMove ? 'White' : 'Black';\n const moveNotation = lastMove.san;\n\n // Generate AI commentary about the move\n const result = yield* new AiRequest.Request({\n observer: GenerationObserver.fromPrinter(new ConsolePrinter({ tag: 'chess-commentary' })),\n }).run({\n prompt:\n `Comment on this chess move as if you're commentating a live match for an audience:\\n\\n` +\n `Move ${moveNumber}: ${player} plays ${moveNotation} (${lastMove.from} to ${lastMove.to})${lastMove.captured ? `, capturing ${lastMove.captured}` : ''}\\n` +\n `Current position: ${chess.fen()}\\n` +\n `${chess.isCheck() ? 'The king is in check! ' : ''}` +\n `${chess.isCheckmate() ? 'CHECKMATE! ' : ''}` +\n `${chess.isStalemate() ? 'STALEMATE! ' : ''}` +\n `\\nGame so far:\\n${chess.pgn()}`,\n system: COMMENTARY_SYSTEM_PROMPT,\n history: [],\n });\n\n const commentaryText = Function.pipe(\n result,\n Array.findLast((msg) => msg.sender.role === 'assistant' && msg.blocks.some((block) => block._tag === 'text')),\n Option.flatMap((msg) =>\n Function.pipe(\n msg.blocks,\n Array.findLast((block) => block._tag === 'text'),\n Option.map((block) => block.text),\n ),\n ),\n Option.getOrThrowWith(() => new Error('No commentary generated')),\n );\n\n const commentary = `## Move ${moveNumber}: ${player} plays ${moveNotation}\\n\\n${commentaryText}\\n\\n`;\n log.info('commentary', { commentary });\n\n // TODO(wittjosiah): Functions currently don't support traversals.\n // const docs = yield* Database.query(\n // Query.select(Filter.id(chessGame.id)).targetOf(HasSubject.HasSubject).source(),\n // ).run.pipe(Effect.map((objects) => objects.filter((object) => Obj.instanceOf(Markdown.Document, object))));\n const docs = yield* Database.query(Filter.type(HasSubject.HasSubject)).run.pipe(\n Effect.map((relations) =>\n relations.filter((relation) => {\n // TODO(wittjosiah): This is a workaround for getTarget not handling deleted objects.\n try {\n log.info('relation', {\n source: Obj.getURI(Relation.getTarget(relation)),\n game: Obj.getURI(chessGame),\n });\n return Obj.getURI(Relation.getTarget(relation)) === Obj.getURI(chessGame);\n } catch {\n return false;\n }\n }),\n ),\n Effect.map((relations) =>\n relations\n .map((relation) => {\n // TODO(wittjosiah): This is a workaround for getSource not handling deleted objects.\n try {\n return Relation.getSource(relation);\n } catch {\n return undefined;\n }\n })\n .filter((source) => source !== undefined),\n ),\n Effect.map((sources) => {\n const docs = sources.filter((source) => Obj.instanceOf(Markdown.Document, source));\n log.info('docs', { sources, docs });\n return docs;\n }),\n );\n log.info('docs', { count: docs.length });\n\n let document: Markdown.Document;\n if (docs.length === 0) {\n // TODO(wittjosiah): Deploy fails if `SpaceProperties` schema is imported because its from `client-protocol`.\n const [properties] = yield* Database.query(Filter.type(DXN.make('org.dxos.type.spaceProperties'))).run;\n const rootCollectionRef = Annotation.get(properties, AppAnnotation.RootCollectionAnnotation).pipe(\n Option.getOrUndefined,\n );\n const rootCollection = rootCollectionRef\n ? yield* Database.load<Collection.Collection>(rootCollectionRef)\n : undefined;\n\n log.info('rootCollection', { rootCollection });\n\n // Create a new markdown document\n const gameName = chessGame.name || 'Chess Game';\n document = yield* Database.add(\n Markdown.make({\n name: `${gameName} Commentary`,\n content: `# ${gameName} Commentary\\n\\n${commentary}`,\n }),\n );\n\n const documentRef = Ref.make(document);\n if (rootCollection) {\n Obj.update(rootCollection, (rootCollection) => {\n rootCollection.objects.push(documentRef);\n });\n }\n\n // Create the HasSubject relation\n yield* Database.add(\n Relation.make(HasSubject.HasSubject, {\n [Relation.Source]: document,\n [Relation.Target]: chessGame,\n }),\n );\n } else {\n document = docs[0];\n\n // Load the text content and append the commentary\n const text = yield* Database.load(document.content);\n const accessor = Doc.createAccessor(text, ['content']);\n accessor.handle.change((doc: A.Doc<Text.Text>) => {\n A.splice(doc, accessor.path.slice(), text.content.length, 0, commentary);\n });\n }\n\n log.info('result', { documentId: Obj.getURI(document), commentary });\n\n yield* Database.flush();\n\n return {\n documentId: Obj.getURI(document),\n commentary,\n };\n },\n Effect.provide(\n Layer.mergeAll(\n AiService.model('com.anthropic.model.claude-haiku-4-5.default'),\n ToolResolverService.layerEmpty,\n ToolExecutionService.layerEmpty,\n Trace.writerLayerNoop,\n Database.notAvailable,\n Layer.succeed(Operation.Service, {\n invoke: () => Effect.die('Not available.'),\n schedule: () => Effect.die('Not available.'),\n invokePromise: async () => ({ error: new Error('Not available.') }),\n } as any),\n registryLayerNoop,\n ),\n ),\n ),\n ),\n);\n\nconst COMMENTARY_SYSTEM_PROMPT = trim`\n You are a professional chess commentator providing live commentary for a chess match.\n\n # Style\n - Write in an engaging, enthusiastic style as if commentating for a live audience\n - Be concise but informative (2-4 sentences)\n - Explain the strategic implications of the move\n - Note any tactical elements (captures, threats, checks)\n - Comment on the position and what it means for the game\n\n # Format\n - Write in plain text (no markdown formatting in the commentary itself)\n - Be natural and conversational\n - Use chess terminology appropriately but keep it accessible\n\n # Special Situations\n - If it's checkmate, express excitement about the conclusion\n - If it's check, note the pressure on the king\n - If a piece is captured, mention the material exchange\n - Comment on the development of pieces and control of key squares when relevant\n`;\n";
|
|
9
9
|
|
|
10
10
|
// raw-loader:/__w/dxos/dxos/packages/plugins/plugin-script/src/templates/data-generator.ts
|
|
11
11
|
var data_generator_default = "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { Expando, S, create, defineFunction } from 'dxos:functions';\n// @ts-ignore\nimport { randText } from 'https://esm.sh/@ngneat/falso@7.1.1?bundle=false';\n\nexport default defineFunction({\n key: 'org.dxos.script.data-generator',\n name: 'Data Generator',\n inputSchema: S.Struct({\n documentAmount: S.optional(S.Number),\n textSize: S.optional(S.Number),\n mutationAmount: S.optional(S.Number),\n waitAfterCreation: S.optional(S.Number),\n }),\n\n outputSchema: S.Struct({}),\n\n handler: async ({\n data: { documentAmount = 1, textSize = 10, mutationAmount = 0, waitAfterCreation = 10_000 },\n context: { space },\n }: any) => {\n space.db.graph.registry.add([Expando]);\n const result: Record<string, any> = {};\n const objects: Expando[] = [];\n\n // Create objects.\n for (let i = 0; i < documentAmount; i++) {\n const obj = space.db.add(\n create(Expando, {\n name: 'scriptGenerated',\n content: randText({ charCount: textSize }),\n }),\n );\n objects.push(obj);\n const objectResult: any = {};\n // Mutate the object.\n for (let i = 0; i < mutationAmount; i++) {\n obj.content = randText({ charCount: textSize });\n }\n objectResult.mutations = mutationAmount;\n objectResult.contentLength = obj.content.length;\n result[obj.id] = objectResult;\n }\n\n // Flush and wait for data to propagate.\n await space.db.flush();\n await new Promise((resolve) => setTimeout(resolve, waitAfterCreation));\n return { createdObjects: objects.length };\n },\n});\n";
|
|
12
12
|
|
|
13
13
|
// raw-loader:/__w/dxos/dxos/packages/plugins/plugin-script/src/templates/discord.ts
|
|
14
|
-
var discord_default = "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { DXN, EchoObject,
|
|
14
|
+
var discord_default = "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { DXN, EchoObject, EntityId, Filter, S, create, defineFunction } from 'dxos:functions';\n// @ts-ignore\nimport { FetchHttpClient } from 'https://esm.sh/@effect/platform@0.89.0?deps=effect@3.17.0&bundle=false';\nimport {\n DiscordConfig,\n DiscordREST,\n DiscordRESTMemoryLive,\n // @ts-ignore\n} from 'https://esm.sh/dfx@0.113.0?deps=effect@3.17.0&bundle=false';\n// @ts-ignore\nimport * as Config from 'https://esm.sh/effect@3.17.0/Config?bundle=false';\n// @ts-ignore\nimport * as Effect from 'https://esm.sh/effect@3.17.0/Effect?bundle=false';\n// @ts-ignore\nimport * as Redacted from 'https://esm.sh/effect@3.17.0/Redacted?bundle=false';\n// @ts-ignore\nimport * as Ref from 'https://esm.sh/effect@3.17.0/Ref?bundle=false';\n\nconst MessageSchema = S.Struct({\n id: EntityId,\n foreignId: S.Any, // bigint?\n from: S.String,\n created: S.String,\n content: S.String,\n}).pipe(\n EchoObject({\n typename: 'com.example.type.message',\n version: '0.1.0',\n }),\n);\n\nconst DEFAULT_AFTER = 1704067200; // 2024-01-01\n\nconst generateSnowflake = (unixTimestamp: number): bigint => {\n const discordEpoch = 1420070400000n; // Discord Epoch (ms)\n return (BigInt(unixTimestamp * 1000) - discordEpoch) << 22n;\n};\n\nexport default defineFunction({\n key: 'org.dxos.script.discord',\n name: 'Discord',\n inputSchema: S.Struct({\n // TODO(wittjosiah): Remove. This is used to provide a terminal for a cron trigger.\n tick: S.optional(S.String),\n channelId: S.String,\n after: S.optional(S.Number),\n pageSize: S.optional(S.Number),\n queueId: S.String,\n }),\n\n outputSchema: S.Struct({\n newMessages: S.Number,\n }),\n\n handler: ({ data: { channelId, queueId, after = DEFAULT_AFTER, pageSize = 5 }, context: { space } }: any) =>\n Effect.gen(function* () {\n const { token } = yield* Effect.tryPromise({\n try: () => space.db.query(Filter.typename('org.dxos.type.accessToken', { source: 'discord.com' })).first(),\n catch: (e: any) => e,\n });\n const { objects } = yield* Effect.tryPromise({\n try: () => space.queues.queryQueue(DXN.tryMake(queueId)!),\n catch: (e: any) => e,\n });\n const backfill = objects.length === 0;\n const newMessages = yield* Ref.make(0);\n const lastMessage = yield* Ref.make(objects.at(-1));\n\n const enqueueMessages = Effect.gen(function* () {\n const rest = yield* DiscordREST;\n\n while (true) {\n const last = yield* Ref.get(lastMessage);\n const options = {\n after: backfill && !last ? `${generateSnowflake(after)}` : last?.foreignId,\n limit: pageSize,\n };\n const messages = yield* rest.getChannelMessages(channelId, options).pipe((res: any) => res.json);\n const queueMessages = messages\n .map((message: any) =>\n create(MessageSchema, {\n id: EntityId.random(),\n foreignId: message.id,\n from: message.author.username,\n created: message.timestamp,\n content: message.content,\n }),\n )\n .toReversed();\n if (queueMessages.length > 0) {\n yield* Effect.tryPromise({\n try: () => space.queues.insertIntoQueue(DXN.tryMake(queueId)!, queueMessages),\n catch: (e: any) => e,\n });\n yield* Ref.update(newMessages, (n: any) => n + queueMessages.length);\n yield* Ref.update(lastMessage, (m: any) => queueMessages.at(-1));\n }\n if (messages.length < pageSize) {\n break;\n }\n }\n }).pipe(\n Effect.provide(DiscordRESTMemoryLive),\n Effect.provide(\n DiscordConfig.layerConfig({\n token: Config.succeed(Redacted.make(token)),\n }),\n ),\n Effect.provide(FetchHttpClient.layer),\n );\n\n yield* enqueueMessages;\n return { newMessages: yield* Ref.get(newMessages) };\n }),\n});\n";
|
|
15
15
|
|
|
16
16
|
// raw-loader:/__w/dxos/dxos/packages/plugins/plugin-script/src/templates/email.ts
|
|
17
17
|
var email_default = "//\n// Copyright 2024 DXOS.org\n//\n\n/**\n * Appends a message to the end of a Document configured through a trigger.\n * Trigger must have a targetDocumentId field set in Meta.\n */\nexport default async ({ data: { bodyText }, context: { space } }: any) => {\n const { email, targetDocumentId: documentId } = JSON.parse(bodyText) as RequestPayload;\n\n const document = await space.db.query({ id: documentId }).first();\n\n const contentId = document.content['/'].split(':')[3];\n const documentContent = await space.db.query({ id: contentId }).first();\n const modifiedContent = [\n documentContent.content,\n '',\n '---',\n `**From:** ${email.from}`,\n `**Subject:** ${email.subject}`,\n `**Date:** ${email.created}`,\n '',\n email.body,\n ].join('\\n');\n\n await space.db.update({ id: contentId }, { content: modifiedContent });\n\n return new Response(JSON.stringify({ success: true }));\n};\n\ntype RequestPayload = {\n email: { from: string; subject: string; created: string; body: string };\n targetDocumentId: string;\n};\n";
|
|
@@ -23,7 +23,7 @@ var forex_effect_default = "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Fe
|
|
|
23
23
|
var forex_default = "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\nimport * as Schema from 'effect/Schema';\n\nimport { Operation } from '@dxos/compute';\nimport { DXN } from '@dxos/keys';\n\nconst Forex = Operation.make({\n meta: {\n key: DXN.make('org.dxos.script.forex'),\n name: 'Forex',\n description: 'Returns the exchange rate between two currencies.',\n },\n input: Schema.Struct({\n from: Schema.String.annotations({ description: 'The source currency' }),\n to: Schema.String.annotations({ description: 'The target currency' }),\n }),\n output: Schema.Any,\n});\n\nexport default Forex.pipe(\n Operation.withHandler(\n Effect.fn(function* ({ from: rawFrom, to: rawTo }) {\n const from = rawFrom.toUpperCase();\n const to = rawTo.toUpperCase();\n const res = yield* Effect.promise(() => fetch(`https://free.ratesdb.com/v1/rates?from=${from}&to=${to}`));\n const {\n data: { rates },\n } = yield* Effect.promise(() => res.json());\n\n return rates[to].toString();\n }),\n ),\n);\n";
|
|
24
24
|
|
|
25
25
|
// raw-loader:/__w/dxos/dxos/packages/plugins/plugin-script/src/templates/gmail.ts
|
|
26
|
-
var gmail_default = "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { EchoObject,
|
|
26
|
+
var gmail_default = "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { EchoObject, EntityId, Filter, S, create, defineFunction } from 'dxos:functions';\n// @ts-ignore\nimport {\n FetchHttpClient,\n HttpClient,\n HttpClientRequest,\n // @ts-ignore\n} from 'https://esm.sh/@effect/platform@0.89.0?deps=effect@3.17.0&bundle=false';\n// @ts-ignore\nimport { format, subDays } from 'https://esm.sh/date-fns@3.3.1?bundle=false';\n// @ts-ignore\nimport * as Chunk from 'https://esm.sh/effect@3.17.0/Chunk?bundle=false';\n// @ts-ignore\nimport * as Effect from 'https://esm.sh/effect@3.17.0/Effect?bundle=false';\n// @ts-ignore\nimport * as Function from 'https://esm.sh/effect@3.17.0/Function?bundle=false';\n// @ts-ignore\nimport * as Ref from 'https://esm.sh/effect@3.17.0/Ref?bundle=false';\n// @ts-ignore\nimport * as Schedule from 'https://esm.sh/effect@3.17.0/Schedule?bundle=false';\n// @ts-ignore\nimport * as Stream from 'https://esm.sh/effect@3.17.0/Stream?bundle=false';\n\nexport default defineFunction({\n key: 'org.dxos.script.gmail',\n name: 'Gmail',\n inputSchema: S.Struct({\n mailboxId: S.String,\n userId: S.optional(S.String).pipe(S.withDecodingDefault(() => 'me')),\n after: S.optional(S.Union(S.Number, S.String)).pipe(\n S.withDecodingDefault(() => format(subDays(new Date(), 30), 'yyyy-MM-dd')),\n ),\n pageSize: S.optional(S.Number).pipe(S.withDecodingDefault(() => 100)),\n // TODO(wittjosiah): Remove. This is used to provide a terminal for a cron trigger.\n tick: S.optional(S.String),\n }),\n\n outputSchema: S.Struct({\n newMessages: S.Number,\n }),\n\n handler: ({ context: { space }, data: { mailboxId, userId, after, pageSize } }: any) =>\n Effect.gen(function* () {\n const { token } = yield* Effect.tryPromise({\n try: () => space.db.query(Filter.typename('org.dxos.type.accessToken', { source: 'gmail.com' })).first(),\n catch: (e: any) => e,\n });\n\n // NOTE: Google API bundles size is v. large and caused runtime issues.\n const makeRequest = (url: string) =>\n Function.pipe(\n url,\n HttpClientRequest.get,\n HttpClientRequest.setHeaders({ Authorization: `Bearer ${token}`, Accept: 'application/json' }),\n HttpClient.execute,\n Effect.flatMap((res: any) => res.json),\n Effect.timeout('1 second'),\n Effect.retry(Schedule.exponential(1000).pipe(Schedule.compose(Schedule.recurs(3)))),\n Effect.scoped,\n );\n\n const listMessages = (userId: string, q: string, pageSize: number, pageToken: string | null) =>\n makeRequest(getUrl(userId, undefined, { q, pageSize, pageToken }));\n\n const getMessage = (userId: string, messageId: string) => makeRequest(getUrl(userId, messageId));\n\n const mailbox = yield* Effect.tryPromise({\n try: () => space.db.query({ id: mailboxId }).first(),\n catch: (e: any) => e,\n });\n const { objects } = yield* Effect.tryPromise({\n try: () => space.queues.queryQueue(mailbox.queue.uri),\n catch: (e: any) => e,\n });\n const newMessages = yield* Ref.make([]);\n const nextPage = yield* Ref.make(null);\n\n do {\n const last = objects.at(-1);\n const q = last\n ? `in:inbox after:${Math.floor(new Date(last.created).getTime() / 1000)}`\n : `in:inbox after:${after}`;\n const pageToken = yield* Ref.get(nextPage);\n const { messages, nextPageToken } = yield* listMessages(userId, q, pageSize, pageToken);\n yield* Ref.update(nextPage, () => nextPageToken);\n for (const message of messages) {\n const messageDetails = yield* getMessage(userId, message.id);\n const created = new Date(parseInt(messageDetails.internalDate)).toISOString();\n const from = messageDetails.payload.headers.find((h: any) => h.name === 'From');\n const sender = from && parseFromHeader(from.value);\n // TODO(wittjosiah): Improve parsing of email contents.\n const content =\n messageDetails.payload.body?.data ??\n messageDetails.payload.parts?.find((p: any) => p.mimeType === 'text/plain')?.body.data;\n // Skip the message if content or sender is missing.\n // Skip the message if it's the same as the last message.\n // TODO(wittjosiah): This comparison should be done via foreignId probably.\n if (!content || !sender || created === last?.created) {\n continue;\n }\n const subject = messageDetails.payload.headers.find((h: any) => h.name === 'Subject')?.value;\n const object = create(MessageType, {\n id: EntityId.random(),\n created,\n sender,\n blocks: [\n {\n _tag: 'text',\n text: Buffer.from(content, 'base64').toString('utf-8'),\n },\n ],\n properties: {\n subject,\n threadId: message.threadId,\n },\n });\n // TODO(wittjosiah): Set foreignId in object meta.\n yield* Ref.update(newMessages, (n: any) => [object, ...n]);\n }\n } while (yield* Ref.get(nextPage));\n\n const queueMessages = yield* Ref.get(newMessages);\n if (queueMessages.length > 0) {\n yield* Function.pipe(\n queueMessages,\n Stream.fromIterable,\n Stream.grouped(10),\n Stream.flatMap((batch: any) =>\n Effect.tryPromise({\n try: () => space.queues.insertIntoQueue(mailbox.queue.uri, Chunk.toReadonlyArray(batch)),\n catch: (e: any) => e,\n }),\n ),\n Stream.runDrain,\n );\n }\n\n return { newMessages: queueMessages.length };\n }).pipe(Effect.provide(FetchHttpClient.layer)),\n});\n\nconst getUrl = (userId: string, messageId?: string, params?: Record<string, any>) => {\n const api = new URL(\n [`https://gmail.googleapis.com/gmail/v1/users/${userId}/messages`, messageId].filter(Boolean).join('/'),\n );\n Object.entries(params ?? {})\n .filter(([_, value]) => value != null)\n .forEach(([key, value]) => api.searchParams.set(key, value));\n return api.toString();\n};\n\n/**\n * Parses an email string in the format \"Name <email@example.com>\" into separate name and email components.\n */\nconst parseFromHeader = (value: string): { name?: string; email: string } | undefined => {\n const EMAIL_REGEX = /^([^<]+?)\\s*<([^>]+@[^>]+)>$/;\n const removeOuterQuotes = (str: string) => str.replace(/^['\"]|['\"]$/g, '');\n const match = value.match(EMAIL_REGEX);\n if (match) {\n const [, name, email] = match;\n return {\n name: removeOuterQuotes(name.trim()),\n email: email.trim(),\n };\n }\n};\n\n//\n// Schemas\n// TODO(wittjosiah): These schemas should be imported from @dxos/schema.\n//\n\nconst ActorRole = S.Literal('user', 'assistant');\ntype ActorRole = S.Schema.Type<typeof ActorRole>;\n\nconst ActorSchema = S.Struct({\n identityKey: S.optional(S.String),\n email: S.optional(S.String),\n name: S.optional(S.String),\n role: S.optional(ActorRole),\n});\n\nconst Base = S.Struct({\n pending: S.optional(S.Boolean),\n});\ntype Base = S.Schema.Type<typeof Base>;\nconst Text = S.TaggedStruct('text', {\n mimeType: S.optional(S.String),\n text: S.String,\n ...Base.fields,\n}).pipe(S.mutable);\ninterface Text extends S.Schema.Type<typeof Text> {}\n\nconst MessageType = S.Struct({\n id: EntityId,\n created: S.String.annotations({\n description: 'ISO date string when the message was sent.',\n }),\n sender: ActorSchema.annotations({\n description: 'Identity of the message sender.',\n }),\n blocks: S.Array(Text).annotations({\n description: 'Contents of the message.',\n }),\n properties: S.optional(\n S.mutable(\n S.Record({ key: S.String, value: S.Any }).annotations({\n description: 'Custom properties for specific message types (e.g. attention context, email subject, etc.).',\n }),\n ),\n ),\n}).pipe(\n EchoObject({\n typename: 'org.dxos.type.message',\n version: '0.1.0',\n }),\n);\ntype MessageType = S.Schema.Type<typeof MessageType>;\n";
|
|
27
27
|
|
|
28
28
|
// raw-loader:/__w/dxos/dxos/packages/plugins/plugin-script/src/templates/ping.ts
|
|
29
29
|
var ping_default = "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\nimport * as Schema from 'effect/Schema';\n\nimport { Operation } from '@dxos/compute';\nimport { DXN } from '@dxos/keys';\n\nconst Ping = Operation.make({\n meta: {\n key: DXN.make('org.dxos.script.ping'),\n name: 'Ping',\n },\n input: Schema.Any,\n output: Schema.Any,\n});\n\nexport default Ping.pipe(\n Operation.withHandler(\n Effect.fn(function* (data) {\n return data;\n }),\n ),\n);\n";
|
|
@@ -93,4 +93,4 @@ export {
|
|
|
93
93
|
data_generator_default,
|
|
94
94
|
templates
|
|
95
95
|
};
|
|
96
|
-
//# sourceMappingURL=chunk-
|
|
96
|
+
//# sourceMappingURL=chunk-WAGQ77UQ.mjs.map
|