@dxos/plugin-debug 0.7.5-labs.a279d8c → 0.7.5-labs.d453967
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/SpaceGenerator-KYSK77VG.mjs +1100 -0
- package/dist/lib/browser/SpaceGenerator-KYSK77VG.mjs.map +7 -0
- package/dist/lib/browser/{app-graph-builder-FXELWOFS.mjs → app-graph-builder-DCMGZAT3.mjs} +8 -4
- package/dist/lib/browser/app-graph-builder-DCMGZAT3.mjs.map +7 -0
- package/dist/lib/browser/chunk-EF3UVAVI.mjs +21 -0
- package/dist/lib/browser/chunk-EF3UVAVI.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +5 -11
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-ACHNR2UU.mjs → react-surface-6GVTLM4O.mjs} +54 -51
- package/dist/lib/browser/react-surface-6GVTLM4O.mjs.map +7 -0
- package/dist/lib/browser/{settings-JCZUA643.mjs → settings-OIMSBZUC.mjs} +2 -2
- package/dist/types/src/DebugPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/app-graph-builder.d.ts +22 -22
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +26 -31
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/components/DebugSettings.d.ts.map +1 -1
- package/dist/types/src/components/DebugStatus.d.ts.map +1 -1
- package/dist/types/src/components/SpaceGenerator/ObjectGenerator.d.ts.map +1 -1
- package/dist/types/src/components/SpaceGenerator/SpaceGenerator.d.ts.map +1 -1
- package/dist/types/src/components/SpaceGenerator/presets.d.ts +21 -0
- package/dist/types/src/components/SpaceGenerator/presets.d.ts.map +1 -0
- package/dist/types/src/meta.d.ts +1 -0
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +47 -46
- package/src/DebugPlugin.tsx +2 -7
- package/src/capabilities/app-graph-builder.ts +7 -9
- package/src/capabilities/index.ts +0 -1
- package/src/capabilities/react-surface.tsx +7 -15
- package/src/components/DebugSettings.tsx +7 -9
- package/src/components/DebugStatus.tsx +17 -21
- package/src/components/SpaceGenerator/ObjectGenerator.tsx +0 -81
- package/src/components/SpaceGenerator/SpaceGenerator.tsx +7 -6
- package/src/components/SpaceGenerator/presets.ts +493 -0
- package/src/meta.ts +3 -1
- package/dist/lib/browser/SpaceGenerator-YNT3WDFI.mjs +0 -479
- package/dist/lib/browser/SpaceGenerator-YNT3WDFI.mjs.map +0 -7
- package/dist/lib/browser/app-graph-builder-FXELWOFS.mjs.map +0 -7
- package/dist/lib/browser/chunk-I3ON45JK.mjs +0 -18
- package/dist/lib/browser/chunk-I3ON45JK.mjs.map +0 -7
- package/dist/lib/browser/react-context-OZU6J7G3.mjs +0 -37
- package/dist/lib/browser/react-context-OZU6J7G3.mjs.map +0 -7
- package/dist/lib/browser/react-surface-ACHNR2UU.mjs.map +0 -7
- package/dist/types/src/capabilities/react-context.d.ts +0 -8
- package/dist/types/src/capabilities/react-context.d.ts.map +0 -1
- package/src/capabilities/react-context.tsx +0 -38
- /package/dist/lib/browser/{settings-JCZUA643.mjs.map → settings-OIMSBZUC.mjs.map} +0 -0
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type ComputeGraphModel, EmailTriggerOutput, NODE_INPUT } from '@dxos/conductor';
|
|
6
|
+
import { AST, ObjectId, S, toJsonSchema } from '@dxos/echo-schema';
|
|
7
|
+
import { FunctionTrigger, TriggerKind, type TriggerType } from '@dxos/functions/types';
|
|
8
|
+
import { invariant } from '@dxos/invariant';
|
|
9
|
+
import { DXN, SpaceId } from '@dxos/keys';
|
|
10
|
+
import { create, makeRef } from '@dxos/live-object';
|
|
11
|
+
import { Filter, type Space } from '@dxos/react-client/echo';
|
|
12
|
+
import {
|
|
13
|
+
type ComputeShape,
|
|
14
|
+
createAppend,
|
|
15
|
+
createChat,
|
|
16
|
+
createComputeGraph,
|
|
17
|
+
createConstant,
|
|
18
|
+
createFunction,
|
|
19
|
+
createGpt,
|
|
20
|
+
createQueue,
|
|
21
|
+
createSurface,
|
|
22
|
+
createRandom,
|
|
23
|
+
createTemplate,
|
|
24
|
+
createText,
|
|
25
|
+
createTrigger,
|
|
26
|
+
} from '@dxos/react-ui-canvas-compute';
|
|
27
|
+
import {
|
|
28
|
+
CanvasBoardType,
|
|
29
|
+
CanvasGraphModel,
|
|
30
|
+
pointMultiply,
|
|
31
|
+
pointsToRect,
|
|
32
|
+
rectToPoints,
|
|
33
|
+
} from '@dxos/react-ui-canvas-editor';
|
|
34
|
+
import { TableType } from '@dxos/react-ui-table';
|
|
35
|
+
import { range } from '@dxos/util';
|
|
36
|
+
|
|
37
|
+
import { type ObjectGenerator } from './ObjectGenerator';
|
|
38
|
+
|
|
39
|
+
export enum PresetName {
|
|
40
|
+
EMAIL_TABLE = 'email-table',
|
|
41
|
+
GPT_QUEUE = 'webhook-gpt-queue',
|
|
42
|
+
CHAT_GPT = 'chat-gpt-text',
|
|
43
|
+
EMAIL_WITH_SUMMARY = 'email-gptSummary-table',
|
|
44
|
+
OBJECT_CHANGE_QUEUE = 'objectChange-queue',
|
|
45
|
+
FOREX_FUNCTION_CALL = 'forex-function-call',
|
|
46
|
+
TIMER_TICK_QUEUE = 'timerTick-queue',
|
|
47
|
+
DISCORD_MESSAGES = 'discord-messages',
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const presets = {
|
|
51
|
+
schemas: [CanvasBoardType, FunctionTrigger],
|
|
52
|
+
types: Object.values(PresetName).map((name) => ({ typename: name })),
|
|
53
|
+
items: [
|
|
54
|
+
[
|
|
55
|
+
PresetName.GPT_QUEUE,
|
|
56
|
+
async (space, n, cb) => {
|
|
57
|
+
const objects = range(n, () => {
|
|
58
|
+
const canvasModel = CanvasGraphModel.create<ComputeShape>();
|
|
59
|
+
|
|
60
|
+
let functionTrigger: FunctionTrigger | undefined;
|
|
61
|
+
canvasModel.builder.call((builder) => {
|
|
62
|
+
const gpt = canvasModel.createNode(createGpt(position({ x: 0, y: -14 })));
|
|
63
|
+
const triggerShape = createTrigger({ triggerKind: TriggerKind.Webhook, ...position({ x: -18, y: -2 }) });
|
|
64
|
+
const trigger = canvasModel.createNode(triggerShape);
|
|
65
|
+
const text = canvasModel.createNode(createText(position({ x: 19, y: 3, width: 10, height: 10 })));
|
|
66
|
+
const { queueId } = setupQueue(canvasModel);
|
|
67
|
+
const append = canvasModel.createNode(createAppend(position({ x: 10, y: 6 })));
|
|
68
|
+
|
|
69
|
+
builder
|
|
70
|
+
.createEdge({ source: trigger.id, target: gpt.id, input: 'prompt', output: 'bodyText' })
|
|
71
|
+
.createEdge({ source: gpt.id, target: text.id, output: 'text' })
|
|
72
|
+
.createEdge({ source: queueId.id, target: append.id, input: 'id' })
|
|
73
|
+
.createEdge({ source: gpt.id, target: append.id, output: 'messages', input: 'items' });
|
|
74
|
+
|
|
75
|
+
functionTrigger = triggerShape.functionTrigger!.target!;
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const computeModel = createComputeGraph(canvasModel);
|
|
79
|
+
|
|
80
|
+
attachTrigger(functionTrigger, computeModel);
|
|
81
|
+
|
|
82
|
+
return addToSpace(PresetName.GPT_QUEUE, space, canvasModel, computeModel);
|
|
83
|
+
});
|
|
84
|
+
cb?.(objects);
|
|
85
|
+
return objects;
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
|
|
89
|
+
[
|
|
90
|
+
PresetName.OBJECT_CHANGE_QUEUE,
|
|
91
|
+
async (space, n, cb) => {
|
|
92
|
+
const objects = range(n, () => {
|
|
93
|
+
const { canvasModel, computeModel } = createQueueSinkPreset(
|
|
94
|
+
TriggerKind.Subscription,
|
|
95
|
+
(triggerSpec) => (triggerSpec.filter = { type: 'dxn:type:dxos.org/type/Chess' }),
|
|
96
|
+
'type',
|
|
97
|
+
);
|
|
98
|
+
return addToSpace(PresetName.OBJECT_CHANGE_QUEUE, space, canvasModel, computeModel);
|
|
99
|
+
});
|
|
100
|
+
cb?.(objects);
|
|
101
|
+
return objects;
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
|
|
105
|
+
[
|
|
106
|
+
PresetName.TIMER_TICK_QUEUE,
|
|
107
|
+
async (space, n, cb) => {
|
|
108
|
+
const objects = range(n, () => {
|
|
109
|
+
const { canvasModel, computeModel } = createQueueSinkPreset(
|
|
110
|
+
TriggerKind.Timer,
|
|
111
|
+
(triggerSpec) => (triggerSpec.cron = '*/5 * * * * *'),
|
|
112
|
+
'result',
|
|
113
|
+
);
|
|
114
|
+
return addToSpace(PresetName.TIMER_TICK_QUEUE, space, canvasModel, computeModel);
|
|
115
|
+
});
|
|
116
|
+
cb?.(objects);
|
|
117
|
+
return objects;
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
|
|
121
|
+
[
|
|
122
|
+
PresetName.EMAIL_TABLE,
|
|
123
|
+
async (space, n, cb) => {
|
|
124
|
+
const objects = range(n, () => {
|
|
125
|
+
const canvasModel = CanvasGraphModel.create<ComputeShape>();
|
|
126
|
+
|
|
127
|
+
const results = space.db.query(Filter.schema(TableType)).runSync();
|
|
128
|
+
const emailTable = results.find((r) => r.object?.view?.target?.query?.type?.endsWith('Email'));
|
|
129
|
+
invariant(emailTable, 'Email table not found.');
|
|
130
|
+
|
|
131
|
+
const template = canvasModel.createNode(
|
|
132
|
+
createTemplate({
|
|
133
|
+
valueType: 'object',
|
|
134
|
+
...rawPosition({ centerX: -80, centerY: -64, width: 320, height: 320 }),
|
|
135
|
+
}),
|
|
136
|
+
);
|
|
137
|
+
const templateContent = ['{'];
|
|
138
|
+
|
|
139
|
+
let functionTrigger: FunctionTrigger | undefined;
|
|
140
|
+
canvasModel.builder.call((builder) => {
|
|
141
|
+
const triggerShape = createTrigger({ triggerKind: TriggerKind.Email, ...position({ x: -18, y: -2 }) });
|
|
142
|
+
const trigger = canvasModel.createNode(triggerShape);
|
|
143
|
+
|
|
144
|
+
const tableId = canvasModel.createNode(
|
|
145
|
+
createConstant({
|
|
146
|
+
value: DXN.fromLocalObjectId(emailTable.id).toString(),
|
|
147
|
+
...position({ x: -18, y: 5, width: 8, height: 6 }),
|
|
148
|
+
}),
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const appendToTable = canvasModel.createNode(createAppend(position({ x: 10, y: 6 })));
|
|
152
|
+
|
|
153
|
+
const properties = AST.getPropertySignatures(EmailTriggerOutput.ast);
|
|
154
|
+
for (let i = 0; i < properties.length; i++) {
|
|
155
|
+
const propName = properties[i].name.toString();
|
|
156
|
+
builder.createEdge({ source: trigger.id, target: template.id, input: propName, output: propName });
|
|
157
|
+
templateContent.push(` "${propName}": "{{${propName}}}"` + (i === properties.length - 1 ? '' : ','));
|
|
158
|
+
}
|
|
159
|
+
templateContent.push('}');
|
|
160
|
+
|
|
161
|
+
builder
|
|
162
|
+
.createEdge({ source: tableId.id, target: appendToTable.id, input: 'id' })
|
|
163
|
+
.createEdge({ source: template.id, target: appendToTable.id, input: 'items' });
|
|
164
|
+
|
|
165
|
+
functionTrigger = triggerShape.functionTrigger!.target!;
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const computeModel = createComputeGraph(canvasModel);
|
|
169
|
+
|
|
170
|
+
const templateComputeNode = computeModel.nodes.find((n) => n.id === template.node);
|
|
171
|
+
invariant(templateComputeNode, 'Template compute node was not created.');
|
|
172
|
+
templateComputeNode.value = templateContent.join('\n');
|
|
173
|
+
templateComputeNode.inputSchema = toJsonSchema(EmailTriggerOutput);
|
|
174
|
+
|
|
175
|
+
attachTrigger(functionTrigger, computeModel);
|
|
176
|
+
|
|
177
|
+
return addToSpace(PresetName.EMAIL_TABLE, space, canvasModel, computeModel);
|
|
178
|
+
});
|
|
179
|
+
cb?.(objects);
|
|
180
|
+
return objects;
|
|
181
|
+
},
|
|
182
|
+
],
|
|
183
|
+
|
|
184
|
+
[
|
|
185
|
+
PresetName.CHAT_GPT,
|
|
186
|
+
async (space, n, cb) => {
|
|
187
|
+
const objects = range(n, () => {
|
|
188
|
+
const canvasModel = CanvasGraphModel.create<ComputeShape>();
|
|
189
|
+
|
|
190
|
+
canvasModel.builder.call((builder) => {
|
|
191
|
+
const gpt = canvasModel.createNode(createGpt(position({ x: 0, y: -14 })));
|
|
192
|
+
const chat = canvasModel.createNode(createChat(position({ x: -18, y: -2 })));
|
|
193
|
+
const text = canvasModel.createNode(createText(position({ x: 19, y: 3, width: 10, height: 10 })));
|
|
194
|
+
const { queueId } = setupQueue(canvasModel);
|
|
195
|
+
|
|
196
|
+
const append = canvasModel.createNode(createAppend(position({ x: 10, y: 6 })));
|
|
197
|
+
|
|
198
|
+
builder
|
|
199
|
+
.createEdge({ source: chat.id, target: gpt.id, input: 'prompt' })
|
|
200
|
+
.createEdge({ source: gpt.id, target: text.id, output: 'text' })
|
|
201
|
+
.createEdge({ source: queueId.id, target: append.id, input: 'id' })
|
|
202
|
+
.createEdge({ source: gpt.id, target: append.id, output: 'messages', input: 'items' });
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
const computeModel = createComputeGraph(canvasModel);
|
|
206
|
+
|
|
207
|
+
return addToSpace(PresetName.CHAT_GPT, space, canvasModel, computeModel);
|
|
208
|
+
});
|
|
209
|
+
cb?.(objects);
|
|
210
|
+
return objects;
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
|
|
214
|
+
[
|
|
215
|
+
PresetName.EMAIL_WITH_SUMMARY,
|
|
216
|
+
async (space, n, cb) => {
|
|
217
|
+
const objects = range(n, () => {
|
|
218
|
+
const canvasModel = CanvasGraphModel.create<ComputeShape>();
|
|
219
|
+
|
|
220
|
+
const results = space.db.query(Filter.schema(TableType)).runSync();
|
|
221
|
+
const emailTable = results.find((r) => r.object?.view?.target?.query?.type?.endsWith('Email'));
|
|
222
|
+
invariant(emailTable, 'Email table not found.');
|
|
223
|
+
|
|
224
|
+
const template = canvasModel.createNode(
|
|
225
|
+
createTemplate({
|
|
226
|
+
valueType: 'object',
|
|
227
|
+
...rawPosition({ centerX: 192, centerY: -176, width: 320, height: 320 }),
|
|
228
|
+
}),
|
|
229
|
+
);
|
|
230
|
+
const templateContent = ['{'];
|
|
231
|
+
|
|
232
|
+
let functionTrigger: FunctionTrigger | undefined;
|
|
233
|
+
canvasModel.builder.call((builder) => {
|
|
234
|
+
const gpt = canvasModel.createNode(
|
|
235
|
+
createGpt(rawPosition({ centerX: -400, centerY: -112, width: 256, height: 202 })),
|
|
236
|
+
);
|
|
237
|
+
const systemPrompt = canvasModel.createNode(
|
|
238
|
+
createConstant({
|
|
239
|
+
value: "use one word to describe content category. don't write anything else",
|
|
240
|
+
...rawPosition({ centerX: -800, centerY: -160, width: 192, height: 128 }),
|
|
241
|
+
}),
|
|
242
|
+
);
|
|
243
|
+
const triggerShape = createTrigger({
|
|
244
|
+
triggerKind: TriggerKind.Email,
|
|
245
|
+
...rawPosition({ centerX: -736, centerY: -384, width: 182, height: 192 }),
|
|
246
|
+
});
|
|
247
|
+
const trigger = canvasModel.createNode(triggerShape);
|
|
248
|
+
|
|
249
|
+
const { queueId } = setupQueue(canvasModel, {
|
|
250
|
+
idPosition: { centerX: -720, centerY: 224, width: 192, height: 256 },
|
|
251
|
+
queuePosition: { centerX: -144, centerY: 416, width: 320, height: 448 },
|
|
252
|
+
});
|
|
253
|
+
const appendToQueue = canvasModel.createNode(
|
|
254
|
+
createAppend(rawPosition({ centerX: -80, centerY: 96, width: 122, height: 128 })),
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
const tableId = canvasModel.createNode(
|
|
258
|
+
createConstant({
|
|
259
|
+
value: DXN.fromLocalObjectId(emailTable.id).toString(),
|
|
260
|
+
...rawPosition({ centerX: -112, centerY: -544, width: 192, height: 256 }),
|
|
261
|
+
}),
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
const appendToTable = canvasModel.createNode(
|
|
265
|
+
createAppend(rawPosition({ centerX: 560, centerY: -416, width: 128, height: 122 })),
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
templateContent.push(' "category": "{{text}}",');
|
|
269
|
+
builder.createEdge({ source: gpt.id, target: template.id, input: 'text', output: 'text' });
|
|
270
|
+
|
|
271
|
+
const properties = AST.getPropertySignatures(EmailTriggerOutput.ast);
|
|
272
|
+
for (let i = 0; i < properties.length; i++) {
|
|
273
|
+
const propName = properties[i].name.toString();
|
|
274
|
+
builder.createEdge({ source: trigger.id, target: template.id, input: propName, output: propName });
|
|
275
|
+
templateContent.push(` "${propName}": "{{${propName}}}"` + (i === properties.length - 1 ? '' : ','));
|
|
276
|
+
}
|
|
277
|
+
templateContent.push('}');
|
|
278
|
+
|
|
279
|
+
builder
|
|
280
|
+
.createEdge({ source: tableId.id, target: appendToTable.id, input: 'id' })
|
|
281
|
+
.createEdge({ source: queueId.id, target: appendToQueue.id, input: 'id' })
|
|
282
|
+
.createEdge({ source: gpt.id, target: appendToQueue.id, output: 'messages', input: 'items' })
|
|
283
|
+
.createEdge({ source: systemPrompt.id, target: gpt.id, input: 'systemPrompt' })
|
|
284
|
+
.createEdge({ source: trigger.id, target: gpt.id, input: 'prompt', output: 'body' })
|
|
285
|
+
.createEdge({ source: template.id, target: appendToTable.id, input: 'items' });
|
|
286
|
+
|
|
287
|
+
functionTrigger = triggerShape.functionTrigger!.target!;
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
const computeModel = createComputeGraph(canvasModel);
|
|
291
|
+
|
|
292
|
+
const templateComputeNode = computeModel.nodes.find((n) => n.id === template.node);
|
|
293
|
+
invariant(templateComputeNode, 'Template compute node was not created.');
|
|
294
|
+
templateComputeNode.value = templateContent.join('\n');
|
|
295
|
+
const extendedSchema = S.extend(EmailTriggerOutput, S.Struct({ text: S.String }));
|
|
296
|
+
templateComputeNode.inputSchema = toJsonSchema(extendedSchema);
|
|
297
|
+
|
|
298
|
+
attachTrigger(functionTrigger, computeModel);
|
|
299
|
+
|
|
300
|
+
return addToSpace(PresetName.EMAIL_WITH_SUMMARY, space, canvasModel, computeModel);
|
|
301
|
+
});
|
|
302
|
+
cb?.(objects);
|
|
303
|
+
return objects;
|
|
304
|
+
},
|
|
305
|
+
],
|
|
306
|
+
[
|
|
307
|
+
PresetName.FOREX_FUNCTION_CALL,
|
|
308
|
+
async (space, n, cb) => {
|
|
309
|
+
const objects = range(n, () => {
|
|
310
|
+
const canvasModel = CanvasGraphModel.create<ComputeShape>();
|
|
311
|
+
|
|
312
|
+
canvasModel.builder.call((builder) => {
|
|
313
|
+
const sourceCurrency = canvasModel.createNode(
|
|
314
|
+
createConstant({ value: 'USD', ...position({ x: -10, y: -5 }) }),
|
|
315
|
+
);
|
|
316
|
+
const targetCurrency = canvasModel.createNode(
|
|
317
|
+
createConstant({ value: 'EUR', ...position({ x: -10, y: 5 }) }),
|
|
318
|
+
);
|
|
319
|
+
const converter = canvasModel.createNode(createFunction(position({ x: 0, y: 0 })));
|
|
320
|
+
const view = canvasModel.createNode(createSurface(position({ x: 12, y: 0 })));
|
|
321
|
+
|
|
322
|
+
builder
|
|
323
|
+
.createEdge({ source: sourceCurrency.id, target: converter.id, input: 'from' })
|
|
324
|
+
.createEdge({ source: targetCurrency.id, target: converter.id, input: 'to' })
|
|
325
|
+
.createEdge({ source: converter.id, target: view.id, output: 'rate' });
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
const computeModel = createComputeGraph(canvasModel);
|
|
329
|
+
|
|
330
|
+
return addToSpace(PresetName.FOREX_FUNCTION_CALL, space, canvasModel, computeModel);
|
|
331
|
+
});
|
|
332
|
+
cb?.(objects);
|
|
333
|
+
return objects;
|
|
334
|
+
},
|
|
335
|
+
],
|
|
336
|
+
[
|
|
337
|
+
PresetName.DISCORD_MESSAGES,
|
|
338
|
+
async (space, n, cb) => {
|
|
339
|
+
const objects = range(n, () => {
|
|
340
|
+
const canvasModel = CanvasGraphModel.create<ComputeShape>();
|
|
341
|
+
|
|
342
|
+
let functionTrigger: FunctionTrigger | undefined;
|
|
343
|
+
canvasModel.builder.call((builder) => {
|
|
344
|
+
const triggerShape = createTrigger({ triggerKind: TriggerKind.Timer, ...position({ x: -10, y: -5 }) });
|
|
345
|
+
const trigger = canvasModel.createNode(triggerShape);
|
|
346
|
+
// DXOS dev-null channel.
|
|
347
|
+
const channelId = canvasModel.createNode(
|
|
348
|
+
createConstant({ value: '1088569858767212554', ...position({ x: -10, y: 0 }) }),
|
|
349
|
+
);
|
|
350
|
+
const queueId = canvasModel.createNode(
|
|
351
|
+
createConstant({
|
|
352
|
+
value: new DXN(DXN.kind.QUEUE, ['data', SpaceId.random(), ObjectId.random()]).toString(),
|
|
353
|
+
...position({ x: -10, y: 5 }),
|
|
354
|
+
}),
|
|
355
|
+
);
|
|
356
|
+
const converter = canvasModel.createNode(createFunction(position({ x: 0, y: 0 })));
|
|
357
|
+
const view = canvasModel.createNode(createText(position({ x: 12, y: 0 })));
|
|
358
|
+
const queue = canvasModel.createNode(createQueue(position({ x: 0, y: 12 })));
|
|
359
|
+
|
|
360
|
+
builder
|
|
361
|
+
.createEdge({ source: trigger.id, target: converter.id, input: 'tick' })
|
|
362
|
+
.createEdge({ source: channelId.id, target: converter.id, input: 'channelId' })
|
|
363
|
+
.createEdge({ source: queueId.id, target: converter.id, input: 'queueId' })
|
|
364
|
+
.createEdge({ source: converter.id, target: view.id, output: 'newMessages' })
|
|
365
|
+
.createEdge({ source: queueId.id, target: queue.id, input: 'input' });
|
|
366
|
+
|
|
367
|
+
functionTrigger = triggerShape.functionTrigger!.target!;
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
const computeModel = createComputeGraph(canvasModel);
|
|
371
|
+
attachTrigger(functionTrigger, computeModel);
|
|
372
|
+
|
|
373
|
+
return addToSpace(PresetName.DISCORD_MESSAGES, space, canvasModel, computeModel);
|
|
374
|
+
});
|
|
375
|
+
cb?.(objects);
|
|
376
|
+
return objects;
|
|
377
|
+
},
|
|
378
|
+
],
|
|
379
|
+
] as [PresetName, ObjectGenerator<any>][],
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
const createQueueSinkPreset = <SpecType extends TriggerKind>(
|
|
383
|
+
triggerKind: SpecType,
|
|
384
|
+
initSpec: (spec: Extract<TriggerType, { type: SpecType }>) => void,
|
|
385
|
+
triggerOutputName: string,
|
|
386
|
+
) => {
|
|
387
|
+
const canvasModel = CanvasGraphModel.create<ComputeShape>();
|
|
388
|
+
|
|
389
|
+
const template = canvasModel.createNode(
|
|
390
|
+
createTemplate({
|
|
391
|
+
valueType: 'object',
|
|
392
|
+
...rawPosition({ centerX: -64, centerY: -79, width: 320, height: 320 }),
|
|
393
|
+
}),
|
|
394
|
+
);
|
|
395
|
+
|
|
396
|
+
let functionTrigger: FunctionTrigger | undefined;
|
|
397
|
+
canvasModel.builder.call((builder) => {
|
|
398
|
+
const triggerShape = createTrigger({
|
|
399
|
+
triggerKind,
|
|
400
|
+
...rawPosition({ centerX: -578, centerY: -187, height: 320, width: 320 }),
|
|
401
|
+
});
|
|
402
|
+
const trigger = canvasModel.createNode(triggerShape);
|
|
403
|
+
const { queueId } = setupQueue(canvasModel, {
|
|
404
|
+
queuePosition: { centerX: -80, centerY: 378, width: 320, height: 448 },
|
|
405
|
+
});
|
|
406
|
+
const append = canvasModel.createNode(
|
|
407
|
+
createAppend(rawPosition({ centerX: 320, centerY: 192, width: 128, height: 122 })),
|
|
408
|
+
);
|
|
409
|
+
const random = canvasModel.createNode(
|
|
410
|
+
createRandom(rawPosition({ centerX: -509, centerY: -30, width: 64, height: 64 })),
|
|
411
|
+
);
|
|
412
|
+
|
|
413
|
+
builder
|
|
414
|
+
.createEdge({ source: queueId.id, target: append.id, input: 'id' })
|
|
415
|
+
.createEdge({ source: template.id, target: append.id, input: 'items' })
|
|
416
|
+
.createEdge({ source: trigger.id, target: template.id, output: triggerOutputName, input: 'type' })
|
|
417
|
+
.createEdge({
|
|
418
|
+
source: random.id,
|
|
419
|
+
target: template.id,
|
|
420
|
+
input: 'changeId',
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
functionTrigger = triggerShape.functionTrigger!.target!;
|
|
424
|
+
const triggerSpec = functionTrigger.spec;
|
|
425
|
+
invariant(triggerSpec && triggerSpec.type === triggerKind, 'No trigger spec.');
|
|
426
|
+
initSpec(triggerSpec as any);
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
const computeModel = createComputeGraph(canvasModel);
|
|
430
|
+
|
|
431
|
+
const templateComputeNode = computeModel.nodes.find((n) => n.id === template.node);
|
|
432
|
+
invariant(templateComputeNode, 'Template compute node was not created.');
|
|
433
|
+
templateComputeNode.value = ['{', ' "@type": "{{type}}",', ' "id": "@{{changeId}}"', '}'].join('\n');
|
|
434
|
+
templateComputeNode.inputSchema = toJsonSchema(S.Struct({ type: S.String, changeId: S.String }));
|
|
435
|
+
|
|
436
|
+
attachTrigger(functionTrigger, computeModel);
|
|
437
|
+
|
|
438
|
+
return { canvasModel, computeModel };
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
const addToSpace = (name: string, space: Space, canvas: CanvasGraphModel, compute: ComputeGraphModel) => {
|
|
442
|
+
return space.db.add(
|
|
443
|
+
create(CanvasBoardType, {
|
|
444
|
+
name,
|
|
445
|
+
computeGraph: makeRef(compute.root),
|
|
446
|
+
layout: canvas.graph,
|
|
447
|
+
}),
|
|
448
|
+
);
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
const setupQueue = (
|
|
452
|
+
canvasModel: CanvasGraphModel,
|
|
453
|
+
args?: { idPosition?: RawPositionInput; queuePosition?: RawPositionInput },
|
|
454
|
+
) => {
|
|
455
|
+
const queueId = canvasModel.createNode(
|
|
456
|
+
createConstant({
|
|
457
|
+
value: new DXN(DXN.kind.QUEUE, ['data', SpaceId.random(), ObjectId.random()]).toString(),
|
|
458
|
+
...(args?.idPosition ? rawPosition(args.idPosition) : position({ x: -18, y: 5, width: 8, height: 6 })),
|
|
459
|
+
}),
|
|
460
|
+
);
|
|
461
|
+
const queue = canvasModel.createNode(
|
|
462
|
+
createQueue(
|
|
463
|
+
args?.queuePosition ? rawPosition(args.queuePosition) : position({ x: -3, y: 3, width: 14, height: 10 }),
|
|
464
|
+
),
|
|
465
|
+
);
|
|
466
|
+
canvasModel.createEdge({ source: queueId.id, target: queue.id });
|
|
467
|
+
return { queue, queueId };
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
const attachTrigger = (functionTrigger: FunctionTrigger | undefined, computeModel: ComputeGraphModel) => {
|
|
471
|
+
invariant(functionTrigger);
|
|
472
|
+
functionTrigger.function = DXN.fromLocalObjectId(computeModel.root.id).toString();
|
|
473
|
+
functionTrigger.meta ??= {};
|
|
474
|
+
const inputNode = computeModel.nodes.find((node) => node.type === NODE_INPUT)!;
|
|
475
|
+
functionTrigger.meta.computeNodeId = inputNode.id;
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
type RawPositionInput = { centerX: number; centerY: number; width: number; height: number };
|
|
479
|
+
|
|
480
|
+
const rawPosition = (args: RawPositionInput) => {
|
|
481
|
+
return { center: { x: args.centerX, y: args.centerY }, size: { width: args.width, height: args.height } };
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
const position = (rect: { x: number; y: number; width?: number; height?: number }) => {
|
|
485
|
+
const snap = 32;
|
|
486
|
+
const [center, size] = rectToPoints({ width: 0, height: 0, ...rect });
|
|
487
|
+
const { x, y, width, height } = pointsToRect([pointMultiply(center, snap), pointMultiply(size, snap)]);
|
|
488
|
+
if (width && height) {
|
|
489
|
+
return { center: { x, y }, size: width && height ? { width, height } : undefined };
|
|
490
|
+
} else {
|
|
491
|
+
return { center: { x, y } };
|
|
492
|
+
}
|
|
493
|
+
};
|
package/src/meta.ts
CHANGED
|
@@ -9,8 +9,10 @@ export const DEBUG_PLUGIN = 'dxos.org/plugin/debug';
|
|
|
9
9
|
export const meta = {
|
|
10
10
|
id: DEBUG_PLUGIN,
|
|
11
11
|
name: 'Debug',
|
|
12
|
-
description:
|
|
12
|
+
description:
|
|
13
|
+
'The debug plugin is useful for troubleshooting inside of Composer. You can also use the Debug plugin to create test data inside of sheets or tables or explore pre-built automations. Non-technical users will likely not spend much time here, but this plugin is invaluable for developers and technical users.',
|
|
13
14
|
icon: 'ph--bug--regular',
|
|
14
15
|
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-debug',
|
|
15
16
|
tags: ['experimental'],
|
|
17
|
+
screenshots: ['https://dxos.network/plugin-details-debug-dark.png'],
|
|
16
18
|
} satisfies PluginMeta;
|