Fix OpenRouter prompt cache stickiness
| @@ -14,6 +14,7 @@ import { | ||
| 14 | 14 | extension_prompt_roles, |
| 15 | 15 | extension_prompt_types, |
| 16 | 16 | Generate, |
| 17 | + getCurrentChatId, | |
| 17 | 18 | getExtensionPrompt, |
| 18 | 19 | getExtensionPromptMaxDepth, |
| 19 | 20 | getMediaDisplay, |
| @@ -2821,6 +2822,14 @@ export async function createGenerationParameters(settings, model, type, messages | ||
| 2821 | 2822 | } |
| 2822 | 2823 | |
| 2823 | 2824 | if (settings.chat_completion_source === chat_completion_sources.OPENROUTER) { |
| 2825 | + const chatId = getCurrentChatId(); | |
| 2826 | + if (chatId) { | |
| 2827 | + // Keep OpenRouter on the same provider endpoint for the lifetime of | |
| 2828 | + // this chat so provider-side prompt caches survive follow-up turns. | |
| 2829 | + // Hash the local chat ID instead of exposing its filename. | |
| 2830 | + generate_data.session_id = `st-${getStringHash(chatId)}`; | |
| 2831 | + } | |
| 2832 | + | |
| 2824 | 2833 | generate_data.top_k = Number(settings.top_k_openai); |
| 2825 | 2834 | generate_data.min_p = Number(settings.min_p_openai); |
| 2826 | 2835 | generate_data.repetition_penalty = Number(settings.repetition_penalty_openai); |
| @@ -2227,6 +2227,10 @@ router.post('/generate', async function (request, response) { | ||
| 2227 | 2227 | }, |
| 2228 | 2228 | }; |
| 2229 | 2229 | |
| 2230 | + if (typeof request.body.session_id === 'string' && request.body.session_id.length <= 256) { | |
| 2231 | + bodyParams['session_id'] = request.body.session_id; | |
| 2232 | + } | |
| 2233 | + | |
| 2230 | 2234 | if (request.body.min_p !== undefined) { |
| 2231 | 2235 | bodyParams['min_p'] = request.body.min_p; |
| 2232 | 2236 | } |