@copilotkitnext/react 1.51.5-next.4 → 1.52.0-next.6
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/components/WildcardToolCallRender.cjs +13 -13
- package/dist/components/WildcardToolCallRender.cjs.map +1 -1
- package/dist/components/WildcardToolCallRender.mjs +13 -13
- package/dist/components/WildcardToolCallRender.mjs.map +1 -1
- package/dist/components/chat/CopilotChat.cjs.map +1 -1
- package/dist/components/chat/CopilotChat.mjs.map +1 -1
- package/dist/components/chat/CopilotChatAssistantMessage.cjs +36 -28
- package/dist/components/chat/CopilotChatAssistantMessage.cjs.map +1 -1
- package/dist/components/chat/CopilotChatAssistantMessage.mjs +37 -29
- package/dist/components/chat/CopilotChatAssistantMessage.mjs.map +1 -1
- package/dist/components/chat/CopilotChatAudioRecorder.cjs +2 -2
- package/dist/components/chat/CopilotChatAudioRecorder.cjs.map +1 -1
- package/dist/components/chat/CopilotChatAudioRecorder.mjs +2 -2
- package/dist/components/chat/CopilotChatAudioRecorder.mjs.map +1 -1
- package/dist/components/chat/CopilotChatInput.cjs +59 -51
- package/dist/components/chat/CopilotChatInput.cjs.map +1 -1
- package/dist/components/chat/CopilotChatInput.d.cts.map +1 -1
- package/dist/components/chat/CopilotChatInput.d.mts.map +1 -1
- package/dist/components/chat/CopilotChatInput.mjs +59 -51
- package/dist/components/chat/CopilotChatInput.mjs.map +1 -1
- package/dist/components/chat/CopilotChatMessageView.cjs +12 -7
- package/dist/components/chat/CopilotChatMessageView.cjs.map +1 -1
- package/dist/components/chat/CopilotChatMessageView.d.cts.map +1 -1
- package/dist/components/chat/CopilotChatMessageView.d.mts.map +1 -1
- package/dist/components/chat/CopilotChatMessageView.mjs +12 -7
- package/dist/components/chat/CopilotChatMessageView.mjs.map +1 -1
- package/dist/components/chat/CopilotChatReasoningMessage.cjs +24 -20
- package/dist/components/chat/CopilotChatReasoningMessage.cjs.map +1 -1
- package/dist/components/chat/CopilotChatReasoningMessage.d.cts.map +1 -1
- package/dist/components/chat/CopilotChatReasoningMessage.d.mts.map +1 -1
- package/dist/components/chat/CopilotChatReasoningMessage.mjs +25 -21
- package/dist/components/chat/CopilotChatReasoningMessage.mjs.map +1 -1
- package/dist/components/chat/CopilotChatSuggestionPill.cjs +6 -5
- package/dist/components/chat/CopilotChatSuggestionPill.cjs.map +1 -1
- package/dist/components/chat/CopilotChatSuggestionPill.mjs +6 -5
- package/dist/components/chat/CopilotChatSuggestionPill.mjs.map +1 -1
- package/dist/components/chat/CopilotChatSuggestionView.cjs +24 -12
- package/dist/components/chat/CopilotChatSuggestionView.cjs.map +1 -1
- package/dist/components/chat/CopilotChatSuggestionView.d.cts.map +1 -1
- package/dist/components/chat/CopilotChatSuggestionView.d.mts.map +1 -1
- package/dist/components/chat/CopilotChatSuggestionView.mjs +25 -13
- package/dist/components/chat/CopilotChatSuggestionView.mjs.map +1 -1
- package/dist/components/chat/CopilotChatToggleButton.cjs +7 -6
- package/dist/components/chat/CopilotChatToggleButton.cjs.map +1 -1
- package/dist/components/chat/CopilotChatToggleButton.d.cts.map +1 -1
- package/dist/components/chat/CopilotChatToggleButton.d.mts.map +1 -1
- package/dist/components/chat/CopilotChatToggleButton.mjs +7 -6
- package/dist/components/chat/CopilotChatToggleButton.mjs.map +1 -1
- package/dist/components/chat/CopilotChatUserMessage.cjs +29 -24
- package/dist/components/chat/CopilotChatUserMessage.cjs.map +1 -1
- package/dist/components/chat/CopilotChatUserMessage.d.cts.map +1 -1
- package/dist/components/chat/CopilotChatUserMessage.d.mts.map +1 -1
- package/dist/components/chat/CopilotChatUserMessage.mjs +30 -25
- package/dist/components/chat/CopilotChatUserMessage.mjs.map +1 -1
- package/dist/components/chat/CopilotChatView.cjs +45 -35
- package/dist/components/chat/CopilotChatView.cjs.map +1 -1
- package/dist/components/chat/CopilotChatView.d.cts +1 -1
- package/dist/components/chat/CopilotChatView.d.cts.map +1 -1
- package/dist/components/chat/CopilotChatView.d.mts +1 -1
- package/dist/components/chat/CopilotChatView.d.mts.map +1 -1
- package/dist/components/chat/CopilotChatView.mjs +45 -35
- package/dist/components/chat/CopilotChatView.mjs.map +1 -1
- package/dist/components/chat/CopilotModalHeader.cjs +8 -8
- package/dist/components/chat/CopilotModalHeader.cjs.map +1 -1
- package/dist/components/chat/CopilotModalHeader.d.cts.map +1 -1
- package/dist/components/chat/CopilotModalHeader.d.mts.map +1 -1
- package/dist/components/chat/CopilotModalHeader.mjs +8 -8
- package/dist/components/chat/CopilotModalHeader.mjs.map +1 -1
- package/dist/components/chat/CopilotPopupView.cjs +20 -15
- package/dist/components/chat/CopilotPopupView.cjs.map +1 -1
- package/dist/components/chat/CopilotPopupView.d.cts.map +1 -1
- package/dist/components/chat/CopilotPopupView.d.mts.map +1 -1
- package/dist/components/chat/CopilotPopupView.mjs +20 -15
- package/dist/components/chat/CopilotPopupView.mjs.map +1 -1
- package/dist/components/chat/CopilotSidebarView.cjs +54 -43
- package/dist/components/chat/CopilotSidebarView.cjs.map +1 -1
- package/dist/components/chat/CopilotSidebarView.d.cts.map +1 -1
- package/dist/components/chat/CopilotSidebarView.d.mts.map +1 -1
- package/dist/components/chat/CopilotSidebarView.mjs +55 -44
- package/dist/components/chat/CopilotSidebarView.mjs.map +1 -1
- package/dist/components/ui/button.cjs +42 -42
- package/dist/components/ui/button.cjs.map +1 -1
- package/dist/components/ui/button.mjs +42 -42
- package/dist/components/ui/button.mjs.map +1 -1
- package/dist/components/ui/dropdown-menu.cjs +7 -6
- package/dist/components/ui/dropdown-menu.cjs.map +1 -1
- package/dist/components/ui/dropdown-menu.mjs +7 -6
- package/dist/components/ui/dropdown-menu.mjs.map +1 -1
- package/dist/components/ui/tooltip.cjs +3 -2
- package/dist/components/ui/tooltip.cjs.map +1 -1
- package/dist/components/ui/tooltip.mjs +3 -2
- package/dist/components/ui/tooltip.mjs.map +1 -1
- package/dist/hooks/use-component.cjs +18 -5
- package/dist/hooks/use-component.cjs.map +1 -1
- package/dist/hooks/use-component.d.cts +21 -7
- package/dist/hooks/use-component.d.cts.map +1 -1
- package/dist/hooks/use-component.d.mts +21 -7
- package/dist/hooks/use-component.d.mts.map +1 -1
- package/dist/hooks/use-component.mjs +18 -5
- package/dist/hooks/use-component.mjs.map +1 -1
- package/dist/hooks/use-default-render-tool.cjs +2 -2
- package/dist/hooks/use-default-render-tool.cjs.map +1 -1
- package/dist/hooks/use-default-render-tool.d.cts +3 -3
- package/dist/hooks/use-default-render-tool.d.cts.map +1 -1
- package/dist/hooks/use-default-render-tool.d.mts +3 -3
- package/dist/hooks/use-default-render-tool.d.mts.map +1 -1
- package/dist/hooks/use-default-render-tool.mjs +2 -2
- package/dist/hooks/use-default-render-tool.mjs.map +1 -1
- package/dist/hooks/use-render-tool.cjs +15 -9
- package/dist/hooks/use-render-tool.cjs.map +1 -1
- package/dist/hooks/use-render-tool.d.cts +9 -9
- package/dist/hooks/use-render-tool.d.cts.map +1 -1
- package/dist/hooks/use-render-tool.d.mts +9 -9
- package/dist/hooks/use-render-tool.d.mts.map +1 -1
- package/dist/hooks/use-render-tool.mjs +15 -9
- package/dist/hooks/use-render-tool.mjs.map +1 -1
- package/dist/index.umd.js +429 -339
- package/dist/index.umd.js.map +1 -1
- package/dist/lib/utils.cjs +2 -1
- package/dist/lib/utils.cjs.map +1 -1
- package/dist/lib/utils.mjs +3 -2
- package/dist/lib/utils.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/eslint-rules/README.md +52 -0
- package/eslint-rules/require-cpk-prefix.mjs +375 -0
- package/eslint.config.mjs +17 -0
- package/package.json +8 -7
|
@@ -9,21 +9,34 @@ let react_jsx_runtime = require("react/jsx-runtime");
|
|
|
9
9
|
* This hook is a convenience wrapper around `useFrontendTool` that:
|
|
10
10
|
* - builds a model-facing tool description,
|
|
11
11
|
* - forwards optional Zod parameters,
|
|
12
|
-
* - renders your component with tool call
|
|
12
|
+
* - renders your component with tool call parameters.
|
|
13
13
|
*
|
|
14
14
|
* Use this when you want to display a typed visual component for a tool call
|
|
15
15
|
* without manually wiring a full frontend tool object.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
17
|
+
* When `parameters` is provided, render props are inferred from the schema
|
|
18
|
+
* via `z.infer`. When omitted, the render component may accept any props.
|
|
19
|
+
*
|
|
20
|
+
* @typeParam TSchema - Zod schema describing tool parameters, or `undefined` when no schema is given.
|
|
18
21
|
* @param config - Tool registration config.
|
|
19
22
|
* @param deps - Optional dependencies to refresh registration (same semantics as `useEffect`).
|
|
20
23
|
*
|
|
21
24
|
* @example
|
|
22
25
|
* ```tsx
|
|
26
|
+
* // Without parameters — render accepts any props
|
|
27
|
+
* useComponent({
|
|
28
|
+
* name: "showGreeting",
|
|
29
|
+
* render: ({ message }: { message: string }) => <div>{message}</div>,
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```tsx
|
|
35
|
+
* // With parameters — render props inferred from schema
|
|
23
36
|
* useComponent({
|
|
24
37
|
* name: "showWeatherCard",
|
|
25
38
|
* parameters: z.object({ city: z.string() }),
|
|
26
|
-
*
|
|
39
|
+
* render: ({ city }) => <div>{city}</div>,
|
|
27
40
|
* });
|
|
28
41
|
* ```
|
|
29
42
|
*
|
|
@@ -33,7 +46,7 @@ let react_jsx_runtime = require("react/jsx-runtime");
|
|
|
33
46
|
* {
|
|
34
47
|
* name: "renderProfile",
|
|
35
48
|
* parameters: z.object({ userId: z.string() }),
|
|
36
|
-
*
|
|
49
|
+
* render: ProfileCard,
|
|
37
50
|
* agentId: "support-agent",
|
|
38
51
|
* },
|
|
39
52
|
* [selectedAgentId],
|
|
@@ -48,7 +61,7 @@ function useComponent(config, deps) {
|
|
|
48
61
|
description: fullDescription,
|
|
49
62
|
parameters: config.parameters,
|
|
50
63
|
render: ({ args }) => {
|
|
51
|
-
const Component = config.
|
|
64
|
+
const Component = config.render;
|
|
52
65
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Component, { ...args });
|
|
53
66
|
},
|
|
54
67
|
agentId: config.agentId
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-component.cjs","names":[],"sources":["../../src/hooks/use-component.tsx"],"sourcesContent":["import { z } from \"zod\";\nimport type { ComponentType } from \"react\";\nimport { useFrontendTool } from \"./use-frontend-tool\";\n\n/**\n * Registers a React component as a frontend tool renderer in chat.\n *\n * This hook is a convenience wrapper around `useFrontendTool` that:\n * - builds a model-facing tool description,\n * - forwards optional Zod parameters,\n * - renders your component with tool call
|
|
1
|
+
{"version":3,"file":"use-component.cjs","names":[],"sources":["../../src/hooks/use-component.tsx"],"sourcesContent":["import { z } from \"zod\";\nimport type { ComponentType } from \"react\";\nimport { useFrontendTool } from \"./use-frontend-tool\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype InferRenderProps<T> = T extends z.ZodTypeAny ? z.infer<T> : any;\n\n/**\n * Registers a React component as a frontend tool renderer in chat.\n *\n * This hook is a convenience wrapper around `useFrontendTool` that:\n * - builds a model-facing tool description,\n * - forwards optional Zod parameters,\n * - renders your component with tool call parameters.\n *\n * Use this when you want to display a typed visual component for a tool call\n * without manually wiring a full frontend tool object.\n *\n * When `parameters` is provided, render props are inferred from the schema\n * via `z.infer`. When omitted, the render component may accept any props.\n *\n * @typeParam TSchema - Zod schema describing tool parameters, or `undefined` when no schema is given.\n * @param config - Tool registration config.\n * @param deps - Optional dependencies to refresh registration (same semantics as `useEffect`).\n *\n * @example\n * ```tsx\n * // Without parameters — render accepts any props\n * useComponent({\n * name: \"showGreeting\",\n * render: ({ message }: { message: string }) => <div>{message}</div>,\n * });\n * ```\n *\n * @example\n * ```tsx\n * // With parameters — render props inferred from schema\n * useComponent({\n * name: \"showWeatherCard\",\n * parameters: z.object({ city: z.string() }),\n * render: ({ city }) => <div>{city}</div>,\n * });\n * ```\n *\n * @example\n * ```tsx\n * useComponent(\n * {\n * name: \"renderProfile\",\n * parameters: z.object({ userId: z.string() }),\n * render: ProfileCard,\n * agentId: \"support-agent\",\n * },\n * [selectedAgentId],\n * );\n * ```\n */\nexport function useComponent<\n TSchema extends z.ZodTypeAny | undefined = undefined,\n>(\n config: {\n name: string;\n description?: string;\n parameters?: TSchema;\n render: ComponentType<NoInfer<InferRenderProps<TSchema>>>;\n agentId?: string;\n },\n deps?: ReadonlyArray<unknown>,\n): void {\n const prefix = `Use this tool to display the \"${config.name}\" component in the chat. This tool renders a visual UI component for the user.`;\n const fullDescription = config.description\n ? `${prefix}\\n\\n${config.description}`\n : prefix;\n\n useFrontendTool(\n {\n name: config.name,\n description: fullDescription,\n parameters: config.parameters,\n render: ({ args }: { args: unknown }) => {\n const Component = config.render;\n return <Component {...(args as InferRenderProps<TSchema>)} />;\n },\n agentId: config.agentId,\n },\n deps,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,SAAgB,aAGd,QAOA,MACM;CACN,MAAM,SAAS,iCAAiC,OAAO,KAAK;CAC5D,MAAM,kBAAkB,OAAO,cAC3B,GAAG,OAAO,MAAM,OAAO,gBACvB;AAEJ,2CACE;EACE,MAAM,OAAO;EACb,aAAa;EACb,YAAY,OAAO;EACnB,SAAS,EAAE,WAA8B;GACvC,MAAM,YAAY,OAAO;AACzB,UAAO,2CAAC,aAAU,GAAK,OAAsC;;EAE/D,SAAS,OAAO;EACjB,EACD,KACD"}
|
|
@@ -2,27 +2,41 @@ import { ComponentType } from "react";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
|
|
4
4
|
//#region src/hooks/use-component.d.ts
|
|
5
|
+
type InferRenderProps<T> = T extends z.ZodTypeAny ? z.infer<T> : any;
|
|
5
6
|
/**
|
|
6
7
|
* Registers a React component as a frontend tool renderer in chat.
|
|
7
8
|
*
|
|
8
9
|
* This hook is a convenience wrapper around `useFrontendTool` that:
|
|
9
10
|
* - builds a model-facing tool description,
|
|
10
11
|
* - forwards optional Zod parameters,
|
|
11
|
-
* - renders your component with tool call
|
|
12
|
+
* - renders your component with tool call parameters.
|
|
12
13
|
*
|
|
13
14
|
* Use this when you want to display a typed visual component for a tool call
|
|
14
15
|
* without manually wiring a full frontend tool object.
|
|
15
16
|
*
|
|
16
|
-
*
|
|
17
|
+
* When `parameters` is provided, render props are inferred from the schema
|
|
18
|
+
* via `z.infer`. When omitted, the render component may accept any props.
|
|
19
|
+
*
|
|
20
|
+
* @typeParam TSchema - Zod schema describing tool parameters, or `undefined` when no schema is given.
|
|
17
21
|
* @param config - Tool registration config.
|
|
18
22
|
* @param deps - Optional dependencies to refresh registration (same semantics as `useEffect`).
|
|
19
23
|
*
|
|
20
24
|
* @example
|
|
21
25
|
* ```tsx
|
|
26
|
+
* // Without parameters — render accepts any props
|
|
27
|
+
* useComponent({
|
|
28
|
+
* name: "showGreeting",
|
|
29
|
+
* render: ({ message }: { message: string }) => <div>{message}</div>,
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```tsx
|
|
35
|
+
* // With parameters — render props inferred from schema
|
|
22
36
|
* useComponent({
|
|
23
37
|
* name: "showWeatherCard",
|
|
24
38
|
* parameters: z.object({ city: z.string() }),
|
|
25
|
-
*
|
|
39
|
+
* render: ({ city }) => <div>{city}</div>,
|
|
26
40
|
* });
|
|
27
41
|
* ```
|
|
28
42
|
*
|
|
@@ -32,18 +46,18 @@ import { z } from "zod";
|
|
|
32
46
|
* {
|
|
33
47
|
* name: "renderProfile",
|
|
34
48
|
* parameters: z.object({ userId: z.string() }),
|
|
35
|
-
*
|
|
49
|
+
* render: ProfileCard,
|
|
36
50
|
* agentId: "support-agent",
|
|
37
51
|
* },
|
|
38
52
|
* [selectedAgentId],
|
|
39
53
|
* );
|
|
40
54
|
* ```
|
|
41
55
|
*/
|
|
42
|
-
declare function useComponent<
|
|
56
|
+
declare function useComponent<TSchema extends z.ZodTypeAny | undefined = undefined>(config: {
|
|
43
57
|
name: string;
|
|
44
58
|
description?: string;
|
|
45
|
-
parameters?:
|
|
46
|
-
|
|
59
|
+
parameters?: TSchema;
|
|
60
|
+
render: ComponentType<NoInfer<InferRenderProps<TSchema>>>;
|
|
47
61
|
agentId?: string;
|
|
48
62
|
}, deps?: ReadonlyArray<unknown>): void;
|
|
49
63
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-component.d.cts","names":[],"sources":["../../src/hooks/use-component.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-component.d.cts","names":[],"sources":["../../src/hooks/use-component.tsx"],"mappings":";;;;KAKK,gBAAA,MAAsB,CAAA,SAAU,CAAA,CAAE,UAAA,GAAa,CAAA,CAAE,KAAA,CAAM,CAAA;;AAJjB;;;;;;;;;;;;;;;;;;AAwD3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,YAAA,iBACE,CAAA,CAAE,UAAA,yBAAA,CAElB,MAAA;EACE,IAAA;EACA,WAAA;EACA,UAAA,GAAa,OAAA;EACb,MAAA,EAAQ,aAAA,CAAc,OAAA,CAAQ,gBAAA,CAAiB,OAAA;EAC/C,OAAA;AAAA,GAEF,IAAA,GAAO,aAAA"}
|
|
@@ -2,27 +2,41 @@ import { ComponentType } from "react";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
|
|
4
4
|
//#region src/hooks/use-component.d.ts
|
|
5
|
+
type InferRenderProps<T> = T extends z.ZodTypeAny ? z.infer<T> : any;
|
|
5
6
|
/**
|
|
6
7
|
* Registers a React component as a frontend tool renderer in chat.
|
|
7
8
|
*
|
|
8
9
|
* This hook is a convenience wrapper around `useFrontendTool` that:
|
|
9
10
|
* - builds a model-facing tool description,
|
|
10
11
|
* - forwards optional Zod parameters,
|
|
11
|
-
* - renders your component with tool call
|
|
12
|
+
* - renders your component with tool call parameters.
|
|
12
13
|
*
|
|
13
14
|
* Use this when you want to display a typed visual component for a tool call
|
|
14
15
|
* without manually wiring a full frontend tool object.
|
|
15
16
|
*
|
|
16
|
-
*
|
|
17
|
+
* When `parameters` is provided, render props are inferred from the schema
|
|
18
|
+
* via `z.infer`. When omitted, the render component may accept any props.
|
|
19
|
+
*
|
|
20
|
+
* @typeParam TSchema - Zod schema describing tool parameters, or `undefined` when no schema is given.
|
|
17
21
|
* @param config - Tool registration config.
|
|
18
22
|
* @param deps - Optional dependencies to refresh registration (same semantics as `useEffect`).
|
|
19
23
|
*
|
|
20
24
|
* @example
|
|
21
25
|
* ```tsx
|
|
26
|
+
* // Without parameters — render accepts any props
|
|
27
|
+
* useComponent({
|
|
28
|
+
* name: "showGreeting",
|
|
29
|
+
* render: ({ message }: { message: string }) => <div>{message}</div>,
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```tsx
|
|
35
|
+
* // With parameters — render props inferred from schema
|
|
22
36
|
* useComponent({
|
|
23
37
|
* name: "showWeatherCard",
|
|
24
38
|
* parameters: z.object({ city: z.string() }),
|
|
25
|
-
*
|
|
39
|
+
* render: ({ city }) => <div>{city}</div>,
|
|
26
40
|
* });
|
|
27
41
|
* ```
|
|
28
42
|
*
|
|
@@ -32,18 +46,18 @@ import { z } from "zod";
|
|
|
32
46
|
* {
|
|
33
47
|
* name: "renderProfile",
|
|
34
48
|
* parameters: z.object({ userId: z.string() }),
|
|
35
|
-
*
|
|
49
|
+
* render: ProfileCard,
|
|
36
50
|
* agentId: "support-agent",
|
|
37
51
|
* },
|
|
38
52
|
* [selectedAgentId],
|
|
39
53
|
* );
|
|
40
54
|
* ```
|
|
41
55
|
*/
|
|
42
|
-
declare function useComponent<
|
|
56
|
+
declare function useComponent<TSchema extends z.ZodTypeAny | undefined = undefined>(config: {
|
|
43
57
|
name: string;
|
|
44
58
|
description?: string;
|
|
45
|
-
parameters?:
|
|
46
|
-
|
|
59
|
+
parameters?: TSchema;
|
|
60
|
+
render: ComponentType<NoInfer<InferRenderProps<TSchema>>>;
|
|
47
61
|
agentId?: string;
|
|
48
62
|
}, deps?: ReadonlyArray<unknown>): void;
|
|
49
63
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-component.d.mts","names":[],"sources":["../../src/hooks/use-component.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-component.d.mts","names":[],"sources":["../../src/hooks/use-component.tsx"],"mappings":";;;;KAKK,gBAAA,MAAsB,CAAA,SAAU,CAAA,CAAE,UAAA,GAAa,CAAA,CAAE,KAAA,CAAM,CAAA;;AAJjB;;;;;;;;;;;;;;;;;;AAwD3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,YAAA,iBACE,CAAA,CAAE,UAAA,yBAAA,CAElB,MAAA;EACE,IAAA;EACA,WAAA;EACA,UAAA,GAAa,OAAA;EACb,MAAA,EAAQ,aAAA,CAAc,OAAA,CAAQ,gBAAA,CAAiB,OAAA;EAC/C,OAAA;AAAA,GAEF,IAAA,GAAO,aAAA"}
|
|
@@ -8,21 +8,34 @@ import { jsx } from "react/jsx-runtime";
|
|
|
8
8
|
* This hook is a convenience wrapper around `useFrontendTool` that:
|
|
9
9
|
* - builds a model-facing tool description,
|
|
10
10
|
* - forwards optional Zod parameters,
|
|
11
|
-
* - renders your component with tool call
|
|
11
|
+
* - renders your component with tool call parameters.
|
|
12
12
|
*
|
|
13
13
|
* Use this when you want to display a typed visual component for a tool call
|
|
14
14
|
* without manually wiring a full frontend tool object.
|
|
15
15
|
*
|
|
16
|
-
*
|
|
16
|
+
* When `parameters` is provided, render props are inferred from the schema
|
|
17
|
+
* via `z.infer`. When omitted, the render component may accept any props.
|
|
18
|
+
*
|
|
19
|
+
* @typeParam TSchema - Zod schema describing tool parameters, or `undefined` when no schema is given.
|
|
17
20
|
* @param config - Tool registration config.
|
|
18
21
|
* @param deps - Optional dependencies to refresh registration (same semantics as `useEffect`).
|
|
19
22
|
*
|
|
20
23
|
* @example
|
|
21
24
|
* ```tsx
|
|
25
|
+
* // Without parameters — render accepts any props
|
|
26
|
+
* useComponent({
|
|
27
|
+
* name: "showGreeting",
|
|
28
|
+
* render: ({ message }: { message: string }) => <div>{message}</div>,
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* // With parameters — render props inferred from schema
|
|
22
35
|
* useComponent({
|
|
23
36
|
* name: "showWeatherCard",
|
|
24
37
|
* parameters: z.object({ city: z.string() }),
|
|
25
|
-
*
|
|
38
|
+
* render: ({ city }) => <div>{city}</div>,
|
|
26
39
|
* });
|
|
27
40
|
* ```
|
|
28
41
|
*
|
|
@@ -32,7 +45,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
32
45
|
* {
|
|
33
46
|
* name: "renderProfile",
|
|
34
47
|
* parameters: z.object({ userId: z.string() }),
|
|
35
|
-
*
|
|
48
|
+
* render: ProfileCard,
|
|
36
49
|
* agentId: "support-agent",
|
|
37
50
|
* },
|
|
38
51
|
* [selectedAgentId],
|
|
@@ -47,7 +60,7 @@ function useComponent(config, deps) {
|
|
|
47
60
|
description: fullDescription,
|
|
48
61
|
parameters: config.parameters,
|
|
49
62
|
render: ({ args }) => {
|
|
50
|
-
const Component = config.
|
|
63
|
+
const Component = config.render;
|
|
51
64
|
return /* @__PURE__ */ jsx(Component, { ...args });
|
|
52
65
|
},
|
|
53
66
|
agentId: config.agentId
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-component.mjs","names":[],"sources":["../../src/hooks/use-component.tsx"],"sourcesContent":["import { z } from \"zod\";\nimport type { ComponentType } from \"react\";\nimport { useFrontendTool } from \"./use-frontend-tool\";\n\n/**\n * Registers a React component as a frontend tool renderer in chat.\n *\n * This hook is a convenience wrapper around `useFrontendTool` that:\n * - builds a model-facing tool description,\n * - forwards optional Zod parameters,\n * - renders your component with tool call
|
|
1
|
+
{"version":3,"file":"use-component.mjs","names":[],"sources":["../../src/hooks/use-component.tsx"],"sourcesContent":["import { z } from \"zod\";\nimport type { ComponentType } from \"react\";\nimport { useFrontendTool } from \"./use-frontend-tool\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype InferRenderProps<T> = T extends z.ZodTypeAny ? z.infer<T> : any;\n\n/**\n * Registers a React component as a frontend tool renderer in chat.\n *\n * This hook is a convenience wrapper around `useFrontendTool` that:\n * - builds a model-facing tool description,\n * - forwards optional Zod parameters,\n * - renders your component with tool call parameters.\n *\n * Use this when you want to display a typed visual component for a tool call\n * without manually wiring a full frontend tool object.\n *\n * When `parameters` is provided, render props are inferred from the schema\n * via `z.infer`. When omitted, the render component may accept any props.\n *\n * @typeParam TSchema - Zod schema describing tool parameters, or `undefined` when no schema is given.\n * @param config - Tool registration config.\n * @param deps - Optional dependencies to refresh registration (same semantics as `useEffect`).\n *\n * @example\n * ```tsx\n * // Without parameters — render accepts any props\n * useComponent({\n * name: \"showGreeting\",\n * render: ({ message }: { message: string }) => <div>{message}</div>,\n * });\n * ```\n *\n * @example\n * ```tsx\n * // With parameters — render props inferred from schema\n * useComponent({\n * name: \"showWeatherCard\",\n * parameters: z.object({ city: z.string() }),\n * render: ({ city }) => <div>{city}</div>,\n * });\n * ```\n *\n * @example\n * ```tsx\n * useComponent(\n * {\n * name: \"renderProfile\",\n * parameters: z.object({ userId: z.string() }),\n * render: ProfileCard,\n * agentId: \"support-agent\",\n * },\n * [selectedAgentId],\n * );\n * ```\n */\nexport function useComponent<\n TSchema extends z.ZodTypeAny | undefined = undefined,\n>(\n config: {\n name: string;\n description?: string;\n parameters?: TSchema;\n render: ComponentType<NoInfer<InferRenderProps<TSchema>>>;\n agentId?: string;\n },\n deps?: ReadonlyArray<unknown>,\n): void {\n const prefix = `Use this tool to display the \"${config.name}\" component in the chat. This tool renders a visual UI component for the user.`;\n const fullDescription = config.description\n ? `${prefix}\\n\\n${config.description}`\n : prefix;\n\n useFrontendTool(\n {\n name: config.name,\n description: fullDescription,\n parameters: config.parameters,\n render: ({ args }: { args: unknown }) => {\n const Component = config.render;\n return <Component {...(args as InferRenderProps<TSchema>)} />;\n },\n agentId: config.agentId,\n },\n deps,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,SAAgB,aAGd,QAOA,MACM;CACN,MAAM,SAAS,iCAAiC,OAAO,KAAK;CAC5D,MAAM,kBAAkB,OAAO,cAC3B,GAAG,OAAO,MAAM,OAAO,gBACvB;AAEJ,iBACE;EACE,MAAM,OAAO;EACb,aAAa;EACb,YAAY,OAAO;EACnB,SAAS,EAAE,WAA8B;GACvC,MAAM,YAAY,OAAO;AACzB,UAAO,oBAAC,aAAU,GAAK,OAAsC;;EAE/D,SAAS,OAAO;EACjB,EACD,KACD"}
|
|
@@ -47,7 +47,7 @@ function useDefaultRenderTool(config, deps) {
|
|
|
47
47
|
render: config?.render ?? DefaultToolCallRenderer
|
|
48
48
|
}, deps);
|
|
49
49
|
}
|
|
50
|
-
function DefaultToolCallRenderer({ name,
|
|
50
|
+
function DefaultToolCallRenderer({ name, parameters, status, result }) {
|
|
51
51
|
const [isExpanded, setIsExpanded] = (0, react.useState)(false);
|
|
52
52
|
const statusString = String(status);
|
|
53
53
|
const isActive = statusString === "inProgress" || statusString === "executing";
|
|
@@ -163,7 +163,7 @@ function DefaultToolCallRenderer({ name, args, status, result }) {
|
|
|
163
163
|
whiteSpace: "pre-wrap",
|
|
164
164
|
wordBreak: "break-word"
|
|
165
165
|
},
|
|
166
|
-
children: JSON.stringify(
|
|
166
|
+
children: JSON.stringify(parameters ?? {}, null, 2)
|
|
167
167
|
})] }), result !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
168
168
|
style: {
|
|
169
169
|
fontSize: "10px",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-default-render-tool.cjs","names":[],"sources":["../../src/hooks/use-default-render-tool.tsx"],"sourcesContent":["import React, { useState } from \"react\";\nimport { useRenderTool } from \"./use-render-tool\";\n\ntype DefaultRenderProps = {\n name: string;\n
|
|
1
|
+
{"version":3,"file":"use-default-render-tool.cjs","names":[],"sources":["../../src/hooks/use-default-render-tool.tsx"],"sourcesContent":["import React, { useState } from \"react\";\nimport { useRenderTool } from \"./use-render-tool\";\n\ntype DefaultRenderProps = {\n /** The name of the tool being called. */\n name: string;\n /** The parsed parameters passed to the tool call. */\n parameters: unknown;\n /** Current execution status of the tool call. */\n status: \"inProgress\" | \"executing\" | \"complete\";\n /** The tool call result string, available only when `status` is `\"complete\"`. */\n result: string | undefined;\n};\n\n/**\n * Registers a wildcard (`\"*\"`) tool-call renderer via `useRenderTool`.\n *\n * - Call with no config to use CopilotKit's built-in default tool-call card.\n * - Pass `config.render` to replace the default UI with your own fallback renderer.\n *\n * This is useful when you want a generic renderer for tools that do not have a\n * dedicated `useRenderTool({ name: \"...\" })` registration.\n *\n * @param config - Optional custom wildcard render function.\n * @param deps - Optional dependencies to refresh registration.\n *\n * @example\n * ```tsx\n * useDefaultRenderTool();\n * ```\n *\n * @example\n * ```tsx\n * useDefaultRenderTool({\n * render: ({ name, status }) => <div>{name}: {status}</div>,\n * });\n * ```\n *\n * @example\n * ```tsx\n * useDefaultRenderTool(\n * {\n * render: ({ name, result }) => (\n * <ToolEventRow title={name} payload={result} compact={compactMode} />\n * ),\n * },\n * [compactMode],\n * );\n * ```\n */\nexport function useDefaultRenderTool(\n config?: {\n render?: (props: DefaultRenderProps) => React.ReactElement;\n },\n deps?: ReadonlyArray<unknown>,\n): void {\n useRenderTool(\n {\n name: \"*\",\n render: config?.render ?? DefaultToolCallRenderer,\n },\n deps,\n );\n}\n\nfunction DefaultToolCallRenderer({\n name,\n parameters,\n status,\n result,\n}: DefaultRenderProps): React.ReactElement {\n const [isExpanded, setIsExpanded] = useState(false);\n\n const statusString = String(status) as\n | \"inProgress\"\n | \"executing\"\n | \"complete\";\n const isActive =\n statusString === \"inProgress\" || statusString === \"executing\";\n const isComplete = statusString === \"complete\";\n\n const statusLabel = isActive ? \"Running\" : isComplete ? \"Done\" : status;\n const dotColor = isActive ? \"#f59e0b\" : isComplete ? \"#10b981\" : \"#a1a1aa\";\n const badgeBg = isActive ? \"#fef3c7\" : isComplete ? \"#d1fae5\" : \"#f4f4f5\";\n const badgeColor = isActive ? \"#92400e\" : isComplete ? \"#065f46\" : \"#3f3f46\";\n\n return (\n <div\n style={{\n marginTop: \"8px\",\n paddingBottom: \"8px\",\n }}\n >\n <div\n style={{\n borderRadius: \"12px\",\n border: \"1px solid #e4e4e7\",\n backgroundColor: \"#fafafa\",\n padding: \"14px 16px\",\n }}\n >\n {/* Header row — always visible */}\n <div\n onClick={() => setIsExpanded(!isExpanded)}\n style={{\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"space-between\",\n gap: \"10px\",\n cursor: \"pointer\",\n userSelect: \"none\",\n }}\n >\n <div\n style={{\n display: \"flex\",\n alignItems: \"center\",\n gap: \"8px\",\n minWidth: 0,\n }}\n >\n <svg\n style={{\n height: \"14px\",\n width: \"14px\",\n color: \"#71717a\",\n transition: \"transform 0.15s\",\n transform: isExpanded ? \"rotate(90deg)\" : \"rotate(0deg)\",\n flexShrink: 0,\n }}\n fill=\"none\"\n viewBox=\"0 0 24 24\"\n strokeWidth={2}\n stroke=\"currentColor\"\n >\n <path\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n d=\"M8.25 4.5l7.5 7.5-7.5 7.5\"\n />\n </svg>\n <span\n style={{\n display: \"inline-block\",\n height: \"8px\",\n width: \"8px\",\n borderRadius: \"50%\",\n backgroundColor: dotColor,\n flexShrink: 0,\n }}\n />\n <span\n style={{\n fontSize: \"13px\",\n fontWeight: 600,\n color: \"#18181b\",\n overflow: \"hidden\",\n textOverflow: \"ellipsis\",\n whiteSpace: \"nowrap\",\n }}\n >\n {name}\n </span>\n </div>\n\n <span\n style={{\n display: \"inline-flex\",\n alignItems: \"center\",\n borderRadius: \"9999px\",\n padding: \"2px 8px\",\n fontSize: \"11px\",\n fontWeight: 500,\n backgroundColor: badgeBg,\n color: badgeColor,\n flexShrink: 0,\n }}\n >\n {statusLabel}\n </span>\n </div>\n\n {/* Expandable details */}\n {isExpanded && (\n <div style={{ marginTop: \"12px\", display: \"grid\", gap: \"12px\" }}>\n <div>\n <div\n style={{\n fontSize: \"10px\",\n textTransform: \"uppercase\",\n letterSpacing: \"0.05em\",\n color: \"#71717a\",\n }}\n >\n Arguments\n </div>\n <pre\n style={{\n marginTop: \"6px\",\n maxHeight: \"200px\",\n overflow: \"auto\",\n borderRadius: \"6px\",\n backgroundColor: \"#f4f4f5\",\n padding: \"10px\",\n fontSize: \"11px\",\n lineHeight: 1.6,\n color: \"#27272a\",\n whiteSpace: \"pre-wrap\",\n wordBreak: \"break-word\",\n }}\n >\n {JSON.stringify(parameters ?? {}, null, 2)}\n </pre>\n </div>\n\n {result !== undefined && (\n <div>\n <div\n style={{\n fontSize: \"10px\",\n textTransform: \"uppercase\",\n letterSpacing: \"0.05em\",\n color: \"#71717a\",\n }}\n >\n Result\n </div>\n <pre\n style={{\n marginTop: \"6px\",\n maxHeight: \"200px\",\n overflow: \"auto\",\n borderRadius: \"6px\",\n backgroundColor: \"#f4f4f5\",\n padding: \"10px\",\n fontSize: \"11px\",\n lineHeight: 1.6,\n color: \"#27272a\",\n whiteSpace: \"pre-wrap\",\n wordBreak: \"break-word\",\n }}\n >\n {typeof result === \"string\"\n ? result\n : JSON.stringify(result, null, 2)}\n </pre>\n </div>\n )}\n </div>\n )}\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,SAAgB,qBACd,QAGA,MACM;AACN,uCACE;EACE,MAAM;EACN,QAAQ,QAAQ,UAAU;EAC3B,EACD,KACD;;AAGH,SAAS,wBAAwB,EAC/B,MACA,YACA,QACA,UACyC;CACzC,MAAM,CAAC,YAAY,qCAA0B,MAAM;CAEnD,MAAM,eAAe,OAAO,OAAO;CAInC,MAAM,WACJ,iBAAiB,gBAAgB,iBAAiB;CACpD,MAAM,aAAa,iBAAiB;AAOpC,QACE,2CAAC;EACC,OAAO;GACL,WAAW;GACX,eAAe;GAChB;YAED,4CAAC;GACC,OAAO;IACL,cAAc;IACd,QAAQ;IACR,iBAAiB;IACjB,SAAS;IACV;cAGD,4CAAC;IACC,eAAe,cAAc,CAAC,WAAW;IACzC,OAAO;KACL,SAAS;KACT,YAAY;KACZ,gBAAgB;KAChB,KAAK;KACL,QAAQ;KACR,YAAY;KACb;eAED,4CAAC;KACC,OAAO;MACL,SAAS;MACT,YAAY;MACZ,KAAK;MACL,UAAU;MACX;;MAED,2CAAC;OACC,OAAO;QACL,QAAQ;QACR,OAAO;QACP,OAAO;QACP,YAAY;QACZ,WAAW,aAAa,kBAAkB;QAC1C,YAAY;QACb;OACD,MAAK;OACL,SAAQ;OACR,aAAa;OACb,QAAO;iBAEP,2CAAC;QACC,eAAc;QACd,gBAAe;QACf,GAAE;SACF;QACE;MACN,2CAAC,UACC,OAAO;OACL,SAAS;OACT,QAAQ;OACR,OAAO;OACP,cAAc;OACd,iBAjEG,WAAW,YAAY,aAAa,YAAY;OAkEnD,YAAY;OACb,GACD;MACF,2CAAC;OACC,OAAO;QACL,UAAU;QACV,YAAY;QACZ,OAAO;QACP,UAAU;QACV,cAAc;QACd,YAAY;QACb;iBAEA;QACI;;MACH,EAEN,2CAAC;KACC,OAAO;MACL,SAAS;MACT,YAAY;MACZ,cAAc;MACd,SAAS;MACT,UAAU;MACV,YAAY;MACZ,iBA1FI,WAAW,YAAY,aAAa,YAAY;MA2FpD,OA1FO,WAAW,YAAY,aAAa,YAAY;MA2FvD,YAAY;MACb;eA/FS,WAAW,YAAY,aAAa,SAAS;MAkGlD;KACH,EAGL,cACC,4CAAC;IAAI,OAAO;KAAE,WAAW;KAAQ,SAAS;KAAQ,KAAK;KAAQ;eAC7D,4CAAC,oBACC,2CAAC;KACC,OAAO;MACL,UAAU;MACV,eAAe;MACf,eAAe;MACf,OAAO;MACR;eACF;MAEK,EACN,2CAAC;KACC,OAAO;MACL,WAAW;MACX,WAAW;MACX,UAAU;MACV,cAAc;MACd,iBAAiB;MACjB,SAAS;MACT,UAAU;MACV,YAAY;MACZ,OAAO;MACP,YAAY;MACZ,WAAW;MACZ;eAEA,KAAK,UAAU,cAAc,EAAE,EAAE,MAAM,EAAE;MACtC,IACF,EAEL,WAAW,UACV,4CAAC,oBACC,2CAAC;KACC,OAAO;MACL,UAAU;MACV,eAAe;MACf,eAAe;MACf,OAAO;MACR;eACF;MAEK,EACN,2CAAC;KACC,OAAO;MACL,WAAW;MACX,WAAW;MACX,UAAU;MACV,cAAc;MACd,iBAAiB;MACjB,SAAS;MACT,UAAU;MACV,YAAY;MACZ,OAAO;MACP,YAAY;MACZ,WAAW;MACZ;eAEA,OAAO,WAAW,WACf,SACA,KAAK,UAAU,QAAQ,MAAM,EAAE;MAC/B,IACF;KAEJ;IAEJ;GACF"}
|
|
@@ -2,9 +2,9 @@ import React from "react";
|
|
|
2
2
|
|
|
3
3
|
//#region src/hooks/use-default-render-tool.d.ts
|
|
4
4
|
type DefaultRenderProps = {
|
|
5
|
-
name: string;
|
|
6
|
-
|
|
7
|
-
status: string
|
|
5
|
+
/** The name of the tool being called. */name: string; /** The parsed parameters passed to the tool call. */
|
|
6
|
+
parameters: unknown; /** Current execution status of the tool call. */
|
|
7
|
+
status: "inProgress" | "executing" | "complete"; /** The tool call result string, available only when `status` is `"complete"`. */
|
|
8
8
|
result: string | undefined;
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-default-render-tool.d.cts","names":[],"sources":["../../src/hooks/use-default-render-tool.tsx"],"mappings":";;;KAGK,kBAAA;
|
|
1
|
+
{"version":3,"file":"use-default-render-tool.d.cts","names":[],"sources":["../../src/hooks/use-default-render-tool.tsx"],"mappings":";;;KAGK,kBAAA;2CAEH,IAAA,UAFqB;EAIrB,UAAA,WAJqB;EAMrB,MAAA,2CAFA;EAIA,MAAA;AAAA;;;AAuCF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,oBAAA,CACd,MAAA;EACE,MAAA,IAAU,KAAA,EAAO,kBAAA,KAAuB,KAAA,CAAM,YAAA;AAAA,GAEhD,IAAA,GAAO,aAAA"}
|
|
@@ -2,9 +2,9 @@ import React from "react";
|
|
|
2
2
|
|
|
3
3
|
//#region src/hooks/use-default-render-tool.d.ts
|
|
4
4
|
type DefaultRenderProps = {
|
|
5
|
-
name: string;
|
|
6
|
-
|
|
7
|
-
status: string
|
|
5
|
+
/** The name of the tool being called. */name: string; /** The parsed parameters passed to the tool call. */
|
|
6
|
+
parameters: unknown; /** Current execution status of the tool call. */
|
|
7
|
+
status: "inProgress" | "executing" | "complete"; /** The tool call result string, available only when `status` is `"complete"`. */
|
|
8
8
|
result: string | undefined;
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-default-render-tool.d.mts","names":[],"sources":["../../src/hooks/use-default-render-tool.tsx"],"mappings":";;;KAGK,kBAAA;
|
|
1
|
+
{"version":3,"file":"use-default-render-tool.d.mts","names":[],"sources":["../../src/hooks/use-default-render-tool.tsx"],"mappings":";;;KAGK,kBAAA;2CAEH,IAAA,UAFqB;EAIrB,UAAA,WAJqB;EAMrB,MAAA,2CAFA;EAIA,MAAA;AAAA;;;AAuCF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,oBAAA,CACd,MAAA;EACE,MAAA,IAAU,KAAA,EAAO,kBAAA,KAAuB,KAAA,CAAM,YAAA;AAAA,GAEhD,IAAA,GAAO,aAAA"}
|
|
@@ -45,7 +45,7 @@ function useDefaultRenderTool(config, deps) {
|
|
|
45
45
|
render: config?.render ?? DefaultToolCallRenderer
|
|
46
46
|
}, deps);
|
|
47
47
|
}
|
|
48
|
-
function DefaultToolCallRenderer({ name,
|
|
48
|
+
function DefaultToolCallRenderer({ name, parameters, status, result }) {
|
|
49
49
|
const [isExpanded, setIsExpanded] = useState(false);
|
|
50
50
|
const statusString = String(status);
|
|
51
51
|
const isActive = statusString === "inProgress" || statusString === "executing";
|
|
@@ -161,7 +161,7 @@ function DefaultToolCallRenderer({ name, args, status, result }) {
|
|
|
161
161
|
whiteSpace: "pre-wrap",
|
|
162
162
|
wordBreak: "break-word"
|
|
163
163
|
},
|
|
164
|
-
children: JSON.stringify(
|
|
164
|
+
children: JSON.stringify(parameters ?? {}, null, 2)
|
|
165
165
|
})] }), result !== void 0 && /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("div", {
|
|
166
166
|
style: {
|
|
167
167
|
fontSize: "10px",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-default-render-tool.mjs","names":[],"sources":["../../src/hooks/use-default-render-tool.tsx"],"sourcesContent":["import React, { useState } from \"react\";\nimport { useRenderTool } from \"./use-render-tool\";\n\ntype DefaultRenderProps = {\n name: string;\n
|
|
1
|
+
{"version":3,"file":"use-default-render-tool.mjs","names":[],"sources":["../../src/hooks/use-default-render-tool.tsx"],"sourcesContent":["import React, { useState } from \"react\";\nimport { useRenderTool } from \"./use-render-tool\";\n\ntype DefaultRenderProps = {\n /** The name of the tool being called. */\n name: string;\n /** The parsed parameters passed to the tool call. */\n parameters: unknown;\n /** Current execution status of the tool call. */\n status: \"inProgress\" | \"executing\" | \"complete\";\n /** The tool call result string, available only when `status` is `\"complete\"`. */\n result: string | undefined;\n};\n\n/**\n * Registers a wildcard (`\"*\"`) tool-call renderer via `useRenderTool`.\n *\n * - Call with no config to use CopilotKit's built-in default tool-call card.\n * - Pass `config.render` to replace the default UI with your own fallback renderer.\n *\n * This is useful when you want a generic renderer for tools that do not have a\n * dedicated `useRenderTool({ name: \"...\" })` registration.\n *\n * @param config - Optional custom wildcard render function.\n * @param deps - Optional dependencies to refresh registration.\n *\n * @example\n * ```tsx\n * useDefaultRenderTool();\n * ```\n *\n * @example\n * ```tsx\n * useDefaultRenderTool({\n * render: ({ name, status }) => <div>{name}: {status}</div>,\n * });\n * ```\n *\n * @example\n * ```tsx\n * useDefaultRenderTool(\n * {\n * render: ({ name, result }) => (\n * <ToolEventRow title={name} payload={result} compact={compactMode} />\n * ),\n * },\n * [compactMode],\n * );\n * ```\n */\nexport function useDefaultRenderTool(\n config?: {\n render?: (props: DefaultRenderProps) => React.ReactElement;\n },\n deps?: ReadonlyArray<unknown>,\n): void {\n useRenderTool(\n {\n name: \"*\",\n render: config?.render ?? DefaultToolCallRenderer,\n },\n deps,\n );\n}\n\nfunction DefaultToolCallRenderer({\n name,\n parameters,\n status,\n result,\n}: DefaultRenderProps): React.ReactElement {\n const [isExpanded, setIsExpanded] = useState(false);\n\n const statusString = String(status) as\n | \"inProgress\"\n | \"executing\"\n | \"complete\";\n const isActive =\n statusString === \"inProgress\" || statusString === \"executing\";\n const isComplete = statusString === \"complete\";\n\n const statusLabel = isActive ? \"Running\" : isComplete ? \"Done\" : status;\n const dotColor = isActive ? \"#f59e0b\" : isComplete ? \"#10b981\" : \"#a1a1aa\";\n const badgeBg = isActive ? \"#fef3c7\" : isComplete ? \"#d1fae5\" : \"#f4f4f5\";\n const badgeColor = isActive ? \"#92400e\" : isComplete ? \"#065f46\" : \"#3f3f46\";\n\n return (\n <div\n style={{\n marginTop: \"8px\",\n paddingBottom: \"8px\",\n }}\n >\n <div\n style={{\n borderRadius: \"12px\",\n border: \"1px solid #e4e4e7\",\n backgroundColor: \"#fafafa\",\n padding: \"14px 16px\",\n }}\n >\n {/* Header row — always visible */}\n <div\n onClick={() => setIsExpanded(!isExpanded)}\n style={{\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"space-between\",\n gap: \"10px\",\n cursor: \"pointer\",\n userSelect: \"none\",\n }}\n >\n <div\n style={{\n display: \"flex\",\n alignItems: \"center\",\n gap: \"8px\",\n minWidth: 0,\n }}\n >\n <svg\n style={{\n height: \"14px\",\n width: \"14px\",\n color: \"#71717a\",\n transition: \"transform 0.15s\",\n transform: isExpanded ? \"rotate(90deg)\" : \"rotate(0deg)\",\n flexShrink: 0,\n }}\n fill=\"none\"\n viewBox=\"0 0 24 24\"\n strokeWidth={2}\n stroke=\"currentColor\"\n >\n <path\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n d=\"M8.25 4.5l7.5 7.5-7.5 7.5\"\n />\n </svg>\n <span\n style={{\n display: \"inline-block\",\n height: \"8px\",\n width: \"8px\",\n borderRadius: \"50%\",\n backgroundColor: dotColor,\n flexShrink: 0,\n }}\n />\n <span\n style={{\n fontSize: \"13px\",\n fontWeight: 600,\n color: \"#18181b\",\n overflow: \"hidden\",\n textOverflow: \"ellipsis\",\n whiteSpace: \"nowrap\",\n }}\n >\n {name}\n </span>\n </div>\n\n <span\n style={{\n display: \"inline-flex\",\n alignItems: \"center\",\n borderRadius: \"9999px\",\n padding: \"2px 8px\",\n fontSize: \"11px\",\n fontWeight: 500,\n backgroundColor: badgeBg,\n color: badgeColor,\n flexShrink: 0,\n }}\n >\n {statusLabel}\n </span>\n </div>\n\n {/* Expandable details */}\n {isExpanded && (\n <div style={{ marginTop: \"12px\", display: \"grid\", gap: \"12px\" }}>\n <div>\n <div\n style={{\n fontSize: \"10px\",\n textTransform: \"uppercase\",\n letterSpacing: \"0.05em\",\n color: \"#71717a\",\n }}\n >\n Arguments\n </div>\n <pre\n style={{\n marginTop: \"6px\",\n maxHeight: \"200px\",\n overflow: \"auto\",\n borderRadius: \"6px\",\n backgroundColor: \"#f4f4f5\",\n padding: \"10px\",\n fontSize: \"11px\",\n lineHeight: 1.6,\n color: \"#27272a\",\n whiteSpace: \"pre-wrap\",\n wordBreak: \"break-word\",\n }}\n >\n {JSON.stringify(parameters ?? {}, null, 2)}\n </pre>\n </div>\n\n {result !== undefined && (\n <div>\n <div\n style={{\n fontSize: \"10px\",\n textTransform: \"uppercase\",\n letterSpacing: \"0.05em\",\n color: \"#71717a\",\n }}\n >\n Result\n </div>\n <pre\n style={{\n marginTop: \"6px\",\n maxHeight: \"200px\",\n overflow: \"auto\",\n borderRadius: \"6px\",\n backgroundColor: \"#f4f4f5\",\n padding: \"10px\",\n fontSize: \"11px\",\n lineHeight: 1.6,\n color: \"#27272a\",\n whiteSpace: \"pre-wrap\",\n wordBreak: \"break-word\",\n }}\n >\n {typeof result === \"string\"\n ? result\n : JSON.stringify(result, null, 2)}\n </pre>\n </div>\n )}\n </div>\n )}\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,SAAgB,qBACd,QAGA,MACM;AACN,eACE;EACE,MAAM;EACN,QAAQ,QAAQ,UAAU;EAC3B,EACD,KACD;;AAGH,SAAS,wBAAwB,EAC/B,MACA,YACA,QACA,UACyC;CACzC,MAAM,CAAC,YAAY,iBAAiB,SAAS,MAAM;CAEnD,MAAM,eAAe,OAAO,OAAO;CAInC,MAAM,WACJ,iBAAiB,gBAAgB,iBAAiB;CACpD,MAAM,aAAa,iBAAiB;AAOpC,QACE,oBAAC;EACC,OAAO;GACL,WAAW;GACX,eAAe;GAChB;YAED,qBAAC;GACC,OAAO;IACL,cAAc;IACd,QAAQ;IACR,iBAAiB;IACjB,SAAS;IACV;cAGD,qBAAC;IACC,eAAe,cAAc,CAAC,WAAW;IACzC,OAAO;KACL,SAAS;KACT,YAAY;KACZ,gBAAgB;KAChB,KAAK;KACL,QAAQ;KACR,YAAY;KACb;eAED,qBAAC;KACC,OAAO;MACL,SAAS;MACT,YAAY;MACZ,KAAK;MACL,UAAU;MACX;;MAED,oBAAC;OACC,OAAO;QACL,QAAQ;QACR,OAAO;QACP,OAAO;QACP,YAAY;QACZ,WAAW,aAAa,kBAAkB;QAC1C,YAAY;QACb;OACD,MAAK;OACL,SAAQ;OACR,aAAa;OACb,QAAO;iBAEP,oBAAC;QACC,eAAc;QACd,gBAAe;QACf,GAAE;SACF;QACE;MACN,oBAAC,UACC,OAAO;OACL,SAAS;OACT,QAAQ;OACR,OAAO;OACP,cAAc;OACd,iBAjEG,WAAW,YAAY,aAAa,YAAY;OAkEnD,YAAY;OACb,GACD;MACF,oBAAC;OACC,OAAO;QACL,UAAU;QACV,YAAY;QACZ,OAAO;QACP,UAAU;QACV,cAAc;QACd,YAAY;QACb;iBAEA;QACI;;MACH,EAEN,oBAAC;KACC,OAAO;MACL,SAAS;MACT,YAAY;MACZ,cAAc;MACd,SAAS;MACT,UAAU;MACV,YAAY;MACZ,iBA1FI,WAAW,YAAY,aAAa,YAAY;MA2FpD,OA1FO,WAAW,YAAY,aAAa,YAAY;MA2FvD,YAAY;MACb;eA/FS,WAAW,YAAY,aAAa,SAAS;MAkGlD;KACH,EAGL,cACC,qBAAC;IAAI,OAAO;KAAE,WAAW;KAAQ,SAAS;KAAQ,KAAK;KAAQ;eAC7D,qBAAC,oBACC,oBAAC;KACC,OAAO;MACL,UAAU;MACV,eAAe;MACf,eAAe;MACf,OAAO;MACR;eACF;MAEK,EACN,oBAAC;KACC,OAAO;MACL,WAAW;MACX,WAAW;MACX,UAAU;MACV,cAAc;MACd,iBAAiB;MACjB,SAAS;MACT,UAAU;MACV,YAAY;MACZ,OAAO;MACP,YAAY;MACZ,WAAW;MACZ;eAEA,KAAK,UAAU,cAAc,EAAE,EAAE,MAAM,EAAE;MACtC,IACF,EAEL,WAAW,UACV,qBAAC,oBACC,oBAAC;KACC,OAAO;MACL,UAAU;MACV,eAAe;MACf,eAAe;MACf,OAAO;MACR;eACF;MAEK,EACN,oBAAC;KACC,OAAO;MACL,WAAW;MACX,WAAW;MACX,UAAU;MACV,cAAc;MACd,iBAAiB;MACjB,SAAS;MACT,UAAU;MACV,YAAY;MACZ,OAAO;MACP,YAAY;MACZ,WAAW;MACZ;eAEA,OAAO,WAAW,WACf,SACA,KAAK,UAAU,QAAQ,MAAM,EAAE;MAC/B,IACF;KAEJ;IAEJ;GACF"}
|
|
@@ -13,7 +13,7 @@ const EMPTY_DEPS = [];
|
|
|
13
13
|
* - keeps renderer entries on cleanup so historical chat tool calls can still render,
|
|
14
14
|
* - refreshes registration when `deps` change.
|
|
15
15
|
*
|
|
16
|
-
* @typeParam S - Zod schema type describing tool call
|
|
16
|
+
* @typeParam S - Zod schema type describing tool call parameters.
|
|
17
17
|
* @param config - Renderer config for wildcard or named tools.
|
|
18
18
|
* @param deps - Optional dependencies to refresh registration.
|
|
19
19
|
*
|
|
@@ -22,9 +22,9 @@ const EMPTY_DEPS = [];
|
|
|
22
22
|
* useRenderTool(
|
|
23
23
|
* {
|
|
24
24
|
* name: "searchDocs",
|
|
25
|
-
*
|
|
26
|
-
* render: ({ status,
|
|
27
|
-
* if (status === "executing") return <div>Searching {
|
|
25
|
+
* parameters: z.object({ query: z.string() }),
|
|
26
|
+
* render: ({ status, parameters, result }) => {
|
|
27
|
+
* if (status === "executing") return <div>Searching {parameters.query}</div>;
|
|
28
28
|
* if (status === "complete") return <div>{result}</div>;
|
|
29
29
|
* return <div>Preparing...</div>;
|
|
30
30
|
* },
|
|
@@ -38,7 +38,7 @@ const EMPTY_DEPS = [];
|
|
|
38
38
|
* useRenderTool(
|
|
39
39
|
* {
|
|
40
40
|
* name: "summarize",
|
|
41
|
-
*
|
|
41
|
+
* parameters: z.object({ text: z.string() }),
|
|
42
42
|
* agentId: "research-agent",
|
|
43
43
|
* render: ({ name, status }) => <div>{name}: {status}</div>,
|
|
44
44
|
* },
|
|
@@ -50,14 +50,20 @@ function useRenderTool(config, deps) {
|
|
|
50
50
|
const { copilotkit } = require_CopilotKitProvider.useCopilotKit();
|
|
51
51
|
const extraDeps = deps ?? EMPTY_DEPS;
|
|
52
52
|
(0, react.useEffect)(() => {
|
|
53
|
-
const renderer = config.name === "*" && !config.
|
|
53
|
+
const renderer = config.name === "*" && !config.parameters ? require_defineToolCallRenderer.defineToolCallRenderer({
|
|
54
54
|
name: "*",
|
|
55
|
-
render: config.render
|
|
55
|
+
render: (props) => config.render({
|
|
56
|
+
...props,
|
|
57
|
+
parameters: props.args
|
|
58
|
+
}),
|
|
56
59
|
...config.agentId ? { agentId: config.agentId } : {}
|
|
57
60
|
}) : require_defineToolCallRenderer.defineToolCallRenderer({
|
|
58
61
|
name: config.name,
|
|
59
|
-
args: config.
|
|
60
|
-
render: config.render
|
|
62
|
+
args: config.parameters,
|
|
63
|
+
render: (props) => config.render({
|
|
64
|
+
...props,
|
|
65
|
+
parameters: props.args
|
|
66
|
+
}),
|
|
61
67
|
...config.agentId ? { agentId: config.agentId } : {}
|
|
62
68
|
});
|
|
63
69
|
const keyOf = (rc) => `${rc.agentId ?? ""}:${rc.name}`;
|
|
@@ -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 { z } from \"zod\";\nimport { useCopilotKit } from \"../providers/CopilotKitProvider\";\nimport { defineToolCallRenderer } from \"../types/defineToolCallRenderer\";\nimport type { ReactToolCallRenderer } from \"../types/react-tool-call-renderer\";\n\nconst EMPTY_DEPS: ReadonlyArray<unknown> = [];\n\nexport interface RenderToolInProgressProps<S extends z.ZodTypeAny> {\n name: string;\n
|
|
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 { z } from \"zod\";\nimport { useCopilotKit } from \"../providers/CopilotKitProvider\";\nimport { defineToolCallRenderer } from \"../types/defineToolCallRenderer\";\nimport type { ReactToolCallRenderer } from \"../types/react-tool-call-renderer\";\n\nconst EMPTY_DEPS: ReadonlyArray<unknown> = [];\n\nexport interface RenderToolInProgressProps<S extends z.ZodTypeAny> {\n name: string;\n parameters: Partial<z.infer<S>>;\n status: \"inProgress\";\n result: undefined;\n}\n\nexport interface RenderToolExecutingProps<S extends z.ZodTypeAny> {\n name: string;\n parameters: z.infer<S>;\n status: \"executing\";\n result: undefined;\n}\n\nexport interface RenderToolCompleteProps<S extends z.ZodTypeAny> {\n name: string;\n parameters: z.infer<S>;\n status: \"complete\";\n result: string;\n}\n\nexport type RenderToolProps<S extends z.ZodTypeAny> =\n | RenderToolInProgressProps<S>\n | RenderToolExecutingProps<S>\n | RenderToolCompleteProps<S>;\n\ntype RenderToolConfig<S extends z.ZodTypeAny> = {\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` Zod schema defines the typed shape of `props.parameters`\n * in `render` for `executing` and `complete` states.\n *\n * @typeParam S - Zod 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 z.ZodTypeAny>(\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 - Zod 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 z.ZodTypeAny>(\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 // Dedupe by \"agentId:name\" key, same pattern as useFrontendTool\n const keyOf = (rc: ReactToolCallRenderer) =>\n `${rc.agentId ?? \"\"}:${rc.name}`;\n const currentRenderToolCalls =\n copilotkit.renderToolCalls as ReactToolCallRenderer[];\n\n const mergedMap = new Map<string, ReactToolCallRenderer>();\n for (const rc of currentRenderToolCalls) {\n mergedMap.set(keyOf(rc), rc);\n }\n\n mergedMap.set(keyOf(renderer), renderer);\n\n copilotkit.setRenderToolCalls(Array.from(mergedMap.values()));\n\n // No cleanup removal — keeps renderer for chat history, same as useFrontendTool\n }, [config.name, copilotkit, extraDeps.length, ...extraDeps]);\n}\n"],"mappings":";;;;;;AAMA,MAAM,aAAqC,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiJ7C,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;EAGR,MAAM,SAAS,OACb,GAAG,GAAG,WAAW,GAAG,GAAG,GAAG;EAC5B,MAAM,yBACJ,WAAW;EAEb,MAAM,4BAAY,IAAI,KAAoC;AAC1D,OAAK,MAAM,MAAM,uBACf,WAAU,IAAI,MAAM,GAAG,EAAE,GAAG;AAG9B,YAAU,IAAI,MAAM,SAAS,EAAE,SAAS;AAExC,aAAW,mBAAmB,MAAM,KAAK,UAAU,QAAQ,CAAC,CAAC;IAG5D;EAAC,OAAO;EAAM;EAAY,UAAU;EAAQ,GAAG;EAAU,CAAC"}
|