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