@nhtio/adk 0.1.0-master-e5947c71 → 0.1.0-master-74266e68
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 +124 -1
- package/artifact_methods-BvoDGBnH.cjs +1 -0
- package/artifact_methods-q52ETLwI.mjs +1 -0
- package/batteries/artifacts/ecmascript.cjs +1 -1
- package/batteries/artifacts/ecmascript.mjs +1 -1
- package/batteries/artifacts/toon.cjs +1 -1
- package/batteries/artifacts/toon.mjs +1 -1
- package/batteries/artifacts/xml.cjs +1 -1
- package/batteries/artifacts/xml.mjs +1 -1
- package/batteries/artifacts/yaml.cjs +1 -1
- package/batteries/artifacts/yaml.mjs +1 -1
- package/batteries/artifacts.cjs +4 -4
- package/batteries/artifacts.mjs +4 -4
- package/batteries/dev-tools/forge.cjs +3 -3
- package/batteries/dev-tools/forge.mjs +3 -3
- package/batteries/dev-tools.cjs +2 -2
- package/batteries/dev-tools.mjs +2 -2
- package/batteries/encoding.cjs +7 -7
- package/batteries/encoding.mjs +7 -7
- package/batteries/generation/gemini/adapter.cjs +1 -1
- package/batteries/generation/gemini/adapter.mjs +1 -1
- package/batteries/generation/local_diffusion/adapter.cjs +1 -1
- package/batteries/generation/local_diffusion/adapter.mjs +1 -1
- package/batteries/generation/openai/adapter.cjs +1 -1
- package/batteries/generation/openai/adapter.mjs +1 -1
- package/batteries/llm/anthropic_messages/adapter.cjs +6 -6
- package/batteries/llm/anthropic_messages/adapter.mjs +6 -6
- package/batteries/llm/anthropic_messages/count_tokens.cjs +2 -2
- package/batteries/llm/anthropic_messages/count_tokens.mjs +1 -1
- package/batteries/llm/anthropic_messages/helpers.cjs +3 -3
- package/batteries/llm/anthropic_messages/helpers.mjs +3 -3
- package/batteries/llm/anthropic_messages/validation.cjs +2 -2
- package/batteries/llm/anthropic_messages/validation.mjs +2 -2
- package/batteries/llm/anthropic_messages.cjs +2 -2
- package/batteries/llm/anthropic_messages.mjs +2 -2
- package/batteries/llm/bedrock_converse/adapter.cjs +6 -6
- package/batteries/llm/bedrock_converse/adapter.mjs +6 -6
- package/batteries/llm/bedrock_converse/helpers.cjs +1 -1
- package/batteries/llm/bedrock_converse/helpers.mjs +1 -1
- package/batteries/llm/bedrock_converse/validation.cjs +2 -2
- package/batteries/llm/bedrock_converse/validation.mjs +2 -2
- package/batteries/llm/bedrock_converse.cjs +2 -2
- package/batteries/llm/bedrock_converse.mjs +2 -2
- package/batteries/llm/claude_code_cli/adapter.cjs +7 -7
- package/batteries/llm/claude_code_cli/adapter.mjs +7 -7
- package/batteries/llm/claude_code_cli/helpers.cjs +3 -3
- package/batteries/llm/claude_code_cli/helpers.mjs +3 -3
- package/batteries/llm/claude_code_cli/validation.cjs +2 -2
- package/batteries/llm/claude_code_cli/validation.mjs +2 -2
- package/batteries/llm/claude_code_cli.cjs +2 -2
- package/batteries/llm/claude_code_cli.mjs +2 -2
- package/batteries/llm/gemini_generate_content/adapter.cjs +7 -7
- package/batteries/llm/gemini_generate_content/adapter.mjs +7 -7
- package/batteries/llm/gemini_generate_content/helpers.cjs +1 -1
- package/batteries/llm/gemini_generate_content/helpers.mjs +1 -1
- package/batteries/llm/gemini_generate_content/validation.cjs +2 -2
- package/batteries/llm/gemini_generate_content/validation.mjs +2 -2
- package/batteries/llm/gemini_generate_content.cjs +2 -2
- package/batteries/llm/gemini_generate_content.mjs +2 -2
- package/batteries/llm/litert_lm/adapter.cjs +6 -6
- package/batteries/llm/litert_lm/adapter.mjs +6 -6
- package/batteries/llm/litert_lm/helpers.cjs +3 -3
- package/batteries/llm/litert_lm/helpers.mjs +3 -3
- package/batteries/llm/litert_lm/validation.cjs +2 -2
- package/batteries/llm/litert_lm/validation.mjs +2 -2
- package/batteries/llm/litert_lm.cjs +1 -1
- package/batteries/llm/litert_lm.mjs +1 -1
- package/batteries/llm/ollama/adapter.cjs +6 -6
- package/batteries/llm/ollama/adapter.mjs +6 -6
- package/batteries/llm/ollama/helpers.cjs +4 -4
- package/batteries/llm/ollama/helpers.mjs +4 -4
- package/batteries/llm/ollama/validation.cjs +2 -2
- package/batteries/llm/ollama/validation.mjs +2 -2
- package/batteries/llm/ollama.cjs +2 -2
- package/batteries/llm/ollama.mjs +2 -2
- package/batteries/llm/openai_chat_completions/adapter.cjs +6 -6
- package/batteries/llm/openai_chat_completions/adapter.mjs +6 -6
- package/batteries/llm/openai_chat_completions/helpers.cjs +4 -4
- package/batteries/llm/openai_chat_completions/helpers.mjs +4 -4
- package/batteries/llm/openai_chat_completions/validation.cjs +2 -2
- package/batteries/llm/openai_chat_completions/validation.mjs +2 -2
- package/batteries/llm/openai_chat_completions.cjs +2 -2
- package/batteries/llm/openai_chat_completions.mjs +2 -2
- package/batteries/llm/openai_responses/adapter.cjs +6 -6
- package/batteries/llm/openai_responses/adapter.mjs +6 -6
- package/batteries/llm/openai_responses/helpers.cjs +3 -3
- package/batteries/llm/openai_responses/helpers.mjs +3 -3
- package/batteries/llm/openai_responses/validation.cjs +2 -2
- package/batteries/llm/openai_responses/validation.mjs +2 -2
- package/batteries/llm/openai_responses.cjs +2 -2
- package/batteries/llm/openai_responses.mjs +2 -2
- package/batteries/llm/transformers_js/adapter.cjs +6 -6
- package/batteries/llm/transformers_js/adapter.mjs +6 -6
- package/batteries/llm/transformers_js/helpers.cjs +3 -3
- package/batteries/llm/transformers_js/helpers.mjs +3 -3
- package/batteries/llm/transformers_js/validation.cjs +2 -2
- package/batteries/llm/transformers_js/validation.mjs +2 -2
- package/batteries/llm/transformers_js.cjs +1 -1
- package/batteries/llm/transformers_js.mjs +1 -1
- package/batteries/llm/webllm_chat_completions/adapter.cjs +6 -6
- package/batteries/llm/webllm_chat_completions/adapter.mjs +6 -6
- package/batteries/llm/webllm_chat_completions/helpers.cjs +1 -1
- package/batteries/llm/webllm_chat_completions/helpers.mjs +1 -1
- package/batteries/llm/webllm_chat_completions/validation.cjs +2 -2
- package/batteries/llm/webllm_chat_completions/validation.mjs +2 -2
- package/batteries/llm/webllm_chat_completions.cjs +2 -2
- package/batteries/llm/webllm_chat_completions.mjs +2 -2
- package/batteries/llm.cjs +2 -2
- package/batteries/llm.mjs +2 -2
- package/batteries/media/contracts.cjs.map +1 -1
- package/batteries/media/contracts.d.ts +93 -2
- package/batteries/media/contracts.mjs.map +1 -1
- package/batteries/media/engines/execa_executor.cjs +285 -13
- package/batteries/media/engines/execa_executor.cjs.map +1 -1
- package/batteries/media/engines/execa_executor.d.ts +113 -8
- package/batteries/media/engines/execa_executor.mjs +285 -13
- package/batteries/media/engines/execa_executor.mjs.map +1 -1
- package/batteries/media/forge.cjs +4 -4
- package/batteries/media/forge.mjs +4 -4
- package/batteries/media/lint.cjs +1 -1
- package/batteries/media/lint.mjs +1 -1
- package/batteries/media.cjs +1 -1
- package/batteries/orchestration/dispatch_reasoner.cjs +4 -4
- package/batteries/orchestration/dispatch_reasoner.mjs +4 -4
- package/batteries/orchestration/executor.cjs +2 -2
- package/batteries/orchestration/executor.mjs +2 -2
- package/batteries/orchestration/forge.cjs +3 -3
- package/batteries/orchestration/forge.mjs +3 -3
- package/batteries/orchestration/validation.cjs +2 -2
- package/batteries/orchestration/validation.mjs +2 -2
- package/batteries/orchestration.cjs +3 -3
- package/batteries/orchestration.mjs +3 -3
- package/batteries/sandbox/contracts/policy_enforcer.d.ts +12 -6
- package/batteries/sandbox/executor.d.ts +28 -10
- package/batteries/sandbox/js.cjs +1 -1
- package/batteries/sandbox/js.mjs +1 -1
- package/batteries/sandbox/node/index.d.ts +1 -1
- package/batteries/sandbox/node/srt_enforcer.d.ts +74 -0
- package/batteries/sandbox/node.cjs +98 -5
- package/batteries/sandbox/node.cjs.map +1 -1
- package/batteries/sandbox/node.mjs +98 -6
- package/batteries/sandbox/node.mjs.map +1 -1
- package/batteries/sandbox/tools.cjs +1 -1
- package/batteries/sandbox/tools.mjs +1 -1
- package/batteries/sandbox.cjs +13 -13
- package/batteries/sandbox.cjs.map +1 -1
- package/batteries/sandbox.mjs +13 -13
- package/batteries/sandbox.mjs.map +1 -1
- package/batteries/skills/in_memory.cjs +1 -1
- package/batteries/skills.cjs +10 -10
- package/batteries/skills.mjs +9 -9
- package/batteries/tools/_shared.cjs +1 -1
- package/batteries/tools/_shared.mjs +1 -1
- package/batteries/tools/color.cjs +2 -2
- package/batteries/tools/color.mjs +2 -2
- package/batteries/tools/comparison.cjs +2 -2
- package/batteries/tools/comparison.mjs +2 -2
- package/batteries/tools/data_structure.cjs +2 -2
- package/batteries/tools/data_structure.mjs +2 -2
- package/batteries/tools/datetime_extended.cjs +3 -3
- package/batteries/tools/datetime_extended.mjs +3 -3
- package/batteries/tools/datetime_math.cjs +3 -3
- package/batteries/tools/datetime_math.mjs +3 -3
- package/batteries/tools/encoding.cjs +2 -2
- package/batteries/tools/encoding.mjs +2 -2
- package/batteries/tools/formatting.cjs +2 -2
- package/batteries/tools/formatting.mjs +2 -2
- package/batteries/tools/geo_basics.cjs +2 -2
- package/batteries/tools/geo_basics.mjs +2 -2
- package/batteries/tools/math.cjs +2 -2
- package/batteries/tools/math.mjs +2 -2
- package/batteries/tools/memory.cjs +5 -5
- package/batteries/tools/memory.mjs +5 -5
- package/batteries/tools/parsing.cjs +3 -3
- package/batteries/tools/parsing.mjs +3 -3
- package/batteries/tools/retrievables.cjs +5 -5
- package/batteries/tools/retrievables.mjs +5 -5
- package/batteries/tools/scrapper.cjs +1 -1
- package/batteries/tools/scrapper.mjs +1 -1
- package/batteries/tools/searxng.cjs +1 -1
- package/batteries/tools/searxng.mjs +1 -1
- package/batteries/tools/standing_instructions.cjs +3 -3
- package/batteries/tools/standing_instructions.mjs +3 -3
- package/batteries/tools/statistics.cjs +3 -3
- package/batteries/tools/statistics.mjs +3 -3
- package/batteries/tools/string_processing.cjs +2 -2
- package/batteries/tools/string_processing.mjs +2 -2
- package/batteries/tools/structured_data.cjs +2 -2
- package/batteries/tools/structured_data.mjs +2 -2
- 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 +3 -3
- package/batteries/tools/time.mjs +3 -3
- package/batteries/tools/unit_conversion.cjs +2 -2
- package/batteries/tools/unit_conversion.mjs +2 -2
- package/batteries/tools.cjs +2 -2
- package/batteries/tools.mjs +2 -2
- package/batteries/validation.cjs +4 -4
- package/batteries/validation.mjs +4 -4
- package/batteries/vector/chroma.cjs +1 -1
- package/batteries/vector/chroma.mjs +1 -1
- package/batteries/vector/clickhouse.cjs +1 -1
- package/batteries/vector/clickhouse.mjs +1 -1
- package/batteries/vector/cloudflare.cjs +1 -1
- package/batteries/vector/cloudflare.mjs +1 -1
- package/batteries/vector/couchbase.cjs +1 -1
- package/batteries/vector/couchbase.mjs +1 -1
- package/batteries/vector/duckdb.cjs +1 -1
- package/batteries/vector/duckdb.mjs +1 -1
- package/batteries/vector/elasticsearch.cjs +1 -1
- package/batteries/vector/elasticsearch.mjs +1 -1
- package/batteries/vector/hnswlib.cjs +1 -1
- package/batteries/vector/hnswlib.mjs +1 -1
- package/batteries/vector/in_memory.cjs +1 -1
- package/batteries/vector/in_memory.mjs +1 -1
- package/batteries/vector/lancedb.cjs +1 -1
- package/batteries/vector/lancedb.mjs +1 -1
- package/batteries/vector/mariadb.cjs +1 -1
- package/batteries/vector/mariadb.mjs +1 -1
- package/batteries/vector/milvus.cjs +1 -1
- package/batteries/vector/milvus.mjs +1 -1
- package/batteries/vector/opensearch.cjs +1 -1
- package/batteries/vector/opensearch.mjs +1 -1
- package/batteries/vector/oracle23ai.cjs +1 -1
- package/batteries/vector/oracle23ai.mjs +1 -1
- package/batteries/vector/orama.cjs +1 -1
- package/batteries/vector/orama.mjs +1 -1
- package/batteries/vector/pgvector.cjs +1 -1
- package/batteries/vector/pgvector.mjs +1 -1
- package/batteries/vector/pinecone.cjs +1 -1
- package/batteries/vector/pinecone.mjs +1 -1
- package/batteries/vector/qdrant.cjs +1 -1
- package/batteries/vector/qdrant.mjs +1 -1
- package/batteries/vector/redis.cjs +1 -1
- package/batteries/vector/redis.mjs +1 -1
- package/batteries/vector/retrievable.cjs +1 -1
- package/batteries/vector/retrievable.mjs +1 -1
- package/batteries/vector/s3vectors.cjs +1 -1
- package/batteries/vector/s3vectors.mjs +1 -1
- package/batteries/vector/sqlite_vec.cjs +1 -1
- package/batteries/vector/sqlite_vec.mjs +1 -1
- package/batteries/vector/typesense.cjs +1 -1
- package/batteries/vector/typesense.mjs +1 -1
- package/batteries/vector/vespa.cjs +1 -1
- package/batteries/vector/vespa.mjs +1 -1
- package/batteries/vector/weaviate.cjs +1 -1
- package/batteries/vector/weaviate.mjs +1 -1
- package/batteries/vector.cjs +2 -2
- package/batteries/vector.mjs +2 -2
- package/batteries.cjs +9 -9
- package/batteries.mjs +9 -9
- package/{chat_common-DKw8FDol.mjs → chat_common-CeoHwSsz.mjs} +2 -2
- package/{chat_common-DKw8FDol.mjs.map → chat_common-CeoHwSsz.mjs.map} +1 -1
- package/{chat_common-vSxDBGgr.cjs → chat_common-DlIK1IAn.cjs} +2 -2
- package/{chat_common-vSxDBGgr.cjs.map → chat_common-DlIK1IAn.cjs.map} +1 -1
- package/{common-oI1niK9Z.mjs → common-B5maOoF_.mjs} +7 -7
- package/{common-oI1niK9Z.mjs.map → common-B5maOoF_.mjs.map} +1 -1
- package/{common-BcB05Isq.cjs → common-joo6vLu-.cjs} +7 -7
- package/{common-BcB05Isq.cjs.map → common-joo6vLu-.cjs.map} +1 -1
- package/common.cjs +7 -7
- package/common.mjs +7 -7
- package/{dispatch_runner-CTAI0RSs.cjs → dispatch_runner-BTaUtdtO.cjs} +5 -5
- package/{dispatch_runner-CTAI0RSs.cjs.map → dispatch_runner-BTaUtdtO.cjs.map} +1 -1
- package/{dispatch_runner-BZDXUe0G.mjs → dispatch_runner-DO7jo_gl.mjs} +5 -5
- package/{dispatch_runner-BZDXUe0G.mjs.map → dispatch_runner-DO7jo_gl.mjs.map} +1 -1
- package/dispatch_runner.cjs +1 -1
- package/dispatch_runner.mjs +1 -1
- package/{ecmascript-DOv8gVQ5.cjs → ecmascript-ChvxTCXz.cjs} +3 -3
- package/{ecmascript-DOv8gVQ5.cjs.map → ecmascript-ChvxTCXz.cjs.map} +1 -1
- package/{ecmascript-B9Z2C24U.mjs → ecmascript-bgwVyZG1.mjs} +3 -3
- package/{ecmascript-B9Z2C24U.mjs.map → ecmascript-bgwVyZG1.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.cjs +1 -1
- package/exceptions.mjs +1 -1
- package/forge.cjs +2 -2
- package/forge.mjs +2 -2
- package/guards.cjs +7 -7
- package/guards.mjs +7 -7
- package/{helpers-mbn_EsDV.mjs → helpers-C1T0DV8Q.mjs} +3 -3
- package/{helpers-mbn_EsDV.mjs.map → helpers-C1T0DV8Q.mjs.map} +1 -1
- package/{helpers-CiZnHmxC.cjs → helpers-D6ebO8Vc.cjs} +3 -3
- package/{helpers-CiZnHmxC.cjs.map → helpers-D6ebO8Vc.cjs.map} +1 -1
- package/index.cjs +10 -10
- package/index.mjs +10 -10
- package/{manifest-BPcrFRN4.cjs → manifest-DPYWN15l.cjs} +2 -2
- package/{manifest-BPcrFRN4.cjs.map → manifest-DPYWN15l.cjs.map} +1 -1
- package/mcp/adk-docs-corpus.json +2 -2
- package/package.json +407 -407
- package/{retrievable-CXTAUuuv.mjs → retrievable-CrGKx4sc.mjs} +3 -3
- package/{retrievable-CXTAUuuv.mjs.map → retrievable-CrGKx4sc.mjs.map} +1 -1
- package/{retrievable-BOuQSDHF.cjs → retrievable-DVkAglIv.cjs} +3 -3
- package/{retrievable-BOuQSDHF.cjs.map → retrievable-DVkAglIv.cjs.map} +1 -1
- package/{scrapper-lXnFGDi0.cjs → scrapper-Boc6kq2v.cjs} +4 -4
- package/{scrapper-lXnFGDi0.cjs.map → scrapper-Boc6kq2v.cjs.map} +1 -1
- package/{scrapper-BCdUm8c8.mjs → scrapper-D2Gy9Jhv.mjs} +4 -4
- package/{scrapper-BCdUm8c8.mjs.map → scrapper-D2Gy9Jhv.mjs.map} +1 -1
- package/{searxng-N7qu6dA-.cjs → searxng-DOy3eBDH.cjs} +4 -4
- package/{searxng-N7qu6dA-.cjs.map → searxng-DOy3eBDH.cjs.map} +1 -1
- package/{searxng-B-LdaVUP.mjs → searxng-cCb0lAcN.mjs} +4 -4
- package/{searxng-B-LdaVUP.mjs.map → searxng-cCb0lAcN.mjs.map} +1 -1
- package/server.json +2 -2
- package/skills/adk-assembly/SKILL.md +2 -2
- package/{spooled_artifact-Bw_7swIp.mjs → spooled_artifact-BkOe4-j-.mjs} +731 -731
- package/spooled_artifact-BkOe4-j-.mjs.map +1 -0
- package/{spooled_artifact-DZXsP4s1.cjs → spooled_artifact-BoYsldvO.cjs} +730 -730
- package/spooled_artifact-BoYsldvO.cjs.map +1 -0
- package/spooled_artifact.cjs +2 -2
- package/spooled_artifact.mjs +2 -2
- package/{spooled_markdown_artifact-vd6eNtIP.mjs → spooled_markdown_artifact-Dnl-lCGv.mjs} +3 -3
- package/{spooled_markdown_artifact-vd6eNtIP.mjs.map → spooled_markdown_artifact-Dnl-lCGv.mjs.map} +1 -1
- package/{spooled_markdown_artifact-Bo0u8cRS.cjs → spooled_markdown_artifact-DzbydBel.cjs} +3 -3
- package/{spooled_markdown_artifact-Bo0u8cRS.cjs.map → spooled_markdown_artifact-DzbydBel.cjs.map} +1 -1
- package/{thought-CxSaF6Xf.mjs → thought-BrQt6HAb.mjs} +3 -3
- package/{thought-CxSaF6Xf.mjs.map → thought-BrQt6HAb.mjs.map} +1 -1
- package/{thought-C12mqaKQ.cjs → thought-CXsVh5hS.cjs} +3 -3
- package/{thought-C12mqaKQ.cjs.map → thought-CXsVh5hS.cjs.map} +1 -1
- package/{tokenizable-BcodRtoW.cjs → tokenizable-DDIdXbJN.cjs} +29 -29
- package/{tokenizable-BcodRtoW.cjs.map → tokenizable-DDIdXbJN.cjs.map} +1 -1
- package/{tokenizable-VB4Av8GF.mjs → tokenizable-xPXj1AQX.mjs} +30 -30
- package/{tokenizable-VB4Av8GF.mjs.map → tokenizable-xPXj1AQX.mjs.map} +1 -1
- package/{tool_call-Cfaj-6zK.mjs → tool_call-8crmZsO8.mjs} +4 -4
- package/{tool_call-Cfaj-6zK.mjs.map → tool_call-8crmZsO8.mjs.map} +1 -1
- package/{tool_call-CsBOpKsg.cjs → tool_call-NvQcPf5d.cjs} +4 -4
- package/{tool_call-CsBOpKsg.cjs.map → tool_call-NvQcPf5d.cjs.map} +1 -1
- package/{tools-BjHXlDlV.cjs → tools-BHc8qB5I.cjs} +6 -6
- package/{tools-BjHXlDlV.cjs.map → tools-BHc8qB5I.cjs.map} +1 -1
- package/{tools-Vkfht7mU.mjs → tools-geIlta3C.mjs} +6 -6
- package/{tools-Vkfht7mU.mjs.map → tools-geIlta3C.mjs.map} +1 -1
- package/{toon-BSTQnHed.mjs → toon-BA9Q7NHG.mjs} +5 -5
- package/{toon-BSTQnHed.mjs.map → toon-BA9Q7NHG.mjs.map} +1 -1
- package/{toon-5c9ceKiU.cjs → toon-C8IFssRi.cjs} +5 -5
- package/{toon-5c9ceKiU.cjs.map → toon-C8IFssRi.cjs.map} +1 -1
- package/{turn_runner--tsMLLx4.cjs → turn_runner-A-vpLUvj.cjs} +5 -5
- package/{turn_runner--tsMLLx4.cjs.map → turn_runner-A-vpLUvj.cjs.map} +1 -1
- package/{turn_runner-BHHD6h77.mjs → turn_runner-BmVXcBZ2.mjs} +5 -5
- package/{turn_runner-BHHD6h77.mjs.map → turn_runner-BmVXcBZ2.mjs.map} +1 -1
- package/turn_runner.cjs +1 -1
- package/turn_runner.mjs +1 -1
- package/{xml-CYseDztH.mjs → xml-B1JIGLpU.mjs} +5 -5
- package/{xml-CYseDztH.mjs.map → xml-B1JIGLpU.mjs.map} +1 -1
- package/{xml-DTOnPN52.cjs → xml-Cu7ZvgBQ.cjs} +5 -5
- package/{xml-DTOnPN52.cjs.map → xml-Cu7ZvgBQ.cjs.map} +1 -1
- package/{yaml-BPBoiOjx.mjs → yaml-1mP4uxdf.mjs} +5 -5
- package/{yaml-BPBoiOjx.mjs.map → yaml-1mP4uxdf.mjs.map} +1 -1
- package/{yaml-CMrbNWLc.cjs → yaml-BlB29N68.cjs} +5 -5
- package/{yaml-CMrbNWLc.cjs.map → yaml-BlB29N68.cjs.map} +1 -1
- package/artifact_methods-Cg0go7Q4.mjs +0 -1
- package/artifact_methods-Dtf4-3C-.cjs +0 -1
- package/spooled_artifact-Bw_7swIp.mjs.map +0 -1
- package/spooled_artifact-DZXsP4s1.cjs.map +0 -1
|
@@ -22,532 +22,538 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
//#endregion
|
|
23
23
|
const require_exceptions = require("./exceptions-DrHnAGQz.cjs");
|
|
24
24
|
const require_guards = require("./guards-5-XmJgD2.cjs");
|
|
25
|
-
const require_tokenizable = require("./tokenizable-
|
|
25
|
+
const require_tokenizable = require("./tokenizable-DDIdXbJN.cjs");
|
|
26
|
+
let luxon = require("luxon");
|
|
27
|
+
let js_sha256 = require("js-sha256");
|
|
26
28
|
let _nhtio_validation = require("@nhtio/validation");
|
|
27
29
|
let dset = require("dset");
|
|
28
30
|
let klona = require("klona");
|
|
29
31
|
let dlv = require("dlv");
|
|
30
32
|
dlv = __toESM(dlv);
|
|
31
|
-
|
|
32
|
-
let js_sha256 = require("js-sha256");
|
|
33
|
-
//#region src/lib/classes/registry.ts
|
|
33
|
+
//#region src/lib/classes/tool_registry.ts
|
|
34
34
|
/**
|
|
35
|
-
* A
|
|
35
|
+
* A mutable, turn-scoped collection of {@link @nhtio/adk!Tool} instances.
|
|
36
36
|
*
|
|
37
37
|
* @remarks
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
38
|
+
* Each `TurnRunner.run()` call constructs a fresh `ToolRegistry` from the runner's configured
|
|
39
|
+
* baseline tools, so middleware edits are isolated to the current turn and cannot bleed across
|
|
40
|
+
* concurrent or subsequent turns.
|
|
41
41
|
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
42
|
+
* `Tool` instances are immutable, so `all()` returns a fresh array without deep-cloning.
|
|
43
|
+
*
|
|
44
|
+
* `register()` throws {@link @nhtio/adk!E_TOOL_ALREADY_REGISTERED} if a tool with the same name is already
|
|
45
|
+
* present — pass `overwrite: true` to replace it explicitly.
|
|
46
|
+
*
|
|
47
|
+
* Tools can be **hidden** — registered and callable, but excluded from the default tool list
|
|
48
|
+
* rendered to the model. This is useful for discovery patterns where an agent has a tool that
|
|
49
|
+
* enumerates available tools, and the model picks one to call by name in a subsequent iteration.
|
|
50
|
+
* Hidden state is a property of the registry, not the tool: the same tool can be visible in one
|
|
51
|
+
* registry and hidden in another. See {@link hide}, {@link visible}, {@link hidden}.
|
|
44
52
|
*/
|
|
45
|
-
var
|
|
46
|
-
#
|
|
53
|
+
var ToolRegistry = class ToolRegistry {
|
|
54
|
+
#tools;
|
|
55
|
+
#hidden;
|
|
47
56
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
57
|
+
* Returns `true` if `value` is a {@link ToolRegistry} instance.
|
|
58
|
+
*
|
|
59
|
+
* @param value - The value to test.
|
|
60
|
+
* @returns `true` when `value` is a {@link ToolRegistry} instance.
|
|
50
61
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
this.#store = initial ? (0, klona.klona)(initial) : {};
|
|
62
|
+
static isToolRegistry(value) {
|
|
63
|
+
return require_guards.isInstanceOf(value, "ToolRegistry", ToolRegistry);
|
|
54
64
|
}
|
|
55
65
|
/**
|
|
56
|
-
*
|
|
66
|
+
* @param tools - Optional initial tools. Insertion order is preserved. Duplicate names throw
|
|
67
|
+
* {@link @nhtio/adk!E_TOOL_ALREADY_REGISTERED} — ensure each tool has a unique name.
|
|
68
|
+
* @throws {@link @nhtio/adk!E_TOOL_ALREADY_REGISTERED} when two tools in `tools` share a name.
|
|
69
|
+
*/
|
|
70
|
+
constructor(tools) {
|
|
71
|
+
this.#tools = /* @__PURE__ */ new Map();
|
|
72
|
+
this.#hidden = /* @__PURE__ */ new Set();
|
|
73
|
+
for (const tool of tools ?? []) this.register(tool);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Adds a tool to the registry.
|
|
77
|
+
*
|
|
78
|
+
* @param tool - The tool to register.
|
|
79
|
+
* @param overwrite - When `true`, silently replaces an existing tool with the same name.
|
|
80
|
+
* Defaults to `false`.
|
|
81
|
+
* @throws {@link @nhtio/adk!E_TOOL_ALREADY_REGISTERED} when a tool with the same name is already registered
|
|
82
|
+
* and `overwrite` is not `true`.
|
|
83
|
+
*/
|
|
84
|
+
register(tool, overwrite) {
|
|
85
|
+
if (this.#tools.has(tool.name) && !overwrite) throw new require_tokenizable.E_TOOL_ALREADY_REGISTERED();
|
|
86
|
+
this.#tools.set(tool.name, tool);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Removes the tool with the given name from the registry.
|
|
57
90
|
*
|
|
58
91
|
* @remarks
|
|
59
|
-
*
|
|
92
|
+
* Also removes the name from the hidden set if present. No-ops if no tool with that name is
|
|
93
|
+
* registered.
|
|
60
94
|
*
|
|
61
|
-
* @param
|
|
62
|
-
* @returns `true` when `value` is a {@link Registry} instance.
|
|
95
|
+
* @param name - The name of the tool to remove.
|
|
63
96
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
97
|
+
unregister(name) {
|
|
98
|
+
this.#tools.delete(name);
|
|
99
|
+
this.#hidden.delete(name);
|
|
66
100
|
}
|
|
67
101
|
/**
|
|
68
|
-
*
|
|
102
|
+
* Returns the tool registered under `name`, or `undefined` if not present.
|
|
69
103
|
*
|
|
70
|
-
* @
|
|
71
|
-
|
|
104
|
+
* @param name - The tool name to look up.
|
|
105
|
+
*/
|
|
106
|
+
get(name) {
|
|
107
|
+
return this.#tools.get(name);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Returns `true` if a tool with the given name is registered.
|
|
72
111
|
*
|
|
73
|
-
* @
|
|
74
|
-
* @param key - Dot-delimited path into the store (e.g. `"user.name"`).
|
|
75
|
-
* @param defaultValue - Fallback returned when the path resolves to `undefined`.
|
|
76
|
-
* @returns A deep clone of the stored value cast to `T`, or `defaultValue` when the path is absent.
|
|
112
|
+
* @param name - The tool name to test.
|
|
77
113
|
*/
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return "undefined" === typeof value ? defaultValue : value;
|
|
114
|
+
has(name) {
|
|
115
|
+
return this.#tools.has(name);
|
|
81
116
|
}
|
|
82
117
|
/**
|
|
83
|
-
*
|
|
118
|
+
* Returns a fresh array of all registered tools in insertion order.
|
|
84
119
|
*
|
|
85
120
|
* @remarks
|
|
86
|
-
*
|
|
87
|
-
*
|
|
121
|
+
* Includes both visible and hidden tools. Use {@link visible} to get only non-hidden tools, or
|
|
122
|
+
* {@link hidden} to get only hidden tools.
|
|
88
123
|
*
|
|
89
|
-
* @
|
|
90
|
-
* @param value - Value to store at the path.
|
|
124
|
+
* Since {@link @nhtio/adk!Tool} instances are immutable, no deep-cloning is needed.
|
|
91
125
|
*/
|
|
92
|
-
|
|
93
|
-
|
|
126
|
+
all() {
|
|
127
|
+
return Array.from(this.#tools.values());
|
|
94
128
|
}
|
|
95
129
|
/**
|
|
96
|
-
* Returns
|
|
130
|
+
* Returns a fresh array of registered tools that are **not** hidden, in insertion order.
|
|
97
131
|
*
|
|
98
132
|
* @remarks
|
|
99
|
-
*
|
|
100
|
-
*
|
|
133
|
+
* This is the accessor LLM batteries should use when building the tool list for the model.
|
|
134
|
+
* Hidden tools are still callable (they resolve via {@link get}) but are excluded from the
|
|
135
|
+
* rendered tool definitions.
|
|
136
|
+
*/
|
|
137
|
+
visible() {
|
|
138
|
+
return this.all().filter((t) => !this.#hidden.has(t.name));
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Returns a fresh array of registered tools that **are** hidden, in insertion order.
|
|
101
142
|
*
|
|
102
|
-
* @
|
|
103
|
-
*
|
|
143
|
+
* @remarks
|
|
144
|
+
* The converse of {@link visible}. Useful for discovery tools that enumerate all available
|
|
145
|
+
* tools, and for propagating hidden state across {@link merge}.
|
|
104
146
|
*/
|
|
105
|
-
|
|
106
|
-
return
|
|
147
|
+
hidden() {
|
|
148
|
+
return this.all().filter((t) => this.#hidden.has(t.name));
|
|
107
149
|
}
|
|
108
150
|
/**
|
|
109
|
-
*
|
|
151
|
+
* Marks one or more registered tools as hidden.
|
|
110
152
|
*
|
|
111
153
|
* @remarks
|
|
112
|
-
*
|
|
113
|
-
*
|
|
154
|
+
* Hidden tools remain registered and callable via {@link get}, but are excluded from
|
|
155
|
+
* {@link visible} (and therefore from the LLM tool list). No-ops for any name that is not
|
|
156
|
+
* currently registered — the end result (the tool is not visible) matches the intent.
|
|
114
157
|
*
|
|
115
|
-
* @
|
|
158
|
+
* @param names - One or more tool names to hide.
|
|
116
159
|
*/
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
const keys = [];
|
|
120
|
-
const isPlainRecord = (value) => {
|
|
121
|
-
if (!require_guards.isObject(value)) return false;
|
|
122
|
-
const prototype = Object.getPrototypeOf(value);
|
|
123
|
-
return prototype === Object.prototype || prototype === null;
|
|
124
|
-
};
|
|
125
|
-
const walk = (value, segments) => {
|
|
126
|
-
if (!isPlainRecord(value)) {
|
|
127
|
-
if (segments.length > 0) keys.push(segments.join("."));
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
for (const [segment, child] of Object.entries(value)) walk(child, [...segments, segment]);
|
|
131
|
-
};
|
|
132
|
-
walk(store, []);
|
|
133
|
-
return keys;
|
|
160
|
+
hide(...names) {
|
|
161
|
+
for (const name of names) this.#hidden.add(name);
|
|
134
162
|
}
|
|
135
163
|
/**
|
|
136
|
-
*
|
|
164
|
+
* Unmarks one or more tools as hidden, making them visible again.
|
|
137
165
|
*
|
|
138
|
-
* @
|
|
166
|
+
* @remarks
|
|
167
|
+
* No-ops for any name that is not currently hidden.
|
|
168
|
+
*
|
|
169
|
+
* @param names - One or more tool names to unhide.
|
|
139
170
|
*/
|
|
140
|
-
|
|
141
|
-
|
|
171
|
+
unhide(...names) {
|
|
172
|
+
for (const name of names) this.#hidden.delete(name);
|
|
142
173
|
}
|
|
143
174
|
/**
|
|
144
|
-
*
|
|
175
|
+
* Replaces the entire hidden set with the given tool names.
|
|
145
176
|
*
|
|
146
177
|
* @remarks
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
178
|
+
* Any previously hidden tool not in `names` becomes visible. Names that are not registered are
|
|
179
|
+
* silently ignored — they are added to the set but have no effect until a tool with that name
|
|
180
|
+
* is registered.
|
|
150
181
|
*
|
|
151
|
-
* @
|
|
182
|
+
* @param names - The complete set of tool names to hide.
|
|
152
183
|
*/
|
|
153
|
-
|
|
154
|
-
|
|
184
|
+
setHidden(...names) {
|
|
185
|
+
this.#hidden = new Set(names);
|
|
155
186
|
}
|
|
156
187
|
/**
|
|
157
|
-
*
|
|
188
|
+
* Unhides every tool in the registry.
|
|
189
|
+
*/
|
|
190
|
+
clearHidden() {
|
|
191
|
+
this.#hidden.clear();
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Removes every tool whose {@link @nhtio/adk!Tool.ephemeral} flag is `true`.
|
|
158
195
|
*
|
|
159
|
-
* @
|
|
160
|
-
*
|
|
196
|
+
* @remarks
|
|
197
|
+
* Also removes pruned tool names from the hidden set. Synchronous and idempotent — calling it
|
|
198
|
+
* twice in a row is a no-op the second time. The canonical caller is
|
|
199
|
+
* {@link ToolRegistry.bindContext}, which schedules this method to run at
|
|
200
|
+
* {@link @nhtio/adk!DispatchContext.ack}. Non-ephemeral tools are left untouched.
|
|
161
201
|
*/
|
|
162
|
-
|
|
163
|
-
|
|
202
|
+
pruneEphemeral() {
|
|
203
|
+
for (const [name, tool] of this.#tools) if (tool.ephemeral) {
|
|
204
|
+
this.#tools.delete(name);
|
|
205
|
+
this.#hidden.delete(name);
|
|
206
|
+
}
|
|
164
207
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
* @
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
208
|
+
/**
|
|
209
|
+
* Binds this registry to a {@link @nhtio/adk!DispatchContext} so that {@link pruneEphemeral} runs
|
|
210
|
+
* automatically when the context is acked.
|
|
211
|
+
*
|
|
212
|
+
* @remarks
|
|
213
|
+
* The handler does NOT fire on {@link @nhtio/adk!DispatchContext.nack} — failed executor runs leave
|
|
214
|
+
* any forged tools in place so the consumer can inspect what was registered when debugging the
|
|
215
|
+
* failure. Subscriptions are short-lived and die with the context regardless.
|
|
216
|
+
*
|
|
217
|
+
* ARTIFACT READERS ARE FORGED BY THE CORE. As of the core-forge change, the `DispatchRunner` forges
|
|
218
|
+
* artifact-reader tools from prior-turn `SpooledArtifact` results into `ctx.tools` (and calls
|
|
219
|
+
* `ctx.tools.bindContext(ctx)`) once per iteration, BEFORE the input pipeline — so a battery executor no
|
|
220
|
+
* longer forges or binds; it reads the already-forged `ctx.tools` for both representation (rendering the
|
|
221
|
+
* tool declarations) and resolution (looking up an incoming call by name). The lifecycle is unchanged:
|
|
222
|
+
* ephemeral readers are still pruned on `ack`, and the core re-forges each iteration (prune-then-forge) so
|
|
223
|
+
* the `callId` enum never goes stale.
|
|
224
|
+
*
|
|
225
|
+
* `bindContext` remains the public seam for a CUSTOM consumer that forges its own ephemeral tools outside
|
|
226
|
+
* the core path. If you forge into a long-lived registry yourself, bind it (or prune manually) or the
|
|
227
|
+
* ephemeral tools accumulate and later `forgeTools(ctx)` calls see a stale `callId` enum. The pattern for a
|
|
228
|
+
* hand-rolled forge is:
|
|
229
|
+
*
|
|
230
|
+
* ```ts
|
|
231
|
+
* // Custom forge (the core already does this for artifact readers on ctx.tools):
|
|
232
|
+
* const forged = SpooledArtifact.forgeTools(ctx)
|
|
233
|
+
* for (const tool of forged.all()) ctx.tools.register(tool, true)
|
|
234
|
+
* ctx.tools.bindContext(ctx) // prune the ephemeral readers when the dispatch acks
|
|
235
|
+
* ```
|
|
236
|
+
*
|
|
237
|
+
* @param ctx - The execution context whose `ack` event should trigger pruning.
|
|
238
|
+
* @returns An unsubscribe function — calling it before `ctx.ack()` prevents pruning. Rarely
|
|
239
|
+
* useful outside of tests.
|
|
240
|
+
*
|
|
241
|
+
* @see {@link @nhtio/adk!SpooledArtifact.forgeTools}
|
|
242
|
+
* @see {@link @nhtio/adk!DispatchContext.onAck}
|
|
243
|
+
*/
|
|
244
|
+
bindContext(ctx) {
|
|
245
|
+
return ctx.onAck(() => this.pruneEphemeral());
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Combines multiple {@link ToolRegistry} instances into a fresh registry without mutating any
|
|
249
|
+
* input.
|
|
250
|
+
*
|
|
251
|
+
* @remarks
|
|
252
|
+
* Iteration is left-to-right across `registries` and then in each registry's insertion order.
|
|
253
|
+
* Collisions are resolved by consulting the **incoming** tool's {@link @nhtio/adk!Tool.onCollision} first:
|
|
254
|
+
*
|
|
255
|
+
* - `'replace'` (per-tool): the incoming tool wins, replacing the existing entry.
|
|
256
|
+
* - `'keep'` (per-tool): the existing entry wins; the incoming tool is dropped.
|
|
257
|
+
* - `'throw'` (per-tool, the default): fall back to the merge-level `options.onCollision`.
|
|
258
|
+
*
|
|
259
|
+
* The merge-level `options.onCollision` defaults to `'throw'`, which mirrors {@link register}.
|
|
260
|
+
*
|
|
261
|
+
* The result is a brand-new registry; no input is mutated and no event subscription is
|
|
262
|
+
* propagated. Each `Tool`'s `ephemeral` flag carries through unchanged — the flag lives on the
|
|
263
|
+
* tool, not the registry, so `bindContext(ctx)` on the merged registry will prune the forged
|
|
264
|
+
* tools as expected.
|
|
265
|
+
*
|
|
266
|
+
* Hidden state is also propagated: a tool that is hidden in any source registry remains hidden
|
|
267
|
+
* in the merged result, provided it survives collision resolution.
|
|
268
|
+
*
|
|
269
|
+
* @param registries - Registries to merge, in priority order (left-to-right insertion).
|
|
270
|
+
* @param options - Merge-level collision policy. Defaults to `{ onCollision: 'throw' }`.
|
|
271
|
+
* @returns A fresh {@link ToolRegistry} containing the resolved union of all inputs.
|
|
272
|
+
* @throws {@link @nhtio/adk!E_TOOL_ALREADY_REGISTERED} when the resolved collision policy is `'throw'`
|
|
273
|
+
* and a collision occurs.
|
|
274
|
+
*/
|
|
275
|
+
static merge(registries, options) {
|
|
276
|
+
const policy = options?.onCollision ?? "throw";
|
|
277
|
+
const merged = new ToolRegistry();
|
|
278
|
+
for (const registry of registries) {
|
|
279
|
+
for (const tool of registry.all()) {
|
|
280
|
+
if (!merged.get(tool.name)) {
|
|
281
|
+
merged.register(tool);
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
const incomingPolicy = tool.onCollision;
|
|
285
|
+
if (incomingPolicy === "replace") {
|
|
286
|
+
merged.register(tool, true);
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
if (incomingPolicy === "keep") continue;
|
|
290
|
+
if (policy === "replace") {
|
|
291
|
+
merged.register(tool, true);
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
if (policy === "keep") continue;
|
|
295
|
+
throw new require_tokenizable.E_TOOL_ALREADY_REGISTERED();
|
|
296
|
+
}
|
|
297
|
+
for (const tool of registry.hidden()) if (merged.has(tool.name)) merged.hide(tool.name);
|
|
298
|
+
}
|
|
299
|
+
return merged;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Serialise this ToolRegistry into an `@nhtio/encoder` snapshot.
|
|
303
|
+
*
|
|
304
|
+
* @remarks
|
|
305
|
+
* Emits the live {@link @nhtio/adk!Tool} instances (the encoder recurses into each — so every tool's
|
|
306
|
+
* handler-closure caveat from {@link Tool.[ENCODE_METHOD]} applies) plus the hidden-set names. Both
|
|
307
|
+
* {@link @nhtio/adk!Tool} and {@link @nhtio/adk!ArtifactTool} entries round-trip to their correct
|
|
308
|
+
* subtype. Round-trips via {@link ToolRegistry.[DECODE_METHOD]}.
|
|
309
|
+
*
|
|
310
|
+
* @returns A `{ tools, hidden }` snapshot.
|
|
311
|
+
*/
|
|
312
|
+
[require_tokenizable.ENCODE_METHOD]() {
|
|
313
|
+
return {
|
|
314
|
+
tools: this.all(),
|
|
315
|
+
hidden: this.hidden().map((tool) => tool.name)
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Reconstruct a {@link ToolRegistry} from a {@link ToolRegistry.[ENCODE_METHOD]} snapshot.
|
|
320
|
+
*
|
|
321
|
+
* @param data - The snapshot produced by {@link ToolRegistry.[ENCODE_METHOD]}.
|
|
322
|
+
* @returns A fresh {@link ToolRegistry} with the same tools and hidden set.
|
|
323
|
+
*/
|
|
324
|
+
static [require_tokenizable.DECODE_METHOD](data) {
|
|
325
|
+
const snapshot = data;
|
|
326
|
+
const registry = new ToolRegistry(snapshot.tools);
|
|
327
|
+
registry.setHidden(...snapshot.hidden);
|
|
328
|
+
return registry;
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
//#endregion
|
|
332
|
+
//#region src/lib/utils/canonical_json.ts
|
|
220
333
|
/**
|
|
221
|
-
*
|
|
222
|
-
*
|
|
334
|
+
* Canonical `JSON.stringify` that sorts object keys recursively so that semantically-equal
|
|
335
|
+
* objects produce identical strings.
|
|
223
336
|
*
|
|
224
337
|
* @remarks
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
338
|
+
* Used wherever the ADK derives a stable identity from a structured value — for example,
|
|
339
|
+
* `Tool.executor` computing the `callId` for `ToolExecutionStart`/`End` events, and the
|
|
340
|
+
* `reportToolCall` executor helper computing the `checksum` field on `TurnToolCallContent`.
|
|
341
|
+
* Both code paths hash `canonicalStringify({ tool, args })` so that argument key order does not
|
|
342
|
+
* affect the resulting identifier.
|
|
228
343
|
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*/
|
|
232
|
-
var implementsSpooledArtifactConstructor = (value) => {
|
|
233
|
-
return require_exceptions.passesSchema(spooledArtifactConstructorSchema, value);
|
|
234
|
-
};
|
|
235
|
-
/**
|
|
236
|
-
* Creates the validator fragment for a resolver returning a spooled-artifact constructor.
|
|
344
|
+
* Arrays are serialised in their declared order (order is meaningful for an array). Object keys
|
|
345
|
+
* are sorted with `Array.prototype.sort()`'s default lexicographic comparator.
|
|
237
346
|
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
* share exactly the same validation behaviour.
|
|
347
|
+
* @param value - The value to serialise.
|
|
348
|
+
* @returns A canonical JSON string representation of `value`.
|
|
241
349
|
*/
|
|
242
|
-
|
|
243
|
-
if (typeof value !== "
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
return helpers.error("any.invalid");
|
|
249
|
-
}
|
|
250
|
-
return implementsSpooledArtifactConstructor(resolved) ? value : helpers.error("any.invalid");
|
|
251
|
-
});
|
|
350
|
+
function canonicalStringify(value) {
|
|
351
|
+
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
352
|
+
if (Array.isArray(value)) return "[" + value.map((v) => canonicalStringify(v)).join(",") + "]";
|
|
353
|
+
const obj = value;
|
|
354
|
+
return "{" + Object.keys(obj).sort().map((k) => JSON.stringify(k) + ":" + canonicalStringify(obj[k])).join(",") + "}";
|
|
355
|
+
}
|
|
252
356
|
//#endregion
|
|
253
|
-
//#region src/lib/classes/
|
|
254
|
-
/**
|
|
255
|
-
* Validator schema for a {@link RawTool}.
|
|
256
|
-
*/
|
|
257
|
-
var rawToolSchema = _nhtio_validation.validator.object({
|
|
258
|
-
name: _nhtio_validation.validator.string().required(),
|
|
259
|
-
description: _nhtio_validation.validator.string().required(),
|
|
260
|
-
inputSchema: _nhtio_validation.validator.any().custom((value, helpers) => {
|
|
261
|
-
if (_nhtio_validation.validator.isSchema(value) && value.type === "object") return value;
|
|
262
|
-
return helpers.error("any.invalid");
|
|
263
|
-
}).required(),
|
|
264
|
-
handler: _nhtio_validation.validator.function().required(),
|
|
265
|
-
artifactConstructor: artifactConstructorResolverSchema().optional(),
|
|
266
|
-
meta: _nhtio_validation.validator.object().pattern(_nhtio_validation.validator.string(), _nhtio_validation.validator.any()).default({}),
|
|
267
|
-
ephemeral: _nhtio_validation.validator.boolean().default(false),
|
|
268
|
-
trusted: _nhtio_validation.validator.boolean().default(false),
|
|
269
|
-
onCollision: _nhtio_validation.validator.string().valid("throw", "replace", "keep").default("throw")
|
|
270
|
-
});
|
|
357
|
+
//#region src/lib/classes/registry.ts
|
|
271
358
|
/**
|
|
272
|
-
* A
|
|
273
|
-
* description, input schema, execution handler, and the {@link @nhtio/adk!SpooledArtifact} subclass that
|
|
274
|
-
* wraps its serialised output.
|
|
275
|
-
*
|
|
276
|
-
* @typeParam A - The {@link @nhtio/adk!SpooledArtifact} subtype this tool's results should be wrapped in.
|
|
277
|
-
* Defaults to {@link @nhtio/adk!SpooledArtifact}.
|
|
359
|
+
* A controlled-mutation key-value store with dot-path access and deep-clone isolation.
|
|
278
360
|
*
|
|
279
361
|
* @remarks
|
|
280
|
-
* The
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
* `.description()`, `.note()`, `.example()` etc. once, and that information is available in both
|
|
284
|
-
* contexts without duplication.
|
|
285
|
-
*
|
|
286
|
-
* The handler is private — invoke it only through `executor(ctx)` which validates args, fires
|
|
287
|
-
* observability events (with a stable `callId` derived from the tool name and arguments), and
|
|
288
|
-
* wraps handler errors in {@link @nhtio/adk!E_TOOL_DOWNSTREAM_ERROR}. The handler returns serialised bytes
|
|
289
|
-
* (`string | Uint8Array`); persistence is the consumer's responsibility.
|
|
362
|
+
* The registry enforces a safe read/write contract: callers never hold a live reference into
|
|
363
|
+
* the internal store. Every value that enters (`set`) or leaves (`get`, `all`) is deep-cloned
|
|
364
|
+
* via `klona`, so mutations to a retrieved value cannot affect stored state and vice versa.
|
|
290
365
|
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
* on the tool instance; the consumer reads it when assembling persisted records.
|
|
366
|
+
* Keys are dot-delimited paths (e.g. `"user.profile.name"`), resolved via `dlv` for reads and
|
|
367
|
+
* `dset` for writes; intermediate objects are created automatically on write.
|
|
294
368
|
*/
|
|
295
|
-
var
|
|
369
|
+
var Registry = class Registry {
|
|
370
|
+
#store;
|
|
296
371
|
/**
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
* @remarks
|
|
300
|
-
* Reusable fragment for any schema that needs to validate or nest a tool entry
|
|
301
|
-
* (e.g. `TurnRunnerConfig.tools`).
|
|
372
|
+
* @param initial - Optional plain object to seed the registry. Deep-cloned on construction.
|
|
373
|
+
* @throws {@link @nhtio/adk!E_INVALID_INITIAL_REGISTRY_VALUE} when `initial` is defined but not a plain object.
|
|
302
374
|
*/
|
|
303
|
-
|
|
375
|
+
constructor(initial) {
|
|
376
|
+
if ("undefined" !== typeof initial && !require_guards.isObject(initial)) throw new require_tokenizable.E_INVALID_INITIAL_REGISTRY_VALUE();
|
|
377
|
+
this.#store = initial ? (0, klona.klona)(initial) : {};
|
|
378
|
+
}
|
|
304
379
|
/**
|
|
305
|
-
* Returns `true` if `value` is a {@link
|
|
380
|
+
* Returns `true` if `value` is a {@link Registry} instance.
|
|
381
|
+
*
|
|
382
|
+
* @remarks
|
|
383
|
+
* Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety.
|
|
306
384
|
*
|
|
307
385
|
* @param value - The value to test.
|
|
308
|
-
* @returns `true` when `value` is a {@link
|
|
386
|
+
* @returns `true` when `value` is a {@link Registry} instance.
|
|
309
387
|
*/
|
|
310
|
-
static
|
|
311
|
-
return require_guards.isInstanceOf(value, "
|
|
388
|
+
static isRegistry(value) {
|
|
389
|
+
return require_guards.isInstanceOf(value, "Registry", Registry);
|
|
312
390
|
}
|
|
313
|
-
#name;
|
|
314
|
-
#description;
|
|
315
|
-
#inputSchema;
|
|
316
|
-
#handler;
|
|
317
|
-
#artifactConstructor;
|
|
318
|
-
#meta;
|
|
319
|
-
#ephemeral;
|
|
320
|
-
#trusted;
|
|
321
|
-
#onCollision;
|
|
322
391
|
/**
|
|
323
|
-
*
|
|
324
|
-
*
|
|
392
|
+
* Retrieves the value at `key`, returning `defaultValue` if the path is absent.
|
|
393
|
+
*
|
|
394
|
+
* @remarks
|
|
395
|
+
* The returned value is a deep clone — mutating it will not affect the stored state.
|
|
396
|
+
*
|
|
397
|
+
* @typeParam T - Expected type of the value at `key`.
|
|
398
|
+
* @param key - Dot-delimited path into the store (e.g. `"user.name"`).
|
|
399
|
+
* @param defaultValue - Fallback returned when the path resolves to `undefined`.
|
|
400
|
+
* @returns A deep clone of the stored value cast to `T`, or `defaultValue` when the path is absent.
|
|
325
401
|
*/
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
resolved = require_exceptions.validateOrThrow(rawToolSchema, raw, true);
|
|
330
|
-
} catch (err) {
|
|
331
|
-
throw new require_tokenizable.E_INVALID_INITIAL_TOOL_VALUE({ cause: require_guards.isError(err) ? err : void 0 });
|
|
332
|
-
}
|
|
333
|
-
this.#name = resolved.name;
|
|
334
|
-
this.#description = resolved.description;
|
|
335
|
-
this.#inputSchema = resolved.inputSchema;
|
|
336
|
-
this.#handler = resolved.handler;
|
|
337
|
-
this.#artifactConstructor = resolved.artifactConstructor;
|
|
338
|
-
this.#meta = new Registry(resolved.meta);
|
|
339
|
-
this.#ephemeral = resolved.ephemeral;
|
|
340
|
-
this.#trusted = resolved.trusted;
|
|
341
|
-
this.#onCollision = resolved.onCollision;
|
|
342
|
-
Object.defineProperties(this, {
|
|
343
|
-
name: {
|
|
344
|
-
get: () => this.#name,
|
|
345
|
-
enumerable: true,
|
|
346
|
-
configurable: false
|
|
347
|
-
},
|
|
348
|
-
description: {
|
|
349
|
-
get: () => this.#description,
|
|
350
|
-
enumerable: true,
|
|
351
|
-
configurable: false
|
|
352
|
-
},
|
|
353
|
-
inputSchema: {
|
|
354
|
-
get: () => this.#inputSchema,
|
|
355
|
-
enumerable: true,
|
|
356
|
-
configurable: false
|
|
357
|
-
},
|
|
358
|
-
artifactConstructor: {
|
|
359
|
-
get: () => this.#artifactConstructor,
|
|
360
|
-
enumerable: true,
|
|
361
|
-
configurable: false
|
|
362
|
-
},
|
|
363
|
-
meta: {
|
|
364
|
-
get: () => this.#meta,
|
|
365
|
-
enumerable: true,
|
|
366
|
-
configurable: false
|
|
367
|
-
},
|
|
368
|
-
ephemeral: {
|
|
369
|
-
get: () => this.#ephemeral,
|
|
370
|
-
enumerable: true,
|
|
371
|
-
configurable: false
|
|
372
|
-
},
|
|
373
|
-
trusted: {
|
|
374
|
-
get: () => this.#trusted,
|
|
375
|
-
enumerable: true,
|
|
376
|
-
configurable: false
|
|
377
|
-
},
|
|
378
|
-
onCollision: {
|
|
379
|
-
get: () => this.#onCollision,
|
|
380
|
-
enumerable: true,
|
|
381
|
-
configurable: false
|
|
382
|
-
}
|
|
383
|
-
});
|
|
402
|
+
get(key, defaultValue) {
|
|
403
|
+
const value = (0, dlv.default)((0, klona.klona)(this.#store), key);
|
|
404
|
+
return "undefined" === typeof value ? defaultValue : value;
|
|
384
405
|
}
|
|
385
406
|
/**
|
|
386
|
-
*
|
|
407
|
+
* Sets the value at `key`, creating intermediate objects as needed.
|
|
387
408
|
*
|
|
388
409
|
* @remarks
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
* in the tool call loop, not a downstream failure.
|
|
410
|
+
* The stored value is isolated from the caller — mutating `value` after this call will not
|
|
411
|
+
* affect what is held in the registry.
|
|
392
412
|
*
|
|
393
|
-
* @param
|
|
394
|
-
* @
|
|
395
|
-
* @throws {@link @nhtio/adk!E_INVALID_TOOL_ARGS} when `args` does not satisfy the input schema.
|
|
413
|
+
* @param key - Dot-delimited path into the store (e.g. `"user.name"`).
|
|
414
|
+
* @param value - Value to store at the path.
|
|
396
415
|
*/
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
return await require_exceptions.asyncValidateOrThrow(this.#inputSchema, args);
|
|
400
|
-
} catch (err) {
|
|
401
|
-
if (require_guards.isInstanceOf(err, "ValidationException", require_exceptions.ValidationException)) throw new require_tokenizable.E_INVALID_TOOL_ARGS({ cause: err });
|
|
402
|
-
throw err;
|
|
403
|
-
}
|
|
416
|
+
set(key, value) {
|
|
417
|
+
(0, dset.dset)(this.#store, key, value);
|
|
404
418
|
}
|
|
405
419
|
/**
|
|
406
|
-
* Returns
|
|
420
|
+
* Returns `true` if the registry has a value at `key`, `false` otherwise.
|
|
407
421
|
*
|
|
408
422
|
* @remarks
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
* (3) emits `toolExecutionStart` on the context (with the computed `callId`), (4) calls the
|
|
412
|
-
* handler, (5) emits `toolExecutionEnd` (with the same `callId`), (6) wraps any handler error
|
|
413
|
-
* in {@link @nhtio/adk!E_TOOL_DOWNSTREAM_ERROR} before re-throwing.
|
|
423
|
+
* A key resolving to `undefined` is treated as absent — same convention as {@link Registry.get}'s
|
|
424
|
+
* `defaultValue` fallback. No clone is performed; this is a pure existence check.
|
|
414
425
|
*
|
|
415
|
-
*
|
|
416
|
-
*
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
426
|
+
* @param key - Dot-delimited path into the store (e.g. `"user.name"`).
|
|
427
|
+
* @returns `true` when the path resolves to a value other than `undefined`.
|
|
428
|
+
*/
|
|
429
|
+
has(key) {
|
|
430
|
+
return "undefined" !== typeof (0, dlv.default)(this.#store, key);
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Returns all leaf dot-paths present in the registry.
|
|
421
434
|
*
|
|
422
|
-
*
|
|
435
|
+
* @remarks
|
|
436
|
+
* The store is deep-cloned before traversal. Plain objects are walked recursively with path
|
|
437
|
+
* segments joined by dots; arrays, primitives, `null`, and class instances are treated as leaves.
|
|
423
438
|
*
|
|
424
|
-
* @
|
|
425
|
-
* @returns An async function `(args) => Promise<string | Uint8Array | SpooledArtifact | Media | Media[]>`.
|
|
426
|
-
* A `SpooledArtifact` is a result the HANDLER built (streamed to storage and wrapped itself); a
|
|
427
|
-
* wrap-site passes it through unwrapped rather than re-spooling it. `string`/`Uint8Array` are the
|
|
428
|
-
* opposite case — bytes the consumer must still store and wrap.
|
|
439
|
+
* @returns A string array of dot-delimited paths to leaf values in the store.
|
|
429
440
|
*/
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
args: validatedArgs,
|
|
443
|
-
startedAt
|
|
444
|
-
});
|
|
445
|
-
try {
|
|
446
|
-
const result = await this.#handler(validatedArgs, ctx, this.#meta);
|
|
447
|
-
const endedAt = luxon.DateTime.now();
|
|
448
|
-
ctx.emitToolExecutionEnd({
|
|
449
|
-
toolName: this.#name,
|
|
450
|
-
turnId: ctx.id,
|
|
451
|
-
callId,
|
|
452
|
-
startedAt,
|
|
453
|
-
endedAt,
|
|
454
|
-
durationMs: endedAt.diff(startedAt).milliseconds,
|
|
455
|
-
isError: false
|
|
456
|
-
});
|
|
457
|
-
return result;
|
|
458
|
-
} catch (err) {
|
|
459
|
-
const endedAt = luxon.DateTime.now();
|
|
460
|
-
ctx.emitToolExecutionEnd({
|
|
461
|
-
toolName: this.#name,
|
|
462
|
-
turnId: ctx.id,
|
|
463
|
-
callId,
|
|
464
|
-
startedAt,
|
|
465
|
-
endedAt,
|
|
466
|
-
durationMs: endedAt.diff(startedAt).milliseconds,
|
|
467
|
-
isError: true
|
|
468
|
-
});
|
|
469
|
-
throw new require_tokenizable.E_TOOL_DOWNSTREAM_ERROR({ cause: require_guards.isError(err) ? err : void 0 });
|
|
441
|
+
keys() {
|
|
442
|
+
const store = (0, klona.klona)(this.#store);
|
|
443
|
+
const keys = [];
|
|
444
|
+
const isPlainRecord = (value) => {
|
|
445
|
+
if (!require_guards.isObject(value)) return false;
|
|
446
|
+
const prototype = Object.getPrototypeOf(value);
|
|
447
|
+
return prototype === Object.prototype || prototype === null;
|
|
448
|
+
};
|
|
449
|
+
const walk = (value, segments) => {
|
|
450
|
+
if (!isPlainRecord(value)) {
|
|
451
|
+
if (segments.length > 0) keys.push(segments.join("."));
|
|
452
|
+
return;
|
|
470
453
|
}
|
|
454
|
+
for (const [segment, child] of Object.entries(value)) walk(child, [...segments, segment]);
|
|
471
455
|
};
|
|
456
|
+
walk(store, []);
|
|
457
|
+
return keys;
|
|
472
458
|
}
|
|
473
459
|
/**
|
|
474
|
-
* Returns a
|
|
475
|
-
*
|
|
476
|
-
* @remarks
|
|
477
|
-
* The `inputSchema` property is the result of calling `.describe()` on the raw schema — a plain
|
|
478
|
-
* object carrying all the annotation metadata (descriptions, notes, examples, types) without any
|
|
479
|
-
* validator functions. Use this to build provider-specific LLM tool definitions.
|
|
460
|
+
* Returns a deep clone of the entire store contents.
|
|
480
461
|
*
|
|
481
|
-
* @returns
|
|
462
|
+
* @returns A plain object snapshot of all stored key-value pairs.
|
|
482
463
|
*/
|
|
483
|
-
|
|
484
|
-
return
|
|
485
|
-
name: this.#name,
|
|
486
|
-
description: this.#description,
|
|
487
|
-
inputSchema: this.#inputSchema.describe()
|
|
488
|
-
};
|
|
464
|
+
all() {
|
|
465
|
+
return (0, klona.klona)(this.#store);
|
|
489
466
|
}
|
|
490
467
|
/**
|
|
491
|
-
* Serialise this
|
|
468
|
+
* Serialise this Registry into an `@nhtio/encoder` snapshot.
|
|
492
469
|
*
|
|
493
470
|
* @remarks
|
|
494
|
-
*
|
|
495
|
-
*
|
|
496
|
-
*
|
|
497
|
-
* - **`inputSchema`** — delegated to `@nhtio/validation`'s `encode()`, which captures the full schema
|
|
498
|
-
* description plus its library version into a compact string; decode rebuilds the live `Schema`.
|
|
499
|
-
* - **`handler` / `artifactConstructor`** — emitted as **functions**. The encoder's `FunctionSerializer`
|
|
500
|
-
* serialises them by **source text** (`fn.toString()`). This is the sharp edge: a handler that
|
|
501
|
-
* closes over `ctx`, service clients, or config loses those bindings on decode — only the source
|
|
502
|
-
* survives, and the captured variables read back as `undefined`. A `.bind()`-ed or native handler
|
|
503
|
-
* cannot be serialised at all and the encoder throws. Tools are rarely serialised in practice; when
|
|
504
|
-
* they are, write handlers that reconstruct their dependencies inside the body rather than closing
|
|
505
|
-
* over them.
|
|
471
|
+
* The snapshot is a deep clone of the store ({@link Registry.all}). Leaf values that are themselves
|
|
472
|
+
* registered encodable instances round-trip; anything the encoder cannot serialise throws at encode
|
|
473
|
+
* time (standard encoder behaviour). Round-trips via {@link Registry.[DECODE_METHOD]}.
|
|
506
474
|
*
|
|
507
|
-
* @returns A
|
|
475
|
+
* @returns A deep-cloned plain-object snapshot of the store.
|
|
508
476
|
*/
|
|
509
477
|
[require_tokenizable.ENCODE_METHOD]() {
|
|
510
|
-
return
|
|
511
|
-
name: this.#name,
|
|
512
|
-
description: this.#description,
|
|
513
|
-
inputSchema: (0, _nhtio_validation.encode)(this.#inputSchema),
|
|
514
|
-
handler: this.#handler,
|
|
515
|
-
artifactConstructor: this.#artifactConstructor,
|
|
516
|
-
meta: this.#meta.all(),
|
|
517
|
-
ephemeral: this.#ephemeral,
|
|
518
|
-
trusted: this.#trusted,
|
|
519
|
-
onCollision: this.#onCollision
|
|
520
|
-
};
|
|
478
|
+
return this.all();
|
|
521
479
|
}
|
|
522
480
|
/**
|
|
523
|
-
* Reconstruct a {@link
|
|
524
|
-
*
|
|
525
|
-
* @remarks
|
|
526
|
-
* Rebuilds the live `Schema` via `@nhtio/validation`'s `decode()`, then re-validates through the
|
|
527
|
-
* constructor. The rehydrated `handler` carries only its source text — see
|
|
528
|
-
* {@link Tool.[ENCODE_METHOD]} for the closure caveat.
|
|
481
|
+
* Reconstruct a {@link Registry} from a {@link Registry.[ENCODE_METHOD]} snapshot.
|
|
529
482
|
*
|
|
530
|
-
* @param data - The snapshot produced by {@link
|
|
531
|
-
* @returns A
|
|
483
|
+
* @param data - The store snapshot produced by {@link Registry.[ENCODE_METHOD]}.
|
|
484
|
+
* @returns A fresh {@link Registry} seeded with the snapshot.
|
|
532
485
|
*/
|
|
533
486
|
static [require_tokenizable.DECODE_METHOD](data) {
|
|
534
|
-
|
|
535
|
-
return new Tool({
|
|
536
|
-
...snapshot,
|
|
537
|
-
inputSchema: (0, _nhtio_validation.decode)(snapshot.inputSchema)
|
|
538
|
-
});
|
|
487
|
+
return new Registry(data);
|
|
539
488
|
}
|
|
540
489
|
};
|
|
541
490
|
//#endregion
|
|
542
|
-
//#region src/lib/
|
|
491
|
+
//#region src/lib/contracts/spooled_artifact_constructor.ts
|
|
492
|
+
var ARTIFACT_METHODS = [
|
|
493
|
+
"head",
|
|
494
|
+
"tail",
|
|
495
|
+
"grep",
|
|
496
|
+
"cat",
|
|
497
|
+
"byteLength",
|
|
498
|
+
"lineCount",
|
|
499
|
+
"estimateTokens"
|
|
500
|
+
];
|
|
543
501
|
/**
|
|
544
|
-
* Validator schema
|
|
502
|
+
* Validator schema used to validate a {@link SpooledArtifactConstructorLike} value.
|
|
545
503
|
*
|
|
546
504
|
* @remarks
|
|
547
|
-
*
|
|
548
|
-
*
|
|
505
|
+
* Because the validator is invoked at validate-time (not at module-load), it is safe to inspect
|
|
506
|
+
* the constructor's prototype here. The check is duck-typed: the value must be a function whose
|
|
507
|
+
* `prototype` carries every canonical artifact instance method (`head`, `tail`, `grep`, `cat`,
|
|
508
|
+
* `byteLength`, `lineCount`, `estimateTokens`). This mirrors {@link spoolReaderSchema}'s
|
|
509
|
+
* cross-realm-safe duck-type pattern — `instanceof SpooledArtifact` would be tighter but would
|
|
510
|
+
* force a value-import of the class and reopen the module cycle.
|
|
549
511
|
*/
|
|
550
|
-
var
|
|
512
|
+
var spooledArtifactConstructorSchema = _nhtio_validation.validator.any().required().custom((value, helpers) => {
|
|
513
|
+
if (typeof value !== "function") return helpers.error("any.invalid");
|
|
514
|
+
const proto = value.prototype;
|
|
515
|
+
if (proto === void 0 || proto === null) return helpers.error("any.invalid");
|
|
516
|
+
if (ARTIFACT_METHODS.every((m) => typeof proto[m] === "function")) return value;
|
|
517
|
+
return helpers.error("any.invalid");
|
|
518
|
+
});
|
|
519
|
+
/**
|
|
520
|
+
* Returns `true` if `value` is a constructor whose prototype carries every canonical
|
|
521
|
+
* {@link @nhtio/adk!SpooledArtifact} instance method.
|
|
522
|
+
*
|
|
523
|
+
* @remarks
|
|
524
|
+
* Duck-typed; does not use `instanceof SpooledArtifact`. Used by the `Tool.artifactConstructor`
|
|
525
|
+
* resolver validator and any other site that needs to recognise a `SpooledArtifact`-like
|
|
526
|
+
* constructor without pulling the class into its module-load graph.
|
|
527
|
+
*
|
|
528
|
+
* @param value - The value to test.
|
|
529
|
+
* @returns `true` when `value` is a `SpooledArtifact`-shaped constructor.
|
|
530
|
+
*/
|
|
531
|
+
var implementsSpooledArtifactConstructor = (value) => {
|
|
532
|
+
return require_exceptions.passesSchema(spooledArtifactConstructorSchema, value);
|
|
533
|
+
};
|
|
534
|
+
/**
|
|
535
|
+
* Creates the validator fragment for a resolver returning a spooled-artifact constructor.
|
|
536
|
+
*
|
|
537
|
+
* The resolver is invoked during validation, then its result is checked with the canonical
|
|
538
|
+
* cross-realm-safe constructor guard. Keeping this fragment here makes `Tool` and `Retrievable`
|
|
539
|
+
* share exactly the same validation behaviour.
|
|
540
|
+
*/
|
|
541
|
+
var artifactConstructorResolverSchema = () => _nhtio_validation.validator.any().custom((value, helpers) => {
|
|
542
|
+
if (typeof value !== "function") return helpers.error("any.invalid");
|
|
543
|
+
let resolved;
|
|
544
|
+
try {
|
|
545
|
+
resolved = value();
|
|
546
|
+
} catch {
|
|
547
|
+
return helpers.error("any.invalid");
|
|
548
|
+
}
|
|
549
|
+
return implementsSpooledArtifactConstructor(resolved) ? value : helpers.error("any.invalid");
|
|
550
|
+
});
|
|
551
|
+
//#endregion
|
|
552
|
+
//#region src/lib/classes/tool.ts
|
|
553
|
+
/**
|
|
554
|
+
* Validator schema for a {@link RawTool}.
|
|
555
|
+
*/
|
|
556
|
+
var rawToolSchema = _nhtio_validation.validator.object({
|
|
551
557
|
name: _nhtio_validation.validator.string().required(),
|
|
552
558
|
description: _nhtio_validation.validator.string().required(),
|
|
553
559
|
inputSchema: _nhtio_validation.validator.any().custom((value, helpers) => {
|
|
@@ -555,404 +561,398 @@ var rawArtifactToolSchema = _nhtio_validation.validator.object({
|
|
|
555
561
|
return helpers.error("any.invalid");
|
|
556
562
|
}).required(),
|
|
557
563
|
handler: _nhtio_validation.validator.function().required(),
|
|
564
|
+
artifactConstructor: artifactConstructorResolverSchema().optional(),
|
|
558
565
|
meta: _nhtio_validation.validator.object().pattern(_nhtio_validation.validator.string(), _nhtio_validation.validator.any()).default({}),
|
|
559
566
|
ephemeral: _nhtio_validation.validator.boolean().default(false),
|
|
560
567
|
trusted: _nhtio_validation.validator.boolean().default(false),
|
|
561
|
-
onCollision: _nhtio_validation.validator.string().valid("throw", "replace", "keep").default("throw")
|
|
562
|
-
artifactConstructor: _nhtio_validation.validator.any().forbidden()
|
|
568
|
+
onCollision: _nhtio_validation.validator.string().valid("throw", "replace", "keep").default("throw")
|
|
563
569
|
});
|
|
564
570
|
/**
|
|
565
|
-
* A
|
|
566
|
-
*
|
|
567
|
-
*
|
|
568
|
-
*
|
|
569
|
-
* @remarks
|
|
570
|
-
* `ArtifactTool` is the canonical producer for **forged artifact-query tools** — the tools
|
|
571
|
-
* `SpooledArtifact.forgeTools(ctx)` emits so the model can `head`, `tail`, `grep`, `json_get`,
|
|
572
|
-
* `md_headings` (etc.) an artifact that is already in `ctx.turnToolCalls`.
|
|
573
|
-
*
|
|
574
|
-
* The difference from {@link @nhtio/adk!Tool} is structural, not stylistic:
|
|
575
|
-
*
|
|
576
|
-
* - A normal `Tool`'s handler returns bytes the ADK wraps in a fresh `SpooledArtifact`.
|
|
577
|
-
* The artifact lands in `ToolCall.results`, joins `ctx.turnToolCalls`, and is itself a
|
|
578
|
-
* first-class queryable artifact in the turn.
|
|
579
|
-
* - An `ArtifactTool`'s handler returns a string that is **already the model-visible answer**
|
|
580
|
-
* to a query against an existing artifact. The ADK wraps it in a `Tokenizable` rather
|
|
581
|
-
* than a `SpooledArtifact`; nothing new is queryable on its own. Subsequent
|
|
582
|
-
* `forgeTools(ctx)` calls exclude `ToolCall`s produced by an `ArtifactTool` from the
|
|
583
|
-
* `callId` enum (via the `ToolCall.fromArtifactTool` marker) — this is the structural fix
|
|
584
|
-
* that breaks the otherwise-recursive grep-on-the-grep-result loop.
|
|
571
|
+
* A tool definition that serves as the single source of truth for a callable tool: its name,
|
|
572
|
+
* description, input schema, execution handler, and the {@link @nhtio/adk!SpooledArtifact} subclass that
|
|
573
|
+
* wraps its serialised output.
|
|
585
574
|
*
|
|
586
|
-
*
|
|
587
|
-
*
|
|
588
|
-
*/
|
|
589
|
-
var ArtifactTool = class ArtifactTool extends Tool {
|
|
590
|
-
/**
|
|
591
|
-
* Validator schema that accepts a {@link RawArtifactTool} object.
|
|
592
|
-
*
|
|
593
|
-
* @remarks
|
|
594
|
-
* Differs from {@link @nhtio/adk!Tool.schema} by forbidding `artifactConstructor` — wrapping is
|
|
595
|
-
* exactly the thing this class opts out of. Typed identically to {@link @nhtio/adk!Tool.schema} so the
|
|
596
|
-
* subclass relationship `class ArtifactTool extends Tool` remains structurally sound; the
|
|
597
|
-
* runtime validation rules still differ as declared by `rawArtifactToolSchema`.
|
|
598
|
-
*/
|
|
599
|
-
static schema = rawArtifactToolSchema;
|
|
600
|
-
/**
|
|
601
|
-
* Returns `true` if `value` is an {@link ArtifactTool} instance.
|
|
602
|
-
*
|
|
603
|
-
* @remarks
|
|
604
|
-
* Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances
|
|
605
|
-
* created in a different module copy or VM context.
|
|
606
|
-
*
|
|
607
|
-
* @param value - The value to test.
|
|
608
|
-
* @returns `true` when `value` is an {@link ArtifactTool} instance.
|
|
609
|
-
*/
|
|
610
|
-
static isArtifactTool(value) {
|
|
611
|
-
return require_guards.isInstanceOf(value, "ArtifactTool", ArtifactTool);
|
|
612
|
-
}
|
|
613
|
-
/**
|
|
614
|
-
* @param raw - Raw tool input validated against {@link ArtifactTool.schema}.
|
|
615
|
-
*
|
|
616
|
-
* @throws {@link @nhtio/adk!E_INVALID_INITIAL_TOOL_VALUE} when `raw` does not satisfy
|
|
617
|
-
* {@link ArtifactTool.schema} (most commonly, when `artifactConstructor` is supplied — it is
|
|
618
|
-
* explicitly forbidden on this class) or when the base {@link @nhtio/adk!Tool} constructor rejects the
|
|
619
|
-
* input for any reason.
|
|
620
|
-
*/
|
|
621
|
-
constructor(raw) {
|
|
622
|
-
try {
|
|
623
|
-
require_exceptions.validateOrThrow(rawArtifactToolSchema, raw, true);
|
|
624
|
-
} catch (err) {
|
|
625
|
-
if (require_guards.isInstanceOf(err, "ValidationException", require_exceptions.ValidationException)) throw new require_tokenizable.E_INVALID_INITIAL_TOOL_VALUE({ cause: err });
|
|
626
|
-
throw err;
|
|
627
|
-
}
|
|
628
|
-
super(raw);
|
|
629
|
-
}
|
|
630
|
-
/**
|
|
631
|
-
* Serialise this ArtifactTool into an `@nhtio/encoder` snapshot.
|
|
632
|
-
*
|
|
633
|
-
* @remarks
|
|
634
|
-
* Reuses the base {@link Tool.[ENCODE_METHOD]} (function-serialised `handler`, validation-encoded
|
|
635
|
-
* `inputSchema`, plain config) and strips `artifactConstructor` — which {@link ArtifactTool.schema}
|
|
636
|
-
* forbids. The handler's closure caveat from {@link Tool.[ENCODE_METHOD]} applies here too.
|
|
637
|
-
*
|
|
638
|
-
* @returns A {@link RawArtifactTool}-shaped snapshot (with `inputSchema` as an encoded string).
|
|
639
|
-
*/
|
|
640
|
-
[require_tokenizable.ENCODE_METHOD]() {
|
|
641
|
-
const base = super[require_tokenizable.ENCODE_METHOD]();
|
|
642
|
-
delete base.artifactConstructor;
|
|
643
|
-
return base;
|
|
644
|
-
}
|
|
645
|
-
/**
|
|
646
|
-
* Reconstruct an {@link ArtifactTool} from an {@link ArtifactTool.[ENCODE_METHOD]} snapshot.
|
|
647
|
-
*
|
|
648
|
-
* @param data - The snapshot produced by {@link ArtifactTool.[ENCODE_METHOD]}.
|
|
649
|
-
* @returns A fully-validated {@link ArtifactTool}.
|
|
650
|
-
*/
|
|
651
|
-
static [require_tokenizable.DECODE_METHOD](data) {
|
|
652
|
-
const snapshot = data;
|
|
653
|
-
return new ArtifactTool({
|
|
654
|
-
...snapshot,
|
|
655
|
-
inputSchema: (0, _nhtio_validation.decode)(snapshot.inputSchema)
|
|
656
|
-
});
|
|
657
|
-
}
|
|
658
|
-
};
|
|
659
|
-
//#endregion
|
|
660
|
-
//#region src/lib/classes/tool_registry.ts
|
|
661
|
-
/**
|
|
662
|
-
* A mutable, turn-scoped collection of {@link @nhtio/adk!Tool} instances.
|
|
575
|
+
* @typeParam A - The {@link @nhtio/adk!SpooledArtifact} subtype this tool's results should be wrapped in.
|
|
576
|
+
* Defaults to {@link @nhtio/adk!SpooledArtifact}.
|
|
663
577
|
*
|
|
664
578
|
* @remarks
|
|
665
|
-
*
|
|
666
|
-
*
|
|
667
|
-
*
|
|
668
|
-
*
|
|
669
|
-
*
|
|
579
|
+
* The `inputSchema` is a `@nhtio/validation` schema. It is used at runtime to validate incoming
|
|
580
|
+
* arguments before the handler is called, and its `.describe()` output provides all the metadata
|
|
581
|
+
* needed to build a provider-specific LLM tool definition — annotate the schema with
|
|
582
|
+
* `.description()`, `.note()`, `.example()` etc. once, and that information is available in both
|
|
583
|
+
* contexts without duplication.
|
|
670
584
|
*
|
|
671
|
-
*
|
|
672
|
-
*
|
|
585
|
+
* The handler is private — invoke it only through `executor(ctx)` which validates args, fires
|
|
586
|
+
* observability events (with a stable `callId` derived from the tool name and arguments), and
|
|
587
|
+
* wraps handler errors in {@link @nhtio/adk!E_TOOL_DOWNSTREAM_ERROR}. The handler returns serialised bytes
|
|
588
|
+
* (`string | Uint8Array`); persistence is the consumer's responsibility.
|
|
673
589
|
*
|
|
674
|
-
*
|
|
675
|
-
*
|
|
676
|
-
*
|
|
677
|
-
* Hidden state is a property of the registry, not the tool: the same tool can be visible in one
|
|
678
|
-
* registry and hidden in another. See {@link hide}, {@link visible}, {@link hidden}.
|
|
590
|
+
* `artifactConstructor` is the {@link @nhtio/adk!SpooledArtifact} subclass the consumer should use when
|
|
591
|
+
* wrapping the handler's output into a `ToolCall.results` field. The author declares it once
|
|
592
|
+
* on the tool instance; the consumer reads it when assembling persisted records.
|
|
679
593
|
*/
|
|
680
|
-
var
|
|
681
|
-
#tools;
|
|
682
|
-
#hidden;
|
|
683
|
-
/**
|
|
684
|
-
* Returns `true` if `value` is a {@link ToolRegistry} instance.
|
|
685
|
-
*
|
|
686
|
-
* @param value - The value to test.
|
|
687
|
-
* @returns `true` when `value` is a {@link ToolRegistry} instance.
|
|
688
|
-
*/
|
|
689
|
-
static isToolRegistry(value) {
|
|
690
|
-
return require_guards.isInstanceOf(value, "ToolRegistry", ToolRegistry);
|
|
691
|
-
}
|
|
692
|
-
/**
|
|
693
|
-
* @param tools - Optional initial tools. Insertion order is preserved. Duplicate names throw
|
|
694
|
-
* {@link @nhtio/adk!E_TOOL_ALREADY_REGISTERED} — ensure each tool has a unique name.
|
|
695
|
-
* @throws {@link @nhtio/adk!E_TOOL_ALREADY_REGISTERED} when two tools in `tools` share a name.
|
|
696
|
-
*/
|
|
697
|
-
constructor(tools) {
|
|
698
|
-
this.#tools = /* @__PURE__ */ new Map();
|
|
699
|
-
this.#hidden = /* @__PURE__ */ new Set();
|
|
700
|
-
for (const tool of tools ?? []) this.register(tool);
|
|
701
|
-
}
|
|
702
|
-
/**
|
|
703
|
-
* Adds a tool to the registry.
|
|
704
|
-
*
|
|
705
|
-
* @param tool - The tool to register.
|
|
706
|
-
* @param overwrite - When `true`, silently replaces an existing tool with the same name.
|
|
707
|
-
* Defaults to `false`.
|
|
708
|
-
* @throws {@link @nhtio/adk!E_TOOL_ALREADY_REGISTERED} when a tool with the same name is already registered
|
|
709
|
-
* and `overwrite` is not `true`.
|
|
710
|
-
*/
|
|
711
|
-
register(tool, overwrite) {
|
|
712
|
-
if (this.#tools.has(tool.name) && !overwrite) throw new require_tokenizable.E_TOOL_ALREADY_REGISTERED();
|
|
713
|
-
this.#tools.set(tool.name, tool);
|
|
714
|
-
}
|
|
594
|
+
var Tool = class Tool {
|
|
715
595
|
/**
|
|
716
|
-
*
|
|
596
|
+
* Validator schema that accepts a {@link RawTool} object.
|
|
717
597
|
*
|
|
718
598
|
* @remarks
|
|
719
|
-
*
|
|
720
|
-
*
|
|
721
|
-
*
|
|
722
|
-
* @param name - The name of the tool to remove.
|
|
599
|
+
* Reusable fragment for any schema that needs to validate or nest a tool entry
|
|
600
|
+
* (e.g. `TurnRunnerConfig.tools`).
|
|
723
601
|
*/
|
|
724
|
-
|
|
725
|
-
this.#tools.delete(name);
|
|
726
|
-
this.#hidden.delete(name);
|
|
727
|
-
}
|
|
602
|
+
static schema = rawToolSchema;
|
|
728
603
|
/**
|
|
729
|
-
* Returns
|
|
604
|
+
* Returns `true` if `value` is a {@link Tool} instance.
|
|
730
605
|
*
|
|
731
|
-
* @param
|
|
606
|
+
* @param value - The value to test.
|
|
607
|
+
* @returns `true` when `value` is a {@link Tool} instance.
|
|
732
608
|
*/
|
|
733
|
-
|
|
734
|
-
return
|
|
609
|
+
static isTool(value) {
|
|
610
|
+
return require_guards.isInstanceOf(value, "Tool", Tool);
|
|
735
611
|
}
|
|
612
|
+
#name;
|
|
613
|
+
#description;
|
|
614
|
+
#inputSchema;
|
|
615
|
+
#handler;
|
|
616
|
+
#artifactConstructor;
|
|
617
|
+
#meta;
|
|
618
|
+
#ephemeral;
|
|
619
|
+
#trusted;
|
|
620
|
+
#onCollision;
|
|
736
621
|
/**
|
|
737
|
-
*
|
|
738
|
-
*
|
|
739
|
-
* @param name - The tool name to test.
|
|
622
|
+
* @param raw - The raw tool input validated against `rawToolSchema`.
|
|
623
|
+
* @throws {@link @nhtio/adk!E_INVALID_INITIAL_TOOL_VALUE} when `raw` does not satisfy the schema.
|
|
740
624
|
*/
|
|
741
|
-
|
|
742
|
-
|
|
625
|
+
constructor(raw) {
|
|
626
|
+
let resolved;
|
|
627
|
+
try {
|
|
628
|
+
resolved = require_exceptions.validateOrThrow(rawToolSchema, raw, true);
|
|
629
|
+
} catch (err) {
|
|
630
|
+
throw new require_tokenizable.E_INVALID_INITIAL_TOOL_VALUE({ cause: require_guards.isError(err) ? err : void 0 });
|
|
631
|
+
}
|
|
632
|
+
this.#name = resolved.name;
|
|
633
|
+
this.#description = resolved.description;
|
|
634
|
+
this.#inputSchema = resolved.inputSchema;
|
|
635
|
+
this.#handler = resolved.handler;
|
|
636
|
+
this.#artifactConstructor = resolved.artifactConstructor;
|
|
637
|
+
this.#meta = new Registry(resolved.meta);
|
|
638
|
+
this.#ephemeral = resolved.ephemeral;
|
|
639
|
+
this.#trusted = resolved.trusted;
|
|
640
|
+
this.#onCollision = resolved.onCollision;
|
|
641
|
+
Object.defineProperties(this, {
|
|
642
|
+
name: {
|
|
643
|
+
get: () => this.#name,
|
|
644
|
+
enumerable: true,
|
|
645
|
+
configurable: false
|
|
646
|
+
},
|
|
647
|
+
description: {
|
|
648
|
+
get: () => this.#description,
|
|
649
|
+
enumerable: true,
|
|
650
|
+
configurable: false
|
|
651
|
+
},
|
|
652
|
+
inputSchema: {
|
|
653
|
+
get: () => this.#inputSchema,
|
|
654
|
+
enumerable: true,
|
|
655
|
+
configurable: false
|
|
656
|
+
},
|
|
657
|
+
artifactConstructor: {
|
|
658
|
+
get: () => this.#artifactConstructor,
|
|
659
|
+
enumerable: true,
|
|
660
|
+
configurable: false
|
|
661
|
+
},
|
|
662
|
+
meta: {
|
|
663
|
+
get: () => this.#meta,
|
|
664
|
+
enumerable: true,
|
|
665
|
+
configurable: false
|
|
666
|
+
},
|
|
667
|
+
ephemeral: {
|
|
668
|
+
get: () => this.#ephemeral,
|
|
669
|
+
enumerable: true,
|
|
670
|
+
configurable: false
|
|
671
|
+
},
|
|
672
|
+
trusted: {
|
|
673
|
+
get: () => this.#trusted,
|
|
674
|
+
enumerable: true,
|
|
675
|
+
configurable: false
|
|
676
|
+
},
|
|
677
|
+
onCollision: {
|
|
678
|
+
get: () => this.#onCollision,
|
|
679
|
+
enumerable: true,
|
|
680
|
+
configurable: false
|
|
681
|
+
}
|
|
682
|
+
});
|
|
743
683
|
}
|
|
744
684
|
/**
|
|
745
|
-
*
|
|
685
|
+
* Validates `args` against the tool's input schema asynchronously.
|
|
746
686
|
*
|
|
747
687
|
* @remarks
|
|
748
|
-
*
|
|
749
|
-
* {@link
|
|
688
|
+
* Async to support schemas with external validators (e.g. database lookups, API calls).
|
|
689
|
+
* A validation failure throws {@link @nhtio/adk!E_INVALID_TOOL_ARGS} — this indicates a programming error
|
|
690
|
+
* in the tool call loop, not a downstream failure.
|
|
750
691
|
*
|
|
751
|
-
*
|
|
692
|
+
* @param args - The arguments to validate.
|
|
693
|
+
* @returns The validated (and coerced) arguments.
|
|
694
|
+
* @throws {@link @nhtio/adk!E_INVALID_TOOL_ARGS} when `args` does not satisfy the input schema.
|
|
752
695
|
*/
|
|
753
|
-
|
|
754
|
-
|
|
696
|
+
async validate(args) {
|
|
697
|
+
try {
|
|
698
|
+
return await require_exceptions.asyncValidateOrThrow(this.#inputSchema, args);
|
|
699
|
+
} catch (err) {
|
|
700
|
+
if (require_guards.isInstanceOf(err, "ValidationException", require_exceptions.ValidationException)) throw new require_tokenizable.E_INVALID_TOOL_ARGS({ cause: err });
|
|
701
|
+
throw err;
|
|
702
|
+
}
|
|
755
703
|
}
|
|
756
704
|
/**
|
|
757
|
-
* Returns a
|
|
705
|
+
* Returns a bound executor function for this tool against the given turn context.
|
|
758
706
|
*
|
|
759
707
|
* @remarks
|
|
760
|
-
*
|
|
761
|
-
*
|
|
762
|
-
*
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
return this.all().filter((t) => !this.#hidden.has(t.name));
|
|
766
|
-
}
|
|
767
|
-
/**
|
|
768
|
-
* Returns a fresh array of registered tools that **are** hidden, in insertion order.
|
|
708
|
+
* The executor: (1) computes a stable `callId` as `sha256(canonicalStringify({tool, args}))`
|
|
709
|
+
* over the **raw, pre-validation args**, (2) validates `args` via {@link Tool.validate},
|
|
710
|
+
* (3) emits `toolExecutionStart` on the context (with the computed `callId`), (4) calls the
|
|
711
|
+
* handler, (5) emits `toolExecutionEnd` (with the same `callId`), (6) wraps any handler error
|
|
712
|
+
* in {@link @nhtio/adk!E_TOOL_DOWNSTREAM_ERROR} before re-throwing.
|
|
769
713
|
*
|
|
770
|
-
*
|
|
771
|
-
*
|
|
772
|
-
*
|
|
714
|
+
* The handler usually returns serialised bytes (`string | Uint8Array`) — persistence is then the
|
|
715
|
+
* consumer's concern, and {@link Tool.artifactConstructor} is the class a wrap-site uses when
|
|
716
|
+
* wrapping those bytes into a `ToolCall.results` field. **A handler may instead return a
|
|
717
|
+
* {@link @nhtio/adk!SpooledArtifact} it built itself** (streaming into storage and wrapping the
|
|
718
|
+
* reader), in which case wrap-sites pass it through untouched and `artifactConstructor` does not
|
|
719
|
+
* apply — the returned instance's own class is what artifact-tool forging reads.
|
|
720
|
+
*
|
|
721
|
+
* Pattern mirrors `Middleware.runner()` — call once per turn, reuse the returned function.
|
|
722
|
+
*
|
|
723
|
+
* @param ctx - The active turn context. Provides emit functions and turn ID.
|
|
724
|
+
* @returns An async function `(args) => Promise<string | Uint8Array | SpooledArtifact | Media | Media[]>`.
|
|
725
|
+
* A `SpooledArtifact` is a result the HANDLER built (streamed to storage and wrapped itself); a
|
|
726
|
+
* wrap-site passes it through unwrapped rather than re-spooling it. `string`/`Uint8Array` are the
|
|
727
|
+
* opposite case — bytes the consumer must still store and wrap.
|
|
773
728
|
*/
|
|
774
|
-
|
|
775
|
-
return
|
|
729
|
+
executor(ctx) {
|
|
730
|
+
return async (args) => {
|
|
731
|
+
const callId = (0, js_sha256.sha256)(canonicalStringify({
|
|
732
|
+
tool: this.#name,
|
|
733
|
+
args
|
|
734
|
+
}));
|
|
735
|
+
const validatedArgs = await this.validate(args);
|
|
736
|
+
const startedAt = luxon.DateTime.now();
|
|
737
|
+
ctx.emitToolExecutionStart({
|
|
738
|
+
toolName: this.#name,
|
|
739
|
+
turnId: ctx.id,
|
|
740
|
+
callId,
|
|
741
|
+
args: validatedArgs,
|
|
742
|
+
startedAt
|
|
743
|
+
});
|
|
744
|
+
try {
|
|
745
|
+
const result = await this.#handler(validatedArgs, ctx, this.#meta);
|
|
746
|
+
const endedAt = luxon.DateTime.now();
|
|
747
|
+
ctx.emitToolExecutionEnd({
|
|
748
|
+
toolName: this.#name,
|
|
749
|
+
turnId: ctx.id,
|
|
750
|
+
callId,
|
|
751
|
+
startedAt,
|
|
752
|
+
endedAt,
|
|
753
|
+
durationMs: endedAt.diff(startedAt).milliseconds,
|
|
754
|
+
isError: false
|
|
755
|
+
});
|
|
756
|
+
return result;
|
|
757
|
+
} catch (err) {
|
|
758
|
+
const endedAt = luxon.DateTime.now();
|
|
759
|
+
ctx.emitToolExecutionEnd({
|
|
760
|
+
toolName: this.#name,
|
|
761
|
+
turnId: ctx.id,
|
|
762
|
+
callId,
|
|
763
|
+
startedAt,
|
|
764
|
+
endedAt,
|
|
765
|
+
durationMs: endedAt.diff(startedAt).milliseconds,
|
|
766
|
+
isError: true
|
|
767
|
+
});
|
|
768
|
+
throw new require_tokenizable.E_TOOL_DOWNSTREAM_ERROR({ cause: require_guards.isError(err) ? err : void 0 });
|
|
769
|
+
}
|
|
770
|
+
};
|
|
776
771
|
}
|
|
777
772
|
/**
|
|
778
|
-
*
|
|
773
|
+
* Returns a fully serialisable snapshot of this tool's definition.
|
|
779
774
|
*
|
|
780
775
|
* @remarks
|
|
781
|
-
*
|
|
782
|
-
*
|
|
783
|
-
*
|
|
776
|
+
* The `inputSchema` property is the result of calling `.describe()` on the raw schema — a plain
|
|
777
|
+
* object carrying all the annotation metadata (descriptions, notes, examples, types) without any
|
|
778
|
+
* validator functions. Use this to build provider-specific LLM tool definitions.
|
|
784
779
|
*
|
|
785
|
-
* @
|
|
780
|
+
* @returns `{ name, description, inputSchema }` where `inputSchema` is the schema description.
|
|
786
781
|
*/
|
|
787
|
-
|
|
788
|
-
|
|
782
|
+
describe() {
|
|
783
|
+
return {
|
|
784
|
+
name: this.#name,
|
|
785
|
+
description: this.#description,
|
|
786
|
+
inputSchema: this.#inputSchema.describe()
|
|
787
|
+
};
|
|
789
788
|
}
|
|
790
789
|
/**
|
|
791
|
-
*
|
|
790
|
+
* Serialise this Tool into an `@nhtio/encoder` snapshot.
|
|
792
791
|
*
|
|
793
792
|
* @remarks
|
|
794
|
-
*
|
|
793
|
+
* Three halves with different serialisation strategies:
|
|
795
794
|
*
|
|
796
|
-
*
|
|
795
|
+
* - **Plain config** (`name`, `description`, `meta`, flags) — emitted verbatim.
|
|
796
|
+
* - **`inputSchema`** — delegated to `@nhtio/validation`'s `encode()`, which captures the full schema
|
|
797
|
+
* description plus its library version into a compact string; decode rebuilds the live `Schema`.
|
|
798
|
+
* - **`handler` / `artifactConstructor`** — emitted as **functions**. The encoder's `FunctionSerializer`
|
|
799
|
+
* serialises them by **source text** (`fn.toString()`). This is the sharp edge: a handler that
|
|
800
|
+
* closes over `ctx`, service clients, or config loses those bindings on decode — only the source
|
|
801
|
+
* survives, and the captured variables read back as `undefined`. A `.bind()`-ed or native handler
|
|
802
|
+
* cannot be serialised at all and the encoder throws. Tools are rarely serialised in practice; when
|
|
803
|
+
* they are, write handlers that reconstruct their dependencies inside the body rather than closing
|
|
804
|
+
* over them.
|
|
805
|
+
*
|
|
806
|
+
* @returns A {@link RawTool}-shaped snapshot (with `inputSchema` as an encoded string).
|
|
797
807
|
*/
|
|
798
|
-
|
|
799
|
-
|
|
808
|
+
[require_tokenizable.ENCODE_METHOD]() {
|
|
809
|
+
return {
|
|
810
|
+
name: this.#name,
|
|
811
|
+
description: this.#description,
|
|
812
|
+
inputSchema: (0, _nhtio_validation.encode)(this.#inputSchema),
|
|
813
|
+
handler: this.#handler,
|
|
814
|
+
artifactConstructor: this.#artifactConstructor,
|
|
815
|
+
meta: this.#meta.all(),
|
|
816
|
+
ephemeral: this.#ephemeral,
|
|
817
|
+
trusted: this.#trusted,
|
|
818
|
+
onCollision: this.#onCollision
|
|
819
|
+
};
|
|
800
820
|
}
|
|
801
821
|
/**
|
|
802
|
-
*
|
|
822
|
+
* Reconstruct a {@link Tool} from a {@link Tool.[ENCODE_METHOD]} snapshot.
|
|
803
823
|
*
|
|
804
824
|
* @remarks
|
|
805
|
-
*
|
|
806
|
-
*
|
|
807
|
-
*
|
|
825
|
+
* Rebuilds the live `Schema` via `@nhtio/validation`'s `decode()`, then re-validates through the
|
|
826
|
+
* constructor. The rehydrated `handler` carries only its source text — see
|
|
827
|
+
* {@link Tool.[ENCODE_METHOD]} for the closure caveat.
|
|
808
828
|
*
|
|
809
|
-
* @param
|
|
810
|
-
|
|
811
|
-
setHidden(...names) {
|
|
812
|
-
this.#hidden = new Set(names);
|
|
813
|
-
}
|
|
814
|
-
/**
|
|
815
|
-
* Unhides every tool in the registry.
|
|
829
|
+
* @param data - The snapshot produced by {@link Tool.[ENCODE_METHOD]}.
|
|
830
|
+
* @returns A fully-validated {@link Tool}.
|
|
816
831
|
*/
|
|
817
|
-
|
|
818
|
-
|
|
832
|
+
static [require_tokenizable.DECODE_METHOD](data) {
|
|
833
|
+
const snapshot = data;
|
|
834
|
+
return new Tool({
|
|
835
|
+
...snapshot,
|
|
836
|
+
inputSchema: (0, _nhtio_validation.decode)(snapshot.inputSchema)
|
|
837
|
+
});
|
|
819
838
|
}
|
|
839
|
+
};
|
|
840
|
+
//#endregion
|
|
841
|
+
//#region src/lib/classes/artifact_tool.ts
|
|
842
|
+
/**
|
|
843
|
+
* Validator schema for a {@link RawArtifactTool}.
|
|
844
|
+
*
|
|
845
|
+
* @remarks
|
|
846
|
+
* Mirrors the base tool schema but explicitly forbids `artifactConstructor` — the entire
|
|
847
|
+
* point of `ArtifactTool` is to opt out of `SpooledArtifact` wrapping.
|
|
848
|
+
*/
|
|
849
|
+
var rawArtifactToolSchema = _nhtio_validation.validator.object({
|
|
850
|
+
name: _nhtio_validation.validator.string().required(),
|
|
851
|
+
description: _nhtio_validation.validator.string().required(),
|
|
852
|
+
inputSchema: _nhtio_validation.validator.any().custom((value, helpers) => {
|
|
853
|
+
if (_nhtio_validation.validator.isSchema(value) && value.type === "object") return value;
|
|
854
|
+
return helpers.error("any.invalid");
|
|
855
|
+
}).required(),
|
|
856
|
+
handler: _nhtio_validation.validator.function().required(),
|
|
857
|
+
meta: _nhtio_validation.validator.object().pattern(_nhtio_validation.validator.string(), _nhtio_validation.validator.any()).default({}),
|
|
858
|
+
ephemeral: _nhtio_validation.validator.boolean().default(false),
|
|
859
|
+
trusted: _nhtio_validation.validator.boolean().default(false),
|
|
860
|
+
onCollision: _nhtio_validation.validator.string().valid("throw", "replace", "keep").default("throw"),
|
|
861
|
+
artifactConstructor: _nhtio_validation.validator.any().forbidden()
|
|
862
|
+
});
|
|
863
|
+
/**
|
|
864
|
+
* A {@link @nhtio/adk!Tool} subclass whose handler return value is wrapped directly in a
|
|
865
|
+
* {@link @nhtio/adk!Tokenizable} (not a {@link @nhtio/adk!SpooledArtifact}) when it
|
|
866
|
+
* lands on `ToolCall.results`.
|
|
867
|
+
*
|
|
868
|
+
* @remarks
|
|
869
|
+
* `ArtifactTool` is the canonical producer for **forged artifact-query tools** — the tools
|
|
870
|
+
* `SpooledArtifact.forgeTools(ctx)` emits so the model can `head`, `tail`, `grep`, `json_get`,
|
|
871
|
+
* `md_headings` (etc.) an artifact that is already in `ctx.turnToolCalls`.
|
|
872
|
+
*
|
|
873
|
+
* The difference from {@link @nhtio/adk!Tool} is structural, not stylistic:
|
|
874
|
+
*
|
|
875
|
+
* - A normal `Tool`'s handler returns bytes the ADK wraps in a fresh `SpooledArtifact`.
|
|
876
|
+
* The artifact lands in `ToolCall.results`, joins `ctx.turnToolCalls`, and is itself a
|
|
877
|
+
* first-class queryable artifact in the turn.
|
|
878
|
+
* - An `ArtifactTool`'s handler returns a string that is **already the model-visible answer**
|
|
879
|
+
* to a query against an existing artifact. The ADK wraps it in a `Tokenizable` rather
|
|
880
|
+
* than a `SpooledArtifact`; nothing new is queryable on its own. Subsequent
|
|
881
|
+
* `forgeTools(ctx)` calls exclude `ToolCall`s produced by an `ArtifactTool` from the
|
|
882
|
+
* `callId` enum (via the `ToolCall.fromArtifactTool` marker) — this is the structural fix
|
|
883
|
+
* that breaks the otherwise-recursive grep-on-the-grep-result loop.
|
|
884
|
+
*
|
|
885
|
+
* Consumers who want to build their own artifact-query tools (e.g. for a domain-specific
|
|
886
|
+
* spooled subclass not shipped by the ADK) should extend or instantiate this class.
|
|
887
|
+
*/
|
|
888
|
+
var ArtifactTool = class ArtifactTool extends Tool {
|
|
820
889
|
/**
|
|
821
|
-
*
|
|
890
|
+
* Validator schema that accepts a {@link RawArtifactTool} object.
|
|
822
891
|
*
|
|
823
892
|
* @remarks
|
|
824
|
-
*
|
|
825
|
-
*
|
|
826
|
-
*
|
|
827
|
-
*
|
|
893
|
+
* Differs from {@link @nhtio/adk!Tool.schema} by forbidding `artifactConstructor` — wrapping is
|
|
894
|
+
* exactly the thing this class opts out of. Typed identically to {@link @nhtio/adk!Tool.schema} so the
|
|
895
|
+
* subclass relationship `class ArtifactTool extends Tool` remains structurally sound; the
|
|
896
|
+
* runtime validation rules still differ as declared by `rawArtifactToolSchema`.
|
|
828
897
|
*/
|
|
829
|
-
|
|
830
|
-
for (const [name, tool] of this.#tools) if (tool.ephemeral) {
|
|
831
|
-
this.#tools.delete(name);
|
|
832
|
-
this.#hidden.delete(name);
|
|
833
|
-
}
|
|
834
|
-
}
|
|
898
|
+
static schema = rawArtifactToolSchema;
|
|
835
899
|
/**
|
|
836
|
-
*
|
|
837
|
-
* automatically when the context is acked.
|
|
900
|
+
* Returns `true` if `value` is an {@link ArtifactTool} instance.
|
|
838
901
|
*
|
|
839
902
|
* @remarks
|
|
840
|
-
*
|
|
841
|
-
*
|
|
842
|
-
* failure. Subscriptions are short-lived and die with the context regardless.
|
|
843
|
-
*
|
|
844
|
-
* ARTIFACT READERS ARE FORGED BY THE CORE. As of the core-forge change, the `DispatchRunner` forges
|
|
845
|
-
* artifact-reader tools from prior-turn `SpooledArtifact` results into `ctx.tools` (and calls
|
|
846
|
-
* `ctx.tools.bindContext(ctx)`) once per iteration, BEFORE the input pipeline — so a battery executor no
|
|
847
|
-
* longer forges or binds; it reads the already-forged `ctx.tools` for both representation (rendering the
|
|
848
|
-
* tool declarations) and resolution (looking up an incoming call by name). The lifecycle is unchanged:
|
|
849
|
-
* ephemeral readers are still pruned on `ack`, and the core re-forges each iteration (prune-then-forge) so
|
|
850
|
-
* the `callId` enum never goes stale.
|
|
851
|
-
*
|
|
852
|
-
* `bindContext` remains the public seam for a CUSTOM consumer that forges its own ephemeral tools outside
|
|
853
|
-
* the core path. If you forge into a long-lived registry yourself, bind it (or prune manually) or the
|
|
854
|
-
* ephemeral tools accumulate and later `forgeTools(ctx)` calls see a stale `callId` enum. The pattern for a
|
|
855
|
-
* hand-rolled forge is:
|
|
856
|
-
*
|
|
857
|
-
* ```ts
|
|
858
|
-
* // Custom forge (the core already does this for artifact readers on ctx.tools):
|
|
859
|
-
* const forged = SpooledArtifact.forgeTools(ctx)
|
|
860
|
-
* for (const tool of forged.all()) ctx.tools.register(tool, true)
|
|
861
|
-
* ctx.tools.bindContext(ctx) // prune the ephemeral readers when the dispatch acks
|
|
862
|
-
* ```
|
|
863
|
-
*
|
|
864
|
-
* @param ctx - The execution context whose `ack` event should trigger pruning.
|
|
865
|
-
* @returns An unsubscribe function — calling it before `ctx.ack()` prevents pruning. Rarely
|
|
866
|
-
* useful outside of tests.
|
|
903
|
+
* Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances
|
|
904
|
+
* created in a different module copy or VM context.
|
|
867
905
|
*
|
|
868
|
-
* @
|
|
869
|
-
* @
|
|
906
|
+
* @param value - The value to test.
|
|
907
|
+
* @returns `true` when `value` is an {@link ArtifactTool} instance.
|
|
870
908
|
*/
|
|
871
|
-
|
|
872
|
-
return
|
|
909
|
+
static isArtifactTool(value) {
|
|
910
|
+
return require_guards.isInstanceOf(value, "ArtifactTool", ArtifactTool);
|
|
873
911
|
}
|
|
874
912
|
/**
|
|
875
|
-
*
|
|
876
|
-
* input.
|
|
877
|
-
*
|
|
878
|
-
* @remarks
|
|
879
|
-
* Iteration is left-to-right across `registries` and then in each registry's insertion order.
|
|
880
|
-
* Collisions are resolved by consulting the **incoming** tool's {@link @nhtio/adk!Tool.onCollision} first:
|
|
881
|
-
*
|
|
882
|
-
* - `'replace'` (per-tool): the incoming tool wins, replacing the existing entry.
|
|
883
|
-
* - `'keep'` (per-tool): the existing entry wins; the incoming tool is dropped.
|
|
884
|
-
* - `'throw'` (per-tool, the default): fall back to the merge-level `options.onCollision`.
|
|
885
|
-
*
|
|
886
|
-
* The merge-level `options.onCollision` defaults to `'throw'`, which mirrors {@link register}.
|
|
887
|
-
*
|
|
888
|
-
* The result is a brand-new registry; no input is mutated and no event subscription is
|
|
889
|
-
* propagated. Each `Tool`'s `ephemeral` flag carries through unchanged — the flag lives on the
|
|
890
|
-
* tool, not the registry, so `bindContext(ctx)` on the merged registry will prune the forged
|
|
891
|
-
* tools as expected.
|
|
892
|
-
*
|
|
893
|
-
* Hidden state is also propagated: a tool that is hidden in any source registry remains hidden
|
|
894
|
-
* in the merged result, provided it survives collision resolution.
|
|
913
|
+
* @param raw - Raw tool input validated against {@link ArtifactTool.schema}.
|
|
895
914
|
*
|
|
896
|
-
* @
|
|
897
|
-
*
|
|
898
|
-
*
|
|
899
|
-
*
|
|
900
|
-
* and a collision occurs.
|
|
915
|
+
* @throws {@link @nhtio/adk!E_INVALID_INITIAL_TOOL_VALUE} when `raw` does not satisfy
|
|
916
|
+
* {@link ArtifactTool.schema} (most commonly, when `artifactConstructor` is supplied — it is
|
|
917
|
+
* explicitly forbidden on this class) or when the base {@link @nhtio/adk!Tool} constructor rejects the
|
|
918
|
+
* input for any reason.
|
|
901
919
|
*/
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
merged.register(tool);
|
|
909
|
-
continue;
|
|
910
|
-
}
|
|
911
|
-
const incomingPolicy = tool.onCollision;
|
|
912
|
-
if (incomingPolicy === "replace") {
|
|
913
|
-
merged.register(tool, true);
|
|
914
|
-
continue;
|
|
915
|
-
}
|
|
916
|
-
if (incomingPolicy === "keep") continue;
|
|
917
|
-
if (policy === "replace") {
|
|
918
|
-
merged.register(tool, true);
|
|
919
|
-
continue;
|
|
920
|
-
}
|
|
921
|
-
if (policy === "keep") continue;
|
|
922
|
-
throw new require_tokenizable.E_TOOL_ALREADY_REGISTERED();
|
|
923
|
-
}
|
|
924
|
-
for (const tool of registry.hidden()) if (merged.has(tool.name)) merged.hide(tool.name);
|
|
920
|
+
constructor(raw) {
|
|
921
|
+
try {
|
|
922
|
+
require_exceptions.validateOrThrow(rawArtifactToolSchema, raw, true);
|
|
923
|
+
} catch (err) {
|
|
924
|
+
if (require_guards.isInstanceOf(err, "ValidationException", require_exceptions.ValidationException)) throw new require_tokenizable.E_INVALID_INITIAL_TOOL_VALUE({ cause: err });
|
|
925
|
+
throw err;
|
|
925
926
|
}
|
|
926
|
-
|
|
927
|
+
super(raw);
|
|
927
928
|
}
|
|
928
929
|
/**
|
|
929
|
-
* Serialise this
|
|
930
|
+
* Serialise this ArtifactTool into an `@nhtio/encoder` snapshot.
|
|
930
931
|
*
|
|
931
932
|
* @remarks
|
|
932
|
-
*
|
|
933
|
-
*
|
|
934
|
-
*
|
|
935
|
-
* subtype. Round-trips via {@link ToolRegistry.[DECODE_METHOD]}.
|
|
933
|
+
* Reuses the base {@link Tool.[ENCODE_METHOD]} (function-serialised `handler`, validation-encoded
|
|
934
|
+
* `inputSchema`, plain config) and strips `artifactConstructor` — which {@link ArtifactTool.schema}
|
|
935
|
+
* forbids. The handler's closure caveat from {@link Tool.[ENCODE_METHOD]} applies here too.
|
|
936
936
|
*
|
|
937
|
-
* @returns A
|
|
937
|
+
* @returns A {@link RawArtifactTool}-shaped snapshot (with `inputSchema` as an encoded string).
|
|
938
938
|
*/
|
|
939
939
|
[require_tokenizable.ENCODE_METHOD]() {
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
};
|
|
940
|
+
const base = super[require_tokenizable.ENCODE_METHOD]();
|
|
941
|
+
delete base.artifactConstructor;
|
|
942
|
+
return base;
|
|
944
943
|
}
|
|
945
944
|
/**
|
|
946
|
-
* Reconstruct
|
|
945
|
+
* Reconstruct an {@link ArtifactTool} from an {@link ArtifactTool.[ENCODE_METHOD]} snapshot.
|
|
947
946
|
*
|
|
948
|
-
* @param data - The snapshot produced by {@link
|
|
949
|
-
* @returns A
|
|
947
|
+
* @param data - The snapshot produced by {@link ArtifactTool.[ENCODE_METHOD]}.
|
|
948
|
+
* @returns A fully-validated {@link ArtifactTool}.
|
|
950
949
|
*/
|
|
951
950
|
static [require_tokenizable.DECODE_METHOD](data) {
|
|
952
951
|
const snapshot = data;
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
952
|
+
return new ArtifactTool({
|
|
953
|
+
...snapshot,
|
|
954
|
+
inputSchema: (0, _nhtio_validation.decode)(snapshot.inputSchema)
|
|
955
|
+
});
|
|
956
956
|
}
|
|
957
957
|
};
|
|
958
958
|
//#endregion
|
|
@@ -1754,4 +1754,4 @@ Object.defineProperty(exports, "resolveSpoolReader", {
|
|
|
1754
1754
|
}
|
|
1755
1755
|
});
|
|
1756
1756
|
|
|
1757
|
-
//# sourceMappingURL=spooled_artifact-
|
|
1757
|
+
//# sourceMappingURL=spooled_artifact-BoYsldvO.cjs.map
|