feat: 增强聊天代理流行为,优化错误处理和工具调用逻辑

This commit is contained in:
ciat-777
2026-03-03 00:03:34 +08:00
parent e2fce12e20
commit 5cebc1554f
4 changed files with 408 additions and 68 deletions
+17
View File
@@ -161,6 +161,10 @@ export function normalizeStopReason(raw: unknown): string | null {
const value = typeof raw === 'string' ? raw.trim().toLowerCase() : '';
if (!value) return null;
if (value === 'failed' || value === 'error') {
return 'error';
}
if (
value === 'end_turn'
|| value === 'stop'
@@ -803,6 +807,19 @@ export function normalizeUpstreamStreamEvent(
};
}
if (type === 'response.failed' || type === 'response.incomplete' || type === 'error') {
const responsePayload = isRecord((payload as any).response) ? (payload as any).response : null;
const finishReason = normalizeStopReason(
(responsePayload as any)?.status
?? (payload as any).status
?? (payload as any).type,
) || 'error';
return {
finishReason,
done: true,
};
}
if (type === 'response.output_item.added' && isRecord((payload as any).item)) {
const item = (payload as any).item as Record<string, unknown>;
if (item.type === 'function_call') {