lmgrep 0.1.17 → 0.2.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 +226 -63
- package/completions/_lmgrep +49 -40
- package/dist/application/Lmgrep.d.ts +107 -0
- package/dist/application/Lmgrep.js +99 -0
- package/dist/application/Lmgrep.js.map +1 -0
- package/dist/application/LmgrepFactory.d.ts +40 -0
- package/dist/application/LmgrepFactory.js +155 -0
- package/dist/application/LmgrepFactory.js.map +1 -0
- package/dist/application/indexing/BranchBootstrapper.d.ts +21 -0
- package/dist/application/indexing/BranchBootstrapper.js +52 -0
- package/dist/application/indexing/BranchBootstrapper.js.map +1 -0
- package/dist/application/indexing/BranchManifestSweeper.d.ts +17 -0
- package/dist/application/indexing/BranchManifestSweeper.js +35 -0
- package/dist/application/indexing/BranchManifestSweeper.js.map +1 -0
- package/dist/application/indexing/Duration.d.ts +9 -0
- package/dist/application/indexing/Duration.js +25 -0
- package/dist/application/indexing/Duration.js.map +1 -0
- package/dist/application/indexing/EmbeddingAbortError.d.ts +11 -0
- package/dist/application/indexing/EmbeddingAbortError.js +20 -0
- package/dist/application/indexing/EmbeddingAbortError.js.map +1 -0
- package/dist/application/indexing/EmbeddingPipeline.d.ts +59 -0
- package/dist/application/indexing/EmbeddingPipeline.js +140 -0
- package/dist/application/indexing/EmbeddingPipeline.js.map +1 -0
- package/dist/application/indexing/IndexBuilder.d.ts +112 -0
- package/dist/application/indexing/IndexBuilder.js +370 -0
- package/dist/application/indexing/IndexBuilder.js.map +1 -0
- package/dist/application/indexing/IndexingProgress.d.ts +34 -0
- package/dist/application/indexing/IndexingProgress.js +2 -0
- package/dist/application/indexing/IndexingProgress.js.map +1 -0
- package/dist/application/operations/Deadline.d.ts +13 -0
- package/dist/application/operations/Deadline.js +29 -0
- package/dist/application/operations/Deadline.js.map +1 -0
- package/dist/application/operations/HealthMonitor.d.ts +58 -0
- package/dist/application/operations/HealthMonitor.js +128 -0
- package/dist/application/operations/HealthMonitor.js.map +1 -0
- package/dist/application/operations/IndexAlternatives.d.ts +35 -0
- package/dist/application/operations/IndexAlternatives.js +61 -0
- package/dist/application/operations/IndexAlternatives.js.map +1 -0
- package/dist/application/operations/IndexInventory.d.ts +69 -0
- package/dist/application/operations/IndexInventory.js +99 -0
- package/dist/application/operations/IndexInventory.js.map +1 -0
- package/dist/application/operations/StatusService.d.ts +90 -0
- package/dist/application/operations/StatusService.js +171 -0
- package/dist/application/operations/StatusService.js.map +1 -0
- package/dist/application/operations/WatchService.d.ts +67 -0
- package/dist/application/operations/WatchService.js +145 -0
- package/dist/application/operations/WatchService.js.map +1 -0
- package/dist/application/operations/WorkingTreeDiff.d.ts +19 -0
- package/dist/application/operations/WorkingTreeDiff.js +36 -0
- package/dist/application/operations/WorkingTreeDiff.js.map +1 -0
- package/dist/application/research/ResearchAgent.d.ts +68 -0
- package/dist/application/research/ResearchAgent.js +201 -0
- package/dist/application/research/ResearchAgent.js.map +1 -0
- package/dist/application/research/ResearchPrompts.d.ts +16 -0
- package/dist/application/research/ResearchPrompts.js +34 -0
- package/dist/application/research/ResearchPrompts.js.map +1 -0
- package/dist/application/search/SearchCriteria.d.ts +37 -0
- package/dist/application/search/SearchCriteria.js +48 -0
- package/dist/application/search/SearchCriteria.js.map +1 -0
- package/dist/application/search/SearchService.d.ts +36 -0
- package/dist/application/search/SearchService.js +108 -0
- package/dist/application/search/SearchService.js.map +1 -0
- package/dist/application/search/SearchTargetResolver.d.ts +56 -0
- package/dist/application/search/SearchTargetResolver.js +104 -0
- package/dist/application/search/SearchTargetResolver.js.map +1 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +5 -754
- package/dist/cli.js.map +1 -1
- package/dist/domain/config/ConfigSource.d.ts +16 -0
- package/dist/domain/config/ConfigSource.js +2 -0
- package/dist/domain/config/ConfigSource.js.map +1 -0
- package/dist/domain/config/LmgrepConfig.d.ts +53 -0
- package/dist/domain/config/LmgrepConfig.js +2 -0
- package/dist/domain/config/LmgrepConfig.js.map +1 -0
- package/dist/domain/corpus/Chunk.d.ts +49 -0
- package/dist/domain/corpus/Chunk.js +60 -0
- package/dist/domain/corpus/Chunk.js.map +1 -0
- package/dist/domain/corpus/CodeLocation.d.ts +18 -0
- package/dist/domain/corpus/CodeLocation.js +34 -0
- package/dist/domain/corpus/CodeLocation.js.map +1 -0
- package/dist/domain/corpus/ContentHash.d.ts +15 -0
- package/dist/domain/corpus/ContentHash.js +30 -0
- package/dist/domain/corpus/ContentHash.js.map +1 -0
- package/dist/domain/corpus/FileVersion.d.ts +31 -0
- package/dist/domain/corpus/FileVersion.js +47 -0
- package/dist/domain/corpus/FileVersion.js.map +1 -0
- package/dist/domain/corpus/SourceFile.d.ts +26 -0
- package/dist/domain/corpus/SourceFile.js +47 -0
- package/dist/domain/corpus/SourceFile.js.map +1 -0
- package/dist/domain/corpus/Vector.d.ts +37 -0
- package/dist/domain/corpus/Vector.js +96 -0
- package/dist/domain/corpus/Vector.js.map +1 -0
- package/dist/domain/ports/ChatModelPort.d.ts +57 -0
- package/dist/domain/ports/ChatModelPort.js +2 -0
- package/dist/domain/ports/ChatModelPort.js.map +1 -0
- package/dist/domain/ports/ChunkRepositoryPort.d.ts +42 -0
- package/dist/domain/ports/ChunkRepositoryPort.js +2 -0
- package/dist/domain/ports/ChunkRepositoryPort.js.map +1 -0
- package/dist/domain/ports/ChunkerPort.d.ts +5 -0
- package/dist/domain/ports/ChunkerPort.js +2 -0
- package/dist/domain/ports/ChunkerPort.js.map +1 -0
- package/dist/domain/ports/DatabaseSessionPort.d.ts +10 -0
- package/dist/domain/ports/DatabaseSessionPort.js +2 -0
- package/dist/domain/ports/DatabaseSessionPort.js.map +1 -0
- package/dist/domain/ports/EmbedderPort.d.ts +14 -0
- package/dist/domain/ports/EmbedderPort.js +2 -0
- package/dist/domain/ports/EmbedderPort.js.map +1 -0
- package/dist/domain/ports/FileManifestRepositoryPort.d.ts +32 -0
- package/dist/domain/ports/FileManifestRepositoryPort.js +2 -0
- package/dist/domain/ports/FileManifestRepositoryPort.js.map +1 -0
- package/dist/domain/ports/GitPort.d.ts +24 -0
- package/dist/domain/ports/GitPort.js +2 -0
- package/dist/domain/ports/GitPort.js.map +1 -0
- package/dist/domain/ports/IndexMaintenancePort.d.ts +58 -0
- package/dist/domain/ports/IndexMaintenancePort.js +2 -0
- package/dist/domain/ports/IndexMaintenancePort.js.map +1 -0
- package/dist/domain/ports/IndexMetadataPort.d.ts +23 -0
- package/dist/domain/ports/IndexMetadataPort.js +2 -0
- package/dist/domain/ports/IndexMetadataPort.js.map +1 -0
- package/dist/domain/ports/LockPort.d.ts +17 -0
- package/dist/domain/ports/LockPort.js +2 -0
- package/dist/domain/ports/LockPort.js.map +1 -0
- package/dist/domain/ports/LoggerPort.d.ts +5 -0
- package/dist/domain/ports/LoggerPort.js +2 -0
- package/dist/domain/ports/LoggerPort.js.map +1 -0
- package/dist/domain/ports/ProjectIndexesPort.d.ts +20 -0
- package/dist/domain/ports/ProjectIndexesPort.js +2 -0
- package/dist/domain/ports/ProjectIndexesPort.js.map +1 -0
- package/dist/domain/ports/ProjectRegistryPort.d.ts +42 -0
- package/dist/domain/ports/ProjectRegistryPort.js +2 -0
- package/dist/domain/ports/ProjectRegistryPort.js.map +1 -0
- package/dist/domain/ports/StateDirectoryPort.d.ts +29 -0
- package/dist/domain/ports/StateDirectoryPort.js +2 -0
- package/dist/domain/ports/StateDirectoryPort.js.map +1 -0
- package/dist/domain/ports/WorkspacePort.d.ts +38 -0
- package/dist/domain/ports/WorkspacePort.js +2 -0
- package/dist/domain/ports/WorkspacePort.js.map +1 -0
- package/dist/domain/project/Branch.d.ts +20 -0
- package/dist/domain/project/Branch.js +33 -0
- package/dist/domain/project/Branch.js.map +1 -0
- package/dist/domain/project/DatabaseLocation.d.ts +32 -0
- package/dist/domain/project/DatabaseLocation.js +35 -0
- package/dist/domain/project/DatabaseLocation.js.map +1 -0
- package/dist/domain/project/IndexMetadata.d.ts +17 -0
- package/dist/domain/project/IndexMetadata.js +2 -0
- package/dist/domain/project/IndexMetadata.js.map +1 -0
- package/dist/domain/project/ModelIdentity.d.ts +58 -0
- package/dist/domain/project/ModelIdentity.js +97 -0
- package/dist/domain/project/ModelIdentity.js.map +1 -0
- package/dist/domain/project/Project.d.ts +17 -0
- package/dist/domain/project/Project.js +21 -0
- package/dist/domain/project/Project.js.map +1 -0
- package/dist/domain/project/ProjectId.d.ts +28 -0
- package/dist/domain/project/ProjectId.js +58 -0
- package/dist/domain/project/ProjectId.js.map +1 -0
- package/dist/domain/project/ProjectLocator.d.ts +112 -0
- package/dist/domain/project/ProjectLocator.js +178 -0
- package/dist/domain/project/ProjectLocator.js.map +1 -0
- package/dist/domain/research/Citation.d.ts +27 -0
- package/dist/domain/research/Citation.js +43 -0
- package/dist/domain/research/Citation.js.map +1 -0
- package/dist/domain/research/EvidenceLedger.d.ts +47 -0
- package/dist/domain/research/EvidenceLedger.js +111 -0
- package/dist/domain/research/EvidenceLedger.js.map +1 -0
- package/dist/domain/research/ResearchTrace.d.ts +19 -0
- package/dist/domain/research/ResearchTrace.js +22 -0
- package/dist/domain/research/ResearchTrace.js.map +1 -0
- package/dist/domain/retrieval/Hit.d.ts +19 -0
- package/dist/domain/retrieval/Hit.js +28 -0
- package/dist/domain/retrieval/Hit.js.map +1 -0
- package/dist/domain/retrieval/HitList.d.ts +35 -0
- package/dist/domain/retrieval/HitList.js +81 -0
- package/dist/domain/retrieval/HitList.js.map +1 -0
- package/dist/domain/retrieval/MissingIndexError.d.ts +11 -0
- package/dist/domain/retrieval/MissingIndexError.js +15 -0
- package/dist/domain/retrieval/MissingIndexError.js.map +1 -0
- package/dist/index.d.ts +43 -33
- package/dist/index.js +32 -215
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/ai/AiSdkChatModel.d.ts +31 -0
- package/dist/infrastructure/ai/AiSdkChatModel.js +137 -0
- package/dist/infrastructure/ai/AiSdkChatModel.js.map +1 -0
- package/dist/infrastructure/ai/AiSdkEmbedder.d.ts +28 -0
- package/dist/infrastructure/ai/AiSdkEmbedder.js +79 -0
- package/dist/infrastructure/ai/AiSdkEmbedder.js.map +1 -0
- package/dist/infrastructure/ai/EmbeddingPrefixes.d.ts +21 -0
- package/dist/infrastructure/ai/EmbeddingPrefixes.js +40 -0
- package/dist/infrastructure/ai/EmbeddingPrefixes.js.map +1 -0
- package/dist/infrastructure/ai/LmStudioProbe.d.ts +18 -0
- package/dist/infrastructure/ai/LmStudioProbe.js +49 -0
- package/dist/infrastructure/ai/LmStudioProbe.js.map +1 -0
- package/dist/infrastructure/ai/LocalModelReloader.d.ts +21 -0
- package/dist/infrastructure/ai/LocalModelReloader.js +61 -0
- package/dist/infrastructure/ai/LocalModelReloader.js.map +1 -0
- package/dist/infrastructure/ai/LocalRuntimeDetector.d.ts +36 -0
- package/dist/infrastructure/ai/LocalRuntimeDetector.js +61 -0
- package/dist/infrastructure/ai/LocalRuntimeDetector.js.map +1 -0
- package/dist/infrastructure/ai/ModelRuntime.d.ts +32 -0
- package/dist/infrastructure/ai/ModelRuntime.js +2 -0
- package/dist/infrastructure/ai/ModelRuntime.js.map +1 -0
- package/dist/infrastructure/ai/OllamaProbe.d.ts +21 -0
- package/dist/infrastructure/ai/OllamaProbe.js +69 -0
- package/dist/infrastructure/ai/OllamaProbe.js.map +1 -0
- package/dist/infrastructure/ai/ProviderFailure.d.ts +16 -0
- package/dist/infrastructure/ai/ProviderFailure.js +35 -0
- package/dist/infrastructure/ai/ProviderFailure.js.map +1 -0
- package/dist/infrastructure/ai/ProviderModuleLoader.d.ts +13 -0
- package/dist/infrastructure/ai/ProviderModuleLoader.js +49 -0
- package/dist/infrastructure/ai/ProviderModuleLoader.js.map +1 -0
- package/dist/infrastructure/ai/ProviderRegistry.d.ts +37 -0
- package/dist/infrastructure/ai/ProviderRegistry.js +55 -0
- package/dist/infrastructure/ai/ProviderRegistry.js.map +1 -0
- package/dist/infrastructure/fs/ConfigLoader.d.ts +59 -0
- package/dist/infrastructure/fs/ConfigLoader.js +194 -0
- package/dist/infrastructure/fs/ConfigLoader.js.map +1 -0
- package/dist/infrastructure/fs/DatabaseLocks.d.ts +52 -0
- package/dist/infrastructure/fs/DatabaseLocks.js +92 -0
- package/dist/infrastructure/fs/DatabaseLocks.js.map +1 -0
- package/dist/infrastructure/fs/DiskUsage.d.ts +6 -0
- package/dist/infrastructure/fs/DiskUsage.js +41 -0
- package/dist/infrastructure/fs/DiskUsage.js.map +1 -0
- package/dist/infrastructure/fs/IndexableFileRules.d.ts +33 -0
- package/dist/infrastructure/fs/IndexableFileRules.js +177 -0
- package/dist/infrastructure/fs/IndexableFileRules.js.map +1 -0
- package/dist/infrastructure/fs/Loggers.d.ts +14 -0
- package/dist/infrastructure/fs/Loggers.js +18 -0
- package/dist/infrastructure/fs/Loggers.js.map +1 -0
- package/dist/infrastructure/fs/PidFileLock.d.ts +40 -0
- package/dist/infrastructure/fs/PidFileLock.js +97 -0
- package/dist/infrastructure/fs/PidFileLock.js.map +1 -0
- package/dist/infrastructure/fs/ProjectIndexes.d.ts +8 -0
- package/dist/infrastructure/fs/ProjectIndexes.js +35 -0
- package/dist/infrastructure/fs/ProjectIndexes.js.map +1 -0
- package/dist/infrastructure/fs/ProjectMetadataStore.d.ts +42 -0
- package/dist/infrastructure/fs/ProjectMetadataStore.js +86 -0
- package/dist/infrastructure/fs/ProjectMetadataStore.js.map +1 -0
- package/dist/infrastructure/fs/ProjectRegistry.d.ts +25 -0
- package/dist/infrastructure/fs/ProjectRegistry.js +83 -0
- package/dist/infrastructure/fs/ProjectRegistry.js.map +1 -0
- package/dist/infrastructure/fs/StateDirectory.d.ts +28 -0
- package/dist/infrastructure/fs/StateDirectory.js +71 -0
- package/dist/infrastructure/fs/StateDirectory.js.map +1 -0
- package/dist/infrastructure/fs/Workspace.d.ts +25 -0
- package/dist/infrastructure/fs/Workspace.js +90 -0
- package/dist/infrastructure/fs/Workspace.js.map +1 -0
- package/dist/infrastructure/git/GitClient.d.ts +34 -0
- package/dist/infrastructure/git/GitClient.js +74 -0
- package/dist/infrastructure/git/GitClient.js.map +1 -0
- package/dist/infrastructure/lancedb/ChunkRepository.d.ts +38 -0
- package/dist/infrastructure/lancedb/ChunkRepository.js +166 -0
- package/dist/infrastructure/lancedb/ChunkRepository.js.map +1 -0
- package/dist/infrastructure/lancedb/DatabaseImporter.d.ts +22 -0
- package/dist/infrastructure/lancedb/DatabaseImporter.js +74 -0
- package/dist/infrastructure/lancedb/DatabaseImporter.js.map +1 -0
- package/dist/infrastructure/lancedb/FileManifestRepository.d.ts +34 -0
- package/dist/infrastructure/lancedb/FileManifestRepository.js +137 -0
- package/dist/infrastructure/lancedb/FileManifestRepository.js.map +1 -0
- package/dist/infrastructure/lancedb/IndexMaintenance.d.ts +53 -0
- package/dist/infrastructure/lancedb/IndexMaintenance.js +227 -0
- package/dist/infrastructure/lancedb/IndexMaintenance.js.map +1 -0
- package/dist/infrastructure/lancedb/LanceTables.d.ts +67 -0
- package/dist/infrastructure/lancedb/LanceTables.js +159 -0
- package/dist/infrastructure/lancedb/LanceTables.js.map +1 -0
- package/dist/infrastructure/lancedb/NativeTuning.d.ts +1 -0
- package/dist/infrastructure/lancedb/NativeTuning.js +9 -0
- package/dist/infrastructure/lancedb/NativeTuning.js.map +1 -0
- package/dist/infrastructure/lancedb/RowReplication.d.ts +27 -0
- package/dist/infrastructure/lancedb/RowReplication.js +82 -0
- package/dist/infrastructure/lancedb/RowReplication.js.map +1 -0
- package/dist/infrastructure/lancedb/VectorIndexPolicy.d.ts +60 -0
- package/dist/infrastructure/lancedb/VectorIndexPolicy.js +72 -0
- package/dist/infrastructure/lancedb/VectorIndexPolicy.js.map +1 -0
- package/dist/infrastructure/p2p/IndexShare.d.ts +45 -0
- package/dist/infrastructure/p2p/IndexShare.js +160 -0
- package/dist/infrastructure/p2p/IndexShare.js.map +1 -0
- package/dist/infrastructure/p2p/PeerSwarm.d.ts +16 -0
- package/dist/infrastructure/p2p/PeerSwarm.js +41 -0
- package/dist/infrastructure/p2p/PeerSwarm.js.map +1 -0
- package/dist/infrastructure/p2p/SecureChannel.d.ts +60 -0
- package/dist/infrastructure/p2p/SecureChannel.js +71 -0
- package/dist/infrastructure/p2p/SecureChannel.js.map +1 -0
- package/dist/infrastructure/p2p/ShareCode.d.ts +25 -0
- package/dist/infrastructure/p2p/ShareCode.js +304 -0
- package/dist/infrastructure/p2p/ShareCode.js.map +1 -0
- package/dist/infrastructure/process/ProcessRegistry.d.ts +50 -0
- package/dist/infrastructure/process/ProcessRegistry.js +109 -0
- package/dist/infrastructure/process/ProcessRegistry.js.map +1 -0
- package/dist/infrastructure/treesitter/ChunkContextBuilder.d.ts +45 -0
- package/dist/infrastructure/treesitter/ChunkContextBuilder.js +159 -0
- package/dist/infrastructure/treesitter/ChunkContextBuilder.js.map +1 -0
- package/dist/infrastructure/treesitter/LanguageCatalog.d.ts +30 -0
- package/dist/{lib/chunker/languages.js → infrastructure/treesitter/LanguageCatalog.js} +65 -41
- package/dist/infrastructure/treesitter/LanguageCatalog.js.map +1 -0
- package/dist/infrastructure/treesitter/SlidingWindowChunker.d.ts +15 -0
- package/dist/infrastructure/treesitter/SlidingWindowChunker.js +42 -0
- package/dist/infrastructure/treesitter/SlidingWindowChunker.js.map +1 -0
- package/dist/infrastructure/treesitter/TreeSitterChunker.d.ts +42 -0
- package/dist/infrastructure/treesitter/TreeSitterChunker.js +163 -0
- package/dist/infrastructure/treesitter/TreeSitterChunker.js.map +1 -0
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.js +15 -61
- package/dist/mcp.js.map +1 -1
- package/dist/presentation/cli/Cli.d.ts +31 -0
- package/dist/presentation/cli/Cli.js +120 -0
- package/dist/presentation/cli/Cli.js.map +1 -0
- package/dist/presentation/cli/CliOptions.d.ts +18 -0
- package/dist/presentation/cli/CliOptions.js +25 -0
- package/dist/presentation/cli/CliOptions.js.map +1 -0
- package/dist/presentation/cli/CommandContext.d.ts +50 -0
- package/dist/presentation/cli/CommandContext.js +88 -0
- package/dist/presentation/cli/CommandContext.js.map +1 -0
- package/dist/presentation/cli/ConfigTemplate.d.ts +31 -0
- package/dist/presentation/cli/ConfigTemplate.js +83 -0
- package/dist/presentation/cli/ConfigTemplate.js.map +1 -0
- package/dist/presentation/cli/Renderer.d.ts +90 -0
- package/dist/presentation/cli/Renderer.js +290 -0
- package/dist/presentation/cli/Renderer.js.map +1 -0
- package/dist/presentation/cli/commands/AskCommand.d.ts +14 -0
- package/dist/presentation/cli/commands/AskCommand.js +48 -0
- package/dist/presentation/cli/commands/AskCommand.js.map +1 -0
- package/dist/presentation/cli/commands/CompletionsCommand.d.ts +18 -0
- package/dist/presentation/cli/commands/CompletionsCommand.js +96 -0
- package/dist/presentation/cli/commands/CompletionsCommand.js.map +1 -0
- package/dist/presentation/cli/commands/ConfigCommands.d.ts +55 -0
- package/dist/presentation/cli/commands/ConfigCommands.js +204 -0
- package/dist/presentation/cli/commands/ConfigCommands.js.map +1 -0
- package/dist/presentation/cli/commands/IndexCommand.d.ts +18 -0
- package/dist/presentation/cli/commands/IndexCommand.js +54 -0
- package/dist/presentation/cli/commands/IndexCommand.js.map +1 -0
- package/dist/presentation/cli/commands/ProjectsCommand.d.ts +48 -0
- package/dist/presentation/cli/commands/ProjectsCommand.js +240 -0
- package/dist/presentation/cli/commands/ProjectsCommand.js.map +1 -0
- package/dist/presentation/cli/commands/SearchCommand.d.ts +19 -0
- package/dist/presentation/cli/commands/SearchCommand.js +55 -0
- package/dist/presentation/cli/commands/SearchCommand.js.map +1 -0
- package/dist/presentation/cli/commands/ServerCommands.d.ts +13 -0
- package/dist/presentation/cli/commands/ServerCommands.js +40 -0
- package/dist/presentation/cli/commands/ServerCommands.js.map +1 -0
- package/dist/presentation/cli/commands/ShareCommands.d.ts +22 -0
- package/dist/presentation/cli/commands/ShareCommands.js +134 -0
- package/dist/presentation/cli/commands/ShareCommands.js.map +1 -0
- package/dist/presentation/cli/commands/StatusCommand.d.ts +15 -0
- package/dist/presentation/cli/commands/StatusCommand.js +53 -0
- package/dist/presentation/cli/commands/StatusCommand.js.map +1 -0
- package/dist/presentation/mcp/HitFormatter.d.ts +17 -0
- package/dist/presentation/mcp/HitFormatter.js +42 -0
- package/dist/presentation/mcp/HitFormatter.js.map +1 -0
- package/dist/presentation/mcp/IndexWatchController.d.ts +17 -0
- package/dist/presentation/mcp/IndexWatchController.js +31 -0
- package/dist/presentation/mcp/IndexWatchController.js.map +1 -0
- package/dist/presentation/mcp/LmgrepCore.d.ts +66 -0
- package/dist/presentation/mcp/LmgrepCore.js +178 -0
- package/dist/presentation/mcp/LmgrepCore.js.map +1 -0
- package/dist/presentation/mcp/McpServer.d.ts +18 -0
- package/dist/presentation/mcp/McpServer.js +63 -0
- package/dist/presentation/mcp/McpServer.js.map +1 -0
- package/dist/presentation/mcp/ToolDescriptions.d.ts +40 -0
- package/dist/presentation/mcp/ToolDescriptions.js +85 -0
- package/dist/presentation/mcp/ToolDescriptions.js.map +1 -0
- package/package.json +84 -63
- package/dist/lib/build.d.ts +0 -7
- package/dist/lib/build.js +0 -284
- package/dist/lib/build.js.map +0 -1
- package/dist/lib/chunker/context.d.ts +0 -21
- package/dist/lib/chunker/context.js +0 -131
- package/dist/lib/chunker/context.js.map +0 -1
- package/dist/lib/chunker/index.d.ts +0 -7
- package/dist/lib/chunker/index.js +0 -150
- package/dist/lib/chunker/index.js.map +0 -1
- package/dist/lib/chunker/languages.d.ts +0 -15
- package/dist/lib/chunker/languages.js.map +0 -1
- package/dist/lib/config.d.ts +0 -12
- package/dist/lib/config.js +0 -83
- package/dist/lib/config.js.map +0 -1
- package/dist/lib/embedder.d.ts +0 -55
- package/dist/lib/embedder.js +0 -221
- package/dist/lib/embedder.js.map +0 -1
- package/dist/lib/p2p.d.ts +0 -32
- package/dist/lib/p2p.js +0 -281
- package/dist/lib/p2p.js.map +0 -1
- package/dist/lib/providers.d.ts +0 -1
- package/dist/lib/providers.js +0 -41
- package/dist/lib/providers.js.map +0 -1
- package/dist/lib/repair.d.ts +0 -10
- package/dist/lib/repair.js +0 -57
- package/dist/lib/repair.js.map +0 -1
- package/dist/lib/scanner.d.ts +0 -34
- package/dist/lib/scanner.js +0 -242
- package/dist/lib/scanner.js.map +0 -1
- package/dist/lib/search-tool.d.ts +0 -47
- package/dist/lib/search-tool.js +0 -239
- package/dist/lib/search-tool.js.map +0 -1
- package/dist/lib/serve.d.ts +0 -11
- package/dist/lib/serve.js +0 -127
- package/dist/lib/serve.js.map +0 -1
- package/dist/lib/store.d.ts +0 -177
- package/dist/lib/store.js +0 -825
- package/dist/lib/store.js.map +0 -1
- package/dist/lib/types.d.ts +0 -129
- package/dist/lib/types.js +0 -13
- package/dist/lib/types.js.map +0 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { createProviderRegistry, embed, embedMany, } from "ai";
|
|
2
|
+
import { Vector } from "../../domain/corpus/Vector.js";
|
|
3
|
+
import { ModelReference, ProviderRegistry } from "./ProviderRegistry.js";
|
|
4
|
+
/**
|
|
5
|
+
* Embeddings via the Vercel AI SDK.
|
|
6
|
+
*
|
|
7
|
+
* Documents and queries take different prefixes because asymmetric models
|
|
8
|
+
* (nomic, e5, bge) are trained to expect them; omitting them degrades recall
|
|
9
|
+
* without any visible error, so the distinction is enforced by having two
|
|
10
|
+
* methods rather than one with a flag.
|
|
11
|
+
*/
|
|
12
|
+
export class AiSdkEmbedder {
|
|
13
|
+
config;
|
|
14
|
+
providers;
|
|
15
|
+
model;
|
|
16
|
+
dimensionsChecked = false;
|
|
17
|
+
constructor(config, providers = new ProviderRegistry()) {
|
|
18
|
+
this.config = config;
|
|
19
|
+
this.providers = providers;
|
|
20
|
+
}
|
|
21
|
+
async embedDocuments(texts) {
|
|
22
|
+
const model = await this.getModel();
|
|
23
|
+
const prefix = this.config.documentPrefix ?? "";
|
|
24
|
+
const out = [];
|
|
25
|
+
// Sub-batch to the configured size: providers reject oversized requests,
|
|
26
|
+
// and a local server will happily OOM on one.
|
|
27
|
+
for (let i = 0; i < texts.length; i += this.config.batchSize) {
|
|
28
|
+
const batch = texts.slice(i, i + this.config.batchSize);
|
|
29
|
+
const values = prefix ? batch.map((t) => prefix + t) : batch;
|
|
30
|
+
const { embeddings } = await embedMany({ model, values });
|
|
31
|
+
if (embeddings.length > 0)
|
|
32
|
+
this.verifyDimensions(embeddings[0]);
|
|
33
|
+
for (const e of embeddings)
|
|
34
|
+
out.push(Vector.from(e));
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
async embedQuery(query) {
|
|
39
|
+
const model = await this.getModel();
|
|
40
|
+
const prefix = this.config.queryPrefix ?? "";
|
|
41
|
+
const { embedding } = await embed({ model, value: prefix + query });
|
|
42
|
+
this.verifyDimensions(embedding);
|
|
43
|
+
return Vector.from(embedding);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check the configured width once, on the first embedding seen. A mismatch
|
|
47
|
+
* means the model is not the one the config describes, and every vector
|
|
48
|
+
* after this would be silently unusable against the index.
|
|
49
|
+
*/
|
|
50
|
+
verifyDimensions(vector) {
|
|
51
|
+
if (this.dimensionsChecked)
|
|
52
|
+
return;
|
|
53
|
+
this.dimensionsChecked = true;
|
|
54
|
+
if (this.config.dimensions != null &&
|
|
55
|
+
vector.length !== this.config.dimensions) {
|
|
56
|
+
throw new Error(`Embedding dimension mismatch: expected ${this.config.dimensions}, ` +
|
|
57
|
+
`got ${vector.length}. Check your model and config.dimensions.`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async getModel() {
|
|
61
|
+
if (this.model)
|
|
62
|
+
return this.model;
|
|
63
|
+
const reference = ModelReference.parse(this.config.model, "Model");
|
|
64
|
+
const instance = await this.providers.instantiate({
|
|
65
|
+
reference,
|
|
66
|
+
packageName: this.config.provider,
|
|
67
|
+
baseURL: this.config.baseURL,
|
|
68
|
+
// Historically the embedding path only falls back to the factory
|
|
69
|
+
// when there is no default export; see ProviderRequest.
|
|
70
|
+
preferFactoryWhenBaseUrlSet: false,
|
|
71
|
+
});
|
|
72
|
+
const registry = createProviderRegistry({
|
|
73
|
+
[reference.provider]: instance,
|
|
74
|
+
});
|
|
75
|
+
this.model = registry.embeddingModel(reference.full);
|
|
76
|
+
return this.model;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=AiSdkEmbedder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiSdkEmbedder.js","sourceRoot":"","sources":["../../../src/infrastructure/ai/AiSdkEmbedder.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,sBAAsB,EAEtB,KAAK,EACL,SAAS,GACT,MAAM,IAAI,CAAC;AAEZ,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AAEvD,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzE;;;;;;;GAOG;AACH,MAAM,OAAO,aAAa;IAKP;IACA;IALV,KAAK,CAA6B;IAClC,iBAAiB,GAAG,KAAK,CAAC;IAElC,YACkB,MAAoB,EACpB,YAA8B,IAAI,gBAAgB,EAAE;QADpD,WAAM,GAAN,MAAM,CAAc;QACpB,cAAS,GAAT,SAAS,CAA2C;IACnE,CAAC;IAEJ,KAAK,CAAC,cAAc,CAAC,KAAe;QACnC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACpC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,IAAI,EAAE,CAAC;QAChD,MAAM,GAAG,GAAa,EAAE,CAAC;QAEzB,yEAAyE;QACzE,8CAA8C;QAC9C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;YAC9D,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAA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,IAAI,KAAK,CACd,0CAA0C,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI;gBACnE,OAAO,MAAM,CAAC,MAAM,2CAA2C,CAChE,CAAC;QACH,CAAC;IACF,CAAC;IAEO,KAAK,CAAC,QAAQ;QACrB,IAAI,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC;QAElC,MAAM,SAAS,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACnE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC;YACjD,SAAS;YACT,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ;YACjC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;YAC5B,iEAAiE;YACjE,wDAAwD;YACxD,2BAA2B,EAAE,KAAK;SAClC,CAAC,CAAC;QAEH,MAAM,QAAQ,GAAG,sBAAsB,CAAC;YACvC,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,QAAQ;SACL,CAAC,CAAC;QAE5B,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,cAAc,CACnC,SAAS,CAAC,IAA6B,CACrB,CAAC;QACpB,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;CACD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query and document prefixes required by asymmetric embedding models.
|
|
3
|
+
*
|
|
4
|
+
* These models are trained with the prefixes present, and omitting them
|
|
5
|
+
* degrades retrieval without producing any error — the vectors are still
|
|
6
|
+
* valid, just worse. Nobody discovers that from the tool; they discover it
|
|
7
|
+
* from the model card, if at all. Setting them at `init` time is the only
|
|
8
|
+
* point where the model is actually known.
|
|
9
|
+
*
|
|
10
|
+
* Deliberately short: it covers only families whose prefixes are documented
|
|
11
|
+
* and unambiguous. An unrecognized model gets none, which is the safe default.
|
|
12
|
+
*/
|
|
13
|
+
export declare class EmbeddingPrefixes {
|
|
14
|
+
private static readonly KNOWN;
|
|
15
|
+
/** Prefixes for a model id, or undefined when none are known to apply. */
|
|
16
|
+
static forModel(modelId: string): {
|
|
17
|
+
query: string;
|
|
18
|
+
document: string;
|
|
19
|
+
family: string;
|
|
20
|
+
} | undefined;
|
|
21
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query and document prefixes required by asymmetric embedding models.
|
|
3
|
+
*
|
|
4
|
+
* These models are trained with the prefixes present, and omitting them
|
|
5
|
+
* degrades retrieval without producing any error — the vectors are still
|
|
6
|
+
* valid, just worse. Nobody discovers that from the tool; they discover it
|
|
7
|
+
* from the model card, if at all. Setting them at `init` time is the only
|
|
8
|
+
* point where the model is actually known.
|
|
9
|
+
*
|
|
10
|
+
* Deliberately short: it covers only families whose prefixes are documented
|
|
11
|
+
* and unambiguous. An unrecognized model gets none, which is the safe default.
|
|
12
|
+
*/
|
|
13
|
+
export class EmbeddingPrefixes {
|
|
14
|
+
static KNOWN = [
|
|
15
|
+
{
|
|
16
|
+
match: /nomic-embed/i,
|
|
17
|
+
query: "search_query: ",
|
|
18
|
+
document: "search_document: ",
|
|
19
|
+
family: "nomic-embed",
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
match: /(^|[^a-z])e5[-_]|multilingual-e5/i,
|
|
23
|
+
query: "query: ",
|
|
24
|
+
document: "passage: ",
|
|
25
|
+
family: "e5",
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
/** Prefixes for a model id, or undefined when none are known to apply. */
|
|
29
|
+
static forModel(modelId) {
|
|
30
|
+
const found = EmbeddingPrefixes.KNOWN.find((e) => e.match.test(modelId));
|
|
31
|
+
if (!found)
|
|
32
|
+
return undefined;
|
|
33
|
+
return {
|
|
34
|
+
query: found.query,
|
|
35
|
+
document: found.document,
|
|
36
|
+
family: found.family,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=EmbeddingPrefixes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EmbeddingPrefixes.js","sourceRoot":"","sources":["../../../src/infrastructure/ai/EmbeddingPrefixes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,iBAAiB;IACrB,MAAM,CAAU,KAAK,GAKxB;QACJ;YACC,KAAK,EAAE,cAAc;YACrB,KAAK,EAAE,gBAAgB;YACvB,QAAQ,EAAE,mBAAmB;YAC7B,MAAM,EAAE,aAAa;SACrB;QACD;YACC,KAAK,EAAE,mCAAmC;YAC1C,KAAK,EAAE,SAAS;YAChB,QAAQ,EAAE,WAAW;YACrB,MAAM,EAAE,IAAI;SACZ;KACD,CAAC;IAEF,0EAA0E;IAC1E,MAAM,CAAC,QAAQ,CACd,OAAe;QAEf,MAAM,KAAK,GAAG,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QACzE,IAAI,CAAC,KAAK;YAAE,OAAO,SAAS,CAAC;QAC7B,OAAO;YACN,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,MAAM,EAAE,KAAK,CAAC,MAAM;SACpB,CAAC;IACH,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DetectedRuntime, RuntimeProbe } from "./ModelRuntime.js";
|
|
2
|
+
/**
|
|
3
|
+
* Detects a local LM Studio server.
|
|
4
|
+
*
|
|
5
|
+
* LM Studio's native listing reports each model's type, so kinds come from the
|
|
6
|
+
* server rather than from guessing at names. Its OpenAI-compatible `/v1`
|
|
7
|
+
* surface is what the embedding calls actually use.
|
|
8
|
+
*/
|
|
9
|
+
export declare class LmStudioProbe implements RuntimeProbe {
|
|
10
|
+
private static readonly CATALOG_URL;
|
|
11
|
+
static readonly BASE_URL = "http://localhost:1234/v1";
|
|
12
|
+
/** LM Studio speaks OpenAI's protocol, not one of its own. */
|
|
13
|
+
static readonly PROVIDER_PACKAGE = "@ai-sdk/openai-compatible";
|
|
14
|
+
private static readonly TIMEOUT_MS;
|
|
15
|
+
detect(): Promise<DetectedRuntime | undefined>;
|
|
16
|
+
/** `vlm` is a vision-capable chat model, and answers text prompts fine. */
|
|
17
|
+
private static kindOf;
|
|
18
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects a local LM Studio server.
|
|
3
|
+
*
|
|
4
|
+
* LM Studio's native listing reports each model's type, so kinds come from the
|
|
5
|
+
* server rather than from guessing at names. Its OpenAI-compatible `/v1`
|
|
6
|
+
* surface is what the embedding calls actually use.
|
|
7
|
+
*/
|
|
8
|
+
export class LmStudioProbe {
|
|
9
|
+
static CATALOG_URL = "http://localhost:1234/api/v0/models";
|
|
10
|
+
static BASE_URL = "http://localhost:1234/v1";
|
|
11
|
+
/** LM Studio speaks OpenAI's protocol, not one of its own. */
|
|
12
|
+
static PROVIDER_PACKAGE = "@ai-sdk/openai-compatible";
|
|
13
|
+
static TIMEOUT_MS = 3000;
|
|
14
|
+
async detect() {
|
|
15
|
+
let payload;
|
|
16
|
+
try {
|
|
17
|
+
const res = await fetch(LmStudioProbe.CATALOG_URL, {
|
|
18
|
+
signal: AbortSignal.timeout(LmStudioProbe.TIMEOUT_MS),
|
|
19
|
+
});
|
|
20
|
+
if (!res.ok)
|
|
21
|
+
return undefined;
|
|
22
|
+
payload = (await res.json());
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
const models = (payload.data ?? []).map((m) => ({
|
|
28
|
+
id: m.id,
|
|
29
|
+
kind: LmStudioProbe.kindOf(m.type),
|
|
30
|
+
loaded: m.state === "loaded",
|
|
31
|
+
}));
|
|
32
|
+
return {
|
|
33
|
+
label: "LM Studio",
|
|
34
|
+
providerId: "lmstudio",
|
|
35
|
+
baseURL: LmStudioProbe.BASE_URL,
|
|
36
|
+
providerPackage: LmStudioProbe.PROVIDER_PACKAGE,
|
|
37
|
+
models,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/** `vlm` is a vision-capable chat model, and answers text prompts fine. */
|
|
41
|
+
static kindOf(type) {
|
|
42
|
+
if (type === "embeddings")
|
|
43
|
+
return "embedding";
|
|
44
|
+
if (type === "llm" || type === "vlm")
|
|
45
|
+
return "chat";
|
|
46
|
+
return "unknown";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=LmStudioProbe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LmStudioProbe.js","sourceRoot":"","sources":["../../../src/infrastructure/ai/LmStudioProbe.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,MAAM,OAAO,aAAa;IACjB,MAAM,CAAU,WAAW,GAAG,qCAAqC,CAAC;IAC5E,MAAM,CAAU,QAAQ,GAAG,0BAA0B,CAAC;IACtD,8DAA8D;IAC9D,MAAM,CAAU,gBAAgB,GAAG,2BAA2B,CAAC;IACvD,MAAM,CAAU,UAAU,GAAG,IAAI,CAAC;IAE1C,KAAK,CAAC,MAAM;QACX,IAAI,OAEH,CAAC;QACF,IAAI,CAAC;YACJ,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,aAAa,CAAC,WAAW,EAAE;gBAClD,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,aAAa,CAAC,UAAU,CAAC;aACrD,CAAC,CAAC;YACH,IAAI,CAAC,GAAG,CAAC,EAAE;gBAAE,OAAO,SAAS,CAAC;YAC9B,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAE1B,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACR,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,MAAM,MAAM,GAAqB,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACjE,EAAE,EAAE,CAAC,CAAC,EAAE;YACR,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;YAClC,MAAM,EAAE,CAAC,CAAC,KAAK,KAAK,QAAQ;SAC5B,CAAC,CAAC,CAAC;QAEJ,OAAO;YACN,KAAK,EAAE,WAAW;YAClB,UAAU,EAAE,UAAU;YACtB,OAAO,EAAE,aAAa,CAAC,QAAQ;YAC/B,eAAe,EAAE,aAAa,CAAC,gBAAgB;YAC/C,MAAM;SACN,CAAC;IACH,CAAC;IAED,2EAA2E;IACnE,MAAM,CAAC,MAAM,CAAC,IAAwB;QAC7C,IAAI,IAAI,KAAK,YAAY;YAAE,OAAO,WAAW,CAAC;QAC9C,IAAI,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK;YAAE,OAAO,MAAM,CAAC;QACpD,OAAO,SAAS,CAAC;IAClB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { LmgrepConfig } from "../../domain/config/LmgrepConfig.js";
|
|
2
|
+
/**
|
|
3
|
+
* Unloads and reloads a model on a local inference server.
|
|
4
|
+
*
|
|
5
|
+
* A local server that has wedged or evicted the model is the common cause of a
|
|
6
|
+
* run of embedding failures, and it recovers on a reload — worth one automatic
|
|
7
|
+
* attempt before abandoning a long index run. Remote providers are never
|
|
8
|
+
* reloaded: the request would be meaningless and possibly billable.
|
|
9
|
+
*/
|
|
10
|
+
export declare class LocalModelReloader {
|
|
11
|
+
private readonly config;
|
|
12
|
+
private static readonly LOOPBACK_HOSTS;
|
|
13
|
+
private static readonly UNLOAD_SETTLE_MS;
|
|
14
|
+
private static readonly DEFAULT_BASE_URL;
|
|
15
|
+
private static readonly DEFAULT_CONTEXT_LENGTH;
|
|
16
|
+
constructor(config: LmgrepConfig);
|
|
17
|
+
/** Whether the configured endpoint is a loopback address. */
|
|
18
|
+
get isLocal(): boolean;
|
|
19
|
+
/** Best-effort reload; false when the server does not cooperate. */
|
|
20
|
+
reload(): Promise<boolean>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unloads and reloads a model on a local inference server.
|
|
3
|
+
*
|
|
4
|
+
* A local server that has wedged or evicted the model is the common cause of a
|
|
5
|
+
* run of embedding failures, and it recovers on a reload — worth one automatic
|
|
6
|
+
* attempt before abandoning a long index run. Remote providers are never
|
|
7
|
+
* reloaded: the request would be meaningless and possibly billable.
|
|
8
|
+
*/
|
|
9
|
+
export class LocalModelReloader {
|
|
10
|
+
config;
|
|
11
|
+
static LOOPBACK_HOSTS = new Set([
|
|
12
|
+
"localhost",
|
|
13
|
+
"127.0.0.1",
|
|
14
|
+
"0.0.0.0",
|
|
15
|
+
]);
|
|
16
|
+
static UNLOAD_SETTLE_MS = 2000;
|
|
17
|
+
static DEFAULT_BASE_URL = "http://localhost:1234";
|
|
18
|
+
static DEFAULT_CONTEXT_LENGTH = 8192;
|
|
19
|
+
constructor(config) {
|
|
20
|
+
this.config = config;
|
|
21
|
+
}
|
|
22
|
+
/** Whether the configured endpoint is a loopback address. */
|
|
23
|
+
get isLocal() {
|
|
24
|
+
if (!this.config.baseURL)
|
|
25
|
+
return false;
|
|
26
|
+
try {
|
|
27
|
+
return LocalModelReloader.LOOPBACK_HOSTS.has(new URL(this.config.baseURL).hostname);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** Best-effort reload; false when the server does not cooperate. */
|
|
34
|
+
async reload() {
|
|
35
|
+
const modelId = this.config.model.split(":").slice(1).join(":");
|
|
36
|
+
const baseURL = this.config.baseURL ?? LocalModelReloader.DEFAULT_BASE_URL;
|
|
37
|
+
const apiBase = baseURL.replace(/\/v1\/?$/, "");
|
|
38
|
+
try {
|
|
39
|
+
await fetch(`${apiBase}/api/v1/models/unload`, {
|
|
40
|
+
method: "POST",
|
|
41
|
+
headers: { "Content-Type": "application/json" },
|
|
42
|
+
body: JSON.stringify({ instance_id: modelId }),
|
|
43
|
+
});
|
|
44
|
+
await new Promise((r) => setTimeout(r, LocalModelReloader.UNLOAD_SETTLE_MS));
|
|
45
|
+
const res = await fetch(`${apiBase}/api/v1/models/load`, {
|
|
46
|
+
method: "POST",
|
|
47
|
+
headers: { "Content-Type": "application/json" },
|
|
48
|
+
body: JSON.stringify({
|
|
49
|
+
model: modelId,
|
|
50
|
+
context_length: this.config.maxTokens ?? LocalModelReloader.DEFAULT_CONTEXT_LENGTH,
|
|
51
|
+
}),
|
|
52
|
+
});
|
|
53
|
+
await res.json();
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=LocalModelReloader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalModelReloader.js","sourceRoot":"","sources":["../../../src/infrastructure/ai/LocalModelReloader.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,OAAO,kBAAkB;IAUD;IATrB,MAAM,CAAU,cAAc,GAAG,IAAI,GAAG,CAAC;QAChD,WAAW;QACX,WAAW;QACX,SAAS;KACT,CAAC,CAAC;IACK,MAAM,CAAU,gBAAgB,GAAG,IAAI,CAAC;IACxC,MAAM,CAAU,gBAAgB,GAAG,uBAAuB,CAAC;IAC3D,MAAM,CAAU,sBAAsB,GAAG,IAAI,CAAC;IAEtD,YAA6B,MAAoB;QAApB,WAAM,GAAN,MAAM,CAAc;IAAG,CAAC;IAErD,6DAA6D;IAC7D,IAAI,OAAO;QACV,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO;YAAE,OAAO,KAAK,CAAC;QACvC,IAAI,CAAC;YACJ,OAAO,kBAAkB,CAAC,cAAc,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,CAAC,IAAI,EAAE,CAAC;YACjB,OAAO,IAAI,CAAC;QACb,CAAC;QAAC,MAAM,CAAC;YACR,OAAO,KAAK,CAAC;QACd,CAAC;IACF,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { CatalogedModel, DetectedRuntime, RuntimeProbe } from "./ModelRuntime.js";
|
|
2
|
+
/**
|
|
3
|
+
* Finds whichever local inference server is running.
|
|
4
|
+
*
|
|
5
|
+
* Probes run concurrently and the first *useful* result wins — a server with
|
|
6
|
+
* models beats one that is merely listening, so a running-but-empty Ollama
|
|
7
|
+
* does not shadow a fully set up LM Studio.
|
|
8
|
+
*/
|
|
9
|
+
export declare class LocalRuntimeDetector {
|
|
10
|
+
private readonly probes;
|
|
11
|
+
constructor(probes?: readonly RuntimeProbe[]);
|
|
12
|
+
detectAll(): Promise<DetectedRuntime[]>;
|
|
13
|
+
/** The best runtime to configure against, if any is usable. */
|
|
14
|
+
detectBest(): Promise<DetectedRuntime | undefined>;
|
|
15
|
+
/**
|
|
16
|
+
* Models the runtime says are embedders, best candidate first.
|
|
17
|
+
*
|
|
18
|
+
* A loaded model sorts ahead of the rest. Runtimes list models in an order
|
|
19
|
+
* of their own — LM Studio appears to use recency — and picking by position
|
|
20
|
+
* means the choice silently changes depending on what was used last.
|
|
21
|
+
* Load state is an explicit signal instead of an incidental one.
|
|
22
|
+
*/
|
|
23
|
+
static embeddingModels(runtime: DetectedRuntime): CatalogedModel[];
|
|
24
|
+
/** Stable sort putting loaded models first, order otherwise preserved. */
|
|
25
|
+
private static loadedFirst;
|
|
26
|
+
/**
|
|
27
|
+
* Models usable for `ask`. Only taken when the runtime typed them: guessing
|
|
28
|
+
* an embedder is a chat model produces a confusing failure at answer time.
|
|
29
|
+
*/
|
|
30
|
+
static chatModels(runtime: DetectedRuntime): CatalogedModel[];
|
|
31
|
+
/**
|
|
32
|
+
* Fallback for runtimes that do not type their models: anything not
|
|
33
|
+
* recognizable as an embedder.
|
|
34
|
+
*/
|
|
35
|
+
static untypedModels(runtime: DetectedRuntime): CatalogedModel[];
|
|
36
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { LmStudioProbe } from "./LmStudioProbe.js";
|
|
2
|
+
import { OllamaProbe } from "./OllamaProbe.js";
|
|
3
|
+
/**
|
|
4
|
+
* Finds whichever local inference server is running.
|
|
5
|
+
*
|
|
6
|
+
* Probes run concurrently and the first *useful* result wins — a server with
|
|
7
|
+
* models beats one that is merely listening, so a running-but-empty Ollama
|
|
8
|
+
* does not shadow a fully set up LM Studio.
|
|
9
|
+
*/
|
|
10
|
+
export class LocalRuntimeDetector {
|
|
11
|
+
probes;
|
|
12
|
+
constructor(probes = [
|
|
13
|
+
new LmStudioProbe(),
|
|
14
|
+
new OllamaProbe(),
|
|
15
|
+
]) {
|
|
16
|
+
this.probes = probes;
|
|
17
|
+
}
|
|
18
|
+
async detectAll() {
|
|
19
|
+
const results = await Promise.all(this.probes.map((p) => p.detect().catch(() => undefined)));
|
|
20
|
+
return results.filter((r) => r !== undefined);
|
|
21
|
+
}
|
|
22
|
+
/** The best runtime to configure against, if any is usable. */
|
|
23
|
+
async detectBest() {
|
|
24
|
+
const found = await this.detectAll();
|
|
25
|
+
return (found.find((r) => LocalRuntimeDetector.embeddingModels(r).length > 0) ??
|
|
26
|
+
found[0]);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Models the runtime says are embedders, best candidate first.
|
|
30
|
+
*
|
|
31
|
+
* A loaded model sorts ahead of the rest. Runtimes list models in an order
|
|
32
|
+
* of their own — LM Studio appears to use recency — and picking by position
|
|
33
|
+
* means the choice silently changes depending on what was used last.
|
|
34
|
+
* Load state is an explicit signal instead of an incidental one.
|
|
35
|
+
*/
|
|
36
|
+
static embeddingModels(runtime) {
|
|
37
|
+
return LocalRuntimeDetector.loadedFirst(runtime.models.filter((m) => m.kind === "embedding"));
|
|
38
|
+
}
|
|
39
|
+
/** Stable sort putting loaded models first, order otherwise preserved. */
|
|
40
|
+
static loadedFirst(models) {
|
|
41
|
+
return [
|
|
42
|
+
...models.filter((m) => m.loaded),
|
|
43
|
+
...models.filter((m) => !m.loaded),
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Models usable for `ask`. Only taken when the runtime typed them: guessing
|
|
48
|
+
* an embedder is a chat model produces a confusing failure at answer time.
|
|
49
|
+
*/
|
|
50
|
+
static chatModels(runtime) {
|
|
51
|
+
return LocalRuntimeDetector.loadedFirst(runtime.models.filter((m) => m.kind === "chat"));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Fallback for runtimes that do not type their models: anything not
|
|
55
|
+
* recognizable as an embedder.
|
|
56
|
+
*/
|
|
57
|
+
static untypedModels(runtime) {
|
|
58
|
+
return LocalRuntimeDetector.loadedFirst(runtime.models.filter((m) => m.kind === "unknown"));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=LocalRuntimeDetector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalRuntimeDetector.js","sourceRoot":"","sources":["../../../src/infrastructure/ai/LocalRuntimeDetector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAMnD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;;;;;GAMG;AACH,MAAM,OAAO,oBAAoB;IAEd;IADlB,YACkB,SAAkC;QAClD,IAAI,aAAa,EAAE;QACnB,IAAI,WAAW,EAAE;KACjB;QAHgB,WAAM,GAAN,MAAM,CAGtB;IACC,CAAC;IAEJ,KAAK,CAAC,SAAS;QACd,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAChC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CA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AC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAClD,CAAC;IACH,CAAC;CACD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** What a discovered model is good for. */
|
|
2
|
+
export type ModelKind = "embedding" | "chat" | "unknown";
|
|
3
|
+
export interface CatalogedModel {
|
|
4
|
+
id: string;
|
|
5
|
+
kind: ModelKind;
|
|
6
|
+
/**
|
|
7
|
+
* Currently loaded in the runtime.
|
|
8
|
+
*
|
|
9
|
+
* The strongest statement of intent available without asking: a model the
|
|
10
|
+
* user has deliberately loaded is the one they mean. Undefined when the
|
|
11
|
+
* runtime does not report load state.
|
|
12
|
+
*/
|
|
13
|
+
loaded?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** A local inference server that was found listening. */
|
|
16
|
+
export interface DetectedRuntime {
|
|
17
|
+
/** Human name, for what `init` prints. */
|
|
18
|
+
label: string;
|
|
19
|
+
/** Provider segment of the `provider:model` string. */
|
|
20
|
+
providerId: string;
|
|
21
|
+
baseURL: string;
|
|
22
|
+
/**
|
|
23
|
+
* AI SDK package to load. Undefined means the default
|
|
24
|
+
* `@ai-sdk/<providerId>` is correct.
|
|
25
|
+
*/
|
|
26
|
+
providerPackage?: string;
|
|
27
|
+
models: CatalogedModel[];
|
|
28
|
+
}
|
|
29
|
+
/** Detects one kind of local inference server. */
|
|
30
|
+
export interface RuntimeProbe {
|
|
31
|
+
detect(): Promise<DetectedRuntime | undefined>;
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModelRuntime.js","sourceRoot":"","sources":["../../../src/infrastructure/ai/ModelRuntime.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { DetectedRuntime, RuntimeProbe } from "./ModelRuntime.js";
|
|
2
|
+
/**
|
|
3
|
+
* Detects a local Ollama server.
|
|
4
|
+
*
|
|
5
|
+
* Ollama's tag listing does not say what a model is for, so kind is inferred
|
|
6
|
+
* from the name. That is a guess, and marked as one — `unknown` models are
|
|
7
|
+
* offered only when nothing better is found.
|
|
8
|
+
*/
|
|
9
|
+
export declare class OllamaProbe implements RuntimeProbe {
|
|
10
|
+
private static readonly TAGS_URL;
|
|
11
|
+
/** Models currently resident in memory. */
|
|
12
|
+
private static readonly RUNNING_URL;
|
|
13
|
+
static readonly BASE_URL = "http://localhost:11434/v1";
|
|
14
|
+
private static readonly TIMEOUT_MS;
|
|
15
|
+
/** Name fragments that reliably indicate an embedding model. */
|
|
16
|
+
private static readonly EMBEDDING_HINTS;
|
|
17
|
+
detect(): Promise<DetectedRuntime | undefined>;
|
|
18
|
+
/** Best-effort; an older Ollama without this endpoint just reports none. */
|
|
19
|
+
private loadedModelNames;
|
|
20
|
+
private static looksLikeEmbedding;
|
|
21
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects a local Ollama server.
|
|
3
|
+
*
|
|
4
|
+
* Ollama's tag listing does not say what a model is for, so kind is inferred
|
|
5
|
+
* from the name. That is a guess, and marked as one — `unknown` models are
|
|
6
|
+
* offered only when nothing better is found.
|
|
7
|
+
*/
|
|
8
|
+
export class OllamaProbe {
|
|
9
|
+
static TAGS_URL = "http://localhost:11434/api/tags";
|
|
10
|
+
/** Models currently resident in memory. */
|
|
11
|
+
static RUNNING_URL = "http://localhost:11434/api/ps";
|
|
12
|
+
static BASE_URL = "http://localhost:11434/v1";
|
|
13
|
+
static TIMEOUT_MS = 3000;
|
|
14
|
+
/** Name fragments that reliably indicate an embedding model. */
|
|
15
|
+
static EMBEDDING_HINTS = [
|
|
16
|
+
"embed",
|
|
17
|
+
"nomic",
|
|
18
|
+
"bge",
|
|
19
|
+
"minilm",
|
|
20
|
+
"gte-",
|
|
21
|
+
"e5-",
|
|
22
|
+
];
|
|
23
|
+
async detect() {
|
|
24
|
+
let payload;
|
|
25
|
+
try {
|
|
26
|
+
const res = await fetch(OllamaProbe.TAGS_URL, {
|
|
27
|
+
signal: AbortSignal.timeout(OllamaProbe.TIMEOUT_MS),
|
|
28
|
+
});
|
|
29
|
+
if (!res.ok)
|
|
30
|
+
return undefined;
|
|
31
|
+
payload = (await res.json());
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
const loaded = await this.loadedModelNames();
|
|
37
|
+
const models = (payload.models ?? []).map((m) => ({
|
|
38
|
+
id: m.name,
|
|
39
|
+
kind: OllamaProbe.looksLikeEmbedding(m.name) ? "embedding" : "unknown",
|
|
40
|
+
loaded: loaded.has(m.name),
|
|
41
|
+
}));
|
|
42
|
+
return {
|
|
43
|
+
label: "Ollama",
|
|
44
|
+
providerId: "ollama",
|
|
45
|
+
baseURL: OllamaProbe.BASE_URL,
|
|
46
|
+
models,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/** Best-effort; an older Ollama without this endpoint just reports none. */
|
|
50
|
+
async loadedModelNames() {
|
|
51
|
+
try {
|
|
52
|
+
const res = await fetch(OllamaProbe.RUNNING_URL, {
|
|
53
|
+
signal: AbortSignal.timeout(OllamaProbe.TIMEOUT_MS),
|
|
54
|
+
});
|
|
55
|
+
if (!res.ok)
|
|
56
|
+
return new Set();
|
|
57
|
+
const payload = (await res.json());
|
|
58
|
+
return new Set((payload.models ?? []).map((m) => m.name));
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return new Set();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
static looksLikeEmbedding(name) {
|
|
65
|
+
const lower = name.toLowerCase();
|
|
66
|
+
return OllamaProbe.EMBEDDING_HINTS.some((hint) => lower.includes(hint));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=OllamaProbe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OllamaProbe.js","sourceRoot":"","sources":["../../../src/infrastructure/ai/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,OAAO;YACN,KAAK,EAAE,QAAQ;YACf,UAAU,EAAE,QAAQ;YACpB,OAAO,EAAE,WAAW,CAAC,QAAQ;YAC7B,MAAM;SACN,CAAC;IACH,CAAC;IAED,4EAA4E;IACpE,KAAK,CAAC,gBAAgB;QAC7B,IAAI,CAAC;YACJ,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,WAAW,CAAC,WAAW,EAAE;gBAChD,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC;aACnD,CAAC,CAAC;YACH,IAAI,CAAC,GAAG,CAAC,EAAE;gBAAE,OAAO,IAAI,GAAG,EAAE,CAAC;YAC9B,MAAM,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAEhC,CAAC;YACF,OAAO,IAAI,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QAC3D,CAAC;QAAC,MAAM,CAAC;YACR,OAAO,IAAI,GAAG,EAAE,CAAC;QAClB,CAAC;IACF,CAAC;IAEO,MAAM,CAAC,kBAAkB,CAAC,IAAY;QAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QACjC,OAAO,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IACzE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Classifies provider errors that the research loop must handle differently
|
|
3
|
+
* from a genuine failure.
|
|
4
|
+
*
|
|
5
|
+
* A timeout and a context overflow both mean "the loop cannot continue, but
|
|
6
|
+
* what it gathered is still good" — they fall through to synthesis rather than
|
|
7
|
+
* degrading the whole run.
|
|
8
|
+
*/
|
|
9
|
+
export declare class ProviderFailure {
|
|
10
|
+
private static readonly OVERFLOW_PATTERN;
|
|
11
|
+
static isAbort(error: unknown): boolean;
|
|
12
|
+
/** A provider 400 whose body mentions the context window being exceeded. */
|
|
13
|
+
static isContextOverflow(error: unknown): boolean;
|
|
14
|
+
/** Opt-in diagnostics; provider errors carry detail worth seeing. */
|
|
15
|
+
static debug(where: string, error: unknown): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Classifies provider errors that the research loop must handle differently
|
|
3
|
+
* from a genuine failure.
|
|
4
|
+
*
|
|
5
|
+
* A timeout and a context overflow both mean "the loop cannot continue, but
|
|
6
|
+
* what it gathered is still good" — they fall through to synthesis rather than
|
|
7
|
+
* degrading the whole run.
|
|
8
|
+
*/
|
|
9
|
+
export class ProviderFailure {
|
|
10
|
+
static OVERFLOW_PATTERN = /context (size|length|window)|exceed|too (long|large)|max.*token/i;
|
|
11
|
+
static isAbort(error) {
|
|
12
|
+
return (error instanceof Error &&
|
|
13
|
+
(error.name === "AbortError" || error.name === "TimeoutError"));
|
|
14
|
+
}
|
|
15
|
+
/** A provider 400 whose body mentions the context window being exceeded. */
|
|
16
|
+
static isContextOverflow(error) {
|
|
17
|
+
const e = error;
|
|
18
|
+
if (e?.statusCode !== 400)
|
|
19
|
+
return false;
|
|
20
|
+
return ProviderFailure.OVERFLOW_PATTERN.test(`${e.responseBody ?? ""} ${e.message ?? ""}`);
|
|
21
|
+
}
|
|
22
|
+
/** Opt-in diagnostics; provider errors carry detail worth seeing. */
|
|
23
|
+
static debug(where, error) {
|
|
24
|
+
if (!process.env.LMGREP_DEBUG)
|
|
25
|
+
return;
|
|
26
|
+
const e = error;
|
|
27
|
+
console.error(`[lmgrep debug] ${where} error:`, {
|
|
28
|
+
name: e?.name,
|
|
29
|
+
message: e?.message,
|
|
30
|
+
statusCode: e?.statusCode,
|
|
31
|
+
responseBody: e?.responseBody,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=ProviderFailure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProviderFailure.js","sourceRoot":"","sources":["../../../src/infrastructure/ai/ProviderFailure.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,OAAO,eAAe;IACnB,MAAM,CAAU,gBAAgB,GACvC,kEAAkE,CAAC;IAEpE,MAAM,CAAC,OAAO,CAAC,KAAc;QAC5B,OAAO,CACN,KAAK,YAAY,KAAK;YACtB,CAAC,KAAK,CAAC,IAAI,KAAK,YAAY,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,CAAC,CAC9D,CAAC;IACH,CAAC;IAED,4EAA4E;IAC5E,MAAM,CAAC,iBAAiB,CAAC,KAAc;QACtC,MAAM,CAAC,GAAG,KAIT,CAAC;QACF,IAAI,CAAC,EAAE,UAAU,KAAK,GAAG;YAAE,OAAO,KAAK,CAAC;QACxC,OAAO,eAAe,CAAC,gBAAgB,CAAC,IAAI,CAC3C,GAAG,CAAC,CAAC,YAAY,IAAI,EAAE,IAAI,CAAC,CAAC,OAAO,IAAI,EAAE,EAAE,CAC5C,CAAC;IACH,CAAC;IAED,qEAAqE;IACrE,MAAM,CAAC,KAAK,CAAC,KAAa,EAAE,KAAc;QACzC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY;YAAE,OAAO;QACtC,MAAM,CAAC,GAAG,KAAgC,CAAC;QAC3C,OAAO,CAAC,KAAK,CAAC,kBAAkB,KAAK,SAAS,EAAE;YAC/C,IAAI,EAAE,CAAC,EAAE,IAAI;YACb,OAAO,EAAE,CAAC,EAAE,OAAO;YACnB,UAAU,EAAE,CAAC,EAAE,UAAU;YACzB,YAAY,EAAE,CAAC,EAAE,YAAY;SAC7B,CAAC,CAAC;IACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Imports an AI SDK provider package.
|
|
3
|
+
*
|
|
4
|
+
* Providers are peer dependencies the user installs, so resolution has to
|
|
5
|
+
* reach beyond this package's own `node_modules`: an `npm i -g @ai-sdk/openai`
|
|
6
|
+
* is a normal setup and would otherwise fail to resolve.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ProviderModuleLoader {
|
|
9
|
+
private readonly cache;
|
|
10
|
+
load(packageName: string): Promise<Record<string, unknown>>;
|
|
11
|
+
private resolve;
|
|
12
|
+
private globalModulePaths;
|
|
13
|
+
}
|