@dxos/react-ui-canvas-compute 0.7.5-labs.5f04cf6

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