fix(ai): Improve AI object response handling in parse-prd
This commit updates to more robustly handle responses from . Previously, the module strictly expected the AI-generated object to be nested under . This change ensures that it now first checks if itself contains the expected task data object, and then falls back to checking . This enhancement increases compatibility with varying AI provider response structures, similar to the improvements recently made in .
This commit is contained in:
@@ -226,10 +226,30 @@ Guidelines:
|
||||
if (!fs.existsSync(tasksDir)) {
|
||||
fs.mkdirSync(tasksDir, { recursive: true });
|
||||
}
|
||||
logFn.success('Successfully parsed PRD via AI service.');
|
||||
logFn.success('Successfully parsed PRD via AI service.\n');
|
||||
|
||||
// Validate and Process Tasks
|
||||
const generatedData = aiServiceResponse?.mainResult?.object;
|
||||
// const generatedData = aiServiceResponse?.mainResult?.object;
|
||||
|
||||
// Robustly get the actual AI-generated object
|
||||
let generatedData = null;
|
||||
if (aiServiceResponse?.mainResult) {
|
||||
if (
|
||||
typeof aiServiceResponse.mainResult === 'object' &&
|
||||
aiServiceResponse.mainResult !== null &&
|
||||
'tasks' in aiServiceResponse.mainResult
|
||||
) {
|
||||
// If mainResult itself is the object with a 'tasks' property
|
||||
generatedData = aiServiceResponse.mainResult;
|
||||
} else if (
|
||||
typeof aiServiceResponse.mainResult.object === 'object' &&
|
||||
aiServiceResponse.mainResult.object !== null &&
|
||||
'tasks' in aiServiceResponse.mainResult.object
|
||||
) {
|
||||
// If mainResult.object is the object with a 'tasks' property
|
||||
generatedData = aiServiceResponse.mainResult.object;
|
||||
}
|
||||
}
|
||||
|
||||
if (!generatedData || !Array.isArray(generatedData.tasks)) {
|
||||
logFn.error(
|
||||
|
||||
Reference in New Issue
Block a user