@@ -43,6 +43,12 @@ import { URI } from "vscode-uri";
4343import fs from 'fs' ;
4444import { writeBallerinaFileDidOpenTemp } from "../../../../../src/utils/modification" ;
4545
46+ const NO_MAPPINGS_GENERATED_WARNING = `**No Relevant Mappings Generated**\n\n` +
47+ `The AI was unable to identify compatible field mappings between the input and output structures.\n\n` +
48+ `**Suggestions:**\n` +
49+ `- Check if input and output record structures are correct\n` +
50+ `- Try providing mapping hints or examples\n` ;
51+
4652// =============================================================================
4753// ENHANCED MAIN ORCHESTRATOR FUNCTION
4854// =============================================================================
@@ -340,6 +346,13 @@ export async function generateMappingCodeCore(mappingRequest: ProcessMappingPara
340346 attachments : mappingRequest . attachments
341347 } , context , eventHandler ) ;
342348
349+ // Check if no mappings were generated
350+ if ( ! allMappingsRequest . mappings || allMappingsRequest . mappings . length === 0 ) {
351+ eventHandler ( { type : "content_block" , content : NO_MAPPINGS_GENERATED_WARNING } ) ;
352+ eventHandler ( { type : "stop" , command : Command . DataMap } ) ;
353+ return ;
354+ }
355+
343356 const sourceCodeResponse = await getAllDataMapperSource ( allMappingsRequest ) ;
344357
345358 await updateSourceCode ( { textEdits : sourceCodeResponse . textEdits , skipPayloadCheck : true } ) ;
@@ -694,6 +707,13 @@ export async function generateInlineMappingCodeCore(inlineMappingRequest: Metada
694707 const inlineMappingsResult : InlineMappingsSourceResult =
695708 await generateInlineMappingsSource ( inlineMappingRequest , langClient , context , eventHandler ) ;
696709
710+ // Check if no mappings were generated
711+ if ( ! inlineMappingsResult . allMappingsRequest . mappings || inlineMappingsResult . allMappingsRequest . mappings . length === 0 ) {
712+ eventHandler ( { type : "content_block" , content : NO_MAPPINGS_GENERATED_WARNING } ) ;
713+ eventHandler ( { type : "stop" , command : Command . DataMap } ) ;
714+ return ;
715+ }
716+
697717 await updateSourceCode ( { textEdits : inlineMappingsResult . sourceResponse . textEdits , skipPayloadCheck : true } ) ;
698718 await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) ) ;
699719
0 commit comments