From 62604b42d58c22ddbe6ab42c381cfbee731bd626 Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Mon, 29 Dec 2025 05:33:20 -0800 Subject: [PATCH] Revert: Update index.js --- index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 8a9a2c7..337f0b1 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; - if (!delta) continue; + const images = delta?.images; - 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 (Array.isArray(delta.images)) collectedImages.push(...delta.images); + if (images) { + this.queueDelta('', images); + } } - if (collectedImages.length) this.queueDelta('', collectedImages); } stop() {