Created
December 10, 2024 08:01
-
-
Save knezdusan/32023d93a0007d4b09309afe507336e0 to your computer and use it in GitHub Desktop.
LangGraph.js Workflow Visualization Graph
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Receive the compiled app graph | |
import Image from 'next/image'; | |
export interface GraphApp { | |
getGraphAsync(): Promise<{ | |
drawMermaidPng(): Promise<{ | |
arrayBuffer(): Promise<ArrayBuffer>; | |
}>; | |
}>; | |
} | |
export default async function GraphVisualize({ app }: { app: GraphApp }) { | |
try { | |
const representation = await app.getGraphAsync(); | |
const image = await representation.drawMermaidPng(); | |
const arrayBuffer = await image.arrayBuffer(); | |
const buffer = new Uint8Array(arrayBuffer); | |
// Convert buffer to base64 string | |
const base64String = Buffer.from(buffer).toString('base64'); | |
const imageUrl = `data:image/png;base64,${base64String}`; | |
return ( | |
<div className="graph-container"> | |
<div> | |
<Image | |
src={imageUrl} | |
alt="Workflow Graph" | |
width={500} | |
height={300} | |
className="graph-image" | |
/> | |
</div> | |
</div> | |
); | |
} catch (error) { | |
console.error('Error generating graph:', error); | |
return ( | |
<div className="graph-container"> | |
<pre>{error instanceof Error ? error.message : JSON.stringify(error)}</pre> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment