@dxos/plugin-script 0.6.11 → 0.6.12-main.2d19bf1
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/README.md +1 -1
- package/dist/lib/browser/{ScriptEditor-5Y3EROG3.mjs → ScriptContainer-M4MDQTBU.mjs} +258 -106
- package/dist/lib/browser/ScriptContainer-M4MDQTBU.mjs.map +7 -0
- package/dist/lib/browser/{chunk-DL5XQRQM.mjs → chunk-G6FWCTGT.mjs} +7 -5
- package/dist/lib/browser/chunk-G6FWCTGT.mjs.map +7 -0
- package/dist/lib/browser/{chunk-RHEZ5LUU.mjs → chunk-G6H56WFS.mjs} +51 -2
- package/dist/lib/browser/{chunk-RHEZ5LUU.mjs.map → chunk-G6H56WFS.mjs.map} +4 -4
- package/dist/lib/browser/{chunk-O4LWBX6A.mjs → chunk-KXVQPS4Y.mjs} +2 -2
- package/dist/lib/browser/{chunk-O4LWBX6A.mjs.map → chunk-KXVQPS4Y.mjs.map} +2 -2
- package/dist/lib/browser/chunk-SGQHRB4P.mjs +17 -0
- package/dist/lib/browser/chunk-SGQHRB4P.mjs.map +7 -0
- package/dist/lib/browser/edge/index.mjs +3 -1
- package/dist/lib/browser/index.mjs +80 -62
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/meta.mjs +1 -1
- package/dist/lib/browser/types/index.mjs +2 -2
- package/dist/lib/node/ScriptContainer-KMIPKT3H.cjs +668 -0
- package/dist/lib/node/ScriptContainer-KMIPKT3H.cjs.map +7 -0
- package/dist/lib/node/{chunk-5RBVXKXT.cjs → chunk-25PQE7FL.cjs} +6 -6
- package/dist/lib/node/{chunk-5RBVXKXT.cjs.map → chunk-25PQE7FL.cjs.map} +2 -2
- package/dist/lib/node/{chunk-4GTXIELQ.cjs → chunk-ACLCRWDB.cjs} +44 -6
- package/dist/lib/node/chunk-ACLCRWDB.cjs.map +7 -0
- package/dist/lib/node/{TypescriptEditor-M3WWFIP2.cjs → chunk-EJC55SDD.cjs} +18 -8
- package/dist/lib/node/chunk-EJC55SDD.cjs.map +7 -0
- package/dist/lib/node/{chunk-PFH3ROEH.cjs → chunk-UZ3ZXEBF.cjs} +11 -8
- package/dist/lib/node/chunk-UZ3ZXEBF.cjs.map +7 -0
- package/dist/lib/node/edge/index.cjs +10 -8
- package/dist/lib/node/edge/index.cjs.map +2 -2
- package/dist/lib/node/index.cjs +95 -82
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.cjs +3 -3
- package/dist/lib/node/meta.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/types/index.cjs +5 -5
- package/dist/lib/node/types/index.cjs.map +1 -1
- package/dist/lib/node-esm/ScriptContainer-EAE6L5JV.mjs +666 -0
- package/dist/lib/node-esm/ScriptContainer-EAE6L5JV.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-2NX3HWPM.mjs +245 -0
- package/dist/lib/node-esm/chunk-2NX3HWPM.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-7EDYDVQH.mjs +47 -0
- package/dist/lib/node-esm/chunk-7EDYDVQH.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-GO7HYFM5.mjs +19 -0
- package/dist/lib/node-esm/chunk-GO7HYFM5.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-LDLNTVAK.mjs +280 -0
- package/dist/lib/node-esm/chunk-LDLNTVAK.mjs.map +7 -0
- package/dist/lib/node-esm/edge/index.mjs +22 -0
- package/dist/lib/node-esm/index.mjs +310 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/lib/node-esm/meta.mjs +10 -0
- package/dist/lib/node-esm/meta.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +13 -0
- package/dist/lib/node-esm/types/index.mjs.map +7 -0
- package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
- package/dist/types/src/components/DebugPanel/DebugPanel.d.ts.map +1 -0
- package/dist/types/src/components/DebugPanel/index.d.ts +2 -0
- package/dist/types/src/components/DebugPanel/index.d.ts.map +1 -0
- package/dist/types/src/components/{ScriptBlock/FrameContainer → FrameContainer}/FrameContainer.d.ts +1 -1
- package/dist/types/src/components/FrameContainer/FrameContainer.d.ts.map +1 -0
- package/dist/types/src/components/FrameContainer/frame.d.ts.map +1 -0
- package/dist/types/src/components/FrameContainer/index.d.ts.map +1 -0
- package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts +1 -3
- package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts.map +1 -1
- package/dist/types/src/components/ScriptBlock/ScriptBlock.stories.d.ts +1 -1
- package/dist/types/src/components/ScriptBlock/ScriptBlock.stories.d.ts.map +1 -1
- package/dist/types/src/components/ScriptContainer.d.ts +5 -0
- package/dist/types/src/components/ScriptContainer.d.ts.map +1 -0
- package/dist/types/src/components/ScriptEditor.d.ts +4 -5
- package/dist/types/src/components/ScriptEditor.d.ts.map +1 -1
- package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts +6 -0
- package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts.map +1 -0
- package/dist/types/src/components/ScriptSettings/index.d.ts +2 -0
- package/dist/types/src/components/ScriptSettings/index.d.ts.map +1 -0
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +23 -0
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -0
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +17 -0
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -0
- package/dist/types/src/components/Toolbar/index.d.ts +2 -0
- package/dist/types/src/components/Toolbar/index.d.ts.map +1 -0
- package/dist/types/src/components/{TypescriptEditor.d.ts → TypescriptEditor/TypescriptEditor.d.ts} +1 -2
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -0
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts +10 -0
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts.map +1 -0
- package/dist/types/src/components/TypescriptEditor/index.d.ts +2 -0
- package/dist/types/src/components/TypescriptEditor/index.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +2 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/edge/functions.d.ts +1 -0
- package/dist/types/src/edge/functions.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +4 -9
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/templates/chat.d.ts +6 -0
- package/dist/types/src/templates/chat.d.ts.map +1 -0
- package/dist/types/src/templates/chess.d.ts +6 -0
- package/dist/types/src/templates/chess.d.ts.map +1 -0
- package/dist/types/src/templates/echo.d.ts +6 -0
- package/dist/types/src/templates/echo.d.ts.map +1 -0
- package/dist/types/src/templates/email.d.ts +6 -0
- package/dist/types/src/templates/email.d.ts.map +1 -0
- package/dist/types/src/templates/forex.d.ts +6 -0
- package/dist/types/src/templates/forex.d.ts.map +1 -0
- package/dist/types/src/templates.d.ts +8 -0
- package/dist/types/src/templates.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +2 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/script.d.ts +4 -4
- package/dist/types/src/types/types.d.ts +4 -3
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/package.json +61 -55
- package/src/ScriptPlugin.tsx +22 -38
- package/src/bundler/bundler.test.ts +12 -2
- package/src/components/{DebugPanel.tsx → DebugPanel/DebugPanel.tsx} +48 -41
- package/src/components/DebugPanel/index.ts +5 -0
- package/src/components/{ScriptBlock/FrameContainer → FrameContainer}/FrameContainer.tsx +1 -1
- package/src/components/ScriptBlock/ScriptBlock.stories.tsx +4 -3
- package/src/components/ScriptBlock/ScriptBlock.tsx +10 -36
- package/src/components/ScriptContainer.tsx +22 -0
- package/src/components/ScriptEditor.tsx +47 -46
- package/src/components/ScriptSettings/ScriptSettings.tsx +47 -0
- package/src/components/ScriptSettings/index.ts +5 -0
- package/src/components/{Toolbar.stories.tsx → Toolbar/Toolbar.stories.tsx} +10 -1
- package/src/components/Toolbar/Toolbar.tsx +180 -0
- package/src/components/{ScriptBlock/Splitter → Toolbar}/index.ts +1 -1
- package/src/components/{TypescriptEditor.stories.tsx → TypescriptEditor/TypescriptEditor.stories.tsx} +7 -28
- package/src/components/{TypescriptEditor.tsx → TypescriptEditor/TypescriptEditor.tsx} +1 -3
- package/src/components/TypescriptEditor/index.ts +5 -0
- package/src/components/index.ts +3 -2
- package/src/edge/functions.ts +1 -0
- package/src/meta.ts +15 -0
- package/src/templates/chat.ts +102 -0
- package/src/templates/chess.ts +41 -0
- package/src/templates/echo.ts +15 -0
- package/src/templates/email.ts +38 -0
- package/src/templates/forex.ts +21 -0
- package/src/templates.ts +54 -0
- package/src/translations.ts +2 -0
- package/src/types/types.ts +9 -5
- package/dist/lib/browser/ScriptEditor-5Y3EROG3.mjs.map +0 -7
- package/dist/lib/browser/TypescriptEditor-GPE72Y6I.mjs +0 -9
- package/dist/lib/browser/chunk-DL5XQRQM.mjs.map +0 -7
- package/dist/lib/browser/chunk-JBACGDOJ.mjs +0 -21
- package/dist/lib/browser/chunk-JBACGDOJ.mjs.map +0 -7
- package/dist/lib/browser/chunk-MRGOT5RF.mjs +0 -78
- package/dist/lib/browser/chunk-MRGOT5RF.mjs.map +0 -7
- package/dist/lib/node/ScriptEditor-YCUQFWQM.cjs +0 -526
- package/dist/lib/node/ScriptEditor-YCUQFWQM.cjs.map +0 -7
- package/dist/lib/node/TypescriptEditor-M3WWFIP2.cjs.map +0 -7
- package/dist/lib/node/chunk-4GTXIELQ.cjs.map +0 -7
- package/dist/lib/node/chunk-4VMNBXWU.cjs +0 -54
- package/dist/lib/node/chunk-4VMNBXWU.cjs.map +0 -7
- package/dist/lib/node/chunk-IMLDKD5Y.cjs +0 -111
- package/dist/lib/node/chunk-IMLDKD5Y.cjs.map +0 -7
- package/dist/lib/node/chunk-PFH3ROEH.cjs.map +0 -7
- package/dist/types/src/components/DebugPanel.d.ts.map +0 -1
- package/dist/types/src/components/ScriptBlock/FrameContainer/FrameContainer.d.ts.map +0 -1
- package/dist/types/src/components/ScriptBlock/FrameContainer/frame.d.ts.map +0 -1
- package/dist/types/src/components/ScriptBlock/FrameContainer/index.d.ts.map +0 -1
- package/dist/types/src/components/ScriptBlock/Splitter/Splitter.d.ts +0 -15
- package/dist/types/src/components/ScriptBlock/Splitter/Splitter.d.ts.map +0 -1
- package/dist/types/src/components/ScriptBlock/Splitter/Splitter.stories.d.ts +0 -13
- package/dist/types/src/components/ScriptBlock/Splitter/Splitter.stories.d.ts.map +0 -1
- package/dist/types/src/components/ScriptBlock/Splitter/index.d.ts +0 -2
- package/dist/types/src/components/ScriptBlock/Splitter/index.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar.d.ts +0 -13
- package/dist/types/src/components/Toolbar.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar.stories.d.ts +0 -14
- package/dist/types/src/components/Toolbar.stories.d.ts.map +0 -1
- package/dist/types/src/components/TypescriptEditor.d.ts.map +0 -1
- package/dist/types/src/components/TypescriptEditor.stories.d.ts +0 -10
- package/dist/types/src/components/TypescriptEditor.stories.d.ts.map +0 -1
- package/src/components/ScriptBlock/Splitter/Splitter.stories.tsx +0 -37
- package/src/components/ScriptBlock/Splitter/Splitter.tsx +0 -52
- package/src/components/Toolbar.tsx +0 -147
- package/src/meta.tsx +0 -19
- /package/dist/lib/{browser/TypescriptEditor-GPE72Y6I.mjs.map → node-esm/edge/index.mjs.map} +0 -0
- /package/dist/types/src/components/{DebugPanel.d.ts → DebugPanel/DebugPanel.d.ts} +0 -0
- /package/dist/types/src/components/{ScriptBlock/FrameContainer → FrameContainer}/frame.d.ts +0 -0
- /package/dist/types/src/components/{ScriptBlock/FrameContainer → FrameContainer}/index.d.ts +0 -0
- /package/src/components/{ScriptBlock/FrameContainer → FrameContainer}/frame.html +0 -0
- /package/src/components/{ScriptBlock/FrameContainer → FrameContainer}/frame.tsx +0 -0
- /package/src/components/{ScriptBlock/FrameContainer → FrameContainer}/index.ts +0 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// packages/plugins/experimental/plugin-script/src/bundler/bundler.ts
|
|
4
|
+
import { build, initialize } from "esbuild-wasm";
|
|
5
|
+
import { subtleCrypto } from "@dxos/crypto";
|
|
6
|
+
import { invariant } from "@dxos/invariant";
|
|
7
|
+
import { log } from "@dxos/log";
|
|
8
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-script/src/bundler/bundler.ts";
|
|
9
|
+
var initialized;
|
|
10
|
+
var initializeBundler = async (options) => {
|
|
11
|
+
await (initialized ??= initialize({
|
|
12
|
+
wasmURL: options.wasmUrl
|
|
13
|
+
}));
|
|
14
|
+
};
|
|
15
|
+
var Bundler = class {
|
|
16
|
+
constructor(_options) {
|
|
17
|
+
this._options = _options;
|
|
18
|
+
}
|
|
19
|
+
async bundle(source) {
|
|
20
|
+
const { sandboxedModules: providedModules, ...options } = this._options;
|
|
21
|
+
const createResult = async (result) => {
|
|
22
|
+
return {
|
|
23
|
+
timestamp: Date.now(),
|
|
24
|
+
sourceHash: Buffer.from(await subtleCrypto.digest("SHA-256", Buffer.from(source))),
|
|
25
|
+
...result
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
if (this._options.platform === "browser") {
|
|
29
|
+
invariant(initialized, "Compiler not initialized.", {
|
|
30
|
+
F: __dxlog_file,
|
|
31
|
+
L: 57,
|
|
32
|
+
S: this,
|
|
33
|
+
A: [
|
|
34
|
+
"initialized",
|
|
35
|
+
"'Compiler not initialized.'"
|
|
36
|
+
]
|
|
37
|
+
});
|
|
38
|
+
await initialized;
|
|
39
|
+
}
|
|
40
|
+
const imports = analyzeSourceFileImports(source);
|
|
41
|
+
try {
|
|
42
|
+
const result = await build({
|
|
43
|
+
platform: options.platform,
|
|
44
|
+
conditions: [
|
|
45
|
+
"workerd",
|
|
46
|
+
"browser"
|
|
47
|
+
],
|
|
48
|
+
metafile: true,
|
|
49
|
+
write: false,
|
|
50
|
+
entryPoints: [
|
|
51
|
+
"memory:main.tsx"
|
|
52
|
+
],
|
|
53
|
+
bundle: true,
|
|
54
|
+
format: "esm",
|
|
55
|
+
plugins: [
|
|
56
|
+
{
|
|
57
|
+
name: "memory",
|
|
58
|
+
setup: (build2) => {
|
|
59
|
+
build2.onResolve({
|
|
60
|
+
filter: /^\.\/runtime\.js$/
|
|
61
|
+
}, ({ path }) => {
|
|
62
|
+
return {
|
|
63
|
+
path,
|
|
64
|
+
external: true
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
build2.onResolve({
|
|
68
|
+
filter: /^memory:/
|
|
69
|
+
}, ({ path }) => {
|
|
70
|
+
return {
|
|
71
|
+
path: path.split(":")[1],
|
|
72
|
+
namespace: "memory"
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
build2.onLoad({
|
|
76
|
+
filter: /.*/,
|
|
77
|
+
namespace: "memory"
|
|
78
|
+
}, ({ path }) => {
|
|
79
|
+
if (path === "main.tsx") {
|
|
80
|
+
return {
|
|
81
|
+
contents: source,
|
|
82
|
+
loader: "tsx"
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
for (const module of providedModules) {
|
|
87
|
+
build2.onResolve({
|
|
88
|
+
filter: new RegExp(`^${module}$`)
|
|
89
|
+
}, ({ path }) => {
|
|
90
|
+
return {
|
|
91
|
+
path,
|
|
92
|
+
namespace: "injected-module"
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
build2.onLoad({
|
|
97
|
+
filter: /.*/,
|
|
98
|
+
namespace: "injected-module"
|
|
99
|
+
}, ({ path }) => {
|
|
100
|
+
const namedImports = imports.find((entry) => entry.moduleIdentifier === path)?.namedImports ?? [];
|
|
101
|
+
return {
|
|
102
|
+
contents: `
|
|
103
|
+
const { ${namedImports.join(",")} } = window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}];
|
|
104
|
+
export { ${namedImports.join(",")} };
|
|
105
|
+
export default window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}].default;
|
|
106
|
+
`,
|
|
107
|
+
loader: "tsx"
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
httpPlugin
|
|
113
|
+
]
|
|
114
|
+
});
|
|
115
|
+
log("compile complete", result.metafile, {
|
|
116
|
+
F: __dxlog_file,
|
|
117
|
+
L: 117,
|
|
118
|
+
S: this,
|
|
119
|
+
C: (f, a) => f(...a)
|
|
120
|
+
});
|
|
121
|
+
return await createResult({
|
|
122
|
+
imports: this.analyzeImports(result),
|
|
123
|
+
bundle: result.outputFiles[0].text
|
|
124
|
+
});
|
|
125
|
+
} catch (err) {
|
|
126
|
+
return await createResult({
|
|
127
|
+
error: err
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// TODO(dmaretskyi): In the future we can replace the compiler with SWC with plugins running in WASM.
|
|
132
|
+
analyzeImports(result) {
|
|
133
|
+
invariant(result.outputFiles, void 0, {
|
|
134
|
+
F: __dxlog_file,
|
|
135
|
+
L: 130,
|
|
136
|
+
S: this,
|
|
137
|
+
A: [
|
|
138
|
+
"result.outputFiles",
|
|
139
|
+
""
|
|
140
|
+
]
|
|
141
|
+
});
|
|
142
|
+
const parsedImports = allMatches(IMPORT_REGEX, result.outputFiles[0].text);
|
|
143
|
+
return Object.values(result.metafile.outputs)[0].imports.map((entry) => {
|
|
144
|
+
const namedImports = [];
|
|
145
|
+
const parsedImport = parsedImports.find((capture) => capture?.[4] === entry.path);
|
|
146
|
+
if (parsedImport?.[2]) {
|
|
147
|
+
NAMED_IMPORTS_REGEX.lastIndex = 0;
|
|
148
|
+
const namedImportsMatch = NAMED_IMPORTS_REGEX.exec(parsedImport[2]);
|
|
149
|
+
if (namedImportsMatch) {
|
|
150
|
+
namedImportsMatch[1].split(",").forEach((importName) => {
|
|
151
|
+
namedImports.push(importName.trim());
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
moduleUrl: entry.path,
|
|
157
|
+
defaultImport: !!parsedImport?.[1],
|
|
158
|
+
namedImports
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
analyzeSourceFileImports(code) {
|
|
163
|
+
const parsedImports = allMatches(IMPORT_REGEX, code);
|
|
164
|
+
return parsedImports.map((capture) => {
|
|
165
|
+
return {
|
|
166
|
+
defaultImportName: capture[1],
|
|
167
|
+
namedImports: capture[2]?.split(",").map((importName) => importName.trim()),
|
|
168
|
+
wildcardImportName: capture[3],
|
|
169
|
+
moduleIdentifier: capture[4],
|
|
170
|
+
quotes: capture[5]
|
|
171
|
+
};
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
var IMPORT_REGEX = /import(?:(?:(?:[ \n\t]+([^ *\n\t{},]+)[ \n\t]*(?:,|[ \n\t]+))?([ \n\t]*{(?:[ \n\t]*[^ \n\t"'{}]+[ \n\t]*,?)+})?[ \n\t]*)|[ \n\t]*\*[ \n\t]*as[ \n\t]+([^ \n\t{}]+)[ \n\t]+)from[ \n\t]*(?:['"])([^'"\n]+)(['"])/gm;
|
|
176
|
+
var NAMED_IMPORTS_REGEX = /[ \n\t]*{((?:[ \n\t]*[^ \n\t"'{}]+[ \n\t]*,?)+)}[ \n\t]*/gm;
|
|
177
|
+
var allMatches = (regex, str) => {
|
|
178
|
+
regex.lastIndex = 0;
|
|
179
|
+
let match;
|
|
180
|
+
const matches = [];
|
|
181
|
+
while (match = regex.exec(str)) {
|
|
182
|
+
matches.push(match);
|
|
183
|
+
}
|
|
184
|
+
return matches;
|
|
185
|
+
};
|
|
186
|
+
var analyzeSourceFileImports = (code) => {
|
|
187
|
+
const parsedImports = allMatches(IMPORT_REGEX, code);
|
|
188
|
+
return parsedImports.map((capture) => {
|
|
189
|
+
return {
|
|
190
|
+
defaultImportName: capture[1],
|
|
191
|
+
namedImports: capture[2]?.trim().slice(1, -1).split(",").map((importName) => importName.trim()),
|
|
192
|
+
wildcardImportName: capture[3],
|
|
193
|
+
moduleIdentifier: capture[4],
|
|
194
|
+
quotes: capture[5]
|
|
195
|
+
};
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
var httpPlugin = {
|
|
199
|
+
name: "http",
|
|
200
|
+
setup: (build2) => {
|
|
201
|
+
build2.onResolve({
|
|
202
|
+
filter: /^https?:\/\//
|
|
203
|
+
}, (args) => ({
|
|
204
|
+
path: args.path,
|
|
205
|
+
namespace: "http-url"
|
|
206
|
+
}));
|
|
207
|
+
build2.onResolve({
|
|
208
|
+
filter: /.*/,
|
|
209
|
+
namespace: "http-url"
|
|
210
|
+
}, (args) => ({
|
|
211
|
+
path: new URL(args.path, args.importer).toString(),
|
|
212
|
+
namespace: "http-url"
|
|
213
|
+
}));
|
|
214
|
+
build2.onLoad({
|
|
215
|
+
filter: /.*/,
|
|
216
|
+
namespace: "http-url"
|
|
217
|
+
}, async (args) => {
|
|
218
|
+
const response = await fetch(args.path);
|
|
219
|
+
return {
|
|
220
|
+
contents: await response.text(),
|
|
221
|
+
loader: "jsx"
|
|
222
|
+
};
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
// raw-loader:./templates/chat.ts?raw
|
|
228
|
+
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";
|
|
229
|
+
|
|
230
|
+
// raw-loader:./templates/chess.ts?raw
|
|
231
|
+
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";
|
|
232
|
+
|
|
233
|
+
// raw-loader:./templates/echo.ts?raw
|
|
234
|
+
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 ?? {}), { headers: { 'Content-Type': 'application/json' } });\n};\n";
|
|
235
|
+
|
|
236
|
+
// raw-loader:./templates/email.ts?raw
|
|
237
|
+
var email_default = "//\n// Copyright 2024 DXOS.org\n//\n\n/**\n * Stores a message into ECHO Mailbox object.\n */\nexport default async ({\n event: {\n data: { request },\n },\n context: { space },\n}: any) => {\n const {\n data: {\n objects: [message],\n },\n } = await request.json();\n\n const mailbox = await space.crud.query({ __typename: 'dxos.org/type/MailboxType' }).first();\n if (!mailbox) {\n return new Response('Mailbox not found.', { status: 500 });\n }\n\n await space.crud.push(\n { id: mailbox.id },\n {\n sender: { email: message.from },\n timestamp: new Date(message.created).toISOString(),\n text: message.body,\n properties: {\n subject: message.subject,\n to: [{ email: message.to }],\n },\n },\n );\n return new Response(JSON.stringify(message));\n};\n";
|
|
238
|
+
|
|
239
|
+
// raw-loader:./templates/forex.ts?raw
|
|
240
|
+
var forex_default = "//\n// Copyright 2024 DXOS.org\n//\n\n/**\n * Returns the exchange rate between two currencies.\n */\nexport default async ({\n event: {\n data: { request },\n },\n}: any) => {\n const { args: [from = 'EUR', to = 'USD'] = [] } = await request.json();\n\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 new Response(rates[to].toString());\n};\n";
|
|
241
|
+
|
|
242
|
+
// packages/plugins/experimental/plugin-script/src/templates.ts
|
|
243
|
+
var removeHeader = (str) => str.split("\n").slice(4).join("\n");
|
|
244
|
+
var templates = [
|
|
245
|
+
{
|
|
246
|
+
id: "dxos.org/script/echo",
|
|
247
|
+
name: "Echo",
|
|
248
|
+
source: removeHeader(echo_default)
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
id: "dxos.org/script/forex",
|
|
252
|
+
name: "Forex",
|
|
253
|
+
source: removeHeader(forex_default)
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
id: "dxos.org/script/gpt",
|
|
257
|
+
name: "Gpt",
|
|
258
|
+
source: removeHeader(chat_default),
|
|
259
|
+
presetId: "dxos.org/function/gpt"
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
id: "dxos.org/script/chess",
|
|
263
|
+
name: "Chess",
|
|
264
|
+
source: removeHeader(chess_default),
|
|
265
|
+
presetId: "dxos.org/function/chess"
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
id: "dxos.org/script/email",
|
|
269
|
+
name: "Email",
|
|
270
|
+
source: removeHeader(email_default),
|
|
271
|
+
presetId: "dxos.org/function/email"
|
|
272
|
+
}
|
|
273
|
+
];
|
|
274
|
+
|
|
275
|
+
export {
|
|
276
|
+
initializeBundler,
|
|
277
|
+
Bundler,
|
|
278
|
+
templates
|
|
279
|
+
};
|
|
280
|
+
//# sourceMappingURL=chunk-LDLNTVAK.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/bundler/bundler.ts", "raw-loader:./templates/chat.ts?raw", "raw-loader:./templates/chess.ts?raw", "raw-loader:./templates/echo.ts?raw", "raw-loader:./templates/email.ts?raw", "raw-loader:./templates/forex.ts?raw", "../../../src/templates.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type BuildOptions } from 'esbuild';\nimport { build, initialize, type BuildResult, type Plugin } from 'esbuild-wasm';\n\nimport { subtleCrypto } from '@dxos/crypto';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nexport type Import = {\n moduleUrl: string;\n defaultImport: boolean;\n namedImports: string[];\n};\n\nexport type BundlerResult = {\n timestamp: number;\n sourceHash: Buffer;\n imports?: Import[];\n bundle?: string;\n error?: any;\n};\n\nexport type BundlerOptions = {\n platform: BuildOptions['platform'];\n sandboxedModules: string[];\n remoteModules: Record<string, string>;\n};\n\nlet initialized: Promise<void>;\nexport const initializeBundler = async (options: { wasmUrl: string }) => {\n await (initialized ??= initialize({\n wasmURL: options.wasmUrl,\n }));\n};\n\n/**\n * ESBuild bundler.\n */\nexport class Bundler {\n constructor(private readonly _options: BundlerOptions) {}\n\n async bundle(source: string): Promise<BundlerResult> {\n const { sandboxedModules: providedModules, ...options } = this._options;\n\n const createResult = async (result?: Partial<BundlerResult>) => {\n return {\n timestamp: Date.now(),\n sourceHash: Buffer.from(await subtleCrypto.digest('SHA-256', Buffer.from(source))),\n ...result,\n };\n };\n\n if (this._options.platform === 'browser') {\n invariant(initialized, 'Compiler not initialized.');\n await initialized;\n }\n\n const imports = analyzeSourceFileImports(source);\n\n // https://esbuild.github.io/api/#build\n try {\n const result = await build({\n platform: options.platform,\n conditions: ['workerd', 'browser'],\n metafile: true,\n write: false,\n entryPoints: ['memory:main.tsx'],\n bundle: true,\n format: 'esm',\n plugins: [\n {\n name: 'memory',\n setup: (build) => {\n build.onResolve({ filter: /^\\.\\/runtime\\.js$/ }, ({ path }) => {\n return { path, external: true };\n });\n\n build.onResolve({ filter: /^memory:/ }, ({ path }) => {\n return { path: path.split(':')[1], namespace: 'memory' };\n });\n\n build.onLoad({ filter: /.*/, namespace: 'memory' }, ({ path }) => {\n if (path === 'main.tsx') {\n return {\n contents: source,\n loader: 'tsx',\n };\n }\n });\n\n for (const module of providedModules) {\n build.onResolve({ filter: new RegExp(`^${module}$`) }, ({ path }) => {\n return { path, namespace: 'injected-module' };\n });\n }\n\n build.onLoad({ filter: /.*/, namespace: 'injected-module' }, ({ path }) => {\n const namedImports = imports.find((entry) => entry.moduleIdentifier === path)?.namedImports ?? [];\n return {\n contents: `\n const { ${namedImports.join(',')} } = window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}];\n export { ${namedImports.join(',')} };\n export default window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}].default;\n `,\n loader: 'tsx',\n };\n });\n },\n },\n httpPlugin,\n ],\n });\n\n log('compile complete', result.metafile);\n\n return await createResult({\n imports: this.analyzeImports(result),\n bundle: result.outputFiles![0].text,\n });\n } catch (err) {\n return await createResult({ error: err });\n }\n }\n\n // TODO(dmaretskyi): In the future we can replace the compiler with SWC with plugins running in WASM.\n analyzeImports(result: BuildResult): Import[] {\n invariant(result.outputFiles);\n\n // TODO(dmaretskyi): Support import aliases and wildcard imports.\n const parsedImports = allMatches(IMPORT_REGEX, result.outputFiles[0].text);\n return Object.values(result.metafile!.outputs)[0].imports.map((entry): Import => {\n const namedImports: string[] = [];\n\n const parsedImport = parsedImports.find((capture) => capture?.[4] === entry.path);\n if (parsedImport?.[2]) {\n NAMED_IMPORTS_REGEX.lastIndex = 0;\n const namedImportsMatch = NAMED_IMPORTS_REGEX.exec(parsedImport[2]);\n if (namedImportsMatch) {\n namedImportsMatch[1].split(',').forEach((importName) => {\n namedImports.push(importName.trim());\n });\n }\n }\n\n return {\n moduleUrl: entry.path,\n defaultImport: !!parsedImport?.[1],\n namedImports,\n };\n });\n }\n\n analyzeSourceFileImports(code: string) {\n // TODO(dmaretskyi): Support import aliases and wildcard imports.\n const parsedImports = allMatches(IMPORT_REGEX, code);\n return parsedImports.map((capture) => {\n return {\n defaultImportName: capture[1],\n namedImports: capture[2]?.split(',').map((importName) => importName.trim()),\n wildcardImportName: capture[3],\n moduleIdentifier: capture[4],\n quotes: capture[5],\n };\n });\n }\n}\n\n// https://regex101.com/r/FEN5ks/1\n// https://stackoverflow.com/a/73265022\n// $1 = default import name (can be non-existent)\n// $2 = destructured exports (can be non-existent)\n// $3 = wildcard import name (can be non-existent)\n// $4 = module identifier\n// $5 = quotes used (either ' or \")\nconst IMPORT_REGEX =\n /import(?:(?:(?:[ \\n\\t]+([^ *\\n\\t{},]+)[ \\n\\t]*(?:,|[ \\n\\t]+))?([ \\n\\t]*{(?:[ \\n\\t]*[^ \\n\\t\"'{}]+[ \\n\\t]*,?)+})?[ \\n\\t]*)|[ \\n\\t]*\\*[ \\n\\t]*as[ \\n\\t]+([^ \\n\\t{}]+)[ \\n\\t]+)from[ \\n\\t]*(?:['\"])([^'\"\\n]+)(['\"])/gm;\n\nconst NAMED_IMPORTS_REGEX = /[ \\n\\t]*{((?:[ \\n\\t]*[^ \\n\\t\"'{}]+[ \\n\\t]*,?)+)}[ \\n\\t]*/gm;\n\nconst allMatches = (regex: RegExp, str: string) => {\n regex.lastIndex = 0;\n\n let match;\n const matches = [];\n while ((match = regex.exec(str))) {\n matches.push(match);\n }\n\n return matches;\n};\n\ntype ParsedImport = {\n defaultImportName?: string;\n namedImports: string[];\n wildcardImportName?: string;\n moduleIdentifier: string;\n quotes: string;\n};\n\nconst analyzeSourceFileImports = (code: string): ParsedImport[] => {\n // TODO(dmaretskyi): Support import aliases and wildcard imports.\n const parsedImports = allMatches(IMPORT_REGEX, code);\n return parsedImports.map((capture) => {\n return {\n defaultImportName: capture[1],\n namedImports: capture[2]\n ?.trim()\n .slice(1, -1)\n .split(',')\n .map((importName) => importName.trim()),\n wildcardImportName: capture[3],\n moduleIdentifier: capture[4],\n quotes: capture[5],\n };\n });\n};\n\nconst httpPlugin: Plugin = {\n name: 'http',\n setup: (build) => {\n // Intercept import paths starting with \"http:\" and \"https:\" so esbuild doesn't attempt to map them to a file system location.\n // Tag them with the \"http-url\" namespace to associate them with this plugin.\n build.onResolve({ filter: /^https?:\\/\\// }, (args) => ({\n path: args.path,\n namespace: 'http-url',\n }));\n\n // We also want to intercept all import paths inside downloaded files and resolve them against the original URL.\n // All of these files will be in the \"http-url\" namespace.\n // Make sure to keep the newly resolved URL in the \"http-url\" namespace so imports inside it will also be resolved as URLs recursively.\n build.onResolve({ filter: /.*/, namespace: 'http-url' }, (args) => ({\n path: new URL(args.path, args.importer).toString(),\n namespace: 'http-url',\n }));\n\n // When a URL is loaded, we want to actually download the content from the internet.\n // This has just enough logic to be able to handle the example import from unpkg.com but in reality this would probably need to be more complex.\n build.onLoad({ filter: /.*/, namespace: 'http-url' }, async (args) => {\n const response = await fetch(args.path);\n return { contents: await response.text(), loader: 'jsx' };\n });\n },\n};\n", "//\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", "//\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", "//\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 ?? {}), { headers: { 'Content-Type': 'application/json' } });\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\n/**\n * Stores a message into ECHO Mailbox object.\n */\nexport default async ({\n event: {\n data: { request },\n },\n context: { space },\n}: any) => {\n const {\n data: {\n objects: [message],\n },\n } = await request.json();\n\n const mailbox = await space.crud.query({ __typename: 'dxos.org/type/MailboxType' }).first();\n if (!mailbox) {\n return new Response('Mailbox not found.', { status: 500 });\n }\n\n await space.crud.push(\n { id: mailbox.id },\n {\n sender: { email: message.from },\n timestamp: new Date(message.created).toISOString(),\n text: message.body,\n properties: {\n subject: message.subject,\n to: [{ email: message.to }],\n },\n },\n );\n return new Response(JSON.stringify(message));\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\n/**\n * Returns the exchange rate between two currencies.\n */\nexport default async ({\n event: {\n data: { request },\n },\n}: any) => {\n const { args: [from = 'EUR', to = 'USD'] = [] } = await request.json();\n\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 new Response(rates[to].toString());\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// @ts-ignore\nimport chat from './templates/chat.ts?raw';\n// @ts-ignore\nimport chess from './templates/chess.ts?raw';\n// @ts-ignore\nimport echo from './templates/echo.ts?raw';\n// @ts-ignore\nimport email from './templates/email.ts?raw';\n// @ts-ignore\nimport forex from './templates/forex.ts?raw';\n\nconst removeHeader = (str: string) => str.split('\\n').slice(4).join('\\n');\n\nexport type Template = {\n id: string;\n name: string;\n source: string;\n presetId?: string;\n};\n\nexport const templates: Template[] = [\n {\n id: 'dxos.org/script/echo',\n name: 'Echo',\n source: removeHeader(echo),\n },\n {\n id: 'dxos.org/script/forex',\n name: 'Forex',\n source: removeHeader(forex),\n },\n {\n id: 'dxos.org/script/gpt',\n name: 'Gpt',\n source: removeHeader(chat),\n presetId: 'dxos.org/function/gpt',\n },\n {\n id: 'dxos.org/script/chess',\n name: 'Chess',\n source: removeHeader(chess),\n presetId: 'dxos.org/function/chess',\n },\n {\n id: 'dxos.org/script/email',\n name: 'Email',\n source: removeHeader(email),\n presetId: 'dxos.org/function/email',\n },\n];\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["build", "initialize", "subtleCrypto", "invariant", "log", "initialized", "initializeBundler", "options", "wasmURL", "wasmUrl", "Bundler", "constructor", "_options", "bundle", "source", "sandboxedModules", "providedModules", "createResult", "result", "timestamp", "Date", "now", "sourceHash", "Buffer", "from", "digest", "platform", "imports", "analyzeSourceFileImports", "conditions", "metafile", "write", "entryPoints", "format", "plugins", "name", "setup", "onResolve", "filter", "path", "external", "split", "namespace", "onLoad", "contents", "loader", "module", "RegExp", "namedImports", "find", "entry", "moduleIdentifier", "join", "JSON", "stringify", "httpPlugin", "analyzeImports", "outputFiles", "text", "err", "error", "parsedImports", "allMatches", "IMPORT_REGEX", "Object", "values", "outputs", "map", "parsedImport", "capture", "NAMED_IMPORTS_REGEX", "lastIndex", "namedImportsMatch", "exec", "forEach", "importName", "push", "trim", "moduleUrl", "defaultImport", "code", "defaultImportName", "wildcardImportName", "quotes", "regex", "str", "match", "matches", "slice", "args", "URL", "importer", "toString", "response", "fetch", "removeHeader", "str", "split", "slice", "join", "templates", "id", "name", "source", "echo", "forex", "chat", "presetId", "chess", "email"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
HeaderCodec,
|
|
4
|
+
USERFUNCTIONS_PRESET_META_KEY,
|
|
5
|
+
codec,
|
|
6
|
+
getUserFunctionUrlInMetadata,
|
|
7
|
+
matchServiceCredential,
|
|
8
|
+
publicKeyToDid,
|
|
9
|
+
setUserFunctionUrlInMetadata,
|
|
10
|
+
uploadWorkerFunction
|
|
11
|
+
} from "../chunk-2NX3HWPM.mjs";
|
|
12
|
+
export {
|
|
13
|
+
HeaderCodec,
|
|
14
|
+
USERFUNCTIONS_PRESET_META_KEY,
|
|
15
|
+
codec,
|
|
16
|
+
getUserFunctionUrlInMetadata,
|
|
17
|
+
matchServiceCredential,
|
|
18
|
+
publicKeyToDid,
|
|
19
|
+
setUserFunctionUrlInMetadata,
|
|
20
|
+
uploadWorkerFunction
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
Bundler,
|
|
4
|
+
initializeBundler,
|
|
5
|
+
templates
|
|
6
|
+
} from "./chunk-LDLNTVAK.mjs";
|
|
7
|
+
import {
|
|
8
|
+
FunctionType,
|
|
9
|
+
ScriptAction,
|
|
10
|
+
ScriptType
|
|
11
|
+
} from "./chunk-7EDYDVQH.mjs";
|
|
12
|
+
import {
|
|
13
|
+
SCRIPT_PLUGIN,
|
|
14
|
+
meta_default
|
|
15
|
+
} from "./chunk-GO7HYFM5.mjs";
|
|
16
|
+
|
|
17
|
+
// packages/plugins/experimental/plugin-script/src/ScriptPlugin.tsx
|
|
18
|
+
import wasmUrl from "esbuild-wasm/esbuild.wasm?url";
|
|
19
|
+
import React3 from "react";
|
|
20
|
+
import { parseIntentPlugin, resolvePlugin, NavigationAction } from "@dxos/app-framework";
|
|
21
|
+
import { create } from "@dxos/echo-schema";
|
|
22
|
+
import { parseClientPlugin } from "@dxos/plugin-client";
|
|
23
|
+
import { createExtension, isActionGroup } from "@dxos/plugin-graph";
|
|
24
|
+
import { TextType } from "@dxos/plugin-markdown/types";
|
|
25
|
+
import { SpaceAction } from "@dxos/plugin-space";
|
|
26
|
+
import { loadObjectReferences } from "@dxos/react-client/echo";
|
|
27
|
+
|
|
28
|
+
// packages/plugins/experimental/plugin-script/src/compiler/compiler.ts
|
|
29
|
+
import { createDefaultMapFromCDN, createSystem, createVirtualTypeScriptEnvironment } from "@typescript/vfs";
|
|
30
|
+
import ts from "typescript";
|
|
31
|
+
import { invariant } from "@dxos/invariant";
|
|
32
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-script/src/compiler/compiler.ts";
|
|
33
|
+
var defaultOptions = {
|
|
34
|
+
lib: [
|
|
35
|
+
"DOM",
|
|
36
|
+
"es2022"
|
|
37
|
+
],
|
|
38
|
+
target: ts.ScriptTarget.ES2022
|
|
39
|
+
};
|
|
40
|
+
var Compiler = class {
|
|
41
|
+
constructor(_options = defaultOptions) {
|
|
42
|
+
this._options = _options;
|
|
43
|
+
}
|
|
44
|
+
async initialize() {
|
|
45
|
+
if (this._env) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
this._fsMap = await createDefaultMapFromCDN(this._options, "5.5.4", true, ts);
|
|
49
|
+
const system = createSystem(this._fsMap);
|
|
50
|
+
this._env = createVirtualTypeScriptEnvironment(system, [], ts, this._options);
|
|
51
|
+
}
|
|
52
|
+
get environment() {
|
|
53
|
+
invariant(this._env, "Compiler environment not initialized.", {
|
|
54
|
+
F: __dxlog_file,
|
|
55
|
+
L: 39,
|
|
56
|
+
S: this,
|
|
57
|
+
A: [
|
|
58
|
+
"this._env",
|
|
59
|
+
"'Compiler environment not initialized.'"
|
|
60
|
+
]
|
|
61
|
+
});
|
|
62
|
+
return this._env;
|
|
63
|
+
}
|
|
64
|
+
setFile(fileName, content) {
|
|
65
|
+
invariant(this._fsMap, "File system map not initialized.", {
|
|
66
|
+
F: __dxlog_file,
|
|
67
|
+
L: 44,
|
|
68
|
+
S: this,
|
|
69
|
+
A: [
|
|
70
|
+
"this._fsMap",
|
|
71
|
+
"'File system map not initialized.'"
|
|
72
|
+
]
|
|
73
|
+
});
|
|
74
|
+
this.environment.createFile(fileName, content);
|
|
75
|
+
}
|
|
76
|
+
compile(fileName) {
|
|
77
|
+
return this.environment.languageService.getEmitOutput(fileName);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// packages/plugins/experimental/plugin-script/src/components/index.ts
|
|
82
|
+
import React2 from "react";
|
|
83
|
+
|
|
84
|
+
// packages/plugins/experimental/plugin-script/src/components/ScriptSettings/ScriptSettings.tsx
|
|
85
|
+
import React from "react";
|
|
86
|
+
import { SettingsValue } from "@dxos/plugin-settings";
|
|
87
|
+
import { useClient } from "@dxos/react-client";
|
|
88
|
+
import { Button, useTranslation } from "@dxos/react-ui";
|
|
89
|
+
var ScriptSettings = ({ settings }) => {
|
|
90
|
+
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
91
|
+
const client = useClient();
|
|
92
|
+
const handleAuthenticate = async () => {
|
|
93
|
+
const { identityKey } = client.halo.identity.get();
|
|
94
|
+
await client.halo.writeCredentials([
|
|
95
|
+
{
|
|
96
|
+
issuer: identityKey,
|
|
97
|
+
issuanceDate: /* @__PURE__ */ new Date(),
|
|
98
|
+
subject: {
|
|
99
|
+
id: identityKey,
|
|
100
|
+
assertion: {
|
|
101
|
+
"@type": "dxos.halo.credentials.ServiceAccess",
|
|
102
|
+
serverName: "hub.dxos.network",
|
|
103
|
+
serverKey: identityKey,
|
|
104
|
+
identityKey,
|
|
105
|
+
capabilities: [
|
|
106
|
+
"composer:beta"
|
|
107
|
+
]
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
]);
|
|
112
|
+
};
|
|
113
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(SettingsValue, {
|
|
114
|
+
label: t("authenticate action label")
|
|
115
|
+
}, /* @__PURE__ */ React.createElement(Button, {
|
|
116
|
+
onClick: handleAuthenticate
|
|
117
|
+
}, t("authenticate button label"))));
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// packages/plugins/experimental/plugin-script/src/components/index.ts
|
|
121
|
+
var ScriptContainer = React2.lazy(() => import("./ScriptContainer-EAE6L5JV.mjs"));
|
|
122
|
+
|
|
123
|
+
// packages/plugins/experimental/plugin-script/src/translations.ts
|
|
124
|
+
var translations_default = [
|
|
125
|
+
{
|
|
126
|
+
"en-US": {
|
|
127
|
+
[SCRIPT_PLUGIN]: {
|
|
128
|
+
"plugin name": "Scripts",
|
|
129
|
+
"object title placeholder": "New script",
|
|
130
|
+
"create object label": "Create script",
|
|
131
|
+
"create stack section label": "Create script",
|
|
132
|
+
"binding placeholder": "Function name",
|
|
133
|
+
"function request placeholder": "Function request",
|
|
134
|
+
"deploy label": "Deploy",
|
|
135
|
+
"deployed label": "Current version of the script is deployed",
|
|
136
|
+
"upload failed label": "Upload failed",
|
|
137
|
+
"copy link label": "Copy function link",
|
|
138
|
+
"format label": "Format",
|
|
139
|
+
"toggle details label": "Toggle details panel",
|
|
140
|
+
"authenticate action label": "Authenticate functions service",
|
|
141
|
+
"authenticate button label": "Authenticate"
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
];
|
|
146
|
+
|
|
147
|
+
// packages/plugins/experimental/plugin-script/src/ScriptPlugin.tsx
|
|
148
|
+
var ScriptPlugin = () => {
|
|
149
|
+
const compiler = new Compiler();
|
|
150
|
+
return {
|
|
151
|
+
meta: meta_default,
|
|
152
|
+
initialize: async () => {
|
|
153
|
+
await compiler.initialize();
|
|
154
|
+
compiler.setFile("/src/typings.d.ts", "declare module 'https://*';");
|
|
155
|
+
compiler.setFile("/src/runtime.ts", `
|
|
156
|
+
export const Filter: any = {};
|
|
157
|
+
export type FunctionHandler = ({ event, context }: { event: any; context: any }) => Promise<Response>;
|
|
158
|
+
export const functionHandler = (handler: FunctionHandler) => handler;
|
|
159
|
+
`);
|
|
160
|
+
await initializeBundler({
|
|
161
|
+
wasmUrl
|
|
162
|
+
});
|
|
163
|
+
},
|
|
164
|
+
provides: {
|
|
165
|
+
settings: {},
|
|
166
|
+
metadata: {
|
|
167
|
+
records: {
|
|
168
|
+
[ScriptType.typename]: {
|
|
169
|
+
placeholder: [
|
|
170
|
+
"object title placeholder",
|
|
171
|
+
{
|
|
172
|
+
ns: SCRIPT_PLUGIN
|
|
173
|
+
}
|
|
174
|
+
],
|
|
175
|
+
icon: "ph--code--regular",
|
|
176
|
+
// TODO(wittjosiah): Move out of metadata.
|
|
177
|
+
loadReferences: (script) => loadObjectReferences(script, (script2) => [
|
|
178
|
+
script2.source
|
|
179
|
+
])
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
translations: translations_default,
|
|
184
|
+
echo: {
|
|
185
|
+
schema: [
|
|
186
|
+
ScriptType,
|
|
187
|
+
FunctionType
|
|
188
|
+
]
|
|
189
|
+
},
|
|
190
|
+
space: {
|
|
191
|
+
onSpaceCreate: {
|
|
192
|
+
label: [
|
|
193
|
+
"create object label",
|
|
194
|
+
{
|
|
195
|
+
ns: SCRIPT_PLUGIN
|
|
196
|
+
}
|
|
197
|
+
],
|
|
198
|
+
action: ScriptAction.CREATE
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
graph: {
|
|
202
|
+
builder: (plugins) => {
|
|
203
|
+
const client = resolvePlugin(plugins, parseClientPlugin)?.provides.client;
|
|
204
|
+
const dispatch = resolvePlugin(plugins, parseIntentPlugin)?.provides.intent.dispatch;
|
|
205
|
+
if (!client || !dispatch) {
|
|
206
|
+
return [];
|
|
207
|
+
}
|
|
208
|
+
return createExtension({
|
|
209
|
+
id: ScriptAction.CREATE,
|
|
210
|
+
filter: (node) => isActionGroup(node) && node.id.startsWith(SpaceAction.ADD_OBJECT),
|
|
211
|
+
actions: ({ node }) => {
|
|
212
|
+
const id = node.id.split("/").at(-1);
|
|
213
|
+
const [spaceId, objectId] = id?.split(":") ?? [];
|
|
214
|
+
const space = client.spaces.get().find((space2) => space2.id === spaceId);
|
|
215
|
+
const object = objectId && space?.db.getObjectById(objectId);
|
|
216
|
+
const target = objectId ? object : space;
|
|
217
|
+
if (!target) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
return [
|
|
221
|
+
{
|
|
222
|
+
id: `${SCRIPT_PLUGIN}/create/${node.id}`,
|
|
223
|
+
data: async () => {
|
|
224
|
+
await dispatch([
|
|
225
|
+
{
|
|
226
|
+
plugin: SCRIPT_PLUGIN,
|
|
227
|
+
action: ScriptAction.CREATE
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
action: SpaceAction.ADD_OBJECT,
|
|
231
|
+
data: {
|
|
232
|
+
target
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
action: NavigationAction.OPEN
|
|
237
|
+
}
|
|
238
|
+
]);
|
|
239
|
+
},
|
|
240
|
+
properties: {
|
|
241
|
+
label: [
|
|
242
|
+
"create object label",
|
|
243
|
+
{
|
|
244
|
+
ns: SCRIPT_PLUGIN
|
|
245
|
+
}
|
|
246
|
+
],
|
|
247
|
+
icon: "ph--code--regular",
|
|
248
|
+
testId: "scriptPlugin.createObject"
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
];
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
surface: {
|
|
257
|
+
component: ({ data, role }) => {
|
|
258
|
+
switch (role) {
|
|
259
|
+
case "settings": {
|
|
260
|
+
return data.plugin === meta_default.id ? /* @__PURE__ */ React3.createElement(ScriptSettings, {
|
|
261
|
+
settings: {}
|
|
262
|
+
}) : null;
|
|
263
|
+
}
|
|
264
|
+
case "article": {
|
|
265
|
+
if (data.object instanceof ScriptType) {
|
|
266
|
+
return /* @__PURE__ */ React3.createElement(ScriptContainer, {
|
|
267
|
+
script: data.object,
|
|
268
|
+
env: compiler.environment
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
intent: {
|
|
278
|
+
resolver: (intent) => {
|
|
279
|
+
switch (intent.action) {
|
|
280
|
+
case ScriptAction.CREATE: {
|
|
281
|
+
return {
|
|
282
|
+
data: create(ScriptType, {
|
|
283
|
+
source: create(TextType, {
|
|
284
|
+
content: templates[0].source
|
|
285
|
+
})
|
|
286
|
+
})
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
// packages/plugins/experimental/plugin-script/src/index.ts
|
|
297
|
+
var src_default = ScriptPlugin;
|
|
298
|
+
export {
|
|
299
|
+
Bundler,
|
|
300
|
+
Compiler,
|
|
301
|
+
FunctionType,
|
|
302
|
+
ScriptAction,
|
|
303
|
+
ScriptContainer,
|
|
304
|
+
ScriptPlugin,
|
|
305
|
+
ScriptSettings,
|
|
306
|
+
ScriptType,
|
|
307
|
+
src_default as default,
|
|
308
|
+
initializeBundler
|
|
309
|
+
};
|
|
310
|
+
//# sourceMappingURL=index.mjs.map
|