@nhtio/adk 1.20260607.2 → 1.20260609.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 +185 -0
- package/batteries/embeddings/openai/adapter.cjs +1 -1
- package/batteries/embeddings/openai/adapter.mjs +1 -1
- package/batteries/embeddings/openai/exceptions.cjs +1 -1
- package/batteries/embeddings/openai/exceptions.mjs +1 -1
- package/batteries/embeddings/openai/types.d.ts +7 -0
- package/batteries/embeddings/webllm/adapter.cjs +1 -1
- package/batteries/embeddings/webllm/adapter.mjs +1 -1
- package/batteries/embeddings/webllm/exceptions.cjs +1 -1
- package/batteries/embeddings/webllm/exceptions.mjs +1 -1
- package/batteries/llm/chat_common/helpers.d.ts +165 -0
- package/batteries/llm/chat_common/types.d.ts +309 -0
- package/batteries/llm/index.d.ts +5 -0
- package/batteries/llm/ollama/adapter.cjs +736 -0
- package/batteries/llm/ollama/adapter.cjs.map +1 -0
- package/batteries/llm/ollama/adapter.d.ts +64 -0
- package/batteries/llm/ollama/adapter.mjs +734 -0
- package/batteries/llm/ollama/adapter.mjs.map +1 -0
- package/batteries/llm/ollama/exceptions.cjs +105 -0
- package/batteries/llm/ollama/exceptions.cjs.map +1 -0
- package/batteries/llm/ollama/exceptions.d.ts +112 -0
- package/batteries/llm/ollama/exceptions.mjs +96 -0
- package/batteries/llm/ollama/exceptions.mjs.map +1 -0
- package/batteries/llm/ollama/helpers.cjs +487 -0
- package/batteries/llm/ollama/helpers.cjs.map +1 -0
- package/batteries/llm/ollama/helpers.d.ts +158 -0
- package/batteries/llm/ollama/helpers.mjs +450 -0
- package/batteries/llm/ollama/helpers.mjs.map +1 -0
- package/batteries/llm/ollama/index.d.ts +29 -0
- package/batteries/llm/ollama/types.cjs +2 -0
- package/batteries/llm/ollama/types.d.ts +334 -0
- package/batteries/llm/ollama/types.mjs +0 -0
- package/batteries/llm/ollama/validation.cjs +130 -0
- package/batteries/llm/ollama/validation.cjs.map +1 -0
- package/batteries/llm/ollama/validation.d.ts +31 -0
- package/batteries/llm/ollama/validation.mjs +127 -0
- package/batteries/llm/ollama/validation.mjs.map +1 -0
- package/batteries/llm/ollama.cjs +54 -0
- package/batteries/llm/ollama.mjs +6 -0
- package/batteries/llm/openai_chat_completions/adapter.cjs +36 -19
- package/batteries/llm/openai_chat_completions/adapter.cjs.map +1 -1
- package/batteries/llm/openai_chat_completions/adapter.mjs +23 -6
- package/batteries/llm/openai_chat_completions/adapter.mjs.map +1 -1
- package/batteries/llm/openai_chat_completions/exceptions.cjs +1 -1
- package/batteries/llm/openai_chat_completions/exceptions.mjs +1 -1
- package/batteries/llm/openai_chat_completions/helpers.cjs +80 -320
- package/batteries/llm/openai_chat_completions/helpers.cjs.map +1 -1
- package/batteries/llm/openai_chat_completions/helpers.d.ts +68 -144
- package/batteries/llm/openai_chat_completions/helpers.mjs +40 -280
- package/batteries/llm/openai_chat_completions/helpers.mjs.map +1 -1
- package/batteries/llm/openai_chat_completions/types.d.ts +273 -181
- package/batteries/llm/openai_chat_completions/validation.cjs +2 -2
- package/batteries/llm/openai_chat_completions/validation.cjs.map +1 -1
- package/batteries/llm/openai_chat_completions/validation.mjs +2 -2
- package/batteries/llm/openai_chat_completions/validation.mjs.map +1 -1
- package/batteries/llm/openai_chat_completions.cjs +29 -28
- package/batteries/llm/openai_chat_completions.mjs +2 -1
- package/batteries/llm/webllm_chat_completions/adapter.cjs +38 -19
- package/batteries/llm/webllm_chat_completions/adapter.cjs.map +1 -1
- package/batteries/llm/webllm_chat_completions/adapter.d.ts +18 -0
- package/batteries/llm/webllm_chat_completions/adapter.mjs +25 -6
- package/batteries/llm/webllm_chat_completions/adapter.mjs.map +1 -1
- package/batteries/llm/webllm_chat_completions/exceptions.cjs +1 -1
- package/batteries/llm/webllm_chat_completions/exceptions.mjs +1 -1
- package/batteries/llm/webllm_chat_completions/helpers.cjs +29 -28
- package/batteries/llm/webllm_chat_completions/helpers.mjs +2 -1
- package/batteries/llm/webllm_chat_completions/types.d.ts +21 -0
- package/batteries/llm/webllm_chat_completions/validation.cjs +13 -1
- package/batteries/llm/webllm_chat_completions/validation.cjs.map +1 -1
- package/batteries/llm/webllm_chat_completions/validation.d.ts +12 -0
- package/batteries/llm/webllm_chat_completions/validation.mjs +13 -1
- package/batteries/llm/webllm_chat_completions/validation.mjs.map +1 -1
- package/batteries/llm/webllm_chat_completions.cjs +29 -28
- package/batteries/llm/webllm_chat_completions.mjs +2 -1
- package/batteries/llm.cjs +44 -28
- package/batteries/llm.mjs +9 -4
- package/batteries/storage/flydrive.cjs +1 -1
- package/batteries/storage/flydrive.mjs +1 -1
- package/batteries/storage/in_memory/index.d.ts +1 -1
- package/batteries/storage/in_memory.cjs +2 -2
- package/batteries/storage/in_memory.cjs.map +1 -1
- package/batteries/storage/in_memory.mjs +2 -2
- package/batteries/storage/in_memory.mjs.map +1 -1
- package/batteries/storage/opfs/index.d.ts +19 -0
- package/batteries/storage/opfs.cjs +1 -1
- package/batteries/storage/opfs.cjs.map +1 -1
- package/batteries/storage/opfs.mjs +1 -1
- package/batteries/storage/opfs.mjs.map +1 -1
- package/batteries/tools/color.cjs +3 -2
- package/batteries/tools/color.cjs.map +1 -1
- package/batteries/tools/color.mjs +3 -2
- package/batteries/tools/color.mjs.map +1 -1
- package/batteries/tools/comparison.cjs +4 -3
- package/batteries/tools/comparison.cjs.map +1 -1
- package/batteries/tools/comparison.mjs +4 -3
- package/batteries/tools/comparison.mjs.map +1 -1
- package/batteries/tools/data_structure.cjs +30 -10
- package/batteries/tools/data_structure.cjs.map +1 -1
- package/batteries/tools/data_structure.mjs +30 -10
- package/batteries/tools/data_structure.mjs.map +1 -1
- package/batteries/tools/datetime_extended.cjs +5 -10
- package/batteries/tools/datetime_extended.cjs.map +1 -1
- package/batteries/tools/datetime_extended.mjs +5 -10
- package/batteries/tools/datetime_extended.mjs.map +1 -1
- package/batteries/tools/datetime_math.cjs +2 -2
- package/batteries/tools/datetime_math.mjs +2 -2
- package/batteries/tools/encoding.cjs +13 -4
- package/batteries/tools/encoding.cjs.map +1 -1
- package/batteries/tools/encoding.mjs +13 -4
- package/batteries/tools/encoding.mjs.map +1 -1
- package/batteries/tools/formatting.cjs +4 -4
- package/batteries/tools/formatting.cjs.map +1 -1
- package/batteries/tools/formatting.mjs +4 -4
- package/batteries/tools/formatting.mjs.map +1 -1
- package/batteries/tools/geo_basics.cjs +2 -2
- package/batteries/tools/geo_basics.mjs +2 -2
- package/batteries/tools/index.d.ts +1 -0
- package/batteries/tools/math.cjs +10 -8
- package/batteries/tools/math.cjs.map +1 -1
- package/batteries/tools/math.mjs +10 -8
- package/batteries/tools/math.mjs.map +1 -1
- package/batteries/tools/memory.cjs +5 -5
- package/batteries/tools/memory.mjs +5 -5
- package/batteries/tools/parsing.cjs +9 -5
- package/batteries/tools/parsing.cjs.map +1 -1
- package/batteries/tools/parsing.mjs +9 -5
- package/batteries/tools/parsing.mjs.map +1 -1
- package/batteries/tools/retrievables.cjs +4 -4
- package/batteries/tools/retrievables.mjs +4 -4
- package/batteries/tools/searxng/exceptions.d.ts +21 -0
- package/batteries/tools/searxng/index.d.ts +150 -0
- package/batteries/tools/searxng.cjs +5 -0
- package/batteries/tools/searxng.mjs +2 -0
- package/batteries/tools/standing_instructions.cjs +4 -4
- package/batteries/tools/standing_instructions.mjs +4 -4
- package/batteries/tools/statistics.cjs +54 -43
- package/batteries/tools/statistics.cjs.map +1 -1
- package/batteries/tools/statistics.mjs +54 -43
- package/batteries/tools/statistics.mjs.map +1 -1
- package/batteries/tools/string_processing.cjs +5 -5
- package/batteries/tools/string_processing.cjs.map +1 -1
- package/batteries/tools/string_processing.mjs +5 -5
- package/batteries/tools/string_processing.mjs.map +1 -1
- package/batteries/tools/structured_data.cjs +8 -13
- package/batteries/tools/structured_data.cjs.map +1 -1
- package/batteries/tools/structured_data.mjs +8 -13
- package/batteries/tools/structured_data.mjs.map +1 -1
- package/batteries/tools/text_analysis.cjs +3 -3
- package/batteries/tools/text_analysis.mjs +3 -3
- package/batteries/tools/text_comparison.cjs +2 -2
- package/batteries/tools/text_comparison.mjs +2 -2
- package/batteries/tools/time.cjs +2 -2
- package/batteries/tools/time.mjs +2 -2
- package/batteries/tools/unit_conversion.cjs +10 -8
- package/batteries/tools/unit_conversion.cjs.map +1 -1
- package/batteries/tools/unit_conversion.mjs +10 -8
- package/batteries/tools/unit_conversion.mjs.map +1 -1
- package/batteries/tools.cjs +3 -0
- package/batteries/tools.mjs +2 -1
- package/batteries/vector/arangodb/index.d.ts +2 -0
- package/batteries/vector/arangodb.cjs +2 -1
- package/batteries/vector/arangodb.cjs.map +1 -1
- package/batteries/vector/arangodb.mjs +2 -1
- package/batteries/vector/arangodb.mjs.map +1 -1
- package/batteries/vector/builder.cjs +31 -0
- package/batteries/vector/builder.cjs.map +1 -1
- package/batteries/vector/builder.d.ts +58 -0
- package/batteries/vector/builder.mjs +31 -0
- package/batteries/vector/builder.mjs.map +1 -1
- package/batteries/vector/chroma/index.d.ts +4 -0
- package/batteries/vector/chroma.cjs +3 -0
- package/batteries/vector/chroma.cjs.map +1 -1
- package/batteries/vector/chroma.mjs +3 -0
- package/batteries/vector/chroma.mjs.map +1 -1
- package/batteries/vector/clickhouse/index.d.ts +2 -0
- package/batteries/vector/clickhouse.cjs +2 -1
- package/batteries/vector/clickhouse.cjs.map +1 -1
- package/batteries/vector/clickhouse.mjs +2 -1
- package/batteries/vector/clickhouse.mjs.map +1 -1
- package/batteries/vector/cloudflare/index.d.ts +2 -0
- package/batteries/vector/cloudflare.cjs +2 -1
- package/batteries/vector/cloudflare.cjs.map +1 -1
- package/batteries/vector/cloudflare.mjs +2 -1
- package/batteries/vector/cloudflare.mjs.map +1 -1
- package/batteries/vector/conformance/index.d.ts +22 -0
- package/batteries/vector/conformance.cjs +22 -0
- package/batteries/vector/conformance.cjs.map +1 -1
- package/batteries/vector/conformance.mjs +22 -0
- package/batteries/vector/conformance.mjs.map +1 -1
- package/batteries/vector/contract.cjs +22 -0
- package/batteries/vector/contract.cjs.map +1 -1
- package/batteries/vector/contract.d.ts +51 -0
- package/batteries/vector/contract.mjs +22 -0
- package/batteries/vector/contract.mjs.map +1 -1
- package/batteries/vector/couchbase/index.d.ts +2 -0
- package/batteries/vector/couchbase.cjs +2 -1
- package/batteries/vector/couchbase.cjs.map +1 -1
- package/batteries/vector/couchbase.mjs +2 -1
- package/batteries/vector/couchbase.mjs.map +1 -1
- package/batteries/vector/duckdb/index.d.ts +2 -0
- package/batteries/vector/duckdb.cjs +2 -1
- package/batteries/vector/duckdb.cjs.map +1 -1
- package/batteries/vector/duckdb.mjs +2 -1
- package/batteries/vector/duckdb.mjs.map +1 -1
- package/batteries/vector/elasticsearch/index.d.ts +2 -0
- package/batteries/vector/elasticsearch.cjs +2 -1
- package/batteries/vector/elasticsearch.cjs.map +1 -1
- package/batteries/vector/elasticsearch.mjs +2 -1
- package/batteries/vector/elasticsearch.mjs.map +1 -1
- package/batteries/vector/exceptions.cjs +1 -1
- package/batteries/vector/exceptions.mjs +1 -1
- package/batteries/vector/factory.cjs +6 -0
- package/batteries/vector/factory.cjs.map +1 -1
- package/batteries/vector/factory.d.ts +14 -0
- package/batteries/vector/factory.mjs +6 -0
- package/batteries/vector/factory.mjs.map +1 -1
- package/batteries/vector/filters.cjs +22 -1
- package/batteries/vector/filters.cjs.map +1 -1
- package/batteries/vector/filters.d.ts +38 -0
- package/batteries/vector/filters.mjs +22 -1
- package/batteries/vector/filters.mjs.map +1 -1
- package/batteries/vector/helpers.cjs +13 -0
- package/batteries/vector/helpers.cjs.map +1 -1
- package/batteries/vector/helpers.d.ts +14 -0
- package/batteries/vector/helpers.mjs +13 -0
- package/batteries/vector/helpers.mjs.map +1 -1
- package/batteries/vector/hnswlib/index.d.ts +2 -0
- package/batteries/vector/hnswlib.cjs +2 -1
- package/batteries/vector/hnswlib.cjs.map +1 -1
- package/batteries/vector/hnswlib.mjs +2 -1
- package/batteries/vector/hnswlib.mjs.map +1 -1
- package/batteries/vector/in_memory/index.d.ts +1 -0
- package/batteries/vector/in_memory.cjs +1 -0
- package/batteries/vector/in_memory.cjs.map +1 -1
- package/batteries/vector/in_memory.mjs +1 -0
- package/batteries/vector/in_memory.mjs.map +1 -1
- package/batteries/vector/lancedb/index.d.ts +2 -0
- package/batteries/vector/lancedb.cjs +2 -1
- package/batteries/vector/lancedb.cjs.map +1 -1
- package/batteries/vector/lancedb.mjs +2 -1
- package/batteries/vector/lancedb.mjs.map +1 -1
- package/batteries/vector/mariadb/index.d.ts +2 -0
- package/batteries/vector/mariadb.cjs +2 -1
- package/batteries/vector/mariadb.cjs.map +1 -1
- package/batteries/vector/mariadb.mjs +2 -1
- package/batteries/vector/mariadb.mjs.map +1 -1
- package/batteries/vector/meilisearch/index.d.ts +2 -0
- package/batteries/vector/meilisearch.cjs +2 -1
- package/batteries/vector/meilisearch.cjs.map +1 -1
- package/batteries/vector/meilisearch.mjs +2 -1
- package/batteries/vector/meilisearch.mjs.map +1 -1
- package/batteries/vector/migrate.cjs +18 -1
- package/batteries/vector/migrate.cjs.map +1 -1
- package/batteries/vector/migrate.d.ts +31 -0
- package/batteries/vector/migrate.mjs +18 -1
- package/batteries/vector/migrate.mjs.map +1 -1
- package/batteries/vector/milvus/index.d.ts +5 -0
- package/batteries/vector/milvus.cjs +4 -0
- package/batteries/vector/milvus.cjs.map +1 -1
- package/batteries/vector/milvus.mjs +4 -0
- package/batteries/vector/milvus.mjs.map +1 -1
- package/batteries/vector/mongodb/index.d.ts +2 -0
- package/batteries/vector/mongodb.cjs +2 -1
- package/batteries/vector/mongodb.cjs.map +1 -1
- package/batteries/vector/mongodb.mjs +2 -1
- package/batteries/vector/mongodb.mjs.map +1 -1
- package/batteries/vector/neo4j/index.d.ts +2 -0
- package/batteries/vector/neo4j.cjs +2 -1
- package/batteries/vector/neo4j.cjs.map +1 -1
- package/batteries/vector/neo4j.mjs +2 -1
- package/batteries/vector/neo4j.mjs.map +1 -1
- package/batteries/vector/opensearch/index.d.ts +2 -0
- package/batteries/vector/opensearch.cjs +2 -1
- package/batteries/vector/opensearch.cjs.map +1 -1
- package/batteries/vector/opensearch.mjs +2 -1
- package/batteries/vector/opensearch.mjs.map +1 -1
- package/batteries/vector/oracle23ai/index.d.ts +2 -0
- package/batteries/vector/oracle23ai.cjs +2 -1
- package/batteries/vector/oracle23ai.cjs.map +1 -1
- package/batteries/vector/oracle23ai.mjs +2 -1
- package/batteries/vector/oracle23ai.mjs.map +1 -1
- package/batteries/vector/orama/index.d.ts +1 -0
- package/batteries/vector/orama.cjs +1 -0
- package/batteries/vector/orama.cjs.map +1 -1
- package/batteries/vector/orama.mjs +1 -0
- package/batteries/vector/orama.mjs.map +1 -1
- package/batteries/vector/pgvector/index.d.ts +9 -2
- package/batteries/vector/pgvector.cjs +4 -0
- package/batteries/vector/pgvector.cjs.map +1 -1
- package/batteries/vector/pgvector.mjs +4 -0
- package/batteries/vector/pgvector.mjs.map +1 -1
- package/batteries/vector/pinecone/index.d.ts +5 -0
- package/batteries/vector/pinecone.cjs +3 -1
- package/batteries/vector/pinecone.cjs.map +1 -1
- package/batteries/vector/pinecone.mjs +3 -1
- package/batteries/vector/pinecone.mjs.map +1 -1
- package/batteries/vector/plan.d.ts +27 -0
- package/batteries/vector/qdrant/index.d.ts +5 -0
- package/batteries/vector/qdrant.cjs +4 -0
- package/batteries/vector/qdrant.cjs.map +1 -1
- package/batteries/vector/qdrant.mjs +4 -0
- package/batteries/vector/qdrant.mjs.map +1 -1
- package/batteries/vector/redis/index.d.ts +2 -0
- package/batteries/vector/redis.cjs +2 -1
- package/batteries/vector/redis.cjs.map +1 -1
- package/batteries/vector/redis.mjs +2 -1
- package/batteries/vector/redis.mjs.map +1 -1
- package/batteries/vector/retrievable.cjs +9 -1
- package/batteries/vector/retrievable.cjs.map +1 -1
- package/batteries/vector/retrievable.mjs +9 -1
- package/batteries/vector/retrievable.mjs.map +1 -1
- package/batteries/vector/retrievable_glue.d.ts +21 -0
- package/batteries/vector/s3vectors/index.d.ts +2 -0
- package/batteries/vector/s3vectors.cjs +2 -1
- package/batteries/vector/s3vectors.cjs.map +1 -1
- package/batteries/vector/s3vectors.mjs +2 -1
- package/batteries/vector/s3vectors.mjs.map +1 -1
- package/batteries/vector/schema.cjs +28 -0
- package/batteries/vector/schema.cjs.map +1 -1
- package/batteries/vector/schema.d.ts +39 -0
- package/batteries/vector/schema.mjs +28 -0
- package/batteries/vector/schema.mjs.map +1 -1
- package/batteries/vector/solr/index.d.ts +2 -0
- package/batteries/vector/solr.cjs +2 -1
- package/batteries/vector/solr.cjs.map +1 -1
- package/batteries/vector/solr.mjs +2 -1
- package/batteries/vector/solr.mjs.map +1 -1
- package/batteries/vector/sqlite_vec/index.d.ts +6 -3
- package/batteries/vector/sqlite_vec.cjs +2 -0
- package/batteries/vector/sqlite_vec.cjs.map +1 -1
- package/batteries/vector/sqlite_vec.mjs +2 -0
- package/batteries/vector/sqlite_vec.mjs.map +1 -1
- package/batteries/vector/surrealdb/index.d.ts +2 -0
- package/batteries/vector/surrealdb.cjs +2 -1
- package/batteries/vector/surrealdb.cjs.map +1 -1
- package/batteries/vector/surrealdb.mjs +2 -1
- package/batteries/vector/surrealdb.mjs.map +1 -1
- package/batteries/vector/types.d.ts +27 -0
- package/batteries/vector/typesense/index.d.ts +2 -0
- package/batteries/vector/typesense.cjs +2 -1
- package/batteries/vector/typesense.cjs.map +1 -1
- package/batteries/vector/typesense.mjs +2 -1
- package/batteries/vector/typesense.mjs.map +1 -1
- package/batteries/vector/validation.cjs +14 -0
- package/batteries/vector/validation.cjs.map +1 -1
- package/batteries/vector/validation.d.ts +14 -0
- package/batteries/vector/validation.mjs +14 -0
- package/batteries/vector/validation.mjs.map +1 -1
- package/batteries/vector/vector_store_constructor.cjs +1 -1
- package/batteries/vector/vector_store_constructor.cjs.map +1 -1
- package/batteries/vector/vector_store_constructor.d.ts +1 -1
- package/batteries/vector/vector_store_constructor.mjs +1 -1
- package/batteries/vector/vector_store_constructor.mjs.map +1 -1
- package/batteries/vector/vespa/index.d.ts +2 -0
- package/batteries/vector/vespa.cjs +2 -1
- package/batteries/vector/vespa.cjs.map +1 -1
- package/batteries/vector/vespa.mjs +2 -1
- package/batteries/vector/vespa.mjs.map +1 -1
- package/batteries/vector/weaviate/index.d.ts +2 -0
- package/batteries/vector/weaviate.cjs +2 -1
- package/batteries/vector/weaviate.cjs.map +1 -1
- package/batteries/vector/weaviate.mjs +2 -1
- package/batteries/vector/weaviate.mjs.map +1 -1
- package/batteries.cjs +46 -28
- package/batteries.mjs +10 -5
- package/{common-BT0nfCi9.mjs → common-DYDUi99O.mjs} +9 -9
- package/common-DYDUi99O.mjs.map +1 -0
- package/{common-Cj8TaQ9U.js → common-DZl3ADJs.js} +9 -9
- package/common-DZl3ADJs.js.map +1 -0
- package/common.cjs +7 -7
- package/common.d.ts +1 -1
- package/common.mjs +7 -7
- package/{dispatch_runner-DPcS7Y_M.mjs → dispatch_runner--ZhdDWRZ.mjs} +27 -5
- package/{dispatch_runner-DPcS7Y_M.mjs.map → dispatch_runner--ZhdDWRZ.mjs.map} +1 -1
- package/{dispatch_runner-BHBNupqp.js → dispatch_runner-nHDKkxye.js} +27 -5
- package/{dispatch_runner-BHBNupqp.js.map → dispatch_runner-nHDKkxye.js.map} +1 -1
- package/dispatch_runner.cjs +1 -1
- package/dispatch_runner.d.ts +1 -1
- package/dispatch_runner.mjs +1 -1
- package/eslint/rules/artifact_tool_forbids_artifact_constructor.cjs +1 -0
- package/eslint/rules/artifact_tool_forbids_artifact_constructor.cjs.map +1 -1
- package/eslint/rules/artifact_tool_forbids_artifact_constructor.d.ts +1 -0
- package/eslint/rules/artifact_tool_forbids_artifact_constructor.mjs +1 -0
- package/eslint/rules/artifact_tool_forbids_artifact_constructor.mjs.map +1 -1
- package/eslint/rules/no_model_in_tool_handler.cjs +1 -0
- package/eslint/rules/no_model_in_tool_handler.cjs.map +1 -1
- package/eslint/rules/no_model_in_tool_handler.d.ts +1 -0
- package/eslint/rules/no_model_in_tool_handler.mjs +1 -0
- package/eslint/rules/no_model_in_tool_handler.mjs.map +1 -1
- package/eslint/rules/require_validator_any_required.cjs +1 -0
- package/eslint/rules/require_validator_any_required.cjs.map +1 -1
- package/eslint/rules/require_validator_any_required.d.ts +1 -0
- package/eslint/rules/require_validator_any_required.mjs +1 -0
- package/eslint/rules/require_validator_any_required.mjs.map +1 -1
- package/eslint/rules/thought_payload_requires_replay_tag.cjs +1 -0
- package/eslint/rules/thought_payload_requires_replay_tag.cjs.map +1 -1
- package/eslint/rules/thought_payload_requires_replay_tag.d.ts +1 -0
- package/eslint/rules/thought_payload_requires_replay_tag.mjs +1 -0
- package/eslint/rules/thought_payload_requires_replay_tag.mjs.map +1 -1
- package/eslint/rules/token_encoding_requires_context_window.cjs +1 -0
- package/eslint/rules/token_encoding_requires_context_window.cjs.map +1 -1
- package/eslint/rules/token_encoding_requires_context_window.d.ts +1 -0
- package/eslint/rules/token_encoding_requires_context_window.mjs +1 -0
- package/eslint/rules/token_encoding_requires_context_window.mjs.map +1 -1
- package/eslint.cjs +1 -1
- package/eslint.mjs +1 -1
- package/{exceptions-BeWH2FwP.mjs → exceptions-BDhN0Xzr.mjs} +3 -2
- package/exceptions-BDhN0Xzr.mjs.map +1 -0
- package/{exceptions-CitH5wZI.js → exceptions-BRXrUKiW.js} +3 -2
- package/exceptions-BRXrUKiW.js.map +1 -0
- package/exceptions.cjs +2 -2
- package/exceptions.mjs +2 -2
- package/factories.cjs +1 -1
- package/factories.mjs +1 -1
- package/forge.cjs +4 -4
- package/forge.d.ts +1 -1
- package/forge.mjs +4 -4
- package/guards.cjs +9 -9
- package/guards.mjs +9 -9
- package/helpers-DSTFxTiC.js +497 -0
- package/helpers-DSTFxTiC.js.map +1 -0
- package/helpers-xhrQbMAG.mjs +306 -0
- package/helpers-xhrQbMAG.mjs.map +1 -0
- package/index.cjs +13 -13
- package/index.mjs +13 -13
- package/lib/classes/base_exception.d.ts +1 -0
- package/lib/classes/media.d.ts +10 -0
- package/lib/classes/retrievable.d.ts +1 -1
- package/lib/classes/spooled_json_artifact.d.ts +1 -1
- package/lib/classes/spooled_markdown_artifact.d.ts +1 -0
- package/lib/classes/tokenizable.d.ts +3 -0
- package/lib/classes/tool.d.ts +8 -0
- package/lib/classes/turn_gate.d.ts +6 -0
- package/lib/dispatch_runner.d.ts +4 -32
- package/lib/helpers/bignum.cjs +82 -0
- package/lib/helpers/bignum.cjs.map +1 -0
- package/lib/helpers/bignum.d.ts +52 -0
- package/lib/helpers/bignum.mjs +74 -0
- package/lib/helpers/bignum.mjs.map +1 -0
- package/lib/turn_runner.d.ts +1 -1
- package/lib/types/dispatch_runner.d.ts +83 -0
- package/lib/utils/exceptions.d.ts +1 -1
- package/lib/utils/retry.cjs.map +1 -1
- package/lib/utils/retry.d.ts +2 -0
- package/lib/utils/retry.mjs.map +1 -1
- package/mcp/adk-docs-corpus.json +1 -1
- package/package.json +264 -224
- package/{runtime-j92CNi5z.mjs → runtime-Bz5zA8wc.mjs} +2 -2
- package/{runtime-j92CNi5z.mjs.map → runtime-Bz5zA8wc.mjs.map} +1 -1
- package/{runtime-MFFcJrRv.js → runtime-DslE1aBw.js} +2 -2
- package/{runtime-MFFcJrRv.js.map → runtime-DslE1aBw.js.map} +1 -1
- package/searxng-Bkrwhwhw.js +269 -0
- package/searxng-Bkrwhwhw.js.map +1 -0
- package/searxng-CyA-nEu5.mjs +257 -0
- package/searxng-CyA-nEu5.mjs.map +1 -0
- package/skills/adk-assembly/SKILL.md +2 -2
- package/{spooled_artifact-CHoZgWwI.mjs → spooled_artifact-7eePq7JA.mjs} +5 -5
- package/{spooled_artifact-CHoZgWwI.mjs.map → spooled_artifact-7eePq7JA.mjs.map} +1 -1
- package/{spooled_artifact-BTq6Nzfy.js → spooled_artifact-DX8LLyUX.js} +5 -5
- package/{spooled_artifact-BTq6Nzfy.js.map → spooled_artifact-DX8LLyUX.js.map} +1 -1
- package/spooled_artifact.cjs +2 -2
- package/spooled_artifact.mjs +2 -2
- package/{spooled_markdown_artifact-CALSDxIx.js → spooled_markdown_artifact-ClX72lek.js} +4 -4
- package/spooled_markdown_artifact-ClX72lek.js.map +1 -0
- package/{spooled_markdown_artifact-Ci5UL7l4.mjs → spooled_markdown_artifact-wkrBF3oX.mjs} +4 -4
- package/spooled_markdown_artifact-wkrBF3oX.mjs.map +1 -0
- package/{thought-D34QQZZ9.mjs → thought-B_vxAiKU.mjs} +5 -5
- package/{thought-D34QQZZ9.mjs.map → thought-B_vxAiKU.mjs.map} +1 -1
- package/{thought-BbwhJ1wb.js → thought-DLwpF7MI.js} +5 -5
- package/{thought-BbwhJ1wb.js.map → thought-DLwpF7MI.js.map} +1 -1
- package/{tool-CVyZkFC7.js → tool-D5WGVIcI.js} +4 -4
- package/{tool-CVyZkFC7.js.map → tool-D5WGVIcI.js.map} +1 -1
- package/{tool-CMhaDRNd.mjs → tool-wMYMVl60.mjs} +4 -4
- package/{tool-CMhaDRNd.mjs.map → tool-wMYMVl60.mjs.map} +1 -1
- package/{tool_call-CV5qVNlb.mjs → tool_call-B4-_-vjG.mjs} +5 -5
- package/tool_call-B4-_-vjG.mjs.map +1 -0
- package/{tool_call-Db68hB7y.js → tool_call-DixVlW40.js} +5 -5
- package/tool_call-DixVlW40.js.map +1 -0
- package/{tool_registry-D1pSSlsd.mjs → tool_registry-791Vrjtf.mjs} +4 -3
- package/tool_registry-791Vrjtf.mjs.map +1 -0
- package/{tool_registry-DYUYqXvo.js → tool_registry-CKJPze3j.js} +4 -3
- package/tool_registry-CKJPze3j.js.map +1 -0
- package/{turn_runner-DqWHNP80.js → turn_runner-HXImLGIn.js} +7 -7
- package/turn_runner-HXImLGIn.js.map +1 -0
- package/{turn_runner-fg1Wc3dK.mjs → turn_runner-ZyYO-Kti.mjs} +7 -7
- package/turn_runner-ZyYO-Kti.mjs.map +1 -0
- package/turn_runner.cjs +1 -1
- package/turn_runner.mjs +1 -1
- package/types.d.ts +1 -1
- package/common-BT0nfCi9.mjs.map +0 -1
- package/common-Cj8TaQ9U.js.map +0 -1
- package/exceptions-BeWH2FwP.mjs.map +0 -1
- package/exceptions-CitH5wZI.js.map +0 -1
- package/spooled_markdown_artifact-CALSDxIx.js.map +0 -1
- package/spooled_markdown_artifact-Ci5UL7l4.mjs.map +0 -1
- package/tool_call-CV5qVNlb.mjs.map +0 -1
- package/tool_call-Db68hB7y.js.map +0 -1
- package/tool_registry-D1pSSlsd.mjs.map +0 -1
- package/tool_registry-DYUYqXvo.js.map +0 -1
- package/turn_runner-DqWHNP80.js.map +0 -1
- package/turn_runner-fg1Wc3dK.mjs.map +0 -1
|
@@ -0,0 +1,736 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../../../chunk-Ble4zEEl.js");
|
|
3
|
+
const require_tool_registry = require("../../../tool_registry-CKJPze3j.js");
|
|
4
|
+
const require_thought = require("../../../thought-DLwpF7MI.js");
|
|
5
|
+
const require_spooled_artifact = require("../../../spooled_artifact-DX8LLyUX.js");
|
|
6
|
+
require("../../../common-DZl3ADJs.js");
|
|
7
|
+
const require_tool_call = require("../../../tool_call-DixVlW40.js");
|
|
8
|
+
require("../../../guards.cjs");
|
|
9
|
+
const require_lib_utils_retry = require("../../../lib/utils/retry.cjs");
|
|
10
|
+
const require_batteries_storage_in_memory = require("../../storage/in_memory.cjs");
|
|
11
|
+
const require_helpers = require("../../../helpers-DSTFxTiC.js");
|
|
12
|
+
const require_batteries_llm_ollama_exceptions = require("./exceptions.cjs");
|
|
13
|
+
const require_batteries_llm_ollama_validation = require("./validation.cjs");
|
|
14
|
+
const require_batteries_llm_ollama_helpers = require("./helpers.cjs");
|
|
15
|
+
let luxon = require("luxon");
|
|
16
|
+
let js_sha256 = require("js-sha256");
|
|
17
|
+
let uuid = require("uuid");
|
|
18
|
+
//#region src/batteries/llm/ollama/adapter.ts
|
|
19
|
+
/**
|
|
20
|
+
* Cross-environment executor adapter for the native Ollama `/api/chat` endpoint.
|
|
21
|
+
*
|
|
22
|
+
* @module @nhtio/adk/batteries/llm/ollama/adapter
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* Native Ollama LLM adapter targeting `/api/chat` (NOT the OpenAI-compat `/v1` layer — the
|
|
26
|
+
* `openai_chat_completions` battery already covers `/v1`). Works against both LOCAL Ollama
|
|
27
|
+
* (`http://localhost:11434`, no auth) and CLOUD Ollama (`https://ollama.com`, `Authorization:
|
|
28
|
+
* Bearer <apiKey>`); the only difference is `baseURL` + the auth header. Native is HTTP-only — a
|
|
29
|
+
* Unix-socket deployment is reached via a custom `fetch` or an external bridge, not an adapter
|
|
30
|
+
* option.
|
|
31
|
+
*
|
|
32
|
+
* Structurally a sibling of the OpenAI Chat Completions adapter, with the native-wire divergences:
|
|
33
|
+
*
|
|
34
|
+
* - Request body: generation params are NESTED under `options`; `think` / `format` / `keep_alive`
|
|
35
|
+
* are top-level native controls; ADK control fields are stripped before sending.
|
|
36
|
+
* - Streaming: NDJSON (newline-delimited JSON objects), terminated in-band by `done: true` — there
|
|
37
|
+
* is no SSE `data:` framing and no `[DONE]` sentinel. Whole `tool_calls` arrive per chunk (no
|
|
38
|
+
* delta accumulation).
|
|
39
|
+
* - Reasoning: the single native `message.thinking` field (no multi-field precedence dance).
|
|
40
|
+
* - Tool calls: `arguments` is already a JSON OBJECT (no `JSON.parse`); native calls carry no `id`,
|
|
41
|
+
* so the adapter synthesizes one (uuidv6) for correlation / checksum / spool keying. Tool-result
|
|
42
|
+
* history messages use `tool_name` (the originating tool), not `tool_call_id`.
|
|
43
|
+
* - Generation stats: the terminal `done: true` object's token counts + nanosecond durations +
|
|
44
|
+
* `done_reason` are surfaced via `helpers.reportGenerationStats`.
|
|
45
|
+
*/
|
|
46
|
+
var mergeRecord = (layers) => {
|
|
47
|
+
let merged;
|
|
48
|
+
for (const layer of layers) {
|
|
49
|
+
if (!layer) continue;
|
|
50
|
+
merged = {
|
|
51
|
+
...merged ?? {},
|
|
52
|
+
...layer
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return merged;
|
|
56
|
+
};
|
|
57
|
+
var mergeOptions = (baseline, exec, stash) => {
|
|
58
|
+
const layers = [
|
|
59
|
+
baseline,
|
|
60
|
+
exec ?? {},
|
|
61
|
+
stash ?? {}
|
|
62
|
+
];
|
|
63
|
+
const out = {};
|
|
64
|
+
for (const layer of layers) for (const [k, v] of Object.entries(layer)) {
|
|
65
|
+
if (v === void 0) continue;
|
|
66
|
+
if (k === "headers" || k === "helpers" || k === "retry" || k === "options") continue;
|
|
67
|
+
out[k] = v;
|
|
68
|
+
}
|
|
69
|
+
const headers = mergeRecord(layers.map((l) => l.headers));
|
|
70
|
+
if (headers !== void 0) out.headers = headers;
|
|
71
|
+
const helpers = mergeRecord(layers.map((l) => l.helpers));
|
|
72
|
+
if (helpers !== void 0) out.helpers = helpers;
|
|
73
|
+
const retry = mergeRecord(layers.map((l) => l.retry));
|
|
74
|
+
if (retry !== void 0) out.retry = retry;
|
|
75
|
+
const runtime = mergeRecord(layers.map((l) => l.options));
|
|
76
|
+
if (runtime !== void 0) out.options = runtime;
|
|
77
|
+
return out;
|
|
78
|
+
};
|
|
79
|
+
var resolveHelpers = (overrides) => {
|
|
80
|
+
const src = overrides ?? {};
|
|
81
|
+
return {
|
|
82
|
+
descriptionToChatCompletionsJsonSchema: src.descriptionToChatCompletionsJsonSchema ?? require_helpers.defaultDescriptionToChatCompletionsJsonSchema,
|
|
83
|
+
renderUntrustedContent: src.renderUntrustedContent ?? require_helpers.defaultRenderUntrustedContent,
|
|
84
|
+
renderTrustedContent: src.renderTrustedContent ?? require_helpers.defaultRenderTrustedContent,
|
|
85
|
+
renderStandingInstructions: src.renderStandingInstructions ?? require_helpers.defaultRenderStandingInstructions,
|
|
86
|
+
renderMemories: src.renderMemories ?? require_helpers.defaultRenderMemories,
|
|
87
|
+
renderRetrievables: src.renderRetrievables ?? require_helpers.defaultRenderRetrievables,
|
|
88
|
+
renderRetrievableSafetyDirective: src.renderRetrievableSafetyDirective ?? require_helpers.defaultRenderRetrievableSafetyDirective,
|
|
89
|
+
renderFirstPartyRetrievables: src.renderFirstPartyRetrievables ?? require_helpers.defaultRenderFirstPartyRetrievables,
|
|
90
|
+
renderThirdPartyPublicRetrievables: src.renderThirdPartyPublicRetrievables ?? require_helpers.defaultRenderThirdPartyPublicRetrievables,
|
|
91
|
+
renderThirdPartyPrivateRetrievables: src.renderThirdPartyPrivateRetrievables ?? require_helpers.defaultRenderThirdPartyPrivateRetrievables,
|
|
92
|
+
renderThought: src.renderThought ?? require_helpers.defaultRenderThought,
|
|
93
|
+
filterThoughts: src.filterThoughts ?? require_helpers.defaultFilterThoughts,
|
|
94
|
+
toolsToChatCompletionsTools: src.toolsToChatCompletionsTools ?? require_helpers.defaultToolsToChatCompletionsTools,
|
|
95
|
+
renderChatCompletionsSystemPrompt: src.renderChatCompletionsSystemPrompt ?? require_helpers.defaultRenderChatCompletionsSystemPrompt,
|
|
96
|
+
renderOllamaTimelineMessage: src.renderOllamaTimelineMessage ?? require_batteries_llm_ollama_helpers.defaultRenderOllamaTimelineMessage,
|
|
97
|
+
renderOllamaToolCallResult: src.renderOllamaToolCallResult ?? require_batteries_llm_ollama_helpers.defaultRenderOllamaToolCallResult,
|
|
98
|
+
buildOllamaHistory: src.buildOllamaHistory ?? require_batteries_llm_ollama_helpers.defaultBuildOllamaHistory
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
var computeChecksum = (tool, args) => (0, js_sha256.sha256)(require_tool_registry.canonicalStringify({
|
|
102
|
+
tool,
|
|
103
|
+
args
|
|
104
|
+
}));
|
|
105
|
+
var nowIso = () => luxon.DateTime.now().toISO() ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
106
|
+
var estimateTokensOf = async (value, encoding) => Promise.resolve(value.estimateTokens(encoding));
|
|
107
|
+
var extractGenerationStats = (src, model) => {
|
|
108
|
+
const stats = {
|
|
109
|
+
provider: "ollama",
|
|
110
|
+
model: src.model ?? model,
|
|
111
|
+
raw: { ...src }
|
|
112
|
+
};
|
|
113
|
+
if (typeof src.prompt_eval_count === "number") stats.promptTokens = src.prompt_eval_count;
|
|
114
|
+
if (typeof src.eval_count === "number") stats.completionTokens = src.eval_count;
|
|
115
|
+
if (typeof src.prompt_eval_count === "number" && typeof src.eval_count === "number") stats.totalTokens = src.prompt_eval_count + src.eval_count;
|
|
116
|
+
if (typeof src.total_duration === "number") stats.totalDurationNs = src.total_duration;
|
|
117
|
+
if (typeof src.load_duration === "number") stats.loadDurationNs = src.load_duration;
|
|
118
|
+
if (typeof src.prompt_eval_duration === "number") stats.promptEvalDurationNs = src.prompt_eval_duration;
|
|
119
|
+
if (typeof src.eval_duration === "number") stats.evalDurationNs = src.eval_duration;
|
|
120
|
+
if (typeof src.done_reason === "string") stats.finishReason = src.done_reason;
|
|
121
|
+
return stats;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Opinionated cross-environment LLM adapter for the native Ollama `/api/chat` wire shape.
|
|
125
|
+
*
|
|
126
|
+
* @remarks
|
|
127
|
+
* Construction validates options eagerly via {@link validateOptions} and throws
|
|
128
|
+
* {@link @nhtio/adk/batteries/llm/ollama!E_INVALID_OLLAMA_OPTIONS} on failure. The returned instance is reusable: call
|
|
129
|
+
* {@link OllamaAdapter.executor} once per `DispatchRunner` configuration to obtain a
|
|
130
|
+
* {@link @nhtio/adk!DispatchExecutorFn} bound to the baseline plus optional executor-scope
|
|
131
|
+
* overrides. Per-iteration overrides live on `ctx.stash.ollama` and take highest precedence;
|
|
132
|
+
* `headers`, `helpers`, `retry`, and the nested runtime `options` merge key-by-key across all three
|
|
133
|
+
* layers, every other field is replaced wholesale at the highest layer that sets it.
|
|
134
|
+
*/
|
|
135
|
+
var OllamaAdapter = class OllamaAdapter {
|
|
136
|
+
/** Customary key for per-iteration overrides on `ctx.stash`. */
|
|
137
|
+
static STASH_KEY = "ollama";
|
|
138
|
+
#baseline;
|
|
139
|
+
/**
|
|
140
|
+
* @param options - Constructor-baseline options. Re-validated on every iteration after
|
|
141
|
+
* per-dispatch and per-iteration overrides are layered in.
|
|
142
|
+
* @throws {@link @nhtio/adk/batteries/llm/ollama!E_INVALID_OLLAMA_OPTIONS} when `options` does not satisfy `ollamaOptionsSchema`.
|
|
143
|
+
*/
|
|
144
|
+
constructor(options) {
|
|
145
|
+
this.#baseline = require_batteries_llm_ollama_validation.validateOptions(options);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Returns a {@link @nhtio/adk!DispatchExecutorFn} bound to this adapter's baseline plus optional
|
|
149
|
+
* executor-scope overrides.
|
|
150
|
+
*
|
|
151
|
+
* @param overrides - Optional executor-scope overrides. Higher precedence than the baseline,
|
|
152
|
+
* lower precedence than `ctx.stash[STASH_KEY]`.
|
|
153
|
+
*/
|
|
154
|
+
executor(overrides) {
|
|
155
|
+
const baseline = this.#baseline;
|
|
156
|
+
const adapterClass = OllamaAdapter;
|
|
157
|
+
return async (ctx, helpers) => {
|
|
158
|
+
const localWarn = (msg) => {
|
|
159
|
+
helpers.log.warn({
|
|
160
|
+
kind: "helper-warning",
|
|
161
|
+
message: msg
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
const stashRaw = ctx.stash.get(adapterClass.STASH_KEY, {});
|
|
165
|
+
const merged = require_batteries_llm_ollama_validation.validateOptions(mergeOptions(baseline, overrides, stashRaw && typeof stashRaw === "object" ? stashRaw : {}));
|
|
166
|
+
if (merged.tokenEncoding !== null && merged.contextWindow === void 0) throw new require_batteries_llm_ollama_exceptions.E_INVALID_OLLAMA_OPTIONS(["tokenEncoding is non-null but contextWindow is undefined"]);
|
|
167
|
+
const resolvedHelpers = resolveHelpers(merged.helpers);
|
|
168
|
+
const uniqueCtors = /* @__PURE__ */ new Set();
|
|
169
|
+
for (const tc of ctx.turnToolCalls) {
|
|
170
|
+
const ctor = tc.results?.constructor;
|
|
171
|
+
if (ctor && require_spooled_artifact.SpooledArtifact.isSpooledArtifactConstructor(ctor)) uniqueCtors.add(ctor);
|
|
172
|
+
}
|
|
173
|
+
const forgedRegistries = [];
|
|
174
|
+
for (const ctor of uniqueCtors) {
|
|
175
|
+
const forgeFn = ctor.forgeTools;
|
|
176
|
+
if (typeof forgeFn === "function") forgedRegistries.push(forgeFn.call(ctor, ctx));
|
|
177
|
+
}
|
|
178
|
+
const mergedRegistry = require_tool_registry.ToolRegistry.merge([ctx.tools, ...forgedRegistries], { onCollision: "replace" });
|
|
179
|
+
mergedRegistry.bindContext(ctx);
|
|
180
|
+
const renderedToolCallResults = /* @__PURE__ */ new Map();
|
|
181
|
+
for (const tc of ctx.turnToolCalls) {
|
|
182
|
+
const rendered = await resolvedHelpers.renderOllamaToolCallResult({
|
|
183
|
+
toolCall: tc,
|
|
184
|
+
results: tc.results,
|
|
185
|
+
tool: mergedRegistry.get(tc.tool),
|
|
186
|
+
renderUntrustedContent: resolvedHelpers.renderUntrustedContent,
|
|
187
|
+
renderTrustedContent: resolvedHelpers.renderTrustedContent,
|
|
188
|
+
unsupportedMediaPolicy: merged.unsupportedMediaPolicy ?? "throw",
|
|
189
|
+
warn: localWarn
|
|
190
|
+
});
|
|
191
|
+
renderedToolCallResults.set(tc.id, rendered);
|
|
192
|
+
}
|
|
193
|
+
if (merged.tokenEncoding !== null && merged.contextWindow !== void 0) {
|
|
194
|
+
const encoding = merged.tokenEncoding;
|
|
195
|
+
let spTokens = await estimateTokensOf(ctx.systemPrompt, encoding);
|
|
196
|
+
let siTokens = 0;
|
|
197
|
+
for (const si of ctx.standingInstructions) siTokens += await estimateTokensOf(si, encoding);
|
|
198
|
+
let memTokens = 0;
|
|
199
|
+
for (const mem of ctx.turnMemories) memTokens += await estimateTokensOf(mem.content, encoding);
|
|
200
|
+
let retTokens = 0;
|
|
201
|
+
for (const r of ctx.turnRetrievables) retTokens += await estimateTokensOf(r.content, encoding);
|
|
202
|
+
let tlTokens = 0;
|
|
203
|
+
for (const msg of ctx.turnMessages) if (msg.content !== void 0) tlTokens += await estimateTokensOf(msg.content, encoding);
|
|
204
|
+
for (const th of ctx.turnThoughts) tlTokens += await estimateTokensOf(th.content, encoding);
|
|
205
|
+
for (const rendered of renderedToolCallResults.values()) tlTokens += await estimateTokensOf(new require_tool_registry.Tokenizable(rendered), encoding);
|
|
206
|
+
const total = spTokens + siTokens + memTokens + retTokens + tlTokens;
|
|
207
|
+
const perBucketObj = {
|
|
208
|
+
systemPrompt: spTokens,
|
|
209
|
+
standingInstructions: siTokens,
|
|
210
|
+
memories: memTokens,
|
|
211
|
+
retrievables: retTokens,
|
|
212
|
+
timeline: tlTokens
|
|
213
|
+
};
|
|
214
|
+
helpers.log.debug({
|
|
215
|
+
kind: "context-window-usage",
|
|
216
|
+
message: `Context window usage: ${total}/${merged.contextWindow} tokens`,
|
|
217
|
+
payload: {
|
|
218
|
+
total,
|
|
219
|
+
limit: merged.contextWindow,
|
|
220
|
+
encoding,
|
|
221
|
+
perBucket: perBucketObj
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
if (total > merged.contextWindow) throw new require_batteries_llm_ollama_exceptions.E_OLLAMA_CONTEXT_OVERFLOW([
|
|
225
|
+
total,
|
|
226
|
+
merged.contextWindow,
|
|
227
|
+
encoding,
|
|
228
|
+
JSON.stringify(perBucketObj)
|
|
229
|
+
]);
|
|
230
|
+
}
|
|
231
|
+
const { messages: wireMessages, reasoningPayloads } = await resolvedHelpers.buildOllamaHistory({
|
|
232
|
+
systemPrompt: ctx.systemPrompt,
|
|
233
|
+
standingInstructions: ctx.standingInstructions,
|
|
234
|
+
memories: ctx.turnMemories,
|
|
235
|
+
retrievables: ctx.turnRetrievables,
|
|
236
|
+
messages: ctx.turnMessages,
|
|
237
|
+
thoughts: ctx.turnThoughts,
|
|
238
|
+
toolCalls: ctx.turnToolCalls,
|
|
239
|
+
tools: mergedRegistry,
|
|
240
|
+
renderedToolCallResults,
|
|
241
|
+
bucketOrder: merged.bucketOrder ?? [
|
|
242
|
+
"standingInstructions",
|
|
243
|
+
"memories",
|
|
244
|
+
"retrievables",
|
|
245
|
+
"timeline"
|
|
246
|
+
],
|
|
247
|
+
selfIdentity: merged.selfIdentity ?? "assistant",
|
|
248
|
+
thoughtSurfacing: merged.thoughtSurfacing ?? "all-self",
|
|
249
|
+
replayCompatibility: merged.replayCompatibility ?? [],
|
|
250
|
+
renderOllamaToolCallResult: resolvedHelpers.renderOllamaToolCallResult,
|
|
251
|
+
renderChatCompletionsSystemPrompt: resolvedHelpers.renderChatCompletionsSystemPrompt,
|
|
252
|
+
renderStandingInstructions: resolvedHelpers.renderStandingInstructions,
|
|
253
|
+
renderMemories: resolvedHelpers.renderMemories,
|
|
254
|
+
renderRetrievables: resolvedHelpers.renderRetrievables,
|
|
255
|
+
renderRetrievableSafetyDirective: resolvedHelpers.renderRetrievableSafetyDirective,
|
|
256
|
+
renderFirstPartyRetrievables: resolvedHelpers.renderFirstPartyRetrievables,
|
|
257
|
+
renderThirdPartyPublicRetrievables: resolvedHelpers.renderThirdPartyPublicRetrievables,
|
|
258
|
+
renderThirdPartyPrivateRetrievables: resolvedHelpers.renderThirdPartyPrivateRetrievables,
|
|
259
|
+
renderOllamaTimelineMessage: resolvedHelpers.renderOllamaTimelineMessage,
|
|
260
|
+
renderThought: resolvedHelpers.renderThought,
|
|
261
|
+
filterThoughts: resolvedHelpers.filterThoughts,
|
|
262
|
+
renderUntrustedContent: resolvedHelpers.renderUntrustedContent,
|
|
263
|
+
renderTrustedContent: resolvedHelpers.renderTrustedContent,
|
|
264
|
+
unsupportedMediaPolicy: merged.unsupportedMediaPolicy ?? "throw",
|
|
265
|
+
warn: localWarn
|
|
266
|
+
});
|
|
267
|
+
const stream = merged.stream ?? true;
|
|
268
|
+
const body = {
|
|
269
|
+
model: merged.model,
|
|
270
|
+
messages: wireMessages,
|
|
271
|
+
stream
|
|
272
|
+
};
|
|
273
|
+
if (merged.think !== void 0) body.think = merged.think;
|
|
274
|
+
if (merged.format !== void 0) body.format = merged.format;
|
|
275
|
+
if (merged.keep_alive !== void 0) body.keep_alive = merged.keep_alive;
|
|
276
|
+
if (merged.options !== void 0) body.options = merged.options;
|
|
277
|
+
const toolsArr = mergedRegistry.visible();
|
|
278
|
+
if (toolsArr.length > 0) body.tools = require_batteries_llm_ollama_helpers.ollamaToolsFromTools(toolsArr, { descriptionToChatCompletionsJsonSchema: resolvedHelpers.descriptionToChatCompletionsJsonSchema });
|
|
279
|
+
if (reasoningPayloads.length > 0) body._adk_reasoning_payloads = reasoningPayloads;
|
|
280
|
+
const rawBase = merged.baseURL ?? "http://localhost:11434";
|
|
281
|
+
const url = `${rawBase.endsWith("/") ? rawBase.slice(0, -1) : rawBase}/api/chat`;
|
|
282
|
+
const headers = { "Content-Type": "application/json" };
|
|
283
|
+
if (stream) headers["Accept"] = "application/x-ndjson";
|
|
284
|
+
if (merged.apiKey) headers["Authorization"] = `Bearer ${merged.apiKey}`;
|
|
285
|
+
if (merged.headers) Object.assign(headers, merged.headers);
|
|
286
|
+
const retryCfg = {
|
|
287
|
+
maxAttempts: merged.retry?.maxAttempts ?? 1,
|
|
288
|
+
baseDelayMs: merged.retry?.baseDelayMs ?? 500,
|
|
289
|
+
maxDelayMs: merged.retry?.maxDelayMs ?? 3e4,
|
|
290
|
+
retriableStatuses: merged.retry?.retriableStatuses ?? [
|
|
291
|
+
429,
|
|
292
|
+
502,
|
|
293
|
+
503,
|
|
294
|
+
504
|
|
295
|
+
],
|
|
296
|
+
honorRetryAfter: merged.retry?.honorRetryAfter ?? true
|
|
297
|
+
};
|
|
298
|
+
const fetchFn = merged.fetch ?? globalThis.fetch;
|
|
299
|
+
const maxAttempts = retryCfg.maxAttempts;
|
|
300
|
+
let response;
|
|
301
|
+
let attempt = 1;
|
|
302
|
+
let disposeLink = () => {};
|
|
303
|
+
while (attempt <= maxAttempts) {
|
|
304
|
+
if (ctx.abortSignal.aborted) return;
|
|
305
|
+
const internalController = new AbortController();
|
|
306
|
+
let timeoutHandle;
|
|
307
|
+
const requestTimeoutMs = merged.requestTimeoutMs ?? 0;
|
|
308
|
+
if (requestTimeoutMs > 0) timeoutHandle = setTimeout(() => internalController.abort(), requestTimeoutMs);
|
|
309
|
+
disposeLink();
|
|
310
|
+
const { signal: linkedSignal, dispose: disposeCurrentLink } = require_lib_utils_retry.linkAbortSignals([ctx.abortSignal, internalController.signal]);
|
|
311
|
+
disposeLink = disposeCurrentLink;
|
|
312
|
+
try {
|
|
313
|
+
response = await fetchFn(url, {
|
|
314
|
+
method: "POST",
|
|
315
|
+
headers,
|
|
316
|
+
body: JSON.stringify(body),
|
|
317
|
+
signal: linkedSignal
|
|
318
|
+
});
|
|
319
|
+
} catch (err) {
|
|
320
|
+
if (timeoutHandle !== void 0) clearTimeout(timeoutHandle);
|
|
321
|
+
if (ctx.abortSignal.aborted) return;
|
|
322
|
+
if (internalController.signal.aborted) {
|
|
323
|
+
helpers.log.warn({
|
|
324
|
+
kind: "request-timeout",
|
|
325
|
+
message: `Request timed out after ${requestTimeoutMs}ms on attempt ${attempt}/${maxAttempts}`,
|
|
326
|
+
payload: {
|
|
327
|
+
requestTimeoutMs,
|
|
328
|
+
attempt,
|
|
329
|
+
maxAttempts
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
if (attempt < maxAttempts) {
|
|
333
|
+
await require_lib_utils_retry.sleepWithJitter(require_lib_utils_retry.computeBackoff(attempt, retryCfg), ctx.abortSignal);
|
|
334
|
+
attempt += 1;
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
ctx.nack(new require_batteries_llm_ollama_exceptions.E_OLLAMA_REQUEST_TIMEOUT([requestTimeoutMs]));
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
helpers.log.error({
|
|
341
|
+
kind: "transport-error",
|
|
342
|
+
message: `Transport failure on attempt ${attempt}/${maxAttempts}: ${require_tool_registry.isError(err) ? err.message : String(err)}`,
|
|
343
|
+
payload: {
|
|
344
|
+
attempt,
|
|
345
|
+
maxAttempts,
|
|
346
|
+
detail: require_tool_registry.isError(err) ? err.message : String(err)
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
ctx.nack(new require_batteries_llm_ollama_exceptions.E_OLLAMA_HTTP_ERROR([0, require_tool_registry.isError(err) ? err.message : String(err)]));
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
if (timeoutHandle !== void 0) clearTimeout(timeoutHandle);
|
|
353
|
+
if (!response.ok) {
|
|
354
|
+
const status = response.status;
|
|
355
|
+
const retriable = retryCfg.retriableStatuses.includes(status);
|
|
356
|
+
if (retriable && attempt < maxAttempts) {
|
|
357
|
+
let delay = require_lib_utils_retry.computeBackoff(attempt, retryCfg);
|
|
358
|
+
if (retryCfg.honorRetryAfter !== false) {
|
|
359
|
+
const ra = response.headers.get("Retry-After");
|
|
360
|
+
if (ra) {
|
|
361
|
+
const raMs = require_lib_utils_retry.parseRetryAfter(ra);
|
|
362
|
+
if (raMs > 0) delay = Math.min(Math.max(delay, raMs), retryCfg.maxDelayMs);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
helpers.log.warn({
|
|
366
|
+
kind: "retry-attempt",
|
|
367
|
+
message: `HTTP ${status} on attempt ${attempt}/${maxAttempts}; retrying in ~${delay}ms`,
|
|
368
|
+
payload: {
|
|
369
|
+
reason: "http-status",
|
|
370
|
+
status,
|
|
371
|
+
delayMs: delay,
|
|
372
|
+
attempt: attempt + 1,
|
|
373
|
+
maxAttempts
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
await require_lib_utils_retry.sleepWithJitter(delay, ctx.abortSignal);
|
|
377
|
+
attempt += 1;
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
const errBody = await response.text().catch(() => "");
|
|
381
|
+
helpers.log.error({
|
|
382
|
+
kind: "http-error",
|
|
383
|
+
message: `HTTP ${status} (terminal): ${errBody.slice(0, 256)}`,
|
|
384
|
+
payload: {
|
|
385
|
+
status,
|
|
386
|
+
body: errBody,
|
|
387
|
+
attempt,
|
|
388
|
+
maxAttempts,
|
|
389
|
+
retriable
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
ctx.nack(new require_batteries_llm_ollama_exceptions.E_OLLAMA_HTTP_ERROR([status, errBody]));
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
if (!response) return;
|
|
398
|
+
const spoolStore = merged.spoolStore ?? new require_batteries_storage_in_memory.InMemorySpoolStore();
|
|
399
|
+
const selfIdentity = merged.selfIdentity ?? "assistant";
|
|
400
|
+
const executeAndPersistToolCall = async (call) => {
|
|
401
|
+
const tool = mergedRegistry.get(call.name);
|
|
402
|
+
let args = {};
|
|
403
|
+
let parseError;
|
|
404
|
+
if (require_tool_registry.isObject(call.args)) args = call.args;
|
|
405
|
+
else parseError = new require_batteries_llm_ollama_exceptions.E_OLLAMA_INVALID_TOOL_CALL_ARGS([`must be a JSON object; received ${Array.isArray(call.args) ? "array" : call.args === null ? "null" : typeof call.args}`, JSON.stringify(call.args)]);
|
|
406
|
+
const completedAt = nowIso();
|
|
407
|
+
if (parseError !== void 0) {
|
|
408
|
+
const results = new require_tool_registry.Tokenizable(parseError.message);
|
|
409
|
+
helpers.reportToolCall(call.id, {
|
|
410
|
+
tool: call.name,
|
|
411
|
+
args
|
|
412
|
+
});
|
|
413
|
+
helpers.reportToolCall(call.id, {
|
|
414
|
+
results,
|
|
415
|
+
isError: true,
|
|
416
|
+
isComplete: true
|
|
417
|
+
});
|
|
418
|
+
await ctx.storeToolCall(new require_tool_call.ToolCall({
|
|
419
|
+
id: call.id,
|
|
420
|
+
tool: call.name,
|
|
421
|
+
args,
|
|
422
|
+
checksum: computeChecksum(call.name, args),
|
|
423
|
+
isComplete: true,
|
|
424
|
+
isError: true,
|
|
425
|
+
results,
|
|
426
|
+
createdAt: completedAt,
|
|
427
|
+
updatedAt: completedAt,
|
|
428
|
+
completedAt
|
|
429
|
+
}));
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
if (!tool) {
|
|
433
|
+
const available = mergedRegistry.all().map((t) => t.name).sort();
|
|
434
|
+
const results = new require_tool_registry.Tokenizable(available.length > 0 ? `Tool not found: ${call.name}. Available tools: ${available.join(", ")}.` : `Tool not found: ${call.name}. No tools are available this turn.`);
|
|
435
|
+
helpers.reportToolCall(call.id, {
|
|
436
|
+
tool: call.name,
|
|
437
|
+
args
|
|
438
|
+
});
|
|
439
|
+
helpers.reportToolCall(call.id, {
|
|
440
|
+
results,
|
|
441
|
+
isError: true,
|
|
442
|
+
isComplete: true
|
|
443
|
+
});
|
|
444
|
+
await ctx.storeToolCall(new require_tool_call.ToolCall({
|
|
445
|
+
id: call.id,
|
|
446
|
+
tool: call.name,
|
|
447
|
+
args,
|
|
448
|
+
checksum: computeChecksum(call.name, args),
|
|
449
|
+
isComplete: true,
|
|
450
|
+
isError: true,
|
|
451
|
+
results,
|
|
452
|
+
createdAt: completedAt,
|
|
453
|
+
updatedAt: completedAt,
|
|
454
|
+
completedAt
|
|
455
|
+
}));
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
helpers.reportToolCall(call.id, {
|
|
459
|
+
tool: tool.name,
|
|
460
|
+
args
|
|
461
|
+
});
|
|
462
|
+
const isArtifactTool = require_spooled_artifact.ArtifactTool.isArtifactTool(tool);
|
|
463
|
+
let results = new require_tool_registry.Tokenizable("");
|
|
464
|
+
let toolHadError = false;
|
|
465
|
+
try {
|
|
466
|
+
const raw = await tool.executor(ctx)(args);
|
|
467
|
+
if (isArtifactTool) if (require_tool_registry.Tokenizable.isTokenizable(raw)) results = raw;
|
|
468
|
+
else if (typeof raw === "string") results = new require_tool_registry.Tokenizable(raw);
|
|
469
|
+
else throw new Error(`ArtifactTool "${tool.name}" returned a non-string/non-Tokenizable value`);
|
|
470
|
+
else if (require_tool_call.Media.isMedia(raw)) results = raw;
|
|
471
|
+
else if (Array.isArray(raw) && raw.length > 0 && raw.every((m) => require_tool_call.Media.isMedia(m))) results = raw;
|
|
472
|
+
else if (typeof raw === "string" || require_tool_registry.isInstanceOf(raw, "Uint8Array", Uint8Array)) {
|
|
473
|
+
const reader = await spoolStore.write(call.id, raw);
|
|
474
|
+
results = new ((tool.artifactConstructor?.()) ?? require_spooled_artifact.SpooledArtifact)(reader);
|
|
475
|
+
} else {
|
|
476
|
+
const reader = await spoolStore.write(call.id, String(raw));
|
|
477
|
+
results = new ((tool.artifactConstructor?.()) ?? require_spooled_artifact.SpooledArtifact)(reader);
|
|
478
|
+
}
|
|
479
|
+
} catch (err) {
|
|
480
|
+
toolHadError = true;
|
|
481
|
+
let detailMsg = require_tool_registry.isError(err) ? err.message : String(err);
|
|
482
|
+
if (require_tool_registry.isError(err) && require_tool_registry.isError(err.cause) && err.cause.message && err.cause.message !== err.message) detailMsg = `${detailMsg} ${err.cause.message}`;
|
|
483
|
+
results = new require_tool_registry.Tokenizable(detailMsg);
|
|
484
|
+
}
|
|
485
|
+
helpers.reportToolCall(call.id, {
|
|
486
|
+
results,
|
|
487
|
+
isError: toolHadError,
|
|
488
|
+
isComplete: true
|
|
489
|
+
});
|
|
490
|
+
const completedAt2 = nowIso();
|
|
491
|
+
await ctx.storeToolCall(new require_tool_call.ToolCall({
|
|
492
|
+
id: call.id,
|
|
493
|
+
tool: tool.name,
|
|
494
|
+
args,
|
|
495
|
+
checksum: computeChecksum(tool.name, args),
|
|
496
|
+
isComplete: true,
|
|
497
|
+
isError: toolHadError,
|
|
498
|
+
results,
|
|
499
|
+
fromArtifactTool: isArtifactTool,
|
|
500
|
+
createdAt: completedAt2,
|
|
501
|
+
updatedAt: completedAt2,
|
|
502
|
+
completedAt: completedAt2
|
|
503
|
+
}));
|
|
504
|
+
};
|
|
505
|
+
if (stream) {
|
|
506
|
+
if (!response.body) {
|
|
507
|
+
ctx.nack(new require_batteries_llm_ollama_exceptions.E_OLLAMA_STREAM_ERROR(["response has no body"]));
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
const reader = response.body.getReader();
|
|
511
|
+
const decoder = new TextDecoder();
|
|
512
|
+
const streamId = (0, uuid.v6)();
|
|
513
|
+
let buffer = "";
|
|
514
|
+
let idleTimer;
|
|
515
|
+
let stalled = false;
|
|
516
|
+
let partialMessageContent = "";
|
|
517
|
+
let sawMessageDelta = false;
|
|
518
|
+
let partialThinking = "";
|
|
519
|
+
let sawThinking = false;
|
|
520
|
+
let doneSeen = false;
|
|
521
|
+
const collectedToolCalls = [];
|
|
522
|
+
const thoughtStreamId = `${streamId}:thought`;
|
|
523
|
+
const idleMs = merged.streamIdleTimeoutMs ?? 0;
|
|
524
|
+
const armIdleTimer = () => {
|
|
525
|
+
if (idleMs <= 0) return;
|
|
526
|
+
if (idleTimer) clearTimeout(idleTimer);
|
|
527
|
+
idleTimer = setTimeout(() => {
|
|
528
|
+
stalled = true;
|
|
529
|
+
helpers.log.warn({
|
|
530
|
+
kind: "stream-idle-timeout",
|
|
531
|
+
message: `NDJSON stream went idle for ${idleMs}ms; cancelling`,
|
|
532
|
+
payload: { idleMs }
|
|
533
|
+
});
|
|
534
|
+
reader.cancel().catch(() => {});
|
|
535
|
+
}, idleMs);
|
|
536
|
+
};
|
|
537
|
+
const clearIdleTimer = () => {
|
|
538
|
+
if (idleTimer) {
|
|
539
|
+
clearTimeout(idleTimer);
|
|
540
|
+
idleTimer = void 0;
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
const drainAndPersist = async (statsSrc) => {
|
|
544
|
+
if (sawMessageDelta) {
|
|
545
|
+
helpers.reportMessage(streamId, "", { isComplete: true });
|
|
546
|
+
await ctx.storeMessage(new require_thought.Message({
|
|
547
|
+
id: streamId,
|
|
548
|
+
role: "assistant",
|
|
549
|
+
content: partialMessageContent,
|
|
550
|
+
identity: selfIdentity,
|
|
551
|
+
createdAt: nowIso(),
|
|
552
|
+
updatedAt: nowIso()
|
|
553
|
+
}));
|
|
554
|
+
}
|
|
555
|
+
if (sawThinking) {
|
|
556
|
+
helpers.reportThought(thoughtStreamId, "", { isComplete: true });
|
|
557
|
+
await ctx.storeThought(new require_thought.Thought({
|
|
558
|
+
id: thoughtStreamId,
|
|
559
|
+
content: partialThinking,
|
|
560
|
+
identity: selfIdentity,
|
|
561
|
+
createdAt: nowIso(),
|
|
562
|
+
updatedAt: nowIso()
|
|
563
|
+
}));
|
|
564
|
+
}
|
|
565
|
+
if (statsSrc !== void 0) helpers.reportGenerationStats(extractGenerationStats(statsSrc, merged.model));
|
|
566
|
+
if (collectedToolCalls.length === 0) {
|
|
567
|
+
if (merged.autoAck) ctx.ack();
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
for (const call of collectedToolCalls) {
|
|
571
|
+
if (ctx.abortSignal.aborted) return;
|
|
572
|
+
await executeAndPersistToolCall(call);
|
|
573
|
+
}
|
|
574
|
+
};
|
|
575
|
+
const handleChunk = (chunk) => {
|
|
576
|
+
const m = chunk.message;
|
|
577
|
+
if (m) {
|
|
578
|
+
if (typeof m.content === "string" && m.content.length > 0) {
|
|
579
|
+
sawMessageDelta = true;
|
|
580
|
+
partialMessageContent += m.content;
|
|
581
|
+
helpers.reportMessage(streamId, m.content);
|
|
582
|
+
}
|
|
583
|
+
if (typeof m.thinking === "string" && m.thinking.length > 0) {
|
|
584
|
+
sawThinking = true;
|
|
585
|
+
partialThinking += m.thinking;
|
|
586
|
+
helpers.reportThought(thoughtStreamId, m.thinking);
|
|
587
|
+
}
|
|
588
|
+
if (Array.isArray(m.tool_calls)) for (const tc of m.tool_calls) collectedToolCalls.push({
|
|
589
|
+
id: (0, uuid.v6)(),
|
|
590
|
+
name: tc.function?.name ?? "",
|
|
591
|
+
args: tc.function?.arguments ?? {}
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
const parseLine = (line) => {
|
|
596
|
+
const trimmed = line.trim();
|
|
597
|
+
if (trimmed.length === 0) return void 0;
|
|
598
|
+
try {
|
|
599
|
+
return JSON.parse(trimmed);
|
|
600
|
+
} catch {
|
|
601
|
+
helpers.log.trace({
|
|
602
|
+
kind: "ndjson-parse-failure",
|
|
603
|
+
message: "Failed to parse NDJSON line as JSON; skipping",
|
|
604
|
+
payload: { linePreview: trimmed.slice(0, 256) }
|
|
605
|
+
});
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
try {
|
|
610
|
+
armIdleTimer();
|
|
611
|
+
while (true) {
|
|
612
|
+
const { done, value } = await reader.read();
|
|
613
|
+
if (done) break;
|
|
614
|
+
armIdleTimer();
|
|
615
|
+
if (ctx.abortSignal.aborted) {
|
|
616
|
+
clearIdleTimer();
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
buffer += decoder.decode(value, { stream: true });
|
|
620
|
+
let nl = buffer.indexOf("\n");
|
|
621
|
+
while (nl !== -1) {
|
|
622
|
+
const line = buffer.slice(0, nl);
|
|
623
|
+
buffer = buffer.slice(nl + 1);
|
|
624
|
+
const chunk = parseLine(line);
|
|
625
|
+
if (chunk !== void 0) {
|
|
626
|
+
handleChunk(chunk);
|
|
627
|
+
if (chunk.done === true) {
|
|
628
|
+
doneSeen = true;
|
|
629
|
+
clearIdleTimer();
|
|
630
|
+
await drainAndPersist(chunk);
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
nl = buffer.indexOf("\n");
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
clearIdleTimer();
|
|
638
|
+
if (stalled) {
|
|
639
|
+
ctx.nack(new require_batteries_llm_ollama_exceptions.E_OLLAMA_STREAM_STALLED([idleMs]));
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
if (!doneSeen && buffer.trim().length > 0) {
|
|
643
|
+
const chunk = parseLine(buffer);
|
|
644
|
+
buffer = "";
|
|
645
|
+
if (chunk !== void 0) {
|
|
646
|
+
handleChunk(chunk);
|
|
647
|
+
if (chunk.done === true) {
|
|
648
|
+
await drainAndPersist(chunk);
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
if (!doneSeen) {
|
|
654
|
+
helpers.log.warn({
|
|
655
|
+
kind: "ndjson-eof-without-done",
|
|
656
|
+
message: "NDJSON stream ended without a done:true chunk; draining accumulated state"
|
|
657
|
+
});
|
|
658
|
+
await drainAndPersist(void 0);
|
|
659
|
+
}
|
|
660
|
+
} catch (err) {
|
|
661
|
+
clearIdleTimer();
|
|
662
|
+
if (ctx.abortSignal.aborted) return;
|
|
663
|
+
if (stalled) {
|
|
664
|
+
ctx.nack(new require_batteries_llm_ollama_exceptions.E_OLLAMA_STREAM_STALLED([idleMs]));
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
helpers.log.error({
|
|
668
|
+
kind: "stream-error",
|
|
669
|
+
message: `NDJSON stream failed: ${require_tool_registry.isError(err) ? err.message : String(err)}`,
|
|
670
|
+
payload: { detail: require_tool_registry.isError(err) ? err.message : String(err) }
|
|
671
|
+
});
|
|
672
|
+
ctx.nack(new require_batteries_llm_ollama_exceptions.E_OLLAMA_STREAM_ERROR([require_tool_registry.isError(err) ? err.message : String(err)]));
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
let parsed;
|
|
678
|
+
try {
|
|
679
|
+
parsed = await response.json();
|
|
680
|
+
} catch (err) {
|
|
681
|
+
ctx.nack(new require_batteries_llm_ollama_exceptions.E_OLLAMA_STREAM_ERROR([require_tool_registry.isError(err) ? err.message : String(err)]));
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
const responseId = (0, uuid.v6)();
|
|
685
|
+
const msg = parsed.message;
|
|
686
|
+
if (msg && typeof msg.content === "string" && msg.content.length > 0) {
|
|
687
|
+
const messageId = `${responseId}:message`;
|
|
688
|
+
helpers.reportMessage(messageId, msg.content, { isComplete: true });
|
|
689
|
+
await ctx.storeMessage(new require_thought.Message({
|
|
690
|
+
id: messageId,
|
|
691
|
+
role: "assistant",
|
|
692
|
+
content: msg.content,
|
|
693
|
+
identity: selfIdentity,
|
|
694
|
+
createdAt: nowIso(),
|
|
695
|
+
updatedAt: nowIso()
|
|
696
|
+
}));
|
|
697
|
+
}
|
|
698
|
+
if (msg && typeof msg.thinking === "string" && msg.thinking.length > 0) {
|
|
699
|
+
const thoughtId = `${responseId}:thought`;
|
|
700
|
+
helpers.reportThought(thoughtId, msg.thinking, { isComplete: true });
|
|
701
|
+
await ctx.storeThought(new require_thought.Thought({
|
|
702
|
+
id: thoughtId,
|
|
703
|
+
content: msg.thinking,
|
|
704
|
+
identity: selfIdentity,
|
|
705
|
+
createdAt: nowIso(),
|
|
706
|
+
updatedAt: nowIso()
|
|
707
|
+
}));
|
|
708
|
+
}
|
|
709
|
+
helpers.reportGenerationStats(extractGenerationStats(parsed, merged.model));
|
|
710
|
+
const rawCalls = msg?.tool_calls ?? [];
|
|
711
|
+
if (rawCalls.length === 0) {
|
|
712
|
+
if (merged.autoAck) ctx.ack();
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
const calls = rawCalls.map((tc) => ({
|
|
716
|
+
id: (0, uuid.v6)(),
|
|
717
|
+
name: tc.function?.name ?? "",
|
|
718
|
+
args: tc.function?.arguments ?? {}
|
|
719
|
+
}));
|
|
720
|
+
for (const call of calls) {
|
|
721
|
+
if (ctx.abortSignal.aborted) return;
|
|
722
|
+
await executeAndPersistToolCall(call);
|
|
723
|
+
}
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* Returns `true` when `value` is an {@link OllamaAdapter} instance.
|
|
728
|
+
*/
|
|
729
|
+
static isOllamaAdapter(value) {
|
|
730
|
+
return require_tool_registry.isInstanceOf(value, "OllamaAdapter", OllamaAdapter);
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
//#endregion
|
|
734
|
+
exports.OllamaAdapter = OllamaAdapter;
|
|
735
|
+
|
|
736
|
+
//# sourceMappingURL=adapter.cjs.map
|