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