@dxos/react-ui-canvas-compute 0.8.4-main.67995b8 → 0.8.4-main.69d29f4
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 +882 -1031
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +882 -1031
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +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 +19 -32
- 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 +2 -2
- package/dist/types/src/hooks/useComputeGraphController.d.ts.map +1 -1
- package/dist/types/src/hooks/useComputeNodeState.d.ts +2 -2
- package/dist/types/src/hooks/useComputeNodeState.d.ts.map +1 -1
- package/dist/types/src/hooks/useGraphMonitor.d.ts +1 -1
- 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 +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 +1 -1
- 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/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 +1 -1
- package/dist/types/src/shapes/Json.d.ts.map +1 -1
- package/dist/types/src/shapes/Logic.d.ts +1 -1
- package/dist/types/src/shapes/Logic.d.ts.map +1 -1
- package/dist/types/src/shapes/Queue.d.ts +1 -1
- package/dist/types/src/shapes/Queue.d.ts.map +1 -1
- package/dist/types/src/shapes/RNG.d.ts +1 -1
- 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 +1 -1
- 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 +6 -34
- 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/Box.d.ts.map +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/defs.d.ts +2 -1
- package/dist/types/src/shapes/defs.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 +58 -53
- package/src/compute-layout.ts +1 -1
- package/src/compute.stories.tsx +78 -121
- package/src/graph/controller.ts +117 -75
- package/src/graph/node-defs.ts +6 -6
- package/src/hooks/useComputeGraphController.ts +2 -2
- package/src/hooks/useComputeNodeState.ts +7 -5
- package/src/hooks/useGraphMonitor.ts +10 -9
- package/src/json.test.ts +4 -4
- package/src/registry.ts +2 -2
- package/src/schema.test.ts +11 -11
- package/src/shapes/Append.tsx +3 -3
- package/src/shapes/Array.tsx +3 -3
- package/src/shapes/Audio.tsx +5 -4
- package/src/shapes/Beacon.tsx +5 -4
- package/src/shapes/Boolean.tsx +5 -5
- package/src/shapes/Chat.tsx +4 -3
- package/src/shapes/Constant.tsx +4 -3
- package/src/shapes/Database.tsx +2 -2
- package/src/shapes/Function.tsx +17 -14
- package/src/shapes/Gpt.tsx +8 -6
- package/src/shapes/GptRealtime.tsx +3 -3
- package/src/shapes/Json.tsx +4 -3
- package/src/shapes/Logic.tsx +3 -3
- package/src/shapes/Queue.tsx +12 -7
- package/src/shapes/RNG.tsx +9 -4
- package/src/shapes/Scope.tsx +6 -5
- package/src/shapes/Surface.tsx +10 -5
- package/src/shapes/Switch.tsx +5 -4
- package/src/shapes/Table.tsx +6 -6
- package/src/shapes/Template.tsx +6 -5
- package/src/shapes/Text.tsx +5 -4
- package/src/shapes/TextToImage.tsx +2 -2
- package/src/shapes/Thread.tsx +9 -9
- package/src/shapes/Trigger.tsx +50 -57
- package/src/shapes/common/Box.tsx +7 -7
- package/src/shapes/common/FunctionBody.tsx +5 -4
- package/src/shapes/common/TypeSelect.tsx +1 -1
- package/src/shapes/defs.ts +5 -4
- package/src/testing/circuits.ts +5 -14
package/src/graph/controller.ts
CHANGED
|
@@ -2,15 +2,21 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
import
|
|
5
|
+
import type * as Context from 'effect/Context';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
import * as Either from 'effect/Either';
|
|
8
|
+
import * as Exit from 'effect/Exit';
|
|
9
|
+
import * as Layer from 'effect/Layer';
|
|
10
|
+
import type * as ManagedRuntime from 'effect/ManagedRuntime';
|
|
11
|
+
import * as Scope from 'effect/Scope';
|
|
12
|
+
|
|
13
|
+
import type { AiService } from '@dxos/ai';
|
|
8
14
|
import { Event, synchronized } from '@dxos/async';
|
|
9
15
|
import {
|
|
10
16
|
type ComputeEdge,
|
|
11
17
|
type ComputeGraphModel,
|
|
12
|
-
type ComputeMeta,
|
|
13
18
|
type ComputeNode,
|
|
19
|
+
type ComputeNodeMeta,
|
|
14
20
|
type GptInput,
|
|
15
21
|
type GptOutput,
|
|
16
22
|
type GraphDiagnostic,
|
|
@@ -19,15 +25,25 @@ import {
|
|
|
19
25
|
isNotExecuted,
|
|
20
26
|
} from '@dxos/conductor';
|
|
21
27
|
import { Resource } from '@dxos/context';
|
|
22
|
-
import
|
|
23
|
-
import {
|
|
28
|
+
import type { Database } from '@dxos/echo';
|
|
29
|
+
import { unwrapExit } from '@dxos/effect';
|
|
30
|
+
import {
|
|
31
|
+
ComputeEventLogger,
|
|
32
|
+
type ComputeEventPayload,
|
|
33
|
+
type CredentialsService,
|
|
34
|
+
type FunctionInvocationService,
|
|
35
|
+
type QueueService,
|
|
36
|
+
TracingService,
|
|
37
|
+
} from '@dxos/functions';
|
|
24
38
|
import { log } from '@dxos/log';
|
|
25
39
|
import { type CanvasGraphModel } from '@dxos/react-ui-canvas-editor';
|
|
40
|
+
import { type ContentBlock } from '@dxos/types';
|
|
26
41
|
|
|
27
|
-
import { resolveComputeNode } from './node-defs';
|
|
28
42
|
import { createComputeGraph } from '../hooks';
|
|
29
43
|
import { type ComputeShape } from '../shapes';
|
|
30
44
|
|
|
45
|
+
import { resolveComputeNode } from './node-defs';
|
|
46
|
+
|
|
31
47
|
// TODO(burdon): API package for conductor.
|
|
32
48
|
export const InvalidStateError = Error;
|
|
33
49
|
|
|
@@ -42,7 +58,7 @@ export interface GptExecutor {
|
|
|
42
58
|
invoke: FunctionCallback<GptInput, GptOutput>;
|
|
43
59
|
|
|
44
60
|
// TODO(dmaretskyi): A hack to get image artifacts working. Rework into querying images from the ai-service store.
|
|
45
|
-
imageCache: Map<string,
|
|
61
|
+
imageCache: Map<string, ContentBlock.Image>;
|
|
46
62
|
}
|
|
47
63
|
|
|
48
64
|
export type RuntimeValue =
|
|
@@ -67,6 +83,14 @@ type ComputeOutputEvent = {
|
|
|
67
83
|
value: RuntimeValue;
|
|
68
84
|
};
|
|
69
85
|
|
|
86
|
+
// TODO(dmaretskyi): Re-use function servies definition.
|
|
87
|
+
export type ComputeServices =
|
|
88
|
+
| AiService.AiService
|
|
89
|
+
| Database.Service
|
|
90
|
+
| QueueService
|
|
91
|
+
| CredentialsService
|
|
92
|
+
| FunctionInvocationService;
|
|
93
|
+
|
|
70
94
|
/**
|
|
71
95
|
* Nodes that will automatically trigger the execution of the graph on startup.
|
|
72
96
|
*/
|
|
@@ -74,10 +98,10 @@ const AUTO_TRIGGER_NODES = ['chat', 'switch', 'constant'];
|
|
|
74
98
|
|
|
75
99
|
export const createComputeGraphController = (
|
|
76
100
|
graph: CanvasGraphModel<ComputeShape>,
|
|
77
|
-
|
|
101
|
+
computeRuntime: ManagedRuntime.ManagedRuntime<ComputeServices, never>,
|
|
78
102
|
) => {
|
|
79
103
|
const computeGraph = createComputeGraph(graph);
|
|
80
|
-
const controller = new ComputeGraphController(
|
|
104
|
+
const controller = new ComputeGraphController(computeRuntime, computeGraph);
|
|
81
105
|
return { controller, graph };
|
|
82
106
|
};
|
|
83
107
|
|
|
@@ -112,7 +136,7 @@ export class ComputeGraphController extends Resource {
|
|
|
112
136
|
public readonly events = new Event<ComputeEventPayload>();
|
|
113
137
|
|
|
114
138
|
constructor(
|
|
115
|
-
private readonly
|
|
139
|
+
private readonly _computeRuntime: ManagedRuntime.ManagedRuntime<ComputeServices, never>,
|
|
116
140
|
/** Persistent compute graph. */
|
|
117
141
|
private readonly _graph: ComputeGraphModel,
|
|
118
142
|
) {
|
|
@@ -153,7 +177,14 @@ export class ComputeGraphController extends Resource {
|
|
|
153
177
|
/**
|
|
154
178
|
* Inputs and outputs for all nodes.
|
|
155
179
|
*/
|
|
156
|
-
get state()
|
|
180
|
+
get state(): Record<
|
|
181
|
+
string,
|
|
182
|
+
{
|
|
183
|
+
node: ComputeNode;
|
|
184
|
+
input: Record<string, RuntimeValue>;
|
|
185
|
+
output: Record<string, RuntimeValue>;
|
|
186
|
+
}
|
|
187
|
+
> {
|
|
157
188
|
const ids = [...new Set([...Object.keys(this._runtimeStateInputs), ...Object.keys(this._runtimeStateOutputs)])];
|
|
158
189
|
return Object.fromEntries(
|
|
159
190
|
ids.map((id) => [
|
|
@@ -200,7 +231,7 @@ export class ComputeGraphController extends Resource {
|
|
|
200
231
|
});
|
|
201
232
|
}
|
|
202
233
|
|
|
203
|
-
async getMeta(node: ComputeNode): Promise<
|
|
234
|
+
async getMeta(node: ComputeNode): Promise<ComputeNodeMeta> {
|
|
204
235
|
const { meta } = await resolveComputeNode(node);
|
|
205
236
|
return meta;
|
|
206
237
|
}
|
|
@@ -220,37 +251,41 @@ export class ComputeGraphController extends Resource {
|
|
|
220
251
|
executor.setOutputs(nodeId, Effect.succeed(ValueBag.make(outputs)));
|
|
221
252
|
}
|
|
222
253
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
254
|
+
unwrapExit(
|
|
255
|
+
await this._computeRuntime.runPromiseExit(
|
|
256
|
+
Effect.gen(this, function* () {
|
|
257
|
+
const scope = yield* Scope.make();
|
|
258
|
+
|
|
259
|
+
// TODO(dmaretskyi): Code duplication.
|
|
260
|
+
const executable = yield* Effect.promise(() => resolveComputeNode(this._graph.getNode(nodeId)));
|
|
261
|
+
const computingOutputs = executable.exec != null;
|
|
262
|
+
// TODO(dmaretskyi): Check if the node has a compute function and run computeOutputs if it does.
|
|
263
|
+
const effect = (computingOutputs ? executor.computeOutputs(nodeId) : executor.computeInputs(nodeId)).pipe(
|
|
264
|
+
Effect.withSpan('runGraph'),
|
|
265
|
+
Scope.extend(scope),
|
|
266
|
+
Effect.provide(
|
|
267
|
+
ComputeEventLogger.layerFromTracing.pipe(
|
|
268
|
+
Layer.provideMerge(TracingService.layerNoop), // TODO(dmaretskyi): Plug-in tracing events to visual feedback in the compute graph editor.
|
|
269
|
+
),
|
|
270
|
+
),
|
|
271
|
+
Effect.flatMap(computeValueBag),
|
|
272
|
+
Effect.withSpan('test'),
|
|
273
|
+
Effect.tap((values) => {
|
|
274
|
+
for (const [key, value] of Object.entries(values)) {
|
|
275
|
+
if (computingOutputs) {
|
|
276
|
+
this._onOutputComputed(nodeId, key, value);
|
|
277
|
+
} else {
|
|
278
|
+
this._onInputComputed(nodeId, key, value);
|
|
279
|
+
}
|
|
245
280
|
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
);
|
|
281
|
+
}),
|
|
282
|
+
);
|
|
249
283
|
|
|
250
|
-
|
|
284
|
+
yield* effect;
|
|
251
285
|
|
|
252
|
-
|
|
253
|
-
|
|
286
|
+
yield* Scope.close(scope, Exit.void);
|
|
287
|
+
}),
|
|
288
|
+
),
|
|
254
289
|
);
|
|
255
290
|
|
|
256
291
|
this.update.emit();
|
|
@@ -278,44 +313,51 @@ export class ComputeGraphController extends Resource {
|
|
|
278
313
|
: this._graph.nodes.filter((node) => node.type != null && AUTO_TRIGGER_NODES.includes(node.type));
|
|
279
314
|
const allAffectedNodes = [...new Set(triggerNodes.flatMap((node) => executor.getAllDependantNodes(node.id)))];
|
|
280
315
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
316
|
+
unwrapExit(
|
|
317
|
+
await this._computeRuntime.runPromiseExit(
|
|
318
|
+
Effect.gen(this, function* () {
|
|
319
|
+
const scope = yield* Scope.make();
|
|
320
|
+
|
|
321
|
+
// TODO(burdon): Return map?
|
|
322
|
+
const tasks: Effect.Effect<unknown, any, ComputeServices>[] = [];
|
|
323
|
+
for (const node of allAffectedNodes) {
|
|
324
|
+
// TODO(dmaretskyi): Code duplication.
|
|
325
|
+
const executable = yield* Effect.promise(() => resolveComputeNode(this._graph.getNode(node)));
|
|
326
|
+
const computingOutputs = executable.exec != null;
|
|
327
|
+
|
|
328
|
+
// TODO(dmaretskyi): Check if the node has a compute function and run computeOutputs if it does.
|
|
329
|
+
const effect = (computingOutputs ? executor.computeOutputs(node) : executor.computeInputs(node)).pipe(
|
|
330
|
+
Effect.withSpan('runGraph'),
|
|
331
|
+
Scope.extend(scope),
|
|
332
|
+
Effect.flatMap(computeValueBag),
|
|
333
|
+
Effect.provide(
|
|
334
|
+
ComputeEventLogger.layerFromTracing.pipe(
|
|
335
|
+
Layer.provideMerge(TracingService.layerNoop), // TODO(dmaretskyi): Plug-in tracing events to visual feedback in the compute graph editor.
|
|
336
|
+
),
|
|
337
|
+
),
|
|
338
|
+
|
|
339
|
+
Effect.withSpan('test'),
|
|
340
|
+
Effect.tap((values) => {
|
|
341
|
+
for (const [key, value] of Object.entries(values)) {
|
|
342
|
+
if (computingOutputs) {
|
|
343
|
+
this._onOutputComputed(node, key, value);
|
|
344
|
+
} else {
|
|
345
|
+
this._onInputComputed(node, key, value);
|
|
346
|
+
}
|
|
305
347
|
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
);
|
|
348
|
+
}),
|
|
349
|
+
);
|
|
309
350
|
|
|
310
|
-
|
|
311
|
-
|
|
351
|
+
tasks.push(effect);
|
|
352
|
+
}
|
|
312
353
|
|
|
313
|
-
|
|
314
|
-
|
|
354
|
+
//
|
|
355
|
+
yield* Effect.all(tasks);
|
|
315
356
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
357
|
+
//
|
|
358
|
+
yield* Scope.close(scope, Exit.void);
|
|
359
|
+
}),
|
|
360
|
+
),
|
|
319
361
|
);
|
|
320
362
|
|
|
321
363
|
this.update.emit();
|
package/src/graph/node-defs.ts
CHANGED
|
@@ -3,16 +3,16 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
-
NODE_INPUT,
|
|
7
|
-
NODE_OUTPUT,
|
|
8
6
|
type ComputeNode,
|
|
9
7
|
type Executable,
|
|
8
|
+
NODE_INPUT,
|
|
9
|
+
NODE_OUTPUT,
|
|
10
10
|
type NodeType,
|
|
11
|
-
registry,
|
|
12
11
|
getTemplateInputSchema,
|
|
12
|
+
registry,
|
|
13
13
|
} from '@dxos/conductor';
|
|
14
14
|
import { raise } from '@dxos/debug';
|
|
15
|
-
import {
|
|
15
|
+
import { JsonSchema, Obj } from '@dxos/echo';
|
|
16
16
|
import { invariant } from '@dxos/invariant';
|
|
17
17
|
|
|
18
18
|
import { type ComputeShape, type ConstantShape, type TemplateShape } from '../shapes';
|
|
@@ -68,7 +68,7 @@ const nodeFactory: Record<NodeType | 'trigger', (shape: ComputeShape) => Compute
|
|
|
68
68
|
['switch' as const]: () => createNode('switch'),
|
|
69
69
|
['template' as const]: (shape) => {
|
|
70
70
|
const node = createNode('template', { valueType: (shape as TemplateShape).valueType, value: shape.text });
|
|
71
|
-
node.inputSchema = toJsonSchema(getTemplateInputSchema(node));
|
|
71
|
+
node.inputSchema = JsonSchema.toJsonSchema(getTemplateInputSchema(node));
|
|
72
72
|
return node;
|
|
73
73
|
},
|
|
74
74
|
['text' as const]: () => createNode('text'),
|
|
@@ -77,7 +77,7 @@ const nodeFactory: Record<NodeType | 'trigger', (shape: ComputeShape) => Compute
|
|
|
77
77
|
};
|
|
78
78
|
|
|
79
79
|
const createNode = (type: string, props?: Partial<ComputeNode>): ComputeNode => ({
|
|
80
|
-
id:
|
|
80
|
+
id: Obj.ID.random(),
|
|
81
81
|
type,
|
|
82
82
|
...props,
|
|
83
83
|
});
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { type RefObject, useEffect, useState } from 'react';
|
|
6
6
|
|
|
7
7
|
import { type CleanupFn } from '@dxos/async';
|
|
8
|
-
import { type
|
|
8
|
+
import { type EditorController, type EditorRootProps } from '@dxos/react-ui-canvas-editor';
|
|
9
9
|
|
|
10
10
|
import { type ComputeGraphController } from '../graph';
|
|
11
11
|
import { type ComputeShape } from '../shapes';
|
|
@@ -21,7 +21,7 @@ const combine = (...cbs: CleanupFn[]) => {
|
|
|
21
21
|
|
|
22
22
|
export type UseComputeGraphControllerOptions = Pick<EditorRootProps<ComputeShape>, 'graph'> & {
|
|
23
23
|
controller: ComputeGraphController | null;
|
|
24
|
-
editorRef: RefObject<EditorController>;
|
|
24
|
+
editorRef: RefObject<EditorController | null>;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
export const useComputeGraphController = ({ controller, graph, editorRef }: UseComputeGraphControllerOptions) => {
|
|
@@ -2,20 +2,21 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
6
|
import { useCallback, useEffect, useState } from 'react';
|
|
7
7
|
|
|
8
|
-
import type { ComputeNode,
|
|
8
|
+
import type { ComputeNode, ComputeNodeMeta } from '@dxos/conductor';
|
|
9
9
|
import type { ComputeEventPayload } from '@dxos/functions';
|
|
10
10
|
import { invariant } from '@dxos/invariant';
|
|
11
11
|
|
|
12
|
-
import { useComputeContext } from './compute-context';
|
|
13
12
|
import { type RuntimeValue } from '../graph';
|
|
14
13
|
import { type ComputeShape } from '../shapes';
|
|
15
14
|
|
|
15
|
+
import { useComputeContext } from './compute-context';
|
|
16
|
+
|
|
16
17
|
export type ComputeNodeState = {
|
|
17
18
|
node: ComputeNode;
|
|
18
|
-
meta:
|
|
19
|
+
meta: ComputeNodeMeta;
|
|
19
20
|
runtime: {
|
|
20
21
|
inputs: Record<string, RuntimeValue>;
|
|
21
22
|
outputs: Record<string, RuntimeValue>;
|
|
@@ -32,7 +33,7 @@ export const useComputeNodeState = (shape: ComputeShape): ComputeNodeState => {
|
|
|
32
33
|
const { controller } = useComputeContext();
|
|
33
34
|
invariant(controller);
|
|
34
35
|
|
|
35
|
-
const [meta, setMeta] = useState<
|
|
36
|
+
const [meta, setMeta] = useState<ComputeNodeMeta>();
|
|
36
37
|
useEffect(() => {
|
|
37
38
|
let disposed = false;
|
|
38
39
|
queueMicrotask(async () => {
|
|
@@ -42,6 +43,7 @@ export const useComputeNodeState = (shape: ComputeShape): ComputeNodeState => {
|
|
|
42
43
|
if (disposed) {
|
|
43
44
|
return;
|
|
44
45
|
}
|
|
46
|
+
|
|
45
47
|
setMeta(meta);
|
|
46
48
|
});
|
|
47
49
|
|
|
@@ -5,10 +5,9 @@
|
|
|
5
5
|
import { useMemo } from 'react';
|
|
6
6
|
|
|
7
7
|
import { type ComputeEdge, ComputeGraphModel, type ComputeNode, DEFAULT_INPUT, DEFAULT_OUTPUT } from '@dxos/conductor';
|
|
8
|
-
import {
|
|
8
|
+
import { Obj, Ref } from '@dxos/echo';
|
|
9
9
|
import { invariant } from '@dxos/invariant';
|
|
10
|
-
import {
|
|
11
|
-
import { type GraphMonitor, type CanvasGraphModel, type Connection } from '@dxos/react-ui-canvas-editor';
|
|
10
|
+
import { type CanvasGraphModel, type Connection, type GraphMonitor } from '@dxos/react-ui-canvas-editor';
|
|
12
11
|
import { isNonNullable } from '@dxos/util';
|
|
13
12
|
|
|
14
13
|
import { createComputeNode, isValidComputeNode } from '../graph';
|
|
@@ -27,7 +26,7 @@ export const mapEdge = (
|
|
|
27
26
|
invariant(targetNode?.node);
|
|
28
27
|
|
|
29
28
|
return {
|
|
30
|
-
id:
|
|
29
|
+
id: Obj.ID.random(),
|
|
31
30
|
source: sourceNode.node,
|
|
32
31
|
target: targetNode.node,
|
|
33
32
|
output,
|
|
@@ -113,19 +112,21 @@ export const createComputeGraph = (graph?: CanvasGraphModel<ComputeShape>) => {
|
|
|
113
112
|
const linkTriggerToCompute = (graph: ComputeGraphModel, computeNode: ComputeNode, triggerData: TriggerShape) => {
|
|
114
113
|
const functionTrigger = triggerData.functionTrigger?.target;
|
|
115
114
|
invariant(functionTrigger);
|
|
116
|
-
functionTrigger
|
|
117
|
-
|
|
115
|
+
Obj.change(functionTrigger, (t) => {
|
|
116
|
+
t.function = Ref.make(graph.root);
|
|
117
|
+
t.inputNodeId = computeNode.id;
|
|
118
|
+
});
|
|
118
119
|
};
|
|
119
120
|
|
|
120
121
|
const deleteTriggerObjects = (computeGraph: ComputeGraphModel, deleted: CanvasGraphModel) => {
|
|
121
|
-
const
|
|
122
|
-
if (!
|
|
122
|
+
const db = Obj.getDatabase(computeGraph.root);
|
|
123
|
+
if (!db) {
|
|
123
124
|
return;
|
|
124
125
|
}
|
|
125
126
|
for (const node of deleted.nodes) {
|
|
126
127
|
if (node.type === 'trigger') {
|
|
127
128
|
const trigger = node as TriggerShape;
|
|
128
|
-
|
|
129
|
+
db.remove(trigger.functionTrigger!.target!);
|
|
129
130
|
}
|
|
130
131
|
}
|
|
131
132
|
};
|
package/src/json.test.ts
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
6
|
import { describe, test } from 'vitest';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { Graph } from '@dxos/graph';
|
|
9
9
|
|
|
10
10
|
import { createGptCircuit } from './testing';
|
|
11
11
|
|
|
12
12
|
export const Shape = Schema.extend(
|
|
13
|
-
|
|
13
|
+
Graph.Node,
|
|
14
14
|
Schema.Struct({
|
|
15
15
|
text: Schema.optional(Schema.String),
|
|
16
16
|
guide: Schema.optional(Schema.Boolean),
|
|
@@ -19,7 +19,7 @@ export const Shape = Schema.extend(
|
|
|
19
19
|
);
|
|
20
20
|
|
|
21
21
|
export const Connection = Schema.extend(
|
|
22
|
-
|
|
22
|
+
Graph.Edge,
|
|
23
23
|
Schema.Struct({
|
|
24
24
|
input: Schema.optional(Schema.String),
|
|
25
25
|
output: Schema.optional(Schema.String),
|
package/src/registry.ts
CHANGED
package/src/schema.test.ts
CHANGED
|
@@ -2,38 +2,38 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
6
|
import { describe, test } from 'vitest';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import { BaseGraphNode, Graph } from '@dxos/graph';
|
|
8
|
+
import { Graph } from '@dxos/graph';
|
|
10
9
|
import {
|
|
10
|
+
CanvasGraphModel,
|
|
11
11
|
Polygon,
|
|
12
|
+
Shape,
|
|
12
13
|
createEllipse,
|
|
13
14
|
createPath,
|
|
14
15
|
createRectangle,
|
|
15
16
|
isPath,
|
|
16
17
|
isPolygon,
|
|
17
|
-
Shape,
|
|
18
18
|
} from '@dxos/react-ui-canvas-editor';
|
|
19
19
|
|
|
20
|
-
import {
|
|
20
|
+
import { ComputeShape, createFunction, createSwitch } from './shapes';
|
|
21
21
|
|
|
22
22
|
describe('compute', () => {
|
|
23
23
|
test('model', ({ expect }) => {
|
|
24
|
-
|
|
24
|
+
const model = CanvasGraphModel.create<ComputeShape>();
|
|
25
25
|
const node = createSwitch({ id: 'x', center: { x: 0, y: 0 }, size: { width: 80, height: 80 } });
|
|
26
26
|
console.log(JSON.stringify(node, null, 2));
|
|
27
27
|
expect(Schema.is(ComputeShape)(node)).toBe(true);
|
|
28
28
|
expect(Schema.is(Polygon)(node)).toBe(true);
|
|
29
29
|
expect(Schema.is(Shape)(node)).toBe(true);
|
|
30
|
-
expect(Schema.is(
|
|
30
|
+
expect(Schema.is(Graph.Node)(node)).toBe(true);
|
|
31
31
|
|
|
32
|
-
const graph =
|
|
33
|
-
graph.nodes.push(node);
|
|
32
|
+
const graph: Graph.Any = { nodes: [], edges: [] };
|
|
33
|
+
graph.nodes.push(node);
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
model.createNode(node);
|
|
36
|
+
console.log(JSON.stringify(model, null, 2));
|
|
37
37
|
});
|
|
38
38
|
});
|
|
39
39
|
|
package/src/shapes/Append.tsx
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
6
|
import React from 'react';
|
|
7
7
|
|
|
8
8
|
import { AppendInput } from '@dxos/conductor';
|
|
9
9
|
import { type ShapeComponentProps, type ShapeDef } from '@dxos/react-ui-canvas-editor';
|
|
10
10
|
|
|
11
|
-
import {
|
|
12
|
-
import { ComputeShape,
|
|
11
|
+
import { FunctionBody, createFunctionAnchors, getHeight } from './common';
|
|
12
|
+
import { ComputeShape, type CreateShapeProps, createShape } from './defs';
|
|
13
13
|
|
|
14
14
|
export const AppendShape = Schema.extend(
|
|
15
15
|
ComputeShape,
|
package/src/shapes/Array.tsx
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
6
|
import React from 'react';
|
|
7
7
|
|
|
8
8
|
import { ReducerInput, ReducerOutput } from '@dxos/conductor';
|
|
9
9
|
import { type ShapeComponentProps, type ShapeDef } from '@dxos/react-ui-canvas-editor';
|
|
10
10
|
|
|
11
|
-
import {
|
|
12
|
-
import { ComputeShape,
|
|
11
|
+
import { FunctionBody, createFunctionAnchors, getHeight } from './common';
|
|
12
|
+
import { ComputeShape, type CreateShapeProps, createShape } from './defs';
|
|
13
13
|
|
|
14
14
|
//
|
|
15
15
|
// Data
|
package/src/shapes/Audio.tsx
CHANGED
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
6
|
import React, { useEffect, useState } from 'react';
|
|
7
7
|
|
|
8
8
|
import { Icon } from '@dxos/react-ui';
|
|
9
|
-
import {
|
|
9
|
+
import { type ShapeComponentProps, type ShapeDef, createAnchorMap } from '@dxos/react-ui-canvas-editor';
|
|
10
10
|
|
|
11
|
-
import { ComputeShape, createAnchorId, createShape, type CreateShapeProps } from './defs';
|
|
12
11
|
import { useComputeNodeState } from '../hooks';
|
|
13
12
|
|
|
13
|
+
import { ComputeShape, type CreateShapeProps, createAnchorId, createShape } from './defs';
|
|
14
|
+
|
|
14
15
|
export const AudioShape = Schema.extend(
|
|
15
16
|
ComputeShape,
|
|
16
17
|
Schema.Struct({
|
|
@@ -34,7 +35,7 @@ export const AudioComponent = ({ shape }: ShapeComponentProps<AudioShape>) => {
|
|
|
34
35
|
|
|
35
36
|
// https://docs.pmnd.rs/react-three-fiber/api/canvas#render-props
|
|
36
37
|
return (
|
|
37
|
-
<div className='flex
|
|
38
|
+
<div className='flex is-full justify-center items-center'>
|
|
38
39
|
<Icon
|
|
39
40
|
icon={active ? 'ph--microphone--regular' : 'ph--microphone-slash--regular'}
|
|
40
41
|
classNames={['transition opacity-20 duration-1000', active && 'opacity-100 text-red-500']}
|
package/src/shapes/Beacon.tsx
CHANGED
|
@@ -2,16 +2,17 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
6
|
import React from 'react';
|
|
7
7
|
|
|
8
8
|
import { DEFAULT_INPUT, isTruthy } from '@dxos/conductor';
|
|
9
9
|
import { Icon } from '@dxos/react-ui';
|
|
10
|
-
import {
|
|
10
|
+
import { type ShapeComponentProps, type ShapeDef, createAnchorMap } from '@dxos/react-ui-canvas-editor';
|
|
11
11
|
|
|
12
|
-
import { ComputeShape, createAnchorId, createShape, type CreateShapeProps } from './defs';
|
|
13
12
|
import { useComputeNodeState } from '../hooks';
|
|
14
13
|
|
|
14
|
+
import { ComputeShape, type CreateShapeProps, createAnchorId, createShape } from './defs';
|
|
15
|
+
|
|
15
16
|
export const BeaconShape = Schema.extend(
|
|
16
17
|
ComputeShape,
|
|
17
18
|
Schema.Struct({
|
|
@@ -32,7 +33,7 @@ export const BeaconComponent = ({ shape }: ShapeComponentProps<BeaconShape>) =>
|
|
|
32
33
|
const value = input?.type === 'executed' ? input.value : false;
|
|
33
34
|
|
|
34
35
|
return (
|
|
35
|
-
<div className='flex
|
|
36
|
+
<div className='flex is-full justify-center items-center'>
|
|
36
37
|
<Icon
|
|
37
38
|
icon='ph--sun--regular'
|
|
38
39
|
classNames={['transition opacity-20 duration-1000', isTruthy(value) && 'opacity-100 text-yellow-500']}
|
package/src/shapes/Boolean.tsx
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
6
|
import React, { type FC } from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { type ShapeDef, getAnchorPoints } from '@dxos/react-ui-canvas-editor';
|
|
9
9
|
import { createAnchors } from '@dxos/react-ui-canvas-editor';
|
|
10
10
|
|
|
11
|
-
import { ComputeShape, createAnchorId, createShape
|
|
11
|
+
import { ComputeShape, type CreateShapeProps, createAnchorId, createShape } from './defs';
|
|
12
12
|
|
|
13
13
|
//
|
|
14
14
|
// Gate utils.
|
|
@@ -57,7 +57,7 @@ const defineShape = <S extends GateShape>({
|
|
|
57
57
|
// Be careful not to name component factories with a capital letter.
|
|
58
58
|
component: () => {
|
|
59
59
|
return (
|
|
60
|
-
<div className='flex
|
|
60
|
+
<div className='flex is-full justify-center items-center'>
|
|
61
61
|
<Symbol />
|
|
62
62
|
</div>
|
|
63
63
|
);
|
|
@@ -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='is-full bs-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} />
|