mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-02 08:33:36 +00:00
feat: Claude Compatible Providers System (#629)
* feat: refactor Claude API Profiles to Claude Compatible Providers
- Rename ClaudeApiProfile to ClaudeCompatibleProvider with models[] array
- Each ProviderModel has mapsToClaudeModel field for Claude tier mapping
- Add providerType field for provider-specific icons (glm, minimax, openrouter)
- Add thinking level support for provider models in phase selectors
- Show all mapped Claude models per provider model (e.g., "Maps to Haiku, Sonnet, Opus")
- Add Bulk Replace feature to switch all phases to a provider at once
- Hide Bulk Replace button when no providers are enabled
- Fix project-level phaseModelOverrides not persisting after refresh
- Fix deleting last provider not persisting (remove empty array guard)
- Add getProviderByModelId() helper for all SDK routes
- Update all routes to pass provider config for provider models
- Update terminology from "profiles" to "providers" throughout UI
- Update documentation to reflect new provider system
* fix: atomic writer race condition and bulk replace reset to defaults
1. AtomicWriter Race Condition Fix (libs/utils/src/atomic-writer.ts):
- Changed temp file naming from Date.now() to Date.now() + random hex
- Uses crypto.randomBytes(4).toString('hex') for uniqueness
- Prevents ENOENT errors when multiple concurrent writes happen
within the same millisecond
2. Bulk Replace "Anthropic Direct" Reset (both dialogs):
- When selecting "Anthropic Direct", now uses DEFAULT_PHASE_MODELS
- Properly resets thinking levels and other settings to defaults
- Added thinkingLevel to the change detection comparison
- Affects both global and project-level bulk replace dialogs
* fix: update tests for new model resolver passthrough behavior
1. model-resolver tests:
- Unknown models now pass through unchanged (provider model support)
- Removed expectations for warnings on unknown models
- Updated case sensitivity and edge case tests accordingly
- Added tests for provider-like model names (GLM-4.7, MiniMax-M2.1)
2. atomic-writer tests:
- Updated regex to match new temp file format with random suffix
- Format changed from .tmp.{timestamp} to .tmp.{timestamp}.{hex}
* refactor: simplify getPhaseModelWithOverrides calls per code review
Address code review feedback on PR #629:
- Make settingsService parameter optional in getPhaseModelWithOverrides
- Function now handles undefined settingsService gracefully by returning defaults
- Remove redundant ternary checks in 4 call sites:
- apps/server/src/routes/context/routes/describe-file.ts
- apps/server/src/routes/context/routes/describe-image.ts
- apps/server/src/routes/worktree/routes/generate-commit-message.ts
- apps/server/src/services/auto-mode-service.ts
- Remove unused DEFAULT_PHASE_MODELS imports where applicable
* test: fix server tests for provider model passthrough behavior
- Update model-resolver.test.ts to expect unknown models to pass through
unchanged (supports ClaudeCompatibleProvider models like GLM-4.7)
- Remove warning expectations for unknown models (valid for providers)
- Add missing getCredentials and getGlobalSettings mocks to
ideation-service.test.ts for settingsService
* fix: address code review feedback for model providers
- Honor thinkingLevel in generate-commit-message.ts
- Pass claudeCompatibleProvider in ideation-service.ts for provider models
- Resolve provider configuration for model overrides in generate-suggestions.ts
- Update "Active Profile" to "Active Provider" label in project-claude-section
- Use substring instead of deprecated substr in api-profiles-section
- Preserve provider enabled state when editing in api-profiles-section
* fix: address CodeRabbit review issues for Claude Compatible Providers
- Fix TypeScript TS2339 error in generate-suggestions.ts where
settingsService was narrowed to 'never' type in else branch
- Use DEFAULT_PHASE_MODELS per-phase defaults instead of hardcoded
'sonnet' in settings-helpers.ts
- Remove duplicate eventHooks key in use-settings-migration.ts
- Add claudeCompatibleProviders to localStorage migration parsing
and merging functions
- Handle canonical claude-* model IDs (claude-haiku, claude-sonnet,
claude-opus) in project-models-section display names
This resolves the CI build failures and addresses code review feedback.
* fix: skip broken list-view-priority E2E test and add Priority column label
- Skip list-view-priority.spec.ts with TODO explaining the infrastructure
issue: setupRealProject only sets localStorage but server settings
take precedence with localStorageMigrated: true
- Add 'Priority' label to list-header.tsx for the priority column
(was empty string, now shows proper header text)
- Increase column width to accommodate the label
The E2E test issue is that tests create features in a temp directory,
but the server loads from the E2E Test Project fixture path set in
setup-e2e-fixtures.mjs. Needs infrastructure fix to properly switch
projects or create features through UI instead of on disk.
This commit is contained in:
committed by
GitHub
parent
8facdc66a9
commit
a1f234c7e2
@@ -29,7 +29,7 @@ import {
|
||||
getSkillsConfiguration,
|
||||
getSubagentsConfiguration,
|
||||
getCustomSubagents,
|
||||
getActiveClaudeApiProfile,
|
||||
getProviderByModelId,
|
||||
} from '../lib/settings-helpers.js';
|
||||
|
||||
interface Message {
|
||||
@@ -275,12 +275,29 @@ 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
|
||||
);
|
||||
// Get credentials for API calls
|
||||
const credentials = await this.settingsService?.getCredentials();
|
||||
|
||||
// Try to find a provider for the model (if it's a provider model like "GLM-4.7")
|
||||
// This allows users to select provider models in the Agent Runner UI
|
||||
let claudeCompatibleProvider: import('@automaker/types').ClaudeCompatibleProvider | undefined;
|
||||
let providerResolvedModel: string | undefined;
|
||||
const requestedModel = model || session.model;
|
||||
if (requestedModel && this.settingsService) {
|
||||
const providerResult = await getProviderByModelId(
|
||||
requestedModel,
|
||||
this.settingsService,
|
||||
'[AgentService]'
|
||||
);
|
||||
if (providerResult.provider) {
|
||||
claudeCompatibleProvider = providerResult.provider;
|
||||
providerResolvedModel = providerResult.resolvedModel;
|
||||
this.logger.info(
|
||||
`[AgentService] Using provider "${providerResult.provider.name}" for model "${requestedModel}"` +
|
||||
(providerResolvedModel ? ` -> resolved to "${providerResolvedModel}"` : '')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
@@ -307,10 +324,16 @@ export class AgentService {
|
||||
// Use thinking level and reasoning effort from request, or fall back to session's stored values
|
||||
const effectiveThinkingLevel = thinkingLevel ?? session.thinkingLevel;
|
||||
const effectiveReasoningEffort = reasoningEffort ?? session.reasoningEffort;
|
||||
|
||||
// When using a provider model, use the resolved Claude model (from mapsToClaudeModel)
|
||||
// e.g., "GLM-4.5-Air" -> "claude-haiku-4-5"
|
||||
const modelForSdk = providerResolvedModel || model;
|
||||
const sessionModelForSdk = providerResolvedModel ? undefined : session.model;
|
||||
|
||||
const sdkOptions = createChatOptions({
|
||||
cwd: effectiveWorkDir,
|
||||
model: model,
|
||||
sessionModel: session.model,
|
||||
model: modelForSdk,
|
||||
sessionModel: sessionModelForSdk,
|
||||
systemPrompt: combinedSystemPrompt,
|
||||
abortController: session.abortController!,
|
||||
autoLoadClaudeMd,
|
||||
@@ -386,8 +409,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
|
||||
claudeCompatibleProvider, // Pass provider for alternative endpoint configuration (GLM, MiniMax, etc.)
|
||||
};
|
||||
|
||||
// Build prompt content with images
|
||||
|
||||
@@ -68,7 +68,8 @@ import {
|
||||
filterClaudeMdFromContext,
|
||||
getMCPServersFromSettings,
|
||||
getPromptCustomization,
|
||||
getActiveClaudeApiProfile,
|
||||
getProviderByModelId,
|
||||
getPhaseModelWithOverrides,
|
||||
} from '../lib/settings-helpers.js';
|
||||
import { getNotificationService } from './notification-service.js';
|
||||
|
||||
@@ -2331,13 +2332,24 @@ Address the follow-up instructions above. Review the previous work and make the
|
||||
Format your response as a structured markdown document.`;
|
||||
|
||||
try {
|
||||
// Get model from phase settings
|
||||
const settings = await this.settingsService?.getGlobalSettings();
|
||||
const phaseModelEntry =
|
||||
settings?.phaseModels?.projectAnalysisModel || DEFAULT_PHASE_MODELS.projectAnalysisModel;
|
||||
// Get model from phase settings with provider info
|
||||
const {
|
||||
phaseModel: phaseModelEntry,
|
||||
provider: analysisClaudeProvider,
|
||||
credentials,
|
||||
} = await getPhaseModelWithOverrides(
|
||||
'projectAnalysisModel',
|
||||
this.settingsService,
|
||||
projectPath,
|
||||
'[AutoMode]'
|
||||
);
|
||||
const { model: analysisModel, thinkingLevel: analysisThinkingLevel } =
|
||||
resolvePhaseModel(phaseModelEntry);
|
||||
logger.info('Using model for project analysis:', analysisModel);
|
||||
logger.info(
|
||||
'Using model for project analysis:',
|
||||
analysisModel,
|
||||
analysisClaudeProvider ? `via provider: ${analysisClaudeProvider.name}` : 'direct API'
|
||||
);
|
||||
|
||||
const provider = ProviderFactory.getProviderForModel(analysisModel);
|
||||
|
||||
@@ -2359,13 +2371,6 @@ 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,
|
||||
@@ -2375,8 +2380,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
|
||||
claudeCompatibleProvider: analysisClaudeProvider, // Pass provider for alternative endpoint configuration
|
||||
};
|
||||
|
||||
const stream = provider.executeQuery(options);
|
||||
@@ -3425,16 +3430,37 @@ 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
|
||||
);
|
||||
// Get credentials for API calls (model comes from request, no phase model)
|
||||
const credentials = await this.settingsService?.getCredentials();
|
||||
|
||||
// Try to find a provider for the model (if it's a provider model like "GLM-4.7")
|
||||
// This allows users to select provider models in the Auto Mode / Feature execution
|
||||
let claudeCompatibleProvider: import('@automaker/types').ClaudeCompatibleProvider | undefined;
|
||||
let providerResolvedModel: string | undefined;
|
||||
if (finalModel && this.settingsService) {
|
||||
const providerResult = await getProviderByModelId(
|
||||
finalModel,
|
||||
this.settingsService,
|
||||
'[AutoMode]'
|
||||
);
|
||||
if (providerResult.provider) {
|
||||
claudeCompatibleProvider = providerResult.provider;
|
||||
providerResolvedModel = providerResult.resolvedModel;
|
||||
logger.info(
|
||||
`[AutoMode] Using provider "${providerResult.provider.name}" for model "${finalModel}"` +
|
||||
(providerResolvedModel ? ` -> resolved to "${providerResolvedModel}"` : '')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Use the resolved model if available (from mapsToClaudeModel), otherwise use bareModel
|
||||
const effectiveBareModel = providerResolvedModel
|
||||
? stripProviderPrefix(providerResolvedModel)
|
||||
: bareModel;
|
||||
|
||||
const executeOptions: ExecuteOptions = {
|
||||
prompt: promptContent,
|
||||
model: bareModel,
|
||||
model: effectiveBareModel,
|
||||
maxTurns: maxTurns,
|
||||
cwd: workDir,
|
||||
allowedTools: allowedTools,
|
||||
@@ -3443,8 +3469,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
|
||||
claudeCompatibleProvider, // Pass provider for alternative endpoint configuration (GLM, MiniMax, etc.)
|
||||
};
|
||||
|
||||
// Execute via provider
|
||||
@@ -3750,8 +3776,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
|
||||
claudeCompatibleProvider, // Pass provider for alternative endpoint configuration
|
||||
});
|
||||
|
||||
let revisionText = '';
|
||||
@@ -3899,8 +3925,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
|
||||
claudeCompatibleProvider, // Pass provider for alternative endpoint configuration
|
||||
});
|
||||
|
||||
let taskOutput = '';
|
||||
@@ -3999,8 +4025,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
|
||||
claudeCompatibleProvider, // Pass provider for alternative endpoint configuration
|
||||
});
|
||||
|
||||
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, getActiveClaudeApiProfile } from '../lib/settings-helpers.js';
|
||||
import { getPromptCustomization, getProviderByModelId } from '../lib/settings-helpers.js';
|
||||
|
||||
const logger = createLogger('IdeationService');
|
||||
|
||||
@@ -208,7 +208,27 @@ export class IdeationService {
|
||||
);
|
||||
|
||||
// Resolve model alias to canonical identifier (with prefix)
|
||||
const modelId = resolveModelString(options?.model ?? 'sonnet');
|
||||
let modelId = resolveModelString(options?.model ?? 'sonnet');
|
||||
|
||||
// Try to find a provider for this model (e.g., GLM, MiniMax models)
|
||||
let claudeCompatibleProvider: import('@automaker/types').ClaudeCompatibleProvider | undefined;
|
||||
let credentials = await this.settingsService?.getCredentials();
|
||||
|
||||
if (this.settingsService && options?.model) {
|
||||
const providerResult = await getProviderByModelId(
|
||||
options.model,
|
||||
this.settingsService,
|
||||
'[IdeationService]'
|
||||
);
|
||||
if (providerResult.provider) {
|
||||
claudeCompatibleProvider = providerResult.provider;
|
||||
// Use resolved model from provider if available (maps to Claude model)
|
||||
if (providerResult.resolvedModel) {
|
||||
modelId = providerResult.resolvedModel;
|
||||
}
|
||||
credentials = providerResult.credentials ?? credentials;
|
||||
}
|
||||
}
|
||||
|
||||
// Create SDK options
|
||||
const sdkOptions = createChatOptions({
|
||||
@@ -223,13 +243,6 @@ 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,
|
||||
@@ -239,7 +252,7 @@ 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
|
||||
claudeCompatibleProvider, // Pass provider for alternative endpoint configuration
|
||||
credentials, // Pass credentials for resolving 'credentials' apiKeySource
|
||||
};
|
||||
|
||||
@@ -687,12 +700,8 @@ 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
|
||||
);
|
||||
// Get credentials for API calls (uses hardcoded model, no phase setting)
|
||||
const credentials = await this.settingsService?.getCredentials();
|
||||
|
||||
const executeOptions: ExecuteOptions = {
|
||||
prompt: prompt.prompt,
|
||||
@@ -704,7 +713,6 @@ 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
|
||||
};
|
||||
|
||||
|
||||
@@ -31,6 +31,9 @@ import type {
|
||||
WorktreeInfo,
|
||||
PhaseModelConfig,
|
||||
PhaseModelEntry,
|
||||
ClaudeApiProfile,
|
||||
ClaudeCompatibleProvider,
|
||||
ProviderModel,
|
||||
} from '../types/settings.js';
|
||||
import {
|
||||
DEFAULT_GLOBAL_SETTINGS,
|
||||
@@ -206,6 +209,28 @@ export class SettingsService {
|
||||
needsSave = true;
|
||||
}
|
||||
|
||||
// Migration v5 -> v6: Convert claudeApiProfiles to claudeCompatibleProviders
|
||||
// The new system uses a models[] array instead of modelMappings, and removes
|
||||
// the "active profile" concept - models are selected directly in phase model configs.
|
||||
if (storedVersion < 6) {
|
||||
const legacyProfiles = settings.claudeApiProfiles || [];
|
||||
if (
|
||||
legacyProfiles.length > 0 &&
|
||||
(!result.claudeCompatibleProviders || result.claudeCompatibleProviders.length === 0)
|
||||
) {
|
||||
logger.info(
|
||||
`Migration v5->v6: Converting ${legacyProfiles.length} Claude API profile(s) to compatible providers`
|
||||
);
|
||||
result.claudeCompatibleProviders = this.migrateProfilesToProviders(legacyProfiles);
|
||||
}
|
||||
// Remove the deprecated activeClaudeApiProfileId field
|
||||
if (result.activeClaudeApiProfileId) {
|
||||
logger.info('Migration v5->v6: Removing deprecated activeClaudeApiProfileId');
|
||||
delete result.activeClaudeApiProfileId;
|
||||
}
|
||||
needsSave = true;
|
||||
}
|
||||
|
||||
// Update version if any migration occurred
|
||||
if (needsSave) {
|
||||
result.version = SETTINGS_VERSION;
|
||||
@@ -290,6 +315,139 @@ export class SettingsService {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate ClaudeApiProfiles to ClaudeCompatibleProviders
|
||||
*
|
||||
* Converts the legacy profile format (with modelMappings) to the new
|
||||
* provider format (with models[] array). Each model mapping entry becomes
|
||||
* a ProviderModel with appropriate tier assignment.
|
||||
*
|
||||
* @param profiles - Legacy ClaudeApiProfile array
|
||||
* @returns Array of ClaudeCompatibleProvider
|
||||
*/
|
||||
private migrateProfilesToProviders(profiles: ClaudeApiProfile[]): ClaudeCompatibleProvider[] {
|
||||
return profiles.map((profile): ClaudeCompatibleProvider => {
|
||||
// Convert modelMappings to models array
|
||||
const models: ProviderModel[] = [];
|
||||
|
||||
if (profile.modelMappings) {
|
||||
// Haiku mapping
|
||||
if (profile.modelMappings.haiku) {
|
||||
models.push({
|
||||
id: profile.modelMappings.haiku,
|
||||
displayName: this.inferModelDisplayName(profile.modelMappings.haiku, 'haiku'),
|
||||
mapsToClaudeModel: 'haiku',
|
||||
});
|
||||
}
|
||||
// Sonnet mapping
|
||||
if (profile.modelMappings.sonnet) {
|
||||
models.push({
|
||||
id: profile.modelMappings.sonnet,
|
||||
displayName: this.inferModelDisplayName(profile.modelMappings.sonnet, 'sonnet'),
|
||||
mapsToClaudeModel: 'sonnet',
|
||||
});
|
||||
}
|
||||
// Opus mapping
|
||||
if (profile.modelMappings.opus) {
|
||||
models.push({
|
||||
id: profile.modelMappings.opus,
|
||||
displayName: this.inferModelDisplayName(profile.modelMappings.opus, 'opus'),
|
||||
mapsToClaudeModel: 'opus',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Infer provider type from base URL or name
|
||||
const providerType = this.inferProviderType(profile);
|
||||
|
||||
return {
|
||||
id: profile.id,
|
||||
name: profile.name,
|
||||
providerType,
|
||||
enabled: true,
|
||||
baseUrl: profile.baseUrl,
|
||||
apiKeySource: profile.apiKeySource ?? 'inline',
|
||||
apiKey: profile.apiKey,
|
||||
useAuthToken: profile.useAuthToken,
|
||||
timeoutMs: profile.timeoutMs,
|
||||
disableNonessentialTraffic: profile.disableNonessentialTraffic,
|
||||
models,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Infer a display name for a model based on its ID and tier
|
||||
*
|
||||
* @param modelId - The raw model ID
|
||||
* @param tier - The tier hint (haiku/sonnet/opus)
|
||||
* @returns A user-friendly display name
|
||||
*/
|
||||
private inferModelDisplayName(modelId: string, tier: 'haiku' | 'sonnet' | 'opus'): string {
|
||||
// Common patterns in model IDs
|
||||
const lowerModelId = modelId.toLowerCase();
|
||||
|
||||
// GLM models
|
||||
if (lowerModelId.includes('glm')) {
|
||||
return modelId.replace(/-/g, ' ').replace(/glm/i, 'GLM');
|
||||
}
|
||||
|
||||
// MiniMax models
|
||||
if (lowerModelId.includes('minimax')) {
|
||||
return modelId.replace(/-/g, ' ').replace(/minimax/i, 'MiniMax');
|
||||
}
|
||||
|
||||
// Claude models via OpenRouter or similar
|
||||
if (lowerModelId.includes('claude')) {
|
||||
return modelId;
|
||||
}
|
||||
|
||||
// Default: use model ID as display name with tier in parentheses
|
||||
return `${modelId} (${tier})`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Infer provider type from profile configuration
|
||||
*
|
||||
* @param profile - The legacy profile
|
||||
* @returns The inferred provider type
|
||||
*/
|
||||
private inferProviderType(profile: ClaudeApiProfile): ClaudeCompatibleProvider['providerType'] {
|
||||
const baseUrl = profile.baseUrl.toLowerCase();
|
||||
const name = profile.name.toLowerCase();
|
||||
|
||||
// Check URL patterns
|
||||
if (baseUrl.includes('z.ai') || baseUrl.includes('zhipuai')) {
|
||||
return 'glm';
|
||||
}
|
||||
if (baseUrl.includes('minimax')) {
|
||||
return 'minimax';
|
||||
}
|
||||
if (baseUrl.includes('openrouter')) {
|
||||
return 'openrouter';
|
||||
}
|
||||
if (baseUrl.includes('anthropic.com')) {
|
||||
return 'anthropic';
|
||||
}
|
||||
|
||||
// Check name patterns
|
||||
if (name.includes('glm') || name.includes('zhipu')) {
|
||||
return 'glm';
|
||||
}
|
||||
if (name.includes('minimax')) {
|
||||
return 'minimax';
|
||||
}
|
||||
if (name.includes('openrouter')) {
|
||||
return 'openrouter';
|
||||
}
|
||||
if (name.includes('anthropic') || name.includes('direct')) {
|
||||
return 'anthropic';
|
||||
}
|
||||
|
||||
// Default to custom
|
||||
return 'custom';
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate model-related settings to canonical format
|
||||
*
|
||||
@@ -413,6 +571,7 @@ export class SettingsService {
|
||||
ignoreEmptyArrayOverwrite('mcpServers');
|
||||
ignoreEmptyArrayOverwrite('enabledCursorModels');
|
||||
ignoreEmptyArrayOverwrite('claudeApiProfiles');
|
||||
// Note: claudeCompatibleProviders intentionally NOT guarded - users should be able to delete all providers
|
||||
|
||||
// Empty object overwrite guard
|
||||
const ignoreEmptyObjectOverwrite = <K extends keyof GlobalSettings>(key: K): void => {
|
||||
@@ -658,6 +817,16 @@ export class SettingsService {
|
||||
delete updated.activeClaudeApiProfileId;
|
||||
}
|
||||
|
||||
// Handle phaseModelOverrides special cases:
|
||||
// - "__CLEAR__" marker means delete the key (use global settings for all phases)
|
||||
// - object means partial overrides for specific phases
|
||||
if (
|
||||
'phaseModelOverrides' in updates &&
|
||||
(updates as Record<string, unknown>).phaseModelOverrides === '__CLEAR__'
|
||||
) {
|
||||
delete updated.phaseModelOverrides;
|
||||
}
|
||||
|
||||
await writeSettingsJson(settingsPath, updated);
|
||||
logger.info(`Project settings updated for ${projectPath}`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user