From 9a652d5b2be11fdee2fa3dad4d28bde73ee42cc5 Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Mon, 29 Dec 2025 05:10:36 -0800 Subject: [PATCH] Feat: Collect and dispatch OpenRouter images --- index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 3035dab..3b4476c 100644 --- a/index.js +++ b/index.js @@ -333,24 +333,24 @@ export class MyDurableObject { const client = new OpenRouter({ apiKey, defaultHeaders: { 'HTTP-Referer': 'https://sune.chat', 'X-Title': 'Sune' } }); const stream = await client.chat.send({ ...body, stream: true }); let hasReasoning = false, hasContent = false; + const collectedImages = []; for await (const chunk of stream) { if (this.phase !== 'running') break; const delta = chunk?.choices?.[0]?.delta; - const images = delta?.images; + if (!delta) continue; - if (delta?.reasoning && body.reasoning?.exclude !== true) { + if (delta.reasoning && body.reasoning?.exclude !== true) { this.queueDelta(delta.reasoning); hasReasoning = true; } - if (delta?.content) { + if (delta.content) { if (hasReasoning && !hasContent) this.queueDelta('\n'); this.queueDelta(delta.content); hasContent = true; } - if (images) { - this.queueDelta('', images); - } + if (Array.isArray(delta.images)) collectedImages.push(...delta.images); } + if (collectedImages.length) this.queueDelta('', collectedImages); } stop() {