fix: unblock local news page generation

This commit is contained in:
john
2026-07-25 21:55:00 +08:00
parent 793e64bfbc
commit 6b6f9ed01c
16 changed files with 1075 additions and 47 deletions
+15 -4
View File
@@ -33,6 +33,19 @@ function messageContentItems(event) {
return candidates.find((content) => Array.isArray(content)) ?? [];
}
export function classifySessionProviderErrorMessage(message) {
const normalized = String(message ?? '').trim();
if (!normalized) return 'SESSION_REPLY_ERROR';
if (/tool_calls|tool_call_id|insufficient tool messages/i.test(normalized)) {
return 'SESSION_TOOL_HISTORY_POISONED';
}
// DeepSeek/Kimi thinking mode: assistant tool-call turns must replay reasoning_content.
if (/reasoning_content/i.test(normalized)) {
return 'SESSION_REASONING_CONTENT_POISONED';
}
return 'SESSION_REPLY_ERROR';
}
function providerReplyError(event) {
if (event?.type !== 'Message') return null;
const text = messageContentItems(event)
@@ -46,9 +59,7 @@ function providerReplyError(event) {
.replace(/\n\nPlease retry if you think this is a transient or recoverable error\.?\s*$/i, '')
.trim();
const error = new Error(normalized || 'session reply failed');
error.code = /tool_calls|tool_call_id|insufficient tool messages/i.test(normalized)
? 'SESSION_TOOL_HISTORY_POISONED'
: 'SESSION_REPLY_ERROR';
error.code = classifySessionProviderErrorMessage(normalized);
return error;
}
@@ -162,7 +173,7 @@ export async function consumeSessionEventsUntilFinish(
onEvent?.(event);
if (event.type === 'Error') {
const err = new Error(String(event.error ?? 'session reply failed'));
err.code = 'SESSION_REPLY_ERROR';
err.code = classifySessionProviderErrorMessage(err.message);
err.retryable = false;
throw err;
}