@dxos/plugin-script 0.8.4-main.f9ba587 → 0.8.4-main.fd6878d
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/{DeploymentDialog-RIGSJM6A.mjs → DeploymentDialog-C3XH2Z56.mjs} +4 -4
- package/dist/lib/browser/{ScriptContainer-BAN4WZHG.mjs → ScriptContainer-FUBR4OZE.mjs} +9 -7
- package/dist/lib/browser/ScriptContainer-FUBR4OZE.mjs.map +7 -0
- package/dist/lib/browser/{app-graph-builder-HLQ7K3BT.mjs → app-graph-builder-IABOSTBK.mjs} +2 -2
- package/dist/lib/{node-esm/app-graph-builder-7EYIHWH4.mjs.map → browser/app-graph-builder-IABOSTBK.mjs.map} +3 -3
- package/dist/lib/browser/{chunk-7CIKV2MG.mjs → chunk-G4A2MGAL.mjs} +9 -285
- package/dist/lib/browser/chunk-G4A2MGAL.mjs.map +7 -0
- package/dist/lib/browser/{chunk-EEL5O3IC.mjs → chunk-IS4OG2UW.mjs} +4 -5
- package/dist/lib/browser/chunk-IS4OG2UW.mjs.map +7 -0
- package/dist/lib/browser/chunk-MWZDJNCQ.mjs +283 -0
- package/dist/lib/browser/chunk-MWZDJNCQ.mjs.map +7 -0
- package/dist/lib/browser/{chunk-QHVTSNHD.mjs → chunk-OAVS36Q3.mjs} +3 -3
- package/dist/lib/browser/chunk-OAVS36Q3.mjs.map +7 -0
- package/dist/lib/browser/{chunk-QYLAH5AK.mjs → chunk-OULPWKXN.mjs} +8 -10
- package/dist/lib/browser/{chunk-QYLAH5AK.mjs.map → chunk-OULPWKXN.mjs.map} +3 -3
- package/dist/lib/browser/{chunk-OORJVKHC.mjs → chunk-SUOLJH55.mjs} +2 -2
- package/dist/lib/browser/{chunk-OORJVKHC.mjs.map → chunk-SUOLJH55.mjs.map} +2 -2
- package/dist/lib/browser/{compiler-CXCUA4UQ.mjs → compiler-RIWQVBPX.mjs} +4 -1
- package/dist/lib/browser/compiler-RIWQVBPX.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +15 -18
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/{intent-resolver-HQRUYTML.mjs → intent-resolver-SAL2TM7U.mjs} +9 -10
- package/dist/lib/browser/intent-resolver-SAL2TM7U.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-FNLARN5M.mjs → react-surface-E3SXU6ON.mjs} +8 -9
- package/dist/lib/browser/react-surface-E3SXU6ON.mjs.map +7 -0
- package/dist/lib/browser/{settings-XU54CGQD.mjs → settings-KCTBK5TY.mjs} +2 -2
- package/dist/lib/browser/templates/index.mjs +9 -0
- package/dist/lib/browser/types/index.mjs +10 -0
- package/dist/lib/node-esm/{DeploymentDialog-6Z7JH3VO.mjs → DeploymentDialog-O2XZVRLU.mjs} +4 -4
- package/dist/lib/node-esm/{ScriptContainer-RB5CSIZ7.mjs → ScriptContainer-VJ75TM24.mjs} +9 -7
- package/dist/lib/node-esm/ScriptContainer-VJ75TM24.mjs.map +7 -0
- package/dist/lib/node-esm/{app-graph-builder-7EYIHWH4.mjs → app-graph-builder-CQTTAYHP.mjs} +2 -2
- package/dist/lib/{browser/app-graph-builder-HLQ7K3BT.mjs.map → node-esm/app-graph-builder-CQTTAYHP.mjs.map} +3 -3
- package/dist/lib/node-esm/{chunk-ORZMINLO.mjs → chunk-3BBEM2U7.mjs} +9 -284
- package/dist/lib/node-esm/chunk-3BBEM2U7.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-HD6MDK3H.mjs → chunk-6WMFL3JL.mjs} +8 -10
- package/dist/lib/node-esm/{chunk-HD6MDK3H.mjs.map → chunk-6WMFL3JL.mjs.map} +3 -3
- package/dist/lib/node-esm/chunk-7L4JDSXJ.mjs +284 -0
- package/dist/lib/node-esm/chunk-7L4JDSXJ.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-YVJGDDNV.mjs → chunk-IO6T72KY.mjs} +3 -3
- package/dist/lib/node-esm/chunk-IO6T72KY.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-OVSJYR6O.mjs → chunk-JIPFLBYA.mjs} +4 -5
- package/dist/lib/node-esm/chunk-JIPFLBYA.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-ABAPR7VQ.mjs → chunk-PACUN7RS.mjs} +2 -2
- package/dist/lib/node-esm/{chunk-ABAPR7VQ.mjs.map → chunk-PACUN7RS.mjs.map} +2 -2
- package/dist/lib/node-esm/{compiler-EPFKQXPE.mjs → compiler-S52P5P3F.mjs} +4 -1
- package/dist/lib/node-esm/compiler-S52P5P3F.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +15 -18
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/{intent-resolver-XLV6FPWH.mjs → intent-resolver-GO53JOPL.mjs} +9 -10
- package/dist/lib/{browser/intent-resolver-HQRUYTML.mjs.map → node-esm/intent-resolver-GO53JOPL.mjs.map} +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{react-surface-BTYC7MGG.mjs → react-surface-W3NRCS5O.mjs} +8 -9
- package/dist/lib/node-esm/react-surface-W3NRCS5O.mjs.map +7 -0
- package/dist/lib/node-esm/{settings-QCMDG2MZ.mjs → settings-DXZ334A3.mjs} +2 -2
- package/dist/lib/node-esm/templates/index.mjs +10 -0
- package/dist/lib/node-esm/templates/index.mjs.map +7 -0
- package/dist/lib/node-esm/{types.mjs → types/index.mjs} +3 -6
- package/dist/lib/node-esm/types/index.mjs.map +7 -0
- package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/capabilities/artifact-definition.d.ts +1 -1
- package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -1
- package/dist/types/src/capabilities/compiler.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +0 -1
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/compiler/compiler.d.ts.map +1 -1
- package/dist/types/src/components/DeploymentDialog/index.d.ts +1 -1
- package/dist/types/src/components/DeploymentDialog/index.d.ts.map +1 -1
- package/dist/types/src/components/ScriptContainer.d.ts +3 -3
- package/dist/types/src/components/ScriptContainer.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.stories.d.ts.map +1 -1
- package/dist/types/src/components/TestPanel/TestContainer.d.ts +1 -1
- package/dist/types/src/components/TestPanel/TestContainer.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts.map +1 -1
- package/dist/types/src/hooks/deploy.d.ts +2 -2
- package/dist/types/src/hooks/deploy.d.ts.map +1 -1
- package/dist/types/src/hooks/useCreateAndDeployScriptTemplates.d.ts.map +1 -1
- package/dist/types/src/templates/data-generator.d.ts.map +1 -1
- package/dist/types/src/templates/index.d.ts +2 -0
- package/dist/types/src/templates/index.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +2 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +2 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- package/dist/types/src/{types.d.ts → types/schema.d.ts} +3 -5
- package/dist/types/src/types/schema.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +69 -58
- package/src/ScriptPlugin.tsx +2 -14
- package/src/capabilities/app-graph-builder.ts +2 -2
- package/src/capabilities/artifact-definition.ts +9 -12
- package/src/capabilities/compiler.ts +2 -1
- package/src/capabilities/index.ts +0 -1
- package/src/capabilities/intent-resolver.ts +2 -5
- package/src/capabilities/react-surface.tsx +4 -3
- package/src/compiler/compiler.ts +1 -1
- package/src/components/DeploymentDialog/DeploymentDialog.tsx +4 -4
- package/src/components/DeploymentDialog/index.ts +1 -1
- package/src/components/FrameContainer/frame.tsx +1 -1
- package/src/components/ScriptContainer.tsx +6 -4
- package/src/components/ScriptToolbar/ScriptToolbar.stories.tsx +2 -1
- package/src/components/ScriptToolbar/ScriptToolbar.tsx +2 -2
- package/src/components/Settings/ScriptObjectSettings.tsx +2 -2
- package/src/components/TestPanel/TestContainer.tsx +4 -3
- package/src/components/TypescriptEditor/TypescriptEditor.stories.tsx +2 -1
- package/src/components/TypescriptEditor/TypescriptEditor.tsx +3 -2
- package/src/hooks/deploy.ts +1 -1
- package/src/hooks/template.ts +1 -1
- package/src/hooks/useCreateAndDeployScriptTemplates.ts +1 -0
- package/src/templates/chess.ts +1 -1
- package/src/templates/data-generator.ts +8 -4
- package/src/templates/discord.ts +2 -2
- package/src/templates/forex-effect.ts +1 -1
- package/src/templates/forex.ts +1 -1
- package/src/templates/gmail.ts +4 -4
- package/src/templates/index.ts +2 -0
- package/src/translations.ts +2 -0
- package/src/types/index.ts +5 -0
- package/src/{types.ts → types/schema.ts} +2 -7
- package/dist/lib/browser/ScriptContainer-BAN4WZHG.mjs.map +0 -7
- package/dist/lib/browser/artifact-definition-KMBAZFRR.mjs +0 -249
- package/dist/lib/browser/artifact-definition-KMBAZFRR.mjs.map +0 -7
- package/dist/lib/browser/chunk-7CIKV2MG.mjs.map +0 -7
- package/dist/lib/browser/chunk-EEL5O3IC.mjs.map +0 -7
- package/dist/lib/browser/chunk-QHVTSNHD.mjs.map +0 -7
- package/dist/lib/browser/compiler-CXCUA4UQ.mjs.map +0 -7
- package/dist/lib/browser/react-surface-FNLARN5M.mjs.map +0 -7
- package/dist/lib/browser/types.mjs +0 -13
- package/dist/lib/node-esm/ScriptContainer-RB5CSIZ7.mjs.map +0 -7
- package/dist/lib/node-esm/artifact-definition-EBLXG5AR.mjs +0 -250
- package/dist/lib/node-esm/artifact-definition-EBLXG5AR.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ORZMINLO.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-OVSJYR6O.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-YVJGDDNV.mjs.map +0 -7
- package/dist/lib/node-esm/compiler-EPFKQXPE.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-XLV6FPWH.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-BTYC7MGG.mjs.map +0 -7
- package/dist/types/src/types.d.ts.map +0 -1
- /package/dist/lib/browser/{DeploymentDialog-RIGSJM6A.mjs.map → DeploymentDialog-C3XH2Z56.mjs.map} +0 -0
- /package/dist/lib/browser/{settings-XU54CGQD.mjs.map → settings-KCTBK5TY.mjs.map} +0 -0
- /package/dist/lib/browser/{types.mjs.map → templates/index.mjs.map} +0 -0
- /package/dist/lib/{node-esm/DeploymentDialog-6Z7JH3VO.mjs.map → browser/types/index.mjs.map} +0 -0
- /package/dist/lib/node-esm/{types.mjs.map → DeploymentDialog-O2XZVRLU.mjs.map} +0 -0
- /package/dist/lib/node-esm/{settings-QCMDG2MZ.mjs.map → settings-DXZ334A3.mjs.map} +0 -0
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/ScriptContainer.tsx", "../../../src/components/ScriptToolbar/ScriptToolbar.tsx", "../../../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 { createDataExtensions, listener, stackItemContentEditorClassNames } from '@dxos/react-ui-editor';\nimport { StackItem, type StackItemContentProps } from '@dxos/react-ui-stack';\n\nimport { ScriptToolbar } from './ScriptToolbar';\nimport { TypescriptEditor, type TypescriptEditorProps } from './TypescriptEditor';\nimport { useDeployState, useToolbarState } from '../hooks';\nimport { type ScriptSettingsProps } from '../types';\n\nexport type ScriptEditorProps = Pick<StackItemContentProps, 'role'> & {\n script: ScriptType;\n settings?: ScriptSettingsProps;\n} & Pick<TypescriptEditorProps, 'env'>;\n\nexport const ScriptContainer = ({ role, script, settings = { editorInputMode: 'vscode' }, env }: ScriptEditorProps) => {\n const identity = useIdentity();\n const space = getSpace(script);\n const state = useToolbarState();\n useDeployState({ state, script });\n\n const extensions = useMemo(\n () =>\n script.source.target\n ? [\n listener({\n onChange: (text) => {\n if (script.source.target?.content !== text) {\n script.changed = true;\n }\n },\n }),\n createDataExtensions({\n id: script.id,\n text: createDocAccessor(script.source.target, ['content']),\n space,\n identity,\n }),\n ]\n : [],\n [identity, space, script, script.source.target],\n );\n\n return (\n <StackItem.Content toolbar>\n <ScriptToolbar state={state} role={role} script={script} />\n <TypescriptEditor\n id={script.id}\n env={env}\n initialValue={script.source?.target?.content}\n extensions={extensions}\n classNames={stackItemContentEditorClassNames(role)}\n inputMode={settings.editorInputMode}\n toolbar\n />\n </StackItem.Content>\n );\n};\n\nexport default ScriptContainer;\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { Rx } from '@effect-rx/rx-react';\nimport React, { useMemo } from 'react';\n\nimport { type ScriptType } from '@dxos/functions';\nimport { fullyQualifiedId } from '@dxos/react-client/echo';\nimport { ElevationProvider, useTranslation, type ThemedClassName } from '@dxos/react-ui';\nimport { createGapSeparator, MenuProvider, rxFromSignal, ToolbarMenu, useMenuActions } from '@dxos/react-ui-menu';\n\nimport {\n type CreateDeployOptions,\n type ScriptToolbarState,\n createDeploy,\n createFormat,\n createTemplateSelect,\n useDeployDeps,\n} from '../../hooks';\nimport { SCRIPT_PLUGIN } from '../../meta';\n\nconst createToolbar = ({ state, script, ...options }: CreateDeployOptions) =>\n Rx.make((get) =>\n get(\n rxFromSignal(() => {\n const templateSelect = createTemplateSelect(script);\n const format = createFormat(script);\n const gap = createGapSeparator();\n const deploy = createDeploy({ state, script, ...options });\n return {\n nodes: [...templateSelect.nodes, ...format.nodes, ...gap.nodes, ...deploy.nodes],\n edges: [...templateSelect.edges, ...format.edges, ...gap.edges, ...deploy.edges],\n };\n }),\n ),\n );\n\nexport type ScriptToolbarProps = ThemedClassName<{\n role?: string;\n script: ScriptType;\n state: ScriptToolbarState;\n}>;\n\nexport const ScriptToolbar = ({ script, role, state, classNames }: ScriptToolbarProps) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n const options = useDeployDeps({ script });\n const toolbarCreator = useMemo(() => createToolbar({ state, script, t, ...options }), [state, script, options, t]);\n const menu = useMenuActions(toolbarCreator);\n\n return (\n <ElevationProvider elevation={role === 'section' ? 'positioned' : 'base'}>\n <MenuProvider {...menu} attendableId={fullyQualifiedId(script)}>\n <ToolbarMenu classNames={classNames} />\n </MenuProvider>\n </ElevationProvider>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { javascript } from '@codemirror/lang-javascript';\nimport { defaultHighlightStyle } from '@codemirror/language';\nimport { lintKeymap } from '@codemirror/lint';\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 ThemedClassName, type ThemeMode, useThemeContext } from '@dxos/react-ui';\nimport {\n type EditorInputMode,\n InputModeExtensions,\n type UseTextEditorProps,\n autocomplete,\n createBasicExtensions,\n createThemeExtensions,\n folding,\n useTextEditor,\n} from '@dxos/react-ui-editor';\nimport { mx } from '@dxos/react-ui-theme';\nimport { isNonNullable } from '@dxos/util';\n\nexport type TypescriptEditorProps = ThemedClassName<\n {\n id: string;\n inputMode?: EditorInputMode;\n toolbar?: boolean;\n env?: VirtualTypeScriptEnvironment;\n } & Pick<UseTextEditorProps, 'initialValue' | 'extensions' | 'scrollTo' | 'selection'>\n>;\n\nexport const TypescriptEditor = ({\n classNames,\n id,\n inputMode = 'vscode',\n toolbar,\n env,\n initialValue,\n extensions,\n scrollTo,\n selection,\n}: TypescriptEditorProps) => {\n const { themeMode } = useThemeContext();\n const { parentRef, focusAttributes } = useTextEditor(\n () => ({\n id,\n initialValue,\n selection,\n scrollTo,\n extensions: [\n extensions,\n createBasicExtensions({\n highlightActiveLine: true,\n indentWithTab: true,\n lineNumbers: true,\n lineWrapping: false,\n monospace: true,\n scrollPastEnd: true,\n }),\n createThemeExtensions({ themeMode, syntaxHighlighting: true }),\n InputModeExtensions[inputMode],\n folding(),\n // Continues block comments when pressing Enter.\n Prec.high(keymap.of(continueKeymap)),\n\n // TODO(burdon): Factor out.\n javascript({ typescript: true }),\n // https://github.com/val-town/codemirror-ts\n autocomplete({ override: env ? [tsAutocomplete()] : undefined }),\n keymap.of(lintKeymap),\n env && [\n tsFacet.of({ env, path: `/src/${id}.ts` }),\n tsSync(),\n tsLinter(),\n tsHover({ renderTooltip: createTooltipRenderer(themeMode) }),\n ],\n ].filter(isNonNullable),\n }),\n [id, extensions, themeMode, inputMode, selection, scrollTo],\n );\n\n return (\n <div\n ref={parentRef}\n data-toolbar={toolbar ? 'enabled' : 'disabled'}\n className={mx(classNames)}\n {...focusAttributes}\n />\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,gBAAgB;AAC5C,SAASC,mBAAmB;AAC5B,SAASC,sBAAsBC,UAAUC,wCAAwC;AACjF,SAASC,iBAA6C;;;;ACNtD,SAASC,UAAU;AACnB,OAAOC,SAASC,eAAe;AAG/B,SAASC,wBAAwB;AACjC,SAASC,mBAAmBC,sBAA4C;AACxE,SAASC,oBAAoBC,cAAcC,cAAcC,aAAaC,sBAAsB;AAY5F,IAAMC,gBAAgB,CAAC,EAAEC,OAAOC,QAAQ,GAAGC,QAAAA,MACzCC,GAAGC,KAAK,CAACC,QACPA,IACEC,aAAa,MAAA;AACX,QAAMC,iBAAiBC,qBAAqBP,MAAAA;AAC5C,QAAMQ,SAASC,aAAaT,MAAAA;AAC5B,QAAMU,MAAMC,mBAAAA;AACZ,QAAMC,SAASC,aAAa;IAAEd;IAAOC;IAAQ,GAAGC;EAAQ,CAAA;AACxD,SAAO;IACLa,OAAO;SAAIR,eAAeQ;SAAUN,OAAOM;SAAUJ,IAAII;SAAUF,OAAOE;;IAC1EC,OAAO;SAAIT,eAAeS;SAAUP,OAAOO;SAAUL,IAAIK;SAAUH,OAAOG;;EAC5E;AACF,CAAA,CAAA,CAAA;AAUC,IAAMC,gBAAgB,CAAC,EAAEhB,QAAQiB,MAAMlB,OAAOmB,WAAU,MAAsB;;;AACnF,UAAM,EAAEC,EAAC,IAAKC,eAAeC,aAAAA;AAC7B,UAAMpB,UAAUqB,cAAc;MAAEtB;IAAO,CAAA;AACvC,UAAMuB,iBAAiBC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AkB,CAAC,EAAEC,MAAMC,QAAQC,WAAW;EAAEC,iBAAiB;AAAS,GAAGC,IAAG,MAAqB;;;AAChH,UAAMC,WAAWC,YAAAA;AACjB,UAAMC,QAAQC,SAASP,MAAAA;AACvB,UAAMQ,QAAQC,gBAAAA;AACdC,mBAAe;MAAEF;MAAOR;IAAO,CAAA;AAE/B,UAAMW,aAAaC,SACjB,MACEZ,OAAOa,OAAOC,SACV;MACEC,SAAS;QACPC,UAAU,CAACC,SAAAA;AACT,cAAIjB,OAAOa,OAAOC,QAAQI,YAAYD,MAAM;AAC1CjB,mBAAOmB,UAAU;UACnB;QACF;MACF,CAAA;MACAC,qBAAqB;QACnBC,IAAIrB,OAAOqB;QACXJ,MAAMK,kBAAkBtB,OAAOa,OAAOC,QAAQ;UAAC;SAAU;QACzDR;QACAF;MACF,CAAA;QAEF,CAAA,GACN;MAACA;MAAUE;MAAON;MAAQA,OAAOa,OAAOC;KAAO;AAGjD,WACE,gBAAAS,OAAA,cAACC,UAAUC,SAAO;MAACC,SAAAA;OACjB,gBAAAH,OAAA,cAACI,eAAAA;MAAcnB;MAAcT;MAAYC;QACzC,gBAAAuB,OAAA,cAACK,kBAAAA;MACCP,IAAIrB,OAAOqB;MACXlB;MACA0B,cAAc7B,OAAOa,QAAQC,QAAQI;MACrCP;MACAmB,YAAYC,iCAAiChC,IAAAA;MAC7CiC,WAAW/B,SAASC;MACpBwB,SAAAA;;;;;AAIR;AAEA,IAAA,0BAAe5B;",
|
|
6
|
-
"names": ["React", "useMemo", "createDocAccessor", "getSpace", "useIdentity", "createDataExtensions", "listener", "stackItemContentEditorClassNames", "StackItem", "Rx", "React", "useMemo", "fullyQualifiedId", "ElevationProvider", "useTranslation", "createGapSeparator", "MenuProvider", "rxFromSignal", "ToolbarMenu", "useMenuActions", "createToolbar", "state", "script", "options", "Rx", "make", "get", "rxFromSignal", "templateSelect", "createTemplateSelect", "format", "createFormat", "gap", "createGapSeparator", "deploy", "createDeploy", "nodes", "edges", "ScriptToolbar", "role", "classNames", "t", "useTranslation", "SCRIPT_PLUGIN", "useDeployDeps", "toolbarCreator", "useMemo", "menu", "useMenuActions", "ElevationProvider", "elevation", "MenuProvider", "attendableId", "fullyQualifiedId", "ToolbarMenu", "javascript", "defaultHighlightStyle", "lintKeymap", "Prec", "oneDarkHighlightStyle", "keymap", "tags", "continueKeymap", "tsSync", "tsFacet", "tsLinter", "tsAutocomplete", "tsHover", "React", "useThemeContext", "InputModeExtensions", "autocomplete", "createBasicExtensions", "createThemeExtensions", "folding", "useTextEditor", "mx", "isNonNullable", "TypescriptEditor", "classNames", "id", "inputMode", "toolbar", "env", "initialValue", "extensions", "scrollTo", "selection", "themeMode", "useThemeContext", "parentRef", "focusAttributes", "useTextEditor", "createBasicExtensions", "highlightActiveLine", "indentWithTab", "lineNumbers", "lineWrapping", "monospace", "scrollPastEnd", "createThemeExtensions", "syntaxHighlighting", "InputModeExtensions", "folding", "Prec", "high", "keymap", "of", "continueKeymap", "javascript", "typescript", "autocomplete", "override", "tsAutocomplete", "undefined", "lintKeymap", "tsFacet", "path", "tsSync", "tsLinter", "tsHover", "renderTooltip", "createTooltipRenderer", "filter", "isNonNullable", "React", "div", "ref", "data-toolbar", "className", "mx", "theme", "oneDarkHighlightStyle", "defaultHighlightStyle", "classFromKind", "_kind", "kind", "endsWith", "validTag", "tags", "tag", "style", "info", "document", "createElement", "quickInfo", "displayParts", "part", "span", "appendChild", "innerText", "text", "dom", "ScriptContainer", "role", "script", "settings", "editorInputMode", "env", "identity", "useIdentity", "space", "getSpace", "state", "useToolbarState", "useDeployState", "extensions", "useMemo", "source", "target", "listener", "onChange", "text", "content", "changed", "createDataExtensions", "id", "createDocAccessor", "React", "StackItem", "Content", "toolbar", "ScriptToolbar", "TypescriptEditor", "initialValue", "classNames", "stackItemContentEditorClassNames", "inputMode"]
|
|
7
|
-
}
|
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
meta
|
|
4
|
-
} from "./chunk-AHXJ6NQU.mjs";
|
|
5
|
-
|
|
6
|
-
// src/capabilities/artifact-definition.ts
|
|
7
|
-
import { Schema } from "effect";
|
|
8
|
-
import { createTool, ToolResult } from "@dxos/ai";
|
|
9
|
-
import { Capabilities, contributes, createIntent } from "@dxos/app-framework";
|
|
10
|
-
import { ArtifactId, defineArtifact } from "@dxos/artifact";
|
|
11
|
-
import { createArtifactElement } from "@dxos/assistant";
|
|
12
|
-
import { Filter, Obj, Ref } from "@dxos/echo";
|
|
13
|
-
import { ScriptType } from "@dxos/functions";
|
|
14
|
-
import { invariant } from "@dxos/invariant";
|
|
15
|
-
import { SpaceAction } from "@dxos/plugin-space/types";
|
|
16
|
-
import { DataType } from "@dxos/schema";
|
|
17
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-script/src/capabilities/artifact-definition.ts";
|
|
18
|
-
var artifact_definition_default = () => {
|
|
19
|
-
const definition = defineArtifact({
|
|
20
|
-
id: `artifact:${meta.id}`,
|
|
21
|
-
name: meta.name,
|
|
22
|
-
// TODO(dmaretskyi): Since writing scripts requires a lot of domain knowledge,
|
|
23
|
-
// we should offload the work of synthesizing the code to a separate model.
|
|
24
|
-
// The main reasoning model will give it a concrete task and the script model will synthesize the code, knowing all the docs.
|
|
25
|
-
instructions: `
|
|
26
|
-
If the user explicitly requests you to write a script, you can create one.
|
|
27
|
-
If the user requests you to change one of the existing script, you can update it.
|
|
28
|
-
You must not create a script unless the user explicitly requests it.
|
|
29
|
-
Scripts are short code pieces of executable code that can be used to perform computations, integrate with external systems, and perform automated tasks.
|
|
30
|
-
Each script must follow as strict shape for the definition but the body can contain any valid executable code.
|
|
31
|
-
Scripts are written in JavaScript or TypeScript.
|
|
32
|
-
Each script must define an input schema and output schema.
|
|
33
|
-
Each script must have its own detailed description.
|
|
34
|
-
|
|
35
|
-
Important: You cannot execute scripts. Scripts are only available as tools after the user deploys them. You must only call the available tools.
|
|
36
|
-
|
|
37
|
-
Description:
|
|
38
|
-
The description is a detailed description of the script.
|
|
39
|
-
It is used to describe the script's purpose, input, and output.
|
|
40
|
-
The description is used to generate the script's documentation.
|
|
41
|
-
The description is also goes into the script metadata.
|
|
42
|
-
The description is used by AI to understand the script and its purpose.
|
|
43
|
-
The description must provide cases on when the script should be used.
|
|
44
|
-
|
|
45
|
-
Schema:
|
|
46
|
-
The schema is defined using a schema-DSL library called Effect Schema.
|
|
47
|
-
The input schema describes the arguments that the script accepts.
|
|
48
|
-
The output schema describes the result that the script produces.
|
|
49
|
-
The schema is used to validate the script's input and output.
|
|
50
|
-
The schema is also goes into the script metadata.
|
|
51
|
-
The properties in the schema must have valid descriptions.
|
|
52
|
-
The input and output schemas must both be a struct of fields.
|
|
53
|
-
|
|
54
|
-
Restricts:
|
|
55
|
-
The scripts can only import code from "dxos:functions" module. No other modules are allowed.
|
|
56
|
-
Some web APIs are available - like fetch.
|
|
57
|
-
|
|
58
|
-
Reasoning:
|
|
59
|
-
Before writing a script, synthesize the following information:
|
|
60
|
-
- Description
|
|
61
|
-
- What APIs will be used.
|
|
62
|
-
- Detailed input schema
|
|
63
|
-
- Detailed output schema
|
|
64
|
-
|
|
65
|
-
<apis>
|
|
66
|
-
export function defineFunction(params: {
|
|
67
|
-
description: string,
|
|
68
|
-
inputSchema: Schema.Schema,
|
|
69
|
-
outputSchema: Schema.Schema,
|
|
70
|
-
handler: (params: { event: { data: TInput } }) => Promise<TOutput>
|
|
71
|
-
}): FunctionDefinition
|
|
72
|
-
/**
|
|
73
|
-
* Effect Schema
|
|
74
|
-
*/
|
|
75
|
-
export const Schema;
|
|
76
|
-
|
|
77
|
-
// Examples:
|
|
78
|
-
|
|
79
|
-
Schema.String
|
|
80
|
-
Schema.Number
|
|
81
|
-
Schema.Boolean
|
|
82
|
-
Schema.Struct({
|
|
83
|
-
from: Schema.String.annotations({ description: 'The source currency' }),
|
|
84
|
-
to: Schema.String.annotations({ description: 'The target currency' }),
|
|
85
|
-
})
|
|
86
|
-
Schema.Array(Schema.String)
|
|
87
|
-
Schema.Union(Schema.String, Schema.Number)
|
|
88
|
-
Schema.optional(Schema.String)
|
|
89
|
-
Schema.String.annotations({ description: 'The source currency' })
|
|
90
|
-
</apis>
|
|
91
|
-
|
|
92
|
-
<handler_function>
|
|
93
|
-
Async function that takes the argument in the form of:
|
|
94
|
-
|
|
95
|
-
type HandlerFunctionParam = {
|
|
96
|
-
event: {
|
|
97
|
-
data: T // The input schema
|
|
98
|
-
},
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
The function must return the result that matches the output schema.
|
|
102
|
-
</handler_function>
|
|
103
|
-
|
|
104
|
-
<example>
|
|
105
|
-
import { defineFunction, S } from 'dxos:functions';
|
|
106
|
-
|
|
107
|
-
export default defineFunction({
|
|
108
|
-
description: 'Returns the exchange rate between two currencies.',
|
|
109
|
-
|
|
110
|
-
inputSchema: Schema.Struct({
|
|
111
|
-
from: Schema.String.annotations({ description: 'The source currency' }),
|
|
112
|
-
to: Schema.String.annotations({ description: 'The target currency' }),
|
|
113
|
-
}),
|
|
114
|
-
|
|
115
|
-
outputSchema: Schema.Struct({
|
|
116
|
-
rate: Schema.String.annotations({ description: 'The exchange rate' }),
|
|
117
|
-
}),
|
|
118
|
-
|
|
119
|
-
handler: async ({
|
|
120
|
-
event: {
|
|
121
|
-
data: { from, to },
|
|
122
|
-
},
|
|
123
|
-
}: any) => {
|
|
124
|
-
const res = await fetch(\`https://free.ratesdb.com/v1/rates?from=\${from}&to=\${to}\`);
|
|
125
|
-
const {
|
|
126
|
-
data: { rates },
|
|
127
|
-
} = await res.json();
|
|
128
|
-
|
|
129
|
-
return { rate: rates[to].toString() };
|
|
130
|
-
},
|
|
131
|
-
});
|
|
132
|
-
</example>
|
|
133
|
-
`,
|
|
134
|
-
schema: ScriptType,
|
|
135
|
-
tools: [
|
|
136
|
-
createTool(meta.id, {
|
|
137
|
-
name: "create",
|
|
138
|
-
description: "Create a new script. Returns the artifact definition for the script",
|
|
139
|
-
caption: "Creating script...",
|
|
140
|
-
schema: Schema.Struct({
|
|
141
|
-
name: Schema.String.annotations({
|
|
142
|
-
description: "The name of the script"
|
|
143
|
-
}),
|
|
144
|
-
code: Schema.String.annotations({
|
|
145
|
-
description: "The full code of the script in JavaScript or TypeScript. Must be valid executable code."
|
|
146
|
-
})
|
|
147
|
-
}),
|
|
148
|
-
execute: async ({ name, code }, { extensions }) => {
|
|
149
|
-
invariant(extensions?.space, "No space", {
|
|
150
|
-
F: __dxlog_file,
|
|
151
|
-
L: 156,
|
|
152
|
-
S: void 0,
|
|
153
|
-
A: [
|
|
154
|
-
"extensions?.space",
|
|
155
|
-
"'No space'"
|
|
156
|
-
]
|
|
157
|
-
});
|
|
158
|
-
invariant(extensions?.dispatch, "No intent dispatcher", {
|
|
159
|
-
F: __dxlog_file,
|
|
160
|
-
L: 157,
|
|
161
|
-
S: void 0,
|
|
162
|
-
A: [
|
|
163
|
-
"extensions?.dispatch",
|
|
164
|
-
"'No intent dispatcher'"
|
|
165
|
-
]
|
|
166
|
-
});
|
|
167
|
-
const script = Obj.make(ScriptType, {
|
|
168
|
-
name,
|
|
169
|
-
source: Ref.make(Obj.make(DataType.Text, {
|
|
170
|
-
content: code
|
|
171
|
-
}))
|
|
172
|
-
});
|
|
173
|
-
extensions.space.db.add(script);
|
|
174
|
-
await extensions.space.db.flush();
|
|
175
|
-
const intent = createIntent(SpaceAction.AddObject, {
|
|
176
|
-
target: extensions.space,
|
|
177
|
-
object: script
|
|
178
|
-
});
|
|
179
|
-
const { data, error } = await extensions.dispatch(intent);
|
|
180
|
-
if (!data || error) {
|
|
181
|
-
return ToolResult.Error(error?.message ?? "Failed to create chess game");
|
|
182
|
-
}
|
|
183
|
-
return ToolResult.Success(createArtifactElement(script.id));
|
|
184
|
-
}
|
|
185
|
-
}),
|
|
186
|
-
createTool(meta.id, {
|
|
187
|
-
name: "inspect",
|
|
188
|
-
description: "Inspect a script. Returns the artifact definition for the script",
|
|
189
|
-
caption: "Inspecting script...",
|
|
190
|
-
schema: Schema.Struct({
|
|
191
|
-
id: ArtifactId
|
|
192
|
-
}),
|
|
193
|
-
execute: async ({ id }, { extensions }) => {
|
|
194
|
-
invariant(extensions?.space, "No space", {
|
|
195
|
-
F: __dxlog_file,
|
|
196
|
-
L: 186,
|
|
197
|
-
S: void 0,
|
|
198
|
-
A: [
|
|
199
|
-
"extensions?.space",
|
|
200
|
-
"'No space'"
|
|
201
|
-
]
|
|
202
|
-
});
|
|
203
|
-
const script = await extensions.space.db.query(Filter.ids(id)).first();
|
|
204
|
-
const { content } = await script.source.load();
|
|
205
|
-
return ToolResult.Success({
|
|
206
|
-
name: script.name,
|
|
207
|
-
code: content
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
}),
|
|
211
|
-
createTool(meta.id, {
|
|
212
|
-
name: "update",
|
|
213
|
-
description: "Update a script. Returns the artifact definition for the script",
|
|
214
|
-
caption: "Updating script...",
|
|
215
|
-
schema: Schema.Struct({
|
|
216
|
-
id: ArtifactId,
|
|
217
|
-
code: Schema.String.annotations({
|
|
218
|
-
description: "The full code of the script in JavaScript or TypeScript. Must be valid executable code."
|
|
219
|
-
})
|
|
220
|
-
}),
|
|
221
|
-
execute: async ({ id, code }, { extensions }) => {
|
|
222
|
-
invariant(extensions?.space, "No space", {
|
|
223
|
-
F: __dxlog_file,
|
|
224
|
-
L: 208,
|
|
225
|
-
S: void 0,
|
|
226
|
-
A: [
|
|
227
|
-
"extensions?.space",
|
|
228
|
-
"'No space'"
|
|
229
|
-
]
|
|
230
|
-
});
|
|
231
|
-
const script = await extensions.space.db.query(Filter.ids(id)).first();
|
|
232
|
-
const source = await script.source.load();
|
|
233
|
-
if (!source) {
|
|
234
|
-
return ToolResult.Error("Script not found");
|
|
235
|
-
}
|
|
236
|
-
source.content = code;
|
|
237
|
-
await extensions.space?.db.flush();
|
|
238
|
-
return ToolResult.Success({
|
|
239
|
-
name: script.name
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
})
|
|
243
|
-
]
|
|
244
|
-
});
|
|
245
|
-
return contributes(Capabilities.ArtifactDefinition, definition);
|
|
246
|
-
};
|
|
247
|
-
export {
|
|
248
|
-
artifact_definition_default as default
|
|
249
|
-
};
|
|
250
|
-
//# sourceMappingURL=artifact-definition-EBLXG5AR.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/capabilities/artifact-definition.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Schema } from 'effect';\n\nimport { createTool, ToolResult } from '@dxos/ai';\nimport { Capabilities, contributes, createIntent, type PromiseIntentDispatcher } from '@dxos/app-framework';\nimport { ArtifactId, defineArtifact } from '@dxos/artifact';\nimport { createArtifactElement } from '@dxos/assistant';\nimport { Filter, Obj, Ref } from '@dxos/echo';\nimport { ScriptType } from '@dxos/functions';\nimport { invariant } from '@dxos/invariant';\nimport { SpaceAction } from '@dxos/plugin-space/types';\nimport { type Space } from '@dxos/react-client/echo';\nimport { DataType } from '@dxos/schema';\n\nimport { meta } from '../meta';\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: `artifact:${meta.id}`,\n name: meta.name,\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 You must not create a script unless the user explicitly requests 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: Schema.Schema, \n outputSchema: Schema.Schema, \n handler: (params: { event: { data: TInput } }) => Promise<TOutput> \n }): FunctionDefinition\n /**\n * Effect Schema\n */\n export const Schema; \n\n // Examples: \n\n Schema.String\n Schema.Number\n Schema.Boolean\n Schema.Struct({\n from: Schema.String.annotations({ description: 'The source currency' }),\n to: Schema.String.annotations({ description: 'The target currency' }),\n })\n Schema.Array(Schema.String)\n Schema.Union(Schema.String, Schema.Number)\n Schema.optional(Schema.String)\n Schema.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: Schema.Struct({\n from: Schema.String.annotations({ description: 'The source currency' }),\n to: Schema.String.annotations({ description: 'The target currency' }),\n }),\n\n outputSchema: Schema.Struct({\n rate: Schema.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 createTool(meta.id, {\n name: 'create',\n description: 'Create a new script. Returns the artifact definition for the script',\n caption: 'Creating script...',\n schema: Schema.Struct({\n name: Schema.String.annotations({ description: 'The name of the script' }),\n code: Schema.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 = Obj.make(ScriptType, {\n name,\n source: Ref.make(\n Obj.make(DataType.Text, {\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 createTool(meta.id, {\n name: 'inspect',\n description: 'Inspect a script. Returns the artifact definition for the script',\n caption: 'Inspecting script...',\n schema: Schema.Struct({\n id: ArtifactId,\n }),\n execute: async ({ id }, { extensions }) => {\n invariant(extensions?.space, 'No space');\n\n const script = (await extensions.space.db.query(Filter.ids(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 createTool(meta.id, {\n name: 'update',\n description: 'Update a script. Returns the artifact definition for the script',\n caption: 'Updating script...',\n schema: Schema.Struct({\n id: ArtifactId,\n code: Schema.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(Filter.ids(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,cAAc;AAEvB,SAASC,YAAYC,kBAAkB;AACvC,SAASC,cAAcC,aAAaC,oBAAkD;AACtF,SAASC,YAAYC,sBAAsB;AAC3C,SAASC,6BAA6B;AACtC,SAASC,QAAQC,KAAKC,WAAW;AACjC,SAASC,kBAAkB;AAC3B,SAASC,iBAAiB;AAC1B,SAASC,mBAAmB;AAE5B,SAASC,gBAAgB;;AAWzB,IAAA,8BAAe,MAAA;AACb,QAAMC,aAAaC,eAAe;IAChCC,IAAI,YAAYC,KAAKD,EAAE;IACvBE,MAAMD,KAAKC;;;;IAIXC,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA6GdC,QAAQC;IACRC,OAAO;MACLC,WAAWN,KAAKD,IAAI;QAClBE,MAAM;QACNM,aAAa;QACbC,SAAS;QACTL,QAAQM,OAAOC,OAAO;UACpBT,MAAMQ,OAAOE,OAAOC,YAAY;YAAEL,aAAa;UAAyB,CAAA;UACxEM,MAAMJ,OAAOE,OAAOC,YAAY;YAC9BL,aAAa;UACf,CAAA;QACF,CAAA;QACAO,SAAS,OAAO,EAAEb,MAAMY,KAAI,GAAI,EAAEE,WAAU,MAAE;AAC5CC,oBAAUD,YAAYE,OAAO,YAAA;;;;;;;;;AAC7BD,oBAAUD,YAAYG,UAAU,wBAAA;;;;;;;;;AAChC,gBAAMC,SAASC,IAAIC,KAAKjB,YAAY;YAClCH;YACAqB,QAAQC,IAAIF,KACVD,IAAIC,KAAKG,SAASC,MAAM;cACtBC,SAASb;YACX,CAAA,CAAA;U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E,MAAMU,GAAGiB,MAAMC,OAAOC,IAAI/C,EAAAA,CAAAA,EAAKgD,MAAK;AACrE,gBAAMzB,SAAS,MAAMH,OAAOG,OAAO0B,KAAI;AACvC,cAAI,CAAC1B,QAAQ;AACX,mBAAOgB,WAAWC,MAAM,kBAAA;UAC1B;AAEAjB,iBAAOI,UAAUb;AACjB,gBAAME,WAAWE,OAAOU,GAAGE,MAAAA;AAE3B,iBAAOS,WAAWG,QAAQ;YACxBxC,MAAMkB,OAAOlB;UACf,CAAA;QACF;MACF,CAAA;;EAEJ,CAAA;AAEA,SAAOgD,YAAYC,aAAaC,oBAAoBtD,UAAAA;AACtD;",
|
|
6
|
-
"names": ["Schema", "createTool", "ToolResult", "Capabilities", "contributes", "createIntent", "ArtifactId", "defineArtifact", "createArtifactElement", "Filter", "Obj", "Ref", "ScriptType", "invariant", "SpaceAction", "DataType", "definition", "defineArtifact", "id", "meta", "name", "instructions", "schema", "ScriptType", "tools", "createTool", "description", "caption", "Schema", "Struct", "String", "annotations", "code", "execute", "extensions", "invariant", "space", "dispatch", "script", "Obj", "make", "source", "Ref", "DataType", "Text", "content", "db", "add", "flush", "intent", "createIntent", "SpaceAction", "AddObject", "target", "object", "data", "error", "ToolResult", "Error", "message", "Success", "createArtifactElement", "ArtifactId", "query", "Filter", "ids", "first", "load", "contributes", "Capabilities", "ArtifactDefinition"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/hooks/deploy.ts", "raw-loader:./chat.ts?raw", "raw-loader:./chess.ts?raw", "raw-loader:./data-generator.ts?raw", "raw-loader:./discord.ts?raw", "raw-loader:./echo.ts?raw", "raw-loader:./email.ts?raw", "raw-loader:./forex-effect.ts?raw", "raw-loader:./forex.ts?raw", "raw-loader:./gmail.ts?raw", "../../../src/templates/index.ts", "../../../src/hooks/useToolbarState.ts", "../../../src/hooks/format.ts", "../../../src/hooks/template.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { useEffect, useMemo } from 'react';\n\nimport { FunctionType, type ScriptType, getUserFunctionUrlInMetadata } from '@dxos/functions';\nimport { log } from '@dxos/log';\nimport { type Client, useClient } from '@dxos/react-client';\nimport { getMeta, getSpace, Query, Ref, type Space, useQuery } from '@dxos/react-client/echo';\nimport { type TFunction } from '@dxos/react-ui';\nimport { createMenuAction } from '@dxos/react-ui-menu';\nimport { errorMessageColors } from '@dxos/react-ui-theme';\n\nimport { SCRIPT_PLUGIN } from '../meta';\nimport { deployScript, getFunctionUrl, isScriptDeployed } from '../util';\n\nexport type DeployActionProperties = { type: 'deploy' } | { type: 'copy' };\n\nexport type DeployState = {\n deploying: boolean;\n deployed: boolean;\n functionUrl: string;\n error: string;\n};\n\nexport type CreateDeployOptions = {\n state: Partial<DeployState>;\n script: ScriptType;\n fn: FunctionType;\n space?: Space;\n existingFunctionUrl?: string;\n client: Client;\n t: TFunction;\n};\n\nexport const createDeploy = ({ state, script, space, fn, client, existingFunctionUrl, t }: CreateDeployOptions) => {\n // TODO(wittjosiah): Should this be an action?\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 classNames: state.error && errorMessageColors,\n });\n\n const deployAction = createMenuAction<DeployActionProperties>(\n 'deploy',\n async () => {\n if (!script.source || !space) {\n return;\n }\n\n state.error = undefined;\n state.deploying = true;\n\n const result = await deployScript({ script, client, space, fn, existingFunctionUrl });\n\n if (!result.success) {\n log.catch(result.error);\n state.error = t('upload failed label');\n }\n\n state.deploying = false;\n },\n {\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\n const copyAction = createMenuAction<DeployActionProperties>(\n 'copy',\n async () => {\n if (!state.functionUrl) {\n return;\n }\n await navigator.clipboard.writeText(state.functionUrl);\n },\n {\n type: 'copy',\n label: ['copy link label', { ns: SCRIPT_PLUGIN }],\n icon: 'ph--link--regular',\n disabled: !state.functionUrl,\n },\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\nexport const useDeployState = ({ state, script }: { state: Partial<DeployState>; script: ScriptType }) => {\n const { space, client, fn, existingFunctionUrl } = useDeployDeps({ script });\n useEffect(() => {\n if (!existingFunctionUrl) {\n return;\n }\n\n state.functionUrl = getFunctionUrl({\n script,\n fn,\n edgeUrl: client.config.values.runtime?.services?.edge?.url ?? '',\n });\n }, [existingFunctionUrl, space, fn, script, client.config.values.runtime?.services?.edge?.url]);\n\n useEffect(() => {\n state.deployed = isScriptDeployed({ script, fn });\n }, [script.changed, existingFunctionUrl, fn, script]);\n};\n\nexport const useDeployDeps = ({ script }: { script: ScriptType }) => {\n const space = getSpace(script);\n const [fn] = useQuery(space, Query.type(FunctionType, { source: Ref.make(script) }));\n const client = useClient();\n const existingFunctionUrl = useMemo(() => fn && getUserFunctionUrlInMetadata(getMeta(fn)), [fn]);\n return { space, fn, client, existingFunctionUrl };\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// @ts-ignore\nimport { transformServerSentEvents } from 'https://esm.sh/@dxos/script-toolbox?bundle=false';\n\n/**\n * Chatbot that answers questions based on the context data.\n */\nexport default async ({ data: { bodyText }, context: { space, ai } }: any) => {\n let parsedRequest: any;\n try {\n parsedRequest = JSON.parse(bodyText);\n } catch (err) {\n const answer = await ai.run('@cf/meta/llama-3.1-8b-instruct', {\n stream: true,\n prompt: `\n Using only the context data below to answer the user's question.\n If you cannot answer the question from the provided content, then reply with \"I don't know.\"\n\n CONTEXT:\n ${await getContext({ space })}\n\n QUESTION:\n ${bodyText}\n `,\n });\n return new Response(transformServerSentEvents(answer));\n }\n\n const promptId = parsedRequest.trigger.promptId;\n const promptObject = await space.crud.query({ id: promptId }).first();\n\n if (parsedRequest.data.objects.length !== 1) {\n return new Response('Message batches not supported.');\n }\n\n const messageId = parsedRequest.data.objects[0];\n let message;\n try {\n message = await space.crud.query({ id: messageId }).first();\n } catch (err) {\n return new Response('Message not replicated yet.', { status: 409 });\n }\n\n if (message.text.includes('--------')) {\n return new Response('Message was already processed.');\n }\n\n let prompt = promptObject.template;\n for (const input of promptObject.inputs) {\n let value: string | null = null;\n if (input.type === TemplateInputType.VALUE) {\n value = String(input.value);\n } else if (input.type === TemplateInputType.RETRIEVER) {\n value = await getContext({ space });\n } else if (input.type === TemplateInputType.PASS_THROUGH) {\n value = message.text;\n }\n if (value) {\n prompt = prompt.replaceAll(`{${input.name}}`, value);\n }\n }\n\n const answer = await ai.run('@cf/meta/llama-3.1-8b-instruct', {\n stream: false,\n prompt,\n });\n const response = { response: answer.response, prompt, message };\n const textWithAnswer = message.text + '\\n--------\\n\\n' + answer.response;\n await space.crud.update({ id: messageId }, { text: textWithAnswer });\n\n return new Response(JSON.stringify(response));\n};\n\nconst getContext = async ({ space }: any) => {\n let context = '';\n const { objects: docs } = await space.crud.query({ __typename: 'dxos.org/type/Document' }).run();\n for (const doc of docs) {\n const { content } = await space.crud.query({ id: doc.content }).first();\n context += content + '\\n\\n';\n }\n return context;\n};\n\nenum TemplateInputType {\n VALUE = 0,\n PASS_THROUGH = 1,\n RETRIEVER = 2,\n FUNCTION = 3,\n QUERY = 4,\n RESOLVER = 5,\n CONTEXT = 6,\n SCHEMA = 7,\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { defineFunction, S } from 'dxos:functions';\n// @ts-ignore\nimport { Chess } from 'https://esm.sh/chess.js@0.13.1?bundle=false';\n\nexport default defineFunction({\n description: 'Plays a random move in a chess game.',\n\n inputSchema: S.Struct({\n changedObjectId: S.String.annotations({\n description: 'The objects to play the game on.',\n }),\n player: S.optional(S.Literal('w', 'b')).annotations({\n description: 'The player to play the game as.',\n }),\n }),\n\n outputSchema: S.Struct({\n state: S.String.annotations({\n description: 'The state of the game as an ASCII art board.',\n }),\n }),\n\n handler: async ({ data: { changedObjectId, player = 'b' }, context: { space } }: any) => {\n const { pgn } = await space.db.query({ id: changedObjectId }).first();\n const game = new Chess();\n game.load_pgn(pgn);\n if (game.turn() !== player) {\n return new Response('Invalid turn', { status: 409 });\n }\n\n const moves = game.moves();\n const move = moves[Math.floor(Math.random() * moves.length)];\n if (!move) {\n return new Response('No legal moves', { status: 406 });\n }\n\n game.move(move);\n const newPgn = game.pgn();\n await space.db.update({ id: changedObjectId }, { pgn: newPgn, fen: game.fen() });\n return { state: game.ascii() };\n },\n});\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { defineFunction, S, create, Expando } from 'dxos:functions';\n// @ts-ignore\nimport { randText } from 'https://esm.sh/@ngneat/falso@7.1.1?bundle=false';\n\nexport default defineFunction({\n inputSchema: S.Struct({\n documentAmount: S.optional(S.Number),\n textSize: S.optional(S.Number),\n mutationAmount: S.optional(S.Number),\n }),\n\n outputSchema: S.Struct({}),\n\n handler: async ({ data: { documentAmount = 1, textSize = 10, mutationAmount = 0 }, context: { space } }: any) => {\n await space.db.graph.schemaRegistry.addSchema([Expando]);\n const result: Record<string, any> = {};\n const objects: Expando[] = [];\n\n // Create objects.\n for (let i = 0; i < documentAmount; i++) {\n const obj = space.db.add(\n create(Expando, {\n name: 'scriptGenerated',\n content: randText({ charCount: textSize }),\n }),\n );\n objects.push(obj);\n const objectResult: any = {};\n // Mutate the object.\n for (let i = 0; i < mutationAmount; i++) {\n obj.content = randText({ charCount: textSize });\n }\n objectResult.mutations = mutationAmount;\n objectResult.contentLength = obj.content.length;\n result[obj.id] = objectResult;\n }\n\n // Flush and wait for data to propagate.\n await space.db.flush();\n await new Promise((resolve) => setTimeout(resolve, 10_000));\n return result;\n },\n});\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { create, defineFunction, DXN, EchoObject, Filter, ObjectId, S } from 'dxos:functions';\n// @ts-ignore\nimport { FetchHttpClient } from 'https://esm.sh/@effect/platform@0.77.2?deps=effect@3.14.21&bundle=false';\nimport {\n DiscordConfig,\n DiscordREST,\n DiscordRESTMemoryLive,\n // @ts-ignore\n} from 'https://esm.sh/dfx@0.113.0?deps=effect@3.14.21&bundle=false';\n// @ts-ignore\nimport { Effect, Config, Redacted, Ref } from 'https://esm.sh/effect@3.14.21?bundle=false';\n\nconst MessageSchema = S.Struct({\n id: ObjectId,\n foreignId: S.Any, // bigint?\n from: S.String,\n created: S.String,\n content: S.String,\n}).pipe(\n EchoObject({\n typename: 'example.com/type/Message',\n version: '0.1.0',\n }),\n);\n\nconst DEFAULT_AFTER = 1704067200; // 2024-01-01\n\nconst generateSnowflake = (unixTimestamp: number): bigint => {\n const discordEpoch = 1420070400000n; // Discord Epoch (ms)\n return (BigInt(unixTimestamp * 1000) - discordEpoch) << 22n;\n};\n\nexport default defineFunction({\n inputSchema: S.Struct({\n // TODO(wittjosiah): Remove. This is used to provide a terminal for a cron trigger.\n tick: S.optional(S.String),\n channelId: S.String,\n after: S.optional(S.Number),\n pageSize: S.optional(S.Number),\n queueId: S.String,\n }),\n\n outputSchema: S.Struct({\n newMessages: S.Number,\n }),\n\n handler: ({ data: { channelId, queueId, after = DEFAULT_AFTER, pageSize = 5 }, context: { space } }: any) =>\n Effect.gen(function* () {\n const { token } = yield* Effect.tryPromise({\n try: () => space.db.query(Filter.typename('dxos.org/type/AccessToken', { source: 'discord.com' })).first(),\n catch: (e: any) => e,\n });\n const { objects } = yield* Effect.tryPromise({\n try: () => space.queues.queryQueue(DXN.parse(queueId)),\n catch: (e: any) => e,\n });\n const backfill = objects.length === 0;\n const newMessages = yield* Ref.make(0);\n const lastMessage = yield* Ref.make(objects.at(-1));\n\n const enqueueMessages = Effect.gen(function* () {\n const rest = yield* DiscordREST;\n\n while (true) {\n const last = yield* Ref.get(lastMessage);\n const options = {\n after: backfill && !last ? `${generateSnowflake(after)}` : last?.foreignId,\n limit: pageSize,\n };\n const messages = yield* rest.getChannelMessages(channelId, options).pipe((res: any) => res.json);\n const queueMessages = messages\n .map((message: any) =>\n create(MessageSchema, {\n id: ObjectId.random(),\n foreignId: message.id,\n from: message.author.username,\n created: message.timestamp,\n content: message.content,\n }),\n )\n .toReversed();\n if (queueMessages.length > 0) {\n yield* Effect.tryPromise({\n try: () => space.queues.insertIntoQueue(DXN.parse(queueId), queueMessages),\n catch: (e: any) => e,\n });\n yield* Ref.update(newMessages, (n: any) => n + queueMessages.length);\n yield* Ref.update(lastMessage, (m: any) => queueMessages.at(-1));\n }\n if (messages.length < pageSize) {\n break;\n }\n }\n }).pipe(\n Effect.provide(DiscordRESTMemoryLive),\n Effect.provide(\n DiscordConfig.layerConfig({\n token: Config.succeed(Redacted.make(token)),\n }),\n ),\n Effect.provide(FetchHttpClient.layer),\n );\n\n yield* enqueueMessages;\n return { newMessages: yield* Ref.get(newMessages) };\n }),\n});\n", "//\n// Copyright 2024 DXOS.org\n//\n\n/**\n * Echos the request data.\n */\nexport default async ({ data }: any) => data;\n", "//\n// Copyright 2024 DXOS.org\n//\n\n/**\n * Appends a message to the end of a Document configured through a trigger.\n * Trigger must have a targetDocumentId field set in Meta.\n */\nexport default async ({ data: { bodyText }, context: { space } }: any) => {\n const { email, targetDocumentId: documentId } = JSON.parse(bodyText) as RequestPayload;\n\n const document = await space.db.query({ id: documentId }).first();\n\n const contentId = document.content['/'].split(':')[3];\n const documentContent = await space.db.query({ id: contentId }).first();\n const modifiedContent = [\n documentContent.content,\n '',\n '---',\n `**From:** ${email.from}`,\n `**Subject:** ${email.subject}`,\n `**Date:** ${email.created}`,\n '',\n email.body,\n ].join('\\n');\n\n await space.db.update({ id: contentId }, { content: modifiedContent });\n\n return new Response(JSON.stringify({ success: true }));\n};\n\ntype RequestPayload = {\n email: { from: string; subject: string; created: string; body: string };\n targetDocumentId: string;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { S, defineFunction } from 'dxos:functions';\nimport {\n HttpClient,\n HttpClientRequest,\n FetchHttpClient,\n // @ts-ignore\n} from 'https://esm.sh/@effect/platform@0.77.2?deps=effect@3.14.21&bundle=false';\n// @ts-ignore\nimport { Effect, Schedule } from 'https://esm.sh/effect@3.14.21?bundle=false';\n\nexport 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.String.annotations({ description: 'The exchange rate between the two currencies' }),\n\n handler: async ({ data: { from, to } }: any) =>\n Effect.gen(function* () {\n const res = yield* HttpClientRequest.get(`https://free.ratesdb.com/v1/rates?from=${from}&to=${to}`).pipe(\n HttpClient.execute,\n Effect.flatMap((res: any) => res.json),\n Effect.timeout('1 second'),\n Effect.retry(Schedule.exponential(1_000).pipe(Schedule.compose(Schedule.recurs(3)))),\n Effect.scoped,\n );\n\n return res.data.rates[to].toString();\n }).pipe(Effect.provide(FetchHttpClient.layer)),\n});\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { defineFunction, S } from 'dxos:functions';\n\nexport 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 handler: async ({ data: { from, to } }: 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 rates[to].toString();\n },\n});\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport { create, defineFunction, EchoObject, Filter, ObjectId, S } from 'dxos:functions';\n// @ts-ignore\nimport {\n HttpClient,\n HttpClientRequest,\n FetchHttpClient,\n // @ts-ignore\n} from 'https://esm.sh/@effect/platform@0.77.2?deps=effect@3.14.21&bundle=false';\n// @ts-ignore\nimport { format, subDays } from 'https://esm.sh/date-fns@3.3.1?bundle=false';\n// @ts-ignore\nimport { pipe, Chunk, Effect, Ref, Schedule, Stream } from 'https://esm.sh/effect@3.14.21?bundle=false';\n\nexport default defineFunction({\n inputSchema: S.Struct({\n mailboxId: S.String,\n userId: S.optional(S.String).pipe(S.withDecodingDefault(() => 'me')),\n after: S.optional(S.Union(S.Number, S.String)).pipe(\n S.withDecodingDefault(() => format(subDays(new Date(), 30), 'yyyy-MM-dd')),\n ),\n pageSize: S.optional(S.Number).pipe(S.withDecodingDefault(() => 100)),\n // TODO(wittjosiah): Remove. This is used to provide a terminal for a cron trigger.\n tick: S.optional(S.String),\n }),\n\n outputSchema: S.Struct({\n newMessages: S.Number,\n }),\n\n handler: ({ context: { space }, data: { mailboxId, userId, after, pageSize } }: any) =>\n Effect.gen(function* () {\n const { token } = yield* Effect.tryPromise({\n try: () => space.db.query(Filter.typename('dxos.org/type/AccessToken', { source: 'gmail.com' })).first(),\n catch: (e: any) => e,\n });\n\n // NOTE: Google API bundles size is v. large and caused runtime issues.\n const makeRequest = (url: string) =>\n pipe(\n url,\n HttpClientRequest.get,\n HttpClientRequest.setHeaders({ Authorization: `Bearer ${token}`, Accept: 'application/json' }),\n HttpClient.execute,\n Effect.flatMap((res: any) => res.json),\n Effect.timeout('1 second'),\n Effect.retry(Schedule.exponential(1000).pipe(Schedule.compose(Schedule.recurs(3)))),\n Effect.scoped,\n );\n\n const listMessages = (userId: string, q: string, pageSize: number, pageToken: string | null) =>\n makeRequest(getUrl(userId, undefined, { q, pageSize, pageToken }));\n\n const getMessage = (userId: string, messageId: string) => makeRequest(getUrl(userId, messageId));\n\n const mailbox = yield* Effect.tryPromise({\n try: () => space.db.query({ id: mailboxId }).first(),\n catch: (e: any) => e,\n });\n const { objects } = yield* Effect.tryPromise({\n try: () => space.queues.queryQueue(mailbox.queue.dxn),\n catch: (e: any) => e,\n });\n const newMessages = yield* Ref.make([]);\n const nextPage = yield* Ref.make(null);\n\n do {\n const last = objects.at(-1);\n const q = last\n ? `in:inbox after:${Math.floor(new Date(last.created).getTime() / 1000)}`\n : `in:inbox after:${after}`;\n const pageToken = yield* Ref.get(nextPage);\n const { messages, nextPageToken } = yield* listMessages(userId, q, pageSize, pageToken);\n yield* Ref.update(nextPage, () => nextPageToken);\n for (const message of messages) {\n const messageDetails = yield* getMessage(userId, message.id);\n const created = new Date(parseInt(messageDetails.internalDate)).toISOString();\n const from = messageDetails.payload.headers.find((h: any) => h.name === 'From');\n const sender = from && parseEmailString(from.value);\n // TODO(wittjosiah): Improve parsing of email contents.\n const content =\n messageDetails.payload.body?.data ??\n messageDetails.payload.parts?.find((p: any) => p.mimeType === 'text/plain')?.body.data;\n // Skip the message if content or sender is missing.\n // Skip the message if it's the same as the last message.\n // TODO(wittjosiah): This comparison should be done via foreignId probably.\n if (!content || !sender || created === last?.created) {\n continue;\n }\n const subject = messageDetails.payload.headers.find((h: any) => h.name === 'Subject')?.value;\n const object = create(MessageType, {\n id: ObjectId.random(),\n created,\n sender,\n blocks: [\n {\n type: 'text',\n text: Buffer.from(content, 'base64').toString('utf-8'),\n },\n ],\n properties: {\n subject,\n threadId: message.threadId,\n },\n });\n // TODO(wittjosiah): Set foreignId in object meta.\n yield* Ref.update(newMessages, (n: any) => [object, ...n]);\n }\n } while (yield* Ref.get(nextPage));\n\n const queueMessages = yield* Ref.get(newMessages);\n if (queueMessages.length > 0) {\n yield* pipe(\n queueMessages,\n Stream.fromIterable,\n Stream.grouped(10),\n Stream.flatMap((batch: any) =>\n Effect.tryPromise({\n try: () => space.queues.insertIntoQueue(mailbox.queue.dxn, Chunk.toReadonlyArray(batch)),\n catch: (e: any) => e,\n }),\n ),\n Stream.runDrain,\n );\n }\n\n return { newMessages: queueMessages.length };\n }).pipe(Effect.provide(FetchHttpClient.layer)),\n});\n\nconst getUrl = (userId: string, messageId?: string, params?: Record<string, any>) => {\n const api = new URL(\n [`https://gmail.googleapis.com/gmail/v1/users/${userId}/messages`, messageId].filter(Boolean).join('/'),\n );\n Object.entries(params ?? {})\n .filter(([_, value]) => value != null)\n .forEach(([key, value]) => api.searchParams.set(key, value));\n return api.toString();\n};\n\n/**\n * Parses an email string in the format \"Name <email@example.com>\" into separate name and email components.\n */\nconst parseEmailString = (emailString: string): { name?: string; email: string } | undefined => {\n const match = emailString.match(/^([^<]+?)\\s*<([^>]+@[^>]+)>$/);\n if (match) {\n const [, name, email] = match;\n return {\n name: name.trim(),\n email: email.trim(),\n };\n }\n\n return undefined;\n};\n\n//\n// Schemas\n// TODO(wittjosiah): These schemas should be imported from @dxos/S.\n//\n\nconst ActorRoles = ['user', 'assistant'] as const;\nconst ActorRole = S.Literal(...ActorRoles);\ntype ActorRole = S.Schema.Type<typeof ActorRole>;\n\nconst ActorSchema = S.Struct({\n identityKey: S.optional(S.String),\n email: S.optional(S.String),\n name: S.optional(S.String),\n role: S.optional(ActorRole),\n});\n\nconst AbstractContentBlock = S.Struct({\n pending: S.optional(S.Boolean),\n});\ntype AbstractContentBlock = S.Schema.Type<typeof AbstractContentBlock>;\nconst TextContentBlock = S.extend(\n AbstractContentBlock,\n S.Struct({\n type: S.Literal('text'),\n disposition: S.optional(S.String),\n text: S.String,\n }),\n).pipe(S.mutable);\ntype TextContentBlock = S.Schema.Type<typeof TextContentBlock>;\nconst JsonContentBlock = S.extend(\n AbstractContentBlock,\n S.Struct({\n type: S.Literal('json'),\n disposition: S.optional(S.String),\n data: S.String,\n }),\n).pipe(S.mutable);\ntype JsonContentBlock = S.Schema.Type<typeof JsonContentBlock>;\nconst Base64ImageSource = S.Struct({\n type: S.Literal('base64'),\n mediaType: S.String,\n data: S.String,\n}).pipe(S.mutable);\nconst HttpImageSource = S.Struct({\n type: S.Literal('http'),\n url: S.String,\n}).pipe(S.mutable);\nconst ImageSource = S.Union(Base64ImageSource, HttpImageSource);\ntype ImageSource = S.Schema.Type<typeof ImageSource>;\nconst ImageContentBlock = S.extend(\n AbstractContentBlock,\n S.Struct({\n type: S.Literal('image'),\n id: S.optional(S.String),\n source: S.optional(ImageSource),\n }),\n).pipe(S.mutable);\ntype ImageContentBlock = S.Schema.Type<typeof ImageContentBlock>;\nconst ReferenceContentBlock = S.extend(\n AbstractContentBlock,\n S.Struct({\n type: S.Literal('reference'),\n reference: S.Any,\n }),\n).pipe(S.mutable);\ntype ReferenceContentBlock = S.Schema.Type<typeof ReferenceContentBlock>;\nconst MessageContentBlock = S.Union(TextContentBlock, JsonContentBlock, ImageContentBlock, ReferenceContentBlock);\n\nconst MessageType = S.Struct({\n id: ObjectId,\n created: S.String.annotations({\n description: 'ISO date string when the message was sent.',\n }),\n sender: ActorSchema.annotations({\n description: 'Identity of the message sender.',\n }),\n blocks: S.Array(MessageContentBlock).annotations({\n description: 'Contents of the message.',\n }),\n properties: S.optional(\n S.mutable(\n S.Record({ key: S.String, value: S.Any }).annotations({\n description: 'Custom properties for specific message types (e.g. attention context, email subject, etc.).',\n }),\n ),\n ),\n}).pipe(\n EchoObject({\n typename: 'dxos.org/type/Message',\n version: '0.2.0',\n }),\n);\ntype MessageType = S.Schema.Type<typeof MessageType>;\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport chat from './chat.ts?raw';\nimport chess from './chess.ts?raw';\nimport dataGenerator from './data-generator.ts?raw';\nimport discord from './discord.ts?raw';\nimport echo from './echo.ts?raw';\nimport email from './email.ts?raw';\nimport forexEffect from './forex-effect.ts?raw';\nimport forex from './forex.ts?raw';\nimport gmail from './gmail.ts?raw';\n\nconst removeHeader = (str: string) => str.split('\\n').slice(4).join('\\n');\n\nexport type Template = {\n id: string;\n name: string;\n source: string;\n presetId?: string;\n};\n\nexport const templates: Template[] = [\n {\n id: 'dxos.org/script/echo',\n name: 'Echo',\n source: removeHeader(echo),\n },\n {\n id: 'dxos.org/script/forex',\n name: 'Forex',\n source: removeHeader(forex),\n },\n {\n id: 'dxos.org/script/forex-effect',\n name: 'Forex (Effect)',\n source: removeHeader(forexEffect),\n },\n {\n id: 'dxos.org/script/gpt',\n name: 'Gpt',\n source: removeHeader(chat),\n presetId: 'dxos.org/function/gpt',\n },\n {\n id: 'dxos.org/script/chess',\n name: 'Chess',\n source: removeHeader(chess),\n presetId: 'dxos.org/function/chess',\n },\n {\n id: 'dxos.org/script/email',\n name: 'Email',\n source: removeHeader(email),\n presetId: 'dxos.org/function/email',\n },\n {\n id: 'dxos.org/script/discord',\n name: 'Discord',\n source: removeHeader(discord),\n presetId: 'dxos.org/function/discord',\n },\n {\n id: 'dxos.org/script/gmail',\n name: 'Gmail',\n source: removeHeader(gmail),\n presetId: 'dxos.org/function/gmail',\n },\n {\n id: 'dxos.org/script/data-generator',\n name: 'Data Generator',\n source: removeHeader(dataGenerator),\n presetId: 'dxos.org/function/data-generator',\n },\n];\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useMemo } from 'react';\n\nimport { live } from '@dxos/live-object';\n\nimport { type DeployState } from './deploy';\n\nexport type ScriptToolbarState = Partial<DeployState>;\n\n// TODO(burdon): Replace with context provider?\nexport const useToolbarState = (initialState: ScriptToolbarState = {}) => {\n return useMemo(() => live<ScriptToolbarState>(initialState), []);\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { format } from 'prettier';\nimport prettierPluginEstree from 'prettier/plugins/estree';\nimport prettierPluginTypescript from 'prettier/plugins/typescript';\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 = (script: ScriptType) => {\n const formatAction = createMenuAction(\n 'format',\n 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 },\n {\n label: ['format label', { ns: SCRIPT_PLUGIN }],\n icon: 'ph--magic-wand--regular',\n },\n );\n\n return {\n nodes: [formatAction],\n edges: [\n {\n source: 'root',\n target: 'format',\n },\n ],\n };\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Obj } from '@dxos/echo';\nimport { FUNCTIONS_PRESET_META_KEY, type ScriptType } from '@dxos/functions';\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 = (script: ScriptType) => {\n return templates.map((template) => {\n return createMenuAction<TemplateActionProperties>(\n `template--${template.id}`,\n () => {\n script.name = template.name;\n script.source!.target!.content = template.source;\n const metaKeys = Obj.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 label: template.name,\n value: template.id,\n type: 'template',\n },\n );\n });\n};\n\nexport const createTemplateSelect = (script: ScriptType) => {\n const templateSelectGroup = createTemplateSelectGroup();\n const templateSelectActions = createTemplateSelectActions(script);\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"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;AAIA,SAASA,WAAWC,eAAe;AAEnC,SAASC,cAA+BC,oCAAoC;AAC5E,SAASC,WAAW;AACpB,SAAsBC,iBAA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wBAAwB1B,4BAA4BC,MAAAA;AAC1D,SAAO;IACL0B,OAAO;MAACF;SAAwBC;;IAChCE,OAAO;MACL;QAAEpB,QAAQ;QAAQC,QAAQ;MAAkB;SACzCiB,sBAAsBvB,IAAI,CAAC0B,YAAY;QAAErB,QAAQ;QAAmBC,QAAQoB,OAAOvB;MAAG,EAAA;;EAE7F;AACF;",
|
|
6
|
-
"names": ["useEffect", "useMemo", "FunctionType", "getUserFunctionUrlInMetadata", "log", "useClient", "getMeta", "getSpace", "Query", "Ref", "useQuery", "createMenuAction", "errorMessageColors", "createDeploy", "state", "script", "space", "fn", "client", "existingFunctionUrl", "t", "errorItem", "createMenuAction", "label", "error", "ns", "SCRIPT_PLUGIN", "icon", "hidden", "classNames", "errorMessageColors", "deployAction", "source", "undefined", "deploying", "result", "deployScript", "success", "log", "catch", "type", "disabled", "copyAction", "functionUrl", "navigator", "clipboard", "writeText", "nodes", "edges", "target", "useDeployState", "useDeployDeps", "useEffect", "getFunctionUrl", "edgeUrl", "config", "values", "runtime", "services", "edge", "url", "deployed", "isScriptDeployed", "changed", "getSpace", "useQuery", "Query", "FunctionType", "Ref", "make", "useClient", "useMemo", "getUserFunctionUrlInMetadata", "getMeta", "removeHeader", "str", "split", "slice", "join", "templates", "id", "name", "source", "echo", "forex", "forexEffect", "chat", "presetId", "chess", "email", "discord", "gmail", "dataGenerator", "useMemo", "live", "useToolbarState", "initialState", "useMemo", "live", "format", "prettierPluginEstree", "prettierPluginTypescript", "log", "createMenuAction", "createFormat", "script", "formatAction", "createMenuAction", "source", "target", "content", "format", "parser", "plugins", "prettierPluginEstree", "prettierPluginTypescript", "semi", "singleQuote", "err", "log", "catch", "label", "ns", "SCRIPT_PLUGIN", "icon", "nodes", "edges", "Obj", "FUNCTIONS_PRESET_META_KEY", "createMenuItemGroup", "createMenuAction", "createTemplateSelectGroup", "createMenuItemGroup", "label", "ns", "SCRIPT_PLUGIN", "variant", "createTemplateSelectActions", "script", "templates", "map", "template", "createMenuAction", "id", "name", "source", "target", "content", "metaKeys", "Obj", "getMeta", "keys", "oldPresetIndex", "findIndex", "key", "FUNCTIONS_PRESET_META_KEY", "splice", "presetId", "push", "value", "type", "createTemplateSelect", "templateSelectGroup", "templateSelectActions", "nodes", "edges", "action"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/types.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { Schema } from 'effect';\n\nimport { SpaceSchema } from '@dxos/client/echo';\nimport { ScriptType } from '@dxos/functions';\nimport { EditorInputMode } from '@dxos/react-ui-editor';\n\nimport { SCRIPT_PLUGIN } from './meta';\n\n// TODO(burdon): Standardize export (e.g., @dxos/plugin-script/meta)?\nexport { SCRIPT_PLUGIN };\n\nexport namespace ScriptAction {\n const SCRIPT_ACTION = `${SCRIPT_PLUGIN}/action`;\n\n export const CreateScriptSchema = Schema.Struct({\n name: Schema.optional(Schema.String),\n // TODO(wittjosiah): Placeholder annotation?\n gistUrl: Schema.optional(Schema.String.annotations({ title: 'Import from Gist (url)' })),\n initialTemplateId: Schema.optional(Schema.String),\n });\n\n export type CreateScriptProps = Schema.Schema.Type<typeof CreateScriptSchema>;\n\n export class Create extends Schema.TaggedClass<Create>()(`${SCRIPT_ACTION}/create`, {\n input: Schema.extend(CreateScriptSchema, Schema.Struct({ space: SpaceSchema })),\n output: Schema.Struct({\n object: ScriptType,\n }),\n }) {}\n}\n\nexport const ScriptSettingsSchema = Schema.mutable(\n Schema.Struct({\n editorInputMode: EditorInputMode,\n }),\n);\n\nexport type ScriptSettingsProps = Schema.Schema.Type<typeof ScriptSettingsSchema>;\n"],
|
|
5
|
-
"mappings": ";;;;;;AAIA,SAASA,cAAc;AAEvB,SAASC,mBAAmB;AAC5B,SAASC,kBAAkB;AAC3B,SAASC,uBAAuB;UAOfC,eAAAA;AACf,QAAMC,gBAAgB,GAAGC,aAAAA;gBAEZC,qBAAqBC,OAAOC,OAAO;IAC9CC,MAAMF,OAAOG,SAASH,OAAOI,MAAM;;IAEnCC,SAASL,OAAOG,SAASH,OAAOI,OAAOE,YAAY;MAAEC,OAAO;IAAyB,CAAA,CAAA;IACrFC,mBAAmBR,OAAOG,SAASH,OAAOI,MAAM;EAClD,CAAA;EAIO,MAAMK,eAAeT,OAAOU,YAAW,EAAW,GAAGb,aAAAA,WAAwB;IAClFc,OAAOX,OAAOY,OAAMhB,cAACG,oBAAoBC,OAAOC,OAAO;MAAEY,OAAOC;IAAY,CAAA,CAAA;IAC5EC,QAAQf,OAAOC,OAAO;MACpBe,QAAQC;IACV,CAAA;EACF,CAAA,EAAA;EAAI;gBALSR,SAAAA;AAMf,GAlBiBb,iBAAAA,eAAAA,CAAAA,EAAAA;AAoBV,IAAMsB,uBAAuBlB,OAAOmB,QACzCnB,OAAOC,OAAO;EACZmB,iBAAiBC;AACnB,CAAA,CAAA;;",
|
|
6
|
-
"names": ["Schema", "SpaceSchema", "ScriptType", "EditorInputMode", "ScriptAction", "SCRIPT_ACTION", "SCRIPT_PLUGIN", "CreateScriptSchema", "Schema", "Struct", "name", "optional", "String", "gistUrl", "annotations", "title", "initialTemplateId", "Create", "TaggedClass", "input", "extend", "space", "SpaceSchema", "output", "object", "ScriptType", "ScriptSettingsSchema", "mutable", "editorInputMode", "EditorInputMode"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/DeploymentDialog/DeploymentDialog.tsx", "../../../src/components/DeploymentDialog/index.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport React, { useEffect, useMemo } from 'react';\n\nimport { createIntent, LayoutAction, useIntentDispatcher } from '@dxos/app-framework';\nimport { getSpace } from '@dxos/react-client/echo';\nimport { Button, Dialog, Icon, useTranslation } from '@dxos/react-ui';\nimport { type DataType } from '@dxos/schema';\n\nimport { useCreateAndDeployScriptTemplates } from '../../hooks/useCreateAndDeployScriptTemplates';\nimport { SCRIPT_PLUGIN } from '../../meta';\nimport { type Template } from '../../templates';\n\nexport const DEPLOYMENT_DIALOG = `${SCRIPT_PLUGIN}/deployment/dialog`;\n\n// TODO(ZaymonFC):\n// - Show activity and feedback to the user.\n// - Only take an array of templateIds and get the name from the data.\n// - Pending / onError states.\n\ntype DeploymentDialogProps = {\n accessToken: DataType.AccessToken;\n scriptTemplates: Template[];\n};\n\nexport const DeploymentDialog = ({ accessToken, scriptTemplates }: DeploymentDialogProps) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n const space = useMemo(() => getSpace(accessToken), [accessToken]);\n\n // TODO(ZaymonFC): Thinking further. All of this should get moved to intents to run async in the background.\n // Deployment shouldn't be tied to the lifecycle of the dialogue component.\n const { handleCreateAndDeployScripts, status } = useCreateAndDeployScriptTemplates(space, scriptTemplates);\n const { dispatchPromise: dispatch } = useIntentDispatcher();\n\n useEffect(() => {\n if (status === 'success') {\n // TODO(ZaymonFC): We can probably re-use this toast for normal script deployment.\n void dispatch(\n createIntent(LayoutAction.AddToast, {\n part: 'toast',\n subject: {\n id: `${SCRIPT_PLUGIN}/deployment-success`,\n icon: 'ph--check--regular',\n duration: Infinity,\n title: ['script deployment toast label', { ns: SCRIPT_PLUGIN, count: scriptTemplates.length }],\n description: ['script deployment toast description', { ns: SCRIPT_PLUGIN, count: scriptTemplates.length }],\n closeLabel: ['script deployment toast close label', { ns: SCRIPT_PLUGIN, count: scriptTemplates.length }],\n },\n }),\n );\n void dispatch(createIntent(LayoutAction.UpdateDialog, { part: 'dialog', options: { state: false } }));\n }\n if (status === 'error') {\n void dispatch(createIntent(LayoutAction.UpdateDialog, { part: 'dialog', options: { state: false } }));\n void dispatch(\n createIntent(LayoutAction.AddToast, {\n part: 'toast',\n subject: {\n id: `${SCRIPT_PLUGIN}/deployment-error`,\n icon: 'ph--warning--regular',\n duration: Infinity,\n title: ['script deployment error toast label', { ns: SCRIPT_PLUGIN, count: scriptTemplates.length }],\n description: [\n 'script deployment error toast description',\n { ns: SCRIPT_PLUGIN, count: scriptTemplates.length },\n ],\n closeLabel: [\n 'script deployment error toast close label',\n { ns: SCRIPT_PLUGIN, count: scriptTemplates.length },\n ],\n },\n }),\n );\n }\n }, [status, dispatch]);\n\n return (\n <Dialog.Content>\n <div className='flex justify-between items-center'>\n <Dialog.Title>{t('deployment dialog title')}</Dialog.Title>\n <Dialog.Close asChild>\n <Button density='fine' variant='ghost'>\n <Icon icon='ph--x--regular' size={4} />\n </Button>\n </Dialog.Close>\n </div>\n <div role='none' className='plb-4'>\n {/* TODO: Implement deployment logic and UI. */}\n <p>{t('deployment dialog scripts found message', { count: scriptTemplates.length })}</p>\n <ul className='pbs-2'>\n {scriptTemplates.map((template) => {\n return <li key={template.id}>{template.name}</li>;\n })}\n </ul>\n </div>\n <div role='none' className='flex flex-row-reverse gap-1'>\n <Button variant='primary' onClick={handleCreateAndDeployScripts} disabled={status === 'pending'}>\n {status === 'pending'\n ? t('deployment dialog deploy functions pending button label', { count: scriptTemplates.length })\n : t('deployment dialog deploy functions button label', { count: scriptTemplates.length })}\n </Button>\n <Dialog.Close asChild disabled={status === 'pending'}>\n <Button disabled={status === 'pending'}>{t('deployment dialog skip button label')}</Button>\n </Dialog.Close>\n </div>\n </Dialog.Content>\n );\n};\n\nexport default DeploymentDialog;\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { DeploymentDialog, DEPLOYMENT_DIALOG } from './DeploymentDialog';\n\nexport { DEPLOYMENT_DIALOG };\n\nexport default DeploymentDialog;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;AAIA,OAAOA,SAASC,WAAWC,eAAe;AAE1C,SAASC,cAAcC,cAAcC,2BAA2B;AAChE,SAASC,gBAAgB;AACzB,SAASC,QAAQC,QAAQC,MAAMC,sBAAsB;AAO9C,IAAMC,oBAAoB,GAAGC,aAAAA;AAY7B,IAA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|
-
"names": ["React", "useEffect", "useMemo", "createIntent", "LayoutAction", "useIntentDispatcher", "getSpace", "Button", "Dialog", "Icon", "useTranslation", "DEPLOYMENT_DIALOG", "SCRIPT_PLUGIN", "DeploymentDialog", "accessToken", "scriptTemplates", "t", "useTranslation", "space", "useMemo", "getSpace", "handleCreateAndDeployScripts", "status", "useCreateAndDeployScriptTemplates", "dispatchPromise", "dispatch", "useIntentDispatcher", "useEffect", "createIntent", "LayoutAction", "AddToast", "part", "subject", "id", "icon", "duration", "Infinity", "title", "ns", "count", "length", "description", "closeLabel", "UpdateDialog", "options", "state", "Dialog", "Content", "div", "className", "Title", "Close", "asChild", "Button", "density", "variant", "Icon", "size", "role", "p", "ul", "map", "template", "li", "key", "name", "onClick", "disabled", "DeploymentDialog"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/capabilities/compiler.ts", "../../../src/compiler/compiler.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport wasmUrl from 'esbuild-wasm/esbuild.wasm?url';\n\nimport { contributes } from '@dxos/app-framework';\nimport { initializeBundler } from '@dxos/functions/bundler';\n\nimport { ScriptCapabilities } from './capabilities';\nimport { Compiler } from '../compiler';\n\nexport default async () => {\n const compiler = new Compiler();\n\n await compiler.initialize();\n // TODO(wittjosiah): Fetch types for https modules.\n compiler.setFile('/src/typings.d.ts', \"declare module 'https://*';\");\n // TODO(wittjosiah): Proper function handler types.\n // TODO(wittjosiah): Remove.\n compiler.setFile(\n '/src/runtime.ts',\n `\n export const Filter: any = {};\n export type FunctionHandler = ({ event, context }: { event: any; context: any }) => Promise<Response>;\n export const functionHandler = (handler: FunctionHandler) => handler;\n `,\n );\n await initializeBundler({ wasmUrl });\n\n return contributes(ScriptCapabilities.Compiler, compiler);\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport {\n createDefaultMapFromCDN,\n createSystem,\n createVirtualTypeScriptEnvironment,\n type VirtualTypeScriptEnvironment,\n} from '@typescript/vfs';\nimport ts from 'typescript';\n\nimport { invariant } from '@dxos/invariant';\n\nconst defaultOptions: ts.CompilerOptions = {\n lib: ['DOM', 'es2022'],\n target: ts.ScriptTarget.ES2022,\n};\n\nexport class Compiler {\n private _env: VirtualTypeScriptEnvironment | undefined;\n private _fsMap: Map<string, string> | undefined;\n\n constructor(private readonly _options: ts.CompilerOptions = defaultOptions) {}\n\n async initialize(): Promise<void> {\n if (this._env) {\n return;\n }\n\n // TODO(wittjosiah): Figure out how to get workers working in plugin packages.\n // https://github.com/val-town/codemirror-ts?tab=readme-ov-file#setup-worker\n this._fsMap = await createDefaultMapFromCDN(this._options, '5.5.4', true, ts);\n const system = createSystem(this._fsMap);\n this._env = createVirtualTypeScriptEnvironment(system, [], ts, this._options);\n }\n\n get environment() {\n invariant(this._env, 'Compiler environment not initialized.');\n return this._env;\n }\n\n setFile(fileName: string, content: string): void {\n invariant(this._fsMap, 'File system map not initialized.');\n this.environment.createFile(fileName, content);\n }\n\n compile(fileName: string): ts.EmitOutput {\n return this.environment.languageService.getEmitOutput(fileName);\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;AAKA,OAAOA,aAAa;AAEpB,SAASC,mBAAmB;AAC5B,SAASC,yBAAyB;;;ACJlC,SACEC,yBACAC,cACAC,0CAEK;AACP,OAAOC,QAAQ;AAEf,SAASC,iBAAiB;;AAE1B,IAAMC,iBAAqC;EACzCC,KAAK;IAAC;IAAO;;EACbC,QAAQJ,GAAGK,aAAaC;AAC1B;AAEO,IAAMC,WAAN,MAAMA;EAIX,YAA6BC,WAA+BN,gBAAgB;SAA/CM,WAAAA;EAAgD;EAE7E,MAAMC,aAA4B;AAChC,QAAI,KAAKC,MAAM;AACb;IACF;AAIA,SAAKC,SAAS,MAAMd,wBAAwB,KAAKW,UAAU,SAAS,MAAMR,EAAAA;AAC1E,UAAMY,SAASd,aAAa,KAAKa,MAAM;AACvC,SAAKD,OAAOX,mCAAmCa,QAAQ,CAAA,GAAIZ,IAAI,KAAKQ,QAAQ;EAC9E;EAEA,IAAIK,cAAc;AAChBZ,cAAU,KAAKS,MAAM,yCAAA;;;;;;;;;AACrB,WAAO,KAAKA;EACd;EAEAI,QAAQC,UAAkBC,SAAuB;AAC/Cf,cAAU,KAAKU,QAAQ,oCAAA;;;;;;;;;AACvB,SAAKE,YAAYI,WAAWF,UAAUC,OAAAA;EACxC;EAEAE,QAAQH,UAAiC;AACvC,WAAO,KAAKF,YAAYM,gBAAgBC,cAAcL,QAAAA;EACxD;AACF;;;ADrCA,IAAA,mBAAe,YAAA;AACb,QAAMM,WAAW,IAAIC,SAAAA;AAErB,QAAMD,SAASE,WAAU;AAEzBF,WAASG,QAAQ,qBAAqB,6BAAA;AAGtCH,WAASG,QACP,mBACA;;;;OAIG;AAEL,QAAMC,kBAAkB;IAAEC;EAAQ,CAAA;AAElC,SAAOC,YAAYC,mBAAmBN,UAAUD,QAAAA;AAClD;",
|
|
6
|
-
"names": ["wasmUrl", "contributes", "initializeBundler", "createDefaultMapFromCDN", "createSystem", "createVirtualTypeScriptEnvironment", "ts", "invariant", "defaultOptions", "lib", "target", "ScriptTarget", "ES2022", "Compiler", "_options", "initialize", "_env", "_fsMap", "system", "environment", "setFile", "fileName", "content", "createFile", "compile", "languageService", "getEmitOutput", "compiler", "Compiler", "initialize", "setFile", "initializeBundler", "wasmUrl", "contributes", "ScriptCapabilities"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/capabilities/intent-resolver.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Octokit } from '@octokit/core';\nimport { Predicate } from 'effect';\n\nimport { contributes, Capabilities, createResolver, createIntent, LayoutAction } from '@dxos/app-framework';\nimport { Obj, Ref } from '@dxos/echo';\nimport { ScriptType } from '@dxos/functions';\nimport { TokenManagerAction } from '@dxos/plugin-token-manager/types';\nimport { DataType } from '@dxos/schema';\n\nimport { DEPLOYMENT_DIALOG } from '../components';\nimport { defaultScriptsForIntegration } from '../meta';\nimport { templates } from '../templates';\nimport { ScriptAction } from '../types';\n\nexport default () =>\n contributes(Capabilities.IntentResolver, [\n createResolver({\n intent: ScriptAction.Create,\n resolve: async ({ name, gistUrl, initialTemplateId }) => {\n let content = templates[0].source;\n\n const gistId = gistUrl?.split('/').at(-1);\n if (gistId) {\n // TODO(wittjosiah): Capability which contributes Octokit?\n // NOTE: AccessToken not needed to read public gists.\n const octokit = new Octokit();\n const response = await octokit.request('GET /gists/{gist_id}', {\n gist_id: gistId,\n });\n const gistContent = Object.values(response.data.files ?? {})[0]?.content;\n if (gistContent) {\n content = gistContent;\n }\n }\n\n if (initialTemplateId) {\n const template = templates.find((template) => template.id === initialTemplateId);\n if (template) {\n content = template.source;\n name = template.name;\n }\n }\n\n return {\n data: {\n object: Obj.make(ScriptType, {\n name,\n source: Ref.make(Obj.make(DataType.Text, { content })),\n }),\n },\n };\n },\n }),\n createResolver({\n intent: TokenManagerAction.AccessTokenCreated,\n resolve: async ({ accessToken }) => {\n const scriptTemplates = (defaultScriptsForIntegration[accessToken.source] ?? [])\n .map((id) => templates.find((t) => t.id === id))\n .filter(Predicate.isNotNullable);\n\n if (scriptTemplates.length > 0) {\n return {\n intents: [\n createIntent(LayoutAction.UpdateDialog, {\n part: 'dialog',\n subject: DEPLOYMENT_DIALOG,\n options: { blockAlign: 'start', state: true, props: { accessToken, scriptTemplates } },\n }),\n ],\n };\n }\n\n return { data: undefined };\n },\n }),\n ]);\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAIA,SAASA,eAAe;AACxB,SAASC,iBAAiB;AAE1B,SAASC,aAAaC,cAAcC,gBAAgBC,cAAcC,oBAAoB;AACtF,SAASC,KAAKC,WAAW;AACzB,SAASC,kBAAkB;AAC3B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Ac;cACtCC,MAAM;cACNC,SAASC;cACTC,SAAS;gBAAEC,YAAY;gBAASC,OAAO;gBAAMC,OAAO;kBAAEnB;kBAAaC;gBAAgB;cAAE;YACvF,CAAA;;QAEJ;MACF;AAEA,aAAO;QAAEf,MAAMkC;MAAU;IAC3B;EACF,CAAA;CACD;",
|
|
6
|
-
"names": ["Octokit", "Predicate", "contributes", "Capabilities", "createResolver", "createIntent", "LayoutAction", "Obj", "Ref", "ScriptType", "TokenManagerAction", "DataType", "contributes", "Capabilities", "IntentResolver", "createResolver", "intent", "ScriptAction", "Create", "resolve", "name", "gistUrl", "initialTemplateId", "content", "templates", "source", "gistId", "split", "at", "octokit", "Octokit", "response", "request", "gist_id", "gistContent", "Object", "values", "data", "files", "template", "find", "id", "object", "Obj", "make", "ScriptType", "Ref", "DataType", "Text", "TokenManagerAction", "AccessTokenCreated", "accessToken", "scriptTemplates", "defaultScriptsForIntegration", "map", "t", "filter", "Predicate", "isNotNullable", "length", "intents", "createIntent", "LayoutAction", "UpdateDialog", "part", "subject", "DEPLOYMENT_DIALOG", "options", "blockAlign", "state", "props", "undefined"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/capabilities/react-surface.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport React from 'react';\n\nimport { Capabilities, contributes, createSurface, useCapability } from '@dxos/app-framework';\nimport { InvocationTraceContainer } from '@dxos/devtools';\nimport { Obj } from '@dxos/echo';\nimport { ScriptType } from '@dxos/functions';\nimport { SettingsStore } from '@dxos/local-storage';\nimport { getSpace } from '@dxos/react-client/echo';\nimport { StackItem } from '@dxos/react-ui-stack';\nimport { type DataType } from '@dxos/schema';\n\nimport { ScriptCapabilities } from './capabilities';\nimport {\n DEPLOYMENT_DIALOG,\n DeploymentDialog,\n ScriptContainer,\n ScriptPluginSettings,\n ScriptObjectSettings,\n ScriptProperties,\n TestContainer,\n} from '../components';\nimport { meta } from '../meta';\nimport { type ScriptSettingsProps } from '../types';\n\nexport default () =>\n contributes(Capabilities.ReactSurface, [\n createSurface({\n id: `${meta.id}/plugin-settings`,\n role: 'article',\n filter: (data): data is { subject: SettingsStore<ScriptSettingsProps> } =>\n data.subject instanceof SettingsStore && data.subject.prefix === meta.id,\n component: ({ data: { subject } }) => <ScriptPluginSettings settings={subject.value} />,\n }),\n createSurface({\n id: `${meta.id}/article`,\n role: 'article',\n filter: (data): data is { subject: ScriptType } => Obj.instanceOf(ScriptType, data.subject),\n component: ({ data, role }) => {\n const compiler = useCapability(ScriptCapabilities.Compiler);\n // TODO(dmaretskyi): Since settings store is not reactive, this would break on the script plugin being enabled without a page reload.\n const settings = useCapability(Capabilities.SettingsStore).getStore<ScriptSettingsProps>(meta.id)?.value;\n return <ScriptContainer role={role} script={data.subject} settings={settings} env={compiler.environment} />;\n },\n }),\n createSurface({\n id: `${meta.id}/companion/base-settings`,\n role: 'base-object-settings',\n filter: (data): data is { subject: ScriptType } => Obj.instanceOf(ScriptType, data.subject),\n component: ({ data }) => <ScriptProperties object={data.subject} />,\n }),\n createSurface({\n id: `${meta.id}/companion/settings`,\n role: 'object-settings',\n filter: (data): data is { subject: ScriptType } => Obj.instanceOf(ScriptType, data.subject),\n component: ({ data }) => <ScriptObjectSettings object={data.subject} />,\n }),\n createSurface({\n id: `${meta.id}/companion/execute`,\n role: 'article',\n filter: (data): data is { companionTo: ScriptType } =>\n Obj.instanceOf(ScriptType, data.companionTo) && data.subject === 'execute',\n component: ({ data, role }) => <TestContainer script={data.companionTo} role={role} />,\n }),\n createSurface({\n id: `${meta.id}/companion/logs`,\n role: 'article',\n filter: (data): data is { companionTo: ScriptType } =>\n Obj.instanceOf(ScriptType, data.companionTo) && data.subject === 'logs',\n component: ({ data, role }) => {\n const space = getSpace(data.companionTo);\n return (\n <StackItem.Content role={role}>\n <InvocationTraceContainer space={space} target={data.companionTo} detailAxis='block' />\n </StackItem.Content>\n );\n },\n }),\n createSurface({\n id: DEPLOYMENT_DIALOG,\n role: 'dialog',\n filter: (data): data is { props: { accessToken: DataType.AccessToken; scriptTemplates: any } } =>\n data.component === DEPLOYMENT_DIALOG,\n component: ({ data }) => <DeploymentDialog {...data.props} />,\n }),\n ]);\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAIA,OAAOA,WAAW;AAElB,SAASC,cAAcC,aAAaC,eAAeC,qBAAqB;AACxE,SAASC,gCAAgC;AACzC,SAASC,WAAW;AACpB,SAASC,kBAAkB;AAC3B,SAASC,qBAAqB;AAC9B,SAASC,gBAAgB;AACzB,SAASC,iBAAiB;AAgB1B,IAAA,wBAAe,MACbC,YAAYC,aAAaC,cAAc;EACrCC,cAAc;IACZC,IAAI,GAAGC,KAAKD,EAAE;IACdE,MAAM;IACNC,QAAQ,CAACC,SACPA,KAAKC,mBAAmBC,iBAAiBF,KAAKC,QAAQE,WAAWN,KAAKD;IACxEQ,WAAW,CAAC,EAAEJ,MAAM,EAAEC,QAAO,EAAE,MAAO,sBAAA,cAACI,sBAAAA;MAAqBC,UAAUL,QAAQM;;EAChF,CAAA;EACAZ,cAAc;IACZC,IAAI,GAAGC,KAAKD,EAAE;IACdE,MAAM;IACNC,QAAQ,CAACC,SAA0CQ,IAAIC,WAAWC,YAAYV,KAAKC,OAAO;IAC1FG,WAAW,CAAC,EAAEJ,MAAMF,KAAI,MAAE;AACxB,YAAMa,WAAWC,cAAcC,mBAAmBC,QAAQ;AAE1D,YAAMR,WAAWM,cAAcnB,aAAaS,aAAa,EAAEa,SAA8BlB,KAAKD,EAAE,GAAGW;AACnG,aAAO,sBAAA,cAACS,iBAAAA;QAAgBlB;QAAYmB,QAAQjB,KAAKC;QAASK;QAAoBY,KAAKP,SAASQ;;IAC9F;EACF,CAAA;EACAxB,cAAc;IACZC,IAAI,GAAGC,KAAKD,EAAE;IACdE,MAAM;IACNC,QAAQ,CAACC,SAA0CQ,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ceContainer", "Obj", "ScriptType", "SettingsStore", "getSpace", "StackItem", "contributes", "Capabilities", "ReactSurface", "createSurface", "id", "meta", "role", "filter", "data", "subject", "SettingsStore", "prefix", "component", "ScriptPluginSettings", "settings", "value", "Obj", "instanceOf", "ScriptType", "compiler", "useCapability", "ScriptCapabilities", "Compiler", "getStore", "ScriptContainer", "script", "env", "environment", "ScriptProperties", "object", "ScriptObjectSettings", "companionTo", "TestContainer", "space", "getSpace", "StackItem", "Content", "InvocationTraceContainer", "target", "detailAxis", "DEPLOYMENT_DIALOG", "DeploymentDialog", "props"]
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAMhC,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAGvC,OAAO,EAAE,aAAa,EAAE,CAAC;AAEzB,yBAAiB,YAAY,CAAC;IAG5B,MAAM,CAAC,MAAM,kBAAkB;;;;MAK7B,CAAC;IAEH,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,kBAAkB,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;IAE9E,MAAM,OAAO,MAAO,SAAQ,WAK1B;KAAG;;CACN;AAED,eAAO,MAAM,oBAAoB;;GAIhC,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
|
/package/dist/lib/browser/{DeploymentDialog-RIGSJM6A.mjs.map → DeploymentDialog-C3XH2Z56.mjs.map}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/lib/{node-esm/DeploymentDialog-6Z7JH3VO.mjs.map → browser/types/index.mjs.map}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|