@nhtio/adk 1.20260604.0 → 1.20260607.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +261 -0
- package/adk-mcp.mjs +1 -1
- package/batteries/embeddings/openai/adapter.cjs +1 -1
- package/batteries/embeddings/openai/adapter.mjs +1 -1
- package/batteries/embeddings/webllm/adapter.cjs +1 -1
- package/batteries/embeddings/webllm/adapter.mjs +1 -1
- package/batteries/index.d.ts +1 -0
- package/batteries/llm/openai_chat_completions/adapter.cjs +6 -6
- package/batteries/llm/openai_chat_completions/adapter.cjs.map +1 -1
- package/batteries/llm/openai_chat_completions/adapter.mjs +6 -6
- package/batteries/llm/openai_chat_completions/adapter.mjs.map +1 -1
- package/batteries/llm/openai_chat_completions/helpers.cjs +2 -2
- package/batteries/llm/openai_chat_completions/helpers.mjs +2 -2
- 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/webllm_chat_completions/adapter.cjs +6 -6
- package/batteries/llm/webllm_chat_completions/adapter.cjs.map +1 -1
- package/batteries/llm/webllm_chat_completions/adapter.mjs +6 -6
- package/batteries/llm/webllm_chat_completions/adapter.mjs.map +1 -1
- package/batteries/llm/webllm_chat_completions/validation.cjs +2 -2
- package/batteries/llm/webllm_chat_completions/validation.cjs.map +1 -1
- package/batteries/llm/webllm_chat_completions/validation.mjs +2 -2
- package/batteries/llm/webllm_chat_completions/validation.mjs.map +1 -1
- package/batteries/storage/flydrive.cjs +1 -1
- package/batteries/storage/flydrive.mjs +2 -2
- package/batteries/storage/in_memory.cjs +1 -1
- package/batteries/storage/in_memory.mjs +1 -1
- package/batteries/storage/opfs.cjs +1 -1
- package/batteries/storage/opfs.mjs +1 -1
- package/batteries/tools/color.cjs +2 -2
- package/batteries/tools/color.mjs +2 -2
- package/batteries/tools/comparison.cjs +3 -3
- package/batteries/tools/comparison.mjs +3 -3
- package/batteries/tools/data_structure.cjs +3 -3
- package/batteries/tools/data_structure.mjs +3 -3
- package/batteries/tools/datetime_extended.cjs +2 -2
- package/batteries/tools/datetime_extended.mjs +2 -2
- package/batteries/tools/datetime_math.cjs +2 -2
- package/batteries/tools/datetime_math.mjs +2 -2
- package/batteries/tools/encoding.cjs +3 -3
- package/batteries/tools/encoding.mjs +3 -3
- package/batteries/tools/formatting.cjs +3 -3
- package/batteries/tools/formatting.mjs +3 -3
- package/batteries/tools/geo_basics.cjs +2 -2
- package/batteries/tools/geo_basics.mjs +2 -2
- package/batteries/tools/math/index.d.ts +16 -5
- package/batteries/tools/math.cjs +340 -22
- package/batteries/tools/math.cjs.map +1 -1
- package/batteries/tools/math.mjs +338 -21
- 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 +4 -4
- package/batteries/tools/parsing.mjs +4 -4
- package/batteries/tools/retrievables.cjs +4 -4
- package/batteries/tools/retrievables.mjs +4 -4
- package/batteries/tools/standing_instructions.cjs +4 -4
- package/batteries/tools/standing_instructions.mjs +4 -4
- package/batteries/tools/statistics.cjs +4 -4
- package/batteries/tools/statistics.mjs +4 -4
- package/batteries/tools/string_processing.cjs +3 -3
- package/batteries/tools/string_processing.mjs +3 -3
- package/batteries/tools/structured_data.cjs +3 -3
- package/batteries/tools/structured_data.mjs +3 -3
- 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 +2 -2
- package/batteries/tools/unit_conversion.mjs +2 -2
- package/batteries/vector/arangodb/index.d.ts +38 -0
- package/batteries/vector/arangodb.cjs +257 -0
- package/batteries/vector/arangodb.cjs.map +1 -0
- package/batteries/vector/arangodb.mjs +255 -0
- package/batteries/vector/arangodb.mjs.map +1 -0
- package/batteries/vector/builder.cjs +297 -0
- package/batteries/vector/builder.cjs.map +1 -0
- package/batteries/vector/builder.d.ts +87 -0
- package/batteries/vector/builder.mjs +294 -0
- package/batteries/vector/builder.mjs.map +1 -0
- package/batteries/vector/chroma/index.d.ts +32 -0
- package/batteries/vector/chroma.cjs +305 -0
- package/batteries/vector/chroma.cjs.map +1 -0
- package/batteries/vector/chroma.mjs +302 -0
- package/batteries/vector/chroma.mjs.map +1 -0
- package/batteries/vector/clickhouse/index.d.ts +39 -0
- package/batteries/vector/clickhouse.cjs +246 -0
- package/batteries/vector/clickhouse.cjs.map +1 -0
- package/batteries/vector/clickhouse.mjs +244 -0
- package/batteries/vector/clickhouse.mjs.map +1 -0
- package/batteries/vector/cloudflare/index.d.ts +43 -0
- package/batteries/vector/cloudflare.cjs +397 -0
- package/batteries/vector/cloudflare.cjs.map +1 -0
- package/batteries/vector/cloudflare.mjs +395 -0
- package/batteries/vector/cloudflare.mjs.map +1 -0
- package/batteries/vector/conformance/index.d.ts +15 -0
- package/batteries/vector/conformance.cjs +209 -0
- package/batteries/vector/conformance.cjs.map +1 -0
- package/batteries/vector/conformance.mjs +205 -0
- package/batteries/vector/conformance.mjs.map +1 -0
- package/batteries/vector/contract.cjs +42 -0
- package/batteries/vector/contract.cjs.map +1 -0
- package/batteries/vector/contract.d.ts +39 -0
- package/batteries/vector/contract.mjs +40 -0
- package/batteries/vector/contract.mjs.map +1 -0
- package/batteries/vector/couchbase/index.d.ts +49 -0
- package/batteries/vector/couchbase.cjs +401 -0
- package/batteries/vector/couchbase.cjs.map +1 -0
- package/batteries/vector/couchbase.mjs +399 -0
- package/batteries/vector/couchbase.mjs.map +1 -0
- package/batteries/vector/duckdb/index.d.ts +33 -0
- package/batteries/vector/duckdb.cjs +218 -0
- package/batteries/vector/duckdb.cjs.map +1 -0
- package/batteries/vector/duckdb.mjs +216 -0
- package/batteries/vector/duckdb.mjs.map +1 -0
- package/batteries/vector/elasticsearch/index.d.ts +43 -0
- package/batteries/vector/elasticsearch.cjs +306 -0
- package/batteries/vector/elasticsearch.cjs.map +1 -0
- package/batteries/vector/elasticsearch.mjs +303 -0
- package/batteries/vector/elasticsearch.mjs.map +1 -0
- package/batteries/vector/exceptions.cjs +126 -0
- package/batteries/vector/exceptions.cjs.map +1 -0
- package/batteries/vector/exceptions.d.ts +142 -0
- package/batteries/vector/exceptions.mjs +107 -0
- package/batteries/vector/exceptions.mjs.map +1 -0
- package/batteries/vector/factory.cjs +28 -0
- package/batteries/vector/factory.cjs.map +1 -0
- package/batteries/vector/factory.d.ts +38 -0
- package/batteries/vector/factory.mjs +25 -0
- package/batteries/vector/factory.mjs.map +1 -0
- package/batteries/vector/filters.cjs +107 -0
- package/batteries/vector/filters.cjs.map +1 -0
- package/batteries/vector/filters.d.ts +34 -0
- package/batteries/vector/filters.mjs +99 -0
- package/batteries/vector/filters.mjs.map +1 -0
- package/batteries/vector/helpers.cjs +23 -0
- package/batteries/vector/helpers.cjs.map +1 -0
- package/batteries/vector/helpers.d.ts +12 -0
- package/batteries/vector/helpers.mjs +17 -0
- package/batteries/vector/helpers.mjs.map +1 -0
- package/batteries/vector/hnswlib/index.d.ts +35 -0
- package/batteries/vector/hnswlib.cjs +237 -0
- package/batteries/vector/hnswlib.cjs.map +1 -0
- package/batteries/vector/hnswlib.mjs +235 -0
- package/batteries/vector/hnswlib.mjs.map +1 -0
- package/batteries/vector/in_memory/index.d.ts +23 -0
- package/batteries/vector/in_memory.cjs +178 -0
- package/batteries/vector/in_memory.cjs.map +1 -0
- package/batteries/vector/in_memory.mjs +176 -0
- package/batteries/vector/in_memory.mjs.map +1 -0
- package/batteries/vector/index.d.ts +18 -0
- package/batteries/vector/lancedb/index.d.ts +34 -0
- package/batteries/vector/lancedb.cjs +224 -0
- package/batteries/vector/lancedb.cjs.map +1 -0
- package/batteries/vector/lancedb.mjs +222 -0
- package/batteries/vector/lancedb.mjs.map +1 -0
- package/batteries/vector/mariadb/index.d.ts +39 -0
- package/batteries/vector/mariadb.cjs +228 -0
- package/batteries/vector/mariadb.cjs.map +1 -0
- package/batteries/vector/mariadb.mjs +226 -0
- package/batteries/vector/mariadb.mjs.map +1 -0
- package/batteries/vector/meilisearch/index.d.ts +36 -0
- package/batteries/vector/meilisearch.cjs +242 -0
- package/batteries/vector/meilisearch.cjs.map +1 -0
- package/batteries/vector/meilisearch.mjs +240 -0
- package/batteries/vector/meilisearch.mjs.map +1 -0
- package/batteries/vector/migrate.cjs +54 -0
- package/batteries/vector/migrate.cjs.map +1 -0
- package/batteries/vector/migrate.d.ts +30 -0
- package/batteries/vector/migrate.mjs +52 -0
- package/batteries/vector/migrate.mjs.map +1 -0
- package/batteries/vector/milvus/index.d.ts +35 -0
- package/batteries/vector/milvus.cjs +357 -0
- package/batteries/vector/milvus.cjs.map +1 -0
- package/batteries/vector/milvus.mjs +354 -0
- package/batteries/vector/milvus.mjs.map +1 -0
- package/batteries/vector/mongodb/index.d.ts +46 -0
- package/batteries/vector/mongodb.cjs +270 -0
- package/batteries/vector/mongodb.cjs.map +1 -0
- package/batteries/vector/mongodb.mjs +268 -0
- package/batteries/vector/mongodb.mjs.map +1 -0
- package/batteries/vector/neo4j/index.d.ts +38 -0
- package/batteries/vector/neo4j.cjs +231 -0
- package/batteries/vector/neo4j.cjs.map +1 -0
- package/batteries/vector/neo4j.mjs +229 -0
- package/batteries/vector/neo4j.mjs.map +1 -0
- package/batteries/vector/opensearch/index.d.ts +46 -0
- package/batteries/vector/opensearch.cjs +316 -0
- package/batteries/vector/opensearch.cjs.map +1 -0
- package/batteries/vector/opensearch.mjs +313 -0
- package/batteries/vector/opensearch.mjs.map +1 -0
- package/batteries/vector/oracle23ai/index.d.ts +45 -0
- package/batteries/vector/oracle23ai.cjs +340 -0
- package/batteries/vector/oracle23ai.cjs.map +1 -0
- package/batteries/vector/oracle23ai.mjs +338 -0
- package/batteries/vector/oracle23ai.mjs.map +1 -0
- package/batteries/vector/orama/index.d.ts +23 -0
- package/batteries/vector/orama.cjs +272 -0
- package/batteries/vector/orama.cjs.map +1 -0
- package/batteries/vector/orama.mjs +270 -0
- package/batteries/vector/orama.mjs.map +1 -0
- package/batteries/vector/pgvector/index.d.ts +43 -0
- package/batteries/vector/pgvector.cjs +411 -0
- package/batteries/vector/pgvector.cjs.map +1 -0
- package/batteries/vector/pgvector.mjs +408 -0
- package/batteries/vector/pgvector.mjs.map +1 -0
- package/batteries/vector/pinecone/index.d.ts +38 -0
- package/batteries/vector/pinecone.cjs +415 -0
- package/batteries/vector/pinecone.cjs.map +1 -0
- package/batteries/vector/pinecone.mjs +412 -0
- package/batteries/vector/pinecone.mjs.map +1 -0
- package/batteries/vector/plan.cjs +2 -0
- package/batteries/vector/plan.d.ts +65 -0
- package/batteries/vector/plan.mjs +0 -0
- package/batteries/vector/qdrant/index.d.ts +34 -0
- package/batteries/vector/qdrant.cjs +286 -0
- package/batteries/vector/qdrant.cjs.map +1 -0
- package/batteries/vector/qdrant.mjs +284 -0
- package/batteries/vector/qdrant.mjs.map +1 -0
- package/batteries/vector/redis/index.d.ts +44 -0
- package/batteries/vector/redis.cjs +391 -0
- package/batteries/vector/redis.cjs.map +1 -0
- package/batteries/vector/redis.mjs +388 -0
- package/batteries/vector/redis.mjs.map +1 -0
- package/batteries/vector/retrievable.cjs +69 -0
- package/batteries/vector/retrievable.cjs.map +1 -0
- package/batteries/vector/retrievable.mjs +67 -0
- package/batteries/vector/retrievable.mjs.map +1 -0
- package/batteries/vector/retrievable_glue.d.ts +24 -0
- package/batteries/vector/s3vectors/index.d.ts +52 -0
- package/batteries/vector/s3vectors.cjs +438 -0
- package/batteries/vector/s3vectors.cjs.map +1 -0
- package/batteries/vector/s3vectors.mjs +436 -0
- package/batteries/vector/s3vectors.mjs.map +1 -0
- package/batteries/vector/schema.cjs +96 -0
- package/batteries/vector/schema.cjs.map +1 -0
- package/batteries/vector/schema.d.ts +40 -0
- package/batteries/vector/schema.mjs +93 -0
- package/batteries/vector/schema.mjs.map +1 -0
- package/batteries/vector/solr/index.d.ts +36 -0
- package/batteries/vector/solr.cjs +230 -0
- package/batteries/vector/solr.cjs.map +1 -0
- package/batteries/vector/solr.mjs +228 -0
- package/batteries/vector/solr.mjs.map +1 -0
- package/batteries/vector/sqlite_vec/index.d.ts +30 -0
- package/batteries/vector/sqlite_vec.cjs +318 -0
- package/batteries/vector/sqlite_vec.cjs.map +1 -0
- package/batteries/vector/sqlite_vec.mjs +316 -0
- package/batteries/vector/sqlite_vec.mjs.map +1 -0
- package/batteries/vector/surrealdb/index.d.ts +37 -0
- package/batteries/vector/surrealdb.cjs +230 -0
- package/batteries/vector/surrealdb.cjs.map +1 -0
- package/batteries/vector/surrealdb.mjs +228 -0
- package/batteries/vector/surrealdb.mjs.map +1 -0
- package/batteries/vector/types.cjs +2 -0
- package/batteries/vector/types.d.ts +100 -0
- package/batteries/vector/types.mjs +0 -0
- package/batteries/vector/typesense/index.d.ts +38 -0
- package/batteries/vector/typesense.cjs +272 -0
- package/batteries/vector/typesense.cjs.map +1 -0
- package/batteries/vector/typesense.mjs +270 -0
- package/batteries/vector/typesense.mjs.map +1 -0
- package/batteries/vector/validation.cjs +90 -0
- package/batteries/vector/validation.cjs.map +1 -0
- package/batteries/vector/validation.d.ts +18 -0
- package/batteries/vector/validation.mjs +83 -0
- package/batteries/vector/validation.mjs.map +1 -0
- package/batteries/vector/vector_store_constructor.cjs +56 -0
- package/batteries/vector/vector_store_constructor.cjs.map +1 -0
- package/batteries/vector/vector_store_constructor.d.ts +30 -0
- package/batteries/vector/vector_store_constructor.mjs +53 -0
- package/batteries/vector/vector_store_constructor.mjs.map +1 -0
- package/batteries/vector/vespa/index.d.ts +39 -0
- package/batteries/vector/vespa.cjs +423 -0
- package/batteries/vector/vespa.cjs.map +1 -0
- package/batteries/vector/vespa.mjs +421 -0
- package/batteries/vector/vespa.mjs.map +1 -0
- package/batteries/vector/weaviate/index.d.ts +57 -0
- package/batteries/vector/weaviate.cjs +325 -0
- package/batteries/vector/weaviate.cjs.map +1 -0
- package/batteries/vector/weaviate.mjs +322 -0
- package/batteries/vector/weaviate.mjs.map +1 -0
- package/batteries/vector.cjs +63 -0
- package/batteries/vector.mjs +14 -0
- package/batteries.cjs +62 -0
- package/batteries.mjs +15 -1
- package/{chunk-kRvK8_k2.mjs → chunk-Bpcn9VDT.mjs} +5 -1
- package/{common-lMrnzoyn.mjs → common-BT0nfCi9.mjs} +8 -8
- package/{common-lMrnzoyn.mjs.map → common-BT0nfCi9.mjs.map} +1 -1
- package/{common-D_e5zYsG.js → common-Cj8TaQ9U.js} +8 -8
- package/{common-D_e5zYsG.js.map → common-Cj8TaQ9U.js.map} +1 -1
- package/common.cjs +7 -7
- package/common.mjs +7 -7
- package/{dispatch_runner-CpuyATj1.js → dispatch_runner-BHBNupqp.js} +2 -2
- package/dispatch_runner-BHBNupqp.js.map +1 -0
- package/{dispatch_runner-CDF3X0nv.mjs → dispatch_runner-DPcS7Y_M.mjs} +2 -2
- package/dispatch_runner-DPcS7Y_M.mjs.map +1 -0
- package/dispatch_runner.cjs +1 -1
- package/dispatch_runner.mjs +1 -1
- package/forge.cjs +4 -4
- package/forge.mjs +4 -4
- package/guards.cjs +8 -8
- package/guards.mjs +8 -8
- package/index.cjs +12 -12
- package/index.mjs +12 -12
- package/lib/classes/tool_registry.d.ts +70 -4
- package/mcp/adk-docs-corpus.json +1 -1
- package/package.json +424 -88
- package/skills/adk-assembly/SKILL.md +2 -2
- package/{spooled_artifact-B8gIIn9h.js → spooled_artifact-BTq6Nzfy.js} +4 -4
- package/spooled_artifact-BTq6Nzfy.js.map +1 -0
- package/{spooled_artifact-CWoKUDEm.mjs → spooled_artifact-CHoZgWwI.mjs} +4 -4
- package/spooled_artifact-CHoZgWwI.mjs.map +1 -0
- package/spooled_artifact.cjs +2 -2
- package/spooled_artifact.mjs +2 -2
- package/{spooled_markdown_artifact-DQX0RCdI.js → spooled_markdown_artifact-CALSDxIx.js} +3 -3
- package/{spooled_markdown_artifact-DQX0RCdI.js.map → spooled_markdown_artifact-CALSDxIx.js.map} +1 -1
- package/{spooled_markdown_artifact-CNle4jXN.mjs → spooled_markdown_artifact-Ci5UL7l4.mjs} +3 -3
- package/{spooled_markdown_artifact-CNle4jXN.mjs.map → spooled_markdown_artifact-Ci5UL7l4.mjs.map} +1 -1
- package/src/types/evaluatex.d.ts +31 -0
- package/{thought-BD6AkkOr.js → thought-BbwhJ1wb.js} +4 -4
- package/thought-BbwhJ1wb.js.map +1 -0
- package/{thought-B_P8LiB6.mjs → thought-D34QQZZ9.mjs} +4 -4
- package/thought-D34QQZZ9.mjs.map +1 -0
- package/{tool-CRZSUcdP.mjs → tool-CMhaDRNd.mjs} +3 -3
- package/tool-CMhaDRNd.mjs.map +1 -0
- package/{tool-CX9vNHAw.js → tool-CVyZkFC7.js} +3 -3
- package/tool-CVyZkFC7.js.map +1 -0
- package/{tool_call-BUeMuCc6.mjs → tool_call-CV5qVNlb.mjs} +3 -3
- package/{tool_call-BUeMuCc6.mjs.map → tool_call-CV5qVNlb.mjs.map} +1 -1
- package/{tool_call--7ti-frB.js → tool_call-Db68hB7y.js} +3 -3
- package/{tool_call--7ti-frB.js.map → tool_call-Db68hB7y.js.map} +1 -1
- package/{tool_registry-BGHg6KTq.mjs → tool_registry-D1pSSlsd.mjs} +109 -22
- package/tool_registry-D1pSSlsd.mjs.map +1 -0
- package/{tool_registry-CtCQ4Xoz.js → tool_registry-DYUYqXvo.js} +109 -22
- package/tool_registry-DYUYqXvo.js.map +1 -0
- package/{turn_runner-BJTtAORU.js → turn_runner-DqWHNP80.js} +5 -5
- package/turn_runner-DqWHNP80.js.map +1 -0
- package/{turn_runner-C02LZHjt.mjs → turn_runner-fg1Wc3dK.mjs} +5 -5
- package/turn_runner-fg1Wc3dK.mjs.map +1 -0
- package/turn_runner.cjs +1 -1
- package/turn_runner.mjs +1 -1
- package/dispatch_runner-CDF3X0nv.mjs.map +0 -1
- package/dispatch_runner-CpuyATj1.js.map +0 -1
- package/spooled_artifact-B8gIIn9h.js.map +0 -1
- package/spooled_artifact-CWoKUDEm.mjs.map +0 -1
- package/thought-BD6AkkOr.js.map +0 -1
- package/thought-B_P8LiB6.mjs.map +0 -1
- package/tool-CRZSUcdP.mjs.map +0 -1
- package/tool-CX9vNHAw.js.map +0 -1
- package/tool_registry-BGHg6KTq.mjs.map +0 -1
- package/tool_registry-CtCQ4Xoz.js.map +0 -1
- package/turn_runner-BJTtAORU.js.map +0 -1
- package/turn_runner-C02LZHjt.mjs.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as Tool } from "../../tool-
|
|
2
|
-
import "../../common-
|
|
1
|
+
import { t as Tool } from "../../tool-CMhaDRNd.mjs";
|
|
2
|
+
import "../../common-BT0nfCi9.mjs";
|
|
3
3
|
import { validator } from "@nhtio/validation";
|
|
4
4
|
import { DateTime, IANAZone } from "luxon";
|
|
5
5
|
import * as chrono from "chrono-node";
|
|
@@ -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-CVyZkFC7.js");
|
|
4
|
+
require("../../common-Cj8TaQ9U.js");
|
|
5
5
|
let _nhtio_validation = require("@nhtio/validation");
|
|
6
6
|
let luxon = require("luxon");
|
|
7
7
|
//#region src/batteries/tools/datetime_math/index.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as Tool } from "../../tool-
|
|
2
|
-
import "../../common-
|
|
1
|
+
import { t as Tool } from "../../tool-CMhaDRNd.mjs";
|
|
2
|
+
import "../../common-BT0nfCi9.mjs";
|
|
3
3
|
import { validator } from "@nhtio/validation";
|
|
4
4
|
import { DateTime, Duration, IANAZone } from "luxon";
|
|
5
5
|
//#region src/batteries/tools/datetime_math/index.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
require("../../chunk-Ble4zEEl.js");
|
|
3
|
-
const require_tool_registry = require("../../tool_registry-
|
|
4
|
-
const require_tool = require("../../tool-
|
|
5
|
-
require("../../common-
|
|
3
|
+
const require_tool_registry = require("../../tool_registry-DYUYqXvo.js");
|
|
4
|
+
const require_tool = require("../../tool-CVyZkFC7.js");
|
|
5
|
+
require("../../common-Cj8TaQ9U.js");
|
|
6
6
|
require("../../guards.cjs");
|
|
7
7
|
let _nhtio_validation = require("@nhtio/validation");
|
|
8
8
|
//#region src/batteries/tools/encoding/index.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { o as isError } from "../../tool_registry-
|
|
2
|
-
import { t as Tool } from "../../tool-
|
|
3
|
-
import "../../common-
|
|
1
|
+
import { o as isError } from "../../tool_registry-D1pSSlsd.mjs";
|
|
2
|
+
import { t as Tool } from "../../tool-CMhaDRNd.mjs";
|
|
3
|
+
import "../../common-BT0nfCi9.mjs";
|
|
4
4
|
import "../../guards.mjs";
|
|
5
5
|
import { validator } from "@nhtio/validation";
|
|
6
6
|
//#region src/batteries/tools/encoding/index.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
require("../../chunk-Ble4zEEl.js");
|
|
3
|
-
const require_tool_registry = require("../../tool_registry-
|
|
4
|
-
const require_tool = require("../../tool-
|
|
5
|
-
require("../../common-
|
|
3
|
+
const require_tool_registry = require("../../tool_registry-DYUYqXvo.js");
|
|
4
|
+
const require_tool = require("../../tool-CVyZkFC7.js");
|
|
5
|
+
require("../../common-Cj8TaQ9U.js");
|
|
6
6
|
require("../../guards.cjs");
|
|
7
7
|
let _nhtio_validation = require("@nhtio/validation");
|
|
8
8
|
//#region src/batteries/tools/formatting/index.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { o as isError } from "../../tool_registry-
|
|
2
|
-
import { t as Tool } from "../../tool-
|
|
3
|
-
import "../../common-
|
|
1
|
+
import { o as isError } from "../../tool_registry-D1pSSlsd.mjs";
|
|
2
|
+
import { t as Tool } from "../../tool-CMhaDRNd.mjs";
|
|
3
|
+
import "../../common-BT0nfCi9.mjs";
|
|
4
4
|
import "../../guards.mjs";
|
|
5
5
|
import { validator } from "@nhtio/validation";
|
|
6
6
|
//#region src/batteries/tools/formatting/index.ts
|
|
@@ -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-CVyZkFC7.js");
|
|
4
|
+
require("../../common-Cj8TaQ9U.js");
|
|
5
5
|
let _nhtio_validation = require("@nhtio/validation");
|
|
6
6
|
//#region src/batteries/tools/geo_basics/index.ts
|
|
7
7
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as Tool } from "../../tool-
|
|
2
|
-
import "../../common-
|
|
1
|
+
import { t as Tool } from "../../tool-CMhaDRNd.mjs";
|
|
2
|
+
import "../../common-BT0nfCi9.mjs";
|
|
3
3
|
import { validator } from "@nhtio/validation";
|
|
4
4
|
//#region src/batteries/tools/geo_basics/index.ts
|
|
5
5
|
/**
|
|
@@ -24,13 +24,24 @@ import { Tool } from "../../../common";
|
|
|
24
24
|
*/
|
|
25
25
|
export declare const calculateTool: Tool<import("../../../common").SpooledArtifact>;
|
|
26
26
|
/**
|
|
27
|
-
* Translates a LaTeX/KaTeX expression
|
|
27
|
+
* Translates a LaTeX/KaTeX expression using evaluatex and returns the numeric result.
|
|
28
28
|
*
|
|
29
29
|
* @remarks
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
30
|
+
* Uses the evaluatex library to parse and evaluate LaTeX expressions. Handles common constructs
|
|
31
|
+
* (`\frac{a}{b}`, `\sqrt{...}`, `\cdot`, `\times`, Greek macros like `\pi`, inverse trig,
|
|
32
|
+
* `\left`/`\right` delimiters, `\text{...}`, subscripts, etc.) with a proper parser rather than
|
|
33
|
+
* brittle regex.
|
|
34
|
+
*
|
|
35
|
+
* Also evaluates three calculus constructs **numerically** (mathjs has no symbolic integration, and
|
|
36
|
+
* its symbolic `derivative` is blocklisted here for safety):
|
|
37
|
+
* - Definite integrals — `\int_{a}^{b} f \,dx` via composite Simpson quadrature.
|
|
38
|
+
* - Derivatives at a point — `\frac{d}{dx} f \big|_{x=a}` via central finite difference.
|
|
39
|
+
* - Limits — `\lim_{x \to a} f` (including `a = \pm\infty`) via a two-sided numeric approach.
|
|
40
|
+
*
|
|
41
|
+
* Numeric results are rounded with `math.format(..., { precision: 12 })` and labelled
|
|
42
|
+
* `Result (numeric):` to flag that they are approximations. Constructs that cannot be evaluated
|
|
43
|
+
* numerically (indefinite integrals, derivatives without a point, infinite integration bounds,
|
|
44
|
+
* singular integrands, divergent limits) return a specific, guiding error string.
|
|
34
45
|
*
|
|
35
46
|
* Parse and evaluation errors are returned as error strings rather than thrown.
|
|
36
47
|
*/
|
package/batteries/tools/math.cjs
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
require("../../chunk-Ble4zEEl.js");
|
|
3
|
-
const require_tool_registry = require("../../tool_registry-
|
|
4
|
-
const require_tool = require("../../tool-
|
|
5
|
-
require("../../common-
|
|
2
|
+
const require_chunk = require("../../chunk-Ble4zEEl.js");
|
|
3
|
+
const require_tool_registry = require("../../tool_registry-DYUYqXvo.js");
|
|
4
|
+
const require_tool = require("../../tool-CVyZkFC7.js");
|
|
5
|
+
require("../../common-Cj8TaQ9U.js");
|
|
6
6
|
require("../../guards.cjs");
|
|
7
7
|
let _nhtio_validation = require("@nhtio/validation");
|
|
8
8
|
let mathjs = require("mathjs");
|
|
9
|
+
let evaluatex = require("evaluatex");
|
|
10
|
+
evaluatex = require_chunk.__toESM(evaluatex);
|
|
9
11
|
//#region src/batteries/tools/math/index.ts
|
|
10
12
|
/**
|
|
11
13
|
* Pre-constructed tools for safe arithmetic, expression evaluation, and numeric operations.
|
|
@@ -32,20 +34,110 @@ function validateExpression(expr) {
|
|
|
32
34
|
if (expr.length > MAX_EXPRESSION_LENGTH) return `Expression too long (max ${MAX_EXPRESSION_LENGTH} characters).`;
|
|
33
35
|
}
|
|
34
36
|
/**
|
|
35
|
-
*
|
|
37
|
+
* EvaluateX scope providing constants and function aliases that evaluatex does not ship
|
|
38
|
+
* out-of-the-box, matching the capabilities that were previously provided by the mathjs
|
|
39
|
+
* translation layer.
|
|
36
40
|
*/
|
|
37
|
-
|
|
41
|
+
var EVALUATEX_SCOPE = {
|
|
42
|
+
pi: Math.PI,
|
|
43
|
+
e: Math.E,
|
|
44
|
+
infinity: Infinity,
|
|
45
|
+
alpha: void 0,
|
|
46
|
+
beta: void 0,
|
|
47
|
+
gamma: void 0,
|
|
48
|
+
delta: void 0,
|
|
49
|
+
epsilon: void 0,
|
|
50
|
+
theta: void 0,
|
|
51
|
+
lambda: void 0,
|
|
52
|
+
mu: void 0,
|
|
53
|
+
sigma: void 0,
|
|
54
|
+
tau: void 0,
|
|
55
|
+
phi: void 0,
|
|
56
|
+
omega: void 0,
|
|
57
|
+
ln: Math.log,
|
|
58
|
+
log10: (x) => Math.log(x) / Math.LN10,
|
|
59
|
+
log2: (x) => Math.log(x) / Math.LN2,
|
|
60
|
+
nthRoot: (x, n) => Math.pow(x, 1 / n),
|
|
61
|
+
det: (x) => x
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Translate a LaTeX/KaTeX expression to evaluatex-compatible syntax and evaluate it.
|
|
65
|
+
*
|
|
66
|
+
* The translation is a lightweight pass over the LaTeX source that handles common constructs
|
|
67
|
+
* (frac, sqrt, trig, Greek macros, delimiters, etc.) and feeds the result to evaluatex with
|
|
68
|
+
* a pre-built scope providing constants and function aliases. This replaces the previous
|
|
69
|
+
* hand-rolled regex → mathjs pipeline.
|
|
70
|
+
*/
|
|
71
|
+
function evaluateLatex(latex) {
|
|
38
72
|
let expr = latex.trim();
|
|
39
73
|
expr = expr.replace(/^\$\$?|\$\$?$/g, "");
|
|
40
74
|
expr = expr.replace(/^\\[[(]|\\[\])]$/g, "");
|
|
41
|
-
for (let i = 0; i <
|
|
75
|
+
for (let i = 0; i < 20; i++) {
|
|
42
76
|
const before = expr;
|
|
43
|
-
expr = expr.replace(/\\frac\s*\{([^
|
|
77
|
+
expr = expr.replace(/\\frac\s*\{([^}]*)\}\s*\{([^}]*)\}/g, "($1)/($2)");
|
|
44
78
|
if (expr === before) break;
|
|
45
79
|
}
|
|
46
|
-
expr = expr.replace(/\\sqrt\[([^\]]+)\]\s*\{([^
|
|
47
|
-
expr = expr.replace(/\\sqrt\s*\{([^
|
|
48
|
-
expr = expr.replace(/\\
|
|
80
|
+
expr = expr.replace(/\\sqrt\[([^\]]+)\]\s*\{([^}]*)\}/g, "nthRoot($2, $1)");
|
|
81
|
+
expr = expr.replace(/\\sqrt\s*\{([^}]*)\}/g, "sqrt($1)");
|
|
82
|
+
expr = expr.replace(/\\arcsin/g, "asin");
|
|
83
|
+
expr = expr.replace(/\\arccos/g, "acos");
|
|
84
|
+
expr = expr.replace(/\\arctan/g, "atan");
|
|
85
|
+
expr = expr.replace(/\\(sin|cos|tan|cot|sec|csc|sinh|cosh|tanh|ln|log|exp|abs|det)/g, "$1");
|
|
86
|
+
expr = expr.replace(/log_\{?(\w+)\}?\(/g, (_, base) => {
|
|
87
|
+
const baseLower = base.toLowerCase();
|
|
88
|
+
if (baseLower === "10") return "log10(";
|
|
89
|
+
if (baseLower === "2") return "log2(";
|
|
90
|
+
if (baseLower === "e") return "ln(";
|
|
91
|
+
return `ln(/ln(${base})`;
|
|
92
|
+
});
|
|
93
|
+
expr = expr.replace(/_\{[^}]*\}/g, "");
|
|
94
|
+
expr = expr.replace(/_\w/g, "");
|
|
95
|
+
expr = expr.replace(/\^{([^{}]*)}/g, "^($1)");
|
|
96
|
+
expr = expr.replace(/\\pi/g, "pi");
|
|
97
|
+
expr = expr.replace(/\\(alpha|beta|gamma|delta|epsilon|theta|lambda|mu|sigma|tau|phi|omega)/g, "$1");
|
|
98
|
+
expr = expr.replace(/\\cdot/g, "*");
|
|
99
|
+
expr = expr.replace(/\\times/g, "*");
|
|
100
|
+
expr = expr.replace(/\\div/g, "/");
|
|
101
|
+
expr = expr.replace(/\\infty/g, "infinity");
|
|
102
|
+
expr = expr.replace(/\\left\s*([([{|])/g, "$1");
|
|
103
|
+
expr = expr.replace(/\\right\s*([)\]}|])/g, "$1");
|
|
104
|
+
expr = expr.replace(/\\sum/g, "sum");
|
|
105
|
+
expr = expr.replace(/\\prod/g, "prod");
|
|
106
|
+
expr = expr.replace(/\\,/g, " ");
|
|
107
|
+
expr = expr.replace(/\\;/g, " ");
|
|
108
|
+
expr = expr.replace(/\\quad/g, " ");
|
|
109
|
+
expr = expr.replace(/\\qquad/g, " ");
|
|
110
|
+
expr = expr.replace(/\\text\{([^{}]*)\}/g, "");
|
|
111
|
+
expr = expr.replace(/(\d)([a-zA-Z(])/g, "$1*$2");
|
|
112
|
+
expr = expr.replace(/\)\s*\(/g, ")*(");
|
|
113
|
+
expr = expr.replace(/\s+/g, " ").trim();
|
|
114
|
+
const result = (0, evaluatex.default)(expr, EVALUATEX_SCOPE)();
|
|
115
|
+
if (typeof result !== "number" || !Number.isFinite(result)) throw new Error("Result is not finite");
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Lightweight LaTeX-to-string translator for internal use by the numeric calculus path.
|
|
120
|
+
*
|
|
121
|
+
* This is the same translation pass as {@link evaluateLatex}, but returns the translated string
|
|
122
|
+
* (compatible with mathjs syntax) rather than evaluating it. Used by the calculus handlers to
|
|
123
|
+
* convert integrands, function bodies, and bound expressions before passing them to
|
|
124
|
+
* `math.evaluate` for specific-point evaluation.
|
|
125
|
+
*/
|
|
126
|
+
function translateLatex(latex) {
|
|
127
|
+
let expr = latex.trim();
|
|
128
|
+
expr = expr.replace(/^\$\$?|\$\$?$/g, "");
|
|
129
|
+
expr = expr.replace(/^\\[[(]|\\[\])]$/g, "");
|
|
130
|
+
for (let i = 0; i < 20; i++) {
|
|
131
|
+
const before = expr;
|
|
132
|
+
expr = expr.replace(/\\frac\s*\{([^}]*)\}\s*\{([^}]*)\}/g, "($1)/($2)");
|
|
133
|
+
if (expr === before) break;
|
|
134
|
+
}
|
|
135
|
+
expr = expr.replace(/\\sqrt\[([^\]]+)\]\s*\{([^}]*)\}/g, "nthRoot($2, $1)");
|
|
136
|
+
expr = expr.replace(/\\sqrt\s*\{([^}]*)\}/g, "sqrt($1)");
|
|
137
|
+
expr = expr.replace(/\\arcsin/g, "asin");
|
|
138
|
+
expr = expr.replace(/\\arccos/g, "acos");
|
|
139
|
+
expr = expr.replace(/\\arctan/g, "atan");
|
|
140
|
+
expr = expr.replace(/\\(sin|cos|tan|cot|sec|csc|sinh|cosh|tanh|ln|log|exp|abs|det)/g, "$1");
|
|
49
141
|
expr = expr.replace(/log_\{?(\w+)\}?\s*\(([^)]+)\)/g, "log($2, $1)");
|
|
50
142
|
expr = expr.replace(/\^{([^{}]*)}/g, "^($1)");
|
|
51
143
|
expr = expr.replace(/_\{[^{}]*\}/g, "");
|
|
@@ -70,6 +162,222 @@ function latexToMathjs(latex) {
|
|
|
70
162
|
expr = expr.replace(/\s+/g, " ").trim();
|
|
71
163
|
return expr;
|
|
72
164
|
}
|
|
165
|
+
/** A tagged error whose message is surfaced to the model verbatim (caught by {@link tryCalculus}). */
|
|
166
|
+
var CalculusError = class extends Error {};
|
|
167
|
+
/** Evaluate a mathjs expression at a single point, guarding against non-finite results. */
|
|
168
|
+
function evalAt(expr, varName, x) {
|
|
169
|
+
const y = math.evaluate(expr, { [varName]: x });
|
|
170
|
+
if (typeof y !== "number" || !Number.isFinite(y)) throw new CalculusError("NON_FINITE");
|
|
171
|
+
return y;
|
|
172
|
+
}
|
|
173
|
+
/** Composite Simpson's rule over a finite interval. Throws {@link CalculusError} on a singularity. */
|
|
174
|
+
function simpson(fn, a, b, n = 1e3) {
|
|
175
|
+
if (n % 2 === 1) n++;
|
|
176
|
+
const h = (b - a) / n;
|
|
177
|
+
let sum = fn(a) + fn(b);
|
|
178
|
+
for (let i = 1; i < n; i++) sum += (i % 2 === 1 ? 4 : 2) * fn(a + i * h);
|
|
179
|
+
const result = h / 3 * sum;
|
|
180
|
+
if (!Number.isFinite(result)) throw new CalculusError("NON_FINITE");
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
183
|
+
/** Round numeric output to 12 significant digits, collapsing floating-point noise. */
|
|
184
|
+
function formatNumeric(n) {
|
|
185
|
+
if (Math.abs(n) < 1e-9) return "0";
|
|
186
|
+
return math.format(n, { precision: 12 });
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Reads a single `_`/`^` script starting at `i`, supporting braced (`_{0}`, `^{\pi}`), command
|
|
190
|
+
* (`^\pi`), and bare-token (`_0`, `^1`) forms. Returns the mark, its raw-LaTeX value, and the next
|
|
191
|
+
* index, or `null` when there is no script at `i`.
|
|
192
|
+
*/
|
|
193
|
+
function readScript(s, i) {
|
|
194
|
+
while (s[i] === " ") i++;
|
|
195
|
+
const mark = s[i];
|
|
196
|
+
if (mark !== "_" && mark !== "^") return null;
|
|
197
|
+
i++;
|
|
198
|
+
while (s[i] === " ") i++;
|
|
199
|
+
if (s[i] === "{") {
|
|
200
|
+
let depth = 0;
|
|
201
|
+
const start = ++i;
|
|
202
|
+
for (; i < s.length; i++) if (s[i] === "{") depth++;
|
|
203
|
+
else if (s[i] === "}") {
|
|
204
|
+
if (depth === 0) break;
|
|
205
|
+
depth--;
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
mark,
|
|
209
|
+
val: s.slice(start, i),
|
|
210
|
+
next: i + 1
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
if (s[i] === "\\") {
|
|
214
|
+
const m = /^\\[a-zA-Z]+/.exec(s.slice(i));
|
|
215
|
+
if (!m) return null;
|
|
216
|
+
return {
|
|
217
|
+
mark,
|
|
218
|
+
val: m[0],
|
|
219
|
+
next: i + m[0].length
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
const m = /^[A-Za-z0-9.]+/.exec(s.slice(i));
|
|
223
|
+
if (!m) return null;
|
|
224
|
+
return {
|
|
225
|
+
mark,
|
|
226
|
+
val: m[0],
|
|
227
|
+
next: i + m[0].length
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
/** Translate a raw-LaTeX bound/target fragment and evaluate it to a finite number. */
|
|
231
|
+
function evalBound(latex) {
|
|
232
|
+
const trimmed = latex.trim();
|
|
233
|
+
if (/\\infty/.test(trimmed)) throw new CalculusError("INFINITE_BOUND");
|
|
234
|
+
const mathjsExpr = translateLatex(trimmed);
|
|
235
|
+
const value = math.evaluate(mathjsExpr);
|
|
236
|
+
if (typeof value !== "number" || !Number.isFinite(value)) throw new CalculusError("BAD_BOUND");
|
|
237
|
+
return value;
|
|
238
|
+
}
|
|
239
|
+
/** Evaluate a definite integral `\int_{a}^{b} f \,dx` by Simpson quadrature. */
|
|
240
|
+
function evalIntegral(s) {
|
|
241
|
+
const m = /\\int(?:\\limits)?/.exec(s);
|
|
242
|
+
if (!m) throw new CalculusError("NOT_INTEGRAL");
|
|
243
|
+
let i = m.index + m[0].length;
|
|
244
|
+
const scripts = {
|
|
245
|
+
"_": void 0,
|
|
246
|
+
"^": void 0
|
|
247
|
+
};
|
|
248
|
+
for (let k = 0; k < 2; k++) {
|
|
249
|
+
const sc = readScript(s, i);
|
|
250
|
+
if (!sc) break;
|
|
251
|
+
scripts[sc.mark] = sc.val;
|
|
252
|
+
i = sc.next;
|
|
253
|
+
}
|
|
254
|
+
if (scripts._ === void 0 || scripts["^"] === void 0) throw new CalculusError("INDEFINITE");
|
|
255
|
+
const rest = s.slice(i);
|
|
256
|
+
const diff = /\\?,?\s*\bd\s*([a-zA-Z])\s*$/.exec(rest);
|
|
257
|
+
if (!diff) throw new CalculusError("NO_DIFFERENTIAL");
|
|
258
|
+
const variable = diff[1];
|
|
259
|
+
const integrandLatex = rest.slice(0, diff.index);
|
|
260
|
+
if (integrandLatex.trim().length === 0) throw new CalculusError("NO_INTEGRAND");
|
|
261
|
+
const a = evalBound(scripts._);
|
|
262
|
+
const b = evalBound(scripts["^"]);
|
|
263
|
+
const integrand = translateLatex(integrandLatex);
|
|
264
|
+
const fn = (x) => evalAt(integrand, variable, x);
|
|
265
|
+
let result;
|
|
266
|
+
if (a === b) result = 0;
|
|
267
|
+
else if (a < b) result = simpson(fn, a, b);
|
|
268
|
+
else result = -simpson(fn, b, a);
|
|
269
|
+
return `Converted: ∫(${integrand}) d${variable} from ${formatNumeric(a)} to ${formatNumeric(b)}\nResult (numeric): ${formatNumeric(result)}`;
|
|
270
|
+
}
|
|
271
|
+
/** Evaluate a derivative `\frac{d}{dx} f \big|_{x=a}` at a point via central finite difference. */
|
|
272
|
+
function evalDerivative(s) {
|
|
273
|
+
let variable;
|
|
274
|
+
let body = s;
|
|
275
|
+
const fracOp = /\\frac\s*\{\s*d\s*\}\s*\{\s*d\s*([a-zA-Z])\s*\}/.exec(s);
|
|
276
|
+
if (fracOp) {
|
|
277
|
+
variable = fracOp[1];
|
|
278
|
+
body = s.slice(fracOp.index + fracOp[0].length);
|
|
279
|
+
} else {
|
|
280
|
+
const bareOp = /(?:^|[^a-zA-Z])d\s*\/\s*d([a-zA-Z])/.exec(s);
|
|
281
|
+
if (bareOp) {
|
|
282
|
+
variable = bareOp[1];
|
|
283
|
+
body = s.slice(bareOp.index + bareOp[0].length);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
if (!variable) throw new CalculusError("NOT_DERIVATIVE");
|
|
287
|
+
body = body.replace(/\\left\.?/g, "").replace(/\\right\.?/g, "");
|
|
288
|
+
const bar = /\\?(?:Big|big|bigg|Bigg)?\s*\|\s*_\s*\{?\s*([a-zA-Z])\s*=\s*([^}]+?)\s*\}?\s*$/.exec(body);
|
|
289
|
+
if (!bar) throw new CalculusError("NO_POINT");
|
|
290
|
+
const point = evalBound(bar[2]);
|
|
291
|
+
let fnLatex = body.slice(0, bar.index).trim();
|
|
292
|
+
fnLatex = fnLatex.replace(/^\\?\(([\s\S]*)\\?\)$/, "$1").replace(/^\[([\s\S]*)\]$/, "$1").trim();
|
|
293
|
+
if (fnLatex.length === 0) throw new CalculusError("NO_FUNCTION");
|
|
294
|
+
const expr = translateLatex(fnLatex);
|
|
295
|
+
const h = 1e-6;
|
|
296
|
+
const fn = (x) => evalAt(expr, variable, x);
|
|
297
|
+
const result = (fn(point + h) - fn(point - h)) / (2 * h);
|
|
298
|
+
if (!Number.isFinite(result)) throw new CalculusError("NON_FINITE");
|
|
299
|
+
return `Converted: d/d${variable}(${expr}) at ${variable}=${formatNumeric(point)}\nResult (numeric): ${formatNumeric(result)}`;
|
|
300
|
+
}
|
|
301
|
+
/** Evaluate a limit `\lim_{x \to a} f(x)` by a two-sided numeric approach. */
|
|
302
|
+
function evalLimit(s) {
|
|
303
|
+
const head = /\\lim\s*_\s*\{\s*([a-zA-Z])\s*\\to\s*([\s\S]+?)\s*\}/.exec(s);
|
|
304
|
+
if (!head) throw new CalculusError("NOT_LIMIT");
|
|
305
|
+
const variable = head[1];
|
|
306
|
+
let targetLatex = head[2].trim();
|
|
307
|
+
const bodyLatex = s.slice(head.index + head[0].length).trim();
|
|
308
|
+
if (bodyLatex.length === 0) throw new CalculusError("NO_FUNCTION");
|
|
309
|
+
let side = "both";
|
|
310
|
+
const oneSided = /\^\s*\{?\s*([+-])\s*\}?\s*$/.exec(targetLatex);
|
|
311
|
+
if (oneSided) {
|
|
312
|
+
side = oneSided[1] === "+" ? "plus" : "minus";
|
|
313
|
+
targetLatex = targetLatex.slice(0, oneSided.index).trim();
|
|
314
|
+
}
|
|
315
|
+
const expr = translateLatex(bodyLatex);
|
|
316
|
+
const fn = (x) => evalAt(expr, variable, x);
|
|
317
|
+
const eps = 1e-6;
|
|
318
|
+
let result;
|
|
319
|
+
let targetLabel;
|
|
320
|
+
if (/^-\s*\\infty$/.test(targetLatex)) {
|
|
321
|
+
result = fn(-1e8);
|
|
322
|
+
targetLabel = "-∞";
|
|
323
|
+
} else if (/^\\infty$/.test(targetLatex)) {
|
|
324
|
+
result = fn(1e8);
|
|
325
|
+
targetLabel = "∞";
|
|
326
|
+
} else {
|
|
327
|
+
const target = evalBound(targetLatex);
|
|
328
|
+
targetLabel = formatNumeric(target);
|
|
329
|
+
if (side === "plus") result = fn(target + eps);
|
|
330
|
+
else if (side === "minus") result = fn(target - eps);
|
|
331
|
+
else {
|
|
332
|
+
const lo = fn(target - eps);
|
|
333
|
+
const hi = fn(target + eps);
|
|
334
|
+
const avg = (lo + hi) / 2;
|
|
335
|
+
if (Math.abs(hi - lo) > .001 * Math.max(1, Math.abs(avg))) throw new CalculusError("LIMIT_MISMATCH");
|
|
336
|
+
result = avg;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
if (!Number.isFinite(result)) throw new CalculusError("LIMIT_UNBOUNDED");
|
|
340
|
+
const nearest = Math.round(result);
|
|
341
|
+
if (Math.abs(result - nearest) < 1e-6) result = nearest;
|
|
342
|
+
return `Converted: lim ${variable}→${targetLabel} of (${expr})\nResult (numeric): ${formatNumeric(result)}`;
|
|
343
|
+
}
|
|
344
|
+
/** Human-readable, model-actionable message for each {@link CalculusError} tag. */
|
|
345
|
+
function calculusErrorMessage(tag) {
|
|
346
|
+
switch (tag) {
|
|
347
|
+
case "INDEFINITE": return "Cannot evaluate an indefinite integral numerically. Provide bounds, e.g. \\int_{0}^{1} x dx.";
|
|
348
|
+
case "NO_DIFFERENTIAL": return "Could not find the integration variable. Expected a trailing differential like 'dx'.";
|
|
349
|
+
case "NO_INTEGRAND": return "The integral has no integrand to evaluate.";
|
|
350
|
+
case "INFINITE_BOUND": return "Infinite integration bounds are not supported. Provide finite numeric bounds, e.g. \\int_{0}^{1} f dx.";
|
|
351
|
+
case "BAD_BOUND": return "Could not evaluate the integration bounds to numbers.";
|
|
352
|
+
case "NO_POINT": return "Cannot evaluate a derivative numerically without a point. Specify where, e.g. \\frac{d}{dx}(x^2)\\Big|_{x=3}.";
|
|
353
|
+
case "NO_FUNCTION": return "Could not find the function to evaluate.";
|
|
354
|
+
case "LIMIT_MISMATCH": return "The limit may not exist (left and right values disagree).";
|
|
355
|
+
case "LIMIT_UNBOUNDED": return "The limit appears to diverge (function is unbounded near the target).";
|
|
356
|
+
case "NON_FINITE": return "The expression is not finite over the requested range (possible singularity); cannot evaluate numerically.";
|
|
357
|
+
default: return "Could not evaluate the calculus expression.";
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Detects a calculus construct in raw LaTeX and routes it to the matching numeric handler. Returns
|
|
362
|
+
* the result/error string, or `null` when the input is not a calculus expression (so the caller
|
|
363
|
+
* falls through to the scalar evaluation path unchanged).
|
|
364
|
+
*/
|
|
365
|
+
function tryCalculus(latex) {
|
|
366
|
+
let s = latex.trim();
|
|
367
|
+
s = s.replace(/^\$\$?|\$\$?$/g, "");
|
|
368
|
+
s = s.replace(/^\\[[(]|\\[\])]$/g, "").trim();
|
|
369
|
+
let handler;
|
|
370
|
+
if (/\\int/.test(s)) handler = evalIntegral;
|
|
371
|
+
else if (/\\lim/.test(s)) handler = evalLimit;
|
|
372
|
+
else if (/\\frac\s*\{\s*d\s*\}\s*\{\s*d\s*[a-zA-Z]\s*\}/.test(s) || /(?:^|[^a-zA-Z])d\s*\/\s*d[a-zA-Z]/.test(s)) handler = evalDerivative;
|
|
373
|
+
if (!handler) return null;
|
|
374
|
+
try {
|
|
375
|
+
return handler(s);
|
|
376
|
+
} catch (err) {
|
|
377
|
+
if (require_tool_registry.isInstanceOf(err, "CalculusError", CalculusError)) return `Error: ${calculusErrorMessage(err.message)}`;
|
|
378
|
+
return `Error: ${require_tool_registry.isError(err) ? err.message : String(err)}`;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
73
381
|
/**
|
|
74
382
|
* Evaluates a mathjs-syntax expression and returns the numeric result alongside the KaTeX
|
|
75
383
|
* representation of the parsed expression.
|
|
@@ -101,29 +409,39 @@ var calculateTool = new require_tool.Tool({
|
|
|
101
409
|
}
|
|
102
410
|
});
|
|
103
411
|
/**
|
|
104
|
-
* Translates a LaTeX/KaTeX expression
|
|
412
|
+
* Translates a LaTeX/KaTeX expression using evaluatex and returns the numeric result.
|
|
105
413
|
*
|
|
106
414
|
* @remarks
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
415
|
+
* Uses the evaluatex library to parse and evaluate LaTeX expressions. Handles common constructs
|
|
416
|
+
* (`\frac{a}{b}`, `\sqrt{...}`, `\cdot`, `\times`, Greek macros like `\pi`, inverse trig,
|
|
417
|
+
* `\left`/`\right` delimiters, `\text{...}`, subscripts, etc.) with a proper parser rather than
|
|
418
|
+
* brittle regex.
|
|
419
|
+
*
|
|
420
|
+
* Also evaluates three calculus constructs **numerically** (mathjs has no symbolic integration, and
|
|
421
|
+
* its symbolic `derivative` is blocklisted here for safety):
|
|
422
|
+
* - Definite integrals — `\int_{a}^{b} f \,dx` via composite Simpson quadrature.
|
|
423
|
+
* - Derivatives at a point — `\frac{d}{dx} f \big|_{x=a}` via central finite difference.
|
|
424
|
+
* - Limits — `\lim_{x \to a} f` (including `a = \pm\infty`) via a two-sided numeric approach.
|
|
425
|
+
*
|
|
426
|
+
* Numeric results are rounded with `math.format(..., { precision: 12 })` and labelled
|
|
427
|
+
* `Result (numeric):` to flag that they are approximations. Constructs that cannot be evaluated
|
|
428
|
+
* numerically (indefinite integrals, derivatives without a point, infinite integration bounds,
|
|
429
|
+
* singular integrands, divergent limits) return a specific, guiding error string.
|
|
111
430
|
*
|
|
112
431
|
* Parse and evaluation errors are returned as error strings rather than thrown.
|
|
113
432
|
*/
|
|
114
433
|
var evaluateKatexTool = new require_tool.Tool({
|
|
115
434
|
name: "evaluate_katex",
|
|
116
|
-
description: "Evaluate a KaTeX/LaTeX math expression and return the numeric result.",
|
|
117
|
-
inputSchema: _nhtio_validation.validator.object({ katex: _nhtio_validation.validator.string().required().description("LaTeX expression, e.g. \"\\frac{1}{2} + \\sqrt{9}\"") }),
|
|
435
|
+
description: "Evaluate a KaTeX/LaTeX math expression and return the numeric result. Supports arithmetic, trig, logs, roots, and numeric calculus: definite integrals (\\int_{a}^{b} f dx), derivatives at a point (\\frac{d}{dx} f|_{x=a}), and limits (\\lim_{x \\to a} f).",
|
|
436
|
+
inputSchema: _nhtio_validation.validator.object({ katex: _nhtio_validation.validator.string().required().description("LaTeX expression, e.g. \"\\frac{1}{2} + \\sqrt{9}\" or \"\\int_{0}^{1} x^2 dx\"") }),
|
|
118
437
|
handler: async (args) => {
|
|
119
438
|
const { katex } = args;
|
|
120
439
|
const lengthError = validateExpression(katex);
|
|
121
440
|
if (lengthError) return lengthError;
|
|
122
441
|
try {
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return `Converted: ${mathjsExpr}\nResult: ${math.evaluate(mathjsExpr)}`;
|
|
442
|
+
const calculus = tryCalculus(katex);
|
|
443
|
+
if (calculus !== null) return calculus;
|
|
444
|
+
return `Result: ${evaluateLatex(katex)}`;
|
|
127
445
|
} catch (err) {
|
|
128
446
|
return `Error: ${require_tool_registry.isError(err) ? err.message : String(err)}`;
|
|
129
447
|
}
|