Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@ export async function generateContextTypesCore(typeCreationRequest: ProcessConte
try {
const biDiagramRpcManager = new BiDiagramRpcManager();
const langClient = StateMachine.langClient();
const context = StateMachine.context();
const projectComponents = await biDiagramRpcManager.getProjectComponents();

// Generate types from context with validation
Expand All @@ -809,11 +810,22 @@ export async function generateContextTypesCore(typeCreationRequest: ProcessConte
langClient
);

// For workspace projects, compute relative file path from workspace root
const workspacePath = context.workspacePath;
const projectRoot = context.projectPath;
let targetFilePath = filePath;

if (workspacePath && projectRoot) {
// Workspace project: need to include package path prefix (e.g., "foo/types.bal")
const absoluteFilePath = path.isAbsolute(filePath) ? filePath : path.join(projectRoot, filePath);
targetFilePath = path.relative(workspacePath, absoluteFilePath);
}

// Build assistant response
const sourceAttachmentNames = typeCreationRequest.attachments?.map(a => a.name).join(", ") || "attachment";
const fileText = typeCreationRequest.attachments?.length === 1 ? "file" : "files";
assistantResponse = `Record types generated from the ${sourceAttachmentNames} ${fileText} shown below.\n`;
assistantResponse += `<code filename="${filePath}" type="type_creator">\n\`\`\`ballerina\n${typesCode}\n\`\`\`\n</code>`;
assistantResponse += `<code filename="${targetFilePath}" type="type_creator">\n\`\`\`ballerina\n${typesCode}\n\`\`\`\n</code>`;

// Send assistant response through event handler
eventHandler({ type: "content_block", content: assistantResponse });
Expand Down
Loading