@dexto/core 1.4.0 → 1.5.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/README.md +36 -0
- package/dist/agent/DextoAgent.cjs +22 -3
- package/dist/agent/DextoAgent.d.ts +19 -2
- package/dist/agent/DextoAgent.d.ts.map +1 -1
- package/dist/agent/DextoAgent.js +23 -4
- package/dist/agent/index.cjs +4 -1
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +5 -1
- package/dist/agent/schemas.cjs +90 -71
- package/dist/agent/schemas.d.ts +5911 -96
- package/dist/agent/schemas.d.ts.map +1 -1
- package/dist/agent/schemas.js +87 -66
- package/dist/approval/manager.cjs +165 -1
- package/dist/approval/manager.d.ts +91 -2
- package/dist/approval/manager.d.ts.map +1 -1
- package/dist/approval/manager.js +155 -1
- package/dist/approval/schemas.cjs +39 -3
- package/dist/approval/schemas.d.ts +238 -1
- package/dist/approval/schemas.d.ts.map +1 -1
- package/dist/approval/schemas.js +35 -3
- package/dist/approval/types.cjs +1 -0
- package/dist/approval/types.d.ts +26 -1
- package/dist/approval/types.d.ts.map +1 -1
- package/dist/approval/types.js +1 -0
- package/dist/context/compaction/factory.cjs +57 -0
- package/dist/context/compaction/factory.d.ts +17 -0
- package/dist/context/compaction/factory.d.ts.map +1 -0
- package/dist/context/compaction/factory.js +34 -0
- package/dist/context/compaction/index.cjs +49 -0
- package/dist/context/compaction/index.d.ts +11 -0
- package/dist/context/compaction/index.d.ts.map +1 -0
- package/dist/context/compaction/index.js +19 -0
- package/dist/context/{compression → compaction}/overflow.cjs +3 -3
- package/dist/context/{compression → compaction}/overflow.d.ts +4 -4
- package/dist/context/compaction/overflow.d.ts.map +1 -0
- package/dist/context/{compression → compaction}/overflow.js +2 -2
- package/dist/context/compaction/provider.cjs +16 -0
- package/dist/context/compaction/provider.d.ts +48 -0
- package/dist/context/compaction/provider.d.ts.map +1 -0
- package/dist/context/compaction/providers/noop-provider.cjs +48 -0
- package/dist/context/compaction/providers/noop-provider.d.ts +24 -0
- package/dist/context/compaction/providers/noop-provider.d.ts.map +1 -0
- package/dist/context/compaction/providers/noop-provider.js +24 -0
- package/dist/context/compaction/providers/reactive-overflow-provider.cjs +61 -0
- package/dist/context/compaction/providers/reactive-overflow-provider.d.ts +36 -0
- package/dist/context/compaction/providers/reactive-overflow-provider.d.ts.map +1 -0
- package/dist/context/compaction/providers/reactive-overflow-provider.js +37 -0
- package/dist/context/compaction/registry.cjs +39 -0
- package/dist/context/compaction/registry.d.ts +19 -0
- package/dist/context/compaction/registry.d.ts.map +1 -0
- package/dist/context/compaction/registry.js +16 -0
- package/dist/context/compaction/schemas.cjs +38 -0
- package/dist/context/compaction/schemas.d.ts +24 -0
- package/dist/context/compaction/schemas.d.ts.map +1 -0
- package/dist/context/compaction/schemas.js +14 -0
- package/dist/context/compaction/strategies/noop.cjs +36 -0
- package/dist/context/compaction/strategies/noop.d.ts +18 -0
- package/dist/context/compaction/strategies/noop.d.ts.map +1 -0
- package/dist/context/compaction/strategies/noop.js +13 -0
- package/dist/context/{compression → compaction/strategies}/reactive-overflow.cjs +3 -3
- package/dist/context/{compression → compaction/strategies}/reactive-overflow.d.ts +6 -6
- package/dist/context/compaction/strategies/reactive-overflow.d.ts.map +1 -0
- package/dist/context/{compression → compaction/strategies}/reactive-overflow.js +4 -4
- package/dist/context/{compression → compaction}/types.d.ts +4 -4
- package/dist/context/compaction/types.d.ts.map +1 -0
- package/dist/context/compaction/types.js +0 -0
- package/dist/context/error-codes.cjs +4 -0
- package/dist/context/error-codes.d.ts +4 -0
- package/dist/context/error-codes.d.ts.map +1 -1
- package/dist/context/error-codes.js +4 -0
- package/dist/context/errors.cjs +40 -0
- package/dist/context/errors.d.ts +14 -0
- package/dist/context/errors.d.ts.map +1 -1
- package/dist/context/errors.js +40 -0
- package/dist/context/index.cjs +3 -1
- package/dist/context/index.d.ts +1 -0
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +1 -0
- package/dist/context/types.d.ts +6 -0
- package/dist/context/types.d.ts.map +1 -1
- package/dist/context/utils.cjs +27 -7
- package/dist/context/utils.d.ts.map +1 -1
- package/dist/context/utils.js +27 -7
- package/dist/errors/result-bridge.cjs +2 -3
- package/dist/errors/result-bridge.d.ts.map +1 -1
- package/dist/errors/result-bridge.js +2 -3
- package/dist/events/index.cjs +2 -2
- package/dist/events/index.d.ts +16 -16
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +2 -2
- package/dist/filesystem/filesystem-service.cjs +39 -0
- package/dist/filesystem/filesystem-service.d.ts +32 -0
- package/dist/filesystem/filesystem-service.d.ts.map +1 -1
- package/dist/filesystem/filesystem-service.js +39 -0
- package/dist/filesystem/index.d.ts +1 -1
- package/dist/filesystem/index.d.ts.map +1 -1
- package/dist/filesystem/path-validator.cjs +69 -1
- package/dist/filesystem/path-validator.d.ts +43 -2
- package/dist/filesystem/path-validator.d.ts.map +1 -1
- package/dist/filesystem/path-validator.js +69 -1
- package/dist/image/define-image.cjs +146 -0
- package/dist/image/define-image.d.ts +71 -0
- package/dist/image/define-image.d.ts.map +1 -0
- package/dist/image/define-image.js +121 -0
- package/dist/image/index.cjs +32 -0
- package/dist/image/index.d.ts +53 -0
- package/dist/image/index.d.ts.map +1 -0
- package/dist/image/index.js +7 -0
- package/dist/image/types.cjs +16 -0
- package/dist/image/types.d.ts +231 -0
- package/dist/image/types.d.ts.map +1 -0
- package/dist/image/types.js +0 -0
- package/dist/index.cjs +5 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/llm/error-codes.cjs +1 -0
- package/dist/llm/error-codes.d.ts +1 -0
- package/dist/llm/error-codes.d.ts.map +1 -1
- package/dist/llm/error-codes.js +1 -0
- package/dist/llm/errors.cjs +24 -0
- package/dist/llm/errors.d.ts +19 -6
- package/dist/llm/errors.d.ts.map +1 -1
- package/dist/llm/errors.js +24 -0
- package/dist/llm/executor/stream-processor.cjs +11 -3
- package/dist/llm/executor/stream-processor.d.ts.map +1 -1
- package/dist/llm/executor/stream-processor.js +11 -3
- package/dist/llm/executor/turn-executor.cjs +50 -23
- package/dist/llm/executor/turn-executor.d.ts +6 -5
- package/dist/llm/executor/turn-executor.d.ts.map +1 -1
- package/dist/llm/executor/turn-executor.js +50 -23
- package/dist/llm/formatters/vercel.cjs +6 -2
- package/dist/llm/formatters/vercel.d.ts.map +1 -1
- package/dist/llm/formatters/vercel.js +6 -2
- package/dist/llm/index.cjs +18 -1
- package/dist/llm/index.d.ts +2 -0
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +14 -0
- package/dist/llm/providers/local/ai-sdk-adapter.cjs +308 -0
- package/dist/llm/providers/local/ai-sdk-adapter.d.ts +29 -0
- package/dist/llm/providers/local/ai-sdk-adapter.d.ts.map +1 -0
- package/dist/llm/providers/local/ai-sdk-adapter.js +278 -0
- package/dist/llm/providers/local/downloader.cjs +291 -0
- package/dist/llm/providers/local/downloader.d.ts +82 -0
- package/dist/llm/providers/local/downloader.d.ts.map +1 -0
- package/dist/llm/providers/local/downloader.js +251 -0
- package/dist/llm/providers/local/error-codes.cjs +57 -0
- package/dist/llm/providers/local/error-codes.d.ts +66 -0
- package/dist/llm/providers/local/error-codes.d.ts.map +1 -0
- package/dist/llm/providers/local/error-codes.js +34 -0
- package/dist/llm/providers/local/errors.cjs +240 -0
- package/dist/llm/providers/local/errors.d.ts +31 -0
- package/dist/llm/providers/local/errors.d.ts.map +1 -0
- package/dist/llm/providers/local/errors.js +217 -0
- package/dist/llm/providers/local/gpu-detector.cjs +214 -0
- package/dist/llm/providers/local/gpu-detector.d.ts +28 -0
- package/dist/llm/providers/local/gpu-detector.d.ts.map +1 -0
- package/dist/llm/providers/local/gpu-detector.js +178 -0
- package/dist/llm/providers/local/index.cjs +147 -0
- package/dist/llm/providers/local/index.d.ts +21 -0
- package/dist/llm/providers/local/index.d.ts.map +1 -0
- package/dist/llm/providers/local/index.js +126 -0
- package/dist/llm/providers/local/node-llama-provider.cjs +216 -0
- package/dist/llm/providers/local/node-llama-provider.d.ts +90 -0
- package/dist/llm/providers/local/node-llama-provider.d.ts.map +1 -0
- package/dist/llm/providers/local/node-llama-provider.js +176 -0
- package/dist/llm/providers/local/ollama-provider.cjs +230 -0
- package/dist/llm/providers/local/ollama-provider.d.ts +70 -0
- package/dist/llm/providers/local/ollama-provider.d.ts.map +1 -0
- package/dist/llm/providers/local/ollama-provider.js +198 -0
- package/dist/llm/providers/local/registry.cjs +343 -0
- package/dist/llm/providers/local/registry.d.ts +51 -0
- package/dist/llm/providers/local/registry.d.ts.map +1 -0
- package/dist/llm/providers/local/registry.js +312 -0
- package/dist/llm/providers/local/schemas.cjs +169 -0
- package/dist/llm/providers/local/schemas.d.ts +395 -0
- package/dist/llm/providers/local/schemas.d.ts.map +1 -0
- package/dist/llm/providers/local/schemas.js +133 -0
- package/dist/llm/providers/local/types.cjs +16 -0
- package/dist/llm/providers/local/types.d.ts +219 -0
- package/dist/llm/providers/local/types.d.ts.map +1 -0
- package/dist/llm/providers/local/types.js +0 -0
- package/dist/llm/providers/openrouter-model-registry.cjs +350 -0
- package/dist/llm/providers/openrouter-model-registry.d.ts +120 -0
- package/dist/llm/providers/openrouter-model-registry.d.ts.map +1 -0
- package/dist/llm/providers/openrouter-model-registry.js +309 -0
- package/dist/llm/registry.cjs +535 -9
- package/dist/llm/registry.d.ts +26 -0
- package/dist/llm/registry.d.ts.map +1 -1
- package/dist/llm/registry.js +532 -9
- package/dist/llm/resolver.cjs +63 -5
- package/dist/llm/resolver.d.ts +3 -3
- package/dist/llm/resolver.d.ts.map +1 -1
- package/dist/llm/resolver.js +69 -6
- package/dist/llm/schemas.cjs +90 -80
- package/dist/llm/schemas.d.ts +158 -22
- package/dist/llm/schemas.d.ts.map +1 -1
- package/dist/llm/schemas.js +90 -80
- package/dist/llm/services/factory.cjs +87 -13
- package/dist/llm/services/factory.d.ts +4 -1
- package/dist/llm/services/factory.d.ts.map +1 -1
- package/dist/llm/services/factory.js +85 -12
- package/dist/llm/services/test-utils.integration.cjs +22 -2
- package/dist/llm/services/test-utils.integration.d.ts +7 -1
- package/dist/llm/services/test-utils.integration.d.ts.map +1 -1
- package/dist/llm/services/test-utils.integration.js +26 -3
- package/dist/llm/services/vercel.cjs +5 -2
- package/dist/llm/services/vercel.d.ts +3 -2
- package/dist/llm/services/vercel.d.ts.map +1 -1
- package/dist/llm/services/vercel.js +5 -2
- package/dist/llm/types.cjs +11 -1
- package/dist/llm/types.d.ts +1 -1
- package/dist/llm/types.d.ts.map +1 -1
- package/dist/llm/types.js +11 -1
- package/dist/mcp/manager.cjs +8 -0
- package/dist/mcp/manager.d.ts +17 -0
- package/dist/mcp/manager.d.ts.map +1 -1
- package/dist/mcp/manager.js +8 -0
- package/dist/mcp/mcp-client.cjs +0 -3
- package/dist/mcp/mcp-client.d.ts.map +1 -1
- package/dist/mcp/mcp-client.js +0 -3
- package/dist/memory/schemas.d.ts +1 -1
- package/dist/plugins/error-codes.cjs +3 -0
- package/dist/plugins/error-codes.d.ts +7 -1
- package/dist/plugins/error-codes.d.ts.map +1 -1
- package/dist/plugins/error-codes.js +3 -0
- package/dist/plugins/index.cjs +7 -0
- package/dist/plugins/index.d.ts +4 -2
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +6 -1
- package/dist/plugins/manager.cjs +92 -7
- package/dist/plugins/manager.d.ts +10 -3
- package/dist/plugins/manager.d.ts.map +1 -1
- package/dist/plugins/manager.js +92 -7
- package/dist/plugins/registry.cjs +63 -0
- package/dist/plugins/registry.d.ts +101 -0
- package/dist/plugins/registry.d.ts.map +1 -0
- package/dist/plugins/registry.js +39 -0
- package/dist/plugins/schemas.cjs +17 -5
- package/dist/plugins/schemas.d.ts +62 -5
- package/dist/plugins/schemas.d.ts.map +1 -1
- package/dist/plugins/schemas.js +15 -4
- package/dist/providers/base-registry.cjs +147 -0
- package/dist/providers/base-registry.d.ts +147 -0
- package/dist/providers/base-registry.d.ts.map +1 -0
- package/dist/providers/base-registry.js +123 -0
- package/dist/providers/discovery.cjs +95 -0
- package/dist/providers/discovery.d.ts +94 -0
- package/dist/providers/discovery.d.ts.map +1 -0
- package/dist/providers/discovery.js +70 -0
- package/dist/providers/index.cjs +24 -0
- package/dist/providers/index.d.ts +32 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +2 -0
- package/dist/resources/reference-parser.cjs +3 -3
- package/dist/resources/reference-parser.d.ts.map +1 -1
- package/dist/resources/reference-parser.js +3 -3
- package/dist/session/chat-session.cjs +20 -3
- package/dist/session/chat-session.d.ts.map +1 -1
- package/dist/session/chat-session.js +21 -4
- package/dist/storage/blob/factory.cjs +8 -11
- package/dist/storage/blob/factory.d.ts +32 -6
- package/dist/storage/blob/factory.d.ts.map +1 -1
- package/dist/storage/blob/factory.js +8 -11
- package/dist/storage/blob/index.cjs +56 -0
- package/dist/storage/blob/index.d.ts +45 -0
- package/dist/storage/blob/index.d.ts.map +1 -0
- package/dist/storage/blob/index.js +30 -0
- package/dist/storage/blob/provider.cjs +16 -0
- package/dist/storage/blob/provider.d.ts +50 -0
- package/dist/storage/blob/provider.d.ts.map +1 -0
- package/dist/storage/blob/provider.js +0 -0
- package/dist/storage/blob/providers/index.cjs +31 -0
- package/dist/storage/blob/providers/index.d.ts +8 -0
- package/dist/storage/blob/providers/index.d.ts.map +1 -0
- package/dist/storage/blob/providers/index.js +7 -0
- package/dist/storage/blob/providers/local.cjs +39 -0
- package/dist/storage/blob/providers/local.d.ts +17 -0
- package/dist/storage/blob/providers/local.d.ts.map +1 -0
- package/dist/storage/blob/providers/local.js +16 -0
- package/dist/storage/blob/providers/memory.cjs +39 -0
- package/dist/storage/blob/providers/memory.d.ts +17 -0
- package/dist/storage/blob/providers/memory.d.ts.map +1 -0
- package/dist/storage/blob/providers/memory.js +16 -0
- package/dist/storage/blob/registry.cjs +50 -0
- package/dist/storage/blob/registry.d.ts +42 -0
- package/dist/storage/blob/registry.d.ts.map +1 -0
- package/dist/storage/blob/registry.js +26 -0
- package/dist/storage/blob/schemas.cjs +9 -12
- package/dist/storage/blob/schemas.d.ts +39 -34
- package/dist/storage/blob/schemas.d.ts.map +1 -1
- package/dist/storage/blob/schemas.js +6 -11
- package/dist/storage/cache/factory.cjs +8 -36
- package/dist/storage/cache/factory.d.ts +32 -7
- package/dist/storage/cache/factory.d.ts.map +1 -1
- package/dist/storage/cache/factory.js +8 -26
- package/dist/storage/cache/index.cjs +53 -0
- package/dist/storage/cache/index.d.ts +44 -0
- package/dist/storage/cache/index.d.ts.map +1 -0
- package/dist/storage/cache/index.js +28 -0
- package/dist/storage/cache/provider.cjs +16 -0
- package/dist/storage/cache/provider.d.ts +56 -0
- package/dist/storage/cache/provider.d.ts.map +1 -0
- package/dist/storage/cache/provider.js +0 -0
- package/dist/storage/cache/providers/index.cjs +31 -0
- package/dist/storage/cache/providers/index.d.ts +8 -0
- package/dist/storage/cache/providers/index.d.ts.map +1 -0
- package/dist/storage/cache/providers/index.js +7 -0
- package/dist/storage/cache/providers/memory.cjs +40 -0
- package/dist/storage/cache/providers/memory.d.ts +17 -0
- package/dist/storage/cache/providers/memory.d.ts.map +1 -0
- package/dist/storage/cache/providers/memory.js +17 -0
- package/dist/storage/cache/providers/redis.cjs +66 -0
- package/dist/storage/cache/providers/redis.d.ts +20 -0
- package/dist/storage/cache/providers/redis.d.ts.map +1 -0
- package/dist/storage/cache/providers/redis.js +33 -0
- package/dist/storage/cache/registry.cjs +50 -0
- package/dist/storage/cache/registry.d.ts +42 -0
- package/dist/storage/cache/registry.d.ts.map +1 -0
- package/dist/storage/cache/registry.js +26 -0
- package/dist/storage/cache/schemas.cjs +6 -2
- package/dist/storage/cache/schemas.d.ts +2 -3
- package/dist/storage/cache/schemas.d.ts.map +1 -1
- package/dist/storage/cache/schemas.js +3 -1
- package/dist/storage/database/factory.cjs +8 -47
- package/dist/storage/database/factory.d.ts +34 -8
- package/dist/storage/database/factory.d.ts.map +1 -1
- package/dist/storage/database/factory.js +8 -37
- package/dist/storage/database/index.cjs +58 -0
- package/dist/storage/database/index.d.ts +45 -0
- package/dist/storage/database/index.d.ts.map +1 -0
- package/dist/storage/database/index.js +37 -0
- package/dist/storage/database/provider.cjs +16 -0
- package/dist/storage/database/provider.d.ts +56 -0
- package/dist/storage/database/provider.d.ts.map +1 -0
- package/dist/storage/database/provider.js +0 -0
- package/dist/storage/database/providers/index.cjs +34 -0
- package/dist/storage/database/providers/index.d.ts +9 -0
- package/dist/storage/database/providers/index.d.ts.map +1 -0
- package/dist/storage/database/providers/index.js +9 -0
- package/dist/storage/database/providers/memory.cjs +40 -0
- package/dist/storage/database/providers/memory.d.ts +16 -0
- package/dist/storage/database/providers/memory.d.ts.map +1 -0
- package/dist/storage/database/providers/memory.js +17 -0
- package/dist/storage/database/providers/postgres.cjs +62 -0
- package/dist/storage/database/providers/postgres.d.ts +19 -0
- package/dist/storage/database/providers/postgres.d.ts.map +1 -0
- package/dist/storage/database/providers/postgres.js +29 -0
- package/dist/storage/database/providers/sqlite.cjs +66 -0
- package/dist/storage/database/providers/sqlite.d.ts +20 -0
- package/dist/storage/database/providers/sqlite.d.ts.map +1 -0
- package/dist/storage/database/providers/sqlite.js +33 -0
- package/dist/storage/database/registry.cjs +50 -0
- package/dist/storage/database/registry.d.ts +42 -0
- package/dist/storage/database/registry.d.ts.map +1 -0
- package/dist/storage/database/registry.js +26 -0
- package/dist/storage/database/schemas.cjs +8 -2
- package/dist/storage/database/schemas.d.ts +3 -4
- package/dist/storage/database/schemas.d.ts.map +1 -1
- package/dist/storage/database/schemas.js +4 -1
- package/dist/storage/error-codes.cjs +6 -0
- package/dist/storage/error-codes.d.ts +7 -1
- package/dist/storage/error-codes.d.ts.map +1 -1
- package/dist/storage/error-codes.js +6 -0
- package/dist/storage/errors.cjs +80 -0
- package/dist/storage/errors.d.ts +24 -0
- package/dist/storage/errors.d.ts.map +1 -1
- package/dist/storage/errors.js +80 -0
- package/dist/storage/index.cjs +47 -4
- package/dist/storage/index.d.ts +34 -8
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +32 -3
- package/dist/storage/schemas.cjs +4 -0
- package/dist/storage/schemas.d.ts +17 -50
- package/dist/storage/schemas.d.ts.map +1 -1
- package/dist/storage/schemas.js +5 -1
- package/dist/storage/storage-manager.cjs +6 -6
- package/dist/storage/storage-manager.d.ts.map +1 -1
- package/dist/storage/storage-manager.js +3 -3
- package/dist/systemPrompt/in-built-prompts.cjs +7 -6
- package/dist/systemPrompt/in-built-prompts.d.ts +2 -2
- package/dist/systemPrompt/in-built-prompts.d.ts.map +1 -1
- package/dist/systemPrompt/in-built-prompts.js +6 -5
- package/dist/systemPrompt/registry.cjs +2 -2
- package/dist/systemPrompt/registry.d.ts +1 -1
- package/dist/systemPrompt/registry.d.ts.map +1 -1
- package/dist/systemPrompt/registry.js +2 -2
- package/dist/systemPrompt/schemas.cjs +2 -2
- package/dist/systemPrompt/schemas.d.ts +13 -13
- package/dist/systemPrompt/schemas.js +2 -2
- package/dist/tools/custom-tool-registry.cjs +64 -0
- package/dist/tools/custom-tool-registry.d.ts +120 -0
- package/dist/tools/custom-tool-registry.d.ts.map +1 -0
- package/dist/tools/custom-tool-registry.js +40 -0
- package/dist/tools/custom-tool-schema-registry.cjs +164 -0
- package/dist/tools/custom-tool-schema-registry.d.ts +86 -0
- package/dist/tools/custom-tool-schema-registry.d.ts.map +1 -0
- package/dist/tools/custom-tool-schema-registry.js +140 -0
- package/dist/tools/error-codes.cjs +3 -0
- package/dist/tools/error-codes.d.ts +4 -1
- package/dist/tools/error-codes.d.ts.map +1 -1
- package/dist/tools/error-codes.js +3 -0
- package/dist/tools/errors.cjs +41 -0
- package/dist/tools/errors.d.ts +17 -0
- package/dist/tools/errors.d.ts.map +1 -1
- package/dist/tools/errors.js +41 -0
- package/dist/tools/index.cjs +13 -1
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +11 -1
- package/dist/tools/internal-tools/constants.cjs +3 -9
- package/dist/tools/internal-tools/constants.d.ts +1 -1
- package/dist/tools/internal-tools/constants.d.ts.map +1 -1
- package/dist/tools/internal-tools/constants.js +3 -9
- package/dist/tools/internal-tools/implementations/get-resource-tool.cjs +113 -0
- package/dist/tools/internal-tools/implementations/get-resource-tool.d.ts +30 -0
- package/dist/tools/internal-tools/implementations/get-resource-tool.d.ts.map +1 -0
- package/dist/tools/internal-tools/implementations/get-resource-tool.js +90 -0
- package/dist/tools/internal-tools/implementations/list-resources-tool.cjs +91 -0
- package/dist/tools/internal-tools/implementations/list-resources-tool.d.ts +24 -0
- package/dist/tools/internal-tools/implementations/list-resources-tool.d.ts.map +1 -0
- package/dist/tools/internal-tools/implementations/list-resources-tool.js +68 -0
- package/dist/tools/internal-tools/provider.cjs +150 -23
- package/dist/tools/internal-tools/provider.d.ts +55 -10
- package/dist/tools/internal-tools/provider.d.ts.map +1 -1
- package/dist/tools/internal-tools/provider.js +150 -23
- package/dist/tools/internal-tools/registry.cjs +18 -43
- package/dist/tools/internal-tools/registry.d.ts +4 -4
- package/dist/tools/internal-tools/registry.d.ts.map +1 -1
- package/dist/tools/internal-tools/registry.js +18 -43
- package/dist/tools/schemas.cjs +20 -0
- package/dist/tools/schemas.d.ts +43 -1
- package/dist/tools/schemas.d.ts.map +1 -1
- package/dist/tools/schemas.js +16 -0
- package/dist/tools/tool-manager.cjs +140 -13
- package/dist/tools/tool-manager.d.ts +22 -3
- package/dist/tools/tool-manager.d.ts.map +1 -1
- package/dist/tools/tool-manager.js +140 -13
- package/dist/tools/types.d.ts +43 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/utils/api-key-resolver.cjs +19 -1
- package/dist/utils/api-key-resolver.d.ts.map +1 -1
- package/dist/utils/api-key-resolver.js +19 -1
- package/dist/utils/index.cjs +0 -2
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/redactor.cjs +18 -3
- package/dist/utils/redactor.d.ts +0 -7
- package/dist/utils/redactor.d.ts.map +1 -1
- package/dist/utils/redactor.js +18 -3
- package/dist/utils/service-initializer.cjs +9 -35
- package/dist/utils/service-initializer.d.ts.map +1 -1
- package/dist/utils/service-initializer.js +9 -35
- package/package.json +5 -2
- package/dist/context/compression/overflow.d.ts.map +0 -1
- package/dist/context/compression/reactive-overflow.d.ts.map +0 -1
- package/dist/context/compression/types.d.ts.map +0 -1
- package/dist/tools/internal-tools/implementations/bash-exec-tool.cjs +0 -130
- package/dist/tools/internal-tools/implementations/bash-exec-tool.d.ts +0 -13
- package/dist/tools/internal-tools/implementations/bash-exec-tool.d.ts.map +0 -1
- package/dist/tools/internal-tools/implementations/bash-exec-tool.js +0 -97
- package/dist/tools/internal-tools/implementations/bash-output-tool.cjs +0 -49
- package/dist/tools/internal-tools/implementations/bash-output-tool.d.ts +0 -12
- package/dist/tools/internal-tools/implementations/bash-output-tool.d.ts.map +0 -1
- package/dist/tools/internal-tools/implementations/bash-output-tool.js +0 -26
- package/dist/tools/internal-tools/implementations/edit-file-tool.cjs +0 -127
- package/dist/tools/internal-tools/implementations/edit-file-tool.d.ts +0 -12
- package/dist/tools/internal-tools/implementations/edit-file-tool.d.ts.map +0 -1
- package/dist/tools/internal-tools/implementations/edit-file-tool.js +0 -104
- package/dist/tools/internal-tools/implementations/glob-files-tool.cjs +0 -70
- package/dist/tools/internal-tools/implementations/glob-files-tool.d.ts +0 -12
- package/dist/tools/internal-tools/implementations/glob-files-tool.d.ts.map +0 -1
- package/dist/tools/internal-tools/implementations/glob-files-tool.js +0 -47
- package/dist/tools/internal-tools/implementations/grep-content-tool.cjs +0 -86
- package/dist/tools/internal-tools/implementations/grep-content-tool.d.ts +0 -12
- package/dist/tools/internal-tools/implementations/grep-content-tool.d.ts.map +0 -1
- package/dist/tools/internal-tools/implementations/grep-content-tool.js +0 -63
- package/dist/tools/internal-tools/implementations/kill-process-tool.cjs +0 -47
- package/dist/tools/internal-tools/implementations/kill-process-tool.d.ts +0 -12
- package/dist/tools/internal-tools/implementations/kill-process-tool.d.ts.map +0 -1
- package/dist/tools/internal-tools/implementations/kill-process-tool.js +0 -24
- package/dist/tools/internal-tools/implementations/read-file-tool.cjs +0 -63
- package/dist/tools/internal-tools/implementations/read-file-tool.d.ts +0 -12
- package/dist/tools/internal-tools/implementations/read-file-tool.d.ts.map +0 -1
- package/dist/tools/internal-tools/implementations/read-file-tool.js +0 -40
- package/dist/tools/internal-tools/implementations/write-file-tool.cjs +0 -124
- package/dist/tools/internal-tools/implementations/write-file-tool.d.ts +0 -12
- package/dist/tools/internal-tools/implementations/write-file-tool.d.ts.map +0 -1
- package/dist/tools/internal-tools/implementations/write-file-tool.js +0 -103
- package/dist/utils/env-file.cjs +0 -118
- package/dist/utils/env-file.d.ts +0 -5
- package/dist/utils/env-file.d.ts.map +0 -1
- package/dist/utils/env-file.js +0 -85
- /package/dist/context/{compression/types.js → compaction/provider.js} +0 -0
- /package/dist/context/{compression → compaction}/types.cjs +0 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import "../../../chunk-PTJYTZNU.js";
|
|
2
|
+
export * from "./types.js";
|
|
3
|
+
import { LocalModelErrorCode } from "./error-codes.js";
|
|
4
|
+
import { LocalModelError } from "./errors.js";
|
|
5
|
+
import {
|
|
6
|
+
GPUBackendSchema,
|
|
7
|
+
QuantizationTypeSchema,
|
|
8
|
+
LocalModelCategorySchema,
|
|
9
|
+
ModelSourceSchema,
|
|
10
|
+
ModelDownloadStatusSchema,
|
|
11
|
+
LocalModelInfoSchema,
|
|
12
|
+
ModelDownloadProgressSchema,
|
|
13
|
+
GPUInfoSchema,
|
|
14
|
+
LocalLLMConfigSchema,
|
|
15
|
+
InstalledModelSchema,
|
|
16
|
+
ModelStateSchema,
|
|
17
|
+
ModelDownloadOptionsSchema,
|
|
18
|
+
OllamaModelInfoSchema,
|
|
19
|
+
OllamaStatusSchema
|
|
20
|
+
} from "./schemas.js";
|
|
21
|
+
import {
|
|
22
|
+
LOCAL_MODEL_REGISTRY,
|
|
23
|
+
getAllLocalModels,
|
|
24
|
+
getLocalModelById,
|
|
25
|
+
getLocalModelsByCategory,
|
|
26
|
+
getRecommendedLocalModels,
|
|
27
|
+
getModelsForVRAM,
|
|
28
|
+
getModelsForRAM,
|
|
29
|
+
searchLocalModels,
|
|
30
|
+
getDefaultLocalModelId
|
|
31
|
+
} from "./registry.js";
|
|
32
|
+
import {
|
|
33
|
+
detectGPU,
|
|
34
|
+
formatGPUInfo,
|
|
35
|
+
isBackendAvailable,
|
|
36
|
+
getAvailableBackends
|
|
37
|
+
} from "./gpu-detector.js";
|
|
38
|
+
import {
|
|
39
|
+
downloadModel,
|
|
40
|
+
downloadModelFromUrl,
|
|
41
|
+
calculateFileHash,
|
|
42
|
+
checkDiskSpace,
|
|
43
|
+
validateDiskSpace,
|
|
44
|
+
cleanupPartialDownload,
|
|
45
|
+
isDownloadInProgress,
|
|
46
|
+
getPartialDownloadProgress
|
|
47
|
+
} from "./downloader.js";
|
|
48
|
+
import {
|
|
49
|
+
DEFAULT_OLLAMA_URL,
|
|
50
|
+
checkOllamaStatus,
|
|
51
|
+
listOllamaModels,
|
|
52
|
+
isOllamaModelAvailable,
|
|
53
|
+
pullOllamaModel,
|
|
54
|
+
createOllamaModel,
|
|
55
|
+
createValidatedOllamaModel,
|
|
56
|
+
getOllamaModelInfo,
|
|
57
|
+
deleteOllamaModel,
|
|
58
|
+
generateOllamaEmbeddings
|
|
59
|
+
} from "./ollama-provider.js";
|
|
60
|
+
import {
|
|
61
|
+
isNodeLlamaCppInstalled,
|
|
62
|
+
requireNodeLlamaCpp,
|
|
63
|
+
loadModel,
|
|
64
|
+
unloadModel,
|
|
65
|
+
unloadAllModels,
|
|
66
|
+
isModelLoaded,
|
|
67
|
+
getLoadedModelCount
|
|
68
|
+
} from "./node-llama-provider.js";
|
|
69
|
+
import { createLocalLanguageModel } from "./ai-sdk-adapter.js";
|
|
70
|
+
export {
|
|
71
|
+
DEFAULT_OLLAMA_URL,
|
|
72
|
+
GPUBackendSchema,
|
|
73
|
+
GPUInfoSchema,
|
|
74
|
+
InstalledModelSchema,
|
|
75
|
+
LOCAL_MODEL_REGISTRY,
|
|
76
|
+
LocalLLMConfigSchema,
|
|
77
|
+
LocalModelCategorySchema,
|
|
78
|
+
LocalModelError,
|
|
79
|
+
LocalModelErrorCode,
|
|
80
|
+
LocalModelInfoSchema,
|
|
81
|
+
ModelDownloadOptionsSchema,
|
|
82
|
+
ModelDownloadProgressSchema,
|
|
83
|
+
ModelDownloadStatusSchema,
|
|
84
|
+
ModelSourceSchema,
|
|
85
|
+
ModelStateSchema,
|
|
86
|
+
OllamaModelInfoSchema,
|
|
87
|
+
OllamaStatusSchema,
|
|
88
|
+
QuantizationTypeSchema,
|
|
89
|
+
calculateFileHash,
|
|
90
|
+
checkDiskSpace,
|
|
91
|
+
checkOllamaStatus,
|
|
92
|
+
cleanupPartialDownload,
|
|
93
|
+
createLocalLanguageModel,
|
|
94
|
+
createOllamaModel,
|
|
95
|
+
createValidatedOllamaModel,
|
|
96
|
+
deleteOllamaModel,
|
|
97
|
+
detectGPU,
|
|
98
|
+
downloadModel,
|
|
99
|
+
downloadModelFromUrl,
|
|
100
|
+
formatGPUInfo,
|
|
101
|
+
generateOllamaEmbeddings,
|
|
102
|
+
getAllLocalModels,
|
|
103
|
+
getAvailableBackends,
|
|
104
|
+
getDefaultLocalModelId,
|
|
105
|
+
getLoadedModelCount,
|
|
106
|
+
getLocalModelById,
|
|
107
|
+
getLocalModelsByCategory,
|
|
108
|
+
getModelsForRAM,
|
|
109
|
+
getModelsForVRAM,
|
|
110
|
+
getOllamaModelInfo,
|
|
111
|
+
getPartialDownloadProgress,
|
|
112
|
+
getRecommendedLocalModels,
|
|
113
|
+
isBackendAvailable,
|
|
114
|
+
isDownloadInProgress,
|
|
115
|
+
isModelLoaded,
|
|
116
|
+
isNodeLlamaCppInstalled,
|
|
117
|
+
isOllamaModelAvailable,
|
|
118
|
+
listOllamaModels,
|
|
119
|
+
loadModel,
|
|
120
|
+
pullOllamaModel,
|
|
121
|
+
requireNodeLlamaCpp,
|
|
122
|
+
searchLocalModels,
|
|
123
|
+
unloadAllModels,
|
|
124
|
+
unloadModel,
|
|
125
|
+
validateDiskSpace
|
|
126
|
+
};
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var node_llama_provider_exports = {};
|
|
30
|
+
__export(node_llama_provider_exports, {
|
|
31
|
+
getLoadedModelCount: () => getLoadedModelCount,
|
|
32
|
+
isModelLoaded: () => isModelLoaded,
|
|
33
|
+
isNodeLlamaCppInstalled: () => isNodeLlamaCppInstalled,
|
|
34
|
+
loadModel: () => loadModel,
|
|
35
|
+
requireNodeLlamaCpp: () => requireNodeLlamaCpp,
|
|
36
|
+
unloadAllModels: () => unloadAllModels,
|
|
37
|
+
unloadModel: () => unloadModel
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(node_llama_provider_exports);
|
|
40
|
+
var import_errors = require("./errors.js");
|
|
41
|
+
var import_gpu_detector = require("./gpu-detector.js");
|
|
42
|
+
var import_path = require("../../../utils/path.js");
|
|
43
|
+
var import_module = require("module");
|
|
44
|
+
var path = __toESM(require("path"), 1);
|
|
45
|
+
const import_meta = {};
|
|
46
|
+
function getGlobalNodeLlamaCppPath() {
|
|
47
|
+
return path.join((0, import_path.getDextoGlobalPath)("deps"), "node_modules", "node-llama-cpp");
|
|
48
|
+
}
|
|
49
|
+
async function isNodeLlamaCppInstalled() {
|
|
50
|
+
try {
|
|
51
|
+
await import("node-llama-cpp");
|
|
52
|
+
return true;
|
|
53
|
+
} catch {
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const globalPath = getGlobalNodeLlamaCppPath();
|
|
57
|
+
const require2 = (0, import_module.createRequire)(import_meta.url);
|
|
58
|
+
require2.resolve(globalPath);
|
|
59
|
+
return true;
|
|
60
|
+
} catch {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async function importNodeLlamaCpp() {
|
|
65
|
+
try {
|
|
66
|
+
return await import("node-llama-cpp");
|
|
67
|
+
} catch {
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
const globalPath = getGlobalNodeLlamaCppPath();
|
|
71
|
+
const entryPoint = path.join(globalPath, "dist", "index.js");
|
|
72
|
+
return await import(entryPoint);
|
|
73
|
+
} catch {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function requireNodeLlamaCpp() {
|
|
78
|
+
throw import_errors.LocalModelError.nodeLlamaNotInstalled();
|
|
79
|
+
}
|
|
80
|
+
const modelCache = /* @__PURE__ */ new Map();
|
|
81
|
+
async function loadModel(config) {
|
|
82
|
+
const { modelPath, gpuLayers = -1, contextSize, threads, batchSize = 512 } = config;
|
|
83
|
+
const cacheKey = `${modelPath}:${gpuLayers}:${contextSize}`;
|
|
84
|
+
const cached = modelCache.get(cacheKey);
|
|
85
|
+
if (cached) {
|
|
86
|
+
return cached;
|
|
87
|
+
}
|
|
88
|
+
const loadPromise = (async () => {
|
|
89
|
+
const nodeLlama = await importNodeLlamaCpp();
|
|
90
|
+
if (!nodeLlama) {
|
|
91
|
+
throw import_errors.LocalModelError.nodeLlamaNotInstalled();
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const gpuInfo = await (0, import_gpu_detector.detectGPU)();
|
|
95
|
+
const getLlama = nodeLlama["getLlama"];
|
|
96
|
+
const LlamaLogLevel = nodeLlama["LlamaLogLevel"];
|
|
97
|
+
const LlamaChatSession = nodeLlama["LlamaChatSession"];
|
|
98
|
+
const llama = await getLlama({
|
|
99
|
+
logLevel: LlamaLogLevel.warn,
|
|
100
|
+
gpu: gpuInfo.backend === "cpu" ? false : "auto"
|
|
101
|
+
});
|
|
102
|
+
const model = await llama.loadModel({
|
|
103
|
+
modelPath,
|
|
104
|
+
gpuLayers: gpuLayers === -1 ? "auto" : gpuLayers
|
|
105
|
+
});
|
|
106
|
+
const contextOptions = {
|
|
107
|
+
batchSize
|
|
108
|
+
};
|
|
109
|
+
if (contextSize !== void 0) {
|
|
110
|
+
contextOptions.contextSize = contextSize;
|
|
111
|
+
}
|
|
112
|
+
if (threads !== void 0) {
|
|
113
|
+
contextOptions.threads = threads;
|
|
114
|
+
}
|
|
115
|
+
const context = await model.createContext(contextOptions);
|
|
116
|
+
return {
|
|
117
|
+
modelPath,
|
|
118
|
+
gpuInfo,
|
|
119
|
+
async createSession() {
|
|
120
|
+
const session = new LlamaChatSession({
|
|
121
|
+
contextSequence: context.getSequence()
|
|
122
|
+
});
|
|
123
|
+
return {
|
|
124
|
+
async prompt(text, options = {}) {
|
|
125
|
+
const {
|
|
126
|
+
maxTokens = 1024,
|
|
127
|
+
temperature = 0.7,
|
|
128
|
+
topP = 0.9,
|
|
129
|
+
signal,
|
|
130
|
+
onToken
|
|
131
|
+
} = options;
|
|
132
|
+
const promptOptions = {
|
|
133
|
+
maxTokens,
|
|
134
|
+
temperature,
|
|
135
|
+
topP,
|
|
136
|
+
stopOnAbortSignal: true,
|
|
137
|
+
trimWhitespaceSuffix: true
|
|
138
|
+
};
|
|
139
|
+
if (signal) {
|
|
140
|
+
promptOptions.signal = signal;
|
|
141
|
+
}
|
|
142
|
+
if (onToken) {
|
|
143
|
+
promptOptions.onTextChunk = onToken;
|
|
144
|
+
}
|
|
145
|
+
const response = await session.prompt(text, promptOptions);
|
|
146
|
+
return response;
|
|
147
|
+
},
|
|
148
|
+
async dispose() {
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
},
|
|
152
|
+
async dispose() {
|
|
153
|
+
await context.dispose();
|
|
154
|
+
await model.dispose();
|
|
155
|
+
modelCache.delete(cacheKey);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
} catch (error) {
|
|
159
|
+
modelCache.delete(cacheKey);
|
|
160
|
+
if (error instanceof Error && "code" in error) {
|
|
161
|
+
throw error;
|
|
162
|
+
}
|
|
163
|
+
throw import_errors.LocalModelError.modelLoadFailed(
|
|
164
|
+
modelPath,
|
|
165
|
+
error instanceof Error ? error.message : String(error)
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
})();
|
|
169
|
+
modelCache.set(cacheKey, loadPromise);
|
|
170
|
+
return loadPromise;
|
|
171
|
+
}
|
|
172
|
+
async function unloadModel(modelPath) {
|
|
173
|
+
for (const [key, loadPromise] of modelCache.entries()) {
|
|
174
|
+
const keyModelPath = key.split(":")[0];
|
|
175
|
+
if (keyModelPath === modelPath) {
|
|
176
|
+
try {
|
|
177
|
+
const loaded = await loadPromise;
|
|
178
|
+
await loaded.dispose();
|
|
179
|
+
} catch {
|
|
180
|
+
}
|
|
181
|
+
modelCache.delete(key);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
async function unloadAllModels() {
|
|
186
|
+
for (const [key, loadPromise] of modelCache.entries()) {
|
|
187
|
+
try {
|
|
188
|
+
const loaded = await loadPromise;
|
|
189
|
+
await loaded.dispose();
|
|
190
|
+
} catch {
|
|
191
|
+
}
|
|
192
|
+
modelCache.delete(key);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function isModelLoaded(modelPath) {
|
|
196
|
+
for (const key of modelCache.keys()) {
|
|
197
|
+
const keyModelPath = key.split(":")[0];
|
|
198
|
+
if (keyModelPath === modelPath) {
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
function getLoadedModelCount() {
|
|
205
|
+
return modelCache.size;
|
|
206
|
+
}
|
|
207
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
208
|
+
0 && (module.exports = {
|
|
209
|
+
getLoadedModelCount,
|
|
210
|
+
isModelLoaded,
|
|
211
|
+
isNodeLlamaCppInstalled,
|
|
212
|
+
loadModel,
|
|
213
|
+
requireNodeLlamaCpp,
|
|
214
|
+
unloadAllModels,
|
|
215
|
+
unloadModel
|
|
216
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* node-llama-cpp provider for native local model execution.
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities for loading and using GGUF models via node-llama-cpp.
|
|
5
|
+
* Since node-llama-cpp is an optional dependency, all functions handle the case
|
|
6
|
+
* where it's not installed gracefully.
|
|
7
|
+
*
|
|
8
|
+
* For Vercel AI SDK integration, we recommend using Ollama which provides
|
|
9
|
+
* an OpenAI-compatible API that works seamlessly with the SDK.
|
|
10
|
+
*/
|
|
11
|
+
import type { GPUInfo } from './types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Check if node-llama-cpp is installed.
|
|
14
|
+
* Checks both standard node resolution (for dev/projects) and global deps (~/.dexto/deps).
|
|
15
|
+
*/
|
|
16
|
+
export declare function isNodeLlamaCppInstalled(): Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* Throws an error indicating node-llama-cpp needs to be installed.
|
|
19
|
+
*/
|
|
20
|
+
export declare function requireNodeLlamaCpp(): never;
|
|
21
|
+
/**
|
|
22
|
+
* Configuration for the node-llama-cpp model.
|
|
23
|
+
*/
|
|
24
|
+
export interface NodeLlamaConfig {
|
|
25
|
+
/** Path to the .gguf model file */
|
|
26
|
+
modelPath: string;
|
|
27
|
+
/** Number of GPU layers to offload (-1 = all, 0 = CPU only) */
|
|
28
|
+
gpuLayers?: number;
|
|
29
|
+
/** Context window size */
|
|
30
|
+
contextSize?: number;
|
|
31
|
+
/** Number of CPU threads */
|
|
32
|
+
threads?: number;
|
|
33
|
+
/** Batch size for inference */
|
|
34
|
+
batchSize?: number;
|
|
35
|
+
/** Whether to use Flash Attention (if available) */
|
|
36
|
+
flashAttention?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Model session interface for node-llama-cpp.
|
|
40
|
+
* This provides a simplified interface for text generation.
|
|
41
|
+
*/
|
|
42
|
+
export interface ModelSession {
|
|
43
|
+
/** Generate a response from a prompt */
|
|
44
|
+
prompt(text: string, options?: {
|
|
45
|
+
maxTokens?: number;
|
|
46
|
+
temperature?: number;
|
|
47
|
+
topP?: number;
|
|
48
|
+
signal?: AbortSignal;
|
|
49
|
+
onToken?: (token: string) => void;
|
|
50
|
+
}): Promise<string>;
|
|
51
|
+
/** Dispose the session and free resources */
|
|
52
|
+
dispose(): Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Loaded model interface.
|
|
56
|
+
*/
|
|
57
|
+
export interface LoadedModel {
|
|
58
|
+
/** Model file path */
|
|
59
|
+
modelPath: string;
|
|
60
|
+
/** GPU info used for loading */
|
|
61
|
+
gpuInfo: GPUInfo;
|
|
62
|
+
/** Create a new chat session */
|
|
63
|
+
createSession(): Promise<ModelSession>;
|
|
64
|
+
/** Dispose the model and free resources */
|
|
65
|
+
dispose(): Promise<void>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Load a GGUF model using node-llama-cpp.
|
|
69
|
+
*
|
|
70
|
+
* @throws {DextoRuntimeError} If node-llama-cpp is not installed
|
|
71
|
+
*/
|
|
72
|
+
export declare function loadModel(config: NodeLlamaConfig): Promise<LoadedModel>;
|
|
73
|
+
/**
|
|
74
|
+
* Unload a model and free resources.
|
|
75
|
+
* Removes all cache entries for the given model path (across different configs).
|
|
76
|
+
*/
|
|
77
|
+
export declare function unloadModel(modelPath: string): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Unload all models and free resources.
|
|
80
|
+
*/
|
|
81
|
+
export declare function unloadAllModels(): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Check if a model is currently loaded.
|
|
84
|
+
*/
|
|
85
|
+
export declare function isModelLoaded(modelPath: string): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Get the number of currently loaded models.
|
|
88
|
+
*/
|
|
89
|
+
export declare function getLoadedModelCount(): number;
|
|
90
|
+
//# sourceMappingURL=node-llama-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-llama-provider.d.ts","sourceRoot":"","sources":["../../../../src/llm/providers/local/node-llama-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAc1C;;;GAGG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,OAAO,CAAC,CAmBhE;AA6BD;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,KAAK,CAE3C;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,+DAA+D;IAC/D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0BAA0B;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4BAA4B;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+BAA+B;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,cAAc,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IACzB,wCAAwC;IACxC,MAAM,CACF,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;QACN,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,WAAW,CAAC;QACrB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;KACrC,GACF,OAAO,CAAC,MAAM,CAAC,CAAC;IAEnB,6CAA6C;IAC7C,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,sBAAsB;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,gCAAgC;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,gCAAgC;IAChC,aAAa,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC;IACvC,2CAA2C;IAC3C,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAKD;;;;GAIG;AACH,wBAAsB,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC,CAuJ7E;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAclE;AAED;;GAEG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAUrD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CASxD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import "../../../chunk-PTJYTZNU.js";
|
|
2
|
+
import { LocalModelError } from "./errors.js";
|
|
3
|
+
import { detectGPU } from "./gpu-detector.js";
|
|
4
|
+
import { getDextoGlobalPath } from "../../../utils/path.js";
|
|
5
|
+
import { createRequire } from "module";
|
|
6
|
+
import * as path from "path";
|
|
7
|
+
function getGlobalNodeLlamaCppPath() {
|
|
8
|
+
return path.join(getDextoGlobalPath("deps"), "node_modules", "node-llama-cpp");
|
|
9
|
+
}
|
|
10
|
+
async function isNodeLlamaCppInstalled() {
|
|
11
|
+
try {
|
|
12
|
+
await import("node-llama-cpp");
|
|
13
|
+
return true;
|
|
14
|
+
} catch {
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
const globalPath = getGlobalNodeLlamaCppPath();
|
|
18
|
+
const require2 = createRequire(import.meta.url);
|
|
19
|
+
require2.resolve(globalPath);
|
|
20
|
+
return true;
|
|
21
|
+
} catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function importNodeLlamaCpp() {
|
|
26
|
+
try {
|
|
27
|
+
return await import("node-llama-cpp");
|
|
28
|
+
} catch {
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const globalPath = getGlobalNodeLlamaCppPath();
|
|
32
|
+
const entryPoint = path.join(globalPath, "dist", "index.js");
|
|
33
|
+
return await import(entryPoint);
|
|
34
|
+
} catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function requireNodeLlamaCpp() {
|
|
39
|
+
throw LocalModelError.nodeLlamaNotInstalled();
|
|
40
|
+
}
|
|
41
|
+
const modelCache = /* @__PURE__ */ new Map();
|
|
42
|
+
async function loadModel(config) {
|
|
43
|
+
const { modelPath, gpuLayers = -1, contextSize, threads, batchSize = 512 } = config;
|
|
44
|
+
const cacheKey = `${modelPath}:${gpuLayers}:${contextSize}`;
|
|
45
|
+
const cached = modelCache.get(cacheKey);
|
|
46
|
+
if (cached) {
|
|
47
|
+
return cached;
|
|
48
|
+
}
|
|
49
|
+
const loadPromise = (async () => {
|
|
50
|
+
const nodeLlama = await importNodeLlamaCpp();
|
|
51
|
+
if (!nodeLlama) {
|
|
52
|
+
throw LocalModelError.nodeLlamaNotInstalled();
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
const gpuInfo = await detectGPU();
|
|
56
|
+
const getLlama = nodeLlama["getLlama"];
|
|
57
|
+
const LlamaLogLevel = nodeLlama["LlamaLogLevel"];
|
|
58
|
+
const LlamaChatSession = nodeLlama["LlamaChatSession"];
|
|
59
|
+
const llama = await getLlama({
|
|
60
|
+
logLevel: LlamaLogLevel.warn,
|
|
61
|
+
gpu: gpuInfo.backend === "cpu" ? false : "auto"
|
|
62
|
+
});
|
|
63
|
+
const model = await llama.loadModel({
|
|
64
|
+
modelPath,
|
|
65
|
+
gpuLayers: gpuLayers === -1 ? "auto" : gpuLayers
|
|
66
|
+
});
|
|
67
|
+
const contextOptions = {
|
|
68
|
+
batchSize
|
|
69
|
+
};
|
|
70
|
+
if (contextSize !== void 0) {
|
|
71
|
+
contextOptions.contextSize = contextSize;
|
|
72
|
+
}
|
|
73
|
+
if (threads !== void 0) {
|
|
74
|
+
contextOptions.threads = threads;
|
|
75
|
+
}
|
|
76
|
+
const context = await model.createContext(contextOptions);
|
|
77
|
+
return {
|
|
78
|
+
modelPath,
|
|
79
|
+
gpuInfo,
|
|
80
|
+
async createSession() {
|
|
81
|
+
const session = new LlamaChatSession({
|
|
82
|
+
contextSequence: context.getSequence()
|
|
83
|
+
});
|
|
84
|
+
return {
|
|
85
|
+
async prompt(text, options = {}) {
|
|
86
|
+
const {
|
|
87
|
+
maxTokens = 1024,
|
|
88
|
+
temperature = 0.7,
|
|
89
|
+
topP = 0.9,
|
|
90
|
+
signal,
|
|
91
|
+
onToken
|
|
92
|
+
} = options;
|
|
93
|
+
const promptOptions = {
|
|
94
|
+
maxTokens,
|
|
95
|
+
temperature,
|
|
96
|
+
topP,
|
|
97
|
+
stopOnAbortSignal: true,
|
|
98
|
+
trimWhitespaceSuffix: true
|
|
99
|
+
};
|
|
100
|
+
if (signal) {
|
|
101
|
+
promptOptions.signal = signal;
|
|
102
|
+
}
|
|
103
|
+
if (onToken) {
|
|
104
|
+
promptOptions.onTextChunk = onToken;
|
|
105
|
+
}
|
|
106
|
+
const response = await session.prompt(text, promptOptions);
|
|
107
|
+
return response;
|
|
108
|
+
},
|
|
109
|
+
async dispose() {
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
},
|
|
113
|
+
async dispose() {
|
|
114
|
+
await context.dispose();
|
|
115
|
+
await model.dispose();
|
|
116
|
+
modelCache.delete(cacheKey);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
} catch (error) {
|
|
120
|
+
modelCache.delete(cacheKey);
|
|
121
|
+
if (error instanceof Error && "code" in error) {
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
throw LocalModelError.modelLoadFailed(
|
|
125
|
+
modelPath,
|
|
126
|
+
error instanceof Error ? error.message : String(error)
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
})();
|
|
130
|
+
modelCache.set(cacheKey, loadPromise);
|
|
131
|
+
return loadPromise;
|
|
132
|
+
}
|
|
133
|
+
async function unloadModel(modelPath) {
|
|
134
|
+
for (const [key, loadPromise] of modelCache.entries()) {
|
|
135
|
+
const keyModelPath = key.split(":")[0];
|
|
136
|
+
if (keyModelPath === modelPath) {
|
|
137
|
+
try {
|
|
138
|
+
const loaded = await loadPromise;
|
|
139
|
+
await loaded.dispose();
|
|
140
|
+
} catch {
|
|
141
|
+
}
|
|
142
|
+
modelCache.delete(key);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
async function unloadAllModels() {
|
|
147
|
+
for (const [key, loadPromise] of modelCache.entries()) {
|
|
148
|
+
try {
|
|
149
|
+
const loaded = await loadPromise;
|
|
150
|
+
await loaded.dispose();
|
|
151
|
+
} catch {
|
|
152
|
+
}
|
|
153
|
+
modelCache.delete(key);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function isModelLoaded(modelPath) {
|
|
157
|
+
for (const key of modelCache.keys()) {
|
|
158
|
+
const keyModelPath = key.split(":")[0];
|
|
159
|
+
if (keyModelPath === modelPath) {
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
function getLoadedModelCount() {
|
|
166
|
+
return modelCache.size;
|
|
167
|
+
}
|
|
168
|
+
export {
|
|
169
|
+
getLoadedModelCount,
|
|
170
|
+
isModelLoaded,
|
|
171
|
+
isNodeLlamaCppInstalled,
|
|
172
|
+
loadModel,
|
|
173
|
+
requireNodeLlamaCpp,
|
|
174
|
+
unloadAllModels,
|
|
175
|
+
unloadModel
|
|
176
|
+
};
|