feat: 增强聊天代理流行为,优化错误处理和工具调用逻辑
This commit is contained in:
@@ -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') {
|
||||
|
||||
Reference in New Issue
Block a user