@dxos/react-ui-canvas-compute 0.9.1-staging.ee54ba693a → 0.11.0
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/index.mjs +2164 -0
- package/dist/lib/index.mjs.map +1 -0
- package/dist/types/src/compute.stories.d.ts.map +1 -1
- package/dist/types/src/shapes/Append.d.ts +2 -51
- package/dist/types/src/shapes/Append.d.ts.map +1 -1
- package/dist/types/src/shapes/Array.d.ts +2 -34
- package/dist/types/src/shapes/Array.d.ts.map +1 -1
- package/dist/types/src/shapes/Audio.d.ts +2 -51
- package/dist/types/src/shapes/Audio.d.ts.map +1 -1
- package/dist/types/src/shapes/Beacon.d.ts +2 -51
- package/dist/types/src/shapes/Beacon.d.ts.map +1 -1
- package/dist/types/src/shapes/Chat.d.ts +2 -51
- package/dist/types/src/shapes/Chat.d.ts.map +1 -1
- package/dist/types/src/shapes/Constant.d.ts +2 -53
- package/dist/types/src/shapes/Constant.d.ts.map +1 -1
- package/dist/types/src/shapes/Database.d.ts +2 -51
- package/dist/types/src/shapes/Database.d.ts.map +1 -1
- package/dist/types/src/shapes/Feed.d.ts +2 -51
- package/dist/types/src/shapes/Feed.d.ts.map +1 -1
- package/dist/types/src/shapes/Function.d.ts +7 -50
- package/dist/types/src/shapes/Function.d.ts.map +1 -1
- package/dist/types/src/shapes/Gpt.d.ts +2 -51
- package/dist/types/src/shapes/Gpt.d.ts.map +1 -1
- package/dist/types/src/shapes/GptRealtime.d.ts +2 -51
- package/dist/types/src/shapes/GptRealtime.d.ts.map +1 -1
- package/dist/types/src/shapes/Json.d.ts +2 -101
- package/dist/types/src/shapes/Json.d.ts.map +1 -1
- package/dist/types/src/shapes/Logic.d.ts +2 -103
- package/dist/types/src/shapes/Logic.d.ts.map +1 -1
- package/dist/types/src/shapes/RNG.d.ts +2 -55
- package/dist/types/src/shapes/RNG.d.ts.map +1 -1
- package/dist/types/src/shapes/Scope.d.ts +2 -51
- package/dist/types/src/shapes/Scope.d.ts.map +1 -1
- package/dist/types/src/shapes/Surface.d.ts +2 -51
- package/dist/types/src/shapes/Surface.d.ts.map +1 -1
- package/dist/types/src/shapes/Switch.d.ts +2 -51
- package/dist/types/src/shapes/Switch.d.ts.map +1 -1
- package/dist/types/src/shapes/Table.d.ts +2 -51
- package/dist/types/src/shapes/Table.d.ts.map +1 -1
- package/dist/types/src/shapes/Template.d.ts +4 -55
- package/dist/types/src/shapes/Template.d.ts.map +1 -1
- package/dist/types/src/shapes/Text.d.ts +2 -51
- package/dist/types/src/shapes/Text.d.ts.map +1 -1
- package/dist/types/src/shapes/TextToImage.d.ts +2 -51
- package/dist/types/src/shapes/TextToImage.d.ts.map +1 -1
- package/dist/types/src/shapes/Thread.d.ts +2 -51
- package/dist/types/src/shapes/Thread.d.ts.map +1 -1
- package/dist/types/src/shapes/Trigger.d.ts +2 -17
- package/dist/types/src/shapes/Trigger.d.ts.map +1 -1
- package/dist/types/src/shapes/append-def.d.ts +52 -0
- package/dist/types/src/shapes/append-def.d.ts.map +1 -0
- package/dist/types/src/shapes/array-def.d.ts +35 -0
- package/dist/types/src/shapes/array-def.d.ts.map +1 -0
- package/dist/types/src/shapes/audio-def.d.ts +52 -0
- package/dist/types/src/shapes/audio-def.d.ts.map +1 -0
- package/dist/types/src/shapes/beacon-def.d.ts +52 -0
- package/dist/types/src/shapes/beacon-def.d.ts.map +1 -0
- package/dist/types/src/shapes/chat-def.d.ts +52 -0
- package/dist/types/src/shapes/chat-def.d.ts.map +1 -0
- package/dist/types/src/shapes/common/Box.d.ts +0 -2
- package/dist/types/src/shapes/common/Box.d.ts.map +1 -1
- package/dist/types/src/shapes/common/FunctionBody.d.ts +1 -3
- package/dist/types/src/shapes/common/FunctionBody.d.ts.map +1 -1
- package/dist/types/src/shapes/common/box-defs.d.ts +3 -0
- package/dist/types/src/shapes/common/box-defs.d.ts.map +1 -0
- package/dist/types/src/shapes/common/function-anchors.d.ts +7 -0
- package/dist/types/src/shapes/common/function-anchors.d.ts.map +1 -0
- package/dist/types/src/shapes/common/index.d.ts +2 -0
- package/dist/types/src/shapes/common/index.d.ts.map +1 -1
- package/dist/types/src/shapes/constant-def.d.ts +54 -0
- package/dist/types/src/shapes/constant-def.d.ts.map +1 -0
- package/dist/types/src/shapes/database-def.d.ts +52 -0
- package/dist/types/src/shapes/database-def.d.ts.map +1 -0
- package/dist/types/src/shapes/feed-def.d.ts +52 -0
- package/dist/types/src/shapes/feed-def.d.ts.map +1 -0
- package/dist/types/src/shapes/function-def.d.ts +52 -0
- package/dist/types/src/shapes/function-def.d.ts.map +1 -0
- package/dist/types/src/shapes/gpt-def.d.ts +52 -0
- package/dist/types/src/shapes/gpt-def.d.ts.map +1 -0
- package/dist/types/src/shapes/gpt-realtime-def.d.ts +52 -0
- package/dist/types/src/shapes/gpt-realtime-def.d.ts.map +1 -0
- package/dist/types/src/shapes/index.d.ts +23 -0
- package/dist/types/src/shapes/index.d.ts.map +1 -1
- package/dist/types/src/shapes/json-def.d.ts +102 -0
- package/dist/types/src/shapes/json-def.d.ts.map +1 -0
- package/dist/types/src/shapes/logic-def.d.ts +104 -0
- package/dist/types/src/shapes/logic-def.d.ts.map +1 -0
- package/dist/types/src/shapes/rng-def.d.ts +56 -0
- package/dist/types/src/shapes/rng-def.d.ts.map +1 -0
- package/dist/types/src/shapes/scope-def.d.ts +52 -0
- package/dist/types/src/shapes/scope-def.d.ts.map +1 -0
- package/dist/types/src/shapes/surface-def.d.ts +52 -0
- package/dist/types/src/shapes/surface-def.d.ts.map +1 -0
- package/dist/types/src/shapes/switch-def.d.ts +52 -0
- package/dist/types/src/shapes/switch-def.d.ts.map +1 -0
- package/dist/types/src/shapes/table-def.d.ts +52 -0
- package/dist/types/src/shapes/table-def.d.ts.map +1 -0
- package/dist/types/src/shapes/template-def.d.ts +56 -0
- package/dist/types/src/shapes/template-def.d.ts.map +1 -0
- package/dist/types/src/shapes/text-def.d.ts +52 -0
- package/dist/types/src/shapes/text-def.d.ts.map +1 -0
- package/dist/types/src/shapes/text-to-image-def.d.ts +52 -0
- package/dist/types/src/shapes/text-to-image-def.d.ts.map +1 -0
- package/dist/types/src/shapes/thread-def.d.ts +52 -0
- package/dist/types/src/shapes/thread-def.d.ts.map +1 -0
- package/dist/types/src/shapes/trigger-def.d.ts +18 -0
- package/dist/types/src/shapes/trigger-def.d.ts.map +1 -0
- package/dist/types/src/shapes/trigger-spec.d.ts +9 -0
- package/dist/types/src/shapes/trigger-spec.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +43 -46
- package/src/compute.stories.tsx +1 -1
- package/src/shapes/Append.tsx +3 -31
- package/src/shapes/Array.tsx +3 -43
- package/src/shapes/Audio.tsx +2 -26
- package/src/shapes/Beacon.tsx +2 -29
- package/src/shapes/Chat.tsx +1 -36
- package/src/shapes/Constant.tsx +1 -37
- package/src/shapes/Database.tsx +2 -27
- package/src/shapes/Feed.tsx +4 -35
- package/src/shapes/Function.tsx +4 -38
- package/src/shapes/Gpt.tsx +3 -33
- package/src/shapes/GptRealtime.tsx +2 -36
- package/src/shapes/Json.tsx +4 -70
- package/src/shapes/Logic.tsx +3 -58
- package/src/shapes/RNG.tsx +2 -32
- package/src/shapes/Scope.tsx +2 -31
- package/src/shapes/Surface.tsx +2 -32
- package/src/shapes/Switch.tsx +2 -26
- package/src/shapes/Table.tsx +3 -34
- package/src/shapes/Template.tsx +6 -36
- package/src/shapes/Text.tsx +2 -28
- package/src/shapes/TextToImage.tsx +2 -27
- package/src/shapes/Thread.tsx +3 -34
- package/src/shapes/Trigger.tsx +6 -79
- package/src/shapes/append-def.ts +42 -0
- package/src/shapes/array-def.ts +54 -0
- package/src/shapes/audio-def.ts +36 -0
- package/src/shapes/beacon-def.ts +39 -0
- package/src/shapes/chat-def.tsx +47 -0
- package/src/shapes/common/Box.tsx +2 -5
- package/src/shapes/common/FunctionBody.tsx +6 -25
- package/src/shapes/common/box-defs.ts +10 -0
- package/src/shapes/common/function-anchors.ts +37 -0
- package/src/shapes/common/index.ts +3 -0
- package/src/shapes/constant-def.tsx +48 -0
- package/src/shapes/database-def.ts +37 -0
- package/src/shapes/feed-def.ts +44 -0
- package/src/shapes/function-def.ts +46 -0
- package/src/shapes/gpt-def.ts +43 -0
- package/src/shapes/gpt-realtime-def.ts +46 -0
- package/src/shapes/index.ts +25 -0
- package/src/shapes/json-def.ts +80 -0
- package/src/shapes/logic-def.ts +69 -0
- package/src/shapes/rng-def.ts +42 -0
- package/src/shapes/scope-def.ts +41 -0
- package/src/shapes/surface-def.ts +42 -0
- package/src/shapes/switch-def.ts +36 -0
- package/src/shapes/table-def.ts +45 -0
- package/src/shapes/template-def.ts +48 -0
- package/src/shapes/text-def.ts +38 -0
- package/src/shapes/text-to-image-def.ts +37 -0
- package/src/shapes/thread-def.ts +45 -0
- package/src/shapes/trigger-def.ts +63 -0
- package/src/shapes/trigger-spec.ts +44 -0
- package/dist/lib/browser/index.mjs +0 -2596
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/node-esm/index.mjs +0 -2596
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
|
@@ -0,0 +1,2164 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Either from "effect/Either";
|
|
3
|
+
import * as Exit from "effect/Exit";
|
|
4
|
+
import * as Layer from "effect/Layer";
|
|
5
|
+
import * as Scope from "effect/Scope";
|
|
6
|
+
import { Event, synchronized } from "@dxos/async";
|
|
7
|
+
import { Operation, Script, Trace, Trigger, TriggerEvent } from "@dxos/compute";
|
|
8
|
+
import { AnyOutput, AppendInput, ComputeBeginEvent, ComputeCustomEvent, ComputeEndEvent, ComputeGraphModel, ComputeInputEvent, ComputeNodeContext, ComputeOutputEvent, ComputeValueType, DEFAULT_INPUT, DEFAULT_OUTPUT, DefaultInput, DefaultOutput, FunctionInput, GptInput, GptOutput, GraphExecutor, IfElseInput, IfElseOutput, IfInput, IfOutput, JsonTransformInput, NODE_INPUT, NODE_OUTPUT, QueueInput, QueueOutput, ReducerInput, ReducerOutput, TemplateOutput, ValueBag, VoidInput, VoidOutput, createInputSchema, createOutputSchema, getTemplateInputSchema, isNotExecuted, isTruthy, registry } from "@dxos/conductor";
|
|
9
|
+
import { Resource } from "@dxos/context";
|
|
10
|
+
import { EffectEx } from "@dxos/effect";
|
|
11
|
+
import { log } from "@dxos/log";
|
|
12
|
+
import { Fragment, createContext, forwardRef, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
13
|
+
import { raise } from "@dxos/debug";
|
|
14
|
+
import * as Schema from "effect/Schema";
|
|
15
|
+
import { invariant } from "@dxos/invariant";
|
|
16
|
+
import { Filter, JsonSchema, Obj, Query, Ref, Type } from "@dxos/echo";
|
|
17
|
+
import { isNonNullable, safeParseJson } from "@dxos/util";
|
|
18
|
+
import { Polygon, ShapeLayout, TextBox, createAnchorMap, createAnchors, getAnchorPoints, getParentShapeElement, noteShape, rowHeight, useEditorContext, useShapeDef } from "@dxos/react-ui-canvas-editor";
|
|
19
|
+
import * as SchemaAST from "effect/SchemaAST";
|
|
20
|
+
import { Card, Icon, IconButton, Input, ScrollArea, Select } from "@dxos/react-ui";
|
|
21
|
+
import { mx } from "@dxos/ui-theme";
|
|
22
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
23
|
+
import { useCanvasContext } from "@dxos/react-ui-canvas";
|
|
24
|
+
import { instanceOf } from "@dxos/echo/Obj";
|
|
25
|
+
import { parseId } from "@dxos/keys";
|
|
26
|
+
import { useClient, useConfig } from "@dxos/react-client";
|
|
27
|
+
import { Syntax } from "@dxos/react-ui-syntax-highlighter";
|
|
28
|
+
import { useAudioStream } from "@dxos/react-ui-audio";
|
|
29
|
+
import { Chaos, shaderPresets } from "@dxos/react-ui-experimental";
|
|
30
|
+
import { Surface } from "@dxos/app-framework/ui";
|
|
31
|
+
import { AppSurface } from "@dxos/app-toolkit/ui";
|
|
32
|
+
import { Message } from "@dxos/types";
|
|
33
|
+
import { toEffectSchema, toJsonSchema } from "@dxos/echo/JsonSchema";
|
|
34
|
+
import { useSpaces } from "@dxos/react-client/echo";
|
|
35
|
+
//#region src/hooks/compute-context.ts
|
|
36
|
+
var ComputeContext = createContext(null);
|
|
37
|
+
var useComputeContext = () => {
|
|
38
|
+
return useContext(ComputeContext) ?? raise(/* @__PURE__ */ new Error("Missing ComputeContext"));
|
|
39
|
+
};
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/hooks/useComputeGraphController.ts
|
|
42
|
+
var combine = (...cbs) => {
|
|
43
|
+
return () => {
|
|
44
|
+
for (const cb of cbs) cb();
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
var useComputeGraphController = ({ controller, graph, editorRef }) => {
|
|
48
|
+
const [, forceUpdate] = useState({});
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (!controller || !graph) return;
|
|
51
|
+
controller.open();
|
|
52
|
+
const off = combine(controller.update.on(() => {
|
|
53
|
+
editorRef.current?.update();
|
|
54
|
+
forceUpdate({});
|
|
55
|
+
}), controller.output.on(({ nodeId, property, value }) => {
|
|
56
|
+
if (value.type === "not-executed") return;
|
|
57
|
+
const edge = graph.edges.find((edge) => {
|
|
58
|
+
return graph.getNode(edge.source).node === nodeId && edge.output === property;
|
|
59
|
+
});
|
|
60
|
+
if (edge) editorRef.current?.action?.({
|
|
61
|
+
type: "trigger",
|
|
62
|
+
edges: [edge]
|
|
63
|
+
});
|
|
64
|
+
}));
|
|
65
|
+
return () => {
|
|
66
|
+
controller.close();
|
|
67
|
+
off();
|
|
68
|
+
};
|
|
69
|
+
}, [graph, controller]);
|
|
70
|
+
};
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/hooks/useComputeNodeState.ts
|
|
73
|
+
var __dxlog_file$6 = "/__w/dxos/dxos/packages/ui/react-ui-canvas-compute/src/hooks/useComputeNodeState.ts";
|
|
74
|
+
/**
|
|
75
|
+
* Runtime state of a compute node.
|
|
76
|
+
*/
|
|
77
|
+
var useComputeNodeState = (shape) => {
|
|
78
|
+
const { controller } = useComputeContext();
|
|
79
|
+
invariant(controller, void 0, {
|
|
80
|
+
"~LogMeta": "~LogMeta",
|
|
81
|
+
F: __dxlog_file$6,
|
|
82
|
+
L: 32,
|
|
83
|
+
S: void 0,
|
|
84
|
+
A: ["controller", ""]
|
|
85
|
+
});
|
|
86
|
+
const [meta, setMeta] = useState();
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
let disposed = false;
|
|
89
|
+
queueMicrotask(async () => {
|
|
90
|
+
invariant(shape.node, "Node not specified", {
|
|
91
|
+
"~LogMeta": "~LogMeta",
|
|
92
|
+
F: __dxlog_file$6,
|
|
93
|
+
L: 38,
|
|
94
|
+
S: void 0,
|
|
95
|
+
A: ["shape.node", "'Node not specified'"]
|
|
96
|
+
});
|
|
97
|
+
const node = controller.getComputeNode(shape.node);
|
|
98
|
+
const meta = await controller.getMeta(node);
|
|
99
|
+
if (disposed) return;
|
|
100
|
+
setMeta(meta);
|
|
101
|
+
});
|
|
102
|
+
return () => {
|
|
103
|
+
disposed = true;
|
|
104
|
+
};
|
|
105
|
+
}, [shape.node]);
|
|
106
|
+
const evalNode = useCallback(() => {
|
|
107
|
+
return controller.evalNode(shape.node);
|
|
108
|
+
}, [shape.node]);
|
|
109
|
+
const subscribeToEventLog = useCallback((cb) => {
|
|
110
|
+
return controller.events.on((ev) => {
|
|
111
|
+
if (ev.nodeId === shape.node) cb(ev);
|
|
112
|
+
});
|
|
113
|
+
}, [shape.node]);
|
|
114
|
+
return {
|
|
115
|
+
node: controller.getComputeNode(shape.node),
|
|
116
|
+
meta: meta ?? {
|
|
117
|
+
input: Schema.Struct({}),
|
|
118
|
+
output: Schema.Struct({})
|
|
119
|
+
},
|
|
120
|
+
runtime: {
|
|
121
|
+
inputs: controller.getInputs(shape.node),
|
|
122
|
+
outputs: controller.getOutputs(shape.node),
|
|
123
|
+
setOutput: (property, value) => {
|
|
124
|
+
controller.setOutput(shape.node, property, value);
|
|
125
|
+
},
|
|
126
|
+
evalNode,
|
|
127
|
+
subscribeToEventLog
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/hooks/useGraphMonitor.ts
|
|
133
|
+
var __dxlog_file$5 = "/__w/dxos/dxos/packages/ui/react-ui-canvas-compute/src/hooks/useGraphMonitor.ts";
|
|
134
|
+
/**
|
|
135
|
+
* Map canvas edge to compute edge.
|
|
136
|
+
*/
|
|
137
|
+
var mapEdge = (graph, { source, target, output = DEFAULT_OUTPUT, input = DEFAULT_INPUT }) => {
|
|
138
|
+
const sourceNode = graph.findNode(source);
|
|
139
|
+
const targetNode = graph.findNode(target);
|
|
140
|
+
invariant(sourceNode?.node, void 0, {
|
|
141
|
+
"~LogMeta": "~LogMeta",
|
|
142
|
+
F: __dxlog_file$5,
|
|
143
|
+
L: 25,
|
|
144
|
+
S: void 0,
|
|
145
|
+
A: ["sourceNode?.node", ""]
|
|
146
|
+
});
|
|
147
|
+
invariant(targetNode?.node, void 0, {
|
|
148
|
+
"~LogMeta": "~LogMeta",
|
|
149
|
+
F: __dxlog_file$5,
|
|
150
|
+
L: 26,
|
|
151
|
+
S: void 0,
|
|
152
|
+
A: ["targetNode?.node", ""]
|
|
153
|
+
});
|
|
154
|
+
return {
|
|
155
|
+
id: Obj.ID.random(),
|
|
156
|
+
source: sourceNode.node,
|
|
157
|
+
target: targetNode.node,
|
|
158
|
+
output,
|
|
159
|
+
input
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* Listens for changes to the graph and updates the compute graph.
|
|
164
|
+
* @param model Compute graph to update on change.
|
|
165
|
+
*/
|
|
166
|
+
var useGraphMonitor = (model) => {
|
|
167
|
+
return useMemo(() => {
|
|
168
|
+
return {
|
|
169
|
+
onCreate: ({ node }) => {
|
|
170
|
+
if (!model) return;
|
|
171
|
+
invariant(node.type, void 0, {
|
|
172
|
+
"~LogMeta": "~LogMeta",
|
|
173
|
+
F: __dxlog_file$5,
|
|
174
|
+
L: 51,
|
|
175
|
+
S: void 0,
|
|
176
|
+
A: ["node.type", ""]
|
|
177
|
+
});
|
|
178
|
+
if (!isValidComputeNode(node.type)) return;
|
|
179
|
+
const computeNode = createComputeNode(node);
|
|
180
|
+
if (node.type === "trigger") linkTriggerToCompute(model, computeNode, node);
|
|
181
|
+
model.addNode(computeNode);
|
|
182
|
+
node.node = computeNode.id;
|
|
183
|
+
},
|
|
184
|
+
onLink: ({ graph, edge }) => {
|
|
185
|
+
if (model) model.addEdge(mapEdge(graph, edge));
|
|
186
|
+
},
|
|
187
|
+
onDelete: ({ subgraph }) => {
|
|
188
|
+
if (model) {
|
|
189
|
+
const nodeIds = subgraph.nodes.map((shape) => shape.node);
|
|
190
|
+
const edgeIds = subgraph.edges.map(({ source, target, output = DEFAULT_OUTPUT, input = DEFAULT_INPUT }) => {
|
|
191
|
+
return model.edges.find((computeEdge) => computeEdge.input === input && computeEdge.output === output)?.id;
|
|
192
|
+
}).filter(isNonNullable);
|
|
193
|
+
model.removeNodes(nodeIds);
|
|
194
|
+
model.removeEdges(edgeIds);
|
|
195
|
+
deleteTriggerObjects(model, subgraph);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
}, [model]);
|
|
200
|
+
};
|
|
201
|
+
var createComputeGraph = (graph) => {
|
|
202
|
+
const computeGraph = ComputeGraphModel.create();
|
|
203
|
+
if (graph) {
|
|
204
|
+
for (const shape of graph.nodes) if (isValidComputeNode(shape.type)) {
|
|
205
|
+
const node = createComputeNode(shape);
|
|
206
|
+
computeGraph.addNode(node);
|
|
207
|
+
shape.node = node.id;
|
|
208
|
+
}
|
|
209
|
+
for (const edge of graph.edges) computeGraph.addEdge(mapEdge(graph, edge));
|
|
210
|
+
}
|
|
211
|
+
return computeGraph;
|
|
212
|
+
};
|
|
213
|
+
var linkTriggerToCompute = (graph, computeNode, triggerData) => {
|
|
214
|
+
const functionTrigger = triggerData.functionTrigger?.target;
|
|
215
|
+
invariant(functionTrigger, void 0, {
|
|
216
|
+
"~LogMeta": "~LogMeta",
|
|
217
|
+
F: __dxlog_file$5,
|
|
218
|
+
L: 114,
|
|
219
|
+
S: void 0,
|
|
220
|
+
A: ["functionTrigger", ""]
|
|
221
|
+
});
|
|
222
|
+
Obj.update(functionTrigger, (functionTrigger) => {
|
|
223
|
+
functionTrigger.runnable = Ref.make(graph.root);
|
|
224
|
+
functionTrigger.inputNodeId = computeNode.id;
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
var deleteTriggerObjects = (computeGraph, deleted) => {
|
|
228
|
+
const db = Obj.getDatabase(computeGraph.root);
|
|
229
|
+
if (!db) return;
|
|
230
|
+
for (const node of deleted.nodes) if (node.type === "trigger") {
|
|
231
|
+
const trigger = node;
|
|
232
|
+
db.remove(trigger.functionTrigger.target);
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/graph/node-defs.ts
|
|
237
|
+
var __dxlog_file$4 = "/__w/dxos/dxos/packages/ui/react-ui-canvas-compute/src/graph/node-defs.ts";
|
|
238
|
+
var resolveComputeNode = async (node) => {
|
|
239
|
+
const impl = registry[node.type];
|
|
240
|
+
invariant(impl, `Unknown node type: ${node.type}`, {
|
|
241
|
+
"~LogMeta": "~LogMeta",
|
|
242
|
+
F: __dxlog_file$4,
|
|
243
|
+
L: 22,
|
|
244
|
+
S: void 0,
|
|
245
|
+
A: ["impl", "`Unknown node type: ${node.type}`"]
|
|
246
|
+
});
|
|
247
|
+
return impl;
|
|
248
|
+
};
|
|
249
|
+
var isValidComputeNode = (type) => {
|
|
250
|
+
return nodeFactory[type] !== void 0;
|
|
251
|
+
};
|
|
252
|
+
var createComputeNode = (shape) => {
|
|
253
|
+
const type = shape.type ?? raise(/* @__PURE__ */ new Error("Type not specified"));
|
|
254
|
+
return (nodeFactory[type] ?? raise(/* @__PURE__ */ new Error(`Unknown shape type: ${type}`)))(shape);
|
|
255
|
+
};
|
|
256
|
+
var nodeFactory = {
|
|
257
|
+
[NODE_INPUT]: () => createNode(NODE_INPUT),
|
|
258
|
+
[NODE_OUTPUT]: () => createNode(NODE_OUTPUT),
|
|
259
|
+
"text-to-image": () => createNode("text-to-image"),
|
|
260
|
+
"and": () => createNode("and"),
|
|
261
|
+
"append": () => createNode("append"),
|
|
262
|
+
"audio": () => createNode("audio"),
|
|
263
|
+
"beacon": () => createNode("beacon"),
|
|
264
|
+
"chat": () => createNode("chat"),
|
|
265
|
+
"constant": (shape) => createNode("constant", { value: shape.value }),
|
|
266
|
+
"make-queue": () => createNode("make-queue"),
|
|
267
|
+
"database": () => createNode("database"),
|
|
268
|
+
"gpt": () => createNode("gpt"),
|
|
269
|
+
"gpt-realtime": () => createNode("gpt-realtime"),
|
|
270
|
+
"if": () => createNode("if"),
|
|
271
|
+
"if-else": () => createNode("if-else"),
|
|
272
|
+
"function": () => createNode("function"),
|
|
273
|
+
"json": () => createNode("json"),
|
|
274
|
+
"json-transform": () => createNode("json-transform"),
|
|
275
|
+
"not": () => createNode("not"),
|
|
276
|
+
"or": () => createNode("or"),
|
|
277
|
+
"queue": () => createNode("queue"),
|
|
278
|
+
"rng": () => createNode("rng"),
|
|
279
|
+
"reducer": () => createNode("reducer"),
|
|
280
|
+
"scope": () => createNode("scope"),
|
|
281
|
+
"surface": () => createNode("surface"),
|
|
282
|
+
"switch": () => createNode("switch"),
|
|
283
|
+
"template": (shape) => {
|
|
284
|
+
const node = createNode("template", {
|
|
285
|
+
valueType: shape.valueType,
|
|
286
|
+
value: shape.text
|
|
287
|
+
});
|
|
288
|
+
node.inputSchema = structuredClone(JsonSchema.toJsonSchema(getTemplateInputSchema(node)));
|
|
289
|
+
return node;
|
|
290
|
+
},
|
|
291
|
+
"text": () => createNode("text"),
|
|
292
|
+
"thread": () => createNode("thread"),
|
|
293
|
+
"trigger": () => createNode(NODE_INPUT)
|
|
294
|
+
};
|
|
295
|
+
var createNode = (type, props) => ({
|
|
296
|
+
id: Obj.ID.random(),
|
|
297
|
+
type,
|
|
298
|
+
...props
|
|
299
|
+
});
|
|
300
|
+
//#endregion
|
|
301
|
+
//#region \0@oxc-project+runtime@0.139.0/helpers/esm/decorate.js
|
|
302
|
+
function __decorate(decorators, target, key, desc) {
|
|
303
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
304
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
305
|
+
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;
|
|
306
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
307
|
+
}
|
|
308
|
+
//#endregion
|
|
309
|
+
//#region src/graph/controller.ts
|
|
310
|
+
var __dxlog_file$3 = "/__w/dxos/dxos/packages/ui/react-ui-canvas-compute/src/graph/controller.ts";
|
|
311
|
+
var InvalidStateError = Error;
|
|
312
|
+
/**
|
|
313
|
+
* Nodes that will automatically trigger the execution of the graph on startup.
|
|
314
|
+
*/
|
|
315
|
+
var AUTO_TRIGGER_NODES = [
|
|
316
|
+
"chat",
|
|
317
|
+
"switch",
|
|
318
|
+
"constant"
|
|
319
|
+
];
|
|
320
|
+
var createComputeGraphController = (graph, computeRuntime) => {
|
|
321
|
+
return {
|
|
322
|
+
controller: new ComputeGraphController(computeRuntime, createComputeGraph(graph)),
|
|
323
|
+
graph
|
|
324
|
+
};
|
|
325
|
+
};
|
|
326
|
+
/**
|
|
327
|
+
* Controller that manages compute graph state, execution, and service coordination.
|
|
328
|
+
*/
|
|
329
|
+
var ComputeGraphController = class extends Resource {
|
|
330
|
+
_computeRuntime;
|
|
331
|
+
_graph;
|
|
332
|
+
_executor = new GraphExecutor({ computeNodeResolver: (node) => resolveComputeNode(node) });
|
|
333
|
+
_diagnostics = [];
|
|
334
|
+
/**
|
|
335
|
+
* Canvas force-sets outputs of those nodes.
|
|
336
|
+
*/
|
|
337
|
+
_forcedOutputs = {};
|
|
338
|
+
/**
|
|
339
|
+
* Runtime state of the execution graph.
|
|
340
|
+
*/
|
|
341
|
+
_runtimeStateInputs = {};
|
|
342
|
+
_runtimeStateOutputs = {};
|
|
343
|
+
update = new Event();
|
|
344
|
+
/** Computed result. */
|
|
345
|
+
output = new Event();
|
|
346
|
+
events = new Event();
|
|
347
|
+
constructor(_computeRuntime, _graph) {
|
|
348
|
+
super();
|
|
349
|
+
this._computeRuntime = _computeRuntime;
|
|
350
|
+
this._graph = _graph;
|
|
351
|
+
}
|
|
352
|
+
toJSON() {
|
|
353
|
+
return {
|
|
354
|
+
graph: this._graph,
|
|
355
|
+
state: {
|
|
356
|
+
inputs: this._runtimeStateInputs,
|
|
357
|
+
outputs: this._runtimeStateOutputs
|
|
358
|
+
},
|
|
359
|
+
forcedOutputs: this._forcedOutputs
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
get graph() {
|
|
363
|
+
return this._graph;
|
|
364
|
+
}
|
|
365
|
+
get diagnostics() {
|
|
366
|
+
return this._diagnostics;
|
|
367
|
+
}
|
|
368
|
+
get userState() {
|
|
369
|
+
return this._forcedOutputs;
|
|
370
|
+
}
|
|
371
|
+
get inputStates() {
|
|
372
|
+
return this._runtimeStateInputs;
|
|
373
|
+
}
|
|
374
|
+
get outputStates() {
|
|
375
|
+
return this._runtimeStateOutputs;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Inputs and outputs for all nodes.
|
|
379
|
+
*/
|
|
380
|
+
get state() {
|
|
381
|
+
const ids = [.../* @__PURE__ */ new Set([...Object.keys(this._runtimeStateInputs), ...Object.keys(this._runtimeStateOutputs)])];
|
|
382
|
+
return Object.fromEntries(ids.map((id) => [id, {
|
|
383
|
+
node: this._graph.getNode(id),
|
|
384
|
+
input: this._runtimeStateInputs[id],
|
|
385
|
+
output: this._runtimeStateOutputs[id]
|
|
386
|
+
}]));
|
|
387
|
+
}
|
|
388
|
+
addNode(node) {
|
|
389
|
+
this._graph.addNode(node);
|
|
390
|
+
}
|
|
391
|
+
addEdge(edge) {
|
|
392
|
+
this._graph.addEdge(edge);
|
|
393
|
+
}
|
|
394
|
+
getComputeNode(nodeId) {
|
|
395
|
+
return this._graph.getNode(nodeId);
|
|
396
|
+
}
|
|
397
|
+
getInputs(nodeId) {
|
|
398
|
+
return this._runtimeStateInputs[nodeId] ?? {};
|
|
399
|
+
}
|
|
400
|
+
getOutputs(nodeId) {
|
|
401
|
+
return this._runtimeStateOutputs[nodeId] ?? {};
|
|
402
|
+
}
|
|
403
|
+
setOutput(nodeId, property, value) {
|
|
404
|
+
this._forcedOutputs[nodeId] ??= {};
|
|
405
|
+
this._forcedOutputs[nodeId][property] = value;
|
|
406
|
+
queueMicrotask(async () => {
|
|
407
|
+
try {
|
|
408
|
+
await this.exec(nodeId);
|
|
409
|
+
} catch (err) {
|
|
410
|
+
log.catch(err, void 0, {
|
|
411
|
+
"~LogMeta": "~LogMeta",
|
|
412
|
+
F: __dxlog_file$3,
|
|
413
|
+
L: 245,
|
|
414
|
+
S: this
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
async getMeta(node) {
|
|
420
|
+
const { meta } = await resolveComputeNode(node);
|
|
421
|
+
return meta;
|
|
422
|
+
}
|
|
423
|
+
async checkGraph() {
|
|
424
|
+
const executor = this._executor.clone();
|
|
425
|
+
await executor.load(this._graph);
|
|
426
|
+
this._diagnostics = executor.getDiagnostics();
|
|
427
|
+
}
|
|
428
|
+
async evalNode(nodeId) {
|
|
429
|
+
const executor = this._executor.clone();
|
|
430
|
+
await executor.load(this._graph);
|
|
431
|
+
for (const [nodeId, outputs] of Object.entries(this._forcedOutputs)) executor.setOutputs(nodeId, Effect.succeed(ValueBag.make(outputs)));
|
|
432
|
+
EffectEx.unwrapExit(await this._computeRuntime.runPromiseExit(Effect.gen(this, function* () {
|
|
433
|
+
const scope = yield* Scope.make();
|
|
434
|
+
const computingOutputs = (yield* Effect.promise(() => resolveComputeNode(this._graph.getNode(nodeId)))).exec != null;
|
|
435
|
+
yield* (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) => {
|
|
436
|
+
for (const [key, value] of Object.entries(values)) if (computingOutputs) this._onOutputComputed(nodeId, key, value);
|
|
437
|
+
else this._onInputComputed(nodeId, key, value);
|
|
438
|
+
}));
|
|
439
|
+
yield* Scope.close(scope, Exit.void);
|
|
440
|
+
})));
|
|
441
|
+
this.update.emit();
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Executes the graph.
|
|
445
|
+
* @param startFromNode - Node to start from, otherwise all {@link AUTO_TRIGGER_NODES} are executed.
|
|
446
|
+
*/
|
|
447
|
+
async exec(startFromNode) {
|
|
448
|
+
this._runtimeStateInputs = {};
|
|
449
|
+
this._runtimeStateOutputs = {};
|
|
450
|
+
const executor = this._executor.clone();
|
|
451
|
+
await executor.load(this._graph);
|
|
452
|
+
for (const [nodeId, outputs] of Object.entries(this._forcedOutputs)) executor.setOutputs(nodeId, Effect.succeed(ValueBag.make(outputs)));
|
|
453
|
+
const triggerNodes = startFromNode != null ? [this._graph.getNode(startFromNode)] : this._graph.nodes.filter((node) => node.type != null && AUTO_TRIGGER_NODES.includes(node.type));
|
|
454
|
+
const allAffectedNodes = [...new Set(triggerNodes.flatMap((node) => executor.getAllDependantNodes(node.id)))];
|
|
455
|
+
EffectEx.unwrapExit(await this._computeRuntime.runPromiseExit(Effect.gen(this, function* () {
|
|
456
|
+
const scope = yield* Scope.make();
|
|
457
|
+
const tasks = [];
|
|
458
|
+
for (const node of allAffectedNodes) {
|
|
459
|
+
const computingOutputs = (yield* Effect.promise(() => resolveComputeNode(this._graph.getNode(node)))).exec != null;
|
|
460
|
+
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) => {
|
|
461
|
+
for (const [key, value] of Object.entries(values)) if (computingOutputs) this._onOutputComputed(node, key, value);
|
|
462
|
+
else this._onInputComputed(node, key, value);
|
|
463
|
+
}));
|
|
464
|
+
tasks.push(effect);
|
|
465
|
+
}
|
|
466
|
+
yield* Effect.all(tasks);
|
|
467
|
+
yield* Scope.close(scope, Exit.void);
|
|
468
|
+
})));
|
|
469
|
+
this.update.emit();
|
|
470
|
+
}
|
|
471
|
+
_createTraceWriter() {
|
|
472
|
+
return { write: (eventType, payload) => {
|
|
473
|
+
const event = traceEventToComputeEvent(eventType.key, payload);
|
|
474
|
+
if (event) this._handleEvent(event);
|
|
475
|
+
} };
|
|
476
|
+
}
|
|
477
|
+
_handleEvent(event) {
|
|
478
|
+
log("handleEvent", { event }, {
|
|
479
|
+
"~LogMeta": "~LogMeta",
|
|
480
|
+
F: __dxlog_file$3,
|
|
481
|
+
L: 396,
|
|
482
|
+
S: this
|
|
483
|
+
});
|
|
484
|
+
switch (event.type) {
|
|
485
|
+
case "compute-input":
|
|
486
|
+
this._onInputComputed(event.nodeId, event.property, {
|
|
487
|
+
type: "executed",
|
|
488
|
+
value: event.value
|
|
489
|
+
});
|
|
490
|
+
break;
|
|
491
|
+
case "compute-output":
|
|
492
|
+
this._onOutputComputed(event.nodeId, event.property, {
|
|
493
|
+
type: "executed",
|
|
494
|
+
value: event.value
|
|
495
|
+
});
|
|
496
|
+
break;
|
|
497
|
+
}
|
|
498
|
+
this.events.emit(event);
|
|
499
|
+
}
|
|
500
|
+
_onInputComputed(nodeId, property, value) {
|
|
501
|
+
this._runtimeStateInputs[nodeId] ??= {};
|
|
502
|
+
this._runtimeStateInputs[nodeId][property] = value;
|
|
503
|
+
}
|
|
504
|
+
_onOutputComputed(nodeId, property, value) {
|
|
505
|
+
this._runtimeStateOutputs[nodeId] ??= {};
|
|
506
|
+
this._runtimeStateOutputs[nodeId][property] = value;
|
|
507
|
+
this.output.emit({
|
|
508
|
+
nodeId,
|
|
509
|
+
property,
|
|
510
|
+
value
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
__decorate([synchronized], ComputeGraphController.prototype, "checkGraph", null);
|
|
515
|
+
__decorate([synchronized], ComputeGraphController.prototype, "exec", null);
|
|
516
|
+
var traceEventToComputeEvent = (key, payload) => {
|
|
517
|
+
switch (key) {
|
|
518
|
+
case ComputeBeginEvent.key: return {
|
|
519
|
+
type: "begin-compute",
|
|
520
|
+
...payload
|
|
521
|
+
};
|
|
522
|
+
case ComputeEndEvent.key: return {
|
|
523
|
+
type: "end-compute",
|
|
524
|
+
...payload
|
|
525
|
+
};
|
|
526
|
+
case ComputeInputEvent.key: return {
|
|
527
|
+
type: "compute-input",
|
|
528
|
+
...payload
|
|
529
|
+
};
|
|
530
|
+
case ComputeOutputEvent.key: return {
|
|
531
|
+
type: "compute-output",
|
|
532
|
+
...payload
|
|
533
|
+
};
|
|
534
|
+
case ComputeCustomEvent.key: return {
|
|
535
|
+
type: "custom",
|
|
536
|
+
...payload
|
|
537
|
+
};
|
|
538
|
+
default: return;
|
|
539
|
+
}
|
|
540
|
+
};
|
|
541
|
+
/**
|
|
542
|
+
* Waits for all effects in the bag to complete and returns the `RuntimeValue` for each property.
|
|
543
|
+
*/
|
|
544
|
+
var computeValueBag = (bag) => {
|
|
545
|
+
return Effect.all(Object.entries(bag.values).map(([key, eff]) => Effect.either(eff).pipe(Effect.map((value) => {
|
|
546
|
+
if (Either.isLeft(value)) if (isNotExecuted(value.left)) return [key, { type: "not-executed" }];
|
|
547
|
+
else return [key, {
|
|
548
|
+
type: "error",
|
|
549
|
+
error: value.left
|
|
550
|
+
}];
|
|
551
|
+
else return [key, {
|
|
552
|
+
type: "executed",
|
|
553
|
+
value: value.right
|
|
554
|
+
}];
|
|
555
|
+
})))).pipe(Effect.map((entries) => Object.fromEntries(entries)));
|
|
556
|
+
};
|
|
557
|
+
//#endregion
|
|
558
|
+
//#region src/shapes/common/box-defs.ts
|
|
559
|
+
var headerHeight = 32;
|
|
560
|
+
var footerHeight = 32;
|
|
561
|
+
//#endregion
|
|
562
|
+
//#region src/shapes/defs.ts
|
|
563
|
+
var getProperties = (ast) => SchemaAST.getPropertySignatures(ast).map(({ name }) => ({ name: name.toString() }));
|
|
564
|
+
var createAnchorId = (kind, property = kind === "input" ? DEFAULT_INPUT : DEFAULT_OUTPUT) => [kind, property].join(".");
|
|
565
|
+
var parseAnchorId = (id) => {
|
|
566
|
+
const parts = id.match(/(input|output)\.(.+)/);
|
|
567
|
+
return parts ? parts.slice(1) : [void 0, id];
|
|
568
|
+
};
|
|
569
|
+
var ComputeShape = Schema.extend(Polygon, Schema.Struct({ node: Schema.optional(Obj.ID.annotations({ description: "Compute node id" })) }).pipe(Schema.mutable));
|
|
570
|
+
var createShape = ({ id, ...rest }) => {
|
|
571
|
+
return {
|
|
572
|
+
id: id ?? Obj.ID.random(),
|
|
573
|
+
...rest
|
|
574
|
+
};
|
|
575
|
+
};
|
|
576
|
+
//#endregion
|
|
577
|
+
//#region src/shapes/common/function-anchors.ts
|
|
578
|
+
/** Vertical padding inside the function body; the height maths below depends on it. */
|
|
579
|
+
var bodyPadding = 8;
|
|
580
|
+
var getHeight = (input) => {
|
|
581
|
+
return 80 + SchemaAST.getPropertySignatures(input.ast).length * rowHeight + 2;
|
|
582
|
+
};
|
|
583
|
+
var createFunctionAnchors = (shape, input = VoidInput, output = VoidOutput) => {
|
|
584
|
+
return createAnchors({
|
|
585
|
+
shape,
|
|
586
|
+
inputs: SchemaAST.getPropertySignatures(input.ast).map(({ name }) => createAnchorId("input", name.toString())),
|
|
587
|
+
outputs: SchemaAST.getPropertySignatures(output.ast).map(({ name }) => createAnchorId("output", name.toString())),
|
|
588
|
+
center: {
|
|
589
|
+
x: 0,
|
|
590
|
+
y: 1
|
|
591
|
+
}
|
|
592
|
+
});
|
|
593
|
+
};
|
|
594
|
+
//#endregion
|
|
595
|
+
//#region src/shapes/common/Box.tsx
|
|
596
|
+
var __dxlog_file$2 = "/__w/dxos/dxos/packages/ui/react-ui-canvas-compute/src/shapes/common/Box.tsx";
|
|
597
|
+
var Box = forwardRef(({ children, classNames, shape, title, status, open, onAction }, forwardedRef) => {
|
|
598
|
+
invariant(shape.type, void 0, {
|
|
599
|
+
"~LogMeta": "~LogMeta",
|
|
600
|
+
F: __dxlog_file$2,
|
|
601
|
+
L: 26,
|
|
602
|
+
S: void 0,
|
|
603
|
+
A: ["shape.type", ""]
|
|
604
|
+
});
|
|
605
|
+
const { icon, name, openable } = useShapeDef(shape.type) ?? { icon: "ph--circle-dashed--regular" };
|
|
606
|
+
const { debug } = useEditorContext();
|
|
607
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
608
|
+
ref: forwardedRef,
|
|
609
|
+
className: "flex flex-col h-full w-full justify-between",
|
|
610
|
+
children: [
|
|
611
|
+
/* @__PURE__ */ jsxs("div", {
|
|
612
|
+
className: "flex shrink-0 w-full justify-between items-center h-[32px] dx-input-surface",
|
|
613
|
+
children: [
|
|
614
|
+
/* @__PURE__ */ jsx(Icon, {
|
|
615
|
+
icon,
|
|
616
|
+
classNames: "mx-2"
|
|
617
|
+
}),
|
|
618
|
+
/* @__PURE__ */ jsx("div", {
|
|
619
|
+
className: "grow text-sm truncate",
|
|
620
|
+
children: debug ? shape.type : name ?? shape.text ?? title
|
|
621
|
+
}),
|
|
622
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
623
|
+
classNames: "p-1 text-green-500",
|
|
624
|
+
variant: "ghost",
|
|
625
|
+
icon: "ph--play--regular",
|
|
626
|
+
label: "run",
|
|
627
|
+
iconOnly: true,
|
|
628
|
+
onDoubleClick: (ev) => ev.stopPropagation(),
|
|
629
|
+
onClick: (ev) => {
|
|
630
|
+
ev.stopPropagation();
|
|
631
|
+
onAction?.("run");
|
|
632
|
+
}
|
|
633
|
+
})
|
|
634
|
+
]
|
|
635
|
+
}),
|
|
636
|
+
/* @__PURE__ */ jsx("div", {
|
|
637
|
+
className: mx("flex flex-col h-full grow overflow-hidden", classNames),
|
|
638
|
+
children
|
|
639
|
+
}),
|
|
640
|
+
/* @__PURE__ */ jsxs("div", {
|
|
641
|
+
className: "flex shrink-0 w-full justify-between items-center h-[32px] dx-input-surface",
|
|
642
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
643
|
+
className: "grow px-2 text-sm truncate",
|
|
644
|
+
children: debug ? shape.id : status
|
|
645
|
+
}), openable && /* @__PURE__ */ jsx(IconButton, {
|
|
646
|
+
classNames: "p-1",
|
|
647
|
+
variant: "ghost",
|
|
648
|
+
icon: open ? "ph--caret-up--regular" : "ph--caret-down--regular",
|
|
649
|
+
label: open ? "close" : "open",
|
|
650
|
+
iconOnly: true,
|
|
651
|
+
onClick: (ev) => {
|
|
652
|
+
ev.stopPropagation();
|
|
653
|
+
onAction?.(open ? "close" : "open");
|
|
654
|
+
}
|
|
655
|
+
})]
|
|
656
|
+
})
|
|
657
|
+
]
|
|
658
|
+
});
|
|
659
|
+
});
|
|
660
|
+
//#endregion
|
|
661
|
+
//#region src/shapes/common/FunctionBody.tsx
|
|
662
|
+
var expandedHeight = 200;
|
|
663
|
+
var FunctionBody = ({ shape, name, content, inputSchema = VoidInput, outputSchema = VoidOutput, ...props }) => {
|
|
664
|
+
const { scale } = useCanvasContext();
|
|
665
|
+
const rootRef = useRef(null);
|
|
666
|
+
const [open, setOpen] = useState(false);
|
|
667
|
+
const handleAction = (action) => {
|
|
668
|
+
if (!rootRef.current) return;
|
|
669
|
+
switch (action) {
|
|
670
|
+
case "open": {
|
|
671
|
+
const el = getParentShapeElement(rootRef.current, shape.id);
|
|
672
|
+
const { height } = el.getBoundingClientRect();
|
|
673
|
+
el.style.height = `${height / scale + expandedHeight}px`;
|
|
674
|
+
setOpen(true);
|
|
675
|
+
break;
|
|
676
|
+
}
|
|
677
|
+
case "close": {
|
|
678
|
+
const el = getParentShapeElement(rootRef.current, shape.id);
|
|
679
|
+
el.style.height = "";
|
|
680
|
+
setOpen(false);
|
|
681
|
+
break;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
const inputs = getProperties(inputSchema.ast);
|
|
686
|
+
const outputs = getProperties(outputSchema.ast);
|
|
687
|
+
const columnCount = inputs.length && outputs.length ? 2 : 1;
|
|
688
|
+
return /* @__PURE__ */ jsxs(Box, {
|
|
689
|
+
ref: rootRef,
|
|
690
|
+
shape,
|
|
691
|
+
title: name,
|
|
692
|
+
classNames: "divide-y divide-subdued-separator",
|
|
693
|
+
open,
|
|
694
|
+
onAction: handleAction,
|
|
695
|
+
...props,
|
|
696
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
697
|
+
className: `grid grid-cols-${columnCount} items-center`,
|
|
698
|
+
style: {
|
|
699
|
+
paddingTop: 8,
|
|
700
|
+
paddingBottom: 8
|
|
701
|
+
},
|
|
702
|
+
children: [(inputs?.length ?? 0) > 0 && /* @__PURE__ */ jsx("div", {
|
|
703
|
+
className: "flex flex-col",
|
|
704
|
+
children: inputs?.map(({ name }) => /* @__PURE__ */ jsx("div", {
|
|
705
|
+
className: "px-2 truncate text-sm font-mono items-center",
|
|
706
|
+
style: { height: rowHeight },
|
|
707
|
+
children: name
|
|
708
|
+
}, name))
|
|
709
|
+
}), (outputs?.length ?? 0) > 0 && /* @__PURE__ */ jsx("div", {
|
|
710
|
+
className: "flex flex-col",
|
|
711
|
+
children: outputs?.map(({ name }) => /* @__PURE__ */ jsx("div", {
|
|
712
|
+
className: "px-2 truncate text-sm font-mono items-center text-right",
|
|
713
|
+
style: { height: rowHeight },
|
|
714
|
+
children: name
|
|
715
|
+
}, name))
|
|
716
|
+
})]
|
|
717
|
+
}), open && /* @__PURE__ */ jsx("div", {
|
|
718
|
+
className: "flex flex-col grow overflow-hidden",
|
|
719
|
+
children: content
|
|
720
|
+
})]
|
|
721
|
+
});
|
|
722
|
+
};
|
|
723
|
+
//#endregion
|
|
724
|
+
//#region src/shapes/common/TypeSelect.tsx
|
|
725
|
+
var TypeSelect = ({ value, onValueChange }) => {
|
|
726
|
+
return /* @__PURE__ */ jsxs(Select.Root, {
|
|
727
|
+
value,
|
|
728
|
+
onValueChange,
|
|
729
|
+
children: [/* @__PURE__ */ jsx(Select.TriggerButton, {
|
|
730
|
+
variant: "ghost",
|
|
731
|
+
classNames: "w-full px-0!"
|
|
732
|
+
}), /* @__PURE__ */ jsx(Select.Portal, { children: /* @__PURE__ */ jsxs(Select.Content, { children: [
|
|
733
|
+
/* @__PURE__ */ jsx(Select.ScrollUpButton, {}),
|
|
734
|
+
/* @__PURE__ */ jsx(Select.Viewport, { children: ComputeValueType.literals.map((type) => /* @__PURE__ */ jsx(Select.Option, {
|
|
735
|
+
value: type,
|
|
736
|
+
children: type
|
|
737
|
+
}, type)) }),
|
|
738
|
+
/* @__PURE__ */ jsx(Select.ScrollDownButton, {}),
|
|
739
|
+
/* @__PURE__ */ jsx(Select.Arrow, {})
|
|
740
|
+
] }) })]
|
|
741
|
+
});
|
|
742
|
+
};
|
|
743
|
+
//#endregion
|
|
744
|
+
//#region src/shapes/Append.tsx
|
|
745
|
+
var AppendComponent = ({ shape }) => {
|
|
746
|
+
return /* @__PURE__ */ jsx(FunctionBody, {
|
|
747
|
+
shape,
|
|
748
|
+
inputSchema: AppendInput
|
|
749
|
+
});
|
|
750
|
+
};
|
|
751
|
+
//#endregion
|
|
752
|
+
//#region src/shapes/append-def.ts
|
|
753
|
+
var AppendShape = Schema.extend(ComputeShape, Schema.Struct({ type: Schema.Literal("append") }));
|
|
754
|
+
var createAppend = (props) => createShape({
|
|
755
|
+
type: "append",
|
|
756
|
+
size: {
|
|
757
|
+
width: 128,
|
|
758
|
+
height: getHeight(AppendInput)
|
|
759
|
+
},
|
|
760
|
+
...props
|
|
761
|
+
});
|
|
762
|
+
var appendShape = {
|
|
763
|
+
type: "append",
|
|
764
|
+
name: "Append",
|
|
765
|
+
icon: "ph--list-plus--regular",
|
|
766
|
+
component: AppendComponent,
|
|
767
|
+
createShape: createAppend,
|
|
768
|
+
getAnchors: (shape) => createFunctionAnchors(shape, AppendInput)
|
|
769
|
+
};
|
|
770
|
+
//#endregion
|
|
771
|
+
//#region src/shapes/Array.tsx
|
|
772
|
+
var ReducerComponent = ({ shape }) => {
|
|
773
|
+
return /* @__PURE__ */ jsx(FunctionBody, {
|
|
774
|
+
shape,
|
|
775
|
+
inputSchema: ReducerInput,
|
|
776
|
+
outputSchema: ReducerOutput
|
|
777
|
+
});
|
|
778
|
+
};
|
|
779
|
+
//#endregion
|
|
780
|
+
//#region src/shapes/array-def.ts
|
|
781
|
+
var ReducerShape = Schema.extend(ComputeShape, Schema.Struct({ type: Schema.Literal("reducer") }));
|
|
782
|
+
var createReducer = ({ id, size = {
|
|
783
|
+
width: 192,
|
|
784
|
+
height: getHeight(ReducerInput)
|
|
785
|
+
}, ...rest }) => createShape({
|
|
786
|
+
type: "reducer",
|
|
787
|
+
size,
|
|
788
|
+
...rest
|
|
789
|
+
});
|
|
790
|
+
var reducerShape = {
|
|
791
|
+
type: "reducer",
|
|
792
|
+
name: "Reducer",
|
|
793
|
+
icon: "ph--repeat--regular",
|
|
794
|
+
component: ReducerComponent,
|
|
795
|
+
createShape: createReducer,
|
|
796
|
+
getAnchors: (shape) => createFunctionAnchors(shape, ReducerInput, ReducerOutput)
|
|
797
|
+
};
|
|
798
|
+
//#endregion
|
|
799
|
+
//#region src/shapes/Audio.tsx
|
|
800
|
+
var AudioComponent = ({ shape }) => {
|
|
801
|
+
const { runtime } = useComputeNodeState(shape);
|
|
802
|
+
const [active, setActive] = useState(false);
|
|
803
|
+
useEffect(() => {
|
|
804
|
+
runtime.setOutput(DEFAULT_OUTPUT, active);
|
|
805
|
+
}, [active]);
|
|
806
|
+
return /* @__PURE__ */ jsx("div", {
|
|
807
|
+
className: "flex w-full justify-center items-center",
|
|
808
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
809
|
+
icon: active ? "ph--microphone--regular" : "ph--microphone-slash--regular",
|
|
810
|
+
classNames: ["transition opacity-20 duration-1000", active && "opacity-100 text-error-text"],
|
|
811
|
+
size: 8,
|
|
812
|
+
onClick: () => setActive(!active)
|
|
813
|
+
})
|
|
814
|
+
});
|
|
815
|
+
};
|
|
816
|
+
//#endregion
|
|
817
|
+
//#region src/shapes/audio-def.ts
|
|
818
|
+
var AudioShape = Schema.extend(ComputeShape, Schema.Struct({ type: Schema.Literal("audio") }));
|
|
819
|
+
var createAudio = (props) => createShape({
|
|
820
|
+
type: "audio",
|
|
821
|
+
size: {
|
|
822
|
+
width: 64,
|
|
823
|
+
height: 64
|
|
824
|
+
},
|
|
825
|
+
...props
|
|
826
|
+
});
|
|
827
|
+
var audioShape = {
|
|
828
|
+
type: "audio",
|
|
829
|
+
name: "Audio",
|
|
830
|
+
icon: "ph--microphone--regular",
|
|
831
|
+
component: AudioComponent,
|
|
832
|
+
createShape: createAudio,
|
|
833
|
+
getAnchors: (shape) => createAnchorMap(shape, { [createAnchorId("output")]: {
|
|
834
|
+
x: 1,
|
|
835
|
+
y: 0
|
|
836
|
+
} })
|
|
837
|
+
};
|
|
838
|
+
//#endregion
|
|
839
|
+
//#region src/shapes/Beacon.tsx
|
|
840
|
+
var BeaconComponent = ({ shape }) => {
|
|
841
|
+
const { runtime } = useComputeNodeState(shape);
|
|
842
|
+
const input = runtime.inputs[DEFAULT_INPUT];
|
|
843
|
+
return /* @__PURE__ */ jsx("div", {
|
|
844
|
+
className: "flex w-full justify-center items-center",
|
|
845
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
846
|
+
icon: "ph--sun--regular",
|
|
847
|
+
classNames: ["transition opacity-20 duration-1000", isTruthy(input?.type === "executed" ? input.value : false) && "opacity-100 text-yellow-500"],
|
|
848
|
+
size: 8
|
|
849
|
+
})
|
|
850
|
+
});
|
|
851
|
+
};
|
|
852
|
+
//#endregion
|
|
853
|
+
//#region src/shapes/beacon-def.ts
|
|
854
|
+
var BeaconShape = Schema.extend(ComputeShape, Schema.Struct({ type: Schema.Literal("beacon") }));
|
|
855
|
+
var createBeacon = (props) => createShape({
|
|
856
|
+
type: "beacon",
|
|
857
|
+
size: {
|
|
858
|
+
width: 64,
|
|
859
|
+
height: 64
|
|
860
|
+
},
|
|
861
|
+
...props
|
|
862
|
+
});
|
|
863
|
+
var beaconShape = {
|
|
864
|
+
type: "beacon",
|
|
865
|
+
name: "Beacon",
|
|
866
|
+
icon: "ph--sun--regular",
|
|
867
|
+
component: BeaconComponent,
|
|
868
|
+
createShape: createBeacon,
|
|
869
|
+
getAnchors: (shape) => createAnchorMap(shape, { [createAnchorId("input")]: {
|
|
870
|
+
x: -1,
|
|
871
|
+
y: 0
|
|
872
|
+
} })
|
|
873
|
+
};
|
|
874
|
+
//#endregion
|
|
875
|
+
//#region src/shapes/Chat.tsx
|
|
876
|
+
var TextInputComponent = ({ shape, title, ...props }) => {
|
|
877
|
+
const { runtime } = useComputeNodeState(shape);
|
|
878
|
+
const inputRef = useRef(null);
|
|
879
|
+
const handleEnter = (text) => {
|
|
880
|
+
const value = text.trim();
|
|
881
|
+
if (value.length) {
|
|
882
|
+
runtime.setOutput(DEFAULT_OUTPUT, value);
|
|
883
|
+
inputRef.current?.setText("");
|
|
884
|
+
}
|
|
885
|
+
};
|
|
886
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
887
|
+
shape,
|
|
888
|
+
title,
|
|
889
|
+
children: /* @__PURE__ */ jsx(TextBox, {
|
|
890
|
+
ref: inputRef,
|
|
891
|
+
onEnter: handleEnter,
|
|
892
|
+
...props
|
|
893
|
+
})
|
|
894
|
+
});
|
|
895
|
+
};
|
|
896
|
+
//#endregion
|
|
897
|
+
//#region src/shapes/chat-def.tsx
|
|
898
|
+
var ChatShape = Schema.extend(ComputeShape, Schema.Struct({ type: Schema.Literal("chat") }));
|
|
899
|
+
var createChat = (props) => createShape({
|
|
900
|
+
type: "chat",
|
|
901
|
+
size: {
|
|
902
|
+
width: 256,
|
|
903
|
+
height: 128
|
|
904
|
+
},
|
|
905
|
+
...props
|
|
906
|
+
});
|
|
907
|
+
var chatShape = {
|
|
908
|
+
type: "chat",
|
|
909
|
+
name: "Chat",
|
|
910
|
+
icon: "ph--textbox--regular",
|
|
911
|
+
component: (props) => /* @__PURE__ */ jsx(TextInputComponent, {
|
|
912
|
+
...props,
|
|
913
|
+
title: "Prompt",
|
|
914
|
+
placeholder: "Message"
|
|
915
|
+
}),
|
|
916
|
+
createShape: createChat,
|
|
917
|
+
getAnchors: (shape) => createAnchorMap(shape, { [createAnchorId("output")]: {
|
|
918
|
+
x: 1,
|
|
919
|
+
y: 0
|
|
920
|
+
} }),
|
|
921
|
+
resizable: true
|
|
922
|
+
};
|
|
923
|
+
//#endregion
|
|
924
|
+
//#region src/shapes/Constant.tsx
|
|
925
|
+
var inferType = (value) => {
|
|
926
|
+
if (typeof value === "string") return "string";
|
|
927
|
+
else if (typeof value === "number") return "number";
|
|
928
|
+
else if (typeof value === "boolean") return "boolean";
|
|
929
|
+
else if (typeof value === "object") return "object";
|
|
930
|
+
};
|
|
931
|
+
var ConstantComponent = ({ shape, title, chat, ...props }) => {
|
|
932
|
+
const { node } = useComputeNodeState(shape);
|
|
933
|
+
const [type, setType] = useState(inferType(node.value) ?? ComputeValueType.literals[0]);
|
|
934
|
+
const inputRef = useRef(null);
|
|
935
|
+
const handleEnter = useCallback((text) => {
|
|
936
|
+
const value = text.trim();
|
|
937
|
+
if (value.length) {
|
|
938
|
+
if (type === "number") {
|
|
939
|
+
const floatValue = parseFloat(value);
|
|
940
|
+
if (!isNaN(floatValue)) node.value = floatValue;
|
|
941
|
+
} else if (type === "object") node.value = safeParseJson(value, {});
|
|
942
|
+
else node.value = value;
|
|
943
|
+
inputRef.current?.focus();
|
|
944
|
+
}
|
|
945
|
+
}, [type]);
|
|
946
|
+
return /* @__PURE__ */ jsxs(Box, {
|
|
947
|
+
shape,
|
|
948
|
+
title,
|
|
949
|
+
status: /* @__PURE__ */ jsx(TypeSelect, {
|
|
950
|
+
value: type,
|
|
951
|
+
onValueChange: setType
|
|
952
|
+
}),
|
|
953
|
+
children: [
|
|
954
|
+
(type === "string" || type === "number") && /* @__PURE__ */ jsx(TextBox, {
|
|
955
|
+
...props,
|
|
956
|
+
ref: inputRef,
|
|
957
|
+
value: node.value,
|
|
958
|
+
onEnter: handleEnter
|
|
959
|
+
}),
|
|
960
|
+
type === "object" && /* @__PURE__ */ jsx(TextBox, {
|
|
961
|
+
...props,
|
|
962
|
+
ref: inputRef,
|
|
963
|
+
value: JSON.stringify(node.value, null, 2),
|
|
964
|
+
language: "json"
|
|
965
|
+
}),
|
|
966
|
+
type === "boolean" && /* @__PURE__ */ jsx("div", {
|
|
967
|
+
className: "flex grow justify-center items-center",
|
|
968
|
+
children: /* @__PURE__ */ jsx(Input.Root, { children: /* @__PURE__ */ jsx(Input.Switch, {
|
|
969
|
+
checked: node.value,
|
|
970
|
+
onCheckedChange: (value) => {
|
|
971
|
+
node.value = value;
|
|
972
|
+
}
|
|
973
|
+
}) })
|
|
974
|
+
})
|
|
975
|
+
]
|
|
976
|
+
});
|
|
977
|
+
};
|
|
978
|
+
//#endregion
|
|
979
|
+
//#region src/shapes/constant-def.tsx
|
|
980
|
+
var ConstantShape = Schema.extend(ComputeShape, Schema.Struct({
|
|
981
|
+
type: Schema.Literal("constant"),
|
|
982
|
+
value: Schema.optional(Schema.Any)
|
|
983
|
+
}));
|
|
984
|
+
var createConstant = (props) => createShape({
|
|
985
|
+
type: "constant",
|
|
986
|
+
size: {
|
|
987
|
+
width: 192,
|
|
988
|
+
height: 128
|
|
989
|
+
},
|
|
990
|
+
...props
|
|
991
|
+
});
|
|
992
|
+
var constantShape = {
|
|
993
|
+
type: "constant",
|
|
994
|
+
name: "Value",
|
|
995
|
+
icon: "ph--dots-three-circle--regular",
|
|
996
|
+
component: (props) => /* @__PURE__ */ jsx(ConstantComponent, {
|
|
997
|
+
...props,
|
|
998
|
+
placeholder: "Constant"
|
|
999
|
+
}),
|
|
1000
|
+
createShape: createConstant,
|
|
1001
|
+
getAnchors: (shape) => createAnchorMap(shape, { [createAnchorId("output")]: {
|
|
1002
|
+
x: 1,
|
|
1003
|
+
y: 0
|
|
1004
|
+
} }),
|
|
1005
|
+
resizable: true
|
|
1006
|
+
};
|
|
1007
|
+
//#endregion
|
|
1008
|
+
//#region src/shapes/Database.tsx
|
|
1009
|
+
var DatabaseComponent = ({ shape }) => {
|
|
1010
|
+
return /* @__PURE__ */ jsx(Box, { shape });
|
|
1011
|
+
};
|
|
1012
|
+
//#endregion
|
|
1013
|
+
//#region src/shapes/database-def.ts
|
|
1014
|
+
var DatabaseShape = Schema.extend(ComputeShape, Schema.Struct({ type: Schema.Literal("database") }));
|
|
1015
|
+
var createDatabase = (props) => createShape({
|
|
1016
|
+
type: "database",
|
|
1017
|
+
size: {
|
|
1018
|
+
width: 128,
|
|
1019
|
+
height: 64
|
|
1020
|
+
},
|
|
1021
|
+
...props
|
|
1022
|
+
});
|
|
1023
|
+
var databaseShape = {
|
|
1024
|
+
type: "database",
|
|
1025
|
+
name: "ECHO",
|
|
1026
|
+
icon: "ph--database--regular",
|
|
1027
|
+
component: DatabaseComponent,
|
|
1028
|
+
createShape: createDatabase,
|
|
1029
|
+
getAnchors: (shape) => createAnchorMap(shape, { [createAnchorId("output")]: {
|
|
1030
|
+
x: 1,
|
|
1031
|
+
y: 0
|
|
1032
|
+
} })
|
|
1033
|
+
};
|
|
1034
|
+
//#endregion
|
|
1035
|
+
//#region src/shapes/Feed.tsx
|
|
1036
|
+
var FeedComponent = ({ shape }) => {
|
|
1037
|
+
const { runtime } = useComputeNodeState(shape);
|
|
1038
|
+
const items = runtime.outputs[DEFAULT_OUTPUT]?.type === "executed" ? runtime.outputs[DEFAULT_OUTPUT].value : [];
|
|
1039
|
+
const handleAction = (action) => {
|
|
1040
|
+
if (action === "run") runtime.evalNode();
|
|
1041
|
+
};
|
|
1042
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
1043
|
+
shape,
|
|
1044
|
+
status: `${items.length} items`,
|
|
1045
|
+
onAction: handleAction,
|
|
1046
|
+
children: /* @__PURE__ */ jsx(ScrollArea.Root, {
|
|
1047
|
+
orientation: "vertical",
|
|
1048
|
+
children: /* @__PURE__ */ jsx(ScrollArea.Viewport, {
|
|
1049
|
+
classNames: "divide-y divide-subdued-separator",
|
|
1050
|
+
children: [...items].map((item, i) => /* @__PURE__ */ jsx(FeedItem, {
|
|
1051
|
+
classNames: "p-1 px-2",
|
|
1052
|
+
item
|
|
1053
|
+
}, i))
|
|
1054
|
+
})
|
|
1055
|
+
})
|
|
1056
|
+
});
|
|
1057
|
+
};
|
|
1058
|
+
var FeedItem = ({ classNames, item }) => {
|
|
1059
|
+
if (typeof item !== "object") return /* @__PURE__ */ jsx("div", {
|
|
1060
|
+
className: mx(classNames, "whitespace-pre-wrap"),
|
|
1061
|
+
children: item
|
|
1062
|
+
});
|
|
1063
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1064
|
+
className: mx("grid grid-cols-[80px_1fr]", classNames),
|
|
1065
|
+
children: Object.entries(item).map(([key, value]) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
|
|
1066
|
+
className: "p-1 text-xs text-subdued",
|
|
1067
|
+
children: key
|
|
1068
|
+
}), /* @__PURE__ */ jsx("div", { children: typeof value === "string" ? value : JSON.stringify(value) })] }, key))
|
|
1069
|
+
});
|
|
1070
|
+
};
|
|
1071
|
+
//#endregion
|
|
1072
|
+
//#region src/shapes/feed-def.ts
|
|
1073
|
+
var FeedShape = Schema.extend(ComputeShape, Schema.Struct({ type: Schema.Literal("queue") }));
|
|
1074
|
+
var createFeed = (props) => createShape({
|
|
1075
|
+
type: "queue",
|
|
1076
|
+
size: {
|
|
1077
|
+
width: 256,
|
|
1078
|
+
height: 512
|
|
1079
|
+
},
|
|
1080
|
+
...props
|
|
1081
|
+
});
|
|
1082
|
+
var feedShape = {
|
|
1083
|
+
type: "queue",
|
|
1084
|
+
name: "Feed",
|
|
1085
|
+
icon: "ph--queue--regular",
|
|
1086
|
+
component: FeedComponent,
|
|
1087
|
+
createShape: createFeed,
|
|
1088
|
+
getAnchors: (shape) => createFunctionAnchors(shape, QueueInput, QueueOutput),
|
|
1089
|
+
resizable: true
|
|
1090
|
+
};
|
|
1091
|
+
//#endregion
|
|
1092
|
+
//#region src/shapes/Function.tsx
|
|
1093
|
+
var FunctionShapeComponent = ({ shape, title, ...props }) => {
|
|
1094
|
+
const client = useClient();
|
|
1095
|
+
const { node, runtime } = useComputeNodeState(shape);
|
|
1096
|
+
const inputRef = useRef(null);
|
|
1097
|
+
const handleEnter = useCallback(async (text) => {
|
|
1098
|
+
const value = text.trim();
|
|
1099
|
+
const { spaceId, objectId } = parseId(value);
|
|
1100
|
+
if (!spaceId || !objectId) return;
|
|
1101
|
+
const space = client.spaces.get(spaceId);
|
|
1102
|
+
const object = space?.db.query(Filter.id(objectId)).runSync()[0];
|
|
1103
|
+
if (!space || !instanceOf(Script.Script, object)) return;
|
|
1104
|
+
const [fn] = await space.db.query(Filter.type(Operation.PersistentOperation, { source: Ref.make(object) })).run();
|
|
1105
|
+
if (!fn) return;
|
|
1106
|
+
node.value = value;
|
|
1107
|
+
node.function = Ref.make(fn);
|
|
1108
|
+
node.inputSchema = fn.inputSchema;
|
|
1109
|
+
node.outputSchema = fn.outputSchema;
|
|
1110
|
+
}, [client, node]);
|
|
1111
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
1112
|
+
shape,
|
|
1113
|
+
title: "Function",
|
|
1114
|
+
onAction: useCallback((action) => {
|
|
1115
|
+
if (action !== "run") return;
|
|
1116
|
+
runtime.evalNode();
|
|
1117
|
+
}, [runtime]),
|
|
1118
|
+
children: /* @__PURE__ */ jsx(TextBox, {
|
|
1119
|
+
...props,
|
|
1120
|
+
ref: inputRef,
|
|
1121
|
+
value: node.value,
|
|
1122
|
+
language: node.valueType === "object" ? "json" : void 0,
|
|
1123
|
+
onBlur: handleEnter,
|
|
1124
|
+
onEnter: handleEnter
|
|
1125
|
+
})
|
|
1126
|
+
});
|
|
1127
|
+
};
|
|
1128
|
+
//#endregion
|
|
1129
|
+
//#region src/shapes/function-def.ts
|
|
1130
|
+
var FunctionShape = Schema.extend(ComputeShape, Schema.Struct({ type: Schema.Literal("function") }));
|
|
1131
|
+
var createFunction = (props) => createShape({
|
|
1132
|
+
type: "function",
|
|
1133
|
+
size: {
|
|
1134
|
+
width: 256,
|
|
1135
|
+
height: 192
|
|
1136
|
+
},
|
|
1137
|
+
...props
|
|
1138
|
+
});
|
|
1139
|
+
var functionShape = {
|
|
1140
|
+
type: "function",
|
|
1141
|
+
name: "Function",
|
|
1142
|
+
icon: "ph--function--regular",
|
|
1143
|
+
component: FunctionShapeComponent,
|
|
1144
|
+
createShape: createFunction,
|
|
1145
|
+
getAnchors: (shape) => createFunctionAnchors(shape, FunctionInput, AnyOutput)
|
|
1146
|
+
};
|
|
1147
|
+
//#endregion
|
|
1148
|
+
//#region src/shapes/Gpt.tsx
|
|
1149
|
+
var GptComponent = ({ shape }) => {
|
|
1150
|
+
const { meta, runtime } = useComputeNodeState(shape);
|
|
1151
|
+
const [text, setText] = useState("");
|
|
1152
|
+
const [tokens, setTokens] = useState(0);
|
|
1153
|
+
useEffect(() => {
|
|
1154
|
+
return runtime.subscribeToEventLog((ev) => {
|
|
1155
|
+
switch (ev.type) {
|
|
1156
|
+
case "begin-compute":
|
|
1157
|
+
setText("");
|
|
1158
|
+
break;
|
|
1159
|
+
case "custom": {
|
|
1160
|
+
const token = ev.event;
|
|
1161
|
+
switch (token.type) {
|
|
1162
|
+
case "content_block_delta":
|
|
1163
|
+
switch (token.delta.type) {
|
|
1164
|
+
case "text_delta": {
|
|
1165
|
+
const delta = token.delta.text;
|
|
1166
|
+
setText((prev) => {
|
|
1167
|
+
const text = prev + delta;
|
|
1168
|
+
setTokens(text.split(" ").length);
|
|
1169
|
+
return text;
|
|
1170
|
+
});
|
|
1171
|
+
break;
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
break;
|
|
1175
|
+
}
|
|
1176
|
+
break;
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
});
|
|
1180
|
+
}, [runtime?.subscribeToEventLog]);
|
|
1181
|
+
return /* @__PURE__ */ jsx(FunctionBody, {
|
|
1182
|
+
shape,
|
|
1183
|
+
content: /* @__PURE__ */ jsx(ScrollArea.Root, {
|
|
1184
|
+
orientation: "vertical",
|
|
1185
|
+
thin: true,
|
|
1186
|
+
children: /* @__PURE__ */ jsx(ScrollArea.Viewport, { children: text })
|
|
1187
|
+
}),
|
|
1188
|
+
status: `${tokens} tokens`,
|
|
1189
|
+
inputSchema: meta.input,
|
|
1190
|
+
outputSchema: meta.output
|
|
1191
|
+
});
|
|
1192
|
+
};
|
|
1193
|
+
//#endregion
|
|
1194
|
+
//#region src/shapes/gpt-def.ts
|
|
1195
|
+
var GptShape = Schema.extend(ComputeShape, Schema.Struct({ type: Schema.Literal("gpt") }));
|
|
1196
|
+
var createGpt = (props) => createShape({
|
|
1197
|
+
type: "gpt",
|
|
1198
|
+
size: {
|
|
1199
|
+
width: 256,
|
|
1200
|
+
height: Math.max(getHeight(GptInput), getHeight(GptOutput))
|
|
1201
|
+
},
|
|
1202
|
+
...props
|
|
1203
|
+
});
|
|
1204
|
+
var gptShape = {
|
|
1205
|
+
type: "gpt",
|
|
1206
|
+
name: "GPT",
|
|
1207
|
+
icon: "ph--brain--regular",
|
|
1208
|
+
component: GptComponent,
|
|
1209
|
+
createShape: createGpt,
|
|
1210
|
+
getAnchors: (shape) => createFunctionAnchors(shape, GptInput, GptOutput),
|
|
1211
|
+
openable: true
|
|
1212
|
+
};
|
|
1213
|
+
//#endregion
|
|
1214
|
+
//#region src/shapes/GptRealtime.tsx
|
|
1215
|
+
var __dxlog_file$1 = "/__w/dxos/dxos/packages/ui/react-ui-canvas-compute/src/shapes/GptRealtime.tsx";
|
|
1216
|
+
var GptRealtimeComponent = ({ shape }) => {
|
|
1217
|
+
const [isLive, setIsLive] = useState(false);
|
|
1218
|
+
const [isReady, setIsReady] = useState(false);
|
|
1219
|
+
const config = useConfig();
|
|
1220
|
+
const start = async () => {
|
|
1221
|
+
setIsLive(true);
|
|
1222
|
+
try {
|
|
1223
|
+
const peerConnection = new RTCPeerConnection();
|
|
1224
|
+
peerConnection.ontrack = (event) => {
|
|
1225
|
+
const audioElement = document.createElement("audio");
|
|
1226
|
+
audioElement.srcObject = event.streams[0];
|
|
1227
|
+
audioElement.autoplay = true;
|
|
1228
|
+
audioElement.controls = false;
|
|
1229
|
+
audioElement.style.display = "none";
|
|
1230
|
+
document.body.appendChild(audioElement);
|
|
1231
|
+
setIsReady(true);
|
|
1232
|
+
};
|
|
1233
|
+
(await navigator.mediaDevices.getUserMedia({ audio: true })).getTracks().forEach((track) => peerConnection.addTransceiver(track, { direction: "sendrecv" }));
|
|
1234
|
+
const offer = await peerConnection.createOffer();
|
|
1235
|
+
await peerConnection.setLocalDescription(offer);
|
|
1236
|
+
const AiServiceUrl = new URL("/rtc-connect", config.values.runtime?.services?.ai?.server ?? DEFAULT_AI_SERVICE_URL);
|
|
1237
|
+
const answer = await (await fetch(AiServiceUrl, {
|
|
1238
|
+
method: "POST",
|
|
1239
|
+
body: offer.sdp,
|
|
1240
|
+
headers: { "Content-Type": "application/sdp" }
|
|
1241
|
+
})).text();
|
|
1242
|
+
await peerConnection.setRemoteDescription({
|
|
1243
|
+
sdp: answer,
|
|
1244
|
+
type: "answer"
|
|
1245
|
+
});
|
|
1246
|
+
const dataChannel = peerConnection.createDataChannel("response");
|
|
1247
|
+
const configureData = () => {
|
|
1248
|
+
log.info("Configuring data channel", void 0, {
|
|
1249
|
+
"~LogMeta": "~LogMeta",
|
|
1250
|
+
F: __dxlog_file$1,
|
|
1251
|
+
L: 71,
|
|
1252
|
+
S: void 0
|
|
1253
|
+
});
|
|
1254
|
+
dataChannel.send(JSON.stringify({
|
|
1255
|
+
type: "session.update",
|
|
1256
|
+
session: {
|
|
1257
|
+
modalities: ["text", "audio"],
|
|
1258
|
+
tools: []
|
|
1259
|
+
}
|
|
1260
|
+
}));
|
|
1261
|
+
};
|
|
1262
|
+
dataChannel.addEventListener("open", (ev) => {
|
|
1263
|
+
log.info("Opening data channel", { ev }, {
|
|
1264
|
+
"~LogMeta": "~LogMeta",
|
|
1265
|
+
F: __dxlog_file$1,
|
|
1266
|
+
L: 84,
|
|
1267
|
+
S: void 0
|
|
1268
|
+
});
|
|
1269
|
+
configureData();
|
|
1270
|
+
});
|
|
1271
|
+
dataChannel.addEventListener("message", async (ev) => {
|
|
1272
|
+
if (JSON.parse(ev.data).type === "response.function_call_arguments.done") {}
|
|
1273
|
+
});
|
|
1274
|
+
} catch (error) {
|
|
1275
|
+
log.error("Error in realtime session:", { error }, {
|
|
1276
|
+
"~LogMeta": "~LogMeta",
|
|
1277
|
+
F: __dxlog_file$1,
|
|
1278
|
+
L: 124,
|
|
1279
|
+
S: void 0
|
|
1280
|
+
});
|
|
1281
|
+
throw error;
|
|
1282
|
+
}
|
|
1283
|
+
};
|
|
1284
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1285
|
+
className: "flex w-full justify-center items-center",
|
|
1286
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
1287
|
+
icon: isReady ? "ph--waveform--regular" : isLive ? "ph--pulse--regular" : "ph--play--regular",
|
|
1288
|
+
size: 16,
|
|
1289
|
+
classNames: !isLive && "cursor-pointer",
|
|
1290
|
+
onClick: start
|
|
1291
|
+
})
|
|
1292
|
+
});
|
|
1293
|
+
};
|
|
1294
|
+
var DEFAULT_AI_SERVICE_URL = "http://localhost:8788";
|
|
1295
|
+
//#endregion
|
|
1296
|
+
//#region src/shapes/gpt-realtime-def.ts
|
|
1297
|
+
var GptRealtimeShape = Schema.extend(ComputeShape, Schema.Struct({ type: Schema.Literal("gpt-realtime") }));
|
|
1298
|
+
var createGptRealtime = (props) => createShape({
|
|
1299
|
+
type: "gpt-realtime",
|
|
1300
|
+
size: {
|
|
1301
|
+
width: 256,
|
|
1302
|
+
height: 256
|
|
1303
|
+
},
|
|
1304
|
+
...props
|
|
1305
|
+
});
|
|
1306
|
+
var gptRealtimeShape = {
|
|
1307
|
+
type: "gpt-realtime",
|
|
1308
|
+
name: "GPT Realtime",
|
|
1309
|
+
icon: "ph--pulse--regular",
|
|
1310
|
+
component: GptRealtimeComponent,
|
|
1311
|
+
createShape: createGptRealtime,
|
|
1312
|
+
getAnchors: (shape) => createFunctionAnchors(shape, Schema.Struct({ audio: Schema.Any }), Schema.Struct({})),
|
|
1313
|
+
resizable: true
|
|
1314
|
+
};
|
|
1315
|
+
//#endregion
|
|
1316
|
+
//#region src/shapes/Json.tsx
|
|
1317
|
+
var JsonComponent = ({ shape, ...props }) => {
|
|
1318
|
+
const { runtime } = useComputeNodeState(shape);
|
|
1319
|
+
const input = runtime.inputs[DEFAULT_INPUT];
|
|
1320
|
+
const value = input?.type === "executed" ? input.value : void 0;
|
|
1321
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
1322
|
+
shape,
|
|
1323
|
+
children: /* @__PURE__ */ jsx(Syntax.Root, {
|
|
1324
|
+
data: value,
|
|
1325
|
+
children: /* @__PURE__ */ jsxs(Syntax.Content, { children: [/* @__PURE__ */ jsx(Syntax.Filter, {}), /* @__PURE__ */ jsx(Syntax.Viewport, { children: /* @__PURE__ */ jsx(Syntax.Code, { classNames: "text-xs" }) })] })
|
|
1326
|
+
})
|
|
1327
|
+
});
|
|
1328
|
+
};
|
|
1329
|
+
var JsonTransformComponent = ({ shape, ...props }) => {
|
|
1330
|
+
return /* @__PURE__ */ jsx(Box, { shape });
|
|
1331
|
+
};
|
|
1332
|
+
//#endregion
|
|
1333
|
+
//#region src/shapes/json-def.ts
|
|
1334
|
+
var JsonShape = Schema.extend(ComputeShape, Schema.Struct({ type: Schema.Literal("json") }));
|
|
1335
|
+
var JsonTransformShape = Schema.extend(ComputeShape, Schema.Struct({ type: Schema.Literal("json-transform") }));
|
|
1336
|
+
var createJson = (props) => createShape({
|
|
1337
|
+
type: "json",
|
|
1338
|
+
size: {
|
|
1339
|
+
width: 256,
|
|
1340
|
+
height: 256
|
|
1341
|
+
},
|
|
1342
|
+
...props
|
|
1343
|
+
});
|
|
1344
|
+
var jsonShape = {
|
|
1345
|
+
type: "json",
|
|
1346
|
+
name: "JSON",
|
|
1347
|
+
icon: "ph--code--regular",
|
|
1348
|
+
component: JsonComponent,
|
|
1349
|
+
createShape: createJson,
|
|
1350
|
+
getAnchors: (shape) => createAnchorMap(shape, {
|
|
1351
|
+
[createAnchorId("input")]: {
|
|
1352
|
+
x: -1,
|
|
1353
|
+
y: 0
|
|
1354
|
+
},
|
|
1355
|
+
[createAnchorId("output")]: {
|
|
1356
|
+
x: 1,
|
|
1357
|
+
y: 0
|
|
1358
|
+
}
|
|
1359
|
+
}),
|
|
1360
|
+
resizable: true
|
|
1361
|
+
};
|
|
1362
|
+
var createJsonTransform = (props) => createShape({
|
|
1363
|
+
type: "json-transform",
|
|
1364
|
+
size: {
|
|
1365
|
+
width: 128,
|
|
1366
|
+
height: getHeight(JsonTransformInput)
|
|
1367
|
+
},
|
|
1368
|
+
...props
|
|
1369
|
+
});
|
|
1370
|
+
var jsonTransformShape = {
|
|
1371
|
+
type: "json-transform",
|
|
1372
|
+
name: "Transform",
|
|
1373
|
+
icon: "ph--shuffle-simple--regular",
|
|
1374
|
+
component: JsonTransformComponent,
|
|
1375
|
+
createShape: createJsonTransform,
|
|
1376
|
+
getAnchors: (shape) => createFunctionAnchors(shape, JsonTransformInput, DefaultOutput),
|
|
1377
|
+
resizable: true
|
|
1378
|
+
};
|
|
1379
|
+
//#endregion
|
|
1380
|
+
//#region src/shapes/Logic.tsx
|
|
1381
|
+
var IfComponent = ({ shape, ...props }) => {
|
|
1382
|
+
return /* @__PURE__ */ jsx(FunctionBody, {
|
|
1383
|
+
shape,
|
|
1384
|
+
inputSchema: IfInput,
|
|
1385
|
+
outputSchema: IfOutput
|
|
1386
|
+
});
|
|
1387
|
+
};
|
|
1388
|
+
var IfElseComponent = ({ shape, ...props }) => {
|
|
1389
|
+
return /* @__PURE__ */ jsx(FunctionBody, {
|
|
1390
|
+
shape,
|
|
1391
|
+
inputSchema: IfElseInput,
|
|
1392
|
+
outputSchema: IfElseOutput
|
|
1393
|
+
});
|
|
1394
|
+
};
|
|
1395
|
+
//#endregion
|
|
1396
|
+
//#region src/shapes/logic-def.ts
|
|
1397
|
+
var IfShape = Schema.extend(ComputeShape, Schema.Struct({ type: Schema.Literal("if") }));
|
|
1398
|
+
var IfElseShape = Schema.extend(ComputeShape, Schema.Struct({ type: Schema.Literal("if-else") }));
|
|
1399
|
+
var createIf = (props) => createShape({
|
|
1400
|
+
type: "if",
|
|
1401
|
+
size: {
|
|
1402
|
+
width: 192,
|
|
1403
|
+
height: getHeight(IfInput)
|
|
1404
|
+
},
|
|
1405
|
+
...props
|
|
1406
|
+
});
|
|
1407
|
+
var ifShape = {
|
|
1408
|
+
type: "if",
|
|
1409
|
+
name: "IF",
|
|
1410
|
+
icon: "ph--arrows-split--regular",
|
|
1411
|
+
component: IfComponent,
|
|
1412
|
+
createShape: createIf,
|
|
1413
|
+
getAnchors: (shape) => createFunctionAnchors(shape, IfInput, IfOutput)
|
|
1414
|
+
};
|
|
1415
|
+
var createIfElse = (props) => createShape({
|
|
1416
|
+
type: "if-else",
|
|
1417
|
+
size: {
|
|
1418
|
+
width: 192,
|
|
1419
|
+
height: getHeight(IfElseInput)
|
|
1420
|
+
},
|
|
1421
|
+
...props
|
|
1422
|
+
});
|
|
1423
|
+
var ifElseShape = {
|
|
1424
|
+
type: "if-else",
|
|
1425
|
+
name: "IF/ELSE",
|
|
1426
|
+
icon: "ph--arrows-merge--regular",
|
|
1427
|
+
component: IfElseComponent,
|
|
1428
|
+
createShape: createIfElse,
|
|
1429
|
+
getAnchors: (shape) => createFunctionAnchors(shape, IfElseInput, IfElseOutput)
|
|
1430
|
+
};
|
|
1431
|
+
//#endregion
|
|
1432
|
+
//#region src/shapes/RNG.tsx
|
|
1433
|
+
var icons = [
|
|
1434
|
+
"ph--dice-one--regular",
|
|
1435
|
+
"ph--dice-two--regular",
|
|
1436
|
+
"ph--dice-three--regular",
|
|
1437
|
+
"ph--dice-four--regular",
|
|
1438
|
+
"ph--dice-five--regular",
|
|
1439
|
+
"ph--dice-six--regular"
|
|
1440
|
+
];
|
|
1441
|
+
var pickIcon = () => icons[Math.floor(Math.random() * icons.length)];
|
|
1442
|
+
var RandomComponent = ({ shape }) => {
|
|
1443
|
+
const { runtime } = useComputeNodeState(shape);
|
|
1444
|
+
const [spin, setSpin] = useState(false);
|
|
1445
|
+
const [icon, setIcon] = useState(pickIcon());
|
|
1446
|
+
useEffect(() => {
|
|
1447
|
+
if (!spin) return;
|
|
1448
|
+
const i = setInterval(() => setIcon(pickIcon()), 250);
|
|
1449
|
+
const t1 = setTimeout(() => clearInterval(i), 900);
|
|
1450
|
+
const t2 = setTimeout(() => setSpin(false), 1100);
|
|
1451
|
+
return () => {
|
|
1452
|
+
clearInterval(i);
|
|
1453
|
+
clearTimeout(t1);
|
|
1454
|
+
clearTimeout(t2);
|
|
1455
|
+
};
|
|
1456
|
+
}, [spin]);
|
|
1457
|
+
const handleClick = (ev) => {
|
|
1458
|
+
ev.stopPropagation();
|
|
1459
|
+
runtime.setOutput(DEFAULT_OUTPUT, Math.random());
|
|
1460
|
+
setSpin(true);
|
|
1461
|
+
};
|
|
1462
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1463
|
+
className: "flex grow items-center justify-center",
|
|
1464
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
1465
|
+
icon,
|
|
1466
|
+
classNames: spin && "animate-[spin_1s]",
|
|
1467
|
+
size: 10,
|
|
1468
|
+
onClick: handleClick
|
|
1469
|
+
})
|
|
1470
|
+
});
|
|
1471
|
+
};
|
|
1472
|
+
//#endregion
|
|
1473
|
+
//#region src/shapes/rng-def.ts
|
|
1474
|
+
var RandomShape = Schema.extend(ComputeShape, Schema.Struct({
|
|
1475
|
+
type: Schema.Literal("rng"),
|
|
1476
|
+
min: Schema.optional(Schema.Number),
|
|
1477
|
+
max: Schema.optional(Schema.Number)
|
|
1478
|
+
}));
|
|
1479
|
+
var createRandom = (props) => createShape({
|
|
1480
|
+
type: "rng",
|
|
1481
|
+
size: {
|
|
1482
|
+
width: 64,
|
|
1483
|
+
height: 64
|
|
1484
|
+
},
|
|
1485
|
+
...props
|
|
1486
|
+
});
|
|
1487
|
+
var randomShape = {
|
|
1488
|
+
type: "rng",
|
|
1489
|
+
name: "Random",
|
|
1490
|
+
icon: "ph--dice-six--regular",
|
|
1491
|
+
component: RandomComponent,
|
|
1492
|
+
createShape: createRandom,
|
|
1493
|
+
getAnchors: (shape) => createAnchorMap(shape, { [createAnchorId("output")]: {
|
|
1494
|
+
x: 1,
|
|
1495
|
+
y: 0
|
|
1496
|
+
} })
|
|
1497
|
+
};
|
|
1498
|
+
//#endregion
|
|
1499
|
+
//#region src/shapes/Scope.tsx
|
|
1500
|
+
var ScopeComponent = ({ shape }) => {
|
|
1501
|
+
const { runtime } = useComputeNodeState(shape);
|
|
1502
|
+
const input = runtime.inputs[DEFAULT_INPUT];
|
|
1503
|
+
const active = input?.type === "executed" ? input.value : false;
|
|
1504
|
+
const { getAverage } = useAudioStream(active);
|
|
1505
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1506
|
+
className: "flex w-full justify-center items-center bg-black",
|
|
1507
|
+
children: /* @__PURE__ */ jsx(Chaos, {
|
|
1508
|
+
active,
|
|
1509
|
+
getValue: getAverage,
|
|
1510
|
+
options: {
|
|
1511
|
+
...shaderPresets.heptapod,
|
|
1512
|
+
zoom: 1.2
|
|
1513
|
+
}
|
|
1514
|
+
})
|
|
1515
|
+
});
|
|
1516
|
+
};
|
|
1517
|
+
//#endregion
|
|
1518
|
+
//#region src/shapes/scope-def.ts
|
|
1519
|
+
var ScopeShape = Schema.extend(ComputeShape, Schema.Struct({ type: Schema.Literal("scope") }));
|
|
1520
|
+
var createScope = (props) => createShape({
|
|
1521
|
+
type: "scope",
|
|
1522
|
+
size: {
|
|
1523
|
+
width: 128,
|
|
1524
|
+
height: 128
|
|
1525
|
+
},
|
|
1526
|
+
classNames: "rounded-full border-primary-800",
|
|
1527
|
+
...props
|
|
1528
|
+
});
|
|
1529
|
+
var scopeShape = {
|
|
1530
|
+
type: "scope",
|
|
1531
|
+
name: "Scope",
|
|
1532
|
+
icon: "ph--waveform--regular",
|
|
1533
|
+
component: ScopeComponent,
|
|
1534
|
+
createShape: createScope,
|
|
1535
|
+
getAnchors: (shape) => createAnchorMap(shape, { [createAnchorId("input")]: {
|
|
1536
|
+
x: -1,
|
|
1537
|
+
y: 0
|
|
1538
|
+
} })
|
|
1539
|
+
};
|
|
1540
|
+
//#endregion
|
|
1541
|
+
//#region src/shapes/Surface.tsx
|
|
1542
|
+
var SurfaceComponent = ({ shape }) => {
|
|
1543
|
+
const { runtime } = useComputeNodeState(shape);
|
|
1544
|
+
const input = runtime.inputs[DEFAULT_INPUT];
|
|
1545
|
+
const value = input?.type === "executed" ? input.value : null;
|
|
1546
|
+
const handleAction = (action) => {
|
|
1547
|
+
if (action === "run") runtime.evalNode();
|
|
1548
|
+
};
|
|
1549
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
1550
|
+
shape,
|
|
1551
|
+
onAction: handleAction,
|
|
1552
|
+
children: /* @__PURE__ */ jsx(Card.Root, { children: value !== null && /* @__PURE__ */ jsx(Surface.Surface, {
|
|
1553
|
+
type: AppSurface.CardContent,
|
|
1554
|
+
data: { subject: value },
|
|
1555
|
+
limit: 1
|
|
1556
|
+
}) })
|
|
1557
|
+
});
|
|
1558
|
+
};
|
|
1559
|
+
//#endregion
|
|
1560
|
+
//#region src/shapes/surface-def.ts
|
|
1561
|
+
var SurfaceShape = Schema.extend(ComputeShape, Schema.Struct({ type: Schema.Literal("surface") }));
|
|
1562
|
+
var createSurface = (props) => createShape({
|
|
1563
|
+
type: "surface",
|
|
1564
|
+
size: {
|
|
1565
|
+
width: 384,
|
|
1566
|
+
height: 384
|
|
1567
|
+
},
|
|
1568
|
+
...props
|
|
1569
|
+
});
|
|
1570
|
+
var surfaceShape = {
|
|
1571
|
+
type: "surface",
|
|
1572
|
+
name: "Surface",
|
|
1573
|
+
icon: "ph--frame-corners--regular",
|
|
1574
|
+
component: SurfaceComponent,
|
|
1575
|
+
createShape: createSurface,
|
|
1576
|
+
getAnchors: (shape) => createAnchorMap(shape, { [createAnchorId("input")]: {
|
|
1577
|
+
x: -1,
|
|
1578
|
+
y: 0
|
|
1579
|
+
} }),
|
|
1580
|
+
resizable: true
|
|
1581
|
+
};
|
|
1582
|
+
//#endregion
|
|
1583
|
+
//#region src/shapes/Switch.tsx
|
|
1584
|
+
var SwitchComponent = ({ shape }) => {
|
|
1585
|
+
const { runtime } = useComputeNodeState(shape);
|
|
1586
|
+
const [value, setValue] = useState(false);
|
|
1587
|
+
useEffect(() => {
|
|
1588
|
+
runtime.setOutput(DEFAULT_OUTPUT, value);
|
|
1589
|
+
}, [value]);
|
|
1590
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1591
|
+
className: "flex w-full justify-center items-center",
|
|
1592
|
+
onClick: (ev) => ev.stopPropagation(),
|
|
1593
|
+
children: /* @__PURE__ */ jsx(Input.Root, { children: /* @__PURE__ */ jsx(Input.Switch, {
|
|
1594
|
+
checked: value,
|
|
1595
|
+
onCheckedChange: (value) => setValue(value)
|
|
1596
|
+
}) })
|
|
1597
|
+
});
|
|
1598
|
+
};
|
|
1599
|
+
//#endregion
|
|
1600
|
+
//#region src/shapes/switch-def.ts
|
|
1601
|
+
var SwitchShape = Schema.extend(ComputeShape, Schema.Struct({ type: Schema.Literal("switch") }));
|
|
1602
|
+
var createSwitch = (props) => createShape({
|
|
1603
|
+
type: "switch",
|
|
1604
|
+
size: {
|
|
1605
|
+
width: 64,
|
|
1606
|
+
height: 64
|
|
1607
|
+
},
|
|
1608
|
+
...props
|
|
1609
|
+
});
|
|
1610
|
+
var switchShape = {
|
|
1611
|
+
type: "switch",
|
|
1612
|
+
name: "Switch",
|
|
1613
|
+
icon: "ph--toggle-left--regular",
|
|
1614
|
+
component: SwitchComponent,
|
|
1615
|
+
createShape: createSwitch,
|
|
1616
|
+
getAnchors: (shape) => createAnchorMap(shape, { [createAnchorId("output")]: {
|
|
1617
|
+
x: 1,
|
|
1618
|
+
y: 0
|
|
1619
|
+
} })
|
|
1620
|
+
};
|
|
1621
|
+
//#endregion
|
|
1622
|
+
//#region src/shapes/Table.tsx
|
|
1623
|
+
var TableComponent = ({ shape }) => {
|
|
1624
|
+
return /* @__PURE__ */ jsx(Box, { shape });
|
|
1625
|
+
};
|
|
1626
|
+
//#endregion
|
|
1627
|
+
//#region src/shapes/table-def.ts
|
|
1628
|
+
var InputSchema$1 = createInputSchema(Type.getSchema(Message.Message));
|
|
1629
|
+
var OutputSchema$1 = createOutputSchema(Schema.mutable(Schema.Array(Type.getSchema(Message.Message))));
|
|
1630
|
+
var TableShape = Schema.extend(ComputeShape, Schema.Struct({ type: Schema.Literal("table") }));
|
|
1631
|
+
var createTable = (props) => createShape({
|
|
1632
|
+
type: "table",
|
|
1633
|
+
size: {
|
|
1634
|
+
width: 320,
|
|
1635
|
+
height: 512
|
|
1636
|
+
},
|
|
1637
|
+
...props
|
|
1638
|
+
});
|
|
1639
|
+
var tableShape = {
|
|
1640
|
+
type: "table",
|
|
1641
|
+
name: "Table",
|
|
1642
|
+
icon: "ph--table--regular",
|
|
1643
|
+
component: TableComponent,
|
|
1644
|
+
createShape: createTable,
|
|
1645
|
+
getAnchors: (shape) => createFunctionAnchors(shape, InputSchema$1, OutputSchema$1),
|
|
1646
|
+
resizable: true
|
|
1647
|
+
};
|
|
1648
|
+
//#endregion
|
|
1649
|
+
//#region src/shapes/Template.tsx
|
|
1650
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-canvas-compute/src/shapes/Template.tsx";
|
|
1651
|
+
var TextInputComponent$1 = ({ shape, title, ...props }) => {
|
|
1652
|
+
const { node } = useComputeNodeState(shape);
|
|
1653
|
+
const inputRef = useRef(null);
|
|
1654
|
+
const handleEnter = (text) => {
|
|
1655
|
+
const value = text.trim();
|
|
1656
|
+
if (value.length) {
|
|
1657
|
+
const schema = getTemplateInputSchema(node);
|
|
1658
|
+
node.value = value;
|
|
1659
|
+
node.inputSchema = toJsonSchema(schema);
|
|
1660
|
+
}
|
|
1661
|
+
};
|
|
1662
|
+
const handleTypeChange = (newType) => {
|
|
1663
|
+
invariant(Schema.is(ComputeValueType)(newType), "Invalid type", {
|
|
1664
|
+
"~LogMeta": "~LogMeta",
|
|
1665
|
+
F: __dxlog_file,
|
|
1666
|
+
L: 43,
|
|
1667
|
+
S: void 0,
|
|
1668
|
+
A: ["Schema.is(ComputeValueType)(newType)", "'Invalid type'"]
|
|
1669
|
+
});
|
|
1670
|
+
node.valueType = newType;
|
|
1671
|
+
node.inputSchema = toJsonSchema(getTemplateInputSchema(node));
|
|
1672
|
+
};
|
|
1673
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
1674
|
+
shape,
|
|
1675
|
+
title: "Template",
|
|
1676
|
+
status: /* @__PURE__ */ jsx(TypeSelect, {
|
|
1677
|
+
value: node.valueType ?? "string",
|
|
1678
|
+
onValueChange: handleTypeChange
|
|
1679
|
+
}),
|
|
1680
|
+
children: /* @__PURE__ */ jsx(TextBox, {
|
|
1681
|
+
...props,
|
|
1682
|
+
ref: inputRef,
|
|
1683
|
+
value: node.value,
|
|
1684
|
+
language: node.valueType === "object" ? "json" : void 0,
|
|
1685
|
+
onBlur: handleEnter,
|
|
1686
|
+
onEnter: handleEnter
|
|
1687
|
+
})
|
|
1688
|
+
});
|
|
1689
|
+
};
|
|
1690
|
+
var TemplateComponent = (props) => /* @__PURE__ */ jsx(TextInputComponent$1, {
|
|
1691
|
+
...props,
|
|
1692
|
+
placeholder: "Prompt"
|
|
1693
|
+
});
|
|
1694
|
+
//#endregion
|
|
1695
|
+
//#region src/shapes/template-def.ts
|
|
1696
|
+
var TemplateShape = Schema.extend(ComputeShape, Schema.Struct({
|
|
1697
|
+
type: Schema.Literal("template"),
|
|
1698
|
+
valueType: Schema.optional(ComputeValueType)
|
|
1699
|
+
}));
|
|
1700
|
+
var createTemplate = (props) => createShape({
|
|
1701
|
+
type: "template",
|
|
1702
|
+
size: {
|
|
1703
|
+
width: 256,
|
|
1704
|
+
height: 384
|
|
1705
|
+
},
|
|
1706
|
+
...props
|
|
1707
|
+
});
|
|
1708
|
+
var templateShape = {
|
|
1709
|
+
type: "template",
|
|
1710
|
+
name: "Template",
|
|
1711
|
+
icon: "ph--article--regular",
|
|
1712
|
+
component: TemplateComponent,
|
|
1713
|
+
createShape: createTemplate,
|
|
1714
|
+
getAnchors: (shape) => createFunctionAnchors(shape, VoidInput, TemplateOutput),
|
|
1715
|
+
resizable: true
|
|
1716
|
+
};
|
|
1717
|
+
//#endregion
|
|
1718
|
+
//#region src/shapes/Text.tsx
|
|
1719
|
+
var TextComponent = ({ shape }) => {
|
|
1720
|
+
const { runtime } = useComputeNodeState(shape);
|
|
1721
|
+
const input = runtime.inputs[DEFAULT_INPUT];
|
|
1722
|
+
const value = input?.type === "executed" ? input.value : 0;
|
|
1723
|
+
const handleAction = (action) => {
|
|
1724
|
+
if (action === "run") runtime.evalNode();
|
|
1725
|
+
};
|
|
1726
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
1727
|
+
shape,
|
|
1728
|
+
onAction: handleAction,
|
|
1729
|
+
children: /* @__PURE__ */ jsx(TextBox, { value })
|
|
1730
|
+
});
|
|
1731
|
+
};
|
|
1732
|
+
//#endregion
|
|
1733
|
+
//#region src/shapes/text-def.ts
|
|
1734
|
+
var TextShape = Schema.extend(ComputeShape, Schema.Struct({ type: Schema.Literal("text") }));
|
|
1735
|
+
var createText = (props) => createShape({
|
|
1736
|
+
type: "text",
|
|
1737
|
+
size: {
|
|
1738
|
+
width: 384,
|
|
1739
|
+
height: 384
|
|
1740
|
+
},
|
|
1741
|
+
...props
|
|
1742
|
+
});
|
|
1743
|
+
var textShape = {
|
|
1744
|
+
type: "text",
|
|
1745
|
+
name: "Text",
|
|
1746
|
+
icon: "ph--article--regular",
|
|
1747
|
+
component: TextComponent,
|
|
1748
|
+
createShape: createText,
|
|
1749
|
+
getAnchors: (shape) => createAnchorMap(shape, { [createAnchorId("input")]: {
|
|
1750
|
+
x: -1,
|
|
1751
|
+
y: 0
|
|
1752
|
+
} }),
|
|
1753
|
+
resizable: true
|
|
1754
|
+
};
|
|
1755
|
+
//#endregion
|
|
1756
|
+
//#region src/shapes/TextToImage.tsx
|
|
1757
|
+
var TextToImageComponent = ({ shape }) => {
|
|
1758
|
+
return /* @__PURE__ */ jsx(Box, { shape });
|
|
1759
|
+
};
|
|
1760
|
+
//#endregion
|
|
1761
|
+
//#region src/shapes/text-to-image-def.ts
|
|
1762
|
+
var TextToImageShape = Schema.extend(ComputeShape, Schema.Struct({ type: Schema.Literal("text-to-image") }));
|
|
1763
|
+
var createTextToImage = (props) => createShape({
|
|
1764
|
+
type: "text-to-image",
|
|
1765
|
+
size: {
|
|
1766
|
+
width: 128,
|
|
1767
|
+
height: 64
|
|
1768
|
+
},
|
|
1769
|
+
...props
|
|
1770
|
+
});
|
|
1771
|
+
var textToImageShape = {
|
|
1772
|
+
type: "text-to-image",
|
|
1773
|
+
name: "Image",
|
|
1774
|
+
icon: "ph--image--regular",
|
|
1775
|
+
component: TextToImageComponent,
|
|
1776
|
+
createShape: createTextToImage,
|
|
1777
|
+
getAnchors: (shape) => createAnchorMap(shape, { [createAnchorId("output")]: {
|
|
1778
|
+
x: 1,
|
|
1779
|
+
y: 0
|
|
1780
|
+
} })
|
|
1781
|
+
};
|
|
1782
|
+
//#endregion
|
|
1783
|
+
//#region src/shapes/Thread.tsx
|
|
1784
|
+
var ThreadComponent = ({ shape }) => {
|
|
1785
|
+
const items = [];
|
|
1786
|
+
const scrollRef = useRef(null);
|
|
1787
|
+
useEffect(() => {
|
|
1788
|
+
if (scrollRef.current) scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
|
|
1789
|
+
}, [items]);
|
|
1790
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
1791
|
+
shape,
|
|
1792
|
+
children: /* @__PURE__ */ jsx(ScrollArea.Root, {
|
|
1793
|
+
orientation: "vertical",
|
|
1794
|
+
children: /* @__PURE__ */ jsx(ScrollArea.Viewport, {
|
|
1795
|
+
classNames: "gap-2 p-2",
|
|
1796
|
+
ref: scrollRef,
|
|
1797
|
+
children: [...items].map((item, i) => /* @__PURE__ */ jsx(ThreadItem, { item }, i))
|
|
1798
|
+
})
|
|
1799
|
+
})
|
|
1800
|
+
});
|
|
1801
|
+
};
|
|
1802
|
+
var ThreadItem = ({ classNames, item }) => {
|
|
1803
|
+
if (typeof item !== "object") return /* @__PURE__ */ jsx("div", {
|
|
1804
|
+
className: mx(classNames),
|
|
1805
|
+
children: item
|
|
1806
|
+
});
|
|
1807
|
+
const { role, message } = item;
|
|
1808
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1809
|
+
className: mx("flex", classNames, role === "user" && "justify-end"),
|
|
1810
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
1811
|
+
className: mx("block rounded-md p-1 px-2 text-sm", role === "user" ? "bg-blue-100 dark:bg-blue-800" : role === "system" ? "bg-red-100, dark:bg-red-800" : "whitespace-pre-wrap bg-neutral-50 dark:bg-neutral-800"),
|
|
1812
|
+
children: message
|
|
1813
|
+
})
|
|
1814
|
+
});
|
|
1815
|
+
};
|
|
1816
|
+
//#endregion
|
|
1817
|
+
//#region src/shapes/thread-def.ts
|
|
1818
|
+
var InputSchema = createInputSchema(Type.getSchema(Message.Message));
|
|
1819
|
+
var OutputSchema = createOutputSchema(Schema.mutable(Schema.Array(Type.getSchema(Message.Message))));
|
|
1820
|
+
var ThreadShape = Schema.extend(ComputeShape, Schema.Struct({ type: Schema.Literal("thread") }));
|
|
1821
|
+
var createThread = (props) => createShape({
|
|
1822
|
+
type: "thread",
|
|
1823
|
+
size: {
|
|
1824
|
+
width: 384,
|
|
1825
|
+
height: 384
|
|
1826
|
+
},
|
|
1827
|
+
...props
|
|
1828
|
+
});
|
|
1829
|
+
var threadShape = {
|
|
1830
|
+
type: "thread",
|
|
1831
|
+
name: "Thread",
|
|
1832
|
+
icon: "ph--chats-circle--regular",
|
|
1833
|
+
component: ThreadComponent,
|
|
1834
|
+
createShape: createThread,
|
|
1835
|
+
getAnchors: (shape) => createFunctionAnchors(shape, InputSchema, OutputSchema),
|
|
1836
|
+
resizable: true
|
|
1837
|
+
};
|
|
1838
|
+
//#endregion
|
|
1839
|
+
//#region src/shapes/trigger-spec.ts
|
|
1840
|
+
var createTriggerSpec = (props) => {
|
|
1841
|
+
switch (props.triggerKind ?? "email") {
|
|
1842
|
+
case "timer": return Trigger.specTimer("*/10 * * * * *");
|
|
1843
|
+
case "webhook": return Trigger.specWebhook({ method: "POST" });
|
|
1844
|
+
case "subscription": return Trigger.specSubscription(Query.select(Filter.nothing()));
|
|
1845
|
+
case "email": return Trigger.specEmail();
|
|
1846
|
+
case "feed": return { kind: "feed" };
|
|
1847
|
+
case "direct": return Trigger.specDirect();
|
|
1848
|
+
}
|
|
1849
|
+
};
|
|
1850
|
+
var getOutputSchema = (kind) => {
|
|
1851
|
+
return {
|
|
1852
|
+
["email"]: TriggerEvent.EmailEvent,
|
|
1853
|
+
["subscription"]: TriggerEvent.SubscriptionEvent,
|
|
1854
|
+
["timer"]: TriggerEvent.TimerEvent,
|
|
1855
|
+
["webhook"]: TriggerEvent.WebhookEvent,
|
|
1856
|
+
["feed"]: TriggerEvent.FeedEvent,
|
|
1857
|
+
["direct"]: TriggerEvent.DirectEvent
|
|
1858
|
+
}[kind];
|
|
1859
|
+
};
|
|
1860
|
+
//#endregion
|
|
1861
|
+
//#region src/shapes/Trigger.tsx
|
|
1862
|
+
var TriggerComponent = ({ shape }) => {
|
|
1863
|
+
const [space] = useSpaces();
|
|
1864
|
+
const functionTrigger = shape.functionTrigger?.target;
|
|
1865
|
+
useEffect(() => {
|
|
1866
|
+
if (functionTrigger && !functionTrigger.spec) Obj.update(functionTrigger, (functionTrigger) => {
|
|
1867
|
+
functionTrigger.spec = createTriggerSpec({
|
|
1868
|
+
triggerKind: "email",
|
|
1869
|
+
spaceId: space?.id
|
|
1870
|
+
});
|
|
1871
|
+
});
|
|
1872
|
+
}, [functionTrigger, functionTrigger?.spec]);
|
|
1873
|
+
useEffect(() => {
|
|
1874
|
+
shape.size.height = getHeight(getOutputSchema(functionTrigger?.spec?.kind ?? "email"));
|
|
1875
|
+
}, [functionTrigger?.spec?.kind]);
|
|
1876
|
+
const setKind = (kind) => {
|
|
1877
|
+
if (functionTrigger?.spec?.kind !== kind) Obj.update(functionTrigger, (obj) => {
|
|
1878
|
+
obj.spec = createTriggerSpec({
|
|
1879
|
+
triggerKind: kind,
|
|
1880
|
+
spaceId: space?.id
|
|
1881
|
+
});
|
|
1882
|
+
});
|
|
1883
|
+
};
|
|
1884
|
+
if (!functionTrigger?.spec) return;
|
|
1885
|
+
return /* @__PURE__ */ jsx(FunctionBody, {
|
|
1886
|
+
shape,
|
|
1887
|
+
status: /* @__PURE__ */ jsx(TriggerKindSelect, {
|
|
1888
|
+
value: functionTrigger.spec?.kind,
|
|
1889
|
+
onValueChange: (kind) => setKind(kind)
|
|
1890
|
+
}),
|
|
1891
|
+
inputSchema: VoidInput,
|
|
1892
|
+
outputSchema: getOutputSchema(functionTrigger.spec.kind)
|
|
1893
|
+
});
|
|
1894
|
+
};
|
|
1895
|
+
var TriggerKindSelect = ({ value, onValueChange }) => {
|
|
1896
|
+
return /* @__PURE__ */ jsxs(Select.Root, {
|
|
1897
|
+
value,
|
|
1898
|
+
onValueChange,
|
|
1899
|
+
children: [/* @__PURE__ */ jsx(Select.TriggerButton, {
|
|
1900
|
+
variant: "ghost",
|
|
1901
|
+
classNames: "w-full px-0!"
|
|
1902
|
+
}), /* @__PURE__ */ jsx(Select.Portal, { children: /* @__PURE__ */ jsxs(Select.Content, { children: [
|
|
1903
|
+
/* @__PURE__ */ jsx(Select.ScrollUpButton, {}),
|
|
1904
|
+
/* @__PURE__ */ jsx(Select.Viewport, { children: Trigger.Kinds.map((kind) => /* @__PURE__ */ jsx(Select.Option, {
|
|
1905
|
+
value: kind,
|
|
1906
|
+
children: kind
|
|
1907
|
+
}, kind)) }),
|
|
1908
|
+
/* @__PURE__ */ jsx(Select.ScrollDownButton, {}),
|
|
1909
|
+
/* @__PURE__ */ jsx(Select.Arrow, {})
|
|
1910
|
+
] }) })]
|
|
1911
|
+
});
|
|
1912
|
+
};
|
|
1913
|
+
var TriggerShape = Schema.extend(ComputeShape, Schema.Struct({
|
|
1914
|
+
type: Schema.Literal("trigger"),
|
|
1915
|
+
functionTrigger: Schema.optional(Ref.Ref(Trigger.Trigger))
|
|
1916
|
+
}));
|
|
1917
|
+
var createTrigger = (props) => {
|
|
1918
|
+
const functionTrigger = Trigger.make({
|
|
1919
|
+
enabled: true,
|
|
1920
|
+
spec: createTriggerSpec(props)
|
|
1921
|
+
});
|
|
1922
|
+
return createShape({
|
|
1923
|
+
type: "trigger",
|
|
1924
|
+
functionTrigger: Ref.make(functionTrigger),
|
|
1925
|
+
size: {
|
|
1926
|
+
width: 192,
|
|
1927
|
+
height: getHeight(TriggerEvent.EmailEvent)
|
|
1928
|
+
},
|
|
1929
|
+
...props
|
|
1930
|
+
});
|
|
1931
|
+
};
|
|
1932
|
+
var triggerShape = {
|
|
1933
|
+
type: "trigger",
|
|
1934
|
+
name: "Trigger",
|
|
1935
|
+
icon: "ph--lightning--regular",
|
|
1936
|
+
component: TriggerComponent,
|
|
1937
|
+
createShape: createTrigger,
|
|
1938
|
+
getAnchors: (shape) => createFunctionAnchors(shape, VoidInput, getOutputSchema(shape.functionTrigger?.target?.spec?.kind ?? "email"))
|
|
1939
|
+
};
|
|
1940
|
+
//#endregion
|
|
1941
|
+
//#region src/shapes/Boolean.tsx
|
|
1942
|
+
var GateShape = Schema.extend(ComputeShape, Schema.Struct({ type: Schema.String }));
|
|
1943
|
+
var createGate = (props) => createShape({
|
|
1944
|
+
size: {
|
|
1945
|
+
width: 64,
|
|
1946
|
+
height: 64
|
|
1947
|
+
},
|
|
1948
|
+
...props
|
|
1949
|
+
});
|
|
1950
|
+
var defineShape = ({ type, name, icon, symbol: Symbol, createShape, inputs, outputs = [createAnchorId("output")] }) => ({
|
|
1951
|
+
type,
|
|
1952
|
+
name,
|
|
1953
|
+
icon,
|
|
1954
|
+
component: () => {
|
|
1955
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1956
|
+
className: "flex w-full justify-center items-center",
|
|
1957
|
+
children: /* @__PURE__ */ jsx(Symbol, {})
|
|
1958
|
+
});
|
|
1959
|
+
},
|
|
1960
|
+
createShape,
|
|
1961
|
+
getAnchors: (shape) => createAnchors({
|
|
1962
|
+
shape,
|
|
1963
|
+
inputs,
|
|
1964
|
+
outputs
|
|
1965
|
+
})
|
|
1966
|
+
});
|
|
1967
|
+
var createSymbol = (pathConstructor, inputs) => ({ width = 64, height = 32, className = "fill-neutral-200 dark:fill-neutral-800 stroke-neutral-500", strokeWidth = 1 }) => {
|
|
1968
|
+
const startX = width * .25;
|
|
1969
|
+
const endX = width * .75;
|
|
1970
|
+
const centerY = height / 2;
|
|
1971
|
+
const paths = pathConstructor({
|
|
1972
|
+
startX,
|
|
1973
|
+
endX,
|
|
1974
|
+
height
|
|
1975
|
+
});
|
|
1976
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
1977
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
1978
|
+
className: "h-full w-full",
|
|
1979
|
+
children: [
|
|
1980
|
+
getAnchorPoints({
|
|
1981
|
+
x: 0,
|
|
1982
|
+
y: centerY
|
|
1983
|
+
}, inputs).map(({ x, y }, i) => /* @__PURE__ */ jsx("line", {
|
|
1984
|
+
x1: x,
|
|
1985
|
+
y1: y,
|
|
1986
|
+
x2: startX * 1.3,
|
|
1987
|
+
y2: y,
|
|
1988
|
+
strokeWidth,
|
|
1989
|
+
className
|
|
1990
|
+
}, i)),
|
|
1991
|
+
/* @__PURE__ */ jsx("line", {
|
|
1992
|
+
x1: endX,
|
|
1993
|
+
y1: centerY,
|
|
1994
|
+
x2: width,
|
|
1995
|
+
y2: centerY,
|
|
1996
|
+
strokeWidth,
|
|
1997
|
+
className
|
|
1998
|
+
}),
|
|
1999
|
+
paths.map((path, i) => /* @__PURE__ */ jsx("path", {
|
|
2000
|
+
d: path,
|
|
2001
|
+
strokeWidth,
|
|
2002
|
+
className
|
|
2003
|
+
}, i))
|
|
2004
|
+
]
|
|
2005
|
+
});
|
|
2006
|
+
};
|
|
2007
|
+
var AndSymbol = createSymbol(({ startX, endX, height }) => {
|
|
2008
|
+
const arcRadius = (endX - startX) / 2;
|
|
2009
|
+
return [`
|
|
2010
|
+
M ${startX},${height * .1}
|
|
2011
|
+
L ${endX - arcRadius},${height * .1}
|
|
2012
|
+
A ${arcRadius},${height * .4} 0 0 1 ${endX - arcRadius},${height * .9}
|
|
2013
|
+
L ${startX},${height * .9}
|
|
2014
|
+
Z
|
|
2015
|
+
`];
|
|
2016
|
+
}, 2);
|
|
2017
|
+
var AndShape = GateShape;
|
|
2018
|
+
var createAnd = (props) => {
|
|
2019
|
+
return createGate({
|
|
2020
|
+
...props,
|
|
2021
|
+
type: "and"
|
|
2022
|
+
});
|
|
2023
|
+
};
|
|
2024
|
+
var andShape = defineShape({
|
|
2025
|
+
type: "and",
|
|
2026
|
+
name: "AND",
|
|
2027
|
+
icon: "ph--intersection--regular",
|
|
2028
|
+
symbol: AndSymbol,
|
|
2029
|
+
createShape: createAnd,
|
|
2030
|
+
inputs: ["input.a", "input.b"]
|
|
2031
|
+
});
|
|
2032
|
+
var OrSymbol = createSymbol(({ startX, endX, height }) => {
|
|
2033
|
+
const arcRadius = (endX - startX) / 2;
|
|
2034
|
+
return [`
|
|
2035
|
+
M ${startX},${height * .1}
|
|
2036
|
+
L ${endX - arcRadius},${height * .1}
|
|
2037
|
+
A ${arcRadius},${height * .4} 0 0 1 ${endX - arcRadius},${height * .9}
|
|
2038
|
+
L ${startX},${height * .9}
|
|
2039
|
+
C ${startX * 1.4},${height * .5} ${startX * 1.4},${height * .5} ${startX},${height * .1}
|
|
2040
|
+
Z
|
|
2041
|
+
`];
|
|
2042
|
+
}, 2);
|
|
2043
|
+
var OrShape = GateShape;
|
|
2044
|
+
var createOr = (props) => {
|
|
2045
|
+
return createGate({
|
|
2046
|
+
...props,
|
|
2047
|
+
type: "or"
|
|
2048
|
+
});
|
|
2049
|
+
};
|
|
2050
|
+
var orShape = defineShape({
|
|
2051
|
+
type: "or",
|
|
2052
|
+
name: "OR",
|
|
2053
|
+
icon: "ph--union--regular",
|
|
2054
|
+
symbol: OrSymbol,
|
|
2055
|
+
createShape: createOr,
|
|
2056
|
+
inputs: ["input.a", "input.b"]
|
|
2057
|
+
});
|
|
2058
|
+
var NotSymbol = createSymbol(({ startX, endX, height }) => {
|
|
2059
|
+
return [`
|
|
2060
|
+
M ${startX},${height * .1}
|
|
2061
|
+
L ${endX * .9},${height * .5}
|
|
2062
|
+
L ${startX},${height * .9}
|
|
2063
|
+
Z
|
|
2064
|
+
`, `
|
|
2065
|
+
M ${endX - height * .2},${height * .5}
|
|
2066
|
+
A ${height * .1} ${height * .1} 0 0 1 ${endX},${height * .5}
|
|
2067
|
+
A ${height * .1} ${height * .1} 0 0 1 ${endX - height * .2},${height * .5}
|
|
2068
|
+
Z
|
|
2069
|
+
`];
|
|
2070
|
+
}, 1);
|
|
2071
|
+
var NotShape = GateShape;
|
|
2072
|
+
var createNot = (props) => {
|
|
2073
|
+
return createGate({
|
|
2074
|
+
...props,
|
|
2075
|
+
type: "not"
|
|
2076
|
+
});
|
|
2077
|
+
};
|
|
2078
|
+
var notShape = defineShape({
|
|
2079
|
+
type: "not",
|
|
2080
|
+
name: "NOT",
|
|
2081
|
+
icon: "ph--x--regular",
|
|
2082
|
+
symbol: NotSymbol,
|
|
2083
|
+
createShape: createNot,
|
|
2084
|
+
inputs: [createAnchorId("input")]
|
|
2085
|
+
});
|
|
2086
|
+
//#endregion
|
|
2087
|
+
//#region src/registry.ts
|
|
2088
|
+
/**
|
|
2089
|
+
* Order used by toolbar.
|
|
2090
|
+
*/
|
|
2091
|
+
var computeShapes = [
|
|
2092
|
+
{
|
|
2093
|
+
title: "Inputs",
|
|
2094
|
+
shapes: [
|
|
2095
|
+
constantShape,
|
|
2096
|
+
templateShape,
|
|
2097
|
+
chatShape,
|
|
2098
|
+
switchShape,
|
|
2099
|
+
audioShape,
|
|
2100
|
+
triggerShape,
|
|
2101
|
+
randomShape
|
|
2102
|
+
]
|
|
2103
|
+
},
|
|
2104
|
+
{
|
|
2105
|
+
title: "Transform",
|
|
2106
|
+
shapes: [
|
|
2107
|
+
gptShape,
|
|
2108
|
+
gptRealtimeShape,
|
|
2109
|
+
functionShape,
|
|
2110
|
+
databaseShape,
|
|
2111
|
+
textToImageShape,
|
|
2112
|
+
appendShape
|
|
2113
|
+
]
|
|
2114
|
+
},
|
|
2115
|
+
{
|
|
2116
|
+
title: "Operations",
|
|
2117
|
+
shapes: [
|
|
2118
|
+
ifShape,
|
|
2119
|
+
ifElseShape,
|
|
2120
|
+
andShape,
|
|
2121
|
+
orShape,
|
|
2122
|
+
notShape,
|
|
2123
|
+
reducerShape,
|
|
2124
|
+
jsonTransformShape
|
|
2125
|
+
]
|
|
2126
|
+
},
|
|
2127
|
+
{
|
|
2128
|
+
title: "Outputs",
|
|
2129
|
+
shapes: [
|
|
2130
|
+
jsonShape,
|
|
2131
|
+
feedShape,
|
|
2132
|
+
threadShape,
|
|
2133
|
+
textShape,
|
|
2134
|
+
surfaceShape,
|
|
2135
|
+
beaconShape,
|
|
2136
|
+
scopeShape
|
|
2137
|
+
]
|
|
2138
|
+
},
|
|
2139
|
+
{
|
|
2140
|
+
title: "Misc",
|
|
2141
|
+
shapes: [noteShape]
|
|
2142
|
+
}
|
|
2143
|
+
];
|
|
2144
|
+
//#endregion
|
|
2145
|
+
//#region src/compute-layout.ts
|
|
2146
|
+
var ComputeShapeLayout = class extends ShapeLayout {
|
|
2147
|
+
_controller;
|
|
2148
|
+
constructor(_controller, registry) {
|
|
2149
|
+
super(registry);
|
|
2150
|
+
this._controller = _controller;
|
|
2151
|
+
}
|
|
2152
|
+
getAnchors(shape) {
|
|
2153
|
+
let anchors = this._registry.getShapeDef(shape.type)?.getAnchors?.(shape) ?? {};
|
|
2154
|
+
if (shape.node) {
|
|
2155
|
+
const node = this._controller.graph.getNode(shape.node);
|
|
2156
|
+
if (node.inputSchema || node.outputSchema) anchors = createFunctionAnchors(shape, node.inputSchema ? toEffectSchema(node.inputSchema) : DefaultInput, node.outputSchema ? toEffectSchema(node.outputSchema) : DefaultOutput);
|
|
2157
|
+
}
|
|
2158
|
+
return anchors;
|
|
2159
|
+
}
|
|
2160
|
+
};
|
|
2161
|
+
//#endregion
|
|
2162
|
+
export { AndShape, AppendComponent, AppendShape, AudioComponent, AudioShape, BeaconComponent, BeaconShape, Box, ChatShape, ComputeContext, ComputeGraphController, ComputeShape, ComputeShapeLayout, ConstantComponent, ConstantShape, DatabaseComponent, DatabaseShape, FeedComponent, FeedItem, FeedShape, FunctionBody, FunctionShape, FunctionShapeComponent, GptComponent, GptRealtimeComponent, GptRealtimeShape, GptShape, IfComponent, IfElseComponent, IfElseShape, IfShape, InvalidStateError, JsonComponent, JsonShape, JsonTransformComponent, JsonTransformShape, NotShape, OrShape, RandomComponent, RandomShape, ReducerComponent, ReducerShape, ScopeComponent, ScopeShape, SurfaceComponent, SurfaceShape, SwitchComponent, SwitchShape, TableComponent, TableShape, TemplateComponent, TemplateShape, TextComponent, TextInputComponent, TextShape, TextToImageComponent, TextToImageShape, ThreadComponent, ThreadItem, ThreadShape, TriggerComponent, TriggerShape, TypeSelect, andShape, appendShape, audioShape, beaconShape, bodyPadding, chatShape, computeShapes, constantShape, createAnchorId, createAnd, createAppend, createAudio, createBeacon, createChat, createComputeGraph, createComputeGraphController, createComputeNode, createConstant, createDatabase, createFeed, createFunction, createFunctionAnchors, createGpt, createGptRealtime, createIf, createIfElse, createJson, createJsonTransform, createNot, createOr, createRandom, createReducer, createScope, createShape, createSurface, createSwitch, createTable, createTemplate, createText, createTextToImage, createThread, createTrigger, databaseShape, feedShape, footerHeight, functionShape, getHeight, getProperties, gptRealtimeShape, gptShape, headerHeight, ifElseShape, ifShape, isValidComputeNode, jsonShape, jsonTransformShape, mapEdge, notShape, orShape, parseAnchorId, randomShape, reducerShape, resolveComputeNode, scopeShape, surfaceShape, switchShape, tableShape, templateShape, textShape, textToImageShape, threadShape, triggerShape, useComputeContext, useComputeGraphController, useComputeNodeState, useGraphMonitor };
|
|
2163
|
+
|
|
2164
|
+
//# sourceMappingURL=index.mjs.map
|