fix: provide local session title fallback for 3P providers
When using non-Anthropic providers (Ollama, Gemini, Codex), the underlying call to queryHaiku for session title generation fails. Previously, this caused the catch block to return null, leaving the terminal tab permanently stuck on 'Claude Code'. Now, when the API call fails, we gracefully derive a title locally from the user's first message (first 7 words, sentence-cased), ensuring users still see a meaningful session title in their terminal tab.
This commit is contained in:
@@ -124,6 +124,29 @@ export async function generateSessionTitle(
|
||||
level: 'error',
|
||||
})
|
||||
logEvent('tengu_session_title_generated', { success: false })
|
||||
return null
|
||||
|
||||
// Fallback: derive a title locally from the user's first message.
|
||||
// This ensures 3P providers (Ollama, Gemini, OpenAI) still get
|
||||
// meaningful terminal titles when the Haiku API call is unavailable.
|
||||
return localFallbackTitle(trimmed)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fallback local title generator for when the Haiku API is unavailable
|
||||
* (e.g. when using third-party providers without an Anthropic API key).
|
||||
*/
|
||||
function localFallbackTitle(text: string): string | null {
|
||||
const words = text.split(/\s+/).slice(0, 7)
|
||||
if (words.length === 0) return null
|
||||
|
||||
// Create a sentence-case string
|
||||
let fallback = words.join(' ')
|
||||
if (fallback.length > 50) {
|
||||
fallback = fallback.substring(0, 49) + '…'
|
||||
}
|
||||
|
||||
if (fallback.length <= 3) return null
|
||||
|
||||
return fallback.charAt(0).toUpperCase() + fallback.slice(1)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user