@dxos/plugin-debug 0.8.3 → 0.8.4-main.f9ba587
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/{DebugApp-WSEJPCKY.mjs → DebugApp-5JPOASYB.mjs} +6 -6
- package/dist/lib/browser/{DevtoolsOverviewContainer-IIIWO77Q.mjs → DevtoolsOverviewContainer-EPD6EWT5.mjs} +2 -2
- package/dist/lib/browser/{SpaceGenerator-VB6IB2LL.mjs → SpaceGenerator-BLFPBKL2.mjs} +9 -9
- package/dist/lib/browser/{app-graph-builder-6HHJMKVU.mjs → app-graph-builder-SQXFD2BL.mjs} +4 -4
- package/dist/lib/browser/{chunk-47JOZTT2.mjs → chunk-5XPIRNQS.mjs} +2 -2
- package/dist/lib/browser/{chunk-KS3YBEL7.mjs → chunk-AJA6RYN3.mjs} +2 -2
- package/dist/lib/browser/index.mjs +12 -12
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-context-ZQRD2WG2.mjs → react-context-NVAGLAJD.mjs} +3 -3
- package/dist/lib/browser/{react-surface-UI6OK73H.mjs → react-surface-EWOX4JS7.mjs} +18 -18
- package/dist/lib/browser/react-surface-EWOX4JS7.mjs.map +7 -0
- package/dist/lib/browser/{settings-SXQWSIM4.mjs → settings-LSSWLM5I.mjs} +4 -4
- package/dist/lib/node-esm/DebugApp-B2TUPIX6.mjs +227 -0
- package/dist/lib/node-esm/DebugApp-B2TUPIX6.mjs.map +7 -0
- package/dist/lib/node-esm/DevtoolsOverviewContainer-K622ZTH2.mjs +27 -0
- package/dist/lib/node-esm/DevtoolsOverviewContainer-K622ZTH2.mjs.map +7 -0
- package/dist/lib/node-esm/SpaceGenerator-MJR725EE.mjs +1240 -0
- package/dist/lib/node-esm/SpaceGenerator-MJR725EE.mjs.map +7 -0
- package/dist/lib/node-esm/app-graph-builder-W26WQYCF.mjs +598 -0
- package/dist/lib/node-esm/app-graph-builder-W26WQYCF.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HTJ6Z5U5.mjs +20 -0
- package/dist/lib/node-esm/chunk-HTJ6Z5U5.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-I6XSKQ6D.mjs +70 -0
- package/dist/lib/node-esm/chunk-I6XSKQ6D.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +131 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/lib/node-esm/react-context-6ELMAMVB.mjs +17 -0
- package/dist/lib/node-esm/react-context-6ELMAMVB.mjs.map +7 -0
- package/dist/lib/node-esm/react-surface-HDU56SYC.mjs +769 -0
- package/dist/lib/node-esm/react-surface-HDU56SYC.mjs.map +7 -0
- package/dist/lib/node-esm/settings-YWFF57TW.mjs +23 -0
- package/dist/lib/node-esm/settings-YWFF57TW.mjs.map +7 -0
- package/dist/types/src/components/SpaceGenerator/SpaceGenerator.stories.d.ts +1 -1
- package/dist/types/src/components/SpaceGenerator/SpaceGenerator.stories.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +60 -60
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +56 -56
- package/src/DebugPlugin.tsx +1 -1
- package/src/capabilities/react-surface.tsx +2 -2
- package/src/components/SpaceGenerator/SpaceGenerator.stories.tsx +1 -1
- package/src/translations.ts +6 -4
- package/dist/lib/browser/react-surface-UI6OK73H.mjs.map +0 -7
- /package/dist/lib/browser/{DebugApp-WSEJPCKY.mjs.map → DebugApp-5JPOASYB.mjs.map} +0 -0
- /package/dist/lib/browser/{DevtoolsOverviewContainer-IIIWO77Q.mjs.map → DevtoolsOverviewContainer-EPD6EWT5.mjs.map} +0 -0
- /package/dist/lib/browser/{SpaceGenerator-VB6IB2LL.mjs.map → SpaceGenerator-BLFPBKL2.mjs.map} +0 -0
- /package/dist/lib/browser/{app-graph-builder-6HHJMKVU.mjs.map → app-graph-builder-SQXFD2BL.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-47JOZTT2.mjs.map → chunk-5XPIRNQS.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-KS3YBEL7.mjs.map → chunk-AJA6RYN3.mjs.map} +0 -0
- /package/dist/lib/browser/{react-context-ZQRD2WG2.mjs.map → react-context-NVAGLAJD.mjs.map} +0 -0
- /package/dist/lib/browser/{settings-SXQWSIM4.mjs.map → settings-LSSWLM5I.mjs.map} +0 -0
|
@@ -0,0 +1,1240 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// src/components/SpaceGenerator/SpaceGenerator.tsx
|
|
4
|
+
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
|
5
|
+
import React2, { useCallback, useMemo, useState } from "react";
|
|
6
|
+
import { createIntent, useIntentDispatcher } from "@dxos/app-framework";
|
|
7
|
+
import { ComputeGraph as ComputeGraph2 } from "@dxos/conductor";
|
|
8
|
+
import { Filter as Filter3, Obj as Obj3, Type as Type2 } from "@dxos/echo";
|
|
9
|
+
import { log } from "@dxos/log";
|
|
10
|
+
import { DocumentType as DocumentType2 } from "@dxos/plugin-markdown/types";
|
|
11
|
+
import { SheetType as SheetType2 } from "@dxos/plugin-sheet/types";
|
|
12
|
+
import { DiagramType as DiagramType2 } from "@dxos/plugin-sketch/types";
|
|
13
|
+
import { SpaceAction } from "@dxos/plugin-space/types";
|
|
14
|
+
import { useClient } from "@dxos/react-client";
|
|
15
|
+
import { getTypename } from "@dxos/react-client/echo";
|
|
16
|
+
import { IconButton as IconButton2, Input, Toolbar, useAsyncEffect } from "@dxos/react-ui";
|
|
17
|
+
import { SyntaxHighlighter } from "@dxos/react-ui-syntax-highlighter";
|
|
18
|
+
import { initializeTable, TableType as TableType3 } from "@dxos/react-ui-table";
|
|
19
|
+
import { DataType as DataType2 } from "@dxos/schema";
|
|
20
|
+
import { jsonKeyReplacer, sortKeys } from "@dxos/util";
|
|
21
|
+
|
|
22
|
+
// src/components/SpaceGenerator/ObjectGenerator.tsx
|
|
23
|
+
import { addressToA1Notation } from "@dxos/compute";
|
|
24
|
+
import { ComputeGraph, ComputeGraphModel, DEFAULT_OUTPUT, NODE_INPUT, NODE_OUTPUT } from "@dxos/conductor";
|
|
25
|
+
import { DXN, Filter, Key, Obj, Ref } from "@dxos/echo";
|
|
26
|
+
import { DocumentType } from "@dxos/plugin-markdown/types";
|
|
27
|
+
import { createSheet } from "@dxos/plugin-sheet/types";
|
|
28
|
+
import { SheetType } from "@dxos/plugin-sheet/types";
|
|
29
|
+
import { CanvasType, DiagramType } from "@dxos/plugin-sketch/types";
|
|
30
|
+
import { faker } from "@dxos/random";
|
|
31
|
+
import { TableType } from "@dxos/react-ui-table";
|
|
32
|
+
import { createView, DataType } from "@dxos/schema";
|
|
33
|
+
import { createAsyncGenerator } from "@dxos/schema/testing";
|
|
34
|
+
import { range } from "@dxos/util";
|
|
35
|
+
var generator = faker;
|
|
36
|
+
var createGenerator = (type) => {
|
|
37
|
+
return async (space, n, cb) => {
|
|
38
|
+
const schema = await space.db.schemaRegistry.query({
|
|
39
|
+
typename: type.typename
|
|
40
|
+
}).firstOrUndefined() ?? (await space.db.schemaRegistry.register([
|
|
41
|
+
type
|
|
42
|
+
]))[0];
|
|
43
|
+
const generate = createAsyncGenerator(generator, schema.snapshot, {
|
|
44
|
+
db: space.db
|
|
45
|
+
});
|
|
46
|
+
const objects = await generate.createObjects(n);
|
|
47
|
+
const { objects: tables } = await space.db.query(Filter.type(TableType)).run();
|
|
48
|
+
const table = tables.find((table2) => table2.view?.target?.query?.typename === type.typename);
|
|
49
|
+
if (!table) {
|
|
50
|
+
const name = type.typename.split("/").pop() ?? type.typename;
|
|
51
|
+
const view = createView({
|
|
52
|
+
name,
|
|
53
|
+
typename: type.typename,
|
|
54
|
+
jsonSchema: schema.jsonSchema
|
|
55
|
+
});
|
|
56
|
+
space.db.add(Obj.make(TableType, {
|
|
57
|
+
name,
|
|
58
|
+
view: Ref.make(view)
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
return objects;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
var staticGenerators = /* @__PURE__ */ new Map([
|
|
65
|
+
[
|
|
66
|
+
DocumentType.typename,
|
|
67
|
+
async (space, n, cb) => {
|
|
68
|
+
const objects = range(n).map(() => {
|
|
69
|
+
return space.db.add(Obj.make(DocumentType, {
|
|
70
|
+
name: faker.commerce.productName(),
|
|
71
|
+
content: Ref.make(Obj.make(DataType.Text, {
|
|
72
|
+
content: faker.lorem.sentences(5)
|
|
73
|
+
}))
|
|
74
|
+
}));
|
|
75
|
+
});
|
|
76
|
+
cb?.(objects);
|
|
77
|
+
return objects;
|
|
78
|
+
}
|
|
79
|
+
],
|
|
80
|
+
[
|
|
81
|
+
DiagramType.typename,
|
|
82
|
+
async (space, n, cb) => {
|
|
83
|
+
const objects = range(n).map(() => {
|
|
84
|
+
const obj = space.db.add(Obj.make(DiagramType, {
|
|
85
|
+
name: faker.commerce.productName(),
|
|
86
|
+
canvas: Ref.make(Obj.make(CanvasType, {
|
|
87
|
+
content: {}
|
|
88
|
+
}))
|
|
89
|
+
}));
|
|
90
|
+
return obj;
|
|
91
|
+
});
|
|
92
|
+
cb?.(objects);
|
|
93
|
+
return objects;
|
|
94
|
+
}
|
|
95
|
+
],
|
|
96
|
+
// TODO(burdon): Create unit tests.
|
|
97
|
+
[
|
|
98
|
+
SheetType.typename,
|
|
99
|
+
async (space, n, cb) => {
|
|
100
|
+
const objects = range(n).map(() => {
|
|
101
|
+
const cells = {};
|
|
102
|
+
const year = (/* @__PURE__ */ new Date()).getFullYear();
|
|
103
|
+
const cols = 4;
|
|
104
|
+
const rows = 16;
|
|
105
|
+
for (let col = 1; col <= cols; col++) {
|
|
106
|
+
for (let row = 1; row <= rows; row++) {
|
|
107
|
+
const cell = addressToA1Notation({
|
|
108
|
+
col,
|
|
109
|
+
row
|
|
110
|
+
});
|
|
111
|
+
if (row === 1) {
|
|
112
|
+
cells[cell] = {
|
|
113
|
+
value: `${year} Q${col}`
|
|
114
|
+
};
|
|
115
|
+
} else if (row === rows) {
|
|
116
|
+
const from = addressToA1Notation({
|
|
117
|
+
col,
|
|
118
|
+
row: 2
|
|
119
|
+
});
|
|
120
|
+
const to = addressToA1Notation({
|
|
121
|
+
col,
|
|
122
|
+
row: rows - 1
|
|
123
|
+
});
|
|
124
|
+
cells[cell] = {
|
|
125
|
+
value: `=SUM(${from}:${to})`
|
|
126
|
+
};
|
|
127
|
+
} else if (row > 2 && row < rows - 1) {
|
|
128
|
+
cells[cell] = {
|
|
129
|
+
value: Math.floor(Math.random() * 1e4)
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return space.db.add(createSheet({
|
|
135
|
+
name: faker.commerce.productName(),
|
|
136
|
+
cells
|
|
137
|
+
}));
|
|
138
|
+
});
|
|
139
|
+
cb?.(objects);
|
|
140
|
+
return objects;
|
|
141
|
+
}
|
|
142
|
+
],
|
|
143
|
+
[
|
|
144
|
+
ComputeGraph.typename,
|
|
145
|
+
async (space, n, cb) => {
|
|
146
|
+
const objects = range(n, () => {
|
|
147
|
+
const model = ComputeGraphModel.create();
|
|
148
|
+
model.builder.createNode({
|
|
149
|
+
id: "gpt-INPUT",
|
|
150
|
+
type: NODE_INPUT
|
|
151
|
+
}).createNode({
|
|
152
|
+
id: "gpt-GPT",
|
|
153
|
+
type: "gpt"
|
|
154
|
+
}).createNode({
|
|
155
|
+
id: "gpt-QUEUE_ID",
|
|
156
|
+
type: "constant",
|
|
157
|
+
value: new DXN(DXN.kind.QUEUE, [
|
|
158
|
+
"data",
|
|
159
|
+
space.id,
|
|
160
|
+
Key.ObjectId.random()
|
|
161
|
+
]).toString()
|
|
162
|
+
}).createNode({
|
|
163
|
+
id: "gpt-APPEND",
|
|
164
|
+
type: "append"
|
|
165
|
+
}).createNode({
|
|
166
|
+
id: "gpt-OUTPUT",
|
|
167
|
+
type: NODE_OUTPUT
|
|
168
|
+
}).createEdge({
|
|
169
|
+
node: "gpt-INPUT",
|
|
170
|
+
property: "prompt"
|
|
171
|
+
}, {
|
|
172
|
+
node: "gpt-GPT",
|
|
173
|
+
property: "prompt"
|
|
174
|
+
}).createEdge({
|
|
175
|
+
node: "gpt-GPT",
|
|
176
|
+
property: "text"
|
|
177
|
+
}, {
|
|
178
|
+
node: "gpt-OUTPUT",
|
|
179
|
+
property: "text"
|
|
180
|
+
}).createEdge({
|
|
181
|
+
node: "gpt-QUEUE_ID",
|
|
182
|
+
property: DEFAULT_OUTPUT
|
|
183
|
+
}, {
|
|
184
|
+
node: "gpt-APPEND",
|
|
185
|
+
property: "id"
|
|
186
|
+
}).createEdge({
|
|
187
|
+
node: "gpt-GPT",
|
|
188
|
+
property: "messages"
|
|
189
|
+
}, {
|
|
190
|
+
node: "gpt-APPEND",
|
|
191
|
+
property: "items"
|
|
192
|
+
}).createEdge({
|
|
193
|
+
node: "gpt-QUEUE_ID",
|
|
194
|
+
property: DEFAULT_OUTPUT
|
|
195
|
+
}, {
|
|
196
|
+
node: "gpt-OUTPUT",
|
|
197
|
+
property: "queue"
|
|
198
|
+
});
|
|
199
|
+
return space.db.add(model.root);
|
|
200
|
+
});
|
|
201
|
+
cb?.(objects);
|
|
202
|
+
return objects;
|
|
203
|
+
}
|
|
204
|
+
]
|
|
205
|
+
]);
|
|
206
|
+
|
|
207
|
+
// src/components/SpaceGenerator/SchemaTable.tsx
|
|
208
|
+
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
209
|
+
import React from "react";
|
|
210
|
+
import { IconButton } from "@dxos/react-ui";
|
|
211
|
+
var SchemaTable = ({ types, objects = {}, label, onClick }) => {
|
|
212
|
+
var _effect = _useSignals();
|
|
213
|
+
try {
|
|
214
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
215
|
+
className: "grid grid-cols-[1fr_80px_40px] gap-1 overflow-none"
|
|
216
|
+
}, /* @__PURE__ */ React.createElement("h2", {
|
|
217
|
+
className: "p-2"
|
|
218
|
+
}, label), types.map((type) => /* @__PURE__ */ React.createElement("div", {
|
|
219
|
+
key: type.typename,
|
|
220
|
+
className: "grid grid-cols-subgrid col-span-3 items-center"
|
|
221
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
222
|
+
className: "px-2 text-sm font-mono text-subdued"
|
|
223
|
+
}, type.typename), /* @__PURE__ */ React.createElement("div", {
|
|
224
|
+
className: "px-2 text-right font-mono"
|
|
225
|
+
}, objects[type.typename] ?? 0), /* @__PURE__ */ React.createElement(IconButton, {
|
|
226
|
+
variant: "ghost",
|
|
227
|
+
icon: "ph--plus--regular",
|
|
228
|
+
iconOnly: true,
|
|
229
|
+
label: "Create data",
|
|
230
|
+
onClick: () => onClick(type.typename)
|
|
231
|
+
}))));
|
|
232
|
+
} finally {
|
|
233
|
+
_effect.f();
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
// src/components/SpaceGenerator/presets.ts
|
|
238
|
+
import { Schema, SchemaAST } from "effect";
|
|
239
|
+
import { NODE_INPUT as NODE_INPUT2 } from "@dxos/conductor";
|
|
240
|
+
import { DXN as DXN2, Key as Key2, Obj as Obj2, Ref as Ref2, Type } from "@dxos/echo";
|
|
241
|
+
import { FunctionTrigger, TriggerKind, EmailTriggerOutput } from "@dxos/functions";
|
|
242
|
+
import { invariant } from "@dxos/invariant";
|
|
243
|
+
import { Filter as Filter2 } from "@dxos/react-client/echo";
|
|
244
|
+
import { createAppend, createChat, createComputeGraph, createConstant, createFunction, createGpt, createQueue, createSurface, createRandom, createTemplate, createText, createTrigger } from "@dxos/react-ui-canvas-compute";
|
|
245
|
+
import { CanvasBoardType, CanvasGraphModel, pointMultiply, pointsToRect, rectToPoints } from "@dxos/react-ui-canvas-editor";
|
|
246
|
+
import { TableType as TableType2 } from "@dxos/react-ui-table";
|
|
247
|
+
import { range as range2 } from "@dxos/util";
|
|
248
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-debug/src/components/SpaceGenerator/presets.ts";
|
|
249
|
+
var PresetName = /* @__PURE__ */ function(PresetName2) {
|
|
250
|
+
PresetName2["EMAIL_TABLE"] = "email-table";
|
|
251
|
+
PresetName2["GPT_QUEUE"] = "webhook-gpt-queue";
|
|
252
|
+
PresetName2["CHAT_GPT"] = "chat-gpt-text";
|
|
253
|
+
PresetName2["EMAIL_WITH_SUMMARY"] = "email-gptSummary-table";
|
|
254
|
+
PresetName2["OBJECT_CHANGE_QUEUE"] = "objectChange-queue";
|
|
255
|
+
PresetName2["FOREX_FUNCTION_CALL"] = "forex-function-call";
|
|
256
|
+
PresetName2["TIMER_TICK_QUEUE"] = "timerTick-queue";
|
|
257
|
+
PresetName2["DISCORD_MESSAGES"] = "discord-messages";
|
|
258
|
+
PresetName2["KANBAN_QUEUE"] = "kanban-queue";
|
|
259
|
+
return PresetName2;
|
|
260
|
+
}({});
|
|
261
|
+
var generator2 = () => ({
|
|
262
|
+
schemas: [
|
|
263
|
+
CanvasBoardType,
|
|
264
|
+
FunctionTrigger
|
|
265
|
+
],
|
|
266
|
+
types: Object.values(PresetName).map((name) => ({
|
|
267
|
+
typename: name
|
|
268
|
+
})),
|
|
269
|
+
items: [
|
|
270
|
+
[
|
|
271
|
+
"webhook-gpt-queue",
|
|
272
|
+
async (space, n, cb) => {
|
|
273
|
+
const objects = range2(n, () => {
|
|
274
|
+
const canvasModel = CanvasGraphModel.create();
|
|
275
|
+
let functionTrigger;
|
|
276
|
+
canvasModel.builder.call((builder) => {
|
|
277
|
+
const gpt = canvasModel.createNode(createGpt(position({
|
|
278
|
+
x: 0,
|
|
279
|
+
y: -14
|
|
280
|
+
})));
|
|
281
|
+
const triggerShape = createTrigger({
|
|
282
|
+
spaceId: space.id,
|
|
283
|
+
triggerKind: TriggerKind.Webhook,
|
|
284
|
+
...position({
|
|
285
|
+
x: -18,
|
|
286
|
+
y: -2
|
|
287
|
+
})
|
|
288
|
+
});
|
|
289
|
+
const trigger = canvasModel.createNode(triggerShape);
|
|
290
|
+
const text = canvasModel.createNode(createText(position({
|
|
291
|
+
x: 19,
|
|
292
|
+
y: 3,
|
|
293
|
+
width: 10,
|
|
294
|
+
height: 10
|
|
295
|
+
})));
|
|
296
|
+
const { queueId } = setupQueue(space, canvasModel);
|
|
297
|
+
const append = canvasModel.createNode(createAppend(position({
|
|
298
|
+
x: 10,
|
|
299
|
+
y: 6
|
|
300
|
+
})));
|
|
301
|
+
builder.createEdge({
|
|
302
|
+
source: trigger.id,
|
|
303
|
+
target: gpt.id,
|
|
304
|
+
input: "prompt",
|
|
305
|
+
output: "bodyText"
|
|
306
|
+
}).createEdge({
|
|
307
|
+
source: gpt.id,
|
|
308
|
+
target: text.id,
|
|
309
|
+
output: "text"
|
|
310
|
+
}).createEdge({
|
|
311
|
+
source: queueId.id,
|
|
312
|
+
target: append.id,
|
|
313
|
+
input: "id"
|
|
314
|
+
}).createEdge({
|
|
315
|
+
source: gpt.id,
|
|
316
|
+
target: append.id,
|
|
317
|
+
output: "messages",
|
|
318
|
+
input: "items"
|
|
319
|
+
});
|
|
320
|
+
functionTrigger = triggerShape.functionTrigger.target;
|
|
321
|
+
});
|
|
322
|
+
const computeModel = createComputeGraph(canvasModel);
|
|
323
|
+
attachTrigger(functionTrigger, computeModel);
|
|
324
|
+
return addToSpace("webhook-gpt-queue", space, canvasModel, computeModel);
|
|
325
|
+
});
|
|
326
|
+
cb?.(objects);
|
|
327
|
+
return objects;
|
|
328
|
+
}
|
|
329
|
+
],
|
|
330
|
+
[
|
|
331
|
+
"objectChange-queue",
|
|
332
|
+
async (space, n, cb) => {
|
|
333
|
+
const objects = range2(n, () => {
|
|
334
|
+
const { canvasModel, computeModel } = createQueueSinkPreset(space, TriggerKind.Subscription, (triggerSpec) => triggerSpec.filter = {
|
|
335
|
+
type: "dxn:type:dxos.org/type/Chess"
|
|
336
|
+
}, "type");
|
|
337
|
+
return addToSpace("objectChange-queue", space, canvasModel, computeModel);
|
|
338
|
+
});
|
|
339
|
+
cb?.(objects);
|
|
340
|
+
return objects;
|
|
341
|
+
}
|
|
342
|
+
],
|
|
343
|
+
[
|
|
344
|
+
"timerTick-queue",
|
|
345
|
+
async (space, n, cb) => {
|
|
346
|
+
const objects = range2(n, () => {
|
|
347
|
+
const { canvasModel, computeModel } = createQueueSinkPreset(space, TriggerKind.Timer, (triggerSpec) => triggerSpec.cron = "*/5 * * * * *", "result");
|
|
348
|
+
return addToSpace("timerTick-queue", space, canvasModel, computeModel);
|
|
349
|
+
});
|
|
350
|
+
cb?.(objects);
|
|
351
|
+
return objects;
|
|
352
|
+
}
|
|
353
|
+
],
|
|
354
|
+
[
|
|
355
|
+
"email-table",
|
|
356
|
+
async (space, n, cb) => {
|
|
357
|
+
const objects = range2(n, () => {
|
|
358
|
+
const canvasModel = CanvasGraphModel.create();
|
|
359
|
+
const results = space.db.query(Filter2.type(TableType2)).runSync();
|
|
360
|
+
const emailTable = results.find((r) => r.object?.view?.target?.query?.typename?.endsWith("Email"));
|
|
361
|
+
invariant(emailTable, "Email table not found.", {
|
|
362
|
+
F: __dxlog_file,
|
|
363
|
+
L: 136,
|
|
364
|
+
S: void 0,
|
|
365
|
+
A: [
|
|
366
|
+
"emailTable",
|
|
367
|
+
"'Email table not found.'"
|
|
368
|
+
]
|
|
369
|
+
});
|
|
370
|
+
const template = canvasModel.createNode(createTemplate({
|
|
371
|
+
valueType: "object",
|
|
372
|
+
...rawPosition({
|
|
373
|
+
centerX: -80,
|
|
374
|
+
centerY: -64,
|
|
375
|
+
width: 320,
|
|
376
|
+
height: 320
|
|
377
|
+
})
|
|
378
|
+
}));
|
|
379
|
+
const templateContent = [
|
|
380
|
+
"{"
|
|
381
|
+
];
|
|
382
|
+
let functionTrigger;
|
|
383
|
+
canvasModel.builder.call((builder) => {
|
|
384
|
+
const triggerShape = createTrigger({
|
|
385
|
+
spaceId: space.id,
|
|
386
|
+
triggerKind: TriggerKind.Email,
|
|
387
|
+
...position({
|
|
388
|
+
x: -18,
|
|
389
|
+
y: -2
|
|
390
|
+
})
|
|
391
|
+
});
|
|
392
|
+
const trigger = canvasModel.createNode(triggerShape);
|
|
393
|
+
const tableId = canvasModel.createNode(createConstant({
|
|
394
|
+
value: DXN2.fromLocalObjectId(emailTable.id).toString(),
|
|
395
|
+
...position({
|
|
396
|
+
x: -18,
|
|
397
|
+
y: 5,
|
|
398
|
+
width: 8,
|
|
399
|
+
height: 6
|
|
400
|
+
})
|
|
401
|
+
}));
|
|
402
|
+
const appendToTable = canvasModel.createNode(createAppend(position({
|
|
403
|
+
x: 10,
|
|
404
|
+
y: 6
|
|
405
|
+
})));
|
|
406
|
+
const properties = SchemaAST.getPropertySignatures(EmailTriggerOutput.ast);
|
|
407
|
+
for (let i = 0; i < properties.length; i++) {
|
|
408
|
+
const propName = properties[i].name.toString();
|
|
409
|
+
builder.createEdge({
|
|
410
|
+
source: trigger.id,
|
|
411
|
+
target: template.id,
|
|
412
|
+
input: propName,
|
|
413
|
+
output: propName
|
|
414
|
+
});
|
|
415
|
+
templateContent.push(` "${propName}": "{{${propName}}}"` + (i === properties.length - 1 ? "" : ","));
|
|
416
|
+
}
|
|
417
|
+
templateContent.push("}");
|
|
418
|
+
builder.createEdge({
|
|
419
|
+
source: tableId.id,
|
|
420
|
+
target: appendToTable.id,
|
|
421
|
+
input: "id"
|
|
422
|
+
}).createEdge({
|
|
423
|
+
source: template.id,
|
|
424
|
+
target: appendToTable.id,
|
|
425
|
+
input: "items"
|
|
426
|
+
});
|
|
427
|
+
functionTrigger = triggerShape.functionTrigger.target;
|
|
428
|
+
});
|
|
429
|
+
const computeModel = createComputeGraph(canvasModel);
|
|
430
|
+
const templateComputeNode = computeModel.nodes.find((n2) => n2.id === template.node);
|
|
431
|
+
invariant(templateComputeNode, "Template compute node was not created.", {
|
|
432
|
+
F: __dxlog_file,
|
|
433
|
+
L: 182,
|
|
434
|
+
S: void 0,
|
|
435
|
+
A: [
|
|
436
|
+
"templateComputeNode",
|
|
437
|
+
"'Template compute node was not created.'"
|
|
438
|
+
]
|
|
439
|
+
});
|
|
440
|
+
templateComputeNode.value = templateContent.join("\n");
|
|
441
|
+
templateComputeNode.inputSchema = Type.toJsonSchema(EmailTriggerOutput);
|
|
442
|
+
attachTrigger(functionTrigger, computeModel);
|
|
443
|
+
return addToSpace("email-table", space, canvasModel, computeModel);
|
|
444
|
+
});
|
|
445
|
+
cb?.(objects);
|
|
446
|
+
return objects;
|
|
447
|
+
}
|
|
448
|
+
],
|
|
449
|
+
[
|
|
450
|
+
"chat-gpt-text",
|
|
451
|
+
async (space, n, cb) => {
|
|
452
|
+
const objects = range2(n, () => {
|
|
453
|
+
const canvasModel = CanvasGraphModel.create();
|
|
454
|
+
canvasModel.builder.call((builder) => {
|
|
455
|
+
const gpt = canvasModel.createNode(createGpt(position({
|
|
456
|
+
x: 0,
|
|
457
|
+
y: -14
|
|
458
|
+
})));
|
|
459
|
+
const chat = canvasModel.createNode(createChat(position({
|
|
460
|
+
x: -18,
|
|
461
|
+
y: -2
|
|
462
|
+
})));
|
|
463
|
+
const text = canvasModel.createNode(createText(position({
|
|
464
|
+
x: 19,
|
|
465
|
+
y: 3,
|
|
466
|
+
width: 10,
|
|
467
|
+
height: 10
|
|
468
|
+
})));
|
|
469
|
+
const { queueId } = setupQueue(space, canvasModel);
|
|
470
|
+
const append = canvasModel.createNode(createAppend(position({
|
|
471
|
+
x: 10,
|
|
472
|
+
y: 6
|
|
473
|
+
})));
|
|
474
|
+
builder.createEdge({
|
|
475
|
+
source: chat.id,
|
|
476
|
+
target: gpt.id,
|
|
477
|
+
input: "prompt"
|
|
478
|
+
}).createEdge({
|
|
479
|
+
source: gpt.id,
|
|
480
|
+
target: text.id,
|
|
481
|
+
output: "text"
|
|
482
|
+
}).createEdge({
|
|
483
|
+
source: queueId.id,
|
|
484
|
+
target: append.id,
|
|
485
|
+
input: "id"
|
|
486
|
+
}).createEdge({
|
|
487
|
+
source: gpt.id,
|
|
488
|
+
target: append.id,
|
|
489
|
+
output: "messages",
|
|
490
|
+
input: "items"
|
|
491
|
+
});
|
|
492
|
+
});
|
|
493
|
+
const computeModel = createComputeGraph(canvasModel);
|
|
494
|
+
return addToSpace("chat-gpt-text", space, canvasModel, computeModel);
|
|
495
|
+
});
|
|
496
|
+
cb?.(objects);
|
|
497
|
+
return objects;
|
|
498
|
+
}
|
|
499
|
+
],
|
|
500
|
+
[
|
|
501
|
+
"email-gptSummary-table",
|
|
502
|
+
async (space, n, cb) => {
|
|
503
|
+
const objects = range2(n, () => {
|
|
504
|
+
const canvasModel = CanvasGraphModel.create();
|
|
505
|
+
const results = space.db.query(Filter2.type(TableType2)).runSync();
|
|
506
|
+
const emailTable = results.find((r) => r.object?.view?.target?.query?.typename?.endsWith("Email"));
|
|
507
|
+
invariant(emailTable, "Email table not found.", {
|
|
508
|
+
F: __dxlog_file,
|
|
509
|
+
L: 233,
|
|
510
|
+
S: void 0,
|
|
511
|
+
A: [
|
|
512
|
+
"emailTable",
|
|
513
|
+
"'Email table not found.'"
|
|
514
|
+
]
|
|
515
|
+
});
|
|
516
|
+
const template = canvasModel.createNode(createTemplate({
|
|
517
|
+
valueType: "object",
|
|
518
|
+
...rawPosition({
|
|
519
|
+
centerX: 192,
|
|
520
|
+
centerY: -176,
|
|
521
|
+
width: 320,
|
|
522
|
+
height: 320
|
|
523
|
+
})
|
|
524
|
+
}));
|
|
525
|
+
const templateContent = [
|
|
526
|
+
"{"
|
|
527
|
+
];
|
|
528
|
+
let functionTrigger;
|
|
529
|
+
canvasModel.builder.call((builder) => {
|
|
530
|
+
const gpt = canvasModel.createNode(createGpt(rawPosition({
|
|
531
|
+
centerX: -400,
|
|
532
|
+
centerY: -112,
|
|
533
|
+
width: 256,
|
|
534
|
+
height: 202
|
|
535
|
+
})));
|
|
536
|
+
const systemPrompt = canvasModel.createNode(createConstant({
|
|
537
|
+
value: "use one word to describe content category. don't write anything else",
|
|
538
|
+
...rawPosition({
|
|
539
|
+
centerX: -800,
|
|
540
|
+
centerY: -160,
|
|
541
|
+
width: 192,
|
|
542
|
+
height: 128
|
|
543
|
+
})
|
|
544
|
+
}));
|
|
545
|
+
const triggerShape = createTrigger({
|
|
546
|
+
spaceId: space.id,
|
|
547
|
+
triggerKind: TriggerKind.Email,
|
|
548
|
+
...rawPosition({
|
|
549
|
+
centerX: -736,
|
|
550
|
+
centerY: -384,
|
|
551
|
+
width: 182,
|
|
552
|
+
height: 192
|
|
553
|
+
})
|
|
554
|
+
});
|
|
555
|
+
const trigger = canvasModel.createNode(triggerShape);
|
|
556
|
+
const { queueId } = setupQueue(space, canvasModel, {
|
|
557
|
+
idPosition: {
|
|
558
|
+
centerX: -720,
|
|
559
|
+
centerY: 224,
|
|
560
|
+
width: 192,
|
|
561
|
+
height: 256
|
|
562
|
+
},
|
|
563
|
+
queuePosition: {
|
|
564
|
+
centerX: -144,
|
|
565
|
+
centerY: 416,
|
|
566
|
+
width: 320,
|
|
567
|
+
height: 448
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
const appendToQueue = canvasModel.createNode(createAppend(rawPosition({
|
|
571
|
+
centerX: -80,
|
|
572
|
+
centerY: 96,
|
|
573
|
+
width: 122,
|
|
574
|
+
height: 128
|
|
575
|
+
})));
|
|
576
|
+
const tableId = canvasModel.createNode(createConstant({
|
|
577
|
+
value: DXN2.fromLocalObjectId(emailTable.id).toString(),
|
|
578
|
+
...rawPosition({
|
|
579
|
+
centerX: -112,
|
|
580
|
+
centerY: -544,
|
|
581
|
+
width: 192,
|
|
582
|
+
height: 256
|
|
583
|
+
})
|
|
584
|
+
}));
|
|
585
|
+
const appendToTable = canvasModel.createNode(createAppend(rawPosition({
|
|
586
|
+
centerX: 560,
|
|
587
|
+
centerY: -416,
|
|
588
|
+
width: 128,
|
|
589
|
+
height: 122
|
|
590
|
+
})));
|
|
591
|
+
templateContent.push(' "category": "{{text}}",');
|
|
592
|
+
builder.createEdge({
|
|
593
|
+
source: gpt.id,
|
|
594
|
+
target: template.id,
|
|
595
|
+
input: "text",
|
|
596
|
+
output: "text"
|
|
597
|
+
});
|
|
598
|
+
const properties = SchemaAST.getPropertySignatures(EmailTriggerOutput.ast);
|
|
599
|
+
for (let i = 0; i < properties.length; i++) {
|
|
600
|
+
const propName = properties[i].name.toString();
|
|
601
|
+
builder.createEdge({
|
|
602
|
+
source: trigger.id,
|
|
603
|
+
target: template.id,
|
|
604
|
+
input: propName,
|
|
605
|
+
output: propName
|
|
606
|
+
});
|
|
607
|
+
templateContent.push(` "${propName}": "{{${propName}}}"` + (i === properties.length - 1 ? "" : ","));
|
|
608
|
+
}
|
|
609
|
+
templateContent.push("}");
|
|
610
|
+
builder.createEdge({
|
|
611
|
+
source: tableId.id,
|
|
612
|
+
target: appendToTable.id,
|
|
613
|
+
input: "id"
|
|
614
|
+
}).createEdge({
|
|
615
|
+
source: queueId.id,
|
|
616
|
+
target: appendToQueue.id,
|
|
617
|
+
input: "id"
|
|
618
|
+
}).createEdge({
|
|
619
|
+
source: gpt.id,
|
|
620
|
+
target: appendToQueue.id,
|
|
621
|
+
output: "messages",
|
|
622
|
+
input: "items"
|
|
623
|
+
}).createEdge({
|
|
624
|
+
source: systemPrompt.id,
|
|
625
|
+
target: gpt.id,
|
|
626
|
+
input: "systemPrompt"
|
|
627
|
+
}).createEdge({
|
|
628
|
+
source: trigger.id,
|
|
629
|
+
target: gpt.id,
|
|
630
|
+
input: "prompt",
|
|
631
|
+
output: "body"
|
|
632
|
+
}).createEdge({
|
|
633
|
+
source: template.id,
|
|
634
|
+
target: appendToTable.id,
|
|
635
|
+
input: "items"
|
|
636
|
+
});
|
|
637
|
+
functionTrigger = triggerShape.functionTrigger.target;
|
|
638
|
+
});
|
|
639
|
+
const computeModel = createComputeGraph(canvasModel);
|
|
640
|
+
const templateComputeNode = computeModel.nodes.find((n2) => n2.id === template.node);
|
|
641
|
+
invariant(templateComputeNode, "Template compute node was not created.", {
|
|
642
|
+
F: __dxlog_file,
|
|
643
|
+
L: 305,
|
|
644
|
+
S: void 0,
|
|
645
|
+
A: [
|
|
646
|
+
"templateComputeNode",
|
|
647
|
+
"'Template compute node was not created.'"
|
|
648
|
+
]
|
|
649
|
+
});
|
|
650
|
+
templateComputeNode.value = templateContent.join("\n");
|
|
651
|
+
const extendedSchema = Schema.extend(EmailTriggerOutput, Schema.Struct({
|
|
652
|
+
text: Schema.String
|
|
653
|
+
}));
|
|
654
|
+
templateComputeNode.inputSchema = Type.toJsonSchema(extendedSchema);
|
|
655
|
+
attachTrigger(functionTrigger, computeModel);
|
|
656
|
+
return addToSpace("email-gptSummary-table", space, canvasModel, computeModel);
|
|
657
|
+
});
|
|
658
|
+
cb?.(objects);
|
|
659
|
+
return objects;
|
|
660
|
+
}
|
|
661
|
+
],
|
|
662
|
+
[
|
|
663
|
+
"forex-function-call",
|
|
664
|
+
async (space, n, cb) => {
|
|
665
|
+
const objects = range2(n, () => {
|
|
666
|
+
const canvasModel = CanvasGraphModel.create();
|
|
667
|
+
canvasModel.builder.call((builder) => {
|
|
668
|
+
const sourceCurrency = canvasModel.createNode(createConstant({
|
|
669
|
+
value: "USD",
|
|
670
|
+
...position({
|
|
671
|
+
x: -10,
|
|
672
|
+
y: -5
|
|
673
|
+
})
|
|
674
|
+
}));
|
|
675
|
+
const targetCurrency = canvasModel.createNode(createConstant({
|
|
676
|
+
value: "EUR",
|
|
677
|
+
...position({
|
|
678
|
+
x: -10,
|
|
679
|
+
y: 5
|
|
680
|
+
})
|
|
681
|
+
}));
|
|
682
|
+
const converter = canvasModel.createNode(createFunction(position({
|
|
683
|
+
x: 0,
|
|
684
|
+
y: 0
|
|
685
|
+
})));
|
|
686
|
+
const view = canvasModel.createNode(createSurface(position({
|
|
687
|
+
x: 12,
|
|
688
|
+
y: 0
|
|
689
|
+
})));
|
|
690
|
+
builder.createEdge({
|
|
691
|
+
source: sourceCurrency.id,
|
|
692
|
+
target: converter.id,
|
|
693
|
+
input: "from"
|
|
694
|
+
}).createEdge({
|
|
695
|
+
source: targetCurrency.id,
|
|
696
|
+
target: converter.id,
|
|
697
|
+
input: "to"
|
|
698
|
+
}).createEdge({
|
|
699
|
+
source: converter.id,
|
|
700
|
+
target: view.id,
|
|
701
|
+
output: "rate"
|
|
702
|
+
});
|
|
703
|
+
});
|
|
704
|
+
const computeModel = createComputeGraph(canvasModel);
|
|
705
|
+
return addToSpace("forex-function-call", space, canvasModel, computeModel);
|
|
706
|
+
});
|
|
707
|
+
cb?.(objects);
|
|
708
|
+
return objects;
|
|
709
|
+
}
|
|
710
|
+
],
|
|
711
|
+
[
|
|
712
|
+
"discord-messages",
|
|
713
|
+
async (space, n, cb) => {
|
|
714
|
+
const objects = range2(n, () => {
|
|
715
|
+
const canvasModel = CanvasGraphModel.create();
|
|
716
|
+
let functionTrigger;
|
|
717
|
+
canvasModel.builder.call((builder) => {
|
|
718
|
+
const triggerShape = createTrigger({
|
|
719
|
+
spaceId: space.id,
|
|
720
|
+
triggerKind: TriggerKind.Timer,
|
|
721
|
+
...position({
|
|
722
|
+
x: -10,
|
|
723
|
+
y: -5
|
|
724
|
+
})
|
|
725
|
+
});
|
|
726
|
+
const trigger = canvasModel.createNode(triggerShape);
|
|
727
|
+
const channelId = canvasModel.createNode(createConstant({
|
|
728
|
+
value: "1088569858767212554",
|
|
729
|
+
...position({
|
|
730
|
+
x: -10,
|
|
731
|
+
y: 0
|
|
732
|
+
})
|
|
733
|
+
}));
|
|
734
|
+
const queueId = canvasModel.createNode(createConstant({
|
|
735
|
+
value: new DXN2(DXN2.kind.QUEUE, [
|
|
736
|
+
"data",
|
|
737
|
+
space.id,
|
|
738
|
+
Key2.ObjectId.random()
|
|
739
|
+
]).toString(),
|
|
740
|
+
...position({
|
|
741
|
+
x: -10,
|
|
742
|
+
y: 5
|
|
743
|
+
})
|
|
744
|
+
}));
|
|
745
|
+
const converter = canvasModel.createNode(createFunction(position({
|
|
746
|
+
x: 0,
|
|
747
|
+
y: 0
|
|
748
|
+
})));
|
|
749
|
+
const view = canvasModel.createNode(createText(position({
|
|
750
|
+
x: 12,
|
|
751
|
+
y: 0
|
|
752
|
+
})));
|
|
753
|
+
const queue = canvasModel.createNode(createQueue(position({
|
|
754
|
+
x: 0,
|
|
755
|
+
y: 12
|
|
756
|
+
})));
|
|
757
|
+
builder.createEdge({
|
|
758
|
+
source: trigger.id,
|
|
759
|
+
target: converter.id,
|
|
760
|
+
input: "tick"
|
|
761
|
+
}).createEdge({
|
|
762
|
+
source: channelId.id,
|
|
763
|
+
target: converter.id,
|
|
764
|
+
input: "channelId"
|
|
765
|
+
}).createEdge({
|
|
766
|
+
source: queueId.id,
|
|
767
|
+
target: converter.id,
|
|
768
|
+
input: "queueId"
|
|
769
|
+
}).createEdge({
|
|
770
|
+
source: converter.id,
|
|
771
|
+
target: view.id,
|
|
772
|
+
output: "newMessages"
|
|
773
|
+
}).createEdge({
|
|
774
|
+
source: queueId.id,
|
|
775
|
+
target: queue.id,
|
|
776
|
+
input: "input"
|
|
777
|
+
});
|
|
778
|
+
functionTrigger = triggerShape.functionTrigger.target;
|
|
779
|
+
});
|
|
780
|
+
const computeModel = createComputeGraph(canvasModel);
|
|
781
|
+
attachTrigger(functionTrigger, computeModel);
|
|
782
|
+
return addToSpace("discord-messages", space, canvasModel, computeModel);
|
|
783
|
+
});
|
|
784
|
+
cb?.(objects);
|
|
785
|
+
return objects;
|
|
786
|
+
}
|
|
787
|
+
],
|
|
788
|
+
[
|
|
789
|
+
"kanban-queue",
|
|
790
|
+
async (space, n, cb) => {
|
|
791
|
+
const objects = range2(n, () => {
|
|
792
|
+
const canvasModel = CanvasGraphModel.create();
|
|
793
|
+
const results = space.db.query(Filter2.type(TableType2)).runSync();
|
|
794
|
+
const messages = results.find((r) => r.object?.view?.target?.query?.typename?.endsWith("Message"));
|
|
795
|
+
invariant(messages, "Table not found.", {
|
|
796
|
+
F: __dxlog_file,
|
|
797
|
+
L: 411,
|
|
798
|
+
S: void 0,
|
|
799
|
+
A: [
|
|
800
|
+
"messages",
|
|
801
|
+
"'Table not found.'"
|
|
802
|
+
]
|
|
803
|
+
});
|
|
804
|
+
let functionTrigger;
|
|
805
|
+
canvasModel.builder.call((builder) => {
|
|
806
|
+
const triggerShape = createTrigger({
|
|
807
|
+
spaceId: space.id,
|
|
808
|
+
triggerKind: TriggerKind.Queue,
|
|
809
|
+
...position({
|
|
810
|
+
x: -10,
|
|
811
|
+
y: -5
|
|
812
|
+
})
|
|
813
|
+
});
|
|
814
|
+
const trigger = canvasModel.createNode(triggerShape);
|
|
815
|
+
const tableId = canvasModel.createNode(createConstant({
|
|
816
|
+
value: DXN2.fromLocalObjectId(messages.id).toString(),
|
|
817
|
+
...position({
|
|
818
|
+
x: -10,
|
|
819
|
+
y: 5
|
|
820
|
+
})
|
|
821
|
+
}));
|
|
822
|
+
const appendToTable = canvasModel.createNode(createAppend(position({
|
|
823
|
+
x: 10,
|
|
824
|
+
y: 0
|
|
825
|
+
})));
|
|
826
|
+
builder.createEdge({
|
|
827
|
+
source: tableId.id,
|
|
828
|
+
target: appendToTable.id,
|
|
829
|
+
input: "id"
|
|
830
|
+
}).createEdge({
|
|
831
|
+
source: trigger.id,
|
|
832
|
+
target: appendToTable.id,
|
|
833
|
+
input: "items",
|
|
834
|
+
output: "item"
|
|
835
|
+
});
|
|
836
|
+
functionTrigger = triggerShape.functionTrigger.target;
|
|
837
|
+
});
|
|
838
|
+
const computeModel = createComputeGraph(canvasModel);
|
|
839
|
+
attachTrigger(functionTrigger, computeModel);
|
|
840
|
+
return addToSpace("kanban-queue", space, canvasModel, computeModel);
|
|
841
|
+
});
|
|
842
|
+
cb?.(objects);
|
|
843
|
+
return objects;
|
|
844
|
+
}
|
|
845
|
+
]
|
|
846
|
+
]
|
|
847
|
+
});
|
|
848
|
+
var createQueueSinkPreset = (space, triggerKind, initSpec, triggerOutputName) => {
|
|
849
|
+
const canvasModel = CanvasGraphModel.create();
|
|
850
|
+
const template = canvasModel.createNode(createTemplate({
|
|
851
|
+
valueType: "object",
|
|
852
|
+
...rawPosition({
|
|
853
|
+
centerX: -64,
|
|
854
|
+
centerY: -79,
|
|
855
|
+
width: 320,
|
|
856
|
+
height: 320
|
|
857
|
+
})
|
|
858
|
+
}));
|
|
859
|
+
let functionTrigger;
|
|
860
|
+
canvasModel.builder.call((builder) => {
|
|
861
|
+
const triggerShape = createTrigger({
|
|
862
|
+
spaceId: space.id,
|
|
863
|
+
triggerKind,
|
|
864
|
+
...rawPosition({
|
|
865
|
+
centerX: -578,
|
|
866
|
+
centerY: -187,
|
|
867
|
+
height: 320,
|
|
868
|
+
width: 320
|
|
869
|
+
})
|
|
870
|
+
});
|
|
871
|
+
const trigger = canvasModel.createNode(triggerShape);
|
|
872
|
+
const { queueId } = setupQueue(space, canvasModel, {
|
|
873
|
+
queuePosition: {
|
|
874
|
+
centerX: -80,
|
|
875
|
+
centerY: 378,
|
|
876
|
+
width: 320,
|
|
877
|
+
height: 448
|
|
878
|
+
}
|
|
879
|
+
});
|
|
880
|
+
const append = canvasModel.createNode(createAppend(rawPosition({
|
|
881
|
+
centerX: 320,
|
|
882
|
+
centerY: 192,
|
|
883
|
+
width: 128,
|
|
884
|
+
height: 122
|
|
885
|
+
})));
|
|
886
|
+
const random = canvasModel.createNode(createRandom(rawPosition({
|
|
887
|
+
centerX: -509,
|
|
888
|
+
centerY: -30,
|
|
889
|
+
width: 64,
|
|
890
|
+
height: 64
|
|
891
|
+
})));
|
|
892
|
+
builder.createEdge({
|
|
893
|
+
source: queueId.id,
|
|
894
|
+
target: append.id,
|
|
895
|
+
input: "id"
|
|
896
|
+
}).createEdge({
|
|
897
|
+
source: template.id,
|
|
898
|
+
target: append.id,
|
|
899
|
+
input: "items"
|
|
900
|
+
}).createEdge({
|
|
901
|
+
source: trigger.id,
|
|
902
|
+
target: template.id,
|
|
903
|
+
output: triggerOutputName,
|
|
904
|
+
input: "type"
|
|
905
|
+
}).createEdge({
|
|
906
|
+
source: random.id,
|
|
907
|
+
target: template.id,
|
|
908
|
+
input: "changeId"
|
|
909
|
+
});
|
|
910
|
+
functionTrigger = triggerShape.functionTrigger.target;
|
|
911
|
+
const triggerSpec = functionTrigger.spec;
|
|
912
|
+
invariant(triggerSpec && triggerSpec.kind === triggerKind, "No trigger spec.", {
|
|
913
|
+
F: __dxlog_file,
|
|
914
|
+
L: 494,
|
|
915
|
+
S: void 0,
|
|
916
|
+
A: [
|
|
917
|
+
"triggerSpec && triggerSpec.kind === triggerKind",
|
|
918
|
+
"'No trigger spec.'"
|
|
919
|
+
]
|
|
920
|
+
});
|
|
921
|
+
initSpec(triggerSpec);
|
|
922
|
+
});
|
|
923
|
+
const computeModel = createComputeGraph(canvasModel);
|
|
924
|
+
const templateComputeNode = computeModel.nodes.find((n) => n.id === template.node);
|
|
925
|
+
invariant(templateComputeNode, "Template compute node was not created.", {
|
|
926
|
+
F: __dxlog_file,
|
|
927
|
+
L: 501,
|
|
928
|
+
S: void 0,
|
|
929
|
+
A: [
|
|
930
|
+
"templateComputeNode",
|
|
931
|
+
"'Template compute node was not created.'"
|
|
932
|
+
]
|
|
933
|
+
});
|
|
934
|
+
templateComputeNode.value = [
|
|
935
|
+
"{",
|
|
936
|
+
' "@type": "{{type}}",',
|
|
937
|
+
' "id": "@{{changeId}}"',
|
|
938
|
+
"}"
|
|
939
|
+
].join("\n");
|
|
940
|
+
templateComputeNode.inputSchema = Type.toJsonSchema(Schema.Struct({
|
|
941
|
+
type: Schema.String,
|
|
942
|
+
changeId: Schema.String
|
|
943
|
+
}));
|
|
944
|
+
attachTrigger(functionTrigger, computeModel);
|
|
945
|
+
return {
|
|
946
|
+
canvasModel,
|
|
947
|
+
computeModel
|
|
948
|
+
};
|
|
949
|
+
};
|
|
950
|
+
var addToSpace = (name, space, canvas, compute) => {
|
|
951
|
+
return space.db.add(Obj2.make(CanvasBoardType, {
|
|
952
|
+
name,
|
|
953
|
+
computeGraph: Ref2.make(compute.root),
|
|
954
|
+
layout: canvas.graph
|
|
955
|
+
}));
|
|
956
|
+
};
|
|
957
|
+
var setupQueue = (space, canvasModel, args) => {
|
|
958
|
+
const queueId = canvasModel.createNode(createConstant({
|
|
959
|
+
value: new DXN2(DXN2.kind.QUEUE, [
|
|
960
|
+
"data",
|
|
961
|
+
space.id,
|
|
962
|
+
Key2.ObjectId.random()
|
|
963
|
+
]).toString(),
|
|
964
|
+
...args?.idPosition ? rawPosition(args.idPosition) : position({
|
|
965
|
+
x: -18,
|
|
966
|
+
y: 5,
|
|
967
|
+
width: 8,
|
|
968
|
+
height: 6
|
|
969
|
+
})
|
|
970
|
+
}));
|
|
971
|
+
const queue = canvasModel.createNode(createQueue(args?.queuePosition ? rawPosition(args.queuePosition) : position({
|
|
972
|
+
x: -3,
|
|
973
|
+
y: 3,
|
|
974
|
+
width: 14,
|
|
975
|
+
height: 10
|
|
976
|
+
})));
|
|
977
|
+
canvasModel.createEdge({
|
|
978
|
+
source: queueId.id,
|
|
979
|
+
target: queue.id
|
|
980
|
+
});
|
|
981
|
+
return {
|
|
982
|
+
queue,
|
|
983
|
+
queueId
|
|
984
|
+
};
|
|
985
|
+
};
|
|
986
|
+
var attachTrigger = (functionTrigger, computeModel) => {
|
|
987
|
+
invariant(functionTrigger, void 0, {
|
|
988
|
+
F: __dxlog_file,
|
|
989
|
+
L: 540,
|
|
990
|
+
S: void 0,
|
|
991
|
+
A: [
|
|
992
|
+
"functionTrigger",
|
|
993
|
+
""
|
|
994
|
+
]
|
|
995
|
+
});
|
|
996
|
+
functionTrigger.function = Ref2.make(computeModel.root);
|
|
997
|
+
const inputNode = computeModel.nodes.find((node) => node.type === NODE_INPUT2);
|
|
998
|
+
functionTrigger.inputNodeId = inputNode.id;
|
|
999
|
+
};
|
|
1000
|
+
var rawPosition = (args) => {
|
|
1001
|
+
return {
|
|
1002
|
+
center: {
|
|
1003
|
+
x: args.centerX,
|
|
1004
|
+
y: args.centerY
|
|
1005
|
+
},
|
|
1006
|
+
size: {
|
|
1007
|
+
width: args.width,
|
|
1008
|
+
height: args.height
|
|
1009
|
+
}
|
|
1010
|
+
};
|
|
1011
|
+
};
|
|
1012
|
+
var position = (rect) => {
|
|
1013
|
+
const snap = 32;
|
|
1014
|
+
const [center, size] = rectToPoints({
|
|
1015
|
+
width: 0,
|
|
1016
|
+
height: 0,
|
|
1017
|
+
...rect
|
|
1018
|
+
});
|
|
1019
|
+
const { x, y, width, height } = pointsToRect([
|
|
1020
|
+
pointMultiply(center, snap),
|
|
1021
|
+
pointMultiply(size, snap)
|
|
1022
|
+
]);
|
|
1023
|
+
if (width && height) {
|
|
1024
|
+
return {
|
|
1025
|
+
center: {
|
|
1026
|
+
x,
|
|
1027
|
+
y
|
|
1028
|
+
},
|
|
1029
|
+
size: width && height ? {
|
|
1030
|
+
width,
|
|
1031
|
+
height
|
|
1032
|
+
} : void 0
|
|
1033
|
+
};
|
|
1034
|
+
} else {
|
|
1035
|
+
return {
|
|
1036
|
+
center: {
|
|
1037
|
+
x,
|
|
1038
|
+
y
|
|
1039
|
+
}
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
};
|
|
1043
|
+
|
|
1044
|
+
// src/components/SpaceGenerator/SpaceGenerator.tsx
|
|
1045
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/plugins/plugin-debug/src/components/SpaceGenerator/SpaceGenerator.tsx";
|
|
1046
|
+
var SpaceGenerator = ({ space, onCreateObjects }) => {
|
|
1047
|
+
var _effect = _useSignals2();
|
|
1048
|
+
try {
|
|
1049
|
+
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
1050
|
+
const client = useClient();
|
|
1051
|
+
const staticTypes = [
|
|
1052
|
+
DocumentType2,
|
|
1053
|
+
DiagramType2,
|
|
1054
|
+
SheetType2,
|
|
1055
|
+
ComputeGraph2
|
|
1056
|
+
];
|
|
1057
|
+
const mutableTypes = [
|
|
1058
|
+
DataType2.Organization,
|
|
1059
|
+
DataType2.Project,
|
|
1060
|
+
DataType2.Person,
|
|
1061
|
+
DataType2.Message
|
|
1062
|
+
];
|
|
1063
|
+
const [count, setCount] = useState(1);
|
|
1064
|
+
const [info, setInfo] = useState({});
|
|
1065
|
+
const presets = useMemo(() => generator2(), []);
|
|
1066
|
+
const typeMap = useMemo(() => {
|
|
1067
|
+
client.addTypes([
|
|
1068
|
+
...staticTypes,
|
|
1069
|
+
...presets.schemas
|
|
1070
|
+
]);
|
|
1071
|
+
const mutableGenerators = new Map(mutableTypes.map((type) => [
|
|
1072
|
+
type.typename,
|
|
1073
|
+
createGenerator(type)
|
|
1074
|
+
]));
|
|
1075
|
+
return new Map([
|
|
1076
|
+
...staticGenerators,
|
|
1077
|
+
...presets.items,
|
|
1078
|
+
...mutableGenerators
|
|
1079
|
+
]);
|
|
1080
|
+
}, [
|
|
1081
|
+
client,
|
|
1082
|
+
mutableTypes
|
|
1083
|
+
]);
|
|
1084
|
+
const updateInfo = async () => {
|
|
1085
|
+
const echoSchema = await space.db.schemaRegistry.query().run();
|
|
1086
|
+
const staticSchema = space.db.graph.schemaRegistry.schemas;
|
|
1087
|
+
const { objects } = await space.db.query(Filter3.everything()).run();
|
|
1088
|
+
const objectMap = sortKeys(objects.reduce((map, obj) => {
|
|
1089
|
+
const type = getTypename(obj);
|
|
1090
|
+
if (type) {
|
|
1091
|
+
const count2 = map[type] ?? 0;
|
|
1092
|
+
map[type] = count2 + 1;
|
|
1093
|
+
}
|
|
1094
|
+
return map;
|
|
1095
|
+
}, {}));
|
|
1096
|
+
setInfo({
|
|
1097
|
+
schema: {
|
|
1098
|
+
static: staticSchema.length,
|
|
1099
|
+
mutable: echoSchema.length
|
|
1100
|
+
},
|
|
1101
|
+
objects: objectMap
|
|
1102
|
+
});
|
|
1103
|
+
};
|
|
1104
|
+
useAsyncEffect(updateInfo, [
|
|
1105
|
+
space
|
|
1106
|
+
]);
|
|
1107
|
+
const handleCreateData = useCallback(async (typename) => {
|
|
1108
|
+
const constructor = typeMap.get(typename);
|
|
1109
|
+
if (constructor) {
|
|
1110
|
+
await constructor(space, count, onCreateObjects);
|
|
1111
|
+
await updateInfo();
|
|
1112
|
+
}
|
|
1113
|
+
}, [
|
|
1114
|
+
typeMap,
|
|
1115
|
+
count
|
|
1116
|
+
]);
|
|
1117
|
+
const handleLoadTables = useCallback(async () => {
|
|
1118
|
+
const input = document.createElement("input");
|
|
1119
|
+
input.type = "file";
|
|
1120
|
+
input.accept = ".json";
|
|
1121
|
+
input.onchange = async (e) => {
|
|
1122
|
+
const file = e.target.files?.[0];
|
|
1123
|
+
if (!file) {
|
|
1124
|
+
return;
|
|
1125
|
+
}
|
|
1126
|
+
try {
|
|
1127
|
+
const content = await file.text();
|
|
1128
|
+
const data = JSON.parse(content);
|
|
1129
|
+
const schemas = await space.db.schemaRegistry.register(data.schemas.map(Type2.toEffectSchema));
|
|
1130
|
+
await Promise.all(schemas.map(async (schema) => {
|
|
1131
|
+
const parts = schema.typename.split("/");
|
|
1132
|
+
const name = parts[parts.length - 1];
|
|
1133
|
+
const table = Obj3.make(TableType3, {
|
|
1134
|
+
name,
|
|
1135
|
+
threads: []
|
|
1136
|
+
});
|
|
1137
|
+
await initializeTable({
|
|
1138
|
+
client,
|
|
1139
|
+
space,
|
|
1140
|
+
table,
|
|
1141
|
+
typename: schema.typename
|
|
1142
|
+
});
|
|
1143
|
+
await dispatch(createIntent(SpaceAction.AddObject, {
|
|
1144
|
+
target: space,
|
|
1145
|
+
object: table
|
|
1146
|
+
}));
|
|
1147
|
+
return table;
|
|
1148
|
+
}));
|
|
1149
|
+
await Promise.all(data.objects.map(async ({ id, "@type": typename, ...fields }) => {
|
|
1150
|
+
const schema = schemas.find((s) => `dxn:type:${s.typename}:${s.version}` === typename);
|
|
1151
|
+
if (!schema) {
|
|
1152
|
+
log.warn("Missing schema for object", {
|
|
1153
|
+
id,
|
|
1154
|
+
typename
|
|
1155
|
+
}, {
|
|
1156
|
+
F: __dxlog_file2,
|
|
1157
|
+
L: 125,
|
|
1158
|
+
S: void 0,
|
|
1159
|
+
C: (f, a) => f(...a)
|
|
1160
|
+
});
|
|
1161
|
+
return;
|
|
1162
|
+
}
|
|
1163
|
+
const object = Obj3.make(schema, fields);
|
|
1164
|
+
space.db.add(object);
|
|
1165
|
+
return object;
|
|
1166
|
+
}));
|
|
1167
|
+
} catch (err) {
|
|
1168
|
+
log.catch(err, void 0, {
|
|
1169
|
+
F: __dxlog_file2,
|
|
1170
|
+
L: 134,
|
|
1171
|
+
S: void 0,
|
|
1172
|
+
C: (f, a) => f(...a)
|
|
1173
|
+
});
|
|
1174
|
+
}
|
|
1175
|
+
};
|
|
1176
|
+
input.click();
|
|
1177
|
+
}, []);
|
|
1178
|
+
return /* @__PURE__ */ React2.createElement("div", {
|
|
1179
|
+
role: "none",
|
|
1180
|
+
className: "flex flex-col grow overflow-hidden"
|
|
1181
|
+
}, /* @__PURE__ */ React2.createElement(Toolbar.Root, {
|
|
1182
|
+
classNames: "border-be border-subduedSeparator"
|
|
1183
|
+
}, /* @__PURE__ */ React2.createElement(IconButton2, {
|
|
1184
|
+
icon: "ph--arrow-clockwise--regular",
|
|
1185
|
+
iconOnly: true,
|
|
1186
|
+
label: "Refresh",
|
|
1187
|
+
onClick: updateInfo
|
|
1188
|
+
}), /* @__PURE__ */ React2.createElement(IconButton2, {
|
|
1189
|
+
icon: "ph--file-arrow-up--regular",
|
|
1190
|
+
iconOnly: true,
|
|
1191
|
+
label: "Load tables from JSON",
|
|
1192
|
+
onClick: handleLoadTables
|
|
1193
|
+
}), /* @__PURE__ */ React2.createElement(Toolbar.Separator, {
|
|
1194
|
+
variant: "gap"
|
|
1195
|
+
}), /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.TextInput, {
|
|
1196
|
+
type: "number",
|
|
1197
|
+
min: 1,
|
|
1198
|
+
max: 100,
|
|
1199
|
+
placeholder: "Count",
|
|
1200
|
+
classNames: "!w-[4rem] !text-right",
|
|
1201
|
+
size: 8,
|
|
1202
|
+
value: count,
|
|
1203
|
+
onChange: (ev) => setCount(parseInt(ev.target.value))
|
|
1204
|
+
}))), /* @__PURE__ */ React2.createElement("div", {
|
|
1205
|
+
className: "flex flex-col overflow-y-auto divide-y divide-separator"
|
|
1206
|
+
}, /* @__PURE__ */ React2.createElement(SchemaTable, {
|
|
1207
|
+
types: staticTypes,
|
|
1208
|
+
objects: info.objects,
|
|
1209
|
+
label: "Static Types",
|
|
1210
|
+
onClick: handleCreateData
|
|
1211
|
+
}), /* @__PURE__ */ React2.createElement(SchemaTable, {
|
|
1212
|
+
types: mutableTypes,
|
|
1213
|
+
objects: info.objects,
|
|
1214
|
+
label: "Mutable Types",
|
|
1215
|
+
onClick: handleCreateData
|
|
1216
|
+
}), /* @__PURE__ */ React2.createElement(SchemaTable, {
|
|
1217
|
+
types: presets.types,
|
|
1218
|
+
objects: info.objects,
|
|
1219
|
+
label: "Presets",
|
|
1220
|
+
onClick: handleCreateData
|
|
1221
|
+
}), /* @__PURE__ */ React2.createElement("div", null, /* @__PURE__ */ React2.createElement(SyntaxHighlighter, {
|
|
1222
|
+
classNames: "flex text-xs",
|
|
1223
|
+
language: "json"
|
|
1224
|
+
}, JSON.stringify({
|
|
1225
|
+
space,
|
|
1226
|
+
...info
|
|
1227
|
+
}, jsonKeyReplacer({
|
|
1228
|
+
truncate: true
|
|
1229
|
+
}), 2)))));
|
|
1230
|
+
} finally {
|
|
1231
|
+
_effect.f();
|
|
1232
|
+
}
|
|
1233
|
+
};
|
|
1234
|
+
|
|
1235
|
+
// src/components/SpaceGenerator/index.ts
|
|
1236
|
+
var SpaceGenerator_default = SpaceGenerator;
|
|
1237
|
+
export {
|
|
1238
|
+
SpaceGenerator_default as default
|
|
1239
|
+
};
|
|
1240
|
+
//# sourceMappingURL=SpaceGenerator-MJR725EE.mjs.map
|