@dxos/react-ui-canvas-compute 0.8.3-main.7f5a14c → 0.8.3-staging.0fa589b
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 +16 -45
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +14 -43
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +16 -45
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/compute.stories.d.ts.map +1 -1
- package/dist/types/src/graph/controller.d.ts +5 -14
- package/dist/types/src/graph/controller.d.ts.map +1 -1
- package/dist/types/src/testing/circuits.d.ts +4 -19
- package/dist/types/src/testing/circuits.d.ts.map +1 -1
- package/package.json +39 -39
- package/src/compute.stories.tsx +55 -17
- package/src/graph/controller.ts +17 -62
- package/src/shapes/GptRealtime.tsx +2 -2
- package/src/testing/circuits.ts +9 -9
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import "@dxos/node-std/globals";
|
|
2
2
|
|
|
3
3
|
// packages/ui/react-ui-canvas-compute/src/graph/controller.ts
|
|
4
|
-
import {
|
|
5
|
-
import { Effect, Either, Exit, Layer, Scope } from "effect";
|
|
4
|
+
import { Effect, Either, Exit, Scope } from "effect";
|
|
6
5
|
import { Event, synchronized } from "@dxos/async";
|
|
7
|
-
import {
|
|
6
|
+
import { GraphExecutor, isNotExecuted, ValueBag } from "@dxos/conductor";
|
|
8
7
|
import { Resource } from "@dxos/context";
|
|
9
8
|
import { log } from "@dxos/log";
|
|
10
9
|
|
|
@@ -356,20 +355,19 @@ var AUTO_TRIGGER_NODES = [
|
|
|
356
355
|
"switch",
|
|
357
356
|
"constant"
|
|
358
357
|
];
|
|
359
|
-
var createComputeGraphController = (graph,
|
|
358
|
+
var createComputeGraphController = (graph, serviceContainer) => {
|
|
360
359
|
const computeGraph = createComputeGraph(graph);
|
|
361
|
-
const controller = new ComputeGraphController(computeGraph);
|
|
362
|
-
controller.setServices(services ?? {});
|
|
360
|
+
const controller = new ComputeGraphController(serviceContainer, computeGraph);
|
|
363
361
|
return {
|
|
364
362
|
controller,
|
|
365
363
|
graph
|
|
366
364
|
};
|
|
367
365
|
};
|
|
368
366
|
var ComputeGraphController = class extends Resource {
|
|
369
|
-
constructor(_graph) {
|
|
370
|
-
super(), this._graph = _graph, this._executor = new GraphExecutor({
|
|
367
|
+
constructor(_serviceContainer, _graph) {
|
|
368
|
+
super(), this._serviceContainer = _serviceContainer, this._graph = _graph, this._executor = new GraphExecutor({
|
|
371
369
|
computeNodeResolver: (node) => resolveComputeNode(node)
|
|
372
|
-
}), this._diagnostics = [], this.
|
|
370
|
+
}), this._diagnostics = [], this._forcedOutputs = {}, this._runtimeStateInputs = {}, this._runtimeStateOutputs = {}, this.update = new Event(), this.output = new Event(), this.events = new Event();
|
|
373
371
|
}
|
|
374
372
|
toJSON() {
|
|
375
373
|
return {
|
|
@@ -381,17 +379,6 @@ var ComputeGraphController = class extends Resource {
|
|
|
381
379
|
forcedOutputs: this._forcedOutputs
|
|
382
380
|
};
|
|
383
381
|
}
|
|
384
|
-
setServices(services) {
|
|
385
|
-
log.info("setServices", {
|
|
386
|
-
services
|
|
387
|
-
}, {
|
|
388
|
-
F: __dxlog_file4,
|
|
389
|
-
L: 149,
|
|
390
|
-
S: this,
|
|
391
|
-
C: (f, a) => f(...a)
|
|
392
|
-
});
|
|
393
|
-
Object.assign(this._services, services);
|
|
394
|
-
}
|
|
395
382
|
get graph() {
|
|
396
383
|
return this._graph;
|
|
397
384
|
}
|
|
@@ -450,7 +437,7 @@ var ComputeGraphController = class extends Resource {
|
|
|
450
437
|
} catch (err) {
|
|
451
438
|
log.catch(err, void 0, {
|
|
452
439
|
F: __dxlog_file4,
|
|
453
|
-
L:
|
|
440
|
+
L: 199,
|
|
454
441
|
S: this,
|
|
455
442
|
C: (f, a) => f(...a)
|
|
456
443
|
});
|
|
@@ -470,14 +457,14 @@ var ComputeGraphController = class extends Resource {
|
|
|
470
457
|
const executor = this._executor.clone();
|
|
471
458
|
await executor.load(this._graph);
|
|
472
459
|
for (const [nodeId2, outputs] of Object.entries(this._forcedOutputs)) {
|
|
473
|
-
executor.setOutputs(nodeId2, Effect.succeed(
|
|
460
|
+
executor.setOutputs(nodeId2, Effect.succeed(ValueBag.make(outputs)));
|
|
474
461
|
}
|
|
475
|
-
const
|
|
462
|
+
const serviceLayer = this._serviceContainer.createLayer();
|
|
476
463
|
await Effect.runPromise(Effect.gen(this, function* () {
|
|
477
464
|
const scope = yield* Scope.make();
|
|
478
465
|
const executable = yield* Effect.promise(() => resolveComputeNode(this._graph.getNode(nodeId)));
|
|
479
466
|
const computingOutputs = executable.exec != null;
|
|
480
|
-
const effect = (computingOutputs ? executor.computeOutputs(nodeId) : executor.computeInputs(nodeId)).pipe(Effect.withSpan("runGraph"), Scope.extend(scope), Effect.flatMap(computeValueBag), Effect.provide(
|
|
467
|
+
const effect = (computingOutputs ? executor.computeOutputs(nodeId) : executor.computeInputs(nodeId)).pipe(Effect.withSpan("runGraph"), Scope.extend(scope), Effect.flatMap(computeValueBag), Effect.provide(serviceLayer), Effect.withSpan("test"), Effect.tap((values) => {
|
|
481
468
|
for (const [key, value] of Object.entries(values)) {
|
|
482
469
|
if (computingOutputs) {
|
|
483
470
|
this._onOutputComputed(nodeId, key, value);
|
|
@@ -501,7 +488,7 @@ var ComputeGraphController = class extends Resource {
|
|
|
501
488
|
const executor = this._executor.clone();
|
|
502
489
|
await executor.load(this._graph);
|
|
503
490
|
for (const [nodeId, outputs] of Object.entries(this._forcedOutputs)) {
|
|
504
|
-
executor.setOutputs(nodeId, Effect.succeed(
|
|
491
|
+
executor.setOutputs(nodeId, Effect.succeed(ValueBag.make(outputs)));
|
|
505
492
|
}
|
|
506
493
|
const triggerNodes = startFromNode != null ? [
|
|
507
494
|
this._graph.getNode(startFromNode)
|
|
@@ -509,14 +496,13 @@ var ComputeGraphController = class extends Resource {
|
|
|
509
496
|
const allAffectedNodes = [
|
|
510
497
|
...new Set(triggerNodes.flatMap((node) => executor.getAllDependantNodes(node.id)))
|
|
511
498
|
];
|
|
512
|
-
const services = this._createServiceLayer();
|
|
513
499
|
await Effect.runPromise(Effect.gen(this, function* () {
|
|
514
500
|
const scope = yield* Scope.make();
|
|
515
501
|
const tasks = [];
|
|
516
502
|
for (const node of allAffectedNodes) {
|
|
517
503
|
const executable = yield* Effect.promise(() => resolveComputeNode(this._graph.getNode(node)));
|
|
518
504
|
const computingOutputs = executable.exec != null;
|
|
519
|
-
const effect = (computingOutputs ? executor.computeOutputs(node) : executor.computeInputs(node)).pipe(Effect.withSpan("runGraph"), Scope.extend(scope), Effect.flatMap(computeValueBag), Effect.provide(
|
|
505
|
+
const effect = (computingOutputs ? executor.computeOutputs(node) : executor.computeInputs(node)).pipe(Effect.withSpan("runGraph"), Scope.extend(scope), Effect.flatMap(computeValueBag), Effect.provide(this._serviceContainer.createLayer()), Effect.withSpan("test"), Effect.tap((values) => {
|
|
520
506
|
for (const [key, value] of Object.entries(values)) {
|
|
521
507
|
if (computingOutputs) {
|
|
522
508
|
this._onOutputComputed(node, key, value);
|
|
@@ -532,18 +518,6 @@ var ComputeGraphController = class extends Resource {
|
|
|
532
518
|
}));
|
|
533
519
|
this.update.emit();
|
|
534
520
|
}
|
|
535
|
-
_createServiceLayer() {
|
|
536
|
-
const services = {
|
|
537
|
-
...DEFAULT_SERVICES,
|
|
538
|
-
...this._services
|
|
539
|
-
};
|
|
540
|
-
const logLayer = Layer.succeed(EventLogger, this._createLogger());
|
|
541
|
-
const gptLayer = Layer.succeed(GptService, services.gpt);
|
|
542
|
-
const queueLayer = services.edgeHttpClient != null ? QueueService.fromClient(services.edgeHttpClient) : QueueService.notAvailable;
|
|
543
|
-
const spaceLayer = services.spaceService != null ? Layer.succeed(SpaceService, services.spaceService) : SpaceService.empty;
|
|
544
|
-
const functionCallServiceLayer = services.edgeHttpClient != null && services.spaceService != null ? Layer.succeed(FunctionCallService, FunctionCallService.fromClient(services.edgeHttpClient.baseUrl, services.spaceService.spaceId)) : Layer.succeed(FunctionCallService, FunctionCallService.mock());
|
|
545
|
-
return Layer.mergeAll(logLayer, gptLayer, queueLayer, spaceLayer, functionCallServiceLayer, FetchHttpClient.layer);
|
|
546
|
-
}
|
|
547
521
|
_createLogger() {
|
|
548
522
|
return {
|
|
549
523
|
log: (event) => {
|
|
@@ -557,7 +531,7 @@ var ComputeGraphController = class extends Resource {
|
|
|
557
531
|
event
|
|
558
532
|
}, {
|
|
559
533
|
F: __dxlog_file4,
|
|
560
|
-
L:
|
|
534
|
+
L: 335,
|
|
561
535
|
S: this,
|
|
562
536
|
C: (f, a) => f(...a)
|
|
563
537
|
});
|
|
@@ -599,9 +573,6 @@ _ts_decorate([
|
|
|
599
573
|
_ts_decorate([
|
|
600
574
|
synchronized
|
|
601
575
|
], ComputeGraphController.prototype, "exec", null);
|
|
602
|
-
var DEFAULT_SERVICES = {
|
|
603
|
-
gpt: new MockGpt()
|
|
604
|
-
};
|
|
605
576
|
var computeValueBag = (bag) => {
|
|
606
577
|
return Effect.all(Object.entries(bag.values).map(([key, eff]) => Effect.either(eff).pipe(Effect.map((value) => {
|
|
607
578
|
if (Either.isLeft(value)) {
|
|
@@ -2521,8 +2492,8 @@ var GptRealtimeComponent = ({ shape }) => {
|
|
|
2521
2492
|
}));
|
|
2522
2493
|
const offer = await peerConnection.createOffer();
|
|
2523
2494
|
await peerConnection.setLocalDescription(offer);
|
|
2524
|
-
const
|
|
2525
|
-
const response = await fetch(
|
|
2495
|
+
const AiServiceUrl = new URL("/rtc-connect", config.values.runtime?.services?.ai?.server ?? DEFAULT_AI_SERVICE_URL);
|
|
2496
|
+
const response = await fetch(AiServiceUrl, {
|
|
2526
2497
|
method: "POST",
|
|
2527
2498
|
body: offer.sdp,
|
|
2528
2499
|
headers: {
|