@dxos/plugin-script 0.12.0-next-73daef452f1464b62efdbca75fb0067c1066f264 → 0.13.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 +93 -17
- package/README.md +1 -1
- package/dist/lib/Notebook.mjs +4 -5
- package/dist/lib/Notebook.mjs.map +1 -1
- package/dist/lib/ScriptCapabilities.mjs.map +1 -1
- package/dist/lib/ScriptOperation.mjs +1 -1
- package/dist/lib/ScriptOperation.mjs.map +1 -1
- package/dist/lib/ScriptOperationHandlerSet.mjs.map +1 -1
- package/dist/lib/ScriptSkill.mjs +1 -1
- package/dist/lib/ScriptSkill.mjs.map +1 -1
- package/dist/lib/capabilities.browser.mjs +51 -0
- package/dist/lib/capabilities.browser.mjs.map +1 -0
- package/dist/lib/capabilities.mjs +17 -7
- package/dist/lib/capabilities.mjs.map +1 -1
- package/dist/lib/capabilities.node.mjs +16 -4
- package/dist/lib/capabilities.node.mjs.map +1 -1
- package/dist/lib/capabilities.tauri.mjs +51 -0
- package/dist/lib/capabilities.tauri.mjs.map +1 -0
- package/dist/lib/capabilities.workerd.mjs +1 -1
- package/dist/lib/capabilities.workerd.mjs.map +1 -1
- package/dist/lib/chunk-DeploymentDialog.mjs +12 -9
- package/dist/lib/chunk-DeploymentDialog.mjs.map +1 -1
- package/dist/lib/chunk-NotebookArticle.mjs +37 -36
- package/dist/lib/chunk-NotebookArticle.mjs.map +1 -1
- package/dist/lib/chunk-PLUGIN.mjs +6 -0
- package/dist/lib/chunk-PLUGIN.mjs.map +1 -0
- package/dist/lib/chunk-ScriptArticle.mjs +14 -15
- package/dist/lib/chunk-ScriptArticle.mjs.map +1 -1
- package/dist/lib/chunk-ScriptProperties.mjs +91 -94
- package/dist/lib/chunk-ScriptProperties.mjs.map +1 -1
- package/dist/lib/chunk-ScriptSettings.mjs +11 -8
- package/dist/lib/chunk-ScriptSettings.mjs.map +1 -1
- package/dist/lib/chunk-TestContainer.mjs +5 -5
- package/dist/lib/chunk-TestContainer.mjs.map +1 -1
- package/dist/lib/chunk-app-graph-builder.mjs +2 -0
- package/dist/lib/chunk-app-graph-builder.mjs.map +1 -1
- package/dist/lib/chunk-compiler.mjs +87 -4
- package/dist/lib/chunk-compiler.mjs.map +1 -1
- package/dist/lib/chunk-create-object.mjs +1 -1
- package/dist/lib/chunk-create-script.mjs.map +1 -1
- package/dist/lib/chunk-create.mjs +4 -4
- package/dist/lib/chunk-create.mjs.map +1 -1
- package/dist/lib/chunk-definitions.mjs +246 -0
- package/dist/lib/chunk-definitions.mjs.map +1 -0
- package/dist/lib/chunk-delete.mjs +2 -2
- package/dist/lib/chunk-delete.mjs.map +1 -1
- package/dist/lib/chunk-deploy.mjs +16 -12
- package/dist/lib/chunk-deploy.mjs.map +1 -1
- package/dist/lib/chunk-errors.mjs +8 -0
- package/dist/lib/chunk-errors.mjs.map +1 -0
- package/dist/lib/chunk-functions.mjs +66 -246
- package/dist/lib/chunk-functions.mjs.map +1 -1
- package/dist/lib/chunk-inspect-invocations.mjs +3 -3
- package/dist/lib/chunk-inspect-invocations.mjs.map +1 -1
- package/dist/lib/chunk-install-function.mjs +11 -11
- package/dist/lib/chunk-install-function.mjs.map +1 -1
- package/dist/lib/chunk-invoke.mjs +6 -6
- package/dist/lib/chunk-invoke.mjs.map +1 -1
- package/dist/lib/chunk-operation-handler.mjs +16 -2
- package/dist/lib/chunk-operation-handler.mjs.map +1 -1
- package/dist/lib/chunk-query-deployed-functions.mjs +5 -6
- package/dist/lib/chunk-query-deployed-functions.mjs.map +1 -1
- package/dist/lib/chunk-react-surface.mjs +14 -10
- package/dist/lib/chunk-react-surface.mjs.map +1 -1
- package/dist/lib/chunk-read.mjs +4 -3
- package/dist/lib/chunk-read.mjs.map +1 -1
- package/dist/lib/chunk-settings.mjs +2 -2
- package/dist/lib/chunk-settings.mjs.map +1 -1
- package/dist/lib/chunk-skill-definition.mjs +1 -1
- package/dist/lib/chunk-templates.mjs +3 -3
- package/dist/lib/chunk-update.mjs +4 -3
- package/dist/lib/chunk-update.mjs.map +1 -1
- package/dist/lib/components.mjs +114 -123
- package/dist/lib/components.mjs.map +1 -1
- package/dist/lib/containers.mjs.map +1 -1
- package/dist/lib/hooks.mjs +96 -16
- package/dist/lib/hooks.mjs.map +1 -1
- package/dist/lib/index.mjs +5 -3
- package/dist/lib/meta.mjs.map +1 -1
- package/dist/lib/ns/ScriptFunction.mjs +12 -0
- package/dist/lib/ns/ScriptFunction.mjs.map +1 -0
- package/dist/lib/ns/Templates.mjs +11 -0
- package/dist/lib/ns/Templates.mjs.map +1 -0
- package/dist/lib/testing.mjs +1 -1
- package/dist/lib/translations.mjs +2 -1
- package/dist/lib/translations.mjs.map +1 -1
- package/dist/types/src/ScriptFunction.d.ts +2 -0
- package/dist/types/src/ScriptFunction.d.ts.map +1 -0
- package/dist/types/src/Templates.d.ts +2 -0
- package/dist/types/src/Templates.d.ts.map +1 -0
- package/dist/types/src/capabilities/ScriptSurfaces.d.ts.map +1 -1
- package/dist/types/src/capabilities/compiler.d.ts +2 -1
- package/dist/types/src/capabilities/compiler.d.ts.map +1 -1
- package/dist/types/src/capabilities/errors.d.ts +33 -0
- package/dist/types/src/capabilities/errors.d.ts.map +1 -0
- package/dist/types/src/capabilities/gen/browser.d.ts +12 -0
- package/dist/types/src/capabilities/gen/browser.d.ts.map +1 -0
- package/dist/types/src/capabilities/gen/node.d.ts.map +1 -1
- package/dist/types/src/capabilities/gen/tauri.d.ts +12 -0
- package/dist/types/src/capabilities/gen/tauri.d.ts.map +1 -0
- package/dist/types/src/capabilities/gen/workerd.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/compiler/index.d.ts +1 -1
- package/dist/types/src/compiler/index.d.ts.map +1 -1
- package/dist/types/src/components/NotebookStack/NotebookCell.d.ts +3 -3
- package/dist/types/src/components/NotebookStack/NotebookCell.d.ts.map +1 -1
- package/dist/types/src/components/NotebookStack/NotebookMenu.d.ts.map +1 -1
- package/dist/types/src/components/NotebookStack/NotebookStack.d.ts +4 -4
- package/dist/types/src/components/NotebookStack/NotebookStack.d.ts.map +1 -1
- package/dist/types/src/components/NotebookStack/NotebookStack.stories.d.ts +10 -0
- package/dist/types/src/components/NotebookStack/NotebookStack.stories.d.ts.map +1 -1
- package/dist/types/src/components/NotebookStack/index.d.ts +2 -2
- package/dist/types/src/components/NotebookStack/index.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts +2 -2
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.stories.d.ts +10 -0
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.stories.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/index.d.ts +1 -1
- package/dist/types/src/components/ScriptToolbar/index.d.ts.map +1 -1
- package/dist/types/src/components/TestPanel/TestPanel.d.ts +2 -2
- package/dist/types/src/components/TestPanel/TestPanel.d.ts.map +1 -1
- package/dist/types/src/components/TestPanel/index.d.ts +1 -1
- package/dist/types/src/components/TestPanel/index.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts +2 -2
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor/index.d.ts +1 -1
- package/dist/types/src/components/TypescriptEditor/index.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +4 -5
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/containers/DeploymentDialog/DeploymentDialog.d.ts +1 -1
- package/dist/types/src/containers/DeploymentDialog/DeploymentDialog.d.ts.map +1 -1
- package/dist/types/src/containers/DeploymentDialog/DeploymentDialog.stories.d.ts +10 -0
- package/dist/types/src/containers/DeploymentDialog/DeploymentDialog.stories.d.ts.map +1 -1
- package/dist/types/src/containers/DeploymentDialog/index.d.ts +1 -1
- package/dist/types/src/containers/DeploymentDialog/index.d.ts.map +1 -1
- package/dist/types/src/containers/NotebookArticle/NotebookArticle.d.ts +1 -1
- package/dist/types/src/containers/NotebookArticle/NotebookArticle.d.ts.map +1 -1
- package/dist/types/src/containers/NotebookArticle/NotebookArticle.stories.d.ts +1 -1
- package/dist/types/src/containers/NotebookArticle/NotebookArticle.stories.d.ts.map +1 -1
- package/dist/types/src/containers/NotebookArticle/index.d.ts +1 -1
- package/dist/types/src/containers/NotebookArticle/index.d.ts.map +1 -1
- package/dist/types/src/containers/ScriptArticle/ScriptArticle.d.ts +1 -1
- package/dist/types/src/containers/ScriptArticle/ScriptArticle.d.ts.map +1 -1
- package/dist/types/src/containers/ScriptArticle/ScriptArticle.stories.d.ts +10 -0
- package/dist/types/src/containers/ScriptArticle/ScriptArticle.stories.d.ts.map +1 -1
- package/dist/types/src/containers/ScriptArticle/index.d.ts +1 -1
- package/dist/types/src/containers/ScriptArticle/index.d.ts.map +1 -1
- package/dist/types/src/containers/ScriptProperties/FunctionBinding.d.ts.map +1 -1
- package/dist/types/src/containers/ScriptProperties/FunctionPublishing.d.ts.map +1 -1
- package/dist/types/src/containers/ScriptProperties/ScriptProperties.d.ts +1 -1
- package/dist/types/src/containers/ScriptProperties/ScriptProperties.d.ts.map +1 -1
- package/dist/types/src/containers/ScriptProperties/ScriptProperties.stories.d.ts +10 -0
- package/dist/types/src/containers/ScriptProperties/ScriptProperties.stories.d.ts.map +1 -1
- package/dist/types/src/containers/ScriptProperties/SkillEditor.d.ts.map +1 -1
- package/dist/types/src/containers/ScriptProperties/index.d.ts +1 -1
- package/dist/types/src/containers/ScriptProperties/index.d.ts.map +1 -1
- package/dist/types/src/containers/ScriptSettings/ScriptSettings.d.ts +2 -2
- package/dist/types/src/containers/ScriptSettings/ScriptSettings.d.ts.map +1 -1
- package/dist/types/src/containers/ScriptSettings/ScriptSettings.stories.d.ts +11 -1
- package/dist/types/src/containers/ScriptSettings/ScriptSettings.stories.d.ts.map +1 -1
- package/dist/types/src/containers/ScriptSettings/index.d.ts +1 -1
- package/dist/types/src/containers/ScriptSettings/index.d.ts.map +1 -1
- package/dist/types/src/containers/TestContainer/index.d.ts +1 -1
- package/dist/types/src/containers/TestContainer/index.d.ts.map +1 -1
- package/dist/types/src/containers/index.d.ts.map +1 -1
- package/dist/types/src/hooks/deploy.d.ts +3 -3
- package/dist/types/src/hooks/deploy.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +6 -6
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useCompiler.d.ts +1 -1
- package/dist/types/src/hooks/useCompiler.d.ts.map +1 -1
- package/dist/types/src/hooks/useCreateAndDeployScriptTemplates.d.ts +1 -1
- package/dist/types/src/hooks/useCreateAndDeployScriptTemplates.d.ts.map +1 -1
- package/dist/types/src/hooks/useToolbarState.d.ts +2 -2
- package/dist/types/src/hooks/useToolbarState.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +5 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/notebook/compute-graph.d.ts +3 -3
- package/dist/types/src/notebook/compute-graph.d.ts.map +1 -1
- package/dist/types/src/notebook/index.d.ts +1 -1
- package/dist/types/src/notebook/index.d.ts.map +1 -1
- package/dist/types/src/operations/ScriptOperationHandlerSet.d.ts.map +1 -1
- package/dist/types/src/operations/index.d.ts +1 -1
- package/dist/types/src/operations/index.d.ts.map +1 -1
- package/dist/types/src/skills/ScriptSkill.d.ts.map +1 -1
- package/dist/types/src/skills/functions/definitions.d.ts +8 -6
- package/dist/types/src/skills/functions/definitions.d.ts.map +1 -1
- package/dist/types/src/skills/functions/deploy.d.ts +4 -2
- package/dist/types/src/skills/functions/deploy.d.ts.map +1 -1
- package/dist/types/src/skills/functions/errors.d.ts +33 -0
- package/dist/types/src/skills/functions/errors.d.ts.map +1 -0
- package/dist/types/src/skills/functions/index.d.ts +1 -1
- package/dist/types/src/skills/functions/index.d.ts.map +1 -1
- package/dist/types/src/skills/functions/install-function.d.ts +3 -2
- package/dist/types/src/skills/functions/install-function.d.ts.map +1 -1
- package/dist/types/src/skills/functions/invoke.d.ts +2 -2
- package/dist/types/src/skills/functions/invoke.d.ts.map +1 -1
- package/dist/types/src/skills/functions/query-deployed-functions.d.ts +2 -2
- package/dist/types/src/skills/functions/query-deployed-functions.d.ts.map +1 -1
- package/dist/types/src/skills/index.d.ts +1 -1
- package/dist/types/src/skills/index.d.ts.map +1 -1
- package/dist/types/src/templates/forex-effect.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +2 -2
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +10 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Notebook.d.ts.map +1 -1
- package/dist/types/src/types/ScriptCapabilities.d.ts +3 -3
- package/dist/types/src/types/ScriptCapabilities.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +5 -5
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/util/deploy.d.ts +6 -3
- package/dist/types/src/util/deploy.d.ts.map +1 -1
- package/dist/types/src/util/functions.d.ts +1 -1
- package/dist/types/src/util/functions.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +2 -2
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +106 -96
- package/src/ScriptFunction.ts +7 -0
- package/src/Templates.ts +7 -0
- package/src/capabilities/ScriptSurfaces.tsx +19 -10
- package/src/capabilities/app-graph-builder.ts +2 -0
- package/src/capabilities/compiler.ts +6 -5
- package/src/capabilities/errors.ts +8 -0
- package/src/capabilities/gen/browser.ts +62 -0
- package/src/capabilities/gen/node.ts +10 -10
- package/src/capabilities/gen/tauri.ts +62 -0
- package/src/capabilities/gen/workerd.ts +4 -4
- package/src/capabilities/index.ts +11 -11
- package/src/capabilities/operation-handler.ts +1 -1
- package/src/capabilities/react-surface.ts +4 -4
- package/src/capabilities/settings.ts +2 -2
- package/src/compiler/compiler.browser.test.ts +1 -1
- package/src/compiler/index.ts +1 -1
- package/src/components/NotebookStack/NotebookCell.tsx +35 -29
- package/src/components/NotebookStack/NotebookMenu.tsx +27 -26
- package/src/components/NotebookStack/NotebookStack.stories.tsx +3 -3
- package/src/components/NotebookStack/NotebookStack.tsx +20 -17
- package/src/components/NotebookStack/index.ts +2 -2
- package/src/components/ScriptToolbar/ScriptToolbar.stories.tsx +5 -5
- package/src/components/ScriptToolbar/ScriptToolbar.tsx +14 -15
- package/src/components/ScriptToolbar/index.ts +1 -1
- package/src/components/TestPanel/TestPanel.tsx +29 -23
- package/src/components/TestPanel/index.ts +1 -1
- package/src/components/TypescriptEditor/TypescriptEditor.stories.tsx +10 -8
- package/src/components/TypescriptEditor/TypescriptEditor.tsx +11 -7
- package/src/components/TypescriptEditor/index.ts +1 -1
- package/src/components/index.ts +4 -5
- package/src/containers/DeploymentDialog/DeploymentDialog.stories.tsx +5 -7
- package/src/containers/DeploymentDialog/DeploymentDialog.tsx +18 -15
- package/src/containers/DeploymentDialog/index.ts +1 -1
- package/src/containers/NotebookArticle/NotebookArticle.stories.tsx +6 -6
- package/src/containers/NotebookArticle/NotebookArticle.tsx +25 -21
- package/src/containers/NotebookArticle/index.ts +1 -1
- package/src/containers/ScriptArticle/ScriptArticle.stories.tsx +3 -3
- package/src/containers/ScriptArticle/ScriptArticle.tsx +13 -11
- package/src/containers/ScriptArticle/index.ts +1 -1
- package/src/containers/ScriptProperties/FunctionBinding.tsx +18 -18
- package/src/containers/ScriptProperties/FunctionPublishing.tsx +22 -22
- package/src/containers/ScriptProperties/ScriptProperties.stories.tsx +3 -3
- package/src/containers/ScriptProperties/ScriptProperties.tsx +10 -10
- package/src/containers/ScriptProperties/SkillEditor.tsx +16 -14
- package/src/containers/ScriptProperties/index.ts +1 -1
- package/src/containers/ScriptSettings/ScriptSettings.stories.tsx +1 -1
- package/src/containers/ScriptSettings/ScriptSettings.tsx +16 -11
- package/src/containers/ScriptSettings/index.ts +1 -1
- package/src/containers/TestContainer/TestContainer.tsx +4 -4
- package/src/containers/TestContainer/index.ts +1 -1
- package/src/containers/index.ts +6 -6
- package/src/e2e/ai.test.ts +1 -1
- package/src/hooks/deploy.ts +12 -5
- package/src/hooks/index.ts +6 -6
- package/src/hooks/template.ts +1 -1
- package/src/hooks/useCompiler.ts +8 -7
- package/src/hooks/useCreateAndDeployScriptTemplates.ts +10 -5
- package/src/hooks/useToolbarState.ts +4 -4
- package/src/index.ts +5 -3
- package/src/meta.ts +1 -1
- package/src/notebook/compute-graph.test.ts +2 -2
- package/src/notebook/compute-graph.ts +4 -4
- package/src/notebook/index.ts +1 -1
- package/src/notebook/vfs-parser.test.ts +1 -1
- package/src/notebook/vfs-parser.ts +1 -1
- package/src/operations/ScriptOperationHandlerSet.ts +3 -1
- package/src/operations/create-script.ts +1 -1
- package/src/operations/index.ts +1 -1
- package/src/plugin.test.ts +2 -2
- package/src/skills/ScriptSkill.ts +3 -1
- package/src/skills/functions/create.ts +4 -4
- package/src/skills/functions/definitions.ts +8 -6
- package/src/skills/functions/delete.ts +1 -1
- package/src/skills/functions/deploy.ts +13 -9
- package/src/skills/functions/errors.ts +8 -0
- package/src/skills/functions/index.ts +11 -11
- package/src/skills/functions/inspect-invocations.ts +1 -1
- package/src/skills/functions/install-function.ts +11 -14
- package/src/skills/functions/invoke.ts +5 -5
- package/src/skills/functions/query-deployed-functions.ts +3 -4
- package/src/skills/functions/read.ts +3 -2
- package/src/skills/functions/update.ts +3 -2
- package/src/skills/index.ts +1 -1
- package/src/templates/anthropic.ts +2 -2
- package/src/templates/commentary.ts +1 -1
- package/src/templates/forex-effect.ts +7 -4
- package/src/testing/index.ts +2 -2
- package/src/translations.ts +4 -2
- package/src/types/Notebook.ts +6 -4
- package/src/types/ScriptCapabilities.ts +3 -3
- package/src/types/ScriptOperation.ts +1 -1
- package/src/types/index.ts +5 -5
- package/src/util/deploy.ts +10 -7
- package/src/util/functions.ts +24 -15
- package/src/util/index.ts +2 -2
- package/dist/lib/chunk-compiler2.mjs +0 -76
- package/dist/lib/chunk-compiler2.mjs.map +0 -1
- package/dist/lib/chunk-util.mjs +0 -146
- package/dist/lib/chunk-util.mjs.map +0 -1
- package/dist/types/src/components/QueryEditor/QueryEditor.d.ts +0 -5
- package/dist/types/src/components/QueryEditor/QueryEditor.d.ts.map +0 -1
- package/dist/types/src/components/QueryEditor/QueryEditor.stories.d.ts +0 -14
- package/dist/types/src/components/QueryEditor/QueryEditor.stories.d.ts.map +0 -1
- package/dist/types/src/components/QueryEditor/index.d.ts +0 -2
- package/dist/types/src/components/QueryEditor/index.d.ts.map +0 -1
- package/src/components/QueryEditor/QueryEditor.stories.tsx +0 -91
- package/src/components/QueryEditor/QueryEditor.tsx +0 -50
- package/src/components/QueryEditor/index.ts +0 -5
|
@@ -1,8 +1,21 @@
|
|
|
1
|
+
import * as Capability from "@dxos/app-framework/Capability";
|
|
2
|
+
import { ScriptCapabilities } from "#types";
|
|
3
|
+
import { log } from "@dxos/log";
|
|
4
|
+
import { trim } from "@dxos/util";
|
|
5
|
+
import * as Schema from "effect/Schema";
|
|
1
6
|
import { invariant } from "@dxos/invariant";
|
|
7
|
+
import { initializeBundler } from "@dxos/edge-compute/bundler";
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
|
+
import * as ts$1 from "@typescript/typescript6";
|
|
2
10
|
import ts from "@typescript/typescript6";
|
|
11
|
+
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
12
|
+
import * as HttpClient from "effect/http/HttpClient";
|
|
13
|
+
import * as Schedule from "effect/Schedule";
|
|
14
|
+
import wasmUrl from "esbuild-wasm/esbuild.wasm?url";
|
|
3
15
|
import { createDefaultMapFromCDN, createSystem, createVirtualTypeScriptEnvironment } from "@typescript/vfs";
|
|
16
|
+
import { BaseError } from "@dxos/errors";
|
|
4
17
|
//#region src/compiler/compiler.ts
|
|
5
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-script/src/compiler/compiler.ts";
|
|
18
|
+
var __dxlog_file$1 = "/__w/dxos/dxos/packages/plugins/plugin-script/src/compiler/compiler.ts";
|
|
6
19
|
var GLOBALS = "globals.d.ts";
|
|
7
20
|
/** TS version hosted on playgroundcdn.typescriptlang.org used to fetch lib .d.ts files.
|
|
8
21
|
* Pinned to 5.6.3 because 5.7+ removed lib.es2022.sharedmemory.d.ts from the CDN.
|
|
@@ -33,7 +46,7 @@ var Compiler = class {
|
|
|
33
46
|
get environment() {
|
|
34
47
|
invariant(this._env, "Compiler environment not initialized.", {
|
|
35
48
|
"~LogMeta": "~LogMeta",
|
|
36
|
-
F: __dxlog_file,
|
|
49
|
+
F: __dxlog_file$1,
|
|
37
50
|
L: 57,
|
|
38
51
|
S: this,
|
|
39
52
|
A: ["this._env", "'Compiler environment not initialized.'"]
|
|
@@ -43,7 +56,7 @@ var Compiler = class {
|
|
|
43
56
|
setFile(fileName, content) {
|
|
44
57
|
invariant(this._fsMap, "File system map not initialized.", {
|
|
45
58
|
"~LogMeta": "~LogMeta",
|
|
46
|
-
F: __dxlog_file,
|
|
59
|
+
F: __dxlog_file$1,
|
|
47
60
|
L: 62,
|
|
48
61
|
S: this,
|
|
49
62
|
A: ["this._fsMap", "'File system map not initialized.'"]
|
|
@@ -55,6 +68,76 @@ var Compiler = class {
|
|
|
55
68
|
}
|
|
56
69
|
};
|
|
57
70
|
//#endregion
|
|
58
|
-
|
|
71
|
+
//#region src/capabilities/errors.ts
|
|
72
|
+
/** The script compiler's WASM bundler or its TypeScript front end failed to start. */
|
|
73
|
+
var CompilerError = class extends BaseError.extend("CompilerError", "Compiler failed to initialize.") {};
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/capabilities/compiler.ts
|
|
76
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-script/src/capabilities/compiler.ts";
|
|
77
|
+
var SCRIPT_PACKAGES_BUCKET = "https://pub-5745ae82e450484aa28f75fc6a175935.r2.dev/dev/";
|
|
78
|
+
var DECLARATION_EXTS = [".d.ts", ".d.mts"];
|
|
79
|
+
var compiler_default = Capability.makeModule(() => Effect.gen(function* () {
|
|
80
|
+
yield* Effect.tryPromise({
|
|
81
|
+
try: () => initializeBundler({ wasmUrl }),
|
|
82
|
+
catch: (error) => new CompilerError({
|
|
83
|
+
message: "Failed to initialize bundler.",
|
|
84
|
+
cause: error
|
|
85
|
+
})
|
|
86
|
+
});
|
|
87
|
+
const runtimeModules = yield* fetchRuntimeModules().pipe(Effect.provide(FetchHttpClient.layer));
|
|
88
|
+
const compiler = new Compiler({
|
|
89
|
+
target: ts$1.ScriptTarget.ES2022,
|
|
90
|
+
lib: ["lib.es2022.d.ts", "lib.dom.d.ts"],
|
|
91
|
+
skipLibCheck: true,
|
|
92
|
+
moduleResolution: ts$1.ModuleResolutionKind.Bundler,
|
|
93
|
+
allowImportingTsExtensions: true,
|
|
94
|
+
noEmit: true,
|
|
95
|
+
strict: true,
|
|
96
|
+
esModuleInterop: true,
|
|
97
|
+
paths: Object.fromEntries(runtimeModules.map((mod) => [mod.moduleName, [`./src/${mod.filename}`]]))
|
|
98
|
+
});
|
|
99
|
+
yield* Effect.tryPromise({
|
|
100
|
+
try: () => compiler.initialize(trim`
|
|
101
|
+
declare module 'https://*';
|
|
102
|
+
${""}
|
|
103
|
+
`),
|
|
104
|
+
catch: (error) => new CompilerError({
|
|
105
|
+
message: "Failed to initialize compiler.",
|
|
106
|
+
cause: error
|
|
107
|
+
})
|
|
108
|
+
});
|
|
109
|
+
return Capability.contribute(ScriptCapabilities.Compiler, compiler);
|
|
110
|
+
}));
|
|
111
|
+
var fetchRuntimeModules = Effect.fnUntraced(function* () {
|
|
112
|
+
const manifest = yield* HttpClient.get(new URL("manifest.json", SCRIPT_PACKAGES_BUCKET)).pipe(Effect.flatMap((_) => _.json), Effect.flatMap(Schema.decodeUnknownEffect(Schema.Struct({ files: Schema.Array(Schema.Struct({ key: Schema.String })) }))), Effect.map((manifest) => ({
|
|
113
|
+
...manifest,
|
|
114
|
+
files: manifest.files.map((f) => f.key)
|
|
115
|
+
})));
|
|
116
|
+
const declarationFiles = manifest.files.filter((file) => DECLARATION_EXTS.some((ext) => file.endsWith(ext)));
|
|
117
|
+
let fetched = 0;
|
|
118
|
+
const modules = yield* Effect.forEach(declarationFiles, Effect.fnUntraced(function* (filename) {
|
|
119
|
+
const content = yield* (yield* HttpClient.get(new URL(filename, SCRIPT_PACKAGES_BUCKET)).pipe(Effect.retry(Schedule.exponential(1e3).pipe(Schedule.upTo({ times: 3 }))))).text;
|
|
120
|
+
const moduleName = filename.replace(/\.d\.(ts|mts)$/, "");
|
|
121
|
+
fetched++;
|
|
122
|
+
return {
|
|
123
|
+
moduleName,
|
|
124
|
+
filename,
|
|
125
|
+
content
|
|
126
|
+
};
|
|
127
|
+
}, Effect.retry(Schedule.exponential(1e3).pipe(Schedule.upTo({ times: 3 })))), { concurrency: 20 });
|
|
128
|
+
log.info("runtime modules", {
|
|
129
|
+
manifest: manifest.files.length,
|
|
130
|
+
files: declarationFiles.length,
|
|
131
|
+
fetched
|
|
132
|
+
}, {
|
|
133
|
+
"~LogMeta": "~LogMeta",
|
|
134
|
+
F: __dxlog_file,
|
|
135
|
+
L: 110,
|
|
136
|
+
S: this
|
|
137
|
+
});
|
|
138
|
+
return modules;
|
|
139
|
+
});
|
|
140
|
+
//#endregion
|
|
141
|
+
export { compiler_default as default };
|
|
59
142
|
|
|
60
143
|
//# sourceMappingURL=chunk-compiler.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk-compiler.mjs","names":[],"sources":["../../src/compiler/compiler.ts"],"sourcesContent":["//\n// Copyright 2024 DXOS.org\n//\n\nimport ts from '@typescript/typescript6';\nimport {\n type VirtualTypeScriptEnvironment,\n createDefaultMapFromCDN,\n createSystem,\n createVirtualTypeScriptEnvironment,\n} from '@typescript/vfs';\n\nimport { invariant } from '@dxos/invariant';\n\nconst GLOBALS = 'globals.d.ts';\n\n/** TS version hosted on playgroundcdn.typescriptlang.org used to fetch lib .d.ts files.\n * Pinned to 5.6.3 because 5.7+ removed lib.es2022.sharedmemory.d.ts from the CDN.\n * The remaining 404s (lib.core.d.ts, lib.core.es6/7.d.ts, lib.es7.d.ts) are phantom\n * entries in @typescript/vfs's hardcoded file list and are harmlessly caught.\n */\nconst CDN_TS_VERSION = '5.6.3';\n\nconst defaultOptions: ts.CompilerOptions = {\n lib: ['DOM', 'es2022'],\n target: ts.ScriptTarget.ES2022,\n // Override `@typescript/vfs`'s default of `NodeJs` (== deprecated `node10`).\n // TypeScript 6 throws on that as a `getCompilerOptionsDiagnostics()` error,\n // which surfaces as an unhandled rejection inside the storybook task.\n moduleResolution: ts.ModuleResolutionKind.Bundler,\n};\n\nexport class Compiler {\n private _env: VirtualTypeScriptEnvironment | undefined;\n private _fsMap: Map<string, string> | undefined;\n\n constructor(private readonly _options: ts.CompilerOptions = defaultOptions) {}\n\n async initialize(globals?: string): Promise<void> {\n if (this._env) {\n return;\n }\n\n // TODO(wittjosiah): Figure out how to get workers working in plugin packages.\n // https://github.com/val-town/codemirror-ts?tab=readme-ov-file#setup-worker\n this._fsMap = await createDefaultMapFromCDN(this._options, CDN_TS_VERSION, true, ts);\n if (globals) {\n this._fsMap.set(GLOBALS, globals);\n }\n\n const rootFiles = globals ? [GLOBALS] : [];\n const system = createSystem(this._fsMap);\n this._env = createVirtualTypeScriptEnvironment(system, rootFiles, ts, this._options);\n }\n\n get environment() {\n invariant(this._env, 'Compiler environment not initialized.');\n return this._env;\n }\n\n setFile(fileName: string, content: string): void {\n invariant(this._fsMap, 'File system map not initialized.');\n this.environment.createFile(fileName, content);\n }\n\n compile(fileName: string): ts.EmitOutput {\n return this.environment.languageService.getEmitOutput(fileName);\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"chunk-compiler.mjs","names":[],"sources":["../../src/compiler/compiler.ts","../../src/capabilities/errors.ts","../../src/capabilities/compiler.ts"],"sourcesContent":["//\n// Copyright 2024 DXOS.org\n//\n\nimport ts from '@typescript/typescript6';\nimport {\n type VirtualTypeScriptEnvironment,\n createDefaultMapFromCDN,\n createSystem,\n createVirtualTypeScriptEnvironment,\n} from '@typescript/vfs';\n\nimport { invariant } from '@dxos/invariant';\n\nconst GLOBALS = 'globals.d.ts';\n\n/** TS version hosted on playgroundcdn.typescriptlang.org used to fetch lib .d.ts files.\n * Pinned to 5.6.3 because 5.7+ removed lib.es2022.sharedmemory.d.ts from the CDN.\n * The remaining 404s (lib.core.d.ts, lib.core.es6/7.d.ts, lib.es7.d.ts) are phantom\n * entries in @typescript/vfs's hardcoded file list and are harmlessly caught.\n */\nconst CDN_TS_VERSION = '5.6.3';\n\nconst defaultOptions: ts.CompilerOptions = {\n lib: ['DOM', 'es2022'],\n target: ts.ScriptTarget.ES2022,\n // Override `@typescript/vfs`'s default of `NodeJs` (== deprecated `node10`).\n // TypeScript 6 throws on that as a `getCompilerOptionsDiagnostics()` error,\n // which surfaces as an unhandled rejection inside the storybook task.\n moduleResolution: ts.ModuleResolutionKind.Bundler,\n};\n\nexport class Compiler {\n private _env: VirtualTypeScriptEnvironment | undefined;\n private _fsMap: Map<string, string> | undefined;\n\n constructor(private readonly _options: ts.CompilerOptions = defaultOptions) {}\n\n async initialize(globals?: string): Promise<void> {\n if (this._env) {\n return;\n }\n\n // TODO(wittjosiah): Figure out how to get workers working in plugin packages.\n // https://github.com/val-town/codemirror-ts?tab=readme-ov-file#setup-worker\n this._fsMap = await createDefaultMapFromCDN(this._options, CDN_TS_VERSION, true, ts);\n if (globals) {\n this._fsMap.set(GLOBALS, globals);\n }\n\n const rootFiles = globals ? [GLOBALS] : [];\n const system = createSystem(this._fsMap);\n this._env = createVirtualTypeScriptEnvironment(system, rootFiles, ts, this._options);\n }\n\n get environment() {\n invariant(this._env, 'Compiler environment not initialized.');\n return this._env;\n }\n\n setFile(fileName: string, content: string): void {\n invariant(this._fsMap, 'File system map not initialized.');\n this.environment.createFile(fileName, content);\n }\n\n compile(fileName: string): ts.EmitOutput {\n return this.environment.languageService.getEmitOutput(fileName);\n }\n}\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport { BaseError } from '@dxos/errors';\n\n/** The script compiler's WASM bundler or its TypeScript front end failed to start. */\nexport class CompilerError extends BaseError.extend('CompilerError', 'Compiler failed to initialize.') {}\n","//\n// Copyright 2025 DXOS.org\n//\n\nimport * as ts from '@typescript/typescript6';\nimport * as Effect from 'effect/Effect';\nimport * as FetchHttpClient from 'effect/http/FetchHttpClient';\nimport * as HttpClient from 'effect/http/HttpClient';\nimport * as Schedule from 'effect/Schedule';\nimport * as Schema from 'effect/Schema';\nimport wasmUrl from 'esbuild-wasm/esbuild.wasm?url';\n\nimport * as Capability from '@dxos/app-framework/Capability';\nimport { initializeBundler } from '@dxos/edge-compute/bundler';\nimport { log } from '@dxos/log';\nimport { trim } from '@dxos/util';\n\nimport { ScriptCapabilities } from '#types';\n\nimport { Compiler } from '../compiler/index.ts';\nimport { CompilerError } from './errors.ts';\n\n// TODO(burdon): Document.\nconst SCRIPT_PACKAGES_BUCKET = 'https://pub-5745ae82e450484aa28f75fc6a175935.r2.dev/dev/';\nconst DECLARATION_EXTS = ['.d.ts', '.d.mts'];\nconst NO_TYPES = true; // Types temopararly disabled due to compiler erorrs.\n\nexport default Capability.makeModule(() =>\n Effect.gen(function* () {\n yield* Effect.tryPromise({\n try: () => initializeBundler({ wasmUrl }),\n catch: (error) => new CompilerError({ message: 'Failed to initialize bundler.', cause: error }),\n });\n\n const runtimeModules = yield* fetchRuntimeModules().pipe(Effect.provide(FetchHttpClient.layer));\n\n const compiler = new Compiler({\n target: ts.ScriptTarget.ES2022,\n lib: ['lib.es2022.d.ts', 'lib.dom.d.ts'],\n skipLibCheck: true,\n moduleResolution: ts.ModuleResolutionKind.Bundler,\n allowImportingTsExtensions: true,\n noEmit: true,\n strict: true,\n esModuleInterop: true,\n paths: Object.fromEntries(runtimeModules.map((mod: any) => [mod.moduleName, [`./src/${mod.filename}`]])),\n });\n\n yield* Effect.tryPromise({\n try: () =>\n compiler.initialize(trim`\n declare module 'https://*';\n ${NO_TYPES ? '' : 'declare module \"*\";'}\n `),\n catch: (error) => new CompilerError({ message: 'Failed to initialize compiler.', cause: error }),\n });\n if (!NO_TYPES) {\n for (const mod of runtimeModules) {\n compiler.setFile(`/src/${mod.filename}`, mod.content);\n }\n }\n\n return Capability.contribute(ScriptCapabilities.Compiler, compiler);\n }),\n);\n\nconst fetchRuntimeModules = Effect.fnUntraced(function* () {\n // { key, size, contentType }\n const manifest = yield* HttpClient.get(new URL('manifest.json', SCRIPT_PACKAGES_BUCKET)).pipe(\n Effect.flatMap((_) => _.json),\n Effect.flatMap(\n Schema.decodeUnknownEffect(\n Schema.Struct({\n files: Schema.Array(\n Schema.Struct({\n key: Schema.String,\n }),\n ),\n }),\n ),\n ),\n Effect.map((manifest) => ({ ...manifest, files: manifest.files.map((f) => f.key) })),\n );\n\n const declarationFiles = manifest.files.filter((file) => DECLARATION_EXTS.some((ext) => file.endsWith(ext)));\n\n let fetched = 0;\n const modules = yield* Effect.forEach(\n declarationFiles,\n Effect.fnUntraced(\n function* (filename) {\n const response = yield* HttpClient.get(new URL(filename, SCRIPT_PACKAGES_BUCKET)).pipe(\n Effect.retry(Schedule.exponential(1_000).pipe(Schedule.upTo({ times: 3 }))),\n );\n const content = yield* response.text;\n const moduleName = filename.replace(/\\.d\\.(ts|mts)$/, '');\n fetched++;\n\n return {\n moduleName,\n filename,\n content,\n };\n },\n Effect.retry(Schedule.exponential(1_000).pipe(Schedule.upTo({ times: 3 }))),\n ),\n { concurrency: 20 },\n );\n\n log.info('runtime modules', { manifest: manifest.files.length, files: declarationFiles.length, fetched });\n return modules;\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AAcA,IAAM,UAAU;;;;;;AAOhB,IAAM,iBAAiB;AAEv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AAW,UAAU;EAInB,MAAM,UAAU,QAAO,OAHC,WAAW,IAAI,IAAI,IAAI,UAAU,sBAAsB,CAAC,CAAC,CAAC,KAChF,OAAO,MAAM,SAAS,YAAY,GAAK,CAAC,CAAC,KAAK,SAAS,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAC5E,EAAA,CACgC;EAChC,MAAM,aAAa,SAAS,QAAQ,kBAAkB,EAAE;EACxD;EAEA,OAAO;GACL;GACA;GACA;EACF;CACF,GACA,OAAO,MAAM,SAAS,YAAY,GAAK,CAAC,CAAC,KAAK,SAAS,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAC5E,GACA,EAAE,aAAa,GAAG,CACpB;CAEA,IAAI,KAAK,mBAAmB;EAAE,UAAU,SAAS,MAAM;EAAQ,OAAO,iBAAiB;EAAQ;CAAQ,GAAA;EAAA,YAAA;EAAA,GAAA;EAAA,GAAA;EAAA,GAAA;CAAA,CAAC;CACxG,OAAO;AACT,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Capability from "@dxos/app-framework/Capability";
|
|
2
2
|
import { Notebook, ScriptOperation } from "#types";
|
|
3
|
-
import * as Operation from "@dxos/compute/Operation";
|
|
4
3
|
import { Type } from "@dxos/echo";
|
|
4
|
+
import * as Operation from "@dxos/compute/Operation";
|
|
5
5
|
import * as Script from "@dxos/compute/Script";
|
|
6
6
|
import * as SpaceOperation from "@dxos/plugin-space/SpaceOperation";
|
|
7
7
|
import * as Effect from "effect/Effect";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk-create-script.mjs","names":[],"sources":["../../src/operations/create-script.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Octokit } from '@octokit/core';\nimport * as Effect from 'effect/Effect';\n\nimport * as Operation from '@dxos/compute/Operation';\nimport * as Script from '@dxos/compute/Script';\n\nimport { ScriptOperation } from '#types';\n\nimport { templates } from '../templates';\n\nconst handler: Operation.WithHandler<typeof ScriptOperation.CreateScript> = ScriptOperation.CreateScript.pipe(\n Operation.withHandler(\n Effect.fnUntraced(function* ({ name, gistUrl, initialTemplateId }) {\n let source = templates[0].source;\n let scriptName = name;\n\n const gistId = gistUrl?.split('/').at(-1);\n if (gistId) {\n const octokit = new Octokit();\n const response = yield* Effect.promise(() =>\n octokit.request('GET /gists/{gist_id}', {\n gist_id: gistId,\n }),\n );\n const gistContent = Object.values(response.data.files ?? {})[0]?.content;\n if (gistContent) {\n source = gistContent;\n }\n }\n\n if (initialTemplateId) {\n const template = templates.find((template) => template.id === initialTemplateId);\n if (template) {\n source = template.source;\n scriptName = scriptName || template.name;\n }\n }\n\n return { object: Script.make({ name: scriptName, source }) };\n }),\n ),\n);\n\nexport default handler;\n"],"mappings":";;;;;;;AAcA,IAAM,UAAsE,gBAAgB,aAAa,KACvG,UAAU,YACR,OAAO,WAAW,WAAW,EAAE,MAAM,SAAS,qBAAqB;CACjE,IAAI,SAAS,UAAU,EAAE,CAAC;CAC1B,IAAI,aAAa;CAEjB,MAAM,SAAS,SAAS,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE;CACxC,IAAI,QAAQ;EACV,MAAM,UAAU,IAAI,QAAQ;EAC5B,MAAM,WAAW,OAAO,OAAO,cAC7B,QAAQ,QAAQ,wBAAwB,EACtC,SAAS,OACX,CAAC,CACH;EACA,MAAM,cAAc,OAAO,OAAO,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE;EACjE,IAAI,aACF,SAAS;CAEb;CAEA,IAAI,mBAAmB;EACrB,MAAM,WAAW,UAAU,MAAM,aAAa,SAAS,OAAO,iBAAiB;EAC/E,IAAI,UAAU;GACZ,SAAS,SAAS;GAClB,aAAa,cAAc,SAAS;EACtC;CACF;CAEA,OAAO,EAAE,QAAQ,OAAO,KAAK;EAAE,MAAM;EAAY;CAAO,CAAC,EAAE;AAC7D,CAAC,CACH,CACF"}
|
|
1
|
+
{"version":3,"file":"chunk-create-script.mjs","names":[],"sources":["../../src/operations/create-script.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Octokit } from '@octokit/core';\nimport * as Effect from 'effect/Effect';\n\nimport * as Operation from '@dxos/compute/Operation';\nimport * as Script from '@dxos/compute/Script';\n\nimport { ScriptOperation } from '#types';\n\nimport { templates } from '../templates/index.ts';\n\nconst handler: Operation.WithHandler<typeof ScriptOperation.CreateScript> = ScriptOperation.CreateScript.pipe(\n Operation.withHandler(\n Effect.fnUntraced(function* ({ name, gistUrl, initialTemplateId }) {\n let source = templates[0].source;\n let scriptName = name;\n\n const gistId = gistUrl?.split('/').at(-1);\n if (gistId) {\n const octokit = new Octokit();\n const response = yield* Effect.promise(() =>\n octokit.request('GET /gists/{gist_id}', {\n gist_id: gistId,\n }),\n );\n const gistContent = Object.values(response.data.files ?? {})[0]?.content;\n if (gistContent) {\n source = gistContent;\n }\n }\n\n if (initialTemplateId) {\n const template = templates.find((template) => template.id === initialTemplateId);\n if (template) {\n source = template.source;\n scriptName = scriptName || template.name;\n }\n }\n\n return { object: Script.make({ name: scriptName, source }) };\n }),\n ),\n);\n\nexport default handler;\n"],"mappings":";;;;;;;AAcA,IAAM,UAAsE,gBAAgB,aAAa,KACvG,UAAU,YACR,OAAO,WAAW,WAAW,EAAE,MAAM,SAAS,qBAAqB;CACjE,IAAI,SAAS,UAAU,EAAE,CAAC;CAC1B,IAAI,aAAa;CAEjB,MAAM,SAAS,SAAS,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE;CACxC,IAAI,QAAQ;EACV,MAAM,UAAU,IAAI,QAAQ;EAC5B,MAAM,WAAW,OAAO,OAAO,cAC7B,QAAQ,QAAQ,wBAAwB,EACtC,SAAS,OACX,CAAC,CACH;EACA,MAAM,cAAc,OAAO,OAAO,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE;EACjE,IAAI,aACF,SAAS;CAEb;CAEA,IAAI,mBAAmB;EACrB,MAAM,WAAW,UAAU,MAAM,aAAa,SAAS,OAAO,iBAAiB;EAC/E,IAAI,UAAU;GACZ,SAAS,SAAS;GAClB,aAAa,cAAc,SAAS;EACtC;CACF;CAEA,OAAO,EAAE,QAAQ,OAAO,KAAK;EAAE,MAAM;EAAY;CAAO,CAAC,EAAE;AAC7D,CAAC,CACH,CACF"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as Operation from "@dxos/compute/Operation";
|
|
1
|
+
import { t as Create } from "./chunk-definitions.mjs";
|
|
3
2
|
import { Database, Obj, Ref } from "@dxos/echo";
|
|
3
|
+
import * as Operation from "@dxos/compute/Operation";
|
|
4
4
|
import * as Script from "@dxos/compute/Script";
|
|
5
5
|
import * as Effect from "effect/Effect";
|
|
6
|
-
import * as
|
|
6
|
+
import * as DefaultParent from "@dxos/app-toolkit/DefaultParent";
|
|
7
7
|
//#region src/skills/functions/create.ts
|
|
8
8
|
var create_default = Create.pipe(Operation.withHandler(Effect.fn(function* ({ name, source, templateId }) {
|
|
9
9
|
let scriptSource = source ?? "";
|
|
@@ -22,7 +22,7 @@ var create_default = Create.pipe(Operation.withHandler(Effect.fn(function* ({ na
|
|
|
22
22
|
name,
|
|
23
23
|
source: Ref.make(script)
|
|
24
24
|
});
|
|
25
|
-
yield*
|
|
25
|
+
yield* DefaultParent.add({ object: fn });
|
|
26
26
|
return { function: Obj.getURI(fn) };
|
|
27
27
|
})));
|
|
28
28
|
var findTemplate = (templateId) => Effect.promise(async () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk-create.mjs","names":[],"sources":["../../src/skills/functions/create.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\n\nimport * as
|
|
1
|
+
{"version":3,"file":"chunk-create.mjs","names":[],"sources":["../../src/skills/functions/create.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\n\nimport * as DefaultParent from '@dxos/app-toolkit/DefaultParent';\nimport * as Operation from '@dxos/compute/Operation';\nimport * as Script from '@dxos/compute/Script';\nimport { Database, Obj, Ref } from '@dxos/echo';\n\nimport { Create } from './definitions.ts';\n\nexport default Create.pipe(\n Operation.withHandler(\n Effect.fn(function* ({ name, source, templateId }) {\n let scriptSource = source ?? '';\n\n if (templateId) {\n const template = yield* findTemplate(templateId);\n if (template) {\n scriptSource = template.source;\n }\n }\n\n const script = Script.make({ name, source: scriptSource });\n const { db } = yield* Database.Service;\n db.add(script);\n\n const fn = Obj.make(Operation.PersistentOperation, {\n [Obj.Meta]: { version: '0.0.0' },\n name,\n source: Ref.make(script),\n });\n yield* DefaultParent.add({ object: fn });\n\n return {\n function: Obj.getURI(fn),\n };\n }),\n ),\n);\n\nconst findTemplate = (templateId: string) =>\n Effect.promise(async () => {\n const { templates } = await import('../../templates/index.ts');\n return templates.find((template) => template.id === templateId);\n });\n"],"mappings":";;;;;;;AAaA,IAAA,iBAAe,OAAO,KACpB,UAAU,YACR,OAAO,GAAG,WAAW,EAAE,MAAM,QAAQ,cAAc;CACjD,IAAI,eAAe,UAAU;CAE7B,IAAI,YAAY;EACd,MAAM,WAAW,OAAO,aAAa,UAAU;EAC/C,IAAI,UACF,eAAe,SAAS;CAE5B;CAEA,MAAM,SAAS,OAAO,KAAK;EAAE;EAAM,QAAQ;CAAa,CAAC;CACzD,MAAM,EAAE,OAAO,OAAO,SAAS;CAC/B,GAAG,IAAI,MAAM;CAEb,MAAM,KAAK,IAAI,KAAK,UAAU,qBAAqB;GAChD,IAAI,OAAO,EAAE,SAAS,QAAQ;EAC/B;EACA,QAAQ,IAAI,KAAK,MAAM;CACzB,CAAC;CACD,OAAO,cAAc,IAAI,EAAE,QAAQ,GAAG,CAAC;CAEvC,OAAO,EACL,UAAU,IAAI,OAAO,EAAE,EACzB;AACF,CAAC,CACH,CACF;AAEA,IAAM,gBAAgB,eACpB,OAAO,QAAQ,YAAY;CACzB,MAAM,EAAE,cAAc,MAAM,OAAO;CACnC,OAAO,UAAU,MAAM,aAAa,SAAS,OAAO,UAAU;AAChE,CAAC"}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { DXN, Database, Hypergraph, Ref } from "@dxos/echo";
|
|
2
|
+
import { trim } from "@dxos/util";
|
|
3
|
+
import * as Operation from "@dxos/compute/Operation";
|
|
4
|
+
import * as Schema from "effect/Schema";
|
|
5
|
+
import { ConfigService } from "@dxos/config";
|
|
6
|
+
import { EdgeHttpClientService } from "@dxos/edge-client";
|
|
7
|
+
import { Identity } from "@dxos/halo";
|
|
8
|
+
//#region src/skills/functions/definitions.ts
|
|
9
|
+
var FunctionRef = Ref.Ref(Operation.PersistentOperation).annotate({ description: "The ID of the function." });
|
|
10
|
+
var FunctionId = Schema.String.annotate({ description: "The ID of the function. Can be passed as the function parameter to other operations." });
|
|
11
|
+
var FUNCTION_FORMAT = trim`
|
|
12
|
+
IMPORTANT: Every function MUST follow this exact pattern — define an Operation, then export default the handler:
|
|
13
|
+
|
|
14
|
+
\`\`\`typescript
|
|
15
|
+
import * as Effect from 'effect/Effect';
|
|
16
|
+
import * as Schema from 'effect/Schema';
|
|
17
|
+
|
|
18
|
+
import { Operation } from '@dxos/compute';
|
|
19
|
+
|
|
20
|
+
const MyFunction = Operation.make({
|
|
21
|
+
meta: {
|
|
22
|
+
key: DXN.make('com.example.operation.example.myFunction'),
|
|
23
|
+
name: 'My Function',
|
|
24
|
+
},
|
|
25
|
+
input: Schema.Struct({
|
|
26
|
+
city: Schema.String.annotate({ description: 'City name' }),
|
|
27
|
+
}),
|
|
28
|
+
output: Schema.Any,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export default MyFunction.pipe(
|
|
32
|
+
Operation.withHandler(
|
|
33
|
+
Effect.fn(function* ({ city }) {
|
|
34
|
+
const res = yield* Effect.promise(() =>
|
|
35
|
+
fetch(\`https://wttr.in/\${city}?format=j1\`)
|
|
36
|
+
);
|
|
37
|
+
const data = yield* Effect.promise(() => res.json());
|
|
38
|
+
return data;
|
|
39
|
+
}),
|
|
40
|
+
),
|
|
41
|
+
);
|
|
42
|
+
\`\`\`
|
|
43
|
+
|
|
44
|
+
Key rules:
|
|
45
|
+
- The file MUST have a single \`export default\` of Operation.pipe(Operation.withHandler(...)).
|
|
46
|
+
- Use \`Effect.fn(function* (...) { ... })\` for the handler body.
|
|
47
|
+
- Wrap async calls with \`yield* Effect.promise(() => ...)\`.
|
|
48
|
+
- Do NOT use top-level await; do NOT export named functions; do NOT use module.exports.
|
|
49
|
+
`;
|
|
50
|
+
var AVAILABLE_PACKAGES = trim`
|
|
51
|
+
Scripts run in an Edge runtime (Cloudflare Workers) with the following pre-bundled packages:
|
|
52
|
+
|
|
53
|
+
DXOS SDK:
|
|
54
|
+
- \`@dxos/echo\` — Reactive local-first database: query, filter, and mutate ECHO objects in spaces.
|
|
55
|
+
- \`@dxos/functions\` — Edge function framework: triggers, queues, and function definitions.
|
|
56
|
+
- \`@dxos/ai\` — AI/LLM integration via AiService (access models like Claude, GPT).
|
|
57
|
+
- \`@dxos/schema\` — Schema utilities and built-in DXOS types.
|
|
58
|
+
- \`@dxos/types\` — DXOS type definitions.
|
|
59
|
+
- \`@dxos/operation\` — Define and handle typed operations with input/output schemas.
|
|
60
|
+
- \`@dxos/util\` — General utility functions.
|
|
61
|
+
- \`@dxos/log\` — Structured logging.
|
|
62
|
+
|
|
63
|
+
Effect-TS (functional programming toolkit):
|
|
64
|
+
- \`effect\` — Core effect system with sub-modules: Effect, Schema, Stream, Schedule, Array, Record, Option, Either, Match, etc.
|
|
65
|
+
- \`@effect/platform\` — HTTP client (\`HttpClient\`), platform abstractions for making typed API requests.
|
|
66
|
+
|
|
67
|
+
Data format parsing & querying:
|
|
68
|
+
- \`jsonata\` — Powerful query and transformation expressions for JSON data (filter, sort, group, aggregate, reshape).
|
|
69
|
+
- \`yaml\` — Parse and stringify YAML documents.
|
|
70
|
+
- \`fast-xml-parser\` — Fast XML parser and builder; convert between XML and JSON.
|
|
71
|
+
- \`papaparse\` — CSV parsing and serialization; stream large files, auto-detect delimiters.
|
|
72
|
+
|
|
73
|
+
Text & markup processing:
|
|
74
|
+
- \`turndown\` — HTML to Markdown converter (useful for feeding web content to LLMs).
|
|
75
|
+
|
|
76
|
+
HTML/DOM parsing:
|
|
77
|
+
- \`linkedom\` — Lightweight DOM parser for worker environments; parse and query HTML documents.
|
|
78
|
+
|
|
79
|
+
Data processing & utilities:
|
|
80
|
+
- \`date-fns\` — Comprehensive date utility library: parsing, formatting, comparison, arithmetic, time zones.
|
|
81
|
+
|
|
82
|
+
Other:
|
|
83
|
+
- \`@automerge/automerge\` — CRDT library for conflict-free collaborative data structures.
|
|
84
|
+
- \`chess.js\` — Chess game logic, move generation, and validation.
|
|
85
|
+
`;
|
|
86
|
+
var Create = Operation.make({
|
|
87
|
+
meta: {
|
|
88
|
+
key: DXN.make("org.dxos.operation.script.createFunction"),
|
|
89
|
+
name: "Create",
|
|
90
|
+
description: `Creates a new function with TypeScript source code and adds it to the space. ${FUNCTION_FORMAT} ${AVAILABLE_PACKAGES}`,
|
|
91
|
+
icon: "ph--code--regular"
|
|
92
|
+
},
|
|
93
|
+
input: Schema.Struct({
|
|
94
|
+
name: Schema.String.annotate({ description: "Name of the function." }),
|
|
95
|
+
source: Schema.optional(Schema.String).annotate({ description: "TypeScript source code for the function." }),
|
|
96
|
+
templateId: Schema.optional(Schema.String).annotate({ description: "ID of a template to use as the initial source." })
|
|
97
|
+
}),
|
|
98
|
+
output: Schema.Struct({ function: FunctionId }),
|
|
99
|
+
services: [Database.Service]
|
|
100
|
+
});
|
|
101
|
+
var Read = Operation.make({
|
|
102
|
+
meta: {
|
|
103
|
+
key: DXN.make("org.dxos.operation.script.read"),
|
|
104
|
+
name: "Read",
|
|
105
|
+
description: "Reads the source code and metadata of a function.",
|
|
106
|
+
icon: "ph--file-text--regular"
|
|
107
|
+
},
|
|
108
|
+
input: Schema.Struct({ function: FunctionRef }),
|
|
109
|
+
output: Schema.Struct({
|
|
110
|
+
name: Schema.optional(Schema.String),
|
|
111
|
+
source: Schema.String,
|
|
112
|
+
description: Schema.optional(Schema.String)
|
|
113
|
+
}),
|
|
114
|
+
services: [Database.Service]
|
|
115
|
+
});
|
|
116
|
+
var Edit = Schema.Struct({
|
|
117
|
+
oldString: Schema.String.annotate({ description: "The text to find in the source." }),
|
|
118
|
+
newString: Schema.String.annotate({ description: "The text to replace it with." }),
|
|
119
|
+
replaceAll: Schema.optional(Schema.Boolean).annotate({ description: "If true, replaces all occurrences. Defaults to false (first occurrence only)." })
|
|
120
|
+
});
|
|
121
|
+
var Update = Operation.make({
|
|
122
|
+
meta: {
|
|
123
|
+
key: DXN.make("org.dxos.operation.script.update"),
|
|
124
|
+
name: "Update",
|
|
125
|
+
description: `Updates the source code or metadata of a function. ${FUNCTION_FORMAT}`,
|
|
126
|
+
icon: "ph--pencil--regular"
|
|
127
|
+
},
|
|
128
|
+
input: Schema.Struct({
|
|
129
|
+
function: FunctionRef,
|
|
130
|
+
name: Schema.optional(Schema.String).annotate({ description: "New name for the function." }),
|
|
131
|
+
description: Schema.optional(Schema.String).annotate({ description: "New description for the function." }),
|
|
132
|
+
edits: Schema.optional(Schema.Array(Edit)).annotate({ description: "Edits to apply to the source. Each edit finds oldString and replaces it with newString." })
|
|
133
|
+
}),
|
|
134
|
+
output: Schema.Struct({ function: FunctionId }),
|
|
135
|
+
services: [Database.Service]
|
|
136
|
+
});
|
|
137
|
+
var Delete = Operation.make({
|
|
138
|
+
meta: {
|
|
139
|
+
key: DXN.make("org.dxos.operation.script.delete"),
|
|
140
|
+
name: "Delete",
|
|
141
|
+
description: "Deletes a function and its source from the space.",
|
|
142
|
+
icon: "ph--trash--regular"
|
|
143
|
+
},
|
|
144
|
+
input: Schema.Struct({ function: FunctionRef }),
|
|
145
|
+
output: Schema.Void,
|
|
146
|
+
services: [Database.Service]
|
|
147
|
+
});
|
|
148
|
+
var Deploy = Operation.make({
|
|
149
|
+
meta: {
|
|
150
|
+
key: DXN.make("org.dxos.operation.script.deploy"),
|
|
151
|
+
name: "Deploy",
|
|
152
|
+
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.`,
|
|
153
|
+
icon: "ph--rocket-launch--regular"
|
|
154
|
+
},
|
|
155
|
+
input: Schema.Struct({ function: FunctionRef }),
|
|
156
|
+
output: Schema.Struct({
|
|
157
|
+
function: FunctionId,
|
|
158
|
+
functionUrl: Schema.optional(Schema.String).annotate({ description: "The URL of the deployed function." })
|
|
159
|
+
}),
|
|
160
|
+
services: [
|
|
161
|
+
Database.Service,
|
|
162
|
+
EdgeHttpClientService,
|
|
163
|
+
Identity.Service,
|
|
164
|
+
ConfigService
|
|
165
|
+
]
|
|
166
|
+
});
|
|
167
|
+
var Invoke = Operation.make({
|
|
168
|
+
meta: {
|
|
169
|
+
key: DXN.make("org.dxos.operation.script.invoke"),
|
|
170
|
+
name: "Invoke",
|
|
171
|
+
description: "Invokes a deployed Edge function with the given payload.",
|
|
172
|
+
icon: "ph--play--regular"
|
|
173
|
+
},
|
|
174
|
+
input: Schema.Struct({
|
|
175
|
+
function: FunctionRef,
|
|
176
|
+
payload: Schema.optional(Schema.Unknown).annotate({ description: "The input payload to pass to the function." })
|
|
177
|
+
}),
|
|
178
|
+
output: Schema.Struct({ response: Schema.Unknown.annotate({ description: "The response from the function." }) }),
|
|
179
|
+
services: [Database.Service, EdgeHttpClientService]
|
|
180
|
+
});
|
|
181
|
+
var InvocationSpanSchema = Schema.Struct({
|
|
182
|
+
id: Schema.String.annotate({ description: "The invocation ID." }),
|
|
183
|
+
timestamp: Schema.Number.annotate({ description: "Start time of the invocation (epoch ms)." }),
|
|
184
|
+
duration: Schema.Number.annotate({ description: "Duration in milliseconds." }),
|
|
185
|
+
outcome: Schema.String.annotate({ description: "Invocation outcome: success, failure, or pending." }),
|
|
186
|
+
input: Schema.ObjectKeyword.annotate({ description: "The input payload passed to the function." }),
|
|
187
|
+
error: Schema.optional(Schema.ObjectKeyword).annotate({ description: "Error details if the invocation failed." })
|
|
188
|
+
});
|
|
189
|
+
var InspectInvocations = Operation.make({
|
|
190
|
+
meta: {
|
|
191
|
+
key: DXN.make("org.dxos.operation.script.inspectInvocations"),
|
|
192
|
+
name: "InspectInvocations",
|
|
193
|
+
description: "Queries the invocation trace feed for a function, returning its invocation history.",
|
|
194
|
+
icon: "ph--magnifying-glass--regular"
|
|
195
|
+
},
|
|
196
|
+
input: Schema.Struct({
|
|
197
|
+
function: FunctionRef,
|
|
198
|
+
limit: Schema.optional(Schema.Number).annotate({ description: "Maximum number of invocations to return. Defaults to 20." })
|
|
199
|
+
}),
|
|
200
|
+
output: Schema.Struct({
|
|
201
|
+
invocations: Schema.Array(InvocationSpanSchema).annotate({ description: "List of invocation spans, most recent first." }),
|
|
202
|
+
total: Schema.Number.annotate({ description: "Total number of invocations found." })
|
|
203
|
+
}),
|
|
204
|
+
services: [Database.Service]
|
|
205
|
+
});
|
|
206
|
+
var DeployedFunctionSchema = Schema.Struct({
|
|
207
|
+
key: Schema.optional(Schema.String).annotate({ description: "Unique key identifying the function. Pass to InstallFunction to install it." }),
|
|
208
|
+
name: Schema.String.annotate({ description: "Display name of the function." }),
|
|
209
|
+
version: Schema.String.annotate({ description: "Semantic version of the deployed function." }),
|
|
210
|
+
description: Schema.optional(Schema.String).annotate({ description: "Description of what the function does." }),
|
|
211
|
+
updated: Schema.optional(Schema.String).annotate({ description: "ISO timestamp of the last deployment." })
|
|
212
|
+
});
|
|
213
|
+
var QueryDeployedFunctions = Operation.make({
|
|
214
|
+
meta: {
|
|
215
|
+
key: DXN.make("org.dxos.operation.script.queryDeployed"),
|
|
216
|
+
name: "QueryDeployedFunctions",
|
|
217
|
+
description: "Lists all functions deployed to the EDGE runtime. Use InstallFunction to add one to the space.",
|
|
218
|
+
icon: "ph--list--regular"
|
|
219
|
+
},
|
|
220
|
+
input: Schema.Void,
|
|
221
|
+
output: Schema.Struct({ functions: Schema.Array(DeployedFunctionSchema).annotate({ description: "List of deployed functions." }) }),
|
|
222
|
+
services: [EdgeHttpClientService]
|
|
223
|
+
});
|
|
224
|
+
var InstallFunction = Operation.make({
|
|
225
|
+
meta: {
|
|
226
|
+
key: DXN.make("org.dxos.operation.script.install"),
|
|
227
|
+
name: "InstallFunction",
|
|
228
|
+
description: "Installs a deployed EDGE function into the current space by key. The returned function ID can be passed directly to Invoke.",
|
|
229
|
+
icon: "ph--download--regular"
|
|
230
|
+
},
|
|
231
|
+
input: Schema.Struct({ key: Schema.String.annotate({ description: "The unique key of the deployed function to install (from QueryDeployedFunctions)." }) }),
|
|
232
|
+
output: Schema.Struct({
|
|
233
|
+
function: FunctionId,
|
|
234
|
+
name: Schema.String.annotate({ description: "Name of the installed function." }),
|
|
235
|
+
version: Schema.String.annotate({ description: "Version of the installed function." })
|
|
236
|
+
}),
|
|
237
|
+
services: [
|
|
238
|
+
Database.Service,
|
|
239
|
+
Hypergraph.Service,
|
|
240
|
+
EdgeHttpClientService
|
|
241
|
+
]
|
|
242
|
+
});
|
|
243
|
+
//#endregion
|
|
244
|
+
export { InstallFunction as a, Read as c, InspectInvocations as i, Update as l, Delete as n, Invoke as o, Deploy as r, QueryDeployedFunctions as s, Create as t };
|
|
245
|
+
|
|
246
|
+
//# sourceMappingURL=chunk-definitions.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk-definitions.mjs","names":[],"sources":["../../src/skills/functions/definitions.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport * as Operation from '@dxos/compute/Operation';\nimport { ConfigService } from '@dxos/config';\nimport { Database, DXN, Hypergraph, Ref } from '@dxos/echo';\nimport { EdgeHttpClientService } from '@dxos/edge-client';\nimport { Identity } from '@dxos/halo';\nimport { trim } from '@dxos/util';\n\nconst FunctionRef = Ref.Ref(Operation.PersistentOperation).annotate({\n description: 'The ID of the function.',\n});\n\nconst FunctionId = Schema.String.annotate({\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('com.example.operation.example.myFunction'),\n name: 'My Function',\n },\n input: Schema.Struct({\n city: Schema.String.annotate({ 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.operation.script.createFunction'),\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.annotate({\n description: 'Name of the function.',\n }),\n source: Schema.optional(Schema.String).annotate({\n description: 'TypeScript source code for the function.',\n }),\n templateId: Schema.optional(Schema.String).annotate({\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.operation.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.annotate({\n description: 'The text to find in the source.',\n }),\n newString: Schema.String.annotate({\n description: 'The text to replace it with.',\n }),\n replaceAll: Schema.optional(Schema.Boolean).annotate({\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.operation.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).annotate({\n description: 'New name for the function.',\n }),\n description: Schema.optional(Schema.String).annotate({\n description: 'New description for the function.',\n }),\n edits: Schema.optional(Schema.Array(Edit)).annotate({\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.operation.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.operation.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).annotate({\n description: 'The URL of the deployed function.',\n }),\n }),\n services: [Database.Service, EdgeHttpClientService, Identity.Service, ConfigService],\n});\n\nexport const Invoke = Operation.make({\n meta: {\n key: DXN.make('org.dxos.operation.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).annotate({\n description: 'The input payload to pass to the function.',\n }),\n }),\n output: Schema.Struct({\n response: Schema.Unknown.annotate({\n description: 'The response from the function.',\n }),\n }),\n services: [Database.Service, EdgeHttpClientService],\n});\n\nconst InvocationSpanSchema = Schema.Struct({\n id: Schema.String.annotate({\n description: 'The invocation ID.',\n }),\n timestamp: Schema.Number.annotate({\n description: 'Start time of the invocation (epoch ms).',\n }),\n duration: Schema.Number.annotate({\n description: 'Duration in milliseconds.',\n }),\n outcome: Schema.String.annotate({\n description: 'Invocation outcome: success, failure, or pending.',\n }),\n input: Schema.ObjectKeyword.annotate({\n description: 'The input payload passed to the function.',\n }),\n error: Schema.optional(Schema.ObjectKeyword).annotate({\n description: 'Error details if the invocation failed.',\n }),\n});\n\nexport const InspectInvocations = Operation.make({\n meta: {\n key: DXN.make('org.dxos.operation.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).annotate({\n description: 'Maximum number of invocations to return. Defaults to 20.',\n }),\n }),\n output: Schema.Struct({\n invocations: Schema.Array(InvocationSpanSchema).annotate({\n description: 'List of invocation spans, most recent first.',\n }),\n total: Schema.Number.annotate({\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).annotate({\n description: 'Unique key identifying the function. Pass to InstallFunction to install it.',\n }),\n name: Schema.String.annotate({\n description: 'Display name of the function.',\n }),\n version: Schema.String.annotate({\n description: 'Semantic version of the deployed function.',\n }),\n description: Schema.optional(Schema.String).annotate({\n description: 'Description of what the function does.',\n }),\n updated: Schema.optional(Schema.String).annotate({\n description: 'ISO timestamp of the last deployment.',\n }),\n});\n\nexport const QueryDeployedFunctions = Operation.make({\n meta: {\n key: DXN.make('org.dxos.operation.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).annotate({\n description: 'List of deployed functions.',\n }),\n }),\n services: [EdgeHttpClientService],\n});\n\nexport const InstallFunction = Operation.make({\n meta: {\n key: DXN.make('org.dxos.operation.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.annotate({\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.annotate({\n description: 'Name of the installed function.',\n }),\n version: Schema.String.annotate({\n description: 'Version of the installed function.',\n }),\n }),\n services: [Database.Service, Hypergraph.Service, EdgeHttpClientService],\n});\n"],"mappings":";;;;;;;;AAaA,IAAM,cAAc,IAAI,IAAI,UAAU,mBAAmB,CAAC,CAAC,SAAS,EAClE,aAAa,0BACf,CAAC;AAED,IAAM,aAAa,OAAO,OAAO,SAAS,EACxC,aAAa,uFACf,CAAC;AAED,IAAM,kBAAkB,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwC5B,IAAM,qBAAqB,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqC/B,IAAa,SAAS,UAAU,KAAK;CACnC,MAAM;EACJ,KAAK,IAAI,KAAK,0CAA0C;EACxD,MAAM;EACN,aAAa,gFAAgF,gBAAgB,GAAG;EAChH,MAAM;CACR;CACA,OAAO,OAAO,OAAO;EACnB,MAAM,OAAO,OAAO,SAAS,EAC3B,aAAa,wBACf,CAAC;EACD,QAAQ,OAAO,SAAS,OAAO,MAAM,C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BAAqB;AAClC,CAAC;AAED,IAAa,kBAAkB,UAAU,KAAK;CAC5C,MAAM;EACJ,KAAK,IAAI,KAAK,mCAAmC;EACjD,MAAM;EACN,aACE;EACF,MAAM;CACR;CACA,OAAO,OAAO,OAAO,EACnB,KAAK,OAAO,OAAO,SAAS,EAC1B,aAAa,oFACf,CAAC,EACH,CAAC;CACD,QAAQ,OAAO,OAAO;EACpB,UAAU;EACV,MAAM,OAAO,OAAO,SAAS,EAC3B,aAAa,kCACf,CAAC;EACD,SAAS,OAAO,OAAO,SAAS,EAC9B,aAAa,qCACf,CAAC;CACH,CAAC;CACD,UAAU;EAAC,SAAS;EAAS,WAAW;EAAS;CAAqB;AACxE,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as Operation from "@dxos/compute/Operation";
|
|
1
|
+
import { n as Delete } from "./chunk-definitions.mjs";
|
|
3
2
|
import { Database } from "@dxos/echo";
|
|
3
|
+
import * as Operation from "@dxos/compute/Operation";
|
|
4
4
|
import * as Effect from "effect/Effect";
|
|
5
5
|
//#region src/skills/functions/delete.ts
|
|
6
6
|
var delete_default = Delete.pipe(Operation.withHandler(Effect.fn(function* ({ function: fn }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk-delete.mjs","names":[],"sources":["../../src/skills/functions/delete.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\n\nimport * as Operation from '@dxos/compute/Operation';\nimport { Database } from '@dxos/echo';\n\nimport { Delete } from './definitions';\n\nexport default Delete.pipe(\n Operation.withHandler(\n Effect.fn(function* ({ function: fn }) {\n const { db } = yield* Database.Service;\n const loaded = yield* Database.load(fn);\n if (loaded.source?.target) {\n db.remove(loaded.source.target);\n }\n db.remove(loaded);\n }),\n ),\n);\n"],"mappings":";;;;;AAWA,IAAA,iBAAe,OAAO,KACpB,UAAU,YACR,OAAO,GAAG,WAAW,EAAE,UAAU,MAAM;CACrC,MAAM,EAAE,OAAO,OAAO,SAAS;CAC/B,MAAM,SAAS,OAAO,SAAS,KAAK,EAAE;CACtC,IAAI,OAAO,QAAQ,QACjB,GAAG,OAAO,OAAO,OAAO,MAAM;CAEhC,GAAG,OAAO,MAAM;AAClB,CAAC,CACH,CACF"}
|
|
1
|
+
{"version":3,"file":"chunk-delete.mjs","names":[],"sources":["../../src/skills/functions/delete.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\n\nimport * as Operation from '@dxos/compute/Operation';\nimport { Database } from '@dxos/echo';\n\nimport { Delete } from './definitions.ts';\n\nexport default Delete.pipe(\n Operation.withHandler(\n Effect.fn(function* ({ function: fn }) {\n const { db } = yield* Database.Service;\n const loaded = yield* Database.load(fn);\n if (loaded.source?.target) {\n db.remove(loaded.source.target);\n }\n db.remove(loaded);\n }),\n ),\n);\n"],"mappings":";;;;;AAWA,IAAA,iBAAe,OAAO,KACpB,UAAU,YACR,OAAO,GAAG,WAAW,EAAE,UAAU,MAAM;CACrC,MAAM,EAAE,OAAO,OAAO,SAAS;CAC/B,MAAM,SAAS,OAAO,SAAS,KAAK,EAAE;CACtC,IAAI,OAAO,QAAQ,QACjB,GAAG,OAAO,OAAO,OAAO,MAAM;CAEhC,GAAG,OAAO,MAAM;AAClB,CAAC,CACH,CACF"}
|
|
@@ -1,34 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { ClientService } from "@dxos/client";
|
|
4
|
-
import { Database, Obj } from "@dxos/echo";
|
|
1
|
+
import { r as Deploy } from "./chunk-definitions.mjs";
|
|
2
|
+
import { t as FunctionError } from "./chunk-errors.mjs";
|
|
5
3
|
import { getUserFunctionIdInMetadata } from "@dxos/compute-runtime";
|
|
4
|
+
import { Database, Obj } from "@dxos/echo";
|
|
5
|
+
import * as Operation from "@dxos/compute/Operation";
|
|
6
|
+
import { ConfigService } from "@dxos/config";
|
|
7
|
+
import { EdgeHttpClientService } from "@dxos/edge-client";
|
|
8
|
+
import { Identity } from "@dxos/halo";
|
|
6
9
|
import { Context } from "@dxos/context";
|
|
7
10
|
import { FunctionsServiceClient, incrementSemverPatch } from "@dxos/edge-compute";
|
|
8
11
|
import { bundleFunction, initializeBundler } from "@dxos/edge-compute/bundler";
|
|
9
12
|
import { FunctionRuntimeKind } from "@dxos/protocols";
|
|
10
13
|
import * as Effect from "effect/Effect";
|
|
11
14
|
import wasmUrl from "esbuild-wasm/esbuild.wasm?url";
|
|
15
|
+
import * as Option from "effect/Option";
|
|
12
16
|
//#region src/skills/functions/deploy.ts
|
|
13
17
|
var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-script/src/skills/functions/deploy.ts";
|
|
14
18
|
var deploy_default = Deploy.pipe(Operation.withHandler(Effect.fn(function* ({ function: fn }) {
|
|
15
19
|
const loaded = yield* Database.load(fn);
|
|
16
|
-
|
|
17
|
-
if (!loaded.source) return yield* Effect.fail(/* @__PURE__ */ new Error("Function has no source script."));
|
|
20
|
+
if (!loaded.source) return yield* Effect.fail(new FunctionError({ message: "Function has no source script." }));
|
|
18
21
|
const script = yield* Database.load(loaded.source);
|
|
19
|
-
if (!Obj.getDatabase(loaded) || !script.source?.target?.content) return yield* Effect.fail(
|
|
22
|
+
if (!Obj.getDatabase(loaded) || !script.source?.target?.content) return yield* Effect.fail(new FunctionError({ message: "Script source or space not available" }));
|
|
20
23
|
yield* Effect.promise(() => initializeBundler({ wasmUrl }));
|
|
21
24
|
const buildResult = yield* Effect.promise(() => bundleFunction({ source: script.source.target.content }));
|
|
22
25
|
if ("error" in buildResult) return yield* Effect.fail(buildResult.error ?? /* @__PURE__ */ new Error("Bundle creation failed"));
|
|
23
26
|
const existingFunctionId = getUserFunctionIdInMetadata(Obj.getMeta(loaded));
|
|
24
27
|
const currentVersion = Obj.getMeta(loaded).version;
|
|
25
|
-
const identity =
|
|
26
|
-
if (!identity) return yield* Effect.fail(
|
|
27
|
-
const functionsService = FunctionsServiceClient
|
|
28
|
+
const identity = Option.getOrUndefined(yield* Identity.getSnapshot);
|
|
29
|
+
if (!identity) return yield* Effect.fail(new FunctionError({ message: "Identity not available." }));
|
|
30
|
+
const functionsService = new FunctionsServiceClient(yield* EdgeHttpClientService);
|
|
28
31
|
const newFunction = yield* Effect.promise(() => functionsService.deploy(Context.default(void 0, {
|
|
29
32
|
"~LogMeta": "~LogMeta",
|
|
30
33
|
F: __dxlog_file,
|
|
31
|
-
L:
|
|
34
|
+
L: 54
|
|
32
35
|
}), {
|
|
33
36
|
ownerUri: identity.did,
|
|
34
37
|
version: currentVersion ? incrementSemverPatch(currentVersion) : "0.0.1",
|
|
@@ -42,9 +45,10 @@ var deploy_default = Deploy.pipe(Operation.withHandler(Effect.fn(function* ({ fu
|
|
|
42
45
|
script.changed = false;
|
|
43
46
|
});
|
|
44
47
|
const edgeFunctionId = getUserFunctionIdInMetadata(Obj.getMeta(loaded));
|
|
48
|
+
const config = yield* ConfigService;
|
|
45
49
|
return {
|
|
46
50
|
function: Obj.getURI(loaded),
|
|
47
|
-
functionUrl: edgeFunctionId ? `${
|
|
51
|
+
functionUrl: edgeFunctionId ? `${config.values.runtime?.services?.edge?.url ?? ""}/functions/${edgeFunctionId}` : void 0
|
|
48
52
|
};
|
|
49
53
|
})));
|
|
50
54
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk-deploy.mjs","names":[],"sources":["../../src/skills/functions/deploy.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\nimport wasmUrl from 'esbuild-wasm/esbuild.wasm?url';\n\nimport {
|
|
1
|
+
{"version":3,"file":"chunk-deploy.mjs","names":[],"sources":["../../src/skills/functions/deploy.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\nimport * as Option from 'effect/Option';\nimport wasmUrl from 'esbuild-wasm/esbuild.wasm?url';\n\nimport { getUserFunctionIdInMetadata } from '@dxos/compute-runtime';\nimport * as Operation from '@dxos/compute/Operation';\nimport * as Script from '@dxos/compute/Script';\nimport { ConfigService } from '@dxos/config';\nimport { Context } from '@dxos/context';\nimport { Database, Obj } from '@dxos/echo';\nimport { EdgeHttpClientService } from '@dxos/edge-client';\nimport { FunctionsServiceClient, incrementSemverPatch } from '@dxos/edge-compute';\nimport { bundleFunction, initializeBundler } from '@dxos/edge-compute/bundler';\nimport { Identity } from '@dxos/halo';\nimport { FunctionRuntimeKind } from '@dxos/protocols';\n\nimport { Deploy } from './definitions.ts';\nimport { FunctionError } from './errors.ts';\n\nexport default Deploy.pipe(\n Operation.withHandler(\n Effect.fn(function* ({ function: fn }) {\n const loaded = yield* Database.load(fn);\n if (!loaded.source) {\n return yield* Effect.fail(new FunctionError({ message: 'Function has no source script.' }));\n }\n const script = (yield* Database.load(loaded.source)) as Script.Script;\n\n const db = Obj.getDatabase(loaded);\n if (!db || !script.source?.target?.content) {\n return yield* Effect.fail(new FunctionError({ message: 'Script source or space not available' }));\n }\n\n yield* Effect.promise(() => initializeBundler({ wasmUrl }));\n const buildResult = yield* Effect.promise(() => bundleFunction({ source: script.source!.target!.content }));\n if ('error' in buildResult) {\n return yield* Effect.fail(buildResult.error ?? new Error('Bundle creation failed'));\n }\n\n const existingFunctionId = getUserFunctionIdInMetadata(Obj.getMeta(loaded));\n const currentVersion = Obj.getMeta(loaded).version;\n\n const identity = Option.getOrUndefined(yield* Identity.getSnapshot);\n if (!identity) {\n return yield* Effect.fail(new FunctionError({ message: 'Identity not available.' }));\n }\n\n const functionsService = new FunctionsServiceClient(yield* EdgeHttpClientService);\n const newFunction = yield* Effect.promise(() =>\n functionsService.deploy(Context.default(), {\n ownerUri: identity.did,\n version: currentVersion ? incrementSemverPatch(currentVersion) : '0.0.1',\n functionId: existingFunctionId,\n entryPoint: buildResult.entryPoint,\n assets: buildResult.assets,\n runtime: FunctionRuntimeKind.enums.WORKER_LOADER,\n }),\n );\n\n Operation.setFrom(loaded, newFunction);\n\n Obj.update(script, (script) => {\n script.changed = false;\n });\n\n const edgeFunctionId = getUserFunctionIdInMetadata(Obj.getMeta(loaded));\n const config = yield* ConfigService;\n return {\n function: Obj.getURI(loaded),\n functionUrl: edgeFunctionId\n ? `${config.values.runtime?.services?.edge?.url ?? ''}/functions/${edgeFunctionId}`\n : undefined,\n };\n }),\n ),\n);\n"],"mappings":";;;;;;;;;;;;;;;;;AAuBA,IAAA,iBAAe,OAAO,KACpB,UAAU,YACR,OAAO,GAAG,WAAW,EAAE,UAAU,MAAM;CACrC,MAAM,SAAS,OAAO,SAAS,KAAK,EAAE;CACtC,IAAI,CAAC,OAAO,QACV,OAAO,OAAO,OAAO,KAAK,IAAI,cAAc,EAAE,SAAS,iCAAiC,CAAC,CAAC;CAE5F,MAAM,SAAU,OAAO,SAAS,KAAK,OAAO,MAAM;CAGlD,IAAI,CADO,IAAI,YAAY,MACtB,KAAM,CAAC,OAAO,QAAQ,QAAQ,SACjC,OAAO,OAAO,OAAO,KAAK,IAAI,cAAc,EAAE,SAAS,uCAAuC,CAAC,CAAC;CAGlG,OAAO,OAAO,cAAc,kBAAkB,EAAE,QAAQ,CAAC,CAAC;CAC1D,MAAM,cAAc,OAAO,OAAO,cAAc,eAAe,EAAE,QAAQ,OAAO,OAAQ,OAAQ,QAAQ,CAAC,CAAC;CAC1G,IAAI,WAAW,aACb,OAAO,OAAO,OAAO,KAAK,YAAY,yBAAS,IAAI,MAAM,wBAAwB,CAAC;CAGpF,MAAM,qBAAqB,4BAA4B,IAAI,QAAQ,MAAM,CAAC;CAC1E,MAAM,iBAAiB,IAAI,QAAQ,MAAM,CAAC,CAAC;CAE3C,MAAM,WAAW,OAAO,eAAe,OAAO,SAAS,WAAW;CAClE,IAAI,CAAC,UACH,OAAO,OAAO,OAAO,KAAK,IAAI,cAAc,EAAE,SAAS,0BAA0B,CAAC,CAAC;CAGrF,MAAM,mBAAmB,IAAI,uBAAuB,OAAO,qBAAqB;CAChF,MAAM,cAAc,OAAO,OAAO,cAChC,iBAAiB,OAAO,QAAQ,QAAO,KAAA,GAAA;EAAA,YAAA;EAAA,GAAA;EAAA,GAAA;CAAA,CAAC,GAAG;EACzC,UAAU,SAAS;EACnB,SAAS,iBAAiB,qBAAqB,cAAc,IAAI;EACjE,YAAY;EACZ,YAAY,YAAY;EACxB,QAAQ,YAAY;EACpB,SAAS,oBAAoB,MAAM;CACrC,CAAC,CACH;CAEA,UAAU,QAAQ,QAAQ,WAAW;CAErC,IAAI,OAAO,SAAS,WAAW;EAC7B,OAAO,UAAU;CACnB,CAAC;CAED,MAAM,iBAAiB,4BAA4B,IAAI,QAAQ,MAAM,CAAC;CACtE,MAAM,SAAS,OAAO;CACtB,OAAO;EACL,UAAU,IAAI,OAAO,MAAM;EAC3B,aAAa,iBACT,GAAG,OAAO,OAAO,SAAS,UAAU,MAAM,OAAO,GAAG,aAAa,mBACjE,KAAA;CACN;AACF,CAAC,CACH,CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BaseError } from "@dxos/errors";
|
|
2
|
+
//#region src/skills/functions/errors.ts
|
|
3
|
+
/** Function operation failed. The underlying failure, where there is one, is the `cause`. */
|
|
4
|
+
var FunctionError = class extends BaseError.extend("FunctionError", "Function operation failed.") {};
|
|
5
|
+
//#endregion
|
|
6
|
+
export { FunctionError as t };
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=chunk-errors.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk-errors.mjs","names":[],"sources":["../../src/skills/functions/errors.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport { BaseError } from '@dxos/errors';\n\n/** Function operation failed. The underlying failure, where there is one, is the `cause`. */\nexport class FunctionError extends BaseError.extend('FunctionError', 'Function operation failed.') {}\n"],"mappings":";;;AAOA,IAAa,gBAAb,cAAmC,UAAU,OAAO,iBAAiB,4BAA4B,CAAC,CAAC,CAAC"}
|