mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-13 04:14:57 +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:
1 file changed
+10
-7
@@ -177,16 +177,16 @@ function getModelsToTry() {
|
|||||||
seen.add(providerModels[currentProvider]);
|
seen.add(providerModels[currentProvider]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Default model
|
// 2. Default model — only when no provider-specific model is configured,
|
||||||
if (!seen.has(DEFAULT_MODEL)) {
|
// 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);
|
models.push(DEFAULT_MODEL);
|
||||||
seen.add(DEFAULT_MODEL);
|
seen.add(DEFAULT_MODEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. ANTHROPIC_MODEL fallback
|
// 3. ANTHROPIC_MODEL fallback — skip, the main chat model is not
|
||||||
if (anthropicModel && !seen.has(anthropicModel)) {
|
// necessarily vision-capable and adds unnecessary retry latency
|
||||||
models.push(anthropicModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
return models;
|
return models;
|
||||||
}
|
}
|
||||||
@@ -382,7 +382,10 @@ function analyzeViaCliProxy(base64Data, mediaType, model, timeoutMs) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const response = JSON.parse(data);
|
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) {
|
if (!text) {
|
||||||
reject(new Error('No text content in response'));
|
reject(new Error('No text content in response'));
|
||||||
|
|||||||
Reference in new issue
Block a user