Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🔨 chore(model-runtime): openai stream error not inherited correctly (#9102)

Neko7f1b631c3515
diff --git a/packages/model-runtime/src/core/streams/openai/openai.test.ts b/packages/model-runtime/src/core/streams/openai/openai.test.ts
index 8a80b0adff0..0ee741aa08c 100644
--- a/packages/model-runtime/src/core/streams/openai/openai.test.ts
+++ b/packages/model-runtime/src/core/streams/openai/openai.test.ts
@@ -396,7 +396,7 @@ describe('OpenAIStream', () => {
expect(chunks).toEqual([
'id: first_chunk_error\n',
'event: error\n',
- `data: {"body":{"errorType":"ProviderBizError","message":"Test error"},"type":"ProviderBizError"}\n\n`,
+ `data: {"body":{"errorType":"ProviderBizError","message":"Test error"},"message":"Test error","type":"ProviderBizError"}\n\n`,
]);
});
@@ -427,7 +427,7 @@ describe('OpenAIStream', () => {
expect(chunks).toEqual([
'id: first_chunk_error\n',
'event: error\n',
- `data: {"body":{"message":"Custom error","errorType":"PermissionDenied","provider":"grok"},"type":"PermissionDenied"}\n\n`,
+ `data: {"body":{"message":"Custom error","errorType":"PermissionDenied","provider":"grok"},"message":"Custom error","type":"PermissionDenied"}\n\n`,
]);
});
diff --git a/packages/model-runtime/src/core/streams/openai/openai.ts b/packages/model-runtime/src/core/streams/openai/openai.ts
index 9d00ce0a2ad..2f178bfab1c 100644
--- a/packages/model-runtime/src/core/streams/openai/openai.ts
+++ b/packages/model-runtime/src/core/streams/openai/openai.ts
@@ -57,8 +57,9 @@ const transformOpenAIStream = (
const errorData = {
body: chunk,
- type: 'errorType' in chunk ? chunk.errorType : AgentRuntimeErrorType.ProviderBizError,
- } as ChatMessageError;
+ message: 'message' in chunk ? typeof chunk.message === 'string' ? chunk.message : JSON.stringify(chunk) : JSON.stringify(chunk),
+ type: 'errorType' in chunk ? chunk.errorType as typeof AgentRuntimeErrorType.ProviderBizError : AgentRuntimeErrorType.ProviderBizError,
+ } satisfies ChatMessageError;
return { data: errorData, id: 'first_chunk_error', type: 'error' };
}
diff --git a/packages/model-runtime/src/core/streams/openai/responsesStream.ts b/packages/model-runtime/src/core/streams/openai/responsesStream.ts
index 5d43bcbc7b9..5d11dbdbaf4 100644
--- a/packages/model-runtime/src/core/streams/openai/responsesStream.ts
+++ b/packages/model-runtime/src/core/streams/openai/responsesStream.ts
@@ -45,8 +45,9 @@ const transformOpenAIStream = (
const errorData = {
body: chunk,
- type: 'errorType' in chunk ? chunk.errorType : AgentRuntimeErrorType.ProviderBizError,
- } as ChatMessageError;
+ message: 'message' in chunk ? typeof chunk.message === 'string' ? chunk.message : JSON.stringify(chunk) : JSON.stringify(chunk),
+ type: 'errorType' in chunk ? chunk.errorType as typeof AgentRuntimeErrorType.ProviderBizError : AgentRuntimeErrorType.ProviderBizError,
+ } satisfies ChatMessageError;
return { data: errorData, id: 'first_chunk_error', type: 'error' };
}