@@ -800,6 +800,7 @@ export async function generateContextTypesCore(typeCreationRequest: ProcessConte
800800 try {
801801 const biDiagramRpcManager = new BiDiagramRpcManager ( ) ;
802802 const langClient = StateMachine . langClient ( ) ;
803+ const context = StateMachine . context ( ) ;
803804 const projectComponents = await biDiagramRpcManager . getProjectComponents ( ) ;
804805
805806 // Generate types from context with validation
@@ -809,11 +810,22 @@ export async function generateContextTypesCore(typeCreationRequest: ProcessConte
809810 langClient
810811 ) ;
811812
813+ // For workspace projects, compute relative file path from workspace root
814+ const workspacePath = context . workspacePath ;
815+ const projectRoot = context . projectPath ;
816+ let targetFilePath = filePath ;
817+
818+ if ( workspacePath && projectRoot ) {
819+ // Workspace project: need to include package path prefix (e.g., "foo/types.bal")
820+ const absoluteFilePath = path . isAbsolute ( filePath ) ? filePath : path . join ( projectRoot , filePath ) ;
821+ targetFilePath = path . relative ( workspacePath , absoluteFilePath ) ;
822+ }
823+
812824 // Build assistant response
813825 const sourceAttachmentNames = typeCreationRequest . attachments ?. map ( a => a . name ) . join ( ", " ) || "attachment" ;
814826 const fileText = typeCreationRequest . attachments ?. length === 1 ? "file" : "files" ;
815827 assistantResponse = `Record types generated from the ${ sourceAttachmentNames } ${ fileText } shown below.\n` ;
816- assistantResponse += `<code filename="${ filePath } " type="type_creator">\n\`\`\`ballerina\n${ typesCode } \n\`\`\`\n</code>` ;
828+ assistantResponse += `<code filename="${ targetFilePath } " type="type_creator">\n\`\`\`ballerina\n${ typesCode } \n\`\`\`\n</code>` ;
817829
818830 // Send assistant response through event handler
819831 eventHandler ( { type : "content_block" , content : assistantResponse } ) ;
0 commit comments