@dxos/plugin-debug 0.7.4 → 0.7.5-labs.071a3e2

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.
Files changed (81) hide show
  1. package/dist/lib/browser/{DebugApp-HCHR6GKO.mjs → DebugApp-LQHFFK3Y.mjs} +4 -2
  2. package/dist/lib/browser/{DebugApp-HCHR6GKO.mjs.map → DebugApp-LQHFFK3Y.mjs.map} +3 -3
  3. package/dist/lib/browser/{DebugSpace-DHKEAMIC.mjs → DebugSpace-4JHYA7FG.mjs} +7 -6
  4. package/dist/lib/browser/DebugSpace-4JHYA7FG.mjs.map +7 -0
  5. package/dist/lib/browser/SpaceGenerator-4VO7E5P2.mjs +846 -0
  6. package/dist/lib/browser/SpaceGenerator-4VO7E5P2.mjs.map +7 -0
  7. package/dist/lib/browser/app-graph-builder-KRYWP5XD.mjs +181 -0
  8. package/dist/lib/browser/app-graph-builder-KRYWP5XD.mjs.map +7 -0
  9. package/dist/lib/browser/chunk-EF3UVAVI.mjs +21 -0
  10. package/dist/lib/browser/chunk-EF3UVAVI.mjs.map +7 -0
  11. package/dist/lib/browser/{chunk-LZEK532R.mjs → chunk-P7GHHMDB.mjs} +1 -11
  12. package/dist/lib/browser/chunk-P7GHHMDB.mjs.map +7 -0
  13. package/dist/lib/browser/index.mjs +60 -737
  14. package/dist/lib/browser/index.mjs.map +4 -4
  15. package/dist/lib/browser/meta.json +1 -1
  16. package/dist/lib/browser/react-surface-ZRQ4TPNG.mjs +484 -0
  17. package/dist/lib/browser/react-surface-ZRQ4TPNG.mjs.map +7 -0
  18. package/dist/lib/browser/settings-OIMSBZUC.mjs +25 -0
  19. package/dist/lib/browser/settings-OIMSBZUC.mjs.map +7 -0
  20. package/dist/types/src/DebugPlugin.d.ts +1 -2
  21. package/dist/types/src/DebugPlugin.d.ts.map +1 -1
  22. package/dist/types/src/capabilities/app-graph-builder.d.ts +181 -0
  23. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -0
  24. package/dist/types/src/capabilities/index.d.ts +180 -0
  25. package/dist/types/src/capabilities/index.d.ts.map +1 -0
  26. package/dist/types/src/capabilities/react-surface.d.ts +4 -0
  27. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
  28. package/dist/types/src/capabilities/settings.d.ts +4 -0
  29. package/dist/types/src/capabilities/settings.d.ts.map +1 -0
  30. package/dist/types/src/components/DebugObjectPanel.d.ts.map +1 -1
  31. package/dist/types/src/components/DebugSettings.d.ts.map +1 -1
  32. package/dist/types/src/components/DebugSpace/DebugSpace.stories.d.ts.map +1 -1
  33. package/dist/types/src/components/DebugSpace/ObjectCreator.stories.d.ts.map +1 -1
  34. package/dist/types/src/components/DebugStatus.d.ts.map +1 -1
  35. package/dist/types/src/components/SpaceGenerator/ObjectGenerator.d.ts +2 -2
  36. package/dist/types/src/components/SpaceGenerator/ObjectGenerator.d.ts.map +1 -1
  37. package/dist/types/src/components/SpaceGenerator/SpaceGenerator.d.ts.map +1 -1
  38. package/dist/types/src/components/SpaceGenerator/draw-util.d.ts.map +1 -1
  39. package/dist/types/src/components/SpaceGenerator/presets.d.ts +17 -0
  40. package/dist/types/src/components/SpaceGenerator/presets.d.ts.map +1 -0
  41. package/dist/types/src/components/Wireframe.d.ts +2 -1
  42. package/dist/types/src/components/Wireframe.d.ts.map +1 -1
  43. package/dist/types/src/index.d.ts +1 -2
  44. package/dist/types/src/index.d.ts.map +1 -1
  45. package/dist/types/src/meta.d.ts +2 -2
  46. package/dist/types/src/meta.d.ts.map +1 -1
  47. package/dist/types/src/types.d.ts +0 -6
  48. package/dist/types/src/types.d.ts.map +1 -1
  49. package/dist/types/tsconfig.tsbuildinfo +1 -0
  50. package/package.json +49 -51
  51. package/src/DebugPlugin.tsx +55 -381
  52. package/src/capabilities/app-graph-builder.ts +180 -0
  53. package/src/capabilities/index.ts +9 -0
  54. package/src/capabilities/react-surface.tsx +130 -0
  55. package/src/capabilities/settings.ts +18 -0
  56. package/src/components/DebugApp/DebugApp.tsx +1 -1
  57. package/src/components/DebugObjectPanel.tsx +17 -5
  58. package/src/components/DebugSettings.tsx +11 -13
  59. package/src/components/DebugSpace/DebugSpace.stories.tsx +4 -3
  60. package/src/components/DebugSpace/DebugSpace.tsx +1 -1
  61. package/src/components/DebugSpace/ObjectCreator.stories.tsx +4 -3
  62. package/src/components/DebugStatus.tsx +17 -27
  63. package/src/components/SpaceGenerator/ObjectGenerator.tsx +45 -18
  64. package/src/components/SpaceGenerator/SpaceGenerator.tsx +11 -8
  65. package/src/components/SpaceGenerator/draw-util.ts +7 -6
  66. package/src/components/SpaceGenerator/presets.ts +322 -0
  67. package/src/components/Wireframe.tsx +2 -2
  68. package/src/index.ts +1 -4
  69. package/src/meta.ts +4 -2
  70. package/src/types.ts +0 -22
  71. package/dist/lib/browser/DebugSpace-DHKEAMIC.mjs.map +0 -7
  72. package/dist/lib/browser/SpaceGenerator-BQ3645OS.mjs +0 -273
  73. package/dist/lib/browser/SpaceGenerator-BQ3645OS.mjs.map +0 -7
  74. package/dist/lib/browser/chunk-CAENAAHY.mjs +0 -18
  75. package/dist/lib/browser/chunk-CAENAAHY.mjs.map +0 -7
  76. package/dist/lib/browser/chunk-LZEK532R.mjs.map +0 -7
  77. package/dist/lib/browser/meta.mjs +0 -9
  78. package/dist/lib/browser/meta.mjs.map +0 -7
  79. package/dist/types/src/components/DebugSurface.d.ts +0 -9
  80. package/dist/types/src/components/DebugSurface.d.ts.map +0 -1
  81. package/src/components/DebugSurface.tsx +0 -55
@@ -2,17 +2,19 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { type AbstractSchema, type BaseObject } from '@dxos/echo-schema';
6
- import { create, type ReactiveObject } from '@dxos/live-object';
7
- import { DocumentType, TextType } from '@dxos/plugin-markdown/types';
8
- import { addressToA1Notation, createSheet } from '@dxos/plugin-sheet';
9
- import { type CellValue } from '@dxos/plugin-sheet/types';
10
- import { SheetType } from '@dxos/plugin-sheet/types';
5
+ import { addressToA1Notation } from '@dxos/compute';
6
+ import { ComputeGraph, ComputeGraphModel, DEFAULT_OUTPUT, NODE_INPUT, NODE_OUTPUT } from '@dxos/conductor';
7
+ import { ObjectId, type BaseObject, type TypedObject } from '@dxos/echo-schema';
8
+ import { DXN, SpaceId } from '@dxos/keys';
9
+ import { create, makeRef, type ReactiveObject } from '@dxos/live-object';
10
+ import { DocumentType } from '@dxos/plugin-markdown/types';
11
+ import { createSheet } from '@dxos/plugin-sheet/types';
12
+ import { SheetType, type CellValue } from '@dxos/plugin-sheet/types';
11
13
  import { CanvasType, DiagramType } from '@dxos/plugin-sketch/types';
12
14
  import { faker } from '@dxos/random';
13
15
  import { Filter, type Space } from '@dxos/react-client/echo';
14
16
  import { TableType } from '@dxos/react-ui-table';
15
- import { createView } from '@dxos/schema';
17
+ import { createView, TextType } from '@dxos/schema';
16
18
  import { createAsyncGenerator, type ValueGenerator } from '@dxos/schema/testing';
17
19
  import { range } from '@dxos/util';
18
20
 
@@ -37,15 +39,13 @@ export const staticGenerators = new Map<string, ObjectGenerator<any>>([
37
39
  DocumentType.typename,
38
40
  async (space, n, cb) => {
39
41
  const objects = range(n).map(() => {
40
- const obj = space.db.add(
42
+ return space.db.add(
41
43
  create(DocumentType, {
42
44
  name: faker.commerce.productName(),
43
- content: create(TextType, { content: faker.lorem.sentences(5) }),
45
+ content: makeRef(create(TextType, { content: faker.lorem.sentences(5) })),
44
46
  threads: [],
45
47
  }),
46
48
  );
47
-
48
- return obj;
49
49
  });
50
50
 
51
51
  cb?.(objects);
@@ -60,7 +60,7 @@ export const staticGenerators = new Map<string, ObjectGenerator<any>>([
60
60
  const obj = space.db.add(
61
61
  create(DiagramType, {
62
62
  name: faker.commerce.productName(),
63
- canvas: create(CanvasType, { content: {} }),
63
+ canvas: makeRef(create(CanvasType, { content: {} })),
64
64
  }),
65
65
  );
66
66
 
@@ -109,30 +109,57 @@ export const staticGenerators = new Map<string, ObjectGenerator<any>>([
109
109
  return objects;
110
110
  },
111
111
  ],
112
+ [
113
+ ComputeGraph.typename,
114
+ async (space, n, cb) => {
115
+ const objects = range(n, () => {
116
+ const model = ComputeGraphModel.create();
117
+ model.builder
118
+ .createNode({ id: 'gpt-INPUT', type: NODE_INPUT })
119
+ .createNode({ id: 'gpt-GPT', type: 'gpt' })
120
+ .createNode({
121
+ id: 'gpt-QUEUE_ID',
122
+ type: 'constant',
123
+ value: new DXN(DXN.kind.QUEUE, ['data', SpaceId.random(), ObjectId.random()]).toString(),
124
+ })
125
+ .createNode({ id: 'gpt-APPEND', type: 'append' })
126
+ .createNode({ id: 'gpt-OUTPUT', type: NODE_OUTPUT })
127
+ .createEdge({ node: 'gpt-INPUT', property: 'prompt' }, { node: 'gpt-GPT', property: 'prompt' })
128
+ .createEdge({ node: 'gpt-GPT', property: 'text' }, { node: 'gpt-OUTPUT', property: 'text' })
129
+ .createEdge({ node: 'gpt-QUEUE_ID', property: DEFAULT_OUTPUT }, { node: 'gpt-APPEND', property: 'id' })
130
+ .createEdge({ node: 'gpt-GPT', property: 'messages' }, { node: 'gpt-APPEND', property: 'items' })
131
+ .createEdge({ node: 'gpt-QUEUE_ID', property: DEFAULT_OUTPUT }, { node: 'gpt-OUTPUT', property: 'queue' });
132
+
133
+ return space.db.add(model.root);
134
+ });
135
+ cb?.(objects);
136
+ return objects;
137
+ },
138
+ ],
112
139
  ]);
113
140
 
114
- export const createGenerator = <T extends BaseObject>(type: AbstractSchema<T>): ObjectGenerator<T> => {
141
+ export const createGenerator = <T extends BaseObject>(type: TypedObject<T>): ObjectGenerator<T> => {
115
142
  return async (
116
143
  space: Space,
117
144
  n: number,
118
145
  cb?: (objects: ReactiveObject<any>[]) => void,
119
146
  ): Promise<ReactiveObject<T>[]> => {
120
147
  // Find or create mutable schema.
121
- const mutableSchema = await space.db.schemaRegistry.query();
122
148
  const schema =
123
- mutableSchema.find((schema) => schema.typename === type.typename) ?? space.db.schemaRegistry.addSchema(type);
149
+ (await space.db.schemaRegistry.query({ typename: type.typename }).firstOrUndefined()) ??
150
+ (await space.db.schemaRegistry.register([type]))[0];
124
151
 
125
152
  // Create objects.
126
- const generate = createAsyncGenerator(generator, schema.schema, { db: space.db });
153
+ const generate = createAsyncGenerator(generator, schema.getSchemaSnapshot(), { db: space.db });
127
154
  const objects = await generate.createObjects(n);
128
155
 
129
156
  // Find or create table and view.
130
157
  const { objects: tables } = await space.db.query(Filter.schema(TableType)).run();
131
- const table = tables.find((table) => table.view?.query?.type === type.typename);
158
+ const table = tables.find((table) => table.view?.target?.query?.type === type.typename);
132
159
  if (!table) {
133
160
  const name = type.typename.split('/').pop() ?? type.typename;
134
161
  const view = createView({ name, typename: type.typename, jsonSchema: schema.jsonSchema });
135
- const table = space.db.add(create(TableType, { name, view }));
162
+ const table = space.db.add(create(TableType, { name, view: makeRef(view) }));
136
163
  cb?.([table]);
137
164
  }
138
165
 
@@ -4,6 +4,7 @@
4
4
 
5
5
  import React, { useCallback, useMemo, useState } from 'react';
6
6
 
7
+ import { ComputeGraph } from '@dxos/conductor';
7
8
  import { type ReactiveObject } from '@dxos/live-object';
8
9
  import { DocumentType } from '@dxos/plugin-markdown/types';
9
10
  import { SheetType } from '@dxos/plugin-sheet/types';
@@ -17,6 +18,7 @@ import { jsonKeyReplacer, sortKeys } from '@dxos/util';
17
18
 
18
19
  import { type ObjectGenerator, createGenerator, staticGenerators } from './ObjectGenerator';
19
20
  import { SchemaTable } from './SchemaTable';
21
+ import { presets } from './presets';
20
22
 
21
23
  export type SpaceGeneratorProps = {
22
24
  space: Space;
@@ -25,25 +27,25 @@ export type SpaceGeneratorProps = {
25
27
 
26
28
  export const SpaceGenerator = ({ space, onCreateObjects }: SpaceGeneratorProps) => {
27
29
  const client = useClient();
28
- const staticTypes = [DocumentType, DiagramType, SheetType]; // TODO(burdon): Make extensible.
29
- 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];
30
32
  const [count, setCount] = useState(1);
31
33
  const [info, setInfo] = useState<any>({});
32
34
 
33
35
  // Create type generators.
34
36
  const typeMap = useMemo(() => {
35
- client.addTypes(staticTypes);
37
+ client.addTypes([...staticTypes, ...presets.schemas]);
36
38
  const mutableGenerators = new Map<string, ObjectGenerator<any>>(
37
- mutableTypes.map((type) => [type.typename, createGenerator(type)]),
39
+ mutableTypes.map((type) => [type.typename, createGenerator(type as any)]),
38
40
  );
39
41
 
40
- return new Map([...staticGenerators, ...mutableGenerators]);
42
+ return new Map([...staticGenerators, ...presets.items, ...mutableGenerators]);
41
43
  }, [client, mutableTypes]);
42
44
 
43
45
  // Query space to get info.
44
46
  const updateInfo = async () => {
45
47
  // Create schema map.
46
- const mutableSchema = await space.db.schemaRegistry.query();
48
+ const echoSchema = await space.db.schemaRegistry.query().run();
47
49
  const staticSchema = space.db.graph.schemaRegistry.schemas;
48
50
 
49
51
  // Create object map.
@@ -62,7 +64,7 @@ export const SpaceGenerator = ({ space, onCreateObjects }: SpaceGeneratorProps)
62
64
  setInfo({
63
65
  schema: {
64
66
  static: staticSchema.length,
65
- mutable: mutableSchema.length,
67
+ mutable: echoSchema.length,
66
68
  },
67
69
  objects: objectMap,
68
70
  });
@@ -86,7 +88,7 @@ export const SpaceGenerator = ({ space, onCreateObjects }: SpaceGeneratorProps)
86
88
  <div role='none' className='flex flex-col divide-y divide-separator'>
87
89
  <Toolbar.Root classNames='p-1'>
88
90
  <IconButton icon='ph--arrow-clockwise--regular' iconOnly label='Refresh' onClick={updateInfo} />
89
- <Toolbar.Expander />
91
+ <Toolbar.Separator variant='gap' />
90
92
  <div className='flex'>
91
93
  <Input.Root>
92
94
  <Input.TextInput
@@ -104,6 +106,7 @@ export const SpaceGenerator = ({ space, onCreateObjects }: SpaceGeneratorProps)
104
106
 
105
107
  <SchemaTable types={staticTypes} objects={info.objects} label='Static Types' onClick={handleCreateData} />
106
108
  <SchemaTable types={mutableTypes} objects={info.objects} label='Mutable Types' onClick={handleCreateData} />
109
+ <SchemaTable types={presets.types} objects={info.objects} label='Presets' onClick={handleCreateData} />
107
110
 
108
111
  <SyntaxHighlighter classNames='flex text-xs' language='json'>
109
112
  {JSON.stringify({ space, ...info }, jsonKeyReplacer({ truncate: true }), 2)}
@@ -86,20 +86,21 @@ export const drawGraph = async (
86
86
  editor: Editor,
87
87
  graph: Graph<PlainObject, PlainObject>,
88
88
  ): Promise<SerializedStore<TLRecord>> => {
89
- const grid = 40;
89
+ const gridSize = 40;
90
90
  const nodeSize = 80;
91
91
 
92
- const snap = (n: number) => Math.round(n / grid) * grid;
92
+ const snap = (n: number) => Math.round(n / gridSize) * gridSize;
93
93
 
94
+ // TODO(burdon): Util.
94
95
  type Intersection<Types extends readonly unknown[]> = Types extends [infer First, ...infer Rest]
95
96
  ? First & Intersection<Rest>
96
97
  : unknown;
97
98
 
98
99
  const defaultOptions: Intersection<[D3ForceLayoutOptions, GridLayoutOptions, RadialLayoutOptions]> = {
99
100
  center: [0, 0],
100
- width: grid * 20,
101
- height: grid * 20,
102
- linkDistance: grid * 2,
101
+ width: gridSize * 20,
102
+ height: gridSize * 20,
103
+ linkDistance: gridSize * 2,
103
104
  nodeSize,
104
105
  nodeSpacing: nodeSize,
105
106
  preventOverlap: true,
@@ -129,7 +130,7 @@ export const drawGraph = async (
129
130
  layout = new RadialLayout({
130
131
  ...defaultOptions,
131
132
  focusNode: graph.getAllNodes()[0],
132
- unitRadius: grid * 2,
133
+ unitRadius: gridSize * 2,
133
134
  });
134
135
  }
135
136
  }
@@ -0,0 +1,322 @@
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
+ createGpt,
19
+ createQueue,
20
+ createTemplate,
21
+ createText,
22
+ createTrigger,
23
+ } from '@dxos/react-ui-canvas-compute';
24
+ import {
25
+ CanvasBoardType,
26
+ CanvasGraphModel,
27
+ pointMultiply,
28
+ pointsToRect,
29
+ rectToPoints,
30
+ } from '@dxos/react-ui-canvas-editor';
31
+ import { TableType } from '@dxos/react-ui-table';
32
+ import { range } from '@dxos/util';
33
+
34
+ import { type ObjectGenerator } from './ObjectGenerator';
35
+
36
+ export enum PresetName {
37
+ EMAIL_TABLE = 'email-table',
38
+ GPT_QUEUE = 'webhook-gpt-queue',
39
+ CHAT_GPT = 'chat-gpt-text',
40
+ EMAIL_WITH_SUMMARY = 'email-gptSummary-table',
41
+ }
42
+
43
+ export const presets = {
44
+ schemas: [CanvasBoardType, FunctionTrigger],
45
+ types: Object.values(PresetName).map((name) => ({ typename: name })),
46
+ items: [
47
+ [
48
+ PresetName.GPT_QUEUE,
49
+ async (space, n, cb) => {
50
+ const objects = range(n, () => {
51
+ const canvasModel = CanvasGraphModel.create<ComputeShape>();
52
+
53
+ let functionTrigger: FunctionTrigger | undefined;
54
+ canvasModel.builder.call((builder) => {
55
+ const gpt = canvasModel.createNode(createGpt(position({ x: 0, y: -14 })));
56
+ const triggerShape = createTrigger({ triggerKind: TriggerKind.Webhook, ...position({ x: -18, y: -2 }) });
57
+ const trigger = canvasModel.createNode(triggerShape);
58
+ const text = canvasModel.createNode(createText(position({ x: 19, y: 3, width: 10, height: 10 })));
59
+ const { queueId } = setupQueue(canvasModel);
60
+ const append = canvasModel.createNode(createAppend(position({ x: 10, y: 6 })));
61
+
62
+ builder
63
+ .createEdge({ source: trigger.id, target: gpt.id, input: 'prompt', output: 'body' })
64
+ .createEdge({ source: gpt.id, target: text.id, output: 'text' })
65
+ .createEdge({ source: queueId.id, target: append.id, input: 'id' })
66
+ .createEdge({ source: gpt.id, target: append.id, output: 'messages', input: 'items' });
67
+
68
+ functionTrigger = triggerShape.functionTrigger!.target!;
69
+ });
70
+
71
+ const computeModel = createComputeGraph(canvasModel);
72
+
73
+ attachTrigger(functionTrigger, computeModel);
74
+
75
+ return addToSpace(PresetName.GPT_QUEUE, space, canvasModel, computeModel);
76
+ });
77
+ cb?.(objects);
78
+ return objects;
79
+ },
80
+ ],
81
+
82
+ [
83
+ PresetName.EMAIL_TABLE,
84
+ async (space, n, cb) => {
85
+ const objects = range(n, () => {
86
+ const canvasModel = CanvasGraphModel.create<ComputeShape>();
87
+
88
+ const results = space.db.query(Filter.schema(TableType)).runSync();
89
+ const emailTable = results.find((r) => r.object?.view?.target?.query?.type?.endsWith('Email'));
90
+ invariant(emailTable, 'Email table not found.');
91
+
92
+ const template = canvasModel.createNode(
93
+ createTemplate({
94
+ valueType: 'object',
95
+ ...rawPosition({ centerX: -80, centerY: -64, width: 320, height: 320 }),
96
+ }),
97
+ );
98
+ const templateContent = ['{'];
99
+
100
+ let functionTrigger: FunctionTrigger | undefined;
101
+ canvasModel.builder.call((builder) => {
102
+ const triggerShape = createTrigger({ triggerKind: TriggerKind.Email, ...position({ x: -18, y: -2 }) });
103
+ const trigger = canvasModel.createNode(triggerShape);
104
+
105
+ const tableId = canvasModel.createNode(
106
+ createConstant({
107
+ value: DXN.fromLocalObjectId(emailTable.id).toString(),
108
+ ...position({ x: -18, y: 5, width: 8, height: 6 }),
109
+ }),
110
+ );
111
+
112
+ const appendToTable = canvasModel.createNode(createAppend(position({ x: 10, y: 6 })));
113
+
114
+ const properties = AST.getPropertySignatures(EmailTriggerOutput.ast);
115
+ for (let i = 0; i < properties.length; i++) {
116
+ const propName = properties[i].name.toString();
117
+ builder.createEdge({ source: trigger.id, target: template.id, input: propName, output: propName });
118
+ templateContent.push(` "${propName}": "{{${propName}}}"` + (i === properties.length - 1 ? '' : ','));
119
+ }
120
+ templateContent.push('}');
121
+
122
+ builder
123
+ .createEdge({ source: tableId.id, target: appendToTable.id, input: 'id' })
124
+ .createEdge({ source: template.id, target: appendToTable.id, input: 'items' });
125
+
126
+ functionTrigger = triggerShape.functionTrigger!.target!;
127
+ });
128
+
129
+ const computeModel = createComputeGraph(canvasModel);
130
+
131
+ const templateComputeNode = computeModel.nodes.find((n) => n.id === template.node);
132
+ invariant(templateComputeNode, 'Template compute node was not created.');
133
+ templateComputeNode.value = templateContent.join('\n');
134
+ templateComputeNode.inputSchema = toJsonSchema(EmailTriggerOutput);
135
+
136
+ attachTrigger(functionTrigger, computeModel);
137
+
138
+ return addToSpace(PresetName.EMAIL_TABLE, space, canvasModel, computeModel);
139
+ });
140
+ cb?.(objects);
141
+ return objects;
142
+ },
143
+ ],
144
+
145
+ [
146
+ PresetName.CHAT_GPT,
147
+ async (space, n, cb) => {
148
+ const objects = range(n, () => {
149
+ const canvasModel = CanvasGraphModel.create<ComputeShape>();
150
+
151
+ canvasModel.builder.call((builder) => {
152
+ const gpt = canvasModel.createNode(createGpt(position({ x: 0, y: -14 })));
153
+ const chat = canvasModel.createNode(createChat(position({ x: -18, y: -2 })));
154
+ const text = canvasModel.createNode(createText(position({ x: 19, y: 3, width: 10, height: 10 })));
155
+ const { queueId } = setupQueue(canvasModel);
156
+
157
+ const append = canvasModel.createNode(createAppend(position({ x: 10, y: 6 })));
158
+
159
+ builder
160
+ .createEdge({ source: chat.id, target: gpt.id, input: 'prompt' })
161
+ .createEdge({ source: gpt.id, target: text.id, output: 'text' })
162
+ .createEdge({ source: queueId.id, target: append.id, input: 'id' })
163
+ .createEdge({ source: gpt.id, target: append.id, output: 'messages', input: 'items' });
164
+ });
165
+
166
+ const computeModel = createComputeGraph(canvasModel);
167
+
168
+ return addToSpace(PresetName.CHAT_GPT, space, canvasModel, computeModel);
169
+ });
170
+ cb?.(objects);
171
+ return objects;
172
+ },
173
+ ],
174
+
175
+ [
176
+ PresetName.EMAIL_WITH_SUMMARY,
177
+ async (space, n, cb) => {
178
+ const objects = range(n, () => {
179
+ const canvasModel = CanvasGraphModel.create<ComputeShape>();
180
+
181
+ const results = space.db.query(Filter.schema(TableType)).runSync();
182
+ const emailTable = results.find((r) => r.object?.view?.target?.query?.type?.endsWith('Email'));
183
+ invariant(emailTable, 'Email table not found.');
184
+
185
+ const template = canvasModel.createNode(
186
+ createTemplate({
187
+ valueType: 'object',
188
+ ...rawPosition({ centerX: 192, centerY: -176, width: 320, height: 320 }),
189
+ }),
190
+ );
191
+ const templateContent = ['{'];
192
+
193
+ let functionTrigger: FunctionTrigger | undefined;
194
+ canvasModel.builder.call((builder) => {
195
+ const gpt = canvasModel.createNode(
196
+ createGpt(rawPosition({ centerX: -400, centerY: -112, width: 256, height: 202 })),
197
+ );
198
+ const systemPrompt = canvasModel.createNode(
199
+ createConstant({
200
+ value: "use one word to describe content category. don't write anything else",
201
+ ...rawPosition({ centerX: -800, centerY: -160, width: 192, height: 128 }),
202
+ }),
203
+ );
204
+ const triggerShape = createTrigger({
205
+ triggerKind: TriggerKind.Email,
206
+ ...rawPosition({ centerX: -736, centerY: -384, width: 182, height: 192 }),
207
+ });
208
+ const trigger = canvasModel.createNode(triggerShape);
209
+
210
+ const { queueId } = setupQueue(canvasModel, {
211
+ idPosition: { centerX: -720, centerY: 224, width: 192, height: 256 },
212
+ queuePosition: { centerX: -144, centerY: 416, width: 320, height: 448 },
213
+ });
214
+ const appendToQueue = canvasModel.createNode(
215
+ createAppend(rawPosition({ centerX: -80, centerY: 96, width: 122, height: 128 })),
216
+ );
217
+
218
+ const tableId = canvasModel.createNode(
219
+ createConstant({
220
+ value: DXN.fromLocalObjectId(emailTable.id).toString(),
221
+ ...rawPosition({ centerX: -112, centerY: -544, width: 192, height: 256 }),
222
+ }),
223
+ );
224
+
225
+ const appendToTable = canvasModel.createNode(
226
+ createAppend(rawPosition({ centerX: 560, centerY: -416, width: 128, height: 122 })),
227
+ );
228
+
229
+ templateContent.push(' "category": "{{text}}",');
230
+ builder.createEdge({ source: gpt.id, target: template.id, input: 'text', output: 'text' });
231
+
232
+ const properties = AST.getPropertySignatures(EmailTriggerOutput.ast);
233
+ for (let i = 0; i < properties.length; i++) {
234
+ const propName = properties[i].name.toString();
235
+ builder.createEdge({ source: trigger.id, target: template.id, input: propName, output: propName });
236
+ templateContent.push(` "${propName}": "{{${propName}}}"` + (i === properties.length - 1 ? '' : ','));
237
+ }
238
+ templateContent.push('}');
239
+
240
+ builder
241
+ .createEdge({ source: tableId.id, target: appendToTable.id, input: 'id' })
242
+ .createEdge({ source: queueId.id, target: appendToQueue.id, input: 'id' })
243
+ .createEdge({ source: gpt.id, target: appendToQueue.id, output: 'messages', input: 'items' })
244
+ .createEdge({ source: systemPrompt.id, target: gpt.id, input: 'systemPrompt' })
245
+ .createEdge({ source: trigger.id, target: gpt.id, input: 'prompt', output: 'body' })
246
+ .createEdge({ source: template.id, target: appendToTable.id, input: 'items' });
247
+
248
+ functionTrigger = triggerShape.functionTrigger!.target!;
249
+ });
250
+
251
+ const computeModel = createComputeGraph(canvasModel);
252
+
253
+ const templateComputeNode = computeModel.nodes.find((n) => n.id === template.node);
254
+ invariant(templateComputeNode, 'Template compute node was not created.');
255
+ templateComputeNode.value = templateContent.join('\n');
256
+ const extendedSchema = S.extend(EmailTriggerOutput, S.Struct({ text: S.String }));
257
+ templateComputeNode.inputSchema = toJsonSchema(extendedSchema);
258
+
259
+ attachTrigger(functionTrigger, computeModel);
260
+
261
+ return addToSpace(PresetName.EMAIL_WITH_SUMMARY, space, canvasModel, computeModel);
262
+ });
263
+ cb?.(objects);
264
+ return objects;
265
+ },
266
+ ],
267
+ ] as [PresetName, ObjectGenerator<any>][],
268
+ };
269
+
270
+ const addToSpace = (name: string, space: Space, canvas: CanvasGraphModel, compute: ComputeGraphModel) => {
271
+ return space.db.add(
272
+ create(CanvasBoardType, {
273
+ name,
274
+ computeGraph: makeRef(compute.root),
275
+ layout: canvas.graph,
276
+ }),
277
+ );
278
+ };
279
+
280
+ const setupQueue = (
281
+ canvasModel: CanvasGraphModel,
282
+ args?: { idPosition?: RawPositionInput; queuePosition?: RawPositionInput },
283
+ ) => {
284
+ const queueId = canvasModel.createNode(
285
+ createConstant({
286
+ value: new DXN(DXN.kind.QUEUE, ['data', SpaceId.random(), ObjectId.random()]).toString(),
287
+ ...(args?.idPosition ? rawPosition(args.idPosition) : position({ x: -18, y: 5, width: 8, height: 6 })),
288
+ }),
289
+ );
290
+ const queue = canvasModel.createNode(
291
+ createQueue(
292
+ args?.queuePosition ? rawPosition(args.queuePosition) : position({ x: -3, y: 3, width: 14, height: 10 }),
293
+ ),
294
+ );
295
+ canvasModel.createEdge({ source: queueId.id, target: queue.id });
296
+ return { queue, queueId };
297
+ };
298
+
299
+ const attachTrigger = (functionTrigger: FunctionTrigger | undefined, computeModel: ComputeGraphModel) => {
300
+ invariant(functionTrigger);
301
+ functionTrigger.function = DXN.fromLocalObjectId(computeModel.root.id).toString();
302
+ functionTrigger.meta ??= {};
303
+ const inputNode = computeModel.nodes.find((node) => node.type === NODE_INPUT)!;
304
+ functionTrigger.meta.computeNodeId = inputNode.id;
305
+ };
306
+
307
+ type RawPositionInput = { centerX: number; centerY: number; width: number; height: number };
308
+
309
+ const rawPosition = (args: RawPositionInput) => {
310
+ return { center: { x: args.centerX, y: args.centerY }, size: { width: args.width, height: args.height } };
311
+ };
312
+
313
+ const position = (rect: { x: number; y: number; width?: number; height?: number }) => {
314
+ const snap = 32;
315
+ const [center, size] = rectToPoints({ width: 0, height: 0, ...rect });
316
+ const { x, y, width, height } = pointsToRect([pointMultiply(center, snap), pointMultiply(size, snap)]);
317
+ if (width && height) {
318
+ return { center: { x, y }, size: width && height ? { width, height } : undefined };
319
+ } else {
320
+ return { center: { x, y } };
321
+ }
322
+ };
@@ -5,7 +5,7 @@
5
5
  import React from 'react';
6
6
  import { useResizeDetector } from 'react-resize-detector';
7
7
 
8
- import { fullyQualifiedId } from '@dxos/react-client/echo';
8
+ import { fullyQualifiedId, type ReactiveEchoObject } from '@dxos/react-client/echo';
9
9
  import { type ThemedClassName } from '@dxos/react-ui';
10
10
  import { useAttendableAttributes } from '@dxos/react-ui-attention';
11
11
  import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
@@ -14,7 +14,7 @@ import { mx } from '@dxos/react-ui-theme';
14
14
  // TODO(burdon): Create generic container with wireframe mode.
15
15
  export type WireframeProps = ThemedClassName<{
16
16
  label?: string;
17
- object?: any;
17
+ object: ReactiveEchoObject<any>;
18
18
  }>;
19
19
 
20
20
  // TODO(burdon): Make focusable and attendable with input.
package/src/index.ts CHANGED
@@ -2,8 +2,5 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { DebugPlugin } from './DebugPlugin';
6
-
7
5
  export * from './DebugPlugin';
8
-
9
- export default DebugPlugin;
6
+ export * from './meta';
package/src/meta.ts CHANGED
@@ -6,11 +6,13 @@ import { type PluginMeta } from '@dxos/app-framework';
6
6
 
7
7
  export const DEBUG_PLUGIN = 'dxos.org/plugin/debug';
8
8
 
9
- export default {
9
+ export const meta = {
10
10
  id: DEBUG_PLUGIN,
11
11
  name: 'Debug',
12
- description: 'DXOS debugging tools.',
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;
package/src/types.ts CHANGED
@@ -4,23 +4,8 @@
4
4
 
5
5
  import { type Context, createContext } from 'react';
6
6
 
7
- import type {
8
- GraphBuilderProvides,
9
- IntentResolverProvides,
10
- SettingsProvides,
11
- SurfaceProvides,
12
- TranslationsProvides,
13
- } from '@dxos/app-framework';
14
7
  import type { TimerCallback, TimerOptions } from '@dxos/async';
15
8
  import { S } from '@dxos/echo-schema';
16
- import { type PanelProvides } from '@dxos/plugin-deck/types';
17
-
18
- import { DEBUG_PLUGIN } from './meta';
19
-
20
- const DEBUG_ACTION = `${DEBUG_PLUGIN}/action`;
21
- export enum DebugAction {
22
- OPEN_DEVTOOLS = `${DEBUG_ACTION}/open-devtools`,
23
- }
24
9
 
25
10
  export type DebugContextType = {
26
11
  running: boolean;
@@ -43,10 +28,3 @@ export const DebugSettingsSchema = S.mutable(
43
28
  );
44
29
 
45
30
  export interface DebugSettingsProps extends S.Schema.Type<typeof DebugSettingsSchema> {}
46
-
47
- export type DebugPluginProvides = SurfaceProvides &
48
- IntentResolverProvides &
49
- GraphBuilderProvides &
50
- SettingsProvides<DebugSettingsProps> &
51
- TranslationsProvides &
52
- PanelProvides;