Skip to content
Closed
Show file tree
Hide file tree
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
42 changes: 42 additions & 0 deletions src/core/webview/webviewMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2655,5 +2655,47 @@ export const webviewMessageHandler = async (
vscode.window.showWarningMessage(t("common:mdm.info.organization_requires_auth"))
break
}
case "fixMermaidDiagram": {
// Handle Mermaid diagram fixing request
const { code, error } = message
if (code && error) {
try {
// Import the MermaidDiagramFixer
const { MermaidDiagramFixer } = await import("../../services/mermaid/MermaidDiagramFixer")

// Get the API configuration
const { apiConfiguration } = await provider.getState()

// Create fixer instance with Gemini API key
const fixer = new MermaidDiagramFixer({
geminiApiKey: apiConfiguration.geminiApiKey,
geminiModel: apiConfiguration.apiModelId,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using apiConfiguration.apiModelId for the Gemini model might cause confusion since this field is meant for the main chat model. Consider using a dedicated field like 'geminiModelId' or 'geminiApiModelId' to avoid conflicts when users have different models configured for chat vs. diagram fixing.

})

// Fix the diagram
const fixedCode = await fixer.fixDiagram(code, error)

// Send the fixed code back to the webview
await provider.postMessageToWebview({
type: "mermaidDiagramFixed",
originalCode: code,
fixedCode: fixedCode,
})

vscode.window.showInformationMessage(
t("common:info.mermaid_diagram_fixed") || "Mermaid diagram has been fixed!",
)
} catch (error) {
provider.log(
`Error fixing Mermaid diagram: ${JSON.stringify(error, Object.getOwnPropertyNames(error), 2)}`,
)
vscode.window.showErrorMessage(
t("common:errors.mermaid.fix_failed") ||
`Failed to fix diagram: ${error instanceof Error ? error.message : String(error)}`,
)
}
}
break
}
}
}
9 changes: 7 additions & 2 deletions src/i18n/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@
"gemini": {
"generate_stream": "Gemini generate context stream error: {{error}}",
"generate_complete_prompt": "Gemini completion error: {{error}}",
"sources": "Sources:"
"sources": "Sources:",
"api_key_required": "Gemini API key is required for diagram fixing"
},
"mermaid": {
"fix_failed": "Failed to fix Mermaid diagram"
},
"cerebras": {
"authenticationFailed": "Cerebras API authentication failed. Please check your API key is valid and not expired.",
Expand Down Expand Up @@ -124,7 +128,8 @@
"image_copied_to_clipboard": "Image data URI copied to clipboard",
"image_saved": "Image saved to {{path}}",
"mode_exported": "Mode '{{mode}}' exported successfully",
"mode_imported": "Mode imported successfully"
"mode_imported": "Mode imported successfully",
"mermaid_diagram_fixed": "Mermaid diagram has been fixed successfully!"
},
"answers": {
"yes": "Yes",
Expand Down
Loading
Loading