@dxos/plugin-script 0.7.5-main.e9bb01b → 0.7.5-staging.2ff1350
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/{AutomationPanel-KZVZMZE6.mjs → AutomationPanel-6HFRNRWV.mjs} +3 -3
- package/dist/lib/browser/{ScriptContainer-AERJBGYK.mjs → ScriptContainer-GR7X5NSI.mjs} +97 -69
- package/dist/lib/browser/ScriptContainer-GR7X5NSI.mjs.map +7 -0
- package/dist/lib/browser/artifact-definition-NAWYXFF5.mjs +243 -0
- package/dist/lib/browser/artifact-definition-NAWYXFF5.mjs.map +7 -0
- package/dist/lib/browser/{chunk-Y4CVWFVS.mjs → chunk-5SXOHNAK.mjs} +4 -4
- package/dist/lib/browser/chunk-5SXOHNAK.mjs.map +7 -0
- package/dist/lib/browser/{chunk-ABNZIPST.mjs → chunk-6MOQ4BP3.mjs} +2 -2
- package/dist/lib/browser/{chunk-J7CBIZI2.mjs → chunk-7RUMC44X.mjs} +19 -7
- package/dist/lib/browser/{chunk-J7CBIZI2.mjs.map → chunk-7RUMC44X.mjs.map} +3 -3
- package/dist/lib/browser/{chunk-ESPJMGXJ.mjs → chunk-FVVCAWNP.mjs} +2 -2
- package/dist/lib/browser/chunk-FVVCAWNP.mjs.map +7 -0
- package/dist/lib/browser/{chunk-NFPF4OIU.mjs → chunk-N46LE7FS.mjs} +2 -2
- package/dist/lib/browser/chunk-YJAKD6E3.mjs +69 -0
- package/dist/lib/browser/chunk-YJAKD6E3.mjs.map +7 -0
- package/dist/lib/browser/{compiler-4QD7VFZX.mjs → compiler-YY2XSKHQ.mjs} +4 -6
- package/dist/lib/browser/compiler-YY2XSKHQ.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +47 -30
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/{intent-resolver-YABC4JRJ.mjs → intent-resolver-I6VDXUDH.mjs} +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-FRQIIYKG.mjs → react-surface-FGWXHB7P.mjs} +5 -5
- package/dist/lib/browser/{react-surface-FRQIIYKG.mjs.map → react-surface-FGWXHB7P.mjs.map} +2 -2
- package/dist/lib/browser/{settings-S4MGGM4D.mjs → settings-SZCDKHWO.mjs} +3 -3
- package/dist/lib/browser/types.mjs +2 -2
- package/dist/lib/node/{AutomationPanel-6QSV7ZYK.cjs → AutomationPanel-RBQ4DODN.cjs} +8 -8
- package/dist/lib/node/{ScriptContainer-DOAQ6KOE.cjs → ScriptContainer-SLARXOSU.cjs} +100 -70
- package/dist/lib/node/ScriptContainer-SLARXOSU.cjs.map +7 -0
- package/dist/lib/node/artifact-definition-7AANUS3X.cjs +262 -0
- package/dist/lib/node/artifact-definition-7AANUS3X.cjs.map +7 -0
- package/dist/lib/node/{chunk-HU2JXUXI.cjs → chunk-5UH3F7TA.cjs} +5 -5
- package/dist/lib/node/chunk-5UH3F7TA.cjs.map +7 -0
- package/dist/lib/node/chunk-7XULMIYT.cjs +77 -0
- package/dist/lib/node/chunk-7XULMIYT.cjs.map +7 -0
- package/dist/lib/node/{chunk-RZHY5LAR.cjs → chunk-ALY3N6PW.cjs} +6 -6
- package/dist/lib/node/{chunk-6M2VRFBC.cjs → chunk-DJGLGRQV.cjs} +6 -6
- package/dist/lib/node/{chunk-63C2KSD6.cjs → chunk-JITODKGN.cjs} +23 -11
- package/dist/lib/node/{chunk-63C2KSD6.cjs.map → chunk-JITODKGN.cjs.map} +3 -3
- package/dist/lib/node/{chunk-CZVVFUVL.cjs → chunk-K3ZZWVXS.cjs} +7 -7
- package/dist/lib/node/chunk-K3ZZWVXS.cjs.map +7 -0
- package/dist/lib/node/{compiler-Q3EXWKV5.cjs → compiler-UIBLKJKG.cjs} +9 -9
- package/dist/lib/node/compiler-UIBLKJKG.cjs.map +7 -0
- package/dist/lib/node/index.cjs +62 -46
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/{intent-resolver-7HI2CDGB.cjs → intent-resolver-MYATX7IR.cjs} +9 -9
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/{react-surface-IKONODLG.cjs → react-surface-2GH5HQX4.cjs} +18 -18
- package/dist/lib/node/{react-surface-IKONODLG.cjs.map → react-surface-2GH5HQX4.cjs.map} +2 -2
- package/dist/lib/node/{settings-Q5XIA4LZ.cjs → settings-SZFSMSKM.cjs} +9 -9
- package/dist/lib/node/types.cjs +4 -4
- package/dist/lib/node/types.cjs.map +1 -1
- package/dist/lib/node-esm/{AutomationPanel-EZQSGJLS.mjs → AutomationPanel-WTVVVMRH.mjs} +3 -3
- package/dist/lib/node-esm/{ScriptContainer-HE5QPPFZ.mjs → ScriptContainer-MHRJXMC4.mjs} +97 -69
- package/dist/lib/node-esm/ScriptContainer-MHRJXMC4.mjs.map +7 -0
- package/dist/lib/node-esm/artifact-definition-KBASPVMM.mjs +245 -0
- package/dist/lib/node-esm/artifact-definition-KBASPVMM.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-77LRZF2W.mjs → chunk-2AFXX34U.mjs} +4 -4
- package/dist/lib/node-esm/chunk-2AFXX34U.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-6CHX4CEL.mjs +71 -0
- package/dist/lib/node-esm/chunk-6CHX4CEL.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-3YOO5E2D.mjs → chunk-CP5LXTK5.mjs} +2 -2
- package/dist/lib/node-esm/{chunk-UWHMEJYW.mjs → chunk-IAELQPSI.mjs} +19 -7
- package/dist/lib/node-esm/{chunk-UWHMEJYW.mjs.map → chunk-IAELQPSI.mjs.map} +3 -3
- package/dist/lib/node-esm/{chunk-EOBGHKNT.mjs → chunk-P2V2Y5LV.mjs} +2 -2
- package/dist/lib/node-esm/chunk-P2V2Y5LV.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-5D2AXTAW.mjs → chunk-UNQFIERE.mjs} +2 -2
- package/dist/lib/node-esm/{compiler-KJEIPDZ6.mjs → compiler-XTXFGZJM.mjs} +4 -6
- package/dist/lib/node-esm/compiler-XTXFGZJM.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +47 -30
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/{intent-resolver-KG7I6JJA.mjs → intent-resolver-PBDTYC4P.mjs} +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{react-surface-YA7WIRAM.mjs → react-surface-MLE3J3TF.mjs} +5 -5
- package/dist/lib/node-esm/{react-surface-YA7WIRAM.mjs.map → react-surface-MLE3J3TF.mjs.map} +2 -2
- package/dist/lib/node-esm/{settings-NZXHNIQ3.mjs → settings-GR4O2WHZ.mjs} +3 -3
- package/dist/lib/node-esm/types.mjs +2 -2
- package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/artifact-definition.d.ts +11 -0
- package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +1 -0
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts +1 -2
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts.map +1 -1
- package/dist/types/src/components/DebugPanel/DebugPanel.d.ts +1 -2
- package/dist/types/src/components/DebugPanel/DebugPanel.d.ts.map +1 -1
- package/dist/types/src/components/FrameContainer/FrameContainer.d.ts +3 -4
- package/dist/types/src/components/FrameContainer/FrameContainer.d.ts.map +1 -1
- package/dist/types/src/components/ScriptContainer.d.ts +2 -3
- package/dist/types/src/components/ScriptContainer.d.ts.map +1 -1
- package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts +1 -2
- package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts.map +1 -1
- package/dist/types/src/components/ScriptSettingsPanel.d.ts +1 -2
- package/dist/types/src/components/ScriptSettingsPanel.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts +2 -3
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts +1 -2
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +2 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/events.d.ts +4 -0
- package/dist/types/src/events.d.ts.map +1 -0
- package/dist/types/src/hooks/deploy.d.ts.map +1 -0
- package/dist/types/src/hooks/format.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +7 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -0
- package/dist/types/src/{components/ScriptToolbar/templateSelect.d.ts → hooks/template.d.ts} +1 -1
- package/dist/types/src/hooks/template.d.ts.map +1 -0
- package/dist/types/src/{components/ScriptToolbar → hooks}/useToolbarAction.d.ts +1 -1
- package/dist/types/src/hooks/useToolbarAction.d.ts.map +1 -0
- package/dist/types/src/hooks/useToolbarState.d.ts.map +1 -0
- package/dist/types/src/hooks/view.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +0 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/templates/chess.d.ts +1 -4
- package/dist/types/src/templates/chess.d.ts.map +1 -1
- package/dist/types/src/templates/discord.d.ts +3 -0
- package/dist/types/src/templates/discord.d.ts.map +1 -0
- package/dist/types/src/templates/echo.d.ts.map +1 -1
- package/dist/types/src/templates/forex-effect.d.ts +3 -0
- package/dist/types/src/templates/forex-effect.d.ts.map +1 -0
- package/dist/types/src/templates/forex.d.ts +1 -4
- package/dist/types/src/templates/forex.d.ts.map +1 -1
- package/dist/types/src/templates/index.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +6 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/package.json +42 -42
- package/src/ScriptPlugin.tsx +28 -12
- package/src/capabilities/artifact-definition.ts +219 -0
- package/src/capabilities/compiler.ts +1 -1
- package/src/capabilities/index.ts +1 -0
- package/src/capabilities/react-surface.tsx +2 -1
- package/src/compiler/compiler.browser.test.ts +1 -1
- package/src/components/DebugPanel/DebugPanel.tsx +2 -2
- package/src/components/FrameContainer/FrameContainer.tsx +5 -4
- package/src/components/ScriptContainer.tsx +10 -5
- package/src/components/ScriptSettingsPanel.tsx +16 -2
- package/src/components/ScriptToolbar/ScriptToolbar.tsx +8 -6
- package/src/components/TypescriptEditor/TypescriptEditor.tsx +2 -2
- package/src/events.ts +11 -0
- package/src/{components/ScriptToolbar → hooks}/deploy.ts +16 -4
- package/src/{components/ScriptToolbar → hooks}/format.ts +1 -1
- package/src/hooks/index.ts +11 -0
- package/src/{components/ScriptToolbar/templateSelect.ts → hooks/template.ts} +2 -2
- package/src/{components/ScriptToolbar → hooks}/useToolbarAction.ts +1 -1
- package/src/{components/ScriptToolbar → hooks}/view.ts +1 -1
- package/src/index.ts +0 -1
- package/src/meta.ts +2 -1
- package/src/templates/chess.ts +42 -35
- package/src/templates/discord.ts +103 -0
- package/src/templates/echo.ts +5 -1
- package/src/templates/forex-effect.ts +41 -0
- package/src/templates/forex.ts +23 -16
- package/src/templates/index.ts +15 -0
- package/src/translations.ts +2 -0
- package/dist/lib/browser/ScriptContainer-AERJBGYK.mjs.map +0 -7
- package/dist/lib/browser/chunk-ESPJMGXJ.mjs.map +0 -7
- package/dist/lib/browser/chunk-REL2R7SB.mjs +0 -52
- package/dist/lib/browser/chunk-REL2R7SB.mjs.map +0 -7
- package/dist/lib/browser/chunk-SDHKTS6H.mjs +0 -237
- package/dist/lib/browser/chunk-SDHKTS6H.mjs.map +0 -7
- package/dist/lib/browser/chunk-Y4CVWFVS.mjs.map +0 -7
- package/dist/lib/browser/compiler-4QD7VFZX.mjs.map +0 -7
- package/dist/lib/node/ScriptContainer-DOAQ6KOE.cjs.map +0 -7
- package/dist/lib/node/chunk-CZVVFUVL.cjs.map +0 -7
- package/dist/lib/node/chunk-HU2JXUXI.cjs.map +0 -7
- package/dist/lib/node/chunk-T4TXCRN5.cjs +0 -260
- package/dist/lib/node/chunk-T4TXCRN5.cjs.map +0 -7
- package/dist/lib/node/chunk-TJ4BTPOS.cjs +0 -64
- package/dist/lib/node/chunk-TJ4BTPOS.cjs.map +0 -7
- package/dist/lib/node/compiler-Q3EXWKV5.cjs.map +0 -7
- package/dist/lib/node-esm/ScriptContainer-HE5QPPFZ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-77LRZF2W.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-EOBGHKNT.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-G76M6O46.mjs +0 -239
- package/dist/lib/node-esm/chunk-G76M6O46.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-JJZYWSD7.mjs +0 -54
- package/dist/lib/node-esm/chunk-JJZYWSD7.mjs.map +0 -7
- package/dist/lib/node-esm/compiler-KJEIPDZ6.mjs.map +0 -7
- package/dist/types/src/bundler/bundler.d.ts +0 -39
- package/dist/types/src/bundler/bundler.d.ts.map +0 -1
- package/dist/types/src/bundler/bundler.test.d.ts +0 -2
- package/dist/types/src/bundler/bundler.test.d.ts.map +0 -1
- package/dist/types/src/bundler/index.d.ts +0 -2
- package/dist/types/src/bundler/index.d.ts.map +0 -1
- package/dist/types/src/components/ScriptToolbar/deploy.d.ts.map +0 -1
- package/dist/types/src/components/ScriptToolbar/format.d.ts.map +0 -1
- package/dist/types/src/components/ScriptToolbar/templateSelect.d.ts.map +0 -1
- package/dist/types/src/components/ScriptToolbar/useToolbarAction.d.ts.map +0 -1
- package/dist/types/src/components/ScriptToolbar/useToolbarState.d.ts.map +0 -1
- package/dist/types/src/components/ScriptToolbar/view.d.ts.map +0 -1
- package/src/bundler/bundler.test.ts +0 -55
- package/src/bundler/bundler.ts +0 -250
- package/src/bundler/index.ts +0 -5
- /package/dist/lib/browser/{AutomationPanel-KZVZMZE6.mjs.map → AutomationPanel-6HFRNRWV.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-ABNZIPST.mjs.map → chunk-6MOQ4BP3.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-NFPF4OIU.mjs.map → chunk-N46LE7FS.mjs.map} +0 -0
- /package/dist/lib/browser/{intent-resolver-YABC4JRJ.mjs.map → intent-resolver-I6VDXUDH.mjs.map} +0 -0
- /package/dist/lib/browser/{settings-S4MGGM4D.mjs.map → settings-SZCDKHWO.mjs.map} +0 -0
- /package/dist/lib/node/{AutomationPanel-6QSV7ZYK.cjs.map → AutomationPanel-RBQ4DODN.cjs.map} +0 -0
- /package/dist/lib/node/{chunk-RZHY5LAR.cjs.map → chunk-ALY3N6PW.cjs.map} +0 -0
- /package/dist/lib/node/{chunk-6M2VRFBC.cjs.map → chunk-DJGLGRQV.cjs.map} +0 -0
- /package/dist/lib/node/{intent-resolver-7HI2CDGB.cjs.map → intent-resolver-MYATX7IR.cjs.map} +0 -0
- /package/dist/lib/node/{settings-Q5XIA4LZ.cjs.map → settings-SZFSMSKM.cjs.map} +0 -0
- /package/dist/lib/node-esm/{AutomationPanel-EZQSGJLS.mjs.map → AutomationPanel-WTVVVMRH.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-3YOO5E2D.mjs.map → chunk-CP5LXTK5.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-5D2AXTAW.mjs.map → chunk-UNQFIERE.mjs.map} +0 -0
- /package/dist/lib/node-esm/{intent-resolver-KG7I6JJA.mjs.map → intent-resolver-PBDTYC4P.mjs.map} +0 -0
- /package/dist/lib/node-esm/{settings-NZXHNIQ3.mjs.map → settings-GR4O2WHZ.mjs.map} +0 -0
- /package/dist/types/src/{components/ScriptToolbar → hooks}/deploy.d.ts +0 -0
- /package/dist/types/src/{components/ScriptToolbar → hooks}/format.d.ts +0 -0
- /package/dist/types/src/{components/ScriptToolbar → hooks}/useToolbarState.d.ts +0 -0
- /package/dist/types/src/{components/ScriptToolbar → hooks}/view.d.ts +0 -0
- /package/src/{components/ScriptToolbar → hooks}/useToolbarState.ts +0 -0
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var artifact_definition_7AANUS3X_exports = {};
|
|
20
|
+
__export(artifact_definition_7AANUS3X_exports, {
|
|
21
|
+
default: () => artifact_definition_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(artifact_definition_7AANUS3X_exports);
|
|
24
|
+
var import_app_framework = require("@dxos/app-framework");
|
|
25
|
+
var import_artifact = require("@dxos/artifact");
|
|
26
|
+
var import_assistant = require("@dxos/assistant");
|
|
27
|
+
var import_echo_schema = require("@dxos/echo-schema");
|
|
28
|
+
var import_functions = require("@dxos/functions");
|
|
29
|
+
var import_invariant = require("@dxos/invariant");
|
|
30
|
+
var import_types = require("@dxos/plugin-space/types");
|
|
31
|
+
var import_echo = require("@dxos/react-client/echo");
|
|
32
|
+
var import_schema = require("@dxos/schema");
|
|
33
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-script/src/capabilities/artifact-definition.ts";
|
|
34
|
+
var artifact_definition_default = () => {
|
|
35
|
+
const definition = (0, import_artifact.defineArtifact)({
|
|
36
|
+
id: "plugin-script",
|
|
37
|
+
// TODO(dmaretskyi): Since writing scripts requires a lot of domain knowledge,
|
|
38
|
+
// we should offload the work of synthesizing the code to a separate model.
|
|
39
|
+
// The main reasoning model will give it a concrete task and the script model will synthesize the code, knowing all the docs.
|
|
40
|
+
instructions: `
|
|
41
|
+
If the user explicitly requests you to write a script, you can create one.
|
|
42
|
+
If the user requests you to change one of the existing script, you can update it.
|
|
43
|
+
Scripts are short code pieces of executable code that can be used to perform computations, integrate with external systems, and perform automated tasks.
|
|
44
|
+
Each script must follow as strict shape for the definition but the body can contain any valid executable code.
|
|
45
|
+
Scripts are written in JavaScript or TypeScript.
|
|
46
|
+
Each script must define an input schema and output schema.
|
|
47
|
+
Each script must have its own detailed description.
|
|
48
|
+
|
|
49
|
+
Important: You cannot execute scripts. Scripts are only available as tools after the user deploys them. You must only call the available tools.
|
|
50
|
+
|
|
51
|
+
Description:
|
|
52
|
+
The description is a detailed description of the script.
|
|
53
|
+
It is used to describe the script's purpose, input, and output.
|
|
54
|
+
The description is used to generate the script's documentation.
|
|
55
|
+
The description is also goes into the script metadata.
|
|
56
|
+
The description is used by AI to understand the script and its purpose.
|
|
57
|
+
The description must provide cases on when the script should be used.
|
|
58
|
+
|
|
59
|
+
Schema:
|
|
60
|
+
The schema is defined using a schema-DSL library called Effect Schema.
|
|
61
|
+
The input schema describes the arguments that the script accepts.
|
|
62
|
+
The output schema describes the result that the script produces.
|
|
63
|
+
The schema is used to validate the script's input and output.
|
|
64
|
+
The schema is also goes into the script metadata.
|
|
65
|
+
The properties in the schema must have valid descriptions.
|
|
66
|
+
The input and output schemas must both be a struct of fields.
|
|
67
|
+
|
|
68
|
+
Restricts:
|
|
69
|
+
The scripts can only import code from "dxos:functions" module. No other modules are allowed.
|
|
70
|
+
Some web APIs are available - like fetch.
|
|
71
|
+
|
|
72
|
+
Reasoning:
|
|
73
|
+
Before writing a script, synthesize the following information:
|
|
74
|
+
- Description
|
|
75
|
+
- What APIs will be used.
|
|
76
|
+
- Detailed input schema
|
|
77
|
+
- Detailed output schema
|
|
78
|
+
|
|
79
|
+
<apis>
|
|
80
|
+
export function defineFunction(params: {
|
|
81
|
+
description: string,
|
|
82
|
+
inputSchema: S.Schema,
|
|
83
|
+
outputSchema: S.Schema,
|
|
84
|
+
handler: (params: { event: { data: TInput } }) => Promise<TOutput>
|
|
85
|
+
}): FunctionDefinition
|
|
86
|
+
/**
|
|
87
|
+
* Effect Schema
|
|
88
|
+
*/
|
|
89
|
+
export const S;
|
|
90
|
+
|
|
91
|
+
// Examples:
|
|
92
|
+
|
|
93
|
+
S.String
|
|
94
|
+
S.Number
|
|
95
|
+
S.Boolean
|
|
96
|
+
S.Struct({
|
|
97
|
+
from: S.String.annotations({ description: 'The source currency' }),
|
|
98
|
+
to: S.String.annotations({ description: 'The target currency' }),
|
|
99
|
+
})
|
|
100
|
+
S.Array(S.String)
|
|
101
|
+
S.Union(S.String, S.Number)
|
|
102
|
+
S.optional(S.String)
|
|
103
|
+
S.String.annotations({ description: 'The source currency' })
|
|
104
|
+
</apis>
|
|
105
|
+
|
|
106
|
+
<handler_function>
|
|
107
|
+
Async function that takes the argument in the form of:
|
|
108
|
+
|
|
109
|
+
type HandlerFunctionParam = {
|
|
110
|
+
event: {
|
|
111
|
+
data: T // The input schema
|
|
112
|
+
},
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
The function must return the result that matches the output schema.
|
|
116
|
+
</handler_function>
|
|
117
|
+
|
|
118
|
+
<example>
|
|
119
|
+
import { defineFunction, S } from 'dxos:functions';
|
|
120
|
+
|
|
121
|
+
export default defineFunction({
|
|
122
|
+
description: 'Returns the exchange rate between two currencies.',
|
|
123
|
+
|
|
124
|
+
inputSchema: S.Struct({
|
|
125
|
+
from: S.String.annotations({ description: 'The source currency' }),
|
|
126
|
+
to: S.String.annotations({ description: 'The target currency' }),
|
|
127
|
+
}),
|
|
128
|
+
|
|
129
|
+
outputSchema: S.Struct({
|
|
130
|
+
rate: S.String.annotations({ description: 'The exchange rate' }),
|
|
131
|
+
}),
|
|
132
|
+
|
|
133
|
+
handler: async ({
|
|
134
|
+
event: {
|
|
135
|
+
data: { from, to },
|
|
136
|
+
},
|
|
137
|
+
}: any) => {
|
|
138
|
+
const res = await fetch(\`https://free.ratesdb.com/v1/rates?from=\${from}&to=\${to}\`);
|
|
139
|
+
const {
|
|
140
|
+
data: { rates },
|
|
141
|
+
} = await res.json();
|
|
142
|
+
|
|
143
|
+
return { rate: rates[to].toString() };
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
</example>
|
|
147
|
+
`,
|
|
148
|
+
schema: import_functions.ScriptType,
|
|
149
|
+
tools: [
|
|
150
|
+
(0, import_artifact.defineTool)({
|
|
151
|
+
name: "script_new",
|
|
152
|
+
description: "Create a new script. Returns the artifact definition for the script",
|
|
153
|
+
schema: import_echo_schema.S.Struct({
|
|
154
|
+
name: import_echo_schema.S.String.annotations({
|
|
155
|
+
description: "The name of the script"
|
|
156
|
+
}),
|
|
157
|
+
code: import_echo_schema.S.String.annotations({
|
|
158
|
+
description: "The full code of the script in JavaScript or TypeScript. Must be valid executable code."
|
|
159
|
+
})
|
|
160
|
+
}),
|
|
161
|
+
execute: async ({ name, code }, { extensions }) => {
|
|
162
|
+
(0, import_invariant.invariant)(extensions?.space, "No space", {
|
|
163
|
+
F: __dxlog_file,
|
|
164
|
+
L: 149,
|
|
165
|
+
S: void 0,
|
|
166
|
+
A: [
|
|
167
|
+
"extensions?.space",
|
|
168
|
+
"'No space'"
|
|
169
|
+
]
|
|
170
|
+
});
|
|
171
|
+
(0, import_invariant.invariant)(extensions?.dispatch, "No intent dispatcher", {
|
|
172
|
+
F: __dxlog_file,
|
|
173
|
+
L: 150,
|
|
174
|
+
S: void 0,
|
|
175
|
+
A: [
|
|
176
|
+
"extensions?.dispatch",
|
|
177
|
+
"'No intent dispatcher'"
|
|
178
|
+
]
|
|
179
|
+
});
|
|
180
|
+
const script = (0, import_echo.create)(import_functions.ScriptType, {
|
|
181
|
+
name,
|
|
182
|
+
source: (0, import_echo.makeRef)((0, import_echo.create)(import_schema.TextType, {
|
|
183
|
+
content: code
|
|
184
|
+
}))
|
|
185
|
+
});
|
|
186
|
+
extensions.space.db.add(script);
|
|
187
|
+
await extensions.space.db.flush();
|
|
188
|
+
const intent = (0, import_app_framework.createIntent)(import_types.SpaceAction.AddObject, {
|
|
189
|
+
target: extensions.space,
|
|
190
|
+
object: script
|
|
191
|
+
});
|
|
192
|
+
const { data, error } = await extensions.dispatch(intent);
|
|
193
|
+
if (!data || error) {
|
|
194
|
+
return import_artifact.ToolResult.Error(error?.message ?? "Failed to create chess game");
|
|
195
|
+
}
|
|
196
|
+
return import_artifact.ToolResult.Success((0, import_assistant.createArtifactElement)(script.id));
|
|
197
|
+
}
|
|
198
|
+
}),
|
|
199
|
+
(0, import_artifact.defineTool)({
|
|
200
|
+
name: "script_inspect",
|
|
201
|
+
description: "Inspect a script. Returns the artifact definition for the script",
|
|
202
|
+
schema: import_echo_schema.S.Struct({
|
|
203
|
+
id: import_echo_schema.ObjectId
|
|
204
|
+
}),
|
|
205
|
+
execute: async ({ id }, { extensions }) => {
|
|
206
|
+
(0, import_invariant.invariant)(extensions?.space, "No space", {
|
|
207
|
+
F: __dxlog_file,
|
|
208
|
+
L: 178,
|
|
209
|
+
S: void 0,
|
|
210
|
+
A: [
|
|
211
|
+
"extensions?.space",
|
|
212
|
+
"'No space'"
|
|
213
|
+
]
|
|
214
|
+
});
|
|
215
|
+
const script = await extensions.space.db.query({
|
|
216
|
+
id
|
|
217
|
+
}).first();
|
|
218
|
+
const { content } = await script.source.load();
|
|
219
|
+
return import_artifact.ToolResult.Success({
|
|
220
|
+
name: script.name,
|
|
221
|
+
code: content
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}),
|
|
225
|
+
(0, import_artifact.defineTool)({
|
|
226
|
+
name: "script_update",
|
|
227
|
+
description: "Update a script. Returns the artifact definition for the script",
|
|
228
|
+
schema: import_echo_schema.S.Struct({
|
|
229
|
+
id: import_echo_schema.ObjectId,
|
|
230
|
+
code: import_echo_schema.S.String.annotations({
|
|
231
|
+
description: "The full code of the script in JavaScript or TypeScript. Must be valid executable code."
|
|
232
|
+
})
|
|
233
|
+
}),
|
|
234
|
+
execute: async ({ id, code }, { extensions }) => {
|
|
235
|
+
(0, import_invariant.invariant)(extensions?.space, "No space", {
|
|
236
|
+
F: __dxlog_file,
|
|
237
|
+
L: 199,
|
|
238
|
+
S: void 0,
|
|
239
|
+
A: [
|
|
240
|
+
"extensions?.space",
|
|
241
|
+
"'No space'"
|
|
242
|
+
]
|
|
243
|
+
});
|
|
244
|
+
const script = await extensions.space.db.query({
|
|
245
|
+
id
|
|
246
|
+
}).first();
|
|
247
|
+
const source = await script.source.load();
|
|
248
|
+
if (!source) {
|
|
249
|
+
return import_artifact.ToolResult.Error("Script not found");
|
|
250
|
+
}
|
|
251
|
+
source.content = code;
|
|
252
|
+
await extensions.space?.db.flush();
|
|
253
|
+
return import_artifact.ToolResult.Success({
|
|
254
|
+
name: script.name
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
})
|
|
258
|
+
]
|
|
259
|
+
});
|
|
260
|
+
return (0, import_app_framework.contributes)(import_app_framework.Capabilities.ArtifactDefinition, definition);
|
|
261
|
+
};
|
|
262
|
+
//# sourceMappingURL=artifact-definition-7AANUS3X.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/capabilities/artifact-definition.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Capabilities, contributes, createIntent, type PromiseIntentDispatcher } from '@dxos/app-framework';\nimport { defineArtifact, defineTool, ToolResult } from '@dxos/artifact';\nimport { createArtifactElement } from '@dxos/assistant';\nimport { ObjectId, S } from '@dxos/echo-schema';\nimport { ScriptType } from '@dxos/functions';\nimport { invariant } from '@dxos/invariant';\nimport { SpaceAction } from '@dxos/plugin-space/types';\nimport { create, makeRef, type Space } from '@dxos/react-client/echo';\nimport { TextType } from '@dxos/schema';\n\n// TODO(burdon): Factor out.\ndeclare global {\n interface ToolContextExtensions {\n space?: Space;\n dispatch?: PromiseIntentDispatcher;\n }\n}\n\nexport default () => {\n const definition = defineArtifact({\n id: 'plugin-script',\n // TODO(dmaretskyi): Since writing scripts requires a lot of domain knowledge,\n // we should offload the work of synthesizing the code to a separate model.\n // The main reasoning model will give it a concrete task and the script model will synthesize the code, knowing all the docs.\n instructions: `\n If the user explicitly requests you to write a script, you can create one.\n If the user requests you to change one of the existing script, you can update it.\n Scripts are short code pieces of executable code that can be used to perform computations, integrate with external systems, and perform automated tasks.\n Each script must follow as strict shape for the definition but the body can contain any valid executable code.\n Scripts are written in JavaScript or TypeScript.\n Each script must define an input schema and output schema.\n Each script must have its own detailed description.\n\n Important: You cannot execute scripts. Scripts are only available as tools after the user deploys them. You must only call the available tools.\n\n Description:\n The description is a detailed description of the script.\n It is used to describe the script's purpose, input, and output.\n The description is used to generate the script's documentation.\n The description is also goes into the script metadata.\n The description is used by AI to understand the script and its purpose.\n The description must provide cases on when the script should be used.\n\n Schema: \n The schema is defined using a schema-DSL library called Effect Schema.\n The input schema describes the arguments that the script accepts.\n The output schema describes the result that the script produces.\n The schema is used to validate the script's input and output.\n The schema is also goes into the script metadata.\n The properties in the schema must have valid descriptions.\n The input and output schemas must both be a struct of fields.\n\n Restricts:\n The scripts can only import code from \"dxos:functions\" module. No other modules are allowed.\n Some web APIs are available - like fetch.\n\n Reasoning:\n Before writing a script, synthesize the following information:\n - Description\n - What APIs will be used.\n - Detailed input schema\n - Detailed output schema\n\n <apis>\n export function defineFunction(params: { \n description: string, \n inputSchema: S.Schema, \n outputSchema: S.Schema, \n handler: (params: { event: { data: TInput } }) => Promise<TOutput> \n }): FunctionDefinition\n /**\n * Effect Schema\n */\n export const S; \n\n // Examples: \n\n S.String\n S.Number\n S.Boolean\n S.Struct({\n from: S.String.annotations({ description: 'The source currency' }),\n to: S.String.annotations({ description: 'The target currency' }),\n })\n S.Array(S.String)\n S.Union(S.String, S.Number)\n S.optional(S.String)\n S.String.annotations({ description: 'The source currency' })\n </apis>\n\n <handler_function>\n Async function that takes the argument in the form of:\n\n type HandlerFunctionParam = {\n event: {\n data: T // The input schema\n },\n }\n\n The function must return the result that matches the output schema.\n </handler_function>\n \n <example>\n import { defineFunction, S } from 'dxos:functions';\n\n export default defineFunction({\n description: 'Returns the exchange rate between two currencies.',\n\n inputSchema: S.Struct({\n from: S.String.annotations({ description: 'The source currency' }),\n to: S.String.annotations({ description: 'The target currency' }),\n }),\n\n outputSchema: S.Struct({\n rate: S.String.annotations({ description: 'The exchange rate' }),\n }),\n\n handler: async ({\n event: {\n data: { from, to },\n },\n }: any) => {\n const res = await fetch(\\`https://free.ratesdb.com/v1/rates?from=\\${from}&to=\\${to}\\`);\n const {\n data: { rates },\n } = await res.json();\n\n return { rate: rates[to].toString() };\n },\n });\n </example>\n `,\n schema: ScriptType,\n tools: [\n defineTool({\n name: 'script_new',\n description: 'Create a new script. Returns the artifact definition for the script',\n schema: S.Struct({\n name: S.String.annotations({ description: 'The name of the script' }),\n code: S.String.annotations({\n description: 'The full code of the script in JavaScript or TypeScript. Must be valid executable code.',\n }),\n }),\n execute: async ({ name, code }, { extensions }) => {\n invariant(extensions?.space, 'No space');\n invariant(extensions?.dispatch, 'No intent dispatcher');\n const script = create(ScriptType, {\n name,\n source: makeRef(\n create(TextType, {\n content: code,\n }),\n ),\n });\n extensions.space.db.add(script);\n await extensions.space.db.flush();\n\n const intent = createIntent(SpaceAction.AddObject, { target: extensions.space, object: script });\n const { data, error } = await extensions.dispatch(intent);\n if (!data || error) {\n return ToolResult.Error(error?.message ?? 'Failed to create chess game');\n }\n\n return ToolResult.Success(createArtifactElement(script.id));\n },\n }),\n defineTool({\n name: 'script_inspect',\n description: 'Inspect a script. Returns the artifact definition for the script',\n schema: S.Struct({\n id: ObjectId,\n }),\n execute: async ({ id }, { extensions }) => {\n invariant(extensions?.space, 'No space');\n\n const script = (await extensions.space.db.query({ id }).first()) as ScriptType;\n const { content } = await script.source.load();\n\n return ToolResult.Success({\n name: script.name,\n code: content,\n });\n },\n }),\n defineTool({\n name: 'script_update',\n description: 'Update a script. Returns the artifact definition for the script',\n schema: S.Struct({\n id: ObjectId,\n code: S.String.annotations({\n description: 'The full code of the script in JavaScript or TypeScript. Must be valid executable code.',\n }),\n }),\n execute: async ({ id, code }, { extensions }) => {\n invariant(extensions?.space, 'No space');\n\n const script = (await extensions.space.db.query({ id }).first()) as ScriptType;\n const source = await script.source.load();\n if (!source) {\n return ToolResult.Error('Script not found');\n }\n\n source.content = code;\n await extensions.space?.db.flush();\n\n return ToolResult.Success({\n name: script.name,\n });\n },\n }),\n ],\n });\n\n return contributes(Capabilities.ArtifactDefinition, definition);\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAIA,2BAAsF;AACtF,sBAAuD;AACvD,uBAAsC;AACtC,yBAA4B;AAC5B,uBAA2B;AAC3B,uBAA0B;AAC1B,mBAA4B;AAC5B,kBAA4C;AAC5C,oBAAyB;;AAUzB,IAAA,8BAAe,MAAA;AACb,QAAMA,iBAAaC,gCAAe;IAChCC,IAAI;;;;IAIJC,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA4GdC,QAAQC;IACRC,OAAO;UACLC,4BAAW;QACTC,MAAM;QACNC,aAAa;QACbL,QAAQM,qBAAEC,OAAO;UACfH,MAAME,qBAAEE,OAAOC,YAAY;YAAEJ,aAAa;UAAyB,CAAA;UACnEK,MAAMJ,qBAAEE,OAAOC,YAAY;YACzBJ,aAAa;UACf,CAAA;QACF,CAAA;QACAM,SAAS,OAAO,EAAEP,MAAMM,KAAI,GAAI,EAAEE,WAAU,MAAE;AAC5CC,0CAAUD,YAAYE,OAAO,YAAA;;;;;;;;;AAC7BD,0CAAUD,YAAYG,UAAU,wBAAA;;;;;;;;;AAChC,gBAAMC,aAASC,oBAAOhB,6BAAY;YAChCG;YACAc,YAAQC,yBACNF,oBAAOG,wBAAU;cACfC,SAASX;YACX,CAAA,CAAA;UAEJ,CAAA;AACAE,qBAAWE,MAAMQ,GAAGC,IAAIP,MAAAA;AACxB,gBAAMJ,WAAWE,MAAMQ,GAAGE,MAAK;AAE/B,gBAAMC,aAASC,mCAAaC,yBAAYC,WAAW;YAAEC,QAAQjB,WAAWE;YAAOgB,QAAQd;UAAO,CAAA;AAC9F,gBAAM,EAAEe,MAAMC,MAAK,IAAK,MAAMpB,WAAWG,SAASU,MAAAA;AAClD,cAAI,CAACM,QAAQC,OAAO;AAClB,mBAAOC,2BAAWC,MAAMF,OAAOG,WAAW,6BAAA;UAC5C;AAEA,iBAAOF,2BAAWG,YAAQC,wCAAsBrB,OAAOlB,EAAE,CAAA;QAC3D;MACF,CAAA;UACAK,4BAAW;QACTC,MAAM;QACNC,aAAa;QACbL,QAAQM,qBAAEC,OAAO;UACfT,IAAIwC;QACN,CAAA;QACA3B,SAAS,OAAO,EAAEb,GAAE,GAAI,EAAEc,WAAU,MAAE;AACpCC,0CAAUD,YAAYE,OAAO,YAAA;;;;;;;;;AAE7B,gBAAME,SAAU,MAAMJ,WAAWE,MAAMQ,GAAGiB,MAAM;YAAEzC;UAAG,CAAA,EAAG0C,MAAK;AAC7D,gBAAM,EAAEnB,QAAO,IAAK,MAAML,OAAOE,OAAOuB,KAAI;AAE5C,iBAAOR,2BAAWG,QAAQ;YACxBhC,MAAMY,OAAOZ;YACbM,MAAMW;UACR,CAAA;QACF;MACF,CAAA;UACAlB,4BAAW;QACTC,MAAM;QACNC,aAAa;QACbL,QAAQM,qBAAEC,OAAO;UACfT,IAAIwC;UACJ5B,MAAMJ,qBAAEE,OAAOC,YAAY;YACzBJ,aAAa;UACf,CAAA;QACF,CAAA;QACAM,SAAS,OAAO,EAAEb,IAAIY,KAAI,GAAI,EAAEE,WAAU,MAAE;AAC1CC,0CAAUD,YAAYE,OAAO,YAAA;;;;;;;;;AAE7B,gBAAME,SAAU,MAAMJ,WAAWE,MAAMQ,GAAGiB,MAAM;YAAEzC;UAAG,CAAA,EAAG0C,MAAK;AAC7D,gBAAMtB,SAAS,MAAMF,OAAOE,OAAOuB,KAAI;AACvC,cAAI,CAACvB,QAAQ;AACX,mBAAOe,2BAAWC,MAAM,kBAAA;UAC1B;AAEAhB,iBAAOG,UAAUX;AACjB,gBAAME,WAAWE,OAAOQ,GAAGE,MAAAA;AAE3B,iBAAOS,2BAAWG,QAAQ;YACxBhC,MAAMY,OAAOZ;UACf,CAAA;QACF;MACF,CAAA;;EAEJ,CAAA;AAEA,aAAOsC,kCAAYC,kCAAaC,oBAAoBhD,UAAAA;AACtD;",
|
|
6
|
+
"names": ["definition", "defineArtifact", "id", "instructions", "schema", "ScriptType", "tools", "defineTool", "name", "description", "S", "Struct", "String", "annotations", "code", "execute", "extensions", "invariant", "space", "dispatch", "script", "create", "source", "makeRef", "TextType", "content", "db", "add", "flush", "intent", "createIntent", "SpaceAction", "AddObject", "target", "object", "data", "error", "ToolResult", "Error", "message", "Success", "createArtifactElement", "ObjectId", "query", "first", "load", "contributes", "Capabilities", "ArtifactDefinition"]
|
|
7
|
+
}
|
|
@@ -16,17 +16,17 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
19
|
+
var chunk_5UH3F7TA_exports = {};
|
|
20
|
+
__export(chunk_5UH3F7TA_exports, {
|
|
21
21
|
SCRIPT_PLUGIN: () => SCRIPT_PLUGIN,
|
|
22
22
|
meta: () => meta
|
|
23
23
|
});
|
|
24
|
-
module.exports = __toCommonJS(
|
|
24
|
+
module.exports = __toCommonJS(chunk_5UH3F7TA_exports);
|
|
25
25
|
var SCRIPT_PLUGIN = "dxos.org/plugin/script";
|
|
26
26
|
var meta = {
|
|
27
27
|
id: SCRIPT_PLUGIN,
|
|
28
28
|
name: "Scripts",
|
|
29
|
-
description:
|
|
29
|
+
description: "Scripts in Composer allow you to deploy custom functions that run on the edge. These functions can be referenced by your AI agent and called inside of cells in any Sheet. Use scripts to interact with API\u2019s or external data inside of Composer.",
|
|
30
30
|
icon: "ph--code--regular",
|
|
31
31
|
source: "https://github.com/dxos/dxos/tree/main/packages/plugins/experimental/plugin-explorer",
|
|
32
32
|
tags: [
|
|
@@ -41,4 +41,4 @@ var meta = {
|
|
|
41
41
|
SCRIPT_PLUGIN,
|
|
42
42
|
meta
|
|
43
43
|
});
|
|
44
|
-
//# sourceMappingURL=chunk-
|
|
44
|
+
//# sourceMappingURL=chunk-5UH3F7TA.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/meta.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type PluginMeta } from '@dxos/app-framework';\n\nexport const SCRIPT_PLUGIN = 'dxos.org/plugin/script';\n\nexport const meta = {\n id: SCRIPT_PLUGIN,\n name: 'Scripts',\n description:\n 'Scripts in Composer allow you to deploy custom functions that run on the edge. These functions can be referenced by your AI agent and called inside of cells in any Sheet. Use scripts to interact with API’s or external data inside of Composer.',\n icon: 'ph--code--regular',\n source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/experimental/plugin-explorer',\n tags: ['experimental'],\n screenshots: ['https://dxos.network/plugin-details-scripts-dark.png'],\n} satisfies PluginMeta;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAMO,IAAMA,gBAAgB;AAEtB,IAAMC,OAAO;EAClBC,IAAIF;EACJG,MAAM;EACNC,aACE;EACFC,MAAM;EACNC,QAAQ;EACRC,MAAM;IAAC;;EACPC,aAAa;IAAC;;AAChB;",
|
|
6
|
+
"names": ["SCRIPT_PLUGIN", "meta", "id", "name", "description", "icon", "source", "tags", "screenshots"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var chunk_7XULMIYT_exports = {};
|
|
20
|
+
__export(chunk_7XULMIYT_exports, {
|
|
21
|
+
templates: () => templates
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(chunk_7XULMIYT_exports);
|
|
24
|
+
var chat_default = "//\n// Copyright 2024 DXOS.org\n//\n\n// @ts-ignore\nimport { transformServerSentEvents } from 'https://esm.sh/@dxos/script-toolbox';\n\n/**\n * Chatbot that answers questions based on the context data.\n */\nexport default async ({\n event: {\n data: { request },\n },\n context: { space, ai },\n}: any) => {\n const textBody = await request.text();\n let parsedRequest: any;\n try {\n parsedRequest = JSON.parse(textBody);\n } catch (err) {\n const answer = await ai.run('@cf/meta/llama-3.1-8b-instruct', {\n stream: true,\n prompt: `\n Using only the context data below to answer the user's question.\n If you cannot answer the question from the provided content, then reply with \"I don't know.\"\n\n CONTEXT:\n ${await getContext({ space })}\n\n QUESTION:\n ${textBody}\n `,\n });\n return new Response(transformServerSentEvents(answer));\n }\n\n const promptId = parsedRequest.trigger.promptId;\n const promptObject = await space.crud.query({ id: promptId }).first();\n\n if (parsedRequest.data.objects.length !== 1) {\n return new Response('Message batches not supported.');\n }\n\n const messageId = parsedRequest.data.objects[0];\n let message;\n try {\n message = await space.crud.query({ id: messageId }).first();\n } catch (err) {\n return new Response('Message not replicated yet.', { status: 409 });\n }\n\n if (message.text.includes('--------')) {\n return new Response('Message was already processed.');\n }\n\n let prompt = promptObject.template;\n for (const input of promptObject.inputs) {\n let value: string | null = null;\n if (input.type === ChainInputType.VALUE) {\n value = String(input.value);\n } else if (input.type === ChainInputType.RETRIEVER) {\n value = await getContext({ space });\n } else if (input.type === ChainInputType.PASS_THROUGH) {\n value = message.text;\n }\n if (value) {\n prompt = prompt.replaceAll(`{${input.name}}`, value);\n }\n }\n\n const answer = await ai.run('@cf/meta/llama-3.1-8b-instruct', {\n stream: false,\n prompt,\n });\n const response = { response: answer.response, prompt, message };\n const textWithAnswer = message.text + '\\n--------\\n\\n' + answer.response;\n await space.crud.update({ id: messageId }, { text: textWithAnswer });\n\n return new Response(JSON.stringify(response));\n};\n\nconst getContext = async ({ space }: any) => {\n let context = '';\n const { objects: docs } = await space.crud.query({ __typename: 'dxos.org/type/Document' }).run();\n for (const doc of docs) {\n const { content } = await space.crud.query({ id: doc.content }).first();\n context += content + '\\n\\n';\n }\n return context;\n};\n\nenum ChainInputType {\n VALUE = 0,\n PASS_THROUGH = 1,\n RETRIEVER = 2,\n FUNCTION = 3,\n QUERY = 4,\n RESOLVER = 5,\n CONTEXT = 6,\n SCHEMA = 7,\n}\n";
|
|
25
|
+
var chess_default = "// @ts-ignore\nimport { defineFunction, S } from 'dxos:functions';\n// @ts-ignore\nimport { Chess } from 'https://esm.sh/chess.js@0.13.1';\n\nexport default defineFunction({\n description: 'Plays a random move in a chess game.',\n\n inputSchema: S.Struct({\n changedObjectId: S.String.annotations({\n description: 'The objects to play the game on.',\n }),\n player: S.optional(S.Literal('w', 'b')).annotations({\n description: 'The player to play the game as.',\n }),\n }),\n\n outputSchema: S.Struct({\n state: S.String.annotations({\n description: 'The state of the game as an ASCII art board.',\n }),\n }),\n\n handler: async ({\n event: {\n data: { changedObjectId, player = 'b' },\n },\n context: { space },\n }: any) => {\n const { pgn } = await space.db.query({ id: changedObjectId }).first();\n const game = new Chess();\n game.load_pgn(pgn);\n if (game.turn() !== player) {\n return new Response('Invalid turn', { status: 409 });\n }\n\n const moves = game.moves();\n const move = moves[Math.floor(Math.random() * moves.length)];\n if (!move) {\n return new Response('No legal moves', { status: 406 });\n }\n\n game.move(move);\n const newPgn = game.pgn();\n await space.db.update({ id: changedObjectId }, { pgn: newPgn, fen: game.fen() });\n return { state: game.ascii() };\n },\n});\n";
|
|
26
|
+
var discord_default = "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { createStatic, EchoObject, defineFunction, DXN, Filter, ObjectId, S } from 'dxos:functions';\nimport {\n FetchHttpClient,\n // @ts-ignore\n} from 'https://esm.sh/@effect/platform@0.77.2?deps=effect@3.13.3';\n// @ts-ignore\nimport { DiscordConfig, DiscordREST, DiscordRESTMemoryLive } from 'https://esm.sh/dfx@0.113.0?deps=effect@3.13.3';\n// @ts-ignore\nimport { Effect, Config, Redacted, Ref } from 'https://esm.sh/effect@3.13.3';\n\nconst MessageSchema = S.Struct({\n id: S.String,\n foreignId: S.Any, // bigint?\n from: S.String,\n created: S.String,\n content: S.String,\n}).pipe(EchoObject('example.com/type/Message', '0.1.0'));\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 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: ({\n event: {\n data: { channelId, queueId, after = DEFAULT_AFTER, pageSize = 5 },\n },\n context: { space },\n }: any) =>\n Effect.gen(function* () {\n const { token } = yield* Effect.tryPromise(() =>\n space.db.query(Filter.typename('dxos.org/type/AccessToken', { source: 'discord.com' })).first(),\n );\n const { objects } = yield* Effect.tryPromise(() => space.queues.queryQueue(DXN.parse(queueId)));\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 createStatic(MessageSchema, {\n id: ObjectId.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(() => space.queues.insertIntoQueue(DXN.parse(queueId), queueMessages));\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";
|
|
27
|
+
var echo_default = "//\n// Copyright 2024 DXOS.org\n//\n\n/**\n * Echos the request data.\n */\nexport default async ({\n event: {\n data: { request },\n },\n}: any) => {\n const data = await request.json();\n return new Response(JSON.stringify(data ?? {}), {\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n};\n";
|
|
28
|
+
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 ({\n event: {\n data: { request },\n },\n context: { space },\n}: any) => {\n const { data, trigger } = (await request.json()) as RequestPayload;\n\n const documentId = trigger.meta.targetDocumentId;\n const document = await space.db.query({ id: documentId }, { format: 'plain' }).first();\n\n const contentId = document.content['/'].split(':')[3];\n const documentContent = await space.db.query({ id: contentId }, { format: 'plain' }).first();\n const modifiedContent = [\n documentContent.content,\n '',\n '---',\n `**From:** ${data.from}`,\n `**Subject:** ${data.subject}`,\n `**Date:** ${data.created}`,\n '',\n data.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 data: { from: string; subject: string; created: string; body: string };\n trigger: { meta: { targetDocumentId: string } };\n};\n";
|
|
29
|
+
var forex_effect_default = "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { defineFunction, S } from 'dxos:functions';\nimport {\n HttpClient,\n HttpClientRequest,\n FetchHttpClient,\n // @ts-ignore\n} from 'https://esm.sh/@effect/platform@0.77.2?deps=effect@3.13.3';\n// @ts-ignore\nimport { Effect, Schedule } from 'https://esm.sh/effect@3.13.3';\n\nexport default defineFunction({\n description: 'Returns the exchange rate between two currencies.',\n\n inputSchema: S.Struct({\n from: S.String.annotations({ description: 'The source currency' }),\n to: S.String.annotations({ description: 'The target currency' }),\n }),\n\n outputSchema: S.String.annotations({ description: 'The exchange rate between the two currencies' }),\n\n handler: async ({\n event: {\n data: { from, to },\n },\n }: any) =>\n Effect.gen(function* () {\n const res = yield* HttpClientRequest.get(`https://free.ratesdb.com/v1/rates?from=${from}&to=${to}`).pipe(\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 return res.data.rates[to].toString();\n }).pipe(Effect.provide(FetchHttpClient.layer)),\n});\n";
|
|
30
|
+
var forex_default = "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { defineFunction, S } from 'dxos:functions';\n\nexport default defineFunction({\n description: 'Returns the exchange rate between two currencies.',\n\n inputSchema: S.Struct({\n from: S.String.annotations({ description: 'The source currency' }),\n to: S.String.annotations({ description: 'The target currency' }),\n }),\n\n handler: async ({\n event: {\n data: { from, to },\n },\n }: any) => {\n const res = await fetch(`https://free.ratesdb.com/v1/rates?from=${from}&to=${to}`);\n const {\n data: { rates },\n } = await res.json();\n\n return rates[to].toString();\n },\n});\n";
|
|
31
|
+
var removeHeader = (str) => str.split("\n").slice(4).join("\n");
|
|
32
|
+
var templates = [
|
|
33
|
+
{
|
|
34
|
+
id: "dxos.org/script/echo",
|
|
35
|
+
name: "Echo",
|
|
36
|
+
source: removeHeader(echo_default)
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: "dxos.org/script/forex",
|
|
40
|
+
name: "Forex",
|
|
41
|
+
source: removeHeader(forex_default)
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
id: "dxos.org/script/forex-effect",
|
|
45
|
+
name: "Forex (Effect)",
|
|
46
|
+
source: removeHeader(forex_effect_default)
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
id: "dxos.org/script/gpt",
|
|
50
|
+
name: "Gpt",
|
|
51
|
+
source: removeHeader(chat_default),
|
|
52
|
+
presetId: "dxos.org/function/gpt"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: "dxos.org/script/chess",
|
|
56
|
+
name: "Chess",
|
|
57
|
+
source: removeHeader(chess_default),
|
|
58
|
+
presetId: "dxos.org/function/chess"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: "dxos.org/script/email",
|
|
62
|
+
name: "Email",
|
|
63
|
+
source: removeHeader(email_default),
|
|
64
|
+
presetId: "dxos.org/function/email"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
id: "dxos.org/script/discord",
|
|
68
|
+
name: "Discord",
|
|
69
|
+
source: removeHeader(discord_default),
|
|
70
|
+
presetId: "dxos.org/function/discord"
|
|
71
|
+
}
|
|
72
|
+
];
|
|
73
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
+
0 && (module.exports = {
|
|
75
|
+
templates
|
|
76
|
+
});
|
|
77
|
+
//# sourceMappingURL=chunk-7XULMIYT.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["raw-loader:./chat.ts?raw", "raw-loader:./chess.ts?raw", "raw-loader:./discord.ts?raw", "raw-loader:./echo.ts?raw", "raw-loader:./email.ts?raw", "raw-loader:./forex-effect.ts?raw", "raw-loader:./forex.ts?raw", "../../../src/templates/index.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\n// @ts-ignore\nimport { transformServerSentEvents } from 'https://esm.sh/@dxos/script-toolbox';\n\n/**\n * Chatbot that answers questions based on the context data.\n */\nexport default async ({\n event: {\n data: { request },\n },\n context: { space, ai },\n}: any) => {\n const textBody = await request.text();\n let parsedRequest: any;\n try {\n parsedRequest = JSON.parse(textBody);\n } catch (err) {\n const answer = await ai.run('@cf/meta/llama-3.1-8b-instruct', {\n stream: true,\n prompt: `\n Using only the context data below to answer the user's question.\n If you cannot answer the question from the provided content, then reply with \"I don't know.\"\n\n CONTEXT:\n ${await getContext({ space })}\n\n QUESTION:\n ${textBody}\n `,\n });\n return new Response(transformServerSentEvents(answer));\n }\n\n const promptId = parsedRequest.trigger.promptId;\n const promptObject = await space.crud.query({ id: promptId }).first();\n\n if (parsedRequest.data.objects.length !== 1) {\n return new Response('Message batches not supported.');\n }\n\n const messageId = parsedRequest.data.objects[0];\n let message;\n try {\n message = await space.crud.query({ id: messageId }).first();\n } catch (err) {\n return new Response('Message not replicated yet.', { status: 409 });\n }\n\n if (message.text.includes('--------')) {\n return new Response('Message was already processed.');\n }\n\n let prompt = promptObject.template;\n for (const input of promptObject.inputs) {\n let value: string | null = null;\n if (input.type === ChainInputType.VALUE) {\n value = String(input.value);\n } else if (input.type === ChainInputType.RETRIEVER) {\n value = await getContext({ space });\n } else if (input.type === ChainInputType.PASS_THROUGH) {\n value = message.text;\n }\n if (value) {\n prompt = prompt.replaceAll(`{${input.name}}`, value);\n }\n }\n\n const answer = await ai.run('@cf/meta/llama-3.1-8b-instruct', {\n stream: false,\n prompt,\n });\n const response = { response: answer.response, prompt, message };\n const textWithAnswer = message.text + '\\n--------\\n\\n' + answer.response;\n await space.crud.update({ id: messageId }, { text: textWithAnswer });\n\n return new Response(JSON.stringify(response));\n};\n\nconst getContext = async ({ space }: any) => {\n let context = '';\n const { objects: docs } = await space.crud.query({ __typename: 'dxos.org/type/Document' }).run();\n for (const doc of docs) {\n const { content } = await space.crud.query({ id: doc.content }).first();\n context += content + '\\n\\n';\n }\n return context;\n};\n\nenum ChainInputType {\n VALUE = 0,\n PASS_THROUGH = 1,\n RETRIEVER = 2,\n FUNCTION = 3,\n QUERY = 4,\n RESOLVER = 5,\n CONTEXT = 6,\n SCHEMA = 7,\n}\n", "// @ts-ignore\nimport { defineFunction, S } from 'dxos:functions';\n// @ts-ignore\nimport { Chess } from 'https://esm.sh/chess.js@0.13.1';\n\nexport default defineFunction({\n description: 'Plays a random move in a chess game.',\n\n inputSchema: S.Struct({\n changedObjectId: S.String.annotations({\n description: 'The objects to play the game on.',\n }),\n player: S.optional(S.Literal('w', 'b')).annotations({\n description: 'The player to play the game as.',\n }),\n }),\n\n outputSchema: S.Struct({\n state: S.String.annotations({\n description: 'The state of the game as an ASCII art board.',\n }),\n }),\n\n handler: async ({\n event: {\n data: { changedObjectId, player = 'b' },\n },\n context: { space },\n }: any) => {\n const { pgn } = await space.db.query({ id: changedObjectId }).first();\n const game = new Chess();\n game.load_pgn(pgn);\n if (game.turn() !== player) {\n return new Response('Invalid turn', { status: 409 });\n }\n\n const moves = game.moves();\n const move = moves[Math.floor(Math.random() * moves.length)];\n if (!move) {\n return new Response('No legal moves', { status: 406 });\n }\n\n game.move(move);\n const newPgn = game.pgn();\n await space.db.update({ id: changedObjectId }, { pgn: newPgn, fen: game.fen() });\n return { state: game.ascii() };\n },\n});\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { createStatic, EchoObject, defineFunction, DXN, Filter, ObjectId, S } from 'dxos:functions';\nimport {\n FetchHttpClient,\n // @ts-ignore\n} from 'https://esm.sh/@effect/platform@0.77.2?deps=effect@3.13.3';\n// @ts-ignore\nimport { DiscordConfig, DiscordREST, DiscordRESTMemoryLive } from 'https://esm.sh/dfx@0.113.0?deps=effect@3.13.3';\n// @ts-ignore\nimport { Effect, Config, Redacted, Ref } from 'https://esm.sh/effect@3.13.3';\n\nconst MessageSchema = S.Struct({\n id: S.String,\n foreignId: S.Any, // bigint?\n from: S.String,\n created: S.String,\n content: S.String,\n}).pipe(EchoObject('example.com/type/Message', '0.1.0'));\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 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: ({\n event: {\n data: { channelId, queueId, after = DEFAULT_AFTER, pageSize = 5 },\n },\n context: { space },\n }: any) =>\n Effect.gen(function* () {\n const { token } = yield* Effect.tryPromise(() =>\n space.db.query(Filter.typename('dxos.org/type/AccessToken', { source: 'discord.com' })).first(),\n );\n const { objects } = yield* Effect.tryPromise(() => space.queues.queryQueue(DXN.parse(queueId)));\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 createStatic(MessageSchema, {\n id: ObjectId.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(() => space.queues.insertIntoQueue(DXN.parse(queueId), queueMessages));\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", "//\n// Copyright 2024 DXOS.org\n//\n\n/**\n * Echos the request data.\n */\nexport default async ({\n event: {\n data: { request },\n },\n}: any) => {\n const data = await request.json();\n return new Response(JSON.stringify(data ?? {}), {\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n};\n", "//\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 ({\n event: {\n data: { request },\n },\n context: { space },\n}: any) => {\n const { data, trigger } = (await request.json()) as RequestPayload;\n\n const documentId = trigger.meta.targetDocumentId;\n const document = await space.db.query({ id: documentId }, { format: 'plain' }).first();\n\n const contentId = document.content['/'].split(':')[3];\n const documentContent = await space.db.query({ id: contentId }, { format: 'plain' }).first();\n const modifiedContent = [\n documentContent.content,\n '',\n '---',\n `**From:** ${data.from}`,\n `**Subject:** ${data.subject}`,\n `**Date:** ${data.created}`,\n '',\n data.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 data: { from: string; subject: string; created: string; body: string };\n trigger: { meta: { targetDocumentId: string } };\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { defineFunction, S } from 'dxos:functions';\nimport {\n HttpClient,\n HttpClientRequest,\n FetchHttpClient,\n // @ts-ignore\n} from 'https://esm.sh/@effect/platform@0.77.2?deps=effect@3.13.3';\n// @ts-ignore\nimport { Effect, Schedule } from 'https://esm.sh/effect@3.13.3';\n\nexport default defineFunction({\n description: 'Returns the exchange rate between two currencies.',\n\n inputSchema: S.Struct({\n from: S.String.annotations({ description: 'The source currency' }),\n to: S.String.annotations({ description: 'The target currency' }),\n }),\n\n outputSchema: S.String.annotations({ description: 'The exchange rate between the two currencies' }),\n\n handler: async ({\n event: {\n data: { from, to },\n },\n }: any) =>\n Effect.gen(function* () {\n const res = yield* HttpClientRequest.get(`https://free.ratesdb.com/v1/rates?from=${from}&to=${to}`).pipe(\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 return res.data.rates[to].toString();\n }).pipe(Effect.provide(FetchHttpClient.layer)),\n});\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { defineFunction, S } from 'dxos:functions';\n\nexport default defineFunction({\n description: 'Returns the exchange rate between two currencies.',\n\n inputSchema: S.Struct({\n from: S.String.annotations({ description: 'The source currency' }),\n to: S.String.annotations({ description: 'The target currency' }),\n }),\n\n handler: async ({\n event: {\n data: { from, to },\n },\n }: any) => {\n const res = await fetch(`https://free.ratesdb.com/v1/rates?from=${from}&to=${to}`);\n const {\n data: { rates },\n } = await res.json();\n\n return rates[to].toString();\n },\n});\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// @ts-ignore\nimport chat from './chat.ts?raw';\n// @ts-ignore\nimport chess from './chess.ts?raw';\n// @ts-ignore\nimport discord from './discord.ts?raw';\n// @ts-ignore\nimport echo from './echo.ts?raw';\n// @ts-ignore\nimport email from './email.ts?raw';\n// @ts-ignore\nimport forexEffect from './forex-effect.ts?raw';\n// @ts-ignore\nimport forex from './forex.ts?raw';\n\nconst removeHeader = (str: string) => str.split('\\n').slice(4).join('\\n');\n\nexport type Template = {\n id: string;\n name: string;\n source: string;\n presetId?: string;\n};\n\nexport const templates: Template[] = [\n {\n id: 'dxos.org/script/echo',\n name: 'Echo',\n source: removeHeader(echo),\n },\n {\n id: 'dxos.org/script/forex',\n name: 'Forex',\n source: removeHeader(forex),\n },\n {\n id: 'dxos.org/script/forex-effect',\n name: 'Forex (Effect)',\n source: removeHeader(forexEffect),\n },\n {\n id: 'dxos.org/script/gpt',\n name: 'Gpt',\n source: removeHeader(chat),\n presetId: 'dxos.org/function/gpt',\n },\n {\n id: 'dxos.org/script/chess',\n name: 'Chess',\n source: removeHeader(chess),\n presetId: 'dxos.org/function/chess',\n },\n {\n id: 'dxos.org/script/email',\n name: 'Email',\n source: removeHeader(email),\n presetId: 'dxos.org/function/email',\n },\n {\n id: 'dxos.org/script/discord',\n name: 'Discord',\n source: removeHeader(discord),\n presetId: 'dxos.org/function/discord',\n },\n];\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA,eAAA;ACAA,IAAA,gBAAA;ACAA,IAAA,kBAAA;ACAA,IAAA,eAAA;ACAA,IAAA,gBAAA;ACAA,IAAA,uBAAA;ACAA,IAAA,gBAAA;ACmBA,IAAMA,eAAe,CAACC,QAAgBA,IAAIC,MAAM,IAAA,EAAMC,MAAM,CAAA,EAAGC,KAAK,IAAA;AAS7D,IAAMC,YAAwB;EACnC;IACEC,IAAI;IACJC,MAAM;IACNC,QAAQR,aAAaS,YAAAA;EACvB;EACA;IACEH,IAAI;IACJC,MAAM;IACNC,QAAQR,aAAaU,aAAAA;EACvB;EACA;IACEJ,IAAI;IACJC,MAAM;IACNC,QAAQR,aAAaW,oBAAAA;EACvB;EACA;IACEL,IAAI;IACJC,MAAM;IACNC,QAAQR,aAAaY,YAAAA;IACrBC,UAAU;EACZ;EACA;IACEP,IAAI;IACJC,MAAM;IACNC,QAAQR,aAAac,aAAAA;IACrBD,UAAU;EACZ;EACA;IACEP,IAAI;IACJC,MAAM;IACNC,QAAQR,aAAae,aAAAA;IACrBF,UAAU;EACZ;EACA;IACEP,IAAI;IACJC,MAAM;IACNC,QAAQR,aAAagB,eAAAA;IACrBH,UAAU;EACZ;;",
|
|
6
|
+
"names": ["removeHeader", "str", "split", "slice", "join", "templates", "id", "name", "source", "echo", "forex", "forexEffect", "chat", "presetId", "chess", "email", "discord"]
|
|
7
|
+
}
|
|
@@ -16,19 +16,19 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
19
|
+
var chunk_ALY3N6PW_exports = {};
|
|
20
|
+
__export(chunk_ALY3N6PW_exports, {
|
|
21
21
|
ScriptCapabilities: () => ScriptCapabilities
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
24
|
-
var
|
|
23
|
+
module.exports = __toCommonJS(chunk_ALY3N6PW_exports);
|
|
24
|
+
var import_chunk_5UH3F7TA = require("./chunk-5UH3F7TA.cjs");
|
|
25
25
|
var import_app_framework = require("@dxos/app-framework");
|
|
26
26
|
var ScriptCapabilities;
|
|
27
27
|
(function(ScriptCapabilities2) {
|
|
28
|
-
ScriptCapabilities2.Compiler = (0, import_app_framework.defineCapability)(`${
|
|
28
|
+
ScriptCapabilities2.Compiler = (0, import_app_framework.defineCapability)(`${import_chunk_5UH3F7TA.SCRIPT_PLUGIN}/capability/compiler`);
|
|
29
29
|
})(ScriptCapabilities || (ScriptCapabilities = {}));
|
|
30
30
|
// Annotate the CommonJS export names for ESM import in node:
|
|
31
31
|
0 && (module.exports = {
|
|
32
32
|
ScriptCapabilities
|
|
33
33
|
});
|
|
34
|
-
//# sourceMappingURL=chunk-
|
|
34
|
+
//# sourceMappingURL=chunk-ALY3N6PW.cjs.map
|
|
@@ -16,13 +16,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
19
|
+
var chunk_DJGLGRQV_exports = {};
|
|
20
|
+
__export(chunk_DJGLGRQV_exports, {
|
|
21
21
|
ScriptAction: () => ScriptAction,
|
|
22
22
|
ScriptSettingsSchema: () => ScriptSettingsSchema
|
|
23
23
|
});
|
|
24
|
-
module.exports = __toCommonJS(
|
|
25
|
-
var
|
|
24
|
+
module.exports = __toCommonJS(chunk_DJGLGRQV_exports);
|
|
25
|
+
var import_chunk_5UH3F7TA = require("./chunk-5UH3F7TA.cjs");
|
|
26
26
|
var import_AST = require("@effect/schema/AST");
|
|
27
27
|
var import_echo = require("@dxos/client/echo");
|
|
28
28
|
var import_echo_schema = require("@dxos/echo-schema");
|
|
@@ -30,7 +30,7 @@ var import_functions = require("@dxos/functions");
|
|
|
30
30
|
var import_react_ui_editor = require("@dxos/react-ui-editor");
|
|
31
31
|
var ScriptAction;
|
|
32
32
|
(function(ScriptAction2) {
|
|
33
|
-
const SCRIPT_ACTION = `${
|
|
33
|
+
const SCRIPT_ACTION = `${import_chunk_5UH3F7TA.SCRIPT_PLUGIN}/action`;
|
|
34
34
|
ScriptAction2.CreateScriptSchema = import_echo_schema.S.Struct({
|
|
35
35
|
name: import_echo_schema.S.optional(import_echo_schema.S.String),
|
|
36
36
|
// TODO(wittjosiah): Placeholder annotation?
|
|
@@ -57,4 +57,4 @@ var ScriptSettingsSchema = import_echo_schema.S.mutable(import_echo_schema.S.Str
|
|
|
57
57
|
ScriptAction,
|
|
58
58
|
ScriptSettingsSchema
|
|
59
59
|
});
|
|
60
|
-
//# sourceMappingURL=chunk-
|
|
60
|
+
//# sourceMappingURL=chunk-DJGLGRQV.cjs.map
|
|
@@ -26,15 +26,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
29
|
+
var chunk_JITODKGN_exports = {};
|
|
30
|
+
__export(chunk_JITODKGN_exports, {
|
|
31
31
|
AutomationPanel: () => AutomationPanel,
|
|
32
32
|
ScriptContainer: () => ScriptContainer,
|
|
33
33
|
ScriptSettings: () => ScriptSettings,
|
|
34
34
|
ScriptSettingsPanel: () => ScriptSettingsPanel
|
|
35
35
|
});
|
|
36
|
-
module.exports = __toCommonJS(
|
|
37
|
-
var
|
|
36
|
+
module.exports = __toCommonJS(chunk_JITODKGN_exports);
|
|
37
|
+
var import_chunk_5UH3F7TA = require("./chunk-5UH3F7TA.cjs");
|
|
38
38
|
var import_react = __toESM(require("react"));
|
|
39
39
|
var import_react_client = require("@dxos/react-client");
|
|
40
40
|
var import_react_ui = require("@dxos/react-ui");
|
|
@@ -51,7 +51,7 @@ var import_react_ui2 = require("@dxos/react-ui");
|
|
|
51
51
|
var import_schema = require("@dxos/schema");
|
|
52
52
|
var import_react3 = require("react");
|
|
53
53
|
var ScriptSettings = ({ settings }) => {
|
|
54
|
-
const { t } = (0, import_react_ui.useTranslation)(
|
|
54
|
+
const { t } = (0, import_react_ui.useTranslation)(import_chunk_5UH3F7TA.SCRIPT_PLUGIN);
|
|
55
55
|
const client = (0, import_react_client.useClient)();
|
|
56
56
|
const handleAuthenticate = async () => {
|
|
57
57
|
const { identityKey } = client.halo.identity.get();
|
|
@@ -95,7 +95,7 @@ var ScriptSettings = ({ settings }) => {
|
|
|
95
95
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-script/src/components/ScriptSettingsPanel.tsx";
|
|
96
96
|
var kebabize = (str) => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? "-" : "") + $.toLowerCase());
|
|
97
97
|
var ScriptSettingsPanel = ({ script }) => {
|
|
98
|
-
const { t } = (0, import_react_ui2.useTranslation)(
|
|
98
|
+
const { t } = (0, import_react_ui2.useTranslation)(import_chunk_5UH3F7TA.SCRIPT_PLUGIN);
|
|
99
99
|
const { dispatchPromise: dispatch } = (0, import_app_framework.useIntentDispatcher)();
|
|
100
100
|
const client = (0, import_react_client2.useClient)();
|
|
101
101
|
const space = (0, import_echo.getSpace)(script);
|
|
@@ -138,7 +138,7 @@ var ScriptSettingsPanel = ({ script }) => {
|
|
|
138
138
|
githubToken,
|
|
139
139
|
gistKey
|
|
140
140
|
]);
|
|
141
|
-
const [binding, setBinding] = (0, import_react_ui2.
|
|
141
|
+
const [binding, setBinding] = (0, import_react_ui2.useControlledState)(fn?.binding ?? "");
|
|
142
142
|
const handleBindingChange = (0, import_react2.useCallback)((event) => {
|
|
143
143
|
setBinding(event.target.value);
|
|
144
144
|
}, [
|
|
@@ -198,7 +198,19 @@ var ScriptSettingsPanel = ({ script }) => {
|
|
|
198
198
|
script,
|
|
199
199
|
githubToken
|
|
200
200
|
]);
|
|
201
|
-
return /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null,
|
|
201
|
+
return /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, /* @__PURE__ */ import_react2.default.createElement("div", {
|
|
202
|
+
role: "form",
|
|
203
|
+
className: "flex flex-col w-full p-2 gap-4"
|
|
204
|
+
}, /* @__PURE__ */ import_react2.default.createElement(import_react_ui2.Input.Root, null, /* @__PURE__ */ import_react2.default.createElement("div", {
|
|
205
|
+
role: "none",
|
|
206
|
+
className: "flex flex-col gap-1"
|
|
207
|
+
}, /* @__PURE__ */ import_react2.default.createElement(import_react_ui2.Input.Label, null, t("description label")), /* @__PURE__ */ import_react2.default.createElement(import_react_ui2.Input.TextInput, {
|
|
208
|
+
placeholder: t("description placeholder"),
|
|
209
|
+
value: script.description ?? "",
|
|
210
|
+
onChange: (event) => {
|
|
211
|
+
script.description = event.target.value;
|
|
212
|
+
}
|
|
213
|
+
})))), fn && functionUrl && /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, /* @__PURE__ */ import_react2.default.createElement(import_react_ui2.Separator, null), /* @__PURE__ */ import_react2.default.createElement("div", {
|
|
202
214
|
role: "form",
|
|
203
215
|
className: "flex flex-col w-full p-2 gap-4"
|
|
204
216
|
}, /* @__PURE__ */ import_react2.default.createElement("h2", null, t("remote function settings heading")), /* @__PURE__ */ import_react2.default.createElement(import_react_ui2.Input.Root, null, /* @__PURE__ */ import_react2.default.createElement("div", {
|
|
@@ -240,8 +252,8 @@ var ScriptSettingsPanel = ({ script }) => {
|
|
|
240
252
|
onClick: handlePublish
|
|
241
253
|
}, t(publishing ? "publishing label" : "publish label")))));
|
|
242
254
|
};
|
|
243
|
-
var AutomationPanel = (0, import_react3.lazy)(() => import("./AutomationPanel-
|
|
244
|
-
var ScriptContainer = (0, import_react3.lazy)(() => import("./ScriptContainer-
|
|
255
|
+
var AutomationPanel = (0, import_react3.lazy)(() => import("./AutomationPanel-RBQ4DODN.cjs"));
|
|
256
|
+
var ScriptContainer = (0, import_react3.lazy)(() => import("./ScriptContainer-SLARXOSU.cjs"));
|
|
245
257
|
// Annotate the CommonJS export names for ESM import in node:
|
|
246
258
|
0 && (module.exports = {
|
|
247
259
|
AutomationPanel,
|
|
@@ -249,4 +261,4 @@ var ScriptContainer = (0, import_react3.lazy)(() => import("./ScriptContainer-DO
|
|
|
249
261
|
ScriptSettings,
|
|
250
262
|
ScriptSettingsPanel
|
|
251
263
|
});
|
|
252
|
-
//# sourceMappingURL=chunk-
|
|
264
|
+
//# sourceMappingURL=chunk-JITODKGN.cjs.map
|