@dxos/plugin-script 0.7.5-labs.071a3e2 → 0.7.5-labs.8a82073
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-LGW52UAJ.mjs → ScriptContainer-QI4NQT7V.mjs} +29 -4
- package/dist/lib/browser/ScriptContainer-QI4NQT7V.mjs.map +7 -0
- package/dist/lib/browser/artifact-3UZZBCZ2.mjs +243 -0
- package/dist/lib/browser/artifact-3UZZBCZ2.mjs.map +7 -0
- package/dist/lib/browser/{chunk-2UXYECEH.mjs → chunk-F22QPQ6G.mjs} +4 -4
- package/dist/lib/browser/{chunk-2UXYECEH.mjs.map → chunk-F22QPQ6G.mjs.map} +2 -2
- package/dist/lib/browser/index.mjs +8 -2
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-XACNR5NR.mjs → react-surface-YR4YO746.mjs} +2 -2
- package/dist/lib/node/{ScriptContainer-UI2MDBYG.cjs → ScriptContainer-FSKWJR6Z.cjs} +32 -7
- package/dist/lib/node/ScriptContainer-FSKWJR6Z.cjs.map +7 -0
- package/dist/lib/node/artifact-A2QXHFGS.cjs +262 -0
- package/dist/lib/node/artifact-A2QXHFGS.cjs.map +7 -0
- package/dist/lib/node/{chunk-73345ZL6.cjs → chunk-JSANQCTA.cjs} +6 -6
- package/dist/lib/node/{chunk-73345ZL6.cjs.map → chunk-JSANQCTA.cjs.map} +2 -2
- package/dist/lib/node/index.cjs +12 -6
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/{react-surface-Y3RD5FW7.cjs → react-surface-MFTICFI5.cjs} +9 -9
- package/dist/lib/node-esm/{ScriptContainer-F7SNP53Z.mjs → ScriptContainer-MNETNTNQ.mjs} +29 -4
- package/dist/lib/node-esm/ScriptContainer-MNETNTNQ.mjs.map +7 -0
- package/dist/lib/node-esm/artifact-RFZQ2AJJ.mjs +245 -0
- package/dist/lib/node-esm/artifact-RFZQ2AJJ.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-PRGBYF4B.mjs → chunk-FGO5DVO2.mjs} +4 -4
- package/dist/lib/node-esm/{chunk-PRGBYF4B.mjs.map → chunk-FGO5DVO2.mjs.map} +2 -2
- package/dist/lib/node-esm/index.mjs +8 -2
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{react-surface-PKUVZH4S.mjs → react-surface-NAK6LMCY.mjs} +2 -2
- package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/artifact.d.ts +11 -0
- package/dist/types/src/capabilities/artifact.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/hooks/deploy.d.ts.map +1 -1
- package/package.json +44 -42
- package/src/ScriptPlugin.tsx +6 -1
- package/src/capabilities/artifact.ts +219 -0
- package/src/capabilities/index.ts +1 -0
- package/src/components/ScriptSettingsPanel.tsx +2 -2
- package/src/hooks/deploy.ts +12 -1
- package/dist/lib/browser/ScriptContainer-LGW52UAJ.mjs.map +0 -7
- package/dist/lib/node/ScriptContainer-UI2MDBYG.cjs.map +0 -7
- package/dist/lib/node-esm/ScriptContainer-F7SNP53Z.mjs.map +0 -7
- /package/dist/lib/browser/{react-surface-XACNR5NR.mjs.map → react-surface-YR4YO746.mjs.map} +0 -0
- /package/dist/lib/node/{react-surface-Y3RD5FW7.cjs.map → react-surface-MFTICFI5.cjs.map} +0 -0
- /package/dist/lib/node-esm/{react-surface-PKUVZH4S.mjs.map → react-surface-NAK6LMCY.mjs.map} +0 -0
|
@@ -181,7 +181,20 @@ var useDeployHandler = ({ state, script }) => {
|
|
|
181
181
|
source: makeRef(script)
|
|
182
182
|
}));
|
|
183
183
|
script.changed = false;
|
|
184
|
-
|
|
184
|
+
if (script.description !== void 0 && script.description.trim() !== "") {
|
|
185
|
+
deployedFunction.description = script.description;
|
|
186
|
+
} else if (meta.description) {
|
|
187
|
+
deployedFunction.description = meta.description;
|
|
188
|
+
} else {
|
|
189
|
+
log.verbose("no description in function metadata", {
|
|
190
|
+
functionId
|
|
191
|
+
}, {
|
|
192
|
+
F: __dxlog_file,
|
|
193
|
+
L: 138,
|
|
194
|
+
S: void 0,
|
|
195
|
+
C: (f, a) => f(...a)
|
|
196
|
+
});
|
|
197
|
+
}
|
|
185
198
|
if (meta.inputSchema) {
|
|
186
199
|
deployedFunction.inputSchema = meta.inputSchema;
|
|
187
200
|
} else {
|
|
@@ -189,7 +202,19 @@ var useDeployHandler = ({ state, script }) => {
|
|
|
189
202
|
functionId
|
|
190
203
|
}, {
|
|
191
204
|
F: __dxlog_file,
|
|
192
|
-
L:
|
|
205
|
+
L: 144,
|
|
206
|
+
S: void 0,
|
|
207
|
+
C: (f, a) => f(...a)
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
if (meta.outputSchema) {
|
|
211
|
+
deployedFunction.outputSchema = meta.outputSchema;
|
|
212
|
+
} else {
|
|
213
|
+
log.verbose("no output schema in function metadata", {
|
|
214
|
+
functionId
|
|
215
|
+
}, {
|
|
216
|
+
F: __dxlog_file,
|
|
217
|
+
L: 149,
|
|
193
218
|
S: void 0,
|
|
194
219
|
C: (f, a) => f(...a)
|
|
195
220
|
});
|
|
@@ -199,7 +224,7 @@ var useDeployHandler = ({ state, script }) => {
|
|
|
199
224
|
} catch (err) {
|
|
200
225
|
log.catch(err, void 0, {
|
|
201
226
|
F: __dxlog_file,
|
|
202
|
-
L:
|
|
227
|
+
L: 156,
|
|
203
228
|
S: void 0,
|
|
204
229
|
C: (f, a) => f(...a)
|
|
205
230
|
});
|
|
@@ -685,4 +710,4 @@ export {
|
|
|
685
710
|
ScriptContainer,
|
|
686
711
|
ScriptContainer_default as default
|
|
687
712
|
};
|
|
688
|
-
//# sourceMappingURL=ScriptContainer-
|
|
713
|
+
//# sourceMappingURL=ScriptContainer-QI4NQT7V.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/ScriptContainer.tsx", "../../../src/components/ScriptToolbar/ScriptToolbar.tsx", "../../../src/hooks/deploy.ts", "../../../src/hooks/format.ts", "../../../src/hooks/template.ts", "../../../src/hooks/view.ts", "../../../src/hooks/useToolbarAction.ts", "../../../src/hooks/useToolbarState.ts", "../../../src/components/TypescriptEditor/TypescriptEditor.tsx"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React, { useMemo } from 'react';\n\nimport { type ScriptType } from '@dxos/functions';\nimport { createDocAccessor, getSpace } from '@dxos/react-client/echo';\nimport { useIdentity } from '@dxos/react-client/halo';\nimport { type ThemedClassName } from '@dxos/react-ui';\nimport { createDataExtensions, listener, stackItemContentEditorClassNames } from '@dxos/react-ui-editor';\nimport { StackItem } from '@dxos/react-ui-stack';\nimport { mx } from '@dxos/react-ui-theme';\n\nimport { DebugPanel } from './DebugPanel';\nimport { ScriptToolbar } from './ScriptToolbar';\nimport { TypescriptEditor, type TypescriptEditorProps } from './TypescriptEditor';\nimport { useDeployState, useToolbarState } from '../hooks';\nimport { type ScriptSettingsProps } from '../types';\n\nexport type ScriptEditorProps = ThemedClassName<{\n script: ScriptType;\n settings?: ScriptSettingsProps;\n role?: string;\n}> &\n Pick<TypescriptEditorProps, 'env'>;\n\nexport const ScriptContainer = ({\n role,\n classNames,\n script,\n settings = { editorInputMode: 'vscode' },\n env,\n}: ScriptEditorProps) => {\n const identity = useIdentity();\n const space = getSpace(script);\n\n const extensions = useMemo(\n () => [\n listener({\n onChange: (text) => {\n if (script.source.target && script.source.target.content !== text) {\n script.changed = true;\n }\n },\n }),\n createDataExtensions({\n id: script.id,\n text: script.source.target && createDocAccessor(script.source.target, ['content']),\n space,\n identity,\n }),\n ],\n [script, script.source.target, space, identity],\n );\n\n const state = useToolbarState({ view: 'editor' });\n useDeployState({ state, script });\n\n return (\n <StackItem.Content toolbar>\n <ScriptToolbar state={state} role={role} script={script} />\n <div role='none' className={mx('flex flex-col w-full overflow-hidden divide-y divide-separator', classNames)}>\n {state.view !== 'debug' && (\n <TypescriptEditor\n id={script.id}\n env={env}\n initialValue={script.source?.target?.content}\n extensions={extensions}\n className={stackItemContentEditorClassNames(role)}\n inputMode={settings.editorInputMode}\n toolbar\n />\n )}\n\n {state.view !== 'editor' && <DebugPanel functionUrl={state.functionUrl} />}\n </div>\n </StackItem.Content>\n );\n};\n\nexport default ScriptContainer;\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { useCallback } from 'react';\n\nimport { type ScriptType } from '@dxos/functions';\nimport { fullyQualifiedId } from '@dxos/react-client/echo';\nimport { ElevationProvider, type ThemedClassName } from '@dxos/react-ui';\nimport { stackItemContentToolbarClassNames } from '@dxos/react-ui-editor';\nimport { createGapSeparator, MenuProvider, ToolbarMenu, useMenuActions } from '@dxos/react-ui-menu';\n\nimport {\n type ScriptToolbarState,\n createDeploy,\n createFormat,\n createTemplateSelect,\n createView,\n useToolbarAction,\n} from '../../hooks';\n\nexport type ScriptToolbarProps = ThemedClassName<{\n role?: string;\n script: ScriptType;\n state: ScriptToolbarState;\n}>;\n\nconst createToolbar = (state: ScriptToolbarState) => {\n const templateSelect = createTemplateSelect();\n const format = createFormat();\n const gap = createGapSeparator();\n const deploy = createDeploy(state);\n const view = createView(state);\n return {\n nodes: [...templateSelect.nodes, ...format.nodes, ...gap.nodes, ...deploy.nodes, ...view.nodes],\n edges: [...templateSelect.edges, ...format.edges, ...gap.edges, ...deploy.edges, ...view.edges],\n };\n};\n\nexport const ScriptToolbar = ({ script, role, state, classNames }: ScriptToolbarProps) => {\n const handleAction = useToolbarAction({ state, script });\n const toolbarCreator = useCallback(() => createToolbar(state), [state]);\n const menu = useMenuActions(toolbarCreator);\n return (\n <div role='none' className={stackItemContentToolbarClassNames(role)}>\n <ElevationProvider elevation={role === 'section' ? 'positioned' : 'base'}>\n <MenuProvider {...menu} onAction={handleAction} attendableId={fullyQualifiedId(script)}>\n <ToolbarMenu classNames={classNames} />\n </MenuProvider>\n </ElevationProvider>\n </div>\n );\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useCallback, useEffect, useMemo } from 'react';\n\nimport {\n FunctionType,\n getInvocationUrl,\n getUserFunctionUrlInMetadata,\n incrementSemverPatch,\n type ScriptType,\n setUserFunctionUrlInMetadata,\n uploadWorkerFunction,\n} from '@dxos/functions';\nimport { log } from '@dxos/log';\nimport { useClient } from '@dxos/react-client';\nimport { Filter, create, getMeta, getSpace, makeRef, useQuery } from '@dxos/react-client/echo';\nimport { useTranslation } from '@dxos/react-ui';\nimport { createMenuAction } from '@dxos/react-ui-menu';\n\nimport { type ViewState } from './view';\nimport { Bundler } from '../bundler';\nimport { SCRIPT_PLUGIN } from '../meta';\n\nexport type DeployActionProperties = { type: 'deploy' } | { type: 'copy' };\n\nexport type DeployState = ViewState & {\n deploying: boolean;\n deployed: boolean;\n functionUrl: string;\n error: string;\n};\n\nexport const createDeploy = (state: Partial<DeployState>) => {\n const errorItem = createMenuAction('error', {\n label: state.error ?? ['no error label', { ns: SCRIPT_PLUGIN }],\n icon: 'ph--warning-circle--regular',\n hidden: !state.error,\n });\n\n const deployAction = createMenuAction<DeployActionProperties>('deploy', {\n type: 'deploy',\n label: [state.deploying ? 'pending label' : 'deploy label', { ns: SCRIPT_PLUGIN }],\n icon: state.deploying ? 'ph--spinner-gap--regular' : 'ph--cloud-arrow-up--regular',\n disabled: state.deploying,\n classNames: state.deploying ? '[&_svg]:animate-spin' : '',\n });\n\n const copyAction = createMenuAction<DeployActionProperties>('copy', {\n type: 'copy',\n label: ['copy link label', { ns: SCRIPT_PLUGIN }],\n icon: 'ph--link--regular',\n disabled: !state.functionUrl,\n });\n\n return {\n nodes: [errorItem, deployAction, copyAction],\n edges: [\n { source: 'root', target: 'error' },\n { source: 'root', target: 'deploy' },\n { source: 'root', target: 'copy' },\n ],\n };\n};\n\nconst useDeployDeps = ({ state, script }: { state: Partial<DeployState>; script: ScriptType }) => {\n const space = getSpace(script);\n const [fn] = useQuery(space, Filter.schema(FunctionType, { source: script }));\n const client = useClient();\n const existingFunctionUrl = useMemo(() => fn && getUserFunctionUrlInMetadata(getMeta(fn)), [fn]);\n return { space, fn, client, existingFunctionUrl };\n};\n\nexport const useDeployState = ({ state, script }: { state: Partial<DeployState>; script: ScriptType }) => {\n const { space, client, existingFunctionUrl } = useDeployDeps({ state, script });\n useEffect(() => {\n if (!existingFunctionUrl) {\n return;\n }\n\n state.functionUrl = getInvocationUrl(existingFunctionUrl, client.config.values.runtime?.services?.edge?.url ?? '', {\n spaceId: space?.id,\n });\n }, [existingFunctionUrl, space]);\n\n useEffect(() => {\n state.deployed = Boolean(existingFunctionUrl) && !script.changed;\n }, [script.changed, existingFunctionUrl]);\n};\n\nexport const useDeployHandler = ({ state, script }: { state: Partial<DeployState>; script: ScriptType }) => {\n const { space, fn, client, existingFunctionUrl } = useDeployDeps({ state, script });\n const { t } = useTranslation(SCRIPT_PLUGIN);\n\n return useCallback(async () => {\n if (!script.source || !space) {\n return;\n }\n\n state.error = undefined;\n state.deploying = true;\n\n try {\n const existingFunctionId = existingFunctionUrl?.split('/').at(-1);\n\n const bundler = new Bundler({ platform: 'browser', sandboxedModules: [], remoteModules: {} });\n const buildResult = await bundler.bundle(script.source.target!.content);\n if (buildResult.error || !buildResult.bundle) {\n throw buildResult.error;\n }\n\n const { functionId, version, meta } = await uploadWorkerFunction({\n client,\n spaceId: space.id,\n version: fn ? incrementSemverPatch(fn.version) : '0.0.1',\n functionId: existingFunctionId,\n source: buildResult.bundle,\n });\n if (functionId === undefined || version === undefined) {\n throw new Error(`Upload didn't return expected data: functionId=${functionId}, version=${version}`);\n }\n\n log.info('function uploaded', { functionId, version });\n if (fn) {\n fn.version = version;\n }\n\n const deployedFunction =\n fn ?? space.db.add(create(FunctionType, { name: functionId, version, source: makeRef(script) }));\n\n script.changed = false;\n if (script.description !== undefined && script.description.trim() !== '') {\n deployedFunction.description = script.description;\n } else if (meta.description) {\n deployedFunction.description = meta.description;\n } else {\n log.verbose('no description in function metadata', { functionId });\n }\n\n if (meta.inputSchema) {\n deployedFunction.inputSchema = meta.inputSchema;\n } else {\n log.verbose('no input schema in function metadata', { functionId });\n }\n if (meta.outputSchema) {\n deployedFunction.outputSchema = meta.outputSchema;\n } else {\n log.verbose('no output schema in function metadata', { functionId });\n }\n\n setUserFunctionUrlInMetadata(getMeta(deployedFunction), `/${space.id}/${functionId}`);\n\n state.view = 'split';\n } catch (err: any) {\n log.catch(err);\n state.error = t('upload failed label');\n }\n state.deploying = false;\n }, [fn, client, t, existingFunctionUrl, script, script.name, script.source, space?.id ?? null]);\n};\n\nexport const useCopyHandler = ({ state }: { state: Partial<DeployState> }) =>\n useCallback(async () => {\n if (!state.functionUrl) {\n return;\n }\n await navigator.clipboard.writeText(state.functionUrl);\n }, [state.functionUrl]);\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { format } from 'prettier';\nimport prettierPluginEstree from 'prettier/plugins/estree';\nimport prettierPluginTypescript from 'prettier/plugins/typescript';\nimport { useCallback } from 'react';\n\nimport { type ScriptType } from '@dxos/functions';\nimport { log } from '@dxos/log';\nimport { createMenuAction } from '@dxos/react-ui-menu';\n\nimport { SCRIPT_PLUGIN } from '../meta';\n\nexport type FormatActionProperties = { type: 'format' };\n\nexport const createFormat = () => {\n const formatAction = createMenuAction('format', {\n label: ['format label', { ns: SCRIPT_PLUGIN }],\n icon: 'ph--magic-wand--regular',\n });\n\n return {\n nodes: [formatAction],\n edges: [{ source: 'root', target: 'format' }],\n };\n};\n\nexport const useFormatHandler = ({ script }: { script: ScriptType }) =>\n useCallback(async () => {\n if (!script.source) {\n return;\n }\n\n try {\n script.source.target!.content = await format(script.source.target!.content, {\n parser: 'typescript',\n plugins: [prettierPluginEstree, prettierPluginTypescript],\n semi: true,\n singleQuote: true,\n });\n } catch (err: any) {\n // TODO(wittjosiah): Show error in UI.\n log.catch(err);\n }\n }, [script.source]);\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useCallback } from 'react';\n\nimport { FUNCTIONS_PRESET_META_KEY, type ScriptType } from '@dxos/functions';\nimport { getMeta } from '@dxos/live-object';\nimport { createMenuItemGroup, createMenuAction } from '@dxos/react-ui-menu';\n\nimport { SCRIPT_PLUGIN } from '../meta';\nimport { templates } from '../templates';\n\nexport type TemplateActionProperties = { type: 'template'; value: string };\n\nconst createTemplateSelectGroup = () => {\n return createMenuItemGroup('template-select', {\n label: ['template select group label', { ns: SCRIPT_PLUGIN }],\n variant: 'dropdownMenu',\n });\n};\n\nconst createTemplateSelectActions = () => {\n return templates.map((template) => {\n return createMenuAction<TemplateActionProperties>(`template--${template.id}`, {\n label: template.name,\n value: template.id,\n type: 'template',\n });\n });\n};\n\nexport const createTemplateSelect = () => {\n const templateSelectGroup = createTemplateSelectGroup();\n const templateSelectActions = createTemplateSelectActions();\n return {\n nodes: [templateSelectGroup, ...templateSelectActions],\n edges: [\n { source: 'root', target: 'template-select' },\n ...templateSelectActions.map((action) => ({ source: 'template-select', target: action.id })),\n ],\n };\n};\n\nexport const useTemplateSelectHandler = ({ script }: { script: ScriptType }) => {\n return useCallback(\n (templateId: string) => {\n const template = templates.find((template) => template.id === templateId);\n if (template) {\n script.name = template.name;\n script.source!.target!.content = template.source;\n const metaKeys = getMeta(script).keys;\n const oldPresetIndex = metaKeys.findIndex((key) => key.source === FUNCTIONS_PRESET_META_KEY);\n if (oldPresetIndex >= 0) {\n metaKeys.splice(oldPresetIndex, 1);\n }\n if (template.presetId) {\n metaKeys.push({ source: FUNCTIONS_PRESET_META_KEY, id: template.presetId });\n }\n }\n },\n [script],\n );\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { createMenuAction, createMenuItemGroup } from '@dxos/react-ui-menu';\n\nimport { SCRIPT_PLUGIN } from '../meta';\n\nexport type ViewType = 'editor' | 'split' | 'debug';\n\nexport type ViewState = { view: ViewType };\n\nexport type ViewActionProperties = { type: 'view'; value: ViewType };\n\nconst views: Record<ViewType, string> = {\n editor: 'ph--code--regular',\n split: 'ph--square-split-vertical--regular',\n debug: 'ph--bug--regular',\n};\n\nconst createViewGroupItem = (state: Partial<ViewState>) => {\n return createMenuItemGroup('view', {\n label: ['view group label', { ns: SCRIPT_PLUGIN }],\n variant: 'dropdownMenu',\n applyActive: true,\n value: state.view,\n });\n};\n\nconst createViewActions = (state: Partial<ViewState>) => {\n return Object.entries(views).map(([viewType, icon]) => {\n return createMenuAction<ViewActionProperties>(`view--${viewType}`, {\n type: 'view',\n value: viewType as ViewType,\n label: [`view ${viewType} label`, { ns: SCRIPT_PLUGIN }],\n icon,\n checked: state.view === viewType,\n });\n });\n};\n\nexport const createView = (state: Partial<ViewState>) => {\n const viewGroupItem = createViewGroupItem(state);\n const viewActions = createViewActions(state);\n return {\n nodes: [viewGroupItem, ...viewActions],\n edges: [\n { source: 'root', target: 'view' },\n ...viewActions.map((action) => ({ source: 'view', target: action.id })),\n ],\n };\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useCallback } from 'react';\n\nimport { type ScriptType } from '@dxos/functions';\nimport { log } from '@dxos/log';\nimport { type MenuAction, type MenuActionHandler } from '@dxos/react-ui-menu';\n\nimport { type DeployActionProperties, useDeployHandler, useCopyHandler } from './deploy';\nimport { type FormatActionProperties, useFormatHandler } from './format';\nimport { type TemplateActionProperties, useTemplateSelectHandler } from './template';\nimport { type ScriptToolbarState } from './useToolbarState';\nimport { type ViewActionProperties } from './view';\n\nexport type ScriptToolbarActionProperties =\n | TemplateActionProperties\n | ViewActionProperties\n | FormatActionProperties\n | DeployActionProperties;\n\nexport type ScriptToolbarAction = MenuAction<ScriptToolbarActionProperties>;\n\nexport const useToolbarAction = (props: { state: ScriptToolbarState; script: ScriptType }) => {\n const handleTemplateSelect = useTemplateSelectHandler(props);\n const handleFormat = useFormatHandler(props);\n const handleDeploy = useDeployHandler(props);\n const handleCopy = useCopyHandler(props);\n return useCallback(\n ((action: ScriptToolbarAction) => {\n switch (action.properties.type) {\n case 'template':\n handleTemplateSelect(action.properties.value);\n break;\n case 'view':\n props.state.view = action.properties.value;\n break;\n case 'format':\n void handleFormat();\n break;\n case 'deploy':\n void handleDeploy();\n break;\n case 'copy':\n void handleCopy();\n break;\n default:\n log.error('Unknown action type', action);\n }\n }) as MenuActionHandler,\n [handleTemplateSelect, handleFormat, handleDeploy, handleCopy],\n );\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useMemo } from 'react';\n\nimport { create } from '@dxos/live-object';\n\nimport { type DeployState } from './deploy';\nimport { type ViewState } from './view';\n\nexport type ScriptToolbarState = Partial<DeployState & ViewState>;\n\nexport const useToolbarState = (initialState: ScriptToolbarState = {}) => {\n return useMemo(() => create<ScriptToolbarState>(initialState), []);\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { javascript } from '@codemirror/lang-javascript';\nimport { defaultHighlightStyle } from '@codemirror/language';\nimport { Prec } from '@codemirror/state';\nimport { oneDarkHighlightStyle } from '@codemirror/theme-one-dark';\nimport { keymap } from '@codemirror/view';\nimport { tags } from '@lezer/highlight';\nimport { type VirtualTypeScriptEnvironment } from '@typescript/vfs';\nimport { continueKeymap } from '@valtown/codemirror-continue';\nimport { tsSync, tsFacet, tsLinter, tsAutocomplete, tsHover, type HoverInfo } from '@valtown/codemirror-ts';\nimport React from 'react';\n\nimport { type ThemeMode, useThemeContext } from '@dxos/react-ui';\nimport {\n autocomplete,\n createBasicExtensions,\n createThemeExtensions,\n editorFullWidth,\n type EditorInputMode,\n editorMonospace,\n EditorView,\n folding,\n InputModeExtensions,\n useTextEditor,\n type UseTextEditorProps,\n} from '@dxos/react-ui-editor';\nimport { nonNullable } from '@dxos/util';\n\nexport type TypescriptEditorProps = {\n id: string;\n inputMode?: EditorInputMode;\n env?: VirtualTypeScriptEnvironment;\n toolbar?: boolean;\n} & Pick<UseTextEditorProps, 'className' | 'initialValue' | 'extensions' | 'scrollTo' | 'selection'>;\n\nexport const TypescriptEditor = ({\n id,\n env,\n className,\n initialValue,\n extensions,\n scrollTo,\n selection,\n toolbar,\n inputMode = 'vscode',\n}: TypescriptEditorProps) => {\n const { themeMode } = useThemeContext();\n const { parentRef, focusAttributes } = useTextEditor(\n () => ({\n id,\n initialValue,\n extensions: [\n extensions,\n createBasicExtensions({\n highlightActiveLine: true,\n indentWithTab: true,\n lineNumbers: true,\n lineWrapping: false,\n scrollPastEnd: true,\n }),\n createThemeExtensions({\n themeMode,\n syntaxHighlighting: true,\n slots: {\n content: { className: editorFullWidth },\n },\n }),\n // NOTE: Not using default editor gutter because folding for code works best right beside text.\n EditorView.theme({\n '.cm-gutters': {\n // Match margin from content.\n marginTop: '16px',\n },\n }),\n InputModeExtensions[inputMode],\n folding(),\n // Continues block comments when you hit Enter.\n Prec.high(keymap.of(continueKeymap)),\n // TODO(burdon): Factor out.\n [\n editorMonospace,\n javascript({ typescript: true }),\n // https://github.com/val-town/codemirror-ts\n autocomplete({ override: env ? [tsAutocomplete()] : [] }),\n env\n ? [\n tsFacet.of({ env, path: `/src/${id}.ts` }),\n tsSync(),\n tsLinter(),\n tsHover({ renderTooltip: createTooltipRenderer(themeMode) }),\n ]\n : [],\n ],\n ].filter(nonNullable),\n selection,\n scrollTo,\n }),\n [id, extensions, themeMode, inputMode, selection, scrollTo],\n );\n\n return (\n <div ref={parentRef} data-toolbar={toolbar ? 'enabled' : 'disabled'} className={className} {...focusAttributes} />\n );\n};\n\nconst createTooltipRenderer = (themeMode: ThemeMode) => {\n const theme = themeMode === 'dark' ? oneDarkHighlightStyle : defaultHighlightStyle;\n\n const classFromKind = (_kind: string) => {\n // E.g., localName, methodName, parameterName, etc.\n const kind = _kind.endsWith('Name') ? 'name' : _kind;\n const validTag = kind in tags;\n if (!validTag) {\n return '';\n }\n\n const tag = tags[kind as keyof typeof tags];\n if (typeof tag === 'function') {\n return '';\n }\n\n return theme.style([tag]) ?? '';\n };\n\n return (info: HoverInfo) => {\n const div = document.createElement('div');\n div.className = 'p-1 rounded border border-separator bg-baseSurface xs:max-w-80 max-w-lg';\n\n if (info.quickInfo?.displayParts) {\n for (const part of info.quickInfo.displayParts) {\n const span = div.appendChild(document.createElement('span'));\n span.className = classFromKind(part.kind);\n span.innerText = part.text;\n }\n }\n\n return { dom: div };\n };\n};\n\nexport default TypescriptEditor;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AAIA,OAAOA,UAASC,WAAAA,gBAAe;AAG/B,SAASC,mBAAmBC,YAAAA,iBAAgB;AAC5C,SAASC,mBAAmB;AAE5B,SAASC,sBAAsBC,UAAUC,wCAAwC;AACjF,SAASC,iBAAiB;AAC1B,SAASC,UAAU;;;ACRnB,OAAOC,SAASC,eAAAA,oBAAmB;AAGnC,SAASC,wBAAwB;AACjC,SAASC,yBAA+C;AACxD,SAASC,yCAAyC;AAClD,SAASC,oBAAoBC,cAAcC,aAAaC,sBAAsB;;;ACN9E,SAASC,aAAaC,WAAWC,eAAe;AAEhD,SACEC,cACAC,kBACAC,8BACAC,sBAEAC,8BACAC,4BACK;AACP,SAASC,WAAW;AACpB,SAASC,iBAAiB;AAC1B,SAASC,QAAQC,QAAQC,SAASC,UAAUC,SAASC,gBAAgB;AACrE,SAASC,sBAAsB;AAC/B,SAASC,wBAAwB;;AAe1B,IAAMC,eAAe,CAACC,UAAAA;AAC3B,QAAMC,YAAYC,iBAAiB,SAAS;IAC1CC,OAAOH,MAAMI,SAAS;MAAC;MAAkB;QAAEC,IAAIC;MAAc;;IAC7DC,MAAM;IACNC,QAAQ,CAACR,MAAMI;EACjB,CAAA;AAEA,QAAMK,eAAeP,iBAAyC,UAAU;IACtEQ,MAAM;IACNP,OAAO;MAACH,MAAMW,YAAY,kBAAkB;MAAgB;QAAEN,IAAIC;MAAc;;IAChFC,MAAMP,MAAMW,YAAY,6BAA6B;IACrDC,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,cAACC,UAAUC,SAAO;IAACC,SAAAA;KACjB,gBAAAH,OAAA,cAACI,eAAAA;IAAcR;IAActB;IAAYE;MACzC,gBAAAwB,OAAA,cAACK,OAAAA;IAAI/B,MAAK;IAAOgC,WAAWC,GAAG,kEAAkEhC,UAAAA;KAC9FqB,MAAME,SAAS,WACd,gBAAAE,OAAA,cAACQ,kBAAAA;IACCd,IAAIlB,OAAOkB;IACXf;IACA8B,cAAcjC,OAAOa,QAAQC,QAAQC;IACrCP;IACAsB,WAAWI,iCAAiCpC,IAAAA;IAC5CqC,WAAWlC,SAASC;IACpByB,SAAAA;MAIHP,MAAME,SAAS,YAAY,gBAAAE,OAAA,cAACY,YAAAA;IAAWC,aAAajB,MAAMiB;;AAInE;AAEA,IAAA,0BAAexC;",
|
|
6
|
+
"names": ["React", "useMemo", "createDocAccessor", "getSpace", "useIdentity", "createDataExtensions", "listener", "stackItemContentEditorClassNames", "StackItem", "mx", "React", "useCallback", "fullyQualifiedId", "ElevationProvider", "stackItemContentToolbarClassNames", "createGapSeparator", "MenuProvider", "ToolbarMenu", "useMenuActions", "useCallback", "useEffect", "useMemo", "FunctionType", "getInvocationUrl", "getUserFunctionUrlInMetadata", "incrementSemverPatch", "setUserFunctionUrlInMetadata", "uploadWorkerFunction", "log", "useClient", "Filter", "create", "getMeta", "getSpace", "makeRef", "useQuery", "useTranslation", "createMenuAction", "createDeploy", "state", "errorItem", "createMenuAction", "label", "error", "ns", "SCRIPT_PLUGIN", "icon", "hidden", "deployAction", "type", "deploying", "disabled", "classNames", "copyAction", "functionUrl", "nodes", "edges", "source", "target", "useDeployDeps", "script", "space", "getSpace", "fn", "useQuery", "Filter", "schema", "FunctionType", "client", "useClient", "existingFunctionUrl", "useMemo", "getUserFunctionUrlInMetadata", "getMeta", "useDeployState", "useEffect", "getInvocationUrl", "config", "values", "runtime", "services", "edge", "url", "spaceId", "id", "deployed", "Boolean", "changed", "useDeployHandler", "t", "useTranslation", "useCallback", "undefined", "existingFunctionId", "split", "at", "bundler", "Bundler", "platform", "sandboxedModules", "remoteModules", "buildResult", "bundle", "content", "functionId", "version", "meta", "uploadWorkerFunction", "incrementSemverPatch", "Error", "log", "info", "deployedFunction", "db", "add", "create", "name", "makeRef", "description", "trim", "verbose", "inputSchema", "outputSchema", "setUserFunctionUrlInMetadata", "view", "err", "catch", "useCopyHandler", "navigator", "clipboard", "writeText", "format", "prettierPluginEstree", "prettierPluginTypescript", "useCallback", "log", "createMenuAction", "createFormat", "formatAction", "createMenuAction", "label", "ns", "SCRIPT_PLUGIN", "icon", "nodes", "edges", "source", "target", "useFormatHandler", "script", "useCallback", "content", "format", "parser", "plugins", "prettierPluginEstree", "prettierPluginTypescript", "semi", "singleQuote", "err", "log", "catch", "useCallback", "FUNCTIONS_PRESET_META_KEY", "getMeta", "createMenuItemGroup", "createMenuAction", "createTemplateSelectGroup", "createMenuItemGroup", "label", "ns", "SCRIPT_PLUGIN", "variant", "createTemplateSelectActions", "templates", "map", "template", "createMenuAction", "id", "name", "value", "type", "createTemplateSelect", "templateSelectGroup", "templateSelectActions", "nodes", "edges", "source", "target", "action", "useTemplateSelectHandler", "script", "useCallback", "templateId", "find", "content", "metaKeys", "getMeta", "keys", "oldPresetIndex", "findIndex", "key", "FUNCTIONS_PRESET_META_KEY", "splice", "presetId", "push", "createMenuAction", "createMenuItemGroup", "views", "editor", "split", "debug", "createViewGroupItem", "state", "createMenuItemGroup", "label", "ns", "SCRIPT_PLUGIN", "variant", "applyActive", "value", "view", "createViewActions", "Object", "entries", "map", "viewType", "icon", "createMenuAction", "type", "checked", "createView", "viewGroupItem", "viewActions", "nodes", "edges", "source", "target", "action", "id", "useCallback", "log", "useToolbarAction", "props", "handleTemplateSelect", "useTemplateSelectHandler", "handleFormat", "useFormatHandler", "handleDeploy", "useDeployHandler", "handleCopy", "useCopyHandler", "useCallback", "action", "properties", "type", "value", "state", "view", "log", "error", "useMemo", "create", "useToolbarState", "initialState", "useMemo", "create", "createToolbar", "state", "templateSelect", "createTemplateSelect", "format", "createFormat", "gap", "createGapSeparator", "deploy", "createDeploy", "view", "createView", "nodes", "edges", "ScriptToolbar", "script", "role", "classNames", "handleAction", "useToolbarAction", "toolbarCreator", "useCallback", "menu", "useMenuActions", "div", "className", "stackItemContentToolbarClassNames", "ElevationProvider", "elevation", "MenuProvider", "onAction", "attendableId", "fullyQualifiedId", "ToolbarMenu", "javascript", "defaultHighlightStyle", "Prec", "oneDarkHighlightStyle", "keymap", "tags", "continueKeymap", "tsSync", "tsFacet", "tsLinter", "tsAutocomplete", "tsHover", "React", "useThemeContext", "autocomplete", "createBasicExtensions", "createThemeExtensions", "editorFullWidth", "editorMonospace", "EditorView", "folding", "InputModeExtensions", "useTextEditor", "nonNullable", "TypescriptEditor", "id", "env", "className", "initialValue", "extensions", "scrollTo", "selection", "toolbar", "inputMode", "themeMode", "useThemeContext", "parentRef", "focusAttributes", "useTextEditor", "createBasicExtensions", "highlightActiveLine", "indentWithTab", "lineNumbers", "lineWrapping", "scrollPastEnd", "createThemeExtensions", "syntaxHighlighting", "slots", "content", "editorFullWidth", "EditorView", "theme", "marginTop", "InputModeExtensions", "folding", "Prec", "high", "keymap", "of", "continueKeymap", "editorMonospace", "javascript", "typescript", "autocomplete", "override", "tsAutocomplete", "tsFacet", "path", "tsSync", "tsLinter", "tsHover", "renderTooltip", "createTooltipRenderer", "filter", "nonNullable", "React", "div", "ref", "data-toolbar", "oneDarkHighlightStyle", "defaultHighlightStyle", "classFromKind", "_kind", "kind", "endsWith", "validTag", "tags", "tag", "style", "info", "document", "createElement", "quickInfo", "displayParts", "part", "span", "appendChild", "innerText", "text", "dom", "ScriptContainer", "role", "classNames", "script", "settings", "editorInputMode", "env", "identity", "useIdentity", "space", "getSpace", "extensions", "useMemo", "listener", "onChange", "text", "source", "target", "content", "changed", "createDataExtensions", "id", "createDocAccessor", "state", "useToolbarState", "view", "useDeployState", "React", "StackItem", "Content", "toolbar", "ScriptToolbar", "div", "className", "mx", "TypescriptEditor", "initialValue", "stackItemContentEditorClassNames", "inputMode", "DebugPanel", "functionUrl"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
// packages/plugins/experimental/plugin-script/src/capabilities/artifact.ts
|
|
2
|
+
import { Capabilities, contributes, createIntent } from "@dxos/app-framework";
|
|
3
|
+
import { defineArtifact, defineTool, ToolResult } from "@dxos/artifact";
|
|
4
|
+
import { createArtifactElement } from "@dxos/assistant";
|
|
5
|
+
import { ObjectId, S } from "@dxos/echo-schema";
|
|
6
|
+
import { ScriptType } from "@dxos/functions";
|
|
7
|
+
import { invariant } from "@dxos/invariant";
|
|
8
|
+
import { create, makeRef } from "@dxos/react-client/echo";
|
|
9
|
+
import { TextType } from "@dxos/schema";
|
|
10
|
+
import { SpaceAction } from "@dxos/plugin-space/types";
|
|
11
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-script/src/capabilities/artifact.ts";
|
|
12
|
+
var artifact_default = () => {
|
|
13
|
+
const definition = defineArtifact({
|
|
14
|
+
id: "plugin-script",
|
|
15
|
+
// TODO(dmaretskyi): Since writing scripts requires a lot of domain knowledge,
|
|
16
|
+
// we should offload the work of synthesizing the code to a separate model.
|
|
17
|
+
// The main reasoning model will give it a concrete task and the script model will synthesize the code, knowing all the docs.
|
|
18
|
+
instructions: `
|
|
19
|
+
If the user explicitly requests you to write a script, you can create one.
|
|
20
|
+
If the user requests you to change one of the existing script, you can update it.
|
|
21
|
+
Scripts are short code pieces of executable code that can be used to perform computations, integrate with external systems, and perform automated tasks.
|
|
22
|
+
Each script must follow as strict shape for the definition but the body can contain any valid executable code.
|
|
23
|
+
Scripts are written in JavaScript or TypeScript.
|
|
24
|
+
Each script must define an input schema and output schema.
|
|
25
|
+
Each script must have its own detailed description.
|
|
26
|
+
|
|
27
|
+
Important: You cannot execute scripts. Scripts are only available as tools after the user deploys them. You must only call the available tools.
|
|
28
|
+
|
|
29
|
+
Description:
|
|
30
|
+
The description is a detailed description of the script.
|
|
31
|
+
It is used to describe the script's purpose, input, and output.
|
|
32
|
+
The description is used to generate the script's documentation.
|
|
33
|
+
The description is also goes into the script metadata.
|
|
34
|
+
The description is used by AI to understand the script and its purpose.
|
|
35
|
+
The description must provide cases on when the script should be used.
|
|
36
|
+
|
|
37
|
+
Schema:
|
|
38
|
+
The schema is defined using a schema-DSL library called Effect Schema.
|
|
39
|
+
The input schema describes the arguments that the script accepts.
|
|
40
|
+
The output schema describes the result that the script produces.
|
|
41
|
+
The schema is used to validate the script's input and output.
|
|
42
|
+
The schema is also goes into the script metadata.
|
|
43
|
+
The properties in the schema must have valid descriptions.
|
|
44
|
+
The input and output schemas must both be a struct of fields.
|
|
45
|
+
|
|
46
|
+
Restricts:
|
|
47
|
+
The scripts can only import code from "dxos:functions" module. No other modules are allowed.
|
|
48
|
+
Some web APIs are available - like fetch.
|
|
49
|
+
|
|
50
|
+
Reasoning:
|
|
51
|
+
Before writing a script, synthesize the following information:
|
|
52
|
+
- Description
|
|
53
|
+
- What APIs will be used.
|
|
54
|
+
- Detailed input schema
|
|
55
|
+
- Detailed output schema
|
|
56
|
+
|
|
57
|
+
<apis>
|
|
58
|
+
export function defineFunction(params: {
|
|
59
|
+
description: string,
|
|
60
|
+
inputSchema: S.Schema,
|
|
61
|
+
outputSchema: S.Schema,
|
|
62
|
+
handler: (params: { event: { data: TInput } }) => Promise<TOutput>
|
|
63
|
+
}): FunctionDefinition
|
|
64
|
+
/**
|
|
65
|
+
* Effect Schema
|
|
66
|
+
*/
|
|
67
|
+
export const S;
|
|
68
|
+
|
|
69
|
+
// Examples:
|
|
70
|
+
|
|
71
|
+
S.String
|
|
72
|
+
S.Number
|
|
73
|
+
S.Boolean
|
|
74
|
+
S.Struct({
|
|
75
|
+
from: S.String.annotations({ description: 'The source currency' }),
|
|
76
|
+
to: S.String.annotations({ description: 'The target currency' }),
|
|
77
|
+
})
|
|
78
|
+
S.Array(S.String)
|
|
79
|
+
S.Union(S.String, S.Number)
|
|
80
|
+
S.Optional(S.String)
|
|
81
|
+
S.String.annotations({ description: 'The source currency' })
|
|
82
|
+
</apis>
|
|
83
|
+
|
|
84
|
+
<handler_function>
|
|
85
|
+
Async function that takes the argument in the form of:
|
|
86
|
+
|
|
87
|
+
type HandlerFunctionParam = {
|
|
88
|
+
event: {
|
|
89
|
+
data: T // The input schema
|
|
90
|
+
},
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
The function must return the result that matches the output schema.
|
|
94
|
+
</handler_function>
|
|
95
|
+
|
|
96
|
+
<example>
|
|
97
|
+
import { defineFunction, S } from 'dxos:functions';
|
|
98
|
+
|
|
99
|
+
export default defineFunction({
|
|
100
|
+
description: 'Returns the exchange rate between two currencies.',
|
|
101
|
+
|
|
102
|
+
inputSchema: S.Struct({
|
|
103
|
+
from: S.String.annotations({ description: 'The source currency' }),
|
|
104
|
+
to: S.String.annotations({ description: 'The target currency' }),
|
|
105
|
+
}),
|
|
106
|
+
|
|
107
|
+
outputSchema: S.Struct({
|
|
108
|
+
rate: S.String.annotations({ description: 'The exchange rate' }),
|
|
109
|
+
}),
|
|
110
|
+
|
|
111
|
+
handler: async ({
|
|
112
|
+
event: {
|
|
113
|
+
data: { from, to },
|
|
114
|
+
},
|
|
115
|
+
}: any) => {
|
|
116
|
+
const res = await fetch(\`https://free.ratesdb.com/v1/rates?from=\${from}&to=\${to}\`);
|
|
117
|
+
const {
|
|
118
|
+
data: { rates },
|
|
119
|
+
} = await res.json();
|
|
120
|
+
|
|
121
|
+
return { rate: rates[to].toString() };
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
</example>
|
|
125
|
+
`,
|
|
126
|
+
schema: ScriptType,
|
|
127
|
+
tools: [
|
|
128
|
+
defineTool({
|
|
129
|
+
name: "script_new",
|
|
130
|
+
description: "Create a new script. Returns the artifact definition for the script",
|
|
131
|
+
schema: S.Struct({
|
|
132
|
+
name: S.String.annotations({
|
|
133
|
+
description: "The name of the script"
|
|
134
|
+
}),
|
|
135
|
+
code: S.String.annotations({
|
|
136
|
+
description: "The full code of the script in JavaScript or TypeScript. Must be valid executable code."
|
|
137
|
+
})
|
|
138
|
+
}),
|
|
139
|
+
execute: async ({ name, code }, { extensions }) => {
|
|
140
|
+
invariant(extensions?.space, "No space", {
|
|
141
|
+
F: __dxlog_file,
|
|
142
|
+
L: 149,
|
|
143
|
+
S: void 0,
|
|
144
|
+
A: [
|
|
145
|
+
"extensions?.space",
|
|
146
|
+
"'No space'"
|
|
147
|
+
]
|
|
148
|
+
});
|
|
149
|
+
invariant(extensions?.dispatch, "No intent dispatcher", {
|
|
150
|
+
F: __dxlog_file,
|
|
151
|
+
L: 150,
|
|
152
|
+
S: void 0,
|
|
153
|
+
A: [
|
|
154
|
+
"extensions?.dispatch",
|
|
155
|
+
"'No intent dispatcher'"
|
|
156
|
+
]
|
|
157
|
+
});
|
|
158
|
+
const script = create(ScriptType, {
|
|
159
|
+
name,
|
|
160
|
+
source: makeRef(create(TextType, {
|
|
161
|
+
content: code
|
|
162
|
+
}))
|
|
163
|
+
});
|
|
164
|
+
extensions.space.db.add(script);
|
|
165
|
+
await extensions.space.db.flush();
|
|
166
|
+
const intent = createIntent(SpaceAction.AddObject, {
|
|
167
|
+
target: extensions.space,
|
|
168
|
+
object: script
|
|
169
|
+
});
|
|
170
|
+
const { data, error } = await extensions.dispatch(intent);
|
|
171
|
+
if (!data || error) {
|
|
172
|
+
return ToolResult.Error(error?.message ?? "Failed to create chess game");
|
|
173
|
+
}
|
|
174
|
+
return ToolResult.Success(createArtifactElement(script.id));
|
|
175
|
+
}
|
|
176
|
+
}),
|
|
177
|
+
defineTool({
|
|
178
|
+
name: "script_inspect",
|
|
179
|
+
description: "Inspect a script. Returns the artifact definition for the script",
|
|
180
|
+
schema: S.Struct({
|
|
181
|
+
id: ObjectId
|
|
182
|
+
}),
|
|
183
|
+
execute: async ({ id }, { extensions }) => {
|
|
184
|
+
invariant(extensions?.space, "No space", {
|
|
185
|
+
F: __dxlog_file,
|
|
186
|
+
L: 178,
|
|
187
|
+
S: void 0,
|
|
188
|
+
A: [
|
|
189
|
+
"extensions?.space",
|
|
190
|
+
"'No space'"
|
|
191
|
+
]
|
|
192
|
+
});
|
|
193
|
+
const script = await extensions.space.db.query({
|
|
194
|
+
id
|
|
195
|
+
}).first();
|
|
196
|
+
const { content } = await script.source.load();
|
|
197
|
+
return ToolResult.Success({
|
|
198
|
+
name: script.name,
|
|
199
|
+
code: content
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}),
|
|
203
|
+
defineTool({
|
|
204
|
+
name: "script_update",
|
|
205
|
+
description: "Update a script. Returns the artifact definition for the script",
|
|
206
|
+
schema: S.Struct({
|
|
207
|
+
id: ObjectId,
|
|
208
|
+
code: S.String.annotations({
|
|
209
|
+
description: "The full code of the script in JavaScript or TypeScript. Must be valid executable code."
|
|
210
|
+
})
|
|
211
|
+
}),
|
|
212
|
+
execute: async ({ id, code }, { extensions }) => {
|
|
213
|
+
invariant(extensions?.space, "No space", {
|
|
214
|
+
F: __dxlog_file,
|
|
215
|
+
L: 199,
|
|
216
|
+
S: void 0,
|
|
217
|
+
A: [
|
|
218
|
+
"extensions?.space",
|
|
219
|
+
"'No space'"
|
|
220
|
+
]
|
|
221
|
+
});
|
|
222
|
+
const script = await extensions.space.db.query({
|
|
223
|
+
id
|
|
224
|
+
}).first();
|
|
225
|
+
const source = await script.source.load();
|
|
226
|
+
if (!source) {
|
|
227
|
+
return ToolResult.Error("Script not found");
|
|
228
|
+
}
|
|
229
|
+
source.content = code;
|
|
230
|
+
await extensions.space?.db.flush();
|
|
231
|
+
return ToolResult.Success({
|
|
232
|
+
name: script.name
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
})
|
|
236
|
+
]
|
|
237
|
+
});
|
|
238
|
+
return contributes(Capabilities.ArtifactDefinition, definition);
|
|
239
|
+
};
|
|
240
|
+
export {
|
|
241
|
+
artifact_default as default
|
|
242
|
+
};
|
|
243
|
+
//# sourceMappingURL=artifact-3UZZBCZ2.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/capabilities/artifact.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Capabilities, contributes, createIntent, type PromiseIntentDispatcher } from '@dxos/app-framework';\nimport { defineArtifact, defineTool, ToolResult } from '@dxos/artifact';\nimport { createArtifactElement } from '@dxos/assistant';\nimport { ObjectId, S } from '@dxos/echo-schema';\nimport { ScriptType } from '@dxos/functions';\nimport { invariant } from '@dxos/invariant';\nimport { create, makeRef, type Space } from '@dxos/react-client/echo';\nimport { TextType } from '@dxos/schema';\nimport { SpaceAction } from '@dxos/plugin-space/types';\n\n// TODO(burdon): Factor out.\ndeclare global {\n interface ToolContextExtensions {\n space?: Space;\n dispatch?: PromiseIntentDispatcher;\n }\n}\n\nexport default () => {\n const definition = defineArtifact({\n id: 'plugin-script',\n // TODO(dmaretskyi): Since writing scripts requires a lot of domain knowledge,\n // we should offload the work of synthesizing the code to a separate model.\n // The main reasoning model will give it a concrete task and the script model will synthesize the code, knowing all the docs.\n instructions: `\n If the user explicitly requests you to write a script, you can create one.\n If the user requests you to change one of the existing script, you can update it.\n Scripts are short code pieces of executable code that can be used to perform computations, integrate with external systems, and perform automated tasks.\n Each script must follow as strict shape for the definition but the body can contain any valid executable code.\n Scripts are written in JavaScript or TypeScript.\n Each script must define an input schema and output schema.\n Each script must have its own detailed description.\n\n Important: You cannot execute scripts. Scripts are only available as tools after the user deploys them. You must only call the available tools.\n\n Description:\n The description is a detailed description of the script.\n It is used to describe the script's purpose, input, and output.\n The description is used to generate the script's documentation.\n The description is also goes into the script metadata.\n The description is used by AI to understand the script and its purpose.\n The description must provide cases on when the script should be used.\n\n Schema: \n The schema is defined using a schema-DSL library called Effect Schema.\n The input schema describes the arguments that the script accepts.\n The output schema describes the result that the script produces.\n The schema is used to validate the script's input and output.\n The schema is also goes into the script metadata.\n The properties in the schema must have valid descriptions.\n The input and output schemas must both be a struct of fields.\n\n Restricts:\n The scripts can only import code from \"dxos:functions\" module. No other modules are allowed.\n Some web APIs are available - like fetch.\n\n Reasoning:\n Before writing a script, synthesize the following information:\n - Description\n - What APIs will be used.\n - Detailed input schema\n - Detailed output schema\n\n <apis>\n export function defineFunction(params: { \n description: string, \n inputSchema: S.Schema, \n outputSchema: S.Schema, \n handler: (params: { event: { data: TInput } }) => Promise<TOutput> \n }): FunctionDefinition\n /**\n * Effect Schema\n */\n export const S; \n\n // Examples: \n\n S.String\n S.Number\n S.Boolean\n S.Struct({\n from: S.String.annotations({ description: 'The source currency' }),\n to: S.String.annotations({ description: 'The target currency' }),\n })\n S.Array(S.String)\n S.Union(S.String, S.Number)\n S.Optional(S.String)\n S.String.annotations({ description: 'The source currency' })\n </apis>\n\n <handler_function>\n Async function that takes the argument in the form of:\n\n type HandlerFunctionParam = {\n event: {\n data: T // The input schema\n },\n }\n\n The function must return the result that matches the output schema.\n </handler_function>\n \n <example>\n import { defineFunction, S } from 'dxos:functions';\n\n export default defineFunction({\n description: 'Returns the exchange rate between two currencies.',\n\n inputSchema: S.Struct({\n from: S.String.annotations({ description: 'The source currency' }),\n to: S.String.annotations({ description: 'The target currency' }),\n }),\n\n outputSchema: S.Struct({\n rate: S.String.annotations({ description: 'The exchange rate' }),\n }),\n\n handler: async ({\n event: {\n data: { from, to },\n },\n }: any) => {\n const res = await fetch(\\`https://free.ratesdb.com/v1/rates?from=\\${from}&to=\\${to}\\`);\n const {\n data: { rates },\n } = await res.json();\n\n return { rate: rates[to].toString() };\n },\n });\n </example>\n `,\n schema: ScriptType,\n tools: [\n defineTool({\n name: 'script_new',\n description: 'Create a new script. Returns the artifact definition for the script',\n schema: S.Struct({\n name: S.String.annotations({ description: 'The name of the script' }),\n code: S.String.annotations({\n description: 'The full code of the script in JavaScript or TypeScript. Must be valid executable code.',\n }),\n }),\n execute: async ({ name, code }, { extensions }) => {\n invariant(extensions?.space, 'No space');\n invariant(extensions?.dispatch, 'No intent dispatcher');\n const script = create(ScriptType, {\n name,\n source: makeRef(\n create(TextType, {\n content: code,\n }),\n ),\n });\n extensions.space.db.add(script);\n await extensions.space.db.flush();\n\n const intent = createIntent(SpaceAction.AddObject, { target: extensions.space, object: script });\n const { data, error } = await extensions.dispatch(intent);\n if (!data || error) {\n return ToolResult.Error(error?.message ?? 'Failed to create chess game');\n }\n\n return ToolResult.Success(createArtifactElement(script.id));\n },\n }),\n defineTool({\n name: 'script_inspect',\n description: 'Inspect a script. Returns the artifact definition for the script',\n schema: S.Struct({\n id: ObjectId,\n }),\n execute: async ({ id }, { extensions }) => {\n invariant(extensions?.space, 'No space');\n\n const script = (await extensions.space.db.query({ id }).first()) as ScriptType;\n const { content } = await script.source.load();\n\n return ToolResult.Success({\n name: script.name,\n code: content,\n });\n },\n }),\n defineTool({\n name: 'script_update',\n description: 'Update a script. Returns the artifact definition for the script',\n schema: S.Struct({\n id: ObjectId,\n code: S.String.annotations({\n description: 'The full code of the script in JavaScript or TypeScript. Must be valid executable code.',\n }),\n }),\n execute: async ({ id, code }, { extensions }) => {\n invariant(extensions?.space, 'No space');\n\n const script = (await extensions.space.db.query({ id }).first()) as ScriptType;\n const source = await script.source.load();\n if (!source) {\n return ToolResult.Error('Script not found');\n }\n\n source.content = code;\n await extensions.space?.db.flush();\n\n return ToolResult.Success({\n name: script.name,\n });\n },\n }),\n ],\n });\n\n return contributes(Capabilities.ArtifactDefinition, definition);\n};\n"],
|
|
5
|
+
"mappings": ";AAIA,SAASA,cAAcC,aAAaC,oBAAkD;AACtF,SAASC,gBAAgBC,YAAYC,kBAAkB;AACvD,SAASC,6BAA6B;AACtC,SAASC,UAAUC,SAAS;AAC5B,SAASC,kBAAkB;AAC3B,SAASC,iBAAiB;AAC1B,SAASC,QAAQC,eAA2B;AAC5C,SAASC,gBAAgB;AACzB,SAASC,mBAAmB;;AAU5B,IAAA,mBAAe,MAAA;AACb,QAAMC,aAAaZ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AE;AACpCjB,oBAAUiB,YAAYC,OAAO,YAAA;;;;;;;;;AAE7B,gBAAME,SAAU,MAAMH,WAAWC,MAAMK,GAAGY,MAAM;YAAE7B;UAAG,CAAA,EAAG8B,MAAK;AAC7D,gBAAM,EAAEd,QAAO,IAAK,MAAMF,OAAOC,OAAOgB,KAAI;AAE5C,iBAAO1C,WAAWuC,QAAQ;YACxBxB,MAAMU,OAAOV;YACbK,MAAMO;UACR,CAAA;QACF;MACF,CAAA;MACA5B,WAAW;QACTgB,MAAM;QACNC,aAAa;QACbH,QAAQV,EAAEc,OAAO;UACfN,IAAIT;UACJkB,MAAMjB,EAAEe,OAAOC,YAAY;YACzBH,aAAa;UACf,CAAA;QACF,CAAA;QACAK,SAAS,OAAO,EAAEV,IAAIS,KAAI,GAAI,EAAEE,WAAU,MAAE;AAC1CjB,oBAAUiB,YAAYC,OAAO,YAAA;;;;;;;;;AAE7B,gBAAME,SAAU,MAAMH,WAAWC,MAAMK,GAAGY,MAAM;YAAE7B;UAAG,CAAA,EAAG8B,MAAK;AAC7D,gBAAMf,SAAS,MAAMD,OAAOC,OAAOgB,KAAI;AACvC,cAAI,CAAChB,QAAQ;AACX,mBAAO1B,WAAWqC,MAAM,kBAAA;UAC1B;AAEAX,iBAAOC,UAAUP;AACjB,gBAAME,WAAWC,OAAOK,GAAGE,MAAAA;AAE3B,iBAAO9B,WAAWuC,QAAQ;YACxBxB,MAAMU,OAAOV;UACf,CAAA;QACF;MACF,CAAA;;EAEJ,CAAA;AAEA,SAAOnB,YAAYD,aAAagD,oBAAoBjC,UAAAA;AACtD;",
|
|
6
|
+
"names": ["Capabilities", "contributes", "createIntent", "defineArtifact", "defineTool", "ToolResult", "createArtifactElement", "ObjectId", "S", "ScriptType", "invariant", "create", "makeRef", "TextType", "SpaceAction", "definition", "id", "instructions", "schema", "tools", "name", "description", "Struct", "String", "annotations", "code", "execute", "extensions", "space", "dispatch", "script", "source", "content", "db", "add", "flush", "intent", "AddObject", "target", "object", "data", "error", "Error", "message", "Success", "query", "first", "load", "ArtifactDefinition"]
|
|
7
|
+
}
|
|
@@ -59,7 +59,7 @@ import { FunctionType, getInvocationUrl, getUserFunctionUrlInMetadata } from "@d
|
|
|
59
59
|
import { log } from "@dxos/log";
|
|
60
60
|
import { useClient as useClient2 } from "@dxos/react-client";
|
|
61
61
|
import { Filter, getMeta, getSpace, useQuery } from "@dxos/react-client/echo";
|
|
62
|
-
import { Button as Button2, Clipboard, Input, Separator,
|
|
62
|
+
import { Button as Button2, Clipboard, Input, Separator, useControlledState, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
63
63
|
import { AccessTokenType } from "@dxos/schema";
|
|
64
64
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-script/src/components/ScriptSettingsPanel.tsx";
|
|
65
65
|
var kebabize = (str) => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? "-" : "") + $.toLowerCase());
|
|
@@ -107,7 +107,7 @@ var ScriptSettingsPanel = ({ script }) => {
|
|
|
107
107
|
githubToken,
|
|
108
108
|
gistKey
|
|
109
109
|
]);
|
|
110
|
-
const [binding, setBinding] =
|
|
110
|
+
const [binding, setBinding] = useControlledState(fn?.binding ?? "");
|
|
111
111
|
const handleBindingChange = useCallback((event) => {
|
|
112
112
|
setBinding(event.target.value);
|
|
113
113
|
}, [
|
|
@@ -225,7 +225,7 @@ var ScriptSettingsPanel = ({ script }) => {
|
|
|
225
225
|
// packages/plugins/experimental/plugin-script/src/components/index.ts
|
|
226
226
|
import { lazy } from "react";
|
|
227
227
|
var AutomationPanel = lazy(() => import("./AutomationPanel-J3SZ5L3Y.mjs"));
|
|
228
|
-
var ScriptContainer = lazy(() => import("./ScriptContainer-
|
|
228
|
+
var ScriptContainer = lazy(() => import("./ScriptContainer-QI4NQT7V.mjs"));
|
|
229
229
|
|
|
230
230
|
export {
|
|
231
231
|
ScriptSettings,
|
|
@@ -233,4 +233,4 @@ export {
|
|
|
233
233
|
AutomationPanel,
|
|
234
234
|
ScriptContainer
|
|
235
235
|
};
|
|
236
|
-
//# sourceMappingURL=chunk-
|
|
236
|
+
//# sourceMappingURL=chunk-F22QPQ6G.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/ScriptSettings/ScriptSettings.tsx", "../../../src/components/ScriptSettingsPanel.tsx", "../../../src/components/index.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React from 'react';\n\nimport { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';\nimport { useClient } from '@dxos/react-client';\nimport { Button, Select, useTranslation } from '@dxos/react-ui';\nimport { type EditorInputMode, EditorInputModes } from '@dxos/react-ui-editor';\nimport { DeprecatedFormContainer, DeprecatedFormInput } from '@dxos/react-ui-form';\n\nimport { SCRIPT_PLUGIN } from '../../meta';\nimport { type ScriptSettingsProps } from '../../types';\n\nexport const ScriptSettings = ({ settings }: { settings: ScriptSettingsProps }) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n const client = useClient();\n\n // TODO(burdon): Check token.\n const handleAuthenticate = async () => {\n const { identityKey } = client.halo.identity.get()!;\n await client.halo.writeCredentials([\n {\n issuer: identityKey,\n issuanceDate: new Date(),\n subject: {\n id: identityKey,\n assertion: {\n '@type': 'dxos.halo.credentials.ServiceAccess',\n serverName: 'hub.dxos.network',\n serverKey: identityKey,\n identityKey,\n capabilities: ['composer:beta'],\n },\n },\n } satisfies Credential,\n ]);\n };\n\n return (\n <DeprecatedFormContainer>\n {/* TODO(wittjosiah): Hide outside of dev environments. */}\n <DeprecatedFormInput label={t('authenticate action label')}>\n <Button onClick={handleAuthenticate}>{t('authenticate button label')}</Button>\n </DeprecatedFormInput>\n\n <DeprecatedFormInput label={t('editor input mode label')}>\n <Select.Root\n value={settings.editorInputMode ?? 'default'}\n onValueChange={(value) => {\n settings.editorInputMode = value as EditorInputMode;\n }}\n >\n <Select.TriggerButton placeholder={t('select editor input mode placeholder')} />\n <Select.Portal>\n <Select.Content>\n <Select.Viewport>\n {EditorInputModes.map((mode) => (\n <Select.Option key={mode} value={mode}>\n {t(`settings editor input mode ${mode} label`)}\n </Select.Option>\n ))}\n </Select.Viewport>\n </Select.Content>\n </Select.Portal>\n </Select.Root>\n </DeprecatedFormInput>\n </DeprecatedFormContainer>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { Octokit } from '@octokit/core';\nimport React, { type ChangeEvent, useCallback, useEffect, useState } from 'react';\n\nimport { createIntent, SettingsAction, useIntentDispatcher } from '@dxos/app-framework';\nimport { FunctionType, type ScriptType, getInvocationUrl, getUserFunctionUrlInMetadata } from '@dxos/functions';\nimport { log } from '@dxos/log';\nimport { useClient } from '@dxos/react-client';\nimport { Filter, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';\nimport { Button, Clipboard, Input, Separator,
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React from 'react';\n\nimport { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';\nimport { useClient } from '@dxos/react-client';\nimport { Button, Select, useTranslation } from '@dxos/react-ui';\nimport { type EditorInputMode, EditorInputModes } from '@dxos/react-ui-editor';\nimport { DeprecatedFormContainer, DeprecatedFormInput } from '@dxos/react-ui-form';\n\nimport { SCRIPT_PLUGIN } from '../../meta';\nimport { type ScriptSettingsProps } from '../../types';\n\nexport const ScriptSettings = ({ settings }: { settings: ScriptSettingsProps }) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n const client = useClient();\n\n // TODO(burdon): Check token.\n const handleAuthenticate = async () => {\n const { identityKey } = client.halo.identity.get()!;\n await client.halo.writeCredentials([\n {\n issuer: identityKey,\n issuanceDate: new Date(),\n subject: {\n id: identityKey,\n assertion: {\n '@type': 'dxos.halo.credentials.ServiceAccess',\n serverName: 'hub.dxos.network',\n serverKey: identityKey,\n identityKey,\n capabilities: ['composer:beta'],\n },\n },\n } satisfies Credential,\n ]);\n };\n\n return (\n <DeprecatedFormContainer>\n {/* TODO(wittjosiah): Hide outside of dev environments. */}\n <DeprecatedFormInput label={t('authenticate action label')}>\n <Button onClick={handleAuthenticate}>{t('authenticate button label')}</Button>\n </DeprecatedFormInput>\n\n <DeprecatedFormInput label={t('editor input mode label')}>\n <Select.Root\n value={settings.editorInputMode ?? 'default'}\n onValueChange={(value) => {\n settings.editorInputMode = value as EditorInputMode;\n }}\n >\n <Select.TriggerButton placeholder={t('select editor input mode placeholder')} />\n <Select.Portal>\n <Select.Content>\n <Select.Viewport>\n {EditorInputModes.map((mode) => (\n <Select.Option key={mode} value={mode}>\n {t(`settings editor input mode ${mode} label`)}\n </Select.Option>\n ))}\n </Select.Viewport>\n </Select.Content>\n </Select.Portal>\n </Select.Root>\n </DeprecatedFormInput>\n </DeprecatedFormContainer>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { Octokit } from '@octokit/core';\nimport React, { type ChangeEvent, useCallback, useEffect, useState } from 'react';\n\nimport { createIntent, SettingsAction, useIntentDispatcher } from '@dxos/app-framework';\nimport { FunctionType, type ScriptType, getInvocationUrl, getUserFunctionUrlInMetadata } from '@dxos/functions';\nimport { log } from '@dxos/log';\nimport { useClient } from '@dxos/react-client';\nimport { Filter, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';\nimport { Button, Clipboard, Input, Separator, useControlledState, useTranslation } from '@dxos/react-ui';\nimport { AccessTokenType } from '@dxos/schema';\n\nimport { SCRIPT_PLUGIN } from '../meta';\n\n// TODO(wittjosiah): Factor out.\n// From https://stackoverflow.com/a/67243723/2804332\nconst kebabize = (str: string) => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? '-' : '') + $.toLowerCase());\n\nexport type ScriptSettingsPanelProps = {\n script: ScriptType;\n};\n\nexport const ScriptSettingsPanel = ({ script }: ScriptSettingsPanelProps) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n const { dispatchPromise: dispatch } = useIntentDispatcher();\n const client = useClient();\n const space = getSpace(script);\n const [fn] = useQuery(space, Filter.schema(FunctionType, { source: script }));\n const [githubToken] = useQuery(space, Filter.schema(AccessTokenType, { source: 'github.com' }));\n const gistKey = getMeta(script).keys.find(({ source }) => source === 'github.com');\n const [gistUrl, setGistUrl] = useState<string | undefined>();\n\n useEffect(() => {\n const token = githubToken?.token;\n const gistId = gistKey?.id;\n if (!token || !gistId) {\n setGistUrl(undefined);\n return;\n }\n\n const timeout = setTimeout(async () => {\n try {\n const octokit = new Octokit({ auth: githubToken.token });\n const response = await octokit.request('GET /gists/{gist_id}', {\n gist_id: gistId,\n });\n setGistUrl(response.data.html_url);\n } catch (err) {\n log.catch(err);\n setGistUrl(undefined);\n }\n });\n\n return () => clearTimeout(timeout);\n }, [githubToken, gistKey]);\n\n const [binding, setBinding] = useControlledState(fn?.binding ?? '');\n const handleBindingChange = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n setBinding(event.target.value);\n },\n [setBinding],\n );\n const handleBindingBlur = useCallback(() => {\n fn.binding = binding;\n }, [fn, binding]);\n\n const functionPath = fn && getUserFunctionUrlInMetadata(getMeta(fn));\n const functionUrl =\n functionPath &&\n getInvocationUrl(functionPath, client.config.values.runtime?.services?.edge?.url ?? '', {\n spaceId: space?.id,\n });\n\n const handleOpenTokenManager = useCallback(\n () => dispatch(createIntent(SettingsAction.Open, { plugin: 'dxos.org/plugin/token-manager' })),\n [],\n );\n\n const [publishing, setPublishing] = useState(false);\n const handlePublish = useCallback(async () => {\n setPublishing(true);\n const octokit = new Octokit({ auth: githubToken.token });\n const source = await script.source.load();\n const filename = script.name ? kebabize(script.name) : 'composer-script';\n const files = { [`${filename}.ts`]: { content: source.content } };\n\n try {\n // TODO(wittjosiah): Factor out to intent.\n const meta = getMeta(script);\n const githubKey = meta.keys.find(({ source }) => source === 'github.com');\n const gistId = githubKey?.id;\n if (gistId) {\n await octokit.request('PATCH /gists/{gist_id}', {\n gist_id: gistId,\n files,\n });\n } else {\n const response = await octokit.request('POST /gists', {\n public: true,\n files,\n });\n if (response.data.id) {\n meta.keys.push({ source: 'github.com', id: response.data.id });\n }\n }\n } finally {\n setPublishing(false);\n }\n }, [script, githubToken]);\n\n return (\n <>\n <div role='form' className='flex flex-col w-full p-2 gap-4'>\n <Input.Root>\n <div role='none' className='flex flex-col gap-1'>\n <Input.Label>{t('description label')}</Input.Label>\n <Input.TextInput\n placeholder={t('description placeholder')}\n value={script.description ?? ''}\n onChange={(event) => {\n script.description = event.target.value;\n }}\n />\n </div>\n </Input.Root>\n </div>\n {fn && functionUrl && (\n <>\n <Separator />\n <div role='form' className='flex flex-col w-full p-2 gap-4'>\n <h2>{t('remote function settings heading')}</h2>\n <Input.Root>\n <div role='none' className='flex flex-col gap-1'>\n <Input.Label>{t('function url label')}</Input.Label>\n <div role='none' className='flex gap-1'>\n <Input.TextInput\n disabled\n value={functionUrl}\n onChange={(event) => {\n fn.name = event.target.value;\n }}\n />\n <Clipboard.IconButton value={functionUrl} />\n </div>\n </div>\n </Input.Root>\n <Input.Root>\n <div role='none' className='flex flex-col gap-1'>\n <Input.Label>{t('function binding label')}</Input.Label>\n <Input.TextInput\n placeholder={t('function binding placeholder')}\n value={binding}\n onChange={handleBindingChange}\n onBlur={handleBindingBlur}\n />\n </div>\n </Input.Root>\n </div>\n </>\n )}\n <Separator />\n <div className='flex flex-col w-full p-2 gap-4'>\n <div>\n <h2>{t('script publish settings label')}</h2>\n <p className='text-description text-sm'>{t('script publish settings description')}</p>\n </div>\n {!githubToken && (\n <div className='flex flex-col items-center justify-center gap-2'>\n <span>{t('no github token label')}</span>\n <Button onClick={handleOpenTokenManager}>{t('open token manager label')}</Button>\n </div>\n )}\n {githubToken && (\n <div className='flex justify-end gap-2'>\n {gistUrl && <Clipboard.IconButton value={gistUrl} />}\n <Button disabled={publishing} onClick={handlePublish}>\n {t(publishing ? 'publishing label' : 'publish label')}\n </Button>\n </div>\n )}\n </div>\n </>\n );\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { lazy } from 'react';\n\nexport * from './ScriptSettings';\nexport * from './ScriptSettingsPanel';\n\nexport const AutomationPanel = lazy(() => import('./AutomationPanel'));\nexport const ScriptContainer = lazy(() => import('./ScriptContainer'));\n"],
|
|
5
5
|
"mappings": ";;;;;AAIA,OAAOA,WAAW;AAGlB,SAASC,iBAAiB;AAC1B,SAASC,QAAQC,QAAQC,sBAAsB;AAC/C,SAA+BC,wBAAwB;AACvD,SAASC,yBAAyBC,2BAA2B;AAKtD,IAAMC,iBAAiB,CAAC,EAAEC,SAAQ,MAAqC;AAC5E,QAAM,EAAEC,EAAC,IAAKC,eAAeC,aAAAA;AAC7B,QAAMC,SAASC,UAAAA;AAGf,QAAMC,qBAAqB,YAAA;AACzB,UAAM,EAAEC,YAAW,IAAKH,OAAOI,KAAKC,SAASC,IAAG;AAChD,UAAMN,OAAOI,KAAKG,iBAAiB;MACjC;QACEC,QAAQL;QACRM,cAAc,oBAAIC,KAAAA;QAClBC,SAAS;UACPC,IAAIT;UACJU,WAAW;YACT,SAAS;YACTC,YAAY;YACZC,WAAWZ;YACXA;YACAa,cAAc;cAAC;;UACjB;QACF;MACF;KACD;EACH;AAEA,SACE,sBAAA,cAACC,yBAAAA,MAEC,sBAAA,cAACC,qBAAAA;IAAoBC,OAAOtB,EAAE,2BAAA;KAC5B,sBAAA,cAACuB,QAAAA;IAAOC,SAASnB;KAAqBL,EAAE,2BAAA,CAAA,CAAA,GAG1C,sBAAA,cAACqB,qBAAAA;IAAoBC,OAAOtB,EAAE,yBAAA;KAC5B,sBAAA,cAACyB,OAAOC,MAAI;IACVC,OAAO5B,SAAS6B,mBAAmB;IACnCC,eAAe,CAACF,UAAAA;AACd5B,eAAS6B,kBAAkBD;IAC7B;KAEA,sBAAA,cAACF,OAAOK,eAAa;IAACC,aAAa/B,EAAE,sCAAA;MACrC,sBAAA,cAACyB,OAAOO,QAAM,MACZ,sB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AAA,GAE5C,CAACgB,eACA,gBAAAiE,OAAA,cAACC,OAAAA;IAAIE,WAAU;KACb,gBAAAH,OAAA,cAACkB,QAAAA,MAAMnG,EAAE,uBAAA,CAAA,GACT,gBAAAiF,OAAA,cAACmB,SAAAA;IAAOC,SAASrC;KAAyBhE,EAAE,0BAAA,CAAA,CAAA,GAG/CgB,eACC,gBAAAiE,OAAA,cAACC,OAAAA;IAAIE,WAAU;KACZ9D,WAAW,gBAAA2D,OAAA,cAACc,UAAUC,YAAU;IAAC7C,OAAO7B;MACzC,gBAAA2D,OAAA,cAACmB,SAAAA;IAAON,UAAUzB;IAAYgC,SAAS9B;KACpCvE,EAAEqE,aAAa,qBAAqB,eAAA,CAAA,CAAA,CAAA,CAAA;AAOnD;;;ACvLA,SAASiC,YAAY;AAKd,IAAMC,kBAAkBC,KAAK,MAAM,OAAO,gCAAA,CAAA;AAC1C,IAAMC,kBAAkBD,KAAK,MAAM,OAAO,gCAAA,CAAA;",
|
|
6
|
-
"names": ["React", "useClient", "Button", "Select", "useTranslation", "EditorInputModes", "DeprecatedFormContainer", "DeprecatedFormInput", "ScriptSettings", "settings", "t", "useTranslation", "SCRIPT_PLUGIN", "client", "useClient", "handleAuthenticate", "identityKey", "halo", "identity", "get", "writeCredentials", "issuer", "issuanceDate", "Date", "subject", "id", "assertion", "serverName", "serverKey", "capabilities", "DeprecatedFormContainer", "DeprecatedFormInput", "label", "Button", "onClick", "Select", "Root", "value", "editorInputMode", "onValueChange", "TriggerButton", "placeholder", "Portal", "Content", "Viewport", "EditorInputModes", "map", "mode", "Option", "key", "Octokit", "React", "useCallback", "useEffect", "useState", "createIntent", "SettingsAction", "useIntentDispatcher", "FunctionType", "getInvocationUrl", "getUserFunctionUrlInMetadata", "log", "useClient", "Filter", "getMeta", "getSpace", "useQuery", "Button", "Clipboard", "Input", "Separator", "
|
|
6
|
+
"names": ["React", "useClient", "Button", "Select", "useTranslation", "EditorInputModes", "DeprecatedFormContainer", "DeprecatedFormInput", "ScriptSettings", "settings", "t", "useTranslation", "SCRIPT_PLUGIN", "client", "useClient", "handleAuthenticate", "identityKey", "halo", "identity", "get", "writeCredentials", "issuer", "issuanceDate", "Date", "subject", "id", "assertion", "serverName", "serverKey", "capabilities", "DeprecatedFormContainer", "DeprecatedFormInput", "label", "Button", "onClick", "Select", "Root", "value", "editorInputMode", "onValueChange", "TriggerButton", "placeholder", "Portal", "Content", "Viewport", "EditorInputModes", "map", "mode", "Option", "key", "Octokit", "React", "useCallback", "useEffect", "useState", "createIntent", "SettingsAction", "useIntentDispatcher", "FunctionType", "getInvocationUrl", "getUserFunctionUrlInMetadata", "log", "useClient", "Filter", "getMeta", "getSpace", "useQuery", "Button", "Clipboard", "Input", "Separator", "useControlledState", "useTranslation", "AccessTokenType", "kebabize", "str", "replace", "$", "ofs", "toLowerCase", "ScriptSettingsPanel", "script", "t", "useTranslation", "SCRIPT_PLUGIN", "dispatchPromise", "dispatch", "useIntentDispatcher", "client", "useClient", "space", "getSpace", "fn", "useQuery", "Filter", "schema", "FunctionType", "source", "githubToken", "AccessTokenType", "gistKey", "getMeta", "keys", "find", "gistUrl", "setGistUrl", "useState", "useEffect", "token", "gistId", "id", "undefined", "timeout", "setTimeout", "octokit", "Octokit", "auth", "response", "request", "gist_id", "data", "html_url", "err", "log", "catch", "clearTimeout", "binding", "setBinding", "useControlledState", "handleBindingChange", "useCallback", "event", "target", "value", "handleBindingBlur", "functionPath", "getUserFunctionUrlInMetadata", "functionUrl", "getInvocationUrl", "config", "values", "runtime", "services", "edge", "url", "spaceId", "handleOpenTokenManager", "createIntent", "SettingsAction", "Open", "plugin", "publishing", "setPublishing", "handlePublish", "load", "filename", "name", "files", "content", "meta", "githubKey", "public", "push", "React", "div", "role", "className", "Input", "Root", "Label", "TextInput", "placeholder", "description", "onChange", "Separator", "h2", "disabled", "Clipboard", "IconButton", "onBlur", "p", "span", "Button", "onClick", "lazy", "AutomationPanel", "lazy", "ScriptContainer"]
|
|
7
7
|
}
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
ScriptContainer,
|
|
8
8
|
ScriptSettings,
|
|
9
9
|
ScriptSettingsPanel
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-F22QPQ6G.mjs";
|
|
11
11
|
import {
|
|
12
12
|
ScriptCapabilities
|
|
13
13
|
} from "./chunk-6MOQ4BP3.mjs";
|
|
@@ -23,8 +23,9 @@ import {
|
|
|
23
23
|
import { lazy } from "@dxos/app-framework";
|
|
24
24
|
var Compiler = lazy(() => import("./compiler-K3FNRDDN.mjs"));
|
|
25
25
|
var IntentResolver = lazy(() => import("./intent-resolver-CMKQTLBG.mjs"));
|
|
26
|
-
var ReactSurface = lazy(() => import("./react-surface-
|
|
26
|
+
var ReactSurface = lazy(() => import("./react-surface-YR4YO746.mjs"));
|
|
27
27
|
var ScriptSettings2 = lazy(() => import("./settings-SZCDKHWO.mjs"));
|
|
28
|
+
var Artifact = lazy(() => import("./artifact-3UZZBCZ2.mjs"));
|
|
28
29
|
|
|
29
30
|
// packages/plugins/experimental/plugin-script/src/ScriptPlugin.tsx
|
|
30
31
|
import { Capabilities, contributes, createIntent, defineModule, definePlugin, Events } from "@dxos/app-framework";
|
|
@@ -146,6 +147,11 @@ var ScriptPlugin = () => definePlugin(meta, [
|
|
|
146
147
|
id: `${meta.id}/module/intent-resolver`,
|
|
147
148
|
activatesOn: Events.SetupIntents,
|
|
148
149
|
activate: IntentResolver
|
|
150
|
+
}),
|
|
151
|
+
defineModule({
|
|
152
|
+
id: `${meta.id}/module/artifact`,
|
|
153
|
+
activatesOn: Events.Startup,
|
|
154
|
+
activate: Artifact
|
|
149
155
|
})
|
|
150
156
|
]);
|
|
151
157
|
export {
|