@dxos/react-ui-canvas-compute 0.7.5-labs.5f04cf6
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 +8 -0
- package/README.md +1 -0
- package/dist/lib/browser/index.mjs +2499 -0
- package/dist/lib/browser/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -0
- package/dist/lib/node/index.cjs +2591 -0
- package/dist/lib/node/index.cjs.map +7 -0
- package/dist/lib/node/meta.json +1 -0
- package/dist/lib/node-esm/index.mjs +2499 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/types/src/compute-layout.d.ts +9 -0
- package/dist/types/src/compute-layout.d.ts.map +1 -0
- package/dist/types/src/compute.stories.d.ts +28 -0
- package/dist/types/src/compute.stories.d.ts.map +1 -0
- package/dist/types/src/graph/controller.d.ts +139 -0
- package/dist/types/src/graph/controller.d.ts.map +1 -0
- package/dist/types/src/graph/index.d.ts +3 -0
- package/dist/types/src/graph/index.d.ts.map +1 -0
- package/dist/types/src/graph/node-defs.d.ts +6 -0
- package/dist/types/src/graph/node-defs.d.ts.map +1 -0
- package/dist/types/src/hooks/compute-context.d.ts +7 -0
- package/dist/types/src/hooks/compute-context.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +4 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -0
- package/dist/types/src/hooks/useComputeNodeState.d.ts +19 -0
- package/dist/types/src/hooks/useComputeNodeState.d.ts.map +1 -0
- package/dist/types/src/hooks/useGraphMonitor.d.ts +14 -0
- package/dist/types/src/hooks/useGraphMonitor.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +6 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/json.test.d.ts +21 -0
- package/dist/types/src/json.test.d.ts.map +1 -0
- package/dist/types/src/registry.d.ts +9 -0
- package/dist/types/src/registry.d.ts.map +1 -0
- package/dist/types/src/schema.test.d.ts +2 -0
- package/dist/types/src/schema.test.d.ts.map +1 -0
- package/dist/types/src/shapes/Append.d.ts +54 -0
- package/dist/types/src/shapes/Append.d.ts.map +1 -0
- package/dist/types/src/shapes/Array.d.ts +38 -0
- package/dist/types/src/shapes/Array.d.ts.map +1 -0
- package/dist/types/src/shapes/Audio.d.ts +54 -0
- package/dist/types/src/shapes/Audio.d.ts.map +1 -0
- package/dist/types/src/shapes/Beacon.d.ts +54 -0
- package/dist/types/src/shapes/Beacon.d.ts.map +1 -0
- package/dist/types/src/shapes/Boolean.d.ts +233 -0
- package/dist/types/src/shapes/Boolean.d.ts.map +1 -0
- package/dist/types/src/shapes/Chat.d.ts +57 -0
- package/dist/types/src/shapes/Chat.d.ts.map +1 -0
- package/dist/types/src/shapes/Constant.d.ts +60 -0
- package/dist/types/src/shapes/Constant.d.ts.map +1 -0
- package/dist/types/src/shapes/Database.d.ts +54 -0
- package/dist/types/src/shapes/Database.d.ts.map +1 -0
- package/dist/types/src/shapes/Function.d.ts +54 -0
- package/dist/types/src/shapes/Function.d.ts.map +1 -0
- package/dist/types/src/shapes/Gpt.d.ts +54 -0
- package/dist/types/src/shapes/Gpt.d.ts.map +1 -0
- package/dist/types/src/shapes/GptRealtime.d.ts +54 -0
- package/dist/types/src/shapes/GptRealtime.d.ts.map +1 -0
- package/dist/types/src/shapes/Json.d.ts +107 -0
- package/dist/types/src/shapes/Json.d.ts.map +1 -0
- package/dist/types/src/shapes/Logic.d.ts +109 -0
- package/dist/types/src/shapes/Logic.d.ts.map +1 -0
- package/dist/types/src/shapes/Queue.d.ts +58 -0
- package/dist/types/src/shapes/Queue.d.ts.map +1 -0
- package/dist/types/src/shapes/RNG.d.ts +58 -0
- package/dist/types/src/shapes/RNG.d.ts.map +1 -0
- package/dist/types/src/shapes/Scope.d.ts +54 -0
- package/dist/types/src/shapes/Scope.d.ts.map +1 -0
- package/dist/types/src/shapes/Surface.d.ts +54 -0
- package/dist/types/src/shapes/Surface.d.ts.map +1 -0
- package/dist/types/src/shapes/Switch.d.ts +54 -0
- package/dist/types/src/shapes/Switch.d.ts.map +1 -0
- package/dist/types/src/shapes/Table.d.ts +54 -0
- package/dist/types/src/shapes/Table.d.ts.map +1 -0
- package/dist/types/src/shapes/Template.d.ts +56 -0
- package/dist/types/src/shapes/Template.d.ts.map +1 -0
- package/dist/types/src/shapes/Text.d.ts +54 -0
- package/dist/types/src/shapes/Text.d.ts.map +1 -0
- package/dist/types/src/shapes/TextToImage.d.ts +54 -0
- package/dist/types/src/shapes/TextToImage.d.ts.map +1 -0
- package/dist/types/src/shapes/Thread.d.ts +58 -0
- package/dist/types/src/shapes/Thread.d.ts.map +1 -0
- package/dist/types/src/shapes/Trigger.d.ts +64 -0
- package/dist/types/src/shapes/Trigger.d.ts.map +1 -0
- package/dist/types/src/shapes/common/Box.d.ts +25 -0
- package/dist/types/src/shapes/common/Box.d.ts.map +1 -0
- package/dist/types/src/shapes/common/FunctionBody.d.ts +15 -0
- package/dist/types/src/shapes/common/FunctionBody.d.ts.map +1 -0
- package/dist/types/src/shapes/common/TypeSelect.d.ts +4 -0
- package/dist/types/src/shapes/common/TypeSelect.d.ts.map +1 -0
- package/dist/types/src/shapes/common/index.d.ts +4 -0
- package/dist/types/src/shapes/common/index.d.ts.map +1 -0
- package/dist/types/src/shapes/defs.d.ts +39 -0
- package/dist/types/src/shapes/defs.d.ts.map +1 -0
- package/dist/types/src/shapes/index.d.ts +27 -0
- package/dist/types/src/shapes/index.d.ts.map +1 -0
- package/dist/types/src/testing/circuits.d.ts +193 -0
- package/dist/types/src/testing/circuits.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +2 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +85 -0
- package/src/README.md +47 -0
- package/src/compute-layout.ts +37 -0
- package/src/compute.stories.tsx +362 -0
- package/src/graph/controller.ts +405 -0
- package/src/graph/index.ts +6 -0
- package/src/graph/node-defs.ts +82 -0
- package/src/hooks/compute-context.ts +19 -0
- package/src/hooks/index.ts +7 -0
- package/src/hooks/useComputeNodeState.ts +83 -0
- package/src/hooks/useGraphMonitor.ts +133 -0
- package/src/index.ts +9 -0
- package/src/json.test.ts +35 -0
- package/src/registry.ts +100 -0
- package/src/schema.test.ts +62 -0
- package/src/shapes/Append.tsx +43 -0
- package/src/shapes/Array.tsx +61 -0
- package/src/shapes/Audio.tsx +55 -0
- package/src/shapes/Beacon.tsx +56 -0
- package/src/shapes/Boolean.tsx +215 -0
- package/src/shapes/Chat.tsx +77 -0
- package/src/shapes/Constant.tsx +125 -0
- package/src/shapes/Database.tsx +39 -0
- package/src/shapes/Function.tsx +40 -0
- package/src/shapes/Gpt.tsx +91 -0
- package/src/shapes/GptRealtime.tsx +168 -0
- package/src/shapes/Json.tsx +103 -0
- package/src/shapes/Logic.tsx +82 -0
- package/src/shapes/Queue.tsx +78 -0
- package/src/shapes/RNG.tsx +84 -0
- package/src/shapes/Scope.tsx +54 -0
- package/src/shapes/Surface.tsx +57 -0
- package/src/shapes/Switch.tsx +53 -0
- package/src/shapes/Table.tsx +45 -0
- package/src/shapes/Template.tsx +98 -0
- package/src/shapes/Text.tsx +56 -0
- package/src/shapes/TextToImage.tsx +39 -0
- package/src/shapes/Thread.tsx +87 -0
- package/src/shapes/Trigger.tsx +152 -0
- package/src/shapes/common/Box.tsx +74 -0
- package/src/shapes/common/FunctionBody.tsx +122 -0
- package/src/shapes/common/TypeSelect.tsx +27 -0
- package/src/shapes/common/index.ts +7 -0
- package/src/shapes/defs.ts +50 -0
- package/src/shapes/index.ts +31 -0
- package/src/testing/circuits.ts +320 -0
- package/src/testing/index.ts +5 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/testing/index.ts"],"names":[],"mappings":"AAIA,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":"5.7.2"}
|
package/package.json
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dxos/react-ui-canvas-compute",
|
|
3
|
+
"version": "0.7.5-labs.5f04cf6",
|
|
4
|
+
"description": "A compute graph extension for the canvas editor component.",
|
|
5
|
+
"homepage": "https://dxos.org",
|
|
6
|
+
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"author": "DXOS.org",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/types/src/index.d.ts",
|
|
12
|
+
"browser": "./dist/lib/browser/index.mjs",
|
|
13
|
+
"node": "./dist/lib/node-esm/index.mjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"types": "dist/types/src/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"src"
|
|
20
|
+
],
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@antv/graphlib": "^2.0.4",
|
|
23
|
+
"@antv/layout": "^1.2.13",
|
|
24
|
+
"chess.js": "^1.0.0",
|
|
25
|
+
"@dxos/app-framework": "0.7.5-labs.5f04cf6",
|
|
26
|
+
"@dxos/assistant": "0.7.5-labs.5f04cf6",
|
|
27
|
+
"@dxos/context": "0.7.5-labs.5f04cf6",
|
|
28
|
+
"@dxos/artifact": "0.7.5-labs.5f04cf6",
|
|
29
|
+
"@dxos/conductor": "0.7.5-labs.5f04cf6",
|
|
30
|
+
"@dxos/debug": "0.7.5-labs.5f04cf6",
|
|
31
|
+
"@dxos/async": "0.7.5-labs.5f04cf6",
|
|
32
|
+
"@dxos/echo-schema": "0.7.5-labs.5f04cf6",
|
|
33
|
+
"@dxos/edge-client": "0.7.5-labs.5f04cf6",
|
|
34
|
+
"@dxos/graph": "0.7.5-labs.5f04cf6",
|
|
35
|
+
"@dxos/keys": "0.7.5-labs.5f04cf6",
|
|
36
|
+
"@dxos/invariant": "0.7.5-labs.5f04cf6",
|
|
37
|
+
"@dxos/functions": "0.7.5-labs.5f04cf6",
|
|
38
|
+
"@dxos/log": "0.7.5-labs.5f04cf6",
|
|
39
|
+
"@dxos/node-std": "0.7.5-labs.5f04cf6",
|
|
40
|
+
"@dxos/react-client": "0.7.5-labs.5f04cf6",
|
|
41
|
+
"@dxos/live-object": "0.7.5-labs.5f04cf6",
|
|
42
|
+
"@dxos/react-edge-client": "0.7.5-labs.5f04cf6",
|
|
43
|
+
"@dxos/react-ui-attention": "0.7.5-labs.5f04cf6",
|
|
44
|
+
"@dxos/react-ui-canvas-editor": "0.7.5-labs.5f04cf6",
|
|
45
|
+
"@dxos/react-ui-canvas": "0.7.5-labs.5f04cf6",
|
|
46
|
+
"@dxos/react-ui-form": "0.7.5-labs.5f04cf6",
|
|
47
|
+
"@dxos/react-ui-editor": "0.7.5-labs.5f04cf6",
|
|
48
|
+
"@dxos/react-ui-sfx": "0.7.5-labs.5f04cf6",
|
|
49
|
+
"@dxos/react-ui-stack": "0.7.5-labs.5f04cf6",
|
|
50
|
+
"@dxos/react-ui-syntax-highlighter": "0.7.5-labs.5f04cf6",
|
|
51
|
+
"@dxos/schema": "0.7.5-labs.5f04cf6",
|
|
52
|
+
"@dxos/util": "0.7.5-labs.5f04cf6"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@effect/ai": "^0.5.1",
|
|
56
|
+
"@effect/platform": "^0.72.1",
|
|
57
|
+
"@types/lodash.defaultsdeep": "^4.6.6",
|
|
58
|
+
"@types/react": "~18.2.0",
|
|
59
|
+
"@types/react-dom": "~18.2.0",
|
|
60
|
+
"effect": "^3.12.3",
|
|
61
|
+
"lodash.defaultsdeep": "^4.6.1",
|
|
62
|
+
"react": "~18.2.0",
|
|
63
|
+
"react-dom": "~18.2.0",
|
|
64
|
+
"vite": "5.4.7",
|
|
65
|
+
"@dxos/artifact-testing": "0.7.5-labs.5f04cf6",
|
|
66
|
+
"@dxos/app-framework": "0.7.5-labs.5f04cf6",
|
|
67
|
+
"@dxos/compute": "0.7.5-labs.5f04cf6",
|
|
68
|
+
"@dxos/random": "0.7.5-labs.5f04cf6",
|
|
69
|
+
"@dxos/echo-signals": "0.7.5-labs.5f04cf6",
|
|
70
|
+
"@dxos/react-ui": "0.7.5-labs.5f04cf6",
|
|
71
|
+
"@dxos/react-ui-theme": "0.7.5-labs.5f04cf6",
|
|
72
|
+
"@dxos/storybook-utils": "0.7.5-labs.5f04cf6"
|
|
73
|
+
},
|
|
74
|
+
"peerDependencies": {
|
|
75
|
+
"@effect/schema": "^0.75.5",
|
|
76
|
+
"effect": "^3.12.3",
|
|
77
|
+
"react": "~18.2.0",
|
|
78
|
+
"react-dom": "~18.2.0",
|
|
79
|
+
"@dxos/react-ui-theme": "0.7.5-labs.5f04cf6",
|
|
80
|
+
"@dxos/react-ui": "0.7.5-labs.5f04cf6"
|
|
81
|
+
},
|
|
82
|
+
"publishConfig": {
|
|
83
|
+
"access": "public"
|
|
84
|
+
}
|
|
85
|
+
}
|
package/src/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Compute
|
|
2
|
+
|
|
3
|
+
- This folder represents a "compute plugin" for the Canvas component.
|
|
4
|
+
- It defines a set of Shapes that implement a state machine.
|
|
5
|
+
|
|
6
|
+
### Notes (burdon)
|
|
7
|
+
|
|
8
|
+
- [x] Text/markdown view (parse cot, etc.)
|
|
9
|
+
- [x] Surface view
|
|
10
|
+
- [ ] Prompt with handlebar variables (dynamic schema)
|
|
11
|
+
- [ ] Artifact tool (find artifact defintions AND instances); conext (e.g., current game).
|
|
12
|
+
- [ ] Chess plugin defines artifact to generate and process FEN?
|
|
13
|
+
- [ ] Deploy funciton to play game.
|
|
14
|
+
- [ ] Function node (call script)
|
|
15
|
+
- [ ] Group nodes (sub-graph)
|
|
16
|
+
- [ ] Markdown surface node (parse COT)
|
|
17
|
+
- [ ] Auto layout graphs
|
|
18
|
+
|
|
19
|
+
### Notes (dmaretskyi)
|
|
20
|
+
|
|
21
|
+
- Consider how different types of edges affect computations:
|
|
22
|
+
- Being able to provide values by reference
|
|
23
|
+
- e.g. GPT gets connected to a vector index that is represented by a separate node that can be queried
|
|
24
|
+
- history node can be provided by reference (as a mutable Thread object) that GPT mutates without requiring a back reference
|
|
25
|
+
- Consider separating purely functional inputs from imperative ones
|
|
26
|
+
- This is what UnrealEngine does - functional inputs trigger computations when the data changes, imperative inputs can trigger computations with the same or no data
|
|
27
|
+
- imperative inputs can represent events or streams of data
|
|
28
|
+
- functional inputs represent values
|
|
29
|
+
|
|
30
|
+
- persisting compute graph and canvas in ECHO
|
|
31
|
+
- (Canvas)-[.nodes]->(CanvasNode)-[.node]->(ComputeNode)<-[.nodes]-(ComputeGraph), (Canvas)-[.computeGraph]->(ComputeGraph)
|
|
32
|
+
|
|
33
|
+
- Computations can operate purely on the ComputeGraph
|
|
34
|
+
- Computations return an ExecutionTrace that is streamable
|
|
35
|
+
- Canvas graph doesn't directly interact with the compute graph, but reads the execution trace
|
|
36
|
+
|
|
37
|
+
- ExecutionTrace
|
|
38
|
+
- has an execution trace id -- one graph can have multiple independent parallel traces
|
|
39
|
+
- series of events - each event is associated with a particular node in a particular graph
|
|
40
|
+
- events include:
|
|
41
|
+
- inputs/outputs being updated
|
|
42
|
+
- logs associated with a node or a graph
|
|
43
|
+
- node state updates (can a node have internal state separate from inputs/outputs)
|
|
44
|
+
- timestep? - to correlate events that happen during a single execution time
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { DefaultInput, DefaultOutput } from '@dxos/conductor';
|
|
6
|
+
import { toEffectSchema } from '@dxos/echo-schema';
|
|
7
|
+
import { type Anchor, ShapeLayout, ShapeRegistry } from '@dxos/react-ui-canvas-editor';
|
|
8
|
+
|
|
9
|
+
import { type ComputeGraphController } from './graph';
|
|
10
|
+
import { type ComputeShape, createFunctionAnchors } from './shapes';
|
|
11
|
+
|
|
12
|
+
// TODO(burdon): Customize layout. Specialize ComputeShapeDef and registry.
|
|
13
|
+
export class ComputeShapeLayout extends ShapeLayout {
|
|
14
|
+
constructor(
|
|
15
|
+
private _controller: ComputeGraphController,
|
|
16
|
+
registry: ShapeRegistry,
|
|
17
|
+
) {
|
|
18
|
+
super(registry);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// TODO(burdon): Doesn't update.
|
|
22
|
+
override getAnchors(shape: ComputeShape): Record<string, Anchor> {
|
|
23
|
+
const shapeDef = this._registry.getShapeDef(shape.type);
|
|
24
|
+
let anchors = shapeDef?.getAnchors?.(shape) ?? {};
|
|
25
|
+
if (shape.node) {
|
|
26
|
+
const node = this._controller.graph.getNode(shape.node);
|
|
27
|
+
if (node.inputSchema || node.outputSchema) {
|
|
28
|
+
// TODO(burdon): Requires that component defined input and output types.
|
|
29
|
+
const inputSchema = node.inputSchema ? toEffectSchema(node.inputSchema) : DefaultInput;
|
|
30
|
+
const outputSchema = node.outputSchema ? toEffectSchema(node.outputSchema) : DefaultOutput;
|
|
31
|
+
anchors = createFunctionAnchors(shape, inputSchema, outputSchema);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return anchors;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import '@dxos-theme';
|
|
6
|
+
|
|
7
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
8
|
+
import React, { type PropsWithChildren, useEffect, useMemo, useRef, useState } from 'react';
|
|
9
|
+
|
|
10
|
+
import { withPluginManager } from '@dxos/app-framework/testing';
|
|
11
|
+
import { capabilities, createEdgeServices } from '@dxos/artifact-testing';
|
|
12
|
+
import { type UnsubscribeCallback } from '@dxos/async';
|
|
13
|
+
import { type ComputeGraphModel, ComputeNode, DefaultInput, DefaultOutput } from '@dxos/conductor';
|
|
14
|
+
import { S, toEffectSchema } from '@dxos/echo-schema';
|
|
15
|
+
import { withClientProvider } from '@dxos/react-client/testing';
|
|
16
|
+
import { Select, Toolbar } from '@dxos/react-ui';
|
|
17
|
+
import { withAttention } from '@dxos/react-ui-attention/testing';
|
|
18
|
+
import {
|
|
19
|
+
type Anchor,
|
|
20
|
+
Editor,
|
|
21
|
+
type EditorController,
|
|
22
|
+
type EditorRootProps,
|
|
23
|
+
ShapeLayout,
|
|
24
|
+
ShapeRegistry,
|
|
25
|
+
} from '@dxos/react-ui-canvas-editor';
|
|
26
|
+
import { Container, useSelection } from '@dxos/react-ui-canvas-editor/testing';
|
|
27
|
+
import { JsonFilter } from '@dxos/react-ui-syntax-highlighter';
|
|
28
|
+
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
29
|
+
|
|
30
|
+
import { type ComputeGraphController } from './graph';
|
|
31
|
+
import { ComputeContext, useGraphMonitor } from './hooks';
|
|
32
|
+
import { computeShapes } from './registry';
|
|
33
|
+
import { createFunctionAnchors, type ComputeShape } from './shapes';
|
|
34
|
+
import {
|
|
35
|
+
createControlCircuit,
|
|
36
|
+
createGPTRealtimeCircuit,
|
|
37
|
+
createLogicCircuit,
|
|
38
|
+
createComputeGraphController,
|
|
39
|
+
createBasicCircuit,
|
|
40
|
+
createGptCircuit,
|
|
41
|
+
createAudioCircuit,
|
|
42
|
+
createTransformCircuit,
|
|
43
|
+
createTemplateCircuit,
|
|
44
|
+
createArtifactCircuit,
|
|
45
|
+
} from './testing';
|
|
46
|
+
import { ComputeShapeLayout } from './compute-layout';
|
|
47
|
+
|
|
48
|
+
const FormSchema = S.omit<any, any, ['subgraph']>('subgraph')(ComputeNode);
|
|
49
|
+
|
|
50
|
+
const sidebarTypes: NonNullable<RenderProps['sidebar']>[] = ['canvas', 'compute', 'controller', 'selected'] as const;
|
|
51
|
+
|
|
52
|
+
// TODO(burdon): Move to async/context?
|
|
53
|
+
const combine = (...cbs: UnsubscribeCallback[]) => {
|
|
54
|
+
return () => {
|
|
55
|
+
for (const cb of cbs) {
|
|
56
|
+
cb();
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
type RenderProps = EditorRootProps<ComputeShape> &
|
|
62
|
+
PropsWithChildren<{
|
|
63
|
+
init?: boolean;
|
|
64
|
+
sidebar?: 'canvas' | 'compute' | 'controller' | 'selected';
|
|
65
|
+
computeGraph?: ComputeGraphModel;
|
|
66
|
+
controller?: ComputeGraphController;
|
|
67
|
+
}>;
|
|
68
|
+
|
|
69
|
+
const Render = ({
|
|
70
|
+
id = 'test',
|
|
71
|
+
children,
|
|
72
|
+
graph,
|
|
73
|
+
controller,
|
|
74
|
+
init,
|
|
75
|
+
sidebar: _sidebar,
|
|
76
|
+
registry,
|
|
77
|
+
...props
|
|
78
|
+
}: RenderProps) => {
|
|
79
|
+
const [, forceUpdate] = useState({});
|
|
80
|
+
|
|
81
|
+
const editorRef = useRef<EditorController>(null);
|
|
82
|
+
|
|
83
|
+
// Selection.
|
|
84
|
+
const [selection, selected] = useSelection(graph);
|
|
85
|
+
|
|
86
|
+
const getComputeNode = (id?: string): ComputeNode | undefined => {
|
|
87
|
+
if (id) {
|
|
88
|
+
const node = graph?.getNode(id) as ComputeShape;
|
|
89
|
+
if (node?.node) {
|
|
90
|
+
return controller?.graph.getNode(node.node);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// Sidebar.
|
|
96
|
+
const [sidebar, setSidebar] = useState(_sidebar);
|
|
97
|
+
const json = useMemo(() => {
|
|
98
|
+
switch (sidebar) {
|
|
99
|
+
case 'canvas':
|
|
100
|
+
return { graph };
|
|
101
|
+
case 'compute':
|
|
102
|
+
return { graph: controller?.graph };
|
|
103
|
+
case 'controller':
|
|
104
|
+
return { state: controller?.state };
|
|
105
|
+
case 'selected':
|
|
106
|
+
return { shape: selected, compute: getComputeNode(selected?.id) };
|
|
107
|
+
}
|
|
108
|
+
}, [graph, controller, sidebar, selected]);
|
|
109
|
+
|
|
110
|
+
// Controller.
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
if (!controller || !graph) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
void controller.open();
|
|
117
|
+
const off = combine(
|
|
118
|
+
controller.update.on(() => {
|
|
119
|
+
void editorRef.current?.update();
|
|
120
|
+
forceUpdate({});
|
|
121
|
+
}),
|
|
122
|
+
|
|
123
|
+
// TODO(burdon): Every node is called on every update.
|
|
124
|
+
controller.output.on(({ nodeId, property, value }) => {
|
|
125
|
+
if (value.type === 'not-executed') {
|
|
126
|
+
// If the node didn't execute, don't trigger.
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const edge = graph.edges.find((edge) => {
|
|
131
|
+
const source = graph.getNode(edge.source);
|
|
132
|
+
return (source as ComputeShape).node === nodeId && edge.output === property;
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
if (edge) {
|
|
136
|
+
void editorRef.current?.action?.({ type: 'trigger', edges: [edge] });
|
|
137
|
+
}
|
|
138
|
+
}),
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
return () => {
|
|
142
|
+
void controller.close();
|
|
143
|
+
off();
|
|
144
|
+
};
|
|
145
|
+
}, [graph, controller]);
|
|
146
|
+
|
|
147
|
+
// Sync monitor.
|
|
148
|
+
const graphMonitor = useGraphMonitor(controller?.graph);
|
|
149
|
+
|
|
150
|
+
// Layout.
|
|
151
|
+
const layout = useMemo(
|
|
152
|
+
() => (controller && registry ? new ComputeShapeLayout(controller, registry) : undefined),
|
|
153
|
+
[controller, registry],
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
if (!controller) {
|
|
157
|
+
return <div />;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return (
|
|
161
|
+
<div className='grid grid-cols-[1fr,360px] w-full h-full'>
|
|
162
|
+
<ComputeContext.Provider value={{ controller }}>
|
|
163
|
+
<Container id={id} classNames={['flex grow overflow-hidden', !sidebar && 'col-span-2']}>
|
|
164
|
+
<Editor.Root<ComputeShape>
|
|
165
|
+
ref={editorRef}
|
|
166
|
+
id={id}
|
|
167
|
+
graph={graph}
|
|
168
|
+
graphMonitor={graphMonitor}
|
|
169
|
+
layout={layout}
|
|
170
|
+
registry={registry}
|
|
171
|
+
selection={selection}
|
|
172
|
+
autoZoom
|
|
173
|
+
{...props}
|
|
174
|
+
>
|
|
175
|
+
<Editor.Canvas>{children}</Editor.Canvas>
|
|
176
|
+
<Editor.UI />
|
|
177
|
+
</Editor.Root>
|
|
178
|
+
</Container>
|
|
179
|
+
</ComputeContext.Provider>
|
|
180
|
+
|
|
181
|
+
{sidebar && (
|
|
182
|
+
<Container id='sidebar' classNames='flex flex-col h-full overflow-hidden'>
|
|
183
|
+
<Toolbar.Root classNames='p-1'>
|
|
184
|
+
<Select.Root value={sidebar} onValueChange={(value) => setSidebar(value as RenderProps['sidebar'])}>
|
|
185
|
+
<Select.TriggerButton classNames='is-full'>{sidebar}</Select.TriggerButton>
|
|
186
|
+
<Select.Portal>
|
|
187
|
+
<Select.Content>
|
|
188
|
+
<Select.Viewport>
|
|
189
|
+
{sidebarTypes.map((type) => (
|
|
190
|
+
<Select.Item key={type} value={type}>
|
|
191
|
+
{type}
|
|
192
|
+
</Select.Item>
|
|
193
|
+
))}
|
|
194
|
+
</Select.Viewport>
|
|
195
|
+
</Select.Content>
|
|
196
|
+
</Select.Portal>
|
|
197
|
+
</Select.Root>
|
|
198
|
+
</Toolbar.Root>
|
|
199
|
+
|
|
200
|
+
<div className='flex flex-col h-full overflow-hidden divide-y divider-separator'>
|
|
201
|
+
{sidebar === 'selected' && selected && (
|
|
202
|
+
<div>Form</div>
|
|
203
|
+
// <Form<ComputeNode> schema={FormSchema} values={getComputeNode(selected.id) ?? {}} Custom={{}} />
|
|
204
|
+
)}
|
|
205
|
+
|
|
206
|
+
<JsonFilter data={json} />
|
|
207
|
+
</div>
|
|
208
|
+
</Container>
|
|
209
|
+
)}
|
|
210
|
+
</div>
|
|
211
|
+
);
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const meta: Meta<RenderProps> = {
|
|
215
|
+
title: 'ui/react-ui-canvas-compute/compute',
|
|
216
|
+
component: Editor.Root,
|
|
217
|
+
render: Render,
|
|
218
|
+
decorators: [
|
|
219
|
+
withClientProvider({ createIdentity: true, createSpace: true }),
|
|
220
|
+
withTheme,
|
|
221
|
+
withAttention,
|
|
222
|
+
withLayout({ fullscreen: true, tooltips: true }),
|
|
223
|
+
withPluginManager({ capabilities }),
|
|
224
|
+
],
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
export default meta;
|
|
228
|
+
|
|
229
|
+
type Story = StoryObj<RenderProps>;
|
|
230
|
+
|
|
231
|
+
export const Default: Story = {
|
|
232
|
+
args: {
|
|
233
|
+
// debug: true,
|
|
234
|
+
showGrid: false,
|
|
235
|
+
snapToGrid: false,
|
|
236
|
+
sidebar: 'selected',
|
|
237
|
+
registry: new ShapeRegistry(computeShapes),
|
|
238
|
+
...createComputeGraphController(),
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
export const Beacon: Story = {
|
|
243
|
+
args: {
|
|
244
|
+
// debug: true,
|
|
245
|
+
showGrid: false,
|
|
246
|
+
snapToGrid: false,
|
|
247
|
+
sidebar: 'selected',
|
|
248
|
+
registry: new ShapeRegistry(computeShapes),
|
|
249
|
+
...createComputeGraphController(createBasicCircuit()),
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
export const Transform: Story = {
|
|
254
|
+
args: {
|
|
255
|
+
// debug: true,
|
|
256
|
+
showGrid: false,
|
|
257
|
+
snapToGrid: false,
|
|
258
|
+
sidebar: 'selected',
|
|
259
|
+
registry: new ShapeRegistry(computeShapes),
|
|
260
|
+
...createComputeGraphController(createTransformCircuit()),
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
export const Logic: Story = {
|
|
265
|
+
args: {
|
|
266
|
+
// debug: true,
|
|
267
|
+
showGrid: false,
|
|
268
|
+
snapToGrid: false,
|
|
269
|
+
sidebar: 'compute',
|
|
270
|
+
registry: new ShapeRegistry(computeShapes),
|
|
271
|
+
...createComputeGraphController(createLogicCircuit()),
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
export const Control: Story = {
|
|
276
|
+
args: {
|
|
277
|
+
// debug: true,
|
|
278
|
+
showGrid: false,
|
|
279
|
+
snapToGrid: false,
|
|
280
|
+
sidebar: 'compute',
|
|
281
|
+
registry: new ShapeRegistry(computeShapes),
|
|
282
|
+
...createComputeGraphController(createControlCircuit()),
|
|
283
|
+
},
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
// export const Ollama: Story = {
|
|
287
|
+
// args: {
|
|
288
|
+
// // debug: true,
|
|
289
|
+
// showGrid: false,
|
|
290
|
+
// snapToGrid: false,
|
|
291
|
+
// registry: new ShapeRegistry(computeShapes),
|
|
292
|
+
// ...createComputeGraphController(createTest3(), createEdgeServices()),
|
|
293
|
+
// },
|
|
294
|
+
// };
|
|
295
|
+
|
|
296
|
+
export const Template: Story = {
|
|
297
|
+
args: {
|
|
298
|
+
showGrid: false,
|
|
299
|
+
snapToGrid: false,
|
|
300
|
+
// sidebar: 'controller',
|
|
301
|
+
registry: new ShapeRegistry(computeShapes),
|
|
302
|
+
...createComputeGraphController(createTemplateCircuit(), createEdgeServices()),
|
|
303
|
+
},
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
export const GPT: Story = {
|
|
307
|
+
args: {
|
|
308
|
+
// debug: true,
|
|
309
|
+
showGrid: false,
|
|
310
|
+
snapToGrid: false,
|
|
311
|
+
// sidebar: 'json',
|
|
312
|
+
sidebar: 'controller',
|
|
313
|
+
registry: new ShapeRegistry(computeShapes),
|
|
314
|
+
...createComputeGraphController(createGptCircuit({ history: true }), createEdgeServices()),
|
|
315
|
+
},
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
export const Plugins: Story = {
|
|
319
|
+
args: {
|
|
320
|
+
// debug: true,
|
|
321
|
+
showGrid: false,
|
|
322
|
+
snapToGrid: false,
|
|
323
|
+
// sidebar: 'json',
|
|
324
|
+
registry: new ShapeRegistry(computeShapes),
|
|
325
|
+
...createComputeGraphController(
|
|
326
|
+
createGptCircuit({ history: true, image: true, artifact: true }),
|
|
327
|
+
createEdgeServices(),
|
|
328
|
+
),
|
|
329
|
+
},
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
export const Artifact: Story = {
|
|
333
|
+
args: {
|
|
334
|
+
// debug: true,
|
|
335
|
+
showGrid: false,
|
|
336
|
+
snapToGrid: false,
|
|
337
|
+
// sidebar: 'json',
|
|
338
|
+
registry: new ShapeRegistry(computeShapes),
|
|
339
|
+
...createComputeGraphController(createArtifactCircuit(), createEdgeServices()),
|
|
340
|
+
},
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
export const Audio: Story = {
|
|
344
|
+
args: {
|
|
345
|
+
// debug: true,
|
|
346
|
+
showGrid: false,
|
|
347
|
+
snapToGrid: false,
|
|
348
|
+
sidebar: 'controller',
|
|
349
|
+
registry: new ShapeRegistry(computeShapes),
|
|
350
|
+
...createComputeGraphController(createAudioCircuit(), createEdgeServices()),
|
|
351
|
+
},
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
export const Voice: Story = {
|
|
355
|
+
args: {
|
|
356
|
+
showGrid: false,
|
|
357
|
+
snapToGrid: false,
|
|
358
|
+
sidebar: 'controller',
|
|
359
|
+
registry: new ShapeRegistry(computeShapes),
|
|
360
|
+
...createComputeGraphController(createGPTRealtimeCircuit(), createEdgeServices()),
|
|
361
|
+
},
|
|
362
|
+
};
|