mirror of
https://github.com/sune-org/ORP.git
synced 2026-01-13 16:17:59 +00:00
Revert: Update index.js
This commit is contained in:
21
index.js
21
index.js
@@ -5,7 +5,7 @@ const TTL_MS = 20 * 60 * 1000;
|
||||
const BATCH_MS = 800;
|
||||
const BATCH_BYTES = 3400;
|
||||
const HB_INTERVAL_MS = 3000;
|
||||
const MAX_RUN_MS = 9 * 60 * 1000;
|
||||
const MAX_RUN_MS = 7 * 60 * 1000;
|
||||
|
||||
const CORS_HEADERS = {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
@@ -142,7 +142,7 @@ export class MyDurableObject {
|
||||
}
|
||||
|
||||
replay(ws, after) {
|
||||
this.buffer.forEach(it => { if (it.seq > after) this.send(ws, { type: 'delta', ...it }); });
|
||||
this.buffer.forEach(it => { if (it.seq > after) this.send(ws, { type: 'delta', seq: it.seq, text: it.text }); });
|
||||
if (this.phase === 'done') this.send(ws, { type: 'done' });
|
||||
else if (['error', 'evicted'].includes(this.phase)) this.send(ws, { type: 'err', message: this.error || 'The run was terminated unexpectedly.' });
|
||||
}
|
||||
@@ -150,9 +150,8 @@ export class MyDurableObject {
|
||||
flush(force = false) {
|
||||
if (this.flushTimer) { clearTimeout(this.flushTimer); this.flushTimer = null; }
|
||||
if (this.pending) {
|
||||
const item = { seq: ++this.seq, text: this.pending };
|
||||
this.buffer.push(item);
|
||||
this.bcast({ type: 'delta', ...item });
|
||||
this.buffer.push({ seq: ++this.seq, text: this.pending });
|
||||
this.bcast({ type: 'delta', seq: this.seq, text: this.pending });
|
||||
this.pending = '';
|
||||
this.lastFlushedAt = Date.now();
|
||||
}
|
||||
@@ -180,11 +179,10 @@ export class MyDurableObject {
|
||||
|
||||
if (req.method === 'GET') {
|
||||
await this.autopsy();
|
||||
const text = this.buffer.filter(it => it.text).map(it => it.text).join('') + this.pending;
|
||||
const images = this.buffer.flatMap(it => it.images || []);
|
||||
const text = this.buffer.map(it => it.text).join('') + this.pending;
|
||||
const isTerminal = ['done', 'error', 'evicted'].includes(this.phase);
|
||||
const isError = ['error', 'evicted'].includes(this.phase);
|
||||
const payload = { rid: this.rid, seq: this.seq, phase: this.phase, done: isTerminal, error: isError ? (this.error || 'The run was terminated unexpectedly.') : null, text, images };
|
||||
const payload = { rid: this.rid, seq: this.seq, phase: this.phase, done: isTerminal, error: isError ? (this.error || 'The run was terminated unexpectedly.') : null, text };
|
||||
return this.corsJSON(payload);
|
||||
}
|
||||
return this.corsJSON({ error: 'not allowed' }, 405);
|
||||
@@ -343,12 +341,6 @@ export class MyDurableObject {
|
||||
this.queueDelta(delta.reasoning);
|
||||
hasReasoning = true;
|
||||
}
|
||||
if (Array.isArray(delta?.images) && delta.images.length > 0) {
|
||||
this.flush(false);
|
||||
const item = { seq: ++this.seq, images: delta.images };
|
||||
this.buffer.push(item);
|
||||
this.bcast({ type: 'delta', ...item });
|
||||
}
|
||||
if (delta?.content) {
|
||||
if (hasReasoning && !hasContent) this.queueDelta('\n');
|
||||
this.queueDelta(delta.content);
|
||||
@@ -453,3 +445,4 @@ export class MyDurableObject {
|
||||
return contents;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user