@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
package/CHANGELOG.md CHANGED
@@ -15,6 +15,120 @@ you *when* you got it, not *what changed*: a `^` range will float across battery
15
15
  breaking changes, so pin an exact version if you need stability and read the entry before
16
16
  upgrading.
17
17
 
18
+ ## 2026-06-26
19
+
20
+ ### Added
21
+
22
+ - **Portable generation vocabulary shared by the two text-out on-device batteries** (`transformers_js`,
23
+ `litert_lm`). Both now accept one canonical {@link ChatGenerationOptions} surface — `maxTokens`, `sampler`
24
+ (`'greedy'`|`'top-k'`|`'top-p'`), `temperature`, `topK`, `topP`, `seed`, `enableThinking`,
25
+ `multimodal: { image, audio }` — and each adapter maps it onto its own runtime API. Precedence is
26
+ **canonical-wins**: the canonical field is honored and the battery's native field (transformers.js
27
+ `maxNewTokens`, LiteRT `maxOutputTokens` / `samplerParams`) is the fallback consulted only when the canonical
28
+ one is absent, so existing native-field config keeps working. Defaults are identical across both batteries
29
+ and chosen for reproducibility (`sampler: 'greedy'`, `enableThinking: false` — many reasoning templates
30
+ default thinking *on* and burn the token budget before the answer; this turns it off unless asked).
31
+ - **Normalized lifecycle hook surface across all on-device batteries** (`transformers_js`, `litert_lm`,
32
+ `webllm_chat_completions`, and the transformers.js embeddings battery). A new opt-in {@link BatteryLifecycleHooks}
33
+ block: an `onLifecycle` firehose plus per-phase hooks `onLoading` → `onCompiling` → `onReady` →
34
+ `onGenerating` → `onComplete` (or `onError`), each handed a normalized `BatteryLifecycleReport`
35
+ (`{ phase, battery, model, at, detail?, progress?, raw?, error? }`). `progress` is normalized to `0..1`
36
+ during `loading` when the provider reports it; the `compiling` phase marks the WebGPU/wasm shader/graph
37
+ build between download and first token — often the slowest part of a cold start, and previously invisible.
38
+ Purely additive — omit the hooks and behavior is byte-for-byte unchanged; a throwing consumer hook can never
39
+ abort a load or a turn. The existing per-provider `onInitProgress` is untouched.
40
+ - **Multimodal INPUT for the transformers.js battery.** Image and audio flow through the model's processor
41
+ (called positionally, `_call(text, images, audio)`); a multimodal model genuinely perceives them. For the
42
+ common audio case — uncompressed PCM WAV — the battery decodes the RIFF itself with a `DataView`,
43
+ dependency-free and **env-neutral**, *before* importing the heavy peer (transformers.js's own `read_audio`
44
+ needs the Web Audio API's `AudioContext`, which does not exist in Node; compressed containers still fall
45
+ back to it, browser-only). Enable per kind via the canonical `multimodal: { image, audio }`.
46
+ - **Opt-in media-OUTPUT seam (`extractMediaOutputs`) on the `transformers_js` and `litert_lm` batteries.**
47
+ Default absent → text-out, byte-for-byte unchanged. Supply the hook and a wrapped media-emitting model's
48
+ generated audio/image is persisted via `ctx.storeMediaBytes`, wrapped as a first-party `Media.toolGenerated(...)`,
49
+ and surfaced as an assistant `Message.attachments` entry (a media-only turn — empty text + attachment — is
50
+ legitimate). The batteries remain multimodal-in / text-out by default; this is for an LLM turn that produces
51
+ media alongside or instead of text.
52
+ - **`'phi'` tool-call parser** added to the shared parser layer's `toolCallParser` set and the `'auto'`
53
+ priority order (`hermes → gemma → gpt_oss → phi → pythonic → llama3_json → mistral → qwen3_coder`). Anchored
54
+ on the literal `functools` token (verified against vLLM's `phi4_mini_json` parser), so it runs with the
55
+ other marker-anchored families ahead of the weak-signal JSON/pythonic forms.
56
+ - **`EmbeddingGemma 300M`** (`onnx-community/embeddinggemma-300m-ONNX`) verified through the
57
+ `transformers_js` embeddings battery — 768-dim, unit-norm, deterministic — alongside the existing
58
+ MiniLM / BGE-small / Arctic-S entries.
59
+ - **The real-model test matrix** (`tests/_fixtures/model_matrix.ts`, gated on `TEST_MODEL_MATRIX=1`): loads
60
+ each real ONNX / `.litertlm` model, drives one dispatch turn, and asserts the expected parser family or
61
+ multimodal grounding is extracted — because a small model may not emit the format its chat template implies
62
+ (Gemma 4 E2B emits the decoder-stripped `call:NAME{k:v}`, not the template's `<|tool_call>…`). A Node half
63
+ (`pnpm run test:matrix`) and a headed-WebGPU browser half (`pnpm run test:matrix:browser`, local-only — CI
64
+ runners have no GPU). `bin/capture_tool_outputs.ts` (`pnpm run capture:tools`) captures real raw output from
65
+ hosted big-only families (`qwen3_coder`, `gpt_oss`, `mistral`) via any OpenAI-compatible proxy into committed
66
+ parser fixtures — configured with `--base-url`/`--api-key` or the generic `CAPTURE_BASE_URL` /
67
+ `CAPTURE_API_KEY` env vars; never run in CI.
68
+ - **Documentation: a dedicated "LLM Batteries" section** under Featured Batteries — an overview hub, a
69
+ "Shared Contract" page (the three `chat_common` pillars: parser layer, portable generation vocabulary,
70
+ lifecycle hooks), and a reference page per battery (OpenAI, Ollama, WebLLM, LiteRT-LM, Transformers.js) each
71
+ carrying a tested-model table grounded in the matrix. Plus a showcase, "Building the On-Device Batteries,"
72
+ documenting the parser archaeology, the false-green fixtures, and the one wall we could not engineer around:
73
+ **LiteRT-LM in the browser runs Gemma and only Gemma**, proven at the file-format level
74
+ (`tf_lite_prefill_decode` vs `tf_lite_artisan_text_decoder`) — converting a non-Gemma model to a
75
+ browser-runnable `.litertlm` is a dead end with the public toolchain. The dead `convert_model` / `deploy_model`
76
+ scripts (which described a fictional CLI) were removed and the conversion doc rewritten as "The Real-Model
77
+ Matrix." Docs are bundled in the npm package and served by the ADK Assembly MCP, so this ships with the release.
78
+
79
+ ### Changed
80
+
81
+ - **`bin/capture_tool_outputs.ts` now reads its proxy URL/key from `CAPTURE_BASE_URL` / `CAPTURE_API_KEY`**
82
+ (or the existing `--base-url` / `--api-key` flags), replacing internal-specific env-var names. Dev tool only;
83
+ not part of the published runtime surface.
84
+
85
+ ## 2026-06-25
86
+
87
+ ### Added
88
+
89
+ - **New opt-in LLM battery `@nhtio/adk/batteries/llm/transformers_js` — on-device ONNX text generation,
90
+ in Node AND the browser.** Ships `TransformersJsAdapter`, a one-line {@link DispatchExecutorFn} wrapping
91
+ [`@huggingface/transformers`](https://www.npmjs.com/package/@huggingface/transformers) (an optional peer,
92
+ already present for the media ASR engine). Unlike the WebLLM and LiteRT-LM batteries (WebGPU/browser-only),
93
+ transformers.js is **environment-neutral** — it auto-selects `onnxruntime-node` (native, plain Node, no GPU)
94
+ or `onnxruntime-web` (WASM + WebGPU) — so this battery runs server-side and client-side from one codepath
95
+ and does **not** gate on `navigator.gpu`. `device`/`dtype` pick the backend and quantization. `STASH_KEY`
96
+ is `'transformersJs'`.
97
+ - **New opt-in embeddings battery `@nhtio/adk/batteries/embeddings/transformers_js`.** Ships
98
+ `TransformersJsEmbeddingsAdapter` — on-device `feature-extraction` embeddings with the same
99
+ `embed`/`embedMany`/`dimensions`/`preload`/`reset`/`isAvailable` surface and `number[]` return shape as the
100
+ OpenAI and WebLLM embedders, plus `pooling` (default `'mean'`) and `normalize` (default `true`). Being
101
+ environment-neutral, it is surfaced from the `@nhtio/adk/batteries/embeddings` aggregate barrel (alongside
102
+ OpenAI; WebLLM stays deep-import-only).
103
+ - **New shared, configurable tool-call + reasoning text-parser layer** (re-exported from both
104
+ `transformers_js` and `litert_lm`). Text-only on-device runtimes inject tool definitions into the chat
105
+ template but emit tool calls and reasoning as **family-specific raw text**, not structured fields — so the
106
+ battery parses them out, the way vLLM/SGLang/Ollama do (post-hoc, per-family, flag-selected). Two options,
107
+ both defaulting to `'auto'` (try the bundled family parsers in priority order, first match wins):
108
+ - `toolCallParser`: `'auto'` · `'hermes'` · `'gemma'` (E2B/E4B) · `'gpt_oss'` (Harmony) · `'pythonic'` ·
109
+ `'llama3_json'` · `'mistral'` · `'qwen3_coder'` · `'none'` · a custom `ToolCallParserFn`.
110
+ - `reasoningParser`: `'auto'` · `'think_tag'` (`<think>…</think>`) · `'harmony_analysis'` · `'gemma_channel'`
111
+ · `'none'` · a custom `ReasoningParserFn`.
112
+ Marker-anchored families run first (no cross-family false positives); weak-signal JSON/pythonic forms are
113
+ gated on the callee being a real tool. Parsed reasoning becomes ADK Thoughts; cleaned prose is the assistant
114
+ Message; tool-call `arguments` are a plain object (no `JSON.parse`). Bundled defaults target the small ONNX /
115
+ Ollama-Cloud-tier open-weight families (Gemma 4 E2B/E4B, gpt-oss:20b, Qwen3-Instruct, Llama 3.2, SmolLM).
116
+ Gemma's tool-call + reasoning delimiters were verified byte-exact against the model's own
117
+ `tokenizer_config.json`; both batteries were validated end-to-end against real ONNX models (MiniLM embeddings,
118
+ SmolLM2-135M generation).
119
+
120
+ ### Fixed
121
+
122
+ - **LiteRT-LM tool calling and reasoning extraction now actually work** (`@nhtio/adk/batteries/llm/litert_lm`).
123
+ The battery as first shipped (v1.20260625.0) read `Message.tool_calls` and `Message.channels` off model
124
+ output — but the `@litert-lm/core` v0.13.1 JS runtime is **text-in / text-out** and never populates those
125
+ fields on output (they are input-only wire fields; the package README confirms text-only I/O). So the prior
126
+ tool-calling and reasoning support was **non-functional against real models** (the mocked tests passed
127
+ because the fakes populated the fields). The adapter now parses tool calls and reasoning out of the model's
128
+ **text** via the new shared parser layer, with the same `toolCallParser` / `reasoningParser` options
129
+ (default `'auto'`). If you relied on LiteRT-LM tool calls or thoughts before, they begin functioning with
130
+ this release.
131
+
18
132
  ## 2026-06-24
19
133
 
20
134
  ### Added
@@ -4,22 +4,28 @@
4
4
  * @module @nhtio/adk/batteries/embeddings
5
5
  *
6
6
  * @remarks
7
- * Aggregate barrel for the embeddings batteries. Re-exports only the **environment-neutral**
8
- * embeddings battery currently just the OpenAI battery (raw `fetch`, runs anywhere) so
9
- * consumers can import this barrel from either Node or the browser without dragging in
10
- * environment-specific runtime requirements.
7
+ * Aggregate barrel for the embeddings batteries. Re-exports the **environment-neutral** embeddings
8
+ * batteries — the OpenAI battery (raw `fetch`, runs anywhere) and the transformers.js battery (ONNX
9
+ * Runtime, auto-selecting native Node vs WASM/WebGPU in the browser) so consumers can import this
10
+ * barrel from either Node or the browser without dragging in environment-specific runtime
11
+ * requirements.
11
12
  *
12
13
  * The browser/WebGPU-only WebLLM embeddings battery is reachable only through its own subpath:
13
14
  *
14
15
  * - `@nhtio/adk/batteries/embeddings/webllm` — browser-only (uses WebGPU via `@mlc-ai/web-llm`).
15
16
  *
16
- * Deep-import that subpath when you need it; don't expect it to be re-exported here. The two
17
- * batteries share one option base and an identical method surface — see
17
+ * Deep-import that subpath when you need it; don't expect it to be re-exported here. All batteries
18
+ * share one option base and an identical method surface — see
18
19
  * {@link @nhtio/adk/batteries/embeddings/openai/types!BaseEmbeddingsAdapterOptions}.
19
20
  */
20
21
  export { OpenAIEmbeddingsAdapter } from "./openai/index";
21
22
  export { applyEmbeddingPrefix } from "./openai/index";
22
23
  export { openAIEmbeddingsOptionsSchema } from "./openai/index";
23
24
  export { validateOptions as validateOpenAIEmbeddingsOptions } from "./openai/index";
25
+ export { TransformersJsEmbeddingsAdapter } from "./transformers_js/index";
26
+ export { transformersJsEmbeddingsOptionsSchema } from "./transformers_js/index";
27
+ export { validateOptions as validateTransformersJsEmbeddingsOptions } from "./transformers_js/index";
28
+ export type { TransformersJsEmbeddingsAdapterOptions, TransformersJsEmbeddingsPipeline, TransformersJsEmbeddingsDataType, TransformersJsEmbeddingsDeviceType, TransformersJsEmbeddingsProgressCallback, TransformersJsPooling, CreateTransformersJsEmbeddingsPipeline, } from "./transformers_js/index";
29
+ export { E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS, E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR, } from "./transformers_js/index";
24
30
  export type { EmbeddingKind, EmbedOptions, EmbeddingsRetryConfig, BaseEmbeddingsAdapterOptions, OpenAIEmbeddingsAdapterOptions, OpenAIEmbeddingsRequestBody, OpenAIEmbeddingsResponseBody, } from "./openai/index";
25
31
  export { E_INVALID_OPENAI_EMBEDDINGS_OPTIONS, E_OPENAI_EMBEDDINGS_HTTP_ERROR, E_OPENAI_EMBEDDINGS_REQUEST_TIMEOUT, E_OPENAI_EMBEDDINGS_MALFORMED_RESPONSE, } from "./openai/index";
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("../../../chunk-Cek0wNdY.js");
3
- const require_tool_registry = require("../../../tool_registry-CIIfbY_w.js");
3
+ const require_tool_registry = require("../../../tool_registry-DbS8Pem9.js");
4
4
  require("../../../guards.cjs");
5
5
  const require_lib_utils_retry = require("../../../lib/utils/retry.cjs");
6
6
  const require_batteries_embeddings_openai_exceptions = require("./exceptions.cjs");
@@ -1,4 +1,4 @@
1
- import { c as isError } from "../../../tool_registry-FeMMz993.mjs";
1
+ import { c as isError } from "../../../tool_registry-Bj0JhXCv.mjs";
2
2
  import "../../../guards.mjs";
3
3
  import { computeBackoff, parseRetryAfter, sleepWithJitter } from "../../../lib/utils/retry.mjs";
4
4
  import { E_OPENAI_EMBEDDINGS_HTTP_ERROR, E_OPENAI_EMBEDDINGS_MALFORMED_RESPONSE, E_OPENAI_EMBEDDINGS_REQUEST_TIMEOUT } from "./exceptions.mjs";
@@ -0,0 +1,193 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("../../../chunk-Cek0wNdY.js");
3
+ const require_tool_registry = require("../../../tool_registry-DbS8Pem9.js");
4
+ require("../../../guards.cjs");
5
+ const require_lifecycle = require("../../../lifecycle-vYQJ2rmf.js");
6
+ const require_batteries_llm_transformers_js_model_source = require("../../llm/transformers_js/model_source.cjs");
7
+ const require_batteries_embeddings_openai_helpers = require("../openai/helpers.cjs");
8
+ const require_batteries_embeddings_transformers_js_pooling = require("./pooling.cjs");
9
+ const require_batteries_embeddings_transformers_js_exceptions = require("./exceptions.cjs");
10
+ const require_batteries_embeddings_transformers_js_validation = require("./validation.cjs");
11
+ //#region src/batteries/embeddings/transformers_js/adapter.ts
12
+ /**
13
+ * transformers.js (ONNX, dual-environment) Embeddings adapter battery.
14
+ *
15
+ * @module @nhtio/adk/batteries/embeddings/transformers_js/adapter
16
+ *
17
+ * @remarks
18
+ * Embeddings battery backed by transformers.js's `feature-extraction` pipeline. **Environment-neutral**
19
+ * — runs in Node (via `onnxruntime-node`) and the browser (via `onnxruntime-web` / WebGPU), auto-
20
+ * selected by the package; there is no WebGPU requirement, so this battery is surfaced from the
21
+ * environment-neutral `@nhtio/adk/batteries/embeddings` barrel alongside the OpenAI one.
22
+ *
23
+ * Same user-facing surface as the OpenAI / WebLLM embeddings batteries (`isAvailable` / `dimensions` /
24
+ * `preload` / `reset` / `embed` / `embedMany`), same `number[]` return shape, same query/document
25
+ * prefix handling (the shared `applyEmbeddingPrefix`).
26
+ *
27
+ * `@huggingface/transformers` is an optional peer dependency, imported lazily.
28
+ *
29
+ * **Cross-runtime vector caveat:** embeddings produced here are not guaranteed bit-identical to those
30
+ * from a different runtime (WebLLM/MLC, or even node-ONNX vs web-ONNX for the same model). A vector
31
+ * corpus must be embedded AND queried by one backend.
32
+ */
33
+ var makeDefaultCreatePipeline = (modelSource) => {
34
+ return async ({ model, device, dtype, onInitProgress }) => {
35
+ const { pipeline, env } = await import("@huggingface/transformers");
36
+ const load = async () => await pipeline("feature-extraction", model, {
37
+ ...device ? { device } : {},
38
+ ...dtype ? { dtype } : {},
39
+ ...onInitProgress ? { progress_callback: onInitProgress } : {}
40
+ });
41
+ return modelSource ? require_batteries_llm_transformers_js_model_source.withModelSource(env, modelSource, load) : load();
42
+ };
43
+ };
44
+ /**
45
+ * Embeddings adapter for transformers.js's feature-extraction pipeline.
46
+ *
47
+ * @remarks
48
+ * Reusable: construct once, call {@link TransformersJsEmbeddingsAdapter.embed} / {@link embedMany} as
49
+ * many times as needed. The pipeline is resolved lazily on first use (or via {@link preload}) and
50
+ * cached with single-flight semantics so concurrent calls share one load.
51
+ */
52
+ var TransformersJsEmbeddingsAdapter = class TransformersJsEmbeddingsAdapter {
53
+ #options;
54
+ #pipeline;
55
+ #pipelinePromise;
56
+ /**
57
+ * Whether this battery is available. transformers.js is environment-neutral (Node + browser), so
58
+ * this is `true` whenever the runtime can import the peer — there is no WebGPU requirement.
59
+ */
60
+ static isAvailable() {
61
+ return true;
62
+ }
63
+ /**
64
+ * @param options - Constructor options. Validated eagerly.
65
+ * @throws {@link @nhtio/adk/batteries!E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS} when invalid.
66
+ */
67
+ constructor(options) {
68
+ this.#options = require_batteries_embeddings_transformers_js_validation.validateOptions(options);
69
+ this.#pipeline = this.#options.pipeline;
70
+ }
71
+ /** Declared output dimensionality (from options), or `undefined` if not configured. */
72
+ get dimensions() {
73
+ return this.#options.dimensions;
74
+ }
75
+ /** Instance availability probe (honours an injected `isAvailable`). */
76
+ isAvailable() {
77
+ return (this.#options.isAvailable ?? TransformersJsEmbeddingsAdapter.isAvailable)();
78
+ }
79
+ /** Eagerly loads (and caches) the pipeline so the first `embed` call is fast. Idempotent. */
80
+ async preload() {
81
+ await this.#resolvePipeline();
82
+ }
83
+ /** Drops the cached pipeline and in-flight load so the next call reloads. */
84
+ reset() {
85
+ this.#pipeline = void 0;
86
+ this.#pipelinePromise = void 0;
87
+ }
88
+ /**
89
+ * Release the loaded model's ONNX sessions + GPU/wasm buffers, then drop the cached pipeline.
90
+ *
91
+ * @remarks
92
+ * `reset()` only nulls the JS reference; the native ONNX Runtime sessions and WebGPU/wasm device memory
93
+ * stay alive until GC. Loading many embedding models back-to-back in one browser session (e.g. a full
94
+ * matrix run) accumulates those sessions until the heap is exhausted. `FeatureExtractionPipeline`
95
+ * extends `Pipeline`, which exposes `dispose()` — this awaits it so the memory is reclaimed between
96
+ * loads, swallows a disposal error (teardown must not throw), and finishes with `reset()`. Idempotent.
97
+ */
98
+ async dispose() {
99
+ const pipeWithDispose = this.#pipeline ?? await this.#pipelinePromise?.catch(() => void 0);
100
+ if (typeof pipeWithDispose?.dispose === "function") await Promise.resolve(pipeWithDispose.dispose()).catch(() => void 0);
101
+ this.reset();
102
+ }
103
+ async #resolvePipeline() {
104
+ if (this.#pipeline) return this.#pipeline;
105
+ if (!this.isAvailable()) throw new require_batteries_embeddings_transformers_js_exceptions.E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS(["the transformers.js embeddings battery is not available in this runtime"]);
106
+ const opts = this.#options;
107
+ this.#pipelinePromise ??= (async () => {
108
+ require_lifecycle.emitLifecycle(opts, "transformers_js_embed", opts.model, "loading", { detail: "loading feature-extraction pipeline" });
109
+ const forwardedInitProgress = opts.onLifecycle ?? opts.onLoading ?? opts.onReady ?? opts.onGenerating ?? opts.onError ? (info) => {
110
+ const p = info?.progress;
111
+ require_lifecycle.emitLifecycle(opts, "transformers_js_embed", opts.model, "loading", {
112
+ ...typeof p === "number" ? { progress: p / 100 } : {},
113
+ raw: info
114
+ });
115
+ opts.onInitProgress?.(info);
116
+ } : opts.onInitProgress;
117
+ const createPipeline = opts.createPipeline ?? makeDefaultCreatePipeline(opts.modelSource);
118
+ try {
119
+ require_lifecycle.emitLifecycle(opts, "transformers_js_embed", opts.model, "compiling", { detail: "compiling feature-extraction graph" });
120
+ const pipe = await createPipeline({
121
+ model: opts.model,
122
+ device: opts.device,
123
+ dtype: opts.dtype,
124
+ onInitProgress: forwardedInitProgress
125
+ });
126
+ this.#pipeline = pipe;
127
+ require_lifecycle.emitLifecycle(opts, "transformers_js_embed", opts.model, "ready", { detail: "feature-extraction pipeline ready" });
128
+ return pipe;
129
+ } catch (err) {
130
+ this.#pipelinePromise = void 0;
131
+ require_lifecycle.emitLifecycle(opts, "transformers_js_embed", opts.model, "error", { error: err });
132
+ throw new require_batteries_embeddings_transformers_js_exceptions.E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR([`could not load the transformers.js pipeline: ${require_tool_registry.isError(err) ? err.message : String(err)} — install the peer dependency (pnpm add @huggingface/transformers)`]);
133
+ }
134
+ })();
135
+ return this.#pipelinePromise;
136
+ }
137
+ /**
138
+ * Embeds a single string.
139
+ *
140
+ * @param text - The input text.
141
+ * @param opts - Per-call options (`kind`).
142
+ * @returns The embedding vector as a plain `number[]`.
143
+ */
144
+ async embed(text, opts) {
145
+ const [vec] = await this.embedMany([text], opts);
146
+ return vec;
147
+ }
148
+ /**
149
+ * Embeds a batch of strings in a single pipeline call.
150
+ *
151
+ * @param texts - The input texts.
152
+ * @param opts - Per-call options (`kind`). Defaults to `kind: 'document'`.
153
+ * @returns One embedding vector per input, in input order, each a plain `number[]`.
154
+ * @throws {@link @nhtio/adk/batteries!E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR} when the call fails
155
+ * or returns a malformed result.
156
+ */
157
+ async embedMany(texts, opts) {
158
+ if (texts.length === 0) return [];
159
+ const input = require_batteries_embeddings_openai_helpers.applyEmbeddingPrefix(texts, opts?.kind ?? "document", this.#options);
160
+ const pipe = await this.#resolvePipeline();
161
+ const pooling = this.#options.pooling ?? "mean";
162
+ const normalize = this.#options.normalize ?? true;
163
+ const battery = (this.#options.poolingOwner ?? "engine") === "battery";
164
+ require_lifecycle.emitLifecycle(this.#options, "transformers_js_embed", this.#options.model, "generating");
165
+ let tensor;
166
+ try {
167
+ tensor = await pipe(input, battery ? { pooling: "none" } : {
168
+ pooling,
169
+ normalize
170
+ });
171
+ } catch (err) {
172
+ require_lifecycle.emitLifecycle(this.#options, "transformers_js_embed", this.#options.model, "error", { error: err });
173
+ throw new require_batteries_embeddings_transformers_js_exceptions.E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR([require_tool_registry.isError(err) ? err.message : String(err)]);
174
+ }
175
+ if (!tensor || typeof tensor.tolist !== "function") throw new require_batteries_embeddings_transformers_js_exceptions.E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR(["feature-extraction returned a non-Tensor result"]);
176
+ const list = tensor.tolist();
177
+ let vectors;
178
+ if (battery) {
179
+ const states = list;
180
+ vectors = require_batteries_embeddings_transformers_js_pooling.poolAndNormalize(Array.isArray(states) && Array.isArray(states[0]) && Array.isArray(states[0][0]) ? states : [states], pooling, normalize);
181
+ } else vectors = Array.isArray(list) && Array.isArray(list[0]) ? list : [list];
182
+ if (vectors.length !== input.length) {
183
+ require_lifecycle.emitLifecycle(this.#options, "transformers_js_embed", this.#options.model, "error", { error: /* @__PURE__ */ new Error(`expected ${input.length} vectors, got ${vectors.length}`) });
184
+ throw new require_batteries_embeddings_transformers_js_exceptions.E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR([`expected ${input.length} vectors, got ${vectors.length}`]);
185
+ }
186
+ require_lifecycle.emitLifecycle(this.#options, "transformers_js_embed", this.#options.model, "complete");
187
+ return vectors;
188
+ }
189
+ };
190
+ //#endregion
191
+ exports.TransformersJsEmbeddingsAdapter = TransformersJsEmbeddingsAdapter;
192
+
193
+ //# sourceMappingURL=adapter.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.cjs","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,80 @@
1
+ /**
2
+ * transformers.js (ONNX, dual-environment) Embeddings adapter battery.
3
+ *
4
+ * @module @nhtio/adk/batteries/embeddings/transformers_js/adapter
5
+ *
6
+ * @remarks
7
+ * Embeddings battery backed by transformers.js's `feature-extraction` pipeline. **Environment-neutral**
8
+ * — runs in Node (via `onnxruntime-node`) and the browser (via `onnxruntime-web` / WebGPU), auto-
9
+ * selected by the package; there is no WebGPU requirement, so this battery is surfaced from the
10
+ * environment-neutral `@nhtio/adk/batteries/embeddings` barrel alongside the OpenAI one.
11
+ *
12
+ * Same user-facing surface as the OpenAI / WebLLM embeddings batteries (`isAvailable` / `dimensions` /
13
+ * `preload` / `reset` / `embed` / `embedMany`), same `number[]` return shape, same query/document
14
+ * prefix handling (the shared `applyEmbeddingPrefix`).
15
+ *
16
+ * `@huggingface/transformers` is an optional peer dependency, imported lazily.
17
+ *
18
+ * **Cross-runtime vector caveat:** embeddings produced here are not guaranteed bit-identical to those
19
+ * from a different runtime (WebLLM/MLC, or even node-ONNX vs web-ONNX for the same model). A vector
20
+ * corpus must be embedded AND queried by one backend.
21
+ */
22
+ import type { EmbedOptions } from "../openai/types";
23
+ /**
24
+ * Embeddings adapter for transformers.js's feature-extraction pipeline.
25
+ *
26
+ * @remarks
27
+ * Reusable: construct once, call {@link TransformersJsEmbeddingsAdapter.embed} / {@link embedMany} as
28
+ * many times as needed. The pipeline is resolved lazily on first use (or via {@link preload}) and
29
+ * cached with single-flight semantics so concurrent calls share one load.
30
+ */
31
+ export declare class TransformersJsEmbeddingsAdapter {
32
+ #private;
33
+ /**
34
+ * Whether this battery is available. transformers.js is environment-neutral (Node + browser), so
35
+ * this is `true` whenever the runtime can import the peer — there is no WebGPU requirement.
36
+ */
37
+ static isAvailable(): boolean;
38
+ /**
39
+ * @param options - Constructor options. Validated eagerly.
40
+ * @throws {@link @nhtio/adk/batteries!E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS} when invalid.
41
+ */
42
+ constructor(options: unknown);
43
+ /** Declared output dimensionality (from options), or `undefined` if not configured. */
44
+ get dimensions(): number | undefined;
45
+ /** Instance availability probe (honours an injected `isAvailable`). */
46
+ isAvailable(): boolean;
47
+ /** Eagerly loads (and caches) the pipeline so the first `embed` call is fast. Idempotent. */
48
+ preload(): Promise<void>;
49
+ /** Drops the cached pipeline and in-flight load so the next call reloads. */
50
+ reset(): void;
51
+ /**
52
+ * Release the loaded model's ONNX sessions + GPU/wasm buffers, then drop the cached pipeline.
53
+ *
54
+ * @remarks
55
+ * `reset()` only nulls the JS reference; the native ONNX Runtime sessions and WebGPU/wasm device memory
56
+ * stay alive until GC. Loading many embedding models back-to-back in one browser session (e.g. a full
57
+ * matrix run) accumulates those sessions until the heap is exhausted. `FeatureExtractionPipeline`
58
+ * extends `Pipeline`, which exposes `dispose()` — this awaits it so the memory is reclaimed between
59
+ * loads, swallows a disposal error (teardown must not throw), and finishes with `reset()`. Idempotent.
60
+ */
61
+ dispose(): Promise<void>;
62
+ /**
63
+ * Embeds a single string.
64
+ *
65
+ * @param text - The input text.
66
+ * @param opts - Per-call options (`kind`).
67
+ * @returns The embedding vector as a plain `number[]`.
68
+ */
69
+ embed(text: string, opts?: EmbedOptions): Promise<number[]>;
70
+ /**
71
+ * Embeds a batch of strings in a single pipeline call.
72
+ *
73
+ * @param texts - The input texts.
74
+ * @param opts - Per-call options (`kind`). Defaults to `kind: 'document'`.
75
+ * @returns One embedding vector per input, in input order, each a plain `number[]`.
76
+ * @throws {@link @nhtio/adk/batteries!E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR} when the call fails
77
+ * or returns a malformed result.
78
+ */
79
+ embedMany(texts: string[], opts?: EmbedOptions): Promise<number[][]>;
80
+ }