@dexto/core 1.4.0 → 1.5.1
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 +5959 -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 +6 -3
- package/dist/events/index.d.ts +35 -19
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +5 -3
- 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/provider-options.cjs +87 -0
- package/dist/llm/executor/provider-options.d.ts +49 -0
- package/dist/llm/executor/provider-options.d.ts.map +1 -0
- package/dist/llm/executor/provider-options.js +63 -0
- package/dist/llm/executor/stream-processor.cjs +22 -11
- package/dist/llm/executor/stream-processor.d.ts.map +1 -1
- package/dist/llm/executor/stream-processor.js +22 -11
- package/dist/llm/executor/turn-executor.cjs +60 -23
- package/dist/llm/executor/turn-executor.d.ts +7 -5
- package/dist/llm/executor/turn-executor.d.ts.map +1 -1
- package/dist/llm/executor/turn-executor.js +60 -23
- package/dist/llm/formatters/vercel.cjs +15 -3
- package/dist/llm/formatters/vercel.d.ts.map +1 -1
- package/dist/llm/formatters/vercel.js +15 -3
- 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 +604 -9
- package/dist/llm/registry.d.ts +35 -0
- package/dist/llm/registry.d.ts.map +1 -1
- package/dist/llm/registry.js +600 -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 +107 -81
- package/dist/llm/schemas.d.ts +181 -22
- package/dist/llm/schemas.d.ts.map +1 -1
- package/dist/llm/schemas.js +107 -81
- 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 +8 -3
- 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 +8 -3
- 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/logger/logger.cjs +7 -3
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.js +7 -3
- 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 +3 -3
- 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 +109 -0
- package/dist/providers/discovery.d.ts +96 -0
- package/dist/providers/discovery.d.ts.map +1 -0
- package/dist/providers/discovery.js +84 -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/session/history/database.cjs +49 -15
- package/dist/session/history/database.d.ts.map +1 -1
- package/dist/session/history/database.js +49 -15
- package/dist/session/session-manager.cjs +2 -1
- package/dist/session/session-manager.d.ts.map +1 -1
- package/dist/session/session-manager.js +2 -1
- 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/postgres-store.cjs +174 -78
- package/dist/storage/database/postgres-store.d.ts +19 -0
- package/dist/storage/database/postgres-store.d.ts.map +1 -1
- package/dist/storage/database/postgres-store.js +174 -78
- 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 +12 -3
- package/dist/storage/database/schemas.d.ts +11 -4
- package/dist/storage/database/schemas.d.ts.map +1 -1
- package/dist/storage/database/schemas.js +8 -2
- 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 +24 -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 +126 -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 +153 -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 +153 -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,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
|
+
};
|
|
@@ -0,0 +1,291 @@
|
|
|
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 downloader_exports = {};
|
|
30
|
+
__export(downloader_exports, {
|
|
31
|
+
calculateFileHash: () => calculateFileHash,
|
|
32
|
+
checkDiskSpace: () => checkDiskSpace,
|
|
33
|
+
cleanupPartialDownload: () => cleanupPartialDownload,
|
|
34
|
+
downloadModel: () => downloadModel,
|
|
35
|
+
downloadModelFromUrl: () => downloadModelFromUrl,
|
|
36
|
+
getPartialDownloadProgress: () => getPartialDownloadProgress,
|
|
37
|
+
isDownloadInProgress: () => isDownloadInProgress,
|
|
38
|
+
validateDiskSpace: () => validateDiskSpace
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(downloader_exports);
|
|
41
|
+
var import_fs = require("fs");
|
|
42
|
+
var import_crypto = require("crypto");
|
|
43
|
+
var path = __toESM(require("path"), 1);
|
|
44
|
+
var import_errors = require("./errors.js");
|
|
45
|
+
var import_registry = require("./registry.js");
|
|
46
|
+
function buildHuggingFaceUrl(huggingfaceId, filename) {
|
|
47
|
+
return `https://huggingface.co/${huggingfaceId}/resolve/main/${filename}`;
|
|
48
|
+
}
|
|
49
|
+
async function getPartialSize(filePath) {
|
|
50
|
+
try {
|
|
51
|
+
const stats = await import_fs.promises.stat(filePath);
|
|
52
|
+
return stats.size;
|
|
53
|
+
} catch {
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async function calculateFileHash(filePath) {
|
|
58
|
+
return new Promise((resolve, reject) => {
|
|
59
|
+
const hash = (0, import_crypto.createHash)("sha256");
|
|
60
|
+
const stream = (0, import_fs.createReadStream)(filePath);
|
|
61
|
+
stream.on("data", (chunk) => hash.update(chunk));
|
|
62
|
+
stream.on("end", () => resolve(hash.digest("hex")));
|
|
63
|
+
stream.on("error", reject);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function createProgressEvent(modelId, status, bytesDownloaded, totalBytes, speed, eta, error) {
|
|
67
|
+
const progress = {
|
|
68
|
+
modelId,
|
|
69
|
+
status,
|
|
70
|
+
bytesDownloaded,
|
|
71
|
+
totalBytes,
|
|
72
|
+
percentage: totalBytes > 0 ? bytesDownloaded / totalBytes * 100 : 0
|
|
73
|
+
};
|
|
74
|
+
if (speed !== void 0) {
|
|
75
|
+
progress.speed = speed;
|
|
76
|
+
}
|
|
77
|
+
if (eta !== void 0) {
|
|
78
|
+
progress.eta = eta;
|
|
79
|
+
}
|
|
80
|
+
if (error !== void 0) {
|
|
81
|
+
progress.error = error;
|
|
82
|
+
}
|
|
83
|
+
return progress;
|
|
84
|
+
}
|
|
85
|
+
async function downloadFromHuggingFace(url, targetPath, options, modelId, expectedSize) {
|
|
86
|
+
const { events, hfToken, signal } = options;
|
|
87
|
+
const tempPath = `${targetPath}.download`;
|
|
88
|
+
const partialSize = await getPartialSize(tempPath);
|
|
89
|
+
const resumed = partialSize > 0;
|
|
90
|
+
const headers = {
|
|
91
|
+
"User-Agent": "Dexto/1.0"
|
|
92
|
+
};
|
|
93
|
+
if (hfToken) {
|
|
94
|
+
headers["Authorization"] = `Bearer ${hfToken}`;
|
|
95
|
+
}
|
|
96
|
+
if (partialSize > 0) {
|
|
97
|
+
headers["Range"] = `bytes=${partialSize}-`;
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
const fetchOptions = { headers };
|
|
101
|
+
if (signal) {
|
|
102
|
+
fetchOptions.signal = signal;
|
|
103
|
+
}
|
|
104
|
+
const response = await fetch(url, fetchOptions);
|
|
105
|
+
if (response.status === 401 || response.status === 403) {
|
|
106
|
+
throw import_errors.LocalModelError.hfAuthRequired(modelId);
|
|
107
|
+
}
|
|
108
|
+
if (!response.ok && response.status !== 206) {
|
|
109
|
+
throw import_errors.LocalModelError.downloadFailed(
|
|
110
|
+
modelId,
|
|
111
|
+
`HTTP ${response.status}: ${response.statusText}`
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
const contentLengthHeader = response.headers.get("content-length");
|
|
115
|
+
const contentLength = contentLengthHeader ? parseInt(contentLengthHeader, 10) : 0;
|
|
116
|
+
const totalSize = partialSize + contentLength;
|
|
117
|
+
await import_fs.promises.mkdir(path.dirname(tempPath), { recursive: true });
|
|
118
|
+
const writeStream = (0, import_fs.createWriteStream)(tempPath, {
|
|
119
|
+
flags: resumed ? "a" : "w"
|
|
120
|
+
});
|
|
121
|
+
let bytesDownloaded = partialSize;
|
|
122
|
+
const startTime = Date.now();
|
|
123
|
+
let lastProgressUpdate = startTime;
|
|
124
|
+
const reader = response.body?.getReader();
|
|
125
|
+
if (!reader) {
|
|
126
|
+
writeStream.destroy();
|
|
127
|
+
throw import_errors.LocalModelError.downloadFailed(modelId, "No response body");
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
while (true) {
|
|
131
|
+
const { done, value } = await reader.read();
|
|
132
|
+
if (done) break;
|
|
133
|
+
writeStream.write(value);
|
|
134
|
+
bytesDownloaded += value.length;
|
|
135
|
+
const now = Date.now();
|
|
136
|
+
if (now - lastProgressUpdate > 100 || done) {
|
|
137
|
+
lastProgressUpdate = now;
|
|
138
|
+
const elapsedSeconds = (now - startTime) / 1e3;
|
|
139
|
+
const speed = elapsedSeconds > 0 ? (bytesDownloaded - partialSize) / elapsedSeconds : 0;
|
|
140
|
+
const remainingBytes = totalSize - bytesDownloaded;
|
|
141
|
+
const eta = speed > 0 ? remainingBytes / speed : 0;
|
|
142
|
+
const progress = createProgressEvent(
|
|
143
|
+
modelId,
|
|
144
|
+
"downloading",
|
|
145
|
+
bytesDownloaded,
|
|
146
|
+
totalSize || expectedSize,
|
|
147
|
+
speed,
|
|
148
|
+
eta
|
|
149
|
+
);
|
|
150
|
+
events?.onProgress?.(progress);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
await new Promise((resolve, reject) => {
|
|
154
|
+
writeStream.end((err) => {
|
|
155
|
+
if (err) reject(err);
|
|
156
|
+
else resolve();
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
} catch (error) {
|
|
160
|
+
writeStream.destroy();
|
|
161
|
+
throw error;
|
|
162
|
+
}
|
|
163
|
+
events?.onProgress?.(createProgressEvent(modelId, "verifying", bytesDownloaded, totalSize));
|
|
164
|
+
await import_fs.promises.rename(tempPath, targetPath);
|
|
165
|
+
const stats = await import_fs.promises.stat(targetPath);
|
|
166
|
+
events?.onProgress?.(createProgressEvent(modelId, "complete", stats.size, stats.size));
|
|
167
|
+
return {
|
|
168
|
+
success: true,
|
|
169
|
+
filePath: targetPath,
|
|
170
|
+
sizeBytes: stats.size,
|
|
171
|
+
resumed
|
|
172
|
+
};
|
|
173
|
+
} catch (error) {
|
|
174
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
175
|
+
throw import_errors.LocalModelError.downloadInterrupted(modelId);
|
|
176
|
+
}
|
|
177
|
+
throw error;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
async function downloadModel(modelId, options) {
|
|
181
|
+
const modelInfo = (0, import_registry.getLocalModelById)(modelId);
|
|
182
|
+
if (!modelInfo) {
|
|
183
|
+
throw import_errors.LocalModelError.modelNotFound(modelId);
|
|
184
|
+
}
|
|
185
|
+
const targetPath = path.join(options.targetDir, modelInfo.filename);
|
|
186
|
+
const url = buildHuggingFaceUrl(modelInfo.huggingfaceId, modelInfo.filename);
|
|
187
|
+
if ((0, import_fs.existsSync)(targetPath)) {
|
|
188
|
+
const stats = await import_fs.promises.stat(targetPath);
|
|
189
|
+
if (stats.size === modelInfo.sizeBytes) {
|
|
190
|
+
return {
|
|
191
|
+
success: true,
|
|
192
|
+
filePath: targetPath,
|
|
193
|
+
sizeBytes: stats.size,
|
|
194
|
+
resumed: false
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
await import_fs.promises.unlink(targetPath);
|
|
198
|
+
}
|
|
199
|
+
try {
|
|
200
|
+
options.events?.onProgress?.(
|
|
201
|
+
createProgressEvent(modelId, "pending", 0, modelInfo.sizeBytes)
|
|
202
|
+
);
|
|
203
|
+
const result = await downloadFromHuggingFace(
|
|
204
|
+
url,
|
|
205
|
+
targetPath,
|
|
206
|
+
options,
|
|
207
|
+
modelId,
|
|
208
|
+
modelInfo.sizeBytes
|
|
209
|
+
);
|
|
210
|
+
if (options.verifyHash && options.expectedHash) {
|
|
211
|
+
const actualHash = await calculateFileHash(targetPath);
|
|
212
|
+
if (actualHash !== options.expectedHash) {
|
|
213
|
+
await import_fs.promises.unlink(targetPath);
|
|
214
|
+
throw import_errors.LocalModelError.hashMismatch(modelId, options.expectedHash, actualHash);
|
|
215
|
+
}
|
|
216
|
+
result.sha256 = actualHash;
|
|
217
|
+
}
|
|
218
|
+
options.events?.onComplete?.(modelId, targetPath);
|
|
219
|
+
return result;
|
|
220
|
+
} catch (error) {
|
|
221
|
+
options.events?.onError?.(modelId, error);
|
|
222
|
+
throw error;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
async function downloadModelFromUrl(modelId, url, filename, options) {
|
|
226
|
+
const targetPath = path.join(options.targetDir, filename);
|
|
227
|
+
try {
|
|
228
|
+
options.events?.onProgress?.(createProgressEvent(modelId, "pending", 0, 0));
|
|
229
|
+
const result = await downloadFromHuggingFace(url, targetPath, options, modelId, 0);
|
|
230
|
+
options.events?.onComplete?.(modelId, targetPath);
|
|
231
|
+
return result;
|
|
232
|
+
} catch (error) {
|
|
233
|
+
options.events?.onError?.(modelId, error);
|
|
234
|
+
throw error;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
async function checkDiskSpace(targetDir) {
|
|
238
|
+
try {
|
|
239
|
+
await import_fs.promises.access(targetDir);
|
|
240
|
+
return Number.MAX_SAFE_INTEGER;
|
|
241
|
+
} catch {
|
|
242
|
+
try {
|
|
243
|
+
await import_fs.promises.mkdir(targetDir, { recursive: true });
|
|
244
|
+
return Number.MAX_SAFE_INTEGER;
|
|
245
|
+
} catch {
|
|
246
|
+
return 0;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
async function validateDiskSpace(modelId, requiredBytes, targetDir) {
|
|
251
|
+
const available = await checkDiskSpace(targetDir);
|
|
252
|
+
if (available < requiredBytes) {
|
|
253
|
+
throw import_errors.LocalModelError.insufficientDiskSpace(modelId, requiredBytes, available);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
async function cleanupPartialDownload(targetDir, filename) {
|
|
257
|
+
const tempPath = path.join(targetDir, `${filename}.download`);
|
|
258
|
+
try {
|
|
259
|
+
await import_fs.promises.unlink(tempPath);
|
|
260
|
+
} catch {
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
async function isDownloadInProgress(targetDir, filename) {
|
|
264
|
+
const tempPath = path.join(targetDir, `${filename}.download`);
|
|
265
|
+
try {
|
|
266
|
+
await import_fs.promises.access(tempPath);
|
|
267
|
+
return true;
|
|
268
|
+
} catch {
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
async function getPartialDownloadProgress(modelId, targetDir, filename, totalBytes) {
|
|
273
|
+
const tempPath = path.join(targetDir, `${filename}.download`);
|
|
274
|
+
try {
|
|
275
|
+
const stats = await import_fs.promises.stat(tempPath);
|
|
276
|
+
return createProgressEvent(modelId, "downloading", stats.size, totalBytes);
|
|
277
|
+
} catch {
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
282
|
+
0 && (module.exports = {
|
|
283
|
+
calculateFileHash,
|
|
284
|
+
checkDiskSpace,
|
|
285
|
+
cleanupPartialDownload,
|
|
286
|
+
downloadModel,
|
|
287
|
+
downloadModelFromUrl,
|
|
288
|
+
getPartialDownloadProgress,
|
|
289
|
+
isDownloadInProgress,
|
|
290
|
+
validateDiskSpace
|
|
291
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model downloader for local GGUF models.
|
|
3
|
+
*
|
|
4
|
+
* Downloads models from HuggingFace with:
|
|
5
|
+
* - Progress tracking via events
|
|
6
|
+
* - Resume support for interrupted downloads
|
|
7
|
+
* - Hash verification after download
|
|
8
|
+
*/
|
|
9
|
+
import type { ModelDownloadProgress } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Event emitter interface for download progress.
|
|
12
|
+
*/
|
|
13
|
+
export interface DownloadEvents {
|
|
14
|
+
onProgress?: (progress: ModelDownloadProgress) => void;
|
|
15
|
+
onComplete?: (modelId: string, filePath: string) => void;
|
|
16
|
+
onError?: (modelId: string, error: Error) => void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Download options.
|
|
20
|
+
*/
|
|
21
|
+
export interface DownloadOptions {
|
|
22
|
+
/** Directory to save the model */
|
|
23
|
+
targetDir: string;
|
|
24
|
+
/** Events for progress tracking */
|
|
25
|
+
events?: DownloadEvents;
|
|
26
|
+
/** HuggingFace token for gated models */
|
|
27
|
+
hfToken?: string;
|
|
28
|
+
/** Whether to verify hash after download */
|
|
29
|
+
verifyHash?: boolean;
|
|
30
|
+
/** Abort signal for cancellation */
|
|
31
|
+
signal?: AbortSignal;
|
|
32
|
+
/** Expected SHA-256 hash for verification */
|
|
33
|
+
expectedHash?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Download result.
|
|
37
|
+
*/
|
|
38
|
+
export interface DownloadResult {
|
|
39
|
+
/** Whether download succeeded */
|
|
40
|
+
success: boolean;
|
|
41
|
+
/** Full path to downloaded file */
|
|
42
|
+
filePath: string;
|
|
43
|
+
/** File size in bytes */
|
|
44
|
+
sizeBytes: number;
|
|
45
|
+
/** SHA-256 hash of the file */
|
|
46
|
+
sha256?: string;
|
|
47
|
+
/** Whether download was resumed from partial */
|
|
48
|
+
resumed: boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Calculate SHA-256 hash of a file.
|
|
52
|
+
*/
|
|
53
|
+
export declare function calculateFileHash(filePath: string): Promise<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Download a local model by ID.
|
|
56
|
+
*/
|
|
57
|
+
export declare function downloadModel(modelId: string, options: DownloadOptions): Promise<DownloadResult>;
|
|
58
|
+
/**
|
|
59
|
+
* Download a model directly from a URL (for custom models).
|
|
60
|
+
*/
|
|
61
|
+
export declare function downloadModelFromUrl(modelId: string, url: string, filename: string, options: DownloadOptions): Promise<DownloadResult>;
|
|
62
|
+
/**
|
|
63
|
+
* Check available disk space at a path.
|
|
64
|
+
*/
|
|
65
|
+
export declare function checkDiskSpace(targetDir: string): Promise<number>;
|
|
66
|
+
/**
|
|
67
|
+
* Validate that there's enough disk space for a model.
|
|
68
|
+
*/
|
|
69
|
+
export declare function validateDiskSpace(modelId: string, requiredBytes: number, targetDir: string): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Clean up partial download files.
|
|
72
|
+
*/
|
|
73
|
+
export declare function cleanupPartialDownload(targetDir: string, filename: string): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Check if a download is in progress (partial file exists).
|
|
76
|
+
*/
|
|
77
|
+
export declare function isDownloadInProgress(targetDir: string, filename: string): Promise<boolean>;
|
|
78
|
+
/**
|
|
79
|
+
* Get the progress of a partial download.
|
|
80
|
+
*/
|
|
81
|
+
export declare function getPartialDownloadProgress(modelId: string, targetDir: string, filename: string, totalBytes: number): Promise<ModelDownloadProgress | null>;
|
|
82
|
+
//# sourceMappingURL=downloader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"downloader.d.ts","sourceRoot":"","sources":["../../../../src/llm/providers/local/downloader.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EAAE,qBAAqB,EAAuB,MAAM,YAAY,CAAC;AAI7E;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,qBAAqB,KAAK,IAAI,CAAC;IACvD,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACzD,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACrD;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B,kCAAkC;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,mCAAmC;IACnC,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,yCAAyC;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,oCAAoC;IACpC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,6CAA6C;IAC7C,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B,iCAAiC;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,mCAAmC;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,yBAAyB;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,+BAA+B;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gDAAgD;IAChD,OAAO,EAAE,OAAO,CAAC;CACpB;AAsBD;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CASzE;AAqLD;;GAEG;AACH,wBAAsB,aAAa,CAC/B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,eAAe,GACzB,OAAO,CAAC,cAAc,CAAC,CAwDzB;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACtC,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,eAAe,GACzB,OAAO,CAAC,cAAc,CAAC,CAczB;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAevE;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CACnC,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC,CAKf;AAED;;GAEG;AACH,wBAAsB,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAO/F;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAQhG;AAED;;GAEG;AACH,wBAAsB,0BAA0B,CAC5C,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GACnB,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC,CAQvC"}
|