@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 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ai/nodes/find-docs/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { type VectorDBDataStore } from '@ixo/data-store';
2
+ import { type Document } from '@langchain/core/documents';
3
+ import { type BaseMessage } from '@langchain/core/messages';
4
+ import { type RunnableConfig } from '@langchain/core/runnables';
5
+ import 'dotenv/config';
6
+ interface IFindDocsNodeRequiredState {
7
+ question: string;
8
+ docs: Document[];
9
+ messages?: BaseMessage[];
10
+ config?: {
11
+ isInternal: boolean;
12
+ };
13
+ status?: 'completed' | 'inProgress';
14
+ }
15
+ export declare const findDocsNode: (store: VectorDBDataStore) => (state: IFindDocsNodeRequiredState, config?: RunnableConfig) => Promise<Partial<IFindDocsNodeRequiredState>>;
16
+ export {};
17
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../../src/ai/nodes/find-docs/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE5D,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,eAAe,CAAC;AAQvB,UAAU,0BAA0B;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;IACzB,MAAM,CAAC,EAAE;QACP,UAAU,EAAE,OAAO,CAAC;KACrB,CAAC;IACF,MAAM,CAAC,EAAE,WAAW,GAAG,YAAY,CAAC;CACrC;AAOD,eAAO,MAAM,YAAY,GACtB,OAAO,iBAAiB,MAEvB,OAAO,0BAA0B,EACjC,SAAS,cAAc,KACtB,OAAO,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAgD7C,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { Logger } from '@ixo/logger';
2
+ import { ChatPromptTemplate } from '@langchain/core/prompts';
3
+ import 'dotenv/config';
4
+ import z from 'zod';
5
+ import { getChatOpenAiModel, retrieverToolFactory, SELF_QUERY_RAG_PROMPT, } from '../../index.js';
6
+ export const findDocsNode = (store) => async (state, config) => {
7
+ try {
8
+ const model = getChatOpenAiModel();
9
+ const modelWithTools = model.withStructuredOutput(z.object({
10
+ questions: z.array(z.string('Generated Queries')),
11
+ }));
12
+ const chain = ChatPromptTemplate.fromMessages([
13
+ ['system', SELF_QUERY_RAG_PROMPT],
14
+ [
15
+ 'user',
16
+ state.messages
17
+ ? `this is the last three messages from the user's conversation ${state.messages
18
+ .map((message) => message.content)
19
+ .slice(-3)
20
+ .join(',')}`
21
+ : state.question,
22
+ ],
23
+ ]).pipe(modelWithTools);
24
+ const response = await chain.invoke({}, config);
25
+ const retrieval = retrieverToolFactory({
26
+ filters: state.config?.isInternal
27
+ ? undefined
28
+ : { approved: true, visibility: 'public' },
29
+ store,
30
+ });
31
+ const docs = await Promise.all(response.questions.map((question) => retrieval.invoke({ query: question })));
32
+ return {
33
+ docs: docs.flat().map((value) => ({
34
+ metadata: value.metadata,
35
+ pageContent: value.pageContent.toString(),
36
+ id: value.id,
37
+ })),
38
+ status: undefined,
39
+ };
40
+ }
41
+ catch (error) {
42
+ Logger.error('Error finding docs', error);
43
+ throw error;
44
+ }
45
+ };
46
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../../../../src/ai/nodes/find-docs/node.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,eAAe,CAAC;AACvB,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AAiBxB,MAAM,CAAC,MAAM,YAAY,GACvB,CAAC,KAAwB,EAAE,EAAE,CAC7B,KAAK,EACH,KAAiC,EACjC,MAAuB,EACuB,EAAE;IAChD,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,kBAAkB,EAAE,CAAC;QACnC,MAAM,cAAc,GAAG,KAAK,CAAC,oBAAoB,CAC/C,CAAC,CAAC,MAAM,CAAC;YACP,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;SAClD,CAAC,CACH,CAAC;QAEF,MAAM,KAAK,GAAG,kBAAkB,CAAC,YAAY,CAAC;YAC5C,CAAC,QAAQ,EAAE,qBAAqB,CAAC;YACjC;gBACE,MAAM;gBACN,KAAK,CAAC,QAAQ;oBACZ,CAAC,CAAC,gEAAgE,KAAK,CAAC,QAAQ;yBAC3E,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC;yBACjC,KAAK,CAAC,CAAC,CAAC,CAAC;yBACT,IAAI,CAAC,GAAG,CAAC,EAAE;oBAChB,CAAC,CAAC,KAAK,CAAC,QAAQ;aACnB;SACF,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAExB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QAChD,MAAM,SAAS,GAAG,oBAAoB,CAAC;YACrC,OAAO,EAAE,KAAK,CAAC,MAAM,EAAE,UAAU;gBAC/B,CAAC,CAAC,SAAS;gBACX,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE;YAC5C,KAAK;SACN,CAAC,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,GAAG,CAC5B,QAAQ,CAAC,SAAS,CAAC,GAAG,CACpB,CAAC,QAAQ,EAAE,EAAE,CACX,SAAS,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAwB,CAC/D,CACF,CAAC;QAEF,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;gBAChC,QAAQ,EAAE,KAAK,CAAC,QAAQ;gBACxB,WAAW,EAAE,KAAK,CAAC,WAAW,CAAC,QAAQ,EAAE;gBACzC,EAAE,EAAE,KAAK,CAAC,EAAE;aACb,CAAC,CAAC;YACH,MAAM,EAAE,SAAS;SAClB,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;QAC1C,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { BaseMessage } from '@langchain/core/messages';
2
+ import { RunnableConfig } from '@langchain/core/runnables';
3
+ import { StructuredTool, Tool } from '@langchain/core/tools';
4
+ import { InputVariables } from './generic-chat.prompt.js';
5
+ type StateWithMessages<S extends object> = {
6
+ messages: BaseMessage[];
7
+ } & S;
8
+ export declare const createGenericChatNode: (inputVariables: InputVariables, tools: (Tool | StructuredTool)[], llm?: import("@langchain/openai").ChatOpenAI<import("@langchain/openai").ChatOpenAICallOptions>) => <S extends object>(state: StateWithMessages<S>, config?: RunnableConfig) => Promise<{
9
+ messages: import("@langchain/core/messages").AIMessageChunk<import("@langchain/core/messages").MessageStructure>[];
10
+ }>;
11
+ export {};
12
+ //# sourceMappingURL=generic-chat.node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generic-chat.node.d.ts","sourceRoot":"","sources":["../../../../src/ai/nodes/generic-chat/generic-chat.node.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAKvD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAE7D,OAAO,EAAuB,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE/E,KAAK,iBAAiB,CAAC,CAAC,SAAS,MAAM,IAAI;IACzC,QAAQ,EAAE,WAAW,EAAE,CAAC;CACzB,GAAG,CAAC,CAAC;AAEN,eAAO,MAAM,qBAAqB,GAChC,gBAAgB,cAAc,EAC9B,OAAO,CAAC,IAAI,GAAG,cAAc,CAAC,EAAE,EAChC,+FAA0B,MAEZ,CAAC,SAAS,MAAM,EAC5B,OAAO,iBAAiB,CAAC,CAAC,CAAC,EAC3B,SAAS,cAAc;;EAmC1B,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { Logger } from '@ixo/logger';
2
+ import { ChatPromptTemplate, MessagesPlaceholder, } from '@langchain/core/prompts';
3
+ import { getChatOpenAiModel } from '../../../ai/models/openai.js';
4
+ import { GENERIC_CHAT_PROMPT } from './generic-chat.prompt.js';
5
+ export const createGenericChatNode = (inputVariables, tools, llm = getChatOpenAiModel()) => {
6
+ return async (state, config) => {
7
+ Logger.debug('Generic chat node called', {
8
+ state,
9
+ config,
10
+ });
11
+ let systemPrompt = '';
12
+ try {
13
+ systemPrompt = await GENERIC_CHAT_PROMPT.format(inputVariables);
14
+ }
15
+ catch (error) {
16
+ Logger.error('Error formatting system prompt', error);
17
+ throw error;
18
+ }
19
+ const chain = ChatPromptTemplate.fromMessages([
20
+ ['system', systemPrompt],
21
+ new MessagesPlaceholder('msgs'),
22
+ ]).pipe(llm.bindTools(tools));
23
+ const result = await chain.invoke({
24
+ msgs: state.messages,
25
+ }, config);
26
+ Logger.debug('Generic chat node result', {
27
+ result,
28
+ });
29
+ return {
30
+ messages: [result],
31
+ };
32
+ };
33
+ };
34
+ //# sourceMappingURL=generic-chat.node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generic-chat.node.js","sourceRoot":"","sources":["../../../../src/ai/nodes/generic-chat/generic-chat.node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EACL,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAkB,MAAM,0BAA0B,CAAC;AAM/E,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,cAA8B,EAC9B,KAAgC,EAChC,GAAG,GAAG,kBAAkB,EAAE,EAC1B,EAAE;IACF,OAAO,KAAK,EACV,KAA2B,EAC3B,MAAuB,EACvB,EAAE;QACF,MAAM,CAAC,KAAK,CAAC,0BAA0B,EAAE;YACvC,KAAK;YACL,MAAM;SACP,CAAC,CAAC;QAEH,IAAI,YAAY,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC;YACH,YAAY,GAAG,MAAM,mBAAmB,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;QAClE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;YACtD,MAAM,KAAK,CAAC;QACd,CAAC;QAED,MAAM,KAAK,GAAG,kBAAkB,CAAC,YAAY,CAAC;YAC5C,CAAC,QAAQ,EAAE,YAAY,CAAC;YACxB,IAAI,mBAAmB,CAAC,MAAM,CAAC;SAChC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;QAE9B,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,MAAM,CAC/B;YACE,IAAI,EAAE,KAAK,CAAC,QAAQ;SACrB,EACD,MAAM,CACP,CAAC;QAEF,MAAM,CAAC,KAAK,CAAC,0BAA0B,EAAE;YACvC,MAAM;SACP,CAAC,CAAC;QAEH,OAAO;YACL,QAAQ,EAAE,CAAC,MAAM,CAAC;SACnB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { PromptTemplate } from '@langchain/core/prompts';
2
+ export type InputVariables = {
3
+ APP_NAME: string;
4
+ APP_PURPOSE: string;
5
+ APP_MAIN_FEATURES: string;
6
+ APP_TARGET_USERS: string;
7
+ APP_UNIQUE_SELLING_POINTS: string;
8
+ };
9
+ export declare const GENERIC_CHAT_PROMPT: PromptTemplate<InputVariables, never>;
10
+ //# sourceMappingURL=generic-chat.prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generic-chat.prompt.d.ts","sourceRoot":"","sources":["../../../../src/ai/nodes/generic-chat/generic-chat.prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,MAAM,CAAC;IACzB,yBAAyB,EAAE,MAAM,CAAC;CACnC,CAAC;AAEF,eAAO,MAAM,mBAAmB,uCAuD9B,CAAC"}
@@ -0,0 +1,58 @@
1
+ import { PromptTemplate } from '@langchain/core/prompts';
2
+ export const GENERIC_CHAT_PROMPT = new PromptTemplate({
3
+ template: `# IXO AI Assistant: Expert Guide and Conversational Partner
4
+
5
+ ## Your Identity
6
+ You are an AI assistant for the IXO Organization. Your primary role is to engage users in friendly, natural conversations, offering casual and informative chitchat. You can discuss various topics to keep conversations engaging and approachable.
7
+
8
+ Additionally, you have detailed knowledge about the app hosting you. Below is essential information about the hosting app that you can refer to when responding to user inquiries about it:
9
+
10
+ ## App Information
11
+ ### App Details
12
+ - **App Name**: {{APP_NAME}}
13
+ - **App Purpose**: {{APP_PURPOSE}}
14
+ - **Main Features**: {{APP_MAIN_FEATURES}}
15
+ - **Target Users**: {{APP_TARGET_USERS}}
16
+ - **Unique Selling Points**: {{APP_UNIQUE_SELLING_POINTS}}
17
+
18
+
19
+ ## Your Capabilities
20
+ - Provide detailed information about the IXO app and ecosystem
21
+ - Engage in natural, friendly conversation on various topics
22
+ - Explain complex concepts in accessible language
23
+ - Guide users through app features when they express interest
24
+ - Offer relevant suggestions based on user inquiries
25
+
26
+ ## Communication Style
27
+ - **Tone**: Professional yet warm, conversational, and engaging
28
+ - **Language**: Clear, concise, and jargon-free unless requested
29
+ - **Personality**: Helpful, patient, and slightly enthusiastic
30
+ - **Responses**: Informative but concise, typically 2-4 sentences
31
+
32
+ ## Interaction Guidelines
33
+ - Begin responses with direct answers to user questions
34
+ - When discussing app features, provide concrete examples of how they benefit users
35
+ - For complex topics, use analogies or step-by-step explanations
36
+ - If uncertain about a specific app detail, acknowledge this transparently
37
+ - Balance informative content with conversational elements
38
+ - Proactively suggest relevant app features when appropriate
39
+ - Personalize responses based on user's demonstrated knowledge level
40
+
41
+ ## What to Avoid
42
+ - Making claims about app capabilities not listed in your knowledge base
43
+ - Using overly technical language with non-technical users
44
+ - Providing lengthy, overwhelming responses
45
+ - Making definitive statements about future IXO developments unless explicitly mentioned
46
+ - Sharing sensitive information about IXO's internal operations
47
+
48
+ Remember that your primary goal is to create a positive, informative experience that builds trust in the IXO platform while making users feel valued and understood.`,
49
+ inputVariables: [
50
+ 'APP_NAME',
51
+ 'APP_PURPOSE',
52
+ 'APP_MAIN_FEATURES',
53
+ 'APP_TARGET_USERS',
54
+ 'APP_UNIQUE_SELLING_POINTS',
55
+ ],
56
+ templateFormat: 'mustache',
57
+ });
58
+ //# sourceMappingURL=generic-chat.prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generic-chat.prompt.js","sourceRoot":"","sources":["../../../../src/ai/nodes/generic-chat/generic-chat.prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAUzD,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,cAAc,CAAwB;IAC3E,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qKA6CyJ;IACnK,cAAc,EAAE;QACd,UAAU;QACV,aAAa;QACb,mBAAmB;QACnB,kBAAkB;QAClB,2BAA2B;KAC5B;IACD,cAAc,EAAE,UAAU;CAC3B,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './generic-chat.node.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ai/nodes/generic-chat/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './generic-chat.node.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ai/nodes/generic-chat/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './create-fake-node.js';
2
+ export * from './find-docs/index.js';
3
+ export * from './generic-chat/index.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ai/nodes/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './create-fake-node.js';
2
+ export * from './find-docs/index.js';
3
+ export * from './generic-chat/index.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ai/nodes/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { LangfuseConfig } from 'langfuse';
2
+ import { zodResponseFormat } from 'openai/helpers/zod';
3
+ import { type EnsureKeys } from '../types.js';
4
+ import { ParsedChatCompletion } from 'openai/resources/chat/completions.mjs';
5
+ export declare const createSemanticRouter: <K extends string[], R extends Record<string, string> = Record<string, string>>(routes: R, basedOn: K, model?: "gpt-4o-mini" | "gpt-4o" | "gpt-4.1-nano" | "gpt-4.1-mini", isComplex?: boolean) => ((state: EnsureKeys<Record<string, unknown>, K>, traceConfig?: LangfuseConfig) => Promise<keyof R>);
6
+ export { zodResponseFormat, type ParsedChatCompletion };
7
+ //# sourceMappingURL=create-semantic-router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-semantic-router.d.ts","sourceRoot":"","sources":["../../../src/ai/semantic-router-factory/create-semantic-router.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAiB,MAAM,UAAU,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAK9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAkB7E,eAAO,MAAM,oBAAoB,GAC/B,CAAC,SAAS,MAAM,EAAE,EAClB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAEzD,QAAQ,CAAC,EACT,SAAS,CAAC,EACV,QACI,aAAa,GACb,QAAQ,GACR,cAAc,GACd,cAA+B,EACnC,mBAAiB,KAChB,CAAC,CACF,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,EAC7C,WAAW,CAAC,EAAE,cAAc,KACzB,OAAO,CAAC,MAAM,CAAC,CAAC,CAyFpB,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,KAAK,oBAAoB,EAAE,CAAC"}
@@ -0,0 +1,71 @@
1
+ import { Logger } from '@ixo/logger';
2
+ import { PromptTemplate } from '@langchain/core/prompts';
3
+ import { observeOpenAI } from 'langfuse';
4
+ import { OpenAI } from 'openai';
5
+ import { zodResponseFormat } from 'openai/helpers/zod';
6
+ import z from 'zod';
7
+ import { jsonToYaml } from '../utils/index.js';
8
+ import { semanticRouterPrompt } from './semantic-router-prompt.js';
9
+ import { validateRoutes } from './validate-routes.js';
10
+ export const createSemanticRouter = (routes, basedOn, model = 'gpt-4.1-mini', isComplex = false) => {
11
+ const keys = validateRoutes(routes, basedOn);
12
+ const schema = z.object({
13
+ nextRoute: z.enum(keys, 'The routes that will be used to resolve the path'),
14
+ });
15
+ return async (state, traceConfig) => {
16
+ const selectedValues = {};
17
+ for (const key of basedOn) {
18
+ const stateValue = state[key];
19
+ if (!stateValue) {
20
+ throw new Error(`The state must have a value for the key ${key}`);
21
+ }
22
+ selectedValues[key] = stateValue;
23
+ }
24
+ if (Object.values(selectedValues).length === 0) {
25
+ throw new Error(`The state must have a value for the key ${basedOn.toString()}`);
26
+ }
27
+ const prompt = PromptTemplate.fromTemplate(semanticRouterPrompt);
28
+ const client = observeOpenAI(new OpenAI(), traceConfig);
29
+ const promptWithState = await prompt.format({
30
+ routes: jsonToYaml(routes),
31
+ state: jsonToYaml(selectedValues),
32
+ });
33
+ const getRoute = async (messages) => {
34
+ if (model === 'gpt-4.1-nano' && isComplex) {
35
+ const { choices } = await client.chat.completions.create({
36
+ messages,
37
+ model,
38
+ });
39
+ const route = choices[0]?.message?.content?.toString();
40
+ Logger.debug('🚀 ~ route:', route);
41
+ return client.chat.completions.parse({
42
+ model,
43
+ messages,
44
+ response_format: zodResponseFormat(schema, 'routesResponse'),
45
+ });
46
+ }
47
+ return client.chat.completions.parse({
48
+ model,
49
+ messages,
50
+ response_format: zodResponseFormat(schema, 'routesResponse'),
51
+ });
52
+ };
53
+ const completion = await getRoute([
54
+ { role: 'system', content: promptWithState },
55
+ {
56
+ role: 'user',
57
+ content: 'Think and analyze the routes and messages then select the next route',
58
+ },
59
+ ]);
60
+ const message = completion.choices[0]?.message;
61
+ if (message?.parsed) {
62
+ const nextRoute = message.parsed.nextRoute;
63
+ Logger.debug(`🚀 ~ nextRoute: ${message.parsed.nextRoute.toString()}`, message.parsed);
64
+ return nextRoute;
65
+ }
66
+ Logger.error('Error parsing the response from the semantic router');
67
+ throw new Error('Error parsing the response from the semantic router');
68
+ };
69
+ };
70
+ export { zodResponseFormat };
71
+ //# sourceMappingURL=create-semantic-router.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-semantic-router.js","sourceRoot":"","sources":["../../../src/ai/semantic-router-factory/create-semantic-router.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=create-semantic-router.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-semantic-router.test.d.ts","sourceRoot":"","sources":["../../../src/ai/semantic-router-factory/create-semantic-router.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,68 @@
1
+ import { createSemanticRouter } from './create-semantic-router.js';
2
+ const parse = jest.fn();
3
+ const create = jest.fn();
4
+ jest.mock('openai', () => ({
5
+ OpenAI: jest.fn().mockImplementation(() => {
6
+ function fn() {
7
+ return {};
8
+ }
9
+ fn.beta = {
10
+ chat: {
11
+ completions: { parse },
12
+ },
13
+ };
14
+ fn.chat = {
15
+ completions: { create },
16
+ };
17
+ return fn;
18
+ }),
19
+ }));
20
+ describe('createSemanticRouter', () => {
21
+ it('should create a semantic router with valid routes', () => {
22
+ expect(() => createSemanticRouter({
23
+ generateBlog: 'if the intent is blog',
24
+ generateSocialMediaPost: 'if the intent is post',
25
+ }, ['intent'])).not.toThrow();
26
+ });
27
+ it('should fail to create a semantic router with invalid routes', () => {
28
+ expect(() => createSemanticRouter({}, ['intent'])).toThrow();
29
+ });
30
+ it('should fail to get route with invalid state', async () => {
31
+ const router = createSemanticRouter({
32
+ generateBlog: 'if the intent is blog',
33
+ generateSocialMediaPost: 'if the intent is post',
34
+ }, ['intent']);
35
+ await expect(router({
36
+ foo: 'boo',
37
+ })).rejects.toThrow();
38
+ });
39
+ it('should get route with valid state', async () => {
40
+ const router = createSemanticRouter({
41
+ generateBlog: 'if the intent is blog',
42
+ generateSocialMediaPost: 'if the intent is post',
43
+ }, ['intent'], 'gpt-4o-mini', false);
44
+ parse.mockResolvedValue({
45
+ choices: [
46
+ {
47
+ message: {
48
+ parsed: {
49
+ nextRoute: 'generateBlog',
50
+ },
51
+ content: 'generateBlog',
52
+ role: 'assistant',
53
+ refusal: null,
54
+ tool_calls: [],
55
+ },
56
+ finish_reason: 'stop',
57
+ index: 0,
58
+ logprobs: null,
59
+ },
60
+ ],
61
+ });
62
+ const route = await router({
63
+ intent: 'blog',
64
+ });
65
+ expect(route).toBe('generateBlog');
66
+ });
67
+ });
68
+ //# sourceMappingURL=create-semantic-router.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-semantic-router.test.js","sourceRoot":"","sources":["../../../src/ai/semantic-router-factory/create-semantic-router.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEnE,MAAM,KAAK,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AACxB,MAAM,MAAM,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AACzB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC;IACzB,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,GAAG,EAAE;QACxC,SAAS,EAAE;YACT,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,EAAE,CAAC,IAAI,GAAG;YACR,IAAI,EAAE;gBACJ,WAAW,EAAE,EAAE,KAAK,EAAE;aACvB;SACF,CAAC;QAEF,EAAE,CAAC,IAAI,GAAG;YACR,WAAW,EAAE,EAAE,MAAM,EAAE;SACxB,CAAC;QACF,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC;CACH,CAAC,CAAC,CAAC;AAEJ,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE;QAQ3D,MAAM,CAAC,GAAG,EAAE,CACV,oBAAoB,CAClB;YACE,YAAY,EAAE,uBAAuB;YACrC,uBAAuB,EAAE,uBAAuB;SACjD,EACD,CAAC,QAAQ,CAAC,CACX,CACF,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IAClB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6DAA6D,EAAE,GAAG,EAAE;QACrE,MAAM,CAAC,GAAG,EAAE,CAAC,oBAAoB,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IAC/D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6CAA6C,EAAE,KAAK,IAAI,EAAE;QAC3D,MAAM,MAAM,GAAG,oBAAoB,CACjC;YACE,YAAY,EAAE,uBAAuB;YACrC,uBAAuB,EAAE,uBAAuB;SACjD,EACD,CAAC,QAAQ,CAAC,CACX,CAAC;QACF,MAAM,MAAM,CACV,MAAM,CAAC;YACL,GAAG,EAAE,KAAK;SACX,CAAC,CACH,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;IACtB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mCAAmC,EAAE,KAAK,IAAI,EAAE;QACjD,MAAM,MAAM,GAAG,oBAAoB,CACjC;YACE,YAAY,EAAE,uBAAuB;YACrC,uBAAuB,EAAE,uBAAuB;SACjD,EACD,CAAC,QAAQ,CAAC,EACV,aAAa,EACb,KAAK,CACN,CAAC;QAEF,KAAK,CAAC,iBAAiB,CAAC;YACtB,OAAO,EAAE;gBACP;oBACE,OAAO,EAAE;wBACP,MAAM,EAAE;4BACN,SAAS,EAAE,cAAc;yBAC1B;wBACD,OAAO,EAAE,cAAc;wBACvB,IAAI,EAAE,WAAW;wBACjB,OAAO,EAAE,IAAI;wBACb,UAAU,EAAE,EAAE;qBACf;oBACD,aAAa,EAAE,MAAM;oBACrB,KAAK,EAAE,CAAC;oBACR,QAAQ,EAAE,IAAI;iBACf;aACF;SACF,CAAC,CAAC;QAEH,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC;YACzB,MAAM,EAAE,MAAM;SACf,CAAC,CAAC;QACH,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './create-semantic-router.js';
2
+ export * from './semantic-router-prompt.js';
3
+ export * from './validate-routes.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ai/semantic-router-factory/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './create-semantic-router.js';
2
+ export * from './semantic-router-prompt.js';
3
+ export * from './validate-routes.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ai/semantic-router-factory/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const semanticRouterPrompt = "You are semantic router responsible for determining the next route based on the given routes and state.\n\n**Instructions:**\n\n1. **Read the Input:**\n - You will receive two pieces of input:\n - **Routes**: A set of named routes with specific conditions that need to be evaluated.\n - **State**: A set of properties that will be used to determine the next route. from the conditions provided in the routes.\n\n2. **Understand the Conditions Format:**\n - Conditions will be provided in a human-readable format. They may involve:\n - Checking the value of specific properties (e.g., \"if the user type is 'admin'\").\n - Evaluating multiple conditions with logical connectors like \"AND\" or \"OR\" (e.g., \"if the user type is 'guest' AND the access level is 'restricted'\").\n - Your task is to convert these human-readable conditions into logical expressions that can be evaluated programmatically.\n\n3. **Special Handling for Message Arrays:**\n - If the state contains a 'messages' array, respect their chronological order.\n - The most recent messages (at the end of the array) should have higher significance for determining intent.\n - Pay special attention to the last user message as it often contains the most current intent.\n\n4. **Evaluate Each Route:**\n - For each route, check if the current state satisfies the condition:\n - Example:\n - Condition: \"if the user type is 'admin' AND the access level is 'full'\"\n - State: \n ```yaml\n userType: admin\n accessLevel: limited\n ```\n - Evaluation: This condition does NOT match because `accessLevel` is 'limited', not 'full'.\n\n5. **Return the Matching Route:**\n - Identify and return the name of the first route where all conditions are met.\n - If no route matches, return 'undefined'.\n\n**Example 1:**\n\n- **Routes:**\n ```yaml\n adminDashboard: \"if the user type is 'admin' AND the access level is 'full'\"\n guestAccess: \"if the user type is 'guest' AND the access level is 'restricted'\"\n viewOnlyMode: \"if the access level is 'view-only'\"\n ```\n \n- **State:**\n ```yaml\n userType: guest\n accessLevel: restricted\n ```\n\n**Evaluation:**\n- **adminDashboard**: Does not match (user type is 'guest', not 'admin').\n- **guestAccess**: Matches (user type is 'guest' and access level is 'restricted').\n- **viewOnlyMode**: Does not match (access level is 'restricted', not 'view-only').\n\n**Result:**\n- Output: \"guestAccess\"\n\n---\n\n**Example 2:**\n\n- **Routes:**\n ```yaml\n escalateTicket: \"if the ticket priority is 'high' AND the status is 'open'\"\n autoClose: \"if the ticket status is 'resolved' AND the resolution time is less than 2 days\"\n notifySupervisor: \"if the ticket priority is 'high' OR the customer rating is less than 3\"\n ```\n\n- **State:**\n ```yaml\n ticketPriority: high\n status: open\n customerRating: 4\n ```\n\n**Evaluation:**\n- **escalateTicket**: Matches (priority is 'high' and status is 'open').\n- **autoClose**: Does not match (status is 'open', not 'resolved').\n- **notifySupervisor**: Also matches (priority is 'high').\n\n**Result:**\n- Output: \"escalateTicket\" (First match found based on input order)\n\n---\n\n**Example 3 (with Messages):**\n\n- **Routes:**\n ```yaml\n chatMode: \"if the messages contain casual conversation or greetings\"\n taskExecution: \"if the messages indicate a specific task to be performed\"\n informationRequest: \"if the messages contain questions about how to use the system\"\n ```\n\n- **State:**\n ```yaml\n messages:\n - sender: user\n content: \"Hello there!\"\n - sender: assistant\n content: \"Hi! How can I help you today?\"\n - sender: user\n content: \"I need to create a new domain for my project.\"\n ```\n\n**Evaluation:**\n- **chatMode**: Does not match fully (initial messages were greetings, but the final message indicates a task).\n- **taskExecution**: Matches (the last message clearly indicates a specific task - domain creation).\n- **informationRequest**: Does not match (no questions about system usage).\n\n**Result:**\n- Output: \"taskExecution\" (Based on the latest user intent in the message array)\n\n---\n\n**Example 4:**\n\n- **Routes:**\n ```yaml\n initiateRefund: \"if the order status is 'cancelled' AND the payment method is 'credit card'\"\n followUp: \"if the order status is 'shipped' AND the delivery status is 'delayed'\"\n quickResolve: \"if the order status is 'delivered' AND the customer feedback is 'positive'\"\n ```\n\n- **State:**\n ```yaml\n orderStatus: shipped\n deliveryStatus: delayed\n paymentMethod: credit card\n ```\n\n**Evaluation:**\n- **initiateRefund**: Does not match (order status is 'shipped', not 'cancelled').\n- **followUp**: Matches (order status is 'shipped' and delivery status is 'delayed').\n- **quickResolve**: Does not match (order status is 'shipped', not 'delivered').\n\n**Result:**\n- Output: \"followUp\"\n\n**Goal:**\n- Analyze the routes and state provided.\n- Explain each evaluation step clearly.\n- Return the correct route name or \"undefined\" if no match is found.\n\n**Output Format:**\n- Provide a single line output with the name of the matched route or \"undefined\".\n\n**Additional Notes:**\n- Be precise and ensure the evaluation logic follows the conditions specified.\n- If multiple conditions are specified, all must be met for a route to be valid.\n- The decision should be based on clear, logical reasoning derived from the state values.\n- When messages are included, prioritize the most recent message for determining intent.\n- Message ordering represents the chronological flow of conversation - later messages reflect the most current intent.\n\n----\nYOUR MISSION IS TO RESOLVE THE ROUTE BASED ON THE STATE PROVIDED. GOOD LUCK!\n\n- **Routes:**\n```yaml\n{routes}\n```\n\n- **State:**\n```yaml\n{state}\n```\n";
2
+ //# sourceMappingURL=semantic-router-prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semantic-router-prompt.d.ts","sourceRoot":"","sources":["../../../src/ai/semantic-router-factory/semantic-router-prompt.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,ozLAuKhC,CAAC"}
@@ -0,0 +1,169 @@
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
+ `;
169
+ //# sourceMappingURL=semantic-router-prompt.js.map