@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
+ export const semanticRouterPrompt = `You are semantic router responsible for determining the next route based on the given routes and state.
2
+
3
+ **Instructions:**
4
+
5
+ 1. **Read the Input:**
6
+ - You will receive two pieces of input:
7
+ - **Routes**: A set of named routes with specific conditions that need to be evaluated.
8
+ - **State**: A set of properties that will be used to determine the next route. from the conditions provided in the routes.
9
+
10
+ 2. **Understand the Conditions Format:**
11
+ - Conditions will be provided in a human-readable format. They may involve:
12
+ - Checking the value of specific properties (e.g., "if the user type is 'admin'").
13
+ - Evaluating multiple conditions with logical connectors like "AND" or "OR" (e.g., "if the user type is 'guest' AND the access level is 'restricted'").
14
+ - Your task is to convert these human-readable conditions into logical expressions that can be evaluated programmatically.
15
+
16
+ 3. **Special Handling for Message Arrays:**
17
+ - If the state contains a 'messages' array, respect their chronological order.
18
+ - The most recent messages (at the end of the array) should have higher significance for determining intent.
19
+ - Pay special attention to the last user message as it often contains the most current intent.
20
+
21
+ 4. **Evaluate Each Route:**
22
+ - For each route, check if the current state satisfies the condition:
23
+ - Example:
24
+ - Condition: "if the user type is 'admin' AND the access level is 'full'"
25
+ - State:
26
+ \`\`\`yaml
27
+ userType: admin
28
+ accessLevel: limited
29
+ \`\`\`
30
+ - Evaluation: This condition does NOT match because \`accessLevel\` is 'limited', not 'full'.
31
+
32
+ 5. **Return the Matching Route:**
33
+ - Identify and return the name of the first route where all conditions are met.
34
+ - If no route matches, return 'undefined'.
35
+
36
+ **Example 1:**
37
+
38
+ - **Routes:**
39
+ \`\`\`yaml
40
+ adminDashboard: "if the user type is 'admin' AND the access level is 'full'"
41
+ guestAccess: "if the user type is 'guest' AND the access level is 'restricted'"
42
+ viewOnlyMode: "if the access level is 'view-only'"
43
+ \`\`\`
44
+
45
+ - **State:**
46
+ \`\`\`yaml
47
+ userType: guest
48
+ accessLevel: restricted
49
+ \`\`\`
50
+
51
+ **Evaluation:**
52
+ - **adminDashboard**: Does not match (user type is 'guest', not 'admin').
53
+ - **guestAccess**: Matches (user type is 'guest' and access level is 'restricted').
54
+ - **viewOnlyMode**: Does not match (access level is 'restricted', not 'view-only').
55
+
56
+ **Result:**
57
+ - Output: "guestAccess"
58
+
59
+ ---
60
+
61
+ **Example 2:**
62
+
63
+ - **Routes:**
64
+ \`\`\`yaml
65
+ escalateTicket: "if the ticket priority is 'high' AND the status is 'open'"
66
+ autoClose: "if the ticket status is 'resolved' AND the resolution time is less than 2 days"
67
+ notifySupervisor: "if the ticket priority is 'high' OR the customer rating is less than 3"
68
+ \`\`\`
69
+
70
+ - **State:**
71
+ \`\`\`yaml
72
+ ticketPriority: high
73
+ status: open
74
+ customerRating: 4
75
+ \`\`\`
76
+
77
+ **Evaluation:**
78
+ - **escalateTicket**: Matches (priority is 'high' and status is 'open').
79
+ - **autoClose**: Does not match (status is 'open', not 'resolved').
80
+ - **notifySupervisor**: Also matches (priority is 'high').
81
+
82
+ **Result:**
83
+ - Output: "escalateTicket" (First match found based on input order)
84
+
85
+ ---
86
+
87
+ **Example 3 (with Messages):**
88
+
89
+ - **Routes:**
90
+ \`\`\`yaml
91
+ chatMode: "if the messages contain casual conversation or greetings"
92
+ taskExecution: "if the messages indicate a specific task to be performed"
93
+ informationRequest: "if the messages contain questions about how to use the system"
94
+ \`\`\`
95
+
96
+ - **State:**
97
+ \`\`\`yaml
98
+ messages:
99
+ - sender: user
100
+ content: "Hello there!"
101
+ - sender: assistant
102
+ content: "Hi! How can I help you today?"
103
+ - sender: user
104
+ content: "I need to create a new domain for my project."
105
+ \`\`\`
106
+
107
+ **Evaluation:**
108
+ - **chatMode**: Does not match fully (initial messages were greetings, but the final message indicates a task).
109
+ - **taskExecution**: Matches (the last message clearly indicates a specific task - domain creation).
110
+ - **informationRequest**: Does not match (no questions about system usage).
111
+
112
+ **Result:**
113
+ - Output: "taskExecution" (Based on the latest user intent in the message array)
114
+
115
+ ---
116
+
117
+ **Example 4:**
118
+
119
+ - **Routes:**
120
+ \`\`\`yaml
121
+ initiateRefund: "if the order status is 'cancelled' AND the payment method is 'credit card'"
122
+ followUp: "if the order status is 'shipped' AND the delivery status is 'delayed'"
123
+ quickResolve: "if the order status is 'delivered' AND the customer feedback is 'positive'"
124
+ \`\`\`
125
+
126
+ - **State:**
127
+ \`\`\`yaml
128
+ orderStatus: shipped
129
+ deliveryStatus: delayed
130
+ paymentMethod: credit card
131
+ \`\`\`
132
+
133
+ **Evaluation:**
134
+ - **initiateRefund**: Does not match (order status is 'shipped', not 'cancelled').
135
+ - **followUp**: Matches (order status is 'shipped' and delivery status is 'delayed').
136
+ - **quickResolve**: Does not match (order status is 'shipped', not 'delivered').
137
+
138
+ **Result:**
139
+ - Output: "followUp"
140
+
141
+ **Goal:**
142
+ - Analyze the routes and state provided.
143
+ - Explain each evaluation step clearly.
144
+ - Return the correct route name or "undefined" if no match is found.
145
+
146
+ **Output Format:**
147
+ - Provide a single line output with the name of the matched route or "undefined".
148
+
149
+ **Additional Notes:**
150
+ - Be precise and ensure the evaluation logic follows the conditions specified.
151
+ - If multiple conditions are specified, all must be met for a route to be valid.
152
+ - The decision should be based on clear, logical reasoning derived from the state values.
153
+ - When messages are included, prioritize the most recent message for determining intent.
154
+ - Message ordering represents the chronological flow of conversation - later messages reflect the most current intent.
155
+
156
+ ----
157
+ YOUR MISSION IS TO RESOLVE THE ROUTE BASED ON THE STATE PROVIDED. GOOD LUCK!
158
+
159
+ - **Routes:**
160
+ \`\`\`yaml
161
+ {routes}
162
+ \`\`\`
163
+
164
+ - **State:**
165
+ \`\`\`yaml
166
+ {state}
167
+ \`\`\`
168
+ `;
@@ -0,0 +1,26 @@
1
+ export const validateRoutes = <
2
+ K extends string[],
3
+ R extends Record<string, string> = Record<string, string>,
4
+ >(
5
+ routes: R,
6
+ basedOn: K,
7
+ ): (keyof R)[] => {
8
+ const keys = Object.keys(routes) as (keyof R)[];
9
+ if (keys.length <= 1) {
10
+ throw new Error(
11
+ `The routes must have at least 2 routes ${keys.toString()} provided`,
12
+ );
13
+ }
14
+ for (const key in routes) {
15
+ const value = routes[key];
16
+
17
+ basedOn.forEach((element) => {
18
+ if (!value?.includes(element)) {
19
+ throw new Error(
20
+ `Invalid route map the value of the route ${key} must include the ${basedOn.toString()} So that the route can be resolve the path`,
21
+ );
22
+ }
23
+ });
24
+ }
25
+ return keys;
26
+ };
@@ -0,0 +1,37 @@
1
+ import { callFrontendTool } from './frontend-tool-caller.js';
2
+
3
+ export interface AgActionResult {
4
+ result?: any;
5
+ error?: string;
6
+ success: boolean;
7
+ }
8
+
9
+ export interface IAgActionCallerParams {
10
+ sessionId: string;
11
+ toolCallId: string;
12
+ toolName: string;
13
+ args: any;
14
+ timeout?: number;
15
+ }
16
+
17
+ /**
18
+ * Call an AG-UI action that executes on the frontend and wait for the result
19
+ * @param params - The parameters for the AG-UI action call
20
+ * @returns Promise that resolves with the action result
21
+ */
22
+ export async function callAgAction({
23
+ sessionId,
24
+ toolCallId,
25
+ toolName,
26
+ args,
27
+ timeout = 10000, // 10 seconds for UI actions
28
+ }: IAgActionCallerParams): Promise<any> {
29
+ return callFrontendTool({
30
+ sessionId,
31
+ toolId: toolCallId,
32
+ toolName,
33
+ args,
34
+ toolType: 'agui',
35
+ timeout,
36
+ });
37
+ }
@@ -0,0 +1,73 @@
1
+ import { tool } from '@langchain/core/tools';
2
+ import z from 'zod';
3
+ import { jsonToYaml } from '../../utils/json-to-yaml.js';
4
+
5
+ export type RequestPayload = {
6
+ message: string;
7
+ did: string;
8
+ sessionId: string;
9
+ };
10
+
11
+ export type ResponsePayload = {
12
+ message: {
13
+ type: 'ai';
14
+ content: string;
15
+ };
16
+ docs: [];
17
+ sessionId: string;
18
+ };
19
+
20
+ const callGuruApi = async ({
21
+ question,
22
+ sessionId,
23
+ }: {
24
+ question: string;
25
+ sessionId: string;
26
+ }): Promise<string> => {
27
+ if (!process.env.IXO_GURU_QUERY_ENDPOINT) {
28
+ throw new Error('IXO Guru API URL is not set');
29
+ }
30
+
31
+ if (!process.env.GURU_ASSISTANCE_API_TOKEN) {
32
+ throw new Error('Guru Assistance API token is not set');
33
+ }
34
+ if (!process.env.ORACLE_DID) {
35
+ throw new Error('Oracle DID is not set');
36
+ }
37
+ const payload: RequestPayload = {
38
+ message: question,
39
+ did: process.env.ORACLE_DID ?? '',
40
+ sessionId,
41
+ };
42
+
43
+ const response = await fetch(process.env.IXO_GURU_QUERY_ENDPOINT, {
44
+ method: 'POST',
45
+ headers: {
46
+ 'Content-Type': 'application/json',
47
+ Authorization: `Bearer ${process.env.GURU_ASSISTANCE_API_TOKEN}`,
48
+ },
49
+ body: JSON.stringify(payload),
50
+ });
51
+
52
+ if (!response.ok) {
53
+ throw new Error(`Error: ${response.statusText}`);
54
+ }
55
+
56
+ const data = (await response.json()) as ResponsePayload;
57
+ return jsonToYaml({
58
+ answer: data.message.content,
59
+ sessionId: data.sessionId,
60
+ });
61
+ };
62
+
63
+ export const askIXOGuruTool = tool(callGuruApi, {
64
+ name: 'ask_guru_ai',
65
+ description:
66
+ 'Ask the IXO Guru AI a question - IXO guru has access to internal knowledge base of IXO organization this tool will return the answer and the session ID to use for chat history if you want to continue a conversation within the same session send the same session ID otherwise a new session ID',
67
+ schema: z.object({
68
+ question: z.string( 'The question to ask the IXO Guru AI',),
69
+ sessionId: z
70
+ .string( 'The session ID to use for chat history if you want to continue a conversation within the same session send the same session ID otherwise a new session ID',)
71
+ .uuid( 'Session ID must be a valid UUID',),
72
+ }),
73
+ });
@@ -0,0 +1 @@
1
+ export * from './ask-ixo-guru.js';
@@ -0,0 +1,37 @@
1
+ import { callFrontendTool } from './frontend-tool-caller.js';
2
+
3
+ export interface BrowserToolResult {
4
+ result?: any;
5
+ error?: string;
6
+ success: boolean;
7
+ }
8
+
9
+ export interface IBrowserToolCallerParams {
10
+ sessionId: string;
11
+ toolCallId: string;
12
+ toolName: string;
13
+ args: any;
14
+ timeout?: number;
15
+ }
16
+
17
+ /**
18
+ * Call a tool that executes on the browser client and wait for the result
19
+ * @param params - The parameters for the browser tool call
20
+ * @returns Promise that resolves with the tool result
21
+ */
22
+ export async function callBrowserTool({
23
+ sessionId,
24
+ toolCallId,
25
+ toolName,
26
+ args,
27
+ timeout = 15000,
28
+ }: IBrowserToolCallerParams): Promise<any> {
29
+ return callFrontendTool({
30
+ sessionId,
31
+ toolId: toolCallId,
32
+ toolName,
33
+ args,
34
+ toolType: 'browser',
35
+ timeout,
36
+ });
37
+ }
@@ -0,0 +1,86 @@
1
+ import { rootEventEmitter } from '@ixo/oracles-events';
2
+ import { BrowserToolCallEvent } from '@ixo/oracles-events';
3
+ import { ActionCallEvent } from '@ixo/oracles-events';
4
+
5
+ export interface IFrontendToolCallerParams {
6
+ sessionId: string;
7
+ toolId: string;
8
+ toolName: string;
9
+ args: any;
10
+ toolType: 'browser' | 'agui';
11
+ timeout?: number;
12
+ }
13
+
14
+ /**
15
+ * Unified function to call frontend tools (browser tools or AG-UI actions)
16
+ * and wait for their result via WebSocket
17
+ * @param params - The parameters for the frontend tool call
18
+ * @returns Promise that resolves with the tool result
19
+ */
20
+ export async function callFrontendTool({
21
+ sessionId,
22
+ toolId,
23
+ toolName,
24
+ args,
25
+ toolType,
26
+ timeout = 15000,
27
+ }: IFrontendToolCallerParams): Promise<any> {
28
+ // Step 1: Emit appropriate event based on tool type
29
+ if (toolType === 'browser') {
30
+ new BrowserToolCallEvent({
31
+ sessionId,
32
+ requestId: toolId,
33
+ toolCallId: toolId,
34
+ toolName,
35
+ args,
36
+ }).emit();
37
+ } else {
38
+ new ActionCallEvent({
39
+ sessionId,
40
+ requestId: toolId,
41
+ toolCallId: toolId,
42
+ toolName,
43
+ args,
44
+ status: 'isRunning',
45
+ } as any).emit();
46
+ }
47
+
48
+ // Step 2: Wait for result via rootEventEmitter
49
+ const resultEventName =
50
+ toolType === 'browser' ? 'browser_tool_result' : 'action_call_result';
51
+
52
+ return await new Promise((resolve, reject) => {
53
+ let timeoutHandle: NodeJS.Timeout;
54
+
55
+ const resultHandler = (data: any) => {
56
+ const receivedId = data.toolCallId;
57
+ if (receivedId === toolId) {
58
+ clearTimeout(timeoutHandle);
59
+ rootEventEmitter.removeListener(resultEventName, resultHandler);
60
+
61
+ // Handle success
62
+ if (data.error) {
63
+ reject(new Error(data.error));
64
+ } else if (toolType === 'agui' && data.result?.success === false) {
65
+ // AG-UI specific error handling
66
+ reject(new Error(data.result.error || 'Action failed'));
67
+ } else {
68
+ resolve(data.result);
69
+ }
70
+ }
71
+ };
72
+
73
+ // Listen for the specific tool result
74
+ rootEventEmitter.on(resultEventName, resultHandler);
75
+
76
+ // Set timeout
77
+ timeoutHandle = setTimeout(() => {
78
+ rootEventEmitter.removeListener(resultEventName, resultHandler);
79
+ reject(
80
+ new Error(
81
+ `${toolType === 'agui' ? 'AG-UI action' : 'Browser tool'} timeout after ${timeout}ms: ${toolName}`,
82
+ ),
83
+ );
84
+ }, timeout);
85
+ });
86
+ }
@@ -0,0 +1,10 @@
1
+ export * from './ask-ixo-guru/index.js';
2
+ export * from './browser-tool-caller.js';
3
+ export * from './parser-browser-tool.js';
4
+ export * from './retriever-tool/index.js';
5
+ export * from './scrape-web-page.js';
6
+ export * from './web-search-tool.js';
7
+ export * from './log-action-to-matrix.js';
8
+ export * from './action-caller.js';
9
+ export * from './frontend-tool-caller.js';
10
+ export * from './parser-action-tool.js';
@@ -0,0 +1,30 @@
1
+ import { Logger } from '@ixo/logger';
2
+ import { MatrixManager } from '@ixo/matrix';
3
+
4
+ const matrixManager = MatrixManager.getInstance();
5
+
6
+
7
+ interface IAction {
8
+ name: string;
9
+ args: Record<string, any>;
10
+ result: any;
11
+ error?: string;
12
+ success: boolean;
13
+ }
14
+
15
+ export async function logActionToMatrix(
16
+ action: IAction,
17
+ config: {
18
+ roomId: string;
19
+ threadId?: string;
20
+ },
21
+ ) {
22
+ if (!matrixManager.getInitializationStatus().isInitialized) {
23
+ await matrixManager.init();
24
+ }
25
+ matrixManager
26
+ .sendActionLog(config.roomId, action, config.threadId)
27
+ .catch((error) => {
28
+ Logger.error('Error sending action to matrix:', error);
29
+ });
30
+ }
@@ -0,0 +1,61 @@
1
+ import { IRunnableConfigWithRequiredFields } from '@ixo/matrix';
2
+ import { tool } from '@langchain/core/tools';
3
+ import { callAgAction } from './action-caller.js';
4
+ import { logActionToMatrix } from './log-action-to-matrix.js';
5
+
6
+ interface IParseAgActionParams {
7
+ name: string;
8
+ description: string;
9
+ schema: Record<string, any>;
10
+ }
11
+
12
+ // Helper function to parse AG-UI action into LangChain tool
13
+ export function parserActionTool(action: IParseAgActionParams) {
14
+ const { name, description, schema } = action;
15
+ return tool(
16
+ async (input, runnableConfig) => {
17
+ const { configurable } =
18
+ runnableConfig as IRunnableConfigWithRequiredFields;
19
+ const { thread_id: sessionId, requestId, configs } = configurable;
20
+
21
+ if (!sessionId) {
22
+ throw new Error('sessionId is required for AG-UI actions');
23
+ }
24
+
25
+ // Call the action and WAIT for result from frontend
26
+ const result = await callAgAction({
27
+ sessionId,
28
+ toolCallId: `ag_${requestId}`,
29
+ toolName: name,
30
+ args: input,
31
+ timeout: 5000, // 5 seconds
32
+ });
33
+
34
+ if (configs?.matrix.roomId) {
35
+ logActionToMatrix(
36
+ {
37
+ name: name,
38
+ args: input as Record<string, unknown>,
39
+ result,
40
+ success: true,
41
+ },
42
+ {
43
+ roomId: configs.matrix.roomId,
44
+ threadId: sessionId,
45
+ },
46
+ );
47
+ }
48
+
49
+ // Return the actual result from frontend
50
+ return JSON.stringify(result);
51
+ },
52
+ {
53
+ name: name,
54
+ description: description,
55
+ schema: schema,
56
+ metadata: {
57
+ actionTool: true,
58
+ },
59
+ },
60
+ );
61
+ }
@@ -0,0 +1,55 @@
1
+ import { IRunnableConfigWithRequiredFields } from '@ixo/matrix';
2
+ import { tool } from '@langchain/core/tools';
3
+ import { callBrowserTool } from './browser-tool-caller.js';
4
+ import { logActionToMatrix } from './log-action-to-matrix.js';
5
+
6
+ interface IParserBrowserToolParams {
7
+ description: string;
8
+ schema: Record<string, any>;
9
+ toolName: string;
10
+ }
11
+
12
+ export function parserBrowserTool(params: IParserBrowserToolParams) {
13
+ const { description, schema, toolName } = params;
14
+ return tool(
15
+ async (input, runnablesConfig) => {
16
+ const {
17
+ configurable: { thread_id: sessionId, requestId, configs },
18
+ } = runnablesConfig as IRunnableConfigWithRequiredFields;
19
+ if (!sessionId) {
20
+ throw new Error('sessionId is required');
21
+ }
22
+
23
+ const result = await callBrowserTool({
24
+ sessionId,
25
+ toolName,
26
+ args: input,
27
+ toolCallId: `tc-${requestId}`,
28
+ });
29
+
30
+ if (configs?.matrix.roomId) {
31
+ logActionToMatrix(
32
+ {
33
+ name: toolName,
34
+ args: input as Record<string, unknown>,
35
+ result,
36
+ success: true,
37
+ },
38
+ {
39
+ roomId: configs.matrix.roomId,
40
+ threadId: sessionId,
41
+ },
42
+ );
43
+ }
44
+ return result;
45
+ },
46
+ {
47
+ name: toolName,
48
+ description,
49
+ schema,
50
+ metadata: {
51
+ browserTool: true,
52
+ },
53
+ },
54
+ );
55
+ }
@@ -0,0 +1 @@
1
+ export * from './retriever-tool.js';