Revert: Update index.js

This commit is contained in:
2025-12-29 05:33:20 -08:00
parent 5d778b3f2e
commit 62604b42d5

View File

@@ -333,24 +333,24 @@ export class MyDurableObject {
const client = new OpenRouter({ apiKey, defaultHeaders: { 'HTTP-Referer': 'https://sune.chat', 'X-Title': 'Sune' } }); const client = new OpenRouter({ apiKey, defaultHeaders: { 'HTTP-Referer': 'https://sune.chat', 'X-Title': 'Sune' } });
const stream = await client.chat.send({ ...body, stream: true }); const stream = await client.chat.send({ ...body, stream: true });
let hasReasoning = false, hasContent = false; let hasReasoning = false, hasContent = false;
const collectedImages = [];
for await (const chunk of stream) { for await (const chunk of stream) {
if (this.phase !== 'running') break; if (this.phase !== 'running') break;
const delta = chunk?.choices?.[0]?.delta; 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); this.queueDelta(delta.reasoning);
hasReasoning = true; hasReasoning = true;
} }
if (delta.content) { if (delta?.content) {
if (hasReasoning && !hasContent) this.queueDelta('\n'); if (hasReasoning && !hasContent) this.queueDelta('\n');
this.queueDelta(delta.content); this.queueDelta(delta.content);
hasContent = true; hasContent = true;
} }
if (Array.isArray(delta.images)) collectedImages.push(...delta.images); if (images) {
this.queueDelta('', images);
}
} }
if (collectedImages.length) this.queueDelta('', collectedImages);
} }
stop() { stop() {