@dxos/plugin-script 0.7.5-labs.5f04cf6 → 0.7.5-labs.8a82073
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-OOIRJFPJ.mjs → AutomationPanel-J3SZ5L3Y.mjs} +3 -3
- package/dist/lib/browser/{ScriptContainer-T2AOMDT3.mjs → ScriptContainer-QI4NQT7V.mjs} +92 -64
- package/dist/lib/browser/ScriptContainer-QI4NQT7V.mjs.map +7 -0
- package/dist/lib/browser/artifact-3UZZBCZ2.mjs +243 -0
- package/dist/lib/browser/artifact-3UZZBCZ2.mjs.map +7 -0
- package/dist/lib/browser/{chunk-SJ4J527G.mjs → chunk-45LXDWNF.mjs} +2 -2
- package/dist/lib/browser/{chunk-ZM6T4HPR.mjs → chunk-6MOQ4BP3.mjs} +2 -2
- package/dist/lib/browser/{chunk-SIOGRRPF.mjs → chunk-F22QPQ6G.mjs} +21 -9
- package/dist/lib/browser/chunk-F22QPQ6G.mjs.map +7 -0
- package/dist/lib/browser/chunk-FVVCAWNP.mjs +21 -0
- package/dist/lib/browser/chunk-FVVCAWNP.mjs.map +7 -0
- package/dist/lib/browser/{chunk-XPGBHZ3L.mjs → chunk-N46LE7FS.mjs} +2 -2
- package/dist/lib/browser/{chunk-REL2R7SB.mjs → chunk-VIX22OMB.mjs} +11 -3
- package/dist/lib/browser/chunk-VIX22OMB.mjs.map +7 -0
- package/dist/lib/browser/{compiler-HT53ILG7.mjs → compiler-K3FNRDDN.mjs} +3 -3
- package/dist/lib/browser/index.mjs +20 -12
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/intent-resolver-CMKQTLBG.mjs +45 -0
- package/dist/lib/browser/intent-resolver-CMKQTLBG.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-GAWVYTJ5.mjs → react-surface-YR4YO746.mjs} +12 -14
- package/dist/lib/browser/react-surface-YR4YO746.mjs.map +7 -0
- package/dist/lib/browser/{settings-YQQEU3DF.mjs → settings-SZCDKHWO.mjs} +3 -3
- package/dist/lib/browser/types.mjs +2 -2
- package/dist/lib/node/{AutomationPanel-EPRDDR3A.cjs → AutomationPanel-4M55FURO.cjs} +8 -8
- package/dist/lib/node/{ScriptContainer-BV56I4OL.cjs → ScriptContainer-FSKWJR6Z.cjs} +95 -67
- package/dist/lib/node/ScriptContainer-FSKWJR6Z.cjs.map +7 -0
- package/dist/lib/node/artifact-A2QXHFGS.cjs +262 -0
- package/dist/lib/node/artifact-A2QXHFGS.cjs.map +7 -0
- package/dist/lib/node/{chunk-EFTZN5X7.cjs → chunk-5UH3F7TA.cjs} +8 -5
- package/dist/lib/node/chunk-5UH3F7TA.cjs.map +7 -0
- package/dist/lib/node/{chunk-A2DI2G4D.cjs → chunk-ALY3N6PW.cjs} +6 -6
- package/dist/lib/node/{chunk-6VKZJ4MH.cjs → chunk-DJGLGRQV.cjs} +6 -6
- package/dist/lib/node/{chunk-DQRAVZM7.cjs → chunk-IID7WUQS.cjs} +6 -6
- package/dist/lib/node/{chunk-5V3XGLTR.cjs → chunk-JSANQCTA.cjs} +24 -12
- package/dist/lib/node/chunk-JSANQCTA.cjs.map +7 -0
- package/dist/lib/node/{chunk-TJ4BTPOS.cjs → chunk-PKT5DD3O.cjs} +12 -6
- package/dist/lib/node/chunk-PKT5DD3O.cjs.map +7 -0
- package/dist/lib/node/{compiler-457ZR24G.cjs → compiler-P2HQB22H.cjs} +7 -7
- package/dist/lib/node/index.cjs +38 -30
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/{intent-resolver-SUAPE7H3.cjs → intent-resolver-V5ASU5DW.cjs} +31 -28
- package/dist/lib/node/intent-resolver-V5ASU5DW.cjs.map +7 -0
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/{react-surface-OMBMSFZT.cjs → react-surface-MFTICFI5.cjs} +23 -25
- package/dist/lib/node/react-surface-MFTICFI5.cjs.map +7 -0
- package/dist/lib/node/{settings-NGHDYAVK.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-DMLAGQS5.mjs → AutomationPanel-W6SKG35R.mjs} +3 -3
- package/dist/lib/node-esm/{ScriptContainer-3S5VHJVR.mjs → ScriptContainer-MNETNTNQ.mjs} +92 -64
- package/dist/lib/node-esm/ScriptContainer-MNETNTNQ.mjs.map +7 -0
- package/dist/lib/node-esm/artifact-RFZQ2AJJ.mjs +245 -0
- package/dist/lib/node-esm/artifact-RFZQ2AJJ.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-XUWS7OTK.mjs → chunk-CGF7EOGD.mjs} +2 -2
- package/dist/lib/node-esm/{chunk-675XSDRN.mjs → chunk-CP5LXTK5.mjs} +2 -2
- package/dist/lib/node-esm/{chunk-XPIKUBGS.mjs → chunk-FGO5DVO2.mjs} +21 -9
- package/dist/lib/node-esm/chunk-FGO5DVO2.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-JJZYWSD7.mjs → chunk-NBAL5DXN.mjs} +11 -3
- package/dist/lib/node-esm/chunk-NBAL5DXN.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-BHP545D7.mjs → chunk-P2V2Y5LV.mjs} +5 -2
- package/dist/lib/node-esm/chunk-P2V2Y5LV.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-JHGOPQVO.mjs → chunk-UNQFIERE.mjs} +2 -2
- package/dist/lib/node-esm/{compiler-PEARFTFR.mjs → compiler-PDN46H4Y.mjs} +3 -3
- package/dist/lib/node-esm/index.mjs +20 -12
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/intent-resolver-75BHFRUK.mjs +46 -0
- package/dist/lib/node-esm/intent-resolver-75BHFRUK.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{react-surface-J7NLV2V4.mjs → react-surface-NAK6LMCY.mjs} +12 -14
- package/dist/lib/node-esm/react-surface-NAK6LMCY.mjs.map +7 -0
- package/dist/lib/node-esm/{settings-XGXDY4NI.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.d.ts +11 -0
- package/dist/types/src/capabilities/artifact.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +5 -4
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/components/ScriptContainer.d.ts +2 -2
- package/dist/types/src/components/ScriptContainer.d.ts.map +1 -1
- package/dist/types/src/components/ScriptSettingsPanel.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- 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/meta.d.ts +1 -0
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/templates/echo.d.ts.map +1 -1
- package/dist/types/src/templates/forex-effect.d.ts +6 -0
- package/dist/types/src/templates/forex-effect.d.ts.map +1 -0
- package/dist/types/src/templates/forex.d.ts +1 -1
- 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/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +44 -41
- package/src/ScriptPlugin.tsx +10 -13
- package/src/capabilities/artifact.ts +219 -0
- package/src/capabilities/index.ts +1 -0
- package/src/capabilities/intent-resolver.ts +25 -22
- package/src/capabilities/react-surface.tsx +8 -8
- package/src/components/ScriptContainer.tsx +10 -5
- package/src/components/ScriptSettings/ScriptSettings.tsx +3 -3
- package/src/components/ScriptSettingsPanel.tsx +16 -2
- package/src/components/ScriptToolbar/ScriptToolbar.tsx +8 -6
- package/src/components/TypescriptEditor/TypescriptEditor.tsx +1 -1
- package/src/{components/ScriptToolbar → hooks}/deploy.ts +14 -2
- 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/meta.ts +3 -1
- package/src/templates/echo.ts +5 -1
- package/src/templates/forex-effect.ts +42 -0
- package/src/templates/forex.ts +21 -13
- package/src/templates/index.ts +7 -0
- package/src/translations.ts +2 -0
- package/dist/lib/browser/ScriptContainer-T2AOMDT3.mjs.map +0 -7
- package/dist/lib/browser/chunk-5BU5ERNU.mjs +0 -18
- package/dist/lib/browser/chunk-5BU5ERNU.mjs.map +0 -7
- package/dist/lib/browser/chunk-REL2R7SB.mjs.map +0 -7
- package/dist/lib/browser/chunk-SIOGRRPF.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-YPHT6HDZ.mjs +0 -42
- package/dist/lib/browser/intent-resolver-YPHT6HDZ.mjs.map +0 -7
- package/dist/lib/browser/react-surface-GAWVYTJ5.mjs.map +0 -7
- package/dist/lib/node/ScriptContainer-BV56I4OL.cjs.map +0 -7
- package/dist/lib/node/chunk-5V3XGLTR.cjs.map +0 -7
- package/dist/lib/node/chunk-EFTZN5X7.cjs.map +0 -7
- package/dist/lib/node/chunk-TJ4BTPOS.cjs.map +0 -7
- package/dist/lib/node/intent-resolver-SUAPE7H3.cjs.map +0 -7
- package/dist/lib/node/react-surface-OMBMSFZT.cjs.map +0 -7
- package/dist/lib/node-esm/ScriptContainer-3S5VHJVR.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-BHP545D7.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-JJZYWSD7.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-XPIKUBGS.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-SZJXQ3CW.mjs +0 -43
- package/dist/lib/node-esm/intent-resolver-SZJXQ3CW.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-J7NLV2V4.mjs.map +0 -7
- 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/dist/lib/browser/{AutomationPanel-OOIRJFPJ.mjs.map → AutomationPanel-J3SZ5L3Y.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-SJ4J527G.mjs.map → chunk-45LXDWNF.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-ZM6T4HPR.mjs.map → chunk-6MOQ4BP3.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-XPGBHZ3L.mjs.map → chunk-N46LE7FS.mjs.map} +0 -0
- /package/dist/lib/browser/{compiler-HT53ILG7.mjs.map → compiler-K3FNRDDN.mjs.map} +0 -0
- /package/dist/lib/browser/{settings-YQQEU3DF.mjs.map → settings-SZCDKHWO.mjs.map} +0 -0
- /package/dist/lib/node/{AutomationPanel-EPRDDR3A.cjs.map → AutomationPanel-4M55FURO.cjs.map} +0 -0
- /package/dist/lib/node/{chunk-A2DI2G4D.cjs.map → chunk-ALY3N6PW.cjs.map} +0 -0
- /package/dist/lib/node/{chunk-6VKZJ4MH.cjs.map → chunk-DJGLGRQV.cjs.map} +0 -0
- /package/dist/lib/node/{chunk-DQRAVZM7.cjs.map → chunk-IID7WUQS.cjs.map} +0 -0
- /package/dist/lib/node/{compiler-457ZR24G.cjs.map → compiler-P2HQB22H.cjs.map} +0 -0
- /package/dist/lib/node/{settings-NGHDYAVK.cjs.map → settings-SZFSMSKM.cjs.map} +0 -0
- /package/dist/lib/node-esm/{AutomationPanel-DMLAGQS5.mjs.map → AutomationPanel-W6SKG35R.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-XUWS7OTK.mjs.map → chunk-CGF7EOGD.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-675XSDRN.mjs.map → chunk-CP5LXTK5.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-JHGOPQVO.mjs.map → chunk-UNQFIERE.mjs.map} +0 -0
- /package/dist/lib/node-esm/{compiler-PEARFTFR.mjs.map → compiler-PDN46H4Y.mjs.map} +0 -0
- /package/dist/lib/node-esm/{settings-XGXDY4NI.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_A2QXHFGS_exports = {};
|
|
20
|
+
__export(artifact_A2QXHFGS_exports, {
|
|
21
|
+
default: () => artifact_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(artifact_A2QXHFGS_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_echo = require("@dxos/react-client/echo");
|
|
31
|
+
var import_schema = require("@dxos/schema");
|
|
32
|
+
var import_types = require("@dxos/plugin-space/types");
|
|
33
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-script/src/capabilities/artifact.ts";
|
|
34
|
+
var artifact_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-A2QXHFGS.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/capabilities/artifact.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 { create, makeRef, type Space } from '@dxos/react-client/echo';\nimport { TextType } from '@dxos/schema';\nimport { SpaceAction } from '@dxos/plugin-space/types';\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,kBAA4C;AAC5C,oBAAyB;AACzB,mBAA4B;;AAU5B,IAAA,mBAAe,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,KAA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BJ,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,21 +16,24 @@ 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: [
|
|
33
33
|
"experimental"
|
|
34
|
+
],
|
|
35
|
+
screenshots: [
|
|
36
|
+
"https://dxos.network/plugin-details-scripts-dark.png"
|
|
34
37
|
]
|
|
35
38
|
};
|
|
36
39
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -38,4 +41,4 @@ var meta = {
|
|
|
38
41
|
SCRIPT_PLUGIN,
|
|
39
42
|
meta
|
|
40
43
|
});
|
|
41
|
-
//# 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
|
+
}
|
|
@@ -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,12 +26,12 @@ 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_IID7WUQS_exports = {};
|
|
30
|
+
__export(chunk_IID7WUQS_exports, {
|
|
31
31
|
DebugPanel: () => DebugPanel
|
|
32
32
|
});
|
|
33
|
-
module.exports = __toCommonJS(
|
|
34
|
-
var
|
|
33
|
+
module.exports = __toCommonJS(chunk_IID7WUQS_exports);
|
|
34
|
+
var import_chunk_5UH3F7TA = require("./chunk-5UH3F7TA.cjs");
|
|
35
35
|
var import_react = __toESM(require("react"));
|
|
36
36
|
var import_log = require("@dxos/log");
|
|
37
37
|
var import_react_ui = require("@dxos/react-ui");
|
|
@@ -39,7 +39,7 @@ var import_react_ui_syntax_highlighter = require("@dxos/react-ui-syntax-highligh
|
|
|
39
39
|
var import_react_ui_theme = require("@dxos/react-ui-theme");
|
|
40
40
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-script/src/components/DebugPanel/DebugPanel.tsx";
|
|
41
41
|
var DebugPanel = ({ classNames, functionUrl }) => {
|
|
42
|
-
const { t } = (0, import_react_ui.useTranslation)(
|
|
42
|
+
const { t } = (0, import_react_ui.useTranslation)(import_chunk_5UH3F7TA.SCRIPT_PLUGIN);
|
|
43
43
|
const inputRef = (0, import_react.useRef)(null);
|
|
44
44
|
const [input, setInput] = (0, import_react.useState)("");
|
|
45
45
|
const [result, setResult] = (0, import_react.useState)("");
|
|
@@ -266,4 +266,4 @@ var RobotAvatar = () => /* @__PURE__ */ import_react.default.createElement(impor
|
|
|
266
266
|
0 && (module.exports = {
|
|
267
267
|
DebugPanel
|
|
268
268
|
});
|
|
269
|
-
//# sourceMappingURL=chunk-
|
|
269
|
+
//# sourceMappingURL=chunk-IID7WUQS.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_JSANQCTA_exports = {};
|
|
30
|
+
__export(chunk_JSANQCTA_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_JSANQCTA_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();
|
|
@@ -74,7 +74,7 @@ var ScriptSettings = ({ settings }) => {
|
|
|
74
74
|
}
|
|
75
75
|
]);
|
|
76
76
|
};
|
|
77
|
-
return /* @__PURE__ */ import_react.default.createElement(
|
|
77
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react_ui_form.DeprecatedFormContainer, null, /* @__PURE__ */ import_react.default.createElement(import_react_ui_form.DeprecatedFormInput, {
|
|
78
78
|
label: t("authenticate action label")
|
|
79
79
|
}, /* @__PURE__ */ import_react.default.createElement(import_react_ui.Button, {
|
|
80
80
|
onClick: handleAuthenticate
|
|
@@ -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-4M55FURO.cjs"));
|
|
256
|
+
var ScriptContainer = (0, import_react3.lazy)(() => import("./ScriptContainer-FSKWJR6Z.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-BV
|
|
|
249
261
|
ScriptSettings,
|
|
250
262
|
ScriptSettingsPanel
|
|
251
263
|
});
|
|
252
|
-
//# sourceMappingURL=chunk-
|
|
264
|
+
//# sourceMappingURL=chunk-JSANQCTA.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/ScriptSettings/ScriptSettings.tsx", "../../../src/components/ScriptSettingsPanel.tsx", "../../../src/components/index.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React from 'react';\n\nimport { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';\nimport { useClient } from '@dxos/react-client';\nimport { Button, Select, useTranslation } from '@dxos/react-ui';\nimport { type EditorInputMode, EditorInputModes } from '@dxos/react-ui-editor';\nimport { DeprecatedFormContainer, DeprecatedFormInput } from '@dxos/react-ui-form';\n\nimport { SCRIPT_PLUGIN } from '../../meta';\nimport { type ScriptSettingsProps } from '../../types';\n\nexport const ScriptSettings = ({ settings }: { settings: ScriptSettingsProps }) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n const client = useClient();\n\n // TODO(burdon): Check token.\n const handleAuthenticate = async () => {\n const { identityKey } = client.halo.identity.get()!;\n await client.halo.writeCredentials([\n {\n issuer: identityKey,\n issuanceDate: new Date(),\n subject: {\n id: identityKey,\n assertion: {\n '@type': 'dxos.halo.credentials.ServiceAccess',\n serverName: 'hub.dxos.network',\n serverKey: identityKey,\n identityKey,\n capabilities: ['composer:beta'],\n },\n },\n } satisfies Credential,\n ]);\n };\n\n return (\n <DeprecatedFormContainer>\n {/* TODO(wittjosiah): Hide outside of dev environments. */}\n <DeprecatedFormInput label={t('authenticate action label')}>\n <Button onClick={handleAuthenticate}>{t('authenticate button label')}</Button>\n </DeprecatedFormInput>\n\n <DeprecatedFormInput label={t('editor input mode label')}>\n <Select.Root\n value={settings.editorInputMode ?? 'default'}\n onValueChange={(value) => {\n settings.editorInputMode = value as EditorInputMode;\n }}\n >\n <Select.TriggerButton placeholder={t('select editor input mode placeholder')} />\n <Select.Portal>\n <Select.Content>\n <Select.Viewport>\n {EditorInputModes.map((mode) => (\n <Select.Option key={mode} value={mode}>\n {t(`settings editor input mode ${mode} label`)}\n </Select.Option>\n ))}\n </Select.Viewport>\n </Select.Content>\n </Select.Portal>\n </Select.Root>\n </DeprecatedFormInput>\n </DeprecatedFormContainer>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { Octokit } from '@octokit/core';\nimport React, { type ChangeEvent, useCallback, useEffect, useState } from 'react';\n\nimport { createIntent, SettingsAction, useIntentDispatcher } from '@dxos/app-framework';\nimport { FunctionType, type ScriptType, getInvocationUrl, getUserFunctionUrlInMetadata } from '@dxos/functions';\nimport { log } from '@dxos/log';\nimport { useClient } from '@dxos/react-client';\nimport { Filter, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';\nimport { Button, Clipboard, Input, Separator, useControlledState, useTranslation } from '@dxos/react-ui';\nimport { AccessTokenType } from '@dxos/schema';\n\nimport { SCRIPT_PLUGIN } from '../meta';\n\n// TODO(wittjosiah): Factor out.\n// From https://stackoverflow.com/a/67243723/2804332\nconst kebabize = (str: string) => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? '-' : '') + $.toLowerCase());\n\nexport type ScriptSettingsPanelProps = {\n script: ScriptType;\n};\n\nexport const ScriptSettingsPanel = ({ script }: ScriptSettingsPanelProps) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n const { dispatchPromise: dispatch } = useIntentDispatcher();\n const client = useClient();\n const space = getSpace(script);\n const [fn] = useQuery(space, Filter.schema(FunctionType, { source: script }));\n const [githubToken] = useQuery(space, Filter.schema(AccessTokenType, { source: 'github.com' }));\n const gistKey = getMeta(script).keys.find(({ source }) => source === 'github.com');\n const [gistUrl, setGistUrl] = useState<string | undefined>();\n\n useEffect(() => {\n const token = githubToken?.token;\n const gistId = gistKey?.id;\n if (!token || !gistId) {\n setGistUrl(undefined);\n return;\n }\n\n const timeout = setTimeout(async () => {\n try {\n const octokit = new Octokit({ auth: githubToken.token });\n const response = await octokit.request('GET /gists/{gist_id}', {\n gist_id: gistId,\n });\n setGistUrl(response.data.html_url);\n } catch (err) {\n log.catch(err);\n setGistUrl(undefined);\n }\n });\n\n return () => clearTimeout(timeout);\n }, [githubToken, gistKey]);\n\n const [binding, setBinding] = useControlledState(fn?.binding ?? '');\n const handleBindingChange = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n setBinding(event.target.value);\n },\n [setBinding],\n );\n const handleBindingBlur = useCallback(() => {\n fn.binding = binding;\n }, [fn, binding]);\n\n const functionPath = fn && getUserFunctionUrlInMetadata(getMeta(fn));\n const functionUrl =\n functionPath &&\n getInvocationUrl(functionPath, client.config.values.runtime?.services?.edge?.url ?? '', {\n spaceId: space?.id,\n });\n\n const handleOpenTokenManager = useCallback(\n () => dispatch(createIntent(SettingsAction.Open, { plugin: 'dxos.org/plugin/token-manager' })),\n [],\n );\n\n const [publishing, setPublishing] = useState(false);\n const handlePublish = useCallback(async () => {\n setPublishing(true);\n const octokit = new Octokit({ auth: githubToken.token });\n const source = await script.source.load();\n const filename = script.name ? kebabize(script.name) : 'composer-script';\n const files = { [`${filename}.ts`]: { content: source.content } };\n\n try {\n // TODO(wittjosiah): Factor out to intent.\n const meta = getMeta(script);\n const githubKey = meta.keys.find(({ source }) => source === 'github.com');\n const gistId = githubKey?.id;\n if (gistId) {\n await octokit.request('PATCH /gists/{gist_id}', {\n gist_id: gistId,\n files,\n });\n } else {\n const response = await octokit.request('POST /gists', {\n public: true,\n files,\n });\n if (response.data.id) {\n meta.keys.push({ source: 'github.com', id: response.data.id });\n }\n }\n } finally {\n setPublishing(false);\n }\n }, [script, githubToken]);\n\n return (\n <>\n <div role='form' className='flex flex-col w-full p-2 gap-4'>\n <Input.Root>\n <div role='none' className='flex flex-col gap-1'>\n <Input.Label>{t('description label')}</Input.Label>\n <Input.TextInput\n placeholder={t('description placeholder')}\n value={script.description ?? ''}\n onChange={(event) => {\n script.description = event.target.value;\n }}\n />\n </div>\n </Input.Root>\n </div>\n {fn && functionUrl && (\n <>\n <Separator />\n <div role='form' className='flex flex-col w-full p-2 gap-4'>\n <h2>{t('remote function settings heading')}</h2>\n <Input.Root>\n <div role='none' className='flex flex-col gap-1'>\n <Input.Label>{t('function url label')}</Input.Label>\n <div role='none' className='flex gap-1'>\n <Input.TextInput\n disabled\n value={functionUrl}\n onChange={(event) => {\n fn.name = event.target.value;\n }}\n />\n <Clipboard.IconButton value={functionUrl} />\n </div>\n </div>\n </Input.Root>\n <Input.Root>\n <div role='none' className='flex flex-col gap-1'>\n <Input.Label>{t('function binding label')}</Input.Label>\n <Input.TextInput\n placeholder={t('function binding placeholder')}\n value={binding}\n onChange={handleBindingChange}\n onBlur={handleBindingBlur}\n />\n </div>\n </Input.Root>\n </div>\n </>\n )}\n <Separator />\n <div className='flex flex-col w-full p-2 gap-4'>\n <div>\n <h2>{t('script publish settings label')}</h2>\n <p className='text-description text-sm'>{t('script publish settings description')}</p>\n </div>\n {!githubToken && (\n <div className='flex flex-col items-center justify-center gap-2'>\n <span>{t('no github token label')}</span>\n <Button onClick={handleOpenTokenManager}>{t('open token manager label')}</Button>\n </div>\n )}\n {githubToken && (\n <div className='flex justify-end gap-2'>\n {gistUrl && <Clipboard.IconButton value={gistUrl} />}\n <Button disabled={publishing} onClick={handlePublish}>\n {t(publishing ? 'publishing label' : 'publish label')}\n </Button>\n </div>\n )}\n </div>\n </>\n );\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { lazy } from 'react';\n\nexport * from './ScriptSettings';\nexport * from './ScriptSettingsPanel';\n\nexport const AutomationPanel = lazy(() => import('./AutomationPanel'));\nexport const ScriptContainer = lazy(() => import('./ScriptContainer'));\n"],
|
|
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EAAE,uBAAA,CAAA,GACToB,8BAAAA,QAAA,cAACI,iBAAAA,QAAAA;IAAOC,SAASiF;KAAyB1G,EAAE,0BAAA,CAAA,CAAA,GAG/C4D,eACCxC,8BAAAA,QAAA,cAACuG,OAAAA;IAAIE,WAAU;KACZ3D,WAAW9C,8BAAAA,QAAA,cAACkH,2BAAUC,YAAU;IAAC3G,OAAOsC;MACzC9C,8BAAAA,QAAA,cAACI,iBAAAA,QAAAA;IAAO6G,UAAUtB;IAAYtF,SAASwF;KACpCjH,EAAE+G,aAAa,qBAAqB,eAAA,CAAA,CAAA,CAAA,CAAA;AAOnD;AClLO,IAAM4B,sBAAkBC,oBAAK,MAAM,OAAO,gCAAA,CAAA;AAC1C,IAAMC,sBAAkBD,oBAAK,MAAM,OAAO,gCAAA,CAAA;",
|
|
6
|
+
"names": ["import_react", "import_react_client", "import_react_ui", "ScriptSettings", "settings", "t", "useTranslation", "SCRIPT_PLUGIN", "client", "useClient", "handleAuthenticate", "identityKey", "halo", "identity", "get", "writeCredentials", "issuer", "issuanceDate", "Date", "subject", "id", "assertion", "serverName", "serverKey", "capabilities", "React", "DeprecatedFormContainer", "DeprecatedFormInput", "label", "Button", "onClick", "Select", "Root", "value", "editorInputMode", "onValueChange", "TriggerButton", "placeholder", "Portal", "Content", "Viewport", "EditorInputModes", "map", "mode", "Option", "key", "kebabize", "str", "replace", "$", "ofs", "toLowerCase", "ScriptSettingsPanel", "script", "dispatchPromise", "dispatch", "useIntentDispatcher", "space", "getSpace", "fn", "useQuery", "Filter", "schema", "FunctionType", "source", "githubToken", "AccessTokenType", "gistKey", "getMeta", "keys", "find", "gistUrl", "setGistUrl", "useState", "useEffect", "token", "gistId", "undefined", "timeout", "setTimeout", "octokit", "Octokit", "auth", "response", "request", "gist_id", "data", "html_url", "err", "log", "catch", "clearTimeout", "binding", "setBinding", "useControlledState", "handleBindingChange", "useCallback", "event", "target", "handleBindingBlur", "functionPath", "getUserFunctionUrlInMetadata", "functionUrl", "getInvocationUrl", "config", "values", "runtime", "services", "edge", "url", "spaceId", "handleOpenTokenManager", "createIntent", "SettingsAction", "Open", "plugin", "publishing", "setPublishing", "handlePublish", "load", "filename", "name", "files", "content", "meta", "githubKey", "public", "push", "div", "role", "className", "Input", "Label", "TextInput", "description", "onChange", "Separator", "h2", "disabled", "Clipboard", "IconButton", "onBlur", "p", "span", "AutomationPanel", "lazy", "ScriptContainer"]
|
|
7
|
+
}
|
|
@@ -16,16 +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_PKT5DD3O_exports = {};
|
|
20
|
+
__export(chunk_PKT5DD3O_exports, {
|
|
21
21
|
templates: () => templates
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
23
|
+
module.exports = __toCommonJS(chunk_PKT5DD3O_exports);
|
|
24
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
25
|
var chess_default = "//\n// Copyright 2024 DXOS.org\n//\n\n// @ts-ignore\nimport { Chess } from 'https://esm.sh/chess.js@0.13.1';\n\n/**\n * Plays a random move in a chess game.\n */\nexport default async ({\n event: {\n data: { request },\n },\n context: { space },\n}: any) => {\n const {\n data: {\n objects: [gameId],\n player = 'b',\n },\n } = await request.json();\n\n const { pgn } = await space.crud.query({ id: gameId }).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.crud.update({ id: gameId }, { pgn: newPgn });\n return new Response(game.ascii());\n};\n";
|
|
26
|
-
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 ?? {}), {
|
|
26
|
+
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";
|
|
27
27
|
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";
|
|
28
|
-
var forex_default = "//\n// Copyright
|
|
28
|
+
var forex_default = "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { defineFunction, S } from 'dxos:functions';\n\n/**\n * Returns the exchange rate between two currencies.\n */\nexport default defineFunction({\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";
|
|
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 HttpClientResponse,\n HttpClientError,\n // @ts-ignore\n} from 'https://esm.sh/@effect/platform@0.61.0?deps=effect@3.6.0';\n// @ts-ignore\nimport type { Cause } from 'https://esm.sh/effect@3.6.0';\n// @ts-ignore\nimport { Effect, Schedule } from 'https://esm.sh/effect@3.6.0';\n\n/**\n * Returns the exchange rate between two currencies.\n */\nexport default defineFunction({\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,\n\n handler: async ({\n event: {\n data: { from, to },\n },\n }: any) =>\n HttpClientRequest.get(`https://free.ratesdb.com/v1/rates?from=${from}&to=${to}`).pipe(\n HttpClient.fetchOk,\n HttpClientResponse.json,\n Effect.timeout('1 second'),\n Effect.retry(Schedule.exponential(1000).pipe(Schedule.compose(Schedule.recurs(3)))),\n Effect.map(({ data: { rates } }: any) => rates[to].toString()),\n ),\n});\n";
|
|
29
30
|
var removeHeader = (str) => str.split("\n").slice(4).join("\n");
|
|
30
31
|
var templates = [
|
|
31
32
|
{
|
|
@@ -38,6 +39,11 @@ var templates = [
|
|
|
38
39
|
name: "Forex",
|
|
39
40
|
source: removeHeader(forex_default)
|
|
40
41
|
},
|
|
42
|
+
{
|
|
43
|
+
id: "dxos.org/script/forex-effect",
|
|
44
|
+
name: "Forex (Effect)",
|
|
45
|
+
source: removeHeader(forex_effect_default)
|
|
46
|
+
},
|
|
41
47
|
{
|
|
42
48
|
id: "dxos.org/script/gpt",
|
|
43
49
|
name: "Gpt",
|
|
@@ -61,4 +67,4 @@ var templates = [
|
|
|
61
67
|
0 && (module.exports = {
|
|
62
68
|
templates
|
|
63
69
|
});
|
|
64
|
-
//# sourceMappingURL=chunk-
|
|
70
|
+
//# sourceMappingURL=chunk-PKT5DD3O.cjs.map
|