@dxos/react-ui-canvas-compute 0.8.1-main.ae460ac → 0.8.1-staging.31c3ee1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/index.mjs +84 -33
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +231 -181
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +84 -33
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/DiagnosticOverlay.d.ts +2 -1
- package/dist/types/src/components/DiagnosticOverlay.d.ts.map +1 -1
- package/dist/types/src/compute.stories.d.ts +1 -1
- package/dist/types/src/compute.stories.d.ts.map +1 -1
- package/dist/types/src/graph/controller.d.ts +7 -6
- package/dist/types/src/graph/controller.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +1 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useComputeGraphController.d.ts +10 -0
- package/dist/types/src/hooks/useComputeGraphController.d.ts.map +1 -0
- package/dist/types/src/shapes/Append.d.ts +2 -1
- package/dist/types/src/shapes/Append.d.ts.map +1 -1
- package/dist/types/src/shapes/Array.d.ts +2 -1
- package/dist/types/src/shapes/Array.d.ts.map +1 -1
- package/dist/types/src/shapes/Audio.d.ts +2 -1
- package/dist/types/src/shapes/Audio.d.ts.map +1 -1
- package/dist/types/src/shapes/Beacon.d.ts +2 -1
- package/dist/types/src/shapes/Beacon.d.ts.map +1 -1
- package/dist/types/src/shapes/Chat.d.ts +2 -1
- package/dist/types/src/shapes/Chat.d.ts.map +1 -1
- package/dist/types/src/shapes/Constant.d.ts +2 -1
- package/dist/types/src/shapes/Constant.d.ts.map +1 -1
- package/dist/types/src/shapes/Database.d.ts +2 -1
- package/dist/types/src/shapes/Database.d.ts.map +1 -1
- package/dist/types/src/shapes/Function.d.ts.map +1 -1
- package/dist/types/src/shapes/Gpt.d.ts +2 -1
- package/dist/types/src/shapes/Gpt.d.ts.map +1 -1
- package/dist/types/src/shapes/GptRealtime.d.ts +2 -1
- package/dist/types/src/shapes/GptRealtime.d.ts.map +1 -1
- package/dist/types/src/shapes/Json.d.ts +3 -2
- package/dist/types/src/shapes/Json.d.ts.map +1 -1
- package/dist/types/src/shapes/Logic.d.ts +3 -2
- package/dist/types/src/shapes/Logic.d.ts.map +1 -1
- package/dist/types/src/shapes/Queue.d.ts +3 -2
- package/dist/types/src/shapes/Queue.d.ts.map +1 -1
- package/dist/types/src/shapes/RNG.d.ts +2 -1
- package/dist/types/src/shapes/RNG.d.ts.map +1 -1
- package/dist/types/src/shapes/Scope.d.ts +2 -1
- package/dist/types/src/shapes/Scope.d.ts.map +1 -1
- package/dist/types/src/shapes/Surface.d.ts +2 -1
- package/dist/types/src/shapes/Surface.d.ts.map +1 -1
- package/dist/types/src/shapes/Switch.d.ts +2 -1
- package/dist/types/src/shapes/Switch.d.ts.map +1 -1
- package/dist/types/src/shapes/Table.d.ts +2 -1
- package/dist/types/src/shapes/Table.d.ts.map +1 -1
- package/dist/types/src/shapes/Text.d.ts +2 -1
- package/dist/types/src/shapes/Text.d.ts.map +1 -1
- package/dist/types/src/shapes/TextToImage.d.ts +2 -1
- package/dist/types/src/shapes/TextToImage.d.ts.map +1 -1
- package/dist/types/src/shapes/Thread.d.ts +3 -2
- package/dist/types/src/shapes/Thread.d.ts.map +1 -1
- package/dist/types/src/shapes/Trigger.d.ts +4 -3
- package/dist/types/src/shapes/Trigger.d.ts.map +1 -1
- package/dist/types/src/shapes/common/FunctionBody.d.ts +1 -1
- package/dist/types/src/shapes/common/FunctionBody.d.ts.map +1 -1
- package/dist/types/src/shapes/common/TypeSelect.d.ts +2 -1
- package/dist/types/src/shapes/common/TypeSelect.d.ts.map +1 -1
- package/dist/types/src/testing/circuits.d.ts +19 -3
- package/dist/types/src/testing/circuits.d.ts.map +1 -1
- package/package.json +40 -40
- package/src/compute.stories.tsx +8 -54
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useComputeGraphController.ts +65 -0
- package/src/shapes/Function.tsx +3 -3
- package/src/shapes/Trigger.tsx +1 -1
- package/src/testing/circuits.ts +4 -1
|
@@ -91,8 +91,58 @@ var useComputeContext = () => {
|
|
|
91
91
|
return useContext(ComputeContext) ?? raise2(new Error("Missing ComputeContext"));
|
|
92
92
|
};
|
|
93
93
|
|
|
94
|
+
// packages/ui/react-ui-canvas-compute/src/hooks/useComputeGraphController.ts
|
|
95
|
+
import { useEffect, useState } from "react";
|
|
96
|
+
var combine = (...cbs) => {
|
|
97
|
+
return () => {
|
|
98
|
+
for (const cb of cbs) {
|
|
99
|
+
cb();
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
var useComputeGraphController = ({ controller, graph, editorRef }) => {
|
|
104
|
+
const [, forceUpdate] = useState({});
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (!controller || !graph) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
void controller.open();
|
|
110
|
+
const off = combine(
|
|
111
|
+
controller.update.on(() => {
|
|
112
|
+
void editorRef.current?.update();
|
|
113
|
+
forceUpdate({});
|
|
114
|
+
}),
|
|
115
|
+
// TODO(burdon): Every node is called on every update.
|
|
116
|
+
controller.output.on(({ nodeId, property, value }) => {
|
|
117
|
+
if (value.type === "not-executed") {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const edge = graph.edges.find((edge2) => {
|
|
121
|
+
const source = graph.getNode(edge2.source);
|
|
122
|
+
return source.node === nodeId && edge2.output === property;
|
|
123
|
+
});
|
|
124
|
+
if (edge) {
|
|
125
|
+
void editorRef.current?.action?.({
|
|
126
|
+
type: "trigger",
|
|
127
|
+
edges: [
|
|
128
|
+
edge
|
|
129
|
+
]
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
);
|
|
134
|
+
return () => {
|
|
135
|
+
void controller.close();
|
|
136
|
+
off();
|
|
137
|
+
};
|
|
138
|
+
}, [
|
|
139
|
+
graph,
|
|
140
|
+
controller
|
|
141
|
+
]);
|
|
142
|
+
};
|
|
143
|
+
|
|
94
144
|
// packages/ui/react-ui-canvas-compute/src/hooks/useComputeNodeState.ts
|
|
95
|
-
import { useCallback, useEffect, useState } from "react";
|
|
145
|
+
import { useCallback, useEffect as useEffect2, useState as useState2 } from "react";
|
|
96
146
|
import { S } from "@dxos/echo-schema";
|
|
97
147
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
98
148
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-canvas-compute/src/hooks/useComputeNodeState.ts";
|
|
@@ -107,8 +157,8 @@ var useComputeNodeState = (shape) => {
|
|
|
107
157
|
""
|
|
108
158
|
]
|
|
109
159
|
});
|
|
110
|
-
const [meta, setMeta] =
|
|
111
|
-
|
|
160
|
+
const [meta, setMeta] = useState2();
|
|
161
|
+
useEffect2(() => {
|
|
112
162
|
let disposed = false;
|
|
113
163
|
queueMicrotask(async () => {
|
|
114
164
|
invariant2(shape.node, "Node not specified", {
|
|
@@ -664,7 +714,7 @@ var Box = /* @__PURE__ */ forwardRef(({ children, classNames, shape, title, stat
|
|
|
664
714
|
});
|
|
665
715
|
|
|
666
716
|
// packages/ui/react-ui-canvas-compute/src/shapes/common/FunctionBody.tsx
|
|
667
|
-
import React2, { useRef, useState as
|
|
717
|
+
import React2, { useRef, useState as useState3 } from "react";
|
|
668
718
|
import { VoidInput, VoidOutput } from "@dxos/conductor";
|
|
669
719
|
import { AST as AST2 } from "@dxos/echo-schema";
|
|
670
720
|
import { useCanvasContext } from "@dxos/react-ui-canvas";
|
|
@@ -708,7 +758,7 @@ var expandedHeight = 200;
|
|
|
708
758
|
var FunctionBody = ({ shape, name, content, inputSchema = VoidInput, outputSchema = VoidOutput, ...props }) => {
|
|
709
759
|
const { scale } = useCanvasContext();
|
|
710
760
|
const rootRef = useRef(null);
|
|
711
|
-
const [open, setOpen] =
|
|
761
|
+
const [open, setOpen] = useState3(false);
|
|
712
762
|
const handleAction = (action) => {
|
|
713
763
|
if (!rootRef.current) {
|
|
714
764
|
return;
|
|
@@ -863,7 +913,7 @@ var appendShape = {
|
|
|
863
913
|
};
|
|
864
914
|
|
|
865
915
|
// packages/ui/react-ui-canvas-compute/src/shapes/Audio.tsx
|
|
866
|
-
import React6, { useEffect as
|
|
916
|
+
import React6, { useEffect as useEffect3, useState as useState4 } from "react";
|
|
867
917
|
import { S as S5 } from "@dxos/echo-schema";
|
|
868
918
|
import { Icon as Icon2 } from "@dxos/react-ui";
|
|
869
919
|
import { createAnchorMap } from "@dxos/react-ui-canvas-editor";
|
|
@@ -880,8 +930,8 @@ var createAudio = (props) => createShape({
|
|
|
880
930
|
});
|
|
881
931
|
var AudioComponent = ({ shape }) => {
|
|
882
932
|
const { node } = useComputeNodeState(shape);
|
|
883
|
-
const [active, setActive] =
|
|
884
|
-
|
|
933
|
+
const [active, setActive] = useState4(false);
|
|
934
|
+
useEffect3(() => {
|
|
885
935
|
node.value = active;
|
|
886
936
|
}, [
|
|
887
937
|
active
|
|
@@ -1183,7 +1233,7 @@ var chatShape = {
|
|
|
1183
1233
|
};
|
|
1184
1234
|
|
|
1185
1235
|
// packages/ui/react-ui-canvas-compute/src/shapes/Constant.tsx
|
|
1186
|
-
import React10, { useCallback as useCallback2, useRef as useRef3, useState as
|
|
1236
|
+
import React10, { useCallback as useCallback2, useRef as useRef3, useState as useState5 } from "react";
|
|
1187
1237
|
import { ComputeValueType as ComputeValueType2 } from "@dxos/conductor";
|
|
1188
1238
|
import { S as S9 } from "@dxos/echo-schema";
|
|
1189
1239
|
import { Input } from "@dxos/react-ui";
|
|
@@ -1207,7 +1257,7 @@ var inferType = (value) => {
|
|
|
1207
1257
|
};
|
|
1208
1258
|
var ConstantComponent = ({ shape, title, chat, ...props }) => {
|
|
1209
1259
|
const { node } = useComputeNodeState(shape);
|
|
1210
|
-
const [type, setType] =
|
|
1260
|
+
const [type, setType] = useState5(inferType(node.value) ?? ComputeValueType2.literals[0]);
|
|
1211
1261
|
const inputRef = useRef3(null);
|
|
1212
1262
|
const handleEnter = useCallback2((text) => {
|
|
1213
1263
|
const value = text.trim();
|
|
@@ -1316,8 +1366,8 @@ var databaseShape = {
|
|
|
1316
1366
|
// packages/ui/react-ui-canvas-compute/src/shapes/Function.tsx
|
|
1317
1367
|
import React12, { useCallback as useCallback3, useRef as useRef4 } from "react";
|
|
1318
1368
|
import { AnyOutput, FunctionInput } from "@dxos/conductor";
|
|
1319
|
-
import { getSnapshot, S as S11 } from "@dxos/echo-schema";
|
|
1320
|
-
import { FunctionType, ScriptType } from "@dxos/functions";
|
|
1369
|
+
import { getSnapshot, isInstanceOf, S as S11 } from "@dxos/echo-schema";
|
|
1370
|
+
import { FunctionType, ScriptType } from "@dxos/functions/types";
|
|
1321
1371
|
import { useClient } from "@dxos/react-client";
|
|
1322
1372
|
import { Filter, makeRef, parseId } from "@dxos/react-client/echo";
|
|
1323
1373
|
import { TextBox as TextBox3 } from "@dxos/react-ui-canvas-editor";
|
|
@@ -1344,7 +1394,7 @@ var TextInputComponent2 = ({ shape, title, ...props }) => {
|
|
|
1344
1394
|
}
|
|
1345
1395
|
const space = client.spaces.get(spaceId);
|
|
1346
1396
|
const object = space?.db.getObjectById(objectId);
|
|
1347
|
-
if (!space || !(object
|
|
1397
|
+
if (!space || !isInstanceOf(ScriptType, object)) {
|
|
1348
1398
|
return;
|
|
1349
1399
|
}
|
|
1350
1400
|
const { objects: [fn] } = await space.db.query(Filter.schema(FunctionType, {
|
|
@@ -1392,7 +1442,7 @@ var functionShape = {
|
|
|
1392
1442
|
};
|
|
1393
1443
|
|
|
1394
1444
|
// packages/ui/react-ui-canvas-compute/src/shapes/Gpt.tsx
|
|
1395
|
-
import React13, { useEffect as
|
|
1445
|
+
import React13, { useEffect as useEffect4, useState as useState6 } from "react";
|
|
1396
1446
|
import { GptInput, GptOutput } from "@dxos/conductor";
|
|
1397
1447
|
import { S as S12 } from "@dxos/echo-schema";
|
|
1398
1448
|
var GptShape = S12.extend(ComputeShape, S12.Struct({
|
|
@@ -1408,9 +1458,9 @@ var createGpt = (props) => createShape({
|
|
|
1408
1458
|
});
|
|
1409
1459
|
var GptComponent = ({ shape }) => {
|
|
1410
1460
|
const { meta, runtime } = useComputeNodeState(shape);
|
|
1411
|
-
const [text, setText] =
|
|
1412
|
-
const [tokens, setTokens] =
|
|
1413
|
-
|
|
1461
|
+
const [text, setText] = useState6("");
|
|
1462
|
+
const [tokens, setTokens] = useState6(0);
|
|
1463
|
+
useEffect4(() => {
|
|
1414
1464
|
return runtime.subscribeToEventLog((ev) => {
|
|
1415
1465
|
switch (ev.type) {
|
|
1416
1466
|
case "begin-compute": {
|
|
@@ -1653,7 +1703,7 @@ var queueShape = {
|
|
|
1653
1703
|
};
|
|
1654
1704
|
|
|
1655
1705
|
// packages/ui/react-ui-canvas-compute/src/shapes/RNG.tsx
|
|
1656
|
-
import React17, { useEffect as
|
|
1706
|
+
import React17, { useEffect as useEffect5, useState as useState7 } from "react";
|
|
1657
1707
|
import { DEFAULT_OUTPUT as DEFAULT_OUTPUT5 } from "@dxos/conductor";
|
|
1658
1708
|
import { S as S16 } from "@dxos/echo-schema";
|
|
1659
1709
|
import { Icon as Icon4 } from "@dxos/react-ui";
|
|
@@ -1683,9 +1733,9 @@ var icons = [
|
|
|
1683
1733
|
var pickIcon = () => icons[Math.floor(Math.random() * icons.length)];
|
|
1684
1734
|
var RandomComponent = ({ shape }) => {
|
|
1685
1735
|
const { runtime } = useComputeNodeState(shape);
|
|
1686
|
-
const [spin, setSpin] =
|
|
1687
|
-
const [icon, setIcon] =
|
|
1688
|
-
|
|
1736
|
+
const [spin, setSpin] = useState7(false);
|
|
1737
|
+
const [icon, setIcon] = useState7(pickIcon());
|
|
1738
|
+
useEffect5(() => {
|
|
1689
1739
|
if (!spin) {
|
|
1690
1740
|
return;
|
|
1691
1741
|
}
|
|
@@ -1829,7 +1879,7 @@ var surfaceShape = {
|
|
|
1829
1879
|
};
|
|
1830
1880
|
|
|
1831
1881
|
// packages/ui/react-ui-canvas-compute/src/shapes/Switch.tsx
|
|
1832
|
-
import React20, { useEffect as
|
|
1882
|
+
import React20, { useEffect as useEffect6, useState as useState8 } from "react";
|
|
1833
1883
|
import { DEFAULT_OUTPUT as DEFAULT_OUTPUT6 } from "@dxos/conductor";
|
|
1834
1884
|
import { S as S19 } from "@dxos/echo-schema";
|
|
1835
1885
|
import { Input as Input2 } from "@dxos/react-ui";
|
|
@@ -1847,8 +1897,8 @@ var createSwitch = (props) => createShape({
|
|
|
1847
1897
|
});
|
|
1848
1898
|
var SwitchComponent = ({ shape }) => {
|
|
1849
1899
|
const { runtime } = useComputeNodeState(shape);
|
|
1850
|
-
const [value, setValue] =
|
|
1851
|
-
|
|
1900
|
+
const [value, setValue] = useState8(false);
|
|
1901
|
+
useEffect6(() => {
|
|
1852
1902
|
runtime.setOutput(DEFAULT_OUTPUT6, value);
|
|
1853
1903
|
}, [
|
|
1854
1904
|
value
|
|
@@ -2028,7 +2078,7 @@ var textShape = {
|
|
|
2028
2078
|
};
|
|
2029
2079
|
|
|
2030
2080
|
// packages/ui/react-ui-canvas-compute/src/shapes/Thread.tsx
|
|
2031
|
-
import React24, { useEffect as
|
|
2081
|
+
import React24, { useEffect as useEffect7, useRef as useRef6 } from "react";
|
|
2032
2082
|
import { createInputSchema as createInputSchema2, createOutputSchema as createOutputSchema2, GptMessage as GptMessage2 } from "@dxos/conductor";
|
|
2033
2083
|
import { S as S23 } from "@dxos/echo-schema";
|
|
2034
2084
|
import { mx as mx5 } from "@dxos/react-ui-theme";
|
|
@@ -2048,7 +2098,7 @@ var createThread = (props) => createShape({
|
|
|
2048
2098
|
var ThreadComponent = ({ shape }) => {
|
|
2049
2099
|
const items = [];
|
|
2050
2100
|
const scrollRef = useRef6(null);
|
|
2051
|
-
|
|
2101
|
+
useEffect7(() => {
|
|
2052
2102
|
if (scrollRef.current) {
|
|
2053
2103
|
scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
|
|
2054
2104
|
}
|
|
@@ -2125,10 +2175,10 @@ var textToImageShape = {
|
|
|
2125
2175
|
};
|
|
2126
2176
|
|
|
2127
2177
|
// packages/ui/react-ui-canvas-compute/src/shapes/Trigger.tsx
|
|
2128
|
-
import React26, { useEffect as
|
|
2178
|
+
import React26, { useEffect as useEffect8 } from "react";
|
|
2129
2179
|
import { EmailTriggerOutput, QueueTriggerOutput, SubscriptionTriggerOutput, TimerTriggerOutput, VoidInput as VoidInput3, WebhookTriggerOutput } from "@dxos/conductor";
|
|
2130
2180
|
import { ObjectId as ObjectId4, Ref, S as S25 } from "@dxos/echo-schema";
|
|
2131
|
-
import { FunctionTrigger, TriggerKind } from "@dxos/functions";
|
|
2181
|
+
import { FunctionTrigger, TriggerKind } from "@dxos/functions/types";
|
|
2132
2182
|
import { DXN as DXN2, SpaceId } from "@dxos/keys";
|
|
2133
2183
|
import { create, makeRef as makeRef2, useSpace } from "@dxos/react-client/echo";
|
|
2134
2184
|
import { Select as Select2 } from "@dxos/react-ui";
|
|
@@ -2154,7 +2204,7 @@ var createTrigger = (props) => {
|
|
|
2154
2204
|
var TriggerComponent = ({ shape }) => {
|
|
2155
2205
|
const space = useSpace();
|
|
2156
2206
|
const functionTrigger = shape.functionTrigger?.target;
|
|
2157
|
-
|
|
2207
|
+
useEffect8(() => {
|
|
2158
2208
|
if (functionTrigger && !functionTrigger.spec) {
|
|
2159
2209
|
functionTrigger.spec = createTriggerSpec({
|
|
2160
2210
|
triggerKind: TriggerKind.Email,
|
|
@@ -2165,7 +2215,7 @@ var TriggerComponent = ({ shape }) => {
|
|
|
2165
2215
|
functionTrigger,
|
|
2166
2216
|
functionTrigger?.spec
|
|
2167
2217
|
]);
|
|
2168
|
-
|
|
2218
|
+
useEffect8(() => {
|
|
2169
2219
|
shape.size.height = getHeight(getOutputSchema(functionTrigger?.spec?.type ?? TriggerKind.Email));
|
|
2170
2220
|
}, [
|
|
2171
2221
|
functionTrigger?.spec?.type
|
|
@@ -2258,7 +2308,7 @@ var triggerShape = {
|
|
|
2258
2308
|
};
|
|
2259
2309
|
|
|
2260
2310
|
// packages/ui/react-ui-canvas-compute/src/shapes/GptRealtime.tsx
|
|
2261
|
-
import React27, { useState as
|
|
2311
|
+
import React27, { useState as useState9 } from "react";
|
|
2262
2312
|
import { S as S26 } from "@dxos/echo-schema";
|
|
2263
2313
|
import { log as log2 } from "@dxos/log";
|
|
2264
2314
|
import { useConfig } from "@dxos/react-client";
|
|
@@ -2276,8 +2326,8 @@ var createGptRealtime = (props) => createShape({
|
|
|
2276
2326
|
...props
|
|
2277
2327
|
});
|
|
2278
2328
|
var GptRealtimeComponent = ({ shape }) => {
|
|
2279
|
-
const [isLive, setIsLive] =
|
|
2280
|
-
const [isReady, setIsReady] =
|
|
2329
|
+
const [isLive, setIsLive] = useState9(false);
|
|
2330
|
+
const [isReady, setIsReady] = useState9(false);
|
|
2281
2331
|
const config = useConfig();
|
|
2282
2332
|
const start = async () => {
|
|
2283
2333
|
setIsLive(true);
|
|
@@ -2605,6 +2655,7 @@ export {
|
|
|
2605
2655
|
threadShape,
|
|
2606
2656
|
triggerShape,
|
|
2607
2657
|
useComputeContext,
|
|
2658
|
+
useComputeGraphController,
|
|
2608
2659
|
useComputeNodeState,
|
|
2609
2660
|
useGraphMonitor
|
|
2610
2661
|
};
|