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
@@ -9,6 +9,9 @@ import type {
|
||||
OpencodeModelId,
|
||||
GroupedModel,
|
||||
PhaseModelEntry,
|
||||
ClaudeCompatibleProvider,
|
||||
ProviderModel,
|
||||
ClaudeModelAlias,
|
||||
} from '@automaker/types';
|
||||
import {
|
||||
stripProviderPrefix,
|
||||
@@ -33,6 +36,9 @@ import {
|
||||
AnthropicIcon,
|
||||
CursorIcon,
|
||||
OpenAIIcon,
|
||||
OpenRouterIcon,
|
||||
GlmIcon,
|
||||
MiniMaxIcon,
|
||||
getProviderIconForModel,
|
||||
} from '@/components/ui/provider-icon';
|
||||
import { Button } from '@/components/ui/button';
|
||||
@@ -154,10 +160,12 @@ export function PhaseModelSelector({
|
||||
const [expandedGroup, setExpandedGroup] = useState<string | null>(null);
|
||||
const [expandedClaudeModel, setExpandedClaudeModel] = useState<ModelAlias | null>(null);
|
||||
const [expandedCodexModel, setExpandedCodexModel] = useState<CodexModelId | null>(null);
|
||||
const [expandedProviderModel, setExpandedProviderModel] = useState<string | null>(null); // Format: providerId:modelId
|
||||
const commandListRef = useRef<HTMLDivElement>(null);
|
||||
const expandedTriggerRef = useRef<HTMLDivElement>(null);
|
||||
const expandedClaudeTriggerRef = useRef<HTMLDivElement>(null);
|
||||
const expandedCodexTriggerRef = useRef<HTMLDivElement>(null);
|
||||
const expandedProviderTriggerRef = useRef<HTMLDivElement>(null);
|
||||
const {
|
||||
enabledCursorModels,
|
||||
favoriteModels,
|
||||
@@ -170,16 +178,23 @@ export function PhaseModelSelector({
|
||||
opencodeModelsLoading,
|
||||
fetchOpencodeModels,
|
||||
disabledProviders,
|
||||
claudeCompatibleProviders,
|
||||
} = useAppStore();
|
||||
|
||||
// Detect mobile devices to use inline expansion instead of nested popovers
|
||||
const isMobile = useIsMobile();
|
||||
|
||||
// Extract model and thinking/reasoning levels from value
|
||||
// Extract model, provider, and thinking/reasoning levels from value
|
||||
const selectedModel = value.model;
|
||||
const selectedProviderId = value.providerId;
|
||||
const selectedThinkingLevel = value.thinkingLevel || 'none';
|
||||
const selectedReasoningEffort = value.reasoningEffort || 'none';
|
||||
|
||||
// Get enabled providers and their models
|
||||
const enabledProviders = useMemo(() => {
|
||||
return (claudeCompatibleProviders || []).filter((p) => p.enabled !== false);
|
||||
}, [claudeCompatibleProviders]);
|
||||
|
||||
// Fetch Codex models on mount
|
||||
useEffect(() => {
|
||||
if (codexModels.length === 0 && !codexModelsLoading) {
|
||||
@@ -267,6 +282,29 @@ export function PhaseModelSelector({
|
||||
return () => observer.disconnect();
|
||||
}, [expandedCodexModel]);
|
||||
|
||||
// Close expanded provider model popover when trigger scrolls out of view
|
||||
useEffect(() => {
|
||||
const triggerElement = expandedProviderTriggerRef.current;
|
||||
const listElement = commandListRef.current;
|
||||
if (!triggerElement || !listElement || !expandedProviderModel) return;
|
||||
|
||||
const observer = new IntersectionObserver(
|
||||
(entries) => {
|
||||
const entry = entries[0];
|
||||
if (!entry.isIntersecting) {
|
||||
setExpandedProviderModel(null);
|
||||
}
|
||||
},
|
||||
{
|
||||
root: listElement,
|
||||
threshold: 0.1,
|
||||
}
|
||||
);
|
||||
|
||||
observer.observe(triggerElement);
|
||||
return () => observer.disconnect();
|
||||
}, [expandedProviderModel]);
|
||||
|
||||
// Transform dynamic Codex models from store to component format
|
||||
const transformedCodexModels = useMemo(() => {
|
||||
return codexModels.map((model) => ({
|
||||
@@ -337,13 +375,55 @@ export function PhaseModelSelector({
|
||||
};
|
||||
}
|
||||
|
||||
// Check ClaudeCompatibleProvider models (when providerId is set)
|
||||
if (selectedProviderId) {
|
||||
const provider = enabledProviders.find((p) => p.id === selectedProviderId);
|
||||
if (provider) {
|
||||
const providerModel = provider.models?.find((m) => m.id === selectedModel);
|
||||
if (providerModel) {
|
||||
// Count providers of same type to determine if we need provider name suffix
|
||||
const sameTypeCount = enabledProviders.filter(
|
||||
(p) => p.providerType === provider.providerType
|
||||
).length;
|
||||
const suffix = sameTypeCount > 1 ? ` (${provider.name})` : '';
|
||||
// Add thinking level to label if not 'none'
|
||||
const thinkingLabel =
|
||||
selectedThinkingLevel !== 'none'
|
||||
? ` (${THINKING_LEVEL_LABELS[selectedThinkingLevel]} Thinking)`
|
||||
: '';
|
||||
// Get icon based on provider type
|
||||
const getIconForProviderType = () => {
|
||||
switch (provider.providerType) {
|
||||
case 'glm':
|
||||
return GlmIcon;
|
||||
case 'minimax':
|
||||
return MiniMaxIcon;
|
||||
case 'openrouter':
|
||||
return OpenRouterIcon;
|
||||
default:
|
||||
return getProviderIconForModel(providerModel.id) || OpenRouterIcon;
|
||||
}
|
||||
};
|
||||
return {
|
||||
id: selectedModel,
|
||||
label: `${providerModel.displayName}${suffix}${thinkingLabel}`,
|
||||
description: provider.name,
|
||||
provider: 'claude-compatible' as const,
|
||||
icon: getIconForProviderType(),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}, [
|
||||
selectedModel,
|
||||
selectedProviderId,
|
||||
selectedThinkingLevel,
|
||||
availableCursorModels,
|
||||
transformedCodexModels,
|
||||
dynamicOpencodeModels,
|
||||
enabledProviders,
|
||||
]);
|
||||
|
||||
// Compute grouped vs standalone Cursor models
|
||||
@@ -907,6 +987,245 @@ export function PhaseModelSelector({
|
||||
);
|
||||
};
|
||||
|
||||
// Render ClaudeCompatibleProvider model item with thinking level support
|
||||
const renderProviderModelItem = (
|
||||
provider: ClaudeCompatibleProvider,
|
||||
model: ProviderModel,
|
||||
showProviderSuffix: boolean,
|
||||
allMappedModels: ClaudeModelAlias[] = []
|
||||
) => {
|
||||
const isSelected = selectedModel === model.id && selectedProviderId === provider.id;
|
||||
const expandKey = `${provider.id}:${model.id}`;
|
||||
const isExpanded = expandedProviderModel === expandKey;
|
||||
const currentThinking = isSelected ? selectedThinkingLevel : 'none';
|
||||
const displayName = showProviderSuffix
|
||||
? `${model.displayName} (${provider.name})`
|
||||
: model.displayName;
|
||||
|
||||
// Build description showing all mapped Claude models
|
||||
const modelLabelMap: Record<ClaudeModelAlias, string> = {
|
||||
haiku: 'Haiku',
|
||||
sonnet: 'Sonnet',
|
||||
opus: 'Opus',
|
||||
};
|
||||
// Sort in order: haiku, sonnet, opus for consistent display
|
||||
const sortOrder: ClaudeModelAlias[] = ['haiku', 'sonnet', 'opus'];
|
||||
const sortedMappedModels = [...allMappedModels].sort(
|
||||
(a, b) => sortOrder.indexOf(a) - sortOrder.indexOf(b)
|
||||
);
|
||||
const mappedModelLabel =
|
||||
sortedMappedModels.length > 0
|
||||
? sortedMappedModels.map((m) => modelLabelMap[m]).join(', ')
|
||||
: 'Claude';
|
||||
|
||||
// Get icon based on provider type, falling back to model-based detection
|
||||
const getProviderTypeIcon = () => {
|
||||
switch (provider.providerType) {
|
||||
case 'glm':
|
||||
return GlmIcon;
|
||||
case 'minimax':
|
||||
return MiniMaxIcon;
|
||||
case 'openrouter':
|
||||
return OpenRouterIcon;
|
||||
default:
|
||||
// For generic/unknown providers, use OpenRouter as a generic "cloud API" icon
|
||||
// unless the model ID has a recognizable pattern
|
||||
return getProviderIconForModel(model.id) || OpenRouterIcon;
|
||||
}
|
||||
};
|
||||
const ProviderIcon = getProviderTypeIcon();
|
||||
|
||||
// On mobile, render inline expansion instead of nested popover
|
||||
if (isMobile) {
|
||||
return (
|
||||
<div key={`${provider.id}-${model.id}`}>
|
||||
<CommandItem
|
||||
value={`${provider.name} ${model.displayName}`}
|
||||
onSelect={() => setExpandedProviderModel(isExpanded ? null : expandKey)}
|
||||
className="group flex items-center justify-between py-2"
|
||||
>
|
||||
<div className="flex items-center gap-3 overflow-hidden">
|
||||
<ProviderIcon
|
||||
className={cn(
|
||||
'h-4 w-4 shrink-0',
|
||||
isSelected ? 'text-primary' : 'text-muted-foreground'
|
||||
)}
|
||||
/>
|
||||
<div className="flex flex-col truncate">
|
||||
<span className={cn('truncate font-medium', isSelected && 'text-primary')}>
|
||||
{displayName}
|
||||
</span>
|
||||
<span className="truncate text-xs text-muted-foreground">
|
||||
{isSelected && currentThinking !== 'none'
|
||||
? `Thinking: ${THINKING_LEVEL_LABELS[currentThinking]}`
|
||||
: `Maps to ${mappedModelLabel}`}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-1 ml-2">
|
||||
{isSelected && !isExpanded && <Check className="h-4 w-4 text-primary shrink-0" />}
|
||||
<ChevronRight
|
||||
className={cn(
|
||||
'h-4 w-4 text-muted-foreground transition-transform',
|
||||
isExpanded && 'rotate-90'
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</CommandItem>
|
||||
|
||||
{/* Inline thinking level options on mobile */}
|
||||
{isExpanded && (
|
||||
<div className="pl-6 pr-2 pb-2 space-y-1">
|
||||
<div className="px-2 py-1 text-xs font-medium text-muted-foreground">
|
||||
Thinking Level
|
||||
</div>
|
||||
{THINKING_LEVELS.map((level) => (
|
||||
<button
|
||||
key={level}
|
||||
onClick={() => {
|
||||
onChange({
|
||||
providerId: provider.id,
|
||||
model: model.id,
|
||||
thinkingLevel: level,
|
||||
});
|
||||
setExpandedProviderModel(null);
|
||||
setOpen(false);
|
||||
}}
|
||||
className={cn(
|
||||
'w-full flex items-center justify-between px-2 py-2 rounded-sm text-sm',
|
||||
'hover:bg-accent cursor-pointer transition-colors',
|
||||
isSelected && currentThinking === level && 'bg-accent text-accent-foreground'
|
||||
)}
|
||||
>
|
||||
<div className="flex flex-col items-start">
|
||||
<span className="font-medium text-xs">{THINKING_LEVEL_LABELS[level]}</span>
|
||||
<span className="text-[10px] text-muted-foreground">
|
||||
{level === 'none' && 'No extended thinking'}
|
||||
{level === 'low' && 'Light reasoning (1k tokens)'}
|
||||
{level === 'medium' && 'Moderate reasoning (10k tokens)'}
|
||||
{level === 'high' && 'Deep reasoning (16k tokens)'}
|
||||
{level === 'ultrathink' && 'Maximum reasoning (32k tokens)'}
|
||||
</span>
|
||||
</div>
|
||||
{isSelected && currentThinking === level && (
|
||||
<Check className="h-3.5 w-3.5 text-primary" />
|
||||
)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Desktop: Use nested popover
|
||||
return (
|
||||
<CommandItem
|
||||
key={`${provider.id}-${model.id}`}
|
||||
value={`${provider.name} ${model.displayName}`}
|
||||
onSelect={() => setExpandedProviderModel(isExpanded ? null : expandKey)}
|
||||
className="p-0 data-[selected=true]:bg-transparent"
|
||||
>
|
||||
<Popover
|
||||
open={isExpanded}
|
||||
onOpenChange={(isOpen) => {
|
||||
if (!isOpen) {
|
||||
setExpandedProviderModel(null);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<PopoverTrigger asChild>
|
||||
<div
|
||||
ref={isExpanded ? expandedProviderTriggerRef : undefined}
|
||||
className={cn(
|
||||
'w-full group flex items-center justify-between py-2 px-2 rounded-sm cursor-pointer',
|
||||
'hover:bg-accent',
|
||||
isExpanded && 'bg-accent'
|
||||
)}
|
||||
>
|
||||
<div className="flex items-center gap-3 overflow-hidden">
|
||||
<ProviderIcon
|
||||
className={cn(
|
||||
'h-4 w-4 shrink-0',
|
||||
isSelected ? 'text-primary' : 'text-muted-foreground'
|
||||
)}
|
||||
/>
|
||||
<div className="flex flex-col truncate">
|
||||
<span className={cn('truncate font-medium', isSelected && 'text-primary')}>
|
||||
{displayName}
|
||||
</span>
|
||||
<span className="truncate text-xs text-muted-foreground">
|
||||
{isSelected && currentThinking !== 'none'
|
||||
? `Thinking: ${THINKING_LEVEL_LABELS[currentThinking]}`
|
||||
: `Maps to ${mappedModelLabel}`}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-1 ml-2">
|
||||
{isSelected && <Check className="h-4 w-4 text-primary shrink-0" />}
|
||||
<ChevronRight
|
||||
className={cn(
|
||||
'h-4 w-4 text-muted-foreground transition-transform',
|
||||
isExpanded && 'rotate-90'
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent
|
||||
side="right"
|
||||
align="start"
|
||||
className="w-[220px] p-1"
|
||||
sideOffset={8}
|
||||
collisionPadding={16}
|
||||
onCloseAutoFocus={(e) => e.preventDefault()}
|
||||
>
|
||||
<div className="space-y-1">
|
||||
<div className="px-2 py-1.5 text-xs font-medium text-muted-foreground border-b border-border/50 mb-1">
|
||||
Thinking Level
|
||||
</div>
|
||||
{THINKING_LEVELS.map((level) => (
|
||||
<button
|
||||
key={level}
|
||||
onClick={() => {
|
||||
onChange({
|
||||
providerId: provider.id,
|
||||
model: model.id,
|
||||
thinkingLevel: level,
|
||||
});
|
||||
setExpandedProviderModel(null);
|
||||
setOpen(false);
|
||||
}}
|
||||
className={cn(
|
||||
'w-full flex items-center justify-between px-2 py-2 rounded-sm text-sm',
|
||||
'hover:bg-accent cursor-pointer transition-colors',
|
||||
isSelected && currentThinking === level && 'bg-accent text-accent-foreground'
|
||||
)}
|
||||
>
|
||||
<div className="flex flex-col items-start">
|
||||
<span className="font-medium">{THINKING_LEVEL_LABELS[level]}</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{level === 'none' && 'No extended thinking'}
|
||||
{level === 'low' && 'Light reasoning (1k tokens)'}
|
||||
{level === 'medium' && 'Moderate reasoning (10k tokens)'}
|
||||
{level === 'high' && 'Deep reasoning (16k tokens)'}
|
||||
{level === 'ultrathink' && 'Maximum reasoning (32k tokens)'}
|
||||
</span>
|
||||
</div>
|
||||
{isSelected && currentThinking === level && (
|
||||
<Check className="h-3.5 w-3.5 text-primary" />
|
||||
)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</CommandItem>
|
||||
);
|
||||
};
|
||||
|
||||
// Render Cursor model item (no thinking level needed)
|
||||
const renderCursorModelItem = (model: (typeof CURSOR_MODELS)[0]) => {
|
||||
// With canonical IDs, store the full prefixed ID
|
||||
@@ -1499,6 +1818,50 @@ export function PhaseModelSelector({
|
||||
</CommandGroup>
|
||||
)}
|
||||
|
||||
{/* ClaudeCompatibleProvider Models - each provider as separate group */}
|
||||
{enabledProviders.map((provider) => {
|
||||
if (!provider.models || provider.models.length === 0) return null;
|
||||
|
||||
// Check if we need provider suffix (multiple providers of same type)
|
||||
const sameTypeCount = enabledProviders.filter(
|
||||
(p) => p.providerType === provider.providerType
|
||||
).length;
|
||||
const showSuffix = sameTypeCount > 1;
|
||||
|
||||
// Group models by ID and collect all mapped Claude models for each
|
||||
const modelsByIdMap = new Map<
|
||||
string,
|
||||
{ model: ProviderModel; mappedModels: ClaudeModelAlias[] }
|
||||
>();
|
||||
for (const model of provider.models) {
|
||||
const existing = modelsByIdMap.get(model.id);
|
||||
if (existing) {
|
||||
// Add this mapped model if not already present
|
||||
if (
|
||||
model.mapsToClaudeModel &&
|
||||
!existing.mappedModels.includes(model.mapsToClaudeModel)
|
||||
) {
|
||||
existing.mappedModels.push(model.mapsToClaudeModel);
|
||||
}
|
||||
} else {
|
||||
// First occurrence of this model ID
|
||||
modelsByIdMap.set(model.id, {
|
||||
model,
|
||||
mappedModels: model.mapsToClaudeModel ? [model.mapsToClaudeModel] : [],
|
||||
});
|
||||
}
|
||||
}
|
||||
const uniqueModelsWithMappings = Array.from(modelsByIdMap.values());
|
||||
|
||||
return (
|
||||
<CommandGroup key={provider.id} heading={`${provider.name} (via Claude)`}>
|
||||
{uniqueModelsWithMappings.map(({ model, mappedModels }) =>
|
||||
renderProviderModelItem(provider, model, showSuffix, mappedModels)
|
||||
)}
|
||||
</CommandGroup>
|
||||
);
|
||||
})}
|
||||
|
||||
{(groupedModels.length > 0 || standaloneCursorModels.length > 0) && (
|
||||
<CommandGroup heading="Cursor Models">
|
||||
{/* Grouped models with secondary popover */}
|
||||
|
||||
Reference in New Issue
Block a user