@dxos/assistant 0.7.4-df37807

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 (128) hide show
  1. package/LICENSE +8 -0
  2. package/README.md +24 -0
  3. package/dist/lib/browser/chunk-AKP45LQH.mjs +1394 -0
  4. package/dist/lib/browser/chunk-AKP45LQH.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +71 -0
  6. package/dist/lib/browser/index.mjs.map +7 -0
  7. package/dist/lib/browser/meta.json +1 -0
  8. package/dist/lib/browser/testing/index.mjs +601 -0
  9. package/dist/lib/browser/testing/index.mjs.map +7 -0
  10. package/dist/lib/node/chunk-G6CGWEMO.cjs +1418 -0
  11. package/dist/lib/node/chunk-G6CGWEMO.cjs.map +7 -0
  12. package/dist/lib/node/index.cjs +93 -0
  13. package/dist/lib/node/index.cjs.map +7 -0
  14. package/dist/lib/node/meta.json +1 -0
  15. package/dist/lib/node/testing/index.cjs +619 -0
  16. package/dist/lib/node/testing/index.cjs.map +7 -0
  17. package/dist/lib/node-esm/chunk-WUPUPEFB.mjs +1396 -0
  18. package/dist/lib/node-esm/chunk-WUPUPEFB.mjs.map +7 -0
  19. package/dist/lib/node-esm/index.mjs +72 -0
  20. package/dist/lib/node-esm/index.mjs.map +7 -0
  21. package/dist/lib/node-esm/meta.json +1 -0
  22. package/dist/lib/node-esm/testing/index.mjs +602 -0
  23. package/dist/lib/node-esm/testing/index.mjs.map +7 -0
  24. package/dist/types/src/ai-service/client.d.ts +48 -0
  25. package/dist/types/src/ai-service/client.d.ts.map +1 -0
  26. package/dist/types/src/ai-service/client.test.d.ts +2 -0
  27. package/dist/types/src/ai-service/client.test.d.ts.map +1 -0
  28. package/dist/types/src/ai-service/index.d.ts +3 -0
  29. package/dist/types/src/ai-service/index.d.ts.map +1 -0
  30. package/dist/types/src/ai-service/schema.d.ts +296 -0
  31. package/dist/types/src/ai-service/schema.d.ts.map +1 -0
  32. package/dist/types/src/ai-service/sse.d.ts +34 -0
  33. package/dist/types/src/ai-service/sse.d.ts.map +1 -0
  34. package/dist/types/src/bin/chat.d.ts +2 -0
  35. package/dist/types/src/bin/chat.d.ts.map +1 -0
  36. package/dist/types/src/conversation/conversation.d.ts +23 -0
  37. package/dist/types/src/conversation/conversation.d.ts.map +1 -0
  38. package/dist/types/src/conversation/conversation.test.d.ts +2 -0
  39. package/dist/types/src/conversation/conversation.test.d.ts.map +1 -0
  40. package/dist/types/src/conversation/index.d.ts +3 -0
  41. package/dist/types/src/conversation/index.d.ts.map +1 -0
  42. package/dist/types/src/conversation/types.d.ts +48 -0
  43. package/dist/types/src/conversation/types.d.ts.map +1 -0
  44. package/dist/types/src/cypher/ast.d.ts +56 -0
  45. package/dist/types/src/cypher/ast.d.ts.map +1 -0
  46. package/dist/types/src/cypher/combinators.d.ts +14 -0
  47. package/dist/types/src/cypher/combinators.d.ts.map +1 -0
  48. package/dist/types/src/cypher/combinators.test.d.ts +2 -0
  49. package/dist/types/src/cypher/combinators.test.d.ts.map +1 -0
  50. package/dist/types/src/cypher/echo-data-source.d.ts +16 -0
  51. package/dist/types/src/cypher/echo-data-source.d.ts.map +1 -0
  52. package/dist/types/src/cypher/execution-plan.d.ts +49 -0
  53. package/dist/types/src/cypher/execution-plan.d.ts.map +1 -0
  54. package/dist/types/src/cypher/execution-plan.test.d.ts +2 -0
  55. package/dist/types/src/cypher/execution-plan.test.d.ts.map +1 -0
  56. package/dist/types/src/cypher/index.d.ts +5 -0
  57. package/dist/types/src/cypher/index.d.ts.map +1 -0
  58. package/dist/types/src/cypher/parjs.d.ts +4 -0
  59. package/dist/types/src/cypher/parjs.d.ts.map +1 -0
  60. package/dist/types/src/cypher/parser.d.ts +6 -0
  61. package/dist/types/src/cypher/parser.d.ts.map +1 -0
  62. package/dist/types/src/cypher/query-executor.d.ts +26 -0
  63. package/dist/types/src/cypher/query-executor.d.ts.map +1 -0
  64. package/dist/types/src/cypher/query-executor.test.d.ts +2 -0
  65. package/dist/types/src/cypher/query-executor.test.d.ts.map +1 -0
  66. package/dist/types/src/cypher/schema.d.ts +12 -0
  67. package/dist/types/src/cypher/schema.d.ts.map +1 -0
  68. package/dist/types/src/cypher/schema.test.d.ts +2 -0
  69. package/dist/types/src/cypher/schema.test.d.ts.map +1 -0
  70. package/dist/types/src/index.d.ts +4 -0
  71. package/dist/types/src/index.d.ts.map +1 -0
  72. package/dist/types/src/sanity.test.d.ts +2 -0
  73. package/dist/types/src/sanity.test.d.ts.map +1 -0
  74. package/dist/types/src/testing/index.d.ts +5 -0
  75. package/dist/types/src/testing/index.d.ts.map +1 -0
  76. package/dist/types/src/testing/logger.d.ts +12 -0
  77. package/dist/types/src/testing/logger.d.ts.map +1 -0
  78. package/dist/types/src/testing/object-extraction.test.d.ts +1 -0
  79. package/dist/types/src/testing/object-extraction.test.d.ts.map +1 -0
  80. package/dist/types/src/testing/query-promts.d.ts +5 -0
  81. package/dist/types/src/testing/query-promts.d.ts.map +1 -0
  82. package/dist/types/src/testing/query.test.d.ts +2 -0
  83. package/dist/types/src/testing/query.test.d.ts.map +1 -0
  84. package/dist/types/src/testing/test-data.d.ts +29 -0
  85. package/dist/types/src/testing/test-data.d.ts.map +1 -0
  86. package/dist/types/src/testing/test-schema.d.ts +50 -0
  87. package/dist/types/src/testing/test-schema.d.ts.map +1 -0
  88. package/dist/types/src/util/index.d.ts +2 -0
  89. package/dist/types/src/util/index.d.ts.map +1 -0
  90. package/dist/types/src/util/trim.d.ts +5 -0
  91. package/dist/types/src/util/trim.d.ts.map +1 -0
  92. package/dist/types/tsconfig.tsbuildinfo +1 -0
  93. package/package.json +64 -0
  94. package/src/ai-service/client.test.ts +162 -0
  95. package/src/ai-service/client.ts +243 -0
  96. package/src/ai-service/index.ts +6 -0
  97. package/src/ai-service/schema.ts +260 -0
  98. package/src/ai-service/sse.ts +336 -0
  99. package/src/bin/chat.ts +79 -0
  100. package/src/conversation/conversation.test.ts +74 -0
  101. package/src/conversation/conversation.ts +134 -0
  102. package/src/conversation/index.ts +6 -0
  103. package/src/conversation/types.ts +90 -0
  104. package/src/cypher/ast.ts +75 -0
  105. package/src/cypher/combinators.test.ts +137 -0
  106. package/src/cypher/combinators.ts +149 -0
  107. package/src/cypher/echo-data-source.ts +105 -0
  108. package/src/cypher/execution-plan.test.ts +42 -0
  109. package/src/cypher/execution-plan.ts +208 -0
  110. package/src/cypher/index.ts +8 -0
  111. package/src/cypher/parjs-shims.d.ts +6 -0
  112. package/src/cypher/parjs.ts +10 -0
  113. package/src/cypher/parser.ts +19 -0
  114. package/src/cypher/query-executor.test.ts +47 -0
  115. package/src/cypher/query-executor.ts +145 -0
  116. package/src/cypher/schema.test.ts +17 -0
  117. package/src/cypher/schema.ts +82 -0
  118. package/src/index.ts +7 -0
  119. package/src/sanity.test.ts +9 -0
  120. package/src/testing/index.ts +8 -0
  121. package/src/testing/logger.ts +128 -0
  122. package/src/testing/object-extraction.test.ts +71 -0
  123. package/src/testing/query-promts.ts +75 -0
  124. package/src/testing/query.test.ts +90 -0
  125. package/src/testing/test-data.ts +366 -0
  126. package/src/testing/test-schema.ts +80 -0
  127. package/src/util/index.ts +5 -0
  128. package/src/util/trim.ts +15 -0
@@ -0,0 +1,619 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var testing_exports = {};
20
+ __export(testing_exports, {
21
+ Contact: () => Contact,
22
+ MockDataSource: () => MockDataSource,
23
+ ObjectId: () => ObjectId2,
24
+ Org: () => Org,
25
+ Project: () => Project,
26
+ Task: () => Task,
27
+ createCypherTool: () => createCypherTool,
28
+ createLogger: () => createLogger,
29
+ createSystemPrompt: () => createSystemPrompt,
30
+ createTestData: () => createTestData,
31
+ seedTestData: () => seedTestData
32
+ });
33
+ module.exports = __toCommonJS(testing_exports);
34
+ var import_chunk_G6CGWEMO = require("../chunk-G6CGWEMO.cjs");
35
+ var import_schema = require("@effect/schema");
36
+ var import_echo_schema = require("@dxos/echo-schema");
37
+ var import_log = require("@dxos/log");
38
+ var import_debug = require("@dxos/debug");
39
+ var import_echo_schema2 = require("@dxos/echo-schema");
40
+ var import_invariant = require("@dxos/invariant");
41
+ var import_live_object = require("@dxos/live-object");
42
+ var import_schema2 = require("@effect/schema");
43
+ var import_echo_schema3 = require("@dxos/echo-schema");
44
+ var createLogger = ({ stream, filter, onImage } = {}) => {
45
+ const images = {};
46
+ let currentText = "";
47
+ return (event) => {
48
+ if (typeof filter === "function" && !filter(event)) {
49
+ return;
50
+ }
51
+ const printContentBlock = (content) => {
52
+ switch (content.type) {
53
+ case "text":
54
+ process.stdout.write(content.text);
55
+ break;
56
+ case "tool_use":
57
+ process.stdout.write(`\u2699\uFE0F [Tool Use] ${content.name}
58
+ `);
59
+ break;
60
+ case "image": {
61
+ if (content.id && content.source) {
62
+ images[content.id] = content.source;
63
+ }
64
+ process.stdout.write(`[Image id=${content.id} media_type=${content.source?.media_type}]`);
65
+ break;
66
+ }
67
+ }
68
+ };
69
+ const onTextBlockPrinted = (text) => {
70
+ const imageMatch = text.match(/<image id="([^"]+)"(?:\s+prompt="([^"]+)")?\s*\/>/);
71
+ if (imageMatch && onImage && images[imageMatch[1]]) {
72
+ onImage({
73
+ id: imageMatch[1],
74
+ description: imageMatch[2],
75
+ source: images[imageMatch[1]]
76
+ });
77
+ }
78
+ };
79
+ if (stream) {
80
+ switch (event.type) {
81
+ case "message_start": {
82
+ process.stdout.write(`${event.message.role.toUpperCase()}
83
+
84
+ `);
85
+ for (const content of event.message.content) {
86
+ printContentBlock(content);
87
+ }
88
+ break;
89
+ }
90
+ case "content_block_start": {
91
+ currentText = "";
92
+ printContentBlock(event.content);
93
+ break;
94
+ }
95
+ case "content_block_delta": {
96
+ switch (event.delta.type) {
97
+ case "text_delta": {
98
+ currentText += event.delta.text;
99
+ process.stdout.write(event.delta.text);
100
+ break;
101
+ }
102
+ case "input_json_delta": {
103
+ process.stdout.write(event.delta.partial_json);
104
+ break;
105
+ }
106
+ }
107
+ break;
108
+ }
109
+ case "content_block_stop": {
110
+ process.stdout.write("\n");
111
+ onTextBlockPrinted(currentText);
112
+ currentText = "";
113
+ break;
114
+ }
115
+ case "message_delta": {
116
+ break;
117
+ }
118
+ case "message_stop": {
119
+ process.stdout.write("\n\n");
120
+ break;
121
+ }
122
+ }
123
+ }
124
+ switch (event.type) {
125
+ case "message": {
126
+ if (!stream || event.message.role !== "assistant") {
127
+ process.stdout.write(`${event.message.role.toUpperCase()}
128
+
129
+ `);
130
+ for (const block of event.message.content) {
131
+ switch (block.type) {
132
+ case "text":
133
+ process.stdout.write(block.text + "\n");
134
+ onTextBlockPrinted(block.text);
135
+ break;
136
+ case "tool_use":
137
+ process.stdout.write(`\u2699\uFE0F [Tool Use] ${block.name}
138
+ `);
139
+ process.stdout.write(` ${JSON.stringify(block.input)}
140
+ `);
141
+ break;
142
+ case "tool_result":
143
+ if (block.isError) {
144
+ process.stdout.write("\u274C [Tool Error]\n");
145
+ process.stdout.write(block.content + "\n");
146
+ } else {
147
+ process.stdout.write("\u2705 [Tool Success]\n");
148
+ process.stdout.write(block.content + "\n");
149
+ }
150
+ }
151
+ process.stdout.write("\n\n");
152
+ }
153
+ }
154
+ break;
155
+ }
156
+ }
157
+ };
158
+ };
159
+ var __dxlog_file = "/Users/yarolegovich/Documents/Workspace/dxos/packages/experimental/assistant/src/testing/query-promts.ts";
160
+ var createCypherTool = (dataSource, schemaTypes = []) => (0, import_chunk_G6CGWEMO.defineTool)({
161
+ name: "graphQuery",
162
+ description: "Query the ECHO graph database in cypher query language. Returns data from the database." + (schemaTypes.length > 0 ? `
163
+
164
+ ${createSystemPrompt(schemaTypes)}` : ""),
165
+ schema: import_schema.Schema.Struct({
166
+ query: import_schema.Schema.String.annotations({
167
+ description: `
168
+ A valid cypher query string to execute.
169
+ Query must have one MATCH clause.
170
+ Match clause can have multiple patterns but they must all be connected via a relationship chain.
171
+ Query might have zero or one WHERE clauses.
172
+ Query must have one RETURN clause.
173
+ RETURN clause can have multiple expressions separated by commas.
174
+ DISTINCT keyword is not allowed.
175
+
176
+ <example>
177
+ MATCH (n:Person) RETURN n.name
178
+ </example>
179
+
180
+ <example>
181
+ MATCH (s:Studio)-[:PRODUCED]->(m:Movie)-[:PRODUCED_IN]->(c:City {name: "Las Vegas"}) RETURN s
182
+ </example>
183
+
184
+ <example>
185
+ MATCH (a:Actor)-[:STARRED_IN]->(m:Movie)<-[:PRODUCED]-(s:Studio {name: "Cinema Pictures"}) WHERE m.name = "Once upon a time" RETURN m.name, a.name
186
+ </example>
187
+ `
188
+ })
189
+ }),
190
+ execute: async ({ query }) => {
191
+ try {
192
+ (0, import_log.log)("cypher query", {
193
+ query
194
+ }, {
195
+ F: __dxlog_file,
196
+ L: 47,
197
+ S: void 0,
198
+ C: (f, a) => f(...a)
199
+ });
200
+ const results = await (0, import_chunk_G6CGWEMO.executeQuery)(dataSource, query);
201
+ (0, import_log.log)("query complete", {
202
+ results
203
+ }, {
204
+ F: __dxlog_file,
205
+ L: 49,
206
+ S: void 0,
207
+ C: (f, a) => f(...a)
208
+ });
209
+ return import_chunk_G6CGWEMO.LLMToolResult.Success(results);
210
+ } catch (e) {
211
+ import_log.log.catch(e, void 0, {
212
+ F: __dxlog_file,
213
+ L: 52,
214
+ S: void 0,
215
+ C: (f, a) => f(...a)
216
+ });
217
+ return import_chunk_G6CGWEMO.LLMToolResult.Error(e.message);
218
+ }
219
+ }
220
+ });
221
+ var createSystemPrompt = (schemaTypes) => import_chunk_G6CGWEMO.trim`
222
+ You have access to ECHO graph database. You can query the database to get data to satisfy user prompts.
223
+
224
+ Database schema is defined in pseud-cypher syntax. The schema is:
225
+
226
+ <schema>
227
+ ${(0, import_chunk_G6CGWEMO.formatJsonSchemaForLLM)(schemaTypes.map((schema) => (0, import_echo_schema.toJsonSchema)(schema)))}
228
+ <schema>
229
+
230
+ Before replying always think step-by-step on how to proceed.
231
+ Print your thoughts inside <cot> tags.
232
+
233
+ <example>
234
+ <cot>To answer the question I need to ...</cot>
235
+ </example>
236
+
237
+ Before answering the user's question, decide what tools you need to use to answer the question.
238
+ `;
239
+ var __dxlog_file2 = "/Users/yarolegovich/Documents/Workspace/dxos/packages/experimental/assistant/src/testing/test-data.ts";
240
+ var seedTestData = (db) => {
241
+ const contactRich = db.add((0, import_live_object.create)(Contact, {
242
+ name: "Rich"
243
+ }));
244
+ const contactJosiah = db.add((0, import_live_object.create)(Contact, {
245
+ name: "Josiah"
246
+ }));
247
+ const contactDima = db.add((0, import_live_object.create)(Contact, {
248
+ name: "Dima"
249
+ }));
250
+ const contactFred = db.add((0, import_live_object.create)(Contact, {
251
+ name: "Fred"
252
+ }));
253
+ const projectComposer = db.add((0, import_live_object.create)(Project, {
254
+ name: "Composer"
255
+ }));
256
+ const projectEcho = db.add((0, import_live_object.create)(Project, {
257
+ name: "ECHO"
258
+ }));
259
+ const projectDoodles = db.add((0, import_live_object.create)(Project, {
260
+ name: "Doodles"
261
+ }));
262
+ const _taskComposer1 = db.add((0, import_live_object.create)(Task, {
263
+ name: "Optimize startup performance",
264
+ project: (0, import_live_object.makeRef)(projectComposer),
265
+ assignee: (0, import_live_object.makeRef)(contactJosiah)
266
+ }));
267
+ const _taskComposer2 = db.add((0, import_live_object.create)(Task, {
268
+ name: "Create form builder",
269
+ project: (0, import_live_object.makeRef)(projectComposer),
270
+ assignee: (0, import_live_object.makeRef)(contactRich)
271
+ }));
272
+ const _taskComposer3 = db.add((0, import_live_object.create)(Task, {
273
+ name: "Add support for custom themes",
274
+ project: (0, import_live_object.makeRef)(projectComposer),
275
+ assignee: (0, import_live_object.makeRef)(contactJosiah)
276
+ }));
277
+ const _taskComposer5 = db.add((0, import_live_object.create)(Task, {
278
+ name: "Implement community plugin",
279
+ project: (0, import_live_object.makeRef)(projectComposer),
280
+ assignee: (0, import_live_object.makeRef)(contactFred)
281
+ }));
282
+ const _taskComposer4 = db.add((0, import_live_object.create)(Task, {
283
+ name: "Implement dark mode",
284
+ project: (0, import_live_object.makeRef)(projectComposer),
285
+ assignee: (0, import_live_object.makeRef)(contactRich)
286
+ }));
287
+ const _taskEcho1 = db.add((0, import_live_object.create)(Task, {
288
+ name: "Implement cypher query engine",
289
+ project: (0, import_live_object.makeRef)(projectEcho),
290
+ assignee: (0, import_live_object.makeRef)(contactDima)
291
+ }));
292
+ const _taskEcho2 = db.add((0, import_live_object.create)(Task, {
293
+ name: "Add schema editor",
294
+ project: (0, import_live_object.makeRef)(projectEcho),
295
+ assignee: (0, import_live_object.makeRef)(contactRich)
296
+ }));
297
+ const _taskDoodles1 = db.add((0, import_live_object.create)(Task, {
298
+ name: "Add support for custom themes",
299
+ project: (0, import_live_object.makeRef)(projectDoodles),
300
+ assignee: (0, import_live_object.makeRef)(contactFred)
301
+ }));
302
+ const _taskDoodles2 = db.add((0, import_live_object.create)(Task, {
303
+ name: "Implement dark mode",
304
+ project: (0, import_live_object.makeRef)(projectDoodles),
305
+ assignee: (0, import_live_object.makeRef)(contactJosiah)
306
+ }));
307
+ const _orgDxos = db.add((0, import_live_object.create)(Org, {
308
+ name: "DXOS",
309
+ employees: [
310
+ (0, import_live_object.makeRef)(contactRich),
311
+ (0, import_live_object.makeRef)(contactJosiah),
312
+ (0, import_live_object.makeRef)(contactDima)
313
+ ],
314
+ projects: [
315
+ (0, import_live_object.makeRef)(projectEcho)
316
+ ]
317
+ }));
318
+ const _orgBraneframe = db.add((0, import_live_object.create)(Org, {
319
+ name: "Braneframe",
320
+ employees: [
321
+ (0, import_live_object.makeRef)(contactJosiah),
322
+ (0, import_live_object.makeRef)(contactRich)
323
+ ],
324
+ projects: [
325
+ (0, import_live_object.makeRef)(projectComposer)
326
+ ]
327
+ }));
328
+ };
329
+ var createTestData = () => {
330
+ const dataSource = new MockDataSource();
331
+ const contactRich = dataSource.add(Contact, {
332
+ id: import_echo_schema2.ObjectId.random(),
333
+ name: "Rich"
334
+ });
335
+ const contactJosiah = dataSource.add(Contact, {
336
+ id: import_echo_schema2.ObjectId.random(),
337
+ name: "Josiah"
338
+ });
339
+ const contactDima = dataSource.add(Contact, {
340
+ id: import_echo_schema2.ObjectId.random(),
341
+ name: "Dima"
342
+ });
343
+ const contactFred = dataSource.add(Contact, {
344
+ id: import_echo_schema2.ObjectId.random(),
345
+ name: "Fred"
346
+ });
347
+ const projectComposer = dataSource.add(Project, {
348
+ id: import_echo_schema2.ObjectId.random(),
349
+ name: "Composer"
350
+ });
351
+ const projectEcho = dataSource.add(Project, {
352
+ id: import_echo_schema2.ObjectId.random(),
353
+ name: "ECHO"
354
+ });
355
+ const projectDoodles = dataSource.add(Project, {
356
+ id: import_echo_schema2.ObjectId.random(),
357
+ name: "Doodles"
358
+ });
359
+ const _taskComposer1 = dataSource.add(Task, {
360
+ id: import_echo_schema2.ObjectId.random(),
361
+ name: "Optimize startup performance",
362
+ project: (0, import_live_object.makeRef)(projectComposer),
363
+ assignee: (0, import_live_object.makeRef)(contactJosiah)
364
+ });
365
+ const _taskComposer2 = dataSource.add(Task, {
366
+ id: import_echo_schema2.ObjectId.random(),
367
+ name: "Create form builder",
368
+ project: (0, import_live_object.makeRef)(projectComposer),
369
+ assignee: (0, import_live_object.makeRef)(contactRich)
370
+ });
371
+ const _taskComposer3 = dataSource.add(Task, {
372
+ id: import_echo_schema2.ObjectId.random(),
373
+ name: "Add support for custom themes",
374
+ project: (0, import_live_object.makeRef)(projectComposer),
375
+ assignee: (0, import_live_object.makeRef)(contactJosiah)
376
+ });
377
+ const _taskComposer5 = dataSource.add(Task, {
378
+ id: import_echo_schema2.ObjectId.random(),
379
+ name: "Implement community plugin",
380
+ project: (0, import_live_object.makeRef)(projectComposer),
381
+ assignee: (0, import_live_object.makeRef)(contactFred)
382
+ });
383
+ const _taskComposer4 = dataSource.add(Task, {
384
+ id: import_echo_schema2.ObjectId.random(),
385
+ name: "Implement dark mode",
386
+ project: (0, import_live_object.makeRef)(projectComposer),
387
+ assignee: (0, import_live_object.makeRef)(contactRich)
388
+ });
389
+ const _taskEcho1 = dataSource.add(Task, {
390
+ id: import_echo_schema2.ObjectId.random(),
391
+ name: "Implement cypher query engine",
392
+ project: (0, import_live_object.makeRef)(projectEcho),
393
+ assignee: (0, import_live_object.makeRef)(contactDima)
394
+ });
395
+ const _taskEcho2 = dataSource.add(Task, {
396
+ id: import_echo_schema2.ObjectId.random(),
397
+ name: "Add schema editor",
398
+ project: (0, import_live_object.makeRef)(projectEcho),
399
+ assignee: (0, import_live_object.makeRef)(contactRich)
400
+ });
401
+ const _taskDoodles1 = dataSource.add(Task, {
402
+ id: import_echo_schema2.ObjectId.random(),
403
+ name: "Add support for custom themes",
404
+ project: (0, import_live_object.makeRef)(projectDoodles),
405
+ assignee: (0, import_live_object.makeRef)(contactFred)
406
+ });
407
+ const _taskDoodles2 = dataSource.add(Task, {
408
+ id: import_echo_schema2.ObjectId.random(),
409
+ name: "Implement dark mode",
410
+ project: (0, import_live_object.makeRef)(projectDoodles),
411
+ assignee: (0, import_live_object.makeRef)(contactJosiah)
412
+ });
413
+ const _orgDxos = dataSource.add(Org, {
414
+ id: import_echo_schema2.ObjectId.random(),
415
+ name: "DXOS",
416
+ employees: [
417
+ (0, import_live_object.makeRef)(contactRich),
418
+ (0, import_live_object.makeRef)(contactJosiah),
419
+ (0, import_live_object.makeRef)(contactDima)
420
+ ],
421
+ projects: [
422
+ (0, import_live_object.makeRef)(projectEcho)
423
+ ]
424
+ });
425
+ const _orgBraneframe = dataSource.add(Org, {
426
+ id: import_echo_schema2.ObjectId.random(),
427
+ name: "Braneframe",
428
+ employees: [
429
+ (0, import_live_object.makeRef)(contactJosiah),
430
+ (0, import_live_object.makeRef)(contactRich)
431
+ ],
432
+ projects: [
433
+ (0, import_live_object.makeRef)(projectComposer)
434
+ ]
435
+ });
436
+ dataSource.computeGraph();
437
+ return dataSource;
438
+ };
439
+ var MockDataSource = class {
440
+ constructor() {
441
+ this.objects = {};
442
+ this.schema = {};
443
+ this.nodes = [];
444
+ this.relationships = [];
445
+ }
446
+ async getNodes({ label }) {
447
+ return this.nodes.filter((node) => !label || node.label === label);
448
+ }
449
+ async getRelationships({ label }) {
450
+ return this.relationships.filter((relationship) => !label || relationship.label === label);
451
+ }
452
+ add(schema, data) {
453
+ (0, import_invariant.invariant)(typeof data.id === "string", "Data must have an id", {
454
+ F: __dxlog_file2,
455
+ L: 277,
456
+ S: this,
457
+ A: [
458
+ "typeof data.id === 'string'",
459
+ "'Data must have an id'"
460
+ ]
461
+ });
462
+ const jsonSchema = (0, import_echo_schema2.toJsonSchema)(schema);
463
+ if (!this.schema[jsonSchema.$id]) {
464
+ this.schema[jsonSchema.$id] = {
465
+ json: jsonSchema,
466
+ instance: schema
467
+ };
468
+ }
469
+ const typenameDxn = jsonSchema.$id ?? (0, import_debug.raise)(new Error("Schema must have $id"));
470
+ this.objects[data.id] = {
471
+ schema,
472
+ id: data.id,
473
+ typeDxn: typenameDxn,
474
+ data
475
+ };
476
+ return data;
477
+ }
478
+ computeGraph() {
479
+ this.nodes = [];
480
+ this.relationships = [];
481
+ for (const object of Object.values(this.objects)) {
482
+ this.nodes.push({
483
+ kind: "node",
484
+ id: object.id,
485
+ label: (0, import_chunk_G6CGWEMO.formatNodeLabel)(object.typeDxn),
486
+ properties: object.data
487
+ });
488
+ }
489
+ for (const object of Object.values(this.objects)) {
490
+ const schema = this.schema[object.typeDxn].json;
491
+ const typenameDxn = schema.$id ?? (0, import_debug.raise)(new Error("Schema must have $id"));
492
+ for (const [name, propSchema] of Object.entries(schema.properties)) {
493
+ if (propSchema.$id === import_echo_schema2.JSON_SCHEMA_ECHO_REF_ID) {
494
+ const label = (0, import_chunk_G6CGWEMO.formatInferredRelationshipLabel)(typenameDxn, name);
495
+ const source = this.nodes.find((node) => node.id === object.id);
496
+ if (!source) {
497
+ continue;
498
+ }
499
+ const { id: targetId } = object.data[name].target;
500
+ const target = this.nodes.find((node) => node.id === targetId);
501
+ if (!target) {
502
+ continue;
503
+ }
504
+ this.relationships.push({
505
+ kind: "relationship",
506
+ id: `${object.id}-${name}-${target.id}`,
507
+ label,
508
+ properties: {},
509
+ source,
510
+ target
511
+ });
512
+ } else if (propSchema.type === "array" && propSchema.items?.$id === import_echo_schema2.JSON_SCHEMA_ECHO_REF_ID) {
513
+ const label = (0, import_chunk_G6CGWEMO.formatInferredRelationshipLabel)(typenameDxn, name);
514
+ const source = this.nodes.find((node) => node.id === object.id);
515
+ if (!source) {
516
+ continue;
517
+ }
518
+ for (const { id: targetId } of object.data[name].map((x) => x.target)) {
519
+ const target = this.nodes.find((node) => node.id === targetId);
520
+ if (!target) {
521
+ continue;
522
+ }
523
+ this.relationships.push({
524
+ kind: "relationship",
525
+ id: `${object.id}-${name}-${targetId}`,
526
+ label,
527
+ properties: {},
528
+ source,
529
+ target
530
+ });
531
+ }
532
+ }
533
+ }
534
+ }
535
+ }
536
+ };
537
+ var ObjectId2 = import_schema2.Schema.String.annotations({
538
+ description: "The unique object identifier."
539
+ });
540
+ var Contact = import_schema2.Schema.Struct({
541
+ id: ObjectId2,
542
+ name: import_schema2.Schema.String.annotations({
543
+ description: "The name of the person."
544
+ }),
545
+ email: import_schema2.Schema.optional(import_schema2.Schema.String).annotations({
546
+ description: "Email address."
547
+ })
548
+ }).pipe(import_schema2.Schema.mutable).annotations({
549
+ [import_echo_schema3.ObjectAnnotationId]: {
550
+ kind: import_echo_schema3.EntityKind.Object,
551
+ typename: "example.com/type/Contact",
552
+ version: "0.1.0"
553
+ },
554
+ description: "Contact information."
555
+ });
556
+ var Project = import_schema2.Schema.Struct({
557
+ id: ObjectId2,
558
+ name: import_schema2.Schema.String.annotations({
559
+ description: "The name of the project."
560
+ }),
561
+ description: import_schema2.Schema.optional(import_schema2.Schema.String).annotations({
562
+ description: "The description of the project."
563
+ })
564
+ }).pipe(import_schema2.Schema.mutable).annotations({
565
+ [import_echo_schema3.ObjectAnnotationId]: {
566
+ kind: import_echo_schema3.EntityKind.Object,
567
+ typename: "example.com/type/Project",
568
+ version: "0.1.0"
569
+ },
570
+ description: "Contact information."
571
+ });
572
+ var Task = import_schema2.Schema.Struct({
573
+ id: ObjectId2,
574
+ name: import_schema2.Schema.String.annotations({
575
+ description: "The name of the task."
576
+ }),
577
+ description: import_schema2.Schema.optional(import_schema2.Schema.String).annotations({
578
+ description: "The description of the task."
579
+ }),
580
+ project: (0, import_echo_schema3.Ref)(Project),
581
+ assignee: (0, import_echo_schema3.Ref)(Contact)
582
+ }).pipe(import_schema2.Schema.mutable).annotations({
583
+ [import_echo_schema3.ObjectAnnotationId]: {
584
+ kind: import_echo_schema3.EntityKind.Object,
585
+ typename: "example.com/type/Task",
586
+ version: "0.1.0"
587
+ },
588
+ description: "Contact information."
589
+ });
590
+ var Org = import_schema2.Schema.Struct({
591
+ id: ObjectId2,
592
+ name: import_schema2.Schema.String.annotations({
593
+ description: "The name of the organization."
594
+ }),
595
+ projects: import_schema2.Schema.Array((0, import_echo_schema3.Ref)(Project)),
596
+ employees: import_schema2.Schema.Array((0, import_echo_schema3.Ref)(Contact))
597
+ }).pipe(import_schema2.Schema.mutable).annotations({
598
+ [import_echo_schema3.ObjectAnnotationId]: {
599
+ kind: import_echo_schema3.EntityKind.Object,
600
+ typename: "example.com/type/Org",
601
+ version: "0.1.0"
602
+ },
603
+ description: "Contact information."
604
+ });
605
+ // Annotate the CommonJS export names for ESM import in node:
606
+ 0 && (module.exports = {
607
+ Contact,
608
+ MockDataSource,
609
+ ObjectId,
610
+ Org,
611
+ Project,
612
+ Task,
613
+ createCypherTool,
614
+ createLogger,
615
+ createSystemPrompt,
616
+ createTestData,
617
+ seedTestData
618
+ });
619
+ //# sourceMappingURL=index.cjs.map