@dxos/react-ui-canvas-compute 0.7.5-labs.e27f9b9 → 0.7.5-labs.f400bbc
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 +116 -40
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +140 -65
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +116 -40
- 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 +1 -2
- package/dist/types/src/components/DiagnosticOverlay.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/graph/controller.d.ts +19 -3
- package/dist/types/src/graph/controller.d.ts.map +1 -1
- package/dist/types/src/shapes/Append.d.ts +1 -2
- package/dist/types/src/shapes/Append.d.ts.map +1 -1
- package/dist/types/src/shapes/Array.d.ts +1 -2
- package/dist/types/src/shapes/Array.d.ts.map +1 -1
- package/dist/types/src/shapes/Audio.d.ts +1 -2
- package/dist/types/src/shapes/Audio.d.ts.map +1 -1
- package/dist/types/src/shapes/Beacon.d.ts +1 -2
- package/dist/types/src/shapes/Beacon.d.ts.map +1 -1
- package/dist/types/src/shapes/Chat.d.ts +1 -2
- package/dist/types/src/shapes/Chat.d.ts.map +1 -1
- package/dist/types/src/shapes/Constant.d.ts +1 -2
- package/dist/types/src/shapes/Constant.d.ts.map +1 -1
- package/dist/types/src/shapes/Database.d.ts +1 -2
- package/dist/types/src/shapes/Database.d.ts.map +1 -1
- package/dist/types/src/shapes/Function.d.ts +1 -3
- package/dist/types/src/shapes/Function.d.ts.map +1 -1
- package/dist/types/src/shapes/Gpt.d.ts +1 -2
- package/dist/types/src/shapes/Gpt.d.ts.map +1 -1
- package/dist/types/src/shapes/GptRealtime.d.ts +1 -2
- package/dist/types/src/shapes/GptRealtime.d.ts.map +1 -1
- package/dist/types/src/shapes/Json.d.ts +2 -3
- package/dist/types/src/shapes/Json.d.ts.map +1 -1
- package/dist/types/src/shapes/Logic.d.ts +2 -3
- package/dist/types/src/shapes/Logic.d.ts.map +1 -1
- package/dist/types/src/shapes/Queue.d.ts +2 -3
- package/dist/types/src/shapes/Queue.d.ts.map +1 -1
- package/dist/types/src/shapes/RNG.d.ts +1 -2
- package/dist/types/src/shapes/RNG.d.ts.map +1 -1
- package/dist/types/src/shapes/Scope.d.ts +1 -2
- package/dist/types/src/shapes/Scope.d.ts.map +1 -1
- package/dist/types/src/shapes/Surface.d.ts +1 -2
- package/dist/types/src/shapes/Surface.d.ts.map +1 -1
- package/dist/types/src/shapes/Switch.d.ts +1 -2
- package/dist/types/src/shapes/Switch.d.ts.map +1 -1
- package/dist/types/src/shapes/Table.d.ts +1 -2
- package/dist/types/src/shapes/Table.d.ts.map +1 -1
- package/dist/types/src/shapes/Text.d.ts +1 -2
- package/dist/types/src/shapes/Text.d.ts.map +1 -1
- package/dist/types/src/shapes/TextToImage.d.ts +1 -2
- package/dist/types/src/shapes/TextToImage.d.ts.map +1 -1
- package/dist/types/src/shapes/Thread.d.ts +2 -3
- package/dist/types/src/shapes/Thread.d.ts.map +1 -1
- package/dist/types/src/shapes/Trigger.d.ts +8 -4
- package/dist/types/src/shapes/Trigger.d.ts.map +1 -1
- package/dist/types/src/shapes/common/Box.d.ts +1 -1
- package/dist/types/src/shapes/common/FunctionBody.d.ts +1 -1
- package/dist/types/src/shapes/common/FunctionBody.d.ts.map +1 -1
- package/dist/types/src/shapes/common/TypeSelect.d.ts +1 -2
- package/dist/types/src/shapes/common/TypeSelect.d.ts.map +1 -1
- package/package.json +41 -40
- package/src/components/DiagnosticOverlay.tsx +4 -0
- package/src/components/index.ts +4 -0
- package/src/graph/controller.ts +14 -3
- package/src/hooks/useGraphMonitor.ts +2 -2
- package/src/shapes/Function.tsx +83 -9
- package/src/shapes/Trigger.tsx +18 -7
- package/src/shapes/common/FunctionBody.tsx +1 -0
package/src/graph/controller.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { FetchHttpClient } from '@effect/platform';
|
|
5
6
|
import { type Context, Effect, Either, Exit, Layer, Scope } from 'effect';
|
|
6
7
|
|
|
7
8
|
import { type ImageContentBlock } from '@dxos/artifact';
|
|
@@ -25,6 +26,7 @@ import {
|
|
|
25
26
|
SpaceService,
|
|
26
27
|
type ValueBag,
|
|
27
28
|
type GraphDiagnostic,
|
|
29
|
+
FunctionCallService,
|
|
28
30
|
} from '@dxos/conductor';
|
|
29
31
|
import { Resource } from '@dxos/context';
|
|
30
32
|
import type { EdgeClient, EdgeHttpClient } from '@dxos/edge-client';
|
|
@@ -144,6 +146,7 @@ export class ComputeGraphController extends Resource {
|
|
|
144
146
|
}
|
|
145
147
|
|
|
146
148
|
setServices(services: Partial<Services>) {
|
|
149
|
+
log.info('setServices', { services });
|
|
147
150
|
Object.assign(this._services, services);
|
|
148
151
|
}
|
|
149
152
|
|
|
@@ -248,10 +251,10 @@ export class ComputeGraphController extends Resource {
|
|
|
248
251
|
// TODO(dmaretskyi): Check if the node has a compute function and run computeOutputs if it does.
|
|
249
252
|
const effect = (computingOutputs ? executor.computeOutputs(nodeId) : executor.computeInputs(nodeId)).pipe(
|
|
250
253
|
Effect.withSpan('runGraph'),
|
|
251
|
-
Effect.provide(services),
|
|
252
254
|
Scope.extend(scope),
|
|
253
255
|
|
|
254
256
|
Effect.flatMap(computeValueBag),
|
|
257
|
+
Effect.provide(services),
|
|
255
258
|
Effect.withSpan('test'),
|
|
256
259
|
Effect.tap((values) => {
|
|
257
260
|
for (const [key, value] of Object.entries(values)) {
|
|
@@ -310,9 +313,9 @@ export class ComputeGraphController extends Resource {
|
|
|
310
313
|
// TODO(dmaretskyi): Check if the node has a compute function and run computeOutputs if it does.
|
|
311
314
|
const effect = (computingOutputs ? executor.computeOutputs(node) : executor.computeInputs(node)).pipe(
|
|
312
315
|
Effect.withSpan('runGraph'),
|
|
313
|
-
Effect.provide(services),
|
|
314
316
|
Scope.extend(scope),
|
|
315
317
|
Effect.flatMap(computeValueBag),
|
|
318
|
+
Effect.provide(services),
|
|
316
319
|
Effect.withSpan('test'),
|
|
317
320
|
Effect.tap((values) => {
|
|
318
321
|
for (const [key, value] of Object.entries(values)) {
|
|
@@ -349,7 +352,15 @@ export class ComputeGraphController extends Resource {
|
|
|
349
352
|
const spaceLayer =
|
|
350
353
|
services.spaceService != null ? Layer.succeed(SpaceService, services.spaceService) : SpaceService.empty;
|
|
351
354
|
|
|
352
|
-
|
|
355
|
+
const functionCallServiceLayer =
|
|
356
|
+
services.edgeHttpClient != null && services.spaceService != null
|
|
357
|
+
? Layer.succeed(
|
|
358
|
+
FunctionCallService,
|
|
359
|
+
FunctionCallService.fromClient(services.edgeHttpClient.baseUrl, services.spaceService.spaceId),
|
|
360
|
+
)
|
|
361
|
+
: Layer.succeed(FunctionCallService, FunctionCallService.mock());
|
|
362
|
+
|
|
363
|
+
return Layer.mergeAll(logLayer, gptLayer, queueLayer, spaceLayer, functionCallServiceLayer, FetchHttpClient.layer);
|
|
353
364
|
}
|
|
354
365
|
|
|
355
366
|
private _createLogger(): Context.Tag.Service<EventLogger> {
|
|
@@ -10,7 +10,7 @@ import { invariant } from '@dxos/invariant';
|
|
|
10
10
|
import { DXN } from '@dxos/keys';
|
|
11
11
|
import { getSpace } from '@dxos/react-client/echo';
|
|
12
12
|
import { type GraphMonitor, type CanvasGraphModel, type Connection } from '@dxos/react-ui-canvas-editor';
|
|
13
|
-
import {
|
|
13
|
+
import { isNonNullable } from '@dxos/util';
|
|
14
14
|
|
|
15
15
|
import { createComputeNode, isValidComputeNode } from '../graph';
|
|
16
16
|
import { type ComputeShape, type TriggerShape } from '../shapes';
|
|
@@ -79,7 +79,7 @@ export const useGraphMonitor = (model?: ComputeGraphModel): GraphMonitor<Compute
|
|
|
79
79
|
return model.edges.find((computeEdge) => computeEdge.input === input && computeEdge.output === output)
|
|
80
80
|
?.id;
|
|
81
81
|
})
|
|
82
|
-
.filter(
|
|
82
|
+
.filter(isNonNullable);
|
|
83
83
|
|
|
84
84
|
model.removeNodes(nodeIds);
|
|
85
85
|
model.removeEdges(edgeIds);
|
package/src/shapes/Function.tsx
CHANGED
|
@@ -2,14 +2,24 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React from 'react';
|
|
5
|
+
import React, { useCallback, useRef } from 'react';
|
|
6
6
|
|
|
7
7
|
import { AnyOutput, FunctionInput } from '@dxos/conductor';
|
|
8
|
-
import { S } from '@dxos/echo-schema';
|
|
9
|
-
import {
|
|
8
|
+
import { getSnapshot, S } from '@dxos/echo-schema';
|
|
9
|
+
import { FunctionType, ScriptType } from '@dxos/functions';
|
|
10
|
+
import { useClient } from '@dxos/react-client';
|
|
11
|
+
import { Filter, makeRef, parseId } from '@dxos/react-client/echo';
|
|
12
|
+
import {
|
|
13
|
+
TextBox,
|
|
14
|
+
type TextBoxControl,
|
|
15
|
+
type TextBoxProps,
|
|
16
|
+
type ShapeComponentProps,
|
|
17
|
+
type ShapeDef,
|
|
18
|
+
} from '@dxos/react-ui-canvas-editor';
|
|
10
19
|
|
|
11
|
-
import {
|
|
20
|
+
import { Box, createFunctionAnchors } from './common';
|
|
12
21
|
import { ComputeShape, createShape, type CreateShapeProps } from './defs';
|
|
22
|
+
import { useComputeNodeState } from '../hooks';
|
|
13
23
|
|
|
14
24
|
export const FunctionShape = S.extend(
|
|
15
25
|
ComputeShape,
|
|
@@ -23,18 +33,82 @@ export type FunctionShape = S.Schema.Type<typeof FunctionShape>;
|
|
|
23
33
|
export type CreateFunctionProps = CreateShapeProps<FunctionShape>;
|
|
24
34
|
|
|
25
35
|
export const createFunction = (props: CreateFunctionProps) =>
|
|
26
|
-
createShape<FunctionShape>({ type: 'function', size: { width:
|
|
36
|
+
createShape<FunctionShape>({ type: 'function', size: { width: 256, height: 192 }, ...props });
|
|
27
37
|
|
|
28
|
-
|
|
29
|
-
|
|
38
|
+
//
|
|
39
|
+
// Component
|
|
40
|
+
//
|
|
41
|
+
|
|
42
|
+
type TextInputComponentProps = ShapeComponentProps<FunctionShape> & TextBoxProps & { title?: string };
|
|
43
|
+
|
|
44
|
+
const TextInputComponent = ({ shape, title, ...props }: TextInputComponentProps) => {
|
|
45
|
+
const client = useClient();
|
|
46
|
+
const { node, runtime } = useComputeNodeState(shape);
|
|
47
|
+
const inputRef = useRef<TextBoxControl>(null);
|
|
48
|
+
|
|
49
|
+
const handleEnter = useCallback(
|
|
50
|
+
async (text: string) => {
|
|
51
|
+
const value = text.trim();
|
|
52
|
+
const { spaceId, objectId } = parseId(value);
|
|
53
|
+
if (!spaceId || !objectId) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const space = client.spaces.get(spaceId);
|
|
58
|
+
const object = space?.db.getObjectById(objectId);
|
|
59
|
+
if (!space || !(object instanceof ScriptType)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const {
|
|
64
|
+
objects: [fn],
|
|
65
|
+
} = await space.db.query(Filter.schema(FunctionType, { source: object })).run();
|
|
66
|
+
if (!fn) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
node.value = value;
|
|
71
|
+
node.function = makeRef(fn);
|
|
72
|
+
node.inputSchema = getSnapshot(fn.inputSchema);
|
|
73
|
+
node.outputSchema = getSnapshot(fn.outputSchema);
|
|
74
|
+
},
|
|
75
|
+
[client, node],
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const handleAction = useCallback(
|
|
79
|
+
(action: 'run' | 'open' | 'close') => {
|
|
80
|
+
if (action !== 'run') {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
runtime.evalNode();
|
|
85
|
+
},
|
|
86
|
+
[runtime],
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<Box shape={shape} title='Function' onAction={handleAction}>
|
|
91
|
+
<TextBox
|
|
92
|
+
{...props}
|
|
93
|
+
ref={inputRef}
|
|
94
|
+
value={node.value}
|
|
95
|
+
language={node.valueType === 'object' ? 'json' : undefined}
|
|
96
|
+
onBlur={handleEnter}
|
|
97
|
+
onEnter={handleEnter}
|
|
98
|
+
/>
|
|
99
|
+
</Box>
|
|
100
|
+
);
|
|
30
101
|
};
|
|
31
102
|
|
|
103
|
+
//
|
|
104
|
+
// Defs
|
|
105
|
+
//
|
|
106
|
+
|
|
32
107
|
export const functionShape: ShapeDef<FunctionShape> = {
|
|
33
108
|
type: 'function',
|
|
34
109
|
name: 'Function',
|
|
35
110
|
icon: 'ph--function--regular',
|
|
36
|
-
component:
|
|
111
|
+
component: TextInputComponent,
|
|
37
112
|
createShape: createFunction,
|
|
38
|
-
// TODO(burdon): Get dynamic schema.
|
|
39
113
|
getAnchors: (shape) => createFunctionAnchors(shape, FunctionInput, AnyOutput),
|
|
40
114
|
};
|
package/src/shapes/Trigger.tsx
CHANGED
|
@@ -6,22 +6,25 @@ import React, { useEffect } from 'react';
|
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
EmailTriggerOutput,
|
|
9
|
+
QueueTriggerOutput,
|
|
9
10
|
SubscriptionTriggerOutput,
|
|
10
11
|
TimerTriggerOutput,
|
|
11
12
|
VoidInput,
|
|
12
13
|
WebhookTriggerOutput,
|
|
13
14
|
} from '@dxos/conductor';
|
|
14
|
-
import { Ref, S } from '@dxos/echo-schema';
|
|
15
|
+
import { ObjectId, Ref, S } from '@dxos/echo-schema';
|
|
15
16
|
import {
|
|
16
17
|
type EmailTrigger,
|
|
17
18
|
FunctionTrigger,
|
|
19
|
+
type QueueTrigger,
|
|
18
20
|
type SubscriptionTrigger,
|
|
19
21
|
type TimerTrigger,
|
|
20
22
|
TriggerKind,
|
|
21
23
|
type TriggerType,
|
|
22
24
|
type WebhookTrigger,
|
|
23
25
|
} from '@dxos/functions';
|
|
24
|
-
import {
|
|
26
|
+
import { DXN, SpaceId } from '@dxos/keys';
|
|
27
|
+
import { create, makeRef, useSpace } from '@dxos/react-client/echo';
|
|
25
28
|
import { Select, type SelectRootProps } from '@dxos/react-ui';
|
|
26
29
|
import { type ShapeComponentProps, type ShapeDef } from '@dxos/react-ui-canvas-editor';
|
|
27
30
|
|
|
@@ -38,13 +41,14 @@ export const TriggerShape = S.extend(
|
|
|
38
41
|
export type TriggerShape = S.Schema.Type<typeof TriggerShape>;
|
|
39
42
|
|
|
40
43
|
export type CreateTriggerProps = CreateShapeProps<Omit<TriggerShape, 'functionTrigger'>> & {
|
|
44
|
+
spaceId?: SpaceId;
|
|
41
45
|
triggerKind?: TriggerKind;
|
|
42
46
|
};
|
|
43
47
|
|
|
44
48
|
export const createTrigger = (props: CreateTriggerProps): TriggerShape => {
|
|
45
49
|
const functionTrigger = create(FunctionTrigger, {
|
|
46
50
|
enabled: true,
|
|
47
|
-
spec: createTriggerSpec(props
|
|
51
|
+
spec: createTriggerSpec(props),
|
|
48
52
|
});
|
|
49
53
|
return createShape<TriggerShape>({
|
|
50
54
|
type: 'trigger',
|
|
@@ -57,11 +61,12 @@ export const createTrigger = (props: CreateTriggerProps): TriggerShape => {
|
|
|
57
61
|
export type TriggerComponentProps = ShapeComponentProps<TriggerShape>;
|
|
58
62
|
|
|
59
63
|
export const TriggerComponent = ({ shape }: TriggerComponentProps) => {
|
|
64
|
+
const space = useSpace();
|
|
60
65
|
const functionTrigger = shape.functionTrigger?.target;
|
|
61
66
|
|
|
62
67
|
useEffect(() => {
|
|
63
68
|
if (functionTrigger && !functionTrigger.spec) {
|
|
64
|
-
functionTrigger.spec = createTriggerSpec(TriggerKind.Email);
|
|
69
|
+
functionTrigger.spec = createTriggerSpec({ triggerKind: TriggerKind.Email, spaceId: space?.id });
|
|
65
70
|
}
|
|
66
71
|
}, [functionTrigger, functionTrigger?.spec]);
|
|
67
72
|
|
|
@@ -71,7 +76,7 @@ export const TriggerComponent = ({ shape }: TriggerComponentProps) => {
|
|
|
71
76
|
|
|
72
77
|
const setKind = (kind: TriggerKind) => {
|
|
73
78
|
if (functionTrigger?.spec?.type !== kind) {
|
|
74
|
-
functionTrigger!.spec = createTriggerSpec(
|
|
79
|
+
functionTrigger!.spec = createTriggerSpec({ triggerKind: TriggerKind.Email, spaceId: space?.id });
|
|
75
80
|
}
|
|
76
81
|
};
|
|
77
82
|
|
|
@@ -114,16 +119,21 @@ const TriggerKindSelect = ({ value, onValueChange }: Pick<SelectRootProps, 'valu
|
|
|
114
119
|
);
|
|
115
120
|
};
|
|
116
121
|
|
|
117
|
-
const createTriggerSpec = (
|
|
122
|
+
const createTriggerSpec = (props: { triggerKind?: TriggerKind; spaceId?: SpaceId }): TriggerType => {
|
|
123
|
+
const kind = props.triggerKind ?? TriggerKind.Email;
|
|
118
124
|
switch (kind) {
|
|
119
125
|
case TriggerKind.Timer:
|
|
120
|
-
return { type: TriggerKind.Timer, cron: '
|
|
126
|
+
return { type: TriggerKind.Timer, cron: '*/10 * * * * *' } satisfies TimerTrigger;
|
|
121
127
|
case TriggerKind.Webhook:
|
|
122
128
|
return { type: TriggerKind.Webhook, method: 'POST' } satisfies WebhookTrigger;
|
|
123
129
|
case TriggerKind.Subscription:
|
|
124
130
|
return { type: TriggerKind.Subscription, filter: {} } satisfies SubscriptionTrigger;
|
|
125
131
|
case TriggerKind.Email:
|
|
126
132
|
return { type: TriggerKind.Email } satisfies EmailTrigger;
|
|
133
|
+
case TriggerKind.Queue: {
|
|
134
|
+
const dxn = new DXN(DXN.kind.QUEUE, ['data', props.spaceId ?? SpaceId.random(), ObjectId.random()]).toString();
|
|
135
|
+
return { type: TriggerKind.Queue, queue: dxn } satisfies QueueTrigger;
|
|
136
|
+
}
|
|
127
137
|
}
|
|
128
138
|
};
|
|
129
139
|
|
|
@@ -133,6 +143,7 @@ const getOutputSchema = (kind: TriggerKind) => {
|
|
|
133
143
|
[TriggerKind.Subscription]: SubscriptionTriggerOutput,
|
|
134
144
|
[TriggerKind.Timer]: TimerTriggerOutput,
|
|
135
145
|
[TriggerKind.Webhook]: WebhookTriggerOutput,
|
|
146
|
+
[TriggerKind.Queue]: QueueTriggerOutput,
|
|
136
147
|
};
|
|
137
148
|
return kindToSchema[kind];
|
|
138
149
|
};
|