@nhtio/adk 1.20260607.2 → 1.20260609.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 (501) hide show
  1. package/CHANGELOG.md +185 -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/color.cjs +3 -2
  90. package/batteries/tools/color.cjs.map +1 -1
  91. package/batteries/tools/color.mjs +3 -2
  92. package/batteries/tools/color.mjs.map +1 -1
  93. package/batteries/tools/comparison.cjs +4 -3
  94. package/batteries/tools/comparison.cjs.map +1 -1
  95. package/batteries/tools/comparison.mjs +4 -3
  96. package/batteries/tools/comparison.mjs.map +1 -1
  97. package/batteries/tools/data_structure.cjs +30 -10
  98. package/batteries/tools/data_structure.cjs.map +1 -1
  99. package/batteries/tools/data_structure.mjs +30 -10
  100. package/batteries/tools/data_structure.mjs.map +1 -1
  101. package/batteries/tools/datetime_extended.cjs +5 -10
  102. package/batteries/tools/datetime_extended.cjs.map +1 -1
  103. package/batteries/tools/datetime_extended.mjs +5 -10
  104. package/batteries/tools/datetime_extended.mjs.map +1 -1
  105. package/batteries/tools/datetime_math.cjs +2 -2
  106. package/batteries/tools/datetime_math.mjs +2 -2
  107. package/batteries/tools/encoding.cjs +13 -4
  108. package/batteries/tools/encoding.cjs.map +1 -1
  109. package/batteries/tools/encoding.mjs +13 -4
  110. package/batteries/tools/encoding.mjs.map +1 -1
  111. package/batteries/tools/formatting.cjs +4 -4
  112. package/batteries/tools/formatting.cjs.map +1 -1
  113. package/batteries/tools/formatting.mjs +4 -4
  114. package/batteries/tools/formatting.mjs.map +1 -1
  115. package/batteries/tools/geo_basics.cjs +2 -2
  116. package/batteries/tools/geo_basics.mjs +2 -2
  117. package/batteries/tools/index.d.ts +1 -0
  118. package/batteries/tools/math.cjs +10 -8
  119. package/batteries/tools/math.cjs.map +1 -1
  120. package/batteries/tools/math.mjs +10 -8
  121. package/batteries/tools/math.mjs.map +1 -1
  122. package/batteries/tools/memory.cjs +5 -5
  123. package/batteries/tools/memory.mjs +5 -5
  124. package/batteries/tools/parsing.cjs +9 -5
  125. package/batteries/tools/parsing.cjs.map +1 -1
  126. package/batteries/tools/parsing.mjs +9 -5
  127. package/batteries/tools/parsing.mjs.map +1 -1
  128. package/batteries/tools/retrievables.cjs +4 -4
  129. package/batteries/tools/retrievables.mjs +4 -4
  130. package/batteries/tools/searxng/exceptions.d.ts +21 -0
  131. package/batteries/tools/searxng/index.d.ts +150 -0
  132. package/batteries/tools/searxng.cjs +5 -0
  133. package/batteries/tools/searxng.mjs +2 -0
  134. package/batteries/tools/standing_instructions.cjs +4 -4
  135. package/batteries/tools/standing_instructions.mjs +4 -4
  136. package/batteries/tools/statistics.cjs +54 -43
  137. package/batteries/tools/statistics.cjs.map +1 -1
  138. package/batteries/tools/statistics.mjs +54 -43
  139. package/batteries/tools/statistics.mjs.map +1 -1
  140. package/batteries/tools/string_processing.cjs +5 -5
  141. package/batteries/tools/string_processing.cjs.map +1 -1
  142. package/batteries/tools/string_processing.mjs +5 -5
  143. package/batteries/tools/string_processing.mjs.map +1 -1
  144. package/batteries/tools/structured_data.cjs +8 -13
  145. package/batteries/tools/structured_data.cjs.map +1 -1
  146. package/batteries/tools/structured_data.mjs +8 -13
  147. package/batteries/tools/structured_data.mjs.map +1 -1
  148. package/batteries/tools/text_analysis.cjs +3 -3
  149. package/batteries/tools/text_analysis.mjs +3 -3
  150. package/batteries/tools/text_comparison.cjs +2 -2
  151. package/batteries/tools/text_comparison.mjs +2 -2
  152. package/batteries/tools/time.cjs +2 -2
  153. package/batteries/tools/time.mjs +2 -2
  154. package/batteries/tools/unit_conversion.cjs +10 -8
  155. package/batteries/tools/unit_conversion.cjs.map +1 -1
  156. package/batteries/tools/unit_conversion.mjs +10 -8
  157. package/batteries/tools/unit_conversion.mjs.map +1 -1
  158. package/batteries/tools.cjs +3 -0
  159. package/batteries/tools.mjs +2 -1
  160. package/batteries/vector/arangodb/index.d.ts +2 -0
  161. package/batteries/vector/arangodb.cjs +2 -1
  162. package/batteries/vector/arangodb.cjs.map +1 -1
  163. package/batteries/vector/arangodb.mjs +2 -1
  164. package/batteries/vector/arangodb.mjs.map +1 -1
  165. package/batteries/vector/builder.cjs +31 -0
  166. package/batteries/vector/builder.cjs.map +1 -1
  167. package/batteries/vector/builder.d.ts +58 -0
  168. package/batteries/vector/builder.mjs +31 -0
  169. package/batteries/vector/builder.mjs.map +1 -1
  170. package/batteries/vector/chroma/index.d.ts +4 -0
  171. package/batteries/vector/chroma.cjs +3 -0
  172. package/batteries/vector/chroma.cjs.map +1 -1
  173. package/batteries/vector/chroma.mjs +3 -0
  174. package/batteries/vector/chroma.mjs.map +1 -1
  175. package/batteries/vector/clickhouse/index.d.ts +2 -0
  176. package/batteries/vector/clickhouse.cjs +2 -1
  177. package/batteries/vector/clickhouse.cjs.map +1 -1
  178. package/batteries/vector/clickhouse.mjs +2 -1
  179. package/batteries/vector/clickhouse.mjs.map +1 -1
  180. package/batteries/vector/cloudflare/index.d.ts +2 -0
  181. package/batteries/vector/cloudflare.cjs +2 -1
  182. package/batteries/vector/cloudflare.cjs.map +1 -1
  183. package/batteries/vector/cloudflare.mjs +2 -1
  184. package/batteries/vector/cloudflare.mjs.map +1 -1
  185. package/batteries/vector/conformance/index.d.ts +22 -0
  186. package/batteries/vector/conformance.cjs +22 -0
  187. package/batteries/vector/conformance.cjs.map +1 -1
  188. package/batteries/vector/conformance.mjs +22 -0
  189. package/batteries/vector/conformance.mjs.map +1 -1
  190. package/batteries/vector/contract.cjs +22 -0
  191. package/batteries/vector/contract.cjs.map +1 -1
  192. package/batteries/vector/contract.d.ts +51 -0
  193. package/batteries/vector/contract.mjs +22 -0
  194. package/batteries/vector/contract.mjs.map +1 -1
  195. package/batteries/vector/couchbase/index.d.ts +2 -0
  196. package/batteries/vector/couchbase.cjs +2 -1
  197. package/batteries/vector/couchbase.cjs.map +1 -1
  198. package/batteries/vector/couchbase.mjs +2 -1
  199. package/batteries/vector/couchbase.mjs.map +1 -1
  200. package/batteries/vector/duckdb/index.d.ts +2 -0
  201. package/batteries/vector/duckdb.cjs +2 -1
  202. package/batteries/vector/duckdb.cjs.map +1 -1
  203. package/batteries/vector/duckdb.mjs +2 -1
  204. package/batteries/vector/duckdb.mjs.map +1 -1
  205. package/batteries/vector/elasticsearch/index.d.ts +2 -0
  206. package/batteries/vector/elasticsearch.cjs +2 -1
  207. package/batteries/vector/elasticsearch.cjs.map +1 -1
  208. package/batteries/vector/elasticsearch.mjs +2 -1
  209. package/batteries/vector/elasticsearch.mjs.map +1 -1
  210. package/batteries/vector/exceptions.cjs +1 -1
  211. package/batteries/vector/exceptions.mjs +1 -1
  212. package/batteries/vector/factory.cjs +6 -0
  213. package/batteries/vector/factory.cjs.map +1 -1
  214. package/batteries/vector/factory.d.ts +14 -0
  215. package/batteries/vector/factory.mjs +6 -0
  216. package/batteries/vector/factory.mjs.map +1 -1
  217. package/batteries/vector/filters.cjs +22 -1
  218. package/batteries/vector/filters.cjs.map +1 -1
  219. package/batteries/vector/filters.d.ts +38 -0
  220. package/batteries/vector/filters.mjs +22 -1
  221. package/batteries/vector/filters.mjs.map +1 -1
  222. package/batteries/vector/helpers.cjs +13 -0
  223. package/batteries/vector/helpers.cjs.map +1 -1
  224. package/batteries/vector/helpers.d.ts +14 -0
  225. package/batteries/vector/helpers.mjs +13 -0
  226. package/batteries/vector/helpers.mjs.map +1 -1
  227. package/batteries/vector/hnswlib/index.d.ts +2 -0
  228. package/batteries/vector/hnswlib.cjs +2 -1
  229. package/batteries/vector/hnswlib.cjs.map +1 -1
  230. package/batteries/vector/hnswlib.mjs +2 -1
  231. package/batteries/vector/hnswlib.mjs.map +1 -1
  232. package/batteries/vector/in_memory/index.d.ts +1 -0
  233. package/batteries/vector/in_memory.cjs +1 -0
  234. package/batteries/vector/in_memory.cjs.map +1 -1
  235. package/batteries/vector/in_memory.mjs +1 -0
  236. package/batteries/vector/in_memory.mjs.map +1 -1
  237. package/batteries/vector/lancedb/index.d.ts +2 -0
  238. package/batteries/vector/lancedb.cjs +2 -1
  239. package/batteries/vector/lancedb.cjs.map +1 -1
  240. package/batteries/vector/lancedb.mjs +2 -1
  241. package/batteries/vector/lancedb.mjs.map +1 -1
  242. package/batteries/vector/mariadb/index.d.ts +2 -0
  243. package/batteries/vector/mariadb.cjs +2 -1
  244. package/batteries/vector/mariadb.cjs.map +1 -1
  245. package/batteries/vector/mariadb.mjs +2 -1
  246. package/batteries/vector/mariadb.mjs.map +1 -1
  247. package/batteries/vector/meilisearch/index.d.ts +2 -0
  248. package/batteries/vector/meilisearch.cjs +2 -1
  249. package/batteries/vector/meilisearch.cjs.map +1 -1
  250. package/batteries/vector/meilisearch.mjs +2 -1
  251. package/batteries/vector/meilisearch.mjs.map +1 -1
  252. package/batteries/vector/migrate.cjs +18 -1
  253. package/batteries/vector/migrate.cjs.map +1 -1
  254. package/batteries/vector/migrate.d.ts +31 -0
  255. package/batteries/vector/migrate.mjs +18 -1
  256. package/batteries/vector/migrate.mjs.map +1 -1
  257. package/batteries/vector/milvus/index.d.ts +5 -0
  258. package/batteries/vector/milvus.cjs +4 -0
  259. package/batteries/vector/milvus.cjs.map +1 -1
  260. package/batteries/vector/milvus.mjs +4 -0
  261. package/batteries/vector/milvus.mjs.map +1 -1
  262. package/batteries/vector/mongodb/index.d.ts +2 -0
  263. package/batteries/vector/mongodb.cjs +2 -1
  264. package/batteries/vector/mongodb.cjs.map +1 -1
  265. package/batteries/vector/mongodb.mjs +2 -1
  266. package/batteries/vector/mongodb.mjs.map +1 -1
  267. package/batteries/vector/neo4j/index.d.ts +2 -0
  268. package/batteries/vector/neo4j.cjs +2 -1
  269. package/batteries/vector/neo4j.cjs.map +1 -1
  270. package/batteries/vector/neo4j.mjs +2 -1
  271. package/batteries/vector/neo4j.mjs.map +1 -1
  272. package/batteries/vector/opensearch/index.d.ts +2 -0
  273. package/batteries/vector/opensearch.cjs +2 -1
  274. package/batteries/vector/opensearch.cjs.map +1 -1
  275. package/batteries/vector/opensearch.mjs +2 -1
  276. package/batteries/vector/opensearch.mjs.map +1 -1
  277. package/batteries/vector/oracle23ai/index.d.ts +2 -0
  278. package/batteries/vector/oracle23ai.cjs +2 -1
  279. package/batteries/vector/oracle23ai.cjs.map +1 -1
  280. package/batteries/vector/oracle23ai.mjs +2 -1
  281. package/batteries/vector/oracle23ai.mjs.map +1 -1
  282. package/batteries/vector/orama/index.d.ts +1 -0
  283. package/batteries/vector/orama.cjs +1 -0
  284. package/batteries/vector/orama.cjs.map +1 -1
  285. package/batteries/vector/orama.mjs +1 -0
  286. package/batteries/vector/orama.mjs.map +1 -1
  287. package/batteries/vector/pgvector/index.d.ts +9 -2
  288. package/batteries/vector/pgvector.cjs +4 -0
  289. package/batteries/vector/pgvector.cjs.map +1 -1
  290. package/batteries/vector/pgvector.mjs +4 -0
  291. package/batteries/vector/pgvector.mjs.map +1 -1
  292. package/batteries/vector/pinecone/index.d.ts +5 -0
  293. package/batteries/vector/pinecone.cjs +3 -1
  294. package/batteries/vector/pinecone.cjs.map +1 -1
  295. package/batteries/vector/pinecone.mjs +3 -1
  296. package/batteries/vector/pinecone.mjs.map +1 -1
  297. package/batteries/vector/plan.d.ts +27 -0
  298. package/batteries/vector/qdrant/index.d.ts +5 -0
  299. package/batteries/vector/qdrant.cjs +4 -0
  300. package/batteries/vector/qdrant.cjs.map +1 -1
  301. package/batteries/vector/qdrant.mjs +4 -0
  302. package/batteries/vector/qdrant.mjs.map +1 -1
  303. package/batteries/vector/redis/index.d.ts +2 -0
  304. package/batteries/vector/redis.cjs +2 -1
  305. package/batteries/vector/redis.cjs.map +1 -1
  306. package/batteries/vector/redis.mjs +2 -1
  307. package/batteries/vector/redis.mjs.map +1 -1
  308. package/batteries/vector/retrievable.cjs +9 -1
  309. package/batteries/vector/retrievable.cjs.map +1 -1
  310. package/batteries/vector/retrievable.mjs +9 -1
  311. package/batteries/vector/retrievable.mjs.map +1 -1
  312. package/batteries/vector/retrievable_glue.d.ts +21 -0
  313. package/batteries/vector/s3vectors/index.d.ts +2 -0
  314. package/batteries/vector/s3vectors.cjs +2 -1
  315. package/batteries/vector/s3vectors.cjs.map +1 -1
  316. package/batteries/vector/s3vectors.mjs +2 -1
  317. package/batteries/vector/s3vectors.mjs.map +1 -1
  318. package/batteries/vector/schema.cjs +28 -0
  319. package/batteries/vector/schema.cjs.map +1 -1
  320. package/batteries/vector/schema.d.ts +39 -0
  321. package/batteries/vector/schema.mjs +28 -0
  322. package/batteries/vector/schema.mjs.map +1 -1
  323. package/batteries/vector/solr/index.d.ts +2 -0
  324. package/batteries/vector/solr.cjs +2 -1
  325. package/batteries/vector/solr.cjs.map +1 -1
  326. package/batteries/vector/solr.mjs +2 -1
  327. package/batteries/vector/solr.mjs.map +1 -1
  328. package/batteries/vector/sqlite_vec/index.d.ts +6 -3
  329. package/batteries/vector/sqlite_vec.cjs +2 -0
  330. package/batteries/vector/sqlite_vec.cjs.map +1 -1
  331. package/batteries/vector/sqlite_vec.mjs +2 -0
  332. package/batteries/vector/sqlite_vec.mjs.map +1 -1
  333. package/batteries/vector/surrealdb/index.d.ts +2 -0
  334. package/batteries/vector/surrealdb.cjs +2 -1
  335. package/batteries/vector/surrealdb.cjs.map +1 -1
  336. package/batteries/vector/surrealdb.mjs +2 -1
  337. package/batteries/vector/surrealdb.mjs.map +1 -1
  338. package/batteries/vector/types.d.ts +27 -0
  339. package/batteries/vector/typesense/index.d.ts +2 -0
  340. package/batteries/vector/typesense.cjs +2 -1
  341. package/batteries/vector/typesense.cjs.map +1 -1
  342. package/batteries/vector/typesense.mjs +2 -1
  343. package/batteries/vector/typesense.mjs.map +1 -1
  344. package/batteries/vector/validation.cjs +14 -0
  345. package/batteries/vector/validation.cjs.map +1 -1
  346. package/batteries/vector/validation.d.ts +14 -0
  347. package/batteries/vector/validation.mjs +14 -0
  348. package/batteries/vector/validation.mjs.map +1 -1
  349. package/batteries/vector/vector_store_constructor.cjs +1 -1
  350. package/batteries/vector/vector_store_constructor.cjs.map +1 -1
  351. package/batteries/vector/vector_store_constructor.d.ts +1 -1
  352. package/batteries/vector/vector_store_constructor.mjs +1 -1
  353. package/batteries/vector/vector_store_constructor.mjs.map +1 -1
  354. package/batteries/vector/vespa/index.d.ts +2 -0
  355. package/batteries/vector/vespa.cjs +2 -1
  356. package/batteries/vector/vespa.cjs.map +1 -1
  357. package/batteries/vector/vespa.mjs +2 -1
  358. package/batteries/vector/vespa.mjs.map +1 -1
  359. package/batteries/vector/weaviate/index.d.ts +2 -0
  360. package/batteries/vector/weaviate.cjs +2 -1
  361. package/batteries/vector/weaviate.cjs.map +1 -1
  362. package/batteries/vector/weaviate.mjs +2 -1
  363. package/batteries/vector/weaviate.mjs.map +1 -1
  364. package/batteries.cjs +46 -28
  365. package/batteries.mjs +10 -5
  366. package/{common-BT0nfCi9.mjs → common-DYDUi99O.mjs} +9 -9
  367. package/common-DYDUi99O.mjs.map +1 -0
  368. package/{common-Cj8TaQ9U.js → common-DZl3ADJs.js} +9 -9
  369. package/common-DZl3ADJs.js.map +1 -0
  370. package/common.cjs +7 -7
  371. package/common.d.ts +1 -1
  372. package/common.mjs +7 -7
  373. package/{dispatch_runner-DPcS7Y_M.mjs → dispatch_runner--ZhdDWRZ.mjs} +27 -5
  374. package/{dispatch_runner-DPcS7Y_M.mjs.map → dispatch_runner--ZhdDWRZ.mjs.map} +1 -1
  375. package/{dispatch_runner-BHBNupqp.js → dispatch_runner-nHDKkxye.js} +27 -5
  376. package/{dispatch_runner-BHBNupqp.js.map → dispatch_runner-nHDKkxye.js.map} +1 -1
  377. package/dispatch_runner.cjs +1 -1
  378. package/dispatch_runner.d.ts +1 -1
  379. package/dispatch_runner.mjs +1 -1
  380. package/eslint/rules/artifact_tool_forbids_artifact_constructor.cjs +1 -0
  381. package/eslint/rules/artifact_tool_forbids_artifact_constructor.cjs.map +1 -1
  382. package/eslint/rules/artifact_tool_forbids_artifact_constructor.d.ts +1 -0
  383. package/eslint/rules/artifact_tool_forbids_artifact_constructor.mjs +1 -0
  384. package/eslint/rules/artifact_tool_forbids_artifact_constructor.mjs.map +1 -1
  385. package/eslint/rules/no_model_in_tool_handler.cjs +1 -0
  386. package/eslint/rules/no_model_in_tool_handler.cjs.map +1 -1
  387. package/eslint/rules/no_model_in_tool_handler.d.ts +1 -0
  388. package/eslint/rules/no_model_in_tool_handler.mjs +1 -0
  389. package/eslint/rules/no_model_in_tool_handler.mjs.map +1 -1
  390. package/eslint/rules/require_validator_any_required.cjs +1 -0
  391. package/eslint/rules/require_validator_any_required.cjs.map +1 -1
  392. package/eslint/rules/require_validator_any_required.d.ts +1 -0
  393. package/eslint/rules/require_validator_any_required.mjs +1 -0
  394. package/eslint/rules/require_validator_any_required.mjs.map +1 -1
  395. package/eslint/rules/thought_payload_requires_replay_tag.cjs +1 -0
  396. package/eslint/rules/thought_payload_requires_replay_tag.cjs.map +1 -1
  397. package/eslint/rules/thought_payload_requires_replay_tag.d.ts +1 -0
  398. package/eslint/rules/thought_payload_requires_replay_tag.mjs +1 -0
  399. package/eslint/rules/thought_payload_requires_replay_tag.mjs.map +1 -1
  400. package/eslint/rules/token_encoding_requires_context_window.cjs +1 -0
  401. package/eslint/rules/token_encoding_requires_context_window.cjs.map +1 -1
  402. package/eslint/rules/token_encoding_requires_context_window.d.ts +1 -0
  403. package/eslint/rules/token_encoding_requires_context_window.mjs +1 -0
  404. package/eslint/rules/token_encoding_requires_context_window.mjs.map +1 -1
  405. package/eslint.cjs +1 -1
  406. package/eslint.mjs +1 -1
  407. package/{exceptions-BeWH2FwP.mjs → exceptions-BDhN0Xzr.mjs} +3 -2
  408. package/exceptions-BDhN0Xzr.mjs.map +1 -0
  409. package/{exceptions-CitH5wZI.js → exceptions-BRXrUKiW.js} +3 -2
  410. package/exceptions-BRXrUKiW.js.map +1 -0
  411. package/exceptions.cjs +2 -2
  412. package/exceptions.mjs +2 -2
  413. package/factories.cjs +1 -1
  414. package/factories.mjs +1 -1
  415. package/forge.cjs +4 -4
  416. package/forge.d.ts +1 -1
  417. package/forge.mjs +4 -4
  418. package/guards.cjs +9 -9
  419. package/guards.mjs +9 -9
  420. package/helpers-DSTFxTiC.js +497 -0
  421. package/helpers-DSTFxTiC.js.map +1 -0
  422. package/helpers-xhrQbMAG.mjs +306 -0
  423. package/helpers-xhrQbMAG.mjs.map +1 -0
  424. package/index.cjs +13 -13
  425. package/index.mjs +13 -13
  426. package/lib/classes/base_exception.d.ts +1 -0
  427. package/lib/classes/media.d.ts +10 -0
  428. package/lib/classes/retrievable.d.ts +1 -1
  429. package/lib/classes/spooled_json_artifact.d.ts +1 -1
  430. package/lib/classes/spooled_markdown_artifact.d.ts +1 -0
  431. package/lib/classes/tokenizable.d.ts +3 -0
  432. package/lib/classes/tool.d.ts +8 -0
  433. package/lib/classes/turn_gate.d.ts +6 -0
  434. package/lib/dispatch_runner.d.ts +4 -32
  435. package/lib/helpers/bignum.cjs +82 -0
  436. package/lib/helpers/bignum.cjs.map +1 -0
  437. package/lib/helpers/bignum.d.ts +52 -0
  438. package/lib/helpers/bignum.mjs +74 -0
  439. package/lib/helpers/bignum.mjs.map +1 -0
  440. package/lib/turn_runner.d.ts +1 -1
  441. package/lib/types/dispatch_runner.d.ts +83 -0
  442. package/lib/utils/exceptions.d.ts +1 -1
  443. package/lib/utils/retry.cjs.map +1 -1
  444. package/lib/utils/retry.d.ts +2 -0
  445. package/lib/utils/retry.mjs.map +1 -1
  446. package/mcp/adk-docs-corpus.json +1 -1
  447. package/package.json +264 -224
  448. package/{runtime-j92CNi5z.mjs → runtime-Bz5zA8wc.mjs} +2 -2
  449. package/{runtime-j92CNi5z.mjs.map → runtime-Bz5zA8wc.mjs.map} +1 -1
  450. package/{runtime-MFFcJrRv.js → runtime-DslE1aBw.js} +2 -2
  451. package/{runtime-MFFcJrRv.js.map → runtime-DslE1aBw.js.map} +1 -1
  452. package/searxng-Bkrwhwhw.js +269 -0
  453. package/searxng-Bkrwhwhw.js.map +1 -0
  454. package/searxng-CyA-nEu5.mjs +257 -0
  455. package/searxng-CyA-nEu5.mjs.map +1 -0
  456. package/skills/adk-assembly/SKILL.md +2 -2
  457. package/{spooled_artifact-CHoZgWwI.mjs → spooled_artifact-7eePq7JA.mjs} +5 -5
  458. package/{spooled_artifact-CHoZgWwI.mjs.map → spooled_artifact-7eePq7JA.mjs.map} +1 -1
  459. package/{spooled_artifact-BTq6Nzfy.js → spooled_artifact-DX8LLyUX.js} +5 -5
  460. package/{spooled_artifact-BTq6Nzfy.js.map → spooled_artifact-DX8LLyUX.js.map} +1 -1
  461. package/spooled_artifact.cjs +2 -2
  462. package/spooled_artifact.mjs +2 -2
  463. package/{spooled_markdown_artifact-CALSDxIx.js → spooled_markdown_artifact-ClX72lek.js} +4 -4
  464. package/spooled_markdown_artifact-ClX72lek.js.map +1 -0
  465. package/{spooled_markdown_artifact-Ci5UL7l4.mjs → spooled_markdown_artifact-wkrBF3oX.mjs} +4 -4
  466. package/spooled_markdown_artifact-wkrBF3oX.mjs.map +1 -0
  467. package/{thought-D34QQZZ9.mjs → thought-B_vxAiKU.mjs} +5 -5
  468. package/{thought-D34QQZZ9.mjs.map → thought-B_vxAiKU.mjs.map} +1 -1
  469. package/{thought-BbwhJ1wb.js → thought-DLwpF7MI.js} +5 -5
  470. package/{thought-BbwhJ1wb.js.map → thought-DLwpF7MI.js.map} +1 -1
  471. package/{tool-CVyZkFC7.js → tool-D5WGVIcI.js} +4 -4
  472. package/{tool-CVyZkFC7.js.map → tool-D5WGVIcI.js.map} +1 -1
  473. package/{tool-CMhaDRNd.mjs → tool-wMYMVl60.mjs} +4 -4
  474. package/{tool-CMhaDRNd.mjs.map → tool-wMYMVl60.mjs.map} +1 -1
  475. package/{tool_call-CV5qVNlb.mjs → tool_call-B4-_-vjG.mjs} +5 -5
  476. package/tool_call-B4-_-vjG.mjs.map +1 -0
  477. package/{tool_call-Db68hB7y.js → tool_call-DixVlW40.js} +5 -5
  478. package/tool_call-DixVlW40.js.map +1 -0
  479. package/{tool_registry-D1pSSlsd.mjs → tool_registry-791Vrjtf.mjs} +4 -3
  480. package/tool_registry-791Vrjtf.mjs.map +1 -0
  481. package/{tool_registry-DYUYqXvo.js → tool_registry-CKJPze3j.js} +4 -3
  482. package/tool_registry-CKJPze3j.js.map +1 -0
  483. package/{turn_runner-DqWHNP80.js → turn_runner-HXImLGIn.js} +7 -7
  484. package/turn_runner-HXImLGIn.js.map +1 -0
  485. package/{turn_runner-fg1Wc3dK.mjs → turn_runner-ZyYO-Kti.mjs} +7 -7
  486. package/turn_runner-ZyYO-Kti.mjs.map +1 -0
  487. package/turn_runner.cjs +1 -1
  488. package/turn_runner.mjs +1 -1
  489. package/types.d.ts +1 -1
  490. package/common-BT0nfCi9.mjs.map +0 -1
  491. package/common-Cj8TaQ9U.js.map +0 -1
  492. package/exceptions-BeWH2FwP.mjs.map +0 -1
  493. package/exceptions-CitH5wZI.js.map +0 -1
  494. package/spooled_markdown_artifact-CALSDxIx.js.map +0 -1
  495. package/spooled_markdown_artifact-Ci5UL7l4.mjs.map +0 -1
  496. package/tool_call-CV5qVNlb.mjs.map +0 -1
  497. package/tool_call-Db68hB7y.js.map +0 -1
  498. package/tool_registry-D1pSSlsd.mjs.map +0 -1
  499. package/tool_registry-DYUYqXvo.js.map +0 -1
  500. package/turn_runner-DqWHNP80.js.map +0 -1
  501. package/turn_runner-fg1Wc3dK.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"validation.mjs","names":[],"sources":["../../../../src/batteries/llm/webllm_chat_completions/validation.ts"],"sourcesContent":["/**\n * Runtime validation schema and wrapper for WebLLM Chat Completions adapter options.\n *\n * @module @nhtio/adk/batteries/llm/webllm_chat_completions/validation\n */\n\nimport { isError } from '@nhtio/adk/guards'\nimport { byteStoreSchema } from '@nhtio/adk/common'\nimport { validator, ValidationError } from '@nhtio/validation'\nimport { E_INVALID_WEBLLM_CHAT_COMPLETIONS_OPTIONS } from './exceptions'\nimport type { WebLLMChatCompletionsAdapterOptions } from './types'\n\nconst bucketLabelSchema = validator\n .string()\n .valid('standingInstructions', 'memories', 'retrievables', 'timeline')\n\nconst bucketOrderSchema = validator\n .array()\n .items(bucketLabelSchema)\n .unique()\n .default(['standingInstructions', 'memories', 'retrievables', 'timeline'])\n\nconst reasoningFieldPrecedenceSchema = validator\n .array()\n .items(validator.string().valid('reasoning', 'reasoning_content'))\n .unique()\n .min(1)\n .default(['reasoning', 'reasoning_content'])\n\nconst tokenEncodingSchema = validator\n .alternatives(\n validator\n .string()\n .valid(\n 'gpt2',\n 'r50k_base',\n 'p50k_base',\n 'p50k_edit',\n 'cl100k_base',\n 'o200k_base',\n 'gemini',\n 'llama2',\n 'claude'\n ),\n // tokenEncoding is OPTIONAL: a valid encoding string, explicit null, or absent (undefined =\n // \"no token counting\"). `.optional()` makes the null/undefined disposition explicit (both\n // allowed) per adk/require-validator-any-required, without rejecting the omitted case.\n validator.any().valid(null).optional()\n )\n .default(null)\n\nconst helperSchema = validator.function()\n\nconst helpersSchema = validator\n .object({\n descriptionToChatCompletionsJsonSchema: helperSchema.optional(),\n renderUntrustedContent: helperSchema.optional(),\n renderTrustedContent: helperSchema.optional(),\n renderStandingInstructions: helperSchema.optional(),\n renderMemories: helperSchema.optional(),\n renderRetrievables: helperSchema.optional(),\n renderRetrievableSafetyDirective: helperSchema.optional(),\n renderFirstPartyRetrievables: helperSchema.optional(),\n renderThirdPartyPublicRetrievables: helperSchema.optional(),\n renderThirdPartyPrivateRetrievables: helperSchema.optional(),\n renderTimelineMessage: helperSchema.optional(),\n renderThought: helperSchema.optional(),\n filterThoughts: helperSchema.optional(),\n toolsToChatCompletionsTools: helperSchema.optional(),\n renderChatCompletionsSystemPrompt: helperSchema.optional(),\n renderChatCompletionsToolCallResult: helperSchema.optional(),\n buildChatCompletionsHistory: helperSchema.optional(),\n createChatCompletionsToolCallDeltaAccumulator: helperSchema.optional(),\n })\n .unknown(false)\n\nconst jsonSchemaSchema = validator.object().unknown(true)\n\nconst responseFormatSchema = validator.alternatives(\n validator.object({ type: validator.string().valid('text').required() }).unknown(false),\n validator.object({ type: validator.string().valid('json_object').required() }).unknown(false),\n validator\n .object({\n type: validator.string().valid('json_schema').required(),\n json_schema: validator\n .object({\n name: validator.string().required(),\n schema: jsonSchemaSchema.required(),\n strict: validator.boolean().optional(),\n description: validator.string().optional(),\n })\n .unknown(false)\n .required(),\n })\n .unknown(false)\n)\n\nconst toolChoiceItemSchema = validator.alternatives(\n validator\n .object({\n type: validator.string().valid('function').required(),\n function: validator.object({ name: validator.string().required() }).unknown(false).required(),\n })\n .unknown(false),\n validator\n .object({\n type: validator.string().valid('custom').required(),\n custom: validator.object({ name: validator.string().required() }).unknown(false).required(),\n })\n .unknown(false)\n)\n\nconst toolChoiceSchema = validator.alternatives(\n validator.string().valid('none', 'auto', 'required'),\n toolChoiceItemSchema,\n validator\n .object({\n type: validator.string().valid('allowed_tools').required(),\n allowed_tools: validator\n .object({\n mode: validator.string().valid('auto', 'required').required(),\n tools: validator.array().items(toolChoiceItemSchema).required(),\n })\n .unknown(false)\n .required(),\n })\n .unknown(false)\n)\n\nexport const webLLMChatCompletionsOptionsSchema = validator\n .object<WebLLMChatCompletionsAdapterOptions>({\n engine: validator.object().unknown(true).optional(),\n createEngine: validator.function().optional(),\n onInitProgress: validator.function().optional(),\n isWebGPUAvailable: validator.function().optional(),\n engineConfig: validator.object().unknown(true).optional(),\n chatOptions: validator\n .alternatives(\n validator.object().unknown(true),\n validator.array().items(validator.object().unknown(true))\n )\n .optional(),\n stream: validator.boolean().default(true),\n bucketOrder: bucketOrderSchema,\n contextWindow: validator.number().integer().min(1).optional(),\n selfIdentity: validator.string().min(1).default('assistant'),\n thoughtSurfacing: validator\n .string()\n .valid('all-self', 'latest-self', 'all')\n .default('all-self'),\n tokenEncoding: tokenEncodingSchema,\n replayCompatibility: validator.array().items(validator.string().min(1)).default([]),\n reasoningFieldPrecedence: reasoningFieldPrecedenceSchema,\n helpers: helpersSchema.optional(),\n spoolStore: byteStoreSchema.optional(),\n strictToolChoice: validator.boolean().default(false),\n // Opt-in: executor self-acks tool-call-free responses only when true.\n // Default false hands turn completion to the implementor (see\n // OpenAIChatCompletionsAdapterOptions.autoAck — inherited here).\n autoAck: validator.boolean().default(false),\n unsupportedMediaPolicy: validator\n .alternatives(\n validator.string().valid('throw', 'fallback-stash', 'synthetic-description'),\n validator\n .object({\n mode: validator.string().valid('fallback-stash').required(),\n stashKeys: validator.array().items(validator.string().min(1)).required(),\n })\n .unknown(false)\n )\n .default('throw'),\n\n model: validator.string().required(),\n frequency_penalty: validator.number().min(-2).max(2).optional(),\n logit_bias: validator.object().pattern(validator.string(), validator.number()).optional(),\n logprobs: validator.boolean().optional(),\n max_tokens: validator.number().integer().min(1).optional(),\n n: validator.number().integer().min(1).optional(),\n presence_penalty: validator.number().min(-2).max(2).optional(),\n response_format: responseFormatSchema.optional(),\n seed: validator.number().integer().optional(),\n stop: validator\n .alternatives(validator.string(), validator.array().items(validator.string()))\n .optional(),\n stream_options: validator.object().unknown(true).optional(),\n temperature: validator.number().min(0).max(2).optional(),\n tool_choice: toolChoiceSchema.optional(),\n top_logprobs: validator.number().integer().min(0).optional(),\n top_p: validator.number().min(0).max(1).optional(),\n user: validator.string().optional(),\n repetition_penalty: validator.number().optional(),\n ignore_eos: validator.boolean().optional(),\n extra_body: validator.object().unknown(true).optional(),\n max_completion_tokens: validator.number().integer().min(1).optional(),\n })\n .unknown(false)\n\nconst isValidationError = (value: unknown): value is ValidationError =>\n isError(value) && Array.isArray((value as ValidationError).details)\n\nconst formatValidationDetails = (err: ValidationError): string =>\n err.details.map((d) => d.message).join(' and ')\n\nexport const validateOptions = (input: unknown): WebLLMChatCompletionsAdapterOptions => {\n const { value, error } = webLLMChatCompletionsOptionsSchema.validate(input, {\n abortEarly: false,\n convert: false,\n })\n if (error) {\n throw new E_INVALID_WEBLLM_CHAT_COMPLETIONS_OPTIONS([formatValidationDetails(error)], {\n cause: error,\n })\n }\n return value as WebLLMChatCompletionsAdapterOptions\n}\n\nvoid isValidationError\n"],"mappings":";;;;;AAYA,IAAM,oBAAoB,UACvB,OAAO,EACP,MAAM,wBAAwB,YAAY,gBAAgB,UAAU;AAEvE,IAAM,oBAAoB,UACvB,MAAM,EACN,MAAM,iBAAiB,EACvB,OAAO,EACP,QAAQ;CAAC;CAAwB;CAAY;CAAgB;AAAU,CAAC;AAE3E,IAAM,iCAAiC,UACpC,MAAM,EACN,MAAM,UAAU,OAAO,EAAE,MAAM,aAAa,mBAAmB,CAAC,EAChE,OAAO,EACP,IAAI,CAAC,EACL,QAAQ,CAAC,aAAa,mBAAmB,CAAC;AAE7C,IAAM,sBAAsB,UACzB,aACC,UACG,OAAO,EACP,MACC,QACA,aACA,aACA,aACA,eACA,cACA,UACA,UACA,QACF,GAIF,UAAU,IAAI,EAAE,MAAM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,iBAAiB,qBAAqB,SAAS;CAC/C,MAAM,UAAU,OAAO,EAAE,QAAQ,EAAE,SAAS;CAC5C,MAAM,UACH,aAAa,UAAU,OAAO,GAAG,UAAU,MAAM,EAAE,MAAM,UAAU,OAAO,CAAC,CAAC,EAC5E,SAAS;CACZ,gBAAgB,UAAU,OAAO,EAAE,QAAQ,IAAI,EAAE,SAAS;CAC1D,aAAa,UAAU,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS;CACvD,aAAa,iBAAiB,SAAS;CACvC,cAAc,UAAU,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,SAAS;CAC3D,OAAO,UAAU,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS;CACjD,MAAM,UAAU,OAAO,EAAE,SAAS;CAClC,oBAAoB,UAAU,OAAO,EAAE,SAAS;CAChD,YAAY,UAAU,QAAQ,EAAE,SAAS;CACzC,YAAY,UAAU,OAAO,EAAE,QAAQ,IAAI,EAAE,SAAS;CACtD,uBAAuB,UAAU,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,SAAS;AACtE,CAAC,EACA,QAAQ,KAAK;AAKhB,IAAM,2BAA2B,QAC/B,IAAI,QAAQ,KAAK,MAAM,EAAE,OAAO,EAAE,KAAK,OAAO;AAEhD,IAAa,mBAAmB,UAAwD;CACtF,MAAM,EAAE,OAAO,UAAU,mCAAmC,SAAS,OAAO;EAC1E,YAAY;EACZ,SAAS;CACX,CAAC;CACD,IAAI,OACF,MAAM,IAAI,0CAA0C,CAAC,wBAAwB,KAAK,CAAC,GAAG,EACpF,OAAO,MACT,CAAC;CAEH,OAAO;AACT"}
1
+ {"version":3,"file":"validation.mjs","names":[],"sources":["../../../../src/batteries/llm/webllm_chat_completions/validation.ts"],"sourcesContent":["/**\n * Runtime validation schema and wrapper for WebLLM Chat Completions adapter options.\n *\n * @module @nhtio/adk/batteries/llm/webllm_chat_completions/validation\n */\n\nimport { isError } from '@nhtio/adk/guards'\nimport { byteStoreSchema } from '@nhtio/adk/common'\nimport { validator, ValidationError } from '@nhtio/validation'\nimport { E_INVALID_WEBLLM_CHAT_COMPLETIONS_OPTIONS } from './exceptions'\nimport type { WebLLMChatCompletionsAdapterOptions } from './types'\n\nconst bucketLabelSchema = validator\n .string()\n .valid('standingInstructions', 'memories', 'retrievables', 'timeline')\n\nconst bucketOrderSchema = validator\n .array()\n .items(bucketLabelSchema)\n .unique()\n .default(['standingInstructions', 'memories', 'retrievables', 'timeline'])\n\nconst reasoningFieldPrecedenceSchema = validator\n .array()\n .items(validator.string().valid('reasoning', 'reasoning_content'))\n .unique()\n .min(1)\n .default(['reasoning', 'reasoning_content'])\n\nconst tokenEncodingSchema = validator\n .alternatives(\n validator\n .string()\n .valid(\n 'gpt2',\n 'r50k_base',\n 'p50k_base',\n 'p50k_edit',\n 'cl100k_base',\n 'o200k_base',\n 'gemini',\n 'llama2',\n 'claude'\n ),\n // tokenEncoding is OPTIONAL: a valid encoding string, explicit null, or absent (undefined =\n // \"no token counting\"). `.optional()` makes the null/undefined disposition explicit (both\n // allowed) per adk/require-validator-any-required, without rejecting the omitted case.\n validator.any().valid(null).optional()\n )\n .default(null)\n\nconst helperSchema = validator.function()\n\nconst helpersSchema = validator\n .object({\n descriptionToChatCompletionsJsonSchema: helperSchema.optional(),\n renderUntrustedContent: helperSchema.optional(),\n renderTrustedContent: helperSchema.optional(),\n renderStandingInstructions: helperSchema.optional(),\n renderMemories: helperSchema.optional(),\n renderRetrievables: helperSchema.optional(),\n renderRetrievableSafetyDirective: helperSchema.optional(),\n renderFirstPartyRetrievables: helperSchema.optional(),\n renderThirdPartyPublicRetrievables: helperSchema.optional(),\n renderThirdPartyPrivateRetrievables: helperSchema.optional(),\n renderTimelineMessage: helperSchema.optional(),\n renderThought: helperSchema.optional(),\n filterThoughts: helperSchema.optional(),\n toolsToChatCompletionsTools: helperSchema.optional(),\n renderChatCompletionsSystemPrompt: helperSchema.optional(),\n renderChatCompletionsToolCallResult: helperSchema.optional(),\n buildChatCompletionsHistory: helperSchema.optional(),\n createChatCompletionsToolCallDeltaAccumulator: helperSchema.optional(),\n })\n .unknown(false)\n\nconst jsonSchemaSchema = validator.object().unknown(true)\n\nconst responseFormatSchema = validator.alternatives(\n validator.object({ type: validator.string().valid('text').required() }).unknown(false),\n validator.object({ type: validator.string().valid('json_object').required() }).unknown(false),\n validator\n .object({\n type: validator.string().valid('json_schema').required(),\n json_schema: validator\n .object({\n name: validator.string().required(),\n schema: jsonSchemaSchema.required(),\n strict: validator.boolean().optional(),\n description: validator.string().optional(),\n })\n .unknown(false)\n .required(),\n })\n .unknown(false)\n)\n\nconst toolChoiceItemSchema = validator.alternatives(\n validator\n .object({\n type: validator.string().valid('function').required(),\n function: validator.object({ name: validator.string().required() }).unknown(false).required(),\n })\n .unknown(false),\n validator\n .object({\n type: validator.string().valid('custom').required(),\n custom: validator.object({ name: validator.string().required() }).unknown(false).required(),\n })\n .unknown(false)\n)\n\nconst toolChoiceSchema = validator.alternatives(\n validator.string().valid('none', 'auto', 'required'),\n toolChoiceItemSchema,\n validator\n .object({\n type: validator.string().valid('allowed_tools').required(),\n allowed_tools: validator\n .object({\n mode: validator.string().valid('auto', 'required').required(),\n tools: validator.array().items(toolChoiceItemSchema).required(),\n })\n .unknown(false)\n .required(),\n })\n .unknown(false)\n)\n\n/**\n * Validator schema for {@link WebLLMChatCompletionsAdapterOptions}. Rejects unknown keys\n * (`.unknown(false)`) so typos and removed fields fail loud, and fills in defaults.\n */\nexport const webLLMChatCompletionsOptionsSchema = validator\n .object<WebLLMChatCompletionsAdapterOptions>({\n engine: validator.object().unknown(true).optional(),\n createEngine: validator.function().optional(),\n onInitProgress: validator.function().optional(),\n isWebGPUAvailable: validator.function().optional(),\n engineConfig: validator.object().unknown(true).optional(),\n chatOptions: validator\n .alternatives(\n validator.object().unknown(true),\n validator.array().items(validator.object().unknown(true))\n )\n .optional(),\n stream: validator.boolean().default(true),\n bucketOrder: bucketOrderSchema,\n contextWindow: validator.number().integer().min(1).optional(),\n selfIdentity: validator.string().min(1).default('assistant'),\n thoughtSurfacing: validator\n .string()\n .valid('all-self', 'latest-self', 'all')\n .default('all-self'),\n tokenEncoding: tokenEncodingSchema,\n replayCompatibility: validator.array().items(validator.string().min(1)).default([]),\n reasoningFieldPrecedence: reasoningFieldPrecedenceSchema,\n helpers: helpersSchema.optional(),\n spoolStore: byteStoreSchema.optional(),\n strictToolChoice: validator.boolean().default(false),\n // Opt-in: executor self-acks tool-call-free responses only when true.\n // Default false hands turn completion to the implementor (see\n // OpenAIChatCompletionsAdapterOptions.autoAck — inherited here).\n autoAck: validator.boolean().default(false),\n unsupportedMediaPolicy: validator\n .alternatives(\n validator.string().valid('throw', 'fallback-stash', 'synthetic-description'),\n validator\n .object({\n mode: validator.string().valid('fallback-stash').required(),\n stashKeys: validator.array().items(validator.string().min(1)).required(),\n })\n .unknown(false)\n )\n .default('throw'),\n\n model: validator.string().required(),\n frequency_penalty: validator.number().min(-2).max(2).optional(),\n logit_bias: validator.object().pattern(validator.string(), validator.number()).optional(),\n logprobs: validator.boolean().optional(),\n max_tokens: validator.number().integer().min(1).optional(),\n n: validator.number().integer().min(1).optional(),\n presence_penalty: validator.number().min(-2).max(2).optional(),\n response_format: responseFormatSchema.optional(),\n seed: validator.number().integer().optional(),\n stop: validator\n .alternatives(validator.string(), validator.array().items(validator.string()))\n .optional(),\n stream_options: validator.object().unknown(true).optional(),\n temperature: validator.number().min(0).max(2).optional(),\n tool_choice: toolChoiceSchema.optional(),\n top_logprobs: validator.number().integer().min(0).optional(),\n top_p: validator.number().min(0).max(1).optional(),\n user: validator.string().optional(),\n repetition_penalty: validator.number().optional(),\n ignore_eos: validator.boolean().optional(),\n extra_body: validator.object().unknown(true).optional(),\n max_completion_tokens: validator.number().integer().min(1).optional(),\n })\n .unknown(false)\n\nconst isValidationError = (value: unknown): value is ValidationError =>\n isError(value) && Array.isArray((value as ValidationError).details)\n\nconst formatValidationDetails = (err: ValidationError): string =>\n err.details.map((d) => d.message).join(' and ')\n\n/**\n * Validates raw adapter options against {@link webLLMChatCompletionsOptionsSchema}, filling in\n * defaults.\n *\n * @param input - The raw options object to validate.\n * @returns The resolved options object with defaults applied.\n * @throws {@link @nhtio/adk/batteries!E_INVALID_WEBLLM_CHAT_COMPLETIONS_OPTIONS} when `input` is invalid.\n */\nexport const validateOptions = (input: unknown): WebLLMChatCompletionsAdapterOptions => {\n const { value, error } = webLLMChatCompletionsOptionsSchema.validate(input, {\n abortEarly: false,\n convert: false,\n })\n if (error) {\n throw new E_INVALID_WEBLLM_CHAT_COMPLETIONS_OPTIONS([formatValidationDetails(error)], {\n cause: error,\n })\n }\n return value as WebLLMChatCompletionsAdapterOptions\n}\n\nvoid isValidationError\n"],"mappings":";;;;;AAYA,IAAM,oBAAoB,UACvB,OAAO,EACP,MAAM,wBAAwB,YAAY,gBAAgB,UAAU;AAEvE,IAAM,oBAAoB,UACvB,MAAM,EACN,MAAM,iBAAiB,EACvB,OAAO,EACP,QAAQ;CAAC;CAAwB;CAAY;CAAgB;AAAU,CAAC;AAE3E,IAAM,iCAAiC,UACpC,MAAM,EACN,MAAM,UAAU,OAAO,EAAE,MAAM,aAAa,mBAAmB,CAAC,EAChE,OAAO,EACP,IAAI,CAAC,EACL,QAAQ,CAAC,aAAa,mBAAmB,CAAC;AAE7C,IAAM,sBAAsB,UACzB,aACC,UACG,OAAO,EACP,MACC,QACA,aACA,aACA,aACA,eACA,cACA,UACA,UACA,QACF,GAIF,UAAU,IAAI,EAAE,MAAM,IAAI,EAAE,SAAS,CACvC,EACC,QAAQ,IAAI;AAEf,IAAM,eAAe,UAAU,SAAS;AAExC,IAAM,gBAAgB,UACnB,OAAO;CACN,wCAAwC,aAAa,SAAS;CAC9D,wBAAwB,aAAa,SAAS;CAC9C,sBAAsB,aAAa,SAAS;CAC5C,4BAA4B,aAAa,SAAS;CAClD,gBAAgB,aAAa,SAAS;CACtC,oBAAoB,aA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U,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS;CACvD,aAAa,iBAAiB,SAAS;CACvC,cAAc,UAAU,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,SAAS;CAC3D,OAAO,UAAU,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS;CACjD,MAAM,UAAU,OAAO,EAAE,SAAS;CAClC,oBAAoB,UAAU,OAAO,EAAE,SAAS;CAChD,YAAY,UAAU,QAAQ,EAAE,SAAS;CACzC,YAAY,UAAU,OAAO,EAAE,QAAQ,IAAI,EAAE,SAAS;CACtD,uBAAuB,UAAU,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,SAAS;AACtE,CAAC,EACA,QAAQ,KAAK;AAKhB,IAAM,2BAA2B,QAC/B,IAAI,QAAQ,KAAK,MAAM,EAAE,OAAO,EAAE,KAAK,OAAO;;;;;;;;;AAUhD,IAAa,mBAAmB,UAAwD;CACtF,MAAM,EAAE,OAAO,UAAU,mCAAmC,SAAS,OAAO;EAC1E,YAAY;EACZ,SAAS;CACX,CAAC;CACD,IAAI,OACF,MAAM,IAAI,0CAA0C,CAAC,wBAAwB,KAAK,CAAC,GAAG,EACpF,OAAO,MACT,CAAC;CAEH,OAAO;AACT"}
@@ -1,5 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("../../chunk-Ble4zEEl.js");
3
+ const require_helpers = require("../../helpers-DSTFxTiC.js");
3
4
  const require_batteries_llm_openai_chat_completions_helpers = require("./openai_chat_completions/helpers.cjs");
4
5
  const require_batteries_llm_webllm_chat_completions_exceptions = require("./webllm_chat_completions/exceptions.cjs");
5
6
  const require_batteries_llm_webllm_chat_completions_validation = require("./webllm_chat_completions/validation.cjs");
@@ -15,38 +16,38 @@ exports.buildChatCompletionsHistory = require_batteries_llm_openai_chat_completi
15
16
  exports.createChatCompletionsToolCallDeltaAccumulator = require_batteries_llm_openai_chat_completions_helpers.createChatCompletionsToolCallDeltaAccumulator;
16
17
  exports.defaultBuildChatCompletionsHistory = require_batteries_llm_openai_chat_completions_helpers.defaultBuildChatCompletionsHistory;
17
18
  exports.defaultCreateChatCompletionsToolCallDeltaAccumulator = require_batteries_llm_openai_chat_completions_helpers.defaultCreateChatCompletionsToolCallDeltaAccumulator;
18
- exports.defaultDescriptionToChatCompletionsJsonSchema = require_batteries_llm_openai_chat_completions_helpers.defaultDescriptionToChatCompletionsJsonSchema;
19
- exports.defaultFilterThoughts = require_batteries_llm_openai_chat_completions_helpers.defaultFilterThoughts;
20
- exports.defaultRenderChatCompletionsSystemPrompt = require_batteries_llm_openai_chat_completions_helpers.defaultRenderChatCompletionsSystemPrompt;
19
+ exports.defaultDescriptionToChatCompletionsJsonSchema = require_helpers.defaultDescriptionToChatCompletionsJsonSchema;
20
+ exports.defaultFilterThoughts = require_helpers.defaultFilterThoughts;
21
+ exports.defaultRenderChatCompletionsSystemPrompt = require_helpers.defaultRenderChatCompletionsSystemPrompt;
21
22
  exports.defaultRenderChatCompletionsToolCallResult = require_batteries_llm_openai_chat_completions_helpers.defaultRenderChatCompletionsToolCallResult;
22
- exports.defaultRenderFirstPartyRetrievables = require_batteries_llm_openai_chat_completions_helpers.defaultRenderFirstPartyRetrievables;
23
- exports.defaultRenderMemories = require_batteries_llm_openai_chat_completions_helpers.defaultRenderMemories;
24
- exports.defaultRenderRetrievableSafetyDirective = require_batteries_llm_openai_chat_completions_helpers.defaultRenderRetrievableSafetyDirective;
25
- exports.defaultRenderRetrievables = require_batteries_llm_openai_chat_completions_helpers.defaultRenderRetrievables;
26
- exports.defaultRenderStandingInstructions = require_batteries_llm_openai_chat_completions_helpers.defaultRenderStandingInstructions;
27
- exports.defaultRenderThirdPartyPrivateRetrievables = require_batteries_llm_openai_chat_completions_helpers.defaultRenderThirdPartyPrivateRetrievables;
28
- exports.defaultRenderThirdPartyPublicRetrievables = require_batteries_llm_openai_chat_completions_helpers.defaultRenderThirdPartyPublicRetrievables;
29
- exports.defaultRenderThought = require_batteries_llm_openai_chat_completions_helpers.defaultRenderThought;
23
+ exports.defaultRenderFirstPartyRetrievables = require_helpers.defaultRenderFirstPartyRetrievables;
24
+ exports.defaultRenderMemories = require_helpers.defaultRenderMemories;
25
+ exports.defaultRenderRetrievableSafetyDirective = require_helpers.defaultRenderRetrievableSafetyDirective;
26
+ exports.defaultRenderRetrievables = require_helpers.defaultRenderRetrievables;
27
+ exports.defaultRenderStandingInstructions = require_helpers.defaultRenderStandingInstructions;
28
+ exports.defaultRenderThirdPartyPrivateRetrievables = require_helpers.defaultRenderThirdPartyPrivateRetrievables;
29
+ exports.defaultRenderThirdPartyPublicRetrievables = require_helpers.defaultRenderThirdPartyPublicRetrievables;
30
+ exports.defaultRenderThought = require_helpers.defaultRenderThought;
30
31
  exports.defaultRenderTimelineMessage = require_batteries_llm_openai_chat_completions_helpers.defaultRenderTimelineMessage;
31
- exports.defaultRenderTrustedContent = require_batteries_llm_openai_chat_completions_helpers.defaultRenderTrustedContent;
32
- exports.defaultRenderUntrustedContent = require_batteries_llm_openai_chat_completions_helpers.defaultRenderUntrustedContent;
33
- exports.defaultToolsToChatCompletionsTools = require_batteries_llm_openai_chat_completions_helpers.defaultToolsToChatCompletionsTools;
34
- exports.descriptionToChatCompletionsJsonSchema = require_batteries_llm_openai_chat_completions_helpers.descriptionToChatCompletionsJsonSchema;
32
+ exports.defaultRenderTrustedContent = require_helpers.defaultRenderTrustedContent;
33
+ exports.defaultRenderUntrustedContent = require_helpers.defaultRenderUntrustedContent;
34
+ exports.defaultToolsToChatCompletionsTools = require_helpers.defaultToolsToChatCompletionsTools;
35
+ exports.descriptionToChatCompletionsJsonSchema = require_helpers.descriptionToChatCompletionsJsonSchema;
35
36
  exports.extractReasoningFields = require_batteries_llm_openai_chat_completions_helpers.extractReasoningFields;
36
- exports.filterThoughts = require_batteries_llm_openai_chat_completions_helpers.filterThoughts;
37
- exports.renderChatCompletionsSystemPrompt = require_batteries_llm_openai_chat_completions_helpers.renderChatCompletionsSystemPrompt;
37
+ exports.filterThoughts = require_helpers.filterThoughts;
38
+ exports.renderChatCompletionsSystemPrompt = require_helpers.renderChatCompletionsSystemPrompt;
38
39
  exports.renderChatCompletionsToolCallResult = require_batteries_llm_openai_chat_completions_helpers.renderChatCompletionsToolCallResult;
39
- exports.renderFirstPartyRetrievables = require_batteries_llm_openai_chat_completions_helpers.renderFirstPartyRetrievables;
40
- exports.renderMemories = require_batteries_llm_openai_chat_completions_helpers.renderMemories;
41
- exports.renderRetrievableSafetyDirective = require_batteries_llm_openai_chat_completions_helpers.renderRetrievableSafetyDirective;
42
- exports.renderRetrievables = require_batteries_llm_openai_chat_completions_helpers.renderRetrievables;
43
- exports.renderStandingInstructions = require_batteries_llm_openai_chat_completions_helpers.renderStandingInstructions;
44
- exports.renderThirdPartyPrivateRetrievables = require_batteries_llm_openai_chat_completions_helpers.renderThirdPartyPrivateRetrievables;
45
- exports.renderThirdPartyPublicRetrievables = require_batteries_llm_openai_chat_completions_helpers.renderThirdPartyPublicRetrievables;
46
- exports.renderThought = require_batteries_llm_openai_chat_completions_helpers.renderThought;
40
+ exports.renderFirstPartyRetrievables = require_helpers.renderFirstPartyRetrievables;
41
+ exports.renderMemories = require_helpers.renderMemories;
42
+ exports.renderRetrievableSafetyDirective = require_helpers.renderRetrievableSafetyDirective;
43
+ exports.renderRetrievables = require_helpers.renderRetrievables;
44
+ exports.renderStandingInstructions = require_helpers.renderStandingInstructions;
45
+ exports.renderThirdPartyPrivateRetrievables = require_helpers.renderThirdPartyPrivateRetrievables;
46
+ exports.renderThirdPartyPublicRetrievables = require_helpers.renderThirdPartyPublicRetrievables;
47
+ exports.renderThought = require_helpers.renderThought;
47
48
  exports.renderTimelineMessage = require_batteries_llm_openai_chat_completions_helpers.renderTimelineMessage;
48
- exports.renderTrustedContent = require_batteries_llm_openai_chat_completions_helpers.renderTrustedContent;
49
- exports.renderUntrustedContent = require_batteries_llm_openai_chat_completions_helpers.renderUntrustedContent;
50
- exports.toolsToChatCompletionsTools = require_batteries_llm_openai_chat_completions_helpers.toolsToChatCompletionsTools;
49
+ exports.renderTrustedContent = require_helpers.renderTrustedContent;
50
+ exports.renderUntrustedContent = require_helpers.renderUntrustedContent;
51
+ exports.toolsToChatCompletionsTools = require_helpers.toolsToChatCompletionsTools;
51
52
  exports.validateOptions = require_batteries_llm_webllm_chat_completions_validation.validateOptions;
52
53
  exports.webLLMChatCompletionsOptionsSchema = require_batteries_llm_webllm_chat_completions_validation.webLLMChatCompletionsOptionsSchema;
@@ -1,4 +1,5 @@
1
- import { buildChatCompletionsHistory, createChatCompletionsToolCallDeltaAccumulator, defaultBuildChatCompletionsHistory, defaultCreateChatCompletionsToolCallDeltaAccumulator, defaultDescriptionToChatCompletionsJsonSchema, defaultFilterThoughts, defaultRenderChatCompletionsSystemPrompt, defaultRenderChatCompletionsToolCallResult, defaultRenderFirstPartyRetrievables, defaultRenderMemories, defaultRenderRetrievableSafetyDirective, defaultRenderRetrievables, defaultRenderStandingInstructions, defaultRenderThirdPartyPrivateRetrievables, defaultRenderThirdPartyPublicRetrievables, defaultRenderThought, defaultRenderTimelineMessage, defaultRenderTrustedContent, defaultRenderUntrustedContent, defaultToolsToChatCompletionsTools, descriptionToChatCompletionsJsonSchema, extractReasoningFields, filterThoughts, renderChatCompletionsSystemPrompt, renderChatCompletionsToolCallResult, renderFirstPartyRetrievables, renderMemories, renderRetrievableSafetyDirective, renderRetrievables, renderStandingInstructions, renderThirdPartyPrivateRetrievables, renderThirdPartyPublicRetrievables, renderThought, renderTimelineMessage, renderTrustedContent, renderUntrustedContent, toolsToChatCompletionsTools } from "./openai_chat_completions/helpers.mjs";
1
+ import { C as renderRetrievables, D as renderThought, E as renderThirdPartyPublicRetrievables, M as toolsToChatCompletionsTools, O as renderTrustedContent, S as renderRetrievableSafetyDirective, T as renderThirdPartyPrivateRetrievables, _ as filterThoughts, a as defaultRenderMemories, b as renderFirstPartyRetrievables, c as defaultRenderStandingInstructions, d as defaultRenderThought, f as defaultRenderTrustedContent, h as descriptionToChatCompletionsJsonSchema, i as defaultRenderFirstPartyRetrievables, k as renderUntrustedContent, 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, w as renderStandingInstructions, x as renderMemories, y as renderChatCompletionsSystemPrompt } from "../../helpers-xhrQbMAG.mjs";
2
+ import { buildChatCompletionsHistory, createChatCompletionsToolCallDeltaAccumulator, defaultBuildChatCompletionsHistory, defaultCreateChatCompletionsToolCallDeltaAccumulator, defaultRenderChatCompletionsToolCallResult, defaultRenderTimelineMessage, extractReasoningFields, renderChatCompletionsToolCallResult, renderTimelineMessage } from "./openai_chat_completions/helpers.mjs";
2
3
  import { E_INVALID_WEBLLM_CHAT_COMPLETIONS_OPTIONS, E_UNSUPPORTED_MEDIA_MODALITY, E_WEBLLM_CHAT_COMPLETIONS_CONTEXT_OVERFLOW, E_WEBLLM_CHAT_COMPLETIONS_INVALID_TOOL_CALL_ARGS, E_WEBLLM_CHAT_COMPLETIONS_STREAM_ERROR } from "./webllm_chat_completions/exceptions.mjs";
3
4
  import { validateOptions, webLLMChatCompletionsOptionsSchema } from "./webllm_chat_completions/validation.mjs";
4
5
  import "./webllm_chat_completions/helpers.mjs";
package/batteries/llm.cjs CHANGED
@@ -2,6 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("../chunk-Ble4zEEl.js");
3
3
  const require_batteries_llm_openai_chat_completions_exceptions = require("./llm/openai_chat_completions/exceptions.cjs");
4
4
  const require_batteries_llm_openai_chat_completions_validation = require("./llm/openai_chat_completions/validation.cjs");
5
+ const require_helpers = require("../helpers-DSTFxTiC.js");
5
6
  const require_batteries_llm_openai_chat_completions_helpers = require("./llm/openai_chat_completions/helpers.cjs");
6
7
  const require_batteries_llm_openai_chat_completions_adapter = require("./llm/openai_chat_completions/adapter.cjs");
7
8
  require("./llm/openai_chat_completions.cjs");
@@ -9,8 +10,20 @@ const require_batteries_llm_webllm_chat_completions_exceptions = require("./llm/
9
10
  const require_batteries_llm_webllm_chat_completions_validation = require("./llm/webllm_chat_completions/validation.cjs");
10
11
  const require_batteries_llm_webllm_chat_completions_adapter = require("./llm/webllm_chat_completions/adapter.cjs");
11
12
  require("./llm/webllm_chat_completions.cjs");
13
+ const require_batteries_llm_ollama_exceptions = require("./llm/ollama/exceptions.cjs");
14
+ const require_batteries_llm_ollama_validation = require("./llm/ollama/validation.cjs");
15
+ const require_batteries_llm_ollama_adapter = require("./llm/ollama/adapter.cjs");
16
+ require("./llm/ollama.cjs");
17
+ exports.E_INVALID_OLLAMA_OPTIONS = require_batteries_llm_ollama_exceptions.E_INVALID_OLLAMA_OPTIONS;
12
18
  exports.E_INVALID_OPENAI_CHAT_COMPLETIONS_OPTIONS = require_batteries_llm_openai_chat_completions_exceptions.E_INVALID_OPENAI_CHAT_COMPLETIONS_OPTIONS;
13
19
  exports.E_INVALID_WEBLLM_CHAT_COMPLETIONS_OPTIONS = require_batteries_llm_webllm_chat_completions_exceptions.E_INVALID_WEBLLM_CHAT_COMPLETIONS_OPTIONS;
20
+ exports.E_OLLAMA_CONTEXT_OVERFLOW = require_batteries_llm_ollama_exceptions.E_OLLAMA_CONTEXT_OVERFLOW;
21
+ exports.E_OLLAMA_HTTP_ERROR = require_batteries_llm_ollama_exceptions.E_OLLAMA_HTTP_ERROR;
22
+ exports.E_OLLAMA_INVALID_TOOL_CALL_ARGS = require_batteries_llm_ollama_exceptions.E_OLLAMA_INVALID_TOOL_CALL_ARGS;
23
+ exports.E_OLLAMA_REQUEST_TIMEOUT = require_batteries_llm_ollama_exceptions.E_OLLAMA_REQUEST_TIMEOUT;
24
+ exports.E_OLLAMA_STREAM_ERROR = require_batteries_llm_ollama_exceptions.E_OLLAMA_STREAM_ERROR;
25
+ exports.E_OLLAMA_STREAM_STALLED = require_batteries_llm_ollama_exceptions.E_OLLAMA_STREAM_STALLED;
26
+ exports.E_OLLAMA_UNSUPPORTED_MEDIA_MODALITY = require_batteries_llm_ollama_exceptions.E_OLLAMA_UNSUPPORTED_MEDIA_MODALITY;
14
27
  exports.E_OPENAI_CHAT_COMPLETIONS_CONTEXT_OVERFLOW = require_batteries_llm_openai_chat_completions_exceptions.E_OPENAI_CHAT_COMPLETIONS_CONTEXT_OVERFLOW;
15
28
  exports.E_OPENAI_CHAT_COMPLETIONS_HTTP_ERROR = require_batteries_llm_openai_chat_completions_exceptions.E_OPENAI_CHAT_COMPLETIONS_HTTP_ERROR;
16
29
  exports.E_OPENAI_CHAT_COMPLETIONS_INVALID_TOOL_CALL_ARGS = require_batteries_llm_openai_chat_completions_exceptions.E_OPENAI_CHAT_COMPLETIONS_INVALID_TOOL_CALL_ARGS;
@@ -20,46 +33,49 @@ exports.E_OPENAI_CHAT_COMPLETIONS_STREAM_STALLED = require_batteries_llm_openai_
20
33
  exports.E_WEBLLM_CHAT_COMPLETIONS_CONTEXT_OVERFLOW = require_batteries_llm_webllm_chat_completions_exceptions.E_WEBLLM_CHAT_COMPLETIONS_CONTEXT_OVERFLOW;
21
34
  exports.E_WEBLLM_CHAT_COMPLETIONS_INVALID_TOOL_CALL_ARGS = require_batteries_llm_webllm_chat_completions_exceptions.E_WEBLLM_CHAT_COMPLETIONS_INVALID_TOOL_CALL_ARGS;
22
35
  exports.E_WEBLLM_CHAT_COMPLETIONS_STREAM_ERROR = require_batteries_llm_webllm_chat_completions_exceptions.E_WEBLLM_CHAT_COMPLETIONS_STREAM_ERROR;
36
+ exports.OllamaAdapter = require_batteries_llm_ollama_adapter.OllamaAdapter;
23
37
  exports.OpenAIChatCompletionsAdapter = require_batteries_llm_openai_chat_completions_adapter.OpenAIChatCompletionsAdapter;
24
38
  exports.WebLLMChatCompletionsAdapter = require_batteries_llm_webllm_chat_completions_adapter.WebLLMChatCompletionsAdapter;
25
39
  exports.buildChatCompletionsHistory = require_batteries_llm_openai_chat_completions_helpers.buildChatCompletionsHistory;
26
40
  exports.createChatCompletionsToolCallDeltaAccumulator = require_batteries_llm_openai_chat_completions_helpers.createChatCompletionsToolCallDeltaAccumulator;
27
41
  exports.defaultBuildChatCompletionsHistory = require_batteries_llm_openai_chat_completions_helpers.defaultBuildChatCompletionsHistory;
28
42
  exports.defaultCreateChatCompletionsToolCallDeltaAccumulator = require_batteries_llm_openai_chat_completions_helpers.defaultCreateChatCompletionsToolCallDeltaAccumulator;
29
- exports.defaultDescriptionToChatCompletionsJsonSchema = require_batteries_llm_openai_chat_completions_helpers.defaultDescriptionToChatCompletionsJsonSchema;
30
- exports.defaultFilterThoughts = require_batteries_llm_openai_chat_completions_helpers.defaultFilterThoughts;
31
- exports.defaultRenderChatCompletionsSystemPrompt = require_batteries_llm_openai_chat_completions_helpers.defaultRenderChatCompletionsSystemPrompt;
43
+ exports.defaultDescriptionToChatCompletionsJsonSchema = require_helpers.defaultDescriptionToChatCompletionsJsonSchema;
44
+ exports.defaultFilterThoughts = require_helpers.defaultFilterThoughts;
45
+ exports.defaultRenderChatCompletionsSystemPrompt = require_helpers.defaultRenderChatCompletionsSystemPrompt;
32
46
  exports.defaultRenderChatCompletionsToolCallResult = require_batteries_llm_openai_chat_completions_helpers.defaultRenderChatCompletionsToolCallResult;
33
- exports.defaultRenderFirstPartyRetrievables = require_batteries_llm_openai_chat_completions_helpers.defaultRenderFirstPartyRetrievables;
34
- exports.defaultRenderMemories = require_batteries_llm_openai_chat_completions_helpers.defaultRenderMemories;
35
- exports.defaultRenderRetrievableSafetyDirective = require_batteries_llm_openai_chat_completions_helpers.defaultRenderRetrievableSafetyDirective;
36
- exports.defaultRenderRetrievables = require_batteries_llm_openai_chat_completions_helpers.defaultRenderRetrievables;
37
- exports.defaultRenderStandingInstructions = require_batteries_llm_openai_chat_completions_helpers.defaultRenderStandingInstructions;
38
- exports.defaultRenderThirdPartyPrivateRetrievables = require_batteries_llm_openai_chat_completions_helpers.defaultRenderThirdPartyPrivateRetrievables;
39
- exports.defaultRenderThirdPartyPublicRetrievables = require_batteries_llm_openai_chat_completions_helpers.defaultRenderThirdPartyPublicRetrievables;
40
- exports.defaultRenderThought = require_batteries_llm_openai_chat_completions_helpers.defaultRenderThought;
47
+ exports.defaultRenderFirstPartyRetrievables = require_helpers.defaultRenderFirstPartyRetrievables;
48
+ exports.defaultRenderMemories = require_helpers.defaultRenderMemories;
49
+ exports.defaultRenderRetrievableSafetyDirective = require_helpers.defaultRenderRetrievableSafetyDirective;
50
+ exports.defaultRenderRetrievables = require_helpers.defaultRenderRetrievables;
51
+ exports.defaultRenderStandingInstructions = require_helpers.defaultRenderStandingInstructions;
52
+ exports.defaultRenderThirdPartyPrivateRetrievables = require_helpers.defaultRenderThirdPartyPrivateRetrievables;
53
+ exports.defaultRenderThirdPartyPublicRetrievables = require_helpers.defaultRenderThirdPartyPublicRetrievables;
54
+ exports.defaultRenderThought = require_helpers.defaultRenderThought;
41
55
  exports.defaultRenderTimelineMessage = require_batteries_llm_openai_chat_completions_helpers.defaultRenderTimelineMessage;
42
- exports.defaultRenderTrustedContent = require_batteries_llm_openai_chat_completions_helpers.defaultRenderTrustedContent;
43
- exports.defaultRenderUntrustedContent = require_batteries_llm_openai_chat_completions_helpers.defaultRenderUntrustedContent;
44
- exports.defaultToolsToChatCompletionsTools = require_batteries_llm_openai_chat_completions_helpers.defaultToolsToChatCompletionsTools;
45
- exports.descriptionToChatCompletionsJsonSchema = require_batteries_llm_openai_chat_completions_helpers.descriptionToChatCompletionsJsonSchema;
56
+ exports.defaultRenderTrustedContent = require_helpers.defaultRenderTrustedContent;
57
+ exports.defaultRenderUntrustedContent = require_helpers.defaultRenderUntrustedContent;
58
+ exports.defaultToolsToChatCompletionsTools = require_helpers.defaultToolsToChatCompletionsTools;
59
+ exports.descriptionToChatCompletionsJsonSchema = require_helpers.descriptionToChatCompletionsJsonSchema;
46
60
  exports.extractReasoningFields = require_batteries_llm_openai_chat_completions_helpers.extractReasoningFields;
47
- exports.filterThoughts = require_batteries_llm_openai_chat_completions_helpers.filterThoughts;
61
+ exports.filterThoughts = require_helpers.filterThoughts;
62
+ exports.ollamaOptionsSchema = require_batteries_llm_ollama_validation.ollamaOptionsSchema;
48
63
  exports.openAIChatCompletionsOptionsSchema = require_batteries_llm_openai_chat_completions_validation.openAIChatCompletionsOptionsSchema;
49
- exports.renderChatCompletionsSystemPrompt = require_batteries_llm_openai_chat_completions_helpers.renderChatCompletionsSystemPrompt;
64
+ exports.renderChatCompletionsSystemPrompt = require_helpers.renderChatCompletionsSystemPrompt;
50
65
  exports.renderChatCompletionsToolCallResult = require_batteries_llm_openai_chat_completions_helpers.renderChatCompletionsToolCallResult;
51
- exports.renderFirstPartyRetrievables = require_batteries_llm_openai_chat_completions_helpers.renderFirstPartyRetrievables;
52
- exports.renderMemories = require_batteries_llm_openai_chat_completions_helpers.renderMemories;
53
- exports.renderRetrievableSafetyDirective = require_batteries_llm_openai_chat_completions_helpers.renderRetrievableSafetyDirective;
54
- exports.renderRetrievables = require_batteries_llm_openai_chat_completions_helpers.renderRetrievables;
55
- exports.renderStandingInstructions = require_batteries_llm_openai_chat_completions_helpers.renderStandingInstructions;
56
- exports.renderThirdPartyPrivateRetrievables = require_batteries_llm_openai_chat_completions_helpers.renderThirdPartyPrivateRetrievables;
57
- exports.renderThirdPartyPublicRetrievables = require_batteries_llm_openai_chat_completions_helpers.renderThirdPartyPublicRetrievables;
58
- exports.renderThought = require_batteries_llm_openai_chat_completions_helpers.renderThought;
66
+ exports.renderFirstPartyRetrievables = require_helpers.renderFirstPartyRetrievables;
67
+ exports.renderMemories = require_helpers.renderMemories;
68
+ exports.renderRetrievableSafetyDirective = require_helpers.renderRetrievableSafetyDirective;
69
+ exports.renderRetrievables = require_helpers.renderRetrievables;
70
+ exports.renderStandingInstructions = require_helpers.renderStandingInstructions;
71
+ exports.renderThirdPartyPrivateRetrievables = require_helpers.renderThirdPartyPrivateRetrievables;
72
+ exports.renderThirdPartyPublicRetrievables = require_helpers.renderThirdPartyPublicRetrievables;
73
+ exports.renderThought = require_helpers.renderThought;
59
74
  exports.renderTimelineMessage = require_batteries_llm_openai_chat_completions_helpers.renderTimelineMessage;
60
- exports.renderTrustedContent = require_batteries_llm_openai_chat_completions_helpers.renderTrustedContent;
61
- exports.renderUntrustedContent = require_batteries_llm_openai_chat_completions_helpers.renderUntrustedContent;
62
- exports.toolsToChatCompletionsTools = require_batteries_llm_openai_chat_completions_helpers.toolsToChatCompletionsTools;
75
+ exports.renderTrustedContent = require_helpers.renderTrustedContent;
76
+ exports.renderUntrustedContent = require_helpers.renderUntrustedContent;
77
+ exports.toolsToChatCompletionsTools = require_helpers.toolsToChatCompletionsTools;
78
+ exports.validateOllamaOptions = require_batteries_llm_ollama_validation.validateOptions;
63
79
  exports.validateOptions = require_batteries_llm_openai_chat_completions_validation.validateOptions;
64
80
  exports.validateWebLLMChatCompletionsOptions = require_batteries_llm_webllm_chat_completions_validation.validateOptions;
65
81
  exports.webLLMChatCompletionsOptionsSchema = require_batteries_llm_webllm_chat_completions_validation.webLLMChatCompletionsOptionsSchema;
package/batteries/llm.mjs CHANGED
@@ -1,10 +1,15 @@
1
1
  import { E_INVALID_OPENAI_CHAT_COMPLETIONS_OPTIONS, E_OPENAI_CHAT_COMPLETIONS_CONTEXT_OVERFLOW, E_OPENAI_CHAT_COMPLETIONS_HTTP_ERROR, E_OPENAI_CHAT_COMPLETIONS_INVALID_TOOL_CALL_ARGS, E_OPENAI_CHAT_COMPLETIONS_REQUEST_TIMEOUT, E_OPENAI_CHAT_COMPLETIONS_STREAM_ERROR, E_OPENAI_CHAT_COMPLETIONS_STREAM_STALLED } from "./llm/openai_chat_completions/exceptions.mjs";
2
- import { openAIChatCompletionsOptionsSchema, validateOptions } from "./llm/openai_chat_completions/validation.mjs";
3
- import { buildChatCompletionsHistory, createChatCompletionsToolCallDeltaAccumulator, defaultBuildChatCompletionsHistory, defaultCreateChatCompletionsToolCallDeltaAccumulator, defaultDescriptionToChatCompletionsJsonSchema, defaultFilterThoughts, defaultRenderChatCompletionsSystemPrompt, defaultRenderChatCompletionsToolCallResult, defaultRenderFirstPartyRetrievables, defaultRenderMemories, defaultRenderRetrievableSafetyDirective, defaultRenderRetrievables, defaultRenderStandingInstructions, defaultRenderThirdPartyPrivateRetrievables, defaultRenderThirdPartyPublicRetrievables, defaultRenderThought, defaultRenderTimelineMessage, defaultRenderTrustedContent, defaultRenderUntrustedContent, defaultToolsToChatCompletionsTools, descriptionToChatCompletionsJsonSchema, extractReasoningFields, filterThoughts, renderChatCompletionsSystemPrompt, renderChatCompletionsToolCallResult, renderFirstPartyRetrievables, renderMemories, renderRetrievableSafetyDirective, renderRetrievables, renderStandingInstructions, renderThirdPartyPrivateRetrievables, renderThirdPartyPublicRetrievables, renderThought, renderTimelineMessage, renderTrustedContent, renderUntrustedContent, toolsToChatCompletionsTools } from "./llm/openai_chat_completions/helpers.mjs";
2
+ import { openAIChatCompletionsOptionsSchema, validateOptions as validateOptions$1 } from "./llm/openai_chat_completions/validation.mjs";
3
+ import { C as renderRetrievables, D as renderThought, E as renderThirdPartyPublicRetrievables, M as toolsToChatCompletionsTools, O as renderTrustedContent, S as renderRetrievableSafetyDirective, T as renderThirdPartyPrivateRetrievables, _ as filterThoughts, a as defaultRenderMemories, b as renderFirstPartyRetrievables, c as defaultRenderStandingInstructions, d as defaultRenderThought, f as defaultRenderTrustedContent, h as descriptionToChatCompletionsJsonSchema, i as defaultRenderFirstPartyRetrievables, k as renderUntrustedContent, 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, w as renderStandingInstructions, x as renderMemories, y as renderChatCompletionsSystemPrompt } from "../helpers-xhrQbMAG.mjs";
4
+ import { buildChatCompletionsHistory, createChatCompletionsToolCallDeltaAccumulator, defaultBuildChatCompletionsHistory, defaultCreateChatCompletionsToolCallDeltaAccumulator, defaultRenderChatCompletionsToolCallResult, defaultRenderTimelineMessage, extractReasoningFields, renderChatCompletionsToolCallResult, renderTimelineMessage } from "./llm/openai_chat_completions/helpers.mjs";
4
5
  import { OpenAIChatCompletionsAdapter } from "./llm/openai_chat_completions/adapter.mjs";
5
6
  import "./llm/openai_chat_completions.mjs";
6
7
  import { E_INVALID_WEBLLM_CHAT_COMPLETIONS_OPTIONS, E_WEBLLM_CHAT_COMPLETIONS_CONTEXT_OVERFLOW, E_WEBLLM_CHAT_COMPLETIONS_INVALID_TOOL_CALL_ARGS, E_WEBLLM_CHAT_COMPLETIONS_STREAM_ERROR } from "./llm/webllm_chat_completions/exceptions.mjs";
7
- import { validateOptions as validateOptions$1, webLLMChatCompletionsOptionsSchema } from "./llm/webllm_chat_completions/validation.mjs";
8
+ import { validateOptions as validateOptions$2, webLLMChatCompletionsOptionsSchema } from "./llm/webllm_chat_completions/validation.mjs";
8
9
  import { WebLLMChatCompletionsAdapter } from "./llm/webllm_chat_completions/adapter.mjs";
9
10
  import "./llm/webllm_chat_completions.mjs";
10
- export { E_INVALID_OPENAI_CHAT_COMPLETIONS_OPTIONS, E_INVALID_WEBLLM_CHAT_COMPLETIONS_OPTIONS, E_OPENAI_CHAT_COMPLETIONS_CONTEXT_OVERFLOW, E_OPENAI_CHAT_COMPLETIONS_HTTP_ERROR, E_OPENAI_CHAT_COMPLETIONS_INVALID_TOOL_CALL_ARGS, E_OPENAI_CHAT_COMPLETIONS_REQUEST_TIMEOUT, E_OPENAI_CHAT_COMPLETIONS_STREAM_ERROR, E_OPENAI_CHAT_COMPLETIONS_STREAM_STALLED, E_WEBLLM_CHAT_COMPLETIONS_CONTEXT_OVERFLOW, E_WEBLLM_CHAT_COMPLETIONS_INVALID_TOOL_CALL_ARGS, E_WEBLLM_CHAT_COMPLETIONS_STREAM_ERROR, OpenAIChatCompletionsAdapter, WebLLMChatCompletionsAdapter, buildChatCompletionsHistory, createChatCompletionsToolCallDeltaAccumulator, defaultBuildChatCompletionsHistory, defaultCreateChatCompletionsToolCallDeltaAccumulator, defaultDescriptionToChatCompletionsJsonSchema, defaultFilterThoughts, defaultRenderChatCompletionsSystemPrompt, defaultRenderChatCompletionsToolCallResult, defaultRenderFirstPartyRetrievables, defaultRenderMemories, defaultRenderRetrievableSafetyDirective, defaultRenderRetrievables, defaultRenderStandingInstructions, defaultRenderThirdPartyPrivateRetrievables, defaultRenderThirdPartyPublicRetrievables, defaultRenderThought, defaultRenderTimelineMessage, defaultRenderTrustedContent, defaultRenderUntrustedContent, defaultToolsToChatCompletionsTools, descriptionToChatCompletionsJsonSchema, extractReasoningFields, filterThoughts, openAIChatCompletionsOptionsSchema, renderChatCompletionsSystemPrompt, renderChatCompletionsToolCallResult, renderFirstPartyRetrievables, renderMemories, renderRetrievableSafetyDirective, renderRetrievables, renderStandingInstructions, renderThirdPartyPrivateRetrievables, renderThirdPartyPublicRetrievables, renderThought, renderTimelineMessage, renderTrustedContent, renderUntrustedContent, toolsToChatCompletionsTools, validateOptions, validateOptions$1 as validateWebLLMChatCompletionsOptions, webLLMChatCompletionsOptionsSchema };
11
+ 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, E_OLLAMA_UNSUPPORTED_MEDIA_MODALITY } from "./llm/ollama/exceptions.mjs";
12
+ import { ollamaOptionsSchema, validateOptions } from "./llm/ollama/validation.mjs";
13
+ import { OllamaAdapter } from "./llm/ollama/adapter.mjs";
14
+ import "./llm/ollama.mjs";
15
+ export { E_INVALID_OLLAMA_OPTIONS, E_INVALID_OPENAI_CHAT_COMPLETIONS_OPTIONS, E_INVALID_WEBLLM_CHAT_COMPLETIONS_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, E_OLLAMA_UNSUPPORTED_MEDIA_MODALITY, E_OPENAI_CHAT_COMPLETIONS_CONTEXT_OVERFLOW, E_OPENAI_CHAT_COMPLETIONS_HTTP_ERROR, E_OPENAI_CHAT_COMPLETIONS_INVALID_TOOL_CALL_ARGS, E_OPENAI_CHAT_COMPLETIONS_REQUEST_TIMEOUT, E_OPENAI_CHAT_COMPLETIONS_STREAM_ERROR, E_OPENAI_CHAT_COMPLETIONS_STREAM_STALLED, E_WEBLLM_CHAT_COMPLETIONS_CONTEXT_OVERFLOW, E_WEBLLM_CHAT_COMPLETIONS_INVALID_TOOL_CALL_ARGS, E_WEBLLM_CHAT_COMPLETIONS_STREAM_ERROR, OllamaAdapter, OpenAIChatCompletionsAdapter, WebLLMChatCompletionsAdapter, buildChatCompletionsHistory, createChatCompletionsToolCallDeltaAccumulator, defaultBuildChatCompletionsHistory, defaultCreateChatCompletionsToolCallDeltaAccumulator, defaultDescriptionToChatCompletionsJsonSchema, defaultFilterThoughts, defaultRenderChatCompletionsSystemPrompt, defaultRenderChatCompletionsToolCallResult, defaultRenderFirstPartyRetrievables, defaultRenderMemories, defaultRenderRetrievableSafetyDirective, defaultRenderRetrievables, defaultRenderStandingInstructions, defaultRenderThirdPartyPrivateRetrievables, defaultRenderThirdPartyPublicRetrievables, defaultRenderThought, defaultRenderTimelineMessage, defaultRenderTrustedContent, defaultRenderUntrustedContent, defaultToolsToChatCompletionsTools, descriptionToChatCompletionsJsonSchema, extractReasoningFields, filterThoughts, ollamaOptionsSchema, openAIChatCompletionsOptionsSchema, renderChatCompletionsSystemPrompt, renderChatCompletionsToolCallResult, renderFirstPartyRetrievables, renderMemories, renderRetrievableSafetyDirective, renderRetrievables, renderStandingInstructions, renderThirdPartyPrivateRetrievables, renderThirdPartyPublicRetrievables, renderThought, renderTimelineMessage, renderTrustedContent, renderUntrustedContent, toolsToChatCompletionsTools, validateOptions as validateOllamaOptions, validateOptions$1 as validateOptions, validateOptions$2 as validateWebLLMChatCompletionsOptions, webLLMChatCompletionsOptionsSchema };
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_chunk = require("../../chunk-Ble4zEEl.js");
3
- const require_tool_registry = require("../../tool_registry-DYUYqXvo.js");
3
+ const require_tool_registry = require("../../tool_registry-CKJPze3j.js");
4
4
  require("../../guards.cjs");
5
5
  //#endregion
6
6
  //#region src/batteries/storage/flydrive/index.ts
@@ -1,5 +1,5 @@
1
1
  import { t as __commonJSMin } from "../../chunk-Bpcn9VDT.mjs";
2
- import { s as isInstanceOf } from "../../tool_registry-D1pSSlsd.mjs";
2
+ import { s as isInstanceOf } from "../../tool_registry-791Vrjtf.mjs";
3
3
  import "../../guards.mjs";
4
4
  //#endregion
5
5
  //#region src/batteries/storage/flydrive/index.ts
@@ -59,7 +59,7 @@ export declare class InMemorySpoolReader implements SpoolReader {
59
59
  * owns the bytes, the reader is a view. Mutating the store after handing out a reader does not
60
60
  * invalidate the reader.
61
61
  *
62
- * Implements {@link @nhtio/adk!SpoolStore} (i.e. `ByteStore<SpoolReader>`).
62
+ * Implements {@link @nhtio/adk/common!SpoolStore} (i.e. `ByteStore<SpoolReader>`).
63
63
  *
64
64
  * @example
65
65
  * ```ts
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("../../chunk-Ble4zEEl.js");
3
- const require_tool_registry = require("../../tool_registry-DYUYqXvo.js");
3
+ const require_tool_registry = require("../../tool_registry-CKJPze3j.js");
4
4
  require("../../guards.cjs");
5
5
  //#region src/batteries/storage/in_memory/index.ts
6
6
  /**
@@ -114,7 +114,7 @@ var drainStream = async (stream) => {
114
114
  * owns the bytes, the reader is a view. Mutating the store after handing out a reader does not
115
115
  * invalidate the reader.
116
116
  *
117
- * Implements {@link @nhtio/adk!SpoolStore} (i.e. `ByteStore<SpoolReader>`).
117
+ * Implements {@link @nhtio/adk/common!SpoolStore} (i.e. `ByteStore<SpoolReader>`).
118
118
  *
119
119
  * @example
120
120
  * ```ts
@@ -1 +1 @@
1
- {"version":3,"file":"in_memory.cjs","names":["#content","#lines","#bytes","#entries"],"sources":["../../../src/batteries/storage/in_memory/index.ts"],"sourcesContent":["/**\n * In-memory spool readers and stores for tests, scripts, and non-durable prototypes.\n *\n * @module @nhtio/adk/batteries/storage/in_memory\n *\n * @remarks\n * Opt-in in-memory persistence battery. Provides {@link InMemorySpoolReader} (a sync\n * {@link @nhtio/adk!SpoolReader} over a string) plus {@link InMemorySpoolStore} (a `Map<callId, bytes>`\n * with a `write()` method that returns a fresh reader bound to the stored bytes).\n *\n * Use this when:\n *\n * - Writing unit or functional tests that need a real `SpoolReader` over known bytes.\n * - Running a REPL or one-shot script where persistence beyond the process lifetime is not\n * needed.\n * - Prototyping an agent before deciding on a real disk/object-store-backed persistence layer.\n *\n * Do **not** use this for production agents that need durability across process restarts —\n * everything lives in process memory and is lost on exit.\n */\n\nimport { isInstanceOf } from '@nhtio/adk/guards'\nimport type { SpoolReader, SpoolStore } from '@nhtio/adk/common'\n\n/**\n * Sync in-memory {@link @nhtio/adk!SpoolReader} over a byte-faithful `Uint8Array` body.\n *\n * @remarks\n * Stores the raw bytes and decodes them as UTF-8 once at construction, then splits the decoded\n * string on `\\n` and caches the resulting line array. All four `SpoolReader` methods resolve\n * synchronously from the cache — no I/O happens after construction. `byteLength()` reports the\n * true stored byte count (not the decoded character count), so it stays correct for multi-byte\n * content; `line()`/`readAll()` operate on the decoded text.\n *\n * The reader accepts a `string` or a `Uint8Array`. A `string` is encoded as UTF-8 for the byte\n * count; a `Uint8Array` is held byte-faithfully (no lossy re-encode) and decoded for text reads.\n *\n * Empty input yields a reader with `lineCount() === 0` and `byteLength() === 0`. A trailing\n * newline produces a final empty line: `\"a\\nb\\n\".split('\\n') === ['a', 'b', '']`. This matches\n * the JavaScript `String.prototype.split` contract and lets a `lineCount()` consumer\n * distinguish \"two lines, no trailing newline\" from \"two lines, trailing newline\".\n */\nexport class InMemorySpoolReader implements SpoolReader {\n readonly #content: string\n readonly #lines: string[]\n readonly #bytes: number\n\n constructor(content: string | Uint8Array) {\n if (typeof content === 'string') {\n this.#content = content\n this.#bytes = new TextEncoder().encode(content).length\n } else {\n this.#content = new TextDecoder().decode(content)\n this.#bytes = content.byteLength\n }\n this.#lines = this.#content === '' ? [] : this.#content.split('\\n')\n }\n\n line(index: number): string | undefined {\n return this.#lines[index]\n }\n\n byteLength(): number {\n return this.#bytes\n }\n\n lineCount(): number {\n return this.#lines.length\n }\n\n readAll(): string {\n return this.#content\n }\n}\n\n/**\n * Drains a `ReadableStream<Uint8Array>` into a single concatenated `Uint8Array`.\n *\n * @remarks\n * In-memory storage cannot stream-to-disk, so a stream input is buffered fully — the documented\n * trade-off for {@link InMemorySpoolStore}. Use {@link @nhtio/adk/batteries/storage/opfs!OpfsSpoolStore}\n * or a Flydrive-backed store when true streaming persistence is required.\n */\nconst drainStream = async (stream: ReadableStream<Uint8Array>): Promise<Uint8Array> => {\n const chunks: Uint8Array[] = []\n let total = 0\n const reader = stream.getReader()\n try {\n for (;;) {\n const { done, value } = await reader.read()\n if (done) break\n if (value) {\n chunks.push(value)\n total += value.byteLength\n }\n }\n } finally {\n reader.releaseLock()\n }\n const out = new Uint8Array(total)\n let offset = 0\n for (const chunk of chunks) {\n out.set(chunk, offset)\n offset += chunk.byteLength\n }\n return out\n}\n\n/**\n * In-memory \"give bytes, get a reader\" persistence layer keyed by `callId`.\n *\n * @remarks\n * Stores each value byte-faithfully as a `Uint8Array`. `string` inputs are encoded as UTF-8;\n * `Uint8Array` inputs are held verbatim (no lossy text round-trip, so binary payloads survive\n * intact); `ReadableStream<Uint8Array>` inputs are drained fully into a buffer — in-memory storage\n * cannot stream to disk, so the stream form resolves asynchronously and is the documented\n * trade-off for this battery.\n *\n * Each `write()` and each `read()` returns a *fresh* {@link InMemorySpoolReader} — the store\n * owns the bytes, the reader is a view. Mutating the store after handing out a reader does not\n * invalidate the reader.\n *\n * Implements {@link @nhtio/adk!SpoolStore} (i.e. `ByteStore<SpoolReader>`).\n *\n * @example\n * ```ts\n * const store = new InMemorySpoolStore()\n * const bytes = await tool.executor(ctx)(args)\n * const reader = await store.write(callId, bytes)\n * const Ctor = tool.artifactConstructor?.() ?? SpooledArtifact\n * const artifact = new Ctor(reader)\n * ```\n */\nexport class InMemorySpoolStore implements SpoolStore {\n readonly #entries = new Map<string, Uint8Array>()\n\n /**\n * Persists `bytes` under `callId` and returns a reader over them.\n *\n * @remarks\n * `string` input is encoded as UTF-8; `Uint8Array` is stored byte-faithfully;\n * `ReadableStream<Uint8Array>` is drained fully (and `write` returns a `Promise`). Re-writing the\n * same `callId` replaces the prior entry; readers handed out before the rewrite continue to view\n * the old bytes (they hold their own snapshot via the `InMemorySpoolReader` constructor).\n *\n * @param callId - Identifier used to retrieve the bytes via {@link InMemorySpoolStore.read}.\n * @param bytes - The bytes to store, as a `string`, `Uint8Array`, or `ReadableStream<Uint8Array>`.\n * @returns A fresh {@link InMemorySpoolReader} bound to the stored bytes — a `Promise` for stream\n * input, synchronous otherwise.\n */\n write(callId: string, bytes: string): InMemorySpoolReader\n write(callId: string, bytes: Uint8Array): InMemorySpoolReader\n write(callId: string, bytes: ReadableStream<Uint8Array>): Promise<InMemorySpoolReader>\n write(\n callId: string,\n bytes: string | Uint8Array | ReadableStream<Uint8Array>\n ): InMemorySpoolReader | Promise<InMemorySpoolReader>\n write(\n callId: string,\n bytes: string | Uint8Array | ReadableStream<Uint8Array>\n ): InMemorySpoolReader | Promise<InMemorySpoolReader> {\n if (isInstanceOf(bytes, 'ReadableStream', ReadableStream)) {\n return drainStream(bytes).then((buffer) => {\n this.#entries.set(callId, buffer)\n return new InMemorySpoolReader(buffer)\n })\n }\n const buffer = typeof bytes === 'string' ? new TextEncoder().encode(bytes) : bytes\n this.#entries.set(callId, buffer)\n return new InMemorySpoolReader(buffer)\n }\n\n /**\n * Returns a reader over the bytes previously written under `callId`, or `undefined` if the\n * entry has not been written or has been deleted.\n *\n * @param callId - Identifier supplied to a prior {@link InMemorySpoolStore.write} call.\n * @returns A fresh {@link InMemorySpoolReader} bound to the stored bytes, or `undefined`.\n */\n read(callId: string): InMemorySpoolReader | undefined {\n const buffer = this.#entries.get(callId)\n if (buffer === undefined) return undefined\n return new InMemorySpoolReader(buffer)\n }\n\n /**\n * Removes the entry under `callId`.\n *\n * @param callId - Identifier whose entry should be removed.\n * @returns `true` if an entry existed and was removed; `false` otherwise.\n */\n delete(callId: string): boolean {\n return this.#entries.delete(callId)\n }\n\n /**\n * Removes every entry from the store.\n *\n * @remarks\n * Existing readers handed out by prior `write()` / `read()` calls remain valid — they hold\n * their own snapshot.\n */\n clear(): void {\n this.#entries.clear()\n }\n\n /**\n * Returns the number of entries currently in the store.\n */\n get size(): number {\n return this.#entries.size\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,IAAa,sBAAb,MAAwD;CACtD;CACA;CACA;CAEA,YAAY,SAA8B;EACxC,IAAI,OAAO,YAAY,UAAU;GAC/B,KAAKA,WAAW;GAChB,KAAKE,SAAS,IAAI,YAAY,EAAE,OAAO,OAAO,EAAE;EAClD,OAAO;GACL,KAAKF,WAAW,IAAI,YAAY,EAAE,OAAO,OAAO;GAChD,KAAKE,SAAS,QAAQ;EACxB;EACA,KAAKD,SAAS,KAAKD,aAAa,KAAK,CAAC,IAAI,KAAKA,SAAS,MAAM,IAAI;CACpE;CAEA,KAAK,OAAmC;EACtC,OAAO,KAAKC,OAAO;C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AAM;CACpC;;;;;;;;CASA,QAAc;EACZ,KAAKA,SAAS,MAAM;CACtB;;;;CAKA,IAAI,OAAe;EACjB,OAAO,KAAKA,SAAS;CACvB;AACF"}
1
+ {"version":3,"file":"in_memory.cjs","names":["#content","#lines","#bytes","#entries"],"sources":["../../../src/batteries/storage/in_memory/index.ts"],"sourcesContent":["/**\n * In-memory spool readers and stores for tests, scripts, and non-durable prototypes.\n *\n * @module @nhtio/adk/batteries/storage/in_memory\n *\n * @remarks\n * Opt-in in-memory persistence battery. Provides {@link InMemorySpoolReader} (a sync\n * {@link @nhtio/adk!SpoolReader} over a string) plus {@link InMemorySpoolStore} (a `Map<callId, bytes>`\n * with a `write()` method that returns a fresh reader bound to the stored bytes).\n *\n * Use this when:\n *\n * - Writing unit or functional tests that need a real `SpoolReader` over known bytes.\n * - Running a REPL or one-shot script where persistence beyond the process lifetime is not\n * needed.\n * - Prototyping an agent before deciding on a real disk/object-store-backed persistence layer.\n *\n * Do **not** use this for production agents that need durability across process restarts —\n * everything lives in process memory and is lost on exit.\n */\n\nimport { isInstanceOf } from '@nhtio/adk/guards'\nimport type { SpoolReader, SpoolStore } from '@nhtio/adk/common'\n\n/**\n * Sync in-memory {@link @nhtio/adk!SpoolReader} over a byte-faithful `Uint8Array` body.\n *\n * @remarks\n * Stores the raw bytes and decodes them as UTF-8 once at construction, then splits the decoded\n * string on `\\n` and caches the resulting line array. All four `SpoolReader` methods resolve\n * synchronously from the cache — no I/O happens after construction. `byteLength()` reports the\n * true stored byte count (not the decoded character count), so it stays correct for multi-byte\n * content; `line()`/`readAll()` operate on the decoded text.\n *\n * The reader accepts a `string` or a `Uint8Array`. A `string` is encoded as UTF-8 for the byte\n * count; a `Uint8Array` is held byte-faithfully (no lossy re-encode) and decoded for text reads.\n *\n * Empty input yields a reader with `lineCount() === 0` and `byteLength() === 0`. A trailing\n * newline produces a final empty line: `\"a\\nb\\n\".split('\\n') === ['a', 'b', '']`. This matches\n * the JavaScript `String.prototype.split` contract and lets a `lineCount()` consumer\n * distinguish \"two lines, no trailing newline\" from \"two lines, trailing newline\".\n */\nexport class InMemorySpoolReader implements SpoolReader {\n readonly #content: string\n readonly #lines: string[]\n readonly #bytes: number\n\n constructor(content: string | Uint8Array) {\n if (typeof content === 'string') {\n this.#content = content\n this.#bytes = new TextEncoder().encode(content).length\n } else {\n this.#content = new TextDecoder().decode(content)\n this.#bytes = content.byteLength\n }\n this.#lines = this.#content === '' ? [] : this.#content.split('\\n')\n }\n\n line(index: number): string | undefined {\n return this.#lines[index]\n }\n\n byteLength(): number {\n return this.#bytes\n }\n\n lineCount(): number {\n return this.#lines.length\n }\n\n readAll(): string {\n return this.#content\n }\n}\n\n/**\n * Drains a `ReadableStream<Uint8Array>` into a single concatenated `Uint8Array`.\n *\n * @remarks\n * In-memory storage cannot stream-to-disk, so a stream input is buffered fully — the documented\n * trade-off for {@link InMemorySpoolStore}. Use {@link @nhtio/adk/batteries/storage/opfs!OpfsSpoolStore}\n * or a Flydrive-backed store when true streaming persistence is required.\n */\nconst drainStream = async (stream: ReadableStream<Uint8Array>): Promise<Uint8Array> => {\n const chunks: Uint8Array[] = []\n let total = 0\n const reader = stream.getReader()\n try {\n for (;;) {\n const { done, value } = await reader.read()\n if (done) break\n if (value) {\n chunks.push(value)\n total += value.byteLength\n }\n }\n } finally {\n reader.releaseLock()\n }\n const out = new Uint8Array(total)\n let offset = 0\n for (const chunk of chunks) {\n out.set(chunk, offset)\n offset += chunk.byteLength\n }\n return out\n}\n\n/**\n * In-memory \"give bytes, get a reader\" persistence layer keyed by `callId`.\n *\n * @remarks\n * Stores each value byte-faithfully as a `Uint8Array`. `string` inputs are encoded as UTF-8;\n * `Uint8Array` inputs are held verbatim (no lossy text round-trip, so binary payloads survive\n * intact); `ReadableStream<Uint8Array>` inputs are drained fully into a buffer — in-memory storage\n * cannot stream to disk, so the stream form resolves asynchronously and is the documented\n * trade-off for this battery.\n *\n * Each `write()` and each `read()` returns a *fresh* {@link InMemorySpoolReader} — the store\n * owns the bytes, the reader is a view. Mutating the store after handing out a reader does not\n * invalidate the reader.\n *\n * Implements {@link @nhtio/adk/common!SpoolStore} (i.e. `ByteStore<SpoolReader>`).\n *\n * @example\n * ```ts\n * const store = new InMemorySpoolStore()\n * const bytes = await tool.executor(ctx)(args)\n * const reader = await store.write(callId, bytes)\n * const Ctor = tool.artifactConstructor?.() ?? SpooledArtifact\n * const artifact = new Ctor(reader)\n * ```\n */\nexport class InMemorySpoolStore implements SpoolStore {\n readonly #entries = new Map<string, Uint8Array>()\n\n /**\n * Persists `bytes` under `callId` and returns a reader over them.\n *\n * @remarks\n * `string` input is encoded as UTF-8; `Uint8Array` is stored byte-faithfully;\n * `ReadableStream<Uint8Array>` is drained fully (and `write` returns a `Promise`). Re-writing the\n * same `callId` replaces the prior entry; readers handed out before the rewrite continue to view\n * the old bytes (they hold their own snapshot via the `InMemorySpoolReader` constructor).\n *\n * @param callId - Identifier used to retrieve the bytes via {@link InMemorySpoolStore.read}.\n * @param bytes - The bytes to store, as a `string`, `Uint8Array`, or `ReadableStream<Uint8Array>`.\n * @returns A fresh {@link InMemorySpoolReader} bound to the stored bytes — a `Promise` for stream\n * input, synchronous otherwise.\n */\n write(callId: string, bytes: string): InMemorySpoolReader\n write(callId: string, bytes: Uint8Array): InMemorySpoolReader\n write(callId: string, bytes: ReadableStream<Uint8Array>): Promise<InMemorySpoolReader>\n write(\n callId: string,\n bytes: string | Uint8Array | ReadableStream<Uint8Array>\n ): InMemorySpoolReader | Promise<InMemorySpoolReader>\n write(\n callId: string,\n bytes: string | Uint8Array | ReadableStream<Uint8Array>\n ): InMemorySpoolReader | Promise<InMemorySpoolReader> {\n if (isInstanceOf(bytes, 'ReadableStream', ReadableStream)) {\n return drainStream(bytes).then((buffer) => {\n this.#entries.set(callId, buffer)\n return new InMemorySpoolReader(buffer)\n })\n }\n const buffer = typeof bytes === 'string' ? new TextEncoder().encode(bytes) : bytes\n this.#entries.set(callId, buffer)\n return new InMemorySpoolReader(buffer)\n }\n\n /**\n * Returns a reader over the bytes previously written under `callId`, or `undefined` if the\n * entry has not been written or has been deleted.\n *\n * @param callId - Identifier supplied to a prior {@link InMemorySpoolStore.write} call.\n * @returns A fresh {@link InMemorySpoolReader} bound to the stored bytes, or `undefined`.\n */\n read(callId: string): InMemorySpoolReader | undefined {\n const buffer = this.#entries.get(callId)\n if (buffer === undefined) return undefined\n return new InMemorySpoolReader(buffer)\n }\n\n /**\n * Removes the entry under `callId`.\n *\n * @param callId - Identifier whose entry should be removed.\n * @returns `true` if an entry existed and was removed; `false` otherwise.\n */\n delete(callId: string): boolean {\n return this.#entries.delete(callId)\n }\n\n /**\n * Removes every entry from the store.\n *\n * @remarks\n * Existing readers handed out by prior `write()` / `read()` calls remain valid — they hold\n * their own snapshot.\n */\n clear(): void {\n this.#entries.clear()\n }\n\n /**\n * Returns the number of entries currently in the store.\n */\n get size(): number {\n return this.#entries.size\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,IAAa,sBAAb,MAAwD;CACtD;CACA;CACA;CAEA,YAAY,SAA8B;EACxC,IAAI,OAAO,YAAY,UAAU;GAC/B,KAAKA,WAAW;GAChB,KAAKE,SAAS,IAAI,YAAY,EAAE,OAAO,OAAO,EAAE;EAClD,OAAO;GACL,KAAKF,WAAW,IAAI,YAAY,EAAE,OAAO,OAAO;GAChD,KAAKE,SAAS,QAAQ;EACxB;EACA,KAAKD,SAAS,KAAKD,aAAa,KAAK,CAAC,IAAI,KAAKA,SAAS,MAAM,IAAI;CACpE;CAEA,KAAK,OAAmC;EACtC,OAAO,KAAKC,OAAO;CACrB;CAEA,aAAqB;EACnB,OAAO,KAAKC;CACd;CAEA,YAAoB;EAClB,OAAO,KAAKD,OAAO;CACrB;CAEA,UAAkB;EAChB,OAAO,KAAKD;CACd;AACF;;;;;;;;;AAUA,IAAM,cAAc,OAAO,WAA4D;CACrF,MAAM,SAAuB,CAAC;CAC9B,IA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f } from "../../tool_registry-791Vrjtf.mjs";
2
2
  import "../../guards.mjs";
3
3
  //#region src/batteries/storage/in_memory/index.ts
4
4
  /**
@@ -112,7 +112,7 @@ var drainStream = async (stream) => {
112
112
  * owns the bytes, the reader is a view. Mutating the store after handing out a reader does not
113
113
  * invalidate the reader.
114
114
  *
115
- * Implements {@link @nhtio/adk!SpoolStore} (i.e. `ByteStore<SpoolReader>`).
115
+ * Implements {@link @nhtio/adk/common!SpoolStore} (i.e. `ByteStore<SpoolReader>`).
116
116
  *
117
117
  * @example
118
118
  * ```ts
@@ -1 +1 @@
1
- {"version":3,"file":"in_memory.mjs","names":["#content","#lines","#bytes","#entries"],"sources":["../../../src/batteries/storage/in_memory/index.ts"],"sourcesContent":["/**\n * In-memory spool readers and stores for tests, scripts, and non-durable prototypes.\n *\n * @module @nhtio/adk/batteries/storage/in_memory\n *\n * @remarks\n * Opt-in in-memory persistence battery. Provides {@link InMemorySpoolReader} (a sync\n * {@link @nhtio/adk!SpoolReader} over a string) plus {@link InMemorySpoolStore} (a `Map<callId, bytes>`\n * with a `write()` method that returns a fresh reader bound to the stored bytes).\n *\n * Use this when:\n *\n * - Writing unit or functional tests that need a real `SpoolReader` over known bytes.\n * - Running a REPL or one-shot script where persistence beyond the process lifetime is not\n * needed.\n * - Prototyping an agent before deciding on a real disk/object-store-backed persistence layer.\n *\n * Do **not** use this for production agents that need durability across process restarts —\n * everything lives in process memory and is lost on exit.\n */\n\nimport { isInstanceOf } from '@nhtio/adk/guards'\nimport type { SpoolReader, SpoolStore } from '@nhtio/adk/common'\n\n/**\n * Sync in-memory {@link @nhtio/adk!SpoolReader} over a byte-faithful `Uint8Array` body.\n *\n * @remarks\n * Stores the raw bytes and decodes them as UTF-8 once at construction, then splits the decoded\n * string on `\\n` and caches the resulting line array. All four `SpoolReader` methods resolve\n * synchronously from the cache — no I/O happens after construction. `byteLength()` reports the\n * true stored byte count (not the decoded character count), so it stays correct for multi-byte\n * content; `line()`/`readAll()` operate on the decoded text.\n *\n * The reader accepts a `string` or a `Uint8Array`. A `string` is encoded as UTF-8 for the byte\n * count; a `Uint8Array` is held byte-faithfully (no lossy re-encode) and decoded for text reads.\n *\n * Empty input yields a reader with `lineCount() === 0` and `byteLength() === 0`. A trailing\n * newline produces a final empty line: `\"a\\nb\\n\".split('\\n') === ['a', 'b', '']`. This matches\n * the JavaScript `String.prototype.split` contract and lets a `lineCount()` consumer\n * distinguish \"two lines, no trailing newline\" from \"two lines, trailing newline\".\n */\nexport class InMemorySpoolReader implements SpoolReader {\n readonly #content: string\n readonly #lines: string[]\n readonly #bytes: number\n\n constructor(content: string | Uint8Array) {\n if (typeof content === 'string') {\n this.#content = content\n this.#bytes = new TextEncoder().encode(content).length\n } else {\n this.#content = new TextDecoder().decode(content)\n this.#bytes = content.byteLength\n }\n this.#lines = this.#content === '' ? [] : this.#content.split('\\n')\n }\n\n line(index: number): string | undefined {\n return this.#lines[index]\n }\n\n byteLength(): number {\n return this.#bytes\n }\n\n lineCount(): number {\n return this.#lines.length\n }\n\n readAll(): string {\n return this.#content\n }\n}\n\n/**\n * Drains a `ReadableStream<Uint8Array>` into a single concatenated `Uint8Array`.\n *\n * @remarks\n * In-memory storage cannot stream-to-disk, so a stream input is buffered fully — the documented\n * trade-off for {@link InMemorySpoolStore}. Use {@link @nhtio/adk/batteries/storage/opfs!OpfsSpoolStore}\n * or a Flydrive-backed store when true streaming persistence is required.\n */\nconst drainStream = async (stream: ReadableStream<Uint8Array>): Promise<Uint8Array> => {\n const chunks: Uint8Array[] = []\n let total = 0\n const reader = stream.getReader()\n try {\n for (;;) {\n const { done, value } = await reader.read()\n if (done) break\n if (value) {\n chunks.push(value)\n total += value.byteLength\n }\n }\n } finally {\n reader.releaseLock()\n }\n const out = new Uint8Array(total)\n let offset = 0\n for (const chunk of chunks) {\n out.set(chunk, offset)\n offset += chunk.byteLength\n }\n return out\n}\n\n/**\n * In-memory \"give bytes, get a reader\" persistence layer keyed by `callId`.\n *\n * @remarks\n * Stores each value byte-faithfully as a `Uint8Array`. `string` inputs are encoded as UTF-8;\n * `Uint8Array` inputs are held verbatim (no lossy text round-trip, so binary payloads survive\n * intact); `ReadableStream<Uint8Array>` inputs are drained fully into a buffer — in-memory storage\n * cannot stream to disk, so the stream form resolves asynchronously and is the documented\n * trade-off for this battery.\n *\n * Each `write()` and each `read()` returns a *fresh* {@link InMemorySpoolReader} — the store\n * owns the bytes, the reader is a view. Mutating the store after handing out a reader does not\n * invalidate the reader.\n *\n * Implements {@link @nhtio/adk!SpoolStore} (i.e. `ByteStore<SpoolReader>`).\n *\n * @example\n * ```ts\n * const store = new InMemorySpoolStore()\n * const bytes = await tool.executor(ctx)(args)\n * const reader = await store.write(callId, bytes)\n * const Ctor = tool.artifactConstructor?.() ?? SpooledArtifact\n * const artifact = new Ctor(reader)\n * ```\n */\nexport class InMemorySpoolStore implements SpoolStore {\n readonly #entries = new Map<string, Uint8Array>()\n\n /**\n * Persists `bytes` under `callId` and returns a reader over them.\n *\n * @remarks\n * `string` input is encoded as UTF-8; `Uint8Array` is stored byte-faithfully;\n * `ReadableStream<Uint8Array>` is drained fully (and `write` returns a `Promise`). Re-writing the\n * same `callId` replaces the prior entry; readers handed out before the rewrite continue to view\n * the old bytes (they hold their own snapshot via the `InMemorySpoolReader` constructor).\n *\n * @param callId - Identifier used to retrieve the bytes via {@link InMemorySpoolStore.read}.\n * @param bytes - The bytes to store, as a `string`, `Uint8Array`, or `ReadableStream<Uint8Array>`.\n * @returns A fresh {@link InMemorySpoolReader} bound to the stored bytes — a `Promise` for stream\n * input, synchronous otherwise.\n */\n write(callId: string, bytes: string): InMemorySpoolReader\n write(callId: string, bytes: Uint8Array): InMemorySpoolReader\n write(callId: string, bytes: ReadableStream<Uint8Array>): Promise<InMemorySpoolReader>\n write(\n callId: string,\n bytes: string | Uint8Array | ReadableStream<Uint8Array>\n ): InMemorySpoolReader | Promise<InMemorySpoolReader>\n write(\n callId: string,\n bytes: string | Uint8Array | ReadableStream<Uint8Array>\n ): InMemorySpoolReader | Promise<InMemorySpoolReader> {\n if (isInstanceOf(bytes, 'ReadableStream', ReadableStream)) {\n return drainStream(bytes).then((buffer) => {\n this.#entries.set(callId, buffer)\n return new InMemorySpoolReader(buffer)\n })\n }\n const buffer = typeof bytes === 'string' ? new TextEncoder().encode(bytes) : bytes\n this.#entries.set(callId, buffer)\n return new InMemorySpoolReader(buffer)\n }\n\n /**\n * Returns a reader over the bytes previously written under `callId`, or `undefined` if the\n * entry has not been written or has been deleted.\n *\n * @param callId - Identifier supplied to a prior {@link InMemorySpoolStore.write} call.\n * @returns A fresh {@link InMemorySpoolReader} bound to the stored bytes, or `undefined`.\n */\n read(callId: string): InMemorySpoolReader | undefined {\n const buffer = this.#entries.get(callId)\n if (buffer === undefined) return undefined\n return new InMemorySpoolReader(buffer)\n }\n\n /**\n * Removes the entry under `callId`.\n *\n * @param callId - Identifier whose entry should be removed.\n * @returns `true` if an entry existed and was removed; `false` otherwise.\n */\n delete(callId: string): boolean {\n return this.#entries.delete(callId)\n }\n\n /**\n * Removes every entry from the store.\n *\n * @remarks\n * Existing readers handed out by prior `write()` / `read()` calls remain valid — they hold\n * their own snapshot.\n */\n clear(): void {\n this.#entries.clear()\n }\n\n /**\n * Returns the number of entries currently in the store.\n */\n get size(): number {\n return this.#entries.size\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,IAAa,sBAAb,MAAwD;CACtD;CACA;CACA;CAEA,YAAY,SAA8B;EACxC,IAAI,OAAO,YAAY,UAAU;GAC/B,KAAKA,WAAW;GAChB,KAAKE,SAAS,IAAI,YAAY,EAAE,OAAO,OAAO,EAAE;EAClD,OAAO;GACL,KAAKF,WAAW,IAAI,YAAY,EAAE,OAAO,OAAO;GAChD,KAAKE,SAAS,QAAQ;EACxB;EACA,KAAKD,SAAS,KAAKD,aAAa,KAAK,CAAC,IAAI,KAAKA,SAAS,MAAM,IAAI;CACpE;CAEA,KAAK,O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AAO,KAAKA,SAAS,OAAO,MAAM;CACpC;;;;;;;;CASA,QAAc;EACZ,KAAKA,SAAS,MAAM;CACtB;;;;CAKA,IAAI,OAAe;EACjB,OAAO,KAAKA,SAAS;CACvB;AACF"}
1
+ {"version":3,"file":"in_memory.mjs","names":["#content","#lines","#bytes","#entries"],"sources":["../../../src/batteries/storage/in_memory/index.ts"],"sourcesContent":["/**\n * In-memory spool readers and stores for tests, scripts, and non-durable prototypes.\n *\n * @module @nhtio/adk/batteries/storage/in_memory\n *\n * @remarks\n * Opt-in in-memory persistence battery. Provides {@link InMemorySpoolReader} (a sync\n * {@link @nhtio/adk!SpoolReader} over a string) plus {@link InMemorySpoolStore} (a `Map<callId, bytes>`\n * with a `write()` method that returns a fresh reader bound to the stored bytes).\n *\n * Use this when:\n *\n * - Writing unit or functional tests that need a real `SpoolReader` over known bytes.\n * - Running a REPL or one-shot script where persistence beyond the process lifetime is not\n * needed.\n * - Prototyping an agent before deciding on a real disk/object-store-backed persistence layer.\n *\n * Do **not** use this for production agents that need durability across process restarts —\n * everything lives in process memory and is lost on exit.\n */\n\nimport { isInstanceOf } from '@nhtio/adk/guards'\nimport type { SpoolReader, SpoolStore } from '@nhtio/adk/common'\n\n/**\n * Sync in-memory {@link @nhtio/adk!SpoolReader} over a byte-faithful `Uint8Array` body.\n *\n * @remarks\n * Stores the raw bytes and decodes them as UTF-8 once at construction, then splits the decoded\n * string on `\\n` and caches the resulting line array. All four `SpoolReader` methods resolve\n * synchronously from the cache — no I/O happens after construction. `byteLength()` reports the\n * true stored byte count (not the decoded character count), so it stays correct for multi-byte\n * content; `line()`/`readAll()` operate on the decoded text.\n *\n * The reader accepts a `string` or a `Uint8Array`. A `string` is encoded as UTF-8 for the byte\n * count; a `Uint8Array` is held byte-faithfully (no lossy re-encode) and decoded for text reads.\n *\n * Empty input yields a reader with `lineCount() === 0` and `byteLength() === 0`. A trailing\n * newline produces a final empty line: `\"a\\nb\\n\".split('\\n') === ['a', 'b', '']`. This matches\n * the JavaScript `String.prototype.split` contract and lets a `lineCount()` consumer\n * distinguish \"two lines, no trailing newline\" from \"two lines, trailing newline\".\n */\nexport class InMemorySpoolReader implements SpoolReader {\n readonly #content: string\n readonly #lines: string[]\n readonly #bytes: number\n\n constructor(content: string | Uint8Array) {\n if (typeof content === 'string') {\n this.#content = content\n this.#bytes = new TextEncoder().encode(content).length\n } else {\n this.#content = new TextDecoder().decode(content)\n this.#bytes = content.byteLength\n }\n this.#lines = this.#content === '' ? [] : this.#content.split('\\n')\n }\n\n line(index: number): string | undefined {\n return this.#lines[index]\n }\n\n byteLength(): number {\n return this.#bytes\n }\n\n lineCount(): number {\n return this.#lines.length\n }\n\n readAll(): string {\n return this.#content\n }\n}\n\n/**\n * Drains a `ReadableStream<Uint8Array>` into a single concatenated `Uint8Array`.\n *\n * @remarks\n * In-memory storage cannot stream-to-disk, so a stream input is buffered fully — the documented\n * trade-off for {@link InMemorySpoolStore}. Use {@link @nhtio/adk/batteries/storage/opfs!OpfsSpoolStore}\n * or a Flydrive-backed store when true streaming persistence is required.\n */\nconst drainStream = async (stream: ReadableStream<Uint8Array>): Promise<Uint8Array> => {\n const chunks: Uint8Array[] = []\n let total = 0\n const reader = stream.getReader()\n try {\n for (;;) {\n const { done, value } = await reader.read()\n if (done) break\n if (value) {\n chunks.push(value)\n total += value.byteLength\n }\n }\n } finally {\n reader.releaseLock()\n }\n const out = new Uint8Array(total)\n let offset = 0\n for (const chunk of chunks) {\n out.set(chunk, offset)\n offset += chunk.byteLength\n }\n return out\n}\n\n/**\n * In-memory \"give bytes, get a reader\" persistence layer keyed by `callId`.\n *\n * @remarks\n * Stores each value byte-faithfully as a `Uint8Array`. `string` inputs are encoded as UTF-8;\n * `Uint8Array` inputs are held verbatim (no lossy text round-trip, so binary payloads survive\n * intact); `ReadableStream<Uint8Array>` inputs are drained fully into a buffer — in-memory storage\n * cannot stream to disk, so the stream form resolves asynchronously and is the documented\n * trade-off for this battery.\n *\n * Each `write()` and each `read()` returns a *fresh* {@link InMemorySpoolReader} — the store\n * owns the bytes, the reader is a view. Mutating the store after handing out a reader does not\n * invalidate the reader.\n *\n * Implements {@link @nhtio/adk/common!SpoolStore} (i.e. `ByteStore<SpoolReader>`).\n *\n * @example\n * ```ts\n * const store = new InMemorySpoolStore()\n * const bytes = await tool.executor(ctx)(args)\n * const reader = await store.write(callId, bytes)\n * const Ctor = tool.artifactConstructor?.() ?? SpooledArtifact\n * const artifact = new Ctor(reader)\n * ```\n */\nexport class InMemorySpoolStore implements SpoolStore {\n readonly #entries = new Map<string, Uint8Array>()\n\n /**\n * Persists `bytes` under `callId` and returns a reader over them.\n *\n * @remarks\n * `string` input is encoded as UTF-8; `Uint8Array` is stored byte-faithfully;\n * `ReadableStream<Uint8Array>` is drained fully (and `write` returns a `Promise`). Re-writing the\n * same `callId` replaces the prior entry; readers handed out before the rewrite continue to view\n * the old bytes (they hold their own snapshot via the `InMemorySpoolReader` constructor).\n *\n * @param callId - Identifier used to retrieve the bytes via {@link InMemorySpoolStore.read}.\n * @param bytes - The bytes to store, as a `string`, `Uint8Array`, or `ReadableStream<Uint8Array>`.\n * @returns A fresh {@link InMemorySpoolReader} bound to the stored bytes — a `Promise` for stream\n * input, synchronous otherwise.\n */\n write(callId: string, bytes: string): InMemorySpoolReader\n write(callId: string, bytes: Uint8Array): InMemorySpoolReader\n write(callId: string, bytes: ReadableStream<Uint8Array>): Promise<InMemorySpoolReader>\n write(\n callId: string,\n bytes: string | Uint8Array | ReadableStream<Uint8Array>\n ): InMemorySpoolReader | Promise<InMemorySpoolReader>\n write(\n callId: string,\n bytes: string | Uint8Array | ReadableStream<Uint8Array>\n ): InMemorySpoolReader | Promise<InMemorySpoolReader> {\n if (isInstanceOf(bytes, 'ReadableStream', ReadableStream)) {\n return drainStream(bytes).then((buffer) => {\n this.#entries.set(callId, buffer)\n return new InMemorySpoolReader(buffer)\n })\n }\n const buffer = typeof bytes === 'string' ? new TextEncoder().encode(bytes) : bytes\n this.#entries.set(callId, buffer)\n return new InMemorySpoolReader(buffer)\n }\n\n /**\n * Returns a reader over the bytes previously written under `callId`, or `undefined` if the\n * entry has not been written or has been deleted.\n *\n * @param callId - Identifier supplied to a prior {@link InMemorySpoolStore.write} call.\n * @returns A fresh {@link InMemorySpoolReader} bound to the stored bytes, or `undefined`.\n */\n read(callId: string): InMemorySpoolReader | undefined {\n const buffer = this.#entries.get(callId)\n if (buffer === undefined) return undefined\n return new InMemorySpoolReader(buffer)\n }\n\n /**\n * Removes the entry under `callId`.\n *\n * @param callId - Identifier whose entry should be removed.\n * @returns `true` if an entry existed and was removed; `false` otherwise.\n */\n delete(callId: string): boolean {\n return this.#entries.delete(callId)\n }\n\n /**\n * Removes every entry from the store.\n *\n * @remarks\n * Existing readers handed out by prior `write()` / `read()` calls remain valid — they hold\n * their own snapshot.\n */\n clear(): void {\n this.#entries.clear()\n }\n\n /**\n * Returns the number of entries currently in the store.\n */\n get size(): number {\n return this.#entries.size\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,IAAa,sBAAb,MAAwD;CACtD;CACA;CACA;CAEA,YAAY,SAA8B;EACxC,IAAI,OAAO,YAAY,UAAU;GAC/B,KAAKA,WAAW;GAChB,KAAKE,SAAS,IAAI,YAAY,EAAE,OAAO,OAAO,EAAE;EAClD,OAAO;GACL,KAAKF,WAAW,IAAI,YAAY,EAAE,OAAO,OAAO;GAChD,KAAKE,SAAS,QAAQ;EACxB;EACA,KAAKD,SAAS,KAAKD,aAAa,KAAK,CAAC,IAAI,KAAKA,SAAS,MAAM,IAAI;CACpE;CAEA,KAAK,OAAmC;EACtC,OAAO,KAAKC,OAAO;CACrB;CAEA,aAAqB;EACnB,OAAO,KAAKC;CACd;CAEA,YAAoB;EAClB,OAAO,KAAKD,OAAO;CACrB;CAEA,UAAkB;EAChB,OAAO,KAAKD;CACd;AACF;;;;;;;;;AAUA,IAAM,cAAc,OAAO,WAA4D;CACrF,MAAM,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OpfsFileHandle` — at call sites you pass real OPFS handles directly.
54
54
  */
55
55
  export interface OpfsFileHandle {
56
+ /** Discriminant: always `'file'`. */
56
57
  readonly kind: 'file';
58
+ /** The entry's name. */
57
59
  readonly name: string;
60
+ /** Resolve a readable {@link OpfsFile} snapshot of the handle's contents. */
58
61
  getFile(): Promise<OpfsFile>;
62
+ /** Open a writable stream that replaces the file's contents. */
59
63
  createWritable(): Promise<OpfsWritableFileStream>;
60
64
  }
61
65
  /**
@@ -66,14 +70,19 @@ export interface OpfsFileHandle {
66
70
  * handles directly.
67
71
  */
68
72
  export interface OpfsDirectoryHandle {
73
+ /** Discriminant: always `'directory'`. */
69
74
  readonly kind: 'directory';
75
+ /** The directory's name. */
70
76
  readonly name: string;
77
+ /** Resolve a child file handle, optionally creating it. */
71
78
  getFileHandle(name: string, options?: {
72
79
  create?: boolean;
73
80
  }): Promise<OpfsFileHandle>;
81
+ /** Resolve a child directory handle, optionally creating it. */
74
82
  getDirectoryHandle(name: string, options?: {
75
83
  create?: boolean;
76
84
  }): Promise<OpfsDirectoryHandle>;
85
+ /** Remove a child entry, optionally recursively. */
77
86
  removeEntry(name: string, options?: {
78
87
  recursive?: boolean;
79
88
  }): Promise<void>;
@@ -83,7 +92,9 @@ export interface OpfsDirectoryHandle {
83
92
  * main-thread write path.
84
93
  */
85
94
  export interface OpfsWritableFileStream {
95
+ /** Append/write a chunk to the stream. */
86
96
  write(data: Uint8Array | ArrayBufferView | ArrayBuffer | string): Promise<void>;
97
+ /** Flush and close the stream, committing the written contents. */
87
98
  close(): Promise<void>;
88
99
  }
89
100
  /**
@@ -92,15 +103,20 @@ export interface OpfsWritableFileStream {
92
103
  * actually call.
93
104
  */
94
105
  export interface OpfsBlob {
106
+ /** Byte length of the blob. */
95
107
  readonly size: number;
108
+ /** Return a sub-range of the blob as a new blob. */
96
109
  slice(start?: number, end?: number, contentType?: string): OpfsBlob;
110
+ /** Read the blob's contents as text. */
97
111
  text(): Promise<string>;
112
+ /** Open a readable byte stream over the blob. */
98
113
  stream(): OpfsReadableStream;
99
114
  }
100
115
  /**
101
116
  * Minimal subset of the DOM `File` interface used by {@link OpfsSpoolReader}.
102
117
  */
103
118
  export interface OpfsFile extends OpfsBlob {
119
+ /** The file's name. */
104
120
  readonly name: string;
105
121
  }
106
122
  /**
@@ -108,6 +124,7 @@ export interface OpfsFile extends OpfsBlob {
108
124
  * index construction.
109
125
  */
110
126
  export interface OpfsReadableStream {
127
+ /** Acquire a reader over the stream. */
111
128
  getReader(): OpfsReadableStreamReader;
112
129
  }
113
130
  /**
@@ -115,6 +132,7 @@ export interface OpfsReadableStream {
115
132
  * streaming-mode index construction.
116
133
  */
117
134
  export interface OpfsReadableStreamReader {
135
+ /** Read the next chunk, or signal end-of-stream with `done: true`. */
118
136
  read(): Promise<{
119
137
  done: false;
120
138
  value: Uint8Array;
@@ -122,6 +140,7 @@ export interface OpfsReadableStreamReader {
122
140
  done: true;
123
141
  value: undefined;
124
142
  }>;
143
+ /** Release the reader's lock on the stream. */
125
144
  releaseLock(): void;
126
145
  }
127
146
  /**
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("../../chunk-Ble4zEEl.js");
3
- const require_tool_registry = require("../../tool_registry-DYUYqXvo.js");
3
+ const require_tool_registry = require("../../tool_registry-CKJPze3j.js");
4
4
  require("../../guards.cjs");
5
5
  //#region src/batteries/storage/opfs/index.ts
6
6
  /**