mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-01-31 06:42:03 +00:00
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
95 lines
2.1 KiB
TypeScript
95 lines
2.1 KiB
TypeScript
/**
|
|
* Abstract base class for AI model providers
|
|
*/
|
|
|
|
import type {
|
|
ProviderConfig,
|
|
ExecuteOptions,
|
|
ProviderMessage,
|
|
InstallationStatus,
|
|
ValidationResult,
|
|
ModelDefinition,
|
|
} from './types.js';
|
|
|
|
/**
|
|
* Base provider class that all provider implementations must extend
|
|
*/
|
|
export abstract class BaseProvider {
|
|
protected config: ProviderConfig;
|
|
protected name: string;
|
|
|
|
constructor(config: ProviderConfig = {}) {
|
|
this.config = config;
|
|
this.name = this.getName();
|
|
}
|
|
|
|
/**
|
|
* Get the provider name (e.g., "claude", "cursor")
|
|
*/
|
|
abstract getName(): string;
|
|
|
|
/**
|
|
* Execute a query and stream responses
|
|
* @param options Execution options
|
|
* @returns AsyncGenerator yielding provider messages
|
|
*/
|
|
abstract executeQuery(options: ExecuteOptions): AsyncGenerator<ProviderMessage>;
|
|
|
|
/**
|
|
* Detect if the provider is installed and configured
|
|
* @returns Installation status
|
|
*/
|
|
abstract detectInstallation(): Promise<InstallationStatus>;
|
|
|
|
/**
|
|
* Get available models for this provider
|
|
* @returns Array of model definitions
|
|
*/
|
|
abstract getAvailableModels(): ModelDefinition[];
|
|
|
|
/**
|
|
* Validate the provider configuration
|
|
* @returns Validation result
|
|
*/
|
|
validateConfig(): ValidationResult {
|
|
const errors: string[] = [];
|
|
const warnings: string[] = [];
|
|
|
|
// Base validation (can be overridden)
|
|
if (!this.config) {
|
|
errors.push('Provider config is missing');
|
|
}
|
|
|
|
return {
|
|
valid: errors.length === 0,
|
|
errors,
|
|
warnings,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Check if the provider supports a specific feature
|
|
* @param feature Feature name (e.g., "vision", "tools", "mcp")
|
|
* @returns Whether the feature is supported
|
|
*/
|
|
supportsFeature(feature: string): boolean {
|
|
// Default implementation - override in subclasses
|
|
const commonFeatures = ['tools', 'text'];
|
|
return commonFeatures.includes(feature);
|
|
}
|
|
|
|
/**
|
|
* Get provider configuration
|
|
*/
|
|
getConfig(): ProviderConfig {
|
|
return this.config;
|
|
}
|
|
|
|
/**
|
|
* Update provider configuration
|
|
*/
|
|
setConfig(config: Partial<ProviderConfig>): void {
|
|
this.config = { ...this.config, ...config };
|
|
}
|
|
}
|