mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-01-02 22:32:27 +08:00
feat: support minimax model (#185)
* feat: support minimax model with XML wrapping fix - Add wrapWithMxFile utility to properly wrap XML for draw.io - Fix 'Not a diagram file' error when model generates raw <root> XML - Add supportsPromptCaching check for conditional caching - Only enable Bedrock prompt caching for Claude models * docs: update model mention to minimax-m2 across About pages and READMEs - Update tooltip in chat-panel.tsx to mention minimax-m2 model change - Update English, Chinese, and Japanese About pages with model change info - Update English, Chinese, and Japanese READMEs with demo site model note --------- Co-authored-by: dayuan.jiang <jiangdy@amazon.co.jp>
This commit is contained in:
@@ -283,3 +283,17 @@ export function getAIModel(): ModelConfig {
|
||||
|
||||
return { model, providerOptions, headers, modelId }
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a model supports prompt caching.
|
||||
* Currently only Claude models on Bedrock support prompt caching.
|
||||
*/
|
||||
export function supportsPromptCaching(modelId: string): boolean {
|
||||
// Bedrock prompt caching is supported for Claude models
|
||||
return (
|
||||
modelId.includes("claude") ||
|
||||
modelId.includes("anthropic") ||
|
||||
modelId.startsWith("us.anthropic") ||
|
||||
modelId.startsWith("eu.anthropic")
|
||||
)
|
||||
}
|
||||
|
||||
26
lib/utils.ts
26
lib/utils.ts
@@ -106,6 +106,32 @@ export function convertToLegalXml(xmlString: string): string {
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap XML content with the full mxfile structure required by draw.io.
|
||||
* Handles cases where XML is just <root>, <mxGraphModel>, or already has <mxfile>.
|
||||
* @param xml - The XML string (may be partial or complete)
|
||||
* @returns Full mxfile-wrapped XML string
|
||||
*/
|
||||
export function wrapWithMxFile(xml: string): string {
|
||||
if (!xml) {
|
||||
return `<mxfile><diagram name="Page-1" id="page-1"><mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel></diagram></mxfile>`
|
||||
}
|
||||
|
||||
// Already has full structure
|
||||
if (xml.includes("<mxfile")) {
|
||||
return xml
|
||||
}
|
||||
|
||||
// Has mxGraphModel but not mxfile
|
||||
if (xml.includes("<mxGraphModel")) {
|
||||
return `<mxfile><diagram name="Page-1" id="page-1">${xml}</diagram></mxfile>`
|
||||
}
|
||||
|
||||
// Just <root> content - extract inner content and wrap fully
|
||||
const rootContent = xml.replace(/<\/?root>/g, "").trim()
|
||||
return `<mxfile><diagram name="Page-1" id="page-1"><mxGraphModel><root>${rootContent}</root></mxGraphModel></diagram></mxfile>`
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace nodes in a Draw.io XML diagram
|
||||
* @param currentXML - The original Draw.io XML string
|
||||
|
||||
Reference in New Issue
Block a user