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