mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-01 20:23:36 +00:00
feat: unified Claude API key and profile system with z.AI, MiniMax, OpenRouter support (#600)
* feat: add Claude API provider profiles for alternative endpoints Add support for managing multiple Claude-compatible API endpoints (z.AI GLM, AWS Bedrock, etc.) through provider profiles in settings. Features: - New ClaudeApiProfile type with base URL, API key, model mappings - Pre-configured z.AI GLM template with correct model names - Profile selector in Settings > Claude > API Profiles - Clean switching between profiles and direct Anthropic API - Immediate persistence to prevent data loss on restart Profile support added to all execution paths: - Agent service (chat) - Ideation service - Auto-mode service (feature agents, enhancements) - Simple query service (title generation, descriptions, etc.) - Backlog planning, commit messages, spec generation - GitHub issue validation, suggestions Environment variables set when profile is active: - ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN/API_KEY - ANTHROPIC_DEFAULT_HAIKU/SONNET/OPUS_MODEL - API_TIMEOUT_MS, CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC
This commit is contained in:
committed by
GitHub
parent
63b8eb0991
commit
d97c4b7b57
@@ -29,6 +29,7 @@ import {
|
||||
getSkillsConfiguration,
|
||||
getSubagentsConfiguration,
|
||||
getCustomSubagents,
|
||||
getActiveClaudeApiProfile,
|
||||
} from '../lib/settings-helpers.js';
|
||||
|
||||
interface Message {
|
||||
@@ -274,6 +275,13 @@ export class AgentService {
|
||||
? await getCustomSubagents(this.settingsService, effectiveWorkDir)
|
||||
: undefined;
|
||||
|
||||
// Get active Claude API profile for alternative endpoint configuration
|
||||
const { profile: claudeApiProfile, credentials } = await getActiveClaudeApiProfile(
|
||||
this.settingsService,
|
||||
'[AgentService]',
|
||||
effectiveWorkDir
|
||||
);
|
||||
|
||||
// Load project context files (CLAUDE.md, CODE_QUALITY.md, etc.) and memory files
|
||||
// Use the user's message as task context for smart memory selection
|
||||
const contextResult = await loadContextFiles({
|
||||
@@ -378,6 +386,8 @@ export class AgentService {
|
||||
agents: customSubagents, // Pass custom subagents for task delegation
|
||||
thinkingLevel: effectiveThinkingLevel, // Pass thinking level for Claude models
|
||||
reasoningEffort: effectiveReasoningEffort, // Pass reasoning effort for Codex models
|
||||
claudeApiProfile, // Pass active Claude API profile for alternative endpoint configuration
|
||||
credentials, // Pass credentials for resolving 'credentials' apiKeySource
|
||||
};
|
||||
|
||||
// Build prompt content with images
|
||||
|
||||
@@ -63,6 +63,7 @@ import {
|
||||
filterClaudeMdFromContext,
|
||||
getMCPServersFromSettings,
|
||||
getPromptCustomization,
|
||||
getActiveClaudeApiProfile,
|
||||
} from '../lib/settings-helpers.js';
|
||||
import { getNotificationService } from './notification-service.js';
|
||||
|
||||
@@ -2057,6 +2058,13 @@ Format your response as a structured markdown document.`;
|
||||
thinkingLevel: analysisThinkingLevel,
|
||||
});
|
||||
|
||||
// Get active Claude API profile for alternative endpoint configuration
|
||||
const { profile: claudeApiProfile, credentials } = await getActiveClaudeApiProfile(
|
||||
this.settingsService,
|
||||
'[AutoMode]',
|
||||
projectPath
|
||||
);
|
||||
|
||||
const options: ExecuteOptions = {
|
||||
prompt,
|
||||
model: sdkOptions.model ?? analysisModel,
|
||||
@@ -2066,6 +2074,8 @@ Format your response as a structured markdown document.`;
|
||||
abortController,
|
||||
settingSources: sdkOptions.settingSources,
|
||||
thinkingLevel: analysisThinkingLevel, // Pass thinking level
|
||||
claudeApiProfile, // Pass active Claude API profile for alternative endpoint configuration
|
||||
credentials, // Pass credentials for resolving 'credentials' apiKeySource
|
||||
};
|
||||
|
||||
const stream = provider.executeQuery(options);
|
||||
@@ -2934,6 +2944,13 @@ This mock response was generated because AUTOMAKER_MOCK_AGENT=true was set.
|
||||
);
|
||||
}
|
||||
|
||||
// Get active Claude API profile for alternative endpoint configuration
|
||||
const { profile: claudeApiProfile, credentials } = await getActiveClaudeApiProfile(
|
||||
this.settingsService,
|
||||
'[AutoMode]',
|
||||
finalProjectPath
|
||||
);
|
||||
|
||||
const executeOptions: ExecuteOptions = {
|
||||
prompt: promptContent,
|
||||
model: bareModel,
|
||||
@@ -2945,6 +2962,8 @@ This mock response was generated because AUTOMAKER_MOCK_AGENT=true was set.
|
||||
settingSources: sdkOptions.settingSources,
|
||||
mcpServers: Object.keys(mcpServers).length > 0 ? mcpServers : undefined, // Pass MCP servers configuration
|
||||
thinkingLevel: options?.thinkingLevel, // Pass thinking level for extended thinking
|
||||
claudeApiProfile, // Pass active Claude API profile for alternative endpoint configuration
|
||||
credentials, // Pass credentials for resolving 'credentials' apiKeySource
|
||||
};
|
||||
|
||||
// Execute via provider
|
||||
@@ -3247,6 +3266,8 @@ After generating the revised spec, output:
|
||||
allowedTools: allowedTools,
|
||||
abortController,
|
||||
mcpServers: Object.keys(mcpServers).length > 0 ? mcpServers : undefined,
|
||||
claudeApiProfile, // Pass active Claude API profile for alternative endpoint configuration
|
||||
credentials, // Pass credentials for resolving 'credentials' apiKeySource
|
||||
});
|
||||
|
||||
let revisionText = '';
|
||||
@@ -3392,6 +3413,8 @@ After generating the revised spec, output:
|
||||
allowedTools: allowedTools,
|
||||
abortController,
|
||||
mcpServers: Object.keys(mcpServers).length > 0 ? mcpServers : undefined,
|
||||
claudeApiProfile, // Pass active Claude API profile for alternative endpoint configuration
|
||||
credentials, // Pass credentials for resolving 'credentials' apiKeySource
|
||||
});
|
||||
|
||||
let taskOutput = '';
|
||||
@@ -3486,6 +3509,8 @@ After generating the revised spec, output:
|
||||
allowedTools: allowedTools,
|
||||
abortController,
|
||||
mcpServers: Object.keys(mcpServers).length > 0 ? mcpServers : undefined,
|
||||
claudeApiProfile, // Pass active Claude API profile for alternative endpoint configuration
|
||||
credentials, // Pass credentials for resolving 'credentials' apiKeySource
|
||||
});
|
||||
|
||||
for await (const msg of continuationStream) {
|
||||
|
||||
@@ -41,7 +41,7 @@ import type { FeatureLoader } from './feature-loader.js';
|
||||
import { createChatOptions, validateWorkingDirectory } from '../lib/sdk-options.js';
|
||||
import { resolveModelString } from '@automaker/model-resolver';
|
||||
import { stripProviderPrefix } from '@automaker/types';
|
||||
import { getPromptCustomization } from '../lib/settings-helpers.js';
|
||||
import { getPromptCustomization, getActiveClaudeApiProfile } from '../lib/settings-helpers.js';
|
||||
|
||||
const logger = createLogger('IdeationService');
|
||||
|
||||
@@ -223,6 +223,13 @@ export class IdeationService {
|
||||
// Strip provider prefix - providers need bare model IDs
|
||||
const bareModel = stripProviderPrefix(modelId);
|
||||
|
||||
// Get active Claude API profile for alternative endpoint configuration
|
||||
const { profile: claudeApiProfile, credentials } = await getActiveClaudeApiProfile(
|
||||
this.settingsService,
|
||||
'[IdeationService]',
|
||||
projectPath
|
||||
);
|
||||
|
||||
const executeOptions: ExecuteOptions = {
|
||||
prompt: message,
|
||||
model: bareModel,
|
||||
@@ -232,6 +239,8 @@ export class IdeationService {
|
||||
maxTurns: 1, // Single turn for ideation
|
||||
abortController: activeSession.abortController!,
|
||||
conversationHistory: conversationHistory.length > 0 ? conversationHistory : undefined,
|
||||
claudeApiProfile, // Pass active Claude API profile for alternative endpoint configuration
|
||||
credentials, // Pass credentials for resolving 'credentials' apiKeySource
|
||||
};
|
||||
|
||||
const stream = provider.executeQuery(executeOptions);
|
||||
@@ -678,6 +687,13 @@ export class IdeationService {
|
||||
// Strip provider prefix - providers need bare model IDs
|
||||
const bareModel = stripProviderPrefix(modelId);
|
||||
|
||||
// Get active Claude API profile for alternative endpoint configuration
|
||||
const { profile: claudeApiProfile, credentials } = await getActiveClaudeApiProfile(
|
||||
this.settingsService,
|
||||
'[IdeationService]',
|
||||
projectPath
|
||||
);
|
||||
|
||||
const executeOptions: ExecuteOptions = {
|
||||
prompt: prompt.prompt,
|
||||
model: bareModel,
|
||||
@@ -688,6 +704,8 @@ export class IdeationService {
|
||||
// Disable all tools - we just want text generation, not codebase analysis
|
||||
allowedTools: [],
|
||||
abortController: new AbortController(),
|
||||
claudeApiProfile, // Pass active Claude API profile for alternative endpoint configuration
|
||||
credentials, // Pass credentials for resolving 'credentials' apiKeySource
|
||||
};
|
||||
|
||||
const stream = provider.executeQuery(executeOptions);
|
||||
|
||||
@@ -166,6 +166,41 @@ export class SettingsService {
|
||||
needsSave = true;
|
||||
}
|
||||
|
||||
// Migration v4 -> v5: Auto-create "Direct Anthropic" profile for existing users
|
||||
// If user has an Anthropic API key in credentials but no profiles, create a
|
||||
// "Direct Anthropic" profile that references the credentials and set it as active.
|
||||
if (storedVersion < 5) {
|
||||
try {
|
||||
const credentials = await this.getCredentials();
|
||||
const hasAnthropicKey = !!credentials.apiKeys?.anthropic;
|
||||
const hasNoProfiles = !result.claudeApiProfiles || result.claudeApiProfiles.length === 0;
|
||||
const hasNoActiveProfile = !result.activeClaudeApiProfileId;
|
||||
|
||||
if (hasAnthropicKey && hasNoProfiles && hasNoActiveProfile) {
|
||||
const directAnthropicProfile = {
|
||||
id: `profile-${Date.now()}-direct-anthropic`,
|
||||
name: 'Direct Anthropic',
|
||||
baseUrl: 'https://api.anthropic.com',
|
||||
apiKeySource: 'credentials' as const,
|
||||
useAuthToken: false,
|
||||
};
|
||||
|
||||
result.claudeApiProfiles = [directAnthropicProfile];
|
||||
result.activeClaudeApiProfileId = directAnthropicProfile.id;
|
||||
|
||||
logger.info(
|
||||
'Migration v4->v5: Created "Direct Anthropic" profile using existing credentials'
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.warn(
|
||||
'Migration v4->v5: Could not check credentials for auto-profile creation:',
|
||||
error
|
||||
);
|
||||
}
|
||||
needsSave = true;
|
||||
}
|
||||
|
||||
// Update version if any migration occurred
|
||||
if (needsSave) {
|
||||
result.version = SETTINGS_VERSION;
|
||||
@@ -372,6 +407,7 @@ export class SettingsService {
|
||||
ignoreEmptyArrayOverwrite('recentFolders');
|
||||
ignoreEmptyArrayOverwrite('mcpServers');
|
||||
ignoreEmptyArrayOverwrite('enabledCursorModels');
|
||||
ignoreEmptyArrayOverwrite('claudeApiProfiles');
|
||||
|
||||
// Empty object overwrite guard
|
||||
if (
|
||||
@@ -597,6 +633,17 @@ export class SettingsService {
|
||||
};
|
||||
}
|
||||
|
||||
// Handle activeClaudeApiProfileId special cases:
|
||||
// - "__USE_GLOBAL__" marker means delete the key (use global setting)
|
||||
// - null means explicit "Direct Anthropic API"
|
||||
// - string means specific profile ID
|
||||
if (
|
||||
'activeClaudeApiProfileId' in updates &&
|
||||
updates.activeClaudeApiProfileId === '__USE_GLOBAL__'
|
||||
) {
|
||||
delete updated.activeClaudeApiProfileId;
|
||||
}
|
||||
|
||||
await writeSettingsJson(settingsPath, updated);
|
||||
logger.info(`Project settings updated for ${projectPath}`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user