@dxos/plugin-script 0.6.12-staging.e11e696 → 0.6.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/{ScriptContainer-AGDWRBHJ.mjs → ScriptEditor-5Y3EROG3.mjs} +106 -258
- package/dist/lib/browser/ScriptEditor-5Y3EROG3.mjs.map +7 -0
- package/dist/lib/browser/TypescriptEditor-GPE72Y6I.mjs +9 -0
- package/dist/lib/browser/{chunk-G6FWCTGT.mjs → chunk-DL5XQRQM.mjs} +5 -7
- package/dist/lib/browser/chunk-DL5XQRQM.mjs.map +7 -0
- package/dist/lib/browser/{chunk-MDX7ACIK.mjs → chunk-JBACGDOJ.mjs} +6 -3
- package/dist/lib/browser/chunk-JBACGDOJ.mjs.map +7 -0
- package/dist/lib/browser/chunk-MRGOT5RF.mjs +78 -0
- package/dist/lib/browser/chunk-MRGOT5RF.mjs.map +7 -0
- package/dist/lib/browser/{chunk-CAEANETO.mjs → chunk-O4LWBX6A.mjs} +2 -2
- package/dist/lib/browser/{chunk-CAEANETO.mjs.map → chunk-O4LWBX6A.mjs.map} +2 -2
- package/dist/lib/browser/{chunk-G6H56WFS.mjs → chunk-RHEZ5LUU.mjs} +2 -51
- package/dist/lib/browser/{chunk-G6H56WFS.mjs.map → chunk-RHEZ5LUU.mjs.map} +4 -4
- package/dist/lib/browser/edge/index.mjs +1 -3
- package/dist/lib/browser/index.mjs +62 -80
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/meta.mjs +1 -1
- package/dist/lib/browser/types/index.mjs +2 -2
- package/dist/lib/node/ScriptEditor-YCUQFWQM.cjs +526 -0
- package/dist/lib/node/ScriptEditor-YCUQFWQM.cjs.map +7 -0
- package/dist/lib/node/{chunk-OJ77BZRH.cjs → TypescriptEditor-M3WWFIP2.cjs} +8 -19
- package/dist/lib/node/TypescriptEditor-M3WWFIP2.cjs.map +7 -0
- package/dist/lib/node/{chunk-ACLCRWDB.cjs → chunk-4GTXIELQ.cjs} +6 -44
- package/dist/lib/node/chunk-4GTXIELQ.cjs.map +7 -0
- package/dist/lib/node/chunk-4VMNBXWU.cjs +54 -0
- package/dist/lib/node/chunk-4VMNBXWU.cjs.map +7 -0
- package/dist/lib/node/{chunk-2PZKJXNP.cjs → chunk-5RBVXKXT.cjs} +6 -6
- package/dist/lib/node/{chunk-2PZKJXNP.cjs.map → chunk-5RBVXKXT.cjs.map} +2 -2
- package/dist/lib/node/chunk-IMLDKD5Y.cjs +111 -0
- package/dist/lib/node/chunk-IMLDKD5Y.cjs.map +7 -0
- package/dist/lib/node/{chunk-UZ3ZXEBF.cjs → chunk-PFH3ROEH.cjs} +8 -11
- package/dist/lib/node/chunk-PFH3ROEH.cjs.map +7 -0
- package/dist/lib/node/edge/index.cjs +8 -10
- package/dist/lib/node/edge/index.cjs.map +2 -2
- package/dist/lib/node/index.cjs +82 -95
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.cjs +3 -3
- package/dist/lib/node/meta.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/types/index.cjs +5 -5
- package/dist/lib/node/types/index.cjs.map +1 -1
- package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
- package/dist/types/src/components/DebugPanel.d.ts.map +1 -0
- package/dist/types/src/components/{FrameContainer → ScriptBlock/FrameContainer}/FrameContainer.d.ts +1 -1
- package/dist/types/src/components/ScriptBlock/FrameContainer/FrameContainer.d.ts.map +1 -0
- package/dist/types/src/components/ScriptBlock/FrameContainer/frame.d.ts.map +1 -0
- package/dist/types/src/components/ScriptBlock/FrameContainer/index.d.ts.map +1 -0
- package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts +3 -1
- package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts.map +1 -1
- package/dist/types/src/components/ScriptBlock/ScriptBlock.stories.d.ts +1 -1
- package/dist/types/src/components/ScriptBlock/ScriptBlock.stories.d.ts.map +1 -1
- package/dist/types/src/components/ScriptBlock/Splitter/Splitter.d.ts +15 -0
- package/dist/types/src/components/ScriptBlock/Splitter/Splitter.d.ts.map +1 -0
- package/dist/types/src/components/ScriptBlock/Splitter/Splitter.stories.d.ts +13 -0
- package/dist/types/src/components/ScriptBlock/Splitter/Splitter.stories.d.ts.map +1 -0
- package/dist/types/src/components/ScriptBlock/Splitter/index.d.ts +2 -0
- package/dist/types/src/components/ScriptBlock/Splitter/index.d.ts.map +1 -0
- package/dist/types/src/components/ScriptEditor.d.ts +5 -4
- package/dist/types/src/components/ScriptEditor.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar.d.ts +13 -0
- package/dist/types/src/components/Toolbar.d.ts.map +1 -0
- package/dist/types/src/components/Toolbar.stories.d.ts +14 -0
- package/dist/types/src/components/Toolbar.stories.d.ts.map +1 -0
- package/dist/types/src/components/{TypescriptEditor/TypescriptEditor.d.ts → TypescriptEditor.d.ts} +2 -1
- package/dist/types/src/components/TypescriptEditor.d.ts.map +1 -0
- package/dist/types/src/components/TypescriptEditor.stories.d.ts +10 -0
- package/dist/types/src/components/TypescriptEditor.stories.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +2 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/edge/functions.d.ts +0 -1
- package/dist/types/src/edge/functions.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +4 -1
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +0 -2
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/script.d.ts +4 -4
- package/dist/types/src/types/types.d.ts +3 -4
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/package.json +55 -61
- package/src/ScriptPlugin.tsx +38 -22
- package/src/bundler/bundler.test.ts +2 -12
- package/src/components/{DebugPanel/DebugPanel.tsx → DebugPanel.tsx} +41 -48
- package/src/components/{FrameContainer → ScriptBlock/FrameContainer}/FrameContainer.tsx +1 -1
- package/src/components/ScriptBlock/ScriptBlock.stories.tsx +3 -4
- package/src/components/ScriptBlock/ScriptBlock.tsx +36 -10
- package/src/components/ScriptBlock/Splitter/Splitter.stories.tsx +37 -0
- package/src/components/ScriptBlock/Splitter/Splitter.tsx +52 -0
- package/src/components/{Toolbar → ScriptBlock/Splitter}/index.ts +1 -1
- package/src/components/ScriptEditor.tsx +46 -47
- package/src/components/{Toolbar/Toolbar.stories.tsx → Toolbar.stories.tsx} +1 -10
- package/src/components/Toolbar.tsx +147 -0
- package/src/components/{TypescriptEditor/TypescriptEditor.stories.tsx → TypescriptEditor.stories.tsx} +28 -7
- package/src/components/{TypescriptEditor/TypescriptEditor.tsx → TypescriptEditor.tsx} +3 -1
- package/src/components/index.ts +2 -3
- package/src/edge/functions.ts +0 -1
- package/src/meta.tsx +6 -2
- package/src/translations.ts +0 -2
- package/src/types/types.ts +5 -9
- package/dist/lib/browser/ScriptContainer-AGDWRBHJ.mjs.map +0 -7
- package/dist/lib/browser/chunk-G6FWCTGT.mjs.map +0 -7
- package/dist/lib/browser/chunk-MDX7ACIK.mjs.map +0 -7
- package/dist/lib/node/ScriptContainer-5R3NWYKS.cjs +0 -668
- package/dist/lib/node/ScriptContainer-5R3NWYKS.cjs.map +0 -7
- package/dist/lib/node/chunk-ACLCRWDB.cjs.map +0 -7
- package/dist/lib/node/chunk-OJ77BZRH.cjs.map +0 -7
- package/dist/lib/node/chunk-UZ3ZXEBF.cjs.map +0 -7
- package/dist/lib/node-esm/ScriptContainer-ZY2XG3GH.mjs +0 -666
- package/dist/lib/node-esm/ScriptContainer-ZY2XG3GH.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-2NX3HWPM.mjs +0 -245
- package/dist/lib/node-esm/chunk-2NX3HWPM.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-7BZDZF7Z.mjs +0 -47
- package/dist/lib/node-esm/chunk-7BZDZF7Z.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-LDLNTVAK.mjs +0 -280
- package/dist/lib/node-esm/chunk-LDLNTVAK.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-TZ3Z4SII.mjs +0 -20
- package/dist/lib/node-esm/chunk-TZ3Z4SII.mjs.map +0 -7
- package/dist/lib/node-esm/edge/index.mjs +0 -22
- package/dist/lib/node-esm/index.mjs +0 -310
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/meta.mjs +0 -10
- package/dist/lib/node-esm/meta.mjs.map +0 -7
- package/dist/lib/node-esm/types/index.mjs +0 -13
- package/dist/lib/node-esm/types/index.mjs.map +0 -7
- package/dist/types/src/components/DebugPanel/DebugPanel.d.ts.map +0 -1
- package/dist/types/src/components/DebugPanel/index.d.ts +0 -2
- package/dist/types/src/components/DebugPanel/index.d.ts.map +0 -1
- package/dist/types/src/components/FrameContainer/FrameContainer.d.ts.map +0 -1
- package/dist/types/src/components/FrameContainer/frame.d.ts.map +0 -1
- package/dist/types/src/components/FrameContainer/index.d.ts.map +0 -1
- package/dist/types/src/components/ScriptContainer.d.ts +0 -5
- package/dist/types/src/components/ScriptContainer.d.ts.map +0 -1
- package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts +0 -6
- package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts.map +0 -1
- package/dist/types/src/components/ScriptSettings/index.d.ts +0 -2
- package/dist/types/src/components/ScriptSettings/index.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +0 -23
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +0 -17
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar/index.d.ts +0 -2
- package/dist/types/src/components/Toolbar/index.d.ts.map +0 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +0 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts +0 -10
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts.map +0 -1
- package/dist/types/src/components/TypescriptEditor/index.d.ts +0 -2
- package/dist/types/src/components/TypescriptEditor/index.d.ts.map +0 -1
- package/dist/types/src/templates/chat.d.ts +0 -6
- package/dist/types/src/templates/chat.d.ts.map +0 -1
- package/dist/types/src/templates/chess.d.ts +0 -6
- package/dist/types/src/templates/chess.d.ts.map +0 -1
- package/dist/types/src/templates/echo.d.ts +0 -6
- package/dist/types/src/templates/echo.d.ts.map +0 -1
- package/dist/types/src/templates/email.d.ts +0 -6
- package/dist/types/src/templates/email.d.ts.map +0 -1
- package/dist/types/src/templates/forex.d.ts +0 -6
- package/dist/types/src/templates/forex.d.ts.map +0 -1
- package/dist/types/src/templates.d.ts +0 -8
- package/dist/types/src/templates.d.ts.map +0 -1
- package/src/components/DebugPanel/index.ts +0 -5
- package/src/components/ScriptContainer.tsx +0 -22
- package/src/components/ScriptSettings/ScriptSettings.tsx +0 -47
- package/src/components/ScriptSettings/index.ts +0 -5
- package/src/components/Toolbar/Toolbar.tsx +0 -180
- package/src/components/TypescriptEditor/index.ts +0 -5
- package/src/templates/chat.ts +0 -102
- package/src/templates/chess.ts +0 -41
- package/src/templates/echo.ts +0 -15
- package/src/templates/email.ts +0 -38
- package/src/templates/forex.ts +0 -21
- package/src/templates.ts +0 -54
- /package/dist/lib/{node-esm/edge/index.mjs.map → browser/TypescriptEditor-GPE72Y6I.mjs.map} +0 -0
- /package/dist/types/src/components/{DebugPanel/DebugPanel.d.ts → DebugPanel.d.ts} +0 -0
- /package/dist/types/src/components/{FrameContainer → ScriptBlock/FrameContainer}/frame.d.ts +0 -0
- /package/dist/types/src/components/{FrameContainer → ScriptBlock/FrameContainer}/index.d.ts +0 -0
- /package/src/components/{FrameContainer → ScriptBlock/FrameContainer}/frame.html +0 -0
- /package/src/components/{FrameContainer → ScriptBlock/FrameContainer}/frame.tsx +0 -0
- /package/src/components/{FrameContainer → ScriptBlock/FrameContainer}/index.ts +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/TypescriptEditor/index.ts"],"names":[],"mappings":"AAIA,cAAc,oBAAoB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../../../src/templates/chat.ts"],"names":[],"mappings":"AAOA;;GAEG;qFAMA,GAAG;AALN,wBAsEE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chess.d.ts","sourceRoot":"","sources":["../../../../src/templates/chess.ts"],"names":[],"mappings":"AAOA;;GAEG;iFAMA,GAAG;AALN,wBA8BE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"echo.d.ts","sourceRoot":"","sources":["../../../../src/templates/echo.ts"],"names":[],"mappings":"AAIA;;GAEG;6DAKA,GAAG;AAJN,wBAOE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../../../../src/templates/email.ts"],"names":[],"mappings":"AAIA;;GAEG;iFAMA,GAAG;AALN,wBA8BE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"forex.d.ts","sourceRoot":"","sources":["../../../../src/templates/forex.ts"],"names":[],"mappings":"AAIA;;GAEG;6DAKA,GAAG;AAJN,wBAaE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../../src/templates.ts"],"names":[],"mappings":"AAiBA,MAAM,MAAM,QAAQ,GAAG;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,QAAQ,EA6B/B,CAAC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React from 'react';
|
|
6
|
-
|
|
7
|
-
import { fullyQualifiedId } from '@dxos/react-client/echo';
|
|
8
|
-
import { useAttendableAttributes } from '@dxos/react-ui-attention';
|
|
9
|
-
import { mx } from '@dxos/react-ui-theme';
|
|
10
|
-
|
|
11
|
-
import { ScriptEditor, type ScriptEditorProps } from './ScriptEditor';
|
|
12
|
-
|
|
13
|
-
const ScriptContainer = ({ script, ...props }: ScriptEditorProps) => {
|
|
14
|
-
const attendableAttrs = useAttendableAttributes(fullyQualifiedId(script));
|
|
15
|
-
return (
|
|
16
|
-
<div role='none' className={mx('flex row-span-2 w-full overflow-hidden attention-surface')} {...attendableAttrs}>
|
|
17
|
-
<ScriptEditor {...props} script={script} />
|
|
18
|
-
</div>
|
|
19
|
-
);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export default ScriptContainer;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React from 'react';
|
|
6
|
-
|
|
7
|
-
import { SettingsValue } from '@dxos/plugin-settings';
|
|
8
|
-
import { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
9
|
-
import { useClient } from '@dxos/react-client';
|
|
10
|
-
import { Button, useTranslation } from '@dxos/react-ui';
|
|
11
|
-
|
|
12
|
-
import { SCRIPT_PLUGIN } from '../../meta';
|
|
13
|
-
import { type ScriptSettingsProps } from '../../types';
|
|
14
|
-
|
|
15
|
-
export const ScriptSettings = ({ settings }: { settings: ScriptSettingsProps }) => {
|
|
16
|
-
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
17
|
-
const client = useClient();
|
|
18
|
-
|
|
19
|
-
// TODO(burdon): Check token.
|
|
20
|
-
const handleAuthenticate = async () => {
|
|
21
|
-
const { identityKey } = client.halo.identity.get()!;
|
|
22
|
-
await client.halo.writeCredentials([
|
|
23
|
-
{
|
|
24
|
-
issuer: identityKey,
|
|
25
|
-
issuanceDate: new Date(),
|
|
26
|
-
subject: {
|
|
27
|
-
id: identityKey,
|
|
28
|
-
assertion: {
|
|
29
|
-
'@type': 'dxos.halo.credentials.ServiceAccess',
|
|
30
|
-
serverName: 'hub.dxos.network',
|
|
31
|
-
serverKey: identityKey,
|
|
32
|
-
identityKey,
|
|
33
|
-
capabilities: ['composer:beta'],
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
} satisfies Credential,
|
|
37
|
-
]);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
return (
|
|
41
|
-
<>
|
|
42
|
-
<SettingsValue label={t('authenticate action label')}>
|
|
43
|
-
<Button onClick={handleAuthenticate}>{t('authenticate button label')}</Button>
|
|
44
|
-
</SettingsValue>
|
|
45
|
-
</>
|
|
46
|
-
);
|
|
47
|
-
};
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React, { useState } from 'react';
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
DensityProvider,
|
|
9
|
-
ElevationProvider,
|
|
10
|
-
Icon,
|
|
11
|
-
Select,
|
|
12
|
-
type ThemedClassName,
|
|
13
|
-
ToggleGroup,
|
|
14
|
-
ToggleGroupItem,
|
|
15
|
-
type ToolbarButtonProps,
|
|
16
|
-
Toolbar as NaturalToolbar,
|
|
17
|
-
Tooltip,
|
|
18
|
-
useTranslation,
|
|
19
|
-
} from '@dxos/react-ui';
|
|
20
|
-
|
|
21
|
-
import { SCRIPT_PLUGIN } from '../../meta';
|
|
22
|
-
import { type Template } from '../../templates';
|
|
23
|
-
|
|
24
|
-
export type ToolbarProps = ThemedClassName<
|
|
25
|
-
{
|
|
26
|
-
deployed?: boolean;
|
|
27
|
-
error?: string;
|
|
28
|
-
functionUrl?: string;
|
|
29
|
-
onDeploy?: () => Promise<void>;
|
|
30
|
-
onFormat?: () => Promise<void>;
|
|
31
|
-
} & TemplateSelectProps &
|
|
32
|
-
ViewSelectorProps
|
|
33
|
-
>;
|
|
34
|
-
|
|
35
|
-
export const Toolbar = ({
|
|
36
|
-
classNames,
|
|
37
|
-
deployed,
|
|
38
|
-
error,
|
|
39
|
-
functionUrl,
|
|
40
|
-
view,
|
|
41
|
-
templates,
|
|
42
|
-
onDeploy,
|
|
43
|
-
onFormat,
|
|
44
|
-
onViewChange,
|
|
45
|
-
onTemplateSelect,
|
|
46
|
-
}: ToolbarProps) => {
|
|
47
|
-
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
48
|
-
const [pending, setPending] = useState(false);
|
|
49
|
-
|
|
50
|
-
const handleCopyLink = async () => {
|
|
51
|
-
if (!functionUrl) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
await navigator.clipboard.writeText(functionUrl);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const handleDeploy = async () => {
|
|
59
|
-
if (!pending) {
|
|
60
|
-
setPending(true);
|
|
61
|
-
await onDeploy?.();
|
|
62
|
-
setPending(false);
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
// TODO(burdon): Factor out common toolbar components with sheet/editor?
|
|
67
|
-
return (
|
|
68
|
-
<DensityProvider density='fine'>
|
|
69
|
-
<ElevationProvider elevation='chrome'>
|
|
70
|
-
<NaturalToolbar.Root classNames={['p-1', classNames]} style={{ contain: 'layout' }}>
|
|
71
|
-
{templates && <TemplateSelect templates={templates} onTemplateSelect={onTemplateSelect} />}
|
|
72
|
-
{onFormat && <ToolbarIconButton icon='ph--magic-wand--regular' text={t('format label')} onClick={onFormat} />}
|
|
73
|
-
|
|
74
|
-
<div role='separator' className='grow' />
|
|
75
|
-
|
|
76
|
-
{error ? (
|
|
77
|
-
<Tooltip.Root>
|
|
78
|
-
<Tooltip.Trigger>
|
|
79
|
-
<Icon icon='ph--warning-circle--regular' size={4} />
|
|
80
|
-
</Tooltip.Trigger>
|
|
81
|
-
<Tooltip.Portal>
|
|
82
|
-
<Tooltip.Content>
|
|
83
|
-
<Tooltip.Arrow />
|
|
84
|
-
{error}
|
|
85
|
-
</Tooltip.Content>
|
|
86
|
-
</Tooltip.Portal>
|
|
87
|
-
</Tooltip.Root>
|
|
88
|
-
) : null}
|
|
89
|
-
|
|
90
|
-
{functionUrl && deployed && (
|
|
91
|
-
<ToolbarIconButton icon='ph--link--regular' text={t('copy link label')} onClick={handleCopyLink} />
|
|
92
|
-
)}
|
|
93
|
-
|
|
94
|
-
{onDeploy && (
|
|
95
|
-
<ToolbarIconButton
|
|
96
|
-
icon={pending ? 'ph--spinner-gap--regular' : 'ph--cloud-arrow-up--regular'}
|
|
97
|
-
classNames={[pending && 'animate-spin']}
|
|
98
|
-
text={pending ? t('pending label') : t('deploy label')}
|
|
99
|
-
onClick={handleDeploy}
|
|
100
|
-
/>
|
|
101
|
-
)}
|
|
102
|
-
|
|
103
|
-
<ViewSelector view={view} onViewChange={onViewChange} />
|
|
104
|
-
</NaturalToolbar.Root>
|
|
105
|
-
</ElevationProvider>
|
|
106
|
-
</DensityProvider>
|
|
107
|
-
);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const ToolbarIconButton = ({
|
|
111
|
-
icon,
|
|
112
|
-
text,
|
|
113
|
-
classNames,
|
|
114
|
-
disabled,
|
|
115
|
-
onClick,
|
|
116
|
-
}: { icon: string; text: string } & Pick<ToolbarButtonProps, 'classNames' | 'disabled' | 'onClick'>) => {
|
|
117
|
-
return (
|
|
118
|
-
<Tooltip.Root>
|
|
119
|
-
<Tooltip.Trigger asChild>
|
|
120
|
-
<NaturalToolbar.Button variant='ghost' disabled={disabled} onClick={onClick}>
|
|
121
|
-
<Icon icon={icon} size={4} classNames={classNames} />
|
|
122
|
-
</NaturalToolbar.Button>
|
|
123
|
-
</Tooltip.Trigger>
|
|
124
|
-
<Tooltip.Portal>
|
|
125
|
-
<Tooltip.Content>
|
|
126
|
-
<Tooltip.Arrow />
|
|
127
|
-
{text}
|
|
128
|
-
</Tooltip.Content>
|
|
129
|
-
</Tooltip.Portal>
|
|
130
|
-
</Tooltip.Root>
|
|
131
|
-
);
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
export type ViewType = 'editor' | 'split' | 'preview';
|
|
135
|
-
|
|
136
|
-
export type TemplateSelectProps = {
|
|
137
|
-
templates?: Template[];
|
|
138
|
-
onTemplateSelect?: (id: string) => void;
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
export const TemplateSelect = ({ templates = [], onTemplateSelect }: TemplateSelectProps) => {
|
|
142
|
-
return (
|
|
143
|
-
<Select.Root value={''} onValueChange={onTemplateSelect}>
|
|
144
|
-
<Select.TriggerButton />
|
|
145
|
-
<Select.Portal>
|
|
146
|
-
<Select.Content>
|
|
147
|
-
<Select.Viewport>
|
|
148
|
-
<Select.Option value={''}>Template</Select.Option>
|
|
149
|
-
{templates.map(({ id, name }) => (
|
|
150
|
-
<Select.Option key={id} value={id}>
|
|
151
|
-
{name}
|
|
152
|
-
</Select.Option>
|
|
153
|
-
))}
|
|
154
|
-
</Select.Viewport>
|
|
155
|
-
</Select.Content>
|
|
156
|
-
</Select.Portal>
|
|
157
|
-
</Select.Root>
|
|
158
|
-
);
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
export type ViewSelectorProps = {
|
|
162
|
-
view?: ViewType;
|
|
163
|
-
onViewChange?: (view: ViewType) => void;
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
export const ViewSelector = ({ view, onViewChange }: ViewSelectorProps) => {
|
|
167
|
-
return (
|
|
168
|
-
<ToggleGroup type='single' value={view} onValueChange={(value) => onViewChange?.(value as ViewType)}>
|
|
169
|
-
<ToggleGroupItem value='editor' classNames='bg-transparent text-subdued'>
|
|
170
|
-
<Icon icon='ph--code--regular' size={4} />
|
|
171
|
-
</ToggleGroupItem>
|
|
172
|
-
<ToggleGroupItem value='split' classNames='bg-transparent text-subdued'>
|
|
173
|
-
<Icon icon='ph--square-split-vertical--regular' size={4} />
|
|
174
|
-
</ToggleGroupItem>
|
|
175
|
-
<ToggleGroupItem value='preview' classNames='bg-transparent text-subdued'>
|
|
176
|
-
<Icon icon='ph--eye--regular' size={4} />
|
|
177
|
-
</ToggleGroupItem>
|
|
178
|
-
</ToggleGroup>
|
|
179
|
-
);
|
|
180
|
-
};
|
package/src/templates/chat.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
import { transformServerSentEvents } from 'https://esm.sh/@dxos/script-toolbox';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Chatbot that answers questions based on the context data.
|
|
10
|
-
*/
|
|
11
|
-
export default async ({
|
|
12
|
-
event: {
|
|
13
|
-
data: { request },
|
|
14
|
-
},
|
|
15
|
-
context: { space, ai },
|
|
16
|
-
}: any) => {
|
|
17
|
-
const textBody = await request.text();
|
|
18
|
-
let parsedRequest: any;
|
|
19
|
-
try {
|
|
20
|
-
parsedRequest = JSON.parse(textBody);
|
|
21
|
-
} catch (err) {
|
|
22
|
-
const answer = await ai.run('@cf/meta/llama-3.1-8b-instruct', {
|
|
23
|
-
stream: true,
|
|
24
|
-
prompt: `
|
|
25
|
-
Using only the context data below to answer the user's question.
|
|
26
|
-
If you cannot answer the question from the provided content, then reply with "I don't know."
|
|
27
|
-
|
|
28
|
-
CONTEXT:
|
|
29
|
-
${await getContext({ space })}
|
|
30
|
-
|
|
31
|
-
QUESTION:
|
|
32
|
-
${textBody}
|
|
33
|
-
`,
|
|
34
|
-
});
|
|
35
|
-
return new Response(transformServerSentEvents(answer));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const promptId = parsedRequest.trigger.promptId;
|
|
39
|
-
const promptObject = await space.crud.query({ id: promptId }).first();
|
|
40
|
-
|
|
41
|
-
if (parsedRequest.data.objects.length !== 1) {
|
|
42
|
-
return new Response('Message batches not supported.');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const messageId = parsedRequest.data.objects[0];
|
|
46
|
-
let message;
|
|
47
|
-
try {
|
|
48
|
-
message = await space.crud.query({ id: messageId }).first();
|
|
49
|
-
} catch (err) {
|
|
50
|
-
return new Response('Message not replicated yet.', { status: 409 });
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (message.text.includes('--------')) {
|
|
54
|
-
return new Response('Message was already processed.');
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
let prompt = promptObject.template;
|
|
58
|
-
for (const input of promptObject.inputs) {
|
|
59
|
-
let value: string | null = null;
|
|
60
|
-
if (input.type === ChainInputType.VALUE) {
|
|
61
|
-
value = String(input.value);
|
|
62
|
-
} else if (input.type === ChainInputType.RETRIEVER) {
|
|
63
|
-
value = await getContext({ space });
|
|
64
|
-
} else if (input.type === ChainInputType.PASS_THROUGH) {
|
|
65
|
-
value = message.text;
|
|
66
|
-
}
|
|
67
|
-
if (value) {
|
|
68
|
-
prompt = prompt.replaceAll(`{${input.name}}`, value);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const answer = await ai.run('@cf/meta/llama-3.1-8b-instruct', {
|
|
73
|
-
stream: false,
|
|
74
|
-
prompt,
|
|
75
|
-
});
|
|
76
|
-
const response = { response: answer.response, prompt, message };
|
|
77
|
-
const textWithAnswer = message.text + '\n--------\n\n' + answer.response;
|
|
78
|
-
await space.crud.update({ id: messageId }, { text: textWithAnswer });
|
|
79
|
-
|
|
80
|
-
return new Response(JSON.stringify(response));
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const getContext = async ({ space }: any) => {
|
|
84
|
-
let context = '';
|
|
85
|
-
const { objects: docs } = await space.crud.query({ __typename: 'dxos.org/type/Document' }).run();
|
|
86
|
-
for (const doc of docs) {
|
|
87
|
-
const { content } = await space.crud.query({ id: doc.content }).first();
|
|
88
|
-
context += content + '\n\n';
|
|
89
|
-
}
|
|
90
|
-
return context;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
enum ChainInputType {
|
|
94
|
-
VALUE = 0,
|
|
95
|
-
PASS_THROUGH = 1,
|
|
96
|
-
RETRIEVER = 2,
|
|
97
|
-
FUNCTION = 3,
|
|
98
|
-
QUERY = 4,
|
|
99
|
-
RESOLVER = 5,
|
|
100
|
-
CONTEXT = 6,
|
|
101
|
-
SCHEMA = 7,
|
|
102
|
-
}
|
package/src/templates/chess.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
import { Chess } from 'https://esm.sh/chess.js@0.13.1';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Plays a random move in a chess game.
|
|
10
|
-
*/
|
|
11
|
-
export default async ({
|
|
12
|
-
event: {
|
|
13
|
-
data: { request },
|
|
14
|
-
},
|
|
15
|
-
context: { space },
|
|
16
|
-
}: any) => {
|
|
17
|
-
const {
|
|
18
|
-
data: {
|
|
19
|
-
objects: [gameId],
|
|
20
|
-
player = 'b',
|
|
21
|
-
},
|
|
22
|
-
} = await request.json();
|
|
23
|
-
|
|
24
|
-
const { pgn } = await space.crud.query({ id: gameId }).first();
|
|
25
|
-
const game = new Chess();
|
|
26
|
-
game.load_pgn(pgn);
|
|
27
|
-
if (game.turn() !== player) {
|
|
28
|
-
return new Response('Invalid turn', { status: 409 });
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const moves = game.moves();
|
|
32
|
-
const move = moves[Math.floor(Math.random() * moves.length)];
|
|
33
|
-
if (!move) {
|
|
34
|
-
return new Response('No legal moves', { status: 406 });
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
game.move(move);
|
|
38
|
-
const newPgn = game.pgn();
|
|
39
|
-
await space.crud.update({ id: gameId }, { pgn: newPgn });
|
|
40
|
-
return new Response(game.ascii());
|
|
41
|
-
};
|
package/src/templates/echo.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Echos the request data.
|
|
7
|
-
*/
|
|
8
|
-
export default async ({
|
|
9
|
-
event: {
|
|
10
|
-
data: { request },
|
|
11
|
-
},
|
|
12
|
-
}: any) => {
|
|
13
|
-
const data = await request.json();
|
|
14
|
-
return new Response(JSON.stringify(data ?? {}), { headers: { 'Content-Type': 'application/json' } });
|
|
15
|
-
};
|
package/src/templates/email.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Stores a message into ECHO Mailbox object.
|
|
7
|
-
*/
|
|
8
|
-
export default async ({
|
|
9
|
-
event: {
|
|
10
|
-
data: { request },
|
|
11
|
-
},
|
|
12
|
-
context: { space },
|
|
13
|
-
}: any) => {
|
|
14
|
-
const {
|
|
15
|
-
data: {
|
|
16
|
-
objects: [message],
|
|
17
|
-
},
|
|
18
|
-
} = await request.json();
|
|
19
|
-
|
|
20
|
-
const mailbox = await space.crud.query({ __typename: 'dxos.org/type/MailboxType' }).first();
|
|
21
|
-
if (!mailbox) {
|
|
22
|
-
return new Response('Mailbox not found.', { status: 500 });
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
await space.crud.push(
|
|
26
|
-
{ id: mailbox.id },
|
|
27
|
-
{
|
|
28
|
-
sender: { email: message.from },
|
|
29
|
-
timestamp: new Date(message.created).toISOString(),
|
|
30
|
-
text: message.body,
|
|
31
|
-
properties: {
|
|
32
|
-
subject: message.subject,
|
|
33
|
-
to: [{ email: message.to }],
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
);
|
|
37
|
-
return new Response(JSON.stringify(message));
|
|
38
|
-
};
|
package/src/templates/forex.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Returns the exchange rate between two currencies.
|
|
7
|
-
*/
|
|
8
|
-
export default async ({
|
|
9
|
-
event: {
|
|
10
|
-
data: { request },
|
|
11
|
-
},
|
|
12
|
-
}: any) => {
|
|
13
|
-
const { args: [from = 'EUR', to = 'USD'] = [] } = await request.json();
|
|
14
|
-
|
|
15
|
-
const res = await fetch(`https://free.ratesdb.com/v1/rates?from=${from}&to=${to}`);
|
|
16
|
-
const {
|
|
17
|
-
data: { rates },
|
|
18
|
-
} = await res.json();
|
|
19
|
-
|
|
20
|
-
return new Response(rates[to].toString());
|
|
21
|
-
};
|
package/src/templates.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
import chat from './templates/chat.ts?raw';
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
import chess from './templates/chess.ts?raw';
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
import echo from './templates/echo.ts?raw';
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
import email from './templates/email.ts?raw';
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
import forex from './templates/forex.ts?raw';
|
|
15
|
-
|
|
16
|
-
const removeHeader = (str: string) => str.split('\n').slice(4).join('\n');
|
|
17
|
-
|
|
18
|
-
export type Template = {
|
|
19
|
-
id: string;
|
|
20
|
-
name: string;
|
|
21
|
-
source: string;
|
|
22
|
-
presetId?: string;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const templates: Template[] = [
|
|
26
|
-
{
|
|
27
|
-
id: 'dxos.org/script/echo',
|
|
28
|
-
name: 'Echo',
|
|
29
|
-
source: removeHeader(echo),
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
id: 'dxos.org/script/forex',
|
|
33
|
-
name: 'Forex',
|
|
34
|
-
source: removeHeader(forex),
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
id: 'dxos.org/script/gpt',
|
|
38
|
-
name: 'Gpt',
|
|
39
|
-
source: removeHeader(chat),
|
|
40
|
-
presetId: 'dxos.org/function/gpt',
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
id: 'dxos.org/script/chess',
|
|
44
|
-
name: 'Chess',
|
|
45
|
-
source: removeHeader(chess),
|
|
46
|
-
presetId: 'dxos.org/function/chess',
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
id: 'dxos.org/script/email',
|
|
50
|
-
name: 'Email',
|
|
51
|
-
source: removeHeader(email),
|
|
52
|
-
presetId: 'dxos.org/function/email',
|
|
53
|
-
},
|
|
54
|
-
];
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|