@dxos/assistant 0.8.2-main.fbd8ed0 → 0.8.2-staging.4d6ad0f

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 (289) hide show
  1. package/dist/lib/browser/index.mjs +1983 -64
  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 +1976 -63
  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 +1984 -64
  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 +79 -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 +3 -0
  18. package/dist/types/src/blueprint/logger.d.ts.map +1 -0
  19. package/dist/types/src/{ai-service/parser.d.ts → blueprint/machine.d.ts} +46 -68
  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 -2
  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 +39 -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.map +1 -0
  60. package/dist/types/src/session/index.d.ts +0 -1
  61. package/dist/types/src/session/index.d.ts.map +1 -1
  62. package/dist/types/src/session/session.d.ts +47 -22
  63. package/dist/types/src/session/session.d.ts.map +1 -1
  64. package/dist/types/src/session/version-pin.d.ts +3 -4
  65. package/dist/types/src/session/version-pin.d.ts.map +1 -1
  66. package/dist/types/src/summarization/summarization.test.d.ts +2 -0
  67. package/dist/types/src/summarization/summarization.test.d.ts.map +1 -0
  68. package/dist/types/src/testing/exa-search-1748337321991.d.ts +38 -0
  69. package/dist/types/src/testing/exa-search-1748337321991.d.ts.map +1 -0
  70. package/dist/types/src/testing/exa-search-1748337331526.d.ts +37 -0
  71. package/dist/types/src/testing/exa-search-1748337331526.d.ts.map +1 -0
  72. package/dist/types/src/testing/exa-search-1748337344119.d.ts +58 -0
  73. package/dist/types/src/testing/exa-search-1748337344119.d.ts.map +1 -0
  74. package/dist/types/src/testing/index.d.ts +2 -7
  75. package/dist/types/src/testing/index.d.ts.map +1 -1
  76. package/dist/types/src/types.d.ts +3 -0
  77. package/dist/types/src/types.d.ts.map +1 -0
  78. package/package.json +22 -38
  79. package/src/blueprint/blueprint.test.ts +142 -0
  80. package/src/blueprint/blueprint.ts +95 -0
  81. package/src/blueprint/index.ts +7 -0
  82. package/src/blueprint/logger.ts +66 -0
  83. package/src/blueprint/machine.ts +208 -0
  84. package/src/blueprint/test-data.ts +55 -0
  85. package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +95 -0
  86. package/src/extraction/extraction-llm-function/extraction-llm-function.ts +64 -0
  87. package/src/extraction/extraction-llm-function/index.ts +5 -0
  88. package/src/extraction/extraction-llm-function/instructions.tpl +28 -0
  89. package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +115 -0
  90. package/src/extraction/extraction-ner-function/extraction-ner-function.ts +54 -0
  91. package/src/extraction/extraction-ner-function/index.ts +6 -0
  92. package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +94 -0
  93. package/src/extraction/extraction-ner-function/named-entity-recognition.ts +97 -0
  94. package/src/extraction/extraction.ts +75 -0
  95. package/src/extraction/index.ts +8 -0
  96. package/src/extraction/quotes.test.ts +27 -0
  97. package/src/extraction/quotes.ts +57 -0
  98. package/src/index.ts +4 -4
  99. package/src/research/exa.ts +100 -0
  100. package/src/research/graph.test.ts +15 -0
  101. package/src/research/graph.ts +291 -0
  102. package/src/research/index.ts +7 -0
  103. package/src/research/instructions-research.tpl +97 -0
  104. package/src/research/research.test.ts +189 -0
  105. package/src/research/research.ts +89 -0
  106. package/src/session/index.ts +0 -1
  107. package/src/session/session.test.ts +7 -7
  108. package/src/session/session.ts +46 -19
  109. package/src/session/version-pin.ts +2 -3
  110. package/src/summarization/summarization.test.ts +216 -0
  111. package/src/testing/exa-search-1748337321991.ts +131 -0
  112. package/src/testing/exa-search-1748337331526.ts +144 -0
  113. package/src/testing/exa-search-1748337344119.ts +133 -0
  114. package/src/testing/index.ts +8 -8
  115. package/src/types.ts +8 -0
  116. package/src/typings.d.ts +8 -0
  117. package/dist/lib/browser/chunk-B4HAWUFW.mjs +0 -2786
  118. package/dist/lib/browser/chunk-B4HAWUFW.mjs.map +0 -7
  119. package/dist/lib/browser/testing/index.mjs +0 -658
  120. package/dist/lib/browser/testing/index.mjs.map +0 -7
  121. package/dist/lib/node/chunk-NOB7CIIC.cjs +0 -2791
  122. package/dist/lib/node/chunk-NOB7CIIC.cjs.map +0 -7
  123. package/dist/lib/node/testing/index.cjs +0 -672
  124. package/dist/lib/node/testing/index.cjs.map +0 -7
  125. package/dist/lib/node-esm/chunk-SAWYU3V5.mjs +0 -2788
  126. package/dist/lib/node-esm/chunk-SAWYU3V5.mjs.map +0 -7
  127. package/dist/lib/node-esm/testing/index.mjs +0 -659
  128. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  129. package/dist/types/src/ai-service/client.test.d.ts +0 -2
  130. package/dist/types/src/ai-service/client.test.d.ts.map +0 -1
  131. package/dist/types/src/ai-service/defs.d.ts +0 -9
  132. package/dist/types/src/ai-service/defs.d.ts.map +0 -1
  133. package/dist/types/src/ai-service/edge-client.d.ts +0 -18
  134. package/dist/types/src/ai-service/edge-client.d.ts.map +0 -1
  135. package/dist/types/src/ai-service/index.d.ts +0 -10
  136. package/dist/types/src/ai-service/index.d.ts.map +0 -1
  137. package/dist/types/src/ai-service/message-collector.d.ts +0 -82
  138. package/dist/types/src/ai-service/message-collector.d.ts.map +0 -1
  139. package/dist/types/src/ai-service/ollama-client.d.ts +0 -43
  140. package/dist/types/src/ai-service/ollama-client.d.ts.map +0 -1
  141. package/dist/types/src/ai-service/parser.d.ts.map +0 -1
  142. package/dist/types/src/ai-service/service.d.ts +0 -25
  143. package/dist/types/src/ai-service/service.d.ts.map +0 -1
  144. package/dist/types/src/ai-service/stream.d.ts +0 -40
  145. package/dist/types/src/ai-service/stream.d.ts.map +0 -1
  146. package/dist/types/src/ai-service/stream.test.d.ts +0 -2
  147. package/dist/types/src/ai-service/stream.test.d.ts.map +0 -1
  148. package/dist/types/src/ai-service/testing/index.d.ts +0 -3
  149. package/dist/types/src/ai-service/testing/index.d.ts.map +0 -1
  150. package/dist/types/src/ai-service/testing/mock.d.ts +0 -11
  151. package/dist/types/src/ai-service/testing/mock.d.ts.map +0 -1
  152. package/dist/types/src/ai-service/testing/test-stream.d.ts +0 -7
  153. package/dist/types/src/ai-service/testing/test-stream.d.ts.map +0 -1
  154. package/dist/types/src/ai-service/transform.d.ts +0 -27
  155. package/dist/types/src/ai-service/transform.d.ts.map +0 -1
  156. package/dist/types/src/ai-service/types.d.ts +0 -210
  157. package/dist/types/src/ai-service/types.d.ts.map +0 -1
  158. package/dist/types/src/ai-service/util/index.d.ts +0 -2
  159. package/dist/types/src/ai-service/util/index.d.ts.map +0 -1
  160. package/dist/types/src/ai-service/util/sse.d.ts +0 -39
  161. package/dist/types/src/ai-service/util/sse.d.ts.map +0 -1
  162. package/dist/types/src/experimental/conversation/conversation.d.ts +0 -61
  163. package/dist/types/src/experimental/conversation/conversation.d.ts.map +0 -1
  164. package/dist/types/src/experimental/conversation/conversation.test.d.ts +0 -2
  165. package/dist/types/src/experimental/conversation/conversation.test.d.ts.map +0 -1
  166. package/dist/types/src/experimental/conversation/index.d.ts +0 -2
  167. package/dist/types/src/experimental/conversation/index.d.ts.map +0 -1
  168. package/dist/types/src/experimental/conversation/types.d.ts +0 -78
  169. package/dist/types/src/experimental/conversation/types.d.ts.map +0 -1
  170. package/dist/types/src/experimental/cypher/ast.d.ts +0 -56
  171. package/dist/types/src/experimental/cypher/ast.d.ts.map +0 -1
  172. package/dist/types/src/experimental/cypher/combinators.d.ts +0 -14
  173. package/dist/types/src/experimental/cypher/combinators.d.ts.map +0 -1
  174. package/dist/types/src/experimental/cypher/combinators.test.d.ts +0 -2
  175. package/dist/types/src/experimental/cypher/combinators.test.d.ts.map +0 -1
  176. package/dist/types/src/experimental/cypher/echo-data-source.d.ts +0 -16
  177. package/dist/types/src/experimental/cypher/echo-data-source.d.ts.map +0 -1
  178. package/dist/types/src/experimental/cypher/execution-plan.d.ts +0 -49
  179. package/dist/types/src/experimental/cypher/execution-plan.d.ts.map +0 -1
  180. package/dist/types/src/experimental/cypher/execution-plan.test.d.ts +0 -2
  181. package/dist/types/src/experimental/cypher/execution-plan.test.d.ts.map +0 -1
  182. package/dist/types/src/experimental/cypher/index.d.ts +0 -5
  183. package/dist/types/src/experimental/cypher/index.d.ts.map +0 -1
  184. package/dist/types/src/experimental/cypher/parjs.d.ts +0 -4
  185. package/dist/types/src/experimental/cypher/parjs.d.ts.map +0 -1
  186. package/dist/types/src/experimental/cypher/parser.d.ts +0 -6
  187. package/dist/types/src/experimental/cypher/parser.d.ts.map +0 -1
  188. package/dist/types/src/experimental/cypher/query-executor.d.ts +0 -26
  189. package/dist/types/src/experimental/cypher/query-executor.d.ts.map +0 -1
  190. package/dist/types/src/experimental/cypher/query-executor.test.d.ts +0 -2
  191. package/dist/types/src/experimental/cypher/query-executor.test.d.ts.map +0 -1
  192. package/dist/types/src/experimental/cypher/schema.d.ts +0 -12
  193. package/dist/types/src/experimental/cypher/schema.d.ts.map +0 -1
  194. package/dist/types/src/experimental/cypher/schema.test.d.ts +0 -2
  195. package/dist/types/src/experimental/cypher/schema.test.d.ts.map +0 -1
  196. package/dist/types/src/experimental/index.d.ts +0 -3
  197. package/dist/types/src/experimental/index.d.ts.map +0 -1
  198. package/dist/types/src/experimental/ner/ner.test.d.ts +0 -2
  199. package/dist/types/src/experimental/ner/ner.test.d.ts.map +0 -1
  200. package/dist/types/src/experimental/research/exa.d.ts +0 -6
  201. package/dist/types/src/experimental/research/exa.d.ts.map +0 -1
  202. package/dist/types/src/experimental/research/research.test.d.ts.map +0 -1
  203. package/dist/types/src/session/tools.d.ts +0 -18
  204. package/dist/types/src/session/tools.d.ts.map +0 -1
  205. package/dist/types/src/testing/artifacts.test.d.ts +0 -1
  206. package/dist/types/src/testing/artifacts.test.d.ts.map +0 -1
  207. package/dist/types/src/testing/data.d.ts +0 -2
  208. package/dist/types/src/testing/data.d.ts.map +0 -1
  209. package/dist/types/src/testing/defs.d.ts +0 -5
  210. package/dist/types/src/testing/defs.d.ts.map +0 -1
  211. package/dist/types/src/testing/logger.d.ts +0 -12
  212. package/dist/types/src/testing/logger.d.ts.map +0 -1
  213. package/dist/types/src/testing/object-extraction.test.d.ts +0 -1
  214. package/dist/types/src/testing/object-extraction.test.d.ts.map +0 -1
  215. package/dist/types/src/testing/ollama.d.ts +0 -6
  216. package/dist/types/src/testing/ollama.d.ts.map +0 -1
  217. package/dist/types/src/testing/printer.d.ts +0 -6
  218. package/dist/types/src/testing/printer.d.ts.map +0 -1
  219. package/dist/types/src/testing/query-promts.d.ts +0 -5
  220. package/dist/types/src/testing/query-promts.d.ts.map +0 -1
  221. package/dist/types/src/testing/query.test.d.ts +0 -2
  222. package/dist/types/src/testing/query.test.d.ts.map +0 -1
  223. package/dist/types/src/testing/test-data.d.ts +0 -29
  224. package/dist/types/src/testing/test-data.d.ts.map +0 -1
  225. package/dist/types/src/testing/test-schema.d.ts +0 -52
  226. package/dist/types/src/testing/test-schema.d.ts.map +0 -1
  227. package/dist/types/src/util/index.d.ts +0 -2
  228. package/dist/types/src/util/index.d.ts.map +0 -1
  229. package/dist/types/src/util/trim.d.ts +0 -5
  230. package/dist/types/src/util/trim.d.ts.map +0 -1
  231. package/src/ai-service/client.test.ts +0 -247
  232. package/src/ai-service/defs.ts +0 -39
  233. package/src/ai-service/edge-client.ts +0 -60
  234. package/src/ai-service/index.ts +0 -13
  235. package/src/ai-service/message-collector.ts +0 -84
  236. package/src/ai-service/ollama-client.ts +0 -506
  237. package/src/ai-service/parser.ts +0 -369
  238. package/src/ai-service/service.ts +0 -31
  239. package/src/ai-service/stream.test.ts +0 -125
  240. package/src/ai-service/stream.ts +0 -118
  241. package/src/ai-service/testing/index.ts +0 -6
  242. package/src/ai-service/testing/mock.ts +0 -30
  243. package/src/ai-service/testing/test-stream.ts +0 -93
  244. package/src/ai-service/transform.ts +0 -121
  245. package/src/ai-service/types.ts +0 -112
  246. package/src/ai-service/util/index.ts +0 -5
  247. package/src/ai-service/util/sse.ts +0 -341
  248. package/src/bin/chat.ts +0 -79
  249. package/src/experimental/conversation/conversation.test.ts +0 -73
  250. package/src/experimental/conversation/conversation.ts +0 -142
  251. package/src/experimental/conversation/index.ts +0 -5
  252. package/src/experimental/conversation/types.ts +0 -126
  253. package/src/experimental/cypher/ast.ts +0 -75
  254. package/src/experimental/cypher/combinators.test.ts +0 -137
  255. package/src/experimental/cypher/combinators.ts +0 -148
  256. package/src/experimental/cypher/echo-data-source.ts +0 -105
  257. package/src/experimental/cypher/execution-plan.test.ts +0 -44
  258. package/src/experimental/cypher/execution-plan.ts +0 -208
  259. package/src/experimental/cypher/index.ts +0 -8
  260. package/src/experimental/cypher/parjs-shims.d.ts +0 -10
  261. package/src/experimental/cypher/parjs.ts +0 -10
  262. package/src/experimental/cypher/parser.ts +0 -19
  263. package/src/experimental/cypher/query-executor.test.ts +0 -47
  264. package/src/experimental/cypher/query-executor.ts +0 -145
  265. package/src/experimental/cypher/schema.test.ts +0 -17
  266. package/src/experimental/cypher/schema.ts +0 -86
  267. package/src/experimental/index.ts +0 -6
  268. package/src/experimental/ner/ner.test.ts +0 -163
  269. package/src/experimental/research/exa.ts +0 -38
  270. package/src/experimental/research/instructions.tpl +0 -64
  271. package/src/experimental/research/research.test.ts +0 -263
  272. package/src/session/tools.ts +0 -117
  273. package/src/testing/artifacts.test.ts +0 -182
  274. package/src/testing/data.ts +0 -13
  275. package/src/testing/defs.ts +0 -9
  276. package/src/testing/logger.ts +0 -129
  277. package/src/testing/object-extraction.test.ts +0 -71
  278. package/src/testing/ollama.ts +0 -15
  279. package/src/testing/printer.ts +0 -41
  280. package/src/testing/query-promts.ts +0 -75
  281. package/src/testing/query.test.ts +0 -88
  282. package/src/testing/test-data.ts +0 -379
  283. package/src/testing/test-schema.ts +0 -79
  284. package/src/util/index.ts +0 -5
  285. package/src/util/trim.ts +0 -15
  286. package/vendor/parjs-browser.mjs +0 -4
  287. package/vendor/parjs-default.mjs +0 -8
  288. /package/dist/types/{src/bin → bin}/chat.d.ts +0 -0
  289. /package/dist/types/src/{experimental/research → research}/research.test.d.ts +0 -0
package/src/bin/chat.ts DELETED
@@ -1,79 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import inquirer from 'inquirer';
6
- import { writeFileSync } from 'node:fs';
7
-
8
- import { createUserMessage } from '@dxos/artifact';
9
- import { ObjectId } from '@dxos/echo-schema';
10
- import { SpaceId } from '@dxos/keys';
11
- import { log } from '@dxos/log';
12
-
13
- import { AIServiceEdgeClient, ToolTypes, DEFAULT_EDGE_MODEL } from '../ai-service';
14
- import { runLLM } from '../experimental';
15
- import {
16
- AI_SERVICE_ENDPOINT,
17
- createLogger,
18
- createCypherTool,
19
- createSystemPrompt,
20
- createTestData,
21
- Contact,
22
- Organization,
23
- Project,
24
- Task,
25
- } from '../testing';
26
-
27
- // TOOD(burdon): Get from config.
28
- const client = new AIServiceEdgeClient({
29
- endpoint: AI_SERVICE_ENDPOINT.LOCAL,
30
- });
31
-
32
- const dataSource = createTestData();
33
-
34
- const cypherTool = createCypherTool(dataSource);
35
-
36
- const schemaTypes = [Organization, Project, Task, Contact];
37
-
38
- const spaceId = SpaceId.random();
39
- const threadId = ObjectId.random();
40
-
41
- while (true) {
42
- const prompt = await inquirer.prompt([
43
- {
44
- type: 'input',
45
- name: 'message',
46
- message: 'Enter a message:',
47
- },
48
- ]);
49
-
50
- await runLLM({
51
- model: DEFAULT_EDGE_MODEL,
52
- spaceId,
53
- threadId,
54
- system: createSystemPrompt(schemaTypes),
55
- tools: [
56
- cypherTool,
57
- {
58
- name: 'text-to-image',
59
- type: ToolTypes.TextToImage,
60
- },
61
- ],
62
- client,
63
- history: [createUserMessage(spaceId, threadId, prompt.message)],
64
- logger: createLogger({
65
- stream: true,
66
- filter: (e) => {
67
- return true;
68
- },
69
- onImage: (img) => {
70
- const path = `/tmp/image-${img.id}.jpeg`;
71
- writeFileSync(path, Buffer.from(img.source.data, 'base64'));
72
- log('Saved image', { path });
73
- // Print image in iTerm using ANSI escape sequence
74
- const imageData = img.source.data;
75
- process.stdout.write('\x1b]1337;File=inline=1:' + imageData + '\x07');
76
- },
77
- }),
78
- });
79
- }
@@ -1,73 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { Schema } from 'effect';
6
- import { describe, test } from 'vitest';
7
-
8
- import { createUserMessage, defineTool, ToolResult } from '@dxos/artifact';
9
- import { ObjectId } from '@dxos/echo-schema';
10
- import { SpaceId } from '@dxos/keys';
11
- import { log } from '@dxos/log';
12
-
13
- import { runLLM, type ConversationEvent } from './conversation';
14
- import { AIServiceEdgeClient, DEFAULT_EDGE_MODEL } from '../../ai-service';
15
- import { AI_SERVICE_ENDPOINT } from '../../testing';
16
-
17
- // TODO(burdon): Local live LLM test.
18
- describe.skip('Conversation tests', () => {
19
- const client = new AIServiceEdgeClient({
20
- endpoint: AI_SERVICE_ENDPOINT.LOCAL,
21
- });
22
-
23
- test('basic', async ({ expect }) => {
24
- const spaceId = SpaceId.random();
25
- const threadId = ObjectId.random();
26
-
27
- const result = await runLLM({
28
- model: DEFAULT_EDGE_MODEL,
29
- history: [createUserMessage(spaceId, threadId, 'Hello, how are you?')],
30
- tools: [],
31
- client,
32
- logger: messageLogger,
33
- });
34
-
35
- log('result', { result });
36
- expect(result.history.length).to.equal(2);
37
- });
38
-
39
- test('tool call', async ({ expect }) => {
40
- const custodian = defineTool('testing', {
41
- name: 'custodian',
42
- description: 'Custodian can tell you the password if you say the magic word',
43
- schema: Schema.Struct({
44
- magicWord: Schema.String.annotations({ description: 'The magic word. Should be exactly "pretty please"' }),
45
- }),
46
- execute: async ({ magicWord }) => {
47
- if (magicWord === 'pretty please') {
48
- return ToolResult.Success('The password is: "The sky is gray"');
49
- } else {
50
- return ToolResult.Error('Wrong magic word');
51
- }
52
- },
53
- });
54
-
55
- const spaceId = SpaceId.random();
56
- const threadId = ObjectId.random();
57
-
58
- const result = await runLLM({
59
- model: DEFAULT_EDGE_MODEL,
60
- history: [createUserMessage(spaceId, threadId, 'What is the password? Ask the custodian.')],
61
- tools: [custodian],
62
- client,
63
- logger: messageLogger,
64
- });
65
- log('result', { result });
66
- });
67
-
68
- const messageLogger = (event: ConversationEvent) => {
69
- if (event.type === 'message') {
70
- log('message', { message: event.message });
71
- }
72
- };
73
- });
@@ -1,142 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { type Message, type Tool } from '@dxos/artifact';
6
- import { ObjectId } from '@dxos/echo-schema';
7
- import { invariant } from '@dxos/invariant';
8
- import { type SpaceId } from '@dxos/keys';
9
- import { log } from '@dxos/log';
10
-
11
- import { type AIServiceClient, type GenerationStreamEvent, type LLMModel } from '../../ai-service';
12
-
13
- export type CreateLLMConversationParams = {
14
- model: LLMModel;
15
-
16
- spaceId?: SpaceId;
17
- threadId?: ObjectId;
18
-
19
- /**
20
- * System prompt that specifies instructions for the LLM.
21
- */
22
- system?: string;
23
-
24
- tools: Tool[];
25
- history?: Message[];
26
- client: AIServiceClient;
27
-
28
- logger?: (event: ConversationEvent) => void;
29
- };
30
-
31
- export type ConversationEvent =
32
- | {
33
- type: 'message';
34
- message: Message;
35
- }
36
- | GenerationStreamEvent;
37
-
38
- // TODO(burdon): Replace with processor from plugin-automation?
39
- export const runLLM = async (params: CreateLLMConversationParams) => {
40
- let conversationResult: any = null;
41
- const history = params.history ?? [];
42
-
43
- const generate = async () => {
44
- log('llm generate', { tools: params.tools });
45
- const beginTs = Date.now();
46
- const stream = await params.client.execStream({
47
- model: params.model,
48
- history,
49
- systemPrompt: params.system,
50
- tools: params.tools as any,
51
- });
52
-
53
- for await (const event of stream) {
54
- params.logger?.(event);
55
- }
56
-
57
- // TODO(burdon): !!!
58
- await stream.complete();
59
- const messages: Message[] = [];
60
- const message = messages.at(-1);
61
- invariant(message);
62
-
63
- log('llm result', { time: Date.now() - beginTs, message });
64
- invariant(message);
65
- params.logger?.({ type: 'message', message });
66
- history.push(
67
- ...messages.map(
68
- (message): Message => ({ ...message, content: message.content.filter((block) => block.type !== 'image') }),
69
- ),
70
- );
71
-
72
- const isToolUse = message.content.at(-1)?.type === 'tool_use';
73
- if (isToolUse) {
74
- const toolCalls = message.content.filter((block) => block.type === 'tool_use');
75
- invariant(toolCalls.length === 1);
76
- const toolCall = toolCalls[0];
77
- const tool = params.tools.find((tool) => tool.name === toolCall.name);
78
- if (!tool) {
79
- throw new Error(`Tool not found: ${toolCall.name}`);
80
- }
81
-
82
- invariant(tool.execute);
83
- const toolResult = await tool.execute(toolCall.input);
84
- switch (toolResult.kind) {
85
- case 'error': {
86
- log.warn('tool error', { message: toolResult.message });
87
- const resultMessage: Message = {
88
- id: ObjectId.random(),
89
- role: 'user',
90
- content: [
91
- {
92
- type: 'tool_result',
93
- toolUseId: toolCall.id,
94
- content: toolResult.message,
95
- isError: true,
96
- },
97
- ],
98
- };
99
- params.logger?.({ type: 'message', message: resultMessage });
100
- history.push(resultMessage);
101
-
102
- return true;
103
- }
104
-
105
- case 'success': {
106
- log('tool success', { result: toolResult.result });
107
- const resultMessage: Message = {
108
- id: ObjectId.random(),
109
- role: 'user',
110
- content: [
111
- {
112
- type: 'tool_result',
113
- toolUseId: toolCall.id,
114
- content: JSON.stringify(toolResult.result),
115
- },
116
- ],
117
- };
118
- params.logger?.({ type: 'message', message: resultMessage });
119
- history.push(resultMessage);
120
-
121
- return true;
122
- }
123
-
124
- case 'break': {
125
- log('tool break', { result: toolResult.result });
126
- conversationResult = toolResult.result;
127
- return false;
128
- }
129
- }
130
- }
131
-
132
- return false;
133
- };
134
-
135
- // eslint-disable-next-line no-empty
136
- while (await generate()) {}
137
-
138
- return {
139
- result: conversationResult,
140
- history,
141
- };
142
- };
@@ -1,5 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- export * from './conversation';
@@ -1,126 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { Schema } from 'effect';
6
-
7
- import { type Message, type MessageContentBlock } from '@dxos/artifact';
8
- import { toJsonSchema, JsonSchemaType, ObjectId } from '@dxos/echo-schema';
9
- import { log } from '@dxos/log';
10
-
11
- export const createUserMessage = (text: string): Message => ({
12
- id: ObjectId.random(),
13
- role: 'user',
14
- content: [{ type: 'text', text }],
15
- });
16
-
17
- /**
18
- * @deprecated Use {@link LLMTool} instead.
19
- */
20
- export const ToolDefinition = Schema.Struct({
21
- name: Schema.String,
22
- description: Schema.String,
23
- parameters: JsonSchemaType,
24
- execute: Schema.Any,
25
- });
26
-
27
- /**
28
- * @deprecated Use {@link LLMTool} instead.
29
- */
30
- export type ToolDefinition = {
31
- name: string;
32
- description: string;
33
- parameters: JsonSchemaType;
34
- execute: (params: unknown, context: ToolExecutionContext) => Promise<ToolResult>;
35
- };
36
-
37
- declare global {
38
- /**
39
- * Extensions to the tool execution context.
40
- *
41
- * Different modules can extend this definition to add their own properties.
42
- *
43
- * @example
44
- * ```ts
45
- * declare global {
46
- * interface ToolContextExtensions {
47
- * chess: {
48
- * board: string;
49
- * };
50
- * }
51
- * }
52
- * ```
53
- *
54
- * @see https://www.typescriptlang.org/docs/handbook/declaration-merging.html#global-augmentation
55
- */
56
- interface ToolContextExtensions {}
57
- }
58
-
59
- export type ToolExecutionContext = {
60
- extensions: ToolContextExtensions;
61
- };
62
-
63
- export type ToolResult =
64
- | { kind: 'success'; result: unknown; extractContentBlocks?: MessageContentBlock[] }
65
- | { kind: 'error'; message: string }
66
- | { kind: 'break'; result: unknown };
67
-
68
- export const ToolResult = Object.freeze({
69
- /**
70
- * The tool execution was successful.
71
- * Gives the result back to the LLM.
72
- */
73
- Success: (result: unknown, extractContentBlocks?: MessageContentBlock[]): ToolResult => ({
74
- kind: 'success',
75
- result,
76
- extractContentBlocks,
77
- }),
78
-
79
- Error: (message: string): ToolResult => ({ kind: 'error', message }),
80
- /**
81
- * Stop the conversation and return the result.
82
- */
83
- Break: (result: unknown): ToolResult => ({ kind: 'break', result }),
84
- });
85
-
86
- export type DefineToolParams<Params extends Schema.Schema.AnyNoContext> = {
87
- name: string;
88
- description: string;
89
- schema: Params;
90
- execute: (params: Schema.Schema.Type<Params>, context: ToolExecutionContext) => Promise<ToolResult>;
91
- };
92
-
93
- export const defineTool = <Params extends Schema.Schema.AnyNoContext>({
94
- name,
95
- description,
96
- schema,
97
- execute,
98
- }: DefineToolParams<Params>): ToolDefinition => {
99
- return {
100
- name,
101
- description,
102
- parameters: toFunctionParameterSchema(schema),
103
- execute: (params, context) => {
104
- const sanitized = Schema.decodeSync(schema)(params);
105
- return execute(sanitized, context);
106
- },
107
- };
108
- };
109
-
110
- /**
111
- * Adapts schems to be able to pass to AI providers.
112
- */
113
- const toFunctionParameterSchema = (schema: Schema.Schema.All) => {
114
- const jsonSchema = toJsonSchema(schema);
115
- log('tool schema', { jsonSchema });
116
- delete jsonSchema.anyOf;
117
- delete jsonSchema.$id;
118
- jsonSchema.type = 'object';
119
- jsonSchema.properties ??= {};
120
- for (const key in jsonSchema.properties) {
121
- if (typeof jsonSchema.properties![key].description !== 'string') {
122
- throw new Error(`Property missing description: ${key}`);
123
- }
124
- }
125
- return jsonSchema;
126
- };
@@ -1,75 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- // TODO(burdon): Why interface not type?
6
-
7
- export interface AstNode<Kind extends string> {
8
- astKind: Kind;
9
- }
10
-
11
- export interface Identifier extends AstNode<'Identifier'> {
12
- name: string;
13
- }
14
-
15
- export interface Property {
16
- key: Identifier;
17
- value: StringLiteral;
18
- }
19
-
20
- export interface Properties extends AstNode<'Properties'> {
21
- properties: Property[];
22
- }
23
-
24
- export interface NodePattern extends AstNode<'NodePattern'> {
25
- variable: Identifier | null;
26
- label: Identifier;
27
- properties: Properties | null;
28
- }
29
-
30
- export interface RelationshipPattern extends AstNode<'RelationshipPattern'> {
31
- variable: Identifier | null;
32
- label: Identifier;
33
- properties: Properties | null;
34
- }
35
-
36
- export interface GraphPatternConnector extends AstNode<'GraphPatternConnector'> {
37
- direction: '-' | '->' | '<-';
38
- }
39
-
40
- export interface GraphPattern extends AstNode<'GraphPattern'> {
41
- segments: (NodePattern | RelationshipPattern)[] & {
42
- separators: GraphPatternConnector[];
43
- };
44
- }
45
-
46
- export interface MatchClause extends AstNode<'MatchClause'> {
47
- pattern: GraphPattern;
48
- }
49
-
50
- export interface StringLiteral extends AstNode<'StringLiteral'> {
51
- value: string;
52
- }
53
-
54
- export interface MemberExpression extends AstNode<'MemberExpression'> {
55
- path: Identifier[];
56
- }
57
-
58
- export interface EqualsPredicate extends AstNode<'EqualsPredicate'> {
59
- left: MemberExpression;
60
- right: StringLiteral;
61
- }
62
-
63
- export interface WhereClause extends AstNode<'WhereClause'> {
64
- predicates: EqualsPredicate[];
65
- }
66
-
67
- export interface ReturnClause extends AstNode<'ReturnClause'> {
68
- fields: MemberExpression[];
69
- }
70
-
71
- export interface CypherQuery extends AstNode<'CypherQuery'> {
72
- matchClause: MatchClause;
73
- whereClause: WhereClause | null;
74
- returnClause: ReturnClause;
75
- }
@@ -1,137 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- /* eslint-disable unused-imports/no-unused-vars */
6
- /* eslint-disable @typescript-eslint/consistent-type-imports */
7
-
8
- import { createRequire } from 'node:module';
9
- import { type Parjser } from 'parjs';
10
- import { describe, test } from 'vitest';
11
-
12
- import { log } from '@dxos/log';
13
-
14
- import {
15
- cypherQuery,
16
- identifier,
17
- matchClause,
18
- nodePattern,
19
- properties,
20
- returnClause,
21
- whereClause,
22
- } from './combinators';
23
-
24
- describe('Cypher Combinators', () => {
25
- // TODO(dmaretskyi): Must be like this or it breaks vitest.
26
- const require = createRequire(import.meta.url);
27
- const { string, regexp, whitespace } = require('parjs') as typeof import('parjs');
28
- const { between, many, manySepBy, or, map, then, recover } =
29
- require('parjs/combinators') as typeof import('parjs/combinators');
30
-
31
- test('string', ({ expect }) => {
32
- expect(string('hello').parse('hello')).toMatchObject({ isOk: true });
33
- });
34
-
35
- test('string with whitespace', ({ expect }) => {
36
- const ws = whitespace(); // Parses whitespace
37
- // many;
38
- // const optionalWs = many(100)(ws);
39
-
40
- expect(string('hello').parse('hello')).toMatchObject({ isOk: true });
41
- });
42
-
43
- test('optional vairable tag', ({ expect }) => {
44
- const node = identifier.pipe(
45
- then(':'),
46
- recover(() => ({ kind: 'Soft' })),
47
- or(''),
48
- then(identifier),
49
- between('(', ')'),
50
- );
51
- const relation = identifier.pipe(
52
- then(':'),
53
- recover(() => ({ kind: 'Soft' })),
54
- or(''),
55
- then(identifier),
56
- between('[', ']'),
57
- );
58
- const parser = or(node)(relation);
59
- const input = '[a:b]';
60
- const result = parser.parse(input);
61
- log('result', { result });
62
- });
63
-
64
- test('properties', ({ expect }) => {
65
- const input = "{name: 'John'}";
66
- const result = properties.parse(input);
67
- log('result', { result });
68
- expect(result).toMatchObject({ isOk: true });
69
- });
70
-
71
- test('node pattern', ({ expect }) => {
72
- testParser(nodePattern, '(:Person)');
73
- testParser(nodePattern, '(n:Person)');
74
- testParser(nodePattern, "(n:Person {name: 'John'})");
75
- });
76
-
77
- test('match clause', ({ expect }) => {
78
- testParser(matchClause, 'MATCH (n:Person)');
79
- testParser(matchClause, 'MATCH (n:Person)-[r:KNOWS]->(m:Person)');
80
- testParser(matchClause, 'MATCH (o:Organization)-[:HAS_EMPLOYEE]->(e:Employee)');
81
- });
82
-
83
- test('where clause', ({ expect }) => {
84
- testParser(whereClause, 'WHERE n.name = "John"');
85
- testParser(whereClause, 'WHERE o.name = "DXOS" AND p.name = "Composer"');
86
- });
87
-
88
- test('return clause', ({ expect }) => {
89
- testParser(returnClause, 'RETURN n, m');
90
- testParser(returnClause, 'RETURN m.name AS employee');
91
-
92
- const cases = ['RETURN n, m'];
93
- for (const input of cases) {
94
- const result = returnClause.parse(input);
95
- log('result', { result });
96
- expect(result).toMatchObject({ isOk: true });
97
- }
98
- });
99
-
100
- test('query', async ({ expect }) => {
101
- testParser(cypherQuery, 'MATCH (n:Person) RETURN n');
102
- testParser(
103
- cypherQuery,
104
- `
105
- MATCH (n:Person {name: 'John'})-[r:KNOWS]->(m:Person)
106
- RETURN n, m
107
- `,
108
- );
109
- testParser(
110
- cypherQuery,
111
- `
112
- MATCH (n:Person)-[r:KNOWS]->(m:Person)
113
- WHERE n.name = "John"
114
- RETURN n, m
115
- `,
116
- );
117
- testParser(
118
- cypherQuery,
119
- 'MATCH (o:Organization)-[:HAS_EMPLOYEE]->(e:Employee)-[:WORKS_ON]->(p:Project) WHERE o.name = "DXOS" AND p.name = "Composer" RETURN e.name, e.id, p.name, p.id',
120
- );
121
- testParser(
122
- cypherQuery,
123
- 'MATCH (n:Organization {name: "DXOS"})-[:HAS_EMPLOYEE]->(m:Employee)<-[:WORKS_ON]-(p:Project {name: "Composer"}) RETURN m.name AS employee',
124
- );
125
- testParser(
126
- cypherQuery,
127
- "MATCH (org:Organization {name: 'DXOS'})-[:ORG_EMPLOYEES]->(c:Contact)<-[:TASK_ASSIGNEE]-(t:Task)-[:TASK_PROJECT]->(p:Project {name: 'Composer'}) RETURN c.name",
128
- );
129
- });
130
- });
131
-
132
- const testParser = (parser: Parjser<any>, input: string) => {
133
- const result = parser.parse(input);
134
- if (!result.isOk) {
135
- throw new Error(`Failed to parse: ${result}`);
136
- }
137
- };