@dxos/plugin-debug 0.7.5-labs.5f04cf6 → 0.7.5-labs.8a82073
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-4VO7E5P2.mjs +846 -0
- package/dist/lib/browser/SpaceGenerator-4VO7E5P2.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-ZRQ4TPNG.mjs} +54 -51
- package/dist/lib/browser/react-surface-ZRQ4TPNG.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 +17 -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 +322 -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,846 @@
|
|
|
1
|
+
// packages/plugins/plugin-debug/src/components/SpaceGenerator/SpaceGenerator.tsx
|
|
2
|
+
import React2, { useCallback, useMemo, useState } from "react";
|
|
3
|
+
import { ComputeGraph as ComputeGraph2 } from "@dxos/conductor";
|
|
4
|
+
import { DocumentType as DocumentType2 } from "@dxos/plugin-markdown/types";
|
|
5
|
+
import { SheetType as SheetType2 } from "@dxos/plugin-sheet/types";
|
|
6
|
+
import { DiagramType as DiagramType2 } from "@dxos/plugin-sketch/types";
|
|
7
|
+
import { useClient } from "@dxos/react-client";
|
|
8
|
+
import { getTypename } from "@dxos/react-client/echo";
|
|
9
|
+
import { IconButton as IconButton2, Input, Toolbar, useAsyncEffect } from "@dxos/react-ui";
|
|
10
|
+
import { SyntaxHighlighter } from "@dxos/react-ui-syntax-highlighter";
|
|
11
|
+
import { Testing } from "@dxos/schema/testing";
|
|
12
|
+
import { jsonKeyReplacer, sortKeys } from "@dxos/util";
|
|
13
|
+
|
|
14
|
+
// packages/plugins/plugin-debug/src/components/SpaceGenerator/ObjectGenerator.tsx
|
|
15
|
+
import { addressToA1Notation } from "@dxos/compute";
|
|
16
|
+
import { ComputeGraph, ComputeGraphModel, DEFAULT_OUTPUT, NODE_INPUT, NODE_OUTPUT } from "@dxos/conductor";
|
|
17
|
+
import { ObjectId } from "@dxos/echo-schema";
|
|
18
|
+
import { DXN, SpaceId } from "@dxos/keys";
|
|
19
|
+
import { create, makeRef } from "@dxos/live-object";
|
|
20
|
+
import { DocumentType } from "@dxos/plugin-markdown/types";
|
|
21
|
+
import { createSheet } from "@dxos/plugin-sheet/types";
|
|
22
|
+
import { SheetType } from "@dxos/plugin-sheet/types";
|
|
23
|
+
import { CanvasType, DiagramType } from "@dxos/plugin-sketch/types";
|
|
24
|
+
import { faker } from "@dxos/random";
|
|
25
|
+
import { Filter } from "@dxos/react-client/echo";
|
|
26
|
+
import { TableType } from "@dxos/react-ui-table";
|
|
27
|
+
import { createView, TextType } from "@dxos/schema";
|
|
28
|
+
import { createAsyncGenerator } from "@dxos/schema/testing";
|
|
29
|
+
import { range } from "@dxos/util";
|
|
30
|
+
var generator = faker;
|
|
31
|
+
var staticGenerators = /* @__PURE__ */ new Map([
|
|
32
|
+
[
|
|
33
|
+
DocumentType.typename,
|
|
34
|
+
async (space, n, cb) => {
|
|
35
|
+
const objects = range(n).map(() => {
|
|
36
|
+
return space.db.add(create(DocumentType, {
|
|
37
|
+
name: faker.commerce.productName(),
|
|
38
|
+
content: makeRef(create(TextType, {
|
|
39
|
+
content: faker.lorem.sentences(5)
|
|
40
|
+
})),
|
|
41
|
+
threads: []
|
|
42
|
+
}));
|
|
43
|
+
});
|
|
44
|
+
cb?.(objects);
|
|
45
|
+
return objects;
|
|
46
|
+
}
|
|
47
|
+
],
|
|
48
|
+
[
|
|
49
|
+
DiagramType.typename,
|
|
50
|
+
async (space, n, cb) => {
|
|
51
|
+
const objects = range(n).map(() => {
|
|
52
|
+
const obj = space.db.add(create(DiagramType, {
|
|
53
|
+
name: faker.commerce.productName(),
|
|
54
|
+
canvas: makeRef(create(CanvasType, {
|
|
55
|
+
content: {}
|
|
56
|
+
}))
|
|
57
|
+
}));
|
|
58
|
+
return obj;
|
|
59
|
+
});
|
|
60
|
+
cb?.(objects);
|
|
61
|
+
return objects;
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
// TODO(burdon): Create unit tests.
|
|
65
|
+
[
|
|
66
|
+
SheetType.typename,
|
|
67
|
+
async (space, n, cb) => {
|
|
68
|
+
const objects = range(n).map(() => {
|
|
69
|
+
const cells = {};
|
|
70
|
+
const year = (/* @__PURE__ */ new Date()).getFullYear();
|
|
71
|
+
const cols = 4;
|
|
72
|
+
const rows = 16;
|
|
73
|
+
for (let col = 1; col <= cols; col++) {
|
|
74
|
+
for (let row = 1; row <= rows; row++) {
|
|
75
|
+
const cell = addressToA1Notation({
|
|
76
|
+
col,
|
|
77
|
+
row
|
|
78
|
+
});
|
|
79
|
+
if (row === 1) {
|
|
80
|
+
cells[cell] = {
|
|
81
|
+
value: `${year} Q${col}`
|
|
82
|
+
};
|
|
83
|
+
} else if (row === rows) {
|
|
84
|
+
const from = addressToA1Notation({
|
|
85
|
+
col,
|
|
86
|
+
row: 2
|
|
87
|
+
});
|
|
88
|
+
const to = addressToA1Notation({
|
|
89
|
+
col,
|
|
90
|
+
row: rows - 1
|
|
91
|
+
});
|
|
92
|
+
cells[cell] = {
|
|
93
|
+
value: `=SUM(${from}:${to})`
|
|
94
|
+
};
|
|
95
|
+
} else if (row > 2 && row < rows - 1) {
|
|
96
|
+
cells[cell] = {
|
|
97
|
+
value: Math.floor(Math.random() * 1e4)
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return space.db.add(createSheet({
|
|
103
|
+
name: faker.commerce.productName(),
|
|
104
|
+
cells
|
|
105
|
+
}));
|
|
106
|
+
});
|
|
107
|
+
cb?.(objects);
|
|
108
|
+
return objects;
|
|
109
|
+
}
|
|
110
|
+
],
|
|
111
|
+
[
|
|
112
|
+
ComputeGraph.typename,
|
|
113
|
+
async (space, n, cb) => {
|
|
114
|
+
const objects = range(n, () => {
|
|
115
|
+
const model = ComputeGraphModel.create();
|
|
116
|
+
model.builder.createNode({
|
|
117
|
+
id: "gpt-INPUT",
|
|
118
|
+
type: NODE_INPUT
|
|
119
|
+
}).createNode({
|
|
120
|
+
id: "gpt-GPT",
|
|
121
|
+
type: "gpt"
|
|
122
|
+
}).createNode({
|
|
123
|
+
id: "gpt-QUEUE_ID",
|
|
124
|
+
type: "constant",
|
|
125
|
+
value: new DXN(DXN.kind.QUEUE, [
|
|
126
|
+
"data",
|
|
127
|
+
SpaceId.random(),
|
|
128
|
+
ObjectId.random()
|
|
129
|
+
]).toString()
|
|
130
|
+
}).createNode({
|
|
131
|
+
id: "gpt-APPEND",
|
|
132
|
+
type: "append"
|
|
133
|
+
}).createNode({
|
|
134
|
+
id: "gpt-OUTPUT",
|
|
135
|
+
type: NODE_OUTPUT
|
|
136
|
+
}).createEdge({
|
|
137
|
+
node: "gpt-INPUT",
|
|
138
|
+
property: "prompt"
|
|
139
|
+
}, {
|
|
140
|
+
node: "gpt-GPT",
|
|
141
|
+
property: "prompt"
|
|
142
|
+
}).createEdge({
|
|
143
|
+
node: "gpt-GPT",
|
|
144
|
+
property: "text"
|
|
145
|
+
}, {
|
|
146
|
+
node: "gpt-OUTPUT",
|
|
147
|
+
property: "text"
|
|
148
|
+
}).createEdge({
|
|
149
|
+
node: "gpt-QUEUE_ID",
|
|
150
|
+
property: DEFAULT_OUTPUT
|
|
151
|
+
}, {
|
|
152
|
+
node: "gpt-APPEND",
|
|
153
|
+
property: "id"
|
|
154
|
+
}).createEdge({
|
|
155
|
+
node: "gpt-GPT",
|
|
156
|
+
property: "messages"
|
|
157
|
+
}, {
|
|
158
|
+
node: "gpt-APPEND",
|
|
159
|
+
property: "items"
|
|
160
|
+
}).createEdge({
|
|
161
|
+
node: "gpt-QUEUE_ID",
|
|
162
|
+
property: DEFAULT_OUTPUT
|
|
163
|
+
}, {
|
|
164
|
+
node: "gpt-OUTPUT",
|
|
165
|
+
property: "queue"
|
|
166
|
+
});
|
|
167
|
+
return space.db.add(model.root);
|
|
168
|
+
});
|
|
169
|
+
cb?.(objects);
|
|
170
|
+
return objects;
|
|
171
|
+
}
|
|
172
|
+
]
|
|
173
|
+
]);
|
|
174
|
+
var createGenerator = (type) => {
|
|
175
|
+
return async (space, n, cb) => {
|
|
176
|
+
const schema = await space.db.schemaRegistry.query({
|
|
177
|
+
typename: type.typename
|
|
178
|
+
}).firstOrUndefined() ?? (await space.db.schemaRegistry.register([
|
|
179
|
+
type
|
|
180
|
+
]))[0];
|
|
181
|
+
const generate = createAsyncGenerator(generator, schema.getSchemaSnapshot(), {
|
|
182
|
+
db: space.db
|
|
183
|
+
});
|
|
184
|
+
const objects = await generate.createObjects(n);
|
|
185
|
+
const { objects: tables } = await space.db.query(Filter.schema(TableType)).run();
|
|
186
|
+
const table = tables.find((table2) => table2.view?.target?.query?.type === type.typename);
|
|
187
|
+
if (!table) {
|
|
188
|
+
const name = type.typename.split("/").pop() ?? type.typename;
|
|
189
|
+
const view = createView({
|
|
190
|
+
name,
|
|
191
|
+
typename: type.typename,
|
|
192
|
+
jsonSchema: schema.jsonSchema
|
|
193
|
+
});
|
|
194
|
+
const table2 = space.db.add(create(TableType, {
|
|
195
|
+
name,
|
|
196
|
+
view: makeRef(view)
|
|
197
|
+
}));
|
|
198
|
+
cb?.([
|
|
199
|
+
table2
|
|
200
|
+
]);
|
|
201
|
+
}
|
|
202
|
+
return objects;
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
// packages/plugins/plugin-debug/src/components/SpaceGenerator/SchemaTable.tsx
|
|
207
|
+
import React from "react";
|
|
208
|
+
import { IconButton } from "@dxos/react-ui";
|
|
209
|
+
var SchemaTable = ({ types, objects = {}, label, onClick }) => {
|
|
210
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
211
|
+
className: "grid grid-cols-[1fr_80px_40px] gap-1 overflow-hidden"
|
|
212
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
213
|
+
className: "grid grid-cols-subgrid col-span-3"
|
|
214
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
215
|
+
className: "px-2 text-sm text-primary-500"
|
|
216
|
+
}, label), /* @__PURE__ */ React.createElement("div", {
|
|
217
|
+
className: "px-2 text-xs text-subdued text-right"
|
|
218
|
+
}, "count")), 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-green-500"
|
|
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
|
+
};
|
|
233
|
+
|
|
234
|
+
// packages/plugins/plugin-debug/src/components/SpaceGenerator/presets.ts
|
|
235
|
+
import { EmailTriggerOutput, NODE_INPUT as NODE_INPUT2 } from "@dxos/conductor";
|
|
236
|
+
import { AST, ObjectId as ObjectId2, S, toJsonSchema } from "@dxos/echo-schema";
|
|
237
|
+
import { FunctionTrigger, TriggerKind } from "@dxos/functions/types";
|
|
238
|
+
import { invariant } from "@dxos/invariant";
|
|
239
|
+
import { DXN as DXN2, SpaceId as SpaceId2 } from "@dxos/keys";
|
|
240
|
+
import { create as create2, makeRef as makeRef2 } from "@dxos/live-object";
|
|
241
|
+
import { Filter as Filter2 } from "@dxos/react-client/echo";
|
|
242
|
+
import { createAppend, createChat, createComputeGraph, createConstant, createGpt, createQueue, createTemplate, createText, createTrigger } from "@dxos/react-ui-canvas-compute";
|
|
243
|
+
import { CanvasBoardType, CanvasGraphModel, pointMultiply, pointsToRect, rectToPoints } from "@dxos/react-ui-canvas-editor";
|
|
244
|
+
import { TableType as TableType2 } from "@dxos/react-ui-table";
|
|
245
|
+
import { range as range2 } from "@dxos/util";
|
|
246
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-debug/src/components/SpaceGenerator/presets.ts";
|
|
247
|
+
var PresetName;
|
|
248
|
+
(function(PresetName2) {
|
|
249
|
+
PresetName2["EMAIL_TABLE"] = "email-table";
|
|
250
|
+
PresetName2["GPT_QUEUE"] = "webhook-gpt-queue";
|
|
251
|
+
PresetName2["CHAT_GPT"] = "chat-gpt-text";
|
|
252
|
+
PresetName2["EMAIL_WITH_SUMMARY"] = "email-gptSummary-table";
|
|
253
|
+
})(PresetName || (PresetName = {}));
|
|
254
|
+
var presets = {
|
|
255
|
+
schemas: [
|
|
256
|
+
CanvasBoardType,
|
|
257
|
+
FunctionTrigger
|
|
258
|
+
],
|
|
259
|
+
types: Object.values(PresetName).map((name) => ({
|
|
260
|
+
typename: name
|
|
261
|
+
})),
|
|
262
|
+
items: [
|
|
263
|
+
[
|
|
264
|
+
"webhook-gpt-queue",
|
|
265
|
+
async (space, n, cb) => {
|
|
266
|
+
const objects = range2(n, () => {
|
|
267
|
+
const canvasModel = CanvasGraphModel.create();
|
|
268
|
+
let functionTrigger;
|
|
269
|
+
canvasModel.builder.call((builder) => {
|
|
270
|
+
const gpt = canvasModel.createNode(createGpt(position({
|
|
271
|
+
x: 0,
|
|
272
|
+
y: -14
|
|
273
|
+
})));
|
|
274
|
+
const triggerShape = createTrigger({
|
|
275
|
+
triggerKind: TriggerKind.Webhook,
|
|
276
|
+
...position({
|
|
277
|
+
x: -18,
|
|
278
|
+
y: -2
|
|
279
|
+
})
|
|
280
|
+
});
|
|
281
|
+
const trigger = canvasModel.createNode(triggerShape);
|
|
282
|
+
const text = canvasModel.createNode(createText(position({
|
|
283
|
+
x: 19,
|
|
284
|
+
y: 3,
|
|
285
|
+
width: 10,
|
|
286
|
+
height: 10
|
|
287
|
+
})));
|
|
288
|
+
const { queueId } = setupQueue(canvasModel);
|
|
289
|
+
const append = canvasModel.createNode(createAppend(position({
|
|
290
|
+
x: 10,
|
|
291
|
+
y: 6
|
|
292
|
+
})));
|
|
293
|
+
builder.createEdge({
|
|
294
|
+
source: trigger.id,
|
|
295
|
+
target: gpt.id,
|
|
296
|
+
input: "prompt",
|
|
297
|
+
output: "body"
|
|
298
|
+
}).createEdge({
|
|
299
|
+
source: gpt.id,
|
|
300
|
+
target: text.id,
|
|
301
|
+
output: "text"
|
|
302
|
+
}).createEdge({
|
|
303
|
+
source: queueId.id,
|
|
304
|
+
target: append.id,
|
|
305
|
+
input: "id"
|
|
306
|
+
}).createEdge({
|
|
307
|
+
source: gpt.id,
|
|
308
|
+
target: append.id,
|
|
309
|
+
output: "messages",
|
|
310
|
+
input: "items"
|
|
311
|
+
});
|
|
312
|
+
functionTrigger = triggerShape.functionTrigger.target;
|
|
313
|
+
});
|
|
314
|
+
const computeModel = createComputeGraph(canvasModel);
|
|
315
|
+
attachTrigger(functionTrigger, computeModel);
|
|
316
|
+
return addToSpace("webhook-gpt-queue", space, canvasModel, computeModel);
|
|
317
|
+
});
|
|
318
|
+
cb?.(objects);
|
|
319
|
+
return objects;
|
|
320
|
+
}
|
|
321
|
+
],
|
|
322
|
+
[
|
|
323
|
+
"email-table",
|
|
324
|
+
async (space, n, cb) => {
|
|
325
|
+
const objects = range2(n, () => {
|
|
326
|
+
const canvasModel = CanvasGraphModel.create();
|
|
327
|
+
const results = space.db.query(Filter2.schema(TableType2)).runSync();
|
|
328
|
+
const emailTable = results.find((r) => r.object?.view?.target?.query?.type?.endsWith("Email"));
|
|
329
|
+
invariant(emailTable, "Email table not found.", {
|
|
330
|
+
F: __dxlog_file,
|
|
331
|
+
L: 90,
|
|
332
|
+
S: void 0,
|
|
333
|
+
A: [
|
|
334
|
+
"emailTable",
|
|
335
|
+
"'Email table not found.'"
|
|
336
|
+
]
|
|
337
|
+
});
|
|
338
|
+
const template = canvasModel.createNode(createTemplate({
|
|
339
|
+
valueType: "object",
|
|
340
|
+
...rawPosition({
|
|
341
|
+
centerX: -80,
|
|
342
|
+
centerY: -64,
|
|
343
|
+
width: 320,
|
|
344
|
+
height: 320
|
|
345
|
+
})
|
|
346
|
+
}));
|
|
347
|
+
const templateContent = [
|
|
348
|
+
"{"
|
|
349
|
+
];
|
|
350
|
+
let functionTrigger;
|
|
351
|
+
canvasModel.builder.call((builder) => {
|
|
352
|
+
const triggerShape = createTrigger({
|
|
353
|
+
triggerKind: TriggerKind.Email,
|
|
354
|
+
...position({
|
|
355
|
+
x: -18,
|
|
356
|
+
y: -2
|
|
357
|
+
})
|
|
358
|
+
});
|
|
359
|
+
const trigger = canvasModel.createNode(triggerShape);
|
|
360
|
+
const tableId = canvasModel.createNode(createConstant({
|
|
361
|
+
value: DXN2.fromLocalObjectId(emailTable.id).toString(),
|
|
362
|
+
...position({
|
|
363
|
+
x: -18,
|
|
364
|
+
y: 5,
|
|
365
|
+
width: 8,
|
|
366
|
+
height: 6
|
|
367
|
+
})
|
|
368
|
+
}));
|
|
369
|
+
const appendToTable = canvasModel.createNode(createAppend(position({
|
|
370
|
+
x: 10,
|
|
371
|
+
y: 6
|
|
372
|
+
})));
|
|
373
|
+
const properties = AST.getPropertySignatures(EmailTriggerOutput.ast);
|
|
374
|
+
for (let i = 0; i < properties.length; i++) {
|
|
375
|
+
const propName = properties[i].name.toString();
|
|
376
|
+
builder.createEdge({
|
|
377
|
+
source: trigger.id,
|
|
378
|
+
target: template.id,
|
|
379
|
+
input: propName,
|
|
380
|
+
output: propName
|
|
381
|
+
});
|
|
382
|
+
templateContent.push(` "${propName}": "{{${propName}}}"` + (i === properties.length - 1 ? "" : ","));
|
|
383
|
+
}
|
|
384
|
+
templateContent.push("}");
|
|
385
|
+
builder.createEdge({
|
|
386
|
+
source: tableId.id,
|
|
387
|
+
target: appendToTable.id,
|
|
388
|
+
input: "id"
|
|
389
|
+
}).createEdge({
|
|
390
|
+
source: template.id,
|
|
391
|
+
target: appendToTable.id,
|
|
392
|
+
input: "items"
|
|
393
|
+
});
|
|
394
|
+
functionTrigger = triggerShape.functionTrigger.target;
|
|
395
|
+
});
|
|
396
|
+
const computeModel = createComputeGraph(canvasModel);
|
|
397
|
+
const templateComputeNode = computeModel.nodes.find((n2) => n2.id === template.node);
|
|
398
|
+
invariant(templateComputeNode, "Template compute node was not created.", {
|
|
399
|
+
F: __dxlog_file,
|
|
400
|
+
L: 132,
|
|
401
|
+
S: void 0,
|
|
402
|
+
A: [
|
|
403
|
+
"templateComputeNode",
|
|
404
|
+
"'Template compute node was not created.'"
|
|
405
|
+
]
|
|
406
|
+
});
|
|
407
|
+
templateComputeNode.value = templateContent.join("\n");
|
|
408
|
+
templateComputeNode.inputSchema = toJsonSchema(EmailTriggerOutput);
|
|
409
|
+
attachTrigger(functionTrigger, computeModel);
|
|
410
|
+
return addToSpace("email-table", space, canvasModel, computeModel);
|
|
411
|
+
});
|
|
412
|
+
cb?.(objects);
|
|
413
|
+
return objects;
|
|
414
|
+
}
|
|
415
|
+
],
|
|
416
|
+
[
|
|
417
|
+
"chat-gpt-text",
|
|
418
|
+
async (space, n, cb) => {
|
|
419
|
+
const objects = range2(n, () => {
|
|
420
|
+
const canvasModel = CanvasGraphModel.create();
|
|
421
|
+
canvasModel.builder.call((builder) => {
|
|
422
|
+
const gpt = canvasModel.createNode(createGpt(position({
|
|
423
|
+
x: 0,
|
|
424
|
+
y: -14
|
|
425
|
+
})));
|
|
426
|
+
const chat = canvasModel.createNode(createChat(position({
|
|
427
|
+
x: -18,
|
|
428
|
+
y: -2
|
|
429
|
+
})));
|
|
430
|
+
const text = canvasModel.createNode(createText(position({
|
|
431
|
+
x: 19,
|
|
432
|
+
y: 3,
|
|
433
|
+
width: 10,
|
|
434
|
+
height: 10
|
|
435
|
+
})));
|
|
436
|
+
const { queueId } = setupQueue(canvasModel);
|
|
437
|
+
const append = canvasModel.createNode(createAppend(position({
|
|
438
|
+
x: 10,
|
|
439
|
+
y: 6
|
|
440
|
+
})));
|
|
441
|
+
builder.createEdge({
|
|
442
|
+
source: chat.id,
|
|
443
|
+
target: gpt.id,
|
|
444
|
+
input: "prompt"
|
|
445
|
+
}).createEdge({
|
|
446
|
+
source: gpt.id,
|
|
447
|
+
target: text.id,
|
|
448
|
+
output: "text"
|
|
449
|
+
}).createEdge({
|
|
450
|
+
source: queueId.id,
|
|
451
|
+
target: append.id,
|
|
452
|
+
input: "id"
|
|
453
|
+
}).createEdge({
|
|
454
|
+
source: gpt.id,
|
|
455
|
+
target: append.id,
|
|
456
|
+
output: "messages",
|
|
457
|
+
input: "items"
|
|
458
|
+
});
|
|
459
|
+
});
|
|
460
|
+
const computeModel = createComputeGraph(canvasModel);
|
|
461
|
+
return addToSpace("chat-gpt-text", space, canvasModel, computeModel);
|
|
462
|
+
});
|
|
463
|
+
cb?.(objects);
|
|
464
|
+
return objects;
|
|
465
|
+
}
|
|
466
|
+
],
|
|
467
|
+
[
|
|
468
|
+
"email-gptSummary-table",
|
|
469
|
+
async (space, n, cb) => {
|
|
470
|
+
const objects = range2(n, () => {
|
|
471
|
+
const canvasModel = CanvasGraphModel.create();
|
|
472
|
+
const results = space.db.query(Filter2.schema(TableType2)).runSync();
|
|
473
|
+
const emailTable = results.find((r) => r.object?.view?.target?.query?.type?.endsWith("Email"));
|
|
474
|
+
invariant(emailTable, "Email table not found.", {
|
|
475
|
+
F: __dxlog_file,
|
|
476
|
+
L: 183,
|
|
477
|
+
S: void 0,
|
|
478
|
+
A: [
|
|
479
|
+
"emailTable",
|
|
480
|
+
"'Email table not found.'"
|
|
481
|
+
]
|
|
482
|
+
});
|
|
483
|
+
const template = canvasModel.createNode(createTemplate({
|
|
484
|
+
valueType: "object",
|
|
485
|
+
...rawPosition({
|
|
486
|
+
centerX: 192,
|
|
487
|
+
centerY: -176,
|
|
488
|
+
width: 320,
|
|
489
|
+
height: 320
|
|
490
|
+
})
|
|
491
|
+
}));
|
|
492
|
+
const templateContent = [
|
|
493
|
+
"{"
|
|
494
|
+
];
|
|
495
|
+
let functionTrigger;
|
|
496
|
+
canvasModel.builder.call((builder) => {
|
|
497
|
+
const gpt = canvasModel.createNode(createGpt(rawPosition({
|
|
498
|
+
centerX: -400,
|
|
499
|
+
centerY: -112,
|
|
500
|
+
width: 256,
|
|
501
|
+
height: 202
|
|
502
|
+
})));
|
|
503
|
+
const systemPrompt = canvasModel.createNode(createConstant({
|
|
504
|
+
value: "use one word to describe content category. don't write anything else",
|
|
505
|
+
...rawPosition({
|
|
506
|
+
centerX: -800,
|
|
507
|
+
centerY: -160,
|
|
508
|
+
width: 192,
|
|
509
|
+
height: 128
|
|
510
|
+
})
|
|
511
|
+
}));
|
|
512
|
+
const triggerShape = createTrigger({
|
|
513
|
+
triggerKind: TriggerKind.Email,
|
|
514
|
+
...rawPosition({
|
|
515
|
+
centerX: -736,
|
|
516
|
+
centerY: -384,
|
|
517
|
+
width: 182,
|
|
518
|
+
height: 192
|
|
519
|
+
})
|
|
520
|
+
});
|
|
521
|
+
const trigger = canvasModel.createNode(triggerShape);
|
|
522
|
+
const { queueId } = setupQueue(canvasModel, {
|
|
523
|
+
idPosition: {
|
|
524
|
+
centerX: -720,
|
|
525
|
+
centerY: 224,
|
|
526
|
+
width: 192,
|
|
527
|
+
height: 256
|
|
528
|
+
},
|
|
529
|
+
queuePosition: {
|
|
530
|
+
centerX: -144,
|
|
531
|
+
centerY: 416,
|
|
532
|
+
width: 320,
|
|
533
|
+
height: 448
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
const appendToQueue = canvasModel.createNode(createAppend(rawPosition({
|
|
537
|
+
centerX: -80,
|
|
538
|
+
centerY: 96,
|
|
539
|
+
width: 122,
|
|
540
|
+
height: 128
|
|
541
|
+
})));
|
|
542
|
+
const tableId = canvasModel.createNode(createConstant({
|
|
543
|
+
value: DXN2.fromLocalObjectId(emailTable.id).toString(),
|
|
544
|
+
...rawPosition({
|
|
545
|
+
centerX: -112,
|
|
546
|
+
centerY: -544,
|
|
547
|
+
width: 192,
|
|
548
|
+
height: 256
|
|
549
|
+
})
|
|
550
|
+
}));
|
|
551
|
+
const appendToTable = canvasModel.createNode(createAppend(rawPosition({
|
|
552
|
+
centerX: 560,
|
|
553
|
+
centerY: -416,
|
|
554
|
+
width: 128,
|
|
555
|
+
height: 122
|
|
556
|
+
})));
|
|
557
|
+
templateContent.push(' "category": "{{text}}",');
|
|
558
|
+
builder.createEdge({
|
|
559
|
+
source: gpt.id,
|
|
560
|
+
target: template.id,
|
|
561
|
+
input: "text",
|
|
562
|
+
output: "text"
|
|
563
|
+
});
|
|
564
|
+
const properties = AST.getPropertySignatures(EmailTriggerOutput.ast);
|
|
565
|
+
for (let i = 0; i < properties.length; i++) {
|
|
566
|
+
const propName = properties[i].name.toString();
|
|
567
|
+
builder.createEdge({
|
|
568
|
+
source: trigger.id,
|
|
569
|
+
target: template.id,
|
|
570
|
+
input: propName,
|
|
571
|
+
output: propName
|
|
572
|
+
});
|
|
573
|
+
templateContent.push(` "${propName}": "{{${propName}}}"` + (i === properties.length - 1 ? "" : ","));
|
|
574
|
+
}
|
|
575
|
+
templateContent.push("}");
|
|
576
|
+
builder.createEdge({
|
|
577
|
+
source: tableId.id,
|
|
578
|
+
target: appendToTable.id,
|
|
579
|
+
input: "id"
|
|
580
|
+
}).createEdge({
|
|
581
|
+
source: queueId.id,
|
|
582
|
+
target: appendToQueue.id,
|
|
583
|
+
input: "id"
|
|
584
|
+
}).createEdge({
|
|
585
|
+
source: gpt.id,
|
|
586
|
+
target: appendToQueue.id,
|
|
587
|
+
output: "messages",
|
|
588
|
+
input: "items"
|
|
589
|
+
}).createEdge({
|
|
590
|
+
source: systemPrompt.id,
|
|
591
|
+
target: gpt.id,
|
|
592
|
+
input: "systemPrompt"
|
|
593
|
+
}).createEdge({
|
|
594
|
+
source: trigger.id,
|
|
595
|
+
target: gpt.id,
|
|
596
|
+
input: "prompt",
|
|
597
|
+
output: "body"
|
|
598
|
+
}).createEdge({
|
|
599
|
+
source: template.id,
|
|
600
|
+
target: appendToTable.id,
|
|
601
|
+
input: "items"
|
|
602
|
+
});
|
|
603
|
+
functionTrigger = triggerShape.functionTrigger.target;
|
|
604
|
+
});
|
|
605
|
+
const computeModel = createComputeGraph(canvasModel);
|
|
606
|
+
const templateComputeNode = computeModel.nodes.find((n2) => n2.id === template.node);
|
|
607
|
+
invariant(templateComputeNode, "Template compute node was not created.", {
|
|
608
|
+
F: __dxlog_file,
|
|
609
|
+
L: 254,
|
|
610
|
+
S: void 0,
|
|
611
|
+
A: [
|
|
612
|
+
"templateComputeNode",
|
|
613
|
+
"'Template compute node was not created.'"
|
|
614
|
+
]
|
|
615
|
+
});
|
|
616
|
+
templateComputeNode.value = templateContent.join("\n");
|
|
617
|
+
const extendedSchema = S.extend(EmailTriggerOutput, S.Struct({
|
|
618
|
+
text: S.String
|
|
619
|
+
}));
|
|
620
|
+
templateComputeNode.inputSchema = toJsonSchema(extendedSchema);
|
|
621
|
+
attachTrigger(functionTrigger, computeModel);
|
|
622
|
+
return addToSpace("email-gptSummary-table", space, canvasModel, computeModel);
|
|
623
|
+
});
|
|
624
|
+
cb?.(objects);
|
|
625
|
+
return objects;
|
|
626
|
+
}
|
|
627
|
+
]
|
|
628
|
+
]
|
|
629
|
+
};
|
|
630
|
+
var addToSpace = (name, space, canvas, compute) => {
|
|
631
|
+
return space.db.add(create2(CanvasBoardType, {
|
|
632
|
+
name,
|
|
633
|
+
computeGraph: makeRef2(compute.root),
|
|
634
|
+
layout: canvas.graph
|
|
635
|
+
}));
|
|
636
|
+
};
|
|
637
|
+
var setupQueue = (canvasModel, args) => {
|
|
638
|
+
const queueId = canvasModel.createNode(createConstant({
|
|
639
|
+
value: new DXN2(DXN2.kind.QUEUE, [
|
|
640
|
+
"data",
|
|
641
|
+
SpaceId2.random(),
|
|
642
|
+
ObjectId2.random()
|
|
643
|
+
]).toString(),
|
|
644
|
+
...args?.idPosition ? rawPosition(args.idPosition) : position({
|
|
645
|
+
x: -18,
|
|
646
|
+
y: 5,
|
|
647
|
+
width: 8,
|
|
648
|
+
height: 6
|
|
649
|
+
})
|
|
650
|
+
}));
|
|
651
|
+
const queue = canvasModel.createNode(createQueue(args?.queuePosition ? rawPosition(args.queuePosition) : position({
|
|
652
|
+
x: -3,
|
|
653
|
+
y: 3,
|
|
654
|
+
width: 14,
|
|
655
|
+
height: 10
|
|
656
|
+
})));
|
|
657
|
+
canvasModel.createEdge({
|
|
658
|
+
source: queueId.id,
|
|
659
|
+
target: queue.id
|
|
660
|
+
});
|
|
661
|
+
return {
|
|
662
|
+
queue,
|
|
663
|
+
queueId
|
|
664
|
+
};
|
|
665
|
+
};
|
|
666
|
+
var attachTrigger = (functionTrigger, computeModel) => {
|
|
667
|
+
invariant(functionTrigger, void 0, {
|
|
668
|
+
F: __dxlog_file,
|
|
669
|
+
L: 300,
|
|
670
|
+
S: void 0,
|
|
671
|
+
A: [
|
|
672
|
+
"functionTrigger",
|
|
673
|
+
""
|
|
674
|
+
]
|
|
675
|
+
});
|
|
676
|
+
functionTrigger.function = DXN2.fromLocalObjectId(computeModel.root.id).toString();
|
|
677
|
+
functionTrigger.meta ??= {};
|
|
678
|
+
const inputNode = computeModel.nodes.find((node) => node.type === NODE_INPUT2);
|
|
679
|
+
functionTrigger.meta.computeNodeId = inputNode.id;
|
|
680
|
+
};
|
|
681
|
+
var rawPosition = (args) => {
|
|
682
|
+
return {
|
|
683
|
+
center: {
|
|
684
|
+
x: args.centerX,
|
|
685
|
+
y: args.centerY
|
|
686
|
+
},
|
|
687
|
+
size: {
|
|
688
|
+
width: args.width,
|
|
689
|
+
height: args.height
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
};
|
|
693
|
+
var position = (rect) => {
|
|
694
|
+
const snap = 32;
|
|
695
|
+
const [center, size] = rectToPoints({
|
|
696
|
+
width: 0,
|
|
697
|
+
height: 0,
|
|
698
|
+
...rect
|
|
699
|
+
});
|
|
700
|
+
const { x, y, width, height } = pointsToRect([
|
|
701
|
+
pointMultiply(center, snap),
|
|
702
|
+
pointMultiply(size, snap)
|
|
703
|
+
]);
|
|
704
|
+
if (width && height) {
|
|
705
|
+
return {
|
|
706
|
+
center: {
|
|
707
|
+
x,
|
|
708
|
+
y
|
|
709
|
+
},
|
|
710
|
+
size: width && height ? {
|
|
711
|
+
width,
|
|
712
|
+
height
|
|
713
|
+
} : void 0
|
|
714
|
+
};
|
|
715
|
+
} else {
|
|
716
|
+
return {
|
|
717
|
+
center: {
|
|
718
|
+
x,
|
|
719
|
+
y
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
|
|
725
|
+
// packages/plugins/plugin-debug/src/components/SpaceGenerator/SpaceGenerator.tsx
|
|
726
|
+
var SpaceGenerator = ({ space, onCreateObjects }) => {
|
|
727
|
+
const client = useClient();
|
|
728
|
+
const staticTypes = [
|
|
729
|
+
DocumentType2,
|
|
730
|
+
DiagramType2,
|
|
731
|
+
SheetType2,
|
|
732
|
+
ComputeGraph2
|
|
733
|
+
];
|
|
734
|
+
const mutableTypes = [
|
|
735
|
+
Testing.OrgType,
|
|
736
|
+
Testing.ProjectType,
|
|
737
|
+
Testing.ContactType,
|
|
738
|
+
Testing.EmailType
|
|
739
|
+
];
|
|
740
|
+
const [count, setCount] = useState(1);
|
|
741
|
+
const [info, setInfo] = useState({});
|
|
742
|
+
const typeMap = useMemo(() => {
|
|
743
|
+
client.addTypes([
|
|
744
|
+
...staticTypes,
|
|
745
|
+
...presets.schemas
|
|
746
|
+
]);
|
|
747
|
+
const mutableGenerators = new Map(mutableTypes.map((type) => [
|
|
748
|
+
type.typename,
|
|
749
|
+
createGenerator(type)
|
|
750
|
+
]));
|
|
751
|
+
return new Map([
|
|
752
|
+
...staticGenerators,
|
|
753
|
+
...presets.items,
|
|
754
|
+
...mutableGenerators
|
|
755
|
+
]);
|
|
756
|
+
}, [
|
|
757
|
+
client,
|
|
758
|
+
mutableTypes
|
|
759
|
+
]);
|
|
760
|
+
const updateInfo = async () => {
|
|
761
|
+
const echoSchema = await space.db.schemaRegistry.query().run();
|
|
762
|
+
const staticSchema = space.db.graph.schemaRegistry.schemas;
|
|
763
|
+
const { objects } = await space.db.query().run();
|
|
764
|
+
const objectMap = sortKeys(objects.reduce((map, obj) => {
|
|
765
|
+
const type = getTypename(obj);
|
|
766
|
+
if (type) {
|
|
767
|
+
const count2 = map[type] ?? 0;
|
|
768
|
+
map[type] = count2 + 1;
|
|
769
|
+
}
|
|
770
|
+
return map;
|
|
771
|
+
}, {}));
|
|
772
|
+
setInfo({
|
|
773
|
+
schema: {
|
|
774
|
+
static: staticSchema.length,
|
|
775
|
+
mutable: echoSchema.length
|
|
776
|
+
},
|
|
777
|
+
objects: objectMap
|
|
778
|
+
});
|
|
779
|
+
};
|
|
780
|
+
useAsyncEffect(updateInfo, [
|
|
781
|
+
space
|
|
782
|
+
]);
|
|
783
|
+
const handleCreateData = useCallback(async (typename) => {
|
|
784
|
+
const constructor = typeMap.get(typename);
|
|
785
|
+
if (constructor) {
|
|
786
|
+
await constructor(space, count, onCreateObjects);
|
|
787
|
+
await updateInfo();
|
|
788
|
+
}
|
|
789
|
+
}, [
|
|
790
|
+
typeMap,
|
|
791
|
+
count
|
|
792
|
+
]);
|
|
793
|
+
return /* @__PURE__ */ React2.createElement("div", {
|
|
794
|
+
role: "none",
|
|
795
|
+
className: "flex flex-col divide-y divide-separator"
|
|
796
|
+
}, /* @__PURE__ */ React2.createElement(Toolbar.Root, {
|
|
797
|
+
classNames: "p-1"
|
|
798
|
+
}, /* @__PURE__ */ React2.createElement(IconButton2, {
|
|
799
|
+
icon: "ph--arrow-clockwise--regular",
|
|
800
|
+
iconOnly: true,
|
|
801
|
+
label: "Refresh",
|
|
802
|
+
onClick: updateInfo
|
|
803
|
+
}), /* @__PURE__ */ React2.createElement(Toolbar.Separator, {
|
|
804
|
+
variant: "gap"
|
|
805
|
+
}), /* @__PURE__ */ React2.createElement("div", {
|
|
806
|
+
className: "flex"
|
|
807
|
+
}, /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.TextInput, {
|
|
808
|
+
type: "number",
|
|
809
|
+
min: 1,
|
|
810
|
+
max: 100,
|
|
811
|
+
placeholder: "Count",
|
|
812
|
+
classNames: "w-[80px]",
|
|
813
|
+
value: count,
|
|
814
|
+
onChange: (ev) => setCount(parseInt(ev.target.value))
|
|
815
|
+
})))), /* @__PURE__ */ React2.createElement(SchemaTable, {
|
|
816
|
+
types: staticTypes,
|
|
817
|
+
objects: info.objects,
|
|
818
|
+
label: "Static Types",
|
|
819
|
+
onClick: handleCreateData
|
|
820
|
+
}), /* @__PURE__ */ React2.createElement(SchemaTable, {
|
|
821
|
+
types: mutableTypes,
|
|
822
|
+
objects: info.objects,
|
|
823
|
+
label: "Mutable Types",
|
|
824
|
+
onClick: handleCreateData
|
|
825
|
+
}), /* @__PURE__ */ React2.createElement(SchemaTable, {
|
|
826
|
+
types: presets.types,
|
|
827
|
+
objects: info.objects,
|
|
828
|
+
label: "Presets",
|
|
829
|
+
onClick: handleCreateData
|
|
830
|
+
}), /* @__PURE__ */ React2.createElement(SyntaxHighlighter, {
|
|
831
|
+
classNames: "flex text-xs",
|
|
832
|
+
language: "json"
|
|
833
|
+
}, JSON.stringify({
|
|
834
|
+
space,
|
|
835
|
+
...info
|
|
836
|
+
}, jsonKeyReplacer({
|
|
837
|
+
truncate: true
|
|
838
|
+
}), 2)));
|
|
839
|
+
};
|
|
840
|
+
|
|
841
|
+
// packages/plugins/plugin-debug/src/components/SpaceGenerator/index.ts
|
|
842
|
+
var SpaceGenerator_default = SpaceGenerator;
|
|
843
|
+
export {
|
|
844
|
+
SpaceGenerator_default as default
|
|
845
|
+
};
|
|
846
|
+
//# sourceMappingURL=SpaceGenerator-4VO7E5P2.mjs.map
|