feat(vscode-ide-companion): 优化权限请求组件并添加错误处理功能

- 移动权限请求组件到抽屉中,优化用户体验
- 为权限选项添加编号,提高可识别性
- 实现错误对象的特殊处理,提取更有意义的错误信息
- 优化工具调用错误内容的展示,提高错误信息的可读性
This commit is contained in:
yiliang114
2025-11-20 00:01:18 +08:00
parent 018990b7f6
commit e81255e589
6 changed files with 342 additions and 20 deletions

View File

@@ -18,6 +18,15 @@ export const formatValue = (value: unknown): string => {
if (typeof value === 'string') {
return value;
}
// Handle Error objects specially
if (value instanceof Error) {
return value.message || value.toString();
}
// Handle error-like objects with message property
if (typeof value === 'object' && value !== null && 'message' in value) {
const errorObj = value as { message?: string; stack?: string };
return errorObj.message || String(value);
}
if (typeof value === 'object') {
try {
return JSON.stringify(value, null, 2);
@@ -84,10 +93,34 @@ export const groupContent = (content?: ToolCallContent[]): GroupedContent => {
// Handle error content
if (contentObj.type === 'error' || 'error' in contentObj) {
const errorMsg =
formatValue(contentObj.error) ||
formatValue(contentObj.text) ||
'An error occurred';
// Try to extract meaningful error message
let errorMsg = '';
// Check if error is a string
if (typeof contentObj.error === 'string') {
errorMsg = contentObj.error;
}
// Check if error has a message property
else if (
contentObj.error &&
typeof contentObj.error === 'object' &&
'message' in contentObj.error
) {
errorMsg = (contentObj.error as { message: string }).message;
}
// Try text field
else if (contentObj.text) {
errorMsg = formatValue(contentObj.text);
}
// Format the error object itself
else if (contentObj.error) {
errorMsg = formatValue(contentObj.error);
}
// Fallback
else {
errorMsg = 'An error occurred';
}
errors.push(errorMsg);
}
// Handle text content