@nhtio/adk 1.20260604.0 → 1.20260607.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 (358) hide show
  1. package/CHANGELOG.md +261 -0
  2. package/adk-mcp.mjs +1 -1
  3. package/batteries/embeddings/openai/adapter.cjs +1 -1
  4. package/batteries/embeddings/openai/adapter.mjs +1 -1
  5. package/batteries/embeddings/webllm/adapter.cjs +1 -1
  6. package/batteries/embeddings/webllm/adapter.mjs +1 -1
  7. package/batteries/index.d.ts +1 -0
  8. package/batteries/llm/openai_chat_completions/adapter.cjs +6 -6
  9. package/batteries/llm/openai_chat_completions/adapter.cjs.map +1 -1
  10. package/batteries/llm/openai_chat_completions/adapter.mjs +6 -6
  11. package/batteries/llm/openai_chat_completions/adapter.mjs.map +1 -1
  12. package/batteries/llm/openai_chat_completions/helpers.cjs +2 -2
  13. package/batteries/llm/openai_chat_completions/helpers.mjs +2 -2
  14. package/batteries/llm/openai_chat_completions/validation.cjs +2 -2
  15. package/batteries/llm/openai_chat_completions/validation.cjs.map +1 -1
  16. package/batteries/llm/openai_chat_completions/validation.mjs +2 -2
  17. package/batteries/llm/openai_chat_completions/validation.mjs.map +1 -1
  18. package/batteries/llm/webllm_chat_completions/adapter.cjs +6 -6
  19. package/batteries/llm/webllm_chat_completions/adapter.cjs.map +1 -1
  20. package/batteries/llm/webllm_chat_completions/adapter.mjs +6 -6
  21. package/batteries/llm/webllm_chat_completions/adapter.mjs.map +1 -1
  22. package/batteries/llm/webllm_chat_completions/validation.cjs +2 -2
  23. package/batteries/llm/webllm_chat_completions/validation.cjs.map +1 -1
  24. package/batteries/llm/webllm_chat_completions/validation.mjs +2 -2
  25. package/batteries/llm/webllm_chat_completions/validation.mjs.map +1 -1
  26. package/batteries/storage/flydrive.cjs +1 -1
  27. package/batteries/storage/flydrive.mjs +2 -2
  28. package/batteries/storage/in_memory.cjs +1 -1
  29. package/batteries/storage/in_memory.mjs +1 -1
  30. package/batteries/storage/opfs.cjs +1 -1
  31. package/batteries/storage/opfs.mjs +1 -1
  32. package/batteries/tools/color.cjs +2 -2
  33. package/batteries/tools/color.mjs +2 -2
  34. package/batteries/tools/comparison.cjs +3 -3
  35. package/batteries/tools/comparison.mjs +3 -3
  36. package/batteries/tools/data_structure.cjs +3 -3
  37. package/batteries/tools/data_structure.mjs +3 -3
  38. package/batteries/tools/datetime_extended.cjs +2 -2
  39. package/batteries/tools/datetime_extended.mjs +2 -2
  40. package/batteries/tools/datetime_math.cjs +2 -2
  41. package/batteries/tools/datetime_math.mjs +2 -2
  42. package/batteries/tools/encoding.cjs +3 -3
  43. package/batteries/tools/encoding.mjs +3 -3
  44. package/batteries/tools/formatting.cjs +3 -3
  45. package/batteries/tools/formatting.mjs +3 -3
  46. package/batteries/tools/geo_basics.cjs +2 -2
  47. package/batteries/tools/geo_basics.mjs +2 -2
  48. package/batteries/tools/math/index.d.ts +16 -5
  49. package/batteries/tools/math.cjs +340 -22
  50. package/batteries/tools/math.cjs.map +1 -1
  51. package/batteries/tools/math.mjs +338 -21
  52. package/batteries/tools/math.mjs.map +1 -1
  53. package/batteries/tools/memory.cjs +5 -5
  54. package/batteries/tools/memory.mjs +5 -5
  55. package/batteries/tools/parsing.cjs +4 -4
  56. package/batteries/tools/parsing.mjs +4 -4
  57. package/batteries/tools/retrievables.cjs +4 -4
  58. package/batteries/tools/retrievables.mjs +4 -4
  59. package/batteries/tools/standing_instructions.cjs +4 -4
  60. package/batteries/tools/standing_instructions.mjs +4 -4
  61. package/batteries/tools/statistics.cjs +4 -4
  62. package/batteries/tools/statistics.mjs +4 -4
  63. package/batteries/tools/string_processing.cjs +3 -3
  64. package/batteries/tools/string_processing.mjs +3 -3
  65. package/batteries/tools/structured_data.cjs +3 -3
  66. package/batteries/tools/structured_data.mjs +3 -3
  67. package/batteries/tools/text_analysis.cjs +3 -3
  68. package/batteries/tools/text_analysis.mjs +3 -3
  69. package/batteries/tools/text_comparison.cjs +2 -2
  70. package/batteries/tools/text_comparison.mjs +2 -2
  71. package/batteries/tools/time.cjs +2 -2
  72. package/batteries/tools/time.mjs +2 -2
  73. package/batteries/tools/unit_conversion.cjs +2 -2
  74. package/batteries/tools/unit_conversion.mjs +2 -2
  75. package/batteries/vector/arangodb/index.d.ts +38 -0
  76. package/batteries/vector/arangodb.cjs +257 -0
  77. package/batteries/vector/arangodb.cjs.map +1 -0
  78. package/batteries/vector/arangodb.mjs +255 -0
  79. package/batteries/vector/arangodb.mjs.map +1 -0
  80. package/batteries/vector/builder.cjs +297 -0
  81. package/batteries/vector/builder.cjs.map +1 -0
  82. package/batteries/vector/builder.d.ts +87 -0
  83. package/batteries/vector/builder.mjs +294 -0
  84. package/batteries/vector/builder.mjs.map +1 -0
  85. package/batteries/vector/chroma/index.d.ts +32 -0
  86. package/batteries/vector/chroma.cjs +305 -0
  87. package/batteries/vector/chroma.cjs.map +1 -0
  88. package/batteries/vector/chroma.mjs +302 -0
  89. package/batteries/vector/chroma.mjs.map +1 -0
  90. package/batteries/vector/clickhouse/index.d.ts +39 -0
  91. package/batteries/vector/clickhouse.cjs +246 -0
  92. package/batteries/vector/clickhouse.cjs.map +1 -0
  93. package/batteries/vector/clickhouse.mjs +244 -0
  94. package/batteries/vector/clickhouse.mjs.map +1 -0
  95. package/batteries/vector/cloudflare/index.d.ts +43 -0
  96. package/batteries/vector/cloudflare.cjs +397 -0
  97. package/batteries/vector/cloudflare.cjs.map +1 -0
  98. package/batteries/vector/cloudflare.mjs +395 -0
  99. package/batteries/vector/cloudflare.mjs.map +1 -0
  100. package/batteries/vector/conformance/index.d.ts +15 -0
  101. package/batteries/vector/conformance.cjs +209 -0
  102. package/batteries/vector/conformance.cjs.map +1 -0
  103. package/batteries/vector/conformance.mjs +205 -0
  104. package/batteries/vector/conformance.mjs.map +1 -0
  105. package/batteries/vector/contract.cjs +42 -0
  106. package/batteries/vector/contract.cjs.map +1 -0
  107. package/batteries/vector/contract.d.ts +39 -0
  108. package/batteries/vector/contract.mjs +40 -0
  109. package/batteries/vector/contract.mjs.map +1 -0
  110. package/batteries/vector/couchbase/index.d.ts +49 -0
  111. package/batteries/vector/couchbase.cjs +401 -0
  112. package/batteries/vector/couchbase.cjs.map +1 -0
  113. package/batteries/vector/couchbase.mjs +399 -0
  114. package/batteries/vector/couchbase.mjs.map +1 -0
  115. package/batteries/vector/duckdb/index.d.ts +33 -0
  116. package/batteries/vector/duckdb.cjs +218 -0
  117. package/batteries/vector/duckdb.cjs.map +1 -0
  118. package/batteries/vector/duckdb.mjs +216 -0
  119. package/batteries/vector/duckdb.mjs.map +1 -0
  120. package/batteries/vector/elasticsearch/index.d.ts +43 -0
  121. package/batteries/vector/elasticsearch.cjs +306 -0
  122. package/batteries/vector/elasticsearch.cjs.map +1 -0
  123. package/batteries/vector/elasticsearch.mjs +303 -0
  124. package/batteries/vector/elasticsearch.mjs.map +1 -0
  125. package/batteries/vector/exceptions.cjs +126 -0
  126. package/batteries/vector/exceptions.cjs.map +1 -0
  127. package/batteries/vector/exceptions.d.ts +142 -0
  128. package/batteries/vector/exceptions.mjs +107 -0
  129. package/batteries/vector/exceptions.mjs.map +1 -0
  130. package/batteries/vector/factory.cjs +28 -0
  131. package/batteries/vector/factory.cjs.map +1 -0
  132. package/batteries/vector/factory.d.ts +38 -0
  133. package/batteries/vector/factory.mjs +25 -0
  134. package/batteries/vector/factory.mjs.map +1 -0
  135. package/batteries/vector/filters.cjs +107 -0
  136. package/batteries/vector/filters.cjs.map +1 -0
  137. package/batteries/vector/filters.d.ts +34 -0
  138. package/batteries/vector/filters.mjs +99 -0
  139. package/batteries/vector/filters.mjs.map +1 -0
  140. package/batteries/vector/helpers.cjs +23 -0
  141. package/batteries/vector/helpers.cjs.map +1 -0
  142. package/batteries/vector/helpers.d.ts +12 -0
  143. package/batteries/vector/helpers.mjs +17 -0
  144. package/batteries/vector/helpers.mjs.map +1 -0
  145. package/batteries/vector/hnswlib/index.d.ts +35 -0
  146. package/batteries/vector/hnswlib.cjs +237 -0
  147. package/batteries/vector/hnswlib.cjs.map +1 -0
  148. package/batteries/vector/hnswlib.mjs +235 -0
  149. package/batteries/vector/hnswlib.mjs.map +1 -0
  150. package/batteries/vector/in_memory/index.d.ts +23 -0
  151. package/batteries/vector/in_memory.cjs +178 -0
  152. package/batteries/vector/in_memory.cjs.map +1 -0
  153. package/batteries/vector/in_memory.mjs +176 -0
  154. package/batteries/vector/in_memory.mjs.map +1 -0
  155. package/batteries/vector/index.d.ts +18 -0
  156. package/batteries/vector/lancedb/index.d.ts +34 -0
  157. package/batteries/vector/lancedb.cjs +224 -0
  158. package/batteries/vector/lancedb.cjs.map +1 -0
  159. package/batteries/vector/lancedb.mjs +222 -0
  160. package/batteries/vector/lancedb.mjs.map +1 -0
  161. package/batteries/vector/mariadb/index.d.ts +39 -0
  162. package/batteries/vector/mariadb.cjs +228 -0
  163. package/batteries/vector/mariadb.cjs.map +1 -0
  164. package/batteries/vector/mariadb.mjs +226 -0
  165. package/batteries/vector/mariadb.mjs.map +1 -0
  166. package/batteries/vector/meilisearch/index.d.ts +36 -0
  167. package/batteries/vector/meilisearch.cjs +242 -0
  168. package/batteries/vector/meilisearch.cjs.map +1 -0
  169. package/batteries/vector/meilisearch.mjs +240 -0
  170. package/batteries/vector/meilisearch.mjs.map +1 -0
  171. package/batteries/vector/migrate.cjs +54 -0
  172. package/batteries/vector/migrate.cjs.map +1 -0
  173. package/batteries/vector/migrate.d.ts +30 -0
  174. package/batteries/vector/migrate.mjs +52 -0
  175. package/batteries/vector/migrate.mjs.map +1 -0
  176. package/batteries/vector/milvus/index.d.ts +35 -0
  177. package/batteries/vector/milvus.cjs +357 -0
  178. package/batteries/vector/milvus.cjs.map +1 -0
  179. package/batteries/vector/milvus.mjs +354 -0
  180. package/batteries/vector/milvus.mjs.map +1 -0
  181. package/batteries/vector/mongodb/index.d.ts +46 -0
  182. package/batteries/vector/mongodb.cjs +270 -0
  183. package/batteries/vector/mongodb.cjs.map +1 -0
  184. package/batteries/vector/mongodb.mjs +268 -0
  185. package/batteries/vector/mongodb.mjs.map +1 -0
  186. package/batteries/vector/neo4j/index.d.ts +38 -0
  187. package/batteries/vector/neo4j.cjs +231 -0
  188. package/batteries/vector/neo4j.cjs.map +1 -0
  189. package/batteries/vector/neo4j.mjs +229 -0
  190. package/batteries/vector/neo4j.mjs.map +1 -0
  191. package/batteries/vector/opensearch/index.d.ts +46 -0
  192. package/batteries/vector/opensearch.cjs +316 -0
  193. package/batteries/vector/opensearch.cjs.map +1 -0
  194. package/batteries/vector/opensearch.mjs +313 -0
  195. package/batteries/vector/opensearch.mjs.map +1 -0
  196. package/batteries/vector/oracle23ai/index.d.ts +45 -0
  197. package/batteries/vector/oracle23ai.cjs +340 -0
  198. package/batteries/vector/oracle23ai.cjs.map +1 -0
  199. package/batteries/vector/oracle23ai.mjs +338 -0
  200. package/batteries/vector/oracle23ai.mjs.map +1 -0
  201. package/batteries/vector/orama/index.d.ts +23 -0
  202. package/batteries/vector/orama.cjs +272 -0
  203. package/batteries/vector/orama.cjs.map +1 -0
  204. package/batteries/vector/orama.mjs +270 -0
  205. package/batteries/vector/orama.mjs.map +1 -0
  206. package/batteries/vector/pgvector/index.d.ts +43 -0
  207. package/batteries/vector/pgvector.cjs +411 -0
  208. package/batteries/vector/pgvector.cjs.map +1 -0
  209. package/batteries/vector/pgvector.mjs +408 -0
  210. package/batteries/vector/pgvector.mjs.map +1 -0
  211. package/batteries/vector/pinecone/index.d.ts +38 -0
  212. package/batteries/vector/pinecone.cjs +415 -0
  213. package/batteries/vector/pinecone.cjs.map +1 -0
  214. package/batteries/vector/pinecone.mjs +412 -0
  215. package/batteries/vector/pinecone.mjs.map +1 -0
  216. package/batteries/vector/plan.cjs +2 -0
  217. package/batteries/vector/plan.d.ts +65 -0
  218. package/batteries/vector/plan.mjs +0 -0
  219. package/batteries/vector/qdrant/index.d.ts +34 -0
  220. package/batteries/vector/qdrant.cjs +286 -0
  221. package/batteries/vector/qdrant.cjs.map +1 -0
  222. package/batteries/vector/qdrant.mjs +284 -0
  223. package/batteries/vector/qdrant.mjs.map +1 -0
  224. package/batteries/vector/redis/index.d.ts +44 -0
  225. package/batteries/vector/redis.cjs +391 -0
  226. package/batteries/vector/redis.cjs.map +1 -0
  227. package/batteries/vector/redis.mjs +388 -0
  228. package/batteries/vector/redis.mjs.map +1 -0
  229. package/batteries/vector/retrievable.cjs +69 -0
  230. package/batteries/vector/retrievable.cjs.map +1 -0
  231. package/batteries/vector/retrievable.mjs +67 -0
  232. package/batteries/vector/retrievable.mjs.map +1 -0
  233. package/batteries/vector/retrievable_glue.d.ts +24 -0
  234. package/batteries/vector/s3vectors/index.d.ts +52 -0
  235. package/batteries/vector/s3vectors.cjs +438 -0
  236. package/batteries/vector/s3vectors.cjs.map +1 -0
  237. package/batteries/vector/s3vectors.mjs +436 -0
  238. package/batteries/vector/s3vectors.mjs.map +1 -0
  239. package/batteries/vector/schema.cjs +96 -0
  240. package/batteries/vector/schema.cjs.map +1 -0
  241. package/batteries/vector/schema.d.ts +40 -0
  242. package/batteries/vector/schema.mjs +93 -0
  243. package/batteries/vector/schema.mjs.map +1 -0
  244. package/batteries/vector/solr/index.d.ts +36 -0
  245. package/batteries/vector/solr.cjs +230 -0
  246. package/batteries/vector/solr.cjs.map +1 -0
  247. package/batteries/vector/solr.mjs +228 -0
  248. package/batteries/vector/solr.mjs.map +1 -0
  249. package/batteries/vector/sqlite_vec/index.d.ts +30 -0
  250. package/batteries/vector/sqlite_vec.cjs +318 -0
  251. package/batteries/vector/sqlite_vec.cjs.map +1 -0
  252. package/batteries/vector/sqlite_vec.mjs +316 -0
  253. package/batteries/vector/sqlite_vec.mjs.map +1 -0
  254. package/batteries/vector/surrealdb/index.d.ts +37 -0
  255. package/batteries/vector/surrealdb.cjs +230 -0
  256. package/batteries/vector/surrealdb.cjs.map +1 -0
  257. package/batteries/vector/surrealdb.mjs +228 -0
  258. package/batteries/vector/surrealdb.mjs.map +1 -0
  259. package/batteries/vector/types.cjs +2 -0
  260. package/batteries/vector/types.d.ts +100 -0
  261. package/batteries/vector/types.mjs +0 -0
  262. package/batteries/vector/typesense/index.d.ts +38 -0
  263. package/batteries/vector/typesense.cjs +272 -0
  264. package/batteries/vector/typesense.cjs.map +1 -0
  265. package/batteries/vector/typesense.mjs +270 -0
  266. package/batteries/vector/typesense.mjs.map +1 -0
  267. package/batteries/vector/validation.cjs +90 -0
  268. package/batteries/vector/validation.cjs.map +1 -0
  269. package/batteries/vector/validation.d.ts +18 -0
  270. package/batteries/vector/validation.mjs +83 -0
  271. package/batteries/vector/validation.mjs.map +1 -0
  272. package/batteries/vector/vector_store_constructor.cjs +56 -0
  273. package/batteries/vector/vector_store_constructor.cjs.map +1 -0
  274. package/batteries/vector/vector_store_constructor.d.ts +30 -0
  275. package/batteries/vector/vector_store_constructor.mjs +53 -0
  276. package/batteries/vector/vector_store_constructor.mjs.map +1 -0
  277. package/batteries/vector/vespa/index.d.ts +39 -0
  278. package/batteries/vector/vespa.cjs +423 -0
  279. package/batteries/vector/vespa.cjs.map +1 -0
  280. package/batteries/vector/vespa.mjs +421 -0
  281. package/batteries/vector/vespa.mjs.map +1 -0
  282. package/batteries/vector/weaviate/index.d.ts +57 -0
  283. package/batteries/vector/weaviate.cjs +325 -0
  284. package/batteries/vector/weaviate.cjs.map +1 -0
  285. package/batteries/vector/weaviate.mjs +322 -0
  286. package/batteries/vector/weaviate.mjs.map +1 -0
  287. package/batteries/vector.cjs +63 -0
  288. package/batteries/vector.mjs +14 -0
  289. package/batteries.cjs +62 -0
  290. package/batteries.mjs +15 -1
  291. package/{chunk-kRvK8_k2.mjs → chunk-Bpcn9VDT.mjs} +5 -1
  292. package/{common-lMrnzoyn.mjs → common-BT0nfCi9.mjs} +8 -8
  293. package/{common-lMrnzoyn.mjs.map → common-BT0nfCi9.mjs.map} +1 -1
  294. package/{common-D_e5zYsG.js → common-Cj8TaQ9U.js} +8 -8
  295. package/{common-D_e5zYsG.js.map → common-Cj8TaQ9U.js.map} +1 -1
  296. package/common.cjs +7 -7
  297. package/common.mjs +7 -7
  298. package/{dispatch_runner-CpuyATj1.js → dispatch_runner-BHBNupqp.js} +2 -2
  299. package/dispatch_runner-BHBNupqp.js.map +1 -0
  300. package/{dispatch_runner-CDF3X0nv.mjs → dispatch_runner-DPcS7Y_M.mjs} +2 -2
  301. package/dispatch_runner-DPcS7Y_M.mjs.map +1 -0
  302. package/dispatch_runner.cjs +1 -1
  303. package/dispatch_runner.mjs +1 -1
  304. package/forge.cjs +4 -4
  305. package/forge.mjs +4 -4
  306. package/guards.cjs +8 -8
  307. package/guards.mjs +8 -8
  308. package/index.cjs +12 -12
  309. package/index.mjs +12 -12
  310. package/lib/classes/tool_registry.d.ts +70 -4
  311. package/mcp/adk-docs-corpus.json +1 -1
  312. package/package.json +424 -88
  313. package/skills/adk-assembly/SKILL.md +2 -2
  314. package/{spooled_artifact-B8gIIn9h.js → spooled_artifact-BTq6Nzfy.js} +4 -4
  315. package/spooled_artifact-BTq6Nzfy.js.map +1 -0
  316. package/{spooled_artifact-CWoKUDEm.mjs → spooled_artifact-CHoZgWwI.mjs} +4 -4
  317. package/spooled_artifact-CHoZgWwI.mjs.map +1 -0
  318. package/spooled_artifact.cjs +2 -2
  319. package/spooled_artifact.mjs +2 -2
  320. package/{spooled_markdown_artifact-DQX0RCdI.js → spooled_markdown_artifact-CALSDxIx.js} +3 -3
  321. package/{spooled_markdown_artifact-DQX0RCdI.js.map → spooled_markdown_artifact-CALSDxIx.js.map} +1 -1
  322. package/{spooled_markdown_artifact-CNle4jXN.mjs → spooled_markdown_artifact-Ci5UL7l4.mjs} +3 -3
  323. package/{spooled_markdown_artifact-CNle4jXN.mjs.map → spooled_markdown_artifact-Ci5UL7l4.mjs.map} +1 -1
  324. package/src/types/evaluatex.d.ts +31 -0
  325. package/{thought-BD6AkkOr.js → thought-BbwhJ1wb.js} +4 -4
  326. package/thought-BbwhJ1wb.js.map +1 -0
  327. package/{thought-B_P8LiB6.mjs → thought-D34QQZZ9.mjs} +4 -4
  328. package/thought-D34QQZZ9.mjs.map +1 -0
  329. package/{tool-CRZSUcdP.mjs → tool-CMhaDRNd.mjs} +3 -3
  330. package/tool-CMhaDRNd.mjs.map +1 -0
  331. package/{tool-CX9vNHAw.js → tool-CVyZkFC7.js} +3 -3
  332. package/tool-CVyZkFC7.js.map +1 -0
  333. package/{tool_call-BUeMuCc6.mjs → tool_call-CV5qVNlb.mjs} +3 -3
  334. package/{tool_call-BUeMuCc6.mjs.map → tool_call-CV5qVNlb.mjs.map} +1 -1
  335. package/{tool_call--7ti-frB.js → tool_call-Db68hB7y.js} +3 -3
  336. package/{tool_call--7ti-frB.js.map → tool_call-Db68hB7y.js.map} +1 -1
  337. package/{tool_registry-BGHg6KTq.mjs → tool_registry-D1pSSlsd.mjs} +109 -22
  338. package/tool_registry-D1pSSlsd.mjs.map +1 -0
  339. package/{tool_registry-CtCQ4Xoz.js → tool_registry-DYUYqXvo.js} +109 -22
  340. package/tool_registry-DYUYqXvo.js.map +1 -0
  341. package/{turn_runner-BJTtAORU.js → turn_runner-DqWHNP80.js} +5 -5
  342. package/turn_runner-DqWHNP80.js.map +1 -0
  343. package/{turn_runner-C02LZHjt.mjs → turn_runner-fg1Wc3dK.mjs} +5 -5
  344. package/turn_runner-fg1Wc3dK.mjs.map +1 -0
  345. package/turn_runner.cjs +1 -1
  346. package/turn_runner.mjs +1 -1
  347. package/dispatch_runner-CDF3X0nv.mjs.map +0 -1
  348. package/dispatch_runner-CpuyATj1.js.map +0 -1
  349. package/spooled_artifact-B8gIIn9h.js.map +0 -1
  350. package/spooled_artifact-CWoKUDEm.mjs.map +0 -1
  351. package/thought-BD6AkkOr.js.map +0 -1
  352. package/thought-B_P8LiB6.mjs.map +0 -1
  353. package/tool-CRZSUcdP.mjs.map +0 -1
  354. package/tool-CX9vNHAw.js.map +0 -1
  355. package/tool_registry-BGHg6KTq.mjs.map +0 -1
  356. package/tool_registry-CtCQ4Xoz.js.map +0 -1
  357. package/turn_runner-BJTtAORU.js.map +0 -1
  358. package/turn_runner-C02LZHjt.mjs.map +0 -1
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Knex-style chainable query builder for the vector storage battery.
3
+ *
4
+ * @module @nhtio/adk/batteries/vector/builder
5
+ */
6
+ import type { VectorRecord, VectorMatch, VectorConsistency } from "./types";
7
+ import type { SearchPlan, UpsertPlan, DeletePlan } from "./plan";
8
+ import type { VectorFilter, FilterOperator } from "./filters";
9
+ export interface PlanSink {
10
+ executeSearch(plan: SearchPlan): Promise<VectorMatch[]>;
11
+ executeUpsert(plan: UpsertPlan): Promise<void>;
12
+ executeDelete(plan: DeletePlan): Promise<void>;
13
+ }
14
+ export type SelectArg = string | [
15
+ string,
16
+ Record<string, unknown>
17
+ ] | Record<string, Record<string, unknown> | true>;
18
+ /**
19
+ * A callback that receives a fresh filter-only builder, used to express a parenthesized group of
20
+ * conditions — `A AND (B OR C)`, `NOT (…)`, and arbitrary nesting. The callback mutates the builder
21
+ * in place (knex-style); its accumulated conditions become a single nested `VectorFilter`.
22
+ *
23
+ * @see {@link FilterBuilder.where}
24
+ */
25
+ export type FilterCallback = (qb: FilterBuilder) => void;
26
+ /**
27
+ * The where-clause surface of the query builder, factored out so a grouping callback can be handed
28
+ * a builder that only exposes filter methods (not `near*`/`select`/`limit` or the terminals).
29
+ *
30
+ * Chained `.where()` ANDs; the first `.orWhere()` snapshots the accumulated AND-list into the first
31
+ * branch of an OR (knex semantics). Any of the where-methods also accepts a {@link FilterCallback}
32
+ * to open a nested group, letting AND and OR mix to any depth.
33
+ */
34
+ declare class FilterBuilder {
35
+ #private;
36
+ protected andConditions: VectorFilter[];
37
+ protected orBranches: VectorFilter[][];
38
+ /** Build a nested group by running `cb` against a fresh {@link FilterBuilder}. */
39
+ protected runGroup(cb: FilterCallback): VectorFilter | undefined;
40
+ where(cb: FilterCallback): this;
41
+ where(a: string, b?: unknown, c?: unknown): this;
42
+ where(obj: Record<string, unknown>): this;
43
+ andWhere(cb: FilterCallback): this;
44
+ andWhere(a: string, b?: unknown, c?: unknown): this;
45
+ andWhere(obj: Record<string, unknown>): this;
46
+ orWhere(cb: FilterCallback): this;
47
+ orWhere(field: string, value: unknown): this;
48
+ orWhere(field: string, op: FilterOperator, value: unknown): this;
49
+ whereNot(cb: FilterCallback): this;
50
+ whereNot(field: string, value: unknown): this;
51
+ orWhereNot(cb: FilterCallback): this;
52
+ orWhereNot(field: string, value: unknown): this;
53
+ whereIn(field: string, values: unknown[]): this;
54
+ whereNotIn(field: string, values: unknown[]): this;
55
+ whereNull(field: string): this;
56
+ whereExists(field: string): this;
57
+ whereRaw(sql: string, bindings?: unknown[]): this;
58
+ whereRaw(rawObj: {
59
+ $dialect: string;
60
+ $raw: unknown;
61
+ $bindings?: unknown[];
62
+ }): this;
63
+ protected buildFilter(): VectorFilter | undefined;
64
+ protected extractIdsFromFilter(): string[];
65
+ }
66
+ declare class VectorQueryBuilder extends FilterBuilder implements PromiseLike<VectorMatch[]> {
67
+ #private;
68
+ constructor(sink: PlanSink, collection: string, defaultTopK: number);
69
+ nearVector(vector: number[]): this;
70
+ nearText(text: string): this;
71
+ nearId(id: string): this;
72
+ select(...args: SelectArg[]): this;
73
+ limit(n: number): this;
74
+ offset(n: number): this;
75
+ /**
76
+ * Per-operation read-after-write override for the terminal `.upsert()` / `.delete()`.
77
+ * Universal across adapters: strongly-consistent backends ignore it (no-op), so a chain
78
+ * written for an eventually-consistent backend keeps working verbatim when the adapter is
79
+ * swapped. Precedence: this > the store's `consistency` option > the adapter's declared
80
+ * `capabilities.consistency.default`. See {@link VectorConsistency}.
81
+ */
82
+ consistency(mode: VectorConsistency): this;
83
+ then<TR1 = VectorMatch[], TR2 = never>(onfulfilled?: ((value: VectorMatch[]) => TR1 | PromiseLike<TR1>) | null, onrejected?: ((reason: unknown) => TR2 | PromiseLike<TR2>) | null): PromiseLike<TR1 | TR2>;
84
+ upsert(records: VectorRecord[]): Promise<void>;
85
+ delete(): Promise<void>;
86
+ }
87
+ export { VectorQueryBuilder, FilterBuilder };
@@ -0,0 +1,294 @@
1
+ import { isFilterCondition, isRawFilter } from "./filters.mjs";
2
+ import { E_VECTOR_STORE_PROJECTION_REQUIRED, E_VECTOR_STORE_QUERY_CONFLICT, E_VECTOR_STORE_RAW_BINDING_MISMATCH, E_VECTOR_STORE_UNSUPPORTED_FILTER_OPERATOR } from "./exceptions.mjs";
3
+ //#region src/batteries/vector/builder.ts
4
+ /**
5
+ * Knex-style chainable query builder for the vector storage battery.
6
+ *
7
+ * @module @nhtio/adk/batteries/vector/builder
8
+ */
9
+ var OP_ALIASES = {
10
+ "=": "eq",
11
+ "==": "eq",
12
+ "===": "eq",
13
+ "!=": "ne",
14
+ "<>": "ne",
15
+ "!==": "ne",
16
+ ">": "gt",
17
+ ">=": "gte",
18
+ "<": "lt",
19
+ "<=": "lte",
20
+ "eq": "eq",
21
+ "ne": "ne",
22
+ "gt": "gt",
23
+ "gte": "gte",
24
+ "lt": "lt",
25
+ "lte": "lte",
26
+ "in": "in",
27
+ "nin": "nin",
28
+ "exists": "exists",
29
+ "contains": "contains"
30
+ };
31
+ var normalizeOp = (op) => {
32
+ const norm = OP_ALIASES[op];
33
+ if (!norm) throw new E_VECTOR_STORE_UNSUPPORTED_FILTER_OPERATOR(["builder", op]);
34
+ return norm;
35
+ };
36
+ /**
37
+ * The where-clause surface of the query builder, factored out so a grouping callback can be handed
38
+ * a builder that only exposes filter methods (not `near*`/`select`/`limit` or the terminals).
39
+ *
40
+ * Chained `.where()` ANDs; the first `.orWhere()` snapshots the accumulated AND-list into the first
41
+ * branch of an OR (knex semantics). Any of the where-methods also accepts a {@link FilterCallback}
42
+ * to open a nested group, letting AND and OR mix to any depth.
43
+ */
44
+ var FilterBuilder = class FilterBuilder {
45
+ andConditions = [];
46
+ orBranches = [];
47
+ /** Build a nested group by running `cb` against a fresh {@link FilterBuilder}. */
48
+ runGroup(cb) {
49
+ const fb = new FilterBuilder();
50
+ cb(fb);
51
+ return fb.buildFilter();
52
+ }
53
+ where(a, b, c) {
54
+ if (typeof a === "function") {
55
+ const group = this.runGroup(a);
56
+ if (group !== void 0) this.andConditions.push(group);
57
+ return this;
58
+ }
59
+ if (typeof a === "object" && !Array.isArray(a)) {
60
+ for (const key of Object.keys(a)) this.andConditions.push({
61
+ field: key,
62
+ op: "eq",
63
+ value: a[key]
64
+ });
65
+ return this;
66
+ }
67
+ const field = a;
68
+ const value = b !== void 0 ? c !== void 0 ? c : b : b;
69
+ const op = c !== void 0 ? normalizeOp(b) : "eq";
70
+ this.andConditions.push({
71
+ field,
72
+ op,
73
+ value
74
+ });
75
+ return this;
76
+ }
77
+ andWhere(a, b, c) {
78
+ return this.where(a, b, c);
79
+ }
80
+ /**
81
+ * Open a new OR branch holding a single filter. The accumulated AND-list is contributed as the
82
+ * first OR-group by {@link buildFilter}, so each branch carries only its own condition(s) — that
83
+ * is what makes `where(A).where(B).orWhere(C)` resolve to `(A AND B) OR C`.
84
+ */
85
+ #pushOrBranch(filter) {
86
+ this.orBranches.push([filter]);
87
+ }
88
+ orWhere(field, b, c) {
89
+ if (typeof field === "function") {
90
+ const group = this.runGroup(field);
91
+ if (group !== void 0) this.#pushOrBranch(group);
92
+ return this;
93
+ }
94
+ const value = c !== void 0 ? c : b;
95
+ const op = c !== void 0 ? normalizeOp(b) : "eq";
96
+ this.#pushOrBranch({
97
+ field,
98
+ op,
99
+ value
100
+ });
101
+ return this;
102
+ }
103
+ whereNot(field, value) {
104
+ if (typeof field === "function") {
105
+ const group = this.runGroup(field);
106
+ if (group !== void 0) this.andConditions.push({ not: group });
107
+ return this;
108
+ }
109
+ return this.where(field, "ne", value);
110
+ }
111
+ orWhereNot(field, value) {
112
+ if (typeof field === "function") {
113
+ const group = this.runGroup(field);
114
+ if (group !== void 0) this.#pushOrBranch({ not: group });
115
+ return this;
116
+ }
117
+ return this.orWhere(field, "ne", value);
118
+ }
119
+ whereIn(field, values) {
120
+ return this.where(field, "in", values);
121
+ }
122
+ whereNotIn(field, values) {
123
+ return this.where(field, "nin", values);
124
+ }
125
+ whereNull(field) {
126
+ return this.where(field, "exists", false);
127
+ }
128
+ whereExists(field) {
129
+ return this.where(field, "exists", true);
130
+ }
131
+ whereRaw(sqlOrObj, bindings) {
132
+ if (typeof sqlOrObj === "object") this.andConditions.push({
133
+ $dialect: sqlOrObj.$dialect,
134
+ $raw: sqlOrObj.$raw,
135
+ $bindings: sqlOrObj.$bindings ?? []
136
+ });
137
+ else this.andConditions.push({
138
+ $dialect: "sql",
139
+ $raw: sqlOrObj,
140
+ $bindings: bindings ?? []
141
+ });
142
+ return this;
143
+ }
144
+ buildFilter() {
145
+ if (this.andConditions.length === 0 && this.orBranches.length === 0) return;
146
+ if (this.orBranches.length > 0) {
147
+ const orGroups = [];
148
+ if (this.andConditions.length > 0) orGroups.push(this.andConditions);
149
+ for (const branch of this.orBranches) if (branch.length > 0) orGroups.push(branch);
150
+ if (orGroups.length === 1) return { and: orGroups[0] };
151
+ return { or: orGroups.map((conds) => ({ and: conds })) };
152
+ }
153
+ return { and: this.andConditions };
154
+ }
155
+ extractIdsFromFilter() {
156
+ const ids = [];
157
+ const only = this.andConditions.length === 1 ? this.andConditions[0] : void 0;
158
+ if (only && isFilterCondition(only) && only.field === "id" && only.op === "in" && Array.isArray(only.value)) ids.push(...only.value);
159
+ return ids;
160
+ }
161
+ };
162
+ var VectorQueryBuilder = class extends FilterBuilder {
163
+ #sink;
164
+ #collection;
165
+ #near;
166
+ #projection = {
167
+ id: false,
168
+ vector: false,
169
+ document: false,
170
+ metadata: false
171
+ };
172
+ #topK;
173
+ #offset = 0;
174
+ #selectCalled = false;
175
+ #consistency;
176
+ constructor(sink, collection, defaultTopK) {
177
+ super();
178
+ this.#sink = sink;
179
+ this.#collection = collection;
180
+ this.#topK = defaultTopK;
181
+ }
182
+ nearVector(vector) {
183
+ if (this.#near !== void 0) throw new E_VECTOR_STORE_QUERY_CONFLICT(["a near* clause was already set"]);
184
+ this.#near = { vector };
185
+ return this;
186
+ }
187
+ nearText(text) {
188
+ if (this.#near !== void 0) throw new E_VECTOR_STORE_QUERY_CONFLICT(["a near* clause was already set"]);
189
+ this.#near = { serverText: text };
190
+ return this;
191
+ }
192
+ nearId(id) {
193
+ if (this.#near !== void 0) throw new E_VECTOR_STORE_QUERY_CONFLICT(["a near* clause was already set"]);
194
+ this.#near = { id };
195
+ return this;
196
+ }
197
+ select(...args) {
198
+ this.#selectCalled = true;
199
+ for (const arg of args) if (typeof arg === "string") {
200
+ if (arg === "*") this.#projection = {
201
+ id: true,
202
+ vector: {},
203
+ document: {},
204
+ metadata: {}
205
+ };
206
+ else if (arg === "id") this.#projection.id = true;
207
+ else if (arg === "vector") this.#projection.vector = {};
208
+ else if (arg === "document") this.#projection.document = {};
209
+ else if (arg === "metadata") this.#projection.metadata = {};
210
+ } else if (Array.isArray(arg)) {
211
+ const [field, config] = arg;
212
+ if (field === "vector") this.#projection.vector = config;
213
+ else if (field === "document") this.#projection.document = config;
214
+ else if (field === "metadata") this.#projection.metadata = config;
215
+ else if (field === "id") this.#projection.id = true;
216
+ } else if (typeof arg === "object") {
217
+ for (const key of Object.keys(arg)) if (key === "vector") this.#projection.vector = arg[key];
218
+ else if (key === "document") this.#projection.document = arg[key];
219
+ else if (key === "metadata") this.#projection.metadata = arg[key];
220
+ else if (key === "id") this.#projection.id = true;
221
+ }
222
+ return this;
223
+ }
224
+ limit(n) {
225
+ this.#topK = n;
226
+ return this;
227
+ }
228
+ offset(n) {
229
+ this.#offset = n;
230
+ return this;
231
+ }
232
+ /**
233
+ * Per-operation read-after-write override for the terminal `.upsert()` / `.delete()`.
234
+ * Universal across adapters: strongly-consistent backends ignore it (no-op), so a chain
235
+ * written for an eventually-consistent backend keeps working verbatim when the adapter is
236
+ * swapped. Precedence: this > the store's `consistency` option > the adapter's declared
237
+ * `capabilities.consistency.default`. See {@link VectorConsistency}.
238
+ */
239
+ consistency(mode) {
240
+ this.#consistency = mode;
241
+ return this;
242
+ }
243
+ then(onfulfilled, onrejected) {
244
+ return this.#run().then(onfulfilled, onrejected);
245
+ }
246
+ async #run() {
247
+ if (!this.#selectCalled) throw new E_VECTOR_STORE_PROJECTION_REQUIRED();
248
+ const filter = this.buildFilter();
249
+ const plan = {
250
+ collection: this.#collection,
251
+ near: this.#near,
252
+ filter,
253
+ topK: this.#topK,
254
+ offset: this.#offset,
255
+ projection: this.#projection
256
+ };
257
+ this.#validateRawFilters(plan.filter);
258
+ return await this.#sink.executeSearch(plan);
259
+ }
260
+ async upsert(records) {
261
+ const plan = {
262
+ collection: this.#collection,
263
+ records,
264
+ consistency: this.#consistency
265
+ };
266
+ await this.#sink.executeUpsert(plan);
267
+ }
268
+ async delete() {
269
+ const ids = this.extractIdsFromFilter();
270
+ const filter = this.buildFilter();
271
+ const plan = {
272
+ collection: this.#collection,
273
+ ids: ids.length > 0 ? ids : void 0,
274
+ filter: filter && Object.keys(filter).length > 0 ? filter : void 0,
275
+ consistency: this.#consistency
276
+ };
277
+ await this.#sink.executeDelete(plan);
278
+ }
279
+ #validateRawFilters(filter) {
280
+ if (!filter) return;
281
+ if (isRawFilter(filter)) {
282
+ const placeholders = (filter.$raw.match(/\?/g) || []).length;
283
+ if (placeholders !== filter.$bindings?.length) throw new E_VECTOR_STORE_RAW_BINDING_MISMATCH([placeholders, filter.$bindings?.length ?? 0]);
284
+ return;
285
+ }
286
+ if ("and" in filter && filter.and) for (const f of filter.and) this.#validateRawFilters(f);
287
+ if ("or" in filter && filter.or) for (const f of filter.or) this.#validateRawFilters(f);
288
+ if ("not" in filter && filter.not) this.#validateRawFilters(filter.not);
289
+ }
290
+ };
291
+ //#endregion
292
+ export { FilterBuilder, VectorQueryBuilder };
293
+
294
+ //# sourceMappingURL=builder.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder.mjs","names":["#pushOrBranch","#sink","#collection","#topK","#near","#selectCalled","#projection","#offset","#consistency","#run","#validateRawFilters"],"sources":["../../../src/batteries/vector/builder.ts"],"sourcesContent":["/**\n * Knex-style chainable query builder for the vector storage battery.\n *\n * @module @nhtio/adk/batteries/vector/builder\n */\n\nimport { isRawFilter, isFilterCondition } from './filters'\nimport {\n E_VECTOR_STORE_QUERY_CONFLICT,\n E_VECTOR_STORE_PROJECTION_REQUIRED,\n E_VECTOR_STORE_RAW_BINDING_MISMATCH,\n E_VECTOR_STORE_UNSUPPORTED_FILTER_OPERATOR,\n} from './exceptions'\nimport type { VectorRecord, VectorMatch, VectorConsistency } from './types'\nimport type { SearchPlan, UpsertPlan, DeletePlan, Projection } from './plan'\nimport type { VectorFilter, FilterCondition, FilterOperator } from './filters'\n\nconst OP_ALIASES: Record<string, FilterOperator> = {\n '=': 'eq',\n '==': 'eq',\n '===': 'eq',\n '!=': 'ne',\n '<>': 'ne',\n '!==': 'ne',\n '>': 'gt',\n '>=': 'gte',\n '<': 'lt',\n '<=': 'lte',\n 'eq': 'eq',\n 'ne': 'ne',\n 'gt': 'gt',\n 'gte': 'gte',\n 'lt': 'lt',\n 'lte': 'lte',\n 'in': 'in',\n 'nin': 'nin',\n 'exists': 'exists',\n 'contains': 'contains',\n}\nconst normalizeOp = (op: string): FilterOperator => {\n const norm = OP_ALIASES[op]\n if (!norm) throw new E_VECTOR_STORE_UNSUPPORTED_FILTER_OPERATOR(['builder', op])\n return norm\n}\n\nexport interface PlanSink {\n executeSearch(plan: SearchPlan): Promise<VectorMatch[]>\n executeUpsert(plan: UpsertPlan): Promise<void>\n executeDelete(plan: DeletePlan): Promise<void>\n}\n\nexport type SelectArg =\n | string\n | [string, Record<string, unknown>]\n | Record<string, Record<string, unknown> | true>\n\n/**\n * A callback that receives a fresh filter-only builder, used to express a parenthesized group of\n * conditions — `A AND (B OR C)`, `NOT (…)`, and arbitrary nesting. The callback mutates the builder\n * in place (knex-style); its accumulated conditions become a single nested `VectorFilter`.\n *\n * @see {@link FilterBuilder.where}\n */\nexport type FilterCallback = (qb: FilterBuilder) => void\n\n/**\n * The where-clause surface of the query builder, factored out so a grouping callback can be handed\n * a builder that only exposes filter methods (not `near*`/`select`/`limit` or the terminals).\n *\n * Chained `.where()` ANDs; the first `.orWhere()` snapshots the accumulated AND-list into the first\n * branch of an OR (knex semantics). Any of the where-methods also accepts a {@link FilterCallback}\n * to open a nested group, letting AND and OR mix to any depth.\n */\nclass FilterBuilder {\n protected andConditions: VectorFilter[] = []\n protected orBranches: VectorFilter[][] = []\n\n /** Build a nested group by running `cb` against a fresh {@link FilterBuilder}. */\n protected runGroup(cb: FilterCallback): VectorFilter | undefined {\n const fb = new FilterBuilder()\n cb(fb)\n return fb.buildFilter()\n }\n\n where(cb: FilterCallback): this\n where(a: string, b?: unknown, c?: unknown): this\n where(obj: Record<string, unknown>): this\n where(a: string | Record<string, unknown> | FilterCallback, b?: unknown, c?: unknown): this {\n if (typeof a === 'function') {\n const group = this.runGroup(a)\n if (group !== undefined) {\n this.andConditions.push(group)\n }\n return this\n }\n if (typeof a === 'object' && !Array.isArray(a)) {\n for (const key of Object.keys(a)) {\n this.andConditions.push({\n field: key,\n op: 'eq',\n value: a[key] as FilterCondition['value'],\n })\n }\n return this\n }\n const field = a as string\n const value = b !== undefined ? (c !== undefined ? c : b) : b\n const op = c !== undefined ? normalizeOp(b as string) : 'eq'\n this.andConditions.push({ field, op, value: value as FilterCondition['value'] })\n return this\n }\n\n andWhere(cb: FilterCallback): this\n andWhere(a: string, b?: unknown, c?: unknown): this\n andWhere(obj: Record<string, unknown>): this\n andWhere(a: string | Record<string, unknown> | FilterCallback, b?: unknown, c?: unknown): this {\n return this.where(a as any, b, c)\n }\n\n /**\n * Open a new OR branch holding a single filter. The accumulated AND-list is contributed as the\n * first OR-group by {@link buildFilter}, so each branch carries only its own condition(s) — that\n * is what makes `where(A).where(B).orWhere(C)` resolve to `(A AND B) OR C`.\n */\n #pushOrBranch(filter: VectorFilter): void {\n this.orBranches.push([filter])\n }\n\n orWhere(cb: FilterCallback): this\n orWhere(field: string, value: unknown): this\n orWhere(field: string, op: FilterOperator, value: unknown): this\n orWhere(field: string | FilterCallback, b?: unknown, c?: unknown): this {\n if (typeof field === 'function') {\n const group = this.runGroup(field)\n if (group !== undefined) {\n this.#pushOrBranch(group)\n }\n return this\n }\n const value = c !== undefined ? c : b\n const op = c !== undefined ? normalizeOp(b as string) : 'eq'\n this.#pushOrBranch({ field, op, value: value as FilterCondition['value'] })\n return this\n }\n\n whereNot(cb: FilterCallback): this\n whereNot(field: string, value: unknown): this\n whereNot(field: string | FilterCallback, value?: unknown): this {\n if (typeof field === 'function') {\n const group = this.runGroup(field)\n if (group !== undefined) {\n this.andConditions.push({ not: group })\n }\n return this\n }\n return this.where(field, 'ne', value as FilterCondition['value'])\n }\n\n orWhereNot(cb: FilterCallback): this\n orWhereNot(field: string, value: unknown): this\n orWhereNot(field: string | FilterCallback, value?: unknown): this {\n if (typeof field === 'function') {\n const group = this.runGroup(field)\n if (group !== undefined) {\n this.#pushOrBranch({ not: group })\n }\n return this\n }\n return this.orWhere(field, 'ne', value)\n }\n\n whereIn(field: string, values: unknown[]): this {\n return this.where(field, 'in', values as FilterCondition['value'])\n }\n\n whereNotIn(field: string, values: unknown[]): this {\n return this.where(field, 'nin', values as FilterCondition['value'])\n }\n\n whereNull(field: string): this {\n return this.where(field, 'exists', false as FilterCondition['value'])\n }\n\n whereExists(field: string): this {\n return this.where(field, 'exists', true as FilterCondition['value'])\n }\n\n whereRaw(sql: string, bindings?: unknown[]): this\n whereRaw(rawObj: { $dialect: string; $raw: unknown; $bindings?: unknown[] }): this\n whereRaw(\n sqlOrObj: string | { $dialect: string; $raw: unknown; $bindings?: unknown[] },\n bindings?: unknown[]\n ): this {\n if (typeof sqlOrObj === 'object') {\n this.andConditions.push({\n $dialect: sqlOrObj.$dialect,\n $raw: sqlOrObj.$raw,\n $bindings: sqlOrObj.$bindings ?? [],\n })\n } else {\n this.andConditions.push({ $dialect: 'sql', $raw: sqlOrObj, $bindings: bindings ?? [] })\n }\n return this\n }\n\n protected buildFilter(): VectorFilter | undefined {\n if (this.andConditions.length === 0 && this.orBranches.length === 0) {\n return undefined\n }\n\n if (this.orBranches.length > 0) {\n const orGroups: VectorFilter[][] = []\n if (this.andConditions.length > 0) {\n orGroups.push(this.andConditions)\n }\n for (const branch of this.orBranches) {\n if (branch.length > 0) {\n orGroups.push(branch)\n }\n }\n if (orGroups.length === 1) {\n return { and: orGroups[0] }\n }\n return { or: orGroups.map((conds) => ({ and: conds })) }\n }\n\n return { and: this.andConditions }\n }\n\n protected extractIdsFromFilter(): string[] {\n const ids: string[] = []\n const only = this.andConditions.length === 1 ? this.andConditions[0] : undefined\n if (\n only &&\n isFilterCondition(only) &&\n only.field === 'id' &&\n only.op === 'in' &&\n Array.isArray(only.value)\n ) {\n ids.push(...(only.value as string[]))\n }\n return ids\n }\n}\n\nclass VectorQueryBuilder extends FilterBuilder implements PromiseLike<VectorMatch[]> {\n #sink: PlanSink\n #collection: string\n #near: { vector: number[] } | { serverText: string } | { id: string } | undefined\n #projection: Projection = { id: false, vector: false, document: false, metadata: false }\n #topK: number\n #offset: number = 0\n #selectCalled: boolean = false\n #consistency: VectorConsistency | undefined\n\n constructor(sink: PlanSink, collection: string, defaultTopK: number) {\n super()\n this.#sink = sink\n this.#collection = collection\n this.#topK = defaultTopK\n }\n\n nearVector(vector: number[]): this {\n if (this.#near !== undefined) {\n throw new E_VECTOR_STORE_QUERY_CONFLICT(['a near* clause was already set'])\n }\n this.#near = { vector }\n return this\n }\n\n nearText(text: string): this {\n if (this.#near !== undefined) {\n throw new E_VECTOR_STORE_QUERY_CONFLICT(['a near* clause was already set'])\n }\n this.#near = { serverText: text }\n return this\n }\n\n nearId(id: string): this {\n if (this.#near !== undefined) {\n throw new E_VECTOR_STORE_QUERY_CONFLICT(['a near* clause was already set'])\n }\n this.#near = { id }\n return this\n }\n\n select(...args: SelectArg[]): this {\n this.#selectCalled = true\n for (const arg of args) {\n if (typeof arg === 'string') {\n if (arg === '*') {\n this.#projection = { id: true, vector: {}, document: {}, metadata: {} }\n } else {\n if (arg === 'id') {\n this.#projection.id = true\n } else if (arg === 'vector') {\n this.#projection.vector = {}\n } else if (arg === 'document') {\n this.#projection.document = {}\n } else if (arg === 'metadata') {\n this.#projection.metadata = {}\n }\n }\n } else if (Array.isArray(arg)) {\n const [field, config] = arg\n if (field === 'vector') {\n this.#projection.vector = config as { name?: string }\n } else if (field === 'document') {\n this.#projection.document = config as { field?: string }\n } else if (field === 'metadata') {\n this.#projection.metadata = config as { fields?: string[] }\n } else if (field === 'id') {\n this.#projection.id = true\n }\n } else if (typeof arg === 'object') {\n for (const key of Object.keys(arg)) {\n if (key === 'vector') {\n this.#projection.vector = arg[key] as { name?: string }\n } else if (key === 'document') {\n this.#projection.document = arg[key] as { field?: string }\n } else if (key === 'metadata') {\n this.#projection.metadata = arg[key] as { fields?: string[] }\n } else if (key === 'id') {\n this.#projection.id = true\n }\n }\n }\n }\n return this\n }\n\n limit(n: number): this {\n this.#topK = n\n return this\n }\n\n offset(n: number): this {\n this.#offset = n\n return this\n }\n\n /**\n * Per-operation read-after-write override for the terminal `.upsert()` / `.delete()`.\n * Universal across adapters: strongly-consistent backends ignore it (no-op), so a chain\n * written for an eventually-consistent backend keeps working verbatim when the adapter is\n * swapped. Precedence: this > the store's `consistency` option > the adapter's declared\n * `capabilities.consistency.default`. See {@link VectorConsistency}.\n */\n consistency(mode: VectorConsistency): this {\n this.#consistency = mode\n return this\n }\n\n then<TR1 = VectorMatch[], TR2 = never>(\n onfulfilled?: ((value: VectorMatch[]) => TR1 | PromiseLike<TR1>) | null,\n onrejected?: ((reason: unknown) => TR2 | PromiseLike<TR2>) | null\n ): PromiseLike<TR1 | TR2> {\n return this.#run().then(onfulfilled as any, onrejected as any)\n }\n\n async #run(): Promise<VectorMatch[]> {\n if (!this.#selectCalled) {\n throw new E_VECTOR_STORE_PROJECTION_REQUIRED()\n }\n\n const filter = this.buildFilter()\n\n const plan: SearchPlan = {\n collection: this.#collection,\n near: this.#near,\n filter,\n topK: this.#topK,\n offset: this.#offset,\n projection: this.#projection,\n }\n\n this.#validateRawFilters(plan.filter)\n\n return await this.#sink.executeSearch(plan)\n }\n\n async upsert(records: VectorRecord[]): Promise<void> {\n const plan: UpsertPlan = {\n collection: this.#collection,\n records,\n consistency: this.#consistency,\n }\n await this.#sink.executeUpsert(plan)\n }\n\n async delete(): Promise<void> {\n const ids = this.extractIdsFromFilter()\n const filter = this.buildFilter()\n\n const plan: DeletePlan = {\n collection: this.#collection,\n ids: ids.length > 0 ? ids : undefined,\n filter: filter && Object.keys(filter).length > 0 ? filter : undefined,\n consistency: this.#consistency,\n }\n\n await this.#sink.executeDelete(plan)\n }\n\n #validateRawFilters(filter: VectorFilter | undefined): void {\n if (!filter) {\n return\n }\n\n if (isRawFilter(filter)) {\n const raw = filter.$raw as string\n const placeholders = (raw.match(/\\?/g) || []).length\n if (placeholders !== filter.$bindings?.length) {\n throw new E_VECTOR_STORE_RAW_BINDING_MISMATCH([placeholders, filter.$bindings?.length ?? 0])\n }\n return\n }\n\n if ('and' in filter && filter.and) {\n for (const f of filter.and) {\n this.#validateRawFilters(f)\n }\n }\n\n if ('or' in filter && filter.or) {\n for (const f of filter.or) {\n this.#validateRawFilters(f)\n }\n }\n\n if ('not' in filter && filter.not) {\n this.#validateRawFilters(filter.not)\n }\n }\n}\n\nexport { VectorQueryBuilder, FilterBuilder }\n"],"mappings":";;;;;;;;AAiBA,IAAM,aAA6C;CACjD,KAAK;CACL,MAAM;CACN,OAAO;CACP,MAAM;CACN,MAAM;CACN,OAAO;CACP,KAAK;CACL,MAAM;CACN,KAAK;CACL,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,OAAO;CACP,MAAM;CACN,OAAO;CACP,MAAM;CACN,OAAO;CACP,UAAU;CACV,YAAY;AACd;AACA,IAAM,eAAe,OAA+B;CAClD,MAAM,OAAO,WAAW;CACxB,IAAI,CAAC,MAAM,MAAM,IAAI,2CAA2C,CAAC,WAAW,EAAE,CAAC;CAC/E,OAAO;AACT;;;;;;;;;AA8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**
2
+ * @module @nhtio/adk/batteries/vector/chroma
3
+ */
4
+ import { BaseVectorStore } from "../contract";
5
+ import type { VectorFilter } from "../filters";
6
+ import type { SearchPlan, UpsertPlan, DeletePlan, CollectionSpec } from "../plan";
7
+ import type { VectorMatch, BaseVectorStoreOptions, VectorStoreCapabilities } from "../types";
8
+ export interface ChromaVectorStoreOptions extends BaseVectorStoreOptions {
9
+ connection?: {
10
+ url?: string;
11
+ host?: string;
12
+ port?: number;
13
+ ssl?: boolean;
14
+ };
15
+ }
16
+ export declare const translateChromaWhere: (filter?: VectorFilter) => Record<string, unknown> | undefined;
17
+ export declare class ChromaVectorStore extends BaseVectorStore {
18
+ #private;
19
+ readonly capabilities: VectorStoreCapabilities;
20
+ static isAvailable(): boolean;
21
+ isAvailable(): boolean;
22
+ connect(): Promise<void>;
23
+ close(): Promise<void>;
24
+ getCollection(name: string): Promise<any>;
25
+ createCollection(spec: CollectionSpec, ifNotExists: boolean): Promise<void>;
26
+ dropCollection(collection: string, ifExists: boolean): Promise<void>;
27
+ hasCollection(collection: string): Promise<boolean>;
28
+ renameCollection(from: string, to: string): Promise<void>;
29
+ executeUpsert(plan: UpsertPlan): Promise<void>;
30
+ executeSearch(plan: SearchPlan): Promise<VectorMatch[]>;
31
+ executeDelete(plan: DeletePlan): Promise<void>;
32
+ }