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:
+12
-9
@@ -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);
|
||||
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');
|
||||
}
|
||||
} catch (_) { /* ignore partial */ }
|
||||
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 from the API.');
|
||||
}
|
||||
}
|
||||
}
|
||||
renderMarkdown(out, acc, false);
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user