mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-17 18:16:15 +08:00
feat(core): add ai tool call error type and ui (#12941)
<img width="775" alt="截屏2025-06-26 16 17 05" src="https://github.com/user-attachments/assets/ed6bcae3-94af-4eb1-81e8-710f36ef5e46" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Introduced a tool to crawl web pages and extract key information. * Added a visual component to display tool call failures in the AI interface. * Enhanced error reporting for document and web search tools with structured error messages. * **Improvements** * Updated error handling across AI tools and components for more consistent and informative feedback. * Default values added for tool card components to improve reliability and display. * **Bug Fixes** * Improved handling of error and empty states in web crawl and web search result displays. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -390,19 +390,19 @@ export interface CustomAITools extends ToolSet {
|
||||
|
||||
type ChunkType = TextStreamPart<CustomAITools>['type'];
|
||||
|
||||
export function parseUnknownError(error: unknown) {
|
||||
export function toError(error: unknown): Error {
|
||||
if (typeof error === 'string') {
|
||||
throw new Error(error);
|
||||
return new Error(error);
|
||||
} else if (error instanceof Error) {
|
||||
throw error;
|
||||
return error;
|
||||
} else if (
|
||||
typeof error === 'object' &&
|
||||
error !== null &&
|
||||
'message' in error
|
||||
) {
|
||||
throw new Error(String(error.message));
|
||||
return new Error(String(error.message));
|
||||
} else {
|
||||
throw new Error(JSON.stringify(error));
|
||||
return new Error(JSON.stringify(error));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -483,8 +483,7 @@ export class TextStreamParser {
|
||||
break;
|
||||
}
|
||||
case 'error': {
|
||||
parseUnknownError(chunk.error);
|
||||
break;
|
||||
throw toError(chunk.error);
|
||||
}
|
||||
}
|
||||
this.lastType = chunk.type;
|
||||
@@ -550,8 +549,7 @@ export class StreamObjectParser {
|
||||
return chunk;
|
||||
}
|
||||
case 'error': {
|
||||
parseUnknownError(chunk.error);
|
||||
return null;
|
||||
throw toError(chunk.error);
|
||||
}
|
||||
default: {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user