@nhtio/adk 1.20260625.0 → 1.20260626.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +114 -0
- package/batteries/embeddings/index.d.ts +12 -6
- package/batteries/embeddings/openai/adapter.cjs +1 -1
- package/batteries/embeddings/openai/adapter.mjs +1 -1
- package/batteries/embeddings/transformers_js/adapter.cjs +193 -0
- package/batteries/embeddings/transformers_js/adapter.cjs.map +1 -0
- package/batteries/embeddings/transformers_js/adapter.d.ts +80 -0
- package/batteries/embeddings/transformers_js/adapter.mjs +191 -0
- package/batteries/embeddings/transformers_js/adapter.mjs.map +1 -0
- package/batteries/embeddings/transformers_js/exceptions.cjs +32 -0
- package/batteries/embeddings/transformers_js/exceptions.cjs.map +1 -0
- package/batteries/embeddings/transformers_js/exceptions.d.ts +26 -0
- package/batteries/embeddings/transformers_js/exceptions.mjs +29 -0
- package/batteries/embeddings/transformers_js/exceptions.mjs.map +1 -0
- package/batteries/embeddings/transformers_js/index.d.ts +18 -0
- package/batteries/embeddings/transformers_js/pooling.cjs +67 -0
- package/batteries/embeddings/transformers_js/pooling.cjs.map +1 -0
- package/batteries/embeddings/transformers_js/pooling.d.ts +41 -0
- package/batteries/embeddings/transformers_js/pooling.mjs +63 -0
- package/batteries/embeddings/transformers_js/pooling.mjs.map +1 -0
- package/batteries/embeddings/transformers_js/types.cjs +2 -0
- package/batteries/embeddings/transformers_js/types.d.ts +97 -0
- package/batteries/embeddings/transformers_js/types.mjs +0 -0
- package/batteries/embeddings/transformers_js/validation.cjs +63 -0
- package/batteries/embeddings/transformers_js/validation.cjs.map +1 -0
- package/batteries/embeddings/transformers_js/validation.d.ts +21 -0
- package/batteries/embeddings/transformers_js/validation.mjs +60 -0
- package/batteries/embeddings/transformers_js/validation.mjs.map +1 -0
- package/batteries/embeddings/transformers_js.cjs +14 -0
- package/batteries/embeddings/transformers_js.mjs +5 -0
- package/batteries/embeddings/webllm/adapter.cjs +1 -1
- package/batteries/embeddings/webllm/adapter.mjs +1 -1
- package/batteries/embeddings.cjs +9 -0
- package/batteries/embeddings.mjs +5 -1
- package/batteries/encoding.cjs +7 -7
- package/batteries/encoding.mjs +7 -7
- package/batteries/llm/chat_common/generation.d.ts +122 -0
- package/batteries/llm/chat_common/helpers.d.ts +68 -0
- package/batteries/llm/chat_common/index.d.ts +15 -0
- package/batteries/llm/chat_common/lifecycle.d.ts +85 -0
- package/batteries/llm/chat_common/reasoning_parsers.d.ts +113 -0
- package/batteries/llm/chat_common/tool_parsers.d.ts +193 -0
- package/batteries/llm/chat_common/types.d.ts +36 -1
- package/batteries/llm/index.d.ts +10 -0
- package/batteries/llm/litert_lm/adapter.cjs +208 -100
- package/batteries/llm/litert_lm/adapter.cjs.map +1 -1
- package/batteries/llm/litert_lm/adapter.d.ts +11 -0
- package/batteries/llm/litert_lm/adapter.mjs +209 -101
- package/batteries/llm/litert_lm/adapter.mjs.map +1 -1
- package/batteries/llm/litert_lm/helpers.cjs +137 -44
- package/batteries/llm/litert_lm/helpers.cjs.map +1 -1
- package/batteries/llm/litert_lm/helpers.d.ts +74 -16
- package/batteries/llm/litert_lm/helpers.mjs +89 -45
- package/batteries/llm/litert_lm/helpers.mjs.map +1 -1
- package/batteries/llm/litert_lm/index.d.ts +4 -1
- package/batteries/llm/litert_lm/types.d.ts +94 -6
- package/batteries/llm/litert_lm/validation.cjs +35 -8
- package/batteries/llm/litert_lm/validation.cjs.map +1 -1
- package/batteries/llm/litert_lm/validation.mjs +35 -8
- package/batteries/llm/litert_lm/validation.mjs.map +1 -1
- package/batteries/llm/litert_lm.cjs +35 -1
- package/batteries/llm/litert_lm.mjs +5 -3
- package/batteries/llm/ollama/adapter.cjs +6 -6
- package/batteries/llm/ollama/adapter.mjs +6 -6
- package/batteries/llm/ollama/helpers.cjs +7 -7
- package/batteries/llm/ollama/helpers.cjs.map +1 -1
- package/batteries/llm/ollama/helpers.mjs +7 -7
- package/batteries/llm/ollama/helpers.mjs.map +1 -1
- package/batteries/llm/ollama/validation.cjs +1 -1
- package/batteries/llm/ollama/validation.mjs +1 -1
- package/batteries/llm/ollama.cjs +1 -1
- package/batteries/llm/ollama.mjs +1 -1
- 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 +16 -10
- package/batteries/llm/openai_chat_completions/helpers.cjs.map +1 -1
- package/batteries/llm/openai_chat_completions/helpers.d.ts +1 -1
- package/batteries/llm/openai_chat_completions/helpers.mjs +12 -11
- package/batteries/llm/openai_chat_completions/helpers.mjs.map +1 -1
- package/batteries/llm/openai_chat_completions/index.d.ts +1 -1
- package/batteries/llm/openai_chat_completions/validation.cjs +1 -1
- package/batteries/llm/openai_chat_completions/validation.mjs +1 -1
- package/batteries/llm/openai_chat_completions.cjs +6 -1
- package/batteries/llm/openai_chat_completions.mjs +2 -2
- package/batteries/llm/transformers_js/adapter.cjs +760 -0
- package/batteries/llm/transformers_js/adapter.cjs.map +1 -0
- package/batteries/llm/transformers_js/adapter.d.ts +88 -0
- package/batteries/llm/transformers_js/adapter.mjs +757 -0
- package/batteries/llm/transformers_js/adapter.mjs.map +1 -0
- package/batteries/llm/transformers_js/exceptions.cjs +65 -0
- package/batteries/llm/transformers_js/exceptions.cjs.map +1 -0
- package/batteries/llm/transformers_js/exceptions.d.ts +70 -0
- package/batteries/llm/transformers_js/exceptions.mjs +58 -0
- package/batteries/llm/transformers_js/exceptions.mjs.map +1 -0
- package/batteries/llm/transformers_js/helpers.cjs +442 -0
- package/batteries/llm/transformers_js/helpers.cjs.map +1 -0
- package/batteries/llm/transformers_js/helpers.d.ts +223 -0
- package/batteries/llm/transformers_js/helpers.mjs +357 -0
- package/batteries/llm/transformers_js/helpers.mjs.map +1 -0
- package/batteries/llm/transformers_js/index.d.ts +32 -0
- package/batteries/llm/transformers_js/model_source.cjs +144 -0
- package/batteries/llm/transformers_js/model_source.cjs.map +1 -0
- package/batteries/llm/transformers_js/model_source.d.ts +95 -0
- package/batteries/llm/transformers_js/model_source.mjs +139 -0
- package/batteries/llm/transformers_js/model_source.mjs.map +1 -0
- package/batteries/llm/transformers_js/types.cjs +2 -0
- package/batteries/llm/transformers_js/types.d.ts +235 -0
- package/batteries/llm/transformers_js/types.mjs +0 -0
- package/batteries/llm/transformers_js/validation.cjs +126 -0
- package/batteries/llm/transformers_js/validation.cjs.map +1 -0
- package/batteries/llm/transformers_js/validation.d.ts +19 -0
- package/batteries/llm/transformers_js/validation.mjs +123 -0
- package/batteries/llm/transformers_js/validation.mjs.map +1 -0
- package/batteries/llm/transformers_js.cjs +108 -0
- package/batteries/llm/transformers_js.mjs +10 -0
- package/batteries/llm/webllm_chat_completions/adapter.cjs +56 -22
- package/batteries/llm/webllm_chat_completions/adapter.cjs.map +1 -1
- package/batteries/llm/webllm_chat_completions/adapter.mjs +56 -22
- package/batteries/llm/webllm_chat_completions/adapter.mjs.map +1 -1
- 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/index.d.ts +1 -1
- package/batteries/llm/webllm_chat_completions/types.d.ts +11 -1
- package/batteries/llm/webllm_chat_completions/validation.cjs +14 -6
- package/batteries/llm/webllm_chat_completions/validation.cjs.map +1 -1
- package/batteries/llm/webllm_chat_completions/validation.mjs +14 -6
- package/batteries/llm/webllm_chat_completions/validation.mjs.map +1 -1
- package/batteries/llm/webllm_chat_completions.cjs +1 -1
- package/batteries/llm/webllm_chat_completions.mjs +1 -1
- package/batteries/llm.cjs +29 -1
- package/batteries/llm.mjs +13 -5
- package/batteries/media/contracts.cjs +1 -1
- package/batteries/media/contracts.mjs +1 -1
- package/batteries/media/engines/audio_decode.cjs +1 -1
- package/batteries/media/engines/audio_decode.mjs +1 -1
- package/batteries/media/engines/data.cjs +1 -1
- package/batteries/media/engines/data.mjs +1 -1
- package/batteries/media/engines/exceljs.cjs +1 -1
- package/batteries/media/engines/exceljs.mjs +1 -1
- package/batteries/media/engines/execa_executor.cjs +1 -1
- package/batteries/media/engines/execa_executor.mjs +1 -1
- package/batteries/media/engines/fs_workspace.cjs +1 -1
- package/batteries/media/engines/fs_workspace.mjs +1 -1
- package/batteries/media/engines/jimp.cjs +1 -1
- package/batteries/media/engines/jimp.mjs +1 -1
- package/batteries/media/engines/sharp.cjs +1 -1
- package/batteries/media/engines/sharp.mjs +1 -1
- package/batteries/media/engines/sheetjs.cjs +1 -1
- package/batteries/media/engines/sheetjs.mjs +1 -1
- package/batteries/media/engines/tesseract_js.cjs +1 -1
- package/batteries/media/engines/tesseract_js.mjs +1 -1
- package/batteries/media/engines/transformers_asr.cjs +1 -1
- package/batteries/media/engines/transformers_asr.mjs +1 -1
- package/batteries/media/forge.cjs +6 -6
- package/batteries/media/forge.mjs +6 -6
- package/batteries/media/lint.cjs +1 -1
- package/batteries/media/lint.mjs +1 -1
- package/batteries/media.cjs +2 -2
- package/batteries/media.mjs +2 -2
- package/batteries/storage/flydrive.cjs +1 -1
- package/batteries/storage/flydrive.mjs +1 -1
- package/batteries/storage/in_memory.cjs +1 -1
- package/batteries/storage/in_memory.mjs +1 -1
- package/batteries/storage/opfs.cjs +1 -1
- package/batteries/storage/opfs.mjs +1 -1
- package/batteries/tools/_shared.cjs +2 -2
- package/batteries/tools/_shared.mjs +2 -2
- package/batteries/tools/color.cjs +2 -2
- package/batteries/tools/color.mjs +2 -2
- package/batteries/tools/comparison.cjs +3 -3
- package/batteries/tools/comparison.mjs +3 -3
- package/batteries/tools/data_structure.cjs +3 -3
- package/batteries/tools/data_structure.mjs +3 -3
- package/batteries/tools/datetime_extended.cjs +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 +3 -3
- package/batteries/tools/encoding.mjs +3 -3
- package/batteries/tools/formatting.cjs +3 -3
- package/batteries/tools/formatting.mjs +3 -3
- package/batteries/tools/geo_basics.cjs +2 -2
- package/batteries/tools/geo_basics.mjs +2 -2
- package/batteries/tools/math.cjs +3 -3
- package/batteries/tools/math.mjs +3 -3
- package/batteries/tools/memory.cjs +6 -6
- package/batteries/tools/memory.mjs +6 -6
- package/batteries/tools/parsing.cjs +4 -4
- package/batteries/tools/parsing.mjs +4 -4
- 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 +4 -4
- package/batteries/tools/standing_instructions.mjs +4 -4
- package/batteries/tools/statistics.cjs +4 -4
- package/batteries/tools/statistics.mjs +4 -4
- package/batteries/tools/string_processing.cjs +3 -3
- package/batteries/tools/string_processing.mjs +3 -3
- package/batteries/tools/structured_data.cjs +3 -3
- package/batteries/tools/structured_data.mjs +3 -3
- package/batteries/tools/text_analysis.cjs +3 -3
- package/batteries/tools/text_analysis.mjs +3 -3
- package/batteries/tools/text_comparison.cjs +2 -2
- package/batteries/tools/text_comparison.mjs +2 -2
- package/batteries/tools/time.cjs +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/web_retrieval.cjs +1 -1
- package/batteries/tools/web_retrieval.mjs +1 -1
- package/batteries/tools.cjs +2 -2
- package/batteries/tools.mjs +2 -2
- package/batteries/vector/arangodb.cjs +1 -1
- package/batteries/vector/arangodb.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/filters.cjs +1 -1
- package/batteries/vector/filters.mjs +1 -1
- package/batteries/vector/hnswlib.cjs +1 -1
- package/batteries/vector/hnswlib.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/meilisearch.cjs +1 -1
- package/batteries/vector/meilisearch.mjs +1 -1
- package/batteries/vector/migrate.cjs +1 -1
- package/batteries/vector/migrate.mjs +1 -1
- package/batteries/vector/mongodb.cjs +1 -1
- package/batteries/vector/mongodb.mjs +1 -1
- package/batteries/vector/neo4j.cjs +1 -1
- package/batteries/vector/neo4j.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/pinecone.cjs +1 -1
- package/batteries/vector/pinecone.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/solr.cjs +1 -1
- package/batteries/vector/solr.mjs +1 -1
- package/batteries/vector/surrealdb.cjs +1 -1
- package/batteries/vector/surrealdb.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.cjs +37 -3
- package/batteries.mjs +17 -8
- package/{common-0CmrSKNb.mjs → common-DJH3UemH.mjs} +7 -7
- package/{common-0CmrSKNb.mjs.map → common-DJH3UemH.mjs.map} +1 -1
- package/{common-CpcsEqPY.js → common-ax3vKu6O.js} +7 -7
- package/{common-CpcsEqPY.js.map → common-ax3vKu6O.js.map} +1 -1
- package/common.cjs +7 -7
- package/common.mjs +7 -7
- package/{dispatch_runner-C2ZpFfw4.mjs → dispatch_runner-3anlRk3F.mjs} +3 -3
- package/{dispatch_runner-C2ZpFfw4.mjs.map → dispatch_runner-3anlRk3F.mjs.map} +1 -1
- package/{dispatch_runner-DMTkGHQI.js → dispatch_runner-CTkL_cMm.js} +3 -3
- package/{dispatch_runner-DMTkGHQI.js.map → dispatch_runner-CTkL_cMm.js.map} +1 -1
- package/dispatch_runner.cjs +1 -1
- package/dispatch_runner.mjs +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/forge.cjs +4 -4
- package/forge.mjs +4 -4
- package/guards.cjs +8 -8
- package/guards.mjs +8 -8
- package/{helpers-1okZzNCa.js → helpers-CJcqikes.js} +131 -1
- package/helpers-CJcqikes.js.map +1 -0
- package/{helpers-BCyDAn_R.mjs → helpers-DlrRbLVn.mjs} +102 -2
- package/helpers-DlrRbLVn.mjs.map +1 -0
- package/index.cjs +11 -11
- package/index.mjs +11 -11
- package/lifecycle-C4kwYJ-N.mjs +68 -0
- package/lifecycle-C4kwYJ-N.mjs.map +1 -0
- package/lifecycle-vYQJ2rmf.js +79 -0
- package/lifecycle-vYQJ2rmf.js.map +1 -0
- package/mcp/adk-docs-corpus.json +1 -1
- package/package.json +231 -166
- package/reasoning_parsers-CFNoFf6x.js +1016 -0
- package/reasoning_parsers-CFNoFf6x.js.map +1 -0
- package/reasoning_parsers-Dp66LFBt.mjs +747 -0
- package/reasoning_parsers-Dp66LFBt.mjs.map +1 -0
- package/{scrapper-DpTMyQcz.mjs → scrapper-BrViMDPI.mjs} +5 -5
- package/{scrapper-DpTMyQcz.mjs.map → scrapper-BrViMDPI.mjs.map} +1 -1
- package/{scrapper-B5G70UqQ.js → scrapper-CzgdX1NN.js} +5 -5
- package/{scrapper-B5G70UqQ.js.map → scrapper-CzgdX1NN.js.map} +1 -1
- package/{searxng-Q79l7IdQ.js → searxng-B5I1KmQj.js} +5 -5
- package/{searxng-Q79l7IdQ.js.map → searxng-B5I1KmQj.js.map} +1 -1
- package/{searxng-L-wd-A_n.mjs → searxng-BvjwwZav.mjs} +5 -5
- package/{searxng-L-wd-A_n.mjs.map → searxng-BvjwwZav.mjs.map} +1 -1
- package/server.json +2 -2
- package/skills/adk-assembly/SKILL.md +2 -2
- package/{spooled_artifact-fgc1lutm.mjs → spooled_artifact-BnbqIZ3a.mjs} +3 -3
- package/{spooled_artifact-fgc1lutm.mjs.map → spooled_artifact-BnbqIZ3a.mjs.map} +1 -1
- package/{spooled_artifact-MbMz6NXX.js → spooled_artifact-DrIR90nV.js} +3 -3
- package/{spooled_artifact-MbMz6NXX.js.map → spooled_artifact-DrIR90nV.js.map} +1 -1
- package/spooled_artifact.cjs +2 -2
- package/spooled_artifact.mjs +2 -2
- package/{spooled_markdown_artifact-3sK6HFRw.mjs → spooled_markdown_artifact-BJH_JZFm.mjs} +3 -3
- package/{spooled_markdown_artifact-3sK6HFRw.mjs.map → spooled_markdown_artifact-BJH_JZFm.mjs.map} +1 -1
- package/{spooled_markdown_artifact-Gj0ruiLJ.js → spooled_markdown_artifact-rg_WCNWq.js} +3 -3
- package/{spooled_markdown_artifact-Gj0ruiLJ.js.map → spooled_markdown_artifact-rg_WCNWq.js.map} +1 -1
- package/{thought-CU7PYkB1.js → thought-CE88bddw.js} +3 -3
- package/{thought-CU7PYkB1.js.map → thought-CE88bddw.js.map} +1 -1
- package/{thought-DmcfCRAw.mjs → thought-DdiQCpgX.mjs} +3 -3
- package/{thought-DmcfCRAw.mjs.map → thought-DdiQCpgX.mjs.map} +1 -1
- package/{tool-Bt6tmFXT.js → tool-BngpaOWb.js} +3 -3
- package/{tool-Bt6tmFXT.js.map → tool-BngpaOWb.js.map} +1 -1
- package/{tool-C_uxdxjp.mjs → tool-asIfCjxb.mjs} +3 -3
- package/{tool-C_uxdxjp.mjs.map → tool-asIfCjxb.mjs.map} +1 -1
- package/{tool_call-BixyvnWZ.js → tool_call-CZVmISyc.js} +4 -4
- package/{tool_call-BixyvnWZ.js.map → tool_call-CZVmISyc.js.map} +1 -1
- package/{tool_call-pfvAsgkY.mjs → tool_call-TtzdXxcb.mjs} +4 -4
- package/{tool_call-pfvAsgkY.mjs.map → tool_call-TtzdXxcb.mjs.map} +1 -1
- package/{tool_registry-FeMMz993.mjs → tool_registry-Bj0JhXCv.mjs} +164 -164
- package/tool_registry-Bj0JhXCv.mjs.map +1 -0
- package/{tool_registry-CIIfbY_w.js → tool_registry-DbS8Pem9.js} +163 -163
- package/tool_registry-DbS8Pem9.js.map +1 -0
- package/{turn_runner-Brz6Sd0F.mjs → turn_runner-305dGa72.mjs} +5 -5
- package/{turn_runner-Brz6Sd0F.mjs.map → turn_runner-305dGa72.mjs.map} +1 -1
- package/{turn_runner-DB-WWls8.js → turn_runner-DqJBbqeU.js} +5 -5
- package/{turn_runner-DB-WWls8.js.map → turn_runner-DqJBbqeU.js.map} +1 -1
- package/turn_runner.cjs +1 -1
- package/turn_runner.mjs +1 -1
- package/{validate-MBEmBzMl.mjs → validate-B8IGAERs.mjs} +2 -2
- package/{validate-MBEmBzMl.mjs.map → validate-B8IGAERs.mjs.map} +1 -1
- package/{validate-B4RXgYJC.js → validate-Cq8xhZrZ.js} +2 -2
- package/{validate-B4RXgYJC.js.map → validate-Cq8xhZrZ.js.map} +1 -1
- package/helpers-1okZzNCa.js.map +0 -1
- package/helpers-BCyDAn_R.mjs.map +0 -1
- package/tool_registry-CIIfbY_w.js.map +0 -1
- package/tool_registry-FeMMz993.mjs.map +0 -1
|
@@ -0,0 +1,747 @@
|
|
|
1
|
+
import { u as isObject } from "./tool_registry-Bj0JhXCv.mjs";
|
|
2
|
+
import "./guards.mjs";
|
|
3
|
+
//#region src/batteries/llm/chat_common/tool_parsers.ts
|
|
4
|
+
/**
|
|
5
|
+
* Runtime-agnostic tool-call text parsers for text-only LLM batteries.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* **Why this exists.** On-device runtimes like transformers.js and LiteRT-LM (v0.13.1) are
|
|
9
|
+
* text-in / text-out: they inject tool definitions into the chat template, but the model emits its
|
|
10
|
+
* tool calls as **raw text in the assistant message**, in a format specific to the model family it
|
|
11
|
+
* was fine-tuned on. Unlike the OpenAI/Ollama wire batteries — where the provider returns a
|
|
12
|
+
* structured `tool_calls` array — these batteries must parse the call out of the text themselves.
|
|
13
|
+
*
|
|
14
|
+
* This mirrors how vLLM / SGLang / Ollama do it: one **post-hoc** parser per model family, selected
|
|
15
|
+
* by a flag, run *after* generation (sub-millisecond, fails gracefully, never constrains decoding).
|
|
16
|
+
* Each family parser is anchored on a literal marker (or, for the weak-signal JSON/pythonic forms, on
|
|
17
|
+
* the callee name matching a real tool) so cross-family false positives are structurally impossible.
|
|
18
|
+
*
|
|
19
|
+
* **Formats are model-specific and drift across versions** (e.g. Gemma has three incompatible tool
|
|
20
|
+
* formats across its generations; gpt-oss's Harmony channel ordering is an active upstream bug). The
|
|
21
|
+
* bundled defaults target the small ONNX models that actually run in transformers.js; the `'auto'`
|
|
22
|
+
* driver fails gracefully and a custom {@link ToolCallParserFn} is the escape hatch for anything else.
|
|
23
|
+
*
|
|
24
|
+
* NOT `@module`-tagged: private to the bundled LLM batteries, re-exported through their public
|
|
25
|
+
* surfaces (`transformers_js`, `litert_lm`). Consumers import from those battery subpaths.
|
|
26
|
+
*/
|
|
27
|
+
var NO_MATCH$1 = (rawText) => ({
|
|
28
|
+
calls: [],
|
|
29
|
+
cleanedText: rawText
|
|
30
|
+
});
|
|
31
|
+
var asArgsObject = (value) => isObject(value) ? value : {};
|
|
32
|
+
/**
|
|
33
|
+
* Remove a set of `[start, end)` spans from `text` (descending by start so offsets stay valid),
|
|
34
|
+
* collapse the resulting whitespace seams, and trim.
|
|
35
|
+
*/
|
|
36
|
+
var removeSpans$1 = (text, spans) => {
|
|
37
|
+
let out = text;
|
|
38
|
+
for (const [start, end] of [...spans].sort((a, b) => b[0] - a[0])) out = out.slice(0, start) + out.slice(end);
|
|
39
|
+
return out.replace(/\n{3,}/g, "\n\n").trim();
|
|
40
|
+
};
|
|
41
|
+
/** Try to JSON.parse; return undefined on failure (parsers decline rather than throw). */
|
|
42
|
+
var tryJsonParse = (s) => {
|
|
43
|
+
try {
|
|
44
|
+
return JSON.parse(s);
|
|
45
|
+
} catch {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* From `text`, with `from` pointing AT an opening `open` char, return the index of its matching
|
|
51
|
+
* `close` char — string-aware, so a delimiter inside a JSON string literal (e.g. a `}` or `]` or a
|
|
52
|
+
* `</tool_call>`-shaped substring inside `{"text":"…"}`) is NOT miscounted. Returns -1 if the run is
|
|
53
|
+
* unbalanced (e.g. a truncated stream). This is the brace/bracket scan that makes the marker-anchored
|
|
54
|
+
* parsers robust to embedded markup in argument values — the dominant failure class the red-team panel
|
|
55
|
+
* found in the old lazy/greedy regexes.
|
|
56
|
+
*/
|
|
57
|
+
var scanBalanced = (text, from, open, close) => {
|
|
58
|
+
let depth = 0;
|
|
59
|
+
let inStr = false;
|
|
60
|
+
let escaped = false;
|
|
61
|
+
for (let i = from; i < text.length; i++) {
|
|
62
|
+
const ch = text[i];
|
|
63
|
+
if (inStr) {
|
|
64
|
+
if (escaped) escaped = false;
|
|
65
|
+
else if (ch === "\\") escaped = true;
|
|
66
|
+
else if (ch === "\"") inStr = false;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (ch === "\"") inStr = true;
|
|
70
|
+
else if (ch === open) depth++;
|
|
71
|
+
else if (ch === close) {
|
|
72
|
+
depth--;
|
|
73
|
+
if (depth === 0) return i;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return -1;
|
|
77
|
+
};
|
|
78
|
+
var HERMES_OPEN = "<tool_call>";
|
|
79
|
+
/**
|
|
80
|
+
* Parse Hermes-style `<tool_call>{"name":…,"arguments":{…}}</tool_call>` tags. The de-facto standard,
|
|
81
|
+
* reused by Qwen2.5/Qwen3-Instruct. Anchored on the literal tags — zero collision with bare JSON.
|
|
82
|
+
*
|
|
83
|
+
* @remarks
|
|
84
|
+
* The JSON object after each `<tool_call>` is located by a string-aware balanced-brace scan (not a lazy
|
|
85
|
+
* `</tool_call>` regex), so an embedded `</tool_call>` or `{`/`}` inside a string argument value (e.g.
|
|
86
|
+
* `{"text":"</tool_call>"}`) survives instead of truncating the call. The literal `</tool_call>` close
|
|
87
|
+
* is still consumed for span removal when present immediately after the object.
|
|
88
|
+
*/
|
|
89
|
+
var hermesToolCallParser = (rawText) => {
|
|
90
|
+
const calls = [];
|
|
91
|
+
const spans = [];
|
|
92
|
+
let searchFrom = 0;
|
|
93
|
+
for (;;) {
|
|
94
|
+
const openIdx = rawText.indexOf(HERMES_OPEN, searchFrom);
|
|
95
|
+
if (openIdx === -1) break;
|
|
96
|
+
const braceStart = rawText.indexOf("{", openIdx + 11);
|
|
97
|
+
if (braceStart === -1) break;
|
|
98
|
+
const braceEnd = scanBalanced(rawText, braceStart, "{", "}");
|
|
99
|
+
if (braceEnd === -1) break;
|
|
100
|
+
const obj = tryJsonParse(rawText.slice(braceStart, braceEnd + 1));
|
|
101
|
+
const afterObj = rawText.slice(braceEnd + 1);
|
|
102
|
+
const closeRel = /^\s*<\/tool_call>/.exec(afterObj);
|
|
103
|
+
if (closeRel && isObject(obj) && typeof obj.name === "string") {
|
|
104
|
+
const o = obj;
|
|
105
|
+
calls.push({
|
|
106
|
+
name: o.name,
|
|
107
|
+
arguments: asArgsObject(o.arguments)
|
|
108
|
+
});
|
|
109
|
+
spans.push([openIdx, braceEnd + 1 + closeRel[0].length]);
|
|
110
|
+
searchFrom = braceEnd + 1 + closeRel[0].length;
|
|
111
|
+
} else searchFrom = braceEnd + 1;
|
|
112
|
+
}
|
|
113
|
+
return calls.length > 0 ? {
|
|
114
|
+
calls,
|
|
115
|
+
cleanedText: removeSpans$1(rawText, spans)
|
|
116
|
+
} : NO_MATCH$1(rawText);
|
|
117
|
+
};
|
|
118
|
+
/** Default {@link hermesToolCallParser}. */
|
|
119
|
+
var defaultHermesToolCallParser = hermesToolCallParser;
|
|
120
|
+
var GEMMA_WRAP_RE = /<\|tool_call>\s*call:\s*([A-Za-z_]\w*)\s*(\{[^{}]*\})\s*<tool_call\|>/g;
|
|
121
|
+
var GEMMA_BARE_RE = /call:\s*([A-Za-z_]\w*)\s*(\{[^{}]*\})/g;
|
|
122
|
+
/** Normalise a Gemma arg block (`{k:<|"|>v<|"|>}` or stripped `{k:v}`) into JSON. */
|
|
123
|
+
var gemmaArgsToJson = (argsBlock) => {
|
|
124
|
+
return tryJsonParse(argsBlock.replace(/<\|"\|>/g, "\"").replace(/([{,]\s*)([A-Za-z_]\w*)\s*:/g, "$1\"$2\":").replace(/:\s*(?!["\d-]|true\b|false\b|null\b)([^,}\]]+?)\s*([,}\]])/g, ":\"$1\"$2"));
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Parse Gemma E2B/E4B tool calls. Accepts the wrapped template form
|
|
128
|
+
* (`<|tool_call>call:NAME{k:<|"|>v<|"|>}<tool_call|>`) AND the decoder-stripped runtime form
|
|
129
|
+
* (`call:NAME{k:v}`, special tokens removed, scalars unquoted — the shape a real ONNX run emits).
|
|
130
|
+
* Targets the E2B/E4B form only — Gemma 3 (`tool_code` fences) and FunctionGemma
|
|
131
|
+
* (`<start_function_call>`) are out of scope (use a custom {@link ToolCallParserFn}).
|
|
132
|
+
*/
|
|
133
|
+
var gemmaToolCallParser = (rawText) => {
|
|
134
|
+
const calls = [];
|
|
135
|
+
const spans = [];
|
|
136
|
+
for (const m of rawText.matchAll(GEMMA_WRAP_RE)) {
|
|
137
|
+
calls.push({
|
|
138
|
+
name: m[1],
|
|
139
|
+
arguments: asArgsObject(gemmaArgsToJson(m[2]))
|
|
140
|
+
});
|
|
141
|
+
spans.push([m.index ?? 0, (m.index ?? 0) + m[0].length]);
|
|
142
|
+
}
|
|
143
|
+
if (calls.length === 0) for (const m of rawText.matchAll(GEMMA_BARE_RE)) {
|
|
144
|
+
calls.push({
|
|
145
|
+
name: m[1],
|
|
146
|
+
arguments: asArgsObject(gemmaArgsToJson(m[2]))
|
|
147
|
+
});
|
|
148
|
+
spans.push([m.index ?? 0, (m.index ?? 0) + m[0].length]);
|
|
149
|
+
}
|
|
150
|
+
return calls.length > 0 ? {
|
|
151
|
+
calls,
|
|
152
|
+
cleanedText: removeSpans$1(rawText, spans)
|
|
153
|
+
} : NO_MATCH$1(rawText);
|
|
154
|
+
};
|
|
155
|
+
/** Default {@link gemmaToolCallParser}. */
|
|
156
|
+
var defaultGemmaToolCallParser = gemmaToolCallParser;
|
|
157
|
+
var GPT_OSS_HEAD_RE = /<\|channel\|>commentary\s+to=functions\.([A-Za-z0-9_]+)[\s\S]*?<\|message\|>/g;
|
|
158
|
+
var GPT_OSS_CALL = "<|call|>";
|
|
159
|
+
/**
|
|
160
|
+
* Parse gpt-oss Harmony tool calls on the `commentary` channel:
|
|
161
|
+
* `<|channel|>commentary to=functions.NAME <|constrain|>json<|message|>{…}<|call|>`. The arguments
|
|
162
|
+
* payload after `<|message|>` is JSON, located by a string-aware balanced-brace scan so an embedded
|
|
163
|
+
* `<|call|>` / brace inside a string value survives. Anchored on the literal Harmony markers.
|
|
164
|
+
*
|
|
165
|
+
* @remarks The Harmony channel/constrain ordering has a documented upstream template-vs-spec drift;
|
|
166
|
+
* this matches the common ordering. Verify against a real gpt-oss ONNX run when one is available.
|
|
167
|
+
*/
|
|
168
|
+
var gptOssToolCallParser = (rawText) => {
|
|
169
|
+
const calls = [];
|
|
170
|
+
const spans = [];
|
|
171
|
+
for (const m of rawText.matchAll(GPT_OSS_HEAD_RE)) {
|
|
172
|
+
const headStart = m.index ?? 0;
|
|
173
|
+
const afterMsg = headStart + m[0].length;
|
|
174
|
+
const braceStart = rawText.indexOf("{", afterMsg);
|
|
175
|
+
if (braceStart === -1) continue;
|
|
176
|
+
const braceEnd = scanBalanced(rawText, braceStart, "{", "}");
|
|
177
|
+
if (braceEnd === -1) continue;
|
|
178
|
+
const obj = tryJsonParse(rawText.slice(braceStart, braceEnd + 1));
|
|
179
|
+
if (!isObject(obj)) continue;
|
|
180
|
+
const afterObj = rawText.slice(braceEnd + 1);
|
|
181
|
+
const callRel = new RegExp(`^\\s*${GPT_OSS_CALL.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`).exec(afterObj);
|
|
182
|
+
if (!callRel) continue;
|
|
183
|
+
calls.push({
|
|
184
|
+
name: m[1],
|
|
185
|
+
arguments: asArgsObject(obj)
|
|
186
|
+
});
|
|
187
|
+
spans.push([headStart, braceEnd + 1 + callRel[0].length]);
|
|
188
|
+
}
|
|
189
|
+
return calls.length > 0 ? {
|
|
190
|
+
calls,
|
|
191
|
+
cleanedText: removeSpans$1(rawText, spans)
|
|
192
|
+
} : NO_MATCH$1(rawText);
|
|
193
|
+
};
|
|
194
|
+
/** Default {@link gptOssToolCallParser}. */
|
|
195
|
+
var defaultGptOssToolCallParser = gptOssToolCallParser;
|
|
196
|
+
var PYTHONIC_SHAPE_RE = /^\[\s*[A-Za-z_]\w*\s*\(.*\)\s*\]$/s;
|
|
197
|
+
var PYTHONIC_CALL_RE = /([A-Za-z_]\w*)\s*\(([^)]*)\)/g;
|
|
198
|
+
/** Read a single pythonic literal: quoted string, number, True/False/None. */
|
|
199
|
+
var readPythonLiteral = (raw) => {
|
|
200
|
+
const t = raw.trim();
|
|
201
|
+
if (/^(['"]).*\1$/s.test(t)) return t.slice(1, -1);
|
|
202
|
+
if (t === "True" || t === "true") return true;
|
|
203
|
+
if (t === "False" || t === "false") return false;
|
|
204
|
+
if (t === "None" || t === "null") return null;
|
|
205
|
+
const n = Number(t);
|
|
206
|
+
return Number.isFinite(n) ? n : t;
|
|
207
|
+
};
|
|
208
|
+
/** Split `k=v, k2=v2` on top-level commas (ignores commas inside quotes/brackets). */
|
|
209
|
+
var splitPythonArgs = (s) => {
|
|
210
|
+
const parts = [];
|
|
211
|
+
let depth = 0;
|
|
212
|
+
let quote;
|
|
213
|
+
let cur = "";
|
|
214
|
+
for (const ch of s) {
|
|
215
|
+
if (quote) {
|
|
216
|
+
cur += ch;
|
|
217
|
+
if (ch === quote) quote = void 0;
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
if (ch === "\"" || ch === "'") {
|
|
221
|
+
quote = ch;
|
|
222
|
+
cur += ch;
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
if (ch === "(" || ch === "[" || ch === "{") depth++;
|
|
226
|
+
if (ch === ")" || ch === "]" || ch === "}") depth--;
|
|
227
|
+
if (ch === "," && depth === 0) {
|
|
228
|
+
parts.push(cur);
|
|
229
|
+
cur = "";
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
cur += ch;
|
|
233
|
+
}
|
|
234
|
+
if (cur.trim().length > 0) parts.push(cur);
|
|
235
|
+
return parts;
|
|
236
|
+
};
|
|
237
|
+
/**
|
|
238
|
+
* Parse pythonic tool calls — `[get_weather(city='SF'), get_time()]`. Requires the **whole trimmed
|
|
239
|
+
* output** to be the bracketed call list, so it cannot false-positive on incidental prose. Parallel
|
|
240
|
+
* calls are inherent to the format.
|
|
241
|
+
*
|
|
242
|
+
* **Disambiguation, NOT authorization.** The `[fn(args), …]` shape (whole-output) is the structural
|
|
243
|
+
* signal that this is a call list. It deliberately does NOT check callees against `ctx.toolNames` —
|
|
244
|
+
* whether a tool is *allowed* is the consumer's call, and the dispatch layer already replies "Tool not
|
|
245
|
+
* found: … Available tools: …" so the model can self-correct. Dropping an unknown-tool call here would
|
|
246
|
+
* hide the request and that feedback loop.
|
|
247
|
+
*/
|
|
248
|
+
var pythonicToolCallParser = (rawText) => {
|
|
249
|
+
const t = rawText.trim();
|
|
250
|
+
if (!PYTHONIC_SHAPE_RE.test(t)) return NO_MATCH$1(rawText);
|
|
251
|
+
const inner = t.slice(1, -1);
|
|
252
|
+
const calls = [];
|
|
253
|
+
for (const m of inner.matchAll(PYTHONIC_CALL_RE)) {
|
|
254
|
+
const name = m[1];
|
|
255
|
+
const args = {};
|
|
256
|
+
for (const pair of splitPythonArgs(m[2])) {
|
|
257
|
+
const eq = pair.indexOf("=");
|
|
258
|
+
if (eq < 0) continue;
|
|
259
|
+
args[pair.slice(0, eq).trim()] = readPythonLiteral(pair.slice(eq + 1));
|
|
260
|
+
}
|
|
261
|
+
calls.push({
|
|
262
|
+
name,
|
|
263
|
+
arguments: args
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
return calls.length > 0 ? {
|
|
267
|
+
calls,
|
|
268
|
+
cleanedText: ""
|
|
269
|
+
} : NO_MATCH$1(rawText);
|
|
270
|
+
};
|
|
271
|
+
/** Default {@link pythonicToolCallParser}. */
|
|
272
|
+
var defaultPythonicToolCallParser = pythonicToolCallParser;
|
|
273
|
+
/** Strip a single surrounding ```` ```json … ``` ```` (or bare ```` ``` ```` ) fence, if present. */
|
|
274
|
+
var stripCodeFence = (text) => {
|
|
275
|
+
const m = /^```(?:json)?\s*\n?([\s\S]*?)\n?```$/.exec(text.trim());
|
|
276
|
+
return m ? m[1].trim() : text.trim();
|
|
277
|
+
};
|
|
278
|
+
/**
|
|
279
|
+
* Parse bare top-level JSON tool call(s) — `{"name":"x","parameters":{…}}` (or `"arguments"`),
|
|
280
|
+
* optionally wrapped in a ```` ```json … ``` ```` fence (a common small-model emission — verified via
|
|
281
|
+
* the real-model matrix on Qwen2.5-Coder-0.5B). The weakest signal, so it is gated hard: after
|
|
282
|
+
* un-fencing, the output must be ONLY top-level JSON object(s) AND every callee must be a real tool
|
|
283
|
+
* (`ctx.toolNames`). Runs after every marker-anchored family in `'auto'`.
|
|
284
|
+
*
|
|
285
|
+
* @remarks
|
|
286
|
+
* **Parallel calls.** Small Llama-family / Qwen-Coder models emit MULTIPLE calls as several top-level
|
|
287
|
+
* objects separated by `,` / `;` / whitespace (verified on the real-model matrix:
|
|
288
|
+
* Llama-3.2-1B → `{…}; {…}`, Qwen2.5-Coder-0.5B → a fenced `{…},\n{…}`). So we string-aware brace-scan
|
|
289
|
+
* the (un-fenced) text into successive balanced `{…}` objects, accepting only the separators above
|
|
290
|
+
* between them — if any NON-separator prose sits between or around the objects, the whole thing declines
|
|
291
|
+
* (the hard whole-output gate, so this never false-positives on JSON embedded in a sentence).
|
|
292
|
+
*
|
|
293
|
+
* **Disambiguation, NOT authorization.** This parser is marker-free, so it must distinguish a tool call
|
|
294
|
+
* from arbitrary JSON content. It does that STRUCTURALLY: whole-output-is-object(s) + each object has a
|
|
295
|
+
* string `name`. It deliberately does NOT check the callee against `ctx.toolNames` — whether a requested
|
|
296
|
+
* tool is *allowed* is the consumer's decision, not the parser's. An unknown-tool call is surfaced like
|
|
297
|
+
* any other; the dispatch layer already replies "Tool not found: … Available tools: …" so the model can
|
|
298
|
+
* self-correct. Silently dropping the call here would hide both the request and that feedback loop.
|
|
299
|
+
*/
|
|
300
|
+
var llama3JsonToolCallParser = (rawText) => {
|
|
301
|
+
const t = stripCodeFence(rawText);
|
|
302
|
+
if (!t.startsWith("{") || !t.endsWith("}")) return NO_MATCH$1(rawText);
|
|
303
|
+
const calls = [];
|
|
304
|
+
let i = 0;
|
|
305
|
+
while (i < t.length) {
|
|
306
|
+
if (/[\s,;]/.test(t[i])) {
|
|
307
|
+
i++;
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
if (t[i] !== "{") return NO_MATCH$1(rawText);
|
|
311
|
+
const end = scanBalanced(t, i, "{", "}");
|
|
312
|
+
if (end === -1) return NO_MATCH$1(rawText);
|
|
313
|
+
const obj = tryJsonParse(t.slice(i, end + 1));
|
|
314
|
+
if (!isObject(obj)) return NO_MATCH$1(rawText);
|
|
315
|
+
const o = obj;
|
|
316
|
+
if (typeof o.name !== "string") return NO_MATCH$1(rawText);
|
|
317
|
+
calls.push({
|
|
318
|
+
name: o.name,
|
|
319
|
+
arguments: asArgsObject(o.parameters ?? o.arguments)
|
|
320
|
+
});
|
|
321
|
+
i = end + 1;
|
|
322
|
+
}
|
|
323
|
+
return calls.length > 0 ? {
|
|
324
|
+
calls,
|
|
325
|
+
cleanedText: ""
|
|
326
|
+
} : NO_MATCH$1(rawText);
|
|
327
|
+
};
|
|
328
|
+
/** Default {@link llama3JsonToolCallParser}. */
|
|
329
|
+
var defaultLlama3JsonToolCallParser = llama3JsonToolCallParser;
|
|
330
|
+
var MISTRAL_BOT_TOKEN = "[TOOL_CALLS]";
|
|
331
|
+
/**
|
|
332
|
+
* Parse Mistral tool calls — the `[TOOL_CALLS]` token followed by a JSON array of
|
|
333
|
+
* `{ name, arguments }`. Anchored on the literal `[TOOL_CALLS]` token.
|
|
334
|
+
*
|
|
335
|
+
* @remarks
|
|
336
|
+
* The array is located by a string-aware balanced-bracket scan from the first `[` after the token (same
|
|
337
|
+
* approach as {@link phiToolCallParser}), so a `]` inside a string argument value (e.g.
|
|
338
|
+
* `{"text":"a]b"}`) does not truncate the array the way the old greedy `\[[\s\S]*\]` regex did.
|
|
339
|
+
*/
|
|
340
|
+
var mistralToolCallParser = (rawText) => {
|
|
341
|
+
const tokenIdx = rawText.indexOf(MISTRAL_BOT_TOKEN);
|
|
342
|
+
if (tokenIdx === -1) return NO_MATCH$1(rawText);
|
|
343
|
+
const arrStart = rawText.indexOf("[", tokenIdx + 12);
|
|
344
|
+
if (arrStart === -1) return NO_MATCH$1(rawText);
|
|
345
|
+
const arrEnd = scanBalanced(rawText, arrStart, "[", "]");
|
|
346
|
+
if (arrEnd === -1) return NO_MATCH$1(rawText);
|
|
347
|
+
const arr = tryJsonParse(rawText.slice(arrStart, arrEnd + 1));
|
|
348
|
+
if (!Array.isArray(arr)) return NO_MATCH$1(rawText);
|
|
349
|
+
const calls = [];
|
|
350
|
+
for (const entry of arr) if (isObject(entry) && typeof entry.name === "string") {
|
|
351
|
+
const e = entry;
|
|
352
|
+
calls.push({
|
|
353
|
+
name: e.name,
|
|
354
|
+
arguments: asArgsObject(e.arguments)
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
return calls.length > 0 ? {
|
|
358
|
+
calls,
|
|
359
|
+
cleanedText: removeSpans$1(rawText, [[tokenIdx, arrEnd + 1]])
|
|
360
|
+
} : NO_MATCH$1(rawText);
|
|
361
|
+
};
|
|
362
|
+
/** Default {@link mistralToolCallParser}. */
|
|
363
|
+
var defaultMistralToolCallParser = mistralToolCallParser;
|
|
364
|
+
var QWEN3_CODER_RE = /<tool_call>\s*<function=([A-Za-z0-9_]+)>([\s\S]*?)<\/function>\s*<\/tool_call>/g;
|
|
365
|
+
var QWEN3_PARAM_RE = /<parameter=([A-Za-z0-9_]+)>([\s\S]*?)<\/parameter>/g;
|
|
366
|
+
/**
|
|
367
|
+
* Parse Qwen3-Coder's custom per-parameter XML — `<tool_call><function=NAME><parameter=k>v</parameter>
|
|
368
|
+
* …</function></tool_call>`. Values are taken as trimmed strings (the format is untyped). Anchored on
|
|
369
|
+
* the literal `<function=` tag, distinct from Hermes's JSON-in-`<tool_call>`.
|
|
370
|
+
*/
|
|
371
|
+
var qwen3CoderToolCallParser = (rawText) => {
|
|
372
|
+
const calls = [];
|
|
373
|
+
const spans = [];
|
|
374
|
+
for (const m of rawText.matchAll(QWEN3_CODER_RE)) {
|
|
375
|
+
const args = {};
|
|
376
|
+
for (const p of m[2].matchAll(QWEN3_PARAM_RE)) args[p[1]] = p[2].trim();
|
|
377
|
+
calls.push({
|
|
378
|
+
name: m[1],
|
|
379
|
+
arguments: args
|
|
380
|
+
});
|
|
381
|
+
spans.push([m.index ?? 0, (m.index ?? 0) + m[0].length]);
|
|
382
|
+
}
|
|
383
|
+
return calls.length > 0 ? {
|
|
384
|
+
calls,
|
|
385
|
+
cleanedText: removeSpans$1(rawText, spans)
|
|
386
|
+
} : NO_MATCH$1(rawText);
|
|
387
|
+
};
|
|
388
|
+
/** Default {@link qwen3CoderToolCallParser}. */
|
|
389
|
+
var defaultQwen3CoderToolCallParser = qwen3CoderToolCallParser;
|
|
390
|
+
var PHI_BOT_TOKEN = "functools";
|
|
391
|
+
/**
|
|
392
|
+
* Parse Phi-4-mini tool calls: the literal `functools` token followed by a JSON array of
|
|
393
|
+
* `{ name, arguments }` objects (e.g. `functools[{"name":"get_weather","arguments":{"city":"SF"}}]`).
|
|
394
|
+
*
|
|
395
|
+
* @remarks
|
|
396
|
+
* Anchored on the `functools` begin-of-tool token (vLLM's `phi4_mini_json`). The array is located by
|
|
397
|
+
* scanning for the first `[` after the token and matching to its balanced closing `]`, so trailing
|
|
398
|
+
* prose after the call does not break parsing. Declines (no-match) if the payload is not a JSON array
|
|
399
|
+
* of name-bearing objects.
|
|
400
|
+
*/
|
|
401
|
+
var phiToolCallParser = (rawText) => {
|
|
402
|
+
const tokenIdx = rawText.indexOf(PHI_BOT_TOKEN);
|
|
403
|
+
if (tokenIdx === -1) return NO_MATCH$1(rawText);
|
|
404
|
+
const arrStart = rawText.indexOf("[", tokenIdx + 9);
|
|
405
|
+
if (arrStart === -1) return NO_MATCH$1(rawText);
|
|
406
|
+
let depth = 0;
|
|
407
|
+
let inStr = false;
|
|
408
|
+
let escaped = false;
|
|
409
|
+
let arrEnd = -1;
|
|
410
|
+
for (let i = arrStart; i < rawText.length; i++) {
|
|
411
|
+
const ch = rawText[i];
|
|
412
|
+
if (inStr) {
|
|
413
|
+
if (escaped) escaped = false;
|
|
414
|
+
else if (ch === "\\") escaped = true;
|
|
415
|
+
else if (ch === "\"") inStr = false;
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
if (ch === "\"") inStr = true;
|
|
419
|
+
else if (ch === "[") depth++;
|
|
420
|
+
else if (ch === "]") {
|
|
421
|
+
depth--;
|
|
422
|
+
if (depth === 0) {
|
|
423
|
+
arrEnd = i;
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
if (arrEnd === -1) return NO_MATCH$1(rawText);
|
|
429
|
+
const arr = tryJsonParse(rawText.slice(arrStart, arrEnd + 1));
|
|
430
|
+
if (!Array.isArray(arr)) return NO_MATCH$1(rawText);
|
|
431
|
+
const calls = [];
|
|
432
|
+
for (const entry of arr) if (isObject(entry) && typeof entry.name === "string") {
|
|
433
|
+
const e = entry;
|
|
434
|
+
calls.push({
|
|
435
|
+
name: e.name,
|
|
436
|
+
arguments: asArgsObject(e.arguments)
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
return calls.length > 0 ? {
|
|
440
|
+
calls,
|
|
441
|
+
cleanedText: removeSpans$1(rawText, [[tokenIdx, arrEnd + 1]])
|
|
442
|
+
} : NO_MATCH$1(rawText);
|
|
443
|
+
};
|
|
444
|
+
/** Default {@link phiToolCallParser}. */
|
|
445
|
+
var defaultPhiToolCallParser = phiToolCallParser;
|
|
446
|
+
/** A parser that never extracts anything — disables tool-call parsing entirely. */
|
|
447
|
+
var noneToolCallParser = (rawText) => NO_MATCH$1(rawText);
|
|
448
|
+
/** Default {@link noneToolCallParser}. */
|
|
449
|
+
var defaultNoneToolCallParser = noneToolCallParser;
|
|
450
|
+
/** The bundled family parsers keyed by name (excluding `'auto'`/`'none'`). */
|
|
451
|
+
var BUNDLED_TOOL_CALL_PARSERS = {
|
|
452
|
+
hermes: hermesToolCallParser,
|
|
453
|
+
gemma: gemmaToolCallParser,
|
|
454
|
+
gpt_oss: gptOssToolCallParser,
|
|
455
|
+
pythonic: pythonicToolCallParser,
|
|
456
|
+
llama3_json: llama3JsonToolCallParser,
|
|
457
|
+
mistral: mistralToolCallParser,
|
|
458
|
+
qwen3_coder: qwen3CoderToolCallParser,
|
|
459
|
+
phi: phiToolCallParser
|
|
460
|
+
};
|
|
461
|
+
/**
|
|
462
|
+
* The default `'auto'` precedence. Marker-anchored families first (collision-free); the weak-signal
|
|
463
|
+
* pythonic/llama3_json forms run last and are gated on callee∈toolNames.
|
|
464
|
+
*/
|
|
465
|
+
var DEFAULT_TOOL_CALL_PARSER_ORDER = [
|
|
466
|
+
"hermes",
|
|
467
|
+
"gemma",
|
|
468
|
+
"gpt_oss",
|
|
469
|
+
"phi",
|
|
470
|
+
"pythonic",
|
|
471
|
+
"llama3_json",
|
|
472
|
+
"mistral",
|
|
473
|
+
"qwen3_coder"
|
|
474
|
+
];
|
|
475
|
+
/**
|
|
476
|
+
* Compose an `'auto'` parser: run each family parser in `order` until one returns a non-empty
|
|
477
|
+
* `calls` array; that result wins. Returns no-match if none claim the text.
|
|
478
|
+
*/
|
|
479
|
+
var createAutoToolCallParser = (parsers = BUNDLED_TOOL_CALL_PARSERS, order = DEFAULT_TOOL_CALL_PARSER_ORDER) => {
|
|
480
|
+
return (rawText, ctx) => {
|
|
481
|
+
for (const name of order) {
|
|
482
|
+
const parser = parsers[name];
|
|
483
|
+
if (!parser) continue;
|
|
484
|
+
const result = parser(rawText, ctx);
|
|
485
|
+
if (result.calls.length > 0) return result;
|
|
486
|
+
}
|
|
487
|
+
return NO_MATCH$1(rawText);
|
|
488
|
+
};
|
|
489
|
+
};
|
|
490
|
+
/** Default {@link createAutoToolCallParser}. */
|
|
491
|
+
var defaultCreateAutoToolCallParser = createAutoToolCallParser;
|
|
492
|
+
/**
|
|
493
|
+
* Resolve a `toolCallParser` option (a name, `'auto'`, `'none'`, or a custom fn) to a concrete
|
|
494
|
+
* {@link ToolCallParserFn}.
|
|
495
|
+
*
|
|
496
|
+
* @param option - The option value. Defaults to `'auto'` when undefined.
|
|
497
|
+
* @param parsers - Override the bundled family parsers (e.g. swap the Gemma parser).
|
|
498
|
+
*/
|
|
499
|
+
var resolveToolCallParser = (option, parsers = BUNDLED_TOOL_CALL_PARSERS) => {
|
|
500
|
+
if (typeof option === "function") return option;
|
|
501
|
+
if (option === void 0 || option === "auto") return createAutoToolCallParser(parsers);
|
|
502
|
+
if (option === "none") return noneToolCallParser;
|
|
503
|
+
return parsers[option] ?? BUNDLED_TOOL_CALL_PARSERS[option] ?? noneToolCallParser;
|
|
504
|
+
};
|
|
505
|
+
/** Default {@link resolveToolCallParser}. */
|
|
506
|
+
var defaultResolveToolCallParser = resolveToolCallParser;
|
|
507
|
+
//#endregion
|
|
508
|
+
//#region src/batteries/llm/chat_common/generation.ts
|
|
509
|
+
/** Deterministic-friendly defaults, identical across batteries. */
|
|
510
|
+
var GENERATION_DEFAULTS = {
|
|
511
|
+
maxTokens: 1024,
|
|
512
|
+
sampler: "greedy",
|
|
513
|
+
temperature: .7,
|
|
514
|
+
topK: 40,
|
|
515
|
+
topP: .95,
|
|
516
|
+
enableThinking: false,
|
|
517
|
+
multimodal: {
|
|
518
|
+
image: false,
|
|
519
|
+
audio: false
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
/** Pick the first defined value (canonical-wins precedence is encoded by argument order at call sites). */
|
|
523
|
+
var firstDefined = (...values) => {
|
|
524
|
+
for (const v of values) if (v !== void 0) return v;
|
|
525
|
+
};
|
|
526
|
+
/**
|
|
527
|
+
* Resolve the canonical {@link ChatGenerationOptions} (already merged across option layers) into a
|
|
528
|
+
* fully-defaulted {@link ResolvedGenerationOptions}. Native per-battery fallbacks are passed via
|
|
529
|
+
* `nativeFallbacks` and consulted ONLY when the canonical field is absent (canonical wins). The adapter
|
|
530
|
+
* then maps the resolved shape onto its runtime API.
|
|
531
|
+
*
|
|
532
|
+
* @param canonical - The canonical fields from the merged adapter options.
|
|
533
|
+
* @param nativeFallbacks - Battery-native equivalents to fall back to when a canonical field is unset
|
|
534
|
+
* (e.g. transformers.js `maxNewTokens`, LiteRT `maxOutputTokens`). Each is consulted second.
|
|
535
|
+
*/
|
|
536
|
+
var resolveGenerationOptions = (canonical, nativeFallbacks = {}) => {
|
|
537
|
+
const mm = firstDefined(canonical.multimodal, nativeFallbacks.multimodal) ?? {};
|
|
538
|
+
return {
|
|
539
|
+
maxTokens: firstDefined(canonical.maxTokens, nativeFallbacks.maxTokens) ?? GENERATION_DEFAULTS.maxTokens,
|
|
540
|
+
sampler: firstDefined(canonical.sampler, nativeFallbacks.sampler) ?? GENERATION_DEFAULTS.sampler,
|
|
541
|
+
temperature: firstDefined(canonical.temperature, nativeFallbacks.temperature) ?? GENERATION_DEFAULTS.temperature,
|
|
542
|
+
topK: firstDefined(canonical.topK, nativeFallbacks.topK) ?? GENERATION_DEFAULTS.topK,
|
|
543
|
+
topP: firstDefined(canonical.topP, nativeFallbacks.topP) ?? GENERATION_DEFAULTS.topP,
|
|
544
|
+
seed: firstDefined(canonical.seed, nativeFallbacks.seed),
|
|
545
|
+
enableThinking: firstDefined(canonical.enableThinking, nativeFallbacks.enableThinking) ?? GENERATION_DEFAULTS.enableThinking,
|
|
546
|
+
multimodal: {
|
|
547
|
+
image: mm.image ?? GENERATION_DEFAULTS.multimodal.image,
|
|
548
|
+
audio: mm.audio ?? GENERATION_DEFAULTS.multimodal.audio
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
};
|
|
552
|
+
/** Default {@link resolveGenerationOptions}. */
|
|
553
|
+
var defaultResolveGenerationOptions = resolveGenerationOptions;
|
|
554
|
+
//#endregion
|
|
555
|
+
//#region src/batteries/llm/chat_common/reasoning_parsers.ts
|
|
556
|
+
var NO_MATCH = (rawText) => ({
|
|
557
|
+
reasoning: [],
|
|
558
|
+
cleanedText: rawText
|
|
559
|
+
});
|
|
560
|
+
var removeSpans = (text, spans) => {
|
|
561
|
+
let out = text;
|
|
562
|
+
for (const [start, end] of [...spans].sort((a, b) => b[0] - a[0])) out = out.slice(0, start) + out.slice(end);
|
|
563
|
+
return out.replace(/\n{3,}/g, "\n\n").trim();
|
|
564
|
+
};
|
|
565
|
+
/**
|
|
566
|
+
* Collect reasoning spans, recovering UNPAIRED markers by inferring the missing half from the
|
|
567
|
+
* pseudo-streaming order (see {@link ReasoningParserOptions}). Algorithm, in precedence:
|
|
568
|
+
*
|
|
569
|
+
* 1. **Paired** spans first — each OPEN whose following text contains a CLOSE forms a complete span
|
|
570
|
+
* `[openStart, closeEnd]`; the trace is the text between. (Unchanged from the strict path.)
|
|
571
|
+
* 2. **Lone closes** — in the text NOT covered by a pair, scan left-to-right for CLOSE markers that
|
|
572
|
+
* have no preceding OPEN. Each spans `[cursor, closeEnd]` where `cursor` starts at start-of-text and
|
|
573
|
+
* advances to each consumed close, so `A </c> B </c> C` → traces `A`, `B` and answer `C` (the second
|
|
574
|
+
* orphan-close opens at the first close, not back at 0).
|
|
575
|
+
* 3. **Lone open** — a final OPEN with no following CLOSE spans `[openStart, end-of-text]` (truncated
|
|
576
|
+
* stream).
|
|
577
|
+
*
|
|
578
|
+
* When `orphanRecovery` is false this collapses to strict paired-only behaviour (identical to the old
|
|
579
|
+
* `collect`). Returns NO_MATCH only when nothing — no pair, no orphan — was found.
|
|
580
|
+
*/
|
|
581
|
+
var collectWithOrphans = (rawText, markers, orphanRecovery) => {
|
|
582
|
+
const { openRe, close } = markers;
|
|
583
|
+
const reasoning = [];
|
|
584
|
+
const spans = [];
|
|
585
|
+
openRe.lastIndex = 0;
|
|
586
|
+
let cursor = 0;
|
|
587
|
+
while (cursor <= rawText.length) {
|
|
588
|
+
openRe.lastIndex = cursor;
|
|
589
|
+
const openMatch = openRe.exec(rawText);
|
|
590
|
+
const openStart = openMatch ? openMatch.index : -1;
|
|
591
|
+
const openEnd = openMatch ? openMatch.index + openMatch[0].length : -1;
|
|
592
|
+
const closeStart = rawText.indexOf(close, cursor);
|
|
593
|
+
if (closeStart !== -1 && (openStart === -1 || closeStart < openStart)) {
|
|
594
|
+
if (!orphanRecovery) {
|
|
595
|
+
cursor = closeStart + close.length;
|
|
596
|
+
continue;
|
|
597
|
+
}
|
|
598
|
+
const trace = rawText.slice(cursor, closeStart).trim();
|
|
599
|
+
if (trace.length > 0) reasoning.push(trace);
|
|
600
|
+
spans.push([cursor, closeStart + close.length]);
|
|
601
|
+
cursor = closeStart + close.length;
|
|
602
|
+
continue;
|
|
603
|
+
}
|
|
604
|
+
if (openStart !== -1) {
|
|
605
|
+
const pairedClose = rawText.indexOf(close, openEnd);
|
|
606
|
+
if (pairedClose !== -1) {
|
|
607
|
+
const trace = rawText.slice(openEnd, pairedClose).trim();
|
|
608
|
+
if (trace.length > 0) reasoning.push(trace);
|
|
609
|
+
spans.push([openStart, pairedClose + close.length]);
|
|
610
|
+
cursor = pairedClose + close.length;
|
|
611
|
+
continue;
|
|
612
|
+
}
|
|
613
|
+
if (!orphanRecovery) break;
|
|
614
|
+
const trace = rawText.slice(openEnd).trim();
|
|
615
|
+
if (trace.length > 0) reasoning.push(trace);
|
|
616
|
+
spans.push([openStart, rawText.length]);
|
|
617
|
+
break;
|
|
618
|
+
}
|
|
619
|
+
break;
|
|
620
|
+
}
|
|
621
|
+
return spans.length > 0 ? {
|
|
622
|
+
reasoning,
|
|
623
|
+
cleanedText: removeSpans(rawText, spans)
|
|
624
|
+
} : NO_MATCH(rawText);
|
|
625
|
+
};
|
|
626
|
+
var THINK_OPEN_RE = /<think>/g;
|
|
627
|
+
var THINKING_OPEN_RE = /<thinking>/g;
|
|
628
|
+
/**
|
|
629
|
+
* Parse `<think>…</think>` (and the `<thinking>…</thinking>` variant) reasoning blocks — the dominant
|
|
630
|
+
* convention, used by Qwen3, DeepSeek-R1, and most distilled reasoning models. Unpaired markers (a lone
|
|
631
|
+
* `</think>` or a truncated `<think>`) are recovered by default — see {@link ReasoningParserOptions}.
|
|
632
|
+
*/
|
|
633
|
+
var makeThinkTagReasoningParser = (opts = {}) => (rawText) => {
|
|
634
|
+
const orphan = opts.orphanRecovery ?? true;
|
|
635
|
+
const first = collectWithOrphans(rawText, {
|
|
636
|
+
openRe: THINK_OPEN_RE,
|
|
637
|
+
close: "</think>"
|
|
638
|
+
}, orphan);
|
|
639
|
+
const second = collectWithOrphans(first.cleanedText, {
|
|
640
|
+
openRe: THINKING_OPEN_RE,
|
|
641
|
+
close: "</thinking>"
|
|
642
|
+
}, orphan);
|
|
643
|
+
const reasoning = [...first.reasoning, ...second.reasoning];
|
|
644
|
+
return reasoning.length > 0 || second.cleanedText !== rawText ? {
|
|
645
|
+
reasoning,
|
|
646
|
+
cleanedText: second.cleanedText
|
|
647
|
+
} : NO_MATCH(rawText);
|
|
648
|
+
};
|
|
649
|
+
/** Default {@link makeThinkTagReasoningParser} (orphan recovery on). */
|
|
650
|
+
var thinkTagReasoningParser = makeThinkTagReasoningParser();
|
|
651
|
+
/** Default {@link thinkTagReasoningParser}. */
|
|
652
|
+
var defaultThinkTagReasoningParser = thinkTagReasoningParser;
|
|
653
|
+
var HARMONY_OPEN_RE = /<\|channel\|>analysis\s*<\|message\|>/g;
|
|
654
|
+
/**
|
|
655
|
+
* Parse gpt-oss Harmony chain-of-thought on the `analysis` channel:
|
|
656
|
+
* `<|channel|>analysis<|message|>…<|end|>`. (The user-visible answer is the separate `final` channel;
|
|
657
|
+
* tool calls are `commentary` — handled by the tool-call parser.) Unpaired markers are recovered by
|
|
658
|
+
* default — see {@link ReasoningParserOptions}.
|
|
659
|
+
*/
|
|
660
|
+
var makeHarmonyAnalysisReasoningParser = (opts = {}) => (rawText) => collectWithOrphans(rawText, {
|
|
661
|
+
openRe: HARMONY_OPEN_RE,
|
|
662
|
+
close: "<|end|>"
|
|
663
|
+
}, opts.orphanRecovery ?? true);
|
|
664
|
+
/** Default {@link makeHarmonyAnalysisReasoningParser} (orphan recovery on). */
|
|
665
|
+
var harmonyAnalysisReasoningParser = makeHarmonyAnalysisReasoningParser();
|
|
666
|
+
/** Default {@link harmonyAnalysisReasoningParser}. */
|
|
667
|
+
var defaultHarmonyAnalysisReasoningParser = harmonyAnalysisReasoningParser;
|
|
668
|
+
var GEMMA_OPEN_RE = /<\|channel>thought\b[^\n]*\n?/g;
|
|
669
|
+
/**
|
|
670
|
+
* Parse Gemma E2B/E4B reasoning emitted on the thought channel:
|
|
671
|
+
* `<|channel>thought\n…<channel|>`. Targets the E2B/E4B delimited form (the transformers.js-runnable
|
|
672
|
+
* one). Reasoning is only emitted when `<|think|>` is injected into the system prompt. Unpaired markers
|
|
673
|
+
* are recovered by default — see {@link ReasoningParserOptions}.
|
|
674
|
+
*/
|
|
675
|
+
var makeGemmaChannelReasoningParser = (opts = {}) => (rawText) => collectWithOrphans(rawText, {
|
|
676
|
+
openRe: GEMMA_OPEN_RE,
|
|
677
|
+
close: "<channel|>"
|
|
678
|
+
}, opts.orphanRecovery ?? true);
|
|
679
|
+
/** Default {@link makeGemmaChannelReasoningParser} (orphan recovery on). */
|
|
680
|
+
var gemmaChannelReasoningParser = makeGemmaChannelReasoningParser();
|
|
681
|
+
/** Default {@link gemmaChannelReasoningParser}. */
|
|
682
|
+
var defaultGemmaChannelReasoningParser = gemmaChannelReasoningParser;
|
|
683
|
+
/** A parser that never extracts anything — disables reasoning parsing entirely. */
|
|
684
|
+
var noneReasoningParser = (rawText) => NO_MATCH(rawText);
|
|
685
|
+
/** Default {@link noneReasoningParser}. */
|
|
686
|
+
var defaultNoneReasoningParser = noneReasoningParser;
|
|
687
|
+
/** The bundled reasoning parsers keyed by name (excluding `'auto'`/`'none'`), orphan recovery ON. */
|
|
688
|
+
var BUNDLED_REASONING_PARSERS = {
|
|
689
|
+
think_tag: thinkTagReasoningParser,
|
|
690
|
+
harmony_analysis: harmonyAnalysisReasoningParser,
|
|
691
|
+
gemma_channel: gemmaChannelReasoningParser
|
|
692
|
+
};
|
|
693
|
+
/** Build the bundled family parsers honouring {@link ReasoningParserOptions} (e.g. orphan recovery). */
|
|
694
|
+
var buildBundledReasoningParsers = (opts = {}) => ({
|
|
695
|
+
think_tag: makeThinkTagReasoningParser(opts),
|
|
696
|
+
harmony_analysis: makeHarmonyAnalysisReasoningParser(opts),
|
|
697
|
+
gemma_channel: makeGemmaChannelReasoningParser(opts)
|
|
698
|
+
});
|
|
699
|
+
/** The default `'auto'` precedence. All three are literal-marker-anchored, so order is collision-free. */
|
|
700
|
+
var DEFAULT_REASONING_PARSER_ORDER = [
|
|
701
|
+
"think_tag",
|
|
702
|
+
"harmony_analysis",
|
|
703
|
+
"gemma_channel"
|
|
704
|
+
];
|
|
705
|
+
/**
|
|
706
|
+
* Compose an `'auto'` reasoning parser: run each parser in `order` until one returns a non-empty
|
|
707
|
+
* `reasoning` array; that result wins. Returns no-match if none claim the text.
|
|
708
|
+
*/
|
|
709
|
+
var createAutoReasoningParser = (parsers = BUNDLED_REASONING_PARSERS, order = DEFAULT_REASONING_PARSER_ORDER) => {
|
|
710
|
+
return (rawText) => {
|
|
711
|
+
for (const name of order) {
|
|
712
|
+
const parser = parsers[name];
|
|
713
|
+
if (!parser) continue;
|
|
714
|
+
const result = parser(rawText);
|
|
715
|
+
if (result.reasoning.length > 0 || result.cleanedText !== rawText) return result;
|
|
716
|
+
}
|
|
717
|
+
return NO_MATCH(rawText);
|
|
718
|
+
};
|
|
719
|
+
};
|
|
720
|
+
/** Default {@link createAutoReasoningParser}. */
|
|
721
|
+
var defaultCreateAutoReasoningParser = createAutoReasoningParser;
|
|
722
|
+
/**
|
|
723
|
+
* Resolve a `reasoningParser` option (a name, `'auto'`, `'none'`, or a custom fn) to a concrete
|
|
724
|
+
* {@link ReasoningParserFn}.
|
|
725
|
+
*
|
|
726
|
+
* @param option - The option value. Defaults to `'auto'` when undefined.
|
|
727
|
+
* @param parsers - Override the bundled parsers. Ignored when `opts.orphanRecovery` is set (the bundled
|
|
728
|
+
* family parsers are rebuilt with that setting); pass a custom `option` fn for full control.
|
|
729
|
+
* @param opts - {@link ReasoningParserOptions}; `orphanRecovery` defaults to `true`. When `false`, the
|
|
730
|
+
* named/auto bundled parsers are rebuilt in strict pair-only mode.
|
|
731
|
+
*/
|
|
732
|
+
var resolveReasoningParser = (option, parsers = BUNDLED_REASONING_PARSERS, opts = {}) => {
|
|
733
|
+
if (typeof option === "function") return option;
|
|
734
|
+
if (option === "none") return noneReasoningParser;
|
|
735
|
+
const resolved = opts.orphanRecovery === false ? buildBundledReasoningParsers(opts) : {
|
|
736
|
+
...BUNDLED_REASONING_PARSERS,
|
|
737
|
+
...parsers
|
|
738
|
+
};
|
|
739
|
+
if (option === void 0 || option === "auto") return createAutoReasoningParser(resolved);
|
|
740
|
+
return resolved[option] ?? noneReasoningParser;
|
|
741
|
+
};
|
|
742
|
+
/** Default {@link resolveReasoningParser}. */
|
|
743
|
+
var defaultResolveReasoningParser = resolveReasoningParser;
|
|
744
|
+
//#endregion
|
|
745
|
+
export { defaultMistralToolCallParser as A, mistralToolCallParser as B, DEFAULT_TOOL_CALL_PARSER_ORDER as C, defaultGptOssToolCallParser as D, defaultGemmaToolCallParser as E, defaultResolveToolCallParser as F, resolveToolCallParser as G, phiToolCallParser as H, gemmaToolCallParser as I, gptOssToolCallParser as L, defaultPhiToolCallParser as M, defaultPythonicToolCallParser as N, defaultHermesToolCallParser as O, defaultQwen3CoderToolCallParser as P, hermesToolCallParser as R, BUNDLED_TOOL_CALL_PARSERS as S, defaultCreateAutoToolCallParser as T, pythonicToolCallParser as U, noneToolCallParser as V, qwen3CoderToolCallParser as W, resolveReasoningParser as _, defaultCreateAutoReasoningParser as a, defaultResolveGenerationOptions as b, defaultNoneReasoningParser as c, gemmaChannelReasoningParser as d, harmonyAnalysisReasoningParser as f, noneReasoningParser as g, makeThinkTagReasoningParser as h, createAutoReasoningParser as i, defaultNoneToolCallParser as j, defaultLlama3JsonToolCallParser as k, defaultResolveReasoningParser as l, makeHarmonyAnalysisReasoningParser as m, DEFAULT_REASONING_PARSER_ORDER as n, defaultGemmaChannelReasoningParser as o, makeGemmaChannelReasoningParser as p, buildBundledReasoningParsers as r, defaultHarmonyAnalysisReasoningParser as s, BUNDLED_REASONING_PARSERS as t, defaultThinkTagReasoningParser as u, thinkTagReasoningParser as v, createAutoToolCallParser as w, resolveGenerationOptions as x, GENERATION_DEFAULTS as y, llama3JsonToolCallParser as z };
|
|
746
|
+
|
|
747
|
+
//# sourceMappingURL=reasoning_parsers-Dp66LFBt.mjs.map
|