mirror of https://github.com/kortix-ai/suna.git
AI: How can we stream the edit_file tool when it generating like create_file ? Also the edit_file tool show this
"""Invalid File Edit Could not extract the file changes from the tool result.""" Check the state of code base and make to sure implement fully
This commit is contained in:
parent
a2eac10d87
commit
2def96efc9
|
@ -38,7 +38,8 @@ export const ShowToolStream: React.FC<ShowToolStreamProps> = ({
|
||||||
stableStartTimeRef.current = Date.now();
|
stableStartTimeRef.current = Date.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
const toolName = extractToolNameFromStream(content);
|
const rawToolName = extractToolNameFromStream(content);
|
||||||
|
const toolName = getUserFriendlyToolName(rawToolName || '');
|
||||||
const isEditFile = toolName === 'AI File Edit';
|
const isEditFile = toolName === 'AI File Edit';
|
||||||
|
|
||||||
// Extract code_edit content for streaming
|
// Extract code_edit content for streaming
|
||||||
|
@ -105,9 +106,9 @@ export const ShowToolStream: React.FC<ShowToolStreamProps> = ({
|
||||||
// Check if this is a file operation tool
|
// Check if this is a file operation tool
|
||||||
const isFileOperationTool = FILE_OPERATION_TOOLS.has(toolName);
|
const isFileOperationTool = FILE_OPERATION_TOOLS.has(toolName);
|
||||||
|
|
||||||
const IconComponent = getToolIcon(toolName);
|
const IconComponent = getToolIcon(rawToolName || '');
|
||||||
const displayName = getUserFriendlyToolName(toolName);
|
const displayName = toolName;
|
||||||
const paramDisplay = extractPrimaryParam(toolName, content);
|
const paramDisplay = extractPrimaryParam(rawToolName || '', content);
|
||||||
|
|
||||||
// Always show tool button, conditionally show content below for file operations only
|
// Always show tool button, conditionally show content below for file operations only
|
||||||
if (showExpanded && (isFileOperationTool || isEditFile)) {
|
if (showExpanded && (isFileOperationTool || isEditFile)) {
|
||||||
|
|
|
@ -201,6 +201,28 @@ export interface ExtractedEditData {
|
||||||
errorMessage?: string;
|
errorMessage?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const parseContent = (content: any): any => {
|
||||||
|
if (typeof content === 'string') {
|
||||||
|
try {
|
||||||
|
return JSON.parse(content);
|
||||||
|
} catch (e) {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return content;
|
||||||
|
};
|
||||||
|
|
||||||
|
const parseOutput = (output: any) => {
|
||||||
|
if (typeof output === 'string') {
|
||||||
|
try {
|
||||||
|
return JSON.parse(output);
|
||||||
|
} catch {
|
||||||
|
return output; // Return as string if not JSON
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
};
|
||||||
|
|
||||||
export const extractFileEditData = (
|
export const extractFileEditData = (
|
||||||
assistantContent: any,
|
assistantContent: any,
|
||||||
toolContent: any,
|
toolContent: any,
|
||||||
|
|
|
@ -100,14 +100,12 @@ export function isNewXmlFormat(content: string): boolean {
|
||||||
export function extractToolNameFromStream(content: string): string | null {
|
export function extractToolNameFromStream(content: string): string | null {
|
||||||
const invokeMatch = content.match(/<invoke\s+name=["']([^"']+)["']/i);
|
const invokeMatch = content.match(/<invoke\s+name=["']([^"']+)["']/i);
|
||||||
if (invokeMatch) {
|
if (invokeMatch) {
|
||||||
const toolName = invokeMatch[1].replace(/_/g, '-');
|
return invokeMatch[1].replace(/_/g, '-');
|
||||||
return formatToolNameForDisplay(toolName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const oldFormatMatch = content.match(/<([a-zA-Z\-_]+)(?:\s+[^>]*)?>(?!\/)/);
|
const oldFormatMatch = content.match(/<([a-zA-Z\-_]+)(?:\s+[^>]*)?>(?!\/)/);
|
||||||
if (oldFormatMatch) {
|
if (oldFormatMatch) {
|
||||||
const toolName = oldFormatMatch[1].replace(/_/g, '-');
|
return oldFormatMatch[1].replace(/_/g, '-');
|
||||||
return formatToolNameForDisplay(toolName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue