@dxos/react-ui-canvas-compute 0.8.4-main.fd6878d → 0.8.4-staging.60fe92afc8
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 +963 -1198
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +963 -1198
- 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 +33 -5
- 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 +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/json.test.d.ts +1 -1
- package/dist/types/src/json.test.d.ts.map +1 -1
- package/dist/types/src/shapes/Append.d.ts +2 -2
- package/dist/types/src/shapes/Append.d.ts.map +1 -1
- package/dist/types/src/shapes/Array.d.ts +2 -2
- package/dist/types/src/shapes/Array.d.ts.map +1 -1
- package/dist/types/src/shapes/Audio.d.ts +2 -2
- package/dist/types/src/shapes/Audio.d.ts.map +1 -1
- package/dist/types/src/shapes/Beacon.d.ts +2 -2
- package/dist/types/src/shapes/Beacon.d.ts.map +1 -1
- package/dist/types/src/shapes/Boolean.d.ts +8 -8
- package/dist/types/src/shapes/Boolean.d.ts.map +1 -1
- package/dist/types/src/shapes/Chat.d.ts +2 -2
- package/dist/types/src/shapes/Chat.d.ts.map +1 -1
- package/dist/types/src/shapes/Constant.d.ts +3 -3
- package/dist/types/src/shapes/Constant.d.ts.map +1 -1
- package/dist/types/src/shapes/Database.d.ts +2 -2
- package/dist/types/src/shapes/Database.d.ts.map +1 -1
- package/dist/types/src/shapes/{Queue.d.ts → Feed.d.ts} +10 -10
- package/dist/types/src/shapes/Feed.d.ts.map +1 -0
- package/dist/types/src/shapes/Function.d.ts +2 -2
- package/dist/types/src/shapes/Function.d.ts.map +1 -1
- package/dist/types/src/shapes/Gpt.d.ts +2 -2
- package/dist/types/src/shapes/Gpt.d.ts.map +1 -1
- package/dist/types/src/shapes/GptRealtime.d.ts +2 -2
- package/dist/types/src/shapes/GptRealtime.d.ts.map +1 -1
- package/dist/types/src/shapes/Json.d.ts +3 -3
- package/dist/types/src/shapes/Json.d.ts.map +1 -1
- package/dist/types/src/shapes/Logic.d.ts +3 -3
- package/dist/types/src/shapes/Logic.d.ts.map +1 -1
- package/dist/types/src/shapes/RNG.d.ts +3 -3
- package/dist/types/src/shapes/RNG.d.ts.map +1 -1
- package/dist/types/src/shapes/Scope.d.ts +2 -2
- package/dist/types/src/shapes/Scope.d.ts.map +1 -1
- package/dist/types/src/shapes/Surface.d.ts +2 -2
- package/dist/types/src/shapes/Surface.d.ts.map +1 -1
- package/dist/types/src/shapes/Switch.d.ts +2 -2
- package/dist/types/src/shapes/Switch.d.ts.map +1 -1
- package/dist/types/src/shapes/Table.d.ts +2 -2
- package/dist/types/src/shapes/Table.d.ts.map +1 -1
- package/dist/types/src/shapes/Template.d.ts +3 -3
- package/dist/types/src/shapes/Template.d.ts.map +1 -1
- package/dist/types/src/shapes/Text.d.ts +2 -2
- package/dist/types/src/shapes/Text.d.ts.map +1 -1
- package/dist/types/src/shapes/TextToImage.d.ts +2 -2
- package/dist/types/src/shapes/TextToImage.d.ts.map +1 -1
- package/dist/types/src/shapes/Thread.d.ts +2 -2
- package/dist/types/src/shapes/Thread.d.ts.map +1 -1
- package/dist/types/src/shapes/Trigger.d.ts +11 -61
- 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 +3 -3
- 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 +3 -2
- 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 +63 -57
- package/src/README.md +0 -3
- package/src/compute-layout.ts +1 -1
- package/src/compute.stories.tsx +100 -123
- package/src/graph/controller.ts +158 -79
- package/src/graph/node-defs.ts +31 -31
- package/src/hooks/useComputeGraphController.ts +1 -1
- package/src/hooks/useComputeNodeState.ts +8 -9
- package/src/hooks/useGraphMonitor.ts +11 -10
- package/src/json.test.ts +4 -4
- package/src/registry.ts +2 -2
- package/src/schema.test.ts +12 -12
- package/src/shapes/Append.tsx +1 -1
- package/src/shapes/Array.tsx +1 -1
- package/src/shapes/Audio.tsx +2 -3
- package/src/shapes/Beacon.tsx +1 -2
- package/src/shapes/Boolean.tsx +2 -2
- package/src/shapes/Chat.tsx +1 -2
- package/src/shapes/Constant.tsx +1 -2
- package/src/shapes/Database.tsx +1 -1
- package/src/shapes/{Queue.tsx → Feed.tsx} +27 -22
- package/src/shapes/Function.tsx +16 -13
- package/src/shapes/Gpt.tsx +7 -3
- package/src/shapes/GptRealtime.tsx +1 -1
- package/src/shapes/Json.tsx +10 -4
- package/src/shapes/Logic.tsx +1 -1
- package/src/shapes/RNG.tsx +6 -3
- package/src/shapes/Scope.tsx +3 -3
- package/src/shapes/Surface.tsx +13 -5
- package/src/shapes/Switch.tsx +1 -2
- package/src/shapes/Table.tsx +5 -4
- package/src/shapes/Template.tsx +2 -3
- package/src/shapes/Text.tsx +1 -2
- package/src/shapes/TextToImage.tsx +1 -1
- package/src/shapes/Thread.tsx +14 -11
- package/src/shapes/Trigger.tsx +51 -58
- package/src/shapes/common/Box.tsx +6 -9
- package/src/shapes/common/FunctionBody.tsx +4 -3
- package/src/shapes/common/TypeSelect.tsx +1 -1
- package/src/shapes/defs.ts +5 -4
- 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/Trigger.tsx
CHANGED
|
@@ -2,57 +2,51 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
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 {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
FunctionTrigger,
|
|
14
|
-
type QueueTrigger,
|
|
15
|
-
QueueTriggerOutput,
|
|
16
|
-
type SubscriptionTrigger,
|
|
17
|
-
SubscriptionTriggerOutput,
|
|
18
|
-
type TimerTrigger,
|
|
19
|
-
TimerTriggerOutput,
|
|
20
|
-
TriggerKind,
|
|
21
|
-
type TriggerType,
|
|
22
|
-
type WebhookTrigger,
|
|
23
|
-
WebhookTriggerOutput,
|
|
24
|
-
} from '@dxos/functions';
|
|
25
|
-
import { DXN, SpaceId } from '@dxos/keys';
|
|
26
|
-
import { live, useSpace } from '@dxos/react-client/echo';
|
|
10
|
+
import { Filter, Obj, Query, Ref } from '@dxos/echo';
|
|
11
|
+
import { type Mutable } from '@dxos/echo/Obj';
|
|
12
|
+
import { type SpaceId } from '@dxos/keys';
|
|
13
|
+
import { useSpaces } from '@dxos/react-client/echo';
|
|
27
14
|
import { Select, type SelectRootProps } from '@dxos/react-ui';
|
|
28
15
|
import { type ShapeComponentProps, type ShapeDef } from '@dxos/react-ui-canvas-editor';
|
|
29
16
|
|
|
30
17
|
import { FunctionBody, createFunctionAnchors, getHeight } from './common';
|
|
31
18
|
import { ComputeShape, type CreateShapeProps, createShape } from './defs';
|
|
32
19
|
|
|
33
|
-
|
|
20
|
+
const TriggerShapeSchema = Schema.extend(
|
|
34
21
|
ComputeShape,
|
|
35
22
|
Schema.Struct({
|
|
36
23
|
type: Schema.Literal('trigger'),
|
|
37
|
-
functionTrigger: Schema.optional(Ref(
|
|
24
|
+
functionTrigger: Schema.optional(Ref.Ref(Trigger.Trigger)),
|
|
38
25
|
}),
|
|
39
26
|
);
|
|
40
|
-
|
|
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;
|
|
41
35
|
|
|
42
36
|
export type CreateTriggerProps = CreateShapeProps<Omit<TriggerShape, 'functionTrigger'>> & {
|
|
43
37
|
spaceId?: SpaceId;
|
|
44
|
-
triggerKind?:
|
|
38
|
+
triggerKind?: Trigger.Kind;
|
|
45
39
|
};
|
|
46
40
|
|
|
47
41
|
export const createTrigger = (props: CreateTriggerProps): TriggerShape => {
|
|
48
|
-
const functionTrigger =
|
|
42
|
+
const functionTrigger = Trigger.make({
|
|
49
43
|
enabled: true,
|
|
50
44
|
spec: createTriggerSpec(props),
|
|
51
45
|
});
|
|
52
46
|
return createShape<TriggerShape>({
|
|
53
47
|
type: 'trigger',
|
|
54
48
|
functionTrigger: Ref.make(functionTrigger),
|
|
55
|
-
size: { width: 192, height: getHeight(
|
|
49
|
+
size: { width: 192, height: getHeight(TriggerEvent.EmailEvent) },
|
|
56
50
|
...props,
|
|
57
51
|
});
|
|
58
52
|
};
|
|
@@ -60,22 +54,26 @@ export const createTrigger = (props: CreateTriggerProps): TriggerShape => {
|
|
|
60
54
|
export type TriggerComponentProps = ShapeComponentProps<TriggerShape>;
|
|
61
55
|
|
|
62
56
|
export const TriggerComponent = ({ shape }: TriggerComponentProps) => {
|
|
63
|
-
const space =
|
|
57
|
+
const [space] = useSpaces();
|
|
64
58
|
const functionTrigger = shape.functionTrigger?.target;
|
|
65
59
|
|
|
66
60
|
useEffect(() => {
|
|
67
61
|
if (functionTrigger && !functionTrigger.spec) {
|
|
68
|
-
|
|
62
|
+
Obj.update(functionTrigger, (functionTrigger) => {
|
|
63
|
+
functionTrigger.spec = createTriggerSpec({ triggerKind: 'email', spaceId: space?.id }) as Mutable<Trigger.Spec>;
|
|
64
|
+
});
|
|
69
65
|
}
|
|
70
66
|
}, [functionTrigger, functionTrigger?.spec]);
|
|
71
67
|
|
|
72
68
|
useEffect(() => {
|
|
73
|
-
shape.size.height = getHeight(getOutputSchema(functionTrigger?.spec?.kind ??
|
|
69
|
+
shape.size.height = getHeight(getOutputSchema(functionTrigger?.spec?.kind ?? 'email'));
|
|
74
70
|
}, [functionTrigger?.spec?.kind]);
|
|
75
71
|
|
|
76
|
-
const setKind = (kind:
|
|
72
|
+
const setKind = (kind: Trigger.Kind) => {
|
|
77
73
|
if (functionTrigger?.spec?.kind !== kind) {
|
|
78
|
-
functionTrigger
|
|
74
|
+
Obj.update(functionTrigger!, (obj) => {
|
|
75
|
+
obj.spec = createTriggerSpec({ triggerKind: kind, spaceId: space?.id }) as Mutable<Trigger.Spec>;
|
|
76
|
+
});
|
|
79
77
|
}
|
|
80
78
|
};
|
|
81
79
|
|
|
@@ -87,7 +85,7 @@ export const TriggerComponent = ({ shape }: TriggerComponentProps) => {
|
|
|
87
85
|
<FunctionBody
|
|
88
86
|
shape={shape}
|
|
89
87
|
status={
|
|
90
|
-
<TriggerKindSelect value={functionTrigger.spec?.kind} onValueChange={(kind) => setKind(kind as
|
|
88
|
+
<TriggerKindSelect value={functionTrigger.spec?.kind} onValueChange={(kind) => setKind(kind as Trigger.Kind)} />
|
|
91
89
|
}
|
|
92
90
|
inputSchema={VoidInput}
|
|
93
91
|
outputSchema={getOutputSchema(functionTrigger.spec!.kind!)}
|
|
@@ -99,12 +97,12 @@ export const TriggerComponent = ({ shape }: TriggerComponentProps) => {
|
|
|
99
97
|
const TriggerKindSelect = ({ value, onValueChange }: Pick<SelectRootProps, 'value' | 'onValueChange'>) => {
|
|
100
98
|
return (
|
|
101
99
|
<Select.Root value={value} onValueChange={onValueChange}>
|
|
102
|
-
<Select.TriggerButton variant='ghost' classNames='w-full
|
|
100
|
+
<Select.TriggerButton variant='ghost' classNames='w-full px-0!' />
|
|
103
101
|
<Select.Portal>
|
|
104
102
|
<Select.Content>
|
|
105
103
|
<Select.ScrollUpButton />
|
|
106
104
|
<Select.Viewport>
|
|
107
|
-
{
|
|
105
|
+
{Trigger.Kinds.map((kind) => (
|
|
108
106
|
<Select.Option key={kind} value={kind}>
|
|
109
107
|
{kind}
|
|
110
108
|
</Select.Option>
|
|
@@ -118,31 +116,30 @@ const TriggerKindSelect = ({ value, onValueChange }: Pick<SelectRootProps, 'valu
|
|
|
118
116
|
);
|
|
119
117
|
};
|
|
120
118
|
|
|
121
|
-
const createTriggerSpec = (props: { triggerKind?:
|
|
122
|
-
const kind = props.triggerKind ??
|
|
119
|
+
const createTriggerSpec = (props: { triggerKind?: Trigger.Kind; spaceId?: SpaceId }): Trigger.Spec => {
|
|
120
|
+
const kind = props.triggerKind ?? 'email';
|
|
123
121
|
switch (kind) {
|
|
124
|
-
case
|
|
125
|
-
return
|
|
126
|
-
case
|
|
127
|
-
return {
|
|
128
|
-
case
|
|
129
|
-
return
|
|
130
|
-
case
|
|
131
|
-
return
|
|
132
|
-
case
|
|
133
|
-
|
|
134
|
-
return { kind: TriggerKind.Queue, queue: dxn } satisfies QueueTrigger;
|
|
122
|
+
case 'timer':
|
|
123
|
+
return Trigger.specTimer('*/10 * * * * *');
|
|
124
|
+
case 'webhook':
|
|
125
|
+
return Trigger.specWebhook({ method: 'POST' });
|
|
126
|
+
case 'subscription':
|
|
127
|
+
return Trigger.specSubscription(Query.select(Filter.nothing()));
|
|
128
|
+
case 'email':
|
|
129
|
+
return Trigger.specEmail();
|
|
130
|
+
case 'feed': {
|
|
131
|
+
return { kind: 'feed' } satisfies Trigger.FeedSpec;
|
|
135
132
|
}
|
|
136
133
|
}
|
|
137
134
|
};
|
|
138
135
|
|
|
139
|
-
const getOutputSchema = (kind:
|
|
140
|
-
const kindToSchema: Record<
|
|
141
|
-
[
|
|
142
|
-
[
|
|
143
|
-
[
|
|
144
|
-
[
|
|
145
|
-
[
|
|
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,
|
|
146
143
|
};
|
|
147
144
|
return kindToSchema[kind];
|
|
148
145
|
};
|
|
@@ -154,9 +151,5 @@ export const triggerShape: ShapeDef<TriggerShape> = {
|
|
|
154
151
|
component: TriggerComponent,
|
|
155
152
|
createShape: createTrigger,
|
|
156
153
|
getAnchors: (shape) =>
|
|
157
|
-
createFunctionAnchors(
|
|
158
|
-
shape,
|
|
159
|
-
VoidInput,
|
|
160
|
-
getOutputSchema(shape.functionTrigger?.target?.spec?.kind ?? TriggerKind.Email),
|
|
161
|
-
),
|
|
154
|
+
createFunctionAnchors(shape, VoidInput, getOutputSchema(shape.functionTrigger?.target?.spec?.kind ?? 'email')),
|
|
162
155
|
};
|
|
@@ -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) => {
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import type * as Schema from 'effect/Schema';
|
|
6
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
6
7
|
import React, { type JSX, useRef, useState } from 'react';
|
|
7
8
|
|
|
8
9
|
import { VoidInput, VoidOutput } from '@dxos/conductor';
|
|
9
10
|
import { useCanvasContext } from '@dxos/react-ui-canvas';
|
|
10
|
-
import { type
|
|
11
|
+
import { type CanvasBoard, type Polygon } from '@dxos/react-ui-canvas-editor';
|
|
11
12
|
import { createAnchors, getParentShapeElement, rowHeight } from '@dxos/react-ui-canvas-editor';
|
|
12
13
|
|
|
13
14
|
import { Box, type BoxProps, footerHeight, headerHeight } from '../common';
|
|
@@ -17,7 +18,7 @@ const bodyPadding = 8;
|
|
|
17
18
|
const expandedHeight = 200;
|
|
18
19
|
|
|
19
20
|
export type FunctionBodyProps = {
|
|
20
|
-
shape: Shape;
|
|
21
|
+
shape: CanvasBoard.Shape;
|
|
21
22
|
name?: string;
|
|
22
23
|
content?: JSX.Element;
|
|
23
24
|
inputSchema?: Schema.Schema.Any;
|
|
@@ -11,7 +11,7 @@ import { Select, type SelectRootProps } from '@dxos/react-ui';
|
|
|
11
11
|
export const TypeSelect = ({ value, onValueChange }: Pick<SelectRootProps, 'value' | 'onValueChange'>) => {
|
|
12
12
|
return (
|
|
13
13
|
<Select.Root value={value} onValueChange={onValueChange}>
|
|
14
|
-
<Select.TriggerButton variant='ghost' classNames='w-full
|
|
14
|
+
<Select.TriggerButton variant='ghost' classNames='w-full px-0!' />
|
|
15
15
|
<Select.Portal>
|
|
16
16
|
<Select.Content>
|
|
17
17
|
<Select.ScrollUpButton />
|
package/src/shapes/defs.ts
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
6
7
|
|
|
7
8
|
import { DEFAULT_INPUT, DEFAULT_OUTPUT } from '@dxos/conductor';
|
|
8
|
-
import {
|
|
9
|
+
import { Obj } from '@dxos/echo';
|
|
9
10
|
import { Polygon } from '@dxos/react-ui-canvas-editor';
|
|
10
11
|
import { type MakeOptional } from '@dxos/util';
|
|
11
12
|
|
|
@@ -36,7 +37,7 @@ export const ComputeShape = Schema.extend(
|
|
|
36
37
|
Polygon,
|
|
37
38
|
Schema.Struct({
|
|
38
39
|
// TODO(burdon): Rename computeNode?
|
|
39
|
-
node: Schema.optional(
|
|
40
|
+
node: Schema.optional(Obj.ID.annotations({ description: 'Compute node id' })),
|
|
40
41
|
}).pipe(Schema.mutable),
|
|
41
42
|
);
|
|
42
43
|
|
|
@@ -44,7 +45,7 @@ export type ComputeShape = Schema.Schema.Type<typeof ComputeShape>;
|
|
|
44
45
|
|
|
45
46
|
export const createShape = <S extends ComputeShape>({ id, ...rest }: CreateShapeProps<S> & { type: string }): S => {
|
|
46
47
|
return {
|
|
47
|
-
id: id ??
|
|
48
|
+
id: id ?? Obj.ID.random(),
|
|
48
49
|
...rest,
|
|
49
50
|
} as S;
|
|
50
51
|
};
|
package/src/shapes/index.ts
CHANGED
|
@@ -13,11 +13,12 @@ export * from './Boolean';
|
|
|
13
13
|
export * from './Chat';
|
|
14
14
|
export * from './Constant';
|
|
15
15
|
export * from './Database';
|
|
16
|
+
export * from './Feed';
|
|
16
17
|
export * from './Function';
|
|
17
18
|
export * from './Gpt';
|
|
19
|
+
export * from './GptRealtime';
|
|
18
20
|
export * from './Json';
|
|
19
21
|
export * from './Logic';
|
|
20
|
-
export * from './Queue';
|
|
21
22
|
export * from './RNG';
|
|
22
23
|
export * from './Scope';
|
|
23
24
|
export * from './Surface';
|
|
@@ -28,4 +29,3 @@ export * from './Text';
|
|
|
28
29
|
export * from './Thread';
|
|
29
30
|
export * from './TextToImage';
|
|
30
31
|
export * from './Trigger';
|
|
31
|
-
export * from './GptRealtime';
|
package/src/testing/circuits.ts
CHANGED
|
@@ -3,14 +3,10 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { createSystemPrompt } from '@dxos/assistant';
|
|
6
|
-
import {
|
|
7
|
-
import { type ServiceContainer } from '@dxos/functions';
|
|
8
|
-
import { DXN, SpaceId } from '@dxos/keys';
|
|
6
|
+
import { EID, EntityId, SpaceId } from '@dxos/keys';
|
|
9
7
|
import { type Dimension, type Point } from '@dxos/react-ui-canvas';
|
|
10
8
|
import { CanvasGraphModel, createNote, pointMultiply, pointsToRect, rectToPoints } from '@dxos/react-ui-canvas-editor';
|
|
11
9
|
|
|
12
|
-
import { ComputeGraphController } from '../graph';
|
|
13
|
-
import { createComputeGraph } from '../hooks';
|
|
14
10
|
import {
|
|
15
11
|
type ComputeShape,
|
|
16
12
|
createAnd,
|
|
@@ -28,7 +24,7 @@ import {
|
|
|
28
24
|
createJsonTransform,
|
|
29
25
|
createNot,
|
|
30
26
|
createOr,
|
|
31
|
-
|
|
27
|
+
createFeed,
|
|
32
28
|
createRandom,
|
|
33
29
|
createScope,
|
|
34
30
|
createSurface,
|
|
@@ -38,19 +34,14 @@ import {
|
|
|
38
34
|
createTextToImage,
|
|
39
35
|
} from '../shapes';
|
|
40
36
|
|
|
41
|
-
export const createComputeGraphController = (
|
|
42
|
-
graph: CanvasGraphModel<ComputeShape>,
|
|
43
|
-
serviceContainer: ServiceContainer,
|
|
44
|
-
) => {
|
|
45
|
-
const computeGraph = createComputeGraph(graph);
|
|
46
|
-
const controller = new ComputeGraphController(serviceContainer, computeGraph);
|
|
47
|
-
return { controller, graph };
|
|
48
|
-
};
|
|
49
|
-
|
|
50
37
|
//
|
|
51
38
|
// Circuits
|
|
52
39
|
//
|
|
53
40
|
|
|
41
|
+
export const createEmptyCircuit = () => {
|
|
42
|
+
return CanvasGraphModel.create<ComputeShape>();
|
|
43
|
+
};
|
|
44
|
+
|
|
54
45
|
export const createBasicCircuit = () => {
|
|
55
46
|
const model = CanvasGraphModel.create<ComputeShape>();
|
|
56
47
|
model.builder.call(({ model }) => {
|
|
@@ -76,7 +67,7 @@ export const createTransformCircuit = () => {
|
|
|
76
67
|
|
|
77
68
|
model.builder
|
|
78
69
|
// TODO(burdon): Make id optional.
|
|
79
|
-
.createNode(createNote({ id:
|
|
70
|
+
.createNode(createNote({ id: EntityId.random(), text: 'Random number generator', ...position({ x: 0, y: -6 }) }))
|
|
80
71
|
.createEdge({ source: a.id, target: c.id })
|
|
81
72
|
.createEdge({ source: b.id, target: c.id, input: 'expression' })
|
|
82
73
|
.createEdge({ source: c.id, target: d.id });
|
|
@@ -245,12 +236,12 @@ export const createGptCircuit = (options: {
|
|
|
245
236
|
if (options.history) {
|
|
246
237
|
const queue = model.createNode(
|
|
247
238
|
createConstant({
|
|
248
|
-
value:
|
|
239
|
+
value: EID.make({ spaceId: SpaceId.random(), entityId: EntityId.random() }),
|
|
249
240
|
...position({ x: -18, y: 5, width: 8, height: 6 }),
|
|
250
241
|
}),
|
|
251
242
|
);
|
|
252
243
|
|
|
253
|
-
const thread = model.createNode(
|
|
244
|
+
const thread = model.createNode(createFeed(position({ x: -3, y: 3, width: 14, height: 10 })));
|
|
254
245
|
const append = model.createNode(createAppend(position({ x: 10, y: 6 })));
|
|
255
246
|
|
|
256
247
|
builder
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Queue.d.ts","sourceRoot":"","sources":["../../../../src/shapes/Queue.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAmB,MAAM,OAAO,CAAC;AAGxC,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,KAAK,mBAAmB,EAAE,KAAK,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAOvF,OAAO,EAAgB,KAAK,gBAAgB,EAAe,MAAM,QAAQ,CAAC;AAE1E,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;GAKtB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,UAAU,CAAC,CAAC;AAE/D,MAAM,MAAM,gBAAgB,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;AAE5D,eAAO,MAAM,WAAW,GAAI,OAAO,gBAAgB;;;;;;;;;;;;;;;;;;;CACsC,CAAC;AAE1F,eAAO,MAAM,cAAc,GAAI,WAAW,mBAAmB,CAAC,UAAU,CAAC,sBAmBxE,CAAC;AAEF,eAAO,MAAM,SAAS,GAAI,sBAAsB,eAAe,CAAC;IAAE,IAAI,EAAE,GAAG,CAAA;CAAE,CAAC,sBAe7E,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,QAAQ,CAAC,UAAU,CAQ3C,CAAC"}
|