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