@dxos/react-ui-canvas-compute 0.8.4-main.406dc2a → 0.8.4-main.43cb759274
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/LICENSE +102 -5
- package/dist/lib/browser/index.mjs +953 -1214
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +953 -1214
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/DiagnosticOverlay.d.ts.map +1 -1
- package/dist/types/src/compute-layout.d.ts.map +1 -1
- package/dist/types/src/compute.stories.d.ts +22 -1
- package/dist/types/src/compute.stories.d.ts.map +1 -1
- package/dist/types/src/graph/controller.d.ts +54 -53
- package/dist/types/src/graph/controller.d.ts.map +1 -1
- package/dist/types/src/graph/node-defs.d.ts.map +1 -1
- package/dist/types/src/hooks/useComputeGraphController.d.ts.map +1 -1
- package/dist/types/src/hooks/useComputeNodeState.d.ts +4 -5
- package/dist/types/src/hooks/useComputeNodeState.d.ts.map +1 -1
- package/dist/types/src/hooks/useGraphMonitor.d.ts +2 -2
- package/dist/types/src/hooks/useGraphMonitor.d.ts.map +1 -1
- package/dist/types/src/shapes/Append.d.ts +1 -1
- package/dist/types/src/shapes/Append.d.ts.map +1 -1
- package/dist/types/src/shapes/Array.d.ts +1 -1
- package/dist/types/src/shapes/Array.d.ts.map +1 -1
- package/dist/types/src/shapes/Audio.d.ts +1 -1
- package/dist/types/src/shapes/Audio.d.ts.map +1 -1
- package/dist/types/src/shapes/Beacon.d.ts +1 -1
- package/dist/types/src/shapes/Beacon.d.ts.map +1 -1
- package/dist/types/src/shapes/Boolean.d.ts +7 -7
- package/dist/types/src/shapes/Boolean.d.ts.map +1 -1
- package/dist/types/src/shapes/Chat.d.ts +1 -1
- package/dist/types/src/shapes/Chat.d.ts.map +1 -1
- package/dist/types/src/shapes/Constant.d.ts +1 -1
- package/dist/types/src/shapes/Constant.d.ts.map +1 -1
- package/dist/types/src/shapes/Database.d.ts +1 -1
- package/dist/types/src/shapes/Database.d.ts.map +1 -1
- package/dist/types/src/shapes/{Queue.d.ts → Feed.d.ts} +9 -9
- package/dist/types/src/shapes/Feed.d.ts.map +1 -0
- package/dist/types/src/shapes/Function.d.ts +1 -1
- package/dist/types/src/shapes/Function.d.ts.map +1 -1
- package/dist/types/src/shapes/Gpt.d.ts +1 -1
- package/dist/types/src/shapes/Gpt.d.ts.map +1 -1
- package/dist/types/src/shapes/GptRealtime.d.ts +1 -1
- package/dist/types/src/shapes/GptRealtime.d.ts.map +1 -1
- package/dist/types/src/shapes/Json.d.ts +2 -2
- package/dist/types/src/shapes/Json.d.ts.map +1 -1
- package/dist/types/src/shapes/Logic.d.ts +2 -2
- package/dist/types/src/shapes/Logic.d.ts.map +1 -1
- package/dist/types/src/shapes/RNG.d.ts +2 -2
- package/dist/types/src/shapes/RNG.d.ts.map +1 -1
- package/dist/types/src/shapes/Scope.d.ts +1 -1
- package/dist/types/src/shapes/Scope.d.ts.map +1 -1
- package/dist/types/src/shapes/Surface.d.ts +1 -1
- package/dist/types/src/shapes/Surface.d.ts.map +1 -1
- package/dist/types/src/shapes/Switch.d.ts +1 -1
- package/dist/types/src/shapes/Switch.d.ts.map +1 -1
- package/dist/types/src/shapes/Table.d.ts +1 -1
- package/dist/types/src/shapes/Table.d.ts.map +1 -1
- package/dist/types/src/shapes/Template.d.ts +2 -2
- package/dist/types/src/shapes/Template.d.ts.map +1 -1
- package/dist/types/src/shapes/Text.d.ts +1 -1
- package/dist/types/src/shapes/Text.d.ts.map +1 -1
- package/dist/types/src/shapes/TextToImage.d.ts +1 -1
- package/dist/types/src/shapes/TextToImage.d.ts.map +1 -1
- package/dist/types/src/shapes/Thread.d.ts +1 -1
- package/dist/types/src/shapes/Thread.d.ts.map +1 -1
- package/dist/types/src/shapes/Trigger.d.ts +10 -31
- package/dist/types/src/shapes/Trigger.d.ts.map +1 -1
- package/dist/types/src/shapes/common/Box.d.ts +4 -4
- package/dist/types/src/shapes/common/Box.d.ts.map +1 -1
- package/dist/types/src/shapes/common/FunctionBody.d.ts +2 -2
- package/dist/types/src/shapes/common/FunctionBody.d.ts.map +1 -1
- package/dist/types/src/shapes/common/TypeSelect.d.ts +1 -1
- package/dist/types/src/shapes/common/TypeSelect.d.ts.map +1 -1
- package/dist/types/src/shapes/defs.d.ts +1 -1
- package/dist/types/src/shapes/defs.d.ts.map +1 -1
- package/dist/types/src/shapes/index.d.ts +2 -2
- package/dist/types/src/shapes/index.d.ts.map +1 -1
- package/dist/types/src/testing/circuits.d.ts +18 -24
- package/dist/types/src/testing/circuits.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +62 -58
- package/src/README.md +0 -3
- package/src/compute.stories.tsx +90 -115
- package/src/graph/controller.ts +154 -79
- package/src/graph/node-defs.ts +31 -31
- package/src/hooks/useComputeNodeState.ts +7 -8
- package/src/hooks/useGraphMonitor.ts +11 -10
- package/src/json.test.ts +3 -3
- package/src/registry.ts +2 -2
- package/src/schema.test.ts +11 -11
- package/src/shapes/Audio.tsx +1 -2
- package/src/shapes/Beacon.tsx +0 -1
- package/src/shapes/Boolean.tsx +1 -1
- package/src/shapes/Chat.tsx +0 -1
- package/src/shapes/Constant.tsx +0 -1
- package/src/shapes/{Queue.tsx → Feed.tsx} +26 -21
- package/src/shapes/Function.tsx +13 -10
- package/src/shapes/Gpt.tsx +6 -2
- package/src/shapes/Json.tsx +9 -3
- package/src/shapes/RNG.tsx +5 -2
- package/src/shapes/Scope.tsx +0 -1
- package/src/shapes/Surface.tsx +12 -4
- package/src/shapes/Switch.tsx +0 -1
- package/src/shapes/Table.tsx +4 -3
- package/src/shapes/Template.tsx +0 -1
- package/src/shapes/Text.tsx +0 -1
- package/src/shapes/Thread.tsx +13 -10
- package/src/shapes/Trigger.tsx +43 -53
- package/src/shapes/common/Box.tsx +6 -9
- package/src/shapes/common/FunctionBody.tsx +2 -2
- package/src/shapes/common/TypeSelect.tsx +1 -1
- package/src/shapes/defs.ts +3 -3
- package/src/shapes/index.ts +2 -2
- package/src/testing/circuits.ts +9 -18
- package/dist/types/src/shapes/Queue.d.ts.map +0 -1
package/src/shapes/Boolean.tsx
CHANGED
|
@@ -95,7 +95,7 @@ const createSymbol =
|
|
|
95
95
|
const paths = pathConstructor({ startX, endX, height });
|
|
96
96
|
|
|
97
97
|
return (
|
|
98
|
-
<svg viewBox={`0 0 ${width} ${height}`} className='
|
|
98
|
+
<svg viewBox={`0 0 ${width} ${height}`} className='h-full w-full'>
|
|
99
99
|
{/* Input line. */}
|
|
100
100
|
{getAnchorPoints({ x: 0, y: centerY }, inputs).map(({ x, y }, i) => (
|
|
101
101
|
<line key={i} x1={x} y1={y} x2={startX * 1.3} y2={y} strokeWidth={strokeWidth} className={className} />
|
package/src/shapes/Chat.tsx
CHANGED
|
@@ -16,7 +16,6 @@ import {
|
|
|
16
16
|
import { createAnchorMap } from '@dxos/react-ui-canvas-editor';
|
|
17
17
|
|
|
18
18
|
import { useComputeNodeState } from '../hooks';
|
|
19
|
-
|
|
20
19
|
import { Box } from './common';
|
|
21
20
|
import { ComputeShape, type CreateShapeProps, createAnchorId, createShape } from './defs';
|
|
22
21
|
|
package/src/shapes/Constant.tsx
CHANGED
|
@@ -18,7 +18,6 @@ import { createAnchorMap } from '@dxos/react-ui-canvas-editor';
|
|
|
18
18
|
import { safeParseJson } from '@dxos/util';
|
|
19
19
|
|
|
20
20
|
import { useComputeNodeState } from '../hooks';
|
|
21
|
-
|
|
22
21
|
import { Box, TypeSelect } from './common';
|
|
23
22
|
import { ComputeShape, type CreateShapeProps, createAnchorId, createShape } from './defs';
|
|
24
23
|
|
|
@@ -6,31 +6,34 @@ import * as Schema from 'effect/Schema';
|
|
|
6
6
|
import React, { Fragment } from 'react';
|
|
7
7
|
|
|
8
8
|
import { DEFAULT_OUTPUT, QueueInput, QueueOutput } from '@dxos/conductor';
|
|
9
|
-
import { type ThemedClassName } from '@dxos/react-ui';
|
|
9
|
+
import { ScrollArea, type ThemedClassName } from '@dxos/react-ui';
|
|
10
10
|
import { type ShapeComponentProps, type ShapeDef } from '@dxos/react-ui-canvas-editor';
|
|
11
|
-
import { mx } from '@dxos/
|
|
11
|
+
import { mx } from '@dxos/ui-theme';
|
|
12
12
|
|
|
13
13
|
import { useComputeNodeState } from '../hooks';
|
|
14
|
-
|
|
15
14
|
import { createFunctionAnchors } from './common';
|
|
16
15
|
import { Box, type BoxActionHandler } from './common';
|
|
17
16
|
import { ComputeShape, type CreateShapeProps, createShape } from './defs';
|
|
18
17
|
|
|
19
|
-
export const
|
|
18
|
+
export const FeedShape = Schema.extend(
|
|
20
19
|
ComputeShape,
|
|
21
20
|
Schema.Struct({
|
|
22
21
|
type: Schema.Literal('queue'),
|
|
23
22
|
}),
|
|
24
23
|
);
|
|
25
24
|
|
|
26
|
-
export type
|
|
25
|
+
export type FeedShape = Schema.Schema.Type<typeof FeedShape>;
|
|
27
26
|
|
|
28
|
-
export type
|
|
27
|
+
export type CreateFeedProps = CreateShapeProps<FeedShape>;
|
|
29
28
|
|
|
30
|
-
export const
|
|
31
|
-
createShape<
|
|
29
|
+
export const createFeed = (props: CreateFeedProps) =>
|
|
30
|
+
createShape<FeedShape>({
|
|
31
|
+
type: 'queue',
|
|
32
|
+
size: { width: 256, height: 512 },
|
|
33
|
+
...props,
|
|
34
|
+
});
|
|
32
35
|
|
|
33
|
-
export const
|
|
36
|
+
export const FeedComponent = ({ shape }: ShapeComponentProps<FeedShape>) => {
|
|
34
37
|
const { runtime } = useComputeNodeState(shape);
|
|
35
38
|
const items = runtime.outputs[DEFAULT_OUTPUT]?.type === 'executed' ? runtime.outputs[DEFAULT_OUTPUT].value : [];
|
|
36
39
|
|
|
@@ -42,22 +45,24 @@ export const QueueComponent = ({ shape }: ShapeComponentProps<QueueShape>) => {
|
|
|
42
45
|
|
|
43
46
|
return (
|
|
44
47
|
<Box shape={shape} status={`${items.length} items`} onAction={handleAction}>
|
|
45
|
-
<
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
<ScrollArea.Root orientation='vertical'>
|
|
49
|
+
<ScrollArea.Viewport classNames='divide-y divide-separator'>
|
|
50
|
+
{[...items].map((item, i) => (
|
|
51
|
+
<FeedItem key={i} classNames='p-1 px-2' item={item} />
|
|
52
|
+
))}
|
|
53
|
+
</ScrollArea.Viewport>
|
|
54
|
+
</ScrollArea.Root>
|
|
50
55
|
</Box>
|
|
51
56
|
);
|
|
52
57
|
};
|
|
53
58
|
|
|
54
|
-
export const
|
|
59
|
+
export const FeedItem = ({ classNames, item }: ThemedClassName<{ item: any }>) => {
|
|
55
60
|
if (typeof item !== 'object') {
|
|
56
61
|
return <div className={mx(classNames, 'whitespace-pre-wrap')}>{item}</div>;
|
|
57
62
|
}
|
|
58
63
|
|
|
59
64
|
return (
|
|
60
|
-
<div className={mx('grid grid-cols-[
|
|
65
|
+
<div className={mx('grid grid-cols-[80px_1fr]', classNames)}>
|
|
61
66
|
{Object.entries(item).map(([key, value]) => (
|
|
62
67
|
<Fragment key={key}>
|
|
63
68
|
<div className='p-1 text-xs text-subdued'>{key}</div>
|
|
@@ -68,12 +73,12 @@ export const QueueItem = ({ classNames, item }: ThemedClassName<{ item: any }>)
|
|
|
68
73
|
);
|
|
69
74
|
};
|
|
70
75
|
|
|
71
|
-
export const
|
|
72
|
-
type: '
|
|
73
|
-
name: '
|
|
76
|
+
export const feedShape: ShapeDef<FeedShape> = {
|
|
77
|
+
type: 'feed',
|
|
78
|
+
name: 'Feed',
|
|
74
79
|
icon: 'ph--queue--regular',
|
|
75
|
-
component:
|
|
76
|
-
createShape:
|
|
80
|
+
component: FeedComponent,
|
|
81
|
+
createShape: createFeed,
|
|
77
82
|
getAnchors: (shape) => createFunctionAnchors(shape, QueueInput, QueueOutput),
|
|
78
83
|
resizable: true,
|
|
79
84
|
};
|
package/src/shapes/Function.tsx
CHANGED
|
@@ -5,11 +5,13 @@
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
import React, { useCallback, useRef } from 'react';
|
|
7
7
|
|
|
8
|
+
import { Script } from '@dxos/compute';
|
|
9
|
+
import { Operation } from '@dxos/compute';
|
|
8
10
|
import { AnyOutput, FunctionInput } from '@dxos/conductor';
|
|
11
|
+
import { Filter } from '@dxos/echo';
|
|
9
12
|
import { Ref, getSnapshot, isInstanceOf } from '@dxos/echo/internal';
|
|
10
|
-
import {
|
|
13
|
+
import { parseId } from '@dxos/keys';
|
|
11
14
|
import { useClient } from '@dxos/react-client';
|
|
12
|
-
import { Filter, parseId } from '@dxos/react-client/echo';
|
|
13
15
|
import {
|
|
14
16
|
type ShapeComponentProps,
|
|
15
17
|
type ShapeDef,
|
|
@@ -19,7 +21,6 @@ import {
|
|
|
19
21
|
} from '@dxos/react-ui-canvas-editor';
|
|
20
22
|
|
|
21
23
|
import { useComputeNodeState } from '../hooks';
|
|
22
|
-
|
|
23
24
|
import { Box, createFunctionAnchors } from './common';
|
|
24
25
|
import { ComputeShape, type CreateShapeProps, createShape } from './defs';
|
|
25
26
|
|
|
@@ -35,7 +36,11 @@ export type FunctionShape = Schema.Schema.Type<typeof FunctionShape>;
|
|
|
35
36
|
export type CreateFunctionProps = CreateShapeProps<FunctionShape>;
|
|
36
37
|
|
|
37
38
|
export const createFunction = (props: CreateFunctionProps) =>
|
|
38
|
-
createShape<FunctionShape>({
|
|
39
|
+
createShape<FunctionShape>({
|
|
40
|
+
type: 'function',
|
|
41
|
+
size: { width: 256, height: 192 },
|
|
42
|
+
...props,
|
|
43
|
+
});
|
|
39
44
|
|
|
40
45
|
//
|
|
41
46
|
// Component
|
|
@@ -58,21 +63,19 @@ const TextInputComponent = ({ shape, title, ...props }: TextInputComponentProps)
|
|
|
58
63
|
|
|
59
64
|
const space = client.spaces.get(spaceId);
|
|
60
65
|
const object = space?.db.getObjectById(objectId);
|
|
61
|
-
if (!space || !isInstanceOf(
|
|
66
|
+
if (!space || !isInstanceOf(Script.Script, object)) {
|
|
62
67
|
return;
|
|
63
68
|
}
|
|
64
69
|
|
|
65
|
-
const {
|
|
66
|
-
objects: [fn],
|
|
67
|
-
} = await space.db.query(Filter.type(FunctionType, { source: Ref.make(object) })).run();
|
|
70
|
+
const [fn] = await space.db.query(Filter.type(Operation.PersistentOperation, { source: Ref.make(object) })).run();
|
|
68
71
|
if (!fn) {
|
|
69
72
|
return;
|
|
70
73
|
}
|
|
71
74
|
|
|
72
75
|
node.value = value;
|
|
73
76
|
node.function = Ref.make(fn);
|
|
74
|
-
node.inputSchema = getSnapshot(fn.inputSchema);
|
|
75
|
-
node.outputSchema = getSnapshot(fn.outputSchema);
|
|
77
|
+
node.inputSchema = fn.inputSchema ? getSnapshot(fn.inputSchema) : undefined;
|
|
78
|
+
node.outputSchema = fn.outputSchema ? getSnapshot(fn.outputSchema) : undefined;
|
|
76
79
|
},
|
|
77
80
|
[client, node],
|
|
78
81
|
);
|
package/src/shapes/Gpt.tsx
CHANGED
|
@@ -6,10 +6,10 @@ import * as Schema from 'effect/Schema';
|
|
|
6
6
|
import React, { useEffect, useState } from 'react';
|
|
7
7
|
|
|
8
8
|
import { GptInput, GptOutput } from '@dxos/conductor';
|
|
9
|
+
import { ScrollArea } from '@dxos/react-ui';
|
|
9
10
|
import { type ShapeComponentProps, type ShapeDef } from '@dxos/react-ui-canvas-editor';
|
|
10
11
|
|
|
11
12
|
import { useComputeNodeState } from '../hooks';
|
|
12
|
-
|
|
13
13
|
import { FunctionBody, createFunctionAnchors, getHeight } from './common';
|
|
14
14
|
import { ComputeShape, type CreateShapeProps, createShape } from './defs';
|
|
15
15
|
|
|
@@ -74,7 +74,11 @@ export const GptComponent = ({ shape }: ShapeComponentProps<GptShape>) => {
|
|
|
74
74
|
return (
|
|
75
75
|
<FunctionBody
|
|
76
76
|
shape={shape}
|
|
77
|
-
content={
|
|
77
|
+
content={
|
|
78
|
+
<ScrollArea.Root orientation='vertical' thin>
|
|
79
|
+
<ScrollArea.Viewport>{text}</ScrollArea.Viewport>
|
|
80
|
+
</ScrollArea.Root>
|
|
81
|
+
}
|
|
78
82
|
status={`${tokens} tokens`}
|
|
79
83
|
inputSchema={meta.input}
|
|
80
84
|
outputSchema={meta.output}
|
package/src/shapes/Json.tsx
CHANGED
|
@@ -8,10 +8,9 @@ import React from 'react';
|
|
|
8
8
|
import { DEFAULT_INPUT, DefaultOutput, JsonTransformInput } from '@dxos/conductor';
|
|
9
9
|
import { type ShapeComponentProps, type ShapeDef } from '@dxos/react-ui-canvas-editor';
|
|
10
10
|
import { createAnchorMap } from '@dxos/react-ui-canvas-editor';
|
|
11
|
-
import {
|
|
11
|
+
import { Syntax } from '@dxos/react-ui-syntax-highlighter';
|
|
12
12
|
|
|
13
13
|
import { useComputeNodeState } from '../hooks';
|
|
14
|
-
|
|
15
14
|
import { Box, createFunctionAnchors, getHeight } from './common';
|
|
16
15
|
import { ComputeShape, type CreateShapeProps, createAnchorId, createShape } from './defs';
|
|
17
16
|
|
|
@@ -50,7 +49,14 @@ export const JsonComponent = ({ shape, ...props }: JsonComponentProps) => {
|
|
|
50
49
|
|
|
51
50
|
return (
|
|
52
51
|
<Box shape={shape}>
|
|
53
|
-
<
|
|
52
|
+
<Syntax.Root data={value}>
|
|
53
|
+
<Syntax.Content>
|
|
54
|
+
<Syntax.Filter />
|
|
55
|
+
<Syntax.Viewport>
|
|
56
|
+
<Syntax.Code classNames='text-xs' />
|
|
57
|
+
</Syntax.Viewport>
|
|
58
|
+
</Syntax.Content>
|
|
59
|
+
</Syntax.Root>
|
|
54
60
|
</Box>
|
|
55
61
|
);
|
|
56
62
|
};
|
package/src/shapes/RNG.tsx
CHANGED
|
@@ -10,7 +10,6 @@ import { Icon, type IconProps } from '@dxos/react-ui';
|
|
|
10
10
|
import { type ShapeComponentProps, type ShapeDef, createAnchorMap } from '@dxos/react-ui-canvas-editor';
|
|
11
11
|
|
|
12
12
|
import { useComputeNodeState } from '../hooks';
|
|
13
|
-
|
|
14
13
|
import { ComputeShape, type CreateShapeProps, createAnchorId, createShape } from './defs';
|
|
15
14
|
|
|
16
15
|
export const RandomShape = Schema.extend(
|
|
@@ -27,7 +26,11 @@ export type RandomShape = Schema.Schema.Type<typeof RandomShape>;
|
|
|
27
26
|
export type CreateRandomProps = CreateShapeProps<RandomShape>;
|
|
28
27
|
|
|
29
28
|
export const createRandom = (props: CreateRandomProps) =>
|
|
30
|
-
createShape<RandomShape>({
|
|
29
|
+
createShape<RandomShape>({
|
|
30
|
+
type: 'rng',
|
|
31
|
+
size: { width: 64, height: 64 },
|
|
32
|
+
...props,
|
|
33
|
+
});
|
|
31
34
|
|
|
32
35
|
const icons = [
|
|
33
36
|
'ph--dice-one--regular',
|
package/src/shapes/Scope.tsx
CHANGED
|
@@ -10,7 +10,6 @@ import { type ShapeComponentProps, type ShapeDef, createAnchorMap } from '@dxos/
|
|
|
10
10
|
import { Chaos, shaderPresets, useAudioStream } from '@dxos/react-ui-sfx';
|
|
11
11
|
|
|
12
12
|
import { useComputeNodeState } from '../hooks';
|
|
13
|
-
|
|
14
13
|
import { ComputeShape, type CreateShapeProps, createAnchorId, createShape } from './defs';
|
|
15
14
|
|
|
16
15
|
export const ScopeShape = Schema.extend(
|
package/src/shapes/Surface.tsx
CHANGED
|
@@ -5,13 +5,14 @@
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
import React from 'react';
|
|
7
7
|
|
|
8
|
-
import { Surface } from '@dxos/app-framework';
|
|
8
|
+
import { Surface } from '@dxos/app-framework/ui';
|
|
9
|
+
import { AppSurface } from '@dxos/app-toolkit/ui';
|
|
9
10
|
import { DEFAULT_INPUT } from '@dxos/conductor';
|
|
11
|
+
import { Card } from '@dxos/react-ui';
|
|
10
12
|
import { type ShapeComponentProps, type ShapeDef } from '@dxos/react-ui-canvas-editor';
|
|
11
13
|
import { createAnchorMap } from '@dxos/react-ui-canvas-editor';
|
|
12
14
|
|
|
13
15
|
import { useComputeNodeState } from '../hooks';
|
|
14
|
-
|
|
15
16
|
import { Box, type BoxActionHandler } from './common';
|
|
16
17
|
import { ComputeShape, type CreateShapeProps, createAnchorId, createShape } from './defs';
|
|
17
18
|
|
|
@@ -27,7 +28,11 @@ export type SurfaceShape = Schema.Schema.Type<typeof SurfaceShape>;
|
|
|
27
28
|
export type CreateSurfaceProps = CreateShapeProps<SurfaceShape>;
|
|
28
29
|
|
|
29
30
|
export const createSurface = (props: CreateSurfaceProps) =>
|
|
30
|
-
createShape<SurfaceShape>({
|
|
31
|
+
createShape<SurfaceShape>({
|
|
32
|
+
type: 'surface',
|
|
33
|
+
size: { width: 384, height: 384 },
|
|
34
|
+
...props,
|
|
35
|
+
});
|
|
31
36
|
|
|
32
37
|
export const SurfaceComponent = ({ shape }: ShapeComponentProps<SurfaceShape>) => {
|
|
33
38
|
const { runtime } = useComputeNodeState(shape);
|
|
@@ -40,9 +45,12 @@ export const SurfaceComponent = ({ shape }: ShapeComponentProps<SurfaceShape>) =
|
|
|
40
45
|
}
|
|
41
46
|
};
|
|
42
47
|
|
|
48
|
+
// TODO(burdon): Subject property?
|
|
43
49
|
return (
|
|
44
50
|
<Box shape={shape} onAction={handleAction}>
|
|
45
|
-
|
|
51
|
+
<Card.Root>
|
|
52
|
+
{value !== null && <Surface.Surface type={AppSurface.Card} data={{ subject: value }} limit={1} />}
|
|
53
|
+
</Card.Root>
|
|
46
54
|
</Box>
|
|
47
55
|
);
|
|
48
56
|
};
|
package/src/shapes/Switch.tsx
CHANGED
|
@@ -10,7 +10,6 @@ import { Input } from '@dxos/react-ui';
|
|
|
10
10
|
import { type ShapeComponentProps, type ShapeDef, createAnchorMap } from '@dxos/react-ui-canvas-editor';
|
|
11
11
|
|
|
12
12
|
import { useComputeNodeState } from '../hooks';
|
|
13
|
-
|
|
14
13
|
import { ComputeShape, type CreateShapeProps, createAnchorId, createShape } from './defs';
|
|
15
14
|
|
|
16
15
|
export const SwitchShape = Schema.extend(
|
package/src/shapes/Table.tsx
CHANGED
|
@@ -6,14 +6,15 @@ import * as Schema from 'effect/Schema';
|
|
|
6
6
|
import React from 'react';
|
|
7
7
|
|
|
8
8
|
import { createInputSchema, createOutputSchema } from '@dxos/conductor';
|
|
9
|
+
import { Type } from '@dxos/echo';
|
|
9
10
|
import { type ShapeComponentProps, type ShapeDef } from '@dxos/react-ui-canvas-editor';
|
|
10
|
-
import {
|
|
11
|
+
import { Message } from '@dxos/types';
|
|
11
12
|
|
|
12
13
|
import { Box, createFunctionAnchors } from './common';
|
|
13
14
|
import { ComputeShape, type CreateShapeProps, createShape } from './defs';
|
|
14
15
|
|
|
15
|
-
const InputSchema = createInputSchema(
|
|
16
|
-
const OutputSchema = createOutputSchema(Schema.mutable(Schema.Array(
|
|
16
|
+
const InputSchema = createInputSchema(Type.getSchema(Message.Message));
|
|
17
|
+
const OutputSchema = createOutputSchema(Schema.mutable(Schema.Array(Type.getSchema(Message.Message))));
|
|
17
18
|
|
|
18
19
|
export const TableShape = Schema.extend(
|
|
19
20
|
ComputeShape,
|
package/src/shapes/Template.tsx
CHANGED
package/src/shapes/Text.tsx
CHANGED
|
@@ -10,7 +10,6 @@ import { type ShapeComponentProps, type ShapeDef, TextBox } from '@dxos/react-ui
|
|
|
10
10
|
import { createAnchorMap } from '@dxos/react-ui-canvas-editor';
|
|
11
11
|
|
|
12
12
|
import { useComputeNodeState } from '../hooks';
|
|
13
|
-
|
|
14
13
|
import { Box, type BoxActionHandler } from './common';
|
|
15
14
|
import { ComputeShape, type CreateShapeProps, createAnchorId, createShape } from './defs';
|
|
16
15
|
|
package/src/shapes/Thread.tsx
CHANGED
|
@@ -6,16 +6,17 @@ import * as Schema from 'effect/Schema';
|
|
|
6
6
|
import React, { useEffect, useRef } from 'react';
|
|
7
7
|
|
|
8
8
|
import { createInputSchema, createOutputSchema } from '@dxos/conductor';
|
|
9
|
-
import {
|
|
9
|
+
import { Type } from '@dxos/echo';
|
|
10
|
+
import { ScrollArea, type ThemedClassName } from '@dxos/react-ui';
|
|
10
11
|
import { type ShapeComponentProps, type ShapeDef } from '@dxos/react-ui-canvas-editor';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
12
|
+
import { Message } from '@dxos/types';
|
|
13
|
+
import { mx } from '@dxos/ui-theme';
|
|
13
14
|
|
|
14
15
|
import { Box, createFunctionAnchors } from './common';
|
|
15
16
|
import { ComputeShape, type CreateShapeProps, createShape } from './defs';
|
|
16
17
|
|
|
17
|
-
const InputSchema = createInputSchema(
|
|
18
|
-
const OutputSchema = createOutputSchema(Schema.mutable(Schema.Array(
|
|
18
|
+
const InputSchema = createInputSchema(Type.getSchema(Message.Message));
|
|
19
|
+
const OutputSchema = createOutputSchema(Schema.mutable(Schema.Array(Type.getSchema(Message.Message))));
|
|
19
20
|
|
|
20
21
|
export const ThreadShape = Schema.extend(
|
|
21
22
|
ComputeShape,
|
|
@@ -42,11 +43,13 @@ export const ThreadComponent = ({ shape }: ShapeComponentProps<ThreadShape>) =>
|
|
|
42
43
|
|
|
43
44
|
return (
|
|
44
45
|
<Box shape={shape}>
|
|
45
|
-
<
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
<ScrollArea.Root orientation='vertical'>
|
|
47
|
+
<ScrollArea.Viewport classNames='gap-2 p-2' ref={scrollRef}>
|
|
48
|
+
{[...items].map((item, i) => (
|
|
49
|
+
<ThreadItem key={i} item={item} />
|
|
50
|
+
))}
|
|
51
|
+
</ScrollArea.Viewport>
|
|
52
|
+
</ScrollArea.Root>
|
|
50
53
|
</Box>
|
|
51
54
|
);
|
|
52
55
|
};
|
package/src/shapes/Trigger.tsx
CHANGED
|
@@ -5,56 +5,48 @@
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
import React, { useEffect } from 'react';
|
|
7
7
|
|
|
8
|
+
import { Trigger, TriggerEvent } from '@dxos/compute';
|
|
8
9
|
import { VoidInput } from '@dxos/conductor';
|
|
9
|
-
import { Filter, Obj, Query } from '@dxos/echo';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
EmailTriggerOutput,
|
|
14
|
-
FunctionTrigger,
|
|
15
|
-
type QueueTrigger,
|
|
16
|
-
QueueTriggerOutput,
|
|
17
|
-
type SubscriptionTrigger,
|
|
18
|
-
SubscriptionTriggerOutput,
|
|
19
|
-
type TimerTrigger,
|
|
20
|
-
TimerTriggerOutput,
|
|
21
|
-
type TriggerKind,
|
|
22
|
-
TriggerKinds,
|
|
23
|
-
type TriggerType,
|
|
24
|
-
type WebhookTrigger,
|
|
25
|
-
WebhookTriggerOutput,
|
|
26
|
-
} from '@dxos/functions';
|
|
27
|
-
import { DXN, SpaceId } from '@dxos/keys';
|
|
28
|
-
import { useSpace } from '@dxos/react-client/echo';
|
|
10
|
+
import { Filter, Obj, Query, Ref } from '@dxos/echo';
|
|
11
|
+
import { type Mutable } from '@dxos/echo/internal';
|
|
12
|
+
import { type SpaceId } from '@dxos/keys';
|
|
13
|
+
import { useSpaces } from '@dxos/react-client/echo';
|
|
29
14
|
import { Select, type SelectRootProps } from '@dxos/react-ui';
|
|
30
15
|
import { type ShapeComponentProps, type ShapeDef } from '@dxos/react-ui-canvas-editor';
|
|
31
16
|
|
|
32
17
|
import { FunctionBody, createFunctionAnchors, getHeight } from './common';
|
|
33
18
|
import { ComputeShape, type CreateShapeProps, createShape } from './defs';
|
|
34
19
|
|
|
35
|
-
|
|
20
|
+
const TriggerShapeSchema = Schema.extend(
|
|
36
21
|
ComputeShape,
|
|
37
22
|
Schema.Struct({
|
|
38
23
|
type: Schema.Literal('trigger'),
|
|
39
|
-
functionTrigger: Schema.optional(Ref(
|
|
24
|
+
functionTrigger: Schema.optional(Ref.Ref(Trigger.Trigger)),
|
|
40
25
|
}),
|
|
41
26
|
);
|
|
42
|
-
|
|
27
|
+
|
|
28
|
+
// TODO(wittjosiah): Try to clean up this type inference.
|
|
29
|
+
export interface TriggerShape extends ComputeShape {
|
|
30
|
+
type: 'trigger';
|
|
31
|
+
functionTrigger?: Ref.Ref<Trigger.Trigger>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const TriggerShape: Schema.Schema<TriggerShape> = TriggerShapeSchema as any;
|
|
43
35
|
|
|
44
36
|
export type CreateTriggerProps = CreateShapeProps<Omit<TriggerShape, 'functionTrigger'>> & {
|
|
45
37
|
spaceId?: SpaceId;
|
|
46
|
-
triggerKind?:
|
|
38
|
+
triggerKind?: Trigger.Kind;
|
|
47
39
|
};
|
|
48
40
|
|
|
49
41
|
export const createTrigger = (props: CreateTriggerProps): TriggerShape => {
|
|
50
|
-
const functionTrigger =
|
|
42
|
+
const functionTrigger = Trigger.make({
|
|
51
43
|
enabled: true,
|
|
52
44
|
spec: createTriggerSpec(props),
|
|
53
45
|
});
|
|
54
46
|
return createShape<TriggerShape>({
|
|
55
47
|
type: 'trigger',
|
|
56
48
|
functionTrigger: Ref.make(functionTrigger),
|
|
57
|
-
size: { width: 192, height: getHeight(
|
|
49
|
+
size: { width: 192, height: getHeight(TriggerEvent.EmailEvent) },
|
|
58
50
|
...props,
|
|
59
51
|
});
|
|
60
52
|
};
|
|
@@ -62,12 +54,14 @@ export const createTrigger = (props: CreateTriggerProps): TriggerShape => {
|
|
|
62
54
|
export type TriggerComponentProps = ShapeComponentProps<TriggerShape>;
|
|
63
55
|
|
|
64
56
|
export const TriggerComponent = ({ shape }: TriggerComponentProps) => {
|
|
65
|
-
const space =
|
|
57
|
+
const [space] = useSpaces();
|
|
66
58
|
const functionTrigger = shape.functionTrigger?.target;
|
|
67
59
|
|
|
68
60
|
useEffect(() => {
|
|
69
61
|
if (functionTrigger && !functionTrigger.spec) {
|
|
70
|
-
|
|
62
|
+
Obj.update(functionTrigger, (functionTrigger) => {
|
|
63
|
+
functionTrigger.spec = createTriggerSpec({ triggerKind: 'email', spaceId: space?.id }) as Mutable<Trigger.Spec>;
|
|
64
|
+
});
|
|
71
65
|
}
|
|
72
66
|
}, [functionTrigger, functionTrigger?.spec]);
|
|
73
67
|
|
|
@@ -75,9 +69,11 @@ export const TriggerComponent = ({ shape }: TriggerComponentProps) => {
|
|
|
75
69
|
shape.size.height = getHeight(getOutputSchema(functionTrigger?.spec?.kind ?? 'email'));
|
|
76
70
|
}, [functionTrigger?.spec?.kind]);
|
|
77
71
|
|
|
78
|
-
const setKind = (kind:
|
|
72
|
+
const setKind = (kind: Trigger.Kind) => {
|
|
79
73
|
if (functionTrigger?.spec?.kind !== kind) {
|
|
80
|
-
functionTrigger
|
|
74
|
+
Obj.update(functionTrigger!, (obj) => {
|
|
75
|
+
obj.spec = createTriggerSpec({ triggerKind: kind, spaceId: space?.id }) as Mutable<Trigger.Spec>;
|
|
76
|
+
});
|
|
81
77
|
}
|
|
82
78
|
};
|
|
83
79
|
|
|
@@ -89,7 +85,7 @@ export const TriggerComponent = ({ shape }: TriggerComponentProps) => {
|
|
|
89
85
|
<FunctionBody
|
|
90
86
|
shape={shape}
|
|
91
87
|
status={
|
|
92
|
-
<TriggerKindSelect value={functionTrigger.spec?.kind} onValueChange={(kind) => setKind(kind as
|
|
88
|
+
<TriggerKindSelect value={functionTrigger.spec?.kind} onValueChange={(kind) => setKind(kind as Trigger.Kind)} />
|
|
93
89
|
}
|
|
94
90
|
inputSchema={VoidInput}
|
|
95
91
|
outputSchema={getOutputSchema(functionTrigger.spec!.kind!)}
|
|
@@ -101,12 +97,12 @@ export const TriggerComponent = ({ shape }: TriggerComponentProps) => {
|
|
|
101
97
|
const TriggerKindSelect = ({ value, onValueChange }: Pick<SelectRootProps, 'value' | 'onValueChange'>) => {
|
|
102
98
|
return (
|
|
103
99
|
<Select.Root value={value} onValueChange={onValueChange}>
|
|
104
|
-
<Select.TriggerButton variant='ghost' classNames='w-full
|
|
100
|
+
<Select.TriggerButton variant='ghost' classNames='w-full px-0!' />
|
|
105
101
|
<Select.Portal>
|
|
106
102
|
<Select.Content>
|
|
107
103
|
<Select.ScrollUpButton />
|
|
108
104
|
<Select.Viewport>
|
|
109
|
-
{
|
|
105
|
+
{Trigger.Kinds.map((kind) => (
|
|
110
106
|
<Select.Option key={kind} value={kind}>
|
|
111
107
|
{kind}
|
|
112
108
|
</Select.Option>
|
|
@@ -120,36 +116,30 @@ const TriggerKindSelect = ({ value, onValueChange }: Pick<SelectRootProps, 'valu
|
|
|
120
116
|
);
|
|
121
117
|
};
|
|
122
118
|
|
|
123
|
-
const createTriggerSpec = (props: { triggerKind?:
|
|
119
|
+
const createTriggerSpec = (props: { triggerKind?: Trigger.Kind; spaceId?: SpaceId }): Trigger.Spec => {
|
|
124
120
|
const kind = props.triggerKind ?? 'email';
|
|
125
121
|
switch (kind) {
|
|
126
122
|
case 'timer':
|
|
127
|
-
return
|
|
123
|
+
return Trigger.specTimer('*/10 * * * * *');
|
|
128
124
|
case 'webhook':
|
|
129
|
-
return {
|
|
125
|
+
return Trigger.specWebhook({ method: 'POST' });
|
|
130
126
|
case 'subscription':
|
|
131
|
-
return
|
|
132
|
-
kind: 'subscription',
|
|
133
|
-
query: {
|
|
134
|
-
ast: Query.select(Filter.nothing()).ast,
|
|
135
|
-
},
|
|
136
|
-
} satisfies SubscriptionTrigger;
|
|
127
|
+
return Trigger.specSubscription(Query.select(Filter.nothing()));
|
|
137
128
|
case 'email':
|
|
138
|
-
return
|
|
139
|
-
case '
|
|
140
|
-
|
|
141
|
-
return { kind: 'queue', queue: dxn } satisfies QueueTrigger;
|
|
129
|
+
return Trigger.specEmail();
|
|
130
|
+
case 'feed': {
|
|
131
|
+
return { kind: 'feed' } satisfies Trigger.FeedSpec;
|
|
142
132
|
}
|
|
143
133
|
}
|
|
144
134
|
};
|
|
145
135
|
|
|
146
|
-
const getOutputSchema = (kind:
|
|
147
|
-
const kindToSchema: Record<
|
|
148
|
-
['email']:
|
|
149
|
-
['subscription']:
|
|
150
|
-
['timer']:
|
|
151
|
-
['webhook']:
|
|
152
|
-
['
|
|
136
|
+
const getOutputSchema = (kind: Trigger.Kind) => {
|
|
137
|
+
const kindToSchema: Record<Trigger.Kind, Schema.Schema<any>> = {
|
|
138
|
+
['email']: TriggerEvent.EmailEvent,
|
|
139
|
+
['subscription']: TriggerEvent.SubscriptionEvent,
|
|
140
|
+
['timer']: TriggerEvent.TimerEvent,
|
|
141
|
+
['webhook']: TriggerEvent.WebhookEvent,
|
|
142
|
+
['feed']: TriggerEvent.FeedEvent,
|
|
153
143
|
};
|
|
154
144
|
return kindToSchema[kind];
|
|
155
145
|
};
|
|
@@ -6,9 +6,8 @@ import React, { type PropsWithChildren, type ReactNode, forwardRef } from 'react
|
|
|
6
6
|
|
|
7
7
|
import { invariant } from '@dxos/invariant';
|
|
8
8
|
import { Icon, IconButton, type ThemedClassName } from '@dxos/react-ui';
|
|
9
|
-
import { useEditorContext, useShapeDef } from '@dxos/react-ui-canvas-editor';
|
|
10
|
-
import {
|
|
11
|
-
import { mx } from '@dxos/react-ui-theme';
|
|
9
|
+
import { type CanvasBoard, useEditorContext, useShapeDef } from '@dxos/react-ui-canvas-editor';
|
|
10
|
+
import { mx } from '@dxos/ui-theme';
|
|
12
11
|
|
|
13
12
|
export const headerHeight = 32;
|
|
14
13
|
export const footerHeight = 32;
|
|
@@ -17,7 +16,7 @@ export type BoxActionHandler = (action: 'run' | 'open' | 'close') => void;
|
|
|
17
16
|
|
|
18
17
|
export type BoxProps = PropsWithChildren<
|
|
19
18
|
ThemedClassName<{
|
|
20
|
-
shape: Shape;
|
|
19
|
+
shape: CanvasBoard.Shape;
|
|
21
20
|
title?: string;
|
|
22
21
|
status?: string | ReactNode;
|
|
23
22
|
open?: boolean;
|
|
@@ -28,19 +27,18 @@ export type BoxProps = PropsWithChildren<
|
|
|
28
27
|
export const Box = forwardRef<HTMLDivElement, BoxProps>(
|
|
29
28
|
({ children, classNames, shape, title, status, open, onAction }, forwardedRef) => {
|
|
30
29
|
invariant(shape.type);
|
|
31
|
-
const { icon, name, openable } = useShapeDef(shape.type) ?? { icon: 'ph--
|
|
30
|
+
const { icon, name, openable } = useShapeDef(shape.type) ?? { icon: 'ph--circle-dashed--regular' };
|
|
32
31
|
const { debug } = useEditorContext();
|
|
33
32
|
|
|
34
33
|
return (
|
|
35
34
|
<div ref={forwardedRef} className='flex flex-col h-full w-full justify-between'>
|
|
36
|
-
<div className='flex shrink-0 w-full justify-between items-center h-[32px] bg-
|
|
35
|
+
<div className='flex shrink-0 w-full justify-between items-center h-[32px] bg-input-surface'>
|
|
37
36
|
<Icon icon={icon} classNames='mx-2' />
|
|
38
37
|
<div className='grow text-sm truncate'>{debug ? shape.type : (name ?? shape.text ?? title)}</div>
|
|
39
38
|
<IconButton
|
|
40
39
|
classNames='p-1 text-green-500'
|
|
41
40
|
variant='ghost'
|
|
42
41
|
icon='ph--play--regular'
|
|
43
|
-
size={4}
|
|
44
42
|
label='run'
|
|
45
43
|
iconOnly
|
|
46
44
|
onDoubleClick={(ev) => ev.stopPropagation()}
|
|
@@ -51,14 +49,13 @@ export const Box = forwardRef<HTMLDivElement, BoxProps>(
|
|
|
51
49
|
/>
|
|
52
50
|
</div>
|
|
53
51
|
<div className={mx('flex flex-col h-full grow overflow-hidden', classNames)}>{children}</div>
|
|
54
|
-
<div className='flex shrink-0 w-full justify-between items-center h-[32px] bg-
|
|
52
|
+
<div className='flex shrink-0 w-full justify-between items-center h-[32px] bg-input-surface'>
|
|
55
53
|
<div className='grow px-2 text-sm truncate'>{debug ? shape.id : status}</div>
|
|
56
54
|
{openable && (
|
|
57
55
|
<IconButton
|
|
58
56
|
classNames='p-1'
|
|
59
57
|
variant='ghost'
|
|
60
58
|
icon={open ? 'ph--caret-up--regular' : 'ph--caret-down--regular'}
|
|
61
|
-
size={4}
|
|
62
59
|
label={open ? 'close' : 'open'}
|
|
63
60
|
iconOnly
|
|
64
61
|
onClick={(ev) => {
|