Skip to content

Commit 4d85cd5

Browse files
committed
fix: use fallback model for name generation when preferred models unavailable
If Haiku/GPT-Mini aren't available (no Anthropic/OpenAI key), fall back to the user's configured message model. This avoids confusing errors when users have only configured alternative providers.
1 parent f95082a commit 4d85cd5

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

src/browser/components/ChatInput/useCreationWorkspace.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,22 @@ export function useCreationWorkspace({
102102
getRuntimeString,
103103
} = useDraftWorkspaceSettings(projectPath, branches, recommendedTrunk);
104104

105+
// Project scope ID for reading send options at send time
106+
const projectScopeId = getProjectScopeId(projectPath);
107+
108+
// Read the user's preferred model for fallback (same source as ChatInput's preferredModel)
109+
const fallbackModel = readPersistedState<string | null>(getModelKey(projectScopeId), null);
110+
105111
// Workspace name generation with debounce
106112
const workspaceNameState = useWorkspaceName({
107113
message,
108114
debounceMs: 500,
115+
fallbackModel: fallbackModel ?? undefined,
109116
});
110117

111118
// Destructure name state functions for use in callbacks
112119
const { waitForGeneration } = workspaceNameState;
113120

114-
// Project scope ID for reading send options at send time
115-
const projectScopeId = getProjectScopeId(projectPath);
116-
117121
// Load branches on mount
118122
useEffect(() => {
119123
// This can be created with an empty project path when the user is

src/browser/hooks/useWorkspaceName.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export interface UseWorkspaceNameOptions {
66
message: string;
77
/** Debounce delay in milliseconds (default: 500) */
88
debounceMs?: number;
9+
/** Model to use if preferred small models aren't available */
10+
fallbackModel?: string;
911
}
1012

1113
/** State and actions for workspace name generation, suitable for passing to components */
@@ -37,7 +39,7 @@ export interface UseWorkspaceNameReturn extends WorkspaceNameState {
3739
* auto-generation resumes.
3840
*/
3941
export function useWorkspaceName(options: UseWorkspaceNameOptions): UseWorkspaceNameReturn {
40-
const { message, debounceMs = 500 } = options;
42+
const { message, debounceMs = 500, fallbackModel } = options;
4143
const { api } = useAPI();
4244

4345
const [generatedName, setGeneratedName] = useState("");
@@ -103,6 +105,7 @@ export function useWorkspaceName(options: UseWorkspaceNameOptions): UseWorkspace
103105
try {
104106
const result = await api.nameGeneration.generate({
105107
message: forMessage,
108+
fallbackModel,
106109
});
107110

108111
// Check if this request is still current (wasn't cancelled)
@@ -141,7 +144,7 @@ export function useWorkspaceName(options: UseWorkspaceNameOptions): UseWorkspace
141144
}
142145
}
143146
},
144-
[api]
147+
[api, fallbackModel]
145148
);
146149

147150
// Debounced generation effect

src/common/orpc/schemas/api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ export const nameGeneration = {
278278
generate: {
279279
input: z.object({
280280
message: z.string(),
281+
/** Model to use if preferred small models (Haiku, GPT-Mini) aren't available */
282+
fallbackModel: z.string().optional(),
281283
}),
282284
output: ResultSchema(
283285
z.object({

src/node/orpc/router.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,15 @@ export const router = (authToken?: string) => {
174174
.input(schemas.nameGeneration.generate.input)
175175
.output(schemas.nameGeneration.generate.output)
176176
.handler(async ({ context, input }) => {
177-
const model = await getPreferredNameModel(context.aiService);
177+
// Prefer small/fast models, fall back to user's configured model
178+
const model =
179+
(await getPreferredNameModel(context.aiService)) ?? input.fallbackModel;
178180
if (!model) {
179181
return {
180182
success: false,
181183
error: {
182184
type: "unknown" as const,
183-
raw: "No model available for name generation. Configure an API key for Anthropic or OpenAI.",
185+
raw: "No model available for name generation.",
184186
},
185187
};
186188
}

0 commit comments

Comments
 (0)