@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
@@ -0,0 +1,257 @@
1
+ import { t as createException } from "./exceptions-BDhN0Xzr.mjs";
2
+ import { c as isObject, o as isError } from "./tool_registry-791Vrjtf.mjs";
3
+ import { t as Tool } from "./tool-wMYMVl60.mjs";
4
+ import "./common-DYDUi99O.mjs";
5
+ import { n as SpooledJsonArtifact } from "./spooled_markdown_artifact-wkrBF3oX.mjs";
6
+ import "./factories.mjs";
7
+ import "./guards.mjs";
8
+ import { validator } from "@nhtio/validation";
9
+ import { Middleware } from "@nhtio/middleware";
10
+ //#region src/batteries/tools/searxng/exceptions.ts
11
+ /**
12
+ * Battery-scoped exception constructors for the SearXNG search tool.
13
+ *
14
+ * @remarks
15
+ * Battery-scoped exception classes owned by the SearXNG tool battery (not the ADK core). Minted
16
+ * via `createException` from `@nhtio/adk/factories` and re-exported from the battery's barrel
17
+ * (`@nhtio/adk/batteries/tools/searxng`). This file intentionally carries **no** `@module` tag:
18
+ * it is an internal sibling relative-imported by `index.ts`, so it does not mint its own
19
+ * `…/searxng/exceptions` entrypoint (whose `exceptions` leaf basename would collide with sibling
20
+ * batteries under the `vite-plugin-dts` rolled-up `.d.ts` rule).
21
+ */
22
+ /**
23
+ * Thrown when {@link createSearxngSearchTool} receives invalid configuration.
24
+ *
25
+ * @remarks
26
+ * Fatal: config bugs (missing or unparseable `instanceUrl`) fail loud at factory-call time
27
+ * rather than at the first search.
28
+ */
29
+ var E_INVALID_SEARXNG_CONFIG = createException("E_INVALID_SEARXNG_CONFIG", "Invalid SearXNG tool config: %s", "E_INVALID_SEARXNG_CONFIG", 529, true);
30
+ //#endregion
31
+ //#region src/batteries/tools/searxng/index.ts
32
+ /**
33
+ * Factory for a configured SearXNG metasearch tool.
34
+ *
35
+ * @module @nhtio/adk/batteries/tools/searxng
36
+ *
37
+ * @remarks
38
+ * Unlike the other bundled tool categories — every one of which exports a ready-made,
39
+ * stateless `Tool` constant — the SearXNG battery exports a **factory**,
40
+ * {@link createSearxngSearchTool}. A search tool has to talk to a *specific* SearXNG instance,
41
+ * usually behind custom authentication, so it needs per-deployment configuration (a base URL
42
+ * and headers) that cannot be baked in at module load.
43
+ *
44
+ * Because this module exports a factory rather than a `Tool` instance, it MUST NOT be
45
+ * bulk-registered via `Object.values(batteries)`. Call the factory first, then register the
46
+ * returned tool: `new ToolRegistry([createSearxngSearchTool({ instanceUrl })])`.
47
+ *
48
+ * @see https://docs.searxng.org/dev/search_api.html
49
+ */
50
+ var DEFAULT_NAME = "searxng_search";
51
+ var DEFAULT_TIMEOUT = 1e4;
52
+ var DEFAULT_DESCRIPTION = "Search the web via a SearXNG metasearch instance. Returns aggregated results (title, url, snippet, source engine) plus any answers, infoboxes, and suggestions.";
53
+ /** Internal sentinel a short-circuiting input stage throws to unwind the pipeline immediately. */
54
+ var SHORT_CIRCUIT = Symbol("searxng.shortCircuit");
55
+ var isShortCircuit = (value) => isObject(value) && value[SHORT_CIRCUIT] === true;
56
+ /** Normalise a loose SearXNG result item into a {@link SearxngResult}. */
57
+ var normaliseResult = (raw) => {
58
+ const r = raw ?? {};
59
+ const out = {};
60
+ if (typeof r.title === "string") out.title = r.title;
61
+ if (typeof r.url === "string") out.url = r.url;
62
+ if (typeof r.content === "string") out.content = r.content;
63
+ if (typeof r.engine === "string") out.engine = r.engine;
64
+ if (typeof r.score === "number") out.score = r.score;
65
+ if (typeof r.publishedDate === "string") out.publishedDate = r.publishedDate;
66
+ return out;
67
+ };
68
+ /** Resolve the configured headers (static object or resolver) for a single request. */
69
+ var resolveHeaders = async (headers) => {
70
+ if (typeof headers === "function") return { ...await headers() };
71
+ return { ...headers ?? {} };
72
+ };
73
+ /**
74
+ * Create a configured SearXNG search {@link Tool}.
75
+ *
76
+ * @remarks
77
+ * The handler always requests `format=json`. Note that SearXNG ships with JSON output
78
+ * **disabled** by default (it is abused by bots); an instance that has not enabled
79
+ * `search.formats: [json]` in its `settings.yml` answers with HTTP 403, which the tool returns
80
+ * as a graceful `Error:` string naming the setting.
81
+ *
82
+ * @warning
83
+ * Do not trust the `number_of_results` field for a result count — SearXNG frequently reports `0`
84
+ * in JSON output even when `results` is non-empty. This is a long-standing upstream quirk, not a
85
+ * tool defect (see {@link https://github.com/searxng/searxng/issues/2987 | searxng#2987} and
86
+ * {@link https://github.com/searxng/searxng/issues/2457 | searxng#2457}). The tool passes the
87
+ * field through verbatim; use `results.length` as the authoritative count.
88
+ *
89
+ * @param config - The instance URL, optional custom headers, output-format policy, artifact
90
+ * type, and input/output middleware pipelines. See {@link SearxngToolConfig}.
91
+ * @returns A `Tool` ready to register in a `ToolRegistry`.
92
+ * @throws {@link E_INVALID_SEARXNG_CONFIG} when `instanceUrl` is missing or unparseable.
93
+ */
94
+ var createSearxngSearchTool = (config) => {
95
+ if (typeof config?.instanceUrl !== "string" || config.instanceUrl.trim() === "") throw new E_INVALID_SEARXNG_CONFIG(["instanceUrl is required"]);
96
+ try {
97
+ new URL(config.instanceUrl);
98
+ } catch {
99
+ throw new E_INVALID_SEARXNG_CONFIG([`instanceUrl is not a valid URL: ${config.instanceUrl}`]);
100
+ }
101
+ const instanceUrl = config.instanceUrl.replace(/\/+$/, "");
102
+ const timeout = config.timeout ?? DEFAULT_TIMEOUT;
103
+ const resultFormat = config.resultFormat ?? "either";
104
+ const toolName = config.name ?? DEFAULT_NAME;
105
+ const artifactConstructor = config.artifactConstructor ?? (() => SpooledJsonArtifact);
106
+ const inputMw = new Middleware();
107
+ for (const fn of config.inputPipeline ?? []) inputMw.add(fn);
108
+ const outputMw = new Middleware();
109
+ for (const fn of config.outputPipeline ?? []) outputMw.add(fn);
110
+ const hasInput = (config.inputPipeline ?? []).length > 0;
111
+ const hasOutput = (config.outputPipeline ?? []).length > 0;
112
+ const schemaShape = {
113
+ query: validator.string().required().description("The search query."),
114
+ categories: validator.string().optional().description("Comma-separated SearXNG categories (e.g. \"general,news\")."),
115
+ engines: validator.string().optional().description("Comma-separated SearXNG engines (e.g. \"google,duckduckgo\")."),
116
+ language: validator.string().optional().description("Language code (e.g. \"en\", \"de\")."),
117
+ pageno: validator.number().min(1).default(1).description("Result page number (1-based)."),
118
+ time_range: validator.string().valid("day", "month", "year").optional().description("Restrict results to a time range."),
119
+ safesearch: validator.number().valid(0, 1, 2).optional().description("Safe-search level: 0 (off), 1 (moderate), 2 (strict).")
120
+ };
121
+ if (resultFormat === "either") schemaShape.format = validator.string().valid("normalized", "raw").default("normalized").description("Output shape: \"normalized\" (trimmed) or \"raw\" (full SearXNG JSON).");
122
+ const inputSchema = validator.object(schemaShape);
123
+ return new Tool({
124
+ name: toolName,
125
+ description: config.description ?? DEFAULT_DESCRIPTION,
126
+ inputSchema,
127
+ artifactConstructor,
128
+ handler: async (args) => {
129
+ const a = args;
130
+ try {
131
+ const format = resultFormat === "either" ? a.format ?? "normalized" : resultFormat;
132
+ const headers = {
133
+ "Accept": "application/json",
134
+ "User-Agent": "adk-searxng-tool",
135
+ ...await resolveHeaders(config.headers)
136
+ };
137
+ const params = {};
138
+ if (a.categories) params.categories = a.categories;
139
+ if (a.engines) params.engines = a.engines;
140
+ if (a.language) params.language = a.language;
141
+ if (a.pageno && a.pageno !== 1) params.pageno = String(a.pageno);
142
+ if (a.time_range) params.time_range = a.time_range;
143
+ if (typeof a.safesearch === "number") params.safesearch = String(a.safesearch);
144
+ const stash = /* @__PURE__ */ new Map();
145
+ const requestCtx = {
146
+ toolName,
147
+ query: a.query,
148
+ params,
149
+ headers,
150
+ instanceUrl,
151
+ stash,
152
+ shortCircuit: (result) => {
153
+ throw {
154
+ [SHORT_CIRCUIT]: true,
155
+ result
156
+ };
157
+ }
158
+ };
159
+ if (hasInput) {
160
+ const short = await runInputPipeline(inputMw, requestCtx);
161
+ if (short !== void 0) return short;
162
+ }
163
+ const url = new URL("/search", instanceUrl + "/");
164
+ url.searchParams.set("q", requestCtx.query);
165
+ for (const [k, v] of Object.entries(requestCtx.params)) url.searchParams.set(k, v);
166
+ url.searchParams.set("format", "json");
167
+ const controller = new AbortController();
168
+ const timer = setTimeout(() => controller.abort(), timeout);
169
+ let response;
170
+ try {
171
+ response = await fetch(url, {
172
+ method: "GET",
173
+ headers: requestCtx.headers,
174
+ signal: controller.signal
175
+ });
176
+ } finally {
177
+ clearTimeout(timer);
178
+ }
179
+ if (!response.ok) {
180
+ if (response.status === 403) return "Error: SearXNG returned 403 Forbidden. The instance likely has the JSON output format disabled — enable it under \"search.formats: [json]\" in its settings.yml.";
181
+ return `Error: SearXNG returned HTTP ${response.status} ${response.statusText}.`;
182
+ }
183
+ const body = await response.json();
184
+ const responseCtx = {
185
+ toolName,
186
+ request: requestCtx,
187
+ raw: body,
188
+ results: Array.isArray(body.results) ? body.results.map(normaliseResult) : [],
189
+ format,
190
+ stash
191
+ };
192
+ if (hasOutput) await runOutputPipeline(outputMw, responseCtx);
193
+ if (typeof responseCtx.output === "string") return responseCtx.output;
194
+ if (responseCtx.format === "raw") return JSON.stringify(responseCtx.raw, null, 2);
195
+ return JSON.stringify(buildNormalisedPayload(responseCtx), null, 2);
196
+ } catch (err) {
197
+ if (isShortCircuit(err)) return err.result;
198
+ return `Error: ${isError(err) ? err.message : String(err)}`;
199
+ }
200
+ }
201
+ });
202
+ };
203
+ /** Assemble the trimmed normalised payload, dropping empty aggregate arrays. */
204
+ var buildNormalisedPayload = (ctx) => {
205
+ const raw = ctx.raw ?? {};
206
+ const payload = {
207
+ query: typeof raw.query === "string" ? raw.query : ctx.request.query,
208
+ results: ctx.results
209
+ };
210
+ if (typeof raw.number_of_results === "number") payload.number_of_results = raw.number_of_results;
211
+ for (const key of [
212
+ "answers",
213
+ "infoboxes",
214
+ "suggestions",
215
+ "corrections"
216
+ ]) {
217
+ const value = raw[key];
218
+ if (Array.isArray(value) && value.length > 0) payload[key] = value;
219
+ }
220
+ return payload;
221
+ };
222
+ /**
223
+ * Run the input pipeline. Returns the short-circuit string when a stage short-circuited, or
224
+ * `undefined` when the pipeline reached its terminal handler. A non-terminal pipeline (a stage
225
+ * that neither called `next()` nor short-circuited) is surfaced as a thrown Error so the handler
226
+ * converts it to an `Error:` string.
227
+ */
228
+ var runInputPipeline = async (mw, ctx) => {
229
+ let reached = false;
230
+ let shortResult;
231
+ let caught;
232
+ await mw.runner().errorHandler(async (error) => {
233
+ caught = error;
234
+ }).finalHandler(async () => {
235
+ reached = true;
236
+ }).run((fn, next) => Promise.resolve(fn(ctx, next)));
237
+ if (caught !== void 0) if (isShortCircuit(caught)) shortResult = caught.result;
238
+ else throw caught;
239
+ else if (!reached) throw new Error("SearXNG input pipeline did not call next() and did not short-circuit.");
240
+ return shortResult;
241
+ };
242
+ /** Run the output pipeline; rethrow any stage error to the handler's try/catch. */
243
+ var runOutputPipeline = async (mw, ctx) => {
244
+ let reached = false;
245
+ let caught;
246
+ await mw.runner().errorHandler(async (error) => {
247
+ caught = error;
248
+ }).finalHandler(async () => {
249
+ reached = true;
250
+ }).run((fn, next) => Promise.resolve(fn(ctx, next)));
251
+ if (caught !== void 0) throw caught;
252
+ if (!reached) throw new Error("SearXNG output pipeline did not call next().");
253
+ };
254
+ //#endregion
255
+ export { E_INVALID_SEARXNG_CONFIG as n, createSearxngSearchTool as t };
256
+
257
+ //# sourceMappingURL=searxng-CyA-nEu5.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"searxng-CyA-nEu5.mjs","names":[],"sources":["../src/batteries/tools/searxng/exceptions.ts","../src/batteries/tools/searxng/index.ts"],"sourcesContent":["/**\n * Battery-scoped exception constructors for the SearXNG search tool.\n *\n * @remarks\n * Battery-scoped exception classes owned by the SearXNG tool battery (not the ADK core). Minted\n * via `createException` from `@nhtio/adk/factories` and re-exported from the battery's barrel\n * (`@nhtio/adk/batteries/tools/searxng`). This file intentionally carries **no** `@module` tag:\n * it is an internal sibling relative-imported by `index.ts`, so it does not mint its own\n * `…/searxng/exceptions` entrypoint (whose `exceptions` leaf basename would collide with sibling\n * batteries under the `vite-plugin-dts` rolled-up `.d.ts` rule).\n */\n\nimport { createException } from '@nhtio/adk/factories'\n\n/**\n * Thrown when {@link createSearxngSearchTool} receives invalid configuration.\n *\n * @remarks\n * Fatal: config bugs (missing or unparseable `instanceUrl`) fail loud at factory-call time\n * rather than at the first search.\n */\nexport const E_INVALID_SEARXNG_CONFIG = createException<[string]>(\n 'E_INVALID_SEARXNG_CONFIG',\n 'Invalid SearXNG tool config: %s',\n 'E_INVALID_SEARXNG_CONFIG',\n 529,\n true\n)\n","/**\n * Factory for a configured SearXNG metasearch tool.\n *\n * @module @nhtio/adk/batteries/tools/searxng\n *\n * @remarks\n * Unlike the other bundled tool categories — every one of which exports a ready-made,\n * stateless `Tool` constant — the SearXNG battery exports a **factory**,\n * {@link createSearxngSearchTool}. A search tool has to talk to a *specific* SearXNG instance,\n * usually behind custom authentication, so it needs per-deployment configuration (a base URL\n * and headers) that cannot be baked in at module load.\n *\n * Because this module exports a factory rather than a `Tool` instance, it MUST NOT be\n * bulk-registered via `Object.values(batteries)`. Call the factory first, then register the\n * returned tool: `new ToolRegistry([createSearxngSearchTool({ instanceUrl })])`.\n *\n * @see https://docs.searxng.org/dev/search_api.html\n */\n\nimport { validator } from '@nhtio/validation'\nimport { Middleware } from '@nhtio/middleware'\nimport { isError, isObject } from '@nhtio/adk/guards'\nimport { E_INVALID_SEARXNG_CONFIG } from './exceptions'\nimport { Tool, SpooledJsonArtifact, type ArtifactConstructorResolver } from '@nhtio/adk/common'\nimport type { Schema } from '@nhtio/validation'\nimport type { NextFn } from '@nhtio/middleware'\n\nexport { E_INVALID_SEARXNG_CONFIG } from './exceptions'\n\n/** A static set of request headers (used for custom authentication). */\nexport type SearxngHeaders = Record<string, string>\n\n/**\n * A resolver returning request headers, sync or async. Use this form when the auth token is\n * refreshable — the resolver runs on every search, so a fresh token can be minted per call.\n */\nexport type SearxngHeadersResolver = () => SearxngHeaders | Promise<SearxngHeaders>\n\n/** The output shape the tool serialises. `either` lets the model pick per call. */\nexport type SearxngResultFormat = 'normalized' | 'raw' | 'either'\n\n/**\n * A single normalised SearXNG result. SearXNG result items are deliberately untyped upstream,\n * so every field except a best-effort `title`/`url` is optional.\n */\nexport interface SearxngResult {\n /** Result title, when the source engine provided one. */\n title?: string\n /** Result URL, when the source engine provided one. */\n url?: string\n /** Snippet / summary text for the result. */\n content?: string\n /** The SearXNG engine that produced this result (e.g. `google`, `duckduckgo`). */\n engine?: string\n /** Relevance score as reported by SearXNG (higher is more relevant). */\n score?: number\n /** Publication date, when the source engine exposed one (ISO-ish string, engine-dependent). */\n publishedDate?: string\n}\n\n/**\n * Mutable context handed to each input-pipeline stage **before** the HTTP request is sent.\n *\n * @remarks\n * Stages mutate this in place (onion `(ctx, next)` style) to adjust the outgoing request —\n * inject or rotate auth headers, force a language, rewrite the query — or call\n * {@link SearxngRequestContext.shortCircuit} to skip the fetch entirely (e.g. a cache hit).\n */\nexport interface SearxngRequestContext {\n /** The tool's name (read-only). */\n readonly toolName: string\n /** The search query. Mutable. */\n query: string\n /** Extra SearXNG query parameters (`categories`, `engines`, `language`, …). Mutable. */\n params: Record<string, string>\n /** Resolved request headers. Mutable — inject, redact, or rotate auth here. */\n headers: SearxngHeaders\n /** The target instance base URL (read-only). */\n readonly instanceUrl: string\n /** Cross-stage scratch space; also carried onto the response context. */\n readonly stash: Map<string, unknown>\n /** Skip the fetch and return `result` verbatim as the tool's output. */\n shortCircuit(result: string): void\n}\n\n/**\n * Mutable context handed to each output-pipeline stage **after** the response JSON is parsed.\n *\n * @remarks\n * Stages reshape, redact, enrich, or re-rank {@link SearxngResponseContext.results}, mutate the\n * raw body, or set {@link SearxngResponseContext.output} to override the serialised string\n * verbatim (e.g. to render markdown that matches a markdown `artifactConstructor`).\n */\nexport interface SearxngResponseContext {\n /** The tool's name (read-only). */\n readonly toolName: string\n /** The request context as it was sent (post-input-pipeline). */\n readonly request: SearxngRequestContext\n /** The parsed SearXNG JSON body. Mutable (used when `format` is `raw`). */\n raw: unknown\n /** The normalised result list. Mutable — filter, redact, or re-rank. */\n results: SearxngResult[]\n /** The effective payload shape for this call. */\n format: 'normalized' | 'raw'\n /** When set, used verbatim as the tool's output (overrides serialisation). */\n output?: string\n /** Cross-stage scratch space; carried over from the request context. */\n readonly stash: Map<string, unknown>\n}\n\n/** An input-pipeline stage. Onion middleware over {@link SearxngRequestContext}. */\nexport type SearxngInputMiddlewareFn = (\n ctx: SearxngRequestContext,\n next: NextFn\n) => void | Promise<void>\n\n/** An output-pipeline stage. Onion middleware over {@link SearxngResponseContext}. */\nexport type SearxngOutputMiddlewareFn = (\n ctx: SearxngResponseContext,\n next: NextFn\n) => void | Promise<void>\n\n/** Configuration for {@link createSearxngSearchTool}. */\nexport interface SearxngToolConfig {\n /** Base URL of the SearXNG instance, e.g. `https://searx.example.org`. Required. */\n instanceUrl: string\n /** Custom request headers — a static object or a (sync/async) resolver for refreshable auth. */\n headers?: SearxngHeaders | SearxngHeadersResolver\n /** Request timeout in milliseconds. Default `10_000`. */\n timeout?: number\n /**\n * Output shape. `normalized`/`raw` pin the shape (the model cannot change it); `either`\n * (default) exposes a `format` argument so the model chooses per call.\n */\n resultFormat?: SearxngResultFormat\n /** Tool name. Default `searxng_search`. */\n name?: string\n /** Tool description override. */\n description?: string\n /**\n * Spool artifact constructor for the tool's output. Default `() => SpooledJsonArtifact`.\n * Pass `() => SpooledMarkdownArtifact` (paired with an output stage that renders markdown into\n * `ctx.output`) or `() => SpooledArtifact` for plain text.\n */\n artifactConstructor?: ArtifactConstructorResolver\n /** Stages run before the HTTP request. See {@link SearxngRequestContext}. */\n inputPipeline?: SearxngInputMiddlewareFn[]\n /** Stages run after the response is parsed. See {@link SearxngResponseContext}. */\n outputPipeline?: SearxngOutputMiddlewareFn[]\n}\n\nconst DEFAULT_NAME = 'searxng_search'\nconst DEFAULT_TIMEOUT = 10_000\nconst DEFAULT_DESCRIPTION =\n 'Search the web via a SearXNG metasearch instance. Returns aggregated results (title, url, ' +\n 'snippet, source engine) plus any answers, infoboxes, and suggestions.'\n\n/** Internal sentinel a short-circuiting input stage throws to unwind the pipeline immediately. */\nconst SHORT_CIRCUIT = Symbol('searxng.shortCircuit')\n\ninterface ShortCircuitSignal {\n [SHORT_CIRCUIT]: true\n result: string\n}\n\nconst isShortCircuit = (value: unknown): value is ShortCircuitSignal =>\n isObject(value) && (value as Record<symbol, unknown>)[SHORT_CIRCUIT] === true\n\n/** Normalise a loose SearXNG result item into a {@link SearxngResult}. */\nconst normaliseResult = (raw: unknown): SearxngResult => {\n const r = (raw ?? {}) as Record<string, unknown>\n const out: SearxngResult = {}\n if (typeof r.title === 'string') out.title = r.title\n if (typeof r.url === 'string') out.url = r.url\n if (typeof r.content === 'string') out.content = r.content\n if (typeof r.engine === 'string') out.engine = r.engine\n if (typeof r.score === 'number') out.score = r.score\n if (typeof r.publishedDate === 'string') out.publishedDate = r.publishedDate\n return out\n}\n\n/** Resolve the configured headers (static object or resolver) for a single request. */\nconst resolveHeaders = async (headers: SearxngToolConfig['headers']): Promise<SearxngHeaders> => {\n if (typeof headers === 'function') return { ...(await headers()) }\n return { ...(headers ?? {}) }\n}\n\n/**\n * Create a configured SearXNG search {@link Tool}.\n *\n * @remarks\n * The handler always requests `format=json`. Note that SearXNG ships with JSON output\n * **disabled** by default (it is abused by bots); an instance that has not enabled\n * `search.formats: [json]` in its `settings.yml` answers with HTTP 403, which the tool returns\n * as a graceful `Error:` string naming the setting.\n *\n * @warning\n * Do not trust the `number_of_results` field for a result count — SearXNG frequently reports `0`\n * in JSON output even when `results` is non-empty. This is a long-standing upstream quirk, not a\n * tool defect (see {@link https://github.com/searxng/searxng/issues/2987 | searxng#2987} and\n * {@link https://github.com/searxng/searxng/issues/2457 | searxng#2457}). The tool passes the\n * field through verbatim; use `results.length` as the authoritative count.\n *\n * @param config - The instance URL, optional custom headers, output-format policy, artifact\n * type, and input/output middleware pipelines. See {@link SearxngToolConfig}.\n * @returns A `Tool` ready to register in a `ToolRegistry`.\n * @throws {@link E_INVALID_SEARXNG_CONFIG} when `instanceUrl` is missing or unparseable.\n */\nexport const createSearxngSearchTool = (config: SearxngToolConfig): Tool => {\n if (typeof config?.instanceUrl !== 'string' || config.instanceUrl.trim() === '') {\n throw new E_INVALID_SEARXNG_CONFIG(['instanceUrl is required'])\n }\n try {\n // Parse-validate only; the normalised string below is what we actually use.\n new URL(config.instanceUrl)\n } catch {\n throw new E_INVALID_SEARXNG_CONFIG([`instanceUrl is not a valid URL: ${config.instanceUrl}`])\n }\n // Normalise away a trailing slash so `new URL('/search', base)` resolves cleanly.\n const instanceUrl = config.instanceUrl.replace(/\\/+$/, '')\n\n const timeout = config.timeout ?? DEFAULT_TIMEOUT\n const resultFormat: SearxngResultFormat = config.resultFormat ?? 'either'\n const toolName = config.name ?? DEFAULT_NAME\n const artifactConstructor: ArtifactConstructorResolver =\n config.artifactConstructor ?? (() => SpooledJsonArtifact)\n\n // Stages are fixed at factory time; build the Middleware shells once. A fresh `.runner()` is\n // minted per invocation inside the handler (runners are single-use).\n const inputMw = new Middleware<SearxngInputMiddlewareFn>()\n for (const fn of config.inputPipeline ?? []) inputMw.add(fn)\n const outputMw = new Middleware<SearxngOutputMiddlewareFn>()\n for (const fn of config.outputPipeline ?? []) outputMw.add(fn)\n const hasInput = (config.inputPipeline ?? []).length > 0\n const hasOutput = (config.outputPipeline ?? []).length > 0\n\n // Build the input schema, conditionally exposing `format` only when the factory is neutral.\n const schemaShape: Record<string, Schema> = {\n query: validator.string().required().description('The search query.'),\n categories: validator\n .string()\n .optional()\n .description('Comma-separated SearXNG categories (e.g. \"general,news\").'),\n engines: validator\n .string()\n .optional()\n .description('Comma-separated SearXNG engines (e.g. \"google,duckduckgo\").'),\n language: validator.string().optional().description('Language code (e.g. \"en\", \"de\").'),\n pageno: validator.number().min(1).default(1).description('Result page number (1-based).'),\n time_range: validator\n .string()\n .valid('day', 'month', 'year')\n .optional()\n .description('Restrict results to a time range.'),\n safesearch: validator\n .number()\n .valid(0, 1, 2)\n .optional()\n .description('Safe-search level: 0 (off), 1 (moderate), 2 (strict).'),\n }\n if (resultFormat === 'either') {\n schemaShape.format = validator\n .string()\n .valid('normalized', 'raw')\n .default('normalized')\n .description('Output shape: \"normalized\" (trimmed) or \"raw\" (full SearXNG JSON).')\n }\n const inputSchema = validator.object(schemaShape)\n\n return new Tool({\n name: toolName,\n description: config.description ?? DEFAULT_DESCRIPTION,\n inputSchema,\n artifactConstructor,\n handler: async (args) => {\n const a = args as {\n query: string\n categories?: string\n engines?: string\n language?: string\n pageno?: number\n time_range?: string\n safesearch?: number\n format?: 'normalized' | 'raw'\n }\n\n try {\n // 1. Effective output format: a pinned factory format wins; else the model's choice.\n const format: 'normalized' | 'raw' =\n resultFormat === 'either' ? (a.format ?? 'normalized') : resultFormat\n\n // 2. Resolve headers, merged over portable defaults (caller headers win).\n const headers: SearxngHeaders = {\n 'Accept': 'application/json',\n 'User-Agent': 'adk-searxng-tool',\n ...(await resolveHeaders(config.headers)),\n }\n\n // 3. Assemble the SearXNG query params from validated args.\n const params: Record<string, string> = {}\n if (a.categories) params.categories = a.categories\n if (a.engines) params.engines = a.engines\n if (a.language) params.language = a.language\n if (a.pageno && a.pageno !== 1) params.pageno = String(a.pageno)\n if (a.time_range) params.time_range = a.time_range\n if (typeof a.safesearch === 'number') params.safesearch = String(a.safesearch)\n\n const stash = new Map<string, unknown>()\n\n // 4. Run the input pipeline (fresh runner) over a mutable request context.\n const requestCtx: SearxngRequestContext = {\n toolName,\n query: a.query,\n params,\n headers,\n instanceUrl,\n stash,\n shortCircuit: (result: string) => {\n const signal: ShortCircuitSignal = { [SHORT_CIRCUIT]: true, result }\n throw signal\n },\n }\n\n if (hasInput) {\n const short = await runInputPipeline(inputMw, requestCtx)\n if (short !== undefined) return short\n }\n\n // 5. Build the request URL from the (possibly mutated) query + params.\n const url = new URL('/search', instanceUrl + '/')\n url.searchParams.set('q', requestCtx.query)\n for (const [k, v] of Object.entries(requestCtx.params)) url.searchParams.set(k, v)\n url.searchParams.set('format', 'json')\n\n // 6. Fetch with an AbortController timeout.\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), timeout)\n let response: Response\n try {\n response = await fetch(url, {\n method: 'GET',\n headers: requestCtx.headers,\n signal: controller.signal,\n })\n } finally {\n clearTimeout(timer)\n }\n\n if (!response.ok) {\n if (response.status === 403) {\n return (\n `Error: SearXNG returned 403 Forbidden. The instance likely has the JSON output ` +\n `format disabled — enable it under \"search.formats: [json]\" in its settings.yml.`\n )\n }\n return `Error: SearXNG returned HTTP ${response.status} ${response.statusText}.`\n }\n\n const body = (await response.json()) as Record<string, unknown>\n\n // 7. Run the output pipeline (fresh runner) over a mutable response context.\n const responseCtx: SearxngResponseContext = {\n toolName,\n request: requestCtx,\n raw: body,\n results: Array.isArray(body.results) ? body.results.map(normaliseResult) : [],\n format,\n stash,\n }\n\n if (hasOutput) await runOutputPipeline(outputMw, responseCtx)\n\n // 8. Serialise and return.\n if (typeof responseCtx.output === 'string') return responseCtx.output\n if (responseCtx.format === 'raw') return JSON.stringify(responseCtx.raw, null, 2)\n return JSON.stringify(buildNormalisedPayload(responseCtx), null, 2)\n } catch (err) {\n if (isShortCircuit(err)) return err.result\n return `Error: ${isError(err) ? err.message : String(err)}`\n }\n },\n })\n}\n\n/** Assemble the trimmed normalised payload, dropping empty aggregate arrays. */\nconst buildNormalisedPayload = (ctx: SearxngResponseContext): Record<string, unknown> => {\n const raw = (ctx.raw ?? {}) as Record<string, unknown>\n const payload: Record<string, unknown> = {\n query: typeof raw.query === 'string' ? raw.query : ctx.request.query,\n results: ctx.results,\n }\n // NOTE: SearXNG's `number_of_results` is frequently `0` in JSON output even when `results`\n // is non-empty — a long-standing upstream quirk, not a tool bug (see\n // https://github.com/searxng/searxng/issues/2987 and\n // https://github.com/searxng/searxng/issues/2457). We pass through whatever the instance\n // reports; treat `results.length` as the authoritative count, not this field.\n if (typeof raw.number_of_results === 'number') payload.number_of_results = raw.number_of_results\n for (const key of ['answers', 'infoboxes', 'suggestions', 'corrections'] as const) {\n const value = raw[key]\n if (Array.isArray(value) && value.length > 0) payload[key] = value\n }\n return payload\n}\n\n/**\n * Run the input pipeline. Returns the short-circuit string when a stage short-circuited, or\n * `undefined` when the pipeline reached its terminal handler. A non-terminal pipeline (a stage\n * that neither called `next()` nor short-circuited) is surfaced as a thrown Error so the handler\n * converts it to an `Error:` string.\n */\nconst runInputPipeline = async (\n mw: Middleware<SearxngInputMiddlewareFn>,\n ctx: SearxngRequestContext\n): Promise<string | undefined> => {\n let reached = false\n let shortResult: string | undefined\n let caught: unknown\n await mw\n .runner()\n .errorHandler(async (error: unknown) => {\n caught = error\n })\n .finalHandler(async () => {\n reached = true\n })\n .run((fn, next) => Promise.resolve(fn(ctx, next)))\n\n if (caught !== undefined) {\n if (isShortCircuit(caught)) {\n shortResult = caught.result\n } else {\n throw caught\n }\n } else if (!reached) {\n throw new Error('SearXNG input pipeline did not call next() and did not short-circuit.')\n }\n return shortResult\n}\n\n/** Run the output pipeline; rethrow any stage error to the handler's try/catch. */\nconst runOutputPipeline = async (\n mw: Middleware<SearxngOutputMiddlewareFn>,\n ctx: SearxngResponseContext\n): Promise<void> => {\n let reached = false\n let caught: unknown\n await mw\n .runner()\n .errorHandler(async (error: unknown) => {\n caught = error\n })\n .finalHandler(async () => {\n reached = true\n })\n .run((fn, next) => Promise.resolve(fn(ctx, next)))\n\n if (caught !== undefined) throw caught\n if (!reached) {\n throw new Error('SearXNG output pipeline did not call next().')\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,IAAa,2BAA2B,g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AAA,GACb,IAAI,eAAe,MAAM,GACvB,cAAc,OAAO;MAErB,MAAM;MAEH,IAAI,CAAC,SACV,MAAM,IAAI,MAAM,uEAAuE;CAEzF,OAAO;AACT;;AAGA,IAAM,oBAAoB,OACxB,IACA,QACkB;CAClB,IAAI,UAAU;CACd,IAAI;CACJ,MAAM,GACH,OAAO,EACP,aAAa,OAAO,UAAmB;EACtC,SAAS;CACX,CAAC,EACA,aAAa,YAAY;EACxB,UAAU;CACZ,CAAC,EACA,KAAK,IAAI,SAAS,QAAQ,QAAQ,GAAG,KAAK,IAAI,CAAC,CAAC;CAEnD,IAAI,WAAW,KAAA,GAAW,MAAM;CAChC,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,8CAA8C;AAElE"}
@@ -5,7 +5,7 @@ license: MIT
5
5
  compatibility: "Requires TypeScript/JavaScript project using @nhtio/adk; examples assume Node 20+ or compatible browser/runtime."
6
6
  metadata:
7
7
  package: "@nhtio/adk"
8
- version: "1.20260607.2"
8
+ version: "1.20260609.0"
9
9
  author: "Jak Giveon <jak@nht.io>"
10
10
  copyright: "© 2025-present New Horizon Technology LTD"
11
11
  ---
@@ -17,7 +17,7 @@ Use this skill to help users build or review an `@nhtio/adk` assembly: the appli
17
17
  ## Package Metadata
18
18
 
19
19
  - Package: `@nhtio/adk`
20
- - Version: `1.20260607.2`
20
+ - Version: `1.20260609.0`
21
21
  - License: MIT
22
22
  - Author: Jak Giveon <jak@nht.io>
23
23
  - Copyright: © 2025-present New Horizon Technology LTD
@@ -1,7 +1,7 @@
1
- import { a as validateOrThrow, i as passesSchema, n as ValidationException } from "./exceptions-BeWH2FwP.mjs";
2
- import { a as Tokenizable, i as TokenEncoding, s as isInstanceOf, t as ToolRegistry } from "./tool_registry-D1pSSlsd.mjs";
3
- import { C as E_NOT_A_SPOOL_READER, d as E_INVALID_INITIAL_TOOL_VALUE } from "./runtime-j92CNi5z.mjs";
4
- import { t as Tool } from "./tool-CMhaDRNd.mjs";
1
+ import { a as validateOrThrow, i as passesSchema, n as ValidationException } from "./exceptions-BDhN0Xzr.mjs";
2
+ import { a as Tokenizable, i as TokenEncoding, s as isInstanceOf, t as ToolRegistry } from "./tool_registry-791Vrjtf.mjs";
3
+ import { C as E_NOT_A_SPOOL_READER, d as E_INVALID_INITIAL_TOOL_VALUE } from "./runtime-Bz5zA8wc.mjs";
4
+ import { t as Tool } from "./tool-wMYMVl60.mjs";
5
5
  import { validator } from "@nhtio/validation";
6
6
  //#region src/lib/classes/artifact_tool.ts
7
7
  /**
@@ -541,4 +541,4 @@ var SpooledArtifact = class SpooledArtifact {
541
541
  //#endregion
542
542
  export { ArtifactTool as i, defaultSerialise as n, implementsSpoolReader as r, SpooledArtifact as t };
543
543
 
544
- //# sourceMappingURL=spooled_artifact-CHoZgWwI.mjs.map
544
+ //# sourceMappingURL=spooled_artifact-7eePq7JA.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"spooled_artifact-CHoZgWwI.mjs","names":["#reader"],"sources":["../src/lib/classes/artifact_tool.ts","../src/lib/contracts/spool_reader.ts","../src/lib/classes/spooled_artifact.ts"],"sourcesContent":["import { Tool } from './tool'\nimport { validator } from '@nhtio/validation'\nimport { isInstanceOf } from '../utils/guards'\nimport { E_INVALID_INITIAL_TOOL_VALUE } from '../exceptions/runtime'\nimport { validateOrThrow, ValidationException } from '../utils/validation'\nimport type { Registry } from './registry'\nimport type { Schema } from '@nhtio/validation'\nimport type { Tokenizable } from './tokenizable'\nimport type { DispatchContext } from '../contracts/dispatch_context'\n\n/**\n * The execution function for an {@link ArtifactTool}.\n *\n * @remarks\n * Identical to the base tool handler except the return type is narrowed to\n * `string | Tokenizable | Promise<string | Tokenizable>`. Forged artifact-query tools emit\n * model-visible strings — the ADK wraps a bare-string return into a {@link @nhtio/adk!Tokenizable}\n * at the result-wrapping site so downstream code can rely on\n * `ToolCall.results instanceof Tokenizable` for every `ArtifactTool` invocation.\n */\nexport type ArtifactToolHandler = (\n args: unknown,\n ctx: DispatchContext,\n meta: Registry\n) => string | Tokenizable | Promise<string | Tokenizable>\n\n/**\n * Plain input object supplied to {@link ArtifactTool} at construction time.\n *\n * @remarks\n * Mirrors the base `RawTool` except `artifactConstructor` is forbidden — an `ArtifactTool`\n * emits a {@link @nhtio/adk!Tokenizable} directly into `ToolCall.results` and explicitly opts out of\n * `SpooledArtifact` wrapping. The forbidden field is enforced by {@link ArtifactTool.schema}\n * at construction time.\n */\nexport interface RawArtifactTool {\n /** Unique identifier used in LLM tool definitions. Recommend lowercase snake_case. */\n name: string\n /** Human-readable description passed to the model to explain what the tool does. */\n description: string\n /** @nhtio/validation schema for the tool's input arguments. */\n inputSchema: Schema\n /** Execution function. Returns a string or {@link @nhtio/adk!Tokenizable}; the ADK wraps a bare string into a `Tokenizable` at the result-wrapping site. */\n handler: ArtifactToolHandler\n /** Optional arbitrary metadata for this tool. Defaults to `{}`. */\n meta?: Record<string, unknown>\n /**\n * When `true`, marks this tool as owned by a specific {@link @nhtio/adk!DispatchContext}.\n *\n * @remarks\n * `ArtifactTool` instances produced by `SpooledArtifact.forgeTools(ctx)` set this to `true`\n * so that `ToolRegistry.pruneEphemeral()` drops them at ctx-completion.\n *\n * @defaultValue `false`\n */\n ephemeral?: boolean\n /**\n * When `true`, declares that this tool's output should be treated as **trusted developer/user\n * intent** rather than as untrusted third-party text when surfaced to the model.\n *\n * @remarks\n * Forged artifact-query tools default to `false` because their results are derived from\n * spooled artifact bodies — which may themselves be untrusted upstream tool output. The\n * trust signal does not promote handle-query results above the trust tier of the underlying\n * artifact.\n *\n * @defaultValue `false`\n */\n trusted?: boolean\n /**\n * Self-declared merge collision policy honoured by `ToolRegistry.merge`.\n *\n * @remarks\n * Forged artifact-query tools set this to `'replace'` so that merging multiple\n * `Subclass.forgeTools(ctx)` outputs (whose base-method tools overlap by name) resolves\n * silently — the descriptors, snapshot, and handler behaviour are interchangeable across\n * subclasses, so replacement is a behavioural no-op.\n *\n * @defaultValue `'throw'`\n */\n onCollision?: 'throw' | 'replace' | 'keep'\n}\n\n/**\n * Validator schema for a {@link RawArtifactTool}.\n *\n * @remarks\n * Mirrors the base tool schema but explicitly forbids `artifactConstructor` — the entire\n * point of `ArtifactTool` is to opt out of `SpooledArtifact` wrapping.\n */\nconst rawArtifactToolSchema = validator.object<RawArtifactTool & { artifactConstructor?: never }>({\n name: validator.string().required(),\n description: validator.string().required(),\n inputSchema: validator\n .any()\n .custom((value, helpers) => {\n if (validator.isSchema(value) && (value as any).type === 'object') return value\n return helpers.error('any.invalid')\n })\n .required(),\n handler: validator.function().required(),\n // eslint-disable-next-line adk/require-validator-any-required -- map value type-arg: meta holds arbitrary values; disposition is set by .default({}) on the object\n meta: validator.object().pattern(validator.string(), validator.any()).default({}),\n ephemeral: validator.boolean().default(false),\n trusted: validator.boolean().default(false),\n onCollision: validator.string().valid('throw', 'replace', 'keep').default('throw'),\n artifactConstructor: validator.any().forbidden(),\n})\n\n/**\n * A {@link @nhtio/adk!Tool} subclass whose handler return value is wrapped directly in a\n * {@link @nhtio/adk!Tokenizable} (not a {@link @nhtio/adk!SpooledArtifact}) when it\n * lands on `ToolCall.results`.\n *\n * @remarks\n * `ArtifactTool` is the canonical producer for **forged artifact-query tools** — the tools\n * `SpooledArtifact.forgeTools(ctx)` emits so the model can `head`, `tail`, `grep`, `json_get`,\n * `md_headings` (etc.) an artifact that is already in `ctx.turnToolCalls`.\n *\n * The difference from {@link @nhtio/adk!Tool} is structural, not stylistic:\n *\n * - A normal `Tool`'s handler returns bytes the ADK wraps in a fresh `SpooledArtifact`.\n * The artifact lands in `ToolCall.results`, joins `ctx.turnToolCalls`, and is itself a\n * first-class queryable artifact in the turn.\n * - An `ArtifactTool`'s handler returns a string that is **already the model-visible answer**\n * to a query against an existing artifact. The ADK wraps it in a `Tokenizable` rather\n * than a `SpooledArtifact`; nothing new is queryable on its own. Subsequent\n * `forgeTools(ctx)` calls exclude `ToolCall`s produced by an `ArtifactTool` from the\n * `callId` enum (via the `ToolCall.fromArtifactTool` marker) — this is the structural fix\n * that breaks the otherwise-recursive grep-on-the-grep-result loop.\n *\n * Consumers who want to build their own artifact-query tools (e.g. for a domain-specific\n * spooled subclass not shipped by the ADK) should extend or instantiate this class.\n */\nexport class ArtifactTool extends Tool {\n /**\n * Validator schema that accepts a {@link RawArtifactTool} object.\n *\n * @remarks\n * Differs from {@link @nhtio/adk!Tool.schema} by forbidding `artifactConstructor` — wrapping is\n * exactly the thing this class opts out of. Typed identically to {@link @nhtio/adk!Tool.schema} so the\n * subclass relationship `class ArtifactTool extends Tool` remains structurally sound; the\n * runtime validation rules still differ as declared by `rawArtifactToolSchema`.\n */\n public static schema = rawArtifactToolSchema as unknown as typeof Tool.schema\n\n /**\n * Returns `true` if `value` is an {@link ArtifactTool} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances\n * created in a different module copy or VM context.\n *\n * @param value - The value to test.\n * @returns `true` when `value` is an {@link ArtifactTool} instance.\n */\n public static isArtifactTool(value: unknown): value is ArtifactTool {\n return isInstanceOf(value, 'ArtifactTool', ArtifactTool)\n }\n\n /**\n * @param raw - Raw tool input validated against {@link ArtifactTool.schema}.\n *\n * @throws {@link @nhtio/adk!E_INVALID_INITIAL_TOOL_VALUE} when `raw` does not satisfy\n * {@link ArtifactTool.schema} (most commonly, when `artifactConstructor` is supplied — it is\n * explicitly forbidden on this class) or when the base {@link @nhtio/adk!Tool} constructor rejects the\n * input for any reason.\n */\n constructor(raw: RawArtifactTool) {\n // Enforce the forbidden `artifactConstructor` field up-front so the error reports against\n // ArtifactTool's contract, not the base Tool's. The base Tool constructor re-validates\n // against its own schema and stores the resolved fields.\n try {\n validateOrThrow(rawArtifactToolSchema, raw, true)\n } catch (err) {\n if (isInstanceOf(err, 'ValidationException', ValidationException)) {\n throw new E_INVALID_INITIAL_TOOL_VALUE({ cause: err })\n }\n throw err\n }\n super(raw as never)\n }\n}\n","import { validator } from '@nhtio/validation'\nimport { passesSchema } from '../utils/validation'\n\n/**\n * Backing store contract for a {@link @nhtio/adk!SpooledArtifact}.\n *\n * @remarks\n * Implementations may read from memory, a file handle, a network stream, or any other byte\n * source. The interface is intentionally minimal — the artifact layer handles all higher-level\n * operations (`head`, `tail`, `grep`, etc.) by composing calls to these three primitives.\n *\n * Line indexing is 0-based. Implementations must return `undefined` from {@link SpoolReader.line}\n * when the index is out of range rather than throwing.\n *\n * All three methods may be synchronous or asynchronous to accommodate both in-memory and I/O-\n * backed implementations without forcing unnecessary promise overhead on simple cases.\n */\nexport interface SpoolReader {\n /**\n * Returns the line at the given 0-based index, or `undefined` when out of range.\n *\n * @param index - 0-based line index.\n * @returns The raw line string (without trailing newline), or `undefined`.\n */\n line(index: number): string | undefined | Promise<string | undefined>\n\n /**\n * Returns the total number of bytes in the underlying data.\n *\n * @remarks\n * Used for reporting and token-estimation purposes. Byte length is distinct from character\n * length for multi-byte encodings.\n *\n * @returns The byte length of the underlying data.\n */\n byteLength(): number | Promise<number>\n\n /**\n * Returns the total number of lines in the underlying data.\n *\n * @remarks\n * Required so consumers know when to stop iterating; the line count must remain stable for the\n * lifetime of the reader.\n *\n * @returns The total line count.\n */\n lineCount(): number | Promise<number>\n\n /**\n * Returns the full underlying content as a single decoded string, byte-faithful to the source.\n *\n * @remarks\n * Unlike {@link SpoolReader.line}, this method preserves trailing newlines and any non-`\\n`\n * line terminators (e.g. `\\r\\n`) present in the original bytes. It is the primitive that\n * powers `SpooledArtifact.asString()` — the round-trip-faithful alternative to assembling\n * the artifact body from per-line reads.\n *\n * Implementations should make this O(n) in the size of the underlying data and may cache the\n * result if the read source is durable. Streaming implementations may choose not to cache.\n *\n * @returns The full underlying content as a single string.\n */\n readAll(): string | Promise<string>\n}\n\n/**\n * Validator schema used to validate a {@link SpoolReader} value.\n *\n * @remarks\n * Because `SpoolReader` is a structural interface with no associated constructor, validation is\n * duck-typed: the value must be an object, class instance, or function with `line`, `byteLength`,\n * and `lineCount` present as callable properties. Arity is not enforced — implementations may add\n * optional parameters beyond the contract.\n */\nexport const spoolReaderSchema = validator\n .any()\n .required()\n .custom((value, helpers) => {\n if (\n value !== null &&\n value !== undefined &&\n typeof (value as any).line === 'function' &&\n typeof (value as any).byteLength === 'function' &&\n typeof (value as any).lineCount === 'function' &&\n typeof (value as any).readAll === 'function'\n ) {\n return value as SpoolReader\n }\n return helpers.error('any.invalid')\n })\n\n/**\n * Returns `true` if `value` implements the {@link SpoolReader} interface.\n *\n * @remarks\n * Duck-typed: checks that `value` is non-null with `line`, `byteLength`, `lineCount`, and\n * `readAll` as callable functions. Does not use `instanceof` — there is no `SpoolReader`\n * constructor.\n *\n * @param value - The value to test.\n * @returns `true` when `value` conforms to the {@link SpoolReader} interface.\n */\nexport const implementsSpoolReader = (value: unknown): value is SpoolReader => {\n return passesSchema(spoolReaderSchema, value)\n}\n","import { validator } from '@nhtio/validation'\nimport { isInstanceOf } from '../utils/guards'\nimport { ArtifactTool } from './artifact_tool'\nimport { ToolRegistry } from './tool_registry'\nimport { Tokenizable, TokenEncoding } from './tokenizable'\nimport { E_NOT_A_SPOOL_READER } from '../exceptions/runtime'\nimport { implementsSpoolReader } from '../contracts/spool_reader'\nimport type { ObjectSchema } from '@nhtio/validation'\nimport type { SpoolReader } from '../contracts/spool_reader'\nimport type { DispatchContext } from '../contracts/dispatch_context'\n\n/**\n * Constructor signature for {@link SpooledArtifact} and any subclass.\n *\n * @remarks\n * Used by {@link @nhtio/adk!Tool} to declare the artifact subclass the consumer should use when wrapping\n * the handler's serialised output. The variadic rest parameter accommodates subclass-specific\n * constructor arguments (e.g. `SpooledJsonArtifact(reader, format?)`).\n *\n * @typeParam A - The {@link SpooledArtifact} subtype the constructor produces.\n */\nexport type SpooledArtifactConstructor<A extends SpooledArtifact = SpooledArtifact> = new (\n reader: SpoolReader,\n ...rest: any[]\n) => A\n\n/**\n * Metadata table entry for one of the artifact's existing query methods, used by\n * {@link SpooledArtifact.forgeTools} to surface that method as an {@link @nhtio/adk!ArtifactTool}.\n *\n * @remarks\n * This is a metadata shape, not a general method → tool pipeline. `forgeTools` knows how to\n * marshal arguments for a fixed, closed set of method names (the base seven on\n * {@link SpooledArtifact} and the JSON/Markdown methods on the bundled subclasses); a\n * descriptor is the place to attach a tool name, description, args schema, and optional\n * serializer to one of those methods. Adding a descriptor for a method whose name is not\n * in that closed set will produce a tool whose handler invokes the method with no arguments.\n *\n * For new methods that require custom argument marshalling, branching, multi-step logic,\n * cross-artifact joins, or any other behaviour beyond \"call this existing method,\" override\n * {@link SpooledArtifact.forgeTools} and mint the {@link @nhtio/adk!ArtifactTool} directly — do not try\n * to express it through a descriptor.\n *\n * Zero-arg methods are the exception: a descriptor with no `argsSchema` (or one that adds\n * only `callId`-adjacent fields you don't consume) works for any method that takes no\n * arguments, regardless of name.\n */\nexport interface ToolMethodDescriptor {\n /** Absolute tool name as exposed to the LLM (e.g. `'artifact_head'`). */\n name: string\n /** Method to invoke on the resolved artifact instance (e.g. `'head'`, `'json_get'`). */\n method: string\n /** Human-readable description passed to the model. Should mention \"in this turn\" so the model understands the artifact's lifecycle scope. */\n description: string\n /** Schema for the method's own args, NOT including `callId`. `forgeTools()` injects `callId`. */\n argsSchema?: ObjectSchema\n /** Optional formatter for non-string return values. Defaults: string → as-is; string[] → newline-join; number → `String(n)`; otherwise `JSON.stringify(value, null, 2)`. */\n serialise?: (result: unknown) => string\n}\n\nconst noArgsSchema = validator.object<Record<string, never>>({})\n\n/**\n * Default serialiser for {@link @nhtio/adk!ArtifactTool} handler return values when a descriptor does not\n * provide its own. Exported for reuse by subclass `forgeTools` overrides.\n *\n * @param result - The artifact-method return value.\n * @returns A string suitable for inclusion in an LLM tool-call response.\n */\nexport const defaultSerialise = (result: unknown): string => {\n if (result === undefined) return '(undefined)'\n if (result === null) return 'null'\n if (typeof result === 'string') return result\n if (Array.isArray(result) && result.every((r) => typeof r === 'string')) {\n if (result.length === 0) return '(empty list)'\n return (result as string[]).join('\\n')\n }\n if (typeof result === 'number') return String(result)\n return JSON.stringify(result, null, 2)\n}\n\nconst baseToolMethods: ReadonlyArray<ToolMethodDescriptor> = Object.freeze([\n {\n name: 'artifact_head',\n method: 'head',\n description:\n 'Return the first n lines of a spooled artifact produced earlier in this turn. Takes a callId selecting which artifact to inspect.',\n argsSchema: validator.object({\n n: validator.number().integer().min(1).default(10).description('Number of lines to return.'),\n }),\n },\n {\n name: 'artifact_tail',\n method: 'tail',\n description:\n 'Return the last n lines of a spooled artifact produced earlier in this turn. Takes a callId selecting which artifact to inspect.',\n argsSchema: validator.object({\n n: validator.number().integer().min(1).default(10).description('Number of lines to return.'),\n }),\n },\n {\n name: 'artifact_grep',\n method: 'grep',\n description:\n 'Return all lines matching a regular expression pattern from a spooled artifact produced earlier in this turn.',\n argsSchema: validator.object({\n pattern: validator\n .string()\n .required()\n .description('Regular expression pattern, applied via JavaScript RegExp.'),\n flags: validator\n .string()\n .pattern(/^[imsu]*$/)\n .optional()\n .description(\n \"Optional RegExp flags. Allowed: 'i' (case-insensitive), 'm' (multiline), 's' (dotAll), 'u' (unicode). 'g' and 'y' are disallowed because per-line matching is stateless.\"\n ),\n }),\n },\n {\n name: 'artifact_cat',\n method: 'cat',\n description:\n 'Return lines from a spooled artifact produced earlier in this turn, optionally bounded to a range.',\n argsSchema: validator.object({\n start: validator.number().integer().min(0).optional().description('Start line (inclusive).'),\n end: validator.number().integer().min(0).optional().description('End line (exclusive).'),\n }),\n },\n {\n name: 'artifact_byte_length',\n method: 'byteLength',\n description:\n 'Return the total byte length of a spooled artifact produced earlier in this turn.',\n argsSchema: noArgsSchema,\n },\n {\n name: 'artifact_line_count',\n method: 'lineCount',\n description: 'Return the total line count of a spooled artifact produced earlier in this turn.',\n argsSchema: noArgsSchema,\n },\n {\n name: 'artifact_estimate_tokens',\n method: 'estimateTokens',\n description:\n 'Estimate the total token count of a spooled artifact produced earlier in this turn under a named encoding.',\n argsSchema: validator.object({\n encoding: validator\n .string()\n .valid(...TokenEncoding)\n .required()\n .description('Token encoding identifier.'),\n }),\n },\n])\n\n/**\n * A lazy, line-oriented view over an arbitrary backing store.\n *\n * @remarks\n * All I/O methods are async to remain compatible with both in-memory and streaming\n * {@link @nhtio/adk!SpoolReader} implementations. Token estimation delegates to\n * {@link @nhtio/adk!Tokenizable.estimateTokens} — the same backends used elsewhere in the ADK.\n *\n * The class is read-only by design: mutation of the underlying data is the responsibility of the\n * producer that created the {@link @nhtio/adk!SpoolReader}, not the consumer reading from this artifact.\n */\nexport class SpooledArtifact {\n /**\n * The set of artifact-query methods this class surfaces via {@link SpooledArtifact.forgeTools}.\n *\n * @remarks\n * The base set covers the generic line-oriented operations every artifact supports:\n * `artifact_head`, `artifact_tail`, `artifact_grep`, `artifact_cat`, `artifact_byte_length`,\n * `artifact_line_count`, `artifact_estimate_tokens`. Each `toolMethods` array lists **only**\n * its own class's descriptors — subclasses do not concatenate inherited descriptors. The\n * subclass instead overrides {@link SpooledArtifact.forgeTools} to merge the base registry\n * (produced by `SpooledArtifact.forgeTools(ctx)`) with its own — see\n * {@link @nhtio/adk!SpooledJsonArtifact.forgeTools} and {@link @nhtio/adk!SpooledMarkdownArtifact.forgeTools} for\n * the canonical shape and the pattern downstream consumers should follow when building\n * their own `SpooledArtifact` subclasses.\n *\n * Tool names are absolute (not subclass-prefixed). Forged tools carry\n * `Tool.onCollision = 'replace'` so merging multiple subclasses' `forgeTools()` outputs is\n * silent — every same-named tool dispatches the same method on whatever artifact the\n * `callId` resolves to, so the overlap is behaviourally interchangeable.\n *\n * Frozen at module load.\n */\n public static toolMethods: ReadonlyArray<ToolMethodDescriptor> = baseToolMethods\n\n #reader: SpoolReader\n\n /**\n * @param reader - The backing store to read from.\n * @throws {@link @nhtio/adk!E_NOT_A_SPOOL_READER} when `reader` does not implement {@link @nhtio/adk!SpoolReader}.\n */\n constructor(reader: SpoolReader) {\n if (!implementsSpoolReader(reader)) {\n throw new E_NOT_A_SPOOL_READER()\n }\n this.#reader = reader\n }\n\n /**\n * Returns the line at the given 0-based index, or `undefined` when out of range.\n *\n * @remarks\n * Protected so subclasses can scan the backing store line-by-line without allocating\n * intermediate arrays. Delegates directly to the {@link @nhtio/adk!SpoolReader}.\n *\n * @param index - 0-based line index.\n * @returns The raw line string, or `undefined` when out of range.\n */\n protected async line(index: number): Promise<string | undefined> {\n return this.#reader.line(index)\n }\n\n /**\n * Returns `true` if `value` is a {@link SpooledArtifact} instance (including any subclass).\n *\n * @remarks\n * Uses the cross-realm-safe {@link @nhtio/adk!isInstanceOf} guard: `instanceof` first, then\n * `Symbol.hasInstance`, then a `constructor.name` fallback. Subclass instances (e.g.\n * {@link @nhtio/adk!SpooledJsonArtifact}) satisfy this guard because `instanceof` walks the prototype\n * chain. The fallbacks handle the dual-module-copy case where two distinct `SpooledArtifact`\n * classes coexist in the same realm (e.g. one bundled into a downstream library, one in the\n * consumer's `node_modules`).\n *\n * @param value - The value to test.\n * @returns `true` when `value` is a {@link SpooledArtifact} instance.\n */\n public static isSpooledArtifact(value: unknown): value is SpooledArtifact {\n return isInstanceOf(value, 'SpooledArtifact', SpooledArtifact)\n }\n\n /**\n * Returns `true` if `value` is a constructor function whose prototype chain includes\n * {@link SpooledArtifact} (including `SpooledArtifact` itself).\n *\n * @remarks\n * Used by {@link @nhtio/adk!Tool} to validate the optional `artifactConstructor` field. Performs an\n * `instanceof`-based check on the prototype chain; falls back to a duck-type test that looks\n * for the canonical SpooledArtifact instance methods on `value.prototype` for cross-realm\n * safety (constructors passed from a different module copy or VM context).\n *\n * @param value - The value to test.\n * @returns `true` when `value` is a constructor for `SpooledArtifact` or a subclass.\n */\n public static isSpooledArtifactConstructor(\n value: unknown\n ): value is SpooledArtifactConstructor<SpooledArtifact> {\n if (typeof value !== 'function') return false\n if (value === SpooledArtifact) return true\n const proto = (value as { prototype?: unknown }).prototype\n if (proto === undefined || proto === null) return false\n if (isInstanceOf(proto, 'SpooledArtifact', SpooledArtifact)) return true\n // Cross-realm duck-type fallback: prototype carries the canonical SpooledArtifact methods\n const methods = ['head', 'tail', 'grep', 'cat', 'byteLength', 'lineCount', 'estimateTokens']\n return methods.every((m) => typeof (proto as Record<string, unknown>)[m] === 'function')\n }\n\n /**\n * Returns the first `n` lines of the artifact.\n *\n * @remarks\n * If the artifact contains fewer than `n` lines, all available lines are returned. Matches the\n * behaviour of POSIX `head -n`.\n *\n * @param n - Number of lines to return. Defaults to 10.\n * @returns Array of line strings, without trailing newlines.\n */\n async head(n: number = 10): Promise<string[]> {\n const count = await this.#reader.lineCount()\n const limit = Math.min(n, count)\n const lines: string[] = []\n for (let i = 0; i < limit; i++) {\n const line = await this.#reader.line(i)\n if (line !== undefined) {\n lines.push(line)\n }\n }\n return lines\n }\n\n /**\n * Returns the last `n` lines of the artifact.\n *\n * @remarks\n * If the artifact contains fewer than `n` lines, all available lines are returned. Matches the\n * behaviour of POSIX `tail -n`.\n *\n * @param n - Number of lines to return. Defaults to 10.\n * @returns Array of line strings, without trailing newlines.\n */\n async tail(n: number = 10): Promise<string[]> {\n const count = await this.#reader.lineCount()\n const start = Math.max(0, count - n)\n const lines: string[] = []\n for (let i = start; i < count; i++) {\n const line = await this.#reader.line(i)\n if (line !== undefined) {\n lines.push(line)\n }\n }\n return lines\n }\n\n /**\n * Returns all lines that match `pattern`.\n *\n * @remarks\n * Behaves like POSIX `grep`: each line is tested against the pattern and included in the result\n * when it matches. The pattern is applied as a JavaScript `RegExp`; flags (e.g. case-\n * insensitivity) should be encoded in the expression itself.\n *\n * Stateful flags (`g`, `y`) on the supplied `RegExp` would normally cause `pattern.test()` to\n * advance `lastIndex` across calls, producing skipped matches and order-dependent results. To\n * keep the per-line semantics stateless, `grep` resets `pattern.lastIndex` to `0` before each\n * line test. The forged `artifact_grep` tool also rejects `g` and `y` flags up-front at schema\n * validation time.\n *\n * @param pattern - The regular expression to test each line against.\n * @returns Array of matching line strings, in order.\n */\n async grep(pattern: RegExp): Promise<string[]> {\n const count = await this.#reader.lineCount()\n const matches: string[] = []\n for (let i = 0; i < count; i++) {\n const line = await this.#reader.line(i)\n if (line !== undefined) {\n pattern.lastIndex = 0\n if (pattern.test(line)) {\n matches.push(line)\n }\n }\n }\n return matches\n }\n\n /**\n * Returns lines from the artifact, optionally bounded to a range.\n *\n * @remarks\n * Without arguments, returns all lines — equivalent to POSIX `cat`. With `start` and/or `end`,\n * behaves like `Array.prototype.slice`: `start` defaults to `0`, `end` defaults to the total\n * line count, and only lines in `[start, end)` are fetched from the backing store. For large\n * artifacts, prefer a bounded range or {@link SpooledArtifact.head} / {@link SpooledArtifact.tail}.\n *\n * @param start - 0-based start line index (inclusive). Defaults to `0`.\n * @param end - 0-based end line index (exclusive). Defaults to `lineCount()`.\n * @returns Array of line strings in the requested range.\n */\n async cat(start?: number, end?: number): Promise<string[]> {\n const count = await this.#reader.lineCount()\n const from = Math.max(0, start ?? 0)\n const to = Math.min(count, end ?? count)\n const lines: string[] = []\n for (let i = from; i < to; i++) {\n const line = await this.#reader.line(i)\n if (line !== undefined) {\n lines.push(line)\n }\n }\n return lines\n }\n\n /**\n * Returns the total byte length of the underlying data.\n *\n * @returns The byte length as reported by the {@link @nhtio/adk!SpoolReader}.\n */\n async byteLength(): Promise<number> {\n return this.#reader.byteLength()\n }\n\n /**\n * Returns the total number of lines in the artifact.\n *\n * @returns The line count as reported by the {@link @nhtio/adk!SpoolReader}.\n */\n async lineCount(): Promise<number> {\n return this.#reader.lineCount()\n }\n\n /**\n * Estimates the total token count of the artifact under `encoding`.\n *\n * @remarks\n * Reads the full byte-faithful content via {@link SpooledArtifact.asString} (which delegates to\n * {@link @nhtio/adk!SpoolReader.readAll}) and delegates to {@link @nhtio/adk!Tokenizable.estimateTokens}. The estimate\n * therefore reflects the actual source bytes — including trailing newlines and non-`\\n` line\n * terminators that the line-based {@link SpooledArtifact.cat} view would otherwise discard or\n * misrepresent.\n *\n * @param encoding - The encoding identifier to use for counting.\n * @returns The estimated number of tokens.\n */\n async estimateTokens(encoding: TokenEncoding): Promise<number> {\n const content = await this.#reader.readAll()\n return Tokenizable.estimateTokens(content, encoding)\n }\n\n /**\n * Returns the full artifact body as a single byte-faithful string.\n *\n * @remarks\n * Round-trip faithful to whatever bytes the {@link @nhtio/adk!SpoolReader} was constructed over —\n * preserves trailing newlines and non-`\\n` line terminators that {@link SpooledArtifact.cat}\n * discards via its line-based view. This is the canonical primitive for \"inline the artifact\n * content directly into a message\" use cases.\n *\n * `asString()` and the static `forgeTools(ctx)` factory on each subclass are independent\n * alternatives — a consumer chooses per turn whether to inline the body in a message\n * (`await tc.results.asString()`) or hand the model query tools\n * (`SpooledArtifact.forgeTools(ctx)`). Neither calls the other; either works with neither.\n *\n * @returns The full content as a single string.\n */\n async asString(): Promise<string> {\n return this.#reader.readAll()\n }\n\n /**\n * Forges a fresh {@link @nhtio/adk!ToolRegistry} of ephemeral {@link @nhtio/adk!ArtifactTool} instances that let the\n * LLM query artifacts already present in `ctx.turnToolCalls`.\n *\n * @remarks\n * Standard subclass extension pattern — each class owns only its own `toolMethods` and its\n * own `forgeTools`. The base `SpooledArtifact.forgeTools(ctx)` narrows the `callId` enum to\n * any `tc.results instanceof SpooledArtifact` (so subclass instances are included — that's\n * the whole point of inheritance) and dispatches the seven base methods (`head`, `tail`,\n * `grep`, `cat`, `byteLength`, `lineCount`, `estimateTokens`) on the resolved artifact.\n * Subclasses override `forgeTools` to call this static first and then register their own\n * tools on the returned registry — see {@link @nhtio/adk!SpooledJsonArtifact.forgeTools} and\n * {@link @nhtio/adk!SpooledMarkdownArtifact.forgeTools} for the canonical shape. There is no\n * `requiresSubclass` field, no helper indirection, and no `this`-based class narrowing —\n * just plain `instanceof ThisClass` at each subclass's own filter site.\n *\n * For each descriptor in this class's `toolMethods`, the factory:\n *\n * 1. Walks `ctx.turnToolCalls` to find `ToolCall`s whose `results instanceof SpooledArtifact`.\n * `ToolCall`s flagged `fromArtifactTool === true` are excluded — they carry a\n * {@link @nhtio/adk!Tokenizable}, not a `SpooledArtifact`, and including them would let the model\n * `artifact_grep` on a previous `artifact_grep` result (an infinite-recursion hazard with\n * no semantic value).\n * 2. Returns an empty registry if no compatible callIds are found — no point shipping tools\n * whose `callId` enum is empty.\n * 3. Otherwise mints an {@link @nhtio/adk!ArtifactTool} with `ephemeral: true` and `onCollision: 'replace'`\n * so multiple `Subclass.forgeTools(ctx)` outputs merge silently. The tool's `inputSchema`\n * includes a required `callId` field with `.valid(...compatibleIds)`, plus the descriptor's\n * own `argsSchema` fields.\n *\n * The handler resolves the artifact via `[...ctx.turnToolCalls].find(t => t.id === callId)`,\n * dispatches the descriptor's method, and serialises the return value (string → as-is;\n * string[] → newline-join; number → `String(n)`; otherwise `JSON.stringify(value, null, 2)`;\n * `descriptor.serialise` overrides the defaults). `grep` is special-cased: the handler\n * constructs `new RegExp(pattern, flags ?? '')` before invoking the artifact's `grep` method.\n *\n * The returned registry must be merged into the consumer's main registry and the main\n * registry must be bound to `ctx` via {@link @nhtio/adk!ToolRegistry.bindContext}:\n *\n * ```ts\n * const executor: DispatchExecutorFn = async (ctx) => {\n * const forged = SpooledArtifact.forgeTools(ctx)\n * const merged = ToolRegistry.merge([main, forged])\n * main.bindContext(ctx)\n * const result = await llm.invoke({ tools: merged.all(), ... })\n * ctx.ack() // ← ephemeral cleanup fires here\n * }\n * ```\n *\n * @warning You **must** call `registry.bindContext(ctx)` on the registry hosting these tools,\n * or ephemeral cleanup will not run and the `callId` enum in subsequent executor calls will\n * be stale (excluding new tool calls produced in the meantime).\n *\n * @param ctx - The execution context whose `turnToolCalls` snapshot defines the `callId` enum.\n * @returns A fresh `ToolRegistry`. Empty when `turnToolCalls` contains no compatible artifacts.\n *\n * @see {@link @nhtio/adk!ToolRegistry.bindContext}\n * @see {@link @nhtio/adk!ToolRegistry.merge}\n * @see {@link @nhtio/adk!DispatchContext.onAck}\n */\n public static forgeTools(ctx: DispatchContext): ToolRegistry {\n const requires: SpooledArtifactConstructor = SpooledArtifact\n const calls = [...ctx.turnToolCalls]\n const compatibleIds = calls\n .filter((tc) => !tc.fromArtifactTool && isInstanceOf(tc.results, requires.name, requires))\n .map((tc) => tc.id)\n if (compatibleIds.length === 0) return new ToolRegistry([])\n\n const tools: ArtifactTool[] = []\n for (const descriptor of this.toolMethods) {\n const callIdSchema = validator\n .string()\n .valid(...compatibleIds)\n .required()\n .description('ToolCall id of the artifact to query.')\n\n const argsSchema = (descriptor.argsSchema ?? noArgsSchema).append({\n callId: callIdSchema,\n })\n\n const serialise = descriptor.serialise ?? defaultSerialise\n\n const tool = new ArtifactTool({\n name: descriptor.name,\n description: descriptor.description,\n inputSchema: argsSchema,\n ephemeral: true,\n onCollision: 'replace',\n handler: async (rawArgs, ctxInner) => {\n const args = rawArgs as Record<string, unknown> & { callId: string }\n const tc = [...ctxInner.turnToolCalls].find((t) => t.id === args.callId)\n if (!tc) {\n return `Error: no tool call with id ${args.callId} in this turn`\n }\n const artifact = tc.results\n if (!isInstanceOf(artifact, requires.name, requires)) {\n return `Error: tool call ${args.callId} results are not a ${requires.name} instance`\n }\n const methodArgs: unknown[] = []\n if (descriptor.method === 'grep') {\n const pattern = args.pattern as string\n const flags = (args.flags as string | undefined) ?? ''\n methodArgs.push(new RegExp(pattern, flags))\n } else if (descriptor.method === 'head' || descriptor.method === 'tail') {\n methodArgs.push((args.n as number | undefined) ?? 10)\n } else if (descriptor.method === 'cat') {\n methodArgs.push(args.start as number | undefined, args.end as number | undefined)\n } else if (descriptor.method === 'estimateTokens') {\n methodArgs.push(args.encoding as TokenEncoding)\n }\n const fn = (artifact as unknown as Record<string, (...a: unknown[]) => unknown>)[\n descriptor.method\n ]\n if (typeof fn !== 'function') {\n return `Error: artifact has no method ${descriptor.method}`\n }\n const result = await Promise.resolve(fn.apply(artifact, methodArgs))\n return serialise(result)\n },\n })\n tools.push(tool)\n }\n return new ToolRegistry(tools)\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA0FA,IAAM,wBAAwB,UAAU,OAA0D;CAChG,MAAM,UAAU,OAAO,EAAE,SAAS;CAClC,aAAa,UAAU,OAAO,EAAE,SAAS;CACzC,aAA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AA+B,KAAK,OAAO;KAEpD,MAAM,WAAW,GAAG;KACpB,IAAI,CAAC,aAAa,UAAU,SAAS,MAAM,QAAQ,GACjD,OAAO,oBAAoB,KAAK,OAAO,qBAAqB,SAAS,KAAK;KAE5E,MAAM,aAAwB,CAAC;KAC/B,IAAI,WAAW,WAAW,QAAQ;MAChC,MAAM,UAAU,KAAK;MACrB,MAAM,QAAS,KAAK,SAAgC;MACpD,WAAW,KAAK,IAAI,OAAO,SAAS,KAAK,CAAC;KAC5C,OAAO,IAAI,WAAW,WAAW,UAAU,WAAW,WAAW,QAC/D,WAAW,KAAM,KAAK,KAA4B,EAAE;UAC/C,IAAI,WAAW,WAAW,OAC/B,WAAW,KAAK,KAAK,OAA6B,KAAK,GAAyB;UAC3E,IAAI,WAAW,WAAW,kBAC/B,WAAW,KAAK,KAAK,QAAyB;KAEhD,MAAM,KAAM,SACV,WAAW;KAEb,IAAI,OAAO,OAAO,YAChB,OAAO,iCAAiC,WAAW;KAGrD,OAAO,UAAU,MADI,QAAQ,QAAQ,GAAG,MAAM,UAAU,UAAU,CAAC,CAC5C;IACzB;GACF,CAAC;GACD,MAAM,KAAK,IAAI;EACjB;EACA,OAAO,IAAI,aAAa,KAAK;CAC/B;AACF"}
1
+ {"version":3,"file":"spooled_artifact-7eePq7JA.mjs","names":["#reader"],"sources":["../src/lib/classes/artifact_tool.ts","../src/lib/contracts/spool_reader.ts","../src/lib/classes/spooled_artifact.ts"],"sourcesContent":["import { Tool } from './tool'\nimport { validator } from '@nhtio/validation'\nimport { isInstanceOf } from '../utils/guards'\nimport { E_INVALID_INITIAL_TOOL_VALUE } from '../exceptions/runtime'\nimport { validateOrThrow, ValidationException } from '../utils/validation'\nimport type { Registry } from './registry'\nimport type { Schema } from '@nhtio/validation'\nimport type { Tokenizable } from './tokenizable'\nimport type { DispatchContext } from '../contracts/dispatch_context'\n\n/**\n * The execution function for an {@link ArtifactTool}.\n *\n * @remarks\n * Identical to the base tool handler except the return type is narrowed to\n * `string | Tokenizable | Promise<string | Tokenizable>`. Forged artifact-query tools emit\n * model-visible strings — the ADK wraps a bare-string return into a {@link @nhtio/adk!Tokenizable}\n * at the result-wrapping site so downstream code can rely on\n * `ToolCall.results instanceof Tokenizable` for every `ArtifactTool` invocation.\n */\nexport type ArtifactToolHandler = (\n args: unknown,\n ctx: DispatchContext,\n meta: Registry\n) => string | Tokenizable | Promise<string | Tokenizable>\n\n/**\n * Plain input object supplied to {@link ArtifactTool} at construction time.\n *\n * @remarks\n * Mirrors the base `RawTool` except `artifactConstructor` is forbidden — an `ArtifactTool`\n * emits a {@link @nhtio/adk!Tokenizable} directly into `ToolCall.results` and explicitly opts out of\n * `SpooledArtifact` wrapping. The forbidden field is enforced by {@link ArtifactTool.schema}\n * at construction time.\n */\nexport interface RawArtifactTool {\n /** Unique identifier used in LLM tool definitions. Recommend lowercase snake_case. */\n name: string\n /** Human-readable description passed to the model to explain what the tool does. */\n description: string\n /** @nhtio/validation schema for the tool's input arguments. */\n inputSchema: Schema\n /** Execution function. Returns a string or {@link @nhtio/adk!Tokenizable}; the ADK wraps a bare string into a `Tokenizable` at the result-wrapping site. */\n handler: ArtifactToolHandler\n /** Optional arbitrary metadata for this tool. Defaults to `{}`. */\n meta?: Record<string, unknown>\n /**\n * When `true`, marks this tool as owned by a specific {@link @nhtio/adk!DispatchContext}.\n *\n * @remarks\n * `ArtifactTool` instances produced by `SpooledArtifact.forgeTools(ctx)` set this to `true`\n * so that `ToolRegistry.pruneEphemeral()` drops them at ctx-completion.\n *\n * @defaultValue `false`\n */\n ephemeral?: boolean\n /**\n * When `true`, declares that this tool's output should be treated as **trusted developer/user\n * intent** rather than as untrusted third-party text when surfaced to the model.\n *\n * @remarks\n * Forged artifact-query tools default to `false` because their results are derived from\n * spooled artifact bodies — which may themselves be untrusted upstream tool output. The\n * trust signal does not promote handle-query results above the trust tier of the underlying\n * artifact.\n *\n * @defaultValue `false`\n */\n trusted?: boolean\n /**\n * Self-declared merge collision policy honoured by `ToolRegistry.merge`.\n *\n * @remarks\n * Forged artifact-query tools set this to `'replace'` so that merging multiple\n * `Subclass.forgeTools(ctx)` outputs (whose base-method tools overlap by name) resolves\n * silently — the descriptors, snapshot, and handler behaviour are interchangeable across\n * subclasses, so replacement is a behavioural no-op.\n *\n * @defaultValue `'throw'`\n */\n onCollision?: 'throw' | 'replace' | 'keep'\n}\n\n/**\n * Validator schema for a {@link RawArtifactTool}.\n *\n * @remarks\n * Mirrors the base tool schema but explicitly forbids `artifactConstructor` — the entire\n * point of `ArtifactTool` is to opt out of `SpooledArtifact` wrapping.\n */\nconst rawArtifactToolSchema = validator.object<RawArtifactTool & { artifactConstructor?: never }>({\n name: validator.string().required(),\n description: validator.string().required(),\n inputSchema: validator\n .any()\n .custom((value, helpers) => {\n if (validator.isSchema(value) && (value as any).type === 'object') return value\n return helpers.error('any.invalid')\n })\n .required(),\n handler: validator.function().required(),\n // eslint-disable-next-line adk/require-validator-any-required -- map value type-arg: meta holds arbitrary values; disposition is set by .default({}) on the object\n meta: validator.object().pattern(validator.string(), validator.any()).default({}),\n ephemeral: validator.boolean().default(false),\n trusted: validator.boolean().default(false),\n onCollision: validator.string().valid('throw', 'replace', 'keep').default('throw'),\n artifactConstructor: validator.any().forbidden(),\n})\n\n/**\n * A {@link @nhtio/adk!Tool} subclass whose handler return value is wrapped directly in a\n * {@link @nhtio/adk!Tokenizable} (not a {@link @nhtio/adk!SpooledArtifact}) when it\n * lands on `ToolCall.results`.\n *\n * @remarks\n * `ArtifactTool` is the canonical producer for **forged artifact-query tools** — the tools\n * `SpooledArtifact.forgeTools(ctx)` emits so the model can `head`, `tail`, `grep`, `json_get`,\n * `md_headings` (etc.) an artifact that is already in `ctx.turnToolCalls`.\n *\n * The difference from {@link @nhtio/adk!Tool} is structural, not stylistic:\n *\n * - A normal `Tool`'s handler returns bytes the ADK wraps in a fresh `SpooledArtifact`.\n * The artifact lands in `ToolCall.results`, joins `ctx.turnToolCalls`, and is itself a\n * first-class queryable artifact in the turn.\n * - An `ArtifactTool`'s handler returns a string that is **already the model-visible answer**\n * to a query against an existing artifact. The ADK wraps it in a `Tokenizable` rather\n * than a `SpooledArtifact`; nothing new is queryable on its own. Subsequent\n * `forgeTools(ctx)` calls exclude `ToolCall`s produced by an `ArtifactTool` from the\n * `callId` enum (via the `ToolCall.fromArtifactTool` marker) — this is the structural fix\n * that breaks the otherwise-recursive grep-on-the-grep-result loop.\n *\n * Consumers who want to build their own artifact-query tools (e.g. for a domain-specific\n * spooled subclass not shipped by the ADK) should extend or instantiate this class.\n */\nexport class ArtifactTool extends Tool {\n /**\n * Validator schema that accepts a {@link RawArtifactTool} object.\n *\n * @remarks\n * Differs from {@link @nhtio/adk!Tool.schema} by forbidding `artifactConstructor` — wrapping is\n * exactly the thing this class opts out of. Typed identically to {@link @nhtio/adk!Tool.schema} so the\n * subclass relationship `class ArtifactTool extends Tool` remains structurally sound; the\n * runtime validation rules still differ as declared by `rawArtifactToolSchema`.\n */\n public static schema = rawArtifactToolSchema as unknown as typeof Tool.schema\n\n /**\n * Returns `true` if `value` is an {@link ArtifactTool} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances\n * created in a different module copy or VM context.\n *\n * @param value - The value to test.\n * @returns `true` when `value` is an {@link ArtifactTool} instance.\n */\n public static isArtifactTool(value: unknown): value is ArtifactTool {\n return isInstanceOf(value, 'ArtifactTool', ArtifactTool)\n }\n\n /**\n * @param raw - Raw tool input validated against {@link ArtifactTool.schema}.\n *\n * @throws {@link @nhtio/adk!E_INVALID_INITIAL_TOOL_VALUE} when `raw` does not satisfy\n * {@link ArtifactTool.schema} (most commonly, when `artifactConstructor` is supplied — it is\n * explicitly forbidden on this class) or when the base {@link @nhtio/adk!Tool} constructor rejects the\n * input for any reason.\n */\n constructor(raw: RawArtifactTool) {\n // Enforce the forbidden `artifactConstructor` field up-front so the error reports against\n // ArtifactTool's contract, not the base Tool's. The base Tool constructor re-validates\n // against its own schema and stores the resolved fields.\n try {\n validateOrThrow(rawArtifactToolSchema, raw, true)\n } catch (err) {\n if (isInstanceOf(err, 'ValidationException', ValidationException)) {\n throw new E_INVALID_INITIAL_TOOL_VALUE({ cause: err })\n }\n throw err\n }\n super(raw as never)\n }\n}\n","import { validator } from '@nhtio/validation'\nimport { passesSchema } from '../utils/validation'\n\n/**\n * Backing store contract for a {@link @nhtio/adk!SpooledArtifact}.\n *\n * @remarks\n * Implementations may read from memory, a file handle, a network stream, or any other byte\n * source. The interface is intentionally minimal — the artifact layer handles all higher-level\n * operations (`head`, `tail`, `grep`, etc.) by composing calls to these three primitives.\n *\n * Line indexing is 0-based. Implementations must return `undefined` from {@link SpoolReader.line}\n * when the index is out of range rather than throwing.\n *\n * All three methods may be synchronous or asynchronous to accommodate both in-memory and I/O-\n * backed implementations without forcing unnecessary promise overhead on simple cases.\n */\nexport interface SpoolReader {\n /**\n * Returns the line at the given 0-based index, or `undefined` when out of range.\n *\n * @param index - 0-based line index.\n * @returns The raw line string (without trailing newline), or `undefined`.\n */\n line(index: number): string | undefined | Promise<string | undefined>\n\n /**\n * Returns the total number of bytes in the underlying data.\n *\n * @remarks\n * Used for reporting and token-estimation purposes. Byte length is distinct from character\n * length for multi-byte encodings.\n *\n * @returns The byte length of the underlying data.\n */\n byteLength(): number | Promise<number>\n\n /**\n * Returns the total number of lines in the underlying data.\n *\n * @remarks\n * Required so consumers know when to stop iterating; the line count must remain stable for the\n * lifetime of the reader.\n *\n * @returns The total line count.\n */\n lineCount(): number | Promise<number>\n\n /**\n * Returns the full underlying content as a single decoded string, byte-faithful to the source.\n *\n * @remarks\n * Unlike {@link SpoolReader.line}, this method preserves trailing newlines and any non-`\\n`\n * line terminators (e.g. `\\r\\n`) present in the original bytes. It is the primitive that\n * powers `SpooledArtifact.asString()` — the round-trip-faithful alternative to assembling\n * the artifact body from per-line reads.\n *\n * Implementations should make this O(n) in the size of the underlying data and may cache the\n * result if the read source is durable. Streaming implementations may choose not to cache.\n *\n * @returns The full underlying content as a single string.\n */\n readAll(): string | Promise<string>\n}\n\n/**\n * Validator schema used to validate a {@link SpoolReader} value.\n *\n * @remarks\n * Because `SpoolReader` is a structural interface with no associated constructor, validation is\n * duck-typed: the value must be an object, class instance, or function with `line`, `byteLength`,\n * and `lineCount` present as callable properties. Arity is not enforced — implementations may add\n * optional parameters beyond the contract.\n */\nexport const spoolReaderSchema = validator\n .any()\n .required()\n .custom((value, helpers) => {\n if (\n value !== null &&\n value !== undefined &&\n typeof (value as any).line === 'function' &&\n typeof (value as any).byteLength === 'function' &&\n typeof (value as any).lineCount === 'function' &&\n typeof (value as any).readAll === 'function'\n ) {\n return value as SpoolReader\n }\n return helpers.error('any.invalid')\n })\n\n/**\n * Returns `true` if `value` implements the {@link SpoolReader} interface.\n *\n * @remarks\n * Duck-typed: checks that `value` is non-null with `line`, `byteLength`, `lineCount`, and\n * `readAll` as callable functions. Does not use `instanceof` — there is no `SpoolReader`\n * constructor.\n *\n * @param value - The value to test.\n * @returns `true` when `value` conforms to the {@link SpoolReader} interface.\n */\nexport const implementsSpoolReader = (value: unknown): value is SpoolReader => {\n return passesSchema(spoolReaderSchema, value)\n}\n","import { validator } from '@nhtio/validation'\nimport { isInstanceOf } from '../utils/guards'\nimport { ArtifactTool } from './artifact_tool'\nimport { ToolRegistry } from './tool_registry'\nimport { Tokenizable, TokenEncoding } from './tokenizable'\nimport { E_NOT_A_SPOOL_READER } from '../exceptions/runtime'\nimport { implementsSpoolReader } from '../contracts/spool_reader'\nimport type { ObjectSchema } from '@nhtio/validation'\nimport type { SpoolReader } from '../contracts/spool_reader'\nimport type { DispatchContext } from '../contracts/dispatch_context'\n\n/**\n * Constructor signature for {@link SpooledArtifact} and any subclass.\n *\n * @remarks\n * Used by {@link @nhtio/adk!Tool} to declare the artifact subclass the consumer should use when wrapping\n * the handler's serialised output. The variadic rest parameter accommodates subclass-specific\n * constructor arguments (e.g. `SpooledJsonArtifact(reader, format?)`).\n *\n * @typeParam A - The {@link SpooledArtifact} subtype the constructor produces.\n */\nexport type SpooledArtifactConstructor<A extends SpooledArtifact = SpooledArtifact> = new (\n reader: SpoolReader,\n ...rest: any[]\n) => A\n\n/**\n * Metadata table entry for one of the artifact's existing query methods, used by\n * {@link SpooledArtifact.forgeTools} to surface that method as an {@link @nhtio/adk!ArtifactTool}.\n *\n * @remarks\n * This is a metadata shape, not a general method → tool pipeline. `forgeTools` knows how to\n * marshal arguments for a fixed, closed set of method names (the base seven on\n * {@link SpooledArtifact} and the JSON/Markdown methods on the bundled subclasses); a\n * descriptor is the place to attach a tool name, description, args schema, and optional\n * serializer to one of those methods. Adding a descriptor for a method whose name is not\n * in that closed set will produce a tool whose handler invokes the method with no arguments.\n *\n * For new methods that require custom argument marshalling, branching, multi-step logic,\n * cross-artifact joins, or any other behaviour beyond \"call this existing method,\" override\n * {@link SpooledArtifact.forgeTools} and mint the {@link @nhtio/adk!ArtifactTool} directly — do not try\n * to express it through a descriptor.\n *\n * Zero-arg methods are the exception: a descriptor with no `argsSchema` (or one that adds\n * only `callId`-adjacent fields you don't consume) works for any method that takes no\n * arguments, regardless of name.\n */\nexport interface ToolMethodDescriptor {\n /** Absolute tool name as exposed to the LLM (e.g. `'artifact_head'`). */\n name: string\n /** Method to invoke on the resolved artifact instance (e.g. `'head'`, `'json_get'`). */\n method: string\n /** Human-readable description passed to the model. Should mention \"in this turn\" so the model understands the artifact's lifecycle scope. */\n description: string\n /** Schema for the method's own args, NOT including `callId`. `forgeTools()` injects `callId`. */\n argsSchema?: ObjectSchema\n /** Optional formatter for non-string return values. Defaults: string → as-is; string[] → newline-join; number → `String(n)`; otherwise `JSON.stringify(value, null, 2)`. */\n serialise?: (result: unknown) => string\n}\n\nconst noArgsSchema = validator.object<Record<string, never>>({})\n\n/**\n * Default serialiser for {@link @nhtio/adk!ArtifactTool} handler return values when a descriptor does not\n * provide its own. Exported for reuse by subclass `forgeTools` overrides.\n *\n * @param result - The artifact-method return value.\n * @returns A string suitable for inclusion in an LLM tool-call response.\n */\nexport const defaultSerialise = (result: unknown): string => {\n if (result === undefined) return '(undefined)'\n if (result === null) return 'null'\n if (typeof result === 'string') return result\n if (Array.isArray(result) && result.every((r) => typeof r === 'string')) {\n if (result.length === 0) return '(empty list)'\n return (result as string[]).join('\\n')\n }\n if (typeof result === 'number') return String(result)\n return JSON.stringify(result, null, 2)\n}\n\nconst baseToolMethods: ReadonlyArray<ToolMethodDescriptor> = Object.freeze([\n {\n name: 'artifact_head',\n method: 'head',\n description:\n 'Return the first n lines of a spooled artifact produced earlier in this turn. Takes a callId selecting which artifact to inspect.',\n argsSchema: validator.object({\n n: validator.number().integer().min(1).default(10).description('Number of lines to return.'),\n }),\n },\n {\n name: 'artifact_tail',\n method: 'tail',\n description:\n 'Return the last n lines of a spooled artifact produced earlier in this turn. Takes a callId selecting which artifact to inspect.',\n argsSchema: validator.object({\n n: validator.number().integer().min(1).default(10).description('Number of lines to return.'),\n }),\n },\n {\n name: 'artifact_grep',\n method: 'grep',\n description:\n 'Return all lines matching a regular expression pattern from a spooled artifact produced earlier in this turn.',\n argsSchema: validator.object({\n pattern: validator\n .string()\n .required()\n .description('Regular expression pattern, applied via JavaScript RegExp.'),\n flags: validator\n .string()\n .pattern(/^[imsu]*$/)\n .optional()\n .description(\n \"Optional RegExp flags. Allowed: 'i' (case-insensitive), 'm' (multiline), 's' (dotAll), 'u' (unicode). 'g' and 'y' are disallowed because per-line matching is stateless.\"\n ),\n }),\n },\n {\n name: 'artifact_cat',\n method: 'cat',\n description:\n 'Return lines from a spooled artifact produced earlier in this turn, optionally bounded to a range.',\n argsSchema: validator.object({\n start: validator.number().integer().min(0).optional().description('Start line (inclusive).'),\n end: validator.number().integer().min(0).optional().description('End line (exclusive).'),\n }),\n },\n {\n name: 'artifact_byte_length',\n method: 'byteLength',\n description:\n 'Return the total byte length of a spooled artifact produced earlier in this turn.',\n argsSchema: noArgsSchema,\n },\n {\n name: 'artifact_line_count',\n method: 'lineCount',\n description: 'Return the total line count of a spooled artifact produced earlier in this turn.',\n argsSchema: noArgsSchema,\n },\n {\n name: 'artifact_estimate_tokens',\n method: 'estimateTokens',\n description:\n 'Estimate the total token count of a spooled artifact produced earlier in this turn under a named encoding.',\n argsSchema: validator.object({\n encoding: validator\n .string()\n .valid(...TokenEncoding)\n .required()\n .description('Token encoding identifier.'),\n }),\n },\n])\n\n/**\n * A lazy, line-oriented view over an arbitrary backing store.\n *\n * @remarks\n * All I/O methods are async to remain compatible with both in-memory and streaming\n * {@link @nhtio/adk!SpoolReader} implementations. Token estimation delegates to\n * {@link @nhtio/adk!Tokenizable.estimateTokens} — the same backends used elsewhere in the ADK.\n *\n * The class is read-only by design: mutation of the underlying data is the responsibility of the\n * producer that created the {@link @nhtio/adk!SpoolReader}, not the consumer reading from this artifact.\n */\nexport class SpooledArtifact {\n /**\n * The set of artifact-query methods this class surfaces via {@link SpooledArtifact.forgeTools}.\n *\n * @remarks\n * The base set covers the generic line-oriented operations every artifact supports:\n * `artifact_head`, `artifact_tail`, `artifact_grep`, `artifact_cat`, `artifact_byte_length`,\n * `artifact_line_count`, `artifact_estimate_tokens`. Each `toolMethods` array lists **only**\n * its own class's descriptors — subclasses do not concatenate inherited descriptors. The\n * subclass instead overrides {@link SpooledArtifact.forgeTools} to merge the base registry\n * (produced by `SpooledArtifact.forgeTools(ctx)`) with its own — see\n * {@link @nhtio/adk!SpooledJsonArtifact.forgeTools} and {@link @nhtio/adk!SpooledMarkdownArtifact.forgeTools} for\n * the canonical shape and the pattern downstream consumers should follow when building\n * their own `SpooledArtifact` subclasses.\n *\n * Tool names are absolute (not subclass-prefixed). Forged tools carry\n * `Tool.onCollision = 'replace'` so merging multiple subclasses' `forgeTools()` outputs is\n * silent — every same-named tool dispatches the same method on whatever artifact the\n * `callId` resolves to, so the overlap is behaviourally interchangeable.\n *\n * Frozen at module load.\n */\n public static toolMethods: ReadonlyArray<ToolMethodDescriptor> = baseToolMethods\n\n #reader: SpoolReader\n\n /**\n * @param reader - The backing store to read from.\n * @throws {@link @nhtio/adk!E_NOT_A_SPOOL_READER} when `reader` does not implement {@link @nhtio/adk!SpoolReader}.\n */\n constructor(reader: SpoolReader) {\n if (!implementsSpoolReader(reader)) {\n throw new E_NOT_A_SPOOL_READER()\n }\n this.#reader = reader\n }\n\n /**\n * Returns the line at the given 0-based index, or `undefined` when out of range.\n *\n * @remarks\n * Protected so subclasses can scan the backing store line-by-line without allocating\n * intermediate arrays. Delegates directly to the {@link @nhtio/adk!SpoolReader}.\n *\n * @param index - 0-based line index.\n * @returns The raw line string, or `undefined` when out of range.\n */\n protected async line(index: number): Promise<string | undefined> {\n return this.#reader.line(index)\n }\n\n /**\n * Returns `true` if `value` is a {@link SpooledArtifact} instance (including any subclass).\n *\n * @remarks\n * Uses the cross-realm-safe {@link @nhtio/adk!isInstanceOf} guard: `instanceof` first, then\n * `Symbol.hasInstance`, then a `constructor.name` fallback. Subclass instances (e.g.\n * {@link @nhtio/adk!SpooledJsonArtifact}) satisfy this guard because `instanceof` walks the prototype\n * chain. The fallbacks handle the dual-module-copy case where two distinct `SpooledArtifact`\n * classes coexist in the same realm (e.g. one bundled into a downstream library, one in the\n * consumer's `node_modules`).\n *\n * @param value - The value to test.\n * @returns `true` when `value` is a {@link SpooledArtifact} instance.\n */\n public static isSpooledArtifact(value: unknown): value is SpooledArtifact {\n return isInstanceOf(value, 'SpooledArtifact', SpooledArtifact)\n }\n\n /**\n * Returns `true` if `value` is a constructor function whose prototype chain includes\n * {@link SpooledArtifact} (including `SpooledArtifact` itself).\n *\n * @remarks\n * Used by {@link @nhtio/adk!Tool} to validate the optional `artifactConstructor` field. Performs an\n * `instanceof`-based check on the prototype chain; falls back to a duck-type test that looks\n * for the canonical SpooledArtifact instance methods on `value.prototype` for cross-realm\n * safety (constructors passed from a different module copy or VM context).\n *\n * @param value - The value to test.\n * @returns `true` when `value` is a constructor for `SpooledArtifact` or a subclass.\n */\n public static isSpooledArtifactConstructor(\n value: unknown\n ): value is SpooledArtifactConstructor<SpooledArtifact> {\n if (typeof value !== 'function') return false\n if (value === SpooledArtifact) return true\n const proto = (value as { prototype?: unknown }).prototype\n if (proto === undefined || proto === null) return false\n if (isInstanceOf(proto, 'SpooledArtifact', SpooledArtifact)) return true\n // Cross-realm duck-type fallback: prototype carries the canonical SpooledArtifact methods\n const methods = ['head', 'tail', 'grep', 'cat', 'byteLength', 'lineCount', 'estimateTokens']\n return methods.every((m) => typeof (proto as Record<string, unknown>)[m] === 'function')\n }\n\n /**\n * Returns the first `n` lines of the artifact.\n *\n * @remarks\n * If the artifact contains fewer than `n` lines, all available lines are returned. Matches the\n * behaviour of POSIX `head -n`.\n *\n * @param n - Number of lines to return. Defaults to 10.\n * @returns Array of line strings, without trailing newlines.\n */\n async head(n: number = 10): Promise<string[]> {\n const count = await this.#reader.lineCount()\n const limit = Math.min(n, count)\n const lines: string[] = []\n for (let i = 0; i < limit; i++) {\n const line = await this.#reader.line(i)\n if (line !== undefined) {\n lines.push(line)\n }\n }\n return lines\n }\n\n /**\n * Returns the last `n` lines of the artifact.\n *\n * @remarks\n * If the artifact contains fewer than `n` lines, all available lines are returned. Matches the\n * behaviour of POSIX `tail -n`.\n *\n * @param n - Number of lines to return. Defaults to 10.\n * @returns Array of line strings, without trailing newlines.\n */\n async tail(n: number = 10): Promise<string[]> {\n const count = await this.#reader.lineCount()\n const start = Math.max(0, count - n)\n const lines: string[] = []\n for (let i = start; i < count; i++) {\n const line = await this.#reader.line(i)\n if (line !== undefined) {\n lines.push(line)\n }\n }\n return lines\n }\n\n /**\n * Returns all lines that match `pattern`.\n *\n * @remarks\n * Behaves like POSIX `grep`: each line is tested against the pattern and included in the result\n * when it matches. The pattern is applied as a JavaScript `RegExp`; flags (e.g. case-\n * insensitivity) should be encoded in the expression itself.\n *\n * Stateful flags (`g`, `y`) on the supplied `RegExp` would normally cause `pattern.test()` to\n * advance `lastIndex` across calls, producing skipped matches and order-dependent results. To\n * keep the per-line semantics stateless, `grep` resets `pattern.lastIndex` to `0` before each\n * line test. The forged `artifact_grep` tool also rejects `g` and `y` flags up-front at schema\n * validation time.\n *\n * @param pattern - The regular expression to test each line against.\n * @returns Array of matching line strings, in order.\n */\n async grep(pattern: RegExp): Promise<string[]> {\n const count = await this.#reader.lineCount()\n const matches: string[] = []\n for (let i = 0; i < count; i++) {\n const line = await this.#reader.line(i)\n if (line !== undefined) {\n pattern.lastIndex = 0\n if (pattern.test(line)) {\n matches.push(line)\n }\n }\n }\n return matches\n }\n\n /**\n * Returns lines from the artifact, optionally bounded to a range.\n *\n * @remarks\n * Without arguments, returns all lines — equivalent to POSIX `cat`. With `start` and/or `end`,\n * behaves like `Array.prototype.slice`: `start` defaults to `0`, `end` defaults to the total\n * line count, and only lines in `[start, end)` are fetched from the backing store. For large\n * artifacts, prefer a bounded range or {@link SpooledArtifact.head} / {@link SpooledArtifact.tail}.\n *\n * @param start - 0-based start line index (inclusive). Defaults to `0`.\n * @param end - 0-based end line index (exclusive). Defaults to `lineCount()`.\n * @returns Array of line strings in the requested range.\n */\n async cat(start?: number, end?: number): Promise<string[]> {\n const count = await this.#reader.lineCount()\n const from = Math.max(0, start ?? 0)\n const to = Math.min(count, end ?? count)\n const lines: string[] = []\n for (let i = from; i < to; i++) {\n const line = await this.#reader.line(i)\n if (line !== undefined) {\n lines.push(line)\n }\n }\n return lines\n }\n\n /**\n * Returns the total byte length of the underlying data.\n *\n * @returns The byte length as reported by the {@link @nhtio/adk!SpoolReader}.\n */\n async byteLength(): Promise<number> {\n return this.#reader.byteLength()\n }\n\n /**\n * Returns the total number of lines in the artifact.\n *\n * @returns The line count as reported by the {@link @nhtio/adk!SpoolReader}.\n */\n async lineCount(): Promise<number> {\n return this.#reader.lineCount()\n }\n\n /**\n * Estimates the total token count of the artifact under `encoding`.\n *\n * @remarks\n * Reads the full byte-faithful content via {@link SpooledArtifact.asString} (which delegates to\n * {@link @nhtio/adk!SpoolReader.readAll}) and delegates to {@link @nhtio/adk!Tokenizable.estimateTokens}. The estimate\n * therefore reflects the actual source bytes — including trailing newlines and non-`\\n` line\n * terminators that the line-based {@link SpooledArtifact.cat} view would otherwise discard or\n * misrepresent.\n *\n * @param encoding - The encoding identifier to use for counting.\n * @returns The estimated number of tokens.\n */\n async estimateTokens(encoding: TokenEncoding): Promise<number> {\n const content = await this.#reader.readAll()\n return Tokenizable.estimateTokens(content, encoding)\n }\n\n /**\n * Returns the full artifact body as a single byte-faithful string.\n *\n * @remarks\n * Round-trip faithful to whatever bytes the {@link @nhtio/adk!SpoolReader} was constructed over —\n * preserves trailing newlines and non-`\\n` line terminators that {@link SpooledArtifact.cat}\n * discards via its line-based view. This is the canonical primitive for \"inline the artifact\n * content directly into a message\" use cases.\n *\n * `asString()` and the static `forgeTools(ctx)` factory on each subclass are independent\n * alternatives — a consumer chooses per turn whether to inline the body in a message\n * (`await tc.results.asString()`) or hand the model query tools\n * (`SpooledArtifact.forgeTools(ctx)`). Neither calls the other; either works with neither.\n *\n * @returns The full content as a single string.\n */\n async asString(): Promise<string> {\n return this.#reader.readAll()\n }\n\n /**\n * Forges a fresh {@link @nhtio/adk!ToolRegistry} of ephemeral {@link @nhtio/adk!ArtifactTool} instances that let the\n * LLM query artifacts already present in `ctx.turnToolCalls`.\n *\n * @remarks\n * Standard subclass extension pattern — each class owns only its own `toolMethods` and its\n * own `forgeTools`. The base `SpooledArtifact.forgeTools(ctx)` narrows the `callId` enum to\n * any `tc.results instanceof SpooledArtifact` (so subclass instances are included — that's\n * the whole point of inheritance) and dispatches the seven base methods (`head`, `tail`,\n * `grep`, `cat`, `byteLength`, `lineCount`, `estimateTokens`) on the resolved artifact.\n * Subclasses override `forgeTools` to call this static first and then register their own\n * tools on the returned registry — see {@link @nhtio/adk!SpooledJsonArtifact.forgeTools} and\n * {@link @nhtio/adk!SpooledMarkdownArtifact.forgeTools} for the canonical shape. There is no\n * `requiresSubclass` field, no helper indirection, and no `this`-based class narrowing —\n * just plain `instanceof ThisClass` at each subclass's own filter site.\n *\n * For each descriptor in this class's `toolMethods`, the factory:\n *\n * 1. Walks `ctx.turnToolCalls` to find `ToolCall`s whose `results instanceof SpooledArtifact`.\n * `ToolCall`s flagged `fromArtifactTool === true` are excluded — they carry a\n * {@link @nhtio/adk!Tokenizable}, not a `SpooledArtifact`, and including them would let the model\n * `artifact_grep` on a previous `artifact_grep` result (an infinite-recursion hazard with\n * no semantic value).\n * 2. Returns an empty registry if no compatible callIds are found — no point shipping tools\n * whose `callId` enum is empty.\n * 3. Otherwise mints an {@link @nhtio/adk!ArtifactTool} with `ephemeral: true` and `onCollision: 'replace'`\n * so multiple `Subclass.forgeTools(ctx)` outputs merge silently. The tool's `inputSchema`\n * includes a required `callId` field with `.valid(...compatibleIds)`, plus the descriptor's\n * own `argsSchema` fields.\n *\n * The handler resolves the artifact via `[...ctx.turnToolCalls].find(t => t.id === callId)`,\n * dispatches the descriptor's method, and serialises the return value (string → as-is;\n * string[] → newline-join; number → `String(n)`; otherwise `JSON.stringify(value, null, 2)`;\n * `descriptor.serialise` overrides the defaults). `grep` is special-cased: the handler\n * constructs `new RegExp(pattern, flags ?? '')` before invoking the artifact's `grep` method.\n *\n * The returned registry must be merged into the consumer's main registry and the main\n * registry must be bound to `ctx` via {@link @nhtio/adk!ToolRegistry.bindContext}:\n *\n * ```ts\n * const executor: DispatchExecutorFn = async (ctx) => {\n * const forged = SpooledArtifact.forgeTools(ctx)\n * const merged = ToolRegistry.merge([main, forged])\n * main.bindContext(ctx)\n * const result = await llm.invoke({ tools: merged.all(), ... })\n * ctx.ack() // ← ephemeral cleanup fires here\n * }\n * ```\n *\n * @warning You **must** call `registry.bindContext(ctx)` on the registry hosting these tools,\n * or ephemeral cleanup will not run and the `callId` enum in subsequent executor calls will\n * be stale (excluding new tool calls produced in the meantime).\n *\n * @param ctx - The execution context whose `turnToolCalls` snapshot defines the `callId` enum.\n * @returns A fresh `ToolRegistry`. Empty when `turnToolCalls` contains no compatible artifacts.\n *\n * @see {@link @nhtio/adk!ToolRegistry.bindContext}\n * @see {@link @nhtio/adk!ToolRegistry.merge}\n * @see {@link @nhtio/adk!DispatchContext.onAck}\n */\n public static forgeTools(ctx: DispatchContext): ToolRegistry {\n const requires: SpooledArtifactConstructor = SpooledArtifact\n const calls = [...ctx.turnToolCalls]\n const compatibleIds = calls\n .filter((tc) => !tc.fromArtifactTool && isInstanceOf(tc.results, requires.name, requires))\n .map((tc) => tc.id)\n if (compatibleIds.length === 0) return new ToolRegistry([])\n\n const tools: ArtifactTool[] = []\n for (const descriptor of this.toolMethods) {\n const callIdSchema = validator\n .string()\n .valid(...compatibleIds)\n .required()\n .description('ToolCall id of the artifact to query.')\n\n const argsSchema = (descriptor.argsSchema ?? noArgsSchema).append({\n callId: callIdSchema,\n })\n\n const serialise = descriptor.serialise ?? defaultSerialise\n\n const tool = new ArtifactTool({\n name: descriptor.name,\n description: descriptor.description,\n inputSchema: argsSchema,\n ephemeral: true,\n onCollision: 'replace',\n handler: async (rawArgs, ctxInner) => {\n const args = rawArgs as Record<string, unknown> & { callId: string }\n const tc = [...ctxInner.turnToolCalls].find((t) => t.id === args.callId)\n if (!tc) {\n return `Error: no tool call with id ${args.callId} in this turn`\n }\n const artifact = tc.results\n if (!isInstanceOf(artifact, requires.name, requires)) {\n return `Error: tool call ${args.callId} results are not a ${requires.name} instance`\n }\n const methodArgs: unknown[] = []\n if (descriptor.method === 'grep') {\n const pattern = args.pattern as string\n const flags = (args.flags as string | undefined) ?? ''\n methodArgs.push(new RegExp(pattern, flags))\n } else if (descriptor.method === 'head' || descriptor.method === 'tail') {\n methodArgs.push((args.n as number | undefined) ?? 10)\n } else if (descriptor.method === 'cat') {\n methodArgs.push(args.start as number | undefined, args.end as number | undefined)\n } else if (descriptor.method === 'estimateTokens') {\n methodArgs.push(args.encoding as TokenEncoding)\n }\n const fn = (artifact as unknown as Record<string, (...a: unknown[]) => unknown>)[\n descriptor.method\n ]\n if (typeof fn !== 'function') {\n return `Error: artifact has no method ${descriptor.method}`\n }\n const result = await Promise.resolve(fn.ap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AW;IACjB,aAAa,WAAW;IACxB,aAAa;IACb,WAAW;IACX,aAAa;IACb,SAAS,OAAO,SAAS,aAAa;KACpC,MAAM,OAAO;KACb,MAAM,KAAK,CAAC,GAAG,SAAS,aAAa,EAAE,MAAM,MAAM,EAAE,OAAO,KAAK,MAAM;KACvE,IAAI,CAAC,IACH,OAAO,+BAA+B,KAAK,OAAO;KAEpD,MAAM,WAAW,GAAG;KACpB,IAAI,CAAC,aAAa,UAAU,SAAS,MAAM,QAAQ,GACjD,OAAO,oBAAoB,KAAK,OAAO,qBAAqB,SAAS,KAAK;KAE5E,MAAM,aAAwB,CAAC;KAC/B,IAAI,WAAW,WAAW,QAAQ;MAChC,MAAM,UAAU,KAAK;MACrB,MAAM,QAAS,KAAK,SAAgC;MACpD,WAAW,KAAK,IAAI,OAAO,SAAS,KAAK,CAAC;KAC5C,OAAO,IAAI,WAAW,WAAW,UAAU,WAAW,WAAW,QAC/D,WAAW,KAAM,KAAK,KAA4B,EAAE;UAC/C,IAAI,WAAW,WAAW,OAC/B,WAAW,KAAK,KAAK,OAA6B,KAAK,GAAyB;UAC3E,IAAI,WAAW,WAAW,kBAC/B,WAAW,KAAK,KAAK,QAAyB;KAEhD,MAAM,KAAM,SACV,WAAW;KAEb,IAAI,OAAO,OAAO,YAChB,OAAO,iCAAiC,WAAW;KAGrD,OAAO,UAAU,MADI,QAAQ,QAAQ,GAAG,MAAM,UAAU,UAAU,CAAC,CAC5C;IACzB;GACF,CAAC;GACD,MAAM,KAAK,IAAI;EACjB;EACA,OAAO,IAAI,aAAa,KAAK;CAC/B;AACF"}
@@ -1,8 +1,8 @@
1
1
  require("./chunk-Ble4zEEl.js");
2
- const require_exceptions = require("./exceptions-CitH5wZI.js");
3
- const require_tool_registry = require("./tool_registry-DYUYqXvo.js");
4
- const require_runtime = require("./runtime-MFFcJrRv.js");
5
- const require_tool = require("./tool-CVyZkFC7.js");
2
+ const require_exceptions = require("./exceptions-BRXrUKiW.js");
3
+ const require_tool_registry = require("./tool_registry-CKJPze3j.js");
4
+ const require_runtime = require("./runtime-DslE1aBw.js");
5
+ const require_tool = require("./tool-D5WGVIcI.js");
6
6
  let _nhtio_validation = require("@nhtio/validation");
7
7
  //#region src/lib/classes/artifact_tool.ts
8
8
  /**
@@ -565,4 +565,4 @@ Object.defineProperty(exports, "implementsSpoolReader", {
565
565
  }
566
566
  });
567
567
 
568
- //# sourceMappingURL=spooled_artifact-BTq6Nzfy.js.map
568
+ //# sourceMappingURL=spooled_artifact-DX8LLyUX.js.map