mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 10:16:49 +00:00
fix(hooks): handle thinking blocks in image analyzer response parsing
When models have thinking enabled (e.g. codex with thinking: auto), the
API returns content as [{ type: 'thinking', thinking: '...' }, { type:
'text', text: '...' }]. The hook reads content[0].text which is
undefined for thinking blocks, causing 'No text content in response'
errors that block the Read tool (exit 2).
Also fix cross-provider model fallback: getModelsToTry() unconditionally
appends DEFAULT_MODEL (gemini-2.5-flash) as retry, which 502s on
non-gemini provider routes (e.g. codex). Only use DEFAULT_MODEL when no
provider-specific model is configured.
Fixes: content[0].text -> content.find(b => b.type === 'text')
Fixes: cross-provider retry causing 'unknown provider' 502
Ref: #511
This commit is contained in:
@@ -177,16 +177,16 @@ function getModelsToTry() {
|
||||
seen.add(providerModels[currentProvider]);
|
||||
}
|
||||
|
||||
// 2. Default model
|
||||
if (!seen.has(DEFAULT_MODEL)) {
|
||||
// 2. Default model — only when no provider-specific model is configured,
|
||||
// since DEFAULT_MODEL (gemini-2.5-flash) may not be routable on the
|
||||
// current provider's CLIProxy endpoint (e.g. codex, claude)
|
||||
if (models.length === 0 && !seen.has(DEFAULT_MODEL)) {
|
||||
models.push(DEFAULT_MODEL);
|
||||
seen.add(DEFAULT_MODEL);
|
||||
}
|
||||
|
||||
// 3. ANTHROPIC_MODEL fallback
|
||||
if (anthropicModel && !seen.has(anthropicModel)) {
|
||||
models.push(anthropicModel);
|
||||
}
|
||||
// 3. ANTHROPIC_MODEL fallback — skip, the main chat model is not
|
||||
// necessarily vision-capable and adds unnecessary retry latency
|
||||
|
||||
return models;
|
||||
}
|
||||
@@ -382,7 +382,10 @@ function analyzeViaCliProxy(base64Data, mediaType, model, timeoutMs) {
|
||||
|
||||
try {
|
||||
const response = JSON.parse(data);
|
||||
const text = response.content?.[0]?.text;
|
||||
// Find the first text block — skip thinking blocks which use
|
||||
// .thinking instead of .text (e.g. codex models with thinking enabled)
|
||||
const textBlock = response.content?.find(b => b.type === 'text' && b.text);
|
||||
const text = textBlock?.text;
|
||||
|
||||
if (!text) {
|
||||
reject(new Error('No text content in response'));
|
||||
|
||||
Reference in New Issue
Block a user