@copilotkitnext/react 1.54.0-next.3 → 1.54.0-next.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/use-frontend-tool.cjs +6 -14
- package/dist/hooks/use-frontend-tool.cjs.map +1 -1
- package/dist/hooks/use-frontend-tool.d.cts.map +1 -1
- package/dist/hooks/use-frontend-tool.d.mts.map +1 -1
- package/dist/hooks/use-frontend-tool.mjs +6 -14
- package/dist/hooks/use-frontend-tool.mjs.map +1 -1
- package/dist/hooks/use-human-in-the-loop.cjs +1 -6
- package/dist/hooks/use-human-in-the-loop.cjs.map +1 -1
- package/dist/hooks/use-human-in-the-loop.mjs +1 -6
- package/dist/hooks/use-human-in-the-loop.mjs.map +1 -1
- package/dist/hooks/use-render-tool.cjs +1 -6
- package/dist/hooks/use-render-tool.cjs.map +1 -1
- package/dist/hooks/use-render-tool.d.cts.map +1 -1
- package/dist/hooks/use-render-tool.d.mts.map +1 -1
- package/dist/hooks/use-render-tool.mjs +1 -6
- package/dist/hooks/use-render-tool.mjs.map +1 -1
- package/dist/index.umd.js +38 -36
- package/dist/index.umd.js.map +1 -1
- package/dist/lib/react-core.cjs +26 -1
- package/dist/lib/react-core.cjs.map +1 -1
- package/dist/lib/react-core.d.cts +5 -0
- package/dist/lib/react-core.d.cts.map +1 -1
- package/dist/lib/react-core.d.mts +5 -0
- package/dist/lib/react-core.d.mts.map +1 -1
- package/dist/lib/react-core.mjs +26 -1
- package/dist/lib/react-core.mjs.map +1 -1
- package/package.json +7 -7
|
@@ -17,20 +17,12 @@ function useFrontendTool(tool, deps) {
|
|
|
17
17
|
copilotkit.removeTool(name, tool.agentId);
|
|
18
18
|
}
|
|
19
19
|
copilotkit.addTool(tool);
|
|
20
|
-
if (tool.render) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
name,
|
|
27
|
-
args: tool.parameters,
|
|
28
|
-
agentId: tool.agentId,
|
|
29
|
-
render: tool.render
|
|
30
|
-
};
|
|
31
|
-
mergedMap.set(keyOf(newEntry), newEntry);
|
|
32
|
-
copilotkit.setRenderToolCalls(Array.from(mergedMap.values()));
|
|
33
|
-
}
|
|
20
|
+
if (tool.render && tool.parameters) copilotkit.addHookRenderToolCall({
|
|
21
|
+
name,
|
|
22
|
+
args: tool.parameters,
|
|
23
|
+
agentId: tool.agentId,
|
|
24
|
+
render: tool.render
|
|
25
|
+
});
|
|
34
26
|
return () => {
|
|
35
27
|
copilotkit.removeTool(name, tool.agentId);
|
|
36
28
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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\";\
|
|
1
|
+
{"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-frontend-tool.d.cts","names":[],"sources":["../../src/hooks/use-frontend-tool.tsx"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"use-frontend-tool.d.cts","names":[],"sources":["../../src/hooks/use-frontend-tool.tsx"],"mappings":";;;iBAMgB,eAAA,WACJ,MAAA,oBAA0B,MAAA,kBAAA,CACpC,IAAA,EAAM,iBAAA,CAAkB,CAAA,GAAI,IAAA,GAAO,aAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-frontend-tool.d.mts","names":[],"sources":["../../src/hooks/use-frontend-tool.tsx"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"use-frontend-tool.d.mts","names":[],"sources":["../../src/hooks/use-frontend-tool.tsx"],"mappings":";;;iBAMgB,eAAA,WACJ,MAAA,oBAA0B,MAAA,kBAAA,CACpC,IAAA,EAAM,iBAAA,CAAkB,CAAA,GAAI,IAAA,GAAO,aAAA"}
|
|
@@ -16,20 +16,12 @@ function useFrontendTool(tool, deps) {
|
|
|
16
16
|
copilotkit.removeTool(name, tool.agentId);
|
|
17
17
|
}
|
|
18
18
|
copilotkit.addTool(tool);
|
|
19
|
-
if (tool.render) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
name,
|
|
26
|
-
args: tool.parameters,
|
|
27
|
-
agentId: tool.agentId,
|
|
28
|
-
render: tool.render
|
|
29
|
-
};
|
|
30
|
-
mergedMap.set(keyOf(newEntry), newEntry);
|
|
31
|
-
copilotkit.setRenderToolCalls(Array.from(mergedMap.values()));
|
|
32
|
-
}
|
|
19
|
+
if (tool.render && tool.parameters) copilotkit.addHookRenderToolCall({
|
|
20
|
+
name,
|
|
21
|
+
args: tool.parameters,
|
|
22
|
+
agentId: tool.agentId,
|
|
23
|
+
render: tool.render
|
|
24
|
+
});
|
|
33
25
|
return () => {
|
|
34
26
|
copilotkit.removeTool(name, tool.agentId);
|
|
35
27
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-frontend-tool.mjs","names":[],"sources":["../../src/hooks/use-frontend-tool.tsx"],"sourcesContent":["import { useEffect } from \"react\";\nimport { useCopilotKit } from \"../providers/CopilotKitProvider\";\nimport type { ReactFrontendTool } from \"../types/frontend-tool\";\
|
|
1
|
+
{"version":3,"file":"use-frontend-tool.mjs","names":[],"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,eAAe,eAAe;CACtC,MAAM,YAAY,QAAQ;AAE1B,iBAAgB;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"}
|
|
@@ -60,12 +60,7 @@ function useHumanInTheLoop(tool, deps) {
|
|
|
60
60
|
}, deps);
|
|
61
61
|
(0, react.useEffect)(() => {
|
|
62
62
|
return () => {
|
|
63
|
-
|
|
64
|
-
const filtered = copilotkit.renderToolCalls.filter((rc) => keyOf(rc) !== keyOf({
|
|
65
|
-
name: tool.name,
|
|
66
|
-
agentId: tool.agentId
|
|
67
|
-
}));
|
|
68
|
-
copilotkit.setRenderToolCalls(filtered);
|
|
63
|
+
copilotkit.removeHookRenderToolCall(tool.name, tool.agentId);
|
|
69
64
|
};
|
|
70
65
|
}, [
|
|
71
66
|
copilotkit,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-human-in-the-loop.cjs","names":["useCopilotKit","React"],"sources":["../../src/hooks/use-human-in-the-loop.tsx"],"sourcesContent":["import { useCopilotKit } from \"@/providers/CopilotKitProvider\";\nimport type { ReactFrontendTool } from \"@/types/frontend-tool\";\nimport type { ReactHumanInTheLoop } from \"@/types/human-in-the-loop\";\nimport type { ReactToolCallRenderer } from \"@/types/react-tool-call-renderer\";\nimport { useCallback, useEffect, useRef } from \"react\";\nimport React from \"react\";\nimport { useFrontendTool } from \"./use-frontend-tool\";\n\nexport function useHumanInTheLoop<\n T extends Record<string, unknown> = Record<string, unknown>,\n>(tool: ReactHumanInTheLoop<T>, deps?: ReadonlyArray<unknown>) {\n const { copilotkit } = useCopilotKit();\n const resolvePromiseRef = useRef<((result: unknown) => void) | null>(null);\n\n const respond = useCallback(async (result: unknown) => {\n if (resolvePromiseRef.current) {\n resolvePromiseRef.current(result);\n resolvePromiseRef.current = null;\n }\n }, []);\n\n const handler = useCallback(async () => {\n return new Promise((resolve) => {\n resolvePromiseRef.current = resolve;\n });\n }, []);\n\n const RenderComponent: ReactToolCallRenderer<T>[\"render\"] = useCallback(\n (props) => {\n const ToolComponent = tool.render;\n\n // Enhance props based on current status\n if (props.status === \"inProgress\") {\n const enhancedProps = {\n ...props,\n name: tool.name,\n description: tool.description || \"\",\n respond: undefined,\n };\n return React.createElement(ToolComponent, enhancedProps);\n } else if (props.status === \"executing\") {\n const enhancedProps = {\n ...props,\n name: tool.name,\n description: tool.description || \"\",\n respond,\n };\n return React.createElement(ToolComponent, enhancedProps);\n } else if (props.status === \"complete\") {\n const enhancedProps = {\n ...props,\n name: tool.name,\n description: tool.description || \"\",\n respond: undefined,\n };\n return React.createElement(ToolComponent, enhancedProps);\n }\n\n // Fallback - just render with original props\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return React.createElement(ToolComponent, props as any);\n },\n [tool.render, tool.name, tool.description, respond],\n );\n\n const frontendTool: ReactFrontendTool<T> = {\n ...tool,\n handler,\n render: RenderComponent,\n };\n\n useFrontendTool(frontendTool, deps);\n\n // Human-in-the-loop tools should remove their renderer on unmount\n // since they can't respond to user interactions anymore\n useEffect(() => {\n return () => {\n
|
|
1
|
+
{"version":3,"file":"use-human-in-the-loop.cjs","names":["useCopilotKit","React"],"sources":["../../src/hooks/use-human-in-the-loop.tsx"],"sourcesContent":["import { useCopilotKit } from \"@/providers/CopilotKitProvider\";\nimport type { ReactFrontendTool } from \"@/types/frontend-tool\";\nimport type { ReactHumanInTheLoop } from \"@/types/human-in-the-loop\";\nimport type { ReactToolCallRenderer } from \"@/types/react-tool-call-renderer\";\nimport { useCallback, useEffect, useRef } from \"react\";\nimport React from \"react\";\nimport { useFrontendTool } from \"./use-frontend-tool\";\n\nexport function useHumanInTheLoop<\n T extends Record<string, unknown> = Record<string, unknown>,\n>(tool: ReactHumanInTheLoop<T>, deps?: ReadonlyArray<unknown>) {\n const { copilotkit } = useCopilotKit();\n const resolvePromiseRef = useRef<((result: unknown) => void) | null>(null);\n\n const respond = useCallback(async (result: unknown) => {\n if (resolvePromiseRef.current) {\n resolvePromiseRef.current(result);\n resolvePromiseRef.current = null;\n }\n }, []);\n\n const handler = useCallback(async () => {\n return new Promise((resolve) => {\n resolvePromiseRef.current = resolve;\n });\n }, []);\n\n const RenderComponent: ReactToolCallRenderer<T>[\"render\"] = useCallback(\n (props) => {\n const ToolComponent = tool.render;\n\n // Enhance props based on current status\n if (props.status === \"inProgress\") {\n const enhancedProps = {\n ...props,\n name: tool.name,\n description: tool.description || \"\",\n respond: undefined,\n };\n return React.createElement(ToolComponent, enhancedProps);\n } else if (props.status === \"executing\") {\n const enhancedProps = {\n ...props,\n name: tool.name,\n description: tool.description || \"\",\n respond,\n };\n return React.createElement(ToolComponent, enhancedProps);\n } else if (props.status === \"complete\") {\n const enhancedProps = {\n ...props,\n name: tool.name,\n description: tool.description || \"\",\n respond: undefined,\n };\n return React.createElement(ToolComponent, enhancedProps);\n }\n\n // Fallback - just render with original props\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return React.createElement(ToolComponent, props as any);\n },\n [tool.render, tool.name, tool.description, respond],\n );\n\n const frontendTool: ReactFrontendTool<T> = {\n ...tool,\n handler,\n render: RenderComponent,\n };\n\n useFrontendTool(frontendTool, deps);\n\n // Human-in-the-loop tools should remove their renderer on unmount\n // since they can't respond to user interactions anymore\n useEffect(() => {\n return () => {\n copilotkit.removeHookRenderToolCall(tool.name, tool.agentId);\n };\n }, [copilotkit, tool.name, tool.agentId]);\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,kBAEd,MAA8B,MAA+B;CAC7D,MAAM,EAAE,eAAeA,0CAAe;CACtC,MAAM,sCAA+D,KAAK;CAE1E,MAAM,iCAAsB,OAAO,WAAoB;AACrD,MAAI,kBAAkB,SAAS;AAC7B,qBAAkB,QAAQ,OAAO;AACjC,qBAAkB,UAAU;;IAE7B,EAAE,CAAC;CAEN,MAAM,iCAAsB,YAAY;AACtC,SAAO,IAAI,SAAS,YAAY;AAC9B,qBAAkB,UAAU;IAC5B;IACD,EAAE,CAAC;CAEN,MAAM,0CACH,UAAU;EACT,MAAM,gBAAgB,KAAK;AAG3B,MAAI,MAAM,WAAW,cAAc;GACjC,MAAM,gBAAgB;IACpB,GAAG;IACH,MAAM,KAAK;IACX,aAAa,KAAK,eAAe;IACjC,SAAS;IACV;AACD,UAAOC,cAAM,cAAc,eAAe,cAAc;aAC/C,MAAM,WAAW,aAAa;GACvC,MAAM,gBAAgB;IACpB,GAAG;IACH,MAAM,KAAK;IACX,aAAa,KAAK,eAAe;IACjC;IACD;AACD,UAAOA,cAAM,cAAc,eAAe,cAAc;aAC/C,MAAM,WAAW,YAAY;GACtC,MAAM,gBAAgB;IACpB,GAAG;IACH,MAAM,KAAK;IACX,aAAa,KAAK,eAAe;IACjC,SAAS;IACV;AACD,UAAOA,cAAM,cAAc,eAAe,cAAc;;AAK1D,SAAOA,cAAM,cAAc,eAAe,MAAa;IAEzD;EAAC,KAAK;EAAQ,KAAK;EAAM,KAAK;EAAa;EAAQ,CACpD;AAQD,2CAN2C;EACzC,GAAG;EACH;EACA,QAAQ;EACT,EAE6B,KAAK;AAInC,4BAAgB;AACd,eAAa;AACX,cAAW,yBAAyB,KAAK,MAAM,KAAK,QAAQ;;IAE7D;EAAC;EAAY,KAAK;EAAM,KAAK;EAAQ,CAAC"}
|
|
@@ -58,12 +58,7 @@ function useHumanInTheLoop(tool, deps) {
|
|
|
58
58
|
}, deps);
|
|
59
59
|
useEffect(() => {
|
|
60
60
|
return () => {
|
|
61
|
-
|
|
62
|
-
const filtered = copilotkit.renderToolCalls.filter((rc) => keyOf(rc) !== keyOf({
|
|
63
|
-
name: tool.name,
|
|
64
|
-
agentId: tool.agentId
|
|
65
|
-
}));
|
|
66
|
-
copilotkit.setRenderToolCalls(filtered);
|
|
61
|
+
copilotkit.removeHookRenderToolCall(tool.name, tool.agentId);
|
|
67
62
|
};
|
|
68
63
|
}, [
|
|
69
64
|
copilotkit,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-human-in-the-loop.mjs","names":[],"sources":["../../src/hooks/use-human-in-the-loop.tsx"],"sourcesContent":["import { useCopilotKit } from \"@/providers/CopilotKitProvider\";\nimport type { ReactFrontendTool } from \"@/types/frontend-tool\";\nimport type { ReactHumanInTheLoop } from \"@/types/human-in-the-loop\";\nimport type { ReactToolCallRenderer } from \"@/types/react-tool-call-renderer\";\nimport { useCallback, useEffect, useRef } from \"react\";\nimport React from \"react\";\nimport { useFrontendTool } from \"./use-frontend-tool\";\n\nexport function useHumanInTheLoop<\n T extends Record<string, unknown> = Record<string, unknown>,\n>(tool: ReactHumanInTheLoop<T>, deps?: ReadonlyArray<unknown>) {\n const { copilotkit } = useCopilotKit();\n const resolvePromiseRef = useRef<((result: unknown) => void) | null>(null);\n\n const respond = useCallback(async (result: unknown) => {\n if (resolvePromiseRef.current) {\n resolvePromiseRef.current(result);\n resolvePromiseRef.current = null;\n }\n }, []);\n\n const handler = useCallback(async () => {\n return new Promise((resolve) => {\n resolvePromiseRef.current = resolve;\n });\n }, []);\n\n const RenderComponent: ReactToolCallRenderer<T>[\"render\"] = useCallback(\n (props) => {\n const ToolComponent = tool.render;\n\n // Enhance props based on current status\n if (props.status === \"inProgress\") {\n const enhancedProps = {\n ...props,\n name: tool.name,\n description: tool.description || \"\",\n respond: undefined,\n };\n return React.createElement(ToolComponent, enhancedProps);\n } else if (props.status === \"executing\") {\n const enhancedProps = {\n ...props,\n name: tool.name,\n description: tool.description || \"\",\n respond,\n };\n return React.createElement(ToolComponent, enhancedProps);\n } else if (props.status === \"complete\") {\n const enhancedProps = {\n ...props,\n name: tool.name,\n description: tool.description || \"\",\n respond: undefined,\n };\n return React.createElement(ToolComponent, enhancedProps);\n }\n\n // Fallback - just render with original props\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return React.createElement(ToolComponent, props as any);\n },\n [tool.render, tool.name, tool.description, respond],\n );\n\n const frontendTool: ReactFrontendTool<T> = {\n ...tool,\n handler,\n render: RenderComponent,\n };\n\n useFrontendTool(frontendTool, deps);\n\n // Human-in-the-loop tools should remove their renderer on unmount\n // since they can't respond to user interactions anymore\n useEffect(() => {\n return () => {\n
|
|
1
|
+
{"version":3,"file":"use-human-in-the-loop.mjs","names":[],"sources":["../../src/hooks/use-human-in-the-loop.tsx"],"sourcesContent":["import { useCopilotKit } from \"@/providers/CopilotKitProvider\";\nimport type { ReactFrontendTool } from \"@/types/frontend-tool\";\nimport type { ReactHumanInTheLoop } from \"@/types/human-in-the-loop\";\nimport type { ReactToolCallRenderer } from \"@/types/react-tool-call-renderer\";\nimport { useCallback, useEffect, useRef } from \"react\";\nimport React from \"react\";\nimport { useFrontendTool } from \"./use-frontend-tool\";\n\nexport function useHumanInTheLoop<\n T extends Record<string, unknown> = Record<string, unknown>,\n>(tool: ReactHumanInTheLoop<T>, deps?: ReadonlyArray<unknown>) {\n const { copilotkit } = useCopilotKit();\n const resolvePromiseRef = useRef<((result: unknown) => void) | null>(null);\n\n const respond = useCallback(async (result: unknown) => {\n if (resolvePromiseRef.current) {\n resolvePromiseRef.current(result);\n resolvePromiseRef.current = null;\n }\n }, []);\n\n const handler = useCallback(async () => {\n return new Promise((resolve) => {\n resolvePromiseRef.current = resolve;\n });\n }, []);\n\n const RenderComponent: ReactToolCallRenderer<T>[\"render\"] = useCallback(\n (props) => {\n const ToolComponent = tool.render;\n\n // Enhance props based on current status\n if (props.status === \"inProgress\") {\n const enhancedProps = {\n ...props,\n name: tool.name,\n description: tool.description || \"\",\n respond: undefined,\n };\n return React.createElement(ToolComponent, enhancedProps);\n } else if (props.status === \"executing\") {\n const enhancedProps = {\n ...props,\n name: tool.name,\n description: tool.description || \"\",\n respond,\n };\n return React.createElement(ToolComponent, enhancedProps);\n } else if (props.status === \"complete\") {\n const enhancedProps = {\n ...props,\n name: tool.name,\n description: tool.description || \"\",\n respond: undefined,\n };\n return React.createElement(ToolComponent, enhancedProps);\n }\n\n // Fallback - just render with original props\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return React.createElement(ToolComponent, props as any);\n },\n [tool.render, tool.name, tool.description, respond],\n );\n\n const frontendTool: ReactFrontendTool<T> = {\n ...tool,\n handler,\n render: RenderComponent,\n };\n\n useFrontendTool(frontendTool, deps);\n\n // Human-in-the-loop tools should remove their renderer on unmount\n // since they can't respond to user interactions anymore\n useEffect(() => {\n return () => {\n copilotkit.removeHookRenderToolCall(tool.name, tool.agentId);\n };\n }, [copilotkit, tool.name, tool.agentId]);\n}\n"],"mappings":";;;;;AAQA,SAAgB,kBAEd,MAA8B,MAA+B;CAC7D,MAAM,EAAE,eAAe,eAAe;CACtC,MAAM,oBAAoB,OAA2C,KAAK;CAE1E,MAAM,UAAU,YAAY,OAAO,WAAoB;AACrD,MAAI,kBAAkB,SAAS;AAC7B,qBAAkB,QAAQ,OAAO;AACjC,qBAAkB,UAAU;;IAE7B,EAAE,CAAC;CAEN,MAAM,UAAU,YAAY,YAAY;AACtC,SAAO,IAAI,SAAS,YAAY;AAC9B,qBAAkB,UAAU;IAC5B;IACD,EAAE,CAAC;CAEN,MAAM,kBAAsD,aACzD,UAAU;EACT,MAAM,gBAAgB,KAAK;AAG3B,MAAI,MAAM,WAAW,cAAc;GACjC,MAAM,gBAAgB;IACpB,GAAG;IACH,MAAM,KAAK;IACX,aAAa,KAAK,eAAe;IACjC,SAAS;IACV;AACD,UAAO,MAAM,cAAc,eAAe,cAAc;aAC/C,MAAM,WAAW,aAAa;GACvC,MAAM,gBAAgB;IACpB,GAAG;IACH,MAAM,KAAK;IACX,aAAa,KAAK,eAAe;IACjC;IACD;AACD,UAAO,MAAM,cAAc,eAAe,cAAc;aAC/C,MAAM,WAAW,YAAY;GACtC,MAAM,gBAAgB;IACpB,GAAG;IACH,MAAM,KAAK;IACX,aAAa,KAAK,eAAe;IACjC,SAAS;IACV;AACD,UAAO,MAAM,cAAc,eAAe,cAAc;;AAK1D,SAAO,MAAM,cAAc,eAAe,MAAa;IAEzD;EAAC,KAAK;EAAQ,KAAK;EAAM,KAAK;EAAa;EAAQ,CACpD;AAQD,iBAN2C;EACzC,GAAG;EACH;EACA,QAAQ;EACT,EAE6B,KAAK;AAInC,iBAAgB;AACd,eAAa;AACX,cAAW,yBAAyB,KAAK,MAAM,KAAK,QAAQ;;IAE7D;EAAC;EAAY,KAAK;EAAM,KAAK;EAAQ,CAAC"}
|
|
@@ -66,12 +66,7 @@ function useRenderTool(config, deps) {
|
|
|
66
66
|
}),
|
|
67
67
|
...config.agentId ? { agentId: config.agentId } : {}
|
|
68
68
|
});
|
|
69
|
-
|
|
70
|
-
const currentRenderToolCalls = copilotkit.renderToolCalls;
|
|
71
|
-
const mergedMap = /* @__PURE__ */ new Map();
|
|
72
|
-
for (const rc of currentRenderToolCalls) mergedMap.set(keyOf(rc), rc);
|
|
73
|
-
mergedMap.set(keyOf(renderer), renderer);
|
|
74
|
-
copilotkit.setRenderToolCalls(Array.from(mergedMap.values()));
|
|
69
|
+
copilotkit.addHookRenderToolCall(renderer);
|
|
75
70
|
}, [
|
|
76
71
|
config.name,
|
|
77
72
|
copilotkit,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-render-tool.cjs","names":["useCopilotKit","defineToolCallRenderer"],"sources":["../../src/hooks/use-render-tool.tsx"],"sourcesContent":["import { useEffect } from \"react\";\nimport type {\n StandardSchemaV1,\n InferSchemaOutput,\n} from \"@copilotkitnext/shared\";\nimport { useCopilotKit } from \"../providers/CopilotKitProvider\";\nimport { defineToolCallRenderer } from \"../types/defineToolCallRenderer\";\
|
|
1
|
+
{"version":3,"file":"use-render-tool.cjs","names":["useCopilotKit","defineToolCallRenderer"],"sources":["../../src/hooks/use-render-tool.tsx"],"sourcesContent":["import { useEffect } from \"react\";\nimport type {\n StandardSchemaV1,\n InferSchemaOutput,\n} from \"@copilotkitnext/shared\";\nimport { useCopilotKit } from \"../providers/CopilotKitProvider\";\nimport { defineToolCallRenderer } from \"../types/defineToolCallRenderer\";\n\nconst EMPTY_DEPS: ReadonlyArray<unknown> = [];\n\nexport interface RenderToolInProgressProps<S extends StandardSchemaV1> {\n name: string;\n parameters: Partial<InferSchemaOutput<S>>;\n status: \"inProgress\";\n result: undefined;\n}\n\nexport interface RenderToolExecutingProps<S extends StandardSchemaV1> {\n name: string;\n parameters: InferSchemaOutput<S>;\n status: \"executing\";\n result: undefined;\n}\n\nexport interface RenderToolCompleteProps<S extends StandardSchemaV1> {\n name: string;\n parameters: InferSchemaOutput<S>;\n status: \"complete\";\n result: string;\n}\n\nexport type RenderToolProps<S extends StandardSchemaV1> =\n | RenderToolInProgressProps<S>\n | RenderToolExecutingProps<S>\n | RenderToolCompleteProps<S>;\n\ntype RenderToolConfig<S extends StandardSchemaV1> = {\n name: string;\n parameters?: S;\n render: (props: RenderToolProps<S>) => React.ReactElement;\n agentId?: string;\n};\n\n/**\n * Registers a wildcard (`\"*\"`) renderer for tool calls.\n *\n * The wildcard renderer is used as a fallback when no exact name-matched\n * renderer is registered for a tool call.\n *\n * @param config - Wildcard renderer configuration.\n * @param deps - Optional dependencies to refresh registration.\n *\n * @example\n * ```tsx\n * useRenderTool(\n * {\n * name: \"*\",\n * render: ({ name, status }) => (\n * <div>\n * {status === \"complete\" ? \"✓\" : \"⏳\"} {name}\n * </div>\n * ),\n * },\n * [],\n * );\n * ```\n */\nexport function useRenderTool(\n config: {\n name: \"*\";\n render: (props: any) => React.ReactElement;\n agentId?: string;\n },\n deps?: ReadonlyArray<unknown>,\n): void;\n\n/**\n * Registers a name-scoped renderer for tool calls.\n *\n * The provided `parameters` schema defines the typed shape of `props.parameters`\n * in `render` for `executing` and `complete` states. Accepts any Standard Schema V1\n * compatible library (Zod, Valibot, ArkType, etc.).\n *\n * @typeParam S - Schema type describing tool call parameters.\n * @param config - Named renderer configuration.\n * @param deps - Optional dependencies to refresh registration.\n *\n * @example\n * ```tsx\n * useRenderTool(\n * {\n * name: \"searchDocs\",\n * parameters: z.object({ query: z.string() }),\n * render: ({ status, parameters, result }) => {\n * if (status === \"inProgress\") return <div>Preparing...</div>;\n * if (status === \"executing\") return <div>Searching {parameters.query}</div>;\n * return <div>{result}</div>;\n * },\n * },\n * [],\n * );\n * ```\n */\nexport function useRenderTool<S extends StandardSchemaV1>(\n config: {\n name: string;\n parameters: S;\n render: (props: RenderToolProps<S>) => React.ReactElement;\n agentId?: string;\n },\n deps?: ReadonlyArray<unknown>,\n): void;\n\n/**\n * Registers a renderer entry in CopilotKit's `renderToolCalls` registry.\n *\n * Key behavior:\n * - deduplicates by `agentId:name` (latest registration wins),\n * - keeps renderer entries on cleanup so historical chat tool calls can still render,\n * - refreshes registration when `deps` change.\n *\n * @typeParam S - Schema type describing tool call parameters.\n * @param config - Renderer config for wildcard or named tools.\n * @param deps - Optional dependencies to refresh registration.\n *\n * @example\n * ```tsx\n * useRenderTool(\n * {\n * name: \"searchDocs\",\n * parameters: z.object({ query: z.string() }),\n * render: ({ status, parameters, result }) => {\n * if (status === \"executing\") return <div>Searching {parameters.query}</div>;\n * if (status === \"complete\") return <div>{result}</div>;\n * return <div>Preparing...</div>;\n * },\n * },\n * [],\n * );\n * ```\n *\n * @example\n * ```tsx\n * useRenderTool(\n * {\n * name: \"summarize\",\n * parameters: z.object({ text: z.string() }),\n * agentId: \"research-agent\",\n * render: ({ name, status }) => <div>{name}: {status}</div>,\n * },\n * [selectedAgentId],\n * );\n * ```\n */\nexport function useRenderTool<S extends StandardSchemaV1>(\n config: RenderToolConfig<S>,\n deps?: ReadonlyArray<unknown>,\n): void {\n const { copilotkit } = useCopilotKit();\n const extraDeps = deps ?? EMPTY_DEPS;\n\n useEffect(() => {\n // Build the ReactToolCallRenderer via defineToolCallRenderer\n const renderer =\n config.name === \"*\" && !config.parameters\n ? defineToolCallRenderer({\n name: \"*\",\n render: (props) =>\n config.render({ ...props, parameters: props.args }),\n ...(config.agentId ? { agentId: config.agentId } : {}),\n })\n : defineToolCallRenderer({\n name: config.name,\n args: config.parameters!,\n render: (props) =>\n config.render({ ...props, parameters: props.args }),\n ...(config.agentId ? { agentId: config.agentId } : {}),\n });\n\n copilotkit.addHookRenderToolCall(renderer);\n\n // No cleanup removal — keeps renderer for chat history, same as useFrontendTool\n }, [config.name, copilotkit, extraDeps.length, ...extraDeps]);\n}\n"],"mappings":";;;;;;AAQA,MAAM,aAAqC,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkJ7C,SAAgB,cACd,QACA,MACM;CACN,MAAM,EAAE,eAAeA,0CAAe;CACtC,MAAM,YAAY,QAAQ;AAE1B,4BAAgB;EAEd,MAAM,WACJ,OAAO,SAAS,OAAO,CAAC,OAAO,aAC3BC,sDAAuB;GACrB,MAAM;GACN,SAAS,UACP,OAAO,OAAO;IAAE,GAAG;IAAO,YAAY,MAAM;IAAM,CAAC;GACrD,GAAI,OAAO,UAAU,EAAE,SAAS,OAAO,SAAS,GAAG,EAAE;GACtD,CAAC,GACFA,sDAAuB;GACrB,MAAM,OAAO;GACb,MAAM,OAAO;GACb,SAAS,UACP,OAAO,OAAO;IAAE,GAAG;IAAO,YAAY,MAAM;IAAM,CAAC;GACrD,GAAI,OAAO,UAAU,EAAE,SAAS,OAAO,SAAS,GAAG,EAAE;GACtD,CAAC;AAER,aAAW,sBAAsB,SAAS;IAGzC;EAAC,OAAO;EAAM;EAAY,UAAU;EAAQ,GAAG;EAAU,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-render-tool.d.cts","names":[],"sources":["../../src/hooks/use-render-tool.tsx"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"use-render-tool.d.cts","names":[],"sources":["../../src/hooks/use-render-tool.tsx"],"mappings":";;;UAUiB,yBAAA,WAAoC,gBAAA;EACnD,IAAA;EACA,UAAA,EAAY,OAAA,CAAQ,iBAAA,CAAkB,CAAA;EACtC,MAAA;EACA,MAAA;AAAA;AAAA,UAGe,wBAAA,WAAmC,gBAAA;EAClD,IAAA;EACA,UAAA,EAAY,iBAAA,CAAkB,CAAA;EAC9B,MAAA;EACA,MAAA;AAAA;AAAA,UAGe,uBAAA,WAAkC,gBAAA;EACjD,IAAA;EACA,UAAA,EAAY,iBAAA,CAAkB,CAAA;EAC9B,MAAA;EACA,MAAA;AAAA;AAAA,KAGU,eAAA,WAA0B,gBAAA,IAClC,yBAAA,CAA0B,CAAA,IAC1B,wBAAA,CAAyB,CAAA,IACzB,uBAAA,CAAwB,CAAA;;;;AAjB5B;;;;;;;;;;;;;;;;;;AAOA;;;iBA2CgB,aAAA,CACd,MAAA;EACE,IAAA;EACA,MAAA,GAAS,KAAA,UAAe,KAAA,CAAM,YAAA;EAC9B,OAAA;AAAA,GAEF,IAAA,GAAO,aAAA;;;;;;;;;;;AA1CT;;;;;;;;;;;;;;;;;iBAwEgB,aAAA,WAAwB,gBAAA,CAAA,CACtC,MAAA;EACE,IAAA;EACA,UAAA,EAAY,CAAA;EACZ,MAAA,GAAS,KAAA,EAAO,eAAA,CAAgB,CAAA,MAAO,KAAA,CAAM,YAAA;EAC7C,OAAA;AAAA,GAEF,IAAA,GAAO,aAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-render-tool.d.mts","names":[],"sources":["../../src/hooks/use-render-tool.tsx"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"use-render-tool.d.mts","names":[],"sources":["../../src/hooks/use-render-tool.tsx"],"mappings":";;;UAUiB,yBAAA,WAAoC,gBAAA;EACnD,IAAA;EACA,UAAA,EAAY,OAAA,CAAQ,iBAAA,CAAkB,CAAA;EACtC,MAAA;EACA,MAAA;AAAA;AAAA,UAGe,wBAAA,WAAmC,gBAAA;EAClD,IAAA;EACA,UAAA,EAAY,iBAAA,CAAkB,CAAA;EAC9B,MAAA;EACA,MAAA;AAAA;AAAA,UAGe,uBAAA,WAAkC,gBAAA;EACjD,IAAA;EACA,UAAA,EAAY,iBAAA,CAAkB,CAAA;EAC9B,MAAA;EACA,MAAA;AAAA;AAAA,KAGU,eAAA,WAA0B,gBAAA,IAClC,yBAAA,CAA0B,CAAA,IAC1B,wBAAA,CAAyB,CAAA,IACzB,uBAAA,CAAwB,CAAA;;;;AAjB5B;;;;;;;;;;;;;;;;;;AAOA;;;iBA2CgB,aAAA,CACd,MAAA;EACE,IAAA;EACA,MAAA,GAAS,KAAA,UAAe,KAAA,CAAM,YAAA;EAC9B,OAAA;AAAA,GAEF,IAAA,GAAO,aAAA;;;;;;;;;;;AA1CT;;;;;;;;;;;;;;;;;iBAwEgB,aAAA,WAAwB,gBAAA,CAAA,CACtC,MAAA;EACE,IAAA;EACA,UAAA,EAAY,CAAA;EACZ,MAAA,GAAS,KAAA,EAAO,eAAA,CAAgB,CAAA,MAAO,KAAA,CAAM,YAAA;EAC7C,OAAA;AAAA,GAEF,IAAA,GAAO,aAAA"}
|
|
@@ -65,12 +65,7 @@ function useRenderTool(config, deps) {
|
|
|
65
65
|
}),
|
|
66
66
|
...config.agentId ? { agentId: config.agentId } : {}
|
|
67
67
|
});
|
|
68
|
-
|
|
69
|
-
const currentRenderToolCalls = copilotkit.renderToolCalls;
|
|
70
|
-
const mergedMap = /* @__PURE__ */ new Map();
|
|
71
|
-
for (const rc of currentRenderToolCalls) mergedMap.set(keyOf(rc), rc);
|
|
72
|
-
mergedMap.set(keyOf(renderer), renderer);
|
|
73
|
-
copilotkit.setRenderToolCalls(Array.from(mergedMap.values()));
|
|
68
|
+
copilotkit.addHookRenderToolCall(renderer);
|
|
74
69
|
}, [
|
|
75
70
|
config.name,
|
|
76
71
|
copilotkit,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-render-tool.mjs","names":[],"sources":["../../src/hooks/use-render-tool.tsx"],"sourcesContent":["import { useEffect } from \"react\";\nimport type {\n StandardSchemaV1,\n InferSchemaOutput,\n} from \"@copilotkitnext/shared\";\nimport { useCopilotKit } from \"../providers/CopilotKitProvider\";\nimport { defineToolCallRenderer } from \"../types/defineToolCallRenderer\";\
|
|
1
|
+
{"version":3,"file":"use-render-tool.mjs","names":[],"sources":["../../src/hooks/use-render-tool.tsx"],"sourcesContent":["import { useEffect } from \"react\";\nimport type {\n StandardSchemaV1,\n InferSchemaOutput,\n} from \"@copilotkitnext/shared\";\nimport { useCopilotKit } from \"../providers/CopilotKitProvider\";\nimport { defineToolCallRenderer } from \"../types/defineToolCallRenderer\";\n\nconst EMPTY_DEPS: ReadonlyArray<unknown> = [];\n\nexport interface RenderToolInProgressProps<S extends StandardSchemaV1> {\n name: string;\n parameters: Partial<InferSchemaOutput<S>>;\n status: \"inProgress\";\n result: undefined;\n}\n\nexport interface RenderToolExecutingProps<S extends StandardSchemaV1> {\n name: string;\n parameters: InferSchemaOutput<S>;\n status: \"executing\";\n result: undefined;\n}\n\nexport interface RenderToolCompleteProps<S extends StandardSchemaV1> {\n name: string;\n parameters: InferSchemaOutput<S>;\n status: \"complete\";\n result: string;\n}\n\nexport type RenderToolProps<S extends StandardSchemaV1> =\n | RenderToolInProgressProps<S>\n | RenderToolExecutingProps<S>\n | RenderToolCompleteProps<S>;\n\ntype RenderToolConfig<S extends StandardSchemaV1> = {\n name: string;\n parameters?: S;\n render: (props: RenderToolProps<S>) => React.ReactElement;\n agentId?: string;\n};\n\n/**\n * Registers a wildcard (`\"*\"`) renderer for tool calls.\n *\n * The wildcard renderer is used as a fallback when no exact name-matched\n * renderer is registered for a tool call.\n *\n * @param config - Wildcard renderer configuration.\n * @param deps - Optional dependencies to refresh registration.\n *\n * @example\n * ```tsx\n * useRenderTool(\n * {\n * name: \"*\",\n * render: ({ name, status }) => (\n * <div>\n * {status === \"complete\" ? \"✓\" : \"⏳\"} {name}\n * </div>\n * ),\n * },\n * [],\n * );\n * ```\n */\nexport function useRenderTool(\n config: {\n name: \"*\";\n render: (props: any) => React.ReactElement;\n agentId?: string;\n },\n deps?: ReadonlyArray<unknown>,\n): void;\n\n/**\n * Registers a name-scoped renderer for tool calls.\n *\n * The provided `parameters` schema defines the typed shape of `props.parameters`\n * in `render` for `executing` and `complete` states. Accepts any Standard Schema V1\n * compatible library (Zod, Valibot, ArkType, etc.).\n *\n * @typeParam S - Schema type describing tool call parameters.\n * @param config - Named renderer configuration.\n * @param deps - Optional dependencies to refresh registration.\n *\n * @example\n * ```tsx\n * useRenderTool(\n * {\n * name: \"searchDocs\",\n * parameters: z.object({ query: z.string() }),\n * render: ({ status, parameters, result }) => {\n * if (status === \"inProgress\") return <div>Preparing...</div>;\n * if (status === \"executing\") return <div>Searching {parameters.query}</div>;\n * return <div>{result}</div>;\n * },\n * },\n * [],\n * );\n * ```\n */\nexport function useRenderTool<S extends StandardSchemaV1>(\n config: {\n name: string;\n parameters: S;\n render: (props: RenderToolProps<S>) => React.ReactElement;\n agentId?: string;\n },\n deps?: ReadonlyArray<unknown>,\n): void;\n\n/**\n * Registers a renderer entry in CopilotKit's `renderToolCalls` registry.\n *\n * Key behavior:\n * - deduplicates by `agentId:name` (latest registration wins),\n * - keeps renderer entries on cleanup so historical chat tool calls can still render,\n * - refreshes registration when `deps` change.\n *\n * @typeParam S - Schema type describing tool call parameters.\n * @param config - Renderer config for wildcard or named tools.\n * @param deps - Optional dependencies to refresh registration.\n *\n * @example\n * ```tsx\n * useRenderTool(\n * {\n * name: \"searchDocs\",\n * parameters: z.object({ query: z.string() }),\n * render: ({ status, parameters, result }) => {\n * if (status === \"executing\") return <div>Searching {parameters.query}</div>;\n * if (status === \"complete\") return <div>{result}</div>;\n * return <div>Preparing...</div>;\n * },\n * },\n * [],\n * );\n * ```\n *\n * @example\n * ```tsx\n * useRenderTool(\n * {\n * name: \"summarize\",\n * parameters: z.object({ text: z.string() }),\n * agentId: \"research-agent\",\n * render: ({ name, status }) => <div>{name}: {status}</div>,\n * },\n * [selectedAgentId],\n * );\n * ```\n */\nexport function useRenderTool<S extends StandardSchemaV1>(\n config: RenderToolConfig<S>,\n deps?: ReadonlyArray<unknown>,\n): void {\n const { copilotkit } = useCopilotKit();\n const extraDeps = deps ?? EMPTY_DEPS;\n\n useEffect(() => {\n // Build the ReactToolCallRenderer via defineToolCallRenderer\n const renderer =\n config.name === \"*\" && !config.parameters\n ? defineToolCallRenderer({\n name: \"*\",\n render: (props) =>\n config.render({ ...props, parameters: props.args }),\n ...(config.agentId ? { agentId: config.agentId } : {}),\n })\n : defineToolCallRenderer({\n name: config.name,\n args: config.parameters!,\n render: (props) =>\n config.render({ ...props, parameters: props.args }),\n ...(config.agentId ? { agentId: config.agentId } : {}),\n });\n\n copilotkit.addHookRenderToolCall(renderer);\n\n // No cleanup removal — keeps renderer for chat history, same as useFrontendTool\n }, [config.name, copilotkit, extraDeps.length, ...extraDeps]);\n}\n"],"mappings":";;;;;AAQA,MAAM,aAAqC,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkJ7C,SAAgB,cACd,QACA,MACM;CACN,MAAM,EAAE,eAAe,eAAe;CACtC,MAAM,YAAY,QAAQ;AAE1B,iBAAgB;EAEd,MAAM,WACJ,OAAO,SAAS,OAAO,CAAC,OAAO,aAC3B,uBAAuB;GACrB,MAAM;GACN,SAAS,UACP,OAAO,OAAO;IAAE,GAAG;IAAO,YAAY,MAAM;IAAM,CAAC;GACrD,GAAI,OAAO,UAAU,EAAE,SAAS,OAAO,SAAS,GAAG,EAAE;GACtD,CAAC,GACF,uBAAuB;GACrB,MAAM,OAAO;GACb,MAAM,OAAO;GACb,SAAS,UACP,OAAO,OAAO;IAAE,GAAG;IAAO,YAAY,MAAM;IAAM,CAAC;GACrD,GAAI,OAAO,UAAU,EAAE,SAAS,OAAO,SAAS,GAAG,EAAE;GACtD,CAAC;AAER,aAAW,sBAAsB,SAAS;IAGzC;EAAC,OAAO;EAAM;EAAY,UAAU;EAAQ,GAAG;EAAU,CAAC"}
|
package/dist/index.umd.js
CHANGED
|
@@ -1943,6 +1943,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1943
1943
|
var _config$renderToolCal, _config$renderCustomM, _config$renderActivit;
|
|
1944
1944
|
super(config);
|
|
1945
1945
|
_defineProperty(this, "_renderToolCalls", []);
|
|
1946
|
+
_defineProperty(this, "_hookRenderToolCalls", /* @__PURE__ */ new Map());
|
|
1947
|
+
_defineProperty(this, "_cachedMergedRenderToolCalls", null);
|
|
1946
1948
|
_defineProperty(this, "_renderCustomMessages", []);
|
|
1947
1949
|
_defineProperty(this, "_renderActivityMessages", []);
|
|
1948
1950
|
_defineProperty(this, "_interruptElement", null);
|
|
@@ -1957,7 +1959,16 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1957
1959
|
return this._renderActivityMessages;
|
|
1958
1960
|
}
|
|
1959
1961
|
get renderToolCalls() {
|
|
1960
|
-
return this._renderToolCalls;
|
|
1962
|
+
if (this._hookRenderToolCalls.size === 0) return this._renderToolCalls;
|
|
1963
|
+
if (this._cachedMergedRenderToolCalls) return this._cachedMergedRenderToolCalls;
|
|
1964
|
+
const merged = /* @__PURE__ */ new Map();
|
|
1965
|
+
for (const rc of this._renderToolCalls) {
|
|
1966
|
+
var _rc$agentId;
|
|
1967
|
+
merged.set(`${(_rc$agentId = rc.agentId) !== null && _rc$agentId !== void 0 ? _rc$agentId : ""}:${rc.name}`, rc);
|
|
1968
|
+
}
|
|
1969
|
+
for (const [key, rc] of this._hookRenderToolCalls) merged.set(key, rc);
|
|
1970
|
+
this._cachedMergedRenderToolCalls = Array.from(merged.values());
|
|
1971
|
+
return this._cachedMergedRenderToolCalls;
|
|
1961
1972
|
}
|
|
1962
1973
|
setRenderActivityMessages(renderers) {
|
|
1963
1974
|
this._renderActivityMessages = renderers;
|
|
@@ -1967,6 +1978,24 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
1967
1978
|
}
|
|
1968
1979
|
setRenderToolCalls(renderToolCalls) {
|
|
1969
1980
|
this._renderToolCalls = renderToolCalls;
|
|
1981
|
+
this._cachedMergedRenderToolCalls = null;
|
|
1982
|
+
this._notifyRenderToolCallsChanged();
|
|
1983
|
+
}
|
|
1984
|
+
addHookRenderToolCall(entry) {
|
|
1985
|
+
var _entry$agentId;
|
|
1986
|
+
const key = `${(_entry$agentId = entry.agentId) !== null && _entry$agentId !== void 0 ? _entry$agentId : ""}:${entry.name}`;
|
|
1987
|
+
this._hookRenderToolCalls.set(key, entry);
|
|
1988
|
+
this._cachedMergedRenderToolCalls = null;
|
|
1989
|
+
this._notifyRenderToolCallsChanged();
|
|
1990
|
+
}
|
|
1991
|
+
removeHookRenderToolCall(name, agentId) {
|
|
1992
|
+
const key = `${agentId !== null && agentId !== void 0 ? agentId : ""}:${name}`;
|
|
1993
|
+
if (this._hookRenderToolCalls.delete(key)) {
|
|
1994
|
+
this._cachedMergedRenderToolCalls = null;
|
|
1995
|
+
this._notifyRenderToolCallsChanged();
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
_notifyRenderToolCallsChanged() {
|
|
1970
1999
|
this.notifySubscribers((subscriber) => {
|
|
1971
2000
|
const reactSubscriber = subscriber;
|
|
1972
2001
|
if (reactSubscriber.onRenderToolCallsChanged) reactSubscriber.onRenderToolCallsChanged({
|
|
@@ -2433,23 +2462,12 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2433
2462
|
copilotkit.removeTool(name, tool.agentId);
|
|
2434
2463
|
}
|
|
2435
2464
|
copilotkit.addTool(tool);
|
|
2436
|
-
if (tool.render) {
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
const mergedMap = /* @__PURE__ */ new Map();
|
|
2443
|
-
for (const rc of currentRenderToolCalls) mergedMap.set(keyOf(rc), rc);
|
|
2444
|
-
const newEntry = {
|
|
2445
|
-
name,
|
|
2446
|
-
args: tool.parameters,
|
|
2447
|
-
agentId: tool.agentId,
|
|
2448
|
-
render: tool.render
|
|
2449
|
-
};
|
|
2450
|
-
mergedMap.set(keyOf(newEntry), newEntry);
|
|
2451
|
-
copilotkit.setRenderToolCalls(Array.from(mergedMap.values()));
|
|
2452
|
-
}
|
|
2465
|
+
if (tool.render && tool.parameters) copilotkit.addHookRenderToolCall({
|
|
2466
|
+
name,
|
|
2467
|
+
args: tool.parameters,
|
|
2468
|
+
agentId: tool.agentId,
|
|
2469
|
+
render: tool.render
|
|
2470
|
+
});
|
|
2453
2471
|
return () => {
|
|
2454
2472
|
copilotkit.removeTool(name, tool.agentId);
|
|
2455
2473
|
};
|
|
@@ -2605,15 +2623,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2605
2623
|
}),
|
|
2606
2624
|
...config.agentId ? { agentId: config.agentId } : {}
|
|
2607
2625
|
});
|
|
2608
|
-
|
|
2609
|
-
var _rc$agentId;
|
|
2610
|
-
return `${(_rc$agentId = rc.agentId) !== null && _rc$agentId !== void 0 ? _rc$agentId : ""}:${rc.name}`;
|
|
2611
|
-
};
|
|
2612
|
-
const currentRenderToolCalls = copilotkit.renderToolCalls;
|
|
2613
|
-
const mergedMap = /* @__PURE__ */ new Map();
|
|
2614
|
-
for (const rc of currentRenderToolCalls) mergedMap.set(keyOf(rc), rc);
|
|
2615
|
-
mergedMap.set(keyOf(renderer), renderer);
|
|
2616
|
-
copilotkit.setRenderToolCalls(Array.from(mergedMap.values()));
|
|
2626
|
+
copilotkit.addHookRenderToolCall(renderer);
|
|
2617
2627
|
}, [
|
|
2618
2628
|
config.name,
|
|
2619
2629
|
copilotkit,
|
|
@@ -2870,15 +2880,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2870
2880
|
}, deps);
|
|
2871
2881
|
(0, react.useEffect)(() => {
|
|
2872
2882
|
return () => {
|
|
2873
|
-
|
|
2874
|
-
var _rc$agentId;
|
|
2875
|
-
return `${(_rc$agentId = rc.agentId) !== null && _rc$agentId !== void 0 ? _rc$agentId : ""}:${rc.name}`;
|
|
2876
|
-
};
|
|
2877
|
-
const filtered = copilotkit.renderToolCalls.filter((rc) => keyOf(rc) !== keyOf({
|
|
2878
|
-
name: tool.name,
|
|
2879
|
-
agentId: tool.agentId
|
|
2880
|
-
}));
|
|
2881
|
-
copilotkit.setRenderToolCalls(filtered);
|
|
2883
|
+
copilotkit.removeHookRenderToolCall(tool.name, tool.agentId);
|
|
2882
2884
|
};
|
|
2883
2885
|
}, [
|
|
2884
2886
|
copilotkit,
|