@viso/code-core
v0.0.7
Published
Core functionality for Code CLI
Readme
@viso/code-core
English | 中文
Core functionality and AI engine for the Code CLI ecosystem.
🚀 Features
- Multi-Provider Support: Works with various AI providers (SiliconFlow, LaoZhang, etc.)
- Intelligent Routing: Automatic provider selection based on performance and availability
- Tool System: Extensible tool framework for code operations
- Context Management: Advanced context handling for better AI responses
- Memory System: Persistent storage for conversations and code snippets
- Planning Engine: Advanced task decomposition and planning capabilities
📦 Installation
npm install @viso/code-core🔧 Usage
Basic Setup
import { EnhancedAIAssistant } from '@viso/code-core';
const assistant = new EnhancedAIAssistant({
providers: [
{
name: 'silicon-flow',
type: 'chat',
apiKey: 'your-api-key',
},
],
});AI Providers
import { SiliconFlowProvider } from '@viso/code-core/providers';
const provider = new SiliconFlowProvider({
apiKey: 'your-api-key',
model: 'deepseek-chat',
});
const response = await provider.chat([
{ role: 'user', content: 'Hello, world!' },
]);Tool System
import { ToolRegistry } from '@viso/code-core/tools';
const registry = new ToolRegistry();
// Register custom tools
registry.register('file-reader', {
name: 'File Reader',
description: 'Read file contents',
execute: async (path: string) => {
// Implementation
},
});Context Management
import { ContextManager } from '@viso/code-core';
const contextManager = new ContextManager();
// Add context
contextManager.addContext('project', {
name: 'My Project',
description: 'A TypeScript project',
files: ['src/index.ts', 'package.json'],
});
// Get relevant context
const context = contextManager.getRelevantContext('typescript');🏗️ Architecture
Core Components
- AI Engine: Main orchestrator for AI interactions
- Provider System: Abstraction layer for different AI services
- Tool Registry: Manages available tools and their execution
- Context Manager: Handles contextual information
- Memory System: Persistent storage for conversations
- Planning Engine: Task decomposition and planning
Provider Interface
interface AIProvider {
name: string;
type: ProviderType;
chat(messages: ChatMessage[]): Promise<ChatResponse>;
isAvailable(): Promise<boolean>;
}Tool Interface
interface Tool {
name: string;
description: string;
parameters: ToolParameter[];
execute(args: any): Promise<any>;
}📖 API Reference
Classes
EnhancedAIAssistant
Main class for AI interactions.
class EnhancedAIAssistant {
constructor(config: AIConfig);
async chat(message: string): Promise<ChatResponse>;
async executeCommand(command: string): Promise<CommandResult>;
async getContext(): Promise<Context>;
}ToolRegistry
Manages available tools.
class ToolRegistry {
register(name: string, tool: Tool): void;
unregister(name: string): void;
execute(name: string, args: any): Promise<any>;
list(): Tool[];
}ContextManager
Handles contextual information.
class ContextManager {
addContext(key: string, context: any): void;
getContext(key: string): any;
getRelevantContext(query: string): any[];
}🔧 Configuration
Environment Variables
# AI Provider Configuration
SILICON_FLOW_API_KEY=your-api-key
SILICON_FLOW_BASE_URL=https://api.siliconflow.cn
# Database Configuration
LANCEDB_PATH=./data/lancedb
MEMORY_ENABLED=true
# Tool Configuration
SHELL_TOOL_ENABLED=true
FILE_TOOL_ENABLED=trueConfiguration File
{
"providers": [
{
"name": "silicon-flow",
"type": "chat",
"apiKey": "${SILICON_FLOW_API_KEY}",
"baseUrl": "https://api.siliconflow.cn"
}
],
"tools": {
"enabled": ["shell", "file", "search"],
"shell": {
"timeout": 30000
}
},
"memory": {
"enabled": true,
"path": "./data/memory"
}
}🧪 Testing
npm test # Run all tests
npm run test:unit # Run unit tests
npm run test:integration # Run integration tests🔗 Related Packages
- @viso/code-shared - Shared types and utilities
- @viso/code-cli - Command line interface
🤝 Contributing
Contributions are welcome! Please read our contributing guidelines before submitting PRs.
📄 License
MIT License - see LICENSE for details.
