@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.
- package/CHANGELOG.md +230 -0
- package/batteries/embeddings/openai/adapter.cjs +1 -1
- package/batteries/embeddings/openai/adapter.mjs +1 -1
- package/batteries/embeddings/openai/exceptions.cjs +1 -1
- package/batteries/embeddings/openai/exceptions.mjs +1 -1
- package/batteries/embeddings/openai/types.d.ts +7 -0
- package/batteries/embeddings/webllm/adapter.cjs +1 -1
- package/batteries/embeddings/webllm/adapter.mjs +1 -1
- package/batteries/embeddings/webllm/exceptions.cjs +1 -1
- package/batteries/embeddings/webllm/exceptions.mjs +1 -1
- package/batteries/llm/chat_common/helpers.d.ts +165 -0
- package/batteries/llm/chat_common/types.d.ts +309 -0
- package/batteries/llm/index.d.ts +5 -0
- package/batteries/llm/ollama/adapter.cjs +736 -0
- package/batteries/llm/ollama/adapter.cjs.map +1 -0
- package/batteries/llm/ollama/adapter.d.ts +64 -0
- package/batteries/llm/ollama/adapter.mjs +734 -0
- package/batteries/llm/ollama/adapter.mjs.map +1 -0
- package/batteries/llm/ollama/exceptions.cjs +105 -0
- package/batteries/llm/ollama/exceptions.cjs.map +1 -0
- package/batteries/llm/ollama/exceptions.d.ts +112 -0
- package/batteries/llm/ollama/exceptions.mjs +96 -0
- package/batteries/llm/ollama/exceptions.mjs.map +1 -0
- package/batteries/llm/ollama/helpers.cjs +487 -0
- package/batteries/llm/ollama/helpers.cjs.map +1 -0
- package/batteries/llm/ollama/helpers.d.ts +158 -0
- package/batteries/llm/ollama/helpers.mjs +450 -0
- package/batteries/llm/ollama/helpers.mjs.map +1 -0
- package/batteries/llm/ollama/index.d.ts +29 -0
- package/batteries/llm/ollama/types.cjs +2 -0
- package/batteries/llm/ollama/types.d.ts +334 -0
- package/batteries/llm/ollama/types.mjs +0 -0
- package/batteries/llm/ollama/validation.cjs +130 -0
- package/batteries/llm/ollama/validation.cjs.map +1 -0
- package/batteries/llm/ollama/validation.d.ts +31 -0
- package/batteries/llm/ollama/validation.mjs +127 -0
- package/batteries/llm/ollama/validation.mjs.map +1 -0
- package/batteries/llm/ollama.cjs +54 -0
- package/batteries/llm/ollama.mjs +6 -0
- package/batteries/llm/openai_chat_completions/adapter.cjs +36 -19
- package/batteries/llm/openai_chat_completions/adapter.cjs.map +1 -1
- package/batteries/llm/openai_chat_completions/adapter.mjs +23 -6
- package/batteries/llm/openai_chat_completions/adapter.mjs.map +1 -1
- package/batteries/llm/openai_chat_completions/exceptions.cjs +1 -1
- package/batteries/llm/openai_chat_completions/exceptions.mjs +1 -1
- package/batteries/llm/openai_chat_completions/helpers.cjs +80 -320
- package/batteries/llm/openai_chat_completions/helpers.cjs.map +1 -1
- package/batteries/llm/openai_chat_completions/helpers.d.ts +68 -144
- package/batteries/llm/openai_chat_completions/helpers.mjs +40 -280
- package/batteries/llm/openai_chat_completions/helpers.mjs.map +1 -1
- package/batteries/llm/openai_chat_completions/types.d.ts +273 -181
- package/batteries/llm/openai_chat_completions/validation.cjs +2 -2
- package/batteries/llm/openai_chat_completions/validation.cjs.map +1 -1
- package/batteries/llm/openai_chat_completions/validation.mjs +2 -2
- package/batteries/llm/openai_chat_completions/validation.mjs.map +1 -1
- package/batteries/llm/openai_chat_completions.cjs +29 -28
- package/batteries/llm/openai_chat_completions.mjs +2 -1
- package/batteries/llm/webllm_chat_completions/adapter.cjs +38 -19
- package/batteries/llm/webllm_chat_completions/adapter.cjs.map +1 -1
- package/batteries/llm/webllm_chat_completions/adapter.d.ts +18 -0
- package/batteries/llm/webllm_chat_completions/adapter.mjs +25 -6
- package/batteries/llm/webllm_chat_completions/adapter.mjs.map +1 -1
- package/batteries/llm/webllm_chat_completions/exceptions.cjs +1 -1
- package/batteries/llm/webllm_chat_completions/exceptions.mjs +1 -1
- package/batteries/llm/webllm_chat_completions/helpers.cjs +29 -28
- package/batteries/llm/webllm_chat_completions/helpers.mjs +2 -1
- package/batteries/llm/webllm_chat_completions/types.d.ts +21 -0
- package/batteries/llm/webllm_chat_completions/validation.cjs +13 -1
- package/batteries/llm/webllm_chat_completions/validation.cjs.map +1 -1
- package/batteries/llm/webllm_chat_completions/validation.d.ts +12 -0
- package/batteries/llm/webllm_chat_completions/validation.mjs +13 -1
- package/batteries/llm/webllm_chat_completions/validation.mjs.map +1 -1
- package/batteries/llm/webllm_chat_completions.cjs +29 -28
- package/batteries/llm/webllm_chat_completions.mjs +2 -1
- package/batteries/llm.cjs +44 -28
- package/batteries/llm.mjs +9 -4
- package/batteries/storage/flydrive.cjs +1 -1
- package/batteries/storage/flydrive.mjs +1 -1
- package/batteries/storage/in_memory/index.d.ts +1 -1
- package/batteries/storage/in_memory.cjs +2 -2
- package/batteries/storage/in_memory.cjs.map +1 -1
- package/batteries/storage/in_memory.mjs +2 -2
- package/batteries/storage/in_memory.mjs.map +1 -1
- package/batteries/storage/opfs/index.d.ts +19 -0
- package/batteries/storage/opfs.cjs +1 -1
- package/batteries/storage/opfs.cjs.map +1 -1
- package/batteries/storage/opfs.mjs +1 -1
- package/batteries/storage/opfs.mjs.map +1 -1
- package/batteries/tools/_shared/index.d.ts +121 -0
- package/batteries/tools/_shared.cjs +157 -0
- package/batteries/tools/_shared.cjs.map +1 -0
- package/batteries/tools/_shared.mjs +149 -0
- package/batteries/tools/_shared.mjs.map +1 -0
- package/batteries/tools/color.cjs +3 -2
- package/batteries/tools/color.cjs.map +1 -1
- package/batteries/tools/color.mjs +3 -2
- package/batteries/tools/color.mjs.map +1 -1
- package/batteries/tools/comparison.cjs +4 -3
- package/batteries/tools/comparison.cjs.map +1 -1
- package/batteries/tools/comparison.mjs +4 -3
- package/batteries/tools/comparison.mjs.map +1 -1
- package/batteries/tools/data_structure.cjs +30 -10
- package/batteries/tools/data_structure.cjs.map +1 -1
- package/batteries/tools/data_structure.mjs +30 -10
- package/batteries/tools/data_structure.mjs.map +1 -1
- package/batteries/tools/datetime_extended.cjs +5 -10
- package/batteries/tools/datetime_extended.cjs.map +1 -1
- package/batteries/tools/datetime_extended.mjs +5 -10
- package/batteries/tools/datetime_extended.mjs.map +1 -1
- package/batteries/tools/datetime_math.cjs +2 -2
- package/batteries/tools/datetime_math.mjs +2 -2
- package/batteries/tools/encoding.cjs +13 -4
- package/batteries/tools/encoding.cjs.map +1 -1
- package/batteries/tools/encoding.mjs +13 -4
- package/batteries/tools/encoding.mjs.map +1 -1
- package/batteries/tools/formatting.cjs +4 -4
- package/batteries/tools/formatting.cjs.map +1 -1
- package/batteries/tools/formatting.mjs +4 -4
- package/batteries/tools/formatting.mjs.map +1 -1
- package/batteries/tools/geo_basics.cjs +2 -2
- package/batteries/tools/geo_basics.mjs +2 -2
- package/batteries/tools/index.d.ts +3 -0
- package/batteries/tools/math.cjs +10 -8
- package/batteries/tools/math.cjs.map +1 -1
- package/batteries/tools/math.mjs +10 -8
- package/batteries/tools/math.mjs.map +1 -1
- package/batteries/tools/memory.cjs +5 -5
- package/batteries/tools/memory.mjs +5 -5
- package/batteries/tools/parsing.cjs +9 -5
- package/batteries/tools/parsing.cjs.map +1 -1
- package/batteries/tools/parsing.mjs +9 -5
- package/batteries/tools/parsing.mjs.map +1 -1
- package/batteries/tools/retrievables.cjs +4 -4
- package/batteries/tools/retrievables.mjs +4 -4
- package/batteries/tools/scrapper/exceptions.d.ts +21 -0
- package/batteries/tools/scrapper/index.d.ts +172 -0
- package/batteries/tools/scrapper/shared.d.ts +139 -0
- package/batteries/tools/scrapper.cjs +8 -0
- package/batteries/tools/scrapper.mjs +2 -0
- package/batteries/tools/searxng/exceptions.d.ts +21 -0
- package/batteries/tools/searxng/index.d.ts +177 -0
- package/batteries/tools/searxng.cjs +6 -0
- package/batteries/tools/searxng.mjs +2 -0
- package/batteries/tools/standing_instructions.cjs +4 -4
- package/batteries/tools/standing_instructions.mjs +4 -4
- package/batteries/tools/statistics.cjs +54 -43
- package/batteries/tools/statistics.cjs.map +1 -1
- package/batteries/tools/statistics.mjs +54 -43
- package/batteries/tools/statistics.mjs.map +1 -1
- package/batteries/tools/string_processing.cjs +5 -5
- package/batteries/tools/string_processing.cjs.map +1 -1
- package/batteries/tools/string_processing.mjs +5 -5
- package/batteries/tools/string_processing.mjs.map +1 -1
- package/batteries/tools/structured_data.cjs +8 -13
- package/batteries/tools/structured_data.cjs.map +1 -1
- package/batteries/tools/structured_data.mjs +8 -13
- package/batteries/tools/structured_data.mjs.map +1 -1
- package/batteries/tools/text_analysis.cjs +3 -3
- package/batteries/tools/text_analysis.mjs +3 -3
- package/batteries/tools/text_comparison.cjs +2 -2
- package/batteries/tools/text_comparison.mjs +2 -2
- package/batteries/tools/time.cjs +2 -2
- package/batteries/tools/time.mjs +2 -2
- package/batteries/tools/unit_conversion.cjs +10 -8
- package/batteries/tools/unit_conversion.cjs.map +1 -1
- package/batteries/tools/unit_conversion.mjs +10 -8
- package/batteries/tools/unit_conversion.mjs.map +1 -1
- package/batteries/tools/web_retrieval/index.d.ts +186 -0
- package/batteries/tools/web_retrieval.cjs +206 -0
- package/batteries/tools/web_retrieval.cjs.map +1 -0
- package/batteries/tools/web_retrieval.mjs +201 -0
- package/batteries/tools/web_retrieval.mjs.map +1 -0
- package/batteries/tools.cjs +15 -0
- package/batteries/tools.mjs +4 -1
- package/batteries/vector/arangodb/index.d.ts +2 -0
- package/batteries/vector/arangodb.cjs +2 -1
- package/batteries/vector/arangodb.cjs.map +1 -1
- package/batteries/vector/arangodb.mjs +2 -1
- package/batteries/vector/arangodb.mjs.map +1 -1
- package/batteries/vector/builder.cjs +31 -0
- package/batteries/vector/builder.cjs.map +1 -1
- package/batteries/vector/builder.d.ts +58 -0
- package/batteries/vector/builder.mjs +31 -0
- package/batteries/vector/builder.mjs.map +1 -1
- package/batteries/vector/chroma/index.d.ts +4 -0
- package/batteries/vector/chroma.cjs +3 -0
- package/batteries/vector/chroma.cjs.map +1 -1
- package/batteries/vector/chroma.mjs +3 -0
- package/batteries/vector/chroma.mjs.map +1 -1
- package/batteries/vector/clickhouse/index.d.ts +2 -0
- package/batteries/vector/clickhouse.cjs +2 -1
- package/batteries/vector/clickhouse.cjs.map +1 -1
- package/batteries/vector/clickhouse.mjs +2 -1
- package/batteries/vector/clickhouse.mjs.map +1 -1
- package/batteries/vector/cloudflare/index.d.ts +2 -0
- package/batteries/vector/cloudflare.cjs +2 -1
- package/batteries/vector/cloudflare.cjs.map +1 -1
- package/batteries/vector/cloudflare.mjs +2 -1
- package/batteries/vector/cloudflare.mjs.map +1 -1
- package/batteries/vector/conformance/index.d.ts +22 -0
- package/batteries/vector/conformance.cjs +22 -0
- package/batteries/vector/conformance.cjs.map +1 -1
- package/batteries/vector/conformance.mjs +22 -0
- package/batteries/vector/conformance.mjs.map +1 -1
- package/batteries/vector/contract.cjs +22 -0
- package/batteries/vector/contract.cjs.map +1 -1
- package/batteries/vector/contract.d.ts +51 -0
- package/batteries/vector/contract.mjs +22 -0
- package/batteries/vector/contract.mjs.map +1 -1
- package/batteries/vector/couchbase/index.d.ts +2 -0
- package/batteries/vector/couchbase.cjs +2 -1
- package/batteries/vector/couchbase.cjs.map +1 -1
- package/batteries/vector/couchbase.mjs +2 -1
- package/batteries/vector/couchbase.mjs.map +1 -1
- package/batteries/vector/duckdb/index.d.ts +2 -0
- package/batteries/vector/duckdb.cjs +2 -1
- package/batteries/vector/duckdb.cjs.map +1 -1
- package/batteries/vector/duckdb.mjs +2 -1
- package/batteries/vector/duckdb.mjs.map +1 -1
- package/batteries/vector/elasticsearch/index.d.ts +2 -0
- package/batteries/vector/elasticsearch.cjs +2 -1
- package/batteries/vector/elasticsearch.cjs.map +1 -1
- package/batteries/vector/elasticsearch.mjs +2 -1
- package/batteries/vector/elasticsearch.mjs.map +1 -1
- package/batteries/vector/exceptions.cjs +1 -1
- package/batteries/vector/exceptions.mjs +1 -1
- package/batteries/vector/factory.cjs +6 -0
- package/batteries/vector/factory.cjs.map +1 -1
- package/batteries/vector/factory.d.ts +14 -0
- package/batteries/vector/factory.mjs +6 -0
- package/batteries/vector/factory.mjs.map +1 -1
- package/batteries/vector/filters.cjs +22 -1
- package/batteries/vector/filters.cjs.map +1 -1
- package/batteries/vector/filters.d.ts +38 -0
- package/batteries/vector/filters.mjs +22 -1
- package/batteries/vector/filters.mjs.map +1 -1
- package/batteries/vector/helpers.cjs +13 -0
- package/batteries/vector/helpers.cjs.map +1 -1
- package/batteries/vector/helpers.d.ts +14 -0
- package/batteries/vector/helpers.mjs +13 -0
- package/batteries/vector/helpers.mjs.map +1 -1
- package/batteries/vector/hnswlib/index.d.ts +2 -0
- package/batteries/vector/hnswlib.cjs +2 -1
- package/batteries/vector/hnswlib.cjs.map +1 -1
- package/batteries/vector/hnswlib.mjs +2 -1
- package/batteries/vector/hnswlib.mjs.map +1 -1
- package/batteries/vector/in_memory/index.d.ts +1 -0
- package/batteries/vector/in_memory.cjs +1 -0
- package/batteries/vector/in_memory.cjs.map +1 -1
- package/batteries/vector/in_memory.mjs +1 -0
- package/batteries/vector/in_memory.mjs.map +1 -1
- package/batteries/vector/lancedb/index.d.ts +2 -0
- package/batteries/vector/lancedb.cjs +2 -1
- package/batteries/vector/lancedb.cjs.map +1 -1
- package/batteries/vector/lancedb.mjs +2 -1
- package/batteries/vector/lancedb.mjs.map +1 -1
- package/batteries/vector/mariadb/index.d.ts +2 -0
- package/batteries/vector/mariadb.cjs +2 -1
- package/batteries/vector/mariadb.cjs.map +1 -1
- package/batteries/vector/mariadb.mjs +2 -1
- package/batteries/vector/mariadb.mjs.map +1 -1
- package/batteries/vector/meilisearch/index.d.ts +2 -0
- package/batteries/vector/meilisearch.cjs +2 -1
- package/batteries/vector/meilisearch.cjs.map +1 -1
- package/batteries/vector/meilisearch.mjs +2 -1
- package/batteries/vector/meilisearch.mjs.map +1 -1
- package/batteries/vector/migrate.cjs +18 -1
- package/batteries/vector/migrate.cjs.map +1 -1
- package/batteries/vector/migrate.d.ts +31 -0
- package/batteries/vector/migrate.mjs +18 -1
- package/batteries/vector/migrate.mjs.map +1 -1
- package/batteries/vector/milvus/index.d.ts +5 -0
- package/batteries/vector/milvus.cjs +4 -0
- package/batteries/vector/milvus.cjs.map +1 -1
- package/batteries/vector/milvus.mjs +4 -0
- package/batteries/vector/milvus.mjs.map +1 -1
- package/batteries/vector/mongodb/index.d.ts +2 -0
- package/batteries/vector/mongodb.cjs +2 -1
- package/batteries/vector/mongodb.cjs.map +1 -1
- package/batteries/vector/mongodb.mjs +2 -1
- package/batteries/vector/mongodb.mjs.map +1 -1
- package/batteries/vector/neo4j/index.d.ts +2 -0
- package/batteries/vector/neo4j.cjs +2 -1
- package/batteries/vector/neo4j.cjs.map +1 -1
- package/batteries/vector/neo4j.mjs +2 -1
- package/batteries/vector/neo4j.mjs.map +1 -1
- package/batteries/vector/opensearch/index.d.ts +2 -0
- package/batteries/vector/opensearch.cjs +2 -1
- package/batteries/vector/opensearch.cjs.map +1 -1
- package/batteries/vector/opensearch.mjs +2 -1
- package/batteries/vector/opensearch.mjs.map +1 -1
- package/batteries/vector/oracle23ai/index.d.ts +2 -0
- package/batteries/vector/oracle23ai.cjs +2 -1
- package/batteries/vector/oracle23ai.cjs.map +1 -1
- package/batteries/vector/oracle23ai.mjs +2 -1
- package/batteries/vector/oracle23ai.mjs.map +1 -1
- package/batteries/vector/orama/index.d.ts +1 -0
- package/batteries/vector/orama.cjs +1 -0
- package/batteries/vector/orama.cjs.map +1 -1
- package/batteries/vector/orama.mjs +1 -0
- package/batteries/vector/orama.mjs.map +1 -1
- package/batteries/vector/pgvector/index.d.ts +9 -2
- package/batteries/vector/pgvector.cjs +4 -0
- package/batteries/vector/pgvector.cjs.map +1 -1
- package/batteries/vector/pgvector.mjs +4 -0
- package/batteries/vector/pgvector.mjs.map +1 -1
- package/batteries/vector/pinecone/index.d.ts +5 -0
- package/batteries/vector/pinecone.cjs +3 -1
- package/batteries/vector/pinecone.cjs.map +1 -1
- package/batteries/vector/pinecone.mjs +3 -1
- package/batteries/vector/pinecone.mjs.map +1 -1
- package/batteries/vector/plan.d.ts +27 -0
- package/batteries/vector/qdrant/index.d.ts +5 -0
- package/batteries/vector/qdrant.cjs +4 -0
- package/batteries/vector/qdrant.cjs.map +1 -1
- package/batteries/vector/qdrant.mjs +4 -0
- package/batteries/vector/qdrant.mjs.map +1 -1
- package/batteries/vector/redis/index.d.ts +2 -0
- package/batteries/vector/redis.cjs +2 -1
- package/batteries/vector/redis.cjs.map +1 -1
- package/batteries/vector/redis.mjs +2 -1
- package/batteries/vector/redis.mjs.map +1 -1
- package/batteries/vector/retrievable.cjs +9 -1
- package/batteries/vector/retrievable.cjs.map +1 -1
- package/batteries/vector/retrievable.mjs +9 -1
- package/batteries/vector/retrievable.mjs.map +1 -1
- package/batteries/vector/retrievable_glue.d.ts +21 -0
- package/batteries/vector/s3vectors/index.d.ts +2 -0
- package/batteries/vector/s3vectors.cjs +2 -1
- package/batteries/vector/s3vectors.cjs.map +1 -1
- package/batteries/vector/s3vectors.mjs +2 -1
- package/batteries/vector/s3vectors.mjs.map +1 -1
- package/batteries/vector/schema.cjs +28 -0
- package/batteries/vector/schema.cjs.map +1 -1
- package/batteries/vector/schema.d.ts +39 -0
- package/batteries/vector/schema.mjs +28 -0
- package/batteries/vector/schema.mjs.map +1 -1
- package/batteries/vector/solr/index.d.ts +2 -0
- package/batteries/vector/solr.cjs +2 -1
- package/batteries/vector/solr.cjs.map +1 -1
- package/batteries/vector/solr.mjs +2 -1
- package/batteries/vector/solr.mjs.map +1 -1
- package/batteries/vector/sqlite_vec/index.d.ts +6 -3
- package/batteries/vector/sqlite_vec.cjs +2 -0
- package/batteries/vector/sqlite_vec.cjs.map +1 -1
- package/batteries/vector/sqlite_vec.mjs +2 -0
- package/batteries/vector/sqlite_vec.mjs.map +1 -1
- package/batteries/vector/surrealdb/index.d.ts +2 -0
- package/batteries/vector/surrealdb.cjs +2 -1
- package/batteries/vector/surrealdb.cjs.map +1 -1
- package/batteries/vector/surrealdb.mjs +2 -1
- package/batteries/vector/surrealdb.mjs.map +1 -1
- package/batteries/vector/types.d.ts +27 -0
- package/batteries/vector/typesense/index.d.ts +2 -0
- package/batteries/vector/typesense.cjs +2 -1
- package/batteries/vector/typesense.cjs.map +1 -1
- package/batteries/vector/typesense.mjs +2 -1
- package/batteries/vector/typesense.mjs.map +1 -1
- package/batteries/vector/validation.cjs +14 -0
- package/batteries/vector/validation.cjs.map +1 -1
- package/batteries/vector/validation.d.ts +14 -0
- package/batteries/vector/validation.mjs +14 -0
- package/batteries/vector/validation.mjs.map +1 -1
- package/batteries/vector/vector_store_constructor.cjs +1 -1
- package/batteries/vector/vector_store_constructor.cjs.map +1 -1
- package/batteries/vector/vector_store_constructor.d.ts +1 -1
- package/batteries/vector/vector_store_constructor.mjs +1 -1
- package/batteries/vector/vector_store_constructor.mjs.map +1 -1
- package/batteries/vector/vespa/index.d.ts +2 -0
- package/batteries/vector/vespa.cjs +2 -1
- package/batteries/vector/vespa.cjs.map +1 -1
- package/batteries/vector/vespa.mjs +2 -1
- package/batteries/vector/vespa.mjs.map +1 -1
- package/batteries/vector/weaviate/index.d.ts +2 -0
- package/batteries/vector/weaviate.cjs +2 -1
- package/batteries/vector/weaviate.cjs.map +1 -1
- package/batteries/vector/weaviate.mjs +2 -1
- package/batteries/vector/weaviate.mjs.map +1 -1
- package/batteries.cjs +58 -28
- package/batteries.mjs +12 -5
- package/{common-BT0nfCi9.mjs → common-DYDUi99O.mjs} +9 -9
- package/common-DYDUi99O.mjs.map +1 -0
- package/{common-Cj8TaQ9U.js → common-DZl3ADJs.js} +9 -9
- package/common-DZl3ADJs.js.map +1 -0
- package/common.cjs +7 -7
- package/common.mjs +7 -7
- package/{dispatch_runner-DPcS7Y_M.mjs → dispatch_runner--ZhdDWRZ.mjs} +27 -5
- package/{dispatch_runner-DPcS7Y_M.mjs.map → dispatch_runner--ZhdDWRZ.mjs.map} +1 -1
- package/{dispatch_runner-BHBNupqp.js → dispatch_runner-nHDKkxye.js} +27 -5
- package/{dispatch_runner-BHBNupqp.js.map → dispatch_runner-nHDKkxye.js.map} +1 -1
- package/dispatch_runner.cjs +1 -1
- package/dispatch_runner.d.ts +1 -1
- package/dispatch_runner.mjs +1 -1
- package/eslint/rules/artifact_tool_forbids_artifact_constructor.cjs +1 -0
- package/eslint/rules/artifact_tool_forbids_artifact_constructor.cjs.map +1 -1
- package/eslint/rules/artifact_tool_forbids_artifact_constructor.d.ts +1 -0
- package/eslint/rules/artifact_tool_forbids_artifact_constructor.mjs +1 -0
- package/eslint/rules/artifact_tool_forbids_artifact_constructor.mjs.map +1 -1
- package/eslint/rules/no_model_in_tool_handler.cjs +1 -0
- package/eslint/rules/no_model_in_tool_handler.cjs.map +1 -1
- package/eslint/rules/no_model_in_tool_handler.d.ts +1 -0
- package/eslint/rules/no_model_in_tool_handler.mjs +1 -0
- package/eslint/rules/no_model_in_tool_handler.mjs.map +1 -1
- package/eslint/rules/require_validator_any_required.cjs +1 -0
- package/eslint/rules/require_validator_any_required.cjs.map +1 -1
- package/eslint/rules/require_validator_any_required.d.ts +1 -0
- package/eslint/rules/require_validator_any_required.mjs +1 -0
- package/eslint/rules/require_validator_any_required.mjs.map +1 -1
- package/eslint/rules/thought_payload_requires_replay_tag.cjs +1 -0
- package/eslint/rules/thought_payload_requires_replay_tag.cjs.map +1 -1
- package/eslint/rules/thought_payload_requires_replay_tag.d.ts +1 -0
- package/eslint/rules/thought_payload_requires_replay_tag.mjs +1 -0
- package/eslint/rules/thought_payload_requires_replay_tag.mjs.map +1 -1
- package/eslint/rules/token_encoding_requires_context_window.cjs +1 -0
- package/eslint/rules/token_encoding_requires_context_window.cjs.map +1 -1
- package/eslint/rules/token_encoding_requires_context_window.d.ts +1 -0
- package/eslint/rules/token_encoding_requires_context_window.mjs +1 -0
- package/eslint/rules/token_encoding_requires_context_window.mjs.map +1 -1
- package/eslint/rules.cjs +1 -1
- package/eslint/rules.mjs +1 -1
- package/eslint.cjs +2 -2
- package/eslint.mjs +2 -2
- package/{exceptions-BeWH2FwP.mjs → exceptions-BDhN0Xzr.mjs} +3 -2
- package/exceptions-BDhN0Xzr.mjs.map +1 -0
- package/{exceptions-CitH5wZI.js → exceptions-BRXrUKiW.js} +3 -2
- package/exceptions-BRXrUKiW.js.map +1 -0
- package/exceptions.cjs +2 -2
- package/exceptions.mjs +2 -2
- package/factories.cjs +1 -1
- package/factories.mjs +1 -1
- package/forge.cjs +4 -4
- package/forge.d.ts +1 -1
- package/forge.mjs +4 -4
- package/guards.cjs +9 -9
- package/guards.mjs +9 -9
- package/helpers-DSTFxTiC.js +497 -0
- package/helpers-DSTFxTiC.js.map +1 -0
- package/helpers-xhrQbMAG.mjs +306 -0
- package/helpers-xhrQbMAG.mjs.map +1 -0
- package/index.cjs +12 -12
- package/index.mjs +12 -12
- package/lib/classes/base_exception.d.ts +1 -0
- package/lib/classes/media.d.ts +10 -0
- package/lib/classes/retrievable.d.ts +1 -1
- package/lib/classes/spooled_json_artifact.d.ts +1 -1
- package/lib/classes/spooled_markdown_artifact.d.ts +1 -0
- package/lib/classes/tokenizable.d.ts +3 -0
- package/lib/classes/tool.d.ts +8 -0
- package/lib/classes/turn_gate.d.ts +6 -0
- package/lib/dispatch_runner.d.ts +4 -32
- package/lib/helpers/bignum.cjs +82 -0
- package/lib/helpers/bignum.cjs.map +1 -0
- package/lib/helpers/bignum.d.ts +52 -0
- package/lib/helpers/bignum.mjs +74 -0
- package/lib/helpers/bignum.mjs.map +1 -0
- package/lib/turn_runner.d.ts +1 -1
- package/lib/types/dispatch_runner.d.ts +83 -0
- package/lib/utils/exceptions.d.ts +1 -1
- package/lib/utils/retry.cjs.map +1 -1
- package/lib/utils/retry.d.ts +2 -0
- package/lib/utils/retry.mjs.map +1 -1
- package/mcp/adk-docs-corpus.json +1 -1
- package/package.json +259 -204
- package/{runtime-j92CNi5z.mjs → runtime-Bz5zA8wc.mjs} +2 -2
- package/{runtime-j92CNi5z.mjs.map → runtime-Bz5zA8wc.mjs.map} +1 -1
- package/{runtime-MFFcJrRv.js → runtime-DslE1aBw.js} +2 -2
- package/{runtime-MFFcJrRv.js.map → runtime-DslE1aBw.js.map} +1 -1
- package/scrapper-BHM1mCde.mjs +432 -0
- package/scrapper-BHM1mCde.mjs.map +1 -0
- package/scrapper-BeweWurk.js +462 -0
- package/scrapper-BeweWurk.js.map +1 -0
- package/searxng-BJFulNcK.mjs +247 -0
- package/searxng-BJFulNcK.mjs.map +1 -0
- package/searxng-B_D--V5q.js +265 -0
- package/searxng-B_D--V5q.js.map +1 -0
- package/skills/adk-assembly/SKILL.md +2 -2
- package/{spooled_artifact-CHoZgWwI.mjs → spooled_artifact-7eePq7JA.mjs} +5 -5
- package/{spooled_artifact-CHoZgWwI.mjs.map → spooled_artifact-7eePq7JA.mjs.map} +1 -1
- package/{spooled_artifact-BTq6Nzfy.js → spooled_artifact-DX8LLyUX.js} +5 -5
- package/{spooled_artifact-BTq6Nzfy.js.map → spooled_artifact-DX8LLyUX.js.map} +1 -1
- package/spooled_artifact.cjs +2 -2
- package/spooled_artifact.mjs +2 -2
- package/{spooled_markdown_artifact-CALSDxIx.js → spooled_markdown_artifact-ClX72lek.js} +4 -4
- package/spooled_markdown_artifact-ClX72lek.js.map +1 -0
- package/{spooled_markdown_artifact-Ci5UL7l4.mjs → spooled_markdown_artifact-wkrBF3oX.mjs} +4 -4
- package/spooled_markdown_artifact-wkrBF3oX.mjs.map +1 -0
- package/{thought-D34QQZZ9.mjs → thought-B_vxAiKU.mjs} +5 -5
- package/{thought-D34QQZZ9.mjs.map → thought-B_vxAiKU.mjs.map} +1 -1
- package/{thought-BbwhJ1wb.js → thought-DLwpF7MI.js} +5 -5
- package/{thought-BbwhJ1wb.js.map → thought-DLwpF7MI.js.map} +1 -1
- package/{tool-CVyZkFC7.js → tool-D5WGVIcI.js} +4 -4
- package/{tool-CVyZkFC7.js.map → tool-D5WGVIcI.js.map} +1 -1
- package/{tool-CMhaDRNd.mjs → tool-wMYMVl60.mjs} +4 -4
- package/{tool-CMhaDRNd.mjs.map → tool-wMYMVl60.mjs.map} +1 -1
- package/{tool_call-CV5qVNlb.mjs → tool_call-B4-_-vjG.mjs} +5 -5
- package/tool_call-B4-_-vjG.mjs.map +1 -0
- package/{tool_call-Db68hB7y.js → tool_call-DixVlW40.js} +5 -5
- package/tool_call-DixVlW40.js.map +1 -0
- package/{tool_registry-D1pSSlsd.mjs → tool_registry-791Vrjtf.mjs} +4 -3
- package/tool_registry-791Vrjtf.mjs.map +1 -0
- package/{tool_registry-DYUYqXvo.js → tool_registry-CKJPze3j.js} +4 -3
- package/tool_registry-CKJPze3j.js.map +1 -0
- package/{turn_runner-DqWHNP80.js → turn_runner-HXImLGIn.js} +7 -7
- package/turn_runner-HXImLGIn.js.map +1 -0
- package/{turn_runner-fg1Wc3dK.mjs → turn_runner-ZyYO-Kti.mjs} +7 -7
- package/turn_runner-ZyYO-Kti.mjs.map +1 -0
- package/turn_runner.cjs +1 -1
- package/turn_runner.mjs +1 -1
- package/types.d.ts +1 -1
- package/common-BT0nfCi9.mjs.map +0 -1
- package/common-Cj8TaQ9U.js.map +0 -1
- package/exceptions-BeWH2FwP.mjs.map +0 -1
- package/exceptions-CitH5wZI.js.map +0 -1
- package/spooled_markdown_artifact-CALSDxIx.js.map +0 -1
- package/spooled_markdown_artifact-Ci5UL7l4.mjs.map +0 -1
- package/tool_call-CV5qVNlb.mjs.map +0 -1
- package/tool_call-Db68hB7y.js.map +0 -1
- package/tool_registry-D1pSSlsd.mjs.map +0 -1
- package/tool_registry-DYUYqXvo.js.map +0 -1
- package/turn_runner-DqWHNP80.js.map +0 -1
- package/turn_runner-fg1Wc3dK.mjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { o as isError } from "../../tool_registry-
|
|
2
|
-
import { t as Tool } from "../../tool-
|
|
3
|
-
import "../../common-
|
|
1
|
+
import { c as isObject, o as isError } from "../../tool_registry-791Vrjtf.mjs";
|
|
2
|
+
import { t as Tool } from "../../tool-wMYMVl60.mjs";
|
|
3
|
+
import "../../common-DYDUi99O.mjs";
|
|
4
4
|
import "../../guards.mjs";
|
|
5
5
|
import { validator } from "@nhtio/validation";
|
|
6
6
|
//#region src/batteries/tools/structured_data/index.ts
|
|
@@ -49,29 +49,24 @@ var formatTableTool = new Tool({
|
|
|
49
49
|
}
|
|
50
50
|
if (!Array.isArray(rows)) return "Error: Input must be a JSON array.";
|
|
51
51
|
if (rows.length === 0) return "Empty array — no data to display.";
|
|
52
|
+
if (!explicitColumns && !isObject(rows[0])) return "Error: Cannot infer columns — the first row is not an object. Provide \"columns\", or pass an array of objects.";
|
|
52
53
|
const columns = explicitColumns ?? Object.keys(rows[0]);
|
|
54
|
+
const cell = (row, col) => isObject(row) ? row[col] : void 0;
|
|
53
55
|
if (format === "csv") {
|
|
54
56
|
const lines = [columns.map(csvEscape).join(",")];
|
|
55
|
-
for (const row of rows)
|
|
56
|
-
const obj = row;
|
|
57
|
-
lines.push(columns.map((col) => csvEscape(obj[col])).join(","));
|
|
58
|
-
}
|
|
57
|
+
for (const row of rows) lines.push(columns.map((col) => csvEscape(cell(row, col))).join(","));
|
|
59
58
|
return lines.join("\n");
|
|
60
59
|
}
|
|
61
60
|
if (format === "tsv") {
|
|
62
61
|
const lines = [columns.map(tsvEscape).join(" ")];
|
|
63
|
-
for (const row of rows)
|
|
64
|
-
const obj = row;
|
|
65
|
-
lines.push(columns.map((col) => tsvEscape(obj[col])).join(" "));
|
|
66
|
-
}
|
|
62
|
+
for (const row of rows) lines.push(columns.map((col) => tsvEscape(cell(row, col))).join(" "));
|
|
67
63
|
return lines.join("\n");
|
|
68
64
|
}
|
|
69
65
|
return [
|
|
70
66
|
"| " + columns.map(mdEscape).join(" | ") + " |",
|
|
71
67
|
"| " + columns.map(() => "---").join(" | ") + " |",
|
|
72
68
|
...rows.map((row) => {
|
|
73
|
-
|
|
74
|
-
return "| " + columns.map((col) => mdEscape(obj[col])).join(" | ") + " |";
|
|
69
|
+
return "| " + columns.map((col) => mdEscape(cell(row, col))).join(" | ") + " |";
|
|
75
70
|
})
|
|
76
71
|
].join("\n");
|
|
77
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structured_data.mjs","names":[],"sources":["../../../src/batteries/tools/structured_data/index.ts"],"sourcesContent":["/**\n * Pre-constructed tools for transforming arrays and objects into tables and tabular text.\n *\n * @module @nhtio/adk/batteries/tools/structured_data\n *\n * @remarks\n * Pre-constructed bundled tools for the `structured_data` category. Import individually, the whole\n * category, or import every tool via `@nhtio/adk/batteries`.\n */\n\nimport { Tool } from '@nhtio/adk/common'\nimport { isError } from '@nhtio/adk/guards'\nimport { validator } from '@nhtio/validation'\n\nfunction csvEscape(value: unknown): string {\n const str = value === null || value === undefined ? '' : String(value)\n if (str.includes(',') || str.includes('\"') || str.includes('\\n') || str.includes('\\r')) {\n return '\"' + str.replace(/\"/g, '\"\"') + '\"'\n }\n return str\n}\n\nfunction tsvEscape(value: unknown): string {\n const str = value === null || value === undefined ? '' : String(value)\n return str.replace(/\\t/g, ' ').replace(/\\r?\\n/g, ' ')\n}\n\nfunction mdEscape(value: unknown): string {\n return String(value === null || value === undefined ? '' : value)\n .replace(/\\|/g, '\\\\|')\n .replace(/\\r?\\n/g, ' ')\n}\n\n/**\n * Convert a JSON array of objects into a formatted table.\n *\n * @remarks\n * Supports `markdown`, `csv`, and `tsv` output. Columns default to the keys of the first row;\n * supply `columns` to control which keys appear and in what order.\n */\nexport const formatTableTool = new Tool({\n name: 'format_table',\n description:\n 'Convert a JSON array of objects into a formatted table. Supports Markdown, CSV, and TSV output.',\n inputSchema: validator.object({\n data: validator.string().required().description('JSON array of objects as a string'),\n format: validator\n .string()\n .valid('markdown', 'csv', 'tsv')\n .required()\n .description('Output format'),\n columns: validator\n .array()\n .items(validator.string())\n .optional()\n .description(\n 'Column keys to include, in order. If omitted, all keys from the first row are used.'\n ),\n }),\n handler: async (args) => {\n const {\n data,\n format,\n columns: explicitColumns,\n } = args as {\n data: string\n format: 'markdown' | 'csv' | 'tsv'\n columns?: string[]\n }\n\n let rows: unknown[]\n try {\n rows = JSON.parse(data)\n } catch {\n return 'Error: Invalid JSON input.'\n }\n\n if (!Array.isArray(rows)) return 'Error: Input must be a JSON array.'\n if (rows.length === 0) return 'Empty array — no data to display.'\n\n const columns = explicitColumns ?? Object.keys(rows[0] as Record<string, unknown>)\n\n if (format === 'csv') {\n const lines = [columns.map(csvEscape).join(',')]\n for (const row of rows) {\n const obj = row as Record<string, unknown>\n lines.push(columns.map((col) => csvEscape(obj[col])).join(','))\n }\n return lines.join('\\n')\n }\n\n if (format === 'tsv') {\n const lines = [columns.map(tsvEscape).join('\\t')]\n for (const row of rows) {\n const obj = row as Record<string, unknown>\n lines.push(columns.map((col) => tsvEscape(obj[col])).join('\\t'))\n }\n return lines.join('\\n')\n }\n\n const header = '| ' + columns.map(mdEscape).join(' | ') + ' |'\n const separator = '| ' + columns.map(() => '---').join(' | ') + ' |'\n const dataRows = rows.map((row) => {\n const obj = row as Record<string, unknown>\n return '| ' + columns.map((col) => mdEscape(obj[col])).join(' | ') + ' |'\n })\n return [header, separator, ...dataRows].join('\\n')\n },\n})\n\n/**\n * Pretty-print or minify a JSON string.\n *\n * @remarks\n * Validates the input as JSON, then re-serialises it with the requested indentation. `indent` is\n * clamped to the range [0, 8]; `0` produces minified output.\n */\nexport const jsonFormatTool = new Tool({\n name: 'json_format',\n description: 'Pretty-print or minify a JSON string. Validates JSON and normalises whitespace.',\n inputSchema: validator.object({\n data: validator.string().required().description('JSON string to format'),\n indent: validator\n .number()\n .default(2)\n .description('Indentation spaces (0 = minify, default: 2). Max: 8.'),\n }),\n handler: async (args) => {\n const { data, indent } = args as { data: string; indent: number }\n try {\n const parsed = JSON.parse(data)\n return JSON.stringify(parsed, null, Math.max(0, Math.min(8, Math.floor(indent))))\n } catch (err) {\n return `Error: Invalid JSON — ${isError(err) ? err.message : String(err)}`\n }\n },\n})\n\nconst FORMAT_PATTERNS: Record<string, { pattern: RegExp; label: string }> = {\n email: {\n pattern: /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/,\n label: 'email address',\n },\n uuid: {\n pattern: /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,\n label: 'UUID (v1–v5)',\n },\n ipv4: {\n pattern: /^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$/,\n label: 'IPv4 address',\n },\n iso_date: {\n pattern: /^\\d{4}-\\d{2}-\\d{2}$/,\n label: 'ISO 8601 date (YYYY-MM-DD)',\n },\n iso_datetime: {\n pattern: /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?(Z|[+-]\\d{2}:\\d{2})?$/,\n label: 'ISO 8601 datetime',\n },\n hex_color: {\n pattern: /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/,\n label: 'CSS hex color',\n },\n phone_e164: {\n pattern: /^\\+[1-9]\\d{1,14}$/,\n label: 'E.164 phone number',\n },\n semver: {\n pattern: /^\\d+\\.\\d+\\.\\d+(-[0-9A-Za-z-.]+)?(\\+[0-9A-Za-z-.]+)?$/,\n label: 'Semantic Version (SemVer)',\n },\n integer: {\n pattern: /^-?\\d+$/,\n label: 'integer',\n },\n decimal: {\n pattern: /^-?\\d+(\\.\\d+)?$/,\n label: 'decimal number',\n },\n alphanumeric: {\n pattern: /^[a-zA-Z0-9]+$/,\n label: 'alphanumeric string',\n },\n slug: {\n pattern: /^[a-z0-9]+(-[a-z0-9]+)*$/,\n label: 'URL slug',\n },\n hex: {\n pattern: /^(0x)?[0-9a-fA-F]+$/,\n label: 'hexadecimal string',\n },\n base64: {\n pattern: /^[A-Za-z0-9+/]*={0,2}$/,\n label: 'base64-encoded string',\n },\n}\n\n/**\n * Check whether a string matches a known format.\n *\n * @remarks\n * Supported formats: `email`, `uuid` (v1–v5), `ipv4`, `iso_date`, `iso_datetime`, `hex_color`,\n * `phone_e164`, `semver`, `integer`, `decimal`, `alphanumeric`, `slug`, `hex`, `base64`.\n */\nexport const validateFormatTool = new Tool({\n name: 'validate_format',\n description:\n 'Check whether a string matches a known format (email, UUID, ISO date, hex colour, phone number, semver, slug, etc.).',\n inputSchema: validator.object({\n value: validator.string().required().description('The string to validate'),\n format: validator\n .string()\n .valid(...Object.keys(FORMAT_PATTERNS))\n .required()\n .description(\n `Format to validate against. One of: ${Object.keys(FORMAT_PATTERNS).join(', ')}`\n ),\n }),\n handler: async (args) => {\n const { value, format } = args as { value: string; format: string }\n const def = FORMAT_PATTERNS[format]\n if (!def) {\n return `Error: Unknown format \"${format}\". Supported: ${Object.keys(FORMAT_PATTERNS).join(', ')}`\n }\n const valid = def.pattern.test(value)\n return valid\n ? `Valid: \"${value}\" is a valid ${def.label}.`\n : `Invalid: \"${value}\" is not a valid ${def.label}.`\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;AAcA,SAAS,UAAU,OAAwB;CACzC,MAAM,MAAM,UAAU,QAAQ,UAAU,KAAA,IAAY,KAAK,OAAO,KAAK;CACrE,IAAI,IAAI,SAAS,GAAG,KAAK,IAAI,SAAS,IAAG,KAAK,IAAI,SAAS,IAAI,KAAK,IAAI,SAAS,IAAI,GACnF,OAAO,OAAM,IAAI,QAAQ,MAAM,MAAI,IAAI;CAEzC,OAAO;AACT;AAEA,SAAS,UAAU,OAAwB;CAEzC,QADY,UAAU,QAAQ,UAAU,KAAA,IAAY,KAAK,OAAO,KAAK,GAC1D,QAAQ,OAAO,GAAG,EAAE,QAAQ,UAAU,GAAG;AACtD;AAEA,SAAS,SAAS,OAAwB;CACxC,OAAO,OAAO,UAAU,QAAQ,UAAU,KAAA,IAAY,KAAK,KAAK,EAC7D,QAAQ,OAAO,KAAK,EACpB,QAAQ,UAAU,GAAG;AAC1B;;;;;;;;AASA,IAAa,kBAAkB,IAAI,KAAK;CACtC,MAAM;CACN,aACE;CACF,aAAa,UAAU,O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;;;;;;;;AASA,IAAa,qBAAqB,IAAI,KAAK;CACzC,MAAM;CACN,aACE;CACF,aAAa,UAAU,OAAO;EAC5B,OAAO,UAAU,OAAO,EAAE,SAAS,EAAE,YAAY,wBAAwB;EACzE,QAAQ,UACL,OAAO,EACP,MAAM,GAAG,OAAO,KAAK,eAAe,CAAC,EACrC,SAAS,EACT,YACC,uCAAuC,OAAO,KAAK,eAAe,EAAE,KAAK,IAAI,GAC/E;CACJ,CAAC;CACD,SAAS,OAAO,SAAS;EACvB,MAAM,EAAE,OAAO,WAAW;EAC1B,MAAM,MAAM,gBAAgB;EAC5B,IAAI,CAAC,KACH,OAAO,0BAA0B,OAAO,gBAAgB,OAAO,KAAK,eAAe,EAAE,KAAK,IAAI;EAGhG,OADc,IAAI,QAAQ,KAAK,KACxB,IACH,WAAW,MAAM,eAAe,IAAI,MAAM,KAC1C,aAAa,MAAM,mBAAmB,IAAI,MAAM;CACtD;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"structured_data.mjs","names":[],"sources":["../../../src/batteries/tools/structured_data/index.ts"],"sourcesContent":["/**\n * Pre-constructed tools for transforming arrays and objects into tables and tabular text.\n *\n * @module @nhtio/adk/batteries/tools/structured_data\n *\n * @remarks\n * Pre-constructed bundled tools for the `structured_data` category. Import individually, the whole\n * category, or import every tool via `@nhtio/adk/batteries`.\n */\n\nimport { Tool } from '@nhtio/adk/common'\nimport { validator } from '@nhtio/validation'\nimport { isError, isObject } from '@nhtio/adk/guards'\n\nfunction csvEscape(value: unknown): string {\n const str = value === null || value === undefined ? '' : String(value)\n if (str.includes(',') || str.includes('\"') || str.includes('\\n') || str.includes('\\r')) {\n return '\"' + str.replace(/\"/g, '\"\"') + '\"'\n }\n return str\n}\n\nfunction tsvEscape(value: unknown): string {\n const str = value === null || value === undefined ? '' : String(value)\n return str.replace(/\\t/g, ' ').replace(/\\r?\\n/g, ' ')\n}\n\nfunction mdEscape(value: unknown): string {\n return String(value === null || value === undefined ? '' : value)\n .replace(/\\|/g, '\\\\|')\n .replace(/\\r?\\n/g, ' ')\n}\n\n/**\n * Convert a JSON array of objects into a formatted table.\n *\n * @remarks\n * Supports `markdown`, `csv`, and `tsv` output. Columns default to the keys of the first row;\n * supply `columns` to control which keys appear and in what order.\n */\nexport const formatTableTool = new Tool({\n name: 'format_table',\n description:\n 'Convert a JSON array of objects into a formatted table. Supports Markdown, CSV, and TSV output.',\n inputSchema: validator.object({\n data: validator.string().required().description('JSON array of objects as a string'),\n format: validator\n .string()\n .valid('markdown', 'csv', 'tsv')\n .required()\n .description('Output format'),\n columns: validator\n .array()\n .items(validator.string())\n .optional()\n .description(\n 'Column keys to include, in order. If omitted, all keys from the first row are used.'\n ),\n }),\n handler: async (args) => {\n const {\n data,\n format,\n columns: explicitColumns,\n } = args as {\n data: string\n format: 'markdown' | 'csv' | 'tsv'\n columns?: string[]\n }\n\n let rows: unknown[]\n try {\n rows = JSON.parse(data)\n } catch {\n return 'Error: Invalid JSON input.'\n }\n\n if (!Array.isArray(rows)) return 'Error: Input must be a JSON array.'\n if (rows.length === 0) return 'Empty array — no data to display.'\n\n // Columns default to the first row's keys, but only an object row has keys. If columns aren't\n // given and the first row isn't an object, there's nothing to tabulate — error clearly rather\n // than throwing on `Object.keys(null)`.\n if (!explicitColumns && !isObject(rows[0])) {\n return 'Error: Cannot infer columns — the first row is not an object. Provide \"columns\", or pass an array of objects.'\n }\n const columns = explicitColumns ?? Object.keys(rows[0] as Record<string, unknown>)\n\n // Read a cell safely: a null/primitive row has no properties, so it yields empty cells rather\n // than throwing on `row[col]`.\n const cell = (row: unknown, col: string): unknown =>\n isObject(row) ? (row as Record<string, unknown>)[col] : undefined\n\n if (format === 'csv') {\n const lines = [columns.map(csvEscape).join(',')]\n for (const row of rows) {\n lines.push(columns.map((col) => csvEscape(cell(row, col))).join(','))\n }\n return lines.join('\\n')\n }\n\n if (format === 'tsv') {\n const lines = [columns.map(tsvEscape).join('\\t')]\n for (const row of rows) {\n lines.push(columns.map((col) => tsvEscape(cell(row, col))).join('\\t'))\n }\n return lines.join('\\n')\n }\n\n const header = '| ' + columns.map(mdEscape).join(' | ') + ' |'\n const separator = '| ' + columns.map(() => '---').join(' | ') + ' |'\n const dataRows = rows.map((row) => {\n return '| ' + columns.map((col) => mdEscape(cell(row, col))).join(' | ') + ' |'\n })\n return [header, separator, ...dataRows].join('\\n')\n },\n})\n\n/**\n * Pretty-print or minify a JSON string.\n *\n * @remarks\n * Validates the input as JSON, then re-serialises it with the requested indentation. `indent` is\n * clamped to the range [0, 8]; `0` produces minified output.\n */\nexport const jsonFormatTool = new Tool({\n name: 'json_format',\n description: 'Pretty-print or minify a JSON string. Validates JSON and normalises whitespace.',\n inputSchema: validator.object({\n data: validator.string().required().description('JSON string to format'),\n indent: validator\n .number()\n .default(2)\n .description('Indentation spaces (0 = minify, default: 2). Max: 8.'),\n }),\n handler: async (args) => {\n const { data, indent } = args as { data: string; indent: number }\n try {\n const parsed = JSON.parse(data)\n return JSON.stringify(parsed, null, Math.max(0, Math.min(8, Math.floor(indent))))\n } catch (err) {\n return `Error: Invalid JSON — ${isError(err) ? err.message : String(err)}`\n }\n },\n})\n\nconst FORMAT_PATTERNS: Record<string, { pattern: RegExp; label: string }> = {\n email: {\n pattern: /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/,\n label: 'email address',\n },\n uuid: {\n pattern: /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,\n label: 'UUID (v1–v5)',\n },\n ipv4: {\n pattern: /^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$/,\n label: 'IPv4 address',\n },\n iso_date: {\n pattern: /^\\d{4}-\\d{2}-\\d{2}$/,\n label: 'ISO 8601 date (YYYY-MM-DD)',\n },\n iso_datetime: {\n pattern: /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?(Z|[+-]\\d{2}:\\d{2})?$/,\n label: 'ISO 8601 datetime',\n },\n hex_color: {\n pattern: /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/,\n label: 'CSS hex color',\n },\n phone_e164: {\n pattern: /^\\+[1-9]\\d{1,14}$/,\n label: 'E.164 phone number',\n },\n semver: {\n pattern: /^\\d+\\.\\d+\\.\\d+(-[0-9A-Za-z-.]+)?(\\+[0-9A-Za-z-.]+)?$/,\n label: 'Semantic Version (SemVer)',\n },\n integer: {\n pattern: /^-?\\d+$/,\n label: 'integer',\n },\n decimal: {\n pattern: /^-?\\d+(\\.\\d+)?$/,\n label: 'decimal number',\n },\n alphanumeric: {\n pattern: /^[a-zA-Z0-9]+$/,\n label: 'alphanumeric string',\n },\n slug: {\n pattern: /^[a-z0-9]+(-[a-z0-9]+)*$/,\n label: 'URL slug',\n },\n hex: {\n pattern: /^(0x)?[0-9a-fA-F]+$/,\n label: 'hexadecimal string',\n },\n base64: {\n pattern: /^[A-Za-z0-9+/]*={0,2}$/,\n label: 'base64-encoded string',\n },\n}\n\n/**\n * Check whether a string matches a known format.\n *\n * @remarks\n * Supported formats: `email`, `uuid` (v1–v5), `ipv4`, `iso_date`, `iso_datetime`, `hex_color`,\n * `phone_e164`, `semver`, `integer`, `decimal`, `alphanumeric`, `slug`, `hex`, `base64`.\n */\nexport const validateFormatTool = new Tool({\n name: 'validate_format',\n description:\n 'Check whether a string matches a known format (email, UUID, ISO date, hex colour, phone number, semver, slug, etc.).',\n inputSchema: validator.object({\n value: validator.string().required().description('The string to validate'),\n format: validator\n .string()\n .valid(...Object.keys(FORMAT_PATTERNS))\n .required()\n .description(\n `Format to validate against. One of: ${Object.keys(FORMAT_PATTERNS).join(', ')}`\n ),\n }),\n handler: async (args) => {\n const { value, format } = args as { value: string; format: string }\n const def = FORMAT_PATTERNS[format]\n if (!def) {\n return `Error: Unknown format \"${format}\". Supported: ${Object.keys(FORMAT_PATTERNS).join(', ')}`\n }\n const valid = def.pattern.test(value)\n return valid\n ? `Valid: \"${value}\" is a valid ${def.label}.`\n : `Invalid: \"${value}\" is not a valid ${def.label}.`\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;AAcA,SAAS,UAAU,OAAwB;CACzC,MAAM,MAAM,UAAU,QAAQ,UAAU,KAAA,IAAY,KAAK,OAAO,KAAK;CACrE,IAAI,IAAI,SAAS,GAAG,KAAK,IAAI,SAAS,IAAG,KAAK,IAAI,SAAS,IAAI,KAAK,IAAI,SAAS,IAAI,GACnF,OAAO,OAAM,IAAI,QAAQ,MAAM,MAAI,IAAI;CAEzC,OAAO;AACT;AAEA,SAAS,UAAU,OAAwB;CAEzC,QADY,UAAU,QAAQ,UAAU,KAAA,IAAY,KAAK,OAAO,KAAK,GAC1D,QAAQ,OAAO,GAAG,EAAE,QAAQ,UAAU,GAAG;AACtD;AAEA,SAAS,SAAS,OAAwB;CACxC,OAAO,OAAO,UAAU,QAAQ,UAAU,KAAA,IAAY,KAAK,KAAK,EAC7D,QAAQ,OAAO,KAAK,EACpB,QAAQ,UAAU,GAAG;AAC1B;;;;;;;;AASA,IAAa,kBAAkB,IAAI,KAAK;CACtC,MAAM;CACN,aACE;CACF,aAAa,UAAU,OAAO;EAC5B,MAAM,UAAU,OAAO,EAAE,SAAS,EAAE,YAAY,mCAAmC;EACnF,QAAQ,UACL,OAAO,EACP,MAAM,YAAY,OAAO,KAAK,EAC9B,SAAS,EACT,YAAY,eAAe;EAC9B,SAAS,UACN,MAAM,EACN,MAAM,UAAU,OAAO,CAAC,EACxB,SAAS,EACT,YACC,qFACF;CACJ,CAAC;CACD,SAAS,OAAO,SAAS;EACvB,MAAM,EACJ,MACA,QACA,SAAS,oBACP;EAMJ,IAAI;EACJ,IAAI;GACF,OAAO,KAAK,MAAM,IAAI;EACxB,QAAQ;GACN,OAAO;EACT;EAEA,IAAI,CAAC,MAAM,QAAQ,IAAI,GAAG,OAA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OAAO,WAAW;EAC1B,MAAM,MAAM,gBAAgB;EAC5B,IAAI,CAAC,KACH,OAAO,0BAA0B,OAAO,gBAAgB,OAAO,KAAK,eAAe,EAAE,KAAK,IAAI;EAGhG,OADc,IAAI,QAAQ,KAAK,KACxB,IACH,WAAW,MAAM,eAAe,IAAI,MAAM,KAC1C,aAAa,MAAM,mBAAmB,IAAI,MAAM;CACtD;AACF,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
require("../../chunk-Ble4zEEl.js");
|
|
3
|
-
const require_tool = require("../../tool-
|
|
4
|
-
require("../../common-
|
|
5
|
-
const require_spooled_markdown_artifact = require("../../spooled_markdown_artifact-
|
|
3
|
+
const require_tool = require("../../tool-D5WGVIcI.js");
|
|
4
|
+
require("../../common-DZl3ADJs.js");
|
|
5
|
+
const require_spooled_markdown_artifact = require("../../spooled_markdown_artifact-ClX72lek.js");
|
|
6
6
|
let _nhtio_validation = require("@nhtio/validation");
|
|
7
7
|
//#region src/batteries/tools/text_analysis/index.ts
|
|
8
8
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as Tool } from "../../tool-
|
|
2
|
-
import "../../common-
|
|
3
|
-
import { n as SpooledJsonArtifact } from "../../spooled_markdown_artifact-
|
|
1
|
+
import { t as Tool } from "../../tool-wMYMVl60.mjs";
|
|
2
|
+
import "../../common-DYDUi99O.mjs";
|
|
3
|
+
import { n as SpooledJsonArtifact } from "../../spooled_markdown_artifact-wkrBF3oX.mjs";
|
|
4
4
|
import { validator } from "@nhtio/validation";
|
|
5
5
|
//#region src/batteries/tools/text_analysis/index.ts
|
|
6
6
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
require("../../chunk-Ble4zEEl.js");
|
|
3
|
-
const require_tool = require("../../tool-
|
|
4
|
-
require("../../common-
|
|
3
|
+
const require_tool = require("../../tool-D5WGVIcI.js");
|
|
4
|
+
require("../../common-DZl3ADJs.js");
|
|
5
5
|
let _nhtio_validation = require("@nhtio/validation");
|
|
6
6
|
let diff = require("diff");
|
|
7
7
|
let fastest_levenshtein = require("fastest-levenshtein");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as Tool } from "../../tool-
|
|
2
|
-
import "../../common-
|
|
1
|
+
import { t as Tool } from "../../tool-wMYMVl60.mjs";
|
|
2
|
+
import "../../common-DYDUi99O.mjs";
|
|
3
3
|
import { validator } from "@nhtio/validation";
|
|
4
4
|
import { diffLines, diffWords } from "diff";
|
|
5
5
|
import { distance } from "fastest-levenshtein";
|
package/batteries/tools/time.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
require("../../chunk-Ble4zEEl.js");
|
|
3
|
-
const require_tool = require("../../tool-
|
|
4
|
-
require("../../common-
|
|
3
|
+
const require_tool = require("../../tool-D5WGVIcI.js");
|
|
4
|
+
require("../../common-DZl3ADJs.js");
|
|
5
5
|
let _nhtio_validation = require("@nhtio/validation");
|
|
6
6
|
let luxon = require("luxon");
|
|
7
7
|
//#region src/batteries/tools/time/index.ts
|
package/batteries/tools/time.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as Tool } from "../../tool-
|
|
2
|
-
import "../../common-
|
|
1
|
+
import { t as Tool } from "../../tool-wMYMVl60.mjs";
|
|
2
|
+
import "../../common-DYDUi99O.mjs";
|
|
3
3
|
import { validator } from "@nhtio/validation";
|
|
4
4
|
import { DateTime, IANAZone } from "luxon";
|
|
5
5
|
//#region src/batteries/tools/time/index.ts
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
require("../../chunk-Ble4zEEl.js");
|
|
3
|
-
const require_tool = require("../../tool-
|
|
4
|
-
require("../../common-
|
|
3
|
+
const require_tool = require("../../tool-D5WGVIcI.js");
|
|
4
|
+
require("../../common-DZl3ADJs.js");
|
|
5
|
+
const require_lib_helpers_bignum = require("../../lib/helpers/bignum.cjs");
|
|
5
6
|
let _nhtio_validation = require("@nhtio/validation");
|
|
6
7
|
//#region src/batteries/tools/unit_conversion/index.ts
|
|
7
8
|
/**
|
|
@@ -425,15 +426,17 @@ var convertUnitTool = new require_tool.Tool({
|
|
|
425
426
|
inputSchema: _nhtio_validation.validator.object({
|
|
426
427
|
value: _nhtio_validation.validator.number().required().description("Numeric value to convert"),
|
|
427
428
|
from: _nhtio_validation.validator.string().required().description(`Source unit key. Supported keys: ${ALL_UNIT_KEYS}`),
|
|
428
|
-
to: _nhtio_validation.validator.string().required().description("Target unit key (must be in the same category as source)")
|
|
429
|
+
to: _nhtio_validation.validator.string().required().description("Target unit key (must be in the same category as source)"),
|
|
430
|
+
precision: _nhtio_validation.validator.number().default(8).description(`Significant digits in the result (default: 8).`)
|
|
429
431
|
}),
|
|
430
432
|
handler: async (args) => {
|
|
431
|
-
const { value, from, to } = args;
|
|
433
|
+
const { value, from, to, precision } = args;
|
|
432
434
|
if (TEMP_UNITS.has(from) || TEMP_UNITS.has(to)) {
|
|
433
435
|
if (!TEMP_UNITS.has(from)) return `Error: "${from}" is not a temperature unit. Use C, F, or K.`;
|
|
434
436
|
if (!TEMP_UNITS.has(to)) return `Error: "${to}" is not a temperature unit. Use C, F, or K.`;
|
|
435
|
-
const
|
|
436
|
-
|
|
437
|
+
const kelvin = toKelvin(value, from);
|
|
438
|
+
if (kelvin < -1e-9) return `Error: ${value}${TEMP_LABELS[from]} is below absolute zero (0 K); not a physical temperature.`;
|
|
439
|
+
const rounded = require_lib_helpers_bignum.formatBig(fromKelvin(kelvin, to), precision);
|
|
437
440
|
return `${value}${TEMP_LABELS[from]} = ${rounded}${TEMP_LABELS[to]}`;
|
|
438
441
|
}
|
|
439
442
|
const fromDef = UNITS[from];
|
|
@@ -441,8 +444,7 @@ var convertUnitTool = new require_tool.Tool({
|
|
|
441
444
|
if (!fromDef) return `Error: Unknown unit "${from}". Supported: ${ALL_UNIT_KEYS}`;
|
|
442
445
|
if (!toDef) return `Error: Unknown unit "${to}". Supported: ${ALL_UNIT_KEYS}`;
|
|
443
446
|
if (fromDef.category !== toDef.category) return `Error: Cannot convert "${from}" (${fromDef.category}) to "${to}" (${toDef.category}) — different categories.`;
|
|
444
|
-
const
|
|
445
|
-
const rounded = Number.parseFloat(result.toPrecision(10));
|
|
447
|
+
const rounded = require_lib_helpers_bignum.formatBig(require_lib_helpers_bignum.bigScale(value, fromDef.factor, toDef.factor), precision);
|
|
446
448
|
return `${value} ${fromDef.label} = ${rounded} ${toDef.label}`;
|
|
447
449
|
}
|
|
448
450
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unit_conversion.cjs","names":[],"sources":["../../../src/batteries/tools/unit_conversion/index.ts"],"sourcesContent":["/**\n * Pre-constructed tools for converting values across common measurement units.\n *\n * @module @nhtio/adk/batteries/tools/unit_conversion\n *\n * @remarks\n * Pre-constructed bundled tools for the `unit_conversion` category. Import individually, the whole\n * category, or import every tool via `@nhtio/adk/batteries`.\n */\n\nimport { Tool } from '@nhtio/adk/common'\nimport { validator } from '@nhtio/validation'\n\ntype UnitDef = { category: string; factor: number; label: string }\n\nconst UNITS: Record<string, UnitDef> = {\n // Length (base: metre)\n m: { category: 'length', factor: 1, label: 'metres' },\n km: { category: 'length', factor: 1000, label: 'kilometres' },\n cm: { category: 'length', factor: 0.01, label: 'centimetres' },\n mm: { category: 'length', factor: 0.001, label: 'millimetres' },\n mi: { category: 'length', factor: 1609.344, label: 'miles' },\n ft: { category: 'length', factor: 0.3048, label: 'feet' },\n in: { category: 'length', factor: 0.0254, label: 'inches' },\n yd: { category: 'length', factor: 0.9144, label: 'yards' },\n nmi: { category: 'length', factor: 1852, label: 'nautical miles' },\n\n // Mass (base: gram)\n g: { category: 'mass', factor: 1, label: 'grams' },\n kg: { category: 'mass', factor: 1000, label: 'kilograms' },\n mg: { category: 'mass', factor: 0.001, label: 'milligrams' },\n t: { category: 'mass', factor: 1_000_000, label: 'metric tons' },\n lb: { category: 'mass', factor: 453.59237, label: 'pounds' },\n oz: { category: 'mass', factor: 28.349523125, label: 'ounces' },\n st: { category: 'mass', factor: 6350.29318, label: 'stone' },\n\n // Volume (base: litre)\n L: { category: 'volume', factor: 1, label: 'litres' },\n mL: { category: 'volume', factor: 0.001, label: 'millilitres' },\n m3: { category: 'volume', factor: 1000, label: 'cubic metres' },\n cm3: { category: 'volume', factor: 0.001, label: 'cubic centimetres' },\n gal: { category: 'volume', factor: 3.785411784, label: 'US gallons' },\n qt: { category: 'volume', factor: 0.946352946, label: 'US quarts' },\n pt: { category: 'volume', factor: 0.473176473, label: 'US pints' },\n cup: { category: 'volume', factor: 0.2365882365, label: 'US cups' },\n floz: { category: 'volume', factor: 0.029573529562, label: 'US fluid ounces' },\n tbsp: { category: 'volume', factor: 0.014786764781, label: 'tablespoons' },\n tsp: { category: 'volume', factor: 0.0049289215938, label: 'teaspoons' },\n\n // Speed (base: m/s)\n m_s: { category: 'speed', factor: 1, label: 'm/s' },\n km_h: { category: 'speed', factor: 1 / 3.6, label: 'km/h' },\n mph: { category: 'speed', factor: 0.44704, label: 'mph' },\n kn: { category: 'speed', factor: 0.514444, label: 'knots' },\n ft_s: { category: 'speed', factor: 0.3048, label: 'ft/s' },\n\n // Area (base: m²)\n m2: { category: 'area', factor: 1, label: 'm²' },\n km2: { category: 'area', factor: 1_000_000, label: 'km²' },\n cm2: { category: 'area', factor: 0.0001, label: 'cm²' },\n mm2: { category: 'area', factor: 0.000001, label: 'mm²' },\n ft2: { category: 'area', factor: 0.09290304, label: 'sq ft' },\n in2: { category: 'area', factor: 0.00064516, label: 'sq in' },\n yd2: { category: 'area', factor: 0.83612736, label: 'sq yd' },\n acre: { category: 'area', factor: 4046.8564224, label: 'acres' },\n ha: { category: 'area', factor: 10_000, label: 'hectares' },\n\n // Data storage (base: bit)\n bit: { category: 'data', factor: 1, label: 'bits' },\n B: { category: 'data', factor: 8, label: 'bytes' },\n KB: { category: 'data', factor: 8_000, label: 'kilobytes' },\n MB: { category: 'data', factor: 8_000_000, label: 'megabytes' },\n GB: { category: 'data', factor: 8_000_000_000, label: 'gigabytes' },\n TB: { category: 'data', factor: 8_000_000_000_000, label: 'terabytes' },\n KiB: { category: 'data', factor: 8 * 1024, label: 'kibibytes' },\n MiB: { category: 'data', factor: 8 * 1024 ** 2, label: 'mebibytes' },\n GiB: { category: 'data', factor: 8 * 1024 ** 3, label: 'gibibytes' },\n TiB: { category: 'data', factor: 8 * 1024 ** 4, label: 'tebibytes' },\n\n // Time (base: second)\n ms: { category: 'time', factor: 0.001, label: 'milliseconds' },\n s: { category: 'time', factor: 1, label: 'seconds' },\n min: { category: 'time', factor: 60, label: 'minutes' },\n h: { category: 'time', factor: 3600, label: 'hours' },\n d: { category: 'time', factor: 86400, label: 'days' },\n wk: { category: 'time', factor: 604800, label: 'weeks' },\n\n // Energy (base: joule)\n J: { category: 'energy', factor: 1, label: 'joules' },\n kJ: { category: 'energy', factor: 1000, label: 'kilojoules' },\n cal: { category: 'energy', factor: 4.184, label: 'calories' },\n kcal: { category: 'energy', factor: 4184, label: 'kilocalories' },\n Wh: { category: 'energy', factor: 3600, label: 'watt-hours' },\n kWh: { category: 'energy', factor: 3_600_000, label: 'kilowatt-hours' },\n BTU: { category: 'energy', factor: 1055.05585, label: 'BTU' },\n\n // Pressure (base: pascal)\n Pa: { category: 'pressure', factor: 1, label: 'pascals' },\n kPa: { category: 'pressure', factor: 1000, label: 'kilopascals' },\n MPa: { category: 'pressure', factor: 1_000_000, label: 'megapascals' },\n bar: { category: 'pressure', factor: 100_000, label: 'bar' },\n psi: { category: 'pressure', factor: 6894.757, label: 'psi' },\n atm: { category: 'pressure', factor: 101325, label: 'atm' },\n mmHg: { category: 'pressure', factor: 133.322, label: 'mmHg' },\n\n // Angle (base: radian)\n rad: { category: 'angle', factor: 1, label: 'radians' },\n deg: { category: 'angle', factor: Math.PI / 180, label: 'degrees' },\n grad: { category: 'angle', factor: Math.PI / 200, label: 'gradians' },\n}\n\nconst TEMP_UNITS = new Set(['C', 'F', 'K'])\ntype TempUnit = 'C' | 'F' | 'K'\nconst TEMP_LABELS: Record<TempUnit, string> = { C: '°C', F: '°F', K: 'K' }\n\nfunction toKelvin(value: number, unit: TempUnit): number {\n if (unit === 'C') return value + 273.15\n if (unit === 'F') return (value - 32) * (5 / 9) + 273.15\n return value\n}\n\nfunction fromKelvin(kelvin: number, unit: TempUnit): number {\n if (unit === 'C') return kelvin - 273.15\n if (unit === 'F') return (kelvin - 273.15) * (9 / 5) + 32\n return kelvin\n}\n\nconst ALL_UNIT_KEYS = [...Object.keys(UNITS), 'C', 'F', 'K'].join(', ')\n\n/**\n * Convert a numeric value between units of the same physical category.\n *\n * @remarks\n * Supported categories: length, mass, volume, temperature, speed, area, data, time, energy,\n * pressure, angle. Uses static conversion tables — no external data required. Temperature is\n * handled specially via a Kelvin intermediate to preserve precision across `C`/`F`/`K`.\n */\nexport const convertUnitTool = new Tool({\n name: 'convert_unit',\n description:\n 'Convert a numeric value between units of the same category (length, mass, volume, temperature, speed, area, data, time, energy, pressure, angle). Uses static lookup tables — no external data required.',\n inputSchema: validator.object({\n value: validator.number().required().description('Numeric value to convert'),\n from: validator\n .string()\n .required()\n .description(`Source unit key. Supported keys: ${ALL_UNIT_KEYS}`),\n to: validator\n .string()\n .required()\n .description('Target unit key (must be in the same category as source)'),\n }),\n handler: async (args) => {\n const { value, from, to } = args as { value: number; from: string; to: string }\n\n if (TEMP_UNITS.has(from) || TEMP_UNITS.has(to)) {\n if (!TEMP_UNITS.has(from))\n return `Error: \"${from}\" is not a temperature unit. Use C, F, or K.`\n if (!TEMP_UNITS.has(to)) return `Error: \"${to}\" is not a temperature unit. Use C, F, or K.`\n const result = fromKelvin(toKelvin(value, from as TempUnit), to as TempUnit)\n const rounded = Number.parseFloat(result.toPrecision(10))\n return `${value}${TEMP_LABELS[from as TempUnit]} = ${rounded}${TEMP_LABELS[to as TempUnit]}`\n }\n\n const fromDef = UNITS[from]\n const toDef = UNITS[to]\n if (!fromDef) return `Error: Unknown unit \"${from}\". Supported: ${ALL_UNIT_KEYS}`\n if (!toDef) return `Error: Unknown unit \"${to}\". Supported: ${ALL_UNIT_KEYS}`\n if (fromDef.category !== toDef.category) {\n return `Error: Cannot convert \"${from}\" (${fromDef.category}) to \"${to}\" (${toDef.category}) — different categories.`\n }\n\n const inBase = value * fromDef.factor\n const result = inBase / toDef.factor\n const rounded = Number.parseFloat(result.toPrecision(10))\n return `${value} ${fromDef.label} = ${rounded} ${toDef.label}`\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;AAeA,IAAM,QAAiC;CAErC,GAAG;EAAE,UAAU;EAAU,QAAQ;EAAG,OAAO;CAAS;CACpD,IAAI;EAAE,UAAU;EAAU,QAAQ;EAAM,OAAO;CAAa;CAC5D,IAAI;EAAE,UAAU;EAAU,QAAQ;EAAM,OAAO;CAAc;CAC7D,IAAI;EAAE,UAAU;EAAU,QAAQ;EAAO,OAAO;CAAc;CAC9D,IAAI;EAAE,UAAU;EAAU,QAAQ;EAAU,OAAO;CAAQ;CAC3D,IAAI;EAAE,UAAU;EAAU,QAAQ;EAAQ,OAAO;CAAO;CACxD,IAAI;EAAE,UAAU;EAAU,QAAQ;EAAQ,OAAO;CAAS;CAC1D,IAAI;EAAE,UAAU;EAAU,QAAQ;EAAQ,OAAO;CAAQ;CACzD,KAAK;EAAE,UAAU;EAAU,QAAQ;EAAM,OAAO;CAAiB;CAGjE,GAAG;EAAE,UAAU;EAAQ,QAAQ;EAAG,OAAO;CAAQ;CACjD,IAAI;EAAE,UAAU;EAAQ,QAAQ;EAAM,OAAO;CAAY;CACzD,IAAI;EAAE,UAAU;EAAQ,QAAQ;EAAO,OAAO;CAAa;CAC3D,GAAG;EAAE,UAAU;EAAQ,QAAQ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AO,wBAAwB,GAAG,gBAAgB;EAC9D,IAAI,QAAQ,aAAa,MAAM,UAC7B,OAAO,0BAA0B,KAAK,KAAK,QAAQ,SAAS,QAAQ,GAAG,KAAK,MAAM,SAAS;EAI7F,MAAM,SADS,QAAQ,QAAQ,SACP,MAAM;EAC9B,MAAM,UAAU,OAAO,WAAW,OAAO,YAAY,EAAE,CAAC;EACxD,OAAO,GAAG,MAAM,GAAG,QAAQ,MAAM,KAAK,QAAQ,GAAG,MAAM;CACzD;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"unit_conversion.cjs","names":[],"sources":["../../../src/batteries/tools/unit_conversion/index.ts"],"sourcesContent":["/**\n * Pre-constructed tools for converting values across common measurement units.\n *\n * @module @nhtio/adk/batteries/tools/unit_conversion\n *\n * @remarks\n * Pre-constructed bundled tools for the `unit_conversion` category. Import individually, the whole\n * category, or import every tool via `@nhtio/adk/batteries`.\n */\n\nimport { Tool } from '@nhtio/adk/common'\nimport { validator } from '@nhtio/validation'\nimport { bigScale, formatBig, DEFAULT_PRECISION } from '@nhtio/adk/lib/helpers/bignum'\n\ntype UnitDef = { category: string; factor: number; label: string }\n\nconst UNITS: Record<string, UnitDef> = {\n // Length (base: metre)\n m: { category: 'length', factor: 1, label: 'metres' },\n km: { category: 'length', factor: 1000, label: 'kilometres' },\n cm: { category: 'length', factor: 0.01, label: 'centimetres' },\n mm: { category: 'length', factor: 0.001, label: 'millimetres' },\n mi: { category: 'length', factor: 1609.344, label: 'miles' },\n ft: { category: 'length', factor: 0.3048, label: 'feet' },\n in: { category: 'length', factor: 0.0254, label: 'inches' },\n yd: { category: 'length', factor: 0.9144, label: 'yards' },\n nmi: { category: 'length', factor: 1852, label: 'nautical miles' },\n\n // Mass (base: gram)\n g: { category: 'mass', factor: 1, label: 'grams' },\n kg: { category: 'mass', factor: 1000, label: 'kilograms' },\n mg: { category: 'mass', factor: 0.001, label: 'milligrams' },\n t: { category: 'mass', factor: 1_000_000, label: 'metric tons' },\n lb: { category: 'mass', factor: 453.59237, label: 'pounds' },\n oz: { category: 'mass', factor: 28.349523125, label: 'ounces' },\n st: { category: 'mass', factor: 6350.29318, label: 'stone' },\n\n // Volume (base: litre)\n L: { category: 'volume', factor: 1, label: 'litres' },\n mL: { category: 'volume', factor: 0.001, label: 'millilitres' },\n m3: { category: 'volume', factor: 1000, label: 'cubic metres' },\n cm3: { category: 'volume', factor: 0.001, label: 'cubic centimetres' },\n gal: { category: 'volume', factor: 3.785411784, label: 'US gallons' },\n qt: { category: 'volume', factor: 0.946352946, label: 'US quarts' },\n pt: { category: 'volume', factor: 0.473176473, label: 'US pints' },\n cup: { category: 'volume', factor: 0.2365882365, label: 'US cups' },\n floz: { category: 'volume', factor: 0.029573529562, label: 'US fluid ounces' },\n tbsp: { category: 'volume', factor: 0.014786764781, label: 'tablespoons' },\n tsp: { category: 'volume', factor: 0.0049289215938, label: 'teaspoons' },\n\n // Speed (base: m/s)\n m_s: { category: 'speed', factor: 1, label: 'm/s' },\n km_h: { category: 'speed', factor: 1 / 3.6, label: 'km/h' },\n mph: { category: 'speed', factor: 0.44704, label: 'mph' },\n kn: { category: 'speed', factor: 0.514444, label: 'knots' },\n ft_s: { category: 'speed', factor: 0.3048, label: 'ft/s' },\n\n // Area (base: m²)\n m2: { category: 'area', factor: 1, label: 'm²' },\n km2: { category: 'area', factor: 1_000_000, label: 'km²' },\n cm2: { category: 'area', factor: 0.0001, label: 'cm²' },\n mm2: { category: 'area', factor: 0.000001, label: 'mm²' },\n ft2: { category: 'area', factor: 0.09290304, label: 'sq ft' },\n in2: { category: 'area', factor: 0.00064516, label: 'sq in' },\n yd2: { category: 'area', factor: 0.83612736, label: 'sq yd' },\n acre: { category: 'area', factor: 4046.8564224, label: 'acres' },\n ha: { category: 'area', factor: 10_000, label: 'hectares' },\n\n // Data storage (base: bit)\n bit: { category: 'data', factor: 1, label: 'bits' },\n B: { category: 'data', factor: 8, label: 'bytes' },\n KB: { category: 'data', factor: 8_000, label: 'kilobytes' },\n MB: { category: 'data', factor: 8_000_000, label: 'megabytes' },\n GB: { category: 'data', factor: 8_000_000_000, label: 'gigabytes' },\n TB: { category: 'data', factor: 8_000_000_000_000, label: 'terabytes' },\n KiB: { category: 'data', factor: 8 * 1024, label: 'kibibytes' },\n MiB: { category: 'data', factor: 8 * 1024 ** 2, label: 'mebibytes' },\n GiB: { category: 'data', factor: 8 * 1024 ** 3, label: 'gibibytes' },\n TiB: { category: 'data', factor: 8 * 1024 ** 4, label: 'tebibytes' },\n\n // Time (base: second)\n ms: { category: 'time', factor: 0.001, label: 'milliseconds' },\n s: { category: 'time', factor: 1, label: 'seconds' },\n min: { category: 'time', factor: 60, label: 'minutes' },\n h: { category: 'time', factor: 3600, label: 'hours' },\n d: { category: 'time', factor: 86400, label: 'days' },\n wk: { category: 'time', factor: 604800, label: 'weeks' },\n\n // Energy (base: joule)\n J: { category: 'energy', factor: 1, label: 'joules' },\n kJ: { category: 'energy', factor: 1000, label: 'kilojoules' },\n cal: { category: 'energy', factor: 4.184, label: 'calories' },\n kcal: { category: 'energy', factor: 4184, label: 'kilocalories' },\n Wh: { category: 'energy', factor: 3600, label: 'watt-hours' },\n kWh: { category: 'energy', factor: 3_600_000, label: 'kilowatt-hours' },\n BTU: { category: 'energy', factor: 1055.05585, label: 'BTU' },\n\n // Pressure (base: pascal)\n Pa: { category: 'pressure', factor: 1, label: 'pascals' },\n kPa: { category: 'pressure', factor: 1000, label: 'kilopascals' },\n MPa: { category: 'pressure', factor: 1_000_000, label: 'megapascals' },\n bar: { category: 'pressure', factor: 100_000, label: 'bar' },\n psi: { category: 'pressure', factor: 6894.757, label: 'psi' },\n atm: { category: 'pressure', factor: 101325, label: 'atm' },\n mmHg: { category: 'pressure', factor: 133.322, label: 'mmHg' },\n\n // Angle (base: radian)\n rad: { category: 'angle', factor: 1, label: 'radians' },\n deg: { category: 'angle', factor: Math.PI / 180, label: 'degrees' },\n grad: { category: 'angle', factor: Math.PI / 200, label: 'gradians' },\n}\n\nconst TEMP_UNITS = new Set(['C', 'F', 'K'])\ntype TempUnit = 'C' | 'F' | 'K'\nconst TEMP_LABELS: Record<TempUnit, string> = { C: '°C', F: '°F', K: 'K' }\n\nfunction toKelvin(value: number, unit: TempUnit): number {\n if (unit === 'C') return value + 273.15\n if (unit === 'F') return (value - 32) * (5 / 9) + 273.15\n return value\n}\n\nfunction fromKelvin(kelvin: number, unit: TempUnit): number {\n if (unit === 'C') return kelvin - 273.15\n if (unit === 'F') return (kelvin - 273.15) * (9 / 5) + 32\n return kelvin\n}\n\nconst ALL_UNIT_KEYS = [...Object.keys(UNITS), 'C', 'F', 'K'].join(', ')\n\n/**\n * Convert a numeric value between units of the same physical category.\n *\n * @remarks\n * Supported categories: length, mass, volume, temperature, speed, area, data, time, energy,\n * pressure, angle. Uses static conversion tables — no external data required. Temperature is\n * handled specially via a Kelvin intermediate to preserve precision across `C`/`F`/`K`.\n */\nexport const convertUnitTool = new Tool({\n name: 'convert_unit',\n description:\n 'Convert a numeric value between units of the same category (length, mass, volume, temperature, speed, area, data, time, energy, pressure, angle). Uses static lookup tables — no external data required.',\n inputSchema: validator.object({\n value: validator.number().required().description('Numeric value to convert'),\n from: validator\n .string()\n .required()\n .description(`Source unit key. Supported keys: ${ALL_UNIT_KEYS}`),\n to: validator\n .string()\n .required()\n .description('Target unit key (must be in the same category as source)'),\n precision: validator\n .number()\n .default(DEFAULT_PRECISION)\n .description(`Significant digits in the result (default: ${DEFAULT_PRECISION}).`),\n }),\n handler: async (args) => {\n const { value, from, to, precision } = args as {\n value: number\n from: string\n to: string\n precision: number\n }\n\n if (TEMP_UNITS.has(from) || TEMP_UNITS.has(to)) {\n if (!TEMP_UNITS.has(from))\n return `Error: \"${from}\" is not a temperature unit. Use C, F, or K.`\n if (!TEMP_UNITS.has(to)) return `Error: \"${to}\" is not a temperature unit. Use C, F, or K.`\n // Temperatures are small bounded values (schema rejects |value| > 2^53), so float64 math\n // is exact enough; only the display precision changes.\n const kelvin = toKelvin(value, from as TempUnit)\n // Reject physically impossible temperatures below absolute zero (0 K) rather than silently\n // returning a nonsensical value like \"-1 K = -274.15 °C\". A tiny epsilon absorbs float noise.\n if (kelvin < -1e-9) {\n return `Error: ${value}${TEMP_LABELS[from as TempUnit]} is below absolute zero (0 K); not a physical temperature.`\n }\n const result = fromKelvin(kelvin, to as TempUnit)\n const rounded = formatBig(result, precision)\n return `${value}${TEMP_LABELS[from as TempUnit]} = ${rounded}${TEMP_LABELS[to as TempUnit]}`\n }\n\n const fromDef = UNITS[from]\n const toDef = UNITS[to]\n if (!fromDef) return `Error: Unknown unit \"${from}\". Supported: ${ALL_UNIT_KEYS}`\n if (!toDef) return `Error: Unknown unit \"${to}\". Supported: ${ALL_UNIT_KEYS}`\n if (fromDef.category !== toDef.category) {\n return `Error: Cannot convert \"${from}\" (${fromDef.category}) to \"${to}\" (${toDef.category}) — different categories.`\n }\n\n // `value * fromFactor / toFactor` in BigNumber so huge ratios (e.g. TB→bit) don't overflow to\n // Infinity, tiny ratios (e.g. in→km) don't underflow to 0, and safe integers keep full digits.\n const result = bigScale(value, fromDef.factor, toDef.factor)\n const rounded = formatBig(result, precision)\n return `${value} ${fromDef.label} = ${rounded} ${toDef.label}`\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,IAAM,QAAiC;CAErC,GAAG;EAAE,UAAU;EAAU,QAAQ;EAAG,OAAO;CAAS;CACpD,IAAI;EAAE,UAAU;EAAU,QAAQ;EAAM,OAAO;CAAa;CAC5D,IAAI;EAAE,UAAU;EAAU,QAAQ;EAAM,OAAO;CAAc;CAC7D,IAAI;EAAE,UAAU;EAAU,QAAQ;EAAO,OAAO;CAAc;CAC9D,IAAI;EAAE,UAAU;EAAU,QAAQ;EAAU,OAAO;CAAQ;CAC3D,IAAI;EAAE,UAAU;EAAU,QAAQ;EAAQ,OAAO;CAAO;CACxD,IAAI;EAAE,UAAU;EAAU,QAAQ;EAAQ,OAAO;CAAS;CAC1D,IAAI;EAAE,UAAU;EAA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AAK;GACzB,IAAI,CAAC,WAAW,IAAI,EAAE,GAAG,OAAO,WAAW,GAAG;GAG9C,MAAM,SAAS,SAAS,OAAO,IAAgB;GAG/C,IAAI,SAAS,OACX,OAAO,UAAU,QAAQ,YAAY,MAAkB;GAGzD,MAAM,UAAU,2BAAA,UADD,WAAW,QAAQ,EACR,GAAQ,SAAS;GAC3C,OAAO,GAAG,QAAQ,YAAY,MAAkB,KAAK,UAAU,YAAY;EAC7E;EAEA,MAAM,UAAU,MAAM;EACtB,MAAM,QAAQ,MAAM;EACpB,IAAI,CAAC,SAAS,OAAO,wBAAwB,KAAK,gBAAgB;EAClE,IAAI,CAAC,OAAO,OAAO,wBAAwB,GAAG,gBAAgB;EAC9D,IAAI,QAAQ,aAAa,MAAM,UAC7B,OAAO,0BAA0B,KAAK,KAAK,QAAQ,SAAS,QAAQ,GAAG,KAAK,MAAM,SAAS;EAM7F,MAAM,UAAU,2BAAA,UADD,2BAAA,SAAS,OAAO,QAAQ,QAAQ,MAAM,MAC3B,GAAQ,SAAS;EAC3C,OAAO,GAAG,MAAM,GAAG,QAAQ,MAAM,KAAK,QAAQ,GAAG,MAAM;CACzD;AACF,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { t as Tool } from "../../tool-
|
|
2
|
-
import "../../common-
|
|
1
|
+
import { t as Tool } from "../../tool-wMYMVl60.mjs";
|
|
2
|
+
import "../../common-DYDUi99O.mjs";
|
|
3
|
+
import { bigScale, formatBig } from "../../lib/helpers/bignum.mjs";
|
|
3
4
|
import { validator } from "@nhtio/validation";
|
|
4
5
|
//#region src/batteries/tools/unit_conversion/index.ts
|
|
5
6
|
/**
|
|
@@ -423,15 +424,17 @@ var convertUnitTool = new Tool({
|
|
|
423
424
|
inputSchema: validator.object({
|
|
424
425
|
value: validator.number().required().description("Numeric value to convert"),
|
|
425
426
|
from: validator.string().required().description(`Source unit key. Supported keys: ${ALL_UNIT_KEYS}`),
|
|
426
|
-
to: validator.string().required().description("Target unit key (must be in the same category as source)")
|
|
427
|
+
to: validator.string().required().description("Target unit key (must be in the same category as source)"),
|
|
428
|
+
precision: validator.number().default(8).description(`Significant digits in the result (default: 8).`)
|
|
427
429
|
}),
|
|
428
430
|
handler: async (args) => {
|
|
429
|
-
const { value, from, to } = args;
|
|
431
|
+
const { value, from, to, precision } = args;
|
|
430
432
|
if (TEMP_UNITS.has(from) || TEMP_UNITS.has(to)) {
|
|
431
433
|
if (!TEMP_UNITS.has(from)) return `Error: "${from}" is not a temperature unit. Use C, F, or K.`;
|
|
432
434
|
if (!TEMP_UNITS.has(to)) return `Error: "${to}" is not a temperature unit. Use C, F, or K.`;
|
|
433
|
-
const
|
|
434
|
-
|
|
435
|
+
const kelvin = toKelvin(value, from);
|
|
436
|
+
if (kelvin < -1e-9) return `Error: ${value}${TEMP_LABELS[from]} is below absolute zero (0 K); not a physical temperature.`;
|
|
437
|
+
const rounded = formatBig(fromKelvin(kelvin, to), precision);
|
|
435
438
|
return `${value}${TEMP_LABELS[from]} = ${rounded}${TEMP_LABELS[to]}`;
|
|
436
439
|
}
|
|
437
440
|
const fromDef = UNITS[from];
|
|
@@ -439,8 +442,7 @@ var convertUnitTool = new Tool({
|
|
|
439
442
|
if (!fromDef) return `Error: Unknown unit "${from}". Supported: ${ALL_UNIT_KEYS}`;
|
|
440
443
|
if (!toDef) return `Error: Unknown unit "${to}". Supported: ${ALL_UNIT_KEYS}`;
|
|
441
444
|
if (fromDef.category !== toDef.category) return `Error: Cannot convert "${from}" (${fromDef.category}) to "${to}" (${toDef.category}) — different categories.`;
|
|
442
|
-
const
|
|
443
|
-
const rounded = Number.parseFloat(result.toPrecision(10));
|
|
445
|
+
const rounded = formatBig(bigScale(value, fromDef.factor, toDef.factor), precision);
|
|
444
446
|
return `${value} ${fromDef.label} = ${rounded} ${toDef.label}`;
|
|
445
447
|
}
|
|
446
448
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unit_conversion.mjs","names":[],"sources":["../../../src/batteries/tools/unit_conversion/index.ts"],"sourcesContent":["/**\n * Pre-constructed tools for converting values across common measurement units.\n *\n * @module @nhtio/adk/batteries/tools/unit_conversion\n *\n * @remarks\n * Pre-constructed bundled tools for the `unit_conversion` category. Import individually, the whole\n * category, or import every tool via `@nhtio/adk/batteries`.\n */\n\nimport { Tool } from '@nhtio/adk/common'\nimport { validator } from '@nhtio/validation'\n\ntype UnitDef = { category: string; factor: number; label: string }\n\nconst UNITS: Record<string, UnitDef> = {\n // Length (base: metre)\n m: { category: 'length', factor: 1, label: 'metres' },\n km: { category: 'length', factor: 1000, label: 'kilometres' },\n cm: { category: 'length', factor: 0.01, label: 'centimetres' },\n mm: { category: 'length', factor: 0.001, label: 'millimetres' },\n mi: { category: 'length', factor: 1609.344, label: 'miles' },\n ft: { category: 'length', factor: 0.3048, label: 'feet' },\n in: { category: 'length', factor: 0.0254, label: 'inches' },\n yd: { category: 'length', factor: 0.9144, label: 'yards' },\n nmi: { category: 'length', factor: 1852, label: 'nautical miles' },\n\n // Mass (base: gram)\n g: { category: 'mass', factor: 1, label: 'grams' },\n kg: { category: 'mass', factor: 1000, label: 'kilograms' },\n mg: { category: 'mass', factor: 0.001, label: 'milligrams' },\n t: { category: 'mass', factor: 1_000_000, label: 'metric tons' },\n lb: { category: 'mass', factor: 453.59237, label: 'pounds' },\n oz: { category: 'mass', factor: 28.349523125, label: 'ounces' },\n st: { category: 'mass', factor: 6350.29318, label: 'stone' },\n\n // Volume (base: litre)\n L: { category: 'volume', factor: 1, label: 'litres' },\n mL: { category: 'volume', factor: 0.001, label: 'millilitres' },\n m3: { category: 'volume', factor: 1000, label: 'cubic metres' },\n cm3: { category: 'volume', factor: 0.001, label: 'cubic centimetres' },\n gal: { category: 'volume', factor: 3.785411784, label: 'US gallons' },\n qt: { category: 'volume', factor: 0.946352946, label: 'US quarts' },\n pt: { category: 'volume', factor: 0.473176473, label: 'US pints' },\n cup: { category: 'volume', factor: 0.2365882365, label: 'US cups' },\n floz: { category: 'volume', factor: 0.029573529562, label: 'US fluid ounces' },\n tbsp: { category: 'volume', factor: 0.014786764781, label: 'tablespoons' },\n tsp: { category: 'volume', factor: 0.0049289215938, label: 'teaspoons' },\n\n // Speed (base: m/s)\n m_s: { category: 'speed', factor: 1, label: 'm/s' },\n km_h: { category: 'speed', factor: 1 / 3.6, label: 'km/h' },\n mph: { category: 'speed', factor: 0.44704, label: 'mph' },\n kn: { category: 'speed', factor: 0.514444, label: 'knots' },\n ft_s: { category: 'speed', factor: 0.3048, label: 'ft/s' },\n\n // Area (base: m²)\n m2: { category: 'area', factor: 1, label: 'm²' },\n km2: { category: 'area', factor: 1_000_000, label: 'km²' },\n cm2: { category: 'area', factor: 0.0001, label: 'cm²' },\n mm2: { category: 'area', factor: 0.000001, label: 'mm²' },\n ft2: { category: 'area', factor: 0.09290304, label: 'sq ft' },\n in2: { category: 'area', factor: 0.00064516, label: 'sq in' },\n yd2: { category: 'area', factor: 0.83612736, label: 'sq yd' },\n acre: { category: 'area', factor: 4046.8564224, label: 'acres' },\n ha: { category: 'area', factor: 10_000, label: 'hectares' },\n\n // Data storage (base: bit)\n bit: { category: 'data', factor: 1, label: 'bits' },\n B: { category: 'data', factor: 8, label: 'bytes' },\n KB: { category: 'data', factor: 8_000, label: 'kilobytes' },\n MB: { category: 'data', factor: 8_000_000, label: 'megabytes' },\n GB: { category: 'data', factor: 8_000_000_000, label: 'gigabytes' },\n TB: { category: 'data', factor: 8_000_000_000_000, label: 'terabytes' },\n KiB: { category: 'data', factor: 8 * 1024, label: 'kibibytes' },\n MiB: { category: 'data', factor: 8 * 1024 ** 2, label: 'mebibytes' },\n GiB: { category: 'data', factor: 8 * 1024 ** 3, label: 'gibibytes' },\n TiB: { category: 'data', factor: 8 * 1024 ** 4, label: 'tebibytes' },\n\n // Time (base: second)\n ms: { category: 'time', factor: 0.001, label: 'milliseconds' },\n s: { category: 'time', factor: 1, label: 'seconds' },\n min: { category: 'time', factor: 60, label: 'minutes' },\n h: { category: 'time', factor: 3600, label: 'hours' },\n d: { category: 'time', factor: 86400, label: 'days' },\n wk: { category: 'time', factor: 604800, label: 'weeks' },\n\n // Energy (base: joule)\n J: { category: 'energy', factor: 1, label: 'joules' },\n kJ: { category: 'energy', factor: 1000, label: 'kilojoules' },\n cal: { category: 'energy', factor: 4.184, label: 'calories' },\n kcal: { category: 'energy', factor: 4184, label: 'kilocalories' },\n Wh: { category: 'energy', factor: 3600, label: 'watt-hours' },\n kWh: { category: 'energy', factor: 3_600_000, label: 'kilowatt-hours' },\n BTU: { category: 'energy', factor: 1055.05585, label: 'BTU' },\n\n // Pressure (base: pascal)\n Pa: { category: 'pressure', factor: 1, label: 'pascals' },\n kPa: { category: 'pressure', factor: 1000, label: 'kilopascals' },\n MPa: { category: 'pressure', factor: 1_000_000, label: 'megapascals' },\n bar: { category: 'pressure', factor: 100_000, label: 'bar' },\n psi: { category: 'pressure', factor: 6894.757, label: 'psi' },\n atm: { category: 'pressure', factor: 101325, label: 'atm' },\n mmHg: { category: 'pressure', factor: 133.322, label: 'mmHg' },\n\n // Angle (base: radian)\n rad: { category: 'angle', factor: 1, label: 'radians' },\n deg: { category: 'angle', factor: Math.PI / 180, label: 'degrees' },\n grad: { category: 'angle', factor: Math.PI / 200, label: 'gradians' },\n}\n\nconst TEMP_UNITS = new Set(['C', 'F', 'K'])\ntype TempUnit = 'C' | 'F' | 'K'\nconst TEMP_LABELS: Record<TempUnit, string> = { C: '°C', F: '°F', K: 'K' }\n\nfunction toKelvin(value: number, unit: TempUnit): number {\n if (unit === 'C') return value + 273.15\n if (unit === 'F') return (value - 32) * (5 / 9) + 273.15\n return value\n}\n\nfunction fromKelvin(kelvin: number, unit: TempUnit): number {\n if (unit === 'C') return kelvin - 273.15\n if (unit === 'F') return (kelvin - 273.15) * (9 / 5) + 32\n return kelvin\n}\n\nconst ALL_UNIT_KEYS = [...Object.keys(UNITS), 'C', 'F', 'K'].join(', ')\n\n/**\n * Convert a numeric value between units of the same physical category.\n *\n * @remarks\n * Supported categories: length, mass, volume, temperature, speed, area, data, time, energy,\n * pressure, angle. Uses static conversion tables — no external data required. Temperature is\n * handled specially via a Kelvin intermediate to preserve precision across `C`/`F`/`K`.\n */\nexport const convertUnitTool = new Tool({\n name: 'convert_unit',\n description:\n 'Convert a numeric value between units of the same category (length, mass, volume, temperature, speed, area, data, time, energy, pressure, angle). Uses static lookup tables — no external data required.',\n inputSchema: validator.object({\n value: validator.number().required().description('Numeric value to convert'),\n from: validator\n .string()\n .required()\n .description(`Source unit key. Supported keys: ${ALL_UNIT_KEYS}`),\n to: validator\n .string()\n .required()\n .description('Target unit key (must be in the same category as source)'),\n }),\n handler: async (args) => {\n const { value, from, to } = args as { value: number; from: string; to: string }\n\n if (TEMP_UNITS.has(from) || TEMP_UNITS.has(to)) {\n if (!TEMP_UNITS.has(from))\n return `Error: \"${from}\" is not a temperature unit. Use C, F, or K.`\n if (!TEMP_UNITS.has(to)) return `Error: \"${to}\" is not a temperature unit. Use C, F, or K.`\n const result = fromKelvin(toKelvin(value, from as TempUnit), to as TempUnit)\n const rounded = Number.parseFloat(result.toPrecision(10))\n return `${value}${TEMP_LABELS[from as TempUnit]} = ${rounded}${TEMP_LABELS[to as TempUnit]}`\n }\n\n const fromDef = UNITS[from]\n const toDef = UNITS[to]\n if (!fromDef) return `Error: Unknown unit \"${from}\". Supported: ${ALL_UNIT_KEYS}`\n if (!toDef) return `Error: Unknown unit \"${to}\". Supported: ${ALL_UNIT_KEYS}`\n if (fromDef.category !== toDef.category) {\n return `Error: Cannot convert \"${from}\" (${fromDef.category}) to \"${to}\" (${toDef.category}) — different categories.`\n }\n\n const inBase = value * fromDef.factor\n const result = inBase / toDef.factor\n const rounded = Number.parseFloat(result.toPrecision(10))\n return `${value} ${fromDef.label} = ${rounded} ${toDef.label}`\n },\n})\n"],"mappings":";;;;;;;;;;;;;AAeA,IAAM,QAAiC;CAErC,GAAG;EAAE,UAAU;EAAU,QAAQ;EAAG,OAAO;CAAS;CAC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,oCAAoC,eAAe;EAClE,IAAI,UACD,OAAO,EACP,SAAS,EACT,YAAY,0DAA0D;CAC3E,CAAC;CACD,SAAS,OAAO,SAAS;EACvB,MAAM,EAAE,OAAO,MAAM,OAAO;EAE5B,IAAI,WAAW,IAAI,IAAI,KAAK,WAAW,IAAI,EAAE,GAAG;GAC9C,IAAI,CAAC,WAAW,IAAI,IAAI,GACtB,OAAO,WAAW,KAAK;GACzB,IAAI,CAAC,WAAW,IAAI,EAAE,GAAG,OAAO,WAAW,GAAG;GAC9C,MAAM,SAAS,WAAW,SAAS,OAAO,IAAgB,GAAG,EAAc;GAC3E,MAAM,UAAU,OAAO,WAAW,OAAO,YAAY,EAAE,CAAC;GACxD,OAAO,GAAG,QAAQ,YAAY,MAAkB,KAAK,UAAU,YAAY;EAC7E;EAEA,MAAM,UAAU,MAAM;EACtB,MAAM,QAAQ,MAAM;EACpB,IAAI,CAAC,SAAS,OAAO,wBAAwB,KAAK,gBAAgB;EAClE,IAAI,CAAC,OAAO,OAAO,wBAAwB,GAAG,gBAAgB;EAC9D,IAAI,QAAQ,aAAa,MAAM,UAC7B,OAAO,0BAA0B,KAAK,KAAK,QAAQ,SAAS,QAAQ,GAAG,KAAK,MAAM,SAAS;EAI7F,MAAM,SADS,QAAQ,QAAQ,SACP,MAAM;EAC9B,MAAM,UAAU,OAAO,WAAW,OAAO,YAAY,EAAE,CAAC;EACxD,OAAO,GAAG,MAAM,GAAG,QAAQ,MAAM,KAAK,QAAQ,GAAG,MAAM;CACzD;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"unit_conversion.mjs","names":[],"sources":["../../../src/batteries/tools/unit_conversion/index.ts"],"sourcesContent":["/**\n * Pre-constructed tools for converting values across common measurement units.\n *\n * @module @nhtio/adk/batteries/tools/unit_conversion\n *\n * @remarks\n * Pre-constructed bundled tools for the `unit_conversion` category. Import individually, the whole\n * category, or import every tool via `@nhtio/adk/batteries`.\n */\n\nimport { Tool } from '@nhtio/adk/common'\nimport { validator } from '@nhtio/validation'\nimport { bigScale, formatBig, DEFAULT_PRECISION } from '@nhtio/adk/lib/helpers/bignum'\n\ntype UnitDef = { category: string; factor: number; label: string }\n\nconst UNITS: Record<string, UnitDef> = {\n // Length (base: metre)\n m: { category: 'length', factor: 1, label: 'metres' },\n km: { category: 'length', factor: 1000, label: 'kilometres' },\n cm: { category: 'length', factor: 0.01, label: 'centimetres' },\n mm: { category: 'length', factor: 0.001, label: 'millimetres' },\n mi: { category: 'length', factor: 1609.344, label: 'miles' },\n ft: { category: 'length', factor: 0.3048, label: 'feet' },\n in: { category: 'length', factor: 0.0254, label: 'inches' },\n yd: { category: 'length', factor: 0.9144, label: 'yards' },\n nmi: { category: 'length', factor: 1852, label: 'nautical miles' },\n\n // Mass (base: gram)\n g: { category: 'mass', factor: 1, label: 'grams' },\n kg: { category: 'mass', factor: 1000, label: 'kilograms' },\n mg: { category: 'mass', factor: 0.001, label: 'milligrams' },\n t: { category: 'mass', factor: 1_000_000, label: 'metric tons' },\n lb: { category: 'mass', factor: 453.59237, label: 'pounds' },\n oz: { category: 'mass', factor: 28.349523125, label: 'ounces' },\n st: { category: 'mass', factor: 6350.29318, label: 'stone' },\n\n // Volume (base: litre)\n L: { category: 'volume', factor: 1, label: 'litres' },\n mL: { category: 'volume', factor: 0.001, label: 'millilitres' },\n m3: { category: 'volume', factor: 1000, label: 'cubic metres' },\n cm3: { category: 'volume', factor: 0.001, label: 'cubic centimetres' },\n gal: { category: 'volume', factor: 3.785411784, label: 'US gallons' },\n qt: { category: 'volume', factor: 0.946352946, label: 'US quarts' },\n pt: { category: 'volume', factor: 0.473176473, label: 'US pints' },\n cup: { category: 'volume', factor: 0.2365882365, label: 'US cups' },\n floz: { category: 'volume', factor: 0.029573529562, label: 'US fluid ounces' },\n tbsp: { category: 'volume', factor: 0.014786764781, label: 'tablespoons' },\n tsp: { category: 'volume', factor: 0.0049289215938, label: 'teaspoons' },\n\n // Speed (base: m/s)\n m_s: { category: 'speed', factor: 1, label: 'm/s' },\n km_h: { category: 'speed', factor: 1 / 3.6, label: 'km/h' },\n mph: { category: 'speed', factor: 0.44704, label: 'mph' },\n kn: { category: 'speed', factor: 0.514444, label: 'knots' },\n ft_s: { category: 'speed', factor: 0.3048, label: 'ft/s' },\n\n // Area (base: m²)\n m2: { category: 'area', factor: 1, label: 'm²' },\n km2: { category: 'area', factor: 1_000_000, label: 'km²' },\n cm2: { category: 'area', factor: 0.0001, label: 'cm²' },\n mm2: { category: 'area', factor: 0.000001, label: 'mm²' },\n ft2: { category: 'area', factor: 0.09290304, label: 'sq ft' },\n in2: { category: 'area', factor: 0.00064516, label: 'sq in' },\n yd2: { category: 'area', factor: 0.83612736, label: 'sq yd' },\n acre: { category: 'area', factor: 4046.8564224, label: 'acres' },\n ha: { category: 'area', factor: 10_000, label: 'hectares' },\n\n // Data storage (base: bit)\n bit: { category: 'data', factor: 1, label: 'bits' },\n B: { category: 'data', factor: 8, label: 'bytes' },\n KB: { category: 'data', factor: 8_000, label: 'kilobytes' },\n MB: { category: 'data', factor: 8_000_000, label: 'megabytes' },\n GB: { category: 'data', factor: 8_000_000_000, label: 'gigabytes' },\n TB: { category: 'data', factor: 8_000_000_000_000, label: 'terabytes' },\n KiB: { category: 'data', factor: 8 * 1024, label: 'kibibytes' },\n MiB: { category: 'data', factor: 8 * 1024 ** 2, label: 'mebibytes' },\n GiB: { category: 'data', factor: 8 * 1024 ** 3, label: 'gibibytes' },\n TiB: { category: 'data', factor: 8 * 1024 ** 4, label: 'tebibytes' },\n\n // Time (base: second)\n ms: { category: 'time', factor: 0.001, label: 'milliseconds' },\n s: { category: 'time', factor: 1, label: 'seconds' },\n min: { category: 'time', factor: 60, label: 'minutes' },\n h: { category: 'time', factor: 3600, label: 'hours' },\n d: { category: 'time', factor: 86400, label: 'days' },\n wk: { category: 'time', factor: 604800, label: 'weeks' },\n\n // Energy (base: joule)\n J: { category: 'energy', factor: 1, label: 'joules' },\n kJ: { category: 'energy', factor: 1000, label: 'kilojoules' },\n cal: { category: 'energy', factor: 4.184, label: 'calories' },\n kcal: { category: 'energy', factor: 4184, label: 'kilocalories' },\n Wh: { category: 'energy', factor: 3600, label: 'watt-hours' },\n kWh: { category: 'energy', factor: 3_600_000, label: 'kilowatt-hours' },\n BTU: { category: 'energy', factor: 1055.05585, label: 'BTU' },\n\n // Pressure (base: pascal)\n Pa: { category: 'pressure', factor: 1, label: 'pascals' },\n kPa: { category: 'pressure', factor: 1000, label: 'kilopascals' },\n MPa: { category: 'pressure', factor: 1_000_000, label: 'megapascals' },\n bar: { category: 'pressure', factor: 100_000, label: 'bar' },\n psi: { category: 'pressure', factor: 6894.757, label: 'psi' },\n atm: { category: 'pressure', factor: 101325, label: 'atm' },\n mmHg: { category: 'pressure', factor: 133.322, label: 'mmHg' },\n\n // Angle (base: radian)\n rad: { category: 'angle', factor: 1, label: 'radians' },\n deg: { category: 'angle', factor: Math.PI / 180, label: 'degrees' },\n grad: { category: 'angle', factor: Math.PI / 200, label: 'gradians' },\n}\n\nconst TEMP_UNITS = new Set(['C', 'F', 'K'])\ntype TempUnit = 'C' | 'F' | 'K'\nconst TEMP_LABELS: Record<TempUnit, string> = { C: '°C', F: '°F', K: 'K' }\n\nfunction toKelvin(value: number, unit: TempUnit): number {\n if (unit === 'C') return value + 273.15\n if (unit === 'F') return (value - 32) * (5 / 9) + 273.15\n return value\n}\n\nfunction fromKelvin(kelvin: number, unit: TempUnit): number {\n if (unit === 'C') return kelvin - 273.15\n if (unit === 'F') return (kelvin - 273.15) * (9 / 5) + 32\n return kelvin\n}\n\nconst ALL_UNIT_KEYS = [...Object.keys(UNITS), 'C', 'F', 'K'].join(', ')\n\n/**\n * Convert a numeric value between units of the same physical category.\n *\n * @remarks\n * Supported categories: length, mass, volume, temperature, speed, area, data, time, energy,\n * pressure, angle. Uses static conversion tables — no external data required. Temperature is\n * handled specially via a Kelvin intermediate to preserve precision across `C`/`F`/`K`.\n */\nexport const convertUnitTool = new Tool({\n name: 'convert_unit',\n description:\n 'Convert a numeric value between units of the same category (length, mass, volume, temperature, speed, area, data, time, energy, pressure, angle). Uses static lookup tables — no external data required.',\n inputSchema: validator.object({\n value: validator.number().required().description('Numeric value to convert'),\n from: validator\n .string()\n .required()\n .description(`Source unit key. Supported keys: ${ALL_UNIT_KEYS}`),\n to: validator\n .string()\n .required()\n .description('Target unit key (must be in the same category as source)'),\n precision: validator\n .number()\n .default(DEFAULT_PRECISION)\n .description(`Significant digits in the result (default: ${DEFAULT_PRECISION}).`),\n }),\n handler: async (args) => {\n const { value, from, to, precision } = args as {\n value: number\n from: string\n to: string\n precision: number\n }\n\n if (TEMP_UNITS.has(from) || TEMP_UNITS.has(to)) {\n if (!TEMP_UNITS.has(from))\n return `Error: \"${from}\" is not a temperature unit. Use C, F, or K.`\n if (!TEMP_UNITS.has(to)) return `Error: \"${to}\" is not a temperature unit. Use C, F, or K.`\n // Temperatures are small bounded values (schema rejects |value| > 2^53), so float64 math\n // is exact enough; only the display precision changes.\n const kelvin = toKelvin(value, from as TempUnit)\n // Reject physically impossible temperatures below absolute zero (0 K) rather than silently\n // returning a nonsensical value like \"-1 K = -274.15 °C\". A tiny epsilon absorbs float noise.\n if (kelvin < -1e-9) {\n return `Error: ${value}${TEMP_LABELS[from as TempUnit]} is below absolute zero (0 K); not a physical temperature.`\n }\n const result = fromKelvin(kelvin, to as TempUnit)\n const rounded = formatBig(result, precision)\n return `${value}${TEMP_LABELS[from as TempUnit]} = ${rounded}${TEMP_LABELS[to as TempUnit]}`\n }\n\n const fromDef = UNITS[from]\n const toDef = UNITS[to]\n if (!fromDef) return `Error: Unknown unit \"${from}\". Supported: ${ALL_UNIT_KEYS}`\n if (!toDef) return `Error: Unknown unit \"${to}\". Supported: ${ALL_UNIT_KEYS}`\n if (fromDef.category !== toDef.category) {\n return `Error: Cannot convert \"${from}\" (${fromDef.category}) to \"${to}\" (${toDef.category}) — different categories.`\n }\n\n // `value * fromFactor / toFactor` in BigNumber so huge ratios (e.g. TB→bit) don't overflow to\n // Infinity, tiny ratios (e.g. in→km) don't underflow to 0, and safe integers keep full digits.\n const result = bigScale(value, fromDef.factor, toDef.factor)\n const rounded = formatBig(result, precision)\n return `${value} ${fromDef.label} = ${rounded} ${toDef.label}`\n },\n})\n"],"mappings":";;;;;;;;;;;;;;AAgBA,IAAM,QAAiC;CAErC,GAAG;EAAE,UAAU;EAAU,QAAQ;EAAG,OAAO;CAAS;CACpD,IAAI;EAAE,UAAU;EAAU,QAAQ;EAAM,OAAO;CAAa;CAC5D,IAAI;EAAE,UAAU;EAAU,QAAQ;EAAM,OAAO;CAAc;CAC7D,IAAI;EAAE,UAAU;EAAU,QAAQ;EAAO,OAAO;CAAc;CAC9D,IAAI;EAAE,UAAU;EAAU,QAAQ;EAAU,OAAO;CAAQ;CAC3D,IAAI;EAAE,UAAU;EAAU,QAAQ;EAAQ,OAAO;CAAO;CACxD,IAAI;EAAE,UAAU;EAAU,QAAQ;EAAQ,OAAO;CAAS;CAC1D,IAAI;EAAE,UAAU;EAAU,QAAQ;EAAQ,OAAO;CAAQ;CACzD,KAAK;EAAE,UAAU;EAAU,QAAQ;EAAM,OAAO;CAAiB;CAGjE,GAAG;EAAE,UAAU;EAAQ,QAAQ;EAAG,OAAO;CAAQ;CACjD,IAAI;EAAE,UAAU;EAAQ,QAAQ;EAAM,OAAO;CAAY;CACzD,IAAI;EAAE,UAAU;EAAQ,QAAQ;EAAO,OAAO;CAAa;CAC3D,GAAG;EAAE,UAAU;EAAQ,QAAQ;EAAW,OAAO;CAAc;CAC/D,IAAI;EAAE,UAAU;EAAQ,QAAQ;EAAW,OAAO;CAAS;CAC3D,IAAI;EAAE,UAAU;EAAQ,QAAQ;EAAc,OAAO;CAAS;CAC9D,IAAI;EAAE,UAAU;EAAQ,QAAQ;EAAY,OAAO;CAAQ;CAG3D,GAAG;EAAE,UAAU;EAAU,QAAQ;EAAG,OAAO;CAAS;CACpD,IAAI;EAAE,UAAU;EAAU,QAAQ;EAAO,OAAO;CAAc;CAC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GAAG,QAAQ,MAAM,KAAK,QAAQ,GAAG,MAAM;CACzD;AACF,CAAC"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RAG glue: turn web-search and web-scrape results into `Retrievable` records for a turn.
|
|
3
|
+
*
|
|
4
|
+
* @module @nhtio/adk/batteries/tools/web_retrieval
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* The seam from "I searched / scraped something" to "it is in the turn as a `Retrievable`",
|
|
8
|
+
* shared by the SearXNG and Scrapper batteries. It is deliberately **decoupled** from the ADK
|
|
9
|
+
* core at runtime:
|
|
10
|
+
*
|
|
11
|
+
* - The converters are **pure** `(payload) => RawRetrievable[]` — they build plain data objects and
|
|
12
|
+
* never instantiate a core class, so the module's only core coupling is erased `import type`.
|
|
13
|
+
* - The recommended spool-artifact type travels as an **open resolver**
|
|
14
|
+
* ({@link @nhtio/adk/forge!ArtifactConstructorResolver}), never a closed string enum — a consumer's
|
|
15
|
+
* future YAML/HTML `SpooledArtifact` subclass works with no change here. The converter hands the
|
|
16
|
+
* recommendation to the caller's `spool` hook; the caller owns the actual class import.
|
|
17
|
+
* - The one helper that must construct a `Retrievable` ({@link storeRetrievables}) takes the
|
|
18
|
+
* constructor via a **resolver** (constructor / sync / async / dynamic-import), exactly like the
|
|
19
|
+
* vector battery's `createVectorStore` `client`.
|
|
20
|
+
*
|
|
21
|
+
* Web content is `'third-party-public'` by default — a definitional constant for open-web data
|
|
22
|
+
* (NOT inferred from the URL, which CONTRIBUTING Design Decision #12 forbids); override via
|
|
23
|
+
* `trustTier` when you know better.
|
|
24
|
+
*/
|
|
25
|
+
import type { SpooledArtifact } from "../../../spooled_artifact";
|
|
26
|
+
import type { ArtifactConstructorResolver } from "../../../forge";
|
|
27
|
+
import type { RawRetrievable, Retrievable, RetrievableTrustTier } from "../../../common";
|
|
28
|
+
/** A constructor that builds a {@link @nhtio/adk!Retrievable} from a {@link @nhtio/adk!RawRetrievable}. */
|
|
29
|
+
export type RetrievableCtor = new (raw: RawRetrievable) => Retrievable;
|
|
30
|
+
/** A resolver of `T`: the value itself, or a (sync/async) thunk, optionally a module `{ default }`. */
|
|
31
|
+
export type Resolver<T> = T | (() => T | {
|
|
32
|
+
default: T;
|
|
33
|
+
}) | (() => Promise<T | {
|
|
34
|
+
default: T;
|
|
35
|
+
}>);
|
|
36
|
+
/**
|
|
37
|
+
* A reader-backed-artifact hook. Called by a converter for content that may be large; the
|
|
38
|
+
* converter passes the artifact constructor it **recommends** for this content (an open
|
|
39
|
+
* {@link @nhtio/adk/forge!ArtifactConstructorResolver}) so the caller can wrap with the right
|
|
40
|
+
* subclass — preserving its forged query tools — using the caller's own core import. Return a
|
|
41
|
+
* {@link @nhtio/adk!SpooledArtifact} to store the content reader-backed, or `undefined` to keep it
|
|
42
|
+
* inline as a string.
|
|
43
|
+
*/
|
|
44
|
+
export type SpoolHook = (id: string, text: string, recommended: ArtifactConstructorResolver) => SpooledArtifact | undefined;
|
|
45
|
+
/** Options common to every converter. */
|
|
46
|
+
export interface ToRetrievableOptions {
|
|
47
|
+
/**
|
|
48
|
+
* Trust tier for the produced records. Default `'third-party-public'` (web content is
|
|
49
|
+
* third-party by definition — this is a constant, not URL inference).
|
|
50
|
+
*/
|
|
51
|
+
trustTier?: RetrievableTrustTier;
|
|
52
|
+
/** Semantic `kind` label, e.g. `'web-search-result'`, `'web-article'`, `'web-links'`. */
|
|
53
|
+
kind?: string;
|
|
54
|
+
/** Prefix for the stable, hashed record id (namespacing across sources). */
|
|
55
|
+
idPrefix?: string;
|
|
56
|
+
/** Optional reader-backed-artifact hook for large content. See {@link SpoolHook}. */
|
|
57
|
+
spool?: SpoolHook;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The artifact-resolver recommendations a caller may supply so the glue names no concrete class
|
|
61
|
+
* itself. Each converter asks for the relevant key; if the caller omits it, content stays inline.
|
|
62
|
+
*/
|
|
63
|
+
export interface ArtifactRecommendations {
|
|
64
|
+
/** Recommended for plain-text / HTML content (base `SpooledArtifact`). */
|
|
65
|
+
text?: ArtifactConstructorResolver;
|
|
66
|
+
/** Recommended for markdown content (`SpooledMarkdownArtifact`). */
|
|
67
|
+
markdown?: ArtifactConstructorResolver;
|
|
68
|
+
/** Recommended for JSON content (`SpooledJsonArtifact`). */
|
|
69
|
+
json?: ArtifactConstructorResolver;
|
|
70
|
+
}
|
|
71
|
+
/** Minimal structural shape of a SearXNG normalised result the converter reads. */
|
|
72
|
+
export interface SearxngResultLike {
|
|
73
|
+
/** Result URL (becomes the record's `source`). */
|
|
74
|
+
url?: string;
|
|
75
|
+
/** Result title (joined into the inline content). */
|
|
76
|
+
title?: string;
|
|
77
|
+
/** Result snippet (joined into the inline content). */
|
|
78
|
+
content?: string;
|
|
79
|
+
/** Relevance score (clamped to `[0,1]` on the record). */
|
|
80
|
+
score?: number;
|
|
81
|
+
}
|
|
82
|
+
/** Minimal structural shape of a SearXNG normalised payload. */
|
|
83
|
+
export interface SearxngPayloadLike {
|
|
84
|
+
/** The result list. */
|
|
85
|
+
results?: SearxngResultLike[];
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Convert a SearXNG normalised payload into one {@link @nhtio/adk!RawRetrievable} per result.
|
|
89
|
+
*
|
|
90
|
+
* @remarks
|
|
91
|
+
* Snippets are short, so `content` stays an inline string (the `spool` hook, if any, is still
|
|
92
|
+
* offered the `text` recommendation). `source` is the result URL; `score` is clamped to `[0,1]`.
|
|
93
|
+
*
|
|
94
|
+
* @param payload - The SearXNG normalised payload (`{ results: [{ url, title, content, score }] }`).
|
|
95
|
+
* @param opts - Trust tier, kind, id prefix, optional spool hook.
|
|
96
|
+
* @param recommend - Optional artifact-resolver recommendations (the glue names no class itself).
|
|
97
|
+
* @returns One `RawRetrievable` per result.
|
|
98
|
+
*/
|
|
99
|
+
export declare const searxngResultsToRetrievables: (payload: SearxngPayloadLike, opts?: ToRetrievableOptions, recommend?: ArtifactRecommendations) => RawRetrievable[];
|
|
100
|
+
/** Minimal structural shape of a Scrapper normalised article. */
|
|
101
|
+
export interface ScrapperArticleLike {
|
|
102
|
+
/** The page URL (becomes the record's `source`). */
|
|
103
|
+
url?: string;
|
|
104
|
+
/** Article title. */
|
|
105
|
+
title?: string;
|
|
106
|
+
/** Article text with HTML stripped (the default content source). */
|
|
107
|
+
textContent?: string;
|
|
108
|
+
/** Processed article HTML (the `'content'` content source). */
|
|
109
|
+
content?: string;
|
|
110
|
+
}
|
|
111
|
+
/** Which article text field to use as the record content. */
|
|
112
|
+
export type ArticleContentSource = 'textContent' | 'content';
|
|
113
|
+
/** Options for {@link scrapperArticleToRetrievable}. */
|
|
114
|
+
export interface ArticleToRetrievableOptions extends ToRetrievableOptions {
|
|
115
|
+
/** Which field to use as content (default `'textContent'`). `'content'` is HTML. */
|
|
116
|
+
contentSource?: ArticleContentSource;
|
|
117
|
+
/**
|
|
118
|
+
* Whether the chosen content is markdown (recommend `markdown`) rather than plain text.
|
|
119
|
+
* Default false. Use when an output pipeline rendered the article to markdown.
|
|
120
|
+
*/
|
|
121
|
+
asMarkdown?: boolean;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Convert a Scrapper normalised article into a single {@link @nhtio/adk!RawRetrievable}.
|
|
125
|
+
*
|
|
126
|
+
* @remarks
|
|
127
|
+
* Long article text is exactly what a reader-backed {@link @nhtio/adk!SpooledArtifact} is for: pass a
|
|
128
|
+
* `spool` hook and the converter offers it the recommended artifact resolver (markdown when
|
|
129
|
+
* `asMarkdown`, else text/HTML) so the model gets the right forged query tools. Without a hook,
|
|
130
|
+
* content stays inline.
|
|
131
|
+
*
|
|
132
|
+
* @param article - The Scrapper normalised article.
|
|
133
|
+
* @param opts - Trust tier, kind, id prefix, content source, markdown flag, optional spool hook.
|
|
134
|
+
* @param recommend - Optional artifact-resolver recommendations.
|
|
135
|
+
* @returns A single `RawRetrievable`.
|
|
136
|
+
*/
|
|
137
|
+
export declare const scrapperArticleToRetrievable: (article: ScrapperArticleLike, opts?: ArticleToRetrievableOptions, recommend?: ArtifactRecommendations) => RawRetrievable;
|
|
138
|
+
/** Minimal structural shape of a Scrapper normalised link. */
|
|
139
|
+
export interface ScrapperLinkLike {
|
|
140
|
+
/** The link's target URL (becomes the record's `source`). */
|
|
141
|
+
url?: string;
|
|
142
|
+
/** The link's anchor text (becomes the record's content). */
|
|
143
|
+
text?: string;
|
|
144
|
+
}
|
|
145
|
+
/** Minimal structural shape of a Scrapper normalised links payload. */
|
|
146
|
+
export interface ScrapperLinksLike {
|
|
147
|
+
/** The page URL the links were collected from. */
|
|
148
|
+
url?: string;
|
|
149
|
+
/** The collected links. */
|
|
150
|
+
links?: ScrapperLinkLike[];
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Convert a Scrapper normalised links payload into one {@link @nhtio/adk!RawRetrievable} per link.
|
|
154
|
+
*
|
|
155
|
+
* @remarks
|
|
156
|
+
* Each link's `text` becomes the (inline) content and its `url` the `source`. Link text is short,
|
|
157
|
+
* so no spooling is applied.
|
|
158
|
+
*
|
|
159
|
+
* @param payload - The Scrapper normalised links payload (`{ links: [{ url, text }] }`).
|
|
160
|
+
* @param opts - Trust tier, kind, id prefix.
|
|
161
|
+
* @returns One `RawRetrievable` per link.
|
|
162
|
+
*/
|
|
163
|
+
export declare const scrapperLinksToRetrievables: (payload: ScrapperLinksLike, opts?: ToRetrievableOptions) => RawRetrievable[];
|
|
164
|
+
/** The minimal context surface {@link storeRetrievables} needs. */
|
|
165
|
+
export interface RetrievableStoreCtx {
|
|
166
|
+
/** Persist a single `Retrievable` into the turn (a `DispatchContext` method, or a stub). */
|
|
167
|
+
storeRetrievable: (v: Retrievable) => unknown | Promise<unknown>;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Construct {@link @nhtio/adk!Retrievable}s from `RawRetrievable`s and store each via `ctx`.
|
|
171
|
+
*
|
|
172
|
+
* @remarks
|
|
173
|
+
* This is the only function here that touches a core class, and it does so through an injected
|
|
174
|
+
* **resolver** (`deps.retrievable`) so the glue itself never value-imports `Retrievable`. Each
|
|
175
|
+
* record's `RawRetrievable` validation (including the required `trustTier`) fires at construction.
|
|
176
|
+
* For reader-backed content, the caller's `spool` hook will typically have used
|
|
177
|
+
* `ctx.storeRetrievableBytes` already; this helper just persists the records into the turn.
|
|
178
|
+
*
|
|
179
|
+
* @param ctx - Anything with a `storeRetrievable` method (a `DispatchContext`, or a stub).
|
|
180
|
+
* @param raws - The plain records from the converters.
|
|
181
|
+
* @param deps - `{ retrievable }`: the `Retrievable` constructor or a resolver of it.
|
|
182
|
+
* @returns The constructed `Retrievable` instances, in input order.
|
|
183
|
+
*/
|
|
184
|
+
export declare const storeRetrievables: (ctx: RetrievableStoreCtx, raws: RawRetrievable[], deps: {
|
|
185
|
+
retrievable: Resolver<RetrievableCtor>;
|
|
186
|
+
}) => Promise<Retrievable[]>;
|