@dxos/react-ui-canvas-compute 0.8.3 → 0.8.4-main.f9ba587

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