@dxos/plugin-script 0.7.5-labs.e27f9b9 → 0.7.5-labs.f400bbc
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-SJ4J527G.mjs → chunk-5SXOHNAK.mjs} +4 -4
- package/dist/lib/browser/chunk-5SXOHNAK.mjs.map +7 -0
- package/dist/lib/browser/{chunk-ZM6T4HPR.mjs → chunk-6MOQ4BP3.mjs} +2 -2
- package/dist/lib/browser/chunk-FVVCAWNP.mjs +21 -0
- package/dist/lib/browser/chunk-FVVCAWNP.mjs.map +7 -0
- package/dist/lib/browser/{ScriptContainer-EBER222J.mjs → chunk-G2FYNDU4.mjs} +94 -305
- package/dist/lib/browser/chunk-G2FYNDU4.mjs.map +7 -0
- package/dist/lib/browser/{chunk-XPGBHZ3L.mjs → chunk-N46LE7FS.mjs} +2 -2
- package/dist/lib/browser/chunk-PZPYF7M4.mjs +69 -0
- package/dist/lib/browser/chunk-PZPYF7M4.mjs.map +7 -0
- package/dist/lib/browser/{chunk-PEYUXEY6.mjs → chunk-VTWBVFBK.mjs} +5 -7
- package/dist/lib/browser/{chunk-PEYUXEY6.mjs.map → chunk-VTWBVFBK.mjs.map} +3 -3
- package/dist/lib/browser/{compiler-HT53ILG7.mjs → compiler-YY2XSKHQ.mjs} +4 -6
- package/dist/lib/browser/compiler-YY2XSKHQ.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +67 -36
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/{intent-resolver-G2REMZHC.mjs → intent-resolver-D6FPY5ZA.mjs} +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-GH4LL6CF.mjs → react-surface-G4C2PZ2K.mjs} +26 -10
- package/dist/lib/browser/react-surface-G4C2PZ2K.mjs.map +7 -0
- package/dist/lib/browser/{settings-YQQEU3DF.mjs → settings-SZCDKHWO.mjs} +3 -3
- package/dist/lib/browser/types.mjs +2 -2
- package/dist/lib/node/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-EFTZN5X7.cjs → chunk-5UH3F7TA.cjs} +8 -5
- package/dist/lib/node/chunk-5UH3F7TA.cjs.map +7 -0
- package/dist/lib/node/{chunk-A2DI2G4D.cjs → chunk-ALY3N6PW.cjs} +6 -6
- package/dist/lib/node/{chunk-6VKZJ4MH.cjs → chunk-DJGLGRQV.cjs} +6 -6
- package/dist/lib/node/chunk-ITAJ3WRW.cjs +77 -0
- package/dist/lib/node/chunk-ITAJ3WRW.cjs.map +7 -0
- package/dist/lib/node/{chunk-DQRAVZM7.cjs → chunk-K3ZZWVXS.cjs} +7 -7
- package/dist/lib/node/chunk-K3ZZWVXS.cjs.map +7 -0
- package/dist/lib/node/{chunk-UAHKFS7F.cjs → chunk-TOXBGIEI.cjs} +9 -12
- package/dist/lib/node/{chunk-UAHKFS7F.cjs.map → chunk-TOXBGIEI.cjs.map} +3 -3
- package/dist/lib/node/chunk-XKYJYY3T.cjs +498 -0
- package/dist/lib/node/chunk-XKYJYY3T.cjs.map +7 -0
- package/dist/lib/node/{compiler-457ZR24G.cjs → compiler-UIBLKJKG.cjs} +9 -9
- package/dist/lib/node/compiler-UIBLKJKG.cjs.map +7 -0
- package/dist/lib/node/index.cjs +77 -48
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/{intent-resolver-IWGK77AZ.cjs → intent-resolver-NYJFPD5B.cjs} +9 -9
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/{react-surface-3JKCVT5O.cjs → react-surface-EGSE3FMN.cjs} +33 -21
- package/dist/lib/node/react-surface-EGSE3FMN.cjs.map +7 -0
- package/dist/lib/node/{settings-NGHDYAVK.cjs → settings-SZFSMSKM.cjs} +9 -9
- package/dist/lib/node/types.cjs +4 -4
- package/dist/lib/node/types.cjs.map +1 -1
- package/dist/lib/node-esm/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-XUWS7OTK.mjs → chunk-2AFXX34U.mjs} +4 -4
- package/dist/lib/node-esm/chunk-2AFXX34U.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-675XSDRN.mjs → chunk-CP5LXTK5.mjs} +2 -2
- package/dist/lib/node-esm/{ScriptContainer-56ES2HQ5.mjs → chunk-NRICF4KE.mjs} +94 -305
- package/dist/lib/node-esm/chunk-NRICF4KE.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-BHP545D7.mjs → chunk-P2V2Y5LV.mjs} +5 -2
- package/dist/lib/node-esm/chunk-P2V2Y5LV.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-TYGM5YLW.mjs → chunk-S64WSJQK.mjs} +5 -7
- package/dist/lib/node-esm/{chunk-TYGM5YLW.mjs.map → chunk-S64WSJQK.mjs.map} +3 -3
- package/dist/lib/node-esm/{chunk-JHGOPQVO.mjs → chunk-UNQFIERE.mjs} +2 -2
- 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-PEARFTFR.mjs → compiler-XTXFGZJM.mjs} +4 -6
- package/dist/lib/node-esm/compiler-XTXFGZJM.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +67 -36
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/{intent-resolver-KGADFH3H.mjs → intent-resolver-KLBHSMW4.mjs} +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{react-surface-JW776PVP.mjs → react-surface-7YSGHZQM.mjs} +26 -10
- package/dist/lib/node-esm/react-surface-7YSGHZQM.mjs.map +7 -0
- package/dist/lib/node-esm/{settings-XGXDY4NI.mjs → settings-GR4O2WHZ.mjs} +3 -3
- package/dist/lib/node-esm/types.mjs +2 -2
- package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/artifact-definition.d.ts +11 -0
- package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +1 -0
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- 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 +2 -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 +2 -3
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts +1 -2
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.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.map +1 -0
- package/dist/types/src/hooks/format.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +7 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -0
- package/dist/types/src/{components/ScriptToolbar/templateSelect.d.ts → hooks/template.d.ts} +2 -2
- package/dist/types/src/hooks/template.d.ts.map +1 -0
- package/dist/types/src/{components/ScriptToolbar → hooks}/useToolbarAction.d.ts +1 -1
- package/dist/types/src/hooks/useToolbarAction.d.ts.map +1 -0
- package/dist/types/src/hooks/useToolbarState.d.ts.map +1 -0
- package/dist/types/src/{components/ScriptToolbar → hooks}/view.d.ts +1 -1
- package/dist/types/src/hooks/view.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +0 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +1 -0
- 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/forex-effect.d.ts +0 -3
- package/dist/types/src/templates/forex-effect.d.ts.map +1 -1
- package/dist/types/src/templates/forex.d.ts +0 -3
- package/dist/types/src/templates/forex.d.ts.map +1 -1
- package/dist/types/src/templates/index.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +3 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +1 -1
- package/package.json +43 -42
- package/src/ScriptPlugin.tsx +40 -15
- package/src/capabilities/artifact-definition.ts +224 -0
- package/src/capabilities/compiler.ts +1 -1
- package/src/capabilities/index.ts +1 -0
- package/src/capabilities/react-surface.tsx +11 -4
- package/src/components/DebugPanel/DebugPanel.tsx +2 -2
- package/src/components/FrameContainer/FrameContainer.tsx +5 -4
- package/src/components/ScriptContainer.tsx +10 -5
- package/src/components/ScriptSettingsPanel.tsx +2 -2
- package/src/components/ScriptToolbar/ScriptToolbar.tsx +8 -6
- package/src/components/TypescriptEditor/TypescriptEditor.tsx +2 -2
- package/src/components/index.ts +1 -1
- package/src/events.ts +11 -0
- package/src/{components/ScriptToolbar → hooks}/deploy.ts +16 -5
- package/src/{components/ScriptToolbar → hooks}/format.ts +1 -1
- package/src/hooks/index.ts +11 -0
- package/src/{components/ScriptToolbar/templateSelect.ts → hooks/template.ts} +2 -2
- package/src/{components/ScriptToolbar → hooks}/useToolbarAction.ts +1 -1
- package/src/{components/ScriptToolbar → hooks}/view.ts +5 -2
- package/src/index.ts +0 -1
- package/src/meta.ts +3 -1
- package/src/templates/chat.ts +4 -4
- package/src/templates/chess.ts +42 -35
- package/src/templates/discord.ts +103 -0
- package/src/templates/forex-effect.ts +16 -17
- package/src/templates/forex.ts +2 -3
- package/src/templates/index.ts +10 -2
- package/src/translations.ts +3 -0
- package/dist/lib/browser/AutomationPanel-OOIRJFPJ.mjs +0 -78
- package/dist/lib/browser/AutomationPanel-OOIRJFPJ.mjs.map +0 -7
- package/dist/lib/browser/ScriptContainer-EBER222J.mjs.map +0 -7
- package/dist/lib/browser/chunk-5BU5ERNU.mjs +0 -18
- package/dist/lib/browser/chunk-5BU5ERNU.mjs.map +0 -7
- package/dist/lib/browser/chunk-SDHKTS6H.mjs +0 -237
- package/dist/lib/browser/chunk-SDHKTS6H.mjs.map +0 -7
- package/dist/lib/browser/chunk-SJ4J527G.mjs.map +0 -7
- package/dist/lib/browser/chunk-VIX22OMB.mjs +0 -60
- package/dist/lib/browser/chunk-VIX22OMB.mjs.map +0 -7
- package/dist/lib/browser/compiler-HT53ILG7.mjs.map +0 -7
- package/dist/lib/browser/react-surface-GH4LL6CF.mjs.map +0 -7
- package/dist/lib/node/AutomationPanel-EPRDDR3A.cjs +0 -104
- package/dist/lib/node/AutomationPanel-EPRDDR3A.cjs.map +0 -7
- package/dist/lib/node/ScriptContainer-UXMQLKDV.cjs +0 -690
- package/dist/lib/node/ScriptContainer-UXMQLKDV.cjs.map +0 -7
- package/dist/lib/node/chunk-DQRAVZM7.cjs.map +0 -7
- package/dist/lib/node/chunk-EFTZN5X7.cjs.map +0 -7
- package/dist/lib/node/chunk-PKT5DD3O.cjs +0 -70
- package/dist/lib/node/chunk-PKT5DD3O.cjs.map +0 -7
- package/dist/lib/node/chunk-T4TXCRN5.cjs +0 -260
- package/dist/lib/node/chunk-T4TXCRN5.cjs.map +0 -7
- package/dist/lib/node/compiler-457ZR24G.cjs.map +0 -7
- package/dist/lib/node/react-surface-3JKCVT5O.cjs.map +0 -7
- package/dist/lib/node-esm/AutomationPanel-DMLAGQS5.mjs +0 -79
- package/dist/lib/node-esm/AutomationPanel-DMLAGQS5.mjs.map +0 -7
- package/dist/lib/node-esm/ScriptContainer-56ES2HQ5.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-BHP545D7.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-G76M6O46.mjs +0 -239
- package/dist/lib/node-esm/chunk-G76M6O46.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-NBAL5DXN.mjs +0 -62
- package/dist/lib/node-esm/chunk-NBAL5DXN.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-XUWS7OTK.mjs.map +0 -7
- package/dist/lib/node-esm/compiler-PEARFTFR.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-JW776PVP.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/ScriptToolbar/deploy.d.ts.map +0 -1
- package/dist/types/src/components/ScriptToolbar/format.d.ts.map +0 -1
- package/dist/types/src/components/ScriptToolbar/templateSelect.d.ts.map +0 -1
- package/dist/types/src/components/ScriptToolbar/useToolbarAction.d.ts.map +0 -1
- package/dist/types/src/components/ScriptToolbar/useToolbarState.d.ts.map +0 -1
- package/dist/types/src/components/ScriptToolbar/view.d.ts.map +0 -1
- package/src/bundler/bundler.test.ts +0 -55
- package/src/bundler/bundler.ts +0 -250
- package/src/bundler/index.ts +0 -5
- package/src/components/AutomationPanel/AutomationPanel.tsx +0 -104
- package/src/components/AutomationPanel/index.ts +0 -9
- /package/dist/lib/browser/{chunk-ZM6T4HPR.mjs.map → chunk-6MOQ4BP3.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-XPGBHZ3L.mjs.map → chunk-N46LE7FS.mjs.map} +0 -0
- /package/dist/lib/browser/{intent-resolver-G2REMZHC.mjs.map → intent-resolver-D6FPY5ZA.mjs.map} +0 -0
- /package/dist/lib/browser/{settings-YQQEU3DF.mjs.map → settings-SZCDKHWO.mjs.map} +0 -0
- /package/dist/lib/node/{chunk-A2DI2G4D.cjs.map → chunk-ALY3N6PW.cjs.map} +0 -0
- /package/dist/lib/node/{chunk-6VKZJ4MH.cjs.map → chunk-DJGLGRQV.cjs.map} +0 -0
- /package/dist/lib/node/{intent-resolver-IWGK77AZ.cjs.map → intent-resolver-NYJFPD5B.cjs.map} +0 -0
- /package/dist/lib/node/{settings-NGHDYAVK.cjs.map → settings-SZFSMSKM.cjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-675XSDRN.mjs.map → chunk-CP5LXTK5.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-JHGOPQVO.mjs.map → chunk-UNQFIERE.mjs.map} +0 -0
- /package/dist/lib/node-esm/{intent-resolver-KGADFH3H.mjs.map → intent-resolver-KLBHSMW4.mjs.map} +0 -0
- /package/dist/lib/node-esm/{settings-XGXDY4NI.mjs.map → settings-GR4O2WHZ.mjs.map} +0 -0
- /package/dist/types/src/{components/ScriptToolbar → hooks}/deploy.d.ts +0 -0
- /package/dist/types/src/{components/ScriptToolbar → hooks}/format.d.ts +0 -0
- /package/dist/types/src/{components/ScriptToolbar → hooks}/useToolbarState.d.ts +0 -0
- /package/src/{components/ScriptToolbar → hooks}/useToolbarState.ts +0 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Capabilities, contributes, createIntent, type PromiseIntentDispatcher } from '@dxos/app-framework';
|
|
6
|
+
import { defineArtifact, defineTool, ToolResult } from '@dxos/artifact';
|
|
7
|
+
import { createArtifactElement } from '@dxos/assistant';
|
|
8
|
+
import { ObjectId, S } from '@dxos/echo-schema';
|
|
9
|
+
import { ScriptType } from '@dxos/functions';
|
|
10
|
+
import { invariant } from '@dxos/invariant';
|
|
11
|
+
import { SpaceAction } from '@dxos/plugin-space/types';
|
|
12
|
+
import { create, makeRef, type Space } from '@dxos/react-client/echo';
|
|
13
|
+
import { TextType } from '@dxos/schema';
|
|
14
|
+
|
|
15
|
+
import { meta } from '../meta';
|
|
16
|
+
// TODO(burdon): Factor out.
|
|
17
|
+
declare global {
|
|
18
|
+
interface ToolContextExtensions {
|
|
19
|
+
space?: Space;
|
|
20
|
+
dispatch?: PromiseIntentDispatcher;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default () => {
|
|
25
|
+
const definition = defineArtifact({
|
|
26
|
+
id: meta.id,
|
|
27
|
+
name: meta.name,
|
|
28
|
+
// TODO(dmaretskyi): Since writing scripts requires a lot of domain knowledge,
|
|
29
|
+
// we should offload the work of synthesizing the code to a separate model.
|
|
30
|
+
// The main reasoning model will give it a concrete task and the script model will synthesize the code, knowing all the docs.
|
|
31
|
+
instructions: `
|
|
32
|
+
If the user explicitly requests you to write a script, you can create one.
|
|
33
|
+
If the user requests you to change one of the existing script, you can update it.
|
|
34
|
+
Scripts are short code pieces of executable code that can be used to perform computations, integrate with external systems, and perform automated tasks.
|
|
35
|
+
Each script must follow as strict shape for the definition but the body can contain any valid executable code.
|
|
36
|
+
Scripts are written in JavaScript or TypeScript.
|
|
37
|
+
Each script must define an input schema and output schema.
|
|
38
|
+
Each script must have its own detailed description.
|
|
39
|
+
|
|
40
|
+
Important: You cannot execute scripts. Scripts are only available as tools after the user deploys them. You must only call the available tools.
|
|
41
|
+
|
|
42
|
+
Description:
|
|
43
|
+
The description is a detailed description of the script.
|
|
44
|
+
It is used to describe the script's purpose, input, and output.
|
|
45
|
+
The description is used to generate the script's documentation.
|
|
46
|
+
The description is also goes into the script metadata.
|
|
47
|
+
The description is used by AI to understand the script and its purpose.
|
|
48
|
+
The description must provide cases on when the script should be used.
|
|
49
|
+
|
|
50
|
+
Schema:
|
|
51
|
+
The schema is defined using a schema-DSL library called Effect Schema.
|
|
52
|
+
The input schema describes the arguments that the script accepts.
|
|
53
|
+
The output schema describes the result that the script produces.
|
|
54
|
+
The schema is used to validate the script's input and output.
|
|
55
|
+
The schema is also goes into the script metadata.
|
|
56
|
+
The properties in the schema must have valid descriptions.
|
|
57
|
+
The input and output schemas must both be a struct of fields.
|
|
58
|
+
|
|
59
|
+
Restricts:
|
|
60
|
+
The scripts can only import code from "dxos:functions" module. No other modules are allowed.
|
|
61
|
+
Some web APIs are available - like fetch.
|
|
62
|
+
|
|
63
|
+
Reasoning:
|
|
64
|
+
Before writing a script, synthesize the following information:
|
|
65
|
+
- Description
|
|
66
|
+
- What APIs will be used.
|
|
67
|
+
- Detailed input schema
|
|
68
|
+
- Detailed output schema
|
|
69
|
+
|
|
70
|
+
<apis>
|
|
71
|
+
export function defineFunction(params: {
|
|
72
|
+
description: string,
|
|
73
|
+
inputSchema: S.Schema,
|
|
74
|
+
outputSchema: S.Schema,
|
|
75
|
+
handler: (params: { event: { data: TInput } }) => Promise<TOutput>
|
|
76
|
+
}): FunctionDefinition
|
|
77
|
+
/**
|
|
78
|
+
* Effect Schema
|
|
79
|
+
*/
|
|
80
|
+
export const S;
|
|
81
|
+
|
|
82
|
+
// Examples:
|
|
83
|
+
|
|
84
|
+
S.String
|
|
85
|
+
S.Number
|
|
86
|
+
S.Boolean
|
|
87
|
+
S.Struct({
|
|
88
|
+
from: S.String.annotations({ description: 'The source currency' }),
|
|
89
|
+
to: S.String.annotations({ description: 'The target currency' }),
|
|
90
|
+
})
|
|
91
|
+
S.Array(S.String)
|
|
92
|
+
S.Union(S.String, S.Number)
|
|
93
|
+
S.optional(S.String)
|
|
94
|
+
S.String.annotations({ description: 'The source currency' })
|
|
95
|
+
</apis>
|
|
96
|
+
|
|
97
|
+
<handler_function>
|
|
98
|
+
Async function that takes the argument in the form of:
|
|
99
|
+
|
|
100
|
+
type HandlerFunctionParam = {
|
|
101
|
+
event: {
|
|
102
|
+
data: T // The input schema
|
|
103
|
+
},
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
The function must return the result that matches the output schema.
|
|
107
|
+
</handler_function>
|
|
108
|
+
|
|
109
|
+
<example>
|
|
110
|
+
import { defineFunction, S } from 'dxos:functions';
|
|
111
|
+
|
|
112
|
+
export default defineFunction({
|
|
113
|
+
description: 'Returns the exchange rate between two currencies.',
|
|
114
|
+
|
|
115
|
+
inputSchema: S.Struct({
|
|
116
|
+
from: S.String.annotations({ description: 'The source currency' }),
|
|
117
|
+
to: S.String.annotations({ description: 'The target currency' }),
|
|
118
|
+
}),
|
|
119
|
+
|
|
120
|
+
outputSchema: S.Struct({
|
|
121
|
+
rate: S.String.annotations({ description: 'The exchange rate' }),
|
|
122
|
+
}),
|
|
123
|
+
|
|
124
|
+
handler: async ({
|
|
125
|
+
event: {
|
|
126
|
+
data: { from, to },
|
|
127
|
+
},
|
|
128
|
+
}: any) => {
|
|
129
|
+
const res = await fetch(\`https://free.ratesdb.com/v1/rates?from=\${from}&to=\${to}\`);
|
|
130
|
+
const {
|
|
131
|
+
data: { rates },
|
|
132
|
+
} = await res.json();
|
|
133
|
+
|
|
134
|
+
return { rate: rates[to].toString() };
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
</example>
|
|
138
|
+
`,
|
|
139
|
+
schema: ScriptType,
|
|
140
|
+
tools: [
|
|
141
|
+
defineTool(meta.id, {
|
|
142
|
+
name: 'create',
|
|
143
|
+
description: 'Create a new script. Returns the artifact definition for the script',
|
|
144
|
+
caption: 'Creating script...',
|
|
145
|
+
schema: S.Struct({
|
|
146
|
+
name: S.String.annotations({ description: 'The name of the script' }),
|
|
147
|
+
code: S.String.annotations({
|
|
148
|
+
description: 'The full code of the script in JavaScript or TypeScript. Must be valid executable code.',
|
|
149
|
+
}),
|
|
150
|
+
}),
|
|
151
|
+
execute: async ({ name, code }, { extensions }) => {
|
|
152
|
+
invariant(extensions?.space, 'No space');
|
|
153
|
+
invariant(extensions?.dispatch, 'No intent dispatcher');
|
|
154
|
+
const script = create(ScriptType, {
|
|
155
|
+
name,
|
|
156
|
+
source: makeRef(
|
|
157
|
+
create(TextType, {
|
|
158
|
+
content: code,
|
|
159
|
+
}),
|
|
160
|
+
),
|
|
161
|
+
});
|
|
162
|
+
extensions.space.db.add(script);
|
|
163
|
+
await extensions.space.db.flush();
|
|
164
|
+
|
|
165
|
+
const intent = createIntent(SpaceAction.AddObject, { target: extensions.space, object: script });
|
|
166
|
+
const { data, error } = await extensions.dispatch(intent);
|
|
167
|
+
if (!data || error) {
|
|
168
|
+
return ToolResult.Error(error?.message ?? 'Failed to create chess game');
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return ToolResult.Success(createArtifactElement(script.id));
|
|
172
|
+
},
|
|
173
|
+
}),
|
|
174
|
+
defineTool(meta.id, {
|
|
175
|
+
name: 'inspect',
|
|
176
|
+
description: 'Inspect a script. Returns the artifact definition for the script',
|
|
177
|
+
caption: 'Inspecting script...',
|
|
178
|
+
schema: S.Struct({
|
|
179
|
+
id: ObjectId,
|
|
180
|
+
}),
|
|
181
|
+
execute: async ({ id }, { extensions }) => {
|
|
182
|
+
invariant(extensions?.space, 'No space');
|
|
183
|
+
|
|
184
|
+
const script = (await extensions.space.db.query({ id }).first()) as ScriptType;
|
|
185
|
+
const { content } = await script.source.load();
|
|
186
|
+
|
|
187
|
+
return ToolResult.Success({
|
|
188
|
+
name: script.name,
|
|
189
|
+
code: content,
|
|
190
|
+
});
|
|
191
|
+
},
|
|
192
|
+
}),
|
|
193
|
+
defineTool(meta.id, {
|
|
194
|
+
name: 'update',
|
|
195
|
+
description: 'Update a script. Returns the artifact definition for the script',
|
|
196
|
+
caption: 'Updating script...',
|
|
197
|
+
schema: S.Struct({
|
|
198
|
+
id: ObjectId,
|
|
199
|
+
code: S.String.annotations({
|
|
200
|
+
description: 'The full code of the script in JavaScript or TypeScript. Must be valid executable code.',
|
|
201
|
+
}),
|
|
202
|
+
}),
|
|
203
|
+
execute: async ({ id, code }, { extensions }) => {
|
|
204
|
+
invariant(extensions?.space, 'No space');
|
|
205
|
+
|
|
206
|
+
const script = (await extensions.space.db.query({ id }).first()) as ScriptType;
|
|
207
|
+
const source = await script.source.load();
|
|
208
|
+
if (!source) {
|
|
209
|
+
return ToolResult.Error('Script not found');
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
source.content = code;
|
|
213
|
+
await extensions.space?.db.flush();
|
|
214
|
+
|
|
215
|
+
return ToolResult.Success({
|
|
216
|
+
name: script.name,
|
|
217
|
+
});
|
|
218
|
+
},
|
|
219
|
+
}),
|
|
220
|
+
],
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
return contributes(Capabilities.ArtifactDefinition, definition);
|
|
224
|
+
};
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
import wasmUrl from 'esbuild-wasm/esbuild.wasm?url';
|
|
7
7
|
|
|
8
8
|
import { contributes } from '@dxos/app-framework';
|
|
9
|
+
import { initializeBundler } from '@dxos/functions/bundler';
|
|
9
10
|
|
|
10
11
|
import { ScriptCapabilities } from './capabilities';
|
|
11
|
-
import { initializeBundler } from '../bundler';
|
|
12
12
|
import { Compiler } from '../compiler';
|
|
13
13
|
|
|
14
14
|
export default async () => {
|
|
@@ -8,5 +8,6 @@ export const Compiler = lazy(() => import('./compiler'));
|
|
|
8
8
|
export const IntentResolver = lazy(() => import('./intent-resolver'));
|
|
9
9
|
export const ReactSurface = lazy(() => import('./react-surface'));
|
|
10
10
|
export const ScriptSettings = lazy(() => import('./settings'));
|
|
11
|
+
export const ArtifactDefinition = lazy(() => import('./artifact-definition'));
|
|
11
12
|
|
|
12
13
|
export * from './capabilities';
|
|
@@ -10,7 +10,8 @@ import { SettingsStore } from '@dxos/local-storage';
|
|
|
10
10
|
import { Clipboard } from '@dxos/react-ui';
|
|
11
11
|
|
|
12
12
|
import { ScriptCapabilities } from './capabilities';
|
|
13
|
-
import {
|
|
13
|
+
import { DebugPanel, ScriptSettings, ScriptContainer, ScriptSettingsPanel } from '../components';
|
|
14
|
+
import { useDeployState, useToolbarState } from '../hooks';
|
|
14
15
|
import { SCRIPT_PLUGIN } from '../meta';
|
|
15
16
|
import { type ScriptSettingsProps } from '../types';
|
|
16
17
|
|
|
@@ -29,16 +30,22 @@ export default () =>
|
|
|
29
30
|
filter: (data): data is { subject: ScriptType } => data.subject instanceof ScriptType,
|
|
30
31
|
component: ({ data, role }) => {
|
|
31
32
|
const compiler = useCapability(ScriptCapabilities.Compiler);
|
|
32
|
-
|
|
33
|
+
// TODO(dmaretskyi): Since settings store is not reactive, this would break on the script plugin being enabled without a page reload.
|
|
34
|
+
const settings = useCapability(Capabilities.SettingsStore).getStore<ScriptSettingsProps>(SCRIPT_PLUGIN)?.value;
|
|
33
35
|
return <ScriptContainer role={role} script={data.subject} settings={settings} env={compiler.environment} />;
|
|
34
36
|
},
|
|
35
37
|
}),
|
|
36
38
|
createSurface({
|
|
37
39
|
id: `${SCRIPT_PLUGIN}/automation`,
|
|
38
|
-
role: 'complementary--
|
|
40
|
+
role: 'complementary--function',
|
|
39
41
|
position: 'hoist',
|
|
40
42
|
filter: (data): data is { subject: ScriptType } => data.subject instanceof ScriptType,
|
|
41
|
-
component: ({ data }) =>
|
|
43
|
+
component: ({ data }) => {
|
|
44
|
+
// TODO(wittjosiah): Decouple hooks from toolbar state.
|
|
45
|
+
const state = useToolbarState({ view: 'editor' });
|
|
46
|
+
useDeployState({ state, script: data.subject });
|
|
47
|
+
return <DebugPanel functionUrl={state.functionUrl} />;
|
|
48
|
+
},
|
|
42
49
|
}),
|
|
43
50
|
createSurface({
|
|
44
51
|
id: `${SCRIPT_PLUGIN}/settings-panel`,
|
|
@@ -7,7 +7,7 @@ import React, { forwardRef, useEffect, useRef, useState } from 'react';
|
|
|
7
7
|
import { log } from '@dxos/log';
|
|
8
8
|
import { Avatar, Icon, Input, type ThemedClassName, Toolbar, useTranslation } from '@dxos/react-ui';
|
|
9
9
|
import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
10
|
-
import { mx } from '@dxos/react-ui-theme';
|
|
10
|
+
import { errorText, mx } from '@dxos/react-ui-theme';
|
|
11
11
|
|
|
12
12
|
import { SCRIPT_PLUGIN } from '../../meta';
|
|
13
13
|
|
|
@@ -232,7 +232,7 @@ const MessageItem = ({ classNames, message }: ThemedClassName<{ message: Message
|
|
|
232
232
|
const wrapper = 'p-1 px-2 rounded-lg bg-hoverSurface overflow-auto';
|
|
233
233
|
return (
|
|
234
234
|
<div className={mx('flex', type === 'request' ? 'ml-[1rem] justify-end' : 'mr-[1rem]', classNames)}>
|
|
235
|
-
{error && <div className={mx(wrapper, 'whitespace-pre
|
|
235
|
+
{error && <div className={mx(wrapper, 'whitespace-pre', errorText)}>{String(error)}</div>}
|
|
236
236
|
|
|
237
237
|
{text !== undefined && (
|
|
238
238
|
<div className={mx(wrapper, type === 'request' && 'bg-primary-400 dark:bg-primary-600')}>
|
|
@@ -5,17 +5,17 @@
|
|
|
5
5
|
import React, { useEffect, useRef } from 'react';
|
|
6
6
|
|
|
7
7
|
import { clientServiceBundle } from '@dxos/client-protocol';
|
|
8
|
+
import { type BundleResult } from '@dxos/functions/bundler';
|
|
9
|
+
import { invariant } from '@dxos/invariant';
|
|
8
10
|
import { log } from '@dxos/log';
|
|
9
11
|
import { useClient } from '@dxos/react-client';
|
|
10
12
|
import { baseSurface, mx } from '@dxos/react-ui-theme';
|
|
11
13
|
import { createProtoRpcPeer } from '@dxos/rpc';
|
|
12
14
|
import { createIFramePort } from '@dxos/rpc-tunnel';
|
|
13
15
|
|
|
14
|
-
import { type BundlerResult } from '../../bundler';
|
|
15
|
-
|
|
16
16
|
export type FrameContainerProps = {
|
|
17
17
|
containerUrl: string;
|
|
18
|
-
result:
|
|
18
|
+
result: BundleResult;
|
|
19
19
|
debug?: boolean;
|
|
20
20
|
};
|
|
21
21
|
|
|
@@ -46,6 +46,7 @@ export const FrameContainer = ({ containerUrl, result, debug = true }: FrameCont
|
|
|
46
46
|
}, [iframeRef]);
|
|
47
47
|
|
|
48
48
|
// Encodes compiled code via URL.
|
|
49
|
+
invariant(result.sourceHash, 'Source hash is required.');
|
|
49
50
|
const sourceHash = Buffer.from(result.sourceHash).toString('hex');
|
|
50
51
|
const src = result.bundle && `${containerUrl}?ts=${sourceHash}#code=${encodeURIComponent(result.bundle)}`;
|
|
51
52
|
|
|
@@ -58,7 +59,7 @@ export const FrameContainer = ({ containerUrl, result, debug = true }: FrameCont
|
|
|
58
59
|
<div
|
|
59
60
|
className={mx(
|
|
60
61
|
baseSurface,
|
|
61
|
-
'flex absolute right-2 bottom-2 w-[
|
|
62
|
+
'flex absolute right-2 bottom-2 w-[30rem] h-[200px] ring rounded',
|
|
62
63
|
'z-20 overflow-x-hidden overflow-y-auto',
|
|
63
64
|
)}
|
|
64
65
|
>
|
|
@@ -14,19 +14,24 @@ import { mx } from '@dxos/react-ui-theme';
|
|
|
14
14
|
|
|
15
15
|
import { DebugPanel } from './DebugPanel';
|
|
16
16
|
import { ScriptToolbar } from './ScriptToolbar';
|
|
17
|
-
import { useDeployState } from './ScriptToolbar/deploy';
|
|
18
|
-
import { useToolbarState } from './ScriptToolbar/useToolbarState';
|
|
19
17
|
import { TypescriptEditor, type TypescriptEditorProps } from './TypescriptEditor';
|
|
18
|
+
import { useDeployState, useToolbarState } from '../hooks';
|
|
20
19
|
import { type ScriptSettingsProps } from '../types';
|
|
21
20
|
|
|
22
21
|
export type ScriptEditorProps = ThemedClassName<{
|
|
23
22
|
script: ScriptType;
|
|
24
|
-
settings
|
|
23
|
+
settings?: ScriptSettingsProps;
|
|
25
24
|
role?: string;
|
|
26
25
|
}> &
|
|
27
26
|
Pick<TypescriptEditorProps, 'env'>;
|
|
28
27
|
|
|
29
|
-
export const ScriptContainer = ({
|
|
28
|
+
export const ScriptContainer = ({
|
|
29
|
+
role,
|
|
30
|
+
classNames,
|
|
31
|
+
script,
|
|
32
|
+
settings = { editorInputMode: 'vscode' },
|
|
33
|
+
env,
|
|
34
|
+
}: ScriptEditorProps) => {
|
|
30
35
|
const identity = useIdentity();
|
|
31
36
|
const space = getSpace(script);
|
|
32
37
|
|
|
@@ -49,7 +54,7 @@ export const ScriptContainer = ({ role, classNames, script, settings, env }: Scr
|
|
|
49
54
|
[script, script.source.target, space, identity],
|
|
50
55
|
);
|
|
51
56
|
|
|
52
|
-
const state = useToolbarState({ view: '
|
|
57
|
+
const state = useToolbarState({ view: 'editor' });
|
|
53
58
|
useDeployState({ state, script });
|
|
54
59
|
|
|
55
60
|
return (
|
|
@@ -10,7 +10,7 @@ import { FunctionType, type ScriptType, getInvocationUrl, getUserFunctionUrlInMe
|
|
|
10
10
|
import { log } from '@dxos/log';
|
|
11
11
|
import { useClient } from '@dxos/react-client';
|
|
12
12
|
import { Filter, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';
|
|
13
|
-
import { Button, Clipboard, Input, Separator,
|
|
13
|
+
import { Button, Clipboard, Input, Separator, useControlledState, useTranslation } from '@dxos/react-ui';
|
|
14
14
|
import { AccessTokenType } from '@dxos/schema';
|
|
15
15
|
|
|
16
16
|
import { SCRIPT_PLUGIN } from '../meta';
|
|
@@ -57,7 +57,7 @@ export const ScriptSettingsPanel = ({ script }: ScriptSettingsPanelProps) => {
|
|
|
57
57
|
return () => clearTimeout(timeout);
|
|
58
58
|
}, [githubToken, gistKey]);
|
|
59
59
|
|
|
60
|
-
const [binding, setBinding] =
|
|
60
|
+
const [binding, setBinding] = useControlledState(fn?.binding ?? '');
|
|
61
61
|
const handleBindingChange = useCallback(
|
|
62
62
|
(event: ChangeEvent<HTMLInputElement>) => {
|
|
63
63
|
setBinding(event.target.value);
|
|
@@ -10,12 +10,14 @@ import { ElevationProvider, type ThemedClassName } from '@dxos/react-ui';
|
|
|
10
10
|
import { stackItemContentToolbarClassNames } from '@dxos/react-ui-editor';
|
|
11
11
|
import { createGapSeparator, MenuProvider, ToolbarMenu, useMenuActions } from '@dxos/react-ui-menu';
|
|
12
12
|
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
import {
|
|
14
|
+
type ScriptToolbarState,
|
|
15
|
+
createDeploy,
|
|
16
|
+
createFormat,
|
|
17
|
+
createTemplateSelect,
|
|
18
|
+
createView,
|
|
19
|
+
useToolbarAction,
|
|
20
|
+
} from '../../hooks';
|
|
19
21
|
|
|
20
22
|
export type ScriptToolbarProps = ThemedClassName<{
|
|
21
23
|
role?: string;
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
useTextEditor,
|
|
28
28
|
type UseTextEditorProps,
|
|
29
29
|
} from '@dxos/react-ui-editor';
|
|
30
|
-
import {
|
|
30
|
+
import { isNonNullable } from '@dxos/util';
|
|
31
31
|
|
|
32
32
|
export type TypescriptEditorProps = {
|
|
33
33
|
id: string;
|
|
@@ -94,7 +94,7 @@ export const TypescriptEditor = ({
|
|
|
94
94
|
]
|
|
95
95
|
: [],
|
|
96
96
|
],
|
|
97
|
-
].filter(
|
|
97
|
+
].filter(isNonNullable),
|
|
98
98
|
selection,
|
|
99
99
|
scrollTo,
|
|
100
100
|
}),
|
package/src/components/index.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
import { lazy } from 'react';
|
|
6
6
|
|
|
7
|
+
export * from './DebugPanel';
|
|
7
8
|
export * from './ScriptSettings';
|
|
8
9
|
export * from './ScriptSettingsPanel';
|
|
9
10
|
|
|
10
|
-
export const AutomationPanel = lazy(() => import('./AutomationPanel'));
|
|
11
11
|
export const ScriptContainer = lazy(() => import('./ScriptContainer'));
|
package/src/events.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { defineEvent } from '@dxos/app-framework';
|
|
6
|
+
|
|
7
|
+
import { SCRIPT_PLUGIN } from './meta';
|
|
8
|
+
|
|
9
|
+
export namespace ScriptEvents {
|
|
10
|
+
export const SetupCompiler = defineEvent(`${SCRIPT_PLUGIN}/event/setup-compiler`);
|
|
11
|
+
}
|
|
@@ -6,13 +6,14 @@ import { useCallback, useEffect, useMemo } from 'react';
|
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
FunctionType,
|
|
9
|
+
type ScriptType,
|
|
9
10
|
getInvocationUrl,
|
|
10
11
|
getUserFunctionUrlInMetadata,
|
|
11
12
|
incrementSemverPatch,
|
|
12
|
-
type ScriptType,
|
|
13
13
|
setUserFunctionUrlInMetadata,
|
|
14
14
|
uploadWorkerFunction,
|
|
15
15
|
} from '@dxos/functions';
|
|
16
|
+
import { Bundler } from '@dxos/functions/bundler';
|
|
16
17
|
import { log } from '@dxos/log';
|
|
17
18
|
import { useClient } from '@dxos/react-client';
|
|
18
19
|
import { Filter, create, getMeta, getSpace, makeRef, useQuery } from '@dxos/react-client/echo';
|
|
@@ -20,8 +21,7 @@ import { useTranslation } from '@dxos/react-ui';
|
|
|
20
21
|
import { createMenuAction } from '@dxos/react-ui-menu';
|
|
21
22
|
|
|
22
23
|
import { type ViewState } from './view';
|
|
23
|
-
import {
|
|
24
|
-
import { SCRIPT_PLUGIN } from '../../meta';
|
|
24
|
+
import { SCRIPT_PLUGIN } from '../meta';
|
|
25
25
|
|
|
26
26
|
export type DeployActionProperties = { type: 'deploy' } | { type: 'copy' };
|
|
27
27
|
|
|
@@ -105,7 +105,7 @@ export const useDeployHandler = ({ state, script }: { state: Partial<DeployState
|
|
|
105
105
|
const existingFunctionId = existingFunctionUrl?.split('/').at(-1);
|
|
106
106
|
|
|
107
107
|
const bundler = new Bundler({ platform: 'browser', sandboxedModules: [], remoteModules: {} });
|
|
108
|
-
const buildResult = await bundler.bundle(script.source.target!.content);
|
|
108
|
+
const buildResult = await bundler.bundle({ source: script.source.target!.content });
|
|
109
109
|
if (buildResult.error || !buildResult.bundle) {
|
|
110
110
|
throw buildResult.error;
|
|
111
111
|
}
|
|
@@ -130,13 +130,24 @@ export const useDeployHandler = ({ state, script }: { state: Partial<DeployState
|
|
|
130
130
|
fn ?? space.db.add(create(FunctionType, { name: functionId, version, source: makeRef(script) }));
|
|
131
131
|
|
|
132
132
|
script.changed = false;
|
|
133
|
-
|
|
133
|
+
if (script.description !== undefined && script.description.trim() !== '') {
|
|
134
|
+
deployedFunction.description = script.description;
|
|
135
|
+
} else if (meta.description) {
|
|
136
|
+
deployedFunction.description = meta.description;
|
|
137
|
+
} else {
|
|
138
|
+
log.verbose('no description in function metadata', { functionId });
|
|
139
|
+
}
|
|
134
140
|
|
|
135
141
|
if (meta.inputSchema) {
|
|
136
142
|
deployedFunction.inputSchema = meta.inputSchema;
|
|
137
143
|
} else {
|
|
138
144
|
log.verbose('no input schema in function metadata', { functionId });
|
|
139
145
|
}
|
|
146
|
+
if (meta.outputSchema) {
|
|
147
|
+
deployedFunction.outputSchema = meta.outputSchema;
|
|
148
|
+
} else {
|
|
149
|
+
log.verbose('no output schema in function metadata', { functionId });
|
|
150
|
+
}
|
|
140
151
|
|
|
141
152
|
setUserFunctionUrlInMetadata(getMeta(deployedFunction), `/${space.id}/${functionId}`);
|
|
142
153
|
|
|
@@ -11,7 +11,7 @@ import { type ScriptType } from '@dxos/functions';
|
|
|
11
11
|
import { log } from '@dxos/log';
|
|
12
12
|
import { createMenuAction } from '@dxos/react-ui-menu';
|
|
13
13
|
|
|
14
|
-
import { SCRIPT_PLUGIN } from '
|
|
14
|
+
import { SCRIPT_PLUGIN } from '../meta';
|
|
15
15
|
|
|
16
16
|
export type FormatActionProperties = { type: 'format' };
|
|
17
17
|
|
|
@@ -8,8 +8,8 @@ import { FUNCTIONS_PRESET_META_KEY, type ScriptType } from '@dxos/functions';
|
|
|
8
8
|
import { getMeta } from '@dxos/live-object';
|
|
9
9
|
import { createMenuItemGroup, createMenuAction } from '@dxos/react-ui-menu';
|
|
10
10
|
|
|
11
|
-
import { SCRIPT_PLUGIN } from '
|
|
12
|
-
import { templates } from '
|
|
11
|
+
import { SCRIPT_PLUGIN } from '../meta';
|
|
12
|
+
import { templates } from '../templates';
|
|
13
13
|
|
|
14
14
|
export type TemplateActionProperties = { type: 'template'; value: string };
|
|
15
15
|
|
|
@@ -10,7 +10,7 @@ import { type MenuAction, type MenuActionHandler } from '@dxos/react-ui-menu';
|
|
|
10
10
|
|
|
11
11
|
import { type DeployActionProperties, useDeployHandler, useCopyHandler } from './deploy';
|
|
12
12
|
import { type FormatActionProperties, useFormatHandler } from './format';
|
|
13
|
-
import { type TemplateActionProperties, useTemplateSelectHandler } from './
|
|
13
|
+
import { type TemplateActionProperties, useTemplateSelectHandler } from './template';
|
|
14
14
|
import { type ScriptToolbarState } from './useToolbarState';
|
|
15
15
|
import { type ViewActionProperties } from './view';
|
|
16
16
|
|
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
import { createMenuAction, createMenuItemGroup } from '@dxos/react-ui-menu';
|
|
6
6
|
|
|
7
|
-
import { SCRIPT_PLUGIN } from '
|
|
7
|
+
import { SCRIPT_PLUGIN } from '../meta';
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
// TODO(wittjosiah): Replace debug with logs.
|
|
10
|
+
export type ViewType = 'editor' | 'split' | 'debug'; // 'logs';
|
|
10
11
|
|
|
11
12
|
export type ViewState = { view: ViewType };
|
|
12
13
|
|
|
@@ -16,6 +17,8 @@ const views: Record<ViewType, string> = {
|
|
|
16
17
|
editor: 'ph--code--regular',
|
|
17
18
|
split: 'ph--square-split-vertical--regular',
|
|
18
19
|
debug: 'ph--bug--regular',
|
|
20
|
+
// TODO(wittjosiah): Replace debug with logs.
|
|
21
|
+
// logs: 'ph--clock-counter-clockwise--regular',
|
|
19
22
|
};
|
|
20
23
|
|
|
21
24
|
const createViewGroupItem = (state: Partial<ViewState>) => {
|
package/src/index.ts
CHANGED
package/src/meta.ts
CHANGED
|
@@ -9,8 +9,10 @@ export const SCRIPT_PLUGIN = 'dxos.org/plugin/script';
|
|
|
9
9
|
export const meta = {
|
|
10
10
|
id: SCRIPT_PLUGIN,
|
|
11
11
|
name: 'Scripts',
|
|
12
|
-
description:
|
|
12
|
+
description:
|
|
13
|
+
'Scripts in Composer allow you to deploy custom functions that run on the edge. These functions can be referenced by your AI agent and called inside of cells in any Sheet. Use scripts to interact with API’s or external data inside of Composer.',
|
|
13
14
|
icon: 'ph--code--regular',
|
|
14
15
|
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/experimental/plugin-explorer',
|
|
15
16
|
tags: ['experimental'],
|
|
17
|
+
screenshots: ['https://dxos.network/plugin-details-scripts-dark.png'],
|
|
16
18
|
} satisfies PluginMeta;
|
package/src/templates/chat.ts
CHANGED
|
@@ -57,11 +57,11 @@ export default async ({
|
|
|
57
57
|
let prompt = promptObject.template;
|
|
58
58
|
for (const input of promptObject.inputs) {
|
|
59
59
|
let value: string | null = null;
|
|
60
|
-
if (input.type ===
|
|
60
|
+
if (input.type === TemplateInputType.VALUE) {
|
|
61
61
|
value = String(input.value);
|
|
62
|
-
} else if (input.type ===
|
|
62
|
+
} else if (input.type === TemplateInputType.RETRIEVER) {
|
|
63
63
|
value = await getContext({ space });
|
|
64
|
-
} else if (input.type ===
|
|
64
|
+
} else if (input.type === TemplateInputType.PASS_THROUGH) {
|
|
65
65
|
value = message.text;
|
|
66
66
|
}
|
|
67
67
|
if (value) {
|
|
@@ -90,7 +90,7 @@ const getContext = async ({ space }: any) => {
|
|
|
90
90
|
return context;
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
-
enum
|
|
93
|
+
enum TemplateInputType {
|
|
94
94
|
VALUE = 0,
|
|
95
95
|
PASS_THROUGH = 1,
|
|
96
96
|
RETRIEVER = 2,
|