@copilotkitnext/react 0.0.3 → 0.0.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.
Files changed (48) hide show
  1. package/package.json +3 -3
  2. package/.turbo/turbo-build$colon$css.log +0 -9
  3. package/.turbo/turbo-build.log +0 -30
  4. package/.turbo/turbo-check-types.log +0 -7
  5. package/.turbo/turbo-lint.log +0 -78
  6. package/.turbo/turbo-test.log +0 -79
  7. package/postcss.config.js +0 -7
  8. package/src/__tests__/setup.ts +0 -2
  9. package/src/components/chat/CopilotChat.tsx +0 -90
  10. package/src/components/chat/CopilotChatAssistantMessage.tsx +0 -478
  11. package/src/components/chat/CopilotChatAudioRecorder.tsx +0 -157
  12. package/src/components/chat/CopilotChatInput.tsx +0 -596
  13. package/src/components/chat/CopilotChatMessageView.tsx +0 -85
  14. package/src/components/chat/CopilotChatToolCallsView.tsx +0 -43
  15. package/src/components/chat/CopilotChatUserMessage.tsx +0 -337
  16. package/src/components/chat/CopilotChatView.tsx +0 -385
  17. package/src/components/chat/__tests__/CopilotChatAssistantMessage.test.tsx +0 -684
  18. package/src/components/chat/__tests__/CopilotChatInput.test.tsx +0 -531
  19. package/src/components/chat/__tests__/setup.ts +0 -1
  20. package/src/components/chat/index.ts +0 -35
  21. package/src/components/index.ts +0 -4
  22. package/src/components/ui/button.tsx +0 -123
  23. package/src/components/ui/dropdown-menu.tsx +0 -257
  24. package/src/components/ui/tooltip.tsx +0 -59
  25. package/src/hooks/index.ts +0 -6
  26. package/src/hooks/use-agent-context.tsx +0 -17
  27. package/src/hooks/use-agent.tsx +0 -48
  28. package/src/hooks/use-frontend-tool.tsx +0 -46
  29. package/src/hooks/use-human-in-the-loop.tsx +0 -76
  30. package/src/hooks/use-render-tool-call.tsx +0 -81
  31. package/src/index.ts +0 -4
  32. package/src/lib/__tests__/completePartialMarkdown.test.ts +0 -495
  33. package/src/lib/__tests__/renderSlot.test.tsx +0 -610
  34. package/src/lib/slots.tsx +0 -55
  35. package/src/lib/utils.ts +0 -6
  36. package/src/providers/CopilotChatConfigurationProvider.tsx +0 -81
  37. package/src/providers/CopilotKitProvider.tsx +0 -269
  38. package/src/providers/__tests__/CopilotKitProvider.test.tsx +0 -487
  39. package/src/providers/__tests__/CopilotKitProvider.wildcard.test.tsx +0 -261
  40. package/src/providers/index.ts +0 -14
  41. package/src/styles/globals.css +0 -302
  42. package/src/types/frontend-tool.ts +0 -8
  43. package/src/types/human-in-the-loop.ts +0 -33
  44. package/src/types/index.ts +0 -3
  45. package/src/types/react-tool-call-render.ts +0 -29
  46. package/tailwind.config.js +0 -9
  47. package/tsconfig.json +0 -23
  48. package/tsup.config.ts +0 -19
@@ -1,257 +0,0 @@
1
- "use client"
2
-
3
- import * as React from "react"
4
- import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu"
5
- import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react"
6
-
7
- import { cn } from "@/lib/utils"
8
-
9
- function DropdownMenu({
10
- ...props
11
- }: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {
12
- return <DropdownMenuPrimitive.Root data-slot="dropdown-menu" {...props} />
13
- }
14
-
15
- function DropdownMenuPortal({
16
- ...props
17
- }: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {
18
- return (
19
- <DropdownMenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />
20
- )
21
- }
22
-
23
- function DropdownMenuTrigger({
24
- ...props
25
- }: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {
26
- return (
27
- <DropdownMenuPrimitive.Trigger
28
- data-slot="dropdown-menu-trigger"
29
- {...props}
30
- />
31
- )
32
- }
33
-
34
- function DropdownMenuContent({
35
- className,
36
- sideOffset = 4,
37
- ...props
38
- }: React.ComponentProps<typeof DropdownMenuPrimitive.Content>) {
39
- return (
40
- <DropdownMenuPrimitive.Portal>
41
- <DropdownMenuPrimitive.Content
42
- data-slot="dropdown-menu-content"
43
- sideOffset={sideOffset}
44
- className={cn(
45
- "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",
46
- className
47
- )}
48
- {...props}
49
- />
50
- </DropdownMenuPrimitive.Portal>
51
- )
52
- }
53
-
54
- function DropdownMenuGroup({
55
- ...props
56
- }: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {
57
- return (
58
- <DropdownMenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />
59
- )
60
- }
61
-
62
- function DropdownMenuItem({
63
- className,
64
- inset,
65
- variant = "default",
66
- ...props
67
- }: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {
68
- inset?: boolean
69
- variant?: "default" | "destructive"
70
- }) {
71
- return (
72
- <DropdownMenuPrimitive.Item
73
- data-slot="dropdown-menu-item"
74
- data-inset={inset}
75
- data-variant={variant}
76
- className={cn(
77
- "focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
78
- className
79
- )}
80
- {...props}
81
- />
82
- )
83
- }
84
-
85
- function DropdownMenuCheckboxItem({
86
- className,
87
- children,
88
- checked,
89
- ...props
90
- }: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem>) {
91
- return (
92
- <DropdownMenuPrimitive.CheckboxItem
93
- data-slot="dropdown-menu-checkbox-item"
94
- className={cn(
95
- "focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
96
- className
97
- )}
98
- checked={checked}
99
- {...props}
100
- >
101
- <span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
102
- <DropdownMenuPrimitive.ItemIndicator>
103
- <CheckIcon className="size-4" />
104
- </DropdownMenuPrimitive.ItemIndicator>
105
- </span>
106
- {children}
107
- </DropdownMenuPrimitive.CheckboxItem>
108
- )
109
- }
110
-
111
- function DropdownMenuRadioGroup({
112
- ...props
113
- }: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {
114
- return (
115
- <DropdownMenuPrimitive.RadioGroup
116
- data-slot="dropdown-menu-radio-group"
117
- {...props}
118
- />
119
- )
120
- }
121
-
122
- function DropdownMenuRadioItem({
123
- className,
124
- children,
125
- ...props
126
- }: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem>) {
127
- return (
128
- <DropdownMenuPrimitive.RadioItem
129
- data-slot="dropdown-menu-radio-item"
130
- className={cn(
131
- "focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
132
- className
133
- )}
134
- {...props}
135
- >
136
- <span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
137
- <DropdownMenuPrimitive.ItemIndicator>
138
- <CircleIcon className="size-2 fill-current" />
139
- </DropdownMenuPrimitive.ItemIndicator>
140
- </span>
141
- {children}
142
- </DropdownMenuPrimitive.RadioItem>
143
- )
144
- }
145
-
146
- function DropdownMenuLabel({
147
- className,
148
- inset,
149
- ...props
150
- }: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {
151
- inset?: boolean
152
- }) {
153
- return (
154
- <DropdownMenuPrimitive.Label
155
- data-slot="dropdown-menu-label"
156
- data-inset={inset}
157
- className={cn(
158
- "px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",
159
- className
160
- )}
161
- {...props}
162
- />
163
- )
164
- }
165
-
166
- function DropdownMenuSeparator({
167
- className,
168
- ...props
169
- }: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>) {
170
- return (
171
- <DropdownMenuPrimitive.Separator
172
- data-slot="dropdown-menu-separator"
173
- className={cn("bg-border -mx-1 my-1 h-px", className)}
174
- {...props}
175
- />
176
- )
177
- }
178
-
179
- function DropdownMenuShortcut({
180
- className,
181
- ...props
182
- }: React.ComponentProps<"span">) {
183
- return (
184
- <span
185
- data-slot="dropdown-menu-shortcut"
186
- className={cn(
187
- "text-muted-foreground ml-auto text-xs tracking-widest",
188
- className
189
- )}
190
- {...props}
191
- />
192
- )
193
- }
194
-
195
- function DropdownMenuSub({
196
- ...props
197
- }: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {
198
- return <DropdownMenuPrimitive.Sub data-slot="dropdown-menu-sub" {...props} />
199
- }
200
-
201
- function DropdownMenuSubTrigger({
202
- className,
203
- inset,
204
- children,
205
- ...props
206
- }: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {
207
- inset?: boolean
208
- }) {
209
- return (
210
- <DropdownMenuPrimitive.SubTrigger
211
- data-slot="dropdown-menu-sub-trigger"
212
- data-inset={inset}
213
- className={cn(
214
- "focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex cursor-default items-center rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[inset]:pl-8",
215
- className
216
- )}
217
- {...props}
218
- >
219
- {children}
220
- <ChevronRightIcon className="ml-auto size-4" />
221
- </DropdownMenuPrimitive.SubTrigger>
222
- )
223
- }
224
-
225
- function DropdownMenuSubContent({
226
- className,
227
- ...props
228
- }: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) {
229
- return (
230
- <DropdownMenuPrimitive.SubContent
231
- data-slot="dropdown-menu-sub-content"
232
- className={cn(
233
- "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg",
234
- className
235
- )}
236
- {...props}
237
- />
238
- )
239
- }
240
-
241
- export {
242
- DropdownMenu,
243
- DropdownMenuPortal,
244
- DropdownMenuTrigger,
245
- DropdownMenuContent,
246
- DropdownMenuGroup,
247
- DropdownMenuLabel,
248
- DropdownMenuItem,
249
- DropdownMenuCheckboxItem,
250
- DropdownMenuRadioGroup,
251
- DropdownMenuRadioItem,
252
- DropdownMenuSeparator,
253
- DropdownMenuShortcut,
254
- DropdownMenuSub,
255
- DropdownMenuSubTrigger,
256
- DropdownMenuSubContent,
257
- }
@@ -1,59 +0,0 @@
1
- import * as React from "react";
2
- import * as TooltipPrimitive from "@radix-ui/react-tooltip";
3
-
4
- import { cn } from "@/lib/utils";
5
-
6
- function TooltipProvider({
7
- delayDuration = 0,
8
- ...props
9
- }: React.ComponentProps<typeof TooltipPrimitive.Provider>) {
10
- return (
11
- <TooltipPrimitive.Provider
12
- data-slot="tooltip-provider"
13
- delayDuration={delayDuration}
14
- {...props}
15
- />
16
- );
17
- }
18
-
19
- function Tooltip({
20
- ...props
21
- }: React.ComponentProps<typeof TooltipPrimitive.Root>) {
22
- return (
23
- <TooltipProvider>
24
- <TooltipPrimitive.Root data-slot="tooltip" {...props} />
25
- </TooltipProvider>
26
- );
27
- }
28
-
29
- function TooltipTrigger({
30
- ...props
31
- }: React.ComponentProps<typeof TooltipPrimitive.Trigger>) {
32
- return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />;
33
- }
34
-
35
- function TooltipContent({
36
- className,
37
- sideOffset = 0,
38
- children,
39
- ...props
40
- }: React.ComponentProps<typeof TooltipPrimitive.Content>) {
41
- return (
42
- <TooltipPrimitive.Portal>
43
- <TooltipPrimitive.Content
44
- data-slot="tooltip-content"
45
- sideOffset={sideOffset}
46
- className={cn(
47
- "bg-primary text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",
48
- className
49
- )}
50
- {...props}
51
- >
52
- {children}
53
- <TooltipPrimitive.Arrow className="bg-primary fill-primary z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]" />
54
- </TooltipPrimitive.Content>
55
- </TooltipPrimitive.Portal>
56
- );
57
- }
58
-
59
- export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };
@@ -1,6 +0,0 @@
1
- // React hooks for CopilotKit2
2
- export { useRenderToolCall } from "./use-render-tool-call";
3
- export { useFrontendTool } from "./use-frontend-tool";
4
- export { useHumanInTheLoop } from "./use-human-in-the-loop";
5
- export { useAgent } from "./use-agent";
6
- export { useAgentContext } from "./use-agent-context";
@@ -1,17 +0,0 @@
1
- import { useCopilotKit } from "../providers/CopilotKitProvider";
2
- import { Context } from "@ag-ui/client";
3
- import { useEffect } from "react";
4
-
5
- export function useAgentContext(context: Context) {
6
- const { description, value } = context;
7
- const { copilotkit } = useCopilotKit();
8
-
9
- useEffect(() => {
10
- if (!copilotkit) return;
11
-
12
- const id = copilotkit.addContext(context);
13
- return () => {
14
- copilotkit.removeContext(id);
15
- };
16
- }, [description, value, copilotkit]);
17
- }
@@ -1,48 +0,0 @@
1
- import { useCopilotKit } from "@/providers/CopilotKitProvider";
2
- import { useMemo, useEffect, useReducer, useState } from "react";
3
- import { DEFAULT_AGENT_ID } from "@copilotkitnext/shared";
4
- import { AbstractAgent } from "@ag-ui/client";
5
-
6
- export interface UseAgentProps {
7
- agentId?: string;
8
- }
9
-
10
- export function useAgent({ agentId }: UseAgentProps = {}) {
11
- agentId ??= DEFAULT_AGENT_ID;
12
-
13
- const { copilotkit } = useCopilotKit();
14
- const [, forceUpdate] = useReducer((x) => x + 1, 0);
15
- const [isRunning, setIsRunning] = useState(false);
16
-
17
- const agent: AbstractAgent | undefined = useMemo(() => {
18
- return copilotkit.getAgent(agentId);
19
- // eslint-disable-next-line react-hooks/exhaustive-deps
20
- }, [agentId, copilotkit.agents, copilotkit.didLoadRuntime, copilotkit]);
21
-
22
- useEffect(() => {
23
- const subscription = agent?.subscribe({
24
- onMessagesChanged() {
25
- forceUpdate();
26
- },
27
- onStateChanged() {
28
- forceUpdate();
29
- },
30
- onRunInitialized() {
31
- setIsRunning(true);
32
- },
33
- onRunFinalized() {
34
- setIsRunning(false);
35
- },
36
- onRunFailed() {
37
- setIsRunning(false);
38
- },
39
- });
40
-
41
- return () => subscription?.unsubscribe();
42
- }, [agent]);
43
-
44
- return {
45
- agent,
46
- isRunning,
47
- };
48
- }
@@ -1,46 +0,0 @@
1
- import { useEffect } from "react";
2
- import { useCopilotKit } from "../providers/CopilotKitProvider";
3
- import { ReactFrontendTool } from "../types/frontend-tool";
4
- import { ReactToolCallRender } from "../types/react-tool-call-render";
5
-
6
- export function useFrontendTool<T extends Record<string, unknown> = Record<string, unknown>>(
7
- tool: ReactFrontendTool<T>
8
- ) {
9
- const { renderToolCalls, copilotkit, setCurrentRenderToolCalls } =
10
- useCopilotKit();
11
-
12
- useEffect(() => {
13
- // Check if tool already exists
14
- if (tool.name in copilotkit.tools) {
15
- console.warn(
16
- `Tool '${tool.name}' already exists. It will be overridden.`
17
- );
18
- }
19
-
20
- copilotkit.addTool(tool);
21
-
22
- if (tool.render && tool.name in renderToolCalls) {
23
- console.warn(
24
- `Render component for tool '${tool.name}' already exists. It will be overridden.`
25
- );
26
- }
27
-
28
- if (tool.render && tool.parameters) {
29
- setCurrentRenderToolCalls((prev) => [
30
- ...prev,
31
- {
32
- name: tool.name,
33
- args: tool.parameters,
34
- render: tool.render,
35
- } as ReactToolCallRender<unknown>,
36
- ]);
37
- }
38
-
39
- return () => {
40
- copilotkit.removeTool(tool.name);
41
- setCurrentRenderToolCalls((prev) =>
42
- prev.filter(rc => rc.name !== tool.name)
43
- );
44
- };
45
- }, [tool, copilotkit, renderToolCalls, setCurrentRenderToolCalls]);
46
- }
@@ -1,76 +0,0 @@
1
- import { ReactToolCallRender } from "@/types/react-tool-call-render";
2
- import { useFrontendTool } from "./use-frontend-tool";
3
- import { ReactFrontendTool } from "@/types/frontend-tool";
4
- import { ReactHumanInTheLoop } from "@/types/human-in-the-loop";
5
- import { useState, useCallback, useRef } from "react";
6
- import React from "react";
7
-
8
- export function useHumanInTheLoop<T extends Record<string, unknown> = Record<string, unknown>>(
9
- tool: ReactHumanInTheLoop<T>
10
- ) {
11
- const [status, setStatus] = useState<"inProgress" | "executing" | "complete">(
12
- "inProgress"
13
- );
14
- const resolvePromiseRef = useRef<((result: unknown) => void) | null>(null);
15
-
16
- const respond = useCallback(async (result: unknown) => {
17
- if (resolvePromiseRef.current) {
18
- resolvePromiseRef.current(result);
19
- setStatus("complete");
20
- resolvePromiseRef.current = null;
21
- }
22
- }, []);
23
-
24
- const handler = useCallback(async () => {
25
- return new Promise((resolve) => {
26
- setStatus("executing");
27
- resolvePromiseRef.current = resolve;
28
- });
29
- }, []);
30
-
31
- const RenderComponent: ReactToolCallRender<T>["render"] = useCallback(
32
- (props) => {
33
- const ToolComponent = tool.render;
34
-
35
- // Enhance props based on current status
36
- if (status === "inProgress" && props.status === "inProgress") {
37
- const enhancedProps = {
38
- ...props,
39
- name: tool.name,
40
- description: tool.description || "",
41
- respond: undefined,
42
- };
43
- return React.createElement(ToolComponent, enhancedProps);
44
- } else if (status === "executing" && props.status === "executing") {
45
- const enhancedProps = {
46
- ...props,
47
- name: tool.name,
48
- description: tool.description || "",
49
- respond,
50
- };
51
- return React.createElement(ToolComponent, enhancedProps);
52
- } else if (status === "complete" && props.status === "complete") {
53
- const enhancedProps = {
54
- ...props,
55
- name: tool.name,
56
- description: tool.description || "",
57
- respond: undefined,
58
- };
59
- return React.createElement(ToolComponent, enhancedProps);
60
- }
61
-
62
- // Fallback - just render with original props
63
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
64
- return React.createElement(ToolComponent, props as any);
65
- },
66
- [tool.render, tool.name, tool.description, status, respond]
67
- );
68
-
69
- const frontendTool: ReactFrontendTool<T> = {
70
- ...tool,
71
- handler,
72
- render: RenderComponent,
73
- };
74
-
75
- useFrontendTool(frontendTool);
76
- }
@@ -1,81 +0,0 @@
1
- import React, { useCallback } from "react";
2
- import { ToolCall, ToolMessage } from "@ag-ui/core";
3
- import { ToolCallStatus } from "@copilotkitnext/core";
4
- import { useCopilotKit } from "@/providers/CopilotKitProvider";
5
- import { partialJSONParse } from "@copilotkitnext/shared";
6
-
7
- export interface UseRenderToolCallProps {
8
- toolCall: ToolCall;
9
- toolMessage?: ToolMessage;
10
- isLoading: boolean;
11
- }
12
-
13
- /**
14
- * Hook that returns a function to render tool calls based on the render functions
15
- * defined in CopilotKitProvider.
16
- *
17
- * @returns A function that takes a tool call and optional tool message and returns the rendered component
18
- */
19
- export function useRenderToolCall() {
20
- const { currentRenderToolCalls } = useCopilotKit();
21
-
22
- const renderToolCall = useCallback(
23
- ({
24
- toolCall,
25
- toolMessage,
26
- isLoading,
27
- }: UseRenderToolCallProps): React.ReactElement | null => {
28
- // Find the render config for this tool call by name
29
- // Also check for wildcard (*) renders if no exact match
30
- const renderConfig =
31
- currentRenderToolCalls.find(
32
- (rc) => rc.name === toolCall.function.name
33
- ) || currentRenderToolCalls.find((rc) => rc.name === "*");
34
-
35
- if (!renderConfig) {
36
- return null;
37
- }
38
-
39
- const RenderComponent = renderConfig.render;
40
-
41
- // Parse the arguments if they're a string
42
- const args = partialJSONParse(toolCall.function.arguments);
43
-
44
- // Create props based on status with proper typing
45
- if (toolMessage) {
46
- // Complete status with result
47
- return (
48
- <RenderComponent
49
- key={toolCall.id}
50
- args={args}
51
- status={ToolCallStatus.Complete}
52
- result={toolMessage.content}
53
- />
54
- );
55
- } else if (isLoading) {
56
- // In progress status when loading
57
- return (
58
- <RenderComponent
59
- key={toolCall.id}
60
- args={args}
61
- status={ToolCallStatus.InProgress}
62
- result={undefined}
63
- />
64
- );
65
- } else {
66
- // Complete status without result (empty result)
67
- return (
68
- <RenderComponent
69
- key={toolCall.id}
70
- args={args}
71
- status={ToolCallStatus.Complete}
72
- result=""
73
- />
74
- );
75
- }
76
- },
77
- [currentRenderToolCalls]
78
- );
79
-
80
- return renderToolCall;
81
- }
package/src/index.ts DELETED
@@ -1,4 +0,0 @@
1
- // React components and hooks for CopilotKit2
2
- export * from "./components";
3
- export * from "./hooks";
4
- export * from "./providers";