@dxos/react-ui-canvas-compute 0.7.5-labs.5f04cf6

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.
Files changed (149) hide show
  1. package/LICENSE +8 -0
  2. package/README.md +1 -0
  3. package/dist/lib/browser/index.mjs +2499 -0
  4. package/dist/lib/browser/index.mjs.map +7 -0
  5. package/dist/lib/browser/meta.json +1 -0
  6. package/dist/lib/node/index.cjs +2591 -0
  7. package/dist/lib/node/index.cjs.map +7 -0
  8. package/dist/lib/node/meta.json +1 -0
  9. package/dist/lib/node-esm/index.mjs +2499 -0
  10. package/dist/lib/node-esm/index.mjs.map +7 -0
  11. package/dist/lib/node-esm/meta.json +1 -0
  12. package/dist/types/src/compute-layout.d.ts +9 -0
  13. package/dist/types/src/compute-layout.d.ts.map +1 -0
  14. package/dist/types/src/compute.stories.d.ts +28 -0
  15. package/dist/types/src/compute.stories.d.ts.map +1 -0
  16. package/dist/types/src/graph/controller.d.ts +139 -0
  17. package/dist/types/src/graph/controller.d.ts.map +1 -0
  18. package/dist/types/src/graph/index.d.ts +3 -0
  19. package/dist/types/src/graph/index.d.ts.map +1 -0
  20. package/dist/types/src/graph/node-defs.d.ts +6 -0
  21. package/dist/types/src/graph/node-defs.d.ts.map +1 -0
  22. package/dist/types/src/hooks/compute-context.d.ts +7 -0
  23. package/dist/types/src/hooks/compute-context.d.ts.map +1 -0
  24. package/dist/types/src/hooks/index.d.ts +4 -0
  25. package/dist/types/src/hooks/index.d.ts.map +1 -0
  26. package/dist/types/src/hooks/useComputeNodeState.d.ts +19 -0
  27. package/dist/types/src/hooks/useComputeNodeState.d.ts.map +1 -0
  28. package/dist/types/src/hooks/useGraphMonitor.d.ts +14 -0
  29. package/dist/types/src/hooks/useGraphMonitor.d.ts.map +1 -0
  30. package/dist/types/src/index.d.ts +6 -0
  31. package/dist/types/src/index.d.ts.map +1 -0
  32. package/dist/types/src/json.test.d.ts +21 -0
  33. package/dist/types/src/json.test.d.ts.map +1 -0
  34. package/dist/types/src/registry.d.ts +9 -0
  35. package/dist/types/src/registry.d.ts.map +1 -0
  36. package/dist/types/src/schema.test.d.ts +2 -0
  37. package/dist/types/src/schema.test.d.ts.map +1 -0
  38. package/dist/types/src/shapes/Append.d.ts +54 -0
  39. package/dist/types/src/shapes/Append.d.ts.map +1 -0
  40. package/dist/types/src/shapes/Array.d.ts +38 -0
  41. package/dist/types/src/shapes/Array.d.ts.map +1 -0
  42. package/dist/types/src/shapes/Audio.d.ts +54 -0
  43. package/dist/types/src/shapes/Audio.d.ts.map +1 -0
  44. package/dist/types/src/shapes/Beacon.d.ts +54 -0
  45. package/dist/types/src/shapes/Beacon.d.ts.map +1 -0
  46. package/dist/types/src/shapes/Boolean.d.ts +233 -0
  47. package/dist/types/src/shapes/Boolean.d.ts.map +1 -0
  48. package/dist/types/src/shapes/Chat.d.ts +57 -0
  49. package/dist/types/src/shapes/Chat.d.ts.map +1 -0
  50. package/dist/types/src/shapes/Constant.d.ts +60 -0
  51. package/dist/types/src/shapes/Constant.d.ts.map +1 -0
  52. package/dist/types/src/shapes/Database.d.ts +54 -0
  53. package/dist/types/src/shapes/Database.d.ts.map +1 -0
  54. package/dist/types/src/shapes/Function.d.ts +54 -0
  55. package/dist/types/src/shapes/Function.d.ts.map +1 -0
  56. package/dist/types/src/shapes/Gpt.d.ts +54 -0
  57. package/dist/types/src/shapes/Gpt.d.ts.map +1 -0
  58. package/dist/types/src/shapes/GptRealtime.d.ts +54 -0
  59. package/dist/types/src/shapes/GptRealtime.d.ts.map +1 -0
  60. package/dist/types/src/shapes/Json.d.ts +107 -0
  61. package/dist/types/src/shapes/Json.d.ts.map +1 -0
  62. package/dist/types/src/shapes/Logic.d.ts +109 -0
  63. package/dist/types/src/shapes/Logic.d.ts.map +1 -0
  64. package/dist/types/src/shapes/Queue.d.ts +58 -0
  65. package/dist/types/src/shapes/Queue.d.ts.map +1 -0
  66. package/dist/types/src/shapes/RNG.d.ts +58 -0
  67. package/dist/types/src/shapes/RNG.d.ts.map +1 -0
  68. package/dist/types/src/shapes/Scope.d.ts +54 -0
  69. package/dist/types/src/shapes/Scope.d.ts.map +1 -0
  70. package/dist/types/src/shapes/Surface.d.ts +54 -0
  71. package/dist/types/src/shapes/Surface.d.ts.map +1 -0
  72. package/dist/types/src/shapes/Switch.d.ts +54 -0
  73. package/dist/types/src/shapes/Switch.d.ts.map +1 -0
  74. package/dist/types/src/shapes/Table.d.ts +54 -0
  75. package/dist/types/src/shapes/Table.d.ts.map +1 -0
  76. package/dist/types/src/shapes/Template.d.ts +56 -0
  77. package/dist/types/src/shapes/Template.d.ts.map +1 -0
  78. package/dist/types/src/shapes/Text.d.ts +54 -0
  79. package/dist/types/src/shapes/Text.d.ts.map +1 -0
  80. package/dist/types/src/shapes/TextToImage.d.ts +54 -0
  81. package/dist/types/src/shapes/TextToImage.d.ts.map +1 -0
  82. package/dist/types/src/shapes/Thread.d.ts +58 -0
  83. package/dist/types/src/shapes/Thread.d.ts.map +1 -0
  84. package/dist/types/src/shapes/Trigger.d.ts +64 -0
  85. package/dist/types/src/shapes/Trigger.d.ts.map +1 -0
  86. package/dist/types/src/shapes/common/Box.d.ts +25 -0
  87. package/dist/types/src/shapes/common/Box.d.ts.map +1 -0
  88. package/dist/types/src/shapes/common/FunctionBody.d.ts +15 -0
  89. package/dist/types/src/shapes/common/FunctionBody.d.ts.map +1 -0
  90. package/dist/types/src/shapes/common/TypeSelect.d.ts +4 -0
  91. package/dist/types/src/shapes/common/TypeSelect.d.ts.map +1 -0
  92. package/dist/types/src/shapes/common/index.d.ts +4 -0
  93. package/dist/types/src/shapes/common/index.d.ts.map +1 -0
  94. package/dist/types/src/shapes/defs.d.ts +39 -0
  95. package/dist/types/src/shapes/defs.d.ts.map +1 -0
  96. package/dist/types/src/shapes/index.d.ts +27 -0
  97. package/dist/types/src/shapes/index.d.ts.map +1 -0
  98. package/dist/types/src/testing/circuits.d.ts +193 -0
  99. package/dist/types/src/testing/circuits.d.ts.map +1 -0
  100. package/dist/types/src/testing/index.d.ts +2 -0
  101. package/dist/types/src/testing/index.d.ts.map +1 -0
  102. package/dist/types/tsconfig.tsbuildinfo +1 -0
  103. package/package.json +85 -0
  104. package/src/README.md +47 -0
  105. package/src/compute-layout.ts +37 -0
  106. package/src/compute.stories.tsx +362 -0
  107. package/src/graph/controller.ts +405 -0
  108. package/src/graph/index.ts +6 -0
  109. package/src/graph/node-defs.ts +82 -0
  110. package/src/hooks/compute-context.ts +19 -0
  111. package/src/hooks/index.ts +7 -0
  112. package/src/hooks/useComputeNodeState.ts +83 -0
  113. package/src/hooks/useGraphMonitor.ts +133 -0
  114. package/src/index.ts +9 -0
  115. package/src/json.test.ts +35 -0
  116. package/src/registry.ts +100 -0
  117. package/src/schema.test.ts +62 -0
  118. package/src/shapes/Append.tsx +43 -0
  119. package/src/shapes/Array.tsx +61 -0
  120. package/src/shapes/Audio.tsx +55 -0
  121. package/src/shapes/Beacon.tsx +56 -0
  122. package/src/shapes/Boolean.tsx +215 -0
  123. package/src/shapes/Chat.tsx +77 -0
  124. package/src/shapes/Constant.tsx +125 -0
  125. package/src/shapes/Database.tsx +39 -0
  126. package/src/shapes/Function.tsx +40 -0
  127. package/src/shapes/Gpt.tsx +91 -0
  128. package/src/shapes/GptRealtime.tsx +168 -0
  129. package/src/shapes/Json.tsx +103 -0
  130. package/src/shapes/Logic.tsx +82 -0
  131. package/src/shapes/Queue.tsx +78 -0
  132. package/src/shapes/RNG.tsx +84 -0
  133. package/src/shapes/Scope.tsx +54 -0
  134. package/src/shapes/Surface.tsx +57 -0
  135. package/src/shapes/Switch.tsx +53 -0
  136. package/src/shapes/Table.tsx +45 -0
  137. package/src/shapes/Template.tsx +98 -0
  138. package/src/shapes/Text.tsx +56 -0
  139. package/src/shapes/TextToImage.tsx +39 -0
  140. package/src/shapes/Thread.tsx +87 -0
  141. package/src/shapes/Trigger.tsx +152 -0
  142. package/src/shapes/common/Box.tsx +74 -0
  143. package/src/shapes/common/FunctionBody.tsx +122 -0
  144. package/src/shapes/common/TypeSelect.tsx +27 -0
  145. package/src/shapes/common/index.ts +7 -0
  146. package/src/shapes/defs.ts +50 -0
  147. package/src/shapes/index.ts +31 -0
  148. package/src/testing/circuits.ts +320 -0
  149. package/src/testing/index.ts +5 -0
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+
3
+ import { Select, type SelectRootProps } from '@dxos/react-ui';
4
+ import { ComputeValueType } from '@dxos/conductor';
5
+
6
+ // TODO(burdon): Factor out.
7
+ export const TypeSelect = ({ value, onValueChange }: Pick<SelectRootProps, 'value' | 'onValueChange'>) => {
8
+ return (
9
+ <Select.Root value={value} onValueChange={onValueChange}>
10
+ <Select.TriggerButton variant='ghost' classNames='w-full !px-0' />
11
+ <Select.Portal>
12
+ <Select.Content>
13
+ <Select.ScrollUpButton />
14
+ <Select.Viewport>
15
+ {ComputeValueType.literals.map((type) => (
16
+ <Select.Option key={type} value={type}>
17
+ {type}
18
+ </Select.Option>
19
+ ))}
20
+ </Select.Viewport>
21
+ <Select.ScrollDownButton />
22
+ <Select.Arrow />
23
+ </Select.Content>
24
+ </Select.Portal>
25
+ </Select.Root>
26
+ );
27
+ };
@@ -0,0 +1,7 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * from './Box';
6
+ export * from './FunctionBody';
7
+ export * from './TypeSelect';
@@ -0,0 +1,50 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { AST } from '@effect/schema';
6
+
7
+ import { DEFAULT_INPUT, DEFAULT_OUTPUT } from '@dxos/conductor';
8
+ import { ObjectId, S } from '@dxos/echo-schema';
9
+ import { Polygon } from '@dxos/react-ui-canvas-editor';
10
+ import { type MakeOptional } from '@dxos/util';
11
+
12
+ //
13
+ // Properties
14
+ //
15
+
16
+ export type PropertyKind = 'input' | 'output';
17
+
18
+ export const getProperties = (ast: AST.AST) =>
19
+ AST.getPropertySignatures(ast).map(({ name }) => ({ name: name.toString() }));
20
+
21
+ export const createAnchorId = (kind: PropertyKind, property = kind === 'input' ? DEFAULT_INPUT : DEFAULT_OUTPUT) =>
22
+ [kind, property].join('.');
23
+
24
+ export const parseAnchorId = (id: string): [PropertyKind | undefined, string] => {
25
+ const parts = id.match(/(input|output)\.(.+)/);
26
+ return parts ? (parts.slice(1) as any) : [undefined, id];
27
+ };
28
+
29
+ //
30
+ // Shapes
31
+ //
32
+
33
+ export type CreateShapeProps<S extends Polygon> = Omit<MakeOptional<S, 'id' | 'size'>, 'type' | 'node'>;
34
+
35
+ export const ComputeShape = S.extend(
36
+ Polygon,
37
+ S.Struct({
38
+ // TODO(burdon): Rename computeNode?
39
+ node: S.optional(ObjectId.annotations({ [AST.DescriptionAnnotationId]: 'Compute node id' })),
40
+ }).pipe(S.mutable),
41
+ );
42
+
43
+ export type ComputeShape = S.Schema.Type<typeof ComputeShape>;
44
+
45
+ export const createShape = <S extends ComputeShape>({ id, ...rest }: CreateShapeProps<S> & { type: string }): S => {
46
+ return {
47
+ id: id ?? ObjectId.random(),
48
+ ...rest,
49
+ } as S;
50
+ };
@@ -0,0 +1,31 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ export * from './common';
6
+ export * from './defs';
7
+
8
+ export * from './Array';
9
+ export * from './Append';
10
+ export * from './Audio';
11
+ export * from './Beacon';
12
+ export * from './Boolean';
13
+ export * from './Chat';
14
+ export * from './Constant';
15
+ export * from './Database';
16
+ export * from './Function';
17
+ export * from './Gpt';
18
+ export * from './Json';
19
+ export * from './Logic';
20
+ export * from './Queue';
21
+ export * from './RNG';
22
+ export * from './Scope';
23
+ export * from './Surface';
24
+ export * from './Switch';
25
+ export * from './Table';
26
+ export * from './Template';
27
+ export * from './Text';
28
+ export * from './Thread';
29
+ export * from './TextToImage';
30
+ export * from './Trigger';
31
+ export * from './GptRealtime';
@@ -0,0 +1,320 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { createSystemPrompt } from '@dxos/artifact';
6
+ import { ObjectId } from '@dxos/echo-schema';
7
+ import { DXN, SpaceId } from '@dxos/keys';
8
+ import { type Dimension, type Point } from '@dxos/react-ui-canvas';
9
+ import { pointMultiply, pointsToRect, rectToPoints, createNote, CanvasGraphModel } from '@dxos/react-ui-canvas-editor';
10
+
11
+ import { ComputeGraphController, type Services } from '../graph';
12
+ import { createComputeGraph } from '../hooks';
13
+ import {
14
+ type ComputeShape,
15
+ createAnd,
16
+ createAppend,
17
+ createAudio,
18
+ createBeacon,
19
+ createChat,
20
+ createConstant,
21
+ createDatabase,
22
+ createGpt,
23
+ createGptRealtime,
24
+ createIf,
25
+ createIfElse,
26
+ createJson,
27
+ createJsonTransform,
28
+ createNot,
29
+ createOr,
30
+ createQueue,
31
+ createRandom,
32
+ createScope,
33
+ createSwitch,
34
+ createSurface,
35
+ createTextToImage,
36
+ createText,
37
+ createTemplate,
38
+ } from '../shapes';
39
+
40
+ export const createComputeGraphController = (graph?: CanvasGraphModel<ComputeShape>, services?: Partial<Services>) => {
41
+ const computeGraph = createComputeGraph(graph);
42
+ const controller = new ComputeGraphController(computeGraph);
43
+ controller.setServices(services ?? {});
44
+ return { controller, graph };
45
+ };
46
+
47
+ //
48
+ // Circuits
49
+ //
50
+
51
+ export const createBasicCircuit = () => {
52
+ const model = CanvasGraphModel.create<ComputeShape>();
53
+ model.builder.call(({ model }) => {
54
+ const a = model.createNode(createSwitch(position({ x: -4, y: 0 })));
55
+ const b = model.createNode(createBeacon(position({ x: 4, y: 0 })));
56
+ const c = model.createNode(createBeacon(position({ x: 4, y: 4 })));
57
+ const d = model.createNode(createNot(position({ x: 0, y: 4 })));
58
+
59
+ model.createEdge({ source: a.id, target: b.id });
60
+ model.createEdge({ source: d.id, target: c.id });
61
+ });
62
+
63
+ return model;
64
+ };
65
+
66
+ export const createTransformCircuit = () => {
67
+ const model = CanvasGraphModel.create<ComputeShape>();
68
+ model.builder.call(({ model }) => {
69
+ const a = model.createNode(createRandom(position({ x: -8, y: -3 })));
70
+ const b = model.createNode(createConstant({ value: '$[?(@ > 0.5)]', ...position({ x: -8, y: 2 }) }));
71
+ const c = model.createNode(createJsonTransform(position({ x: 0, y: 0 })));
72
+ const d = model.createNode(createBeacon(position({ x: 8, y: 0 })));
73
+
74
+ model.builder
75
+ // TODO(burdon): Make id optional.
76
+ .createNode(createNote({ id: ObjectId.random(), text: 'Random number generator', ...position({ x: 0, y: -6 }) }))
77
+ .createEdge({ source: a.id, target: c.id })
78
+ .createEdge({ source: b.id, target: c.id, input: 'expression' })
79
+ .createEdge({ source: c.id, target: d.id });
80
+ });
81
+
82
+ return model;
83
+ };
84
+
85
+ export const createLogicCircuit = () => {
86
+ const model = CanvasGraphModel.create<ComputeShape>();
87
+ model.builder.call(({ model }) => {
88
+ const a1 = model.createNode(createSwitch(position({ x: -4, y: -4 })));
89
+ const a2 = model.createNode(createSwitch(position({ x: -4, y: 0 })));
90
+ const a3 = model.createNode(createSwitch(position({ x: -4, y: 4 })));
91
+ const b1 = model.createNode(createAnd(position({ x: 0, y: -2 })));
92
+ const c1 = model.createNode(createOr(position({ x: 4, y: 0 })));
93
+ const d1 = model.createNode(createBeacon(position({ x: 8, y: 0 })));
94
+
95
+ model.builder
96
+ .createEdge({ source: a1.id, target: b1.id, input: 'a' })
97
+ .createEdge({ source: a2.id, target: b1.id, input: 'b' })
98
+ .createEdge({ source: b1.id, target: c1.id, input: 'a' })
99
+ .createEdge({ source: a3.id, target: c1.id, input: 'b' })
100
+ .createEdge({ source: c1.id, target: d1.id });
101
+ });
102
+
103
+ return model;
104
+ };
105
+
106
+ export const createControlCircuit = () => {
107
+ const model = CanvasGraphModel.create<ComputeShape>();
108
+ model.builder.call((builder) => {
109
+ const model = builder.model;
110
+
111
+ const s = model.createNode(createSwitch(position({ x: -9, y: -1 })));
112
+ const c1 = model.createNode(createConstant({ value: 'hello', ...position({ x: -10, y: -10 }) }));
113
+ const c2 = model.createNode(createConstant({ value: 'world', ...position({ x: -10, y: -5 }) }));
114
+ const c3 = model.createNode(createConstant({ value: true, ...position({ x: -10, y: 3 }) }));
115
+ const if1 = model.createNode(createIf(position({ x: 0, y: 1 })));
116
+ const if2 = model.createNode(createIfElse(position({ x: 0, y: -8 })));
117
+ const b1 = model.createNode(createBeacon(position({ x: 9, y: -1 })));
118
+ const b2 = model.createNode(createBeacon(position({ x: 9, y: 3 })));
119
+ const j = model.createNode(createJson(position({ x: 12, y: -8 })));
120
+
121
+ builder
122
+ .createEdge({ source: s.id, target: if1.id, input: 'condition' })
123
+ .createEdge({ source: s.id, target: if2.id, input: 'condition' })
124
+ .createEdge({ source: c1.id, target: if2.id, input: 'true' })
125
+ .createEdge({ source: c2.id, target: if2.id, input: 'false' })
126
+ .createEdge({ source: c3.id, target: if1.id, input: 'value' })
127
+ .createEdge({ source: if1.id, target: b1.id, output: 'true' })
128
+ .createEdge({ source: if1.id, target: b2.id, output: 'false' })
129
+ .createEdge({ source: if2.id, target: j.id });
130
+ });
131
+
132
+ return model;
133
+ };
134
+
135
+ export const createTemplateCircuit = () => {
136
+ const model = CanvasGraphModel.create<ComputeShape>();
137
+
138
+ // Gpt
139
+ model.builder.call((builder) => {
140
+ const chat = model.createNode(createChat(position({ x: -12, y: 6 })));
141
+ const template = model.createNode(createTemplate(position({ x: -12, y: -4 })));
142
+ const gpt = model.createNode(createGpt(position({ x: 0, y: 0 })));
143
+ const text = model.createNode(createText(position({ x: 14, y: 0 })));
144
+
145
+ builder
146
+ .createEdge({ source: chat.id, target: gpt.id, input: 'prompt' })
147
+ .createEdge({ source: gpt.id, target: text.id, output: 'text' })
148
+ .createEdge({ source: template.id, target: gpt.id, input: 'systemPrompt' });
149
+ });
150
+
151
+ // Text
152
+ model.builder.call((builder) => {
153
+ const text = model.createNode(
154
+ createConstant({ value: 'DXOS', ...position({ x: -12, y: 15, width: 8, height: 4 }) }),
155
+ );
156
+ const template = model.createNode(
157
+ createTemplate({ valueType: 'string', text: 'Hello, {{name}}!', ...position({ x: 0, y: 15 }) }),
158
+ );
159
+ const view = model.createNode(createSurface(position({ x: 14, y: 15 })));
160
+ builder.createEdge({ source: text.id, target: template.id, input: 'name' });
161
+ builder.createEdge({ source: template.id, target: view.id });
162
+ });
163
+
164
+ // Json
165
+ model.builder.call((builder) => {
166
+ const sender = model.createNode(
167
+ createConstant({ value: 'alice@example.com', ...position({ x: -12, y: 24, width: 8, height: 4 }) }),
168
+ );
169
+ const body = model.createNode(
170
+ createConstant({ value: 'Hello', ...position({ x: -12, y: 29, width: 8, height: 4 }) }),
171
+ );
172
+ const meta = model.createNode(
173
+ createConstant({ value: { location: 'Tokyo' }, ...position({ x: -12, y: 35, width: 8, height: 6 }) }),
174
+ );
175
+ const template = model.createNode(
176
+ createTemplate({
177
+ valueType: 'object',
178
+ text: JSON.stringify(
179
+ {
180
+ headers: {
181
+ to: '{{recipient}}',
182
+ },
183
+ body: '{{greeting}} {{recipient}}',
184
+ meta: '{{meta}}',
185
+ },
186
+ null,
187
+ 2,
188
+ ),
189
+ ...position({ x: 0, y: 30 }),
190
+ }),
191
+ );
192
+ const view = model.createNode(createSurface(position({ x: 14, y: 30 })));
193
+ builder.createEdge({ source: sender.id, target: template.id, input: 'recipient' });
194
+ builder.createEdge({ source: body.id, target: template.id, input: 'greeting' });
195
+ builder.createEdge({ source: meta.id, target: template.id, input: 'meta' });
196
+ builder.createEdge({ source: template.id, target: view.id });
197
+ });
198
+
199
+ return model;
200
+ };
201
+
202
+ export const createArtifactCircuit = () => {
203
+ const model = CanvasGraphModel.create<ComputeShape>();
204
+ model.builder.call((builder) => {
205
+ const prompt = model.createNode(
206
+ createTemplate({
207
+ text: createSystemPrompt(),
208
+ ...position({ x: -10, y: -5, width: 8, height: 18 }),
209
+ }),
210
+ );
211
+ const chat = model.createNode(createChat(position({ x: -10, y: 8, width: 8, height: 6 })));
212
+ const gpt = model.createNode(createGpt(position({ x: 0, y: 0 })));
213
+ const text = model.createNode(createText(position({ x: 16, y: 8, width: 16, height: 6 })));
214
+ const surface = model.createNode(createSurface(position({ x: 16, y: -5, width: 16, height: 18 })));
215
+ builder
216
+ .createEdge({ source: prompt.id, target: gpt.id, input: 'systemPrompt' })
217
+ .createEdge({ source: chat.id, target: gpt.id, input: 'prompt' })
218
+ .createEdge({ source: gpt.id, target: text.id, output: 'text' })
219
+ .createEdge({ source: gpt.id, target: surface.id, output: 'artifact' });
220
+ });
221
+
222
+ return model;
223
+ };
224
+
225
+ export const createGptCircuit = (options: {
226
+ db?: boolean;
227
+ cot?: boolean;
228
+ image?: boolean;
229
+ history?: boolean;
230
+ artifact?: boolean;
231
+ }) => {
232
+ const model = CanvasGraphModel.create<ComputeShape>();
233
+ model.builder.call((builder) => {
234
+ const gpt = model.createNode(createGpt(position({ x: 0, y: -14 })));
235
+ const chat = model.createNode(createChat(position({ x: -18, y: -2 })));
236
+ const text = model.createNode(createText(position({ x: 19, y: 3, width: 10, height: 10 })));
237
+ builder
238
+ .createEdge({ source: chat.id, target: gpt.id, input: 'prompt' })
239
+ .createEdge({ source: gpt.id, target: text.id, output: 'text' });
240
+
241
+ if (options.history) {
242
+ const queue = model.createNode(
243
+ createConstant({
244
+ value: new DXN(DXN.kind.QUEUE, ['data', SpaceId.random(), ObjectId.random()]).toString(),
245
+ ...position({ x: -18, y: 5, width: 8, height: 6 }),
246
+ }),
247
+ );
248
+
249
+ const thread = model.createNode(createQueue(position({ x: -3, y: 3, width: 14, height: 10 })));
250
+ const append = model.createNode(createAppend(position({ x: 10, y: 6 })));
251
+
252
+ builder
253
+ .createEdge({ source: queue.id, target: thread.id })
254
+ .createEdge({ source: queue.id, target: append.id, input: 'id' })
255
+ .createEdge({ source: gpt.id, target: append.id, output: 'messages', input: 'items' });
256
+ }
257
+
258
+ if (options.artifact) {
259
+ const prompt = model.createNode(
260
+ createTemplate({
261
+ text: createSystemPrompt(),
262
+ ...position({ x: -18, y: -12, width: 8, height: 10 }),
263
+ }),
264
+ );
265
+ const artifact = model.createNode(createSurface(position({ x: 17, y: -10, width: 14, height: 14 })));
266
+
267
+ builder
268
+ .createEdge({ source: prompt.id, target: gpt.id, input: 'systemPrompt' })
269
+ .createEdge({ source: gpt.id, target: artifact.id, output: 'artifact' });
270
+ }
271
+
272
+ if (options.cot) {
273
+ const cot = model.createNode(createText(position({ x: 0, y: -10, width: 8, height: 10 })));
274
+ builder.createEdge({ source: gpt.id, target: cot.id, output: 'cot' });
275
+ }
276
+
277
+ if (options.db) {
278
+ const database = model.createNode(createDatabase(position({ x: -10, y: 4 })));
279
+ builder.createEdge({ source: database.id, target: gpt.id, input: 'tools' });
280
+ }
281
+
282
+ if (options.image) {
283
+ const tool = model.createNode(createTextToImage(position({ x: -8, y: -16 })));
284
+ builder.createEdge({ source: tool.id, target: gpt.id, input: 'tools' });
285
+ }
286
+ });
287
+
288
+ return model;
289
+ };
290
+
291
+ export const createGPTRealtimeCircuit = () => {
292
+ return CanvasGraphModel.create<ComputeShape>({
293
+ nodes: [createGptRealtime(position({ x: 0, y: 0 }))],
294
+ });
295
+ };
296
+
297
+ export const createAudioCircuit = () => {
298
+ const model = CanvasGraphModel.create<ComputeShape>();
299
+ model.builder.call(({ model }) => {
300
+ const a = model.createNode(createAudio(position({ x: -4, y: -4 })));
301
+ const b = model.createNode(createScope(position({ x: 4, y: -4 })));
302
+ model.createEdge({ source: a.id, target: b.id });
303
+ });
304
+
305
+ return model;
306
+ };
307
+
308
+ //
309
+ // Utils
310
+ //
311
+
312
+ const position = (rect: Point & Partial<Dimension>, snap = 32): { center: Point; size?: Dimension } => {
313
+ const [center, size] = rectToPoints({ width: 0, height: 0, ...rect });
314
+ const { x, y, width, height } = pointsToRect([pointMultiply(center, snap), pointMultiply(size, snap)]);
315
+ if (width && height) {
316
+ return { center: { x, y }, size: width && height ? { width, height } : undefined };
317
+ } else {
318
+ return { center: { x, y } };
319
+ }
320
+ };
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * from './circuits';