@nhtio/adk 1.20260625.0 → 1.20260626.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 (353) hide show
  1. package/CHANGELOG.md +114 -0
  2. package/batteries/embeddings/index.d.ts +12 -6
  3. package/batteries/embeddings/openai/adapter.cjs +1 -1
  4. package/batteries/embeddings/openai/adapter.mjs +1 -1
  5. package/batteries/embeddings/transformers_js/adapter.cjs +193 -0
  6. package/batteries/embeddings/transformers_js/adapter.cjs.map +1 -0
  7. package/batteries/embeddings/transformers_js/adapter.d.ts +80 -0
  8. package/batteries/embeddings/transformers_js/adapter.mjs +191 -0
  9. package/batteries/embeddings/transformers_js/adapter.mjs.map +1 -0
  10. package/batteries/embeddings/transformers_js/exceptions.cjs +32 -0
  11. package/batteries/embeddings/transformers_js/exceptions.cjs.map +1 -0
  12. package/batteries/embeddings/transformers_js/exceptions.d.ts +26 -0
  13. package/batteries/embeddings/transformers_js/exceptions.mjs +29 -0
  14. package/batteries/embeddings/transformers_js/exceptions.mjs.map +1 -0
  15. package/batteries/embeddings/transformers_js/index.d.ts +18 -0
  16. package/batteries/embeddings/transformers_js/pooling.cjs +67 -0
  17. package/batteries/embeddings/transformers_js/pooling.cjs.map +1 -0
  18. package/batteries/embeddings/transformers_js/pooling.d.ts +41 -0
  19. package/batteries/embeddings/transformers_js/pooling.mjs +63 -0
  20. package/batteries/embeddings/transformers_js/pooling.mjs.map +1 -0
  21. package/batteries/embeddings/transformers_js/types.cjs +2 -0
  22. package/batteries/embeddings/transformers_js/types.d.ts +97 -0
  23. package/batteries/embeddings/transformers_js/types.mjs +0 -0
  24. package/batteries/embeddings/transformers_js/validation.cjs +63 -0
  25. package/batteries/embeddings/transformers_js/validation.cjs.map +1 -0
  26. package/batteries/embeddings/transformers_js/validation.d.ts +21 -0
  27. package/batteries/embeddings/transformers_js/validation.mjs +60 -0
  28. package/batteries/embeddings/transformers_js/validation.mjs.map +1 -0
  29. package/batteries/embeddings/transformers_js.cjs +14 -0
  30. package/batteries/embeddings/transformers_js.mjs +5 -0
  31. package/batteries/embeddings/webllm/adapter.cjs +1 -1
  32. package/batteries/embeddings/webllm/adapter.mjs +1 -1
  33. package/batteries/embeddings.cjs +9 -0
  34. package/batteries/embeddings.mjs +5 -1
  35. package/batteries/encoding.cjs +7 -7
  36. package/batteries/encoding.mjs +7 -7
  37. package/batteries/llm/chat_common/generation.d.ts +122 -0
  38. package/batteries/llm/chat_common/helpers.d.ts +68 -0
  39. package/batteries/llm/chat_common/index.d.ts +15 -0
  40. package/batteries/llm/chat_common/lifecycle.d.ts +85 -0
  41. package/batteries/llm/chat_common/reasoning_parsers.d.ts +113 -0
  42. package/batteries/llm/chat_common/tool_parsers.d.ts +193 -0
  43. package/batteries/llm/chat_common/types.d.ts +36 -1
  44. package/batteries/llm/index.d.ts +10 -0
  45. package/batteries/llm/litert_lm/adapter.cjs +208 -100
  46. package/batteries/llm/litert_lm/adapter.cjs.map +1 -1
  47. package/batteries/llm/litert_lm/adapter.d.ts +11 -0
  48. package/batteries/llm/litert_lm/adapter.mjs +209 -101
  49. package/batteries/llm/litert_lm/adapter.mjs.map +1 -1
  50. package/batteries/llm/litert_lm/helpers.cjs +137 -44
  51. package/batteries/llm/litert_lm/helpers.cjs.map +1 -1
  52. package/batteries/llm/litert_lm/helpers.d.ts +74 -16
  53. package/batteries/llm/litert_lm/helpers.mjs +89 -45
  54. package/batteries/llm/litert_lm/helpers.mjs.map +1 -1
  55. package/batteries/llm/litert_lm/index.d.ts +4 -1
  56. package/batteries/llm/litert_lm/types.d.ts +94 -6
  57. package/batteries/llm/litert_lm/validation.cjs +35 -8
  58. package/batteries/llm/litert_lm/validation.cjs.map +1 -1
  59. package/batteries/llm/litert_lm/validation.mjs +35 -8
  60. package/batteries/llm/litert_lm/validation.mjs.map +1 -1
  61. package/batteries/llm/litert_lm.cjs +35 -1
  62. package/batteries/llm/litert_lm.mjs +5 -3
  63. package/batteries/llm/ollama/adapter.cjs +6 -6
  64. package/batteries/llm/ollama/adapter.mjs +6 -6
  65. package/batteries/llm/ollama/helpers.cjs +7 -7
  66. package/batteries/llm/ollama/helpers.cjs.map +1 -1
  67. package/batteries/llm/ollama/helpers.mjs +7 -7
  68. package/batteries/llm/ollama/helpers.mjs.map +1 -1
  69. package/batteries/llm/ollama/validation.cjs +1 -1
  70. package/batteries/llm/ollama/validation.mjs +1 -1
  71. package/batteries/llm/ollama.cjs +1 -1
  72. package/batteries/llm/ollama.mjs +1 -1
  73. package/batteries/llm/openai_chat_completions/adapter.cjs +6 -6
  74. package/batteries/llm/openai_chat_completions/adapter.mjs +6 -6
  75. package/batteries/llm/openai_chat_completions/helpers.cjs +16 -10
  76. package/batteries/llm/openai_chat_completions/helpers.cjs.map +1 -1
  77. package/batteries/llm/openai_chat_completions/helpers.d.ts +1 -1
  78. package/batteries/llm/openai_chat_completions/helpers.mjs +12 -11
  79. package/batteries/llm/openai_chat_completions/helpers.mjs.map +1 -1
  80. package/batteries/llm/openai_chat_completions/index.d.ts +1 -1
  81. package/batteries/llm/openai_chat_completions/validation.cjs +1 -1
  82. package/batteries/llm/openai_chat_completions/validation.mjs +1 -1
  83. package/batteries/llm/openai_chat_completions.cjs +6 -1
  84. package/batteries/llm/openai_chat_completions.mjs +2 -2
  85. package/batteries/llm/transformers_js/adapter.cjs +760 -0
  86. package/batteries/llm/transformers_js/adapter.cjs.map +1 -0
  87. package/batteries/llm/transformers_js/adapter.d.ts +88 -0
  88. package/batteries/llm/transformers_js/adapter.mjs +757 -0
  89. package/batteries/llm/transformers_js/adapter.mjs.map +1 -0
  90. package/batteries/llm/transformers_js/exceptions.cjs +65 -0
  91. package/batteries/llm/transformers_js/exceptions.cjs.map +1 -0
  92. package/batteries/llm/transformers_js/exceptions.d.ts +70 -0
  93. package/batteries/llm/transformers_js/exceptions.mjs +58 -0
  94. package/batteries/llm/transformers_js/exceptions.mjs.map +1 -0
  95. package/batteries/llm/transformers_js/helpers.cjs +442 -0
  96. package/batteries/llm/transformers_js/helpers.cjs.map +1 -0
  97. package/batteries/llm/transformers_js/helpers.d.ts +223 -0
  98. package/batteries/llm/transformers_js/helpers.mjs +357 -0
  99. package/batteries/llm/transformers_js/helpers.mjs.map +1 -0
  100. package/batteries/llm/transformers_js/index.d.ts +32 -0
  101. package/batteries/llm/transformers_js/model_source.cjs +144 -0
  102. package/batteries/llm/transformers_js/model_source.cjs.map +1 -0
  103. package/batteries/llm/transformers_js/model_source.d.ts +95 -0
  104. package/batteries/llm/transformers_js/model_source.mjs +139 -0
  105. package/batteries/llm/transformers_js/model_source.mjs.map +1 -0
  106. package/batteries/llm/transformers_js/types.cjs +2 -0
  107. package/batteries/llm/transformers_js/types.d.ts +235 -0
  108. package/batteries/llm/transformers_js/types.mjs +0 -0
  109. package/batteries/llm/transformers_js/validation.cjs +126 -0
  110. package/batteries/llm/transformers_js/validation.cjs.map +1 -0
  111. package/batteries/llm/transformers_js/validation.d.ts +19 -0
  112. package/batteries/llm/transformers_js/validation.mjs +123 -0
  113. package/batteries/llm/transformers_js/validation.mjs.map +1 -0
  114. package/batteries/llm/transformers_js.cjs +108 -0
  115. package/batteries/llm/transformers_js.mjs +10 -0
  116. package/batteries/llm/webllm_chat_completions/adapter.cjs +56 -22
  117. package/batteries/llm/webllm_chat_completions/adapter.cjs.map +1 -1
  118. package/batteries/llm/webllm_chat_completions/adapter.mjs +56 -22
  119. package/batteries/llm/webllm_chat_completions/adapter.mjs.map +1 -1
  120. package/batteries/llm/webllm_chat_completions/helpers.cjs +1 -1
  121. package/batteries/llm/webllm_chat_completions/helpers.mjs +1 -1
  122. package/batteries/llm/webllm_chat_completions/index.d.ts +1 -1
  123. package/batteries/llm/webllm_chat_completions/types.d.ts +11 -1
  124. package/batteries/llm/webllm_chat_completions/validation.cjs +14 -6
  125. package/batteries/llm/webllm_chat_completions/validation.cjs.map +1 -1
  126. package/batteries/llm/webllm_chat_completions/validation.mjs +14 -6
  127. package/batteries/llm/webllm_chat_completions/validation.mjs.map +1 -1
  128. package/batteries/llm/webllm_chat_completions.cjs +1 -1
  129. package/batteries/llm/webllm_chat_completions.mjs +1 -1
  130. package/batteries/llm.cjs +29 -1
  131. package/batteries/llm.mjs +13 -5
  132. package/batteries/media/contracts.cjs +1 -1
  133. package/batteries/media/contracts.mjs +1 -1
  134. package/batteries/media/engines/audio_decode.cjs +1 -1
  135. package/batteries/media/engines/audio_decode.mjs +1 -1
  136. package/batteries/media/engines/data.cjs +1 -1
  137. package/batteries/media/engines/data.mjs +1 -1
  138. package/batteries/media/engines/exceljs.cjs +1 -1
  139. package/batteries/media/engines/exceljs.mjs +1 -1
  140. package/batteries/media/engines/execa_executor.cjs +1 -1
  141. package/batteries/media/engines/execa_executor.mjs +1 -1
  142. package/batteries/media/engines/fs_workspace.cjs +1 -1
  143. package/batteries/media/engines/fs_workspace.mjs +1 -1
  144. package/batteries/media/engines/jimp.cjs +1 -1
  145. package/batteries/media/engines/jimp.mjs +1 -1
  146. package/batteries/media/engines/sharp.cjs +1 -1
  147. package/batteries/media/engines/sharp.mjs +1 -1
  148. package/batteries/media/engines/sheetjs.cjs +1 -1
  149. package/batteries/media/engines/sheetjs.mjs +1 -1
  150. package/batteries/media/engines/tesseract_js.cjs +1 -1
  151. package/batteries/media/engines/tesseract_js.mjs +1 -1
  152. package/batteries/media/engines/transformers_asr.cjs +1 -1
  153. package/batteries/media/engines/transformers_asr.mjs +1 -1
  154. package/batteries/media/forge.cjs +6 -6
  155. package/batteries/media/forge.mjs +6 -6
  156. package/batteries/media/lint.cjs +1 -1
  157. package/batteries/media/lint.mjs +1 -1
  158. package/batteries/media.cjs +2 -2
  159. package/batteries/media.mjs +2 -2
  160. package/batteries/storage/flydrive.cjs +1 -1
  161. package/batteries/storage/flydrive.mjs +1 -1
  162. package/batteries/storage/in_memory.cjs +1 -1
  163. package/batteries/storage/in_memory.mjs +1 -1
  164. package/batteries/storage/opfs.cjs +1 -1
  165. package/batteries/storage/opfs.mjs +1 -1
  166. package/batteries/tools/_shared.cjs +2 -2
  167. package/batteries/tools/_shared.mjs +2 -2
  168. package/batteries/tools/color.cjs +2 -2
  169. package/batteries/tools/color.mjs +2 -2
  170. package/batteries/tools/comparison.cjs +3 -3
  171. package/batteries/tools/comparison.mjs +3 -3
  172. package/batteries/tools/data_structure.cjs +3 -3
  173. package/batteries/tools/data_structure.mjs +3 -3
  174. package/batteries/tools/datetime_extended.cjs +3 -3
  175. package/batteries/tools/datetime_extended.mjs +3 -3
  176. package/batteries/tools/datetime_math.cjs +3 -3
  177. package/batteries/tools/datetime_math.mjs +3 -3
  178. package/batteries/tools/encoding.cjs +3 -3
  179. package/batteries/tools/encoding.mjs +3 -3
  180. package/batteries/tools/formatting.cjs +3 -3
  181. package/batteries/tools/formatting.mjs +3 -3
  182. package/batteries/tools/geo_basics.cjs +2 -2
  183. package/batteries/tools/geo_basics.mjs +2 -2
  184. package/batteries/tools/math.cjs +3 -3
  185. package/batteries/tools/math.mjs +3 -3
  186. package/batteries/tools/memory.cjs +6 -6
  187. package/batteries/tools/memory.mjs +6 -6
  188. package/batteries/tools/parsing.cjs +4 -4
  189. package/batteries/tools/parsing.mjs +4 -4
  190. package/batteries/tools/retrievables.cjs +5 -5
  191. package/batteries/tools/retrievables.mjs +5 -5
  192. package/batteries/tools/scrapper.cjs +1 -1
  193. package/batteries/tools/scrapper.mjs +1 -1
  194. package/batteries/tools/searxng.cjs +1 -1
  195. package/batteries/tools/searxng.mjs +1 -1
  196. package/batteries/tools/standing_instructions.cjs +4 -4
  197. package/batteries/tools/standing_instructions.mjs +4 -4
  198. package/batteries/tools/statistics.cjs +4 -4
  199. package/batteries/tools/statistics.mjs +4 -4
  200. package/batteries/tools/string_processing.cjs +3 -3
  201. package/batteries/tools/string_processing.mjs +3 -3
  202. package/batteries/tools/structured_data.cjs +3 -3
  203. package/batteries/tools/structured_data.mjs +3 -3
  204. package/batteries/tools/text_analysis.cjs +3 -3
  205. package/batteries/tools/text_analysis.mjs +3 -3
  206. package/batteries/tools/text_comparison.cjs +2 -2
  207. package/batteries/tools/text_comparison.mjs +2 -2
  208. package/batteries/tools/time.cjs +3 -3
  209. package/batteries/tools/time.mjs +3 -3
  210. package/batteries/tools/unit_conversion.cjs +2 -2
  211. package/batteries/tools/unit_conversion.mjs +2 -2
  212. package/batteries/tools/web_retrieval.cjs +1 -1
  213. package/batteries/tools/web_retrieval.mjs +1 -1
  214. package/batteries/tools.cjs +2 -2
  215. package/batteries/tools.mjs +2 -2
  216. package/batteries/vector/arangodb.cjs +1 -1
  217. package/batteries/vector/arangodb.mjs +1 -1
  218. package/batteries/vector/clickhouse.cjs +1 -1
  219. package/batteries/vector/clickhouse.mjs +1 -1
  220. package/batteries/vector/cloudflare.cjs +1 -1
  221. package/batteries/vector/cloudflare.mjs +1 -1
  222. package/batteries/vector/couchbase.cjs +1 -1
  223. package/batteries/vector/couchbase.mjs +1 -1
  224. package/batteries/vector/duckdb.cjs +1 -1
  225. package/batteries/vector/duckdb.mjs +1 -1
  226. package/batteries/vector/elasticsearch.cjs +1 -1
  227. package/batteries/vector/elasticsearch.mjs +1 -1
  228. package/batteries/vector/filters.cjs +1 -1
  229. package/batteries/vector/filters.mjs +1 -1
  230. package/batteries/vector/hnswlib.cjs +1 -1
  231. package/batteries/vector/hnswlib.mjs +1 -1
  232. package/batteries/vector/lancedb.cjs +1 -1
  233. package/batteries/vector/lancedb.mjs +1 -1
  234. package/batteries/vector/mariadb.cjs +1 -1
  235. package/batteries/vector/mariadb.mjs +1 -1
  236. package/batteries/vector/meilisearch.cjs +1 -1
  237. package/batteries/vector/meilisearch.mjs +1 -1
  238. package/batteries/vector/migrate.cjs +1 -1
  239. package/batteries/vector/migrate.mjs +1 -1
  240. package/batteries/vector/mongodb.cjs +1 -1
  241. package/batteries/vector/mongodb.mjs +1 -1
  242. package/batteries/vector/neo4j.cjs +1 -1
  243. package/batteries/vector/neo4j.mjs +1 -1
  244. package/batteries/vector/opensearch.cjs +1 -1
  245. package/batteries/vector/opensearch.mjs +1 -1
  246. package/batteries/vector/oracle23ai.cjs +1 -1
  247. package/batteries/vector/oracle23ai.mjs +1 -1
  248. package/batteries/vector/pinecone.cjs +1 -1
  249. package/batteries/vector/pinecone.mjs +1 -1
  250. package/batteries/vector/redis.cjs +1 -1
  251. package/batteries/vector/redis.mjs +1 -1
  252. package/batteries/vector/retrievable.cjs +1 -1
  253. package/batteries/vector/retrievable.mjs +1 -1
  254. package/batteries/vector/s3vectors.cjs +1 -1
  255. package/batteries/vector/s3vectors.mjs +1 -1
  256. package/batteries/vector/solr.cjs +1 -1
  257. package/batteries/vector/solr.mjs +1 -1
  258. package/batteries/vector/surrealdb.cjs +1 -1
  259. package/batteries/vector/surrealdb.mjs +1 -1
  260. package/batteries/vector/typesense.cjs +1 -1
  261. package/batteries/vector/typesense.mjs +1 -1
  262. package/batteries/vector/vespa.cjs +1 -1
  263. package/batteries/vector/vespa.mjs +1 -1
  264. package/batteries/vector/weaviate.cjs +1 -1
  265. package/batteries/vector/weaviate.mjs +1 -1
  266. package/batteries.cjs +37 -3
  267. package/batteries.mjs +17 -8
  268. package/{common-0CmrSKNb.mjs → common-DJH3UemH.mjs} +7 -7
  269. package/{common-0CmrSKNb.mjs.map → common-DJH3UemH.mjs.map} +1 -1
  270. package/{common-CpcsEqPY.js → common-ax3vKu6O.js} +7 -7
  271. package/{common-CpcsEqPY.js.map → common-ax3vKu6O.js.map} +1 -1
  272. package/common.cjs +7 -7
  273. package/common.mjs +7 -7
  274. package/{dispatch_runner-C2ZpFfw4.mjs → dispatch_runner-3anlRk3F.mjs} +3 -3
  275. package/{dispatch_runner-C2ZpFfw4.mjs.map → dispatch_runner-3anlRk3F.mjs.map} +1 -1
  276. package/{dispatch_runner-DMTkGHQI.js → dispatch_runner-CTkL_cMm.js} +3 -3
  277. package/{dispatch_runner-DMTkGHQI.js.map → dispatch_runner-CTkL_cMm.js.map} +1 -1
  278. package/dispatch_runner.cjs +1 -1
  279. package/dispatch_runner.mjs +1 -1
  280. package/eslint/rules.cjs +1 -1
  281. package/eslint/rules.mjs +1 -1
  282. package/eslint.cjs +2 -2
  283. package/eslint.mjs +2 -2
  284. package/forge.cjs +4 -4
  285. package/forge.mjs +4 -4
  286. package/guards.cjs +8 -8
  287. package/guards.mjs +8 -8
  288. package/{helpers-1okZzNCa.js → helpers-CJcqikes.js} +131 -1
  289. package/helpers-CJcqikes.js.map +1 -0
  290. package/{helpers-BCyDAn_R.mjs → helpers-DlrRbLVn.mjs} +102 -2
  291. package/helpers-DlrRbLVn.mjs.map +1 -0
  292. package/index.cjs +11 -11
  293. package/index.mjs +11 -11
  294. package/lifecycle-C4kwYJ-N.mjs +68 -0
  295. package/lifecycle-C4kwYJ-N.mjs.map +1 -0
  296. package/lifecycle-vYQJ2rmf.js +79 -0
  297. package/lifecycle-vYQJ2rmf.js.map +1 -0
  298. package/mcp/adk-docs-corpus.json +1 -1
  299. package/package.json +231 -166
  300. package/reasoning_parsers-CFNoFf6x.js +1016 -0
  301. package/reasoning_parsers-CFNoFf6x.js.map +1 -0
  302. package/reasoning_parsers-Dp66LFBt.mjs +747 -0
  303. package/reasoning_parsers-Dp66LFBt.mjs.map +1 -0
  304. package/{scrapper-DpTMyQcz.mjs → scrapper-BrViMDPI.mjs} +5 -5
  305. package/{scrapper-DpTMyQcz.mjs.map → scrapper-BrViMDPI.mjs.map} +1 -1
  306. package/{scrapper-B5G70UqQ.js → scrapper-CzgdX1NN.js} +5 -5
  307. package/{scrapper-B5G70UqQ.js.map → scrapper-CzgdX1NN.js.map} +1 -1
  308. package/{searxng-Q79l7IdQ.js → searxng-B5I1KmQj.js} +5 -5
  309. package/{searxng-Q79l7IdQ.js.map → searxng-B5I1KmQj.js.map} +1 -1
  310. package/{searxng-L-wd-A_n.mjs → searxng-BvjwwZav.mjs} +5 -5
  311. package/{searxng-L-wd-A_n.mjs.map → searxng-BvjwwZav.mjs.map} +1 -1
  312. package/server.json +2 -2
  313. package/skills/adk-assembly/SKILL.md +2 -2
  314. package/{spooled_artifact-fgc1lutm.mjs → spooled_artifact-BnbqIZ3a.mjs} +3 -3
  315. package/{spooled_artifact-fgc1lutm.mjs.map → spooled_artifact-BnbqIZ3a.mjs.map} +1 -1
  316. package/{spooled_artifact-MbMz6NXX.js → spooled_artifact-DrIR90nV.js} +3 -3
  317. package/{spooled_artifact-MbMz6NXX.js.map → spooled_artifact-DrIR90nV.js.map} +1 -1
  318. package/spooled_artifact.cjs +2 -2
  319. package/spooled_artifact.mjs +2 -2
  320. package/{spooled_markdown_artifact-3sK6HFRw.mjs → spooled_markdown_artifact-BJH_JZFm.mjs} +3 -3
  321. package/{spooled_markdown_artifact-3sK6HFRw.mjs.map → spooled_markdown_artifact-BJH_JZFm.mjs.map} +1 -1
  322. package/{spooled_markdown_artifact-Gj0ruiLJ.js → spooled_markdown_artifact-rg_WCNWq.js} +3 -3
  323. package/{spooled_markdown_artifact-Gj0ruiLJ.js.map → spooled_markdown_artifact-rg_WCNWq.js.map} +1 -1
  324. package/{thought-CU7PYkB1.js → thought-CE88bddw.js} +3 -3
  325. package/{thought-CU7PYkB1.js.map → thought-CE88bddw.js.map} +1 -1
  326. package/{thought-DmcfCRAw.mjs → thought-DdiQCpgX.mjs} +3 -3
  327. package/{thought-DmcfCRAw.mjs.map → thought-DdiQCpgX.mjs.map} +1 -1
  328. package/{tool-Bt6tmFXT.js → tool-BngpaOWb.js} +3 -3
  329. package/{tool-Bt6tmFXT.js.map → tool-BngpaOWb.js.map} +1 -1
  330. package/{tool-C_uxdxjp.mjs → tool-asIfCjxb.mjs} +3 -3
  331. package/{tool-C_uxdxjp.mjs.map → tool-asIfCjxb.mjs.map} +1 -1
  332. package/{tool_call-BixyvnWZ.js → tool_call-CZVmISyc.js} +4 -4
  333. package/{tool_call-BixyvnWZ.js.map → tool_call-CZVmISyc.js.map} +1 -1
  334. package/{tool_call-pfvAsgkY.mjs → tool_call-TtzdXxcb.mjs} +4 -4
  335. package/{tool_call-pfvAsgkY.mjs.map → tool_call-TtzdXxcb.mjs.map} +1 -1
  336. package/{tool_registry-FeMMz993.mjs → tool_registry-Bj0JhXCv.mjs} +164 -164
  337. package/tool_registry-Bj0JhXCv.mjs.map +1 -0
  338. package/{tool_registry-CIIfbY_w.js → tool_registry-DbS8Pem9.js} +163 -163
  339. package/tool_registry-DbS8Pem9.js.map +1 -0
  340. package/{turn_runner-Brz6Sd0F.mjs → turn_runner-305dGa72.mjs} +5 -5
  341. package/{turn_runner-Brz6Sd0F.mjs.map → turn_runner-305dGa72.mjs.map} +1 -1
  342. package/{turn_runner-DB-WWls8.js → turn_runner-DqJBbqeU.js} +5 -5
  343. package/{turn_runner-DB-WWls8.js.map → turn_runner-DqJBbqeU.js.map} +1 -1
  344. package/turn_runner.cjs +1 -1
  345. package/turn_runner.mjs +1 -1
  346. package/{validate-MBEmBzMl.mjs → validate-B8IGAERs.mjs} +2 -2
  347. package/{validate-MBEmBzMl.mjs.map → validate-B8IGAERs.mjs.map} +1 -1
  348. package/{validate-B4RXgYJC.js → validate-Cq8xhZrZ.js} +2 -2
  349. package/{validate-B4RXgYJC.js.map → validate-Cq8xhZrZ.js.map} +1 -1
  350. package/helpers-1okZzNCa.js.map +0 -1
  351. package/helpers-BCyDAn_R.mjs.map +0 -1
  352. package/tool_registry-CIIfbY_w.js.map +0 -1
  353. package/tool_registry-FeMMz993.mjs.map +0 -1
@@ -0,0 +1,191 @@
1
+ import { c as isError } from "../../../tool_registry-Bj0JhXCv.mjs";
2
+ import "../../../guards.mjs";
3
+ import { n as emitLifecycle } from "../../../lifecycle-C4kwYJ-N.mjs";
4
+ import { withModelSource } from "../../llm/transformers_js/model_source.mjs";
5
+ import { applyEmbeddingPrefix } from "../openai/helpers.mjs";
6
+ import { poolAndNormalize } from "./pooling.mjs";
7
+ import { E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS, E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR } from "./exceptions.mjs";
8
+ import { validateOptions } from "./validation.mjs";
9
+ //#region src/batteries/embeddings/transformers_js/adapter.ts
10
+ /**
11
+ * transformers.js (ONNX, dual-environment) Embeddings adapter battery.
12
+ *
13
+ * @module @nhtio/adk/batteries/embeddings/transformers_js/adapter
14
+ *
15
+ * @remarks
16
+ * Embeddings battery backed by transformers.js's `feature-extraction` pipeline. **Environment-neutral**
17
+ * — runs in Node (via `onnxruntime-node`) and the browser (via `onnxruntime-web` / WebGPU), auto-
18
+ * selected by the package; there is no WebGPU requirement, so this battery is surfaced from the
19
+ * environment-neutral `@nhtio/adk/batteries/embeddings` barrel alongside the OpenAI one.
20
+ *
21
+ * Same user-facing surface as the OpenAI / WebLLM embeddings batteries (`isAvailable` / `dimensions` /
22
+ * `preload` / `reset` / `embed` / `embedMany`), same `number[]` return shape, same query/document
23
+ * prefix handling (the shared `applyEmbeddingPrefix`).
24
+ *
25
+ * `@huggingface/transformers` is an optional peer dependency, imported lazily.
26
+ *
27
+ * **Cross-runtime vector caveat:** embeddings produced here are not guaranteed bit-identical to those
28
+ * from a different runtime (WebLLM/MLC, or even node-ONNX vs web-ONNX for the same model). A vector
29
+ * corpus must be embedded AND queried by one backend.
30
+ */
31
+ var makeDefaultCreatePipeline = (modelSource) => {
32
+ return async ({ model, device, dtype, onInitProgress }) => {
33
+ const { pipeline, env } = await import("@huggingface/transformers");
34
+ const load = async () => await pipeline("feature-extraction", model, {
35
+ ...device ? { device } : {},
36
+ ...dtype ? { dtype } : {},
37
+ ...onInitProgress ? { progress_callback: onInitProgress } : {}
38
+ });
39
+ return modelSource ? withModelSource(env, modelSource, load) : load();
40
+ };
41
+ };
42
+ /**
43
+ * Embeddings adapter for transformers.js's feature-extraction pipeline.
44
+ *
45
+ * @remarks
46
+ * Reusable: construct once, call {@link TransformersJsEmbeddingsAdapter.embed} / {@link embedMany} as
47
+ * many times as needed. The pipeline is resolved lazily on first use (or via {@link preload}) and
48
+ * cached with single-flight semantics so concurrent calls share one load.
49
+ */
50
+ var TransformersJsEmbeddingsAdapter = class TransformersJsEmbeddingsAdapter {
51
+ #options;
52
+ #pipeline;
53
+ #pipelinePromise;
54
+ /**
55
+ * Whether this battery is available. transformers.js is environment-neutral (Node + browser), so
56
+ * this is `true` whenever the runtime can import the peer — there is no WebGPU requirement.
57
+ */
58
+ static isAvailable() {
59
+ return true;
60
+ }
61
+ /**
62
+ * @param options - Constructor options. Validated eagerly.
63
+ * @throws {@link @nhtio/adk/batteries!E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS} when invalid.
64
+ */
65
+ constructor(options) {
66
+ this.#options = validateOptions(options);
67
+ this.#pipeline = this.#options.pipeline;
68
+ }
69
+ /** Declared output dimensionality (from options), or `undefined` if not configured. */
70
+ get dimensions() {
71
+ return this.#options.dimensions;
72
+ }
73
+ /** Instance availability probe (honours an injected `isAvailable`). */
74
+ isAvailable() {
75
+ return (this.#options.isAvailable ?? TransformersJsEmbeddingsAdapter.isAvailable)();
76
+ }
77
+ /** Eagerly loads (and caches) the pipeline so the first `embed` call is fast. Idempotent. */
78
+ async preload() {
79
+ await this.#resolvePipeline();
80
+ }
81
+ /** Drops the cached pipeline and in-flight load so the next call reloads. */
82
+ reset() {
83
+ this.#pipeline = void 0;
84
+ this.#pipelinePromise = void 0;
85
+ }
86
+ /**
87
+ * Release the loaded model's ONNX sessions + GPU/wasm buffers, then drop the cached pipeline.
88
+ *
89
+ * @remarks
90
+ * `reset()` only nulls the JS reference; the native ONNX Runtime sessions and WebGPU/wasm device memory
91
+ * stay alive until GC. Loading many embedding models back-to-back in one browser session (e.g. a full
92
+ * matrix run) accumulates those sessions until the heap is exhausted. `FeatureExtractionPipeline`
93
+ * extends `Pipeline`, which exposes `dispose()` — this awaits it so the memory is reclaimed between
94
+ * loads, swallows a disposal error (teardown must not throw), and finishes with `reset()`. Idempotent.
95
+ */
96
+ async dispose() {
97
+ const pipeWithDispose = this.#pipeline ?? await this.#pipelinePromise?.catch(() => void 0);
98
+ if (typeof pipeWithDispose?.dispose === "function") await Promise.resolve(pipeWithDispose.dispose()).catch(() => void 0);
99
+ this.reset();
100
+ }
101
+ async #resolvePipeline() {
102
+ if (this.#pipeline) return this.#pipeline;
103
+ if (!this.isAvailable()) throw new E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS(["the transformers.js embeddings battery is not available in this runtime"]);
104
+ const opts = this.#options;
105
+ this.#pipelinePromise ??= (async () => {
106
+ emitLifecycle(opts, "transformers_js_embed", opts.model, "loading", { detail: "loading feature-extraction pipeline" });
107
+ const forwardedInitProgress = opts.onLifecycle ?? opts.onLoading ?? opts.onReady ?? opts.onGenerating ?? opts.onError ? (info) => {
108
+ const p = info?.progress;
109
+ emitLifecycle(opts, "transformers_js_embed", opts.model, "loading", {
110
+ ...typeof p === "number" ? { progress: p / 100 } : {},
111
+ raw: info
112
+ });
113
+ opts.onInitProgress?.(info);
114
+ } : opts.onInitProgress;
115
+ const createPipeline = opts.createPipeline ?? makeDefaultCreatePipeline(opts.modelSource);
116
+ try {
117
+ emitLifecycle(opts, "transformers_js_embed", opts.model, "compiling", { detail: "compiling feature-extraction graph" });
118
+ const pipe = await createPipeline({
119
+ model: opts.model,
120
+ device: opts.device,
121
+ dtype: opts.dtype,
122
+ onInitProgress: forwardedInitProgress
123
+ });
124
+ this.#pipeline = pipe;
125
+ emitLifecycle(opts, "transformers_js_embed", opts.model, "ready", { detail: "feature-extraction pipeline ready" });
126
+ return pipe;
127
+ } catch (err) {
128
+ this.#pipelinePromise = void 0;
129
+ emitLifecycle(opts, "transformers_js_embed", opts.model, "error", { error: err });
130
+ throw new E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR([`could not load the transformers.js pipeline: ${isError(err) ? err.message : String(err)} — install the peer dependency (pnpm add @huggingface/transformers)`]);
131
+ }
132
+ })();
133
+ return this.#pipelinePromise;
134
+ }
135
+ /**
136
+ * Embeds a single string.
137
+ *
138
+ * @param text - The input text.
139
+ * @param opts - Per-call options (`kind`).
140
+ * @returns The embedding vector as a plain `number[]`.
141
+ */
142
+ async embed(text, opts) {
143
+ const [vec] = await this.embedMany([text], opts);
144
+ return vec;
145
+ }
146
+ /**
147
+ * Embeds a batch of strings in a single pipeline call.
148
+ *
149
+ * @param texts - The input texts.
150
+ * @param opts - Per-call options (`kind`). Defaults to `kind: 'document'`.
151
+ * @returns One embedding vector per input, in input order, each a plain `number[]`.
152
+ * @throws {@link @nhtio/adk/batteries!E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR} when the call fails
153
+ * or returns a malformed result.
154
+ */
155
+ async embedMany(texts, opts) {
156
+ if (texts.length === 0) return [];
157
+ const input = applyEmbeddingPrefix(texts, opts?.kind ?? "document", this.#options);
158
+ const pipe = await this.#resolvePipeline();
159
+ const pooling = this.#options.pooling ?? "mean";
160
+ const normalize = this.#options.normalize ?? true;
161
+ const battery = (this.#options.poolingOwner ?? "engine") === "battery";
162
+ emitLifecycle(this.#options, "transformers_js_embed", this.#options.model, "generating");
163
+ let tensor;
164
+ try {
165
+ tensor = await pipe(input, battery ? { pooling: "none" } : {
166
+ pooling,
167
+ normalize
168
+ });
169
+ } catch (err) {
170
+ emitLifecycle(this.#options, "transformers_js_embed", this.#options.model, "error", { error: err });
171
+ throw new E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR([isError(err) ? err.message : String(err)]);
172
+ }
173
+ if (!tensor || typeof tensor.tolist !== "function") throw new E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR(["feature-extraction returned a non-Tensor result"]);
174
+ const list = tensor.tolist();
175
+ let vectors;
176
+ if (battery) {
177
+ const states = list;
178
+ vectors = poolAndNormalize(Array.isArray(states) && Array.isArray(states[0]) && Array.isArray(states[0][0]) ? states : [states], pooling, normalize);
179
+ } else vectors = Array.isArray(list) && Array.isArray(list[0]) ? list : [list];
180
+ if (vectors.length !== input.length) {
181
+ emitLifecycle(this.#options, "transformers_js_embed", this.#options.model, "error", { error: /* @__PURE__ */ new Error(`expected ${input.length} vectors, got ${vectors.length}`) });
182
+ throw new E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR([`expected ${input.length} vectors, got ${vectors.length}`]);
183
+ }
184
+ emitLifecycle(this.#options, "transformers_js_embed", this.#options.model, "complete");
185
+ return vectors;
186
+ }
187
+ };
188
+ //#endregion
189
+ export { TransformersJsEmbeddingsAdapter };
190
+
191
+ //# sourceMappingURL=adapter.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.mjs","names":["#options","#pipeline","#resolvePipeline","#pipelinePromise"],"sources":["../../../../src/batteries/embeddings/transformers_js/adapter.ts"],"sourcesContent":["/**\n * transformers.js (ONNX, dual-environment) Embeddings adapter battery.\n *\n * @module @nhtio/adk/batteries/embeddings/transformers_js/adapter\n *\n * @remarks\n * Embeddings battery backed by transformers.js's `feature-extraction` pipeline. **Environment-neutral**\n * — runs in Node (via `onnxruntime-node`) and the browser (via `onnxruntime-web` / WebGPU), auto-\n * selected by the package; there is no WebGPU requirement, so this battery is surfaced from the\n * environment-neutral `@nhtio/adk/batteries/embeddings` barrel alongside the OpenAI one.\n *\n * Same user-facing surface as the OpenAI / WebLLM embeddings batteries (`isAvailable` / `dimensions` /\n * `preload` / `reset` / `embed` / `embedMany`), same `number[]` return shape, same query/document\n * prefix handling (the shared `applyEmbeddingPrefix`).\n *\n * `@huggingface/transformers` is an optional peer dependency, imported lazily.\n *\n * **Cross-runtime vector caveat:** embeddings produced here are not guaranteed bit-identical to those\n * from a different runtime (WebLLM/MLC, or even node-ONNX vs web-ONNX for the same model). A vector\n * corpus must be embedded AND queried by one backend.\n */\n\nimport { isError } from '@nhtio/adk/guards'\nimport { poolAndNormalize } from './pooling'\nimport { validateOptions } from './validation'\nimport { applyEmbeddingPrefix } from '../openai/helpers'\nimport { emitLifecycle } from '../../llm/chat_common/lifecycle'\nimport { withModelSource } from '../../llm/transformers_js/model_source'\nimport {\n E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS,\n E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR,\n} from './exceptions'\nimport type { EmbedOptions } from '../openai/types'\nimport type {\n TransformersJsEmbeddingsAdapterOptions,\n TransformersJsEmbeddingsPipeline,\n CreateTransformersJsEmbeddingsPipeline,\n} from './types'\n\nconst makeDefaultCreatePipeline = (\n modelSource: TransformersJsEmbeddingsAdapterOptions['modelSource']\n): CreateTransformersJsEmbeddingsPipeline => {\n return async ({ model, device, dtype, onInitProgress }) => {\n const transformers = await import('@huggingface/transformers')\n const { pipeline, env } = transformers\n const load = async () =>\n (await pipeline('feature-extraction', model, {\n ...(device ? { device } : {}),\n ...(dtype ? { dtype } : {}),\n ...(onInitProgress ? { progress_callback: onInitProgress } : {}),\n } as never)) as unknown as TransformersJsEmbeddingsPipeline\n // When a custom model source is configured, serve files through it behind the global-`env` mutex.\n return modelSource ? withModelSource(env as never, modelSource, load) : load()\n }\n}\n\n/**\n * Embeddings adapter for transformers.js's feature-extraction pipeline.\n *\n * @remarks\n * Reusable: construct once, call {@link TransformersJsEmbeddingsAdapter.embed} / {@link embedMany} as\n * many times as needed. The pipeline is resolved lazily on first use (or via {@link preload}) and\n * cached with single-flight semantics so concurrent calls share one load.\n */\nexport class TransformersJsEmbeddingsAdapter {\n readonly #options: TransformersJsEmbeddingsAdapterOptions\n #pipeline: TransformersJsEmbeddingsPipeline | undefined\n #pipelinePromise: Promise<TransformersJsEmbeddingsPipeline> | undefined\n\n /**\n * Whether this battery is available. transformers.js is environment-neutral (Node + browser), so\n * this is `true` whenever the runtime can import the peer — there is no WebGPU requirement.\n */\n public static isAvailable(): boolean {\n return true\n }\n\n /**\n * @param options - Constructor options. Validated eagerly.\n * @throws {@link @nhtio/adk/batteries!E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS} when invalid.\n */\n constructor(options: unknown) {\n this.#options = validateOptions(options)\n this.#pipeline = this.#options.pipeline\n }\n\n /** Declared output dimensionality (from options), or `undefined` if not configured. */\n get dimensions(): number | undefined {\n return this.#options.dimensions\n }\n\n /** Instance availability probe (honours an injected `isAvailable`). */\n isAvailable(): boolean {\n return (this.#options.isAvailable ?? TransformersJsEmbeddingsAdapter.isAvailable)()\n }\n\n /** Eagerly loads (and caches) the pipeline so the first `embed` call is fast. Idempotent. */\n async preload(): Promise<void> {\n await this.#resolvePipeline()\n }\n\n /** Drops the cached pipeline and in-flight load so the next call reloads. */\n reset(): void {\n this.#pipeline = undefined\n this.#pipelinePromise = undefined\n }\n\n /**\n * Release the loaded model's ONNX sessions + GPU/wasm buffers, then drop the cached pipeline.\n *\n * @remarks\n * `reset()` only nulls the JS reference; the native ONNX Runtime sessions and WebGPU/wasm device memory\n * stay alive until GC. Loading many embedding models back-to-back in one browser session (e.g. a full\n * matrix run) accumulates those sessions until the heap is exhausted. `FeatureExtractionPipeline`\n * extends `Pipeline`, which exposes `dispose()` — this awaits it so the memory is reclaimed between\n * loads, swallows a disposal error (teardown must not throw), and finishes with `reset()`. Idempotent.\n */\n async dispose(): Promise<void> {\n const pipeline = this.#pipeline ?? (await this.#pipelinePromise?.catch(() => undefined))\n const pipeWithDispose = pipeline as { dispose?: () => Promise<unknown> } | undefined\n if (typeof pipeWithDispose?.dispose === 'function') {\n await Promise.resolve(pipeWithDispose.dispose()).catch(() => undefined)\n }\n this.reset()\n }\n\n async #resolvePipeline(): Promise<TransformersJsEmbeddingsPipeline> {\n if (this.#pipeline) return this.#pipeline\n if (!this.isAvailable()) {\n throw new E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS([\n 'the transformers.js embeddings battery is not available in this runtime',\n ])\n }\n const opts = this.#options\n this.#pipelinePromise ??= (async () => {\n emitLifecycle(opts, 'transformers_js_embed', opts.model, 'loading', {\n detail: 'loading feature-extraction pipeline',\n })\n // Forward each provider download event into a normalized `loading` lifecycle report.\n const hasLifecycle =\n opts.onLifecycle ?? opts.onLoading ?? opts.onReady ?? opts.onGenerating ?? opts.onError\n const forwardedInitProgress = hasLifecycle\n ? (info: unknown) => {\n const p = (info as { progress?: number } | undefined)?.progress\n emitLifecycle(opts, 'transformers_js_embed', opts.model, 'loading', {\n ...(typeof p === 'number' ? { progress: p / 100 } : {}),\n raw: info,\n })\n opts.onInitProgress?.(info as never)\n }\n : opts.onInitProgress\n const createPipeline = opts.createPipeline ?? makeDefaultCreatePipeline(opts.modelSource)\n try {\n // `from_pretrained` covers both fetch (reported via progress_callback → `loading`) and the\n // ONNX-graph / WebGPU-WASM warmup. Mark the latter as `compiling` — a COARSE upper-bound marker\n // (fetch + compile overlap inside the call), consistent with the LLM batteries.\n emitLifecycle(opts, 'transformers_js_embed', opts.model, 'compiling', {\n detail: 'compiling feature-extraction graph',\n })\n const pipe = await createPipeline({\n model: opts.model,\n device: opts.device,\n dtype: opts.dtype,\n onInitProgress: forwardedInitProgress,\n })\n this.#pipeline = pipe\n emitLifecycle(opts, 'transformers_js_embed', opts.model, 'ready', {\n detail: 'feature-extraction pipeline ready',\n })\n return pipe\n } catch (err) {\n this.#pipelinePromise = undefined\n emitLifecycle(opts, 'transformers_js_embed', opts.model, 'error', { error: err })\n throw new E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR([\n `could not load the transformers.js pipeline: ${isError(err) ? err.message : String(err)} — install the peer dependency (pnpm add @huggingface/transformers)`,\n ])\n }\n })()\n return this.#pipelinePromise\n }\n\n /**\n * Embeds a single string.\n *\n * @param text - The input text.\n * @param opts - Per-call options (`kind`).\n * @returns The embedding vector as a plain `number[]`.\n */\n async embed(text: string, opts?: EmbedOptions): Promise<number[]> {\n const [vec] = await this.embedMany([text], opts)\n return vec\n }\n\n /**\n * Embeds a batch of strings in a single pipeline call.\n *\n * @param texts - The input texts.\n * @param opts - Per-call options (`kind`). Defaults to `kind: 'document'`.\n * @returns One embedding vector per input, in input order, each a plain `number[]`.\n * @throws {@link @nhtio/adk/batteries!E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR} when the call fails\n * or returns a malformed result.\n */\n async embedMany(texts: string[], opts?: EmbedOptions): Promise<number[][]> {\n if (texts.length === 0) return []\n const kind = opts?.kind ?? 'document'\n const input = applyEmbeddingPrefix(texts, kind, this.#options)\n\n const pipe = await this.#resolvePipeline()\n const pooling = this.#options.pooling ?? 'mean'\n const normalize = this.#options.normalize ?? true\n const battery = (this.#options.poolingOwner ?? 'engine') === 'battery'\n\n emitLifecycle(this.#options, 'transformers_js_embed', this.#options.model, 'generating')\n\n let tensor: { tolist: () => unknown; dims?: number[] }\n try {\n tensor = (await (pipe as unknown as (i: unknown, o: unknown) => Promise<unknown>)(\n input,\n // 'battery' owner: request RAW token states (no engine pooling/normalize) and do it ourselves\n // in deterministic JS. 'engine' owner: delegate to the pipeline exactly as before.\n battery ? { pooling: 'none' } : { pooling, normalize }\n )) as { tolist: () => unknown; dims?: number[] }\n } catch (err) {\n emitLifecycle(this.#options, 'transformers_js_embed', this.#options.model, 'error', {\n error: err,\n })\n throw new E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR([\n isError(err) ? err.message : String(err),\n ])\n }\n\n if (!tensor || typeof tensor.tolist !== 'function') {\n throw new E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR([\n 'feature-extraction returned a non-Tensor result',\n ])\n }\n\n const list = tensor.tolist()\n let vectors: number[][]\n if (battery) {\n // Raw states: tolist() → [batch, seq, hidden]. A single ungrouped input may come back as\n // [seq, hidden] → wrap to a batch of one. Pool + normalize deterministically.\n const states = list as unknown[]\n const tokenStates = (\n Array.isArray(states) &&\n Array.isArray(states[0]) &&\n Array.isArray((states[0] as unknown[])[0])\n ? states\n : [states]\n ) as number[][][]\n vectors = poolAndNormalize(tokenStates, pooling, normalize)\n } else {\n // With engine pooling, the Tensor is [batch, hidden] → tolist() yields number[][].\n vectors =\n Array.isArray(list) && Array.isArray(list[0]) ? (list as number[][]) : [list as number[]]\n }\n\n if (vectors.length !== input.length) {\n emitLifecycle(this.#options, 'transformers_js_embed', this.#options.model, 'error', {\n error: new Error(`expected ${input.length} vectors, got ${vectors.length}`),\n })\n throw new E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR([\n `expected ${input.length} vectors, got ${vectors.length}`,\n ])\n }\n emitLifecycle(this.#options, 'transformers_js_embed', this.#options.model, 'complete')\n return vectors\n }\n}\n"],"mappings":"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"}
@@ -0,0 +1,32 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("../../../chunk-Cek0wNdY.js");
3
+ const require_exceptions = require("../../../exceptions-BfOYct3J.js");
4
+ require("../../../factories.cjs");
5
+ //#region src/batteries/embeddings/transformers_js/exceptions.ts
6
+ /**
7
+ * Battery-scoped exception constructors for the transformers.js Embeddings adapter.
8
+ *
9
+ * @module @nhtio/adk/batteries/embeddings/transformers_js/exceptions
10
+ *
11
+ * @remarks
12
+ * Battery-scoped exception classes for the transformers.js (`@huggingface/transformers`) Embeddings
13
+ * adapter, minted via `createException` from `@nhtio/adk/factories`. Categories mirror the OpenAI and
14
+ * WebLLM embeddings batteries one-to-one — only the engine-specific failure differs.
15
+ */
16
+ /**
17
+ * Thrown when the resolved adapter options fail validation against
18
+ * `transformersJsEmbeddingsOptionsSchema` — e.g. a missing/empty `model` or an unknown option key.
19
+ * Fatal: config bugs fail loud, not at embed time.
20
+ */
21
+ var E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS = require_exceptions.createException("E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS", "Invalid transformers.js Embeddings adapter options: %s", "E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS", 529, true);
22
+ /**
23
+ * Thrown when the transformers.js pipeline fails to load (e.g. the `@huggingface/transformers` peer
24
+ * is not installed) or the `feature-extraction` call throws/returns a malformed result. Non-fatal.
25
+ * Printf arg: `[detail]`.
26
+ */
27
+ var E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR = require_exceptions.createException("E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR", "transformers.js Embeddings engine error: %s", "E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR", 502, false);
28
+ //#endregion
29
+ exports.E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS = E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS;
30
+ exports.E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR = E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR;
31
+
32
+ //# sourceMappingURL=exceptions.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exceptions.cjs","names":[],"sources":["../../../../src/batteries/embeddings/transformers_js/exceptions.ts"],"sourcesContent":["/**\n * Battery-scoped exception constructors for the transformers.js Embeddings adapter.\n *\n * @module @nhtio/adk/batteries/embeddings/transformers_js/exceptions\n *\n * @remarks\n * Battery-scoped exception classes for the transformers.js (`@huggingface/transformers`) Embeddings\n * adapter, minted via `createException` from `@nhtio/adk/factories`. Categories mirror the OpenAI and\n * WebLLM embeddings batteries one-to-one — only the engine-specific failure differs.\n */\n\nimport { createException } from '@nhtio/adk/factories'\n\n/**\n * Thrown when the resolved adapter options fail validation against\n * `transformersJsEmbeddingsOptionsSchema` — e.g. a missing/empty `model` or an unknown option key.\n * Fatal: config bugs fail loud, not at embed time.\n */\nexport const E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS = createException<[string]>(\n 'E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS',\n 'Invalid transformers.js Embeddings adapter options: %s',\n 'E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS',\n 529,\n true\n)\n\n/**\n * Thrown when the transformers.js pipeline fails to load (e.g. the `@huggingface/transformers` peer\n * is not installed) or the `feature-extraction` call throws/returns a malformed result. Non-fatal.\n * Printf arg: `[detail]`.\n */\nexport const E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR = createException<[string]>(\n 'E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR',\n 'transformers.js Embeddings engine error: %s',\n 'E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR',\n 502,\n false\n)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkBA,IAAa,+CAA+C,mBAAA,gBAC1D,gDACA,0DACA,gDACA,KACA,IACF;;;;;;AAOA,IAAa,4CAA4C,mBAAA,gBACvD,6CACA,+CACA,6CACA,KACA,KACF"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Battery-scoped exception constructors for the transformers.js Embeddings adapter.
3
+ *
4
+ * @module @nhtio/adk/batteries/embeddings/transformers_js/exceptions
5
+ *
6
+ * @remarks
7
+ * Battery-scoped exception classes for the transformers.js (`@huggingface/transformers`) Embeddings
8
+ * adapter, minted via `createException` from `@nhtio/adk/factories`. Categories mirror the OpenAI and
9
+ * WebLLM embeddings batteries one-to-one — only the engine-specific failure differs.
10
+ */
11
+ /**
12
+ * Thrown when the resolved adapter options fail validation against
13
+ * `transformersJsEmbeddingsOptionsSchema` — e.g. a missing/empty `model` or an unknown option key.
14
+ * Fatal: config bugs fail loud, not at embed time.
15
+ */
16
+ export declare const E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS: import("../../../factories").CreatedException<[
17
+ string
18
+ ]>;
19
+ /**
20
+ * Thrown when the transformers.js pipeline fails to load (e.g. the `@huggingface/transformers` peer
21
+ * is not installed) or the `feature-extraction` call throws/returns a malformed result. Non-fatal.
22
+ * Printf arg: `[detail]`.
23
+ */
24
+ export declare const E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR: import("../../../factories").CreatedException<[
25
+ string
26
+ ]>;
@@ -0,0 +1,29 @@
1
+ import { t as createException } from "../../../exceptions-DgmgW0MU.mjs";
2
+ import "../../../factories.mjs";
3
+ //#region src/batteries/embeddings/transformers_js/exceptions.ts
4
+ /**
5
+ * Battery-scoped exception constructors for the transformers.js Embeddings adapter.
6
+ *
7
+ * @module @nhtio/adk/batteries/embeddings/transformers_js/exceptions
8
+ *
9
+ * @remarks
10
+ * Battery-scoped exception classes for the transformers.js (`@huggingface/transformers`) Embeddings
11
+ * adapter, minted via `createException` from `@nhtio/adk/factories`. Categories mirror the OpenAI and
12
+ * WebLLM embeddings batteries one-to-one — only the engine-specific failure differs.
13
+ */
14
+ /**
15
+ * Thrown when the resolved adapter options fail validation against
16
+ * `transformersJsEmbeddingsOptionsSchema` — e.g. a missing/empty `model` or an unknown option key.
17
+ * Fatal: config bugs fail loud, not at embed time.
18
+ */
19
+ var E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS = createException("E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS", "Invalid transformers.js Embeddings adapter options: %s", "E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS", 529, true);
20
+ /**
21
+ * Thrown when the transformers.js pipeline fails to load (e.g. the `@huggingface/transformers` peer
22
+ * is not installed) or the `feature-extraction` call throws/returns a malformed result. Non-fatal.
23
+ * Printf arg: `[detail]`.
24
+ */
25
+ var E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR = createException("E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR", "transformers.js Embeddings engine error: %s", "E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR", 502, false);
26
+ //#endregion
27
+ export { E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS, E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR };
28
+
29
+ //# sourceMappingURL=exceptions.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exceptions.mjs","names":[],"sources":["../../../../src/batteries/embeddings/transformers_js/exceptions.ts"],"sourcesContent":["/**\n * Battery-scoped exception constructors for the transformers.js Embeddings adapter.\n *\n * @module @nhtio/adk/batteries/embeddings/transformers_js/exceptions\n *\n * @remarks\n * Battery-scoped exception classes for the transformers.js (`@huggingface/transformers`) Embeddings\n * adapter, minted via `createException` from `@nhtio/adk/factories`. Categories mirror the OpenAI and\n * WebLLM embeddings batteries one-to-one — only the engine-specific failure differs.\n */\n\nimport { createException } from '@nhtio/adk/factories'\n\n/**\n * Thrown when the resolved adapter options fail validation against\n * `transformersJsEmbeddingsOptionsSchema` — e.g. a missing/empty `model` or an unknown option key.\n * Fatal: config bugs fail loud, not at embed time.\n */\nexport const E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS = createException<[string]>(\n 'E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS',\n 'Invalid transformers.js Embeddings adapter options: %s',\n 'E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS',\n 529,\n true\n)\n\n/**\n * Thrown when the transformers.js pipeline fails to load (e.g. the `@huggingface/transformers` peer\n * is not installed) or the `feature-extraction` call throws/returns a malformed result. Non-fatal.\n * Printf arg: `[detail]`.\n */\nexport const E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR = createException<[string]>(\n 'E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR',\n 'transformers.js Embeddings engine error: %s',\n 'E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR',\n 502,\n false\n)\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,IAAa,+CAA+C,gBAC1D,gDACA,0DACA,gDACA,KACA,IACF;;;;;;AAOA,IAAa,4CAA4C,gBACvD,6CACA,+CACA,6CACA,KACA,KACF"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * transformers.js Embeddings adapter battery — dual-environment ONNX feature-extraction.
3
+ *
4
+ * @module @nhtio/adk/batteries/embeddings/transformers_js
5
+ *
6
+ * @remarks
7
+ * Environment-neutral (Node + browser, ONNX Runtime auto-selected) — so, unlike the WebLLM embeddings
8
+ * battery, it IS re-exported from the environment-neutral `@nhtio/adk/batteries/embeddings` barrel.
9
+ * Re-exports the adapter class, the validation schema + `validateOptions` wrapper, every option /
10
+ * pipeline type alias (including the shared base shapes re-exported from the OpenAI battery), and the
11
+ * battery-scoped exceptions.
12
+ */
13
+ export { TransformersJsEmbeddingsAdapter } from "./adapter";
14
+ export { transformersJsEmbeddingsOptionsSchema, validateOptions } from "./validation";
15
+ export { poolAndNormalize, defaultPoolAndNormalize, l2Normalize } from "./pooling";
16
+ export type { TokenStates3D, Pooled2D } from "./pooling";
17
+ export type { EmbeddingKind, EmbedOptions, BaseEmbeddingsAdapterOptions, TransformersJsEmbeddingsAdapterOptions, TransformersJsEmbeddingsPipeline, TransformersJsEmbeddingsDataType, TransformersJsEmbeddingsDeviceType, TransformersJsEmbeddingsProgressCallback, TransformersJsPooling, TransformersJsPoolingOwner, TransformersJsEmbeddingsModelSource, CreateTransformersJsEmbeddingsPipeline, BatteryLifecyclePhase, BatteryLifecycleBattery, BatteryLifecycleReport, BatteryLifecycleCallback, BatteryLifecycleHooks, } from "./types";
18
+ export { E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS, E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR, } from "./exceptions";
@@ -0,0 +1,67 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("../../../chunk-Cek0wNdY.js");
3
+ //#region src/batteries/embeddings/transformers_js/pooling.ts
4
+ /**
5
+ * Mean-pool a `[seq, hidden]` matrix into a `[hidden]` vector.
6
+ *
7
+ * @param rows - The per-token hidden-state rows.
8
+ */
9
+ var meanPool = (rows) => {
10
+ const seq = rows.length;
11
+ if (seq === 0) return [];
12
+ const hidden = rows[0].length;
13
+ const out = new Array(hidden).fill(0);
14
+ for (const row of rows) for (let h = 0; h < hidden; h++) out[h] += row[h];
15
+ for (let h = 0; h < hidden; h++) out[h] /= seq;
16
+ return out;
17
+ };
18
+ /**
19
+ * L2-normalize a vector in place-safe fashion (returns a new array). A zero vector is returned
20
+ * unchanged (no divide-by-zero).
21
+ *
22
+ * @param vec - The vector to normalize.
23
+ */
24
+ var l2Normalize = (vec) => {
25
+ let sumSq = 0;
26
+ for (const v of vec) sumSq += v * v;
27
+ const norm = Math.sqrt(sumSq);
28
+ if (norm === 0) return vec.slice();
29
+ return vec.map((v) => v / norm);
30
+ };
31
+ /**
32
+ * Pool a single `[seq, hidden]` matrix into one `[hidden]` vector per the strategy.
33
+ *
34
+ * @param rows - The per-token hidden-state rows for one input.
35
+ * @param pooling - The pooling strategy.
36
+ */
37
+ var poolOne = (rows, pooling) => {
38
+ switch (pooling) {
39
+ case "cls":
40
+ case "first_token": return (rows[0] ?? []).slice();
41
+ case "eos":
42
+ case "last_token": return (rows[rows.length - 1] ?? []).slice();
43
+ case "none": return meanPool(rows);
44
+ default: return meanPool(rows);
45
+ }
46
+ };
47
+ /**
48
+ * Pool raw `[batch, seq, hidden]` token states into `[batch, hidden]` vectors and optionally
49
+ * L2-normalize — the deterministic battery-owned path (`poolingOwner: 'battery'`).
50
+ *
51
+ * @param tokenStates - The `[batch, seq, hidden]` raw states from `pooling:'none'`.
52
+ * @param pooling - The pooling strategy (`'mean'` default).
53
+ * @param normalize - Whether to L2-normalize each pooled vector (default `true`).
54
+ * @returns One pooled (and optionally normalized) vector per batch row.
55
+ */
56
+ var poolAndNormalize = (tokenStates, pooling, normalize) => tokenStates.map((rows) => {
57
+ const pooled = poolOne(rows, pooling);
58
+ return normalize ? l2Normalize(pooled) : pooled;
59
+ });
60
+ /** Default {@link poolAndNormalize}. */
61
+ var defaultPoolAndNormalize = poolAndNormalize;
62
+ //#endregion
63
+ exports.defaultPoolAndNormalize = defaultPoolAndNormalize;
64
+ exports.l2Normalize = l2Normalize;
65
+ exports.poolAndNormalize = poolAndNormalize;
66
+
67
+ //# sourceMappingURL=pooling.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pooling.cjs","names":[],"sources":["../../../../src/batteries/embeddings/transformers_js/pooling.ts"],"sourcesContent":["/**\n * Deterministic, battery-owned pooling + L2-normalization for the transformers.js embeddings battery.\n *\n * @module @nhtio/adk/batteries/embeddings/transformers_js/pooling\n *\n * @remarks\n * Used when `poolingOwner: 'battery'`. The pipeline is asked for raw `pooling:'none'` token states —\n * a `[batch, seq, hidden]` tensor — and this module pools them into one vector per input in pure JS,\n * identically across Node and the browser. That removes the per-runtime post-processing variance that\n * widens the node↔browser cosine gap; only the irreducible ONNX-Runtime kernel floor remains.\n *\n * Pooling strategies mirror the transformers.js feature-extraction options:\n * - `mean` — attention-unaware mean over the sequence axis (matches the pipeline's `'mean'`, which\n * also means over all positions for a single ungrouped sequence).\n * - `cls` / `first_token` — the first token's hidden state.\n * - `eos` / `last_token` — the last token's hidden state.\n * - `none` — no pooling (caller already has the vector); returned unchanged per row.\n */\n\n/** A 3-D `[batch, seq, hidden]` nested array (raw token states from `pooling:'none'`). */\nexport type TokenStates3D = number[][][]\n/** A 2-D `[batch, hidden]` nested array (already-pooled vectors). */\nexport type Pooled2D = number[][]\n\n/**\n * Mean-pool a `[seq, hidden]` matrix into a `[hidden]` vector.\n *\n * @param rows - The per-token hidden-state rows.\n */\nconst meanPool = (rows: number[][]): number[] => {\n const seq = rows.length\n if (seq === 0) return []\n const hidden = rows[0].length\n const out = new Array<number>(hidden).fill(0)\n for (const row of rows) {\n for (let h = 0; h < hidden; h++) out[h] += row[h]\n }\n for (let h = 0; h < hidden; h++) out[h] /= seq\n return out\n}\n\n/**\n * L2-normalize a vector in place-safe fashion (returns a new array). A zero vector is returned\n * unchanged (no divide-by-zero).\n *\n * @param vec - The vector to normalize.\n */\nexport const l2Normalize = (vec: number[]): number[] => {\n let sumSq = 0\n for (const v of vec) sumSq += v * v\n const norm = Math.sqrt(sumSq)\n if (norm === 0) return vec.slice()\n return vec.map((v) => v / norm)\n}\n\n/**\n * Pool a single `[seq, hidden]` matrix into one `[hidden]` vector per the strategy.\n *\n * @param rows - The per-token hidden-state rows for one input.\n * @param pooling - The pooling strategy.\n */\nconst poolOne = (rows: number[][], pooling: string): number[] => {\n switch (pooling) {\n case 'cls':\n case 'first_token':\n return (rows[0] ?? []).slice()\n case 'eos':\n case 'last_token':\n return (rows[rows.length - 1] ?? []).slice()\n case 'none':\n // No pooling requested but we have token states — fall back to mean so a vector still results.\n return meanPool(rows)\n case 'mean':\n default:\n return meanPool(rows)\n }\n}\n\n/**\n * Pool raw `[batch, seq, hidden]` token states into `[batch, hidden]` vectors and optionally\n * L2-normalize — the deterministic battery-owned path (`poolingOwner: 'battery'`).\n *\n * @param tokenStates - The `[batch, seq, hidden]` raw states from `pooling:'none'`.\n * @param pooling - The pooling strategy (`'mean'` default).\n * @param normalize - Whether to L2-normalize each pooled vector (default `true`).\n * @returns One pooled (and optionally normalized) vector per batch row.\n */\nexport const poolAndNormalize = (\n tokenStates: TokenStates3D,\n pooling: string,\n normalize: boolean\n): Pooled2D =>\n tokenStates.map((rows) => {\n const pooled = poolOne(rows, pooling)\n return normalize ? l2Normalize(pooled) : pooled\n })\n\n/** Default {@link poolAndNormalize}. */\nexport const defaultPoolAndNormalize = poolAndNormalize\n"],"mappings":";;;;;;;;AA6BA,IAAM,YAAY,SAA+B;CAC/C,MAAM,MAAM,KAAK;CACjB,IAAI,QAAQ,GAAG,OAAO,CAAC;CACvB,MAAM,SAAS,KAAK,GAAG;CACvB,MAAM,MAAM,IAAI,MAAc,MAAM,EAAE,KAAK,CAAC;CAC5C,KAAK,MAAM,OAAO,MAChB,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,KAAK,IAAI,MAAM,IAAI;CAEjD,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,KAAK,IAAI,MAAM;CAC3C,OAAO;AACT;;;;;;;AAQA,IAAa,eAAe,QAA4B;CACtD,IAAI,QAAQ;CACZ,KAAK,MAAM,KAAK,KAAK,SAAS,IAAI;CAClC,MAAM,OAAO,KAAK,KAAK,KAAK;CAC5B,IAAI,SAAS,GAAG,OAAO,IAAI,MAAM;CACjC,OAAO,IAAI,KAAK,MAAM,IAAI,IAAI;AAChC;;;;;;;AAQA,IAAM,WAAW,MAAkB,YAA8B;CAC/D,QAAQ,SAAR;EACE,KAAK;EACL,KAAK,eACH,QAAQ,KAAK,MAAM,CAAC,GAAG,MAAM;EAC/B,KAAK;EACL,KAAK,cACH,QAAQ,KAAK,KAAK,SAAS,MAAM,CAAC,GAAG,MAAM;EAC7C,KAAK,QAEH,OAAO,SAAS,IAAI;EAEtB,SACE,OAAO,SAAS,IAAI;CACxB;AACF;;;;;;;;;;AAWA,IAAa,oBACX,aACA,SACA,cAEA,YAAY,KAAK,SAAS;CACxB,MAAM,SAAS,QAAQ,MAAM,OAAO;CACpC,OAAO,YAAY,YAAY,MAAM,IAAI;AAC3C,CAAC;;AAGH,IAAa,0BAA0B"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Deterministic, battery-owned pooling + L2-normalization for the transformers.js embeddings battery.
3
+ *
4
+ * @module @nhtio/adk/batteries/embeddings/transformers_js/pooling
5
+ *
6
+ * @remarks
7
+ * Used when `poolingOwner: 'battery'`. The pipeline is asked for raw `pooling:'none'` token states —
8
+ * a `[batch, seq, hidden]` tensor — and this module pools them into one vector per input in pure JS,
9
+ * identically across Node and the browser. That removes the per-runtime post-processing variance that
10
+ * widens the node↔browser cosine gap; only the irreducible ONNX-Runtime kernel floor remains.
11
+ *
12
+ * Pooling strategies mirror the transformers.js feature-extraction options:
13
+ * - `mean` — attention-unaware mean over the sequence axis (matches the pipeline's `'mean'`, which
14
+ * also means over all positions for a single ungrouped sequence).
15
+ * - `cls` / `first_token` — the first token's hidden state.
16
+ * - `eos` / `last_token` — the last token's hidden state.
17
+ * - `none` — no pooling (caller already has the vector); returned unchanged per row.
18
+ */
19
+ /** A 3-D `[batch, seq, hidden]` nested array (raw token states from `pooling:'none'`). */
20
+ export type TokenStates3D = number[][][];
21
+ /** A 2-D `[batch, hidden]` nested array (already-pooled vectors). */
22
+ export type Pooled2D = number[][];
23
+ /**
24
+ * L2-normalize a vector in place-safe fashion (returns a new array). A zero vector is returned
25
+ * unchanged (no divide-by-zero).
26
+ *
27
+ * @param vec - The vector to normalize.
28
+ */
29
+ export declare const l2Normalize: (vec: number[]) => number[];
30
+ /**
31
+ * Pool raw `[batch, seq, hidden]` token states into `[batch, hidden]` vectors and optionally
32
+ * L2-normalize — the deterministic battery-owned path (`poolingOwner: 'battery'`).
33
+ *
34
+ * @param tokenStates - The `[batch, seq, hidden]` raw states from `pooling:'none'`.
35
+ * @param pooling - The pooling strategy (`'mean'` default).
36
+ * @param normalize - Whether to L2-normalize each pooled vector (default `true`).
37
+ * @returns One pooled (and optionally normalized) vector per batch row.
38
+ */
39
+ export declare const poolAndNormalize: (tokenStates: TokenStates3D, pooling: string, normalize: boolean) => Pooled2D;
40
+ /** Default {@link poolAndNormalize}. */
41
+ export declare const defaultPoolAndNormalize: (tokenStates: TokenStates3D, pooling: string, normalize: boolean) => Pooled2D;
@@ -0,0 +1,63 @@
1
+ //#region src/batteries/embeddings/transformers_js/pooling.ts
2
+ /**
3
+ * Mean-pool a `[seq, hidden]` matrix into a `[hidden]` vector.
4
+ *
5
+ * @param rows - The per-token hidden-state rows.
6
+ */
7
+ var meanPool = (rows) => {
8
+ const seq = rows.length;
9
+ if (seq === 0) return [];
10
+ const hidden = rows[0].length;
11
+ const out = new Array(hidden).fill(0);
12
+ for (const row of rows) for (let h = 0; h < hidden; h++) out[h] += row[h];
13
+ for (let h = 0; h < hidden; h++) out[h] /= seq;
14
+ return out;
15
+ };
16
+ /**
17
+ * L2-normalize a vector in place-safe fashion (returns a new array). A zero vector is returned
18
+ * unchanged (no divide-by-zero).
19
+ *
20
+ * @param vec - The vector to normalize.
21
+ */
22
+ var l2Normalize = (vec) => {
23
+ let sumSq = 0;
24
+ for (const v of vec) sumSq += v * v;
25
+ const norm = Math.sqrt(sumSq);
26
+ if (norm === 0) return vec.slice();
27
+ return vec.map((v) => v / norm);
28
+ };
29
+ /**
30
+ * Pool a single `[seq, hidden]` matrix into one `[hidden]` vector per the strategy.
31
+ *
32
+ * @param rows - The per-token hidden-state rows for one input.
33
+ * @param pooling - The pooling strategy.
34
+ */
35
+ var poolOne = (rows, pooling) => {
36
+ switch (pooling) {
37
+ case "cls":
38
+ case "first_token": return (rows[0] ?? []).slice();
39
+ case "eos":
40
+ case "last_token": return (rows[rows.length - 1] ?? []).slice();
41
+ case "none": return meanPool(rows);
42
+ default: return meanPool(rows);
43
+ }
44
+ };
45
+ /**
46
+ * Pool raw `[batch, seq, hidden]` token states into `[batch, hidden]` vectors and optionally
47
+ * L2-normalize — the deterministic battery-owned path (`poolingOwner: 'battery'`).
48
+ *
49
+ * @param tokenStates - The `[batch, seq, hidden]` raw states from `pooling:'none'`.
50
+ * @param pooling - The pooling strategy (`'mean'` default).
51
+ * @param normalize - Whether to L2-normalize each pooled vector (default `true`).
52
+ * @returns One pooled (and optionally normalized) vector per batch row.
53
+ */
54
+ var poolAndNormalize = (tokenStates, pooling, normalize) => tokenStates.map((rows) => {
55
+ const pooled = poolOne(rows, pooling);
56
+ return normalize ? l2Normalize(pooled) : pooled;
57
+ });
58
+ /** Default {@link poolAndNormalize}. */
59
+ var defaultPoolAndNormalize = poolAndNormalize;
60
+ //#endregion
61
+ export { defaultPoolAndNormalize, l2Normalize, poolAndNormalize };
62
+
63
+ //# sourceMappingURL=pooling.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pooling.mjs","names":[],"sources":["../../../../src/batteries/embeddings/transformers_js/pooling.ts"],"sourcesContent":["/**\n * Deterministic, battery-owned pooling + L2-normalization for the transformers.js embeddings battery.\n *\n * @module @nhtio/adk/batteries/embeddings/transformers_js/pooling\n *\n * @remarks\n * Used when `poolingOwner: 'battery'`. The pipeline is asked for raw `pooling:'none'` token states —\n * a `[batch, seq, hidden]` tensor — and this module pools them into one vector per input in pure JS,\n * identically across Node and the browser. That removes the per-runtime post-processing variance that\n * widens the node↔browser cosine gap; only the irreducible ONNX-Runtime kernel floor remains.\n *\n * Pooling strategies mirror the transformers.js feature-extraction options:\n * - `mean` — attention-unaware mean over the sequence axis (matches the pipeline's `'mean'`, which\n * also means over all positions for a single ungrouped sequence).\n * - `cls` / `first_token` — the first token's hidden state.\n * - `eos` / `last_token` — the last token's hidden state.\n * - `none` — no pooling (caller already has the vector); returned unchanged per row.\n */\n\n/** A 3-D `[batch, seq, hidden]` nested array (raw token states from `pooling:'none'`). */\nexport type TokenStates3D = number[][][]\n/** A 2-D `[batch, hidden]` nested array (already-pooled vectors). */\nexport type Pooled2D = number[][]\n\n/**\n * Mean-pool a `[seq, hidden]` matrix into a `[hidden]` vector.\n *\n * @param rows - The per-token hidden-state rows.\n */\nconst meanPool = (rows: number[][]): number[] => {\n const seq = rows.length\n if (seq === 0) return []\n const hidden = rows[0].length\n const out = new Array<number>(hidden).fill(0)\n for (const row of rows) {\n for (let h = 0; h < hidden; h++) out[h] += row[h]\n }\n for (let h = 0; h < hidden; h++) out[h] /= seq\n return out\n}\n\n/**\n * L2-normalize a vector in place-safe fashion (returns a new array). A zero vector is returned\n * unchanged (no divide-by-zero).\n *\n * @param vec - The vector to normalize.\n */\nexport const l2Normalize = (vec: number[]): number[] => {\n let sumSq = 0\n for (const v of vec) sumSq += v * v\n const norm = Math.sqrt(sumSq)\n if (norm === 0) return vec.slice()\n return vec.map((v) => v / norm)\n}\n\n/**\n * Pool a single `[seq, hidden]` matrix into one `[hidden]` vector per the strategy.\n *\n * @param rows - The per-token hidden-state rows for one input.\n * @param pooling - The pooling strategy.\n */\nconst poolOne = (rows: number[][], pooling: string): number[] => {\n switch (pooling) {\n case 'cls':\n case 'first_token':\n return (rows[0] ?? []).slice()\n case 'eos':\n case 'last_token':\n return (rows[rows.length - 1] ?? []).slice()\n case 'none':\n // No pooling requested but we have token states — fall back to mean so a vector still results.\n return meanPool(rows)\n case 'mean':\n default:\n return meanPool(rows)\n }\n}\n\n/**\n * Pool raw `[batch, seq, hidden]` token states into `[batch, hidden]` vectors and optionally\n * L2-normalize — the deterministic battery-owned path (`poolingOwner: 'battery'`).\n *\n * @param tokenStates - The `[batch, seq, hidden]` raw states from `pooling:'none'`.\n * @param pooling - The pooling strategy (`'mean'` default).\n * @param normalize - Whether to L2-normalize each pooled vector (default `true`).\n * @returns One pooled (and optionally normalized) vector per batch row.\n */\nexport const poolAndNormalize = (\n tokenStates: TokenStates3D,\n pooling: string,\n normalize: boolean\n): Pooled2D =>\n tokenStates.map((rows) => {\n const pooled = poolOne(rows, pooling)\n return normalize ? l2Normalize(pooled) : pooled\n })\n\n/** Default {@link poolAndNormalize}. */\nexport const defaultPoolAndNormalize = poolAndNormalize\n"],"mappings":";;;;;;AA6BA,IAAM,YAAY,SAA+B;CAC/C,MAAM,MAAM,KAAK;CACjB,IAAI,QAAQ,GAAG,OAAO,CAAC;CACvB,MAAM,SAAS,KAAK,GAAG;CACvB,MAAM,MAAM,IAAI,MAAc,MAAM,EAAE,KAAK,CAAC;CAC5C,KAAK,MAAM,OAAO,MAChB,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,KAAK,IAAI,MAAM,IAAI;CAEjD,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,KAAK,IAAI,MAAM;CAC3C,OAAO;AACT;;;;;;;AAQA,IAAa,eAAe,QAA4B;CACtD,IAAI,QAAQ;CACZ,KAAK,MAAM,KAAK,KAAK,SAAS,IAAI;CAClC,MAAM,OAAO,KAAK,KAAK,KAAK;CAC5B,IAAI,SAAS,GAAG,OAAO,IAAI,MAAM;CACjC,OAAO,IAAI,KAAK,MAAM,IAAI,IAAI;AAChC;;;;;;;AAQA,IAAM,WAAW,MAAkB,YAA8B;CAC/D,QAAQ,SAAR;EACE,KAAK;EACL,KAAK,eACH,QAAQ,KAAK,MAAM,CAAC,GAAG,MAAM;EAC/B,KAAK;EACL,KAAK,cACH,QAAQ,KAAK,KAAK,SAAS,MAAM,CAAC,GAAG,MAAM;EAC7C,KAAK,QAEH,OAAO,SAAS,IAAI;EAEtB,SACE,OAAO,SAAS,IAAI;CACxB;AACF;;;;;;;;;;AAWA,IAAa,oBACX,aACA,SACA,cAEA,YAAY,KAAK,SAAS;CACxB,MAAM,SAAS,QAAQ,MAAM,OAAO;CACpC,OAAO,YAAY,YAAY,MAAM,IAAI;AAC3C,CAAC;;AAGH,IAAa,0BAA0B"}
@@ -0,0 +1,2 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("../../../chunk-Cek0wNdY.js");