{"version":3,"file":"use-frontend-tool.cjs","names":["useCopilotKit"],"sources":["../../src/hooks/use-frontend-tool.tsx"],"sourcesContent":["import { useEffect } from \"react\";\nimport { useCopilotKit } from \"../providers/CopilotKitProvider\";\nimport type { ReactFrontendTool } from \"../types/frontend-tool\";\n\nconst EMPTY_DEPS: ReadonlyArray<unknown> = [];\n\nexport function useFrontendTool<\n  T extends Record<string, unknown> = Record<string, unknown>,\n>(tool: ReactFrontendTool<T>, deps?: ReadonlyArray<unknown>) {\n  const { copilotkit } = useCopilotKit();\n  const extraDeps = deps ?? EMPTY_DEPS;\n\n  useEffect(() => {\n    const name = tool.name;\n\n    // Always register/override the tool for this name on mount\n    if (copilotkit.getTool({ toolName: name, agentId: tool.agentId })) {\n      console.warn(\n        `Tool '${name}' already exists for agent '${tool.agentId || \"global\"}'. Overriding with latest registration.`,\n      );\n      copilotkit.removeTool(name, tool.agentId);\n    }\n    copilotkit.addTool(tool);\n\n    // Register/override renderer by name and agentId through core\n    if (tool.render && tool.parameters) {\n      copilotkit.addHookRenderToolCall({\n        name,\n        args: tool.parameters,\n        agentId: tool.agentId,\n        render: tool.render,\n      });\n    }\n\n    return () => {\n      copilotkit.removeTool(name, tool.agentId);\n      // we are intentionally not removing the render here so that the tools can still render in the chat history\n    };\n    // Depend on stable keys by default and allow callers to opt into\n    // additional dependencies for dynamic tool configuration.\n    // tool.available is included so toggling availability re-registers the tool.\n  }, [tool.name, tool.available, copilotkit, extraDeps.length, ...extraDeps]);\n}\n"],"mappings":";;;;;AAIA,MAAM,aAAqC,EAAE;AAE7C,SAAgB,gBAEd,MAA4B,MAA+B;CAC3D,MAAM,EAAE,eAAeA,0CAAe;CACtC,MAAM,YAAY,QAAQ;AAE1B,4BAAgB;EACd,MAAM,OAAO,KAAK;AAGlB,MAAI,WAAW,QAAQ;GAAE,UAAU;GAAM,SAAS,KAAK;GAAS,CAAC,EAAE;AACjE,WAAQ,KACN,SAAS,KAAK,8BAA8B,KAAK,WAAW,SAAS,yCACtE;AACD,cAAW,WAAW,MAAM,KAAK,QAAQ;;AAE3C,aAAW,QAAQ,KAAK;AAGxB,MAAI,KAAK,UAAU,KAAK,WACtB,YAAW,sBAAsB;GAC/B;GACA,MAAM,KAAK;GACX,SAAS,KAAK;GACd,QAAQ,KAAK;GACd,CAAC;AAGJ,eAAa;AACX,cAAW,WAAW,MAAM,KAAK,QAAQ;;IAM1C;EAAC,KAAK;EAAM,KAAK;EAAW;EAAY,UAAU;EAAQ,GAAG;EAAU,CAAC"}