@dxos/plugin-script 0.6.14-staging.8758a12 → 0.6.14-staging.9b873ce
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/{AutomationPanel-XLL2ZXGS.mjs → AutomationPanel-F2SAN67R.mjs} +3 -3
- package/dist/lib/browser/{ScriptContainer-YXH4MFEO.mjs → ScriptContainer-F2DFCOHF.mjs} +19 -8
- package/dist/lib/browser/{ScriptContainer-YXH4MFEO.mjs.map → ScriptContainer-F2DFCOHF.mjs.map} +3 -3
- package/dist/lib/browser/{chunk-G6H56WFS.mjs → chunk-4UTRJLQ3.mjs} +11 -3
- package/dist/lib/browser/chunk-4UTRJLQ3.mjs.map +7 -0
- package/dist/lib/browser/{chunk-KHNN3F7J.mjs → chunk-5GGRYRS4.mjs} +5 -5
- package/dist/lib/browser/{chunk-KHNN3F7J.mjs.map → chunk-5GGRYRS4.mjs.map} +2 -2
- package/dist/lib/browser/{chunk-USXWNH3S.mjs → chunk-JBXEMQ6S.mjs} +4 -3
- package/dist/lib/browser/chunk-JBXEMQ6S.mjs.map +7 -0
- package/dist/lib/browser/edge/index.mjs +1 -1
- package/dist/lib/browser/index.mjs +5 -5
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/types/index.mjs +1 -1
- package/dist/lib/node/{AutomationPanel-OSPAFWZU.cjs → AutomationPanel-M5UHEMPG.cjs} +12 -12
- package/dist/lib/node/{ScriptContainer-FWHFEIHK.cjs → ScriptContainer-X76C7OD2.cjs} +32 -21
- package/dist/lib/node/{ScriptContainer-FWHFEIHK.cjs.map → ScriptContainer-X76C7OD2.cjs.map} +3 -3
- package/dist/lib/node/{chunk-ACLCRWDB.cjs → chunk-WPP65EYS.cjs} +14 -6
- package/dist/lib/node/chunk-WPP65EYS.cjs.map +7 -0
- package/dist/lib/node/{chunk-FY5KKL5N.cjs → chunk-XS6GEYYH.cjs} +8 -8
- package/dist/lib/node/{chunk-FY5KKL5N.cjs.map → chunk-XS6GEYYH.cjs.map} +2 -2
- package/dist/lib/node/{chunk-CPNHUAFN.cjs → chunk-ZTUFXDTH.cjs} +6 -5
- package/dist/lib/node/chunk-ZTUFXDTH.cjs.map +7 -0
- package/dist/lib/node/edge/index.cjs +10 -10
- package/dist/lib/node/edge/index.cjs.map +1 -1
- package/dist/lib/node/index.cjs +26 -26
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/types/index.cjs +4 -4
- package/dist/lib/node/types/index.cjs.map +1 -1
- package/dist/lib/node-esm/{AutomationPanel-KJNL6ARP.mjs → AutomationPanel-JQ2NLXYS.mjs} +3 -3
- package/dist/lib/node-esm/{ScriptContainer-6U5WJFRB.mjs → ScriptContainer-KXUHDS5D.mjs} +19 -8
- package/dist/lib/node-esm/{ScriptContainer-6U5WJFRB.mjs.map → ScriptContainer-KXUHDS5D.mjs.map} +3 -3
- package/dist/lib/node-esm/{chunk-2NPZGQGA.mjs → chunk-3QSMHAWD.mjs} +4 -3
- package/dist/lib/node-esm/chunk-3QSMHAWD.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-LDLNTVAK.mjs → chunk-4SRPREUK.mjs} +11 -3
- package/dist/lib/node-esm/chunk-4SRPREUK.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-QMTTZYLF.mjs → chunk-V74XKPLC.mjs} +5 -5
- package/dist/lib/node-esm/{chunk-QMTTZYLF.mjs.map → chunk-V74XKPLC.mjs.map} +2 -2
- package/dist/lib/node-esm/edge/index.mjs +1 -1
- package/dist/lib/node-esm/index.mjs +5 -5
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/types/index.mjs +1 -1
- package/dist/types/src/bundler/bundler.d.ts.map +1 -1
- package/dist/types/src/components/ScriptEditor.d.ts.map +1 -1
- package/dist/types/src/edge/functions.d.ts +4 -1
- package/dist/types/src/edge/functions.d.ts.map +1 -1
- package/dist/types/src/types/script.d.ts +3 -1
- package/dist/types/src/types/script.d.ts.map +1 -1
- package/package.json +36 -36
- package/src/bundler/bundler.ts +4 -0
- package/src/components/ScriptEditor.tsx +9 -3
- package/src/edge/functions.ts +4 -1
- package/src/types/script.ts +2 -1
- package/dist/lib/browser/chunk-G6H56WFS.mjs.map +0 -7
- package/dist/lib/browser/chunk-USXWNH3S.mjs.map +0 -7
- package/dist/lib/node/chunk-ACLCRWDB.cjs.map +0 -7
- package/dist/lib/node/chunk-CPNHUAFN.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-2NPZGQGA.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-LDLNTVAK.mjs.map +0 -7
- /package/dist/lib/browser/{AutomationPanel-XLL2ZXGS.mjs.map → AutomationPanel-F2SAN67R.mjs.map} +0 -0
- /package/dist/lib/node/{AutomationPanel-OSPAFWZU.cjs.map → AutomationPanel-M5UHEMPG.cjs.map} +0 -0
- /package/dist/lib/node-esm/{AutomationPanel-KJNL6ARP.mjs.map → AutomationPanel-JQ2NLXYS.mjs.map} +0 -0
|
@@ -16,13 +16,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
19
|
+
var chunk_WPP65EYS_exports = {};
|
|
20
|
+
__export(chunk_WPP65EYS_exports, {
|
|
21
21
|
Bundler: () => Bundler,
|
|
22
22
|
initializeBundler: () => initializeBundler,
|
|
23
23
|
templates: () => templates
|
|
24
24
|
});
|
|
25
|
-
module.exports = __toCommonJS(
|
|
25
|
+
module.exports = __toCommonJS(chunk_WPP65EYS_exports);
|
|
26
26
|
var import_esbuild_wasm = require("esbuild-wasm");
|
|
27
27
|
var import_crypto = require("@dxos/crypto");
|
|
28
28
|
var import_invariant = require("@dxos/invariant");
|
|
@@ -86,6 +86,14 @@ var Bundler = class {
|
|
|
86
86
|
external: true
|
|
87
87
|
};
|
|
88
88
|
});
|
|
89
|
+
build2.onResolve({
|
|
90
|
+
filter: /^dxos:functions$/
|
|
91
|
+
}, ({ path }) => {
|
|
92
|
+
return {
|
|
93
|
+
path: "./runtime.js",
|
|
94
|
+
external: true
|
|
95
|
+
};
|
|
96
|
+
});
|
|
89
97
|
build2.onResolve({
|
|
90
98
|
filter: /^memory:/
|
|
91
99
|
}, ({ path }) => {
|
|
@@ -136,7 +144,7 @@ var Bundler = class {
|
|
|
136
144
|
});
|
|
137
145
|
(0, import_log.log)("compile complete", result.metafile, {
|
|
138
146
|
F: __dxlog_file,
|
|
139
|
-
L:
|
|
147
|
+
L: 121,
|
|
140
148
|
S: this,
|
|
141
149
|
C: (f, a) => f(...a)
|
|
142
150
|
});
|
|
@@ -154,7 +162,7 @@ var Bundler = class {
|
|
|
154
162
|
analyzeImports(result) {
|
|
155
163
|
(0, import_invariant.invariant)(result.outputFiles, void 0, {
|
|
156
164
|
F: __dxlog_file,
|
|
157
|
-
L:
|
|
165
|
+
L: 134,
|
|
158
166
|
S: this,
|
|
159
167
|
A: [
|
|
160
168
|
"result.outputFiles",
|
|
@@ -287,4 +295,4 @@ var templates = [
|
|
|
287
295
|
initializeBundler,
|
|
288
296
|
templates
|
|
289
297
|
});
|
|
290
|
-
//# sourceMappingURL=chunk-
|
|
298
|
+
//# sourceMappingURL=chunk-WPP65EYS.cjs.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: /^dxos:functions$/ }, ({ path }) => {\n return { path: './runtime.js', 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),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AAI7C,MAAM,IAAA,EAAMgD,MAAM,CAAA,EAAGrC,KAAK,IAAA;AAS7D,IAAM6C,YAAwB;EACnC;IACEC,IAAI;IACJ/D,MAAM;IACNxB,QAAQqF,aAAaG,YAAAA;EACvB;EACA;IACED,IAAI;IACJ/D,MAAM;IACNxB,QAAQqF,aAAaI,aAAAA;EACvB;EACA;IACEF,IAAI;IACJ/D,MAAM;IACNxB,QAAQqF,aAAaK,YAAAA;IACrBC,UAAU;EACZ;EACA;IACEJ,IAAI;IACJ/D,MAAM;IACNxB,QAAQqF,aAAaO,aAAAA;IACrBD,UAAU;EACZ;EACA;IACEJ,IAAI;IACJ/D,MAAM;IACNxB,QAAQqF,aAAaQ,aAAAA;IACrBF,UAAU;EACZ;;",
|
|
6
|
+
"names": ["initialized", "initializeBundler", "options", "initialize", "wasmURL", "wasmUrl", "Bundler", "constructor", "_options", "bundle", "source", "sandboxedModules", "providedModules", "createResult", "result", "timestamp", "Date", "now", "sourceHash", "Buffer", "from", "subtleCrypto", "digest", "platform", "invariant", "imports", "analyzeSourceFileImports", "build", "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", "log", "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", "templates", "id", "echo", "forex", "chat", "presetId", "chess", "email"]
|
|
7
|
+
}
|
|
@@ -16,8 +16,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
19
|
+
var chunk_XS6GEYYH_exports = {};
|
|
20
|
+
__export(chunk_XS6GEYYH_exports, {
|
|
21
21
|
HeaderCodec: () => HeaderCodec,
|
|
22
22
|
USERFUNCTIONS_PRESET_META_KEY: () => USERFUNCTIONS_PRESET_META_KEY,
|
|
23
23
|
codec: () => codec,
|
|
@@ -28,7 +28,7 @@ __export(chunk_FY5KKL5N_exports, {
|
|
|
28
28
|
setUserFunctionUrlInMetadata: () => setUserFunctionUrlInMetadata,
|
|
29
29
|
uploadWorkerFunction: () => uploadWorkerFunction
|
|
30
30
|
});
|
|
31
|
-
module.exports = __toCommonJS(
|
|
31
|
+
module.exports = __toCommonJS(chunk_XS6GEYYH_exports);
|
|
32
32
|
var import_keys = require("@dxos/keys");
|
|
33
33
|
var import_async = require("@dxos/async");
|
|
34
34
|
var import_invariant = require("@dxos/invariant");
|
|
@@ -154,7 +154,7 @@ var uploadWorkerFunction = async ({ clientConfig, halo, name, source, ownerDid,
|
|
|
154
154
|
uploadUrl: uploadUrl.toString()
|
|
155
155
|
}, {
|
|
156
156
|
F: __dxlog_file,
|
|
157
|
-
L:
|
|
157
|
+
L: 76,
|
|
158
158
|
S: void 0,
|
|
159
159
|
C: (f, a) => f(...a)
|
|
160
160
|
});
|
|
@@ -178,7 +178,7 @@ var uploadWorkerFunction = async ({ clientConfig, halo, name, source, ownerDid,
|
|
|
178
178
|
res
|
|
179
179
|
}, {
|
|
180
180
|
F: __dxlog_file,
|
|
181
|
-
L:
|
|
181
|
+
L: 87,
|
|
182
182
|
S: void 0,
|
|
183
183
|
C: (f, a) => f(...a)
|
|
184
184
|
});
|
|
@@ -227,13 +227,13 @@ var presentationForIdentity = async ({ halo, timeout }) => {
|
|
|
227
227
|
credential
|
|
228
228
|
}, {
|
|
229
229
|
F: __dxlog_file,
|
|
230
|
-
L:
|
|
230
|
+
L: 133,
|
|
231
231
|
S: void 0,
|
|
232
232
|
C: (f, a) => f(...a)
|
|
233
233
|
});
|
|
234
234
|
(0, import_invariant.invariant)(credential.id, "beta credential missing id", {
|
|
235
235
|
F: __dxlog_file,
|
|
236
|
-
L:
|
|
236
|
+
L: 135,
|
|
237
237
|
S: void 0,
|
|
238
238
|
A: [
|
|
239
239
|
"credential.id",
|
|
@@ -270,4 +270,4 @@ var getInvocationUrl = (functionUrl, edgeUrl, options = {}) => {
|
|
|
270
270
|
setUserFunctionUrlInMetadata,
|
|
271
271
|
uploadWorkerFunction
|
|
272
272
|
});
|
|
273
|
-
//# sourceMappingURL=chunk-
|
|
273
|
+
//# sourceMappingURL=chunk-XS6GEYYH.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/edge/codec.ts", "../../../src/edge/header-codec.ts", "../../../src/edge/functions.ts", "../../../src/edge/hub-protocol.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { PublicKey } from '@dxos/keys';\n\nimport { HeaderCodec, type EncodedKey } from './header-codec';\n\nexport const codec = new HeaderCodec<PublicKey>({\n isKey: (value: any): value is PublicKey => value instanceof PublicKey,\n encode: (key: PublicKey): EncodedKey => ({ __k: key.toHex() }),\n decode: (value: EncodedKey): PublicKey => PublicKey.fromHex(value.__k),\n});\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// TODO(burdon): Factor out from @dxos/hub-protocol\n\nconst ENCODING = 'base64';\n\nexport type EncodedKey = { __k: string };\n\nexport type EncodedBytes = { __b: string };\n\nexport type EncodedTimestamp = { __t: number };\n\nexport interface KeyCodec<KeyType> {\n isKey(value: any): value is KeyType;\n encode(key: KeyType): EncodedKey;\n decode(value: EncodedKey): KeyType;\n}\n\n// TODO(wittjosiah): Use deepMapValues from @dxos/util -- it handles recursion for you.\nexport class HeaderCodec<Key> {\n constructor(private readonly _keyCodec: KeyCodec<Key>) {}\n\n encode(obj: any): string {\n const objectToEncode = this._prepareForEncoding(obj);\n const encoded = Buffer.from(JSON.stringify(objectToEncode));\n return encoded.toString(ENCODING);\n }\n\n decode<Type>(buffer: string): Type {\n const json = JSON.parse(Buffer.from(buffer, ENCODING).toString());\n return this._decodeRecursive(json);\n }\n\n private _decodeRecursive(obj: any): any {\n return this._recurse(obj, (value) => {\n if (isEncodedBytes(value)) {\n return decodeBytes(value.__b);\n }\n if (isEncodedKey(value)) {\n return this._keyCodec.decode(value);\n }\n if (isEncodedDate(value)) {\n return decodeDate(value);\n }\n return null;\n });\n }\n\n private _prepareForEncoding(obj: any): any {\n return this._recurse(obj, (value) => {\n if (value instanceof Uint8Array) {\n return { __b: encodeBytes(value) };\n }\n if (this._keyCodec.isKey(value)) {\n return this._keyCodec.encode(value);\n }\n if (value instanceof Date) {\n return encodeDate(value);\n }\n return null;\n });\n }\n\n private _recurse(obj: any, handler: (obj: object) => any | null): any {\n if (typeof obj !== 'object') {\n return obj;\n }\n const handled = handler(obj);\n if (handled != null) {\n return handled;\n }\n if (Array.isArray(obj)) {\n const result = [];\n for (const elem of obj) {\n result.push(this._recurse(elem, handler));\n }\n return result;\n }\n const result: any = {};\n for (const [key, value] of Object.entries(obj)) {\n result[key] = this._recurse(value, handler);\n }\n return result;\n }\n}\n\nconst isEncodedKey = (obj: object): obj is EncodedKey => '__k' in obj && typeof obj.__k === 'string';\nconst isEncodedBytes = (obj: object): obj is EncodedBytes => '__b' in obj && typeof obj.__b === 'string';\nconst isEncodedDate = (obj: object): obj is EncodedTimestamp => '__t' in obj && typeof obj.__t === 'number';\n\nconst encodeDate = (date: Date) => ({ __t: date.getTime() });\nconst decodeDate = (timestamp: EncodedTimestamp) => new Date(timestamp.__t);\n\nconst encodeBytes = (bytes: Uint8Array) => Buffer.from(bytes).toString(ENCODING);\nconst decodeBytes = (bytes: string) => Buffer.from(bytes, ENCODING);\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type DID } from 'iso-did/types';\n\nimport { Trigger } from '@dxos/async';\nimport { type Config } from '@dxos/client';\nimport { type Halo } from '@dxos/client-protocol';\nimport { type ObjectMeta } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport type { SpaceId } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';\n\nimport { codec } from './codec';\nimport { matchServiceCredential } from './hub-protocol';\n\n// TODO: use URL scheme for source?\nconst USERFUNCTIONS_META_KEY = 'dxos.org/service/function';\nexport const USERFUNCTIONS_PRESET_META_KEY = 'dxos.org/service/function-preset';\nconst USERFUNCTIONS_CREDENTIAL_CAPABILITY = 'composer:beta';\n\n// TODO: Synchronize API types with server\nexport type UserFunctionUploadResult = {\n result: 'success' | 'error';\n errorMessage?: string;\n functionId?: string;\n functionVersionNumber?: number;\n};\n\nexport type UploadWorkerProps = {\n clientConfig: Config;\n halo: Halo;\n name?: string;\n source: string;\n functionId?: string;\n ownerDid: DID;\n credentialLoadTimeout?: number; // ms to wait for credentials to load\n};\n\n// TODO(burdon): Config.\nconst defaultUserFunctionsBaseUrl = 'https://edge-main.dxos.workers.dev/functions'; // 'http://localhost:8600';\n\nconst getBaseUrl = (config: Config) => {\n if (config.values.runtime?.services?.edge?.url) {\n const url = new URL('/functions', config.values.runtime?.services?.edge?.url);\n url.protocol = 'https';\n return url.toString();\n } else {\n return defaultUserFunctionsBaseUrl;\n }\n};\n\nexport const uploadWorkerFunction = async ({\n clientConfig,\n halo,\n name,\n source,\n ownerDid,\n functionId,\n credentialLoadTimeout,\n}: UploadWorkerProps) => {\n const identity = halo.identity.get();\n if (!identity) {\n throw new Error('Identity not available');\n }\n const userFunctionsBaseUrl = getBaseUrl(clientConfig);\n\n // TODO: codify naming convention\n const uploadUrl = `${userFunctionsBaseUrl}/${ownerDid}` + (functionId ? `/${functionId}` : '');\n\n log('Upload', { functionId, source, name, identityKey: identity.identityKey, uploadUrl: uploadUrl.toString() });\n const response = await fetch(uploadUrl, {\n method: 'PUT',\n body: JSON.stringify({ script: source, name }),\n headers: await presentationForIdentity({ halo, timeout: credentialLoadTimeout }),\n });\n if (!response.ok) {\n return (await response.json()) as UserFunctionUploadResult;\n }\n\n const res = await response.json();\n log('Upload response', { status: response.status, res });\n\n return res as UserFunctionUploadResult;\n};\n\nexport const getUserFunctionUrlInMetadata = (meta: ObjectMeta) => {\n return meta.keys.find((key) => key.source === USERFUNCTIONS_META_KEY)?.id;\n};\n\nexport const setUserFunctionUrlInMetadata = (meta: ObjectMeta, functionUrl: string) => {\n const key = meta.keys.find((key) => key.source === USERFUNCTIONS_META_KEY);\n if (key) {\n if (key.id !== functionUrl) {\n throw new Error('Metadata mismatch');\n }\n } else {\n meta.keys.push({ source: USERFUNCTIONS_META_KEY, id: functionUrl });\n }\n};\n\n// TODO: handle team owner\n\nconst presentationForIdentity = async ({ halo, timeout }: { halo: Halo; timeout?: number }) => {\n let credential: Credential | undefined;\n\n if (timeout) {\n const credentialsLoaded = new Trigger();\n halo.credentials.subscribe((c) => {\n credential = c.find(matchServiceCredential([USERFUNCTIONS_CREDENTIAL_CAPABILITY]));\n if (credential) {\n credentialsLoaded.wake();\n }\n });\n await credentialsLoaded.wait({\n timeout,\n });\n } else {\n credential = halo\n .queryCredentials()\n .toSorted((a, b) => b.issuanceDate.getTime() - a.issuanceDate.getTime())\n .find(matchServiceCredential([USERFUNCTIONS_CREDENTIAL_CAPABILITY]));\n }\n\n if (!credential) {\n throw new Error('No credential found');\n }\n log('credential found', { credential });\n // TODO(wittjosiah): If id is required to present credentials, then it should always be present for queried credentials.\n invariant(credential.id, 'beta credential missing id');\n const presentation = await halo.presentCredentials({ ids: [credential.id] });\n\n return { Authorization: `Bearer ${codec.encode(presentation)}` };\n};\n\nexport type InvocationOptions = {\n spaceId?: SpaceId;\n subjectId?: string;\n};\n\nexport const getInvocationUrl = (functionUrl: string, edgeUrl: string, options: InvocationOptions = {}) => {\n const baseUrl = new URL('functions/', edgeUrl);\n\n // Leading slashes cause the URL to be treated as an absolute path.\n const relativeUrl = functionUrl.replace(/^\\//, '');\n const url = new URL(`./${relativeUrl}`, baseUrl.toString());\n options.spaceId && url.searchParams.set('spaceId', options.spaceId);\n options.subjectId && url.searchParams.set('subjectId', options.subjectId);\n url.protocol = 'https';\n return url.toString();\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type DID } from 'iso-did/types';\n\nimport { type Credential } from '@dxos/client/halo';\nimport { type PublicKey } from '@dxos/keys';\n\n// TODO(burdon): Factor out to @dxos/hub-protocol.\n\nexport const matchServiceCredential =\n (capabilities: string[] = []) =>\n (credential: Credential) => {\n if (credential.subject.assertion['@type'] !== 'dxos.halo.credentials.ServiceAccess') {\n return false;\n }\n\n const { capabilities: credentialCapabilities } = credential.subject.assertion;\n return capabilities.every((capability) => credentialCapabilities.includes(capability));\n };\n\n// TODO: reconcile with @dxos/hub-protocol\n\nexport const publicKeyToDid = (key: PublicKey): DID => {\n return `did:key:${key.toHex()}`;\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,kBAA0B;AEE1B,mBAAwB;AAIxB,uBAA0B;AAE1B,iBAAoB;ADNpB,IAAMA,WAAW;AAeV,IAAMC,cAAN,MAAMA;EACXC,YAA6BC,WAA0B;SAA1BA,YAAAA;EAA2B;EAExDC,OAAOC,KAAkB;AACvB,UAAMC,iBAAiB,KAAKC,oBAAoBF,GAAAA;AAChD,UAAMG,UAAUC,OAAOC,KAAKC,KAAKC,UAAUN,cAAAA,CAAAA;AAC3C,WAAOE,QAAQK,SAASb,QAAAA;EAC1B;EAEAc,OAAaC,QAAsB;AACjC,UAAMC,OAAOL,KAAKM,MAAMR,OAAOC,KAAKK,QAAQf,QAAAA,EAAUa,SAAQ,CAAA;AAC9D,WAAO,KAAKK,iBAAiBF,IAAAA;EAC/B;EAEQE,iBAAiBb,KAAe;AACtC,WAAO,KAAKc,SAASd,KAAK,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QAAqC,SAASA,OAAO,OAAOA,IAAIkB,QAAQ;AAChG,IAAME,gBAAgB,CAACpB,QAAyC,SAASA,OAAO,OAAOA,IAAIsC,QAAQ;AAEnG,IAAMZ,aAAa,CAACa,UAAgB;EAAED,KAAKC,KAAKC,QAAO;AAAG;AAC1D,IAAMnB,aAAa,CAACoB,cAAgC,IAAIhB,KAAKgB,UAAUH,GAAG;AAE1E,IAAMf,cAAc,CAACmB,UAAsBtC,OAAOC,KAAKqC,KAAAA,EAAOlC,SAASb,QAAAA;AACvE,IAAMsB,cAAc,CAACyB,UAAkBtC,OAAOC,KAAKqC,OAAO/C,QAAAA;ADxFnD,IAAMgD,QAAQ,IAAI/C,YAAuB;EAC9C4B,OAAO,CAACT,UAAmCA,iBAAiB6B;EAC5D7C,QAAQ,CAACmC,SAAgC;IAAEG,KAAKH,IAAIW,MAAK;EAAG;EAC5DpC,QAAQ,CAACM,UAAiC6B,sBAAUE,QAAQ/B,MAAMsB,GAAG;AACvE,CAAA;AGDO,IAAMU,yBACX,CAACC,eAAyB,CAAA,MAC1B,CAACC,eAAAA;AACC,MAAIA,WAAWC,QAAQC,UAAU,OAAA,MAAa,uCAAuC;AACnF,WAAO;EACT;AAEA,QAAM,EAAEH,cAAcI,uBAAsB,IAAKH,WAAWC,QAAQC;AACpE,SAAOH,aAAaK,MAAM,CAACC,eAAeF,uBAAuBG,SAASD,UAAAA,CAAAA;AAC5E;AAIK,IAAME,iBAAiB,CAACtB,QAAAA;AAC7B,SAAO,WAAWA,IAAIW,MAAK,CAAA;AAC7B;;ADPA,IAAMY,yBAAyB;AACxB,IAAMC,gCAAgC;AAC7C,IAAMC,sCAAsC;
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { PublicKey } from '@dxos/keys';\n\nimport { HeaderCodec, type EncodedKey } from './header-codec';\n\nexport const codec = new HeaderCodec<PublicKey>({\n isKey: (value: any): value is PublicKey => value instanceof PublicKey,\n encode: (key: PublicKey): EncodedKey => ({ __k: key.toHex() }),\n decode: (value: EncodedKey): PublicKey => PublicKey.fromHex(value.__k),\n});\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// TODO(burdon): Factor out from @dxos/hub-protocol\n\nconst ENCODING = 'base64';\n\nexport type EncodedKey = { __k: string };\n\nexport type EncodedBytes = { __b: string };\n\nexport type EncodedTimestamp = { __t: number };\n\nexport interface KeyCodec<KeyType> {\n isKey(value: any): value is KeyType;\n encode(key: KeyType): EncodedKey;\n decode(value: EncodedKey): KeyType;\n}\n\n// TODO(wittjosiah): Use deepMapValues from @dxos/util -- it handles recursion for you.\nexport class HeaderCodec<Key> {\n constructor(private readonly _keyCodec: KeyCodec<Key>) {}\n\n encode(obj: any): string {\n const objectToEncode = this._prepareForEncoding(obj);\n const encoded = Buffer.from(JSON.stringify(objectToEncode));\n return encoded.toString(ENCODING);\n }\n\n decode<Type>(buffer: string): Type {\n const json = JSON.parse(Buffer.from(buffer, ENCODING).toString());\n return this._decodeRecursive(json);\n }\n\n private _decodeRecursive(obj: any): any {\n return this._recurse(obj, (value) => {\n if (isEncodedBytes(value)) {\n return decodeBytes(value.__b);\n }\n if (isEncodedKey(value)) {\n return this._keyCodec.decode(value);\n }\n if (isEncodedDate(value)) {\n return decodeDate(value);\n }\n return null;\n });\n }\n\n private _prepareForEncoding(obj: any): any {\n return this._recurse(obj, (value) => {\n if (value instanceof Uint8Array) {\n return { __b: encodeBytes(value) };\n }\n if (this._keyCodec.isKey(value)) {\n return this._keyCodec.encode(value);\n }\n if (value instanceof Date) {\n return encodeDate(value);\n }\n return null;\n });\n }\n\n private _recurse(obj: any, handler: (obj: object) => any | null): any {\n if (typeof obj !== 'object') {\n return obj;\n }\n const handled = handler(obj);\n if (handled != null) {\n return handled;\n }\n if (Array.isArray(obj)) {\n const result = [];\n for (const elem of obj) {\n result.push(this._recurse(elem, handler));\n }\n return result;\n }\n const result: any = {};\n for (const [key, value] of Object.entries(obj)) {\n result[key] = this._recurse(value, handler);\n }\n return result;\n }\n}\n\nconst isEncodedKey = (obj: object): obj is EncodedKey => '__k' in obj && typeof obj.__k === 'string';\nconst isEncodedBytes = (obj: object): obj is EncodedBytes => '__b' in obj && typeof obj.__b === 'string';\nconst isEncodedDate = (obj: object): obj is EncodedTimestamp => '__t' in obj && typeof obj.__t === 'number';\n\nconst encodeDate = (date: Date) => ({ __t: date.getTime() });\nconst decodeDate = (timestamp: EncodedTimestamp) => new Date(timestamp.__t);\n\nconst encodeBytes = (bytes: Uint8Array) => Buffer.from(bytes).toString(ENCODING);\nconst decodeBytes = (bytes: string) => Buffer.from(bytes, ENCODING);\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type DID } from 'iso-did/types';\n\nimport { Trigger } from '@dxos/async';\nimport { type Config } from '@dxos/client';\nimport { type Halo } from '@dxos/client-protocol';\nimport { type JsonSchemaType, type ObjectMeta } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport type { SpaceId } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';\n\nimport { codec } from './codec';\nimport { matchServiceCredential } from './hub-protocol';\n\n// TODO: use URL scheme for source?\nconst USERFUNCTIONS_META_KEY = 'dxos.org/service/function';\nexport const USERFUNCTIONS_PRESET_META_KEY = 'dxos.org/service/function-preset';\nconst USERFUNCTIONS_CREDENTIAL_CAPABILITY = 'composer:beta';\n\n// TODO: Synchronize API types with server\nexport type UserFunctionUploadResult = {\n result: 'success' | 'error';\n errorMessage?: string;\n functionId?: string;\n functionVersionNumber?: number;\n meta: {\n inputSchema?: JsonSchemaType;\n };\n};\n\nexport type UploadWorkerProps = {\n clientConfig: Config;\n halo: Halo;\n name?: string;\n source: string;\n functionId?: string;\n ownerDid: DID;\n credentialLoadTimeout?: number; // ms to wait for credentials to load\n};\n\n// TODO(burdon): Config.\nconst defaultUserFunctionsBaseUrl = 'https://edge-main.dxos.workers.dev/functions'; // 'http://localhost:8600';\n\nconst getBaseUrl = (config: Config) => {\n if (config.values.runtime?.services?.edge?.url) {\n const url = new URL('/functions', config.values.runtime?.services?.edge?.url);\n url.protocol = 'https';\n return url.toString();\n } else {\n return defaultUserFunctionsBaseUrl;\n }\n};\n\nexport const uploadWorkerFunction = async ({\n clientConfig,\n halo,\n name,\n source,\n ownerDid,\n functionId,\n credentialLoadTimeout,\n}: UploadWorkerProps) => {\n const identity = halo.identity.get();\n if (!identity) {\n throw new Error('Identity not available');\n }\n const userFunctionsBaseUrl = getBaseUrl(clientConfig);\n\n // TODO: codify naming convention\n const uploadUrl = `${userFunctionsBaseUrl}/${ownerDid}` + (functionId ? `/${functionId}` : '');\n\n log('Upload', { functionId, source, name, identityKey: identity.identityKey, uploadUrl: uploadUrl.toString() });\n const response = await fetch(uploadUrl, {\n method: 'PUT',\n body: JSON.stringify({ script: source, name }),\n headers: await presentationForIdentity({ halo, timeout: credentialLoadTimeout }),\n });\n if (!response.ok) {\n return (await response.json()) as UserFunctionUploadResult;\n }\n\n const res = await response.json();\n log('Upload response', { status: response.status, res });\n\n return res as UserFunctionUploadResult;\n};\n\nexport const getUserFunctionUrlInMetadata = (meta: ObjectMeta) => {\n return meta.keys.find((key) => key.source === USERFUNCTIONS_META_KEY)?.id;\n};\n\nexport const setUserFunctionUrlInMetadata = (meta: ObjectMeta, functionUrl: string) => {\n const key = meta.keys.find((key) => key.source === USERFUNCTIONS_META_KEY);\n if (key) {\n if (key.id !== functionUrl) {\n throw new Error('Metadata mismatch');\n }\n } else {\n meta.keys.push({ source: USERFUNCTIONS_META_KEY, id: functionUrl });\n }\n};\n\n// TODO: handle team owner\n\nconst presentationForIdentity = async ({ halo, timeout }: { halo: Halo; timeout?: number }) => {\n let credential: Credential | undefined;\n\n if (timeout) {\n const credentialsLoaded = new Trigger();\n halo.credentials.subscribe((c) => {\n credential = c.find(matchServiceCredential([USERFUNCTIONS_CREDENTIAL_CAPABILITY]));\n if (credential) {\n credentialsLoaded.wake();\n }\n });\n await credentialsLoaded.wait({\n timeout,\n });\n } else {\n credential = halo\n .queryCredentials()\n .toSorted((a, b) => b.issuanceDate.getTime() - a.issuanceDate.getTime())\n .find(matchServiceCredential([USERFUNCTIONS_CREDENTIAL_CAPABILITY]));\n }\n\n if (!credential) {\n throw new Error('No credential found');\n }\n log('credential found', { credential });\n // TODO(wittjosiah): If id is required to present credentials, then it should always be present for queried credentials.\n invariant(credential.id, 'beta credential missing id');\n const presentation = await halo.presentCredentials({ ids: [credential.id] });\n\n return { Authorization: `Bearer ${codec.encode(presentation)}` };\n};\n\nexport type InvocationOptions = {\n spaceId?: SpaceId;\n subjectId?: string;\n};\n\nexport const getInvocationUrl = (functionUrl: string, edgeUrl: string, options: InvocationOptions = {}) => {\n const baseUrl = new URL('functions/', edgeUrl);\n\n // Leading slashes cause the URL to be treated as an absolute path.\n const relativeUrl = functionUrl.replace(/^\\//, '');\n const url = new URL(`./${relativeUrl}`, baseUrl.toString());\n options.spaceId && url.searchParams.set('spaceId', options.spaceId);\n options.subjectId && url.searchParams.set('subjectId', options.subjectId);\n url.protocol = 'https';\n return url.toString();\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type DID } from 'iso-did/types';\n\nimport { type Credential } from '@dxos/client/halo';\nimport { type PublicKey } from '@dxos/keys';\n\n// TODO(burdon): Factor out to @dxos/hub-protocol.\n\nexport const matchServiceCredential =\n (capabilities: string[] = []) =>\n (credential: Credential) => {\n if (credential.subject.assertion['@type'] !== 'dxos.halo.credentials.ServiceAccess') {\n return false;\n }\n\n const { capabilities: credentialCapabilities } = credential.subject.assertion;\n return capabilities.every((capability) => credentialCapabilities.includes(capability));\n };\n\n// TODO: reconcile with @dxos/hub-protocol\n\nexport const publicKeyToDid = (key: PublicKey): DID => {\n return `did:key:${key.toHex()}`;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,kBAA0B;AEE1B,mBAAwB;AAIxB,uBAA0B;AAE1B,iBAAoB;ADNpB,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WmD,IAAI,8BAAA;;;;;;;;;AACzB,QAAMgB,eAAe,MAAM5C,KAAK6C,mBAAmB;IAAEC,KAAK;MAACrE,WAAWmD;;EAAI,CAAA;AAE1E,SAAO;IAAEmB,eAAe,UAAU5E,MAAM5C,OAAOqH,YAAAA,CAAAA;EAAgB;AACjE;AAOO,IAAMI,mBAAmB,CAAClB,aAAqBmB,SAAiBC,UAA6B,CAAC,MAAC;AACpG,QAAMC,UAAU,IAAIvD,IAAI,cAAcqD,OAAAA;AAGtC,QAAMG,cAActB,YAAYuB,QAAQ,OAAO,EAAA;AAC/C,QAAM1D,MAAM,IAAIC,IAAI,KAAKwD,WAAAA,IAAeD,QAAQnH,SAAQ,CAAA;AACxDkH,UAAQI,WAAW3D,IAAI4D,aAAaC,IAAI,WAAWN,QAAQI,OAAO;AAClEJ,UAAQO,aAAa9D,IAAI4D,aAAaC,IAAI,aAAaN,QAAQO,SAAS;AACxE9D,MAAIE,WAAW;AACf,SAAOF,IAAI3D,SAAQ;AACrB;",
|
|
6
6
|
"names": ["ENCODING", "HeaderCodec", "constructor", "_keyCodec", "encode", "obj", "objectToEncode", "_prepareForEncoding", "encoded", "Buffer", "from", "JSON", "stringify", "toString", "decode", "buffer", "json", "parse", "_decodeRecursive", "_recurse", "value", "isEncodedBytes", "decodeBytes", "__b", "isEncodedKey", "isEncodedDate", "decodeDate", "Uint8Array", "encodeBytes", "isKey", "Date", "encodeDate", "handler", "handled", "Array", "isArray", "result", "elem", "push", "key", "Object", "entries", "__k", "__t", "date", "getTime", "timestamp", "bytes", "codec", "PublicKey", "toHex", "fromHex", "matchServiceCredential", "capabilities", "credential", "subject", "assertion", "credentialCapabilities", "every", "capability", "includes", "publicKeyToDid", "USERFUNCTIONS_META_KEY", "USERFUNCTIONS_PRESET_META_KEY", "USERFUNCTIONS_CREDENTIAL_CAPABILITY", "defaultUserFunctionsBaseUrl", "getBaseUrl", "config", "values", "runtime", "services", "edge", "url", "URL", "protocol", "uploadWorkerFunction", "clientConfig", "halo", "name", "source", "ownerDid", "functionId", "credentialLoadTimeout", "identity", "get", "Error", "userFunctionsBaseUrl", "uploadUrl", "log", "identityKey", "response", "fetch", "method", "body", "script", "headers", "presentationForIdentity", "timeout", "ok", "res", "status", "getUserFunctionUrlInMetadata", "meta", "keys", "find", "id", "setUserFunctionUrlInMetadata", "functionUrl", "credentialsLoaded", "Trigger", "credentials", "subscribe", "c", "wake", "wait", "queryCredentials", "toSorted", "a", "b", "issuanceDate", "invariant", "presentation", "presentCredentials", "ids", "Authorization", "getInvocationUrl", "edgeUrl", "options", "baseUrl", "relativeUrl", "replace", "spaceId", "searchParams", "set", "subjectId"]
|
|
7
7
|
}
|
|
@@ -16,13 +16,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
19
|
+
var chunk_ZTUFXDTH_exports = {};
|
|
20
|
+
__export(chunk_ZTUFXDTH_exports, {
|
|
21
21
|
FunctionType: () => FunctionType,
|
|
22
22
|
ScriptAction: () => ScriptAction,
|
|
23
23
|
ScriptType: () => ScriptType
|
|
24
24
|
});
|
|
25
|
-
module.exports = __toCommonJS(
|
|
25
|
+
module.exports = __toCommonJS(chunk_ZTUFXDTH_exports);
|
|
26
26
|
var import_chunk_6LYX73ZT = require("./chunk-6LYX73ZT.cjs");
|
|
27
27
|
var import_echo_schema = require("@dxos/echo-schema");
|
|
28
28
|
var import_types = require("@dxos/plugin-markdown/types");
|
|
@@ -49,7 +49,8 @@ var FunctionType = class extends (0, import_echo_schema.TypedObject)({
|
|
|
49
49
|
// TODO(burdon): Move binding to inner type.
|
|
50
50
|
binding: import_echo_schema.S.optional(import_echo_schema.S.String),
|
|
51
51
|
// Reference to a source script if it exists within ECHO.
|
|
52
|
-
source: import_echo_schema.S.optional((0, import_echo_schema.ref)(ScriptType))
|
|
52
|
+
source: import_echo_schema.S.optional((0, import_echo_schema.ref)(ScriptType)),
|
|
53
|
+
inputSchema: import_echo_schema.S.optional(import_echo_schema.JsonSchemaType)
|
|
53
54
|
}) {
|
|
54
55
|
};
|
|
55
56
|
var ScriptAction;
|
|
@@ -62,4 +63,4 @@ var ScriptAction;
|
|
|
62
63
|
ScriptAction,
|
|
63
64
|
ScriptType
|
|
64
65
|
});
|
|
65
|
-
//# sourceMappingURL=chunk-
|
|
66
|
+
//# sourceMappingURL=chunk-ZTUFXDTH.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/types/script.ts", "../../../src/types/types.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { JsonSchemaType, ref, S, TypedObject } from '@dxos/echo-schema';\nimport { TextType } from '@dxos/plugin-markdown/types';\n\n// TODO(burdon): Which is the outer type? I.e., in the navbar?\n\n/**\n * Source script.\n */\nexport class ScriptType extends TypedObject({ typename: 'dxos.org/type/Script', version: '0.1.0' })({\n // TODO(burdon): Change to URI?\n name: S.optional(S.String),\n description: S.optional(S.String),\n source: ref(TextType),\n // TODO(burdon): Change to has of deployed content.\n // Whether source has changed since last deploy.\n changed: S.optional(S.Boolean),\n}) {}\n\n/**\n * Function deployment.\n */\nexport class FunctionType extends TypedObject({ typename: 'dxos.org/type/Function', version: '0.1.0' })({\n name: S.optional(S.String),\n version: S.Number,\n // Local binding to a function name.\n // TODO(burdon): Move binding to inner type.\n binding: S.optional(S.String),\n // Reference to a source script if it exists within ECHO.\n source: S.optional(ref(ScriptType)),\n inputSchema: S.optional(JsonSchemaType),\n}) {}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport type {\n GraphBuilderProvides,\n IntentResolverProvides,\n MetadataRecordsProvides,\n SettingsProvides,\n SurfaceProvides,\n TranslationsProvides,\n} from '@dxos/app-framework';\nimport { type SchemaProvides } from '@dxos/plugin-client';\nimport { type SpaceInitProvides } from '@dxos/plugin-space';\n\nimport { SCRIPT_PLUGIN } from '../meta';\n\nexport enum ScriptAction {\n CREATE = `${SCRIPT_PLUGIN}/create`,\n}\n\nexport type ScriptSettingsProps = {};\n\nexport type ScriptPluginProvides = GraphBuilderProvides &\n IntentResolverProvides &\n MetadataRecordsProvides &\n SchemaProvides &\n SettingsProvides<ScriptSettingsProps> &\n SpaceInitProvides &\n SurfaceProvides &\n TranslationsProvides;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,yBAAoD;AACpD,mBAAyB;AAOlB,IAAMA,aAAN,kBAAyBC,gCAAY;EAAEC,UAAU;EAAwBC,SAAS;AAAQ,CAAA,EAAG;;EAElGC,MAAMC,qBAAEC,SAASD,qBAAEE,MAAM;EACzBC,aAAaH,qBAAEC,SAASD,qBAAEE,MAAM;EAChCE,YAAQC,wBAAIC,qBAAAA;;;EAGZC,SAASP,qBAAEC,SAASD,qBAAEQ,OAAO;AAC/B,CAAA,EAAA;AAAI;AAKG,IAAMC,eAAN,kBAA2Bb,gCAAY;EAAEC,UAAU;EAA0BC,SAAS;AAAQ,CAAA,EAAG;EACtGC,MAAMC,qBAAEC,SAASD,qBAAEE,MAAM;EACzBJ,SAASE,qBAAEU;;;EAGXC,SAASX,qBAAEC,SAASD,qBAAEE,MAAM;;EAE5BE,QAAQJ,qBAAEC,aAASI,wBAAIV,UAAAA,CAAAA;EACvBiB,aAAaZ,qBAAEC,SAASY,iCAAAA;AAC1B,CAAA,EAAA;AAAI;;UCjBQC,eAAAA;0CACD,GAAGC,mCAAAA,SAAsB,IAAA;GADxBD,iBAAAA,eAAAA,CAAAA,EAAAA;",
|
|
6
|
+
"names": ["ScriptType", "TypedObject", "typename", "version", "name", "S", "optional", "String", "description", "source", "ref", "TextType", "changed", "Boolean", "FunctionType", "Number", "binding", "inputSchema", "JsonSchemaType", "ScriptAction", "SCRIPT_PLUGIN"]
|
|
7
|
+
}
|
|
@@ -18,18 +18,18 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var edge_exports = {};
|
|
20
20
|
__export(edge_exports, {
|
|
21
|
-
HeaderCodec: () =>
|
|
22
|
-
USERFUNCTIONS_PRESET_META_KEY: () =>
|
|
23
|
-
codec: () =>
|
|
24
|
-
getInvocationUrl: () =>
|
|
25
|
-
getUserFunctionUrlInMetadata: () =>
|
|
26
|
-
matchServiceCredential: () =>
|
|
27
|
-
publicKeyToDid: () =>
|
|
28
|
-
setUserFunctionUrlInMetadata: () =>
|
|
29
|
-
uploadWorkerFunction: () =>
|
|
21
|
+
HeaderCodec: () => import_chunk_XS6GEYYH.HeaderCodec,
|
|
22
|
+
USERFUNCTIONS_PRESET_META_KEY: () => import_chunk_XS6GEYYH.USERFUNCTIONS_PRESET_META_KEY,
|
|
23
|
+
codec: () => import_chunk_XS6GEYYH.codec,
|
|
24
|
+
getInvocationUrl: () => import_chunk_XS6GEYYH.getInvocationUrl,
|
|
25
|
+
getUserFunctionUrlInMetadata: () => import_chunk_XS6GEYYH.getUserFunctionUrlInMetadata,
|
|
26
|
+
matchServiceCredential: () => import_chunk_XS6GEYYH.matchServiceCredential,
|
|
27
|
+
publicKeyToDid: () => import_chunk_XS6GEYYH.publicKeyToDid,
|
|
28
|
+
setUserFunctionUrlInMetadata: () => import_chunk_XS6GEYYH.setUserFunctionUrlInMetadata,
|
|
29
|
+
uploadWorkerFunction: () => import_chunk_XS6GEYYH.uploadWorkerFunction
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(edge_exports);
|
|
32
|
-
var
|
|
32
|
+
var import_chunk_XS6GEYYH = require("../chunk-XS6GEYYH.cjs");
|
|
33
33
|
// Annotate the CommonJS export names for ESM import in node:
|
|
34
34
|
0 && (module.exports = {
|
|
35
35
|
HeaderCodec,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["index.cjs"],
|
|
4
|
-
"sourcesContent": ["import {\n HeaderCodec,\n USERFUNCTIONS_PRESET_META_KEY,\n codec,\n getInvocationUrl,\n getUserFunctionUrlInMetadata,\n matchServiceCredential,\n publicKeyToDid,\n setUserFunctionUrlInMetadata,\n uploadWorkerFunction\n} from \"../chunk-
|
|
4
|
+
"sourcesContent": ["import {\n HeaderCodec,\n USERFUNCTIONS_PRESET_META_KEY,\n codec,\n getInvocationUrl,\n getUserFunctionUrlInMetadata,\n matchServiceCredential,\n publicKeyToDid,\n setUserFunctionUrlInMetadata,\n uploadWorkerFunction\n} from \"../chunk-XS6GEYYH.cjs\";\nexport {\n HeaderCodec,\n USERFUNCTIONS_PRESET_META_KEY,\n codec,\n getInvocationUrl,\n getUserFunctionUrlInMetadata,\n matchServiceCredential,\n publicKeyToDid,\n setUserFunctionUrlInMetadata,\n uploadWorkerFunction\n};\n//# sourceMappingURL=index.cjs.map\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAUO;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/lib/node/index.cjs
CHANGED
|
@@ -29,22 +29,22 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var node_exports = {};
|
|
30
30
|
__export(node_exports, {
|
|
31
31
|
AutomationPanel: () => AutomationPanel,
|
|
32
|
-
Bundler: () =>
|
|
32
|
+
Bundler: () => import_chunk_WPP65EYS.Bundler,
|
|
33
33
|
Compiler: () => Compiler,
|
|
34
|
-
FunctionType: () =>
|
|
35
|
-
ScriptAction: () =>
|
|
34
|
+
FunctionType: () => import_chunk_ZTUFXDTH.FunctionType,
|
|
35
|
+
ScriptAction: () => import_chunk_ZTUFXDTH.ScriptAction,
|
|
36
36
|
ScriptContainer: () => ScriptContainer,
|
|
37
37
|
ScriptPlugin: () => ScriptPlugin,
|
|
38
38
|
ScriptSettings: () => ScriptSettings,
|
|
39
39
|
ScriptSettingsPanel: () => ScriptSettingsPanel,
|
|
40
|
-
ScriptType: () =>
|
|
40
|
+
ScriptType: () => import_chunk_ZTUFXDTH.ScriptType,
|
|
41
41
|
default: () => src_default,
|
|
42
|
-
initializeBundler: () =>
|
|
42
|
+
initializeBundler: () => import_chunk_WPP65EYS.initializeBundler
|
|
43
43
|
});
|
|
44
44
|
module.exports = __toCommonJS(node_exports);
|
|
45
|
-
var
|
|
46
|
-
var
|
|
47
|
-
var
|
|
45
|
+
var import_chunk_WPP65EYS = require("./chunk-WPP65EYS.cjs");
|
|
46
|
+
var import_chunk_XS6GEYYH = require("./chunk-XS6GEYYH.cjs");
|
|
47
|
+
var import_chunk_ZTUFXDTH = require("./chunk-ZTUFXDTH.cjs");
|
|
48
48
|
var import_chunk_6LYX73ZT = require("./chunk-6LYX73ZT.cjs");
|
|
49
49
|
var import_esbuild = __toESM(require("esbuild-wasm/esbuild.wasm?url"));
|
|
50
50
|
var import_react = __toESM(require("react"));
|
|
@@ -149,7 +149,7 @@ var ScriptSettingsPanel = ({ script }) => {
|
|
|
149
149
|
const { t } = (0, import_react_ui2.useTranslation)(import_chunk_6LYX73ZT.SCRIPT_PLUGIN);
|
|
150
150
|
const client = (0, import_react_client2.useClient)();
|
|
151
151
|
const space = (0, import_echo2.getSpace)(script);
|
|
152
|
-
const [fn] = (0, import_echo2.useQuery)(space, import_echo2.Filter.schema(
|
|
152
|
+
const [fn] = (0, import_echo2.useQuery)(space, import_echo2.Filter.schema(import_chunk_ZTUFXDTH.FunctionType, (fn2) => fn2.source === script));
|
|
153
153
|
const handleNameChange = (0, import_react4.useCallback)((event) => {
|
|
154
154
|
script.name = event.target.value;
|
|
155
155
|
}, [
|
|
@@ -167,8 +167,8 @@ var ScriptSettingsPanel = ({ script }) => {
|
|
|
167
167
|
fn,
|
|
168
168
|
binding
|
|
169
169
|
]);
|
|
170
|
-
const functionPath = fn && (0,
|
|
171
|
-
const functionUrl = functionPath && (0,
|
|
170
|
+
const functionPath = fn && (0, import_chunk_XS6GEYYH.getUserFunctionUrlInMetadata)((0, import_echo2.getMeta)(fn));
|
|
171
|
+
const functionUrl = functionPath && (0, import_chunk_XS6GEYYH.getInvocationUrl)(functionPath, client.config.values.runtime?.services?.edge?.url ?? "", {
|
|
172
172
|
spaceId: space?.id
|
|
173
173
|
});
|
|
174
174
|
const handleCopy = (0, import_react4.useCallback)(() => functionUrl && navigator.clipboard.writeText(functionUrl), [
|
|
@@ -213,8 +213,8 @@ var ScriptSettingsPanel = ({ script }) => {
|
|
|
213
213
|
onBlur: handleBindingBlur
|
|
214
214
|
})))));
|
|
215
215
|
};
|
|
216
|
-
var AutomationPanel = (0, import_react2.lazy)(() => import("./AutomationPanel-
|
|
217
|
-
var ScriptContainer = (0, import_react2.lazy)(() => import("./ScriptContainer-
|
|
216
|
+
var AutomationPanel = (0, import_react2.lazy)(() => import("./AutomationPanel-M5UHEMPG.cjs"));
|
|
217
|
+
var ScriptContainer = (0, import_react2.lazy)(() => import("./ScriptContainer-X76C7OD2.cjs"));
|
|
218
218
|
var translations_default = [
|
|
219
219
|
{
|
|
220
220
|
"en-US": {
|
|
@@ -254,7 +254,7 @@ var ScriptPlugin = () => {
|
|
|
254
254
|
export type FunctionHandler = ({ event, context }: { event: any; context: any }) => Promise<Response>;
|
|
255
255
|
export const functionHandler = (handler: FunctionHandler) => handler;
|
|
256
256
|
`);
|
|
257
|
-
await (0,
|
|
257
|
+
await (0, import_chunk_WPP65EYS.initializeBundler)({
|
|
258
258
|
wasmUrl: import_esbuild.default
|
|
259
259
|
});
|
|
260
260
|
},
|
|
@@ -262,7 +262,7 @@ var ScriptPlugin = () => {
|
|
|
262
262
|
settings: {},
|
|
263
263
|
metadata: {
|
|
264
264
|
records: {
|
|
265
|
-
[
|
|
265
|
+
[import_chunk_ZTUFXDTH.ScriptType.typename]: {
|
|
266
266
|
placeholder: [
|
|
267
267
|
"object title placeholder",
|
|
268
268
|
{
|
|
@@ -280,8 +280,8 @@ var ScriptPlugin = () => {
|
|
|
280
280
|
translations: translations_default,
|
|
281
281
|
echo: {
|
|
282
282
|
schema: [
|
|
283
|
-
|
|
284
|
-
|
|
283
|
+
import_chunk_ZTUFXDTH.ScriptType,
|
|
284
|
+
import_chunk_ZTUFXDTH.FunctionType
|
|
285
285
|
]
|
|
286
286
|
},
|
|
287
287
|
space: {
|
|
@@ -292,7 +292,7 @@ var ScriptPlugin = () => {
|
|
|
292
292
|
ns: import_chunk_6LYX73ZT.SCRIPT_PLUGIN
|
|
293
293
|
}
|
|
294
294
|
],
|
|
295
|
-
action:
|
|
295
|
+
action: import_chunk_ZTUFXDTH.ScriptAction.CREATE
|
|
296
296
|
}
|
|
297
297
|
},
|
|
298
298
|
graph: {
|
|
@@ -303,7 +303,7 @@ var ScriptPlugin = () => {
|
|
|
303
303
|
return [];
|
|
304
304
|
}
|
|
305
305
|
return (0, import_plugin_graph.createExtension)({
|
|
306
|
-
id:
|
|
306
|
+
id: import_chunk_ZTUFXDTH.ScriptAction.CREATE,
|
|
307
307
|
filter: (node) => (0, import_plugin_graph.isActionGroup)(node) && node.id.startsWith(import_plugin_space.SpaceAction.ADD_OBJECT),
|
|
308
308
|
actions: ({ node }) => {
|
|
309
309
|
const id = node.id.split("/").at(-1);
|
|
@@ -321,7 +321,7 @@ var ScriptPlugin = () => {
|
|
|
321
321
|
await dispatch([
|
|
322
322
|
{
|
|
323
323
|
plugin: import_chunk_6LYX73ZT.SCRIPT_PLUGIN,
|
|
324
|
-
action:
|
|
324
|
+
action: import_chunk_ZTUFXDTH.ScriptAction.CREATE
|
|
325
325
|
},
|
|
326
326
|
{
|
|
327
327
|
action: import_plugin_space.SpaceAction.ADD_OBJECT,
|
|
@@ -359,7 +359,7 @@ var ScriptPlugin = () => {
|
|
|
359
359
|
}) : null;
|
|
360
360
|
}
|
|
361
361
|
case "article": {
|
|
362
|
-
if (data.object instanceof
|
|
362
|
+
if (data.object instanceof import_chunk_ZTUFXDTH.ScriptType) {
|
|
363
363
|
return /* @__PURE__ */ import_react.default.createElement(ScriptContainer, {
|
|
364
364
|
script: data.object,
|
|
365
365
|
env: compiler.environment
|
|
@@ -368,7 +368,7 @@ var ScriptPlugin = () => {
|
|
|
368
368
|
break;
|
|
369
369
|
}
|
|
370
370
|
case "complementary--automation": {
|
|
371
|
-
if (data.subject instanceof
|
|
371
|
+
if (data.subject instanceof import_chunk_ZTUFXDTH.ScriptType) {
|
|
372
372
|
return {
|
|
373
373
|
node: /* @__PURE__ */ import_react.default.createElement(AutomationPanel, {
|
|
374
374
|
subject: data.subject
|
|
@@ -379,7 +379,7 @@ var ScriptPlugin = () => {
|
|
|
379
379
|
break;
|
|
380
380
|
}
|
|
381
381
|
case "complementary--settings": {
|
|
382
|
-
if (data.subject instanceof
|
|
382
|
+
if (data.subject instanceof import_chunk_ZTUFXDTH.ScriptType) {
|
|
383
383
|
return /* @__PURE__ */ import_react.default.createElement(ScriptSettingsPanel, {
|
|
384
384
|
script: data.subject
|
|
385
385
|
});
|
|
@@ -393,11 +393,11 @@ var ScriptPlugin = () => {
|
|
|
393
393
|
intent: {
|
|
394
394
|
resolver: (intent) => {
|
|
395
395
|
switch (intent.action) {
|
|
396
|
-
case
|
|
396
|
+
case import_chunk_ZTUFXDTH.ScriptAction.CREATE: {
|
|
397
397
|
return {
|
|
398
|
-
data: (0, import_echo_schema.create)(
|
|
398
|
+
data: (0, import_echo_schema.create)(import_chunk_ZTUFXDTH.ScriptType, {
|
|
399
399
|
source: (0, import_echo_schema.create)(import_types.TextType, {
|
|
400
|
-
content:
|
|
400
|
+
content: import_chunk_WPP65EYS.templates[0].source
|
|
401
401
|
})
|
|
402
402
|
})
|
|
403
403
|
};
|