MCPcopy Create free account
hub / github.com/ResearAI/AutoFigure / onToolCall

Function onToolCall

frontend/components/chat-panel.tsx:210–357  ·  view source on GitHub ↗
({ toolCall })

Source from the content-addressed store, hash-verified

208 api: "/api/chat",
209 }),
210 async onToolCall({ toolCall }) {
211 if (DEBUG) {
212 console.log(
213 `[onToolCall] Tool: ${toolCall.toolName}, CallId: ${toolCall.toolCallId}`,
214 )
215 }
216
217 if (toolCall.toolName === "display_diagram") {
218 const { xml } = toolCall.input as { xml: string }
219 if (DEBUG) {
220 console.log(
221 `[display_diagram] Received XML length: ${xml.length}`,
222 )
223 }
224
225 // Wrap raw XML with full mxfile structure for draw.io
226 const fullXml = wrapWithMxFile(xml)
227
228 // loadDiagram validates and returns error if invalid
229 const validationError = onDisplayChart(fullXml)
230
231 if (validationError) {
232 console.warn(
233 "[display_diagram] Validation error:",
234 validationError,
235 )
236 // Return error to model - sendAutomaticallyWhen will trigger retry
237 if (DEBUG) {
238 console.log(
239 "[display_diagram] Adding tool output with state: output-error",
240 )
241 }
242 addToolOutput({
243 tool: "display_diagram",
244 toolCallId: toolCall.toolCallId,
245 state: "output-error",
246 errorText: `${validationError}
247
248Please fix the XML issues and call display_diagram again with corrected XML.
249
250Your failed XML:
251\`\`\`xml
252${xml}
253\`\`\``,
254 })
255 } else {
256 // Success - diagram will be rendered by chat-message-display
257 if (DEBUG) {
258 console.log(
259 "[display_diagram] Success! Adding tool output with state: output-available",
260 )
261 }
262 addToolOutput({
263 tool: "display_diagram",
264 toolCallId: toolCall.toolCallId,
265 output: "Successfully displayed the diagram.",
266 })
267 if (DEBUG) {

Callers

nothing calls this directly

Calls 3

wrapWithMxFileFunction · 0.90
onFetchChartFunction · 0.85
replaceXMLPartsFunction · 0.85

Tested by

no test coverage detected