@dxos/react-ui-canvas-compute 0.9.1-staging.ee54ba693a → 0.11.0
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/index.mjs +2164 -0
- package/dist/lib/index.mjs.map +1 -0
- package/dist/types/src/compute.stories.d.ts.map +1 -1
- package/dist/types/src/shapes/Append.d.ts +2 -51
- package/dist/types/src/shapes/Append.d.ts.map +1 -1
- package/dist/types/src/shapes/Array.d.ts +2 -34
- package/dist/types/src/shapes/Array.d.ts.map +1 -1
- package/dist/types/src/shapes/Audio.d.ts +2 -51
- package/dist/types/src/shapes/Audio.d.ts.map +1 -1
- package/dist/types/src/shapes/Beacon.d.ts +2 -51
- package/dist/types/src/shapes/Beacon.d.ts.map +1 -1
- package/dist/types/src/shapes/Chat.d.ts +2 -51
- package/dist/types/src/shapes/Chat.d.ts.map +1 -1
- package/dist/types/src/shapes/Constant.d.ts +2 -53
- package/dist/types/src/shapes/Constant.d.ts.map +1 -1
- package/dist/types/src/shapes/Database.d.ts +2 -51
- package/dist/types/src/shapes/Database.d.ts.map +1 -1
- package/dist/types/src/shapes/Feed.d.ts +2 -51
- package/dist/types/src/shapes/Feed.d.ts.map +1 -1
- package/dist/types/src/shapes/Function.d.ts +7 -50
- package/dist/types/src/shapes/Function.d.ts.map +1 -1
- package/dist/types/src/shapes/Gpt.d.ts +2 -51
- package/dist/types/src/shapes/Gpt.d.ts.map +1 -1
- package/dist/types/src/shapes/GptRealtime.d.ts +2 -51
- package/dist/types/src/shapes/GptRealtime.d.ts.map +1 -1
- package/dist/types/src/shapes/Json.d.ts +2 -101
- package/dist/types/src/shapes/Json.d.ts.map +1 -1
- package/dist/types/src/shapes/Logic.d.ts +2 -103
- package/dist/types/src/shapes/Logic.d.ts.map +1 -1
- package/dist/types/src/shapes/RNG.d.ts +2 -55
- package/dist/types/src/shapes/RNG.d.ts.map +1 -1
- package/dist/types/src/shapes/Scope.d.ts +2 -51
- package/dist/types/src/shapes/Scope.d.ts.map +1 -1
- package/dist/types/src/shapes/Surface.d.ts +2 -51
- package/dist/types/src/shapes/Surface.d.ts.map +1 -1
- package/dist/types/src/shapes/Switch.d.ts +2 -51
- package/dist/types/src/shapes/Switch.d.ts.map +1 -1
- package/dist/types/src/shapes/Table.d.ts +2 -51
- package/dist/types/src/shapes/Table.d.ts.map +1 -1
- package/dist/types/src/shapes/Template.d.ts +4 -55
- package/dist/types/src/shapes/Template.d.ts.map +1 -1
- package/dist/types/src/shapes/Text.d.ts +2 -51
- package/dist/types/src/shapes/Text.d.ts.map +1 -1
- package/dist/types/src/shapes/TextToImage.d.ts +2 -51
- package/dist/types/src/shapes/TextToImage.d.ts.map +1 -1
- package/dist/types/src/shapes/Thread.d.ts +2 -51
- package/dist/types/src/shapes/Thread.d.ts.map +1 -1
- package/dist/types/src/shapes/Trigger.d.ts +2 -17
- package/dist/types/src/shapes/Trigger.d.ts.map +1 -1
- package/dist/types/src/shapes/append-def.d.ts +52 -0
- package/dist/types/src/shapes/append-def.d.ts.map +1 -0
- package/dist/types/src/shapes/array-def.d.ts +35 -0
- package/dist/types/src/shapes/array-def.d.ts.map +1 -0
- package/dist/types/src/shapes/audio-def.d.ts +52 -0
- package/dist/types/src/shapes/audio-def.d.ts.map +1 -0
- package/dist/types/src/shapes/beacon-def.d.ts +52 -0
- package/dist/types/src/shapes/beacon-def.d.ts.map +1 -0
- package/dist/types/src/shapes/chat-def.d.ts +52 -0
- package/dist/types/src/shapes/chat-def.d.ts.map +1 -0
- package/dist/types/src/shapes/common/Box.d.ts +0 -2
- package/dist/types/src/shapes/common/Box.d.ts.map +1 -1
- package/dist/types/src/shapes/common/FunctionBody.d.ts +1 -3
- package/dist/types/src/shapes/common/FunctionBody.d.ts.map +1 -1
- package/dist/types/src/shapes/common/box-defs.d.ts +3 -0
- package/dist/types/src/shapes/common/box-defs.d.ts.map +1 -0
- package/dist/types/src/shapes/common/function-anchors.d.ts +7 -0
- package/dist/types/src/shapes/common/function-anchors.d.ts.map +1 -0
- package/dist/types/src/shapes/common/index.d.ts +2 -0
- package/dist/types/src/shapes/common/index.d.ts.map +1 -1
- package/dist/types/src/shapes/constant-def.d.ts +54 -0
- package/dist/types/src/shapes/constant-def.d.ts.map +1 -0
- package/dist/types/src/shapes/database-def.d.ts +52 -0
- package/dist/types/src/shapes/database-def.d.ts.map +1 -0
- package/dist/types/src/shapes/feed-def.d.ts +52 -0
- package/dist/types/src/shapes/feed-def.d.ts.map +1 -0
- package/dist/types/src/shapes/function-def.d.ts +52 -0
- package/dist/types/src/shapes/function-def.d.ts.map +1 -0
- package/dist/types/src/shapes/gpt-def.d.ts +52 -0
- package/dist/types/src/shapes/gpt-def.d.ts.map +1 -0
- package/dist/types/src/shapes/gpt-realtime-def.d.ts +52 -0
- package/dist/types/src/shapes/gpt-realtime-def.d.ts.map +1 -0
- package/dist/types/src/shapes/index.d.ts +23 -0
- package/dist/types/src/shapes/index.d.ts.map +1 -1
- package/dist/types/src/shapes/json-def.d.ts +102 -0
- package/dist/types/src/shapes/json-def.d.ts.map +1 -0
- package/dist/types/src/shapes/logic-def.d.ts +104 -0
- package/dist/types/src/shapes/logic-def.d.ts.map +1 -0
- package/dist/types/src/shapes/rng-def.d.ts +56 -0
- package/dist/types/src/shapes/rng-def.d.ts.map +1 -0
- package/dist/types/src/shapes/scope-def.d.ts +52 -0
- package/dist/types/src/shapes/scope-def.d.ts.map +1 -0
- package/dist/types/src/shapes/surface-def.d.ts +52 -0
- package/dist/types/src/shapes/surface-def.d.ts.map +1 -0
- package/dist/types/src/shapes/switch-def.d.ts +52 -0
- package/dist/types/src/shapes/switch-def.d.ts.map +1 -0
- package/dist/types/src/shapes/table-def.d.ts +52 -0
- package/dist/types/src/shapes/table-def.d.ts.map +1 -0
- package/dist/types/src/shapes/template-def.d.ts +56 -0
- package/dist/types/src/shapes/template-def.d.ts.map +1 -0
- package/dist/types/src/shapes/text-def.d.ts +52 -0
- package/dist/types/src/shapes/text-def.d.ts.map +1 -0
- package/dist/types/src/shapes/text-to-image-def.d.ts +52 -0
- package/dist/types/src/shapes/text-to-image-def.d.ts.map +1 -0
- package/dist/types/src/shapes/thread-def.d.ts +52 -0
- package/dist/types/src/shapes/thread-def.d.ts.map +1 -0
- package/dist/types/src/shapes/trigger-def.d.ts +18 -0
- package/dist/types/src/shapes/trigger-def.d.ts.map +1 -0
- package/dist/types/src/shapes/trigger-spec.d.ts +9 -0
- package/dist/types/src/shapes/trigger-spec.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +43 -46
- package/src/compute.stories.tsx +1 -1
- package/src/shapes/Append.tsx +3 -31
- package/src/shapes/Array.tsx +3 -43
- package/src/shapes/Audio.tsx +2 -26
- package/src/shapes/Beacon.tsx +2 -29
- package/src/shapes/Chat.tsx +1 -36
- package/src/shapes/Constant.tsx +1 -37
- package/src/shapes/Database.tsx +2 -27
- package/src/shapes/Feed.tsx +4 -35
- package/src/shapes/Function.tsx +4 -38
- package/src/shapes/Gpt.tsx +3 -33
- package/src/shapes/GptRealtime.tsx +2 -36
- package/src/shapes/Json.tsx +4 -70
- package/src/shapes/Logic.tsx +3 -58
- package/src/shapes/RNG.tsx +2 -32
- package/src/shapes/Scope.tsx +2 -31
- package/src/shapes/Surface.tsx +2 -32
- package/src/shapes/Switch.tsx +2 -26
- package/src/shapes/Table.tsx +3 -34
- package/src/shapes/Template.tsx +6 -36
- package/src/shapes/Text.tsx +2 -28
- package/src/shapes/TextToImage.tsx +2 -27
- package/src/shapes/Thread.tsx +3 -34
- package/src/shapes/Trigger.tsx +6 -79
- package/src/shapes/append-def.ts +42 -0
- package/src/shapes/array-def.ts +54 -0
- package/src/shapes/audio-def.ts +36 -0
- package/src/shapes/beacon-def.ts +39 -0
- package/src/shapes/chat-def.tsx +47 -0
- package/src/shapes/common/Box.tsx +2 -5
- package/src/shapes/common/FunctionBody.tsx +6 -25
- package/src/shapes/common/box-defs.ts +10 -0
- package/src/shapes/common/function-anchors.ts +37 -0
- package/src/shapes/common/index.ts +3 -0
- package/src/shapes/constant-def.tsx +48 -0
- package/src/shapes/database-def.ts +37 -0
- package/src/shapes/feed-def.ts +44 -0
- package/src/shapes/function-def.ts +46 -0
- package/src/shapes/gpt-def.ts +43 -0
- package/src/shapes/gpt-realtime-def.ts +46 -0
- package/src/shapes/index.ts +25 -0
- package/src/shapes/json-def.ts +80 -0
- package/src/shapes/logic-def.ts +69 -0
- package/src/shapes/rng-def.ts +42 -0
- package/src/shapes/scope-def.ts +41 -0
- package/src/shapes/surface-def.ts +42 -0
- package/src/shapes/switch-def.ts +36 -0
- package/src/shapes/table-def.ts +45 -0
- package/src/shapes/template-def.ts +48 -0
- package/src/shapes/text-def.ts +38 -0
- package/src/shapes/text-to-image-def.ts +37 -0
- package/src/shapes/thread-def.ts +45 -0
- package/src/shapes/trigger-def.ts +63 -0
- package/src/shapes/trigger-spec.ts +44 -0
- package/dist/lib/browser/index.mjs +0 -2596
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/node-esm/index.mjs +0 -2596
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
|
@@ -1,2596 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
-
|
|
3
|
-
// src/graph/controller.ts
|
|
4
|
-
import * as Effect from "effect/Effect";
|
|
5
|
-
import * as Either from "effect/Either";
|
|
6
|
-
import * as Exit from "effect/Exit";
|
|
7
|
-
import * as Layer from "effect/Layer";
|
|
8
|
-
import * as Scope from "effect/Scope";
|
|
9
|
-
import { Event, synchronized } from "@dxos/async";
|
|
10
|
-
import { Trace } from "@dxos/compute";
|
|
11
|
-
import { ComputeBeginEvent, ComputeCustomEvent, ComputeEndEvent, ComputeInputEvent, ComputeNodeContext, ComputeOutputEvent, GraphExecutor, ValueBag, isNotExecuted } from "@dxos/conductor";
|
|
12
|
-
import { Resource } from "@dxos/context";
|
|
13
|
-
import { EffectEx } from "@dxos/effect";
|
|
14
|
-
import { log } from "@dxos/log";
|
|
15
|
-
|
|
16
|
-
// src/hooks/compute-context.ts
|
|
17
|
-
import { createContext, useContext } from "react";
|
|
18
|
-
import { raise } from "@dxos/debug";
|
|
19
|
-
var ComputeContext = createContext(null);
|
|
20
|
-
var useComputeContext = () => {
|
|
21
|
-
return useContext(ComputeContext) ?? raise(new Error("Missing ComputeContext"));
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
// src/hooks/useComputeGraphController.ts
|
|
25
|
-
import { useEffect, useState } from "react";
|
|
26
|
-
var combine = (...cbs) => {
|
|
27
|
-
return () => {
|
|
28
|
-
for (const cb of cbs) {
|
|
29
|
-
cb();
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
var useComputeGraphController = ({ controller, graph, editorRef }) => {
|
|
34
|
-
const [, forceUpdate] = useState({});
|
|
35
|
-
useEffect(() => {
|
|
36
|
-
if (!controller || !graph) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
void controller.open();
|
|
40
|
-
const off = combine(
|
|
41
|
-
controller.update.on(() => {
|
|
42
|
-
void editorRef.current?.update();
|
|
43
|
-
forceUpdate({});
|
|
44
|
-
}),
|
|
45
|
-
// TODO(burdon): Every node is called on every update.
|
|
46
|
-
controller.output.on(({ nodeId, property, value }) => {
|
|
47
|
-
if (value.type === "not-executed") {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const edge = graph.edges.find((edge2) => {
|
|
51
|
-
const source = graph.getNode(edge2.source);
|
|
52
|
-
return source.node === nodeId && edge2.output === property;
|
|
53
|
-
});
|
|
54
|
-
if (edge) {
|
|
55
|
-
void editorRef.current?.action?.({
|
|
56
|
-
type: "trigger",
|
|
57
|
-
edges: [
|
|
58
|
-
edge
|
|
59
|
-
]
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
})
|
|
63
|
-
);
|
|
64
|
-
return () => {
|
|
65
|
-
void controller.close();
|
|
66
|
-
off();
|
|
67
|
-
};
|
|
68
|
-
}, [
|
|
69
|
-
graph,
|
|
70
|
-
controller
|
|
71
|
-
]);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
// src/hooks/useComputeNodeState.ts
|
|
75
|
-
import * as Schema from "effect/Schema";
|
|
76
|
-
import { useCallback, useEffect as useEffect2, useState as useState2 } from "react";
|
|
77
|
-
import { invariant } from "@dxos/invariant";
|
|
78
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-canvas-compute/src/hooks/useComputeNodeState.ts";
|
|
79
|
-
var useComputeNodeState = (shape) => {
|
|
80
|
-
const { controller } = useComputeContext();
|
|
81
|
-
invariant(controller, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 12, S: void 0, A: ["controller", ""] });
|
|
82
|
-
const [meta, setMeta] = useState2();
|
|
83
|
-
useEffect2(() => {
|
|
84
|
-
let disposed = false;
|
|
85
|
-
queueMicrotask(async () => {
|
|
86
|
-
invariant(shape.node, "Node not specified", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 17, S: void 0, A: ["shape.node", "'Node not specified'"] });
|
|
87
|
-
const node = controller.getComputeNode(shape.node);
|
|
88
|
-
const meta2 = await controller.getMeta(node);
|
|
89
|
-
if (disposed) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
setMeta(meta2);
|
|
93
|
-
});
|
|
94
|
-
return () => {
|
|
95
|
-
disposed = true;
|
|
96
|
-
};
|
|
97
|
-
}, [
|
|
98
|
-
shape.node
|
|
99
|
-
]);
|
|
100
|
-
const evalNode = useCallback(() => {
|
|
101
|
-
return controller.evalNode(shape.node);
|
|
102
|
-
}, [
|
|
103
|
-
shape.node
|
|
104
|
-
]);
|
|
105
|
-
const subscribeToEventLog = useCallback((cb) => {
|
|
106
|
-
return controller.events.on((ev) => {
|
|
107
|
-
if (ev.nodeId === shape.node) {
|
|
108
|
-
cb(ev);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}, [
|
|
112
|
-
shape.node
|
|
113
|
-
]);
|
|
114
|
-
return {
|
|
115
|
-
node: controller.getComputeNode(shape.node),
|
|
116
|
-
meta: meta ?? {
|
|
117
|
-
input: Schema.Struct({}),
|
|
118
|
-
output: Schema.Struct({})
|
|
119
|
-
},
|
|
120
|
-
runtime: {
|
|
121
|
-
inputs: controller.getInputs(shape.node),
|
|
122
|
-
outputs: controller.getOutputs(shape.node),
|
|
123
|
-
setOutput: (property, value) => {
|
|
124
|
-
controller.setOutput(shape.node, property, value);
|
|
125
|
-
},
|
|
126
|
-
evalNode,
|
|
127
|
-
subscribeToEventLog
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
// src/hooks/useGraphMonitor.ts
|
|
133
|
-
import { useMemo } from "react";
|
|
134
|
-
import { ComputeGraphModel, DEFAULT_INPUT, DEFAULT_OUTPUT } from "@dxos/conductor";
|
|
135
|
-
import { Obj, Ref } from "@dxos/echo";
|
|
136
|
-
import { invariant as invariant2 } from "@dxos/invariant";
|
|
137
|
-
import { isNonNullable } from "@dxos/util";
|
|
138
|
-
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-canvas-compute/src/hooks/useGraphMonitor.ts";
|
|
139
|
-
var mapEdge = (graph, { source, target, output = DEFAULT_OUTPUT, input = DEFAULT_INPUT }) => {
|
|
140
|
-
const sourceNode = graph.findNode(source);
|
|
141
|
-
const targetNode = graph.findNode(target);
|
|
142
|
-
invariant2(sourceNode?.node, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 15, S: void 0, A: ["sourceNode?.node", ""] });
|
|
143
|
-
invariant2(targetNode?.node, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 16, S: void 0, A: ["targetNode?.node", ""] });
|
|
144
|
-
return {
|
|
145
|
-
id: Obj.ID.random(),
|
|
146
|
-
source: sourceNode.node,
|
|
147
|
-
target: targetNode.node,
|
|
148
|
-
output,
|
|
149
|
-
input
|
|
150
|
-
};
|
|
151
|
-
};
|
|
152
|
-
var useGraphMonitor = (model) => {
|
|
153
|
-
return useMemo(() => {
|
|
154
|
-
return {
|
|
155
|
-
onCreate: ({ node }) => {
|
|
156
|
-
if (!model) {
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
invariant2(node.type, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 37, S: void 0, A: ["node.type", ""] });
|
|
160
|
-
if (!isValidComputeNode(node.type)) {
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
const computeNode = createComputeNode(node);
|
|
164
|
-
if (node.type === "trigger") {
|
|
165
|
-
linkTriggerToCompute(model, computeNode, node);
|
|
166
|
-
}
|
|
167
|
-
model.addNode(computeNode);
|
|
168
|
-
node.node = computeNode.id;
|
|
169
|
-
},
|
|
170
|
-
onLink: ({ graph, edge }) => {
|
|
171
|
-
if (model) {
|
|
172
|
-
model.addEdge(mapEdge(graph, edge));
|
|
173
|
-
}
|
|
174
|
-
},
|
|
175
|
-
onDelete: ({ subgraph }) => {
|
|
176
|
-
if (model) {
|
|
177
|
-
const nodeIds = subgraph.nodes.map((shape) => shape.node);
|
|
178
|
-
const edgeIds = subgraph.edges.map(({ source, target, output = DEFAULT_OUTPUT, input = DEFAULT_INPUT }) => {
|
|
179
|
-
return model.edges.find((computeEdge) => computeEdge.input === input && computeEdge.output === output)?.id;
|
|
180
|
-
}).filter(isNonNullable);
|
|
181
|
-
model.removeNodes(nodeIds);
|
|
182
|
-
model.removeEdges(edgeIds);
|
|
183
|
-
deleteTriggerObjects(model, subgraph);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
}, [
|
|
188
|
-
model
|
|
189
|
-
]);
|
|
190
|
-
};
|
|
191
|
-
var createComputeGraph = (graph) => {
|
|
192
|
-
const computeGraph = ComputeGraphModel.create();
|
|
193
|
-
if (graph) {
|
|
194
|
-
for (const shape of graph.nodes) {
|
|
195
|
-
if (isValidComputeNode(shape.type)) {
|
|
196
|
-
const node = createComputeNode(shape);
|
|
197
|
-
computeGraph.addNode(node);
|
|
198
|
-
shape.node = node.id;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
for (const edge of graph.edges) {
|
|
202
|
-
computeGraph.addEdge(mapEdge(graph, edge));
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
return computeGraph;
|
|
206
|
-
};
|
|
207
|
-
var linkTriggerToCompute = (graph, computeNode, triggerData) => {
|
|
208
|
-
const functionTrigger = triggerData.functionTrigger?.target;
|
|
209
|
-
invariant2(functionTrigger, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 88, S: void 0, A: ["functionTrigger", ""] });
|
|
210
|
-
Obj.update(functionTrigger, (functionTrigger2) => {
|
|
211
|
-
functionTrigger2.runnable = Ref.make(graph.root);
|
|
212
|
-
functionTrigger2.inputNodeId = computeNode.id;
|
|
213
|
-
});
|
|
214
|
-
};
|
|
215
|
-
var deleteTriggerObjects = (computeGraph, deleted) => {
|
|
216
|
-
const db = Obj.getDatabase(computeGraph.root);
|
|
217
|
-
if (!db) {
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
for (const node of deleted.nodes) {
|
|
221
|
-
if (node.type === "trigger") {
|
|
222
|
-
const trigger = node;
|
|
223
|
-
db.remove(trigger.functionTrigger.target);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
// src/graph/node-defs.ts
|
|
229
|
-
import { NODE_INPUT, NODE_OUTPUT, getTemplateInputSchema, registry } from "@dxos/conductor";
|
|
230
|
-
import { raise as raise2 } from "@dxos/debug";
|
|
231
|
-
import { JsonSchema, Obj as Obj2 } from "@dxos/echo";
|
|
232
|
-
import { invariant as invariant3 } from "@dxos/invariant";
|
|
233
|
-
var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-canvas-compute/src/graph/node-defs.ts";
|
|
234
|
-
var resolveComputeNode = async (node) => {
|
|
235
|
-
const impl = registry[node.type];
|
|
236
|
-
invariant3(impl, `Unknown node type: ${node.type}`, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 10, S: void 0, A: ["impl", "`Unknown node type: ${node.type}`"] });
|
|
237
|
-
return impl;
|
|
238
|
-
};
|
|
239
|
-
var isValidComputeNode = (type) => {
|
|
240
|
-
return nodeFactory[type] !== void 0;
|
|
241
|
-
};
|
|
242
|
-
var createComputeNode = (shape) => {
|
|
243
|
-
const type = shape.type ?? raise2(new Error("Type not specified"));
|
|
244
|
-
const factory = nodeFactory[type] ?? raise2(new Error(`Unknown shape type: ${type}`));
|
|
245
|
-
return factory(shape);
|
|
246
|
-
};
|
|
247
|
-
var nodeFactory = {
|
|
248
|
-
// System.
|
|
249
|
-
[NODE_INPUT]: () => createNode(NODE_INPUT),
|
|
250
|
-
[NODE_OUTPUT]: () => createNode(NODE_OUTPUT),
|
|
251
|
-
// Extensions.
|
|
252
|
-
"text-to-image": () => createNode("text-to-image"),
|
|
253
|
-
"and": () => createNode("and"),
|
|
254
|
-
"append": () => createNode("append"),
|
|
255
|
-
"audio": () => createNode("audio"),
|
|
256
|
-
"beacon": () => createNode("beacon"),
|
|
257
|
-
"chat": () => createNode("chat"),
|
|
258
|
-
"constant": (shape) => createNode("constant", {
|
|
259
|
-
value: shape.value
|
|
260
|
-
}),
|
|
261
|
-
"make-queue": () => createNode("make-queue"),
|
|
262
|
-
"database": () => createNode("database"),
|
|
263
|
-
"gpt": () => createNode("gpt"),
|
|
264
|
-
"gpt-realtime": () => createNode("gpt-realtime"),
|
|
265
|
-
"if": () => createNode("if"),
|
|
266
|
-
"if-else": () => createNode("if-else"),
|
|
267
|
-
"function": () => createNode("function"),
|
|
268
|
-
"json": () => createNode("json"),
|
|
269
|
-
"json-transform": () => createNode("json-transform"),
|
|
270
|
-
"not": () => createNode("not"),
|
|
271
|
-
"or": () => createNode("or"),
|
|
272
|
-
"queue": () => createNode("queue"),
|
|
273
|
-
"rng": () => createNode("rng"),
|
|
274
|
-
"reducer": () => createNode("reducer"),
|
|
275
|
-
"scope": () => createNode("scope"),
|
|
276
|
-
"surface": () => createNode("surface"),
|
|
277
|
-
"switch": () => createNode("switch"),
|
|
278
|
-
"template": (shape) => {
|
|
279
|
-
const node = createNode("template", {
|
|
280
|
-
valueType: shape.valueType,
|
|
281
|
-
value: shape.text
|
|
282
|
-
});
|
|
283
|
-
node.inputSchema = structuredClone(JsonSchema.toJsonSchema(getTemplateInputSchema(node)));
|
|
284
|
-
return node;
|
|
285
|
-
},
|
|
286
|
-
"text": () => createNode("text"),
|
|
287
|
-
"thread": () => createNode("thread"),
|
|
288
|
-
"trigger": () => createNode(NODE_INPUT)
|
|
289
|
-
};
|
|
290
|
-
var createNode = (type, props) => ({
|
|
291
|
-
id: Obj2.ID.random(),
|
|
292
|
-
type,
|
|
293
|
-
...props
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
// src/graph/controller.ts
|
|
297
|
-
var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/react-ui-canvas-compute/src/graph/controller.ts";
|
|
298
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
299
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
300
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
301
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
302
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
303
|
-
}
|
|
304
|
-
var InvalidStateError = Error;
|
|
305
|
-
var AUTO_TRIGGER_NODES = [
|
|
306
|
-
"chat",
|
|
307
|
-
"switch",
|
|
308
|
-
"constant"
|
|
309
|
-
];
|
|
310
|
-
var createComputeGraphController = (graph, computeRuntime) => {
|
|
311
|
-
const computeGraph = createComputeGraph(graph);
|
|
312
|
-
const controller = new ComputeGraphController(computeRuntime, computeGraph);
|
|
313
|
-
return {
|
|
314
|
-
controller,
|
|
315
|
-
graph
|
|
316
|
-
};
|
|
317
|
-
};
|
|
318
|
-
var ComputeGraphController = class extends Resource {
|
|
319
|
-
_computeRuntime;
|
|
320
|
-
_graph;
|
|
321
|
-
_executor = new GraphExecutor({
|
|
322
|
-
computeNodeResolver: (node) => resolveComputeNode(node)
|
|
323
|
-
});
|
|
324
|
-
_diagnostics = [];
|
|
325
|
-
/**
|
|
326
|
-
* Canvas force-sets outputs of those nodes.
|
|
327
|
-
*/
|
|
328
|
-
_forcedOutputs = {};
|
|
329
|
-
/**
|
|
330
|
-
* Runtime state of the execution graph.
|
|
331
|
-
*/
|
|
332
|
-
_runtimeStateInputs = {};
|
|
333
|
-
_runtimeStateOutputs = {};
|
|
334
|
-
// TODO(burdon): Remove? Make state reactive?
|
|
335
|
-
update = new Event();
|
|
336
|
-
/** Computed result. */
|
|
337
|
-
output = new Event();
|
|
338
|
-
events = new Event();
|
|
339
|
-
constructor(_computeRuntime, _graph) {
|
|
340
|
-
super(), this._computeRuntime = _computeRuntime, this._graph = _graph;
|
|
341
|
-
}
|
|
342
|
-
toJSON() {
|
|
343
|
-
return {
|
|
344
|
-
graph: this._graph,
|
|
345
|
-
state: {
|
|
346
|
-
inputs: this._runtimeStateInputs,
|
|
347
|
-
outputs: this._runtimeStateOutputs
|
|
348
|
-
},
|
|
349
|
-
forcedOutputs: this._forcedOutputs
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
get graph() {
|
|
353
|
-
return this._graph;
|
|
354
|
-
}
|
|
355
|
-
get diagnostics() {
|
|
356
|
-
return this._diagnostics;
|
|
357
|
-
}
|
|
358
|
-
get userState() {
|
|
359
|
-
return this._forcedOutputs;
|
|
360
|
-
}
|
|
361
|
-
get inputStates() {
|
|
362
|
-
return this._runtimeStateInputs;
|
|
363
|
-
}
|
|
364
|
-
get outputStates() {
|
|
365
|
-
return this._runtimeStateOutputs;
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* Inputs and outputs for all nodes.
|
|
369
|
-
*/
|
|
370
|
-
get state() {
|
|
371
|
-
const ids = [
|
|
372
|
-
.../* @__PURE__ */ new Set([
|
|
373
|
-
...Object.keys(this._runtimeStateInputs),
|
|
374
|
-
...Object.keys(this._runtimeStateOutputs)
|
|
375
|
-
])
|
|
376
|
-
];
|
|
377
|
-
return Object.fromEntries(ids.map((id) => [
|
|
378
|
-
id,
|
|
379
|
-
{
|
|
380
|
-
node: this._graph.getNode(id),
|
|
381
|
-
input: this._runtimeStateInputs[id],
|
|
382
|
-
output: this._runtimeStateOutputs[id]
|
|
383
|
-
}
|
|
384
|
-
]));
|
|
385
|
-
}
|
|
386
|
-
addNode(node) {
|
|
387
|
-
this._graph.addNode(node);
|
|
388
|
-
}
|
|
389
|
-
addEdge(edge) {
|
|
390
|
-
this._graph.addEdge(edge);
|
|
391
|
-
}
|
|
392
|
-
getComputeNode(nodeId) {
|
|
393
|
-
return this._graph.getNode(nodeId);
|
|
394
|
-
}
|
|
395
|
-
getInputs(nodeId) {
|
|
396
|
-
return this._runtimeStateInputs[nodeId] ?? {};
|
|
397
|
-
}
|
|
398
|
-
getOutputs(nodeId) {
|
|
399
|
-
return this._runtimeStateOutputs[nodeId] ?? {};
|
|
400
|
-
}
|
|
401
|
-
setOutput(nodeId, property, value) {
|
|
402
|
-
this._forcedOutputs[nodeId] ??= {};
|
|
403
|
-
this._forcedOutputs[nodeId][property] = value;
|
|
404
|
-
queueMicrotask(async () => {
|
|
405
|
-
try {
|
|
406
|
-
await this.exec(nodeId);
|
|
407
|
-
} catch (err) {
|
|
408
|
-
log.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 128, S: this });
|
|
409
|
-
}
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
async getMeta(node) {
|
|
413
|
-
const { meta } = await resolveComputeNode(node);
|
|
414
|
-
return meta;
|
|
415
|
-
}
|
|
416
|
-
async checkGraph() {
|
|
417
|
-
const executor = this._executor.clone();
|
|
418
|
-
await executor.load(this._graph);
|
|
419
|
-
this._diagnostics = executor.getDiagnostics();
|
|
420
|
-
}
|
|
421
|
-
async evalNode(nodeId) {
|
|
422
|
-
const executor = this._executor.clone();
|
|
423
|
-
await executor.load(this._graph);
|
|
424
|
-
for (const [nodeId2, outputs] of Object.entries(this._forcedOutputs)) {
|
|
425
|
-
executor.setOutputs(nodeId2, Effect.succeed(ValueBag.make(outputs)));
|
|
426
|
-
}
|
|
427
|
-
EffectEx.unwrapExit(await this._computeRuntime.runPromiseExit(Effect.gen(this, function* () {
|
|
428
|
-
const scope = yield* Scope.make();
|
|
429
|
-
const executable = yield* Effect.promise(() => resolveComputeNode(this._graph.getNode(nodeId)));
|
|
430
|
-
const computingOutputs = executable.exec != null;
|
|
431
|
-
const effect = (computingOutputs ? executor.computeOutputs(nodeId) : executor.computeInputs(nodeId)).pipe(Effect.withSpan("runGraph"), Scope.extend(scope), Effect.provide(Layer.mergeAll(Layer.succeed(Trace.TraceService, this._createTraceWriter()), ComputeNodeContext.layerNoop)), Effect.flatMap(computeValueBag), Effect.withSpan("test"), Effect.tap((values) => {
|
|
432
|
-
for (const [key, value] of Object.entries(values)) {
|
|
433
|
-
if (computingOutputs) {
|
|
434
|
-
this._onOutputComputed(nodeId, key, value);
|
|
435
|
-
} else {
|
|
436
|
-
this._onInputComputed(nodeId, key, value);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
}));
|
|
440
|
-
yield* effect;
|
|
441
|
-
yield* Scope.close(scope, Exit.void);
|
|
442
|
-
})));
|
|
443
|
-
this.update.emit();
|
|
444
|
-
}
|
|
445
|
-
/**
|
|
446
|
-
* Executes the graph.
|
|
447
|
-
* @param startFromNode - Node to start from, otherwise all {@link AUTO_TRIGGER_NODES} are executed.
|
|
448
|
-
*/
|
|
449
|
-
async exec(startFromNode) {
|
|
450
|
-
this._runtimeStateInputs = {};
|
|
451
|
-
this._runtimeStateOutputs = {};
|
|
452
|
-
const executor = this._executor.clone();
|
|
453
|
-
await executor.load(this._graph);
|
|
454
|
-
for (const [nodeId, outputs] of Object.entries(this._forcedOutputs)) {
|
|
455
|
-
executor.setOutputs(nodeId, Effect.succeed(ValueBag.make(outputs)));
|
|
456
|
-
}
|
|
457
|
-
const triggerNodes = startFromNode != null ? [
|
|
458
|
-
this._graph.getNode(startFromNode)
|
|
459
|
-
] : this._graph.nodes.filter((node) => node.type != null && AUTO_TRIGGER_NODES.includes(node.type));
|
|
460
|
-
const allAffectedNodes = [
|
|
461
|
-
...new Set(triggerNodes.flatMap((node) => executor.getAllDependantNodes(node.id)))
|
|
462
|
-
];
|
|
463
|
-
EffectEx.unwrapExit(await this._computeRuntime.runPromiseExit(Effect.gen(this, function* () {
|
|
464
|
-
const scope = yield* Scope.make();
|
|
465
|
-
const tasks = [];
|
|
466
|
-
for (const node of allAffectedNodes) {
|
|
467
|
-
const executable = yield* Effect.promise(() => resolveComputeNode(this._graph.getNode(node)));
|
|
468
|
-
const computingOutputs = executable.exec != null;
|
|
469
|
-
const effect = (computingOutputs ? executor.computeOutputs(node) : executor.computeInputs(node)).pipe(Effect.withSpan("runGraph"), Scope.extend(scope), Effect.flatMap(computeValueBag), Effect.provide(Layer.mergeAll(Layer.succeed(Trace.TraceService, this._createTraceWriter()), ComputeNodeContext.layerNoop)), Effect.withSpan("test"), Effect.tap((values) => {
|
|
470
|
-
for (const [key, value] of Object.entries(values)) {
|
|
471
|
-
if (computingOutputs) {
|
|
472
|
-
this._onOutputComputed(node, key, value);
|
|
473
|
-
} else {
|
|
474
|
-
this._onInputComputed(node, key, value);
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
}));
|
|
478
|
-
tasks.push(effect);
|
|
479
|
-
}
|
|
480
|
-
yield* Effect.all(tasks);
|
|
481
|
-
yield* Scope.close(scope, Exit.void);
|
|
482
|
-
})));
|
|
483
|
-
this.update.emit();
|
|
484
|
-
}
|
|
485
|
-
_createTraceWriter() {
|
|
486
|
-
return {
|
|
487
|
-
write: (eventType, payload) => {
|
|
488
|
-
const event = traceEventToComputeEvent(eventType.key, payload);
|
|
489
|
-
if (event) {
|
|
490
|
-
this._handleEvent(event);
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
_handleEvent(event) {
|
|
496
|
-
log("handleEvent", {
|
|
497
|
-
event
|
|
498
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 223, S: this });
|
|
499
|
-
switch (event.type) {
|
|
500
|
-
case "compute-input": {
|
|
501
|
-
this._onInputComputed(event.nodeId, event.property, {
|
|
502
|
-
type: "executed",
|
|
503
|
-
value: event.value
|
|
504
|
-
});
|
|
505
|
-
break;
|
|
506
|
-
}
|
|
507
|
-
case "compute-output": {
|
|
508
|
-
this._onOutputComputed(event.nodeId, event.property, {
|
|
509
|
-
type: "executed",
|
|
510
|
-
value: event.value
|
|
511
|
-
});
|
|
512
|
-
break;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
this.events.emit(event);
|
|
516
|
-
}
|
|
517
|
-
_onInputComputed(nodeId, property, value) {
|
|
518
|
-
this._runtimeStateInputs[nodeId] ??= {};
|
|
519
|
-
this._runtimeStateInputs[nodeId][property] = value;
|
|
520
|
-
}
|
|
521
|
-
_onOutputComputed(nodeId, property, value) {
|
|
522
|
-
this._runtimeStateOutputs[nodeId] ??= {};
|
|
523
|
-
this._runtimeStateOutputs[nodeId][property] = value;
|
|
524
|
-
this.output.emit({
|
|
525
|
-
nodeId,
|
|
526
|
-
property,
|
|
527
|
-
value
|
|
528
|
-
});
|
|
529
|
-
}
|
|
530
|
-
};
|
|
531
|
-
_ts_decorate([
|
|
532
|
-
synchronized
|
|
533
|
-
], ComputeGraphController.prototype, "checkGraph", null);
|
|
534
|
-
_ts_decorate([
|
|
535
|
-
synchronized
|
|
536
|
-
], ComputeGraphController.prototype, "exec", null);
|
|
537
|
-
var traceEventToComputeEvent = (key, payload) => {
|
|
538
|
-
switch (key) {
|
|
539
|
-
case ComputeBeginEvent.key:
|
|
540
|
-
return {
|
|
541
|
-
type: "begin-compute",
|
|
542
|
-
...payload
|
|
543
|
-
};
|
|
544
|
-
case ComputeEndEvent.key:
|
|
545
|
-
return {
|
|
546
|
-
type: "end-compute",
|
|
547
|
-
...payload
|
|
548
|
-
};
|
|
549
|
-
case ComputeInputEvent.key:
|
|
550
|
-
return {
|
|
551
|
-
type: "compute-input",
|
|
552
|
-
...payload
|
|
553
|
-
};
|
|
554
|
-
case ComputeOutputEvent.key:
|
|
555
|
-
return {
|
|
556
|
-
type: "compute-output",
|
|
557
|
-
...payload
|
|
558
|
-
};
|
|
559
|
-
case ComputeCustomEvent.key:
|
|
560
|
-
return {
|
|
561
|
-
type: "custom",
|
|
562
|
-
...payload
|
|
563
|
-
};
|
|
564
|
-
default:
|
|
565
|
-
return void 0;
|
|
566
|
-
}
|
|
567
|
-
};
|
|
568
|
-
var computeValueBag = (bag) => {
|
|
569
|
-
return Effect.all(Object.entries(bag.values).map(([key, eff]) => Effect.either(eff).pipe(Effect.map((value) => {
|
|
570
|
-
if (Either.isLeft(value)) {
|
|
571
|
-
if (isNotExecuted(value.left)) {
|
|
572
|
-
return [
|
|
573
|
-
key,
|
|
574
|
-
{
|
|
575
|
-
type: "not-executed"
|
|
576
|
-
}
|
|
577
|
-
];
|
|
578
|
-
} else {
|
|
579
|
-
return [
|
|
580
|
-
key,
|
|
581
|
-
{
|
|
582
|
-
type: "error",
|
|
583
|
-
error: value.left
|
|
584
|
-
}
|
|
585
|
-
];
|
|
586
|
-
}
|
|
587
|
-
} else {
|
|
588
|
-
return [
|
|
589
|
-
key,
|
|
590
|
-
{
|
|
591
|
-
type: "executed",
|
|
592
|
-
value: value.right
|
|
593
|
-
}
|
|
594
|
-
];
|
|
595
|
-
}
|
|
596
|
-
})))).pipe(Effect.map((entries) => Object.fromEntries(entries)));
|
|
597
|
-
};
|
|
598
|
-
|
|
599
|
-
// src/registry.ts
|
|
600
|
-
import { noteShape } from "@dxos/react-ui-canvas-editor";
|
|
601
|
-
|
|
602
|
-
// src/shapes/common/Box.tsx
|
|
603
|
-
import React, { forwardRef } from "react";
|
|
604
|
-
import { invariant as invariant4 } from "@dxos/invariant";
|
|
605
|
-
import { Icon, IconButton } from "@dxos/react-ui";
|
|
606
|
-
import { useEditorContext, useShapeDef } from "@dxos/react-ui-canvas-editor";
|
|
607
|
-
import { mx } from "@dxos/ui-theme";
|
|
608
|
-
var __dxlog_file5 = "/__w/dxos/dxos/packages/ui/react-ui-canvas-compute/src/shapes/common/Box.tsx";
|
|
609
|
-
var headerHeight = 32;
|
|
610
|
-
var footerHeight = 32;
|
|
611
|
-
var Box = /* @__PURE__ */ forwardRef(({ children, classNames, shape, title, status, open, onAction }, forwardedRef) => {
|
|
612
|
-
invariant4(shape.type, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 12, S: void 0, A: ["shape.type", ""] });
|
|
613
|
-
const { icon, name, openable } = useShapeDef(shape.type) ?? {
|
|
614
|
-
icon: "ph--circle-dashed--regular"
|
|
615
|
-
};
|
|
616
|
-
const { debug } = useEditorContext();
|
|
617
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
618
|
-
ref: forwardedRef,
|
|
619
|
-
className: "flex flex-col h-full w-full justify-between"
|
|
620
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
621
|
-
className: "flex shrink-0 w-full justify-between items-center h-[32px] bg-input-surface"
|
|
622
|
-
}, /* @__PURE__ */ React.createElement(Icon, {
|
|
623
|
-
icon,
|
|
624
|
-
classNames: "mx-2"
|
|
625
|
-
}), /* @__PURE__ */ React.createElement("div", {
|
|
626
|
-
className: "grow text-sm truncate"
|
|
627
|
-
}, debug ? shape.type : name ?? shape.text ?? title), /* @__PURE__ */ React.createElement(IconButton, {
|
|
628
|
-
classNames: "p-1 text-green-500",
|
|
629
|
-
variant: "ghost",
|
|
630
|
-
icon: "ph--play--regular",
|
|
631
|
-
label: "run",
|
|
632
|
-
iconOnly: true,
|
|
633
|
-
onDoubleClick: (ev) => ev.stopPropagation(),
|
|
634
|
-
onClick: (ev) => {
|
|
635
|
-
ev.stopPropagation();
|
|
636
|
-
onAction?.("run");
|
|
637
|
-
}
|
|
638
|
-
})), /* @__PURE__ */ React.createElement("div", {
|
|
639
|
-
className: mx("flex flex-col h-full grow overflow-hidden", classNames)
|
|
640
|
-
}, children), /* @__PURE__ */ React.createElement("div", {
|
|
641
|
-
className: "flex shrink-0 w-full justify-between items-center h-[32px] bg-input-surface"
|
|
642
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
643
|
-
className: "grow px-2 text-sm truncate"
|
|
644
|
-
}, debug ? shape.id : status), openable && /* @__PURE__ */ React.createElement(IconButton, {
|
|
645
|
-
classNames: "p-1",
|
|
646
|
-
variant: "ghost",
|
|
647
|
-
icon: open ? "ph--caret-up--regular" : "ph--caret-down--regular",
|
|
648
|
-
label: open ? "close" : "open",
|
|
649
|
-
iconOnly: true,
|
|
650
|
-
onClick: (ev) => {
|
|
651
|
-
ev.stopPropagation();
|
|
652
|
-
onAction?.(open ? "close" : "open");
|
|
653
|
-
}
|
|
654
|
-
})));
|
|
655
|
-
});
|
|
656
|
-
|
|
657
|
-
// src/shapes/common/FunctionBody.tsx
|
|
658
|
-
import * as SchemaAST2 from "effect/SchemaAST";
|
|
659
|
-
import React2, { useRef, useState as useState3 } from "react";
|
|
660
|
-
import { VoidInput, VoidOutput } from "@dxos/conductor";
|
|
661
|
-
import { useCanvasContext } from "@dxos/react-ui-canvas";
|
|
662
|
-
import { createAnchors, getParentShapeElement, rowHeight } from "@dxos/react-ui-canvas-editor";
|
|
663
|
-
|
|
664
|
-
// src/shapes/defs.ts
|
|
665
|
-
import * as Schema2 from "effect/Schema";
|
|
666
|
-
import * as SchemaAST from "effect/SchemaAST";
|
|
667
|
-
import { DEFAULT_INPUT as DEFAULT_INPUT2, DEFAULT_OUTPUT as DEFAULT_OUTPUT2 } from "@dxos/conductor";
|
|
668
|
-
import { Obj as Obj3 } from "@dxos/echo";
|
|
669
|
-
import { Polygon } from "@dxos/react-ui-canvas-editor";
|
|
670
|
-
var getProperties = (ast) => SchemaAST.getPropertySignatures(ast).map(({ name }) => ({
|
|
671
|
-
name: name.toString()
|
|
672
|
-
}));
|
|
673
|
-
var createAnchorId = (kind, property = kind === "input" ? DEFAULT_INPUT2 : DEFAULT_OUTPUT2) => [
|
|
674
|
-
kind,
|
|
675
|
-
property
|
|
676
|
-
].join(".");
|
|
677
|
-
var parseAnchorId = (id) => {
|
|
678
|
-
const parts = id.match(/(input|output)\.(.+)/);
|
|
679
|
-
return parts ? parts.slice(1) : [
|
|
680
|
-
void 0,
|
|
681
|
-
id
|
|
682
|
-
];
|
|
683
|
-
};
|
|
684
|
-
var ComputeShape = Schema2.extend(Polygon, Schema2.Struct({
|
|
685
|
-
// TODO(burdon): Rename computeNode?
|
|
686
|
-
node: Schema2.optional(Obj3.ID.annotations({
|
|
687
|
-
description: "Compute node id"
|
|
688
|
-
}))
|
|
689
|
-
}).pipe(Schema2.mutable));
|
|
690
|
-
var createShape = ({ id, ...rest }) => {
|
|
691
|
-
return {
|
|
692
|
-
id: id ?? Obj3.ID.random(),
|
|
693
|
-
...rest
|
|
694
|
-
};
|
|
695
|
-
};
|
|
696
|
-
|
|
697
|
-
// src/shapes/common/FunctionBody.tsx
|
|
698
|
-
var bodyPadding = 8;
|
|
699
|
-
var expandedHeight = 200;
|
|
700
|
-
var FunctionBody = ({ shape, name, content, inputSchema = VoidInput, outputSchema = VoidOutput, ...props }) => {
|
|
701
|
-
const { scale } = useCanvasContext();
|
|
702
|
-
const rootRef = useRef(null);
|
|
703
|
-
const [open, setOpen] = useState3(false);
|
|
704
|
-
const handleAction = (action) => {
|
|
705
|
-
if (!rootRef.current) {
|
|
706
|
-
return;
|
|
707
|
-
}
|
|
708
|
-
switch (action) {
|
|
709
|
-
case "open": {
|
|
710
|
-
const el = getParentShapeElement(rootRef.current, shape.id);
|
|
711
|
-
const { height } = el.getBoundingClientRect();
|
|
712
|
-
el.style.height = `${height / scale + expandedHeight}px`;
|
|
713
|
-
setOpen(true);
|
|
714
|
-
break;
|
|
715
|
-
}
|
|
716
|
-
case "close": {
|
|
717
|
-
const el = getParentShapeElement(rootRef.current, shape.id);
|
|
718
|
-
el.style.height = "";
|
|
719
|
-
setOpen(false);
|
|
720
|
-
break;
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
};
|
|
724
|
-
const inputs = getProperties(inputSchema.ast);
|
|
725
|
-
const outputs = getProperties(outputSchema.ast);
|
|
726
|
-
const columnCount = inputs.length && outputs.length ? 2 : 1;
|
|
727
|
-
return /* @__PURE__ */ React2.createElement(Box, {
|
|
728
|
-
ref: rootRef,
|
|
729
|
-
shape,
|
|
730
|
-
title: name,
|
|
731
|
-
classNames: "divide-y divide-separator",
|
|
732
|
-
open,
|
|
733
|
-
onAction: handleAction,
|
|
734
|
-
...props
|
|
735
|
-
}, /* @__PURE__ */ React2.createElement("div", {
|
|
736
|
-
className: `grid grid-cols-${columnCount} items-center`,
|
|
737
|
-
style: {
|
|
738
|
-
paddingTop: bodyPadding,
|
|
739
|
-
paddingBottom: bodyPadding
|
|
740
|
-
}
|
|
741
|
-
}, (inputs?.length ?? 0) > 0 && /* @__PURE__ */ React2.createElement("div", {
|
|
742
|
-
className: "flex flex-col"
|
|
743
|
-
}, inputs?.map(({ name: name2 }) => /* @__PURE__ */ React2.createElement("div", {
|
|
744
|
-
key: name2,
|
|
745
|
-
className: "px-2 truncate text-sm font-mono items-center",
|
|
746
|
-
style: {
|
|
747
|
-
height: rowHeight
|
|
748
|
-
}
|
|
749
|
-
}, name2))), (outputs?.length ?? 0) > 0 && /* @__PURE__ */ React2.createElement("div", {
|
|
750
|
-
className: "flex flex-col"
|
|
751
|
-
}, outputs?.map(({ name: name2 }) => /* @__PURE__ */ React2.createElement("div", {
|
|
752
|
-
key: name2,
|
|
753
|
-
className: "px-2 truncate text-sm font-mono items-center text-right",
|
|
754
|
-
style: {
|
|
755
|
-
height: rowHeight
|
|
756
|
-
}
|
|
757
|
-
}, name2)))), open && /* @__PURE__ */ React2.createElement("div", {
|
|
758
|
-
className: "flex flex-col grow overflow-hidden"
|
|
759
|
-
}, content));
|
|
760
|
-
};
|
|
761
|
-
var getHeight = (input) => {
|
|
762
|
-
const properties = SchemaAST2.getPropertySignatures(input.ast);
|
|
763
|
-
return headerHeight + footerHeight + bodyPadding * 2 + properties.length * rowHeight + 2;
|
|
764
|
-
};
|
|
765
|
-
var createFunctionAnchors = (shape, input = VoidInput, output = VoidOutput) => {
|
|
766
|
-
const inputs = SchemaAST2.getPropertySignatures(input.ast).map(({ name }) => createAnchorId("input", name.toString()));
|
|
767
|
-
const outputs = SchemaAST2.getPropertySignatures(output.ast).map(({ name }) => createAnchorId("output", name.toString()));
|
|
768
|
-
return createAnchors({
|
|
769
|
-
shape,
|
|
770
|
-
inputs,
|
|
771
|
-
outputs,
|
|
772
|
-
center: {
|
|
773
|
-
x: 0,
|
|
774
|
-
y: (headerHeight - footerHeight) / 2 + 1
|
|
775
|
-
}
|
|
776
|
-
});
|
|
777
|
-
};
|
|
778
|
-
|
|
779
|
-
// src/shapes/common/TypeSelect.tsx
|
|
780
|
-
import React3 from "react";
|
|
781
|
-
import { ComputeValueType } from "@dxos/conductor";
|
|
782
|
-
import { Select } from "@dxos/react-ui";
|
|
783
|
-
var TypeSelect = ({ value, onValueChange }) => {
|
|
784
|
-
return /* @__PURE__ */ React3.createElement(Select.Root, {
|
|
785
|
-
value,
|
|
786
|
-
onValueChange
|
|
787
|
-
}, /* @__PURE__ */ React3.createElement(Select.TriggerButton, {
|
|
788
|
-
variant: "ghost",
|
|
789
|
-
classNames: "w-full px-0!"
|
|
790
|
-
}), /* @__PURE__ */ React3.createElement(Select.Portal, null, /* @__PURE__ */ React3.createElement(Select.Content, null, /* @__PURE__ */ React3.createElement(Select.ScrollUpButton, null), /* @__PURE__ */ React3.createElement(Select.Viewport, null, ComputeValueType.literals.map((type) => /* @__PURE__ */ React3.createElement(Select.Option, {
|
|
791
|
-
key: type,
|
|
792
|
-
value: type
|
|
793
|
-
}, type))), /* @__PURE__ */ React3.createElement(Select.ScrollDownButton, null), /* @__PURE__ */ React3.createElement(Select.Arrow, null))));
|
|
794
|
-
};
|
|
795
|
-
|
|
796
|
-
// src/shapes/Array.tsx
|
|
797
|
-
import * as Schema3 from "effect/Schema";
|
|
798
|
-
import React4 from "react";
|
|
799
|
-
import { ReducerInput, ReducerOutput } from "@dxos/conductor";
|
|
800
|
-
var ReducerShape = Schema3.extend(ComputeShape, Schema3.Struct({
|
|
801
|
-
type: Schema3.Literal("reducer")
|
|
802
|
-
}));
|
|
803
|
-
var ReducerComponent = ({ shape }) => {
|
|
804
|
-
return /* @__PURE__ */ React4.createElement(FunctionBody, {
|
|
805
|
-
shape,
|
|
806
|
-
inputSchema: ReducerInput,
|
|
807
|
-
outputSchema: ReducerOutput
|
|
808
|
-
});
|
|
809
|
-
};
|
|
810
|
-
var createReducer = ({ id, size = {
|
|
811
|
-
width: 192,
|
|
812
|
-
height: getHeight(ReducerInput)
|
|
813
|
-
}, ...rest }) => createShape({
|
|
814
|
-
type: "reducer",
|
|
815
|
-
size,
|
|
816
|
-
...rest
|
|
817
|
-
});
|
|
818
|
-
var reducerShape = {
|
|
819
|
-
type: "reducer",
|
|
820
|
-
name: "Reducer",
|
|
821
|
-
icon: "ph--repeat--regular",
|
|
822
|
-
component: (props) => /* @__PURE__ */ React4.createElement(ReducerComponent, props),
|
|
823
|
-
createShape: createReducer,
|
|
824
|
-
getAnchors: (shape) => createFunctionAnchors(shape, ReducerInput, ReducerOutput)
|
|
825
|
-
};
|
|
826
|
-
|
|
827
|
-
// src/shapes/Append.tsx
|
|
828
|
-
import * as Schema4 from "effect/Schema";
|
|
829
|
-
import React5 from "react";
|
|
830
|
-
import { AppendInput } from "@dxos/conductor";
|
|
831
|
-
var AppendShape = Schema4.extend(ComputeShape, Schema4.Struct({
|
|
832
|
-
type: Schema4.Literal("append")
|
|
833
|
-
}));
|
|
834
|
-
var createAppend = (props) => createShape({
|
|
835
|
-
type: "append",
|
|
836
|
-
size: {
|
|
837
|
-
width: 128,
|
|
838
|
-
height: getHeight(AppendInput)
|
|
839
|
-
},
|
|
840
|
-
...props
|
|
841
|
-
});
|
|
842
|
-
var AppendComponent = ({ shape }) => {
|
|
843
|
-
return /* @__PURE__ */ React5.createElement(FunctionBody, {
|
|
844
|
-
shape,
|
|
845
|
-
inputSchema: AppendInput
|
|
846
|
-
});
|
|
847
|
-
};
|
|
848
|
-
var appendShape = {
|
|
849
|
-
type: "append",
|
|
850
|
-
name: "Append",
|
|
851
|
-
icon: "ph--list-plus--regular",
|
|
852
|
-
component: AppendComponent,
|
|
853
|
-
createShape: createAppend,
|
|
854
|
-
getAnchors: (shape) => createFunctionAnchors(shape, AppendInput)
|
|
855
|
-
};
|
|
856
|
-
|
|
857
|
-
// src/shapes/Audio.tsx
|
|
858
|
-
import * as Schema5 from "effect/Schema";
|
|
859
|
-
import React6, { useEffect as useEffect3, useState as useState4 } from "react";
|
|
860
|
-
import { DEFAULT_OUTPUT as DEFAULT_OUTPUT3 } from "@dxos/conductor";
|
|
861
|
-
import { Icon as Icon2 } from "@dxos/react-ui";
|
|
862
|
-
import { createAnchorMap } from "@dxos/react-ui-canvas-editor";
|
|
863
|
-
var AudioShape = Schema5.extend(ComputeShape, Schema5.Struct({
|
|
864
|
-
type: Schema5.Literal("audio")
|
|
865
|
-
}));
|
|
866
|
-
var createAudio = (props) => createShape({
|
|
867
|
-
type: "audio",
|
|
868
|
-
size: {
|
|
869
|
-
width: 64,
|
|
870
|
-
height: 64
|
|
871
|
-
},
|
|
872
|
-
...props
|
|
873
|
-
});
|
|
874
|
-
var AudioComponent = ({ shape }) => {
|
|
875
|
-
const { runtime } = useComputeNodeState(shape);
|
|
876
|
-
const [active, setActive] = useState4(false);
|
|
877
|
-
useEffect3(() => {
|
|
878
|
-
runtime.setOutput(DEFAULT_OUTPUT3, active);
|
|
879
|
-
}, [
|
|
880
|
-
active
|
|
881
|
-
]);
|
|
882
|
-
return /* @__PURE__ */ React6.createElement("div", {
|
|
883
|
-
className: "flex w-full justify-center items-center"
|
|
884
|
-
}, /* @__PURE__ */ React6.createElement(Icon2, {
|
|
885
|
-
icon: active ? "ph--microphone--regular" : "ph--microphone-slash--regular",
|
|
886
|
-
classNames: [
|
|
887
|
-
"transition opacity-20 duration-1000",
|
|
888
|
-
active && "opacity-100 text-error-text"
|
|
889
|
-
],
|
|
890
|
-
size: 8,
|
|
891
|
-
onClick: () => setActive(!active)
|
|
892
|
-
}));
|
|
893
|
-
};
|
|
894
|
-
var audioShape = {
|
|
895
|
-
type: "audio",
|
|
896
|
-
name: "Audio",
|
|
897
|
-
icon: "ph--microphone--regular",
|
|
898
|
-
component: AudioComponent,
|
|
899
|
-
createShape: createAudio,
|
|
900
|
-
getAnchors: (shape) => createAnchorMap(shape, {
|
|
901
|
-
[createAnchorId("output")]: {
|
|
902
|
-
x: 1,
|
|
903
|
-
y: 0
|
|
904
|
-
}
|
|
905
|
-
})
|
|
906
|
-
};
|
|
907
|
-
|
|
908
|
-
// src/shapes/Beacon.tsx
|
|
909
|
-
import * as Schema6 from "effect/Schema";
|
|
910
|
-
import React7 from "react";
|
|
911
|
-
import { DEFAULT_INPUT as DEFAULT_INPUT3, isTruthy } from "@dxos/conductor";
|
|
912
|
-
import { Icon as Icon3 } from "@dxos/react-ui";
|
|
913
|
-
import { createAnchorMap as createAnchorMap2 } from "@dxos/react-ui-canvas-editor";
|
|
914
|
-
var BeaconShape = Schema6.extend(ComputeShape, Schema6.Struct({
|
|
915
|
-
type: Schema6.Literal("beacon")
|
|
916
|
-
}));
|
|
917
|
-
var createBeacon = (props) => createShape({
|
|
918
|
-
type: "beacon",
|
|
919
|
-
size: {
|
|
920
|
-
width: 64,
|
|
921
|
-
height: 64
|
|
922
|
-
},
|
|
923
|
-
...props
|
|
924
|
-
});
|
|
925
|
-
var BeaconComponent = ({ shape }) => {
|
|
926
|
-
const { runtime } = useComputeNodeState(shape);
|
|
927
|
-
const input = runtime.inputs[DEFAULT_INPUT3];
|
|
928
|
-
const value = input?.type === "executed" ? input.value : false;
|
|
929
|
-
return /* @__PURE__ */ React7.createElement("div", {
|
|
930
|
-
className: "flex w-full justify-center items-center"
|
|
931
|
-
}, /* @__PURE__ */ React7.createElement(Icon3, {
|
|
932
|
-
icon: "ph--sun--regular",
|
|
933
|
-
classNames: [
|
|
934
|
-
"transition opacity-20 duration-1000",
|
|
935
|
-
isTruthy(value) && "opacity-100 text-yellow-500"
|
|
936
|
-
],
|
|
937
|
-
size: 8
|
|
938
|
-
}));
|
|
939
|
-
};
|
|
940
|
-
var beaconShape = {
|
|
941
|
-
type: "beacon",
|
|
942
|
-
name: "Beacon",
|
|
943
|
-
icon: "ph--sun--regular",
|
|
944
|
-
component: BeaconComponent,
|
|
945
|
-
createShape: createBeacon,
|
|
946
|
-
getAnchors: (shape) => createAnchorMap2(shape, {
|
|
947
|
-
[createAnchorId("input")]: {
|
|
948
|
-
x: -1,
|
|
949
|
-
y: 0
|
|
950
|
-
}
|
|
951
|
-
})
|
|
952
|
-
};
|
|
953
|
-
|
|
954
|
-
// src/shapes/Boolean.tsx
|
|
955
|
-
import * as Schema7 from "effect/Schema";
|
|
956
|
-
import React8 from "react";
|
|
957
|
-
import { getAnchorPoints } from "@dxos/react-ui-canvas-editor";
|
|
958
|
-
import { createAnchors as createAnchors2 } from "@dxos/react-ui-canvas-editor";
|
|
959
|
-
var GateShape = Schema7.extend(ComputeShape, Schema7.Struct({
|
|
960
|
-
type: Schema7.String
|
|
961
|
-
}));
|
|
962
|
-
var createGate = (props) => createShape({
|
|
963
|
-
size: {
|
|
964
|
-
width: 64,
|
|
965
|
-
height: 64
|
|
966
|
-
},
|
|
967
|
-
...props
|
|
968
|
-
});
|
|
969
|
-
var defineShape = ({ type, name, icon, symbol: Symbol, createShape: createShape2, inputs, outputs = [
|
|
970
|
-
createAnchorId("output")
|
|
971
|
-
] }) => ({
|
|
972
|
-
type,
|
|
973
|
-
name,
|
|
974
|
-
icon,
|
|
975
|
-
// NOTE: Preact interprets captitalized properties as React components.
|
|
976
|
-
// Be careful not to name component factories with a capital letter.
|
|
977
|
-
component: () => {
|
|
978
|
-
return /* @__PURE__ */ React8.createElement("div", {
|
|
979
|
-
className: "flex w-full justify-center items-center"
|
|
980
|
-
}, /* @__PURE__ */ React8.createElement(Symbol, null));
|
|
981
|
-
},
|
|
982
|
-
createShape: createShape2,
|
|
983
|
-
getAnchors: (shape) => createAnchors2({
|
|
984
|
-
shape,
|
|
985
|
-
inputs,
|
|
986
|
-
outputs
|
|
987
|
-
})
|
|
988
|
-
});
|
|
989
|
-
var createSymbol = (pathConstructor, inputs) => ({
|
|
990
|
-
width = 64,
|
|
991
|
-
height = 32,
|
|
992
|
-
// TODO(burdon): Same as line color.
|
|
993
|
-
className = "fill-neutral-200 dark:fill-neutral-800 stroke-neutral-500",
|
|
994
|
-
strokeWidth = 1
|
|
995
|
-
}) => {
|
|
996
|
-
const startX = width * 0.25;
|
|
997
|
-
const endX = width * 0.75;
|
|
998
|
-
const centerY = height / 2;
|
|
999
|
-
const paths = pathConstructor({
|
|
1000
|
-
startX,
|
|
1001
|
-
endX,
|
|
1002
|
-
height
|
|
1003
|
-
});
|
|
1004
|
-
return /* @__PURE__ */ React8.createElement("svg", {
|
|
1005
|
-
viewBox: `0 0 ${width} ${height}`,
|
|
1006
|
-
className: "h-full w-full"
|
|
1007
|
-
}, getAnchorPoints({
|
|
1008
|
-
x: 0,
|
|
1009
|
-
y: centerY
|
|
1010
|
-
}, inputs).map(({ x, y }, i) => /* @__PURE__ */ React8.createElement("line", {
|
|
1011
|
-
key: i,
|
|
1012
|
-
x1: x,
|
|
1013
|
-
y1: y,
|
|
1014
|
-
x2: startX * 1.3,
|
|
1015
|
-
y2: y,
|
|
1016
|
-
strokeWidth,
|
|
1017
|
-
className
|
|
1018
|
-
})), /* @__PURE__ */ React8.createElement("line", {
|
|
1019
|
-
x1: endX,
|
|
1020
|
-
y1: centerY,
|
|
1021
|
-
x2: width,
|
|
1022
|
-
y2: centerY,
|
|
1023
|
-
strokeWidth,
|
|
1024
|
-
className
|
|
1025
|
-
}), paths.map((path, i) => /* @__PURE__ */ React8.createElement("path", {
|
|
1026
|
-
key: i,
|
|
1027
|
-
d: path,
|
|
1028
|
-
strokeWidth,
|
|
1029
|
-
className
|
|
1030
|
-
})));
|
|
1031
|
-
};
|
|
1032
|
-
var AndSymbol = createSymbol(({ startX, endX, height }) => {
|
|
1033
|
-
const arcRadius = (endX - startX) / 2;
|
|
1034
|
-
return [
|
|
1035
|
-
`
|
|
1036
|
-
M ${startX},${height * 0.1}
|
|
1037
|
-
L ${endX - arcRadius},${height * 0.1}
|
|
1038
|
-
A ${arcRadius},${height * 0.4} 0 0 1 ${endX - arcRadius},${height * 0.9}
|
|
1039
|
-
L ${startX},${height * 0.9}
|
|
1040
|
-
Z
|
|
1041
|
-
`
|
|
1042
|
-
];
|
|
1043
|
-
}, 2);
|
|
1044
|
-
var AndShape = GateShape;
|
|
1045
|
-
var createAnd = (props) => {
|
|
1046
|
-
return createGate({
|
|
1047
|
-
...props,
|
|
1048
|
-
type: "and"
|
|
1049
|
-
});
|
|
1050
|
-
};
|
|
1051
|
-
var andShape = defineShape({
|
|
1052
|
-
type: "and",
|
|
1053
|
-
name: "AND",
|
|
1054
|
-
icon: "ph--intersection--regular",
|
|
1055
|
-
symbol: AndSymbol,
|
|
1056
|
-
createShape: createAnd,
|
|
1057
|
-
inputs: [
|
|
1058
|
-
"input.a",
|
|
1059
|
-
"input.b"
|
|
1060
|
-
]
|
|
1061
|
-
});
|
|
1062
|
-
var OrSymbol = createSymbol(({ startX, endX, height }) => {
|
|
1063
|
-
const arcRadius = (endX - startX) / 2;
|
|
1064
|
-
return [
|
|
1065
|
-
`
|
|
1066
|
-
M ${startX},${height * 0.1}
|
|
1067
|
-
L ${endX - arcRadius},${height * 0.1}
|
|
1068
|
-
A ${arcRadius},${height * 0.4} 0 0 1 ${endX - arcRadius},${height * 0.9}
|
|
1069
|
-
L ${startX},${height * 0.9}
|
|
1070
|
-
C ${startX * 1.4},${height * 0.5} ${startX * 1.4},${height * 0.5} ${startX},${height * 0.1}
|
|
1071
|
-
Z
|
|
1072
|
-
`
|
|
1073
|
-
];
|
|
1074
|
-
}, 2);
|
|
1075
|
-
var OrShape = GateShape;
|
|
1076
|
-
var createOr = (props) => {
|
|
1077
|
-
return createGate({
|
|
1078
|
-
...props,
|
|
1079
|
-
type: "or"
|
|
1080
|
-
});
|
|
1081
|
-
};
|
|
1082
|
-
var orShape = defineShape({
|
|
1083
|
-
type: "or",
|
|
1084
|
-
name: "OR",
|
|
1085
|
-
icon: "ph--union--regular",
|
|
1086
|
-
symbol: OrSymbol,
|
|
1087
|
-
createShape: createOr,
|
|
1088
|
-
inputs: [
|
|
1089
|
-
"input.a",
|
|
1090
|
-
"input.b"
|
|
1091
|
-
]
|
|
1092
|
-
});
|
|
1093
|
-
var NotSymbol = createSymbol(({ startX, endX, height }) => {
|
|
1094
|
-
return [
|
|
1095
|
-
`
|
|
1096
|
-
M ${startX},${height * 0.1}
|
|
1097
|
-
L ${endX * 0.9},${height * 0.5}
|
|
1098
|
-
L ${startX},${height * 0.9}
|
|
1099
|
-
Z
|
|
1100
|
-
`,
|
|
1101
|
-
`
|
|
1102
|
-
M ${endX - height * 0.2},${height * 0.5}
|
|
1103
|
-
A ${height * 0.1} ${height * 0.1} 0 0 1 ${endX},${height * 0.5}
|
|
1104
|
-
A ${height * 0.1} ${height * 0.1} 0 0 1 ${endX - height * 0.2},${height * 0.5}
|
|
1105
|
-
Z
|
|
1106
|
-
`
|
|
1107
|
-
];
|
|
1108
|
-
}, 1);
|
|
1109
|
-
var NotShape = GateShape;
|
|
1110
|
-
var createNot = (props) => {
|
|
1111
|
-
return createGate({
|
|
1112
|
-
...props,
|
|
1113
|
-
type: "not"
|
|
1114
|
-
});
|
|
1115
|
-
};
|
|
1116
|
-
var notShape = defineShape({
|
|
1117
|
-
type: "not",
|
|
1118
|
-
name: "NOT",
|
|
1119
|
-
icon: "ph--x--regular",
|
|
1120
|
-
symbol: NotSymbol,
|
|
1121
|
-
createShape: createNot,
|
|
1122
|
-
inputs: [
|
|
1123
|
-
createAnchorId("input")
|
|
1124
|
-
]
|
|
1125
|
-
});
|
|
1126
|
-
|
|
1127
|
-
// src/shapes/Chat.tsx
|
|
1128
|
-
import * as Schema8 from "effect/Schema";
|
|
1129
|
-
import React9, { useRef as useRef2 } from "react";
|
|
1130
|
-
import { DEFAULT_OUTPUT as DEFAULT_OUTPUT4 } from "@dxos/conductor";
|
|
1131
|
-
import { TextBox } from "@dxos/react-ui-canvas-editor";
|
|
1132
|
-
import { createAnchorMap as createAnchorMap3 } from "@dxos/react-ui-canvas-editor";
|
|
1133
|
-
var ChatShape = Schema8.extend(ComputeShape, Schema8.Struct({
|
|
1134
|
-
type: Schema8.Literal("chat")
|
|
1135
|
-
}));
|
|
1136
|
-
var TextInputComponent = ({ shape, title, ...props }) => {
|
|
1137
|
-
const { runtime } = useComputeNodeState(shape);
|
|
1138
|
-
const inputRef = useRef2(null);
|
|
1139
|
-
const handleEnter = (text) => {
|
|
1140
|
-
const value = text.trim();
|
|
1141
|
-
if (value.length) {
|
|
1142
|
-
runtime.setOutput(DEFAULT_OUTPUT4, value);
|
|
1143
|
-
inputRef.current?.setText("");
|
|
1144
|
-
}
|
|
1145
|
-
};
|
|
1146
|
-
return /* @__PURE__ */ React9.createElement(Box, {
|
|
1147
|
-
shape,
|
|
1148
|
-
title
|
|
1149
|
-
}, /* @__PURE__ */ React9.createElement(TextBox, {
|
|
1150
|
-
ref: inputRef,
|
|
1151
|
-
onEnter: handleEnter,
|
|
1152
|
-
...props
|
|
1153
|
-
}));
|
|
1154
|
-
};
|
|
1155
|
-
var createChat = (props) => createShape({
|
|
1156
|
-
type: "chat",
|
|
1157
|
-
size: {
|
|
1158
|
-
width: 256,
|
|
1159
|
-
height: 128
|
|
1160
|
-
},
|
|
1161
|
-
...props
|
|
1162
|
-
});
|
|
1163
|
-
var chatShape = {
|
|
1164
|
-
type: "chat",
|
|
1165
|
-
name: "Chat",
|
|
1166
|
-
icon: "ph--textbox--regular",
|
|
1167
|
-
component: (props) => /* @__PURE__ */ React9.createElement(TextInputComponent, {
|
|
1168
|
-
...props,
|
|
1169
|
-
title: "Prompt",
|
|
1170
|
-
placeholder: "Message"
|
|
1171
|
-
}),
|
|
1172
|
-
createShape: createChat,
|
|
1173
|
-
getAnchors: (shape) => createAnchorMap3(shape, {
|
|
1174
|
-
[createAnchorId("output")]: {
|
|
1175
|
-
x: 1,
|
|
1176
|
-
y: 0
|
|
1177
|
-
}
|
|
1178
|
-
}),
|
|
1179
|
-
resizable: true
|
|
1180
|
-
};
|
|
1181
|
-
|
|
1182
|
-
// src/shapes/Constant.tsx
|
|
1183
|
-
import * as Schema9 from "effect/Schema";
|
|
1184
|
-
import React10, { useCallback as useCallback2, useRef as useRef3, useState as useState5 } from "react";
|
|
1185
|
-
import { ComputeValueType as ComputeValueType2 } from "@dxos/conductor";
|
|
1186
|
-
import { Input } from "@dxos/react-ui";
|
|
1187
|
-
import { TextBox as TextBox2 } from "@dxos/react-ui-canvas-editor";
|
|
1188
|
-
import { createAnchorMap as createAnchorMap4 } from "@dxos/react-ui-canvas-editor";
|
|
1189
|
-
import { safeParseJson } from "@dxos/util";
|
|
1190
|
-
var ConstantShape = Schema9.extend(ComputeShape, Schema9.Struct({
|
|
1191
|
-
type: Schema9.Literal("constant"),
|
|
1192
|
-
value: Schema9.optional(Schema9.Any)
|
|
1193
|
-
}));
|
|
1194
|
-
var inferType = (value) => {
|
|
1195
|
-
if (typeof value === "string") {
|
|
1196
|
-
return "string";
|
|
1197
|
-
} else if (typeof value === "number") {
|
|
1198
|
-
return "number";
|
|
1199
|
-
} else if (typeof value === "boolean") {
|
|
1200
|
-
return "boolean";
|
|
1201
|
-
} else if (typeof value === "object") {
|
|
1202
|
-
return "object";
|
|
1203
|
-
}
|
|
1204
|
-
};
|
|
1205
|
-
var ConstantComponent = ({ shape, title, chat, ...props }) => {
|
|
1206
|
-
const { node } = useComputeNodeState(shape);
|
|
1207
|
-
const [type, setType] = useState5(inferType(node.value) ?? ComputeValueType2.literals[0]);
|
|
1208
|
-
const inputRef = useRef3(null);
|
|
1209
|
-
const handleEnter = useCallback2((text) => {
|
|
1210
|
-
const value = text.trim();
|
|
1211
|
-
if (value.length) {
|
|
1212
|
-
if (type === "number") {
|
|
1213
|
-
const floatValue = parseFloat(value);
|
|
1214
|
-
if (!isNaN(floatValue)) {
|
|
1215
|
-
node.value = floatValue;
|
|
1216
|
-
}
|
|
1217
|
-
} else if (type === "object") {
|
|
1218
|
-
node.value = safeParseJson(value, {});
|
|
1219
|
-
} else {
|
|
1220
|
-
node.value = value;
|
|
1221
|
-
}
|
|
1222
|
-
inputRef.current?.focus();
|
|
1223
|
-
}
|
|
1224
|
-
}, [
|
|
1225
|
-
type
|
|
1226
|
-
]);
|
|
1227
|
-
return /* @__PURE__ */ React10.createElement(Box, {
|
|
1228
|
-
shape,
|
|
1229
|
-
title,
|
|
1230
|
-
status: /* @__PURE__ */ React10.createElement(TypeSelect, {
|
|
1231
|
-
value: type,
|
|
1232
|
-
onValueChange: setType
|
|
1233
|
-
})
|
|
1234
|
-
}, (type === "string" || type === "number") && /* @__PURE__ */ React10.createElement(TextBox2, {
|
|
1235
|
-
...props,
|
|
1236
|
-
ref: inputRef,
|
|
1237
|
-
value: node.value,
|
|
1238
|
-
onEnter: handleEnter
|
|
1239
|
-
}), type === "object" && /* @__PURE__ */ React10.createElement(TextBox2, {
|
|
1240
|
-
...props,
|
|
1241
|
-
ref: inputRef,
|
|
1242
|
-
value: JSON.stringify(node.value, null, 2),
|
|
1243
|
-
language: "json"
|
|
1244
|
-
}), type === "boolean" && /* @__PURE__ */ React10.createElement("div", {
|
|
1245
|
-
className: "flex grow justify-center items-center"
|
|
1246
|
-
}, /* @__PURE__ */ React10.createElement(Input.Root, null, /* @__PURE__ */ React10.createElement(Input.Switch, {
|
|
1247
|
-
checked: node.value,
|
|
1248
|
-
onCheckedChange: (value) => {
|
|
1249
|
-
node.value = value;
|
|
1250
|
-
}
|
|
1251
|
-
}))));
|
|
1252
|
-
};
|
|
1253
|
-
var createConstant = (props) => createShape({
|
|
1254
|
-
type: "constant",
|
|
1255
|
-
size: {
|
|
1256
|
-
width: 192,
|
|
1257
|
-
height: 128
|
|
1258
|
-
},
|
|
1259
|
-
...props
|
|
1260
|
-
});
|
|
1261
|
-
var constantShape = {
|
|
1262
|
-
type: "constant",
|
|
1263
|
-
name: "Value",
|
|
1264
|
-
icon: "ph--dots-three-circle--regular",
|
|
1265
|
-
component: (props) => /* @__PURE__ */ React10.createElement(ConstantComponent, {
|
|
1266
|
-
...props,
|
|
1267
|
-
placeholder: "Constant"
|
|
1268
|
-
}),
|
|
1269
|
-
createShape: createConstant,
|
|
1270
|
-
getAnchors: (shape) => createAnchorMap4(shape, {
|
|
1271
|
-
[createAnchorId("output")]: {
|
|
1272
|
-
x: 1,
|
|
1273
|
-
y: 0
|
|
1274
|
-
}
|
|
1275
|
-
}),
|
|
1276
|
-
resizable: true
|
|
1277
|
-
};
|
|
1278
|
-
|
|
1279
|
-
// src/shapes/Database.tsx
|
|
1280
|
-
import * as Schema10 from "effect/Schema";
|
|
1281
|
-
import React11 from "react";
|
|
1282
|
-
import { createAnchorMap as createAnchorMap5 } from "@dxos/react-ui-canvas-editor";
|
|
1283
|
-
var DatabaseShape = Schema10.extend(ComputeShape, Schema10.Struct({
|
|
1284
|
-
type: Schema10.Literal("database")
|
|
1285
|
-
}));
|
|
1286
|
-
var createDatabase = (props) => createShape({
|
|
1287
|
-
type: "database",
|
|
1288
|
-
size: {
|
|
1289
|
-
width: 128,
|
|
1290
|
-
height: 64
|
|
1291
|
-
},
|
|
1292
|
-
...props
|
|
1293
|
-
});
|
|
1294
|
-
var DatabaseComponent = ({ shape }) => {
|
|
1295
|
-
return /* @__PURE__ */ React11.createElement(Box, {
|
|
1296
|
-
shape
|
|
1297
|
-
});
|
|
1298
|
-
};
|
|
1299
|
-
var databaseShape = {
|
|
1300
|
-
type: "database",
|
|
1301
|
-
name: "ECHO",
|
|
1302
|
-
icon: "ph--database--regular",
|
|
1303
|
-
component: DatabaseComponent,
|
|
1304
|
-
createShape: createDatabase,
|
|
1305
|
-
getAnchors: (shape) => createAnchorMap5(shape, {
|
|
1306
|
-
[createAnchorId("output")]: {
|
|
1307
|
-
x: 1,
|
|
1308
|
-
y: 0
|
|
1309
|
-
}
|
|
1310
|
-
})
|
|
1311
|
-
};
|
|
1312
|
-
|
|
1313
|
-
// src/shapes/Feed.tsx
|
|
1314
|
-
import * as Schema11 from "effect/Schema";
|
|
1315
|
-
import React12, { Fragment } from "react";
|
|
1316
|
-
import { DEFAULT_OUTPUT as DEFAULT_OUTPUT5, QueueInput, QueueOutput } from "@dxos/conductor";
|
|
1317
|
-
import { ScrollArea } from "@dxos/react-ui";
|
|
1318
|
-
import { mx as mx2 } from "@dxos/ui-theme";
|
|
1319
|
-
var FeedShape = Schema11.extend(ComputeShape, Schema11.Struct({
|
|
1320
|
-
type: Schema11.Literal("queue")
|
|
1321
|
-
}));
|
|
1322
|
-
var createFeed = (props) => createShape({
|
|
1323
|
-
type: "queue",
|
|
1324
|
-
size: {
|
|
1325
|
-
width: 256,
|
|
1326
|
-
height: 512
|
|
1327
|
-
},
|
|
1328
|
-
...props
|
|
1329
|
-
});
|
|
1330
|
-
var FeedComponent = ({ shape }) => {
|
|
1331
|
-
const { runtime } = useComputeNodeState(shape);
|
|
1332
|
-
const items = runtime.outputs[DEFAULT_OUTPUT5]?.type === "executed" ? runtime.outputs[DEFAULT_OUTPUT5].value : [];
|
|
1333
|
-
const handleAction = (action) => {
|
|
1334
|
-
if (action === "run") {
|
|
1335
|
-
runtime.evalNode();
|
|
1336
|
-
}
|
|
1337
|
-
};
|
|
1338
|
-
return /* @__PURE__ */ React12.createElement(Box, {
|
|
1339
|
-
shape,
|
|
1340
|
-
status: `${items.length} items`,
|
|
1341
|
-
onAction: handleAction
|
|
1342
|
-
}, /* @__PURE__ */ React12.createElement(ScrollArea.Root, {
|
|
1343
|
-
orientation: "vertical"
|
|
1344
|
-
}, /* @__PURE__ */ React12.createElement(ScrollArea.Viewport, {
|
|
1345
|
-
classNames: "divide-y divide-separator"
|
|
1346
|
-
}, [
|
|
1347
|
-
...items
|
|
1348
|
-
].map((item, i) => /* @__PURE__ */ React12.createElement(FeedItem, {
|
|
1349
|
-
key: i,
|
|
1350
|
-
classNames: "p-1 px-2",
|
|
1351
|
-
item
|
|
1352
|
-
})))));
|
|
1353
|
-
};
|
|
1354
|
-
var FeedItem = ({ classNames, item }) => {
|
|
1355
|
-
if (typeof item !== "object") {
|
|
1356
|
-
return /* @__PURE__ */ React12.createElement("div", {
|
|
1357
|
-
className: mx2(classNames, "whitespace-pre-wrap")
|
|
1358
|
-
}, item);
|
|
1359
|
-
}
|
|
1360
|
-
return /* @__PURE__ */ React12.createElement("div", {
|
|
1361
|
-
className: mx2("grid grid-cols-[80px_1fr]", classNames)
|
|
1362
|
-
}, Object.entries(item).map(([key, value]) => /* @__PURE__ */ React12.createElement(Fragment, {
|
|
1363
|
-
key
|
|
1364
|
-
}, /* @__PURE__ */ React12.createElement("div", {
|
|
1365
|
-
className: "p-1 text-xs text-subdued"
|
|
1366
|
-
}, key), /* @__PURE__ */ React12.createElement("div", null, typeof value === "string" ? value : JSON.stringify(value)))));
|
|
1367
|
-
};
|
|
1368
|
-
var feedShape = {
|
|
1369
|
-
// Must match the shape's `type` literal ('queue') so the registry resolves it; the registry is keyed by this.
|
|
1370
|
-
type: "queue",
|
|
1371
|
-
name: "Feed",
|
|
1372
|
-
icon: "ph--queue--regular",
|
|
1373
|
-
component: FeedComponent,
|
|
1374
|
-
createShape: createFeed,
|
|
1375
|
-
getAnchors: (shape) => createFunctionAnchors(shape, QueueInput, QueueOutput),
|
|
1376
|
-
resizable: true
|
|
1377
|
-
};
|
|
1378
|
-
|
|
1379
|
-
// src/shapes/Function.tsx
|
|
1380
|
-
import * as Schema12 from "effect/Schema";
|
|
1381
|
-
import React13, { useCallback as useCallback3, useRef as useRef4 } from "react";
|
|
1382
|
-
import { Script } from "@dxos/compute";
|
|
1383
|
-
import { Operation } from "@dxos/compute";
|
|
1384
|
-
import { AnyOutput, FunctionInput } from "@dxos/conductor";
|
|
1385
|
-
import { Filter, Ref as Ref2 } from "@dxos/echo";
|
|
1386
|
-
import { instanceOf as isInstanceOf } from "@dxos/echo/Obj";
|
|
1387
|
-
import { parseId } from "@dxos/keys";
|
|
1388
|
-
import { useClient } from "@dxos/react-client";
|
|
1389
|
-
import { TextBox as TextBox3 } from "@dxos/react-ui-canvas-editor";
|
|
1390
|
-
var FunctionShape = Schema12.extend(ComputeShape, Schema12.Struct({
|
|
1391
|
-
type: Schema12.Literal("function")
|
|
1392
|
-
}));
|
|
1393
|
-
var createFunction = (props) => createShape({
|
|
1394
|
-
type: "function",
|
|
1395
|
-
size: {
|
|
1396
|
-
width: 256,
|
|
1397
|
-
height: 192
|
|
1398
|
-
},
|
|
1399
|
-
...props
|
|
1400
|
-
});
|
|
1401
|
-
var TextInputComponent2 = ({ shape, title, ...props }) => {
|
|
1402
|
-
const client = useClient();
|
|
1403
|
-
const { node, runtime } = useComputeNodeState(shape);
|
|
1404
|
-
const inputRef = useRef4(null);
|
|
1405
|
-
const handleEnter = useCallback3(async (text) => {
|
|
1406
|
-
const value = text.trim();
|
|
1407
|
-
const { spaceId, objectId } = parseId(value);
|
|
1408
|
-
if (!spaceId || !objectId) {
|
|
1409
|
-
return;
|
|
1410
|
-
}
|
|
1411
|
-
const space = client.spaces.get(spaceId);
|
|
1412
|
-
const object = space?.db.query(Filter.id(objectId)).runSync()[0];
|
|
1413
|
-
if (!space || !isInstanceOf(Script.Script, object)) {
|
|
1414
|
-
return;
|
|
1415
|
-
}
|
|
1416
|
-
const [fn] = await space.db.query(Filter.type(Operation.PersistentOperation, {
|
|
1417
|
-
source: Ref2.make(object)
|
|
1418
|
-
})).run();
|
|
1419
|
-
if (!fn) {
|
|
1420
|
-
return;
|
|
1421
|
-
}
|
|
1422
|
-
node.value = value;
|
|
1423
|
-
node.function = Ref2.make(fn);
|
|
1424
|
-
node.inputSchema = fn.inputSchema;
|
|
1425
|
-
node.outputSchema = fn.outputSchema;
|
|
1426
|
-
}, [
|
|
1427
|
-
client,
|
|
1428
|
-
node
|
|
1429
|
-
]);
|
|
1430
|
-
const handleAction = useCallback3((action) => {
|
|
1431
|
-
if (action !== "run") {
|
|
1432
|
-
return;
|
|
1433
|
-
}
|
|
1434
|
-
runtime.evalNode();
|
|
1435
|
-
}, [
|
|
1436
|
-
runtime
|
|
1437
|
-
]);
|
|
1438
|
-
return /* @__PURE__ */ React13.createElement(Box, {
|
|
1439
|
-
shape,
|
|
1440
|
-
title: "Function",
|
|
1441
|
-
onAction: handleAction
|
|
1442
|
-
}, /* @__PURE__ */ React13.createElement(TextBox3, {
|
|
1443
|
-
...props,
|
|
1444
|
-
ref: inputRef,
|
|
1445
|
-
value: node.value,
|
|
1446
|
-
language: node.valueType === "object" ? "json" : void 0,
|
|
1447
|
-
onBlur: handleEnter,
|
|
1448
|
-
onEnter: handleEnter
|
|
1449
|
-
}));
|
|
1450
|
-
};
|
|
1451
|
-
var functionShape = {
|
|
1452
|
-
type: "function",
|
|
1453
|
-
name: "Function",
|
|
1454
|
-
icon: "ph--function--regular",
|
|
1455
|
-
component: TextInputComponent2,
|
|
1456
|
-
createShape: createFunction,
|
|
1457
|
-
getAnchors: (shape) => createFunctionAnchors(shape, FunctionInput, AnyOutput)
|
|
1458
|
-
};
|
|
1459
|
-
|
|
1460
|
-
// src/shapes/Gpt.tsx
|
|
1461
|
-
import * as Schema13 from "effect/Schema";
|
|
1462
|
-
import React14, { useEffect as useEffect4, useState as useState6 } from "react";
|
|
1463
|
-
import { GptInput, GptOutput } from "@dxos/conductor";
|
|
1464
|
-
import { ScrollArea as ScrollArea2 } from "@dxos/react-ui";
|
|
1465
|
-
var GptShape = Schema13.extend(ComputeShape, Schema13.Struct({
|
|
1466
|
-
type: Schema13.Literal("gpt")
|
|
1467
|
-
}));
|
|
1468
|
-
var createGpt = (props) => createShape({
|
|
1469
|
-
type: "gpt",
|
|
1470
|
-
size: {
|
|
1471
|
-
width: 256,
|
|
1472
|
-
height: Math.max(getHeight(GptInput), getHeight(GptOutput))
|
|
1473
|
-
},
|
|
1474
|
-
...props
|
|
1475
|
-
});
|
|
1476
|
-
var GptComponent = ({ shape }) => {
|
|
1477
|
-
const { meta, runtime } = useComputeNodeState(shape);
|
|
1478
|
-
const [text, setText] = useState6("");
|
|
1479
|
-
const [tokens, setTokens] = useState6(0);
|
|
1480
|
-
useEffect4(() => {
|
|
1481
|
-
return runtime.subscribeToEventLog((ev) => {
|
|
1482
|
-
switch (ev.type) {
|
|
1483
|
-
case "begin-compute": {
|
|
1484
|
-
setText("");
|
|
1485
|
-
break;
|
|
1486
|
-
}
|
|
1487
|
-
case "custom": {
|
|
1488
|
-
const token = ev.event;
|
|
1489
|
-
switch (token.type) {
|
|
1490
|
-
case "content_block_delta":
|
|
1491
|
-
switch (token.delta.type) {
|
|
1492
|
-
case "text_delta": {
|
|
1493
|
-
const delta = token.delta.text;
|
|
1494
|
-
setText((prev) => {
|
|
1495
|
-
const text2 = prev + delta;
|
|
1496
|
-
setTokens(text2.split(" ").length);
|
|
1497
|
-
return text2;
|
|
1498
|
-
});
|
|
1499
|
-
break;
|
|
1500
|
-
}
|
|
1501
|
-
}
|
|
1502
|
-
break;
|
|
1503
|
-
}
|
|
1504
|
-
break;
|
|
1505
|
-
}
|
|
1506
|
-
}
|
|
1507
|
-
});
|
|
1508
|
-
}, [
|
|
1509
|
-
runtime?.subscribeToEventLog
|
|
1510
|
-
]);
|
|
1511
|
-
return /* @__PURE__ */ React14.createElement(FunctionBody, {
|
|
1512
|
-
shape,
|
|
1513
|
-
content: /* @__PURE__ */ React14.createElement(ScrollArea2.Root, {
|
|
1514
|
-
orientation: "vertical",
|
|
1515
|
-
thin: true
|
|
1516
|
-
}, /* @__PURE__ */ React14.createElement(ScrollArea2.Viewport, null, text)),
|
|
1517
|
-
status: `${tokens} tokens`,
|
|
1518
|
-
inputSchema: meta.input,
|
|
1519
|
-
outputSchema: meta.output
|
|
1520
|
-
});
|
|
1521
|
-
};
|
|
1522
|
-
var gptShape = {
|
|
1523
|
-
type: "gpt",
|
|
1524
|
-
name: "GPT",
|
|
1525
|
-
icon: "ph--brain--regular",
|
|
1526
|
-
component: GptComponent,
|
|
1527
|
-
createShape: createGpt,
|
|
1528
|
-
getAnchors: (shape) => createFunctionAnchors(shape, GptInput, GptOutput),
|
|
1529
|
-
openable: true
|
|
1530
|
-
};
|
|
1531
|
-
|
|
1532
|
-
// src/shapes/GptRealtime.tsx
|
|
1533
|
-
import * as Schema14 from "effect/Schema";
|
|
1534
|
-
import React15, { useState as useState7 } from "react";
|
|
1535
|
-
import { log as log2 } from "@dxos/log";
|
|
1536
|
-
import { useConfig } from "@dxos/react-client";
|
|
1537
|
-
import { Icon as Icon4 } from "@dxos/react-ui";
|
|
1538
|
-
var __dxlog_file6 = "/__w/dxos/dxos/packages/ui/react-ui-canvas-compute/src/shapes/GptRealtime.tsx";
|
|
1539
|
-
var GptRealtimeShape = Schema14.extend(ComputeShape, Schema14.Struct({
|
|
1540
|
-
type: Schema14.Literal("gpt-realtime")
|
|
1541
|
-
}));
|
|
1542
|
-
var createGptRealtime = (props) => createShape({
|
|
1543
|
-
type: "gpt-realtime",
|
|
1544
|
-
size: {
|
|
1545
|
-
width: 256,
|
|
1546
|
-
height: 256
|
|
1547
|
-
},
|
|
1548
|
-
...props
|
|
1549
|
-
});
|
|
1550
|
-
var GptRealtimeComponent = ({ shape }) => {
|
|
1551
|
-
const [isLive, setIsLive] = useState7(false);
|
|
1552
|
-
const [isReady, setIsReady] = useState7(false);
|
|
1553
|
-
const config = useConfig();
|
|
1554
|
-
const start = async () => {
|
|
1555
|
-
setIsLive(true);
|
|
1556
|
-
try {
|
|
1557
|
-
const peerConnection = new RTCPeerConnection();
|
|
1558
|
-
peerConnection.ontrack = (event) => {
|
|
1559
|
-
const audioElement = document.createElement("audio");
|
|
1560
|
-
audioElement.srcObject = event.streams[0];
|
|
1561
|
-
audioElement.autoplay = true;
|
|
1562
|
-
audioElement.controls = false;
|
|
1563
|
-
audioElement.style.display = "none";
|
|
1564
|
-
document.body.appendChild(audioElement);
|
|
1565
|
-
setIsReady(true);
|
|
1566
|
-
};
|
|
1567
|
-
const stream = await navigator.mediaDevices.getUserMedia({
|
|
1568
|
-
audio: true
|
|
1569
|
-
});
|
|
1570
|
-
stream.getTracks().forEach((track) => peerConnection.addTransceiver(track, {
|
|
1571
|
-
direction: "sendrecv"
|
|
1572
|
-
}));
|
|
1573
|
-
const offer = await peerConnection.createOffer();
|
|
1574
|
-
await peerConnection.setLocalDescription(offer);
|
|
1575
|
-
const AiServiceUrl = new URL("/rtc-connect", config.values.runtime?.services?.ai?.server ?? DEFAULT_AI_SERVICE_URL);
|
|
1576
|
-
const response = await fetch(AiServiceUrl, {
|
|
1577
|
-
method: "POST",
|
|
1578
|
-
body: offer.sdp,
|
|
1579
|
-
headers: {
|
|
1580
|
-
"Content-Type": "application/sdp"
|
|
1581
|
-
}
|
|
1582
|
-
});
|
|
1583
|
-
const answer = await response.text();
|
|
1584
|
-
await peerConnection.setRemoteDescription({
|
|
1585
|
-
sdp: answer,
|
|
1586
|
-
type: "answer"
|
|
1587
|
-
});
|
|
1588
|
-
const dataChannel = peerConnection.createDataChannel("response");
|
|
1589
|
-
const configureData = () => {
|
|
1590
|
-
log2.info("Configuring data channel", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 69, S: void 0 });
|
|
1591
|
-
const event = {
|
|
1592
|
-
type: "session.update",
|
|
1593
|
-
session: {
|
|
1594
|
-
modalities: [
|
|
1595
|
-
"text",
|
|
1596
|
-
"audio"
|
|
1597
|
-
],
|
|
1598
|
-
// Provide the tools. Note they match the keys in the `fns` object above
|
|
1599
|
-
tools: []
|
|
1600
|
-
}
|
|
1601
|
-
};
|
|
1602
|
-
dataChannel.send(JSON.stringify(event));
|
|
1603
|
-
};
|
|
1604
|
-
dataChannel.addEventListener("open", (ev) => {
|
|
1605
|
-
log2.info("Opening data channel", {
|
|
1606
|
-
ev
|
|
1607
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 84, S: void 0 });
|
|
1608
|
-
configureData();
|
|
1609
|
-
});
|
|
1610
|
-
dataChannel.addEventListener("message", async (ev) => {
|
|
1611
|
-
const msg = JSON.parse(ev.data);
|
|
1612
|
-
if (msg.type === "response.function_call_arguments.done") {
|
|
1613
|
-
}
|
|
1614
|
-
});
|
|
1615
|
-
} catch (error) {
|
|
1616
|
-
log2.error("Error in realtime session:", {
|
|
1617
|
-
error
|
|
1618
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 124, S: void 0 });
|
|
1619
|
-
throw error;
|
|
1620
|
-
}
|
|
1621
|
-
};
|
|
1622
|
-
return /* @__PURE__ */ React15.createElement("div", {
|
|
1623
|
-
className: "flex w-full justify-center items-center"
|
|
1624
|
-
}, /* @__PURE__ */ React15.createElement(Icon4, {
|
|
1625
|
-
icon: isReady ? "ph--waveform--regular" : isLive ? "ph--pulse--regular" : "ph--play--regular",
|
|
1626
|
-
size: 16,
|
|
1627
|
-
classNames: !isLive && "cursor-pointer",
|
|
1628
|
-
onClick: start
|
|
1629
|
-
}));
|
|
1630
|
-
};
|
|
1631
|
-
var gptRealtimeShape = {
|
|
1632
|
-
type: "gpt-realtime",
|
|
1633
|
-
name: "GPT Realtime",
|
|
1634
|
-
icon: "ph--pulse--regular",
|
|
1635
|
-
component: GptRealtimeComponent,
|
|
1636
|
-
createShape: createGptRealtime,
|
|
1637
|
-
// TODO(dmaretskyi): Can we fetch the schema dynamically?
|
|
1638
|
-
getAnchors: (shape) => createFunctionAnchors(shape, Schema14.Struct({
|
|
1639
|
-
audio: Schema14.Any
|
|
1640
|
-
}), Schema14.Struct({})),
|
|
1641
|
-
resizable: true
|
|
1642
|
-
};
|
|
1643
|
-
var DEFAULT_AI_SERVICE_URL = "http://localhost:8788";
|
|
1644
|
-
|
|
1645
|
-
// src/shapes/Json.tsx
|
|
1646
|
-
import * as Schema15 from "effect/Schema";
|
|
1647
|
-
import React16 from "react";
|
|
1648
|
-
import { DEFAULT_INPUT as DEFAULT_INPUT4, DefaultOutput, JsonTransformInput } from "@dxos/conductor";
|
|
1649
|
-
import { createAnchorMap as createAnchorMap6 } from "@dxos/react-ui-canvas-editor";
|
|
1650
|
-
import { Syntax } from "@dxos/react-ui-syntax-highlighter";
|
|
1651
|
-
var JsonShape = Schema15.extend(ComputeShape, Schema15.Struct({
|
|
1652
|
-
type: Schema15.Literal("json")
|
|
1653
|
-
}));
|
|
1654
|
-
var JsonTransformShape = Schema15.extend(ComputeShape, Schema15.Struct({
|
|
1655
|
-
type: Schema15.Literal("json-transform")
|
|
1656
|
-
}));
|
|
1657
|
-
var JsonComponent = ({ shape, ...props }) => {
|
|
1658
|
-
const { runtime } = useComputeNodeState(shape);
|
|
1659
|
-
const input = runtime.inputs[DEFAULT_INPUT4];
|
|
1660
|
-
const value = input?.type === "executed" ? input.value : void 0;
|
|
1661
|
-
return /* @__PURE__ */ React16.createElement(Box, {
|
|
1662
|
-
shape
|
|
1663
|
-
}, /* @__PURE__ */ React16.createElement(Syntax.Root, {
|
|
1664
|
-
data: value
|
|
1665
|
-
}, /* @__PURE__ */ React16.createElement(Syntax.Content, null, /* @__PURE__ */ React16.createElement(Syntax.Filter, null), /* @__PURE__ */ React16.createElement(Syntax.Viewport, null, /* @__PURE__ */ React16.createElement(Syntax.Code, {
|
|
1666
|
-
classNames: "text-xs"
|
|
1667
|
-
})))));
|
|
1668
|
-
};
|
|
1669
|
-
var JsonTransformComponent = ({ shape, ...props }) => {
|
|
1670
|
-
return /* @__PURE__ */ React16.createElement(Box, {
|
|
1671
|
-
shape
|
|
1672
|
-
});
|
|
1673
|
-
};
|
|
1674
|
-
var createJson = (props) => createShape({
|
|
1675
|
-
type: "json",
|
|
1676
|
-
size: {
|
|
1677
|
-
width: 256,
|
|
1678
|
-
height: 256
|
|
1679
|
-
},
|
|
1680
|
-
...props
|
|
1681
|
-
});
|
|
1682
|
-
var jsonShape = {
|
|
1683
|
-
type: "json",
|
|
1684
|
-
name: "JSON",
|
|
1685
|
-
icon: "ph--code--regular",
|
|
1686
|
-
component: (props) => /* @__PURE__ */ React16.createElement(JsonComponent, props),
|
|
1687
|
-
createShape: createJson,
|
|
1688
|
-
getAnchors: (shape) => createAnchorMap6(shape, {
|
|
1689
|
-
[createAnchorId("input")]: {
|
|
1690
|
-
x: -1,
|
|
1691
|
-
y: 0
|
|
1692
|
-
},
|
|
1693
|
-
[createAnchorId("output")]: {
|
|
1694
|
-
x: 1,
|
|
1695
|
-
y: 0
|
|
1696
|
-
}
|
|
1697
|
-
}),
|
|
1698
|
-
resizable: true
|
|
1699
|
-
};
|
|
1700
|
-
var createJsonTransform = (props) => createShape({
|
|
1701
|
-
type: "json-transform",
|
|
1702
|
-
size: {
|
|
1703
|
-
width: 128,
|
|
1704
|
-
height: getHeight(JsonTransformInput)
|
|
1705
|
-
},
|
|
1706
|
-
...props
|
|
1707
|
-
});
|
|
1708
|
-
var jsonTransformShape = {
|
|
1709
|
-
type: "json-transform",
|
|
1710
|
-
name: "Transform",
|
|
1711
|
-
icon: "ph--shuffle-simple--regular",
|
|
1712
|
-
component: (props) => /* @__PURE__ */ React16.createElement(JsonTransformComponent, props),
|
|
1713
|
-
createShape: createJsonTransform,
|
|
1714
|
-
getAnchors: (shape) => createFunctionAnchors(shape, JsonTransformInput, DefaultOutput),
|
|
1715
|
-
resizable: true
|
|
1716
|
-
};
|
|
1717
|
-
|
|
1718
|
-
// src/shapes/Logic.tsx
|
|
1719
|
-
import * as Schema16 from "effect/Schema";
|
|
1720
|
-
import React17 from "react";
|
|
1721
|
-
import { IfElseInput, IfElseOutput, IfInput, IfOutput } from "@dxos/conductor";
|
|
1722
|
-
var IfShape = Schema16.extend(ComputeShape, Schema16.Struct({
|
|
1723
|
-
type: Schema16.Literal("if")
|
|
1724
|
-
}));
|
|
1725
|
-
var IfElseShape = Schema16.extend(ComputeShape, Schema16.Struct({
|
|
1726
|
-
type: Schema16.Literal("if-else")
|
|
1727
|
-
}));
|
|
1728
|
-
var IfComponent = ({ shape, ...props }) => {
|
|
1729
|
-
return /* @__PURE__ */ React17.createElement(FunctionBody, {
|
|
1730
|
-
shape,
|
|
1731
|
-
inputSchema: IfInput,
|
|
1732
|
-
outputSchema: IfOutput
|
|
1733
|
-
});
|
|
1734
|
-
};
|
|
1735
|
-
var IfElseComponent = ({ shape, ...props }) => {
|
|
1736
|
-
return /* @__PURE__ */ React17.createElement(FunctionBody, {
|
|
1737
|
-
shape,
|
|
1738
|
-
inputSchema: IfElseInput,
|
|
1739
|
-
outputSchema: IfElseOutput
|
|
1740
|
-
});
|
|
1741
|
-
};
|
|
1742
|
-
var createIf = (props) => createShape({
|
|
1743
|
-
type: "if",
|
|
1744
|
-
size: {
|
|
1745
|
-
width: 192,
|
|
1746
|
-
height: getHeight(IfInput)
|
|
1747
|
-
},
|
|
1748
|
-
...props
|
|
1749
|
-
});
|
|
1750
|
-
var ifShape = {
|
|
1751
|
-
type: "if",
|
|
1752
|
-
name: "IF",
|
|
1753
|
-
icon: "ph--arrows-split--regular",
|
|
1754
|
-
component: (props) => /* @__PURE__ */ React17.createElement(IfComponent, props),
|
|
1755
|
-
createShape: createIf,
|
|
1756
|
-
getAnchors: (shape) => createFunctionAnchors(shape, IfInput, IfOutput)
|
|
1757
|
-
};
|
|
1758
|
-
var createIfElse = (props) => createShape({
|
|
1759
|
-
type: "if-else",
|
|
1760
|
-
size: {
|
|
1761
|
-
width: 192,
|
|
1762
|
-
height: getHeight(IfElseInput)
|
|
1763
|
-
},
|
|
1764
|
-
...props
|
|
1765
|
-
});
|
|
1766
|
-
var ifElseShape = {
|
|
1767
|
-
type: "if-else",
|
|
1768
|
-
name: "IF/ELSE",
|
|
1769
|
-
icon: "ph--arrows-merge--regular",
|
|
1770
|
-
component: (props) => /* @__PURE__ */ React17.createElement(IfElseComponent, props),
|
|
1771
|
-
createShape: createIfElse,
|
|
1772
|
-
getAnchors: (shape) => createFunctionAnchors(shape, IfElseInput, IfElseOutput)
|
|
1773
|
-
};
|
|
1774
|
-
|
|
1775
|
-
// src/shapes/RNG.tsx
|
|
1776
|
-
import * as Schema17 from "effect/Schema";
|
|
1777
|
-
import React18, { useEffect as useEffect5, useState as useState8 } from "react";
|
|
1778
|
-
import { DEFAULT_OUTPUT as DEFAULT_OUTPUT6 } from "@dxos/conductor";
|
|
1779
|
-
import { Icon as Icon5 } from "@dxos/react-ui";
|
|
1780
|
-
import { createAnchorMap as createAnchorMap7 } from "@dxos/react-ui-canvas-editor";
|
|
1781
|
-
var RandomShape = Schema17.extend(ComputeShape, Schema17.Struct({
|
|
1782
|
-
type: Schema17.Literal("rng"),
|
|
1783
|
-
min: Schema17.optional(Schema17.Number),
|
|
1784
|
-
max: Schema17.optional(Schema17.Number)
|
|
1785
|
-
}));
|
|
1786
|
-
var createRandom = (props) => createShape({
|
|
1787
|
-
type: "rng",
|
|
1788
|
-
size: {
|
|
1789
|
-
width: 64,
|
|
1790
|
-
height: 64
|
|
1791
|
-
},
|
|
1792
|
-
...props
|
|
1793
|
-
});
|
|
1794
|
-
var icons = [
|
|
1795
|
-
"ph--dice-one--regular",
|
|
1796
|
-
"ph--dice-two--regular",
|
|
1797
|
-
"ph--dice-three--regular",
|
|
1798
|
-
"ph--dice-four--regular",
|
|
1799
|
-
"ph--dice-five--regular",
|
|
1800
|
-
"ph--dice-six--regular"
|
|
1801
|
-
];
|
|
1802
|
-
var pickIcon = () => icons[Math.floor(Math.random() * icons.length)];
|
|
1803
|
-
var RandomComponent = ({ shape }) => {
|
|
1804
|
-
const { runtime } = useComputeNodeState(shape);
|
|
1805
|
-
const [spin, setSpin] = useState8(false);
|
|
1806
|
-
const [icon, setIcon] = useState8(pickIcon());
|
|
1807
|
-
useEffect5(() => {
|
|
1808
|
-
if (!spin) {
|
|
1809
|
-
return;
|
|
1810
|
-
}
|
|
1811
|
-
const i = setInterval(() => setIcon(pickIcon()), 250);
|
|
1812
|
-
const t1 = setTimeout(() => clearInterval(i), 900);
|
|
1813
|
-
const t2 = setTimeout(() => setSpin(false), 1100);
|
|
1814
|
-
return () => {
|
|
1815
|
-
clearInterval(i);
|
|
1816
|
-
clearTimeout(t1);
|
|
1817
|
-
clearTimeout(t2);
|
|
1818
|
-
};
|
|
1819
|
-
}, [
|
|
1820
|
-
spin
|
|
1821
|
-
]);
|
|
1822
|
-
const handleClick = (ev) => {
|
|
1823
|
-
ev.stopPropagation();
|
|
1824
|
-
runtime.setOutput(DEFAULT_OUTPUT6, Math.random());
|
|
1825
|
-
setSpin(true);
|
|
1826
|
-
};
|
|
1827
|
-
return /* @__PURE__ */ React18.createElement("div", {
|
|
1828
|
-
className: "flex grow items-center justify-center"
|
|
1829
|
-
}, /* @__PURE__ */ React18.createElement(Icon5, {
|
|
1830
|
-
icon,
|
|
1831
|
-
classNames: spin && "animate-[spin_1s]",
|
|
1832
|
-
size: 10,
|
|
1833
|
-
onClick: handleClick
|
|
1834
|
-
}));
|
|
1835
|
-
};
|
|
1836
|
-
var randomShape = {
|
|
1837
|
-
type: "rng",
|
|
1838
|
-
name: "Random",
|
|
1839
|
-
icon: "ph--dice-six--regular",
|
|
1840
|
-
component: RandomComponent,
|
|
1841
|
-
createShape: createRandom,
|
|
1842
|
-
getAnchors: (shape) => createAnchorMap7(shape, {
|
|
1843
|
-
[createAnchorId("output")]: {
|
|
1844
|
-
x: 1,
|
|
1845
|
-
y: 0
|
|
1846
|
-
}
|
|
1847
|
-
})
|
|
1848
|
-
};
|
|
1849
|
-
|
|
1850
|
-
// src/shapes/Scope.tsx
|
|
1851
|
-
import * as Schema18 from "effect/Schema";
|
|
1852
|
-
import React19 from "react";
|
|
1853
|
-
import { DEFAULT_INPUT as DEFAULT_INPUT5 } from "@dxos/conductor";
|
|
1854
|
-
import { useAudioStream } from "@dxos/react-ui-audio";
|
|
1855
|
-
import { createAnchorMap as createAnchorMap8 } from "@dxos/react-ui-canvas-editor";
|
|
1856
|
-
import { Chaos, shaderPresets } from "@dxos/react-ui-experimental";
|
|
1857
|
-
var ScopeShape = Schema18.extend(ComputeShape, Schema18.Struct({
|
|
1858
|
-
type: Schema18.Literal("scope")
|
|
1859
|
-
}));
|
|
1860
|
-
var createScope = (props) => createShape({
|
|
1861
|
-
type: "scope",
|
|
1862
|
-
size: {
|
|
1863
|
-
width: 128,
|
|
1864
|
-
height: 128
|
|
1865
|
-
},
|
|
1866
|
-
classNames: "rounded-full border-primary-800",
|
|
1867
|
-
...props
|
|
1868
|
-
});
|
|
1869
|
-
var ScopeComponent = ({ shape }) => {
|
|
1870
|
-
const { runtime } = useComputeNodeState(shape);
|
|
1871
|
-
const input = runtime.inputs[DEFAULT_INPUT5];
|
|
1872
|
-
const active = input?.type === "executed" ? input.value : false;
|
|
1873
|
-
const { getAverage } = useAudioStream(active);
|
|
1874
|
-
return /* @__PURE__ */ React19.createElement("div", {
|
|
1875
|
-
className: "flex w-full justify-center items-center bg-black"
|
|
1876
|
-
}, /* @__PURE__ */ React19.createElement(Chaos, {
|
|
1877
|
-
active,
|
|
1878
|
-
getValue: getAverage,
|
|
1879
|
-
options: {
|
|
1880
|
-
...shaderPresets.heptapod,
|
|
1881
|
-
zoom: 1.2
|
|
1882
|
-
}
|
|
1883
|
-
}));
|
|
1884
|
-
};
|
|
1885
|
-
var scopeShape = {
|
|
1886
|
-
type: "scope",
|
|
1887
|
-
name: "Scope",
|
|
1888
|
-
icon: "ph--waveform--regular",
|
|
1889
|
-
component: ScopeComponent,
|
|
1890
|
-
createShape: createScope,
|
|
1891
|
-
getAnchors: (shape) => createAnchorMap8(shape, {
|
|
1892
|
-
[createAnchorId("input")]: {
|
|
1893
|
-
x: -1,
|
|
1894
|
-
y: 0
|
|
1895
|
-
}
|
|
1896
|
-
})
|
|
1897
|
-
};
|
|
1898
|
-
|
|
1899
|
-
// src/shapes/Surface.tsx
|
|
1900
|
-
import * as Schema19 from "effect/Schema";
|
|
1901
|
-
import React20 from "react";
|
|
1902
|
-
import { Surface } from "@dxos/app-framework/ui";
|
|
1903
|
-
import { AppSurface } from "@dxos/app-toolkit/ui";
|
|
1904
|
-
import { DEFAULT_INPUT as DEFAULT_INPUT6 } from "@dxos/conductor";
|
|
1905
|
-
import { Card } from "@dxos/react-ui";
|
|
1906
|
-
import { createAnchorMap as createAnchorMap9 } from "@dxos/react-ui-canvas-editor";
|
|
1907
|
-
var SurfaceShape = Schema19.extend(ComputeShape, Schema19.Struct({
|
|
1908
|
-
type: Schema19.Literal("surface")
|
|
1909
|
-
}));
|
|
1910
|
-
var createSurface = (props) => createShape({
|
|
1911
|
-
type: "surface",
|
|
1912
|
-
size: {
|
|
1913
|
-
width: 384,
|
|
1914
|
-
height: 384
|
|
1915
|
-
},
|
|
1916
|
-
...props
|
|
1917
|
-
});
|
|
1918
|
-
var SurfaceComponent = ({ shape }) => {
|
|
1919
|
-
const { runtime } = useComputeNodeState(shape);
|
|
1920
|
-
const input = runtime.inputs[DEFAULT_INPUT6];
|
|
1921
|
-
const value = input?.type === "executed" ? input.value : null;
|
|
1922
|
-
const handleAction = (action) => {
|
|
1923
|
-
if (action === "run") {
|
|
1924
|
-
runtime.evalNode();
|
|
1925
|
-
}
|
|
1926
|
-
};
|
|
1927
|
-
return /* @__PURE__ */ React20.createElement(Box, {
|
|
1928
|
-
shape,
|
|
1929
|
-
onAction: handleAction
|
|
1930
|
-
}, /* @__PURE__ */ React20.createElement(Card.Root, null, value !== null && /* @__PURE__ */ React20.createElement(Surface.Surface, {
|
|
1931
|
-
type: AppSurface.CardContent,
|
|
1932
|
-
data: {
|
|
1933
|
-
subject: value
|
|
1934
|
-
},
|
|
1935
|
-
limit: 1
|
|
1936
|
-
})));
|
|
1937
|
-
};
|
|
1938
|
-
var surfaceShape = {
|
|
1939
|
-
type: "surface",
|
|
1940
|
-
name: "Surface",
|
|
1941
|
-
icon: "ph--frame-corners--regular",
|
|
1942
|
-
component: SurfaceComponent,
|
|
1943
|
-
createShape: createSurface,
|
|
1944
|
-
getAnchors: (shape) => createAnchorMap9(shape, {
|
|
1945
|
-
[createAnchorId("input")]: {
|
|
1946
|
-
x: -1,
|
|
1947
|
-
y: 0
|
|
1948
|
-
}
|
|
1949
|
-
}),
|
|
1950
|
-
resizable: true
|
|
1951
|
-
};
|
|
1952
|
-
|
|
1953
|
-
// src/shapes/Switch.tsx
|
|
1954
|
-
import * as Schema20 from "effect/Schema";
|
|
1955
|
-
import React21, { useEffect as useEffect6, useState as useState9 } from "react";
|
|
1956
|
-
import { DEFAULT_OUTPUT as DEFAULT_OUTPUT7 } from "@dxos/conductor";
|
|
1957
|
-
import { Input as Input2 } from "@dxos/react-ui";
|
|
1958
|
-
import { createAnchorMap as createAnchorMap10 } from "@dxos/react-ui-canvas-editor";
|
|
1959
|
-
var SwitchShape = Schema20.extend(ComputeShape, Schema20.Struct({
|
|
1960
|
-
type: Schema20.Literal("switch")
|
|
1961
|
-
}));
|
|
1962
|
-
var createSwitch = (props) => createShape({
|
|
1963
|
-
type: "switch",
|
|
1964
|
-
size: {
|
|
1965
|
-
width: 64,
|
|
1966
|
-
height: 64
|
|
1967
|
-
},
|
|
1968
|
-
...props
|
|
1969
|
-
});
|
|
1970
|
-
var SwitchComponent = ({ shape }) => {
|
|
1971
|
-
const { runtime } = useComputeNodeState(shape);
|
|
1972
|
-
const [value, setValue] = useState9(false);
|
|
1973
|
-
useEffect6(() => {
|
|
1974
|
-
runtime.setOutput(DEFAULT_OUTPUT7, value);
|
|
1975
|
-
}, [
|
|
1976
|
-
value
|
|
1977
|
-
]);
|
|
1978
|
-
return /* @__PURE__ */ React21.createElement("div", {
|
|
1979
|
-
className: "flex w-full justify-center items-center",
|
|
1980
|
-
onClick: (ev) => ev.stopPropagation()
|
|
1981
|
-
}, /* @__PURE__ */ React21.createElement(Input2.Root, null, /* @__PURE__ */ React21.createElement(Input2.Switch, {
|
|
1982
|
-
checked: value,
|
|
1983
|
-
onCheckedChange: (value2) => setValue(value2)
|
|
1984
|
-
})));
|
|
1985
|
-
};
|
|
1986
|
-
var switchShape = {
|
|
1987
|
-
type: "switch",
|
|
1988
|
-
name: "Switch",
|
|
1989
|
-
icon: "ph--toggle-left--regular",
|
|
1990
|
-
component: SwitchComponent,
|
|
1991
|
-
createShape: createSwitch,
|
|
1992
|
-
getAnchors: (shape) => createAnchorMap10(shape, {
|
|
1993
|
-
[createAnchorId("output")]: {
|
|
1994
|
-
x: 1,
|
|
1995
|
-
y: 0
|
|
1996
|
-
}
|
|
1997
|
-
})
|
|
1998
|
-
};
|
|
1999
|
-
|
|
2000
|
-
// src/shapes/Table.tsx
|
|
2001
|
-
import * as Schema21 from "effect/Schema";
|
|
2002
|
-
import React22 from "react";
|
|
2003
|
-
import { createInputSchema, createOutputSchema } from "@dxos/conductor";
|
|
2004
|
-
import { Type } from "@dxos/echo";
|
|
2005
|
-
import { Message } from "@dxos/types";
|
|
2006
|
-
var InputSchema = createInputSchema(Type.getSchema(Message.Message));
|
|
2007
|
-
var OutputSchema = createOutputSchema(Schema21.mutable(Schema21.Array(Type.getSchema(Message.Message))));
|
|
2008
|
-
var TableShape = Schema21.extend(ComputeShape, Schema21.Struct({
|
|
2009
|
-
type: Schema21.Literal("table")
|
|
2010
|
-
}));
|
|
2011
|
-
var createTable = (props) => createShape({
|
|
2012
|
-
type: "table",
|
|
2013
|
-
size: {
|
|
2014
|
-
width: 320,
|
|
2015
|
-
height: 512
|
|
2016
|
-
},
|
|
2017
|
-
...props
|
|
2018
|
-
});
|
|
2019
|
-
var TableComponent = ({ shape }) => {
|
|
2020
|
-
return /* @__PURE__ */ React22.createElement(Box, {
|
|
2021
|
-
shape
|
|
2022
|
-
});
|
|
2023
|
-
};
|
|
2024
|
-
var tableShape = {
|
|
2025
|
-
type: "table",
|
|
2026
|
-
name: "Table",
|
|
2027
|
-
icon: "ph--table--regular",
|
|
2028
|
-
component: TableComponent,
|
|
2029
|
-
createShape: createTable,
|
|
2030
|
-
getAnchors: (shape) => createFunctionAnchors(shape, InputSchema, OutputSchema),
|
|
2031
|
-
resizable: true
|
|
2032
|
-
};
|
|
2033
|
-
|
|
2034
|
-
// src/shapes/Template.tsx
|
|
2035
|
-
import * as Schema22 from "effect/Schema";
|
|
2036
|
-
import React23, { useRef as useRef5 } from "react";
|
|
2037
|
-
import { ComputeValueType as ComputeValueType3, TemplateOutput, VoidInput as VoidInput2, getTemplateInputSchema as getTemplateInputSchema2 } from "@dxos/conductor";
|
|
2038
|
-
import { toJsonSchema } from "@dxos/echo/JsonSchema";
|
|
2039
|
-
import { invariant as invariant5 } from "@dxos/invariant";
|
|
2040
|
-
import { TextBox as TextBox4 } from "@dxos/react-ui-canvas-editor";
|
|
2041
|
-
var __dxlog_file7 = "/__w/dxos/dxos/packages/ui/react-ui-canvas-compute/src/shapes/Template.tsx";
|
|
2042
|
-
var TemplateShape = Schema22.extend(ComputeShape, Schema22.Struct({
|
|
2043
|
-
type: Schema22.Literal("template"),
|
|
2044
|
-
valueType: Schema22.optional(ComputeValueType3)
|
|
2045
|
-
}));
|
|
2046
|
-
var TextInputComponent3 = ({ shape, title, ...props }) => {
|
|
2047
|
-
const { node } = useComputeNodeState(shape);
|
|
2048
|
-
const inputRef = useRef5(null);
|
|
2049
|
-
const handleEnter = (text) => {
|
|
2050
|
-
const value = text.trim();
|
|
2051
|
-
if (value.length) {
|
|
2052
|
-
const schema = getTemplateInputSchema2(node);
|
|
2053
|
-
node.value = value;
|
|
2054
|
-
node.inputSchema = toJsonSchema(schema);
|
|
2055
|
-
}
|
|
2056
|
-
};
|
|
2057
|
-
const handleTypeChange = (newType) => {
|
|
2058
|
-
invariant5(Schema22.is(ComputeValueType3)(newType), "Invalid type", { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 32, S: void 0, A: ["Schema.is(ComputeValueType)(newType)", "'Invalid type'"] });
|
|
2059
|
-
node.valueType = newType;
|
|
2060
|
-
node.inputSchema = toJsonSchema(getTemplateInputSchema2(node));
|
|
2061
|
-
};
|
|
2062
|
-
return /* @__PURE__ */ React23.createElement(Box, {
|
|
2063
|
-
shape,
|
|
2064
|
-
title: "Template",
|
|
2065
|
-
status: /* @__PURE__ */ React23.createElement(TypeSelect, {
|
|
2066
|
-
value: node.valueType ?? "string",
|
|
2067
|
-
onValueChange: handleTypeChange
|
|
2068
|
-
})
|
|
2069
|
-
}, /* @__PURE__ */ React23.createElement(TextBox4, {
|
|
2070
|
-
...props,
|
|
2071
|
-
ref: inputRef,
|
|
2072
|
-
value: node.value,
|
|
2073
|
-
language: node.valueType === "object" ? "json" : void 0,
|
|
2074
|
-
onBlur: handleEnter,
|
|
2075
|
-
onEnter: handleEnter
|
|
2076
|
-
}));
|
|
2077
|
-
};
|
|
2078
|
-
var createTemplate = (props) => createShape({
|
|
2079
|
-
type: "template",
|
|
2080
|
-
size: {
|
|
2081
|
-
width: 256,
|
|
2082
|
-
height: 384
|
|
2083
|
-
},
|
|
2084
|
-
...props
|
|
2085
|
-
});
|
|
2086
|
-
var templateShape = {
|
|
2087
|
-
type: "template",
|
|
2088
|
-
name: "Template",
|
|
2089
|
-
icon: "ph--article--regular",
|
|
2090
|
-
component: (props) => /* @__PURE__ */ React23.createElement(TextInputComponent3, {
|
|
2091
|
-
...props,
|
|
2092
|
-
placeholder: "Prompt"
|
|
2093
|
-
}),
|
|
2094
|
-
createShape: createTemplate,
|
|
2095
|
-
getAnchors: (shape) => createFunctionAnchors(shape, VoidInput2, TemplateOutput),
|
|
2096
|
-
resizable: true
|
|
2097
|
-
};
|
|
2098
|
-
|
|
2099
|
-
// src/shapes/Text.tsx
|
|
2100
|
-
import * as Schema23 from "effect/Schema";
|
|
2101
|
-
import React24 from "react";
|
|
2102
|
-
import { DEFAULT_INPUT as DEFAULT_INPUT7 } from "@dxos/conductor";
|
|
2103
|
-
import { TextBox as TextBox5 } from "@dxos/react-ui-canvas-editor";
|
|
2104
|
-
import { createAnchorMap as createAnchorMap11 } from "@dxos/react-ui-canvas-editor";
|
|
2105
|
-
var TextShape = Schema23.extend(ComputeShape, Schema23.Struct({
|
|
2106
|
-
type: Schema23.Literal("text")
|
|
2107
|
-
}));
|
|
2108
|
-
var createText = (props) => createShape({
|
|
2109
|
-
type: "text",
|
|
2110
|
-
size: {
|
|
2111
|
-
width: 384,
|
|
2112
|
-
height: 384
|
|
2113
|
-
},
|
|
2114
|
-
...props
|
|
2115
|
-
});
|
|
2116
|
-
var TextComponent = ({ shape }) => {
|
|
2117
|
-
const { runtime } = useComputeNodeState(shape);
|
|
2118
|
-
const input = runtime.inputs[DEFAULT_INPUT7];
|
|
2119
|
-
const value = input?.type === "executed" ? input.value : 0;
|
|
2120
|
-
const handleAction = (action) => {
|
|
2121
|
-
if (action === "run") {
|
|
2122
|
-
runtime.evalNode();
|
|
2123
|
-
}
|
|
2124
|
-
};
|
|
2125
|
-
return /* @__PURE__ */ React24.createElement(Box, {
|
|
2126
|
-
shape,
|
|
2127
|
-
onAction: handleAction
|
|
2128
|
-
}, /* @__PURE__ */ React24.createElement(TextBox5, {
|
|
2129
|
-
value
|
|
2130
|
-
}));
|
|
2131
|
-
};
|
|
2132
|
-
var textShape = {
|
|
2133
|
-
type: "text",
|
|
2134
|
-
name: "Text",
|
|
2135
|
-
icon: "ph--article--regular",
|
|
2136
|
-
component: TextComponent,
|
|
2137
|
-
createShape: createText,
|
|
2138
|
-
getAnchors: (shape) => createAnchorMap11(shape, {
|
|
2139
|
-
[createAnchorId("input")]: {
|
|
2140
|
-
x: -1,
|
|
2141
|
-
y: 0
|
|
2142
|
-
}
|
|
2143
|
-
}),
|
|
2144
|
-
resizable: true
|
|
2145
|
-
};
|
|
2146
|
-
|
|
2147
|
-
// src/shapes/Thread.tsx
|
|
2148
|
-
import * as Schema24 from "effect/Schema";
|
|
2149
|
-
import React25, { useEffect as useEffect7, useRef as useRef6 } from "react";
|
|
2150
|
-
import { createInputSchema as createInputSchema2, createOutputSchema as createOutputSchema2 } from "@dxos/conductor";
|
|
2151
|
-
import { Type as Type2 } from "@dxos/echo";
|
|
2152
|
-
import { ScrollArea as ScrollArea3 } from "@dxos/react-ui";
|
|
2153
|
-
import { Message as Message2 } from "@dxos/types";
|
|
2154
|
-
import { mx as mx3 } from "@dxos/ui-theme";
|
|
2155
|
-
var InputSchema2 = createInputSchema2(Type2.getSchema(Message2.Message));
|
|
2156
|
-
var OutputSchema2 = createOutputSchema2(Schema24.mutable(Schema24.Array(Type2.getSchema(Message2.Message))));
|
|
2157
|
-
var ThreadShape = Schema24.extend(ComputeShape, Schema24.Struct({
|
|
2158
|
-
type: Schema24.Literal("thread")
|
|
2159
|
-
}));
|
|
2160
|
-
var createThread = (props) => createShape({
|
|
2161
|
-
type: "thread",
|
|
2162
|
-
size: {
|
|
2163
|
-
width: 384,
|
|
2164
|
-
height: 384
|
|
2165
|
-
},
|
|
2166
|
-
...props
|
|
2167
|
-
});
|
|
2168
|
-
var ThreadComponent = ({ shape }) => {
|
|
2169
|
-
const items = [];
|
|
2170
|
-
const scrollRef = useRef6(null);
|
|
2171
|
-
useEffect7(() => {
|
|
2172
|
-
if (scrollRef.current) {
|
|
2173
|
-
scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
|
|
2174
|
-
}
|
|
2175
|
-
}, [
|
|
2176
|
-
items
|
|
2177
|
-
]);
|
|
2178
|
-
return /* @__PURE__ */ React25.createElement(Box, {
|
|
2179
|
-
shape
|
|
2180
|
-
}, /* @__PURE__ */ React25.createElement(ScrollArea3.Root, {
|
|
2181
|
-
orientation: "vertical"
|
|
2182
|
-
}, /* @__PURE__ */ React25.createElement(ScrollArea3.Viewport, {
|
|
2183
|
-
classNames: "gap-2 p-2",
|
|
2184
|
-
ref: scrollRef
|
|
2185
|
-
}, [
|
|
2186
|
-
...items
|
|
2187
|
-
].map((item, i) => /* @__PURE__ */ React25.createElement(ThreadItem, {
|
|
2188
|
-
key: i,
|
|
2189
|
-
item
|
|
2190
|
-
})))));
|
|
2191
|
-
};
|
|
2192
|
-
var ThreadItem = ({ classNames, item }) => {
|
|
2193
|
-
if (typeof item !== "object") {
|
|
2194
|
-
return /* @__PURE__ */ React25.createElement("div", {
|
|
2195
|
-
className: mx3(classNames)
|
|
2196
|
-
}, item);
|
|
2197
|
-
}
|
|
2198
|
-
const { role, message } = item;
|
|
2199
|
-
return /* @__PURE__ */ React25.createElement("div", {
|
|
2200
|
-
className: mx3("flex", classNames, role === "user" && "justify-end")
|
|
2201
|
-
}, /* @__PURE__ */ React25.createElement("div", {
|
|
2202
|
-
className: mx3("block rounded-md p-1 px-2 text-sm", role === "user" ? "bg-blue-100 dark:bg-blue-800" : role === "system" ? "bg-red-100, dark:bg-red-800" : "whitespace-pre-wrap bg-neutral-50 dark:bg-neutral-800")
|
|
2203
|
-
}, message));
|
|
2204
|
-
};
|
|
2205
|
-
var threadShape = {
|
|
2206
|
-
type: "thread",
|
|
2207
|
-
name: "Thread",
|
|
2208
|
-
icon: "ph--chats-circle--regular",
|
|
2209
|
-
component: ThreadComponent,
|
|
2210
|
-
createShape: createThread,
|
|
2211
|
-
getAnchors: (shape) => createFunctionAnchors(shape, InputSchema2, OutputSchema2),
|
|
2212
|
-
resizable: true
|
|
2213
|
-
};
|
|
2214
|
-
|
|
2215
|
-
// src/shapes/TextToImage.tsx
|
|
2216
|
-
import * as Schema25 from "effect/Schema";
|
|
2217
|
-
import React26 from "react";
|
|
2218
|
-
import { createAnchorMap as createAnchorMap12 } from "@dxos/react-ui-canvas-editor";
|
|
2219
|
-
var TextToImageShape = Schema25.extend(ComputeShape, Schema25.Struct({
|
|
2220
|
-
type: Schema25.Literal("text-to-image")
|
|
2221
|
-
}));
|
|
2222
|
-
var createTextToImage = (props) => createShape({
|
|
2223
|
-
type: "text-to-image",
|
|
2224
|
-
size: {
|
|
2225
|
-
width: 128,
|
|
2226
|
-
height: 64
|
|
2227
|
-
},
|
|
2228
|
-
...props
|
|
2229
|
-
});
|
|
2230
|
-
var TextToImageComponent = ({ shape }) => {
|
|
2231
|
-
return /* @__PURE__ */ React26.createElement(Box, {
|
|
2232
|
-
shape
|
|
2233
|
-
});
|
|
2234
|
-
};
|
|
2235
|
-
var textToImageShape = {
|
|
2236
|
-
type: "text-to-image",
|
|
2237
|
-
name: "Image",
|
|
2238
|
-
icon: "ph--image--regular",
|
|
2239
|
-
component: TextToImageComponent,
|
|
2240
|
-
createShape: createTextToImage,
|
|
2241
|
-
getAnchors: (shape) => createAnchorMap12(shape, {
|
|
2242
|
-
[createAnchorId("output")]: {
|
|
2243
|
-
x: 1,
|
|
2244
|
-
y: 0
|
|
2245
|
-
}
|
|
2246
|
-
})
|
|
2247
|
-
};
|
|
2248
|
-
|
|
2249
|
-
// src/shapes/Trigger.tsx
|
|
2250
|
-
import * as Schema26 from "effect/Schema";
|
|
2251
|
-
import React27, { useEffect as useEffect8 } from "react";
|
|
2252
|
-
import { Trigger, TriggerEvent } from "@dxos/compute";
|
|
2253
|
-
import { VoidInput as VoidInput3 } from "@dxos/conductor";
|
|
2254
|
-
import { Filter as Filter2, Obj as Obj4, Query, Ref as Ref3 } from "@dxos/echo";
|
|
2255
|
-
import { useSpaces } from "@dxos/react-client/echo";
|
|
2256
|
-
import { Select as Select2 } from "@dxos/react-ui";
|
|
2257
|
-
var TriggerShapeSchema = Schema26.extend(ComputeShape, Schema26.Struct({
|
|
2258
|
-
type: Schema26.Literal("trigger"),
|
|
2259
|
-
functionTrigger: Schema26.optional(Ref3.Ref(Trigger.Trigger))
|
|
2260
|
-
}));
|
|
2261
|
-
var TriggerShape = TriggerShapeSchema;
|
|
2262
|
-
var createTrigger = (props) => {
|
|
2263
|
-
const functionTrigger = Trigger.make({
|
|
2264
|
-
enabled: true,
|
|
2265
|
-
spec: createTriggerSpec(props)
|
|
2266
|
-
});
|
|
2267
|
-
return createShape({
|
|
2268
|
-
type: "trigger",
|
|
2269
|
-
functionTrigger: Ref3.make(functionTrigger),
|
|
2270
|
-
size: {
|
|
2271
|
-
width: 192,
|
|
2272
|
-
height: getHeight(TriggerEvent.EmailEvent)
|
|
2273
|
-
},
|
|
2274
|
-
...props
|
|
2275
|
-
});
|
|
2276
|
-
};
|
|
2277
|
-
var TriggerComponent = ({ shape }) => {
|
|
2278
|
-
const [space] = useSpaces();
|
|
2279
|
-
const functionTrigger = shape.functionTrigger?.target;
|
|
2280
|
-
useEffect8(() => {
|
|
2281
|
-
if (functionTrigger && !functionTrigger.spec) {
|
|
2282
|
-
Obj4.update(functionTrigger, (functionTrigger2) => {
|
|
2283
|
-
functionTrigger2.spec = createTriggerSpec({
|
|
2284
|
-
triggerKind: "email",
|
|
2285
|
-
spaceId: space?.id
|
|
2286
|
-
});
|
|
2287
|
-
});
|
|
2288
|
-
}
|
|
2289
|
-
}, [
|
|
2290
|
-
functionTrigger,
|
|
2291
|
-
functionTrigger?.spec
|
|
2292
|
-
]);
|
|
2293
|
-
useEffect8(() => {
|
|
2294
|
-
shape.size.height = getHeight(getOutputSchema(functionTrigger?.spec?.kind ?? "email"));
|
|
2295
|
-
}, [
|
|
2296
|
-
functionTrigger?.spec?.kind
|
|
2297
|
-
]);
|
|
2298
|
-
const setKind = (kind) => {
|
|
2299
|
-
if (functionTrigger?.spec?.kind !== kind) {
|
|
2300
|
-
Obj4.update(functionTrigger, (obj) => {
|
|
2301
|
-
obj.spec = createTriggerSpec({
|
|
2302
|
-
triggerKind: kind,
|
|
2303
|
-
spaceId: space?.id
|
|
2304
|
-
});
|
|
2305
|
-
});
|
|
2306
|
-
}
|
|
2307
|
-
};
|
|
2308
|
-
if (!functionTrigger?.spec) {
|
|
2309
|
-
return;
|
|
2310
|
-
}
|
|
2311
|
-
return /* @__PURE__ */ React27.createElement(FunctionBody, {
|
|
2312
|
-
shape,
|
|
2313
|
-
status: /* @__PURE__ */ React27.createElement(TriggerKindSelect, {
|
|
2314
|
-
value: functionTrigger.spec?.kind,
|
|
2315
|
-
onValueChange: (kind) => setKind(kind)
|
|
2316
|
-
}),
|
|
2317
|
-
inputSchema: VoidInput3,
|
|
2318
|
-
outputSchema: getOutputSchema(functionTrigger.spec.kind)
|
|
2319
|
-
});
|
|
2320
|
-
};
|
|
2321
|
-
var TriggerKindSelect = ({ value, onValueChange }) => {
|
|
2322
|
-
return /* @__PURE__ */ React27.createElement(Select2.Root, {
|
|
2323
|
-
value,
|
|
2324
|
-
onValueChange
|
|
2325
|
-
}, /* @__PURE__ */ React27.createElement(Select2.TriggerButton, {
|
|
2326
|
-
variant: "ghost",
|
|
2327
|
-
classNames: "w-full px-0!"
|
|
2328
|
-
}), /* @__PURE__ */ React27.createElement(Select2.Portal, null, /* @__PURE__ */ React27.createElement(Select2.Content, null, /* @__PURE__ */ React27.createElement(Select2.ScrollUpButton, null), /* @__PURE__ */ React27.createElement(Select2.Viewport, null, Trigger.Kinds.map((kind) => /* @__PURE__ */ React27.createElement(Select2.Option, {
|
|
2329
|
-
key: kind,
|
|
2330
|
-
value: kind
|
|
2331
|
-
}, kind))), /* @__PURE__ */ React27.createElement(Select2.ScrollDownButton, null), /* @__PURE__ */ React27.createElement(Select2.Arrow, null))));
|
|
2332
|
-
};
|
|
2333
|
-
var createTriggerSpec = (props) => {
|
|
2334
|
-
const kind = props.triggerKind ?? "email";
|
|
2335
|
-
switch (kind) {
|
|
2336
|
-
case "timer":
|
|
2337
|
-
return Trigger.specTimer("*/10 * * * * *");
|
|
2338
|
-
case "webhook":
|
|
2339
|
-
return Trigger.specWebhook({
|
|
2340
|
-
method: "POST"
|
|
2341
|
-
});
|
|
2342
|
-
case "subscription":
|
|
2343
|
-
return Trigger.specSubscription(Query.select(Filter2.nothing()));
|
|
2344
|
-
case "email":
|
|
2345
|
-
return Trigger.specEmail();
|
|
2346
|
-
case "feed": {
|
|
2347
|
-
return {
|
|
2348
|
-
kind: "feed"
|
|
2349
|
-
};
|
|
2350
|
-
}
|
|
2351
|
-
}
|
|
2352
|
-
};
|
|
2353
|
-
var getOutputSchema = (kind) => {
|
|
2354
|
-
const kindToSchema = {
|
|
2355
|
-
["email"]: TriggerEvent.EmailEvent,
|
|
2356
|
-
["subscription"]: TriggerEvent.SubscriptionEvent,
|
|
2357
|
-
["timer"]: TriggerEvent.TimerEvent,
|
|
2358
|
-
["webhook"]: TriggerEvent.WebhookEvent,
|
|
2359
|
-
["feed"]: TriggerEvent.FeedEvent
|
|
2360
|
-
};
|
|
2361
|
-
return kindToSchema[kind];
|
|
2362
|
-
};
|
|
2363
|
-
var triggerShape = {
|
|
2364
|
-
type: "trigger",
|
|
2365
|
-
name: "Trigger",
|
|
2366
|
-
icon: "ph--lightning--regular",
|
|
2367
|
-
component: TriggerComponent,
|
|
2368
|
-
createShape: createTrigger,
|
|
2369
|
-
getAnchors: (shape) => createFunctionAnchors(shape, VoidInput3, getOutputSchema(shape.functionTrigger?.target?.spec?.kind ?? "email"))
|
|
2370
|
-
};
|
|
2371
|
-
|
|
2372
|
-
// src/registry.ts
|
|
2373
|
-
var computeShapes = [
|
|
2374
|
-
{
|
|
2375
|
-
title: "Inputs",
|
|
2376
|
-
shapes: [
|
|
2377
|
-
//
|
|
2378
|
-
constantShape,
|
|
2379
|
-
templateShape,
|
|
2380
|
-
chatShape,
|
|
2381
|
-
switchShape,
|
|
2382
|
-
audioShape,
|
|
2383
|
-
triggerShape,
|
|
2384
|
-
randomShape
|
|
2385
|
-
]
|
|
2386
|
-
},
|
|
2387
|
-
{
|
|
2388
|
-
title: "Transform",
|
|
2389
|
-
shapes: [
|
|
2390
|
-
//
|
|
2391
|
-
gptShape,
|
|
2392
|
-
gptRealtimeShape,
|
|
2393
|
-
functionShape,
|
|
2394
|
-
databaseShape,
|
|
2395
|
-
textToImageShape,
|
|
2396
|
-
appendShape
|
|
2397
|
-
]
|
|
2398
|
-
},
|
|
2399
|
-
{
|
|
2400
|
-
title: "Operations",
|
|
2401
|
-
shapes: [
|
|
2402
|
-
//
|
|
2403
|
-
ifShape,
|
|
2404
|
-
ifElseShape,
|
|
2405
|
-
andShape,
|
|
2406
|
-
orShape,
|
|
2407
|
-
notShape,
|
|
2408
|
-
reducerShape,
|
|
2409
|
-
jsonTransformShape
|
|
2410
|
-
]
|
|
2411
|
-
},
|
|
2412
|
-
{
|
|
2413
|
-
title: "Outputs",
|
|
2414
|
-
shapes: [
|
|
2415
|
-
//
|
|
2416
|
-
jsonShape,
|
|
2417
|
-
feedShape,
|
|
2418
|
-
threadShape,
|
|
2419
|
-
textShape,
|
|
2420
|
-
surfaceShape,
|
|
2421
|
-
beaconShape,
|
|
2422
|
-
scopeShape
|
|
2423
|
-
]
|
|
2424
|
-
},
|
|
2425
|
-
{
|
|
2426
|
-
title: "Misc",
|
|
2427
|
-
shapes: [
|
|
2428
|
-
//
|
|
2429
|
-
noteShape
|
|
2430
|
-
]
|
|
2431
|
-
}
|
|
2432
|
-
];
|
|
2433
|
-
|
|
2434
|
-
// src/compute-layout.ts
|
|
2435
|
-
import { DefaultInput, DefaultOutput as DefaultOutput2 } from "@dxos/conductor";
|
|
2436
|
-
import { toEffectSchema } from "@dxos/echo/JsonSchema";
|
|
2437
|
-
import { ShapeLayout } from "@dxos/react-ui-canvas-editor";
|
|
2438
|
-
var ComputeShapeLayout = class extends ShapeLayout {
|
|
2439
|
-
_controller;
|
|
2440
|
-
constructor(_controller, registry2) {
|
|
2441
|
-
super(registry2), this._controller = _controller;
|
|
2442
|
-
}
|
|
2443
|
-
// TODO(burdon): Doesn't update.
|
|
2444
|
-
getAnchors(shape) {
|
|
2445
|
-
const shapeDef = this._registry.getShapeDef(shape.type);
|
|
2446
|
-
let anchors = shapeDef?.getAnchors?.(shape) ?? {};
|
|
2447
|
-
if (shape.node) {
|
|
2448
|
-
const node = this._controller.graph.getNode(shape.node);
|
|
2449
|
-
if (node.inputSchema || node.outputSchema) {
|
|
2450
|
-
const inputSchema = node.inputSchema ? toEffectSchema(node.inputSchema) : DefaultInput;
|
|
2451
|
-
const outputSchema = node.outputSchema ? toEffectSchema(node.outputSchema) : DefaultOutput2;
|
|
2452
|
-
anchors = createFunctionAnchors(shape, inputSchema, outputSchema);
|
|
2453
|
-
}
|
|
2454
|
-
}
|
|
2455
|
-
return anchors;
|
|
2456
|
-
}
|
|
2457
|
-
};
|
|
2458
|
-
export {
|
|
2459
|
-
AndShape,
|
|
2460
|
-
AppendComponent,
|
|
2461
|
-
AppendShape,
|
|
2462
|
-
AudioComponent,
|
|
2463
|
-
AudioShape,
|
|
2464
|
-
BeaconComponent,
|
|
2465
|
-
BeaconShape,
|
|
2466
|
-
Box,
|
|
2467
|
-
ChatShape,
|
|
2468
|
-
ComputeContext,
|
|
2469
|
-
ComputeGraphController,
|
|
2470
|
-
ComputeShape,
|
|
2471
|
-
ComputeShapeLayout,
|
|
2472
|
-
ConstantComponent,
|
|
2473
|
-
ConstantShape,
|
|
2474
|
-
DatabaseComponent,
|
|
2475
|
-
DatabaseShape,
|
|
2476
|
-
FeedComponent,
|
|
2477
|
-
FeedItem,
|
|
2478
|
-
FeedShape,
|
|
2479
|
-
FunctionBody,
|
|
2480
|
-
FunctionShape,
|
|
2481
|
-
GptComponent,
|
|
2482
|
-
GptRealtimeComponent,
|
|
2483
|
-
GptRealtimeShape,
|
|
2484
|
-
GptShape,
|
|
2485
|
-
IfComponent,
|
|
2486
|
-
IfElseComponent,
|
|
2487
|
-
IfElseShape,
|
|
2488
|
-
IfShape,
|
|
2489
|
-
InvalidStateError,
|
|
2490
|
-
JsonComponent,
|
|
2491
|
-
JsonShape,
|
|
2492
|
-
JsonTransformComponent,
|
|
2493
|
-
JsonTransformShape,
|
|
2494
|
-
NotShape,
|
|
2495
|
-
OrShape,
|
|
2496
|
-
RandomComponent,
|
|
2497
|
-
RandomShape,
|
|
2498
|
-
ReducerComponent,
|
|
2499
|
-
ReducerShape,
|
|
2500
|
-
ScopeComponent,
|
|
2501
|
-
ScopeShape,
|
|
2502
|
-
SurfaceComponent,
|
|
2503
|
-
SurfaceShape,
|
|
2504
|
-
SwitchComponent,
|
|
2505
|
-
SwitchShape,
|
|
2506
|
-
TableComponent,
|
|
2507
|
-
TableShape,
|
|
2508
|
-
TemplateShape,
|
|
2509
|
-
TextComponent,
|
|
2510
|
-
TextInputComponent,
|
|
2511
|
-
TextShape,
|
|
2512
|
-
TextToImageComponent,
|
|
2513
|
-
TextToImageShape,
|
|
2514
|
-
ThreadComponent,
|
|
2515
|
-
ThreadItem,
|
|
2516
|
-
ThreadShape,
|
|
2517
|
-
TriggerComponent,
|
|
2518
|
-
TriggerShape,
|
|
2519
|
-
TypeSelect,
|
|
2520
|
-
andShape,
|
|
2521
|
-
appendShape,
|
|
2522
|
-
audioShape,
|
|
2523
|
-
beaconShape,
|
|
2524
|
-
chatShape,
|
|
2525
|
-
computeShapes,
|
|
2526
|
-
constantShape,
|
|
2527
|
-
createAnchorId,
|
|
2528
|
-
createAnd,
|
|
2529
|
-
createAppend,
|
|
2530
|
-
createAudio,
|
|
2531
|
-
createBeacon,
|
|
2532
|
-
createChat,
|
|
2533
|
-
createComputeGraph,
|
|
2534
|
-
createComputeGraphController,
|
|
2535
|
-
createComputeNode,
|
|
2536
|
-
createConstant,
|
|
2537
|
-
createDatabase,
|
|
2538
|
-
createFeed,
|
|
2539
|
-
createFunction,
|
|
2540
|
-
createFunctionAnchors,
|
|
2541
|
-
createGpt,
|
|
2542
|
-
createGptRealtime,
|
|
2543
|
-
createIf,
|
|
2544
|
-
createIfElse,
|
|
2545
|
-
createJson,
|
|
2546
|
-
createJsonTransform,
|
|
2547
|
-
createNot,
|
|
2548
|
-
createOr,
|
|
2549
|
-
createRandom,
|
|
2550
|
-
createReducer,
|
|
2551
|
-
createScope,
|
|
2552
|
-
createShape,
|
|
2553
|
-
createSurface,
|
|
2554
|
-
createSwitch,
|
|
2555
|
-
createTable,
|
|
2556
|
-
createTemplate,
|
|
2557
|
-
createText,
|
|
2558
|
-
createTextToImage,
|
|
2559
|
-
createThread,
|
|
2560
|
-
createTrigger,
|
|
2561
|
-
databaseShape,
|
|
2562
|
-
feedShape,
|
|
2563
|
-
footerHeight,
|
|
2564
|
-
functionShape,
|
|
2565
|
-
getHeight,
|
|
2566
|
-
getProperties,
|
|
2567
|
-
gptRealtimeShape,
|
|
2568
|
-
gptShape,
|
|
2569
|
-
headerHeight,
|
|
2570
|
-
ifElseShape,
|
|
2571
|
-
ifShape,
|
|
2572
|
-
isValidComputeNode,
|
|
2573
|
-
jsonShape,
|
|
2574
|
-
jsonTransformShape,
|
|
2575
|
-
mapEdge,
|
|
2576
|
-
notShape,
|
|
2577
|
-
orShape,
|
|
2578
|
-
parseAnchorId,
|
|
2579
|
-
randomShape,
|
|
2580
|
-
reducerShape,
|
|
2581
|
-
resolveComputeNode,
|
|
2582
|
-
scopeShape,
|
|
2583
|
-
surfaceShape,
|
|
2584
|
-
switchShape,
|
|
2585
|
-
tableShape,
|
|
2586
|
-
templateShape,
|
|
2587
|
-
textShape,
|
|
2588
|
-
textToImageShape,
|
|
2589
|
-
threadShape,
|
|
2590
|
-
triggerShape,
|
|
2591
|
-
useComputeContext,
|
|
2592
|
-
useComputeGraphController,
|
|
2593
|
-
useComputeNodeState,
|
|
2594
|
-
useGraphMonitor
|
|
2595
|
-
};
|
|
2596
|
-
//# sourceMappingURL=index.mjs.map
|