@dxos/react-ui-canvas-compute 0.8.4-main.72ec0f3 → 0.8.4-main.937b3ca
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 +697 -872
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +697 -872
- 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 +22 -1
- package/dist/types/src/compute.stories.d.ts.map +1 -1
- package/dist/types/src/graph/controller.d.ts +8 -4
- package/dist/types/src/graph/controller.d.ts.map +1 -1
- package/dist/types/src/hooks/useGraphMonitor.d.ts.map +1 -1
- package/dist/types/src/shapes/Function.d.ts.map +1 -1
- package/dist/types/src/shapes/Queue.d.ts.map +1 -1
- package/dist/types/src/shapes/Trigger.d.ts +3 -2
- package/dist/types/src/shapes/Trigger.d.ts.map +1 -1
- package/dist/types/src/shapes/common/Box.d.ts +1 -1
- package/dist/types/src/testing/circuits.d.ts +18 -24
- package/dist/types/src/testing/circuits.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +55 -53
- package/src/compute.stories.tsx +63 -107
- package/src/graph/controller.ts +97 -67
- package/src/graph/node-defs.ts +3 -3
- package/src/hooks/useGraphMonitor.ts +9 -8
- package/src/json.test.ts +3 -3
- package/src/schema.test.ts +8 -8
- package/src/shapes/Function.tsx +8 -6
- package/src/shapes/Queue.tsx +6 -2
- package/src/shapes/Thread.tsx +1 -1
- package/src/shapes/Trigger.tsx +12 -7
- package/src/shapes/common/Box.tsx +1 -1
- package/src/shapes/defs.ts +3 -3
- package/src/testing/circuits.ts +5 -14
package/src/graph/controller.ts
CHANGED
|
@@ -6,8 +6,11 @@ import type * as Context from 'effect/Context';
|
|
|
6
6
|
import * as Effect from 'effect/Effect';
|
|
7
7
|
import * as Either from 'effect/Either';
|
|
8
8
|
import * as Exit from 'effect/Exit';
|
|
9
|
+
import * as Layer from 'effect/Layer';
|
|
10
|
+
import type * as ManagedRuntime from 'effect/ManagedRuntime';
|
|
9
11
|
import * as Scope from 'effect/Scope';
|
|
10
12
|
|
|
13
|
+
import type { AiService } from '@dxos/ai';
|
|
11
14
|
import { Event, synchronized } from '@dxos/async';
|
|
12
15
|
import {
|
|
13
16
|
type ComputeEdge,
|
|
@@ -22,8 +25,16 @@ import {
|
|
|
22
25
|
isNotExecuted,
|
|
23
26
|
} from '@dxos/conductor';
|
|
24
27
|
import { Resource } from '@dxos/context';
|
|
25
|
-
import
|
|
26
|
-
import {
|
|
28
|
+
import type { Database } from '@dxos/echo';
|
|
29
|
+
import { unwrapExit } from '@dxos/effect';
|
|
30
|
+
import {
|
|
31
|
+
ComputeEventLogger,
|
|
32
|
+
type ComputeEventPayload,
|
|
33
|
+
type CredentialsService,
|
|
34
|
+
type FunctionInvocationService,
|
|
35
|
+
type QueueService,
|
|
36
|
+
TracingService,
|
|
37
|
+
} from '@dxos/functions';
|
|
27
38
|
import { log } from '@dxos/log';
|
|
28
39
|
import { type CanvasGraphModel } from '@dxos/react-ui-canvas-editor';
|
|
29
40
|
import { type ContentBlock } from '@dxos/types';
|
|
@@ -72,6 +83,14 @@ type ComputeOutputEvent = {
|
|
|
72
83
|
value: RuntimeValue;
|
|
73
84
|
};
|
|
74
85
|
|
|
86
|
+
// TODO(dmaretskyi): Re-use function servies definition.
|
|
87
|
+
export type ComputeServices =
|
|
88
|
+
| AiService.AiService
|
|
89
|
+
| Database.Service
|
|
90
|
+
| QueueService
|
|
91
|
+
| CredentialsService
|
|
92
|
+
| FunctionInvocationService;
|
|
93
|
+
|
|
75
94
|
/**
|
|
76
95
|
* Nodes that will automatically trigger the execution of the graph on startup.
|
|
77
96
|
*/
|
|
@@ -79,10 +98,10 @@ const AUTO_TRIGGER_NODES = ['chat', 'switch', 'constant'];
|
|
|
79
98
|
|
|
80
99
|
export const createComputeGraphController = (
|
|
81
100
|
graph: CanvasGraphModel<ComputeShape>,
|
|
82
|
-
|
|
101
|
+
computeRuntime: ManagedRuntime.ManagedRuntime<ComputeServices, never>,
|
|
83
102
|
) => {
|
|
84
103
|
const computeGraph = createComputeGraph(graph);
|
|
85
|
-
const controller = new ComputeGraphController(
|
|
104
|
+
const controller = new ComputeGraphController(computeRuntime, computeGraph);
|
|
86
105
|
return { controller, graph };
|
|
87
106
|
};
|
|
88
107
|
|
|
@@ -117,7 +136,7 @@ export class ComputeGraphController extends Resource {
|
|
|
117
136
|
public readonly events = new Event<ComputeEventPayload>();
|
|
118
137
|
|
|
119
138
|
constructor(
|
|
120
|
-
private readonly
|
|
139
|
+
private readonly _computeRuntime: ManagedRuntime.ManagedRuntime<ComputeServices, never>,
|
|
121
140
|
/** Persistent compute graph. */
|
|
122
141
|
private readonly _graph: ComputeGraphModel,
|
|
123
142
|
) {
|
|
@@ -232,37 +251,41 @@ export class ComputeGraphController extends Resource {
|
|
|
232
251
|
executor.setOutputs(nodeId, Effect.succeed(ValueBag.make(outputs)));
|
|
233
252
|
}
|
|
234
253
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
254
|
+
unwrapExit(
|
|
255
|
+
await this._computeRuntime.runPromiseExit(
|
|
256
|
+
Effect.gen(this, function* () {
|
|
257
|
+
const scope = yield* Scope.make();
|
|
258
|
+
|
|
259
|
+
// TODO(dmaretskyi): Code duplication.
|
|
260
|
+
const executable = yield* Effect.promise(() => resolveComputeNode(this._graph.getNode(nodeId)));
|
|
261
|
+
const computingOutputs = executable.exec != null;
|
|
262
|
+
// TODO(dmaretskyi): Check if the node has a compute function and run computeOutputs if it does.
|
|
263
|
+
const effect = (computingOutputs ? executor.computeOutputs(nodeId) : executor.computeInputs(nodeId)).pipe(
|
|
264
|
+
Effect.withSpan('runGraph'),
|
|
265
|
+
Scope.extend(scope),
|
|
266
|
+
Effect.provide(
|
|
267
|
+
ComputeEventLogger.layerFromTracing.pipe(
|
|
268
|
+
Layer.provideMerge(TracingService.layerNoop), // TODO(dmaretskyi): Plug-in tracing events to visual feedback in the compute graph editor.
|
|
269
|
+
),
|
|
270
|
+
),
|
|
271
|
+
Effect.flatMap(computeValueBag),
|
|
272
|
+
Effect.withSpan('test'),
|
|
273
|
+
Effect.tap((values) => {
|
|
274
|
+
for (const [key, value] of Object.entries(values)) {
|
|
275
|
+
if (computingOutputs) {
|
|
276
|
+
this._onOutputComputed(nodeId, key, value);
|
|
277
|
+
} else {
|
|
278
|
+
this._onInputComputed(nodeId, key, value);
|
|
279
|
+
}
|
|
257
280
|
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
);
|
|
281
|
+
}),
|
|
282
|
+
);
|
|
261
283
|
|
|
262
|
-
|
|
284
|
+
yield* effect;
|
|
263
285
|
|
|
264
|
-
|
|
265
|
-
|
|
286
|
+
yield* Scope.close(scope, Exit.void);
|
|
287
|
+
}),
|
|
288
|
+
),
|
|
266
289
|
);
|
|
267
290
|
|
|
268
291
|
this.update.emit();
|
|
@@ -290,44 +313,51 @@ export class ComputeGraphController extends Resource {
|
|
|
290
313
|
: this._graph.nodes.filter((node) => node.type != null && AUTO_TRIGGER_NODES.includes(node.type));
|
|
291
314
|
const allAffectedNodes = [...new Set(triggerNodes.flatMap((node) => executor.getAllDependantNodes(node.id)))];
|
|
292
315
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
316
|
+
unwrapExit(
|
|
317
|
+
await this._computeRuntime.runPromiseExit(
|
|
318
|
+
Effect.gen(this, function* () {
|
|
319
|
+
const scope = yield* Scope.make();
|
|
320
|
+
|
|
321
|
+
// TODO(burdon): Return map?
|
|
322
|
+
const tasks: Effect.Effect<unknown, any, ComputeServices>[] = [];
|
|
323
|
+
for (const node of allAffectedNodes) {
|
|
324
|
+
// TODO(dmaretskyi): Code duplication.
|
|
325
|
+
const executable = yield* Effect.promise(() => resolveComputeNode(this._graph.getNode(node)));
|
|
326
|
+
const computingOutputs = executable.exec != null;
|
|
327
|
+
|
|
328
|
+
// TODO(dmaretskyi): Check if the node has a compute function and run computeOutputs if it does.
|
|
329
|
+
const effect = (computingOutputs ? executor.computeOutputs(node) : executor.computeInputs(node)).pipe(
|
|
330
|
+
Effect.withSpan('runGraph'),
|
|
331
|
+
Scope.extend(scope),
|
|
332
|
+
Effect.flatMap(computeValueBag),
|
|
333
|
+
Effect.provide(
|
|
334
|
+
ComputeEventLogger.layerFromTracing.pipe(
|
|
335
|
+
Layer.provideMerge(TracingService.layerNoop), // TODO(dmaretskyi): Plug-in tracing events to visual feedback in the compute graph editor.
|
|
336
|
+
),
|
|
337
|
+
),
|
|
338
|
+
|
|
339
|
+
Effect.withSpan('test'),
|
|
340
|
+
Effect.tap((values) => {
|
|
341
|
+
for (const [key, value] of Object.entries(values)) {
|
|
342
|
+
if (computingOutputs) {
|
|
343
|
+
this._onOutputComputed(node, key, value);
|
|
344
|
+
} else {
|
|
345
|
+
this._onInputComputed(node, key, value);
|
|
346
|
+
}
|
|
317
347
|
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
);
|
|
348
|
+
}),
|
|
349
|
+
);
|
|
321
350
|
|
|
322
|
-
|
|
323
|
-
|
|
351
|
+
tasks.push(effect);
|
|
352
|
+
}
|
|
324
353
|
|
|
325
|
-
|
|
326
|
-
|
|
354
|
+
//
|
|
355
|
+
yield* Effect.all(tasks);
|
|
327
356
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
357
|
+
//
|
|
358
|
+
yield* Scope.close(scope, Exit.void);
|
|
359
|
+
}),
|
|
360
|
+
),
|
|
331
361
|
);
|
|
332
362
|
|
|
333
363
|
this.update.emit();
|
package/src/graph/node-defs.ts
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
registry,
|
|
13
13
|
} from '@dxos/conductor';
|
|
14
14
|
import { raise } from '@dxos/debug';
|
|
15
|
-
import {
|
|
15
|
+
import { JsonSchema, Obj } from '@dxos/echo';
|
|
16
16
|
import { invariant } from '@dxos/invariant';
|
|
17
17
|
|
|
18
18
|
import { type ComputeShape, type ConstantShape, type TemplateShape } from '../shapes';
|
|
@@ -68,7 +68,7 @@ const nodeFactory: Record<NodeType | 'trigger', (shape: ComputeShape) => Compute
|
|
|
68
68
|
['switch' as const]: () => createNode('switch'),
|
|
69
69
|
['template' as const]: (shape) => {
|
|
70
70
|
const node = createNode('template', { valueType: (shape as TemplateShape).valueType, value: shape.text });
|
|
71
|
-
node.inputSchema = toJsonSchema(getTemplateInputSchema(node));
|
|
71
|
+
node.inputSchema = JsonSchema.toJsonSchema(getTemplateInputSchema(node));
|
|
72
72
|
return node;
|
|
73
73
|
},
|
|
74
74
|
['text' as const]: () => createNode('text'),
|
|
@@ -77,7 +77,7 @@ const nodeFactory: Record<NodeType | 'trigger', (shape: ComputeShape) => Compute
|
|
|
77
77
|
};
|
|
78
78
|
|
|
79
79
|
const createNode = (type: string, props?: Partial<ComputeNode>): ComputeNode => ({
|
|
80
|
-
id:
|
|
80
|
+
id: Obj.ID.random(),
|
|
81
81
|
type,
|
|
82
82
|
...props,
|
|
83
83
|
});
|
|
@@ -5,9 +5,8 @@
|
|
|
5
5
|
import { useMemo } from 'react';
|
|
6
6
|
|
|
7
7
|
import { type ComputeEdge, ComputeGraphModel, type ComputeNode, DEFAULT_INPUT, DEFAULT_OUTPUT } from '@dxos/conductor';
|
|
8
|
-
import {
|
|
8
|
+
import { Obj, Ref } from '@dxos/echo';
|
|
9
9
|
import { invariant } from '@dxos/invariant';
|
|
10
|
-
import { getSpace } from '@dxos/react-client/echo';
|
|
11
10
|
import { type CanvasGraphModel, type Connection, type GraphMonitor } from '@dxos/react-ui-canvas-editor';
|
|
12
11
|
import { isNonNullable } from '@dxos/util';
|
|
13
12
|
|
|
@@ -27,7 +26,7 @@ export const mapEdge = (
|
|
|
27
26
|
invariant(targetNode?.node);
|
|
28
27
|
|
|
29
28
|
return {
|
|
30
|
-
id:
|
|
29
|
+
id: Obj.ID.random(),
|
|
31
30
|
source: sourceNode.node,
|
|
32
31
|
target: targetNode.node,
|
|
33
32
|
output,
|
|
@@ -113,19 +112,21 @@ export const createComputeGraph = (graph?: CanvasGraphModel<ComputeShape>) => {
|
|
|
113
112
|
const linkTriggerToCompute = (graph: ComputeGraphModel, computeNode: ComputeNode, triggerData: TriggerShape) => {
|
|
114
113
|
const functionTrigger = triggerData.functionTrigger?.target;
|
|
115
114
|
invariant(functionTrigger);
|
|
116
|
-
functionTrigger
|
|
117
|
-
|
|
115
|
+
Obj.change(functionTrigger, (t) => {
|
|
116
|
+
t.function = Ref.make(graph.root);
|
|
117
|
+
t.inputNodeId = computeNode.id;
|
|
118
|
+
});
|
|
118
119
|
};
|
|
119
120
|
|
|
120
121
|
const deleteTriggerObjects = (computeGraph: ComputeGraphModel, deleted: CanvasGraphModel) => {
|
|
121
|
-
const
|
|
122
|
-
if (!
|
|
122
|
+
const db = Obj.getDatabase(computeGraph.root);
|
|
123
|
+
if (!db) {
|
|
123
124
|
return;
|
|
124
125
|
}
|
|
125
126
|
for (const node of deleted.nodes) {
|
|
126
127
|
if (node.type === 'trigger') {
|
|
127
128
|
const trigger = node as TriggerShape;
|
|
128
|
-
|
|
129
|
+
db.remove(trigger.functionTrigger!.target!);
|
|
129
130
|
}
|
|
130
131
|
}
|
|
131
132
|
};
|
package/src/json.test.ts
CHANGED
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
import { describe, test } from 'vitest';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { Graph } from '@dxos/graph';
|
|
9
9
|
|
|
10
10
|
import { createGptCircuit } from './testing';
|
|
11
11
|
|
|
12
12
|
export const Shape = Schema.extend(
|
|
13
|
-
|
|
13
|
+
Graph.Node,
|
|
14
14
|
Schema.Struct({
|
|
15
15
|
text: Schema.optional(Schema.String),
|
|
16
16
|
guide: Schema.optional(Schema.Boolean),
|
|
@@ -19,7 +19,7 @@ export const Shape = Schema.extend(
|
|
|
19
19
|
);
|
|
20
20
|
|
|
21
21
|
export const Connection = Schema.extend(
|
|
22
|
-
|
|
22
|
+
Graph.Edge,
|
|
23
23
|
Schema.Struct({
|
|
24
24
|
input: Schema.optional(Schema.String),
|
|
25
25
|
output: Schema.optional(Schema.String),
|
package/src/schema.test.ts
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
import { describe, test } from 'vitest';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import { BaseGraphNode, Graph } from '@dxos/graph';
|
|
8
|
+
import { Graph } from '@dxos/graph';
|
|
10
9
|
import {
|
|
10
|
+
CanvasGraphModel,
|
|
11
11
|
Polygon,
|
|
12
12
|
Shape,
|
|
13
13
|
createEllipse,
|
|
@@ -21,19 +21,19 @@ import { ComputeShape, createFunction, createSwitch } from './shapes';
|
|
|
21
21
|
|
|
22
22
|
describe('compute', () => {
|
|
23
23
|
test('model', ({ expect }) => {
|
|
24
|
-
|
|
24
|
+
const model = CanvasGraphModel.create<ComputeShape>();
|
|
25
25
|
const node = createSwitch({ id: 'x', center: { x: 0, y: 0 }, size: { width: 80, height: 80 } });
|
|
26
26
|
console.log(JSON.stringify(node, null, 2));
|
|
27
27
|
expect(Schema.is(ComputeShape)(node)).toBe(true);
|
|
28
28
|
expect(Schema.is(Polygon)(node)).toBe(true);
|
|
29
29
|
expect(Schema.is(Shape)(node)).toBe(true);
|
|
30
|
-
expect(Schema.is(
|
|
30
|
+
expect(Schema.is(Graph.Node)(node)).toBe(true);
|
|
31
31
|
|
|
32
|
-
const graph =
|
|
33
|
-
graph.nodes.push(node);
|
|
32
|
+
const graph: Graph.Any = { nodes: [], edges: [] };
|
|
33
|
+
graph.nodes.push(node);
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
model.createNode(node);
|
|
36
|
+
console.log(JSON.stringify(model, null, 2));
|
|
37
37
|
});
|
|
38
38
|
});
|
|
39
39
|
|
package/src/shapes/Function.tsx
CHANGED
|
@@ -35,7 +35,11 @@ export type FunctionShape = Schema.Schema.Type<typeof FunctionShape>;
|
|
|
35
35
|
export type CreateFunctionProps = CreateShapeProps<FunctionShape>;
|
|
36
36
|
|
|
37
37
|
export const createFunction = (props: CreateFunctionProps) =>
|
|
38
|
-
createShape<FunctionShape>({
|
|
38
|
+
createShape<FunctionShape>({
|
|
39
|
+
type: 'function',
|
|
40
|
+
size: { width: 256, height: 192 },
|
|
41
|
+
...props,
|
|
42
|
+
});
|
|
39
43
|
|
|
40
44
|
//
|
|
41
45
|
// Component
|
|
@@ -62,17 +66,15 @@ const TextInputComponent = ({ shape, title, ...props }: TextInputComponentProps)
|
|
|
62
66
|
return;
|
|
63
67
|
}
|
|
64
68
|
|
|
65
|
-
const {
|
|
66
|
-
objects: [fn],
|
|
67
|
-
} = await space.db.query(Filter.type(Function.Function, { source: Ref.make(object) })).run();
|
|
69
|
+
const [fn] = await space.db.query(Filter.type(Function.Function, { source: Ref.make(object) })).run();
|
|
68
70
|
if (!fn) {
|
|
69
71
|
return;
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
node.value = value;
|
|
73
75
|
node.function = Ref.make(fn);
|
|
74
|
-
node.inputSchema = getSnapshot(fn.inputSchema);
|
|
75
|
-
node.outputSchema = getSnapshot(fn.outputSchema);
|
|
76
|
+
node.inputSchema = fn.inputSchema ? getSnapshot(fn.inputSchema) : undefined;
|
|
77
|
+
node.outputSchema = fn.outputSchema ? getSnapshot(fn.outputSchema) : undefined;
|
|
76
78
|
},
|
|
77
79
|
[client, node],
|
|
78
80
|
);
|
package/src/shapes/Queue.tsx
CHANGED
|
@@ -8,7 +8,7 @@ import React, { Fragment } from 'react';
|
|
|
8
8
|
import { DEFAULT_OUTPUT, QueueInput, QueueOutput } from '@dxos/conductor';
|
|
9
9
|
import { type ThemedClassName } from '@dxos/react-ui';
|
|
10
10
|
import { type ShapeComponentProps, type ShapeDef } from '@dxos/react-ui-canvas-editor';
|
|
11
|
-
import { mx } from '@dxos/
|
|
11
|
+
import { mx } from '@dxos/ui-theme';
|
|
12
12
|
|
|
13
13
|
import { useComputeNodeState } from '../hooks';
|
|
14
14
|
|
|
@@ -28,7 +28,11 @@ export type QueueShape = Schema.Schema.Type<typeof QueueShape>;
|
|
|
28
28
|
export type CreateQueueProps = CreateShapeProps<QueueShape>;
|
|
29
29
|
|
|
30
30
|
export const createQueue = (props: CreateQueueProps) =>
|
|
31
|
-
createShape<QueueShape>({
|
|
31
|
+
createShape<QueueShape>({
|
|
32
|
+
type: 'queue',
|
|
33
|
+
size: { width: 256, height: 512 },
|
|
34
|
+
...props,
|
|
35
|
+
});
|
|
32
36
|
|
|
33
37
|
export const QueueComponent = ({ shape }: ShapeComponentProps<QueueShape>) => {
|
|
34
38
|
const { runtime } = useComputeNodeState(shape);
|
package/src/shapes/Thread.tsx
CHANGED
|
@@ -8,8 +8,8 @@ import React, { useEffect, useRef } from 'react';
|
|
|
8
8
|
import { createInputSchema, createOutputSchema } from '@dxos/conductor';
|
|
9
9
|
import { type ThemedClassName } from '@dxos/react-ui';
|
|
10
10
|
import { type ShapeComponentProps, type ShapeDef } from '@dxos/react-ui-canvas-editor';
|
|
11
|
-
import { mx } from '@dxos/react-ui-theme';
|
|
12
11
|
import { Message } from '@dxos/types';
|
|
12
|
+
import { mx } from '@dxos/ui-theme';
|
|
13
13
|
|
|
14
14
|
import { Box, createFunctionAnchors } from './common';
|
|
15
15
|
import { ComputeShape, type CreateShapeProps, createShape } from './defs';
|
package/src/shapes/Trigger.tsx
CHANGED
|
@@ -6,8 +6,8 @@ import * as Schema from 'effect/Schema';
|
|
|
6
6
|
import React, { useEffect } from 'react';
|
|
7
7
|
|
|
8
8
|
import { VoidInput } from '@dxos/conductor';
|
|
9
|
-
import { Filter, Query } from '@dxos/echo';
|
|
10
|
-
import {
|
|
9
|
+
import { Filter, Obj, Query, Ref, Type } from '@dxos/echo';
|
|
10
|
+
import { type Mutable } from '@dxos/echo/internal';
|
|
11
11
|
import { Trigger, TriggerEvent } from '@dxos/functions';
|
|
12
12
|
import { DXN, SpaceId } from '@dxos/keys';
|
|
13
13
|
import { useSpace } from '@dxos/react-client/echo';
|
|
@@ -21,10 +21,11 @@ export const TriggerShape = Schema.extend(
|
|
|
21
21
|
ComputeShape,
|
|
22
22
|
Schema.Struct({
|
|
23
23
|
type: Schema.Literal('trigger'),
|
|
24
|
-
functionTrigger: Schema.optional(Ref(Trigger.Trigger)),
|
|
24
|
+
functionTrigger: Schema.optional(Type.Ref(Trigger.Trigger)),
|
|
25
25
|
}),
|
|
26
26
|
);
|
|
27
|
-
|
|
27
|
+
|
|
28
|
+
export interface TriggerShape extends Schema.Schema.Type<typeof TriggerShape> {}
|
|
28
29
|
|
|
29
30
|
export type CreateTriggerProps = CreateShapeProps<Omit<TriggerShape, 'functionTrigger'>> & {
|
|
30
31
|
spaceId?: SpaceId;
|
|
@@ -52,7 +53,9 @@ export const TriggerComponent = ({ shape }: TriggerComponentProps) => {
|
|
|
52
53
|
|
|
53
54
|
useEffect(() => {
|
|
54
55
|
if (functionTrigger && !functionTrigger.spec) {
|
|
55
|
-
|
|
56
|
+
Obj.change(functionTrigger, (t) => {
|
|
57
|
+
t.spec = createTriggerSpec({ triggerKind: 'email', spaceId: space?.id }) as Mutable<Trigger.Spec>;
|
|
58
|
+
});
|
|
56
59
|
}
|
|
57
60
|
}, [functionTrigger, functionTrigger?.spec]);
|
|
58
61
|
|
|
@@ -62,7 +65,9 @@ export const TriggerComponent = ({ shape }: TriggerComponentProps) => {
|
|
|
62
65
|
|
|
63
66
|
const setKind = (kind: Trigger.Kind) => {
|
|
64
67
|
if (functionTrigger?.spec?.kind !== kind) {
|
|
65
|
-
functionTrigger
|
|
68
|
+
Obj.change(functionTrigger!, (t) => {
|
|
69
|
+
t.spec = createTriggerSpec({ triggerKind: kind, spaceId: space?.id }) as Mutable<Trigger.Spec>;
|
|
70
|
+
});
|
|
66
71
|
}
|
|
67
72
|
};
|
|
68
73
|
|
|
@@ -122,7 +127,7 @@ const createTriggerSpec = (props: { triggerKind?: Trigger.Kind; spaceId?: SpaceI
|
|
|
122
127
|
case 'email':
|
|
123
128
|
return { kind: 'email' } satisfies Trigger.EmailSpec;
|
|
124
129
|
case 'queue': {
|
|
125
|
-
const dxn = new DXN(DXN.kind.QUEUE, ['data', props.spaceId ?? SpaceId.random(),
|
|
130
|
+
const dxn = new DXN(DXN.kind.QUEUE, ['data', props.spaceId ?? SpaceId.random(), Obj.ID.random()]).toString();
|
|
126
131
|
return { kind: 'queue', queue: dxn } satisfies Trigger.QueueSpec;
|
|
127
132
|
}
|
|
128
133
|
}
|
|
@@ -8,7 +8,7 @@ import { invariant } from '@dxos/invariant';
|
|
|
8
8
|
import { Icon, IconButton, type ThemedClassName } from '@dxos/react-ui';
|
|
9
9
|
import { useEditorContext, useShapeDef } from '@dxos/react-ui-canvas-editor';
|
|
10
10
|
import { type Shape } from '@dxos/react-ui-canvas-editor';
|
|
11
|
-
import { mx } from '@dxos/
|
|
11
|
+
import { mx } from '@dxos/ui-theme';
|
|
12
12
|
|
|
13
13
|
export const headerHeight = 32;
|
|
14
14
|
export const footerHeight = 32;
|
package/src/shapes/defs.ts
CHANGED
|
@@ -6,7 +6,7 @@ import * as Schema from 'effect/Schema';
|
|
|
6
6
|
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
7
|
|
|
8
8
|
import { DEFAULT_INPUT, DEFAULT_OUTPUT } from '@dxos/conductor';
|
|
9
|
-
import {
|
|
9
|
+
import { Obj } from '@dxos/echo';
|
|
10
10
|
import { Polygon } from '@dxos/react-ui-canvas-editor';
|
|
11
11
|
import { type MakeOptional } from '@dxos/util';
|
|
12
12
|
|
|
@@ -37,7 +37,7 @@ export const ComputeShape = Schema.extend(
|
|
|
37
37
|
Polygon,
|
|
38
38
|
Schema.Struct({
|
|
39
39
|
// TODO(burdon): Rename computeNode?
|
|
40
|
-
node: Schema.optional(
|
|
40
|
+
node: Schema.optional(Obj.ID.annotations({ description: 'Compute node id' })),
|
|
41
41
|
}).pipe(Schema.mutable),
|
|
42
42
|
);
|
|
43
43
|
|
|
@@ -45,7 +45,7 @@ export type ComputeShape = Schema.Schema.Type<typeof ComputeShape>;
|
|
|
45
45
|
|
|
46
46
|
export const createShape = <S extends ComputeShape>({ id, ...rest }: CreateShapeProps<S> & { type: string }): S => {
|
|
47
47
|
return {
|
|
48
|
-
id: id ??
|
|
48
|
+
id: id ?? Obj.ID.random(),
|
|
49
49
|
...rest,
|
|
50
50
|
} as S;
|
|
51
51
|
};
|
package/src/testing/circuits.ts
CHANGED
|
@@ -3,14 +3,10 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { createSystemPrompt } from '@dxos/assistant';
|
|
6
|
-
import { ObjectId } from '@dxos/
|
|
7
|
-
import { type ServiceContainer } from '@dxos/functions-runtime';
|
|
8
|
-
import { DXN, SpaceId } from '@dxos/keys';
|
|
6
|
+
import { DXN, ObjectId, SpaceId } from '@dxos/keys';
|
|
9
7
|
import { type Dimension, type Point } from '@dxos/react-ui-canvas';
|
|
10
8
|
import { CanvasGraphModel, createNote, pointMultiply, pointsToRect, rectToPoints } from '@dxos/react-ui-canvas-editor';
|
|
11
9
|
|
|
12
|
-
import { ComputeGraphController } from '../graph';
|
|
13
|
-
import { createComputeGraph } from '../hooks';
|
|
14
10
|
import {
|
|
15
11
|
type ComputeShape,
|
|
16
12
|
createAnd,
|
|
@@ -38,19 +34,14 @@ import {
|
|
|
38
34
|
createTextToImage,
|
|
39
35
|
} from '../shapes';
|
|
40
36
|
|
|
41
|
-
export const createComputeGraphController = (
|
|
42
|
-
graph: CanvasGraphModel<ComputeShape>,
|
|
43
|
-
serviceContainer: ServiceContainer,
|
|
44
|
-
) => {
|
|
45
|
-
const computeGraph = createComputeGraph(graph);
|
|
46
|
-
const controller = new ComputeGraphController(serviceContainer, computeGraph);
|
|
47
|
-
return { controller, graph };
|
|
48
|
-
};
|
|
49
|
-
|
|
50
37
|
//
|
|
51
38
|
// Circuits
|
|
52
39
|
//
|
|
53
40
|
|
|
41
|
+
export const createEmptyCircuit = () => {
|
|
42
|
+
return CanvasGraphModel.create<ComputeShape>();
|
|
43
|
+
};
|
|
44
|
+
|
|
54
45
|
export const createBasicCircuit = () => {
|
|
55
46
|
const model = CanvasGraphModel.create<ComputeShape>();
|
|
56
47
|
model.builder.call(({ model }) => {
|