@dxos/react-ui-canvas-compute 0.7.5-labs.8a82073 → 0.7.5-labs.c0e040f
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 +87 -32
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +119 -65
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +87 -32
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/graph/controller.d.ts +16 -0
- package/dist/types/src/graph/controller.d.ts.map +1 -1
- package/dist/types/src/shapes/Function.d.ts +1 -3
- package/dist/types/src/shapes/Function.d.ts.map +1 -1
- package/dist/types/src/shapes/common/FunctionBody.d.ts.map +1 -1
- package/package.json +40 -40
- package/src/graph/controller.ts +14 -3
- package/src/hooks/useGraphMonitor.ts +2 -2
- package/src/shapes/Function.tsx +83 -9
- package/src/shapes/common/FunctionBody.tsx +1 -0
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import "@dxos/node-std/globals";
|
|
2
2
|
|
|
3
3
|
// packages/ui/react-ui-canvas-compute/src/graph/controller.ts
|
|
4
|
+
import { FetchHttpClient } from "@effect/platform";
|
|
4
5
|
import { Effect, Either, Exit, Layer, Scope } from "effect";
|
|
5
6
|
import { Event, synchronized } from "@dxos/async";
|
|
6
|
-
import { isNotExecuted, makeValueBag, EventLogger, GptService, GraphExecutor, MockGpt, QueueService, SpaceService } from "@dxos/conductor";
|
|
7
|
+
import { isNotExecuted, makeValueBag, EventLogger, GptService, GraphExecutor, MockGpt, QueueService, SpaceService, FunctionCallService } from "@dxos/conductor";
|
|
7
8
|
import { Resource } from "@dxos/context";
|
|
8
9
|
import { log } from "@dxos/log";
|
|
9
10
|
|
|
@@ -171,7 +172,7 @@ import { ObjectId as ObjectId2 } from "@dxos/echo-schema";
|
|
|
171
172
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
172
173
|
import { DXN } from "@dxos/keys";
|
|
173
174
|
import { getSpace } from "@dxos/react-client/echo";
|
|
174
|
-
import {
|
|
175
|
+
import { isNonNullable } from "@dxos/util";
|
|
175
176
|
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-canvas-compute/src/hooks/useGraphMonitor.ts";
|
|
176
177
|
var mapEdge = (graph, { source, target, output = DEFAULT_OUTPUT, input = DEFAULT_INPUT }) => {
|
|
177
178
|
const sourceNode = graph.findNode(source);
|
|
@@ -238,7 +239,7 @@ var useGraphMonitor = (model) => {
|
|
|
238
239
|
const nodeIds = subgraph.nodes.map((shape) => shape.node);
|
|
239
240
|
const edgeIds = subgraph.edges.map(({ source, target, output = DEFAULT_OUTPUT, input = DEFAULT_INPUT }) => {
|
|
240
241
|
return model.edges.find((computeEdge) => computeEdge.input === input && computeEdge.output === output)?.id;
|
|
241
|
-
}).filter(
|
|
242
|
+
}).filter(isNonNullable);
|
|
242
243
|
model.removeNodes(nodeIds);
|
|
243
244
|
model.removeEdges(edgeIds);
|
|
244
245
|
deleteTriggerObjects(model, subgraph);
|
|
@@ -343,6 +344,14 @@ var ComputeGraphController = class extends Resource {
|
|
|
343
344
|
};
|
|
344
345
|
}
|
|
345
346
|
setServices(services) {
|
|
347
|
+
log.info("setServices", {
|
|
348
|
+
services
|
|
349
|
+
}, {
|
|
350
|
+
F: __dxlog_file4,
|
|
351
|
+
L: 149,
|
|
352
|
+
S: this,
|
|
353
|
+
C: (f, a) => f(...a)
|
|
354
|
+
});
|
|
346
355
|
Object.assign(this._services, services);
|
|
347
356
|
}
|
|
348
357
|
get graph() {
|
|
@@ -403,7 +412,7 @@ var ComputeGraphController = class extends Resource {
|
|
|
403
412
|
} catch (err) {
|
|
404
413
|
log.catch(err, void 0, {
|
|
405
414
|
F: __dxlog_file4,
|
|
406
|
-
L:
|
|
415
|
+
L: 218,
|
|
407
416
|
S: this,
|
|
408
417
|
C: (f, a) => f(...a)
|
|
409
418
|
});
|
|
@@ -430,7 +439,7 @@ var ComputeGraphController = class extends Resource {
|
|
|
430
439
|
const scope = yield* Scope.make();
|
|
431
440
|
const executable = yield* Effect.promise(() => resolveComputeNode(this._graph.getNode(nodeId)));
|
|
432
441
|
const computingOutputs = executable.exec != null;
|
|
433
|
-
const effect = (computingOutputs ? executor.computeOutputs(nodeId) : executor.computeInputs(nodeId)).pipe(Effect.withSpan("runGraph"),
|
|
442
|
+
const effect = (computingOutputs ? executor.computeOutputs(nodeId) : executor.computeInputs(nodeId)).pipe(Effect.withSpan("runGraph"), Scope.extend(scope), Effect.flatMap(computeValueBag), Effect.provide(services), Effect.withSpan("test"), Effect.tap((values) => {
|
|
434
443
|
for (const [key, value] of Object.entries(values)) {
|
|
435
444
|
if (computingOutputs) {
|
|
436
445
|
this._onOutputComputed(nodeId, key, value);
|
|
@@ -469,7 +478,7 @@ var ComputeGraphController = class extends Resource {
|
|
|
469
478
|
for (const node of allAffectedNodes) {
|
|
470
479
|
const executable = yield* Effect.promise(() => resolveComputeNode(this._graph.getNode(node)));
|
|
471
480
|
const computingOutputs = executable.exec != null;
|
|
472
|
-
const effect = (computingOutputs ? executor.computeOutputs(node) : executor.computeInputs(node)).pipe(Effect.withSpan("runGraph"),
|
|
481
|
+
const effect = (computingOutputs ? executor.computeOutputs(node) : executor.computeInputs(node)).pipe(Effect.withSpan("runGraph"), Scope.extend(scope), Effect.flatMap(computeValueBag), Effect.provide(services), Effect.withSpan("test"), Effect.tap((values) => {
|
|
473
482
|
for (const [key, value] of Object.entries(values)) {
|
|
474
483
|
if (computingOutputs) {
|
|
475
484
|
this._onOutputComputed(node, key, value);
|
|
@@ -494,7 +503,8 @@ var ComputeGraphController = class extends Resource {
|
|
|
494
503
|
const gptLayer = Layer.succeed(GptService, services.gpt);
|
|
495
504
|
const queueLayer = services.edgeHttpClient != null ? QueueService.fromClient(services.edgeHttpClient) : QueueService.notAvailable;
|
|
496
505
|
const spaceLayer = services.spaceService != null ? Layer.succeed(SpaceService, services.spaceService) : SpaceService.empty;
|
|
497
|
-
|
|
506
|
+
const functionCallServiceLayer = services.edgeHttpClient != null && services.spaceService != null ? Layer.succeed(FunctionCallService, FunctionCallService.fromClient(services.edgeHttpClient.baseUrl, services.spaceService.spaceId)) : Layer.succeed(FunctionCallService, FunctionCallService.mock());
|
|
507
|
+
return Layer.mergeAll(logLayer, gptLayer, queueLayer, spaceLayer, functionCallServiceLayer, FetchHttpClient.layer);
|
|
498
508
|
}
|
|
499
509
|
_createLogger() {
|
|
500
510
|
return {
|
|
@@ -509,7 +519,7 @@ var ComputeGraphController = class extends Resource {
|
|
|
509
519
|
event
|
|
510
520
|
}, {
|
|
511
521
|
F: __dxlog_file4,
|
|
512
|
-
L:
|
|
522
|
+
L: 376,
|
|
513
523
|
S: this,
|
|
514
524
|
C: (f, a) => f(...a)
|
|
515
525
|
});
|
|
@@ -1304,34 +1314,80 @@ var databaseShape = {
|
|
|
1304
1314
|
};
|
|
1305
1315
|
|
|
1306
1316
|
// packages/ui/react-ui-canvas-compute/src/shapes/Function.tsx
|
|
1307
|
-
import React12 from "react";
|
|
1317
|
+
import React12, { useCallback as useCallback3, useRef as useRef4 } from "react";
|
|
1308
1318
|
import { AnyOutput, FunctionInput } from "@dxos/conductor";
|
|
1309
|
-
import { S as S11 } from "@dxos/echo-schema";
|
|
1319
|
+
import { getSnapshot, S as S11 } from "@dxos/echo-schema";
|
|
1320
|
+
import { FunctionType, ScriptType } from "@dxos/functions";
|
|
1321
|
+
import { useClient } from "@dxos/react-client";
|
|
1322
|
+
import { Filter, makeRef, parseId } from "@dxos/react-client/echo";
|
|
1323
|
+
import { TextBox as TextBox3 } from "@dxos/react-ui-canvas-editor";
|
|
1310
1324
|
var FunctionShape = S11.extend(ComputeShape, S11.Struct({
|
|
1311
1325
|
type: S11.Literal("function")
|
|
1312
1326
|
}));
|
|
1313
1327
|
var createFunction = (props) => createShape({
|
|
1314
1328
|
type: "function",
|
|
1315
1329
|
size: {
|
|
1316
|
-
width:
|
|
1317
|
-
height:
|
|
1330
|
+
width: 256,
|
|
1331
|
+
height: 192
|
|
1318
1332
|
},
|
|
1319
1333
|
...props
|
|
1320
1334
|
});
|
|
1321
|
-
var
|
|
1322
|
-
|
|
1335
|
+
var TextInputComponent2 = ({ shape, title, ...props }) => {
|
|
1336
|
+
const client = useClient();
|
|
1337
|
+
const { node, runtime } = useComputeNodeState(shape);
|
|
1338
|
+
const inputRef = useRef4(null);
|
|
1339
|
+
const handleEnter = useCallback3(async (text) => {
|
|
1340
|
+
const value = text.trim();
|
|
1341
|
+
const { spaceId, objectId } = parseId(value);
|
|
1342
|
+
if (!spaceId || !objectId) {
|
|
1343
|
+
return;
|
|
1344
|
+
}
|
|
1345
|
+
const space = client.spaces.get(spaceId);
|
|
1346
|
+
const object = space?.db.getObjectById(objectId);
|
|
1347
|
+
if (!space || !(object instanceof ScriptType)) {
|
|
1348
|
+
return;
|
|
1349
|
+
}
|
|
1350
|
+
const { objects: [fn] } = await space.db.query(Filter.schema(FunctionType, {
|
|
1351
|
+
source: object
|
|
1352
|
+
})).run();
|
|
1353
|
+
if (!fn) {
|
|
1354
|
+
return;
|
|
1355
|
+
}
|
|
1356
|
+
node.value = value;
|
|
1357
|
+
node.function = makeRef(fn);
|
|
1358
|
+
node.inputSchema = getSnapshot(fn.inputSchema);
|
|
1359
|
+
node.outputSchema = getSnapshot(fn.outputSchema);
|
|
1360
|
+
}, [
|
|
1361
|
+
client,
|
|
1362
|
+
node
|
|
1363
|
+
]);
|
|
1364
|
+
const handleAction = useCallback3((action) => {
|
|
1365
|
+
if (action !== "run") {
|
|
1366
|
+
return;
|
|
1367
|
+
}
|
|
1368
|
+
runtime.evalNode();
|
|
1369
|
+
}, [
|
|
1370
|
+
runtime
|
|
1371
|
+
]);
|
|
1372
|
+
return /* @__PURE__ */ React12.createElement(Box, {
|
|
1323
1373
|
shape,
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
}
|
|
1374
|
+
title: "Function",
|
|
1375
|
+
onAction: handleAction
|
|
1376
|
+
}, /* @__PURE__ */ React12.createElement(TextBox3, {
|
|
1377
|
+
...props,
|
|
1378
|
+
ref: inputRef,
|
|
1379
|
+
value: node.value,
|
|
1380
|
+
language: node.valueType === "object" ? "json" : void 0,
|
|
1381
|
+
onBlur: handleEnter,
|
|
1382
|
+
onEnter: handleEnter
|
|
1383
|
+
}));
|
|
1327
1384
|
};
|
|
1328
1385
|
var functionShape = {
|
|
1329
1386
|
type: "function",
|
|
1330
1387
|
name: "Function",
|
|
1331
1388
|
icon: "ph--function--regular",
|
|
1332
|
-
component:
|
|
1389
|
+
component: TextInputComponent2,
|
|
1333
1390
|
createShape: createFunction,
|
|
1334
|
-
// TODO(burdon): Get dynamic schema.
|
|
1335
1391
|
getAnchors: (shape) => createFunctionAnchors(shape, FunctionInput, AnyOutput)
|
|
1336
1392
|
};
|
|
1337
1393
|
|
|
@@ -1852,19 +1908,19 @@ var tableShape = {
|
|
|
1852
1908
|
};
|
|
1853
1909
|
|
|
1854
1910
|
// packages/ui/react-ui-canvas-compute/src/shapes/Template.tsx
|
|
1855
|
-
import React22, { useRef as
|
|
1911
|
+
import React22, { useRef as useRef5 } from "react";
|
|
1856
1912
|
import { ComputeValueType as ComputeValueType3, getTemplateInputSchema as getTemplateInputSchema2, TemplateOutput, VoidInput as VoidInput2 } from "@dxos/conductor";
|
|
1857
1913
|
import { S as S21, toJsonSchema as toJsonSchema2 } from "@dxos/echo-schema";
|
|
1858
1914
|
import { invariant as invariant5 } from "@dxos/invariant";
|
|
1859
|
-
import { TextBox as
|
|
1915
|
+
import { TextBox as TextBox4 } from "@dxos/react-ui-canvas-editor";
|
|
1860
1916
|
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-canvas-compute/src/shapes/Template.tsx";
|
|
1861
1917
|
var TemplateShape = S21.extend(ComputeShape, S21.Struct({
|
|
1862
1918
|
type: S21.Literal("template"),
|
|
1863
1919
|
valueType: S21.optional(ComputeValueType3)
|
|
1864
1920
|
}));
|
|
1865
|
-
var
|
|
1921
|
+
var TextInputComponent3 = ({ shape, title, ...props }) => {
|
|
1866
1922
|
const { node } = useComputeNodeState(shape);
|
|
1867
|
-
const inputRef =
|
|
1923
|
+
const inputRef = useRef5(null);
|
|
1868
1924
|
const handleEnter = (text) => {
|
|
1869
1925
|
const value = text.trim();
|
|
1870
1926
|
if (value.length) {
|
|
@@ -1893,7 +1949,7 @@ var TextInputComponent2 = ({ shape, title, ...props }) => {
|
|
|
1893
1949
|
value: node.valueType ?? "string",
|
|
1894
1950
|
onValueChange: handleTypeChange
|
|
1895
1951
|
})
|
|
1896
|
-
}, /* @__PURE__ */ React22.createElement(
|
|
1952
|
+
}, /* @__PURE__ */ React22.createElement(TextBox4, {
|
|
1897
1953
|
...props,
|
|
1898
1954
|
ref: inputRef,
|
|
1899
1955
|
value: node.value,
|
|
@@ -1914,7 +1970,7 @@ var templateShape = {
|
|
|
1914
1970
|
type: "template",
|
|
1915
1971
|
name: "Template",
|
|
1916
1972
|
icon: "ph--article--regular",
|
|
1917
|
-
component: (props) => /* @__PURE__ */ React22.createElement(
|
|
1973
|
+
component: (props) => /* @__PURE__ */ React22.createElement(TextInputComponent3, {
|
|
1918
1974
|
...props,
|
|
1919
1975
|
placeholder: "Prompt"
|
|
1920
1976
|
}),
|
|
@@ -1927,7 +1983,7 @@ var templateShape = {
|
|
|
1927
1983
|
import React23 from "react";
|
|
1928
1984
|
import { DEFAULT_INPUT as DEFAULT_INPUT7 } from "@dxos/conductor";
|
|
1929
1985
|
import { S as S22 } from "@dxos/echo-schema";
|
|
1930
|
-
import { TextBox as
|
|
1986
|
+
import { TextBox as TextBox5 } from "@dxos/react-ui-canvas-editor";
|
|
1931
1987
|
import { createAnchorMap as createAnchorMap11 } from "@dxos/react-ui-canvas-editor";
|
|
1932
1988
|
var TextShape = S22.extend(ComputeShape, S22.Struct({
|
|
1933
1989
|
type: S22.Literal("text")
|
|
@@ -1952,7 +2008,7 @@ var TextComponent = ({ shape }) => {
|
|
|
1952
2008
|
return /* @__PURE__ */ React23.createElement(Box, {
|
|
1953
2009
|
shape,
|
|
1954
2010
|
onAction: handleAction
|
|
1955
|
-
}, /* @__PURE__ */ React23.createElement(
|
|
2011
|
+
}, /* @__PURE__ */ React23.createElement(TextBox5, {
|
|
1956
2012
|
value
|
|
1957
2013
|
}));
|
|
1958
2014
|
};
|
|
@@ -1972,7 +2028,7 @@ var textShape = {
|
|
|
1972
2028
|
};
|
|
1973
2029
|
|
|
1974
2030
|
// packages/ui/react-ui-canvas-compute/src/shapes/Thread.tsx
|
|
1975
|
-
import React24, { useEffect as useEffect6, useRef as
|
|
2031
|
+
import React24, { useEffect as useEffect6, useRef as useRef6 } from "react";
|
|
1976
2032
|
import { createInputSchema as createInputSchema2, createOutputSchema as createOutputSchema2, GptMessage as GptMessage2 } from "@dxos/conductor";
|
|
1977
2033
|
import { S as S23 } from "@dxos/echo-schema";
|
|
1978
2034
|
import { mx as mx5 } from "@dxos/react-ui-theme";
|
|
@@ -1991,7 +2047,7 @@ var createThread = (props) => createShape({
|
|
|
1991
2047
|
});
|
|
1992
2048
|
var ThreadComponent = ({ shape }) => {
|
|
1993
2049
|
const items = [];
|
|
1994
|
-
const scrollRef =
|
|
2050
|
+
const scrollRef = useRef6(null);
|
|
1995
2051
|
useEffect6(() => {
|
|
1996
2052
|
if (scrollRef.current) {
|
|
1997
2053
|
scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
|
|
@@ -2074,7 +2130,7 @@ import { EmailTriggerOutput, SubscriptionTriggerOutput, TimerTriggerOutput, Void
|
|
|
2074
2130
|
import { ObjectId as ObjectId4, Ref, S as S25 } from "@dxos/echo-schema";
|
|
2075
2131
|
import { FunctionTrigger, TriggerKind } from "@dxos/functions";
|
|
2076
2132
|
import { DXN as DXN2, SpaceId } from "@dxos/keys";
|
|
2077
|
-
import { create, makeRef } from "@dxos/react-client/echo";
|
|
2133
|
+
import { create, makeRef as makeRef2 } from "@dxos/react-client/echo";
|
|
2078
2134
|
import { Select as Select2 } from "@dxos/react-ui";
|
|
2079
2135
|
var TriggerShape = S25.extend(ComputeShape, S25.Struct({
|
|
2080
2136
|
type: S25.Literal("trigger"),
|
|
@@ -2087,7 +2143,7 @@ var createTrigger = (props) => {
|
|
|
2087
2143
|
});
|
|
2088
2144
|
return createShape({
|
|
2089
2145
|
type: "trigger",
|
|
2090
|
-
functionTrigger:
|
|
2146
|
+
functionTrigger: makeRef2(functionTrigger),
|
|
2091
2147
|
size: {
|
|
2092
2148
|
width: 192,
|
|
2093
2149
|
height: getHeight(EmailTriggerOutput)
|
|
@@ -2426,7 +2482,6 @@ export {
|
|
|
2426
2482
|
DatabaseComponent,
|
|
2427
2483
|
DatabaseShape,
|
|
2428
2484
|
FunctionBody,
|
|
2429
|
-
FunctionComponent,
|
|
2430
2485
|
FunctionShape,
|
|
2431
2486
|
GptComponent,
|
|
2432
2487
|
GptRealtimeComponent,
|