Commit 3309ef80 by liimin

fix(engine): 修复 shadcn 脚手架组件编译错误与 launch 解析容错

- shadcn-ui.ts: 补充缺失依赖 @radix-ui/react-avatar;修正 form.tsx 的 getFieldState 用法(改用 useFormContext);修正 sheet.tsx 箭头函数前多余换行导致的语法错误
- launch-agent/utils.ts: parseLaunchResult 容错增强(兼容 json 大小写/无语言标签/裸 JSON/尾逗号),避免模型格式微小偏差导致整个校验任务硬失败
1 parent 2de0a5f0
...@@ -20,46 +20,50 @@ export function parseLaunchResult(response: string): Promise<LaunchAgentResult> ...@@ -20,46 +20,50 @@ export function parseLaunchResult(response: string): Promise<LaunchAgentResult>
}); });
} }
// Extract JSON from markdown code block // The evoltagent library strips <TaskCompletion> tags before calling postProcessor.
// The evoltagent library strips <TaskCompletion> tags before calling postProcessor // Be tolerant: the model may emit ```json, ```JSON, a bare ``` fence, or even a
const jsonMatch = response.match(/```json\n([\s\S]*?)\n```/); // bare {…} object. We try several extraction strategies before giving up so a
// minor formatting variance (or a trailing comma) does not abort the whole run.
const candidates: string[] = [];
if (!jsonMatch) { const jsonFence = response.match(/```json\s*\n?([\s\S]*?)```/i);
logger.printInfoLog('Launch agent response missing JSON block'); if (jsonFence) candidates.push(jsonFence[1]);
return Promise.resolve({
success: false,
error: 'No JSON code block found in agent response',
});
}
const jsonStr = jsonMatch[1]; const anyFence = response.match(/```\s*\n?([\s\S]*?)```/);
if (anyFence) candidates.push(anyFence[1]);
if (!jsonStr || jsonStr.trim().length === 0) { const braceMatch = response.match(/\{[\s\S]*\}/);
logger.printInfoLog('Launch agent response has empty JSON'); if (braceMatch) candidates.push(braceMatch[0]);
return Promise.resolve({
success: false,
error: 'Empty JSON content in code block',
});
}
try { for (const raw of candidates) {
const parsed = JSON.parse(jsonStr) as LaunchAgentResult; const jsonStr = (raw ?? '').trim();
if (!jsonStr) continue;
// Validate required fields if success is true // Tolerate trailing commas before parsing
if (parsed.success === true && (!parsed.serverKey || !parsed.url || !parsed.port)) { const normalized = jsonStr.replace(/,(\s*[}\]])/g, '$1');
logger.printInfoLog('Launch agent success response missing required fields');
return Promise.resolve({
success: false,
error: 'Missing required fields (serverKey, url, or port)',
});
}
return Promise.resolve(parsed); try {
} catch (error) { const parsed = JSON.parse(normalized) as LaunchAgentResult;
logger.printInfoLog(`Launch agent response JSON parse failed: ${error instanceof Error ? error.message : String(error)}`); if (!parsed || typeof parsed !== 'object') continue;
return Promise.resolve({
success: false, // A usable result must signal success explicitly OR carry the server fields.
error: error instanceof Error ? error.message : String(error), const hasServerFields = !!(parsed.serverKey && parsed.url && parsed.port);
}); if (parsed.success === true && !hasServerFields) {
continue; // incomplete success payload, try next candidate
}
if (parsed.success === undefined && !hasServerFields) {
continue; // not a real launch result, try next candidate
}
return Promise.resolve(parsed);
} catch {
// Try next candidate
}
} }
logger.printInfoLog('Launch agent response missing JSON block');
return Promise.resolve({
success: false,
error: 'No JSON code block found in agent response',
});
} }
...@@ -24,6 +24,7 @@ export const shadcnDeps: Record<string, string> = { ...@@ -24,6 +24,7 @@ export const shadcnDeps: Record<string, string> = {
"@radix-ui/react-dialog": "^1.1.6", "@radix-ui/react-dialog": "^1.1.6",
"@radix-ui/react-dropdown-menu": "^2.1.6", "@radix-ui/react-dropdown-menu": "^2.1.6",
"@radix-ui/react-tooltip": "^1.1.8", "@radix-ui/react-tooltip": "^1.1.8",
"@radix-ui/react-avatar": "^1.1.2",
"@radix-ui/react-tabs": "^1.1.3", "@radix-ui/react-tabs": "^1.1.3",
"class-variance-authority": "^0.7.1", "class-variance-authority": "^0.7.1",
clsx: "^2.1.1", clsx: "^2.1.1",
...@@ -661,9 +662,7 @@ SheetTitle.displayName = SheetPrimitive.Title.displayName ...@@ -661,9 +662,7 @@ SheetTitle.displayName = SheetPrimitive.Title.displayName
const SheetDescription = React.forwardRef< const SheetDescription = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Description>, React.ElementRef<typeof SheetPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Description> React.ComponentPropsWithoutRef<typeof SheetPrimitive.Description>
>(({ className, ...props }, ref) >(({ className, ...props }, ref) => (
=> (
<SheetPrimitive.Description ref={ref} className={cn("text-sm text-muted-foreground", className)} {...props} /> <SheetPrimitive.Description ref={ref} className={cn("text-sm text-muted-foreground", className)} {...props} />
)) ))
SheetDescription.displayName = SheetPrimitive.Description.displayName SheetDescription.displayName = SheetPrimitive.Description.displayName
...@@ -869,9 +868,8 @@ const FormField = ({ name, ...props }: { name: string } & React.ComponentProps<t ...@@ -869,9 +868,8 @@ const FormField = ({ name, ...props }: { name: string } & React.ComponentProps<t
const useFormField = () => { const useFormField = () => {
const fieldContext = React.useContext(FormFieldContext) const fieldContext = React.useContext(FormFieldContext)
const { getFieldState } = useFormState({ name: fieldContext.name }) const { getFieldState, formState } = useFormContext()
const formContext = useFormContext() const fieldState = getFieldState(fieldContext.name, formState)
const fieldState = getFieldState(formContext)
return { name: fieldContext.name, formItemId: \`\${fieldContext.name}-form-item\`, formDescriptionId: \`\${fieldContext.name}-form-item-description\`, formMessageId: \`\${fieldContext.name}-form-item-message\`, ...fieldState } return { name: fieldContext.name, formItemId: \`\${fieldContext.name}-form-item\`, formDescriptionId: \`\${fieldContext.name}-form-item-description\`, formMessageId: \`\${fieldContext.name}-form-item-message\`, ...fieldState }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!