This change makes the Claude Code SDK package optional, preventing installation failures for users who don't need Claude Code functionality. Changes: - Added @anthropic-ai/claude-code to optionalDependencies in package.json - Implemented lazy loading in language-model.js to only import the SDK when actually used - Updated documentation to explain the optional installation requirement - Applied formatting fixes to ensure code consistency Benefits: - Users without Claude Code subscriptions don't need to install the dependency - Reduces package size for users who don't use Claude Code - Prevents installation failures if the package is unavailable - Provides clear error messages when the package is needed but not installed The implementation uses dynamic imports to load the SDK only when doGenerate() or doStream() is called, ensuring the provider can be instantiated without the package present.
48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
/**
|
|
* src/ai-providers/claude-code.js
|
|
*
|
|
* Implementation for interacting with Claude models via Claude Code CLI
|
|
* using a custom AI SDK implementation.
|
|
*/
|
|
|
|
import { createClaudeCode } from './custom-sdk/claude-code/index.js';
|
|
import { BaseAIProvider } from './base-provider.js';
|
|
|
|
export class ClaudeCodeProvider extends BaseAIProvider {
|
|
constructor() {
|
|
super();
|
|
this.name = 'Claude Code';
|
|
}
|
|
|
|
/**
|
|
* Override validateAuth to skip API key validation for Claude Code
|
|
* @param {object} params - Parameters to validate
|
|
*/
|
|
validateAuth(params) {
|
|
// Claude Code doesn't require an API key
|
|
// No validation needed
|
|
}
|
|
|
|
/**
|
|
* Creates and returns a Claude Code client instance.
|
|
* @param {object} params - Parameters for client initialization
|
|
* @param {string} [params.baseURL] - Optional custom API endpoint (not used by Claude Code)
|
|
* @returns {Function} Claude Code client function
|
|
* @throws {Error} If initialization fails
|
|
*/
|
|
getClient(params) {
|
|
try {
|
|
// Claude Code doesn't use API keys or base URLs
|
|
// Just return the provider factory
|
|
return createClaudeCode({
|
|
defaultSettings: {
|
|
// Add any default settings if needed
|
|
// These can be overridden per request
|
|
}
|
|
});
|
|
} catch (error) {
|
|
this.handleError('client initialization', error);
|
|
}
|
|
}
|
|
}
|