CoolFace
Apppublic

LiquidAI/LFM2-MCP

sourceHugging Faceapache-2.0updated 3mo agoView on Hugging Face
39likes
ToolResultRenderer.tsx45 linesDownload Raw Back to components
1import React from "react";2import ResultBlock from "./ResultBlock";3 4interface ToolResultRendererProps {5  result: unknown;6  rendererCode?: string;7  input?: unknown;8}9 10const ToolResultRenderer: React.FC<ToolResultRendererProps> = ({ result, rendererCode, input }) => {11  if (!rendererCode) {12    return <ResultBlock result={result} />;13  }14 15  try {16    const exportMatch = rendererCode.match(/export\s+default\s+(.*)/s);17    if (!exportMatch) {18      throw new Error("Invalid renderer format - no export default found");19    }20 21    const componentCode = exportMatch[1].trim();22    const componentFunction = new Function(23      "React",24      "input",25      "output",26      `27      const { createElement: h, Fragment } = React;28      const JSXComponent = ${componentCode};29      return JSXComponent(input, output);30      `,31    );32 33    const element = componentFunction(React, input || {}, result);34    return element;35  } catch (error) {36    return (37      <ResultBlock38        error={error instanceof Error ? error.message : "Unknown error"}39        result={result}40      />41    );42  }43};44export default ToolResultRenderer;45