@nhtio/adk 1.20260607.2 → 1.20260609.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (521) hide show
  1. package/CHANGELOG.md +230 -0
  2. package/batteries/embeddings/openai/adapter.cjs +1 -1
  3. package/batteries/embeddings/openai/adapter.mjs +1 -1
  4. package/batteries/embeddings/openai/exceptions.cjs +1 -1
  5. package/batteries/embeddings/openai/exceptions.mjs +1 -1
  6. package/batteries/embeddings/openai/types.d.ts +7 -0
  7. package/batteries/embeddings/webllm/adapter.cjs +1 -1
  8. package/batteries/embeddings/webllm/adapter.mjs +1 -1
  9. package/batteries/embeddings/webllm/exceptions.cjs +1 -1
  10. package/batteries/embeddings/webllm/exceptions.mjs +1 -1
  11. package/batteries/llm/chat_common/helpers.d.ts +165 -0
  12. package/batteries/llm/chat_common/types.d.ts +309 -0
  13. package/batteries/llm/index.d.ts +5 -0
  14. package/batteries/llm/ollama/adapter.cjs +736 -0
  15. package/batteries/llm/ollama/adapter.cjs.map +1 -0
  16. package/batteries/llm/ollama/adapter.d.ts +64 -0
  17. package/batteries/llm/ollama/adapter.mjs +734 -0
  18. package/batteries/llm/ollama/adapter.mjs.map +1 -0
  19. package/batteries/llm/ollama/exceptions.cjs +105 -0
  20. package/batteries/llm/ollama/exceptions.cjs.map +1 -0
  21. package/batteries/llm/ollama/exceptions.d.ts +112 -0
  22. package/batteries/llm/ollama/exceptions.mjs +96 -0
  23. package/batteries/llm/ollama/exceptions.mjs.map +1 -0
  24. package/batteries/llm/ollama/helpers.cjs +487 -0
  25. package/batteries/llm/ollama/helpers.cjs.map +1 -0
  26. package/batteries/llm/ollama/helpers.d.ts +158 -0
  27. package/batteries/llm/ollama/helpers.mjs +450 -0
  28. package/batteries/llm/ollama/helpers.mjs.map +1 -0
  29. package/batteries/llm/ollama/index.d.ts +29 -0
  30. package/batteries/llm/ollama/types.cjs +2 -0
  31. package/batteries/llm/ollama/types.d.ts +334 -0
  32. package/batteries/llm/ollama/types.mjs +0 -0
  33. package/batteries/llm/ollama/validation.cjs +130 -0
  34. package/batteries/llm/ollama/validation.cjs.map +1 -0
  35. package/batteries/llm/ollama/validation.d.ts +31 -0
  36. package/batteries/llm/ollama/validation.mjs +127 -0
  37. package/batteries/llm/ollama/validation.mjs.map +1 -0
  38. package/batteries/llm/ollama.cjs +54 -0
  39. package/batteries/llm/ollama.mjs +6 -0
  40. package/batteries/llm/openai_chat_completions/adapter.cjs +36 -19
  41. package/batteries/llm/openai_chat_completions/adapter.cjs.map +1 -1
  42. package/batteries/llm/openai_chat_completions/adapter.mjs +23 -6
  43. package/batteries/llm/openai_chat_completions/adapter.mjs.map +1 -1
  44. package/batteries/llm/openai_chat_completions/exceptions.cjs +1 -1
  45. package/batteries/llm/openai_chat_completions/exceptions.mjs +1 -1
  46. package/batteries/llm/openai_chat_completions/helpers.cjs +80 -320
  47. package/batteries/llm/openai_chat_completions/helpers.cjs.map +1 -1
  48. package/batteries/llm/openai_chat_completions/helpers.d.ts +68 -144
  49. package/batteries/llm/openai_chat_completions/helpers.mjs +40 -280
  50. package/batteries/llm/openai_chat_completions/helpers.mjs.map +1 -1
  51. package/batteries/llm/openai_chat_completions/types.d.ts +273 -181
  52. package/batteries/llm/openai_chat_completions/validation.cjs +2 -2
  53. package/batteries/llm/openai_chat_completions/validation.cjs.map +1 -1
  54. package/batteries/llm/openai_chat_completions/validation.mjs +2 -2
  55. package/batteries/llm/openai_chat_completions/validation.mjs.map +1 -1
  56. package/batteries/llm/openai_chat_completions.cjs +29 -28
  57. package/batteries/llm/openai_chat_completions.mjs +2 -1
  58. package/batteries/llm/webllm_chat_completions/adapter.cjs +38 -19
  59. package/batteries/llm/webllm_chat_completions/adapter.cjs.map +1 -1
  60. package/batteries/llm/webllm_chat_completions/adapter.d.ts +18 -0
  61. package/batteries/llm/webllm_chat_completions/adapter.mjs +25 -6
  62. package/batteries/llm/webllm_chat_completions/adapter.mjs.map +1 -1
  63. package/batteries/llm/webllm_chat_completions/exceptions.cjs +1 -1
  64. package/batteries/llm/webllm_chat_completions/exceptions.mjs +1 -1
  65. package/batteries/llm/webllm_chat_completions/helpers.cjs +29 -28
  66. package/batteries/llm/webllm_chat_completions/helpers.mjs +2 -1
  67. package/batteries/llm/webllm_chat_completions/types.d.ts +21 -0
  68. package/batteries/llm/webllm_chat_completions/validation.cjs +13 -1
  69. package/batteries/llm/webllm_chat_completions/validation.cjs.map +1 -1
  70. package/batteries/llm/webllm_chat_completions/validation.d.ts +12 -0
  71. package/batteries/llm/webllm_chat_completions/validation.mjs +13 -1
  72. package/batteries/llm/webllm_chat_completions/validation.mjs.map +1 -1
  73. package/batteries/llm/webllm_chat_completions.cjs +29 -28
  74. package/batteries/llm/webllm_chat_completions.mjs +2 -1
  75. package/batteries/llm.cjs +44 -28
  76. package/batteries/llm.mjs +9 -4
  77. package/batteries/storage/flydrive.cjs +1 -1
  78. package/batteries/storage/flydrive.mjs +1 -1
  79. package/batteries/storage/in_memory/index.d.ts +1 -1
  80. package/batteries/storage/in_memory.cjs +2 -2
  81. package/batteries/storage/in_memory.cjs.map +1 -1
  82. package/batteries/storage/in_memory.mjs +2 -2
  83. package/batteries/storage/in_memory.mjs.map +1 -1
  84. package/batteries/storage/opfs/index.d.ts +19 -0
  85. package/batteries/storage/opfs.cjs +1 -1
  86. package/batteries/storage/opfs.cjs.map +1 -1
  87. package/batteries/storage/opfs.mjs +1 -1
  88. package/batteries/storage/opfs.mjs.map +1 -1
  89. package/batteries/tools/_shared/index.d.ts +121 -0
  90. package/batteries/tools/_shared.cjs +157 -0
  91. package/batteries/tools/_shared.cjs.map +1 -0
  92. package/batteries/tools/_shared.mjs +149 -0
  93. package/batteries/tools/_shared.mjs.map +1 -0
  94. package/batteries/tools/color.cjs +3 -2
  95. package/batteries/tools/color.cjs.map +1 -1
  96. package/batteries/tools/color.mjs +3 -2
  97. package/batteries/tools/color.mjs.map +1 -1
  98. package/batteries/tools/comparison.cjs +4 -3
  99. package/batteries/tools/comparison.cjs.map +1 -1
  100. package/batteries/tools/comparison.mjs +4 -3
  101. package/batteries/tools/comparison.mjs.map +1 -1
  102. package/batteries/tools/data_structure.cjs +30 -10
  103. package/batteries/tools/data_structure.cjs.map +1 -1
  104. package/batteries/tools/data_structure.mjs +30 -10
  105. package/batteries/tools/data_structure.mjs.map +1 -1
  106. package/batteries/tools/datetime_extended.cjs +5 -10
  107. package/batteries/tools/datetime_extended.cjs.map +1 -1
  108. package/batteries/tools/datetime_extended.mjs +5 -10
  109. package/batteries/tools/datetime_extended.mjs.map +1 -1
  110. package/batteries/tools/datetime_math.cjs +2 -2
  111. package/batteries/tools/datetime_math.mjs +2 -2
  112. package/batteries/tools/encoding.cjs +13 -4
  113. package/batteries/tools/encoding.cjs.map +1 -1
  114. package/batteries/tools/encoding.mjs +13 -4
  115. package/batteries/tools/encoding.mjs.map +1 -1
  116. package/batteries/tools/formatting.cjs +4 -4
  117. package/batteries/tools/formatting.cjs.map +1 -1
  118. package/batteries/tools/formatting.mjs +4 -4
  119. package/batteries/tools/formatting.mjs.map +1 -1
  120. package/batteries/tools/geo_basics.cjs +2 -2
  121. package/batteries/tools/geo_basics.mjs +2 -2
  122. package/batteries/tools/index.d.ts +3 -0
  123. package/batteries/tools/math.cjs +10 -8
  124. package/batteries/tools/math.cjs.map +1 -1
  125. package/batteries/tools/math.mjs +10 -8
  126. package/batteries/tools/math.mjs.map +1 -1
  127. package/batteries/tools/memory.cjs +5 -5
  128. package/batteries/tools/memory.mjs +5 -5
  129. package/batteries/tools/parsing.cjs +9 -5
  130. package/batteries/tools/parsing.cjs.map +1 -1
  131. package/batteries/tools/parsing.mjs +9 -5
  132. package/batteries/tools/parsing.mjs.map +1 -1
  133. package/batteries/tools/retrievables.cjs +4 -4
  134. package/batteries/tools/retrievables.mjs +4 -4
  135. package/batteries/tools/scrapper/exceptions.d.ts +21 -0
  136. package/batteries/tools/scrapper/index.d.ts +172 -0
  137. package/batteries/tools/scrapper/shared.d.ts +139 -0
  138. package/batteries/tools/scrapper.cjs +8 -0
  139. package/batteries/tools/scrapper.mjs +2 -0
  140. package/batteries/tools/searxng/exceptions.d.ts +21 -0
  141. package/batteries/tools/searxng/index.d.ts +177 -0
  142. package/batteries/tools/searxng.cjs +6 -0
  143. package/batteries/tools/searxng.mjs +2 -0
  144. package/batteries/tools/standing_instructions.cjs +4 -4
  145. package/batteries/tools/standing_instructions.mjs +4 -4
  146. package/batteries/tools/statistics.cjs +54 -43
  147. package/batteries/tools/statistics.cjs.map +1 -1
  148. package/batteries/tools/statistics.mjs +54 -43
  149. package/batteries/tools/statistics.mjs.map +1 -1
  150. package/batteries/tools/string_processing.cjs +5 -5
  151. package/batteries/tools/string_processing.cjs.map +1 -1
  152. package/batteries/tools/string_processing.mjs +5 -5
  153. package/batteries/tools/string_processing.mjs.map +1 -1
  154. package/batteries/tools/structured_data.cjs +8 -13
  155. package/batteries/tools/structured_data.cjs.map +1 -1
  156. package/batteries/tools/structured_data.mjs +8 -13
  157. package/batteries/tools/structured_data.mjs.map +1 -1
  158. package/batteries/tools/text_analysis.cjs +3 -3
  159. package/batteries/tools/text_analysis.mjs +3 -3
  160. package/batteries/tools/text_comparison.cjs +2 -2
  161. package/batteries/tools/text_comparison.mjs +2 -2
  162. package/batteries/tools/time.cjs +2 -2
  163. package/batteries/tools/time.mjs +2 -2
  164. package/batteries/tools/unit_conversion.cjs +10 -8
  165. package/batteries/tools/unit_conversion.cjs.map +1 -1
  166. package/batteries/tools/unit_conversion.mjs +10 -8
  167. package/batteries/tools/unit_conversion.mjs.map +1 -1
  168. package/batteries/tools/web_retrieval/index.d.ts +186 -0
  169. package/batteries/tools/web_retrieval.cjs +206 -0
  170. package/batteries/tools/web_retrieval.cjs.map +1 -0
  171. package/batteries/tools/web_retrieval.mjs +201 -0
  172. package/batteries/tools/web_retrieval.mjs.map +1 -0
  173. package/batteries/tools.cjs +15 -0
  174. package/batteries/tools.mjs +4 -1
  175. package/batteries/vector/arangodb/index.d.ts +2 -0
  176. package/batteries/vector/arangodb.cjs +2 -1
  177. package/batteries/vector/arangodb.cjs.map +1 -1
  178. package/batteries/vector/arangodb.mjs +2 -1
  179. package/batteries/vector/arangodb.mjs.map +1 -1
  180. package/batteries/vector/builder.cjs +31 -0
  181. package/batteries/vector/builder.cjs.map +1 -1
  182. package/batteries/vector/builder.d.ts +58 -0
  183. package/batteries/vector/builder.mjs +31 -0
  184. package/batteries/vector/builder.mjs.map +1 -1
  185. package/batteries/vector/chroma/index.d.ts +4 -0
  186. package/batteries/vector/chroma.cjs +3 -0
  187. package/batteries/vector/chroma.cjs.map +1 -1
  188. package/batteries/vector/chroma.mjs +3 -0
  189. package/batteries/vector/chroma.mjs.map +1 -1
  190. package/batteries/vector/clickhouse/index.d.ts +2 -0
  191. package/batteries/vector/clickhouse.cjs +2 -1
  192. package/batteries/vector/clickhouse.cjs.map +1 -1
  193. package/batteries/vector/clickhouse.mjs +2 -1
  194. package/batteries/vector/clickhouse.mjs.map +1 -1
  195. package/batteries/vector/cloudflare/index.d.ts +2 -0
  196. package/batteries/vector/cloudflare.cjs +2 -1
  197. package/batteries/vector/cloudflare.cjs.map +1 -1
  198. package/batteries/vector/cloudflare.mjs +2 -1
  199. package/batteries/vector/cloudflare.mjs.map +1 -1
  200. package/batteries/vector/conformance/index.d.ts +22 -0
  201. package/batteries/vector/conformance.cjs +22 -0
  202. package/batteries/vector/conformance.cjs.map +1 -1
  203. package/batteries/vector/conformance.mjs +22 -0
  204. package/batteries/vector/conformance.mjs.map +1 -1
  205. package/batteries/vector/contract.cjs +22 -0
  206. package/batteries/vector/contract.cjs.map +1 -1
  207. package/batteries/vector/contract.d.ts +51 -0
  208. package/batteries/vector/contract.mjs +22 -0
  209. package/batteries/vector/contract.mjs.map +1 -1
  210. package/batteries/vector/couchbase/index.d.ts +2 -0
  211. package/batteries/vector/couchbase.cjs +2 -1
  212. package/batteries/vector/couchbase.cjs.map +1 -1
  213. package/batteries/vector/couchbase.mjs +2 -1
  214. package/batteries/vector/couchbase.mjs.map +1 -1
  215. package/batteries/vector/duckdb/index.d.ts +2 -0
  216. package/batteries/vector/duckdb.cjs +2 -1
  217. package/batteries/vector/duckdb.cjs.map +1 -1
  218. package/batteries/vector/duckdb.mjs +2 -1
  219. package/batteries/vector/duckdb.mjs.map +1 -1
  220. package/batteries/vector/elasticsearch/index.d.ts +2 -0
  221. package/batteries/vector/elasticsearch.cjs +2 -1
  222. package/batteries/vector/elasticsearch.cjs.map +1 -1
  223. package/batteries/vector/elasticsearch.mjs +2 -1
  224. package/batteries/vector/elasticsearch.mjs.map +1 -1
  225. package/batteries/vector/exceptions.cjs +1 -1
  226. package/batteries/vector/exceptions.mjs +1 -1
  227. package/batteries/vector/factory.cjs +6 -0
  228. package/batteries/vector/factory.cjs.map +1 -1
  229. package/batteries/vector/factory.d.ts +14 -0
  230. package/batteries/vector/factory.mjs +6 -0
  231. package/batteries/vector/factory.mjs.map +1 -1
  232. package/batteries/vector/filters.cjs +22 -1
  233. package/batteries/vector/filters.cjs.map +1 -1
  234. package/batteries/vector/filters.d.ts +38 -0
  235. package/batteries/vector/filters.mjs +22 -1
  236. package/batteries/vector/filters.mjs.map +1 -1
  237. package/batteries/vector/helpers.cjs +13 -0
  238. package/batteries/vector/helpers.cjs.map +1 -1
  239. package/batteries/vector/helpers.d.ts +14 -0
  240. package/batteries/vector/helpers.mjs +13 -0
  241. package/batteries/vector/helpers.mjs.map +1 -1
  242. package/batteries/vector/hnswlib/index.d.ts +2 -0
  243. package/batteries/vector/hnswlib.cjs +2 -1
  244. package/batteries/vector/hnswlib.cjs.map +1 -1
  245. package/batteries/vector/hnswlib.mjs +2 -1
  246. package/batteries/vector/hnswlib.mjs.map +1 -1
  247. package/batteries/vector/in_memory/index.d.ts +1 -0
  248. package/batteries/vector/in_memory.cjs +1 -0
  249. package/batteries/vector/in_memory.cjs.map +1 -1
  250. package/batteries/vector/in_memory.mjs +1 -0
  251. package/batteries/vector/in_memory.mjs.map +1 -1
  252. package/batteries/vector/lancedb/index.d.ts +2 -0
  253. package/batteries/vector/lancedb.cjs +2 -1
  254. package/batteries/vector/lancedb.cjs.map +1 -1
  255. package/batteries/vector/lancedb.mjs +2 -1
  256. package/batteries/vector/lancedb.mjs.map +1 -1
  257. package/batteries/vector/mariadb/index.d.ts +2 -0
  258. package/batteries/vector/mariadb.cjs +2 -1
  259. package/batteries/vector/mariadb.cjs.map +1 -1
  260. package/batteries/vector/mariadb.mjs +2 -1
  261. package/batteries/vector/mariadb.mjs.map +1 -1
  262. package/batteries/vector/meilisearch/index.d.ts +2 -0
  263. package/batteries/vector/meilisearch.cjs +2 -1
  264. package/batteries/vector/meilisearch.cjs.map +1 -1
  265. package/batteries/vector/meilisearch.mjs +2 -1
  266. package/batteries/vector/meilisearch.mjs.map +1 -1
  267. package/batteries/vector/migrate.cjs +18 -1
  268. package/batteries/vector/migrate.cjs.map +1 -1
  269. package/batteries/vector/migrate.d.ts +31 -0
  270. package/batteries/vector/migrate.mjs +18 -1
  271. package/batteries/vector/migrate.mjs.map +1 -1
  272. package/batteries/vector/milvus/index.d.ts +5 -0
  273. package/batteries/vector/milvus.cjs +4 -0
  274. package/batteries/vector/milvus.cjs.map +1 -1
  275. package/batteries/vector/milvus.mjs +4 -0
  276. package/batteries/vector/milvus.mjs.map +1 -1
  277. package/batteries/vector/mongodb/index.d.ts +2 -0
  278. package/batteries/vector/mongodb.cjs +2 -1
  279. package/batteries/vector/mongodb.cjs.map +1 -1
  280. package/batteries/vector/mongodb.mjs +2 -1
  281. package/batteries/vector/mongodb.mjs.map +1 -1
  282. package/batteries/vector/neo4j/index.d.ts +2 -0
  283. package/batteries/vector/neo4j.cjs +2 -1
  284. package/batteries/vector/neo4j.cjs.map +1 -1
  285. package/batteries/vector/neo4j.mjs +2 -1
  286. package/batteries/vector/neo4j.mjs.map +1 -1
  287. package/batteries/vector/opensearch/index.d.ts +2 -0
  288. package/batteries/vector/opensearch.cjs +2 -1
  289. package/batteries/vector/opensearch.cjs.map +1 -1
  290. package/batteries/vector/opensearch.mjs +2 -1
  291. package/batteries/vector/opensearch.mjs.map +1 -1
  292. package/batteries/vector/oracle23ai/index.d.ts +2 -0
  293. package/batteries/vector/oracle23ai.cjs +2 -1
  294. package/batteries/vector/oracle23ai.cjs.map +1 -1
  295. package/batteries/vector/oracle23ai.mjs +2 -1
  296. package/batteries/vector/oracle23ai.mjs.map +1 -1
  297. package/batteries/vector/orama/index.d.ts +1 -0
  298. package/batteries/vector/orama.cjs +1 -0
  299. package/batteries/vector/orama.cjs.map +1 -1
  300. package/batteries/vector/orama.mjs +1 -0
  301. package/batteries/vector/orama.mjs.map +1 -1
  302. package/batteries/vector/pgvector/index.d.ts +9 -2
  303. package/batteries/vector/pgvector.cjs +4 -0
  304. package/batteries/vector/pgvector.cjs.map +1 -1
  305. package/batteries/vector/pgvector.mjs +4 -0
  306. package/batteries/vector/pgvector.mjs.map +1 -1
  307. package/batteries/vector/pinecone/index.d.ts +5 -0
  308. package/batteries/vector/pinecone.cjs +3 -1
  309. package/batteries/vector/pinecone.cjs.map +1 -1
  310. package/batteries/vector/pinecone.mjs +3 -1
  311. package/batteries/vector/pinecone.mjs.map +1 -1
  312. package/batteries/vector/plan.d.ts +27 -0
  313. package/batteries/vector/qdrant/index.d.ts +5 -0
  314. package/batteries/vector/qdrant.cjs +4 -0
  315. package/batteries/vector/qdrant.cjs.map +1 -1
  316. package/batteries/vector/qdrant.mjs +4 -0
  317. package/batteries/vector/qdrant.mjs.map +1 -1
  318. package/batteries/vector/redis/index.d.ts +2 -0
  319. package/batteries/vector/redis.cjs +2 -1
  320. package/batteries/vector/redis.cjs.map +1 -1
  321. package/batteries/vector/redis.mjs +2 -1
  322. package/batteries/vector/redis.mjs.map +1 -1
  323. package/batteries/vector/retrievable.cjs +9 -1
  324. package/batteries/vector/retrievable.cjs.map +1 -1
  325. package/batteries/vector/retrievable.mjs +9 -1
  326. package/batteries/vector/retrievable.mjs.map +1 -1
  327. package/batteries/vector/retrievable_glue.d.ts +21 -0
  328. package/batteries/vector/s3vectors/index.d.ts +2 -0
  329. package/batteries/vector/s3vectors.cjs +2 -1
  330. package/batteries/vector/s3vectors.cjs.map +1 -1
  331. package/batteries/vector/s3vectors.mjs +2 -1
  332. package/batteries/vector/s3vectors.mjs.map +1 -1
  333. package/batteries/vector/schema.cjs +28 -0
  334. package/batteries/vector/schema.cjs.map +1 -1
  335. package/batteries/vector/schema.d.ts +39 -0
  336. package/batteries/vector/schema.mjs +28 -0
  337. package/batteries/vector/schema.mjs.map +1 -1
  338. package/batteries/vector/solr/index.d.ts +2 -0
  339. package/batteries/vector/solr.cjs +2 -1
  340. package/batteries/vector/solr.cjs.map +1 -1
  341. package/batteries/vector/solr.mjs +2 -1
  342. package/batteries/vector/solr.mjs.map +1 -1
  343. package/batteries/vector/sqlite_vec/index.d.ts +6 -3
  344. package/batteries/vector/sqlite_vec.cjs +2 -0
  345. package/batteries/vector/sqlite_vec.cjs.map +1 -1
  346. package/batteries/vector/sqlite_vec.mjs +2 -0
  347. package/batteries/vector/sqlite_vec.mjs.map +1 -1
  348. package/batteries/vector/surrealdb/index.d.ts +2 -0
  349. package/batteries/vector/surrealdb.cjs +2 -1
  350. package/batteries/vector/surrealdb.cjs.map +1 -1
  351. package/batteries/vector/surrealdb.mjs +2 -1
  352. package/batteries/vector/surrealdb.mjs.map +1 -1
  353. package/batteries/vector/types.d.ts +27 -0
  354. package/batteries/vector/typesense/index.d.ts +2 -0
  355. package/batteries/vector/typesense.cjs +2 -1
  356. package/batteries/vector/typesense.cjs.map +1 -1
  357. package/batteries/vector/typesense.mjs +2 -1
  358. package/batteries/vector/typesense.mjs.map +1 -1
  359. package/batteries/vector/validation.cjs +14 -0
  360. package/batteries/vector/validation.cjs.map +1 -1
  361. package/batteries/vector/validation.d.ts +14 -0
  362. package/batteries/vector/validation.mjs +14 -0
  363. package/batteries/vector/validation.mjs.map +1 -1
  364. package/batteries/vector/vector_store_constructor.cjs +1 -1
  365. package/batteries/vector/vector_store_constructor.cjs.map +1 -1
  366. package/batteries/vector/vector_store_constructor.d.ts +1 -1
  367. package/batteries/vector/vector_store_constructor.mjs +1 -1
  368. package/batteries/vector/vector_store_constructor.mjs.map +1 -1
  369. package/batteries/vector/vespa/index.d.ts +2 -0
  370. package/batteries/vector/vespa.cjs +2 -1
  371. package/batteries/vector/vespa.cjs.map +1 -1
  372. package/batteries/vector/vespa.mjs +2 -1
  373. package/batteries/vector/vespa.mjs.map +1 -1
  374. package/batteries/vector/weaviate/index.d.ts +2 -0
  375. package/batteries/vector/weaviate.cjs +2 -1
  376. package/batteries/vector/weaviate.cjs.map +1 -1
  377. package/batteries/vector/weaviate.mjs +2 -1
  378. package/batteries/vector/weaviate.mjs.map +1 -1
  379. package/batteries.cjs +58 -28
  380. package/batteries.mjs +12 -5
  381. package/{common-BT0nfCi9.mjs → common-DYDUi99O.mjs} +9 -9
  382. package/common-DYDUi99O.mjs.map +1 -0
  383. package/{common-Cj8TaQ9U.js → common-DZl3ADJs.js} +9 -9
  384. package/common-DZl3ADJs.js.map +1 -0
  385. package/common.cjs +7 -7
  386. package/common.mjs +7 -7
  387. package/{dispatch_runner-DPcS7Y_M.mjs → dispatch_runner--ZhdDWRZ.mjs} +27 -5
  388. package/{dispatch_runner-DPcS7Y_M.mjs.map → dispatch_runner--ZhdDWRZ.mjs.map} +1 -1
  389. package/{dispatch_runner-BHBNupqp.js → dispatch_runner-nHDKkxye.js} +27 -5
  390. package/{dispatch_runner-BHBNupqp.js.map → dispatch_runner-nHDKkxye.js.map} +1 -1
  391. package/dispatch_runner.cjs +1 -1
  392. package/dispatch_runner.d.ts +1 -1
  393. package/dispatch_runner.mjs +1 -1
  394. package/eslint/rules/artifact_tool_forbids_artifact_constructor.cjs +1 -0
  395. package/eslint/rules/artifact_tool_forbids_artifact_constructor.cjs.map +1 -1
  396. package/eslint/rules/artifact_tool_forbids_artifact_constructor.d.ts +1 -0
  397. package/eslint/rules/artifact_tool_forbids_artifact_constructor.mjs +1 -0
  398. package/eslint/rules/artifact_tool_forbids_artifact_constructor.mjs.map +1 -1
  399. package/eslint/rules/no_model_in_tool_handler.cjs +1 -0
  400. package/eslint/rules/no_model_in_tool_handler.cjs.map +1 -1
  401. package/eslint/rules/no_model_in_tool_handler.d.ts +1 -0
  402. package/eslint/rules/no_model_in_tool_handler.mjs +1 -0
  403. package/eslint/rules/no_model_in_tool_handler.mjs.map +1 -1
  404. package/eslint/rules/require_validator_any_required.cjs +1 -0
  405. package/eslint/rules/require_validator_any_required.cjs.map +1 -1
  406. package/eslint/rules/require_validator_any_required.d.ts +1 -0
  407. package/eslint/rules/require_validator_any_required.mjs +1 -0
  408. package/eslint/rules/require_validator_any_required.mjs.map +1 -1
  409. package/eslint/rules/thought_payload_requires_replay_tag.cjs +1 -0
  410. package/eslint/rules/thought_payload_requires_replay_tag.cjs.map +1 -1
  411. package/eslint/rules/thought_payload_requires_replay_tag.d.ts +1 -0
  412. package/eslint/rules/thought_payload_requires_replay_tag.mjs +1 -0
  413. package/eslint/rules/thought_payload_requires_replay_tag.mjs.map +1 -1
  414. package/eslint/rules/token_encoding_requires_context_window.cjs +1 -0
  415. package/eslint/rules/token_encoding_requires_context_window.cjs.map +1 -1
  416. package/eslint/rules/token_encoding_requires_context_window.d.ts +1 -0
  417. package/eslint/rules/token_encoding_requires_context_window.mjs +1 -0
  418. package/eslint/rules/token_encoding_requires_context_window.mjs.map +1 -1
  419. package/eslint/rules.cjs +1 -1
  420. package/eslint/rules.mjs +1 -1
  421. package/eslint.cjs +2 -2
  422. package/eslint.mjs +2 -2
  423. package/{exceptions-BeWH2FwP.mjs → exceptions-BDhN0Xzr.mjs} +3 -2
  424. package/exceptions-BDhN0Xzr.mjs.map +1 -0
  425. package/{exceptions-CitH5wZI.js → exceptions-BRXrUKiW.js} +3 -2
  426. package/exceptions-BRXrUKiW.js.map +1 -0
  427. package/exceptions.cjs +2 -2
  428. package/exceptions.mjs +2 -2
  429. package/factories.cjs +1 -1
  430. package/factories.mjs +1 -1
  431. package/forge.cjs +4 -4
  432. package/forge.d.ts +1 -1
  433. package/forge.mjs +4 -4
  434. package/guards.cjs +9 -9
  435. package/guards.mjs +9 -9
  436. package/helpers-DSTFxTiC.js +497 -0
  437. package/helpers-DSTFxTiC.js.map +1 -0
  438. package/helpers-xhrQbMAG.mjs +306 -0
  439. package/helpers-xhrQbMAG.mjs.map +1 -0
  440. package/index.cjs +12 -12
  441. package/index.mjs +12 -12
  442. package/lib/classes/base_exception.d.ts +1 -0
  443. package/lib/classes/media.d.ts +10 -0
  444. package/lib/classes/retrievable.d.ts +1 -1
  445. package/lib/classes/spooled_json_artifact.d.ts +1 -1
  446. package/lib/classes/spooled_markdown_artifact.d.ts +1 -0
  447. package/lib/classes/tokenizable.d.ts +3 -0
  448. package/lib/classes/tool.d.ts +8 -0
  449. package/lib/classes/turn_gate.d.ts +6 -0
  450. package/lib/dispatch_runner.d.ts +4 -32
  451. package/lib/helpers/bignum.cjs +82 -0
  452. package/lib/helpers/bignum.cjs.map +1 -0
  453. package/lib/helpers/bignum.d.ts +52 -0
  454. package/lib/helpers/bignum.mjs +74 -0
  455. package/lib/helpers/bignum.mjs.map +1 -0
  456. package/lib/turn_runner.d.ts +1 -1
  457. package/lib/types/dispatch_runner.d.ts +83 -0
  458. package/lib/utils/exceptions.d.ts +1 -1
  459. package/lib/utils/retry.cjs.map +1 -1
  460. package/lib/utils/retry.d.ts +2 -0
  461. package/lib/utils/retry.mjs.map +1 -1
  462. package/mcp/adk-docs-corpus.json +1 -1
  463. package/package.json +259 -204
  464. package/{runtime-j92CNi5z.mjs → runtime-Bz5zA8wc.mjs} +2 -2
  465. package/{runtime-j92CNi5z.mjs.map → runtime-Bz5zA8wc.mjs.map} +1 -1
  466. package/{runtime-MFFcJrRv.js → runtime-DslE1aBw.js} +2 -2
  467. package/{runtime-MFFcJrRv.js.map → runtime-DslE1aBw.js.map} +1 -1
  468. package/scrapper-BHM1mCde.mjs +432 -0
  469. package/scrapper-BHM1mCde.mjs.map +1 -0
  470. package/scrapper-BeweWurk.js +462 -0
  471. package/scrapper-BeweWurk.js.map +1 -0
  472. package/searxng-BJFulNcK.mjs +247 -0
  473. package/searxng-BJFulNcK.mjs.map +1 -0
  474. package/searxng-B_D--V5q.js +265 -0
  475. package/searxng-B_D--V5q.js.map +1 -0
  476. package/skills/adk-assembly/SKILL.md +2 -2
  477. package/{spooled_artifact-CHoZgWwI.mjs → spooled_artifact-7eePq7JA.mjs} +5 -5
  478. package/{spooled_artifact-CHoZgWwI.mjs.map → spooled_artifact-7eePq7JA.mjs.map} +1 -1
  479. package/{spooled_artifact-BTq6Nzfy.js → spooled_artifact-DX8LLyUX.js} +5 -5
  480. package/{spooled_artifact-BTq6Nzfy.js.map → spooled_artifact-DX8LLyUX.js.map} +1 -1
  481. package/spooled_artifact.cjs +2 -2
  482. package/spooled_artifact.mjs +2 -2
  483. package/{spooled_markdown_artifact-CALSDxIx.js → spooled_markdown_artifact-ClX72lek.js} +4 -4
  484. package/spooled_markdown_artifact-ClX72lek.js.map +1 -0
  485. package/{spooled_markdown_artifact-Ci5UL7l4.mjs → spooled_markdown_artifact-wkrBF3oX.mjs} +4 -4
  486. package/spooled_markdown_artifact-wkrBF3oX.mjs.map +1 -0
  487. package/{thought-D34QQZZ9.mjs → thought-B_vxAiKU.mjs} +5 -5
  488. package/{thought-D34QQZZ9.mjs.map → thought-B_vxAiKU.mjs.map} +1 -1
  489. package/{thought-BbwhJ1wb.js → thought-DLwpF7MI.js} +5 -5
  490. package/{thought-BbwhJ1wb.js.map → thought-DLwpF7MI.js.map} +1 -1
  491. package/{tool-CVyZkFC7.js → tool-D5WGVIcI.js} +4 -4
  492. package/{tool-CVyZkFC7.js.map → tool-D5WGVIcI.js.map} +1 -1
  493. package/{tool-CMhaDRNd.mjs → tool-wMYMVl60.mjs} +4 -4
  494. package/{tool-CMhaDRNd.mjs.map → tool-wMYMVl60.mjs.map} +1 -1
  495. package/{tool_call-CV5qVNlb.mjs → tool_call-B4-_-vjG.mjs} +5 -5
  496. package/tool_call-B4-_-vjG.mjs.map +1 -0
  497. package/{tool_call-Db68hB7y.js → tool_call-DixVlW40.js} +5 -5
  498. package/tool_call-DixVlW40.js.map +1 -0
  499. package/{tool_registry-D1pSSlsd.mjs → tool_registry-791Vrjtf.mjs} +4 -3
  500. package/tool_registry-791Vrjtf.mjs.map +1 -0
  501. package/{tool_registry-DYUYqXvo.js → tool_registry-CKJPze3j.js} +4 -3
  502. package/tool_registry-CKJPze3j.js.map +1 -0
  503. package/{turn_runner-DqWHNP80.js → turn_runner-HXImLGIn.js} +7 -7
  504. package/turn_runner-HXImLGIn.js.map +1 -0
  505. package/{turn_runner-fg1Wc3dK.mjs → turn_runner-ZyYO-Kti.mjs} +7 -7
  506. package/turn_runner-ZyYO-Kti.mjs.map +1 -0
  507. package/turn_runner.cjs +1 -1
  508. package/turn_runner.mjs +1 -1
  509. package/types.d.ts +1 -1
  510. package/common-BT0nfCi9.mjs.map +0 -1
  511. package/common-Cj8TaQ9U.js.map +0 -1
  512. package/exceptions-BeWH2FwP.mjs.map +0 -1
  513. package/exceptions-CitH5wZI.js.map +0 -1
  514. package/spooled_markdown_artifact-CALSDxIx.js.map +0 -1
  515. package/spooled_markdown_artifact-Ci5UL7l4.mjs.map +0 -1
  516. package/tool_call-CV5qVNlb.mjs.map +0 -1
  517. package/tool_call-Db68hB7y.js.map +0 -1
  518. package/tool_registry-D1pSSlsd.mjs.map +0 -1
  519. package/tool_registry-DYUYqXvo.js.map +0 -1
  520. package/turn_runner-DqWHNP80.js.map +0 -1
  521. package/turn_runner-fg1Wc3dK.mjs.map +0 -1
@@ -0,0 +1,487 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("../../../chunk-Ble4zEEl.js");
3
+ require("../../../common-DZl3ADJs.js");
4
+ const require_tool_call = require("../../../tool_call-DixVlW40.js");
5
+ require("../../../guards.cjs");
6
+ const require_helpers = require("../../../helpers-DSTFxTiC.js");
7
+ const require_batteries_llm_ollama_exceptions = require("./exceptions.cjs");
8
+ //#region src/batteries/llm/ollama/helpers.ts
9
+ /**
10
+ * Swappable translation helpers for rendering ADK state into native Ollama `/api/chat` requests.
11
+ *
12
+ * @module @nhtio/adk/batteries/llm/ollama/helpers
13
+ *
14
+ * @remarks
15
+ * The wire-shape-agnostic helpers (`renderUntrustedContent`, `renderMemories`,
16
+ * `renderChatCompletionsSystemPrompt`, `toolsToChatCompletionsTools`, …) are shared with the OpenAI
17
+ * battery via the internal `../chat_common/helpers` submodule and re-exported here under their
18
+ * original names. Only the Ollama-WIRE-SPECIFIC helpers are defined here:
19
+ * `renderOllamaTimelineMessage` (flat `content` + base64 `images[]` + `thinking`),
20
+ * `renderOllamaToolCallResult` (string-only result content), `buildOllamaHistory` (synthetic
21
+ * `assistant.tool_calls` with object-form `arguments` + `tool`-role messages labelled by
22
+ * `tool_name`), and `ollamaToolsFromTools` (alias of the shared tool-definition renderer — native
23
+ * `/api/chat` uses the same function-tool wire shape).
24
+ *
25
+ * Native `/api/chat` supports only base64 `images[]`; every non-image modality routes through the
26
+ * `unsupportedMediaPolicy` fallback (stash text / synthetic description) or throws.
27
+ */
28
+ /**
29
+ * Convert ADK tools to the native Ollama `tools[]` wire. Native `/api/chat` uses the identical
30
+ * `{ type: 'function', function: { name, description, parameters } }` shape as Chat Completions, so
31
+ * this is an alias of the shared renderer.
32
+ */
33
+ var ollamaToolsFromTools = (tools, deps) => require_helpers.toolsToChatCompletionsTools(tools, deps);
34
+ /** Default implementation of {@link OllamaHelpers}-style tool translation; alias of {@link ollamaToolsFromTools}. */
35
+ var defaultOllamaToolsFromTools = ollamaToolsFromTools;
36
+ var DEFAULT_STASH_FALLBACK_KEYS = [
37
+ "text:transcript",
38
+ "text:caption",
39
+ "text:description"
40
+ ];
41
+ var modalityHazardToAttr = (h) => {
42
+ if (h === "inert") return "inert";
43
+ if (h === "extractable-instructions") return "extractable";
44
+ return "opaque";
45
+ };
46
+ var formatBytesHumanReadable = (bytes) => {
47
+ if (bytes === void 0 || !Number.isFinite(bytes)) return "unknown size";
48
+ if (bytes < 1024) return `${bytes} B`;
49
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
50
+ if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
51
+ return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GB`;
52
+ };
53
+ var isMediaTextStashEntry = (e) => {
54
+ if (!e || typeof e !== "object") return false;
55
+ const r = e;
56
+ return typeof r.value === "string" && typeof r.trustTier === "string";
57
+ };
58
+ var resolveFallbackStash = (media, keys) => {
59
+ for (const key of keys) {
60
+ const entry = media.stash.get(key);
61
+ if (isMediaTextStashEntry(entry)) return {
62
+ text: entry.value,
63
+ entryTier: entry.trustTier
64
+ };
65
+ }
66
+ };
67
+ var renderTextInEnvelope = (text, args) => {
68
+ if (args.trustTier === "first-party") return args.renderTrustedContent(text, {
69
+ nonce: args.nonce,
70
+ kind: "media-fallback",
71
+ tool: args.toolName,
72
+ modality: args.modality
73
+ });
74
+ return args.renderUntrustedContent(text, {
75
+ nonce: args.nonce,
76
+ kind: "media-fallback",
77
+ tool: args.toolName,
78
+ modality: args.modality
79
+ });
80
+ };
81
+ var renderSyntheticMediaDescription = (media, byteLen) => `[media: ${media.filename}, ${media.mimeType}, ${formatBytesHumanReadable(byteLen)}]`;
82
+ /**
83
+ * Render a single {@link Media} for the native Ollama wire. Images become a base64 entry pushed to
84
+ * the message's `images[]` array (returned via `image`); every other modality is unsupported and
85
+ * routes through `unsupportedMediaPolicy` to a text envelope (returned via `text`) or throws.
86
+ */
87
+ var renderMediaForOllama = async (input) => {
88
+ const { media, toolName, nonce, unsupportedMediaPolicy, warn } = input;
89
+ const modality = modalityHazardToAttr(media.modalityHazard);
90
+ if (media.kind === "image") return { image: await media.asBase64() };
91
+ const fallbackText = async (keys, allowSyntheticFallthrough) => {
92
+ const fallback = resolveFallbackStash(media, keys);
93
+ if (fallback) return { text: renderTextInEnvelope(fallback.text, {
94
+ trustTier: fallback.entryTier,
95
+ modality,
96
+ nonce,
97
+ toolName,
98
+ renderTrustedContent: input.renderTrustedContent,
99
+ renderUntrustedContent: input.renderUntrustedContent
100
+ }) };
101
+ if (!allowSyntheticFallthrough) warn?.(`unsupportedMediaPolicy='fallback-stash' for ${media.filename}: no matching stash entry — falling through to synthetic description.`);
102
+ return { text: renderTextInEnvelope(renderSyntheticMediaDescription(media, await media.byteLength()), {
103
+ trustTier: media.trustTier,
104
+ modality,
105
+ nonce,
106
+ toolName,
107
+ renderTrustedContent: input.renderTrustedContent,
108
+ renderUntrustedContent: input.renderUntrustedContent
109
+ }) };
110
+ };
111
+ if (unsupportedMediaPolicy === "throw") throw new require_batteries_llm_ollama_exceptions.E_OLLAMA_UNSUPPORTED_MEDIA_MODALITY([
112
+ media.kind,
113
+ media.mimeType,
114
+ media.filename
115
+ ]);
116
+ if (unsupportedMediaPolicy === "fallback-stash" || typeof unsupportedMediaPolicy === "object" && unsupportedMediaPolicy.mode === "fallback-stash") return fallbackText(typeof unsupportedMediaPolicy === "object" ? unsupportedMediaPolicy.stashKeys : DEFAULT_STASH_FALLBACK_KEYS, false);
117
+ return fallbackText([], true);
118
+ };
119
+ /**
120
+ * Renders a single timeline {@link @nhtio/adk!Message} into a native Ollama message — flattening any
121
+ * media into the base64 `images[]` array, surfacing reasoning as `thinking`, and wrapping textual
122
+ * bodies in the appropriate trust envelope.
123
+ */
124
+ var renderOllamaTimelineMessage = async (input) => {
125
+ const { message, selfIdentity, unsupportedMediaPolicy, warn } = input;
126
+ const identifier = message.identity?.identifier !== void 0 && message.identity?.identifier !== null ? String(message.identity.identifier) : "";
127
+ const representationRaw = message.identity?.representation !== void 0 && message.identity?.representation !== null ? message.identity.representation.toString() : "";
128
+ const representation = representationRaw.length > 0 ? representationRaw : identifier;
129
+ const text = message.content !== void 0 ? message.content.toString() : "";
130
+ const createdAtStr = message.createdAt.toISO?.() ?? "";
131
+ const createdAtAttr = createdAtStr ? ` createdAt="${require_helpers.escapeXmlAttribute(createdAtStr)}"` : "";
132
+ const attachments = message.attachments;
133
+ let envelopeText;
134
+ let role;
135
+ if (message.role === "user") {
136
+ role = "user";
137
+ if (identifier.length === 0) envelopeText = text;
138
+ else {
139
+ const fromAttr = require_helpers.escapeXmlAttribute(representation);
140
+ envelopeText = `<message_${message.id} from="${fromAttr}" role="user"${createdAtAttr}>\n${text}\n</message_${message.id}>`;
141
+ }
142
+ } else {
143
+ role = "assistant";
144
+ if (identifier.length === 0 || identifier === selfIdentity) envelopeText = text;
145
+ else {
146
+ const fromAttr = require_helpers.escapeXmlAttribute(representation);
147
+ envelopeText = `<peer_agent_output_${message.id} from="${fromAttr}"${createdAtAttr}>\n${text}\n</peer_agent_output_${message.id}>`;
148
+ }
149
+ }
150
+ const images = [];
151
+ const extraTexts = [];
152
+ for (const media of attachments) {
153
+ const rendered = await renderMediaForOllama({
154
+ media,
155
+ toolName: void 0,
156
+ nonce: message.id,
157
+ unsupportedMediaPolicy,
158
+ renderTrustedContent: require_helpers.renderTrustedContent,
159
+ renderUntrustedContent: require_helpers.renderUntrustedContent,
160
+ warn
161
+ });
162
+ if (rendered.image !== void 0) images.push(rendered.image);
163
+ if (rendered.text !== void 0) extraTexts.push(rendered.text);
164
+ }
165
+ const contentParts = [];
166
+ if (envelopeText.length > 0) contentParts.push(envelopeText);
167
+ for (const t of extraTexts) contentParts.push(t);
168
+ const out = {
169
+ role,
170
+ content: contentParts.join("\n")
171
+ };
172
+ if (images.length > 0) out.images = images;
173
+ return out;
174
+ };
175
+ /** Default timeline-message renderer; alias of {@link renderOllamaTimelineMessage}. */
176
+ var defaultRenderOllamaTimelineMessage = renderOllamaTimelineMessage;
177
+ var looksLikeSpooledArtifact = (value) => {
178
+ if (!value || typeof value !== "object") return false;
179
+ const v = value;
180
+ return typeof v.asString === "function" && typeof v.byteLength === "function" && typeof v.lineCount === "function" && typeof v.estimateTokens === "function";
181
+ };
182
+ var renderArtifactHandleBody = (toolCall, artifact, byteLength, lineCount) => {
183
+ const ctor = artifact.constructor;
184
+ const methods = ctor?.toolMethods ?? [];
185
+ const lines = [];
186
+ lines.push(`This tool returned a large artifact that was not inlined to preserve context budget.`);
187
+ lines.push(``);
188
+ lines.push(`Artifact metadata:`);
189
+ lines.push(`- callId: ${toolCall.id}`);
190
+ lines.push(`- kind: ${ctor?.constructor?.name ?? "SpooledArtifact"}`);
191
+ lines.push(`- byteLength: ${byteLength}`);
192
+ lines.push(`- lineCount: ${lineCount}`);
193
+ lines.push(``);
194
+ lines.push(`To read this artifact in this turn, call one of the following tools with`);
195
+ lines.push(`callId=${toolCall.id}:`);
196
+ for (const m of methods) if (m.description) lines.push(`- ${m.name} — ${m.description}`);
197
+ else lines.push(`- ${m.name}`);
198
+ lines.push(``);
199
+ lines.push(`The artifact persists in this turn's context — multiple queries against the same callId are allowed and efficient. Do not assume the body has been inlined anywhere else.`);
200
+ return lines.join("\n");
201
+ };
202
+ /**
203
+ * Render a tool-call result to native Ollama tool-message content (always a string). Media results
204
+ * are routed through the internal media renderer: images cannot ride on a tool-role message's
205
+ * `content`, so an image result is replaced with a short text marker (the image bytes are not
206
+ * re-sent on a tool message); non-image media use the same fallback-text path as elsewhere.
207
+ */
208
+ var renderOllamaToolCallResult = async (input) => {
209
+ const { toolCall, results, tool, warn, unsupportedMediaPolicy } = input;
210
+ const isTrusted = tool !== null && tool !== void 0 && tool.trusted === true;
211
+ if (tool === void 0) warn?.(`Tool "${toolCall.tool}" is not present in the bound tool registry at render time; defaulting to untrusted envelope.`);
212
+ const isMediaResult = require_tool_call.Media.isMedia(results);
213
+ const isMediaArrayResult = Array.isArray(results) && results.length > 0 && results.every((r) => require_tool_call.Media.isMedia(r));
214
+ if (isMediaResult || isMediaArrayResult) {
215
+ const mediaList = isMediaResult ? [results] : results;
216
+ const parts = [];
217
+ for (const media of mediaList) {
218
+ const rendered = await renderMediaForOllama({
219
+ media,
220
+ toolName: toolCall.tool,
221
+ nonce: toolCall.checksum,
222
+ unsupportedMediaPolicy,
223
+ renderTrustedContent: input.renderTrustedContent,
224
+ renderUntrustedContent: input.renderUntrustedContent,
225
+ warn
226
+ });
227
+ if (rendered.text !== void 0) parts.push(rendered.text);
228
+ else {
229
+ const byteLen = await media.byteLength();
230
+ parts.push(input.renderUntrustedContent(renderSyntheticMediaDescription(media, byteLen), {
231
+ nonce: toolCall.checksum,
232
+ kind: "tool-result-image",
233
+ tool: toolCall.tool,
234
+ modality: modalityHazardToAttr(media.modalityHazard)
235
+ }));
236
+ }
237
+ }
238
+ return parts.join("\n");
239
+ }
240
+ if (Array.isArray(results)) {
241
+ const parts = [];
242
+ for (const a of results) parts.push(await a.asString());
243
+ const joined = parts.join("\n\n");
244
+ return isTrusted ? input.renderTrustedContent(joined, {
245
+ nonce: toolCall.checksum,
246
+ kind: "trusted-tool-result",
247
+ tool: toolCall.tool
248
+ }) : input.renderUntrustedContent(joined, {
249
+ nonce: toolCall.checksum,
250
+ kind: "tool-result",
251
+ tool: toolCall.tool
252
+ });
253
+ }
254
+ const isSpooled = looksLikeSpooledArtifact(results);
255
+ if (isSpooled && toolCall.inline === false) {
256
+ const artifact = results;
257
+ let byteLength = 0;
258
+ let lineCount = 0;
259
+ try {
260
+ byteLength = await artifact.byteLength();
261
+ } catch {
262
+ byteLength = 0;
263
+ }
264
+ try {
265
+ lineCount = await artifact.lineCount();
266
+ } catch {
267
+ lineCount = 0;
268
+ }
269
+ const body = renderArtifactHandleBody(toolCall, artifact, byteLength, lineCount);
270
+ return input.renderUntrustedContent(body, {
271
+ nonce: toolCall.checksum,
272
+ kind: "artifact-handle",
273
+ tool: toolCall.tool
274
+ });
275
+ }
276
+ if (!isSpooled && toolCall.inline === false) warn?.(`Tool call ${toolCall.id} has inline=false but results is a Tokenizable (not a SpooledArtifact); rendering inline anyway.`);
277
+ const body = isSpooled ? await results.asString() : results.toString();
278
+ return isTrusted ? input.renderTrustedContent(body, {
279
+ nonce: toolCall.checksum,
280
+ kind: "trusted-tool-result",
281
+ tool: toolCall.tool
282
+ }) : input.renderUntrustedContent(body, {
283
+ nonce: toolCall.checksum,
284
+ kind: "tool-result",
285
+ tool: toolCall.tool
286
+ });
287
+ };
288
+ /** Default tool-call-result renderer; alias of {@link renderOllamaToolCallResult}. */
289
+ var defaultRenderOllamaToolCallResult = renderOllamaToolCallResult;
290
+ /**
291
+ * Assembles the complete native Ollama message history for a dispatch — system prompt and content
292
+ * buckets, the interleaved timeline of messages/thoughts/tool calls, and the collected opaque
293
+ * reasoning payloads — by delegating to the injected sub-renderers.
294
+ */
295
+ var buildOllamaHistory = async (input) => {
296
+ const out = [];
297
+ const reasoningPayloads = [];
298
+ const buckets = input.bucketOrder;
299
+ const timelineIdx = buckets.indexOf("timeline");
300
+ const leadingSystem = await input.renderChatCompletionsSystemPrompt({
301
+ systemPrompt: input.systemPrompt,
302
+ standingInstructions: input.standingInstructions,
303
+ memories: input.memories,
304
+ retrievables: input.retrievables,
305
+ bucketOrder: buckets,
306
+ renderStandingInstructions: input.renderStandingInstructions,
307
+ renderMemories: input.renderMemories,
308
+ renderRetrievables: input.renderRetrievables,
309
+ renderRetrievableSafetyDirective: input.renderRetrievableSafetyDirective,
310
+ renderFirstPartyRetrievables: input.renderFirstPartyRetrievables,
311
+ renderThirdPartyPublicRetrievables: input.renderThirdPartyPublicRetrievables,
312
+ renderThirdPartyPrivateRetrievables: input.renderThirdPartyPrivateRetrievables,
313
+ renderUntrustedContent: input.renderUntrustedContent
314
+ });
315
+ if (leadingSystem.length > 0) out.push({
316
+ role: "system",
317
+ content: leadingSystem
318
+ });
319
+ const includesTimeline = timelineIdx !== -1;
320
+ if (includesTimeline) {
321
+ const survivingThoughts = input.filterThoughts(input.thoughts, input.thoughtSurfacing, input.selfIdentity, input.replayCompatibility);
322
+ const items = [];
323
+ for (const m of input.messages) items.push({
324
+ kind: "message",
325
+ createdAt: m.createdAt.toMillis(),
326
+ value: m
327
+ });
328
+ for (const t of survivingThoughts) items.push({
329
+ kind: "thought",
330
+ createdAt: t.createdAt.toMillis(),
331
+ value: t
332
+ });
333
+ for (const tc of input.toolCalls) items.push({
334
+ kind: "toolCall",
335
+ createdAt: tc.createdAt.toMillis(),
336
+ value: tc
337
+ });
338
+ items.sort((a, b) => a.createdAt - b.createdAt);
339
+ const replaySet = new Set([...input.replayCompatibility]);
340
+ for (const item of items) if (item.kind === "message") out.push(await input.renderOllamaTimelineMessage({
341
+ message: item.value,
342
+ selfIdentity: input.selfIdentity,
343
+ unsupportedMediaPolicy: input.unsupportedMediaPolicy,
344
+ warn: input.warn
345
+ }));
346
+ else if (item.kind === "thought") {
347
+ const t = item.value;
348
+ const identifier = String(t.identity?.identifier ?? "");
349
+ const isSelf = identifier === input.selfIdentity;
350
+ const hasPayload = t.payload !== void 0;
351
+ const compatTag = t.replayCompatibility;
352
+ if (hasPayload && compatTag && replaySet.has(compatTag)) {
353
+ reasoningPayloads.push({
354
+ id: t.id,
355
+ replayCompatibility: compatTag,
356
+ payload: t.payload
357
+ });
358
+ const envelope = input.renderThought(t.content.toString(), {
359
+ nonce: t.id,
360
+ kind: "opaque-reasoning",
361
+ from: identifier,
362
+ createdAt: t.createdAt?.toISO?.() ?? void 0,
363
+ replayCompatibility: compatTag
364
+ }, t.payload);
365
+ out.push({
366
+ role: "assistant",
367
+ content: envelope
368
+ });
369
+ } else if (!hasPayload) {
370
+ const envelope = input.renderThought(t.content.toString(), {
371
+ nonce: t.id,
372
+ kind: isSelf ? "self-reasoning" : "peer-reasoning",
373
+ from: identifier,
374
+ createdAt: t.createdAt?.toISO?.() ?? void 0
375
+ });
376
+ out.push({
377
+ role: "assistant",
378
+ content: envelope
379
+ });
380
+ }
381
+ } else {
382
+ const tc = item.value;
383
+ const args = tc.args !== null && typeof tc.args === "object" && !Array.isArray(tc.args) ? tc.args : {};
384
+ out.push({
385
+ role: "assistant",
386
+ content: "",
387
+ tool_calls: [{ function: {
388
+ name: tc.tool,
389
+ arguments: args
390
+ } }]
391
+ });
392
+ let rendered = input.renderedToolCallResults.get(tc.id);
393
+ if (rendered === void 0) {
394
+ const tool = input.tools.get?.(tc.tool);
395
+ rendered = await input.renderOllamaToolCallResult({
396
+ toolCall: tc,
397
+ results: tc.results,
398
+ tool,
399
+ renderUntrustedContent: input.renderUntrustedContent,
400
+ renderTrustedContent: input.renderTrustedContent,
401
+ unsupportedMediaPolicy: input.unsupportedMediaPolicy,
402
+ warn: input.warn
403
+ });
404
+ }
405
+ out.push({
406
+ role: "tool",
407
+ content: rendered,
408
+ tool_name: tc.tool
409
+ });
410
+ }
411
+ }
412
+ if (includesTimeline) {
413
+ const trailingParts = [];
414
+ for (let i = timelineIdx + 1; i < buckets.length; i++) {
415
+ const label = buckets[i];
416
+ if (label === "standingInstructions") {
417
+ const block = input.renderStandingInstructions(input.standingInstructions);
418
+ if (block.length > 0) trailingParts.push(block);
419
+ } else if (label === "memories") {
420
+ const wrapped = [];
421
+ for (const m of input.memories) wrapped.push(require_helpers.memoryToAttrs(m));
422
+ const block = input.renderMemories(wrapped);
423
+ if (block.length > 0) trailingParts.push(block);
424
+ } else if (label === "retrievables") {
425
+ const wrapped = [];
426
+ for (const r of input.retrievables) wrapped.push(require_helpers.retrievableToAttrs(r));
427
+ const block = await input.renderRetrievables(wrapped, {
428
+ renderRetrievableSafetyDirective: input.renderRetrievableSafetyDirective,
429
+ renderFirstPartyRetrievables: input.renderFirstPartyRetrievables,
430
+ renderThirdPartyPublicRetrievables: input.renderThirdPartyPublicRetrievables,
431
+ renderThirdPartyPrivateRetrievables: input.renderThirdPartyPrivateRetrievables,
432
+ renderUntrustedContent: input.renderUntrustedContent
433
+ });
434
+ if (block.length > 0) trailingParts.push(block);
435
+ }
436
+ }
437
+ if (trailingParts.length > 0) out.push({
438
+ role: "system",
439
+ content: trailingParts.join("\n\n")
440
+ });
441
+ }
442
+ return {
443
+ messages: out,
444
+ reasoningPayloads
445
+ };
446
+ };
447
+ /** Default native-history assembler; alias of {@link buildOllamaHistory}. */
448
+ var defaultBuildOllamaHistory = buildOllamaHistory;
449
+ //#endregion
450
+ exports.buildOllamaHistory = buildOllamaHistory;
451
+ exports.defaultBuildOllamaHistory = defaultBuildOllamaHistory;
452
+ exports.defaultDescriptionToChatCompletionsJsonSchema = require_helpers.defaultDescriptionToChatCompletionsJsonSchema;
453
+ exports.defaultFilterThoughts = require_helpers.defaultFilterThoughts;
454
+ exports.defaultOllamaToolsFromTools = defaultOllamaToolsFromTools;
455
+ exports.defaultRenderChatCompletionsSystemPrompt = require_helpers.defaultRenderChatCompletionsSystemPrompt;
456
+ exports.defaultRenderFirstPartyRetrievables = require_helpers.defaultRenderFirstPartyRetrievables;
457
+ exports.defaultRenderMemories = require_helpers.defaultRenderMemories;
458
+ exports.defaultRenderOllamaTimelineMessage = defaultRenderOllamaTimelineMessage;
459
+ exports.defaultRenderOllamaToolCallResult = defaultRenderOllamaToolCallResult;
460
+ exports.defaultRenderRetrievableSafetyDirective = require_helpers.defaultRenderRetrievableSafetyDirective;
461
+ exports.defaultRenderRetrievables = require_helpers.defaultRenderRetrievables;
462
+ exports.defaultRenderStandingInstructions = require_helpers.defaultRenderStandingInstructions;
463
+ exports.defaultRenderThirdPartyPrivateRetrievables = require_helpers.defaultRenderThirdPartyPrivateRetrievables;
464
+ exports.defaultRenderThirdPartyPublicRetrievables = require_helpers.defaultRenderThirdPartyPublicRetrievables;
465
+ exports.defaultRenderThought = require_helpers.defaultRenderThought;
466
+ exports.defaultRenderTrustedContent = require_helpers.defaultRenderTrustedContent;
467
+ exports.defaultRenderUntrustedContent = require_helpers.defaultRenderUntrustedContent;
468
+ exports.defaultToolsToChatCompletionsTools = require_helpers.defaultToolsToChatCompletionsTools;
469
+ exports.descriptionToChatCompletionsJsonSchema = require_helpers.descriptionToChatCompletionsJsonSchema;
470
+ exports.filterThoughts = require_helpers.filterThoughts;
471
+ exports.ollamaToolsFromTools = ollamaToolsFromTools;
472
+ exports.renderChatCompletionsSystemPrompt = require_helpers.renderChatCompletionsSystemPrompt;
473
+ exports.renderFirstPartyRetrievables = require_helpers.renderFirstPartyRetrievables;
474
+ exports.renderMemories = require_helpers.renderMemories;
475
+ exports.renderOllamaTimelineMessage = renderOllamaTimelineMessage;
476
+ exports.renderOllamaToolCallResult = renderOllamaToolCallResult;
477
+ exports.renderRetrievableSafetyDirective = require_helpers.renderRetrievableSafetyDirective;
478
+ exports.renderRetrievables = require_helpers.renderRetrievables;
479
+ exports.renderStandingInstructions = require_helpers.renderStandingInstructions;
480
+ exports.renderThirdPartyPrivateRetrievables = require_helpers.renderThirdPartyPrivateRetrievables;
481
+ exports.renderThirdPartyPublicRetrievables = require_helpers.renderThirdPartyPublicRetrievables;
482
+ exports.renderThought = require_helpers.renderThought;
483
+ exports.renderTrustedContent = require_helpers.renderTrustedContent;
484
+ exports.renderUntrustedContent = require_helpers.renderUntrustedContent;
485
+ exports.toolsToChatCompletionsTools = require_helpers.toolsToChatCompletionsTools;
486
+
487
+ //# sourceMappingURL=helpers.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.cjs","names":[],"sources":["../../../../src/batteries/llm/ollama/helpers.ts"],"sourcesContent":["/**\n * Swappable translation helpers for rendering ADK state into native Ollama `/api/chat` requests.\n *\n * @module @nhtio/adk/batteries/llm/ollama/helpers\n *\n * @remarks\n * The wire-shape-agnostic helpers (`renderUntrustedContent`, `renderMemories`,\n * `renderChatCompletionsSystemPrompt`, `toolsToChatCompletionsTools`, …) are shared with the OpenAI\n * battery via the internal `../chat_common/helpers` submodule and re-exported here under their\n * original names. Only the Ollama-WIRE-SPECIFIC helpers are defined here:\n * `renderOllamaTimelineMessage` (flat `content` + base64 `images[]` + `thinking`),\n * `renderOllamaToolCallResult` (string-only result content), `buildOllamaHistory` (synthetic\n * `assistant.tool_calls` with object-form `arguments` + `tool`-role messages labelled by\n * `tool_name`), and `ollamaToolsFromTools` (alias of the shared tool-definition renderer — native\n * `/api/chat` uses the same function-tool wire shape).\n *\n * Native `/api/chat` supports only base64 `images[]`; every non-image modality routes through the\n * `unsupportedMediaPolicy` fallback (stash text / synthetic description) or throws.\n */\n\nimport { Media } from '@nhtio/adk/common'\nimport { isInstanceOf } from '@nhtio/adk/guards'\nimport { E_OLLAMA_UNSUPPORTED_MEDIA_MODALITY } from './exceptions'\nimport {\n escapeXmlAttribute,\n memoryToAttrs,\n retrievableToAttrs,\n renderTrustedContent,\n renderUntrustedContent,\n toolsToChatCompletionsTools,\n} from '../chat_common/helpers'\nimport type { ChatHelpersCommon } from '../chat_common/types'\nimport type {\n OllamaMessage,\n OllamaTool,\n OllamaHelpers,\n MemoryAttrs,\n RetrievableAttrs,\n ChatCompletionsBucketOrder,\n UnsupportedMediaPolicy,\n} from './types'\nimport type {\n Tool,\n ArtifactTool,\n ToolRegistry,\n Tokenizable,\n Memory,\n Message,\n Thought,\n ToolCall,\n Retrievable,\n SpooledArtifact,\n MediaModalityHazard,\n MediaStashEntry,\n} from '@nhtio/adk/common'\n\n// ─── Re-exported wire-shape-agnostic helpers (shared submodule) ───────────────\nexport {\n descriptionToChatCompletionsJsonSchema,\n defaultDescriptionToChatCompletionsJsonSchema,\n renderUntrustedContent,\n defaultRenderUntrustedContent,\n renderTrustedContent,\n defaultRenderTrustedContent,\n renderStandingInstructions,\n defaultRenderStandingInstructions,\n renderMemories,\n defaultRenderMemories,\n renderRetrievableSafetyDirective,\n defaultRenderRetrievableSafetyDirective,\n renderFirstPartyRetrievables,\n defaultRenderFirstPartyRetrievables,\n renderThirdPartyPublicRetrievables,\n defaultRenderThirdPartyPublicRetrievables,\n renderThirdPartyPrivateRetrievables,\n defaultRenderThirdPartyPrivateRetrievables,\n renderRetrievables,\n defaultRenderRetrievables,\n renderThought,\n defaultRenderThought,\n filterThoughts,\n defaultFilterThoughts,\n toolsToChatCompletionsTools,\n defaultToolsToChatCompletionsTools,\n renderChatCompletionsSystemPrompt,\n defaultRenderChatCompletionsSystemPrompt,\n} from '../chat_common/helpers'\n\n// ─── ollamaToolsFromTools (alias — native tool wire == Chat Completions wire) ──\n\n/**\n * Convert ADK tools to the native Ollama `tools[]` wire. Native `/api/chat` uses the identical\n * `{ type: 'function', function: { name, description, parameters } }` shape as Chat Completions, so\n * this is an alias of the shared renderer.\n */\nexport const ollamaToolsFromTools = (\n tools: ReadonlyArray<Tool | ArtifactTool>,\n deps: Parameters<typeof toolsToChatCompletionsTools>[1]\n): OllamaTool[] => toolsToChatCompletionsTools(tools, deps)\n/** Default implementation of {@link OllamaHelpers}-style tool translation; alias of {@link ollamaToolsFromTools}. */\nexport const defaultOllamaToolsFromTools = ollamaToolsFromTools\n\n// ─── Media rendering (Ollama native — images only) ────────────────────────────\n\nconst DEFAULT_STASH_FALLBACK_KEYS: ReadonlyArray<string> = [\n 'text:transcript',\n 'text:caption',\n 'text:description',\n]\n\nconst modalityHazardToAttr = (h: MediaModalityHazard): 'inert' | 'extractable' | 'opaque' => {\n if (h === 'inert') return 'inert'\n if (h === 'extractable-instructions') return 'extractable'\n return 'opaque'\n}\n\nconst formatBytesHumanReadable = (bytes: number | undefined): string => {\n if (bytes === undefined || !Number.isFinite(bytes)) return 'unknown size'\n if (bytes < 1024) return `${bytes} B`\n if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`\n if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`\n return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GB`\n}\n\nconst isMediaTextStashEntry = (e: unknown): e is MediaStashEntry => {\n if (!e || typeof e !== 'object') return false\n const r = e as Record<string, unknown>\n return typeof r.value === 'string' && typeof r.trustTier === 'string'\n}\n\nconst resolveFallbackStash = (\n media: Media,\n keys: ReadonlyArray<string>\n): { text: string; entryTier: MediaStashEntry['trustTier'] } | undefined => {\n for (const key of keys) {\n const entry = media.stash.get(key)\n if (isMediaTextStashEntry(entry)) {\n return { text: entry.value as string, entryTier: entry.trustTier }\n }\n }\n return undefined\n}\n\nconst renderTextInEnvelope = (\n text: string,\n args: {\n trustTier: MediaStashEntry['trustTier']\n modality: 'inert' | 'extractable' | 'opaque'\n nonce: string\n toolName: string | undefined\n renderTrustedContent: ChatHelpersCommon['renderTrustedContent']\n renderUntrustedContent: ChatHelpersCommon['renderUntrustedContent']\n }\n): string => {\n if (args.trustTier === 'first-party') {\n return args.renderTrustedContent(text, {\n nonce: args.nonce,\n kind: 'media-fallback',\n tool: args.toolName,\n modality: args.modality,\n })\n }\n return args.renderUntrustedContent(text, {\n nonce: args.nonce,\n kind: 'media-fallback',\n tool: args.toolName,\n modality: args.modality,\n })\n}\n\nconst renderSyntheticMediaDescription = (media: Media, byteLen: number | undefined): string =>\n `[media: ${media.filename}, ${media.mimeType}, ${formatBytesHumanReadable(byteLen)}]`\n\n/**\n * Render a single {@link Media} for the native Ollama wire. Images become a base64 entry pushed to\n * the message's `images[]` array (returned via `image`); every other modality is unsupported and\n * routes through `unsupportedMediaPolicy` to a text envelope (returned via `text`) or throws.\n */\nconst renderMediaForOllama = async (input: {\n media: Media\n toolName: string | undefined\n nonce: string\n unsupportedMediaPolicy: UnsupportedMediaPolicy\n renderTrustedContent: ChatHelpersCommon['renderTrustedContent']\n renderUntrustedContent: ChatHelpersCommon['renderUntrustedContent']\n warn?: (msg: string) => void\n}): Promise<{ image?: string; text?: string }> => {\n const { media, toolName, nonce, unsupportedMediaPolicy, warn } = input\n const modality = modalityHazardToAttr(media.modalityHazard)\n\n if (media.kind === 'image') {\n const b64 = await media.asBase64()\n return { image: b64 }\n }\n\n // Non-image modality — native /api/chat has no representation for it.\n const fallbackText = async (\n keys: ReadonlyArray<string>,\n allowSyntheticFallthrough: boolean\n ): Promise<{ text: string }> => {\n const fallback = resolveFallbackStash(media, keys)\n if (fallback) {\n return {\n text: renderTextInEnvelope(fallback.text, {\n trustTier: fallback.entryTier,\n modality,\n nonce,\n toolName,\n renderTrustedContent: input.renderTrustedContent,\n renderUntrustedContent: input.renderUntrustedContent,\n }),\n }\n }\n if (!allowSyntheticFallthrough) {\n warn?.(\n `unsupportedMediaPolicy='fallback-stash' for ${media.filename}: no matching stash entry — falling through to synthetic description.`\n )\n }\n const byteLen = await media.byteLength()\n return {\n text: renderTextInEnvelope(renderSyntheticMediaDescription(media, byteLen), {\n trustTier: media.trustTier,\n modality,\n nonce,\n toolName,\n renderTrustedContent: input.renderTrustedContent,\n renderUntrustedContent: input.renderUntrustedContent,\n }),\n }\n }\n\n if (unsupportedMediaPolicy === 'throw') {\n throw new E_OLLAMA_UNSUPPORTED_MEDIA_MODALITY([media.kind, media.mimeType, media.filename])\n }\n if (\n unsupportedMediaPolicy === 'fallback-stash' ||\n (typeof unsupportedMediaPolicy === 'object' && unsupportedMediaPolicy.mode === 'fallback-stash')\n ) {\n const keys =\n typeof unsupportedMediaPolicy === 'object'\n ? unsupportedMediaPolicy.stashKeys\n : DEFAULT_STASH_FALLBACK_KEYS\n return fallbackText(keys, false)\n }\n return fallbackText([], true)\n}\n\n// ─── renderOllamaTimelineMessage ──────────────────────────────────────────────\n\n/**\n * Renders a single timeline {@link @nhtio/adk!Message} into a native Ollama message — flattening any\n * media into the base64 `images[]` array, surfacing reasoning as `thinking`, and wrapping textual\n * bodies in the appropriate trust envelope.\n */\nexport const renderOllamaTimelineMessage = async (input: {\n message: Message\n selfIdentity: string\n unsupportedMediaPolicy: UnsupportedMediaPolicy\n warn?: (msg: string) => void\n}): Promise<OllamaMessage> => {\n const { message, selfIdentity, unsupportedMediaPolicy, warn } = input\n const identifier =\n message.identity?.identifier !== undefined && message.identity?.identifier !== null\n ? String(message.identity.identifier)\n : ''\n const representationRaw =\n message.identity?.representation !== undefined && message.identity?.representation !== null\n ? message.identity.representation.toString()\n : ''\n const representation = representationRaw.length > 0 ? representationRaw : identifier\n const text = message.content !== undefined ? message.content.toString() : ''\n const createdAtStr = message.createdAt.toISO?.() ?? ''\n const createdAtAttr = createdAtStr ? ` createdAt=\"${escapeXmlAttribute(createdAtStr)}\"` : ''\n const attachments = message.attachments\n\n // Build the text envelope (same identity logic as the OpenAI battery — wire-agnostic).\n let envelopeText: string\n let role: 'user' | 'assistant'\n if (message.role === 'user') {\n role = 'user'\n if (identifier.length === 0) {\n envelopeText = text\n } else {\n const fromAttr = escapeXmlAttribute(representation)\n envelopeText = `<message_${message.id} from=\"${fromAttr}\" role=\"user\"${createdAtAttr}>\\n${text}\\n</message_${message.id}>`\n }\n } else {\n role = 'assistant'\n if (identifier.length === 0 || identifier === selfIdentity) {\n envelopeText = text\n } else {\n const fromAttr = escapeXmlAttribute(representation)\n envelopeText = `<peer_agent_output_${message.id} from=\"${fromAttr}\"${createdAtAttr}>\\n${text}\\n</peer_agent_output_${message.id}>`\n }\n }\n\n const images: string[] = []\n const extraTexts: string[] = []\n for (const media of attachments) {\n const rendered = await renderMediaForOllama({\n media,\n toolName: undefined,\n nonce: message.id,\n unsupportedMediaPolicy,\n renderTrustedContent,\n renderUntrustedContent,\n warn,\n })\n if (rendered.image !== undefined) images.push(rendered.image)\n if (rendered.text !== undefined) extraTexts.push(rendered.text)\n }\n\n // Non-image fallbacks (text envelopes) are appended to the message content; images ride in the\n // separate native `images[]` field.\n const contentParts: string[] = []\n if (envelopeText.length > 0) contentParts.push(envelopeText)\n for (const t of extraTexts) contentParts.push(t)\n const out: OllamaMessage = { role, content: contentParts.join('\\n') }\n if (images.length > 0) out.images = images\n return out\n}\n/** Default timeline-message renderer; alias of {@link renderOllamaTimelineMessage}. */\nexport const defaultRenderOllamaTimelineMessage = renderOllamaTimelineMessage\n\n// ─── renderOllamaToolCallResult ───────────────────────────────────────────────\n\nconst looksLikeSpooledArtifact = (value: unknown): value is SpooledArtifact => {\n if (!value || typeof value !== 'object') return false\n const v = value as Record<string, unknown>\n return (\n typeof v.asString === 'function' &&\n typeof v.byteLength === 'function' &&\n typeof v.lineCount === 'function' &&\n typeof v.estimateTokens === 'function'\n )\n}\n\nconst renderArtifactHandleBody = (\n toolCall: ToolCall,\n artifact: SpooledArtifact,\n byteLength: number,\n lineCount: number\n): string => {\n const ctor = (\n artifact as unknown as {\n constructor: { toolMethods?: ReadonlyArray<{ name: string; description?: string }> }\n }\n ).constructor\n const methods = ctor?.toolMethods ?? []\n const lines: string[] = []\n lines.push(`This tool returned a large artifact that was not inlined to preserve context budget.`)\n lines.push(``)\n lines.push(`Artifact metadata:`)\n lines.push(`- callId: ${toolCall.id}`)\n lines.push(`- kind: ${ctor?.constructor?.name ?? 'SpooledArtifact'}`)\n lines.push(`- byteLength: ${byteLength}`)\n lines.push(`- lineCount: ${lineCount}`)\n lines.push(``)\n lines.push(`To read this artifact in this turn, call one of the following tools with`)\n lines.push(`callId=${toolCall.id}:`)\n for (const m of methods) {\n if (m.description) {\n lines.push(`- ${m.name} — ${m.description}`)\n } else {\n lines.push(`- ${m.name}`)\n }\n }\n lines.push(``)\n lines.push(\n `The artifact persists in this turn's context — multiple queries against the same callId are allowed and efficient. Do not assume the body has been inlined anywhere else.`\n )\n return lines.join('\\n')\n}\n\n/**\n * Render a tool-call result to native Ollama tool-message content (always a string). Media results\n * are routed through the internal media renderer: images cannot ride on a tool-role message's\n * `content`, so an image result is replaced with a short text marker (the image bytes are not\n * re-sent on a tool message); non-image media use the same fallback-text path as elsewhere.\n */\nexport const renderOllamaToolCallResult = async (input: {\n toolCall: ToolCall\n results: Tokenizable | SpooledArtifact | SpooledArtifact[] | Media | Media[]\n tool: Tool | ArtifactTool | undefined\n renderUntrustedContent: ChatHelpersCommon['renderUntrustedContent']\n renderTrustedContent: ChatHelpersCommon['renderTrustedContent']\n unsupportedMediaPolicy: UnsupportedMediaPolicy\n warn?: (msg: string) => void\n}): Promise<string> => {\n const { toolCall, results, tool, warn, unsupportedMediaPolicy } = input\n const isTrusted =\n tool !== null && tool !== undefined && (tool as { trusted?: boolean }).trusted === true\n\n if (tool === undefined) {\n warn?.(\n `Tool \"${toolCall.tool}\" is not present in the bound tool registry at render time; defaulting to untrusted envelope.`\n )\n }\n\n // Media silo — bypasses Tool.trusted (Trust-Is-Content rule).\n const isMediaResult = Media.isMedia(results)\n const isMediaArrayResult =\n Array.isArray(results) && results.length > 0 && results.every((r) => Media.isMedia(r))\n if (isMediaResult || isMediaArrayResult) {\n const mediaList = isMediaResult ? [results as Media] : (results as Media[])\n const parts: string[] = []\n for (const media of mediaList) {\n const rendered = await renderMediaForOllama({\n media,\n toolName: toolCall.tool,\n nonce: toolCall.checksum,\n unsupportedMediaPolicy,\n renderTrustedContent: input.renderTrustedContent,\n renderUntrustedContent: input.renderUntrustedContent,\n warn,\n })\n if (rendered.text !== undefined) {\n parts.push(rendered.text)\n } else {\n // An image tool-result cannot be carried on a tool-role message's string content; emit a\n // text marker in its place so the model knows an image was produced.\n const byteLen = await media.byteLength()\n parts.push(\n input.renderUntrustedContent(renderSyntheticMediaDescription(media, byteLen), {\n nonce: toolCall.checksum,\n kind: 'tool-result-image',\n tool: toolCall.tool,\n modality: modalityHazardToAttr(media.modalityHazard),\n })\n )\n }\n }\n return parts.join('\\n')\n }\n\n // SpooledArtifact[] silo.\n if (Array.isArray(results)) {\n const parts: string[] = []\n for (const a of results) {\n parts.push(await (a as SpooledArtifact).asString())\n }\n const joined = parts.join('\\n\\n')\n return isTrusted\n ? input.renderTrustedContent(joined, {\n nonce: toolCall.checksum,\n kind: 'trusted-tool-result',\n tool: toolCall.tool,\n })\n : input.renderUntrustedContent(joined, {\n nonce: toolCall.checksum,\n kind: 'tool-result',\n tool: toolCall.tool,\n })\n }\n\n const isSpooled = looksLikeSpooledArtifact(results)\n\n // Handle-pattern branch: spooled + inline=false → always untrusted (queryable-data).\n if (isSpooled && toolCall.inline === false) {\n const artifact = results as SpooledArtifact\n let byteLength = 0\n let lineCount = 0\n try {\n byteLength = await artifact.byteLength()\n } catch {\n byteLength = 0\n }\n try {\n lineCount = await artifact.lineCount()\n } catch {\n lineCount = 0\n }\n const body = renderArtifactHandleBody(toolCall, artifact, byteLength, lineCount)\n return input.renderUntrustedContent(body, {\n nonce: toolCall.checksum,\n kind: 'artifact-handle',\n tool: toolCall.tool,\n })\n }\n\n if (!isSpooled && toolCall.inline === false) {\n warn?.(\n `Tool call ${toolCall.id} has inline=false but results is a Tokenizable (not a SpooledArtifact); rendering inline anyway.`\n )\n }\n\n const body = isSpooled\n ? await (results as SpooledArtifact).asString()\n : (results as Tokenizable).toString()\n\n return isTrusted\n ? input.renderTrustedContent(body, {\n nonce: toolCall.checksum,\n kind: 'trusted-tool-result',\n tool: toolCall.tool,\n })\n : input.renderUntrustedContent(body, {\n nonce: toolCall.checksum,\n kind: 'tool-result',\n tool: toolCall.tool,\n })\n}\n/** Default tool-call-result renderer; alias of {@link renderOllamaToolCallResult}. */\nexport const defaultRenderOllamaToolCallResult = renderOllamaToolCallResult\n\n// ─── buildOllamaHistory ───────────────────────────────────────────────────────\n\ntype TimelineItem =\n | { kind: 'message'; createdAt: number; value: Message }\n | { kind: 'thought'; createdAt: number; value: Thought }\n | { kind: 'toolCall'; createdAt: number; value: ToolCall }\n\n/**\n * Assembles the complete native Ollama message history for a dispatch — system prompt and content\n * buckets, the interleaved timeline of messages/thoughts/tool calls, and the collected opaque\n * reasoning payloads — by delegating to the injected sub-renderers.\n */\nexport const buildOllamaHistory = async (input: {\n systemPrompt: Tokenizable\n standingInstructions: Iterable<Tokenizable>\n memories: Iterable<Memory>\n retrievables: Iterable<Retrievable>\n messages: Iterable<Message>\n thoughts: Iterable<Thought>\n toolCalls: Iterable<ToolCall>\n tools: ToolRegistry\n renderedToolCallResults: Map<string, string>\n bucketOrder: ChatCompletionsBucketOrder\n selfIdentity: string\n thoughtSurfacing: 'all-self' | 'latest-self' | 'all'\n replayCompatibility: ReadonlyArray<string>\n unsupportedMediaPolicy: UnsupportedMediaPolicy\n renderOllamaToolCallResult: OllamaHelpers['renderOllamaToolCallResult']\n renderChatCompletionsSystemPrompt: ChatHelpersCommon['renderChatCompletionsSystemPrompt']\n renderStandingInstructions: ChatHelpersCommon['renderStandingInstructions']\n renderMemories: ChatHelpersCommon['renderMemories']\n renderRetrievables: ChatHelpersCommon['renderRetrievables']\n renderRetrievableSafetyDirective: ChatHelpersCommon['renderRetrievableSafetyDirective']\n renderFirstPartyRetrievables: ChatHelpersCommon['renderFirstPartyRetrievables']\n renderThirdPartyPublicRetrievables: ChatHelpersCommon['renderThirdPartyPublicRetrievables']\n renderThirdPartyPrivateRetrievables: ChatHelpersCommon['renderThirdPartyPrivateRetrievables']\n renderOllamaTimelineMessage: OllamaHelpers['renderOllamaTimelineMessage']\n renderThought: ChatHelpersCommon['renderThought']\n filterThoughts: ChatHelpersCommon['filterThoughts']\n renderUntrustedContent: ChatHelpersCommon['renderUntrustedContent']\n renderTrustedContent: ChatHelpersCommon['renderTrustedContent']\n warn?: (msg: string) => void\n}): Promise<{\n messages: OllamaMessage[]\n reasoningPayloads: Array<{ id: string; replayCompatibility: string; payload: unknown }>\n}> => {\n const out: OllamaMessage[] = []\n const reasoningPayloads: Array<{ id: string; replayCompatibility: string; payload: unknown }> = []\n\n const buckets = input.bucketOrder\n const timelineIdx = buckets.indexOf('timeline')\n\n const leadingSystem = await input.renderChatCompletionsSystemPrompt({\n systemPrompt: input.systemPrompt,\n standingInstructions: input.standingInstructions,\n memories: input.memories,\n retrievables: input.retrievables,\n bucketOrder: buckets,\n renderStandingInstructions: input.renderStandingInstructions,\n renderMemories: input.renderMemories,\n renderRetrievables: input.renderRetrievables,\n renderRetrievableSafetyDirective: input.renderRetrievableSafetyDirective,\n renderFirstPartyRetrievables: input.renderFirstPartyRetrievables,\n renderThirdPartyPublicRetrievables: input.renderThirdPartyPublicRetrievables,\n renderThirdPartyPrivateRetrievables: input.renderThirdPartyPrivateRetrievables,\n renderUntrustedContent: input.renderUntrustedContent,\n })\n if (leadingSystem.length > 0) {\n out.push({ role: 'system', content: leadingSystem })\n }\n\n const includesTimeline = timelineIdx !== -1\n if (includesTimeline) {\n const survivingThoughts = input.filterThoughts(\n input.thoughts,\n input.thoughtSurfacing,\n input.selfIdentity,\n input.replayCompatibility\n )\n\n const items: TimelineItem[] = []\n for (const m of input.messages) {\n items.push({ kind: 'message', createdAt: m.createdAt.toMillis(), value: m })\n }\n for (const t of survivingThoughts) {\n items.push({ kind: 'thought', createdAt: t.createdAt.toMillis(), value: t })\n }\n for (const tc of input.toolCalls) {\n items.push({ kind: 'toolCall', createdAt: tc.createdAt.toMillis(), value: tc })\n }\n items.sort((a, b) => a.createdAt - b.createdAt)\n\n const replaySet = new Set<string>([...input.replayCompatibility])\n\n for (const item of items) {\n if (item.kind === 'message') {\n out.push(\n await input.renderOllamaTimelineMessage({\n message: item.value,\n selfIdentity: input.selfIdentity,\n unsupportedMediaPolicy: input.unsupportedMediaPolicy,\n warn: input.warn,\n })\n )\n } else if (item.kind === 'thought') {\n const t = item.value\n const identifier = String(t.identity?.identifier ?? '')\n const isSelf = identifier === input.selfIdentity\n const hasPayload = t.payload !== undefined\n const compatTag = t.replayCompatibility\n\n if (hasPayload && compatTag && replaySet.has(compatTag)) {\n reasoningPayloads.push({ id: t.id, replayCompatibility: compatTag, payload: t.payload })\n const envelope = input.renderThought(\n t.content.toString(),\n {\n nonce: t.id,\n kind: 'opaque-reasoning',\n from: identifier,\n createdAt: t.createdAt?.toISO?.() ?? undefined,\n replayCompatibility: compatTag,\n },\n t.payload\n )\n out.push({ role: 'assistant', content: envelope })\n } else if (!hasPayload) {\n const envelope = input.renderThought(t.content.toString(), {\n nonce: t.id,\n kind: isSelf ? 'self-reasoning' : 'peer-reasoning',\n from: identifier,\n createdAt: t.createdAt?.toISO?.() ?? undefined,\n })\n out.push({ role: 'assistant', content: envelope })\n }\n // else: opaque, non-matching → elided.\n } else {\n // tool call: synthetic assistant message carrying tool_calls[] (object-form arguments),\n // followed by a tool-role message labelled by `tool_name` (NOT tool_call_id).\n const tc = item.value\n const args =\n tc.args !== null && typeof tc.args === 'object' && !Array.isArray(tc.args)\n ? (tc.args as Record<string, unknown>)\n : {}\n out.push({\n role: 'assistant',\n content: '',\n tool_calls: [{ function: { name: tc.tool, arguments: args } }],\n })\n\n let rendered = input.renderedToolCallResults.get(tc.id)\n if (rendered === undefined) {\n const tool = input.tools.get?.(tc.tool)\n rendered = await input.renderOllamaToolCallResult({\n toolCall: tc,\n results: tc.results as\n | Tokenizable\n | SpooledArtifact\n | SpooledArtifact[]\n | Media\n | Media[],\n tool: tool as Tool | ArtifactTool | undefined,\n renderUntrustedContent: input.renderUntrustedContent,\n renderTrustedContent: input.renderTrustedContent,\n unsupportedMediaPolicy: input.unsupportedMediaPolicy,\n warn: input.warn,\n })\n }\n out.push({ role: 'tool', content: rendered, tool_name: tc.tool })\n }\n }\n }\n\n if (includesTimeline) {\n const trailingParts: string[] = []\n for (let i = timelineIdx + 1; i < buckets.length; i++) {\n const label = buckets[i]!\n if (label === 'standingInstructions') {\n const block = input.renderStandingInstructions(input.standingInstructions)\n if (block.length > 0) trailingParts.push(block)\n } else if (label === 'memories') {\n const wrapped: Array<{ memory: Memory; attrs: MemoryAttrs }> = []\n for (const m of input.memories) {\n wrapped.push(memoryToAttrs(m))\n }\n const block = input.renderMemories(wrapped)\n if (block.length > 0) trailingParts.push(block)\n } else if (label === 'retrievables') {\n const wrapped: Array<{ retrievable: Retrievable; attrs: RetrievableAttrs }> = []\n for (const r of input.retrievables) {\n wrapped.push(retrievableToAttrs(r))\n }\n const block = await input.renderRetrievables(wrapped, {\n renderRetrievableSafetyDirective: input.renderRetrievableSafetyDirective,\n renderFirstPartyRetrievables: input.renderFirstPartyRetrievables,\n renderThirdPartyPublicRetrievables: input.renderThirdPartyPublicRetrievables,\n renderThirdPartyPrivateRetrievables: input.renderThirdPartyPrivateRetrievables,\n renderUntrustedContent: input.renderUntrustedContent,\n })\n if (block.length > 0) trailingParts.push(block)\n }\n }\n if (trailingParts.length > 0) {\n out.push({ role: 'system', content: trailingParts.join('\\n\\n') })\n }\n }\n\n return { messages: out, reasoningPayloads }\n}\n/** Default native-history assembler; alias of {@link buildOllamaHistory}. */\nexport const defaultBuildOllamaHistory = buildOllamaHistory\n\n// suppress unused\nvoid isInstanceOf\n"],"mappings":";;;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