@dxos/plugin-script 0.8.2-main.fbd8ed0 → 0.8.2-staging.4d6ad0f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/DeploymentDialog-NLWQHNKE.mjs +12 -0
- package/dist/lib/browser/ScriptContainer-Q2K5FJSC.mjs +272 -0
- package/dist/lib/browser/ScriptContainer-Q2K5FJSC.mjs.map +7 -0
- package/dist/lib/browser/{app-graph-builder-BFBTQPSP.mjs → app-graph-builder-V3HPXJAD.mjs} +2 -2
- package/dist/lib/browser/{artifact-definition-PD4UAAQZ.mjs → artifact-definition-L3AIY4XA.mjs} +15 -24
- package/dist/lib/browser/artifact-definition-L3AIY4XA.mjs.map +7 -0
- package/dist/lib/browser/{chunk-INL55MFV.mjs → chunk-6T64VQHF.mjs} +2 -2
- package/dist/lib/browser/{chunk-KJMVDGRB.mjs → chunk-6ZHHWU6S.mjs} +3 -3
- package/dist/lib/browser/{chunk-KJMVDGRB.mjs.map → chunk-6ZHHWU6S.mjs.map} +1 -1
- package/dist/lib/browser/chunk-74DEDPHT.mjs +530 -0
- package/dist/lib/{node-esm/chunk-A3TXZHGD.mjs.map → browser/chunk-74DEDPHT.mjs.map} +1 -1
- package/dist/lib/browser/chunk-BTEFFA4C.mjs +153 -0
- package/dist/lib/{node-esm/chunk-V733VFCJ.mjs.map → browser/chunk-BTEFFA4C.mjs.map} +1 -1
- package/dist/lib/browser/{chunk-FFDJENAN.mjs → chunk-JQOAZJTK.mjs} +4 -4
- package/dist/lib/browser/chunk-M6QMJBKQ.mjs +87 -0
- package/dist/lib/browser/chunk-M6QMJBKQ.mjs.map +7 -0
- package/dist/lib/browser/{chunk-6MLJJI73.mjs → chunk-WB3X5Z7Q.mjs} +7 -7
- package/dist/lib/browser/chunk-WB3X5Z7Q.mjs.map +7 -0
- package/dist/lib/browser/{chunk-A4VOGQ2P.mjs → chunk-YSQMXTYO.mjs} +3 -3
- package/dist/lib/{node-esm/chunk-HKJUN636.mjs.map → browser/chunk-YSQMXTYO.mjs.map} +1 -1
- package/dist/lib/browser/{compiler-O4FJK7RR.mjs → compiler-W4BYJYTL.mjs} +3 -3
- package/dist/lib/browser/compiler-W4BYJYTL.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +13 -13
- package/dist/lib/browser/index.mjs.map +1 -1
- package/dist/lib/browser/{intent-resolver-SXO6X6XQ.mjs → intent-resolver-U5YRUE7W.mjs} +7 -7
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-TZGE7EGC.mjs → react-surface-3MSPT54G.mjs} +9 -9
- package/dist/lib/browser/{settings-EOKSUGB6.mjs → settings-FU7NTENS.mjs} +3 -3
- package/dist/lib/browser/types.mjs +2 -2
- package/dist/lib/node/{DeploymentDialog-43SI7XFL.cjs → DeploymentDialog-PC5AL3BB.cjs} +10 -10
- package/dist/lib/node/DeploymentDialog-PC5AL3BB.cjs.map +7 -0
- package/dist/lib/node/ScriptContainer-56SH6R24.cjs +289 -0
- package/dist/lib/node/ScriptContainer-56SH6R24.cjs.map +7 -0
- package/dist/lib/node/{app-graph-builder-IKOX7GHW.cjs → app-graph-builder-YE4OM4OC.cjs} +9 -9
- package/dist/lib/node/{artifact-definition-C644EAYM.cjs → artifact-definition-6BD6CVOV.cjs} +23 -32
- package/dist/lib/node/artifact-definition-6BD6CVOV.cjs.map +7 -0
- package/dist/lib/node/chunk-5LHP5EUJ.cjs +557 -0
- package/dist/lib/node/{chunk-HPBQHRM3.cjs.map → chunk-5LHP5EUJ.cjs.map} +1 -1
- package/dist/lib/node/chunk-BYLHJ26I.cjs +91 -0
- package/dist/lib/node/chunk-BYLHJ26I.cjs.map +7 -0
- package/dist/lib/node/{chunk-SXJGHLK6.cjs → chunk-HCRW6T3G.cjs} +8 -8
- package/dist/lib/node/chunk-HCRW6T3G.cjs.map +7 -0
- package/dist/lib/node/{chunk-7NNN3IUQ.cjs → chunk-NRZJV5SV.cjs} +16 -16
- package/dist/lib/node/{chunk-NO5Y74F3.cjs → chunk-QG2X6J74.cjs} +6 -6
- package/dist/lib/node/{chunk-NO5Y74F3.cjs.map → chunk-QG2X6J74.cjs.map} +1 -1
- package/dist/lib/node/chunk-RARNZD62.cjs +179 -0
- package/dist/lib/node/{chunk-VHSIOCS5.cjs.map → chunk-RARNZD62.cjs.map} +1 -1
- package/dist/lib/node/{chunk-K7PPLRVQ.cjs → chunk-V6L73D7S.cjs} +6 -6
- package/dist/lib/node/{chunk-KFJQVOGS.cjs → chunk-ZEV3VARQ.cjs} +7 -7
- package/dist/lib/node/{chunk-KFJQVOGS.cjs.map → chunk-ZEV3VARQ.cjs.map} +1 -1
- package/dist/lib/node/{compiler-FBC6ELQN.cjs → compiler-TFSJRLL4.cjs} +7 -7
- package/dist/lib/node/{compiler-FBC6ELQN.cjs.map → compiler-TFSJRLL4.cjs.map} +3 -3
- package/dist/lib/node/index.cjs +38 -38
- package/dist/lib/node/index.cjs.map +1 -1
- package/dist/lib/node/{intent-resolver-PDSMZM2T.cjs → intent-resolver-7SF26VGC.cjs} +15 -15
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/{react-surface-BHHJQZ7P.cjs → react-surface-L6RS7BT2.cjs} +31 -31
- package/dist/lib/node/{settings-425QHVGC.cjs → settings-RRCQ7ZQD.cjs} +9 -9
- package/dist/lib/node/types.cjs +5 -5
- package/dist/lib/node/types.cjs.map +1 -1
- package/dist/lib/node-esm/{DeploymentDialog-2RRUJEBC.mjs → DeploymentDialog-QHB2BGNJ.mjs} +5 -5
- package/dist/lib/node-esm/ScriptContainer-6RCZ43TI.mjs +273 -0
- package/dist/lib/node-esm/ScriptContainer-6RCZ43TI.mjs.map +7 -0
- package/dist/lib/node-esm/{app-graph-builder-KZGKGSP6.mjs → app-graph-builder-4CN7URJQ.mjs} +2 -2
- package/dist/lib/node-esm/{artifact-definition-J6UM6BQF.mjs → artifact-definition-PPV2XKU7.mjs} +15 -24
- package/dist/lib/node-esm/artifact-definition-PPV2XKU7.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-25GOLUXY.mjs +154 -0
- package/dist/lib/{browser/chunk-YNOCAJYT.mjs.map → node-esm/chunk-25GOLUXY.mjs.map} +1 -1
- package/dist/lib/node-esm/{chunk-HKJUN636.mjs → chunk-2KJYPUQD.mjs} +3 -3
- package/dist/lib/{browser/chunk-A4VOGQ2P.mjs.map → node-esm/chunk-2KJYPUQD.mjs.map} +1 -1
- package/dist/lib/node-esm/{chunk-F47OE6ZM.mjs → chunk-47MABIVX.mjs} +2 -2
- package/dist/lib/node-esm/{chunk-H7FRB3M7.mjs → chunk-AEB5TPEW.mjs} +3 -3
- package/dist/lib/node-esm/{chunk-H7FRB3M7.mjs.map → chunk-AEB5TPEW.mjs.map} +1 -1
- package/dist/lib/node-esm/chunk-KOO76P2Y.mjs +531 -0
- package/dist/lib/{browser/chunk-BONEXAIK.mjs.map → node-esm/chunk-KOO76P2Y.mjs.map} +1 -1
- package/dist/lib/node-esm/{chunk-VMQPOPKV.mjs → chunk-UESZKXLR.mjs} +7 -7
- package/dist/lib/node-esm/chunk-UESZKXLR.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-NYA7KDN6.mjs → chunk-WD7OFSM3.mjs} +4 -4
- package/dist/lib/node-esm/chunk-Z44O2YIK.mjs +89 -0
- package/dist/lib/node-esm/chunk-Z44O2YIK.mjs.map +7 -0
- package/dist/lib/node-esm/{compiler-3NG4T5LH.mjs → compiler-7PQ4D43R.mjs} +3 -3
- package/dist/lib/{browser/compiler-O4FJK7RR.mjs.map → node-esm/compiler-7PQ4D43R.mjs.map} +3 -3
- package/dist/lib/node-esm/index.mjs +13 -13
- package/dist/lib/node-esm/index.mjs.map +1 -1
- package/dist/lib/node-esm/{intent-resolver-WSAVLQY5.mjs → intent-resolver-3APO7YDF.mjs} +7 -7
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{react-surface-W7BM4PDK.mjs → react-surface-S5LHD3IA.mjs} +9 -9
- package/dist/lib/node-esm/{settings-BWSKKIVQ.mjs → settings-NKNC32QC.mjs} +3 -3
- package/dist/lib/node-esm/types.mjs +2 -2
- package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -1
- package/dist/types/src/compiler/compiler.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -1
- package/dist/types/src/templates/discord.d.ts.map +1 -1
- package/dist/types/src/types.d.ts.map +1 -1
- package/package.json +51 -51
- package/src/capabilities/artifact-definition.ts +10 -11
- package/src/compiler/compiler.ts +3 -3
- package/src/components/ScriptToolbar/ScriptToolbar.tsx +19 -16
- package/src/components/TypescriptEditor/TypescriptEditor.tsx +0 -6
- package/src/meta.ts +2 -2
- package/src/templates/chat.ts +1 -1
- package/src/templates/chess.ts +1 -1
- package/src/templates/data-generator.ts +1 -1
- package/src/templates/discord.ts +7 -5
- package/src/templates/forex-effect.ts +2 -2
- package/src/templates/gmail.ts +6 -4
- package/src/types.ts +2 -2
- package/dist/lib/browser/DeploymentDialog-W7PY33VN.mjs +0 -12
- package/dist/lib/browser/ScriptContainer-6DYV7D65.mjs +0 -260
- package/dist/lib/browser/ScriptContainer-6DYV7D65.mjs.map +0 -7
- package/dist/lib/browser/artifact-definition-PD4UAAQZ.mjs.map +0 -7
- package/dist/lib/browser/chunk-6MLJJI73.mjs.map +0 -7
- package/dist/lib/browser/chunk-BONEXAIK.mjs +0 -480
- package/dist/lib/browser/chunk-RTVU4RZW.mjs +0 -87
- package/dist/lib/browser/chunk-RTVU4RZW.mjs.map +0 -7
- package/dist/lib/browser/chunk-YNOCAJYT.mjs +0 -147
- package/dist/lib/node/DeploymentDialog-43SI7XFL.cjs.map +0 -7
- package/dist/lib/node/ScriptContainer-H56OW5FC.cjs +0 -277
- package/dist/lib/node/ScriptContainer-H56OW5FC.cjs.map +0 -7
- package/dist/lib/node/artifact-definition-C644EAYM.cjs.map +0 -7
- package/dist/lib/node/chunk-HPBQHRM3.cjs +0 -507
- package/dist/lib/node/chunk-SXJGHLK6.cjs.map +0 -7
- package/dist/lib/node/chunk-VHSIOCS5.cjs +0 -173
- package/dist/lib/node/chunk-VNSZBEJW.cjs +0 -91
- package/dist/lib/node/chunk-VNSZBEJW.cjs.map +0 -7
- package/dist/lib/node-esm/ScriptContainer-762FHDZ4.mjs +0 -261
- package/dist/lib/node-esm/ScriptContainer-762FHDZ4.mjs.map +0 -7
- package/dist/lib/node-esm/artifact-definition-J6UM6BQF.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-A3TXZHGD.mjs +0 -481
- package/dist/lib/node-esm/chunk-V733VFCJ.mjs +0 -148
- package/dist/lib/node-esm/chunk-VMQPOPKV.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-YCTECQLY.mjs +0 -89
- package/dist/lib/node-esm/chunk-YCTECQLY.mjs.map +0 -7
- package/dist/lib/node-esm/compiler-3NG4T5LH.mjs.map +0 -7
- /package/dist/lib/browser/{DeploymentDialog-W7PY33VN.mjs.map → DeploymentDialog-NLWQHNKE.mjs.map} +0 -0
- /package/dist/lib/browser/{app-graph-builder-BFBTQPSP.mjs.map → app-graph-builder-V3HPXJAD.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-INL55MFV.mjs.map → chunk-6T64VQHF.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-FFDJENAN.mjs.map → chunk-JQOAZJTK.mjs.map} +0 -0
- /package/dist/lib/browser/{intent-resolver-SXO6X6XQ.mjs.map → intent-resolver-U5YRUE7W.mjs.map} +0 -0
- /package/dist/lib/browser/{react-surface-TZGE7EGC.mjs.map → react-surface-3MSPT54G.mjs.map} +0 -0
- /package/dist/lib/browser/{settings-EOKSUGB6.mjs.map → settings-FU7NTENS.mjs.map} +0 -0
- /package/dist/lib/node/{app-graph-builder-IKOX7GHW.cjs.map → app-graph-builder-YE4OM4OC.cjs.map} +0 -0
- /package/dist/lib/node/{chunk-7NNN3IUQ.cjs.map → chunk-NRZJV5SV.cjs.map} +0 -0
- /package/dist/lib/node/{chunk-K7PPLRVQ.cjs.map → chunk-V6L73D7S.cjs.map} +0 -0
- /package/dist/lib/node/{intent-resolver-PDSMZM2T.cjs.map → intent-resolver-7SF26VGC.cjs.map} +0 -0
- /package/dist/lib/node/{react-surface-BHHJQZ7P.cjs.map → react-surface-L6RS7BT2.cjs.map} +0 -0
- /package/dist/lib/node/{settings-425QHVGC.cjs.map → settings-RRCQ7ZQD.cjs.map} +0 -0
- /package/dist/lib/node-esm/{DeploymentDialog-2RRUJEBC.mjs.map → DeploymentDialog-QHB2BGNJ.mjs.map} +0 -0
- /package/dist/lib/node-esm/{app-graph-builder-KZGKGSP6.mjs.map → app-graph-builder-4CN7URJQ.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-F47OE6ZM.mjs.map → chunk-47MABIVX.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-NYA7KDN6.mjs.map → chunk-WD7OFSM3.mjs.map} +0 -0
- /package/dist/lib/node-esm/{intent-resolver-WSAVLQY5.mjs.map → intent-resolver-3APO7YDF.mjs.map} +0 -0
- /package/dist/lib/node-esm/{react-surface-W7BM4PDK.mjs.map → react-surface-S5LHD3IA.mjs.map} +0 -0
- /package/dist/lib/node-esm/{settings-BWSKKIVQ.mjs.map → settings-NKNC32QC.mjs.map} +0 -0
|
@@ -1,480 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SCRIPT_PLUGIN,
|
|
3
|
-
meta
|
|
4
|
-
} from "./chunk-KJMVDGRB.mjs";
|
|
5
|
-
|
|
6
|
-
// packages/plugins/plugin-script/src/components/Settings/ScriptObjectSettings.tsx
|
|
7
|
-
import { Octokit } from "@octokit/core";
|
|
8
|
-
import React, { useCallback, useEffect, useState } from "react";
|
|
9
|
-
import { createIntent, SettingsAction, useIntentDispatcher } from "@dxos/app-framework";
|
|
10
|
-
import { FunctionType, getInvocationUrl, getUserFunctionUrlInMetadata } from "@dxos/functions";
|
|
11
|
-
import { log } from "@dxos/log";
|
|
12
|
-
import { useClient } from "@dxos/react-client";
|
|
13
|
-
import { Filter, getMeta, getSpace, Ref, useQuery } from "@dxos/react-client/echo";
|
|
14
|
-
import { Button, Clipboard, Input, useControlledState, useTranslation } from "@dxos/react-ui";
|
|
15
|
-
import { DataType } from "@dxos/schema";
|
|
16
|
-
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-script/src/components/Settings/ScriptObjectSettings.tsx";
|
|
17
|
-
var ScriptObjectSettings = ({ object }) => {
|
|
18
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Binding, {
|
|
19
|
-
object
|
|
20
|
-
}), /* @__PURE__ */ React.createElement(Publishing, {
|
|
21
|
-
object
|
|
22
|
-
}));
|
|
23
|
-
};
|
|
24
|
-
var ScriptProperties = ({ object }) => {
|
|
25
|
-
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
26
|
-
return /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement(Input.Label, null, t("description label")), /* @__PURE__ */ React.createElement(Input.TextInput, {
|
|
27
|
-
placeholder: t("description placeholder"),
|
|
28
|
-
value: object.description ?? "",
|
|
29
|
-
onChange: (event) => {
|
|
30
|
-
object.description = event.target.value;
|
|
31
|
-
}
|
|
32
|
-
}));
|
|
33
|
-
};
|
|
34
|
-
var Binding = ({ object }) => {
|
|
35
|
-
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
36
|
-
const client = useClient();
|
|
37
|
-
const space = getSpace(object);
|
|
38
|
-
const [fn] = useQuery(space, Filter.type(FunctionType, {
|
|
39
|
-
source: Ref.make(object)
|
|
40
|
-
}));
|
|
41
|
-
const functionPath = fn && getUserFunctionUrlInMetadata(getMeta(fn));
|
|
42
|
-
const functionUrl = functionPath && getInvocationUrl(functionPath, client.config.values.runtime?.services?.edge?.url ?? "", {
|
|
43
|
-
spaceId: space?.id
|
|
44
|
-
});
|
|
45
|
-
const [binding, setBinding] = useControlledState(fn?.binding ?? "");
|
|
46
|
-
const handleBindingChange = useCallback((event) => {
|
|
47
|
-
setBinding(event.target.value);
|
|
48
|
-
}, [
|
|
49
|
-
setBinding
|
|
50
|
-
]);
|
|
51
|
-
const handleBindingBlur = useCallback(() => {
|
|
52
|
-
fn.binding = binding;
|
|
53
|
-
}, [
|
|
54
|
-
fn,
|
|
55
|
-
binding
|
|
56
|
-
]);
|
|
57
|
-
if (!fn || !functionUrl) {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
61
|
-
role: "form",
|
|
62
|
-
className: "flex flex-col p-2 gap-2"
|
|
63
|
-
}, /* @__PURE__ */ React.createElement("h2", null, t("remote function settings heading")), /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement("div", {
|
|
64
|
-
role: "none",
|
|
65
|
-
className: "flex flex-col gap-1"
|
|
66
|
-
}, /* @__PURE__ */ React.createElement(Input.Label, null, t("function url label")), /* @__PURE__ */ React.createElement("div", {
|
|
67
|
-
role: "none",
|
|
68
|
-
className: "flex gap-1"
|
|
69
|
-
}, /* @__PURE__ */ React.createElement(Input.TextInput, {
|
|
70
|
-
disabled: true,
|
|
71
|
-
value: functionUrl,
|
|
72
|
-
onChange: (event) => {
|
|
73
|
-
fn.name = event.target.value;
|
|
74
|
-
}
|
|
75
|
-
}), /* @__PURE__ */ React.createElement(Clipboard.IconButton, {
|
|
76
|
-
value: functionUrl
|
|
77
|
-
})))), /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement("div", {
|
|
78
|
-
role: "none",
|
|
79
|
-
className: "flex flex-col gap-1"
|
|
80
|
-
}, /* @__PURE__ */ React.createElement(Input.Label, null, t("function binding label")), /* @__PURE__ */ React.createElement(Input.TextInput, {
|
|
81
|
-
placeholder: t("function binding placeholder"),
|
|
82
|
-
value: binding,
|
|
83
|
-
onChange: handleBindingChange,
|
|
84
|
-
onBlur: handleBindingBlur
|
|
85
|
-
}))));
|
|
86
|
-
};
|
|
87
|
-
var Publishing = ({ object }) => {
|
|
88
|
-
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
89
|
-
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
90
|
-
const space = getSpace(object);
|
|
91
|
-
const [githubToken] = useQuery(space, Filter.type(DataType.AccessToken, {
|
|
92
|
-
source: "github.com"
|
|
93
|
-
}));
|
|
94
|
-
const gistKey = getMeta(object).keys.find(({ source }) => source === "github.com");
|
|
95
|
-
const [gistUrl, setGistUrl] = useState();
|
|
96
|
-
useEffect(() => {
|
|
97
|
-
const token = githubToken?.token;
|
|
98
|
-
const gistId = gistKey?.id;
|
|
99
|
-
if (!token || !gistId) {
|
|
100
|
-
setGistUrl(void 0);
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const timeout = setTimeout(async () => {
|
|
104
|
-
try {
|
|
105
|
-
const octokit = new Octokit({
|
|
106
|
-
auth: githubToken.token
|
|
107
|
-
});
|
|
108
|
-
const response = await octokit.request("GET /gists/{gist_id}", {
|
|
109
|
-
gist_id: gistId
|
|
110
|
-
});
|
|
111
|
-
setGistUrl(response.data.html_url);
|
|
112
|
-
} catch (err) {
|
|
113
|
-
log.catch(err, void 0, {
|
|
114
|
-
F: __dxlog_file,
|
|
115
|
-
L: 135,
|
|
116
|
-
S: void 0,
|
|
117
|
-
C: (f, a) => f(...a)
|
|
118
|
-
});
|
|
119
|
-
setGistUrl(void 0);
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
return () => clearTimeout(timeout);
|
|
123
|
-
}, [
|
|
124
|
-
githubToken,
|
|
125
|
-
gistKey
|
|
126
|
-
]);
|
|
127
|
-
const handleOpenTokenManager = useCallback(() => dispatch(createIntent(SettingsAction.Open, {
|
|
128
|
-
plugin: "dxos.org/plugin/token-manager"
|
|
129
|
-
})), []);
|
|
130
|
-
const [publishing, setPublishing] = useState(false);
|
|
131
|
-
const handlePublish = useCallback(async () => {
|
|
132
|
-
setPublishing(true);
|
|
133
|
-
const octokit = new Octokit({
|
|
134
|
-
auth: githubToken.token
|
|
135
|
-
});
|
|
136
|
-
const source = await object.source.load();
|
|
137
|
-
const filename = object.name ? kebabize(object.name) : "composer-script";
|
|
138
|
-
const files = {
|
|
139
|
-
[`${filename}.ts`]: {
|
|
140
|
-
content: source.content
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
try {
|
|
144
|
-
const meta2 = getMeta(object);
|
|
145
|
-
const githubKey = meta2.keys.find(({ source: source2 }) => source2 === "github.com");
|
|
146
|
-
const gistId = githubKey?.id;
|
|
147
|
-
if (gistId) {
|
|
148
|
-
await octokit.request("PATCH /gists/{gist_id}", {
|
|
149
|
-
gist_id: gistId,
|
|
150
|
-
files
|
|
151
|
-
});
|
|
152
|
-
} else {
|
|
153
|
-
const response = await octokit.request("POST /gists", {
|
|
154
|
-
public: true,
|
|
155
|
-
files
|
|
156
|
-
});
|
|
157
|
-
if (response.data.id) {
|
|
158
|
-
meta2.keys.push({
|
|
159
|
-
source: "github.com",
|
|
160
|
-
id: response.data.id
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
} finally {
|
|
165
|
-
setPublishing(false);
|
|
166
|
-
}
|
|
167
|
-
}, [
|
|
168
|
-
object,
|
|
169
|
-
githubToken
|
|
170
|
-
]);
|
|
171
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
172
|
-
className: "flex flex-col p-2 gap-4"
|
|
173
|
-
}, /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("h2", null, t("script publish settings label")), /* @__PURE__ */ React.createElement("p", {
|
|
174
|
-
className: "text-description text-sm"
|
|
175
|
-
}, t("script publish settings description"))), !githubToken && /* @__PURE__ */ React.createElement("div", {
|
|
176
|
-
className: "flex flex-col gap-2"
|
|
177
|
-
}, /* @__PURE__ */ React.createElement("span", null, t("no github token label")), /* @__PURE__ */ React.createElement(Button, {
|
|
178
|
-
onClick: handleOpenTokenManager
|
|
179
|
-
}, t("open token manager label"))), githubToken && /* @__PURE__ */ React.createElement("div", {
|
|
180
|
-
className: "flex justify-end gap-2"
|
|
181
|
-
}, gistUrl && /* @__PURE__ */ React.createElement(Clipboard.IconButton, {
|
|
182
|
-
value: gistUrl
|
|
183
|
-
}), /* @__PURE__ */ React.createElement(Button, {
|
|
184
|
-
disabled: publishing,
|
|
185
|
-
onClick: handlePublish
|
|
186
|
-
}, t(publishing ? "publishing label" : "publish label"))));
|
|
187
|
-
};
|
|
188
|
-
var kebabize = (str) => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? "-" : "") + $.toLowerCase());
|
|
189
|
-
|
|
190
|
-
// packages/plugins/plugin-script/src/components/Settings/ScriptPluginSettings.tsx
|
|
191
|
-
import React2 from "react";
|
|
192
|
-
import { useClient as useClient2 } from "@dxos/react-client";
|
|
193
|
-
import { Button as Button2, Select, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
194
|
-
import { EditorInputModes } from "@dxos/react-ui-editor";
|
|
195
|
-
import { DeprecatedFormContainer, DeprecatedFormInput } from "@dxos/react-ui-form";
|
|
196
|
-
var ScriptPluginSettings = ({ settings }) => {
|
|
197
|
-
const { t } = useTranslation2(meta.id);
|
|
198
|
-
const client = useClient2();
|
|
199
|
-
const handleAuthenticate = async () => {
|
|
200
|
-
const { identityKey } = client.halo.identity.get();
|
|
201
|
-
await client.halo.writeCredentials([
|
|
202
|
-
{
|
|
203
|
-
issuer: identityKey,
|
|
204
|
-
issuanceDate: /* @__PURE__ */ new Date(),
|
|
205
|
-
subject: {
|
|
206
|
-
id: identityKey,
|
|
207
|
-
assertion: {
|
|
208
|
-
"@type": "dxos.halo.credentials.ServiceAccess",
|
|
209
|
-
serverName: "hub.dxos.network",
|
|
210
|
-
serverKey: identityKey,
|
|
211
|
-
identityKey,
|
|
212
|
-
capabilities: [
|
|
213
|
-
"composer:beta"
|
|
214
|
-
]
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
]);
|
|
219
|
-
};
|
|
220
|
-
return /* @__PURE__ */ React2.createElement(DeprecatedFormContainer, null, /* @__PURE__ */ React2.createElement(DeprecatedFormInput, {
|
|
221
|
-
label: t("authenticate action label")
|
|
222
|
-
}, /* @__PURE__ */ React2.createElement(Button2, {
|
|
223
|
-
onClick: handleAuthenticate
|
|
224
|
-
}, t("authenticate button label"))), /* @__PURE__ */ React2.createElement(DeprecatedFormInput, {
|
|
225
|
-
label: t("editor input mode label")
|
|
226
|
-
}, /* @__PURE__ */ React2.createElement(Select.Root, {
|
|
227
|
-
value: settings.editorInputMode ?? "default",
|
|
228
|
-
onValueChange: (value) => {
|
|
229
|
-
settings.editorInputMode = value;
|
|
230
|
-
}
|
|
231
|
-
}, /* @__PURE__ */ React2.createElement(Select.TriggerButton, {
|
|
232
|
-
placeholder: t("select editor input mode placeholder")
|
|
233
|
-
}), /* @__PURE__ */ React2.createElement(Select.Portal, null, /* @__PURE__ */ React2.createElement(Select.Content, null, /* @__PURE__ */ React2.createElement(Select.Viewport, null, EditorInputModes.map((mode) => /* @__PURE__ */ React2.createElement(Select.Option, {
|
|
234
|
-
key: mode,
|
|
235
|
-
value: mode
|
|
236
|
-
}, t(`settings editor input mode ${mode} label`)))))))));
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
// packages/plugins/plugin-script/src/components/TestPanel/TestPanel.tsx
|
|
240
|
-
import React3, { forwardRef, useEffect as useEffect2, useRef, useState as useState2 } from "react";
|
|
241
|
-
import { log as log2 } from "@dxos/log";
|
|
242
|
-
import { Avatar, Icon, Input as Input2, Toolbar, useTranslation as useTranslation3 } from "@dxos/react-ui";
|
|
243
|
-
import { SyntaxHighlighter } from "@dxos/react-ui-syntax-highlighter";
|
|
244
|
-
import { errorText, mx } from "@dxos/react-ui-theme";
|
|
245
|
-
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-script/src/components/TestPanel/TestPanel.tsx";
|
|
246
|
-
var TestPanel = ({ classNames, functionUrl }) => {
|
|
247
|
-
const { t } = useTranslation3(SCRIPT_PLUGIN);
|
|
248
|
-
const inputRef = useRef(null);
|
|
249
|
-
const [input, setInput] = useState2("");
|
|
250
|
-
const [result, setResult] = useState2("");
|
|
251
|
-
const [state, setState] = useState2(null);
|
|
252
|
-
const [history, setHistory] = useState2([]);
|
|
253
|
-
const scrollerRef = useRef(null);
|
|
254
|
-
const handleScroll = () => {
|
|
255
|
-
if (scrollerRef.current) {
|
|
256
|
-
scrollerRef.current.scrollTop = scrollerRef.current.scrollHeight;
|
|
257
|
-
}
|
|
258
|
-
};
|
|
259
|
-
const controller = useRef();
|
|
260
|
-
useEffect2(() => {
|
|
261
|
-
return () => {
|
|
262
|
-
handleStop();
|
|
263
|
-
};
|
|
264
|
-
}, []);
|
|
265
|
-
const handleStop = () => {
|
|
266
|
-
controller.current?.abort("stop");
|
|
267
|
-
controller.current = void 0;
|
|
268
|
-
};
|
|
269
|
-
const handleClear = () => {
|
|
270
|
-
handleStop();
|
|
271
|
-
setInput("");
|
|
272
|
-
setResult("");
|
|
273
|
-
setHistory([]);
|
|
274
|
-
inputRef.current?.focus();
|
|
275
|
-
};
|
|
276
|
-
const handleResponse = ({ text, data, error } = {}) => {
|
|
277
|
-
controller.current = void 0;
|
|
278
|
-
setHistory((history2) => [
|
|
279
|
-
...history2,
|
|
280
|
-
{
|
|
281
|
-
type: "response",
|
|
282
|
-
text,
|
|
283
|
-
data,
|
|
284
|
-
error
|
|
285
|
-
}
|
|
286
|
-
]);
|
|
287
|
-
setResult("");
|
|
288
|
-
setState(null);
|
|
289
|
-
handleScroll();
|
|
290
|
-
};
|
|
291
|
-
const handleRequest = async (input2) => {
|
|
292
|
-
try {
|
|
293
|
-
setState("pending");
|
|
294
|
-
let data = null;
|
|
295
|
-
if (input2.charAt(0) === "{") {
|
|
296
|
-
try {
|
|
297
|
-
const validJsonString = input2.replace(/'/g, '"').replace(/([{,]\s*)([a-zA-Z0-9_]+)(\s*:)/g, '$1"$2"$3');
|
|
298
|
-
data = JSON.parse(validJsonString);
|
|
299
|
-
input2 = JSON.stringify(data, null, 2);
|
|
300
|
-
} catch (err) {
|
|
301
|
-
inputRef.current?.focus();
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
setInput("");
|
|
306
|
-
setResult("");
|
|
307
|
-
setHistory((history2) => [
|
|
308
|
-
...history2,
|
|
309
|
-
{
|
|
310
|
-
type: "request",
|
|
311
|
-
text: input2
|
|
312
|
-
}
|
|
313
|
-
]);
|
|
314
|
-
setTimeout(() => {
|
|
315
|
-
handleScroll();
|
|
316
|
-
});
|
|
317
|
-
controller.current = new AbortController();
|
|
318
|
-
const response = await fetch(functionUrl, {
|
|
319
|
-
signal: controller.current.signal,
|
|
320
|
-
method: "POST",
|
|
321
|
-
body: input2,
|
|
322
|
-
headers: {
|
|
323
|
-
"Content-Type": data ? "application/json" : "text/plain"
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
if (!response.ok) {
|
|
327
|
-
const text2 = await response.text();
|
|
328
|
-
handleResponse({
|
|
329
|
-
error: new Error(text2 || response.statusText || String(response.status))
|
|
330
|
-
});
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
const contentType = response.headers.get("content-type");
|
|
334
|
-
if (contentType === "application/json") {
|
|
335
|
-
const data2 = await response.json();
|
|
336
|
-
handleResponse({
|
|
337
|
-
data: data2
|
|
338
|
-
});
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
setState("responding");
|
|
342
|
-
let text = "";
|
|
343
|
-
const reader = response.body.getReader();
|
|
344
|
-
const pump = async ({ done, value }) => {
|
|
345
|
-
text = text + new TextDecoder().decode(value);
|
|
346
|
-
if (!controller.current || done) {
|
|
347
|
-
handleResponse({
|
|
348
|
-
text
|
|
349
|
-
});
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
setResult(text);
|
|
353
|
-
setTimeout(() => {
|
|
354
|
-
handleScroll();
|
|
355
|
-
});
|
|
356
|
-
return reader.read().then(pump);
|
|
357
|
-
};
|
|
358
|
-
void reader.read().then(pump).catch((err) => {
|
|
359
|
-
if (err.name !== "AbortError") {
|
|
360
|
-
log2.catch(err, void 0, {
|
|
361
|
-
F: __dxlog_file2,
|
|
362
|
-
L: 147,
|
|
363
|
-
S: void 0,
|
|
364
|
-
C: (f, a) => f(...a)
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
});
|
|
368
|
-
} catch (err) {
|
|
369
|
-
if (err !== "stop") {
|
|
370
|
-
const error = err instanceof Error ? err : new Error(err);
|
|
371
|
-
handleResponse({
|
|
372
|
-
error
|
|
373
|
-
});
|
|
374
|
-
log2.catch(err, void 0, {
|
|
375
|
-
F: __dxlog_file2,
|
|
376
|
-
L: 154,
|
|
377
|
-
S: void 0,
|
|
378
|
-
C: (f, a) => f(...a)
|
|
379
|
-
});
|
|
380
|
-
} else {
|
|
381
|
-
handleResponse();
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
};
|
|
385
|
-
return /* @__PURE__ */ React3.createElement("div", {
|
|
386
|
-
className: mx("flex flex-col h-full overflow-hidden", classNames)
|
|
387
|
-
}, /* @__PURE__ */ React3.createElement(MessageThread, {
|
|
388
|
-
ref: scrollerRef,
|
|
389
|
-
state,
|
|
390
|
-
result,
|
|
391
|
-
history
|
|
392
|
-
}), /* @__PURE__ */ React3.createElement(Toolbar.Root, {
|
|
393
|
-
classNames: "p-2"
|
|
394
|
-
}, /* @__PURE__ */ React3.createElement(Input2.Root, null, /* @__PURE__ */ React3.createElement(Input2.TextInput, {
|
|
395
|
-
ref: inputRef,
|
|
396
|
-
autoFocus: true,
|
|
397
|
-
placeholder: t("function request placeholder"),
|
|
398
|
-
value: input,
|
|
399
|
-
onChange: (ev) => setInput(ev.target.value),
|
|
400
|
-
onKeyDown: (ev) => ev.key === "Enter" && handleRequest(input)
|
|
401
|
-
})), /* @__PURE__ */ React3.createElement(Toolbar.Button, {
|
|
402
|
-
onClick: () => handleRequest(input)
|
|
403
|
-
}, /* @__PURE__ */ React3.createElement(Icon, {
|
|
404
|
-
icon: "ph--play--regular",
|
|
405
|
-
size: 4
|
|
406
|
-
})), /* @__PURE__ */ React3.createElement(Toolbar.Button, {
|
|
407
|
-
onClick: () => state ? handleStop() : handleClear()
|
|
408
|
-
}, /* @__PURE__ */ React3.createElement(Icon, {
|
|
409
|
-
icon: state ? "ph--stop--regular" : "ph--trash--regular",
|
|
410
|
-
size: 4
|
|
411
|
-
}))));
|
|
412
|
-
};
|
|
413
|
-
var MessageThread = /* @__PURE__ */ forwardRef(({ state, history, result }, forwardedRef) => {
|
|
414
|
-
return /* @__PURE__ */ React3.createElement("div", {
|
|
415
|
-
ref: forwardedRef,
|
|
416
|
-
className: "flex flex-col gap-6 h-full p-2 overflow-x-hidden overflow-y-auto"
|
|
417
|
-
}, history.map((message, i) => /* @__PURE__ */ React3.createElement("div", {
|
|
418
|
-
key: i,
|
|
419
|
-
className: "grid grid-cols-[2rem_1fr_2rem]"
|
|
420
|
-
}, /* @__PURE__ */ React3.createElement("div", {
|
|
421
|
-
className: "p-1"
|
|
422
|
-
}, message.type === "response" && /* @__PURE__ */ React3.createElement(RobotAvatar, null)), /* @__PURE__ */ React3.createElement("div", {
|
|
423
|
-
className: "overflow-auto"
|
|
424
|
-
}, /* @__PURE__ */ React3.createElement(MessageItem, {
|
|
425
|
-
message
|
|
426
|
-
})))), result?.length > 0 && /* @__PURE__ */ React3.createElement("div", {
|
|
427
|
-
className: "grid grid-cols-[2rem_1fr_2rem]"
|
|
428
|
-
}, /* @__PURE__ */ React3.createElement("div", {
|
|
429
|
-
className: "p-1"
|
|
430
|
-
}, state === "pending" && /* @__PURE__ */ React3.createElement(Icon, {
|
|
431
|
-
icon: "ph--spinner--regular",
|
|
432
|
-
size: 6,
|
|
433
|
-
classNames: "animate-spin"
|
|
434
|
-
}) || /* @__PURE__ */ React3.createElement(Icon, {
|
|
435
|
-
icon: "ph--robot--regular",
|
|
436
|
-
size: 6,
|
|
437
|
-
classNames: "animate-[pulse_1s_ease-in-out_infinite]"
|
|
438
|
-
})), /* @__PURE__ */ React3.createElement("div", {
|
|
439
|
-
className: "overflow-auto"
|
|
440
|
-
}, /* @__PURE__ */ React3.createElement(MessageItem, {
|
|
441
|
-
message: {
|
|
442
|
-
type: "response",
|
|
443
|
-
text: result
|
|
444
|
-
}
|
|
445
|
-
}))));
|
|
446
|
-
});
|
|
447
|
-
var MessageItem = ({ classNames, message }) => {
|
|
448
|
-
const { type, text, data, error } = message;
|
|
449
|
-
const wrapper = "p-1 px-2 rounded-lg bg-hoverSurface overflow-auto";
|
|
450
|
-
return /* @__PURE__ */ React3.createElement("div", {
|
|
451
|
-
className: mx("flex", type === "request" ? "ml-[1rem] justify-end" : "mr-[1rem]", classNames)
|
|
452
|
-
}, error && /* @__PURE__ */ React3.createElement("div", {
|
|
453
|
-
className: mx(wrapper, "whitespace-pre", errorText)
|
|
454
|
-
}, String(error)), text !== void 0 && /* @__PURE__ */ React3.createElement("div", {
|
|
455
|
-
className: mx(wrapper, type === "request" && "bg-primary-400 dark:bg-primary-600")
|
|
456
|
-
}, text || "\xD8"), data && /* @__PURE__ */ React3.createElement(SyntaxHighlighter, {
|
|
457
|
-
language: "json",
|
|
458
|
-
className: mx(wrapper, "px-8 py-2 text-xs")
|
|
459
|
-
}, JSON.stringify(data, null, 2)));
|
|
460
|
-
};
|
|
461
|
-
var RobotAvatar = () => /* @__PURE__ */ React3.createElement(Avatar.Root, null, /* @__PURE__ */ React3.createElement(Avatar.Content, {
|
|
462
|
-
size: 6,
|
|
463
|
-
variant: "circle",
|
|
464
|
-
icon: "ph--robot--regular"
|
|
465
|
-
}));
|
|
466
|
-
|
|
467
|
-
// packages/plugins/plugin-script/src/components/index.ts
|
|
468
|
-
import { lazy } from "react";
|
|
469
|
-
var ScriptContainer = lazy(() => import("./ScriptContainer-6DYV7D65.mjs"));
|
|
470
|
-
var DeploymentDialog = lazy(() => import("./DeploymentDialog-W7PY33VN.mjs"));
|
|
471
|
-
|
|
472
|
-
export {
|
|
473
|
-
ScriptObjectSettings,
|
|
474
|
-
ScriptProperties,
|
|
475
|
-
ScriptPluginSettings,
|
|
476
|
-
TestPanel,
|
|
477
|
-
ScriptContainer,
|
|
478
|
-
DeploymentDialog
|
|
479
|
-
};
|
|
480
|
-
//# sourceMappingURL=chunk-BONEXAIK.mjs.map
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
// raw-loader:./chat.ts?raw
|
|
2
|
-
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 ({ data: { bodyText }, context: { space, ai } }: any) => {\n let parsedRequest: any;\n try {\n parsedRequest = JSON.parse(bodyText);\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 ${bodyText}\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 === TemplateInputType.VALUE) {\n value = String(input.value);\n } else if (input.type === TemplateInputType.RETRIEVER) {\n value = await getContext({ space });\n } else if (input.type === TemplateInputType.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 TemplateInputType {\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";
|
|
3
|
-
|
|
4
|
-
// raw-loader:./chess.ts?raw
|
|
5
|
-
var chess_default = "//\n// Copyright 2025 DXOS.org\n//\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 ({ data: { changedObjectId, player = 'b' }, context: { space } }: 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";
|
|
6
|
-
|
|
7
|
-
// raw-loader:./data-generator.ts?raw
|
|
8
|
-
var data_generator_default = "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { defineFunction, S, create, Expando } from 'dxos:functions';\n// @ts-ignore\nimport { randText } from 'https://esm.sh/@ngneat/falso@7.1.1';\n\nexport default defineFunction({\n inputSchema: S.Struct({\n documentAmount: S.optional(S.Number),\n textSize: S.optional(S.Number),\n mutationAmount: S.optional(S.Number),\n }),\n\n outputSchema: S.Struct({}),\n\n handler: async ({ data: { documentAmount = 1, textSize = 10, mutationAmount = 0 }, context: { space } }: any) => {\n await space.db.graph.schemaRegistry.addSchema([Expando]);\n const result: Record<string, any> = {};\n const objects: Expando[] = [];\n\n // Create objects.\n for (let i = 0; i < documentAmount; i++) {\n const obj = space.db.add(\n create(Expando, {\n name: 'scriptGenerated',\n content: randText({ charCount: textSize }),\n }),\n );\n objects.push(obj);\n const objectResult: any = {};\n // Mutate the object.\n for (let i = 0; i < mutationAmount; i++) {\n obj.content = randText({ charCount: textSize });\n }\n objectResult.mutations = mutationAmount;\n objectResult.contentLength = obj.content.length;\n result[obj.id] = objectResult;\n }\n\n // Flush and wait for data to propagate.\n await space.db.flush();\n await new Promise((resolve) => setTimeout(resolve, 10_000));\n return result;\n },\n});\n";
|
|
9
|
-
|
|
10
|
-
// raw-loader:./discord.ts?raw
|
|
11
|
-
var discord_default = "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { create, defineFunction, DXN, EchoObject, 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: ObjectId,\n foreignId: S.Any, // bigint?\n from: S.String,\n created: S.String,\n content: S.String,\n}).pipe(\n EchoObject({\n typename: 'example.com/type/Message',\n version: '0.1.0',\n }),\n);\n\nconst DEFAULT_AFTER = 1704067200; // 2024-01-01\n\nconst generateSnowflake = (unixTimestamp: number): bigint => {\n const discordEpoch = 1420070400000n; // Discord Epoch (ms)\n return (BigInt(unixTimestamp * 1000) - discordEpoch) << 22n;\n};\n\nexport default defineFunction({\n inputSchema: S.Struct({\n // TODO(wittjosiah): Remove. This is used to provide a terminal for a cron trigger.\n tick: S.optional(S.String),\n channelId: S.String,\n after: S.optional(S.Number),\n pageSize: S.optional(S.Number),\n queueId: S.String,\n }),\n\n outputSchema: S.Struct({\n newMessages: S.Number,\n }),\n\n handler: ({ data: { channelId, queueId, after = DEFAULT_AFTER, pageSize = 5 }, context: { space } }: any) =>\n Effect.gen(function* () {\n const { token } = yield* Effect.tryPromise({\n try: () => space.db.query(Filter.typename('dxos.org/type/AccessToken', { source: 'discord.com' })).first(),\n catch: (e: any) => e,\n });\n const { objects } = yield* Effect.tryPromise({\n try: () => space.queues.queryQueue(DXN.parse(queueId)),\n catch: (e: any) => e,\n });\n const backfill = objects.length === 0;\n const newMessages = yield* Ref.make(0);\n const lastMessage = yield* Ref.make(objects.at(-1));\n\n const enqueueMessages = Effect.gen(function* () {\n const rest = yield* DiscordREST;\n\n while (true) {\n const last = yield* Ref.get(lastMessage);\n const options = {\n after: backfill && !last ? `${generateSnowflake(after)}` : last?.foreignId,\n limit: pageSize,\n };\n const messages = yield* rest.getChannelMessages(channelId, options).pipe((res: any) => res.json);\n const queueMessages = messages\n .map((message: any) =>\n create(MessageSchema, {\n id: 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({\n try: () => space.queues.insertIntoQueue(DXN.parse(queueId), queueMessages),\n catch: (e: any) => e,\n });\n yield* Ref.update(newMessages, (n: any) => n + queueMessages.length);\n yield* Ref.update(lastMessage, (m: any) => queueMessages.at(-1));\n }\n if (messages.length < pageSize) {\n break;\n }\n }\n }).pipe(\n Effect.provide(DiscordRESTMemoryLive),\n Effect.provide(\n DiscordConfig.layerConfig({\n token: Config.succeed(Redacted.make(token)),\n }),\n ),\n Effect.provide(FetchHttpClient.layer),\n );\n\n yield* enqueueMessages;\n return { newMessages: yield* Ref.get(newMessages) };\n }),\n});\n";
|
|
12
|
-
|
|
13
|
-
// raw-loader:./echo.ts?raw
|
|
14
|
-
var echo_default = "//\n// Copyright 2024 DXOS.org\n//\n\n/**\n * Echos the request data.\n */\nexport default async ({ data }: any) => data;\n";
|
|
15
|
-
|
|
16
|
-
// raw-loader:./email.ts?raw
|
|
17
|
-
var email_default = "//\n// Copyright 2024 DXOS.org\n//\n\n/**\n * Appends a message to the end of a Document configured through a trigger.\n * Trigger must have a targetDocumentId field set in Meta.\n */\nexport default async ({ data: { bodyText }, context: { space } }: any) => {\n const { email, targetDocumentId: documentId } = JSON.parse(bodyText) as RequestPayload;\n\n const document = await space.db.query({ id: documentId }, { 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:** ${email.from}`,\n `**Subject:** ${email.subject}`,\n `**Date:** ${email.created}`,\n '',\n email.body,\n ].join('\\n');\n\n await space.db.update({ id: contentId }, { content: modifiedContent });\n\n return new Response(JSON.stringify({ success: true }));\n};\n\ntype RequestPayload = {\n email: { from: string; subject: string; created: string; body: string };\n targetDocumentId: string;\n};\n";
|
|
18
|
-
|
|
19
|
-
// raw-loader:./forex-effect.ts?raw
|
|
20
|
-
var forex_effect_default = "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { S, defineFunction } 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 ({ data: { from, to } }: 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(1_000).pipe(Schedule.compose(Schedule.recurs(3)))),\n Effect.scoped,\n );\n\n return res.data.rates[to].toString();\n }).pipe(Effect.provide(FetchHttpClient.layer)),\n});\n";
|
|
21
|
-
|
|
22
|
-
// raw-loader:./forex.ts?raw
|
|
23
|
-
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 ({ data: { from, to } }: 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";
|
|
24
|
-
|
|
25
|
-
// raw-loader:./gmail.ts?raw
|
|
26
|
-
var gmail_default = "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { create, defineFunction, EchoObject, Filter, ObjectId, S } from 'dxos:functions';\n// @ts-ignore\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 { format, subDays } from 'https://esm.sh/date-fns@3.3.1';\n// @ts-ignore\nimport { pipe, Chunk, Effect, Ref, Schedule, Stream } from 'https://esm.sh/effect@3.13.3';\n\nexport default defineFunction({\n inputSchema: S.Struct({\n mailboxId: S.String,\n userId: S.optional(S.String).pipe(S.withDecodingDefault(() => 'me')),\n after: S.optional(S.Union(S.Number, S.String)).pipe(\n S.withDecodingDefault(() => format(subDays(new Date(), 30), 'yyyy-MM-dd')),\n ),\n pageSize: S.optional(S.Number).pipe(S.withDecodingDefault(() => 100)),\n // TODO(wittjosiah): Remove. This is used to provide a terminal for a cron trigger.\n tick: S.optional(S.String),\n }),\n\n outputSchema: S.Struct({\n newMessages: S.Number,\n }),\n\n handler: ({ context: { space }, data: { mailboxId, userId, after, pageSize } }: any) =>\n Effect.gen(function* () {\n const { token } = yield* Effect.tryPromise({\n try: () => space.db.query(Filter.typename('dxos.org/type/AccessToken', { source: 'gmail.com' })).first(),\n catch: (e: any) => e,\n });\n\n // NOTE: Google API bundles size is v. large and caused runtime issues.\n const makeRequest = (url: string) =>\n pipe(\n url,\n HttpClientRequest.get,\n HttpClientRequest.setHeaders({ Authorization: `Bearer ${token}`, Accept: 'application/json' }),\n HttpClient.execute,\n Effect.flatMap((res: any) => res.json),\n Effect.timeout('1 second'),\n Effect.retry(Schedule.exponential(1000).pipe(Schedule.compose(Schedule.recurs(3)))),\n Effect.scoped,\n );\n\n const listMessages = (userId: string, q: string, pageSize: number, pageToken: string | null) =>\n makeRequest(getUrl(userId, undefined, { q, pageSize, pageToken }));\n\n const getMessage = (userId: string, messageId: string) => makeRequest(getUrl(userId, messageId));\n\n const mailbox = yield* Effect.tryPromise({\n try: () => space.db.query({ id: mailboxId }).first(),\n catch: (e: any) => e,\n });\n const { objects } = yield* Effect.tryPromise({\n try: () => space.queues.queryQueue(mailbox.queue.dxn),\n catch: (e: any) => e,\n });\n const newMessages = yield* Ref.make([]);\n const nextPage = yield* Ref.make(null);\n\n do {\n const last = objects.at(-1);\n const q = last\n ? `in:inbox after:${Math.floor(new Date(last.created).getTime() / 1000)}`\n : `in:inbox after:${after}`;\n const pageToken = yield* Ref.get(nextPage);\n const { messages, nextPageToken } = yield* listMessages(userId, q, pageSize, pageToken);\n yield* Ref.update(nextPage, () => nextPageToken);\n for (const message of messages) {\n const messageDetails = yield* getMessage(userId, message.id);\n const created = new Date(parseInt(messageDetails.internalDate)).toISOString();\n const from = messageDetails.payload.headers.find((h: any) => h.name === 'From');\n const sender = from && parseEmailString(from.value);\n // TODO(wittjosiah): Improve parsing of email contents.\n const content =\n messageDetails.payload.body?.data ??\n messageDetails.payload.parts?.find((p: any) => p.mimeType === 'text/plain')?.body.data;\n // Skip the message if content or sender is missing.\n // Skip the message if it's the same as the last message.\n // TODO(wittjosiah): This comparison should be done via foreignId probably.\n if (!content || !sender || created === last?.created) {\n continue;\n }\n const subject = messageDetails.payload.headers.find((h: any) => h.name === 'Subject')?.value;\n const object = create(MessageType, {\n id: ObjectId.random(),\n created,\n sender,\n blocks: [\n {\n type: 'text',\n text: Buffer.from(content, 'base64').toString('utf-8'),\n },\n ],\n properties: {\n subject,\n threadId: message.threadId,\n },\n });\n // TODO(wittjosiah): Set foreignId in object meta.\n yield* Ref.update(newMessages, (n: any) => [object, ...n]);\n }\n } while (yield* Ref.get(nextPage));\n\n const queueMessages = yield* Ref.get(newMessages);\n if (queueMessages.length > 0) {\n yield* pipe(\n queueMessages,\n Stream.fromIterable,\n Stream.grouped(10),\n Stream.flatMap((batch: any) =>\n Effect.tryPromise({\n try: () => space.queues.insertIntoQueue(mailbox.queue.dxn, Chunk.toReadonlyArray(batch)),\n catch: (e: any) => e,\n }),\n ),\n Stream.runDrain,\n );\n }\n\n return { newMessages: queueMessages.length };\n }).pipe(Effect.provide(FetchHttpClient.layer)),\n});\n\nconst getUrl = (userId: string, messageId?: string, params?: Record<string, any>) => {\n const api = new URL(\n [`https://gmail.googleapis.com/gmail/v1/users/${userId}/messages`, messageId].filter(Boolean).join('/'),\n );\n Object.entries(params ?? {}).forEach(([key, value]) => api.searchParams.set(key, value));\n return api.toString();\n};\n\n/**\n * Parses an email string in the format \"Name <email@example.com>\" into separate name and email components.\n */\nconst parseEmailString = (emailString: string): { name?: string; email: string } | undefined => {\n const match = emailString.match(/^([^<]+?)\\s*<([^>]+@[^>]+)>$/);\n if (match) {\n const [, name, email] = match;\n return {\n name: name.trim(),\n email: email.trim(),\n };\n }\n\n return undefined;\n};\n\n//\n// Schemas\n// TODO(wittjosiah): These schemas should be imported from @dxos/S.\n//\n\nconst ActorRoles = ['user', 'assistant'] as const;\nconst ActorRole = S.Literal(...ActorRoles);\ntype ActorRole = S.Schema.Type<typeof ActorRole>;\n\nconst ActorSchema = S.Struct({\n identityKey: S.optional(S.String),\n email: S.optional(S.String),\n name: S.optional(S.String),\n role: S.optional(ActorRole),\n});\n\nconst AbstractContentBlock = S.Struct({\n pending: S.optional(S.Boolean),\n});\ntype AbstractContentBlock = S.Schema.Type<typeof AbstractContentBlock>;\nconst TextContentBlock = S.extend(\n AbstractContentBlock,\n S.Struct({\n type: S.Literal('text'),\n disposition: S.optional(S.String),\n text: S.String,\n }),\n).pipe(S.mutable);\ntype TextContentBlock = S.Schema.Type<typeof TextContentBlock>;\nconst JsonContentBlock = S.extend(\n AbstractContentBlock,\n S.Struct({\n type: S.Literal('json'),\n disposition: S.optional(S.String),\n data: S.String,\n }),\n).pipe(S.mutable);\ntype JsonContentBlock = S.Schema.Type<typeof JsonContentBlock>;\nconst Base64ImageSource = S.Struct({\n type: S.Literal('base64'),\n mediaType: S.String,\n data: S.String,\n}).pipe(S.mutable);\nconst HttpImageSource = S.Struct({\n type: S.Literal('http'),\n url: S.String,\n}).pipe(S.mutable);\nconst ImageSource = S.Union(Base64ImageSource, HttpImageSource);\ntype ImageSource = S.Schema.Type<typeof ImageSource>;\nconst ImageContentBlock = S.extend(\n AbstractContentBlock,\n S.Struct({\n type: S.Literal('image'),\n id: S.optional(S.String),\n source: S.optional(ImageSource),\n }),\n).pipe(S.mutable);\ntype ImageContentBlock = S.Schema.Type<typeof ImageContentBlock>;\nconst ReferenceContentBlock = S.extend(\n AbstractContentBlock,\n S.Struct({\n type: S.Literal('reference'),\n reference: S.Any,\n }),\n).pipe(S.mutable);\ntype ReferenceContentBlock = S.Schema.Type<typeof ReferenceContentBlock>;\nconst MessageContentBlock = S.Union(TextContentBlock, JsonContentBlock, ImageContentBlock, ReferenceContentBlock);\n\nconst MessageType = S.Struct({\n id: ObjectId,\n created: S.String.annotations({\n description: 'ISO date string when the message was sent.',\n }),\n sender: ActorSchema.annotations({\n description: 'Identity of the message sender.',\n }),\n blocks: S.Array(MessageContentBlock).annotations({\n description: 'Contents of the message.',\n }),\n properties: S.optional(\n S.mutable(\n S.Record({ key: S.String, value: S.Any }).annotations({\n description: 'Custom properties for specific message types (e.g. attention context, email subject, etc.).',\n }),\n ),\n ),\n}).pipe(\n EchoObject({\n typename: 'dxos.org/type/Message',\n version: '0.1.0',\n }),\n);\ntype MessageType = S.Schema.Type<typeof MessageType>;\n";
|
|
27
|
-
|
|
28
|
-
// packages/plugins/plugin-script/src/templates/index.ts
|
|
29
|
-
var removeHeader = (str) => str.split("\n").slice(4).join("\n");
|
|
30
|
-
var templates = [
|
|
31
|
-
{
|
|
32
|
-
id: "dxos.org/script/echo",
|
|
33
|
-
name: "Echo",
|
|
34
|
-
source: removeHeader(echo_default)
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
id: "dxos.org/script/forex",
|
|
38
|
-
name: "Forex",
|
|
39
|
-
source: removeHeader(forex_default)
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
id: "dxos.org/script/forex-effect",
|
|
43
|
-
name: "Forex (Effect)",
|
|
44
|
-
source: removeHeader(forex_effect_default)
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
id: "dxos.org/script/gpt",
|
|
48
|
-
name: "Gpt",
|
|
49
|
-
source: removeHeader(chat_default),
|
|
50
|
-
presetId: "dxos.org/function/gpt"
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
id: "dxos.org/script/chess",
|
|
54
|
-
name: "Chess",
|
|
55
|
-
source: removeHeader(chess_default),
|
|
56
|
-
presetId: "dxos.org/function/chess"
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
id: "dxos.org/script/email",
|
|
60
|
-
name: "Email",
|
|
61
|
-
source: removeHeader(email_default),
|
|
62
|
-
presetId: "dxos.org/function/email"
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
id: "dxos.org/script/discord",
|
|
66
|
-
name: "Discord",
|
|
67
|
-
source: removeHeader(discord_default),
|
|
68
|
-
presetId: "dxos.org/function/discord"
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
id: "dxos.org/script/gmail",
|
|
72
|
-
name: "Gmail",
|
|
73
|
-
source: removeHeader(gmail_default),
|
|
74
|
-
presetId: "dxos.org/function/gmail"
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
id: "dxos.org/script/data-generator",
|
|
78
|
-
name: "Data Generator",
|
|
79
|
-
source: removeHeader(data_generator_default),
|
|
80
|
-
presetId: "dxos.org/function/data-generator"
|
|
81
|
-
}
|
|
82
|
-
];
|
|
83
|
-
|
|
84
|
-
export {
|
|
85
|
-
templates
|
|
86
|
-
};
|
|
87
|
-
//# sourceMappingURL=chunk-RTVU4RZW.mjs.map
|