@dxos/plugin-debug 0.7.5-labs.a279d8c → 0.7.5-labs.c0e040f
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-OIDM3MIN.mjs +1059 -0
- package/dist/lib/browser/SpaceGenerator-OIDM3MIN.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-YAJPSHG4.mjs} +54 -51
- package/dist/lib/browser/react-surface-YAJPSHG4.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 +20 -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 +453 -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
|
@@ -4,15 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { useEffect, useRef, useState } from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { useAppGraph, useLayout } from '@dxos/app-framework';
|
|
8
8
|
import { TimeoutError } from '@dxos/async';
|
|
9
9
|
import { StatsPanel, useStats } from '@dxos/devtools';
|
|
10
10
|
import { getActiveSpace } from '@dxos/plugin-space';
|
|
11
11
|
import { StatusBar } from '@dxos/plugin-status-bar';
|
|
12
12
|
import { ConnectionState } from '@dxos/protocols/proto/dxos/client/services';
|
|
13
13
|
import { useNetworkStatus } from '@dxos/react-client/mesh';
|
|
14
|
-
import { Icon } from '@dxos/react-ui';
|
|
15
|
-
import { mx } from '@dxos/react-ui-theme';
|
|
14
|
+
import { Icon, Popover } from '@dxos/react-ui';
|
|
16
15
|
|
|
17
16
|
const styles = {
|
|
18
17
|
success: 'text-sky-300 dark:text-green-700',
|
|
@@ -136,9 +135,9 @@ const SwarmIndicator = () => {
|
|
|
136
135
|
// TODO(burdon): Merge with SaveStatus.
|
|
137
136
|
const SavingIndicator = () => {
|
|
138
137
|
const [state, _setState] = useState(0);
|
|
139
|
-
const
|
|
140
|
-
const { graph } =
|
|
141
|
-
const _space =
|
|
138
|
+
const layout = useLayout();
|
|
139
|
+
const { graph } = useAppGraph();
|
|
140
|
+
const _space = graph ? getActiveSpace(graph, layout.active[0]) : undefined;
|
|
142
141
|
// TODO(dmaretskyi): Fix this when we have save status for automerge.
|
|
143
142
|
// useEffect(() => {
|
|
144
143
|
// if (!space) {
|
|
@@ -186,22 +185,19 @@ const PerformanceIndicator = () => {
|
|
|
186
185
|
const [stats, refreshStats] = useStats();
|
|
187
186
|
|
|
188
187
|
return (
|
|
189
|
-
|
|
190
|
-
<
|
|
191
|
-
<
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
'overflow-x-hidden overflow-y-auto scrollbar-thin',
|
|
198
|
-
'border-x border-y border-separator',
|
|
199
|
-
)}
|
|
200
|
-
>
|
|
188
|
+
<Popover.Root open={visible} onOpenChange={setVisible}>
|
|
189
|
+
<Popover.Trigger asChild>
|
|
190
|
+
<StatusBar.Button onClick={() => setVisible((visible) => !visible)} title='Performance panels'>
|
|
191
|
+
<Icon icon='ph--chart-bar--regular' size={4} />
|
|
192
|
+
</StatusBar.Button>
|
|
193
|
+
</Popover.Trigger>
|
|
194
|
+
<Popover.Portal>
|
|
195
|
+
<Popover.Content classNames='max-is-[min(var(--radix-popover-content-available-width),300px)] max-bs-[--radix-popover-content-available-height]'>
|
|
201
196
|
<StatsPanel stats={stats} onRefresh={refreshStats} />
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
197
|
+
<Popover.Arrow />
|
|
198
|
+
</Popover.Content>
|
|
199
|
+
</Popover.Portal>
|
|
200
|
+
</Popover.Root>
|
|
205
201
|
);
|
|
206
202
|
};
|
|
207
203
|
|
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
import { addressToA1Notation } from '@dxos/compute';
|
|
6
6
|
import { ComputeGraph, ComputeGraphModel, DEFAULT_OUTPUT, NODE_INPUT, NODE_OUTPUT } from '@dxos/conductor';
|
|
7
7
|
import { ObjectId, type BaseObject, type TypedObject } from '@dxos/echo-schema';
|
|
8
|
-
import { type FunctionTrigger, TriggerKind } from '@dxos/functions/types';
|
|
9
|
-
import { invariant } from '@dxos/invariant';
|
|
10
8
|
import { DXN, SpaceId } from '@dxos/keys';
|
|
11
9
|
import { create, makeRef, type ReactiveObject } from '@dxos/live-object';
|
|
12
10
|
import { DocumentType } from '@dxos/plugin-markdown/types';
|
|
@@ -15,23 +13,6 @@ import { SheetType, type CellValue } from '@dxos/plugin-sheet/types';
|
|
|
15
13
|
import { CanvasType, DiagramType } from '@dxos/plugin-sketch/types';
|
|
16
14
|
import { faker } from '@dxos/random';
|
|
17
15
|
import { Filter, type Space } from '@dxos/react-client/echo';
|
|
18
|
-
import {
|
|
19
|
-
type ComputeShape,
|
|
20
|
-
createAppend,
|
|
21
|
-
createComputeGraph,
|
|
22
|
-
createConstant,
|
|
23
|
-
createGpt,
|
|
24
|
-
createQueue,
|
|
25
|
-
createText,
|
|
26
|
-
createTrigger,
|
|
27
|
-
} from '@dxos/react-ui-canvas-compute';
|
|
28
|
-
import {
|
|
29
|
-
pointMultiply,
|
|
30
|
-
pointsToRect,
|
|
31
|
-
rectToPoints,
|
|
32
|
-
CanvasBoardType,
|
|
33
|
-
CanvasGraphModel,
|
|
34
|
-
} from '@dxos/react-ui-canvas-editor';
|
|
35
16
|
import { TableType } from '@dxos/react-ui-table';
|
|
36
17
|
import { createView, TextType } from '@dxos/schema';
|
|
37
18
|
import { createAsyncGenerator, type ValueGenerator } from '@dxos/schema/testing';
|
|
@@ -155,70 +136,8 @@ export const staticGenerators = new Map<string, ObjectGenerator<any>>([
|
|
|
155
136
|
return objects;
|
|
156
137
|
},
|
|
157
138
|
],
|
|
158
|
-
[
|
|
159
|
-
CanvasBoardType.typename,
|
|
160
|
-
async (space, n, cb) => {
|
|
161
|
-
const objects = range(n, () => {
|
|
162
|
-
const canvasModel = CanvasGraphModel.create<ComputeShape>();
|
|
163
|
-
|
|
164
|
-
let functionTrigger: FunctionTrigger | undefined;
|
|
165
|
-
canvasModel.builder.call((builder) => {
|
|
166
|
-
const gpt = canvasModel.createNode(createGpt(position({ x: 0, y: -14 })));
|
|
167
|
-
const triggerShape = createTrigger({ triggerKind: TriggerKind.Webhook, ...position({ x: -18, y: -2 }) });
|
|
168
|
-
const trigger = canvasModel.createNode(triggerShape);
|
|
169
|
-
const text = canvasModel.createNode(createText(position({ x: 19, y: 3, width: 10, height: 10 })));
|
|
170
|
-
const queueId = canvasModel.createNode(
|
|
171
|
-
createConstant({
|
|
172
|
-
value: new DXN(DXN.kind.QUEUE, ['data', SpaceId.random(), ObjectId.random()]).toString(),
|
|
173
|
-
...position({ x: -18, y: 5, width: 8, height: 6 }),
|
|
174
|
-
}),
|
|
175
|
-
);
|
|
176
|
-
const queue = canvasModel.createNode(createQueue(position({ x: -3, y: 3, width: 14, height: 10 })));
|
|
177
|
-
const append = canvasModel.createNode(createAppend(position({ x: 10, y: 6 })));
|
|
178
|
-
|
|
179
|
-
builder
|
|
180
|
-
.createEdge({ source: trigger.id, target: gpt.id, input: 'prompt', output: 'bodyText' })
|
|
181
|
-
.createEdge({ source: gpt.id, target: text.id, output: 'text' })
|
|
182
|
-
.createEdge({ source: queueId.id, target: queue.id })
|
|
183
|
-
.createEdge({ source: queueId.id, target: append.id, input: 'id' })
|
|
184
|
-
.createEdge({ source: gpt.id, target: append.id, output: 'messages', input: 'items' });
|
|
185
|
-
|
|
186
|
-
functionTrigger = triggerShape.functionTrigger!.target!;
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
const computeModel = createComputeGraph(canvasModel);
|
|
190
|
-
const computeGraph = computeModel.root;
|
|
191
|
-
|
|
192
|
-
invariant(functionTrigger);
|
|
193
|
-
functionTrigger.function = DXN.fromLocalObjectId(computeGraph.id).toString();
|
|
194
|
-
functionTrigger.meta ??= {};
|
|
195
|
-
const inputNode = computeModel.nodes.find((node) => node.type === NODE_INPUT)!;
|
|
196
|
-
functionTrigger.meta.computeNodeId = inputNode.id;
|
|
197
|
-
|
|
198
|
-
return space.db.add(
|
|
199
|
-
create(CanvasBoardType, {
|
|
200
|
-
computeGraph: makeRef(computeGraph),
|
|
201
|
-
layout: canvasModel.graph,
|
|
202
|
-
}),
|
|
203
|
-
);
|
|
204
|
-
});
|
|
205
|
-
cb?.(objects);
|
|
206
|
-
return objects;
|
|
207
|
-
},
|
|
208
|
-
],
|
|
209
139
|
]);
|
|
210
140
|
|
|
211
|
-
const position = (rect: { x: number; y: number; width?: number; height?: number }) => {
|
|
212
|
-
const snap = 32;
|
|
213
|
-
const [center, size] = rectToPoints({ width: 0, height: 0, ...rect });
|
|
214
|
-
const { x, y, width, height } = pointsToRect([pointMultiply(center, snap), pointMultiply(size, snap)]);
|
|
215
|
-
if (width && height) {
|
|
216
|
-
return { center: { x, y }, size: width && height ? { width, height } : undefined };
|
|
217
|
-
} else {
|
|
218
|
-
return { center: { x, y } };
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
|
|
222
141
|
export const createGenerator = <T extends BaseObject>(type: TypedObject<T>): ObjectGenerator<T> => {
|
|
223
142
|
return async (
|
|
224
143
|
space: Space,
|
|
@@ -12,13 +12,13 @@ import { DiagramType } from '@dxos/plugin-sketch/types';
|
|
|
12
12
|
import { useClient } from '@dxos/react-client';
|
|
13
13
|
import { getTypename, type Space } from '@dxos/react-client/echo';
|
|
14
14
|
import { IconButton, Input, Toolbar, useAsyncEffect } from '@dxos/react-ui';
|
|
15
|
-
import { CanvasBoardType } from '@dxos/react-ui-canvas-editor';
|
|
16
15
|
import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
17
16
|
import { Testing } from '@dxos/schema/testing';
|
|
18
17
|
import { jsonKeyReplacer, sortKeys } from '@dxos/util';
|
|
19
18
|
|
|
20
19
|
import { type ObjectGenerator, createGenerator, staticGenerators } from './ObjectGenerator';
|
|
21
20
|
import { SchemaTable } from './SchemaTable';
|
|
21
|
+
import { presets } from './presets';
|
|
22
22
|
|
|
23
23
|
export type SpaceGeneratorProps = {
|
|
24
24
|
space: Space;
|
|
@@ -27,19 +27,19 @@ export type SpaceGeneratorProps = {
|
|
|
27
27
|
|
|
28
28
|
export const SpaceGenerator = ({ space, onCreateObjects }: SpaceGeneratorProps) => {
|
|
29
29
|
const client = useClient();
|
|
30
|
-
const staticTypes = [DocumentType, DiagramType, SheetType, ComputeGraph
|
|
31
|
-
const mutableTypes = [Testing.OrgType, Testing.ProjectType, Testing.ContactType];
|
|
30
|
+
const staticTypes = [DocumentType, DiagramType, SheetType, ComputeGraph]; // TODO(burdon): Make extensible.
|
|
31
|
+
const mutableTypes = [Testing.OrgType, Testing.ProjectType, Testing.ContactType, Testing.EmailType];
|
|
32
32
|
const [count, setCount] = useState(1);
|
|
33
33
|
const [info, setInfo] = useState<any>({});
|
|
34
34
|
|
|
35
35
|
// Create type generators.
|
|
36
36
|
const typeMap = useMemo(() => {
|
|
37
|
-
client.addTypes(staticTypes);
|
|
37
|
+
client.addTypes([...staticTypes, ...presets.schemas]);
|
|
38
38
|
const mutableGenerators = new Map<string, ObjectGenerator<any>>(
|
|
39
|
-
mutableTypes.map((type) => [type.typename, createGenerator(type)]),
|
|
39
|
+
mutableTypes.map((type) => [type.typename, createGenerator(type as any)]),
|
|
40
40
|
);
|
|
41
41
|
|
|
42
|
-
return new Map([...staticGenerators, ...mutableGenerators]);
|
|
42
|
+
return new Map([...staticGenerators, ...presets.items, ...mutableGenerators]);
|
|
43
43
|
}, [client, mutableTypes]);
|
|
44
44
|
|
|
45
45
|
// Query space to get info.
|
|
@@ -106,6 +106,7 @@ export const SpaceGenerator = ({ space, onCreateObjects }: SpaceGeneratorProps)
|
|
|
106
106
|
|
|
107
107
|
<SchemaTable types={staticTypes} objects={info.objects} label='Static Types' onClick={handleCreateData} />
|
|
108
108
|
<SchemaTable types={mutableTypes} objects={info.objects} label='Mutable Types' onClick={handleCreateData} />
|
|
109
|
+
<SchemaTable types={presets.types} objects={info.objects} label='Presets' onClick={handleCreateData} />
|
|
109
110
|
|
|
110
111
|
<SyntaxHighlighter classNames='flex text-xs' language='json'>
|
|
111
112
|
{JSON.stringify({ space, ...info }, jsonKeyReplacer({ truncate: true }), 2)}
|
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type ComputeGraphModel, EmailTriggerOutput, NODE_INPUT } from '@dxos/conductor';
|
|
6
|
+
import { AST, ObjectId, S, toJsonSchema } from '@dxos/echo-schema';
|
|
7
|
+
import { FunctionTrigger, TriggerKind } from '@dxos/functions/types';
|
|
8
|
+
import { invariant } from '@dxos/invariant';
|
|
9
|
+
import { DXN, SpaceId } from '@dxos/keys';
|
|
10
|
+
import { create, makeRef } from '@dxos/live-object';
|
|
11
|
+
import { Filter, type Space } from '@dxos/react-client/echo';
|
|
12
|
+
import {
|
|
13
|
+
type ComputeShape,
|
|
14
|
+
createAppend,
|
|
15
|
+
createChat,
|
|
16
|
+
createComputeGraph,
|
|
17
|
+
createConstant,
|
|
18
|
+
createFunction,
|
|
19
|
+
createGpt,
|
|
20
|
+
createQueue,
|
|
21
|
+
createSurface,
|
|
22
|
+
createTemplate,
|
|
23
|
+
createText,
|
|
24
|
+
createTrigger,
|
|
25
|
+
} from '@dxos/react-ui-canvas-compute';
|
|
26
|
+
import {
|
|
27
|
+
CanvasBoardType,
|
|
28
|
+
CanvasGraphModel,
|
|
29
|
+
pointMultiply,
|
|
30
|
+
pointsToRect,
|
|
31
|
+
rectToPoints,
|
|
32
|
+
} from '@dxos/react-ui-canvas-editor';
|
|
33
|
+
import { TableType } from '@dxos/react-ui-table';
|
|
34
|
+
import { range } from '@dxos/util';
|
|
35
|
+
|
|
36
|
+
import { type ObjectGenerator } from './ObjectGenerator';
|
|
37
|
+
|
|
38
|
+
export enum PresetName {
|
|
39
|
+
EMAIL_TABLE = 'email-table',
|
|
40
|
+
GPT_QUEUE = 'webhook-gpt-queue',
|
|
41
|
+
CHAT_GPT = 'chat-gpt-text',
|
|
42
|
+
EMAIL_WITH_SUMMARY = 'email-gptSummary-table',
|
|
43
|
+
OBJECT_CHANGE_QUEUE = 'objectChange-queue',
|
|
44
|
+
FOREX_FUNCTION_CALL = 'forex-function-call',
|
|
45
|
+
DISCORD_MESSAGES = 'discord-messages',
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const presets = {
|
|
49
|
+
schemas: [CanvasBoardType, FunctionTrigger],
|
|
50
|
+
types: Object.values(PresetName).map((name) => ({ typename: name })),
|
|
51
|
+
items: [
|
|
52
|
+
[
|
|
53
|
+
PresetName.GPT_QUEUE,
|
|
54
|
+
async (space, n, cb) => {
|
|
55
|
+
const objects = range(n, () => {
|
|
56
|
+
const canvasModel = CanvasGraphModel.create<ComputeShape>();
|
|
57
|
+
|
|
58
|
+
let functionTrigger: FunctionTrigger | undefined;
|
|
59
|
+
canvasModel.builder.call((builder) => {
|
|
60
|
+
const gpt = canvasModel.createNode(createGpt(position({ x: 0, y: -14 })));
|
|
61
|
+
const triggerShape = createTrigger({ triggerKind: TriggerKind.Webhook, ...position({ x: -18, y: -2 }) });
|
|
62
|
+
const trigger = canvasModel.createNode(triggerShape);
|
|
63
|
+
const text = canvasModel.createNode(createText(position({ x: 19, y: 3, width: 10, height: 10 })));
|
|
64
|
+
const { queueId } = setupQueue(canvasModel);
|
|
65
|
+
const append = canvasModel.createNode(createAppend(position({ x: 10, y: 6 })));
|
|
66
|
+
|
|
67
|
+
builder
|
|
68
|
+
.createEdge({ source: trigger.id, target: gpt.id, input: 'prompt', output: 'bodyText' })
|
|
69
|
+
.createEdge({ source: gpt.id, target: text.id, output: 'text' })
|
|
70
|
+
.createEdge({ source: queueId.id, target: append.id, input: 'id' })
|
|
71
|
+
.createEdge({ source: gpt.id, target: append.id, output: 'messages', input: 'items' });
|
|
72
|
+
|
|
73
|
+
functionTrigger = triggerShape.functionTrigger!.target!;
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const computeModel = createComputeGraph(canvasModel);
|
|
77
|
+
|
|
78
|
+
attachTrigger(functionTrigger, computeModel);
|
|
79
|
+
|
|
80
|
+
return addToSpace(PresetName.GPT_QUEUE, space, canvasModel, computeModel);
|
|
81
|
+
});
|
|
82
|
+
cb?.(objects);
|
|
83
|
+
return objects;
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
|
|
87
|
+
[
|
|
88
|
+
PresetName.OBJECT_CHANGE_QUEUE,
|
|
89
|
+
async (space, n, cb) => {
|
|
90
|
+
const objects = range(n, () => {
|
|
91
|
+
const canvasModel = CanvasGraphModel.create<ComputeShape>();
|
|
92
|
+
|
|
93
|
+
const template = canvasModel.createNode(
|
|
94
|
+
createTemplate({
|
|
95
|
+
valueType: 'object',
|
|
96
|
+
...rawPosition({ centerX: -64, centerY: -79, width: 320, height: 320 }),
|
|
97
|
+
}),
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
let functionTrigger: FunctionTrigger | undefined;
|
|
101
|
+
canvasModel.builder.call((builder) => {
|
|
102
|
+
const triggerShape = createTrigger({
|
|
103
|
+
triggerKind: TriggerKind.Subscription,
|
|
104
|
+
...position({ x: -18, y: -2 }),
|
|
105
|
+
});
|
|
106
|
+
const trigger = canvasModel.createNode(triggerShape);
|
|
107
|
+
const { queueId } = setupQueue(canvasModel, {
|
|
108
|
+
queuePosition: { centerX: -80, centerY: 378, width: 320, height: 448 },
|
|
109
|
+
});
|
|
110
|
+
const append = canvasModel.createNode(
|
|
111
|
+
createAppend(rawPosition({ centerX: 320, centerY: 192, width: 128, height: 122 })),
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
builder
|
|
115
|
+
.createEdge({ source: queueId.id, target: append.id, input: 'id' })
|
|
116
|
+
.createEdge({ source: template.id, target: append.id, input: 'items' })
|
|
117
|
+
.createEdge({ source: trigger.id, target: template.id, output: 'type', input: 'type' })
|
|
118
|
+
.createEdge({
|
|
119
|
+
source: trigger.id,
|
|
120
|
+
target: template.id,
|
|
121
|
+
output: 'changedObjectId',
|
|
122
|
+
input: 'changedObjectId',
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
functionTrigger = triggerShape.functionTrigger!.target!;
|
|
126
|
+
const triggerSpec = functionTrigger.spec;
|
|
127
|
+
invariant(triggerSpec && triggerSpec.type === TriggerKind.Subscription, 'No trigger spec.');
|
|
128
|
+
triggerSpec.filter = { type: 'dxn:type:dxos.org/type/Chess' };
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const computeModel = createComputeGraph(canvasModel);
|
|
132
|
+
|
|
133
|
+
const templateComputeNode = computeModel.nodes.find((n) => n.id === template.node);
|
|
134
|
+
invariant(templateComputeNode, 'Template compute node was not created.');
|
|
135
|
+
templateComputeNode.value = ['{', ' "@type": "{{type}}",', ' "id": "{{changedObjectId}}"', '}'].join('\n');
|
|
136
|
+
templateComputeNode.inputSchema = toJsonSchema(S.Struct({ type: S.String, changedObjectId: S.String }));
|
|
137
|
+
|
|
138
|
+
attachTrigger(functionTrigger, computeModel);
|
|
139
|
+
|
|
140
|
+
return addToSpace(PresetName.OBJECT_CHANGE_QUEUE, space, canvasModel, computeModel);
|
|
141
|
+
});
|
|
142
|
+
cb?.(objects);
|
|
143
|
+
return objects;
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
|
|
147
|
+
[
|
|
148
|
+
PresetName.EMAIL_TABLE,
|
|
149
|
+
async (space, n, cb) => {
|
|
150
|
+
const objects = range(n, () => {
|
|
151
|
+
const canvasModel = CanvasGraphModel.create<ComputeShape>();
|
|
152
|
+
|
|
153
|
+
const results = space.db.query(Filter.schema(TableType)).runSync();
|
|
154
|
+
const emailTable = results.find((r) => r.object?.view?.target?.query?.type?.endsWith('Email'));
|
|
155
|
+
invariant(emailTable, 'Email table not found.');
|
|
156
|
+
|
|
157
|
+
const template = canvasModel.createNode(
|
|
158
|
+
createTemplate({
|
|
159
|
+
valueType: 'object',
|
|
160
|
+
...rawPosition({ centerX: -80, centerY: -64, width: 320, height: 320 }),
|
|
161
|
+
}),
|
|
162
|
+
);
|
|
163
|
+
const templateContent = ['{'];
|
|
164
|
+
|
|
165
|
+
let functionTrigger: FunctionTrigger | undefined;
|
|
166
|
+
canvasModel.builder.call((builder) => {
|
|
167
|
+
const triggerShape = createTrigger({ triggerKind: TriggerKind.Email, ...position({ x: -18, y: -2 }) });
|
|
168
|
+
const trigger = canvasModel.createNode(triggerShape);
|
|
169
|
+
|
|
170
|
+
const tableId = canvasModel.createNode(
|
|
171
|
+
createConstant({
|
|
172
|
+
value: DXN.fromLocalObjectId(emailTable.id).toString(),
|
|
173
|
+
...position({ x: -18, y: 5, width: 8, height: 6 }),
|
|
174
|
+
}),
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
const appendToTable = canvasModel.createNode(createAppend(position({ x: 10, y: 6 })));
|
|
178
|
+
|
|
179
|
+
const properties = AST.getPropertySignatures(EmailTriggerOutput.ast);
|
|
180
|
+
for (let i = 0; i < properties.length; i++) {
|
|
181
|
+
const propName = properties[i].name.toString();
|
|
182
|
+
builder.createEdge({ source: trigger.id, target: template.id, input: propName, output: propName });
|
|
183
|
+
templateContent.push(` "${propName}": "{{${propName}}}"` + (i === properties.length - 1 ? '' : ','));
|
|
184
|
+
}
|
|
185
|
+
templateContent.push('}');
|
|
186
|
+
|
|
187
|
+
builder
|
|
188
|
+
.createEdge({ source: tableId.id, target: appendToTable.id, input: 'id' })
|
|
189
|
+
.createEdge({ source: template.id, target: appendToTable.id, input: 'items' });
|
|
190
|
+
|
|
191
|
+
functionTrigger = triggerShape.functionTrigger!.target!;
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
const computeModel = createComputeGraph(canvasModel);
|
|
195
|
+
|
|
196
|
+
const templateComputeNode = computeModel.nodes.find((n) => n.id === template.node);
|
|
197
|
+
invariant(templateComputeNode, 'Template compute node was not created.');
|
|
198
|
+
templateComputeNode.value = templateContent.join('\n');
|
|
199
|
+
templateComputeNode.inputSchema = toJsonSchema(EmailTriggerOutput);
|
|
200
|
+
|
|
201
|
+
attachTrigger(functionTrigger, computeModel);
|
|
202
|
+
|
|
203
|
+
return addToSpace(PresetName.EMAIL_TABLE, space, canvasModel, computeModel);
|
|
204
|
+
});
|
|
205
|
+
cb?.(objects);
|
|
206
|
+
return objects;
|
|
207
|
+
},
|
|
208
|
+
],
|
|
209
|
+
|
|
210
|
+
[
|
|
211
|
+
PresetName.CHAT_GPT,
|
|
212
|
+
async (space, n, cb) => {
|
|
213
|
+
const objects = range(n, () => {
|
|
214
|
+
const canvasModel = CanvasGraphModel.create<ComputeShape>();
|
|
215
|
+
|
|
216
|
+
canvasModel.builder.call((builder) => {
|
|
217
|
+
const gpt = canvasModel.createNode(createGpt(position({ x: 0, y: -14 })));
|
|
218
|
+
const chat = canvasModel.createNode(createChat(position({ x: -18, y: -2 })));
|
|
219
|
+
const text = canvasModel.createNode(createText(position({ x: 19, y: 3, width: 10, height: 10 })));
|
|
220
|
+
const { queueId } = setupQueue(canvasModel);
|
|
221
|
+
|
|
222
|
+
const append = canvasModel.createNode(createAppend(position({ x: 10, y: 6 })));
|
|
223
|
+
|
|
224
|
+
builder
|
|
225
|
+
.createEdge({ source: chat.id, target: gpt.id, input: 'prompt' })
|
|
226
|
+
.createEdge({ source: gpt.id, target: text.id, output: 'text' })
|
|
227
|
+
.createEdge({ source: queueId.id, target: append.id, input: 'id' })
|
|
228
|
+
.createEdge({ source: gpt.id, target: append.id, output: 'messages', input: 'items' });
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
const computeModel = createComputeGraph(canvasModel);
|
|
232
|
+
|
|
233
|
+
return addToSpace(PresetName.CHAT_GPT, space, canvasModel, computeModel);
|
|
234
|
+
});
|
|
235
|
+
cb?.(objects);
|
|
236
|
+
return objects;
|
|
237
|
+
},
|
|
238
|
+
],
|
|
239
|
+
|
|
240
|
+
[
|
|
241
|
+
PresetName.EMAIL_WITH_SUMMARY,
|
|
242
|
+
async (space, n, cb) => {
|
|
243
|
+
const objects = range(n, () => {
|
|
244
|
+
const canvasModel = CanvasGraphModel.create<ComputeShape>();
|
|
245
|
+
|
|
246
|
+
const results = space.db.query(Filter.schema(TableType)).runSync();
|
|
247
|
+
const emailTable = results.find((r) => r.object?.view?.target?.query?.type?.endsWith('Email'));
|
|
248
|
+
invariant(emailTable, 'Email table not found.');
|
|
249
|
+
|
|
250
|
+
const template = canvasModel.createNode(
|
|
251
|
+
createTemplate({
|
|
252
|
+
valueType: 'object',
|
|
253
|
+
...rawPosition({ centerX: 192, centerY: -176, width: 320, height: 320 }),
|
|
254
|
+
}),
|
|
255
|
+
);
|
|
256
|
+
const templateContent = ['{'];
|
|
257
|
+
|
|
258
|
+
let functionTrigger: FunctionTrigger | undefined;
|
|
259
|
+
canvasModel.builder.call((builder) => {
|
|
260
|
+
const gpt = canvasModel.createNode(
|
|
261
|
+
createGpt(rawPosition({ centerX: -400, centerY: -112, width: 256, height: 202 })),
|
|
262
|
+
);
|
|
263
|
+
const systemPrompt = canvasModel.createNode(
|
|
264
|
+
createConstant({
|
|
265
|
+
value: "use one word to describe content category. don't write anything else",
|
|
266
|
+
...rawPosition({ centerX: -800, centerY: -160, width: 192, height: 128 }),
|
|
267
|
+
}),
|
|
268
|
+
);
|
|
269
|
+
const triggerShape = createTrigger({
|
|
270
|
+
triggerKind: TriggerKind.Email,
|
|
271
|
+
...rawPosition({ centerX: -736, centerY: -384, width: 182, height: 192 }),
|
|
272
|
+
});
|
|
273
|
+
const trigger = canvasModel.createNode(triggerShape);
|
|
274
|
+
|
|
275
|
+
const { queueId } = setupQueue(canvasModel, {
|
|
276
|
+
idPosition: { centerX: -720, centerY: 224, width: 192, height: 256 },
|
|
277
|
+
queuePosition: { centerX: -144, centerY: 416, width: 320, height: 448 },
|
|
278
|
+
});
|
|
279
|
+
const appendToQueue = canvasModel.createNode(
|
|
280
|
+
createAppend(rawPosition({ centerX: -80, centerY: 96, width: 122, height: 128 })),
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
const tableId = canvasModel.createNode(
|
|
284
|
+
createConstant({
|
|
285
|
+
value: DXN.fromLocalObjectId(emailTable.id).toString(),
|
|
286
|
+
...rawPosition({ centerX: -112, centerY: -544, width: 192, height: 256 }),
|
|
287
|
+
}),
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
const appendToTable = canvasModel.createNode(
|
|
291
|
+
createAppend(rawPosition({ centerX: 560, centerY: -416, width: 128, height: 122 })),
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
templateContent.push(' "category": "{{text}}",');
|
|
295
|
+
builder.createEdge({ source: gpt.id, target: template.id, input: 'text', output: 'text' });
|
|
296
|
+
|
|
297
|
+
const properties = AST.getPropertySignatures(EmailTriggerOutput.ast);
|
|
298
|
+
for (let i = 0; i < properties.length; i++) {
|
|
299
|
+
const propName = properties[i].name.toString();
|
|
300
|
+
builder.createEdge({ source: trigger.id, target: template.id, input: propName, output: propName });
|
|
301
|
+
templateContent.push(` "${propName}": "{{${propName}}}"` + (i === properties.length - 1 ? '' : ','));
|
|
302
|
+
}
|
|
303
|
+
templateContent.push('}');
|
|
304
|
+
|
|
305
|
+
builder
|
|
306
|
+
.createEdge({ source: tableId.id, target: appendToTable.id, input: 'id' })
|
|
307
|
+
.createEdge({ source: queueId.id, target: appendToQueue.id, input: 'id' })
|
|
308
|
+
.createEdge({ source: gpt.id, target: appendToQueue.id, output: 'messages', input: 'items' })
|
|
309
|
+
.createEdge({ source: systemPrompt.id, target: gpt.id, input: 'systemPrompt' })
|
|
310
|
+
.createEdge({ source: trigger.id, target: gpt.id, input: 'prompt', output: 'body' })
|
|
311
|
+
.createEdge({ source: template.id, target: appendToTable.id, input: 'items' });
|
|
312
|
+
|
|
313
|
+
functionTrigger = triggerShape.functionTrigger!.target!;
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
const computeModel = createComputeGraph(canvasModel);
|
|
317
|
+
|
|
318
|
+
const templateComputeNode = computeModel.nodes.find((n) => n.id === template.node);
|
|
319
|
+
invariant(templateComputeNode, 'Template compute node was not created.');
|
|
320
|
+
templateComputeNode.value = templateContent.join('\n');
|
|
321
|
+
const extendedSchema = S.extend(EmailTriggerOutput, S.Struct({ text: S.String }));
|
|
322
|
+
templateComputeNode.inputSchema = toJsonSchema(extendedSchema);
|
|
323
|
+
|
|
324
|
+
attachTrigger(functionTrigger, computeModel);
|
|
325
|
+
|
|
326
|
+
return addToSpace(PresetName.EMAIL_WITH_SUMMARY, space, canvasModel, computeModel);
|
|
327
|
+
});
|
|
328
|
+
cb?.(objects);
|
|
329
|
+
return objects;
|
|
330
|
+
},
|
|
331
|
+
],
|
|
332
|
+
[
|
|
333
|
+
PresetName.FOREX_FUNCTION_CALL,
|
|
334
|
+
async (space, n, cb) => {
|
|
335
|
+
const objects = range(n, () => {
|
|
336
|
+
const canvasModel = CanvasGraphModel.create<ComputeShape>();
|
|
337
|
+
|
|
338
|
+
canvasModel.builder.call((builder) => {
|
|
339
|
+
const sourceCurrency = canvasModel.createNode(
|
|
340
|
+
createConstant({ value: 'USD', ...position({ x: -10, y: -5 }) }),
|
|
341
|
+
);
|
|
342
|
+
const targetCurrency = canvasModel.createNode(
|
|
343
|
+
createConstant({ value: 'EUR', ...position({ x: -10, y: 5 }) }),
|
|
344
|
+
);
|
|
345
|
+
const converter = canvasModel.createNode(createFunction(position({ x: 0, y: 0 })));
|
|
346
|
+
const view = canvasModel.createNode(createSurface(position({ x: 12, y: 0 })));
|
|
347
|
+
|
|
348
|
+
builder
|
|
349
|
+
.createEdge({ source: sourceCurrency.id, target: converter.id, input: 'from' })
|
|
350
|
+
.createEdge({ source: targetCurrency.id, target: converter.id, input: 'to' })
|
|
351
|
+
.createEdge({ source: converter.id, target: view.id, output: 'rate' });
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
const computeModel = createComputeGraph(canvasModel);
|
|
355
|
+
|
|
356
|
+
return addToSpace(PresetName.FOREX_FUNCTION_CALL, space, canvasModel, computeModel);
|
|
357
|
+
});
|
|
358
|
+
cb?.(objects);
|
|
359
|
+
return objects;
|
|
360
|
+
},
|
|
361
|
+
],
|
|
362
|
+
[
|
|
363
|
+
PresetName.DISCORD_MESSAGES,
|
|
364
|
+
async (space, n, cb) => {
|
|
365
|
+
const objects = range(n, () => {
|
|
366
|
+
const canvasModel = CanvasGraphModel.create<ComputeShape>();
|
|
367
|
+
|
|
368
|
+
canvasModel.builder.call((builder) => {
|
|
369
|
+
// DXOS general channel.
|
|
370
|
+
const channelId = canvasModel.createNode(
|
|
371
|
+
createConstant({ value: '837138313172353098', ...position({ x: -10, y: -5 }) }),
|
|
372
|
+
);
|
|
373
|
+
const queueId = canvasModel.createNode(
|
|
374
|
+
createConstant({
|
|
375
|
+
value: new DXN(DXN.kind.QUEUE, ['data', SpaceId.random(), ObjectId.random()]).toString(),
|
|
376
|
+
...position({ x: -10, y: 5 }),
|
|
377
|
+
}),
|
|
378
|
+
);
|
|
379
|
+
const converter = canvasModel.createNode(createFunction(position({ x: 0, y: 0 })));
|
|
380
|
+
const view = canvasModel.createNode(createText(position({ x: 12, y: 0 })));
|
|
381
|
+
const queue = canvasModel.createNode(createQueue(position({ x: 0, y: 12 })));
|
|
382
|
+
|
|
383
|
+
builder
|
|
384
|
+
.createEdge({ source: queueId.id, target: converter.id, input: 'queueId' })
|
|
385
|
+
.createEdge({ source: channelId.id, target: converter.id, input: 'channelId' })
|
|
386
|
+
.createEdge({ source: converter.id, target: view.id, output: 'newMessages' })
|
|
387
|
+
.createEdge({ source: queueId.id, target: queue.id, input: 'input' });
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
const computeModel = createComputeGraph(canvasModel);
|
|
391
|
+
|
|
392
|
+
return addToSpace(PresetName.DISCORD_MESSAGES, space, canvasModel, computeModel);
|
|
393
|
+
});
|
|
394
|
+
cb?.(objects);
|
|
395
|
+
return objects;
|
|
396
|
+
},
|
|
397
|
+
],
|
|
398
|
+
] as [PresetName, ObjectGenerator<any>][],
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
const addToSpace = (name: string, space: Space, canvas: CanvasGraphModel, compute: ComputeGraphModel) => {
|
|
402
|
+
return space.db.add(
|
|
403
|
+
create(CanvasBoardType, {
|
|
404
|
+
name,
|
|
405
|
+
computeGraph: makeRef(compute.root),
|
|
406
|
+
layout: canvas.graph,
|
|
407
|
+
}),
|
|
408
|
+
);
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
const setupQueue = (
|
|
412
|
+
canvasModel: CanvasGraphModel,
|
|
413
|
+
args?: { idPosition?: RawPositionInput; queuePosition?: RawPositionInput },
|
|
414
|
+
) => {
|
|
415
|
+
const queueId = canvasModel.createNode(
|
|
416
|
+
createConstant({
|
|
417
|
+
value: new DXN(DXN.kind.QUEUE, ['data', SpaceId.random(), ObjectId.random()]).toString(),
|
|
418
|
+
...(args?.idPosition ? rawPosition(args.idPosition) : position({ x: -18, y: 5, width: 8, height: 6 })),
|
|
419
|
+
}),
|
|
420
|
+
);
|
|
421
|
+
const queue = canvasModel.createNode(
|
|
422
|
+
createQueue(
|
|
423
|
+
args?.queuePosition ? rawPosition(args.queuePosition) : position({ x: -3, y: 3, width: 14, height: 10 }),
|
|
424
|
+
),
|
|
425
|
+
);
|
|
426
|
+
canvasModel.createEdge({ source: queueId.id, target: queue.id });
|
|
427
|
+
return { queue, queueId };
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
const attachTrigger = (functionTrigger: FunctionTrigger | undefined, computeModel: ComputeGraphModel) => {
|
|
431
|
+
invariant(functionTrigger);
|
|
432
|
+
functionTrigger.function = DXN.fromLocalObjectId(computeModel.root.id).toString();
|
|
433
|
+
functionTrigger.meta ??= {};
|
|
434
|
+
const inputNode = computeModel.nodes.find((node) => node.type === NODE_INPUT)!;
|
|
435
|
+
functionTrigger.meta.computeNodeId = inputNode.id;
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
type RawPositionInput = { centerX: number; centerY: number; width: number; height: number };
|
|
439
|
+
|
|
440
|
+
const rawPosition = (args: RawPositionInput) => {
|
|
441
|
+
return { center: { x: args.centerX, y: args.centerY }, size: { width: args.width, height: args.height } };
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
const position = (rect: { x: number; y: number; width?: number; height?: number }) => {
|
|
445
|
+
const snap = 32;
|
|
446
|
+
const [center, size] = rectToPoints({ width: 0, height: 0, ...rect });
|
|
447
|
+
const { x, y, width, height } = pointsToRect([pointMultiply(center, snap), pointMultiply(size, snap)]);
|
|
448
|
+
if (width && height) {
|
|
449
|
+
return { center: { x, y }, size: width && height ? { width, height } : undefined };
|
|
450
|
+
} else {
|
|
451
|
+
return { center: { x, y } };
|
|
452
|
+
}
|
|
453
|
+
};
|
package/src/meta.ts
CHANGED
|
@@ -9,8 +9,10 @@ export const DEBUG_PLUGIN = 'dxos.org/plugin/debug';
|
|
|
9
9
|
export const meta = {
|
|
10
10
|
id: DEBUG_PLUGIN,
|
|
11
11
|
name: 'Debug',
|
|
12
|
-
description:
|
|
12
|
+
description:
|
|
13
|
+
'The debug plugin is useful for troubleshooting inside of Composer. You can also use the Debug plugin to create test data inside of sheets or tables or explore pre-built automations. Non-technical users will likely not spend much time here, but this plugin is invaluable for developers and technical users.',
|
|
13
14
|
icon: 'ph--bug--regular',
|
|
14
15
|
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-debug',
|
|
15
16
|
tags: ['experimental'],
|
|
17
|
+
screenshots: ['https://dxos.network/plugin-details-debug-dark.png'],
|
|
16
18
|
} satisfies PluginMeta;
|