feat: make @anthropic-ai/claude-code an optional dependency
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.
This commit is contained in:
committed by
Ralph Khreish
parent
5c726dc542
commit
0840ad8316
@@ -623,7 +623,7 @@ function createProjectStructure(
|
|||||||
...replacements
|
...replacements
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// Update config.json with correct maxTokens values from supported-models.json
|
// Update config.json with correct maxTokens values from supported-models.json
|
||||||
const configPath = path.join(targetDir, TASKMASTER_CONFIG_FILE);
|
const configPath = path.join(targetDir, TASKMASTER_CONFIG_FILE);
|
||||||
if (updateConfigMaxTokens(configPath)) {
|
if (updateConfigMaxTokens(configPath)) {
|
||||||
|
|||||||
@@ -20,29 +20,33 @@ export function updateConfigMaxTokens(configPath) {
|
|||||||
try {
|
try {
|
||||||
// Load supported models
|
// Load supported models
|
||||||
const supportedModelsPath = path.join(__dirname, 'supported-models.json');
|
const supportedModelsPath = path.join(__dirname, 'supported-models.json');
|
||||||
const supportedModels = JSON.parse(fs.readFileSync(supportedModelsPath, 'utf-8'));
|
const supportedModels = JSON.parse(
|
||||||
|
fs.readFileSync(supportedModelsPath, 'utf-8')
|
||||||
|
);
|
||||||
|
|
||||||
// Load config
|
// Load config
|
||||||
const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
||||||
|
|
||||||
// Update each role's maxTokens if the model exists in supported-models.json
|
// Update each role's maxTokens if the model exists in supported-models.json
|
||||||
const roles = ['main', 'research', 'fallback'];
|
const roles = ['main', 'research', 'fallback'];
|
||||||
|
|
||||||
for (const role of roles) {
|
for (const role of roles) {
|
||||||
if (config.models && config.models[role]) {
|
if (config.models && config.models[role]) {
|
||||||
const provider = config.models[role].provider;
|
const provider = config.models[role].provider;
|
||||||
const modelId = config.models[role].modelId;
|
const modelId = config.models[role].modelId;
|
||||||
|
|
||||||
// Find the model in supported models
|
// Find the model in supported models
|
||||||
if (supportedModels[provider]) {
|
if (supportedModels[provider]) {
|
||||||
const modelData = supportedModels[provider].find(m => m.id === modelId);
|
const modelData = supportedModels[provider].find(
|
||||||
|
(m) => m.id === modelId
|
||||||
|
);
|
||||||
if (modelData && modelData.max_tokens) {
|
if (modelData && modelData.max_tokens) {
|
||||||
config.models[role].maxTokens = modelData.max_tokens;
|
config.models[role].maxTokens = modelData.max_tokens;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write back the updated config
|
// Write back the updated config
|
||||||
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
||||||
return true;
|
return true;
|
||||||
@@ -50,4 +54,4 @@ export function updateConfigMaxTokens(configPath) {
|
|||||||
console.error('Error updating config maxTokens:', error.message);
|
console.error('Error updating config maxTokens:', error.message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user