@dxos/assistant 0.8.2-staging.7ac8446 → 0.8.3-main.672df60

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 (277) hide show
  1. package/dist/lib/browser/index.mjs +1909 -228
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node/index.cjs +1907 -229
  5. package/dist/lib/node/index.cjs.map +4 -4
  6. package/dist/lib/node/meta.json +1 -1
  7. package/dist/lib/node-esm/index.mjs +1910 -228
  8. package/dist/lib/node-esm/index.mjs.map +4 -4
  9. package/dist/lib/node-esm/meta.json +1 -1
  10. package/dist/types/{src/bin → bin}/chat.d.ts.map +1 -1
  11. package/dist/types/src/blueprint/blueprint.d.ts +51 -0
  12. package/dist/types/src/blueprint/blueprint.d.ts.map +1 -0
  13. package/dist/types/src/blueprint/blueprint.test.d.ts +2 -0
  14. package/dist/types/src/blueprint/blueprint.test.d.ts.map +1 -0
  15. package/dist/types/src/blueprint/index.d.ts +4 -0
  16. package/dist/types/src/blueprint/index.d.ts.map +1 -0
  17. package/dist/types/src/blueprint/logger.d.ts +12 -0
  18. package/dist/types/src/blueprint/logger.d.ts.map +1 -0
  19. package/dist/types/src/blueprint/machine.d.ts +122 -0
  20. package/dist/types/src/blueprint/machine.d.ts.map +1 -0
  21. package/dist/types/src/blueprint/test-data.d.ts +3 -0
  22. package/dist/types/src/blueprint/test-data.d.ts.map +1 -0
  23. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts +4 -0
  24. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +1 -0
  25. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts +2 -0
  26. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts.map +1 -0
  27. package/dist/types/src/extraction/extraction-llm-function/index.d.ts +2 -0
  28. package/dist/types/src/extraction/extraction-llm-function/index.d.ts.map +1 -0
  29. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +210 -0
  30. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +1 -0
  31. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts +2 -0
  32. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts.map +1 -0
  33. package/dist/types/src/extraction/extraction-ner-function/index.d.ts +3 -0
  34. package/dist/types/src/extraction/extraction-ner-function/index.d.ts.map +1 -0
  35. package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts +14 -0
  36. package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts.map +1 -0
  37. package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.test.d.ts +2 -0
  38. package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.test.d.ts.map +1 -0
  39. package/dist/types/src/extraction/extraction.d.ts +242 -0
  40. package/dist/types/src/extraction/extraction.d.ts.map +1 -0
  41. package/dist/types/src/extraction/index.d.ts +5 -0
  42. package/dist/types/src/extraction/index.d.ts.map +1 -0
  43. package/dist/types/src/extraction/quotes.d.ts +15 -0
  44. package/dist/types/src/extraction/quotes.d.ts.map +1 -0
  45. package/dist/types/src/extraction/quotes.test.d.ts +2 -0
  46. package/dist/types/src/extraction/quotes.test.d.ts.map +1 -0
  47. package/dist/types/src/index.d.ts +4 -3
  48. package/dist/types/src/index.d.ts.map +1 -1
  49. package/dist/types/src/research/exa.d.ts +7 -0
  50. package/dist/types/src/research/exa.d.ts.map +1 -0
  51. package/dist/types/src/research/graph.d.ts +40 -0
  52. package/dist/types/src/research/graph.d.ts.map +1 -0
  53. package/dist/types/src/research/graph.test.d.ts +2 -0
  54. package/dist/types/src/research/graph.test.d.ts.map +1 -0
  55. package/dist/types/src/research/index.d.ts +4 -0
  56. package/dist/types/src/research/index.d.ts.map +1 -0
  57. package/dist/types/src/research/research.d.ts +10 -0
  58. package/dist/types/src/research/research.d.ts.map +1 -0
  59. package/dist/types/src/research/research.test.d.ts +2 -0
  60. package/dist/types/src/research/research.test.d.ts.map +1 -0
  61. package/dist/types/src/session/index.d.ts +1 -0
  62. package/dist/types/src/session/index.d.ts.map +1 -1
  63. package/dist/types/src/session/session.d.ts +80 -35
  64. package/dist/types/src/session/session.d.ts.map +1 -1
  65. package/dist/types/src/session/version-pin.d.ts +21 -0
  66. package/dist/types/src/session/version-pin.d.ts.map +1 -0
  67. package/dist/types/src/session/version-pin.test.d.ts +2 -0
  68. package/dist/types/src/session/version-pin.test.d.ts.map +1 -0
  69. package/dist/types/src/summarization/summarization.test.d.ts +2 -0
  70. package/dist/types/src/summarization/summarization.test.d.ts.map +1 -0
  71. package/dist/types/src/testing/exa-search-1748337321991.d.ts +38 -0
  72. package/dist/types/src/testing/exa-search-1748337321991.d.ts.map +1 -0
  73. package/dist/types/src/testing/exa-search-1748337331526.d.ts +37 -0
  74. package/dist/types/src/testing/exa-search-1748337331526.d.ts.map +1 -0
  75. package/dist/types/src/testing/exa-search-1748337344119.d.ts +58 -0
  76. package/dist/types/src/testing/exa-search-1748337344119.d.ts.map +1 -0
  77. package/dist/types/src/testing/index.d.ts +2 -6
  78. package/dist/types/src/testing/index.d.ts.map +1 -1
  79. package/dist/types/src/types.d.ts +3 -0
  80. package/dist/types/src/types.d.ts.map +1 -0
  81. package/dist/types/tsconfig.tsbuildinfo +1 -1
  82. package/package.json +26 -35
  83. package/src/blueprint/blueprint.test.ts +149 -0
  84. package/src/blueprint/blueprint.ts +71 -0
  85. package/src/blueprint/index.ts +7 -0
  86. package/src/blueprint/logger.ts +109 -0
  87. package/src/blueprint/machine.ts +214 -0
  88. package/src/blueprint/test-data.ts +55 -0
  89. package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +95 -0
  90. package/src/extraction/extraction-llm-function/extraction-llm-function.ts +64 -0
  91. package/src/extraction/extraction-llm-function/index.ts +5 -0
  92. package/src/extraction/extraction-llm-function/instructions.tpl +28 -0
  93. package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +115 -0
  94. package/src/extraction/extraction-ner-function/extraction-ner-function.ts +54 -0
  95. package/src/extraction/extraction-ner-function/index.ts +6 -0
  96. package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +94 -0
  97. package/src/extraction/extraction-ner-function/named-entity-recognition.ts +97 -0
  98. package/src/extraction/extraction.ts +75 -0
  99. package/src/extraction/index.ts +8 -0
  100. package/src/extraction/quotes.test.ts +27 -0
  101. package/src/extraction/quotes.ts +57 -0
  102. package/src/index.ts +4 -3
  103. package/src/research/exa.ts +100 -0
  104. package/src/research/graph.test.ts +15 -0
  105. package/src/research/graph.ts +339 -0
  106. package/src/research/index.ts +7 -0
  107. package/src/research/instructions-research.tpl +97 -0
  108. package/src/research/research.test.ts +189 -0
  109. package/src/research/research.ts +89 -0
  110. package/src/session/index.ts +1 -0
  111. package/src/session/session.test.ts +39 -67
  112. package/src/session/session.ts +328 -155
  113. package/src/session/version-pin.test.ts +26 -0
  114. package/src/session/version-pin.ts +48 -0
  115. package/src/summarization/summarization.test.ts +216 -0
  116. package/src/testing/exa-search-1748337321991.ts +131 -0
  117. package/src/testing/exa-search-1748337331526.ts +144 -0
  118. package/src/testing/exa-search-1748337344119.ts +133 -0
  119. package/src/testing/index.ts +8 -7
  120. package/src/typedefs.d.ts +8 -0
  121. package/src/types.ts +8 -0
  122. package/src/typings.d.ts +8 -0
  123. package/dist/lib/browser/chunk-PND5VR6D.mjs +0 -2315
  124. package/dist/lib/browser/chunk-PND5VR6D.mjs.map +0 -7
  125. package/dist/lib/browser/testing/index.mjs +0 -621
  126. package/dist/lib/browser/testing/index.mjs.map +0 -7
  127. package/dist/lib/node/chunk-IBOBRBDF.cjs +0 -2326
  128. package/dist/lib/node/chunk-IBOBRBDF.cjs.map +0 -7
  129. package/dist/lib/node/testing/index.cjs +0 -637
  130. package/dist/lib/node/testing/index.cjs.map +0 -7
  131. package/dist/lib/node-esm/chunk-DCQJOLSR.mjs +0 -2317
  132. package/dist/lib/node-esm/chunk-DCQJOLSR.mjs.map +0 -7
  133. package/dist/lib/node-esm/testing/index.mjs +0 -622
  134. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  135. package/dist/types/src/ai-service/client.test.d.ts +0 -2
  136. package/dist/types/src/ai-service/client.test.d.ts.map +0 -1
  137. package/dist/types/src/ai-service/defs.d.ts +0 -9
  138. package/dist/types/src/ai-service/defs.d.ts.map +0 -1
  139. package/dist/types/src/ai-service/edge-client.d.ts +0 -19
  140. package/dist/types/src/ai-service/edge-client.d.ts.map +0 -1
  141. package/dist/types/src/ai-service/index.d.ts +0 -10
  142. package/dist/types/src/ai-service/index.d.ts.map +0 -1
  143. package/dist/types/src/ai-service/message-collector.d.ts +0 -88
  144. package/dist/types/src/ai-service/message-collector.d.ts.map +0 -1
  145. package/dist/types/src/ai-service/ollama-client.d.ts +0 -39
  146. package/dist/types/src/ai-service/ollama-client.d.ts.map +0 -1
  147. package/dist/types/src/ai-service/parser.d.ts +0 -138
  148. package/dist/types/src/ai-service/parser.d.ts.map +0 -1
  149. package/dist/types/src/ai-service/service.d.ts +0 -9
  150. package/dist/types/src/ai-service/service.d.ts.map +0 -1
  151. package/dist/types/src/ai-service/stream.d.ts +0 -40
  152. package/dist/types/src/ai-service/stream.d.ts.map +0 -1
  153. package/dist/types/src/ai-service/stream.test.d.ts +0 -2
  154. package/dist/types/src/ai-service/stream.test.d.ts.map +0 -1
  155. package/dist/types/src/ai-service/testing/index.d.ts +0 -3
  156. package/dist/types/src/ai-service/testing/index.d.ts.map +0 -1
  157. package/dist/types/src/ai-service/testing/mock.d.ts +0 -7
  158. package/dist/types/src/ai-service/testing/mock.d.ts.map +0 -1
  159. package/dist/types/src/ai-service/testing/test-stream.d.ts +0 -7
  160. package/dist/types/src/ai-service/testing/test-stream.d.ts.map +0 -1
  161. package/dist/types/src/ai-service/transform.d.ts +0 -27
  162. package/dist/types/src/ai-service/transform.d.ts.map +0 -1
  163. package/dist/types/src/ai-service/types.d.ts +0 -167
  164. package/dist/types/src/ai-service/types.d.ts.map +0 -1
  165. package/dist/types/src/ai-service/util/index.d.ts +0 -2
  166. package/dist/types/src/ai-service/util/index.d.ts.map +0 -1
  167. package/dist/types/src/ai-service/util/sse.d.ts +0 -39
  168. package/dist/types/src/ai-service/util/sse.d.ts.map +0 -1
  169. package/dist/types/src/conversation/conversation.d.ts +0 -80
  170. package/dist/types/src/conversation/conversation.d.ts.map +0 -1
  171. package/dist/types/src/conversation/conversation.test.d.ts +0 -2
  172. package/dist/types/src/conversation/conversation.test.d.ts.map +0 -1
  173. package/dist/types/src/conversation/index.d.ts +0 -2
  174. package/dist/types/src/conversation/index.d.ts.map +0 -1
  175. package/dist/types/src/conversation/types.d.ts +0 -79
  176. package/dist/types/src/conversation/types.d.ts.map +0 -1
  177. package/dist/types/src/cypher/ast.d.ts +0 -56
  178. package/dist/types/src/cypher/ast.d.ts.map +0 -1
  179. package/dist/types/src/cypher/combinators.d.ts +0 -14
  180. package/dist/types/src/cypher/combinators.d.ts.map +0 -1
  181. package/dist/types/src/cypher/combinators.test.d.ts +0 -2
  182. package/dist/types/src/cypher/combinators.test.d.ts.map +0 -1
  183. package/dist/types/src/cypher/echo-data-source.d.ts +0 -16
  184. package/dist/types/src/cypher/echo-data-source.d.ts.map +0 -1
  185. package/dist/types/src/cypher/execution-plan.d.ts +0 -49
  186. package/dist/types/src/cypher/execution-plan.d.ts.map +0 -1
  187. package/dist/types/src/cypher/execution-plan.test.d.ts +0 -2
  188. package/dist/types/src/cypher/execution-plan.test.d.ts.map +0 -1
  189. package/dist/types/src/cypher/index.d.ts +0 -5
  190. package/dist/types/src/cypher/index.d.ts.map +0 -1
  191. package/dist/types/src/cypher/parjs.d.ts +0 -4
  192. package/dist/types/src/cypher/parjs.d.ts.map +0 -1
  193. package/dist/types/src/cypher/parser.d.ts +0 -6
  194. package/dist/types/src/cypher/parser.d.ts.map +0 -1
  195. package/dist/types/src/cypher/query-executor.d.ts +0 -26
  196. package/dist/types/src/cypher/query-executor.d.ts.map +0 -1
  197. package/dist/types/src/cypher/query-executor.test.d.ts +0 -2
  198. package/dist/types/src/cypher/query-executor.test.d.ts.map +0 -1
  199. package/dist/types/src/cypher/schema.d.ts +0 -12
  200. package/dist/types/src/cypher/schema.d.ts.map +0 -1
  201. package/dist/types/src/cypher/schema.test.d.ts +0 -2
  202. package/dist/types/src/cypher/schema.test.d.ts.map +0 -1
  203. package/dist/types/src/testing/artifacts.test.d.ts +0 -1
  204. package/dist/types/src/testing/artifacts.test.d.ts.map +0 -1
  205. package/dist/types/src/testing/data.d.ts +0 -2
  206. package/dist/types/src/testing/data.d.ts.map +0 -1
  207. package/dist/types/src/testing/defs.d.ts +0 -5
  208. package/dist/types/src/testing/defs.d.ts.map +0 -1
  209. package/dist/types/src/testing/logger.d.ts +0 -12
  210. package/dist/types/src/testing/logger.d.ts.map +0 -1
  211. package/dist/types/src/testing/object-extraction.test.d.ts +0 -1
  212. package/dist/types/src/testing/object-extraction.test.d.ts.map +0 -1
  213. package/dist/types/src/testing/ollama.d.ts +0 -6
  214. package/dist/types/src/testing/ollama.d.ts.map +0 -1
  215. package/dist/types/src/testing/query-promts.d.ts +0 -5
  216. package/dist/types/src/testing/query-promts.d.ts.map +0 -1
  217. package/dist/types/src/testing/query.test.d.ts +0 -2
  218. package/dist/types/src/testing/query.test.d.ts.map +0 -1
  219. package/dist/types/src/testing/test-data.d.ts +0 -29
  220. package/dist/types/src/testing/test-data.d.ts.map +0 -1
  221. package/dist/types/src/testing/test-schema.d.ts +0 -50
  222. package/dist/types/src/testing/test-schema.d.ts.map +0 -1
  223. package/dist/types/src/util/index.d.ts +0 -2
  224. package/dist/types/src/util/index.d.ts.map +0 -1
  225. package/dist/types/src/util/trim.d.ts +0 -5
  226. package/dist/types/src/util/trim.d.ts.map +0 -1
  227. package/src/ai-service/client.test.ts +0 -265
  228. package/src/ai-service/defs.ts +0 -39
  229. package/src/ai-service/edge-client.ts +0 -67
  230. package/src/ai-service/index.ts +0 -13
  231. package/src/ai-service/message-collector.ts +0 -84
  232. package/src/ai-service/ollama-client.ts +0 -499
  233. package/src/ai-service/parser.ts +0 -358
  234. package/src/ai-service/service.ts +0 -15
  235. package/src/ai-service/stream.test.ts +0 -125
  236. package/src/ai-service/stream.ts +0 -118
  237. package/src/ai-service/testing/index.ts +0 -6
  238. package/src/ai-service/testing/mock.ts +0 -22
  239. package/src/ai-service/testing/test-stream.ts +0 -93
  240. package/src/ai-service/transform.ts +0 -121
  241. package/src/ai-service/types.ts +0 -103
  242. package/src/ai-service/util/index.ts +0 -5
  243. package/src/ai-service/util/sse.ts +0 -341
  244. package/src/bin/chat.ts +0 -79
  245. package/src/conversation/conversation.test.ts +0 -73
  246. package/src/conversation/conversation.ts +0 -257
  247. package/src/conversation/index.ts +0 -5
  248. package/src/conversation/types.ts +0 -129
  249. package/src/cypher/ast.ts +0 -75
  250. package/src/cypher/combinators.test.ts +0 -137
  251. package/src/cypher/combinators.ts +0 -148
  252. package/src/cypher/echo-data-source.ts +0 -105
  253. package/src/cypher/execution-plan.test.ts +0 -44
  254. package/src/cypher/execution-plan.ts +0 -208
  255. package/src/cypher/index.ts +0 -8
  256. package/src/cypher/parjs-shims.d.ts +0 -10
  257. package/src/cypher/parjs.ts +0 -10
  258. package/src/cypher/parser.ts +0 -19
  259. package/src/cypher/query-executor.test.ts +0 -47
  260. package/src/cypher/query-executor.ts +0 -145
  261. package/src/cypher/schema.test.ts +0 -17
  262. package/src/cypher/schema.ts +0 -86
  263. package/src/testing/artifacts.test.ts +0 -182
  264. package/src/testing/data.ts +0 -13
  265. package/src/testing/defs.ts +0 -9
  266. package/src/testing/logger.ts +0 -129
  267. package/src/testing/object-extraction.test.ts +0 -71
  268. package/src/testing/ollama.ts +0 -15
  269. package/src/testing/query-promts.ts +0 -75
  270. package/src/testing/query.test.ts +0 -91
  271. package/src/testing/test-data.ts +0 -372
  272. package/src/testing/test-schema.ts +0 -80
  273. package/src/util/index.ts +0 -5
  274. package/src/util/trim.ts +0 -15
  275. package/vendor/parjs-browser.mjs +0 -4
  276. package/vendor/parjs-default.mjs +0 -8
  277. /package/dist/types/{src/bin → bin}/chat.d.ts +0 -0
@@ -1,71 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- // import { AnthropicBackend } from '../conversation';
6
- // import { runLLM } from '../conversation';
7
- // import { createUserMessage } from '../conversation';
8
-
9
- // test('extract objects from the DXOS explainer', async () => {
10
- // const result = await runLLM({
11
- // model: DEFAULT_EDGE_MODEL,
12
- // messages: [
13
- // createUserMessage(`
14
- // # README
15
-
16
- // > Welcome to DXOS Composer.
17
-
18
- // Here, you can:
19
- // - Create and organize things
20
- // - Share and collaborate with others in real-time
21
- // - Work offline
22
-
23
- // Composer is:
24
- // - Free. Software built with DXOS requires no expensive server infrastructure to operate.
25
- // - Private. Your data never travels to or lives on any servers. Connections with collaborators are peer-to-peer.
26
- // - Local-first. Your data is stored entirely in your browser.
27
- // - Extensible. Add features by building plugins.
28
- // - Open source.
29
-
30
- // Your feedback is most welcome: feature requests, bug reports, questions: [Discord](https://discord.gg/uTYyx6srAW).
31
-
32
- // See also:
33
- // - [DXOS Documentation](https://docs.dxos.org) where you can build your own local-first, collaborative software.
34
- // `),
35
- // ],
36
- // system: `
37
- // <instructions>
38
- // Extract a list of objects that appear in the text.
39
- // Objects can include names, places, technologies, people, concepts, etc.
40
- // Extracts objects that are interesting or important in the context of the text.
41
- // </instructions>
42
-
43
- // <formatting>
44
- // Output a list of object names from text, each surrounded with an object <object> tag.
45
- // </formatting>
46
-
47
- // <example>
48
- // <input>
49
- // Czerniaków was born on 30 November 1880 in Warsaw, Poland (then part of the Congress Poland). He studied engineering in Warsaw and Dresden and taught in the Jewish community's vocational school in Warsaw.
50
- // </input>
51
- // <output>
52
- // <object>Czerniaków</object>
53
- // <object>30 November 1880</object>
54
- // <object>Warsaw</object>
55
- // <object>Poland</object>
56
- // <object>Congress Poland</object>
57
- // <object>engineering</object>
58
- // <object>Dresden</object>
59
- // </output>
60
- // </example>
61
- // `,
62
- // tools: [],
63
- // backend,
64
- // });
65
-
66
- // log('result', { result });
67
- // });
68
-
69
- // const backend = new AnthropicBackend({
70
- // apiKey: process.env.ANTHROPIC_API_KEY!,
71
- // });
@@ -1,15 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { DEFAULT_OLLAMA_MODEL, OllamaClient, type OllamaClientParams } from '../ai-service';
6
-
7
- /**
8
- * Create a test client with small local model and no temperature for predictable results.
9
- */
10
- export const createTestOllamaClient = (options?: Pick<OllamaClientParams, 'tools'>) => {
11
- return new OllamaClient({
12
- tools: options?.tools,
13
- overrides: { model: DEFAULT_OLLAMA_MODEL, temperature: 0 },
14
- });
15
- };
@@ -1,75 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { Schema as S } from 'effect';
6
-
7
- import { defineTool, ToolResult } from '@dxos/artifact';
8
- import { toJsonSchema } from '@dxos/echo-schema';
9
- import { log } from '@dxos/log';
10
-
11
- import { executeQuery, formatJsonSchemaForLLM, type DataSource } from '../cypher';
12
- import { trim } from '../util';
13
-
14
- export const createCypherTool = (dataSource: DataSource, schemaTypes: S.Schema.Any[] = []) =>
15
- defineTool('dxos.org/echo', {
16
- name: 'query',
17
- description:
18
- 'Query the ECHO graph database in cypher query language. Returns data from the database.' +
19
- (schemaTypes.length > 0 ? `\n\n${createSystemPrompt(schemaTypes)}` : ''),
20
- schema: S.Struct({
21
- query: S.String.annotations({
22
- description: `
23
- A valid cypher query string to execute.
24
- Query must have one MATCH clause.
25
- Match clause can have multiple patterns but they must all be connected via a relationship chain.
26
- Query might have zero or one WHERE clauses.
27
- Query must have one RETURN clause.
28
- RETURN clause can have multiple expressions separated by commas.
29
- DISTINCT keyword is not allowed.
30
-
31
- <example>
32
- MATCH (n:Person) RETURN n.name
33
- </example>
34
-
35
- <example>
36
- MATCH (s:Studio)-[:PRODUCED]->(m:Movie)-[:PRODUCED_IN]->(c:City {name: "Las Vegas"}) RETURN s
37
- </example>
38
-
39
- <example>
40
- 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
41
- </example>
42
- `,
43
- }),
44
- }),
45
- execute: async ({ query }) => {
46
- try {
47
- log('cypher query', { query });
48
- const results = await executeQuery(dataSource, query);
49
- log('query complete', { results });
50
- return ToolResult.Success(results);
51
- } catch (e: any) {
52
- log.catch(e);
53
- return ToolResult.Error(e.message);
54
- }
55
- },
56
- });
57
-
58
- export const createSystemPrompt = (schemaTypes: S.Schema.Any[]) => trim`
59
- You have access to ECHO graph database. You can query the database to get data to satisfy user prompts.
60
-
61
- Database schema is defined in pseud-cypher syntax. The schema is:
62
-
63
- <schema>
64
- ${formatJsonSchemaForLLM(schemaTypes.map((schema) => toJsonSchema(schema)))}
65
- <schema>
66
-
67
- Before replying always think step-by-step on how to proceed.
68
- Print your thoughts inside <cot> tags.
69
-
70
- <example>
71
- <cot>To answer the question I need to ...</cot>
72
- </example>
73
-
74
- Before answering the user's question, decide what tools you need to use to answer the question.
75
- `;
@@ -1,91 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { test } from 'vitest';
6
-
7
- import { createUserMessage } from '@dxos/artifact';
8
- import { EchoTestBuilder } from '@dxos/echo-db/testing';
9
- import { ObjectId } from '@dxos/echo-schema';
10
- import { SpaceId } from '@dxos/keys';
11
- import { log } from '@dxos/log';
12
-
13
- import { AI_SERVICE_ENDPOINT } from './defs';
14
- import { createLogger } from './logger';
15
- import { createCypherTool, createSystemPrompt } from './query-promts';
16
- import { createTestData, seedTestData } from './test-data';
17
- import { Contact, Org, Project, Task } from './test-schema';
18
- import { AIServiceEdgeClient, DEFAULT_EDGE_MODEL } from '../ai-service';
19
- import { runLLM } from '../conversation';
20
- import { EchoDataSource } from '../cypher';
21
-
22
- const client = new AIServiceEdgeClient({
23
- endpoint: AI_SERVICE_ENDPOINT.LOCAL,
24
- });
25
-
26
- test.skip('cypher query', async () => {
27
- const dataSource = createTestData();
28
- const schemaTypes = [Org, Project, Task, Contact];
29
-
30
- const cypherTool = createCypherTool(dataSource);
31
-
32
- const spaceId = SpaceId.random();
33
- const threadId = ObjectId.random();
34
-
35
- await client.appendMessages([
36
- createUserMessage(
37
- spaceId,
38
- threadId,
39
- 'Query the database and give me all employees from DXOS organization that work on Composer and what their tasks are.',
40
- ),
41
- ]);
42
-
43
- const result = await runLLM({
44
- model: DEFAULT_EDGE_MODEL,
45
- tools: [cypherTool],
46
- spaceId,
47
- threadId,
48
- system: createSystemPrompt(schemaTypes),
49
- client,
50
- logger: createLogger({ stream: false }),
51
- });
52
-
53
- log('DONE', { result: result.result });
54
- });
55
-
56
- test.skip('query ECHO', async () => {
57
- await using builder = await new EchoTestBuilder().open();
58
- const { db, graph } = await builder.createDatabase();
59
-
60
- const schemaTypes = [Org, Project, Task, Contact];
61
- graph.schemaRegistry.addSchema(schemaTypes);
62
-
63
- seedTestData(db);
64
- await db.flush({ indexes: true });
65
-
66
- const dataSource = new EchoDataSource(db);
67
- const cypherTool = createCypherTool(dataSource);
68
-
69
- const spaceId = SpaceId.random();
70
- const threadId = ObjectId.random();
71
-
72
- await client.appendMessages([
73
- createUserMessage(
74
- spaceId,
75
- threadId,
76
- 'Query the database and give me all employees from DXOS organization that work on Composer and what their tasks are.',
77
- ),
78
- ]);
79
-
80
- const result = await runLLM({
81
- model: DEFAULT_EDGE_MODEL,
82
- tools: [cypherTool],
83
- spaceId,
84
- threadId,
85
- system: createSystemPrompt(schemaTypes),
86
- client,
87
- logger: createLogger({ stream: false }),
88
- });
89
-
90
- log('DONE', { result: result.result });
91
- });
@@ -1,372 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { type Schema as S } from 'effect';
6
-
7
- import { raise } from '@dxos/debug';
8
- import type { EchoDatabase } from '@dxos/echo-db';
9
- import { JSON_SCHEMA_ECHO_REF_ID, ObjectId, toJsonSchema, type JsonSchemaType, type Ref } from '@dxos/echo-schema';
10
- import { invariant } from '@dxos/invariant';
11
- import { create, makeRef } from '@dxos/live-object';
12
-
13
- import {
14
- type DataSource,
15
- type Node,
16
- type Relationship,
17
- formatInferredRelationshipLabel,
18
- formatNodeLabel,
19
- } from '../cypher';
20
- import { Contact, Org, Project, Task } from '../testing';
21
-
22
- export const seedTestData = (db: EchoDatabase) => {
23
- const contactRich = db.add(
24
- create(Contact, {
25
- name: 'Rich',
26
- }),
27
- );
28
- const contactJosiah = db.add(
29
- create(Contact, {
30
- name: 'Josiah',
31
- }),
32
- );
33
- const contactDima = db.add(
34
- create(Contact, {
35
- name: 'Dima',
36
- }),
37
- );
38
- const contactFred = db.add(
39
- create(Contact, {
40
- name: 'Fred',
41
- }),
42
- );
43
-
44
- const projectComposer = db.add(
45
- create(Project, {
46
- name: 'Composer',
47
- }),
48
- );
49
- const projectEcho = db.add(
50
- create(Project, {
51
- name: 'ECHO',
52
- }),
53
- );
54
- const projectDoodles = db.add(
55
- create(Project, {
56
- name: 'Doodles',
57
- }),
58
- );
59
-
60
- const _taskComposer1 = db.add(
61
- create(Task, {
62
- name: 'Optimize startup performance',
63
- project: makeRef(projectComposer),
64
- assignee: makeRef(contactJosiah),
65
- }),
66
- );
67
- const _taskComposer2 = db.add(
68
- create(Task, {
69
- name: 'Create form builder',
70
- project: makeRef(projectComposer),
71
- assignee: makeRef(contactRich),
72
- }),
73
- );
74
- const _taskComposer3 = db.add(
75
- create(Task, {
76
- name: 'Add support for custom themes',
77
- project: makeRef(projectComposer),
78
- assignee: makeRef(contactJosiah),
79
- }),
80
- );
81
- const _taskComposer5 = db.add(
82
- create(Task, {
83
- name: 'Implement community plugin',
84
- project: makeRef(projectComposer),
85
- assignee: makeRef(contactFred),
86
- }),
87
- );
88
- const _taskComposer4 = db.add(
89
- create(Task, {
90
- name: 'Implement dark mode',
91
- project: makeRef(projectComposer),
92
- assignee: makeRef(contactRich),
93
- }),
94
- );
95
- const _taskEcho1 = db.add(
96
- create(Task, {
97
- name: 'Implement cypher query engine',
98
- project: makeRef(projectEcho),
99
- assignee: makeRef(contactDima),
100
- }),
101
- );
102
- const _taskEcho2 = db.add(
103
- create(Task, {
104
- name: 'Add schema editor',
105
- project: makeRef(projectEcho),
106
- assignee: makeRef(contactRich),
107
- }),
108
- );
109
- const _taskDoodles1 = db.add(
110
- create(Task, {
111
- name: 'Add support for custom themes',
112
- project: makeRef(projectDoodles),
113
- assignee: makeRef(contactFred),
114
- }),
115
- );
116
- const _taskDoodles2 = db.add(
117
- create(Task, {
118
- name: 'Implement dark mode',
119
- project: makeRef(projectDoodles),
120
- assignee: makeRef(contactJosiah),
121
- }),
122
- );
123
-
124
- const _orgDxos = db.add(
125
- create(Org, {
126
- name: 'DXOS',
127
- employees: [makeRef(contactRich), makeRef(contactJosiah), makeRef(contactDima)],
128
- projects: [makeRef(projectEcho)],
129
- }),
130
- );
131
- const _orgBraneframe = db.add(
132
- create(Org, {
133
- name: 'Braneframe',
134
- employees: [makeRef(contactJosiah), makeRef(contactRich)],
135
- projects: [makeRef(projectComposer)],
136
- }),
137
- );
138
- };
139
-
140
- // TODO(burdon): Use schema/testing.
141
- export const createTestData = (): MockDataSource => {
142
- const dataSource = new MockDataSource();
143
-
144
- const contactRich = dataSource.add(Contact, {
145
- id: ObjectId.random(),
146
- name: 'Rich',
147
- });
148
- const contactJosiah = dataSource.add(Contact, {
149
- id: ObjectId.random(),
150
- name: 'Josiah',
151
- });
152
- const contactDima = dataSource.add(Contact, {
153
- id: ObjectId.random(),
154
- name: 'Dima',
155
- });
156
- const contactFred = dataSource.add(Contact, {
157
- id: ObjectId.random(),
158
- name: 'Fred',
159
- });
160
-
161
- const projectComposer = dataSource.add(Project, {
162
- id: ObjectId.random(),
163
- name: 'Composer',
164
- });
165
- const projectEcho = dataSource.add(Project, {
166
- id: ObjectId.random(),
167
- name: 'ECHO',
168
- });
169
- const projectDoodles = dataSource.add(Project, {
170
- id: ObjectId.random(),
171
- name: 'Doodles',
172
- });
173
-
174
- const _taskComposer1 = dataSource.add(Task, {
175
- id: ObjectId.random(),
176
- name: 'Optimize startup performance',
177
- project: makeRef(projectComposer),
178
- assignee: makeRef(contactJosiah),
179
- });
180
- const _taskComposer2 = dataSource.add(Task, {
181
- id: ObjectId.random(),
182
- name: 'Create form builder',
183
- project: makeRef(projectComposer),
184
- assignee: makeRef(contactRich),
185
- });
186
- const _taskComposer3 = dataSource.add(Task, {
187
- id: ObjectId.random(),
188
- name: 'Add support for custom themes',
189
- project: makeRef(projectComposer),
190
- assignee: makeRef(contactJosiah),
191
- });
192
- const _taskComposer5 = dataSource.add(Task, {
193
- id: ObjectId.random(),
194
- name: 'Implement community plugin',
195
- project: makeRef(projectComposer),
196
- assignee: makeRef(contactFred),
197
- });
198
- const _taskComposer4 = dataSource.add(Task, {
199
- id: ObjectId.random(),
200
- name: 'Implement dark mode',
201
- project: makeRef(projectComposer),
202
- assignee: makeRef(contactRich),
203
- });
204
- const _taskEcho1 = dataSource.add(Task, {
205
- id: ObjectId.random(),
206
- name: 'Implement cypher query engine',
207
- project: makeRef(projectEcho),
208
- assignee: makeRef(contactDima),
209
- });
210
- const _taskEcho2 = dataSource.add(Task, {
211
- id: ObjectId.random(),
212
- name: 'Add schema editor',
213
- project: makeRef(projectEcho),
214
- assignee: makeRef(contactRich),
215
- });
216
- const _taskDoodles1 = dataSource.add(Task, {
217
- id: ObjectId.random(),
218
- name: 'Add support for custom themes',
219
- project: makeRef(projectDoodles),
220
- assignee: makeRef(contactFred),
221
- });
222
- const _taskDoodles2 = dataSource.add(Task, {
223
- id: ObjectId.random(),
224
- name: 'Implement dark mode',
225
- project: makeRef(projectDoodles),
226
- assignee: makeRef(contactJosiah),
227
- });
228
-
229
- const _orgDxos = dataSource.add(Org, {
230
- id: ObjectId.random(),
231
- name: 'DXOS',
232
- employees: [makeRef(contactRich), makeRef(contactJosiah), makeRef(contactDima)],
233
- projects: [makeRef(projectEcho)],
234
- });
235
- const _orgBraneframe = dataSource.add(Org, {
236
- id: ObjectId.random(),
237
- name: 'Braneframe',
238
- employees: [makeRef(contactJosiah), makeRef(contactRich)],
239
- projects: [makeRef(projectComposer)],
240
- });
241
- dataSource.computeGraph();
242
-
243
- return dataSource;
244
- };
245
-
246
- export class MockDataSource implements DataSource {
247
- objects: Record<
248
- string,
249
- {
250
- schema: S.Schema.All;
251
- typeDxn: string;
252
- id: string;
253
- data: unknown;
254
- }
255
- > = {};
256
-
257
- schema: Record<
258
- string,
259
- {
260
- json: JsonSchemaType;
261
- instance: S.Schema.All;
262
- }
263
- > = {};
264
-
265
- nodes: Node[] = [];
266
- relationships: Relationship[] = [];
267
-
268
- async getNodes({ label }: { label?: string }) {
269
- return this.nodes.filter((node) => !label || node.label === label);
270
- }
271
-
272
- async getRelationships({ label }: { label?: string }) {
273
- return this.relationships.filter((relationship) => !label || relationship.label === label);
274
- }
275
-
276
- add<S extends S.Schema.All>(schema: S, data: S.Schema.Type<S>) {
277
- invariant(typeof data.id === 'string', 'Data must have an id');
278
- const jsonSchema = toJsonSchema(schema);
279
- if (!this.schema[jsonSchema.$id!]) {
280
- this.schema[jsonSchema.$id!] = {
281
- json: jsonSchema,
282
- instance: schema,
283
- };
284
- }
285
-
286
- const typenameDxn = jsonSchema.$id ?? raise(new Error('Schema must have $id'));
287
-
288
- this.objects[data.id] = {
289
- schema,
290
- id: data.id,
291
- typeDxn: typenameDxn,
292
- data,
293
- };
294
-
295
- return data;
296
- }
297
-
298
- computeGraph() {
299
- this.nodes = [];
300
- this.relationships = [];
301
-
302
- for (const object of Object.values(this.objects)) {
303
- this.nodes.push({
304
- kind: 'node',
305
- id: object.id,
306
- label: formatNodeLabel(object.typeDxn),
307
- properties: object.data as any,
308
- });
309
- }
310
-
311
- for (const object of Object.values(this.objects)) {
312
- const schema = this.schema[object.typeDxn].json;
313
- const typenameDxn = schema.$id ?? raise(new Error('Schema must have $id'));
314
-
315
- for (const [name, propSchema] of Object.entries(schema.properties!)) {
316
- if (propSchema.$id === JSON_SCHEMA_ECHO_REF_ID) {
317
- const label = formatInferredRelationshipLabel(typenameDxn, name);
318
-
319
- const source = this.nodes.find((node) => node.id === object.id);
320
- if (!source) {
321
- continue;
322
- }
323
-
324
- const { id: targetId } = (object.data as any)[name].target;
325
-
326
- const target = this.nodes.find((node) => node.id === targetId);
327
- if (!target) {
328
- continue;
329
- }
330
-
331
- this.relationships.push({
332
- kind: 'relationship',
333
- id: `${object.id}-${name}-${target.id}`,
334
- label,
335
- properties: {},
336
- source,
337
- target,
338
- });
339
- } else if (
340
- propSchema.type === 'array' &&
341
- propSchema.items &&
342
- typeof propSchema.items === 'object' &&
343
- '$id' in propSchema.items &&
344
- propSchema.items.$id === JSON_SCHEMA_ECHO_REF_ID
345
- ) {
346
- const label = formatInferredRelationshipLabel(typenameDxn, name);
347
-
348
- const source = this.nodes.find((node) => node.id === object.id);
349
- if (!source) {
350
- continue;
351
- }
352
-
353
- for (const { id: targetId } of (object.data as any)[name].map((x: Ref<any>) => x.target)) {
354
- const target = this.nodes.find((node) => node.id === targetId);
355
- if (!target) {
356
- continue;
357
- }
358
-
359
- this.relationships.push({
360
- kind: 'relationship',
361
- id: `${object.id}-${name}-${targetId}`,
362
- label,
363
- properties: {},
364
- source,
365
- target,
366
- });
367
- }
368
- }
369
- }
370
- }
371
- }
372
- }
@@ -1,80 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { Schema as S } from 'effect';
6
-
7
- import { EntityKind, TypeAnnotationId, Ref } from '@dxos/echo-schema';
8
-
9
- // TODO(burdon): Reconcile with sdk/schema/testing.
10
- // TODO(burdon): Convert interface to type.
11
-
12
- // TODO(dmaretskyi): Extract.
13
- export const ObjectId = S.String.annotations({ description: 'The unique object identifier.' });
14
-
15
- export const Contact = S.Struct({
16
- id: ObjectId,
17
- name: S.String.annotations({ description: 'The name of the person.' }),
18
- email: S.optional(S.String).annotations({ description: 'Email address.' }),
19
- })
20
- .pipe(S.mutable)
21
- .annotations({
22
- [TypeAnnotationId]: {
23
- kind: EntityKind.Object,
24
- typename: 'example.com/type/Contact',
25
- version: '0.1.0',
26
- },
27
- description: 'Contact information.',
28
- });
29
- export interface Contact extends S.Schema.Type<typeof Contact> {}
30
-
31
- export const Project = S.Struct({
32
- id: ObjectId,
33
- name: S.String.annotations({ description: 'The name of the project.' }),
34
- description: S.optional(S.String).annotations({ description: 'The description of the project.' }),
35
- })
36
- .pipe(S.mutable)
37
- .annotations({
38
- [TypeAnnotationId]: {
39
- kind: EntityKind.Object,
40
- typename: 'example.com/type/Project',
41
- version: '0.1.0',
42
- },
43
- description: 'Contact information.',
44
- });
45
- export interface Project extends S.Schema.Type<typeof Project> {}
46
-
47
- export const Task = S.Struct({
48
- id: ObjectId,
49
- name: S.String.annotations({ description: 'The name of the task.' }),
50
- description: S.optional(S.String).annotations({ description: 'The description of the task.' }),
51
- project: Ref(Project),
52
- assignee: Ref(Contact),
53
- })
54
- .pipe(S.mutable)
55
- .annotations({
56
- [TypeAnnotationId]: {
57
- kind: EntityKind.Object,
58
- typename: 'example.com/type/Task',
59
- version: '0.1.0',
60
- },
61
- description: 'Contact information.',
62
- });
63
- export interface Task extends S.Schema.Type<typeof Task> {}
64
-
65
- export const Org = S.Struct({
66
- id: ObjectId,
67
- name: S.String.annotations({ description: 'The name of the organization.' }),
68
- projects: S.Array(Ref(Project)),
69
- employees: S.Array(Ref(Contact)),
70
- })
71
- .pipe(S.mutable)
72
- .annotations({
73
- [TypeAnnotationId]: {
74
- kind: EntityKind.Object,
75
- typename: 'example.com/type/Org',
76
- version: '0.1.0',
77
- },
78
- description: 'Contact information.',
79
- });
80
- export interface Org extends S.Schema.Type<typeof Org> {}