| @@ -2284,13 +2284,14 @@ | ||
| 2284 | 2284 | * used only when the core model catalog is unavailable. Byte-identical to the |
| 2285 | 2285 | * old inline if/elseif at the call site. |
| 2286 | 2286 | */ |
| 2287 | 2287 | private function mxchat_cg_reasoning_effort_fallback($model) { |
| 2288 | - if (strpos($model, 'gpt-5') !== 0) return null; | |
| 2288 | + if (strpos($model, 'gpt-5') !== 0 && strpos($model, 'gpt-6') !== 0) return null; // gpt-6 too (plan 45c22d) | |
| 2289 | 2289 | if ($model === 'gpt-5.2' || $model === 'gpt-5.1-chat-latest') return null; |
| 2290 | 2290 | if ($model === 'gpt-5.1-2025-11-13') return 'low'; |
| 2291 | 2291 | if ($model === 'gpt-5.5') return 'low'; |
| 2292 | 2292 | if ($model === 'gpt-5.4') return 'low'; |
| 2293 | + if (in_array($model, array('gpt-6-astra', 'gpt-6-sol', 'gpt-6-luna'), true)) return 'low'; // plan 45c22d | |
| 2293 | 2294 | if (in_array($model, array('gpt-5.6-sol', 'gpt-5.6-terra', 'gpt-5.6-luna'), true)) return 'low'; |
| 2294 | 2295 | return 'minimal'; |
| 2295 | 2296 | } |
| 2296 | 2297 | |
| @@ -2311,9 +2312,9 @@ | ||
| 2311 | 2312 | // GPT-5.x models require max_completion_tokens and only support temperature=1. |
| 2312 | 2313 | // Token key, temperature gate, and reasoning_effort are sourced from the |
| 2313 | 2314 | // core model catalog (plan-dcb71c); frozen fallbacks preserve exact |
| 2314 | 2315 | // pre-dcb71c behavior if the catalog class is unavailable. |
| 2315 | - $is_gpt5 = strpos($model, 'gpt-5') === 0; | |
| 2316 | + $is_gpt5 = strpos($model, 'gpt-5') === 0 || strpos($model, 'gpt-6') === 0; // gpt-6 too (plan 45c22d) | |
| 2316 | 2317 | $catalog = class_exists('MxChat_Model_Catalog'); |
| 2317 | 2318 | $token_key = ($catalog && method_exists('MxChat_Model_Catalog', 'openai_token_param')) |
| 2318 | 2319 | ? MxChat_Model_Catalog::openai_token_param($model) |
| 2319 | 2320 | : ($is_gpt5 ? 'max_completion_tokens' : 'max_tokens'); |
| @@ -2412,11 +2413,10 @@ | ||
| 2412 | 2413 | * Call Claude (Anthropic) API |
| 2413 | 2414 | */ |
| 2414 | 2415 | private function call_claude($model, $api_key, $system_prompt, $messages, $max_tokens) { |
| 2415 | 2416 | // Anthropic retired claude-opus-4-20250514 / claude-sonnet-4-20250514 on 2026-06-15. |
| 2416 | - // Read-time rescue: remap a saved dead ID to the current equivalent before the API call. | |
| 2417 | - if ($model === 'claude-opus-4-20250514') { $model = 'claude-opus-4-8'; } | |
| 2418 | - elseif ($model === 'claude-sonnet-4-20250514') { $model = 'claude-sonnet-4-6'; } | |
| 2417 | + // Read-time rescue: a saved retired id is remapped to the catalog's replacement before the API call. | |
| 2418 | + $model = MxChat_Model_Catalog::resolve_retired($model); // plan 8c4eb4: the catalog's one map | |
| 2419 | 2419 | if (empty($api_key)) { |
| 2420 | 2420 | return new WP_Error('no_api_key', __('Claude API key not configured.', 'mxchat')); |
| 2421 | 2421 | } |
| 2422 | 2422 | |
| @@ -2555,12 +2555,29 @@ | ||
| 2555 | 2555 | $error_msg = $decoded['error']['message'] ?? __('Gemini API error ', 'mxchat') . $status_code; |
| 2556 | 2556 | return new WP_Error('gemini_error', $error_msg); |
| 2557 | 2557 | } |
| 2558 | 2558 | |
| 2559 | - if (isset($decoded['candidates'][0]['content']['parts'][0]['text'])) { | |
| 2560 | - return trim($decoded['candidates'][0]['content']['parts'][0]['text']); | |
| 2559 | + // plan 781afd: join every text part (skip thought parts), not only parts[0]. | |
| 2560 | + $text = ''; | |
| 2561 | + if (isset($decoded['candidates'][0]['content']['parts']) && is_array($decoded['candidates'][0]['content']['parts'])) { | |
| 2562 | + foreach ($decoded['candidates'][0]['content']['parts'] as $part) { | |
| 2563 | + if (is_array($part) && isset($part['text']) && is_string($part['text']) && empty($part['thought'])) { | |
| 2564 | + $text .= $part['text']; | |
| 2565 | + } | |
| 2566 | + } | |
| 2561 | 2567 | } |
| 2568 | + $text = trim($text); | |
| 2569 | + if ($text !== '') { | |
| 2570 | + return $text; | |
| 2571 | + } | |
| 2562 | 2572 | |
| 2573 | + $no_text_reason = isset($decoded['candidates'][0]['finishReason']) && is_string($decoded['candidates'][0]['finishReason']) | |
| 2574 | + ? $decoded['candidates'][0]['finishReason'] | |
| 2575 | + : (isset($decoded['promptFeedback']['blockReason']) && is_string($decoded['promptFeedback']['blockReason']) ? $decoded['promptFeedback']['blockReason'] : ''); | |
| 2576 | + if ($no_text_reason !== '') { | |
| 2577 | + /* translators: %s: Gemini's finish or block reason, e.g. SAFETY */ | |
| 2578 | + return new WP_Error('gemini_no_text', sprintf(__('Gemini returned no text (%s).', 'mxchat'), $no_text_reason)); | |
| 2579 | + } | |
| 2563 | 2580 | return new WP_Error('unexpected_response', __('Unexpected Gemini response format.', 'mxchat')); |
| 2564 | 2581 | } |
| 2565 | 2582 | |
| 2566 | 2583 | // ─── Model Detection Helpers ──────────────────────────────────────── |