fix(web): propagate mid-stream API errors and raise max_tokens

- Streaming loop swallowed errors: a mid-stream error event (e.g.
  overloaded_error) was thrown inside the same try/catch used to skip
  unparseable SSE lines, so it was silently ignored and the run reported
  "Done." with truncated output. Separate JSON parsing from event handling
  so real errors surface to the user.
- Raise max_tokens 4096 -> 8192 to avoid truncating long skill outputs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Mohit
2026-06-09 12:07:18 +01:00
parent 735df19a9b
commit 5721cd3a49
2 changed files with 13 additions and 10 deletions
+7 -4
View File
@@ -170,7 +170,7 @@ async function run() {
},
body: JSON.stringify({
model: el('model').value,
max_tokens: 4096,
max_tokens: 8192,
stream: true,
system,
messages: [{ role: 'user', content: userMessage }],
@@ -193,15 +193,18 @@ async function run() {
if (!line.startsWith('data:')) continue;
const payload = line.slice(5).trim();
if (!payload || payload === '[DONE]') continue;
let evt;
try {
const evt = JSON.parse(payload);
evt = JSON.parse(payload);
} catch (_) {
continue; // skip an unparseable / partial SSE line
}
if (evt.type === 'content_block_delta' && evt.delta && evt.delta.text) {
acc += evt.delta.text;
renderMarkdown(out, acc, true);
} else if (evt.type === 'error') {
throw new Error(evt.error ? evt.error.message : 'stream error');
throw new Error(evt.error ? evt.error.message : 'Stream error from the API.');
}
} catch (_) { /* ignore partial */ }
}
}
renderMarkdown(out, acc, false);
+1 -1
View File
File diff suppressed because one or more lines are too long