@dxos/plugin-script 0.7.5-main.499c70c → 0.7.5-main.6a330ac
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/ScriptContainer-3RFMYKTV.mjs +258 -0
- package/dist/lib/browser/ScriptContainer-3RFMYKTV.mjs.map +7 -0
- package/dist/lib/browser/artifact-definition-4LWPD3DH.mjs +251 -0
- package/dist/lib/browser/artifact-definition-4LWPD3DH.mjs.map +7 -0
- package/dist/lib/browser/{chunk-K7KY6YMG.mjs → chunk-5SXOHNAK.mjs} +4 -4
- package/dist/lib/browser/chunk-5SXOHNAK.mjs.map +7 -0
- package/dist/lib/browser/chunk-6MOQ4BP3.mjs +15 -0
- package/dist/lib/browser/chunk-6MOQ4BP3.mjs.map +7 -0
- package/dist/lib/browser/chunk-FVVCAWNP.mjs +21 -0
- package/dist/lib/browser/chunk-FVVCAWNP.mjs.map +7 -0
- package/dist/lib/browser/chunk-G2FYNDU4.mjs +475 -0
- package/dist/lib/browser/chunk-G2FYNDU4.mjs.map +7 -0
- package/dist/lib/browser/chunk-N46LE7FS.mjs +40 -0
- package/dist/lib/browser/chunk-N46LE7FS.mjs.map +7 -0
- package/dist/lib/browser/chunk-PZPYF7M4.mjs +69 -0
- package/dist/lib/browser/chunk-PZPYF7M4.mjs.map +7 -0
- package/dist/lib/browser/chunk-VTWBVFBK.mjs +234 -0
- package/dist/lib/browser/chunk-VTWBVFBK.mjs.map +7 -0
- package/dist/lib/browser/compiler-YY2XSKHQ.mjs +82 -0
- package/dist/lib/browser/compiler-YY2XSKHQ.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +146 -289
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/intent-resolver-D6FPY5ZA.mjs +45 -0
- package/dist/lib/browser/intent-resolver-D6FPY5ZA.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/react-surface-G4C2PZ2K.mjs +81 -0
- package/dist/lib/browser/react-surface-G4C2PZ2K.mjs.map +7 -0
- package/dist/lib/browser/settings-SZCDKHWO.mjs +24 -0
- package/dist/lib/browser/settings-SZCDKHWO.mjs.map +7 -0
- package/dist/lib/browser/types.mjs +6 -4
- package/dist/lib/node/ScriptContainer-G6FZU4AM.cjs +274 -0
- package/dist/lib/node/ScriptContainer-G6FZU4AM.cjs.map +7 -0
- package/dist/lib/node/artifact-definition-BXQCFPAH.cjs +267 -0
- package/dist/lib/node/artifact-definition-BXQCFPAH.cjs.map +7 -0
- package/dist/lib/node/{chunk-6LYX73ZT.cjs → chunk-5UH3F7TA.cjs} +11 -8
- package/dist/lib/node/chunk-5UH3F7TA.cjs.map +7 -0
- package/dist/lib/node/{meta.cjs → chunk-ALY3N6PW.cjs} +12 -8
- package/dist/lib/node/chunk-ALY3N6PW.cjs.map +7 -0
- package/dist/lib/node/{chunk-PK3OQP5L.cjs → chunk-DJGLGRQV.cjs} +26 -11
- package/dist/lib/node/chunk-DJGLGRQV.cjs.map +7 -0
- package/dist/lib/node/chunk-ITAJ3WRW.cjs +77 -0
- package/dist/lib/node/chunk-ITAJ3WRW.cjs.map +7 -0
- package/dist/lib/node/{chunk-4INUJLXL.cjs → chunk-K3ZZWVXS.cjs} +7 -7
- package/dist/lib/node/chunk-K3ZZWVXS.cjs.map +7 -0
- package/dist/lib/node/chunk-TOXBGIEI.cjs +261 -0
- package/dist/lib/node/chunk-TOXBGIEI.cjs.map +7 -0
- package/dist/lib/node/chunk-XKYJYY3T.cjs +498 -0
- package/dist/lib/node/chunk-XKYJYY3T.cjs.map +7 -0
- package/dist/lib/node/compiler-UIBLKJKG.cjs +104 -0
- package/dist/lib/node/compiler-UIBLKJKG.cjs.map +7 -0
- package/dist/lib/node/index.cjs +138 -278
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/intent-resolver-NYJFPD5B.cjs +59 -0
- package/dist/lib/node/intent-resolver-NYJFPD5B.cjs.map +7 -0
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/react-surface-EGSE3FMN.cjs +96 -0
- package/dist/lib/node/react-surface-EGSE3FMN.cjs.map +7 -0
- package/dist/lib/node/settings-SZFSMSKM.cjs +38 -0
- package/dist/lib/node/settings-SZFSMSKM.cjs.map +7 -0
- package/dist/lib/node/types.cjs +6 -4
- package/dist/lib/node/types.cjs.map +2 -2
- package/dist/lib/node-esm/ScriptContainer-7FTCFIF3.mjs +259 -0
- package/dist/lib/node-esm/ScriptContainer-7FTCFIF3.mjs.map +7 -0
- package/dist/lib/node-esm/artifact-definition-KT4DK2LQ.mjs +252 -0
- package/dist/lib/node-esm/artifact-definition-KT4DK2LQ.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-OFYGBUNI.mjs → chunk-2AFXX34U.mjs} +4 -4
- package/dist/lib/node-esm/chunk-2AFXX34U.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-CP5LXTK5.mjs +16 -0
- package/dist/lib/node-esm/chunk-CP5LXTK5.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-NRICF4KE.mjs +476 -0
- package/dist/lib/node-esm/chunk-NRICF4KE.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-SLTZMY34.mjs → chunk-P2V2Y5LV.mjs} +7 -4
- package/dist/lib/node-esm/chunk-P2V2Y5LV.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-S64WSJQK.mjs +235 -0
- package/dist/lib/node-esm/chunk-S64WSJQK.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-UNQFIERE.mjs +41 -0
- package/dist/lib/node-esm/chunk-UNQFIERE.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-YIWRJ25J.mjs +71 -0
- package/dist/lib/node-esm/chunk-YIWRJ25J.mjs.map +7 -0
- package/dist/lib/node-esm/compiler-XTXFGZJM.mjs +83 -0
- package/dist/lib/node-esm/compiler-XTXFGZJM.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +146 -289
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/intent-resolver-KLBHSMW4.mjs +46 -0
- package/dist/lib/node-esm/intent-resolver-KLBHSMW4.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/react-surface-7YSGHZQM.mjs +82 -0
- package/dist/lib/node-esm/react-surface-7YSGHZQM.mjs.map +7 -0
- package/dist/lib/node-esm/settings-GR4O2WHZ.mjs +25 -0
- package/dist/lib/node-esm/settings-GR4O2WHZ.mjs.map +7 -0
- package/dist/lib/node-esm/types.mjs +6 -4
- package/dist/types/src/ScriptPlugin.d.ts +1 -3
- package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/artifact-definition.d.ts +11 -0
- package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -0
- package/dist/types/src/capabilities/capabilities.d.ts +5 -0
- package/dist/types/src/capabilities/capabilities.d.ts.map +1 -0
- package/dist/types/src/capabilities/compiler.d.ts +4 -0
- package/dist/types/src/capabilities/compiler.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +7 -0
- package/dist/types/src/capabilities/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/intent-resolver.d.ts +4 -0
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface.d.ts +4 -0
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
- package/dist/types/src/capabilities/settings.d.ts +4 -0
- package/dist/types/src/capabilities/settings.d.ts.map +1 -0
- package/dist/types/src/components/DebugPanel/DebugPanel.d.ts +1 -2
- package/dist/types/src/components/DebugPanel/DebugPanel.d.ts.map +1 -1
- package/dist/types/src/components/FrameContainer/FrameContainer.d.ts +3 -4
- package/dist/types/src/components/FrameContainer/FrameContainer.d.ts.map +1 -1
- package/dist/types/src/components/ScriptContainer.d.ts +10 -3
- package/dist/types/src/components/ScriptContainer.d.ts.map +1 -1
- package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts +1 -2
- package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts.map +1 -1
- package/dist/types/src/components/ScriptSettingsPanel.d.ts +1 -2
- package/dist/types/src/components/ScriptSettingsPanel.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts +10 -0
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts.map +1 -0
- package/dist/types/src/components/{Toolbar/Toolbar.stories.d.ts → ScriptToolbar/ScriptToolbar.stories.d.ts} +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.stories.d.ts.map +1 -0
- package/dist/types/src/components/ScriptToolbar/index.d.ts +2 -0
- package/dist/types/src/components/ScriptToolbar/index.d.ts.map +1 -0
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts +4 -3
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +2 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/events.d.ts +4 -0
- package/dist/types/src/events.d.ts.map +1 -0
- package/dist/types/src/hooks/deploy.d.ts +48 -0
- package/dist/types/src/hooks/deploy.d.ts.map +1 -0
- package/dist/types/src/hooks/format.d.ts +25 -0
- package/dist/types/src/hooks/format.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +7 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -0
- package/dist/types/src/hooks/template.d.ts +31 -0
- package/dist/types/src/hooks/template.d.ts.map +1 -0
- package/dist/types/src/hooks/useToolbarAction.d.ts +14 -0
- package/dist/types/src/hooks/useToolbarAction.d.ts.map +1 -0
- package/dist/types/src/hooks/useToolbarState.d.ts +10 -0
- package/dist/types/src/hooks/useToolbarState.d.ts.map +1 -0
- package/dist/types/src/hooks/view.d.ts +33 -0
- package/dist/types/src/hooks/view.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +2 -5
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +2 -2
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/templates/chess.d.ts +1 -4
- package/dist/types/src/templates/chess.d.ts.map +1 -1
- package/dist/types/src/templates/discord.d.ts +3 -0
- package/dist/types/src/templates/discord.d.ts.map +1 -0
- package/dist/types/src/templates/echo.d.ts.map +1 -1
- package/dist/types/src/templates/email.d.ts +2 -1
- package/dist/types/src/templates/email.d.ts.map +1 -1
- package/dist/types/src/templates/forex-effect.d.ts +3 -0
- package/dist/types/src/templates/forex-effect.d.ts.map +1 -0
- package/dist/types/src/templates/forex.d.ts +1 -4
- package/dist/types/src/templates/forex.d.ts.map +1 -1
- package/dist/types/src/{templates.d.ts → templates/index.d.ts} +1 -1
- package/dist/types/src/templates/index.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +100 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +14 -6
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +46 -46
- package/src/ScriptPlugin.tsx +80 -91
- package/src/capabilities/artifact-definition.ts +224 -0
- package/src/capabilities/capabilities.ts +12 -0
- package/src/capabilities/compiler.ts +33 -0
- package/src/capabilities/index.ts +13 -0
- package/src/capabilities/intent-resolver.ts +46 -0
- package/src/capabilities/react-surface.tsx +60 -0
- package/src/capabilities/settings.ts +14 -0
- package/src/compiler/compiler.browser.test.ts +1 -1
- package/src/components/DebugPanel/DebugPanel.tsx +2 -2
- package/src/components/FrameContainer/FrameContainer.tsx +5 -4
- package/src/components/ScriptContainer.tsx +69 -9
- package/src/components/ScriptSettings/ScriptSettings.tsx +28 -4
- package/src/components/ScriptSettingsPanel.tsx +139 -51
- package/src/components/{Toolbar/Toolbar.stories.tsx → ScriptToolbar/ScriptToolbar.stories.tsx} +2 -2
- package/src/components/ScriptToolbar/ScriptToolbar.tsx +53 -0
- package/src/{bundler → components/ScriptToolbar}/index.ts +1 -1
- package/src/components/TypescriptEditor/TypescriptEditor.stories.tsx +2 -0
- package/src/components/TypescriptEditor/TypescriptEditor.tsx +75 -10
- package/src/components/index.ts +1 -1
- package/src/events.ts +11 -0
- package/src/hooks/deploy.ts +169 -0
- package/src/hooks/format.ts +47 -0
- package/src/hooks/index.ts +11 -0
- package/src/hooks/template.ts +64 -0
- package/src/hooks/useToolbarAction.ts +54 -0
- package/src/hooks/useToolbarState.ts +16 -0
- package/src/hooks/view.ts +55 -0
- package/src/index.ts +2 -7
- package/src/meta.ts +4 -2
- package/src/templates/chat.ts +4 -4
- package/src/templates/chess.ts +42 -35
- package/src/templates/discord.ts +103 -0
- package/src/templates/echo.ts +5 -1
- package/src/templates/email.ts +26 -23
- package/src/templates/forex-effect.ts +41 -0
- package/src/templates/forex.ts +23 -16
- package/src/{templates.ts → templates/index.ts} +20 -5
- package/src/translations.ts +26 -0
- package/src/types.ts +19 -18
- package/dist/lib/browser/AutomationPanel-RFQAQ7NF.mjs +0 -78
- package/dist/lib/browser/AutomationPanel-RFQAQ7NF.mjs.map +0 -7
- package/dist/lib/browser/ScriptContainer-IJNY7NHA.mjs +0 -415
- package/dist/lib/browser/ScriptContainer-IJNY7NHA.mjs.map +0 -7
- package/dist/lib/browser/chunk-4UTRJLQ3.mjs +0 -286
- package/dist/lib/browser/chunk-4UTRJLQ3.mjs.map +0 -7
- package/dist/lib/browser/chunk-C7VBULMK.mjs +0 -18
- package/dist/lib/browser/chunk-C7VBULMK.mjs.map +0 -7
- package/dist/lib/browser/chunk-K7KY6YMG.mjs.map +0 -7
- package/dist/lib/browser/chunk-RQA3EB5K.mjs +0 -26
- package/dist/lib/browser/chunk-RQA3EB5K.mjs.map +0 -7
- package/dist/lib/browser/meta.mjs +0 -9
- package/dist/lib/browser/meta.mjs.map +0 -7
- package/dist/lib/node/AutomationPanel-5CJEF4MI.cjs +0 -104
- package/dist/lib/node/AutomationPanel-5CJEF4MI.cjs.map +0 -7
- package/dist/lib/node/ScriptContainer-D7CCLTCJ.cjs +0 -426
- package/dist/lib/node/ScriptContainer-D7CCLTCJ.cjs.map +0 -7
- package/dist/lib/node/chunk-4INUJLXL.cjs.map +0 -7
- package/dist/lib/node/chunk-6LYX73ZT.cjs.map +0 -7
- package/dist/lib/node/chunk-PK3OQP5L.cjs.map +0 -7
- package/dist/lib/node/chunk-WPP65EYS.cjs +0 -298
- package/dist/lib/node/chunk-WPP65EYS.cjs.map +0 -7
- package/dist/lib/node/meta.cjs.map +0 -7
- package/dist/lib/node-esm/AutomationPanel-7Y6REBNJ.mjs +0 -79
- package/dist/lib/node-esm/AutomationPanel-7Y6REBNJ.mjs.map +0 -7
- package/dist/lib/node-esm/ScriptContainer-FURREOFW.mjs +0 -416
- package/dist/lib/node-esm/ScriptContainer-FURREOFW.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-4SRPREUK.mjs +0 -288
- package/dist/lib/node-esm/chunk-4SRPREUK.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-H6BBLQ5Q.mjs +0 -27
- package/dist/lib/node-esm/chunk-H6BBLQ5Q.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-OFYGBUNI.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-SLTZMY34.mjs.map +0 -7
- package/dist/lib/node-esm/meta.mjs +0 -10
- package/dist/lib/node-esm/meta.mjs.map +0 -7
- package/dist/types/src/bundler/bundler.d.ts +0 -39
- package/dist/types/src/bundler/bundler.d.ts.map +0 -1
- package/dist/types/src/bundler/bundler.test.d.ts +0 -2
- package/dist/types/src/bundler/bundler.test.d.ts.map +0 -1
- package/dist/types/src/bundler/index.d.ts +0 -2
- package/dist/types/src/bundler/index.d.ts.map +0 -1
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts +0 -17
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts.map +0 -1
- package/dist/types/src/components/AutomationPanel/index.d.ts +0 -4
- package/dist/types/src/components/AutomationPanel/index.d.ts.map +0 -1
- package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts +0 -12
- package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts.map +0 -1
- package/dist/types/src/components/ScriptBlock/ScriptBlock.stories.d.ts +0 -6
- package/dist/types/src/components/ScriptBlock/ScriptBlock.stories.d.ts.map +0 -1
- package/dist/types/src/components/ScriptBlock/index.d.ts +0 -2
- package/dist/types/src/components/ScriptBlock/index.d.ts.map +0 -1
- package/dist/types/src/components/ScriptEditor.d.ts +0 -9
- package/dist/types/src/components/ScriptEditor.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +0 -23
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar/index.d.ts +0 -2
- package/dist/types/src/components/Toolbar/index.d.ts.map +0 -1
- package/dist/types/src/templates.d.ts.map +0 -1
- package/src/bundler/bundler.test.ts +0 -54
- package/src/bundler/bundler.ts +0 -250
- package/src/components/AutomationPanel/AutomationPanel.tsx +0 -104
- package/src/components/AutomationPanel/index.ts +0 -9
- package/src/components/ScriptBlock/ScriptBlock.stories.tsx +0 -55
- package/src/components/ScriptBlock/ScriptBlock.tsx +0 -102
- package/src/components/ScriptBlock/index.ts +0 -5
- package/src/components/ScriptEditor.tsx +0 -193
- package/src/components/Toolbar/Toolbar.tsx +0 -177
- package/src/components/Toolbar/index.ts +0 -5
package/src/templates/chess.ts
CHANGED
|
@@ -1,41 +1,48 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
//
|
|
4
|
-
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import { defineFunction, S } from 'dxos:functions';
|
|
5
3
|
// @ts-ignore
|
|
6
4
|
import { Chess } from 'https://esm.sh/chess.js@0.13.1';
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*/
|
|
11
|
-
export default async ({
|
|
12
|
-
event: {
|
|
13
|
-
data: { request },
|
|
14
|
-
},
|
|
15
|
-
context: { space },
|
|
16
|
-
}: any) => {
|
|
17
|
-
const {
|
|
18
|
-
data: {
|
|
19
|
-
objects: [gameId],
|
|
20
|
-
player = 'b',
|
|
21
|
-
},
|
|
22
|
-
} = await request.json();
|
|
6
|
+
export default defineFunction({
|
|
7
|
+
description: 'Plays a random move in a chess game.',
|
|
23
8
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
9
|
+
inputSchema: S.Struct({
|
|
10
|
+
changedObjectId: S.String.annotations({
|
|
11
|
+
description: 'The objects to play the game on.',
|
|
12
|
+
}),
|
|
13
|
+
player: S.optional(S.Literal('w', 'b')).annotations({
|
|
14
|
+
description: 'The player to play the game as.',
|
|
15
|
+
}),
|
|
16
|
+
}),
|
|
30
17
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
18
|
+
outputSchema: S.Struct({
|
|
19
|
+
state: S.String.annotations({
|
|
20
|
+
description: 'The state of the game as an ASCII art board.',
|
|
21
|
+
}),
|
|
22
|
+
}),
|
|
36
23
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
24
|
+
handler: async ({
|
|
25
|
+
event: {
|
|
26
|
+
data: { changedObjectId, player = 'b' },
|
|
27
|
+
},
|
|
28
|
+
context: { space },
|
|
29
|
+
}: any) => {
|
|
30
|
+
const { pgn } = await space.db.query({ id: changedObjectId }).first();
|
|
31
|
+
const game = new Chess();
|
|
32
|
+
game.load_pgn(pgn);
|
|
33
|
+
if (game.turn() !== player) {
|
|
34
|
+
return new Response('Invalid turn', { status: 409 });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const moves = game.moves();
|
|
38
|
+
const move = moves[Math.floor(Math.random() * moves.length)];
|
|
39
|
+
if (!move) {
|
|
40
|
+
return new Response('No legal moves', { status: 406 });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
game.move(move);
|
|
44
|
+
const newPgn = game.pgn();
|
|
45
|
+
await space.db.update({ id: changedObjectId }, { pgn: newPgn, fen: game.fen() });
|
|
46
|
+
return { state: game.ascii() };
|
|
47
|
+
},
|
|
48
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import { createStatic, EchoObject, defineFunction, DXN, Filter, ObjectId, S } from 'dxos:functions';
|
|
7
|
+
import {
|
|
8
|
+
FetchHttpClient,
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
} from 'https://esm.sh/@effect/platform@0.77.2?deps=effect@3.13.3';
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
import { DiscordConfig, DiscordREST, DiscordRESTMemoryLive } from 'https://esm.sh/dfx@0.113.0?deps=effect@3.13.3';
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
import { Effect, Config, Redacted, Ref } from 'https://esm.sh/effect@3.13.3';
|
|
15
|
+
|
|
16
|
+
const MessageSchema = S.Struct({
|
|
17
|
+
id: S.String,
|
|
18
|
+
foreignId: S.Any, // bigint?
|
|
19
|
+
from: S.String,
|
|
20
|
+
created: S.String,
|
|
21
|
+
content: S.String,
|
|
22
|
+
}).pipe(EchoObject('example.com/type/Message', '0.1.0'));
|
|
23
|
+
|
|
24
|
+
const DEFAULT_AFTER = 1704067200; // 2024-01-01
|
|
25
|
+
|
|
26
|
+
const generateSnowflake = (unixTimestamp: number): bigint => {
|
|
27
|
+
const discordEpoch = 1420070400000n; // Discord Epoch (ms)
|
|
28
|
+
return (BigInt(unixTimestamp * 1000) - discordEpoch) << 22n;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default defineFunction({
|
|
32
|
+
inputSchema: S.Struct({
|
|
33
|
+
// TODO(wittjosiah): Remove. This is used to provide a terminal for a cron trigger.
|
|
34
|
+
tick: S.optional(S.String),
|
|
35
|
+
channelId: S.String,
|
|
36
|
+
after: S.optional(S.Number),
|
|
37
|
+
pageSize: S.optional(S.Number),
|
|
38
|
+
queueId: S.String,
|
|
39
|
+
}),
|
|
40
|
+
|
|
41
|
+
outputSchema: S.Struct({
|
|
42
|
+
newMessages: S.Number,
|
|
43
|
+
}),
|
|
44
|
+
|
|
45
|
+
handler: ({
|
|
46
|
+
event: {
|
|
47
|
+
data: { channelId, queueId, after = DEFAULT_AFTER, pageSize = 5 },
|
|
48
|
+
},
|
|
49
|
+
context: { space },
|
|
50
|
+
}: any) =>
|
|
51
|
+
Effect.gen(function* () {
|
|
52
|
+
const { token } = yield* Effect.tryPromise(() =>
|
|
53
|
+
space.db.query(Filter.typename('dxos.org/type/AccessToken', { source: 'discord.com' })).first(),
|
|
54
|
+
);
|
|
55
|
+
const { objects } = yield* Effect.tryPromise(() => space.queues.queryQueue(DXN.parse(queueId)));
|
|
56
|
+
const backfill = objects.length === 0;
|
|
57
|
+
const newMessages = yield* Ref.make(0);
|
|
58
|
+
const lastMessage = yield* Ref.make(objects.at(-1));
|
|
59
|
+
|
|
60
|
+
const enqueueMessages = Effect.gen(function* () {
|
|
61
|
+
const rest = yield* DiscordREST;
|
|
62
|
+
|
|
63
|
+
while (true) {
|
|
64
|
+
const last = yield* Ref.get(lastMessage);
|
|
65
|
+
const options = {
|
|
66
|
+
after: backfill && !last ? `${generateSnowflake(after)}` : last?.foreignId,
|
|
67
|
+
limit: pageSize,
|
|
68
|
+
};
|
|
69
|
+
const messages = yield* rest.getChannelMessages(channelId, options).pipe((res: any) => res.json);
|
|
70
|
+
const queueMessages = messages
|
|
71
|
+
.map((message: any) =>
|
|
72
|
+
createStatic(MessageSchema, {
|
|
73
|
+
id: ObjectId.random(),
|
|
74
|
+
foreignId: message.id,
|
|
75
|
+
from: message.author.username,
|
|
76
|
+
created: message.timestamp,
|
|
77
|
+
content: message.content,
|
|
78
|
+
}),
|
|
79
|
+
)
|
|
80
|
+
.toReversed();
|
|
81
|
+
if (queueMessages.length > 0) {
|
|
82
|
+
yield* Effect.tryPromise(() => space.queues.insertIntoQueue(DXN.parse(queueId), queueMessages));
|
|
83
|
+
yield* Ref.update(newMessages, (n: any) => n + queueMessages.length);
|
|
84
|
+
yield* Ref.update(lastMessage, (m: any) => queueMessages.at(-1));
|
|
85
|
+
}
|
|
86
|
+
if (messages.length < pageSize) {
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}).pipe(
|
|
91
|
+
Effect.provide(DiscordRESTMemoryLive),
|
|
92
|
+
Effect.provide(
|
|
93
|
+
DiscordConfig.layerConfig({
|
|
94
|
+
token: Config.succeed(Redacted.make(token)),
|
|
95
|
+
}),
|
|
96
|
+
),
|
|
97
|
+
Effect.provide(FetchHttpClient.layer),
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
yield* enqueueMessages;
|
|
101
|
+
return { newMessages: yield* Ref.get(newMessages) };
|
|
102
|
+
}),
|
|
103
|
+
});
|
package/src/templates/echo.ts
CHANGED
|
@@ -11,5 +11,9 @@ export default async ({
|
|
|
11
11
|
},
|
|
12
12
|
}: any) => {
|
|
13
13
|
const data = await request.json();
|
|
14
|
-
return new Response(JSON.stringify(data ?? {}), {
|
|
14
|
+
return new Response(JSON.stringify(data ?? {}), {
|
|
15
|
+
headers: {
|
|
16
|
+
'Content-Type': 'application/json',
|
|
17
|
+
},
|
|
18
|
+
});
|
|
15
19
|
};
|
package/src/templates/email.ts
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Appends a message to the end of a Document configured through a trigger.
|
|
7
|
+
* Trigger must have a targetDocumentId field set in Meta.
|
|
7
8
|
*/
|
|
8
9
|
export default async ({
|
|
9
10
|
event: {
|
|
@@ -11,28 +12,30 @@ export default async ({
|
|
|
11
12
|
},
|
|
12
13
|
context: { space },
|
|
13
14
|
}: any) => {
|
|
14
|
-
const {
|
|
15
|
-
data: {
|
|
16
|
-
objects: [message],
|
|
17
|
-
},
|
|
18
|
-
} = await request.json();
|
|
15
|
+
const { data, trigger } = (await request.json()) as RequestPayload;
|
|
19
16
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
return new Response('Mailbox not found.', { status: 500 });
|
|
23
|
-
}
|
|
17
|
+
const documentId = trigger.meta.targetDocumentId;
|
|
18
|
+
const document = await space.db.query({ id: documentId }, { format: 'plain' }).first();
|
|
24
19
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
);
|
|
37
|
-
|
|
20
|
+
const contentId = document.content['/'].split(':')[3];
|
|
21
|
+
const documentContent = await space.db.query({ id: contentId }, { format: 'plain' }).first();
|
|
22
|
+
const modifiedContent = [
|
|
23
|
+
documentContent.content,
|
|
24
|
+
'',
|
|
25
|
+
'---',
|
|
26
|
+
`**From:** ${data.from}`,
|
|
27
|
+
`**Subject:** ${data.subject}`,
|
|
28
|
+
`**Date:** ${data.created}`,
|
|
29
|
+
'',
|
|
30
|
+
data.body,
|
|
31
|
+
].join('\n');
|
|
32
|
+
|
|
33
|
+
await space.db.update({ id: contentId }, { content: modifiedContent });
|
|
34
|
+
|
|
35
|
+
return new Response(JSON.stringify({ success: true }));
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
type RequestPayload = {
|
|
39
|
+
data: { from: string; subject: string; created: string; body: string };
|
|
40
|
+
trigger: { meta: { targetDocumentId: string } };
|
|
38
41
|
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import { defineFunction, S } from 'dxos:functions';
|
|
7
|
+
import {
|
|
8
|
+
HttpClient,
|
|
9
|
+
HttpClientRequest,
|
|
10
|
+
FetchHttpClient,
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
} from 'https://esm.sh/@effect/platform@0.77.2?deps=effect@3.13.3';
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
import { Effect, Schedule } from 'https://esm.sh/effect@3.13.3';
|
|
15
|
+
|
|
16
|
+
export default defineFunction({
|
|
17
|
+
description: 'Returns the exchange rate between two currencies.',
|
|
18
|
+
|
|
19
|
+
inputSchema: S.Struct({
|
|
20
|
+
from: S.String.annotations({ description: 'The source currency' }),
|
|
21
|
+
to: S.String.annotations({ description: 'The target currency' }),
|
|
22
|
+
}),
|
|
23
|
+
|
|
24
|
+
outputSchema: S.String.annotations({ description: 'The exchange rate between the two currencies' }),
|
|
25
|
+
|
|
26
|
+
handler: async ({
|
|
27
|
+
event: {
|
|
28
|
+
data: { from, to },
|
|
29
|
+
},
|
|
30
|
+
}: any) =>
|
|
31
|
+
Effect.gen(function* () {
|
|
32
|
+
const res = yield* HttpClientRequest.get(`https://free.ratesdb.com/v1/rates?from=${from}&to=${to}`).pipe(
|
|
33
|
+
HttpClient.execute,
|
|
34
|
+
Effect.flatMap((res: any) => res.json),
|
|
35
|
+
Effect.timeout('1 second'),
|
|
36
|
+
Effect.retry(Schedule.exponential(1000).pipe(Schedule.compose(Schedule.recurs(3)))),
|
|
37
|
+
Effect.scoped,
|
|
38
|
+
);
|
|
39
|
+
return res.data.rates[to].toString();
|
|
40
|
+
}).pipe(Effect.provide(FetchHttpClient.layer)),
|
|
41
|
+
});
|
package/src/templates/forex.ts
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
//
|
|
2
|
-
// Copyright
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export default
|
|
9
|
-
|
|
10
|
-
data: { request },
|
|
11
|
-
},
|
|
12
|
-
}: any) => {
|
|
13
|
-
const { args: [from = 'EUR', to = 'USD'] = [] } = await request.json();
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import { defineFunction, S } from 'dxos:functions';
|
|
7
|
+
|
|
8
|
+
export default defineFunction({
|
|
9
|
+
description: 'Returns the exchange rate between two currencies.',
|
|
14
10
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
11
|
+
inputSchema: S.Struct({
|
|
12
|
+
from: S.String.annotations({ description: 'The source currency' }),
|
|
13
|
+
to: S.String.annotations({ description: 'The target currency' }),
|
|
14
|
+
}),
|
|
19
15
|
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
handler: async ({
|
|
17
|
+
event: {
|
|
18
|
+
data: { from, to },
|
|
19
|
+
},
|
|
20
|
+
}: any) => {
|
|
21
|
+
const res = await fetch(`https://free.ratesdb.com/v1/rates?from=${from}&to=${to}`);
|
|
22
|
+
const {
|
|
23
|
+
data: { rates },
|
|
24
|
+
} = await res.json();
|
|
25
|
+
|
|
26
|
+
return rates[to].toString();
|
|
27
|
+
},
|
|
28
|
+
});
|
|
@@ -3,15 +3,19 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
// @ts-ignore
|
|
6
|
-
import chat from './
|
|
6
|
+
import chat from './chat.ts?raw';
|
|
7
7
|
// @ts-ignore
|
|
8
|
-
import chess from './
|
|
8
|
+
import chess from './chess.ts?raw';
|
|
9
9
|
// @ts-ignore
|
|
10
|
-
import
|
|
10
|
+
import discord from './discord.ts?raw';
|
|
11
11
|
// @ts-ignore
|
|
12
|
-
import
|
|
12
|
+
import echo from './echo.ts?raw';
|
|
13
13
|
// @ts-ignore
|
|
14
|
-
import
|
|
14
|
+
import email from './email.ts?raw';
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
import forexEffect from './forex-effect.ts?raw';
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
import forex from './forex.ts?raw';
|
|
15
19
|
|
|
16
20
|
const removeHeader = (str: string) => str.split('\n').slice(4).join('\n');
|
|
17
21
|
|
|
@@ -33,6 +37,11 @@ export const templates: Template[] = [
|
|
|
33
37
|
name: 'Forex',
|
|
34
38
|
source: removeHeader(forex),
|
|
35
39
|
},
|
|
40
|
+
{
|
|
41
|
+
id: 'dxos.org/script/forex-effect',
|
|
42
|
+
name: 'Forex (Effect)',
|
|
43
|
+
source: removeHeader(forexEffect),
|
|
44
|
+
},
|
|
36
45
|
{
|
|
37
46
|
id: 'dxos.org/script/gpt',
|
|
38
47
|
name: 'Gpt',
|
|
@@ -51,4 +60,10 @@ export const templates: Template[] = [
|
|
|
51
60
|
source: removeHeader(email),
|
|
52
61
|
presetId: 'dxos.org/function/email',
|
|
53
62
|
},
|
|
63
|
+
{
|
|
64
|
+
id: 'dxos.org/script/discord',
|
|
65
|
+
name: 'Discord',
|
|
66
|
+
source: removeHeader(discord),
|
|
67
|
+
presetId: 'dxos.org/function/discord',
|
|
68
|
+
},
|
|
54
69
|
];
|
package/src/translations.ts
CHANGED
|
@@ -2,16 +2,23 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { ScriptType } from '@dxos/functions';
|
|
6
|
+
|
|
5
7
|
import { SCRIPT_PLUGIN } from './meta';
|
|
6
8
|
|
|
7
9
|
export default [
|
|
8
10
|
{
|
|
9
11
|
'en-US': {
|
|
12
|
+
[ScriptType.typename]: {
|
|
13
|
+
'typename label': 'Script',
|
|
14
|
+
},
|
|
10
15
|
[SCRIPT_PLUGIN]: {
|
|
11
16
|
'plugin name': 'Scripts',
|
|
12
17
|
'object title placeholder': 'New script',
|
|
13
18
|
'create object label': 'Create script',
|
|
14
19
|
'create stack section label': 'Create script',
|
|
20
|
+
'description label': 'Description',
|
|
21
|
+
'description placeholder': 'Describe what the script does.',
|
|
15
22
|
'binding placeholder': 'Function name',
|
|
16
23
|
'function request placeholder': 'Function request',
|
|
17
24
|
'deploy label': 'Deploy',
|
|
@@ -27,6 +34,25 @@ export default [
|
|
|
27
34
|
'function url label': 'Invocation URL',
|
|
28
35
|
'function binding label': 'Function binding',
|
|
29
36
|
'function binding placeholder': 'BINDING',
|
|
37
|
+
'script publish settings label': 'Publishing',
|
|
38
|
+
'script publish settings description': 'Scripts can be shared publicly as Github gists.',
|
|
39
|
+
'no github token label': 'This space has no Github access token available.',
|
|
40
|
+
'open token manager label': 'Open Token Manager',
|
|
41
|
+
'publish label': 'Publish',
|
|
42
|
+
'publishing label': 'Publishing',
|
|
43
|
+
'editor input mode label': 'Editor input mode',
|
|
44
|
+
'select editor input mode placeholder': 'Select editor input mode…',
|
|
45
|
+
'settings editor input mode default label': 'Default',
|
|
46
|
+
'settings editor input mode vim label': 'Vim',
|
|
47
|
+
'settings editor input mode vscode label': 'VS Code',
|
|
48
|
+
'view group label': 'View',
|
|
49
|
+
'view editor label': 'Editor',
|
|
50
|
+
'view split label': 'Split',
|
|
51
|
+
'view debug label': 'Debug',
|
|
52
|
+
// TODO(wittjosiah): Replace debug with logs.
|
|
53
|
+
// 'view logs label': 'Logs',
|
|
54
|
+
'template select group label': 'Select template',
|
|
55
|
+
'function panel label': 'Debug Function',
|
|
30
56
|
},
|
|
31
57
|
},
|
|
32
58
|
},
|
package/src/types.ts
CHANGED
|
@@ -2,37 +2,38 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
SettingsProvides,
|
|
9
|
-
SurfaceProvides,
|
|
10
|
-
TranslationsProvides,
|
|
11
|
-
} from '@dxos/app-framework';
|
|
5
|
+
import { TitleAnnotationId } from '@effect/schema/AST';
|
|
6
|
+
|
|
7
|
+
import { SpaceSchema } from '@dxos/client/echo';
|
|
12
8
|
import { S } from '@dxos/echo-schema';
|
|
13
9
|
import { ScriptType } from '@dxos/functions';
|
|
14
|
-
import {
|
|
10
|
+
import { EditorInputMode } from '@dxos/react-ui-editor';
|
|
15
11
|
|
|
16
12
|
import { SCRIPT_PLUGIN } from './meta';
|
|
17
13
|
|
|
18
14
|
export namespace ScriptAction {
|
|
19
15
|
const SCRIPT_ACTION = `${SCRIPT_PLUGIN}/action`;
|
|
20
16
|
|
|
17
|
+
export const CreateScriptSchema = S.Struct({
|
|
18
|
+
name: S.optional(S.String),
|
|
19
|
+
// TODO(wittjosiah): Placeholder annotation?
|
|
20
|
+
gistUrl: S.optional(S.String.annotations({ [TitleAnnotationId]: 'Import from Gist (url)' })),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export type CreateScriptProps = S.Schema.Type<typeof CreateScriptSchema>;
|
|
24
|
+
|
|
21
25
|
export class Create extends S.TaggedClass<Create>()(`${SCRIPT_ACTION}/create`, {
|
|
22
|
-
input: S.Struct({
|
|
23
|
-
name: S.optional(S.String),
|
|
24
|
-
}),
|
|
26
|
+
input: S.extend(CreateScriptSchema, S.Struct({ space: SpaceSchema })),
|
|
25
27
|
output: S.Struct({
|
|
26
28
|
object: ScriptType,
|
|
27
29
|
}),
|
|
28
30
|
}) {}
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
export
|
|
33
|
+
export const ScriptSettingsSchema = S.mutable(
|
|
34
|
+
S.Struct({
|
|
35
|
+
editorInputMode: EditorInputMode,
|
|
36
|
+
}),
|
|
37
|
+
);
|
|
32
38
|
|
|
33
|
-
export type
|
|
34
|
-
MetadataRecordsProvides &
|
|
35
|
-
SchemaProvides &
|
|
36
|
-
SettingsProvides<ScriptSettingsProps> &
|
|
37
|
-
SurfaceProvides &
|
|
38
|
-
TranslationsProvides;
|
|
39
|
+
export type ScriptSettingsProps = S.Schema.Type<typeof ScriptSettingsSchema>;
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DebugPanel
|
|
3
|
-
} from "./chunk-K7KY6YMG.mjs";
|
|
4
|
-
import {
|
|
5
|
-
SCRIPT_PLUGIN
|
|
6
|
-
} from "./chunk-C7VBULMK.mjs";
|
|
7
|
-
|
|
8
|
-
// packages/plugins/experimental/plugin-script/src/components/AutomationPanel/AutomationPanel.tsx
|
|
9
|
-
import React, { useMemo, useState } from "react";
|
|
10
|
-
import { failUndefined } from "@dxos/debug";
|
|
11
|
-
import { FunctionType, ScriptType, getInvocationUrl, getUserFunctionUrlInMetadata } from "@dxos/functions";
|
|
12
|
-
import { useClient } from "@dxos/react-client";
|
|
13
|
-
import { Filter, getMeta, getSpace, useQuery } from "@dxos/react-client/echo";
|
|
14
|
-
import { Select, useTranslation } from "@dxos/react-ui";
|
|
15
|
-
var AutomationPanel = ({ subject }) => {
|
|
16
|
-
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
17
|
-
const space = getSpace(subject);
|
|
18
|
-
const functions = useQuery(space ?? void 0, subject instanceof ScriptType ? Filter.schema(FunctionType, {
|
|
19
|
-
source: subject
|
|
20
|
-
}) : Filter.schema(FunctionType, (fn) => fn.binding != null), {}, [
|
|
21
|
-
subject
|
|
22
|
-
]);
|
|
23
|
-
const [selectedFunction, setSelectedFunction] = useState(null);
|
|
24
|
-
const chatFunction = subject instanceof ScriptType ? functions[0] : selectedFunction;
|
|
25
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
26
|
-
className: "h-full flex flex-col"
|
|
27
|
-
}, !(subject instanceof ScriptType) && /* @__PURE__ */ React.createElement(BindingSelect, {
|
|
28
|
-
selectedFunction,
|
|
29
|
-
setSelectedFunction,
|
|
30
|
-
functions
|
|
31
|
-
}), chatFunction && /* @__PURE__ */ React.createElement(ChatPanel, {
|
|
32
|
-
fn: chatFunction,
|
|
33
|
-
subject
|
|
34
|
-
}), subject instanceof ScriptType && functions.length === 0 && /* @__PURE__ */ React.createElement("div", {
|
|
35
|
-
className: "p-1"
|
|
36
|
-
}, t("not deployed")));
|
|
37
|
-
};
|
|
38
|
-
var ChatPanel = ({ fn, subject }) => {
|
|
39
|
-
const client = useClient();
|
|
40
|
-
const space = getSpace(fn);
|
|
41
|
-
const existingFunctionUrl = getUserFunctionUrlInMetadata(getMeta(fn));
|
|
42
|
-
const functionUrl = useMemo(() => {
|
|
43
|
-
if (!existingFunctionUrl) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
return getInvocationUrl(existingFunctionUrl, client.config.values.runtime?.services?.edge?.url ?? "", {
|
|
47
|
-
spaceId: space?.id,
|
|
48
|
-
subjectId: subject?.id
|
|
49
|
-
});
|
|
50
|
-
}, [
|
|
51
|
-
existingFunctionUrl,
|
|
52
|
-
space,
|
|
53
|
-
subject
|
|
54
|
-
]);
|
|
55
|
-
return /* @__PURE__ */ React.createElement(DebugPanel, {
|
|
56
|
-
functionUrl,
|
|
57
|
-
classNames: "flex-1"
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
var BindingSelect = ({ selectedFunction, setSelectedFunction, functions }) => {
|
|
61
|
-
return /* @__PURE__ */ React.createElement(Select.Root, {
|
|
62
|
-
value: selectedFunction?.id,
|
|
63
|
-
onValueChange: (id) => setSelectedFunction(functions.find((fn) => fn.id === id) ?? failUndefined())
|
|
64
|
-
}, /* @__PURE__ */ React.createElement(Select.TriggerButton, {
|
|
65
|
-
placeholder: "Select value"
|
|
66
|
-
}), /* @__PURE__ */ React.createElement(Select.Portal, null, /* @__PURE__ */ React.createElement(Select.Content, null, /* @__PURE__ */ React.createElement(Select.ScrollUpButton, null), /* @__PURE__ */ React.createElement(Select.Viewport, null, functions.map(({ id, binding }) => /* @__PURE__ */ React.createElement(Select.Option, {
|
|
67
|
-
key: id,
|
|
68
|
-
value: id
|
|
69
|
-
}, binding))), /* @__PURE__ */ React.createElement(Select.ScrollDownButton, null), /* @__PURE__ */ React.createElement(Select.Arrow, null))));
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
// packages/plugins/experimental/plugin-script/src/components/AutomationPanel/index.ts
|
|
73
|
-
var AutomationPanel_default = AutomationPanel;
|
|
74
|
-
export {
|
|
75
|
-
AutomationPanel,
|
|
76
|
-
AutomationPanel_default as default
|
|
77
|
-
};
|
|
78
|
-
//# sourceMappingURL=AutomationPanel-RFQAQ7NF.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/AutomationPanel/AutomationPanel.tsx", "../../../src/components/AutomationPanel/index.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { useMemo, useState } from 'react';\n\nimport { failUndefined } from '@dxos/debug';\nimport { FunctionType, ScriptType, getInvocationUrl, getUserFunctionUrlInMetadata } from '@dxos/functions';\nimport { useClient } from '@dxos/react-client';\nimport { Filter, getMeta, getSpace, type ReactiveEchoObject, useQuery } from '@dxos/react-client/echo';\nimport { Select, useTranslation } from '@dxos/react-ui';\n\nimport { SCRIPT_PLUGIN } from '../../meta';\nimport { DebugPanel } from '../DebugPanel';\n\nexport interface AutomationPanelProps {\n subject: ReactiveEchoObject<any>;\n}\n\nexport const AutomationPanel = ({ subject }: AutomationPanelProps) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n const space = getSpace(subject);\n\n // TODO(dmaretskyi): Parametric query.\n const functions = useQuery(\n space ?? undefined,\n subject instanceof ScriptType\n ? Filter.schema(FunctionType, { source: subject })\n : Filter.schema(FunctionType, (fn) => fn.binding != null),\n {},\n [subject],\n );\n\n const [selectedFunction, setSelectedFunction] = useState<FunctionType | null>(null);\n const chatFunction = subject instanceof ScriptType ? functions[0] : selectedFunction;\n\n return (\n <div className='h-full flex flex-col'>\n {!(subject instanceof ScriptType) && (\n <BindingSelect\n selectedFunction={selectedFunction}\n setSelectedFunction={setSelectedFunction}\n functions={functions}\n />\n )}\n {chatFunction && <ChatPanel fn={chatFunction} subject={subject} />}\n {subject instanceof ScriptType && functions.length === 0 && <div className='p-1'>{t('not deployed')}</div>}\n </div>\n );\n};\n\nexport interface ChatPanelProps {\n fn: FunctionType;\n subject: ReactiveEchoObject<any>;\n}\n\nconst ChatPanel = ({ fn, subject }: ChatPanelProps) => {\n const client = useClient();\n const space = getSpace(fn);\n const existingFunctionUrl = getUserFunctionUrlInMetadata(getMeta(fn));\n const functionUrl = useMemo(() => {\n if (!existingFunctionUrl) {\n return;\n }\n\n return getInvocationUrl(existingFunctionUrl, client.config.values.runtime?.services?.edge?.url ?? '', {\n spaceId: space?.id,\n subjectId: subject?.id,\n });\n }, [existingFunctionUrl, space, subject]);\n\n return <DebugPanel functionUrl={functionUrl} classNames='flex-1' />;\n};\n\nexport interface BindingSelectProps {\n selectedFunction: FunctionType | null;\n setSelectedFunction: (fn: FunctionType) => void;\n functions: FunctionType[];\n}\n\nconst BindingSelect = ({ selectedFunction, setSelectedFunction, functions }: BindingSelectProps) => {\n return (\n <Select.Root\n value={selectedFunction?.id}\n onValueChange={(id) => setSelectedFunction(functions.find((fn) => fn.id === id) ?? failUndefined())}\n >\n <Select.TriggerButton placeholder='Select value' />\n <Select.Portal>\n <Select.Content>\n <Select.ScrollUpButton />\n <Select.Viewport>\n {functions.map(({ id, binding }) => (\n <Select.Option key={id} value={id}>\n {binding}\n </Select.Option>\n ))}\n </Select.Viewport>\n <Select.ScrollDownButton />\n <Select.Arrow />\n </Select.Content>\n </Select.Portal>\n </Select.Root>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AutomationPanel } from './AutomationPanel';\n\nexport * from './AutomationPanel';\n\nexport default AutomationPanel;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;AAIA,OAAOA,SAASC,SAASC,gBAAgB;AAEzC,SAASC,qBAAqB;AAC9B,SAASC,cAAcC,YAAYC,kBAAkBC,oCAAoC;AACzF,SAASC,iBAAiB;AAC1B,SAASC,QAAQC,SAASC,UAAmCC,gBAAgB;AAC7E,SAASC,QAAQC,sBAAsB;AAShC,IAAMC,kBAAkB,CAAC,EAAEC,QAAO,MAAwB;AAC/D,QAAM,EAAEC,EAAC,IAAKC,eAAeC,aAAAA;AAC7B,QAAMC,QAAQC,SAASL,OAAAA;AAGvB,QAAMM,YAAYC,SAChBH,SAASI,QACTR,mBAAmBS,aACfC,OAAOC,OAAOC,cAAc;IAAEC,QAAQb;EAAQ,CAAA,IAC9CU,OAAOC,OAAOC,cAAc,CAACE,OAAOA,GAAGC,WAAW,IAAA,GACtD,CAAC,GACD;IAACf;GAAQ;AAGX,QAAM,CAACgB,kBAAkBC,mBAAAA,IAAuBC,SAA8B,IAAA;AAC9E,QAAMC,eAAenB,mBAAmBS,aAAaH,UAAU,CAAA,IAAKU;AAEpE,SACE,sBAAA,cAACI,OAAAA;IAAIC,WAAU;KACZ,EAAErB,mBAAmBS,eACpB,sBAAA,cAACa,eAAAA;IACCN;IACAC;IACAX;MAGHa,gBAAgB,sBAAA,cAACI,WAAAA;IAAUT,IAAIK;IAAcnB;MAC7CA,mBAAmBS,cAAcH,UAAUkB,WAAW,KAAK,sBAAA,cAACJ,OAAAA;IAAIC,WAAU;KAAOpB,EAAE,cAAA,CAAA,CAAA;AAG1F;AAOA,IAAMsB,YAAY,CAAC,EAAET,IAAId,QAAO,MAAkB;AAChD,QAAMyB,SAASC,UAAAA;AACf,QAAMtB,QAAQC,SAASS,EAAAA;AACvB,QAAMa,sBAAsBC,6BAA6BC,QAAQf,EAAAA,CAAAA;AACjE,QAAMgB,cAAcC,QAAQ,MAAA;AAC1B,QAAI,CAACJ,qBAAqB;AACxB;IACF;AAEA,WAAOK,iBAAiBL,qBAAqBF,OAAOQ,OAAOC,OAAOC,SAASC,UAAUC,MAAMC,OAAO,IAAI;MACpGC,SAASnC,OAAOoC;MAChBC,WAAWzC,SAASwC;IACtB,CAAA;EACF,GAAG;IAACb;IAAqBvB;IAAOJ;GAAQ;AAExC,SAAO,sBAAA,cAAC0C,YAAAA;IAAWZ;IAA0Ba,YAAW;;AAC1D;AAQA,IAAMrB,gBAAgB,CAAC,EAAEN,kBAAkBC,qBAAqBX,UAAS,MAAsB;AAC7F,SACE,sBAAA,cAACsC,OAAOC,MAAI;IACVC,OAAO9B,kBAAkBwB;IACzBO,eAAe,CAACP,OAAOvB,oBAAoBX,UAAU0C,KAAK,CAAClC,OAAOA,GAAG0B,OAAOA,EAAAA,KAAOS,cAAAA,CAAAA;KAEnF,sBAAA,cAACL,OAAOM,eAAa;IAACC,aAAY;MAClC,sBAAA,cAACP,OAAOQ,QAAM,MACZ,sBAAA,cAACR,OAAOS,SAAO,MACb,sBAAA,cAACT,OAAOU,gBAAc,IAAA,GACtB,sBAAA,cAACV,OAAOW,UAAQ,MACbjD,UAAUkD,IAAI,CAAC,EAAEhB,IAAIzB,QAAO,MAC3B,sBAAA,cAAC6B,OAAOa,QAAM;IAACC,KAAKlB;IAAIM,OAAON;KAC5BzB,OAAAA,CAAAA,CAAAA,GAIP,sBAAA,cAAC6B,OAAOe,kBAAgB,IAAA,GACxB,sBAAA,cAACf,OAAOgB,OAAK,IAAA,CAAA,CAAA,CAAA;AAKvB;;;AC/FA,IAAA,0BAAeC;",
|
|
6
|
-
"names": ["React", "useMemo", "useState", "failUndefined", "FunctionType", "ScriptType", "getInvocationUrl", "getUserFunctionUrlInMetadata", "useClient", "Filter", "getMeta", "getSpace", "useQuery", "Select", "useTranslation", "AutomationPanel", "subject", "t", "useTranslation", "SCRIPT_PLUGIN", "space", "getSpace", "functions", "useQuery", "undefined", "ScriptType", "Filter", "schema", "FunctionType", "source", "fn", "binding", "selectedFunction", "setSelectedFunction", "useState", "chatFunction", "div", "className", "BindingSelect", "ChatPanel", "length", "client", "useClient", "existingFunctionUrl", "getUserFunctionUrlInMetadata", "getMeta", "functionUrl", "useMemo", "getInvocationUrl", "config", "values", "runtime", "services", "edge", "url", "spaceId", "id", "subjectId", "DebugPanel", "classNames", "Select", "Root", "value", "onValueChange", "find", "failUndefined", "TriggerButton", "placeholder", "Portal", "Content", "ScrollUpButton", "Viewport", "map", "Option", "key", "ScrollDownButton", "Arrow", "AutomationPanel"]
|
|
7
|
-
}
|