While measure() tells you the space something takes up, layout() tells you the available space. I think that’s what you need to fire up your TikZ compilation, right?
Once you know the width in Typst, you can use a command line query to get that value out of Typst and use it in a script. And once you have compiled your diagram, you can in turn include it in your document.
In principle, prequery is meant to help automate such workflows. But I haven’t done the larger part of the work yet: provide a tool that can query documents and dispatch to various applications according to some config. Yet, the package’s manual may give you some insight in how you can structure your workflow – even if the package doesn’t solve the bulk of the problem.