@ixo/common 1.1.0

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 (328) hide show
  1. package/.eslintrc.js +9 -0
  2. package/.prettierignore +3 -0
  3. package/.prettierrc.cjs +4 -0
  4. package/.turbo/turbo-build.log +4 -0
  5. package/CHANGELOG.md +76 -0
  6. package/README.md +245 -0
  7. package/dist/ai/checkpointer/index.d.ts +2 -0
  8. package/dist/ai/checkpointer/index.d.ts.map +1 -0
  9. package/dist/ai/checkpointer/index.js +2 -0
  10. package/dist/ai/checkpointer/index.js.map +1 -0
  11. package/dist/ai/index.d.ts +9 -0
  12. package/dist/ai/index.d.ts.map +1 -0
  13. package/dist/ai/index.js +9 -0
  14. package/dist/ai/index.js.map +1 -0
  15. package/dist/ai/models/index.d.ts +2 -0
  16. package/dist/ai/models/index.d.ts.map +1 -0
  17. package/dist/ai/models/index.js +2 -0
  18. package/dist/ai/models/index.js.map +1 -0
  19. package/dist/ai/models/openai.d.ts +10 -0
  20. package/dist/ai/models/openai.d.ts.map +1 -0
  21. package/dist/ai/models/openai.js +38 -0
  22. package/dist/ai/models/openai.js.map +1 -0
  23. package/dist/ai/models/openai.test.d.ts +2 -0
  24. package/dist/ai/models/openai.test.d.ts.map +1 -0
  25. package/dist/ai/models/openai.test.js +58 -0
  26. package/dist/ai/models/openai.test.js.map +1 -0
  27. package/dist/ai/nodes/create-fake-node.d.ts +2 -0
  28. package/dist/ai/nodes/create-fake-node.d.ts.map +1 -0
  29. package/dist/ai/nodes/create-fake-node.js +2 -0
  30. package/dist/ai/nodes/create-fake-node.js.map +1 -0
  31. package/dist/ai/nodes/find-docs/find-docs.prompt.d.ts +3 -0
  32. package/dist/ai/nodes/find-docs/find-docs.prompt.d.ts.map +1 -0
  33. package/dist/ai/nodes/find-docs/find-docs.prompt.js +61 -0
  34. package/dist/ai/nodes/find-docs/find-docs.prompt.js.map +1 -0
  35. package/dist/ai/nodes/find-docs/index.d.ts +3 -0
  36. package/dist/ai/nodes/find-docs/index.d.ts.map +1 -0
  37. package/dist/ai/nodes/find-docs/index.js +3 -0
  38. package/dist/ai/nodes/find-docs/index.js.map +1 -0
  39. package/dist/ai/nodes/find-docs/node.d.ts +17 -0
  40. package/dist/ai/nodes/find-docs/node.d.ts.map +1 -0
  41. package/dist/ai/nodes/find-docs/node.js +46 -0
  42. package/dist/ai/nodes/find-docs/node.js.map +1 -0
  43. package/dist/ai/nodes/generic-chat/generic-chat.node.d.ts +12 -0
  44. package/dist/ai/nodes/generic-chat/generic-chat.node.d.ts.map +1 -0
  45. package/dist/ai/nodes/generic-chat/generic-chat.node.js +34 -0
  46. package/dist/ai/nodes/generic-chat/generic-chat.node.js.map +1 -0
  47. package/dist/ai/nodes/generic-chat/generic-chat.prompt.d.ts +10 -0
  48. package/dist/ai/nodes/generic-chat/generic-chat.prompt.d.ts.map +1 -0
  49. package/dist/ai/nodes/generic-chat/generic-chat.prompt.js +58 -0
  50. package/dist/ai/nodes/generic-chat/generic-chat.prompt.js.map +1 -0
  51. package/dist/ai/nodes/generic-chat/index.d.ts +2 -0
  52. package/dist/ai/nodes/generic-chat/index.d.ts.map +1 -0
  53. package/dist/ai/nodes/generic-chat/index.js +2 -0
  54. package/dist/ai/nodes/generic-chat/index.js.map +1 -0
  55. package/dist/ai/nodes/index.d.ts +4 -0
  56. package/dist/ai/nodes/index.d.ts.map +1 -0
  57. package/dist/ai/nodes/index.js +4 -0
  58. package/dist/ai/nodes/index.js.map +1 -0
  59. package/dist/ai/semantic-router-factory/create-semantic-router.d.ts +7 -0
  60. package/dist/ai/semantic-router-factory/create-semantic-router.d.ts.map +1 -0
  61. package/dist/ai/semantic-router-factory/create-semantic-router.js +71 -0
  62. package/dist/ai/semantic-router-factory/create-semantic-router.js.map +1 -0
  63. package/dist/ai/semantic-router-factory/create-semantic-router.test.d.ts +2 -0
  64. package/dist/ai/semantic-router-factory/create-semantic-router.test.d.ts.map +1 -0
  65. package/dist/ai/semantic-router-factory/create-semantic-router.test.js +68 -0
  66. package/dist/ai/semantic-router-factory/create-semantic-router.test.js.map +1 -0
  67. package/dist/ai/semantic-router-factory/index.d.ts +4 -0
  68. package/dist/ai/semantic-router-factory/index.d.ts.map +1 -0
  69. package/dist/ai/semantic-router-factory/index.js +4 -0
  70. package/dist/ai/semantic-router-factory/index.js.map +1 -0
  71. package/dist/ai/semantic-router-factory/semantic-router-prompt.d.ts +2 -0
  72. package/dist/ai/semantic-router-factory/semantic-router-prompt.d.ts.map +1 -0
  73. package/dist/ai/semantic-router-factory/semantic-router-prompt.js +169 -0
  74. package/dist/ai/semantic-router-factory/semantic-router-prompt.js.map +1 -0
  75. package/dist/ai/semantic-router-factory/validate-routes.d.ts +2 -0
  76. package/dist/ai/semantic-router-factory/validate-routes.d.ts.map +1 -0
  77. package/dist/ai/semantic-router-factory/validate-routes.js +16 -0
  78. package/dist/ai/semantic-router-factory/validate-routes.js.map +1 -0
  79. package/dist/ai/tools/action-caller.d.ts +14 -0
  80. package/dist/ai/tools/action-caller.d.ts.map +1 -0
  81. package/dist/ai/tools/action-caller.js +12 -0
  82. package/dist/ai/tools/action-caller.js.map +1 -0
  83. package/dist/ai/tools/ask-ixo-guru/ask-ixo-guru.d.ts +25 -0
  84. package/dist/ai/tools/ask-ixo-guru/ask-ixo-guru.d.ts.map +1 -0
  85. package/dist/ai/tools/ask-ixo-guru/ask-ixo-guru.js +46 -0
  86. package/dist/ai/tools/ask-ixo-guru/ask-ixo-guru.js.map +1 -0
  87. package/dist/ai/tools/ask-ixo-guru/index.d.ts +2 -0
  88. package/dist/ai/tools/ask-ixo-guru/index.d.ts.map +1 -0
  89. package/dist/ai/tools/ask-ixo-guru/index.js +2 -0
  90. package/dist/ai/tools/ask-ixo-guru/index.js.map +1 -0
  91. package/dist/ai/tools/browser-tool-caller.d.ts +14 -0
  92. package/dist/ai/tools/browser-tool-caller.d.ts.map +1 -0
  93. package/dist/ai/tools/browser-tool-caller.js +12 -0
  94. package/dist/ai/tools/browser-tool-caller.js.map +1 -0
  95. package/dist/ai/tools/frontend-tool-caller.d.ts +10 -0
  96. package/dist/ai/tools/frontend-tool-caller.d.ts.map +1 -0
  97. package/dist/ai/tools/frontend-tool-caller.js +50 -0
  98. package/dist/ai/tools/frontend-tool-caller.js.map +1 -0
  99. package/dist/ai/tools/index.d.ts +11 -0
  100. package/dist/ai/tools/index.d.ts.map +1 -0
  101. package/dist/ai/tools/index.js +11 -0
  102. package/dist/ai/tools/index.js.map +1 -0
  103. package/dist/ai/tools/log-action-to-matrix.d.ts +13 -0
  104. package/dist/ai/tools/log-action-to-matrix.d.ts.map +1 -0
  105. package/dist/ai/tools/log-action-to-matrix.js +14 -0
  106. package/dist/ai/tools/log-action-to-matrix.js.map +1 -0
  107. package/dist/ai/tools/parser-action-tool.d.ts +8 -0
  108. package/dist/ai/tools/parser-action-tool.d.ts.map +1 -0
  109. package/dist/ai/tools/parser-action-tool.js +40 -0
  110. package/dist/ai/tools/parser-action-tool.js.map +1 -0
  111. package/dist/ai/tools/parser-browser-tool.d.ts +8 -0
  112. package/dist/ai/tools/parser-browser-tool.d.ts.map +1 -0
  113. package/dist/ai/tools/parser-browser-tool.js +38 -0
  114. package/dist/ai/tools/parser-browser-tool.js.map +1 -0
  115. package/dist/ai/tools/retriever-tool/index.d.ts +2 -0
  116. package/dist/ai/tools/retriever-tool/index.d.ts.map +1 -0
  117. package/dist/ai/tools/retriever-tool/index.js +2 -0
  118. package/dist/ai/tools/retriever-tool/index.js.map +1 -0
  119. package/dist/ai/tools/retriever-tool/retriever-tool.d.ts +18 -0
  120. package/dist/ai/tools/retriever-tool/retriever-tool.d.ts.map +1 -0
  121. package/dist/ai/tools/retriever-tool/retriever-tool.js +62 -0
  122. package/dist/ai/tools/retriever-tool/retriever-tool.js.map +1 -0
  123. package/dist/ai/tools/retriever-tool/retriever-tool.test.d.ts +2 -0
  124. package/dist/ai/tools/retriever-tool/retriever-tool.test.d.ts.map +1 -0
  125. package/dist/ai/tools/retriever-tool/retriever-tool.test.js +119 -0
  126. package/dist/ai/tools/retriever-tool/retriever-tool.test.js.map +1 -0
  127. package/dist/ai/tools/scrape-web-page.d.ts +7 -0
  128. package/dist/ai/tools/scrape-web-page.d.ts.map +1 -0
  129. package/dist/ai/tools/scrape-web-page.js +65 -0
  130. package/dist/ai/tools/scrape-web-page.js.map +1 -0
  131. package/dist/ai/tools/web-search-tool.d.ts +10 -0
  132. package/dist/ai/tools/web-search-tool.d.ts.map +1 -0
  133. package/dist/ai/tools/web-search-tool.js +30 -0
  134. package/dist/ai/tools/web-search-tool.js.map +1 -0
  135. package/dist/ai/types.d.ts +4 -0
  136. package/dist/ai/types.d.ts.map +1 -0
  137. package/dist/ai/types.js +2 -0
  138. package/dist/ai/types.js.map +1 -0
  139. package/dist/ai/utils/__tests__/chunk-arr.test.d.ts +2 -0
  140. package/dist/ai/utils/__tests__/chunk-arr.test.d.ts.map +1 -0
  141. package/dist/ai/utils/__tests__/chunk-arr.test.js +37 -0
  142. package/dist/ai/utils/__tests__/chunk-arr.test.js.map +1 -0
  143. package/dist/ai/utils/__tests__/doc-relevance-checker.test.d.ts +2 -0
  144. package/dist/ai/utils/__tests__/doc-relevance-checker.test.d.ts.map +1 -0
  145. package/dist/ai/utils/__tests__/doc-relevance-checker.test.js +80 -0
  146. package/dist/ai/utils/__tests__/doc-relevance-checker.test.js.map +1 -0
  147. package/dist/ai/utils/__tests__/doc-splitter.test.d.ts +2 -0
  148. package/dist/ai/utils/__tests__/doc-splitter.test.d.ts.map +1 -0
  149. package/dist/ai/utils/__tests__/doc-splitter.test.js +35 -0
  150. package/dist/ai/utils/__tests__/doc-splitter.test.js.map +1 -0
  151. package/dist/ai/utils/__tests__/filter-similarity-search-results.test.d.ts +2 -0
  152. package/dist/ai/utils/__tests__/filter-similarity-search-results.test.d.ts.map +1 -0
  153. package/dist/ai/utils/__tests__/filter-similarity-search-results.test.js +47 -0
  154. package/dist/ai/utils/__tests__/filter-similarity-search-results.test.js.map +1 -0
  155. package/dist/ai/utils/__tests__/json-to-yaml.test.d.ts +2 -0
  156. package/dist/ai/utils/__tests__/json-to-yaml.test.d.ts.map +1 -0
  157. package/dist/ai/utils/__tests__/json-to-yaml.test.js +63 -0
  158. package/dist/ai/utils/__tests__/json-to-yaml.test.js.map +1 -0
  159. package/dist/ai/utils/__tests__/stringify-docs.test.d.ts +2 -0
  160. package/dist/ai/utils/__tests__/stringify-docs.test.d.ts.map +1 -0
  161. package/dist/ai/utils/__tests__/stringify-docs.test.js +54 -0
  162. package/dist/ai/utils/__tests__/stringify-docs.test.js.map +1 -0
  163. package/dist/ai/utils/chunk-arr.d.ts +3 -0
  164. package/dist/ai/utils/chunk-arr.d.ts.map +1 -0
  165. package/dist/ai/utils/chunk-arr.js +13 -0
  166. package/dist/ai/utils/chunk-arr.js.map +1 -0
  167. package/dist/ai/utils/doc-relevance-checker.d.ts +10 -0
  168. package/dist/ai/utils/doc-relevance-checker.d.ts.map +1 -0
  169. package/dist/ai/utils/doc-relevance-checker.js +37 -0
  170. package/dist/ai/utils/doc-relevance-checker.js.map +1 -0
  171. package/dist/ai/utils/doc-splitter.d.ts +3 -0
  172. package/dist/ai/utils/doc-splitter.d.ts.map +1 -0
  173. package/dist/ai/utils/doc-splitter.js +20 -0
  174. package/dist/ai/utils/doc-splitter.js.map +1 -0
  175. package/dist/ai/utils/filter-similarity-search-results.d.ts +4 -0
  176. package/dist/ai/utils/filter-similarity-search-results.d.ts.map +1 -0
  177. package/dist/ai/utils/filter-similarity-search-results.js +11 -0
  178. package/dist/ai/utils/filter-similarity-search-results.js.map +1 -0
  179. package/dist/ai/utils/generate-questions-from-chunks.d.ts +15 -0
  180. package/dist/ai/utils/generate-questions-from-chunks.d.ts.map +1 -0
  181. package/dist/ai/utils/generate-questions-from-chunks.js +101 -0
  182. package/dist/ai/utils/generate-questions-from-chunks.js.map +1 -0
  183. package/dist/ai/utils/index.d.ts +11 -0
  184. package/dist/ai/utils/index.d.ts.map +1 -0
  185. package/dist/ai/utils/index.js +11 -0
  186. package/dist/ai/utils/index.js.map +1 -0
  187. package/dist/ai/utils/json-to-yaml.d.ts +2 -0
  188. package/dist/ai/utils/json-to-yaml.d.ts.map +1 -0
  189. package/dist/ai/utils/json-to-yaml.js +25 -0
  190. package/dist/ai/utils/json-to-yaml.js.map +1 -0
  191. package/dist/ai/utils/load-file.d.ts +3 -0
  192. package/dist/ai/utils/load-file.d.ts.map +1 -0
  193. package/dist/ai/utils/load-file.js +133 -0
  194. package/dist/ai/utils/load-file.js.map +1 -0
  195. package/dist/ai/utils/stringify-docs.d.ts +3 -0
  196. package/dist/ai/utils/stringify-docs.d.ts.map +1 -0
  197. package/dist/ai/utils/stringify-docs.js +6 -0
  198. package/dist/ai/utils/stringify-docs.js.map +1 -0
  199. package/dist/ai/utils/transformGraphStateMessageToListMessageResponse.d.ts +35 -0
  200. package/dist/ai/utils/transformGraphStateMessageToListMessageResponse.d.ts.map +1 -0
  201. package/dist/ai/utils/transformGraphStateMessageToListMessageResponse.js +55 -0
  202. package/dist/ai/utils/transformGraphStateMessageToListMessageResponse.js.map +1 -0
  203. package/dist/ai/utils/verify-matrix-openId-token.d.ts +6 -0
  204. package/dist/ai/utils/verify-matrix-openId-token.d.ts.map +1 -0
  205. package/dist/ai/utils/verify-matrix-openId-token.js +36 -0
  206. package/dist/ai/utils/verify-matrix-openId-token.js.map +1 -0
  207. package/dist/index.d.ts +4 -0
  208. package/dist/index.d.ts.map +1 -0
  209. package/dist/index.js +4 -0
  210. package/dist/index.js.map +1 -0
  211. package/dist/services/env/env-service.test.d.ts +2 -0
  212. package/dist/services/env/env-service.test.d.ts.map +1 -0
  213. package/dist/services/env/env-service.test.js +99 -0
  214. package/dist/services/env/env-service.test.js.map +1 -0
  215. package/dist/services/env/env.service.d.ts +11 -0
  216. package/dist/services/env/env.service.d.ts.map +1 -0
  217. package/dist/services/env/env.service.js +42 -0
  218. package/dist/services/env/env.service.js.map +1 -0
  219. package/dist/services/env/index.d.ts +2 -0
  220. package/dist/services/env/index.d.ts.map +1 -0
  221. package/dist/services/env/index.js +2 -0
  222. package/dist/services/env/index.js.map +1 -0
  223. package/dist/services/index.d.ts +5 -0
  224. package/dist/services/index.d.ts.map +1 -0
  225. package/dist/services/index.js +5 -0
  226. package/dist/services/index.js.map +1 -0
  227. package/dist/services/memory-engine/memory-engine.service.d.ts +35 -0
  228. package/dist/services/memory-engine/memory-engine.service.d.ts.map +1 -0
  229. package/dist/services/memory-engine/memory-engine.service.js +295 -0
  230. package/dist/services/memory-engine/memory-engine.service.js.map +1 -0
  231. package/dist/services/memory-engine/types.d.ts +88 -0
  232. package/dist/services/memory-engine/types.d.ts.map +1 -0
  233. package/dist/services/memory-engine/types.js +2 -0
  234. package/dist/services/memory-engine/types.js.map +1 -0
  235. package/dist/services/session-manager/dto.d.ts +40 -0
  236. package/dist/services/session-manager/dto.d.ts.map +1 -0
  237. package/dist/services/session-manager/dto.js +170 -0
  238. package/dist/services/session-manager/dto.js.map +1 -0
  239. package/dist/services/session-manager/errors.d.ts +22 -0
  240. package/dist/services/session-manager/errors.d.ts.map +1 -0
  241. package/dist/services/session-manager/errors.js +41 -0
  242. package/dist/services/session-manager/errors.js.map +1 -0
  243. package/dist/services/session-manager/index.d.ts +4 -0
  244. package/dist/services/session-manager/index.d.ts.map +1 -0
  245. package/dist/services/session-manager/index.js +4 -0
  246. package/dist/services/session-manager/index.js.map +1 -0
  247. package/dist/services/session-manager/session-manager.service.d.ts +40 -0
  248. package/dist/services/session-manager/session-manager.service.d.ts.map +1 -0
  249. package/dist/services/session-manager/session-manager.service.js +251 -0
  250. package/dist/services/session-manager/session-manager.service.js.map +1 -0
  251. package/dist/utils/get-user-subscription.d.ts +21 -0
  252. package/dist/utils/get-user-subscription.d.ts.map +1 -0
  253. package/dist/utils/get-user-subscription.js +44 -0
  254. package/dist/utils/get-user-subscription.js.map +1 -0
  255. package/dist/utils/index.d.ts +2 -0
  256. package/dist/utils/index.d.ts.map +1 -0
  257. package/dist/utils/index.js +2 -0
  258. package/dist/utils/index.js.map +1 -0
  259. package/docs/ai-module.md +84 -0
  260. package/docs/services.md +168 -0
  261. package/docs/tools.md +325 -0
  262. package/jest.config.js +6 -0
  263. package/package.json +81 -0
  264. package/src/ai/checkpointer/index.ts +1 -0
  265. package/src/ai/index.ts +8 -0
  266. package/src/ai/models/index.ts +1 -0
  267. package/src/ai/models/openai.test.ts +72 -0
  268. package/src/ai/models/openai.ts +54 -0
  269. package/src/ai/nodes/create-fake-node.ts +1 -0
  270. package/src/ai/nodes/find-docs/find-docs.prompt.ts +61 -0
  271. package/src/ai/nodes/find-docs/index.ts +2 -0
  272. package/src/ai/nodes/find-docs/node.ts +83 -0
  273. package/src/ai/nodes/generic-chat/generic-chat.node.ts +58 -0
  274. package/src/ai/nodes/generic-chat/generic-chat.prompt.ts +66 -0
  275. package/src/ai/nodes/generic-chat/index.ts +1 -0
  276. package/src/ai/nodes/index.ts +3 -0
  277. package/src/ai/semantic-router-factory/create-semantic-router.test.ts +98 -0
  278. package/src/ai/semantic-router-factory/create-semantic-router.ts +136 -0
  279. package/src/ai/semantic-router-factory/index.ts +3 -0
  280. package/src/ai/semantic-router-factory/semantic-router-prompt.ts +168 -0
  281. package/src/ai/semantic-router-factory/validate-routes.ts +26 -0
  282. package/src/ai/tools/action-caller.ts +37 -0
  283. package/src/ai/tools/ask-ixo-guru/ask-ixo-guru.ts +73 -0
  284. package/src/ai/tools/ask-ixo-guru/index.ts +1 -0
  285. package/src/ai/tools/browser-tool-caller.ts +37 -0
  286. package/src/ai/tools/frontend-tool-caller.ts +86 -0
  287. package/src/ai/tools/index.ts +10 -0
  288. package/src/ai/tools/log-action-to-matrix.ts +30 -0
  289. package/src/ai/tools/parser-action-tool.ts +61 -0
  290. package/src/ai/tools/parser-browser-tool.ts +55 -0
  291. package/src/ai/tools/retriever-tool/index.ts +1 -0
  292. package/src/ai/tools/retriever-tool/retriever-tool.test.ts +156 -0
  293. package/src/ai/tools/retriever-tool/retriever-tool.ts +107 -0
  294. package/src/ai/tools/scrape-web-page.ts +75 -0
  295. package/src/ai/tools/web-search-tool.ts +38 -0
  296. package/src/ai/types.ts +6 -0
  297. package/src/ai/utils/__tests__/chunk-arr.test.ts +46 -0
  298. package/src/ai/utils/__tests__/doc-relevance-checker.test.ts +90 -0
  299. package/src/ai/utils/__tests__/doc-splitter.test.ts +42 -0
  300. package/src/ai/utils/__tests__/filter-similarity-search-results.test.ts +57 -0
  301. package/src/ai/utils/__tests__/json-to-yaml.test.ts +70 -0
  302. package/src/ai/utils/__tests__/stringify-docs.test.ts +61 -0
  303. package/src/ai/utils/chunk-arr.ts +13 -0
  304. package/src/ai/utils/doc-relevance-checker.ts +58 -0
  305. package/src/ai/utils/doc-splitter.ts +28 -0
  306. package/src/ai/utils/filter-similarity-search-results.ts +15 -0
  307. package/src/ai/utils/generate-questions-from-chunks.ts +114 -0
  308. package/src/ai/utils/index.ts +10 -0
  309. package/src/ai/utils/json-to-yaml.ts +32 -0
  310. package/src/ai/utils/load-file.ts +170 -0
  311. package/src/ai/utils/stringify-docs.ts +14 -0
  312. package/src/ai/utils/transformGraphStateMessageToListMessageResponse.ts +108 -0
  313. package/src/ai/utils/verify-matrix-openId-token.ts +46 -0
  314. package/src/index.ts +3 -0
  315. package/src/services/env/env-service.test.ts +153 -0
  316. package/src/services/env/env.service.ts +65 -0
  317. package/src/services/env/index.ts +1 -0
  318. package/src/services/index.ts +4 -0
  319. package/src/services/memory-engine/memory-engine.service.ts +486 -0
  320. package/src/services/memory-engine/types.ts +208 -0
  321. package/src/services/session-manager/dto.ts +120 -0
  322. package/src/services/session-manager/errors.ts +56 -0
  323. package/src/services/session-manager/index.ts +3 -0
  324. package/src/services/session-manager/session-manager.service.ts +405 -0
  325. package/src/utils/get-user-subscription.ts +84 -0
  326. package/src/utils/index.ts +1 -0
  327. package/tsconfig.json +16 -0
  328. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,168 @@
1
+ # Services Documentation
2
+
3
+ ## Overview
4
+
5
+ The Services module in `@ixo/common` provides essential services for managing Matrix rooms and chat sessions. It integrates with the Matrix protocol through `@ixo/matrix` and provides type-safe operations for room and session management.
6
+
7
+ ## Core Services
8
+
9
+ ### Room Manager Service
10
+
11
+ A service for managing Matrix rooms with support for creation, retrieval, and access control.
12
+
13
+ ```typescript
14
+ import { RoomManagerService } from '@ixo/common/services';
15
+
16
+ const roomManager = new RoomManagerService();
17
+
18
+ // Create or get existing room
19
+ const roomId = await roomManager.getOrCreateRoom({
20
+ did: 'user-did',
21
+ oracleName: 'oracle-name',
22
+ userAccessToken: 'matrix-access-token',
23
+ });
24
+
25
+ // Get room by DID and oracle name
26
+ const room = await roomManager.getRoom({
27
+ did: 'user-did',
28
+ oracleName: 'oracle-name',
29
+ });
30
+ ```
31
+
32
+ #### Room Manager Capabilities
33
+
34
+ - Create new Matrix rooms
35
+ - Retrieve existing rooms by DID and oracle name
36
+ - Get or create rooms (idempotent operation)
37
+
38
+ #### Room Manager Types
39
+
40
+ ```typescript
41
+ interface CreateRoomDto {
42
+ did: string;
43
+ oracleName: string;
44
+ userAccessToken: string;
45
+ }
46
+
47
+ interface GetRoomDto {
48
+ did: string;
49
+ oracleName: string;
50
+ }
51
+ ```
52
+
53
+ ### Session Manager Service
54
+
55
+ A service for managing chat sessions with support for persistence in Matrix rooms.
56
+
57
+ ```typescript
58
+ import { SessionManagerService } from '@ixo/common/services';
59
+
60
+ const sessionManager = new SessionManagerService();
61
+
62
+ // Create new chat session
63
+ const session = await sessionManager.createSession({
64
+ did: 'user-did',
65
+ oracleName: 'oracle-name',
66
+ matrixAccessToken: 'access-token',
67
+ });
68
+
69
+ // List user's sessions
70
+ const { sessions } = await sessionManager.listSessions({
71
+ did: 'user-did',
72
+ matrixAccessToken: 'access-token',
73
+ });
74
+
75
+ // Delete a session
76
+ await sessionManager.deleteSession({
77
+ did: 'user-did',
78
+ sessionId: 'session-uuid',
79
+ matrixAccessToken: 'access-token',
80
+ });
81
+ ```
82
+
83
+ #### Session Manager Capabilities
84
+
85
+ - Create new chat sessions
86
+ - List existing sessions for a user
87
+ - Delete sessions
88
+ - Automatic session title generation using AI
89
+ - Session state persistence in Matrix rooms
90
+ - Type-safe operations with DTOs
91
+
92
+ #### Session Types
93
+
94
+ ```typescript
95
+ interface ChatSession {
96
+ sessionId: string;
97
+ oracleName: string;
98
+ title: string;
99
+ lastUpdatedAt: string;
100
+ createdAt: string;
101
+ }
102
+
103
+ interface CreateChatSessionDto {
104
+ did: string;
105
+ oracleName: string;
106
+ matrixAccessToken: string;
107
+ }
108
+
109
+ interface ListChatSessionsDto {
110
+ did: string;
111
+ matrixAccessToken: string;
112
+ }
113
+
114
+ interface DeleteChatSessionDto {
115
+ did: string;
116
+ sessionId: string;
117
+ matrixAccessToken: string;
118
+ }
119
+ ```
120
+
121
+ ## Error Handling
122
+
123
+ The services provide specific error types for common scenarios:
124
+
125
+ ```typescript
126
+ import {
127
+ NoUserRoomsFoundError,
128
+ RoomNotFoundError,
129
+ UserNotInRoomError,
130
+ } from '@ixo/common/services';
131
+
132
+ try {
133
+ await operation();
134
+ } catch (error) {
135
+ if (error instanceof NoUserRoomsFoundError) {
136
+ // Handle case where user has no rooms
137
+ } else if (error instanceof RoomNotFoundError) {
138
+ // Handle case where specific room not found
139
+ } else if (error instanceof UserNotInRoomError) {
140
+ // Handle case where user doesn't have access
141
+ }
142
+ }
143
+ ```
144
+
145
+ ## Integration with Matrix
146
+
147
+ Both services integrate with the Matrix protocol through `@ixo/matrix`:
148
+
149
+ - Uses Matrix rooms for persistence
150
+ - Leverages Matrix state events for session storage
151
+ - Handles Matrix authentication and access control
152
+ - Provides type-safe Matrix operations
153
+
154
+ ## Best Practices
155
+
156
+ ### Room Management
157
+
158
+ - Store room IDs for frequent access
159
+ - Handle room creation idempotently
160
+ - Validate user access tokens
161
+ - Use appropriate error handling
162
+
163
+ ### Session Management
164
+
165
+ - Use UUIDs for session IDs
166
+ - Handle session state updates atomically
167
+ - Implement proper cleanup for deleted sessions
168
+ - Validate session access before operations
package/docs/tools.md ADDED
@@ -0,0 +1,325 @@
1
+ # Tools and Utilities Documentation
2
+
3
+ This document provides detailed information about the tools and utilities available in the `@ixo/common` package.
4
+
5
+ ## Tools
6
+
7
+ ### Ask IXO Guru Tool
8
+
9
+ A LangChain tool for interacting with the IXO Guru AI, which provides access to IXO's internal knowledge base.
10
+
11
+ ```typescript
12
+ import { askIXOGuruTool } from '@ixo/common/ai/tools';
13
+
14
+ // Ask a question
15
+ const response = await askIXOGuruTool.invoke({
16
+ question: "What is IXO's approach to impact tokens?",
17
+ sessionId: 'uuid-v4-string', // To save the conversation to matrix
18
+ });
19
+ ```
20
+
21
+ #### Configuration
22
+
23
+ Requires the following environment variables:
24
+
25
+ ```env
26
+ IXO_GURU_QUERY_ENDPOINT=your_endpoint_url
27
+ GURU_ASSISTANCE_API_TOKEN=your_api_token
28
+ ORACLE_DID=your_oracle_did
29
+ ```
30
+
31
+ #### Response Format
32
+
33
+ ```yaml
34
+ answer: "The AI's response to your question"
35
+ sessionId: 'conversation-session-uuid'
36
+ ```
37
+
38
+ #### Error Handling
39
+
40
+ The tool handles various error scenarios:
41
+
42
+ - Missing environment variables
43
+ - API connection issues
44
+ - Invalid session IDs
45
+ - Authentication failures
46
+
47
+ ### Retriever Tool
48
+
49
+ A LangChain tool factory for creating document retrieval tools that can search and filter documents from a vector database with relevance checking.
50
+
51
+ ```typescript
52
+ import { retrieverToolFactory } from '@ixo/common/ai/tools';
53
+ import { VectorDBDataStore } from '@ixo/data-store';
54
+
55
+ // Create a retriever tool
56
+ const retriever = retrieverToolFactory({
57
+ store: vectorStore, // Your VectorDBDataStore instance
58
+ similarThreshold: 0.3, // Optional similarity threshold
59
+ filters: { category: 'tech' }, // Optional filters
60
+ map: new Map(), // Optional map to store metadata
61
+ requestId: 'unique-id', // Optional request identifier
62
+ });
63
+
64
+ // Use the tool
65
+ const docs = await retriever.invoke({
66
+ query: "What's new in AI?",
67
+ });
68
+ ```
69
+
70
+ #### Features
71
+
72
+ - Integrates with vector databases via VectorDBDataStore
73
+ - Configurable similarity threshold for initial filtering
74
+ - Additional AI-powered relevance checking for better results
75
+ - Optional metadata mapping for tracking used documents
76
+ - Support for custom filters and OpenAI models
77
+ - Returns LangChain Document objects
78
+
79
+ #### Configuration Options
80
+
81
+ ```typescript
82
+ type RetrieverToolFactoryArgs = {
83
+ model?: BaseChatModel; // Optional OpenAI model
84
+ filters?: Record<string, unknown>; // Vector store filters
85
+ similarThreshold?: number; // Similarity cutoff (default: 0.3)
86
+ store: VectorDBDataStore; // Required vector store
87
+ map?: Map<string, unknown>; // Optional metadata map
88
+ requestId?: string; // Optional request tracking
89
+ };
90
+ ```
91
+
92
+ #### Behavior
93
+
94
+ - Queries vector store with similarity search
95
+ - For threshold ≥ 0.3, performs additional AI relevance check
96
+ - Stores document metadata in provided map if configured
97
+ - Returns undefined if no documents found
98
+ - Handles errors gracefully with logging
99
+
100
+ ### Web Search Tool
101
+
102
+ A LangChain tool that provides web search capabilities using the Tavily API. This tool is optimized for comprehensive, accurate, and trusted search results.
103
+
104
+ ```typescript
105
+ import { webSearchTool } from '@ixo/common/ai/tools';
106
+
107
+ // Use in LangChain
108
+ const result = await webSearchTool.invoke({
109
+ input: "What's new in AI technology?",
110
+ });
111
+ ```
112
+
113
+ #### Features and Behavior
114
+
115
+ - Uses Tavily's AI-powered search engine
116
+ - Returns structured search results including:
117
+ - Query summary
118
+ - Top 3 most relevant results
119
+ - Each result includes title, URL, content, and publish date
120
+ - Results are formatted in YAML for better readability for AI and ovid parsing errors
121
+ - Built-in input validation using Zod
122
+
123
+ #### Web Search Configuration
124
+
125
+ Requires the `TAVILY_API_KEY` environment variable to be set:
126
+
127
+ ```env
128
+ TAVILY_API_KEY=your_api_key_here
129
+ ```
130
+
131
+ #### Web Search Response Format
132
+
133
+ ```yaml
134
+ query: 'your search query'
135
+ summary: 'AI-generated summary of search results'
136
+ results:
137
+ - title: 'Result Title'
138
+ url: 'https://result.url'
139
+ content: 'Result content snippet'
140
+ publishedAt: '2024-01-28'
141
+ ```
142
+
143
+ ## Utilities
144
+
145
+ ### File Loading Utility
146
+
147
+ A versatile utility for loading and processing various types of files, supporting both local files and URLs. It automatically handles different file formats and returns processed LangChain Document objects.
148
+
149
+ ```typescript
150
+ import { loadFile } from '@ixo/common/ai/utils';
151
+
152
+ // Load a local file
153
+ const pdfDocs = await loadFile('path/to/document.pdf');
154
+
155
+ // Load a file from URL with optional fetch options
156
+ const docsDocs = await loadFile('https://example.com/document.docx', {
157
+ headers: {
158
+ Authorization: 'Bearer token', // user OAuth token from Slack
159
+ },
160
+ });
161
+ ```
162
+
163
+ #### Supported File Types
164
+
165
+ - PDF (.pdf)
166
+ - Microsoft Word (.doc, .docx)
167
+ - Markdown (.md, .markdown)
168
+ - HTML (.html, .htm)
169
+ - Plain Text (.txt)
170
+
171
+ #### File Loading Features
172
+
173
+ - Automatic file type detection based on extension and MIME type
174
+ - Support for both local files and URLs
175
+ - Built-in error handling and logging
176
+ - Automatic text splitting using RecursiveCharacterTextSplitter
177
+ - HTML to text conversion for web content
178
+ - Returns LangChain Document objects ready for further processing
179
+
180
+ ### Document Splitter
181
+
182
+ A utility for splitting text content into manageable chunks using LangChain's RecursiveCharacterTextSplitter.
183
+
184
+ ```typescript
185
+ import { docSplitter } from '@ixo/common/ai/utils';
186
+
187
+ // Split a single string
188
+ const chunks = await docSplitter('Long text content...');
189
+
190
+ // Split multiple strings
191
+ const multiChunks = await docSplitter(['Text 1...', 'Text 2...']);
192
+ ```
193
+
194
+ #### Document Splitter Features
195
+
196
+ - Input validation using Zod
197
+ - Supports both single string and string array inputs
198
+ - Returns array of LangChain Document objects
199
+ - Automatic error handling for empty or invalid inputs
200
+
201
+ ### JSON to YAML Converter
202
+
203
+ A utility for converting JSON objects to YAML format, useful for creating human-readable configurations and outputs.
204
+
205
+ ```typescript
206
+ import { jsonToYaml } from '@ixo/common/ai/utils';
207
+
208
+ const yaml = jsonToYaml({
209
+ name: 'example',
210
+ config: {
211
+ enabled: true,
212
+ values: [1, 2, 3],
213
+ },
214
+ });
215
+ ```
216
+
217
+ ### Document Stringifier
218
+
219
+ A utility for converting LangChain Document objects to string format.
220
+
221
+ ```typescript
222
+ import { stringifyDocs } from '@ixo/common/ai/utils';
223
+
224
+ const stringified = stringifyDocs(documents);
225
+ ```
226
+
227
+ ### Array Chunking
228
+
229
+ A utility for splitting arrays into smaller chunks of a specified size.
230
+
231
+ ```typescript
232
+ import { chunkArr } from '@ixo/common/ai/utils';
233
+
234
+ const chunks = chunkArr([1, 2, 3, 4, 5], 2);
235
+ // Result: [[1, 2], [3, 4], [5]]
236
+ ```
237
+
238
+ ### Document Relevance Checker
239
+
240
+ A utility that uses LLMs to determine if a document is relevant to a given query. It's particularly useful for filtering search results and ensuring content relevance.
241
+
242
+ ```typescript
243
+ import checkDocRelevance from '@ixo/common/ai/utils';
244
+
245
+ // Check document relevance
246
+ const isRelevant = await checkDocRelevance({
247
+ doc: 'Document content or LangChain Document', // Can be string or Document
248
+ query: 'What technologies does IXO use?',
249
+ model: customModel, // Optional: defaults to OpenAI
250
+ });
251
+ ```
252
+
253
+ #### Relevance Checker Capabilities
254
+
255
+ - Accepts both string content and LangChain Document objects
256
+ - Uses structured LLM output with Zod validation
257
+ - Customizable LLM model support
258
+ - Semantic relevance checking based on content meaning
259
+ - Built-in prompt template for consistent evaluation
260
+
261
+ #### Relevance Checker Behavior
262
+
263
+ The checker evaluates relevance based on three criteria:
264
+
265
+ 1. Identifies documents completely unrelated to the query
266
+ 2. Considers documents relevant if they contain related keywords or semantic meaning
267
+ 3. Accepts partially relevant documents if they contain any related information
268
+
269
+ #### Usage Example with Custom Model
270
+
271
+ ```typescript
272
+ import { ChatOpenAI } from '@langchain/openai';
273
+ import checkDocRelevance from '@ixo/common/ai/utils';
274
+
275
+ const customModel = new ChatOpenAI({
276
+ modelName: 'gpt-4',
277
+ temperature: 0,
278
+ });
279
+
280
+ const isRelevant = await checkDocRelevance({
281
+ doc: new Document({ pageContent: 'content here' }),
282
+ query: 'your query',
283
+ model: customModel,
284
+ });
285
+ ```
286
+
287
+ ### Similarity Search Filter
288
+
289
+ A utility for filtering vector similarity search results based on a similarity threshold. This is useful for ensuring high-quality search results by removing low-similarity matches.
290
+
291
+ ```typescript
292
+ import { filterSimilaritySearchResults } from '@ixo/common/ai/utils';
293
+
294
+ // Filter search results
295
+ const results: [Document, number][] = [
296
+ [doc1, 0.8],
297
+ [doc2, 0.4],
298
+ [doc3, 0.9],
299
+ ];
300
+
301
+ const filteredDocs = filterSimilaritySearchResults(results, 0.7);
302
+ // Returns only docs with similarity >= 0.7
303
+ ```
304
+
305
+ #### Filter Capabilities
306
+
307
+ - Type-safe implementation with generics
308
+ - Works with LangChain Document objects
309
+ - Filters based on configurable threshold
310
+ - Preserves document order
311
+ - Simple and efficient filtering
312
+
313
+ #### Usage with Vector Search
314
+
315
+ ```typescript
316
+ import { filterSimilaritySearchResults } from '@ixo/common/ai/utils';
317
+ import { type Document } from '@langchain/core/documents';
318
+
319
+ // Example with vector search results
320
+ type SearchResult = [Document, number];
321
+ const searchResults: SearchResult[] = await vectorStore.similaritySearch(query);
322
+
323
+ // Filter results with similarity >= 0.8
324
+ const highQualityResults = filterSimilaritySearchResults(searchResults, 0.8);
325
+ ```
package/jest.config.js ADDED
@@ -0,0 +1,6 @@
1
+ const baseConfig = require('@ixo/jest-config/nest');
2
+
3
+ module.exports = {
4
+ ...baseConfig,
5
+ displayName: 'common',
6
+ };
package/package.json ADDED
@@ -0,0 +1,81 @@
1
+ {
2
+ "name": "@ixo/common",
3
+ "version": "1.1.0",
4
+ "private": false,
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "type": "module",
9
+ "main": "dist/index.js",
10
+ "types": "dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js",
15
+ "default": "./dist/index.js"
16
+ },
17
+ "./ai": {
18
+ "types": "./dist/ai/index.d.ts",
19
+ "import": "./dist/ai/index.js"
20
+ },
21
+ "./*": {
22
+ "types": "./dist/*.d.ts",
23
+ "import": "./dist/*.js"
24
+ }
25
+ },
26
+ "devDependencies": {
27
+ "@jest/types": "^29.6.3",
28
+ "@langchain/langgraph-checkpoint-validation": "^1.0.0",
29
+ "@testcontainers/postgresql": "^10.16.0",
30
+ "@types/better-sqlite3": "^7.6.13",
31
+ "@types/jest": "^29.5.14",
32
+ "@types/node": "^22.7.3",
33
+ "@types/store": "^2.0.5",
34
+ "better-sqlite3": "^12.4.6",
35
+ "jest": "^29.7.0",
36
+ "testcontainers": "^10.16.0",
37
+ "ts-jest": "^29.2.5",
38
+ "typescript": "^5.3.3",
39
+ "@ixo/eslint-config": "1.0.0",
40
+ "@ixo/data-store": "^1.0.1",
41
+ "@ixo/jest-config": "0.0.0",
42
+ "@ixo/typescript-config": "1.0.0",
43
+ "@ixo/oracles-events": "^1.0.1"
44
+ },
45
+ "dependencies": {
46
+ "@cosmjs/proto-signing": "^0.33.0",
47
+ "@cosmjs/stargate": "^0.33.0",
48
+ "@ixo/impactxclient-sdk": "^2.3.1",
49
+ "@langchain/community": "^1.0.4",
50
+ "@langchain/core": "1.0.6",
51
+ "@langchain/langgraph": "1.0.2",
52
+ "@langchain/langgraph-checkpoint": "^1.0.0",
53
+ "@langchain/langgraph-checkpoint-sqlite": "^1.0.0",
54
+ "@langchain/openai": "^1.1.2",
55
+ "@langchain/textsplitters": "^1.0.0",
56
+ "@tavily/core": "0.0.2",
57
+ "axios": "^1.7.9",
58
+ "axios-retry": "^4.5.0",
59
+ "class-transformer": "^0.5.1",
60
+ "class-validator": "^0.14.1",
61
+ "dotenv": "^16.4.5",
62
+ "duck-duck-scrape": "^2.2.5",
63
+ "html-to-text": "9.0.5",
64
+ "langchain": "1.0.6",
65
+ "langfuse": "^3.38.5",
66
+ "langsmith": "^0.1.61",
67
+ "mammoth": "1.8.0",
68
+ "openai": "^6.9.1",
69
+ "pdf-parse": "^1.1.1",
70
+ "playwright": "^1.51.0",
71
+ "store": "^2.0.12",
72
+ "zod": "^4.1.12",
73
+ "@ixo/logger": "0.0.2",
74
+ "@ixo/matrix": "1.1.0",
75
+ "@ixo/oracles-chain-client": "1.2.0"
76
+ },
77
+ "scripts": {
78
+ "build": "tsc && tsc-alias",
79
+ "test": "jest"
80
+ }
81
+ }
@@ -0,0 +1 @@
1
+ export * from '@langchain/langgraph-checkpoint-sqlite';
@@ -0,0 +1,8 @@
1
+ export * from './checkpointer/index.js';
2
+ export * from './models/index.js';
3
+ export * from './nodes/index.js';
4
+ export * from './semantic-router-factory/index.js';
5
+ export * from './tools/index.js';
6
+ export * from './types.js';
7
+ export * from './utils/index.js';
8
+ export { zodResponseFormat } from 'openai/helpers/zod';
@@ -0,0 +1 @@
1
+ export * from './openai.js';
@@ -0,0 +1,72 @@
1
+ import { ChatOpenAI, OpenAIEmbeddings } from '@langchain/openai';
2
+ import { getChatOpenAiModel, getOpenAiEmbeddings } from './openai.js';
3
+
4
+ // Mock environment variables
5
+ const originalEnv = process.env;
6
+
7
+ describe('OpenAI Models', () => {
8
+ beforeEach(() => {
9
+ jest.resetModules();
10
+ process.env = { ...originalEnv };
11
+ process.env.OPENAI_API_KEY = 'test-api-key';
12
+ });
13
+
14
+ afterEach(() => {
15
+ process.env = originalEnv;
16
+ });
17
+
18
+ describe('getChatOpenAiModel', () => {
19
+ it('should create a ChatOpenAI instance with default parameters', () => {
20
+ const model = getChatOpenAiModel();
21
+
22
+ expect(model).toBeInstanceOf(ChatOpenAI);
23
+ expect(model).toHaveProperty('temperature', 0.2);
24
+ expect(model).toHaveProperty('modelName', 'gpt-4o-mini');
25
+ expect(model).toHaveProperty('apiKey', 'test-api-key');
26
+ });
27
+
28
+ it('should override default parameters when provided', () => {
29
+ const customParams = {
30
+ temperature: 0.8,
31
+ model: 'gpt-4',
32
+ apiKey: 'custom-api-key',
33
+ };
34
+
35
+ const model = getChatOpenAiModel(customParams);
36
+
37
+ expect(model).toBeInstanceOf(ChatOpenAI);
38
+ expect(model).toHaveProperty('temperature', 0.8);
39
+ expect(model).toHaveProperty('modelName', 'gpt-4');
40
+ expect(model).toHaveProperty('apiKey', 'custom-api-key');
41
+ });
42
+ });
43
+
44
+ describe('getOpenAiEmbeddings', () => {
45
+ it('should create an OpenAIEmbeddings instance with default parameters', () => {
46
+ const embeddings = getOpenAiEmbeddings();
47
+ expect(embeddings).toBeInstanceOf(OpenAIEmbeddings);
48
+ expect(embeddings.model).toEqual('text-embedding-3-small');
49
+ });
50
+
51
+ it('should override default parameters when provided', () => {
52
+ const customParams = {
53
+ model: 'text-embedding-ada-002',
54
+ apiKey: 'custom-api-key',
55
+ };
56
+
57
+ const embeddings = getOpenAiEmbeddings(customParams);
58
+
59
+ expect(embeddings).toBeInstanceOf(OpenAIEmbeddings);
60
+ expect(embeddings.model).toEqual('text-embedding-ada-002');
61
+ });
62
+ });
63
+
64
+ describe('Error handling', () => {
65
+ it('should throw an error when OPENAI_API_KEY is not set', () => {
66
+ delete process.env.OPENAI_API_KEY;
67
+
68
+ expect(() => getChatOpenAiModel()).toThrow();
69
+ expect(() => getOpenAiEmbeddings()).toThrow();
70
+ });
71
+ });
72
+ });