@dxos/react-ui-canvas-compute 0.8.2-staging.7ac8446 → 0.8.2
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/index.mjs +1022 -836
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +1040 -854
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +1022 -836
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/DiagnosticOverlay.d.ts.map +1 -1
- package/dist/types/src/graph/controller.d.ts +2 -18
- 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.map +1 -1
- package/dist/types/src/hooks/useGraphMonitor.d.ts.map +1 -1
- package/dist/types/src/json.test.d.ts +18 -18
- package/dist/types/src/json.test.d.ts.map +1 -1
- package/dist/types/src/shapes/Append.d.ts +19 -19
- package/dist/types/src/shapes/Append.d.ts.map +1 -1
- package/dist/types/src/shapes/Array.d.ts +19 -19
- package/dist/types/src/shapes/Array.d.ts.map +1 -1
- package/dist/types/src/shapes/Audio.d.ts +19 -19
- package/dist/types/src/shapes/Audio.d.ts.map +1 -1
- package/dist/types/src/shapes/Beacon.d.ts +19 -19
- package/dist/types/src/shapes/Beacon.d.ts.map +1 -1
- package/dist/types/src/shapes/Boolean.d.ts +70 -70
- package/dist/types/src/shapes/Boolean.d.ts.map +1 -1
- package/dist/types/src/shapes/Chat.d.ts +19 -19
- package/dist/types/src/shapes/Chat.d.ts.map +1 -1
- package/dist/types/src/shapes/Constant.d.ts +20 -20
- package/dist/types/src/shapes/Constant.d.ts.map +1 -1
- package/dist/types/src/shapes/Database.d.ts +19 -19
- package/dist/types/src/shapes/Database.d.ts.map +1 -1
- package/dist/types/src/shapes/Function.d.ts +19 -19
- package/dist/types/src/shapes/Function.d.ts.map +1 -1
- package/dist/types/src/shapes/Gpt.d.ts +19 -19
- package/dist/types/src/shapes/Gpt.d.ts.map +1 -1
- package/dist/types/src/shapes/GptRealtime.d.ts +19 -19
- package/dist/types/src/shapes/GptRealtime.d.ts.map +1 -1
- package/dist/types/src/shapes/Json.d.ts +37 -37
- package/dist/types/src/shapes/Json.d.ts.map +1 -1
- package/dist/types/src/shapes/Logic.d.ts +37 -37
- package/dist/types/src/shapes/Logic.d.ts.map +1 -1
- package/dist/types/src/shapes/Queue.d.ts +19 -19
- package/dist/types/src/shapes/Queue.d.ts.map +1 -1
- package/dist/types/src/shapes/RNG.d.ts +21 -21
- package/dist/types/src/shapes/RNG.d.ts.map +1 -1
- package/dist/types/src/shapes/Scope.d.ts +19 -19
- package/dist/types/src/shapes/Scope.d.ts.map +1 -1
- package/dist/types/src/shapes/Surface.d.ts +19 -19
- package/dist/types/src/shapes/Surface.d.ts.map +1 -1
- package/dist/types/src/shapes/Switch.d.ts +19 -19
- package/dist/types/src/shapes/Switch.d.ts.map +1 -1
- package/dist/types/src/shapes/Table.d.ts +19 -19
- package/dist/types/src/shapes/Table.d.ts.map +1 -1
- package/dist/types/src/shapes/Template.d.ts +20 -20
- package/dist/types/src/shapes/Template.d.ts.map +1 -1
- package/dist/types/src/shapes/Text.d.ts +19 -19
- package/dist/types/src/shapes/Text.d.ts.map +1 -1
- package/dist/types/src/shapes/TextToImage.d.ts +19 -19
- package/dist/types/src/shapes/TextToImage.d.ts.map +1 -1
- package/dist/types/src/shapes/Thread.d.ts +19 -19
- package/dist/types/src/shapes/Thread.d.ts.map +1 -1
- package/dist/types/src/shapes/Trigger.d.ts +47 -45
- package/dist/types/src/shapes/Trigger.d.ts.map +1 -1
- package/dist/types/src/shapes/common/FunctionBody.d.ts +5 -5
- package/dist/types/src/shapes/common/FunctionBody.d.ts.map +1 -1
- package/dist/types/src/shapes/common/TypeSelect.d.ts.map +1 -1
- package/dist/types/src/shapes/defs.d.ts +18 -19
- package/dist/types/src/shapes/defs.d.ts.map +1 -1
- package/dist/types/src/testing/circuits.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +42 -40
- package/src/compute.stories.tsx +3 -3
- package/src/graph/controller.ts +12 -12
- package/src/hooks/useComputeNodeState.ts +3 -3
- package/src/hooks/useGraphMonitor.ts +3 -5
- package/src/json.test.ts +10 -10
- package/src/schema.test.ts +7 -7
- package/src/shapes/Append.tsx +5 -5
- package/src/shapes/Array.tsx +5 -5
- package/src/shapes/Audio.tsx +5 -5
- package/src/shapes/Beacon.tsx +5 -5
- package/src/shapes/Boolean.tsx +5 -5
- package/src/shapes/Chat.tsx +5 -5
- package/src/shapes/Constant.tsx +6 -6
- package/src/shapes/Database.tsx +5 -5
- package/src/shapes/Function.tsx +8 -7
- package/src/shapes/Gpt.tsx +6 -6
- package/src/shapes/GptRealtime.tsx +8 -8
- package/src/shapes/Json.tsx +9 -9
- package/src/shapes/Logic.tsx +9 -9
- package/src/shapes/Queue.tsx +5 -5
- package/src/shapes/RNG.tsx +7 -7
- package/src/shapes/Scope.tsx +5 -5
- package/src/shapes/Surface.tsx +5 -5
- package/src/shapes/Switch.tsx +5 -5
- package/src/shapes/Table.tsx +6 -6
- package/src/shapes/Template.tsx +8 -7
- package/src/shapes/Text.tsx +5 -5
- package/src/shapes/TextToImage.tsx +5 -5
- package/src/shapes/Thread.tsx +6 -6
- package/src/shapes/Trigger.tsx +32 -33
- package/src/shapes/common/FunctionBody.tsx +11 -9
- package/src/shapes/defs.ts +9 -9
package/src/shapes/Trigger.tsx
CHANGED
|
@@ -2,17 +2,11 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { Schema } from 'effect';
|
|
5
6
|
import React, { useEffect } from 'react';
|
|
6
7
|
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
QueueTriggerOutput,
|
|
10
|
-
SubscriptionTriggerOutput,
|
|
11
|
-
TimerTriggerOutput,
|
|
12
|
-
VoidInput,
|
|
13
|
-
WebhookTriggerOutput,
|
|
14
|
-
} from '@dxos/conductor';
|
|
15
|
-
import { ObjectId, Ref, S } from '@dxos/echo-schema';
|
|
8
|
+
import { VoidInput } from '@dxos/conductor';
|
|
9
|
+
import { ObjectId, Ref } from '@dxos/echo-schema';
|
|
16
10
|
import {
|
|
17
11
|
type EmailTrigger,
|
|
18
12
|
FunctionTrigger,
|
|
@@ -22,23 +16,28 @@ import {
|
|
|
22
16
|
TriggerKind,
|
|
23
17
|
type TriggerType,
|
|
24
18
|
type WebhookTrigger,
|
|
25
|
-
|
|
19
|
+
EmailTriggerOutput,
|
|
20
|
+
QueueTriggerOutput,
|
|
21
|
+
SubscriptionTriggerOutput,
|
|
22
|
+
TimerTriggerOutput,
|
|
23
|
+
WebhookTriggerOutput,
|
|
24
|
+
} from '@dxos/functions';
|
|
26
25
|
import { DXN, SpaceId } from '@dxos/keys';
|
|
27
|
-
import {
|
|
26
|
+
import { live, makeRef, useSpace } from '@dxos/react-client/echo';
|
|
28
27
|
import { Select, type SelectRootProps } from '@dxos/react-ui';
|
|
29
28
|
import { type ShapeComponentProps, type ShapeDef } from '@dxos/react-ui-canvas-editor';
|
|
30
29
|
|
|
31
30
|
import { createFunctionAnchors, FunctionBody, getHeight } from './common';
|
|
32
31
|
import { ComputeShape, createShape, type CreateShapeProps } from './defs';
|
|
33
32
|
|
|
34
|
-
export const TriggerShape =
|
|
33
|
+
export const TriggerShape = Schema.extend(
|
|
35
34
|
ComputeShape,
|
|
36
|
-
|
|
37
|
-
type:
|
|
38
|
-
functionTrigger:
|
|
35
|
+
Schema.Struct({
|
|
36
|
+
type: Schema.Literal('trigger'),
|
|
37
|
+
functionTrigger: Schema.optional(Ref(FunctionTrigger)),
|
|
39
38
|
}),
|
|
40
39
|
);
|
|
41
|
-
export type TriggerShape =
|
|
40
|
+
export type TriggerShape = Schema.Schema.Type<typeof TriggerShape>;
|
|
42
41
|
|
|
43
42
|
export type CreateTriggerProps = CreateShapeProps<Omit<TriggerShape, 'functionTrigger'>> & {
|
|
44
43
|
spaceId?: SpaceId;
|
|
@@ -46,7 +45,7 @@ export type CreateTriggerProps = CreateShapeProps<Omit<TriggerShape, 'functionTr
|
|
|
46
45
|
};
|
|
47
46
|
|
|
48
47
|
export const createTrigger = (props: CreateTriggerProps): TriggerShape => {
|
|
49
|
-
const functionTrigger =
|
|
48
|
+
const functionTrigger = live(FunctionTrigger, {
|
|
50
49
|
enabled: true,
|
|
51
50
|
spec: createTriggerSpec(props),
|
|
52
51
|
});
|
|
@@ -71,12 +70,12 @@ export const TriggerComponent = ({ shape }: TriggerComponentProps) => {
|
|
|
71
70
|
}, [functionTrigger, functionTrigger?.spec]);
|
|
72
71
|
|
|
73
72
|
useEffect(() => {
|
|
74
|
-
shape.size.height = getHeight(getOutputSchema(functionTrigger?.spec?.
|
|
75
|
-
}, [functionTrigger?.spec?.
|
|
73
|
+
shape.size.height = getHeight(getOutputSchema(functionTrigger?.spec?.kind ?? TriggerKind.Email));
|
|
74
|
+
}, [functionTrigger?.spec?.kind]);
|
|
76
75
|
|
|
77
76
|
const setKind = (kind: TriggerKind) => {
|
|
78
|
-
if (functionTrigger?.spec?.
|
|
79
|
-
functionTrigger!.spec = createTriggerSpec({ triggerKind:
|
|
77
|
+
if (functionTrigger?.spec?.kind !== kind) {
|
|
78
|
+
functionTrigger!.spec = createTriggerSpec({ triggerKind: kind, spaceId: space?.id });
|
|
80
79
|
}
|
|
81
80
|
};
|
|
82
81
|
|
|
@@ -88,10 +87,10 @@ export const TriggerComponent = ({ shape }: TriggerComponentProps) => {
|
|
|
88
87
|
<FunctionBody
|
|
89
88
|
shape={shape}
|
|
90
89
|
status={
|
|
91
|
-
<TriggerKindSelect value={functionTrigger.spec?.
|
|
90
|
+
<TriggerKindSelect value={functionTrigger.spec?.kind} onValueChange={(kind) => setKind(kind as TriggerKind)} />
|
|
92
91
|
}
|
|
93
92
|
inputSchema={VoidInput}
|
|
94
|
-
outputSchema={getOutputSchema(functionTrigger.spec!.
|
|
93
|
+
outputSchema={getOutputSchema(functionTrigger.spec!.kind!)}
|
|
95
94
|
/>
|
|
96
95
|
);
|
|
97
96
|
};
|
|
@@ -105,9 +104,9 @@ const TriggerKindSelect = ({ value, onValueChange }: Pick<SelectRootProps, 'valu
|
|
|
105
104
|
<Select.Content>
|
|
106
105
|
<Select.ScrollUpButton />
|
|
107
106
|
<Select.Viewport>
|
|
108
|
-
{Object.values(TriggerKind).map((
|
|
109
|
-
<Select.Option key={
|
|
110
|
-
{
|
|
107
|
+
{Object.values(TriggerKind).map((kind) => (
|
|
108
|
+
<Select.Option key={kind} value={kind}>
|
|
109
|
+
{kind}
|
|
111
110
|
</Select.Option>
|
|
112
111
|
))}
|
|
113
112
|
</Select.Viewport>
|
|
@@ -123,22 +122,22 @@ const createTriggerSpec = (props: { triggerKind?: TriggerKind; spaceId?: SpaceId
|
|
|
123
122
|
const kind = props.triggerKind ?? TriggerKind.Email;
|
|
124
123
|
switch (kind) {
|
|
125
124
|
case TriggerKind.Timer:
|
|
126
|
-
return {
|
|
125
|
+
return { kind: TriggerKind.Timer, cron: '*/10 * * * * *' } satisfies TimerTrigger;
|
|
127
126
|
case TriggerKind.Webhook:
|
|
128
|
-
return {
|
|
127
|
+
return { kind: TriggerKind.Webhook, method: 'POST' } satisfies WebhookTrigger;
|
|
129
128
|
case TriggerKind.Subscription:
|
|
130
|
-
return {
|
|
129
|
+
return { kind: TriggerKind.Subscription, filter: {} } satisfies SubscriptionTrigger;
|
|
131
130
|
case TriggerKind.Email:
|
|
132
|
-
return {
|
|
131
|
+
return { kind: TriggerKind.Email } satisfies EmailTrigger;
|
|
133
132
|
case TriggerKind.Queue: {
|
|
134
133
|
const dxn = new DXN(DXN.kind.QUEUE, ['data', props.spaceId ?? SpaceId.random(), ObjectId.random()]).toString();
|
|
135
|
-
return {
|
|
134
|
+
return { kind: TriggerKind.Queue, queue: dxn } satisfies QueueTrigger;
|
|
136
135
|
}
|
|
137
136
|
}
|
|
138
137
|
};
|
|
139
138
|
|
|
140
139
|
const getOutputSchema = (kind: TriggerKind) => {
|
|
141
|
-
const kindToSchema: Record<TriggerKind,
|
|
140
|
+
const kindToSchema: Record<TriggerKind, Schema.Schema<any>> = {
|
|
142
141
|
[TriggerKind.Email]: EmailTriggerOutput,
|
|
143
142
|
[TriggerKind.Subscription]: SubscriptionTriggerOutput,
|
|
144
143
|
[TriggerKind.Timer]: TimerTriggerOutput,
|
|
@@ -158,6 +157,6 @@ export const triggerShape: ShapeDef<TriggerShape> = {
|
|
|
158
157
|
createFunctionAnchors(
|
|
159
158
|
shape,
|
|
160
159
|
VoidInput,
|
|
161
|
-
getOutputSchema(shape.functionTrigger?.target?.spec?.
|
|
160
|
+
getOutputSchema(shape.functionTrigger?.target?.spec?.kind ?? TriggerKind.Email),
|
|
162
161
|
),
|
|
163
162
|
};
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { type Schema, SchemaAST } from 'effect';
|
|
5
6
|
import React, { type JSX, useRef, useState } from 'react';
|
|
6
7
|
|
|
7
8
|
import { VoidInput, VoidOutput } from '@dxos/conductor';
|
|
8
|
-
import { AST, type S } from '@dxos/echo-schema';
|
|
9
9
|
import { useCanvasContext } from '@dxos/react-ui-canvas';
|
|
10
10
|
import { type Polygon, type Shape } from '@dxos/react-ui-canvas-editor';
|
|
11
11
|
import { getParentShapeElement, createAnchors, rowHeight } from '@dxos/react-ui-canvas-editor';
|
|
@@ -20,8 +20,8 @@ export type FunctionBodyProps = {
|
|
|
20
20
|
shape: Shape;
|
|
21
21
|
name?: string;
|
|
22
22
|
content?: JSX.Element;
|
|
23
|
-
inputSchema?:
|
|
24
|
-
outputSchema?:
|
|
23
|
+
inputSchema?: Schema.Schema.Any;
|
|
24
|
+
outputSchema?: Schema.Schema.Any;
|
|
25
25
|
} & Pick<BoxProps, 'status'>;
|
|
26
26
|
|
|
27
27
|
// TODO(wittjosiah): Rename, not used for functions.
|
|
@@ -106,18 +106,20 @@ export const FunctionBody = ({
|
|
|
106
106
|
);
|
|
107
107
|
};
|
|
108
108
|
|
|
109
|
-
export const getHeight = (input:
|
|
110
|
-
const properties =
|
|
109
|
+
export const getHeight = (input: Schema.Schema<any>) => {
|
|
110
|
+
const properties = SchemaAST.getPropertySignatures(input.ast);
|
|
111
111
|
return headerHeight + footerHeight + bodyPadding * 2 + properties.length * rowHeight + 2; // Incl. borders.
|
|
112
112
|
};
|
|
113
113
|
|
|
114
114
|
export const createFunctionAnchors = (
|
|
115
115
|
shape: Polygon,
|
|
116
|
-
input:
|
|
117
|
-
output:
|
|
116
|
+
input: Schema.Schema<any> = VoidInput,
|
|
117
|
+
output: Schema.Schema<any> = VoidOutput,
|
|
118
118
|
) => {
|
|
119
119
|
// TODO(burdon): Set type.
|
|
120
|
-
const inputs =
|
|
121
|
-
const outputs =
|
|
120
|
+
const inputs = SchemaAST.getPropertySignatures(input.ast).map(({ name }) => createAnchorId('input', name.toString()));
|
|
121
|
+
const outputs = SchemaAST.getPropertySignatures(output.ast).map(({ name }) =>
|
|
122
|
+
createAnchorId('output', name.toString()),
|
|
123
|
+
);
|
|
122
124
|
return createAnchors({ shape, inputs, outputs, center: { x: 0, y: (headerHeight - footerHeight) / 2 + 1 } });
|
|
123
125
|
};
|
package/src/shapes/defs.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { SchemaAST
|
|
5
|
+
import { Schema, SchemaAST } from 'effect';
|
|
6
6
|
|
|
7
7
|
import { DEFAULT_INPUT, DEFAULT_OUTPUT } from '@dxos/conductor';
|
|
8
|
-
import { ObjectId
|
|
8
|
+
import { ObjectId } from '@dxos/echo-schema';
|
|
9
9
|
import { Polygon } from '@dxos/react-ui-canvas-editor';
|
|
10
10
|
import { type MakeOptional } from '@dxos/util';
|
|
11
11
|
|
|
@@ -15,8 +15,8 @@ import { type MakeOptional } from '@dxos/util';
|
|
|
15
15
|
|
|
16
16
|
export type PropertyKind = 'input' | 'output';
|
|
17
17
|
|
|
18
|
-
export const getProperties = (ast:
|
|
19
|
-
|
|
18
|
+
export const getProperties = (ast: SchemaAST.AST) =>
|
|
19
|
+
SchemaAST.getPropertySignatures(ast).map(({ name }) => ({ name: name.toString() }));
|
|
20
20
|
|
|
21
21
|
export const createAnchorId = (kind: PropertyKind, property = kind === 'input' ? DEFAULT_INPUT : DEFAULT_OUTPUT) =>
|
|
22
22
|
[kind, property].join('.');
|
|
@@ -32,15 +32,15 @@ export const parseAnchorId = (id: string): [PropertyKind | undefined, string] =>
|
|
|
32
32
|
|
|
33
33
|
export type CreateShapeProps<S extends Polygon> = Omit<MakeOptional<S, 'id' | 'size'>, 'type' | 'node'>;
|
|
34
34
|
|
|
35
|
-
export const ComputeShape =
|
|
35
|
+
export const ComputeShape = Schema.extend(
|
|
36
36
|
Polygon,
|
|
37
|
-
|
|
37
|
+
Schema.Struct({
|
|
38
38
|
// TODO(burdon): Rename computeNode?
|
|
39
|
-
node:
|
|
40
|
-
}).pipe(
|
|
39
|
+
node: Schema.optional(ObjectId.annotations({ description: 'Compute node id' })),
|
|
40
|
+
}).pipe(Schema.mutable),
|
|
41
41
|
);
|
|
42
42
|
|
|
43
|
-
export type ComputeShape =
|
|
43
|
+
export type ComputeShape = Schema.Schema.Type<typeof ComputeShape>;
|
|
44
44
|
|
|
45
45
|
export const createShape = <S extends ComputeShape>({ id, ...rest }: CreateShapeProps<S> & { type: string }): S => {
|
|
46
46
|
return {
|