@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,308 @@
|
|
|
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 ai_sdk_adapter_exports = {};
|
|
30
|
+
__export(ai_sdk_adapter_exports, {
|
|
31
|
+
createLocalLanguageModel: () => createLocalLanguageModel
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(ai_sdk_adapter_exports);
|
|
34
|
+
var import_node_llama_provider = require("./node-llama-provider.js");
|
|
35
|
+
var import_errors = require("./errors.js");
|
|
36
|
+
var import_registry = require("./registry.js");
|
|
37
|
+
var fs = __toESM(require("fs"), 1);
|
|
38
|
+
var path = __toESM(require("path"), 1);
|
|
39
|
+
var os = __toESM(require("os"), 1);
|
|
40
|
+
function getModelsDirectory() {
|
|
41
|
+
return path.join(os.homedir(), ".dexto", "models");
|
|
42
|
+
}
|
|
43
|
+
function getInstalledModelInfo(modelId) {
|
|
44
|
+
const stateFile = path.join(getModelsDirectory(), "state.json");
|
|
45
|
+
try {
|
|
46
|
+
if (!fs.existsSync(stateFile)) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const content = fs.readFileSync(stateFile, "utf-8");
|
|
50
|
+
const state = JSON.parse(content);
|
|
51
|
+
return state.installed[modelId] ?? null;
|
|
52
|
+
} catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function getCustomModelFilePath(modelId) {
|
|
57
|
+
const customModelsFile = path.join(getModelsDirectory(), "custom-models.json");
|
|
58
|
+
try {
|
|
59
|
+
if (!fs.existsSync(customModelsFile)) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const content = fs.readFileSync(customModelsFile, "utf-8");
|
|
63
|
+
const storage = JSON.parse(content);
|
|
64
|
+
const customModel = storage.models.find(
|
|
65
|
+
(m) => m.name === modelId && m.provider === "local" && m.filePath
|
|
66
|
+
);
|
|
67
|
+
return customModel?.filePath ?? null;
|
|
68
|
+
} catch {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function createLocalLanguageModel(config) {
|
|
73
|
+
return new LocalLanguageModel(config);
|
|
74
|
+
}
|
|
75
|
+
class LocalLanguageModel {
|
|
76
|
+
specificationVersion = "v2";
|
|
77
|
+
provider = "local";
|
|
78
|
+
modelId;
|
|
79
|
+
// Local models don't support URL-based content natively
|
|
80
|
+
supportedUrls = {};
|
|
81
|
+
config;
|
|
82
|
+
session = null;
|
|
83
|
+
loadedModel = null;
|
|
84
|
+
initPromise = null;
|
|
85
|
+
deviceName = "Local";
|
|
86
|
+
constructor(config) {
|
|
87
|
+
this.modelId = config.modelId;
|
|
88
|
+
this.config = config;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Initialize the model lazily on first use.
|
|
92
|
+
*/
|
|
93
|
+
async ensureInitialized() {
|
|
94
|
+
if (this.session) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (this.initPromise) {
|
|
98
|
+
return this.initPromise;
|
|
99
|
+
}
|
|
100
|
+
this.initPromise = this.initialize();
|
|
101
|
+
return this.initPromise;
|
|
102
|
+
}
|
|
103
|
+
async initialize() {
|
|
104
|
+
const {
|
|
105
|
+
modelId,
|
|
106
|
+
modelPath: directPath,
|
|
107
|
+
contextSize,
|
|
108
|
+
// Let node-llama-cpp default to "auto" if not specified
|
|
109
|
+
gpuLayers = -1,
|
|
110
|
+
threads
|
|
111
|
+
} = this.config;
|
|
112
|
+
const isInstalled = await (0, import_node_llama_provider.isNodeLlamaCppInstalled)();
|
|
113
|
+
if (!isInstalled) {
|
|
114
|
+
throw import_errors.LocalModelError.nodeLlamaNotInstalled();
|
|
115
|
+
}
|
|
116
|
+
let modelPath;
|
|
117
|
+
if (directPath) {
|
|
118
|
+
modelPath = directPath;
|
|
119
|
+
} else {
|
|
120
|
+
const installedModel = getInstalledModelInfo(modelId);
|
|
121
|
+
if (installedModel) {
|
|
122
|
+
modelPath = installedModel.filePath;
|
|
123
|
+
} else {
|
|
124
|
+
const customPath = getCustomModelFilePath(modelId);
|
|
125
|
+
if (customPath) {
|
|
126
|
+
modelPath = customPath;
|
|
127
|
+
} else {
|
|
128
|
+
const registryModel = (0, import_registry.getLocalModelById)(modelId);
|
|
129
|
+
if (!registryModel) {
|
|
130
|
+
throw import_errors.LocalModelError.modelNotFound(modelId);
|
|
131
|
+
}
|
|
132
|
+
throw import_errors.LocalModelError.modelNotDownloaded(modelId);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const loadConfig = {
|
|
137
|
+
modelPath,
|
|
138
|
+
gpuLayers
|
|
139
|
+
};
|
|
140
|
+
if (contextSize !== void 0) {
|
|
141
|
+
loadConfig.contextSize = contextSize;
|
|
142
|
+
}
|
|
143
|
+
if (threads !== void 0) {
|
|
144
|
+
loadConfig.threads = threads;
|
|
145
|
+
}
|
|
146
|
+
this.loadedModel = await (0, import_node_llama_provider.loadModel)(loadConfig);
|
|
147
|
+
this.deviceName = this.loadedModel.gpuInfo.deviceName || "Local";
|
|
148
|
+
this.session = await this.loadedModel.createSession();
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Non-streaming text generation (V2 interface).
|
|
152
|
+
*/
|
|
153
|
+
async doGenerate(options) {
|
|
154
|
+
await this.ensureInitialized();
|
|
155
|
+
const prompt = this.formatPrompt(options);
|
|
156
|
+
const maxTokens = options.maxOutputTokens ?? 1024;
|
|
157
|
+
const temperature = options.temperature ?? 0.7;
|
|
158
|
+
const promptOptions = {
|
|
159
|
+
maxTokens,
|
|
160
|
+
temperature
|
|
161
|
+
};
|
|
162
|
+
if (options.abortSignal) {
|
|
163
|
+
promptOptions.signal = options.abortSignal;
|
|
164
|
+
}
|
|
165
|
+
const response = await this.session.prompt(prompt, promptOptions);
|
|
166
|
+
const inputTokens = Math.ceil(prompt.length / 4);
|
|
167
|
+
const outputTokens = Math.ceil(response.length / 4);
|
|
168
|
+
const content = [{ type: "text", text: response }];
|
|
169
|
+
const finishReason = "stop";
|
|
170
|
+
const usage = {
|
|
171
|
+
inputTokens,
|
|
172
|
+
outputTokens,
|
|
173
|
+
totalTokens: inputTokens + outputTokens
|
|
174
|
+
};
|
|
175
|
+
const warnings = [];
|
|
176
|
+
return {
|
|
177
|
+
content,
|
|
178
|
+
finishReason,
|
|
179
|
+
usage,
|
|
180
|
+
providerMetadata: {
|
|
181
|
+
local: {
|
|
182
|
+
device: this.deviceName
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
warnings
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Streaming text generation (V2 interface).
|
|
190
|
+
*/
|
|
191
|
+
async doStream(options) {
|
|
192
|
+
await this.ensureInitialized();
|
|
193
|
+
const prompt = this.formatPrompt(options);
|
|
194
|
+
const maxTokens = options.maxOutputTokens ?? 1024;
|
|
195
|
+
const temperature = options.temperature ?? 0.7;
|
|
196
|
+
const inputTokens = Math.ceil(prompt.length / 4);
|
|
197
|
+
let outputTokens = 0;
|
|
198
|
+
const session = this.session;
|
|
199
|
+
const textId = "text-0";
|
|
200
|
+
const streamPromptOptions = {
|
|
201
|
+
maxTokens,
|
|
202
|
+
temperature,
|
|
203
|
+
onToken: (_token) => {
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
if (options.abortSignal) {
|
|
207
|
+
streamPromptOptions.signal = options.abortSignal;
|
|
208
|
+
}
|
|
209
|
+
let controller;
|
|
210
|
+
const stream = new ReadableStream({
|
|
211
|
+
async start(ctrl) {
|
|
212
|
+
controller = ctrl;
|
|
213
|
+
controller.enqueue({
|
|
214
|
+
type: "stream-start",
|
|
215
|
+
warnings: []
|
|
216
|
+
});
|
|
217
|
+
controller.enqueue({
|
|
218
|
+
type: "text-start",
|
|
219
|
+
id: textId
|
|
220
|
+
});
|
|
221
|
+
try {
|
|
222
|
+
streamPromptOptions.onToken = (token) => {
|
|
223
|
+
outputTokens += 1;
|
|
224
|
+
controller.enqueue({
|
|
225
|
+
type: "text-delta",
|
|
226
|
+
id: textId,
|
|
227
|
+
delta: token
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
await session.prompt(prompt, streamPromptOptions);
|
|
231
|
+
controller.enqueue({
|
|
232
|
+
type: "text-end",
|
|
233
|
+
id: textId
|
|
234
|
+
});
|
|
235
|
+
controller.enqueue({
|
|
236
|
+
type: "finish",
|
|
237
|
+
finishReason: "stop",
|
|
238
|
+
usage: {
|
|
239
|
+
inputTokens,
|
|
240
|
+
outputTokens,
|
|
241
|
+
totalTokens: inputTokens + outputTokens
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
controller.close();
|
|
245
|
+
} catch (error) {
|
|
246
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
247
|
+
controller.enqueue({
|
|
248
|
+
type: "text-end",
|
|
249
|
+
id: textId
|
|
250
|
+
});
|
|
251
|
+
controller.enqueue({
|
|
252
|
+
type: "finish",
|
|
253
|
+
finishReason: "stop",
|
|
254
|
+
usage: {
|
|
255
|
+
inputTokens,
|
|
256
|
+
outputTokens,
|
|
257
|
+
totalTokens: inputTokens + outputTokens
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
controller.close();
|
|
261
|
+
} else {
|
|
262
|
+
controller.enqueue({
|
|
263
|
+
type: "error",
|
|
264
|
+
error
|
|
265
|
+
});
|
|
266
|
+
controller.close();
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
return {
|
|
272
|
+
stream
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Format the prompt from AI SDK message format.
|
|
277
|
+
*/
|
|
278
|
+
formatPrompt(options) {
|
|
279
|
+
const parts = [];
|
|
280
|
+
if (options.prompt && Array.isArray(options.prompt)) {
|
|
281
|
+
for (const message of options.prompt) {
|
|
282
|
+
if (message.role === "system") {
|
|
283
|
+
parts.push(`System: ${message.content}`);
|
|
284
|
+
} else if (message.role === "user") {
|
|
285
|
+
if (Array.isArray(message.content)) {
|
|
286
|
+
const textParts = message.content.filter((p) => p.type === "text").map((p) => p.text);
|
|
287
|
+
if (textParts.length > 0) {
|
|
288
|
+
parts.push(`User: ${textParts.join("\n")}`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
} else if (message.role === "assistant") {
|
|
292
|
+
if (Array.isArray(message.content)) {
|
|
293
|
+
const textParts = message.content.filter((p) => p.type === "text").map((p) => p.text);
|
|
294
|
+
if (textParts.length > 0) {
|
|
295
|
+
parts.push(`Assistant: ${textParts.join("\n")}`);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
parts.push("Assistant:");
|
|
302
|
+
return parts.join("\n\n");
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
306
|
+
0 && (module.exports = {
|
|
307
|
+
createLocalLanguageModel
|
|
308
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vercel AI SDK adapter for node-llama-cpp.
|
|
3
|
+
*
|
|
4
|
+
* This module creates a LanguageModelV2 implementation that wraps node-llama-cpp,
|
|
5
|
+
* allowing local GGUF models to be used with the Vercel AI SDK.
|
|
6
|
+
*/
|
|
7
|
+
import type { LanguageModelV2 } from '@ai-sdk/provider';
|
|
8
|
+
/**
|
|
9
|
+
* Configuration for the local model AI SDK adapter.
|
|
10
|
+
*/
|
|
11
|
+
export interface LocalModelAdapterConfig {
|
|
12
|
+
/** Model ID from the local registry */
|
|
13
|
+
modelId: string;
|
|
14
|
+
/** Direct path to model file (optional, overrides modelId lookup) */
|
|
15
|
+
modelPath?: string;
|
|
16
|
+
/** Context window size (default: 4096) */
|
|
17
|
+
contextSize?: number;
|
|
18
|
+
/** Number of GPU layers to offload (-1 = all, 0 = CPU only) */
|
|
19
|
+
gpuLayers?: number;
|
|
20
|
+
/** Number of CPU threads */
|
|
21
|
+
threads?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Create a Vercel AI SDK compatible LanguageModelV2 from a local GGUF model.
|
|
25
|
+
* This is a synchronous function that returns a LanguageModel with lazy initialization.
|
|
26
|
+
* The actual model loading happens on first use.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createLocalLanguageModel(config: LocalModelAdapterConfig): LanguageModelV2;
|
|
29
|
+
//# sourceMappingURL=ai-sdk-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-sdk-adapter.d.ts","sourceRoot":"","sources":["../../../../src/llm/providers/local/ai-sdk-adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EACR,eAAe,EAOlB,MAAM,kBAAkB,CAAC;AAa1B;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACpC,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0CAA0C;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+DAA+D;IAC/D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4BAA4B;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AA+FD;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,uBAAuB,GAAG,eAAe,CAEzF"}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import "../../../chunk-PTJYTZNU.js";
|
|
2
|
+
import {
|
|
3
|
+
loadModel,
|
|
4
|
+
isNodeLlamaCppInstalled
|
|
5
|
+
} from "./node-llama-provider.js";
|
|
6
|
+
import { LocalModelError } from "./errors.js";
|
|
7
|
+
import { getLocalModelById } from "./registry.js";
|
|
8
|
+
import * as fs from "fs";
|
|
9
|
+
import * as path from "path";
|
|
10
|
+
import * as os from "os";
|
|
11
|
+
function getModelsDirectory() {
|
|
12
|
+
return path.join(os.homedir(), ".dexto", "models");
|
|
13
|
+
}
|
|
14
|
+
function getInstalledModelInfo(modelId) {
|
|
15
|
+
const stateFile = path.join(getModelsDirectory(), "state.json");
|
|
16
|
+
try {
|
|
17
|
+
if (!fs.existsSync(stateFile)) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const content = fs.readFileSync(stateFile, "utf-8");
|
|
21
|
+
const state = JSON.parse(content);
|
|
22
|
+
return state.installed[modelId] ?? null;
|
|
23
|
+
} catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function getCustomModelFilePath(modelId) {
|
|
28
|
+
const customModelsFile = path.join(getModelsDirectory(), "custom-models.json");
|
|
29
|
+
try {
|
|
30
|
+
if (!fs.existsSync(customModelsFile)) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
const content = fs.readFileSync(customModelsFile, "utf-8");
|
|
34
|
+
const storage = JSON.parse(content);
|
|
35
|
+
const customModel = storage.models.find(
|
|
36
|
+
(m) => m.name === modelId && m.provider === "local" && m.filePath
|
|
37
|
+
);
|
|
38
|
+
return customModel?.filePath ?? null;
|
|
39
|
+
} catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function createLocalLanguageModel(config) {
|
|
44
|
+
return new LocalLanguageModel(config);
|
|
45
|
+
}
|
|
46
|
+
class LocalLanguageModel {
|
|
47
|
+
specificationVersion = "v2";
|
|
48
|
+
provider = "local";
|
|
49
|
+
modelId;
|
|
50
|
+
// Local models don't support URL-based content natively
|
|
51
|
+
supportedUrls = {};
|
|
52
|
+
config;
|
|
53
|
+
session = null;
|
|
54
|
+
loadedModel = null;
|
|
55
|
+
initPromise = null;
|
|
56
|
+
deviceName = "Local";
|
|
57
|
+
constructor(config) {
|
|
58
|
+
this.modelId = config.modelId;
|
|
59
|
+
this.config = config;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Initialize the model lazily on first use.
|
|
63
|
+
*/
|
|
64
|
+
async ensureInitialized() {
|
|
65
|
+
if (this.session) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (this.initPromise) {
|
|
69
|
+
return this.initPromise;
|
|
70
|
+
}
|
|
71
|
+
this.initPromise = this.initialize();
|
|
72
|
+
return this.initPromise;
|
|
73
|
+
}
|
|
74
|
+
async initialize() {
|
|
75
|
+
const {
|
|
76
|
+
modelId,
|
|
77
|
+
modelPath: directPath,
|
|
78
|
+
contextSize,
|
|
79
|
+
// Let node-llama-cpp default to "auto" if not specified
|
|
80
|
+
gpuLayers = -1,
|
|
81
|
+
threads
|
|
82
|
+
} = this.config;
|
|
83
|
+
const isInstalled = await isNodeLlamaCppInstalled();
|
|
84
|
+
if (!isInstalled) {
|
|
85
|
+
throw LocalModelError.nodeLlamaNotInstalled();
|
|
86
|
+
}
|
|
87
|
+
let modelPath;
|
|
88
|
+
if (directPath) {
|
|
89
|
+
modelPath = directPath;
|
|
90
|
+
} else {
|
|
91
|
+
const installedModel = getInstalledModelInfo(modelId);
|
|
92
|
+
if (installedModel) {
|
|
93
|
+
modelPath = installedModel.filePath;
|
|
94
|
+
} else {
|
|
95
|
+
const customPath = getCustomModelFilePath(modelId);
|
|
96
|
+
if (customPath) {
|
|
97
|
+
modelPath = customPath;
|
|
98
|
+
} else {
|
|
99
|
+
const registryModel = getLocalModelById(modelId);
|
|
100
|
+
if (!registryModel) {
|
|
101
|
+
throw LocalModelError.modelNotFound(modelId);
|
|
102
|
+
}
|
|
103
|
+
throw LocalModelError.modelNotDownloaded(modelId);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const loadConfig = {
|
|
108
|
+
modelPath,
|
|
109
|
+
gpuLayers
|
|
110
|
+
};
|
|
111
|
+
if (contextSize !== void 0) {
|
|
112
|
+
loadConfig.contextSize = contextSize;
|
|
113
|
+
}
|
|
114
|
+
if (threads !== void 0) {
|
|
115
|
+
loadConfig.threads = threads;
|
|
116
|
+
}
|
|
117
|
+
this.loadedModel = await loadModel(loadConfig);
|
|
118
|
+
this.deviceName = this.loadedModel.gpuInfo.deviceName || "Local";
|
|
119
|
+
this.session = await this.loadedModel.createSession();
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Non-streaming text generation (V2 interface).
|
|
123
|
+
*/
|
|
124
|
+
async doGenerate(options) {
|
|
125
|
+
await this.ensureInitialized();
|
|
126
|
+
const prompt = this.formatPrompt(options);
|
|
127
|
+
const maxTokens = options.maxOutputTokens ?? 1024;
|
|
128
|
+
const temperature = options.temperature ?? 0.7;
|
|
129
|
+
const promptOptions = {
|
|
130
|
+
maxTokens,
|
|
131
|
+
temperature
|
|
132
|
+
};
|
|
133
|
+
if (options.abortSignal) {
|
|
134
|
+
promptOptions.signal = options.abortSignal;
|
|
135
|
+
}
|
|
136
|
+
const response = await this.session.prompt(prompt, promptOptions);
|
|
137
|
+
const inputTokens = Math.ceil(prompt.length / 4);
|
|
138
|
+
const outputTokens = Math.ceil(response.length / 4);
|
|
139
|
+
const content = [{ type: "text", text: response }];
|
|
140
|
+
const finishReason = "stop";
|
|
141
|
+
const usage = {
|
|
142
|
+
inputTokens,
|
|
143
|
+
outputTokens,
|
|
144
|
+
totalTokens: inputTokens + outputTokens
|
|
145
|
+
};
|
|
146
|
+
const warnings = [];
|
|
147
|
+
return {
|
|
148
|
+
content,
|
|
149
|
+
finishReason,
|
|
150
|
+
usage,
|
|
151
|
+
providerMetadata: {
|
|
152
|
+
local: {
|
|
153
|
+
device: this.deviceName
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
warnings
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Streaming text generation (V2 interface).
|
|
161
|
+
*/
|
|
162
|
+
async doStream(options) {
|
|
163
|
+
await this.ensureInitialized();
|
|
164
|
+
const prompt = this.formatPrompt(options);
|
|
165
|
+
const maxTokens = options.maxOutputTokens ?? 1024;
|
|
166
|
+
const temperature = options.temperature ?? 0.7;
|
|
167
|
+
const inputTokens = Math.ceil(prompt.length / 4);
|
|
168
|
+
let outputTokens = 0;
|
|
169
|
+
const session = this.session;
|
|
170
|
+
const textId = "text-0";
|
|
171
|
+
const streamPromptOptions = {
|
|
172
|
+
maxTokens,
|
|
173
|
+
temperature,
|
|
174
|
+
onToken: (_token) => {
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
if (options.abortSignal) {
|
|
178
|
+
streamPromptOptions.signal = options.abortSignal;
|
|
179
|
+
}
|
|
180
|
+
let controller;
|
|
181
|
+
const stream = new ReadableStream({
|
|
182
|
+
async start(ctrl) {
|
|
183
|
+
controller = ctrl;
|
|
184
|
+
controller.enqueue({
|
|
185
|
+
type: "stream-start",
|
|
186
|
+
warnings: []
|
|
187
|
+
});
|
|
188
|
+
controller.enqueue({
|
|
189
|
+
type: "text-start",
|
|
190
|
+
id: textId
|
|
191
|
+
});
|
|
192
|
+
try {
|
|
193
|
+
streamPromptOptions.onToken = (token) => {
|
|
194
|
+
outputTokens += 1;
|
|
195
|
+
controller.enqueue({
|
|
196
|
+
type: "text-delta",
|
|
197
|
+
id: textId,
|
|
198
|
+
delta: token
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
await session.prompt(prompt, streamPromptOptions);
|
|
202
|
+
controller.enqueue({
|
|
203
|
+
type: "text-end",
|
|
204
|
+
id: textId
|
|
205
|
+
});
|
|
206
|
+
controller.enqueue({
|
|
207
|
+
type: "finish",
|
|
208
|
+
finishReason: "stop",
|
|
209
|
+
usage: {
|
|
210
|
+
inputTokens,
|
|
211
|
+
outputTokens,
|
|
212
|
+
totalTokens: inputTokens + outputTokens
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
controller.close();
|
|
216
|
+
} catch (error) {
|
|
217
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
218
|
+
controller.enqueue({
|
|
219
|
+
type: "text-end",
|
|
220
|
+
id: textId
|
|
221
|
+
});
|
|
222
|
+
controller.enqueue({
|
|
223
|
+
type: "finish",
|
|
224
|
+
finishReason: "stop",
|
|
225
|
+
usage: {
|
|
226
|
+
inputTokens,
|
|
227
|
+
outputTokens,
|
|
228
|
+
totalTokens: inputTokens + outputTokens
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
controller.close();
|
|
232
|
+
} else {
|
|
233
|
+
controller.enqueue({
|
|
234
|
+
type: "error",
|
|
235
|
+
error
|
|
236
|
+
});
|
|
237
|
+
controller.close();
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
return {
|
|
243
|
+
stream
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Format the prompt from AI SDK message format.
|
|
248
|
+
*/
|
|
249
|
+
formatPrompt(options) {
|
|
250
|
+
const parts = [];
|
|
251
|
+
if (options.prompt && Array.isArray(options.prompt)) {
|
|
252
|
+
for (const message of options.prompt) {
|
|
253
|
+
if (message.role === "system") {
|
|
254
|
+
parts.push(`System: ${message.content}`);
|
|
255
|
+
} else if (message.role === "user") {
|
|
256
|
+
if (Array.isArray(message.content)) {
|
|
257
|
+
const textParts = message.content.filter((p) => p.type === "text").map((p) => p.text);
|
|
258
|
+
if (textParts.length > 0) {
|
|
259
|
+
parts.push(`User: ${textParts.join("\n")}`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
} else if (message.role === "assistant") {
|
|
263
|
+
if (Array.isArray(message.content)) {
|
|
264
|
+
const textParts = message.content.filter((p) => p.type === "text").map((p) => p.text);
|
|
265
|
+
if (textParts.length > 0) {
|
|
266
|
+
parts.push(`Assistant: ${textParts.join("\n")}`);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
parts.push("Assistant:");
|
|
273
|
+
return parts.join("\n\n");
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
export {
|
|
277
|
+
createLocalLanguageModel
|
|
278
|
+
};
|