@nhtio/adk 1.20260607.2 → 1.20260609.1

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 (521) hide show
  1. package/CHANGELOG.md +230 -0
  2. package/batteries/embeddings/openai/adapter.cjs +1 -1
  3. package/batteries/embeddings/openai/adapter.mjs +1 -1
  4. package/batteries/embeddings/openai/exceptions.cjs +1 -1
  5. package/batteries/embeddings/openai/exceptions.mjs +1 -1
  6. package/batteries/embeddings/openai/types.d.ts +7 -0
  7. package/batteries/embeddings/webllm/adapter.cjs +1 -1
  8. package/batteries/embeddings/webllm/adapter.mjs +1 -1
  9. package/batteries/embeddings/webllm/exceptions.cjs +1 -1
  10. package/batteries/embeddings/webllm/exceptions.mjs +1 -1
  11. package/batteries/llm/chat_common/helpers.d.ts +165 -0
  12. package/batteries/llm/chat_common/types.d.ts +309 -0
  13. package/batteries/llm/index.d.ts +5 -0
  14. package/batteries/llm/ollama/adapter.cjs +736 -0
  15. package/batteries/llm/ollama/adapter.cjs.map +1 -0
  16. package/batteries/llm/ollama/adapter.d.ts +64 -0
  17. package/batteries/llm/ollama/adapter.mjs +734 -0
  18. package/batteries/llm/ollama/adapter.mjs.map +1 -0
  19. package/batteries/llm/ollama/exceptions.cjs +105 -0
  20. package/batteries/llm/ollama/exceptions.cjs.map +1 -0
  21. package/batteries/llm/ollama/exceptions.d.ts +112 -0
  22. package/batteries/llm/ollama/exceptions.mjs +96 -0
  23. package/batteries/llm/ollama/exceptions.mjs.map +1 -0
  24. package/batteries/llm/ollama/helpers.cjs +487 -0
  25. package/batteries/llm/ollama/helpers.cjs.map +1 -0
  26. package/batteries/llm/ollama/helpers.d.ts +158 -0
  27. package/batteries/llm/ollama/helpers.mjs +450 -0
  28. package/batteries/llm/ollama/helpers.mjs.map +1 -0
  29. package/batteries/llm/ollama/index.d.ts +29 -0
  30. package/batteries/llm/ollama/types.cjs +2 -0
  31. package/batteries/llm/ollama/types.d.ts +334 -0
  32. package/batteries/llm/ollama/types.mjs +0 -0
  33. package/batteries/llm/ollama/validation.cjs +130 -0
  34. package/batteries/llm/ollama/validation.cjs.map +1 -0
  35. package/batteries/llm/ollama/validation.d.ts +31 -0
  36. package/batteries/llm/ollama/validation.mjs +127 -0
  37. package/batteries/llm/ollama/validation.mjs.map +1 -0
  38. package/batteries/llm/ollama.cjs +54 -0
  39. package/batteries/llm/ollama.mjs +6 -0
  40. package/batteries/llm/openai_chat_completions/adapter.cjs +36 -19
  41. package/batteries/llm/openai_chat_completions/adapter.cjs.map +1 -1
  42. package/batteries/llm/openai_chat_completions/adapter.mjs +23 -6
  43. package/batteries/llm/openai_chat_completions/adapter.mjs.map +1 -1
  44. package/batteries/llm/openai_chat_completions/exceptions.cjs +1 -1
  45. package/batteries/llm/openai_chat_completions/exceptions.mjs +1 -1
  46. package/batteries/llm/openai_chat_completions/helpers.cjs +80 -320
  47. package/batteries/llm/openai_chat_completions/helpers.cjs.map +1 -1
  48. package/batteries/llm/openai_chat_completions/helpers.d.ts +68 -144
  49. package/batteries/llm/openai_chat_completions/helpers.mjs +40 -280
  50. package/batteries/llm/openai_chat_completions/helpers.mjs.map +1 -1
  51. package/batteries/llm/openai_chat_completions/types.d.ts +273 -181
  52. package/batteries/llm/openai_chat_completions/validation.cjs +2 -2
  53. package/batteries/llm/openai_chat_completions/validation.cjs.map +1 -1
  54. package/batteries/llm/openai_chat_completions/validation.mjs +2 -2
  55. package/batteries/llm/openai_chat_completions/validation.mjs.map +1 -1
  56. package/batteries/llm/openai_chat_completions.cjs +29 -28
  57. package/batteries/llm/openai_chat_completions.mjs +2 -1
  58. package/batteries/llm/webllm_chat_completions/adapter.cjs +38 -19
  59. package/batteries/llm/webllm_chat_completions/adapter.cjs.map +1 -1
  60. package/batteries/llm/webllm_chat_completions/adapter.d.ts +18 -0
  61. package/batteries/llm/webllm_chat_completions/adapter.mjs +25 -6
  62. package/batteries/llm/webllm_chat_completions/adapter.mjs.map +1 -1
  63. package/batteries/llm/webllm_chat_completions/exceptions.cjs +1 -1
  64. package/batteries/llm/webllm_chat_completions/exceptions.mjs +1 -1
  65. package/batteries/llm/webllm_chat_completions/helpers.cjs +29 -28
  66. package/batteries/llm/webllm_chat_completions/helpers.mjs +2 -1
  67. package/batteries/llm/webllm_chat_completions/types.d.ts +21 -0
  68. package/batteries/llm/webllm_chat_completions/validation.cjs +13 -1
  69. package/batteries/llm/webllm_chat_completions/validation.cjs.map +1 -1
  70. package/batteries/llm/webllm_chat_completions/validation.d.ts +12 -0
  71. package/batteries/llm/webllm_chat_completions/validation.mjs +13 -1
  72. package/batteries/llm/webllm_chat_completions/validation.mjs.map +1 -1
  73. package/batteries/llm/webllm_chat_completions.cjs +29 -28
  74. package/batteries/llm/webllm_chat_completions.mjs +2 -1
  75. package/batteries/llm.cjs +44 -28
  76. package/batteries/llm.mjs +9 -4
  77. package/batteries/storage/flydrive.cjs +1 -1
  78. package/batteries/storage/flydrive.mjs +1 -1
  79. package/batteries/storage/in_memory/index.d.ts +1 -1
  80. package/batteries/storage/in_memory.cjs +2 -2
  81. package/batteries/storage/in_memory.cjs.map +1 -1
  82. package/batteries/storage/in_memory.mjs +2 -2
  83. package/batteries/storage/in_memory.mjs.map +1 -1
  84. package/batteries/storage/opfs/index.d.ts +19 -0
  85. package/batteries/storage/opfs.cjs +1 -1
  86. package/batteries/storage/opfs.cjs.map +1 -1
  87. package/batteries/storage/opfs.mjs +1 -1
  88. package/batteries/storage/opfs.mjs.map +1 -1
  89. package/batteries/tools/_shared/index.d.ts +121 -0
  90. package/batteries/tools/_shared.cjs +157 -0
  91. package/batteries/tools/_shared.cjs.map +1 -0
  92. package/batteries/tools/_shared.mjs +149 -0
  93. package/batteries/tools/_shared.mjs.map +1 -0
  94. package/batteries/tools/color.cjs +3 -2
  95. package/batteries/tools/color.cjs.map +1 -1
  96. package/batteries/tools/color.mjs +3 -2
  97. package/batteries/tools/color.mjs.map +1 -1
  98. package/batteries/tools/comparison.cjs +4 -3
  99. package/batteries/tools/comparison.cjs.map +1 -1
  100. package/batteries/tools/comparison.mjs +4 -3
  101. package/batteries/tools/comparison.mjs.map +1 -1
  102. package/batteries/tools/data_structure.cjs +30 -10
  103. package/batteries/tools/data_structure.cjs.map +1 -1
  104. package/batteries/tools/data_structure.mjs +30 -10
  105. package/batteries/tools/data_structure.mjs.map +1 -1
  106. package/batteries/tools/datetime_extended.cjs +5 -10
  107. package/batteries/tools/datetime_extended.cjs.map +1 -1
  108. package/batteries/tools/datetime_extended.mjs +5 -10
  109. package/batteries/tools/datetime_extended.mjs.map +1 -1
  110. package/batteries/tools/datetime_math.cjs +2 -2
  111. package/batteries/tools/datetime_math.mjs +2 -2
  112. package/batteries/tools/encoding.cjs +13 -4
  113. package/batteries/tools/encoding.cjs.map +1 -1
  114. package/batteries/tools/encoding.mjs +13 -4
  115. package/batteries/tools/encoding.mjs.map +1 -1
  116. package/batteries/tools/formatting.cjs +4 -4
  117. package/batteries/tools/formatting.cjs.map +1 -1
  118. package/batteries/tools/formatting.mjs +4 -4
  119. package/batteries/tools/formatting.mjs.map +1 -1
  120. package/batteries/tools/geo_basics.cjs +2 -2
  121. package/batteries/tools/geo_basics.mjs +2 -2
  122. package/batteries/tools/index.d.ts +3 -0
  123. package/batteries/tools/math.cjs +10 -8
  124. package/batteries/tools/math.cjs.map +1 -1
  125. package/batteries/tools/math.mjs +10 -8
  126. package/batteries/tools/math.mjs.map +1 -1
  127. package/batteries/tools/memory.cjs +5 -5
  128. package/batteries/tools/memory.mjs +5 -5
  129. package/batteries/tools/parsing.cjs +9 -5
  130. package/batteries/tools/parsing.cjs.map +1 -1
  131. package/batteries/tools/parsing.mjs +9 -5
  132. package/batteries/tools/parsing.mjs.map +1 -1
  133. package/batteries/tools/retrievables.cjs +4 -4
  134. package/batteries/tools/retrievables.mjs +4 -4
  135. package/batteries/tools/scrapper/exceptions.d.ts +21 -0
  136. package/batteries/tools/scrapper/index.d.ts +172 -0
  137. package/batteries/tools/scrapper/shared.d.ts +139 -0
  138. package/batteries/tools/scrapper.cjs +8 -0
  139. package/batteries/tools/scrapper.mjs +2 -0
  140. package/batteries/tools/searxng/exceptions.d.ts +21 -0
  141. package/batteries/tools/searxng/index.d.ts +177 -0
  142. package/batteries/tools/searxng.cjs +6 -0
  143. package/batteries/tools/searxng.mjs +2 -0
  144. package/batteries/tools/standing_instructions.cjs +4 -4
  145. package/batteries/tools/standing_instructions.mjs +4 -4
  146. package/batteries/tools/statistics.cjs +54 -43
  147. package/batteries/tools/statistics.cjs.map +1 -1
  148. package/batteries/tools/statistics.mjs +54 -43
  149. package/batteries/tools/statistics.mjs.map +1 -1
  150. package/batteries/tools/string_processing.cjs +5 -5
  151. package/batteries/tools/string_processing.cjs.map +1 -1
  152. package/batteries/tools/string_processing.mjs +5 -5
  153. package/batteries/tools/string_processing.mjs.map +1 -1
  154. package/batteries/tools/structured_data.cjs +8 -13
  155. package/batteries/tools/structured_data.cjs.map +1 -1
  156. package/batteries/tools/structured_data.mjs +8 -13
  157. package/batteries/tools/structured_data.mjs.map +1 -1
  158. package/batteries/tools/text_analysis.cjs +3 -3
  159. package/batteries/tools/text_analysis.mjs +3 -3
  160. package/batteries/tools/text_comparison.cjs +2 -2
  161. package/batteries/tools/text_comparison.mjs +2 -2
  162. package/batteries/tools/time.cjs +2 -2
  163. package/batteries/tools/time.mjs +2 -2
  164. package/batteries/tools/unit_conversion.cjs +10 -8
  165. package/batteries/tools/unit_conversion.cjs.map +1 -1
  166. package/batteries/tools/unit_conversion.mjs +10 -8
  167. package/batteries/tools/unit_conversion.mjs.map +1 -1
  168. package/batteries/tools/web_retrieval/index.d.ts +186 -0
  169. package/batteries/tools/web_retrieval.cjs +206 -0
  170. package/batteries/tools/web_retrieval.cjs.map +1 -0
  171. package/batteries/tools/web_retrieval.mjs +201 -0
  172. package/batteries/tools/web_retrieval.mjs.map +1 -0
  173. package/batteries/tools.cjs +15 -0
  174. package/batteries/tools.mjs +4 -1
  175. package/batteries/vector/arangodb/index.d.ts +2 -0
  176. package/batteries/vector/arangodb.cjs +2 -1
  177. package/batteries/vector/arangodb.cjs.map +1 -1
  178. package/batteries/vector/arangodb.mjs +2 -1
  179. package/batteries/vector/arangodb.mjs.map +1 -1
  180. package/batteries/vector/builder.cjs +31 -0
  181. package/batteries/vector/builder.cjs.map +1 -1
  182. package/batteries/vector/builder.d.ts +58 -0
  183. package/batteries/vector/builder.mjs +31 -0
  184. package/batteries/vector/builder.mjs.map +1 -1
  185. package/batteries/vector/chroma/index.d.ts +4 -0
  186. package/batteries/vector/chroma.cjs +3 -0
  187. package/batteries/vector/chroma.cjs.map +1 -1
  188. package/batteries/vector/chroma.mjs +3 -0
  189. package/batteries/vector/chroma.mjs.map +1 -1
  190. package/batteries/vector/clickhouse/index.d.ts +2 -0
  191. package/batteries/vector/clickhouse.cjs +2 -1
  192. package/batteries/vector/clickhouse.cjs.map +1 -1
  193. package/batteries/vector/clickhouse.mjs +2 -1
  194. package/batteries/vector/clickhouse.mjs.map +1 -1
  195. package/batteries/vector/cloudflare/index.d.ts +2 -0
  196. package/batteries/vector/cloudflare.cjs +2 -1
  197. package/batteries/vector/cloudflare.cjs.map +1 -1
  198. package/batteries/vector/cloudflare.mjs +2 -1
  199. package/batteries/vector/cloudflare.mjs.map +1 -1
  200. package/batteries/vector/conformance/index.d.ts +22 -0
  201. package/batteries/vector/conformance.cjs +22 -0
  202. package/batteries/vector/conformance.cjs.map +1 -1
  203. package/batteries/vector/conformance.mjs +22 -0
  204. package/batteries/vector/conformance.mjs.map +1 -1
  205. package/batteries/vector/contract.cjs +22 -0
  206. package/batteries/vector/contract.cjs.map +1 -1
  207. package/batteries/vector/contract.d.ts +51 -0
  208. package/batteries/vector/contract.mjs +22 -0
  209. package/batteries/vector/contract.mjs.map +1 -1
  210. package/batteries/vector/couchbase/index.d.ts +2 -0
  211. package/batteries/vector/couchbase.cjs +2 -1
  212. package/batteries/vector/couchbase.cjs.map +1 -1
  213. package/batteries/vector/couchbase.mjs +2 -1
  214. package/batteries/vector/couchbase.mjs.map +1 -1
  215. package/batteries/vector/duckdb/index.d.ts +2 -0
  216. package/batteries/vector/duckdb.cjs +2 -1
  217. package/batteries/vector/duckdb.cjs.map +1 -1
  218. package/batteries/vector/duckdb.mjs +2 -1
  219. package/batteries/vector/duckdb.mjs.map +1 -1
  220. package/batteries/vector/elasticsearch/index.d.ts +2 -0
  221. package/batteries/vector/elasticsearch.cjs +2 -1
  222. package/batteries/vector/elasticsearch.cjs.map +1 -1
  223. package/batteries/vector/elasticsearch.mjs +2 -1
  224. package/batteries/vector/elasticsearch.mjs.map +1 -1
  225. package/batteries/vector/exceptions.cjs +1 -1
  226. package/batteries/vector/exceptions.mjs +1 -1
  227. package/batteries/vector/factory.cjs +6 -0
  228. package/batteries/vector/factory.cjs.map +1 -1
  229. package/batteries/vector/factory.d.ts +14 -0
  230. package/batteries/vector/factory.mjs +6 -0
  231. package/batteries/vector/factory.mjs.map +1 -1
  232. package/batteries/vector/filters.cjs +22 -1
  233. package/batteries/vector/filters.cjs.map +1 -1
  234. package/batteries/vector/filters.d.ts +38 -0
  235. package/batteries/vector/filters.mjs +22 -1
  236. package/batteries/vector/filters.mjs.map +1 -1
  237. package/batteries/vector/helpers.cjs +13 -0
  238. package/batteries/vector/helpers.cjs.map +1 -1
  239. package/batteries/vector/helpers.d.ts +14 -0
  240. package/batteries/vector/helpers.mjs +13 -0
  241. package/batteries/vector/helpers.mjs.map +1 -1
  242. package/batteries/vector/hnswlib/index.d.ts +2 -0
  243. package/batteries/vector/hnswlib.cjs +2 -1
  244. package/batteries/vector/hnswlib.cjs.map +1 -1
  245. package/batteries/vector/hnswlib.mjs +2 -1
  246. package/batteries/vector/hnswlib.mjs.map +1 -1
  247. package/batteries/vector/in_memory/index.d.ts +1 -0
  248. package/batteries/vector/in_memory.cjs +1 -0
  249. package/batteries/vector/in_memory.cjs.map +1 -1
  250. package/batteries/vector/in_memory.mjs +1 -0
  251. package/batteries/vector/in_memory.mjs.map +1 -1
  252. package/batteries/vector/lancedb/index.d.ts +2 -0
  253. package/batteries/vector/lancedb.cjs +2 -1
  254. package/batteries/vector/lancedb.cjs.map +1 -1
  255. package/batteries/vector/lancedb.mjs +2 -1
  256. package/batteries/vector/lancedb.mjs.map +1 -1
  257. package/batteries/vector/mariadb/index.d.ts +2 -0
  258. package/batteries/vector/mariadb.cjs +2 -1
  259. package/batteries/vector/mariadb.cjs.map +1 -1
  260. package/batteries/vector/mariadb.mjs +2 -1
  261. package/batteries/vector/mariadb.mjs.map +1 -1
  262. package/batteries/vector/meilisearch/index.d.ts +2 -0
  263. package/batteries/vector/meilisearch.cjs +2 -1
  264. package/batteries/vector/meilisearch.cjs.map +1 -1
  265. package/batteries/vector/meilisearch.mjs +2 -1
  266. package/batteries/vector/meilisearch.mjs.map +1 -1
  267. package/batteries/vector/migrate.cjs +18 -1
  268. package/batteries/vector/migrate.cjs.map +1 -1
  269. package/batteries/vector/migrate.d.ts +31 -0
  270. package/batteries/vector/migrate.mjs +18 -1
  271. package/batteries/vector/migrate.mjs.map +1 -1
  272. package/batteries/vector/milvus/index.d.ts +5 -0
  273. package/batteries/vector/milvus.cjs +4 -0
  274. package/batteries/vector/milvus.cjs.map +1 -1
  275. package/batteries/vector/milvus.mjs +4 -0
  276. package/batteries/vector/milvus.mjs.map +1 -1
  277. package/batteries/vector/mongodb/index.d.ts +2 -0
  278. package/batteries/vector/mongodb.cjs +2 -1
  279. package/batteries/vector/mongodb.cjs.map +1 -1
  280. package/batteries/vector/mongodb.mjs +2 -1
  281. package/batteries/vector/mongodb.mjs.map +1 -1
  282. package/batteries/vector/neo4j/index.d.ts +2 -0
  283. package/batteries/vector/neo4j.cjs +2 -1
  284. package/batteries/vector/neo4j.cjs.map +1 -1
  285. package/batteries/vector/neo4j.mjs +2 -1
  286. package/batteries/vector/neo4j.mjs.map +1 -1
  287. package/batteries/vector/opensearch/index.d.ts +2 -0
  288. package/batteries/vector/opensearch.cjs +2 -1
  289. package/batteries/vector/opensearch.cjs.map +1 -1
  290. package/batteries/vector/opensearch.mjs +2 -1
  291. package/batteries/vector/opensearch.mjs.map +1 -1
  292. package/batteries/vector/oracle23ai/index.d.ts +2 -0
  293. package/batteries/vector/oracle23ai.cjs +2 -1
  294. package/batteries/vector/oracle23ai.cjs.map +1 -1
  295. package/batteries/vector/oracle23ai.mjs +2 -1
  296. package/batteries/vector/oracle23ai.mjs.map +1 -1
  297. package/batteries/vector/orama/index.d.ts +1 -0
  298. package/batteries/vector/orama.cjs +1 -0
  299. package/batteries/vector/orama.cjs.map +1 -1
  300. package/batteries/vector/orama.mjs +1 -0
  301. package/batteries/vector/orama.mjs.map +1 -1
  302. package/batteries/vector/pgvector/index.d.ts +9 -2
  303. package/batteries/vector/pgvector.cjs +4 -0
  304. package/batteries/vector/pgvector.cjs.map +1 -1
  305. package/batteries/vector/pgvector.mjs +4 -0
  306. package/batteries/vector/pgvector.mjs.map +1 -1
  307. package/batteries/vector/pinecone/index.d.ts +5 -0
  308. package/batteries/vector/pinecone.cjs +3 -1
  309. package/batteries/vector/pinecone.cjs.map +1 -1
  310. package/batteries/vector/pinecone.mjs +3 -1
  311. package/batteries/vector/pinecone.mjs.map +1 -1
  312. package/batteries/vector/plan.d.ts +27 -0
  313. package/batteries/vector/qdrant/index.d.ts +5 -0
  314. package/batteries/vector/qdrant.cjs +4 -0
  315. package/batteries/vector/qdrant.cjs.map +1 -1
  316. package/batteries/vector/qdrant.mjs +4 -0
  317. package/batteries/vector/qdrant.mjs.map +1 -1
  318. package/batteries/vector/redis/index.d.ts +2 -0
  319. package/batteries/vector/redis.cjs +2 -1
  320. package/batteries/vector/redis.cjs.map +1 -1
  321. package/batteries/vector/redis.mjs +2 -1
  322. package/batteries/vector/redis.mjs.map +1 -1
  323. package/batteries/vector/retrievable.cjs +9 -1
  324. package/batteries/vector/retrievable.cjs.map +1 -1
  325. package/batteries/vector/retrievable.mjs +9 -1
  326. package/batteries/vector/retrievable.mjs.map +1 -1
  327. package/batteries/vector/retrievable_glue.d.ts +21 -0
  328. package/batteries/vector/s3vectors/index.d.ts +2 -0
  329. package/batteries/vector/s3vectors.cjs +2 -1
  330. package/batteries/vector/s3vectors.cjs.map +1 -1
  331. package/batteries/vector/s3vectors.mjs +2 -1
  332. package/batteries/vector/s3vectors.mjs.map +1 -1
  333. package/batteries/vector/schema.cjs +28 -0
  334. package/batteries/vector/schema.cjs.map +1 -1
  335. package/batteries/vector/schema.d.ts +39 -0
  336. package/batteries/vector/schema.mjs +28 -0
  337. package/batteries/vector/schema.mjs.map +1 -1
  338. package/batteries/vector/solr/index.d.ts +2 -0
  339. package/batteries/vector/solr.cjs +2 -1
  340. package/batteries/vector/solr.cjs.map +1 -1
  341. package/batteries/vector/solr.mjs +2 -1
  342. package/batteries/vector/solr.mjs.map +1 -1
  343. package/batteries/vector/sqlite_vec/index.d.ts +6 -3
  344. package/batteries/vector/sqlite_vec.cjs +2 -0
  345. package/batteries/vector/sqlite_vec.cjs.map +1 -1
  346. package/batteries/vector/sqlite_vec.mjs +2 -0
  347. package/batteries/vector/sqlite_vec.mjs.map +1 -1
  348. package/batteries/vector/surrealdb/index.d.ts +2 -0
  349. package/batteries/vector/surrealdb.cjs +2 -1
  350. package/batteries/vector/surrealdb.cjs.map +1 -1
  351. package/batteries/vector/surrealdb.mjs +2 -1
  352. package/batteries/vector/surrealdb.mjs.map +1 -1
  353. package/batteries/vector/types.d.ts +27 -0
  354. package/batteries/vector/typesense/index.d.ts +2 -0
  355. package/batteries/vector/typesense.cjs +2 -1
  356. package/batteries/vector/typesense.cjs.map +1 -1
  357. package/batteries/vector/typesense.mjs +2 -1
  358. package/batteries/vector/typesense.mjs.map +1 -1
  359. package/batteries/vector/validation.cjs +14 -0
  360. package/batteries/vector/validation.cjs.map +1 -1
  361. package/batteries/vector/validation.d.ts +14 -0
  362. package/batteries/vector/validation.mjs +14 -0
  363. package/batteries/vector/validation.mjs.map +1 -1
  364. package/batteries/vector/vector_store_constructor.cjs +1 -1
  365. package/batteries/vector/vector_store_constructor.cjs.map +1 -1
  366. package/batteries/vector/vector_store_constructor.d.ts +1 -1
  367. package/batteries/vector/vector_store_constructor.mjs +1 -1
  368. package/batteries/vector/vector_store_constructor.mjs.map +1 -1
  369. package/batteries/vector/vespa/index.d.ts +2 -0
  370. package/batteries/vector/vespa.cjs +2 -1
  371. package/batteries/vector/vespa.cjs.map +1 -1
  372. package/batteries/vector/vespa.mjs +2 -1
  373. package/batteries/vector/vespa.mjs.map +1 -1
  374. package/batteries/vector/weaviate/index.d.ts +2 -0
  375. package/batteries/vector/weaviate.cjs +2 -1
  376. package/batteries/vector/weaviate.cjs.map +1 -1
  377. package/batteries/vector/weaviate.mjs +2 -1
  378. package/batteries/vector/weaviate.mjs.map +1 -1
  379. package/batteries.cjs +58 -28
  380. package/batteries.mjs +12 -5
  381. package/{common-BT0nfCi9.mjs → common-DYDUi99O.mjs} +9 -9
  382. package/common-DYDUi99O.mjs.map +1 -0
  383. package/{common-Cj8TaQ9U.js → common-DZl3ADJs.js} +9 -9
  384. package/common-DZl3ADJs.js.map +1 -0
  385. package/common.cjs +7 -7
  386. package/common.mjs +7 -7
  387. package/{dispatch_runner-DPcS7Y_M.mjs → dispatch_runner--ZhdDWRZ.mjs} +27 -5
  388. package/{dispatch_runner-DPcS7Y_M.mjs.map → dispatch_runner--ZhdDWRZ.mjs.map} +1 -1
  389. package/{dispatch_runner-BHBNupqp.js → dispatch_runner-nHDKkxye.js} +27 -5
  390. package/{dispatch_runner-BHBNupqp.js.map → dispatch_runner-nHDKkxye.js.map} +1 -1
  391. package/dispatch_runner.cjs +1 -1
  392. package/dispatch_runner.d.ts +1 -1
  393. package/dispatch_runner.mjs +1 -1
  394. package/eslint/rules/artifact_tool_forbids_artifact_constructor.cjs +1 -0
  395. package/eslint/rules/artifact_tool_forbids_artifact_constructor.cjs.map +1 -1
  396. package/eslint/rules/artifact_tool_forbids_artifact_constructor.d.ts +1 -0
  397. package/eslint/rules/artifact_tool_forbids_artifact_constructor.mjs +1 -0
  398. package/eslint/rules/artifact_tool_forbids_artifact_constructor.mjs.map +1 -1
  399. package/eslint/rules/no_model_in_tool_handler.cjs +1 -0
  400. package/eslint/rules/no_model_in_tool_handler.cjs.map +1 -1
  401. package/eslint/rules/no_model_in_tool_handler.d.ts +1 -0
  402. package/eslint/rules/no_model_in_tool_handler.mjs +1 -0
  403. package/eslint/rules/no_model_in_tool_handler.mjs.map +1 -1
  404. package/eslint/rules/require_validator_any_required.cjs +1 -0
  405. package/eslint/rules/require_validator_any_required.cjs.map +1 -1
  406. package/eslint/rules/require_validator_any_required.d.ts +1 -0
  407. package/eslint/rules/require_validator_any_required.mjs +1 -0
  408. package/eslint/rules/require_validator_any_required.mjs.map +1 -1
  409. package/eslint/rules/thought_payload_requires_replay_tag.cjs +1 -0
  410. package/eslint/rules/thought_payload_requires_replay_tag.cjs.map +1 -1
  411. package/eslint/rules/thought_payload_requires_replay_tag.d.ts +1 -0
  412. package/eslint/rules/thought_payload_requires_replay_tag.mjs +1 -0
  413. package/eslint/rules/thought_payload_requires_replay_tag.mjs.map +1 -1
  414. package/eslint/rules/token_encoding_requires_context_window.cjs +1 -0
  415. package/eslint/rules/token_encoding_requires_context_window.cjs.map +1 -1
  416. package/eslint/rules/token_encoding_requires_context_window.d.ts +1 -0
  417. package/eslint/rules/token_encoding_requires_context_window.mjs +1 -0
  418. package/eslint/rules/token_encoding_requires_context_window.mjs.map +1 -1
  419. package/eslint/rules.cjs +1 -1
  420. package/eslint/rules.mjs +1 -1
  421. package/eslint.cjs +2 -2
  422. package/eslint.mjs +2 -2
  423. package/{exceptions-BeWH2FwP.mjs → exceptions-BDhN0Xzr.mjs} +3 -2
  424. package/exceptions-BDhN0Xzr.mjs.map +1 -0
  425. package/{exceptions-CitH5wZI.js → exceptions-BRXrUKiW.js} +3 -2
  426. package/exceptions-BRXrUKiW.js.map +1 -0
  427. package/exceptions.cjs +2 -2
  428. package/exceptions.mjs +2 -2
  429. package/factories.cjs +1 -1
  430. package/factories.mjs +1 -1
  431. package/forge.cjs +4 -4
  432. package/forge.d.ts +1 -1
  433. package/forge.mjs +4 -4
  434. package/guards.cjs +9 -9
  435. package/guards.mjs +9 -9
  436. package/helpers-DSTFxTiC.js +497 -0
  437. package/helpers-DSTFxTiC.js.map +1 -0
  438. package/helpers-xhrQbMAG.mjs +306 -0
  439. package/helpers-xhrQbMAG.mjs.map +1 -0
  440. package/index.cjs +12 -12
  441. package/index.mjs +12 -12
  442. package/lib/classes/base_exception.d.ts +1 -0
  443. package/lib/classes/media.d.ts +10 -0
  444. package/lib/classes/retrievable.d.ts +1 -1
  445. package/lib/classes/spooled_json_artifact.d.ts +1 -1
  446. package/lib/classes/spooled_markdown_artifact.d.ts +1 -0
  447. package/lib/classes/tokenizable.d.ts +3 -0
  448. package/lib/classes/tool.d.ts +8 -0
  449. package/lib/classes/turn_gate.d.ts +6 -0
  450. package/lib/dispatch_runner.d.ts +4 -32
  451. package/lib/helpers/bignum.cjs +82 -0
  452. package/lib/helpers/bignum.cjs.map +1 -0
  453. package/lib/helpers/bignum.d.ts +52 -0
  454. package/lib/helpers/bignum.mjs +74 -0
  455. package/lib/helpers/bignum.mjs.map +1 -0
  456. package/lib/turn_runner.d.ts +1 -1
  457. package/lib/types/dispatch_runner.d.ts +83 -0
  458. package/lib/utils/exceptions.d.ts +1 -1
  459. package/lib/utils/retry.cjs.map +1 -1
  460. package/lib/utils/retry.d.ts +2 -0
  461. package/lib/utils/retry.mjs.map +1 -1
  462. package/mcp/adk-docs-corpus.json +1 -1
  463. package/package.json +259 -204
  464. package/{runtime-j92CNi5z.mjs → runtime-Bz5zA8wc.mjs} +2 -2
  465. package/{runtime-j92CNi5z.mjs.map → runtime-Bz5zA8wc.mjs.map} +1 -1
  466. package/{runtime-MFFcJrRv.js → runtime-DslE1aBw.js} +2 -2
  467. package/{runtime-MFFcJrRv.js.map → runtime-DslE1aBw.js.map} +1 -1
  468. package/scrapper-BHM1mCde.mjs +432 -0
  469. package/scrapper-BHM1mCde.mjs.map +1 -0
  470. package/scrapper-BeweWurk.js +462 -0
  471. package/scrapper-BeweWurk.js.map +1 -0
  472. package/searxng-BJFulNcK.mjs +247 -0
  473. package/searxng-BJFulNcK.mjs.map +1 -0
  474. package/searxng-B_D--V5q.js +265 -0
  475. package/searxng-B_D--V5q.js.map +1 -0
  476. package/skills/adk-assembly/SKILL.md +2 -2
  477. package/{spooled_artifact-CHoZgWwI.mjs → spooled_artifact-7eePq7JA.mjs} +5 -5
  478. package/{spooled_artifact-CHoZgWwI.mjs.map → spooled_artifact-7eePq7JA.mjs.map} +1 -1
  479. package/{spooled_artifact-BTq6Nzfy.js → spooled_artifact-DX8LLyUX.js} +5 -5
  480. package/{spooled_artifact-BTq6Nzfy.js.map → spooled_artifact-DX8LLyUX.js.map} +1 -1
  481. package/spooled_artifact.cjs +2 -2
  482. package/spooled_artifact.mjs +2 -2
  483. package/{spooled_markdown_artifact-CALSDxIx.js → spooled_markdown_artifact-ClX72lek.js} +4 -4
  484. package/spooled_markdown_artifact-ClX72lek.js.map +1 -0
  485. package/{spooled_markdown_artifact-Ci5UL7l4.mjs → spooled_markdown_artifact-wkrBF3oX.mjs} +4 -4
  486. package/spooled_markdown_artifact-wkrBF3oX.mjs.map +1 -0
  487. package/{thought-D34QQZZ9.mjs → thought-B_vxAiKU.mjs} +5 -5
  488. package/{thought-D34QQZZ9.mjs.map → thought-B_vxAiKU.mjs.map} +1 -1
  489. package/{thought-BbwhJ1wb.js → thought-DLwpF7MI.js} +5 -5
  490. package/{thought-BbwhJ1wb.js.map → thought-DLwpF7MI.js.map} +1 -1
  491. package/{tool-CVyZkFC7.js → tool-D5WGVIcI.js} +4 -4
  492. package/{tool-CVyZkFC7.js.map → tool-D5WGVIcI.js.map} +1 -1
  493. package/{tool-CMhaDRNd.mjs → tool-wMYMVl60.mjs} +4 -4
  494. package/{tool-CMhaDRNd.mjs.map → tool-wMYMVl60.mjs.map} +1 -1
  495. package/{tool_call-CV5qVNlb.mjs → tool_call-B4-_-vjG.mjs} +5 -5
  496. package/tool_call-B4-_-vjG.mjs.map +1 -0
  497. package/{tool_call-Db68hB7y.js → tool_call-DixVlW40.js} +5 -5
  498. package/tool_call-DixVlW40.js.map +1 -0
  499. package/{tool_registry-D1pSSlsd.mjs → tool_registry-791Vrjtf.mjs} +4 -3
  500. package/tool_registry-791Vrjtf.mjs.map +1 -0
  501. package/{tool_registry-DYUYqXvo.js → tool_registry-CKJPze3j.js} +4 -3
  502. package/tool_registry-CKJPze3j.js.map +1 -0
  503. package/{turn_runner-DqWHNP80.js → turn_runner-HXImLGIn.js} +7 -7
  504. package/turn_runner-HXImLGIn.js.map +1 -0
  505. package/{turn_runner-fg1Wc3dK.mjs → turn_runner-ZyYO-Kti.mjs} +7 -7
  506. package/turn_runner-ZyYO-Kti.mjs.map +1 -0
  507. package/turn_runner.cjs +1 -1
  508. package/turn_runner.mjs +1 -1
  509. package/types.d.ts +1 -1
  510. package/common-BT0nfCi9.mjs.map +0 -1
  511. package/common-Cj8TaQ9U.js.map +0 -1
  512. package/exceptions-BeWH2FwP.mjs.map +0 -1
  513. package/exceptions-CitH5wZI.js.map +0 -1
  514. package/spooled_markdown_artifact-CALSDxIx.js.map +0 -1
  515. package/spooled_markdown_artifact-Ci5UL7l4.mjs.map +0 -1
  516. package/tool_call-CV5qVNlb.mjs.map +0 -1
  517. package/tool_call-Db68hB7y.js.map +0 -1
  518. package/tool_registry-D1pSSlsd.mjs.map +0 -1
  519. package/tool_registry-DYUYqXvo.js.map +0 -1
  520. package/turn_runner-DqWHNP80.js.map +0 -1
  521. package/turn_runner-fg1Wc3dK.mjs.map +0 -1
@@ -0,0 +1,734 @@
1
+ import { a as Tokenizable, c as isObject, n as canonicalStringify, o as isError, s as isInstanceOf, t as ToolRegistry } from "../../../tool_registry-791Vrjtf.mjs";
2
+ import { n as Message, t as Thought } from "../../../thought-B_vxAiKU.mjs";
3
+ import { i as ArtifactTool, t as SpooledArtifact } from "../../../spooled_artifact-7eePq7JA.mjs";
4
+ import "../../../common-DYDUi99O.mjs";
5
+ import { n as Media, t as ToolCall } from "../../../tool_call-B4-_-vjG.mjs";
6
+ import "../../../guards.mjs";
7
+ import { computeBackoff, linkAbortSignals, parseRetryAfter, sleepWithJitter } from "../../../lib/utils/retry.mjs";
8
+ import { InMemorySpoolStore } from "../../storage/in_memory.mjs";
9
+ import { a as defaultRenderMemories, c as defaultRenderStandingInstructions, d as defaultRenderThought, f as defaultRenderTrustedContent, i as defaultRenderFirstPartyRetrievables, l as defaultRenderThirdPartyPrivateRetrievables, m as defaultToolsToChatCompletionsTools, n as defaultFilterThoughts, o as defaultRenderRetrievableSafetyDirective, p as defaultRenderUntrustedContent, r as defaultRenderChatCompletionsSystemPrompt, s as defaultRenderRetrievables, t as defaultDescriptionToChatCompletionsJsonSchema, u as defaultRenderThirdPartyPublicRetrievables } from "../../../helpers-xhrQbMAG.mjs";
10
+ import { E_INVALID_OLLAMA_OPTIONS, E_OLLAMA_CONTEXT_OVERFLOW, E_OLLAMA_HTTP_ERROR, E_OLLAMA_INVALID_TOOL_CALL_ARGS, E_OLLAMA_REQUEST_TIMEOUT, E_OLLAMA_STREAM_ERROR, E_OLLAMA_STREAM_STALLED } from "./exceptions.mjs";
11
+ import { validateOptions } from "./validation.mjs";
12
+ import { defaultBuildOllamaHistory, defaultRenderOllamaTimelineMessage, defaultRenderOllamaToolCallResult, ollamaToolsFromTools } from "./helpers.mjs";
13
+ import { DateTime } from "luxon";
14
+ import { sha256 } from "js-sha256";
15
+ import { v6 } from "uuid";
16
+ //#region src/batteries/llm/ollama/adapter.ts
17
+ /**
18
+ * Cross-environment executor adapter for the native Ollama `/api/chat` endpoint.
19
+ *
20
+ * @module @nhtio/adk/batteries/llm/ollama/adapter
21
+ *
22
+ * @remarks
23
+ * Native Ollama LLM adapter targeting `/api/chat` (NOT the OpenAI-compat `/v1` layer — the
24
+ * `openai_chat_completions` battery already covers `/v1`). Works against both LOCAL Ollama
25
+ * (`http://localhost:11434`, no auth) and CLOUD Ollama (`https://ollama.com`, `Authorization:
26
+ * Bearer <apiKey>`); the only difference is `baseURL` + the auth header. Native is HTTP-only — a
27
+ * Unix-socket deployment is reached via a custom `fetch` or an external bridge, not an adapter
28
+ * option.
29
+ *
30
+ * Structurally a sibling of the OpenAI Chat Completions adapter, with the native-wire divergences:
31
+ *
32
+ * - Request body: generation params are NESTED under `options`; `think` / `format` / `keep_alive`
33
+ * are top-level native controls; ADK control fields are stripped before sending.
34
+ * - Streaming: NDJSON (newline-delimited JSON objects), terminated in-band by `done: true` — there
35
+ * is no SSE `data:` framing and no `[DONE]` sentinel. Whole `tool_calls` arrive per chunk (no
36
+ * delta accumulation).
37
+ * - Reasoning: the single native `message.thinking` field (no multi-field precedence dance).
38
+ * - Tool calls: `arguments` is already a JSON OBJECT (no `JSON.parse`); native calls carry no `id`,
39
+ * so the adapter synthesizes one (uuidv6) for correlation / checksum / spool keying. Tool-result
40
+ * history messages use `tool_name` (the originating tool), not `tool_call_id`.
41
+ * - Generation stats: the terminal `done: true` object's token counts + nanosecond durations +
42
+ * `done_reason` are surfaced via `helpers.reportGenerationStats`.
43
+ */
44
+ var mergeRecord = (layers) => {
45
+ let merged;
46
+ for (const layer of layers) {
47
+ if (!layer) continue;
48
+ merged = {
49
+ ...merged ?? {},
50
+ ...layer
51
+ };
52
+ }
53
+ return merged;
54
+ };
55
+ var mergeOptions = (baseline, exec, stash) => {
56
+ const layers = [
57
+ baseline,
58
+ exec ?? {},
59
+ stash ?? {}
60
+ ];
61
+ const out = {};
62
+ for (const layer of layers) for (const [k, v] of Object.entries(layer)) {
63
+ if (v === void 0) continue;
64
+ if (k === "headers" || k === "helpers" || k === "retry" || k === "options") continue;
65
+ out[k] = v;
66
+ }
67
+ const headers = mergeRecord(layers.map((l) => l.headers));
68
+ if (headers !== void 0) out.headers = headers;
69
+ const helpers = mergeRecord(layers.map((l) => l.helpers));
70
+ if (helpers !== void 0) out.helpers = helpers;
71
+ const retry = mergeRecord(layers.map((l) => l.retry));
72
+ if (retry !== void 0) out.retry = retry;
73
+ const runtime = mergeRecord(layers.map((l) => l.options));
74
+ if (runtime !== void 0) out.options = runtime;
75
+ return out;
76
+ };
77
+ var resolveHelpers = (overrides) => {
78
+ const src = overrides ?? {};
79
+ return {
80
+ descriptionToChatCompletionsJsonSchema: src.descriptionToChatCompletionsJsonSchema ?? defaultDescriptionToChatCompletionsJsonSchema,
81
+ renderUntrustedContent: src.renderUntrustedContent ?? defaultRenderUntrustedContent,
82
+ renderTrustedContent: src.renderTrustedContent ?? defaultRenderTrustedContent,
83
+ renderStandingInstructions: src.renderStandingInstructions ?? defaultRenderStandingInstructions,
84
+ renderMemories: src.renderMemories ?? defaultRenderMemories,
85
+ renderRetrievables: src.renderRetrievables ?? defaultRenderRetrievables,
86
+ renderRetrievableSafetyDirective: src.renderRetrievableSafetyDirective ?? defaultRenderRetrievableSafetyDirective,
87
+ renderFirstPartyRetrievables: src.renderFirstPartyRetrievables ?? defaultRenderFirstPartyRetrievables,
88
+ renderThirdPartyPublicRetrievables: src.renderThirdPartyPublicRetrievables ?? defaultRenderThirdPartyPublicRetrievables,
89
+ renderThirdPartyPrivateRetrievables: src.renderThirdPartyPrivateRetrievables ?? defaultRenderThirdPartyPrivateRetrievables,
90
+ renderThought: src.renderThought ?? defaultRenderThought,
91
+ filterThoughts: src.filterThoughts ?? defaultFilterThoughts,
92
+ toolsToChatCompletionsTools: src.toolsToChatCompletionsTools ?? defaultToolsToChatCompletionsTools,
93
+ renderChatCompletionsSystemPrompt: src.renderChatCompletionsSystemPrompt ?? defaultRenderChatCompletionsSystemPrompt,
94
+ renderOllamaTimelineMessage: src.renderOllamaTimelineMessage ?? defaultRenderOllamaTimelineMessage,
95
+ renderOllamaToolCallResult: src.renderOllamaToolCallResult ?? defaultRenderOllamaToolCallResult,
96
+ buildOllamaHistory: src.buildOllamaHistory ?? defaultBuildOllamaHistory
97
+ };
98
+ };
99
+ var computeChecksum = (tool, args) => sha256(canonicalStringify({
100
+ tool,
101
+ args
102
+ }));
103
+ var nowIso = () => DateTime.now().toISO() ?? (/* @__PURE__ */ new Date()).toISOString();
104
+ var estimateTokensOf = async (value, encoding) => Promise.resolve(value.estimateTokens(encoding));
105
+ var extractGenerationStats = (src, model) => {
106
+ const stats = {
107
+ provider: "ollama",
108
+ model: src.model ?? model,
109
+ raw: { ...src }
110
+ };
111
+ if (typeof src.prompt_eval_count === "number") stats.promptTokens = src.prompt_eval_count;
112
+ if (typeof src.eval_count === "number") stats.completionTokens = src.eval_count;
113
+ if (typeof src.prompt_eval_count === "number" && typeof src.eval_count === "number") stats.totalTokens = src.prompt_eval_count + src.eval_count;
114
+ if (typeof src.total_duration === "number") stats.totalDurationNs = src.total_duration;
115
+ if (typeof src.load_duration === "number") stats.loadDurationNs = src.load_duration;
116
+ if (typeof src.prompt_eval_duration === "number") stats.promptEvalDurationNs = src.prompt_eval_duration;
117
+ if (typeof src.eval_duration === "number") stats.evalDurationNs = src.eval_duration;
118
+ if (typeof src.done_reason === "string") stats.finishReason = src.done_reason;
119
+ return stats;
120
+ };
121
+ /**
122
+ * Opinionated cross-environment LLM adapter for the native Ollama `/api/chat` wire shape.
123
+ *
124
+ * @remarks
125
+ * Construction validates options eagerly via {@link validateOptions} and throws
126
+ * {@link @nhtio/adk/batteries/llm/ollama!E_INVALID_OLLAMA_OPTIONS} on failure. The returned instance is reusable: call
127
+ * {@link OllamaAdapter.executor} once per `DispatchRunner` configuration to obtain a
128
+ * {@link @nhtio/adk!DispatchExecutorFn} bound to the baseline plus optional executor-scope
129
+ * overrides. Per-iteration overrides live on `ctx.stash.ollama` and take highest precedence;
130
+ * `headers`, `helpers`, `retry`, and the nested runtime `options` merge key-by-key across all three
131
+ * layers, every other field is replaced wholesale at the highest layer that sets it.
132
+ */
133
+ var OllamaAdapter = class OllamaAdapter {
134
+ /** Customary key for per-iteration overrides on `ctx.stash`. */
135
+ static STASH_KEY = "ollama";
136
+ #baseline;
137
+ /**
138
+ * @param options - Constructor-baseline options. Re-validated on every iteration after
139
+ * per-dispatch and per-iteration overrides are layered in.
140
+ * @throws {@link @nhtio/adk/batteries/llm/ollama!E_INVALID_OLLAMA_OPTIONS} when `options` does not satisfy `ollamaOptionsSchema`.
141
+ */
142
+ constructor(options) {
143
+ this.#baseline = validateOptions(options);
144
+ }
145
+ /**
146
+ * Returns a {@link @nhtio/adk!DispatchExecutorFn} bound to this adapter's baseline plus optional
147
+ * executor-scope overrides.
148
+ *
149
+ * @param overrides - Optional executor-scope overrides. Higher precedence than the baseline,
150
+ * lower precedence than `ctx.stash[STASH_KEY]`.
151
+ */
152
+ executor(overrides) {
153
+ const baseline = this.#baseline;
154
+ const adapterClass = OllamaAdapter;
155
+ return async (ctx, helpers) => {
156
+ const localWarn = (msg) => {
157
+ helpers.log.warn({
158
+ kind: "helper-warning",
159
+ message: msg
160
+ });
161
+ };
162
+ const stashRaw = ctx.stash.get(adapterClass.STASH_KEY, {});
163
+ const merged = validateOptions(mergeOptions(baseline, overrides, stashRaw && typeof stashRaw === "object" ? stashRaw : {}));
164
+ if (merged.tokenEncoding !== null && merged.contextWindow === void 0) throw new E_INVALID_OLLAMA_OPTIONS(["tokenEncoding is non-null but contextWindow is undefined"]);
165
+ const resolvedHelpers = resolveHelpers(merged.helpers);
166
+ const uniqueCtors = /* @__PURE__ */ new Set();
167
+ for (const tc of ctx.turnToolCalls) {
168
+ const ctor = tc.results?.constructor;
169
+ if (ctor && SpooledArtifact.isSpooledArtifactConstructor(ctor)) uniqueCtors.add(ctor);
170
+ }
171
+ const forgedRegistries = [];
172
+ for (const ctor of uniqueCtors) {
173
+ const forgeFn = ctor.forgeTools;
174
+ if (typeof forgeFn === "function") forgedRegistries.push(forgeFn.call(ctor, ctx));
175
+ }
176
+ const mergedRegistry = ToolRegistry.merge([ctx.tools, ...forgedRegistries], { onCollision: "replace" });
177
+ mergedRegistry.bindContext(ctx);
178
+ const renderedToolCallResults = /* @__PURE__ */ new Map();
179
+ for (const tc of ctx.turnToolCalls) {
180
+ const rendered = await resolvedHelpers.renderOllamaToolCallResult({
181
+ toolCall: tc,
182
+ results: tc.results,
183
+ tool: mergedRegistry.get(tc.tool),
184
+ renderUntrustedContent: resolvedHelpers.renderUntrustedContent,
185
+ renderTrustedContent: resolvedHelpers.renderTrustedContent,
186
+ unsupportedMediaPolicy: merged.unsupportedMediaPolicy ?? "throw",
187
+ warn: localWarn
188
+ });
189
+ renderedToolCallResults.set(tc.id, rendered);
190
+ }
191
+ if (merged.tokenEncoding !== null && merged.contextWindow !== void 0) {
192
+ const encoding = merged.tokenEncoding;
193
+ let spTokens = await estimateTokensOf(ctx.systemPrompt, encoding);
194
+ let siTokens = 0;
195
+ for (const si of ctx.standingInstructions) siTokens += await estimateTokensOf(si, encoding);
196
+ let memTokens = 0;
197
+ for (const mem of ctx.turnMemories) memTokens += await estimateTokensOf(mem.content, encoding);
198
+ let retTokens = 0;
199
+ for (const r of ctx.turnRetrievables) retTokens += await estimateTokensOf(r.content, encoding);
200
+ let tlTokens = 0;
201
+ for (const msg of ctx.turnMessages) if (msg.content !== void 0) tlTokens += await estimateTokensOf(msg.content, encoding);
202
+ for (const th of ctx.turnThoughts) tlTokens += await estimateTokensOf(th.content, encoding);
203
+ for (const rendered of renderedToolCallResults.values()) tlTokens += await estimateTokensOf(new Tokenizable(rendered), encoding);
204
+ const total = spTokens + siTokens + memTokens + retTokens + tlTokens;
205
+ const perBucketObj = {
206
+ systemPrompt: spTokens,
207
+ standingInstructions: siTokens,
208
+ memories: memTokens,
209
+ retrievables: retTokens,
210
+ timeline: tlTokens
211
+ };
212
+ helpers.log.debug({
213
+ kind: "context-window-usage",
214
+ message: `Context window usage: ${total}/${merged.contextWindow} tokens`,
215
+ payload: {
216
+ total,
217
+ limit: merged.contextWindow,
218
+ encoding,
219
+ perBucket: perBucketObj
220
+ }
221
+ });
222
+ if (total > merged.contextWindow) throw new E_OLLAMA_CONTEXT_OVERFLOW([
223
+ total,
224
+ merged.contextWindow,
225
+ encoding,
226
+ JSON.stringify(perBucketObj)
227
+ ]);
228
+ }
229
+ const { messages: wireMessages, reasoningPayloads } = await resolvedHelpers.buildOllamaHistory({
230
+ systemPrompt: ctx.systemPrompt,
231
+ standingInstructions: ctx.standingInstructions,
232
+ memories: ctx.turnMemories,
233
+ retrievables: ctx.turnRetrievables,
234
+ messages: ctx.turnMessages,
235
+ thoughts: ctx.turnThoughts,
236
+ toolCalls: ctx.turnToolCalls,
237
+ tools: mergedRegistry,
238
+ renderedToolCallResults,
239
+ bucketOrder: merged.bucketOrder ?? [
240
+ "standingInstructions",
241
+ "memories",
242
+ "retrievables",
243
+ "timeline"
244
+ ],
245
+ selfIdentity: merged.selfIdentity ?? "assistant",
246
+ thoughtSurfacing: merged.thoughtSurfacing ?? "all-self",
247
+ replayCompatibility: merged.replayCompatibility ?? [],
248
+ renderOllamaToolCallResult: resolvedHelpers.renderOllamaToolCallResult,
249
+ renderChatCompletionsSystemPrompt: resolvedHelpers.renderChatCompletionsSystemPrompt,
250
+ renderStandingInstructions: resolvedHelpers.renderStandingInstructions,
251
+ renderMemories: resolvedHelpers.renderMemories,
252
+ renderRetrievables: resolvedHelpers.renderRetrievables,
253
+ renderRetrievableSafetyDirective: resolvedHelpers.renderRetrievableSafetyDirective,
254
+ renderFirstPartyRetrievables: resolvedHelpers.renderFirstPartyRetrievables,
255
+ renderThirdPartyPublicRetrievables: resolvedHelpers.renderThirdPartyPublicRetrievables,
256
+ renderThirdPartyPrivateRetrievables: resolvedHelpers.renderThirdPartyPrivateRetrievables,
257
+ renderOllamaTimelineMessage: resolvedHelpers.renderOllamaTimelineMessage,
258
+ renderThought: resolvedHelpers.renderThought,
259
+ filterThoughts: resolvedHelpers.filterThoughts,
260
+ renderUntrustedContent: resolvedHelpers.renderUntrustedContent,
261
+ renderTrustedContent: resolvedHelpers.renderTrustedContent,
262
+ unsupportedMediaPolicy: merged.unsupportedMediaPolicy ?? "throw",
263
+ warn: localWarn
264
+ });
265
+ const stream = merged.stream ?? true;
266
+ const body = {
267
+ model: merged.model,
268
+ messages: wireMessages,
269
+ stream
270
+ };
271
+ if (merged.think !== void 0) body.think = merged.think;
272
+ if (merged.format !== void 0) body.format = merged.format;
273
+ if (merged.keep_alive !== void 0) body.keep_alive = merged.keep_alive;
274
+ if (merged.options !== void 0) body.options = merged.options;
275
+ const toolsArr = mergedRegistry.visible();
276
+ if (toolsArr.length > 0) body.tools = ollamaToolsFromTools(toolsArr, { descriptionToChatCompletionsJsonSchema: resolvedHelpers.descriptionToChatCompletionsJsonSchema });
277
+ if (reasoningPayloads.length > 0) body._adk_reasoning_payloads = reasoningPayloads;
278
+ const rawBase = merged.baseURL ?? "http://localhost:11434";
279
+ const url = `${rawBase.endsWith("/") ? rawBase.slice(0, -1) : rawBase}/api/chat`;
280
+ const headers = { "Content-Type": "application/json" };
281
+ if (stream) headers["Accept"] = "application/x-ndjson";
282
+ if (merged.apiKey) headers["Authorization"] = `Bearer ${merged.apiKey}`;
283
+ if (merged.headers) Object.assign(headers, merged.headers);
284
+ const retryCfg = {
285
+ maxAttempts: merged.retry?.maxAttempts ?? 1,
286
+ baseDelayMs: merged.retry?.baseDelayMs ?? 500,
287
+ maxDelayMs: merged.retry?.maxDelayMs ?? 3e4,
288
+ retriableStatuses: merged.retry?.retriableStatuses ?? [
289
+ 429,
290
+ 502,
291
+ 503,
292
+ 504
293
+ ],
294
+ honorRetryAfter: merged.retry?.honorRetryAfter ?? true
295
+ };
296
+ const fetchFn = merged.fetch ?? globalThis.fetch;
297
+ const maxAttempts = retryCfg.maxAttempts;
298
+ let response;
299
+ let attempt = 1;
300
+ let disposeLink = () => {};
301
+ while (attempt <= maxAttempts) {
302
+ if (ctx.abortSignal.aborted) return;
303
+ const internalController = new AbortController();
304
+ let timeoutHandle;
305
+ const requestTimeoutMs = merged.requestTimeoutMs ?? 0;
306
+ if (requestTimeoutMs > 0) timeoutHandle = setTimeout(() => internalController.abort(), requestTimeoutMs);
307
+ disposeLink();
308
+ const { signal: linkedSignal, dispose: disposeCurrentLink } = linkAbortSignals([ctx.abortSignal, internalController.signal]);
309
+ disposeLink = disposeCurrentLink;
310
+ try {
311
+ response = await fetchFn(url, {
312
+ method: "POST",
313
+ headers,
314
+ body: JSON.stringify(body),
315
+ signal: linkedSignal
316
+ });
317
+ } catch (err) {
318
+ if (timeoutHandle !== void 0) clearTimeout(timeoutHandle);
319
+ if (ctx.abortSignal.aborted) return;
320
+ if (internalController.signal.aborted) {
321
+ helpers.log.warn({
322
+ kind: "request-timeout",
323
+ message: `Request timed out after ${requestTimeoutMs}ms on attempt ${attempt}/${maxAttempts}`,
324
+ payload: {
325
+ requestTimeoutMs,
326
+ attempt,
327
+ maxAttempts
328
+ }
329
+ });
330
+ if (attempt < maxAttempts) {
331
+ await sleepWithJitter(computeBackoff(attempt, retryCfg), ctx.abortSignal);
332
+ attempt += 1;
333
+ continue;
334
+ }
335
+ ctx.nack(new E_OLLAMA_REQUEST_TIMEOUT([requestTimeoutMs]));
336
+ return;
337
+ }
338
+ helpers.log.error({
339
+ kind: "transport-error",
340
+ message: `Transport failure on attempt ${attempt}/${maxAttempts}: ${isError(err) ? err.message : String(err)}`,
341
+ payload: {
342
+ attempt,
343
+ maxAttempts,
344
+ detail: isError(err) ? err.message : String(err)
345
+ }
346
+ });
347
+ ctx.nack(new E_OLLAMA_HTTP_ERROR([0, isError(err) ? err.message : String(err)]));
348
+ return;
349
+ }
350
+ if (timeoutHandle !== void 0) clearTimeout(timeoutHandle);
351
+ if (!response.ok) {
352
+ const status = response.status;
353
+ const retriable = retryCfg.retriableStatuses.includes(status);
354
+ if (retriable && attempt < maxAttempts) {
355
+ let delay = computeBackoff(attempt, retryCfg);
356
+ if (retryCfg.honorRetryAfter !== false) {
357
+ const ra = response.headers.get("Retry-After");
358
+ if (ra) {
359
+ const raMs = parseRetryAfter(ra);
360
+ if (raMs > 0) delay = Math.min(Math.max(delay, raMs), retryCfg.maxDelayMs);
361
+ }
362
+ }
363
+ helpers.log.warn({
364
+ kind: "retry-attempt",
365
+ message: `HTTP ${status} on attempt ${attempt}/${maxAttempts}; retrying in ~${delay}ms`,
366
+ payload: {
367
+ reason: "http-status",
368
+ status,
369
+ delayMs: delay,
370
+ attempt: attempt + 1,
371
+ maxAttempts
372
+ }
373
+ });
374
+ await sleepWithJitter(delay, ctx.abortSignal);
375
+ attempt += 1;
376
+ continue;
377
+ }
378
+ const errBody = await response.text().catch(() => "");
379
+ helpers.log.error({
380
+ kind: "http-error",
381
+ message: `HTTP ${status} (terminal): ${errBody.slice(0, 256)}`,
382
+ payload: {
383
+ status,
384
+ body: errBody,
385
+ attempt,
386
+ maxAttempts,
387
+ retriable
388
+ }
389
+ });
390
+ ctx.nack(new E_OLLAMA_HTTP_ERROR([status, errBody]));
391
+ return;
392
+ }
393
+ break;
394
+ }
395
+ if (!response) return;
396
+ const spoolStore = merged.spoolStore ?? new InMemorySpoolStore();
397
+ const selfIdentity = merged.selfIdentity ?? "assistant";
398
+ const executeAndPersistToolCall = async (call) => {
399
+ const tool = mergedRegistry.get(call.name);
400
+ let args = {};
401
+ let parseError;
402
+ if (isObject(call.args)) args = call.args;
403
+ else parseError = new E_OLLAMA_INVALID_TOOL_CALL_ARGS([`must be a JSON object; received ${Array.isArray(call.args) ? "array" : call.args === null ? "null" : typeof call.args}`, JSON.stringify(call.args)]);
404
+ const completedAt = nowIso();
405
+ if (parseError !== void 0) {
406
+ const results = new Tokenizable(parseError.message);
407
+ helpers.reportToolCall(call.id, {
408
+ tool: call.name,
409
+ args
410
+ });
411
+ helpers.reportToolCall(call.id, {
412
+ results,
413
+ isError: true,
414
+ isComplete: true
415
+ });
416
+ await ctx.storeToolCall(new ToolCall({
417
+ id: call.id,
418
+ tool: call.name,
419
+ args,
420
+ checksum: computeChecksum(call.name, args),
421
+ isComplete: true,
422
+ isError: true,
423
+ results,
424
+ createdAt: completedAt,
425
+ updatedAt: completedAt,
426
+ completedAt
427
+ }));
428
+ return;
429
+ }
430
+ if (!tool) {
431
+ const available = mergedRegistry.all().map((t) => t.name).sort();
432
+ const results = new Tokenizable(available.length > 0 ? `Tool not found: ${call.name}. Available tools: ${available.join(", ")}.` : `Tool not found: ${call.name}. No tools are available this turn.`);
433
+ helpers.reportToolCall(call.id, {
434
+ tool: call.name,
435
+ args
436
+ });
437
+ helpers.reportToolCall(call.id, {
438
+ results,
439
+ isError: true,
440
+ isComplete: true
441
+ });
442
+ await ctx.storeToolCall(new ToolCall({
443
+ id: call.id,
444
+ tool: call.name,
445
+ args,
446
+ checksum: computeChecksum(call.name, args),
447
+ isComplete: true,
448
+ isError: true,
449
+ results,
450
+ createdAt: completedAt,
451
+ updatedAt: completedAt,
452
+ completedAt
453
+ }));
454
+ return;
455
+ }
456
+ helpers.reportToolCall(call.id, {
457
+ tool: tool.name,
458
+ args
459
+ });
460
+ const isArtifactTool = ArtifactTool.isArtifactTool(tool);
461
+ let results = new Tokenizable("");
462
+ let toolHadError = false;
463
+ try {
464
+ const raw = await tool.executor(ctx)(args);
465
+ if (isArtifactTool) if (Tokenizable.isTokenizable(raw)) results = raw;
466
+ else if (typeof raw === "string") results = new Tokenizable(raw);
467
+ else throw new Error(`ArtifactTool "${tool.name}" returned a non-string/non-Tokenizable value`);
468
+ else if (Media.isMedia(raw)) results = raw;
469
+ else if (Array.isArray(raw) && raw.length > 0 && raw.every((m) => Media.isMedia(m))) results = raw;
470
+ else if (typeof raw === "string" || isInstanceOf(raw, "Uint8Array", Uint8Array)) {
471
+ const reader = await spoolStore.write(call.id, raw);
472
+ results = new ((tool.artifactConstructor?.()) ?? SpooledArtifact)(reader);
473
+ } else {
474
+ const reader = await spoolStore.write(call.id, String(raw));
475
+ results = new ((tool.artifactConstructor?.()) ?? SpooledArtifact)(reader);
476
+ }
477
+ } catch (err) {
478
+ toolHadError = true;
479
+ let detailMsg = isError(err) ? err.message : String(err);
480
+ if (isError(err) && isError(err.cause) && err.cause.message && err.cause.message !== err.message) detailMsg = `${detailMsg} ${err.cause.message}`;
481
+ results = new Tokenizable(detailMsg);
482
+ }
483
+ helpers.reportToolCall(call.id, {
484
+ results,
485
+ isError: toolHadError,
486
+ isComplete: true
487
+ });
488
+ const completedAt2 = nowIso();
489
+ await ctx.storeToolCall(new ToolCall({
490
+ id: call.id,
491
+ tool: tool.name,
492
+ args,
493
+ checksum: computeChecksum(tool.name, args),
494
+ isComplete: true,
495
+ isError: toolHadError,
496
+ results,
497
+ fromArtifactTool: isArtifactTool,
498
+ createdAt: completedAt2,
499
+ updatedAt: completedAt2,
500
+ completedAt: completedAt2
501
+ }));
502
+ };
503
+ if (stream) {
504
+ if (!response.body) {
505
+ ctx.nack(new E_OLLAMA_STREAM_ERROR(["response has no body"]));
506
+ return;
507
+ }
508
+ const reader = response.body.getReader();
509
+ const decoder = new TextDecoder();
510
+ const streamId = v6();
511
+ let buffer = "";
512
+ let idleTimer;
513
+ let stalled = false;
514
+ let partialMessageContent = "";
515
+ let sawMessageDelta = false;
516
+ let partialThinking = "";
517
+ let sawThinking = false;
518
+ let doneSeen = false;
519
+ const collectedToolCalls = [];
520
+ const thoughtStreamId = `${streamId}:thought`;
521
+ const idleMs = merged.streamIdleTimeoutMs ?? 0;
522
+ const armIdleTimer = () => {
523
+ if (idleMs <= 0) return;
524
+ if (idleTimer) clearTimeout(idleTimer);
525
+ idleTimer = setTimeout(() => {
526
+ stalled = true;
527
+ helpers.log.warn({
528
+ kind: "stream-idle-timeout",
529
+ message: `NDJSON stream went idle for ${idleMs}ms; cancelling`,
530
+ payload: { idleMs }
531
+ });
532
+ reader.cancel().catch(() => {});
533
+ }, idleMs);
534
+ };
535
+ const clearIdleTimer = () => {
536
+ if (idleTimer) {
537
+ clearTimeout(idleTimer);
538
+ idleTimer = void 0;
539
+ }
540
+ };
541
+ const drainAndPersist = async (statsSrc) => {
542
+ if (sawMessageDelta) {
543
+ helpers.reportMessage(streamId, "", { isComplete: true });
544
+ await ctx.storeMessage(new Message({
545
+ id: streamId,
546
+ role: "assistant",
547
+ content: partialMessageContent,
548
+ identity: selfIdentity,
549
+ createdAt: nowIso(),
550
+ updatedAt: nowIso()
551
+ }));
552
+ }
553
+ if (sawThinking) {
554
+ helpers.reportThought(thoughtStreamId, "", { isComplete: true });
555
+ await ctx.storeThought(new Thought({
556
+ id: thoughtStreamId,
557
+ content: partialThinking,
558
+ identity: selfIdentity,
559
+ createdAt: nowIso(),
560
+ updatedAt: nowIso()
561
+ }));
562
+ }
563
+ if (statsSrc !== void 0) helpers.reportGenerationStats(extractGenerationStats(statsSrc, merged.model));
564
+ if (collectedToolCalls.length === 0) {
565
+ if (merged.autoAck) ctx.ack();
566
+ return;
567
+ }
568
+ for (const call of collectedToolCalls) {
569
+ if (ctx.abortSignal.aborted) return;
570
+ await executeAndPersistToolCall(call);
571
+ }
572
+ };
573
+ const handleChunk = (chunk) => {
574
+ const m = chunk.message;
575
+ if (m) {
576
+ if (typeof m.content === "string" && m.content.length > 0) {
577
+ sawMessageDelta = true;
578
+ partialMessageContent += m.content;
579
+ helpers.reportMessage(streamId, m.content);
580
+ }
581
+ if (typeof m.thinking === "string" && m.thinking.length > 0) {
582
+ sawThinking = true;
583
+ partialThinking += m.thinking;
584
+ helpers.reportThought(thoughtStreamId, m.thinking);
585
+ }
586
+ if (Array.isArray(m.tool_calls)) for (const tc of m.tool_calls) collectedToolCalls.push({
587
+ id: v6(),
588
+ name: tc.function?.name ?? "",
589
+ args: tc.function?.arguments ?? {}
590
+ });
591
+ }
592
+ };
593
+ const parseLine = (line) => {
594
+ const trimmed = line.trim();
595
+ if (trimmed.length === 0) return void 0;
596
+ try {
597
+ return JSON.parse(trimmed);
598
+ } catch {
599
+ helpers.log.trace({
600
+ kind: "ndjson-parse-failure",
601
+ message: "Failed to parse NDJSON line as JSON; skipping",
602
+ payload: { linePreview: trimmed.slice(0, 256) }
603
+ });
604
+ return;
605
+ }
606
+ };
607
+ try {
608
+ armIdleTimer();
609
+ while (true) {
610
+ const { done, value } = await reader.read();
611
+ if (done) break;
612
+ armIdleTimer();
613
+ if (ctx.abortSignal.aborted) {
614
+ clearIdleTimer();
615
+ return;
616
+ }
617
+ buffer += decoder.decode(value, { stream: true });
618
+ let nl = buffer.indexOf("\n");
619
+ while (nl !== -1) {
620
+ const line = buffer.slice(0, nl);
621
+ buffer = buffer.slice(nl + 1);
622
+ const chunk = parseLine(line);
623
+ if (chunk !== void 0) {
624
+ handleChunk(chunk);
625
+ if (chunk.done === true) {
626
+ doneSeen = true;
627
+ clearIdleTimer();
628
+ await drainAndPersist(chunk);
629
+ return;
630
+ }
631
+ }
632
+ nl = buffer.indexOf("\n");
633
+ }
634
+ }
635
+ clearIdleTimer();
636
+ if (stalled) {
637
+ ctx.nack(new E_OLLAMA_STREAM_STALLED([idleMs]));
638
+ return;
639
+ }
640
+ if (!doneSeen && buffer.trim().length > 0) {
641
+ const chunk = parseLine(buffer);
642
+ buffer = "";
643
+ if (chunk !== void 0) {
644
+ handleChunk(chunk);
645
+ if (chunk.done === true) {
646
+ await drainAndPersist(chunk);
647
+ return;
648
+ }
649
+ }
650
+ }
651
+ if (!doneSeen) {
652
+ helpers.log.warn({
653
+ kind: "ndjson-eof-without-done",
654
+ message: "NDJSON stream ended without a done:true chunk; draining accumulated state"
655
+ });
656
+ await drainAndPersist(void 0);
657
+ }
658
+ } catch (err) {
659
+ clearIdleTimer();
660
+ if (ctx.abortSignal.aborted) return;
661
+ if (stalled) {
662
+ ctx.nack(new E_OLLAMA_STREAM_STALLED([idleMs]));
663
+ return;
664
+ }
665
+ helpers.log.error({
666
+ kind: "stream-error",
667
+ message: `NDJSON stream failed: ${isError(err) ? err.message : String(err)}`,
668
+ payload: { detail: isError(err) ? err.message : String(err) }
669
+ });
670
+ ctx.nack(new E_OLLAMA_STREAM_ERROR([isError(err) ? err.message : String(err)]));
671
+ return;
672
+ }
673
+ return;
674
+ }
675
+ let parsed;
676
+ try {
677
+ parsed = await response.json();
678
+ } catch (err) {
679
+ ctx.nack(new E_OLLAMA_STREAM_ERROR([isError(err) ? err.message : String(err)]));
680
+ return;
681
+ }
682
+ const responseId = v6();
683
+ const msg = parsed.message;
684
+ if (msg && typeof msg.content === "string" && msg.content.length > 0) {
685
+ const messageId = `${responseId}:message`;
686
+ helpers.reportMessage(messageId, msg.content, { isComplete: true });
687
+ await ctx.storeMessage(new Message({
688
+ id: messageId,
689
+ role: "assistant",
690
+ content: msg.content,
691
+ identity: selfIdentity,
692
+ createdAt: nowIso(),
693
+ updatedAt: nowIso()
694
+ }));
695
+ }
696
+ if (msg && typeof msg.thinking === "string" && msg.thinking.length > 0) {
697
+ const thoughtId = `${responseId}:thought`;
698
+ helpers.reportThought(thoughtId, msg.thinking, { isComplete: true });
699
+ await ctx.storeThought(new Thought({
700
+ id: thoughtId,
701
+ content: msg.thinking,
702
+ identity: selfIdentity,
703
+ createdAt: nowIso(),
704
+ updatedAt: nowIso()
705
+ }));
706
+ }
707
+ helpers.reportGenerationStats(extractGenerationStats(parsed, merged.model));
708
+ const rawCalls = msg?.tool_calls ?? [];
709
+ if (rawCalls.length === 0) {
710
+ if (merged.autoAck) ctx.ack();
711
+ return;
712
+ }
713
+ const calls = rawCalls.map((tc) => ({
714
+ id: v6(),
715
+ name: tc.function?.name ?? "",
716
+ args: tc.function?.arguments ?? {}
717
+ }));
718
+ for (const call of calls) {
719
+ if (ctx.abortSignal.aborted) return;
720
+ await executeAndPersistToolCall(call);
721
+ }
722
+ };
723
+ }
724
+ /**
725
+ * Returns `true` when `value` is an {@link OllamaAdapter} instance.
726
+ */
727
+ static isOllamaAdapter(value) {
728
+ return isInstanceOf(value, "OllamaAdapter", OllamaAdapter);
729
+ }
730
+ };
731
+ //#endregion
732
+ export { OllamaAdapter };
733
+
734
+ //# sourceMappingURL=adapter.mjs.map