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>
});
}
// Extract JSON from markdown code block
// The evoltagent library strips <TaskCompletion> tags before calling postProcessor
const jsonMatch = response.match(/```json\n([\s\S]*?)\n```/);
// The evoltagent library strips <TaskCompletion> tags before calling postProcessor.
// Be tolerant: the model may emit ```json, ```JSON, a bare ``` fence, or even a
// 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) {
logger.printInfoLog('Launch agent response missing JSON block');
return Promise.resolve({
success: false,
error: 'No JSON code block found in agent response',
});
}
const jsonFence = response.match(/```json\s*\n?([\s\S]*?)```/i);
if (jsonFence) candidates.push(jsonFence[1]);
const jsonStr = jsonMatch[1];
const anyFence = response.match(/```\s*\n?([\s\S]*?)```/);
if (anyFence) candidates.push(anyFence[1]);
if (!jsonStr || jsonStr.trim().length === 0) {
logger.printInfoLog('Launch agent response has empty JSON');
return Promise.resolve({
success: false,
error: 'Empty JSON content in code block',
});
}
const braceMatch = response.match(/\{[\s\S]*\}/);
if (braceMatch) candidates.push(braceMatch[0]);
try {
const parsed = JSON.parse(jsonStr) as LaunchAgentResult;
for (const raw of candidates) {
const jsonStr = (raw ?? '').trim();
if (!jsonStr) continue;
// Validate required fields if success is true
if (parsed.success === true && (!parsed.serverKey || !parsed.url || !parsed.port)) {
logger.printInfoLog('Launch agent success response missing required fields');
return Promise.resolve({
success: false,
error: 'Missing required fields (serverKey, url, or port)',
});
}
// Tolerate trailing commas before parsing
const normalized = jsonStr.replace(/,(\s*[}\]])/g, '$1');
return Promise.resolve(parsed);
} catch (error) {
logger.printInfoLog(`Launch agent response JSON parse failed: ${error instanceof Error ? error.message : String(error)}`);
return Promise.resolve({
success: false,
error: error instanceof Error ? error.message : String(error),
});
try {
const parsed = JSON.parse(normalized) as LaunchAgentResult;
if (!parsed || typeof parsed !== 'object') continue;
// A usable result must signal success explicitly OR carry the server fields.
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> = {
"@radix-ui/react-dialog": "^1.1.6",
"@radix-ui/react-dropdown-menu": "^2.1.6",
"@radix-ui/react-tooltip": "^1.1.8",
"@radix-ui/react-avatar": "^1.1.2",
"@radix-ui/react-tabs": "^1.1.3",
"class-variance-authority": "^0.7.1",
clsx: "^2.1.1",
......@@ -661,9 +662,7 @@ SheetTitle.displayName = SheetPrimitive.Title.displayName
const SheetDescription = React.forwardRef<
React.ElementRef<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} />
))
SheetDescription.displayName = SheetPrimitive.Description.displayName
......@@ -869,9 +868,8 @@ const FormField = ({ name, ...props }: { name: string } & React.ComponentProps<t
const useFormField = () => {
const fieldContext = React.useContext(FormFieldContext)
const { getFieldState } = useFormState({ name: fieldContext.name })
const formContext = useFormContext()
const fieldState = getFieldState(formContext)
const { getFieldState, formState } = useFormContext()
const fieldState = getFieldState(fieldContext.name, formState)
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!