@dxos/react-ui-canvas-compute 0.8.4-main.406dc2a → 0.8.4-main.43cb759274

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